From 6caebe05d97d052b27733309ce3fb24fab13404e Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 16 Apr 2015 14:41:24 -0400 Subject: [PATCH] Migrated darwin/label.m; fixed up some of the other files. --- darwin/button.m | 2 +- darwin/checkbox.m | 2 +- darwin/entry.m | 54 +++++++++++++++++++++++++-------------------- darwin/label.m | 56 ++++++++++++++++++++++++++--------------------- 4 files changed, 63 insertions(+), 51 deletions(-) diff --git a/darwin/button.m b/darwin/button.m index ac4fb0a9..fd73675a 100644 --- a/darwin/button.m +++ b/darwin/button.m @@ -11,7 +11,7 @@ - (void)viewDidMoveToSuperview { - if (uiDarwinControlFreeWhenAppropriate(self.uiC, [self superview])) { + if (uiDarwinControlFreeWhenAppropriate(uiControl(self.uiB), [self superview])) { [self setTarget:nil]; self.uiB = NULL; } diff --git a/darwin/checkbox.m b/darwin/checkbox.m index 42ea833a..5ad6961b 100644 --- a/darwin/checkbox.m +++ b/darwin/checkbox.m @@ -11,7 +11,7 @@ - (void)viewDidMoveToSuperview { - if (uiDarwinControlFreeWhenAppropriate(self.uiC, [self superview])) { + if (uiDarwinControlFreeWhenAppropriate(uiControl(self.uiC), [self superview])) { [self setTarget:nil]; self.uiC = NULL; } diff --git a/darwin/entry.m b/darwin/entry.m index f2b208bb..84835f36 100644 --- a/darwin/entry.m +++ b/darwin/entry.m @@ -2,22 +2,38 @@ #import "uipriv_darwin.h" @interface uiNSTextField : NSTextField -@property uiControl *uiC; +@property uiEntry *uiE; @end @implementation uiNSTextField - (void)viewDidMoveToSuperview { - if (uiDarwinControlFreeWhenAppropriate(self.uiC, [self superview])) { + if (uiDarwinControlFreeWhenAppropriate(uiControl(self.uiE), [self superview])) { [self setTarget:nil]; - self.uiC = NULL; + self.uiE = NULL; } [super viewDidMoveToSuperview]; } @end +static char *entryText(uiEntry *e) +{ + uiNSTextField *t; + + t = (uiNSTextField *) uiControlHandle(uiControl(e)); + return uiDarwinNSStringToText([t stringValue]); +} + +static void entrySetText(uiEntry *e, const char *text) +{ + uiNSTextField *t; + + t = (uiNSTextField *) uiControlHandle(uiControl(e)); + [t setStringValue:toNSString(text)]; +} + // 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 isEntry) @@ -35,33 +51,23 @@ void finishNewTextField(NSTextField *t, BOOL isEntry) [[t cell] setScrollable:YES]; } -uiControl *uiNewEntry(void) +uiEntry *uiNewEntry(void) { - uiControl *c; + uiEntry *e; uiNSTextField *t; - c = uiDarwinNewControl([uiNSTextField class], NO, NO); + e = uiNew(uiEntry); + + uiDarwinNewControl(uiControl(e), [uiNSTextField class], NO, NO); t = (uiNSTextField *) uiControlHandle(c); - t.uiC = c; [t setSelectable:YES]; // otherwise the setting is masked by the editable default of YES finishNewTextField((NSTextField *) t, YES); - return t.uiC; -} - -char *uiEntryText(uiControl *c) -{ - uiNSTextField *t; - - t = (uiNSTextField *) uiControlHandle(c); - return uiDarwinNSStringToText([t stringValue]); -} - -void uiEntrySetText(uiControl *c, const char *text) -{ - uiNSTextField *t; - - t = (uiNSTextField *) uiControlHandle(c); - [t setStringValue:toNSString(text)]; + uiEntry(e)->Text = entryText; + uiEntry(e)->SetText = entrySetText; + + t.uiE = e; + + return t.uiE; } diff --git a/darwin/label.m b/darwin/label.m index e3fb3512..4f20e985 100644 --- a/darwin/label.m +++ b/darwin/label.m @@ -2,52 +2,58 @@ #import "uipriv_darwin.h" @interface uiLabelNSTextField : NSTextField -@property uiControl *uiC; +@property uiLabel *uiL; @end @implementation uiLabelNSTextField - (void)viewDidMoveToSuperview { - if (uiDarwinControlFreeWhenAppropriate(self.uiC, [self superview])) { + if (uiDarwinControlFreeWhenAppropriate(uiControl(self.uiL), [self superview])) { [self setTarget:nil]; - self.uiC = NULL; + self.uiL = NULL; } [super viewDidMoveToSuperview]; } @end -uiControl *uiNewLabel(const char *text) -{ - uiControl *c; - uiLabelNSTextField *l; - - c = uiDarwinNewControl([uiLabelNSTextField class], NO, NO); - l = (uiLabelNSTextField *) uiControlHandle(c); - l.uiC = c; - - [l setStringValue:toNSString(text)]; - [l setEditable:NO]; - [l setSelectable:NO]; - [l setDrawsBackground:NO]; - finishNewTextField((NSTextField *) l, NO); - - return l.uiC; -} - -char *uiLabelText(uiControl *c) +static char *labelText(uiLabel *l) { uiLabelNSTextField *t; - t = (uiLabelNSTextField *) uiControlHandle(c); + t = (uiLabelNSTextField *) uiControlHandle(uiControl(l)); return uiDarwinNSStringToText([t stringValue]); } -void uiLabelSetText(uiControl *c, const char *text) +static void labelSetText(uiLabel *l, const char *text) { uiLabelNSTextField *t; - t = (uiLabelNSTextField *) uiControlHandle(c); + t = (uiLabelNSTextField *) uiControlHandle(uiControl(l)); [t setStringValue:toNSString(text)]; } + +uiControl *uiNewLabel(const char *text) +{ + uiLabel *l; + uiLabelNSTextField *t; + + l = uiNew(uiLabel); + + uiDarwinNewControl(uiControl(l), [uiLabelNSTextField class], NO, NO); + t = (uiLabelNSTextField *) uiControlHandle(c); + + [t setStringValue:toNSString(text)]; + [t setEditable:NO]; + [t setSelectable:NO]; + [t setDrawsBackground:NO]; + finishNewTextField((NSTextField *) t, NO); + + uiLabel(l)->Text = labelText; + uiLabel(l)->SetText = labelSetText; + + t.uiC = l; + + return t.uiC; +}