2015-04-28 15:33:16 -05:00
|
|
|
// 28 april 2015
|
|
|
|
#import "uipriv_darwin.h"
|
|
|
|
|
|
|
|
@interface containerView : NSView {
|
|
|
|
uiContainer *c;
|
|
|
|
uiContainer *parent;
|
|
|
|
int hidden;
|
|
|
|
}
|
|
|
|
@property uiContainer *containerParent;
|
|
|
|
@property int containerHidden;
|
|
|
|
- (void)setContainer:(uiContainer *)cc;
|
|
|
|
- (void)containerUpdate;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation containerView
|
|
|
|
|
|
|
|
- (void)setContainer:(uiContainer *)cc
|
|
|
|
{
|
|
|
|
self->c = cc;
|
|
|
|
}
|
|
|
|
|
|
|
|
// These are based on measurements from Interface Builder.
|
|
|
|
// These seem to be based on Auto Layout constants, but I don't see an API that exposes these...
|
|
|
|
// This one is 8 for most pairs of controls that I've tried; the only difference is between two pushbuttons, where it's 12...
|
|
|
|
#define macXPadding 8
|
|
|
|
// Likewise, this one appears to be 12 for pairs of push buttons...
|
|
|
|
#define macYPadding 8
|
|
|
|
|
|
|
|
- (void)containerUpdate
|
|
|
|
{
|
|
|
|
uiSizing d;
|
|
|
|
intmax_t x, y, width, height;
|
|
|
|
|
|
|
|
x = [self bounds].origin.x;
|
|
|
|
y = [self bounds].origin.y;
|
|
|
|
width = [self bounds].size.width;
|
|
|
|
height = [self bounds].size.height;
|
|
|
|
d.xPadding = macXPadding;
|
|
|
|
d.yPadding = macYPadding;
|
|
|
|
uiContainerResizeChildren(self->c, x, y, width, height, &d);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setFrameSize:(NSSize)s
|
|
|
|
{
|
|
|
|
[super setFrameSize:s];
|
|
|
|
[self containerUpdate];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
// subclasses override this and call back here when all children are destroyed
|
|
|
|
static void containerDestroy(uiControl *cc)
|
|
|
|
{
|
|
|
|
containerView *c = (containerView *) (cc->Internal);
|
|
|
|
|
|
|
|
if (c.containerParent != NULL)
|
|
|
|
complain("attempt to destroy uiContainer %p while it has a parent", cc);
|
|
|
|
[c release]; // release our initial reference, which destroys the view
|
|
|
|
}
|
|
|
|
|
|
|
|
static uintptr_t containerHandle(uiControl *cc)
|
|
|
|
{
|
|
|
|
containerView *c = (containerView *) (cc->Internal);
|
|
|
|
|
|
|
|
return (uintptr_t) c;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void containerSetParent(uiControl *cc, uiContainer *parent)
|
|
|
|
{
|
|
|
|
containerView *c = (containerView *) (cc->Internal);
|
|
|
|
uiContainer *oldparent;
|
|
|
|
NSView *newcontainer;
|
|
|
|
|
|
|
|
oldparent = c.containerParent;
|
|
|
|
c.containerParent = parent;
|
|
|
|
if (oldparent != NULL)
|
|
|
|
[c removeFromSuperview];
|
|
|
|
if (c.containerParent != NULL) {
|
|
|
|
newcontainer = (NSView *) uiControlHandle(uiControl(c.containerParent));
|
|
|
|
[newcontainer addSubview:c];
|
|
|
|
}
|
|
|
|
if (oldparent != NULL)
|
|
|
|
uiContainerUpdate(oldparent);
|
|
|
|
if (c.containerParent != NULL)
|
|
|
|
uiContainerUpdate(c.containerParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void containerResize(uiControl *cc, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d)
|
|
|
|
{
|
|
|
|
containerView *c = (containerView *) (cc->Internal);
|
|
|
|
NSRect r;
|
|
|
|
|
|
|
|
r.origin.x = x;
|
2015-04-29 13:21:12 -05:00
|
|
|
// mac os x coordinate system has (0,0) in the lower-left
|
|
|
|
r.origin.y = ([[c superview] bounds].size.height - height) - y;
|
2015-04-28 15:33:16 -05:00
|
|
|
r.size.width = width;
|
|
|
|
r.size.height = height;
|
|
|
|
// we can safely use setFrame here since we have no alignment rect to worry about
|
|
|
|
[c setFrame:r];
|
|
|
|
}
|
|
|
|
|
|
|
|
static int containerVisible(uiControl *cc)
|
|
|
|
{
|
|
|
|
containerView *c = (containerView *) (cc->Internal);
|
|
|
|
|
|
|
|
return !c.containerHidden;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void containerShow(uiControl *cc)
|
|
|
|
{
|
|
|
|
containerView *c = (containerView *) (cc->Internal);
|
|
|
|
|
|
|
|
[c setHidden:NO];
|
2015-04-28 20:35:29 -05:00
|
|
|
// hidden controls don't count in boxes and grids
|
2015-04-29 13:25:34 -05:00
|
|
|
// be sure to change the hidden variable FIRST, otherwise immediate resizes like on OS X don't work right
|
|
|
|
c.containerHidden = 0;
|
2015-04-28 20:35:29 -05:00
|
|
|
if (c.containerParent != NULL)
|
|
|
|
uiContainerUpdate(c.containerParent);
|
2015-04-28 15:33:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void containerHide(uiControl *cc)
|
|
|
|
{
|
|
|
|
containerView *c = (containerView *) (cc->Internal);
|
|
|
|
|
|
|
|
[c setHidden:YES];
|
2015-04-29 13:25:34 -05:00
|
|
|
c.containerHidden = 1;
|
2015-04-28 20:35:29 -05:00
|
|
|
if (c.containerParent != NULL)
|
|
|
|
uiContainerUpdate(c.containerParent);
|
2015-04-28 15:33:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void containerEnable(uiControl *cc)
|
|
|
|
{
|
|
|
|
containerView *c = (containerView *) (cc->Internal);
|
2015-05-04 00:14:18 -05:00
|
|
|
uiControlSysFuncParams p;
|
2015-04-28 15:33:16 -05:00
|
|
|
|
2015-05-04 00:14:18 -05:00
|
|
|
p.Func = uiDarwinSysFuncContainerEnable;
|
|
|
|
uiControlSysFunc(cc, &p);
|
2015-04-28 15:33:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void containerDisable(uiControl *cc)
|
|
|
|
{
|
|
|
|
containerView *c = (containerView *) (cc->Internal);
|
2015-05-04 00:14:18 -05:00
|
|
|
uiControlSysFuncParams p;
|
2015-04-28 15:33:16 -05:00
|
|
|
|
2015-05-04 00:14:18 -05:00
|
|
|
p.Func = uiDarwinSysFuncContainerDisable;
|
|
|
|
uiControlSysFunc(cc, &p);
|
2015-04-28 15:33:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void containerUpdate(uiContainer *cc)
|
|
|
|
{
|
|
|
|
containerView *c = (containerView *) (uiControl(cc)->Internal);
|
|
|
|
|
|
|
|
[c containerUpdate];
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiMakeContainer(uiContainer *cc)
|
|
|
|
{
|
|
|
|
containerView *c;
|
|
|
|
|
|
|
|
c = [[containerView alloc] initWithFrame:NSZeroRect];
|
|
|
|
[c setContainer:cc];
|
|
|
|
// keep a reference to our container so it stays alive when reparented
|
|
|
|
[c retain];
|
|
|
|
|
|
|
|
uiControl(cc)->Internal = c;
|
|
|
|
uiControl(cc)->Destroy = containerDestroy;
|
|
|
|
uiControl(cc)->Handle = containerHandle;
|
|
|
|
uiControl(cc)->SetParent = containerSetParent;
|
|
|
|
// PreferredSize() is provided by subclasses
|
|
|
|
uiControl(cc)->Resize = containerResize;
|
|
|
|
uiControl(cc)->Visible = containerVisible;
|
|
|
|
uiControl(cc)->Show = containerShow;
|
|
|
|
uiControl(cc)->Hide = containerHide;
|
|
|
|
uiControl(cc)->Enable = containerEnable;
|
|
|
|
uiControl(cc)->Disable = containerDisable;
|
2015-05-04 00:14:18 -05:00
|
|
|
// SysFunc() is provided by subclasses
|
2015-04-28 15:33:16 -05:00
|
|
|
|
|
|
|
// ResizeChildren() is provided by subclasses
|
|
|
|
uiContainer(cc)->Update = containerUpdate;
|
|
|
|
}
|