Allowed uiGroups and uiTabs to have no and NULL controls with defined behavior on OS X. Actually added the test code this time.
This commit is contained in:
parent
0e785d886b
commit
fd9f6cea6a
16
darwin/tab.m
16
darwin/tab.m
|
@ -58,6 +58,7 @@ struct uiTab {
|
|||
{
|
||||
[self removeChildConstraints];
|
||||
if (self.c == NULL)
|
||||
// TODO make sure we need the margins
|
||||
return;
|
||||
singleChildConstraintsEstablish(&(self->constraints),
|
||||
self->view, [self childView],
|
||||
|
@ -97,10 +98,12 @@ static void uiTabDestroy(uiControl *c)
|
|||
// then destroy all the children
|
||||
for (page in t->pages) {
|
||||
[page removeChildConstraints];
|
||||
if (page.c != NULL) {
|
||||
uiControlSetParent(page.c, NULL);
|
||||
uiDarwinControlSetSuperview(uiDarwinControl(page.c), nil);
|
||||
uiControlDestroy(page.c);
|
||||
}
|
||||
}
|
||||
// and finally destroy ourselves
|
||||
[t->pages release];
|
||||
[t->tabview release];
|
||||
|
@ -187,23 +190,26 @@ void uiTabInsertAt(uiTab *t, const char *name, uintmax_t n, uiControl *child)
|
|||
NSTabViewItem *i;
|
||||
NSObject *pageID;
|
||||
|
||||
uiControlSetParent(child, uiControl(t));
|
||||
|
||||
view = [[NSView alloc] initWithFrame:NSZeroRect];
|
||||
// TODO if we turn off the autoresizing mask, nothing shows up; didn't this get documented somewhere?
|
||||
// don't turn off the autoresizing mask on view; if we do, nothing shows up
|
||||
if (child != NULL) {
|
||||
uiControlSetParent(child, uiControl(t));
|
||||
uiDarwinControlSetSuperview(uiDarwinControl(child), view);
|
||||
uiDarwinControlSyncEnableState(uiDarwinControl(child), uiControlEnabledToUser(uiControl(t)));
|
||||
}
|
||||
|
||||
// the documentation says these can be nil but the headers say these must not be; let's be safe and make them non-nil anyway
|
||||
pageID = [NSObject new];
|
||||
page = [[tabPage alloc] initWithView:view pageID:pageID];
|
||||
page.c = child;
|
||||
|
||||
if (page.c != NULL) {
|
||||
// don't hug, just in case we're a stretchy tab
|
||||
page.oldHorzHuggingPri = uiDarwinControlHuggingPriority(uiDarwinControl(page.c), NSLayoutConstraintOrientationHorizontal);
|
||||
page.oldVertHuggingPri = uiDarwinControlHuggingPriority(uiDarwinControl(page.c), NSLayoutConstraintOrientationVertical);
|
||||
uiDarwinControlSetHuggingPriority(uiDarwinControl(page.c), NSLayoutPriorityDefaultLow, NSLayoutConstraintOrientationHorizontal);
|
||||
uiDarwinControlSetHuggingPriority(uiDarwinControl(page.c), NSLayoutPriorityDefaultLow, NSLayoutConstraintOrientationVertical);
|
||||
}
|
||||
|
||||
[t->pages insertObject:page atIndex:n];
|
||||
[page release]; // no need for initial reference
|
||||
|
@ -228,15 +234,19 @@ void uiTabDelete(uiTab *t, uintmax_t n)
|
|||
|
||||
page = (tabPage *) [t->pages objectAtIndex:n];
|
||||
|
||||
if (page.c != NULL) {
|
||||
uiDarwinControlSetHuggingPriority(uiDarwinControl(page.c), page.oldHorzHuggingPri, NSLayoutConstraintOrientationHorizontal);
|
||||
uiDarwinControlSetHuggingPriority(uiDarwinControl(page.c), page.oldVertHuggingPri, NSLayoutConstraintOrientationVertical);
|
||||
}
|
||||
|
||||
child = page.c;
|
||||
[page removeChildConstraints];
|
||||
[t->pages removeObjectAtIndex:n];
|
||||
|
||||
if (child != NULL) {
|
||||
uiControlSetParent(child, NULL);
|
||||
uiDarwinControlSetSuperview(uiDarwinControl(child), nil);
|
||||
}
|
||||
|
||||
i = [t->tabview tabViewItemAtIndex:n];
|
||||
[t->tabview removeTabViewItem:i];
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
// 14 may 2016
|
||||
#include "test.h"
|
||||
|
||||
// TODO add a test for childless windows
|
||||
|
||||
static uiGroup *newg(const char *n, int s)
|
||||
{
|
||||
uiGroup *g;
|
||||
|
||||
g = uiNewGroup(n);
|
||||
if (s)
|
||||
uiGroupSetChild(g, NULL);
|
||||
return g;
|
||||
}
|
||||
|
||||
static uiTab *newt(int tt)
|
||||
{
|
||||
uiTab *t;
|
||||
|
||||
t = uiNewTab();
|
||||
if (tt)
|
||||
uiTabAppend(t, "Test", NULL);
|
||||
return t;
|
||||
}
|
||||
|
||||
uiBox *makePage11(void)
|
||||
{
|
||||
uiBox *page11;
|
||||
uiBox *ns;
|
||||
uiBox *s;
|
||||
|
||||
page11 = newHorizontalBox();
|
||||
|
||||
ns = newVerticalBox();
|
||||
uiBoxAppend(ns, uiControl(newg("", 0)), 0);
|
||||
uiBoxAppend(ns, uiControl(newg("", 1)), 0);
|
||||
uiBoxAppend(ns, uiControl(newg("Group", 0)), 0);
|
||||
uiBoxAppend(ns, uiControl(newg("Group", 1)), 0);
|
||||
uiBoxAppend(ns, uiControl(newt(0)), 0);
|
||||
uiBoxAppend(ns, uiControl(newt(1)), 0);
|
||||
uiBoxAppend(page11, uiControl(ns), 1);
|
||||
|
||||
s = newVerticalBox();
|
||||
uiBoxAppend(s, uiControl(newg("", 0)), 1);
|
||||
uiBoxAppend(s, uiControl(newg("", 1)), 1);
|
||||
uiBoxAppend(s, uiControl(newg("Group", 0)), 1);
|
||||
uiBoxAppend(s, uiControl(newg("Group", 1)), 1);
|
||||
uiBoxAppend(s, uiControl(newt(0)), 1);
|
||||
uiBoxAppend(s, uiControl(newt(1)), 1);
|
||||
uiBoxAppend(page11, uiControl(s), 1);
|
||||
|
||||
return page11;
|
||||
}
|
Loading…
Reference in New Issue