Added the GTK+ implementation of uiTab, for the most part I think.
This commit is contained in:
parent
ca1103e347
commit
390899f803
|
@ -7,6 +7,7 @@ osCFILES = \
|
||||||
unix/main.c \
|
unix/main.c \
|
||||||
unix/menu.c \
|
unix/menu.c \
|
||||||
unix/newcontrol.c \
|
unix/newcontrol.c \
|
||||||
|
unix/tab.c \
|
||||||
unix/text.c \
|
unix/text.c \
|
||||||
unix/util.c \
|
unix/util.c \
|
||||||
unix/window.c
|
unix/window.c
|
||||||
|
|
|
@ -6,7 +6,8 @@ struct tab {
|
||||||
GtkWidget *widget;
|
GtkWidget *widget;
|
||||||
GtkContainer *container;
|
GtkContainer *container;
|
||||||
GtkNotebook *notebook;
|
GtkNotebook *notebook;
|
||||||
uiParent **pages;
|
// TODO switch to GArray or GPtrArray
|
||||||
|
uiContainer **pages;
|
||||||
uintmax_t len;
|
uintmax_t len;
|
||||||
uintmax_t cap;
|
uintmax_t cap;
|
||||||
};
|
};
|
||||||
|
@ -16,52 +17,61 @@ static void onDestroy(void *data)
|
||||||
struct tab *t = (struct tab *) data;
|
struct tab *t = (struct tab *) data;
|
||||||
uintmax_t i;
|
uintmax_t i;
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// TODO verify if this is sufficient
|
||||||
for (i = 0; i < t->len; i++)
|
for (i = 0; i < t->len; i++)
|
||||||
uiParentDestroy(t->pages[i]);
|
uiControlDestroy(uiControl(t->pages[i]));
|
||||||
|
// then free ourselves
|
||||||
uiFree(t->pages);
|
uiFree(t->pages);
|
||||||
uiFree(t);
|
uiFree(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define tabCapGrow 32
|
#define tabCapGrow 32
|
||||||
|
|
||||||
static void tabAddPage(uiTab *tt, const char *name, uiControl *child)
|
static void tabAppendPage(uiTab *tt, const char *name, uiControl *child)
|
||||||
{
|
{
|
||||||
struct tab *t = (struct tab *) tt;
|
struct tab *t = (struct tab *) tt;
|
||||||
uiParent *content;
|
uiContainer *page;
|
||||||
|
GtkWidget *pageWidget;
|
||||||
|
|
||||||
if (t->len >= t->cap) {
|
if (t->len >= t->cap) {
|
||||||
t->cap += tabCapGrow;
|
t->cap += tabCapGrow;
|
||||||
t->pages = (uiParent **) uiRealloc(t->pages, t->cap * sizeof (uiParent *), "uiParent *[]");
|
t->pages = (uiContainer **) uiRealloc(t->pages, t->cap * sizeof (uiContainer *), "uiContainer *[]");
|
||||||
}
|
}
|
||||||
|
|
||||||
content = uiNewParent((uintptr_t) (t->container));
|
page = newBin();
|
||||||
uiParentSetMainControl(content, child);
|
binSetMainControl(page, child);
|
||||||
uiParentUpdate(content);
|
// and add it as a tab page
|
||||||
gtk_notebook_set_tab_label_text(t->notebook, GTK_WIDGET(uiParentHandle(content)), name);
|
binSetParent(page, (uintptr_t) (t->container));
|
||||||
|
pageWidget = GTK_WIDGET(uiControlHandle(uiControl(page)));
|
||||||
|
gtk_notebook_set_tab_label_text(t->notebook, pageWidget, name);
|
||||||
|
|
||||||
t->pages[t->len] = content;
|
t->pages[t->len] = page;
|
||||||
t->len++;
|
t->len++;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tabDeletePage(uiTab *tt, uintmax_t n)
|
static void tabDeletePage(uiTab *tt, uintmax_t n)
|
||||||
{
|
{
|
||||||
struct tab *t = (struct tab *) tt;
|
struct tab *t = (struct tab *) tt;
|
||||||
uiParent *p;
|
uiContainer *page;
|
||||||
uintmax_t i;
|
uintmax_t i;
|
||||||
|
|
||||||
p = t->pages[n];
|
page = t->pages[n];
|
||||||
for (i = n; i < t->len - 1; i++)
|
for (i = n; i < t->len - 1; i++)
|
||||||
t->pages[i] = t->pages[i + 1];
|
t->pages[i] = t->pages[i + 1];
|
||||||
t->pages[i] = NULL;
|
t->pages[i] = NULL;
|
||||||
t->len--;
|
t->len--;
|
||||||
|
|
||||||
// make sure the page's control isn't destroyed
|
// make sure the page's control isn't destroyed
|
||||||
uiParentSetMainControl(p, NULL);
|
binSetMainControl(page, NULL);
|
||||||
|
|
||||||
// now destroy the page
|
// now destroy the page
|
||||||
// this will also remove the tab
|
// this will also remove the tab
|
||||||
// why? simple: both gtk_notebook_remove_tab() and gtk_widget_destroy() call gtk_container_remove()
|
// why? simple: both gtk_notebook_remove_tab() and gtk_widget_destroy() call gtk_container_remove()
|
||||||
uiParentDestroy(p);
|
// TODO verify this
|
||||||
|
uiControlDestroy(uiControl(page));
|
||||||
}
|
}
|
||||||
|
|
||||||
uiTab *uiNewTab(void)
|
uiTab *uiNewTab(void)
|
||||||
|
@ -74,11 +84,11 @@ uiTab *uiNewTab(void)
|
||||||
FALSE, FALSE, onDestroy, t,
|
FALSE, FALSE, onDestroy, t,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
t->widget = WIDGET(t);
|
t->widget = GTK_WIDGET(uiControlHandle(uiControl(t)));
|
||||||
t->container = GTK_CONTAINER(t->widget);
|
t->container = GTK_CONTAINER(t->widget);
|
||||||
t->notebook = GTK_NOTEBOOK(t->widget);
|
t->notebook = GTK_NOTEBOOK(t->widget);
|
||||||
|
|
||||||
uiTab(t)->AddPage = tabAddPage;
|
uiTab(t)->AppendPage = tabAppendPage;
|
||||||
uiTab(t)->DeletePage = tabDeletePage;
|
uiTab(t)->DeletePage = tabDeletePage;
|
||||||
|
|
||||||
return uiTab(t);
|
return uiTab(t);
|
Loading…
Reference in New Issue