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.
This commit is contained in:
Bryan Schumaker 2011-10-27 12:08:21 -04:00
parent 007a2e820d
commit d3c9301628
3 changed files with 11 additions and 22 deletions

View File

@ -3,8 +3,7 @@
#include <ocarina/gtk.h>
GtkWidget *get_tiny_footer();
void ref_footer();
void unref_footer();
GtkWidget *get_footer();
void put_footer();
#endif /* OCARINA_FOOTER */

View File

@ -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()

View File

@ -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);