Re: [gtk-list] how to swap pixmaps in a button?
- From: Owen Taylor <owt1 cornell edu>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] how to swap pixmaps in a button?
- Date: Wed, 21 Jan 1998 14:55:17 -0500
"Michael J. Hammel" <mjhammel@fastlane.net> writes:
> I've been trying to get a button to swap pixmaps when its been activated.
> I have two pixmaps and do something like the following:
>
> gtk_container_remove(
> GTK_CONTAINER(pn->pn_alarmwidget), pn->pn_alarm_pixmapid);
> gtk_container_add(
> GTK_CONTAINER(pn->pn_alarmwidget), pn->pn_alarmoff_pixmapid);
>
> I remove the old one then add the new one. But this doesn't seem to have
> any effect. Does anyone know what the steps are for swapping pixmaps in a
> button (or any widget)? Do I need to be doing this from the gdk level
> instead?
You could do it either way:
If pn->pn_alarmwidget is a box or button, an pn->pn_alarm_pixmapid
is a Pixmap _widget_, then the above should work.
A not that will be true in a week or to: (but isn't now)
You have to worry about reference counting when doing things like
this. (Reference count = how many places is information about this
widget stored) Widgets are created with refcount = 1, and a "floating
flag" when such a widget is added to a container, that initial
reference count is adopted by the container. When it is removed from
the container, the reference count is decremented, and GTK says
"aha - I can get rid of this widget, nobody is using it", and does so.
Since you are storing references to your Pixmaps elsewhere, and don't
want them to be freed, you should call gdk_object_ref() when you
create them. Then you just have to gdk_object_unref() the pixmaps when
pn is destroyed. (However that happens in your program)
Or, you could use a single Pixmap widget, and switch the
GDK pixmaps between them. In this case, you just call
gtk_pixmap_set (pn->pn_alarmwidget, my_new_gdk_pixmap);
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.
Hope this helps,
Owen
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]