Xfce Foundation Classes
Main Page  | IndexNamespace List  |  Alphabetical List  |  Class List  |  File List


Xfc::Glade::Xml Class Reference

A GladeXML C++ wrapper class. More...

#include <xfc/glade/xml.hh>

Inheritance diagram for Xfc::Glade::Xml:

Xfc::G::Object Xfc::G::TypeInstance Xfc::Trackable List of all members.

Public Member Functions

Constructors
Accessors

Static Public Member Functions

Constructors
Accessors

Protected Member Functions

Constructors
Methods

Detailed Description

A GladeXML C++ wrapper class.

Glade::Xml represents an instantiation of an XML interface description. When one of these objects is created, the XML file is read, and the interface is created. The Xml object then provides an interface for accessing the widgets in the interface by the names assigned to them inside the XML description. The Xml object can also be used to connect signals handlers to the named signals in the description.

Example: Instantiating a main application window from an XML description.

     //Declare derived window class.
     
     class MyWindow : public Gtk::Window
     {
        Gtk::Button *ok_button;
        
     protected:
        void on_ok_clicked();
        
     public: 
        MyWindow(CObjectType *object, const Glade::Xml& xml);
     };
     
     // Define constructor and load any widgets built by the Glade::Xml object.
     
     MyWindow::MyWindow(CObjectType *object, const Glade::Xml& xml)
     : Gtk::Window(object)
     {
        if (xml.get_widget("ok_button", ok_button))
        {
                ok_button->signal_clicked().connect(sigc::mem_fun((this, &MyWindow::on_ok_clicked));
        }
     }
     
     // Define on_ok_clicked handler, just calls dispose the destroy the window.
     
     void 
     MyWindow::on_ok_clicked()
     {
        dispose();
     }
     
     // Create the Glade::Xml object in main() and instantiate the main application window.
     
     int main(int argc, char *argv[])
     {
        using namespace Main;
     
        init(&argc, &argv);
        
        Pointer<Glade::Xml> xml = Glade::Xml::create("mywindow.glade");
        if (!xml)
                return 1;
        
        MyWindow *window;
        if (xml->get_widget_derived("MyWindow", window))
        {
                window->signal_destroy().connect(sigc::ptr_fun(&Xfc::Main::quit));
                window->show();
                run();
        }
        return 0;
     }


Constructor & Destructor Documentation

Xfc::Glade::Xml::Xml  )  [protected]
 

Construct an empty Xml object.

To create the interface from an XML interface description call construct().

Xfc::Glade::Xml::Xml GladeXML *  self,
bool  owns_reference = true
[explicit, protected]
 

Construct a new Xml object from an existing GladeXML object.

Parameters:
self A pointer to a GladeXML object.
owns_reference Set false if the initial reference count is floating, set true if it's not.
The self argument can be a newly created GladeXML object or an existing GladeXML object (see G::Object::Object).


Member Function Documentation

bool Xfc::Glade::Xml::construct const std::string &  filename,
const String root,
const String domain
[protected]
 

This method is used by derived classes to help construct the Xml object.

Parameters:
filename The XML filename.
root The root widget node, or null for none.
domain The translation domain, or null for the default.
Returns:
true if the construction succeeded, false on failure.

Pointer<Xml> Xfc::Glade::Xml::create const char *  buffer,
int  size,
const String root = 0,
const String domain = 0
[static]
 

Creates a new Glade::XML object (and the corresponding widgets) from the buffer buffer.

Parameters:
buffer The memory buffer containing the XML document.
size The size of the buffer.
root The widget node in filename to start building from, or null.
domain The translation domain for the XML buffer, or null for the default.
Returns:
A smart pointer to the newly created Xml object, or null on failure.
Optionally it will only build the interface from the widget node root (if it is not null). This feature is useful if you only want to build say a toolbar or menu from the XML document, but not the window it is embedded in.

Pointer<Xml> Xfc::Glade::Xml::create const std::string &  filename,
const String root = 0,
const String domain = 0
[static]
 

