forked from andlabs/ui
/
group_windows.go
82 lines (66 loc) · 1.72 KB
/
group_windows.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
// 15 august 2014
package ui
// #include "winapi_windows.h"
import "C"
type group struct {
_hwnd C.HWND
_textlen C.LONG
*container
}
func newGroup(text string, control Control) Group {
hwnd := C.newControl(buttonclass,
C.BS_GROUPBOX,
C.WS_EX_CONTROLPARENT)
g := &group{
_hwnd: hwnd,
container: newContainer(control),
}
g.SetText(text)
C.controlSetControlFont(g._hwnd)
g.container.setParent(g._hwnd)
g.container.isGroup = true
return g
}
func (g *group) Text() string {
return baseText(g)
}
func (g *group) SetText(text string) {
baseSetText(g, text)
}
func (g *group) hwnd() C.HWND {
return g._hwnd
}
func (g *group) textlen() C.LONG {
return g._textlen
}
func (g *group) settextlen(len C.LONG) {
g._textlen = len
}
func (g *group) setParent(p *controlParent) {
basesetParent(g, p)
}
func (g *group) allocate(x int, y int, width int, height int, d *sizing) []*allocation {
return baseallocate(g, x, y, width, height, d)
}
func (g *group) preferredSize(d *sizing) (width, height int) {
width, height = g.child.preferredSize(d)
if width < int(g._textlen) { // if the text is longer, try not to truncate
width = int(g._textlen)
}
// the two margin constants come from container_windows.go
return width, height + fromdlgunitsY(groupYMarginTop, d) + fromdlgunitsY(groupYMarginBottom, d)
}
func (g *group) commitResize(c *allocation, d *sizing) {
var r C.RECT
// pretend that the client area of the group box only includes the actual empty space
// container will handle the necessary adjustments properly
r.left = 0
r.top = 0
r.right = C.LONG(c.width)
r.bottom = C.LONG(c.height)
g.container.move(&r)
basecommitResize(g, c, d)
}
func (g *group) getAuxResizeInfo(d *sizing) {
basegetAuxResizeInfo(g, d)
}