Migrated GTK+ uiTab to the child functions.

This commit is contained in:
Pietro Gagliardi 2015-08-28 16:50:55 -04:00
parent 19c9b0f9da
commit 77b53b5278
2 changed files with 25 additions and 42 deletions

View File

@ -59,6 +59,10 @@ struct child *newChildWithBox(uiControl *child, uiControl *parent, GtkContainer
box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_widget_show(box);
c = newChild(child, parent, GTK_CONTAINER(box));
gtk_widget_set_hexpand(c->widget, TRUE);
gtk_widget_set_halign(c->widget, GTK_ALIGN_FILL);
gtk_widget_set_vexpand(c->widget, TRUE);
gtk_widget_set_valign(c->widget, GTK_ALIGN_FILL);
c->box = box;
gtk_container_add(parentContainer, c->box);
childSetMargined(c, margined);

View File

@ -8,13 +8,7 @@ struct uiTab {
GtkContainer *container;
GtkNotebook *notebook;
GArray *pages;
};
struct tabPage {
GtkWidget *box;
uiControl *c;
int margined;
GArray *pages; // []*struct child
};
static void onDestroy(uiTab *);
@ -28,15 +22,11 @@ uiUnixDefineControlWithOnDestroy(
static void onDestroy(uiTab *t)
{
guint i;
struct tabPage *page;
struct child *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);
uiControlDestroy(page->c);
gtk_widget_destroy(page->box);
page = g_array_index(t->pages, struct child *, i);
childDestroy(page);
}
g_array_free(t->pages, TRUE);
}
@ -50,35 +40,24 @@ void uiTabAppend(uiTab *t, const char *name, uiControl *child)
void uiTabInsertAt(uiTab *t, const char *name, uintmax_t n, uiControl *child)
{
struct tabPage page;
struct child *page;
page.c = child;
page.box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_container_add(GTK_CONTAINER(page.box),
GTK_WIDGET(uiControlHandle(page.c)));
gtk_widget_show(page.box);
// this will create a tab, because of gtk_container_add()
page = newChildWithBox(child, uiControl(t), t->container, 0);
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);
gtk_notebook_set_tab_label_text(t->notebook, childBox(page), name);
gtk_notebook_reorder_child(t->notebook, childBox(page), n);
g_array_insert_val(t->pages, n, page);
}
void uiTabDelete(uiTab *t, uintmax_t n)
{
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)));
// this will also remove the tab
gtk_widget_destroy(page->box);
struct child *page;
page = g_array_index(t->pages, struct child *, n);
// this will remove the tab, because gtk_widget_destroy() calls gtk_container_remove()
childRemove(page);
g_array_remove_index(t->pages, n);
}
@ -89,19 +68,19 @@ uintmax_t uiTabNumPages(uiTab *t)
int uiTabMargined(uiTab *t, uintmax_t n)
{
struct tabPage *page;
struct child *page;
page = &g_array_index(t->pages, struct tabPage, n);
return page->margined;
page = g_array_index(t->pages, struct child *, n);
return childFlag(page);
}
void uiTabSetMargined(uiTab *t, uintmax_t n, int margined)
{
struct tabPage *page;
struct child *page;
page = &g_array_index(t->pages, struct tabPage, n);
page->margined = margined;
setMargined(GTK_CONTAINER(page->box), page->margined);
page = g_array_index(t->pages, struct child *, n);
childSetFlag(page, margined);
childSetMargined(page, childFlag(page));
}
uiTab *uiNewTab(void)
@ -116,7 +95,7 @@ uiTab *uiNewTab(void)
gtk_notebook_set_scrollable(t->notebook, TRUE);
t->pages = g_array_new(FALSE, TRUE, sizeof (struct tabPage));
t->pages = g_array_new(FALSE, TRUE, sizeof (struct child *));
uiUnixFinishNewControl(t, uiTab);
//TODO uiControl(t)->ContainerUpdateState = tabContainerUpdateState;