2015-08-15 16:05:11 -05:00
|
|
|
// 15 august 2015
|
|
|
|
#import "uipriv_darwin.h"
|
|
|
|
|
2016-06-07 22:25:01 -05:00
|
|
|
// TODO need to jiggle on tab change too (second page disabled tab label initially ambiguous)
|
|
|
|
|
2016-05-11 18:11:26 -05:00
|
|
|
@interface tabPage : NSObject {
|
|
|
|
struct singleChildConstraints constraints;
|
|
|
|
int margined;
|
|
|
|
NSView *view; // the NSTabViewItem view itself
|
|
|
|
NSObject *pageID;
|
|
|
|
}
|
|
|
|
@property uiControl *c;
|
2016-05-13 12:28:20 -05:00
|
|
|
@property NSLayoutPriority oldHorzHuggingPri;
|
|
|
|
@property NSLayoutPriority oldVertHuggingPri;
|
2016-05-11 18:11:26 -05:00
|
|
|
- (id)initWithView:(NSView *)v pageID:(NSObject *)o;
|
|
|
|
- (NSView *)childView;
|
|
|
|
- (void)establishChildConstraints;
|
|
|
|
- (void)removeChildConstraints;
|
|
|
|
- (int)isMargined;
|
|
|
|
- (void)setMargined:(int)m;
|
|
|
|
@end
|
2016-04-25 11:52:54 -05:00
|
|
|
|
2015-08-15 16:05:11 -05:00
|
|
|
struct uiTab {
|
|
|
|
uiDarwinControl c;
|
|
|
|
NSTabView *tabview;
|
2016-05-11 18:11:26 -05:00
|
|
|
NSMutableArray *pages;
|
2016-05-12 11:26:43 -05:00
|
|
|
NSLayoutPriority horzHuggingPri;
|
|
|
|
NSLayoutPriority vertHuggingPri;
|
2015-08-15 16:05:11 -05:00
|
|
|
};
|
|
|
|
|
2016-05-11 18:11:26 -05:00
|
|
|
@implementation tabPage
|
|
|
|
|
2016-05-12 00:31:47 -05:00
|
|
|
- (id)initWithView:(NSView *)v pageID:(NSObject *)o
|
2016-05-11 18:11:26 -05:00
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self != nil) {
|
2016-05-24 22:17:08 -05:00
|
|
|
self->view = [v retain];
|
|
|
|
self->pageID = [o retain];
|
2016-05-11 18:11:26 -05:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[self removeChildConstraints];
|
|
|
|
[self->view release];
|
|
|
|
[self->pageID release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSView *)childView
|
|
|
|
{
|
|
|
|
return (NSView *) uiControlHandle(self.c);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)establishChildConstraints
|
|
|
|
{
|
2016-05-11 23:43:52 -05:00
|
|
|
[self removeChildConstraints];
|
2016-05-11 18:11:26 -05:00
|
|
|
if (self.c == NULL)
|
|
|
|
return;
|
|
|
|
singleChildConstraintsEstablish(&(self->constraints),
|
|
|
|
self->view, [self childView],
|
|
|
|
uiDarwinControlHugsTrailingEdge(uiDarwinControl(self.c)),
|
|
|
|
uiDarwinControlHugsBottom(uiDarwinControl(self.c)),
|
|
|
|
self->margined,
|
|
|
|
@"uiTab page");
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)removeChildConstraints
|
|
|
|
{
|
|
|
|
singleChildConstraintsRemove(&(self->constraints), self->view);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int)isMargined
|
|
|
|
{
|
|
|
|
return self->margined;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setMargined:(int)m
|
|
|
|
{
|
|
|
|
self->margined = m;
|
|
|
|
singleChildConstraintsSetMargined(&(self->constraints), self->margined);
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2016-04-25 11:52:54 -05:00
|
|
|
static void uiTabDestroy(uiControl *c)
|
2015-08-15 16:05:11 -05:00
|
|
|
{
|
2016-04-25 11:52:54 -05:00
|
|
|
uiTab *t = uiTab(c);
|
2016-05-11 18:11:26 -05:00
|
|
|
tabPage *page;
|
2016-04-25 11:52:54 -05:00
|
|
|
|
2015-08-15 18:35:36 -05:00
|
|
|
// first remove all tab pages so we can destroy all the children
|
2015-08-15 16:05:11 -05:00
|
|
|
while ([t->tabview numberOfTabViewItems] != 0)
|
|
|
|
[t->tabview removeTabViewItem:[t->tabview tabViewItemAtIndex:0]];
|
2015-08-15 18:35:36 -05:00
|
|
|
// then destroy all the children
|
2016-05-11 23:43:52 -05:00
|
|
|
for (page in t->pages) {
|
|
|
|
[page removeChildConstraints];
|
2016-05-15 12:56:53 -05:00
|
|
|
uiControlSetParent(page.c, NULL);
|
|
|
|
uiDarwinControlSetSuperview(uiDarwinControl(page.c), nil);
|
|
|
|
uiControlDestroy(page.c);
|
2016-05-11 23:43:52 -05:00
|
|
|
}
|
2015-08-15 16:05:11 -05:00
|
|
|
// and finally destroy ourselves
|
|
|
|
[t->pages release];
|
2016-04-25 11:52:54 -05:00
|
|
|
[t->tabview release];
|
|
|
|
uiFreeControl(uiControl(t));
|
2015-08-15 16:05:11 -05:00
|
|
|
}
|
|
|
|
|
2016-04-25 11:52:54 -05:00
|
|
|
uiDarwinControlDefaultHandle(uiTab, tabview)
|
|
|
|
uiDarwinControlDefaultParent(uiTab, tabview)
|
|
|
|
uiDarwinControlDefaultSetParent(uiTab, tabview)
|
|
|
|
uiDarwinControlDefaultToplevel(uiTab, tabview)
|
|
|
|
uiDarwinControlDefaultVisible(uiTab, tabview)
|
|
|
|
uiDarwinControlDefaultShow(uiTab, tabview)
|
|
|
|
uiDarwinControlDefaultHide(uiTab, tabview)
|
|
|
|
uiDarwinControlDefaultEnabled(uiTab, tabview)
|
|
|
|
uiDarwinControlDefaultEnable(uiTab, tabview)
|
|
|
|
uiDarwinControlDefaultDisable(uiTab, tabview)
|
|
|
|
|
2016-05-28 20:17:54 -05:00
|
|
|
static void uiTabSyncEnableState(uiDarwinControl *c, int enabled)
|
|
|
|
{
|
|
|
|
uiTab *t = uiTab(c);
|
|
|
|
tabPage *page;
|
|
|
|
|
|
|
|
if (uiDarwinShouldStopSyncEnableState(uiDarwinControl(t), enabled))
|
|
|
|
return;
|
|
|
|
for (page in t->pages)
|
|
|
|
uiDarwinControlSyncEnableState(uiDarwinControl(page.c), enabled);
|
|
|
|
}
|
2016-04-25 11:52:54 -05:00
|
|
|
|
|
|
|
uiDarwinControlDefaultSetSuperview(uiTab, tabview)
|
2016-05-07 00:34:33 -05:00
|
|
|
|
2016-04-25 12:38:17 -05:00
|
|
|
static void tabRelayout(uiTab *t)
|
2015-08-18 20:14:58 -05:00
|
|
|
{
|
2016-05-11 23:43:52 -05:00
|
|
|
tabPage *page;
|
2015-08-18 20:14:58 -05:00
|
|
|
|
2016-05-11 23:43:52 -05:00
|
|
|
for (page in t->pages)
|
|
|
|
[page establishChildConstraints];
|
2016-05-12 19:18:22 -05:00
|
|
|
// and this gets rid of some weird issues with regards to box alignment
|
|
|
|
jiggleViewLayout(t->tabview);
|
2016-05-11 23:43:52 -05:00
|
|
|
}
|
|
|
|
|
2016-05-12 11:26:43 -05:00
|
|
|
BOOL uiTabHugsTrailingEdge(uiDarwinControl *c)
|
|
|
|
{
|
|
|
|
uiTab *t = uiTab(c);
|
|
|
|
|
|
|
|
return t->horzHuggingPri < NSLayoutPriorityWindowSizeStayPut;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL uiTabHugsBottom(uiDarwinControl *c)
|
|
|
|
{
|
|
|
|
uiTab *t = uiTab(c);
|
|
|
|
|
|
|
|
return t->vertHuggingPri < NSLayoutPriorityWindowSizeStayPut;
|
|
|
|
}
|
2016-05-11 23:43:52 -05:00
|
|
|
|
|
|
|
static void uiTabChildEdgeHuggingChanged(uiDarwinControl *c)
|
|
|
|
{
|
|
|
|
uiTab *t = uiTab(c);
|
|
|
|
|
|
|
|
tabRelayout(t);
|
2015-08-18 20:14:58 -05:00
|
|
|
}
|
|
|
|
|
2016-05-12 11:26:43 -05:00
|
|
|
static NSLayoutPriority uiTabHuggingPriority(uiDarwinControl *c, NSLayoutConstraintOrientation orientation)
|
|
|
|
{
|
|
|
|
uiTab *t = uiTab(c);
|
|
|
|
|
|
|
|
if (orientation == NSLayoutConstraintOrientationHorizontal)
|
|
|
|
return t->horzHuggingPri;
|
|
|
|
return t->vertHuggingPri;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uiTabSetHuggingPriority(uiDarwinControl *c, NSLayoutPriority priority, NSLayoutConstraintOrientation orientation)
|
|
|
|
{
|
|
|
|
uiTab *t = uiTab(c);
|
|
|
|
|
|
|
|
if (orientation == NSLayoutConstraintOrientationHorizontal)
|
|
|
|
t->horzHuggingPri = priority;
|
|
|
|
else
|
|
|
|
t->vertHuggingPri = priority;
|
|
|
|
uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl(t));
|
|
|
|
}
|
|
|
|
|
2016-06-14 09:37:19 -05:00
|
|
|
static void uiTabChildVisibilityChanged(uiDarwinControl *c)
|
|
|
|
{
|
|
|
|
uiTab *t = uiTab(c);
|
|
|
|
|
|
|
|
tabRelayout(t);
|
|
|
|
}
|
|
|
|
|
2015-08-15 16:05:11 -05:00
|
|
|
void uiTabAppend(uiTab *t, const char *name, uiControl *child)
|
|
|
|
{
|
2015-08-15 18:35:36 -05:00
|
|
|
uiTabInsertAt(t, name, [t->pages count], child);
|
2015-08-15 16:05:11 -05:00
|
|
|
}
|
|
|
|
|
2016-06-13 19:55:50 -05:00
|
|
|
void uiTabInsertAt(uiTab *t, const char *name, int n, uiControl *child)
|
2015-08-15 16:05:11 -05:00
|
|
|
{
|
2016-05-12 00:31:47 -05:00
|
|
|
tabPage *page;
|
2015-08-15 18:35:36 -05:00
|
|
|
NSView *view;
|
2015-08-15 16:05:11 -05:00
|
|
|
NSTabViewItem *i;
|
2016-05-01 15:15:54 -05:00
|
|
|
NSObject *pageID;
|
2015-08-15 16:05:11 -05:00
|
|
|
|
2016-05-15 12:56:53 -05:00
|
|
|
uiControlSetParent(child, uiControl(t));
|
|
|
|
|
2016-05-24 22:17:08 -05:00
|
|
|
view = [[[NSView alloc] initWithFrame:NSZeroRect] autorelease];
|
2016-05-28 20:17:54 -05:00
|
|
|
// note: if we turn off the autoresizing mask, nothing shows up
|
2016-05-15 12:56:53 -05:00
|
|
|
uiDarwinControlSetSuperview(uiDarwinControl(child), view);
|
|
|
|
uiDarwinControlSyncEnableState(uiDarwinControl(child), uiControlEnabledToUser(uiControl(t)));
|
2015-08-15 18:35:36 -05:00
|
|
|
|
2016-05-01 15:15:54 -05:00
|
|
|
// 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];
|
2016-05-24 22:17:08 -05:00
|
|
|
page = [[[tabPage alloc] initWithView:view pageID:pageID] autorelease];
|
2016-05-11 23:43:52 -05:00
|
|
|
page.c = child;
|
2016-05-13 12:28:20 -05:00
|
|
|
|
2016-05-15 12:56:53 -05:00
|
|
|
// 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);
|
2016-05-13 12:28:20 -05:00
|
|
|
|
2016-05-11 23:43:52 -05:00
|
|
|
[t->pages insertObject:page atIndex:n];
|
|
|
|
|
2016-05-24 22:17:08 -05:00
|
|
|
i = [[[NSTabViewItem alloc] initWithIdentifier:pageID] autorelease];
|
2018-05-03 21:38:21 -05:00
|
|
|
[i setLabel:uiprivToNSString(name)];
|
2015-08-15 18:35:36 -05:00
|
|
|
[i setView:view];
|
2015-08-15 16:05:11 -05:00
|
|
|
[t->tabview insertTabViewItem:i atIndex:n];
|
2015-08-18 20:14:58 -05:00
|
|
|
|
2016-04-25 11:52:54 -05:00
|
|
|
tabRelayout(t);
|
2015-08-15 16:05:11 -05:00
|
|
|
}
|
|
|
|
|
2016-06-13 19:55:50 -05:00
|
|
|
void uiTabDelete(uiTab *t, int n)
|
2015-08-15 16:05:11 -05:00
|
|
|
{
|
2016-05-11 23:43:52 -05:00
|
|
|
tabPage *page;
|
2015-08-15 18:35:36 -05:00
|
|
|
uiControl *child;
|
2015-08-15 16:05:11 -05:00
|
|
|
NSTabViewItem *i;
|
|
|
|
|
2016-05-11 23:43:52 -05:00
|
|
|
page = (tabPage *) [t->pages objectAtIndex:n];
|
2016-05-13 12:28:20 -05:00
|
|
|
|
2016-05-15 12:56:53 -05:00
|
|
|
uiDarwinControlSetHuggingPriority(uiDarwinControl(page.c), page.oldHorzHuggingPri, NSLayoutConstraintOrientationHorizontal);
|
|
|
|
uiDarwinControlSetHuggingPriority(uiDarwinControl(page.c), page.oldVertHuggingPri, NSLayoutConstraintOrientationVertical);
|
2016-05-13 12:28:20 -05:00
|
|
|
|
2016-05-11 23:43:52 -05:00
|
|
|
child = page.c;
|
|
|
|
[page removeChildConstraints];
|
2015-08-15 16:05:11 -05:00
|
|
|
[t->pages removeObjectAtIndex:n];
|
|
|
|
|
2016-05-15 12:56:53 -05:00
|
|
|
uiControlSetParent(child, NULL);
|
|
|
|
uiDarwinControlSetSuperview(uiDarwinControl(child), nil);
|
2015-08-15 16:05:11 -05:00
|
|
|
|
|
|
|
i = [t->tabview tabViewItemAtIndex:n];
|
|
|
|
[t->tabview removeTabViewItem:i];
|
2016-04-25 11:52:54 -05:00
|
|
|
|
|
|
|
tabRelayout(t);
|
2015-08-15 16:05:11 -05:00
|
|
|
}
|
|
|
|
|
2016-06-13 19:55:50 -05:00
|
|
|
int uiTabNumPages(uiTab *t)
|
2015-08-15 16:05:11 -05:00
|
|
|
{
|
|
|
|
return [t->pages count];
|
|
|
|
}
|
|
|
|
|
2016-06-13 19:55:50 -05:00
|
|
|
int uiTabMargined(uiTab *t, int n)
|
2015-08-15 16:05:11 -05:00
|
|
|
{
|
2016-05-11 23:43:52 -05:00
|
|
|
tabPage *page;
|
2015-08-15 16:05:11 -05:00
|
|
|
|
2016-05-11 23:43:52 -05:00
|
|
|
page = (tabPage *) [t->pages objectAtIndex:n];
|
|
|
|
return [page isMargined];
|
2015-08-15 16:05:11 -05:00
|
|
|
}
|
|
|
|
|
2016-06-13 19:55:50 -05:00
|
|
|
void uiTabSetMargined(uiTab *t, int n, int margined)
|
2015-08-15 16:05:11 -05:00
|
|
|
{
|
2016-05-11 23:43:52 -05:00
|
|
|
tabPage *page;
|
2015-08-15 16:05:11 -05:00
|
|
|
|
2016-05-11 23:43:52 -05:00
|
|
|
page = (tabPage *) [t->pages objectAtIndex:n];
|
|
|
|
[page setMargined:margined];
|
2015-08-15 16:05:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
uiTab *uiNewTab(void)
|
|
|
|
{
|
|
|
|
uiTab *t;
|
|
|
|
|
2016-04-25 11:52:54 -05:00
|
|
|
uiDarwinNewControl(uiTab, t);
|
2015-08-15 16:05:11 -05:00
|
|
|
|
|
|
|
t->tabview = [[NSTabView alloc] initWithFrame:NSZeroRect];
|
|
|
|
// also good for NSTabView (same selector and everything)
|
|
|
|
uiDarwinSetControlFont((NSControl *) (t->tabview), NSRegularControlSize);
|
|
|
|
|
|
|
|
t->pages = [NSMutableArray new];
|
|
|
|
|
2016-05-12 11:26:43 -05:00
|
|
|
// default to low hugging to not hug edges
|
|
|
|
t->horzHuggingPri = NSLayoutPriorityDefaultLow;
|
|
|
|
t->vertHuggingPri = NSLayoutPriorityDefaultLow;
|
|
|
|
|
2015-08-15 16:05:11 -05:00
|
|
|
return t;
|
|
|
|
}
|