Debian Codegraph @

modules/engines/pixbuf/pixbuf-draw.c

raw
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 <math.h>
24 #include <string.h>
25
26 #undef GDK_DISABLE_DEPRECATED
27
28 #include "pixbuf.h"
29 #include "pixbuf-rc-style.h"
30 #include "pixbuf-style.h"
31
32 static void pixbuf_style_init (PixbufStyle *style);
33 static void pixbuf_style_class_init (PixbufStyleClass *klass);
34
35 static GtkStyleClass *parent_class = NULL;
36
37 static ThemeImage *
38 match_theme_image (GtkStyle *style,
39 ThemeMatchData *match_data)
40 {
41 GList *tmp_list;
42
43 tmp_list = PIXBUF_RC_STYLE (style->rc_style)->img_list;
44
45 while (tmp_list)
46 {
47 guint flags;
48 ThemeImage *image = tmp_list->data;
49 tmp_list = tmp_list->next;
50
51 if (match_data->function != image->match_data.function)
52 continue;
53
54 flags = match_data->flags & image->match_data.flags;
55
56 if (flags != image->match_data.flags) /* Required components not present */
57 continue;
58
59 if ((flags & THEME_MATCH_STATE) &&
60 match_data->state != image->match_data.state)
61 continue;
62
63 if ((flags & THEME_MATCH_SHADOW) &&
64 match_data->shadow != image->match_data.shadow)
65 continue;
66
67 if ((flags & THEME_MATCH_ARROW_DIRECTION) &&
68 match_data->arrow_direction != image->match_data.arrow_direction)
69 continue;
70
71 if ((flags & THEME_MATCH_ORIENTATION) &&
72 match_data->orientation != image->match_data.orientation)
73 continue;
74
75 if ((flags & THEME_MATCH_DIRECTION) &&
76 match_data->direction != image->match_data.direction)
77 continue;
78
79 if ((flags & THEME_MATCH_GAP_SIDE) &&
80 match_data->gap_side != image->match_data.gap_side)
81 continue;
82
83 if ((flags & THEME_MATCH_EXPANDER_STYLE) &&
84 match_data->expander_style != image->match_data.expander_style)
85 continue;
86
87 if ((flags & THEME_MATCH_WINDOW_EDGE) &&
88 match_data->window_edge != image->match_data.window_edge)
89 continue;
90
91 if (image->match_data.detail &&
92 (!match_data->detail ||
93 strcmp (match_data->detail, image->match_data.detail) != 0))
94 continue;
95
96 return image;
97 }
98
99 return NULL;
100 }
101
102 static gboolean
103 draw_simple_image(GtkStyle *style,
104 GdkWindow *window,
105 GdkRectangle *area,
106 GtkWidget *widget,
107 ThemeMatchData *match_data,
108 gboolean draw_center,
109 gboolean allow_setbg,
110 gint x,
111 gint y,
112 gint width,
113 gint height)
114 {
115 ThemeImage *image;
116
117 if ((width == -1) && (height == -1))
118 gdk_drawable_get_size(window, &width, &height);
119 else if (width == -1)
120 gdk_drawable_get_size(window, &width, NULL);
121 else if (height == -1)
122 gdk_drawable_get_size(window, NULL, &height);
123
124 if (!(match_data->flags & THEME_MATCH_ORIENTATION))
125 {
126 match_data->flags |= THEME_MATCH_ORIENTATION;
127
128 if (height > width)
129 match_data->orientation = GTK_ORIENTATION_VERTICAL;
130 else
131 match_data->orientation = GTK_ORIENTATION_HORIZONTAL;
132 }
133
134 if (widget && !(match_data->flags & THEME_MATCH_DIRECTION))
135 {
136 match_data->flags |= THEME_MATCH_DIRECTION;
137 match_data->direction = gtk_widget_get_direction (widget);
138 }
139
140 image = match_theme_image (style, match_data);
141 if (image)
142 {
143 if (image->background)
144 {
145 theme_pixbuf_render (image->background,
146 window, NULL, area,
147 draw_center ? COMPONENT_ALL : COMPONENT_ALL | COMPONENT_CENTER,
148 FALSE,
149 x, y, width, height);
150 }
151
152 if (image->overlay && draw_center)
153 theme_pixbuf_render (image->overlay,
154 window, NULL, area, COMPONENT_ALL,
155 TRUE,
156 x, y, width, height);
157
158 return TRUE;
159 }
160 else
161 return FALSE;
162 }
163
164 static gboolean
165 draw_gap_image(GtkStyle *style,
166 GdkWindow *window,
167 GdkRectangle *area,
168 GtkWidget *widget,
169 ThemeMatchData *match_data,
170 gboolean draw_center,
171 gint x,
172 gint y,
173 gint width,
174 gint height,
175 GtkPositionType gap_side,
176 gint gap_x,
177 gint gap_width)
178 {
179 ThemeImage *image;
180
181 if ((width == -1) && (height == -1))
182 gdk_drawable_get_size(window, &width, &height);
183 else if (width == -1)
184 gdk_drawable_get_size(window, &width, NULL);
185 else if (height == -1)
186 gdk_drawable_get_size(window, NULL, &height);
187
188 if (!(match_data->flags & THEME_MATCH_ORIENTATION))
189 {
190 match_data->flags |= THEME_MATCH_ORIENTATION;
191
192 if (height > width)
193 match_data->orientation = GTK_ORIENTATION_VERTICAL;
194 else
195 match_data->orientation = GTK_ORIENTATION_HORIZONTAL;
196 }
197
198 match_data->flags |= THEME_MATCH_GAP_SIDE;
199 match_data->gap_side = gap_side;
200
201 image = match_theme_image (style, match_data);
202 if (image)
203 {
204 gint thickness;
205 GdkRectangle r1, r2, r3;
206 GdkPixbuf *pixbuf = NULL;
207 guint components = COMPONENT_ALL;
208
209 if (!draw_center)
210 components |= COMPONENT_CENTER;
211
212 if (image->gap_start)
213 pixbuf = theme_pixbuf_get_pixbuf (image->gap_start);
214
215 switch (gap_side)
216 {
217 case GTK_POS_TOP:
218 if (pixbuf)
219 thickness = gdk_pixbuf_get_height (pixbuf);
220 else
221 thickness = style->ythickness;
222
223 if (!draw_center)
224 components |= COMPONENT_NORTH_WEST | COMPONENT_NORTH | COMPONENT_NORTH_EAST;
225
226 r1.x = x;
227 r1.y = y;
228 r1.width = gap_x;
229 r1.height = thickness;
230 r2.x = x + gap_x;
231 r2.y = y;
232 r2.width = gap_width;
233 r2.height = thickness;
234 r3.x = x + gap_x + gap_width;
235 r3.y = y;
236 r3.width = width - (gap_x + gap_width);
237 r3.height = thickness;
238 break;
239
240 case GTK_POS_BOTTOM:
241 if (pixbuf)
242 thickness = gdk_pixbuf_get_height (pixbuf);
243 else
244 thickness = style->ythickness;
245
246 if (!draw_center)
247 components |= COMPONENT_SOUTH_WEST | COMPONENT_SOUTH | COMPONENT_SOUTH_EAST;
248
249 r1.x = x;
250 r1.y = y + height - thickness;
251 r1.width = gap_x;
252 r1.height = thickness;
253 r2.x = x + gap_x;
254 r2.y = y + height - thickness;
255 r2.width = gap_width;
256 r2.height = thickness;
257 r3.x = x + gap_x + gap_width;
258 r3.y = y + height - thickness;
259 r3.width = width - (gap_x + gap_width);
260 r3.height = thickness;
261 break;
262
263 case GTK_POS_LEFT:
264 if (pixbuf)
265 thickness = gdk_pixbuf_get_width (pixbuf);
266 else
267 thickness = style->xthickness;
268
269 if (!draw_center)
270 components |= COMPONENT_NORTH_WEST | COMPONENT_WEST | COMPONENT_SOUTH_WEST;
271
272 r1.x = x;
273 r1.y = y;
274 r1.width = thickness;
275 r1.height = gap_x;
276 r2.x = x;
277 r2.y = y + gap_x;
278 r2.width = thickness;
279 r2.height = gap_width;
280 r3.x = x;
281 r3.y = y + gap_x + gap_width;
282 r3.width = thickness;
283 r3.height = height - (gap_x + gap_width);
284 break;
285
286 case GTK_POS_RIGHT:
287 if (pixbuf)
288 thickness = gdk_pixbuf_get_width (pixbuf);
289 else
290 thickness = style->xthickness;
291
292 if (!draw_center)
293 components |= COMPONENT_NORTH_EAST | COMPONENT_EAST | COMPONENT_SOUTH_EAST;
294
295 r1.x = x + width - thickness;
296 r1.y = y;
297 r1.width = thickness;
298 r1.height = gap_x;
299 r2.x = x + width - thickness;
300 r2.y = y + gap_x;
301 r2.width = thickness;
302 r2.height = gap_width;
303 r3.x = x + width - thickness;
304 r3.y = y + gap_x + gap_width;
305 r3.width = thickness;
306 r3.height = height - (gap_x + gap_width);
307 break;
308
309 default:
310 g_assert_not_reached ();
311 }
312
313 if (image->background)
314 theme_pixbuf_render (image->background,
315 window, NULL, area, components, FALSE,
316 x, y, width, height);
317 if (image->gap_start)
318 theme_pixbuf_render (image->gap_start,
319 window, NULL, area, COMPONENT_ALL, FALSE,
320 r1.x, r1.y, r1.width, r1.height);
321 if (image->gap)
322 theme_pixbuf_render (image->gap,
323 window, NULL, area, COMPONENT_ALL, FALSE,
324 r2.x, r2.y, r2.width, r2.height);
325 if (image->gap_end)
326 theme_pixbuf_render (image->gap_end,
327 window, NULL, area, COMPONENT_ALL, FALSE,
328 r3.x, r3.y, r3.width, r3.height);
329
330 return TRUE;
331 }
332 else
333 return FALSE;
334 }
335
336 static void
337 draw_hline (GtkStyle *style,
338 GdkWindow *window,
339 GtkStateType state,
340 GdkRectangle *area,
341 GtkWidget *widget,
342 const gchar *detail,
343 gint x1,
344 gint x2,
345 gint y)
346 {
347 ThemeImage *image;
348 ThemeMatchData match_data;
349
350 g_return_if_fail(style != NULL);
351 g_return_if_fail(window != NULL);
352
353 match_data.function = TOKEN_D_HLINE;
354 match_data.detail = (gchar *)detail;
355 match_data.flags = THEME_MATCH_ORIENTATION | THEME_MATCH_STATE;
356 match_data.state = state;
357 match_data.orientation = GTK_ORIENTATION_HORIZONTAL;
358
359 image = match_theme_image (style, &match_data);
360 if (image)
361 {
362 if (image->background)
363 theme_pixbuf_render (image->background,
364 window, NULL, area, COMPONENT_ALL, FALSE,
365 x1, y, (x2 - x1) + 1, 2);
366 }
367 else
368 parent_class->draw_hline (style, window, state, area, widget, detail,
369 x1, x2, y);
370 }
371
372 static void
373 draw_vline (GtkStyle *style,
374 GdkWindow *window,
375 GtkStateType state,
376 GdkRectangle *area,
377 GtkWidget *widget,
378 const gchar *detail,
379 gint y1,
380 gint y2,
381 gint x)
382 {
383 ThemeImage *image;
384 ThemeMatchData match_data;
385
386 g_return_if_fail (style != NULL);
387 g_return_if_fail (window != NULL);
388
389 match_data.function = TOKEN_D_VLINE;
390 match_data.detail = (gchar *)detail;
391 match_data.flags = THEME_MATCH_ORIENTATION | THEME_MATCH_STATE;
392 match_data.state = state;
393 match_data.orientation = GTK_ORIENTATION_VERTICAL;
394
395 image = match_theme_image (style, &match_data);
396 if (image)
397 {
398 if (image->background)
399 theme_pixbuf_render (image->background,
400 window, NULL, area, COMPONENT_ALL, FALSE,
401 x, y1, 2, (y2 - y1) + 1);
402 }
403 else
404 parent_class->draw_vline (style, window, state, area, widget, detail,
405 y1, y2, x);
406 }
407
408 static void
409 draw_shadow(GtkStyle *style,
410 GdkWindow *window,
411 GtkStateType state,
412 GtkShadowType shadow,
413 GdkRectangle *area,
414 GtkWidget *widget,
415 const gchar *detail,
416 gint x,
417 gint y,
418 gint width,
419 gint height)
420 {
421 ThemeMatchData match_data;
422
423 g_return_if_fail(style != NULL);
424 g_return_if_fail(window != NULL);
425
426 match_data.function = TOKEN_D_SHADOW;
427 match_data.detail = (gchar *)detail;
428 match_data.flags = THEME_MATCH_SHADOW | THEME_MATCH_STATE;
429 match_data.shadow = shadow;
430 match_data.state = state;
431
432 if (!draw_simple_image (style, window, area, widget, &match_data, FALSE, FALSE,
433 x, y, width, height))
434 parent_class->draw_shadow (style, window, state, shadow, area, widget, detail,
435 x, y, width, height);
436 }
437
438 /* This function makes up for some brokeness in gtkrange.c
439 * where we never get the full arrow of the stepper button
440 * and the type of button in a single drawing function.
441 *
442 * It doesn't work correctly when the scrollbar is squished
443 * to the point we don't have room for full-sized steppers.
444 */
445 static void
446 reverse_engineer_stepper_box (GtkWidget *range,
447 GtkArrowType arrow_type,
448 gint *x,
449 gint *y,
450 gint *width,
451 gint *height)
452 {
453 gint slider_width = 14, stepper_size = 14;
454 gint box_width;
455 gint box_height;
456
457 if (range && GTK_IS_RANGE (range))
458 {
459 gtk_widget_style_get (range,
460 "slider_width", &slider_width,
461 "stepper_size", &stepper_size,
462 NULL);
463 }
464
465 if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
466 {
467 box_width = slider_width;
468 box_height = stepper_size;
469 }
470 else
471 {
472 box_width = stepper_size;
473 box_height = slider_width;
474 }
475
476 *x = *x - (box_width - *width) / 2;
477 *y = *y - (box_height - *height) / 2;
478 *width = box_width;
479 *height = box_height;
480 }
481
482 static void
483 draw_arrow (GtkStyle *style,
484 GdkWindow *window,
485 GtkStateType state,
486 GtkShadowType shadow,
487 GdkRectangle *area,
488 GtkWidget *widget,
489 const gchar *detail,
490 GtkArrowType arrow_direction,
491 gint fill,
492 gint x,
493 gint y,
494 gint width,
495 gint height)
496 {
497 ThemeMatchData match_data;
498
499 g_return_if_fail(style != NULL);
500 g_return_if_fail(window != NULL);
501
502 if (detail &&
503 (strcmp (detail, "hscrollbar") == 0 || strcmp (detail, "vscrollbar") == 0))
504 {
505 /* This is a hack to work around the fact that scrollbar steppers are drawn
506 * as a box + arrow, so we never have
507 *
508 * The full bounding box of the scrollbar
509 * The arrow direction
510 *
511 * At the same time. We simulate an extra paint function, "STEPPER", by doing
512 * nothing for the box, and then here, reverse engineering the box that
513 * was passed to draw box and using that
514 */
515 gint box_x = x;
516 gint box_y = y;
517 gint box_width = width;
518 gint box_height = height;
519
520 reverse_engineer_stepper_box (widget, arrow_direction,
521 &box_x, &box_y, &box_width, &box_height);
522
523 match_data.function = TOKEN_D_STEPPER;
524 match_data.detail = (gchar *)detail;
525 match_data.flags = (THEME_MATCH_SHADOW |
526 THEME_MATCH_STATE |
527 THEME_MATCH_ARROW_DIRECTION);
528 match_data.shadow = shadow;
529 match_data.state = state;
530 match_data.arrow_direction = arrow_direction;
531
532 if (draw_simple_image (style, window, area, widget, &match_data, TRUE, TRUE,
533 box_x, box_y, box_width, box_height))
534 {
535 /* The theme included stepper images, we're done */
536 return;
537 }
538
539 /* Otherwise, draw the full box, and fall through to draw the arrow
540 */
541 match_data.function = TOKEN_D_BOX;
542 match_data.detail = (gchar *)detail;
543 match_data.flags = THEME_MATCH_SHADOW | THEME_MATCH_STATE;
544 match_data.shadow = shadow;
545 match_data.state = state;
546
547 if (!draw_simple_image (style, window, area, widget, &match_data, TRUE, TRUE,
548 box_x, box_y, box_width, box_height))
549 parent_class->draw_box (style, window, state, shadow, area, widget, detail,
550 box_x, box_y, box_width, box_height);
551 }
552
553
554 match_data.function = TOKEN_D_ARROW;
555 match_data.detail = (gchar *)detail;
556 match_data.flags = (THEME_MATCH_SHADOW |
557 THEME_MATCH_STATE |
558 THEME_MATCH_ARROW_DIRECTION);
559 match_data.shadow = shadow;
560 match_data.state = state;
561 match_data.arrow_direction = arrow_direction;
562
563 if (!draw_simple_image (style, window, area, widget, &match_data, TRUE, TRUE,
564 x, y, width, height))
565 parent_class->draw_arrow (style, window, state, shadow, area, widget, detail,
566 arrow_direction, fill, x, y, width, height);
567 }
568
569 static void
570 draw_diamond (GtkStyle *style,
571 GdkWindow *window,
572 GtkStateType state,
573 GtkShadowType shadow,
574 GdkRectangle *area,
575 GtkWidget *widget,
576 const gchar *detail,
577 gint x,
578 gint y,
579 gint width,
580 gint height)
581 {
582 ThemeMatchData match_data;
583
584 g_return_if_fail(style != NULL);
585 g_return_if_fail(window != NULL);
586
587 match_data.function = TOKEN_D_DIAMOND;
588 match_data.detail = (gchar *)detail;
589 match_data.flags = THEME_MATCH_SHADOW | THEME_MATCH_STATE;
590 match_data.shadow = shadow;
591 match_data.state = state;
592
593 if (!draw_simple_image (style, window, area, widget, &match_data, TRUE, TRUE,
594 x, y, width, height))
595 parent_class->draw_diamond (style, window, state, shadow, area, widget, detail,
596 x, y, width, height);
597 }
598
599 static void
600 draw_string (GtkStyle * style,
601 GdkWindow * window,
602 GtkStateType state,
603 GdkRectangle * area,
604 GtkWidget * widget,
605 const gchar *detail,
606 gint x,
607 gint y,
608 const gchar * string)
609 {
610 g_return_if_fail(style != NULL);
611 g_return_if_fail(window != NULL);
612
613 if (state == GTK_STATE_INSENSITIVE)
614 {
615 if (area)
616 {
617 gdk_gc_set_clip_rectangle(style->white_gc, area);
618 gdk_gc_set_clip_rectangle(style->fg_gc[state], area);
619 }
620
621 gdk_draw_string(window, gtk_style_get_font (style), style->fg_gc[state], x, y, string);
622
623 if (area)
624 {
625 gdk_gc_set_clip_rectangle(style->white_gc, NULL);
626 gdk_gc_set_clip_rectangle(style->fg_gc[state], NULL);
627 }
628 }
629 else
630 {
631 gdk_gc_set_clip_rectangle(style->fg_gc[state], area);
632 gdk_draw_string(window, gtk_style_get_font (style), style->fg_gc[state], x, y, string);
633 gdk_gc_set_clip_rectangle(style->fg_gc[state], NULL);
634 }
635 }
636
637 static void
638 draw_box (GtkStyle *style,
639 GdkWindow *window,
640 GtkStateType state,
641 GtkShadowType shadow,
642 GdkRectangle *area,
643 GtkWidget *widget,
644 const gchar *detail,
645 gint x,
646 gint y,
647 gint width,
648 gint height)
649 {
650 ThemeMatchData match_data;
651
652 g_return_if_fail(style != NULL);
653 g_return_if_fail(window != NULL);
654
655 if (detail &&
656 (strcmp (detail, "hscrollbar") == 0 || strcmp (detail, "vscrollbar") == 0))
657 {
658 /* We handle this in draw_arrow */
659 return;
660 }
661
662 match_data.function = TOKEN_D_BOX;
663 match_data.detail = (gchar *)detail;
664 match_data.flags = THEME_MATCH_SHADOW | THEME_MATCH_STATE;
665 match_data.shadow = shadow;
666 match_data.state = state;
667
668 if (!draw_simple_image (style, window, area, widget, &match_data, TRUE, TRUE,
669 x, y, width, height)) {
670 parent_class->draw_box (style, window, state, shadow, area, widget, detail,
671 x, y, width, height);
672 }
673 }
674
675 static void
676 draw_flat_box (GtkStyle *style,
677 GdkWindow *window,
678 GtkStateType state,
679 GtkShadowType shadow,
680 GdkRectangle *area,
681 GtkWidget *widget,
682 const gchar *detail,
683 gint x,
684 gint y,
685 gint width,
686 gint height)
687 {
688 ThemeMatchData match_data;
689
690 g_return_if_fail(style != NULL);
691 g_return_if_fail(window != NULL);
692
693 match_data.function = TOKEN_D_FLAT_BOX;
694 match_data.detail = (gchar *)detail;
695 match_data.flags = THEME_MATCH_SHADOW | THEME_MATCH_STATE;
696 match_data.shadow = shadow;
697 match_data.state = state;
698
699 if (!draw_simple_image (style, window, area, widget, &match_data, TRUE, TRUE,
700 x, y, width, height))
701 parent_class->draw_flat_box (style, window, state, shadow, area, widget, detail,
702 x, y, width, height);
703 }
704
705 static void
706 draw_check (GtkStyle *style,
707 GdkWindow *window,
708 GtkStateType state,
709 GtkShadowType shadow,
710 GdkRectangle *area,
711 GtkWidget *widget,
712 const gchar *detail,
713 gint x,
714 gint y,
715 gint width,
716 gint height)
717 {
718 ThemeMatchData match_data;
719
720 g_return_if_fail(style != NULL);
721 g_return_if_fail(window != NULL);
722
723 match_data.function = TOKEN_D_CHECK;
724 match_data.detail = (gchar *)detail;
725 match_data.flags = THEME_MATCH_SHADOW | THEME_MATCH_STATE;
726 match_data.shadow = shadow;
727 match_data.state = state;
728
729 if (!draw_simple_image (style, window, area, widget, &match_data, TRUE, TRUE,
730 x, y, width, height))
731 parent_class->draw_check (style, window, state, shadow, area, widget, detail,
732 x, y, width, height);
733 }
734
735 static void
736 draw_option (GtkStyle *style,
737 GdkWindow *window,
738 GtkStateType state,
739 GtkShadowType shadow,
740 GdkRectangle *area,
741 GtkWidget *widget,
742 const gchar *detail,
743 gint x,
744 gint y,
745 gint width,
746 gint height)
747 {
748 ThemeMatchData match_data;
749
750 g_return_if_fail(style != NULL);
751 g_return_if_fail(window != NULL);
752
753 match_data.function = TOKEN_D_OPTION;
754 match_data.detail = (gchar *)detail;
755 match_data.flags = THEME_MATCH_SHADOW | THEME_MATCH_STATE;
756 match_data.shadow = shadow;
757 match_data.state = state;
758
759 if (!draw_simple_image (style, window, area, widget, &match_data, TRUE, TRUE,
760 x, y, width, height))
761 parent_class->draw_option (style, window, state, shadow, area, widget, detail,
762 x, y, width, height);
763 }
764
765 static void
766 draw_tab (GtkStyle *style,
767 GdkWindow *window,
768 GtkStateType state,
769 GtkShadowType shadow,
770 GdkRectangle *area,
771 GtkWidget *widget,
772 const gchar *detail,
773 gint x,
774 gint y,
775 gint width,
776 gint height)
777 {
778 ThemeMatchData match_data;
779
780 g_return_if_fail(style != NULL);
781 g_return_if_fail(window != NULL);
782
783 match_data.function = TOKEN_D_TAB;
784 match_data.detail = (gchar *)detail;
785 match_data.flags = THEME_MATCH_SHADOW | THEME_MATCH_STATE;
786 match_data.shadow = shadow;
787 match_data.state = state;
788
789 if (!draw_simple_image (style, window, area, widget, &match_data, TRUE, TRUE,
790 x, y, width, height))
791 parent_class->draw_tab (style, window, state, shadow, area, widget, detail,
792 x, y, width, height);
793 }
794
795 static void
796 draw_shadow_gap (GtkStyle *style,
797 GdkWindow *window,
798 GtkStateType state,
799 GtkShadowType shadow,
800 GdkRectangle *area,
801 GtkWidget *widget,
802 const gchar *detail,
803 gint x,
804 gint y,
805 gint width,
806 gint height,
807 GtkPositionType gap_side,
808 gint gap_x,
809 gint gap_width)
810 {
811 ThemeMatchData match_data;
812
813 match_data.function = TOKEN_D_SHADOW_GAP;
814 match_data.detail = (gchar *)detail;
815 match_data.flags = THEME_MATCH_SHADOW | THEME_MATCH_STATE;
816 match_data.flags = (THEME_MATCH_SHADOW |
817 THEME_MATCH_STATE |
818 THEME_MATCH_ORIENTATION);
819 match_data.shadow = shadow;
820 match_data.state = state;
821
822 if (!draw_gap_image (style, window, area, widget, &match_data, FALSE,
823 x, y, width, height, gap_side, gap_x, gap_width))
824 parent_class->draw_shadow_gap (style, window, state, shadow, area, widget, detail,
825 x, y, width, height, gap_side, gap_x, gap_width);
826 }
827
828 static void
829 draw_box_gap (GtkStyle *style,
830 GdkWindow *window,
831 GtkStateType state,
832 GtkShadowType shadow,
833 GdkRectangle *area,
834 GtkWidget *widget,
835 const gchar *detail,
836 gint x,
837 gint y,
838 gint width,
839 gint height,
840 GtkPositionType gap_side,
841 gint gap_x,
842 gint gap_width)
843 {
844 ThemeMatchData match_data;
845
846 match_data.function = TOKEN_D_BOX_GAP;
847 match_data.detail = (gchar *)detail;
848 match_data.flags = THEME_MATCH_SHADOW | THEME_MATCH_STATE;
849 match_data.flags = (THEME_MATCH_SHADOW |
850 THEME_MATCH_STATE |
851 THEME_MATCH_ORIENTATION);
852 match_data.shadow = shadow;
853 match_data.state = state;
854
855 if (!draw_gap_image (style, window, area, widget, &match_data, TRUE,
856 x, y, width, height, gap_side, gap_x, gap_width))
857 parent_class->draw_box_gap (style, window, state, shadow, area, widget, detail,
858 x, y, width, height, gap_side, gap_x, gap_width);
859 }
860
861 static void
862 draw_extension (GtkStyle *style,
863 GdkWindow *window,
864 GtkStateType state,
865 GtkShadowType shadow,
866 GdkRectangle *area,
867 GtkWidget *widget,
868 const gchar *detail,
869 gint x,
870 gint y,
871 gint width,
872 gint height,
873 GtkPositionType gap_side)
874 {
875 ThemeMatchData match_data;
876
877 g_return_if_fail (style != NULL);
878 g_return_if_fail (window != NULL);
879
880 match_data.function = TOKEN_D_EXTENSION;
881 match_data.detail = (gchar *)detail;
882 match_data.flags = THEME_MATCH_SHADOW | THEME_MATCH_STATE | THEME_MATCH_GAP_SIDE;
883 match_data.shadow = shadow;
884 match_data.state = state;
885 match_data.gap_side = gap_side;
886
887 if (!draw_simple_image (style, window, area, widget, &match_data, TRUE, TRUE,
888 x, y, width, height))
889 parent_class->draw_extension (style, window, state, shadow, area, widget, detail,
890 x, y, width, height, gap_side);
891 }
892
893 static void
894 draw_focus (GtkStyle *style,
895 GdkWindow *window,
896 GtkStateType state_type,
897 GdkRectangle *area,
898 GtkWidget *widget,
899 const gchar *detail,
900 gint x,
901 gint y,
902 gint width,
903 gint height)
904 {
905 ThemeMatchData match_data;
906
907 g_return_if_fail (style != NULL);
908 g_return_if_fail (window != NULL);
909
910 match_data.function = TOKEN_D_FOCUS;
911 match_data.detail = (gchar *)detail;
912 match_data.flags = 0;
913
914 if (!draw_simple_image (style, window, area, widget, &match_data, TRUE, FALSE,
915 x, y, width, height))
916 parent_class->draw_focus (style, window, state_type, area, widget, detail,
917 x, y, width, height);
918 }
919
920 static void
921 draw_slider (GtkStyle *style,
922 GdkWindow *window,
923 GtkStateType state,
924 GtkShadowType shadow,
925 GdkRectangle *area,
926 GtkWidget *widget,
927 const gchar *detail,
928 gint x,
929 gint y,
930 gint width,
931 gint height,
932 GtkOrientation orientation)
933 {
934 ThemeMatchData match_data;
935
936 g_return_if_fail(style != NULL);
937 g_return_if_fail(window != NULL);
938
939 match_data.function = TOKEN_D_SLIDER;
940 match_data.detail = (gchar *)detail;
941 match_data.flags = (THEME_MATCH_SHADOW |
942 THEME_MATCH_STATE |
943 THEME_MATCH_ORIENTATION);
944 match_data.shadow = shadow;
945 match_data.state = state;
946 match_data.orientation = orientation;
947
948 if (!draw_simple_image (style, window, area, widget, &match_data, TRUE, TRUE,
949 x, y, width, height))
950 parent_class->draw_slider (style, window, state, shadow, area, widget, detail,
951 x, y, width, height, orientation);
952 }
953
954
955 static void
956 draw_handle (GtkStyle *style,
957 GdkWindow *window,
958 GtkStateType state,
959 GtkShadowType shadow,
960 GdkRectangle *area,
961 GtkWidget *widget,
962 const gchar *detail,
963 gint x,
964 gint y,
965 gint width,
966 gint height,
967 GtkOrientation orientation)
968 {
969 ThemeMatchData match_data;
970
971 g_return_if_fail (style != NULL);
972 g_return_if_fail (window != NULL);
973
974 match_data.function = TOKEN_D_HANDLE;
975 match_data.detail = (gchar *)detail;
976 match_data.flags = (THEME_MATCH_SHADOW |
977 THEME_MATCH_STATE |
978 THEME_MATCH_ORIENTATION);
979 match_data.shadow = shadow;
980 match_data.state = state;
981 match_data.orientation = orientation;
982
983 if (!draw_simple_image (style, window, area, widget, &match_data, TRUE, TRUE,
984 x, y, width, height))
985 parent_class->draw_handle (style, window, state, shadow, area, widget, detail,
986 x, y, width, height, orientation);
987 }
988
989 static void
990 draw_expander (GtkStyle *style,
991 GdkWindow *window,
992 GtkStateType state,
993 GdkRectangle *area,
994 GtkWidget *widget,
995 const gchar *detail,
996 gint x,
997 gint y,
998 GtkExpanderStyle expander_style)
999 {
1000 #define DEFAULT_EXPANDER_SIZE 12
1001
1002 ThemeMatchData match_data;
1003 gint expander_size;
1004 gint radius;
1005
1006 g_return_if_fail (style != NULL);
1007 g_return_if_fail (window != NULL);
1008
1009 if (widget &&
1010 gtk_widget_class_find_style_property (GTK_WIDGET_GET_CLASS (widget),
1011 "expander-size"))
1012 {
1013 gtk_widget_style_get (widget,
1014 "expander-size", &expander_size,
1015 NULL);
1016 }
1017 else
1018 expander_size = DEFAULT_EXPANDER_SIZE;
1019
1020 radius = expander_size/2;
1021
1022 match_data.function = TOKEN_D_EXPANDER;
1023 match_data.detail = (gchar *)detail;
1024 match_data.flags = (THEME_MATCH_STATE |
1025 THEME_MATCH_EXPANDER_STYLE);
1026 match_data.state = state;
1027 match_data.expander_style = expander_style;
1028
1029 if (!draw_simple_image (style, window, area, widget, &match_data, TRUE, TRUE,
1030 x - radius, y - radius, expander_size, expander_size))
1031 parent_class->draw_expander (style, window, state, area, widget, detail,
1032 x, y, expander_style);
1033 }
1034
1035 static void
1036 draw_resize_grip (GtkStyle *style,
1037 GdkWindow *window,
1038 GtkStateType state,
1039 GdkRectangle *area,
1040 GtkWidget *widget,
1041 const gchar *detail,
1042 GdkWindowEdge edge,
1043 gint x,
1044 gint y,
1045 gint width,
1046 gint height)
1047 {
1048 ThemeMatchData match_data;
1049
1050 g_return_if_fail (style != NULL);
1051 g_return_if_fail (window != NULL);
1052
1053 match_data.function = TOKEN_D_RESIZE_GRIP;
1054 match_data.detail = (gchar *)detail;
1055 match_data.flags = (THEME_MATCH_STATE |
1056 THEME_MATCH_WINDOW_EDGE);
1057 match_data.state = state;
1058 match_data.window_edge = edge;
1059
1060 if (!draw_simple_image (style, window, area, widget, &match_data, TRUE, TRUE,
1061 x, y, width, height))
1062 parent_class->draw_resize_grip (style, window, state, area, widget, detail,
1063 edge, x, y, width, height);
1064 }
1065
1066 GType pixbuf_type_style = 0;
1067
1068 void
1069 pixbuf_style_register_type (GTypeModule *module)
1070 {
1071 const GTypeInfo object_info =
1072 {
1073 sizeof (PixbufStyleClass),
1074 (GBaseInitFunc) NULL,
1075 (GBaseFinalizeFunc) NULL,
1076 (GClassInitFunc) pixbuf_style_class_init,
1077 NULL, /* class_finalize */
1078 NULL, /* class_data */
1079 sizeof (PixbufStyle),
1080 0, /* n_preallocs */
1081 (GInstanceInitFunc) pixbuf_style_init,
1082 };
1083
1084 pixbuf_type_style = g_type_module_register_type (module,
1085 GTK_TYPE_STYLE,
1086 "PixbufStyle",
1087 &object_info, 0);
1088 }
1089
1090 static void
1091 pixbuf_style_init (PixbufStyle *style)
1092 {
1093 }
1094
1095 static void
1096 pixbuf_style_class_init (PixbufStyleClass *klass)
1097 {
1098 GtkStyleClass *style_class = GTK_STYLE_CLASS (klass);
1099
1100 parent_class = g_type_class_peek_parent (klass);
1101
1102 style_class->draw_hline = draw_hline;
1103 style_class->draw_vline = draw_vline;
1104 style_class->draw_shadow = draw_shadow;
1105 style_class->draw_arrow = draw_arrow;
1106 style_class->draw_diamond = draw_diamond;
1107 style_class->draw_string = draw_string;
1108 style_class->draw_box = draw_box;
1109 style_class->draw_flat_box = draw_flat_box;
1110 style_class->draw_check = draw_check;
1111 style_class->draw_option = draw_option;
1112 style_class->draw_tab = draw_tab;
1113 style_class->draw_shadow_gap = draw_shadow_gap;
1114 style_class->draw_box_gap = draw_box_gap;
1115 style_class->draw_extension = draw_extension;
1116 style_class->draw_focus = draw_focus;
1117 style_class->draw_slider = draw_slider;
1118 style_class->draw_handle = draw_handle;
1119 style_class->draw_expander = draw_expander;
1120 style_class->draw_resize_grip = draw_resize_grip;
1121 }