diff --git a/redo/container_darwin.go b/redo/container_darwin.go index fd28b4c..1f8a477 100644 --- a/redo/container_darwin.go +++ b/redo/container_darwin.go @@ -10,6 +10,7 @@ import ( import "C" type container struct { + // TODO rename to id view C.id *sizer } @@ -27,5 +28,6 @@ func newContainer(child Control) *container { //export containerResized func containerResized(data unsafe.Pointer, width C.intptr_t, height C.intptr_t) { c := (*container)(unsafe.Pointer(data)) + // the origin of a view's content area is always (0, 0) c.resize(0, 0, int(width), int(height)) } diff --git a/redo/container_darwin.m b/redo/container_darwin.m index 17ada72..8f1e3ac 100644 --- a/redo/container_darwin.m +++ b/redo/container_darwin.m @@ -5,7 +5,11 @@ #include // calling -[className] on the content views of NSWindow, NSTabItem, and NSBox all return NSView, so I'm assuming I just need to override these -// fortunately, in the case of NSTabView, this -[setFrame:] is called when resizing and when changing tabs, so we can indeed use this directly there +// 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: @interface goContainerView : NSView { @public void *gocontainer; @@ -14,11 +18,12 @@ @implementation goContainerView -- (void)setFrame:(NSRect)r +- (void)setFrameSize:(NSSize)s { - [super setFrame:r]; +NSLog(@"setFrameSize %@", NSStringFromSize(s)); + [super setFrameSize:s]; if (self->gocontainer != NULL) - containerResized(self->gocontainer, (intptr_t) r.size.width, (intptr_t) r.size.height); + containerResized(self->gocontainer, (intptr_t) s.width, (intptr_t) s.height); } @end diff --git a/redo/objc_darwin.h b/redo/objc_darwin.h index 28b07e4..703f757 100644 --- a/redo/objc_darwin.h +++ b/redo/objc_darwin.h @@ -23,6 +23,7 @@ extern void issue(void *); /* window_darwin.m */ extern id newWindow(intptr_t, intptr_t); extern void windowSetDelegate(id, void *); +extern void windowSetContentView(id, id); extern const char *windowTitle(id); extern void windowSetTitle(id, const char *); extern void windowShow(id); diff --git a/redo/window_darwin.go b/redo/window_darwin.go index 8393cf7..4fa847b 100644 --- a/redo/window_darwin.go +++ b/redo/window_darwin.go @@ -15,7 +15,7 @@ type window struct { closing *event - *sizer + *container } func newWindow(title string, width int, height int, control Control) *window { @@ -26,11 +26,10 @@ func newWindow(title string, width int, height int, control Control) *window { w := &window{ id: id, closing: newEvent(), - sizer: new(sizer), + container: newContainer(control), } - C.windowSetDelegate(id, unsafe.Pointer(w)) - w.child = control - w.child.setParent(&controlParent{C.windowContentView(w.id)}) + C.windowSetDelegate(w.id, unsafe.Pointer(w)) + C.windowSetContentView(w.id, w.container.view) return w } @@ -69,11 +68,3 @@ func windowClosing(xw unsafe.Pointer) C.BOOL { } return C.NO } - -//export windowResized -func windowResized(xw unsafe.Pointer, width C.uintptr_t, height C.uintptr_t) { - w := (*window)(unsafe.Pointer(xw)) - // the origin of the window's content area is always (0, 0) - w.resize(0, 0, int(width), int(height)) - fmt.Printf("new size %d x %d\n", width, height) -} diff --git a/redo/window_darwin.m b/redo/window_darwin.m index 9a02862..f0930f8 100644 --- a/redo/window_darwin.m +++ b/redo/window_darwin.m @@ -5,6 +5,7 @@ #import #define toNSWindow(x) ((NSWindow *) (x)) +#define toNSView(x) ((NSView *) (x)) @interface goWindowDelegate : NSObject { @public @@ -19,11 +20,6 @@ return windowClosing(self->gowin); } -- (void)windowDidResize:(NSNotification *)n -{ - [self doWindowResize:[n object]]; -} - - (void)doWindowResize:(id)win { NSWindow *w; @@ -69,6 +65,11 @@ void windowSetDelegate(id win, void *w) [toNSWindow(win) setDelegate:d]; } +void windowSetContentView(id win, id view) +{ + [toNSWindow(win) setContentView:toNSView(view)]; +} + const char *windowTitle(id win) { return [[toNSWindow(win) title] UTF8String];