1 /* Clearlooks theme engine
2 * Copyright (C) 2005 Richard Stellingwerff.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
19 * Written by Owen Taylor <otaylor@redhat.com>
20 * and by Alexander Larsson <alexl@redhat.com>
21 * Modified by Richard Stellingwerff <remenic@gmail.com>
22 * Modified by Kulyk Nazar <schamane@myeburg.net>
25 #include "clearlooks_style.h"
26 #include "clearlooks_rc_style.h"
28 #include "animation.h"
30 static void clearlooks_rc_style_init (ClearlooksRcStyle
*style
);
32 static void clearlooks_rc_style_finalize (GObject
*object
);
34 static void clearlooks_rc_style_class_init (ClearlooksRcStyleClass
*klass
);
35 static GtkStyle
*clearlooks_rc_style_create_style (GtkRcStyle
*rc_style
);
36 static guint
clearlooks_rc_style_parse (GtkRcStyle
*rc_style
,
37 GtkSettings
*settings
,
39 static void clearlooks_rc_style_merge (GtkRcStyle
*dest
,
43 static GtkRcStyleClass
*clearlooks_parent_rc_class
;
45 GType clearlooks_type_rc_style
= 0;
49 TOKEN_SCROLLBARCOLOR
= G_TOKEN_LAST
+ 1,
50 TOKEN_COLORIZESCROLLBAR
,
53 TOKEN_PROGRESSBARSTYLE
,
57 TOKEN_LISTVIEWITEMSTYLE
,
76 clearlooks_gtk2_rc_symbols
[] =
78 { "scrollbar_color", TOKEN_SCROLLBARCOLOR
},
79 { "colorize_scrollbar", TOKEN_COLORIZESCROLLBAR
},
80 { "contrast", TOKEN_CONTRAST
},
81 { "sunkenmenubar", TOKEN_SUNKENMENU
},
82 { "progressbarstyle", TOKEN_PROGRESSBARSTYLE
},
83 { "menubarstyle", TOKEN_MENUBARSTYLE
},
84 { "toolbarstyle", TOKEN_TOOLBARSTYLE
},
85 { "menuitemstyle", TOKEN_MENUITEMSTYLE
},
86 { "listviewitemstyle", TOKEN_LISTVIEWITEMSTYLE
},
87 { "animation", TOKEN_ANIMATION
},
88 { "style", TOKEN_STYLE
},
89 { "radius", TOKEN_RADIUS
},
91 { "CLASSIC", TOKEN_CLASSIC
},
92 { "GLOSSY", TOKEN_GLOSSY
},
93 { "INVERTED", TOKEN_INVERTED
},
94 { "GUMMY", TOKEN_GUMMY
},
96 { "TRUE", TOKEN_TRUE
},
97 { "FALSE", TOKEN_FALSE
}
102 clearlooks_rc_style_register_type (GTypeModule
*module
)
104 static const GTypeInfo object_info
=
106 sizeof (ClearlooksRcStyleClass
),
107 (GBaseInitFunc
) NULL
,
108 (GBaseFinalizeFunc
) NULL
,
109 (GClassInitFunc
) clearlooks_rc_style_class_init
,
110 NULL
, /* class_finalize */
111 NULL
, /* class_data */
112 sizeof (ClearlooksRcStyle
),
114 (GInstanceInitFunc
) clearlooks_rc_style_init
,
118 clearlooks_type_rc_style
= g_type_module_register_type (module
,
125 clearlooks_rc_style_init (ClearlooksRcStyle
*clearlooks_rc
)
127 clearlooks_rc
->style
= CL_STYLE_CLASSIC
;
129 clearlooks_rc
->flags
= 0;
131 clearlooks_rc
->contrast
= 1.0;
132 clearlooks_rc
->menubarstyle
= 0;
133 clearlooks_rc
->toolbarstyle
= 0;
134 clearlooks_rc
->animation
= FALSE
;
135 clearlooks_rc
->colorize_scrollbar
= FALSE
;
136 clearlooks_rc
->radius
= 3.0;
139 #ifdef HAVE_ANIMATION
141 clearlooks_rc_style_finalize (GObject
*object
)
143 /* cleanup all the animation stuff */
144 clearlooks_animation_cleanup ();
146 if (G_OBJECT_CLASS (clearlooks_parent_rc_class
)->finalize
!= NULL
)
147 G_OBJECT_CLASS (clearlooks_parent_rc_class
)->finalize(object
);
153 clearlooks_rc_style_class_init (ClearlooksRcStyleClass
*klass
)
155 GtkRcStyleClass
*rc_style_class
= GTK_RC_STYLE_CLASS (klass
);
156 #ifdef HAVE_ANIMATION
157 GObjectClass
*g_object_class
= G_OBJECT_CLASS (klass
);
160 clearlooks_parent_rc_class
= g_type_class_peek_parent (klass
);
162 rc_style_class
->parse
= clearlooks_rc_style_parse
;
163 rc_style_class
->create_style
= clearlooks_rc_style_create_style
;
164 rc_style_class
->merge
= clearlooks_rc_style_merge
;
166 #ifdef HAVE_ANIMATION
167 g_object_class
->finalize
= clearlooks_rc_style_finalize
;
172 clearlooks_gtk2_rc_parse_boolean (GtkSettings
*settings
,
179 token
= g_scanner_get_next_token(scanner
);
181 token
= g_scanner_get_next_token(scanner
);
182 if (token
!= G_TOKEN_EQUAL_SIGN
)
183 return G_TOKEN_EQUAL_SIGN
;
185 token
= g_scanner_get_next_token(scanner
);
186 if (token
== TOKEN_TRUE
)
188 else if (token
== TOKEN_FALSE
)
197 clearlooks_gtk2_rc_parse_color(GtkSettings
*settings
,
205 /* Skip 'blah_color' */
206 token
= g_scanner_get_next_token(scanner
);
208 token
= g_scanner_get_next_token(scanner
);
209 if (token
!= G_TOKEN_EQUAL_SIGN
)
210 return G_TOKEN_EQUAL_SIGN
;
212 return gtk_rc_parse_color (scanner
, color
);
216 clearlooks_gtk2_rc_parse_double (GtkSettings
*settings
,
225 token
= g_scanner_get_next_token(scanner
);
227 token
= g_scanner_get_next_token(scanner
);
228 if (token
!= G_TOKEN_EQUAL_SIGN
)
229 return G_TOKEN_EQUAL_SIGN
;
231 token
= g_scanner_get_next_token(scanner
);
232 if (token
!= G_TOKEN_FLOAT
)
233 return G_TOKEN_FLOAT
;
235 *val
= scanner
->value
.v_float
;
241 clearlooks_gtk2_rc_parse_int (GtkSettings
*settings
,
243 guint8
*progressbarstyle
)
249 /* Skip 'sunkenmenubar' */
250 token
= g_scanner_get_next_token(scanner
);
252 token
= g_scanner_get_next_token(scanner
);
253 if (token
!= G_TOKEN_EQUAL_SIGN
)
254 return G_TOKEN_EQUAL_SIGN
;
256 token
= g_scanner_get_next_token(scanner
);
257 if (token
!= G_TOKEN_INT
)
260 *progressbarstyle
= scanner
->value
.v_int
;
266 clearlooks_gtk2_rc_parse_style (GtkSettings
*settings
,
268 ClearlooksStyles
*style
)
274 g_assert (CL_NUM_STYLES
== CL_STYLE_GUMMY
+ 1); /* so that people don't forget ;-) */
277 token
= g_scanner_get_next_token (scanner
);
279 token
= g_scanner_get_next_token (scanner
);
280 if (token
!= G_TOKEN_EQUAL_SIGN
)
281 return G_TOKEN_EQUAL_SIGN
;
283 token
= g_scanner_get_next_token (scanner
);
288 *style
= CL_STYLE_CLASSIC
;
291 *style
= CL_STYLE_GLOSSY
;
294 *style
= CL_STYLE_INVERTED
;
297 *style
= CL_STYLE_GUMMY
;
300 return TOKEN_CLASSIC
;
307 clearlooks_gtk2_rc_parse_dummy (GtkSettings
*settings
,
316 token
= g_scanner_get_next_token (scanner
);
318 /* print a warning. Isn't there a way to get the string from the scanner? */
319 g_scanner_warn (scanner
, "Clearlooks configuration option \"%s\" is not supported and will be ignored.", name
);
322 token
= g_scanner_get_next_token (scanner
);
323 if (token
!= G_TOKEN_EQUAL_SIGN
)
324 return G_TOKEN_EQUAL_SIGN
;
326 /* eat whatever comes next */
327 token
= g_scanner_get_next_token (scanner
);
333 clearlooks_rc_style_parse (GtkRcStyle
*rc_style
,
334 GtkSettings
*settings
,
338 static GQuark scope_id
= 0;
339 ClearlooksRcStyle
*clearlooks_style
= CLEARLOOKS_RC_STYLE (rc_style
);
345 /* Set up a new scope in this scanner. */
348 scope_id
= g_quark_from_string("clearlooks_theme_engine");
350 /* If we bail out due to errors, we *don't* reset the scope, so the
351 * error messaging code can make sense of our tokens.
353 old_scope
= g_scanner_set_scope(scanner
, scope_id
);
355 /* Now check if we already added our symbols to this scope
356 * (in some previous call to clearlooks_rc_style_parse for the
360 if (!g_scanner_lookup_symbol(scanner
, clearlooks_gtk2_rc_symbols
[0].name
))
362 for (i
= 0; i
< G_N_ELEMENTS (clearlooks_gtk2_rc_symbols
); i
++)
363 g_scanner_scope_add_symbol(scanner
, scope_id
,
364 clearlooks_gtk2_rc_symbols
[i
].name
,
365 GINT_TO_POINTER(clearlooks_gtk2_rc_symbols
[i
].token
));
368 /* We're ready to go, now parse the top level */
370 token
= g_scanner_peek_next_token(scanner
);
371 while (token
!= G_TOKEN_RIGHT_CURLY
)
375 case TOKEN_SCROLLBARCOLOR
:
376 token
= clearlooks_gtk2_rc_parse_color (settings
, scanner
, &clearlooks_style
->scrollbar_color
);
377 clearlooks_style
->flags
|= CL_FLAG_SCROLLBAR_COLOR
;
379 case TOKEN_COLORIZESCROLLBAR
:
380 token
= clearlooks_gtk2_rc_parse_boolean (settings
, scanner
, &clearlooks_style
->colorize_scrollbar
);
381 clearlooks_style
->flags
|= CL_FLAG_COLORIZE_SCROLLBAR
;
384 token
= clearlooks_gtk2_rc_parse_double (settings
, scanner
, &clearlooks_style
->contrast
);
385 clearlooks_style
->flags
|= CL_FLAG_CONTRAST
;
387 case TOKEN_MENUBARSTYLE
:
388 token
= clearlooks_gtk2_rc_parse_int (settings
, scanner
, &clearlooks_style
->menubarstyle
);
389 clearlooks_style
->flags
|= CL_FLAG_MENUBARSTYLE
;
391 case TOKEN_TOOLBARSTYLE
:
392 token
= clearlooks_gtk2_rc_parse_int (settings
, scanner
, &clearlooks_style
->toolbarstyle
);
393 clearlooks_style
->flags
|= CL_FLAG_TOOLBARSTYLE
;
395 case TOKEN_ANIMATION
:
396 token
= clearlooks_gtk2_rc_parse_boolean (settings
, scanner
, &clearlooks_style
->animation
);
397 clearlooks_style
->flags
|= CL_FLAG_ANIMATION
;
400 token
= clearlooks_gtk2_rc_parse_style (settings
, scanner
, &clearlooks_style
->style
);
401 clearlooks_style
->flags
|= CL_FLAG_STYLE
;
404 token
= clearlooks_gtk2_rc_parse_double (settings
, scanner
, &clearlooks_style
->radius
);
405 clearlooks_style
->flags
|= CL_FLAG_RADIUS
;
408 /* stuff to ignore */
409 case TOKEN_SUNKENMENU
:
410 token
= clearlooks_gtk2_rc_parse_dummy (settings
, scanner
, "sunkenmenu");
412 case TOKEN_PROGRESSBARSTYLE
:
413 token
= clearlooks_gtk2_rc_parse_dummy (settings
, scanner
, "progressbarstyle");
415 case TOKEN_MENUITEMSTYLE
:
416 token
= clearlooks_gtk2_rc_parse_dummy (settings
, scanner
, "menuitemstyle");
418 case TOKEN_LISTVIEWITEMSTYLE
:
419 token
= clearlooks_gtk2_rc_parse_dummy (settings
, scanner
, "listviewitemstyle");
423 g_scanner_get_next_token(scanner
);
424 token
= G_TOKEN_RIGHT_CURLY
;
428 if (token
!= G_TOKEN_NONE
)
431 token
= g_scanner_peek_next_token(scanner
);
434 g_scanner_get_next_token(scanner
);
436 g_scanner_set_scope(scanner
, old_scope
);
442 clearlooks_rc_style_merge (GtkRcStyle
*dest
,
445 ClearlooksRcStyle
*dest_w
, *src_w
;
446 ClearlooksRcFlags flags
;
448 clearlooks_parent_rc_class
->merge (dest
, src
);
450 if (!CLEARLOOKS_IS_RC_STYLE (src
))
453 src_w
= CLEARLOOKS_RC_STYLE (src
);
454 dest_w
= CLEARLOOKS_RC_STYLE (dest
);
456 flags
= (~dest_w
->flags
) & src_w
->flags
;
458 if (flags
& CL_FLAG_STYLE
)
459 dest_w
->style
= src_w
->style
;
460 if (flags
& CL_FLAG_CONTRAST
)
461 dest_w
->contrast
= src_w
->contrast
;
462 if (flags
& CL_FLAG_MENUBARSTYLE
)
463 dest_w
->menubarstyle
= src_w
->menubarstyle
;
464 if (flags
& CL_FLAG_TOOLBARSTYLE
)
465 dest_w
->toolbarstyle
= src_w
->toolbarstyle
;
466 if (flags
& CL_FLAG_SCROLLBAR_COLOR
)
467 dest_w
->scrollbar_color
= src_w
->scrollbar_color
;
468 if (flags
& CL_FLAG_COLORIZE_SCROLLBAR
)
469 dest_w
->colorize_scrollbar
= src_w
->colorize_scrollbar
;
470 if (flags
& CL_FLAG_ANIMATION
)
471 dest_w
->animation
= src_w
->animation
;
472 if (flags
& CL_FLAG_RADIUS
)
473 dest_w
->radius
= src_w
->radius
;
475 dest_w
->flags
|= src_w
->flags
;
479 /* Create an empty style suitable to this RC style
482 clearlooks_rc_style_create_style (GtkRcStyle
*rc_style
)
486 return GTK_STYLE (g_object_new (CLEARLOOKS_TYPE_STYLE
, NULL
));