Restored the test program to its full glory. Also removed the whole NSTabViewDelegate song and dance; that seemed to actually introduce bugs (like the tab view going partially offscreen at the top on first ppage switch to Page 2).

This commit is contained in:
Pietro Gagliardi 2015-08-20 17:09:41 -04:00
parent 2aeccf4444
commit 0fd453fa91
2 changed files with 8 additions and 69 deletions

View File

@ -12,60 +12,6 @@ struct uiTab {
NSMutableArray *margined; // []NSNumber
};
// NSTabView handles tab switching interestingly: it /removes the old tab from the view hierarchy outright/
// for some reason that I don't know (TODO), this casues problems for our auto layout, even if we do a depth first recomputation of all of our fitting sizes
// therefore, we have to only update the current tab page
// TODO this doesn't really work...
@interface tabDelegateClass : NSObject<NSTabViewDelegate> {
NSMapTable *tabs;
}
- (void)tabView:(NSTabView *)tv didSelectTabViewItem:(NSTabViewItem *)item;
- (void)registerTab:(uiTab *)b;
- (void)unregisterTab:(uiTab *)b;
@end
@implementation tabDelegateClass
- (id)init
{
self = [super init];
if (self)
self->tabs = newMap();
return self;
}
- (void)dealloc
{
if ([self->tabs count] != 0)
complain("attempt to destroy shared tab delegate but tabs are still registered to it");
[self->tabs release];
[super dealloc];
}
- (void)tabView:(NSTabView *)tv didSelectTabViewItem:(NSTabViewItem *)item
{
uiTab *t;
t = (uiTab *) mapGet(self->tabs, tv);
uiDarwinControlTriggerRelayout(uiDarwinControl(t));
}
- (void)registerTab:(uiTab *)t
{
mapSet(self->tabs, t->tabview, t);
[t->tabview setDelegate:self];
}
- (void)unregisterTab:(uiTab *)t
{
[t->tabview setDelegate:nil];
[self->tabs removeObjectForKey:t->tabview];
}
@end
static tabDelegateClass *tabDelegate = nil;
static void onDestroy(uiTab *);
uiDarwinDefineControlWithOnDestroy(
@ -97,20 +43,20 @@ static void onDestroy(uiTab *t)
// TODO container update
// TODO document our updating all pages here
static void tabRelayout(uiDarwinControl *c)
{
uiTab *t = uiTab(c);
NSUInteger i;
NSValue *v;
uiControl *child;
uiDarwinControl *cc;
NSView *view, *childView;
NSNumber *margined;
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;
v = (NSValue *) [t->pages objectAtIndex:i];
child = (uiControl *) [v pointerValue];
view = (NSView *) [t->views objectAtIndex:i];
@ -211,12 +157,6 @@ uiTab *uiNewTab(void)
t->views = [NSMutableArray new];
t->margined = [NSMutableArray new];
if (tabDelegate == nil) {
tabDelegate = [tabDelegateClass new];
[delegates addObject:tabDelegate];
}
[tabDelegate registerTab:t];
uiDarwinFinishNewControl(t, uiTab);
uiDarwinControl(t)->Relayout = tabRelayout;

View File

@ -77,7 +77,7 @@ int main(int argc, char *argv[])
uiOnShouldQuit(onShouldQuit, w);
mainBox = newHorizontalBox();
// uiWindowSetChild(w, uiControl(mainBox));
uiWindowSetChild(w, uiControl(mainBox));
mainTab = newTab();
uiBoxAppend(mainBox, uiControl(mainTab), 1);
@ -88,8 +88,7 @@ int main(int argc, char *argv[])
makePage1(w);
uiTabAppend(mainTab, "Page 1", uiControl(page1));
// uiTabAppend(mainTab, "Page 2", uiControl(page2));
uiWindowSetChild(w, uiControl(page2));
uiTabAppend(mainTab, "Page 2", uiControl(page2));
uiTabAppend(mainTab, "Empty Page", uiControl(uiNewHorizontalBox()));