From c99e8d4af47ab8d0ba5f7e45868d50013a75227f Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 19 Apr 2015 11:41:23 -0400 Subject: [PATCH] Added uiTab page tracking to the Mac OS X backend; necessary for tabDeletePage(). Fixed some small NULL pointer errors in some other files too. --- darwin/checkbox.m | 2 +- darwin/entry.m | 2 +- darwin/label.m | 2 +- darwin/tab.m | 21 ++++++++++++++++++++- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/darwin/checkbox.m b/darwin/checkbox.m index 757e4ae7..f1e4195f 100644 --- a/darwin/checkbox.m +++ b/darwin/checkbox.m @@ -98,7 +98,7 @@ uiCheckbox *uiNewCheckbox(const char *text) 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); diff --git a/darwin/entry.m b/darwin/entry.m index d7b63b33..59fede13 100644 --- a/darwin/entry.m +++ b/darwin/entry.m @@ -49,7 +49,7 @@ uiEntry *uiNewEntry(void) 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); diff --git a/darwin/label.m b/darwin/label.m index f2fad18a..c8768bfc 100644 --- a/darwin/label.m +++ b/darwin/label.m @@ -33,7 +33,7 @@ uiLabel *uiNewLabel(const char *text) 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); diff --git a/darwin/tab.m b/darwin/tab.m index 84f93d0e..339e8f9b 100644 --- a/darwin/tab.m +++ b/darwin/tab.m @@ -8,12 +8,21 @@ struct tab { uiTab t; NSTabView *tabview; + NSMutableArray *pages; }; static void destroy(void *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); } @@ -37,6 +46,7 @@ static void tabAddPage(uiTab *tt, const char *name, uiControl *child) content = uiNewParent(0); uiParentSetMainControl(content, child); + [t->pages addObject:[NSValue valueWithPointer:content]]; i = [[NSTabViewItem alloc] initWithIdentifier:nil]; [i setLabel:toNSString(name)]; @@ -44,19 +54,28 @@ static void tabAddPage(uiTab *tt, const char *name, uiControl *child) [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) { struct tab *t; 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); // also good for NSTabView (same selector and everything) setStandardControlFont((NSControl *) (t->tabview)); + t->pages = [NSMutableArray new]; + uiControl(t)->PreferredSize = preferredSize; uiTab(t)->AddPage = tabAddPage;