summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-03-09 21:40:14 -0400
committerPietro Gagliardi <[email protected]>2014-03-09 21:40:14 -0400
commit45e07797908a16102952e07ca75a3d3a262ecde1 (patch)
tree006f1e66ed886ee2d765ae8711df9755a17acaef
parent3ff9c7d23378c8fbcdc1eebc97d8e9d0ee64c22c (diff)
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).
-rw-r--r--sysdata.go3
-rw-r--r--sysdata_darwin.go6
-rw-r--r--sysdata_unix.go6
-rw-r--r--sysdata_windows.go49
-rw-r--r--window.go2
5 files changed, 43 insertions, 23 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
+func (s *sysData) firstShow() error {
+ ret := make(chan uiret)
+ defer close(ret)
+ uitask <- &uimsg{
+ call: _showWindow,
+ p: []uintptr{
+ uintptr(s.hwnd),
+ uintptr(nCmdShow),
+ },
+ ret: ret,
}
- show := uintptr(_SW_SHOW)
- if !s.shownAlready {
- show = uintptr(nCmdShow)
+ <-ret
+ 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)
- // TODO figure out how to handle error
uitask <- &uimsg{
call: _showWindow,
- p: []uintptr{uintptr(s.hwnd), show},
+ p: []uintptr{
+ uintptr(s.hwnd),
+ uintptr(_SW_SHOW),
+ },
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
- }
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)
}