Re: [gtk-list] Re: how to swap pixmaps in a button?




"Michael J. Hammel" <mjhammel@fastlane.net> writes:

> > You still have to be concerned about refcounting here, but things
> > are a bit different - there is no "floating" flag or adoption -
> > gtk_pixmap_set (and gtk_pixmap_new) just increment the reference
> > count on the pixmap that is added. So you don't have to call
> > gdk_pixmap_ref to begin with, but you do need to call
> > gdk_pixmap_unref at the end.
> 
> I'm a little confused on this part.  I create one pixmap with a call to
>    pixmap_id = gtk_pixmap_new(pixmap, mask).
> Now, when I destroy the widget that is using this I need to do
>    gdk_pixmap_unref(pixmap_id)
> Is that correct?

If you are only putting _one_ pixmap into the Pixmap, and you
don't want to do anything else with it, then you can _unref()
it immediately on creation:

  pixmap = gdk_pixmap_create_...
  mask = gdk_bitmap_create_...
  pixmap_widget = gtk_pixmap_new (pixmap, mask);
  gdk_pixmap_unref (pixmap);
  gdk_pixmap_unref (mask);

If you do this, then you don't have to worry any further about
the pixmap, since the only reference to it is held by the
Pixmap widget. Which will be destroyed when the toplevel 
holding the Pixmap widget is destroyed.
 
> One other thing - when I destroy the button in which these pixmaps live, I
> do so by destroying the top level widget (a dialog window).  Won't that
> clean up everything on its own?  Or do I need to do the gdk_pixmap_unref()
> anyway?

You do need the gdk_pixmap_unref() because one of the pixmaps
won't be referenced by the pixmap at all. While you could
only hold a reference to the other one, and let that one be
destroyed with the Pixmap widget, I think that is more complex
than holding an extra reference to both.

If you don't already have a function that is being invoked
when the dialog is destroyed (i.e., a handler for the "destroy"
signal for the dialog), you could put the _unref() in "destroy"
handler for the Pixmap.

Regards,
                                        Owen



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