2015-04-07 14:45:00 -05:00
|
|
|
// 4 august 2014
|
|
|
|
#import "uipriv_darwin.h"
|
|
|
|
|
|
|
|
// calling -[className] on the content views of NSWindow, NSTabItem, and NSBox all return NSView, so I'm assuming I just need to override these
|
|
|
|
// fornunately:
|
|
|
|
// - NSWindow resizing calls -[setFrameSize:] (but not -[setFrame:])
|
|
|
|
// - NSTab resizing calls both -[setFrame:] and -[setFrameSIze:] on the current tab
|
|
|
|
// - NSTab switching tabs calls both -[setFrame:] and -[setFrameSize:] on the new tab
|
|
|
|
// so we just override setFrameSize:
|
|
|
|
// thanks to mikeash and JtRip in irc.freenode.net/#macdev
|
2015-04-09 14:10:12 -05:00
|
|
|
@implementation uiContainer {
|
|
|
|
BOOL uimargined;
|
|
|
|
}
|
2015-04-07 14:45:00 -05:00
|
|
|
|
2015-04-08 14:53:50 -05:00
|
|
|
uiLogObjCClassAllocations
|
|
|
|
|
|
|
|
- (void)viewDidMoveToSuperview
|
|
|
|
{
|
|
|
|
if ([self superview] == nil)
|
|
|
|
if (self.child != NULL) {
|
|
|
|
uiControlDestroy(self.child);
|
|
|
|
self.child = NULL;
|
|
|
|
}
|
|
|
|
[super viewDidMoveToSuperview];
|
|
|
|
}
|
2015-04-07 23:26:49 -05:00
|
|
|
|
2015-04-07 14:45:00 -05:00
|
|
|
- (void)setFrameSize:(NSSize)s
|
2015-04-08 18:14:22 -05:00
|
|
|
{
|
|
|
|
[super setFrameSize:s];
|
|
|
|
[self uiUpdateNow];
|
|
|
|
}
|
|
|
|
|
2015-04-09 14:10:12 -05:00
|
|
|
// These are based on measurements from Interface Builder.
|
|
|
|
// TODO reverify these against /layout rects/, not /frame rects/
|
|
|
|
#define macXMargin 20
|
|
|
|
#define macYMargin 20
|
2015-04-09 14:30:24 -05:00
|
|
|
#define macXPadding 8
|
|
|
|
#define macYPadding 8
|
2015-04-09 14:10:12 -05:00
|
|
|
|
2015-04-08 18:14:22 -05:00
|
|
|
- (void)uiUpdateNow
|
2015-04-07 14:45:00 -05:00
|
|
|
{
|
|
|
|
uiSizing d;
|
2015-04-09 14:10:12 -05:00
|
|
|
intmax_t x, y, width, height;
|
|
|
|
|
|
|
|
if (self.child == NULL)
|
|
|
|
return;
|
|
|
|
x = [self bounds].origin.x;
|
|
|
|
y = [self bounds].origin.y;
|
|
|
|
width = [self bounds].size.width;
|
|
|
|
height = [self bounds].size.height;
|
|
|
|
if (self->uimargined) {
|
|
|
|
x += macXMargin;
|
|
|
|
y += macYMargin;
|
|
|
|
width -= 2 * macXMargin;
|
|
|
|
height -= 2 * macYMargin;
|
|
|
|
}
|
2015-04-09 14:30:24 -05:00
|
|
|
d.xPadding = macXPadding;
|
|
|
|
d.yPadding = macYPadding;
|
2015-04-09 14:10:12 -05:00
|
|
|
(*(self.child->resize))(self.child, x, y, width, height, &d);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO margined
|
2015-04-07 14:45:00 -05:00
|
|
|
|
2015-04-09 14:10:12 -05:00
|
|
|
- (void)uiSetMargined:(BOOL)margined
|
|
|
|
{
|
|
|
|
self->uimargined = margined;
|
|
|
|
[self uiUpdateNow];
|
2015-04-07 14:45:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
2015-04-08 18:14:22 -05:00
|
|
|
|
|
|
|
void updateParent(uintptr_t parent)
|
|
|
|
{
|
|
|
|
uiContainer *c;
|
|
|
|
|
|
|
|
if (parent == 0)
|
|
|
|
return;
|
|
|
|
c = (uiContainer *) parent;
|
|
|
|
[c uiUpdateNow];
|
|
|
|
}
|