libui/zOLD_unix/tab.c

98 lines
2.0 KiB
C
Raw Normal View History

2015-06-11 18:07:06 -05:00
// 11 june 2015
#include "uipriv_unix.h"
struct uiTab {
uiUnixControl c;
2015-06-11 18:07:06 -05:00
GtkWidget *widget;
GtkContainer *container;
GtkNotebook *notebook;
2015-06-29 21:49:12 -05:00
GArray *pages; // []*uiprivChild
2015-06-11 18:07:06 -05:00
};
uiUnixControlAllDefaultsExceptDestroy(uiTab)
static void uiTabDestroy(uiControl *c)
2015-07-01 00:02:34 -05:00
{
uiTab *t = uiTab(c);
2015-07-01 00:02:34 -05:00
guint i;
uiprivChild *page;
2015-07-01 00:02:34 -05:00
for (i = 0; i < t->pages->len; i++) {
page = g_array_index(t->pages, uiprivChild *, i);
uiprivChildDestroy(page);
2015-07-01 00:02:34 -05:00
}
g_array_free(t->pages, TRUE);
// and free ourselves
g_object_unref(t->widget);
uiFreeControl(uiControl(t));
2015-07-01 00:02:34 -05:00
}
void uiTabAppend(uiTab *t, const char *name, uiControl *child)
2015-06-11 18:07:06 -05:00
{
uiTabInsertAt(t, name, t->pages->len, child);
2015-06-11 18:07:06 -05:00
}
2016-06-13 19:55:50 -05:00
void uiTabInsertAt(uiTab *t, const char *name, int n, uiControl *child)
2015-06-11 18:07:06 -05:00
{
uiprivChild *page;
2015-06-11 18:07:06 -05:00
// this will create a tab, because of gtk_container_add()
page = uiprivNewChildWithBox(child, uiControl(t), t->container, 0);
2015-06-29 21:49:12 -05:00
gtk_notebook_set_tab_label_text(t->notebook, uiprivChildBox(page), name);
gtk_notebook_reorder_child(t->notebook, uiprivChildBox(page), n);
2015-06-29 21:49:12 -05:00
g_array_insert_val(t->pages, n, page);
2015-06-11 18:07:06 -05:00
}
2016-06-13 19:55:50 -05:00
void uiTabDelete(uiTab *t, int n)
2015-06-11 18:07:06 -05:00
{
uiprivChild *page;
2015-06-11 18:07:06 -05:00
page = g_array_index(t->pages, uiprivChild *, n);
// this will remove the tab, because gtk_widget_destroy() calls gtk_container_remove()
uiprivChildRemove(page);
2015-07-01 00:02:34 -05:00
g_array_remove_index(t->pages, n);
2015-06-11 18:07:06 -05:00
}
2016-06-13 19:55:50 -05:00
int uiTabNumPages(uiTab *t)
2015-06-11 18:07:06 -05:00
{
2015-06-29 21:49:12 -05:00
return t->pages->len;
2015-06-11 18:07:06 -05:00
}
2016-06-13 19:55:50 -05:00
int uiTabMargined(uiTab *t, int n)
2015-06-11 18:07:06 -05:00
{
uiprivChild *page;
2015-06-11 18:07:06 -05:00
page = g_array_index(t->pages, uiprivChild *, n);
return uiprivChildFlag(page);
2015-06-11 18:07:06 -05:00
}
2016-06-13 19:55:50 -05:00
void uiTabSetMargined(uiTab *t, int n, int margined)
2015-06-11 18:07:06 -05:00
{
uiprivChild *page;
2015-06-11 18:07:06 -05:00
page = g_array_index(t->pages, uiprivChild *, n);
uiprivChildSetFlag(page, margined);
uiprivChildSetMargined(page, uiprivChildFlag(page));
2015-06-11 18:07:06 -05:00
}
uiTab *uiNewTab(void)
{
uiTab *t;
2015-06-11 18:07:06 -05:00
uiUnixNewControl(uiTab, t);
2015-06-11 18:07:06 -05:00
t->widget = gtk_notebook_new();
t->container = GTK_CONTAINER(t->widget);
t->notebook = GTK_NOTEBOOK(t->widget);
gtk_notebook_set_scrollable(t->notebook, TRUE);
2015-06-11 18:07:06 -05:00
t->pages = g_array_new(FALSE, TRUE, sizeof (uiprivChild *));
2015-06-29 21:49:12 -05:00
return t;
2015-06-11 18:07:06 -05:00
}