summaryrefslogtreecommitdiff
path: root/new/unix/tab.c
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2015-04-15 18:49:45 -0400
committerPietro Gagliardi <[email protected]>2015-04-15 18:49:45 -0400
commit518a5ddbf15d50a254c732a80d5907ef8878abe0 (patch)
tree48cf259f98994e4570e65c389fcd9824272884ad /new/unix/tab.c
parent50ae3ca045e7f5f5744043df0a4506e2f6930bb1 (diff)
Split all OS backends into their own folders.
Diffstat (limited to 'new/unix/tab.c')
-rw-r--r--new/unix/tab.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/new/unix/tab.c b/new/unix/tab.c
new file mode 100644
index 0000000..dd69e4c
--- /dev/null
+++ b/new/unix/tab.c
@@ -0,0 +1,58 @@
+// 12 april 2015
+#include "uipriv_unix.h"
+
+struct tab {
+ uiParent **pages;
+ uintmax_t len;
+ uintmax_t cap;
+};
+
+static void onDestroy(GtkWidget *widget, gpointer data)
+{
+ struct tab *t = (struct tab *) data;
+
+ uiFree(t->pages);
+ uiFree(t);
+}
+
+uiControl *uiNewTab(void)
+{
+ uiControl *c;
+ struct tab *t;
+ GtkWidget *widget;
+
+ c = uiUnixNewControl(GTK_TYPE_NOTEBOOK,
+ FALSE, FALSE,
+ NULL);
+
+ widget = GTK_WIDGET(uiControlHandle(c));
+
+ t = uiNew(struct tab);
+ g_signal_connect(widget, "destroy", G_CALLBACK(onDestroy), t);
+ c->data = t;
+
+ return c;
+}
+
+#define tabCapGrow 32
+
+void uiTabAddPage(uiControl *c, const char *name, uiControl *child)
+{
+ struct tab *t = (struct tab *) (c->data);
+ GtkWidget *notebook;
+ uiParent *content;
+
+ if (t->len >= t->cap) {
+ t->cap += tabCapGrow;
+ t->pages = (uiParent **) uiRealloc(t->pages, t->cap * sizeof (uiParent *), "uiParent *[]");
+ }
+
+ notebook = GTK_WIDGET(uiControlHandle(c));
+ content = uiNewParent((uintptr_t) notebook);
+ uiParentSetChild(content, child);
+ uiParentUpdate(content);
+ gtk_notebook_set_tab_label_text(GTK_NOTEBOOK(notebook), GTK_WIDGET(uiParentHandle(content)), name);
+
+ t->pages[t->len] = content;
+ t->len++;
+}