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);
827 * @style: a #GtkStyle
828 * @window: a #GdkWindow
829 * @state_type: a state
830 * @x1: the starting x coordinate
831 * @x2: the ending x coordinate
832 * @y: the y coordinate
834 * Draws a horizontal line from (@x1, @y) to (@x2, @y) in @window
835 * using the given style and state.
837 * This function is deprecated, use gtk_paint_hline() instead.
840 gtk_draw_hline (GtkStyle *style,
842 GtkStateType state_type,
847 g_return_if_fail (GTK_IS_STYLE (style));
848 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
850 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, NULL, NULL, NULL, x1, x2, y);
856 * @style: a #GtkStyle
857 * @window: a #GdkWindow
858 * @state_type: a state
859 * @y1: the starting y coordinate
860 * @y2: the ending y coordinate
861 * @x: the x coordinate
863 * Draws a vertical line from (@x, @y1) to (@x, @y2) in @window
864 * using the given style and state.
866 * This function is deprecated, use gtk_paint_vline() instead.
869 gtk_draw_vline (GtkStyle *style,
871 GtkStateType state_type,
876 g_return_if_fail (GTK_IS_STYLE (style));
877 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
879 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, NULL, NULL, NULL, y1, y2, x);
884 gtk_draw_shadow (GtkStyle *style,
886 GtkStateType state_type,
887 GtkShadowType shadow_type,
893 g_return_if_fail (GTK_IS_STYLE (style));
894 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
896 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
900 gtk_draw_polygon (GtkStyle *style,
902 GtkStateType state_type,
903 GtkShadowType shadow_type,
908 g_return_if_fail (GTK_IS_STYLE (style));
909 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_polygon != NULL);
911 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, NULL, NULL, NULL, points, npoints, fill);
915 gtk_draw_arrow (GtkStyle *style,
917 GtkStateType state_type,
918 GtkShadowType shadow_type,
919 GtkArrowType arrow_type,
926 g_return_if_fail (GTK_IS_STYLE (style));
927 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
929 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, NULL, NULL, NULL, arrow_type, fill, x, y, width, height);
934 gtk_draw_diamond (GtkStyle *style,
936 GtkStateType state_type,
937 GtkShadowType shadow_type,
943 g_return_if_fail (GTK_IS_STYLE (style));
944 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
946 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
951 gtk_draw_string (GtkStyle *style,
953 GtkStateType state_type,
958 g_return_if_fail (GTK_IS_STYLE (style));
959 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
961 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, NULL, NULL, NULL, x, y, string);
965 gtk_draw_box (GtkStyle *style,
967 GtkStateType state_type,
968 GtkShadowType shadow_type,
974 g_return_if_fail (GTK_IS_STYLE (style));
975 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
977 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
981 gtk_draw_flat_box (GtkStyle *style,
983 GtkStateType state_type,
984 GtkShadowType shadow_type,
990 g_return_if_fail (GTK_IS_STYLE (style));
991 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
993 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
997 gtk_draw_check (GtkStyle *style,
999 GtkStateType state_type,
1000 GtkShadowType shadow_type,
1006 g_return_if_fail (GTK_IS_STYLE (style));
1007 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
1009 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1013 gtk_draw_option (GtkStyle *style,
1015 GtkStateType state_type,
1016 GtkShadowType shadow_type,
1022 g_return_if_fail (GTK_IS_STYLE (style));
1023 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
1025 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1029 gtk_draw_tab (GtkStyle *style,
1031 GtkStateType state_type,
1032 GtkShadowType shadow_type,
1038 g_return_if_fail (GTK_IS_STYLE (style));
1039 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
1041 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1045 gtk_draw_shadow_gap (GtkStyle *style,
1047 GtkStateType state_type,
1048 GtkShadowType shadow_type,
1053 GtkPositionType gap_side,
1057 g_return_if_fail (GTK_IS_STYLE (style));
1058 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
1060 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);
1064 gtk_draw_box_gap (GtkStyle *style,
1066 GtkStateType state_type,
1067 GtkShadowType shadow_type,
1072 GtkPositionType gap_side,
1076 g_return_if_fail (GTK_IS_STYLE (style));
1077 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
1079 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);
1083 gtk_draw_extension (GtkStyle *style,
1085 GtkStateType state_type,
1086 GtkShadowType shadow_type,
1091 GtkPositionType gap_side)
1093 g_return_if_fail (GTK_IS_STYLE (style));
1094 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
1096 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side);
1100 gtk_draw_focus (GtkStyle *style,
1107 g_return_if_fail (GTK_IS_STYLE (style));
1108 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
1110 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, GTK_STATE_NORMAL, NULL, NULL, NULL, x, y, width, height);
1114 gtk_draw_slider (GtkStyle *style,
1116 GtkStateType state_type,
1117 GtkShadowType shadow_type,
1122 GtkOrientation orientation)
1124 g_return_if_fail (GTK_IS_STYLE (style));
1125 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
1127 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
1131 gtk_draw_handle (GtkStyle *style,
1133 GtkStateType state_type,
1134 GtkShadowType shadow_type,
1139 GtkOrientation orientation)
1141 g_return_if_fail (GTK_IS_STYLE (style));
1142 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
1144 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
1148 gtk_draw_expander (GtkStyle *style,
1150 GtkStateType state_type,
1153 GtkExpanderStyle expander_style)
1155 g_return_if_fail (GTK_IS_STYLE (style));
1156 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
1158 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type,
1160 x, y, expander_style);
1164 gtk_draw_layout (GtkStyle *style,
1166 GtkStateType state_type,
1170 PangoLayout *layout)
1172 g_return_if_fail (GTK_IS_STYLE (style));
1173 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
1175 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text,
1181 gtk_draw_resize_grip (GtkStyle *style,
1183 GtkStateType state_type,
1190 g_return_if_fail (GTK_IS_STYLE (style));
1191 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
1193 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
1196 x, y, width, height);
1201 gtk_style_set_background (GtkStyle *style,
1203 GtkStateType state_type)
1205 g_return_if_fail (GTK_IS_STYLE (style));
1206 g_return_if_fail (window != NULL);
1208 GTK_STYLE_GET_CLASS (style)->set_background (style, window, state_type);
1211 /* Default functions */
1213 gtk_style_real_clone (GtkStyle *style)
1215 return GTK_STYLE (g_object_new (G_OBJECT_TYPE (style), NULL));
1219 gtk_style_real_copy (GtkStyle *style,
1224 for (i = 0; i < 5; i++)
1226 style->fg[i] = src->fg[i];
1227 style->bg[i] = src->bg[i];
1228 style->text[i] = src->text[i];
1229 style->base[i] = src->base[i];
1231 style->bg_pixmap[i] = src->bg_pixmap[i];
1234 if (style->private_font)
1235 gdk_font_unref (style->private_font);
1236 style->private_font = src->private_font;
1237 if (style->private_font)
1238 gdk_font_ref (style->private_font);
1240 if (style->font_desc)
1241 pango_font_description_free (style->font_desc);
1243 style->font_desc = pango_font_description_copy (src->font_desc);
1245 style->font_desc = NULL;
1247 style->xthickness = src->xthickness;
1248 style->ythickness = src->ythickness;
1250 if (style->rc_style)
1251 gtk_rc_style_unref (style->rc_style);
1252 style->rc_style = src->rc_style;
1254 gtk_rc_style_ref (src->rc_style);
1256 /* don't copy, just clear cache */
1257 clear_property_cache (style);
1261 gtk_style_real_init_from_rc (GtkStyle *style,
1262 GtkRcStyle *rc_style)
1266 /* cache _should_ be still empty */
1267 clear_property_cache (style);
1269 if (rc_style->font_desc)
1270 pango_font_description_merge (style->font_desc, rc_style->font_desc, TRUE);
1272 for (i = 0; i < 5; i++)
1274 if (rc_style->color_flags[i] & GTK_RC_FG)
1275 style->fg[i] = rc_style->fg[i];
1276 if (rc_style->color_flags[i] & GTK_RC_BG)
1277 style->bg[i] = rc_style->bg[i];
1278 if (rc_style->color_flags[i] & GTK_RC_TEXT)
1279 style->text[i] = rc_style->text[i];
1280 if (rc_style->color_flags[i] & GTK_RC_BASE)
1281 style->base[i] = rc_style->base[i];
1284 if (rc_style->xthickness >= 0)
1285 style->xthickness = rc_style->xthickness;
1286 if (rc_style->ythickness >= 0)
1287 style->ythickness = rc_style->ythickness;
1289 if (rc_style->icon_factories)
1293 style->icon_factories = g_slist_copy (rc_style->icon_factories);
1295 iter = style->icon_factories;
1296 while (iter != NULL)
1298 g_object_ref (G_OBJECT (iter->data));
1300 iter = g_slist_next (iter);
1306 style_property_values_cmp (gconstpointer bsearch_node1,
1307 gconstpointer bsearch_node2)
1309 const PropertyValue *val1 = bsearch_node1;
1310 const PropertyValue *val2 = bsearch_node2;
1312 if (val1->widget_type == val2->widget_type)
1313 return val1->pspec < val2->pspec ? -1 : val1->pspec == val2->pspec ? 0 : 1;
1315 return val1->widget_type < val2->widget_type ? -1 : 1;
1319 _gtk_style_peek_property_value (GtkStyle *style,
1322 GtkRcPropertyParser parser)
1324 PropertyValue *pcache, key = { 0, NULL, { 0, } };
1325 const GtkRcProperty *rcprop = NULL;
1328 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1329 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), NULL);
1330 g_return_val_if_fail (g_type_is_a (pspec->owner_type, GTK_TYPE_WIDGET), NULL);
1331 g_return_val_if_fail (g_type_is_a (widget_type, pspec->owner_type), NULL);
1333 key.widget_type = widget_type;
1336 /* need value cache array */
1337 if (!style->property_cache)
1338 style->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
1341 pcache = bsearch (&key,
1342 style->property_cache->data, style->property_cache->len,
1343 sizeof (PropertyValue), style_property_values_cmp);
1345 return &pcache->value;
1349 while (i < style->property_cache->len &&
1350 style_property_values_cmp (&key, &g_array_index (style->property_cache, PropertyValue, i)) >= 0)
1353 g_array_insert_val (style->property_cache, i, key);
1354 pcache = &g_array_index (style->property_cache, PropertyValue, i);
1356 /* cache miss, initialize value type, then set contents */
1357 g_param_spec_ref (pcache->pspec);
1358 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1360 /* value provided by rc style? */
1361 if (style->rc_style)
1363 GQuark prop_quark = g_quark_from_string (pspec->name);
1367 rcprop = _gtk_rc_style_lookup_rc_property (style->rc_style,
1368 g_type_qname (widget_type),
1372 widget_type = g_type_parent (widget_type);
1374 while (g_type_is_a (widget_type, pspec->owner_type));
1377 /* when supplied by rc style, we need to convert */
1378 if (rcprop && !_gtk_settings_parse_convert (parser, &rcprop->value,
1379 pspec, &pcache->value))
1381 gchar *contents = g_strdup_value_contents (&rcprop->value);
1383 g_message ("%s: failed to retrieve property `%s::%s' of type `%s' from rc file value \"%s\" of type `%s'",
1385 g_type_name (pspec->owner_type), pspec->name,
1386 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1388 G_VALUE_TYPE_NAME (&rcprop->value));
1390 rcprop = NULL; /* needs default */
1393 /* not supplied by rc style (or conversion failed), revert to default */
1395 g_param_value_set_default (pspec, &pcache->value);
1397 return &pcache->value;
1401 load_bg_image (GdkColormap *colormap,
1403 const gchar *filename)
1405 if (strcmp (filename, "<parent>") == 0)
1406 return (GdkPixmap*) GDK_PARENT_RELATIVE;
1409 return gdk_pixmap_colormap_create_from_xpm (NULL, colormap, NULL,
1416 gtk_style_real_realize (GtkStyle *style)
1418 GdkGCValues gc_values;
1419 GdkGCValuesMask gc_values_mask;
1423 for (i = 0; i < 5; i++)
1425 gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT);
1426 gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT);
1428 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
1429 style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
1430 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
1432 style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
1433 style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
1434 style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;
1437 gdk_color_black (style->colormap, &style->black);
1438 gdk_color_white (style->colormap, &style->white);
1440 gc_values_mask = GDK_GC_FOREGROUND;
1442 gc_values.foreground = style->black;
1443 style->black_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1445 gc_values.foreground = style->white;
1446 style->white_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1448 for (i = 0; i < 5; i++)
1450 if (style->rc_style && style->rc_style->bg_pixmap_name[i])
1451 style->bg_pixmap[i] = load_bg_image (style->colormap,
1453 style->rc_style->bg_pixmap_name[i]);
1455 if (!gdk_color_alloc (style->colormap, &style->fg[i]))
1456 g_warning ("unable to allocate color: ( %d %d %d )",
1457 style->fg[i].red, style->fg[i].green, style->fg[i].blue);
1458 if (!gdk_color_alloc (style->colormap, &style->bg[i]))
1459 g_warning ("unable to allocate color: ( %d %d %d )",
1460 style->bg[i].red, style->bg[i].green, style->bg[i].blue);
1461 if (!gdk_color_alloc (style->colormap, &style->light[i]))
1462 g_warning ("unable to allocate color: ( %d %d %d )",
1463 style->light[i].red, style->light[i].green, style->light[i].blue);
1464 if (!gdk_color_alloc (style->colormap, &style->dark[i]))
1465 g_warning ("unable to allocate color: ( %d %d %d )",
1466 style->dark[i].red, style->dark[i].green, style->dark[i].blue);
1467 if (!gdk_color_alloc (style->colormap, &style->mid[i]))
1468 g_warning ("unable to allocate color: ( %d %d %d )",
1469 style->mid[i].red, style->mid[i].green, style->mid[i].blue);
1470 if (!gdk_color_alloc (style->colormap, &style->text[i]))
1471 g_warning ("unable to allocate color: ( %d %d %d )",
1472 style->text[i].red, style->text[i].green, style->text[i].blue);
1473 if (!gdk_color_alloc (style->colormap, &style->base[i]))
1474 g_warning ("unable to allocate color: ( %d %d %d )",
1475 style->base[i].red, style->base[i].green, style->base[i].blue);
1476 if (!gdk_color_alloc (style->colormap, &style->text_aa[i]))
1477 g_warning ("unable to allocate color: ( %d %d %d )",
1478 style->text_aa[i].red, style->text_aa[i].green, style->text_aa[i].blue);
1480 gc_values.foreground = style->fg[i];
1481 style->fg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1483 gc_values.foreground = style->bg[i];
1484 style->bg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1486 gc_values.foreground = style->light[i];
1487 style->light_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1489 gc_values.foreground = style->dark[i];
1490 style->dark_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1492 gc_values.foreground = style->mid[i];
1493 style->mid_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1495 gc_values.foreground = style->text[i];
1496 style->text_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1498 gc_values.foreground = style->base[i];
1499 style->base_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1501 gc_values.foreground = style->text_aa[i];
1502 style->text_aa_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1507 gtk_style_real_unrealize (GtkStyle *style)
1511 gtk_gc_release (style->black_gc);
1512 gtk_gc_release (style->white_gc);
1514 for (i = 0; i < 5; i++)
1516 gtk_gc_release (style->fg_gc[i]);
1517 gtk_gc_release (style->bg_gc[i]);
1518 gtk_gc_release (style->light_gc[i]);
1519 gtk_gc_release (style->dark_gc[i]);
1520 gtk_gc_release (style->mid_gc[i]);
1521 gtk_gc_release (style->text_gc[i]);
1522 gtk_gc_release (style->base_gc[i]);
1523 gtk_gc_release (style->text_aa_gc[i]);
1525 if (style->bg_pixmap[i] && style->bg_pixmap[i] != (GdkPixmap*) GDK_PARENT_RELATIVE)
1526 gdk_pixmap_unref (style->bg_pixmap[i]);
1529 gdk_colormap_free_colors (style->colormap, style->fg, 5);
1530 gdk_colormap_free_colors (style->colormap, style->bg, 5);
1531 gdk_colormap_free_colors (style->colormap, style->light, 5);
1532 gdk_colormap_free_colors (style->colormap, style->dark, 5);
1533 gdk_colormap_free_colors (style->colormap, style->mid, 5);
1534 gdk_colormap_free_colors (style->colormap, style->text, 5);
1535 gdk_colormap_free_colors (style->colormap, style->base, 5);
1536 gdk_colormap_free_colors (style->colormap, style->text_aa, 5);
1540 gtk_style_real_set_background (GtkStyle *style,
1542 GtkStateType state_type)
1545 gint parent_relative;
1547 if (style->bg_pixmap[state_type])
1549 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1552 parent_relative = TRUE;
1556 pixmap = style->bg_pixmap[state_type];
1557 parent_relative = FALSE;
1560 gdk_window_set_back_pixmap (window, pixmap, parent_relative);
1563 gdk_window_set_background (window, &style->bg[state_type]);
1567 gtk_style_render_icon (GtkStyle *style,
1568 const GtkIconSource *source,
1569 GtkTextDirection direction,
1573 const gchar *detail)
1577 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1578 g_return_val_if_fail (GTK_STYLE_GET_CLASS (style)->render_icon != NULL, NULL);
1580 pixbuf = GTK_STYLE_GET_CLASS (style)->render_icon (style, source, direction, state,
1581 size, widget, detail);
1583 g_return_val_if_fail (pixbuf != NULL, NULL);
1588 /* Default functions */
1590 gtk_style_apply_default_background (GtkStyle *style,
1593 GtkStateType state_type,
1600 GdkRectangle new_rect, old_rect;
1606 old_rect.width = width;
1607 old_rect.height = height;
1609 if (!gdk_rectangle_intersect (area, &old_rect, &new_rect))
1616 new_rect.width = width;
1617 new_rect.height = height;
1620 if (!style->bg_pixmap[state_type] ||
1621 GDK_IS_PIXMAP (window) ||
1622 (!set_bg && style->bg_pixmap[state_type] != (GdkPixmap*) GDK_PARENT_RELATIVE))
1624 GdkGC *gc = style->bg_gc[state_type];
1626 if (style->bg_pixmap[state_type])
1628 gdk_gc_set_fill (gc, GDK_TILED);
1629 gdk_gc_set_tile (gc, style->bg_pixmap[state_type]);
1632 gdk_draw_rectangle (window, gc, TRUE,
1633 new_rect.x, new_rect.y, new_rect.width, new_rect.height);
1634 if (style->bg_pixmap[state_type])
1635 gdk_gc_set_fill (gc, GDK_SOLID);
1641 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1642 gdk_window_set_back_pixmap (window, NULL, TRUE);
1644 gdk_window_set_back_pixmap (window, style->bg_pixmap[state_type], FALSE);
1647 gdk_window_clear_area (window,
1648 new_rect.x, new_rect.y,
1649 new_rect.width, new_rect.height);
1654 scale_or_ref (GdkPixbuf *src,
1658 if (width == gdk_pixbuf_get_width (src) &&
1659 height == gdk_pixbuf_get_height (src))
1661 gdk_pixbuf_ref (src);
1666 return gdk_pixbuf_scale_simple (src,
1668 GDK_INTERP_BILINEAR);
1673 gtk_default_render_icon (GtkStyle *style,
1674 const GtkIconSource *source,
1675 GtkTextDirection direction,
1679 const gchar *detail)
1685 GdkPixbuf *base_pixbuf;
1687 /* Oddly, style can be NULL in this function, because
1688 * GtkIconSet can be used without a style and if so
1689 * it uses this function.
1692 base_pixbuf = gtk_icon_source_get_pixbuf (source);
1694 g_return_val_if_fail (base_pixbuf != NULL, NULL);
1696 if (!gtk_icon_size_lookup (size, &width, &height))
1698 g_warning (G_STRLOC ": invalid icon size `%d'", size);
1702 /* If the size was wildcarded, then scale; otherwise, leave it
1705 if (gtk_icon_source_get_size_wildcarded (source))
1706 scaled = scale_or_ref (base_pixbuf, width, height);
1708 scaled = GDK_PIXBUF (g_object_ref (G_OBJECT (base_pixbuf)));
1710 /* If the state was wildcarded, then generate a state. */
1711 if (gtk_icon_source_get_state_wildcarded (source))
1713 if (state == GTK_STATE_INSENSITIVE)
1715 stated = gdk_pixbuf_copy (scaled);
1717 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
1720 gdk_pixbuf_unref (scaled);
1722 else if (state == GTK_STATE_PRELIGHT)
1724 stated = gdk_pixbuf_copy (scaled);
1726 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
1729 gdk_pixbuf_unref (scaled);
1743 sanitize_size (GdkWindow *window,
1747 gboolean set_bg = FALSE;
1749 if ((*width == -1) && (*height == -1))
1751 set_bg = GDK_IS_WINDOW (window);
1752 gdk_window_get_size (window, width, height);
1754 else if (*width == -1)
1755 gdk_window_get_size (window, width, NULL);
1756 else if (*height == -1)
1757 gdk_window_get_size (window, NULL, height);
1763 draw_part (GdkDrawable *drawable,
1771 gdk_gc_set_clip_rectangle (gc, area);
1773 if (!indicator_parts[part].bmap)
1774 indicator_parts[part].bmap = gdk_bitmap_create_from_data (drawable,
1775 indicator_parts[part].bits,
1776 INDICATOR_PART_SIZE, INDICATOR_PART_SIZE);
1778 gdk_gc_set_ts_origin (gc, x, y);
1779 gdk_gc_set_stipple (gc, indicator_parts[part].bmap);
1780 gdk_gc_set_fill (gc, GDK_STIPPLED);
1782 gdk_draw_rectangle (drawable, gc, TRUE, x, y, INDICATOR_PART_SIZE, INDICATOR_PART_SIZE);
1784 gdk_gc_set_fill (gc, GDK_SOLID);
1787 gdk_gc_set_clip_rectangle (gc, NULL);
1791 gtk_default_draw_hline (GtkStyle *style,
1793 GtkStateType state_type,
1796 const gchar *detail,
1801 gint thickness_light;
1802 gint thickness_dark;
1805 g_return_if_fail (GTK_IS_STYLE (style));
1806 g_return_if_fail (window != NULL);
1808 thickness_light = style->ythickness / 2;
1809 thickness_dark = style->ythickness - thickness_light;
1813 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
1814 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
1817 if (detail && !strcmp (detail, "label"))
1819 if (state_type == GTK_STATE_INSENSITIVE)
1820 gdk_draw_line (window, style->white_gc, x1 + 1, y + 1, x2 + 1, y + 1);
1821 gdk_draw_line (window, style->fg_gc[state_type], x1, y, x2, y);
1825 for (i = 0; i < thickness_dark; i++)
1827 gdk_draw_line (window, style->light_gc[state_type], x2 - i - 1, y + i, x2, y + i);
1828 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x2 - i - 1, y + i);
1831 y += thickness_dark;
1832 for (i = 0; i < thickness_light; i++)
1834 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x1 + thickness_light - i - 1, y + i);
1835 gdk_draw_line (window, style->light_gc[state_type], x1 + thickness_light - i - 1, y + i, x2, y + i);
1841 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
1842 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
1848 gtk_default_draw_vline (GtkStyle *style,
1850 GtkStateType state_type,
1853 const gchar *detail,
1858 gint thickness_light;
1859 gint thickness_dark;
1862 g_return_if_fail (GTK_IS_STYLE (style));
1863 g_return_if_fail (window != NULL);
1865 thickness_light = style->xthickness / 2;
1866 thickness_dark = style->xthickness - thickness_light;
1870 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
1871 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
1873 for (i = 0; i < thickness_dark; i++)
1875 gdk_draw_line (window, style->light_gc[state_type], x + i, y2 - i - 1, x + i, y2);
1876 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y2 - i - 1);
1879 x += thickness_dark;
1880 for (i = 0; i < thickness_light; i++)
1882 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y1 + thickness_light - i);
1883 gdk_draw_line (window, style->light_gc[state_type], x + i, y1 + thickness_light - i, x + i, y2);
1887 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
1888 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
1894 draw_thin_shadow (GtkStyle *style,
1905 sanitize_size (window, &width, &height);
1907 gc1 = style->light_gc[state];
1908 gc2 = style->dark_gc[state];
1912 gdk_gc_set_clip_rectangle (gc1, area);
1913 gdk_gc_set_clip_rectangle (gc2, area);
1916 gdk_draw_line (window, gc1,
1917 x, y + height - 1, x + width - 1, y + height - 1);
1918 gdk_draw_line (window, gc1,
1919 x + width - 1, y, x + width - 1, y + height - 1);
1921 gdk_draw_line (window, gc2,
1922 x, y, x + width - 1, y);
1923 gdk_draw_line (window, gc2,
1924 x, y, x, y + height - 1);
1928 gdk_gc_set_clip_rectangle (gc1, NULL);
1929 gdk_gc_set_clip_rectangle (gc2, NULL);
1934 draw_spin_entry_shadow (GtkStyle *style,
1943 gint window_width, window_height;
1944 gboolean focus_inset;
1946 gdk_window_get_size (window, &window_width, &window_height);
1949 width = window_width;
1951 height = window_height;
1953 focus_inset = (width < window_width && height < window_height);
1957 gdk_gc_set_clip_rectangle (style->light_gc[state], area);
1958 gdk_gc_set_clip_rectangle (style->dark_gc[state], area);
1959 gdk_gc_set_clip_rectangle (style->black_gc, area);
1960 gdk_gc_set_clip_rectangle (style->bg_gc[state], area);
1961 gdk_gc_set_clip_rectangle (style->base_gc[state], area);
1964 gdk_draw_line (window, style->light_gc[state],
1965 x, y + height - 1, x + width - 1, y + height - 1);
1967 gdk_draw_line (window,
1968 style->base_gc[state],
1969 x + width - 1, y + 1, x + width - 1, y + height - 3);
1973 gdk_draw_line (window, style->bg_gc[state],
1974 x + 1, y + height - 2, x + width - 1, y + height - 2);
1975 gdk_draw_line (window,
1976 style->base_gc[state],
1977 x + width - 2, y + 1, x + width - 2, y + height - 3);
1979 gdk_draw_line (window, style->black_gc,
1980 x + 1, y + 1, x + width - 1, y + 1);
1981 gdk_draw_line (window, style->black_gc,
1982 x + 1, y + 1, x + 1, y + height - 2);
1985 gdk_draw_line (window, style->dark_gc[state],
1986 x, y, x + width - 1, y);
1987 gdk_draw_line (window, style->dark_gc[state],
1988 x, y, x, y + height - 1);
1992 gdk_gc_set_clip_rectangle (style->light_gc[state], NULL);
1993 gdk_gc_set_clip_rectangle (style->dark_gc[state], NULL);
1994 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
1995 gdk_gc_set_clip_rectangle (style->bg_gc[state], NULL);
1996 gdk_gc_set_clip_rectangle (style->base_gc[state], NULL);
2001 draw_spinbutton_shadow (GtkStyle *style,
2010 gint y_middle = y + height / 2;
2012 sanitize_size (window, &width, &height);
2016 gdk_gc_set_clip_rectangle (style->black_gc, area);
2017 gdk_gc_set_clip_rectangle (style->bg_gc[state], area);
2018 gdk_gc_set_clip_rectangle (style->dark_gc[state], area);
2019 gdk_gc_set_clip_rectangle (style->light_gc[state], area);
2022 gdk_draw_line (window, style->black_gc,
2023 x, y + 2, x, y + height - 3);
2024 gdk_draw_line (window, style->black_gc,
2025 x, y + 1, x + width - 2, y + 1);
2026 gdk_draw_line (window, style->black_gc,
2027 x + width - 2, y + 2, x + width - 2, y + height - 3);
2029 gdk_draw_line (window, style->bg_gc[state],
2030 x, y + height - 2, x + width - 2, y + height - 2);
2032 gdk_draw_line (window, style->dark_gc[state],
2033 x, y, x + width - 1, y);
2034 gdk_draw_line (window, style->dark_gc[state],
2035 x + 1, y_middle - 1, x + width - 3, y_middle - 1);
2036 gdk_draw_line (window, style->dark_gc[state],
2037 x + 1, y + height - 3, x + width - 3, y + height - 3);
2039 gdk_draw_line (window, style->light_gc[state],
2040 x + 1, y + 2, x + width - 3, y + 2);
2041 gdk_draw_line (window, style->light_gc[state],
2042 x + 1, y_middle, x + width - 3, y_middle);
2043 gdk_draw_line (window, style->light_gc[state],
2044 x + width - 1, y + 1, x + width - 1, y + height - 1);
2045 gdk_draw_line (window, style->light_gc[state],
2046 x, y + height - 1, x + width - 2, y + height - 1);
2050 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2051 gdk_gc_set_clip_rectangle (style->bg_gc[state], NULL);
2052 gdk_gc_set_clip_rectangle (style->dark_gc[state], NULL);
2053 gdk_gc_set_clip_rectangle (style->light_gc[state], NULL);
2058 gtk_default_draw_shadow (GtkStyle *style,
2060 GtkStateType state_type,
2061 GtkShadowType shadow_type,
2064 const gchar *detail,
2072 gint thickness_light;
2073 gint thickness_dark;
2076 g_return_if_fail (GTK_IS_STYLE (style));
2077 g_return_if_fail (window != NULL);
2079 if (shadow_type == GTK_SHADOW_IN)
2081 if (detail && (strcmp (detail, "buttondefault") == 0))
2083 sanitize_size (window, &width, &height);
2085 gdk_draw_rectangle (window, style->black_gc, FALSE,
2086 x, y, width - 1, height - 1);
2090 if (detail && strcmp (detail, "trough") == 0)
2092 draw_thin_shadow (style, window, state_type, area,
2093 x, y, width, height);
2096 else if (widget && GTK_IS_SPIN_BUTTON (widget) &&
2097 detail && strcmp (detail, "entry") == 0)
2099 draw_spin_entry_shadow (style, window, state_type, area,
2100 x, y, width, height);
2103 else if (widget && GTK_IS_SPIN_BUTTON (widget) &&
2104 detail && strcmp (detail, "spinbutton") == 0)
2106 draw_spinbutton_shadow (style, window, state_type,
2107 area, x, y, width, height);
2112 sanitize_size (window, &width, &height);
2114 switch (shadow_type)
2116 case GTK_SHADOW_NONE:
2119 case GTK_SHADOW_ETCHED_IN:
2120 gc1 = style->light_gc[state_type];
2121 gc2 = style->dark_gc[state_type];
2123 case GTK_SHADOW_OUT:
2124 case GTK_SHADOW_ETCHED_OUT:
2125 gc1 = style->dark_gc[state_type];
2126 gc2 = style->light_gc[state_type];
2132 gdk_gc_set_clip_rectangle (gc1, area);
2133 gdk_gc_set_clip_rectangle (gc2, area);
2134 if (shadow_type == GTK_SHADOW_IN ||
2135 shadow_type == GTK_SHADOW_OUT)
2137 gdk_gc_set_clip_rectangle (style->black_gc, area);
2138 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2142 switch (shadow_type)
2144 case GTK_SHADOW_NONE:
2148 /* Light around right and bottom edge */
2150 if (style->ythickness > 0)
2151 gdk_draw_line (window, gc1,
2152 x, y + height - 1, x + width - 1, y + height - 1);
2153 if (style->xthickness > 0)
2154 gdk_draw_line (window, gc1,
2155 x + width - 1, y, x + width - 1, y + height - 1);
2157 if (style->ythickness > 1)
2158 gdk_draw_line (window, style->bg_gc[state_type],
2159 x + 1, y + height - 2, x + width - 2, y + height - 2);
2160 if (style->xthickness > 1)
2161 gdk_draw_line (window, style->bg_gc[state_type],
2162 x + width - 2, y + 1, x + width - 2, y + height - 2);
2164 /* Dark around left and top */
2166 if (style->ythickness > 1)
2167 gdk_draw_line (window, style->black_gc,
2168 x + 1, y + 1, x + width - 2, y + 1);
2169 if (style->xthickness > 1)
2170 gdk_draw_line (window, style->black_gc,
2171 x + 1, y + 1, x + 1, y + height - 2);
2173 if (style->ythickness > 0)
2174 gdk_draw_line (window, gc2,
2175 x, y, x + width - 1, y);
2176 if (style->xthickness > 0)
2177 gdk_draw_line (window, gc2,
2178 x, y, x, y + height - 1);
2181 case GTK_SHADOW_OUT:
2182 /* Dark around right and bottom edge */
2184 if (style->ythickness > 0)
2186 if (style->ythickness > 1)
2188 gdk_draw_line (window, gc1,
2189 x + 1, y + height - 2, x + width - 2, y + height - 2);
2190 gdk_draw_line (window, style->black_gc,
2191 x, y + height - 1, x + width - 1, y + height - 1);
2195 gdk_draw_line (window, gc1,
2196 x + 1, y + height - 1, x + width - 1, y + height - 1);
2200 if (style->xthickness > 0)
2202 if (style->xthickness > 1)
2204 gdk_draw_line (window, gc1,
2205 x + width - 2, y + 1, x + width - 2, y + height - 2);
2207 gdk_draw_line (window, style->black_gc,
2208 x + width - 1, y, x + width - 1, y + height - 1);
2212 gdk_draw_line (window, gc1,
2213 x + width - 1, y + 1, x + width - 1, y + height - 1);
2217 /* Light around top and left */
2219 if (style->ythickness > 0)
2220 gdk_draw_line (window, gc2,
2221 x, y, x + width - 1, y);
2222 if (style->xthickness > 0)
2223 gdk_draw_line (window, gc2,
2224 x, y, x, y + height - 1);
2226 if (style->ythickness > 1)
2227 gdk_draw_line (window, style->bg_gc[state_type],
2228 x + 1, y + 1, x + width - 2, y + 1);
2229 if (style->xthickness > 1)
2230 gdk_draw_line (window, style->bg_gc[state_type],
2231 x + 1, y + 1, x + 1, y + height - 2);
2234 case GTK_SHADOW_ETCHED_IN:
2235 case GTK_SHADOW_ETCHED_OUT:
2236 if (style->xthickness > 0)
2238 if (style->xthickness > 1)
2240 thickness_light = 1;
2243 for (i = 0; i < thickness_dark; i++)
2245 gdk_draw_line (window, gc1,
2249 y + height - i - 1);
2250 gdk_draw_line (window, gc2,
2254 y + height - i - 2);
2257 for (i = 0; i < thickness_light; i++)
2259 gdk_draw_line (window, gc1,
2260 x + thickness_dark + i,
2261 y + thickness_dark + i,
2262 x + thickness_dark + i,
2263 y + height - thickness_dark - i - 1);
2264 gdk_draw_line (window, gc2,
2265 x + width - thickness_light - i - 1,
2266 y + thickness_dark + i,
2267 x + width - thickness_light - i - 1,
2268 y + height - thickness_light - 1);
2273 gdk_draw_line (window,
2274 style->dark_gc[state_type],
2275 x, y, x, y + height);
2276 gdk_draw_line (window,
2277 style->dark_gc[state_type],
2278 x + width, y, x + width, y + height);
2282 if (style->ythickness > 0)
2284 if (style->ythickness > 1)
2286 thickness_light = 1;
2289 for (i = 0; i < thickness_dark; i++)
2291 gdk_draw_line (window, gc1,
2295 y + height - i - 1);
2297 gdk_draw_line (window, gc2,
2304 for (i = 0; i < thickness_light; i++)
2306 gdk_draw_line (window, gc1,
2307 x + thickness_dark + i,
2308 y + thickness_dark + i,
2309 x + width - thickness_dark - i - 1,
2310 y + thickness_dark + i);
2312 gdk_draw_line (window, gc2,
2313 x + thickness_dark + i,
2314 y + height - thickness_light - i - 1,
2315 x + width - thickness_light - 1,
2316 y + height - thickness_light - i - 1);
2321 gdk_draw_line (window,
2322 style->dark_gc[state_type],
2323 x, y, x + width, y);
2324 gdk_draw_line (window,
2325 style->dark_gc[state_type],
2326 x, y + height, x + width, y + height);
2334 gdk_gc_set_clip_rectangle (gc1, NULL);
2335 gdk_gc_set_clip_rectangle (gc2, NULL);
2336 if (shadow_type == GTK_SHADOW_IN ||
2337 shadow_type == GTK_SHADOW_OUT)
2339 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2340 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2346 gtk_default_draw_polygon (GtkStyle *style,
2348 GtkStateType state_type,
2349 GtkShadowType shadow_type,
2352 const gchar *detail,
2357 static const gdouble pi_over_4 = G_PI_4;
2358 static const gdouble pi_3_over_4 = G_PI_4 * 3;
2368 g_return_if_fail (GTK_IS_STYLE (style));
2369 g_return_if_fail (window != NULL);
2370 g_return_if_fail (points != NULL);
2372 switch (shadow_type)
2375 gc1 = style->bg_gc[state_type];
2376 gc2 = style->dark_gc[state_type];
2377 gc3 = style->light_gc[state_type];
2378 gc4 = style->black_gc;
2380 case GTK_SHADOW_ETCHED_IN:
2381 gc1 = style->light_gc[state_type];
2382 gc2 = style->dark_gc[state_type];
2383 gc3 = style->dark_gc[state_type];
2384 gc4 = style->light_gc[state_type];
2386 case GTK_SHADOW_OUT:
2387 gc1 = style->dark_gc[state_type];
2388 gc2 = style->light_gc[state_type];
2389 gc3 = style->black_gc;
2390 gc4 = style->bg_gc[state_type];
2392 case GTK_SHADOW_ETCHED_OUT:
2393 gc1 = style->dark_gc[state_type];
2394 gc2 = style->light_gc[state_type];
2395 gc3 = style->light_gc[state_type];
2396 gc4 = style->dark_gc[state_type];
2404 gdk_gc_set_clip_rectangle (gc1, area);
2405 gdk_gc_set_clip_rectangle (gc2, area);
2406 gdk_gc_set_clip_rectangle (gc3, area);
2407 gdk_gc_set_clip_rectangle (gc4, area);
2411 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, npoints);
2415 for (i = 0; i < npoints; i++)
2417 if ((points[i].x == points[i+1].x) &&
2418 (points[i].y == points[i+1].y))
2424 angle = atan2 (points[i+1].y - points[i].y,
2425 points[i+1].x - points[i].x);
2428 if ((angle > -pi_3_over_4) && (angle < pi_over_4))
2430 if (angle > -pi_over_4)
2441 gdk_draw_line (window, gc1,
2442 points[i].x-xadjust, points[i].y-yadjust,
2443 points[i+1].x-xadjust, points[i+1].y-yadjust);
2444 gdk_draw_line (window, gc3,
2445 points[i].x, points[i].y,
2446 points[i+1].x, points[i+1].y);
2450 if ((angle < -pi_3_over_4) || (angle > pi_3_over_4))
2461 gdk_draw_line (window, gc4,
2462 points[i].x+xadjust, points[i].y+yadjust,
2463 points[i+1].x+xadjust, points[i+1].y+yadjust);
2464 gdk_draw_line (window, gc2,
2465 points[i].x, points[i].y,
2466 points[i+1].x, points[i+1].y);
2472 gdk_gc_set_clip_rectangle (gc1, NULL);
2473 gdk_gc_set_clip_rectangle (gc2, NULL);
2474 gdk_gc_set_clip_rectangle (gc3, NULL);
2475 gdk_gc_set_clip_rectangle (gc4, NULL);
2480 draw_varrow (GdkWindow *window,
2482 GtkShadowType shadow_type,
2484 GtkArrowType arrow_type,
2491 gint y_start, y_increment;
2495 gdk_gc_set_clip_rectangle (gc, area);
2497 width = width + width % 2 - 1; /* Force odd */
2499 steps = 1 + width / 2;
2501 extra = height - steps;
2503 if (arrow_type == GTK_ARROW_DOWN)
2510 y_start = y + height - 1;
2514 for (i = 0; i < extra; i++)
2516 gdk_draw_line (window, gc,
2517 x, y_start + i * y_increment,
2518 x + width - 1, y_start + i * y_increment);
2520 for (; i < height; i++)
2522 gdk_draw_line (window, gc,
2523 x + (i - extra), y_start + i * y_increment,
2524 x + width - (i - extra) - 1, y_start + i * y_increment);
2529 gdk_gc_set_clip_rectangle (gc, NULL);
2533 draw_harrow (GdkWindow *window,
2535 GtkShadowType shadow_type,
2537 GtkArrowType arrow_type,
2544 gint x_start, x_increment;
2548 gdk_gc_set_clip_rectangle (gc, area);
2550 height = height + height % 2 - 1; /* Force odd */
2552 steps = 1 + height / 2;
2554 extra = width - steps;
2556 if (arrow_type == GTK_ARROW_RIGHT)
2563 x_start = x + width - 1;
2567 for (i = 0; i < extra; i++)
2569 gdk_draw_line (window, gc,
2570 x_start + i * x_increment, y,
2571 x_start + i * x_increment, y + height - 1);
2573 for (; i < width; i++)
2575 gdk_draw_line (window, gc,
2576 x_start + i * x_increment, y + (i - extra),
2577 x_start + i * x_increment, y + height - (i - extra) - 1);
2582 gdk_gc_set_clip_rectangle (gc, NULL);
2586 gtk_default_draw_arrow (GtkStyle *style,
2589 GtkShadowType shadow,
2592 const gchar *detail,
2593 GtkArrowType arrow_type,
2600 sanitize_size (window, &width, &height);
2602 if (detail && strcmp (detail, "spinbutton") == 0)
2605 int my_height = height;
2606 int my_width = width;
2609 if (my_height > my_width)
2611 vpad_add = (my_height - my_width) / 2;
2612 my_height = my_width;
2615 hpad = my_width / 4;
2620 vpad = 2 * hpad - 1;
2627 draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
2628 x, y, my_width - hpad, my_height - vpad);
2630 else if (detail && strcmp (detail, "vscrollbar") == 0)
2632 gtk_paint_box (style, window, state, shadow, area,
2633 widget, detail, x, y, width, height);
2635 x += (width - 7) / 2;
2636 y += (height - 5) / 2;
2638 draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
2641 else if (detail && strcmp (detail, "hscrollbar") == 0)
2643 gtk_paint_box (style, window, state, shadow, area,
2644 widget, detail, x, y, width, height);
2646 y += (height - 7) / 2;
2647 x += (width - 5) / 2;
2649 draw_harrow (window, style->fg_gc[state], shadow, area, arrow_type,
2654 if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
2656 x += (width - 7) / 2;
2657 y += (height - 5) / 2;
2659 draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
2664 x += (width - 5) / 2;
2665 y += (height - 7) / 2;
2667 draw_harrow (window, style->fg_gc[state], shadow, area, arrow_type,
2674 gtk_default_draw_diamond (GtkStyle *style,
2676 GtkStateType state_type,
2677 GtkShadowType shadow_type,
2680 const gchar *detail,
2688 GdkGC *outer_nw = NULL;
2689 GdkGC *outer_ne = NULL;
2690 GdkGC *outer_sw = NULL;
2691 GdkGC *outer_se = NULL;
2692 GdkGC *middle_nw = NULL;
2693 GdkGC *middle_ne = NULL;
2694 GdkGC *middle_sw = NULL;
2695 GdkGC *middle_se = NULL;
2696 GdkGC *inner_nw = NULL;
2697 GdkGC *inner_ne = NULL;
2698 GdkGC *inner_sw = NULL;
2699 GdkGC *inner_se = NULL;
2701 g_return_if_fail (GTK_IS_STYLE (style));
2702 g_return_if_fail (window != NULL);
2704 sanitize_size (window, &width, &height);
2706 half_width = width / 2;
2707 half_height = height / 2;
2711 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
2712 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2713 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
2714 gdk_gc_set_clip_rectangle (style->black_gc, area);
2717 switch (shadow_type)
2720 inner_sw = inner_se = style->bg_gc[state_type];
2721 middle_sw = middle_se = style->light_gc[state_type];
2722 outer_sw = outer_se = style->light_gc[state_type];
2723 inner_nw = inner_ne = style->black_gc;
2724 middle_nw = middle_ne = style->dark_gc[state_type];
2725 outer_nw = outer_ne = style->dark_gc[state_type];
2728 case GTK_SHADOW_OUT:
2729 inner_sw = inner_se = style->dark_gc[state_type];
2730 middle_sw = middle_se = style->dark_gc[state_type];
2731 outer_sw = outer_se = style->black_gc;
2732 inner_nw = inner_ne = style->bg_gc[state_type];
2733 middle_nw = middle_ne = style->light_gc[state_type];
2734 outer_nw = outer_ne = style->light_gc[state_type];
2737 case GTK_SHADOW_ETCHED_IN:
2738 inner_sw = inner_se = style->bg_gc[state_type];
2739 middle_sw = middle_se = style->dark_gc[state_type];
2740 outer_sw = outer_se = style->light_gc[state_type];
2741 inner_nw = inner_ne = style->bg_gc[state_type];
2742 middle_nw = middle_ne = style->light_gc[state_type];
2743 outer_nw = outer_ne = style->dark_gc[state_type];
2746 case GTK_SHADOW_ETCHED_OUT:
2747 inner_sw = inner_se = style->bg_gc[state_type];
2748 middle_sw = middle_se = style->light_gc[state_type];
2749 outer_sw = outer_se = style->dark_gc[state_type];
2750 inner_nw = inner_ne = style->bg_gc[state_type];
2751 middle_nw = middle_ne = style->dark_gc[state_type];
2752 outer_nw = outer_ne = style->light_gc[state_type];
2762 gdk_draw_line (window, inner_sw,
2763 x + 2, y + half_height,
2764 x + half_width, y + height - 2);
2765 gdk_draw_line (window, inner_se,
2766 x + half_width, y + height - 2,
2767 x + width - 2, y + half_height);
2768 gdk_draw_line (window, middle_sw,
2769 x + 1, y + half_height,
2770 x + half_width, y + height - 1);
2771 gdk_draw_line (window, middle_se,
2772 x + half_width, y + height - 1,
2773 x + width - 1, y + half_height);
2774 gdk_draw_line (window, outer_sw,
2776 x + half_width, y + height);
2777 gdk_draw_line (window, outer_se,
2778 x + half_width, y + height,
2779 x + width, y + half_height);
2781 gdk_draw_line (window, inner_nw,
2782 x + 2, y + half_height,
2783 x + half_width, y + 2);
2784 gdk_draw_line (window, inner_ne,
2785 x + half_width, y + 2,
2786 x + width - 2, y + half_height);
2787 gdk_draw_line (window, middle_nw,
2788 x + 1, y + half_height,
2789 x + half_width, y + 1);
2790 gdk_draw_line (window, middle_ne,
2791 x + half_width, y + 1,
2792 x + width - 1, y + half_height);
2793 gdk_draw_line (window, outer_nw,
2796 gdk_draw_line (window, outer_ne,
2798 x + width, y + half_height);
2803 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
2804 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2805 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
2806 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2811 gtk_default_draw_string (GtkStyle *style,
2813 GtkStateType state_type,
2816 const gchar *detail,
2819 const gchar *string)
2821 g_return_if_fail (GTK_IS_STYLE (style));
2822 g_return_if_fail (window != NULL);
2826 gdk_gc_set_clip_rectangle (style->white_gc, area);
2827 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], area);
2830 if (state_type == GTK_STATE_INSENSITIVE)
2831 gdk_draw_string (window, gtk_style_get_font (style), style->white_gc, x + 1, y + 1, string);
2833 gdk_draw_string (window, gtk_style_get_font (style), style->fg_gc[state_type], x, y, string);
2837 gdk_gc_set_clip_rectangle (style->white_gc, NULL);
2838 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], NULL);
2843 option_menu_get_props (GtkWidget *widget,
2844 GtkRequisition *indicator_size,
2845 GtkBorder *indicator_spacing)
2847 GtkRequisition *tmp_size = NULL;
2848 GtkBorder *tmp_spacing = NULL;
2851 gtk_widget_style_get (widget,
2852 "indicator_size", &tmp_size,
2853 "indicator_spacing", &tmp_spacing,
2858 *indicator_size = *tmp_size;
2862 *indicator_size = default_option_indicator_size;
2866 *indicator_spacing = *tmp_spacing;
2867 g_free (tmp_spacing);
2870 *indicator_spacing = default_option_indicator_spacing;
2874 gtk_default_draw_box (GtkStyle *style,
2876 GtkStateType state_type,
2877 GtkShadowType shadow_type,
2880 const gchar *detail,
2886 g_return_if_fail (GTK_IS_STYLE (style));
2887 g_return_if_fail (window != NULL);
2889 sanitize_size (window, &width, &height);
2891 if (!style->bg_pixmap[state_type] ||
2892 GDK_IS_PIXMAP (window))
2895 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2897 gdk_draw_rectangle (window, style->bg_gc[state_type], TRUE,
2898 x, y, width, height);
2900 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2903 gtk_style_apply_default_background (style, window,
2904 widget && !GTK_WIDGET_NO_WINDOW (widget),
2905 state_type, area, x, y, width, height);
2907 gtk_paint_shadow (style, window, state_type, shadow_type, area, widget, detail,
2908 x, y, width, height);
2910 if (detail && strcmp (detail, "optionmenu") == 0)
2912 GtkRequisition indicator_size;
2913 GtkBorder indicator_spacing;
2915 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
2917 sanitize_size (window, &width, &height);
2919 gtk_paint_vline (style, window, state_type, area, widget,
2921 y + style->ythickness + 1,
2922 y + height - style->ythickness - 3,
2923 x + width - (indicator_size.width + indicator_spacing.left + indicator_spacing.right) - style->xthickness);
2928 get_darkened_gc (GdkWindow *window,
2932 GdkColor src = *color;
2936 gc = gdk_gc_new (window);
2938 while (darken_count)
2940 gtk_style_shade (&src, &shaded, 0.93);
2945 gdk_gc_set_rgb_fg_color (gc, &shaded);
2951 gtk_default_draw_flat_box (GtkStyle *style,
2953 GtkStateType state_type,
2954 GtkShadowType shadow_type,
2957 const gchar *detail,
2964 GdkGC *freeme = NULL;
2966 g_return_if_fail (GTK_IS_STYLE (style));
2967 g_return_if_fail (window != NULL);
2969 sanitize_size (window, &width, &height);
2973 if (state_type == GTK_STATE_SELECTED)
2975 if (!strcmp ("text", detail))
2976 gc1 = style->bg_gc[GTK_STATE_SELECTED];
2977 else if (!strncmp ("cell_even", detail, strlen ("cell_even")) ||
2978 !strncmp ("cell_odd", detail, strlen ("cell_odd")))
2980 /* This has to be really broken; alex made me do it. -jrb */
2981 if (GTK_WIDGET_HAS_FOCUS (widget))
2982 gc1 = style->base_gc[state_type];
2984 gc1 = style->base_gc[GTK_STATE_ACTIVE];
2988 gc1 = style->bg_gc[state_type];
2993 if (!strcmp ("viewportbin", detail))
2994 gc1 = style->bg_gc[GTK_STATE_NORMAL];
2995 else if (!strcmp ("entry_bg", detail))
2996 gc1 = style->base_gc[state_type];
2998 /* For trees: even rows are base color, odd rows are a shade of
2999 * the base color, the sort column is a shade of the original color
3003 /* FIXME when we have style properties, clean this up.
3006 else if (!strcmp ("cell_even", detail) ||
3007 !strcmp ("cell_odd", detail) ||
3008 !strcmp ("cell_even_ruled", detail))
3010 gc1 = style->base_gc[state_type];
3012 else if (!strcmp ("cell_even_sorted", detail) ||
3013 !strcmp ("cell_odd_sorted", detail) ||
3014 !strcmp ("cell_odd_ruled", detail) ||
3015 !strcmp ("cell_even_ruled_sorted", detail))
3017 freeme = get_darkened_gc (window, &style->base[state_type], 1);
3020 else if (!strcmp ("cell_odd_ruled_sorted", detail))
3022 freeme = get_darkened_gc (window, &style->base[state_type], 2);
3026 gc1 = style->bg_gc[state_type];
3030 gc1 = style->bg_gc[state_type];
3032 if (!style->bg_pixmap[state_type] || gc1 != style->bg_gc[state_type] ||
3033 GDK_IS_PIXMAP (window))
3036 gdk_gc_set_clip_rectangle (gc1, area);
3038 gdk_draw_rectangle (window, gc1, TRUE,
3039 x, y, width, height);
3041 if (detail && !strcmp ("tooltip", detail))
3042 gdk_draw_rectangle (window, style->black_gc, FALSE,
3043 x, y, width - 1, height - 1);
3046 gdk_gc_set_clip_rectangle (gc1, NULL);
3049 gtk_style_apply_default_background (style, window,
3050 widget && !GTK_WIDGET_NO_WINDOW (widget),
3051 state_type, area, x, y, width, height);
3055 g_object_unref (G_OBJECT (freeme));
3059 gtk_default_draw_check (GtkStyle *style,
3061 GtkStateType state_type,
3062 GtkShadowType shadow_type,
3065 const gchar *detail,
3071 if (detail && strcmp (detail, "cellcheck") == 0)
3073 gdk_draw_rectangle (window,
3074 widget->style->base_gc[state_type],
3078 gdk_draw_rectangle (window,
3079 widget->style->text_gc[state_type],
3084 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3085 y -= (((1 + INDICATOR_PART_SIZE - height) / 2) - 1);
3086 if (shadow_type == GTK_SHADOW_IN)
3088 draw_part (window, style->text_gc[state_type], area, x, y, CHECK_TEXT);
3089 draw_part (window, style->text_aa_gc[state_type], area, x, y, CHECK_AA);
3094 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3095 y -= (1 + INDICATOR_PART_SIZE - height) / 2;
3097 if (strcmp (detail, "check") == 0) /* Menu item */
3099 if (shadow_type == GTK_SHADOW_IN)
3101 draw_part (window, style->black_gc, area, x, y, CHECK_TEXT);
3102 draw_part (window, style->dark_gc[state_type], area, x, y, CHECK_AA);
3107 draw_part (window, style->black_gc, area, x, y, CHECK_BLACK);
3108 draw_part (window, style->dark_gc[state_type], area, x, y, CHECK_DARK);
3109 draw_part (window, style->mid_gc[state_type], area, x, y, CHECK_MID);
3110 draw_part (window, style->light_gc[state_type], area, x, y, CHECK_LIGHT);
3111 draw_part (window, style->base_gc[state_type], area, x, y, CHECK_BASE);
3113 if (shadow_type == GTK_SHADOW_IN)
3115 draw_part (window, style->text_gc[state_type], area, x, y, CHECK_TEXT);
3116 draw_part (window, style->text_aa_gc[state_type], area, x, y, CHECK_AA);
3124 gtk_default_draw_option (GtkStyle *style,
3126 GtkStateType state_type,
3127 GtkShadowType shadow_type,
3130 const gchar *detail,
3136 if (detail && strcmp (detail, "cellradio") == 0)
3138 gdk_draw_arc (window,
3139 widget->style->fg_gc[state_type],
3146 if (shadow_type == GTK_SHADOW_IN)
3148 gdk_draw_arc (window,
3149 widget->style->fg_gc[state_type],
3160 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3161 y -= (1 + INDICATOR_PART_SIZE - height) / 2;
3163 if (strcmp (detail, "option") == 0) /* Menu item */
3165 if (shadow_type == GTK_SHADOW_IN)
3166 draw_part (window, style->fg_gc[state_type], area, x, y, RADIO_TEXT);
3170 draw_part (window, style->black_gc, area, x, y, RADIO_BLACK);
3171 draw_part (window, style->dark_gc[state_type], area, x, y, RADIO_DARK);
3172 draw_part (window, style->mid_gc[state_type], area, x, y, RADIO_MID);
3173 draw_part (window, style->light_gc[state_type], area, x, y, RADIO_LIGHT);
3174 draw_part (window, style->base_gc[state_type], area, x, y, RADIO_BASE);
3176 if (shadow_type == GTK_SHADOW_IN)
3177 draw_part (window, style->text_gc[state_type], area, x, y, RADIO_TEXT);
3183 gtk_default_draw_tab (GtkStyle *style,
3185 GtkStateType state_type,
3186 GtkShadowType shadow_type,
3189 const gchar *detail,
3195 GtkRequisition indicator_size;
3196 GtkBorder indicator_spacing;
3198 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
3200 x += (width - indicator_size.width) / 2;
3201 y += (height - indicator_size.height) / 2 - 1;
3203 draw_varrow (window, style->black_gc, shadow_type, area, GTK_ARROW_UP,
3204 x, y, indicator_size.width, 5);
3205 draw_varrow (window, style->black_gc, shadow_type, area, GTK_ARROW_DOWN,
3206 x, y + 8, indicator_size.width, 5);
3210 gtk_default_draw_shadow_gap (GtkStyle *style,
3212 GtkStateType state_type,
3213 GtkShadowType shadow_type,
3216 const gchar *detail,
3221 GtkPositionType gap_side,
3230 g_return_if_fail (GTK_IS_STYLE (style));
3231 g_return_if_fail (window != NULL);
3233 sanitize_size (window, &width, &height);
3235 switch (shadow_type)
3237 case GTK_SHADOW_NONE:
3240 gc1 = style->dark_gc[state_type];
3241 gc2 = style->black_gc;
3242 gc3 = style->bg_gc[state_type];
3243 gc4 = style->light_gc[state_type];
3245 case GTK_SHADOW_ETCHED_IN:
3246 gc1 = style->dark_gc[state_type];
3247 gc2 = style->light_gc[state_type];
3248 gc3 = style->dark_gc[state_type];
3249 gc4 = style->light_gc[state_type];
3251 case GTK_SHADOW_OUT:
3252 gc1 = style->light_gc[state_type];
3253 gc2 = style->bg_gc[state_type];
3254 gc3 = style->dark_gc[state_type];
3255 gc4 = style->black_gc;
3257 case GTK_SHADOW_ETCHED_OUT:
3258 gc1 = style->light_gc[state_type];
3259 gc2 = style->dark_gc[state_type];
3260 gc3 = style->light_gc[state_type];
3261 gc4 = style->dark_gc[state_type];
3266 gdk_gc_set_clip_rectangle (gc1, area);
3267 gdk_gc_set_clip_rectangle (gc2, area);
3268 gdk_gc_set_clip_rectangle (gc3, area);
3269 gdk_gc_set_clip_rectangle (gc4, area);
3272 switch (shadow_type)
3274 case GTK_SHADOW_NONE:
3276 case GTK_SHADOW_OUT:
3277 case GTK_SHADOW_ETCHED_IN:
3278 case GTK_SHADOW_ETCHED_OUT:
3282 gdk_draw_line (window, gc1,
3283 x, y, x, y + height - 1);
3284 gdk_draw_line (window, gc2,
3285 x + 1, y, x + 1, y + height - 2);
3287 gdk_draw_line (window, gc3,
3288 x + 1, y + height - 2, x + width - 2, y + height - 2);
3289 gdk_draw_line (window, gc3,
3290 x + width - 2, y, x + width - 2, y + height - 2);
3291 gdk_draw_line (window, gc4,
3292 x, y + height - 1, x + width - 1, y + height - 1);
3293 gdk_draw_line (window, gc4,
3294 x + width - 1, y, x + width - 1, y + height - 1);
3297 gdk_draw_line (window, gc1,
3298 x, y, x + gap_x - 1, y);
3299 gdk_draw_line (window, gc2,
3300 x + 1, y + 1, x + gap_x - 1, y + 1);
3301 gdk_draw_line (window, gc2,
3302 x + gap_x, y, x + gap_x, y);
3304 if ((width - (gap_x + gap_width)) > 0)
3306 gdk_draw_line (window, gc1,
3307 x + gap_x + gap_width, y, x + width - 2, y);
3308 gdk_draw_line (window, gc2,
3309 x + gap_x + gap_width, y + 1, x + width - 3, y + 1);
3310 gdk_draw_line (window, gc2,
3311 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
3314 case GTK_POS_BOTTOM:
3315 gdk_draw_line (window, gc1,
3316 x, y, x + width - 1, y);
3317 gdk_draw_line (window, gc1,
3318 x, y, x, y + height - 1);
3319 gdk_draw_line (window, gc2,
3320 x + 1, y + 1, x + width - 2, y + 1);
3321 gdk_draw_line (window, gc2,
3322 x + 1, y + 1, x + 1, y + height - 1);
3324 gdk_draw_line (window, gc3,
3325 x + width - 2, y + 1, x + width - 2, y + height - 1);
3326 gdk_draw_line (window, gc4,
3327 x + width - 1, y, x + width - 1, y + height - 1);
3330 gdk_draw_line (window, gc4,
3331 x, y + height - 1, x + gap_x - 1, y + height - 1);
3332 gdk_draw_line (window, gc3,
3333 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
3334 gdk_draw_line (window, gc3,
3335 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
3337 if ((width - (gap_x + gap_width)) > 0)
3339 gdk_draw_line (window, gc4,
3340 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
3341 gdk_draw_line (window, gc3,
3342 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
3343 gdk_draw_line (window, gc3,
3344 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
3348 gdk_draw_line (window, gc1,
3349 x, y, x + width - 1, y);
3350 gdk_draw_line (window, gc2,
3351 x, y + 1, x + width - 2, y + 1);
3353 gdk_draw_line (window, gc3,
3354 x, y + height - 2, x + width - 2, y + height - 2);
3355 gdk_draw_line (window, gc3,
3356 x + width - 2, y + 1, x + width - 2, y + height - 2);
3357 gdk_draw_line (window, gc4,
3358 x, y + height - 1, x + width - 1, y + height - 1);
3359 gdk_draw_line (window, gc4,
3360 x + width - 1, y, x + width - 1, y + height - 1);
3363 gdk_draw_line (window, gc1,
3364 x, y, x, y + gap_x - 1);
3365 gdk_draw_line (window, gc2,
3366 x + 1, y + 1, x + 1, y + gap_x - 1);
3367 gdk_draw_line (window, gc2,
3368 x, y + gap_x, x, y + gap_x);
3370 if ((width - (gap_x + gap_width)) > 0)
3372 gdk_draw_line (window, gc1,
3373 x, y + gap_x + gap_width, x, y + height - 2);
3374 gdk_draw_line (window, gc2,
3375 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
3376 gdk_draw_line (window, gc2,
3377 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
3381 gdk_draw_line (window, gc1,
3382 x, y, x + width - 1, y);
3383 gdk_draw_line (window, gc1,
3384 x, y, x, y + height - 1);
3385 gdk_draw_line (window, gc2,
3386 x + 1, y + 1, x + width - 1, y + 1);
3387 gdk_draw_line (window, gc2,
3388 x + 1, y + 1, x + 1, y + height - 2);
3390 gdk_draw_line (window, gc3,
3391 x + 1, y + height - 2, x + width - 1, y + height - 2);
3392 gdk_draw_line (window, gc4,
3393 x, y + height - 1, x + width - 1, y + height - 1);
3396 gdk_draw_line (window, gc4,
3397 x + width - 1, y, x + width - 1, y + gap_x - 1);
3398 gdk_draw_line (window, gc3,
3399 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
3400 gdk_draw_line (window, gc3,
3401 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
3403 if ((width - (gap_x + gap_width)) > 0)
3405 gdk_draw_line (window, gc4,
3406 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
3407 gdk_draw_line (window, gc3,
3408 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
3409 gdk_draw_line (window, gc3,
3410 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
3418 gdk_gc_set_clip_rectangle (gc1, NULL);
3419 gdk_gc_set_clip_rectangle (gc2, NULL);
3420 gdk_gc_set_clip_rectangle (gc3, NULL);
3421 gdk_gc_set_clip_rectangle (gc4, NULL);
3426 gtk_default_draw_box_gap (GtkStyle *style,
3428 GtkStateType state_type,
3429 GtkShadowType shadow_type,
3432 const gchar *detail,
3437 GtkPositionType gap_side,
3446 g_return_if_fail (GTK_IS_STYLE (style));
3447 g_return_if_fail (window != NULL);
3449 gtk_style_apply_default_background (style, window,
3450 widget && !GTK_WIDGET_NO_WINDOW (widget),
3451 state_type, area, x, y, width, height);
3453 sanitize_size (window, &width, &height);
3455 switch (shadow_type)
3457 case GTK_SHADOW_NONE:
3460 gc1 = style->dark_gc[state_type];
3461 gc2 = style->black_gc;
3462 gc3 = style->bg_gc[state_type];
3463 gc4 = style->light_gc[state_type];
3465 case GTK_SHADOW_ETCHED_IN:
3466 gc1 = style->dark_gc[state_type];
3467 gc2 = style->light_gc[state_type];
3468 gc3 = style->dark_gc[state_type];
3469 gc4 = style->light_gc[state_type];
3471 case GTK_SHADOW_OUT:
3472 gc1 = style->light_gc[state_type];
3473 gc2 = style->bg_gc[state_type];
3474 gc3 = style->dark_gc[state_type];
3475 gc4 = style->black_gc;
3477 case GTK_SHADOW_ETCHED_OUT:
3478 gc1 = style->light_gc[state_type];
3479 gc2 = style->dark_gc[state_type];
3480 gc3 = style->light_gc[state_type];
3481 gc4 = style->dark_gc[state_type];
3487 gdk_gc_set_clip_rectangle (gc1, area);
3488 gdk_gc_set_clip_rectangle (gc2, area);
3489 gdk_gc_set_clip_rectangle (gc3, area);
3490 gdk_gc_set_clip_rectangle (gc4, area);
3493 switch (shadow_type)
3495 case GTK_SHADOW_NONE:
3497 case GTK_SHADOW_OUT:
3498 case GTK_SHADOW_ETCHED_IN:
3499 case GTK_SHADOW_ETCHED_OUT:
3503 gdk_draw_line (window, gc1,
3504 x, y, x, y + height - 1);
3505 gdk_draw_line (window, gc2,
3506 x + 1, y, x + 1, y + height - 2);
3508 gdk_draw_line (window, gc3,
3509 x + 1, y + height - 2, x + width - 2, y + height - 2);
3510 gdk_draw_line (window, gc3,
3511 x + width - 2, y, x + width - 2, y + height - 2);
3512 gdk_draw_line (window, gc4,
3513 x, y + height - 1, x + width - 1, y + height - 1);
3514 gdk_draw_line (window, gc4,
3515 x + width - 1, y, x + width - 1, y + height - 1);
3518 gdk_draw_line (window, gc1,
3519 x, y, x + gap_x - 1, y);
3520 gdk_draw_line (window, gc2,
3521 x + 1, y + 1, x + gap_x - 1, y + 1);
3522 gdk_draw_line (window, gc2,
3523 x + gap_x, y, x + gap_x, y);
3525 if ((width - (gap_x + gap_width)) > 0)
3527 gdk_draw_line (window, gc1,
3528 x + gap_x + gap_width, y, x + width - 2, y);
3529 gdk_draw_line (window, gc2,
3530 x + gap_x + gap_width, y + 1, x + width - 2, y + 1);
3531 gdk_draw_line (window, gc2,
3532 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
3535 case GTK_POS_BOTTOM:
3536 gdk_draw_line (window, gc1,
3537 x, y, x + width - 1, y);
3538 gdk_draw_line (window, gc1,
3539 x, y, x, y + height - 1);
3540 gdk_draw_line (window, gc2,
3541 x + 1, y + 1, x + width - 2, y + 1);
3542 gdk_draw_line (window, gc2,
3543 x + 1, y + 1, x + 1, y + height - 1);
3545 gdk_draw_line (window, gc3,
3546 x + width - 2, y + 1, x + width - 2, y + height - 1);
3547 gdk_draw_line (window, gc4,
3548 x + width - 1, y, x + width - 1, y + height - 1);
3551 gdk_draw_line (window, gc4,
3552 x, y + height - 1, x + gap_x - 1, y + height - 1);
3553 gdk_draw_line (window, gc3,
3554 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
3555 gdk_draw_line (window, gc3,
3556 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
3558 if ((width - (gap_x + gap_width)) > 0)
3560 gdk_draw_line (window, gc4,
3561 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
3562 gdk_draw_line (window, gc3,
3563 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
3564 gdk_draw_line (window, gc3,
3565 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
3569 gdk_draw_line (window, gc1,
3570 x, y, x + width - 1, y);
3571 gdk_draw_line (window, gc2,
3572 x, y + 1, x + width - 2, y + 1);
3574 gdk_draw_line (window, gc3,
3575 x, y + height - 2, x + width - 2, y + height - 2);
3576 gdk_draw_line (window, gc3,
3577 x + width - 2, y + 1, x + width - 2, y + height - 2);
3578 gdk_draw_line (window, gc4,
3579 x, y + height - 1, x + width - 1, y + height - 1);
3580 gdk_draw_line (window, gc4,
3581 x + width - 1, y, x + width - 1, y + height - 1);
3584 gdk_draw_line (window, gc1,
3585 x, y, x, y + gap_x - 1);
3586 gdk_draw_line (window, gc2,
3587 x + 1, y + 1, x + 1, y + gap_x - 1);
3588 gdk_draw_line (window, gc2,
3589 x, y + gap_x, x, y + gap_x);
3591 if ((width - (gap_x + gap_width)) > 0)
3593 gdk_draw_line (window, gc1,
3594 x, y + gap_x + gap_width, x, y + height - 2);
3595 gdk_draw_line (window, gc2,
3596 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
3597 gdk_draw_line (window, gc2,
3598 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
3602 gdk_draw_line (window, gc1,
3603 x, y, x + width - 1, y);
3604 gdk_draw_line (window, gc1,
3605 x, y, x, y + height - 1);
3606 gdk_draw_line (window, gc2,
3607 x + 1, y + 1, x + width - 1, y + 1);
3608 gdk_draw_line (window, gc2,
3609 x + 1, y + 1, x + 1, y + height - 2);
3611 gdk_draw_line (window, gc3,
3612 x + 1, y + height - 2, x + width - 1, y + height - 2);
3613 gdk_draw_line (window, gc4,
3614 x, y + height - 1, x + width - 1, y + height - 1);
3617 gdk_draw_line (window, gc4,
3618 x + width - 1, y, x + width - 1, y + gap_x - 1);
3619 gdk_draw_line (window, gc3,
3620 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
3621 gdk_draw_line (window, gc3,
3622 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
3624 if ((width - (gap_x + gap_width)) > 0)
3626 gdk_draw_line (window, gc4,
3627 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
3628 gdk_draw_line (window, gc3,
3629 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
3630 gdk_draw_line (window, gc3,
3631 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
3639 gdk_gc_set_clip_rectangle (gc1, NULL);
3640 gdk_gc_set_clip_rectangle (gc2, NULL);
3641 gdk_gc_set_clip_rectangle (gc3, NULL);
3642 gdk_gc_set_clip_rectangle (gc4, NULL);
3647 gtk_default_draw_extension (GtkStyle *style,
3649 GtkStateType state_type,
3650 GtkShadowType shadow_type,
3653 const gchar *detail,
3658 GtkPositionType gap_side)
3665 g_return_if_fail (GTK_IS_STYLE (style));
3666 g_return_if_fail (window != NULL);
3668 gtk_style_apply_default_background (style, window,
3669 widget && !GTK_WIDGET_NO_WINDOW (widget),
3670 GTK_STATE_NORMAL, area, x, y, width, height);
3672 sanitize_size (window, &width, &height);
3674 switch (shadow_type)
3676 case GTK_SHADOW_NONE:
3679 gc1 = style->dark_gc[state_type];
3680 gc2 = style->black_gc;
3681 gc3 = style->bg_gc[state_type];
3682 gc4 = style->light_gc[state_type];
3684 case GTK_SHADOW_ETCHED_IN:
3685 gc1 = style->dark_gc[state_type];
3686 gc2 = style->light_gc[state_type];
3687 gc3 = style->dark_gc[state_type];
3688 gc4 = style->light_gc[state_type];
3690 case GTK_SHADOW_OUT:
3691 gc1 = style->light_gc[state_type];
3692 gc2 = style->bg_gc[state_type];
3693 gc3 = style->dark_gc[state_type];
3694 gc4 = style->black_gc;
3696 case GTK_SHADOW_ETCHED_OUT:
3697 gc1 = style->light_gc[state_type];
3698 gc2 = style->dark_gc[state_type];
3699 gc3 = style->light_gc[state_type];
3700 gc4 = style->dark_gc[state_type];
3706 gdk_gc_set_clip_rectangle (gc1, area);
3707 gdk_gc_set_clip_rectangle (gc2, area);
3708 gdk_gc_set_clip_rectangle (gc3, area);
3709 gdk_gc_set_clip_rectangle (gc4, area);
3712 switch (shadow_type)
3714 case GTK_SHADOW_NONE:
3716 case GTK_SHADOW_OUT:
3717 case GTK_SHADOW_ETCHED_IN:
3718 case GTK_SHADOW_ETCHED_OUT:
3722 gtk_style_apply_default_background (style, window,
3723 widget && !GTK_WIDGET_NO_WINDOW (widget),
3725 x + style->xthickness,
3727 width - (2 * style->xthickness),
3728 height - (style->ythickness));
3729 gdk_draw_line (window, gc1,
3730 x, y, x, y + height - 2);
3731 gdk_draw_line (window, gc2,
3732 x + 1, y, x + 1, y + height - 2);
3734 gdk_draw_line (window, gc3,
3735 x + 2, y + height - 2, x + width - 2, y + height - 2);
3736 gdk_draw_line (window, gc3,
3737 x + width - 2, y, x + width - 2, y + height - 2);
3738 gdk_draw_line (window, gc4,
3739 x + 1, y + height - 1, x + width - 2, y + height - 1);
3740 gdk_draw_line (window, gc4,
3741 x + width - 1, y, x + width - 1, y + height - 2);
3743 case GTK_POS_BOTTOM:
3744 gtk_style_apply_default_background (style, window,
3745 widget && !GTK_WIDGET_NO_WINDOW (widget),
3747 x + style->xthickness,
3748 y + style->ythickness,
3749 width - (2 * style->xthickness),
3750 height - (style->ythickness));
3751 gdk_draw_line (window, gc1,
3752 x + 1, y, x + width - 2, y);
3753 gdk_draw_line (window, gc1,
3754 x, y + 1, x, y + height - 1);
3755 gdk_draw_line (window, gc2,
3756 x + 1, y + 1, x + width - 2, y + 1);
3757 gdk_draw_line (window, gc2,
3758 x + 1, y + 1, x + 1, y + height - 1);
3760 gdk_draw_line (window, gc3,
3761 x + width - 2, y + 2, x + width - 2, y + height - 1);
3762 gdk_draw_line (window, gc4,
3763 x + width - 1, y + 1, x + width - 1, y + height - 1);
3766 gtk_style_apply_default_background (style, window,
3767 widget && !GTK_WIDGET_NO_WINDOW (widget),
3770 y + style->ythickness,
3771 width - (style->xthickness),
3772 height - (2 * style->ythickness));
3773 gdk_draw_line (window, gc1,
3774 x, y, x + width - 2, y);
3775 gdk_draw_line (window, gc2,
3776 x + 1, y + 1, x + width - 2, y + 1);
3778 gdk_draw_line (window, gc3,
3779 x, y + height - 2, x + width - 2, y + height - 2);
3780 gdk_draw_line (window, gc3,
3781 x + width - 2, y + 2, x + width - 2, y + height - 2);
3782 gdk_draw_line (window, gc4,
3783 x, y + height - 1, x + width - 2, y + height - 1);
3784 gdk_draw_line (window, gc4,
3785 x + width - 1, y + 1, x + width - 1, y + height - 2);
3788 gtk_style_apply_default_background (style, window,
3789 widget && !GTK_WIDGET_NO_WINDOW (widget),
3791 x + style->xthickness,
3792 y + style->ythickness,
3793 width - (style->xthickness),
3794 height - (2 * style->ythickness));
3795 gdk_draw_line (window, gc1,
3796 x + 1, y, x + width - 1, y);
3797 gdk_draw_line (window, gc1,
3798 x, y + 1, x, y + height - 2);
3799 gdk_draw_line (window, gc2,
3800 x + 1, y + 1, x + width - 1, y + 1);
3801 gdk_draw_line (window, gc2,
3802 x + 1, y + 1, x + 1, y + height - 2);
3804 gdk_draw_line (window, gc3,
3805 x + 2, y + height - 2, x + width - 1, y + height - 2);
3806 gdk_draw_line (window, gc4,
3807 x + 1, y + height - 1, x + width - 1, y + height - 1);
3814 gdk_gc_set_clip_rectangle (gc1, NULL);
3815 gdk_gc_set_clip_rectangle (gc2, NULL);
3816 gdk_gc_set_clip_rectangle (gc3, NULL);
3817 gdk_gc_set_clip_rectangle (gc4, NULL);
3822 gtk_default_draw_focus (GtkStyle *style,
3824 GtkStateType state_type,
3827 const gchar *detail,
3835 gboolean free_dash_list = FALSE;
3836 gint line_width = 1;
3837 gchar *dash_list = "\1\1";
3840 gc = style->fg_gc[state_type];
3844 gtk_widget_style_get (widget,
3845 "focus-line-width", &line_width,
3846 "focus-line-pattern", (gchar *)&dash_list,
3849 free_dash_list = TRUE;
3852 sanitize_size (window, &width, &height);
3855 gdk_gc_set_clip_rectangle (gc, area);
3857 gdk_gc_set_line_attributes (gc, line_width,
3858 dash_list[0] ? GDK_LINE_ON_OFF_DASH : GDK_LINE_SOLID,
3859 GDK_CAP_BUTT, GDK_JOIN_MITER);
3862 if (detail && !strcmp (detail, "add-mode"))
3868 free_dash_list = FALSE;
3871 points[0].x = x + line_width / 2;
3872 points[0].y = y + line_width / 2;
3873 points[1].x = x + width - line_width + line_width / 2;
3874 points[1].y = y + line_width / 2;
3875 points[2].x = x + width - line_width + line_width / 2;
3876 points[2].y = y + height - line_width + line_width / 2;
3877 points[3].x = x + line_width / 2;
3878 points[3].y = y + height - line_width + line_width / 2;
3879 points[4] = points[0];
3883 gdk_draw_lines (window, gc, points, 5);
3887 /* We go through all the pain below because the X rasterization
3888 * rules don't really work right for dashed lines if you
3889 * want continuity in segments that go between top/right
3890 * and left/bottom. For instance, a top left corner
3891 * with a 1-1 dash is drawn as:
3898 * This is because pixels on the top and left boundaries
3899 * of polygons are drawn, but not on the bottom and right.
3900 * So, if you have a line going up that turns the corner
3901 * and goes right, there is a one pixel shift in the pattern.
3903 * So, to fix this, we drawn the top and right in one call,
3904 * then the left and bottom in another call, fixing up
3905 * the dash offset for the second call ourselves to get
3906 * continuity at the upper left.
3908 * It's not perfect since we really should have a join at
3909 * the upper left and lower right instead of two intersecting
3910 * lines but that's only really apparent for no-dashes,
3911 * which (for this reason) are done as one polygon and
3912 * don't to through this code path.
3915 dash_len = strlen (dash_list);
3918 gdk_gc_set_dashes (gc, 0, dash_list, dash_len);
3920 gdk_draw_lines (window, gc, points, 3);
3922 /* We draw this line one farther over than it is "supposed" to
3923 * because of another rasterization problem ... if two 1 pixel
3924 * unjoined lines meet at the lower right, there will be a missing
3931 gint dash_pixels = 0;
3934 /* Adjust the dash offset for the bottom and left so we
3935 * match up at the upper left.
3937 for (i = 0; i < dash_len; i++)
3938 dash_pixels += dash_list[i];
3940 if (dash_len % 2 == 1)
3943 gdk_gc_set_dashes (gc, dash_pixels - (width + height - 2 * line_width) % dash_pixels, dash_list, dash_len);
3946 gdk_draw_lines (window, gc, points + 2, 3);
3949 gdk_gc_set_line_attributes (gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
3952 gdk_gc_set_clip_rectangle (gc, NULL);
3959 gtk_default_draw_slider (GtkStyle *style,
3961 GtkStateType state_type,
3962 GtkShadowType shadow_type,
3965 const gchar *detail,
3970 GtkOrientation orientation)
3972 g_return_if_fail (GTK_IS_STYLE (style));
3973 g_return_if_fail (window != NULL);
3975 sanitize_size (window, &width, &height);
3977 gtk_paint_box (style, window, state_type, shadow_type,
3978 area, widget, detail, x, y, width, height);
3981 (strcmp ("hscale", detail) == 0 ||
3982 strcmp ("vscale", detail) == 0))
3984 if (orientation == GTK_ORIENTATION_HORIZONTAL)
3985 gtk_paint_vline (style, window, state_type, area, widget, detail,
3986 y + style->ythickness,
3987 y + height - style->ythickness - 1, x + width / 2);
3989 gtk_paint_hline (style, window, state_type, area, widget, detail,
3990 x + style->xthickness,
3991 x + width - style->xthickness - 1, y + height / 2);
3996 draw_dot (GdkWindow *window,
4004 size = CLAMP (size, 2, 3);
4008 gdk_draw_point (window, light_gc, x, y);
4009 gdk_draw_point (window, light_gc, x+1, y+1);
4011 else if (size == 3);
4013 gdk_draw_point (window, light_gc, x, y);
4014 gdk_draw_point (window, light_gc, x+1, y);
4015 gdk_draw_point (window, light_gc, x, y+1);
4016 gdk_draw_point (window, dark_gc, x+1, y+2);
4017 gdk_draw_point (window, dark_gc, x+2, y+1);
4018 gdk_draw_point (window, dark_gc, x+2, y+2);
4023 gtk_default_draw_handle (GtkStyle *style,
4025 GtkStateType state_type,
4026 GtkShadowType shadow_type,
4029 const gchar *detail,
4034 GtkOrientation orientation)
4037 gint xthick, ythick;
4038 GdkGC *light_gc, *dark_gc;
4043 g_return_if_fail (GTK_IS_STYLE (style));
4044 g_return_if_fail (window != NULL);
4046 sanitize_size (window, &width, &height);
4048 gtk_paint_box (style, window, state_type, shadow_type, area, widget,
4049 detail, x, y, width, height);
4052 if (!strcmp (detail, "paned"))
4054 /* we want to ignore the shadow border in paned widgets */
4058 light_gc = style->light_gc[state_type];
4059 dark_gc = style->black_gc;
4063 xthick = style->xthickness;
4064 ythick = style->ythickness;
4066 light_gc = style->light_gc[state_type];
4067 dark_gc = style->dark_gc[state_type];
4070 rect.x = x + xthick;
4071 rect.y = y + ythick;
4072 rect.width = width - (xthick * 2);
4073 rect.height = height - (ythick * 2);
4076 intersect = gdk_rectangle_intersect (area, &rect, &dest);
4086 gdk_gc_set_clip_rectangle (light_gc, &dest);
4087 gdk_gc_set_clip_rectangle (dark_gc, &dest);
4089 if (!strcmp (detail, "paned"))
4091 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4092 for (xx = x + width/2 - 15; xx <= x + width/2 + 15; xx += 5)
4093 draw_dot (window, light_gc, dark_gc, xx, y + height/2 - 1, 3);
4095 for (yy = y + height/2 - 15; yy <= y + height/2 + 15; yy += 5)
4096 draw_dot (window, light_gc, dark_gc, x + width/2 - 1, yy, 3);
4100 for (yy = y + ythick; yy < (y + height - ythick); yy += 3)
4101 for (xx = x + xthick; xx < (x + width - xthick); xx += 6)
4103 draw_dot (window, light_gc, dark_gc, xx, yy, 2);
4104 draw_dot (window, light_gc, dark_gc, xx + 3, yy + 1, 2);
4108 gdk_gc_set_clip_rectangle (light_gc, NULL);
4109 gdk_gc_set_clip_rectangle (dark_gc, NULL);
4113 create_expander_affine (gdouble affine[6],
4123 width = expander_size / 4.0;
4124 height = expander_size / 2.0;
4126 s = sin (degrees * G_PI / 180.0);
4127 c = cos (degrees * G_PI / 180.0);
4133 affine[4] = -width * c - height * -s + x;
4134 affine[5] = -width * s - height * c + y;
4138 apply_affine_on_point (double affine[6], GdkPoint *point)
4142 x = point->x * affine[0] + point->y * affine[2] + affine[4];
4143 y = point->x * affine[1] + point->y * affine[3] + affine[5];
4150 gtk_default_draw_expander (GtkStyle *style,
4152 GtkStateType state_type,
4155 const gchar *detail,
4158 GtkExpanderStyle expander_style)
4166 gtk_widget_style_get (widget,
4167 "expander_size", &expander_size,
4172 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], area);
4173 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], area);
4178 points[1].x = expander_size / 2;
4179 points[1].y = expander_size / 2;
4181 points[2].y = expander_size;
4183 switch (expander_style)
4185 case GTK_EXPANDER_COLLAPSED:
4188 case GTK_EXPANDER_SEMI_COLLAPSED:
4191 case GTK_EXPANDER_SEMI_EXPANDED:
4194 case GTK_EXPANDER_EXPANDED:
4198 g_assert_not_reached ();
4201 create_expander_affine (affine, degrees, expander_size, x, y);
4203 for (i = 0; i < 3; i++)
4204 apply_affine_on_point (affine, &points[i]);
4206 if (state_type == GTK_STATE_PRELIGHT)
4208 gdk_draw_polygon (window, style->fg_gc[GTK_STATE_NORMAL],
4211 else if (state_type == GTK_STATE_ACTIVE)
4213 gdk_draw_polygon (window, style->light_gc[GTK_STATE_ACTIVE],
4215 gdk_draw_polygon (window, style->fg_gc[GTK_STATE_NORMAL],
4220 gdk_draw_polygon (window, style->base_gc[GTK_STATE_NORMAL],
4222 gdk_draw_polygon (window, style->fg_gc[GTK_STATE_NORMAL],
4227 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], NULL);
4228 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], NULL);
4232 typedef struct _ByteRange ByteRange;
4241 range_new (guint start,
4244 ByteRange *br = g_new (ByteRange, 1);
4253 get_insensitive_layout (PangoLayout *layout)
4255 GSList *embossed_ranges = NULL;
4256 GSList *stippled_ranges = NULL;
4257 PangoLayoutIter *iter;
4258 GSList *tmp_list = NULL;
4259 PangoLayout *new_layout;
4260 PangoAttrList *attrs;
4261 GdkBitmap *stipple = NULL;
4263 iter = pango_layout_get_iter (layout);
4267 PangoLayoutRun *run;
4268 PangoAttribute *attr;
4269 gboolean need_stipple = FALSE;
4272 run = pango_layout_iter_get_run (iter);
4276 tmp_list = run->item->analysis.extra_attrs;
4278 while (tmp_list != NULL)
4280 attr = tmp_list->data;
4281 switch (attr->klass->type)
4283 case PANGO_ATTR_FOREGROUND:
4284 case PANGO_ATTR_BACKGROUND:
4285 need_stipple = TRUE;
4295 tmp_list = g_slist_next (tmp_list);
4298 br = range_new (run->item->offset, run->item->offset + run->item->length);
4301 stippled_ranges = g_slist_prepend (stippled_ranges, br);
4303 embossed_ranges = g_slist_prepend (embossed_ranges, br);
4306 while (pango_layout_iter_next_run (iter));
4308 pango_layout_iter_free (iter);
4310 new_layout = pango_layout_copy (layout);
4312 attrs = pango_layout_get_attributes (new_layout);
4316 /* Create attr list if there wasn't one */
4317 attrs = pango_attr_list_new ();
4318 pango_layout_set_attributes (new_layout, attrs);
4319 pango_attr_list_unref (attrs);
4322 tmp_list = embossed_ranges;
4323 while (tmp_list != NULL)
4325 PangoAttribute *attr;
4326 ByteRange *br = tmp_list->data;
4328 attr = gdk_pango_attr_embossed_new (TRUE);
4330 attr->start_index = br->start;
4331 attr->end_index = br->end;
4333 pango_attr_list_change (attrs, attr);
4337 tmp_list = g_slist_next (tmp_list);
4340 g_slist_free (embossed_ranges);
4342 tmp_list = stippled_ranges;
4343 while (tmp_list != NULL)
4345 PangoAttribute *attr;
4346 ByteRange *br = tmp_list->data;
4348 if (stipple == NULL)
4350 #define gray50_width 2
4351 #define gray50_height 2
4352 static char gray50_bits[] = {
4356 stipple = gdk_bitmap_create_from_data (NULL,
4357 gray50_bits, gray50_width,
4361 attr = gdk_pango_attr_stipple_new (stipple);
4363 attr->start_index = br->start;
4364 attr->end_index = br->end;
4366 pango_attr_list_change (attrs, attr);
4370 tmp_list = g_slist_next (tmp_list);
4373 g_slist_free (stippled_ranges);
4376 g_object_unref (G_OBJECT (stipple));
4382 gtk_default_draw_layout (GtkStyle *style,
4384 GtkStateType state_type,
4388 const gchar *detail,
4391 PangoLayout *layout)
4395 g_return_if_fail (GTK_IS_STYLE (style));
4396 g_return_if_fail (window != NULL);
4398 gc = use_text ? style->text_gc[state_type] : style->fg_gc[state_type];
4401 gdk_gc_set_clip_rectangle (gc, area);
4403 if (state_type == GTK_STATE_INSENSITIVE)
4407 ins = get_insensitive_layout (layout);
4409 gdk_draw_layout (window, gc, x, y, ins);
4411 g_object_unref (G_OBJECT (ins));
4415 gdk_draw_layout (window, gc, x, y, layout);
4419 gdk_gc_set_clip_rectangle (gc, NULL);
4423 gtk_default_draw_resize_grip (GtkStyle *style,
4425 GtkStateType state_type,
4428 const gchar *detail,
4435 g_return_if_fail (GTK_IS_STYLE (style));
4436 g_return_if_fail (window != NULL);
4440 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
4441 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
4442 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
4445 /* make it square, aligning to bottom right */
4448 y += (height - width);
4451 else if (height < width)
4453 x += (width - height);
4457 /* Clear background */
4458 gdk_draw_rectangle (window,
4459 style->bg_gc[state_type],
4461 x, y, width, height);
4465 case GDK_WINDOW_EDGE_SOUTH_EAST:
4472 while (xi < (x + width - 3))
4474 gdk_draw_line (window,
4475 style->light_gc[state_type],
4482 gdk_draw_line (window,
4483 style->dark_gc[state_type],
4490 gdk_draw_line (window,
4491 style->dark_gc[state_type],
4501 g_assert_not_reached ();
4507 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
4508 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
4509 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
4514 gtk_style_shade (GdkColor *a,
4522 red = (gdouble) a->red / 65535.0;
4523 green = (gdouble) a->green / 65535.0;
4524 blue = (gdouble) a->blue / 65535.0;
4526 rgb_to_hls (&red, &green, &blue);
4531 else if (green < 0.0)
4537 else if (blue < 0.0)
4540 hls_to_rgb (&red, &green, &blue);
4542 b->red = red * 65535.0;
4543 b->green = green * 65535.0;
4544 b->blue = blue * 65535.0;
4548 rgb_to_hls (gdouble *r,
4589 l = (max + min) / 2;
4596 s = (max - min) / (max + min);
4598 s = (max - min) / (2 - max - min);
4602 h = (green - blue) / delta;
4603 else if (green == max)
4604 h = 2 + (blue - red) / delta;
4605 else if (blue == max)
4606 h = 4 + (red - green) / delta;
4619 hls_to_rgb (gdouble *h,
4632 if (lightness <= 0.5)
4633 m2 = lightness * (1 + saturation);
4635 m2 = lightness + saturation - lightness * saturation;
4636 m1 = 2 * lightness - m2;
4638 if (saturation == 0)
4653 r = m1 + (m2 - m1) * hue / 60;
4657 r = m1 + (m2 - m1) * (240 - hue) / 60;
4668 g = m1 + (m2 - m1) * hue / 60;
4672 g = m1 + (m2 - m1) * (240 - hue) / 60;
4683 b = m1 + (m2 - m1) * hue / 60;
4687 b = m1 + (m2 - m1) * (240 - hue) / 60;
4700 * @style: a #GtkStyle
4701 * @window: a #GdkWindow
4702 * @state_type: a state
4703 * @area: rectangle to which the output is clipped
4706 * @x1: the starting x coordinate
4707 * @x2: the ending x coordinate
4708 * @y: the y coordinate
4710 * Draws a horizontal line from (@x1, @y) to (@x2, @y) in @window
4711 * using the given style and state.
4714 gtk_paint_hline (GtkStyle *style,
4716 GtkStateType state_type,
4719 const gchar *detail,
4724 g_return_if_fail (GTK_IS_STYLE (style));
4725 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
4727 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, area, widget, detail, x1, x2, y);
4732 * @style: a #GtkStyle
4733 * @window: a #GdkWindow
4734 * @state_type: a state
4735 * @area: rectangle to which the output is clipped
4738 * @y1: the starting y coordinate
4739 * @y2: the ending y coordinate
4740 * @x: the x coordinate
4742 * Draws a vertical line from (@x, @y1) to (@x, @y1) in @window
4743 * using the given style and state.
4746 gtk_paint_vline (GtkStyle *style,
4748 GtkStateType state_type,
4751 const gchar *detail,
4756 g_return_if_fail (GTK_IS_STYLE (style));
4757 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
4759 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, area, widget, detail, y1, y2, x);
4763 gtk_paint_shadow (GtkStyle *style,
4765 GtkStateType state_type,
4766 GtkShadowType shadow_type,
4769 const gchar *detail,
4775 g_return_if_fail (GTK_IS_STYLE (style));
4776 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
4778 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4782 gtk_paint_polygon (GtkStyle *style,
4784 GtkStateType state_type,
4785 GtkShadowType shadow_type,
4788 const gchar *detail,
4793 g_return_if_fail (GTK_IS_STYLE (style));
4794 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
4796 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, area, widget, detail, points, npoints, fill);
4800 gtk_paint_arrow (GtkStyle *style,
4802 GtkStateType state_type,
4803 GtkShadowType shadow_type,
4806 const gchar *detail,
4807 GtkArrowType arrow_type,
4814 g_return_if_fail (GTK_IS_STYLE (style));
4815 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
4817 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, area, widget, detail, arrow_type, fill, x, y, width, height);
4821 gtk_paint_diamond (GtkStyle *style,
4823 GtkStateType state_type,
4824 GtkShadowType shadow_type,
4827 const gchar *detail,
4833 g_return_if_fail (GTK_IS_STYLE (style));
4834 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
4836 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4840 gtk_paint_string (GtkStyle *style,
4842 GtkStateType state_type,
4845 const gchar *detail,
4848 const gchar *string)
4850 g_return_if_fail (GTK_IS_STYLE (style));
4851 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
4853 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, area, widget, detail, x, y, string);
4857 gtk_paint_box (GtkStyle *style,
4859 GtkStateType state_type,
4860 GtkShadowType shadow_type,
4863 const gchar *detail,
4869 g_return_if_fail (GTK_IS_STYLE (style));
4870 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
4872 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4876 gtk_paint_flat_box (GtkStyle *style,
4878 GtkStateType state_type,
4879 GtkShadowType shadow_type,
4882 const gchar *detail,
4888 g_return_if_fail (GTK_IS_STYLE (style));
4889 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
4891 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4895 gtk_paint_check (GtkStyle *style,
4897 GtkStateType state_type,
4898 GtkShadowType shadow_type,
4901 const gchar *detail,
4907 g_return_if_fail (GTK_IS_STYLE (style));
4908 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
4910 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4914 gtk_paint_option (GtkStyle *style,
4916 GtkStateType state_type,
4917 GtkShadowType shadow_type,
4920 const gchar *detail,
4926 g_return_if_fail (GTK_IS_STYLE (style));
4927 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
4929 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4933 gtk_paint_tab (GtkStyle *style,
4935 GtkStateType state_type,
4936 GtkShadowType shadow_type,
4939 const gchar *detail,
4945 g_return_if_fail (GTK_IS_STYLE (style));
4946 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
4948 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4952 gtk_paint_shadow_gap (GtkStyle *style,
4954 GtkStateType state_type,
4955 GtkShadowType shadow_type,
4963 GtkPositionType gap_side,
4967 g_return_if_fail (GTK_IS_STYLE (style));
4968 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
4970 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);
4975 gtk_paint_box_gap (GtkStyle *style,
4977 GtkStateType state_type,
4978 GtkShadowType shadow_type,
4986 GtkPositionType gap_side,
4990 g_return_if_fail (GTK_IS_STYLE (style));
4991 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
4993 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);
4997 gtk_paint_extension (GtkStyle *style,
4999 GtkStateType state_type,
5000 GtkShadowType shadow_type,
5008 GtkPositionType gap_side)
5010 g_return_if_fail (GTK_IS_STYLE (style));
5011 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
5013 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side);
5017 gtk_paint_focus (GtkStyle *style,
5019 GtkStateType state_type,
5022 const gchar *detail,
5028 g_return_if_fail (GTK_IS_STYLE (style));
5029 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
5031 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, state_type, area, widget, detail, x, y, width, height);
5035 gtk_paint_slider (GtkStyle *style,
5037 GtkStateType state_type,
5038 GtkShadowType shadow_type,
5041 const gchar *detail,
5046 GtkOrientation orientation)
5048 g_return_if_fail (GTK_IS_STYLE (style));
5049 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
5051 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
5055 gtk_paint_handle (GtkStyle *style,
5057 GtkStateType state_type,
5058 GtkShadowType shadow_type,
5061 const gchar *detail,
5066 GtkOrientation orientation)
5068 g_return_if_fail (GTK_IS_STYLE (style));
5069 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
5071 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
5075 gtk_paint_expander (GtkStyle *style,
5077 GtkStateType state_type,
5080 const gchar *detail,
5083 GtkExpanderStyle expander_style)
5085 g_return_if_fail (GTK_IS_STYLE (style));
5086 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
5088 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type, area,
5089 widget, detail, x, y, expander_style);
5093 gtk_paint_layout (GtkStyle *style,
5095 GtkStateType state_type,
5099 const gchar *detail,
5102 PangoLayout *layout)
5104 g_return_if_fail (GTK_IS_STYLE (style));
5105 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
5107 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text, area,
5108 widget, detail, x, y, layout);
5112 gtk_paint_resize_grip (GtkStyle *style,
5114 GtkStateType state_type,
5117 const gchar *detail,
5125 g_return_if_fail (GTK_IS_STYLE (style));
5126 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
5128 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
5129 area, widget, detail,
5130 edge, x, y, width, height);
5135 * @border: a #GtkBorder.
5136 * @returns: a copy of @border.
5138 * Copies a #GtkBorder structure.
5141 gtk_border_copy (const GtkBorder *border)
5143 return (GtkBorder *)g_memdup (border, sizeof (GtkBorder));
5148 * @border: a #GtkBorder.
5150 * Frees a #GtkBorder structure.
5153 gtk_border_free (GtkBorder *border)
5159 * gtk_style_get_font:
5160 * @style: a #GtkStyle
5162 * Gets the #GdkFont to use for the given style. This is
5163 * meant only as a replacement for direct access to @style->font
5164 * and should not be used in new code. New code should
5165 * use @style->font_desc instead.
5167 * Return value: the #GdkFont for the style. This font is owned
5168 * by the style; if you want to keep around a copy, you must
5169 * call gdk_font_ref().
5172 gtk_style_get_font (GtkStyle *style)
5174 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
5176 if (style->private_font && style->private_font_desc)
5178 if (!style->font_desc ||
5179 !pango_font_description_equal (style->private_font_desc, style->font_desc))
5181 gdk_font_unref (style->private_font);
5182 style->private_font = NULL;
5184 if (style->private_font_desc)
5186 pango_font_description_free (style->private_font_desc);
5187 style->private_font_desc = NULL;
5192 if (!style->private_font)
5194 if (style->font_desc)
5196 style->private_font = gdk_font_from_description (style->font_desc);
5197 style->private_font_desc = pango_font_description_copy (style->font_desc);
5200 if (!style->private_font)
5201 style->private_font = gdk_font_load ("fixed");
5203 if (!style->private_font)
5204 g_error ("Unable to load \"fixed\" font");
5207 return style->private_font;
5211 * gtk_style_set_font:
5212 * @style: a #GtkStyle.
5213 * @font: a #GdkFont, or %NULL to use the #GdkFont corresponding
5214 * to style->font_desc.
5216 * Sets the #GdkFont to use for a given style. This is
5217 * meant only as a replacement for direct access to style->font
5218 * and should not be used in new code. New code should
5219 * use style->font_desc instead.
5222 gtk_style_set_font (GtkStyle *style,
5227 g_return_if_fail (GTK_IS_STYLE (style));
5229 old_font = style->private_font;
5231 style->private_font = font;
5233 gdk_font_ref (font);
5236 gdk_font_unref (old_font);
5238 if (style->private_font_desc)
5240 pango_font_description_free (style->private_font_desc);
5241 style->private_font_desc = NULL;
5246 * _gtk_draw_insertion_cursor:
5247 * @drawable: a #GdkDrawable
5249 * @location: location where to draw the cursor (@location->width is ignored)
5250 * @dir: text direction for the cursor, used to decide whether to draw a
5251 * directional arrow on the cursor and in what direction. Unless both
5252 * strong and weak cursors are displayed, this should be %GTK_TEXT_DIR_NONE.
5254 * Draws a text caret on @drawable at @location. This is not a style function
5255 * but merely a convenience function for drawing the standard cursor shape.
5258 _gtk_draw_insertion_cursor (GdkDrawable *drawable,
5260 GdkRectangle *location,
5261 GtkTextDirection dir)
5263 gint stem_width = location->height / 30 + 1;
5264 gint arrow_width = stem_width + 1;
5268 for (i = 0; i < stem_width; i++)
5269 gdk_draw_line (drawable, gc,
5270 location->x + i - stem_width / 2, location->y,
5271 location->x + i - stem_width / 2, location->y + location->height);
5273 if (dir == GTK_TEXT_DIR_RTL)
5275 x = location->x - stem_width / 2 - 1;
5276 y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
5278 for (i = 0; i < arrow_width; i++)
5280 gdk_draw_line (drawable, gc,
5282 x, y + 2 * arrow_width - i - 1);
5286 else if (dir == GTK_TEXT_DIR_LTR)
5288 x = location->x + stem_width - stem_width / 2;
5289 y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
5291 for (i = 0; i < arrow_width; i++)
5293 gdk_draw_line (drawable, gc,
5295 x, y + 2 * arrow_width - i - 1);