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-16 22:20:54 -05:00
|
|
|
GtkWidget *widget;
|
|
|
|
GtkContainer *container;
|
|
|
|
GtkNotebook *notebook;
|
2015-04-13 11:05:14 -05:00
|
|
|
uiParent **pages;
|
2015-04-12 00:06:42 -05:00
|
|
|
uintmax_t len;
|
|
|
|
uintmax_t cap;
|
|
|
|
};
|
|
|
|
|
2015-04-18 16:14:19 -05:00
|
|
|
static void onDestroy(void *data)
|
2015-04-12 00:06:42 -05:00
|
|
|
{
|
2015-04-18 16:14:19 -05:00
|
|
|
struct tab *t = (struct tab *) data;
|
2015-04-18 12:43:05 -05:00
|
|
|
uintmax_t i;
|
2015-04-12 00:06:42 -05:00
|
|
|
|
2015-04-18 12:43:05 -05:00
|
|
|
for (i = 0; i < t->len; i++)
|
|
|
|
uiParentDestroy(t->pages[i]);
|
2015-04-12 00:06:42 -05:00
|
|
|
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
|
|
|
{
|
2015-04-15 21:20:25 -05:00
|
|
|
struct tab *t = (struct tab *) tt;
|
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-16 22:20:54 -05:00
|
|
|
content = uiNewParent((uintptr_t) (t->container));
|
2015-04-17 12:43:01 -05:00
|
|
|
uiParentSetMainControl(content, child);
|
2015-04-13 11:05:14 -05:00
|
|
|
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
|
|
|
|
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-17 21:26:05 -05:00
|
|
|
static void tabDeletePage(uiTab *tt, uintmax_t n)
|
|
|
|
{
|
|
|
|
struct tab *t = (struct tab *) tt;
|
|
|
|
uiParent *p;
|
|
|
|
uintmax_t i;
|
|
|
|
|
|
|
|
p = t->pages[n];
|
|
|
|
for (i = n; i < t->len - 1; i++)
|
|
|
|
t->pages[i] = t->pages[i + 1];
|
|
|
|
t->pages[i] = NULL;
|
|
|
|
t->len--;
|
|
|
|
|
|
|
|
// make sure the page's control isn't destroyed
|
|
|
|
uiParentSetMainControl(p, NULL);
|
|
|
|
|
2015-04-18 16:28:13 -05:00
|
|
|
// now destroy the page
|
|
|
|
// this will also remove the tab
|
|
|
|
// why? simple: both gtk_notebook_remove_tab() and gtk_widget_destroy() call gtk_container_remove()
|
|
|
|
uiParentDestroy(p);
|
2015-04-17 21:26:05 -05:00
|
|
|
}
|
|
|
|
|
2015-04-15 22:07:43 -05:00
|
|
|
uiTab *uiNewTab(void)
|
2015-04-15 21:20:25 -05:00
|
|
|
{
|
|
|
|
struct tab *t;
|
|
|
|
|
|
|
|
t = uiNew(struct tab);
|
|
|
|
|
|
|
|
uiUnixNewControl(uiControl(t), GTK_TYPE_NOTEBOOK,
|
2015-04-18 16:14:19 -05:00
|
|
|
FALSE, FALSE, onDestroy, t,
|
2015-04-15 21:20:25 -05:00
|
|
|
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);
|
|
|
|
|
|
|
|
uiTab(t)->AddPage = tabAddPage;
|
2015-04-17 21:26:05 -05:00
|
|
|
uiTab(t)->DeletePage = tabDeletePage;
|
2015-04-15 21:20:25 -05:00
|
|
|
|
|
|
|
return uiTab(t);
|
|
|
|
}
|