2015-06-11 18:07:06 -05:00
|
|
|
// 11 june 2015
|
|
|
|
#include "uipriv_unix.h"
|
|
|
|
|
|
|
|
struct tab {
|
|
|
|
uiTab t;
|
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;
|
2015-07-01 00:02:34 -05:00
|
|
|
|
|
|
|
void (*baseCommitDestroy)(uiControl *);
|
2015-06-29 21:49:12 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
struct tabPage {
|
2015-06-30 21:36:12 -05:00
|
|
|
uiControl *bin;
|
|
|
|
GtkWidget *binWidget;
|
2015-06-29 21:49:12 -05:00
|
|
|
uiControl *c;
|
2015-06-11 18:07:06 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
uiDefineControlType(uiTab, uiTypeTab, struct tab)
|
|
|
|
|
2015-07-01 00:02:34 -05:00
|
|
|
static void tabCommitDestroy(uiControl *c)
|
|
|
|
{
|
|
|
|
struct tab *t = (struct tab *) c;
|
|
|
|
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);
|
|
|
|
binSetChild(page->bin, NULL);
|
|
|
|
uiControlDestroy(page->c);
|
|
|
|
uiControlSetParent(page->bin, NULL);
|
|
|
|
uiControlDestroy(page->bin);
|
|
|
|
}
|
|
|
|
// then free ourselves
|
|
|
|
g_array_free(t->pages, TRUE);
|
|
|
|
(*(t->baseCommitDestroy))(uiControl(t));
|
|
|
|
}
|
|
|
|
|
2015-06-11 18:07:06 -05:00
|
|
|
static uintptr_t tabHandle(uiControl *c)
|
|
|
|
{
|
|
|
|
struct tab *t = (struct tab *) c;
|
|
|
|
|
|
|
|
return (uintptr_t) (t->widget);
|
|
|
|
}
|
|
|
|
|
2015-07-29 12:29:32 -05:00
|
|
|
// TODO tabContainerUpdateState()?
|
2015-07-29 11:28:13 -05:00
|
|
|
|
2015-06-11 18:07:06 -05:00
|
|
|
static void tabAppend(uiTab *tt, const char *name, uiControl *child)
|
|
|
|
{
|
|
|
|
struct tab *t = (struct tab *) tt;
|
|
|
|
|
2015-06-29 21:49:12 -05:00
|
|
|
uiTabInsertAt(tt, name, t->pages->len, child);
|
2015-06-11 18:07:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void tabInsertAt(uiTab *tt, const char *name, uintmax_t n, uiControl *child)
|
|
|
|
{
|
|
|
|
struct tab *t = (struct tab *) tt;
|
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-06-30 21:36:12 -05:00
|
|
|
page.bin = newBin();
|
|
|
|
page.binWidget = GTK_WIDGET(uiControlHandle(page.bin));
|
|
|
|
binSetChild(page.bin, page.c);
|
2015-06-29 21:49:12 -05:00
|
|
|
|
2015-06-30 21:36:12 -05:00
|
|
|
uiControlSetParent(page.bin, uiControl(t));
|
|
|
|
gtk_notebook_set_tab_label_text(t->notebook, page.binWidget, name);
|
|
|
|
gtk_notebook_reorder_child(t->notebook, page.binWidget, 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
|
|
|
}
|
|
|
|
|
|
|
|
static void tabDelete(uiTab *tt, uintmax_t n)
|
|
|
|
{
|
|
|
|
struct tab *t = (struct tab *) tt;
|
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
|
|
|
|
binSetChild(page->bin, NULL);
|
|
|
|
|
|
|
|
// 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()
|
|
|
|
// 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)
|
|
|
|
// TODO redo this comment
|
|
|
|
uiControlSetParent(page->bin, NULL);
|
|
|
|
uiControlDestroy(page->bin);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static uintmax_t tabNumPages(uiTab *tt)
|
|
|
|
{
|
|
|
|
struct tab *t = (struct tab *) tt;
|
|
|
|
|
2015-06-29 21:49:12 -05:00
|
|
|
return t->pages->len;
|
2015-06-11 18:07:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static int tabMargined(uiTab *tt, uintmax_t n)
|
|
|
|
{
|
|
|
|
struct tab *t = (struct tab *) tt;
|
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);
|
|
|
|
return binMargined(page->bin);
|
2015-06-11 18:07:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void tabSetMargined(uiTab *tt, uintmax_t n, int margined)
|
|
|
|
{
|
|
|
|
struct tab *t = (struct tab *) tt;
|
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);
|
|
|
|
binSetMargined(page->bin, margined);
|
2015-06-11 18:07:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
uiTab *uiNewTab(void)
|
|
|
|
{
|
|
|
|
struct tab *t;
|
|
|
|
|
2015-06-14 19:02:38 -05:00
|
|
|
t = (struct tab *) uiNewControl(uiTypeTab());
|
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);
|
|
|
|
uiUnixMakeSingleWidgetControl(uiControl(t), 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-06-11 18:07:06 -05:00
|
|
|
uiControl(t)->Handle = tabHandle;
|
2015-07-01 00:02:34 -05:00
|
|
|
t->baseCommitDestroy = uiControl(t)->CommitDestroy;
|
|
|
|
uiControl(t)->CommitDestroy = tabCommitDestroy;
|
2015-06-11 18:07:06 -05:00
|
|
|
|
|
|
|
uiTab(t)->Append = tabAppend;
|
|
|
|
uiTab(t)->InsertAt = tabInsertAt;
|
|
|
|
uiTab(t)->Delete = tabDelete;
|
|
|
|
uiTab(t)->NumPages = tabNumPages;
|
|
|
|
uiTab(t)->Margined = tabMargined;
|
|
|
|
uiTab(t)->SetMargined = tabSetMargined;
|
|
|
|
|
|
|
|
return uiTab(t);
|
|
|
|
}
|