libui/redo/unix/tab.c

126 lines
2.7 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;
};
struct tabPage {
GtkWidget *box;
2015-06-29 21:49:12 -05:00
uiControl *c;
int margined;
2015-06-11 18:07:06 -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
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);
uiControlSetParent(page->c, NULL);
2015-07-01 00:02:34 -05:00
uiControlDestroy(page->c);
gtk_widget_destroy(page->box);
2015-07-01 00:02:34 -05:00
}
g_array_free(t->pages, TRUE);
}
// TODO tabContainerUpdateState()
2015-06-11 18:07:06 -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
}
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;
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
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
}
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
uiControlSetParent(page->c, NULL);
gtk_container_remove(GTK_CONTAINER(page->box),
GTK_WIDGET(uiControlHandle(page->c)));
2015-07-01 00:02:34 -05:00
// this will also remove the tab
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
}
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
}
int uiTabMargined(uiTab *t, uintmax_t n)
2015-06-11 18:07:06 -05:00
{
struct tabPage *page;
2015-06-11 18:07:06 -05:00
page = &g_array_index(t->pages, struct tabPage, n);
return page->margined;
2015-06-11 18:07:06 -05:00
}
void uiTabSetMargined(uiTab *t, uintmax_t n, int margined)
2015-06-11 18:07:06 -05:00
{
struct tabPage *page;
2015-06-11 18:07:06 -05:00
page = &g_array_index(t->pages, struct tabPage, n);
page->margined = margined;
setMargined(GTK_CONTAINER(page->box), page->margined);
2015-06-11 18:07:06 -05:00
}
uiTab *uiNewTab(void)
{
uiTab *t;
2015-06-11 18:07:06 -05:00
t = (uiTab *) uiNewControl(uiTabType());
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
2015-06-29 21:49:12 -05:00
t->pages = g_array_new(FALSE, TRUE, sizeof (struct tabPage));
uiUnixFinishNewControl(t, uiTab);
//TODO uiControl(t)->ContainerUpdateState = tabContainerUpdateState;
2015-06-11 18:07:06 -05:00
return t;
2015-06-11 18:07:06 -05:00
}