ocarina/ocarina/body/tabs.cpp
Bryan Schumaker 882f917c8f 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.
2011-10-21 14:51:22 -04:00

64 lines
1.3 KiB
C++

#include <ocarina/gtk.h>
#include <ocarina/page.h>
#include <ocarina/footer.h>
#include <libsaria/print.h>
#include <vector>
using namespace std;
static GtkWidget *tabs = NULL;
static vector<Page> pages;
static int cur_page()
{
return gtk_notebook_get_current_page(GTK_NOTEBOOK(tabs));
}
static void switch_page(GtkWidget *notebook, GtkWidget *page, int pagenum)
{
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();
}
static void make_tabs()
{
tabs = gtk_notebook_new();
GTK_CONNECT(tabs, "switch-page", switch_page, NULL);
gtk_notebook_set_tab_pos(GTK_NOTEBOOK(tabs), GTK_POS_LEFT);
gtk_widget_show(tabs);
}
GtkWidget *get_tabs()
{
if (tabs == NULL)
make_tabs();
return 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),
page.get_page(),
TRUE,
TRUE,
GTK_PACK_START);
}
};