Re: changing icon of button on toolbar
- From: Emmanuel Gravel <e_gravel yahoo com>
- To: gtk-app-devel-list gnome org
- Subject: Re: changing icon of button on toolbar
- Date: Fri, 23 Feb 2001 09:09:48 -0800 (PST)
There's an easier way to do this. I've created a bit
of code, both in C and C++, that cycles through button
icons when you press on the button. I can't remember
where I got the base code for this but I'm sure it's
in one of the available tutorials on the net. All I
did
was set a callback function that used a static
variable
that I would change each time and check for. Then I'd
just re-create the pixmap each time, no destruction
necessary.
Here's the code:
#include <gtk/gtk.h>
/* Our usual callback function */
void callback( GtkWidget *widget,
gpointer data )
{
static int i=0;
GtkWidget *pix;
GdkPixmap *pixmap;
GdkBitmap *mask;
pix = GTK_WIDGET(data);
if (i==0)
pixmap = gdk_pixmap_create_from_xpm
(widget->window,
&mask,
NULL,
"stop.xpm");
else if (i==1)
pixmap = gdk_pixmap_create_from_xpm
(widget->window,
&mask,
NULL,
"start.xpm");
else
g_print("Can't get pixmap\n");
gtk_pixmap_set
(GTK_PIXMAP(widget->button->pixmapwid), pixmap, mask);
gtk_widget_show(widget->button->pixmapwid);
if (i==0)
i=1;
else
i=0;
}
int main( int argc,
char *argv[] )
{
/* GtkWidget is the storage type for widgets */
GtkWidget *window;
GtkWidget *button;
GtkWidget *pixmapwid;
GdkPixmap *pixmap;
GdkBitmap *mask;
GtkStyle *style;
gtk_init (&argc, &argv);
/* Create a new window */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Pixmap'd
Buttons!");
/* It's a good idea to do this for all windows. */
gtk_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC (gtk_exit), NULL);
gtk_signal_connect (GTK_OBJECT (window),
"delete_event",
GTK_SIGNAL_FUNC (gtk_exit), NULL);
/* Sets the border width of the window. */
gtk_container_set_border_width (GTK_CONTAINER
(window), 10);
gtk_widget_realize(window);
/* Create a new button */
button = gtk_button_new ();
/* Get the style of the button to get the
* background color. */
style = gtk_widget_get_style(window);
/* Now on to the xpm stuff */
pixmap = gdk_pixmap_create_from_xpm (window->window,
&mask,
&style->bg[GTK_STATE_NORMAL],
"start.xpm");
pixmapwid = gtk_pixmap_new (pixmap, mask);
/* Connect the "clicked" signal of the button to our
callback */
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (callback), (gpointer)
pixmapwid);
gtk_widget_show(pixmapwid);
/* Pack and show all our widgets */
gtk_container_add (GTK_CONTAINER (button),
pixmapwid);
gtk_widget_show(button);
gtk_container_add (GTK_CONTAINER (window), button);
gtk_widget_show (window);
/* Rest in gtk_main and wait for the fun to begin!
*/
gtk_main ();
return(0);
}
Hope this helps!
Manu
--- Ben Dougherty <benjamind miles33 co uk> wrote:
Carn't you hide or destroy the pixmap widget and
show/create the other
one? I believe an icon is just a GtkWidget which has
been created from
a GdkPixmap and then added to the button.
As a GtkButton is a container so you could add a
hbox container into
the button then pack as many gtkpixmaps as you want
into the box then
show/hide the pixmap you want.
Ben.
"Dennis L. Goyette Sr." wrote:
The way I was able to do it was to remove
(gtk_widget_destroy()) the
button, then toolbar, and then rebuild both. It
works but seems like so
much work when all I want to do is change the icon
associated with the
button...... any better ways???
Dennis L. Goyette Sr. wrote:
How do I change the icon associated with a
button in a toolbar?? I
want to change the icon based on another button
that is
clicked/pressed after a popup window containing
a toolbar with button
icons comes up. The button that is clicked on
in the popup
window/toolbar is the one that is to replace
another button icon....
Dennis
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices! http://auctions.yahoo.com/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]