forked from andlabs/ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
control_windows.go
69 lines (56 loc) · 1.5 KB
/
control_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
// 30 july 2014
package ui
// #include "winapi_windows.h"
import "C"
type controlParent struct {
hwnd C.HWND
}
// don't specify preferredSize in any of these; they're per-control
type controlSingleHWND struct {
*controlbase
hwnd C.HWND
}
func newControlSingleHWND(hwnd C.HWND) *controlSingleHWND {
c := new(controlSingleHWND)
c.controlbase = &controlbase{
fsetParent: c.xsetParent,
fresize: c.xresize,
fnTabStops: func() int {
// most controls count as one tab stop
return 1
},
fcontainerShow: func() {
C.ShowWindow(c.hwnd, C.SW_SHOW)
},
fcontainerHide: func() {
C.ShowWindow(c.hwnd, C.SW_HIDE)
},
}
c.hwnd = hwnd
return c
}
func (c *controlSingleHWND) xsetParent(p *controlParent) {
C.controlSetParent(c.hwnd, p.hwnd)
}
func (c *controlSingleHWND) xresize(x int, y int, width int, height int, d *sizing) {
C.moveWindow(c.hwnd, C.int(x), C.int(y), C.int(width), C.int(height))
}
// these are provided for convenience
type controlSingleHWNDWithText struct {
*controlSingleHWND
textlen C.LONG
}
func newControlSingleHWNDWithText(h C.HWND) *controlSingleHWNDWithText {
return &controlSingleHWNDWithText{
controlSingleHWND: newControlSingleHWND(h),
}
}
// TODO export these instead of requiring dummy declarations in each implementation
func (c *controlSingleHWNDWithText) text() string {
return getWindowText(c.hwnd)
}
func (c *controlSingleHWNDWithText) setText(text string) {
t := toUTF16(text)
C.setWindowText(c.hwnd, t)
c.textlen = C.controlTextLength(c.hwnd, t)
}