summaryrefslogtreecommitdiff
path: root/redo/control_darwin.go
blob: 09ebdae2f23f1f56e0552df1e7d31b2df44a41e3 (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
// 30 july 2014

package ui

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

type controlbase struct {
	*controldefs
	id	C.id
}

type controlParent struct {
	id	C.id
}

func newControl(id C.id) *controlbase {
	c := new(controlbase)
	c.id = id
	c.controldefs = new(controldefs)
	c.fsetParent = func(p *controlParent) {
		// redrawing the new window handled by C.parent()
		C.parent(c.id, p.id)
	}
	c.fcontainerShow = func() {
		C.controlSetHidden(c.id, C.NO)
	}
	c.fcontainerHide = func() {
		C.controlSetHidden(c.id, C.YES)
	}
	c.fallocate = baseallocate(c)
	c.fpreferredSize = func(d *sizing) (int, int) {
		s := C.controlPrefSize(c.id)
		return int(s.width), int(s.height)
	}
	c.fcommitResize = func(a *allocation, d *sizing) {
		C.moveControl(c.id, C.intptr_t(a.x), C.intptr_t(a.y), C.intptr_t(a.width), C.intptr_t(a.height))
	}
	c.fgetAuxResizeInfo = func(d *sizing) {
		d.neighborAlign = C.alignmentInfo(c.id, C.frame(c.id))
	}
	return c
}

type scrolledcontrol struct {
	*controlbase
	scroller			*controlbase
}

func newScrolledControl(id C.id) *scrolledcontrol {
	scroller := C.newScrollView(id)
	s := &scrolledcontrol{
		controlbase:		newControl(id),
		scroller:			newControl(scroller),
	}
	s.fsetParent = s.scroller.fsetParent
	s.fcommitResize = s.scroller.fcommitResize
	return s
}