-
Notifications
You must be signed in to change notification settings - Fork 10
/
COPopUpTextField.m
89 lines (78 loc) · 2.32 KB
/
COPopUpTextField.m
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
#import "COPopUpTextField.h"
@implementation COPopUpTextField
- (void)setMaxSize:(NSSize)size
{
if (size.width > maxSize.width || size.height > maxSize.height) {
maxSize = size;
}
}
- (void)awakeFromNib
{
pb = [[NSPopUpButton alloc] init];
//maxSize = NSZeroSize;
}
- (void)setMenu:(NSMenu *)aMenu
{
[pb setMenu:aMenu];
}
- (void)drawRect:(NSRect)aRect
{
[super drawRect:aRect];
NSImage *image = [NSImage imageNamed:@"updown"];
NSImageRep *rep = [[image representations] objectAtIndex:0];
NSRect tempRect = NSMakeRect(aRect.size.width-25,-6,25,25);
tempRect = NSMakeRect(aRect.size.width-25,-6,25,25);
[image drawInRect:tempRect
fromRect:NSMakeRect(0,0,[rep pixelsWide],[rep pixelsHigh])
operation:NSCompositeSourceOver fraction:1.0];
}
- (void)sizeToFit
{
[self setHidden:YES];
[super sizeToFit];
NSRect tempRect = [self frame];
NSSize tempSize = tempRect.size;
/*
if (tempSize.height>maxSize.height) {
tempRect = NSMakeRect(tempRect.origin.x,tempRect.origin.y,maxSize.width,19)
}*/
if (tempSize.width > maxSize.width) {
tempRect = NSMakeRect(tempRect.origin.x,tempRect.origin.y,maxSize.width-25,19);
}
[self setFrame:NSMakeRect(tempRect.origin.x,tempRect.origin.y,tempRect.size.width+25,19)];
[self setFrame:NSMakeRect(tempRect.origin.x,tempRect.origin.y,tempRect.size.width+25,19)];
[self setHidden:NO];
}
- (void)mouseDown:(NSEvent *)theEvent
{
/*
NSEvent *aMenuEvent;
NSPoint aMenuLoc;
aMenuLoc = [self frame].origin;
aMenuEvent = [ NSEvent mouseEventWithType:[ theEvent type ]
location: aMenuLoc
modifierFlags:[ theEvent modifierFlags ]
timestamp:[ theEvent timestamp ]
windowNumber:[ theEvent windowNumber ]
context:[ theEvent context ]
eventNumber:[ theEvent eventNumber ]
clickCount:[ theEvent clickCount ]
pressure:[ theEvent pressure ]];
[ NSMenu popUpContextMenu:[ self menu ] withEvent:aMenuEvent forView:self ];
*/
NSRect temp;
temp = NSMakeRect([self visibleRect].origin.x+8,
[self visibleRect].origin.y+20,
[self visibleRect].size.width,
[self visibleRect].size.height);
[[pb cell] performClickWithFrame:temp inView:self];
//[self display];
//[[pb cell] attachPopUpWithFrame:[self visibleRect] inView:self];
}
/*
- (void)mouseUp:(NSEvent *)theEvent
{
[[pb cell] dismissPopUp];
}
*/
@end