-
Notifications
You must be signed in to change notification settings - Fork 0
/
splitbutton.go
112 lines (84 loc) · 2.09 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
104
105
106
107
108
109
110
111
112
// 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)
menu, err := NewMenu()
if err != nil {
return nil, err
}
if err := InitWidget(
sb,
parent,
"BUTTON",
win.WS_TABSTOP|win.WS_VISIBLE|win.BS_SPLITBUTTON,
0); err != nil {
return nil, err
}
sb.Button.init()
sb.menu = menu
sb.GraphicsEffects().Add(InteractionEffect)
sb.GraphicsEffects().Add(FocusEffect)
return sb, nil
}
func (sb *SplitButton) Dispose() {
sb.Button.Dispose()
sb.menu.Dispose()
}
func (*SplitButton) LayoutFlags() LayoutFlags {
return GrowableHorz
}
func (sb *SplitButton) MinSizeHint() Size {
var s win.SIZE
sb.SendMessage(win.BCM_GETIDEALSIZE, 0, uintptr(unsafe.Pointer(&s)))
return maxSize(Size{int(s.CX), int(s.CY)}, sb.dialogBaseUnitsToPixels(Size{50, 14}))
}
func (sb *SplitButton) SizeHint() Size {
return sb.MinSizeHint()
}
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)
}