Implemented the text functions on OS X.

This commit is contained in:
Pietro Gagliardi 2015-04-09 11:54:02 -04:00
parent 8e0d74865d
commit 07fc337324
5 changed files with 49 additions and 4 deletions

View File

@ -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)
{

View File

@ -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)];
}

View File

@ -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 {

View File

@ -6,3 +6,8 @@ void setStandardControlFont(NSControl *control)
{
[control setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSRegularControlSize]]];
}
void uiFreeText(char *s)
{
free(s);
}

View File

@ -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)
{