summaryrefslogtreecommitdiff
path: root/redo/control_windows.go
blob: ac3297e033e3119a90edf60a1bf4dca0c9635c39 (plain)
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
// 30 july 2014

package ui

// #include "winapi_windows.h"
import "C"

type controlPrivate interface {
	// TODO
	Control
}

type controlbase struct {
	hwnd	C.HWND
	parent	C.HWND		// for Tab and Group
	textlen	C.LONG
}

type controlParent struct {
	hwnd	C.HWND
}

func newControl(class C.LPWSTR, style C.DWORD, extstyle C.DWORD) *controlbase {
	c := new(controlbase)
	// TODO rename to newWidget
	c.hwnd = C.newWidget(class, style, extstyle)
	return c
}

// TODO for maximum correctness these shouldn't take controlbases... but then the amount of duplicated code would skyrocket

func basesetParent(c *controlbase, p *controlParent) {
	C.controlSetParent(c.hwnd, p.hwnd)
	c.parent = p.hwnd
}

func basecontainerShow(c *controlbase) {
	C.ShowWindow(c.hwnd, C.SW_SHOW)
}

func basecontainerHide(c *controlbase) {
	C.ShowWindow(c.hwnd, C.SW_HIDE)
}

// don't specify basepreferredSize; it is custom on ALL controls

func basecommitResize(c *controlbase, a *allocation, d *sizing) {
	C.moveWindow(c.hwnd, C.int(a.x), C.int(a.y), C.int(a.width), C.int(a.height))
}

func basegetAuxResizeInfo(c controlPrivate, d *sizing) {
	// do nothing
}

// these are provided for convenience

func (c *controlbase) text() string {
	return getWindowText(c.hwnd)
}

func (c *controlbase) setText(text string) {
	t := toUTF16(text)
	C.setWindowText(c.hwnd, t)
	c.textlen = C.controlTextLength(c.hwnd, t)
}