98 lines
2.0 KiB
C
Raw Normal View History

2017-07-03 06:34:21 +02:00
// 11 june 2015
#include "uipriv_unix.h"
struct uiTab {
uiUnixControl c;
GtkWidget *widget;
GtkContainer *container;
GtkNotebook *notebook;
GArray *pages; // []*struct child
};
uiUnixControlAllDefaultsExceptDestroy(uiTab)
static void uiTabDestroy(uiControl *c)
{
2017-08-12 19:51:39 -04:00
uiTab *t = uiTab(c);
2017-07-03 06:34:21 +02:00
guint i;
2017-08-12 19:51:39 -04:00
struct child *page;
2017-07-03 06:34:21 +02:00
2017-08-12 19:51:39 -04:00
for (i = 0; i < t->pages->len; i++) {
2017-07-03 06:34:21 +02:00
page = g_array_index(t->pages, struct child *, i);
childDestroy(page);
}
g_array_free(t->pages, TRUE);
2017-08-12 19:51:39 -04:00
// and free ourselves
2017-07-03 06:34:21 +02:00
g_object_unref(t->widget);
uiFreeControl(uiControl(t));
}
void uiTabAppend(uiTab *t, const char *name, uiControl *child)
{
uiTabInsertAt(t, name, t->pages->len, child);
}
void uiTabInsertAt(uiTab *t, const char *name, int n, uiControl *child)
{
2017-08-12 19:51:39 -04:00
struct child *page;
// this will create a tab, because of gtk_container_add()
page = newChildWithBox(child, uiControl(t), t->container, 0);
2017-07-03 06:34:21 +02:00
gtk_notebook_set_tab_label_text(t->notebook, childBox(page), name);
gtk_notebook_reorder_child(t->notebook, childBox(page), n);
g_array_insert_val(t->pages, n, page);
}
void uiTabDelete(uiTab *t, int n)
{
2017-08-12 19:51:39 -04:00
struct child *page;
2017-07-03 06:34:21 +02:00
2017-08-12 19:51:39 -04:00
page = g_array_index(t->pages, struct child *, n);
// this will remove the tab, because gtk_widget_destroy() calls gtk_container_remove()
2017-07-03 06:34:21 +02:00
childRemove(page);
g_array_remove_index(t->pages, n);
}
int uiTabNumPages(uiTab *t)
{
return t->pages->len;
}
int uiTabMargined(uiTab *t, int n)
{
2017-08-12 19:51:39 -04:00
struct child *page;
2017-07-03 06:34:21 +02:00
2017-08-12 19:51:39 -04:00
page = g_array_index(t->pages, struct child *, n);
2017-07-03 06:34:21 +02:00
return childFlag(page);
}
void uiTabSetMargined(uiTab *t, int n, int margined)
{
2017-08-12 19:51:39 -04:00
struct child *page;
2017-07-03 06:34:21 +02:00
2017-08-12 19:51:39 -04:00
page = g_array_index(t->pages, struct child *, n);
2017-07-03 06:34:21 +02:00
childSetFlag(page, margined);
childSetMargined(page, childFlag(page));
}
uiTab *uiNewTab(void)
{
2017-08-12 19:51:39 -04:00
uiTab *t;
2017-07-03 06:34:21 +02:00
uiUnixNewControl(uiTab, t);
2017-08-12 19:51:39 -04:00
t->widget = gtk_notebook_new();
2017-07-03 06:34:21 +02:00
t->container = GTK_CONTAINER(t->widget);
2017-08-12 19:51:39 -04:00
t->notebook = GTK_NOTEBOOK(t->widget);
2017-07-03 06:34:21 +02:00
gtk_notebook_set_scrollable(t->notebook, TRUE);
t->pages = g_array_new(FALSE, TRUE, sizeof (struct child *));
return t;
}