From 45e07797908a16102952e07ca75a3d3a262ecde1 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 9 Mar 2014 21:40:14 -0400 Subject: [PATCH] Split sysData.show() into separate show() and firstShow() to accomodate Windows's differing rules for first-time window show; this will also allow me to remove the error returns from sysData.show() and sysData.hide() (later). --- sysdata.go | 3 +++ sysdata_darwin.go | 6 ++++++ sysdata_unix.go | 6 ++++++ sysdata_windows.go | 51 +++++++++++++++++++++++++--------------------- window.go | 2 +- 5 files changed, 44 insertions(+), 24 deletions(-) diff --git a/sysdata.go b/sysdata.go index 8ee6f3e..56313e3 100644 --- a/sysdata.go +++ b/sysdata.go @@ -22,6 +22,9 @@ type cSysData struct { func (c *cSysData) make(initText string, window *sysData) error { panic(runtime.GOOS + " sysData does not define make()") } +func (c *cSysData) firstShow() error { + panic(runtime.GOOS + " sysData does not define firstShow()") +} func (c *cSysData) show() error { panic(runtime.GOOS + " sysData does not define show()") } diff --git a/sysdata_darwin.go b/sysdata_darwin.go index 02e3d8e..057b333 100644 --- a/sysdata_darwin.go +++ b/sysdata_darwin.go @@ -314,6 +314,12 @@ func (s *sysData) make(initText string, window *sysData) error { return nil } +// used for Windows; nothing special needed elsewhere +func (s *sysData) firstShow() error { + s.show() + return nil +} + func (s *sysData) show() error { ret := make(chan struct{}) defer close(ret) diff --git a/sysdata_unix.go b/sysdata_unix.go index c07545a..143a64c 100644 --- a/sysdata_unix.go +++ b/sysdata_unix.go @@ -156,6 +156,12 @@ func (s *sysData) make(initText string, window *sysData) error { return nil } +// used for Windows; nothing special needed elsewhere +func (s *sysData) firstShow() error { + s.show() + return nil +} + func (s *sysData) show() error { ret := make(chan struct{}) defer close(ret) diff --git a/sysdata_windows.go b/sysdata_windows.go index 4b951f2..1619374 100644 --- a/sysdata_windows.go +++ b/sysdata_windows.go @@ -15,7 +15,6 @@ type sysData struct { children map[_HMENU]*sysData nextChildID _HMENU childrenLock sync.Mutex - shownAlready bool } type classData struct { @@ -190,36 +189,42 @@ var ( // if the object is a window, we need to do the following the first time // ShowWindow(hwnd, nCmdShow); // UpdateWindow(hwnd); -// otherwise we go ahead and show the object normally with SW_SHOW -func (s *sysData) show() (err error) { - if s.ctype != c_window { // don't do the init ShowWindow/UpdateWindow chain on non-windows - s.shownAlready = true - } - show := uintptr(_SW_SHOW) - if !s.shownAlready { - show = uintptr(nCmdShow) - } +func (s *sysData) firstShow() error { ret := make(chan uiret) defer close(ret) - // TODO figure out how to handle error uitask <- &uimsg{ call: _showWindow, - p: []uintptr{uintptr(s.hwnd), show}, + p: []uintptr{ + uintptr(s.hwnd), + uintptr(nCmdShow), + }, ret: ret, } <-ret - if !s.shownAlready { - uitask <- &uimsg{ - call: _updateWindow, - p: []uintptr{uintptr(s.hwnd)}, - ret: ret, - } - r := <-ret - if r.ret == 0 { // failure - return fmt.Errorf("error updating window for the first time: %v", r.err) - } - s.shownAlready = true + uitask <- &uimsg{ + call: _updateWindow, + p: []uintptr{uintptr(s.hwnd)}, + ret: ret, } + r := <-ret + if r.ret == 0 { // failure + return fmt.Errorf("error updating window for the first time: %v", r.err) + } + return nil +} + +func (s *sysData) show() (err error) { + ret := make(chan uiret) + defer close(ret) + uitask <- &uimsg{ + call: _showWindow, + p: []uintptr{ + uintptr(s.hwnd), + uintptr(_SW_SHOW), + }, + ret: ret, + } + <-ret return nil } diff --git a/window.go b/window.go index 6a0e6ea..d6c78c6 100644 --- a/window.go +++ b/window.go @@ -90,7 +90,7 @@ func (w *Window) Open(control Control) (err error) { return fmt.Errorf("error setting window size (in Window.Open()): %v", err) } // TODO separate showing? - err = w.sysData.show() + err = w.sysData.firstShow() if err != nil { return fmt.Errorf("error showing window (in Window.Open()): %v", err) }