On May 11, 2013, at 11:37 PM, Martin Owens wrote:
On Sat, 2013-05-11 at 12:48 -0700, Jon Cruz wrote:
and not as generally useful.
I think my code is broken when using non-references with the class context changer GTK_CONTAINER and GTK_WIDGET. From other code these work with references right? Should I be using references for widgets? The code isn't always consistent and I'm not even sure why there is a difference in an OO language.
Is there a good (and short) explanation of what these things are actually doing? Plus points for diagrams. Because I need help badly and I can't seem to find any between mailing lists, irc and the web.
GTK_CONTAINER() and GTK_WIDGET() are C macros that work with pointers. Aside from casting the pointer to a different type they also check the gobject runtime structures and warn if the pointer does not match the target type. In general this is all legacy code.
The approach with C++ and gtkmm is to leverage C++ inheritance. Since Gtk::Container is a subclass of Gtk::Widget, one can simple use a reference or pointer to a Gtk::Container anywhere one for Gtk::Widget is called for, and without any need for casts of any kind (C or C++).
Gtkmm objects can hold members directly, but for widget subclasses one can create them via new, feed the pointer through Gtk::manage() and place it in a parent widget. That transfers ownership of the instance.
If you can send me some specific examples, we can get some info on the wiki to address specific points.