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

Re: Changing window color



On Fri, 31 Jan 2003 11:11:52 +0100 (CET)
TORRI Vincent wrote:

> 
> Hello, 
>   I've tried to make a callback wich changes the color and, indeed,
>   the 
> background is not changed. It seems that the widget has to be redrawn.
> So I use gtk_widget_queue_draw to update it. You can try this (Perhaps
> there is some more efficient code): 
> 
> #include <gtk/gtk.h>
> 
> guint n;
> 
> GdkColor red   = {0, 0xffff, 0x0000, 0x0000};
> GdkColor gray = {1, 0x9999, 0x9999, 0x9999};
> GtkStyle *style;
> 
> void change_color(GtkWidget *b, GtkWidget *ww)
> {
>   GtkStyle *w_style;
>   GdkColor c;
> 
>   n=1-n;
> 
>   if (n==1)
>     {
>       c = gray;
>     }
>   else
>     {
>       c = red;
>     }
>   
>   gtk_widget_queue_draw (ww);
>   w_style = gtk_style_copy (style);
>   w_style->bg[GTK_STATE_NORMAL] = c;
>   style = gtk_style_copy (w_style);
>   gtk_widget_set_style (ww, style);
> }
> 
> int main(int argc, char *argv[])
> {
>   GtkWidget *w, *b;
> 
>   gtk_init(&argc, &argv);
> 
>   w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
>   gtk_container_set_border_width(GTK_CONTAINER(w), 15);
>   b = gtk_button_new_with_label("Change color");
>   gtk_signal_connect(GTK_OBJECT(b), "clicked", 
> (GtkSignalFunc)change_color, (gpointer)w);
>   gtk_container_add(GTK_CONTAINER(w), b);
>   
>   n = 0;
>   style = gtk_widget_get_style(w); 
>   
>   gtk_widget_show_all(w);
> 
>   gtk_main();
> 
>   return 0;
> }
> 
> 
> regards
> 
> Vincent TORRI
> 
> 

Many, many, many thaks. This is *exactly* what I wanted ! Many thanks
again !

-- 
Liviu BURCUSEL
Network Administrator
Registered Linux User #221627



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