Added Checkbox.Checked().

This commit is contained in:
Pietro Gagliardi 2014-02-13 15:14:10 -05:00
parent f3c77bda6e
commit 44842fea4b
5 changed files with 55 additions and 5 deletions

View File

@ -39,7 +39,17 @@ func (c *Checkbox) SetText(text string) (err error) {
return nil
}
// TODO Checked()
// Checked() returns whether or not the checkbox has been checked.
func (c *Checkbox) Checked() bool {
c.lock.Lock()
defer c.lock.Unlock()
check, err := c.sysData.isChecked()
if err != nil {
panic(err) // TODO
}
return check
}
func (c *Checkbox) apply(window *sysData) error {
c.lock.Lock()

View File

@ -38,10 +38,25 @@ const (
_BS_FLAT = 0x00008000
_BS_RIGHTBUTTON = _BS_LEFTTEXT
// from commctrl.h
// _BS_SPLITBUTTON = 0x0000000C // Windows Vista and newer and(/or?) comctl6 only
// _BS_DEFSPLITBUTTON = 0x0000000D // Windows Vista and newer and(/or?) comctl6 only
// _BS_SPLITBUTTON = 0x0000000C // Windows Vista and newer and(/or?) comctl6 only
// _BS_DEFSPLITBUTTON = 0x0000000D // Windows Vista and newer and(/or?) comctl6 only
// _BS_COMMANDLINK = 0x0000000E // Windows Vista and newer and(/or?) comctl6 only
// _BS_DEFCOMMANDLINK = 0x0000000F // Windows Vista and newer and(/or?) comctl6 only
// _BS_DEFCOMMANDLINK = 0x0000000F // Windows Vista and newer and(/or?) comctl6 only
)
// Button messages.
// TODO check if any are not defined on Windows 2000
const (
// from winuser.h
_BM_GETCHECK = 0x00F0
_BM_SETCHECK = 0x00F1
_BM_GETSTATE = 0x00F2
_BM_SETSTATE = 0x00F3
_BM_SETSTYLE = 0x00F4
_BM_CLICK = 0x00F5
_BM_GETIMAGE = 0x00F6
_BM_SETIMAGE = 0x00F7
_BM_SETDONTCLICK = 0x00F8
)
// Button WM_COMMAND notifications.

View File

@ -1,6 +1,10 @@
// 11 february 2014
package main
import (
"fmt"
)
func main() {
w := NewWindow("Main Window", 320, 240)
w.Closing = make(chan struct{})
@ -23,7 +27,7 @@ mainloop:
case <-w.Closing:
break mainloop
case <-b.Clicked:
err := w.SetTitle("Button Clicked")
err := w.SetTitle(fmt.Sprintf("Check State: %v", c.Checked()))
if err != nil {
panic(err)
}

View File

@ -26,6 +26,9 @@ func (c *cSysData) setText(text string) error {
func (c *cSysData) setRect(x int, y int, width int, height int) error {
panic(runtime.GOOS + " sysData does not define setRect()")
}
func (c *cSysData) isChecked() (bool, error) {
panic(runtime.GOOS + " sysData does not define isChecked()")
}
const (
c_window = iota

View File

@ -201,3 +201,21 @@ func (s *sysData) setRect(x int, y int, width int, height int) error {
}
return nil
}
// TODO figure out how to handle error
func (s *sysData) isChecked() (bool, error) {
ret := make(chan uiret)
defer close(ret)
uitask <- &uimsg{
call: _sendMessage,
p: []uintptr{
uintptr(s.hwnd),
uintptr(_BM_GETCHECK),
uintptr(0),
uintptr(0),
},
ret: ret,
}
r := <-ret
return r.ret == _BST_CHECKED, nil
}