Changing icon of button on toolbar
- From: Edoardo Vigoni <vigoni aero polimi it>
- To: gtk-app-devel-list gnome org
- Subject: Changing icon of button on toolbar
- Date: 10 Jul 2003 09:11:14 +0200
I must change icon of a button clicking it.
I found an old mail in this list in wich there was the following code,
but doesn't work. Compiler didn't accept. I don't understand
GTK_PIXMAP(widget->button->pixmapwid). I substituted it with
GTK_PIXMAP(data), but crashed. What's the solution?
Thank's
#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);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]