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
|
|
|
|
|
|
|
GArray *pages;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct tabPage {
|
2015-08-28 08:56:41 -05:00
|
|
|
GtkWidget *box;
|
2015-06-29 21:49:12 -05:00
|
|
|
uiControl *c;
|
2015-08-28 08:56:41 -05:00
|
|
|
int margined;
|
2015-06-11 18:07:06 -05:00
|
|
|
};
|
|
|
|
|
2015-08-28 08:56:41 -05:00
|
|
|
static void onDestroy(uiTab *);
|
|
|
|
|
|
|
|
uiUnixDefineControlWithOnDestroy(
|
|
|
|
uiTab, // type name
|
|
|
|
uiTabType, // type function
|
|
|
|
onDestroy(this); // on destroy
|
|
|
|
)
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2015-08-28 08:56:41 -05:00
|
|
|
static void onDestroy(uiTab *t)
|
2015-07-01 00:02:34 -05:00
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
struct tabPage *page;
|
|
|
|
|
|
|
|
// the pages do not have a libui parent, so we can simply destroy them
|
|
|
|
// we need to remove them from the tab first; see below
|
|
|
|
for (i = 0; i < t->pages->len; i++) {
|
|
|
|
page = &g_array_index(t->pages, struct tabPage, i);
|
2015-08-28 08:56:41 -05:00
|
|
|
uiControlSetParent(page->c, NULL);
|
2015-07-01 00:02:34 -05:00
|
|
|
uiControlDestroy(page->c);
|
2015-08-28 08:56:41 -05:00
|
|
|
gtk_widget_destroy(page->box);
|
2015-07-01 00:02:34 -05:00
|
|
|
}
|
|
|
|
g_array_free(t->pages, TRUE);
|
|
|
|
}
|
|
|
|
|
2015-08-28 08:56:41 -05:00
|
|
|
// TODO tabContainerUpdateState()
|
2015-06-11 18:07:06 -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
|
|
|
}
|
|
|
|
|
2015-08-28 08:56:41 -05:00
|
|
|
void uiTabInsertAt(uiTab *t, const char *name, uintmax_t n, uiControl *child)
|
2015-06-11 18:07:06 -05:00
|
|
|
{
|
2015-06-29 21:49:12 -05:00
|
|
|
struct tabPage page;
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2015-06-29 21:49:12 -05:00
|
|
|
page.c = child;
|
2015-08-28 08:56:41 -05:00
|
|
|
page.box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
|
|
|
|
gtk_container_add(GTK_CONTAINER(page.box),
|
|
|
|
GTK_WIDGET(uiControlHandle(page.c)));
|
2015-08-28 09:43:53 -05:00
|
|
|
gtk_widget_show(page.box);
|
2015-06-29 21:49:12 -05:00
|
|
|
|
2015-08-28 08:56:41 -05:00
|
|
|
gtk_container_add(t->container, page.box);
|
|
|
|
gtk_notebook_set_tab_label_text(t->notebook, page.box, name);
|
|
|
|
gtk_notebook_reorder_child(t->notebook, page.box, 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
|
|
|
}
|
|
|
|
|
2015-08-28 08:56:41 -05:00
|
|
|
void uiTabDelete(uiTab *t, uintmax_t n)
|
2015-06-11 18:07:06 -05:00
|
|
|
{
|
2015-07-01 00:02:34 -05:00
|
|
|
struct tabPage *page;
|
|
|
|
|
|
|
|
page = &g_array_index(t->pages, struct tabPage, n);
|
|
|
|
|
|
|
|
// make sure the page's control isn't destroyed
|
2015-08-28 08:56:41 -05:00
|
|
|
uiControlSetParent(page->c, NULL);
|
|
|
|
gtk_container_remove(GTK_CONTAINER(page->box),
|
2015-08-28 09:30:42 -05:00
|
|
|
GTK_WIDGET(uiControlHandle(page->c)));
|
2015-07-01 00:02:34 -05:00
|
|
|
|
|
|
|
// this will also remove the tab
|
2015-08-28 08:56:41 -05:00
|
|
|
gtk_widget_destroy(page->box);
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2015-07-01 00:02:34 -05:00
|
|
|
g_array_remove_index(t->pages, n);
|
2015-06-11 18:07:06 -05:00
|
|
|
}
|
|
|
|
|
2015-08-28 08:56:41 -05:00
|
|
|
uintmax_t 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
|
|
|
}
|
|
|
|
|
2015-08-28 08:56:41 -05:00
|
|
|
int uiTabMargined(uiTab *t, uintmax_t n)
|
2015-06-11 18:07:06 -05:00
|
|
|
{
|
2015-06-30 21:36:12 -05:00
|
|
|
struct tabPage *page;
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2015-06-30 21:36:12 -05:00
|
|
|
page = &g_array_index(t->pages, struct tabPage, n);
|
2015-08-28 08:56:41 -05:00
|
|
|
return page->margined;
|
2015-06-11 18:07:06 -05:00
|
|
|
}
|
|
|
|
|
2015-08-28 08:56:41 -05:00
|
|
|
void uiTabSetMargined(uiTab *t, uintmax_t n, int margined)
|
2015-06-11 18:07:06 -05:00
|
|
|
{
|
2015-06-30 21:36:12 -05:00
|
|
|
struct tabPage *page;
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2015-06-30 21:36:12 -05:00
|
|
|
page = &g_array_index(t->pages, struct tabPage, n);
|
2015-08-28 08:56:41 -05:00
|
|
|
page->margined = margined;
|
|
|
|
setMargined(GTK_CONTAINER(page->box), page->margined);
|
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
|
|
|
|
2015-08-28 09:10:52 -05:00
|
|
|
t = (uiTab *) uiNewControl(uiTabType());
|
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
|
|
|
|
2015-06-29 21:49:12 -05:00
|
|
|
t->pages = g_array_new(FALSE, TRUE, sizeof (struct tabPage));
|
|
|
|
|
2015-08-28 08:56:41 -05:00
|
|
|
uiUnixFinishNewControl(t, uiTab);
|
|
|
|
//TODO uiControl(t)->ContainerUpdateState = tabContainerUpdateState;
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2015-08-28 08:56:41 -05:00
|
|
|
return t;
|
2015-06-11 18:07:06 -05:00
|
|
|
}
|