Creates a new Glade::Xml object (and the corresponding widgets) from the XML file filename.

Parameters:
filename The XML filename.
root The widget node in filename to start building from, or null.
domain The translation domain for the XML file, or null for the default.
Returns:
A smart pointer to the newly created Xml object, or null on failure.
Optionally it will only build the interface from the widget node root (if it is not null). This feature is useful if you only want to build say a toolbar or menu from the XML file, but not the window it is embedded in. Note also that the XML parse tree is cached to speed up creating another Glade::Xml object for the same file.

std::string Xfc::Glade::Xml::get_filename  )  const
 

Gets the name of the XML file that was used to create the Glade::Xml object.

Returns:
The XML filename, or an empty string if an error occurs.

template<typename WidgetType>
bool Xfc::Glade::Xml::get_widget const String name,
WidgetType *&  widget
const
 

Gets a pointer to the Gtk::Widget corresponding to name in the interface description.

Parameters:
name The name of the widget in the XML description.
widget A reference to a pointer to hold the widget matching name, or null if none exists.
Returns:
true if successful, false if no widget exists.
To use this method WidgetType must be one of the standard XFC widgets.

Example: Connecting a "clicked" signal handler to a Gtk::Button.

             Gtk::Button *button;
             if (xml->get_widget("my_button", button))
             {
                 button->signal_clicked().connect(sigc::mem_fun(this, &MyWindow::on_my_button_clicked));
             }

Gtk::Widget* Xfc::Glade::Xml::get_widget const String name  )  const
 

Gets a pointer to the Gtk::Widget corresponding to name in the interface description.

Parameters:
name The name of the widget in the XML description.
Returns:
A pointer to the widget matching name, or null if none exists.

template<typename DerivedType>
bool Xfc::Glade::Xml::get_widget_derived const String name,
DerivedType *&  widget
const
 

Gets a pointer to the Gtk::Widget corresponding to name in the interface description.

Parameters:
name The name of the widget in the XML description.
widget A reference to a pointer to hold the widget matching name, or null if none exists.
Returns:
true if successful, false if no widget exists.
To use this method DerivedType must be a user-defined widget class that derives from one of the standard XFC widgets. The derived widget class must declare it's constructor with the following signature:

             DerivedType(CObjectType *object, Glade::Xml& xml_object)

Example: Instantiating a main application window from an XML description.

             MyWindow *window;
             if (xml->get_widget_derived("MyWindow", window))
             {
                 window->signal_destroy().connect(sigc::ptr_fun(&Xfc::Main::quit));
                 window->show();
                 run();
             }

String Xfc::Glade::Xml::get_widget_name Gtk::Widget widget  )  [static]
 

Gets the name of a widget that was generated by a Glade::XML object.

Parameters:
widget The widget to get the name for.
Returns:
The name of the widget.

bool Xfc::Glade::Xml::get_widget_prefix const String prefix,
std::vector< Gtk::Widget * > &  widgets
const
 

Fills a vector with a list of pointers to the Gtk::Widget(s) with names that start with the string prefix in the XML interface description.

Parameters:
prefix The starting prefix that is part of the name of a widget(s) in the XML description.
widgets A vector of Gtk::Widget pointers to hold the widgets with names matching prefix.
Returns:
true if any widgets are found, false if no widgets exist.
You would use this method if you have to do something to all of these widgets after loading.

Pointer<Xml> Xfc::Glade::Xml::get_widget_tree Gtk::Widget widget  )  [static]
 

Gets the Glade::Xml object that built this widget.

Parameters:
widget The widget to get the name for.
Returns:
A smart pointer to the Glade::Xml object that built this widget.

std::string Xfc::Glade::Xml::relative_file const std::string &  filename  )  const
 

This method resolves a relative pathname, using the directory of the XML file as a base.

Parameters:
filename The filename to resolve.
Returns:
The filename.
If the pathname is absolute, then the original filename is returned.


The documentation for this class was generated from the following file: Xfce Foundation Classes
Copyright © 2004-2005 The XFC Development Team XFC 4.3