Re: how to remove a CanvasWidget from a canvas and put it on another

Thomas Morris wrote:
> Havoc Pennington wrote:
> > writes:
> > > > I've tried your suggestion however when the canvas is destroyed the  canvasitem
> > > > that is associated with the gtkwidget is destroyed and subsequently performs a
> > > > gtk_widget_destroy() on the gtkwidget. Calling gtk_widget_ref() before destroying
> > > > the canvas doesn't seem to keep the widget from being destroyed along with the
> > > > canvasitem.
> > >
> > > This sounds like a bug. A widget should not be destroyed if there is a ref held
> > > on it.
> > >
> >
> > False, destruction has nothing to do with the refcount. The refcount
> > merely prevents finalization. has
> > some text on this point.
> >
> thats a great point about refcount. It solves a few problems that I've experienced. I
> hadn't dug deep enough into gtk to figure this out. I am still at a loss on how exactly
> to remove a CanvasWidget from a canvas without destroying the underlying widget. I want
> to cleanly move a widget from one canvas to another by removing the widget from the
> first canvas, destroying the canvas, then creating a CanvasWidget on the second canvas
> from the widget I removed from the first. I've got a way to make this work however it
> means accessing some of the CanvasItems' struct members directly instead of throught
> member functions. Basically what I would like is a gnome_canvas_remove_item(GnomeCanvas
> *c, GnomeCanvasItem *i) function that removes the CanvasItem but doesn't destroy the
> widget used to create CanvasItemWidgets.  I thought using gtk_container_remove would do
> the trick but it doesn't.  Anyway, thanks for the help and enlightening me on refcounts.

It is a bug. gnome_canvas_widget_destroy() calls gtk_widget_destroy()
which destroys
your widget.

You may be able to work around it by:

 o calling gtk_widget_ref() on the widget.
 o setting the "widget" arg of the canvas item to NULL. (The
   function calls gtk_container_remove() instead of
 o destroying the canvas item.
 o adding the widget to the new GnomeCanvasWidget item.
 o calling gtk_widget_unref() to unref it.

(There also seems to be a bug in gnome_canvas_widget_set_arg() - if you
set the widget to
NULL it does not set the widget field to NULL.)


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