summaryrefslogtreecommitdiff
path: root/redo/containers_unix.go
blob: 20d1bef383b80aac162a246800f3725520284f4d (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
// 25 july 2014

package ui

import (
	"unsafe"
)

// #include "gtk_unix.h"
// extern void layoutResizing(GtkWidget *, GdkRectangle *, gpointer);
import "C"

type tab struct {
	*widgetbase
	notebook		*C.GtkNotebook

	containers	[]*container
	layoutws		[]*C.GtkWidget
	layoutcs		[]*C.GtkContainer
	layouts		[]*C.GtkLayout
}

func newTab() Tab {
	widget := C.gtk_notebook_new()
	t := &tab{
		widgetbase:	newWidget(widget),
		notebook:		(*C.GtkNotebook)(unsafe.Pointer(widget)),
	}
	return t
}

func (t *tab) Append(name string, control Control) {
	// TODO isolate and standardize
	layout := C.gtk_layout_new(nil, nil)
	t.layoutws = append(t.layoutws, layout)
	t.layoutcs = append(t.layoutcs, (*C.GtkContainer)(unsafe.Pointer(layout)))
	t.layouts = append(t.layouts, (*C.GtkLayout)(unsafe.Pointer(layout)))
	c := new(container)
	c.beginResize = beginResize
	t.containers = append(t.containers, c)
	c.child = control
	c.child.setParent((*C.GtkContainer)(unsafe.Pointer(layout)))
	g_signal_connect_after(
		C.gpointer(unsafe.Pointer(layout)),
		"size-allocate",
		C.GCallback(C.layoutResizing),
		C.gpointer(unsafe.Pointer(c)))
	cname := togstr(name)
	defer freegstr(cname)
	tab := C.gtk_notebook_append_page(t.notebook,
		layout,
		C.gtk_label_new(cname))
	if tab == -1 {
		panic("gtk_notebook_append_page() failed")
	}
}

//export layoutResizing
func layoutResizing(wid *C.GtkWidget, r *C.GdkRectangle, data C.gpointer) {
	c := (*container)(unsafe.Pointer(data))
	c.resize(int(r.width), int(r.height))
}