Hello, I have a custom widget that I've implemented in C and then used gmmproc[1] to generate C++ bindings for that widget. The process was mostly smooth, but I cannot seem to use my generated C++ bindings in Gtk::Builder::get_widget. I can post the full source code if needed, but probably there is something simple that I a missing so I'll start with what I think is most relevant:
My widget is a relatively simple extension of GtkDrawingArea which adds the ability to pan and zoom using mouse motion and mouse wheel. It's called GtkPanZoomArea. I have created a Glade catalog XML file which allows me to use my custom widget in glade. I have successfully used my widget in an application using the plain-C API, retrieving a pointer to an instance of this widget like so: ~~~ GtkPanZoomArea* panzoom_ = GTK_PANZOOM_AREA(builder->get_object("overhead-view")->gobj()); ~~~ I have gone through the process of using `h2def.py` and `enum.py`, and written a custom `gen_extra_defs.cc` (using `glibmm_generate_extra_defs`) to generate def files, and I have used `gmmproc` to generate the `mm-` wrapper `Gtk::PanZoomArea`. Everything compiles, but when I change the above code to: ~~~ Gtk::PanZoomArea panzoom_; builder->get_widget("overhead-view", panzoom_) ~~~ the member is assigned nullptr and I see the following errors printed to stderr: ~~~ : CRITICAL **: 13:53:12.873: Gtk::Builder::get_widget(): dynamic_cast<> failed. ~~~ The following works: ~~~ Gtk::DrawingArea* drawingarea; builder->get_widget("overhead-view", drawingarea); ~~~ But then this subsequently does not work: ~~~ auto panzoom_ = dynamic_cast<Gtk::PanZoomArea*>(drawingarea); ~~~ My guess is that the most likely place for there to be an error is in the `.hg` file so here is the class declaration I have in `mm/panzoomarea.hg`: ~~~ class PanZoomArea : public Gtk::DrawingArea { _CLASS_GOBJECT(PanZoomArea, GtkPanZoomArea, GTK_PANZOOM_AREA, Gtk::DrawingArea, GtkDrawingArea); ~~~ And here is the type declaration in `panzoomarea.h`: ~~~ G_DECLARE_DERIVABLE_TYPE(GtkPanZoomArea, gtk_panzoom_area, GTK, PANZOOM_AREA, GtkDrawingArea); ~~~ Does anyone know what I'm doing wrong here? The code for `get_widget_checked` in `builder.ccg`[2] looks like it would print errors if there were any problem retrieving the widget and checking the type and since it does neither of these, it seems to be a problem in `Glib::wrap`. For some reason `Glib::wrap` is constructing a C++ object other than my object. It appears to be constructing a `Gtk::DrawingArea`. Assuming the `Glib::wrap` uses the gobject type registry, I added the following in my `main()`: ~~~ auto _ignoreme = Gtk::PanZoomArea::get_type(); (void)_ignoreme; ~~~ but this did not fix the problem. [1]: https://developer.gnome.org/gtkmm-tutorial/stable/chapter-wrapping-c-libraries.html.en [2]: https://fossies.org/linux/gtkmm/gtk/src/builder.ccg#290
_______________________________________________ gtkmm-list mailing list gtkmm-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtkmm-list