| 1 |
/* GTK+ Pixbuf Engine |
| 2 |
* Copyright (C) 1998-2000 Red Hat, Inc. |
| 3 |
* |
| 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. |
| 8 |
* |
| 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. |
| 13 |
* |
| 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. |
| 18 |
* |
| 19 |
* Written by Owen Taylor <[email protected]>, based on code by |
| 20 |
* Carsten Haitzler <[email protected]> |
| 21 |
*/ |
| 22 |
|
| 23 |
#include "pixbuf.h" |
| 24 |
#include "pixbuf-style.h" |
| 25 |
#include "pixbuf-rc-style.h" |
| 26 |
|
| 27 |
static void pixbuf_rc_style_init (PixbufRcStyle *style); |
| 28 |
static void pixbuf_rc_style_class_init (PixbufRcStyleClass *klass); |
| 29 |
static void pixbuf_rc_style_finalize (GObject *object); |
| 30 |
static guint pixbuf_rc_style_parse (GtkRcStyle *rc_style, |
| 31 |
GtkSettings *settings, |
| 32 |
GScanner *scanner); |
| 33 |
static void pixbuf_rc_style_merge (GtkRcStyle *dest, |
| 34 |
GtkRcStyle *src); |
| 35 |
static GtkStyle *pixbuf_rc_style_create_style (GtkRcStyle *rc_style); |
| 36 |
|
| 37 |
static void theme_image_unref (ThemeImage *data); |
| 38 |
|
| 39 |
static const struct |
| 40 |
{ |
| 41 |
gchar *name; |
| 42 |
guint token; |
| 43 |
} |
| 44 |
theme_symbols[] = |
| 45 |
{ |
| 46 |
{ "image", TOKEN_IMAGE }, |
| 47 |
{ "function", TOKEN_FUNCTION }, |
| 48 |
{ "file", TOKEN_FILE }, |
| 49 |
{ "stretch", TOKEN_STRETCH }, |
| 50 |
{ "recolorable", TOKEN_RECOLORABLE }, |
| 51 |
{ "border", TOKEN_BORDER }, |
| 52 |
{ "detail", TOKEN_DETAIL }, |
| 53 |
{ "state", TOKEN_STATE }, |
| 54 |
{ "shadow", TOKEN_SHADOW }, |
| 55 |
{ "gap_side", TOKEN_GAP_SIDE }, |
| 56 |
{ "gap_file", TOKEN_GAP_FILE }, |
| 57 |
{ "gap_border", TOKEN_GAP_BORDER }, |
| 58 |
{ "gap_start_file", TOKEN_GAP_START_FILE }, |
| 59 |
{ "gap_start_border", TOKEN_GAP_START_BORDER }, |
| 60 |
{ "gap_end_file", TOKEN_GAP_END_FILE }, |
| 61 |
{ "gap_end_border", TOKEN_GAP_END_BORDER }, |
| 62 |
{ "overlay_file", TOKEN_OVERLAY_FILE }, |
| 63 |
{ "overlay_border", TOKEN_OVERLAY_BORDER }, |
| 64 |
{ "overlay_stretch", TOKEN_OVERLAY_STRETCH }, |
| 65 |
{ "arrow_direction", TOKEN_ARROW_DIRECTION }, |
| 66 |
{ "orientation", TOKEN_ORIENTATION }, |
| 67 |
{ "direction", TOKEN_DIRECTION }, |
| 68 |
{ "expander_style", TOKEN_EXPANDER_STYLE }, |
| 69 |
{ "window_edge", TOKEN_WINDOW_EDGE }, |
| 70 |
|
| 71 |
{ "HLINE", TOKEN_D_HLINE }, |
| 72 |
{ "VLINE", TOKEN_D_VLINE }, |
| 73 |
{ "SHADOW", TOKEN_D_SHADOW }, |
| 74 |
{ "POLYGON", TOKEN_D_POLYGON }, |
| 75 |
{ "ARROW", TOKEN_D_ARROW }, |
| 76 |
{ "DIAMOND", TOKEN_D_DIAMOND }, |
| 77 |
{ "OVAL", TOKEN_D_OVAL }, |
| 78 |
{ "STRING", TOKEN_D_STRING }, |
| 79 |
{ "BOX", TOKEN_D_BOX }, |
| 80 |
{ "FLAT_BOX", TOKEN_D_FLAT_BOX }, |
| 81 |
{ "CHECK", TOKEN_D_CHECK }, |
| 82 |
{ "OPTION", TOKEN_D_OPTION }, |
| 83 |
{ "CROSS", TOKEN_D_CROSS }, |
| 84 |
{ "RAMP", TOKEN_D_RAMP }, |
| 85 |
{ "TAB", TOKEN_D_TAB }, |
| 86 |
{ "SHADOW_GAP", TOKEN_D_SHADOW_GAP }, |
| 87 |
{ "BOX_GAP", TOKEN_D_BOX_GAP }, |
| 88 |
{ "EXTENSION", TOKEN_D_EXTENSION }, |
| 89 |
{ "FOCUS", TOKEN_D_FOCUS }, |
| 90 |
{ "SLIDER", TOKEN_D_SLIDER }, |
| 91 |
{ "ENTRY", TOKEN_D_ENTRY }, |
| 92 |
{ "HANDLE", TOKEN_D_HANDLE }, |
| 93 |
{ "STEPPER", TOKEN_D_STEPPER }, |
| 94 |
{ "EXPANDER", TOKEN_D_EXPANDER }, |
| 95 |
{ "RESIZE_GRIP", TOKEN_D_RESIZE_GRIP }, |
| 96 |
|
| 97 |
{ "TRUE", TOKEN_TRUE }, |
| 98 |
{ "FALSE", TOKEN_FALSE }, |
| 99 |
|
| 100 |
{ "TOP", TOKEN_TOP }, |
| 101 |
{ "UP", TOKEN_UP }, |
| 102 |
{ "BOTTOM", TOKEN_BOTTOM }, |
| 103 |
{ "DOWN", TOKEN_DOWN }, |
| 104 |
{ "LEFT", TOKEN_LEFT }, |
| 105 |
{ "RIGHT", TOKEN_RIGHT }, |
| 106 |
|
| 107 |
{ "NORMAL", TOKEN_NORMAL }, |
| 108 |
{ "ACTIVE", TOKEN_ACTIVE }, |
| 109 |
{ "PRELIGHT", TOKEN_PRELIGHT }, |
| 110 |
{ "SELECTED", TOKEN_SELECTED }, |
| 111 |
{ "INSENSITIVE", TOKEN_INSENSITIVE }, |
| 112 |
|
| 113 |
{ "NONE", TOKEN_NONE }, |
| 114 |
{ "IN", TOKEN_IN }, |
| 115 |
{ "OUT", TOKEN_OUT }, |
| 116 |
{ "ETCHED_IN", TOKEN_ETCHED_IN }, |
| 117 |
{ "ETCHED_OUT", TOKEN_ETCHED_OUT }, |
| 118 |
|
| 119 |
{ "HORIZONTAL", TOKEN_HORIZONTAL }, |
| 120 |
{ "VERTICAL", TOKEN_VERTICAL }, |
| 121 |
|
| 122 |
{ "COLLAPSED", TOKEN_COLLAPSED }, |
| 123 |
{ "SEMI_COLLAPSED", TOKEN_SEMI_COLLAPSED }, |
| 124 |
{ "SEMI_EXPANDED", TOKEN_SEMI_EXPANDED }, |
| 125 |
{ "EXPANDED", TOKEN_EXPANDED }, |
| 126 |
|
| 127 |
{ "NORTH_WEST", TOKEN_NORTH_WEST }, |
| 128 |
{ "NORTH", TOKEN_NORTH }, |
| 129 |
{ "NORTH_EAST", TOKEN_NORTH_EAST }, |
| 130 |
{ "WEST", TOKEN_WEST }, |
| 131 |
{ "EAST", TOKEN_EAST }, |
| 132 |
{ "SOUTH_WEST", TOKEN_SOUTH_WEST }, |
| 133 |
{ "SOUTH", TOKEN_SOUTH }, |
| 134 |
{ "SOUTH_EAST", TOKEN_SOUTH_EAST }, |
| 135 |
|
| 136 |
{ "LTR", TOKEN_LTR }, |
| 137 |
{ "RTL", TOKEN_RTL } |
| 138 |
}; |
| 139 |
|
| 140 |
static GtkRcStyleClass *parent_class; |
| 141 |
|
| 142 |
GType pixbuf_type_rc_style = 0; |
| 143 |
|
| 144 |
void |
| 145 |
pixbuf_rc_style_register_type (GTypeModule *module) |
| 146 |
{ |
| 147 |
const GTypeInfo object_info = |
| 148 |
{ |
| 149 |
sizeof (PixbufRcStyleClass), |
| 150 |
(GBaseInitFunc) NULL, |
| 151 |
(GBaseFinalizeFunc) NULL, |
| 152 |
(GClassInitFunc) pixbuf_rc_style_class_init, |
| 153 |
NULL, /* class_finalize */ |
| 154 |
NULL, /* class_data */ |
| 155 |
sizeof (PixbufRcStyle), |
| 156 |
0, /* n_preallocs */ |
| 157 |
(GInstanceInitFunc) pixbuf_rc_style_init, |
| 158 |
}; |
| 159 |
|
| 160 |
pixbuf_type_rc_style = g_type_module_register_type (module, |
| 161 |
GTK_TYPE_RC_STYLE, |
| 162 |
"PixbufRcStyle", |
| 163 |
&object_info, 0); |
| 164 |
} |
| 165 |
|
| 166 |
static void |
| 167 |
pixbuf_rc_style_init (PixbufRcStyle *style) |
| 168 |
{ |
| 169 |
} |
| 170 |
|
| 171 |
static void |
| 172 |
pixbuf_rc_style_class_init (PixbufRcStyleClass *klass) |
| 173 |
{ |
| 174 |
GtkRcStyleClass *rc_style_class = GTK_RC_STYLE_CLASS (klass); |
| 175 |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
| 176 |
|
| 177 |
parent_class = g_type_class_peek_parent (klass); |
| 178 |
|
| 179 |
rc_style_class->parse = pixbuf_rc_style_parse; |
| 180 |
rc_style_class->merge = pixbuf_rc_style_merge; |
| 181 |
rc_style_class->create_style = pixbuf_rc_style_create_style; |
| 182 |
|
| 183 |
object_class->finalize = pixbuf_rc_style_finalize; |
| 184 |
} |
| 185 |
|
| 186 |
static void |
| 187 |
pixbuf_rc_style_finalize (GObject *object) |
| 188 |
{ |
| 189 |
PixbufRcStyle *rc_style = PIXBUF_RC_STYLE (object); |
| 190 |
|
| 191 |
g_list_foreach (rc_style->img_list, (GFunc) theme_image_unref, NULL); |
| 192 |
g_list_free (rc_style->img_list); |
| 193 |
|
| 194 |
G_OBJECT_CLASS (parent_class)->finalize (object); |
| 195 |
} |
| 196 |
|
| 197 |
static guint |
| 198 |
theme_parse_file(GtkSettings *settings, |
| 199 |
GScanner *scanner, |
| 200 |
ThemePixbuf **theme_pb) |
| 201 |
{ |
| 202 |
guint token; |
| 203 |
gchar *pixmap; |
| 204 |
|
| 205 |
/* Skip 'blah_file' */ |
| 206 |
token = g_scanner_get_next_token(scanner); |
| 207 |
|
| 208 |
token = g_scanner_get_next_token(scanner); |
| 209 |
if (token != G_TOKEN_EQUAL_SIGN) |
| 210 |
return G_TOKEN_EQUAL_SIGN; |
| 211 |
|
| 212 |
token = g_scanner_get_next_token(scanner); |
| 213 |
if (token != G_TOKEN_STRING) |
| 214 |
return G_TOKEN_STRING; |
| 215 |
|
| 216 |
if (!*theme_pb) |
| 217 |
*theme_pb = theme_pixbuf_new (); |
| 218 |
|
| 219 |
pixmap = gtk_rc_find_pixmap_in_path(settings, scanner, scanner->value.v_string); |
| 220 |
if (pixmap) |
| 221 |
{ |
| 222 |
theme_pixbuf_set_filename (*theme_pb, pixmap); |
| 223 |
g_free (pixmap); |
| 224 |
} |
| 225 |
|
| 226 |
return G_TOKEN_NONE; |
| 227 |
} |
| 228 |
|
| 229 |
static guint |
| 230 |
theme_parse_border (GScanner *scanner, |
| 231 |
ThemePixbuf **theme_pb) |
| 232 |
{ |
| 233 |
guint token; |
| 234 |
gint left, right, top, bottom; |
| 235 |
|
| 236 |
/* Skip 'blah_border' */ |
| 237 |
token = g_scanner_get_next_token(scanner); |
| 238 |
|
| 239 |
token = g_scanner_get_next_token(scanner); |
| 240 |
if (token != G_TOKEN_EQUAL_SIGN) |
| 241 |
return G_TOKEN_EQUAL_SIGN; |
| 242 |
|
| 243 |
token = g_scanner_get_next_token(scanner); |
| 244 |
if (token != G_TOKEN_LEFT_CURLY) |
| 245 |
return G_TOKEN_LEFT_CURLY; |
| 246 |
|
| 247 |
token = g_scanner_get_next_token(scanner); |
| 248 |
if (token != G_TOKEN_INT) |
| 249 |
return G_TOKEN_INT; |
| 250 |
left = scanner->value.v_int; |
| 251 |
token = g_scanner_get_next_token(scanner); |
| 252 |
if (token != G_TOKEN_COMMA) |
| 253 |
return G_TOKEN_COMMA; |
| 254 |
|
| 255 |
token = g_scanner_get_next_token(scanner); |
| 256 |
if (token != G_TOKEN_INT) |
| 257 |
return G_TOKEN_INT; |
| 258 |
right = scanner->value.v_int; |
| 259 |
token = g_scanner_get_next_token(scanner); |
| 260 |
if (token != G_TOKEN_COMMA) |
| 261 |
return G_TOKEN_COMMA; |
| 262 |
|
| 263 |
token = g_scanner_get_next_token(scanner); |
| 264 |
if (token != G_TOKEN_INT) |
| 265 |
return G_TOKEN_INT; |
| 266 |
top = scanner->value.v_int; |
| 267 |
token = g_scanner_get_next_token(scanner); |
| 268 |
if (token != G_TOKEN_COMMA) |
| 269 |
return G_TOKEN_COMMA; |
| 270 |
|
| 271 |
token = g_scanner_get_next_token(scanner); |
| 272 |
if (token != G_TOKEN_INT) |
| 273 |
return G_TOKEN_INT; |
| 274 |
bottom = scanner->value.v_int; |
| 275 |
|
| 276 |
token = g_scanner_get_next_token(scanner); |
| 277 |
if (token != G_TOKEN_RIGHT_CURLY) |
| 278 |
return G_TOKEN_RIGHT_CURLY; |
| 279 |
|
| 280 |
if (!*theme_pb) |
| 281 |
*theme_pb = theme_pixbuf_new (); |
| 282 |
|
| 283 |
theme_pixbuf_set_border (*theme_pb, left, right, top, bottom); |
| 284 |
|
| 285 |
return G_TOKEN_NONE; |
| 286 |
} |
| 287 |
|
| 288 |
static guint |
| 289 |
theme_parse_stretch(GScanner *scanner, |
| 290 |
ThemePixbuf **theme_pb) |
| 291 |
{ |
| 292 |
guint token; |
| 293 |
gboolean stretch; |
| 294 |
|
| 295 |
/* Skip 'blah_stretch' */ |
| 296 |
token = g_scanner_get_next_token(scanner); |
| 297 |
|
| 298 |
token = g_scanner_get_next_token(scanner); |
| 299 |
if (token != G_TOKEN_EQUAL_SIGN) |
| 300 |
return G_TOKEN_EQUAL_SIGN; |
| 301 |
|
| 302 |
token = g_scanner_get_next_token(scanner); |
| 303 |
if (token == TOKEN_TRUE) |
| 304 |
stretch = TRUE; |
| 305 |
else if (token == TOKEN_FALSE) |
| 306 |
stretch = FALSE; |
| 307 |
else |
| 308 |
return TOKEN_TRUE; |
| 309 |
|
| 310 |
if (!*theme_pb) |
| 311 |
*theme_pb = theme_pixbuf_new (); |
| 312 |
|
| 313 |
theme_pixbuf_set_stretch (*theme_pb, stretch); |
| 314 |
|
| 315 |
return G_TOKEN_NONE; |
| 316 |
} |
| 317 |
|
| 318 |
static guint |
| 319 |
theme_parse_recolorable(GScanner * scanner, |
| 320 |
ThemeImage * data) |
| 321 |
{ |
| 322 |
guint token; |
| 323 |
|
| 324 |
token = g_scanner_get_next_token(scanner); |
| 325 |
if (token != TOKEN_RECOLORABLE) |
| 326 |
return TOKEN_RECOLORABLE; |
| 327 |
|
| 328 |
token = g_scanner_get_next_token(scanner); |
| 329 |
if (token != G_TOKEN_EQUAL_SIGN) |
| 330 |
return G_TOKEN_EQUAL_SIGN; |
| 331 |
|
| 332 |
token = g_scanner_get_next_token(scanner); |
| 333 |
if (token == TOKEN_TRUE) |
| 334 |
data->recolorable = 1; |
| 335 |
else if (token == TOKEN_FALSE) |
| 336 |
data->recolorable = 0; |
| 337 |
else |
| 338 |
return TOKEN_TRUE; |
| 339 |
|
| 340 |
return G_TOKEN_NONE; |
| 341 |
} |
| 342 |
|
| 343 |
static guint |
| 344 |
theme_parse_function(GScanner * scanner, |
| 345 |
ThemeImage *data) |
| 346 |
{ |
| 347 |
guint token; |
| 348 |
|
| 349 |
token = g_scanner_get_next_token(scanner); |
| 350 |
if (token != TOKEN_FUNCTION) |
| 351 |
return TOKEN_FUNCTION; |
| 352 |
|
| 353 |
token = g_scanner_get_next_token(scanner); |
| 354 |
if (token != G_TOKEN_EQUAL_SIGN) |
| 355 |
return G_TOKEN_EQUAL_SIGN; |
| 356 |
|
| 357 |
token = g_scanner_get_next_token(scanner); |
| 358 |
if ((token >= TOKEN_D_HLINE) && (token <= TOKEN_D_RESIZE_GRIP)) |
| 359 |
data->match_data.function = token; |
| 360 |
|
| 361 |
return G_TOKEN_NONE; |
| 362 |
} |
| 363 |
|
| 364 |
static guint |
| 365 |
theme_parse_detail(GScanner * scanner, |
| 366 |
ThemeImage * data) |
| 367 |
{ |
| 368 |
guint token; |
| 369 |
|
| 370 |
token = g_scanner_get_next_token(scanner); |
| 371 |
if (token != TOKEN_DETAIL) |
| 372 |
return TOKEN_DETAIL; |
| 373 |
|
| 374 |
token = g_scanner_get_next_token(scanner); |
| 375 |
if (token != G_TOKEN_EQUAL_SIGN) |
| 376 |
return G_TOKEN_EQUAL_SIGN; |
| 377 |
|
| 378 |
token = g_scanner_get_next_token(scanner); |
| 379 |
if (token != G_TOKEN_STRING) |
| 380 |
return G_TOKEN_STRING; |
| 381 |
|
| 382 |
g_free (data->match_data.detail); |
| 383 |
|
| 384 |
data->match_data.detail = g_strdup(scanner->value.v_string); |
| 385 |
|
| 386 |
return G_TOKEN_NONE; |
| 387 |
} |
| 388 |
|
| 389 |
static guint |
| 390 |
theme_parse_state(GScanner * scanner, |
| 391 |
ThemeImage * data) |
| 392 |
{ |
| 393 |
guint token; |
| 394 |
|
| 395 |
token = g_scanner_get_next_token(scanner); |
| 396 |
if (token != TOKEN_STATE) |
| 397 |
return TOKEN_STATE; |
| 398 |
|
| 399 |
token = g_scanner_get_next_token(scanner); |
| 400 |
if (token != G_TOKEN_EQUAL_SIGN) |
| 401 |
return G_TOKEN_EQUAL_SIGN; |
| 402 |
|
| 403 |
token = g_scanner_get_next_token(scanner); |
| 404 |
if (token == TOKEN_NORMAL) |
| 405 |
data->match_data.state = GTK_STATE_NORMAL; |
| 406 |
else if (token == TOKEN_ACTIVE) |
| 407 |
data->match_data.state = GTK_STATE_ACTIVE; |
| 408 |
else if (token == TOKEN_PRELIGHT) |
| 409 |
data->match_data.state = GTK_STATE_PRELIGHT; |
| 410 |
else if (token == TOKEN_SELECTED) |
| 411 |
data->match_data.state = GTK_STATE_SELECTED; |
| 412 |
else if (token == TOKEN_INSENSITIVE) |
| 413 |
data->match_data.state = GTK_STATE_INSENSITIVE; |
| 414 |
else |
| 415 |
return TOKEN_NORMAL; |
| 416 |
|
| 417 |
data->match_data.flags |= THEME_MATCH_STATE; |
| 418 |
|
| 419 |
return G_TOKEN_NONE; |
| 420 |
} |
| 421 |
|
| 422 |
static guint |
| 423 |
theme_parse_shadow(GScanner * scanner, |
| 424 |
ThemeImage * data) |
| 425 |
{ |
| 426 |
guint token; |
| 427 |
|
| 428 |
token = g_scanner_get_next_token(scanner); |
| 429 |
if (token != TOKEN_SHADOW) |
| 430 |
return TOKEN_SHADOW; |
| 431 |
|
| 432 |
token = g_scanner_get_next_token(scanner); |
| 433 |
if (token != G_TOKEN_EQUAL_SIGN) |
| 434 |
return G_TOKEN_EQUAL_SIGN; |
| 435 |
|
| 436 |
token = g_scanner_get_next_token(scanner); |
| 437 |
if (token == TOKEN_NONE) |
| 438 |
data->match_data.shadow = GTK_SHADOW_NONE; |
| 439 |
else if (token == TOKEN_IN) |
| 440 |
data->match_data.shadow = GTK_SHADOW_IN; |
| 441 |
else if (token == TOKEN_OUT) |
| 442 |
data->match_data.shadow = GTK_SHADOW_OUT; |
| 443 |
else if (token == TOKEN_ETCHED_IN) |
| 444 |
data->match_data.shadow = GTK_SHADOW_ETCHED_IN; |
| 445 |
else if (token == TOKEN_ETCHED_OUT) |
| 446 |
data->match_data.shadow = GTK_SHADOW_ETCHED_OUT; |
| 447 |
else |
| 448 |
return TOKEN_NONE; |
| 449 |
|
| 450 |
data->match_data.flags |= THEME_MATCH_SHADOW; |
| 451 |
|
| 452 |
return G_TOKEN_NONE; |
| 453 |
} |
| 454 |
|
| 455 |
static guint |
| 456 |
theme_parse_arrow_direction(GScanner * scanner, |
| 457 |
ThemeImage * data) |
| 458 |
{ |
| 459 |
guint token; |
| 460 |
|
| 461 |
token = g_scanner_get_next_token(scanner); |
| 462 |
if (token != TOKEN_ARROW_DIRECTION) |
| 463 |
return TOKEN_ARROW_DIRECTION; |
| 464 |
|
| 465 |
token = g_scanner_get_next_token(scanner); |
| 466 |
if (token != G_TOKEN_EQUAL_SIGN) |
| 467 |
return G_TOKEN_EQUAL_SIGN; |
| 468 |
|
| 469 |
token = g_scanner_get_next_token(scanner); |
| 470 |
if (token == TOKEN_UP) |
| 471 |
data->match_data.arrow_direction = GTK_ARROW_UP; |
| 472 |
else if (token == TOKEN_DOWN) |
| 473 |
data->match_data.arrow_direction = GTK_ARROW_DOWN; |
| 474 |
else if (token == TOKEN_LEFT) |
| 475 |
data->match_data.arrow_direction = GTK_ARROW_LEFT; |
| 476 |
else if (token == TOKEN_RIGHT) |
| 477 |
data->match_data.arrow_direction = GTK_ARROW_RIGHT; |
| 478 |
else |
| 479 |
return TOKEN_UP; |
| 480 |
|
| 481 |
data->match_data.flags |= THEME_MATCH_ARROW_DIRECTION; |
| 482 |
|
| 483 |
return G_TOKEN_NONE; |
| 484 |
} |
| 485 |
|
| 486 |
static guint |
| 487 |
theme_parse_gap_side(GScanner * scanner, |
| 488 |
ThemeImage * data) |
| 489 |
{ |
| 490 |
guint token; |
| 491 |
|
| 492 |
token = g_scanner_get_next_token(scanner); |
| 493 |
if (token != TOKEN_GAP_SIDE) |
| 494 |
return TOKEN_GAP_SIDE; |
| 495 |
|
| 496 |
token = g_scanner_get_next_token(scanner); |
| 497 |
if (token != G_TOKEN_EQUAL_SIGN) |
| 498 |
return G_TOKEN_EQUAL_SIGN; |
| 499 |
|
| 500 |
token = g_scanner_get_next_token(scanner); |
| 501 |
|
| 502 |
if (token == TOKEN_TOP) |
| 503 |
data->match_data.gap_side = GTK_POS_TOP; |
| 504 |
else if (token == TOKEN_BOTTOM) |
| 505 |
data->match_data.gap_side = GTK_POS_BOTTOM; |
| 506 |
else if (token == TOKEN_LEFT) |
| 507 |
data->match_data.gap_side = GTK_POS_LEFT; |
| 508 |
else if (token == TOKEN_RIGHT) |
| 509 |
data->match_data.gap_side = GTK_POS_RIGHT; |
| 510 |
else |
| 511 |
return TOKEN_TOP; |
| 512 |
|
| 513 |
data->match_data.flags |= THEME_MATCH_GAP_SIDE; |
| 514 |
|
| 515 |
return G_TOKEN_NONE; |
| 516 |
} |
| 517 |
|
| 518 |
static guint |
| 519 |
theme_parse_orientation(GScanner * scanner, |
| 520 |
ThemeImage * data) |
| 521 |
{ |
| 522 |
guint token; |
| 523 |
|
| 524 |
token = g_scanner_get_next_token(scanner); |
| 525 |
if (token != TOKEN_ORIENTATION) |
| 526 |
return TOKEN_ORIENTATION; |
| 527 |
|
| 528 |
token = g_scanner_get_next_token(scanner); |
| 529 |
if (token != G_TOKEN_EQUAL_SIGN) |
| 530 |
return G_TOKEN_EQUAL_SIGN; |
| 531 |
|
| 532 |
token = g_scanner_get_next_token(scanner); |
| 533 |
|
| 534 |
if (token == TOKEN_HORIZONTAL) |
| 535 |
data->match_data.orientation = GTK_ORIENTATION_HORIZONTAL; |
| 536 |
else if (token == TOKEN_VERTICAL) |
| 537 |
data->match_data.orientation = GTK_ORIENTATION_VERTICAL; |
| 538 |
else |
| 539 |
return TOKEN_HORIZONTAL; |
| 540 |
|
| 541 |
data->match_data.flags |= THEME_MATCH_ORIENTATION; |
| 542 |
|
| 543 |
return G_TOKEN_NONE; |
| 544 |
} |
| 545 |
|
| 546 |
static guint |
| 547 |
theme_parse_expander_style(GScanner * scanner, |
| 548 |
ThemeImage * data) |
| 549 |
{ |
| 550 |
guint token; |
| 551 |
|
| 552 |
token = g_scanner_get_next_token(scanner); |
| 553 |
if (token != TOKEN_EXPANDER_STYLE) |
| 554 |
return TOKEN_EXPANDER_STYLE; |
| 555 |
|
| 556 |
token = g_scanner_get_next_token(scanner); |
| 557 |
if (token != G_TOKEN_EQUAL_SIGN) |
| 558 |
return G_TOKEN_EQUAL_SIGN; |
| 559 |
|
| 560 |
token = g_scanner_get_next_token(scanner); |
| 561 |
if (token == TOKEN_COLLAPSED) |
| 562 |
data->match_data.expander_style = GTK_EXPANDER_COLLAPSED; |
| 563 |
else if (token == TOKEN_SEMI_COLLAPSED) |
| 564 |
data->match_data.expander_style = GTK_EXPANDER_SEMI_COLLAPSED; |
| 565 |
else if (token == TOKEN_SEMI_EXPANDED) |
| 566 |
data->match_data.expander_style = GTK_EXPANDER_SEMI_EXPANDED; |
| 567 |
else if (token == TOKEN_EXPANDED) |
| 568 |
data->match_data.expander_style = GTK_EXPANDER_EXPANDED; |
| 569 |
else |
| 570 |
return TOKEN_COLLAPSED; |
| 571 |
|
| 572 |
data->match_data.flags |= THEME_MATCH_EXPANDER_STYLE; |
| 573 |
|
| 574 |
return G_TOKEN_NONE; |
| 575 |
} |
| 576 |
|
| 577 |
static guint |
| 578 |
theme_parse_window_edge(GScanner * scanner, |
| 579 |
ThemeImage * data) |
| 580 |
{ |
| 581 |
guint token; |
| 582 |
|
| 583 |
token = g_scanner_get_next_token(scanner); |
| 584 |
if (token != TOKEN_WINDOW_EDGE) |
| 585 |
return TOKEN_WINDOW_EDGE; |
| 586 |
|
| 587 |
token = g_scanner_get_next_token(scanner); |
| 588 |
if (token != G_TOKEN_EQUAL_SIGN) |
| 589 |
return G_TOKEN_EQUAL_SIGN; |
| 590 |
|
| 591 |
token = g_scanner_get_next_token(scanner); |
| 592 |
if (token == TOKEN_NORTH_WEST) |
| 593 |
data->match_data.window_edge = GDK_WINDOW_EDGE_NORTH_WEST; |
| 594 |
else if (token == TOKEN_NORTH) |
| 595 |
data->match_data.window_edge = GDK_WINDOW_EDGE_NORTH; |
| 596 |
else if (token == TOKEN_NORTH_EAST) |
| 597 |
data->match_data.window_edge = GDK_WINDOW_EDGE_NORTH_EAST; |
| 598 |
else if (token == TOKEN_WEST) |
| 599 |
data->match_data.window_edge = GDK_WINDOW_EDGE_WEST; |
| 600 |
else if (token == TOKEN_EAST) |
| 601 |
data->match_data.window_edge = GDK_WINDOW_EDGE_EAST; |
| 602 |
else if (token == TOKEN_SOUTH_WEST) |
| 603 |
data->match_data.window_edge = GDK_WINDOW_EDGE_SOUTH_WEST; |
| 604 |
else if (token == TOKEN_SOUTH) |
| 605 |
data->match_data.window_edge = GDK_WINDOW_EDGE_SOUTH; |
| 606 |
else if (token == TOKEN_SOUTH_EAST) |
| 607 |
data->match_data.window_edge = GDK_WINDOW_EDGE_SOUTH_EAST; |
| 608 |
else |
| 609 |
return TOKEN_NORTH_WEST; |
| 610 |
|
| 611 |
data->match_data.flags |= THEME_MATCH_WINDOW_EDGE; |
| 612 |
|
| 613 |
return G_TOKEN_NONE; |
| 614 |
} |
| 615 |
|
| 616 |
static guint |
| 617 |
theme_parse_direction(GScanner * scanner, |
| 618 |
ThemeImage * data) |
| 619 |
{ |
| 620 |
guint token; |
| 621 |
|
| 622 |
token = g_scanner_get_next_token(scanner); |
| 623 |
if (token != TOKEN_DIRECTION) |
| 624 |
return TOKEN_DIRECTION; |
| 625 |
|
| 626 |
token = g_scanner_get_next_token(scanner); |
| 627 |
if (token != G_TOKEN_EQUAL_SIGN) |
| 628 |
return G_TOKEN_EQUAL_SIGN; |
| 629 |
|
| 630 |
token = g_scanner_get_next_token(scanner); |
| 631 |
|
| 632 |
if (token == TOKEN_LTR) |
| 633 |
data->match_data.direction = GTK_TEXT_DIR_LTR; |
| 634 |
else if (token == TOKEN_RTL) |
| 635 |
data->match_data.direction = GTK_TEXT_DIR_RTL; |
| 636 |
else |
| 637 |
return TOKEN_LTR; |
| 638 |
|
| 639 |
data->match_data.flags |= THEME_MATCH_DIRECTION; |
| 640 |
|
| 641 |
return G_TOKEN_NONE; |
| 642 |
} |
| 643 |
|
| 644 |
static void |
| 645 |
theme_image_ref (ThemeImage *data) |
| 646 |
{ |
| 647 |
data->refcount++; |
| 648 |
} |
| 649 |
|
| 650 |
static void |
| 651 |
theme_image_unref (ThemeImage *data) |
| 652 |
{ |
| 653 |
data->refcount--; |
| 654 |
if (data->refcount == 0) |
| 655 |
{ |
| 656 |
g_free (data->match_data.detail); |
| 657 |
theme_pixbuf_destroy (data->background); |
| 658 |
theme_pixbuf_destroy (data->overlay); |
| 659 |
theme_pixbuf_destroy (data->gap_start); |
| 660 |
theme_pixbuf_destroy (data->gap_end); |
| 661 |
theme_pixbuf_destroy (data->gap); |
| 662 |
g_free (data); |
| 663 |
} |
| 664 |
} |
| 665 |
|
| 666 |
static inline void |
| 667 |
clear_theme_pixbuf_and_warn (ThemePixbuf **theme_pb, |
| 668 |
GScanner *scanner, |
| 669 |
const char *message) |
| 670 |
{ |
| 671 |
theme_clear_pixbuf (theme_pb); |
| 672 |
g_scanner_warn (scanner, "%s", message); |
| 673 |
} |
| 674 |
|
| 675 |
static guint |
| 676 |
theme_parse_image(GtkSettings *settings, |
| 677 |
GScanner *scanner, |
| 678 |
PixbufRcStyle *pixbuf_style, |
| 679 |
ThemeImage **data_return) |
| 680 |
{ |
| 681 |
guint token; |
| 682 |
ThemeImage *data; |
| 683 |
|
| 684 |
data = NULL; |
| 685 |
token = g_scanner_get_next_token(scanner); |
| 686 |
if (token != TOKEN_IMAGE) |
| 687 |
return TOKEN_IMAGE; |
| 688 |
|
| 689 |
token = g_scanner_get_next_token(scanner); |
| 690 |
if (token != G_TOKEN_LEFT_CURLY) |
| 691 |
return G_TOKEN_LEFT_CURLY; |
| 692 |
|
| 693 |
data = g_malloc(sizeof(ThemeImage)); |
| 694 |
|
| 695 |
data->refcount = 1; |
| 696 |
|
| 697 |
data->background = NULL; |
| 698 |
data->overlay = NULL; |
| 699 |
data->gap_start = NULL; |
| 700 |
data->gap = NULL; |
| 701 |
data->gap_end = NULL; |
| 702 |
|
| 703 |
data->recolorable = FALSE; |
| 704 |
|
| 705 |
data->match_data.function = 0; |
| 706 |
data->match_data.detail = NULL; |
| 707 |
data->match_data.flags = 0; |
| 708 |
|
| 709 |
token = g_scanner_peek_next_token(scanner); |
| 710 |
while (token != G_TOKEN_RIGHT_CURLY) |
| 711 |
{ |
| 712 |
switch (token) |
| 713 |
{ |
| 714 |
case TOKEN_FUNCTION: |
| 715 |
token = theme_parse_function(scanner, data); |
| 716 |
break; |
| 717 |
case TOKEN_RECOLORABLE: |
| 718 |
token = theme_parse_recolorable(scanner, data); |
| 719 |
break; |
| 720 |
case TOKEN_DETAIL: |
| 721 |
token = theme_parse_detail(scanner, data); |
| 722 |
break; |
| 723 |
case TOKEN_STATE: |
| 724 |
token = theme_parse_state(scanner, data); |
| 725 |
break; |
| 726 |
case TOKEN_SHADOW: |
| 727 |
token = theme_parse_shadow(scanner, data); |
| 728 |
break; |
| 729 |
case TOKEN_GAP_SIDE: |
| 730 |
token = theme_parse_gap_side(scanner, data); |
| 731 |
break; |
| 732 |
case TOKEN_ARROW_DIRECTION: |
| 733 |
token = theme_parse_arrow_direction(scanner, data); |
| 734 |
break; |
| 735 |
case TOKEN_ORIENTATION: |
| 736 |
token = theme_parse_orientation(scanner, data); |
| 737 |
break; |
| 738 |
case TOKEN_FILE: |
| 739 |
token = theme_parse_file(settings, scanner, &data->background); |
| 740 |
break; |
| 741 |
case TOKEN_BORDER: |
| 742 |
token = theme_parse_border(scanner, &data->background); |
| 743 |
break; |
| 744 |
case TOKEN_STRETCH: |
| 745 |
token = theme_parse_stretch(scanner, &data->background); |
| 746 |
break; |
| 747 |
case TOKEN_GAP_FILE: |
| 748 |
token = theme_parse_file(settings, scanner, &data->gap); |
| 749 |
break; |
| 750 |
case TOKEN_GAP_BORDER: |
| 751 |
token = theme_parse_border(scanner, &data->gap); |
| 752 |
break; |
| 753 |
case TOKEN_GAP_START_FILE: |
| 754 |
token = theme_parse_file(settings, scanner, &data->gap_start); |
| 755 |
break; |
| 756 |
case TOKEN_GAP_START_BORDER: |
| 757 |
token = theme_parse_border(scanner, &data->gap_start); |
| 758 |
break; |
| 759 |
case TOKEN_GAP_END_FILE: |
| 760 |
token = theme_parse_file(settings, scanner, &data->gap_end); |
| 761 |
break; |
| 762 |
case TOKEN_GAP_END_BORDER: |
| 763 |
token = theme_parse_border(scanner, &data->gap_end); |
| 764 |
break; |
| 765 |
case TOKEN_OVERLAY_FILE: |
| 766 |
token = theme_parse_file(settings, scanner, &data->overlay); |
| 767 |
break; |
| 768 |
case TOKEN_OVERLAY_BORDER: |
| 769 |
token = theme_parse_border(scanner, &data->overlay); |
| 770 |
break; |
| 771 |
case TOKEN_OVERLAY_STRETCH: |
| 772 |
token = theme_parse_stretch(scanner, &data->overlay); |
| 773 |
break; |
| 774 |
case TOKEN_EXPANDER_STYLE: |
| 775 |
token = theme_parse_expander_style(scanner, data); |
| 776 |
break; |
| 777 |
case TOKEN_WINDOW_EDGE: |
| 778 |
token = theme_parse_window_edge(scanner, data); |
| 779 |
break; |
| 780 |
case TOKEN_DIRECTION: |
| 781 |
token = theme_parse_direction(scanner, data); |
| 782 |
break; |
| 783 |
default: |
| 784 |
g_scanner_get_next_token(scanner); |
| 785 |
token = G_TOKEN_RIGHT_CURLY; |
| 786 |
break; |
| 787 |
} |
| 788 |
if (token != G_TOKEN_NONE) |
| 789 |
{ |
| 790 |
/* error - cleanup for exit */ |
| 791 |
theme_image_unref (data); |
| 792 |
*data_return = NULL; |
| 793 |
return token; |
| 794 |
} |
| 795 |
token = g_scanner_peek_next_token(scanner); |
| 796 |
} |
| 797 |
|
| 798 |
token = g_scanner_get_next_token(scanner); |
| 799 |
|
| 800 |
if (data->background && !data->background->filename) |
| 801 |
clear_theme_pixbuf_and_warn (&data->background, scanner, "Background image options specified without filename"); |
| 802 |
|
| 803 |
if (data->overlay && !data->overlay->filename) |
| 804 |
clear_theme_pixbuf_and_warn (&data->overlay, scanner, "Overlay image options specified without filename"); |
| 805 |
|
| 806 |
if (data->gap && !data->gap->filename) |
| 807 |
clear_theme_pixbuf_and_warn (&data->gap, scanner, "Gap image options specified without filename"); |
| 808 |
|
| 809 |
if (data->gap_start && !data->gap_start->filename) |
| 810 |
clear_theme_pixbuf_and_warn (&data->gap_start, scanner, "Gap start image options specified without filename"); |
| 811 |
|
| 812 |
if (data->gap_end && !data->gap_end->filename) |
| 813 |
clear_theme_pixbuf_and_warn (&data->gap_end, scanner, "Gap end image options specified without filename"); |
| 814 |
|
| 815 |
if (token != G_TOKEN_RIGHT_CURLY) |
| 816 |
{ |
| 817 |
/* error - cleanup for exit */ |
| 818 |
theme_image_unref (data); |
| 819 |
*data_return = NULL; |
| 820 |
return G_TOKEN_RIGHT_CURLY; |
| 821 |
} |
| 822 |
|
| 823 |
/* everything is fine now - insert yer cruft */ |
| 824 |
*data_return = data; |
| 825 |
return G_TOKEN_NONE; |
| 826 |
} |
| 827 |
|
| 828 |
static guint |
| 829 |
pixbuf_rc_style_parse (GtkRcStyle *rc_style, |
| 830 |
GtkSettings *settings, |
| 831 |
GScanner *scanner) |
| 832 |
|
| 833 |
{ |
| 834 |
static GQuark scope_id = 0; |
| 835 |
PixbufRcStyle *pixbuf_style = PIXBUF_RC_STYLE (rc_style); |
| 836 |
|
| 837 |
guint old_scope; |
| 838 |
guint token; |
| 839 |
gint i; |
| 840 |
ThemeImage *img; |
| 841 |
|
| 842 |
/* Set up a new scope in this scanner. */ |
| 843 |
|
| 844 |
if (!scope_id) |
| 845 |
scope_id = g_quark_from_string("pixbuf_theme_engine"); |
| 846 |
|
| 847 |
/* If we bail out due to errors, we *don't* reset the scope, so the |
| 848 |
* error messaging code can make sense of our tokens. |
| 849 |
*/ |
| 850 |
old_scope = g_scanner_set_scope(scanner, scope_id); |
| 851 |
|
| 852 |
/* Now check if we already added our symbols to this scope |
| 853 |
* (in some previous call to theme_parse_rc_style for the |
| 854 |
* same scanner. |
| 855 |
*/ |
| 856 |
|
| 857 |
if (!g_scanner_lookup_symbol(scanner, theme_symbols[0].name)) |
| 858 |
{ |
| 859 |
for (i = 0; i < G_N_ELEMENTS (theme_symbols); i++) |
| 860 |
g_scanner_scope_add_symbol(scanner, scope_id, |
| 861 |
theme_symbols[i].name, |
| 862 |
GINT_TO_POINTER(theme_symbols[i].token)); |
| 863 |
} |
| 864 |
|
| 865 |
/* We're ready to go, now parse the top level */ |
| 866 |
|
| 867 |
token = g_scanner_peek_next_token(scanner); |
| 868 |
while (token != G_TOKEN_RIGHT_CURLY) |
| 869 |
{ |
| 870 |
switch (token) |
| 871 |
{ |
| 872 |
case TOKEN_IMAGE: |
| 873 |
img = NULL; |
| 874 |
token = theme_parse_image(settings, scanner, pixbuf_style, &img); |
| 875 |
break; |
| 876 |
default: |
| 877 |
g_scanner_get_next_token(scanner); |
| 878 |
token = G_TOKEN_RIGHT_CURLY; |
| 879 |
break; |
| 880 |
} |
| 881 |
|
| 882 |
if (token != G_TOKEN_NONE) |
| 883 |
return token; |
| 884 |
else |
| 885 |
pixbuf_style->img_list = g_list_append(pixbuf_style->img_list, img); |
| 886 |
|
| 887 |
token = g_scanner_peek_next_token(scanner); |
| 888 |
} |
| 889 |
|
| 890 |
g_scanner_get_next_token(scanner); |
| 891 |
|
| 892 |
g_scanner_set_scope(scanner, old_scope); |
| 893 |
|
| 894 |
return G_TOKEN_NONE; |
| 895 |
} |
| 896 |
|
| 897 |
static void |
| 898 |
pixbuf_rc_style_merge (GtkRcStyle *dest, |
| 899 |
GtkRcStyle *src) |
| 900 |
{ |
| 901 |
if (PIXBUF_IS_RC_STYLE (src)) |
| 902 |
{ |
| 903 |
PixbufRcStyle *pixbuf_dest = PIXBUF_RC_STYLE (dest); |
| 904 |
PixbufRcStyle *pixbuf_src = PIXBUF_RC_STYLE (src); |
| 905 |
GList *tmp_list1, *tmp_list2; |
| 906 |
|
| 907 |
if (pixbuf_src->img_list) |
| 908 |
{ |
| 909 |
/* Copy src image list and append to dest image list */ |
| 910 |
|
| 911 |
tmp_list2 = g_list_last (pixbuf_dest->img_list); |
| 912 |
tmp_list1 = pixbuf_src->img_list; |
| 913 |
|
| 914 |
while (tmp_list1) |
| 915 |
{ |
| 916 |
if (tmp_list2) |
| 917 |
{ |
| 918 |
tmp_list2->next = g_list_alloc(); |
| 919 |
tmp_list2->next->data = tmp_list1->data; |
| 920 |
tmp_list2->next->prev = tmp_list2; |
| 921 |
|
| 922 |
tmp_list2 = tmp_list2->next; |
| 923 |
} |
| 924 |
else |
| 925 |
{ |
| 926 |
pixbuf_dest->img_list = g_list_append (NULL, tmp_list1->data); |
| 927 |
tmp_list2 = pixbuf_dest->img_list; |
| 928 |
} |
| 929 |
|
| 930 |
theme_image_ref (tmp_list1->data); |
| 931 |
tmp_list1 = tmp_list1->next; |
| 932 |
} |
| 933 |
} |
| 934 |
} |
| 935 |
|
| 936 |
parent_class->merge (dest, src); |
| 937 |
} |
| 938 |
|
| 939 |
/* Create an empty style suitable to this RC style |
| 940 |
*/ |
| 941 |
static GtkStyle * |
| 942 |
pixbuf_rc_style_create_style (GtkRcStyle *rc_style) |
| 943 |
{ |
| 944 |
return g_object_new (PIXBUF_TYPE_STYLE, NULL); |
| 945 |
} |
| 946 |
|