1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser 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 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser 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.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
32 #include "gtkspinbutton.h"
34 #include "gtkwidget.h"
35 #include "gtkthemes.h"
36 #include "gtkiconfactory.h"
37 #include "gtksettings.h" /* _gtk_settings_parse_convert() */
39 #define LIGHTNESS_MULT 1.3
40 #define DARKNESS_MULT 0.7
42 /* --- typedefs & structures --- */
50 /* --- prototypes --- */
51 static void gtk_style_init (GtkStyle *style);
52 static void gtk_style_class_init (GtkStyleClass *klass);
53 static void gtk_style_finalize (GObject *object);
54 static void gtk_style_realize (GtkStyle *style,
55 GdkColormap *colormap);
56 static void gtk_style_real_realize (GtkStyle *style);
57 static void gtk_style_real_unrealize (GtkStyle *style);
58 static void gtk_style_real_copy (GtkStyle *style,
60 static void gtk_style_real_set_background (GtkStyle *style,
62 GtkStateType state_type);
63 static GtkStyle *gtk_style_real_clone (GtkStyle *style);
64 static void gtk_style_real_init_from_rc (GtkStyle *style,
65 GtkRcStyle *rc_style);
66 static GdkPixbuf *gtk_default_render_icon (GtkStyle *style,
67 const GtkIconSource *source,
68 GtkTextDirection direction,
73 static void gtk_default_draw_hline (GtkStyle *style,
75 GtkStateType state_type,
82 static void gtk_default_draw_vline (GtkStyle *style,
84 GtkStateType state_type,
91 static void gtk_default_draw_shadow (GtkStyle *style,
93 GtkStateType state_type,
94 GtkShadowType shadow_type,
102 static void gtk_default_draw_polygon (GtkStyle *style,
104 GtkStateType state_type,
105 GtkShadowType shadow_type,
112 static void gtk_default_draw_arrow (GtkStyle *style,
114 GtkStateType state_type,
115 GtkShadowType shadow_type,
119 GtkArrowType arrow_type,
125 static void gtk_default_draw_diamond (GtkStyle *style,
127 GtkStateType state_type,
128 GtkShadowType shadow_type,
136 static void gtk_default_draw_string (GtkStyle *style,
138 GtkStateType state_type,
144 const gchar *string);
145 static void gtk_default_draw_box (GtkStyle *style,
147 GtkStateType state_type,
148 GtkShadowType shadow_type,
156 static void gtk_default_draw_flat_box (GtkStyle *style,
158 GtkStateType state_type,
159 GtkShadowType shadow_type,
167 static void gtk_default_draw_check (GtkStyle *style,
169 GtkStateType state_type,
170 GtkShadowType shadow_type,
178 static void gtk_default_draw_option (GtkStyle *style,
180 GtkStateType state_type,
181 GtkShadowType shadow_type,
189 static void gtk_default_draw_tab (GtkStyle *style,
191 GtkStateType state_type,
192 GtkShadowType shadow_type,
200 static void gtk_default_draw_shadow_gap (GtkStyle *style,
202 GtkStateType state_type,
203 GtkShadowType shadow_type,
211 GtkPositionType gap_side,
214 static void gtk_default_draw_box_gap (GtkStyle *style,
216 GtkStateType state_type,
217 GtkShadowType shadow_type,
225 GtkPositionType gap_side,
228 static void gtk_default_draw_extension (GtkStyle *style,
230 GtkStateType state_type,
231 GtkShadowType shadow_type,
239 GtkPositionType gap_side);
240 static void gtk_default_draw_focus (GtkStyle *style,
242 GtkStateType state_type,
250 static void gtk_default_draw_slider (GtkStyle *style,
252 GtkStateType state_type,
253 GtkShadowType shadow_type,
261 GtkOrientation orientation);
262 static void gtk_default_draw_handle (GtkStyle *style,
264 GtkStateType state_type,
265 GtkShadowType shadow_type,
273 GtkOrientation orientation);
274 static void gtk_default_draw_expander (GtkStyle *style,
276 GtkStateType state_type,
282 GtkExpanderStyle expander_style);
283 static void gtk_default_draw_layout (GtkStyle *style,
285 GtkStateType state_type,
292 PangoLayout *layout);
293 static void gtk_default_draw_resize_grip (GtkStyle *style,
295 GtkStateType state_type,
305 static void gtk_style_shade (GdkColor *a,
308 static void rgb_to_hls (gdouble *r,
311 static void hls_to_rgb (gdouble *h,
317 * Data for default check and radio buttons
320 static GtkRequisition default_option_indicator_size = { 7, 13 };
321 static GtkBorder default_option_indicator_spacing = { 7, 5, 2, 2 };
323 #define INDICATOR_PART_SIZE 13
341 static char check_aa_bits[] = {
342 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x58,0x00,0xa0,
343 0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
344 static char check_base_bits[] = {
345 0x00,0x00,0x00,0x00,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,
346 0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0x00,0x00,0x00,0x00};
347 static char check_black_bits[] = {
348 0x00,0x00,0xfe,0x0f,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
349 0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x00,0x00};
350 static char check_dark_bits[] = {
351 0xff,0x1f,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
352 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00};
353 static char check_light_bits[] = {
354 0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
355 0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0xfe,0x1f};
356 static char check_mid_bits[] = {
357 0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,
358 0x08,0x00,0x08,0x00,0x08,0x00,0x08,0xfc,0x0f,0x00,0x00};
359 static char check_text_bits[] = {
360 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x03,0x80,0x01,0x80,0x00,0xd8,
361 0x00,0x60,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
362 static char radio_base_bits[] = {
363 0x00,0x00,0x00,0x00,0xf0,0x01,0xf8,0x03,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,
364 0x07,0xfc,0x07,0xf8,0x03,0xf0,0x01,0x00,0x00,0x00,0x00};
365 static char radio_black_bits[] = {
366 0x00,0x00,0xf0,0x01,0x08,0x02,0x04,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
367 0x00,0x02,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
368 static char radio_dark_bits[] = {
369 0xf0,0x01,0x08,0x02,0x04,0x04,0x02,0x04,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
370 0x00,0x01,0x00,0x02,0x00,0x0c,0x00,0x00,0x00,0x00,0x00};
371 static char radio_light_bits[] = {
372 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
373 0x10,0x00,0x10,0x00,0x08,0x00,0x04,0x08,0x02,0xf0,0x01};
374 static char radio_mid_bits[] = {
375 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,
376 0x08,0x00,0x08,0x00,0x04,0x00,0x02,0xf0,0x01,0x00,0x00};
377 static char radio_text_bits[] = {
378 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x00,0xf0,0x01,0xf0,0x01,0xf0,
379 0x01,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
384 } indicator_parts[] = {
385 { check_aa_bits, NULL },
386 { check_base_bits, NULL },
387 { check_black_bits, NULL },
388 { check_dark_bits, NULL },
389 { check_light_bits, NULL },
390 { check_mid_bits, NULL },
391 { check_text_bits, NULL },
392 { radio_base_bits, NULL },
393 { radio_black_bits, NULL },
394 { radio_dark_bits, NULL },
395 { radio_light_bits, NULL },
396 { radio_mid_bits, NULL },
397 { radio_text_bits, NULL }
400 /* --- variables --- */
401 static GdkColor gtk_default_normal_fg = { 0, 0, 0, 0 };
402 static GdkColor gtk_default_active_fg = { 0, 0, 0, 0 };
403 static GdkColor gtk_default_prelight_fg = { 0, 0, 0, 0 };
404 static GdkColor gtk_default_selected_fg = { 0, 0xffff, 0xffff, 0xffff };
405 static GdkColor gtk_default_insensitive_fg = { 0, 0x7530, 0x7530, 0x7530 };
407 static GdkColor gtk_default_normal_bg = { 0, 0xd6d6, 0xd6d6, 0xd6d6 };
408 static GdkColor gtk_default_active_bg = { 0, 0xc350, 0xc350, 0xc350 };
409 static GdkColor gtk_default_prelight_bg = { 0, 0xea60, 0xea60, 0xea60 };
410 static GdkColor gtk_default_selected_bg = { 0, 0, 0, 0x9c40 };
411 static GdkColor gtk_default_insensitive_bg = { 0, 0xd6d6, 0xd6d6, 0xd6d6 };
412 static GdkColor gtk_default_selected_base = { 0, 0xa4a4, 0xdfdf, 0xffff };
413 static GdkColor gtk_default_active_base = { 0, 0xbcbc, 0xd2d2, 0xeeee };
415 static gpointer parent_class = NULL;
418 /* --- functions --- */
420 gtk_style_get_type (void)
422 static GType style_type = 0;
426 static const GTypeInfo style_info =
428 sizeof (GtkStyleClass),
429 (GBaseInitFunc) NULL,
430 (GBaseFinalizeFunc) NULL,
431 (GClassInitFunc) gtk_style_class_init,
432 NULL, /* class_finalize */
433 NULL, /* class_data */
436 (GInstanceInitFunc) gtk_style_init,
439 style_type = g_type_register_static (G_TYPE_OBJECT,
448 gtk_style_init (GtkStyle *style)
452 style->font_desc = pango_font_description_from_string ("Sans 10");
454 style->attach_count = 0;
455 style->colormap = NULL;
458 style->black.red = 0;
459 style->black.green = 0;
460 style->black.blue = 0;
462 style->white.red = 65535;
463 style->white.green = 65535;
464 style->white.blue = 65535;
466 style->black_gc = NULL;
467 style->white_gc = NULL;
469 style->fg[GTK_STATE_NORMAL] = gtk_default_normal_fg;
470 style->fg[GTK_STATE_ACTIVE] = gtk_default_active_fg;
471 style->fg[GTK_STATE_PRELIGHT] = gtk_default_prelight_fg;
472 style->fg[GTK_STATE_SELECTED] = gtk_default_selected_fg;
473 style->fg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
475 style->bg[GTK_STATE_NORMAL] = gtk_default_normal_bg;
476 style->bg[GTK_STATE_ACTIVE] = gtk_default_active_bg;
477 style->bg[GTK_STATE_PRELIGHT] = gtk_default_prelight_bg;
478 style->bg[GTK_STATE_SELECTED] = gtk_default_selected_bg;
479 style->bg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg;
481 for (i = 0; i < 4; i++)
483 style->text[i] = style->fg[i];
484 style->base[i] = style->white;
487 style->base[GTK_STATE_SELECTED] = gtk_default_selected_base;
488 style->text[GTK_STATE_SELECTED] = style->black;
489 style->base[GTK_STATE_ACTIVE] = gtk_default_active_base;
490 style->text[GTK_STATE_ACTIVE] = style->black;
491 style->base[GTK_STATE_INSENSITIVE] = gtk_default_prelight_bg;
492 style->text[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
494 for (i = 0; i < 5; i++)
495 style->bg_pixmap[i] = NULL;
497 style->rc_style = NULL;
499 for (i = 0; i < 5; i++)
501 style->fg_gc[i] = NULL;
502 style->bg_gc[i] = NULL;
503 style->light_gc[i] = NULL;
504 style->dark_gc[i] = NULL;
505 style->mid_gc[i] = NULL;
506 style->text_gc[i] = NULL;
507 style->base_gc[i] = NULL;
508 style->text_aa_gc[i] = NULL;
511 style->xthickness = 2;
512 style->ythickness = 2;
514 style->property_cache = NULL;
518 gtk_style_class_init (GtkStyleClass *klass)
520 GObjectClass *object_class = G_OBJECT_CLASS (klass);
522 parent_class = g_type_class_peek_parent (klass);
524 object_class->finalize = gtk_style_finalize;
526 klass->clone = gtk_style_real_clone;
527 klass->copy = gtk_style_real_copy;
528 klass->init_from_rc = gtk_style_real_init_from_rc;
529 klass->realize = gtk_style_real_realize;
530 klass->unrealize = gtk_style_real_unrealize;
531 klass->set_background = gtk_style_real_set_background;
532 klass->render_icon = gtk_default_render_icon;
534 klass->draw_hline = gtk_default_draw_hline;
535 klass->draw_vline = gtk_default_draw_vline;
536 klass->draw_shadow = gtk_default_draw_shadow;
537 klass->draw_polygon = gtk_default_draw_polygon;
538 klass->draw_arrow = gtk_default_draw_arrow;
539 klass->draw_diamond = gtk_default_draw_diamond;
540 klass->draw_string = gtk_default_draw_string;
541 klass->draw_box = gtk_default_draw_box;
542 klass->draw_flat_box = gtk_default_draw_flat_box;
543 klass->draw_check = gtk_default_draw_check;
544 klass->draw_option = gtk_default_draw_option;
545 klass->draw_tab = gtk_default_draw_tab;
546 klass->draw_shadow_gap = gtk_default_draw_shadow_gap;
547 klass->draw_box_gap = gtk_default_draw_box_gap;
548 klass->draw_extension = gtk_default_draw_extension;
549 klass->draw_focus = gtk_default_draw_focus;
550 klass->draw_slider = gtk_default_draw_slider;
551 klass->draw_handle = gtk_default_draw_handle;
552 klass->draw_expander = gtk_default_draw_expander;
553 klass->draw_layout = gtk_default_draw_layout;
554 klass->draw_resize_grip = gtk_default_draw_resize_grip;
558 clear_property_cache (GtkStyle *style)
560 if (style->property_cache)
564 for (i = 0; i < style->property_cache->len; i++)
566 PropertyValue *node = &g_array_index (style->property_cache, PropertyValue, i);
568 g_param_spec_unref (node->pspec);
569 g_value_unset (&node->value);
571 g_array_free (style->property_cache, TRUE);
572 style->property_cache = NULL;
577 gtk_style_finalize (GObject *object)
579 GtkStyle *style = GTK_STYLE (object);
581 g_return_if_fail (style->attach_count == 0);
583 clear_property_cache (style);
587 if (style->styles->data != style)
588 g_slist_remove (style->styles, style);
591 GSList *tmp_list = style->styles->next;
595 GTK_STYLE (tmp_list->data)->styles = style->styles->next;
596 tmp_list = tmp_list->next;
598 g_slist_free_1 (style->styles);
602 pango_font_description_free (style->font_desc);
604 if (style->private_font)
605 gdk_font_unref (style->private_font);
607 if (style->private_font_desc)
608 pango_font_description_free (style->private_font_desc);
611 gtk_rc_style_unref (style->rc_style);
613 G_OBJECT_CLASS (parent_class)->finalize (object);
618 gtk_style_copy (GtkStyle *style)
622 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
624 new_style = GTK_STYLE_GET_CLASS (style)->clone (style);
625 GTK_STYLE_GET_CLASS (style)->copy (new_style, style);
631 gtk_style_duplicate (GtkStyle *style)
635 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
637 new_style = gtk_style_copy (style);
639 style->styles = g_slist_append (style->styles, new_style);
640 new_style->styles = style->styles;
650 style = g_object_new (GTK_TYPE_STYLE, NULL);
657 * @style: a #GtkStyle.
658 * @window: a #GtkWindow.
659 * @returns: Either @style, or a newly-created #GtkStyle.
660 * If the style is newly created, the style parameter
661 * will be dereferenced, and the new style will have
662 * a reference count belonging to the caller.
664 * Attaches a style to a window; this process allocates the
665 * colors and creates the GC's for the style - it specializes
666 * it to a particular visual and colormap. The process may
667 * involve the creation of a new style if the style has already
668 * been attached to a window with a different style and colormap.
671 * FIXME: The sequence -
672 * create a style => s1
673 * attach s1 to v1, c1 => s1
674 * attach s1 to v2, c2 => s2
675 * detach s1 from v1, c1
676 * attach s1 to v2, c2 => s3
677 * results in two separate, unlinked styles s2 and s3 which
678 * are identical and could be shared. To fix this, we would
679 * want to never remove a style from the list of linked
680 * styles as long as as it has a reference count. However, the
681 * disadvantage of doing it this way means that we would need two
682 * passes through the linked list when attaching (one to check for
683 * matching styles, one to look for empty unattached styles - but
684 * it will almost never be longer than 2 elements.
687 gtk_style_attach (GtkStyle *style,
691 GtkStyle *new_style = NULL;
692 GdkColormap *colormap;
694 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
695 g_return_val_if_fail (window != NULL, NULL);
697 colormap = gdk_window_get_colormap (window);
700 style->styles = g_slist_append (NULL, style);
702 styles = style->styles;
705 new_style = styles->data;
707 if (new_style->attach_count == 0)
709 gtk_style_realize (new_style, colormap);
712 else if (new_style->colormap == colormap)
716 styles = styles->next;
721 new_style = gtk_style_duplicate (style);
722 gtk_style_realize (new_style, colormap);
725 /* A style gets a refcount from being attached */
726 if (new_style->attach_count == 0)
727 g_object_ref (new_style);
729 /* Another refcount belongs to the parent */
730 if (style != new_style)
732 g_object_unref (style);
733 g_object_ref (new_style);
736 new_style->attach_count++;
742 gtk_style_detach (GtkStyle *style)
744 g_return_if_fail (GTK_IS_STYLE (style));
746 style->attach_count -= 1;
747 if (style->attach_count == 0)
749 GTK_STYLE_GET_CLASS (style)->unrealize (style);
751 gdk_colormap_unref (style->colormap);
752 style->colormap = NULL;
754 g_object_unref (style);
759 gtk_style_ref (GtkStyle *style)
761 return (GtkStyle *) g_object_ref (G_OBJECT (style));
765 gtk_style_unref (GtkStyle *style)
767 g_object_unref (G_OBJECT (style));
771 gtk_style_realize (GtkStyle *style,
772 GdkColormap *colormap)
774 g_return_if_fail (GTK_IS_STYLE (style));
775 g_return_if_fail (GDK_IS_COLORMAP (colormap));
777 style->colormap = gdk_colormap_ref (colormap);
778 style->depth = gdk_colormap_get_visual (colormap)->depth;
780 GTK_STYLE_GET_CLASS (style)->realize (style);
784 gtk_style_lookup_icon_set (GtkStyle *style,
785 const char *stock_id)
789 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
790 g_return_val_if_fail (stock_id != NULL, NULL);
792 iter = style->icon_factories;
795 GtkIconSet *icon_set = gtk_icon_factory_lookup (GTK_ICON_FACTORY (iter->data),
800 iter = g_slist_next (iter);
803 return gtk_icon_factory_lookup_default (stock_id);
807 gtk_draw_hline (GtkStyle *style,
809 GtkStateType state_type,
814 g_return_if_fail (GTK_IS_STYLE (style));
815 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
817 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, NULL, NULL, NULL, x1, x2, y);
822 gtk_draw_vline (GtkStyle *style,
824 GtkStateType state_type,
829 g_return_if_fail (GTK_IS_STYLE (style));
830 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
832 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, NULL, NULL, NULL, y1, y2, x);
837 gtk_draw_shadow (GtkStyle *style,
839 GtkStateType state_type,
840 GtkShadowType shadow_type,
846 g_return_if_fail (GTK_IS_STYLE (style));
847 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
849 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
853 gtk_draw_polygon (GtkStyle *style,
855 GtkStateType state_type,
856 GtkShadowType shadow_type,
861 g_return_if_fail (GTK_IS_STYLE (style));
862 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_polygon != NULL);
864 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, NULL, NULL, NULL, points, npoints, fill);
868 gtk_draw_arrow (GtkStyle *style,
870 GtkStateType state_type,
871 GtkShadowType shadow_type,
872 GtkArrowType arrow_type,
879 g_return_if_fail (GTK_IS_STYLE (style));
880 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
882 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, NULL, NULL, NULL, arrow_type, fill, x, y, width, height);
887 gtk_draw_diamond (GtkStyle *style,
889 GtkStateType state_type,
890 GtkShadowType shadow_type,
896 g_return_if_fail (GTK_IS_STYLE (style));
897 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
899 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
904 gtk_draw_string (GtkStyle *style,
906 GtkStateType state_type,
911 g_return_if_fail (GTK_IS_STYLE (style));
912 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
914 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, NULL, NULL, NULL, x, y, string);
918 gtk_draw_box (GtkStyle *style,
920 GtkStateType state_type,
921 GtkShadowType shadow_type,
927 g_return_if_fail (GTK_IS_STYLE (style));
928 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
930 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
934 gtk_draw_flat_box (GtkStyle *style,
936 GtkStateType state_type,
937 GtkShadowType shadow_type,
943 g_return_if_fail (GTK_IS_STYLE (style));
944 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
946 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
950 gtk_draw_check (GtkStyle *style,
952 GtkStateType state_type,
953 GtkShadowType shadow_type,
959 g_return_if_fail (GTK_IS_STYLE (style));
960 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
962 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
966 gtk_draw_option (GtkStyle *style,
968 GtkStateType state_type,
969 GtkShadowType shadow_type,
975 g_return_if_fail (GTK_IS_STYLE (style));
976 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
978 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
982 gtk_draw_tab (GtkStyle *style,
984 GtkStateType state_type,
985 GtkShadowType shadow_type,
991 g_return_if_fail (GTK_IS_STYLE (style));
992 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
994 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
998 gtk_draw_shadow_gap (GtkStyle *style,
1000 GtkStateType state_type,
1001 GtkShadowType shadow_type,
1006 GtkPositionType gap_side,
1010 g_return_if_fail (GTK_IS_STYLE (style));
1011 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
1013 GTK_STYLE_GET_CLASS (style)->draw_shadow_gap (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side, gap_x, gap_width);
1017 gtk_draw_box_gap (GtkStyle *style,
1019 GtkStateType state_type,
1020 GtkShadowType shadow_type,
1025 GtkPositionType gap_side,
1029 g_return_if_fail (GTK_IS_STYLE (style));
1030 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
1032 GTK_STYLE_GET_CLASS (style)->draw_box_gap (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side, gap_x, gap_width);
1036 gtk_draw_extension (GtkStyle *style,
1038 GtkStateType state_type,
1039 GtkShadowType shadow_type,
1044 GtkPositionType gap_side)
1046 g_return_if_fail (GTK_IS_STYLE (style));
1047 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
1049 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side);
1053 gtk_draw_focus (GtkStyle *style,
1060 g_return_if_fail (GTK_IS_STYLE (style));
1061 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
1063 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, GTK_STATE_NORMAL, NULL, NULL, NULL, x, y, width, height);
1067 gtk_draw_slider (GtkStyle *style,
1069 GtkStateType state_type,
1070 GtkShadowType shadow_type,
1075 GtkOrientation orientation)
1077 g_return_if_fail (GTK_IS_STYLE (style));
1078 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
1080 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
1084 gtk_draw_handle (GtkStyle *style,
1086 GtkStateType state_type,
1087 GtkShadowType shadow_type,
1092 GtkOrientation orientation)
1094 g_return_if_fail (GTK_IS_STYLE (style));
1095 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
1097 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
1101 gtk_draw_expander (GtkStyle *style,
1103 GtkStateType state_type,
1106 GtkExpanderStyle expander_style)
1108 g_return_if_fail (GTK_IS_STYLE (style));
1109 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
1111 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type,
1113 x, y, expander_style);
1117 gtk_draw_layout (GtkStyle *style,
1119 GtkStateType state_type,
1123 PangoLayout *layout)
1125 g_return_if_fail (GTK_IS_STYLE (style));
1126 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
1128 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text,
1134 gtk_draw_resize_grip (GtkStyle *style,
1136 GtkStateType state_type,
1143 g_return_if_fail (GTK_IS_STYLE (style));
1144 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
1146 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
1149 x, y, width, height);
1154 gtk_style_set_background (GtkStyle *style,
1156 GtkStateType state_type)
1158 g_return_if_fail (GTK_IS_STYLE (style));
1159 g_return_if_fail (window != NULL);
1161 GTK_STYLE_GET_CLASS (style)->set_background (style, window, state_type);
1164 /* Default functions */
1166 gtk_style_real_clone (GtkStyle *style)
1168 return GTK_STYLE (g_object_new (G_OBJECT_TYPE (style), NULL));
1172 gtk_style_real_copy (GtkStyle *style,
1177 for (i = 0; i < 5; i++)
1179 style->fg[i] = src->fg[i];
1180 style->bg[i] = src->bg[i];
1181 style->text[i] = src->text[i];
1182 style->base[i] = src->base[i];
1184 style->bg_pixmap[i] = src->bg_pixmap[i];
1187 if (style->private_font)
1188 gdk_font_unref (style->private_font);
1189 style->private_font = src->private_font;
1190 if (style->private_font)
1191 gdk_font_ref (style->private_font);
1193 if (style->font_desc)
1194 pango_font_description_free (style->font_desc);
1196 style->font_desc = pango_font_description_copy (src->font_desc);
1198 style->font_desc = NULL;
1200 style->xthickness = src->xthickness;
1201 style->ythickness = src->ythickness;
1203 if (style->rc_style)
1204 gtk_rc_style_unref (style->rc_style);
1205 style->rc_style = src->rc_style;
1207 gtk_rc_style_ref (src->rc_style);
1209 /* don't copy, just clear cache */
1210 clear_property_cache (style);
1214 gtk_style_real_init_from_rc (GtkStyle *style,
1215 GtkRcStyle *rc_style)
1219 /* cache _should_ be still empty */
1220 clear_property_cache (style);
1222 if (rc_style->font_desc)
1224 pango_font_description_free (style->font_desc);
1225 style->font_desc = pango_font_description_copy (rc_style->font_desc);
1228 for (i = 0; i < 5; i++)
1230 if (rc_style->color_flags[i] & GTK_RC_FG)
1231 style->fg[i] = rc_style->fg[i];
1232 if (rc_style->color_flags[i] & GTK_RC_BG)
1233 style->bg[i] = rc_style->bg[i];
1234 if (rc_style->color_flags[i] & GTK_RC_TEXT)
1235 style->text[i] = rc_style->text[i];
1236 if (rc_style->color_flags[i] & GTK_RC_BASE)
1237 style->base[i] = rc_style->base[i];
1240 if (rc_style->xthickness >= 0)
1241 style->xthickness = rc_style->xthickness;
1242 if (rc_style->ythickness >= 0)
1243 style->ythickness = rc_style->ythickness;
1245 if (rc_style->icon_factories)
1249 style->icon_factories = g_slist_copy (rc_style->icon_factories);
1251 iter = style->icon_factories;
1252 while (iter != NULL)
1254 g_object_ref (G_OBJECT (iter->data));
1256 iter = g_slist_next (iter);
1262 style_property_values_cmp (gconstpointer bsearch_node1,
1263 gconstpointer bsearch_node2)
1265 const PropertyValue *val1 = bsearch_node1;
1266 const PropertyValue *val2 = bsearch_node2;
1268 if (val1->widget_type == val2->widget_type)
1269 return val1->pspec < val2->pspec ? -1 : val1->pspec == val2->pspec ? 0 : 1;
1271 return val1->widget_type < val2->widget_type ? -1 : 1;
1275 _gtk_style_peek_property_value (GtkStyle *style,
1278 GtkRcPropertyParser parser)
1280 PropertyValue *pcache, key = { 0, NULL, { 0, } };
1281 const GtkRcProperty *rcprop = NULL;
1284 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1285 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), NULL);
1286 g_return_val_if_fail (g_type_is_a (pspec->owner_type, GTK_TYPE_WIDGET), NULL);
1287 g_return_val_if_fail (g_type_is_a (widget_type, pspec->owner_type), NULL);
1289 key.widget_type = widget_type;
1292 /* need value cache array */
1293 if (!style->property_cache)
1294 style->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
1297 pcache = bsearch (&key,
1298 style->property_cache->data, style->property_cache->len,
1299 sizeof (PropertyValue), style_property_values_cmp);
1301 return &pcache->value;
1305 while (i < style->property_cache->len &&
1306 style_property_values_cmp (&key, &g_array_index (style->property_cache, PropertyValue, i)) >= 0)
1309 g_array_insert_val (style->property_cache, i, key);
1310 pcache = &g_array_index (style->property_cache, PropertyValue, i);
1312 /* cache miss, initialize value type, then set contents */
1313 g_param_spec_ref (pcache->pspec);
1314 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1316 /* value provided by rc style? */
1317 if (style->rc_style)
1319 GQuark prop_quark = g_quark_from_string (pspec->name);
1323 rcprop = _gtk_rc_style_lookup_rc_property (style->rc_style,
1324 g_type_qname (widget_type),
1328 widget_type = g_type_parent (widget_type);
1330 while (g_type_is_a (widget_type, pspec->owner_type));
1333 /* when supplied by rc style, we need to convert */
1334 if (rcprop && !_gtk_settings_parse_convert (parser, &rcprop->value,
1335 pspec, &pcache->value))
1337 gchar *contents = g_strdup_value_contents (&rcprop->value);
1339 g_message ("%s: failed to retrieve property `%s::%s' of type `%s' from rc file value \"%s\" of type `%s'",
1341 g_type_name (pspec->owner_type), pspec->name,
1342 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1344 G_VALUE_TYPE_NAME (&rcprop->value));
1346 rcprop = NULL; /* needs default */
1349 /* not supplied by rc style (or conversion failed), revert to default */
1351 g_param_value_set_default (pspec, &pcache->value);
1353 return &pcache->value;
1357 load_bg_image (GdkColormap *colormap,
1359 const gchar *filename)
1361 if (strcmp (filename, "<parent>") == 0)
1362 return (GdkPixmap*) GDK_PARENT_RELATIVE;
1365 return gdk_pixmap_colormap_create_from_xpm (NULL, colormap, NULL,
1372 gtk_style_real_realize (GtkStyle *style)
1374 GdkGCValues gc_values;
1375 GdkGCValuesMask gc_values_mask;
1379 for (i = 0; i < 5; i++)
1381 gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT);
1382 gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT);
1384 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
1385 style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
1386 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
1388 style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
1389 style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
1390 style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;
1393 gdk_color_black (style->colormap, &style->black);
1394 gdk_color_white (style->colormap, &style->white);
1396 gc_values_mask = GDK_GC_FOREGROUND;
1398 gc_values.foreground = style->black;
1399 style->black_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1401 gc_values.foreground = style->white;
1402 style->white_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1404 for (i = 0; i < 5; i++)
1406 if (style->rc_style && style->rc_style->bg_pixmap_name[i])
1407 style->bg_pixmap[i] = load_bg_image (style->colormap,
1409 style->rc_style->bg_pixmap_name[i]);
1411 if (!gdk_color_alloc (style->colormap, &style->fg[i]))
1412 g_warning ("unable to allocate color: ( %d %d %d )",
1413 style->fg[i].red, style->fg[i].green, style->fg[i].blue);
1414 if (!gdk_color_alloc (style->colormap, &style->bg[i]))
1415 g_warning ("unable to allocate color: ( %d %d %d )",
1416 style->bg[i].red, style->bg[i].green, style->bg[i].blue);
1417 if (!gdk_color_alloc (style->colormap, &style->light[i]))
1418 g_warning ("unable to allocate color: ( %d %d %d )",
1419 style->light[i].red, style->light[i].green, style->light[i].blue);
1420 if (!gdk_color_alloc (style->colormap, &style->dark[i]))
1421 g_warning ("unable to allocate color: ( %d %d %d )",
1422 style->dark[i].red, style->dark[i].green, style->dark[i].blue);
1423 if (!gdk_color_alloc (style->colormap, &style->mid[i]))
1424 g_warning ("unable to allocate color: ( %d %d %d )",
1425 style->mid[i].red, style->mid[i].green, style->mid[i].blue);
1426 if (!gdk_color_alloc (style->colormap, &style->text[i]))
1427 g_warning ("unable to allocate color: ( %d %d %d )",
1428 style->text[i].red, style->text[i].green, style->text[i].blue);
1429 if (!gdk_color_alloc (style->colormap, &style->base[i]))
1430 g_warning ("unable to allocate color: ( %d %d %d )",
1431 style->base[i].red, style->base[i].green, style->base[i].blue);
1432 if (!gdk_color_alloc (style->colormap, &style->text_aa[i]))
1433 g_warning ("unable to allocate color: ( %d %d %d )",
1434 style->text_aa[i].red, style->text_aa[i].green, style->text_aa[i].blue);
1436 gc_values.foreground = style->fg[i];
1437 style->fg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1439 gc_values.foreground = style->bg[i];
1440 style->bg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1442 gc_values.foreground = style->light[i];
1443 style->light_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1445 gc_values.foreground = style->dark[i];
1446 style->dark_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1448 gc_values.foreground = style->mid[i];
1449 style->mid_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1451 gc_values.foreground = style->text[i];
1452 style->text_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1454 gc_values.foreground = style->base[i];
1455 style->base_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1457 gc_values.foreground = style->text_aa[i];
1458 style->text_aa_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1463 gtk_style_real_unrealize (GtkStyle *style)
1467 gtk_gc_release (style->black_gc);
1468 gtk_gc_release (style->white_gc);
1470 for (i = 0; i < 5; i++)
1472 gtk_gc_release (style->fg_gc[i]);
1473 gtk_gc_release (style->bg_gc[i]);
1474 gtk_gc_release (style->light_gc[i]);
1475 gtk_gc_release (style->dark_gc[i]);
1476 gtk_gc_release (style->mid_gc[i]);
1477 gtk_gc_release (style->text_gc[i]);
1478 gtk_gc_release (style->base_gc[i]);
1479 gtk_gc_release (style->text_aa_gc[i]);
1481 if (style->bg_pixmap[i] && style->bg_pixmap[i] != (GdkPixmap*) GDK_PARENT_RELATIVE)
1482 gdk_pixmap_unref (style->bg_pixmap[i]);
1485 gdk_colormap_free_colors (style->colormap, style->fg, 5);
1486 gdk_colormap_free_colors (style->colormap, style->bg, 5);
1487 gdk_colormap_free_colors (style->colormap, style->light, 5);
1488 gdk_colormap_free_colors (style->colormap, style->dark, 5);
1489 gdk_colormap_free_colors (style->colormap, style->mid, 5);
1490 gdk_colormap_free_colors (style->colormap, style->text, 5);
1491 gdk_colormap_free_colors (style->colormap, style->base, 5);
1492 gdk_colormap_free_colors (style->colormap, style->text_aa, 5);
1496 gtk_style_real_set_background (GtkStyle *style,
1498 GtkStateType state_type)
1501 gint parent_relative;
1503 if (style->bg_pixmap[state_type])
1505 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1508 parent_relative = TRUE;
1512 pixmap = style->bg_pixmap[state_type];
1513 parent_relative = FALSE;
1516 gdk_window_set_back_pixmap (window, pixmap, parent_relative);
1519 gdk_window_set_background (window, &style->bg[state_type]);
1523 gtk_style_render_icon (GtkStyle *style,
1524 const GtkIconSource *source,
1525 GtkTextDirection direction,
1529 const gchar *detail)
1533 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1534 g_return_val_if_fail (GTK_STYLE_GET_CLASS (style)->render_icon != NULL, NULL);
1536 pixbuf = GTK_STYLE_GET_CLASS (style)->render_icon (style, source, direction, state,
1537 size, widget, detail);
1539 g_return_val_if_fail (pixbuf != NULL, NULL);
1544 /* Default functions */
1546 gtk_style_apply_default_background (GtkStyle *style,
1549 GtkStateType state_type,
1556 GdkRectangle new_rect, old_rect;
1562 old_rect.width = width;
1563 old_rect.height = height;
1565 if (!gdk_rectangle_intersect (area, &old_rect, &new_rect))
1572 new_rect.width = width;
1573 new_rect.height = height;
1576 if (!style->bg_pixmap[state_type] ||
1577 GDK_IS_PIXMAP (window) ||
1578 (!set_bg && style->bg_pixmap[state_type] != (GdkPixmap*) GDK_PARENT_RELATIVE))
1580 GdkGC *gc = style->bg_gc[state_type];
1582 if (style->bg_pixmap[state_type])
1584 gdk_gc_set_fill (gc, GDK_TILED);
1585 gdk_gc_set_tile (gc, style->bg_pixmap[state_type]);
1588 gdk_draw_rectangle (window, gc, TRUE,
1589 new_rect.x, new_rect.y, new_rect.width, new_rect.height);
1590 if (style->bg_pixmap[state_type])
1591 gdk_gc_set_fill (gc, GDK_SOLID);
1597 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1598 gdk_window_set_back_pixmap (window, NULL, TRUE);
1600 gdk_window_set_back_pixmap (window, style->bg_pixmap[state_type], FALSE);
1603 gdk_window_clear_area (window,
1604 new_rect.x, new_rect.y,
1605 new_rect.width, new_rect.height);
1610 scale_or_ref (GdkPixbuf *src,
1614 if (width == gdk_pixbuf_get_width (src) &&
1615 height == gdk_pixbuf_get_height (src))
1617 gdk_pixbuf_ref (src);
1622 return gdk_pixbuf_scale_simple (src,
1624 GDK_INTERP_BILINEAR);
1629 gtk_default_render_icon (GtkStyle *style,
1630 const GtkIconSource *source,
1631 GtkTextDirection direction,
1635 const gchar *detail)
1641 GdkPixbuf *base_pixbuf;
1643 /* Oddly, style can be NULL in this function, because
1644 * GtkIconSet can be used without a style and if so
1645 * it uses this function.
1648 base_pixbuf = gtk_icon_source_get_pixbuf (source);
1650 g_return_val_if_fail (base_pixbuf != NULL, NULL);
1652 if (!gtk_icon_size_lookup (size, &width, &height))
1654 g_warning (G_STRLOC ": invalid icon size `%d'", size);
1658 /* If the size was wildcarded, then scale; otherwise, leave it
1661 if (gtk_icon_source_get_size_wildcarded (source))
1662 scaled = scale_or_ref (base_pixbuf, width, height);
1664 scaled = GDK_PIXBUF (g_object_ref (G_OBJECT (base_pixbuf)));
1666 /* If the state was wildcarded, then generate a state. */
1667 if (gtk_icon_source_get_state_wildcarded (source))
1669 if (state == GTK_STATE_INSENSITIVE)
1671 stated = gdk_pixbuf_copy (scaled);
1673 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
1676 gdk_pixbuf_unref (scaled);
1678 else if (state == GTK_STATE_PRELIGHT)
1680 stated = gdk_pixbuf_copy (scaled);
1682 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
1685 gdk_pixbuf_unref (scaled);
1699 sanitize_size (GdkWindow *window,
1703 gboolean set_bg = FALSE;
1705 if ((*width == -1) && (*height == -1))
1707 set_bg = GDK_IS_WINDOW (window);
1708 gdk_window_get_size (window, width, height);
1710 else if (*width == -1)
1711 gdk_window_get_size (window, width, NULL);
1712 else if (*height == -1)
1713 gdk_window_get_size (window, NULL, height);
1719 draw_part (GdkDrawable *drawable,
1727 gdk_gc_set_clip_rectangle (gc, area);
1729 if (!indicator_parts[part].bmap)
1730 indicator_parts[part].bmap = gdk_bitmap_create_from_data (drawable,
1731 indicator_parts[part].bits,
1732 INDICATOR_PART_SIZE, INDICATOR_PART_SIZE);
1734 gdk_gc_set_ts_origin (gc, x, y);
1735 gdk_gc_set_stipple (gc, indicator_parts[part].bmap);
1736 gdk_gc_set_fill (gc, GDK_STIPPLED);
1738 gdk_draw_rectangle (drawable, gc, TRUE, x, y, INDICATOR_PART_SIZE, INDICATOR_PART_SIZE);
1740 gdk_gc_set_fill (gc, GDK_SOLID);
1743 gdk_gc_set_clip_rectangle (gc, NULL);
1747 gtk_default_draw_hline (GtkStyle *style,
1749 GtkStateType state_type,
1752 const gchar *detail,
1757 gint thickness_light;
1758 gint thickness_dark;
1761 g_return_if_fail (GTK_IS_STYLE (style));
1762 g_return_if_fail (window != NULL);
1764 thickness_light = style->ythickness / 2;
1765 thickness_dark = style->ythickness - thickness_light;
1769 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
1770 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
1773 if (detail && !strcmp (detail, "label"))
1775 if (state_type == GTK_STATE_INSENSITIVE)
1776 gdk_draw_line (window, style->white_gc, x1 + 1, y + 1, x2 + 1, y + 1);
1777 gdk_draw_line (window, style->fg_gc[state_type], x1, y, x2, y);
1781 for (i = 0; i < thickness_dark; i++)
1783 gdk_draw_line (window, style->light_gc[state_type], x2 - i - 1, y + i, x2, y + i);
1784 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x2 - i - 1, y + i);
1787 y += thickness_dark;
1788 for (i = 0; i < thickness_light; i++)
1790 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x1 + thickness_light - i - 1, y + i);
1791 gdk_draw_line (window, style->light_gc[state_type], x1 + thickness_light - i - 1, y + i, x2, y + i);
1797 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
1798 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
1804 gtk_default_draw_vline (GtkStyle *style,
1806 GtkStateType state_type,
1809 const gchar *detail,
1814 gint thickness_light;
1815 gint thickness_dark;
1818 g_return_if_fail (GTK_IS_STYLE (style));
1819 g_return_if_fail (window != NULL);
1821 thickness_light = style->xthickness / 2;
1822 thickness_dark = style->xthickness - thickness_light;
1826 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
1827 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
1829 for (i = 0; i < thickness_dark; i++)
1831 gdk_draw_line (window, style->light_gc[state_type], x + i, y2 - i - 1, x + i, y2);
1832 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y2 - i - 1);
1835 x += thickness_dark;
1836 for (i = 0; i < thickness_light; i++)
1838 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y1 + thickness_light - i);
1839 gdk_draw_line (window, style->light_gc[state_type], x + i, y1 + thickness_light - i, x + i, y2);
1843 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
1844 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
1850 draw_thin_shadow (GtkStyle *style,
1861 sanitize_size (window, &width, &height);
1863 gc1 = style->light_gc[state];
1864 gc2 = style->dark_gc[state];
1868 gdk_gc_set_clip_rectangle (gc1, area);
1869 gdk_gc_set_clip_rectangle (gc2, area);
1872 gdk_draw_line (window, gc1,
1873 x, y + height - 1, x + width - 1, y + height - 1);
1874 gdk_draw_line (window, gc1,
1875 x + width - 1, y, x + width - 1, y + height - 1);
1877 gdk_draw_line (window, gc2,
1878 x, y, x + width - 1, y);
1879 gdk_draw_line (window, gc2,
1880 x, y, x, y + height - 1);
1884 gdk_gc_set_clip_rectangle (gc1, NULL);
1885 gdk_gc_set_clip_rectangle (gc2, NULL);
1890 draw_spin_entry_shadow (GtkStyle *style,
1899 gint window_width, window_height;
1900 gboolean focus_inset;
1902 gdk_window_get_size (window, &window_width, &window_height);
1905 width = window_width;
1907 height = window_height;
1909 focus_inset = (width < window_width && height < window_height);
1913 gdk_gc_set_clip_rectangle (style->light_gc[state], area);
1914 gdk_gc_set_clip_rectangle (style->dark_gc[state], area);
1915 gdk_gc_set_clip_rectangle (style->black_gc, area);
1916 gdk_gc_set_clip_rectangle (style->bg_gc[state], area);
1917 gdk_gc_set_clip_rectangle (style->base_gc[state], area);
1920 gdk_draw_line (window, style->light_gc[state],
1921 x, y + height - 1, x + width - 1, y + height - 1);
1923 gdk_draw_line (window,
1924 style->base_gc[state],
1925 x + width - 1, y + 1, x + width - 1, y + height - 3);
1929 gdk_draw_line (window, style->bg_gc[state],
1930 x + 1, y + height - 2, x + width - 1, y + height - 2);
1931 gdk_draw_line (window,
1932 style->base_gc[state],
1933 x + width - 2, y + 1, x + width - 2, y + height - 3);
1935 gdk_draw_line (window, style->black_gc,
1936 x + 1, y + 1, x + width - 1, y + 1);
1937 gdk_draw_line (window, style->black_gc,
1938 x + 1, y + 1, x + 1, y + height - 2);
1941 gdk_draw_line (window, style->dark_gc[state],
1942 x, y, x + width - 1, y);
1943 gdk_draw_line (window, style->dark_gc[state],
1944 x, y, x, y + height - 1);
1948 gdk_gc_set_clip_rectangle (style->light_gc[state], NULL);
1949 gdk_gc_set_clip_rectangle (style->dark_gc[state], NULL);
1950 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
1951 gdk_gc_set_clip_rectangle (style->bg_gc[state], NULL);
1952 gdk_gc_set_clip_rectangle (style->base_gc[state], NULL);
1957 draw_spinbutton_shadow (GtkStyle *style,
1966 gint y_middle = y + height / 2;
1968 sanitize_size (window, &width, &height);
1972 gdk_gc_set_clip_rectangle (style->black_gc, area);
1973 gdk_gc_set_clip_rectangle (style->bg_gc[state], area);
1974 gdk_gc_set_clip_rectangle (style->dark_gc[state], area);
1975 gdk_gc_set_clip_rectangle (style->light_gc[state], area);
1978 gdk_draw_line (window, style->black_gc,
1979 x, y + 2, x, y + height - 3);
1980 gdk_draw_line (window, style->black_gc,
1981 x, y + 1, x + width - 2, y + 1);
1982 gdk_draw_line (window, style->black_gc,
1983 x + width - 2, y + 2, x + width - 2, y + height - 3);
1985 gdk_draw_line (window, style->bg_gc[state],
1986 x, y + height - 2, x + width - 2, y + height - 2);
1988 gdk_draw_line (window, style->dark_gc[state],
1989 x, y, x + width - 1, y);
1990 gdk_draw_line (window, style->dark_gc[state],
1991 x + 1, y_middle - 1, x + width - 3, y_middle - 1);
1992 gdk_draw_line (window, style->dark_gc[state],
1993 x + 1, y + height - 3, x + width - 3, y + height - 3);
1995 gdk_draw_line (window, style->light_gc[state],
1996 x + 1, y + 2, x + width - 3, y + 2);
1997 gdk_draw_line (window, style->light_gc[state],
1998 x + 1, y_middle, x + width - 3, y_middle);
1999 gdk_draw_line (window, style->light_gc[state],
2000 x + width - 1, y + 1, x + width - 1, y + height - 1);
2001 gdk_draw_line (window, style->light_gc[state],
2002 x, y + height - 1, x + width - 2, y + height - 1);
2006 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2007 gdk_gc_set_clip_rectangle (style->bg_gc[state], NULL);
2008 gdk_gc_set_clip_rectangle (style->dark_gc[state], NULL);
2009 gdk_gc_set_clip_rectangle (style->light_gc[state], NULL);
2014 gtk_default_draw_shadow (GtkStyle *style,
2016 GtkStateType state_type,
2017 GtkShadowType shadow_type,
2020 const gchar *detail,
2028 gint thickness_light;
2029 gint thickness_dark;
2032 g_return_if_fail (GTK_IS_STYLE (style));
2033 g_return_if_fail (window != NULL);
2035 if (shadow_type == GTK_SHADOW_IN)
2037 if (detail && (strcmp (detail, "buttondefault") == 0))
2039 sanitize_size (window, &width, &height);
2041 gdk_draw_rectangle (window, style->black_gc, FALSE,
2042 x, y, width - 1, height - 1);
2046 if (detail && strcmp (detail, "trough") == 0)
2048 draw_thin_shadow (style, window, state_type, area,
2049 x, y, width, height);
2052 else if (widget && GTK_IS_SPIN_BUTTON (widget) &&
2053 detail && strcmp (detail, "entry") == 0)
2055 draw_spin_entry_shadow (style, window, state_type, area,
2056 x, y, width, height);
2059 else if (widget && GTK_IS_SPIN_BUTTON (widget) &&
2060 detail && strcmp (detail, "spinbutton") == 0)
2062 draw_spinbutton_shadow (style, window, state_type,
2063 area, x, y, width, height);
2068 sanitize_size (window, &width, &height);
2070 switch (shadow_type)
2072 case GTK_SHADOW_NONE:
2075 case GTK_SHADOW_ETCHED_IN:
2076 gc1 = style->light_gc[state_type];
2077 gc2 = style->dark_gc[state_type];
2079 case GTK_SHADOW_OUT:
2080 case GTK_SHADOW_ETCHED_OUT:
2081 gc1 = style->dark_gc[state_type];
2082 gc2 = style->light_gc[state_type];
2088 gdk_gc_set_clip_rectangle (gc1, area);
2089 gdk_gc_set_clip_rectangle (gc2, area);
2090 if (shadow_type == GTK_SHADOW_IN ||
2091 shadow_type == GTK_SHADOW_OUT)
2093 gdk_gc_set_clip_rectangle (style->black_gc, area);
2094 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2098 switch (shadow_type)
2100 case GTK_SHADOW_NONE:
2104 /* Light around right and bottom edge */
2106 if (style->ythickness > 0)
2107 gdk_draw_line (window, gc1,
2108 x, y + height - 1, x + width - 1, y + height - 1);
2109 if (style->xthickness > 0)
2110 gdk_draw_line (window, gc1,
2111 x + width - 1, y, x + width - 1, y + height - 1);
2113 if (style->ythickness > 1)
2114 gdk_draw_line (window, style->bg_gc[state_type],
2115 x + 1, y + height - 2, x + width - 2, y + height - 2);
2116 if (style->xthickness > 1)
2117 gdk_draw_line (window, style->bg_gc[state_type],
2118 x + width - 2, y + 1, x + width - 2, y + height - 2);
2120 /* Dark around left and top */
2122 if (style->ythickness > 1)
2123 gdk_draw_line (window, style->black_gc,
2124 x + 1, y + 1, x + width - 2, y + 1);
2125 if (style->xthickness > 1)
2126 gdk_draw_line (window, style->black_gc,
2127 x + 1, y + 1, x + 1, y + height - 2);
2129 if (style->ythickness > 0)
2130 gdk_draw_line (window, gc2,
2131 x, y, x + width - 1, y);
2132 if (style->xthickness > 0)
2133 gdk_draw_line (window, gc2,
2134 x, y, x, y + height - 1);
2137 case GTK_SHADOW_OUT:
2138 /* Dark around right and bottom edge */
2140 if (style->ythickness > 0)
2142 if (style->ythickness > 1)
2144 gdk_draw_line (window, gc1,
2145 x + 1, y + height - 2, x + width - 2, y + height - 2);
2146 gdk_draw_line (window, style->black_gc,
2147 x, y + height - 1, x + width - 1, y + height - 1);
2151 gdk_draw_line (window, gc1,
2152 x + 1, y + height - 1, x + width - 1, y + height - 1);
2156 if (style->xthickness > 0)
2158 if (style->xthickness > 1)
2160 gdk_draw_line (window, gc1,
2161 x + width - 2, y + 1, x + width - 2, y + height - 2);
2163 gdk_draw_line (window, style->black_gc,
2164 x + width - 1, y, x + width - 1, y + height - 1);
2168 gdk_draw_line (window, gc1,
2169 x + width - 1, y + 1, x + width - 1, y + height - 1);
2173 /* Light around top and left */
2175 if (style->ythickness > 0)
2176 gdk_draw_line (window, gc2,
2177 x, y, x + width - 1, y);
2178 if (style->xthickness > 0)
2179 gdk_draw_line (window, gc2,
2180 x, y, x, y + height - 1);
2182 if (style->ythickness > 1)
2183 gdk_draw_line (window, style->bg_gc[state_type],
2184 x + 1, y + 1, x + width - 2, y + 1);
2185 if (style->xthickness > 1)
2186 gdk_draw_line (window, style->bg_gc[state_type],
2187 x + 1, y + 1, x + 1, y + height - 2);
2190 case GTK_SHADOW_ETCHED_IN:
2191 case GTK_SHADOW_ETCHED_OUT:
2192 if (style->xthickness > 0)
2194 if (style->xthickness > 1)
2196 thickness_light = 1;
2199 for (i = 0; i < thickness_dark; i++)
2201 gdk_draw_line (window, gc1,
2205 y + height - i - 1);
2206 gdk_draw_line (window, gc2,
2210 y + height - i - 2);
2213 for (i = 0; i < thickness_light; i++)
2215 gdk_draw_line (window, gc1,
2216 x + thickness_dark + i,
2217 y + thickness_dark + i,
2218 x + thickness_dark + i,
2219 y + height - thickness_dark - i - 1);
2220 gdk_draw_line (window, gc2,
2221 x + width - thickness_light - i - 1,
2222 y + thickness_dark + i,
2223 x + width - thickness_light - i - 1,
2224 y + height - thickness_light - 1);
2229 gdk_draw_line (window,
2230 style->dark_gc[state_type],
2231 x, y, x, y + height);
2232 gdk_draw_line (window,
2233 style->dark_gc[state_type],
2234 x + width, y, x + width, y + height);
2238 if (style->ythickness > 0)
2240 if (style->ythickness > 1)
2242 thickness_light = 1;
2245 for (i = 0; i < thickness_dark; i++)
2247 gdk_draw_line (window, gc1,
2251 y + height - i - 1);
2253 gdk_draw_line (window, gc2,
2260 for (i = 0; i < thickness_light; i++)
2262 gdk_draw_line (window, gc1,
2263 x + thickness_dark + i,
2264 y + thickness_dark + i,
2265 x + width - thickness_dark - i - 1,
2266 y + thickness_dark + i);
2268 gdk_draw_line (window, gc2,
2269 x + thickness_dark + i,
2270 y + height - thickness_light - i - 1,
2271 x + width - thickness_light - 1,
2272 y + height - thickness_light - i - 1);
2277 gdk_draw_line (window,
2278 style->dark_gc[state_type],
2279 x, y, x + width, y);
2280 gdk_draw_line (window,
2281 style->dark_gc[state_type],
2282 x, y + height, x + width, y + height);
2290 gdk_gc_set_clip_rectangle (gc1, NULL);
2291 gdk_gc_set_clip_rectangle (gc2, NULL);
2292 if (shadow_type == GTK_SHADOW_IN ||
2293 shadow_type == GTK_SHADOW_OUT)
2295 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2296 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2302 gtk_default_draw_polygon (GtkStyle *style,
2304 GtkStateType state_type,
2305 GtkShadowType shadow_type,
2308 const gchar *detail,
2313 static const gdouble pi_over_4 = G_PI_4;
2314 static const gdouble pi_3_over_4 = G_PI_4 * 3;
2324 g_return_if_fail (GTK_IS_STYLE (style));
2325 g_return_if_fail (window != NULL);
2326 g_return_if_fail (points != NULL);
2328 switch (shadow_type)
2331 gc1 = style->bg_gc[state_type];
2332 gc2 = style->dark_gc[state_type];
2333 gc3 = style->light_gc[state_type];
2334 gc4 = style->black_gc;
2336 case GTK_SHADOW_ETCHED_IN:
2337 gc1 = style->light_gc[state_type];
2338 gc2 = style->dark_gc[state_type];
2339 gc3 = style->dark_gc[state_type];
2340 gc4 = style->light_gc[state_type];
2342 case GTK_SHADOW_OUT:
2343 gc1 = style->dark_gc[state_type];
2344 gc2 = style->light_gc[state_type];
2345 gc3 = style->black_gc;
2346 gc4 = style->bg_gc[state_type];
2348 case GTK_SHADOW_ETCHED_OUT:
2349 gc1 = style->dark_gc[state_type];
2350 gc2 = style->light_gc[state_type];
2351 gc3 = style->light_gc[state_type];
2352 gc4 = style->dark_gc[state_type];
2360 gdk_gc_set_clip_rectangle (gc1, area);
2361 gdk_gc_set_clip_rectangle (gc2, area);
2362 gdk_gc_set_clip_rectangle (gc3, area);
2363 gdk_gc_set_clip_rectangle (gc4, area);
2367 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, npoints);
2371 for (i = 0; i < npoints; i++)
2373 if ((points[i].x == points[i+1].x) &&
2374 (points[i].y == points[i+1].y))
2380 angle = atan2 (points[i+1].y - points[i].y,
2381 points[i+1].x - points[i].x);
2384 if ((angle > -pi_3_over_4) && (angle < pi_over_4))
2386 if (angle > -pi_over_4)
2397 gdk_draw_line (window, gc1,
2398 points[i].x-xadjust, points[i].y-yadjust,
2399 points[i+1].x-xadjust, points[i+1].y-yadjust);
2400 gdk_draw_line (window, gc3,
2401 points[i].x, points[i].y,
2402 points[i+1].x, points[i+1].y);
2406 if ((angle < -pi_3_over_4) || (angle > pi_3_over_4))
2417 gdk_draw_line (window, gc4,
2418 points[i].x+xadjust, points[i].y+yadjust,
2419 points[i+1].x+xadjust, points[i+1].y+yadjust);
2420 gdk_draw_line (window, gc2,
2421 points[i].x, points[i].y,
2422 points[i+1].x, points[i+1].y);
2428 gdk_gc_set_clip_rectangle (gc1, NULL);
2429 gdk_gc_set_clip_rectangle (gc2, NULL);
2430 gdk_gc_set_clip_rectangle (gc3, NULL);
2431 gdk_gc_set_clip_rectangle (gc4, NULL);
2436 draw_varrow (GdkWindow *window,
2438 GtkShadowType shadow_type,
2440 GtkArrowType arrow_type,
2447 gint y_start, y_increment;
2451 gdk_gc_set_clip_rectangle (gc, area);
2453 width = width + width % 2 - 1; /* Force odd */
2455 steps = 1 + width / 2;
2457 extra = height - steps;
2459 if (arrow_type == GTK_ARROW_DOWN)
2466 y_start = y + height - 1;
2470 for (i = 0; i < extra; i++)
2472 gdk_draw_line (window, gc,
2473 x, y_start + i * y_increment,
2474 x + width - 1, y_start + i * y_increment);
2476 for (; i < height; i++)
2478 gdk_draw_line (window, gc,
2479 x + (i - extra), y_start + i * y_increment,
2480 x + width - (i - extra) - 1, y_start + i * y_increment);
2485 gdk_gc_set_clip_rectangle (gc, NULL);
2489 draw_harrow (GdkWindow *window,
2491 GtkShadowType shadow_type,
2493 GtkArrowType arrow_type,
2500 gint x_start, x_increment;
2504 gdk_gc_set_clip_rectangle (gc, area);
2506 height = height + height % 2 - 1; /* Force odd */
2508 steps = 1 + height / 2;
2510 extra = width - steps;
2512 if (arrow_type == GTK_ARROW_RIGHT)
2519 x_start = x + width - 1;
2523 for (i = 0; i < extra; i++)
2525 gdk_draw_line (window, gc,
2526 x_start + i * x_increment, y,
2527 x_start + i * x_increment, y + height - 1);
2529 for (; i < width; i++)
2531 gdk_draw_line (window, gc,
2532 x_start + i * x_increment, y + (i - extra),
2533 x_start + i * x_increment, y + height - (i - extra) - 1);
2538 gdk_gc_set_clip_rectangle (gc, NULL);
2542 gtk_default_draw_arrow (GtkStyle *style,
2545 GtkShadowType shadow,
2548 const gchar *detail,
2549 GtkArrowType arrow_type,
2556 sanitize_size (window, &width, &height);
2558 if (detail && strcmp (detail, "spinbutton") == 0)
2561 int my_height = height;
2562 int my_width = width;
2565 if (my_height > my_width)
2567 vpad_add = (my_height - my_width) / 2;
2568 my_height = my_width;
2571 hpad = my_width / 4;
2576 vpad = 2 * hpad - 1;
2583 draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
2584 x, y, my_width - hpad, my_height - vpad);
2586 else if (detail && strcmp (detail, "vscrollbar") == 0)
2588 gtk_paint_box (style, window, state, shadow, area,
2589 widget, detail, x, y, width, height);
2591 x += (width - 7) / 2;
2592 y += (height - 5) / 2;
2594 draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
2597 else if (detail && strcmp (detail, "hscrollbar") == 0)
2599 gtk_paint_box (style, window, state, shadow, area,
2600 widget, detail, x, y, width, height);
2602 y += (height - 7) / 2;
2603 x += (width - 5) / 2;
2605 draw_harrow (window, style->fg_gc[state], shadow, area, arrow_type,
2610 if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
2612 x += (width - 7) / 2;
2613 y += (height - 5) / 2;
2615 draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
2620 x += (width - 5) / 2;
2621 y += (height - 7) / 2;
2623 draw_harrow (window, style->fg_gc[state], shadow, area, arrow_type,
2630 gtk_default_draw_diamond (GtkStyle *style,
2632 GtkStateType state_type,
2633 GtkShadowType shadow_type,
2636 const gchar *detail,
2644 GdkGC *outer_nw = NULL;
2645 GdkGC *outer_ne = NULL;
2646 GdkGC *outer_sw = NULL;
2647 GdkGC *outer_se = NULL;
2648 GdkGC *middle_nw = NULL;
2649 GdkGC *middle_ne = NULL;
2650 GdkGC *middle_sw = NULL;
2651 GdkGC *middle_se = NULL;
2652 GdkGC *inner_nw = NULL;
2653 GdkGC *inner_ne = NULL;
2654 GdkGC *inner_sw = NULL;
2655 GdkGC *inner_se = NULL;
2657 g_return_if_fail (GTK_IS_STYLE (style));
2658 g_return_if_fail (window != NULL);
2660 sanitize_size (window, &width, &height);
2662 half_width = width / 2;
2663 half_height = height / 2;
2667 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
2668 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2669 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
2670 gdk_gc_set_clip_rectangle (style->black_gc, area);
2673 switch (shadow_type)
2676 inner_sw = inner_se = style->bg_gc[state_type];
2677 middle_sw = middle_se = style->light_gc[state_type];
2678 outer_sw = outer_se = style->light_gc[state_type];
2679 inner_nw = inner_ne = style->black_gc;
2680 middle_nw = middle_ne = style->dark_gc[state_type];
2681 outer_nw = outer_ne = style->dark_gc[state_type];
2684 case GTK_SHADOW_OUT:
2685 inner_sw = inner_se = style->dark_gc[state_type];
2686 middle_sw = middle_se = style->dark_gc[state_type];
2687 outer_sw = outer_se = style->black_gc;
2688 inner_nw = inner_ne = style->bg_gc[state_type];
2689 middle_nw = middle_ne = style->light_gc[state_type];
2690 outer_nw = outer_ne = style->light_gc[state_type];
2693 case GTK_SHADOW_ETCHED_IN:
2694 inner_sw = inner_se = style->bg_gc[state_type];
2695 middle_sw = middle_se = style->dark_gc[state_type];
2696 outer_sw = outer_se = style->light_gc[state_type];
2697 inner_nw = inner_ne = style->bg_gc[state_type];
2698 middle_nw = middle_ne = style->light_gc[state_type];
2699 outer_nw = outer_ne = style->dark_gc[state_type];
2702 case GTK_SHADOW_ETCHED_OUT:
2703 inner_sw = inner_se = style->bg_gc[state_type];
2704 middle_sw = middle_se = style->light_gc[state_type];
2705 outer_sw = outer_se = style->dark_gc[state_type];
2706 inner_nw = inner_ne = style->bg_gc[state_type];
2707 middle_nw = middle_ne = style->dark_gc[state_type];
2708 outer_nw = outer_ne = style->light_gc[state_type];
2718 gdk_draw_line (window, inner_sw,
2719 x + 2, y + half_height,
2720 x + half_width, y + height - 2);
2721 gdk_draw_line (window, inner_se,
2722 x + half_width, y + height - 2,
2723 x + width - 2, y + half_height);
2724 gdk_draw_line (window, middle_sw,
2725 x + 1, y + half_height,
2726 x + half_width, y + height - 1);
2727 gdk_draw_line (window, middle_se,
2728 x + half_width, y + height - 1,
2729 x + width - 1, y + half_height);
2730 gdk_draw_line (window, outer_sw,
2732 x + half_width, y + height);
2733 gdk_draw_line (window, outer_se,
2734 x + half_width, y + height,
2735 x + width, y + half_height);
2737 gdk_draw_line (window, inner_nw,
2738 x + 2, y + half_height,
2739 x + half_width, y + 2);
2740 gdk_draw_line (window, inner_ne,
2741 x + half_width, y + 2,
2742 x + width - 2, y + half_height);
2743 gdk_draw_line (window, middle_nw,
2744 x + 1, y + half_height,
2745 x + half_width, y + 1);
2746 gdk_draw_line (window, middle_ne,
2747 x + half_width, y + 1,
2748 x + width - 1, y + half_height);
2749 gdk_draw_line (window, outer_nw,
2752 gdk_draw_line (window, outer_ne,
2754 x + width, y + half_height);
2759 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
2760 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2761 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
2762 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2767 gtk_default_draw_string (GtkStyle *style,
2769 GtkStateType state_type,
2772 const gchar *detail,
2775 const gchar *string)
2777 g_return_if_fail (GTK_IS_STYLE (style));
2778 g_return_if_fail (window != NULL);
2782 gdk_gc_set_clip_rectangle (style->white_gc, area);
2783 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], area);
2786 if (state_type == GTK_STATE_INSENSITIVE)
2787 gdk_draw_string (window, gtk_style_get_font (style), style->white_gc, x + 1, y + 1, string);
2789 gdk_draw_string (window, gtk_style_get_font (style), style->fg_gc[state_type], x, y, string);
2793 gdk_gc_set_clip_rectangle (style->white_gc, NULL);
2794 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], NULL);
2799 option_menu_get_props (GtkWidget *widget,
2800 GtkRequisition *indicator_size,
2801 GtkBorder *indicator_spacing)
2803 GtkRequisition *tmp_size = NULL;
2804 GtkBorder *tmp_spacing = NULL;
2807 gtk_widget_style_get (widget,
2808 "indicator_size", &tmp_size,
2809 "indicator_spacing", &tmp_spacing,
2814 *indicator_size = *tmp_size;
2818 *indicator_size = default_option_indicator_size;
2822 *indicator_spacing = *tmp_spacing;
2823 g_free (tmp_spacing);
2826 *indicator_spacing = default_option_indicator_spacing;
2830 gtk_default_draw_box (GtkStyle *style,
2832 GtkStateType state_type,
2833 GtkShadowType shadow_type,
2836 const gchar *detail,
2842 g_return_if_fail (GTK_IS_STYLE (style));
2843 g_return_if_fail (window != NULL);
2845 sanitize_size (window, &width, &height);
2847 if (!style->bg_pixmap[state_type] ||
2848 GDK_IS_PIXMAP (window))
2851 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2853 gdk_draw_rectangle (window, style->bg_gc[state_type], TRUE,
2854 x, y, width, height);
2856 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2859 gtk_style_apply_default_background (style, window,
2860 widget && !GTK_WIDGET_NO_WINDOW (widget),
2861 state_type, area, x, y, width, height);
2863 gtk_paint_shadow (style, window, state_type, shadow_type, area, widget, detail,
2864 x, y, width, height);
2866 if (detail && strcmp (detail, "optionmenu") == 0)
2868 GtkRequisition indicator_size;
2869 GtkBorder indicator_spacing;
2871 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
2873 sanitize_size (window, &width, &height);
2875 gtk_paint_vline (style, window, state_type, area, widget,
2877 y + style->ythickness + 1,
2878 y + height - style->ythickness - 3,
2879 x + width - (indicator_size.width + indicator_spacing.left + indicator_spacing.right) - style->xthickness);
2884 get_darkened_gc (GdkWindow *window,
2888 GdkColor src = *color;
2892 gc = gdk_gc_new (window);
2894 while (darken_count)
2896 gtk_style_shade (&src, &shaded, 0.93);
2901 gdk_gc_set_rgb_fg_color (gc, &shaded);
2907 gtk_default_draw_flat_box (GtkStyle *style,
2909 GtkStateType state_type,
2910 GtkShadowType shadow_type,
2913 const gchar *detail,
2920 GdkGC *freeme = NULL;
2922 g_return_if_fail (GTK_IS_STYLE (style));
2923 g_return_if_fail (window != NULL);
2925 sanitize_size (window, &width, &height);
2929 if (state_type == GTK_STATE_SELECTED)
2931 if (!strcmp ("text", detail))
2932 gc1 = style->bg_gc[GTK_STATE_SELECTED];
2933 else if (!strncmp ("cell_even", detail, strlen ("cell_even")) ||
2934 !strncmp ("cell_odd", detail, strlen ("cell_odd")))
2936 /* This has to be really broken; alex made me do it. -jrb */
2937 if (GTK_WIDGET_HAS_FOCUS (widget))
2938 gc1 = style->base_gc[state_type];
2940 gc1 = style->base_gc[GTK_STATE_ACTIVE];
2944 gc1 = style->bg_gc[state_type];
2949 if (!strcmp ("viewportbin", detail))
2950 gc1 = style->bg_gc[GTK_STATE_NORMAL];
2951 else if (!strcmp ("entry_bg", detail))
2952 gc1 = style->base_gc[state_type];
2954 /* For trees: even rows are base color, odd rows are a shade of
2955 * the base color, the sort column is a shade of the original color
2959 /* FIXME when we have style properties, clean this up.
2962 else if (!strcmp ("cell_even", detail) ||
2963 !strcmp ("cell_odd", detail) ||
2964 !strcmp ("cell_even_ruled", detail))
2966 gc1 = style->base_gc[state_type];
2968 else if (!strcmp ("cell_even_sorted", detail) ||
2969 !strcmp ("cell_odd_sorted", detail) ||
2970 !strcmp ("cell_odd_ruled", detail) ||
2971 !strcmp ("cell_even_ruled_sorted", detail))
2973 freeme = get_darkened_gc (window, &style->base[state_type], 1);
2976 else if (!strcmp ("cell_odd_ruled_sorted", detail))
2978 freeme = get_darkened_gc (window, &style->base[state_type], 2);
2982 gc1 = style->bg_gc[state_type];
2986 gc1 = style->bg_gc[state_type];
2988 if (!style->bg_pixmap[state_type] || gc1 != style->bg_gc[state_type] ||
2989 GDK_IS_PIXMAP (window))
2992 gdk_gc_set_clip_rectangle (gc1, area);
2994 gdk_draw_rectangle (window, gc1, TRUE,
2995 x, y, width, height);
2997 if (detail && !strcmp ("tooltip", detail))
2998 gdk_draw_rectangle (window, style->black_gc, FALSE,
2999 x, y, width - 1, height - 1);
3002 gdk_gc_set_clip_rectangle (gc1, NULL);
3005 gtk_style_apply_default_background (style, window,
3006 widget && !GTK_WIDGET_NO_WINDOW (widget),
3007 state_type, area, x, y, width, height);
3011 g_object_unref (G_OBJECT (freeme));
3015 gtk_default_draw_check (GtkStyle *style,
3017 GtkStateType state_type,
3018 GtkShadowType shadow_type,
3021 const gchar *detail,
3027 if (detail && strcmp (detail, "cellcheck") == 0)
3029 gdk_draw_rectangle (window,
3030 widget->style->base_gc[state_type],
3034 gdk_draw_rectangle (window,
3035 widget->style->text_gc[state_type],
3040 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3041 y -= (((1 + INDICATOR_PART_SIZE - height) / 2) - 1);
3042 if (shadow_type == GTK_SHADOW_IN)
3044 draw_part (window, style->text_gc[state_type], area, x, y, CHECK_TEXT);
3045 draw_part (window, style->text_aa_gc[state_type], area, x, y, CHECK_AA);
3050 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3051 y -= (1 + INDICATOR_PART_SIZE - height) / 2;
3053 if (strcmp (detail, "check") == 0) /* Menu item */
3055 if (shadow_type == GTK_SHADOW_IN)
3057 draw_part (window, style->black_gc, area, x, y, CHECK_TEXT);
3058 draw_part (window, style->dark_gc[state_type], area, x, y, CHECK_AA);
3063 draw_part (window, style->black_gc, area, x, y, CHECK_BLACK);
3064 draw_part (window, style->dark_gc[state_type], area, x, y, CHECK_DARK);
3065 draw_part (window, style->mid_gc[state_type], area, x, y, CHECK_MID);
3066 draw_part (window, style->light_gc[state_type], area, x, y, CHECK_LIGHT);
3067 draw_part (window, style->base_gc[state_type], area, x, y, CHECK_BASE);
3069 if (shadow_type == GTK_SHADOW_IN)
3071 draw_part (window, style->text_gc[state_type], area, x, y, CHECK_TEXT);
3072 draw_part (window, style->text_aa_gc[state_type], area, x, y, CHECK_AA);
3080 gtk_default_draw_option (GtkStyle *style,
3082 GtkStateType state_type,
3083 GtkShadowType shadow_type,
3086 const gchar *detail,
3092 if (detail && strcmp (detail, "cellradio") == 0)
3094 gdk_draw_arc (window,
3095 widget->style->fg_gc[state_type],
3102 if (shadow_type == GTK_SHADOW_IN)
3104 gdk_draw_arc (window,
3105 widget->style->fg_gc[state_type],
3116 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3117 y -= (1 + INDICATOR_PART_SIZE - height) / 2;
3119 if (strcmp (detail, "option") == 0) /* Menu item */
3121 if (shadow_type == GTK_SHADOW_IN)
3122 draw_part (window, style->fg_gc[state_type], area, x, y, RADIO_TEXT);
3126 draw_part (window, style->black_gc, area, x, y, RADIO_BLACK);
3127 draw_part (window, style->dark_gc[state_type], area, x, y, RADIO_DARK);
3128 draw_part (window, style->mid_gc[state_type], area, x, y, RADIO_MID);
3129 draw_part (window, style->light_gc[state_type], area, x, y, RADIO_LIGHT);
3130 draw_part (window, style->base_gc[state_type], area, x, y, RADIO_BASE);
3132 if (shadow_type == GTK_SHADOW_IN)
3133 draw_part (window, style->text_gc[state_type], area, x, y, RADIO_TEXT);
3139 gtk_default_draw_tab (GtkStyle *style,
3141 GtkStateType state_type,
3142 GtkShadowType shadow_type,
3145 const gchar *detail,
3151 GtkRequisition indicator_size;
3152 GtkBorder indicator_spacing;
3154 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
3156 x += (width - indicator_size.width) / 2;
3157 y += (height - indicator_size.height) / 2 - 1;
3159 draw_varrow (window, style->black_gc, shadow_type, area, GTK_ARROW_UP,
3160 x, y, indicator_size.width, 5);
3161 draw_varrow (window, style->black_gc, shadow_type, area, GTK_ARROW_DOWN,
3162 x, y + 8, indicator_size.width, 5);
3166 gtk_default_draw_shadow_gap (GtkStyle *style,
3168 GtkStateType state_type,
3169 GtkShadowType shadow_type,
3172 const gchar *detail,
3177 GtkPositionType gap_side,
3186 g_return_if_fail (GTK_IS_STYLE (style));
3187 g_return_if_fail (window != NULL);
3189 sanitize_size (window, &width, &height);
3191 switch (shadow_type)
3193 case GTK_SHADOW_NONE:
3196 gc1 = style->dark_gc[state_type];
3197 gc2 = style->black_gc;
3198 gc3 = style->bg_gc[state_type];
3199 gc4 = style->light_gc[state_type];
3201 case GTK_SHADOW_ETCHED_IN:
3202 gc1 = style->dark_gc[state_type];
3203 gc2 = style->light_gc[state_type];
3204 gc3 = style->dark_gc[state_type];
3205 gc4 = style->light_gc[state_type];
3207 case GTK_SHADOW_OUT:
3208 gc1 = style->light_gc[state_type];
3209 gc2 = style->bg_gc[state_type];
3210 gc3 = style->dark_gc[state_type];
3211 gc4 = style->black_gc;
3213 case GTK_SHADOW_ETCHED_OUT:
3214 gc1 = style->light_gc[state_type];
3215 gc2 = style->dark_gc[state_type];
3216 gc3 = style->light_gc[state_type];
3217 gc4 = style->dark_gc[state_type];
3222 gdk_gc_set_clip_rectangle (gc1, area);
3223 gdk_gc_set_clip_rectangle (gc2, area);
3224 gdk_gc_set_clip_rectangle (gc3, area);
3225 gdk_gc_set_clip_rectangle (gc4, area);
3228 switch (shadow_type)
3230 case GTK_SHADOW_NONE:
3232 case GTK_SHADOW_OUT:
3233 case GTK_SHADOW_ETCHED_IN:
3234 case GTK_SHADOW_ETCHED_OUT:
3238 gdk_draw_line (window, gc1,
3239 x, y, x, y + height - 1);
3240 gdk_draw_line (window, gc2,
3241 x + 1, y, x + 1, y + height - 2);
3243 gdk_draw_line (window, gc3,
3244 x + 1, y + height - 2, x + width - 2, y + height - 2);
3245 gdk_draw_line (window, gc3,
3246 x + width - 2, y, x + width - 2, y + height - 2);
3247 gdk_draw_line (window, gc4,
3248 x, y + height - 1, x + width - 1, y + height - 1);
3249 gdk_draw_line (window, gc4,
3250 x + width - 1, y, x + width - 1, y + height - 1);
3253 gdk_draw_line (window, gc1,
3254 x, y, x + gap_x - 1, y);
3255 gdk_draw_line (window, gc2,
3256 x + 1, y + 1, x + gap_x - 1, y + 1);
3257 gdk_draw_line (window, gc2,
3258 x + gap_x, y, x + gap_x, y);
3260 if ((width - (gap_x + gap_width)) > 0)
3262 gdk_draw_line (window, gc1,
3263 x + gap_x + gap_width, y, x + width - 2, y);
3264 gdk_draw_line (window, gc2,
3265 x + gap_x + gap_width, y + 1, x + width - 2, y + 1);
3266 gdk_draw_line (window, gc2,
3267 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
3270 case GTK_POS_BOTTOM:
3271 gdk_draw_line (window, gc1,
3272 x, y, x + width - 1, y);
3273 gdk_draw_line (window, gc1,
3274 x, y, x, y + height - 1);
3275 gdk_draw_line (window, gc2,
3276 x + 1, y + 1, x + width - 2, y + 1);
3277 gdk_draw_line (window, gc2,
3278 x + 1, y + 1, x + 1, y + height - 1);
3280 gdk_draw_line (window, gc3,
3281 x + width - 2, y + 1, x + width - 2, y + height - 1);
3282 gdk_draw_line (window, gc4,
3283 x + width - 1, y, x + width - 1, y + height - 1);
3286 gdk_draw_line (window, gc4,
3287 x, y + height - 1, x + gap_x - 1, y + height - 1);
3288 gdk_draw_line (window, gc3,
3289 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
3290 gdk_draw_line (window, gc3,
3291 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
3293 if ((width - (gap_x + gap_width)) > 0)
3295 gdk_draw_line (window, gc4,
3296 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
3297 gdk_draw_line (window, gc3,
3298 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
3299 gdk_draw_line (window, gc3,
3300 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
3304 gdk_draw_line (window, gc1,
3305 x, y, x + width - 1, y);
3306 gdk_draw_line (window, gc2,
3307 x, y + 1, x + width - 2, y + 1);
3309 gdk_draw_line (window, gc3,
3310 x, y + height - 2, x + width - 2, y + height - 2);
3311 gdk_draw_line (window, gc3,
3312 x + width - 2, y + 1, x + width - 2, y + height - 2);
3313 gdk_draw_line (window, gc4,
3314 x, y + height - 1, x + width - 1, y + height - 1);
3315 gdk_draw_line (window, gc4,
3316 x + width - 1, y, x + width - 1, y + height - 1);
3319 gdk_draw_line (window, gc1,
3320 x, y, x, y + gap_x - 1);
3321 gdk_draw_line (window, gc2,
3322 x + 1, y + 1, x + 1, y + gap_x - 1);
3323 gdk_draw_line (window, gc2,
3324 x, y + gap_x, x, y + gap_x);
3326 if ((width - (gap_x + gap_width)) > 0)
3328 gdk_draw_line (window, gc1,
3329 x, y + gap_x + gap_width, x, y + height - 2);
3330 gdk_draw_line (window, gc2,
3331 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
3332 gdk_draw_line (window, gc2,
3333 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
3337 gdk_draw_line (window, gc1,
3338 x, y, x + width - 1, y);
3339 gdk_draw_line (window, gc1,
3340 x, y, x, y + height - 1);
3341 gdk_draw_line (window, gc2,
3342 x + 1, y + 1, x + width - 1, y + 1);
3343 gdk_draw_line (window, gc2,
3344 x + 1, y + 1, x + 1, y + height - 2);
3346 gdk_draw_line (window, gc3,
3347 x + 1, y + height - 2, x + width - 1, y + height - 2);
3348 gdk_draw_line (window, gc4,
3349 x, y + height - 1, x + width - 1, y + height - 1);
3352 gdk_draw_line (window, gc4,
3353 x + width - 1, y, x + width - 1, y + gap_x - 1);
3354 gdk_draw_line (window, gc3,
3355 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
3356 gdk_draw_line (window, gc3,
3357 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
3359 if ((width - (gap_x + gap_width)) > 0)
3361 gdk_draw_line (window, gc4,
3362 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
3363 gdk_draw_line (window, gc3,
3364 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
3365 gdk_draw_line (window, gc3,
3366 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
3374 gdk_gc_set_clip_rectangle (gc1, NULL);
3375 gdk_gc_set_clip_rectangle (gc2, NULL);
3376 gdk_gc_set_clip_rectangle (gc3, NULL);
3377 gdk_gc_set_clip_rectangle (gc4, NULL);
3382 gtk_default_draw_box_gap (GtkStyle *style,
3384 GtkStateType state_type,
3385 GtkShadowType shadow_type,
3388 const gchar *detail,
3393 GtkPositionType gap_side,
3402 g_return_if_fail (GTK_IS_STYLE (style));
3403 g_return_if_fail (window != NULL);
3405 gtk_style_apply_default_background (style, window,
3406 widget && !GTK_WIDGET_NO_WINDOW (widget),
3407 state_type, area, x, y, width, height);
3409 sanitize_size (window, &width, &height);
3411 switch (shadow_type)
3413 case GTK_SHADOW_NONE:
3416 gc1 = style->dark_gc[state_type];
3417 gc2 = style->black_gc;
3418 gc3 = style->bg_gc[state_type];
3419 gc4 = style->light_gc[state_type];
3421 case GTK_SHADOW_ETCHED_IN:
3422 gc1 = style->dark_gc[state_type];
3423 gc2 = style->light_gc[state_type];
3424 gc3 = style->dark_gc[state_type];
3425 gc4 = style->light_gc[state_type];
3427 case GTK_SHADOW_OUT:
3428 gc1 = style->light_gc[state_type];
3429 gc2 = style->bg_gc[state_type];
3430 gc3 = style->dark_gc[state_type];
3431 gc4 = style->black_gc;
3433 case GTK_SHADOW_ETCHED_OUT:
3434 gc1 = style->light_gc[state_type];
3435 gc2 = style->dark_gc[state_type];
3436 gc3 = style->light_gc[state_type];
3437 gc4 = style->dark_gc[state_type];
3443 gdk_gc_set_clip_rectangle (gc1, area);
3444 gdk_gc_set_clip_rectangle (gc2, area);
3445 gdk_gc_set_clip_rectangle (gc3, area);
3446 gdk_gc_set_clip_rectangle (gc4, area);
3449 switch (shadow_type)
3451 case GTK_SHADOW_NONE:
3453 case GTK_SHADOW_OUT:
3454 case GTK_SHADOW_ETCHED_IN:
3455 case GTK_SHADOW_ETCHED_OUT:
3459 gdk_draw_line (window, gc1,
3460 x, y, x, y + height - 1);
3461 gdk_draw_line (window, gc2,
3462 x + 1, y, x + 1, y + height - 2);
3464 gdk_draw_line (window, gc3,
3465 x + 1, y + height - 2, x + width - 2, y + height - 2);
3466 gdk_draw_line (window, gc3,
3467 x + width - 2, y, x + width - 2, y + height - 2);
3468 gdk_draw_line (window, gc4,
3469 x, y + height - 1, x + width - 1, y + height - 1);
3470 gdk_draw_line (window, gc4,
3471 x + width - 1, y, x + width - 1, y + height - 1);
3474 gdk_draw_line (window, gc1,
3475 x, y, x + gap_x - 1, y);
3476 gdk_draw_line (window, gc2,
3477 x + 1, y + 1, x + gap_x - 1, y + 1);
3478 gdk_draw_line (window, gc2,
3479 x + gap_x, y, x + gap_x, y);
3481 if ((width - (gap_x + gap_width)) > 0)
3483 gdk_draw_line (window, gc1,
3484 x + gap_x + gap_width, y, x + width - 2, y);
3485 gdk_draw_line (window, gc2,
3486 x + gap_x + gap_width, y + 1, x + width - 2, y + 1);
3487 gdk_draw_line (window, gc2,
3488 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
3491 case GTK_POS_BOTTOM:
3492 gdk_draw_line (window, gc1,
3493 x, y, x + width - 1, y);
3494 gdk_draw_line (window, gc1,
3495 x, y, x, y + height - 1);
3496 gdk_draw_line (window, gc2,
3497 x + 1, y + 1, x + width - 2, y + 1);
3498 gdk_draw_line (window, gc2,
3499 x + 1, y + 1, x + 1, y + height - 1);
3501 gdk_draw_line (window, gc3,
3502 x + width - 2, y + 1, x + width - 2, y + height - 1);
3503 gdk_draw_line (window, gc4,
3504 x + width - 1, y, x + width - 1, y + height - 1);
3507 gdk_draw_line (window, gc4,
3508 x, y + height - 1, x + gap_x - 1, y + height - 1);
3509 gdk_draw_line (window, gc3,
3510 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
3511 gdk_draw_line (window, gc3,
3512 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
3514 if ((width - (gap_x + gap_width)) > 0)
3516 gdk_draw_line (window, gc4,
3517 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
3518 gdk_draw_line (window, gc3,
3519 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
3520 gdk_draw_line (window, gc3,
3521 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
3525 gdk_draw_line (window, gc1,
3526 x, y, x + width - 1, y);
3527 gdk_draw_line (window, gc2,
3528 x, y + 1, x + width - 2, y + 1);
3530 gdk_draw_line (window, gc3,
3531 x, y + height - 2, x + width - 2, y + height - 2);
3532 gdk_draw_line (window, gc3,
3533 x + width - 2, y + 1, x + width - 2, y + height - 2);
3534 gdk_draw_line (window, gc4,
3535 x, y + height - 1, x + width - 1, y + height - 1);
3536 gdk_draw_line (window, gc4,
3537 x + width - 1, y, x + width - 1, y + height - 1);
3540 gdk_draw_line (window, gc1,
3541 x, y, x, y + gap_x - 1);
3542 gdk_draw_line (window, gc2,
3543 x + 1, y + 1, x + 1, y + gap_x - 1);
3544 gdk_draw_line (window, gc2,
3545 x, y + gap_x, x, y + gap_x);
3547 if ((width - (gap_x + gap_width)) > 0)
3549 gdk_draw_line (window, gc1,
3550 x, y + gap_x + gap_width, x, y + height - 2);
3551 gdk_draw_line (window, gc2,
3552 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
3553 gdk_draw_line (window, gc2,
3554 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
3558 gdk_draw_line (window, gc1,
3559 x, y, x + width - 1, y);
3560 gdk_draw_line (window, gc1,
3561 x, y, x, y + height - 1);
3562 gdk_draw_line (window, gc2,
3563 x + 1, y + 1, x + width - 1, y + 1);
3564 gdk_draw_line (window, gc2,
3565 x + 1, y + 1, x + 1, y + height - 2);
3567 gdk_draw_line (window, gc3,
3568 x + 1, y + height - 2, x + width - 1, y + height - 2);
3569 gdk_draw_line (window, gc4,
3570 x, y + height - 1, x + width - 1, y + height - 1);
3573 gdk_draw_line (window, gc4,
3574 x + width - 1, y, x + width - 1, y + gap_x - 1);
3575 gdk_draw_line (window, gc3,
3576 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
3577 gdk_draw_line (window, gc3,
3578 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
3580 if ((width - (gap_x + gap_width)) > 0)
3582 gdk_draw_line (window, gc4,
3583 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
3584 gdk_draw_line (window, gc3,
3585 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
3586 gdk_draw_line (window, gc3,
3587 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
3595 gdk_gc_set_clip_rectangle (gc1, NULL);
3596 gdk_gc_set_clip_rectangle (gc2, NULL);
3597 gdk_gc_set_clip_rectangle (gc3, NULL);
3598 gdk_gc_set_clip_rectangle (gc4, NULL);
3603 gtk_default_draw_extension (GtkStyle *style,
3605 GtkStateType state_type,
3606 GtkShadowType shadow_type,
3609 const gchar *detail,
3614 GtkPositionType gap_side)
3621 g_return_if_fail (GTK_IS_STYLE (style));
3622 g_return_if_fail (window != NULL);
3624 gtk_style_apply_default_background (style, window,
3625 widget && !GTK_WIDGET_NO_WINDOW (widget),
3626 GTK_STATE_NORMAL, area, x, y, width, height);
3628 sanitize_size (window, &width, &height);
3630 switch (shadow_type)
3632 case GTK_SHADOW_NONE:
3635 gc1 = style->dark_gc[state_type];
3636 gc2 = style->black_gc;
3637 gc3 = style->bg_gc[state_type];
3638 gc4 = style->light_gc[state_type];
3640 case GTK_SHADOW_ETCHED_IN:
3641 gc1 = style->dark_gc[state_type];
3642 gc2 = style->light_gc[state_type];
3643 gc3 = style->dark_gc[state_type];
3644 gc4 = style->light_gc[state_type];
3646 case GTK_SHADOW_OUT:
3647 gc1 = style->light_gc[state_type];
3648 gc2 = style->bg_gc[state_type];
3649 gc3 = style->dark_gc[state_type];
3650 gc4 = style->black_gc;
3652 case GTK_SHADOW_ETCHED_OUT:
3653 gc1 = style->light_gc[state_type];
3654 gc2 = style->dark_gc[state_type];
3655 gc3 = style->light_gc[state_type];
3656 gc4 = style->dark_gc[state_type];
3662 gdk_gc_set_clip_rectangle (gc1, area);
3663 gdk_gc_set_clip_rectangle (gc2, area);
3664 gdk_gc_set_clip_rectangle (gc3, area);
3665 gdk_gc_set_clip_rectangle (gc4, area);
3668 switch (shadow_type)
3670 case GTK_SHADOW_NONE:
3672 case GTK_SHADOW_OUT:
3673 case GTK_SHADOW_ETCHED_IN:
3674 case GTK_SHADOW_ETCHED_OUT:
3678 gtk_style_apply_default_background (style, window,
3679 widget && !GTK_WIDGET_NO_WINDOW (widget),
3681 x + style->xthickness,
3683 width - (2 * style->xthickness),
3684 height - (style->ythickness));
3685 gdk_draw_line (window, gc1,
3686 x, y, x, y + height - 2);
3687 gdk_draw_line (window, gc2,
3688 x + 1, y, x + 1, y + height - 2);
3690 gdk_draw_line (window, gc3,
3691 x + 2, y + height - 2, x + width - 2, y + height - 2);
3692 gdk_draw_line (window, gc3,
3693 x + width - 2, y, x + width - 2, y + height - 2);
3694 gdk_draw_line (window, gc4,
3695 x + 1, y + height - 1, x + width - 2, y + height - 1);
3696 gdk_draw_line (window, gc4,
3697 x + width - 1, y, x + width - 1, y + height - 2);
3699 case GTK_POS_BOTTOM:
3700 gtk_style_apply_default_background (style, window,
3701 widget && !GTK_WIDGET_NO_WINDOW (widget),
3703 x + style->xthickness,
3704 y + style->ythickness,
3705 width - (2 * style->xthickness),
3706 height - (style->ythickness));
3707 gdk_draw_line (window, gc1,
3708 x + 1, y, x + width - 2, y);
3709 gdk_draw_line (window, gc1,
3710 x, y + 1, x, y + height - 1);
3711 gdk_draw_line (window, gc2,
3712 x + 1, y + 1, x + width - 2, y + 1);
3713 gdk_draw_line (window, gc2,
3714 x + 1, y + 1, x + 1, y + height - 1);
3716 gdk_draw_line (window, gc3,
3717 x + width - 2, y + 2, x + width - 2, y + height - 1);
3718 gdk_draw_line (window, gc4,
3719 x + width - 1, y + 1, x + width - 1, y + height - 1);
3722 gtk_style_apply_default_background (style, window,
3723 widget && !GTK_WIDGET_NO_WINDOW (widget),
3726 y + style->ythickness,
3727 width - (style->xthickness),
3728 height - (2 * style->ythickness));
3729 gdk_draw_line (window, gc1,
3730 x, y, x + width - 2, y);
3731 gdk_draw_line (window, gc2,
3732 x + 1, y + 1, x + width - 2, y + 1);
3734 gdk_draw_line (window, gc3,
3735 x, y + height - 2, x + width - 2, y + height - 2);
3736 gdk_draw_line (window, gc3,
3737 x + width - 2, y + 2, x + width - 2, y + height - 2);
3738 gdk_draw_line (window, gc4,
3739 x, y + height - 1, x + width - 2, y + height - 1);
3740 gdk_draw_line (window, gc4,
3741 x + width - 1, y + 1, x + width - 1, y + height - 2);
3744 gtk_style_apply_default_background (style, window,
3745 widget && !GTK_WIDGET_NO_WINDOW (widget),
3747 x + style->xthickness,
3748 y + style->ythickness,
3749 width - (style->xthickness),
3750 height - (2 * style->ythickness));
3751 gdk_draw_line (window, gc1,
3752 x + 1, y, x + width - 1, y);
3753 gdk_draw_line (window, gc1,
3754 x, y + 1, x, y + height - 2);
3755 gdk_draw_line (window, gc2,
3756 x + 1, y + 1, x + width - 1, y + 1);
3757 gdk_draw_line (window, gc2,
3758 x + 1, y + 1, x + 1, y + height - 2);
3760 gdk_draw_line (window, gc3,
3761 x + 2, y + height - 2, x + width - 1, y + height - 2);
3762 gdk_draw_line (window, gc4,
3763 x + 1, y + height - 1, x + width - 1, y + height - 1);
3770 gdk_gc_set_clip_rectangle (gc1, NULL);
3771 gdk_gc_set_clip_rectangle (gc2, NULL);
3772 gdk_gc_set_clip_rectangle (gc3, NULL);
3773 gdk_gc_set_clip_rectangle (gc4, NULL);
3778 gtk_default_draw_focus (GtkStyle *style,
3780 GtkStateType state_type,
3783 const gchar *detail,
3791 gint line_width = 1;
3792 gchar *dash_list = "\1\1";
3795 gc = style->fg_gc[state_type];
3798 gtk_widget_style_get (widget,
3799 "focus-line-width", &line_width,
3800 "focus-line-pattern", (gchar *)&dash_list,
3803 sanitize_size (window, &width, &height);
3806 gdk_gc_set_clip_rectangle (gc, area);
3808 gdk_gc_set_line_attributes (gc, line_width,
3809 dash_list[0] ? GDK_LINE_ON_OFF_DASH : GDK_LINE_SOLID,
3810 GDK_CAP_BUTT, GDK_JOIN_MITER);
3813 if (detail && !strcmp (detail, "add-mode"))
3816 points[0].x = x + line_width / 2;
3817 points[0].y = y + line_width / 2;
3818 points[1].x = x + width - line_width + line_width / 2;
3819 points[1].y = y + line_width / 2;
3820 points[2].x = x + width - line_width + line_width / 2;
3821 points[2].y = y + height - line_width + line_width / 2;
3822 points[3].x = x + line_width / 2;
3823 points[3].y = y + height - line_width + line_width / 2;
3824 points[4] = points[0];
3828 gdk_draw_lines (window, gc, points, 5);
3832 /* We go through all the pain below because the X rasterization
3833 * rules don't really work right for dashed lines if you
3834 * want continuity in segments that go between top/right
3835 * and left/bottom. For instance, a top left corner
3836 * with a 1-1 dash is drawn as:
3843 * This is because pixels on the top and left boundaries
3844 * of polygons are drawn, but not on the bottom and right.
3845 * So, if you have a line going up that turns the corner
3846 * and goes right, there is a one pixel shift in the pattern.
3848 * So, to fix this, we drawn the top and right in one call,
3849 * then the left and bottom in another call, fixing up
3850 * the dash offset for the second call ourselves to get
3851 * continuity at the upper left.
3853 * It's not perfect since we really should have a join at
3854 * the upper left and lower right instead of two intersecting
3855 * lines but that's only really apparent for no-dashes,
3856 * which (for this reason) are done as one polygon and
3857 * don't to through this code path.
3860 dash_len = strlen (dash_list);
3863 gdk_gc_set_dashes (gc, 0, dash_list, dash_len);
3865 gdk_draw_lines (window, gc, points, 3);
3867 /* We draw this line one farther over than it is "supposed" to
3868 * because of another rasterization problem ... if two 1 pixel
3869 * unjoined lines meet at the lower right, there will be a missing
3876 gint dash_pixels = 0;
3879 /* Adjust the dash offset for the bottom and left so we
3880 * match up at the upper left.
3882 for (i = 0; i < dash_len; i++)
3883 dash_pixels += dash_list[i];
3885 if (dash_len % 2 == 1)
3888 gdk_gc_set_dashes (gc, dash_pixels - (width + height - 2 * line_width) % dash_pixels, dash_list, dash_len);
3891 gdk_draw_lines (window, gc, points + 2, 3);
3894 gdk_gc_set_line_attributes (gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
3897 gdk_gc_set_clip_rectangle (gc, NULL);
3901 gtk_default_draw_slider (GtkStyle *style,
3903 GtkStateType state_type,
3904 GtkShadowType shadow_type,
3907 const gchar *detail,
3912 GtkOrientation orientation)
3914 g_return_if_fail (GTK_IS_STYLE (style));
3915 g_return_if_fail (window != NULL);
3917 sanitize_size (window, &width, &height);
3919 gtk_paint_box (style, window, state_type, shadow_type,
3920 area, widget, detail, x, y, width, height);
3923 (strcmp ("hscale", detail) == 0 ||
3924 strcmp ("vscale", detail) == 0))
3926 if (orientation == GTK_ORIENTATION_HORIZONTAL)
3927 gtk_paint_vline (style, window, state_type, area, widget, detail,
3928 y + style->ythickness,
3929 y + height - style->ythickness - 1, x + width / 2);
3931 gtk_paint_hline (style, window, state_type, area, widget, detail,
3932 x + style->xthickness,
3933 x + width - style->xthickness - 1, y + height / 2);
3938 draw_dot (GdkWindow *window,
3946 size = CLAMP (size, 2, 3);
3950 gdk_draw_point (window, light_gc, x, y);
3951 gdk_draw_point (window, light_gc, x+1, y+1);
3953 else if (size == 3);
3955 gdk_draw_point (window, light_gc, x, y);
3956 gdk_draw_point (window, light_gc, x+1, y);
3957 gdk_draw_point (window, light_gc, x, y+1);
3958 gdk_draw_point (window, dark_gc, x+1, y+2);
3959 gdk_draw_point (window, dark_gc, x+2, y+1);
3960 gdk_draw_point (window, dark_gc, x+2, y+2);
3965 gtk_default_draw_handle (GtkStyle *style,
3967 GtkStateType state_type,
3968 GtkShadowType shadow_type,
3971 const gchar *detail,
3976 GtkOrientation orientation)
3979 gint xthick, ythick;
3980 GdkGC *light_gc, *dark_gc;
3985 g_return_if_fail (GTK_IS_STYLE (style));
3986 g_return_if_fail (window != NULL);
3988 sanitize_size (window, &width, &height);
3990 gtk_paint_box (style, window, state_type, shadow_type, area, widget,
3991 detail, x, y, width, height);
3994 if (!strcmp (detail, "paned"))
3996 /* we want to ignore the shadow border in paned widgets */
4000 light_gc = style->light_gc[state_type];
4001 dark_gc = style->black_gc;
4005 xthick = style->xthickness;
4006 ythick = style->ythickness;
4008 light_gc = style->light_gc[state_type];
4009 dark_gc = style->dark_gc[state_type];
4012 rect.x = x + xthick;
4013 rect.y = y + ythick;
4014 rect.width = width - (xthick * 2);
4015 rect.height = height - (ythick * 2);
4018 intersect = gdk_rectangle_intersect (area, &rect, &dest);
4028 gdk_gc_set_clip_rectangle (light_gc, &dest);
4029 gdk_gc_set_clip_rectangle (dark_gc, &dest);
4031 if (!strcmp (detail, "paned"))
4033 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4034 for (xx = x + width/2 - 15; xx <= x + width/2 + 15; xx += 5)
4035 draw_dot (window, light_gc, dark_gc, xx, y + height/2 - 1, 3);
4037 for (yy = y + height/2 - 15; yy <= y + height/2 + 15; yy += 5)
4038 draw_dot (window, light_gc, dark_gc, x + width/2 - 1, yy, 3);
4042 for (yy = y + ythick; yy < (y + height - ythick); yy += 3)
4043 for (xx = x + xthick; xx < (x + width - xthick); xx += 6)
4045 draw_dot (window, light_gc, dark_gc, xx, yy, 2);
4046 draw_dot (window, light_gc, dark_gc, xx + 3, yy + 1, 2);
4050 gdk_gc_set_clip_rectangle (light_gc, NULL);
4051 gdk_gc_set_clip_rectangle (dark_gc, NULL);
4055 create_expander_affine (gdouble affine[6],
4065 width = expander_size / 4.0;
4066 height = expander_size / 2.0;
4068 s = sin (degrees * G_PI / 180.0);
4069 c = cos (degrees * G_PI / 180.0);
4075 affine[4] = -width * c - height * -s + x;
4076 affine[5] = -width * s - height * c + y;
4080 apply_affine_on_point (double affine[6], GdkPoint *point)
4084 x = point->x * affine[0] + point->y * affine[2] + affine[4];
4085 y = point->x * affine[1] + point->y * affine[3] + affine[5];
4092 gtk_default_draw_expander (GtkStyle *style,
4094 GtkStateType state_type,
4097 const gchar *detail,
4100 GtkExpanderStyle expander_style)
4108 gtk_widget_style_get (widget,
4109 "expander_size", &expander_size,
4114 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], area);
4115 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], area);
4120 points[1].x = expander_size / 2;
4121 points[1].y = expander_size / 2;
4123 points[2].y = expander_size;
4125 switch (expander_style)
4127 case GTK_EXPANDER_COLLAPSED:
4130 case GTK_EXPANDER_SEMI_COLLAPSED:
4133 case GTK_EXPANDER_SEMI_EXPANDED:
4136 case GTK_EXPANDER_EXPANDED:
4140 g_assert_not_reached ();
4143 create_expander_affine (affine, degrees, expander_size, x, y);
4145 for (i = 0; i < 3; i++)
4146 apply_affine_on_point (affine, &points[i]);
4148 if (state_type == GTK_STATE_PRELIGHT)
4150 gdk_draw_polygon (window, style->fg_gc[GTK_STATE_NORMAL],
4153 else if (state_type == GTK_STATE_ACTIVE)
4155 gdk_draw_polygon (window, style->light_gc[GTK_STATE_ACTIVE],
4157 gdk_draw_polygon (window, style->fg_gc[GTK_STATE_NORMAL],
4162 gdk_draw_polygon (window, style->base_gc[GTK_STATE_NORMAL],
4164 gdk_draw_polygon (window, style->fg_gc[GTK_STATE_NORMAL],
4169 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], NULL);
4170 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], NULL);
4174 typedef struct _ByteRange ByteRange;
4183 range_new (guint start,
4186 ByteRange *br = g_new (ByteRange, 1);
4195 get_insensitive_layout (PangoLayout *layout)
4197 GSList *embossed_ranges = NULL;
4198 GSList *stippled_ranges = NULL;
4199 PangoLayoutIter *iter;
4200 GSList *tmp_list = NULL;
4201 PangoLayout *new_layout;
4202 PangoAttrList *attrs;
4203 GdkBitmap *stipple = NULL;
4205 iter = pango_layout_get_iter (layout);
4209 PangoLayoutRun *run;
4210 PangoAttribute *attr;
4211 gboolean need_stipple = FALSE;
4214 run = pango_layout_iter_get_run (iter);
4218 tmp_list = run->item->analysis.extra_attrs;
4220 while (tmp_list != NULL)
4222 attr = tmp_list->data;
4223 switch (attr->klass->type)
4225 case PANGO_ATTR_FOREGROUND:
4226 case PANGO_ATTR_BACKGROUND:
4227 need_stipple = TRUE;
4237 tmp_list = g_slist_next (tmp_list);
4240 br = range_new (run->item->offset, run->item->offset + run->item->length);
4243 stippled_ranges = g_slist_prepend (stippled_ranges, br);
4245 embossed_ranges = g_slist_prepend (embossed_ranges, br);
4248 while (pango_layout_iter_next_run (iter));
4250 pango_layout_iter_free (iter);
4252 new_layout = pango_layout_copy (layout);
4254 attrs = pango_layout_get_attributes (new_layout);
4258 /* Create attr list if there wasn't one */
4259 attrs = pango_attr_list_new ();
4260 pango_layout_set_attributes (new_layout, attrs);
4261 pango_attr_list_unref (attrs);
4264 tmp_list = embossed_ranges;
4265 while (tmp_list != NULL)
4267 PangoAttribute *attr;
4268 ByteRange *br = tmp_list->data;
4270 attr = gdk_pango_attr_embossed_new (TRUE);
4272 attr->start_index = br->start;
4273 attr->end_index = br->end;
4275 pango_attr_list_change (attrs, attr);
4279 tmp_list = g_slist_next (tmp_list);
4282 g_slist_free (embossed_ranges);
4284 tmp_list = stippled_ranges;
4285 while (tmp_list != NULL)
4287 PangoAttribute *attr;
4288 ByteRange *br = tmp_list->data;
4290 if (stipple == NULL)
4292 #define gray50_width 2
4293 #define gray50_height 2
4294 static char gray50_bits[] = {
4298 stipple = gdk_bitmap_create_from_data (NULL,
4299 gray50_bits, gray50_width,
4303 attr = gdk_pango_attr_stipple_new (stipple);
4305 attr->start_index = br->start;
4306 attr->end_index = br->end;
4308 pango_attr_list_change (attrs, attr);
4312 tmp_list = g_slist_next (tmp_list);
4315 g_slist_free (stippled_ranges);
4318 g_object_unref (G_OBJECT (stipple));
4324 gtk_default_draw_layout (GtkStyle *style,
4326 GtkStateType state_type,
4330 const gchar *detail,
4333 PangoLayout *layout)
4337 g_return_if_fail (GTK_IS_STYLE (style));
4338 g_return_if_fail (window != NULL);
4340 gc = use_text ? style->text_gc[state_type] : style->fg_gc[state_type];
4343 gdk_gc_set_clip_rectangle (gc, area);
4345 if (state_type == GTK_STATE_INSENSITIVE)
4349 ins = get_insensitive_layout (layout);
4351 gdk_draw_layout (window, gc, x, y, ins);
4353 g_object_unref (G_OBJECT (ins));
4357 gdk_draw_layout (window, gc, x, y, layout);
4361 gdk_gc_set_clip_rectangle (gc, NULL);
4365 gtk_default_draw_resize_grip (GtkStyle *style,
4367 GtkStateType state_type,
4370 const gchar *detail,
4377 g_return_if_fail (GTK_IS_STYLE (style));
4378 g_return_if_fail (window != NULL);
4382 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
4383 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
4384 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
4387 /* make it square, aligning to bottom right */
4390 y += (height - width);
4393 else if (height < width)
4395 x += (width - height);
4399 /* Clear background */
4400 gdk_draw_rectangle (window,
4401 style->bg_gc[state_type],
4403 x, y, width, height);
4407 case GDK_WINDOW_EDGE_SOUTH_EAST:
4414 while (xi < (x + width - 3))
4416 gdk_draw_line (window,
4417 style->light_gc[state_type],
4424 gdk_draw_line (window,
4425 style->dark_gc[state_type],
4432 gdk_draw_line (window,
4433 style->dark_gc[state_type],
4443 g_assert_not_reached ();
4449 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
4450 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
4451 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
4456 gtk_style_shade (GdkColor *a,
4464 red = (gdouble) a->red / 65535.0;
4465 green = (gdouble) a->green / 65535.0;
4466 blue = (gdouble) a->blue / 65535.0;
4468 rgb_to_hls (&red, &green, &blue);
4473 else if (green < 0.0)
4479 else if (blue < 0.0)
4482 hls_to_rgb (&red, &green, &blue);
4484 b->red = red * 65535.0;
4485 b->green = green * 65535.0;
4486 b->blue = blue * 65535.0;
4490 rgb_to_hls (gdouble *r,
4531 l = (max + min) / 2;
4538 s = (max - min) / (max + min);
4540 s = (max - min) / (2 - max - min);
4544 h = (green - blue) / delta;
4545 else if (green == max)
4546 h = 2 + (blue - red) / delta;
4547 else if (blue == max)
4548 h = 4 + (red - green) / delta;
4561 hls_to_rgb (gdouble *h,
4574 if (lightness <= 0.5)
4575 m2 = lightness * (1 + saturation);
4577 m2 = lightness + saturation - lightness * saturation;
4578 m1 = 2 * lightness - m2;
4580 if (saturation == 0)
4595 r = m1 + (m2 - m1) * hue / 60;
4599 r = m1 + (m2 - m1) * (240 - hue) / 60;
4610 g = m1 + (m2 - m1) * hue / 60;
4614 g = m1 + (m2 - m1) * (240 - hue) / 60;
4625 b = m1 + (m2 - m1) * hue / 60;
4629 b = m1 + (m2 - m1) * (240 - hue) / 60;
4640 gtk_paint_hline (GtkStyle *style,
4642 GtkStateType state_type,
4645 const gchar *detail,
4650 g_return_if_fail (GTK_IS_STYLE (style));
4651 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
4653 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, area, widget, detail, x1, x2, y);
4657 gtk_paint_vline (GtkStyle *style,
4659 GtkStateType state_type,
4662 const gchar *detail,
4667 g_return_if_fail (GTK_IS_STYLE (style));
4668 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
4670 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, area, widget, detail, y1, y2, x);
4674 gtk_paint_shadow (GtkStyle *style,
4676 GtkStateType state_type,
4677 GtkShadowType shadow_type,
4680 const gchar *detail,
4686 g_return_if_fail (GTK_IS_STYLE (style));
4687 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
4689 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4693 gtk_paint_polygon (GtkStyle *style,
4695 GtkStateType state_type,
4696 GtkShadowType shadow_type,
4699 const gchar *detail,
4704 g_return_if_fail (GTK_IS_STYLE (style));
4705 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
4707 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, area, widget, detail, points, npoints, fill);
4711 gtk_paint_arrow (GtkStyle *style,
4713 GtkStateType state_type,
4714 GtkShadowType shadow_type,
4717 const gchar *detail,
4718 GtkArrowType arrow_type,
4725 g_return_if_fail (GTK_IS_STYLE (style));
4726 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
4728 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, area, widget, detail, arrow_type, fill, x, y, width, height);
4732 gtk_paint_diamond (GtkStyle *style,
4734 GtkStateType state_type,
4735 GtkShadowType shadow_type,
4738 const gchar *detail,
4744 g_return_if_fail (GTK_IS_STYLE (style));
4745 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
4747 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4751 gtk_paint_string (GtkStyle *style,
4753 GtkStateType state_type,
4756 const gchar *detail,
4759 const gchar *string)
4761 g_return_if_fail (GTK_IS_STYLE (style));
4762 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
4764 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, area, widget, detail, x, y, string);
4768 gtk_paint_box (GtkStyle *style,
4770 GtkStateType state_type,
4771 GtkShadowType shadow_type,
4774 const gchar *detail,
4780 g_return_if_fail (GTK_IS_STYLE (style));
4781 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
4783 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4787 gtk_paint_flat_box (GtkStyle *style,
4789 GtkStateType state_type,
4790 GtkShadowType shadow_type,
4793 const gchar *detail,
4799 g_return_if_fail (GTK_IS_STYLE (style));
4800 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
4802 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4806 gtk_paint_check (GtkStyle *style,
4808 GtkStateType state_type,
4809 GtkShadowType shadow_type,
4812 const gchar *detail,
4818 g_return_if_fail (GTK_IS_STYLE (style));
4819 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
4821 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4825 gtk_paint_option (GtkStyle *style,
4827 GtkStateType state_type,
4828 GtkShadowType shadow_type,
4831 const gchar *detail,
4837 g_return_if_fail (GTK_IS_STYLE (style));
4838 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
4840 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4844 gtk_paint_tab (GtkStyle *style,
4846 GtkStateType state_type,
4847 GtkShadowType shadow_type,
4850 const gchar *detail,
4856 g_return_if_fail (GTK_IS_STYLE (style));
4857 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
4859 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4863 gtk_paint_shadow_gap (GtkStyle *style,
4865 GtkStateType state_type,
4866 GtkShadowType shadow_type,
4874 GtkPositionType gap_side,
4878 g_return_if_fail (GTK_IS_STYLE (style));
4879 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
4881 GTK_STYLE_GET_CLASS (style)->draw_shadow_gap (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side, gap_x, gap_width);
4886 gtk_paint_box_gap (GtkStyle *style,
4888 GtkStateType state_type,
4889 GtkShadowType shadow_type,
4897 GtkPositionType gap_side,
4901 g_return_if_fail (GTK_IS_STYLE (style));
4902 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
4904 GTK_STYLE_GET_CLASS (style)->draw_box_gap (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side, gap_x, gap_width);
4908 gtk_paint_extension (GtkStyle *style,
4910 GtkStateType state_type,
4911 GtkShadowType shadow_type,
4919 GtkPositionType gap_side)
4921 g_return_if_fail (GTK_IS_STYLE (style));
4922 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
4924 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side);
4928 gtk_paint_focus (GtkStyle *style,
4930 GtkStateType state_type,
4933 const gchar *detail,
4939 g_return_if_fail (GTK_IS_STYLE (style));
4940 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
4942 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, state_type, area, widget, detail, x, y, width, height);
4946 gtk_paint_slider (GtkStyle *style,
4948 GtkStateType state_type,
4949 GtkShadowType shadow_type,
4952 const gchar *detail,
4957 GtkOrientation orientation)
4959 g_return_if_fail (GTK_IS_STYLE (style));
4960 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
4962 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
4966 gtk_paint_handle (GtkStyle *style,
4968 GtkStateType state_type,
4969 GtkShadowType shadow_type,
4972 const gchar *detail,
4977 GtkOrientation orientation)
4979 g_return_if_fail (GTK_IS_STYLE (style));
4980 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
4982 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
4986 gtk_paint_expander (GtkStyle *style,
4988 GtkStateType state_type,
4991 const gchar *detail,
4994 GtkExpanderStyle expander_style)
4996 g_return_if_fail (GTK_IS_STYLE (style));
4997 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
4999 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type, area,
5000 widget, detail, x, y, expander_style);
5004 gtk_paint_layout (GtkStyle *style,
5006 GtkStateType state_type,
5010 const gchar *detail,
5013 PangoLayout *layout)
5015 g_return_if_fail (GTK_IS_STYLE (style));
5016 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
5018 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text, area,
5019 widget, detail, x, y, layout);
5023 gtk_paint_resize_grip (GtkStyle *style,
5025 GtkStateType state_type,
5028 const gchar *detail,
5036 g_return_if_fail (GTK_IS_STYLE (style));
5037 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
5039 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
5040 area, widget, detail,
5041 edge, x, y, width, height);
5045 gtk_border_copy (const GtkBorder *border)
5047 return (GtkBorder *)g_memdup (border, sizeof (GtkBorder));
5051 gtk_border_free (GtkBorder *border)
5057 * gtk_style_get_font:
5058 * @style: a #GtkStyle
5060 * Gets the #GdkFont to use for the given style. This is
5061 * meant only as a replacement for direct access to style->font
5062 * and should not be used in new code. New code should
5063 * use style->font_desc instead.
5065 * Return value: the #GdkFont for the style. This font is owned
5066 * by the style; if you want to keep around a copy, you must
5067 * call gdk_font_ref().
5070 gtk_style_get_font (GtkStyle *style)
5072 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
5074 if (style->private_font && style->private_font_desc)
5076 if (!style->font_desc ||
5077 !pango_font_description_equal (style->private_font_desc, style->font_desc))
5079 gdk_font_unref (style->private_font);
5080 style->private_font = NULL;
5082 if (style->private_font_desc)
5084 pango_font_description_free (style->private_font_desc);
5085 style->private_font_desc = NULL;
5090 if (!style->private_font)
5092 if (style->font_desc)
5094 style->private_font = gdk_font_from_description (style->font_desc);
5095 style->private_font_desc = pango_font_description_copy (style->font_desc);
5098 if (!style->private_font)
5099 style->private_font = gdk_font_load ("fixed");
5101 if (!style->private_font)
5102 g_error ("Unable to load \"fixed\" font");
5105 return style->private_font;
5109 * gtk_style_set_font:
5110 * @style: a #GtkStyle.
5111 * @font: a #GdkFont, or %NULL to use the #GdkFont corresponding
5112 * to style->font_desc.
5114 * Sets the #GdkFont to use for a given style. This is
5115 * meant only as a replacement for direct access to style->font
5116 * and should not be used in new code. New code should
5117 * use style->font_desc instead.
5120 gtk_style_set_font (GtkStyle *style,
5125 g_return_if_fail (GTK_IS_STYLE (style));
5127 old_font = style->private_font;
5129 style->private_font = font;
5131 gdk_font_ref (font);
5134 gdk_font_unref (old_font);
5136 if (style->private_font_desc)
5138 pango_font_description_free (style->private_font_desc);
5139 style->private_font_desc = NULL;
5144 * _gtk_draw_insertion_cursor:
5145 * @drawable: a #GdkDrawable
5147 * @location: location where to draw the cursor (@location->width is ignored)
5148 * @dir: text direction for the cursor, used to decide whether to draw a
5149 * directional arrow on the cursor and in what direction. Unless both
5150 * strong and weak cursors are displayed, this should be %GTK_TEXT_DIR_NONE.
5152 * Draws a text caret on @drawable at @location. This is not a style function
5153 * but merely a convenience function for drawing the standard cursor shape.
5156 _gtk_draw_insertion_cursor (GdkDrawable *drawable,
5158 GdkRectangle *location,
5159 GtkTextDirection dir)
5161 gint stem_width = location->height / 30 + 1;
5162 gint arrow_width = stem_width + 1;
5166 for (i = 0; i < stem_width; i++)
5167 gdk_draw_line (drawable, gc,
5168 location->x + i - stem_width / 2, location->y,
5169 location->x + i - stem_width / 2, location->y + location->height);
5171 if (dir == GTK_TEXT_DIR_RTL)
5173 x = location->x - stem_width / 2 - 1;
5174 y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
5176 for (i = 0; i < arrow_width; i++)
5178 gdk_draw_line (drawable, gc,
5180 x, y + 2 * arrow_width - i - 1);
5184 else if (dir == GTK_TEXT_DIR_LTR)
5186 x = location->x + stem_width - stem_width / 2;
5187 y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
5189 for (i = 0; i < arrow_width; i++)
5191 gdk_draw_line (drawable, gc,
5193 x, y + 2 * arrow_width - i - 1);