Added uiTab page tracking to the Mac OS X backend; necessary for tabDeletePage(). Fixed some small NULL pointer errors in some other files too.

This commit is contained in:
Pietro Gagliardi 2015-04-19 11:41:23 -04:00
parent 8179d66ae6
commit c99e8d4af4
4 changed files with 23 additions and 4 deletions

View File

@ -98,7 +98,7 @@ uiCheckbox *uiNewCheckbox(const char *text)
c = uiNew(struct checkbox); c = uiNew(struct checkbox);
uiDarwinNewControl(uiControl(c), [NSButton class], NO, NO, destroy, NULL); uiDarwinNewControl(uiControl(c), [NSButton class], NO, NO, destroy, c);
c->checkbox = (NSButton *) VIEW(c); c->checkbox = (NSButton *) VIEW(c);

View File

@ -49,7 +49,7 @@ uiEntry *uiNewEntry(void)
e = uiNew(struct entry); e = uiNew(struct entry);
uiDarwinNewControl(uiControl(e), [NSTextField class], NO, NO, destroy, NULL); uiDarwinNewControl(uiControl(e), [NSTextField class], NO, NO, destroy, e);
e->textfield = (NSTextField *) VIEW(e); e->textfield = (NSTextField *) VIEW(e);

View File

@ -33,7 +33,7 @@ uiLabel *uiNewLabel(const char *text)
l = uiNew(struct label); l = uiNew(struct label);
uiDarwinNewControl(uiControl(l), [NSTextField class], NO, NO, destroy, NULL); uiDarwinNewControl(uiControl(l), [NSTextField class], NO, NO, destroy, l);
l->label = (NSTextField *) VIEW(l); l->label = (NSTextField *) VIEW(l);

View File

@ -8,12 +8,21 @@
struct tab { struct tab {
uiTab t; uiTab t;
NSTabView *tabview; NSTabView *tabview;
NSMutableArray *pages;
}; };
static void destroy(void *data) static void destroy(void *data)
{ {
struct tab *t = (struct tab *) data; struct tab *t = (struct tab *) data;
[t->pages enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
NSValue *v = (NSValue *) obj;
uiParent *p;
p = (uiParent *) [v pointerValue];
uiParentDestroy(p);
}];
[t->pages release];
uiFree(t); uiFree(t);
} }
@ -37,6 +46,7 @@ static void tabAddPage(uiTab *tt, const char *name, uiControl *child)
content = uiNewParent(0); content = uiNewParent(0);
uiParentSetMainControl(content, child); uiParentSetMainControl(content, child);
[t->pages addObject:[NSValue valueWithPointer:content]];
i = [[NSTabViewItem alloc] initWithIdentifier:nil]; i = [[NSTabViewItem alloc] initWithIdentifier:nil];
[i setLabel:toNSString(name)]; [i setLabel:toNSString(name)];
@ -44,19 +54,28 @@ static void tabAddPage(uiTab *tt, const char *name, uiControl *child)
[t->tabview addTabViewItem:i]; [t->tabview addTabViewItem:i];
} }
static void tabDeletePage(uiTab *tt, uintmax_t n)
{
struct tab *t = (struct tab *) tt;
[t->pages removeObjectAtIndex:n];
}
uiTab *uiNewTab(void) uiTab *uiNewTab(void)
{ {
struct tab *t; struct tab *t;
t = uiNew(struct tab); t = uiNew(struct tab);
uiDarwinNewControl(uiControl(t), [NSTabView class], NO, NO, destroy, NULL); uiDarwinNewControl(uiControl(t), [NSTabView class], NO, NO, destroy, t);
t->tabview = (NSTabView *) VIEW(t); t->tabview = (NSTabView *) VIEW(t);
// also good for NSTabView (same selector and everything) // also good for NSTabView (same selector and everything)
setStandardControlFont((NSControl *) (t->tabview)); setStandardControlFont((NSControl *) (t->tabview));
t->pages = [NSMutableArray new];
uiControl(t)->PreferredSize = preferredSize; uiControl(t)->PreferredSize = preferredSize;
uiTab(t)->AddPage = tabAddPage; uiTab(t)->AddPage = tabAddPage;