Added provisions for proper window redraw on Window.SetParent() and implemented them on Mac OS X; still untested.
This commit is contained in:
parent
e989c953fa
commit
e9c6d96d2d
|
@ -11,7 +11,7 @@ import "C"
|
||||||
|
|
||||||
type widgetbase struct {
|
type widgetbase struct {
|
||||||
id C.id
|
id C.id
|
||||||
parentw *window
|
notnew bool // to prevent unparenting a new control
|
||||||
floating bool
|
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
|
// these few methods are embedded by all the various Controls since they all will do the same thing
|
||||||
|
|
||||||
func (w *widgetbase) unparent() {
|
func (w *widgetbase) unparent() {
|
||||||
if w.parentw != nil {
|
if w.notnew {
|
||||||
|
// redrawing the old window handled by C.unparent()
|
||||||
C.unparent(w.id)
|
C.unparent(w.id)
|
||||||
w.floating = true
|
w.floating = true
|
||||||
w.parentw = nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *widgetbase) parent(win *window) {
|
func (w *widgetbase) parent(win *window) {
|
||||||
|
// redrawing the new window handled by C.parent()
|
||||||
C.parent(w.id, win.id, toBOOL(w.floating))
|
C.parent(w.id, win.id, toBOOL(w.floating))
|
||||||
w.floating = false
|
w.floating = false
|
||||||
w.parentw = win
|
w.notnew = true
|
||||||
}
|
}
|
||||||
|
|
||||||
type button struct {
|
type button struct {
|
||||||
|
|
|
@ -11,8 +11,13 @@
|
||||||
|
|
||||||
void unparent(id control)
|
void unparent(id control)
|
||||||
{
|
{
|
||||||
|
NSWindow *old;
|
||||||
|
|
||||||
[toNSView(control) retain]; // save from being freed when released by the removal selector below
|
[toNSView(control) retain]; // save from being freed when released by the removal selector below
|
||||||
|
old = [toNSView(control) window];
|
||||||
[toNSView(control) removeFromSuperview];
|
[toNSView(control) removeFromSuperview];
|
||||||
|
// redraw since we changed controls
|
||||||
|
windowRedraw((id) old);
|
||||||
}
|
}
|
||||||
|
|
||||||
void parent(id control, id parentid, BOOL floating)
|
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)];
|
[[toNSWindow(parentid) contentView] addSubview:toNSView(control)];
|
||||||
if (floating) // previously unparented
|
if (floating) // previously unparented
|
||||||
[toNSView(control) release];
|
[toNSView(control) release];
|
||||||
|
// redraw since we changed controls
|
||||||
|
windowRedraw(parentid);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void setStandardControlFont(id control)
|
static inline void setStandardControlFont(id control)
|
||||||
|
|
|
@ -45,6 +45,5 @@ func (w *window) SetControl(control Control) {
|
||||||
control.unparent()
|
control.unparent()
|
||||||
control.parent(w)
|
control.parent(w)
|
||||||
w.child = control
|
w.child = control
|
||||||
// TODO trigger a resize to let the new control actually be shown
|
// each call to unparent() and parent() will cause the old/new parents to be redrawn; we don't have to worry about that here
|
||||||
// TODO do the same with control's old parent, if any
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,12 +65,9 @@ void windowSetTitle(id win, const char * title)
|
||||||
|
|
||||||
void windowShow(id win)
|
void windowShow(id win)
|
||||||
{
|
{
|
||||||
goWindowDelegate *d;
|
|
||||||
|
|
||||||
[toNSWindow(win) makeKeyAndOrderFront:toNSWindow(win)];
|
[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
|
// 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];
|
windowRedraw(win);
|
||||||
[d doWindowResize:win];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void windowHide(id win)
|
void windowHide(id win)
|
||||||
|
@ -82,3 +79,12 @@ void windowClose(id win)
|
||||||
{
|
{
|
||||||
[toNSWindow(win) close];
|
[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];
|
||||||
|
}
|
Loading…
Reference in New Issue