Re: [gtk-list] Re: Redrawing an Object?
- From: Marc <marc upr41 univ-rennes1 fr>
- To: "gtk-list redhat com" <gtk-list redhat com>
- Subject: Re: [gtk-list] Re: Redrawing an Object?
- Date: Fri, 03 Jul 1998 10:52:24 +0200
Frank Sweetser wrote:
>
>
> hi... i went off to try this (having had a similar problem), but i can't
> seem to get gtk_pixmap_new even to work. what documentation i could find
> doesn't even match the header files, and the url to the archives someone
> else posted also doesn't work, so would a kind sould please send me a code
> snippet demonstrating this, or at least explain it a little more?
>
Two buttons in a vbox, one with a pixmap in it...
When you click this button the pixmap changes (and the button gets
insensitive ... just for the fun) !
Hope it'll help.
/* Change Pixmap in a Button */
#include <gtk/gtk.h>
GtkWidget *window;
GtkWidget *pixmapwid;
GtkWidget *button;
GtkStyle *style;
static char * pix1_xpm[] = {
"14 14 3 1",
" c None",
". c #7F7F7F",
"+ c #0019FF",
" ",
" . ",
" . ",
" ........... ",
" ............ ",
" ",
" ",
" ++++++++++++ ",
" +++++++++++ ",
" + ",
" + ",
" ",
" ",
" "};
static char * pix2_xpm[] = {
"14 14 3 1",
" c None",
". c #B2B2B2",
"+ c #A0A0A0",
" ",
" . ",
" . ",
" ........... ",
" ............ ",
" ",
" ",
" ++++++++++++ ",
" +++++++++++ ",
" + ",
" + ",
" ",
" ",
" "};
GtkWidget * new_pixmap (char **filename, GdkWindow *window, GdkColor
*transparent);
void ButtonClicked_callback (GtkWidget *widget, gpointer data);
GtkWidget * new_pixmap (char **filename, GdkWindow *window, GdkColor
*transparent)
{
GtkWidget *wpixmap;
GdkPixmap *pixmap;
GdkBitmap *mask;
pixmap = gdk_pixmap_create_from_xpm_d (window, &mask, transparent,
filename);
wpixmap = gtk_pixmap_new (pixmap, mask);
return wpixmap;
}
void ButtonClicked_callback (GtkWidget *widget, gpointer data)
{
gtk_container_remove (GTK_CONTAINER(button), pixmapwid);
pixmapwid = new_pixmap ((char **)pix2_xpm, window->window,
&style->bg[GTK_STATE_NORMAL]);
gtk_widget_show (pixmapwid);
gtk_container_add (GTK_CONTAINER (button), pixmapwid );
gtk_widget_set_state (GTK_WIDGET (button), GTK_STATE_INSENSITIVE);
}
int main (int argc, char *argv[])
{
GtkWidget *main_vbox;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Change Pixmap In A
Button");
gtk_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
gtk_container_border_width (GTK_CONTAINER (window), 5);
gtk_widget_set_usize (GTK_WIDGET (window), 250, 60);
main_vbox = gtk_vbox_new (FALSE, 1);
gtk_container_add (GTK_CONTAINER (window), main_vbox);
gtk_widget_realize (window);
button = gtk_button_new_with_label ("Quit");
gtk_box_pack_start (GTK_BOX (main_vbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (gtk_widget_destroy),
GTK_OBJECT(window) );
style = gtk_widget_get_style (window);
/* Pixmap Widget */
pixmapwid = new_pixmap ((char **)pix1_xpm, window->window,
&style->bg[GTK_STATE_NORMAL]);
gtk_widget_show (pixmapwid);
/* Button */
button = gtk_button_new();
gtk_box_pack_start (GTK_BOX (main_vbox), button, FALSE, FALSE, 0);
gtk_container_add (GTK_CONTAINER (button), pixmapwid );
gtk_widget_show(button);
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (ButtonClicked_callback), NULL);
gtk_widget_show (main_vbox);
gtk_widget_show (window);
gtk_main ();
return 0;
} /* end main */
--
Marc
** ERROR **: sigsegv caught
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]