From e8df54cb825e7026a2e6f2fdaa15da1ab06cb607 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 26 Jul 2014 09:20:33 -0400 Subject: Implemented TextField on Mac OS X. --- redo/controls_darwin.m | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'redo/controls_darwin.m') 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]]; +} -- cgit v1.2.3