2015-06-11 18:07:06 -05:00
|
|
|
// 11 june 2015
|
|
|
|
#include "uipriv_unix.h"
|
|
|
|
|
2015-08-28 08:56:41 -05:00
|
|
|
struct uiTab {
|
|
|
|
uiUnixControl c;
|
2015-06-26 20:52:42 -05:00
|
|
|
|
2015-06-11 18:07:06 -05:00
|
|
|
GtkWidget *widget;
|
2015-06-26 20:52:42 -05:00
|
|
|
GtkContainer *container;
|
|
|
|
GtkNotebook *notebook;
|
2015-06-29 21:49:12 -05:00
|
|
|
|
2018-05-12 12:03:55 -05:00
|
|
|
GArray *pages; // []*uiprivChild
|
2015-06-11 18:07:06 -05:00
|
|
|
};
|
|
|
|
|
2016-04-25 19:15:02 -05:00
|
|
|
uiUnixControlAllDefaultsExceptDestroy(uiTab)
|
2015-08-28 08:56:41 -05:00
|
|
|
|
2016-04-25 19:15:02 -05:00
|
|
|
static void uiTabDestroy(uiControl *c)
|
2015-07-01 00:02:34 -05:00
|
|
|
{
|
2016-04-25 19:15:02 -05:00
|
|
|
uiTab *t = uiTab(c);
|
2015-07-01 00:02:34 -05:00
|
|
|
guint i;
|
2018-05-12 12:03:55 -05:00
|
|
|
uiprivChild *page;
|
2015-07-01 00:02:34 -05:00
|
|
|
|
|
|
|
for (i = 0; i < t->pages->len; i++) {
|
2018-05-12 12:03:55 -05:00
|
|
|
page = g_array_index(t->pages, uiprivChild *, i);
|
|
|
|
uiprivChildDestroy(page);
|
2015-07-01 00:02:34 -05:00
|
|
|
}
|
|
|
|
g_array_free(t->pages, TRUE);
|
2016-04-25 19:15:02 -05:00
|
|
|
// and free ourselves
|
|
|
|
g_object_unref(t->widget);
|
2016-04-25 19:34:12 -05:00
|
|
|
uiFreeControl(uiControl(t));
|
2015-07-01 00:02:34 -05:00
|
|
|
}
|
|
|
|
|
2015-08-28 08:56:41 -05:00
|
|
|
void uiTabAppend(uiTab *t, const char *name, uiControl *child)
|
2015-06-11 18:07:06 -05:00
|
|
|
{
|
2015-08-28 08:56:41 -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
|
|
|
{
|
2018-05-12 12:03:55 -05:00
|
|
|
uiprivChild *page;
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2015-08-28 15:50:55 -05:00
|
|
|
// this will create a tab, because of gtk_container_add()
|
2018-05-12 12:03:55 -05:00
|
|
|
page = uiprivNewChildWithBox(child, uiControl(t), t->container, 0);
|
2015-06-29 21:49:12 -05:00
|
|
|
|
2018-05-12 12:03:55 -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
|
|
|
{
|
2018-05-12 12:03:55 -05:00
|
|
|
uiprivChild *page;
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2018-05-12 12:03:55 -05:00
|
|
|
page = g_array_index(t->pages, uiprivChild *, n);
|
2015-08-28 15:50:55 -05:00
|
|
|
// this will remove the tab, because gtk_widget_destroy() calls gtk_container_remove()
|
2018-05-12 12:03:55 -05:00
|
|
|
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
|
|
|
{
|
2018-05-12 12:03:55 -05:00
|
|
|
uiprivChild *page;
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2018-05-12 12:03:55 -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
|
|
|
{
|
2018-05-12 12:03:55 -05:00
|
|
|
uiprivChild *page;
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2018-05-12 12:03:55 -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)
|
|
|
|
{
|
2015-08-28 08:56:41 -05:00
|
|
|
uiTab *t;
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2016-04-25 19:15:02 -05:00
|
|
|
uiUnixNewControl(uiTab, t);
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2015-06-26 20:52:42 -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
|
|
|
|
2018-05-12 12:03:55 -05:00
|
|
|
t->pages = g_array_new(FALSE, TRUE, sizeof (uiprivChild *));
|
2015-06-29 21:49:12 -05:00
|
|
|
|
2015-08-28 08:56:41 -05:00
|
|
|
return t;
|
2015-06-11 18:07:06 -05:00
|
|
|
}
|