Migrated darwin/tab.m. Now to test...

This commit is contained in:
Pietro Gagliardi 2015-04-17 18:45:17 -04:00
parent bac2ce130e
commit 7b0004cfff
1 changed files with 20 additions and 28 deletions

View File

@ -5,38 +5,33 @@
// - verify margins against extra space around the tab // - verify margins against extra space around the tab
// - free child containers properly // - free child containers properly
@interface uiNSTabView : NSTabView struct tab {
@property uiTab *uiT; uiTab t;
@end NSTabView *tabview;
};
@implementation uiNSTabView static void destroy(void *data)
- (void)viewDidMoveToSuperview
{ {
// TODO free all tabs explicitly struct tab *t = (struct tab *) data;
if (uiDarwinControlFreeWhenAppropriate(uiControl(self.uiT), [self superview]))
self.uiT = NULL;
[super viewDidMoveToSuperview];
}
@end uiFree(t);
}
// the default new control implementation uses -sizeToFit, which we don't have with NSTabView // the default new control implementation uses -sizeToFit, which we don't have with NSTabView
// fortunately, we do have -minimumSize // fortunately, we do have -minimumSize
static void preferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height) static void preferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
{ {
uiNSTabView *tv; struct tab *t = (struct tab *) c;
NSSize s; NSSize s;
tv = (uiNSTabView *) uiControlHandle(c); s = [t->tabview minimumSize];
s = [tv minimumSize];
*width = (intmax_t) (s.width); *width = (intmax_t) (s.width);
*height = (intmax_t) (s.height); *height = (intmax_t) (s.height);
} }
static void tabAddPage(uiTab *t, const char *name, uiControl *child) static void tabAddPage(uiTab *tt, const char *name, uiControl *child)
{ {
uiNSTabView *tv; struct tab *t = (struct tab *) tt;
uiParent *content; uiParent *content;
NSTabViewItem *i; NSTabViewItem *i;
@ -46,28 +41,25 @@ static void tabAddPage(uiTab *t, const char *name, uiControl *child)
i = [[NSTabViewItem alloc] initWithIdentifier:nil]; i = [[NSTabViewItem alloc] initWithIdentifier:nil];
[i setLabel:toNSString(name)]; [i setLabel:toNSString(name)];
[i setView:((NSView *) uiParentHandle(content))]; [i setView:((NSView *) uiParentHandle(content))];
tv = (uiNSTabView *) uiControlHandle(uiControl(t)); [t->tabview addTabViewItem:i];
[tv addTabViewItem:i];
} }
uiTab *uiNewTab(void) uiTab *uiNewTab(void)
{ {
uiTab *t; struct tab *t;
uiNSTabView *tv;
t = uiNew(uiTab); t = uiNew(struct tab);
uiDarwinNewControl(uiControl(t), [uiNSTabView class], NO, NO); uiDarwinNewControl(uiControl(t), [NSTabView class], NO, NO, destroy, NULL);
tv = (uiNSTabView *) uiControlHandle(uiControl(t));
t->tabview = (NSTabView *) VIEW(t);
// also good for NSTabView (same selector and everything) // also good for NSTabView (same selector and everything)
setStandardControlFont((NSControl *) tv); setStandardControlFont((NSControl *) (t->tabview));
uiControl(t)->PreferredSize = preferredSize; uiControl(t)->PreferredSize = preferredSize;
uiTab(t)->AddPage = tabAddPage; uiTab(t)->AddPage = tabAddPage;
tv.uiT = t; return uiTab(t);
return tv.uiT;
} }