Added Checkbox.Checked().
This commit is contained in:
parent
f3c77bda6e
commit
44842fea4b
12
checkbox.go
12
checkbox.go
|
@ -39,7 +39,17 @@ func (c *Checkbox) SetText(text string) (err error) {
|
||||||
return nil
|
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 {
|
func (c *Checkbox) apply(window *sysData) error {
|
||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
|
|
|
@ -38,10 +38,25 @@ const (
|
||||||
_BS_FLAT = 0x00008000
|
_BS_FLAT = 0x00008000
|
||||||
_BS_RIGHTBUTTON = _BS_LEFTTEXT
|
_BS_RIGHTBUTTON = _BS_LEFTTEXT
|
||||||
// from commctrl.h
|
// from commctrl.h
|
||||||
// _BS_SPLITBUTTON = 0x0000000C // 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_DEFSPLITBUTTON = 0x0000000D // Windows Vista and newer and(/or?) comctl6 only
|
||||||
// _BS_COMMANDLINK = 0x0000000E // 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.
|
// Button WM_COMMAND notifications.
|
||||||
|
|
6
main.go
6
main.go
|
@ -1,6 +1,10 @@
|
||||||
// 11 february 2014
|
// 11 february 2014
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
w := NewWindow("Main Window", 320, 240)
|
w := NewWindow("Main Window", 320, 240)
|
||||||
w.Closing = make(chan struct{})
|
w.Closing = make(chan struct{})
|
||||||
|
@ -23,7 +27,7 @@ mainloop:
|
||||||
case <-w.Closing:
|
case <-w.Closing:
|
||||||
break mainloop
|
break mainloop
|
||||||
case <-b.Clicked:
|
case <-b.Clicked:
|
||||||
err := w.SetTitle("Button Clicked")
|
err := w.SetTitle(fmt.Sprintf("Check State: %v", c.Checked()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,9 @@ func (c *cSysData) setText(text string) error {
|
||||||
func (c *cSysData) setRect(x int, y int, width int, height int) error {
|
func (c *cSysData) setRect(x int, y int, width int, height int) error {
|
||||||
panic(runtime.GOOS + " sysData does not define setRect()")
|
panic(runtime.GOOS + " sysData does not define setRect()")
|
||||||
}
|
}
|
||||||
|
func (c *cSysData) isChecked() (bool, error) {
|
||||||
|
panic(runtime.GOOS + " sysData does not define isChecked()")
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
c_window = iota
|
c_window = iota
|
||||||
|
|
|
@ -201,3 +201,21 @@ func (s *sysData) setRect(x int, y int, width int, height int) error {
|
||||||
}
|
}
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue