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



On 8 Jul 1998, Georg Greve wrote:

> 
> Hi Tim !
> 

> > 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.
> 
> Doing that as well. In fact I got the color shift working
> yesterday. What is bothering me is that I have to do a copy and and a
> set every time. Am I allocating more and more memory there ???

GtkStyles use regular reference counting and thus they usually get destroyed
automatically once their use count drops to zero.
though while looking at the code, i just figured there seems to be a
possibility for some inconsistent referencing situations, but that needs
further investigation.

> How are the widget styles handled ?? Does the old one get destroyed
> automatically when the new one is being attached ?? It seems to be
> that way... if it is the case I got the thing ready. I am doing:
> 
>     style = gtk_style_copy(stdstyle);
>     style->bg[GTK_STATE_NORMAL].red = normal.red;
>     style->bg[GTK_STATE_NORMAL].green = normal.green;
>     style->bg[GTK_STATE_NORMAL].blue = normal.blue;
>     style->bg[GTK_STATE_PRELIGHT].red = plight.red;
>     style->bg[GTK_STATE_PRELIGHT].green = plight.green;
>     style->bg[GTK_STATE_PRELIGHT].blue = plight.blue;
>     gtk_widget_set_style(button, style);

hm, actuually you should call
  gtk_style_unref (style);
after gtk_widget_set_style(), because gtk_style_copy() sets up the reference
count with one, and gtk_widget_set_style() cares about referencing
the style on its own.

> But this can be called pretty often over time, so I'd like to make
> sure no resources are wasted this way.

> 
> Later,
> 	Georg
> 

---
ciaoTJ



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