Hey!

Murrayc asked me to provide an introduction into the alternative way of
instantiating derived widgets using libglademm as described here by André:


  http://mail.gnome.org/archives/gtkmm-list/2007-October/msg00074.html


For convenience, I've uploaded the actual header file (it's only 1 small
header) here as well: http://rafb.net/p/5T3xSC85.html

The reasoning for even considering this system is so that we can potentially
put away with the custom constructor for derived widgets, and make it
possible to allow custom constructors (albeit the
constructor still needs access to an instance of Gnome::Glade::Xml somehow,
which can be of course easily passed through a parameter to it).

An usage example of the proposed way is:



  #include "widgetloader.h"

  class MyWindow : public Gnome::Glade::WidgetLoader<Gtk::Window>
  {
    public:

     MyWindow( const Glib::RefPtr<Gnome::Glade::Xml>& xml )
     : Gnome::Glade::WidgetLoader<Gtk::Window>( xml,
"mywindow-widgetname-in-the-gladexml" )
     {
     }

     virtual ~MyWindow ()
     {}
  };



What does this do? Where is the difference to the usual way?

The main difference is that here, we inherit from
Gnome::Glade::WidgetLoader<>, which serves as an _instantiator_ using the


  Gtk::Widget_T::Widget_T( Gtk::Widget_T::BaseObjectType* );


constructors which every widget has. Basically, it is a constructor wrapper.

So, instead of demanding that the Widget be instantiated with the custom
constructor which currently has to be made available
in derived widgets:

  Gtk::Widget_T::Widget_T( BaseObjectType * cobj, const
Glib::RefPtr<Gnome::Glade::Xml>& ) ;

It simply does this (i think code says here more than a 1000 plain text
words would, and remember, it's templated!):

    WidgetLoader(const Glib::RefPtr<Xml>& refxml, const Glib::ustring&
widgetname) :
        /*
        * with help of get_widget the underlying
        * T_WIDGET class is initialized
        */
        T_WIDGET( get_widget(refxml, widgetname))
    {}

In "untemplated" code it would look like, for our above example:

    WidgetLoader(const Glib::RefPtr<Xml>& refxml, const Glib::ustring&
widgetname) :
        /*
        * with help of get_widget the underlying
        * T_WIDGET class is initialized
        */
        Gtk::Window((GtkWindow*)(get_widget(refxml, widgetname)))
    {}

Well, that is basically all; get_widget() is an internal function that
basically does the same as the current libglademm equivalent.

So, that is it!

Cheers!
Milosz
_______________________________________________
gtkmm-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Reply via email to