Migrated darwin/label.m; fixed up some of the other files.

This commit is contained in:
Pietro Gagliardi 2015-04-16 14:41:24 -04:00
parent 7ec19d56a8
commit 6caebe05d9
4 changed files with 63 additions and 51 deletions

View File

@ -11,7 +11,7 @@
- (void)viewDidMoveToSuperview - (void)viewDidMoveToSuperview
{ {
if (uiDarwinControlFreeWhenAppropriate(self.uiC, [self superview])) { if (uiDarwinControlFreeWhenAppropriate(uiControl(self.uiB), [self superview])) {
[self setTarget:nil]; [self setTarget:nil];
self.uiB = NULL; self.uiB = NULL;
} }

View File

@ -11,7 +11,7 @@
- (void)viewDidMoveToSuperview - (void)viewDidMoveToSuperview
{ {
if (uiDarwinControlFreeWhenAppropriate(self.uiC, [self superview])) { if (uiDarwinControlFreeWhenAppropriate(uiControl(self.uiC), [self superview])) {
[self setTarget:nil]; [self setTarget:nil];
self.uiC = NULL; self.uiC = NULL;
} }

View File

@ -2,22 +2,38 @@
#import "uipriv_darwin.h" #import "uipriv_darwin.h"
@interface uiNSTextField : NSTextField @interface uiNSTextField : NSTextField
@property uiControl *uiC; @property uiEntry *uiE;
@end @end
@implementation uiNSTextField @implementation uiNSTextField
- (void)viewDidMoveToSuperview - (void)viewDidMoveToSuperview
{ {
if (uiDarwinControlFreeWhenAppropriate(self.uiC, [self superview])) { if (uiDarwinControlFreeWhenAppropriate(uiControl(self.uiE), [self superview])) {
[self setTarget:nil]; [self setTarget:nil];
self.uiC = NULL; self.uiE = NULL;
} }
[super viewDidMoveToSuperview]; [super viewDidMoveToSuperview];
} }
@end @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 // 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 :/ // 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) void finishNewTextField(NSTextField *t, BOOL isEntry)
@ -35,33 +51,23 @@ void finishNewTextField(NSTextField *t, BOOL isEntry)
[[t cell] setScrollable:YES]; [[t cell] setScrollable:YES];
} }
uiControl *uiNewEntry(void) uiEntry *uiNewEntry(void)
{ {
uiControl *c; uiEntry *e;
uiNSTextField *t; uiNSTextField *t;
c = uiDarwinNewControl([uiNSTextField class], NO, NO); e = uiNew(uiEntry);
uiDarwinNewControl(uiControl(e), [uiNSTextField class], NO, NO);
t = (uiNSTextField *) uiControlHandle(c); t = (uiNSTextField *) uiControlHandle(c);
t.uiC = c;
[t setSelectable:YES]; // otherwise the setting is masked by the editable default of YES [t setSelectable:YES]; // otherwise the setting is masked by the editable default of YES
finishNewTextField((NSTextField *) t, YES); finishNewTextField((NSTextField *) t, YES);
return t.uiC; uiEntry(e)->Text = entryText;
} uiEntry(e)->SetText = entrySetText;
char *uiEntryText(uiControl *c) t.uiE = e;
{
uiNSTextField *t; return t.uiE;
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)];
} }

View File

@ -2,52 +2,58 @@
#import "uipriv_darwin.h" #import "uipriv_darwin.h"
@interface uiLabelNSTextField : NSTextField @interface uiLabelNSTextField : NSTextField
@property uiControl *uiC; @property uiLabel *uiL;
@end @end
@implementation uiLabelNSTextField @implementation uiLabelNSTextField
- (void)viewDidMoveToSuperview - (void)viewDidMoveToSuperview
{ {
if (uiDarwinControlFreeWhenAppropriate(self.uiC, [self superview])) { if (uiDarwinControlFreeWhenAppropriate(uiControl(self.uiL), [self superview])) {
[self setTarget:nil]; [self setTarget:nil];
self.uiC = NULL; self.uiL = NULL;
} }
[super viewDidMoveToSuperview]; [super viewDidMoveToSuperview];
} }
@end @end
uiControl *uiNewLabel(const char *text) static char *labelText(uiLabel *l)
{
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)
{ {
uiLabelNSTextField *t; uiLabelNSTextField *t;
t = (uiLabelNSTextField *) uiControlHandle(c); t = (uiLabelNSTextField *) uiControlHandle(uiControl(l));
return uiDarwinNSStringToText([t stringValue]); return uiDarwinNSStringToText([t stringValue]);
} }
void uiLabelSetText(uiControl *c, const char *text) static void labelSetText(uiLabel *l, const char *text)
{ {
uiLabelNSTextField *t; uiLabelNSTextField *t;
t = (uiLabelNSTextField *) uiControlHandle(c); t = (uiLabelNSTextField *) uiControlHandle(uiControl(l));
[t setStringValue:toNSString(text)]; [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;
}