Re: GtkStyleKey / GtkStyle




Jost Boekemeier <jostobfe@calvados.zrz.TU-Berlin.DE> writes:

> Umm no, I just changed the order of the symbols. 
> The size of _GtkStyleKey and  _GtkStyle remains the same.
> 
> gtk_style_find() creates a GtkStyleKey key, fills in the
> appropriate values (fg, bg, text, .., depth, cmap), calls
> gtk_cache_insert, which then duplicates the key and allocates
> more memory at the end of the structure. This key is then casted to
> GtkStyle and given to gtk_style_init (GtkStyle *style), which reads some
> values (fg, bg) and fills other values into the spaces allocated at the end 
> of GtkStyleKey (now GtkStyle).

Huh?  g_cache_insert, calls gtk_style_new_from_key(), which, if
it has to create a new style, copies values from the key over, field
by field. There is no requirement that they have the same layout.

(It would be slightly more efficient if the first portion of a style
could be used as the key, but that is a different animal then whether
the current code is correct)

The user should never see GtkStyleKey at all. (There may be a bug
somewhere, but I don't see that it is what you are claiming)

> In other words: GtkStyle /is a/ GtkStyleKey, with some fields added at its end.
> So the current implementation is wrong:

You'll have to do some more work to convince me of that. Styles
certainly seem to work reasonably OK now; they'd be pretty broken
if you are right. Do you have a test case?

> struct _GtkStyleKey		struct _GtkStyle
> {				{
>   GdkColor fg[5];		  GdkColor fg[5];
>   GdkColor bg[5];		  GdkColor bg[5];
>   GdkColor text[5];		  GdkColor light[5];
>   GdkColor base[5];		  GdkColor dark[5];
> 				  GdkColor mid[5];
>   GdkPixmap *bg_pixmap[5];	  GdkColor text[5];
> 				  GdkColor base[5];
>   GdkFont *font;

[...]


> By the way, is there any documentation available? You've written
> nice code, but it is a bit difficult to understand when there is
> no comment what a function does.

If that is the singular "you", then I'm afraid I can't take credit
for the style code. (Or most of GTK) Peter Mattis still gets credit
for 80% or so of the code and the design. No, there isn't any real
documentation for the internals of the style stuff.

Regards,
                                        Owen



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