diff options
| author | Pietro Gagliardi <[email protected]> | 2014-07-26 09:20:33 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-07-26 09:20:33 -0400 |
| commit | e8df54cb825e7026a2e6f2fdaa15da1ab06cb607 (patch) | |
| tree | 04fa43804a3a6a3f80c45a1227c3e341e855d19f /redo/controls_darwin.m | |
| parent | 348b3f70327e1bbf35e9db455a5939f7197b17d9 (diff) | |
Implemented TextField on Mac OS X.
Diffstat (limited to 'redo/controls_darwin.m')
| -rw-r--r-- | redo/controls_darwin.m | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/redo/controls_darwin.m b/redo/controls_darwin.m index ecb4abd..198e363 100644 --- a/redo/controls_darwin.m +++ b/redo/controls_darwin.m @@ -8,6 +8,7 @@ #define toNSWindow(x) ((NSWindow *) (x)) #define toNSControl(x) ((NSControl *) (x)) #define toNSButton(x) ((NSButton *) (x)) +#define toNSTextField(x) ((NSTextField *) (x)) void parent(id control, id parentid) { @@ -101,3 +102,42 @@ void checkboxSetChecked(id c, BOOL checked) state = NSOffState; [toNSButton(c) setState:state]; } + +static id finishNewTextField(NSTextField *t) +{ + // TODO font + // TODO smart quotes + // Interface Builder does this to make the text box behave properly + // this disables both word wrap AND ellipsizing in one fell swoop + // however, we need to send it to the control's cell, not to the control directly + [[t cell] setLineBreakMode:NSLineBreakByClipping]; + // Interface Builder also sets this to allow horizontal scrolling + [[t cell] setScrollable:YES]; + return (id) t; +} + +id newTextField(void) +{ + NSTextField *t; + + t = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]; + return finishNewTextField(t); +} + +id newPasswordField(void) +{ + NSSecureTextField *t; + + t = [[NSSecureTextField alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]; + return finishNewTextField(toNSTextField(t)); +} + +const char *textFieldText(id t) +{ + return [[toNSTextField(t) stringValue] UTF8String]; +} + +void textFieldSetText(id t, char *text) +{ + [toNSTextField(t) setStringValue:[NSString stringWithUTF8String:text]]; +} |
