summaryrefslogtreecommitdiff
path: root/new/container_darwin.m
blob: bdfab908596183af2a1286461fe3c50f56cad277 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// 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
@implementation uiContainer {
	BOOL uimargined;
}

uiLogObjCClassAllocations

- (void)viewDidMoveToSuperview
{
	if ([self superview] == nil)
		if (self.child != NULL) {
			uiControlDestroy(self.child);
			self.child = NULL;
		}
	[super viewDidMoveToSuperview];
}

- (void)setFrameSize:(NSSize)s
{
	[super setFrameSize:s];
	[self uiUpdateNow];
}

// These are based on measurements from Interface Builder.
// TODO reverify these against /layout rects/, not /frame rects/
#define macXMargin 20
#define macYMargin 20
#define macXPadding 8
#define macYPadding 8

- (void)uiUpdateNow
{
	uiSizing d;
	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;
	}
	d.xPadding = macXPadding;
	d.yPadding = macYPadding;
	(*(self.child->resize))(self.child, x, y, width, height, &d);
}

// TODO margined

- (void)uiSetMargined:(BOOL)margined
{
	self->uimargined = margined;
	[self uiUpdateNow];
}

@end

void updateParent(uintptr_t parent)
{
	uiContainer *c;

	if (parent == 0)
		return;
	c = (uiContainer *) parent;
	[c uiUpdateNow];
}