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 *b;
struct button *b;
b = uiNew(uiButton);
b = uiNew(struct button);
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 *c;
struct checkbox *c;
c = uiNew(uiCheckbox);
c = uiNew(struct checkbox);
uiDarwinNewControl(uiControl(c), [NSButton class], NO, NO, destroy, NULL);

View File

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

View File

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