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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
// 11 june 2015
#include "uipriv_unix.h"
struct uiTab {
uiUnixControl c;
GtkWidget *widget;
GtkContainer *container;
GtkNotebook *notebook;
GArray *pages; // []*struct child
};
uiUnixControlAllDefaultsExceptDestroy(uiTab)
static void uiTabDestroy(uiControl *c)
{
uiTab *t = uiTab(c);
guint i;
struct child *page;
for (i = 0; i < t->pages->len; i++) {
page = g_array_index(t->pages, struct child *, i);
childDestroy(page);
}
g_array_free(t->pages, TRUE);
// and free ourselves
g_object_unref(t->widget);
uiFreeControl(uiControl(t));
}
void uiTabAppend(uiTab *t, const char *name, uiControl *child)
{
uiTabInsertAt(t, name, t->pages->len, child);
}
void uiTabInsertAt(uiTab *t, const char *name, int n, uiControl *child)
{
struct child *page;
// this will create a tab, because of gtk_container_add()
page = newChildWithBox(child, uiControl(t), t->container, 0);
gtk_notebook_set_tab_label_text(t->notebook, childBox(page), name);
gtk_notebook_reorder_child(t->notebook, childBox(page), n);
g_array_insert_val(t->pages, n, page);
}
void uiTabDelete(uiTab *t, int n)
{
struct child *page;
page = g_array_index(t->pages, struct child *, n);
// this will remove the tab, because gtk_widget_destroy() calls gtk_container_remove()
childRemove(page);
g_array_remove_index(t->pages, n);
}
int uiTabNumPages(uiTab *t)
{
return t->pages->len;
}
int uiTabMargined(uiTab *t, int n)
{
struct child *page;
page = g_array_index(t->pages, struct child *, n);
return childFlag(page);
}
void uiTabSetMargined(uiTab *t, int n, int margined)
{
struct child *page;
page = g_array_index(t->pages, struct child *, n);
childSetFlag(page, margined);
childSetMargined(page, childFlag(page));
}
uiTab *uiNewTab(void)
{
uiTab *t;
uiUnixNewControl(uiTab, t);
t->widget = gtk_notebook_new();
t->container = GTK_CONTAINER(t->widget);
t->notebook = GTK_NOTEBOOK(t->widget);
gtk_notebook_set_scrollable(t->notebook, TRUE);
t->pages = g_array_new(FALSE, TRUE, sizeof (struct child *));
return t;
}
|