2015-07-29 11:28:13 -05:00
|
|
|
// 28 april 2015
|
|
|
|
#import "uipriv_darwin.h"
|
|
|
|
|
|
|
|
// This is a uiControl wrapper a la GtkBin on GTK+.
|
|
|
|
// It serves the function of tabPage on Windows: it allows uiWindow and uiTab to give their children a real uiControl as a parent while not screwing with the internal NSView structure of those uiControls.
|
|
|
|
// It also provides margins.
|
|
|
|
|
|
|
|
struct bin {
|
|
|
|
uiControl c;
|
|
|
|
NSView *view;
|
|
|
|
uiControl *child;
|
|
|
|
int margined;
|
2015-07-29 18:57:23 -05:00
|
|
|
NSArray *hconstraint;
|
|
|
|
NSArray *vconstraint;
|
2015-07-29 11:28:13 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
uiDefineControlType(bin, binType, struct bin)
|
|
|
|
|
|
|
|
static uintptr_t binHandle(uiControl *c)
|
|
|
|
{
|
|
|
|
struct bin *b = (struct bin *) c;
|
|
|
|
|
|
|
|
return (uintptr_t) (b->view);
|
|
|
|
}
|
|
|
|
|
|
|
|
uiControl *newBin(void)
|
|
|
|
{
|
|
|
|
struct bin *b;
|
|
|
|
|
|
|
|
b = (struct bin *) uiNewControl(binType());
|
|
|
|
|
|
|
|
// a simple NSView will do fine
|
|
|
|
b->view = [[NSView alloc] initWithFrame:NSZeroRect];
|
2015-07-29 12:29:32 -05:00
|
|
|
uiDarwinMakeSingleViewControl(uiControl(b), b->view, NO);
|
2015-07-29 11:28:13 -05:00
|
|
|
|
|
|
|
uiControl(b)->Handle = binHandle;
|
|
|
|
|
|
|
|
return uiControl(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
void binSetChild(uiControl *c, uiControl *child)
|
|
|
|
{
|
|
|
|
struct bin *b = (struct bin *) c;
|
2015-07-29 18:57:23 -05:00
|
|
|
NSView *binView, *childView;
|
|
|
|
NSDictionary *views;
|
2015-07-29 11:28:13 -05:00
|
|
|
|
2015-07-29 18:57:23 -05:00
|
|
|
binView = (NSView *) uiControlHandle(uiControl(b));
|
2015-07-29 11:28:13 -05:00
|
|
|
if (b->child != NULL) {
|
2015-07-29 18:57:23 -05:00
|
|
|
[binView removeConstraints:b->hconstraint];
|
|
|
|
[binView removeConstraints:b->vconstraint];
|
|
|
|
[b->hconstraint release];
|
|
|
|
[b->vconstraint release];
|
2015-07-29 11:28:13 -05:00
|
|
|
childView = (NSView *) uiControlHandle(b->child);
|
|
|
|
[childView removeFromSuperview];
|
|
|
|
}
|
|
|
|
b->child = child;
|
|
|
|
if (b->child != NULL) {
|
|
|
|
uiControlSetParent(b->child, uiControl(b));
|
|
|
|
childView = (NSView *) uiControlHandle(b->child);
|
2015-07-29 18:57:23 -05:00
|
|
|
[childView setTranslatesAutoresizingMaskIntoConstraints:NO];
|
|
|
|
views = NSDictionaryOfVariableBindings(childView);
|
|
|
|
b->hconstraint = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[childView]|" options:0 metrics:nil views:views];
|
|
|
|
b->vconstraint = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[childView]|" options:0 metrics:nil views:views];
|
|
|
|
[binView addConstraints:b->hconstraint];
|
|
|
|
[binView addConstraints:b->vconstraint];
|
2015-07-29 11:28:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int binMargined(uiControl *c)
|
|
|
|
{
|
|
|
|
struct bin *b = (struct bin *) c;
|
|
|
|
|
|
|
|
return b->margined;
|
|
|
|
}
|
|
|
|
|
|
|
|
void binSetMargined(uiControl *c, int margined)
|
|
|
|
{
|
|
|
|
struct bin *b = (struct bin *) c;
|
|
|
|
|
|
|
|
b->margined = margined;
|
|
|
|
// TODO use auto layout
|
|
|
|
}
|