-
Notifications
You must be signed in to change notification settings - Fork 45
/
buttons.go
147 lines (113 loc) · 3 KB
/
buttons.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package gform
import (
"github.com/AllenDang/w32"
)
type Button struct {
W32Control
}
func (this *Button) Checked() bool {
result := w32.SendMessage(this.hwnd, w32.BM_GETCHECK, 0, 0)
return result == w32.BST_CHECKED
}
func (this *Button) SetChecked(checked bool) {
wparam := w32.BST_CHECKED
if !checked {
wparam = w32.BST_UNCHECKED
}
w32.SendMessage(this.hwnd, w32.BM_SETCHECK, uintptr(wparam), 0)
}
type PushButton struct {
Button
}
func NewPushButton(parent Controller) *PushButton {
pb := new(PushButton)
pb.init(parent)
pb.SetFont(DefaultFont)
pb.SetCaption("Button")
pb.SetSize(100, 25)
return pb
}
func AttachPushButton(parent Controller, id int) *PushButton {
pb := new(PushButton)
pb.attach(parent, id)
RegMsgHandler(pb)
return pb
}
func (this *PushButton) init(parent Controller) {
this.W32Control.init("BUTTON", parent, 0, w32.BS_PUSHBUTTON|w32.WS_TABSTOP|w32.WS_VISIBLE|w32.WS_CHILD)
RegMsgHandler(this)
}
func (this *PushButton) WndProc(msg uint, wparam, lparam uintptr) uintptr {
switch msg {
case w32.BN_CLICKED:
println("Clicked")
case w32.WM_LBUTTONDOWN:
w32.SetCapture(this.Handle())
case w32.WM_LBUTTONUP:
w32.ReleaseCapture()
}
return this.W32Control.WndProc(msg, wparam, lparam)
}
type CheckBox struct {
Button
}
func NewCheckBox(parent Controller) *CheckBox {
cb := new(CheckBox)
cb.init(parent)
cb.SetFont(DefaultFont)
cb.SetCaption("CheckBox")
cb.SetSize(100, 25)
return cb
}
func AttachCheckBox(parent Controller, id int) *CheckBox {
cb := new(CheckBox)
cb.attach(parent, id)
RegMsgHandler(cb)
return cb
}
func (this *CheckBox) init(parent Controller) {
this.W32Control.init("BUTTON", parent, 0, w32.WS_TABSTOP|w32.WS_VISIBLE|w32.WS_CHILD|w32.BS_AUTOCHECKBOX)
RegMsgHandler(this)
}
type RadioButton struct {
Button
}
func NewRadioButton(parent Controller) *RadioButton {
rb := new(RadioButton)
rb.init(parent)
rb.SetFont(DefaultFont)
rb.SetCaption("RadioButton")
rb.SetSize(100, 25)
return rb
}
func AttachRadioButton(parent Controller, id int) *RadioButton {
rb := new(RadioButton)
rb.attach(parent, id)
RegMsgHandler(rb)
return rb
}
func (this *RadioButton) init(parent Controller) {
this.W32Control.init("BUTTON", parent, 0, w32.WS_TABSTOP|w32.WS_VISIBLE|w32.WS_CHILD|w32.BS_AUTORADIOBUTTON)
RegMsgHandler(this)
}
type GroupBox struct {
Button
}
func NewGroupBox(parent Controller) *GroupBox {
gb := new(GroupBox)
gb.init(parent)
gb.SetFont(DefaultFont)
gb.SetCaption("GroupBox")
gb.SetSize(100, 100)
return gb
}
func AttachGroupBox(parent Controller, id int) *GroupBox {
gb := new(GroupBox)
gb.attach(parent, id)
RegMsgHandler(gb)
return gb
}
func (this *GroupBox) init(parent Controller) {
this.W32Control.init("BUTTON", parent, 0, w32.WS_CHILD|w32.WS_VISIBLE|w32.WS_GROUP|w32.BS_GROUPBOX)
RegMsgHandler(this)
}