Xfce
Foundation Classes |
|||
« Main Page | Index | |||
NotebooksThe NoteBook Widget is a collection of "pages" that overlap each other, each page contains different information with only one page visible at a time. The pages can be switched between using tab labels along one edge. This widget has become more common lately in GUI programming, and it is a good way to show blocks of similar information that warrant separation in their display. The first method you will need to know, as you can probably guess, is the constructor used to create a new notebook widget: Notebook(); The first one we will look at is how to position the page indicators. These page indicators or 'tabs' as they are referred to, can be positioned in four ways: top, bottom, left, or right: void
set_tab_pos(Gtk::PositionType pos);
Next we will look at how to add
pages to the notebook. There are three
ways to add pages to the NoteBook - append, prepend and insert. Let's
look at the first two together as they are quite similar.
void
append_page(Gtk::Widget& child, Gtk::Widget *tab_label = 0,
Gtk::Widget *menu_label = 0); There are two overloaded versions of each method. These methods add pages to the notebook by inserting them from the back of the notebook (append), or the front of the notebook (prepend). The 'child' argument is the widget that is placed within the notebook page, 'tab_label' is the label for the page being added and 'menu_label' is the label to use for the page-switch menu, if that is enabled. The child widget must be created separately, and is typically a set of options setup within one of the other container widgets, such as a table. In the first append and prepend page methods 'tab_label' and 'menu_label' are pointers to the widgets that are to be used as the page and page-switch menu labels. The second append and prepend page methods create these widgets for you and sets 'tab_label' and 'menu_label' as the label text. The final method for adding a page to the notebook contains all of the properties of the previous two, but it allows you to specify what position you want the page to be in the notebook: void
insert_page(Gtk::Widget& child, int
position, Gtk::Widget *tab_label = 0, Gtk::Widget *menu_label = 0); The arguments are the same as the append and prepend page methods except there is an extra argument, position. This argument is used to specify what place this page will be inserted into, the first page having position zero. Now that we know how to add a page, lets see how we can remove a page from the notebook: void
remove_page(int page_num); This method takes the page specified by 'page_num' and removes it from the widget. To find out what the current page is in a notebook use the following method: int
get_current_page() const; These next two methods are simple calls to move the current notebook page forward or backward: void
next_page(); Simply call the respective method for the notebook widget you wish to operate on. Note, when the NoteBook is currently on the last page, and next_page() is called, the notebook will wrap back to the first page. Likewise, if the NoteBook is on the first page, and prev_page() is called, the notebook will wrap to the last page. This next method sets the 'active' page. If you wish the notebook to be opened to page 5 for example, you would use this method. Without using this method the notebook defaults to the first page. void
set_current_page(int page_num); The next two methods add or remove the notebook page border and the notebook tabs respectively. void
set_show_border(bool show_border); The next method is useful when the you have a large number of pages, and the tabs don't fit on the page. It allows the tabs to be scrolled through using two arrow buttons. void
set_scrollable(bool scrollable); Notebook ExampleLet's take a look at an example. This small program creates a window with a notebook and six buttons. The notebook contains 11 pages, added in three different ways, appended, inserted, and prepended. The buttons allow you rotate the tab positions, add/remove the tabs and border, remove a page, change pages in both a forward and backward manner, and exit the program.The header file for the Notebook example is
<notebook.hh>:
#include <xfc/main.hh> and the source file is <notebook.cc>: #include "notebook.hh" Compiling Notebook
If you compiled and installed XFC yourself, you will find the source
code for Notebook in the
<examples/notebook> source directory along with a Makefile. If
XFC came pre-installed, or you installed it from an RPM package, you
will
find the source code in the
</usr/share/doc/xfcui-X.X/examples/notebook> subdirectory. In
this case you will have to create the Makefile yourself (replace X.X
with the
version number of the libXFCui library you have installed). |
Copyright © 2004-2005 The XFC Development Team | Top |
XFC
4.4 |