From 5bd6140d46b80bbcc8ab888084f9d238a97f7b3e Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 17 Apr 2015 22:26:05 -0400 Subject: [PATCH] Sort of implemented uiTabDeletePage() on GTK+. It's segfaulting on close; that isn't good... --- TODO.md | 1 + test.c | 2 +- ui.idl | 2 +- unix/tab.c | 20 ++++++++++++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/TODO.md b/TODO.md index 8b2e018a..a7f24e17 100644 --- a/TODO.md +++ b/TODO.md @@ -18,6 +18,7 @@ - verify retainment for uiParents in GTK+ - add an example of events to each of the new controls guides - verify that uiParentSetMainControl() does indeed not update +- settle differences between intmax_t and uintmax_t ultimately: - make everything vtable-based diff --git a/test.c b/test.c index 93db5d85..d5e09362 100644 --- a/test.c +++ b/test.c @@ -173,7 +173,7 @@ uiTab *tab; void movePage1Out(uiButton *b, void *data) { - uiTabDeletePage(tab, 0) + uiTabDeletePage(tab, 0); uiStackAppend(mainStack, uiControl(page1stack), 1); } diff --git a/ui.idl b/ui.idl index ee0708e5..b776531f 100644 --- a/ui.idl +++ b/ui.idl @@ -124,7 +124,7 @@ func NewLabel(text *const char) *Label; interface Tab from Control { // TODO rename to AppendPage() func AddPage(name *const char, c *Control); - func DeletePage(index intmax_t); + func DeletePage(index uintmax_t); }; func NewTab(void) *Tab; diff --git a/unix/tab.c b/unix/tab.c index 02467ad0..ba7bfa37 100644 --- a/unix/tab.c +++ b/unix/tab.c @@ -40,6 +40,25 @@ static void tabAddPage(uiTab *tt, const char *name, uiControl *child) t->len++; } +static void tabDeletePage(uiTab *tt, uintmax_t n) +{ + struct tab *t = (struct tab *) tt; + uiParent *p; + uintmax_t i; + + p = t->pages[n]; + for (i = n; i < t->len - 1; i++) + t->pages[i] = t->pages[i + 1]; + t->pages[i] = NULL; + t->len--; + + // make sure the page's control isn't destroyed + uiParentSetMainControl(p, NULL); + // TODO don't call uiParentDestroy() here as the following line will do so; figure out how to prevent + + gtk_notebook_remove_page(t->notebook, n); +} + uiTab *uiNewTab(void) { struct tab *t; @@ -57,6 +76,7 @@ uiTab *uiNewTab(void) g_signal_connect(t->widget, "destroy", G_CALLBACK(onDestroy), t); uiTab(t)->AddPage = tabAddPage; + uiTab(t)->DeletePage = tabDeletePage; return uiTab(t); }