Added sizing of windows and the main window control. It presently deadlocks; I'll need to redo my mutexes...

This commit is contained in:
Pietro Gagliardi 2014-02-13 05:28:26 -05:00
parent ae9afced2a
commit 5626b9e35c
7 changed files with 53 additions and 28 deletions

View File

@ -49,6 +49,13 @@ func (b *Button) apply(window *sysData) error {
// TODO size to parent size
}
func (b *Button) setRect(x int, y int, width int, height int) error {
b.lock.Lock()
defer b.lock.Unlock()
return b.sysData.setRect(x, y, width, height)
}
func (b *Button) setParent(c Control) {
b.parent = c
}

View File

@ -9,5 +9,6 @@ import (
// A Control represents an UI control. Note that Control contains unexported members; this has the consequence that you can't build custom controls that interface directly with the system-specific code (fo rinstance, to import an unsupported control), or at least not without some hackery. If you want to make your own controls, embed Area and provide its necessities.
type Control interface {
apply(window *sysData) error
setRect(x int, y int, width int, height int) error
setParent(c Control)
}

View File

@ -42,7 +42,20 @@ func stdWndProc(s *sysData) func(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam
_ = mm
return 0
case _WM_SIZE:
// TODO
if s.resize != nil {
var r _RECT
r1, _, err := _getClientRect.Call(
uintptr(hwnd),
uintptr(unsafe.Pointer(&r)))
if r1 == 0 {
panic("GetClientRect failed: " + err.Error())
}
err = s.resize(int(r.Left), int(r.Top), int(r.Right), int(r.Bottom))
if err != nil {
panic("child resize failed: " + err.Error())
}
}
return 0
case _WM_CLOSE:
if s.event != nil {

View File

@ -9,6 +9,7 @@ import (
type cSysData struct {
ctype int
event chan struct{}
resize func(x int, y int, width int, height int) error
}
func (c *cSysData) make(initText string, initWidth int, initHeight int, window *sysData) error {
panic(runtime.GOOS + " sysData does not define make()")
@ -22,6 +23,9 @@ func (c *cSysData) hide() error {
func (c *cSysData) setText(text string) error {
panic(runtime.GOOS + " sysData does not define setText()")
}
func (c *cSysData) setRect(x int, y int, width int, height int) error {
panic(runtime.GOOS + " sysData does not define setRect()")
}
const (
c_window = iota

View File

@ -174,3 +174,25 @@ func (s *sysData) setText(text string) error {
}
return nil
}
func (s *sysData) setRect(x int, y int, width int, height int) error {
ret := make(chan uiret)
defer close(ret)
uitask <- &uimsg{
call: _moveWindow,
p: []uintptr{
uintptr(s.hwnd),
uintptr(x),
uintptr(y),
uintptr(width),
uintptr(height),
uintptr(_TRUE),
},
ret: ret,
}
r := <-ret
if r.ret == 0 { // failure
return r.err
}
return nil
}

View File

@ -77,6 +77,7 @@ func (w *Window) Open(control Control) (err error) {
return err
}
if control != nil {
w.sysData.resize = control.setRect
err = control.apply(w.sysData)
if err != nil {
return err
@ -101,6 +102,9 @@ func (w *Window) Hide() (err error) {
func (w *Window) apply(window *sysData) error {
panic("Window.apply() should never be called")
}
func (w *Window) setRect(x int, y int, width int, height int) error {
panic("Window.setRect() should never be called")
}
func (w *Window) setParent(c Control) {
panic("Window.setParent() should never be called")
}

View File

@ -169,6 +169,7 @@ var (
_destroyWindow = user32.NewProc("DestroyWindow")
_getClientRect = user32.NewProc("GetClientRect")
_enumChildWindows = user32.NewProc("EnumChildWindows")
_moveWindow = user32.NewProc("MoveWindow")
_setWindowPos = user32.NewProc("SetWindowPos")
_setWindowText = user32.NewProc("SetWindowTextW")
_showWindow = user32.NewProc("ShowWindow")
@ -203,33 +204,6 @@ func EnumChildWindows(hWndParent HWND, lpEnumFunc WNDENUMPROC, lParam LPARAM) (e
uintptr(lParam))
return nil
}
// TODO return the rect itself?
func GetClientRect(hWnd HWND) (lpRect *RECT, err error) {
lpRect = new(RECT)
r1, _, err := getClientRect.Call(
uintptr(hWnd),
uintptr(unsafe.Pointer(lpRect)))
if r1 == 0 { // failure
return nil, err
}
return lpRect, nil
}
func SetWindowPos(hWnd HWND, hWndInsertAfter HWND, X int, Y int, cx int, cy int, uFlags uint32) (err error) {
r1, _, err := setWindowPos.Call(
uintptr(hWnd),
uintptr(hWndInsertAfter),
uintptr(X),
uintptr(Y),
uintptr(cx),
uintptr(cy),
uintptr(uFlags))
if r1 == 0 { // failure
return err
}
return nil
}
*/
// WM_SETICON and WM_GETICON values.