And the uitask message fixed was the issue all along. Now it works.

This commit is contained in:
Pietro Gagliardi 2014-02-24 14:16:05 -05:00
parent 4c6ce9639f
commit b166c0f114
2 changed files with 5 additions and 13 deletions

View File

@ -55,39 +55,32 @@ var stdDlgSizes = [nctypes]dlgunits{
}
var (
_getTextMetrics = user32.NewProc("GetTextMetricsW")
_getTextMetrics = gdi32.NewProc("GetTextMetricsW")
_getWindowDC = user32.NewProc("GetWindowDC")
_releaseDC = user32.NewProc("ReleaseDC")
)
func (s *sysData) preferredSize() (width int, height int) {
println("size of control", s.ctype)
var dc _HANDLE
var tm _TEXTMETRICS
var baseX, baseY int
println("calling getWindowDC")
r1, _, err := _getWindowDC.Call(uintptr(s.hwnd))
println("getWindowDC",r1,err)
if r1 == 0 { // failure
panic(err) // TODO return it instead
}
dc = _HANDLE(r1)
println("getTextMetrics")
r1, _, err = _getTextMetrics.Call(
uintptr(dc),
uintptr(unsafe.Pointer(&tm)))
println("getTextMetrics",r1,err)
if r1 == 0 { // failure
panic(err) // TODO return it instead
}
baseX = int(tm.tmAveCharWidth) // TODO not optimal; third reference has better way
baseY = int(tm.tmHeight)
println("releaseDC")
r1, _, err = _releaseDC.Call(
uintptr(s.hwnd),
uintptr(dc))
println("releaseDC",r1,err)
if r1 == 0 { // failure
panic(err) // TODO return it instead
}
@ -100,7 +93,6 @@ println("releaseDC",r1,err)
height = stdDlgSizes[s.ctype].height
width = muldiv(width, baseX, 4) // equivalent to right of rect
height = muldiv(height, baseY, 8) // equivalent to bottom of rect
println("result:", width, height)
return width, height
}

View File

@ -85,15 +85,15 @@ func (w *Window) Open(control Control) (err error) {
return fmt.Errorf("error adding window's control: %v", err)
}
}
err = w.sysData.setWindowSize(w.initWidth, w.initHeight)
if err != nil {
return fmt.Errorf("error setting window size (in Window.Open()): %v", err)
}
// TODO separate showing?
err = w.sysData.show()
if err != nil {
return fmt.Errorf("error showing window (in Window.Open()): %v", err)
}
err = w.sysData.setWindowSize(w.initWidth, w.initHeight)
if err != nil {
return fmt.Errorf("error setting window size (in Window.Open()): %v", err)
}
w.created = true
return nil
}