Xfce
Foundation Classes |
|||
« Main Page | Index | |||
Font SelectionThe font selection widget is an interactive widget that lists all the available fonts, styles and sizes, allowing the user to select a font. It is used in the FontSelectionDialog widget to provide a dialog box for selecting fonts. A FontSelection can be created with the constructor: FontSelection(); You will probably not be using
this constructor
directly. It creates an orphan FontSelection widget which you'll have
to
parent yourself. The FontSelection widget inherits from the Gtk::VBox.
FontSelectionDialog(); These are the most common font
selection
constructors. Both constructors create a FontSelectionDialog, the first
with the default title, which is just the program name and the second
with the specified title. A FontSelectionDialog consists of a VBox
containing the FontSelection widget, an HSeparator and an HBox with
three buttons, "Ok", "Cancel" and "Apply". The Apply button is not
shown
by default. You can reach these buttons by using one of the
corresponding accessors:
Gtk::Button* ok_button() const; You can set and retrieve the selected font name by calling either of the following FontSelection or FontSelectionDialog methods: bool set_font_name(const String&
fontname); There are two FontSelection methods which can be used to retrieve Pango font information: Pango::FontFamily*
get_font_family() const; These methods return the current font family and face. To change the font used by a widget that displays text you will need to create a FontDescription. You can do this with the following Pango::FontDescription constructor: FontDescription(const String& desc); The 'desc' argument is the string returned by the call to get_font_name() above. To change a widget's font you must call the Gtk::Widget method: void
modify_font(const
Pango::FontDescription& font_desc); Font Selection ExampleHere's a simple example demonstrating the use of the FontSelectionDialog. The program displays a window that contains two widgets: a label displaying the text "Welcome to XFC" and a button. When the button is clicked a FontSelectionDialog appears. Selecting a new font, font style and/or font size and clicking on the "OK" button will result in the selected font being applied to the text in the label.The header file for the Font Selection example is <fontselection.hh>: #include <xfc/main.hh> and the source file is <fontselection.cc>: #include "fontselection.hh" Compiling Font Selection
If you compiled and installed XFC yourself, you will find the source
code for Font Selection in the
<examples/fontselection > 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/fontselection> 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 |