-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathIPSWebAddressFieldCell.m
More file actions
executable file
·123 lines (94 loc) · 5.04 KB
/
Copy pathIPSWebAddressFieldCell.m
File metadata and controls
executable file
·123 lines (94 loc) · 5.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
Copyright (c) 2007, Marketcircle Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#import "IPSWebAddressFieldCell.h"
#import "IPSWebAddressField.h"
static NSImageCell *background = nil;
static NSImageCell *leftCap = nil;
static NSImageCell *rightCap = nil;
static NSImageCell *backgroundLoading = nil;
static NSImageCell *leftCapLoading = nil;
static NSImageCell *rightCapLoading = nil;
@implementation IPSWebAddressFieldCell
+ (void)initialize;
{
// Initialize our background image
background = [[NSImageCell alloc] initImageCell:[NSImage imageNamed:@"IPSWebAddressFieldBackground"]];
[background setImageScaling:NSScaleToFit];
leftCap = [[NSImageCell alloc] initImageCell:[NSImage imageNamed:@"IPSWebAddressFieldLeftCap"]];
rightCap = [[NSImageCell alloc] initImageCell:[NSImage imageNamed:@"IPSWebAddressFieldRightCap"]];
backgroundLoading = [[NSImageCell alloc] initImageCell:[NSImage imageNamed:@"IPSWebAddressBarLoadingBackground"]];
[backgroundLoading setImageScaling:NSScaleToFit];
leftCapLoading = [[NSImageCell alloc] initImageCell:[NSImage imageNamed:@"IPSWebAddressFieldLoadingLeftCap"]];
rightCapLoading = [[NSImageCell alloc] initImageCell:[NSImage imageNamed:@"IPSWebAddressFieldLoadingRightCap"]];
}
- (id) init {
self = [super init];
if (self != nil) {
progressRect = NSZeroRect;
}
return self;
}
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
IPSWebAddressField *addressField = (IPSWebAddressField *)controlView;
BOOL addressFieldIsBeingEdited = [[[addressField window] fieldEditor:NO forObject:nil] delegate] == addressField;
if (([addressField progress] > 0.0) && !addressFieldIsBeingEdited ) {
progressRect = NSMakeRect(cellFrame.origin.x + 10, cellFrame.origin.y,cellFrame.size.width - 20,cellFrame.size.height);
progressRect.size.width = progressRect.size.width * [addressField progress];
[backgroundLoading drawWithFrame:progressRect inView:controlView];
NSRect bgRect = NSMakeRect(progressRect.origin.x + progressRect.size.width, cellFrame.origin.y,cellFrame.size.width - 20 - progressRect.size.width,cellFrame.size.height);
[background drawWithFrame:bgRect inView:controlView];
NSRect leftCapRect = NSMakeRect(cellFrame.origin.x,cellFrame.origin.y,10,32);
[leftCapLoading drawWithFrame:leftCapRect inView:controlView];
if ([addressField progress] == 1.0) {
NSRect rightCapRect = NSMakeRect(cellFrame.origin.x + cellFrame.size.width - 10,cellFrame.origin.y,10,32);
[rightCapLoading drawWithFrame:rightCapRect inView:controlView];
} else {
NSRect rightCapRect = NSMakeRect(cellFrame.origin.x + cellFrame.size.width - 10,cellFrame.origin.y,10,32);
[rightCap drawWithFrame:rightCapRect inView:controlView];
}
}
else {
NSRect bgRect = NSMakeRect(cellFrame.origin.x + 10, cellFrame.origin.y,cellFrame.size.width - 20,cellFrame.size.height);
[background drawWithFrame:bgRect inView:controlView];
NSRect leftCapRect = NSMakeRect(cellFrame.origin.x,cellFrame.origin.y,10,32);
[leftCap drawWithFrame:leftCapRect inView:controlView];
NSRect rightCapRect = NSMakeRect(cellFrame.origin.x + cellFrame.size.width - 10,cellFrame.origin.y,10,32);
[rightCap drawWithFrame:rightCapRect inView:controlView];
}
[super drawWithFrame:cellFrame inView:controlView];
}
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
NSRect textRect = NSMakeRect(cellFrame.origin.x+10,cellFrame.origin.y + 8,cellFrame.size.width - 20,cellFrame.size.height - 8);
[super drawInteriorWithFrame:textRect inView:controlView];
}
- (void)editWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject event:(NSEvent *)theEvent
{
NSRect textRect = NSMakeRect(aRect.origin.x+10,aRect.origin.y + 8,aRect.size.width - 20,aRect.size.height - 8);
[super editWithFrame:textRect inView:controlView editor:textObj delegate:anObject event:theEvent];
}
- (void)selectWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject start:(int)selStart length:(int)selLength
{
NSRect textRect = NSMakeRect(aRect.origin.x+10,aRect.origin.y + 8,aRect.size.width - 20,aRect.size.height - 8);
[super selectWithFrame:textRect inView:controlView editor:textObj delegate:anObject start:selStart length:selLength];
}
- (NSText *)setUpFieldEditorAttributes:(NSText *)textObj
{
NSText *fieldEditor = [super setUpFieldEditorAttributes:textObj];
[fieldEditor setDrawsBackground:NO];
return fieldEditor;
}
@end