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.
This commit is contained in:
parent
6467356cf6
commit
882f917c8f
|
@ -4,5 +4,7 @@
|
|||
#include <ocarina/gtk.h>
|
||||
|
||||
GtkWidget *get_tiny_footer();
|
||||
void ref_footer();
|
||||
void unref_footer();
|
||||
|
||||
#endif /* OCARINA_FOOTER */
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
|
||||
#include <ocarina/page.h>
|
||||
#include <ocarina/gtk.h>
|
||||
#include <ocarina/footer.h>
|
||||
|
||||
#include <libsaria/print.h>
|
||||
|
||||
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()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
#include <ocarina/gtk.h>
|
||||
#include <ocarina/page.h>
|
||||
#include <ocarina/footer.h>
|
||||
#include <libsaria/print.h>
|
||||
|
||||
#include <vector>
|
||||
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue