2015-07-11 15:56:37 -05:00
|
|
|
// 11 june 2015
|
2015-07-11 16:02:01 -05:00
|
|
|
#include "uipriv_darwin.h"
|
2015-07-11 15:56:37 -05:00
|
|
|
|
2015-07-24 14:42:10 -05:00
|
|
|
// TODO rewrite this whole file to take advantage of what we used to call bin functions
|
|
|
|
|
2015-07-11 15:56:37 -05:00
|
|
|
struct tab {
|
|
|
|
uiTab t;
|
2015-07-24 14:42:10 -05:00
|
|
|
NSTabView *tabview;
|
|
|
|
NSMutableArray *pages;
|
|
|
|
NSMutableArray *margined;
|
|
|
|
void (*baseCommitDestroy)(uiControl *);
|
2015-07-11 15:56:37 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
uiDefineControlType(uiTab, uiTypeTab, struct tab)
|
|
|
|
|
2015-07-24 14:42:10 -05:00
|
|
|
static void tabCommitDestroy(uiControl *c)
|
|
|
|
{
|
|
|
|
struct tab *t = (struct tab *) c;
|
|
|
|
|
|
|
|
// first destroy all tab pages so we can destroy all the bins
|
|
|
|
while ([t->tabview numberOfTabViewItems] != 0)
|
|
|
|
[t->tabview removeTabViewItem:[t->tabview tabViewItemAtIndex:0]];
|
|
|
|
// then destroy all the bins, destroying children in the process
|
|
|
|
// the above loop serves the purpose of binSetParent()
|
|
|
|
[t->pages enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
|
|
|
NSValue *v = (NSValue *) obj;
|
2015-07-29 11:28:13 -05:00
|
|
|
uiControl *bin;
|
2015-07-24 14:42:10 -05:00
|
|
|
|
2015-07-29 11:28:13 -05:00
|
|
|
bin = (uiControl *) [v pointerValue];
|
|
|
|
binSetChild(bin, NULL);
|
|
|
|
// TODO destroy the child
|
|
|
|
uiControlDestroy(uiControl(bin));
|
2015-07-24 14:42:10 -05:00
|
|
|
}];
|
|
|
|
// and finally destroy ourselves
|
|
|
|
[t->pages release];
|
|
|
|
[t->margined release];
|
|
|
|
(*(t->baseCommitDestroy))(uiControl(t));
|
|
|
|
}
|
|
|
|
|
2015-07-11 15:56:37 -05:00
|
|
|
static uintptr_t tabHandle(uiControl *c)
|
|
|
|
{
|
|
|
|
struct tab *t = (struct tab *) c;
|
|
|
|
|
2015-07-24 14:42:10 -05:00
|
|
|
return (uintptr_t) (t->tabview);
|
|
|
|
}
|
|
|
|
|
|
|
|
// the default new control implementation uses -sizeToFit, which we don't have with NSTabView
|
|
|
|
// fortunately, we do have -minimumSize
|
|
|
|
static void tabPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
|
|
|
|
{
|
|
|
|
struct tab *t = (struct tab *) c;
|
|
|
|
NSSize s;
|
|
|
|
|
|
|
|
s = [t->tabview minimumSize];
|
|
|
|
*width = (intmax_t) (s.width);
|
|
|
|
*height = (intmax_t) (s.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tabContainerUpdate(uiControl *c)
|
|
|
|
{
|
|
|
|
struct tab *t = (struct tab *) c;
|
|
|
|
|
|
|
|
(*(t->baseEnable))(uiControl(t));
|
2015-07-29 11:28:13 -05:00
|
|
|
// TODO enumerate over page CONTROLS instead
|
2015-07-24 14:42:10 -05:00
|
|
|
[t->pages enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
|
|
|
NSValue *v = (NSValue *) obj;
|
2015-07-29 11:28:13 -05:00
|
|
|
uiControl *bin;
|
2015-07-24 14:42:10 -05:00
|
|
|
|
2015-07-29 11:28:13 -05:00
|
|
|
bin = (uiControl *) [v pointerValue];
|
2015-07-24 14:42:10 -05:00
|
|
|
// TODO get the right function
|
2015-07-29 11:28:13 -05:00
|
|
|
uiContainerUpdate(uiControl(bin));
|
2015-07-24 14:42:10 -05:00
|
|
|
}];
|
2015-07-11 15:56:37 -05:00
|
|
|
}
|
|
|
|
|
2015-07-24 14:42:10 -05:00
|
|
|
// TODO merge with InsertAt
|
2015-07-11 15:56:37 -05:00
|
|
|
static void tabAppend(uiTab *tt, const char *name, uiControl *child)
|
|
|
|
{
|
|
|
|
struct tab *t = (struct tab *) tt;
|
2015-07-29 11:28:13 -05:00
|
|
|
uiControl *page;
|
2015-07-24 14:42:10 -05:00
|
|
|
NSTabViewItem *i;
|
|
|
|
|
|
|
|
page = newBin();
|
2015-07-29 11:28:13 -05:00
|
|
|
binSetChild(page, child);
|
2015-07-24 14:42:10 -05:00
|
|
|
[t->pages addObject:[NSValue valueWithPointer:page]];
|
|
|
|
[t->margined addObject:[NSNumber numberWithInt:0]];
|
|
|
|
|
|
|
|
i = [[NSTabViewItem alloc] initWithIdentifier:nil];
|
|
|
|
[i setLabel:toNSString(name)];
|
|
|
|
[i setView:((NSView *) uiControlHandle(uiControl(page)))];
|
|
|
|
[t->tabview addTabViewItem:i];
|
2015-07-11 15:56:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void tabInsertAt(uiTab *tt, const char *name, uintmax_t n, uiControl *child)
|
|
|
|
{
|
|
|
|
struct tab *t = (struct tab *) tt;
|
2015-07-29 11:28:13 -05:00
|
|
|
uiControl *page;
|
2015-07-24 14:42:10 -05:00
|
|
|
NSTabViewItem *i;
|
|
|
|
|
|
|
|
page = newBin();
|
2015-07-29 11:28:13 -05:00
|
|
|
binSetChild(page, child);
|
2015-07-24 14:42:10 -05:00
|
|
|
[t->pages insertObject:[NSValue valueWithPointer:page] atIndex:n];
|
|
|
|
[t->margined insertObject:[NSNumber numberWithInt:0] atIndex:n];
|
|
|
|
|
|
|
|
i = [[NSTabViewItem alloc] initWithIdentifier:nil];
|
|
|
|
[i setLabel:toNSString(name)];
|
|
|
|
[i setView:((NSView *) uiControlHandle(uiControl(page)))];
|
|
|
|
[t->tabview insertTabViewItem:i atIndex:n];
|
2015-07-11 15:56:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void tabDelete(uiTab *tt, uintmax_t n)
|
|
|
|
{
|
|
|
|
struct tab *t = (struct tab *) tt;
|
2015-07-24 14:42:10 -05:00
|
|
|
NSValue *v;
|
2015-07-29 11:28:13 -05:00
|
|
|
uiControl *page;
|
2015-07-24 14:42:10 -05:00
|
|
|
NSTabViewItem *i;
|
|
|
|
|
|
|
|
v = (NSValue *) [t->pages objectAtIndex:n];
|
|
|
|
page = (uiBin *) [v pointerValue];
|
|
|
|
[t->pages removeObjectAtIndex:n];
|
|
|
|
[t->margined removeObjectAtIndex:n];
|
2015-07-11 15:56:37 -05:00
|
|
|
|
2015-07-24 14:42:10 -05:00
|
|
|
// make sure the children of the tab aren't destroyed
|
2015-07-29 11:28:13 -05:00
|
|
|
binSetChild(page, NULL);
|
2015-07-24 14:42:10 -05:00
|
|
|
|
|
|
|
// remove the bin from the tab view
|
|
|
|
// this serves the purpose of uiBinRemoveOSParent()
|
|
|
|
i = [t->tabview tabViewItemAtIndex:n];
|
|
|
|
[t->tabview removeTabViewItem:i];
|
|
|
|
|
|
|
|
// then destroy the bin
|
|
|
|
uiControlDestroy(uiControl(page));
|
2015-07-11 15:56:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static uintmax_t tabNumPages(uiTab *tt)
|
|
|
|
{
|
|
|
|
struct tab *t = (struct tab *) tt;
|
|
|
|
|
2015-07-24 14:42:10 -05:00
|
|
|
return [t->pages count];
|
2015-07-11 15:56:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static int tabMargined(uiTab *tt, uintmax_t n)
|
|
|
|
{
|
|
|
|
struct tab *t = (struct tab *) tt;
|
2015-07-24 14:42:10 -05:00
|
|
|
NSNumber *v;
|
2015-07-11 15:56:37 -05:00
|
|
|
|
2015-07-24 14:42:10 -05:00
|
|
|
v = (NSNumber *) [t->margined objectAtIndex:n];
|
|
|
|
return [v intValue];
|
2015-07-11 15:56:37 -05:00
|
|
|
}
|
|
|
|
|
2015-07-24 14:42:10 -05:00
|
|
|
// These are based on measurements from Interface Builder.
|
|
|
|
// These seem to be based on Auto Layout constants, but I don't see an API that exposes these...
|
|
|
|
#define tabLeftMargin 17
|
|
|
|
#define tabTopMargin 3
|
|
|
|
#define tabRightMargin 17
|
|
|
|
#define tabBottomMargin 17
|
|
|
|
|
|
|
|
// notes:
|
|
|
|
// top margin of a tab to its parent should be 12, not 20
|
|
|
|
// our system doesn't allow this...
|
|
|
|
|
2015-07-11 15:56:37 -05:00
|
|
|
static void tabSetMargined(uiTab *tt, uintmax_t n, int margined)
|
|
|
|
{
|
|
|
|
struct tab *t = (struct tab *) tt;
|
2015-07-24 14:42:10 -05:00
|
|
|
NSNumber *v;
|
|
|
|
NSValue *pagev;
|
|
|
|
uiBin *page;
|
|
|
|
|
|
|
|
v = [NSNumber numberWithInt:margined];
|
|
|
|
[t->margined replaceObjectAtIndex:n withObject:v];
|
|
|
|
pagev = (NSValue *) [t->pages objectAtIndex:n];
|
|
|
|
page = (uiBin *) [pagev pointerValue];
|
2015-07-29 11:28:13 -05:00
|
|
|
/* TODO
|
2015-07-24 14:42:10 -05:00
|
|
|
if ([v intValue])
|
|
|
|
uiBinSetMargins(page, tabLeftMargin, tabTopMargin, tabRightMargin, tabBottomMargin);
|
|
|
|
else
|
|
|
|
uiBinSetMargins(page, 0, 0, 0, 0);
|
2015-07-29 11:28:13 -05:00
|
|
|
*/
|
2015-07-11 15:56:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
uiTab *uiNewTab(void)
|
|
|
|
{
|
|
|
|
struct tab *t;
|
|
|
|
|
|
|
|
t = (struct tab *) MAKE_CONTROL_INSTANCE(uiTypeTab());
|
|
|
|
|
2015-07-24 14:42:10 -05:00
|
|
|
t->tabview = [[NSTabView alloc] initWithFrame:NSZeroRect];
|
|
|
|
// also good for NSTabView (same selector and everything)
|
|
|
|
uiDarwinMakeSingleViewControl(uiControl(t), t->tabview, YES);
|
|
|
|
|
|
|
|
t->pages = [NSMutableArray new];
|
|
|
|
t->margined = [NSMutableArray new];
|
2015-07-11 15:56:37 -05:00
|
|
|
|
|
|
|
uiControl(t)->Handle = tabHandle;
|
2015-07-24 14:42:10 -05:00
|
|
|
uiControl(t)->PreferredSize = tabPreferredSize;
|
|
|
|
t->baseCommitDestroy = uiControl(t)->CommitDestroy;
|
|
|
|
uiControl(t)->CommitDestroy = tabCommitDestroy;
|
|
|
|
uiControl(t)->ContainerUpdate = tabContainerUpdate;
|
2015-07-11 15:56:37 -05:00
|
|
|
|
|
|
|
uiTab(t)->Append = tabAppend;
|
|
|
|
uiTab(t)->InsertAt = tabInsertAt;
|
|
|
|
uiTab(t)->Delete = tabDelete;
|
|
|
|
uiTab(t)->NumPages = tabNumPages;
|
|
|
|
uiTab(t)->Margined = tabMargined;
|
|
|
|
uiTab(t)->SetMargined = tabSetMargined;
|
|
|
|
|
|
|
|
return uiTab(t);
|
|
|
|
}
|