Finished the new uiTab. That just leaves the new uiBox.

This commit is contained in:
Pietro Gagliardi 2016-05-12 00:43:52 -04:00
parent 1f96ee9b54
commit 89425f0fa7
3 changed files with 43 additions and 61 deletions

View File

@ -23,6 +23,7 @@ static void uiGroupDestroy(uiControl *c)
removeConstraints(g);
if (g->child != NULL) {
uiControlSetParent(g->child, NULL);
uiDarwinControlSetSuperview(uiDarwinControl(g->child), nil);
uiControlDestroy(g->child);
}
[g->box release];
@ -71,7 +72,7 @@ static void groupRelayout(uiGroup *g)
uiDarwinControlDefaultHugsTrailingEdge(uiGroup, box)
uiDarwinControlDefaultHugsBottom(uiGroup, box)
static void uiWindowChildEdgeHuggingChanged(uiDarwinControl *c)
static void uiGroupChildEdgeHuggingChanged(uiDarwinControl *c)
{
uiGroup *g = uiGroup(c);

View File

@ -49,7 +49,7 @@ struct uiTab {
- (void)establishChildConstraints
{
[self removeChildConstraints]
[self removeChildConstraints];
if (self.c == NULL)
return;
singleChildConstraintsEstablish(&(self->constraints),
@ -88,19 +88,14 @@ static void uiTabDestroy(uiControl *c)
while ([t->tabview numberOfTabViewItems] != 0)
[t->tabview removeTabViewItem:[t->tabview tabViewItemAtIndex:0]];
// then destroy all the children
[t->pages enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
NSValue *v = (NSValue *) obj;
uiControl *c;
c = (uiControl *) [v pointerValue];
uiControlSetParent(c, NULL);
uiControlDestroy(c);
}];
for (page in t->pages) {
[page removeChildConstraints];
uiControlSetParent(page.c, NULL);
uiDarwinControlSetSuperview(uiDarwinControl(page.c), nil);
uiControlDestroy(page.c);
}
// and finally destroy ourselves
[t->pageIDs release];
[t->pages release];
[t->views release];
[t->margined release];
[t->tabview release];
uiFreeControl(uiControl(t));
}
@ -123,28 +118,20 @@ uiDarwinControlDefaultSetSuperview(uiTab, tabview)
static void tabRelayout(uiTab *t)
{
NSUInteger i;
tabPage *page;
if ([t->pages count] == 0)
return;
for (i = 0; i < [t->pages count]; i++) {
NSValue *v;
uiControl *child;
uiDarwinControl *cc;
NSView *view, *childView;
NSNumber *margined;
for (page in t->pages)
[page establishChildConstraints];
}
v = (NSValue *) [t->pages objectAtIndex:i];
child = (uiControl *) [v pointerValue];
view = (NSView *) [t->views objectAtIndex:i];
childView = (NSView *) uiControlHandle(child);
margined = (NSNumber *) [t->margined objectAtIndex:i];
// first lay out the child
cc = uiDarwinControl(child);
//TODO (*(cc->Relayout))(cc);
// then lay out the page
//TODO layoutSingleView(view, childView, [margined intValue], @"uiTab");
}
uiDarwinControlDefaultHugsTrailingEdge(uiTab, tabview)
uiDarwinControlDefaultHugsBottom(uiTab, tabview)
static void uiTabChildEdgeHuggingChanged(uiDarwinControl *c)
{
uiTab *t = uiTab(c);
tabRelayout(t);
}
void uiTabAppend(uiTab *t, const char *name, uiControl *child)
@ -154,51 +141,51 @@ void uiTabAppend(uiTab *t, const char *name, uiControl *child)
void uiTabInsertAt(uiTab *t, const char *name, uintmax_t n, uiControl *child)
{
NSView *childView;
boxPage *page;
NSView *view;
NSTabViewItem *i;
NSObject *pageID;
uiControlSetParent(child, uiControl(t));
childView = (NSView *) uiControlHandle(child);
view = [[NSView alloc] initWithFrame:NSZeroRect];
// TODO if we turn off the autoresizing mask, nothing shows up; didn't this get documented somewhere?
uiDarwinControlSetSuperview(uiDarwinControl(child), view);
uiDarwinControlSyncEnableState(uiDarwinControl(child), uiControlEnabledToUser(uiControl(t)));
[t->pages insertObject:[NSValue valueWithPointer:child] atIndex:n];
[t->views insertObject:view atIndex:n];
[t->margined insertObject:[NSNumber numberWithInt:0] atIndex:n];
// 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];
[t->pageIDs insertObject:pageID atIndex:n];
page = [[tabPage alloc] initWithView:view pageID:pageID];
page.c = child;
[t->pages insertObject:page atIndex:n];
[page release]; // no need for initial reference
i = [[NSTabViewItem alloc] initWithIdentifier:pageID];
[i setLabel:toNSString(name)];
[i setView:view];
[t->tabview insertTabViewItem:i atIndex:n];
// TODO release i?
[pageID release]; // no need for initial reference
[view release];
tabRelayout(t);
}
void uiTabDelete(uiTab *t, uintmax_t n)
{
NSValue *v;
tabPage *page;
uiControl *child;
NSView *childView;
NSTabViewItem *i;
v = (NSValue *) [t->pages objectAtIndex:n];
child = (uiControl *) [v pointerValue];
page = (tabPage *) [t->pages objectAtIndex:n];
child = page.c;
[page removeChildConstraints];
[t->pages removeObjectAtIndex:n];
[t->views removeObjectAtIndex:n];
[t->margined removeObjectAtIndex:n];
childView = (NSView *) uiControlHandle(child);
[childView removeFromSuperview];
uiControlSetParent(child, NULL);
uiDarwinControlSetSuperview(uiDarwinControl(child), nil);
i = [t->tabview tabViewItemAtIndex:n];
[t->tabview removeTabViewItem:i];
@ -213,19 +200,18 @@ uintmax_t uiTabNumPages(uiTab *t)
int uiTabMargined(uiTab *t, uintmax_t n)
{
NSNumber *v;
tabPage *page;
v = (NSNumber *) [t->margined objectAtIndex:n];
return [v intValue];
page = (tabPage *) [t->pages objectAtIndex:n];
return [page isMargined];
}
void uiTabSetMargined(uiTab *t, uintmax_t n, int margined)
{
NSNumber *v;
tabPage *page;
v = [NSNumber numberWithInt:margined];
[t->margined replaceObjectAtIndex:n withObject:v];
tabRelayout(t);
page = (tabPage *) [t->pages objectAtIndex:n];
[page setMargined:margined];
}
uiTab *uiNewTab(void)
@ -239,9 +225,6 @@ uiTab *uiNewTab(void)
uiDarwinSetControlFont((NSControl *) (t->tabview), NSRegularControlSize);
t->pages = [NSMutableArray new];
t->views = [NSMutableArray new];
t->margined = [NSMutableArray new];
t->pageIDs = [NSMutableArray new];
return t;
}

View File

@ -83,15 +83,13 @@ static void removeConstraints(uiWindow *w)
static void uiWindowDestroy(uiControl *c)
{
uiWindow *w = uiWindow(c);
NSView *childView;
// hide the window
[w->window orderOut:w->window];
removeConstraints(w);
if (w->child != NULL) {
childView = (NSView *) uiControlHandle(w->child);
[childView removeFromSuperview];
uiControlSetParent(w->child, NULL);
uiDarwinControlSetSuperview(uiDarwinControl(w->child), nil);
uiControlDestroy(w->child);
}
[windowDelegate unregisterWindow:w];