Re: Reparenting bug

Conrad Steenberg <> writes:

> On Thu, 22 Jul 1999, Havoc Pennington wrote:
> > Anyway, I think the problem is that GtkSpinButton has two subwindows that
> > are direct children of its parent's windows, so gtk_widget_reparent()'s
> > attempt to reparent widget->window and save an unrealize leaves the
> > subwindow containing the little arrows behind. Using
> > container_remove()/container_add() will be a nice workaround, but this is
> > really a Gtk bug, I think. At least, I"m guessing that that's the problem.
> Hmmm, container_remove doesn't by any chance destroy the widget as well?
> Doing a remove/add as suggested results in the remove succeeding, but the
> add failing complaining that the child widget is not a widget anymore.

The parent widget holds the reference count on the widget, so
you need to do:

 gtk_object_ref (widget);
 gtk_container_remove (old_parent, widget);
 gtk_container_add (new_parent, widget);
 gtk_object_unref (widget);

> Anyway, as far as the reparenting goes, doing a reparent once works (out
> of original window), reparent back fails (back to original), and reparent
> again (out out original) works again. So it is the 'moving back to
> original window' op that fails.

Reparenting is broken for a number of widgets; that needs
to be fixed at some point; that could be done a couple
of ways.

 1) Add another widget flag which says: "This widget
    cannot be reparented using XReparentWindow()"

 2) Give up on reparenting - simply make gtk_widget_reparent
    always do the above ref()/remove()/add()/unref() sequence.
    This is going to be 99% as efficient as what
    reparent does now ... the only thing that you
    save currently is destroying and creating the
    X windows.

 3) Scan all child GdkWindows of the parent window
    and try to figure out which ones belong to the
    widget. This is, I suspect, not going to be 
    reliable, anyways.

If you want to add a bug report to the bug tracker about
this, it will help make sure that it doesn't forgotten
about. For now, just use container_remove()/add(). 


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