changes associated with save/restore of AutomationControl id's
[ardour2.git] / libs / clearlooks-newer / clearlooks_rc_style.c
blobc9a30ff6b4877f9d5e9d4ba16cbc92bcc8cff589
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);
31 #ifdef HAVE_ANIMATION
32 static void clearlooks_rc_style_finalize (GObject *object);
33 #endif
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,
38 GScanner *scanner);
39 static void clearlooks_rc_style_merge (GtkRcStyle *dest,
40 GtkRcStyle *src);
43 static GtkRcStyleClass *clearlooks_parent_rc_class;
45 GType clearlooks_type_rc_style = 0;
47 enum
49 TOKEN_SCROLLBARCOLOR = G_TOKEN_LAST + 1,
50 TOKEN_COLORIZESCROLLBAR,
51 TOKEN_CONTRAST,
52 TOKEN_SUNKENMENU,
53 TOKEN_PROGRESSBARSTYLE,
54 TOKEN_MENUBARSTYLE,
55 TOKEN_TOOLBARSTYLE,
56 TOKEN_MENUITEMSTYLE,
57 TOKEN_LISTVIEWITEMSTYLE,
58 TOKEN_ANIMATION,
59 TOKEN_STYLE,
60 TOKEN_RADIUS,
62 TOKEN_CLASSIC,
63 TOKEN_GLOSSY,
64 TOKEN_INVERTED,
65 TOKEN_GUMMY,
67 TOKEN_TRUE,
68 TOKEN_FALSE
71 static struct
73 const gchar *name;
74 guint token;
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 }
101 void
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),
113 0, /* n_preallocs */
114 (GInstanceInitFunc) clearlooks_rc_style_init,
115 NULL
118 clearlooks_type_rc_style = g_type_module_register_type (module,
119 GTK_TYPE_RC_STYLE,
120 "ClearlooksRcStyle",
121 &object_info, 0);
124 static void
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
140 static void
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);
149 #endif
152 static void
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);
158 #endif
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;
168 #endif
171 static guint
172 clearlooks_gtk2_rc_parse_boolean (GtkSettings *settings,
173 GScanner *scanner,
174 gboolean *retval)
176 (void) settings;
178 guint token;
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)
187 *retval = TRUE;
188 else if (token == TOKEN_FALSE)
189 *retval = FALSE;
190 else
191 return TOKEN_TRUE;
193 return G_TOKEN_NONE;
196 static guint
197 clearlooks_gtk2_rc_parse_color(GtkSettings *settings,
198 GScanner *scanner,
199 GdkColor *color)
201 (void) settings;
203 guint token;
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);
215 static guint
216 clearlooks_gtk2_rc_parse_double (GtkSettings *settings,
217 GScanner *scanner,
218 gdouble *val)
220 (void) settings;
222 guint token;
224 /* Skip 'blah' */
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;
237 return G_TOKEN_NONE;
240 static guint
241 clearlooks_gtk2_rc_parse_int (GtkSettings *settings,
242 GScanner *scanner,
243 guint8 *progressbarstyle)
245 (void) settings;
247 guint token;
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)
258 return G_TOKEN_INT;
260 *progressbarstyle = scanner->value.v_int;
262 return G_TOKEN_NONE;
265 static guint
266 clearlooks_gtk2_rc_parse_style (GtkSettings *settings,
267 GScanner *scanner,
268 ClearlooksStyles *style)
270 (void) settings;
272 guint token;
274 g_assert (CL_NUM_STYLES == CL_STYLE_GUMMY + 1); /* so that people don't forget ;-) */
276 /* Skip 'style' */
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);
285 switch (token)
287 case TOKEN_CLASSIC:
288 *style = CL_STYLE_CLASSIC;
289 break;
290 case TOKEN_GLOSSY:
291 *style = CL_STYLE_GLOSSY;
292 break;
293 case TOKEN_INVERTED:
294 *style = CL_STYLE_INVERTED;
295 break;
296 case TOKEN_GUMMY:
297 *style = CL_STYLE_GUMMY;
298 break;
299 default:
300 return TOKEN_CLASSIC;
303 return G_TOKEN_NONE;
306 static guint
307 clearlooks_gtk2_rc_parse_dummy (GtkSettings *settings,
308 GScanner *scanner,
309 gchar *name)
311 (void) settings;
313 guint token;
315 /* Skip option */
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);
321 /* equal sign */
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);
329 return G_TOKEN_NONE;
332 static guint
333 clearlooks_rc_style_parse (GtkRcStyle *rc_style,
334 GtkSettings *settings,
335 GScanner *scanner)
338 static GQuark scope_id = 0;
339 ClearlooksRcStyle *clearlooks_style = CLEARLOOKS_RC_STYLE (rc_style);
341 guint old_scope;
342 guint token;
343 guint i;
345 /* Set up a new scope in this scanner. */
347 if (!scope_id)
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
357 * same scanner.
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)
373 switch (token)
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;
378 break;
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;
382 break;
383 case TOKEN_CONTRAST:
384 token = clearlooks_gtk2_rc_parse_double (settings, scanner, &clearlooks_style->contrast);
385 clearlooks_style->flags |= CL_FLAG_CONTRAST;
386 break;
387 case TOKEN_MENUBARSTYLE:
388 token = clearlooks_gtk2_rc_parse_int (settings, scanner, &clearlooks_style->menubarstyle);
389 clearlooks_style->flags |= CL_FLAG_MENUBARSTYLE;
390 break;
391 case TOKEN_TOOLBARSTYLE:
392 token = clearlooks_gtk2_rc_parse_int (settings, scanner, &clearlooks_style->toolbarstyle);
393 clearlooks_style->flags |= CL_FLAG_TOOLBARSTYLE;
394 break;
395 case TOKEN_ANIMATION:
396 token = clearlooks_gtk2_rc_parse_boolean (settings, scanner, &clearlooks_style->animation);
397 clearlooks_style->flags |= CL_FLAG_ANIMATION;
398 break;
399 case TOKEN_STYLE:
400 token = clearlooks_gtk2_rc_parse_style (settings, scanner, &clearlooks_style->style);
401 clearlooks_style->flags |= CL_FLAG_STYLE;
402 break;
403 case TOKEN_RADIUS:
404 token = clearlooks_gtk2_rc_parse_double (settings, scanner, &clearlooks_style->radius);
405 clearlooks_style->flags |= CL_FLAG_RADIUS;
406 break;
408 /* stuff to ignore */
409 case TOKEN_SUNKENMENU:
410 token = clearlooks_gtk2_rc_parse_dummy (settings, scanner, "sunkenmenu");
411 break;
412 case TOKEN_PROGRESSBARSTYLE:
413 token = clearlooks_gtk2_rc_parse_dummy (settings, scanner, "progressbarstyle");
414 break;
415 case TOKEN_MENUITEMSTYLE:
416 token = clearlooks_gtk2_rc_parse_dummy (settings, scanner, "menuitemstyle");
417 break;
418 case TOKEN_LISTVIEWITEMSTYLE:
419 token = clearlooks_gtk2_rc_parse_dummy (settings, scanner, "listviewitemstyle");
420 break;
422 default:
423 g_scanner_get_next_token(scanner);
424 token = G_TOKEN_RIGHT_CURLY;
425 break;
428 if (token != G_TOKEN_NONE)
429 return token;
431 token = g_scanner_peek_next_token(scanner);
434 g_scanner_get_next_token(scanner);
436 g_scanner_set_scope(scanner, old_scope);
438 return G_TOKEN_NONE;
441 static void
442 clearlooks_rc_style_merge (GtkRcStyle *dest,
443 GtkRcStyle *src)
445 ClearlooksRcStyle *dest_w, *src_w;
446 ClearlooksRcFlags flags;
448 clearlooks_parent_rc_class->merge (dest, src);
450 if (!CLEARLOOKS_IS_RC_STYLE (src))
451 return;
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
481 static GtkStyle *
482 clearlooks_rc_style_create_style (GtkRcStyle *rc_style)
484 (void) rc_style;
486 return GTK_STYLE (g_object_new (CLEARLOOKS_TYPE_STYLE, NULL));