Migrated darwin/tab.m. Now to test...
This commit is contained in:
parent
bac2ce130e
commit
7b0004cfff
48
darwin/tab.m
48
darwin/tab.m
|
@ -5,38 +5,33 @@
|
|||
// - verify margins against extra space around the tab
|
||||
// - free child containers properly
|
||||
|
||||
@interface uiNSTabView : NSTabView
|
||||
@property uiTab *uiT;
|
||||
@end
|
||||
struct tab {
|
||||
uiTab t;
|
||||
NSTabView *tabview;
|
||||
};
|
||||
|
||||
@implementation uiNSTabView
|
||||
|
||||
- (void)viewDidMoveToSuperview
|
||||
static void destroy(void *data)
|
||||
{
|
||||
// TODO free all tabs explicitly
|
||||
if (uiDarwinControlFreeWhenAppropriate(uiControl(self.uiT), [self superview]))
|
||||
self.uiT = NULL;
|
||||
[super viewDidMoveToSuperview];
|
||||
}
|
||||
struct tab *t = (struct tab *) data;
|
||||
|
||||
@end
|
||||
uiFree(t);
|
||||
}
|
||||
|
||||
// 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;
|
||||
struct tab *t = (struct tab *) c;
|
||||
NSSize s;
|
||||
|
||||
tv = (uiNSTabView *) uiControlHandle(c);
|
||||
s = [tv minimumSize];
|
||||
s = [t->tabview minimumSize];
|
||||
*width = (intmax_t) (s.width);
|
||||
*height = (intmax_t) (s.height);
|
||||
}
|
||||
|
||||
static void tabAddPage(uiTab *t, const char *name, uiControl *child)
|
||||
static void tabAddPage(uiTab *tt, const char *name, uiControl *child)
|
||||
{
|
||||
uiNSTabView *tv;
|
||||
struct tab *t = (struct tab *) tt;
|
||||
uiParent *content;
|
||||
NSTabViewItem *i;
|
||||
|
||||
|
@ -46,28 +41,25 @@ static void tabAddPage(uiTab *t, const char *name, uiControl *child)
|
|||
i = [[NSTabViewItem alloc] initWithIdentifier:nil];
|
||||
[i setLabel:toNSString(name)];
|
||||
[i setView:((NSView *) uiParentHandle(content))];
|
||||
tv = (uiNSTabView *) uiControlHandle(uiControl(t));
|
||||
[tv addTabViewItem:i];
|
||||
[t->tabview addTabViewItem:i];
|
||||
}
|
||||
|
||||
uiTab *uiNewTab(void)
|
||||
{
|
||||
uiTab *t;
|
||||
uiNSTabView *tv;
|
||||
struct tab *t;
|
||||
|
||||
t = uiNew(uiTab);
|
||||
t = uiNew(struct tab);
|
||||
|
||||
uiDarwinNewControl(uiControl(t), [uiNSTabView class], NO, NO);
|
||||
tv = (uiNSTabView *) uiControlHandle(uiControl(t));
|
||||
uiDarwinNewControl(uiControl(t), [NSTabView class], NO, NO, destroy, NULL);
|
||||
|
||||
t->tabview = (NSTabView *) VIEW(t);
|
||||
|
||||
// also good for NSTabView (same selector and everything)
|
||||
setStandardControlFont((NSControl *) tv);
|
||||
setStandardControlFont((NSControl *) (t->tabview));
|
||||
|
||||
uiControl(t)->PreferredSize = preferredSize;
|
||||
|
||||
uiTab(t)->AddPage = tabAddPage;
|
||||
|
||||
tv.uiT = t;
|
||||
|
||||
return tv.uiT;
|
||||
return uiTab(t);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue