-
Notifications
You must be signed in to change notification settings - Fork 2
/
groupbox.go
192 lines (150 loc) · 3.74 KB
/
groupbox.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// 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 (
"syscall"
)
import (
"github.com/lxn/win"
)
const groupBoxWindowClass = `\o/ Walk_GroupBox_Class \o/`
func init() {
MustRegisterWindowClass(groupBoxWindowClass)
}
type GroupBox struct {
WidgetBase
hWndGroupBox win.HWND
composite *Composite
titleChangedPublisher EventPublisher
}
func NewGroupBox(parent Container) (*GroupBox, error) {
gb := new(GroupBox)
if err := InitWidget(
gb,
parent,
groupBoxWindowClass,
win.WS_VISIBLE,
win.WS_EX_CONTROLPARENT); err != nil {
return nil, err
}
succeeded := false
defer func() {
if !succeeded {
gb.Dispose()
}
}()
var err error
gb.composite, err = NewComposite(gb)
if err != nil {
return nil, err
}
gb.hWndGroupBox = win.CreateWindowEx(
0, syscall.StringToUTF16Ptr("BUTTON"), nil,
win.WS_CHILD|win.WS_VISIBLE|win.BS_GROUPBOX,
0, 0, 80, 24, gb.hWnd, 0, 0, nil)
if gb.hWndGroupBox == 0 {
return nil, lastError("CreateWindowEx(BUTTON)")
}
// Set font to nil first to outsmart SetFont.
gb.font = nil
gb.SetFont(defaultFont)
gb.MustRegisterProperty("Title", NewProperty(
func() interface{} {
return gb.Title()
},
func(v interface{}) error {
return gb.SetTitle(v.(string))
},
gb.titleChangedPublisher.Event()))
succeeded = true
return gb, nil
}
func (gb *GroupBox) AsContainerBase() *ContainerBase {
return gb.composite.AsContainerBase()
}
func (gb *GroupBox) LayoutFlags() LayoutFlags {
if gb.composite == nil {
return 0
}
return gb.composite.LayoutFlags()
}
func (gb *GroupBox) MinSizeHint() Size {
if gb.composite == nil {
return Size{100, 100}
}
cmsh := gb.composite.MinSizeHint()
return Size{cmsh.Width + 2, cmsh.Height + 9}
}
func (gb *GroupBox) SizeHint() Size {
return gb.MinSizeHint()
}
func (gb *GroupBox) ClientBounds() Rectangle {
cb := windowClientBounds(gb.hWndGroupBox)
if gb.Layout() == nil {
return cb
}
// FIXME: Use appropriate margins
return Rectangle{cb.X + 1, cb.Y + 14, cb.Width - 2, cb.Height - 9}
}
func (gb *GroupBox) SetFont(value *Font) {
if value != gb.font {
setWindowFont(gb.hWndGroupBox, value)
gb.font = value
}
}
func (gb *GroupBox) SetSuspended(suspend bool) {
gb.composite.SetSuspended(suspend)
gb.WidgetBase.SetSuspended(suspend)
gb.Invalidate()
}
func (gb *GroupBox) DataBinder() *DataBinder {
return gb.composite.dataBinder
}
func (gb *GroupBox) SetDataBinder(dataBinder *DataBinder) {
gb.composite.SetDataBinder(dataBinder)
}
func (gb *GroupBox) Title() string {
return windowText(gb.hWndGroupBox)
}
func (gb *GroupBox) SetTitle(value string) error {
return setWindowText(gb.hWndGroupBox, value)
}
func (gb *GroupBox) Children() *WidgetList {
if gb.composite == nil {
// Without this we would get into trouble in NewComposite.
return nil
}
return gb.composite.Children()
}
func (gb *GroupBox) Layout() Layout {
return gb.composite.Layout()
}
func (gb *GroupBox) SetLayout(value Layout) error {
return gb.composite.SetLayout(value)
}
func (gb *GroupBox) WndProc(hwnd win.HWND, msg uint32, wParam, lParam uintptr) uintptr {
if gb.composite != nil {
switch msg {
case win.WM_COMMAND, win.WM_NOTIFY:
gb.composite.WndProc(hwnd, msg, wParam, lParam)
case win.WM_SETTEXT:
gb.titleChangedPublisher.Publish()
case win.WM_SIZE, win.WM_SIZING:
wbcb := gb.WidgetBase.ClientBounds()
if !win.MoveWindow(
gb.hWndGroupBox,
int32(wbcb.X),
int32(wbcb.Y),
int32(wbcb.Width),
int32(wbcb.Height),
true) {
lastError("MoveWindow")
break
}
gbcb := gb.ClientBounds()
gb.composite.SetBounds(gbcb)
}
}
return gb.WidgetBase.WndProc(hwnd, msg, wParam, lParam)
}