libui/darwin/tab.m

66 lines
1.4 KiB
Mathematica
Raw Normal View History

// 12 april 2015
#import "uipriv_darwin.h"
// TODO
// - verify margins against extra space around the tab
// - free child containers properly
2015-04-17 17:45:17 -05:00
struct tab {
uiTab t;
NSTabView *tabview;
};
2015-04-17 17:45:17 -05:00
static void destroy(void *data)
{
2015-04-17 17:45:17 -05:00
struct tab *t = (struct tab *) data;
2015-04-17 17:45:17 -05:00
uiFree(t);
}
// the default new control implementation uses -sizeToFit, which we don't have with NSTabView
// fortunately, we do have -minimumSize
static void preferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
{
2015-04-17 17:45:17 -05:00
struct tab *t = (struct tab *) c;
NSSize s;
2015-04-17 17:45:17 -05:00
s = [t->tabview minimumSize];
*width = (intmax_t) (s.width);
*height = (intmax_t) (s.height);
}
2015-04-17 17:45:17 -05:00
static void tabAddPage(uiTab *tt, const char *name, uiControl *child)
{
2015-04-17 17:45:17 -05:00
struct tab *t = (struct tab *) tt;
uiParent *content;
NSTabViewItem *i;
content = uiNewParent(0);
uiParentSetMainControl(content, child);
i = [[NSTabViewItem alloc] initWithIdentifier:nil];
[i setLabel:toNSString(name)];
[i setView:((NSView *) uiParentHandle(content))];
2015-04-17 17:45:17 -05:00
[t->tabview addTabViewItem:i];
}
uiTab *uiNewTab(void)
{
2015-04-17 17:45:17 -05:00
struct tab *t;
2015-04-17 17:45:17 -05:00
t = uiNew(struct tab);
2015-04-17 17:45:17 -05:00
uiDarwinNewControl(uiControl(t), [NSTabView class], NO, NO, destroy, NULL);
t->tabview = (NSTabView *) VIEW(t);
// also good for NSTabView (same selector and everything)
2015-04-17 17:45:17 -05:00
setStandardControlFont((NSControl *) (t->tabview));
uiControl(t)->PreferredSize = preferredSize;
uiTab(t)->AddPage = tabAddPage;
2015-04-17 17:45:17 -05:00
return uiTab(t);
}