Re: [gtk-list] Re: Dynamic Style/Color change - I don't find the solution...



On Tue, 7 Jul 1998, Georg Greve wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> 
> Hi Tim !
> 
> Tim Janik <timj@gtk.org> writes:
> > On Mon, 6 Jul 1998, Georg Greve wrote:
> > could you provide a small example snippet?
> > your approach seems to be correct, and you should really not get a segfault
> > with this.
> 
> Sure. What I do during initialization is: 
>      GdkColormap* cmap = gdk_colormap_get_system();
> 
> and (in a loop for each object I want to be changeable later):
> 
>     myobject->style = gtk_style_copy(gtk_rc_get_style(window));

you should first add all widgets to their containers, and then do:

 style = gtk_rc_get_style (myobject->widget);

and then

 if (!style)
   style = gtk_widget_get_default_style ();

now, after you assured style != NULL, you can copy it:

 myobject->style = gtk_style_copy (style);

assuming that you have not yet realized myobject->widget, you set up the
style like this:

 myobject->style->bg[GTK_PRELIGHT].red = 0;
 myobject->style->bg[GTK_PRELIGHT].green = 0;
 myobject->style->bg[GTK_PRELIGHT].blue = 65535;

and then attach it:

 gtk_widget_set_style (myobject->widget, myobject->style);

the colors of this style will then be allocated upon realization of the widget.
 
>     gtk_widget_set_style(myobject->widget, myobject->style);
> (myobject is a class with objects GtkWidget* widget and GtkStyle* style)
> 
> window is the main window widget and this part works just fine so far
> (the style settings for the main window are being used for the
> objects).
> 
> 
> During the change-phase I do:
> 
>   GdkColor normal = {0,color triplet};
>   GdkColor plight = {0,color triplet};
> 
>   gdk_color_alloc (cmap, &normal);
>   gdk_color_alloc (cmap, &plight);
> 
> /*
> 
> 	I tried gtk_style_detach and so on here
> 
> */
>   myobject->style->bg[GTK_STATE_NORMAL].red = normal.red;
>   myobject->style->bg[GTK_STATE_NORMAL].green = normal.green;
>   myobject->style->bg[GTK_STATE_NORMAL].blue = normal.blue;
>   myobject->style->bg[GTK_STATE_PRELIGHT].red = plight.red;
>   myobject->style->bg[GTK_STATE_PRELIGHT].green = plight.green;
>   myobject->style->bg[GTK_STATE_PRELIGHT].blue = plight.blue;
> 
> /*	
> 
> 	I tried widget_realize and everything else here
> 
> */	
> 
>   if ( myobject->pixels[0] != 0 && myobject->pixels[1] != 0 )
>     gdk_colors_free(cmap, myobject->pixels, 2, 0);  
> 
>   myobject->pixels[0] = normal.pixel;
>   myobject->pixels[1] = plight.pixel;
> 
> 
> This should (in my eyes) allocate the new colors and free the ones
> that it had been changed to on the last run... 
> 
> So what is missing there ??? I am really clueless by now (which
> doesn't mean I'll stop trying... :-) ).


BTW: what is this fusebox-ml.gtk newsgroup stuff about?

> 
> Later,
> 	Georg
> 

---
ciaoTJ



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