Re: GTK_FLOATING broken in 2.9?



> could you please outline why you need this in GtkMM

By default, gtkmm _Widgets_ are not owned by their containers, because
that would not allow regular C++ memory management.  For instance:

Gtk::VBox* box1 = new Gtk::VBox;
Gtk::Button button("Hello");
box1.pack_start(button); //The button is in box1.
delete box1;

Gtk::VBox* box2 = new Gtk::VBox;
box2.pack_start(button); //Now the button is in box2.

At best we'd have to have separate lifetimes for gtkmm objects and their
underlying GTK+ objects, meaning that we'd have the annoying concept of
"invalid" gtkmm objects. This works and is not something I'm going to
debate.

However, containers-owning-children is useful, as long as it's not the
default. So, we have a Gtk::manage() function that makes objects floating
again. For instance:

Gtk::VBox* box = new Gtk::VBox;
Gtk::Button* button = Gtk::manage(new Gtk::Button("Hello"));
box.pack_start(button); //The button is in box1 (and owned by box1)
delete box;
//button has now been deleted (by the box), and I shouldn't use it anymore
unless I like segfaults.

So, we need to re-float the object when we use Gtk::manage(). Hence the
use of GTK_OBJECT_SET_FLAGS(object, GTK_FLOATING)


For (not important) completeness, here's a link to the source of the
Object::set_manage() function where this happens:
in gtkmm 2.8:
http://cvs.gnome.org/viewcvs/gtkmm/gtk/src/object.ccg?rev=1.7&only_with_tag=gtkmm-2-8&view=markup

and in gtkmm 2.9, using the new glib 2.9 API:
http://cvs.gnome.org/viewcvs/gtkmm/gtk/src/object.ccg?view=markup


> (especially
> considering that james gets along without it in python)?

I guess reference-counting/garbage-collection is the default (only?)
memory management used in Python.

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]