78 lines
1.4 KiB
C++
78 lines
1.4 KiB
C++
|
|
#include <ocarina/gtk.h>
|
|
#include <ocarina/page.h>
|
|
#include <ocarina/header.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)
|
|
{
|
|
GtkWidget *header = get_header();
|
|
int cur = cur_page();
|
|
|
|
if (cur != -1) {
|
|
pages[cur].remove_header(header);
|
|
}
|
|
if (pagenum != -1) {
|
|
pages[pagenum].add_header(header);
|
|
}
|
|
|
|
if (header != NULL)
|
|
put_header();
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
unsigned int add_page(GtkWidget *label, GtkWidget *content, bool fill)
|
|
{
|
|
unsigned int index = pages.size();
|
|
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);
|
|
}
|
|
page.add_footer(get_footer());
|
|
|
|
return index;
|
|
};
|
|
|
|
void hide_page(unsigned int index)
|
|
{
|
|
pages[index].hide();
|
|
}
|
|
|
|
void show_page(unsigned int index)
|
|
{
|
|
pages[index].show();
|
|
}
|