Skip to content

Commit

Permalink
Added sizing of windows and the main window control. It presently dea…
Browse files Browse the repository at this point in the history
…dlocks; I'll need to redo my mutexes...
  • Loading branch information
andlabs committed Feb 13, 2014
1 parent ae9afce commit 5626b9e
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 28 deletions.
7 changes: 7 additions & 0 deletions button.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions control.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
15 changes: 14 additions & 1 deletion stdwndclass_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions sysdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()")
Expand All @@ -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
Expand Down
22 changes: 22 additions & 0 deletions sysdata_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions window.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
}
28 changes: 1 addition & 27 deletions windows_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 5626b9e

Please sign in to comment.