Re: Reverse-wrapping gtkmm widgets to gtk+ (for glade3)



On Sat, 2006-11-18 at 15:56 +0100, Alexander Brinkman wrote:
> On Sat, 2006-11-18 at 11:23 +0100, Murray Cumming wrote:
> > If you have some example code, I'd like to look into this.
> 
> Attached you will find example code that does what I wrote earlier:
> 
> - mywidget.cxx / mywidget.h: MyWidget, derived from Gtk::Label.
> - main.cxx: the main code.
> - mywidet-example.glade: glade file which should create a MyWidget.
> 
> If you comment out the init_widgets() function in main() you'll notice
> that libglade starts complaining about not knowing about the
> gtkmm__CustomObject_mywidget type.

I added a check for the G_OBJECT_TYPE_NAME of the object returned by
Glade::get_widget. That showed me that the correct C object was being
instantiated.

But the problem then is that Glib::wrap(), used by Glade::get_widget(),
doesn't know how to convert the C object (based on its GType) to a C++
instance, so it falls back to Gtk::Label.

I added a call to Glib::wrap_register() to fix this, and now it seems to
work - see the attachment. This is analogous to what happens when you
use an extra wrapper library. For instance, I am using gtksourceviewmm
(which extends GtkTextView) in Glom with libglade in the same way, and
the init() function of gtksourceviewmm does this for us.

I'll have to think about how this might be done automatically when using
a custom GType, but I don't think it's too inconvenient now. If it works
without problems then we should add a section the gtkmm book about it.

Thanks for exploring this.

-- 
Murray Cumming
murrayc murrayc com
www.murrayc.com
www.openismus.com

Attachment: mywidget_murrayc.tar.gz
Description: application/compressed-tar



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]