Fixed up tab.m.
This commit is contained in:
parent
f8fbcb3dfb
commit
459900ffd5
|
@ -4,8 +4,12 @@
|
||||||
struct uiTab {
|
struct uiTab {
|
||||||
uiDarwinControl c;
|
uiDarwinControl c;
|
||||||
NSTabView *tabview;
|
NSTabView *tabview;
|
||||||
NSMutableArray *pages;
|
// TODO either rename all uses of child to page or rename this to children
|
||||||
NSMutableArray *margined;
|
NSMutableArray *pages; // []NSValue<uiControl *>
|
||||||
|
// the views that contain the children's views
|
||||||
|
// these are the views that are assigned to each NSTabViewItem
|
||||||
|
NSMutableArray *views; // []NSView
|
||||||
|
NSMutableArray *margined; // []NSNumber
|
||||||
};
|
};
|
||||||
|
|
||||||
static void onDestroy(uiTab *);
|
static void onDestroy(uiTab *);
|
||||||
|
@ -19,81 +23,73 @@ uiDarwinDefineControlWithOnDestroy(
|
||||||
|
|
||||||
static void onDestroy(uiTab *t)
|
static void onDestroy(uiTab *t)
|
||||||
{
|
{
|
||||||
// first destroy all tab pages so we can destroy all the bins
|
// first remove all tab pages so we can destroy all the children
|
||||||
while ([t->tabview numberOfTabViewItems] != 0)
|
while ([t->tabview numberOfTabViewItems] != 0)
|
||||||
[t->tabview removeTabViewItem:[t->tabview tabViewItemAtIndex:0]];
|
[t->tabview removeTabViewItem:[t->tabview tabViewItemAtIndex:0]];
|
||||||
// then destroy all the bins, destroying children in the process
|
// then destroy all the children
|
||||||
// the above loop serves the purpose of binSetParent()
|
|
||||||
[t->pages enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
[t->pages enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
||||||
NSValue *v = (NSValue *) obj;
|
NSValue *v = (NSValue *) obj;
|
||||||
uiControl *bin;
|
uiControl *c;
|
||||||
|
|
||||||
bin = (uiControl *) [v pointerValue];
|
c = (uiControl *) [v pointerValue];
|
||||||
binSetChild(bin, NULL);
|
uiControlDestroy(c);
|
||||||
// TODO destroy the child
|
|
||||||
uiControlDestroy(uiControl(bin));
|
|
||||||
}];
|
}];
|
||||||
// and finally destroy ourselves
|
// and finally destroy ourselves
|
||||||
[t->pages release];
|
[t->pages release];
|
||||||
|
[t->views release];
|
||||||
[t->margined release];
|
[t->margined release];
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO container update
|
// TODO container update
|
||||||
|
|
||||||
// TODO merge with InsertAt
|
|
||||||
void uiTabAppend(uiTab *t, const char *name, uiControl *child)
|
void uiTabAppend(uiTab *t, const char *name, uiControl *child)
|
||||||
{
|
{
|
||||||
uiControl *page;
|
uiTabInsertAt(t, name, [t->pages count], child);
|
||||||
NSTabViewItem *i;
|
|
||||||
|
|
||||||
page = newBin();
|
|
||||||
binSetChild(page, child);
|
|
||||||
[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];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiTabInsertAt(uiTab *t, const char *name, uintmax_t n, uiControl *child)
|
void uiTabInsertAt(uiTab *t, const char *name, uintmax_t n, uiControl *child)
|
||||||
{
|
{
|
||||||
uiControl *page;
|
NSView *childView;
|
||||||
|
NSView *view;
|
||||||
NSTabViewItem *i;
|
NSTabViewItem *i;
|
||||||
|
|
||||||
page = newBin();
|
uiControlSetParent(child, uiControl(t));
|
||||||
binSetChild(page, child);
|
|
||||||
|
childView = (NSView *) uiControlHandle(child);
|
||||||
|
view = [[NSView alloc] initWithFrame:NSZeroRect];
|
||||||
|
[view addSubview:childView];
|
||||||
|
layoutSingleView(view, childView, 0);
|
||||||
|
|
||||||
[t->pages insertObject:[NSValue valueWithPointer:page] atIndex:n];
|
[t->pages insertObject:[NSValue valueWithPointer:page] atIndex:n];
|
||||||
|
[t->views insertObject:view atIndex:n];
|
||||||
[t->margined insertObject:[NSNumber numberWithInt:0] atIndex:n];
|
[t->margined insertObject:[NSNumber numberWithInt:0] atIndex:n];
|
||||||
|
|
||||||
i = [[NSTabViewItem alloc] initWithIdentifier:nil];
|
i = [[NSTabViewItem alloc] initWithIdentifier:nil];
|
||||||
[i setLabel:toNSString(name)];
|
[i setLabel:toNSString(name)];
|
||||||
[i setView:((NSView *) uiControlHandle(uiControl(page)))];
|
[i setView:view];
|
||||||
[t->tabview insertTabViewItem:i atIndex:n];
|
[t->tabview insertTabViewItem:i atIndex:n];
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiTabDelete(uiTab *t, uintmax_t n)
|
void uiTabDelete(uiTab *t, uintmax_t n)
|
||||||
{
|
{
|
||||||
NSValue *v;
|
NSValue *v;
|
||||||
uiControl *page;
|
uiControl *child;
|
||||||
|
NSView *childView;
|
||||||
NSTabViewItem *i;
|
NSTabViewItem *i;
|
||||||
|
|
||||||
v = (NSValue *) [t->pages objectAtIndex:n];
|
v = (NSValue *) [t->pages objectAtIndex:n];
|
||||||
page = (uiControl *) [v pointerValue];
|
child = (uiControl *) [v pointerValue];
|
||||||
|
|
||||||
[t->pages removeObjectAtIndex:n];
|
[t->pages removeObjectAtIndex:n];
|
||||||
|
[t->views removeObjectAtIndex:n];
|
||||||
[t->margined removeObjectAtIndex:n];
|
[t->margined removeObjectAtIndex:n];
|
||||||
|
|
||||||
// make sure the children of the tab aren't destroyed
|
childView = (NSView *) uiControlHandle(child);
|
||||||
binSetChild(page, NULL);
|
[childView removeFromSuperview];
|
||||||
|
uiControlSetParent(childView, NULL);
|
||||||
|
|
||||||
// remove the bin from the tab view
|
|
||||||
// this serves the purpose of uiControlSetOSParent(bin, NULL)
|
|
||||||
i = [t->tabview tabViewItemAtIndex:n];
|
i = [t->tabview tabViewItemAtIndex:n];
|
||||||
[t->tabview removeTabViewItem:i];
|
[t->tabview removeTabViewItem:i];
|
||||||
|
|
||||||
// then destroy the bin
|
|
||||||
uiControlDestroy(uiControl(page));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uintmax_t uITabNumPages(uiTab *t)
|
uintmax_t uITabNumPages(uiTab *t)
|
||||||
|
@ -109,33 +105,21 @@ int uiTabMargined(uiTab *t, uintmax_t n)
|
||||||
return [v intValue];
|
return [v intValue];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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...
|
|
||||||
|
|
||||||
void uiTabSetMargined(uiTab *t, uintmax_t n, int margined)
|
void uiTabSetMargined(uiTab *t, uintmax_t n, int margined)
|
||||||
{
|
{
|
||||||
NSNumber *v;
|
NSNumber *v;
|
||||||
NSValue *pagev;
|
NSValue *childv;
|
||||||
uiControl *page;
|
uiControl *child;
|
||||||
|
NSView *childView;
|
||||||
|
|
||||||
v = [NSNumber numberWithInt:margined];
|
v = [NSNumber numberWithInt:margined];
|
||||||
[t->margined replaceObjectAtIndex:n withObject:v];
|
[t->margined replaceObjectAtIndex:n withObject:v];
|
||||||
pagev = (NSValue *) [t->pages objectAtIndex:n];
|
|
||||||
page = (uiControl *) [pagev pointerValue];
|
view = (NSView *) [t->views objectAtIndex:n];
|
||||||
/* TODO
|
childv = (NSValue *) [t->pages objectAtIndex:n];
|
||||||
if ([v intValue])
|
child = (uiControl *) [childv pointerValue];
|
||||||
uiBinSetMargins(page, tabLeftMargin, tabTopMargin, tabRightMargin, tabBottomMargin);
|
childView = (NSView *) uiControlHandle(child);
|
||||||
else
|
layoutSingleView(view, childView, margined);
|
||||||
uiBinSetMargins(page, 0, 0, 0, 0);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uiTab *uiNewTab(void)
|
uiTab *uiNewTab(void)
|
||||||
|
@ -149,6 +133,7 @@ uiTab *uiNewTab(void)
|
||||||
uiDarwinSetControlFont((NSControl *) (t->tabview), NSRegularControlSize);
|
uiDarwinSetControlFont((NSControl *) (t->tabview), NSRegularControlSize);
|
||||||
|
|
||||||
t->pages = [NSMutableArray new];
|
t->pages = [NSMutableArray new];
|
||||||
|
t->views = [NSMutableArray new];
|
||||||
t->margined = [NSMutableArray new];
|
t->margined = [NSMutableArray new];
|
||||||
|
|
||||||
uiDarwinFinishNewControl(t, uiTab);
|
uiDarwinFinishNewControl(t, uiTab);
|
||||||
|
|
Loading…
Reference in New Issue