summaryrefslogtreecommitdiff
path: root/new/tab_unix.c
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2015-04-12 01:06:42 -0400
committerPietro Gagliardi <[email protected]>2015-04-12 01:06:42 -0400
commita001448e63963ac0a70932abbf0fdc3738d972c9 (patch)
treeaf84524cd086b9767e425b6a7efcc8a06d3e95bc /new/tab_unix.c
parent499611a3fec4ac39d5ebf53c6656b2f5971d08e4 (diff)
Added uiTab to the GTK+ backend.
Diffstat (limited to 'new/tab_unix.c')
-rw-r--r--new/tab_unix.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/new/tab_unix.c b/new/tab_unix.c
new file mode 100644
index 0000000..c8d8de7
--- /dev/null
+++ b/new/tab_unix.c
@@ -0,0 +1,64 @@
+// 12 april 2015
+#include "uipriv_unix.h"
+
+struct tab {
+ struct tabPage *pages;
+ uintmax_t len;
+ uintmax_t cap;
+};
+
+struct tabPage {
+ GtkWidget *container;
+};
+
+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;
+ GtkWidget *container;
+
+ if (t->len >= t->cap) {
+ t->cap += tabCapGrow;
+ t->pages = (struct tabPage *) uiRealloc(t->pages, t->cap * sizeof (struct tabPage), "struct tabPage[]");
+ }
+
+ container = newContainer();
+ uiContainer(container)->child = child;
+ uiControlSetParent(uiContainer(container)->child, (uintptr_t) (container));
+ notebook = GTK_WIDGET(uiControlHandle(c));
+ gtk_container_add(GTK_CONTAINER(notebook), container);
+ gtk_notebook_set_tab_label_text(GTK_NOTEBOOK(notebook), container, name);
+ gtk_widget_show_all(container);
+
+ t->pages[t->len].container = container;
+ t->len++;
+}