Re: libglademm proposed change: arbitrary constructors for get_widget_derived
- From: Murray Cumming <murrayc murrayc com>
- To: Marek Materzok <tilk lucifer czad org>
- Cc: gnomemm-list <gnomemm-list gnome org>
- Subject: Re: libglademm proposed change: arbitrary constructors for get_widget_derived
- Date: Wed, 04 May 2005 18:17:19 +0200
On Mon, 2005-05-02 at 00:37 +0200, Marek Materzok wrote:
> Hello,
>
> It's convenient to code window's functionality in classes derived from
> Gtk::Window or Gtk::Dialog. Gtkmm makes it easy to do so, but libglademm
> puts a restriction on this. It requires, that the derived widgets
> constructed from gtkmm should have two specific parameters: pointer to
> GtkWidget and RefPtr to Glade::Xml.
It must have a GtkWidget* (or GObject* actually) parameter with
get_widget() too.
> The attached patch adds overloaded version of get_widget_derived, which
> allows arbitrary constructors in derived widgets. The last parameter of
> this function is a construction functor, which receives the two original
> construction parameters (GtkWidget* and RefPtr<Glade::Xml>). There exist
> facilities allowing to construct such a functor - for example
> boost::bind or sigc::bind.
I'd prefer to use a sigc::slot<> explicitly here. It's clearer.
Also, Glib::RefPtr<Gnome::Glade::Xml> should be passed by const
reference.
> The ConstructDerived functor in the patch is
> just a wrapper, added for the purpose of not duplicating the code of
> get_widget_derived function. ConstructDerived should not be part of the
> interface, so it probably should be hidden somewhere (maybe in private
> part of Glade::Xml?)
I think it's slightly useful. It allows you to use a derived widget but
do things to that widget's children outside of the class, instead of
inside. Personally, I think the derived widget should not want you to
mess around with its (normally protected) child widgets directly like
this. Can you persuade me that it's useful?
If you revise the patch, please put it in bugzilla:
http://www.gtkmm.org/bugs.shtml#CreatingPatches
This idea might also be interesting. I _still_ have not looked at it
properly:
http://bugzilla.gnome.org/show_bug.cgi?id=134161
Thanks
> What do you think about it?
>
> Marek Materzok
>
> --- xml.h.old 2005-05-02 00:15:23.000000000 +0200
> +++ xml.h 2005-04-23 00:42:48.000000000 +0200
> @@ -61,6 +61,17 @@
> Glib::ustring message_;
> };
>
> +class Xml;
> +
> +template <class T_Widget>
> +struct ConstructDerived
> +{
> + typedef typename T_Widget::BaseObjectType cwidget_type;
> + T_Widget *operator()(cwidget_type *pCWidget, Glib::RefPtr<Gnome::Glade::Xml> refThis) const
> + {
> + return new T_Widget(pCWidget, refThis);
> + }
> +};
>
> class Xml : public Glib::Object
> {
> @@ -228,6 +239,12 @@
> template <class T_Widget> inline
> T_Widget* get_widget_derived(const Glib::ustring& name, T_Widget*& widget)
> {
> + return get_widget_derived<T_Widget, ConstructDerived<T_Widget> >(name, widget, ConstructDerived<T_Widget>());
> + }
> +
> + template <class T_Widget, typename T_Construct> inline
> + T_Widget* get_widget_derived(const Glib::ustring& name, T_Widget*& widget, const T_Construct &construct)
> + {
> // initialize input parameter
> widget = 0;
>
> @@ -260,7 +277,7 @@
> //Set the output variable. We needed to do this because we can not template the return type.
> Glib::RefPtr<Gnome::Glade::Xml> refThis(this);
> refThis->reference(); //take a copy.
> - widget = new T_Widget(pCWidget, refThis);
> + widget = construct(pCWidget, refThis);
> }
>
> //We return it as well (we need the parameter as well, because C++ can not just template the return type.)
>
> _______________________________________________
> gnomemm-list mailing list
> gnomemm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gnomemm-list
--
Murray Cumming
murrayc murrayc com
www.murrayc.com
www.openismus.com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]