2015-04-12 14:46:58 -05:00
|
|
|
// 12 april 2015
|
|
|
|
#import "uipriv_darwin.h"
|
|
|
|
|
2015-04-12 15:00:09 -05:00
|
|
|
// TODO
|
|
|
|
// - verify margins against extra space around the tab
|
|
|
|
// - free child containers properly
|
2015-04-12 14:46:58 -05:00
|
|
|
|
|
|
|
@interface uiNSTabView : NSTabView
|
2015-04-16 13:50:05 -05:00
|
|
|
@property uiTab *uiT;
|
2015-04-12 14:46:58 -05:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation uiNSTabView
|
|
|
|
|
|
|
|
- (void)viewDidMoveToSuperview
|
|
|
|
{
|
2015-04-13 11:53:05 -05:00
|
|
|
// TODO free all tabs explicitly
|
2015-04-16 13:50:05 -05:00
|
|
|
if (uiDarwinControlFreeWhenAppropriate(uiControl(self.uiT), [self superview]))
|
2015-04-16 14:08:49 -05:00
|
|
|
self.uiT = NULL;
|
2015-04-12 14:46:58 -05:00
|
|
|
[super viewDidMoveToSuperview];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
// the default new control implementation uses -sizeToFit, which we don't have with NSTabView
|
|
|
|
// fortunately, we do have -minimumSize
|
|
|
|
static void preferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
|
|
|
|
{
|
|
|
|
uiNSTabView *tv;
|
|
|
|
NSSize s;
|
|
|
|
|
|
|
|
tv = (uiNSTabView *) uiControlHandle(c);
|
|
|
|
s = [tv minimumSize];
|
|
|
|
*width = (intmax_t) (s.width);
|
|
|
|
*height = (intmax_t) (s.height);
|
|
|
|
}
|
|
|
|
|
2015-04-16 13:50:05 -05:00
|
|
|
static void tabAddPage(uiTab *t, const char *name, uiControl *child)
|
2015-04-12 14:46:58 -05:00
|
|
|
{
|
|
|
|
uiNSTabView *tv;
|
2015-04-13 11:53:05 -05:00
|
|
|
uiParent *content;
|
2015-04-12 14:46:58 -05:00
|
|
|
NSTabViewItem *i;
|
|
|
|
|
2015-04-13 11:53:05 -05:00
|
|
|
content = uiNewParent(0);
|
2015-04-17 12:43:01 -05:00
|
|
|
uiParentSetMainControl(content, child);
|
2015-04-12 14:46:58 -05:00
|
|
|
|
|
|
|
i = [[NSTabViewItem alloc] initWithIdentifier:nil];
|
|
|
|
[i setLabel:toNSString(name)];
|
2015-04-13 11:53:05 -05:00
|
|
|
[i setView:((NSView *) uiParentHandle(content))];
|
2015-04-16 13:50:05 -05:00
|
|
|
tv = (uiNSTabView *) uiControlHandle(uiControl(t));
|
2015-04-12 14:46:58 -05:00
|
|
|
[tv addTabViewItem:i];
|
|
|
|
}
|
2015-04-16 13:50:05 -05:00
|
|
|
|
|
|
|
uiTab *uiNewTab(void)
|
|
|
|
{
|
|
|
|
uiTab *t;
|
|
|
|
uiNSTabView *tv;
|
|
|
|
|
2015-04-16 14:08:49 -05:00
|
|
|
t = uiNew(uiTab);
|
|
|
|
|
2015-04-16 13:50:05 -05:00
|
|
|
uiDarwinNewControl(uiControl(t), [uiNSTabView class], NO, NO);
|
2015-04-16 14:08:49 -05:00
|
|
|
tv = (uiNSTabView *) uiControlHandle(uiControl(t));
|
2015-04-16 13:50:05 -05:00
|
|
|
|
|
|
|
// also good for NSTabView (same selector and everything)
|
|
|
|
setStandardControlFont((NSControl *) tv);
|
|
|
|
|
|
|
|
uiControl(t)->PreferredSize = preferredSize;
|
|
|
|
|
|
|
|
uiTab(t)->AddPage = tabAddPage;
|
|
|
|
|
|
|
|
tv.uiT = t;
|
|
|
|
|
|
|
|
return tv.uiT;
|
|
|
|
}
|