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;
647 * @returns: a new #GtkStyle.
649 * Creates a new #GtkStyle.
656 style = g_object_new (GTK_TYPE_STYLE, NULL);
663 * @style: a #GtkStyle.
664 * @window: a #GtkWindow.
665 * @returns: Either @style, or a newly-created #GtkStyle.
666 * If the style is newly created, the style parameter
667 * will be dereferenced, and the new style will have
668 * a reference count belonging to the caller.
670 * Attaches a style to a window; this process allocates the
671 * colors and creates the GC's for the style - it specializes
672 * it to a particular visual and colormap. The process may
673 * involve the creation of a new style if the style has already
674 * been attached to a window with a different style and colormap.
677 * FIXME: The sequence -
678 * create a style => s1
679 * attach s1 to v1, c1 => s1
680 * attach s1 to v2, c2 => s2
681 * detach s1 from v1, c1
682 * attach s1 to v2, c2 => s3
683 * results in two separate, unlinked styles s2 and s3 which
684 * are identical and could be shared. To fix this, we would
685 * want to never remove a style from the list of linked
686 * styles as long as as it has a reference count. However, the
687 * disadvantage of doing it this way means that we would need two
688 * passes through the linked list when attaching (one to check for
689 * matching styles, one to look for empty unattached styles - but
690 * it will almost never be longer than 2 elements.
693 gtk_style_attach (GtkStyle *style,
697 GtkStyle *new_style = NULL;
698 GdkColormap *colormap;
700 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
701 g_return_val_if_fail (window != NULL, NULL);
703 colormap = gdk_window_get_colormap (window);
706 style->styles = g_slist_append (NULL, style);
708 styles = style->styles;
711 new_style = styles->data;
713 if (new_style->attach_count == 0)
715 gtk_style_realize (new_style, colormap);
718 else if (new_style->colormap == colormap)
722 styles = styles->next;
727 new_style = gtk_style_duplicate (style);
728 gtk_style_realize (new_style, colormap);
731 /* A style gets a refcount from being attached */
732 if (new_style->attach_count == 0)
733 g_object_ref (new_style);
735 /* Another refcount belongs to the parent */
736 if (style != new_style)
738 g_object_unref (style);
739 g_object_ref (new_style);
742 new_style->attach_count++;
748 gtk_style_detach (GtkStyle *style)
750 g_return_if_fail (GTK_IS_STYLE (style));
752 style->attach_count -= 1;
753 if (style->attach_count == 0)
755 GTK_STYLE_GET_CLASS (style)->unrealize (style);
757 gdk_colormap_unref (style->colormap);
758 style->colormap = NULL;
760 g_object_unref (style);
766 * @style: a #GtkStyle.
769 * Deprecated equivalent of g_object_ref().
772 gtk_style_ref (GtkStyle *style)
774 return (GtkStyle *) g_object_ref (G_OBJECT (style));
779 * @style: a #GtkStyle.
781 * Deprecated equivalent of g_object_unref().
784 gtk_style_unref (GtkStyle *style)
786 g_object_unref (G_OBJECT (style));
790 gtk_style_realize (GtkStyle *style,
791 GdkColormap *colormap)
793 g_return_if_fail (GTK_IS_STYLE (style));
794 g_return_if_fail (GDK_IS_COLORMAP (colormap));
796 style->colormap = gdk_colormap_ref (colormap);
797 style->depth = gdk_colormap_get_visual (colormap)->depth;
799 GTK_STYLE_GET_CLASS (style)->realize (style);
803 gtk_style_lookup_icon_set (GtkStyle *style,
804 const char *stock_id)
808 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
809 g_return_val_if_fail (stock_id != NULL, NULL);
811 iter = style->icon_factories;
814 GtkIconSet *icon_set = gtk_icon_factory_lookup (GTK_ICON_FACTORY (iter->data),
819 iter = g_slist_next (iter);
822 return gtk_icon_factory_lookup_default (stock_id);
826 gtk_draw_hline (GtkStyle *style,
828 GtkStateType state_type,
833 g_return_if_fail (GTK_IS_STYLE (style));
834 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
836 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, NULL, NULL, NULL, x1, x2, y);
841 gtk_draw_vline (GtkStyle *style,
843 GtkStateType state_type,
848 g_return_if_fail (GTK_IS_STYLE (style));
849 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
851 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, NULL, NULL, NULL, y1, y2, x);
856 gtk_draw_shadow (GtkStyle *style,
858 GtkStateType state_type,
859 GtkShadowType shadow_type,
865 g_return_if_fail (GTK_IS_STYLE (style));
866 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
868 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
872 gtk_draw_polygon (GtkStyle *style,
874 GtkStateType state_type,
875 GtkShadowType shadow_type,
880 g_return_if_fail (GTK_IS_STYLE (style));
881 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_polygon != NULL);
883 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, NULL, NULL, NULL, points, npoints, fill);
887 gtk_draw_arrow (GtkStyle *style,
889 GtkStateType state_type,
890 GtkShadowType shadow_type,
891 GtkArrowType arrow_type,
898 g_return_if_fail (GTK_IS_STYLE (style));
899 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
901 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, NULL, NULL, NULL, arrow_type, fill, x, y, width, height);
906 gtk_draw_diamond (GtkStyle *style,
908 GtkStateType state_type,
909 GtkShadowType shadow_type,
915 g_return_if_fail (GTK_IS_STYLE (style));
916 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
918 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
923 gtk_draw_string (GtkStyle *style,
925 GtkStateType state_type,
930 g_return_if_fail (GTK_IS_STYLE (style));
931 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
933 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, NULL, NULL, NULL, x, y, string);
937 gtk_draw_box (GtkStyle *style,
939 GtkStateType state_type,
940 GtkShadowType shadow_type,
946 g_return_if_fail (GTK_IS_STYLE (style));
947 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
949 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
953 gtk_draw_flat_box (GtkStyle *style,
955 GtkStateType state_type,
956 GtkShadowType shadow_type,
962 g_return_if_fail (GTK_IS_STYLE (style));
963 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
965 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
969 gtk_draw_check (GtkStyle *style,
971 GtkStateType state_type,
972 GtkShadowType shadow_type,
978 g_return_if_fail (GTK_IS_STYLE (style));
979 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
981 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
985 gtk_draw_option (GtkStyle *style,
987 GtkStateType state_type,
988 GtkShadowType shadow_type,
994 g_return_if_fail (GTK_IS_STYLE (style));
995 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
997 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1001 gtk_draw_tab (GtkStyle *style,
1003 GtkStateType state_type,
1004 GtkShadowType shadow_type,
1010 g_return_if_fail (GTK_IS_STYLE (style));
1011 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
1013 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1017 gtk_draw_shadow_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_shadow_gap != NULL);
1032 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);
1036 gtk_draw_box_gap (GtkStyle *style,
1038 GtkStateType state_type,
1039 GtkShadowType shadow_type,
1044 GtkPositionType gap_side,
1048 g_return_if_fail (GTK_IS_STYLE (style));
1049 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
1051 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);
1055 gtk_draw_extension (GtkStyle *style,
1057 GtkStateType state_type,
1058 GtkShadowType shadow_type,
1063 GtkPositionType gap_side)
1065 g_return_if_fail (GTK_IS_STYLE (style));
1066 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
1068 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side);
1072 gtk_draw_focus (GtkStyle *style,
1079 g_return_if_fail (GTK_IS_STYLE (style));
1080 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
1082 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, GTK_STATE_NORMAL, NULL, NULL, NULL, x, y, width, height);
1086 gtk_draw_slider (GtkStyle *style,
1088 GtkStateType state_type,
1089 GtkShadowType shadow_type,
1094 GtkOrientation orientation)
1096 g_return_if_fail (GTK_IS_STYLE (style));
1097 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
1099 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
1103 gtk_draw_handle (GtkStyle *style,
1105 GtkStateType state_type,
1106 GtkShadowType shadow_type,
1111 GtkOrientation orientation)
1113 g_return_if_fail (GTK_IS_STYLE (style));
1114 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
1116 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
1120 gtk_draw_expander (GtkStyle *style,
1122 GtkStateType state_type,
1125 GtkExpanderStyle expander_style)
1127 g_return_if_fail (GTK_IS_STYLE (style));
1128 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
1130 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type,
1132 x, y, expander_style);
1136 gtk_draw_layout (GtkStyle *style,
1138 GtkStateType state_type,
1142 PangoLayout *layout)
1144 g_return_if_fail (GTK_IS_STYLE (style));
1145 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
1147 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text,
1153 gtk_draw_resize_grip (GtkStyle *style,
1155 GtkStateType state_type,
1162 g_return_if_fail (GTK_IS_STYLE (style));
1163 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
1165 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
1168 x, y, width, height);
1173 gtk_style_set_background (GtkStyle *style,
1175 GtkStateType state_type)
1177 g_return_if_fail (GTK_IS_STYLE (style));
1178 g_return_if_fail (window != NULL);
1180 GTK_STYLE_GET_CLASS (style)->set_background (style, window, state_type);
1183 /* Default functions */
1185 gtk_style_real_clone (GtkStyle *style)
1187 return GTK_STYLE (g_object_new (G_OBJECT_TYPE (style), NULL));
1191 gtk_style_real_copy (GtkStyle *style,
1196 for (i = 0; i < 5; i++)
1198 style->fg[i] = src->fg[i];
1199 style->bg[i] = src->bg[i];
1200 style->text[i] = src->text[i];
1201 style->base[i] = src->base[i];
1203 style->bg_pixmap[i] = src->bg_pixmap[i];
1206 if (style->private_font)
1207 gdk_font_unref (style->private_font);
1208 style->private_font = src->private_font;
1209 if (style->private_font)
1210 gdk_font_ref (style->private_font);
1212 if (style->font_desc)
1213 pango_font_description_free (style->font_desc);
1215 style->font_desc = pango_font_description_copy (src->font_desc);
1217 style->font_desc = NULL;
1219 style->xthickness = src->xthickness;
1220 style->ythickness = src->ythickness;
1222 if (style->rc_style)
1223 gtk_rc_style_unref (style->rc_style);
1224 style->rc_style = src->rc_style;
1226 gtk_rc_style_ref (src->rc_style);
1228 /* don't copy, just clear cache */
1229 clear_property_cache (style);
1233 gtk_style_real_init_from_rc (GtkStyle *style,
1234 GtkRcStyle *rc_style)
1238 /* cache _should_ be still empty */
1239 clear_property_cache (style);
1241 if (rc_style->font_desc)
1243 pango_font_description_free (style->font_desc);
1244 style->font_desc = pango_font_description_copy (rc_style->font_desc);
1247 for (i = 0; i < 5; i++)
1249 if (rc_style->color_flags[i] & GTK_RC_FG)
1250 style->fg[i] = rc_style->fg[i];
1251 if (rc_style->color_flags[i] & GTK_RC_BG)
1252 style->bg[i] = rc_style->bg[i];
1253 if (rc_style->color_flags[i] & GTK_RC_TEXT)
1254 style->text[i] = rc_style->text[i];
1255 if (rc_style->color_flags[i] & GTK_RC_BASE)
1256 style->base[i] = rc_style->base[i];
1259 if (rc_style->xthickness >= 0)
1260 style->xthickness = rc_style->xthickness;
1261 if (rc_style->ythickness >= 0)
1262 style->ythickness = rc_style->ythickness;
1264 if (rc_style->icon_factories)
1268 style->icon_factories = g_slist_copy (rc_style->icon_factories);
1270 iter = style->icon_factories;
1271 while (iter != NULL)
1273 g_object_ref (G_OBJECT (iter->data));
1275 iter = g_slist_next (iter);
1281 style_property_values_cmp (gconstpointer bsearch_node1,
1282 gconstpointer bsearch_node2)
1284 const PropertyValue *val1 = bsearch_node1;
1285 const PropertyValue *val2 = bsearch_node2;
1287 if (val1->widget_type == val2->widget_type)
1288 return val1->pspec < val2->pspec ? -1 : val1->pspec == val2->pspec ? 0 : 1;
1290 return val1->widget_type < val2->widget_type ? -1 : 1;
1294 _gtk_style_peek_property_value (GtkStyle *style,
1297 GtkRcPropertyParser parser)
1299 PropertyValue *pcache, key = { 0, NULL, { 0, } };
1300 const GtkRcProperty *rcprop = NULL;
1303 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1304 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), NULL);
1305 g_return_val_if_fail (g_type_is_a (pspec->owner_type, GTK_TYPE_WIDGET), NULL);
1306 g_return_val_if_fail (g_type_is_a (widget_type, pspec->owner_type), NULL);
1308 key.widget_type = widget_type;
1311 /* need value cache array */
1312 if (!style->property_cache)
1313 style->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
1316 pcache = bsearch (&key,
1317 style->property_cache->data, style->property_cache->len,
1318 sizeof (PropertyValue), style_property_values_cmp);
1320 return &pcache->value;
1324 while (i < style->property_cache->len &&
1325 style_property_values_cmp (&key, &g_array_index (style->property_cache, PropertyValue, i)) >= 0)
1328 g_array_insert_val (style->property_cache, i, key);
1329 pcache = &g_array_index (style->property_cache, PropertyValue, i);
1331 /* cache miss, initialize value type, then set contents */
1332 g_param_spec_ref (pcache->pspec);
1333 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1335 /* value provided by rc style? */
1336 if (style->rc_style)
1338 GQuark prop_quark = g_quark_from_string (pspec->name);
1342 rcprop = _gtk_rc_style_lookup_rc_property (style->rc_style,
1343 g_type_qname (widget_type),
1347 widget_type = g_type_parent (widget_type);
1349 while (g_type_is_a (widget_type, pspec->owner_type));
1352 /* when supplied by rc style, we need to convert */
1353 if (rcprop && !_gtk_settings_parse_convert (parser, &rcprop->value,
1354 pspec, &pcache->value))
1356 gchar *contents = g_strdup_value_contents (&rcprop->value);
1358 g_message ("%s: failed to retrieve property `%s::%s' of type `%s' from rc file value \"%s\" of type `%s'",
1360 g_type_name (pspec->owner_type), pspec->name,
1361 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1363 G_VALUE_TYPE_NAME (&rcprop->value));
1365 rcprop = NULL; /* needs default */
1368 /* not supplied by rc style (or conversion failed), revert to default */
1370 g_param_value_set_default (pspec, &pcache->value);
1372 return &pcache->value;
1376 load_bg_image (GdkColormap *colormap,
1378 const gchar *filename)
1380 if (strcmp (filename, "<parent>") == 0)
1381 return (GdkPixmap*) GDK_PARENT_RELATIVE;
1384 return gdk_pixmap_colormap_create_from_xpm (NULL, colormap, NULL,
1391 gtk_style_real_realize (GtkStyle *style)
1393 GdkGCValues gc_values;
1394 GdkGCValuesMask gc_values_mask;
1398 for (i = 0; i < 5; i++)
1400 gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT);
1401 gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT);
1403 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
1404 style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
1405 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
1407 style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
1408 style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
1409 style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;
1412 gdk_color_black (style->colormap, &style->black);
1413 gdk_color_white (style->colormap, &style->white);
1415 gc_values_mask = GDK_GC_FOREGROUND;
1417 gc_values.foreground = style->black;
1418 style->black_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1420 gc_values.foreground = style->white;
1421 style->white_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1423 for (i = 0; i < 5; i++)
1425 if (style->rc_style && style->rc_style->bg_pixmap_name[i])
1426 style->bg_pixmap[i] = load_bg_image (style->colormap,
1428 style->rc_style->bg_pixmap_name[i]);
1430 if (!gdk_color_alloc (style->colormap, &style->fg[i]))
1431 g_warning ("unable to allocate color: ( %d %d %d )",
1432 style->fg[i].red, style->fg[i].green, style->fg[i].blue);
1433 if (!gdk_color_alloc (style->colormap, &style->bg[i]))
1434 g_warning ("unable to allocate color: ( %d %d %d )",
1435 style->bg[i].red, style->bg[i].green, style->bg[i].blue);
1436 if (!gdk_color_alloc (style->colormap, &style->light[i]))
1437 g_warning ("unable to allocate color: ( %d %d %d )",
1438 style->light[i].red, style->light[i].green, style->light[i].blue);
1439 if (!gdk_color_alloc (style->colormap, &style->dark[i]))
1440 g_warning ("unable to allocate color: ( %d %d %d )",
1441 style->dark[i].red, style->dark[i].green, style->dark[i].blue);
1442 if (!gdk_color_alloc (style->colormap, &style->mid[i]))
1443 g_warning ("unable to allocate color: ( %d %d %d )",
1444 style->mid[i].red, style->mid[i].green, style->mid[i].blue);
1445 if (!gdk_color_alloc (style->colormap, &style->text[i]))
1446 g_warning ("unable to allocate color: ( %d %d %d )",
1447 style->text[i].red, style->text[i].green, style->text[i].blue);
1448 if (!gdk_color_alloc (style->colormap, &style->base[i]))
1449 g_warning ("unable to allocate color: ( %d %d %d )",
1450 style->base[i].red, style->base[i].green, style->base[i].blue);
1451 if (!gdk_color_alloc (style->colormap, &style->text_aa[i]))
1452 g_warning ("unable to allocate color: ( %d %d %d )",
1453 style->text_aa[i].red, style->text_aa[i].green, style->text_aa[i].blue);
1455 gc_values.foreground = style->fg[i];
1456 style->fg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1458 gc_values.foreground = style->bg[i];
1459 style->bg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1461 gc_values.foreground = style->light[i];
1462 style->light_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1464 gc_values.foreground = style->dark[i];
1465 style->dark_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1467 gc_values.foreground = style->mid[i];
1468 style->mid_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1470 gc_values.foreground = style->text[i];
1471 style->text_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1473 gc_values.foreground = style->base[i];
1474 style->base_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1476 gc_values.foreground = style->text_aa[i];
1477 style->text_aa_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1482 gtk_style_real_unrealize (GtkStyle *style)
1486 gtk_gc_release (style->black_gc);
1487 gtk_gc_release (style->white_gc);
1489 for (i = 0; i < 5; i++)
1491 gtk_gc_release (style->fg_gc[i]);
1492 gtk_gc_release (style->bg_gc[i]);
1493 gtk_gc_release (style->light_gc[i]);
1494 gtk_gc_release (style->dark_gc[i]);
1495 gtk_gc_release (style->mid_gc[i]);
1496 gtk_gc_release (style->text_gc[i]);
1497 gtk_gc_release (style->base_gc[i]);
1498 gtk_gc_release (style->text_aa_gc[i]);
1500 if (style->bg_pixmap[i] && style->bg_pixmap[i] != (GdkPixmap*) GDK_PARENT_RELATIVE)
1501 gdk_pixmap_unref (style->bg_pixmap[i]);
1504 gdk_colormap_free_colors (style->colormap, style->fg, 5);
1505 gdk_colormap_free_colors (style->colormap, style->bg, 5);
1506 gdk_colormap_free_colors (style->colormap, style->light, 5);
1507 gdk_colormap_free_colors (style->colormap, style->dark, 5);
1508 gdk_colormap_free_colors (style->colormap, style->mid, 5);
1509 gdk_colormap_free_colors (style->colormap, style->text, 5);
1510 gdk_colormap_free_colors (style->colormap, style->base, 5);
1511 gdk_colormap_free_colors (style->colormap, style->text_aa, 5);
1515 gtk_style_real_set_background (GtkStyle *style,
1517 GtkStateType state_type)
1520 gint parent_relative;
1522 if (style->bg_pixmap[state_type])
1524 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1527 parent_relative = TRUE;
1531 pixmap = style->bg_pixmap[state_type];
1532 parent_relative = FALSE;
1535 gdk_window_set_back_pixmap (window, pixmap, parent_relative);
1538 gdk_window_set_background (window, &style->bg[state_type]);
1542 gtk_style_render_icon (GtkStyle *style,
1543 const GtkIconSource *source,
1544 GtkTextDirection direction,
1548 const gchar *detail)
1552 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1553 g_return_val_if_fail (GTK_STYLE_GET_CLASS (style)->render_icon != NULL, NULL);
1555 pixbuf = GTK_STYLE_GET_CLASS (style)->render_icon (style, source, direction, state,
1556 size, widget, detail);
1558 g_return_val_if_fail (pixbuf != NULL, NULL);
1563 /* Default functions */
1565 gtk_style_apply_default_background (GtkStyle *style,
1568 GtkStateType state_type,
1575 GdkRectangle new_rect, old_rect;
1581 old_rect.width = width;
1582 old_rect.height = height;
1584 if (!gdk_rectangle_intersect (area, &old_rect, &new_rect))
1591 new_rect.width = width;
1592 new_rect.height = height;
1595 if (!style->bg_pixmap[state_type] ||
1596 GDK_IS_PIXMAP (window) ||
1597 (!set_bg && style->bg_pixmap[state_type] != (GdkPixmap*) GDK_PARENT_RELATIVE))
1599 GdkGC *gc = style->bg_gc[state_type];
1601 if (style->bg_pixmap[state_type])
1603 gdk_gc_set_fill (gc, GDK_TILED);
1604 gdk_gc_set_tile (gc, style->bg_pixmap[state_type]);
1607 gdk_draw_rectangle (window, gc, TRUE,
1608 new_rect.x, new_rect.y, new_rect.width, new_rect.height);
1609 if (style->bg_pixmap[state_type])
1610 gdk_gc_set_fill (gc, GDK_SOLID);
1616 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1617 gdk_window_set_back_pixmap (window, NULL, TRUE);
1619 gdk_window_set_back_pixmap (window, style->bg_pixmap[state_type], FALSE);
1622 gdk_window_clear_area (window,
1623 new_rect.x, new_rect.y,
1624 new_rect.width, new_rect.height);
1629 scale_or_ref (GdkPixbuf *src,
1633 if (width == gdk_pixbuf_get_width (src) &&
1634 height == gdk_pixbuf_get_height (src))
1636 gdk_pixbuf_ref (src);
1641 return gdk_pixbuf_scale_simple (src,
1643 GDK_INTERP_BILINEAR);
1648 gtk_default_render_icon (GtkStyle *style,
1649 const GtkIconSource *source,
1650 GtkTextDirection direction,
1654 const gchar *detail)
1660 GdkPixbuf *base_pixbuf;
1662 /* Oddly, style can be NULL in this function, because
1663 * GtkIconSet can be used without a style and if so
1664 * it uses this function.
1667 base_pixbuf = gtk_icon_source_get_pixbuf (source);
1669 g_return_val_if_fail (base_pixbuf != NULL, NULL);
1671 if (!gtk_icon_size_lookup (size, &width, &height))
1673 g_warning (G_STRLOC ": invalid icon size `%d'", size);
1677 /* If the size was wildcarded, then scale; otherwise, leave it
1680 if (gtk_icon_source_get_size_wildcarded (source))
1681 scaled = scale_or_ref (base_pixbuf, width, height);
1683 scaled = GDK_PIXBUF (g_object_ref (G_OBJECT (base_pixbuf)));
1685 /* If the state was wildcarded, then generate a state. */
1686 if (gtk_icon_source_get_state_wildcarded (source))
1688 if (state == GTK_STATE_INSENSITIVE)
1690 stated = gdk_pixbuf_copy (scaled);
1692 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
1695 gdk_pixbuf_unref (scaled);
1697 else if (state == GTK_STATE_PRELIGHT)
1699 stated = gdk_pixbuf_copy (scaled);
1701 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
1704 gdk_pixbuf_unref (scaled);
1718 sanitize_size (GdkWindow *window,
1722 gboolean set_bg = FALSE;
1724 if ((*width == -1) && (*height == -1))
1726 set_bg = GDK_IS_WINDOW (window);
1727 gdk_window_get_size (window, width, height);
1729 else if (*width == -1)
1730 gdk_window_get_size (window, width, NULL);
1731 else if (*height == -1)
1732 gdk_window_get_size (window, NULL, height);
1738 draw_part (GdkDrawable *drawable,
1746 gdk_gc_set_clip_rectangle (gc, area);
1748 if (!indicator_parts[part].bmap)
1749 indicator_parts[part].bmap = gdk_bitmap_create_from_data (drawable,
1750 indicator_parts[part].bits,
1751 INDICATOR_PART_SIZE, INDICATOR_PART_SIZE);
1753 gdk_gc_set_ts_origin (gc, x, y);
1754 gdk_gc_set_stipple (gc, indicator_parts[part].bmap);
1755 gdk_gc_set_fill (gc, GDK_STIPPLED);
1757 gdk_draw_rectangle (drawable, gc, TRUE, x, y, INDICATOR_PART_SIZE, INDICATOR_PART_SIZE);
1759 gdk_gc_set_fill (gc, GDK_SOLID);
1762 gdk_gc_set_clip_rectangle (gc, NULL);
1766 gtk_default_draw_hline (GtkStyle *style,
1768 GtkStateType state_type,
1771 const gchar *detail,
1776 gint thickness_light;
1777 gint thickness_dark;
1780 g_return_if_fail (GTK_IS_STYLE (style));
1781 g_return_if_fail (window != NULL);
1783 thickness_light = style->ythickness / 2;
1784 thickness_dark = style->ythickness - thickness_light;
1788 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
1789 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
1792 if (detail && !strcmp (detail, "label"))
1794 if (state_type == GTK_STATE_INSENSITIVE)
1795 gdk_draw_line (window, style->white_gc, x1 + 1, y + 1, x2 + 1, y + 1);
1796 gdk_draw_line (window, style->fg_gc[state_type], x1, y, x2, y);
1800 for (i = 0; i < thickness_dark; i++)
1802 gdk_draw_line (window, style->light_gc[state_type], x2 - i - 1, y + i, x2, y + i);
1803 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x2 - i - 1, y + i);
1806 y += thickness_dark;
1807 for (i = 0; i < thickness_light; i++)
1809 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x1 + thickness_light - i - 1, y + i);
1810 gdk_draw_line (window, style->light_gc[state_type], x1 + thickness_light - i - 1, y + i, x2, y + i);
1816 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
1817 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
1823 gtk_default_draw_vline (GtkStyle *style,
1825 GtkStateType state_type,
1828 const gchar *detail,
1833 gint thickness_light;
1834 gint thickness_dark;
1837 g_return_if_fail (GTK_IS_STYLE (style));
1838 g_return_if_fail (window != NULL);
1840 thickness_light = style->xthickness / 2;
1841 thickness_dark = style->xthickness - thickness_light;
1845 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
1846 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
1848 for (i = 0; i < thickness_dark; i++)
1850 gdk_draw_line (window, style->light_gc[state_type], x + i, y2 - i - 1, x + i, y2);
1851 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y2 - i - 1);
1854 x += thickness_dark;
1855 for (i = 0; i < thickness_light; i++)
1857 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y1 + thickness_light - i);
1858 gdk_draw_line (window, style->light_gc[state_type], x + i, y1 + thickness_light - i, x + i, y2);
1862 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
1863 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
1869 draw_thin_shadow (GtkStyle *style,
1880 sanitize_size (window, &width, &height);
1882 gc1 = style->light_gc[state];
1883 gc2 = style->dark_gc[state];
1887 gdk_gc_set_clip_rectangle (gc1, area);
1888 gdk_gc_set_clip_rectangle (gc2, area);
1891 gdk_draw_line (window, gc1,
1892 x, y + height - 1, x + width - 1, y + height - 1);
1893 gdk_draw_line (window, gc1,
1894 x + width - 1, y, x + width - 1, y + height - 1);
1896 gdk_draw_line (window, gc2,
1897 x, y, x + width - 1, y);
1898 gdk_draw_line (window, gc2,
1899 x, y, x, y + height - 1);
1903 gdk_gc_set_clip_rectangle (gc1, NULL);
1904 gdk_gc_set_clip_rectangle (gc2, NULL);
1909 draw_spin_entry_shadow (GtkStyle *style,
1918 gint window_width, window_height;
1919 gboolean focus_inset;
1921 gdk_window_get_size (window, &window_width, &window_height);
1924 width = window_width;
1926 height = window_height;
1928 focus_inset = (width < window_width && height < window_height);
1932 gdk_gc_set_clip_rectangle (style->light_gc[state], area);
1933 gdk_gc_set_clip_rectangle (style->dark_gc[state], area);
1934 gdk_gc_set_clip_rectangle (style->black_gc, area);
1935 gdk_gc_set_clip_rectangle (style->bg_gc[state], area);
1936 gdk_gc_set_clip_rectangle (style->base_gc[state], area);
1939 gdk_draw_line (window, style->light_gc[state],
1940 x, y + height - 1, x + width - 1, y + height - 1);
1942 gdk_draw_line (window,
1943 style->base_gc[state],
1944 x + width - 1, y + 1, x + width - 1, y + height - 3);
1948 gdk_draw_line (window, style->bg_gc[state],
1949 x + 1, y + height - 2, x + width - 1, y + height - 2);
1950 gdk_draw_line (window,
1951 style->base_gc[state],
1952 x + width - 2, y + 1, x + width - 2, y + height - 3);
1954 gdk_draw_line (window, style->black_gc,
1955 x + 1, y + 1, x + width - 1, y + 1);
1956 gdk_draw_line (window, style->black_gc,
1957 x + 1, y + 1, x + 1, y + height - 2);
1960 gdk_draw_line (window, style->dark_gc[state],
1961 x, y, x + width - 1, y);
1962 gdk_draw_line (window, style->dark_gc[state],
1963 x, y, x, y + height - 1);
1967 gdk_gc_set_clip_rectangle (style->light_gc[state], NULL);
1968 gdk_gc_set_clip_rectangle (style->dark_gc[state], NULL);
1969 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
1970 gdk_gc_set_clip_rectangle (style->bg_gc[state], NULL);
1971 gdk_gc_set_clip_rectangle (style->base_gc[state], NULL);
1976 draw_spinbutton_shadow (GtkStyle *style,
1985 gint y_middle = y + height / 2;
1987 sanitize_size (window, &width, &height);
1991 gdk_gc_set_clip_rectangle (style->black_gc, area);
1992 gdk_gc_set_clip_rectangle (style->bg_gc[state], area);
1993 gdk_gc_set_clip_rectangle (style->dark_gc[state], area);
1994 gdk_gc_set_clip_rectangle (style->light_gc[state], area);
1997 gdk_draw_line (window, style->black_gc,
1998 x, y + 2, x, y + height - 3);
1999 gdk_draw_line (window, style->black_gc,
2000 x, y + 1, x + width - 2, y + 1);
2001 gdk_draw_line (window, style->black_gc,
2002 x + width - 2, y + 2, x + width - 2, y + height - 3);
2004 gdk_draw_line (window, style->bg_gc[state],
2005 x, y + height - 2, x + width - 2, y + height - 2);
2007 gdk_draw_line (window, style->dark_gc[state],
2008 x, y, x + width - 1, y);
2009 gdk_draw_line (window, style->dark_gc[state],
2010 x + 1, y_middle - 1, x + width - 3, y_middle - 1);
2011 gdk_draw_line (window, style->dark_gc[state],
2012 x + 1, y + height - 3, x + width - 3, y + height - 3);
2014 gdk_draw_line (window, style->light_gc[state],
2015 x + 1, y + 2, x + width - 3, y + 2);
2016 gdk_draw_line (window, style->light_gc[state],
2017 x + 1, y_middle, x + width - 3, y_middle);
2018 gdk_draw_line (window, style->light_gc[state],
2019 x + width - 1, y + 1, x + width - 1, y + height - 1);
2020 gdk_draw_line (window, style->light_gc[state],
2021 x, y + height - 1, x + width - 2, y + height - 1);
2025 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2026 gdk_gc_set_clip_rectangle (style->bg_gc[state], NULL);
2027 gdk_gc_set_clip_rectangle (style->dark_gc[state], NULL);
2028 gdk_gc_set_clip_rectangle (style->light_gc[state], NULL);
2033 gtk_default_draw_shadow (GtkStyle *style,
2035 GtkStateType state_type,
2036 GtkShadowType shadow_type,
2039 const gchar *detail,
2047 gint thickness_light;
2048 gint thickness_dark;
2051 g_return_if_fail (GTK_IS_STYLE (style));
2052 g_return_if_fail (window != NULL);
2054 if (shadow_type == GTK_SHADOW_IN)
2056 if (detail && (strcmp (detail, "buttondefault") == 0))
2058 sanitize_size (window, &width, &height);
2060 gdk_draw_rectangle (window, style->black_gc, FALSE,
2061 x, y, width - 1, height - 1);
2065 if (detail && strcmp (detail, "trough") == 0)
2067 draw_thin_shadow (style, window, state_type, area,
2068 x, y, width, height);
2071 else if (widget && GTK_IS_SPIN_BUTTON (widget) &&
2072 detail && strcmp (detail, "entry") == 0)
2074 draw_spin_entry_shadow (style, window, state_type, area,
2075 x, y, width, height);
2078 else if (widget && GTK_IS_SPIN_BUTTON (widget) &&
2079 detail && strcmp (detail, "spinbutton") == 0)
2081 draw_spinbutton_shadow (style, window, state_type,
2082 area, x, y, width, height);
2087 sanitize_size (window, &width, &height);
2089 switch (shadow_type)
2091 case GTK_SHADOW_NONE:
2094 case GTK_SHADOW_ETCHED_IN:
2095 gc1 = style->light_gc[state_type];
2096 gc2 = style->dark_gc[state_type];
2098 case GTK_SHADOW_OUT:
2099 case GTK_SHADOW_ETCHED_OUT:
2100 gc1 = style->dark_gc[state_type];
2101 gc2 = style->light_gc[state_type];
2107 gdk_gc_set_clip_rectangle (gc1, area);
2108 gdk_gc_set_clip_rectangle (gc2, area);
2109 if (shadow_type == GTK_SHADOW_IN ||
2110 shadow_type == GTK_SHADOW_OUT)
2112 gdk_gc_set_clip_rectangle (style->black_gc, area);
2113 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2117 switch (shadow_type)
2119 case GTK_SHADOW_NONE:
2123 /* Light around right and bottom edge */
2125 if (style->ythickness > 0)
2126 gdk_draw_line (window, gc1,
2127 x, y + height - 1, x + width - 1, y + height - 1);
2128 if (style->xthickness > 0)
2129 gdk_draw_line (window, gc1,
2130 x + width - 1, y, x + width - 1, y + height - 1);
2132 if (style->ythickness > 1)
2133 gdk_draw_line (window, style->bg_gc[state_type],
2134 x + 1, y + height - 2, x + width - 2, y + height - 2);
2135 if (style->xthickness > 1)
2136 gdk_draw_line (window, style->bg_gc[state_type],
2137 x + width - 2, y + 1, x + width - 2, y + height - 2);
2139 /* Dark around left and top */
2141 if (style->ythickness > 1)
2142 gdk_draw_line (window, style->black_gc,
2143 x + 1, y + 1, x + width - 2, y + 1);
2144 if (style->xthickness > 1)
2145 gdk_draw_line (window, style->black_gc,
2146 x + 1, y + 1, x + 1, y + height - 2);
2148 if (style->ythickness > 0)
2149 gdk_draw_line (window, gc2,
2150 x, y, x + width - 1, y);
2151 if (style->xthickness > 0)
2152 gdk_draw_line (window, gc2,
2153 x, y, x, y + height - 1);
2156 case GTK_SHADOW_OUT:
2157 /* Dark around right and bottom edge */
2159 if (style->ythickness > 0)
2161 if (style->ythickness > 1)
2163 gdk_draw_line (window, gc1,
2164 x + 1, y + height - 2, x + width - 2, y + height - 2);
2165 gdk_draw_line (window, style->black_gc,
2166 x, y + height - 1, x + width - 1, y + height - 1);
2170 gdk_draw_line (window, gc1,
2171 x + 1, y + height - 1, x + width - 1, y + height - 1);
2175 if (style->xthickness > 0)
2177 if (style->xthickness > 1)
2179 gdk_draw_line (window, gc1,
2180 x + width - 2, y + 1, x + width - 2, y + height - 2);
2182 gdk_draw_line (window, style->black_gc,
2183 x + width - 1, y, x + width - 1, y + height - 1);
2187 gdk_draw_line (window, gc1,
2188 x + width - 1, y + 1, x + width - 1, y + height - 1);
2192 /* Light around top and left */
2194 if (style->ythickness > 0)
2195 gdk_draw_line (window, gc2,
2196 x, y, x + width - 1, y);
2197 if (style->xthickness > 0)
2198 gdk_draw_line (window, gc2,
2199 x, y, x, y + height - 1);
2201 if (style->ythickness > 1)
2202 gdk_draw_line (window, style->bg_gc[state_type],
2203 x + 1, y + 1, x + width - 2, y + 1);
2204 if (style->xthickness > 1)
2205 gdk_draw_line (window, style->bg_gc[state_type],
2206 x + 1, y + 1, x + 1, y + height - 2);
2209 case GTK_SHADOW_ETCHED_IN:
2210 case GTK_SHADOW_ETCHED_OUT:
2211 if (style->xthickness > 0)
2213 if (style->xthickness > 1)
2215 thickness_light = 1;
2218 for (i = 0; i < thickness_dark; i++)
2220 gdk_draw_line (window, gc1,
2224 y + height - i - 1);
2225 gdk_draw_line (window, gc2,
2229 y + height - i - 2);
2232 for (i = 0; i < thickness_light; i++)
2234 gdk_draw_line (window, gc1,
2235 x + thickness_dark + i,
2236 y + thickness_dark + i,
2237 x + thickness_dark + i,
2238 y + height - thickness_dark - i - 1);
2239 gdk_draw_line (window, gc2,
2240 x + width - thickness_light - i - 1,
2241 y + thickness_dark + i,
2242 x + width - thickness_light - i - 1,
2243 y + height - thickness_light - 1);
2248 gdk_draw_line (window,
2249 style->dark_gc[state_type],
2250 x, y, x, y + height);
2251 gdk_draw_line (window,
2252 style->dark_gc[state_type],
2253 x + width, y, x + width, y + height);
2257 if (style->ythickness > 0)
2259 if (style->ythickness > 1)
2261 thickness_light = 1;
2264 for (i = 0; i < thickness_dark; i++)
2266 gdk_draw_line (window, gc1,
2270 y + height - i - 1);
2272 gdk_draw_line (window, gc2,
2279 for (i = 0; i < thickness_light; i++)
2281 gdk_draw_line (window, gc1,
2282 x + thickness_dark + i,
2283 y + thickness_dark + i,
2284 x + width - thickness_dark - i - 1,
2285 y + thickness_dark + i);
2287 gdk_draw_line (window, gc2,
2288 x + thickness_dark + i,
2289 y + height - thickness_light - i - 1,
2290 x + width - thickness_light - 1,
2291 y + height - thickness_light - i - 1);
2296 gdk_draw_line (window,
2297 style->dark_gc[state_type],
2298 x, y, x + width, y);
2299 gdk_draw_line (window,
2300 style->dark_gc[state_type],
2301 x, y + height, x + width, y + height);
2309 gdk_gc_set_clip_rectangle (gc1, NULL);
2310 gdk_gc_set_clip_rectangle (gc2, NULL);
2311 if (shadow_type == GTK_SHADOW_IN ||
2312 shadow_type == GTK_SHADOW_OUT)
2314 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2315 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2321 gtk_default_draw_polygon (GtkStyle *style,
2323 GtkStateType state_type,
2324 GtkShadowType shadow_type,
2327 const gchar *detail,
2332 static const gdouble pi_over_4 = G_PI_4;
2333 static const gdouble pi_3_over_4 = G_PI_4 * 3;
2343 g_return_if_fail (GTK_IS_STYLE (style));
2344 g_return_if_fail (window != NULL);
2345 g_return_if_fail (points != NULL);
2347 switch (shadow_type)
2350 gc1 = style->bg_gc[state_type];
2351 gc2 = style->dark_gc[state_type];
2352 gc3 = style->light_gc[state_type];
2353 gc4 = style->black_gc;
2355 case GTK_SHADOW_ETCHED_IN:
2356 gc1 = style->light_gc[state_type];
2357 gc2 = style->dark_gc[state_type];
2358 gc3 = style->dark_gc[state_type];
2359 gc4 = style->light_gc[state_type];
2361 case GTK_SHADOW_OUT:
2362 gc1 = style->dark_gc[state_type];
2363 gc2 = style->light_gc[state_type];
2364 gc3 = style->black_gc;
2365 gc4 = style->bg_gc[state_type];
2367 case GTK_SHADOW_ETCHED_OUT:
2368 gc1 = style->dark_gc[state_type];
2369 gc2 = style->light_gc[state_type];
2370 gc3 = style->light_gc[state_type];
2371 gc4 = style->dark_gc[state_type];
2379 gdk_gc_set_clip_rectangle (gc1, area);
2380 gdk_gc_set_clip_rectangle (gc2, area);
2381 gdk_gc_set_clip_rectangle (gc3, area);
2382 gdk_gc_set_clip_rectangle (gc4, area);
2386 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, npoints);
2390 for (i = 0; i < npoints; i++)
2392 if ((points[i].x == points[i+1].x) &&
2393 (points[i].y == points[i+1].y))
2399 angle = atan2 (points[i+1].y - points[i].y,
2400 points[i+1].x - points[i].x);
2403 if ((angle > -pi_3_over_4) && (angle < pi_over_4))
2405 if (angle > -pi_over_4)
2416 gdk_draw_line (window, gc1,
2417 points[i].x-xadjust, points[i].y-yadjust,
2418 points[i+1].x-xadjust, points[i+1].y-yadjust);
2419 gdk_draw_line (window, gc3,
2420 points[i].x, points[i].y,
2421 points[i+1].x, points[i+1].y);
2425 if ((angle < -pi_3_over_4) || (angle > pi_3_over_4))
2436 gdk_draw_line (window, gc4,
2437 points[i].x+xadjust, points[i].y+yadjust,
2438 points[i+1].x+xadjust, points[i+1].y+yadjust);
2439 gdk_draw_line (window, gc2,
2440 points[i].x, points[i].y,
2441 points[i+1].x, points[i+1].y);
2447 gdk_gc_set_clip_rectangle (gc1, NULL);
2448 gdk_gc_set_clip_rectangle (gc2, NULL);
2449 gdk_gc_set_clip_rectangle (gc3, NULL);
2450 gdk_gc_set_clip_rectangle (gc4, NULL);
2455 draw_varrow (GdkWindow *window,
2457 GtkShadowType shadow_type,
2459 GtkArrowType arrow_type,
2466 gint y_start, y_increment;
2470 gdk_gc_set_clip_rectangle (gc, area);
2472 width = width + width % 2 - 1; /* Force odd */
2474 steps = 1 + width / 2;
2476 extra = height - steps;
2478 if (arrow_type == GTK_ARROW_DOWN)
2485 y_start = y + height - 1;
2489 for (i = 0; i < extra; i++)
2491 gdk_draw_line (window, gc,
2492 x, y_start + i * y_increment,
2493 x + width - 1, y_start + i * y_increment);
2495 for (; i < height; i++)
2497 gdk_draw_line (window, gc,
2498 x + (i - extra), y_start + i * y_increment,
2499 x + width - (i - extra) - 1, y_start + i * y_increment);
2504 gdk_gc_set_clip_rectangle (gc, NULL);
2508 draw_harrow (GdkWindow *window,
2510 GtkShadowType shadow_type,
2512 GtkArrowType arrow_type,
2519 gint x_start, x_increment;
2523 gdk_gc_set_clip_rectangle (gc, area);
2525 height = height + height % 2 - 1; /* Force odd */
2527 steps = 1 + height / 2;
2529 extra = width - steps;
2531 if (arrow_type == GTK_ARROW_RIGHT)
2538 x_start = x + width - 1;
2542 for (i = 0; i < extra; i++)
2544 gdk_draw_line (window, gc,
2545 x_start + i * x_increment, y,
2546 x_start + i * x_increment, y + height - 1);
2548 for (; i < width; i++)
2550 gdk_draw_line (window, gc,
2551 x_start + i * x_increment, y + (i - extra),
2552 x_start + i * x_increment, y + height - (i - extra) - 1);
2557 gdk_gc_set_clip_rectangle (gc, NULL);
2561 gtk_default_draw_arrow (GtkStyle *style,
2564 GtkShadowType shadow,
2567 const gchar *detail,
2568 GtkArrowType arrow_type,
2575 sanitize_size (window, &width, &height);
2577 if (detail && strcmp (detail, "spinbutton") == 0)
2580 int my_height = height;
2581 int my_width = width;
2584 if (my_height > my_width)
2586 vpad_add = (my_height - my_width) / 2;
2587 my_height = my_width;
2590 hpad = my_width / 4;
2595 vpad = 2 * hpad - 1;
2602 draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
2603 x, y, my_width - hpad, my_height - vpad);
2605 else if (detail && strcmp (detail, "vscrollbar") == 0)
2607 gtk_paint_box (style, window, state, shadow, area,
2608 widget, detail, x, y, width, height);
2610 x += (width - 7) / 2;
2611 y += (height - 5) / 2;
2613 draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
2616 else if (detail && strcmp (detail, "hscrollbar") == 0)
2618 gtk_paint_box (style, window, state, shadow, area,
2619 widget, detail, x, y, width, height);
2621 y += (height - 7) / 2;
2622 x += (width - 5) / 2;
2624 draw_harrow (window, style->fg_gc[state], shadow, area, arrow_type,
2629 if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
2631 x += (width - 7) / 2;
2632 y += (height - 5) / 2;
2634 draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
2639 x += (width - 5) / 2;
2640 y += (height - 7) / 2;
2642 draw_harrow (window, style->fg_gc[state], shadow, area, arrow_type,
2649 gtk_default_draw_diamond (GtkStyle *style,
2651 GtkStateType state_type,
2652 GtkShadowType shadow_type,
2655 const gchar *detail,
2663 GdkGC *outer_nw = NULL;
2664 GdkGC *outer_ne = NULL;
2665 GdkGC *outer_sw = NULL;
2666 GdkGC *outer_se = NULL;
2667 GdkGC *middle_nw = NULL;
2668 GdkGC *middle_ne = NULL;
2669 GdkGC *middle_sw = NULL;
2670 GdkGC *middle_se = NULL;
2671 GdkGC *inner_nw = NULL;
2672 GdkGC *inner_ne = NULL;
2673 GdkGC *inner_sw = NULL;
2674 GdkGC *inner_se = NULL;
2676 g_return_if_fail (GTK_IS_STYLE (style));
2677 g_return_if_fail (window != NULL);
2679 sanitize_size (window, &width, &height);
2681 half_width = width / 2;
2682 half_height = height / 2;
2686 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
2687 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2688 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
2689 gdk_gc_set_clip_rectangle (style->black_gc, area);
2692 switch (shadow_type)
2695 inner_sw = inner_se = style->bg_gc[state_type];
2696 middle_sw = middle_se = style->light_gc[state_type];
2697 outer_sw = outer_se = style->light_gc[state_type];
2698 inner_nw = inner_ne = style->black_gc;
2699 middle_nw = middle_ne = style->dark_gc[state_type];
2700 outer_nw = outer_ne = style->dark_gc[state_type];
2703 case GTK_SHADOW_OUT:
2704 inner_sw = inner_se = style->dark_gc[state_type];
2705 middle_sw = middle_se = style->dark_gc[state_type];
2706 outer_sw = outer_se = style->black_gc;
2707 inner_nw = inner_ne = style->bg_gc[state_type];
2708 middle_nw = middle_ne = style->light_gc[state_type];
2709 outer_nw = outer_ne = style->light_gc[state_type];
2712 case GTK_SHADOW_ETCHED_IN:
2713 inner_sw = inner_se = style->bg_gc[state_type];
2714 middle_sw = middle_se = style->dark_gc[state_type];
2715 outer_sw = outer_se = style->light_gc[state_type];
2716 inner_nw = inner_ne = style->bg_gc[state_type];
2717 middle_nw = middle_ne = style->light_gc[state_type];
2718 outer_nw = outer_ne = style->dark_gc[state_type];
2721 case GTK_SHADOW_ETCHED_OUT:
2722 inner_sw = inner_se = style->bg_gc[state_type];
2723 middle_sw = middle_se = style->light_gc[state_type];
2724 outer_sw = outer_se = style->dark_gc[state_type];
2725 inner_nw = inner_ne = style->bg_gc[state_type];
2726 middle_nw = middle_ne = style->dark_gc[state_type];
2727 outer_nw = outer_ne = style->light_gc[state_type];
2737 gdk_draw_line (window, inner_sw,
2738 x + 2, y + half_height,
2739 x + half_width, y + height - 2);
2740 gdk_draw_line (window, inner_se,
2741 x + half_width, y + height - 2,
2742 x + width - 2, y + half_height);
2743 gdk_draw_line (window, middle_sw,
2744 x + 1, y + half_height,
2745 x + half_width, y + height - 1);
2746 gdk_draw_line (window, middle_se,
2747 x + half_width, y + height - 1,
2748 x + width - 1, y + half_height);
2749 gdk_draw_line (window, outer_sw,
2751 x + half_width, y + height);
2752 gdk_draw_line (window, outer_se,
2753 x + half_width, y + height,
2754 x + width, y + half_height);
2756 gdk_draw_line (window, inner_nw,
2757 x + 2, y + half_height,
2758 x + half_width, y + 2);
2759 gdk_draw_line (window, inner_ne,
2760 x + half_width, y + 2,
2761 x + width - 2, y + half_height);
2762 gdk_draw_line (window, middle_nw,
2763 x + 1, y + half_height,
2764 x + half_width, y + 1);
2765 gdk_draw_line (window, middle_ne,
2766 x + half_width, y + 1,
2767 x + width - 1, y + half_height);
2768 gdk_draw_line (window, outer_nw,
2771 gdk_draw_line (window, outer_ne,
2773 x + width, y + half_height);
2778 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
2779 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2780 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
2781 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2786 gtk_default_draw_string (GtkStyle *style,
2788 GtkStateType state_type,
2791 const gchar *detail,
2794 const gchar *string)
2796 g_return_if_fail (GTK_IS_STYLE (style));
2797 g_return_if_fail (window != NULL);
2801 gdk_gc_set_clip_rectangle (style->white_gc, area);
2802 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], area);
2805 if (state_type == GTK_STATE_INSENSITIVE)
2806 gdk_draw_string (window, gtk_style_get_font (style), style->white_gc, x + 1, y + 1, string);
2808 gdk_draw_string (window, gtk_style_get_font (style), style->fg_gc[state_type], x, y, string);
2812 gdk_gc_set_clip_rectangle (style->white_gc, NULL);
2813 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], NULL);
2818 option_menu_get_props (GtkWidget *widget,
2819 GtkRequisition *indicator_size,
2820 GtkBorder *indicator_spacing)
2822 GtkRequisition *tmp_size = NULL;
2823 GtkBorder *tmp_spacing = NULL;
2826 gtk_widget_style_get (widget,
2827 "indicator_size", &tmp_size,
2828 "indicator_spacing", &tmp_spacing,
2833 *indicator_size = *tmp_size;
2837 *indicator_size = default_option_indicator_size;
2841 *indicator_spacing = *tmp_spacing;
2842 g_free (tmp_spacing);
2845 *indicator_spacing = default_option_indicator_spacing;
2849 gtk_default_draw_box (GtkStyle *style,
2851 GtkStateType state_type,
2852 GtkShadowType shadow_type,
2855 const gchar *detail,
2861 g_return_if_fail (GTK_IS_STYLE (style));
2862 g_return_if_fail (window != NULL);
2864 sanitize_size (window, &width, &height);
2866 if (!style->bg_pixmap[state_type] ||
2867 GDK_IS_PIXMAP (window))
2870 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2872 gdk_draw_rectangle (window, style->bg_gc[state_type], TRUE,
2873 x, y, width, height);
2875 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2878 gtk_style_apply_default_background (style, window,
2879 widget && !GTK_WIDGET_NO_WINDOW (widget),
2880 state_type, area, x, y, width, height);
2882 gtk_paint_shadow (style, window, state_type, shadow_type, area, widget, detail,
2883 x, y, width, height);
2885 if (detail && strcmp (detail, "optionmenu") == 0)
2887 GtkRequisition indicator_size;
2888 GtkBorder indicator_spacing;
2890 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
2892 sanitize_size (window, &width, &height);
2894 gtk_paint_vline (style, window, state_type, area, widget,
2896 y + style->ythickness + 1,
2897 y + height - style->ythickness - 3,
2898 x + width - (indicator_size.width + indicator_spacing.left + indicator_spacing.right) - style->xthickness);
2903 get_darkened_gc (GdkWindow *window,
2907 GdkColor src = *color;
2911 gc = gdk_gc_new (window);
2913 while (darken_count)
2915 gtk_style_shade (&src, &shaded, 0.93);
2920 gdk_gc_set_rgb_fg_color (gc, &shaded);
2926 gtk_default_draw_flat_box (GtkStyle *style,
2928 GtkStateType state_type,
2929 GtkShadowType shadow_type,
2932 const gchar *detail,
2939 GdkGC *freeme = NULL;
2941 g_return_if_fail (GTK_IS_STYLE (style));
2942 g_return_if_fail (window != NULL);
2944 sanitize_size (window, &width, &height);
2948 if (state_type == GTK_STATE_SELECTED)
2950 if (!strcmp ("text", detail))
2951 gc1 = style->bg_gc[GTK_STATE_SELECTED];
2952 else if (!strncmp ("cell_even", detail, strlen ("cell_even")) ||
2953 !strncmp ("cell_odd", detail, strlen ("cell_odd")))
2955 /* This has to be really broken; alex made me do it. -jrb */
2956 if (GTK_WIDGET_HAS_FOCUS (widget))
2957 gc1 = style->base_gc[state_type];
2959 gc1 = style->base_gc[GTK_STATE_ACTIVE];
2963 gc1 = style->bg_gc[state_type];
2968 if (!strcmp ("viewportbin", detail))
2969 gc1 = style->bg_gc[GTK_STATE_NORMAL];
2970 else if (!strcmp ("entry_bg", detail))
2971 gc1 = style->base_gc[state_type];
2973 /* For trees: even rows are base color, odd rows are a shade of
2974 * the base color, the sort column is a shade of the original color
2978 /* FIXME when we have style properties, clean this up.
2981 else if (!strcmp ("cell_even", detail) ||
2982 !strcmp ("cell_odd", detail) ||
2983 !strcmp ("cell_even_ruled", detail))
2985 gc1 = style->base_gc[state_type];
2987 else if (!strcmp ("cell_even_sorted", detail) ||
2988 !strcmp ("cell_odd_sorted", detail) ||
2989 !strcmp ("cell_odd_ruled", detail) ||
2990 !strcmp ("cell_even_ruled_sorted", detail))
2992 freeme = get_darkened_gc (window, &style->base[state_type], 1);
2995 else if (!strcmp ("cell_odd_ruled_sorted", detail))
2997 freeme = get_darkened_gc (window, &style->base[state_type], 2);
3001 gc1 = style->bg_gc[state_type];
3005 gc1 = style->bg_gc[state_type];
3007 if (!style->bg_pixmap[state_type] || gc1 != style->bg_gc[state_type] ||
3008 GDK_IS_PIXMAP (window))
3011 gdk_gc_set_clip_rectangle (gc1, area);
3013 gdk_draw_rectangle (window, gc1, TRUE,
3014 x, y, width, height);
3016 if (detail && !strcmp ("tooltip", detail))
3017 gdk_draw_rectangle (window, style->black_gc, FALSE,
3018 x, y, width - 1, height - 1);
3021 gdk_gc_set_clip_rectangle (gc1, NULL);
3024 gtk_style_apply_default_background (style, window,
3025 widget && !GTK_WIDGET_NO_WINDOW (widget),
3026 state_type, area, x, y, width, height);
3030 g_object_unref (G_OBJECT (freeme));
3034 gtk_default_draw_check (GtkStyle *style,
3036 GtkStateType state_type,
3037 GtkShadowType shadow_type,
3040 const gchar *detail,
3046 if (detail && strcmp (detail, "cellcheck") == 0)
3048 gdk_draw_rectangle (window,
3049 widget->style->base_gc[state_type],
3053 gdk_draw_rectangle (window,
3054 widget->style->text_gc[state_type],
3059 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3060 y -= (((1 + INDICATOR_PART_SIZE - height) / 2) - 1);
3061 if (shadow_type == GTK_SHADOW_IN)
3063 draw_part (window, style->text_gc[state_type], area, x, y, CHECK_TEXT);
3064 draw_part (window, style->text_aa_gc[state_type], area, x, y, CHECK_AA);
3069 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3070 y -= (1 + INDICATOR_PART_SIZE - height) / 2;
3072 if (strcmp (detail, "check") == 0) /* Menu item */
3074 if (shadow_type == GTK_SHADOW_IN)
3076 draw_part (window, style->black_gc, area, x, y, CHECK_TEXT);
3077 draw_part (window, style->dark_gc[state_type], area, x, y, CHECK_AA);
3082 draw_part (window, style->black_gc, area, x, y, CHECK_BLACK);
3083 draw_part (window, style->dark_gc[state_type], area, x, y, CHECK_DARK);
3084 draw_part (window, style->mid_gc[state_type], area, x, y, CHECK_MID);
3085 draw_part (window, style->light_gc[state_type], area, x, y, CHECK_LIGHT);
3086 draw_part (window, style->base_gc[state_type], area, x, y, CHECK_BASE);
3088 if (shadow_type == GTK_SHADOW_IN)
3090 draw_part (window, style->text_gc[state_type], area, x, y, CHECK_TEXT);
3091 draw_part (window, style->text_aa_gc[state_type], area, x, y, CHECK_AA);
3099 gtk_default_draw_option (GtkStyle *style,
3101 GtkStateType state_type,
3102 GtkShadowType shadow_type,
3105 const gchar *detail,
3111 if (detail && strcmp (detail, "cellradio") == 0)
3113 gdk_draw_arc (window,
3114 widget->style->fg_gc[state_type],
3121 if (shadow_type == GTK_SHADOW_IN)
3123 gdk_draw_arc (window,
3124 widget->style->fg_gc[state_type],
3135 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3136 y -= (1 + INDICATOR_PART_SIZE - height) / 2;
3138 if (strcmp (detail, "option") == 0) /* Menu item */
3140 if (shadow_type == GTK_SHADOW_IN)
3141 draw_part (window, style->fg_gc[state_type], area, x, y, RADIO_TEXT);
3145 draw_part (window, style->black_gc, area, x, y, RADIO_BLACK);
3146 draw_part (window, style->dark_gc[state_type], area, x, y, RADIO_DARK);
3147 draw_part (window, style->mid_gc[state_type], area, x, y, RADIO_MID);
3148 draw_part (window, style->light_gc[state_type], area, x, y, RADIO_LIGHT);
3149 draw_part (window, style->base_gc[state_type], area, x, y, RADIO_BASE);
3151 if (shadow_type == GTK_SHADOW_IN)
3152 draw_part (window, style->text_gc[state_type], area, x, y, RADIO_TEXT);
3158 gtk_default_draw_tab (GtkStyle *style,
3160 GtkStateType state_type,
3161 GtkShadowType shadow_type,
3164 const gchar *detail,
3170 GtkRequisition indicator_size;
3171 GtkBorder indicator_spacing;
3173 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
3175 x += (width - indicator_size.width) / 2;
3176 y += (height - indicator_size.height) / 2 - 1;
3178 draw_varrow (window, style->black_gc, shadow_type, area, GTK_ARROW_UP,
3179 x, y, indicator_size.width, 5);
3180 draw_varrow (window, style->black_gc, shadow_type, area, GTK_ARROW_DOWN,
3181 x, y + 8, indicator_size.width, 5);
3185 gtk_default_draw_shadow_gap (GtkStyle *style,
3187 GtkStateType state_type,
3188 GtkShadowType shadow_type,
3191 const gchar *detail,
3196 GtkPositionType gap_side,
3205 g_return_if_fail (GTK_IS_STYLE (style));
3206 g_return_if_fail (window != NULL);
3208 sanitize_size (window, &width, &height);
3210 switch (shadow_type)
3212 case GTK_SHADOW_NONE:
3215 gc1 = style->dark_gc[state_type];
3216 gc2 = style->black_gc;
3217 gc3 = style->bg_gc[state_type];
3218 gc4 = style->light_gc[state_type];
3220 case GTK_SHADOW_ETCHED_IN:
3221 gc1 = style->dark_gc[state_type];
3222 gc2 = style->light_gc[state_type];
3223 gc3 = style->dark_gc[state_type];
3224 gc4 = style->light_gc[state_type];
3226 case GTK_SHADOW_OUT:
3227 gc1 = style->light_gc[state_type];
3228 gc2 = style->bg_gc[state_type];
3229 gc3 = style->dark_gc[state_type];
3230 gc4 = style->black_gc;
3232 case GTK_SHADOW_ETCHED_OUT:
3233 gc1 = style->light_gc[state_type];
3234 gc2 = style->dark_gc[state_type];
3235 gc3 = style->light_gc[state_type];
3236 gc4 = style->dark_gc[state_type];
3241 gdk_gc_set_clip_rectangle (gc1, area);
3242 gdk_gc_set_clip_rectangle (gc2, area);
3243 gdk_gc_set_clip_rectangle (gc3, area);
3244 gdk_gc_set_clip_rectangle (gc4, area);
3247 switch (shadow_type)
3249 case GTK_SHADOW_NONE:
3251 case GTK_SHADOW_OUT:
3252 case GTK_SHADOW_ETCHED_IN:
3253 case GTK_SHADOW_ETCHED_OUT:
3257 gdk_draw_line (window, gc1,
3258 x, y, x, y + height - 1);
3259 gdk_draw_line (window, gc2,
3260 x + 1, y, x + 1, y + height - 2);
3262 gdk_draw_line (window, gc3,
3263 x + 1, y + height - 2, x + width - 2, y + height - 2);
3264 gdk_draw_line (window, gc3,
3265 x + width - 2, y, x + width - 2, y + height - 2);
3266 gdk_draw_line (window, gc4,
3267 x, y + height - 1, x + width - 1, y + height - 1);
3268 gdk_draw_line (window, gc4,
3269 x + width - 1, y, x + width - 1, y + height - 1);
3272 gdk_draw_line (window, gc1,
3273 x, y, x + gap_x - 1, y);
3274 gdk_draw_line (window, gc2,
3275 x + 1, y + 1, x + gap_x - 1, y + 1);
3276 gdk_draw_line (window, gc2,
3277 x + gap_x, y, x + gap_x, y);
3279 if ((width - (gap_x + gap_width)) > 0)
3281 gdk_draw_line (window, gc1,
3282 x + gap_x + gap_width, y, x + width - 2, y);
3283 gdk_draw_line (window, gc2,
3284 x + gap_x + gap_width, y + 1, x + width - 2, y + 1);
3285 gdk_draw_line (window, gc2,
3286 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
3289 case GTK_POS_BOTTOM:
3290 gdk_draw_line (window, gc1,
3291 x, y, x + width - 1, y);
3292 gdk_draw_line (window, gc1,
3293 x, y, x, y + height - 1);
3294 gdk_draw_line (window, gc2,
3295 x + 1, y + 1, x + width - 2, y + 1);
3296 gdk_draw_line (window, gc2,
3297 x + 1, y + 1, x + 1, y + height - 1);
3299 gdk_draw_line (window, gc3,
3300 x + width - 2, y + 1, x + width - 2, y + height - 1);
3301 gdk_draw_line (window, gc4,
3302 x + width - 1, y, x + width - 1, y + height - 1);
3305 gdk_draw_line (window, gc4,
3306 x, y + height - 1, x + gap_x - 1, y + height - 1);
3307 gdk_draw_line (window, gc3,
3308 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
3309 gdk_draw_line (window, gc3,
3310 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
3312 if ((width - (gap_x + gap_width)) > 0)
3314 gdk_draw_line (window, gc4,
3315 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
3316 gdk_draw_line (window, gc3,
3317 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
3318 gdk_draw_line (window, gc3,
3319 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
3323 gdk_draw_line (window, gc1,
3324 x, y, x + width - 1, y);
3325 gdk_draw_line (window, gc2,
3326 x, y + 1, x + width - 2, y + 1);
3328 gdk_draw_line (window, gc3,
3329 x, y + height - 2, x + width - 2, y + height - 2);
3330 gdk_draw_line (window, gc3,
3331 x + width - 2, y + 1, x + width - 2, y + height - 2);
3332 gdk_draw_line (window, gc4,
3333 x, y + height - 1, x + width - 1, y + height - 1);
3334 gdk_draw_line (window, gc4,
3335 x + width - 1, y, x + width - 1, y + height - 1);
3338 gdk_draw_line (window, gc1,
3339 x, y, x, y + gap_x - 1);
3340 gdk_draw_line (window, gc2,
3341 x + 1, y + 1, x + 1, y + gap_x - 1);
3342 gdk_draw_line (window, gc2,
3343 x, y + gap_x, x, y + gap_x);
3345 if ((width - (gap_x + gap_width)) > 0)
3347 gdk_draw_line (window, gc1,
3348 x, y + gap_x + gap_width, x, y + height - 2);
3349 gdk_draw_line (window, gc2,
3350 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
3351 gdk_draw_line (window, gc2,
3352 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
3356 gdk_draw_line (window, gc1,
3357 x, y, x + width - 1, y);
3358 gdk_draw_line (window, gc1,
3359 x, y, x, y + height - 1);
3360 gdk_draw_line (window, gc2,
3361 x + 1, y + 1, x + width - 1, y + 1);
3362 gdk_draw_line (window, gc2,
3363 x + 1, y + 1, x + 1, y + height - 2);
3365 gdk_draw_line (window, gc3,
3366 x + 1, y + height - 2, x + width - 1, y + height - 2);
3367 gdk_draw_line (window, gc4,
3368 x, y + height - 1, x + width - 1, y + height - 1);
3371 gdk_draw_line (window, gc4,
3372 x + width - 1, y, x + width - 1, y + gap_x - 1);
3373 gdk_draw_line (window, gc3,
3374 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
3375 gdk_draw_line (window, gc3,
3376 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
3378 if ((width - (gap_x + gap_width)) > 0)
3380 gdk_draw_line (window, gc4,
3381 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
3382 gdk_draw_line (window, gc3,
3383 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
3384 gdk_draw_line (window, gc3,
3385 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
3393 gdk_gc_set_clip_rectangle (gc1, NULL);
3394 gdk_gc_set_clip_rectangle (gc2, NULL);
3395 gdk_gc_set_clip_rectangle (gc3, NULL);
3396 gdk_gc_set_clip_rectangle (gc4, NULL);
3401 gtk_default_draw_box_gap (GtkStyle *style,
3403 GtkStateType state_type,
3404 GtkShadowType shadow_type,
3407 const gchar *detail,
3412 GtkPositionType gap_side,
3421 g_return_if_fail (GTK_IS_STYLE (style));
3422 g_return_if_fail (window != NULL);
3424 gtk_style_apply_default_background (style, window,
3425 widget && !GTK_WIDGET_NO_WINDOW (widget),
3426 state_type, area, x, y, width, height);
3428 sanitize_size (window, &width, &height);
3430 switch (shadow_type)
3432 case GTK_SHADOW_NONE:
3435 gc1 = style->dark_gc[state_type];
3436 gc2 = style->black_gc;
3437 gc3 = style->bg_gc[state_type];
3438 gc4 = style->light_gc[state_type];
3440 case GTK_SHADOW_ETCHED_IN:
3441 gc1 = style->dark_gc[state_type];
3442 gc2 = style->light_gc[state_type];
3443 gc3 = style->dark_gc[state_type];
3444 gc4 = style->light_gc[state_type];
3446 case GTK_SHADOW_OUT:
3447 gc1 = style->light_gc[state_type];
3448 gc2 = style->bg_gc[state_type];
3449 gc3 = style->dark_gc[state_type];
3450 gc4 = style->black_gc;
3452 case GTK_SHADOW_ETCHED_OUT:
3453 gc1 = style->light_gc[state_type];
3454 gc2 = style->dark_gc[state_type];
3455 gc3 = style->light_gc[state_type];
3456 gc4 = style->dark_gc[state_type];
3462 gdk_gc_set_clip_rectangle (gc1, area);
3463 gdk_gc_set_clip_rectangle (gc2, area);
3464 gdk_gc_set_clip_rectangle (gc3, area);
3465 gdk_gc_set_clip_rectangle (gc4, area);
3468 switch (shadow_type)
3470 case GTK_SHADOW_NONE:
3472 case GTK_SHADOW_OUT:
3473 case GTK_SHADOW_ETCHED_IN:
3474 case GTK_SHADOW_ETCHED_OUT:
3478 gdk_draw_line (window, gc1,
3479 x, y, x, y + height - 1);
3480 gdk_draw_line (window, gc2,
3481 x + 1, y, x + 1, y + height - 2);
3483 gdk_draw_line (window, gc3,
3484 x + 1, y + height - 2, x + width - 2, y + height - 2);
3485 gdk_draw_line (window, gc3,
3486 x + width - 2, y, x + width - 2, y + height - 2);
3487 gdk_draw_line (window, gc4,
3488 x, y + height - 1, x + width - 1, y + height - 1);
3489 gdk_draw_line (window, gc4,
3490 x + width - 1, y, x + width - 1, y + height - 1);
3493 gdk_draw_line (window, gc1,
3494 x, y, x + gap_x - 1, y);
3495 gdk_draw_line (window, gc2,
3496 x + 1, y + 1, x + gap_x - 1, y + 1);
3497 gdk_draw_line (window, gc2,
3498 x + gap_x, y, x + gap_x, y);
3500 if ((width - (gap_x + gap_width)) > 0)
3502 gdk_draw_line (window, gc1,
3503 x + gap_x + gap_width, y, x + width - 2, y);
3504 gdk_draw_line (window, gc2,
3505 x + gap_x + gap_width, y + 1, x + width - 2, y + 1);
3506 gdk_draw_line (window, gc2,
3507 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
3510 case GTK_POS_BOTTOM:
3511 gdk_draw_line (window, gc1,
3512 x, y, x + width - 1, y);
3513 gdk_draw_line (window, gc1,
3514 x, y, x, y + height - 1);
3515 gdk_draw_line (window, gc2,
3516 x + 1, y + 1, x + width - 2, y + 1);
3517 gdk_draw_line (window, gc2,
3518 x + 1, y + 1, x + 1, y + height - 1);
3520 gdk_draw_line (window, gc3,
3521 x + width - 2, y + 1, x + width - 2, y + height - 1);
3522 gdk_draw_line (window, gc4,
3523 x + width - 1, y, x + width - 1, y + height - 1);
3526 gdk_draw_line (window, gc4,
3527 x, y + height - 1, x + gap_x - 1, y + height - 1);
3528 gdk_draw_line (window, gc3,
3529 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
3530 gdk_draw_line (window, gc3,
3531 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
3533 if ((width - (gap_x + gap_width)) > 0)
3535 gdk_draw_line (window, gc4,
3536 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
3537 gdk_draw_line (window, gc3,
3538 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
3539 gdk_draw_line (window, gc3,
3540 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
3544 gdk_draw_line (window, gc1,
3545 x, y, x + width - 1, y);
3546 gdk_draw_line (window, gc2,
3547 x, y + 1, x + width - 2, y + 1);
3549 gdk_draw_line (window, gc3,
3550 x, y + height - 2, x + width - 2, y + height - 2);
3551 gdk_draw_line (window, gc3,
3552 x + width - 2, y + 1, x + width - 2, y + height - 2);
3553 gdk_draw_line (window, gc4,
3554 x, y + height - 1, x + width - 1, y + height - 1);
3555 gdk_draw_line (window, gc4,
3556 x + width - 1, y, x + width - 1, y + height - 1);
3559 gdk_draw_line (window, gc1,
3560 x, y, x, y + gap_x - 1);
3561 gdk_draw_line (window, gc2,
3562 x + 1, y + 1, x + 1, y + gap_x - 1);
3563 gdk_draw_line (window, gc2,
3564 x, y + gap_x, x, y + gap_x);
3566 if ((width - (gap_x + gap_width)) > 0)
3568 gdk_draw_line (window, gc1,
3569 x, y + gap_x + gap_width, x, y + height - 2);
3570 gdk_draw_line (window, gc2,
3571 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
3572 gdk_draw_line (window, gc2,
3573 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
3577 gdk_draw_line (window, gc1,
3578 x, y, x + width - 1, y);
3579 gdk_draw_line (window, gc1,
3580 x, y, x, y + height - 1);
3581 gdk_draw_line (window, gc2,
3582 x + 1, y + 1, x + width - 1, y + 1);
3583 gdk_draw_line (window, gc2,
3584 x + 1, y + 1, x + 1, y + height - 2);
3586 gdk_draw_line (window, gc3,
3587 x + 1, y + height - 2, x + width - 1, y + height - 2);
3588 gdk_draw_line (window, gc4,
3589 x, y + height - 1, x + width - 1, y + height - 1);
3592 gdk_draw_line (window, gc4,
3593 x + width - 1, y, x + width - 1, y + gap_x - 1);
3594 gdk_draw_line (window, gc3,
3595 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
3596 gdk_draw_line (window, gc3,
3597 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
3599 if ((width - (gap_x + gap_width)) > 0)
3601 gdk_draw_line (window, gc4,
3602 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
3603 gdk_draw_line (window, gc3,
3604 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
3605 gdk_draw_line (window, gc3,
3606 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
3614 gdk_gc_set_clip_rectangle (gc1, NULL);
3615 gdk_gc_set_clip_rectangle (gc2, NULL);
3616 gdk_gc_set_clip_rectangle (gc3, NULL);
3617 gdk_gc_set_clip_rectangle (gc4, NULL);
3622 gtk_default_draw_extension (GtkStyle *style,
3624 GtkStateType state_type,
3625 GtkShadowType shadow_type,
3628 const gchar *detail,
3633 GtkPositionType gap_side)
3640 g_return_if_fail (GTK_IS_STYLE (style));
3641 g_return_if_fail (window != NULL);
3643 gtk_style_apply_default_background (style, window,
3644 widget && !GTK_WIDGET_NO_WINDOW (widget),
3645 GTK_STATE_NORMAL, area, x, y, width, height);
3647 sanitize_size (window, &width, &height);
3649 switch (shadow_type)
3651 case GTK_SHADOW_NONE:
3654 gc1 = style->dark_gc[state_type];
3655 gc2 = style->black_gc;
3656 gc3 = style->bg_gc[state_type];
3657 gc4 = style->light_gc[state_type];
3659 case GTK_SHADOW_ETCHED_IN:
3660 gc1 = style->dark_gc[state_type];
3661 gc2 = style->light_gc[state_type];
3662 gc3 = style->dark_gc[state_type];
3663 gc4 = style->light_gc[state_type];
3665 case GTK_SHADOW_OUT:
3666 gc1 = style->light_gc[state_type];
3667 gc2 = style->bg_gc[state_type];
3668 gc3 = style->dark_gc[state_type];
3669 gc4 = style->black_gc;
3671 case GTK_SHADOW_ETCHED_OUT:
3672 gc1 = style->light_gc[state_type];
3673 gc2 = style->dark_gc[state_type];
3674 gc3 = style->light_gc[state_type];
3675 gc4 = style->dark_gc[state_type];
3681 gdk_gc_set_clip_rectangle (gc1, area);
3682 gdk_gc_set_clip_rectangle (gc2, area);
3683 gdk_gc_set_clip_rectangle (gc3, area);
3684 gdk_gc_set_clip_rectangle (gc4, area);
3687 switch (shadow_type)
3689 case GTK_SHADOW_NONE:
3691 case GTK_SHADOW_OUT:
3692 case GTK_SHADOW_ETCHED_IN:
3693 case GTK_SHADOW_ETCHED_OUT:
3697 gtk_style_apply_default_background (style, window,
3698 widget && !GTK_WIDGET_NO_WINDOW (widget),
3700 x + style->xthickness,
3702 width - (2 * style->xthickness),
3703 height - (style->ythickness));
3704 gdk_draw_line (window, gc1,
3705 x, y, x, y + height - 2);
3706 gdk_draw_line (window, gc2,
3707 x + 1, y, x + 1, y + height - 2);
3709 gdk_draw_line (window, gc3,
3710 x + 2, y + height - 2, x + width - 2, y + height - 2);
3711 gdk_draw_line (window, gc3,
3712 x + width - 2, y, x + width - 2, y + height - 2);
3713 gdk_draw_line (window, gc4,
3714 x + 1, y + height - 1, x + width - 2, y + height - 1);
3715 gdk_draw_line (window, gc4,
3716 x + width - 1, y, x + width - 1, y + height - 2);
3718 case GTK_POS_BOTTOM:
3719 gtk_style_apply_default_background (style, window,
3720 widget && !GTK_WIDGET_NO_WINDOW (widget),
3722 x + style->xthickness,
3723 y + style->ythickness,
3724 width - (2 * style->xthickness),
3725 height - (style->ythickness));
3726 gdk_draw_line (window, gc1,
3727 x + 1, y, x + width - 2, y);
3728 gdk_draw_line (window, gc1,
3729 x, y + 1, x, y + height - 1);
3730 gdk_draw_line (window, gc2,
3731 x + 1, y + 1, x + width - 2, y + 1);
3732 gdk_draw_line (window, gc2,
3733 x + 1, y + 1, x + 1, y + height - 1);
3735 gdk_draw_line (window, gc3,
3736 x + width - 2, y + 2, x + width - 2, y + height - 1);
3737 gdk_draw_line (window, gc4,
3738 x + width - 1, y + 1, x + width - 1, y + height - 1);
3741 gtk_style_apply_default_background (style, window,
3742 widget && !GTK_WIDGET_NO_WINDOW (widget),
3745 y + style->ythickness,
3746 width - (style->xthickness),
3747 height - (2 * style->ythickness));
3748 gdk_draw_line (window, gc1,
3749 x, y, x + width - 2, y);
3750 gdk_draw_line (window, gc2,
3751 x + 1, y + 1, x + width - 2, y + 1);
3753 gdk_draw_line (window, gc3,
3754 x, y + height - 2, x + width - 2, y + height - 2);
3755 gdk_draw_line (window, gc3,
3756 x + width - 2, y + 2, x + width - 2, y + height - 2);
3757 gdk_draw_line (window, gc4,
3758 x, y + height - 1, x + width - 2, y + height - 1);
3759 gdk_draw_line (window, gc4,
3760 x + width - 1, y + 1, x + width - 1, y + height - 2);
3763 gtk_style_apply_default_background (style, window,
3764 widget && !GTK_WIDGET_NO_WINDOW (widget),
3766 x + style->xthickness,
3767 y + style->ythickness,
3768 width - (style->xthickness),
3769 height - (2 * style->ythickness));
3770 gdk_draw_line (window, gc1,
3771 x + 1, y, x + width - 1, y);
3772 gdk_draw_line (window, gc1,
3773 x, y + 1, x, y + height - 2);
3774 gdk_draw_line (window, gc2,
3775 x + 1, y + 1, x + width - 1, y + 1);
3776 gdk_draw_line (window, gc2,
3777 x + 1, y + 1, x + 1, y + height - 2);
3779 gdk_draw_line (window, gc3,
3780 x + 2, y + height - 2, x + width - 1, y + height - 2);
3781 gdk_draw_line (window, gc4,
3782 x + 1, y + height - 1, x + width - 1, y + height - 1);
3789 gdk_gc_set_clip_rectangle (gc1, NULL);
3790 gdk_gc_set_clip_rectangle (gc2, NULL);
3791 gdk_gc_set_clip_rectangle (gc3, NULL);
3792 gdk_gc_set_clip_rectangle (gc4, NULL);
3797 gtk_default_draw_focus (GtkStyle *style,
3799 GtkStateType state_type,
3802 const gchar *detail,
3810 gint line_width = 1;
3811 gchar *dash_list = "\1\1";
3814 gc = style->fg_gc[state_type];
3817 gtk_widget_style_get (widget,
3818 "focus-line-width", &line_width,
3819 "focus-line-pattern", (gchar *)&dash_list,
3822 sanitize_size (window, &width, &height);
3825 gdk_gc_set_clip_rectangle (gc, area);
3827 gdk_gc_set_line_attributes (gc, line_width,
3828 dash_list[0] ? GDK_LINE_ON_OFF_DASH : GDK_LINE_SOLID,
3829 GDK_CAP_BUTT, GDK_JOIN_MITER);
3832 if (detail && !strcmp (detail, "add-mode"))
3835 points[0].x = x + line_width / 2;
3836 points[0].y = y + line_width / 2;
3837 points[1].x = x + width - line_width + line_width / 2;
3838 points[1].y = y + line_width / 2;
3839 points[2].x = x + width - line_width + line_width / 2;
3840 points[2].y = y + height - line_width + line_width / 2;
3841 points[3].x = x + line_width / 2;
3842 points[3].y = y + height - line_width + line_width / 2;
3843 points[4] = points[0];
3847 gdk_draw_lines (window, gc, points, 5);
3851 /* We go through all the pain below because the X rasterization
3852 * rules don't really work right for dashed lines if you
3853 * want continuity in segments that go between top/right
3854 * and left/bottom. For instance, a top left corner
3855 * with a 1-1 dash is drawn as:
3862 * This is because pixels on the top and left boundaries
3863 * of polygons are drawn, but not on the bottom and right.
3864 * So, if you have a line going up that turns the corner
3865 * and goes right, there is a one pixel shift in the pattern.
3867 * So, to fix this, we drawn the top and right in one call,
3868 * then the left and bottom in another call, fixing up
3869 * the dash offset for the second call ourselves to get
3870 * continuity at the upper left.
3872 * It's not perfect since we really should have a join at
3873 * the upper left and lower right instead of two intersecting
3874 * lines but that's only really apparent for no-dashes,
3875 * which (for this reason) are done as one polygon and
3876 * don't to through this code path.
3879 dash_len = strlen (dash_list);
3882 gdk_gc_set_dashes (gc, 0, dash_list, dash_len);
3884 gdk_draw_lines (window, gc, points, 3);
3886 /* We draw this line one farther over than it is "supposed" to
3887 * because of another rasterization problem ... if two 1 pixel
3888 * unjoined lines meet at the lower right, there will be a missing
3895 gint dash_pixels = 0;
3898 /* Adjust the dash offset for the bottom and left so we
3899 * match up at the upper left.
3901 for (i = 0; i < dash_len; i++)
3902 dash_pixels += dash_list[i];
3904 if (dash_len % 2 == 1)
3907 gdk_gc_set_dashes (gc, dash_pixels - (width + height - 2 * line_width) % dash_pixels, dash_list, dash_len);
3910 gdk_draw_lines (window, gc, points + 2, 3);
3913 gdk_gc_set_line_attributes (gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
3916 gdk_gc_set_clip_rectangle (gc, NULL);
3920 gtk_default_draw_slider (GtkStyle *style,
3922 GtkStateType state_type,
3923 GtkShadowType shadow_type,
3926 const gchar *detail,
3931 GtkOrientation orientation)
3933 g_return_if_fail (GTK_IS_STYLE (style));
3934 g_return_if_fail (window != NULL);
3936 sanitize_size (window, &width, &height);
3938 gtk_paint_box (style, window, state_type, shadow_type,
3939 area, widget, detail, x, y, width, height);
3942 (strcmp ("hscale", detail) == 0 ||
3943 strcmp ("vscale", detail) == 0))
3945 if (orientation == GTK_ORIENTATION_HORIZONTAL)
3946 gtk_paint_vline (style, window, state_type, area, widget, detail,
3947 y + style->ythickness,
3948 y + height - style->ythickness - 1, x + width / 2);
3950 gtk_paint_hline (style, window, state_type, area, widget, detail,
3951 x + style->xthickness,
3952 x + width - style->xthickness - 1, y + height / 2);
3957 draw_dot (GdkWindow *window,
3965 size = CLAMP (size, 2, 3);
3969 gdk_draw_point (window, light_gc, x, y);
3970 gdk_draw_point (window, light_gc, x+1, y+1);
3972 else if (size == 3);
3974 gdk_draw_point (window, light_gc, x, y);
3975 gdk_draw_point (window, light_gc, x+1, y);
3976 gdk_draw_point (window, light_gc, x, y+1);
3977 gdk_draw_point (window, dark_gc, x+1, y+2);
3978 gdk_draw_point (window, dark_gc, x+2, y+1);
3979 gdk_draw_point (window, dark_gc, x+2, y+2);
3984 gtk_default_draw_handle (GtkStyle *style,
3986 GtkStateType state_type,
3987 GtkShadowType shadow_type,
3990 const gchar *detail,
3995 GtkOrientation orientation)
3998 gint xthick, ythick;
3999 GdkGC *light_gc, *dark_gc;
4004 g_return_if_fail (GTK_IS_STYLE (style));
4005 g_return_if_fail (window != NULL);
4007 sanitize_size (window, &width, &height);
4009 gtk_paint_box (style, window, state_type, shadow_type, area, widget,
4010 detail, x, y, width, height);
4013 if (!strcmp (detail, "paned"))
4015 /* we want to ignore the shadow border in paned widgets */
4019 light_gc = style->light_gc[state_type];
4020 dark_gc = style->black_gc;
4024 xthick = style->xthickness;
4025 ythick = style->ythickness;
4027 light_gc = style->light_gc[state_type];
4028 dark_gc = style->dark_gc[state_type];
4031 rect.x = x + xthick;
4032 rect.y = y + ythick;
4033 rect.width = width - (xthick * 2);
4034 rect.height = height - (ythick * 2);
4037 intersect = gdk_rectangle_intersect (area, &rect, &dest);
4047 gdk_gc_set_clip_rectangle (light_gc, &dest);
4048 gdk_gc_set_clip_rectangle (dark_gc, &dest);
4050 if (!strcmp (detail, "paned"))
4052 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4053 for (xx = x + width/2 - 15; xx <= x + width/2 + 15; xx += 5)
4054 draw_dot (window, light_gc, dark_gc, xx, y + height/2 - 1, 3);
4056 for (yy = y + height/2 - 15; yy <= y + height/2 + 15; yy += 5)
4057 draw_dot (window, light_gc, dark_gc, x + width/2 - 1, yy, 3);
4061 for (yy = y + ythick; yy < (y + height - ythick); yy += 3)
4062 for (xx = x + xthick; xx < (x + width - xthick); xx += 6)
4064 draw_dot (window, light_gc, dark_gc, xx, yy, 2);
4065 draw_dot (window, light_gc, dark_gc, xx + 3, yy + 1, 2);
4069 gdk_gc_set_clip_rectangle (light_gc, NULL);
4070 gdk_gc_set_clip_rectangle (dark_gc, NULL);
4074 create_expander_affine (gdouble affine[6],
4084 width = expander_size / 4.0;
4085 height = expander_size / 2.0;
4087 s = sin (degrees * G_PI / 180.0);
4088 c = cos (degrees * G_PI / 180.0);
4094 affine[4] = -width * c - height * -s + x;
4095 affine[5] = -width * s - height * c + y;
4099 apply_affine_on_point (double affine[6], GdkPoint *point)
4103 x = point->x * affine[0] + point->y * affine[2] + affine[4];
4104 y = point->x * affine[1] + point->y * affine[3] + affine[5];
4111 gtk_default_draw_expander (GtkStyle *style,
4113 GtkStateType state_type,
4116 const gchar *detail,
4119 GtkExpanderStyle expander_style)
4127 gtk_widget_style_get (widget,
4128 "expander_size", &expander_size,
4133 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], area);
4134 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], area);
4139 points[1].x = expander_size / 2;
4140 points[1].y = expander_size / 2;
4142 points[2].y = expander_size;
4144 switch (expander_style)
4146 case GTK_EXPANDER_COLLAPSED:
4149 case GTK_EXPANDER_SEMI_COLLAPSED:
4152 case GTK_EXPANDER_SEMI_EXPANDED:
4155 case GTK_EXPANDER_EXPANDED:
4159 g_assert_not_reached ();
4162 create_expander_affine (affine, degrees, expander_size, x, y);
4164 for (i = 0; i < 3; i++)
4165 apply_affine_on_point (affine, &points[i]);
4167 if (state_type == GTK_STATE_PRELIGHT)
4169 gdk_draw_polygon (window, style->fg_gc[GTK_STATE_NORMAL],
4172 else if (state_type == GTK_STATE_ACTIVE)
4174 gdk_draw_polygon (window, style->light_gc[GTK_STATE_ACTIVE],
4176 gdk_draw_polygon (window, style->fg_gc[GTK_STATE_NORMAL],
4181 gdk_draw_polygon (window, style->base_gc[GTK_STATE_NORMAL],
4183 gdk_draw_polygon (window, style->fg_gc[GTK_STATE_NORMAL],
4188 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], NULL);
4189 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], NULL);
4193 typedef struct _ByteRange ByteRange;
4202 range_new (guint start,
4205 ByteRange *br = g_new (ByteRange, 1);
4214 get_insensitive_layout (PangoLayout *layout)
4216 GSList *embossed_ranges = NULL;
4217 GSList *stippled_ranges = NULL;
4218 PangoLayoutIter *iter;
4219 GSList *tmp_list = NULL;
4220 PangoLayout *new_layout;
4221 PangoAttrList *attrs;
4222 GdkBitmap *stipple = NULL;
4224 iter = pango_layout_get_iter (layout);
4228 PangoLayoutRun *run;
4229 PangoAttribute *attr;
4230 gboolean need_stipple = FALSE;
4233 run = pango_layout_iter_get_run (iter);
4237 tmp_list = run->item->analysis.extra_attrs;
4239 while (tmp_list != NULL)
4241 attr = tmp_list->data;
4242 switch (attr->klass->type)
4244 case PANGO_ATTR_FOREGROUND:
4245 case PANGO_ATTR_BACKGROUND:
4246 need_stipple = TRUE;
4256 tmp_list = g_slist_next (tmp_list);
4259 br = range_new (run->item->offset, run->item->offset + run->item->length);
4262 stippled_ranges = g_slist_prepend (stippled_ranges, br);
4264 embossed_ranges = g_slist_prepend (embossed_ranges, br);
4267 while (pango_layout_iter_next_run (iter));
4269 pango_layout_iter_free (iter);
4271 new_layout = pango_layout_copy (layout);
4273 attrs = pango_layout_get_attributes (new_layout);
4277 /* Create attr list if there wasn't one */
4278 attrs = pango_attr_list_new ();
4279 pango_layout_set_attributes (new_layout, attrs);
4280 pango_attr_list_unref (attrs);
4283 tmp_list = embossed_ranges;
4284 while (tmp_list != NULL)
4286 PangoAttribute *attr;
4287 ByteRange *br = tmp_list->data;
4289 attr = gdk_pango_attr_embossed_new (TRUE);
4291 attr->start_index = br->start;
4292 attr->end_index = br->end;
4294 pango_attr_list_change (attrs, attr);
4298 tmp_list = g_slist_next (tmp_list);
4301 g_slist_free (embossed_ranges);
4303 tmp_list = stippled_ranges;
4304 while (tmp_list != NULL)
4306 PangoAttribute *attr;
4307 ByteRange *br = tmp_list->data;
4309 if (stipple == NULL)
4311 #define gray50_width 2
4312 #define gray50_height 2
4313 static char gray50_bits[] = {
4317 stipple = gdk_bitmap_create_from_data (NULL,
4318 gray50_bits, gray50_width,
4322 attr = gdk_pango_attr_stipple_new (stipple);
4324 attr->start_index = br->start;
4325 attr->end_index = br->end;
4327 pango_attr_list_change (attrs, attr);
4331 tmp_list = g_slist_next (tmp_list);
4334 g_slist_free (stippled_ranges);
4337 g_object_unref (G_OBJECT (stipple));
4343 gtk_default_draw_layout (GtkStyle *style,
4345 GtkStateType state_type,
4349 const gchar *detail,
4352 PangoLayout *layout)
4356 g_return_if_fail (GTK_IS_STYLE (style));
4357 g_return_if_fail (window != NULL);
4359 gc = use_text ? style->text_gc[state_type] : style->fg_gc[state_type];
4362 gdk_gc_set_clip_rectangle (gc, area);
4364 if (state_type == GTK_STATE_INSENSITIVE)
4368 ins = get_insensitive_layout (layout);
4370 gdk_draw_layout (window, gc, x, y, ins);
4372 g_object_unref (G_OBJECT (ins));
4376 gdk_draw_layout (window, gc, x, y, layout);
4380 gdk_gc_set_clip_rectangle (gc, NULL);
4384 gtk_default_draw_resize_grip (GtkStyle *style,
4386 GtkStateType state_type,
4389 const gchar *detail,
4396 g_return_if_fail (GTK_IS_STYLE (style));
4397 g_return_if_fail (window != NULL);
4401 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
4402 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
4403 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
4406 /* make it square, aligning to bottom right */
4409 y += (height - width);
4412 else if (height < width)
4414 x += (width - height);
4418 /* Clear background */
4419 gdk_draw_rectangle (window,
4420 style->bg_gc[state_type],
4422 x, y, width, height);
4426 case GDK_WINDOW_EDGE_SOUTH_EAST:
4433 while (xi < (x + width - 3))
4435 gdk_draw_line (window,
4436 style->light_gc[state_type],
4443 gdk_draw_line (window,
4444 style->dark_gc[state_type],
4451 gdk_draw_line (window,
4452 style->dark_gc[state_type],
4462 g_assert_not_reached ();
4468 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
4469 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
4470 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
4475 gtk_style_shade (GdkColor *a,
4483 red = (gdouble) a->red / 65535.0;
4484 green = (gdouble) a->green / 65535.0;
4485 blue = (gdouble) a->blue / 65535.0;
4487 rgb_to_hls (&red, &green, &blue);
4492 else if (green < 0.0)
4498 else if (blue < 0.0)
4501 hls_to_rgb (&red, &green, &blue);
4503 b->red = red * 65535.0;
4504 b->green = green * 65535.0;
4505 b->blue = blue * 65535.0;
4509 rgb_to_hls (gdouble *r,
4550 l = (max + min) / 2;
4557 s = (max - min) / (max + min);
4559 s = (max - min) / (2 - max - min);
4563 h = (green - blue) / delta;
4564 else if (green == max)
4565 h = 2 + (blue - red) / delta;
4566 else if (blue == max)
4567 h = 4 + (red - green) / delta;
4580 hls_to_rgb (gdouble *h,
4593 if (lightness <= 0.5)
4594 m2 = lightness * (1 + saturation);
4596 m2 = lightness + saturation - lightness * saturation;
4597 m1 = 2 * lightness - m2;
4599 if (saturation == 0)
4614 r = m1 + (m2 - m1) * hue / 60;
4618 r = m1 + (m2 - m1) * (240 - hue) / 60;
4629 g = m1 + (m2 - m1) * hue / 60;
4633 g = m1 + (m2 - m1) * (240 - hue) / 60;
4644 b = m1 + (m2 - m1) * hue / 60;
4648 b = m1 + (m2 - m1) * (240 - hue) / 60;
4659 gtk_paint_hline (GtkStyle *style,
4661 GtkStateType state_type,
4664 const gchar *detail,
4669 g_return_if_fail (GTK_IS_STYLE (style));
4670 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
4672 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, area, widget, detail, x1, x2, y);
4676 gtk_paint_vline (GtkStyle *style,
4678 GtkStateType state_type,
4681 const gchar *detail,
4686 g_return_if_fail (GTK_IS_STYLE (style));
4687 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
4689 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, area, widget, detail, y1, y2, x);
4693 gtk_paint_shadow (GtkStyle *style,
4695 GtkStateType state_type,
4696 GtkShadowType shadow_type,
4699 const gchar *detail,
4705 g_return_if_fail (GTK_IS_STYLE (style));
4706 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
4708 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4712 gtk_paint_polygon (GtkStyle *style,
4714 GtkStateType state_type,
4715 GtkShadowType shadow_type,
4718 const gchar *detail,
4723 g_return_if_fail (GTK_IS_STYLE (style));
4724 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
4726 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, area, widget, detail, points, npoints, fill);
4730 gtk_paint_arrow (GtkStyle *style,
4732 GtkStateType state_type,
4733 GtkShadowType shadow_type,
4736 const gchar *detail,
4737 GtkArrowType arrow_type,
4744 g_return_if_fail (GTK_IS_STYLE (style));
4745 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
4747 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, area, widget, detail, arrow_type, fill, x, y, width, height);
4751 gtk_paint_diamond (GtkStyle *style,
4753 GtkStateType state_type,
4754 GtkShadowType shadow_type,
4757 const gchar *detail,
4763 g_return_if_fail (GTK_IS_STYLE (style));
4764 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
4766 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4770 gtk_paint_string (GtkStyle *style,
4772 GtkStateType state_type,
4775 const gchar *detail,
4778 const gchar *string)
4780 g_return_if_fail (GTK_IS_STYLE (style));
4781 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
4783 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, area, widget, detail, x, y, string);
4787 gtk_paint_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_box != NULL);
4802 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4806 gtk_paint_flat_box (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_flat_box != NULL);
4821 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4825 gtk_paint_check (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_check != NULL);
4840 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4844 gtk_paint_option (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_option != NULL);
4859 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4863 gtk_paint_tab (GtkStyle *style,
4865 GtkStateType state_type,
4866 GtkShadowType shadow_type,
4869 const gchar *detail,
4875 g_return_if_fail (GTK_IS_STYLE (style));
4876 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
4878 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4882 gtk_paint_shadow_gap (GtkStyle *style,
4884 GtkStateType state_type,
4885 GtkShadowType shadow_type,
4893 GtkPositionType gap_side,
4897 g_return_if_fail (GTK_IS_STYLE (style));
4898 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
4900 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);
4905 gtk_paint_box_gap (GtkStyle *style,
4907 GtkStateType state_type,
4908 GtkShadowType shadow_type,
4916 GtkPositionType gap_side,
4920 g_return_if_fail (GTK_IS_STYLE (style));
4921 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
4923 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);
4927 gtk_paint_extension (GtkStyle *style,
4929 GtkStateType state_type,
4930 GtkShadowType shadow_type,
4938 GtkPositionType gap_side)
4940 g_return_if_fail (GTK_IS_STYLE (style));
4941 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
4943 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side);
4947 gtk_paint_focus (GtkStyle *style,
4949 GtkStateType state_type,
4952 const gchar *detail,
4958 g_return_if_fail (GTK_IS_STYLE (style));
4959 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
4961 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, state_type, area, widget, detail, x, y, width, height);
4965 gtk_paint_slider (GtkStyle *style,
4967 GtkStateType state_type,
4968 GtkShadowType shadow_type,
4971 const gchar *detail,
4976 GtkOrientation orientation)
4978 g_return_if_fail (GTK_IS_STYLE (style));
4979 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
4981 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
4985 gtk_paint_handle (GtkStyle *style,
4987 GtkStateType state_type,
4988 GtkShadowType shadow_type,
4991 const gchar *detail,
4996 GtkOrientation orientation)
4998 g_return_if_fail (GTK_IS_STYLE (style));
4999 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
5001 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
5005 gtk_paint_expander (GtkStyle *style,
5007 GtkStateType state_type,
5010 const gchar *detail,
5013 GtkExpanderStyle expander_style)
5015 g_return_if_fail (GTK_IS_STYLE (style));
5016 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
5018 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type, area,
5019 widget, detail, x, y, expander_style);
5023 gtk_paint_layout (GtkStyle *style,
5025 GtkStateType state_type,
5029 const gchar *detail,
5032 PangoLayout *layout)
5034 g_return_if_fail (GTK_IS_STYLE (style));
5035 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
5037 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text, area,
5038 widget, detail, x, y, layout);
5042 gtk_paint_resize_grip (GtkStyle *style,
5044 GtkStateType state_type,
5047 const gchar *detail,
5055 g_return_if_fail (GTK_IS_STYLE (style));
5056 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
5058 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
5059 area, widget, detail,
5060 edge, x, y, width, height);
5065 * @border: a #GtkBorder.
5066 * @returns: a copy of @border.
5068 * Copies a #GtkBorder structure.
5071 gtk_border_copy (const GtkBorder *border)
5073 return (GtkBorder *)g_memdup (border, sizeof (GtkBorder));
5078 * @border: a #GtkBorder.
5080 * Frees a #GtkBorder structure.
5083 gtk_border_free (GtkBorder *border)
5089 * gtk_style_get_font:
5090 * @style: a #GtkStyle
5092 * Gets the #GdkFont to use for the given style. This is
5093 * meant only as a replacement for direct access to style->font
5094 * and should not be used in new code. New code should
5095 * use style->font_desc instead.
5097 * Return value: the #GdkFont for the style. This font is owned
5098 * by the style; if you want to keep around a copy, you must
5099 * call gdk_font_ref().
5102 gtk_style_get_font (GtkStyle *style)
5104 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
5106 if (style->private_font && style->private_font_desc)
5108 if (!style->font_desc ||
5109 !pango_font_description_equal (style->private_font_desc, style->font_desc))
5111 gdk_font_unref (style->private_font);
5112 style->private_font = NULL;
5114 if (style->private_font_desc)
5116 pango_font_description_free (style->private_font_desc);
5117 style->private_font_desc = NULL;
5122 if (!style->private_font)
5124 if (style->font_desc)
5126 style->private_font = gdk_font_from_description (style->font_desc);
5127 style->private_font_desc = pango_font_description_copy (style->font_desc);
5130 if (!style->private_font)
5131 style->private_font = gdk_font_load ("fixed");
5133 if (!style->private_font)
5134 g_error ("Unable to load \"fixed\" font");
5137 return style->private_font;
5141 * gtk_style_set_font:
5142 * @style: a #GtkStyle.
5143 * @font: a #GdkFont, or %NULL to use the #GdkFont corresponding
5144 * to style->font_desc.
5146 * Sets the #GdkFont to use for a given style. This is
5147 * meant only as a replacement for direct access to style->font
5148 * and should not be used in new code. New code should
5149 * use style->font_desc instead.
5152 gtk_style_set_font (GtkStyle *style,
5157 g_return_if_fail (GTK_IS_STYLE (style));
5159 old_font = style->private_font;
5161 style->private_font = font;
5163 gdk_font_ref (font);
5166 gdk_font_unref (old_font);
5168 if (style->private_font_desc)
5170 pango_font_description_free (style->private_font_desc);
5171 style->private_font_desc = NULL;
5176 * _gtk_draw_insertion_cursor:
5177 * @drawable: a #GdkDrawable
5179 * @location: location where to draw the cursor (@location->width is ignored)
5180 * @dir: text direction for the cursor, used to decide whether to draw a
5181 * directional arrow on the cursor and in what direction. Unless both
5182 * strong and weak cursors are displayed, this should be %GTK_TEXT_DIR_NONE.
5184 * Draws a text caret on @drawable at @location. This is not a style function
5185 * but merely a convenience function for drawing the standard cursor shape.
5188 _gtk_draw_insertion_cursor (GdkDrawable *drawable,
5190 GdkRectangle *location,
5191 GtkTextDirection dir)
5193 gint stem_width = location->height / 30 + 1;
5194 gint arrow_width = stem_width + 1;
5198 for (i = 0; i < stem_width; i++)
5199 gdk_draw_line (drawable, gc,
5200 location->x + i - stem_width / 2, location->y,
5201 location->x + i - stem_width / 2, location->y + location->height);
5203 if (dir == GTK_TEXT_DIR_RTL)
5205 x = location->x - stem_width / 2 - 1;
5206 y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
5208 for (i = 0; i < arrow_width; i++)
5210 gdk_draw_line (drawable, gc,
5212 x, y + 2 * arrow_width - i - 1);
5216 else if (dir == GTK_TEXT_DIR_LTR)
5218 x = location->x + stem_width - stem_width / 2;
5219 y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
5221 for (i = 0; i < arrow_width; i++)
5223 gdk_draw_line (drawable, gc,
5225 x, y + 2 * arrow_width - i - 1);