Migrated darwin/entry.m and darwin/label.m; fixed more errors in darwin/button.m and darwin/checkbox.m (hopefully for good!).

This commit is contained in:
Pietro Gagliardi 2015-04-17 18:40:12 -04:00
parent 44dfc7d721
commit bac2ce130e
4 changed files with 54 additions and 73 deletions

View File

@ -76,9 +76,9 @@ static void buttonOnClicked(uiButton *bb, void (*f)(uiButton *, void *), void *d
uiButton *uiNewButton(const char *text) uiButton *uiNewButton(const char *text)
{ {
uiButton *b; struct button *b;
b = uiNew(uiButton); b = uiNew(struct button);
uiDarwinNewControl(uiControl(b), [NSButton class], NO, NO, destroy, b); uiDarwinNewControl(uiControl(b), [NSButton class], NO, NO, destroy, b);

View File

@ -94,9 +94,9 @@ static void checkboxSetChecked(uiCheckbox *cc, int checked)
uiCheckbox *uiNewCheckbox(const char *text) uiCheckbox *uiNewCheckbox(const char *text)
{ {
uiCheckbox *c; struct checkbox *c;
c = uiNew(uiCheckbox); c = uiNew(struct checkbox);
uiDarwinNewControl(uiControl(c), [NSButton class], NO, NO, destroy, NULL); uiDarwinNewControl(uiControl(c), [NSButton class], NO, NO, destroy, NULL);

View File

@ -1,44 +1,36 @@
// 9 april 2015 // 9 april 2015
#import "uipriv_darwin.h" #import "uipriv_darwin.h"
@interface uiNSTextField : NSTextField struct entry {
@property uiEntry *uiE; uiEntry e;
@end NSTextField *textfield;
}
@implementation uiNSTextField static void destroy(void *data)
- (void)viewDidMoveToSuperview
{ {
if (uiDarwinControlFreeWhenAppropriate(uiControl(self.uiE), [self superview])) { struct entry *e = (struct entry *) data;
[self setTarget:nil];
self.uiE = NULL; uiFree(e);
}
[super viewDidMoveToSuperview];
} }
@end static char *entryText(uiEntry *ee)
static char *entryText(uiEntry *e)
{ {
uiNSTextField *t; struct entry *e = (struct entry *) ee;
t = (uiNSTextField *) uiControlHandle(uiControl(e)); return uiDarwinNSStringToText([e->textfield stringValue]);
return uiDarwinNSStringToText([t stringValue]);
} }
static void entrySetText(uiEntry *e, const char *text) static void entrySetText(uiEntry *ee, const char *text)
{ {
uiNSTextField *t; struct entry *e = (struct entry *) ee;
t = (uiNSTextField *) uiControlHandle(uiControl(e)); [e->textfield setStringValue:toNSString(text)];
[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 :/ // 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)
{ {
setStandardControlFont((id) t); setStandardControlFont(t);
// THE ORDER OF THESE CALLS IS IMPORTANT; CHANGE IT AND THE BORDERS WILL DISAPPEAR // THE ORDER OF THESE CALLS IS IMPORTANT; CHANGE IT AND THE BORDERS WILL DISAPPEAR
[t setBordered:NO]; [t setBordered:NO];
@ -53,21 +45,19 @@ void finishNewTextField(NSTextField *t, BOOL isEntry)
uiEntry *uiNewEntry(void) uiEntry *uiNewEntry(void)
{ {
uiEntry *e; struct entry *e;
uiNSTextField *t;
e = uiNew(uiEntry); e = uiNew(struct entry);
uiDarwinNewControl(uiControl(e), [uiNSTextField class], NO, NO); uiDarwinNewControl(uiControl(e), [NSTextField class], NO, NO, destroy, NULL);
t = (uiNSTextField *) uiControlHandle(uiControl(e));
[t setSelectable:YES]; // otherwise the setting is masked by the editable default of YES e->textfield = (NSTextField *) VIEW(e);
finishNewTextField((NSTextField *) t, YES);
[e->textfield setSelectable:YES]; // otherwise the setting is masked by the editable default of YES
finishNewTextField(e->textfield, YES);
uiEntry(e)->Text = entryText; uiEntry(e)->Text = entryText;
uiEntry(e)->SetText = entrySetText; uiEntry(e)->SetText = entrySetText;
t.uiE = e; return uiEntry(e);
return t.uiE;
} }

View File

@ -1,59 +1,50 @@
// 9 april 2015 // 9 april 2015
#import "uipriv_darwin.h" #import "uipriv_darwin.h"
@interface uiLabelNSTextField : NSTextField struct label {
@property uiLabel *uiL; uiLabel l;
@end NSTextField *label;
};
@implementation uiLabelNSTextField static void destroy(void *data)
- (void)viewDidMoveToSuperview
{ {
if (uiDarwinControlFreeWhenAppropriate(uiControl(self.uiL), [self superview])) { struct label *l = (struct label *) data;
[self setTarget:nil];
self.uiL = NULL; uiFree(l);
}
[super viewDidMoveToSuperview];
} }
@end static char *labelText(uiLabel *ll)
static char *labelText(uiLabel *l)
{ {
uiLabelNSTextField *t; struct label *l = (struct label *) ll;
t = (uiLabelNSTextField *) uiControlHandle(uiControl(l)); return uiDarwinNSStringToText([l->label stringValue]);
return uiDarwinNSStringToText([t stringValue]);
} }
static void labelSetText(uiLabel *l, const char *text) static void labelSetText(uiLabel *ll, const char *text)
{ {
uiLabelNSTextField *t; struct label *l = (struct label *) ll;
t = (uiLabelNSTextField *) uiControlHandle(uiControl(l)); [l->label setStringValue:toNSString(text)];
[t setStringValue:toNSString(text)];
} }
uiLabel *uiNewLabel(const char *text) uiLabel *uiNewLabel(const char *text)
{ {
uiLabel *l; struct label *l;
uiLabelNSTextField *t;
l = uiNew(uiLabel); l = uiNew(struct label);
uiDarwinNewControl(uiControl(l), [uiLabelNSTextField class], NO, NO); uiDarwinNewControl(uiControl(l), [NSTextField class], NO, NO, destroy, NULL);
t = (uiLabelNSTextField *) uiControlHandle(uiControl(l));
[t setStringValue:toNSString(text)]; l->label = (NSTextField *) VIEW(l);
[t setEditable:NO];
[t setSelectable:NO]; [l->label setStringValue:toNSString(text)];
[t setDrawsBackground:NO]; [l->label setEditable:NO];
finishNewTextField((NSTextField *) t, NO); [l->label setSelectable:NO];
[l->label setDrawsBackground:NO];
finishNewTextField(l->label, NO);
uiLabel(l)->Text = labelText; uiLabel(l)->Text = labelText;
uiLabel(l)->SetText = labelSetText; uiLabel(l)->SetText = labelSetText;
t.uiL = l; return uiLabel(l);
return t.uiL;
} }