1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
#include "notebook.hh"
#include <gfc/gtk/box.hh>
#include <gfc/gtk/checkbutton.hh>
#include <gfc/gtk/frame.hh>
#include <gfc/gtk/label.hh>
#include <gfc/gtk/table.hh>
// Notebook
Notebook::Notebook()
{
set_tab_pos(Gtk::POS_TOP);
show();
}
Notebook::~Notebook()
{
}
void
Notebook::on_rotate_book()
{
// This function rotates the position of the tabs
set_tab_pos((Gtk::PositionType)((gtk_notebook()->tab_pos + 1) % 4));
}
void
Notebook::on_tabsborder_book()
{
// Add/Remove the page tabs and the borders
int tval = false;
int bval = false;
if (!get_show_tabs())
tval = true;
if (!get_show_border())
bval = true;
set_show_tabs(tval);
set_show_border(bval);
}
void
Notebook::on_remove_book()
{
// Remove a page from the notebook
int page = get_current_page();
remove_page(page);
// Need to refresh the widget -- This forces the widget to redraw itself.
queue_draw();
}
// NotebookWindow
NotebookWindow::NotebookWindow()
{
set_border_width(10);
Gtk::Table *table = new Gtk::Table(3, 6);
add(*table);
// Create a new notebook, place the position of the tabs
Notebook *notebook = new Notebook;
table->attach(*notebook, 0, 6, 0, 1);
// Let's append a bunch of pages to the notebook
Gtk::Label *label;
for (int i = 0; i < 5; i++)
{
String s1 = String::format("Append Frame %d", i + 1);
String s2 = String::format("Page %d", i + 1);
Gtk::Frame *frame = new Gtk::Frame(s1);
frame->set_border_width(10);
frame->set_size_request(100, 75);
label = new Gtk::Label(s1);
frame->add(*label);
label = new Gtk::Label(s2);
notebook->append_page(*frame, label);
}
// Now let's add a page to a specific spot
Gtk::CheckButton *checkbutton = new Gtk::CheckButton("Check me please!");
checkbutton->set_size_request(100, 75);
label = new Gtk::Label("Add page");
notebook->insert_page(*checkbutton, 2, label);
// Now finally let's prepend pages to the notebook
for (int i = 0; i < 5; i++)
{
String s1 = String::format("Prepend Frame %d", i + 1);
String s2 = String::format("PPage %d", i + 1);
Gtk::Frame *frame = new Gtk::Frame(s1);
frame->set_border_width(10);
frame->set_size_request(100, 75);
label = new Gtk::Label(s1);
frame->add(*label);
label = new Gtk::Label(s2);
notebook->prepend_page(*frame, label);
}
// Set what page to start at (page 4)
notebook->set_current_page(3);
// Create a bunch of buttons
Gtk::Button *button = new Gtk::Button("close");
button->sig_clicked().connect(sigc::mem_fun(this, &NotebookWindow::dispose));
table->attach(*button, 0, 1, 1, 2);
button = new Gtk::Button("next page");
button->sig_clicked().connect(sigc::mem_fun(notebook, &Notebook::next_page));
table->attach(*button, 1, 2, 1, 2);
button = new Gtk::Button("prev page");
button->sig_clicked().connect(sigc::mem_fun(notebook, &Notebook::prev_page));
table->attach(*button, 2, 3, 1, 2);
button = new Gtk::Button("tab position");
button->sig_clicked().connect(sigc::mem_fun(notebook, &Notebook::on_rotate_book));
table->attach(*button, 3, 4, 1, 2);
button = new Gtk::Button("tabs/border on/off");
button->sig_clicked().connect(sigc::mem_fun(notebook, &Notebook::on_tabsborder_book));
table->attach(*button, 4, 5, 1, 2);
button = new Gtk::Button("remove page");
button->sig_clicked().connect(sigc::mem_fun(notebook, &Notebook::on_remove_book));
table->attach(*button, 5, 6, 1, 2);
table->show_all();
show();
}
NotebookWindow::~NotebookWindow()
{
}
int main (int argc, char *argv[])
{
using namespace Main;
init(&argc, &argv);
NotebookWindow window;
window.sig_destroy().connect(sigc::ptr_fun(&GFC::Main::quit));
run();
return 0;
}
|