-
Notifications
You must be signed in to change notification settings - Fork 0
/
button.go
68 lines (52 loc) · 1.22 KB
/
button.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
// Copyright 2010 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package walk
import . "github.com/lxn/go-winapi"
type clickable interface {
raiseClicked()
}
type Button struct {
WidgetBase
clickedPublisher EventPublisher
}
func (b *Button) Text() string {
return widgetText(b.hWnd)
}
func (b *Button) SetText(value string) error {
if value == b.Text() {
return nil
}
if err := setWidgetText(b.hWnd, value); err != nil {
return err
}
return b.updateParentLayout()
}
func (b *Button) Checked() bool {
return SendMessage(b.hWnd, BM_GETCHECK, 0, 0) == BST_CHECKED
}
func (b *Button) SetChecked(value bool) {
var chk uintptr
if value {
chk = BST_CHECKED
} else {
chk = BST_UNCHECKED
}
SendMessage(b.hWnd, BM_SETCHECK, chk, 0)
}
func (b *Button) Clicked() *Event {
return b.clickedPublisher.Event()
}
func (b *Button) raiseClicked() {
b.clickedPublisher.Publish()
}
func (b *Button) wndProc(hwnd HWND, msg uint32, wParam, lParam uintptr) uintptr {
switch msg {
case WM_COMMAND:
switch HIWORD(uint32(wParam)) {
case BN_CLICKED:
b.raiseClicked()
}
}
return b.WidgetBase.wndProc(hwnd, msg, wParam, lParam)
}