2015-04-12 00:06:42 -05:00
|
|
|
// 12 april 2015
|
|
|
|
#include "uipriv_unix.h"
|
|
|
|
|
|
|
|
struct tab {
|
2015-04-15 21:20:25 -05:00
|
|
|
uiTab t;
|
2015-04-16 22:20:54 -05:00
|
|
|
GtkWidget *widget;
|
|
|
|
GtkContainer *container;
|
|
|
|
GtkNotebook *notebook;
|
2015-04-29 00:20:09 -05:00
|
|
|
GArray *pages;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct tabPage {
|
2015-05-10 13:05:59 -05:00
|
|
|
uiBin *bin;
|
|
|
|
// TODO remove the need for this
|
2015-04-29 00:20:09 -05:00
|
|
|
GtkWidget *binWidget;
|
2015-04-30 14:31:25 -05:00
|
|
|
int margined;
|
2015-04-12 00:06:42 -05:00
|
|
|
};
|
|
|
|
|
2015-04-18 16:14:19 -05:00
|
|
|
static void onDestroy(void *data)
|
2015-04-12 00:06:42 -05:00
|
|
|
{
|
2015-04-18 16:14:19 -05:00
|
|
|
struct tab *t = (struct tab *) data;
|
2015-04-29 00:20:09 -05:00
|
|
|
guint i;
|
2015-05-10 20:22:22 -05:00
|
|
|
struct tabPage *page;
|
2015-04-12 00:06:42 -05:00
|
|
|
|
2015-04-28 23:57:51 -05:00
|
|
|
// first hide ourselves to avoid flicker
|
|
|
|
gtk_widget_hide(t->widget);
|
|
|
|
// the pages do not have a libui parent, so we can simply destroy them
|
2015-04-29 00:26:52 -05:00
|
|
|
// we need to remove them from the tab first; see below
|
2015-04-29 00:20:09 -05:00
|
|
|
for (i = 0; i < t->pages->len; i++) {
|
2015-05-10 20:22:22 -05:00
|
|
|
page = &g_array_index(t->pages, struct tabPage, i);
|
|
|
|
uiBinRemoveOSParent(page->bin);
|
|
|
|
uiControlDestroy(uiControl(page->bin));
|
2015-04-29 00:20:09 -05:00
|
|
|
}
|
2015-04-28 23:57:51 -05:00
|
|
|
// then free ourselves
|
2015-04-29 00:20:09 -05:00
|
|
|
g_array_free(t->pages, TRUE);
|
2015-04-12 00:06:42 -05:00
|
|
|
uiFree(t);
|
|
|
|
}
|
|
|
|
|
2015-05-03 23:16:31 -05:00
|
|
|
static void tabShow(uiControl *c)
|
|
|
|
{
|
|
|
|
struct tab *t = (struct tab *) t;
|
|
|
|
|
2015-05-03 23:17:23 -05:00
|
|
|
// don't call gtk_widget_show_all() like the default handler does; that'll override user hiding of children
|
2015-05-03 23:16:31 -05:00
|
|
|
gtk_widget_show(t->widget);
|
|
|
|
}
|
|
|
|
|
2015-04-12 00:06:42 -05:00
|
|
|
#define tabCapGrow 32
|
|
|
|
|
2015-04-28 23:57:51 -05:00
|
|
|
static void tabAppendPage(uiTab *tt, const char *name, uiControl *child)
|
2015-04-12 00:06:42 -05:00
|
|
|
{
|
2015-04-15 21:20:25 -05:00
|
|
|
struct tab *t = (struct tab *) tt;
|
2015-05-10 20:22:22 -05:00
|
|
|
struct tabPage page;
|
2015-04-12 00:06:42 -05:00
|
|
|
|
2015-05-10 20:22:22 -05:00
|
|
|
page.bin = newBin();
|
|
|
|
uiBinSetMainControl(page.bin, child);
|
2015-04-28 23:57:51 -05:00
|
|
|
// and add it as a tab page
|
2015-05-10 20:22:22 -05:00
|
|
|
uiBinSetOSParent(page.bin, (uintptr_t) (t->container));
|
|
|
|
page.binWidget = GTK_WIDGET(uiControlHandle(uiControl(page.bin)));
|
|
|
|
gtk_notebook_set_tab_label_text(t->notebook, page.binWidget, name);
|
2015-04-12 00:06:42 -05:00
|
|
|
|
2015-05-10 20:22:22 -05:00
|
|
|
g_array_append_val(t->pages, page);
|
2015-04-12 00:06:42 -05:00
|
|
|
}
|
2015-04-15 21:20:25 -05:00
|
|
|
|
2015-05-06 13:32:07 -05:00
|
|
|
static void tabInsertPageBefore(uiTab *tt, const char *name, uintmax_t n, uiControl *child)
|
|
|
|
{
|
|
|
|
struct tab *t = (struct tab *) tt;
|
2015-05-10 20:22:22 -05:00
|
|
|
struct tabPage page;
|
2015-05-06 13:32:07 -05:00
|
|
|
|
2015-05-10 20:22:22 -05:00
|
|
|
page.bin = newBin();
|
|
|
|
uiBinSetMainControl(page.bin, child);
|
2015-05-06 13:32:07 -05:00
|
|
|
// and add it as a tab page
|
2015-05-10 20:22:22 -05:00
|
|
|
uiBinSetOSParent(page.bin, (uintptr_t) (t->container));
|
|
|
|
page.binWidget = GTK_WIDGET(uiControlHandle(uiControl(page.bin)));
|
|
|
|
gtk_notebook_set_tab_label_text(t->notebook, page.binWidget, name);
|
2015-05-06 13:32:07 -05:00
|
|
|
|
2015-05-10 20:22:22 -05:00
|
|
|
gtk_notebook_reorder_child(t->notebook, page.binWidget, n);
|
|
|
|
g_array_insert_val(t->pages, n, page);
|
2015-05-06 13:32:07 -05:00
|
|
|
}
|
|
|
|
|
2015-04-17 21:26:05 -05:00
|
|
|
static void tabDeletePage(uiTab *tt, uintmax_t n)
|
|
|
|
{
|
|
|
|
struct tab *t = (struct tab *) tt;
|
2015-05-10 20:22:22 -05:00
|
|
|
struct tabPage *page;
|
2015-04-17 21:26:05 -05:00
|
|
|
|
2015-05-10 20:22:22 -05:00
|
|
|
page = &g_array_index(t->pages, struct tabPage, n);
|
2015-04-17 21:26:05 -05:00
|
|
|
|
|
|
|
// make sure the page's control isn't destroyed
|
2015-05-10 20:22:22 -05:00
|
|
|
uiBinSetMainControl(page->bin, NULL);
|
2015-04-17 21:26:05 -05:00
|
|
|
|
2015-04-18 16:28:13 -05:00
|
|
|
// now destroy the page
|
|
|
|
// this will also remove the tab
|
|
|
|
// why? simple: both gtk_notebook_remove_tab() and gtk_widget_destroy() call gtk_container_remove()
|
2015-04-29 00:26:52 -05:00
|
|
|
// we need to remove them from the tab first, though, otherwise they won't really be destroyed properly
|
|
|
|
// (the GtkNotebook will still have the tab in it because its reference ISN'T destroyed, and we crash resizing a bin that no longer exists
|
2015-05-10 13:05:59 -05:00
|
|
|
// TODO redo this comment
|
2015-05-10 20:22:22 -05:00
|
|
|
uiBinRemoveOSParent(page->bin);
|
|
|
|
uiControlDestroy(uiControl(page->bin));
|
2015-04-29 00:20:09 -05:00
|
|
|
|
|
|
|
g_array_remove_index(t->pages, n);
|
2015-04-17 21:26:05 -05:00
|
|
|
}
|
|
|
|
|
2015-04-30 14:31:25 -05:00
|
|
|
static uintmax_t tabNumPages(uiTab *tt)
|
|
|
|
{
|
|
|
|
struct tab *t = (struct tab *) tt;
|
|
|
|
|
|
|
|
return t->pages->len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tabMargined(uiTab *tt, uintmax_t n)
|
|
|
|
{
|
|
|
|
struct tab *t = (struct tab *) tt;
|
2015-05-10 20:22:22 -05:00
|
|
|
struct tabPage *page;
|
2015-04-30 14:31:25 -05:00
|
|
|
|
2015-05-10 20:22:22 -05:00
|
|
|
page = &g_array_index(t->pages, struct tabPage, n);
|
|
|
|
return page->margined;
|
2015-04-30 14:31:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void tabSetMargined(uiTab *tt, uintmax_t n, int margined)
|
|
|
|
{
|
|
|
|
struct tab *t = (struct tab *) tt;
|
2015-05-10 20:22:22 -05:00
|
|
|
struct tabPage *page;
|
2015-04-30 14:31:25 -05:00
|
|
|
|
2015-05-10 20:22:22 -05:00
|
|
|
page = &g_array_index(t->pages, struct tabPage, n);
|
|
|
|
page->margined = margined;
|
|
|
|
if (page->margined)
|
|
|
|
uiBinSetMargins(page->bin, gtkXMargin, gtkYMargin, gtkXMargin, gtkYMargin);
|
2015-04-30 14:31:25 -05:00
|
|
|
else
|
2015-05-10 20:22:22 -05:00
|
|
|
uiBinSetMargins(page->bin, 0, 0, 0, 0);
|
2015-05-11 11:42:13 -05:00
|
|
|
uiContainerUpdate(page->bin);
|
2015-04-30 14:31:25 -05:00
|
|
|
}
|
|
|
|
|
2015-04-15 22:07:43 -05:00
|
|
|
uiTab *uiNewTab(void)
|
2015-04-15 21:20:25 -05:00
|
|
|
{
|
|
|
|
struct tab *t;
|
|
|
|
|
|
|
|
t = uiNew(struct tab);
|
|
|
|
|
2015-04-29 00:20:09 -05:00
|
|
|
t->pages = g_array_new(FALSE, TRUE, sizeof (struct tabPage));
|
|
|
|
|
2015-05-03 23:16:31 -05:00
|
|
|
uiControl(t)->Show = tabShow;
|
|
|
|
|
2015-04-28 23:57:51 -05:00
|
|
|
uiTab(t)->AppendPage = tabAppendPage;
|
2015-05-06 13:32:07 -05:00
|
|
|
uiTab(t)->InsertPageBefore = tabInsertPageBefore;
|
2015-04-17 21:26:05 -05:00
|
|
|
uiTab(t)->DeletePage = tabDeletePage;
|
2015-04-30 14:31:25 -05:00
|
|
|
uiTab(t)->NumPages = tabNumPages;
|
|
|
|
uiTab(t)->Margined = tabMargined;
|
|
|
|
uiTab(t)->SetMargined = tabSetMargined;
|
2015-04-15 21:20:25 -05:00
|
|
|
|
|
|
|
return uiTab(t);
|
|
|
|
}
|