ocarina: Move tab page content into a table

This should make it easier to add or remove headers and footers so that
I can share one widget between all pages.
This commit is contained in:
Bryan Schumaker 2011-10-20 19:33:05 -04:00
parent 83719838aa
commit 2c12cb80aa
3 changed files with 56 additions and 3 deletions

View File

@ -8,10 +8,15 @@ class Page
private:
GtkWidget *table;
void add_content(GtkWidget *);
void add_footer(GtkWidget *);
public:
Page(GtkWidget *);
~Page();
GtkWidget *get_page();
void hide();
void show();
};
#endif /* OCARINA_PAGE_H */

View File

@ -1,10 +1,17 @@
#include <ocarina/page.h>
#include <ocarina/footer.h>
#include <libsaria/print.h>
GtkAttachOptions GROW;
GtkAttachOptions SHRINK;
Page::Page(GtkWidget *content)
{
table = gtk_table_new(3, 1, FALSE);
add_content(content);
gtk_widget_show(table);
}
Page::~Page()
@ -13,5 +20,23 @@ Page::~Page()
void Page::add_content(GtkWidget *content)
{
gtk_table_attach_defaults(GTK_TABLE(table), content, 0, 1, 1, 2);
gtk_table_attach_defaults(GTK_TABLE(table), content, 0, 1, 0, 1);
}
void Page::add_footer(GtkWidget *footer)
{
gtk_table_attach(GTK_TABLE(table), footer, 0, 1, 2, 3, GROW, SHRINK, 0, 0);
}
GtkWidget *Page::get_page()
{
return table;
}
void Page::hide()
{
}
void Page::show()
{
}

View File

@ -1,11 +1,32 @@
#include <ocarina/gtk.h>
#include <ocarina/page.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)
pages[cur].hide();
if (pagenum != -1)
pages[pagenum].show();
}
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);
}
@ -19,12 +40,14 @@ GtkWidget *get_tabs()
void add_page(GtkWidget *label, GtkWidget *content, bool fill)
{
gtk_notebook_append_page(GTK_NOTEBOOK(tabs), content, label);
Page page(content);
gtk_notebook_append_page(GTK_NOTEBOOK(tabs), page.get_page(), label);
if (fill == true) {
gtk_notebook_set_tab_label_packing(GTK_NOTEBOOK(tabs),
content,
page.get_page(),
TRUE,
TRUE,
GTK_PACK_START);
}
pages.push_back(page);
};