1 | #include "thinice_rc_style.h" |
---|
2 | #include "thinice_style.h" |
---|
3 | |
---|
4 | static void thinice_rc_style_init (ThiniceRcStyle *style); |
---|
5 | static void thinice_rc_style_class_init (ThiniceRcStyleClass *klass); |
---|
6 | static void thinice_rc_style_finalize (GObject *object); |
---|
7 | static guint thinice_rc_style_parse (GtkRcStyle *rc_style, |
---|
8 | GtkSettings *settings, |
---|
9 | GScanner *scanner); |
---|
10 | static void thinice_rc_style_merge (GtkRcStyle *dest, |
---|
11 | GtkRcStyle *src); |
---|
12 | |
---|
13 | static GtkStyle *thinice_rc_style_create_style (GtkRcStyle *rc_style); |
---|
14 | |
---|
15 | |
---|
16 | static struct |
---|
17 | { |
---|
18 | gchar *name; |
---|
19 | guint token; |
---|
20 | } |
---|
21 | theme_symbols[] = |
---|
22 | { |
---|
23 | { "rect_scrollbar", TOKEN_RECTSCROLLBAR }, |
---|
24 | { "scrollbar_marks", TOKEN_SCROLLBARMARKS }, |
---|
25 | { "scroll_button_marks", TOKEN_SCROLLBUTTONMARKS }, |
---|
26 | { "handlebox_marks", TOKEN_HANDLEBOXMARKS }, |
---|
27 | { "mark_type1", TOKEN_MARKTYPE1 }, |
---|
28 | { "mark_type2", TOKEN_MARKTYPE2 }, |
---|
29 | { "paned_dots", TOKEN_PANEDDOTS }, |
---|
30 | |
---|
31 | { "TRUE", TOKEN_TRUE }, |
---|
32 | { "FALSE", TOKEN_FALSE }, |
---|
33 | |
---|
34 | { "NOTHING", TOKEN_NOTHING }, |
---|
35 | { "SLASH", TOKEN_SLASH }, |
---|
36 | { "INVSLASH", TOKEN_INVSLASH }, |
---|
37 | { "DOT", TOKEN_DOT }, |
---|
38 | { "INVDOT", TOKEN_INVDOT }, |
---|
39 | { "ARROW", TOKEN_ARROW }, |
---|
40 | |
---|
41 | { "FULL", TOKEN_FULL }, |
---|
42 | { "SOME", TOKEN_SOME }, |
---|
43 | { "NONE", TOKEN_NONE }, |
---|
44 | |
---|
45 | }; |
---|
46 | |
---|
47 | static guint n_theme_symbols = sizeof(theme_symbols) / sizeof(theme_symbols[0]); |
---|
48 | |
---|
49 | static GtkRcStyleClass *parent_class; |
---|
50 | |
---|
51 | GType thinice_type_rc_style = 0; |
---|
52 | |
---|
53 | void |
---|
54 | thinice_rc_style_register_type (GTypeModule *module) |
---|
55 | { |
---|
56 | static const GTypeInfo object_info = |
---|
57 | { |
---|
58 | sizeof (ThiniceRcStyleClass), |
---|
59 | (GBaseInitFunc) NULL, |
---|
60 | (GBaseFinalizeFunc) NULL, |
---|
61 | (GClassInitFunc) thinice_rc_style_class_init, |
---|
62 | NULL, /* class_finalize */ |
---|
63 | NULL, /* class_data */ |
---|
64 | sizeof (ThiniceRcStyle), |
---|
65 | 0, /* n_preallocs */ |
---|
66 | (GInstanceInitFunc) thinice_rc_style_init, |
---|
67 | }; |
---|
68 | |
---|
69 | thinice_type_rc_style = g_type_module_register_type (module, |
---|
70 | GTK_TYPE_RC_STYLE, |
---|
71 | "ThiniceRcStyle", |
---|
72 | &object_info, 0); |
---|
73 | } |
---|
74 | |
---|
75 | static void |
---|
76 | thinice_rc_style_init (ThiniceRcStyle *style) |
---|
77 | { |
---|
78 | } |
---|
79 | |
---|
80 | static void |
---|
81 | thinice_rc_style_class_init (ThiniceRcStyleClass *klass) |
---|
82 | { |
---|
83 | GtkRcStyleClass *rc_style_class = GTK_RC_STYLE_CLASS (klass); |
---|
84 | GObjectClass *object_class = G_OBJECT_CLASS (klass); |
---|
85 | |
---|
86 | parent_class = g_type_class_peek_parent (klass); |
---|
87 | |
---|
88 | rc_style_class->parse = thinice_rc_style_parse; |
---|
89 | rc_style_class->merge = thinice_rc_style_merge; |
---|
90 | rc_style_class->create_style = thinice_rc_style_create_style; |
---|
91 | } |
---|
92 | |
---|
93 | #if 0 |
---|
94 | static guint |
---|
95 | theme_parse_int(GScanner *scanner, |
---|
96 | GTokenType wanted_token, |
---|
97 | guint *retval) |
---|
98 | { |
---|
99 | guint token; |
---|
100 | |
---|
101 | token = g_scanner_get_next_token(scanner); |
---|
102 | if (token != wanted_token) |
---|
103 | return wanted_token; |
---|
104 | |
---|
105 | token = g_scanner_get_next_token(scanner); |
---|
106 | if (token != G_TOKEN_EQUAL_SIGN) |
---|
107 | return wanted_token; |
---|
108 | |
---|
109 | token = g_scanner_get_next_token(scanner); |
---|
110 | if (token != G_TOKEN_INT) |
---|
111 | return G_TOKEN_INT; |
---|
112 | |
---|
113 | *retval = g_scanner_cur_value(scanner).v_int; |
---|
114 | |
---|
115 | return G_TOKEN_NONE; |
---|
116 | } |
---|
117 | #endif |
---|
118 | |
---|
119 | static guint |
---|
120 | theme_parse_boolean(GScanner *scanner, |
---|
121 | GTokenType wanted_token, |
---|
122 | guint *retval) |
---|
123 | { |
---|
124 | guint token; |
---|
125 | |
---|
126 | token = g_scanner_get_next_token(scanner); |
---|
127 | if (token != wanted_token) |
---|
128 | return wanted_token; |
---|
129 | |
---|
130 | token = g_scanner_get_next_token(scanner); |
---|
131 | if (token != G_TOKEN_EQUAL_SIGN) |
---|
132 | return G_TOKEN_EQUAL_SIGN; |
---|
133 | |
---|
134 | token = g_scanner_get_next_token(scanner); |
---|
135 | if (token == TOKEN_TRUE) |
---|
136 | *retval = TRUE; |
---|
137 | else if (token == TOKEN_FALSE) |
---|
138 | *retval = FALSE; |
---|
139 | else |
---|
140 | return TOKEN_TRUE; |
---|
141 | |
---|
142 | return G_TOKEN_NONE; |
---|
143 | } |
---|
144 | |
---|
145 | static guint |
---|
146 | theme_parse_marktype(GScanner *scanner, |
---|
147 | GTokenType wanted_token, |
---|
148 | guint *retval) |
---|
149 | { |
---|
150 | guint token; |
---|
151 | |
---|
152 | token = g_scanner_get_next_token(scanner); |
---|
153 | if (token != wanted_token) |
---|
154 | return wanted_token; |
---|
155 | |
---|
156 | token = g_scanner_get_next_token(scanner); |
---|
157 | if (token != G_TOKEN_EQUAL_SIGN) |
---|
158 | return G_TOKEN_EQUAL_SIGN; |
---|
159 | |
---|
160 | token = g_scanner_get_next_token(scanner); |
---|
161 | switch (token) |
---|
162 | { |
---|
163 | case TOKEN_NOTHING: |
---|
164 | *retval = MARKS_NOTHING; |
---|
165 | break; |
---|
166 | case TOKEN_SLASH: |
---|
167 | *retval = MARKS_SLASH; |
---|
168 | break; |
---|
169 | case TOKEN_INVSLASH: |
---|
170 | *retval = MARKS_INVSLASH; |
---|
171 | break; |
---|
172 | case TOKEN_DOT: |
---|
173 | *retval = MARKS_DOT; |
---|
174 | break; |
---|
175 | case TOKEN_INVDOT: |
---|
176 | *retval = MARKS_INVDOT; |
---|
177 | break; |
---|
178 | case TOKEN_ARROW: |
---|
179 | *retval = MARKS_ARROW; |
---|
180 | break; |
---|
181 | default: |
---|
182 | return TOKEN_NOTHING; |
---|
183 | } |
---|
184 | |
---|
185 | return G_TOKEN_NONE; |
---|
186 | } |
---|
187 | |
---|
188 | static guint |
---|
189 | theme_parse_paned(GScanner *scanner, |
---|
190 | GTokenType wanted_token, |
---|
191 | guint *retval) |
---|
192 | { |
---|
193 | guint token; |
---|
194 | |
---|
195 | token = g_scanner_get_next_token(scanner); |
---|
196 | if (token != wanted_token) |
---|
197 | return wanted_token; |
---|
198 | |
---|
199 | token = g_scanner_get_next_token(scanner); |
---|
200 | if (token != G_TOKEN_EQUAL_SIGN) |
---|
201 | return G_TOKEN_EQUAL_SIGN; |
---|
202 | |
---|
203 | token = g_scanner_get_next_token(scanner); |
---|
204 | switch (token) |
---|
205 | { |
---|
206 | case TOKEN_NONE: |
---|
207 | *retval = PANED_DOTSNONE; |
---|
208 | break; |
---|
209 | case TOKEN_SOME: |
---|
210 | *retval = PANED_DOTSSOME; |
---|
211 | break; |
---|
212 | case TOKEN_FULL: |
---|
213 | *retval = PANED_DOTSFULL; |
---|
214 | break; |
---|
215 | default: |
---|
216 | return TOKEN_NOTHING; |
---|
217 | } |
---|
218 | |
---|
219 | return G_TOKEN_NONE; |
---|
220 | } |
---|
221 | |
---|
222 | static guint |
---|
223 | thinice_rc_style_parse (GtkRcStyle *rc_style, |
---|
224 | GtkSettings *settings, |
---|
225 | GScanner *scanner) |
---|
226 | { |
---|
227 | static GQuark scope_id = 0; |
---|
228 | ThiniceRcStyle *theme_data = THINICE_RC_STYLE (rc_style); |
---|
229 | guint old_scope; |
---|
230 | guint token; |
---|
231 | guint i; |
---|
232 | |
---|
233 | /* Set up a new scope in this scanner. */ |
---|
234 | |
---|
235 | /* |
---|
236 | g_print("theme_parse_rc_style(\"%s\")\n", rc_style->name); |
---|
237 | */ |
---|
238 | if (!scope_id) |
---|
239 | scope_id = g_quark_from_string("theme_engine"); |
---|
240 | |
---|
241 | /* If we bail out due to errors, we *don't* reset the scope, so the |
---|
242 | * error messaging code can make sense of our tokens. |
---|
243 | */ |
---|
244 | old_scope = g_scanner_set_scope(scanner, scope_id); |
---|
245 | |
---|
246 | /* Now check if we already added our symbols to this scope |
---|
247 | * (in some previous call to theme_parse_rc_style for the |
---|
248 | * same scanner. |
---|
249 | */ |
---|
250 | |
---|
251 | if (!g_scanner_lookup_symbol(scanner, theme_symbols[0].name)) |
---|
252 | { |
---|
253 | g_scanner_freeze_symbol_table(scanner); |
---|
254 | for (i = 0; i < n_theme_symbols; i++) |
---|
255 | { |
---|
256 | g_scanner_scope_add_symbol(scanner, scope_id, |
---|
257 | theme_symbols[i].name, |
---|
258 | GINT_TO_POINTER(theme_symbols[i].token)); |
---|
259 | } |
---|
260 | g_scanner_thaw_symbol_table(scanner); |
---|
261 | } |
---|
262 | |
---|
263 | /* We're ready to go, now parse the top level */ |
---|
264 | |
---|
265 | /* theme_data = g_new0(ThiniceRcStyle, 1); */ |
---|
266 | theme_data->scrollbar_type = DEFAULT_SCROLLSHAPE; |
---|
267 | theme_data->scrollbar_marks = DEFAULT_SCROLLBARMARKS; |
---|
268 | theme_data->scroll_button_marks = DEFAULT_SCROLLBUTTONMARKS; |
---|
269 | theme_data->handlebox_marks = DEFAULT_HANDLEBOXMARKS; |
---|
270 | theme_data->mark_type1 = DEFAULT_MARKTYPE1; |
---|
271 | theme_data->mark_type2 = DEFAULT_MARKTYPE2; |
---|
272 | |
---|
273 | token = g_scanner_peek_next_token(scanner); |
---|
274 | while (token != G_TOKEN_RIGHT_CURLY) |
---|
275 | { |
---|
276 | switch (token) |
---|
277 | { |
---|
278 | case TOKEN_RECTSCROLLBAR: |
---|
279 | token = theme_parse_boolean(scanner, TOKEN_RECTSCROLLBAR, &i); |
---|
280 | if (token != G_TOKEN_NONE) |
---|
281 | break; |
---|
282 | if (i == FALSE) |
---|
283 | theme_data->scrollbar_type = SCROLL_SHAPED; |
---|
284 | else |
---|
285 | theme_data->scrollbar_type = SCROLL_RECT; |
---|
286 | break; |
---|
287 | |
---|
288 | case TOKEN_SCROLLBUTTONMARKS: |
---|
289 | token = theme_parse_boolean(scanner, TOKEN_SCROLLBUTTONMARKS, &i); |
---|
290 | if (token != G_TOKEN_NONE) |
---|
291 | break; |
---|
292 | if (i == TRUE) |
---|
293 | theme_data->mark_type2 = MARKS_SLASH; |
---|
294 | else |
---|
295 | theme_data->mark_type2 = MARKS_NOTHING; |
---|
296 | /* |
---|
297 | if (i == TRUE) |
---|
298 | theme_data->scroll_button_marks = MARKS_ON; |
---|
299 | else |
---|
300 | theme_data->scroll_button_marks = MARKS_OFF; |
---|
301 | */ |
---|
302 | break; |
---|
303 | |
---|
304 | case TOKEN_SCROLLBARMARKS: |
---|
305 | token = theme_parse_boolean(scanner, TOKEN_SCROLLBARMARKS, &i); |
---|
306 | if (token != G_TOKEN_NONE) |
---|
307 | break; |
---|
308 | if (i == TRUE) |
---|
309 | theme_data->mark_type1 = MARKS_SLASH; |
---|
310 | else |
---|
311 | theme_data->mark_type1 = MARKS_NOTHING; |
---|
312 | /* |
---|
313 | if (i == TRUE) |
---|
314 | theme_data->scrollbar_marks = MARKS_ON; |
---|
315 | else |
---|
316 | theme_data->scrollbar_marks = MARKS_OFF; |
---|
317 | */ |
---|
318 | break; |
---|
319 | |
---|
320 | case TOKEN_HANDLEBOXMARKS: |
---|
321 | token = theme_parse_boolean(scanner, TOKEN_HANDLEBOXMARKS, &i); |
---|
322 | if (token != G_TOKEN_NONE) |
---|
323 | break; |
---|
324 | if (i == TRUE) |
---|
325 | theme_data->handlebox_marks = MARKS_ON; |
---|
326 | else |
---|
327 | theme_data->handlebox_marks = MARKS_OFF; |
---|
328 | break; |
---|
329 | |
---|
330 | case TOKEN_MARKTYPE1: |
---|
331 | token = theme_parse_marktype(scanner, TOKEN_MARKTYPE1, &i); |
---|
332 | if (token != G_TOKEN_NONE) |
---|
333 | break; |
---|
334 | theme_data->mark_type1 = i; |
---|
335 | break; |
---|
336 | |
---|
337 | case TOKEN_MARKTYPE2: |
---|
338 | token = theme_parse_marktype(scanner, TOKEN_MARKTYPE2, &i); |
---|
339 | if (token != G_TOKEN_NONE) |
---|
340 | break; |
---|
341 | theme_data->mark_type2 = i; |
---|
342 | break; |
---|
343 | |
---|
344 | case TOKEN_PANEDDOTS: |
---|
345 | token = theme_parse_paned(scanner, TOKEN_PANEDDOTS, &i); |
---|
346 | if (token != G_TOKEN_NONE) |
---|
347 | break; |
---|
348 | theme_data->paned_dots = i; |
---|
349 | break; |
---|
350 | |
---|
351 | default: |
---|
352 | g_scanner_get_next_token(scanner); |
---|
353 | token = G_TOKEN_RIGHT_CURLY; |
---|
354 | break; |
---|
355 | } |
---|
356 | |
---|
357 | if (token != G_TOKEN_NONE) |
---|
358 | { |
---|
359 | g_free(theme_data); |
---|
360 | return token; |
---|
361 | } |
---|
362 | token = g_scanner_peek_next_token(scanner); |
---|
363 | } |
---|
364 | |
---|
365 | g_scanner_get_next_token(scanner); |
---|
366 | |
---|
367 | g_scanner_set_scope(scanner, old_scope); |
---|
368 | |
---|
369 | return G_TOKEN_NONE; |
---|
370 | } |
---|
371 | |
---|
372 | static void |
---|
373 | thinice_rc_style_merge (GtkRcStyle * dest, |
---|
374 | GtkRcStyle * src) |
---|
375 | { |
---|
376 | if (THINICE_IS_RC_STYLE (src)) { |
---|
377 | ThiniceRcStyle *src_data = THINICE_RC_STYLE (src); |
---|
378 | ThiniceRcStyle *dest_data = THINICE_RC_STYLE (dest); |
---|
379 | |
---|
380 | /* |
---|
381 | g_print("theme_merge_rc_style(\"%s\", \"%s\")\n", dest->name, src->name); |
---|
382 | */ |
---|
383 | |
---|
384 | dest_data->scrollbar_type = src_data->scrollbar_type; |
---|
385 | dest_data->scrollbar_marks = src_data->scrollbar_marks; |
---|
386 | dest_data->scroll_button_marks = src_data->scroll_button_marks; |
---|
387 | dest_data->handlebox_marks = src_data->handlebox_marks; |
---|
388 | dest_data->mark_type1 = src_data->mark_type1; |
---|
389 | dest_data->mark_type2 = src_data->mark_type2; |
---|
390 | dest_data->paned_dots = src_data->paned_dots; |
---|
391 | } |
---|
392 | |
---|
393 | parent_class->merge (dest, src); |
---|
394 | } |
---|
395 | |
---|
396 | /* Create an empty style suitable to this RC style |
---|
397 | */ |
---|
398 | static GtkStyle * |
---|
399 | thinice_rc_style_create_style (GtkRcStyle *rc_style) |
---|
400 | { |
---|
401 | void *ptr; |
---|
402 | ptr = GTK_STYLE (g_object_new (THINICE_TYPE_STYLE, NULL)); |
---|
403 | return (GtkStyle *)ptr; |
---|
404 | } |
---|