Migrated GTK+ uiTab to the child functions.
This commit is contained in:
parent
19c9b0f9da
commit
77b53b5278
|
@ -59,6 +59,10 @@ struct child *newChildWithBox(uiControl *child, uiControl *parent, GtkContainer
|
||||||
box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
|
box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
|
||||||
gtk_widget_show(box);
|
gtk_widget_show(box);
|
||||||
c = newChild(child, parent, GTK_CONTAINER(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;
|
c->box = box;
|
||||||
gtk_container_add(parentContainer, c->box);
|
gtk_container_add(parentContainer, c->box);
|
||||||
childSetMargined(c, margined);
|
childSetMargined(c, margined);
|
||||||
|
|
|
@ -8,13 +8,7 @@ struct uiTab {
|
||||||
GtkContainer *container;
|
GtkContainer *container;
|
||||||
GtkNotebook *notebook;
|
GtkNotebook *notebook;
|
||||||
|
|
||||||
GArray *pages;
|
GArray *pages; // []*struct child
|
||||||
};
|
|
||||||
|
|
||||||
struct tabPage {
|
|
||||||
GtkWidget *box;
|
|
||||||
uiControl *c;
|
|
||||||
int margined;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void onDestroy(uiTab *);
|
static void onDestroy(uiTab *);
|
||||||
|
@ -28,15 +22,11 @@ uiUnixDefineControlWithOnDestroy(
|
||||||
static void onDestroy(uiTab *t)
|
static void onDestroy(uiTab *t)
|
||||||
{
|
{
|
||||||
guint i;
|
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++) {
|
for (i = 0; i < t->pages->len; i++) {
|
||||||
page = &g_array_index(t->pages, struct tabPage, i);
|
page = g_array_index(t->pages, struct child *, i);
|
||||||
uiControlSetParent(page->c, NULL);
|
childDestroy(page);
|
||||||
uiControlDestroy(page->c);
|
|
||||||
gtk_widget_destroy(page->box);
|
|
||||||
}
|
}
|
||||||
g_array_free(t->pages, TRUE);
|
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)
|
void uiTabInsertAt(uiTab *t, const char *name, uintmax_t n, uiControl *child)
|
||||||
{
|
{
|
||||||
struct tabPage page;
|
struct child *page;
|
||||||
|
|
||||||
page.c = child;
|
// this will create a tab, because of gtk_container_add()
|
||||||
page.box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
|
page = newChildWithBox(child, uiControl(t), t->container, 0);
|
||||||
gtk_container_add(GTK_CONTAINER(page.box),
|
|
||||||
GTK_WIDGET(uiControlHandle(page.c)));
|
|
||||||
gtk_widget_show(page.box);
|
|
||||||
|
|
||||||
gtk_container_add(t->container, page.box);
|
gtk_notebook_set_tab_label_text(t->notebook, childBox(page), name);
|
||||||
gtk_notebook_set_tab_label_text(t->notebook, page.box, name);
|
gtk_notebook_reorder_child(t->notebook, childBox(page), n);
|
||||||
gtk_notebook_reorder_child(t->notebook, page.box, n);
|
|
||||||
|
|
||||||
g_array_insert_val(t->pages, n, page);
|
g_array_insert_val(t->pages, n, page);
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiTabDelete(uiTab *t, uintmax_t n)
|
void uiTabDelete(uiTab *t, uintmax_t n)
|
||||||
{
|
{
|
||||||
struct tabPage *page;
|
struct child *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);
|
|
||||||
|
|
||||||
|
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);
|
g_array_remove_index(t->pages, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,19 +68,19 @@ uintmax_t uiTabNumPages(uiTab *t)
|
||||||
|
|
||||||
int uiTabMargined(uiTab *t, uintmax_t n)
|
int uiTabMargined(uiTab *t, uintmax_t n)
|
||||||
{
|
{
|
||||||
struct tabPage *page;
|
struct child *page;
|
||||||
|
|
||||||
page = &g_array_index(t->pages, struct tabPage, n);
|
page = g_array_index(t->pages, struct child *, n);
|
||||||
return page->margined;
|
return childFlag(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiTabSetMargined(uiTab *t, uintmax_t n, int margined)
|
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 = g_array_index(t->pages, struct child *, n);
|
||||||
page->margined = margined;
|
childSetFlag(page, margined);
|
||||||
setMargined(GTK_CONTAINER(page->box), page->margined);
|
childSetMargined(page, childFlag(page));
|
||||||
}
|
}
|
||||||
|
|
||||||
uiTab *uiNewTab(void)
|
uiTab *uiNewTab(void)
|
||||||
|
@ -116,7 +95,7 @@ uiTab *uiNewTab(void)
|
||||||
|
|
||||||
gtk_notebook_set_scrollable(t->notebook, TRUE);
|
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);
|
uiUnixFinishNewControl(t, uiTab);
|
||||||
//TODO uiControl(t)->ContainerUpdateState = tabContainerUpdateState;
|
//TODO uiControl(t)->ContainerUpdateState = tabContainerUpdateState;
|
||||||
|
|
Loading…
Reference in New Issue