2015-04-12 00:06:42 -05:00
|
|
|
// 12 april 2015
|
|
|
|
#include "uipriv_unix.h"
|
|
|
|
|
|
|
|
struct tab {
|
2015-04-15 21:20:25 -05:00
|
|
|
uiTab t;
|
2015-04-13 11:05:14 -05:00
|
|
|
uiParent **pages;
|
2015-04-12 00:06:42 -05:00
|
|
|
uintmax_t len;
|
|
|
|
uintmax_t cap;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void onDestroy(GtkWidget *widget, gpointer data)
|
|
|
|
{
|
|
|
|
struct tab *t = (struct tab *) data;
|
|
|
|
|
|
|
|
uiFree(t->pages);
|
|
|
|
uiFree(t);
|
|
|
|
}
|
|
|
|
|
2015-04-15 21:20:25 -05:00
|
|
|
#define TAB(t) GTK_NOTEBOOK(uiControlHandle(uiControl(t)))
|
2015-04-12 00:06:42 -05:00
|
|
|
|
|
|
|
#define tabCapGrow 32
|
|
|
|
|
2015-04-15 21:20:25 -05:00
|
|
|
static void addPage(uiTab *tt, const char *name, uiControl *child)
|
2015-04-12 00:06:42 -05:00
|
|
|
{
|
2015-04-15 21:20:25 -05:00
|
|
|
struct tab *t = (struct tab *) tt;
|
2015-04-12 00:06:42 -05:00
|
|
|
GtkWidget *notebook;
|
2015-04-13 11:05:14 -05:00
|
|
|
uiParent *content;
|
2015-04-12 00:06:42 -05:00
|
|
|
|
|
|
|
if (t->len >= t->cap) {
|
|
|
|
t->cap += tabCapGrow;
|
2015-04-13 11:05:14 -05:00
|
|
|
t->pages = (uiParent **) uiRealloc(t->pages, t->cap * sizeof (uiParent *), "uiParent *[]");
|
2015-04-12 00:06:42 -05:00
|
|
|
}
|
|
|
|
|
2015-04-15 22:07:43 -05:00
|
|
|
notebook = GTK_WIDGET(TAB(t));
|
2015-04-13 11:05:14 -05:00
|
|
|
content = uiNewParent((uintptr_t) notebook);
|
|
|
|
uiParentSetChild(content, child);
|
|
|
|
uiParentUpdate(content);
|
2015-04-13 11:12:00 -05:00
|
|
|
gtk_notebook_set_tab_label_text(GTK_NOTEBOOK(notebook), GTK_WIDGET(uiParentHandle(content)), name);
|
2015-04-12 00:06:42 -05:00
|
|
|
|
2015-04-13 11:05:14 -05:00
|
|
|
t->pages[t->len] = content;
|
2015-04-12 00:06:42 -05:00
|
|
|
t->len++;
|
|
|
|
}
|
2015-04-15 21:20:25 -05:00
|
|
|
|
2015-04-15 22:07:43 -05:00
|
|
|
uiTab *uiNewTab(void)
|
2015-04-15 21:20:25 -05:00
|
|
|
{
|
|
|
|
struct tab *t;
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
|
|
t = uiNew(struct tab);
|
|
|
|
|
|
|
|
uiUnixNewControl(uiControl(t), GTK_TYPE_NOTEBOOK,
|
|
|
|
FALSE, FALSE,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
widget = GTK_WIDGET(TAB(t));
|
|
|
|
g_signal_connect(widget, "destroy", G_CALLBACK(onDestroy), t);
|
|
|
|
|
|
|
|
uiTab(t)->AddPage = addPage;
|
|
|
|
|
|
|
|
return uiTab(t);
|
|
|
|
}
|