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
|
|
|
|
@property uiControl *uiC;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation uiNSTabView
|
|
|
|
|
|
|
|
- (void)viewDidMoveToSuperview
|
|
|
|
{
|
2015-04-13 11:53:05 -05:00
|
|
|
// TODO free all tabs explicitly
|
2015-04-12 14:46:58 -05:00
|
|
|
if (uiDarwinControlFreeWhenAppropriate(self.uiC, [self superview]))
|
|
|
|
self.uiC = NULL;
|
|
|
|
[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);
|
|
|
|
}
|
|
|
|
|
|
|
|
uiControl *uiNewTab(void)
|
|
|
|
{
|
|
|
|
uiControl *c;
|
|
|
|
uiNSTabView *t;
|
|
|
|
|
|
|
|
c = uiDarwinNewControl([uiNSTabView class], NO, NO);
|
|
|
|
c->preferredSize = preferredSize;
|
|
|
|
t = (uiNSTabView *) uiControlHandle(c);
|
|
|
|
t.uiC = c;
|
|
|
|
|
|
|
|
// also good for NSTabView (same selector and everything)
|
|
|
|
setStandardControlFont((NSControl *) t);
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiTabAddPage(uiControl *c, const char *name, uiControl *child)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
uiParentSetChild(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-12 14:46:58 -05:00
|
|
|
tv = (uiNSTabView *) uiControlHandle(c);
|
|
|
|
[tv addTabViewItem:i];
|
|
|
|
}
|