From 882f917c8f717fcc2d48731427c6013be94ba260 Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Fri, 21 Oct 2011 14:51:22 -0400 Subject: [PATCH] ocarina: Add a reference to the footer before moving Calling the remove() function will destroy the footer if it has no other references. To prevent this, I need to call g_object_ref() add a reference to the widget. --- include/ocarina/footer.h | 2 ++ include/ocarina/page.h | 5 ++--- ocarina/body/page.cpp | 16 +++++++--------- ocarina/body/tabs.cpp | 18 ++++++++++++++---- ocarina/footer/tiny.cpp | 12 ++++++++++++ ocarina/ocarina.cpp | 1 - 6 files changed, 37 insertions(+), 17 deletions(-) diff --git a/include/ocarina/footer.h b/include/ocarina/footer.h index 8b8f4e81..ab484535 100644 --- a/include/ocarina/footer.h +++ b/include/ocarina/footer.h @@ -4,5 +4,7 @@ #include GtkWidget *get_tiny_footer(); +void ref_footer(); +void unref_footer(); #endif /* OCARINA_FOOTER */ diff --git a/include/ocarina/page.h b/include/ocarina/page.h index d3886b6b..e95bf906 100644 --- a/include/ocarina/page.h +++ b/include/ocarina/page.h @@ -8,15 +8,14 @@ class Page private: GtkWidget *table; void add_content(GtkWidget *); - void add_footer(GtkWidget *); public: Page(GtkWidget *); ~Page(); GtkWidget *get_page(); - void hide(); - void show(); + void add_footer(GtkWidget *); + void remove_footer(GtkWidget *); }; #endif /* OCARINA_PAGE_H */ diff --git a/ocarina/body/page.cpp b/ocarina/body/page.cpp index add984f1..d52df848 100644 --- a/ocarina/body/page.cpp +++ b/ocarina/body/page.cpp @@ -1,10 +1,11 @@ #include +#include #include #include -GtkAttachOptions GROW; +GtkAttachOptions GROW = GTK_FILL; GtkAttachOptions SHRINK; Page::Page(GtkWidget *content) @@ -23,6 +24,11 @@ void Page::add_content(GtkWidget *content) gtk_table_attach_defaults(GTK_TABLE(table), content, 0, 1, 0, 1); } +void Page::remove_footer(GtkWidget *footer) +{ + gtk_container_remove(GTK_CONTAINER(table), footer); +} + void Page::add_footer(GtkWidget *footer) { gtk_table_attach(GTK_TABLE(table), footer, 0, 1, 2, 3, GROW, SHRINK, 0, 0); @@ -32,11 +38,3 @@ GtkWidget *Page::get_page() { return table; } - -void Page::hide() -{ -} - -void Page::show() -{ -} diff --git a/ocarina/body/tabs.cpp b/ocarina/body/tabs.cpp index 6afefc74..c667b5f6 100644 --- a/ocarina/body/tabs.cpp +++ b/ocarina/body/tabs.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include @@ -17,10 +18,18 @@ static int cur_page() static void switch_page(GtkWidget *notebook, GtkWidget *page, int pagenum) { int cur = cur_page(); - if (cur != -1) - pages[cur].hide(); + if (cur != -1) { + /* + * If we don't reference the footer here it will be + * destroyed during the remove() call. + */ + ref_footer(); + pages[cur].remove_footer(get_tiny_footer()); + } if (pagenum != -1) - pages[pagenum].show(); + pages[pagenum].add_footer(get_tiny_footer()); + if (cur != -1) + unref_footer(); } static void make_tabs() @@ -41,6 +50,8 @@ GtkWidget *get_tabs() void add_page(GtkWidget *label, GtkWidget *content, bool fill) { Page page(content); + pages.push_back(page); + gtk_notebook_append_page(GTK_NOTEBOOK(tabs), page.get_page(), label); if (fill == true) { gtk_notebook_set_tab_label_packing(GTK_NOTEBOOK(tabs), @@ -49,5 +60,4 @@ void add_page(GtkWidget *label, GtkWidget *content, bool fill) TRUE, GTK_PACK_START); } - pages.push_back(page); }; diff --git a/ocarina/footer/tiny.cpp b/ocarina/footer/tiny.cpp index 8194ec25..a9bb68e5 100644 --- a/ocarina/footer/tiny.cpp +++ b/ocarina/footer/tiny.cpp @@ -29,3 +29,15 @@ GtkWidget *get_tiny_footer() make_tiny_footer(); return footer; } + +void ref_footer() +{ + if (footer != NULL) + g_object_ref(footer); +} + +void unref_footer() +{ + if (footer != NULL) + g_object_unref(footer); +} diff --git a/ocarina/ocarina.cpp b/ocarina/ocarina.cpp index 33c18b6b..9912afbe 100644 --- a/ocarina/ocarina.cpp +++ b/ocarina/ocarina.cpp @@ -34,7 +34,6 @@ void ocarina_init(int argc, char **argv) window_icon("images/ocarina.png"); box_pack_start(vbox, get_tabs(), TRUE, TRUE, 0); - box_pack_start(vbox, get_tiny_footer(), FALSE, FALSE, 0); gtk_widget_show(vbox); window_add(vbox);