libui/unix/tab.c

63 lines
1.2 KiB
C
Raw Normal View History

2015-04-12 00:06:42 -05:00
// 12 april 2015
#include "uipriv_unix.h"
struct tab {
uiTab t;
2015-04-16 22:20:54 -05:00
GtkWidget *widget;
GtkContainer *container;
GtkNotebook *notebook;
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);
}
#define tabCapGrow 32
2015-04-16 22:20:54 -05:00
static void tabAddPage(uiTab *tt, const char *name, uiControl *child)
2015-04-12 00:06:42 -05:00
{
struct tab *t = (struct tab *) tt;
uiParent *content;
2015-04-12 00:06:42 -05:00
if (t->len >= t->cap) {
t->cap += tabCapGrow;
t->pages = (uiParent **) uiRealloc(t->pages, t->cap * sizeof (uiParent *), "uiParent *[]");
2015-04-12 00:06:42 -05:00
}
2015-04-16 22:20:54 -05:00
content = uiNewParent((uintptr_t) (t->container));
uiParentSetChild(content, child);
uiParentUpdate(content);
2015-04-16 22:20:54 -05:00
gtk_notebook_set_tab_label_text(t->notebook, GTK_WIDGET(uiParentHandle(content)), name);
2015-04-12 00:06:42 -05:00
t->pages[t->len] = content;
2015-04-12 00:06:42 -05:00
t->len++;
}
uiTab *uiNewTab(void)
{
struct tab *t;
t = uiNew(struct tab);
uiUnixNewControl(uiControl(t), GTK_TYPE_NOTEBOOK,
FALSE, FALSE,
NULL);
2015-04-16 22:20:54 -05:00
t->widget = WIDGET(t);
t->container = GTK_CONTAINER(t->widget);
t->notebook = GTK_NOTEBOOK(t->widget);
g_signal_connect(t->widget, "destroy", G_CALLBACK(onDestroy), t);
2015-04-16 22:20:54 -05:00
uiTab(t)->AddPage = tabAddPage;
return uiTab(t);
}