From d3c9301628010ca1794a66fe25e4307b685412e7 Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Thu, 27 Oct 2011 12:08:21 -0400 Subject: [PATCH] ocarina: Access footer through get_footer() and put_footer() I combined reference counting with the get_footer() function to make using it easier (no manual reference counting). put_footer() will deallocate the widget if the reference count is 0 (this is already done by the g_object_unref() function) so it should work in a sane way. --- include/ocarina/footer.h | 5 ++--- ocarina/body/tabs.cpp | 17 ++++++----------- ocarina/footer/tiny.cpp | 11 +++-------- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/include/ocarina/footer.h b/include/ocarina/footer.h index ab484535..42be8763 100644 --- a/include/ocarina/footer.h +++ b/include/ocarina/footer.h @@ -3,8 +3,7 @@ #include -GtkWidget *get_tiny_footer(); -void ref_footer(); -void unref_footer(); +GtkWidget *get_footer(); +void put_footer(); #endif /* OCARINA_FOOTER */ diff --git a/ocarina/body/tabs.cpp b/ocarina/body/tabs.cpp index c667b5f6..6f1f8fe1 100644 --- a/ocarina/body/tabs.cpp +++ b/ocarina/body/tabs.cpp @@ -17,19 +17,14 @@ static int cur_page() static void switch_page(GtkWidget *notebook, GtkWidget *page, int pagenum) { + GtkWidget *footer = get_footer(); int cur = cur_page(); - 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].add_footer(get_tiny_footer()); if (cur != -1) - unref_footer(); + pages[cur].remove_footer(footer); + if (pagenum != -1) + pages[pagenum].add_footer(footer); + if (footer != NULL) + put_footer(); } static void make_tabs() diff --git a/ocarina/footer/tiny.cpp b/ocarina/footer/tiny.cpp index 79360a9e..d2739e8d 100644 --- a/ocarina/footer/tiny.cpp +++ b/ocarina/footer/tiny.cpp @@ -23,20 +23,15 @@ static void make_tiny_footer() footer_pack(make_open_button()); } -GtkWidget *get_tiny_footer() +GtkWidget *get_footer() { if (footer == NULL) make_tiny_footer(); + g_object_ref(footer); return footer; } -void ref_footer() -{ - if (footer != NULL) - g_object_ref(footer); -} - -void unref_footer() +void put_footer() { if (footer != NULL) g_object_unref(footer);