summaryrefslogtreecommitdiff
path: root/redo/container_darwin.m
blob: 0a598c66dcff511444a460c0f21c26d6ef1fb89c (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
// 4 august 2014

#include "objc_darwin.h"
#include "_cgo_export.h"
#include <Cocoa/Cocoa.h>

#define toNSView(x) ((NSView *) (x))

// 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
@interface goContainerView : NSView {
@public
	void *gocontainer;
}
@end

@implementation goContainerView

- (void)setFrameSize:(NSSize)s
{
	[super setFrameSize:s];
	containerResized(self->gocontainer, (intptr_t) s.width, (intptr_t) s.height);
}

@end

id newContainerView(void *gocontainer)
{
	goContainerView *c;

	c = [[goContainerView alloc] initWithFrame:NSZeroRect];
	c->gocontainer = gocontainer;
	return (id) c;
}

void moveControl(id c, intptr_t x, intptr_t y, intptr_t width, intptr_t height)
{
	[toNSView(c) setFrame:NSMakeRect((CGFloat) x, (CGFloat) y, (CGFloat) width, (CGFloat) height)];
}