GNOME Bugzilla – Bug 124297
Need a custom TreeModel example
Last modified: 2004-12-22 21:47:04 UTC
Some people have managed to implement custom Gtk::TreeModels, but they seem to be using strange hacky techniques. It needs to register a GType, but that should be similar to the custom cell renderer.
Created attachment 23167 [details] Feel free to simplify the GObject related stuff
So, the question is, why do need the awful C GClass stuff. Here (gtkmm_custom_treemodel2.cc) is a version that is more like what we would expect. Ignore the first warning. But it gives this bizarre warning: (a.out:24508): GLib-GObject-WARNING **: cannot add interface type `GtkTreeModel' to type `GObject', since type `GtkListStore' already conforms to interface But we don't mention ListStore anywhere in the example.
Created attachment 23281 [details] gtkmm_custom_treemodel2.cc
I just checked in a fix to both branches that makes gtkmm_custom_treemodel2.cc work. It properly implements the Glib::Object default constructor so that it generates a custom on-the-fly derived GType (derived from GObject) when you have already called teh ObjectBase(typeid(MyCustomClass)) constructor. So, now the nasty GType stuff is gone, and we just need to tidy this example up (Separate files for each class. No method implementation in a .h file.) and add some comments.
I am working on a nicer example.
Done. There's an ugly one in gtkmm 2.2 (The gtkmm2 cvs module) and a prettier more-C++ one in gtkmm 2.4). The model has no children, because I can't think of a way to manage memory of more complicated user_data information in the GtkTreeIter. At the moment, I am just shoving an int into the void* user_data.