2015-04-12 14:46:58 -05:00
|
|
|
// 12 april 2015
|
|
|
|
#import "uipriv_darwin.h"
|
|
|
|
|
2015-04-12 15:00:09 -05:00
|
|
|
// TODO
|
|
|
|
// - verify margins against extra space around the tab
|
2015-04-12 14:46:58 -05:00
|
|
|
|
2015-04-17 17:45:17 -05:00
|
|
|
struct tab {
|
|
|
|
uiTab t;
|
|
|
|
NSTabView *tabview;
|
2015-04-19 10:41:23 -05:00
|
|
|
NSMutableArray *pages;
|
2015-04-17 17:45:17 -05:00
|
|
|
};
|
2015-04-12 14:46:58 -05:00
|
|
|
|
2015-04-17 17:45:17 -05:00
|
|
|
static void destroy(void *data)
|
2015-04-12 14:46:58 -05:00
|
|
|
{
|
2015-04-17 17:45:17 -05:00
|
|
|
struct tab *t = (struct tab *) data;
|
2015-04-12 14:46:58 -05:00
|
|
|
|
2015-04-19 10:41:23 -05:00
|
|
|
[t->pages enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
|
|
|
NSValue *v = (NSValue *) obj;
|
|
|
|
uiParent *p;
|
|
|
|
|
|
|
|
p = (uiParent *) [v pointerValue];
|
|
|
|
uiParentDestroy(p);
|
|
|
|
}];
|
|
|
|
[t->pages release];
|
2015-04-17 17:45:17 -05:00
|
|
|
uiFree(t);
|
|
|
|
}
|
2015-04-12 14:46:58 -05:00
|
|
|
|
|
|
|
// 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;
|
2015-04-12 14:46:58 -05:00
|
|
|
NSSize s;
|
|
|
|
|
2015-04-17 17:45:17 -05:00
|
|
|
s = [t->tabview minimumSize];
|
2015-04-12 14:46:58 -05:00
|
|
|
*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-12 14:46:58 -05:00
|
|
|
{
|
2015-04-17 17:45:17 -05:00
|
|
|
struct tab *t = (struct tab *) tt;
|
2015-04-13 11:53:05 -05:00
|
|
|
uiParent *content;
|
2015-04-12 14:46:58 -05:00
|
|
|
NSTabViewItem *i;
|
|
|
|
|
2015-04-13 11:53:05 -05:00
|
|
|
content = uiNewParent(0);
|
2015-04-17 12:43:01 -05:00
|
|
|
uiParentSetMainControl(content, child);
|
2015-04-19 10:41:23 -05:00
|
|
|
[t->pages addObject:[NSValue valueWithPointer:content]];
|
2015-04-12 14:46:58 -05:00
|
|
|
|
|
|
|
i = [[NSTabViewItem alloc] initWithIdentifier:nil];
|
|
|
|
[i setLabel:toNSString(name)];
|
2015-04-13 11:53:05 -05:00
|
|
|
[i setView:((NSView *) uiParentHandle(content))];
|
2015-04-17 17:45:17 -05:00
|
|
|
[t->tabview addTabViewItem:i];
|
2015-04-12 14:46:58 -05:00
|
|
|
}
|
2015-04-16 13:50:05 -05:00
|
|
|
|
2015-04-19 10:41:23 -05:00
|
|
|
static void tabDeletePage(uiTab *tt, uintmax_t n)
|
|
|
|
{
|
|
|
|
struct tab *t = (struct tab *) tt;
|
2015-04-19 10:53:31 -05:00
|
|
|
NSValue *v;
|
|
|
|
uiParent *p;
|
|
|
|
NSTabViewItem *i;
|
2015-04-19 10:41:23 -05:00
|
|
|
|
2015-04-19 10:53:31 -05:00
|
|
|
v = (NSValue *) [t->pages objectAtIndex:n];
|
|
|
|
p = (uiParent *) [v pointerValue];
|
2015-04-19 10:41:23 -05:00
|
|
|
[t->pages removeObjectAtIndex:n];
|
2015-04-19 10:53:31 -05:00
|
|
|
// make sure the children of the tab aren't destroyed
|
|
|
|
uiParentSetMainControl(p, NULL);
|
|
|
|
|
|
|
|
// TODO negotiate lifetimes better
|
|
|
|
i = [t->tabview tabViewItemAtIndex:n];
|
|
|
|
[t->tabview removeTabViewItem:i];
|
2015-04-19 10:41:23 -05:00
|
|
|
}
|
|
|
|
|
2015-04-16 13:50:05 -05:00
|
|
|
uiTab *uiNewTab(void)
|
|
|
|
{
|
2015-04-17 17:45:17 -05:00
|
|
|
struct tab *t;
|
2015-04-16 13:50:05 -05:00
|
|
|
|
2015-04-17 17:45:17 -05:00
|
|
|
t = uiNew(struct tab);
|
2015-04-16 14:08:49 -05:00
|
|
|
|
2015-04-19 10:41:23 -05:00
|
|
|
uiDarwinNewControl(uiControl(t), [NSTabView class], NO, NO, destroy, t);
|
2015-04-17 17:45:17 -05:00
|
|
|
|
|
|
|
t->tabview = (NSTabView *) VIEW(t);
|
2015-04-16 13:50:05 -05:00
|
|
|
|
|
|
|
// also good for NSTabView (same selector and everything)
|
2015-04-17 17:45:17 -05:00
|
|
|
setStandardControlFont((NSControl *) (t->tabview));
|
2015-04-16 13:50:05 -05:00
|
|
|
|
2015-04-19 10:41:23 -05:00
|
|
|
t->pages = [NSMutableArray new];
|
|
|
|
|
2015-04-16 13:50:05 -05:00
|
|
|
uiControl(t)->PreferredSize = preferredSize;
|
|
|
|
|
|
|
|
uiTab(t)->AddPage = tabAddPage;
|
2015-04-19 10:53:31 -05:00
|
|
|
uiTab(t)->DeletePage = tabDeletePage;
|
2015-04-16 13:50:05 -05:00
|
|
|
|
2015-04-17 17:45:17 -05:00
|
|
|
return uiTab(t);
|
2015-04-16 13:50:05 -05:00
|
|
|
}
|