ocarina: Remove the Page class

This patch does two things.  First, I remove the Page class and let each
notebook page manage itself.  Second, I created functions to add the
header and footer to a GtkWidget and then prepend the page in the
notebook (so it adds pages as if it was a stack).

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-02-27 11:31:33 -05:00
parent b7e1c2c631
commit d41c64c798
7 changed files with 42 additions and 95 deletions

View File

@ -5,8 +5,9 @@
#include <ocarina/page.h>
GtkWidget *get_tabs();
unsigned int add_page(GtkWidget *, GtkWidget *, bool);
void hide_page(unsigned int);
void show_page(unsigned int);
GtkWidget *make_page(GtkWidget *);
void push_page(GtkWidget *, GtkWidget *, bool);
void remove_page(GtkWidget *);
void set_current_page(GtkWidget *);
#endif /* OCARINA_BODY_H */

View File

@ -1,61 +0,0 @@
// Copyright (c) 2011 Bryan Schumaker
#include <ocarina/page.h>
#include <ocarina/gtk.h>
#include <ocarina/header.h>
#include <ocarina/footer.h>
#include <libsaria/print.h>
GtkAttachOptions GROW = GTK_FILL;
GtkAttachOptions SHRINK;
Page::Page(GtkWidget *content)
{
table = gtk_table_new(3, 1, FALSE);
add_content(content);
gtk_widget_show(table);
}
Page::~Page()
{
}
void Page::add_content(GtkWidget *content)
{
gtk_table_attach_defaults(GTK_TABLE(table), content, 0, 1, 1, 2);
}
void Page::remove_header(GtkWidget *header)
{
gtk_container_remove(GTK_CONTAINER(table), header);
}
void Page::remove_footer(GtkWidget *footer)
{
gtk_container_remove(GTK_CONTAINER(table), footer);
}
void Page::add_header(GtkWidget *header)
{
gtk_table_attach(GTK_TABLE(table), header, 0, 1, 0, 1, GROW, SHRINK, 0, 0);
}
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()
{
gtk_widget_hide(table);
}
void Page::show()
{
gtk_widget_show(table);
}

View File

@ -5,11 +5,7 @@
#include <ocarina/footer.h>
#include <libsaria/print.h>
#include <vector>
using namespace std;
static GtkWidget *tabs = NULL;
static vector<Page> pages;
static void make_tabs()
{
@ -25,32 +21,38 @@ GtkWidget *get_tabs()
return tabs;
}
unsigned int add_page(GtkWidget *label, GtkWidget *content, bool fill)
void push_page(GtkWidget *page, GtkWidget *label, 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);
gtk_notebook_prepend_page(GTK_NOTEBOOK(tabs), page, label);
if (fill == true) {
gtk_notebook_set_tab_label_packing(GTK_NOTEBOOK(tabs),
page.get_page(),
page,
TRUE,
TRUE,
GTK_PACK_START);
}
page.add_header(get_header());
page.add_footer(get_footer());
}
return index;
void remove_page(GtkWidget *page)
{
int pg_num = gtk_notebook_page_num(GTK_NOTEBOOK(tabs), page);
gtk_notebook_remove_page(GTK_NOTEBOOK(tabs), pg_num);
}
GtkWidget *make_page(GtkWidget *content)
{
GtkWidget *page = gtk_vbox_new(FALSE, 0);
box_pack_start(page, get_header(), FALSE, FALSE, 0);
box_pack_start(page, content, TRUE, TRUE, 0);
box_pack_start(page, get_footer(), FALSE, FALSE, 0);
gtk_widget_show(page);
return page;
};
void hide_page(unsigned int index)
void set_current_page(GtkWidget *page)
{
pages[index].hide();
}
void show_page(unsigned int index)
{
pages[index].show();
int pg_num = gtk_notebook_page_num(GTK_NOTEBOOK(tabs), page);
gtk_notebook_set_current_page(GTK_NOTEBOOK(tabs), pg_num);
}

View File

@ -15,6 +15,7 @@ using namespace std;
static SongList library_list;
static list <MenuItem> library_menu;
static GtkWidget *library_page = NULL;
static void add_to_queue()
{
@ -54,7 +55,9 @@ namespace ocarina
library_list.set_playlist(libsaria::library::get_playlist());
library_list.init("Library", &library_menu, true);
add_page(library_list.get_label(), library_list.get_window(), true);
library_page = make_page(library_list.get_window());
push_page(library_page, library_list.get_label(), true);
set_current_page(library_page);
ocarina::library::refresh();
}

View File

@ -58,9 +58,9 @@ namespace ocarina
{
window_init("Ocarina " + vers_str(), full_path("images/ocarina.png"));
window_add(get_tabs());
ocarina::queue::init();
ocarina::library::init();
settings_init();
ocarina::library::init();
ocarina::queue::init();
header_init();
footer_init();
idle_add();

View File

@ -12,13 +12,13 @@ using namespace std;
static SongList queue_list;
static list <MenuItem> queue_menu;
unsigned int queue_index;
GtkWidget *queue_page;
static void rm_from_queue()
{
queue_list.rm_selected_indices();
if (libsaria::queue::size() == 0)
hide_page(queue_index);
gtk_widget_hide(queue_page);
}
static void rm_from_queue_event(GtkMenuItem *menu, gpointer data)
@ -34,9 +34,9 @@ namespace ocarina
queue_list.clear();
if (libsaria::queue::size() > 0) {
queue_list.fill();
show_page(queue_index);
gtk_widget_show(queue_page);
} else
hide_page(queue_index);
gtk_widget_hide(queue_page);
}
void queue::init()
@ -46,8 +46,8 @@ namespace ocarina
queue_list.set_playlist(libsaria::queue::get_playlist());
queue_list.init("Queue", &queue_menu, false);
queue_index = add_page(queue_list.get_label(),
queue_list.get_window(), true);
queue_page = make_page(queue_list.get_window());;
push_page(queue_page, queue_list.get_label(), true);
ocarina::queue::refresh();
}

View File

@ -4,6 +4,7 @@
#include <ocarina/gtk.h>
static GtkWidget *settings_tabs = NULL;
static GtkWidget *settings_page = NULL;
void settings_init()
{
@ -13,7 +14,8 @@ void settings_init()
gtk_widget_show(image);
gtk_widget_show(settings_tabs);
add_page(image, settings_tabs, false);
settings_page = make_page(settings_tabs);
push_page(settings_page, image, false);
general_settings_init();
library_settings_init();