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
{
if (uiDarwinControlFreeWhenAppropriate(self.uiC, [self superview])) {
if (uiDarwinControlFreeWhenAppropriate(uiControl(self.uiB), [self superview])) {
[self setTarget:nil];
self.uiB = NULL;
}

View File

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

View File

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

View File

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