diff --git a/redo/controls_darwin.go b/redo/controls_darwin.go index 92eb836..6d5edf8 100644 --- a/redo/controls_darwin.go +++ b/redo/controls_darwin.go @@ -11,7 +11,7 @@ import "C" type widgetbase struct { id C.id - parentw *window + notnew bool // to prevent unparenting a new control floating bool } @@ -24,17 +24,18 @@ func newWidget(id C.id) *widgetbase { // these few methods are embedded by all the various Controls since they all will do the same thing func (w *widgetbase) unparent() { - if w.parentw != nil { + if w.notnew { + // redrawing the old window handled by C.unparent() C.unparent(w.id) w.floating = true - w.parentw = nil } } func (w *widgetbase) parent(win *window) { + // redrawing the new window handled by C.parent() C.parent(w.id, win.id, toBOOL(w.floating)) w.floating = false - w.parentw = win + w.notnew = true } type button struct { diff --git a/redo/controls_darwin.m b/redo/controls_darwin.m index e1cdb8f..5233129 100644 --- a/redo/controls_darwin.m +++ b/redo/controls_darwin.m @@ -11,8 +11,13 @@ void unparent(id control) { + NSWindow *old; + [toNSView(control) retain]; // save from being freed when released by the removal selector below + old = [toNSView(control) window]; [toNSView(control) removeFromSuperview]; + // redraw since we changed controls + windowRedraw((id) old); } void parent(id control, id parentid, BOOL floating) @@ -20,6 +25,8 @@ void parent(id control, id parentid, BOOL floating) [[toNSWindow(parentid) contentView] addSubview:toNSView(control)]; if (floating) // previously unparented [toNSView(control) release]; + // redraw since we changed controls + windowRedraw(parentid); } static inline void setStandardControlFont(id control) diff --git a/redo/window.go b/redo/window.go index 143a875..40e846c 100644 --- a/redo/window.go +++ b/redo/window.go @@ -45,6 +45,5 @@ func (w *window) SetControl(control Control) { control.unparent() control.parent(w) w.child = control - // TODO trigger a resize to let the new control actually be shown - // TODO do the same with control's old parent, if any + // each call to unparent() and parent() will cause the old/new parents to be redrawn; we don't have to worry about that here } diff --git a/redo/window_darwin.m b/redo/window_darwin.m index 4737702..18dee84 100644 --- a/redo/window_darwin.m +++ b/redo/window_darwin.m @@ -65,12 +65,9 @@ void windowSetTitle(id win, const char * title) void windowShow(id win) { - goWindowDelegate *d; - [toNSWindow(win) makeKeyAndOrderFront:toNSWindow(win)]; // calling the above the first time won't emit a size changed event (unlike on Windows and GTK+), so fake one to get the controls laid out properly - d = [toNSWindow(win) delegate]; - [d doWindowResize:win]; + windowRedraw(win); } void windowHide(id win) @@ -82,3 +79,12 @@ void windowClose(id win) { [toNSWindow(win) close]; } + +// fake a resize event under certain conditions; see each invocation for details +void windowRedraw(id win) +{ + goWindowDelegate *d; + + d = [toNSWindow(win) delegate]; + [d doWindowResize:win]; +} \ No newline at end of file