-
Notifications
You must be signed in to change notification settings - Fork 886
/
splitbutton.go
103 lines (79 loc) · 1.87 KB
/
splitbutton.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
// Copyright 2016 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.
// +build windows
package walk
import (
"unsafe"
)
import (
"github.com/lxn/win"
)
type SplitButton struct {
Button
menu *Menu
}
func NewSplitButton(parent Container) (*SplitButton, error) {
sb := new(SplitButton)
var disposables Disposables
defer disposables.Treat()
if err := InitWidget(
sb,
parent,
"BUTTON",
win.WS_TABSTOP|win.WS_VISIBLE|win.BS_SPLITBUTTON,
0); err != nil {
return nil, err
}
disposables.Add(sb)
sb.Button.init()
menu, err := NewMenu()
if err != nil {
return nil, err
}
disposables.Add(menu)
menu.window = sb
sb.menu = menu
sb.GraphicsEffects().Add(InteractionEffect)
sb.GraphicsEffects().Add(FocusEffect)
disposables.Spare()
return sb, nil
}
func (sb *SplitButton) Dispose() {
sb.Button.Dispose()
sb.menu.Dispose()
}
func (sb *SplitButton) ImageAboveText() bool {
return sb.hasStyleBits(win.BS_TOP)
}
func (sb *SplitButton) SetImageAboveText(value bool) error {
if err := sb.ensureStyleBits(win.BS_TOP, value); err != nil {
return err
}
// We need to set the image again, or Windows will fail to calculate the
// button control size correctly.
return sb.SetImage(sb.image)
}
func (sb *SplitButton) Menu() *Menu {
return sb.menu
}
func (sb *SplitButton) WndProc(hwnd win.HWND, msg uint32, wParam, lParam uintptr) uintptr {
switch msg {
case win.WM_NOTIFY:
switch ((*win.NMHDR)(unsafe.Pointer(lParam))).Code {
case win.BCN_DROPDOWN:
dd := (*win.NMBCDROPDOWN)(unsafe.Pointer(lParam))
p := win.POINT{dd.RcButton.Left, dd.RcButton.Bottom}
win.ClientToScreen(sb.hWnd, &p)
win.TrackPopupMenuEx(
sb.menu.hMenu,
win.TPM_NOANIMATION,
p.X,
p.Y,
sb.hWnd,
nil)
return 0
}
}
return sb.Button.WndProc(hwnd, msg, wParam, lParam)
}