Xfce Foundation Classes
 « Main Page | Index


Frames can be used to enclose one or more widgets with a decorative box which can optionally be labeled. The position of the label and the style of the box can be altered to suit.

A Frame can be created with one of the following constructors:

Frame(Gtk::ShadowType type = Gtk::SHADOW_ETCHED_IN);

Frame(const String& label, Gtk::ShadowType type = Gtk::SHADOW_ETCHED_IN);

The first constructor creates a Frame with the specified ShadowType, which by default is SHADOW_ETCHED_IN. The second constructor additionally lets you specify a label for the frame. The label is by default placed in the upper left hand corner of the frame.

The text of the label can be set or changed using this next method:

void set_label(const String& label);

A label widget can be added later by either calling the set_label() method, in which case a label widget is created for you, or by specifically calling the next method followed by a call to set_label() to set the label text.

void set_label_widget(Widget& label_widget);

The position of the label can be changed using this method:

void set_label_align(float xalign, float yalign);

The 'xalign' and 'yalign' arguments take values between 0.0 and 1.0. xalign indicates the position of the label along the top horizontal of the frame. yalign indicates the vertical position with respect to the top horizontal of the frame - either above (0.0), below (1.0) or somewhere over it. The default value of xalign is 0.0 which places the label at the left hand end of the frame. The default value of yalign is 0.5 which places the middle of the label over the top horizontal of the frame.

The next function alters the style of the box that is used to outline the frame.

void set_shadow_type(Gtk::ShadowType type);

The 'type' argument can take one of the following values from the Gtk::ShadowType enum:
  • SHADOW_ETCHED_IN (the default)

Frame Example

The following code example illustrates the use of the Frame widget. It creates a simple window that contains a frame with a label aligned to the left side on the top edge.

The header file for the Frame example is <frame.hh>:

#include <xfc/main.hh>
#include <xfc/gtk/window.hh>

using namespace Xfc;

class FrameWindow : public Gtk::Window
    virtual ~FrameWindow();

and the source file is <frame.cc>:

#include "frame.hh"
#include <xfc/gtk/frame.hh>

    set_title("Frame Example");
    set_size_request(300, 300);

    // Sets the border width of the window.

    // Create a Frame
    Gtk::Frame *frame = new Gtk::Frame;

    // Set the frame's label
    frame->set_label(" Gtk::Frame Widget");

    // Align the label at the right of the frame
    frame->set_label_align(1.0, 0.0);

    // Set the style of the frame



Compiling Frame

If you compiled and installed XFC yourself, you will find the source code for Frame in the <examples/howto/frame> 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/howto/frame> 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).

To create a Makefile for Frame, add the following lines to a new text file and save it using the name "Makefile":

CC = g++

CFLAGS = -Wall -O2

frame: frame.cc frame.hh
    $(CC) frame.cc -o frame $(CFLAGS) `pkg-config xfcui-X.X --cflags --libs`

    rm -f *.o frame

If you cut and paste these lines make sure the whitespace before $(CC) and rm is a tab character. When you compile and run this program you will see the following window appear:

The XFC_MAIN macro is a convenience macro that writes a simple main function, its only argument is the name of the main window class. The macro is defined in <xfc/main.hh> as:

#define XFC_MAIN(MainWidget)\
    int main (int argc, char *argv[])\
        Xfc::Main::init(&argc, &argv);\
        MainWidget main_widget;\
        return 0;\

Most main functions in C++ are simple because all the creation work for the main window is done inside its constructor, not the main function.

Copyright © 2004-2005 The XFC Development Team Top
XFC 4.4