Added buttons.
This commit is contained in:
parent
87a99bd675
commit
ddfb5c7603
|
@ -10,5 +10,5 @@ import (
|
||||||
type Control interface {
|
type Control interface {
|
||||||
apply() error
|
apply() error
|
||||||
setParent(c Control)
|
setParent(c Control)
|
||||||
setParentWindow(w *Window)
|
parentWindow() *Window
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,65 +9,65 @@ import (
|
||||||
// Button styles.
|
// Button styles.
|
||||||
const (
|
const (
|
||||||
// from winuser.h
|
// from winuser.h
|
||||||
BS_PUSHBUTTON = 0x00000000
|
_BS_PUSHBUTTON = 0x00000000
|
||||||
BS_DEFPUSHBUTTON = 0x00000001
|
_BS_DEFPUSHBUTTON = 0x00000001
|
||||||
BS_CHECKBOX = 0x00000002
|
_BS_CHECKBOX = 0x00000002
|
||||||
BS_AUTOCHECKBOX = 0x00000003
|
_BS_AUTOCHECKBOX = 0x00000003
|
||||||
BS_RADIOBUTTON = 0x00000004
|
_BS_RADIOBUTTON = 0x00000004
|
||||||
BS_3STATE = 0x00000005
|
_BS_3STATE = 0x00000005
|
||||||
BS_AUTO3STATE = 0x00000006
|
_BS_AUTO3STATE = 0x00000006
|
||||||
BS_GROUPBOX = 0x00000007
|
_BS_GROUPBOX = 0x00000007
|
||||||
BS_USERBUTTON = 0x00000008
|
_BS_USERBUTTON = 0x00000008
|
||||||
BS_AUTORADIOBUTTON = 0x00000009
|
_BS_AUTORADIOBUTTON = 0x00000009
|
||||||
BS_PUSHBOX = 0x0000000A
|
_BS_PUSHBOX = 0x0000000A
|
||||||
BS_OWNERDRAW = 0x0000000B
|
_BS_OWNERDRAW = 0x0000000B
|
||||||
BS_TYPEMASK = 0x0000000F
|
_BS_TYPEMASK = 0x0000000F
|
||||||
BS_LEFTTEXT = 0x00000020
|
_BS_LEFTTEXT = 0x00000020
|
||||||
BS_TEXT = 0x00000000
|
_BS_TEXT = 0x00000000
|
||||||
BS_ICON = 0x00000040
|
_BS_ICON = 0x00000040
|
||||||
BS_BITMAP = 0x00000080
|
_BS_BITMAP = 0x00000080
|
||||||
BS_LEFT = 0x00000100
|
_BS_LEFT = 0x00000100
|
||||||
BS_RIGHT = 0x00000200
|
_BS_RIGHT = 0x00000200
|
||||||
BS_CENTER = 0x00000300
|
_BS_CENTER = 0x00000300
|
||||||
BS_TOP = 0x00000400
|
_BS_TOP = 0x00000400
|
||||||
BS_BOTTOM = 0x00000800
|
_BS_BOTTOM = 0x00000800
|
||||||
BS_VCENTER = 0x00000C00
|
_BS_VCENTER = 0x00000C00
|
||||||
BS_PUSHLIKE = 0x00001000
|
_BS_PUSHLIKE = 0x00001000
|
||||||
BS_MULTILINE = 0x00002000
|
_BS_MULTILINE = 0x00002000
|
||||||
BS_NOTIFY = 0x00004000
|
_BS_NOTIFY = 0x00004000
|
||||||
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 WM_COMMAND notifications.
|
// Button WM_COMMAND notifications.
|
||||||
const (
|
const (
|
||||||
// from winuser.h
|
// from winuser.h
|
||||||
BN_CLICKED = 0
|
_BN_CLICKED = 0
|
||||||
BN_PAINT = 1
|
_BN_PAINT = 1
|
||||||
BN_HILITE = 2
|
_BN_HILITE = 2
|
||||||
BN_UNHILITE = 3
|
_BN_UNHILITE = 3
|
||||||
BN_DISABLE = 4
|
_BN_DISABLE = 4
|
||||||
BN_DOUBLECLICKED = 5
|
_BN_DOUBLECLICKED = 5
|
||||||
BN_PUSHED = BN_HILITE
|
_BN_PUSHED = _BN_HILITE
|
||||||
BN_UNPUSHED = BN_UNHILITE
|
_BN_UNPUSHED = _BN_UNHILITE
|
||||||
BN_DBLCLK = BN_DOUBLECLICKED
|
_BN_DBLCLK = _BN_DOUBLECLICKED
|
||||||
BN_SETFOCUS = 6
|
_BN_SETFOCUS = 6
|
||||||
BN_KILLFOCUS = 7
|
_BN_KILLFOCUS = 7
|
||||||
)
|
)
|
||||||
|
|
||||||
// Button check states.
|
// Button check states.
|
||||||
const (
|
const (
|
||||||
// from winuser.h
|
// from winuser.h
|
||||||
BST_UNCHECKED = 0x0000
|
_BST_UNCHECKED = 0x0000
|
||||||
BST_CHECKED = 0x0001
|
_BST_CHECKED = 0x0001
|
||||||
BST_INDETERMINATE = 0x0002
|
_BST_INDETERMINATE = 0x0002
|
||||||
)
|
)
|
||||||
|
/*
|
||||||
var (
|
var (
|
||||||
checkDlgButton = user32.NewProc("CheckDlgButton")
|
checkDlgButton = user32.NewProc("CheckDlgButton")
|
||||||
checkRadioButton = user32.NewProc("CheckRadioButton")
|
checkRadioButton = user32.NewProc("CheckRadioButton")
|
||||||
|
@ -402,3 +402,4 @@ const (
|
||||||
STN_ENABLE = 2
|
STN_ENABLE = 2
|
||||||
STN_DISABLE = 3
|
STN_DISABLE = 3
|
||||||
)
|
)
|
||||||
|
*/
|
12
main.go
12
main.go
|
@ -4,11 +4,21 @@ package main
|
||||||
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{})
|
||||||
|
b := NewButton("Click Me")
|
||||||
|
w.SetControl(b)
|
||||||
err := w.Open()
|
err := w.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
<-w.Closing
|
mainloop:
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-w.Closing:
|
||||||
|
break mainloop
|
||||||
|
case <-b.Clicked:
|
||||||
|
println("clicked")
|
||||||
|
}
|
||||||
|
}
|
||||||
w.Close()
|
w.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,8 @@ import (
|
||||||
|
|
||||||
// The sysData type contains all system data. It provides the system-specific underlying implementation. It is guaranteed to have the following by embedding:
|
// The sysData type contains all system data. It provides the system-specific underlying implementation. It is guaranteed to have the following by embedding:
|
||||||
type cSysData struct {
|
type cSysData struct {
|
||||||
ctype int
|
ctype int
|
||||||
|
parentWindow *sysData
|
||||||
|
|
||||||
// for Window
|
// for Window
|
||||||
closing chan struct{}
|
closing chan struct{}
|
||||||
|
|
|
@ -23,8 +23,8 @@ type classData struct {
|
||||||
mkid bool
|
mkid bool
|
||||||
}
|
}
|
||||||
|
|
||||||
//const controlstyle = _WS_CHILD | _WS_VISIBLE | _WS_TABSTOP
|
const controlstyle = _WS_CHILD | _WS_VISIBLE | _WS_TABSTOP
|
||||||
//const controlxstyle = 0
|
const controlxstyle = 0
|
||||||
|
|
||||||
var classTypes = [nctypes]*classData{
|
var classTypes = [nctypes]*classData{
|
||||||
c_window: &classData{
|
c_window: &classData{
|
||||||
|
@ -32,12 +32,12 @@ var classTypes = [nctypes]*classData{
|
||||||
style: _WS_OVERLAPPEDWINDOW,
|
style: _WS_OVERLAPPEDWINDOW,
|
||||||
xstyle: 0,
|
xstyle: 0,
|
||||||
},
|
},
|
||||||
// c_button: &classData{
|
c_button: &classData{
|
||||||
// name: "BUTTON"
|
name: "BUTTON",
|
||||||
// style: _BS_PUSHBUTTON | controlstyle,
|
style: _BS_PUSHBUTTON | controlstyle,
|
||||||
// xstyle: 0 | controlxstyle,
|
xstyle: 0 | controlxstyle,
|
||||||
// mkid: true,
|
mkid: true,
|
||||||
// },
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -56,8 +56,10 @@ func (s *sysData) make(initText string, initWidth int, initHeight int) (err erro
|
||||||
ret := make(chan uiret)
|
ret := make(chan uiret)
|
||||||
defer close(ret)
|
defer close(ret)
|
||||||
ct := classTypes[s.ctype]
|
ct := classTypes[s.ctype]
|
||||||
|
pwin := uintptr(_NULL)
|
||||||
if ct.mkid {
|
if ct.mkid {
|
||||||
s.cid = nextID()
|
s.cid = nextID()
|
||||||
|
pwin = uintptr(s.parentWindow.hwnd)
|
||||||
}
|
}
|
||||||
uitask <- &uimsg{
|
uitask <- &uimsg{
|
||||||
call: _createWindowEx,
|
call: _createWindowEx,
|
||||||
|
@ -70,7 +72,7 @@ func (s *sysData) make(initText string, initWidth int, initHeight int) (err erro
|
||||||
uintptr(_CW_USEDEFAULT),
|
uintptr(_CW_USEDEFAULT),
|
||||||
uintptr(initWidth),
|
uintptr(initWidth),
|
||||||
uintptr(initHeight),
|
uintptr(initHeight),
|
||||||
uintptr(_NULL), // TODO parent
|
pwin,
|
||||||
uintptr(s.cid),
|
uintptr(s.cid),
|
||||||
uintptr(hInstance),
|
uintptr(hInstance),
|
||||||
uintptr(_NULL),
|
uintptr(_NULL),
|
||||||
|
|
|
@ -47,7 +47,6 @@ func (w *Window) SetControl(control Control) (err error) {
|
||||||
}
|
}
|
||||||
w.control = control
|
w.control = control
|
||||||
w.control.setParent(w)
|
w.control.setParent(w)
|
||||||
w.control.setParentWindow(w)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,6 +111,6 @@ func (w *Window) apply() error {
|
||||||
func (w *Window) setParent(c Control) {
|
func (w *Window) setParent(c Control) {
|
||||||
panic("Window.setParent() should never be called")
|
panic("Window.setParent() should never be called")
|
||||||
}
|
}
|
||||||
func (w *Window) setParentWindow(w2 *Window) {
|
func (w *Window) parentWindow() *Window {
|
||||||
panic("Window.setParent() should never be called")
|
panic("Window.parentWindow() should never be called")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue