| 1 |
@implementation CocoaLineEdit : NSTextField |
| 2 |
|
| 3 |
-(id) initWith:(phoenix::LineEdit&)lineEditReference { |
| 4 |
if(self = [super initWithFrame:NSMakeRect(0, 0, 0, 0)]) { |
| 5 |
lineEdit = &lineEditReference; |
| 6 |
|
| 7 |
[self setDelegate:self]; |
| 8 |
[self setTarget:self]; |
| 9 |
[self setAction:@selector(activate:)]; |
| 10 |
|
| 11 |
//prevent focus changes from generating activate event |
| 12 |
[[self cell] setSendsActionOnEndEditing:NO]; |
| 13 |
} |
| 14 |
return self; |
| 15 |
} |
| 16 |
|
| 17 |
-(void) textDidChange:(NSNotification*)n { |
| 18 |
if(lineEdit->onChange) lineEdit->onChange(); |
| 19 |
} |
| 20 |
|
| 21 |
-(IBAction) activate:(id)sender { |
| 22 |
if(lineEdit->onActivate) lineEdit->onActivate(); |
| 23 |
} |
| 24 |
|
| 25 |
@end |
| 26 |
|
| 27 |
namespace phoenix { |
| 28 |
|
| 29 |
Size pLineEdit::minimumSize() { |
| 30 |
Size size = Font::size(lineEdit.font(), lineEdit.state.text); |
| 31 |
return {size.width + 10, size.height + 8}; |
| 32 |
} |
| 33 |
|
| 34 |
void pLineEdit::setEditable(bool editable) { |
| 35 |
@autoreleasepool { |
| 36 |
[cocoaView setEditable:editable]; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
void pLineEdit::setText(string text) { |
| 41 |
@autoreleasepool { |
| 42 |
[cocoaView setStringValue:[NSString stringWithUTF8String:text]]; |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
string pLineEdit::text() { |
| 47 |
@autoreleasepool { |
| 48 |
return [[cocoaView stringValue] UTF8String]; |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
void pLineEdit::constructor() { |
| 53 |
@autoreleasepool { |
| 54 |
cocoaView = cocoaLineEdit = [[CocoaLineEdit alloc] initWith:lineEdit]; |
| 55 |
setEditable(lineEdit.state.editable); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
void pLineEdit::destructor() { |
| 60 |
@autoreleasepool { |
| 61 |
[cocoaView release]; |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
} |