| 1 |
#if defined(Hiro_LineEdit) |
| 2 |
|
| 3 |
@implementation CocoaLineEdit |
| 4 |
|
| 5 |
-(id) initWith:(hiro::mLineEdit&)lineEditReference { |
| 6 |
if(self = [super initWithFrame:NSMakeRect(0, 0, 0, 0)]) { |
| 7 |
lineEdit = &lineEditReference; |
| 8 |
|
| 9 |
[self setDelegate:self]; |
| 10 |
[self setTarget:self]; |
| 11 |
[self setAction:@selector(activate:)]; |
| 12 |
|
| 13 |
//prevent focus changes from generating activate event |
| 14 |
[[self cell] setSendsActionOnEndEditing:NO]; |
| 15 |
} |
| 16 |
return self; |
| 17 |
} |
| 18 |
|
| 19 |
-(void) textDidChange:(NSNotification*)n { |
| 20 |
lineEdit->state.text = [[self stringValue] UTF8String]; |
| 21 |
lineEdit->doChange(); |
| 22 |
} |
| 23 |
|
| 24 |
-(IBAction) activate:(id)sender { |
| 25 |
lineEdit->doActivate(); |
| 26 |
} |
| 27 |
|
| 28 |
@end |
| 29 |
|
| 30 |
namespace hiro { |
| 31 |
|
| 32 |
auto pLineEdit::construct() -> void { |
| 33 |
cocoaView = cocoaLineEdit = [[CocoaLineEdit alloc] initWith:self()]; |
| 34 |
pWidget::construct(); |
| 35 |
|
| 36 |
setBackgroundColor(state().backgroundColor); |
| 37 |
setEditable(state().editable); |
| 38 |
setForegroundColor(state().foregroundColor); |
| 39 |
setText(state().text); |
| 40 |
} |
| 41 |
|
| 42 |
auto pLineEdit::destruct() -> void { |
| 43 |
[cocoaView removeFromSuperview]; |
| 44 |
} |
| 45 |
|
| 46 |
auto pLineEdit::minimumSize() const -> Size { |
| 47 |
Size size = pFont::size(self().font(true), state().text); |
| 48 |
return {size.width() + 10, size.height() + 8}; |
| 49 |
} |
| 50 |
|
| 51 |
auto pLineEdit::setBackgroundColor(Color color) -> void { |
| 52 |
} |
| 53 |
|
| 54 |
auto pLineEdit::setEditable(bool editable) -> void { |
| 55 |
[(CocoaLineEdit*)cocoaView setEditable:editable]; |
| 56 |
} |
| 57 |
|
| 58 |
auto pLineEdit::setForegroundColor(SystemColor color) -> void { |
| 59 |
[[(CocoaLineEdit*)cocoaView cell] setTextColor: NSMakeColor(color)]; |
| 60 |
} |
| 61 |
|
| 62 |
auto pLineEdit::setForegroundColor(Color color) -> void { |
| 63 |
[[(CocoaLineEdit*)cocoaView cell] setTextColor: color ? NSMakeColor(color) : NSMakeColor(hiro::SystemColor::Text)]; |
| 64 |
} |
| 65 |
|
| 66 |
auto pLineEdit::setText(const string& text) -> void { |
| 67 |
[(CocoaLineEdit*)cocoaView setStringValue:[NSString stringWithUTF8String:text]]; |
| 68 |
} |
| 69 |
|
| 70 |
/* |
| 71 |
auto pLineEdit::text() const -> string { |
| 72 |
return [[cocoaView stringValue] UTF8String]; |
| 73 |
} |
| 74 |
*/ |
| 75 |
|
| 76 |
} |
| 77 |
|
| 78 |
#endif |