From 07fc3373242fe145ff26c0c7a6a259c9b06002a0 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 9 Apr 2015 11:54:02 -0400 Subject: [PATCH] Implemented the text functions on OS X. --- button_darwin.m | 16 +++++++++++++++- entry_darwin.m | 21 +++++++++++++++++++-- uipriv_darwin.h | 1 + util_darwin.m | 5 +++++ window_darwin.m | 10 +++++++++- 5 files changed, 49 insertions(+), 4 deletions(-) diff --git a/button_darwin.m b/button_darwin.m index 9eab2e48..a4191a9f 100644 --- a/button_darwin.m +++ b/button_darwin.m @@ -53,7 +53,21 @@ uiControl *uiNewButton(const char *text) return b.uiC; } -// TODO text +char *uiButtonText(uiControl *c) +{ + uiNSButton *b; + + b = (uiNSButton *) uiControlHandle(c); + return strdup(fromNSString([b title])); +} + +void uiButtonSetText(uiControl *c, const char *text) +{ + uiNSButton *b; + + b = (uiNSButton *) uiControlHandle(c); + [b setTitle:toNSString(text)]; +} void uiButtonOnClicked(uiControl *c, void (*f)(uiControl *, void *), void *data) { diff --git a/entry_darwin.m b/entry_darwin.m index b08d53b3..4a4047a0 100644 --- a/entry_darwin.m +++ b/entry_darwin.m @@ -20,14 +20,14 @@ // TOOD move elsewhere // these are based on interface builder defaults; my comments in the old code weren't very good so I don't really know what talked about what, sorry :/ -void finishNewTextField(NSTextField *t, BOOL isLabel) +void finishNewTextField(NSTextField *t, BOOL isEntry) { setStandardControlFont((id) t); // THE ORDER OF THESE CALLS IS IMPORTANT; CHANGE IT AND THE BORDERS WILL DISAPPEAR [t setBordered:NO]; [t setBezelStyle:NSTextFieldSquareBezel]; - [t setBezeled:isLabel]; + [t setBezeled:isEntry]; // TODO autocorrect comment @@ -49,3 +49,20 @@ uiControl *uiNewEntry(void) return t.uiC; } + +char *uiEntryText(uiControl *c) +{ + uiNSTextField *t; + + t = (uiNSTextField *) uiControlHandle(c); + // TODO wrap all strdup calls + return strdup(fromNSString([t stringValue])); +} + +void uiEntrySetText(uiControl *c, const char *text) +{ + uiNSTextField *t; + + t = (uiNSTextField *) uiControlHandle(c); + [t setStringValue:toNSString(text)]; +} diff --git a/uipriv_darwin.h b/uipriv_darwin.h index 1205d81b..5a48fcac 100644 --- a/uipriv_darwin.h +++ b/uipriv_darwin.h @@ -6,6 +6,7 @@ #import "ui_darwin.h" #define toNSString(str) [NSString stringWithUTF8String:(str)] +#define fromNSString(str) [(str) UTF8String] // TODO move this to the right place struct uiSizing { diff --git a/util_darwin.m b/util_darwin.m index d8166e95..8fbf391b 100644 --- a/util_darwin.m +++ b/util_darwin.m @@ -6,3 +6,8 @@ void setStandardControlFont(NSControl *control) { [control setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSRegularControlSize]]]; } + +void uiFreeText(char *s) +{ + free(s); +} diff --git a/window_darwin.m b/window_darwin.m index c2c312a1..2052f18d 100644 --- a/window_darwin.m +++ b/window_darwin.m @@ -79,7 +79,15 @@ uintptr_t uiWindowHandle(uiWindow *w) return (uintptr_t) (D.w); } -// TODO titles +char *uiWindowTitle(uiWindow *w) +{ + return strdup(fromNSString([D.w title])); +} + +void uiWindowSetTitle(uiWindow *w, const char *title) +{ + [D.w setTitle:toNSString(title)]; +} void uiWindowShow(uiWindow *w) {