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,
249 static void gtk_default_draw_slider (GtkStyle *style,
251 GtkStateType state_type,
252 GtkShadowType shadow_type,
260 GtkOrientation orientation);
261 static void gtk_default_draw_handle (GtkStyle *style,
263 GtkStateType state_type,
264 GtkShadowType shadow_type,
272 GtkOrientation orientation);
273 static void gtk_default_draw_expander (GtkStyle *style,
275 GtkStateType state_type,
281 GtkExpanderStyle expander_style);
282 static void gtk_default_draw_layout (GtkStyle *style,
284 GtkStateType state_type,
291 PangoLayout *layout);
292 static void gtk_default_draw_resize_grip (GtkStyle *style,
294 GtkStateType state_type,
304 static void gtk_style_shade (GdkColor *a,
307 static void rgb_to_hls (gdouble *r,
310 static void hls_to_rgb (gdouble *h,
316 * Data for default check and radio buttons
319 static GtkRequisition default_option_indicator_size = { 7, 13 };
320 static GtkBorder default_option_indicator_spacing = { 7, 5, 2, 2 };
322 #define INDICATOR_PART_SIZE 13
340 static char check_aa_bits[] = {
341 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x58,0x00,0xa0,
342 0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
343 static char check_base_bits[] = {
344 0x00,0x00,0x00,0x00,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,
345 0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0x00,0x00,0x00,0x00};
346 static char check_black_bits[] = {
347 0x00,0x00,0xfe,0x0f,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
348 0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x00,0x00};
349 static char check_dark_bits[] = {
350 0xff,0x1f,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
351 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00};
352 static char check_light_bits[] = {
353 0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
354 0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0xfe,0x1f};
355 static char check_mid_bits[] = {
356 0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,
357 0x08,0x00,0x08,0x00,0x08,0x00,0x08,0xfc,0x0f,0x00,0x00};
358 static char check_text_bits[] = {
359 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x03,0x80,0x01,0x80,0x00,0xd8,
360 0x00,0x60,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
361 static char radio_base_bits[] = {
362 0x00,0x00,0x00,0x00,0xf0,0x01,0xf8,0x03,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,
363 0x07,0xfc,0x07,0xf8,0x03,0xf0,0x01,0x00,0x00,0x00,0x00};
364 static char radio_black_bits[] = {
365 0x00,0x00,0xf0,0x01,0x08,0x02,0x04,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
366 0x00,0x02,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
367 static char radio_dark_bits[] = {
368 0xf0,0x01,0x08,0x02,0x04,0x04,0x02,0x04,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
369 0x00,0x01,0x00,0x02,0x00,0x0c,0x00,0x00,0x00,0x00,0x00};
370 static char radio_light_bits[] = {
371 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
372 0x10,0x00,0x10,0x00,0x08,0x00,0x04,0x08,0x02,0xf0,0x01};
373 static char radio_mid_bits[] = {
374 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,
375 0x08,0x00,0x08,0x00,0x04,0x00,0x02,0xf0,0x01,0x00,0x00};
376 static char radio_text_bits[] = {
377 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x00,0xf0,0x01,0xf0,0x01,0xf0,
378 0x01,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
383 } indicator_parts[] = {
384 { check_aa_bits, NULL },
385 { check_base_bits, NULL },
386 { check_black_bits, NULL },
387 { check_dark_bits, NULL },
388 { check_light_bits, NULL },
389 { check_mid_bits, NULL },
390 { check_text_bits, NULL },
391 { radio_base_bits, NULL },
392 { radio_black_bits, NULL },
393 { radio_dark_bits, NULL },
394 { radio_light_bits, NULL },
395 { radio_mid_bits, NULL },
396 { radio_text_bits, NULL }
399 /* --- variables --- */
400 static GdkColor gtk_default_normal_fg = { 0, 0, 0, 0 };
401 static GdkColor gtk_default_active_fg = { 0, 0, 0, 0 };
402 static GdkColor gtk_default_prelight_fg = { 0, 0, 0, 0 };
403 static GdkColor gtk_default_selected_fg = { 0, 0xffff, 0xffff, 0xffff };
404 static GdkColor gtk_default_insensitive_fg = { 0, 0x7530, 0x7530, 0x7530 };
406 static GdkColor gtk_default_normal_bg = { 0, 0xd6d6, 0xd6d6, 0xd6d6 };
407 static GdkColor gtk_default_active_bg = { 0, 0xc350, 0xc350, 0xc350 };
408 static GdkColor gtk_default_prelight_bg = { 0, 0xea60, 0xea60, 0xea60 };
409 static GdkColor gtk_default_selected_bg = { 0, 0, 0, 0x9c40 };
410 static GdkColor gtk_default_insensitive_bg = { 0, 0xd6d6, 0xd6d6, 0xd6d6 };
411 static GdkColor gtk_default_selected_base = { 0, 0xa4a4, 0xdfdf, 0xffff };
412 static GdkColor gtk_default_active_base = { 0, 0xbcbc, 0xd2d2, 0xeeee };
414 static gpointer parent_class = NULL;
417 /* --- functions --- */
419 gtk_style_get_type (void)
421 static GType style_type = 0;
425 static const GTypeInfo style_info =
427 sizeof (GtkStyleClass),
428 (GBaseInitFunc) NULL,
429 (GBaseFinalizeFunc) NULL,
430 (GClassInitFunc) gtk_style_class_init,
431 NULL, /* class_finalize */
432 NULL, /* class_data */
435 (GInstanceInitFunc) gtk_style_init,
438 style_type = g_type_register_static (G_TYPE_OBJECT,
447 gtk_style_init (GtkStyle *style)
451 style->font_desc = pango_font_description_from_string ("Sans 10");
453 style->attach_count = 0;
454 style->colormap = NULL;
457 style->black.red = 0;
458 style->black.green = 0;
459 style->black.blue = 0;
461 style->white.red = 65535;
462 style->white.green = 65535;
463 style->white.blue = 65535;
465 style->black_gc = NULL;
466 style->white_gc = NULL;
468 style->fg[GTK_STATE_NORMAL] = gtk_default_normal_fg;
469 style->fg[GTK_STATE_ACTIVE] = gtk_default_active_fg;
470 style->fg[GTK_STATE_PRELIGHT] = gtk_default_prelight_fg;
471 style->fg[GTK_STATE_SELECTED] = gtk_default_selected_fg;
472 style->fg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
474 style->bg[GTK_STATE_NORMAL] = gtk_default_normal_bg;
475 style->bg[GTK_STATE_ACTIVE] = gtk_default_active_bg;
476 style->bg[GTK_STATE_PRELIGHT] = gtk_default_prelight_bg;
477 style->bg[GTK_STATE_SELECTED] = gtk_default_selected_bg;
478 style->bg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg;
480 for (i = 0; i < 4; i++)
482 style->text[i] = style->fg[i];
483 style->base[i] = style->white;
486 style->base[GTK_STATE_SELECTED] = gtk_default_selected_base;
487 style->text[GTK_STATE_SELECTED] = style->black;
488 style->base[GTK_STATE_ACTIVE] = gtk_default_active_base;
489 style->text[GTK_STATE_ACTIVE] = style->black;
490 style->base[GTK_STATE_INSENSITIVE] = gtk_default_prelight_bg;
491 style->text[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
493 for (i = 0; i < 5; i++)
494 style->bg_pixmap[i] = NULL;
496 style->rc_style = NULL;
498 for (i = 0; i < 5; i++)
500 style->fg_gc[i] = NULL;
501 style->bg_gc[i] = NULL;
502 style->light_gc[i] = NULL;
503 style->dark_gc[i] = NULL;
504 style->mid_gc[i] = NULL;
505 style->text_gc[i] = NULL;
506 style->base_gc[i] = NULL;
507 style->text_aa_gc[i] = NULL;
510 style->xthickness = 2;
511 style->ythickness = 2;
513 style->property_cache = NULL;
517 gtk_style_class_init (GtkStyleClass *klass)
519 GObjectClass *object_class = G_OBJECT_CLASS (klass);
521 parent_class = g_type_class_peek_parent (klass);
523 object_class->finalize = gtk_style_finalize;
525 klass->clone = gtk_style_real_clone;
526 klass->copy = gtk_style_real_copy;
527 klass->init_from_rc = gtk_style_real_init_from_rc;
528 klass->realize = gtk_style_real_realize;
529 klass->unrealize = gtk_style_real_unrealize;
530 klass->set_background = gtk_style_real_set_background;
531 klass->render_icon = gtk_default_render_icon;
533 klass->draw_hline = gtk_default_draw_hline;
534 klass->draw_vline = gtk_default_draw_vline;
535 klass->draw_shadow = gtk_default_draw_shadow;
536 klass->draw_polygon = gtk_default_draw_polygon;
537 klass->draw_arrow = gtk_default_draw_arrow;
538 klass->draw_diamond = gtk_default_draw_diamond;
539 klass->draw_string = gtk_default_draw_string;
540 klass->draw_box = gtk_default_draw_box;
541 klass->draw_flat_box = gtk_default_draw_flat_box;
542 klass->draw_check = gtk_default_draw_check;
543 klass->draw_option = gtk_default_draw_option;
544 klass->draw_tab = gtk_default_draw_tab;
545 klass->draw_shadow_gap = gtk_default_draw_shadow_gap;
546 klass->draw_box_gap = gtk_default_draw_box_gap;
547 klass->draw_extension = gtk_default_draw_extension;
548 klass->draw_focus = gtk_default_draw_focus;
549 klass->draw_slider = gtk_default_draw_slider;
550 klass->draw_handle = gtk_default_draw_handle;
551 klass->draw_expander = gtk_default_draw_expander;
552 klass->draw_layout = gtk_default_draw_layout;
553 klass->draw_resize_grip = gtk_default_draw_resize_grip;
557 clear_property_cache (GtkStyle *style)
559 if (style->property_cache)
563 for (i = 0; i < style->property_cache->len; i++)
565 PropertyValue *node = &g_array_index (style->property_cache, PropertyValue, i);
567 g_param_spec_unref (node->pspec);
568 g_value_unset (&node->value);
570 g_array_free (style->property_cache, TRUE);
571 style->property_cache = NULL;
576 gtk_style_finalize (GObject *object)
578 GtkStyle *style = GTK_STYLE (object);
580 g_return_if_fail (style->attach_count == 0);
582 clear_property_cache (style);
586 if (style->styles->data != style)
587 g_slist_remove (style->styles, style);
590 GSList *tmp_list = style->styles->next;
594 GTK_STYLE (tmp_list->data)->styles = style->styles->next;
595 tmp_list = tmp_list->next;
597 g_slist_free_1 (style->styles);
601 pango_font_description_free (style->font_desc);
603 if (style->private_font)
604 gdk_font_unref (style->private_font);
606 if (style->private_font_desc)
607 pango_font_description_free (style->private_font_desc);
610 gtk_rc_style_unref (style->rc_style);
612 G_OBJECT_CLASS (parent_class)->finalize (object);
617 gtk_style_copy (GtkStyle *style)
621 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
623 new_style = GTK_STYLE_GET_CLASS (style)->clone (style);
624 GTK_STYLE_GET_CLASS (style)->copy (new_style, style);
630 gtk_style_duplicate (GtkStyle *style)
634 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
636 new_style = gtk_style_copy (style);
638 style->styles = g_slist_append (style->styles, new_style);
639 new_style->styles = style->styles;
649 style = g_object_new (GTK_TYPE_STYLE, NULL);
654 /*************************************************************
656 * Attach a style to a window; this process allocates the
657 * colors and creates the GC's for the style - it specializes
658 * it to a particular visual and colormap. The process
659 * may involve the creation of a new style if the style
660 * has already been attached to a window with a different
661 * style and colormap.
666 * Either the style parameter, or a newly created style.
667 * If the style is newly created, the style parameter
668 * will be dereferenced, and the new style will have
669 * a reference count belonging to the caller.
671 * FIXME: The sequence -
672 * create a style => s1
673 * attach s1 to v1, c1 => s1
674 * attach s1 to v2, c2 => s2
675 * detach s1 from v1, c1
676 * attach s1 to v2, c2 => s3
677 * results in two separate, unlinked styles s2 and s3 which
678 * are identical and could be shared. To fix this, we would
679 * want to never remove a style from the list of linked
680 * styles as long as as it has a reference count. However, the
681 * disadvantage of doing it this way means that we would need two
682 * passes through the linked list when attaching (one to check for
683 * matching styles, one to look for empty unattached styles - but
684 * it will almost never be longer than 2 elements.
685 *************************************************************/
688 gtk_style_attach (GtkStyle *style,
692 GtkStyle *new_style = NULL;
693 GdkColormap *colormap;
695 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
696 g_return_val_if_fail (window != NULL, NULL);
698 colormap = gdk_window_get_colormap (window);
701 style->styles = g_slist_append (NULL, style);
703 styles = style->styles;
706 new_style = styles->data;
708 if (new_style->attach_count == 0)
710 gtk_style_realize (new_style, colormap);
713 else if (new_style->colormap == colormap)
717 styles = styles->next;
722 new_style = gtk_style_duplicate (style);
723 gtk_style_realize (new_style, colormap);
726 /* A style gets a refcount from being attached */
727 if (new_style->attach_count == 0)
728 g_object_ref (new_style);
730 /* Another refcount belongs to the parent */
731 if (style != new_style)
733 g_object_unref (style);
734 g_object_ref (new_style);
737 new_style->attach_count++;
743 gtk_style_detach (GtkStyle *style)
745 g_return_if_fail (GTK_IS_STYLE (style));
747 style->attach_count -= 1;
748 if (style->attach_count == 0)
750 GTK_STYLE_GET_CLASS (style)->unrealize (style);
752 gdk_colormap_unref (style->colormap);
753 style->colormap = NULL;
755 g_object_unref (style);
760 gtk_style_ref (GtkStyle *style)
762 return (GtkStyle *) g_object_ref (G_OBJECT (style));
766 gtk_style_unref (GtkStyle *style)
768 g_object_unref (G_OBJECT (style));
772 gtk_style_realize (GtkStyle *style,
773 GdkColormap *colormap)
775 g_return_if_fail (GTK_IS_STYLE (style));
776 g_return_if_fail (GDK_IS_COLORMAP (colormap));
778 style->colormap = gdk_colormap_ref (colormap);
779 style->depth = gdk_colormap_get_visual (colormap)->depth;
781 GTK_STYLE_GET_CLASS (style)->realize (style);
785 gtk_style_lookup_icon_set (GtkStyle *style,
786 const char *stock_id)
790 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
791 g_return_val_if_fail (stock_id != NULL, NULL);
793 iter = style->icon_factories;
796 GtkIconSet *icon_set = gtk_icon_factory_lookup (GTK_ICON_FACTORY (iter->data),
801 iter = g_slist_next (iter);
804 return gtk_icon_factory_lookup_default (stock_id);
808 gtk_draw_hline (GtkStyle *style,
810 GtkStateType state_type,
815 g_return_if_fail (GTK_IS_STYLE (style));
816 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
818 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, NULL, NULL, NULL, x1, x2, y);
823 gtk_draw_vline (GtkStyle *style,
825 GtkStateType state_type,
830 g_return_if_fail (GTK_IS_STYLE (style));
831 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
833 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, NULL, NULL, NULL, y1, y2, x);
838 gtk_draw_shadow (GtkStyle *style,
840 GtkStateType state_type,
841 GtkShadowType shadow_type,
847 g_return_if_fail (GTK_IS_STYLE (style));
848 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
850 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
854 gtk_draw_polygon (GtkStyle *style,
856 GtkStateType state_type,
857 GtkShadowType shadow_type,
862 g_return_if_fail (GTK_IS_STYLE (style));
863 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_polygon != NULL);
865 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, NULL, NULL, NULL, points, npoints, fill);
869 gtk_draw_arrow (GtkStyle *style,
871 GtkStateType state_type,
872 GtkShadowType shadow_type,
873 GtkArrowType arrow_type,
880 g_return_if_fail (GTK_IS_STYLE (style));
881 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
883 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, NULL, NULL, NULL, arrow_type, fill, x, y, width, height);
888 gtk_draw_diamond (GtkStyle *style,
890 GtkStateType state_type,
891 GtkShadowType shadow_type,
897 g_return_if_fail (GTK_IS_STYLE (style));
898 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
900 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
905 gtk_draw_string (GtkStyle *style,
907 GtkStateType state_type,
912 g_return_if_fail (GTK_IS_STYLE (style));
913 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
915 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, NULL, NULL, NULL, x, y, string);
919 gtk_draw_box (GtkStyle *style,
921 GtkStateType state_type,
922 GtkShadowType shadow_type,
928 g_return_if_fail (GTK_IS_STYLE (style));
929 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
931 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
935 gtk_draw_flat_box (GtkStyle *style,
937 GtkStateType state_type,
938 GtkShadowType shadow_type,
944 g_return_if_fail (GTK_IS_STYLE (style));
945 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
947 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
951 gtk_draw_check (GtkStyle *style,
953 GtkStateType state_type,
954 GtkShadowType shadow_type,
960 g_return_if_fail (GTK_IS_STYLE (style));
961 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
963 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
967 gtk_draw_option (GtkStyle *style,
969 GtkStateType state_type,
970 GtkShadowType shadow_type,
976 g_return_if_fail (GTK_IS_STYLE (style));
977 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
979 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
983 gtk_draw_tab (GtkStyle *style,
985 GtkStateType state_type,
986 GtkShadowType shadow_type,
992 g_return_if_fail (GTK_IS_STYLE (style));
993 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
995 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
999 gtk_draw_shadow_gap (GtkStyle *style,
1001 GtkStateType state_type,
1002 GtkShadowType shadow_type,
1007 GtkPositionType gap_side,
1011 g_return_if_fail (GTK_IS_STYLE (style));
1012 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
1014 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);
1018 gtk_draw_box_gap (GtkStyle *style,
1020 GtkStateType state_type,
1021 GtkShadowType shadow_type,
1026 GtkPositionType gap_side,
1030 g_return_if_fail (GTK_IS_STYLE (style));
1031 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
1033 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);
1037 gtk_draw_extension (GtkStyle *style,
1039 GtkStateType state_type,
1040 GtkShadowType shadow_type,
1045 GtkPositionType gap_side)
1047 g_return_if_fail (GTK_IS_STYLE (style));
1048 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
1050 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side);
1054 gtk_draw_focus (GtkStyle *style,
1061 g_return_if_fail (GTK_IS_STYLE (style));
1062 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
1064 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, NULL, NULL, NULL, x, y, width, height);
1068 gtk_draw_slider (GtkStyle *style,
1070 GtkStateType state_type,
1071 GtkShadowType shadow_type,
1076 GtkOrientation orientation)
1078 g_return_if_fail (GTK_IS_STYLE (style));
1079 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
1081 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
1085 gtk_draw_handle (GtkStyle *style,
1087 GtkStateType state_type,
1088 GtkShadowType shadow_type,
1093 GtkOrientation orientation)
1095 g_return_if_fail (GTK_IS_STYLE (style));
1096 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
1098 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
1102 gtk_draw_expander (GtkStyle *style,
1104 GtkStateType state_type,
1107 GtkExpanderStyle expander_style)
1109 g_return_if_fail (GTK_IS_STYLE (style));
1110 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
1112 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type,
1114 x, y, expander_style);
1118 gtk_draw_layout (GtkStyle *style,
1120 GtkStateType state_type,
1124 PangoLayout *layout)
1126 g_return_if_fail (GTK_IS_STYLE (style));
1127 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
1129 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text,
1135 gtk_draw_resize_grip (GtkStyle *style,
1137 GtkStateType state_type,
1144 g_return_if_fail (GTK_IS_STYLE (style));
1145 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
1147 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
1150 x, y, width, height);
1155 gtk_style_set_background (GtkStyle *style,
1157 GtkStateType state_type)
1159 g_return_if_fail (GTK_IS_STYLE (style));
1160 g_return_if_fail (window != NULL);
1162 GTK_STYLE_GET_CLASS (style)->set_background (style, window, state_type);
1165 /* Default functions */
1167 gtk_style_real_clone (GtkStyle *style)
1169 return GTK_STYLE (g_object_new (G_OBJECT_TYPE (style), NULL));
1173 gtk_style_real_copy (GtkStyle *style,
1178 for (i = 0; i < 5; i++)
1180 style->fg[i] = src->fg[i];
1181 style->bg[i] = src->bg[i];
1182 style->text[i] = src->text[i];
1183 style->base[i] = src->base[i];
1185 style->bg_pixmap[i] = src->bg_pixmap[i];
1188 if (style->private_font)
1189 gdk_font_unref (style->private_font);
1190 style->private_font = src->private_font;
1191 if (style->private_font)
1192 gdk_font_ref (style->private_font);
1194 if (style->font_desc)
1195 pango_font_description_free (style->font_desc);
1197 style->font_desc = pango_font_description_copy (src->font_desc);
1199 style->font_desc = NULL;
1201 style->xthickness = src->xthickness;
1202 style->ythickness = src->ythickness;
1204 if (style->rc_style)
1205 gtk_rc_style_unref (style->rc_style);
1206 style->rc_style = src->rc_style;
1208 gtk_rc_style_ref (src->rc_style);
1210 /* don't copy, just clear cache */
1211 clear_property_cache (style);
1215 gtk_style_real_init_from_rc (GtkStyle *style,
1216 GtkRcStyle *rc_style)
1220 /* cache _should_ be still empty */
1221 clear_property_cache (style);
1223 if (rc_style->font_desc)
1225 pango_font_description_free (style->font_desc);
1226 style->font_desc = pango_font_description_copy (rc_style->font_desc);
1229 for (i = 0; i < 5; i++)
1231 if (rc_style->color_flags[i] & GTK_RC_FG)
1232 style->fg[i] = rc_style->fg[i];
1233 if (rc_style->color_flags[i] & GTK_RC_BG)
1234 style->bg[i] = rc_style->bg[i];
1235 if (rc_style->color_flags[i] & GTK_RC_TEXT)
1236 style->text[i] = rc_style->text[i];
1237 if (rc_style->color_flags[i] & GTK_RC_BASE)
1238 style->base[i] = rc_style->base[i];
1241 if (rc_style->xthickness >= 0)
1242 style->xthickness = rc_style->xthickness;
1243 if (rc_style->ythickness >= 0)
1244 style->ythickness = rc_style->ythickness;
1246 if (rc_style->icon_factories)
1250 style->icon_factories = g_slist_copy (rc_style->icon_factories);
1252 iter = style->icon_factories;
1253 while (iter != NULL)
1255 g_object_ref (G_OBJECT (iter->data));
1257 iter = g_slist_next (iter);
1263 style_property_values_cmp (gconstpointer bsearch_node1,
1264 gconstpointer bsearch_node2)
1266 const PropertyValue *val1 = bsearch_node1;
1267 const PropertyValue *val2 = bsearch_node2;
1269 if (val1->widget_type == val2->widget_type)
1270 return val1->pspec < val2->pspec ? -1 : val1->pspec == val2->pspec ? 0 : 1;
1272 return val1->widget_type < val2->widget_type ? -1 : 1;
1276 _gtk_style_peek_property_value (GtkStyle *style,
1279 GtkRcPropertyParser parser)
1281 PropertyValue *pcache, key = { 0, NULL, { 0, } };
1282 const GtkRcProperty *rcprop = NULL;
1285 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1286 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), NULL);
1287 g_return_val_if_fail (g_type_is_a (pspec->owner_type, GTK_TYPE_WIDGET), NULL);
1288 g_return_val_if_fail (g_type_is_a (widget_type, pspec->owner_type), NULL);
1290 key.widget_type = widget_type;
1293 /* need value cache array */
1294 if (!style->property_cache)
1295 style->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
1298 pcache = bsearch (&key,
1299 style->property_cache->data, style->property_cache->len,
1300 sizeof (PropertyValue), style_property_values_cmp);
1302 return &pcache->value;
1306 while (i < style->property_cache->len &&
1307 style_property_values_cmp (&key, &g_array_index (style->property_cache, PropertyValue, i)) >= 0)
1310 g_array_insert_val (style->property_cache, i, key);
1311 pcache = &g_array_index (style->property_cache, PropertyValue, i);
1313 /* cache miss, initialize value type, then set contents */
1314 g_param_spec_ref (pcache->pspec);
1315 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1317 /* value provided by rc style? */
1318 if (style->rc_style)
1320 GQuark prop_quark = g_quark_from_string (pspec->name);
1324 rcprop = _gtk_rc_style_lookup_rc_property (style->rc_style,
1325 g_type_qname (widget_type),
1329 widget_type = g_type_parent (widget_type);
1331 while (g_type_is_a (widget_type, pspec->owner_type));
1334 /* when supplied by rc style, we need to convert */
1335 if (rcprop && !_gtk_settings_parse_convert (parser, &rcprop->value,
1336 pspec, &pcache->value))
1338 gchar *contents = g_strdup_value_contents (&rcprop->value);
1340 g_message ("%s: failed to retrive property `%s::%s' of type `%s' from rc file value \"%s\" of type `%s'",
1342 g_type_name (pspec->owner_type), pspec->name,
1343 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1345 G_VALUE_TYPE_NAME (&rcprop->value));
1347 rcprop = NULL; /* needs default */
1350 /* not supplied by rc style (or conversion failed), revert to default */
1352 g_param_value_set_default (pspec, &pcache->value);
1354 return &pcache->value;
1358 load_bg_image (GdkColormap *colormap,
1360 const gchar *filename)
1362 if (strcmp (filename, "<parent>") == 0)
1363 return (GdkPixmap*) GDK_PARENT_RELATIVE;
1366 return gdk_pixmap_colormap_create_from_xpm (NULL, colormap, NULL,
1373 gtk_style_real_realize (GtkStyle *style)
1375 GdkGCValues gc_values;
1376 GdkGCValuesMask gc_values_mask;
1380 for (i = 0; i < 5; i++)
1382 gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT);
1383 gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT);
1385 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
1386 style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
1387 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
1389 style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
1390 style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
1391 style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;
1394 gdk_color_black (style->colormap, &style->black);
1395 gdk_color_white (style->colormap, &style->white);
1397 gc_values_mask = GDK_GC_FOREGROUND;
1399 gc_values.foreground = style->black;
1400 style->black_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1402 gc_values.foreground = style->white;
1403 style->white_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1405 for (i = 0; i < 5; i++)
1407 if (style->rc_style && style->rc_style->bg_pixmap_name[i])
1408 style->bg_pixmap[i] = load_bg_image (style->colormap,
1410 style->rc_style->bg_pixmap_name[i]);
1412 if (!gdk_color_alloc (style->colormap, &style->fg[i]))
1413 g_warning ("unable to allocate color: ( %d %d %d )",
1414 style->fg[i].red, style->fg[i].green, style->fg[i].blue);
1415 if (!gdk_color_alloc (style->colormap, &style->bg[i]))
1416 g_warning ("unable to allocate color: ( %d %d %d )",
1417 style->bg[i].red, style->bg[i].green, style->bg[i].blue);
1418 if (!gdk_color_alloc (style->colormap, &style->light[i]))
1419 g_warning ("unable to allocate color: ( %d %d %d )",
1420 style->light[i].red, style->light[i].green, style->light[i].blue);
1421 if (!gdk_color_alloc (style->colormap, &style->dark[i]))
1422 g_warning ("unable to allocate color: ( %d %d %d )",
1423 style->dark[i].red, style->dark[i].green, style->dark[i].blue);
1424 if (!gdk_color_alloc (style->colormap, &style->mid[i]))
1425 g_warning ("unable to allocate color: ( %d %d %d )",
1426 style->mid[i].red, style->mid[i].green, style->mid[i].blue);
1427 if (!gdk_color_alloc (style->colormap, &style->text[i]))
1428 g_warning ("unable to allocate color: ( %d %d %d )",
1429 style->text[i].red, style->text[i].green, style->text[i].blue);
1430 if (!gdk_color_alloc (style->colormap, &style->base[i]))
1431 g_warning ("unable to allocate color: ( %d %d %d )",
1432 style->base[i].red, style->base[i].green, style->base[i].blue);
1433 if (!gdk_color_alloc (style->colormap, &style->text_aa[i]))
1434 g_warning ("unable to allocate color: ( %d %d %d )",
1435 style->text_aa[i].red, style->text_aa[i].green, style->text_aa[i].blue);
1437 gc_values.foreground = style->fg[i];
1438 style->fg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1440 gc_values.foreground = style->bg[i];
1441 style->bg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1443 gc_values.foreground = style->light[i];
1444 style->light_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1446 gc_values.foreground = style->dark[i];
1447 style->dark_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1449 gc_values.foreground = style->mid[i];
1450 style->mid_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1452 gc_values.foreground = style->text[i];
1453 style->text_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1455 gc_values.foreground = style->base[i];
1456 style->base_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1458 gc_values.foreground = style->text_aa[i];
1459 style->text_aa_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1464 gtk_style_real_unrealize (GtkStyle *style)
1468 gtk_gc_release (style->black_gc);
1469 gtk_gc_release (style->white_gc);
1471 for (i = 0; i < 5; i++)
1473 gtk_gc_release (style->fg_gc[i]);
1474 gtk_gc_release (style->bg_gc[i]);
1475 gtk_gc_release (style->light_gc[i]);
1476 gtk_gc_release (style->dark_gc[i]);
1477 gtk_gc_release (style->mid_gc[i]);
1478 gtk_gc_release (style->text_gc[i]);
1479 gtk_gc_release (style->base_gc[i]);
1480 gtk_gc_release (style->text_aa_gc[i]);
1482 if (style->bg_pixmap[i] && style->bg_pixmap[i] != (GdkPixmap*) GDK_PARENT_RELATIVE)
1483 gdk_pixmap_unref (style->bg_pixmap[i]);
1486 gdk_colormap_free_colors (style->colormap, style->fg, 5);
1487 gdk_colormap_free_colors (style->colormap, style->bg, 5);
1488 gdk_colormap_free_colors (style->colormap, style->light, 5);
1489 gdk_colormap_free_colors (style->colormap, style->dark, 5);
1490 gdk_colormap_free_colors (style->colormap, style->mid, 5);
1491 gdk_colormap_free_colors (style->colormap, style->text, 5);
1492 gdk_colormap_free_colors (style->colormap, style->base, 5);
1493 gdk_colormap_free_colors (style->colormap, style->text_aa, 5);
1497 gtk_style_real_set_background (GtkStyle *style,
1499 GtkStateType state_type)
1502 gint parent_relative;
1504 if (style->bg_pixmap[state_type])
1506 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1509 parent_relative = TRUE;
1513 pixmap = style->bg_pixmap[state_type];
1514 parent_relative = FALSE;
1517 gdk_window_set_back_pixmap (window, pixmap, parent_relative);
1520 gdk_window_set_background (window, &style->bg[state_type]);
1524 gtk_style_render_icon (GtkStyle *style,
1525 const GtkIconSource *source,
1526 GtkTextDirection direction,
1530 const gchar *detail)
1534 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1535 g_return_val_if_fail (GTK_STYLE_GET_CLASS (style)->render_icon != NULL, NULL);
1537 pixbuf = GTK_STYLE_GET_CLASS (style)->render_icon (style, source, direction, state,
1538 size, widget, detail);
1540 g_return_val_if_fail (pixbuf != NULL, NULL);
1545 /* Default functions */
1547 gtk_style_apply_default_background (GtkStyle *style,
1550 GtkStateType state_type,
1557 GdkRectangle new_rect, old_rect;
1563 old_rect.width = width;
1564 old_rect.height = height;
1566 if (!gdk_rectangle_intersect (area, &old_rect, &new_rect))
1573 new_rect.width = width;
1574 new_rect.height = height;
1577 if (!style->bg_pixmap[state_type] ||
1578 GDK_IS_PIXMAP (window) ||
1579 (!set_bg && style->bg_pixmap[state_type] != (GdkPixmap*) GDK_PARENT_RELATIVE))
1581 GdkGC *gc = style->bg_gc[state_type];
1583 if (style->bg_pixmap[state_type])
1585 gdk_gc_set_fill (gc, GDK_TILED);
1586 gdk_gc_set_tile (gc, style->bg_pixmap[state_type]);
1589 gdk_draw_rectangle (window, gc, TRUE,
1590 new_rect.x, new_rect.y, new_rect.width, new_rect.height);
1591 if (style->bg_pixmap[state_type])
1592 gdk_gc_set_fill (gc, GDK_SOLID);
1598 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1599 gdk_window_set_back_pixmap (window, NULL, TRUE);
1601 gdk_window_set_back_pixmap (window, style->bg_pixmap[state_type], FALSE);
1604 gdk_window_clear_area (window,
1605 new_rect.x, new_rect.y,
1606 new_rect.width, new_rect.height);
1611 scale_or_ref (GdkPixbuf *src,
1615 if (width == gdk_pixbuf_get_width (src) &&
1616 height == gdk_pixbuf_get_height (src))
1618 gdk_pixbuf_ref (src);
1623 return gdk_pixbuf_scale_simple (src,
1625 GDK_INTERP_BILINEAR);
1630 gtk_default_render_icon (GtkStyle *style,
1631 const GtkIconSource *source,
1632 GtkTextDirection direction,
1636 const gchar *detail)
1642 GdkPixbuf *base_pixbuf;
1644 /* Oddly, style can be NULL in this function, because
1645 * GtkIconSet can be used without a style and if so
1646 * it uses this function.
1649 base_pixbuf = gtk_icon_source_get_pixbuf (source);
1651 g_return_val_if_fail (base_pixbuf != NULL, NULL);
1653 if (!gtk_icon_size_lookup (size, &width, &height))
1655 g_warning (G_STRLOC ": invalid icon size `%d'", size);
1659 /* If the size was wildcarded, then scale; otherwise, leave it
1662 if (gtk_icon_source_get_size_wildcarded (source))
1663 scaled = scale_or_ref (base_pixbuf, width, height);
1665 scaled = GDK_PIXBUF (g_object_ref (G_OBJECT (base_pixbuf)));
1667 /* If the state was wildcarded, then generate a state. */
1668 if (gtk_icon_source_get_state_wildcarded (source))
1670 if (state == GTK_STATE_INSENSITIVE)
1672 stated = gdk_pixbuf_copy (scaled);
1674 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
1677 gdk_pixbuf_unref (scaled);
1679 else if (state == GTK_STATE_PRELIGHT)
1681 stated = gdk_pixbuf_copy (scaled);
1683 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
1686 gdk_pixbuf_unref (scaled);
1700 sanitize_size (GdkWindow *window,
1704 gboolean set_bg = FALSE;
1706 if ((*width == -1) && (*height == -1))
1708 set_bg = GDK_IS_WINDOW (window);
1709 gdk_window_get_size (window, width, height);
1711 else if (*width == -1)
1712 gdk_window_get_size (window, width, NULL);
1713 else if (*height == -1)
1714 gdk_window_get_size (window, NULL, height);
1720 draw_part (GdkDrawable *drawable,
1728 gdk_gc_set_clip_rectangle (gc, area);
1730 if (!indicator_parts[part].bmap)
1731 indicator_parts[part].bmap = gdk_bitmap_create_from_data (drawable,
1732 indicator_parts[part].bits,
1733 INDICATOR_PART_SIZE, INDICATOR_PART_SIZE);
1735 gdk_gc_set_ts_origin (gc, x, y);
1736 gdk_gc_set_stipple (gc, indicator_parts[part].bmap);
1737 gdk_gc_set_fill (gc, GDK_STIPPLED);
1739 gdk_draw_rectangle (drawable, gc, TRUE, x, y, INDICATOR_PART_SIZE, INDICATOR_PART_SIZE);
1741 gdk_gc_set_fill (gc, GDK_SOLID);
1744 gdk_gc_set_clip_rectangle (gc, NULL);
1748 gtk_default_draw_hline (GtkStyle *style,
1750 GtkStateType state_type,
1753 const gchar *detail,
1758 gint thickness_light;
1759 gint thickness_dark;
1762 g_return_if_fail (GTK_IS_STYLE (style));
1763 g_return_if_fail (window != NULL);
1765 thickness_light = style->ythickness / 2;
1766 thickness_dark = style->ythickness - thickness_light;
1770 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
1771 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
1774 if (detail && !strcmp (detail, "label"))
1776 if (state_type == GTK_STATE_INSENSITIVE)
1777 gdk_draw_line (window, style->white_gc, x1 + 1, y + 1, x2 + 1, y + 1);
1778 gdk_draw_line (window, style->fg_gc[state_type], x1, y, x2, y);
1782 for (i = 0; i < thickness_dark; i++)
1784 gdk_draw_line (window, style->light_gc[state_type], x2 - i - 1, y + i, x2, y + i);
1785 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x2 - i - 1, y + i);
1788 y += thickness_dark;
1789 for (i = 0; i < thickness_light; i++)
1791 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x1 + thickness_light - i - 1, y + i);
1792 gdk_draw_line (window, style->light_gc[state_type], x1 + thickness_light - i - 1, y + i, x2, y + i);
1798 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
1799 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
1805 gtk_default_draw_vline (GtkStyle *style,
1807 GtkStateType state_type,
1810 const gchar *detail,
1815 gint thickness_light;
1816 gint thickness_dark;
1819 g_return_if_fail (GTK_IS_STYLE (style));
1820 g_return_if_fail (window != NULL);
1822 thickness_light = style->xthickness / 2;
1823 thickness_dark = style->xthickness - thickness_light;
1827 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
1828 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
1830 for (i = 0; i < thickness_dark; i++)
1832 gdk_draw_line (window, style->light_gc[state_type], x + i, y2 - i - 1, x + i, y2);
1833 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y2 - i - 1);
1836 x += thickness_dark;
1837 for (i = 0; i < thickness_light; i++)
1839 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y1 + thickness_light - i);
1840 gdk_draw_line (window, style->light_gc[state_type], x + i, y1 + thickness_light - i, x + i, y2);
1844 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
1845 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
1851 draw_thin_shadow (GtkStyle *style,
1862 sanitize_size (window, &width, &height);
1864 gc1 = style->light_gc[state];
1865 gc2 = style->dark_gc[state];
1869 gdk_gc_set_clip_rectangle (gc1, area);
1870 gdk_gc_set_clip_rectangle (gc2, area);
1873 gdk_draw_line (window, gc1,
1874 x, y + height - 1, x + width - 1, y + height - 1);
1875 gdk_draw_line (window, gc1,
1876 x + width - 1, y, x + width - 1, y + height - 1);
1878 gdk_draw_line (window, gc2,
1879 x, y, x + width - 1, y);
1880 gdk_draw_line (window, gc2,
1881 x, y, x, y + height - 1);
1885 gdk_gc_set_clip_rectangle (gc1, NULL);
1886 gdk_gc_set_clip_rectangle (gc2, NULL);
1891 draw_spin_entry_shadow (GtkStyle *style,
1900 gint window_width, window_height;
1901 gboolean focus_inset;
1903 gdk_window_get_size (window, &window_width, &window_height);
1906 width = window_width;
1908 height = window_height;
1910 focus_inset = (width < window_width && height < window_height);
1914 gdk_gc_set_clip_rectangle (style->light_gc[state], area);
1915 gdk_gc_set_clip_rectangle (style->dark_gc[state], area);
1916 gdk_gc_set_clip_rectangle (style->black_gc, area);
1917 gdk_gc_set_clip_rectangle (style->bg_gc[state], area);
1918 gdk_gc_set_clip_rectangle (style->base_gc[state], area);
1921 gdk_draw_line (window, style->light_gc[state],
1922 x, y + height - 1, x + width - 1, y + height - 1);
1924 gdk_draw_line (window,
1925 style->base_gc[state],
1926 x + width - 1, y + 1, x + width - 1, y + height - 3);
1930 gdk_draw_line (window, style->bg_gc[state],
1931 x + 1, y + height - 2, x + width - 1, y + height - 2);
1932 gdk_draw_line (window,
1933 style->base_gc[state],
1934 x + width - 2, y + 1, x + width - 2, y + height - 3);
1936 gdk_draw_line (window, style->black_gc,
1937 x + 1, y + 1, x + width - 1, y + 1);
1938 gdk_draw_line (window, style->black_gc,
1939 x + 1, y + 1, x + 1, y + height - 2);
1942 gdk_draw_line (window, style->dark_gc[state],
1943 x, y, x + width - 1, y);
1944 gdk_draw_line (window, style->dark_gc[state],
1945 x, y, x, y + height - 1);
1949 gdk_gc_set_clip_rectangle (style->light_gc[state], NULL);
1950 gdk_gc_set_clip_rectangle (style->dark_gc[state], NULL);
1951 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
1952 gdk_gc_set_clip_rectangle (style->bg_gc[state], NULL);
1953 gdk_gc_set_clip_rectangle (style->base_gc[state], NULL);
1958 draw_spinbutton_shadow (GtkStyle *style,
1967 gint y_middle = y + height / 2;
1969 sanitize_size (window, &width, &height);
1973 gdk_gc_set_clip_rectangle (style->black_gc, area);
1974 gdk_gc_set_clip_rectangle (style->bg_gc[state], area);
1975 gdk_gc_set_clip_rectangle (style->dark_gc[state], area);
1976 gdk_gc_set_clip_rectangle (style->light_gc[state], area);
1979 gdk_draw_line (window, style->black_gc,
1980 x, y + 2, x, y + height - 3);
1981 gdk_draw_line (window, style->black_gc,
1982 x, y + 1, x + width - 2, y + 1);
1983 gdk_draw_line (window, style->black_gc,
1984 x + width - 2, y + 2, x + width - 2, y + height - 3);
1986 gdk_draw_line (window, style->bg_gc[state],
1987 x, y + height - 2, x + width - 2, y + height - 2);
1989 gdk_draw_line (window, style->dark_gc[state],
1990 x, y, x + width - 1, y);
1991 gdk_draw_line (window, style->dark_gc[state],
1992 x + 1, y_middle - 1, x + width - 3, y_middle - 1);
1993 gdk_draw_line (window, style->dark_gc[state],
1994 x + 1, y + height - 3, x + width - 3, y + height - 3);
1996 gdk_draw_line (window, style->light_gc[state],
1997 x + 1, y + 2, x + width - 3, y + 2);
1998 gdk_draw_line (window, style->light_gc[state],
1999 x + 1, y_middle, x + width - 3, y_middle);
2000 gdk_draw_line (window, style->light_gc[state],
2001 x + width - 1, y + 1, x + width - 1, y + height - 1);
2002 gdk_draw_line (window, style->light_gc[state],
2003 x, y + height - 1, x + width - 2, y + height - 1);
2007 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2008 gdk_gc_set_clip_rectangle (style->bg_gc[state], NULL);
2009 gdk_gc_set_clip_rectangle (style->dark_gc[state], NULL);
2010 gdk_gc_set_clip_rectangle (style->light_gc[state], NULL);
2015 gtk_default_draw_shadow (GtkStyle *style,
2017 GtkStateType state_type,
2018 GtkShadowType shadow_type,
2021 const gchar *detail,
2029 gint thickness_light;
2030 gint thickness_dark;
2033 g_return_if_fail (GTK_IS_STYLE (style));
2034 g_return_if_fail (window != NULL);
2036 if (shadow_type == GTK_SHADOW_IN)
2038 if (detail && (strcmp (detail, "buttondefault") == 0))
2040 sanitize_size (window, &width, &height);
2042 gdk_draw_rectangle (window, style->black_gc, FALSE,
2043 x, y, width - 1, height - 1);
2047 if (detail && strcmp (detail, "trough") == 0)
2049 draw_thin_shadow (style, window, state_type, area,
2050 x, y, width, height);
2053 else if (widget && GTK_IS_SPIN_BUTTON (widget) &&
2054 detail && strcmp (detail, "entry") == 0)
2056 draw_spin_entry_shadow (style, window, state_type, area,
2057 x, y, width, height);
2060 else if (widget && GTK_IS_SPIN_BUTTON (widget) &&
2061 detail && strcmp (detail, "spinbutton") == 0)
2063 draw_spinbutton_shadow (style, window, state_type,
2064 area, x, y, width, height);
2069 sanitize_size (window, &width, &height);
2071 switch (shadow_type)
2073 case GTK_SHADOW_NONE:
2076 case GTK_SHADOW_ETCHED_IN:
2077 gc1 = style->light_gc[state_type];
2078 gc2 = style->dark_gc[state_type];
2080 case GTK_SHADOW_OUT:
2081 case GTK_SHADOW_ETCHED_OUT:
2082 gc1 = style->dark_gc[state_type];
2083 gc2 = style->light_gc[state_type];
2089 gdk_gc_set_clip_rectangle (gc1, area);
2090 gdk_gc_set_clip_rectangle (gc2, area);
2091 if (shadow_type == GTK_SHADOW_IN ||
2092 shadow_type == GTK_SHADOW_OUT)
2094 gdk_gc_set_clip_rectangle (style->black_gc, area);
2095 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2099 switch (shadow_type)
2101 case GTK_SHADOW_NONE:
2105 /* Light around right and bottom edge */
2107 if (style->ythickness > 0)
2108 gdk_draw_line (window, gc1,
2109 x, y + height - 1, x + width - 1, y + height - 1);
2110 if (style->xthickness > 0)
2111 gdk_draw_line (window, gc1,
2112 x + width - 1, y, x + width - 1, y + height - 1);
2114 if (style->ythickness > 1)
2115 gdk_draw_line (window, style->bg_gc[state_type],
2116 x + 1, y + height - 2, x + width - 2, y + height - 2);
2117 if (style->xthickness > 1)
2118 gdk_draw_line (window, style->bg_gc[state_type],
2119 x + width - 2, y + 1, x + width - 2, y + height - 2);
2121 /* Dark around left and top */
2123 if (style->ythickness > 1)
2124 gdk_draw_line (window, style->black_gc,
2125 x + 1, y + 1, x + width - 2, y + 1);
2126 if (style->xthickness > 1)
2127 gdk_draw_line (window, style->black_gc,
2128 x + 1, y + 1, x + 1, y + height - 2);
2130 if (style->ythickness > 0)
2131 gdk_draw_line (window, gc2,
2132 x, y, x + width - 1, y);
2133 if (style->xthickness > 0)
2134 gdk_draw_line (window, gc2,
2135 x, y, x, y + height - 1);
2138 case GTK_SHADOW_OUT:
2139 /* Dark around right and bottom edge */
2141 if (style->ythickness > 0)
2143 if (style->ythickness > 1)
2145 gdk_draw_line (window, gc1,
2146 x + 1, y + height - 2, x + width - 2, y + height - 2);
2147 gdk_draw_line (window, style->black_gc,
2148 x, y + height - 1, x + width - 1, y + height - 1);
2152 gdk_draw_line (window, gc1,
2153 x + 1, y + height - 1, x + width - 1, y + height - 1);
2157 if (style->xthickness > 0)
2159 if (style->xthickness > 1)
2161 gdk_draw_line (window, gc1,
2162 x + width - 2, y + 1, x + width - 2, y + height - 2);
2164 gdk_draw_line (window, style->black_gc,
2165 x + width - 1, y, x + width - 1, y + height - 1);
2169 gdk_draw_line (window, gc1,
2170 x + width - 1, y + 1, x + width - 1, y + height - 1);
2174 /* Light around top and left */
2176 if (style->ythickness > 0)
2177 gdk_draw_line (window, gc2,
2178 x, y, x + width - 1, y);
2179 if (style->xthickness > 0)
2180 gdk_draw_line (window, gc2,
2181 x, y, x, y + height - 1);
2183 if (style->ythickness > 1)
2184 gdk_draw_line (window, style->bg_gc[state_type],
2185 x + 1, y + 1, x + width - 2, y + 1);
2186 if (style->xthickness > 1)
2187 gdk_draw_line (window, style->bg_gc[state_type],
2188 x + 1, y + 1, x + 1, y + height - 2);
2191 case GTK_SHADOW_ETCHED_IN:
2192 case GTK_SHADOW_ETCHED_OUT:
2193 if (style->xthickness > 0)
2195 if (style->xthickness > 1)
2197 thickness_light = 1;
2200 for (i = 0; i < thickness_dark; i++)
2202 gdk_draw_line (window, gc1,
2206 y + height - i - 1);
2207 gdk_draw_line (window, gc2,
2211 y + height - i - 2);
2214 for (i = 0; i < thickness_light; i++)
2216 gdk_draw_line (window, gc1,
2217 x + thickness_dark + i,
2218 y + thickness_dark + i,
2219 x + thickness_dark + i,
2220 y + height - thickness_dark - i - 1);
2221 gdk_draw_line (window, gc2,
2222 x + width - thickness_light - i - 1,
2223 y + thickness_dark + i,
2224 x + width - thickness_light - i - 1,
2225 y + height - thickness_light - 1);
2230 gdk_draw_line (window,
2231 style->dark_gc[state_type],
2232 x, y, x, y + height);
2233 gdk_draw_line (window,
2234 style->dark_gc[state_type],
2235 x + width, y, x + width, y + height);
2239 if (style->ythickness > 0)
2241 if (style->ythickness > 1)
2243 thickness_light = 1;
2246 for (i = 0; i < thickness_dark; i++)
2248 gdk_draw_line (window, gc1,
2252 y + height - i - 1);
2254 gdk_draw_line (window, gc2,
2261 for (i = 0; i < thickness_light; i++)
2263 gdk_draw_line (window, gc1,
2264 x + thickness_dark + i,
2265 y + thickness_dark + i,
2266 x + width - thickness_dark - i - 1,
2267 y + thickness_dark + i);
2269 gdk_draw_line (window, gc2,
2270 x + thickness_dark + i,
2271 y + height - thickness_light - i - 1,
2272 x + width - thickness_light - 1,
2273 y + height - thickness_light - i - 1);
2278 gdk_draw_line (window,
2279 style->dark_gc[state_type],
2280 x, y, x + width, y);
2281 gdk_draw_line (window,
2282 style->dark_gc[state_type],
2283 x, y + height, x + width, y + height);
2291 gdk_gc_set_clip_rectangle (gc1, NULL);
2292 gdk_gc_set_clip_rectangle (gc2, NULL);
2293 if (shadow_type == GTK_SHADOW_IN ||
2294 shadow_type == GTK_SHADOW_OUT)
2296 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2297 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2303 gtk_default_draw_polygon (GtkStyle *style,
2305 GtkStateType state_type,
2306 GtkShadowType shadow_type,
2309 const gchar *detail,
2314 static const gdouble pi_over_4 = G_PI_4;
2315 static const gdouble pi_3_over_4 = G_PI_4 * 3;
2325 g_return_if_fail (GTK_IS_STYLE (style));
2326 g_return_if_fail (window != NULL);
2327 g_return_if_fail (points != NULL);
2329 switch (shadow_type)
2332 gc1 = style->bg_gc[state_type];
2333 gc2 = style->dark_gc[state_type];
2334 gc3 = style->light_gc[state_type];
2335 gc4 = style->black_gc;
2337 case GTK_SHADOW_ETCHED_IN:
2338 gc1 = style->light_gc[state_type];
2339 gc2 = style->dark_gc[state_type];
2340 gc3 = style->dark_gc[state_type];
2341 gc4 = style->light_gc[state_type];
2343 case GTK_SHADOW_OUT:
2344 gc1 = style->dark_gc[state_type];
2345 gc2 = style->light_gc[state_type];
2346 gc3 = style->black_gc;
2347 gc4 = style->bg_gc[state_type];
2349 case GTK_SHADOW_ETCHED_OUT:
2350 gc1 = style->dark_gc[state_type];
2351 gc2 = style->light_gc[state_type];
2352 gc3 = style->light_gc[state_type];
2353 gc4 = style->dark_gc[state_type];
2361 gdk_gc_set_clip_rectangle (gc1, area);
2362 gdk_gc_set_clip_rectangle (gc2, area);
2363 gdk_gc_set_clip_rectangle (gc3, area);
2364 gdk_gc_set_clip_rectangle (gc4, area);
2368 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, npoints);
2372 for (i = 0; i < npoints; i++)
2374 if ((points[i].x == points[i+1].x) &&
2375 (points[i].y == points[i+1].y))
2381 angle = atan2 (points[i+1].y - points[i].y,
2382 points[i+1].x - points[i].x);
2385 if ((angle > -pi_3_over_4) && (angle < pi_over_4))
2387 if (angle > -pi_over_4)
2398 gdk_draw_line (window, gc1,
2399 points[i].x-xadjust, points[i].y-yadjust,
2400 points[i+1].x-xadjust, points[i+1].y-yadjust);
2401 gdk_draw_line (window, gc3,
2402 points[i].x, points[i].y,
2403 points[i+1].x, points[i+1].y);
2407 if ((angle < -pi_3_over_4) || (angle > pi_3_over_4))
2418 gdk_draw_line (window, gc4,
2419 points[i].x+xadjust, points[i].y+yadjust,
2420 points[i+1].x+xadjust, points[i+1].y+yadjust);
2421 gdk_draw_line (window, gc2,
2422 points[i].x, points[i].y,
2423 points[i+1].x, points[i+1].y);
2429 gdk_gc_set_clip_rectangle (gc1, NULL);
2430 gdk_gc_set_clip_rectangle (gc2, NULL);
2431 gdk_gc_set_clip_rectangle (gc3, NULL);
2432 gdk_gc_set_clip_rectangle (gc4, NULL);
2437 draw_varrow (GdkWindow *window,
2439 GtkShadowType shadow_type,
2441 GtkArrowType arrow_type,
2448 gint y_start, y_increment;
2452 gdk_gc_set_clip_rectangle (gc, area);
2454 width = width + width % 2 - 1; /* Force odd */
2456 steps = 1 + width / 2;
2458 extra = height - steps;
2460 if (arrow_type == GTK_ARROW_DOWN)
2467 y_start = y + height - 1;
2471 for (i = 0; i < extra; i++)
2473 gdk_draw_line (window, gc,
2474 x, y_start + i * y_increment,
2475 x + width - 1, y_start + i * y_increment);
2477 for (; i < height; i++)
2479 gdk_draw_line (window, gc,
2480 x + (i - extra), y_start + i * y_increment,
2481 x + width - (i - extra) - 1, y_start + i * y_increment);
2486 gdk_gc_set_clip_rectangle (gc, NULL);
2490 draw_harrow (GdkWindow *window,
2492 GtkShadowType shadow_type,
2494 GtkArrowType arrow_type,
2501 gint x_start, x_increment;
2505 gdk_gc_set_clip_rectangle (gc, area);
2507 height = height + height % 2 - 1; /* Force odd */
2509 steps = 1 + height / 2;
2511 extra = width - steps;
2513 if (arrow_type == GTK_ARROW_RIGHT)
2520 x_start = x + width - 1;
2524 for (i = 0; i < extra; i++)
2526 gdk_draw_line (window, gc,
2527 x_start + i * x_increment, y,
2528 x_start + i * x_increment, y + height - 1);
2530 for (; i < width; i++)
2532 gdk_draw_line (window, gc,
2533 x_start + i * x_increment, y + (i - extra),
2534 x_start + i * x_increment, y + height - (i - extra) - 1);
2539 gdk_gc_set_clip_rectangle (gc, NULL);
2543 gtk_default_draw_arrow (GtkStyle *style,
2546 GtkShadowType shadow,
2549 const gchar *detail,
2550 GtkArrowType arrow_type,
2557 sanitize_size (window, &width, &height);
2559 if (detail && strcmp (detail, "spinbutton") == 0)
2561 x += (width - 7) / 2;
2563 if (arrow_type == GTK_ARROW_UP)
2564 y += (height - 4) / 2;
2566 y += (1 + height - 4) / 2;
2568 draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
2571 else if (detail && strcmp (detail, "vscrollbar") == 0)
2573 gtk_paint_box (style, window, state, shadow, area,
2574 widget, detail, x, y, width, height);
2576 x += (width - 7) / 2;
2577 y += (height - 5) / 2;
2579 draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
2583 else if (detail && strcmp (detail, "hscrollbar") == 0)
2585 gtk_paint_box (style, window, state, shadow, area,
2586 widget, detail, x, y, width, height);
2588 y += (height - 7) / 2;
2589 x += (width - 5) / 2;
2591 draw_harrow (window, style->fg_gc[state], shadow, area, arrow_type,
2596 if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
2598 x += (width - 7) / 2;
2599 y += (height - 5) / 2;
2601 draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
2606 x += (width - 5) / 2;
2607 y += (height - 7) / 2;
2609 draw_harrow (window, style->fg_gc[state], shadow, area, arrow_type,
2616 gtk_default_draw_diamond (GtkStyle *style,
2618 GtkStateType state_type,
2619 GtkShadowType shadow_type,
2622 const gchar *detail,
2630 GdkGC *outer_nw = NULL;
2631 GdkGC *outer_ne = NULL;
2632 GdkGC *outer_sw = NULL;
2633 GdkGC *outer_se = NULL;
2634 GdkGC *middle_nw = NULL;
2635 GdkGC *middle_ne = NULL;
2636 GdkGC *middle_sw = NULL;
2637 GdkGC *middle_se = NULL;
2638 GdkGC *inner_nw = NULL;
2639 GdkGC *inner_ne = NULL;
2640 GdkGC *inner_sw = NULL;
2641 GdkGC *inner_se = NULL;
2643 g_return_if_fail (GTK_IS_STYLE (style));
2644 g_return_if_fail (window != NULL);
2646 sanitize_size (window, &width, &height);
2648 half_width = width / 2;
2649 half_height = height / 2;
2653 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
2654 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2655 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
2656 gdk_gc_set_clip_rectangle (style->black_gc, area);
2659 switch (shadow_type)
2662 inner_sw = inner_se = style->bg_gc[state_type];
2663 middle_sw = middle_se = style->light_gc[state_type];
2664 outer_sw = outer_se = style->light_gc[state_type];
2665 inner_nw = inner_ne = style->black_gc;
2666 middle_nw = middle_ne = style->dark_gc[state_type];
2667 outer_nw = outer_ne = style->dark_gc[state_type];
2670 case GTK_SHADOW_OUT:
2671 inner_sw = inner_se = style->dark_gc[state_type];
2672 middle_sw = middle_se = style->dark_gc[state_type];
2673 outer_sw = outer_se = style->black_gc;
2674 inner_nw = inner_ne = style->bg_gc[state_type];
2675 middle_nw = middle_ne = style->light_gc[state_type];
2676 outer_nw = outer_ne = style->light_gc[state_type];
2679 case GTK_SHADOW_ETCHED_IN:
2680 inner_sw = inner_se = style->bg_gc[state_type];
2681 middle_sw = middle_se = style->dark_gc[state_type];
2682 outer_sw = outer_se = style->light_gc[state_type];
2683 inner_nw = inner_ne = style->bg_gc[state_type];
2684 middle_nw = middle_ne = style->light_gc[state_type];
2685 outer_nw = outer_ne = style->dark_gc[state_type];
2688 case GTK_SHADOW_ETCHED_OUT:
2689 inner_sw = inner_se = style->bg_gc[state_type];
2690 middle_sw = middle_se = style->light_gc[state_type];
2691 outer_sw = outer_se = style->dark_gc[state_type];
2692 inner_nw = inner_ne = style->bg_gc[state_type];
2693 middle_nw = middle_ne = style->dark_gc[state_type];
2694 outer_nw = outer_ne = style->light_gc[state_type];
2704 gdk_draw_line (window, inner_sw,
2705 x + 2, y + half_height,
2706 x + half_width, y + height - 2);
2707 gdk_draw_line (window, inner_se,
2708 x + half_width, y + height - 2,
2709 x + width - 2, y + half_height);
2710 gdk_draw_line (window, middle_sw,
2711 x + 1, y + half_height,
2712 x + half_width, y + height - 1);
2713 gdk_draw_line (window, middle_se,
2714 x + half_width, y + height - 1,
2715 x + width - 1, y + half_height);
2716 gdk_draw_line (window, outer_sw,
2718 x + half_width, y + height);
2719 gdk_draw_line (window, outer_se,
2720 x + half_width, y + height,
2721 x + width, y + half_height);
2723 gdk_draw_line (window, inner_nw,
2724 x + 2, y + half_height,
2725 x + half_width, y + 2);
2726 gdk_draw_line (window, inner_ne,
2727 x + half_width, y + 2,
2728 x + width - 2, y + half_height);
2729 gdk_draw_line (window, middle_nw,
2730 x + 1, y + half_height,
2731 x + half_width, y + 1);
2732 gdk_draw_line (window, middle_ne,
2733 x + half_width, y + 1,
2734 x + width - 1, y + half_height);
2735 gdk_draw_line (window, outer_nw,
2738 gdk_draw_line (window, outer_ne,
2740 x + width, y + half_height);
2745 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
2746 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2747 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
2748 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2753 gtk_default_draw_string (GtkStyle *style,
2755 GtkStateType state_type,
2758 const gchar *detail,
2761 const gchar *string)
2763 g_return_if_fail (GTK_IS_STYLE (style));
2764 g_return_if_fail (window != NULL);
2768 gdk_gc_set_clip_rectangle (style->white_gc, area);
2769 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], area);
2772 if (state_type == GTK_STATE_INSENSITIVE)
2773 gdk_draw_string (window, gtk_style_get_font (style), style->white_gc, x + 1, y + 1, string);
2775 gdk_draw_string (window, gtk_style_get_font (style), style->fg_gc[state_type], x, y, string);
2779 gdk_gc_set_clip_rectangle (style->white_gc, NULL);
2780 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], NULL);
2785 option_menu_get_props (GtkWidget *widget,
2786 GtkRequisition *indicator_size,
2787 GtkBorder *indicator_spacing)
2789 GtkRequisition *tmp_size = NULL;
2790 GtkBorder *tmp_spacing = NULL;
2793 gtk_widget_style_get (widget,
2794 "indicator_size", &tmp_size,
2795 "indicator_spacing", &tmp_spacing,
2800 *indicator_size = *tmp_size;
2804 *indicator_size = default_option_indicator_size;
2808 *indicator_spacing = *tmp_spacing;
2809 g_free (tmp_spacing);
2812 *indicator_spacing = default_option_indicator_spacing;
2816 gtk_default_draw_box (GtkStyle *style,
2818 GtkStateType state_type,
2819 GtkShadowType shadow_type,
2822 const gchar *detail,
2828 g_return_if_fail (GTK_IS_STYLE (style));
2829 g_return_if_fail (window != NULL);
2831 sanitize_size (window, &width, &height);
2833 if (!style->bg_pixmap[state_type] ||
2834 GDK_IS_PIXMAP (window))
2837 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2839 gdk_draw_rectangle (window, style->bg_gc[state_type], TRUE,
2840 x, y, width, height);
2842 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2845 gtk_style_apply_default_background (style, window,
2846 widget && !GTK_WIDGET_NO_WINDOW (widget),
2847 state_type, area, x, y, width, height);
2849 gtk_paint_shadow (style, window, state_type, shadow_type, area, widget, detail,
2850 x, y, width, height);
2852 if (detail && strcmp (detail, "optionmenu") == 0)
2854 GtkRequisition indicator_size;
2855 GtkBorder indicator_spacing;
2857 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
2859 sanitize_size (window, &width, &height);
2861 gtk_paint_vline (style, window, state_type, area, widget,
2863 y + style->ythickness + 1,
2864 y + height - style->ythickness - 3,
2865 x + width - (indicator_size.width + indicator_spacing.left + indicator_spacing.right) - style->xthickness);
2870 get_darkened_gc (GdkWindow *window,
2874 GdkColor src = *color;
2878 gc = gdk_gc_new (window);
2880 while (darken_count)
2882 gtk_style_shade (&src, &shaded, 0.93);
2887 gdk_gc_set_rgb_fg_color (gc, &shaded);
2893 gtk_default_draw_flat_box (GtkStyle *style,
2895 GtkStateType state_type,
2896 GtkShadowType shadow_type,
2899 const gchar *detail,
2906 GdkGC *freeme = NULL;
2908 g_return_if_fail (GTK_IS_STYLE (style));
2909 g_return_if_fail (window != NULL);
2911 sanitize_size (window, &width, &height);
2915 if (state_type == GTK_STATE_SELECTED)
2917 if (!strcmp ("text", detail))
2918 gc1 = style->bg_gc[GTK_STATE_SELECTED];
2919 else if (!strncmp ("cell_even", detail, strlen ("cell_even")) ||
2920 !strncmp ("cell_odd", detail, strlen ("cell_odd")))
2922 /* This has to be really broken; alex made me do it. -jrb */
2923 if (GTK_WIDGET_HAS_FOCUS (widget))
2924 gc1 = style->base_gc[state_type];
2926 gc1 = style->base_gc[GTK_STATE_ACTIVE];
2930 gc1 = style->bg_gc[state_type];
2935 if (!strcmp ("viewportbin", detail))
2936 gc1 = style->bg_gc[GTK_STATE_NORMAL];
2937 else if (!strcmp ("entry_bg", detail))
2938 gc1 = style->base_gc[state_type];
2940 /* For trees: even rows are base color, odd rows are a shade of
2941 * the base color, the sort column is a shade of the original color
2945 /* FIXME when we have style properties, clean this up.
2948 else if (!strcmp ("cell_even", detail) ||
2949 !strcmp ("cell_odd", detail) ||
2950 !strcmp ("cell_even_ruled", detail))
2952 gc1 = style->base_gc[state_type];
2954 else if (!strcmp ("cell_even_sorted", detail) ||
2955 !strcmp ("cell_odd_sorted", detail) ||
2956 !strcmp ("cell_odd_ruled", detail) ||
2957 !strcmp ("cell_even_ruled_sorted", detail))
2959 freeme = get_darkened_gc (window, &style->base[state_type], 1);
2962 else if (!strcmp ("cell_odd_ruled_sorted", detail))
2964 freeme = get_darkened_gc (window, &style->base[state_type], 2);
2968 gc1 = style->bg_gc[state_type];
2972 gc1 = style->bg_gc[state_type];
2974 if (!style->bg_pixmap[state_type] || gc1 != style->bg_gc[state_type] ||
2975 GDK_IS_PIXMAP (window))
2978 gdk_gc_set_clip_rectangle (gc1, area);
2980 gdk_draw_rectangle (window, gc1, TRUE,
2981 x, y, width, height);
2983 if (detail && !strcmp ("tooltip", detail))
2984 gdk_draw_rectangle (window, style->black_gc, FALSE,
2985 x, y, width - 1, height - 1);
2988 gdk_gc_set_clip_rectangle (gc1, NULL);
2991 gtk_style_apply_default_background (style, window,
2992 widget && !GTK_WIDGET_NO_WINDOW (widget),
2993 state_type, area, x, y, width, height);
2997 g_object_unref (G_OBJECT (freeme));
3001 gtk_default_draw_check (GtkStyle *style,
3003 GtkStateType state_type,
3004 GtkShadowType shadow_type,
3007 const gchar *detail,
3013 if (detail && strcmp (detail, "cellcheck") == 0)
3015 gdk_draw_rectangle (window,
3016 widget->style->fg_gc[state_type],
3021 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3022 y -= (((1 + INDICATOR_PART_SIZE - height) / 2) - 1);
3023 if (shadow_type == GTK_SHADOW_IN)
3025 draw_part (window, style->text_gc[state_type], area, x, y, CHECK_TEXT);
3026 draw_part (window, style->text_aa_gc[state_type], area, x, y, CHECK_AA);
3031 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3032 y -= (1 + INDICATOR_PART_SIZE - height) / 2;
3034 if (strcmp (detail, "check") == 0) /* Menu item */
3036 if (shadow_type == GTK_SHADOW_IN)
3038 draw_part (window, style->black_gc, area, x, y, CHECK_TEXT);
3039 draw_part (window, style->dark_gc[state_type], area, x, y, CHECK_AA);
3044 draw_part (window, style->black_gc, area, x, y, CHECK_BLACK);
3045 draw_part (window, style->dark_gc[state_type], area, x, y, CHECK_DARK);
3046 draw_part (window, style->mid_gc[state_type], area, x, y, CHECK_MID);
3047 draw_part (window, style->light_gc[state_type], area, x, y, CHECK_LIGHT);
3048 draw_part (window, style->base_gc[state_type], area, x, y, CHECK_BASE);
3050 if (shadow_type == GTK_SHADOW_IN)
3052 draw_part (window, style->text_gc[state_type], area, x, y, CHECK_TEXT);
3053 draw_part (window, style->text_aa_gc[state_type], area, x, y, CHECK_AA);
3061 gtk_default_draw_option (GtkStyle *style,
3063 GtkStateType state_type,
3064 GtkShadowType shadow_type,
3067 const gchar *detail,
3073 if (detail && strcmp (detail, "cellradio") == 0)
3075 gdk_draw_arc (window,
3076 widget->style->fg_gc[state_type],
3083 if (shadow_type == GTK_SHADOW_IN)
3085 gdk_draw_arc (window,
3086 widget->style->fg_gc[state_type],
3097 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3098 y -= (1 + INDICATOR_PART_SIZE - height) / 2;
3100 if (strcmp (detail, "option") == 0) /* Menu item */
3102 if (shadow_type == GTK_SHADOW_IN)
3103 draw_part (window, style->fg_gc[state_type], area, x, y, RADIO_TEXT);
3107 draw_part (window, style->black_gc, area, x, y, RADIO_BLACK);
3108 draw_part (window, style->dark_gc[state_type], area, x, y, RADIO_DARK);
3109 draw_part (window, style->mid_gc[state_type], area, x, y, RADIO_MID);
3110 draw_part (window, style->light_gc[state_type], area, x, y, RADIO_LIGHT);
3111 draw_part (window, style->base_gc[state_type], area, x, y, RADIO_BASE);
3113 if (shadow_type == GTK_SHADOW_IN)
3114 draw_part (window, style->text_gc[state_type], area, x, y, RADIO_TEXT);
3120 gtk_default_draw_tab (GtkStyle *style,
3122 GtkStateType state_type,
3123 GtkShadowType shadow_type,
3126 const gchar *detail,
3132 GtkRequisition indicator_size;
3133 GtkBorder indicator_spacing;
3135 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
3137 x += (width - indicator_size.width) / 2;
3138 y += (height - indicator_size.height) / 2 - 1;
3140 draw_varrow (window, style->black_gc, shadow_type, area, GTK_ARROW_UP,
3141 x, y, indicator_size.width, 5);
3142 draw_varrow (window, style->black_gc, shadow_type, area, GTK_ARROW_DOWN,
3143 x, y + 8, indicator_size.width, 5);
3147 gtk_default_draw_shadow_gap (GtkStyle *style,
3149 GtkStateType state_type,
3150 GtkShadowType shadow_type,
3153 const gchar *detail,
3158 GtkPositionType gap_side,
3167 g_return_if_fail (GTK_IS_STYLE (style));
3168 g_return_if_fail (window != NULL);
3170 sanitize_size (window, &width, &height);
3172 switch (shadow_type)
3174 case GTK_SHADOW_NONE:
3177 gc1 = style->dark_gc[state_type];
3178 gc2 = style->black_gc;
3179 gc3 = style->bg_gc[state_type];
3180 gc4 = style->light_gc[state_type];
3182 case GTK_SHADOW_ETCHED_IN:
3183 gc1 = style->dark_gc[state_type];
3184 gc2 = style->light_gc[state_type];
3185 gc3 = style->dark_gc[state_type];
3186 gc4 = style->light_gc[state_type];
3188 case GTK_SHADOW_OUT:
3189 gc1 = style->light_gc[state_type];
3190 gc2 = style->bg_gc[state_type];
3191 gc3 = style->dark_gc[state_type];
3192 gc4 = style->black_gc;
3194 case GTK_SHADOW_ETCHED_OUT:
3195 gc1 = style->light_gc[state_type];
3196 gc2 = style->dark_gc[state_type];
3197 gc3 = style->light_gc[state_type];
3198 gc4 = style->dark_gc[state_type];
3203 gdk_gc_set_clip_rectangle (gc1, area);
3204 gdk_gc_set_clip_rectangle (gc2, area);
3205 gdk_gc_set_clip_rectangle (gc3, area);
3206 gdk_gc_set_clip_rectangle (gc4, area);
3209 switch (shadow_type)
3211 case GTK_SHADOW_NONE:
3213 case GTK_SHADOW_OUT:
3214 case GTK_SHADOW_ETCHED_IN:
3215 case GTK_SHADOW_ETCHED_OUT:
3219 gdk_draw_line (window, gc1,
3220 x, y, x, y + height - 1);
3221 gdk_draw_line (window, gc2,
3222 x + 1, y, x + 1, y + height - 2);
3224 gdk_draw_line (window, gc3,
3225 x + 1, y + height - 2, x + width - 2, y + height - 2);
3226 gdk_draw_line (window, gc3,
3227 x + width - 2, y, x + width - 2, y + height - 2);
3228 gdk_draw_line (window, gc4,
3229 x, y + height - 1, x + width - 1, y + height - 1);
3230 gdk_draw_line (window, gc4,
3231 x + width - 1, y, x + width - 1, y + height - 1);
3234 gdk_draw_line (window, gc1,
3235 x, y, x + gap_x - 1, y);
3236 gdk_draw_line (window, gc2,
3237 x + 1, y + 1, x + gap_x - 1, y + 1);
3238 gdk_draw_line (window, gc2,
3239 x + gap_x, y, x + gap_x, y);
3241 if ((width - (gap_x + gap_width)) > 0)
3243 gdk_draw_line (window, gc1,
3244 x + gap_x + gap_width, y, x + width - 2, y);
3245 gdk_draw_line (window, gc2,
3246 x + gap_x + gap_width, y + 1, x + width - 2, y + 1);
3247 gdk_draw_line (window, gc2,
3248 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
3251 case GTK_POS_BOTTOM:
3252 gdk_draw_line (window, gc1,
3253 x, y, x + width - 1, y);
3254 gdk_draw_line (window, gc1,
3255 x, y, x, y + height - 1);
3256 gdk_draw_line (window, gc2,
3257 x + 1, y + 1, x + width - 2, y + 1);
3258 gdk_draw_line (window, gc2,
3259 x + 1, y + 1, x + 1, y + height - 1);
3261 gdk_draw_line (window, gc3,
3262 x + width - 2, y + 1, x + width - 2, y + height - 1);
3263 gdk_draw_line (window, gc4,
3264 x + width - 1, y, x + width - 1, y + height - 1);
3267 gdk_draw_line (window, gc4,
3268 x, y + height - 1, x + gap_x - 1, y + height - 1);
3269 gdk_draw_line (window, gc3,
3270 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
3271 gdk_draw_line (window, gc3,
3272 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
3274 if ((width - (gap_x + gap_width)) > 0)
3276 gdk_draw_line (window, gc4,
3277 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
3278 gdk_draw_line (window, gc3,
3279 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
3280 gdk_draw_line (window, gc3,
3281 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
3285 gdk_draw_line (window, gc1,
3286 x, y, x + width - 1, y);
3287 gdk_draw_line (window, gc2,
3288 x, y + 1, x + width - 2, y + 1);
3290 gdk_draw_line (window, gc3,
3291 x, y + height - 2, x + width - 2, y + height - 2);
3292 gdk_draw_line (window, gc3,
3293 x + width - 2, y + 1, x + width - 2, y + height - 2);
3294 gdk_draw_line (window, gc4,
3295 x, y + height - 1, x + width - 1, y + height - 1);
3296 gdk_draw_line (window, gc4,
3297 x + width - 1, y, x + width - 1, y + height - 1);
3300 gdk_draw_line (window, gc1,
3301 x, y, x, y + gap_x - 1);
3302 gdk_draw_line (window, gc2,
3303 x + 1, y + 1, x + 1, y + gap_x - 1);
3304 gdk_draw_line (window, gc2,
3305 x, y + gap_x, x, y + gap_x);
3307 if ((width - (gap_x + gap_width)) > 0)
3309 gdk_draw_line (window, gc1,
3310 x, y + gap_x + gap_width, x, y + height - 2);
3311 gdk_draw_line (window, gc2,
3312 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
3313 gdk_draw_line (window, gc2,
3314 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
3318 gdk_draw_line (window, gc1,
3319 x, y, x + width - 1, y);
3320 gdk_draw_line (window, gc1,
3321 x, y, x, y + height - 1);
3322 gdk_draw_line (window, gc2,
3323 x + 1, y + 1, x + width - 1, y + 1);
3324 gdk_draw_line (window, gc2,
3325 x + 1, y + 1, x + 1, y + height - 2);
3327 gdk_draw_line (window, gc3,
3328 x + 1, y + height - 2, x + width - 1, y + height - 2);
3329 gdk_draw_line (window, gc4,
3330 x, y + height - 1, x + width - 1, y + height - 1);
3333 gdk_draw_line (window, gc4,
3334 x + width - 1, y, x + width - 1, y + gap_x - 1);
3335 gdk_draw_line (window, gc3,
3336 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
3337 gdk_draw_line (window, gc3,
3338 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
3340 if ((width - (gap_x + gap_width)) > 0)
3342 gdk_draw_line (window, gc4,
3343 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
3344 gdk_draw_line (window, gc3,
3345 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
3346 gdk_draw_line (window, gc3,
3347 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
3355 gdk_gc_set_clip_rectangle (gc1, NULL);
3356 gdk_gc_set_clip_rectangle (gc2, NULL);
3357 gdk_gc_set_clip_rectangle (gc3, NULL);
3358 gdk_gc_set_clip_rectangle (gc4, NULL);
3363 gtk_default_draw_box_gap (GtkStyle *style,
3365 GtkStateType state_type,
3366 GtkShadowType shadow_type,
3369 const gchar *detail,
3374 GtkPositionType gap_side,
3383 g_return_if_fail (GTK_IS_STYLE (style));
3384 g_return_if_fail (window != NULL);
3386 gtk_style_apply_default_background (style, window,
3387 widget && !GTK_WIDGET_NO_WINDOW (widget),
3388 state_type, area, x, y, width, height);
3390 sanitize_size (window, &width, &height);
3392 switch (shadow_type)
3394 case GTK_SHADOW_NONE:
3397 gc1 = style->dark_gc[state_type];
3398 gc2 = style->black_gc;
3399 gc3 = style->bg_gc[state_type];
3400 gc4 = style->light_gc[state_type];
3402 case GTK_SHADOW_ETCHED_IN:
3403 gc1 = style->dark_gc[state_type];
3404 gc2 = style->light_gc[state_type];
3405 gc3 = style->dark_gc[state_type];
3406 gc4 = style->light_gc[state_type];
3408 case GTK_SHADOW_OUT:
3409 gc1 = style->light_gc[state_type];
3410 gc2 = style->bg_gc[state_type];
3411 gc3 = style->dark_gc[state_type];
3412 gc4 = style->black_gc;
3414 case GTK_SHADOW_ETCHED_OUT:
3415 gc1 = style->light_gc[state_type];
3416 gc2 = style->dark_gc[state_type];
3417 gc3 = style->light_gc[state_type];
3418 gc4 = style->dark_gc[state_type];
3424 gdk_gc_set_clip_rectangle (gc1, area);
3425 gdk_gc_set_clip_rectangle (gc2, area);
3426 gdk_gc_set_clip_rectangle (gc3, area);
3427 gdk_gc_set_clip_rectangle (gc4, area);
3430 switch (shadow_type)
3432 case GTK_SHADOW_NONE:
3434 case GTK_SHADOW_OUT:
3435 case GTK_SHADOW_ETCHED_IN:
3436 case GTK_SHADOW_ETCHED_OUT:
3440 gdk_draw_line (window, gc1,
3441 x, y, x, y + height - 1);
3442 gdk_draw_line (window, gc2,
3443 x + 1, y, x + 1, y + height - 2);
3445 gdk_draw_line (window, gc3,
3446 x + 1, y + height - 2, x + width - 2, y + height - 2);
3447 gdk_draw_line (window, gc3,
3448 x + width - 2, y, x + width - 2, y + height - 2);
3449 gdk_draw_line (window, gc4,
3450 x, y + height - 1, x + width - 1, y + height - 1);
3451 gdk_draw_line (window, gc4,
3452 x + width - 1, y, x + width - 1, y + height - 1);
3455 gdk_draw_line (window, gc1,
3456 x, y, x + gap_x - 1, y);
3457 gdk_draw_line (window, gc2,
3458 x + 1, y + 1, x + gap_x - 1, y + 1);
3459 gdk_draw_line (window, gc2,
3460 x + gap_x, y, x + gap_x, y);
3462 if ((width - (gap_x + gap_width)) > 0)
3464 gdk_draw_line (window, gc1,
3465 x + gap_x + gap_width, y, x + width - 2, y);
3466 gdk_draw_line (window, gc2,
3467 x + gap_x + gap_width, y + 1, x + width - 2, y + 1);
3468 gdk_draw_line (window, gc2,
3469 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
3472 case GTK_POS_BOTTOM:
3473 gdk_draw_line (window, gc1,
3474 x, y, x + width - 1, y);
3475 gdk_draw_line (window, gc1,
3476 x, y, x, y + height - 1);
3477 gdk_draw_line (window, gc2,
3478 x + 1, y + 1, x + width - 2, y + 1);
3479 gdk_draw_line (window, gc2,
3480 x + 1, y + 1, x + 1, y + height - 1);
3482 gdk_draw_line (window, gc3,
3483 x + width - 2, y + 1, x + width - 2, y + height - 1);
3484 gdk_draw_line (window, gc4,
3485 x + width - 1, y, x + width - 1, y + height - 1);
3488 gdk_draw_line (window, gc4,
3489 x, y + height - 1, x + gap_x - 1, y + height - 1);
3490 gdk_draw_line (window, gc3,
3491 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
3492 gdk_draw_line (window, gc3,
3493 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
3495 if ((width - (gap_x + gap_width)) > 0)
3497 gdk_draw_line (window, gc4,
3498 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
3499 gdk_draw_line (window, gc3,
3500 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
3501 gdk_draw_line (window, gc3,
3502 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
3506 gdk_draw_line (window, gc1,
3507 x, y, x + width - 1, y);
3508 gdk_draw_line (window, gc2,
3509 x, y + 1, x + width - 2, y + 1);
3511 gdk_draw_line (window, gc3,
3512 x, y + height - 2, x + width - 2, y + height - 2);
3513 gdk_draw_line (window, gc3,
3514 x + width - 2, y + 1, x + width - 2, y + height - 2);
3515 gdk_draw_line (window, gc4,
3516 x, y + height - 1, x + width - 1, y + height - 1);
3517 gdk_draw_line (window, gc4,
3518 x + width - 1, y, x + width - 1, y + height - 1);
3521 gdk_draw_line (window, gc1,
3522 x, y, x, y + gap_x - 1);
3523 gdk_draw_line (window, gc2,
3524 x + 1, y + 1, x + 1, y + gap_x - 1);
3525 gdk_draw_line (window, gc2,
3526 x, y + gap_x, x, y + gap_x);
3528 if ((width - (gap_x + gap_width)) > 0)
3530 gdk_draw_line (window, gc1,
3531 x, y + gap_x + gap_width, x, y + height - 2);
3532 gdk_draw_line (window, gc2,
3533 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
3534 gdk_draw_line (window, gc2,
3535 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
3539 gdk_draw_line (window, gc1,
3540 x, y, x + width - 1, y);
3541 gdk_draw_line (window, gc1,
3542 x, y, x, y + height - 1);
3543 gdk_draw_line (window, gc2,
3544 x + 1, y + 1, x + width - 1, y + 1);
3545 gdk_draw_line (window, gc2,
3546 x + 1, y + 1, x + 1, y + height - 2);
3548 gdk_draw_line (window, gc3,
3549 x + 1, y + height - 2, x + width - 1, y + height - 2);
3550 gdk_draw_line (window, gc4,
3551 x, y + height - 1, x + width - 1, y + height - 1);
3554 gdk_draw_line (window, gc4,
3555 x + width - 1, y, x + width - 1, y + gap_x - 1);
3556 gdk_draw_line (window, gc3,
3557 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
3558 gdk_draw_line (window, gc3,
3559 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
3561 if ((width - (gap_x + gap_width)) > 0)
3563 gdk_draw_line (window, gc4,
3564 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
3565 gdk_draw_line (window, gc3,
3566 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
3567 gdk_draw_line (window, gc3,
3568 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
3576 gdk_gc_set_clip_rectangle (gc1, NULL);
3577 gdk_gc_set_clip_rectangle (gc2, NULL);
3578 gdk_gc_set_clip_rectangle (gc3, NULL);
3579 gdk_gc_set_clip_rectangle (gc4, NULL);
3584 gtk_default_draw_extension (GtkStyle *style,
3586 GtkStateType state_type,
3587 GtkShadowType shadow_type,
3590 const gchar *detail,
3595 GtkPositionType gap_side)
3602 g_return_if_fail (GTK_IS_STYLE (style));
3603 g_return_if_fail (window != NULL);
3605 gtk_style_apply_default_background (style, window,
3606 widget && !GTK_WIDGET_NO_WINDOW (widget),
3607 GTK_STATE_NORMAL, area, x, y, width, height);
3609 sanitize_size (window, &width, &height);
3611 switch (shadow_type)
3613 case GTK_SHADOW_NONE:
3616 gc1 = style->dark_gc[state_type];
3617 gc2 = style->black_gc;
3618 gc3 = style->bg_gc[state_type];
3619 gc4 = style->light_gc[state_type];
3621 case GTK_SHADOW_ETCHED_IN:
3622 gc1 = style->dark_gc[state_type];
3623 gc2 = style->light_gc[state_type];
3624 gc3 = style->dark_gc[state_type];
3625 gc4 = style->light_gc[state_type];
3627 case GTK_SHADOW_OUT:
3628 gc1 = style->light_gc[state_type];
3629 gc2 = style->bg_gc[state_type];
3630 gc3 = style->dark_gc[state_type];
3631 gc4 = style->black_gc;
3633 case GTK_SHADOW_ETCHED_OUT:
3634 gc1 = style->light_gc[state_type];
3635 gc2 = style->dark_gc[state_type];
3636 gc3 = style->light_gc[state_type];
3637 gc4 = style->dark_gc[state_type];
3643 gdk_gc_set_clip_rectangle (gc1, area);
3644 gdk_gc_set_clip_rectangle (gc2, area);
3645 gdk_gc_set_clip_rectangle (gc3, area);
3646 gdk_gc_set_clip_rectangle (gc4, area);
3649 switch (shadow_type)
3651 case GTK_SHADOW_NONE:
3653 case GTK_SHADOW_OUT:
3654 case GTK_SHADOW_ETCHED_IN:
3655 case GTK_SHADOW_ETCHED_OUT:
3659 gtk_style_apply_default_background (style, window,
3660 widget && !GTK_WIDGET_NO_WINDOW (widget),
3662 x + style->xthickness,
3664 width - (2 * style->xthickness),
3665 height - (style->ythickness));
3666 gdk_draw_line (window, gc1,
3667 x, y, x, y + height - 2);
3668 gdk_draw_line (window, gc2,
3669 x + 1, y, x + 1, y + height - 2);
3671 gdk_draw_line (window, gc3,
3672 x + 2, y + height - 2, x + width - 2, y + height - 2);
3673 gdk_draw_line (window, gc3,
3674 x + width - 2, y, x + width - 2, y + height - 2);
3675 gdk_draw_line (window, gc4,
3676 x + 1, y + height - 1, x + width - 2, y + height - 1);
3677 gdk_draw_line (window, gc4,
3678 x + width - 1, y, x + width - 1, y + height - 2);
3680 case GTK_POS_BOTTOM:
3681 gtk_style_apply_default_background (style, window,
3682 widget && !GTK_WIDGET_NO_WINDOW (widget),
3684 x + style->xthickness,
3685 y + style->ythickness,
3686 width - (2 * style->xthickness),
3687 height - (style->ythickness));
3688 gdk_draw_line (window, gc1,
3689 x + 1, y, x + width - 2, y);
3690 gdk_draw_line (window, gc1,
3691 x, y + 1, x, y + height - 1);
3692 gdk_draw_line (window, gc2,
3693 x + 1, y + 1, x + width - 2, y + 1);
3694 gdk_draw_line (window, gc2,
3695 x + 1, y + 1, x + 1, y + height - 1);
3697 gdk_draw_line (window, gc3,
3698 x + width - 2, y + 2, x + width - 2, y + height - 1);
3699 gdk_draw_line (window, gc4,
3700 x + width - 1, y + 1, x + width - 1, y + height - 1);
3703 gtk_style_apply_default_background (style, window,
3704 widget && !GTK_WIDGET_NO_WINDOW (widget),
3707 y + style->ythickness,
3708 width - (style->xthickness),
3709 height - (2 * style->ythickness));
3710 gdk_draw_line (window, gc1,
3711 x, y, x + width - 2, y);
3712 gdk_draw_line (window, gc2,
3713 x + 1, y + 1, x + width - 2, y + 1);
3715 gdk_draw_line (window, gc3,
3716 x, y + height - 2, x + width - 2, y + height - 2);
3717 gdk_draw_line (window, gc3,
3718 x + width - 2, y + 2, x + width - 2, y + height - 2);
3719 gdk_draw_line (window, gc4,
3720 x, y + height - 1, x + width - 2, y + height - 1);
3721 gdk_draw_line (window, gc4,
3722 x + width - 1, y + 1, x + width - 1, y + height - 2);
3725 gtk_style_apply_default_background (style, window,
3726 widget && !GTK_WIDGET_NO_WINDOW (widget),
3728 x + style->xthickness,
3729 y + style->ythickness,
3730 width - (style->xthickness),
3731 height - (2 * style->ythickness));
3732 gdk_draw_line (window, gc1,
3733 x + 1, y, x + width - 1, y);
3734 gdk_draw_line (window, gc1,
3735 x, y + 1, x, y + height - 2);
3736 gdk_draw_line (window, gc2,
3737 x + 1, y + 1, x + width - 1, y + 1);
3738 gdk_draw_line (window, gc2,
3739 x + 1, y + 1, x + 1, y + height - 2);
3741 gdk_draw_line (window, gc3,
3742 x + 2, y + height - 2, x + width - 1, y + height - 2);
3743 gdk_draw_line (window, gc4,
3744 x + 1, y + height - 1, x + width - 1, y + height - 1);
3751 gdk_gc_set_clip_rectangle (gc1, NULL);
3752 gdk_gc_set_clip_rectangle (gc2, NULL);
3753 gdk_gc_set_clip_rectangle (gc3, NULL);
3754 gdk_gc_set_clip_rectangle (gc4, NULL);
3759 gtk_default_draw_focus (GtkStyle *style,
3763 const gchar *detail,
3771 sanitize_size (window, &width, &height);
3774 gdk_gc_set_clip_rectangle (style->black_gc, area);
3776 gdk_gc_set_line_attributes (style->black_gc, 1, GDK_LINE_ON_OFF_DASH, 0, 0);
3778 if (detail && !strcmp (detail, "add-mode"))
3779 gdk_gc_set_dashes (style->black_gc, 0, "\4\4", 2);
3781 gdk_gc_set_dashes (style->black_gc, 0, "\1\1", 2);
3785 points[1].x = x + width;
3787 points[2].x = x + width;
3788 points[2].y = y + height;
3790 points[3].y = y + height;
3791 points[4] = points[0];
3793 gdk_draw_polygon (window, style->black_gc, FALSE, points, 4);
3794 gdk_gc_set_line_attributes (style->black_gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
3797 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
3801 gtk_default_draw_slider (GtkStyle *style,
3803 GtkStateType state_type,
3804 GtkShadowType shadow_type,
3807 const gchar *detail,
3812 GtkOrientation orientation)
3814 g_return_if_fail (GTK_IS_STYLE (style));
3815 g_return_if_fail (window != NULL);
3817 sanitize_size (window, &width, &height);
3819 gtk_paint_box (style, window, state_type, shadow_type,
3820 area, widget, detail, x, y, width, height);
3823 (strcmp ("hscale", detail) == 0 ||
3824 strcmp ("vscale", detail) == 0))
3826 if (orientation == GTK_ORIENTATION_HORIZONTAL)
3827 gtk_paint_vline (style, window, state_type, area, widget, detail,
3828 y + style->ythickness,
3829 y + height - style->ythickness - 1, x + width / 2);
3831 gtk_paint_hline (style, window, state_type, area, widget, detail,
3832 x + style->xthickness,
3833 x + width - style->xthickness - 1, y + height / 2);
3838 draw_dot (GdkWindow *window,
3846 size = CLAMP (size, 2, 3);
3850 gdk_draw_point (window, light_gc, x, y);
3851 gdk_draw_point (window, light_gc, x+1, y+1);
3853 else if (size == 3);
3855 gdk_draw_point (window, light_gc, x, y);
3856 gdk_draw_point (window, light_gc, x+1, y);
3857 gdk_draw_point (window, light_gc, x, y+1);
3858 gdk_draw_point (window, dark_gc, x+1, y+2);
3859 gdk_draw_point (window, dark_gc, x+2, y+1);
3860 gdk_draw_point (window, dark_gc, x+2, y+2);
3865 gtk_default_draw_handle (GtkStyle *style,
3867 GtkStateType state_type,
3868 GtkShadowType shadow_type,
3871 const gchar *detail,
3876 GtkOrientation orientation)
3879 gint xthick, ythick;
3880 GdkGC *light_gc, *dark_gc;
3885 g_return_if_fail (GTK_IS_STYLE (style));
3886 g_return_if_fail (window != NULL);
3888 sanitize_size (window, &width, &height);
3890 gtk_paint_box (style, window, state_type, shadow_type, area, widget,
3891 detail, x, y, width, height);
3894 if (!strcmp (detail, "paned"))
3896 /* we want to ignore the shadow border in paned widgets */
3900 light_gc = style->light_gc[state_type];
3901 dark_gc = style->black_gc;
3905 xthick = style->xthickness;
3906 ythick = style->ythickness;
3908 light_gc = style->light_gc[state_type];
3909 dark_gc = style->dark_gc[state_type];
3912 rect.x = x + xthick;
3913 rect.y = y + ythick;
3914 rect.width = width - (xthick * 2);
3915 rect.height = height - (ythick * 2);
3918 intersect = gdk_rectangle_intersect (area, &rect, &dest);
3928 gdk_gc_set_clip_rectangle (light_gc, &dest);
3929 gdk_gc_set_clip_rectangle (dark_gc, &dest);
3931 if (!strcmp (detail, "paned"))
3936 gdk_window_get_size (window, &window_width, &window_height);
3938 if (orientation == GTK_ORIENTATION_HORIZONTAL)
3939 for (xx = window_width/2 - 15; xx <= window_width/2 + 15; xx += 5)
3940 draw_dot (window, light_gc, dark_gc, xx, window_height/2 - 1, 3);
3942 for (yy = window_height/2 - 15; yy <= window_height/2 + 15; yy += 5)
3943 draw_dot (window, light_gc, dark_gc, window_width/2 - 1, yy, 3);
3947 for (yy = y + ythick; yy < (y + height - ythick); yy += 3)
3948 for (xx = x + xthick; xx < (x + width - xthick); xx += 6)
3950 draw_dot (window, light_gc, dark_gc, xx, yy, 2);
3951 draw_dot (window, light_gc, dark_gc, xx + 3, yy + 1, 2);
3955 gdk_gc_set_clip_rectangle (light_gc, NULL);
3956 gdk_gc_set_clip_rectangle (dark_gc, NULL);
3960 create_expander_affine (gdouble affine[6],
3970 width = expander_size / 4.0;
3971 height = expander_size / 2.0;
3973 s = sin (degrees * G_PI / 180.0);
3974 c = cos (degrees * G_PI / 180.0);
3980 affine[4] = -width * c - height * -s + x;
3981 affine[5] = -width * s - height * c + y;
3985 apply_affine_on_point (double affine[6], GdkPoint *point)
3989 x = point->x * affine[0] + point->y * affine[2] + affine[4];
3990 y = point->x * affine[1] + point->y * affine[3] + affine[5];
3997 gtk_default_draw_expander (GtkStyle *style,
3999 GtkStateType state_type,
4002 const gchar *detail,
4005 GtkExpanderStyle expander_style)
4013 gtk_widget_style_get (widget,
4014 "expander_size", &expander_size,
4019 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], area);
4020 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], area);
4025 points[1].x = expander_size / 2;
4026 points[1].y = expander_size / 2;
4028 points[2].y = expander_size;
4030 switch (expander_style)
4032 case GTK_EXPANDER_COLLAPSED:
4035 case GTK_EXPANDER_SEMI_COLLAPSED:
4038 case GTK_EXPANDER_SEMI_EXPANDED:
4041 case GTK_EXPANDER_EXPANDED:
4045 g_assert_not_reached ();
4048 create_expander_affine (affine, degrees, expander_size, x, y);
4050 for (i = 0; i < 3; i++)
4051 apply_affine_on_point (affine, &points[i]);
4053 if (state_type == GTK_STATE_PRELIGHT)
4055 gdk_draw_polygon (window, style->base_gc[GTK_STATE_NORMAL],
4057 gdk_draw_polygon (window, style->fg_gc[GTK_STATE_NORMAL],
4060 else if (state_type == GTK_STATE_ACTIVE)
4062 gdk_draw_polygon (window, style->light_gc[GTK_STATE_ACTIVE],
4064 gdk_draw_polygon (window, style->fg_gc[GTK_STATE_NORMAL],
4069 gdk_draw_polygon (window, style->fg_gc[GTK_STATE_NORMAL],
4074 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], NULL);
4075 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], NULL);
4079 typedef struct _ByteRange ByteRange;
4088 range_new (guint start,
4091 ByteRange *br = g_new (ByteRange, 1);
4100 get_insensitive_layout (PangoLayout *layout)
4102 GSList *embossed_ranges = NULL;
4103 GSList *stippled_ranges = NULL;
4104 PangoLayoutIter *iter;
4105 GSList *tmp_list = NULL;
4106 PangoLayout *new_layout;
4107 PangoAttrList *attrs;
4108 GdkBitmap *stipple = NULL;
4110 iter = pango_layout_get_iter (layout);
4114 PangoLayoutRun *run;
4115 PangoAttribute *attr;
4116 gboolean need_stipple = FALSE;
4119 run = pango_layout_iter_get_run (iter);
4123 tmp_list = run->item->analysis.extra_attrs;
4125 while (tmp_list != NULL)
4127 attr = tmp_list->data;
4128 switch (attr->klass->type)
4130 case PANGO_ATTR_FOREGROUND:
4131 case PANGO_ATTR_BACKGROUND:
4132 need_stipple = TRUE;
4142 tmp_list = g_slist_next (tmp_list);
4145 br = range_new (run->item->offset, run->item->offset + run->item->length);
4148 stippled_ranges = g_slist_prepend (stippled_ranges, br);
4150 embossed_ranges = g_slist_prepend (embossed_ranges, br);
4153 while (pango_layout_iter_next_run (iter));
4155 pango_layout_iter_free (iter);
4157 new_layout = pango_layout_copy (layout);
4159 attrs = pango_layout_get_attributes (new_layout);
4163 /* Create attr list if there wasn't one */
4164 attrs = pango_attr_list_new ();
4165 pango_layout_set_attributes (new_layout, attrs);
4166 pango_attr_list_unref (attrs);
4169 tmp_list = embossed_ranges;
4170 while (tmp_list != NULL)
4172 PangoAttribute *attr;
4173 ByteRange *br = tmp_list->data;
4175 attr = gdk_pango_attr_embossed_new (TRUE);
4177 attr->start_index = br->start;
4178 attr->end_index = br->end;
4180 pango_attr_list_change (attrs, attr);
4184 tmp_list = g_slist_next (tmp_list);
4187 g_slist_free (embossed_ranges);
4189 tmp_list = stippled_ranges;
4190 while (tmp_list != NULL)
4192 PangoAttribute *attr;
4193 ByteRange *br = tmp_list->data;
4195 if (stipple == NULL)
4197 #define gray50_width 2
4198 #define gray50_height 2
4199 static char gray50_bits[] = {
4203 stipple = gdk_bitmap_create_from_data (NULL,
4204 gray50_bits, gray50_width,
4208 attr = gdk_pango_attr_stipple_new (stipple);
4210 attr->start_index = br->start;
4211 attr->end_index = br->end;
4213 pango_attr_list_change (attrs, attr);
4217 tmp_list = g_slist_next (tmp_list);
4220 g_slist_free (stippled_ranges);
4223 g_object_unref (G_OBJECT (stipple));
4229 gtk_default_draw_layout (GtkStyle *style,
4231 GtkStateType state_type,
4235 const gchar *detail,
4238 PangoLayout *layout)
4242 g_return_if_fail (GTK_IS_STYLE (style));
4243 g_return_if_fail (window != NULL);
4245 gc = use_text ? style->text_gc[state_type] : style->fg_gc[state_type];
4248 gdk_gc_set_clip_rectangle (gc, area);
4250 if (state_type == GTK_STATE_INSENSITIVE)
4254 ins = get_insensitive_layout (layout);
4256 gdk_draw_layout (window, gc, x, y, ins);
4258 g_object_unref (G_OBJECT (ins));
4262 gdk_draw_layout (window, gc, x, y, layout);
4266 gdk_gc_set_clip_rectangle (gc, NULL);
4270 gtk_default_draw_resize_grip (GtkStyle *style,
4272 GtkStateType state_type,
4275 const gchar *detail,
4282 g_return_if_fail (GTK_IS_STYLE (style));
4283 g_return_if_fail (window != NULL);
4287 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
4288 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
4289 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
4292 /* make it square, aligning to bottom right */
4295 y += (height - width);
4298 else if (height < width)
4300 x += (width - height);
4304 /* Clear background */
4305 gdk_draw_rectangle (window,
4306 style->bg_gc[state_type],
4308 x, y, width, height);
4312 case GDK_WINDOW_EDGE_SOUTH_EAST:
4319 while (xi < (x + width - 3))
4321 gdk_draw_line (window,
4322 style->light_gc[state_type],
4329 gdk_draw_line (window,
4330 style->dark_gc[state_type],
4337 gdk_draw_line (window,
4338 style->dark_gc[state_type],
4348 g_assert_not_reached ();
4354 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
4355 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
4356 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
4361 gtk_style_shade (GdkColor *a,
4369 red = (gdouble) a->red / 65535.0;
4370 green = (gdouble) a->green / 65535.0;
4371 blue = (gdouble) a->blue / 65535.0;
4373 rgb_to_hls (&red, &green, &blue);
4378 else if (green < 0.0)
4384 else if (blue < 0.0)
4387 hls_to_rgb (&red, &green, &blue);
4389 b->red = red * 65535.0;
4390 b->green = green * 65535.0;
4391 b->blue = blue * 65535.0;
4395 rgb_to_hls (gdouble *r,
4436 l = (max + min) / 2;
4443 s = (max - min) / (max + min);
4445 s = (max - min) / (2 - max - min);
4449 h = (green - blue) / delta;
4450 else if (green == max)
4451 h = 2 + (blue - red) / delta;
4452 else if (blue == max)
4453 h = 4 + (red - green) / delta;
4466 hls_to_rgb (gdouble *h,
4479 if (lightness <= 0.5)
4480 m2 = lightness * (1 + saturation);
4482 m2 = lightness + saturation - lightness * saturation;
4483 m1 = 2 * lightness - m2;
4485 if (saturation == 0)
4500 r = m1 + (m2 - m1) * hue / 60;
4504 r = m1 + (m2 - m1) * (240 - hue) / 60;
4515 g = m1 + (m2 - m1) * hue / 60;
4519 g = m1 + (m2 - m1) * (240 - hue) / 60;
4530 b = m1 + (m2 - m1) * hue / 60;
4534 b = m1 + (m2 - m1) * (240 - hue) / 60;
4545 gtk_paint_hline (GtkStyle *style,
4547 GtkStateType state_type,
4550 const gchar *detail,
4555 g_return_if_fail (GTK_IS_STYLE (style));
4556 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
4558 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, area, widget, detail, x1, x2, y);
4562 gtk_paint_vline (GtkStyle *style,
4564 GtkStateType state_type,
4567 const gchar *detail,
4572 g_return_if_fail (GTK_IS_STYLE (style));
4573 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
4575 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, area, widget, detail, y1, y2, x);
4579 gtk_paint_shadow (GtkStyle *style,
4581 GtkStateType state_type,
4582 GtkShadowType shadow_type,
4585 const gchar *detail,
4591 g_return_if_fail (GTK_IS_STYLE (style));
4592 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
4594 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4598 gtk_paint_polygon (GtkStyle *style,
4600 GtkStateType state_type,
4601 GtkShadowType shadow_type,
4604 const gchar *detail,
4609 g_return_if_fail (GTK_IS_STYLE (style));
4610 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
4612 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, area, widget, detail, points, npoints, fill);
4616 gtk_paint_arrow (GtkStyle *style,
4618 GtkStateType state_type,
4619 GtkShadowType shadow_type,
4622 const gchar *detail,
4623 GtkArrowType arrow_type,
4630 g_return_if_fail (GTK_IS_STYLE (style));
4631 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
4633 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, area, widget, detail, arrow_type, fill, x, y, width, height);
4637 gtk_paint_diamond (GtkStyle *style,
4639 GtkStateType state_type,
4640 GtkShadowType shadow_type,
4643 const gchar *detail,
4649 g_return_if_fail (GTK_IS_STYLE (style));
4650 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
4652 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4656 gtk_paint_string (GtkStyle *style,
4658 GtkStateType state_type,
4661 const gchar *detail,
4664 const gchar *string)
4666 g_return_if_fail (GTK_IS_STYLE (style));
4667 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
4669 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, area, widget, detail, x, y, string);
4673 gtk_paint_box (GtkStyle *style,
4675 GtkStateType state_type,
4676 GtkShadowType shadow_type,
4679 const gchar *detail,
4685 g_return_if_fail (GTK_IS_STYLE (style));
4686 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
4688 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4692 gtk_paint_flat_box (GtkStyle *style,
4694 GtkStateType state_type,
4695 GtkShadowType shadow_type,
4698 const gchar *detail,
4704 g_return_if_fail (GTK_IS_STYLE (style));
4705 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
4707 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4711 gtk_paint_check (GtkStyle *style,
4713 GtkStateType state_type,
4714 GtkShadowType shadow_type,
4717 const gchar *detail,
4723 g_return_if_fail (GTK_IS_STYLE (style));
4724 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
4726 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4730 gtk_paint_option (GtkStyle *style,
4732 GtkStateType state_type,
4733 GtkShadowType shadow_type,
4736 const gchar *detail,
4742 g_return_if_fail (GTK_IS_STYLE (style));
4743 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
4745 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4749 gtk_paint_tab (GtkStyle *style,
4751 GtkStateType state_type,
4752 GtkShadowType shadow_type,
4755 const gchar *detail,
4761 g_return_if_fail (GTK_IS_STYLE (style));
4762 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
4764 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
4768 gtk_paint_shadow_gap (GtkStyle *style,
4770 GtkStateType state_type,
4771 GtkShadowType shadow_type,
4779 GtkPositionType gap_side,
4783 g_return_if_fail (GTK_IS_STYLE (style));
4784 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
4786 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);
4791 gtk_paint_box_gap (GtkStyle *style,
4793 GtkStateType state_type,
4794 GtkShadowType shadow_type,
4802 GtkPositionType gap_side,
4806 g_return_if_fail (GTK_IS_STYLE (style));
4807 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
4809 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);
4813 gtk_paint_extension (GtkStyle *style,
4815 GtkStateType state_type,
4816 GtkShadowType shadow_type,
4824 GtkPositionType gap_side)
4826 g_return_if_fail (GTK_IS_STYLE (style));
4827 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
4829 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side);
4833 gtk_paint_focus (GtkStyle *style,
4837 const gchar *detail,
4843 g_return_if_fail (GTK_IS_STYLE (style));
4844 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
4846 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, area, widget, detail, x, y, width, height);
4850 gtk_paint_slider (GtkStyle *style,
4852 GtkStateType state_type,
4853 GtkShadowType shadow_type,
4856 const gchar *detail,
4861 GtkOrientation orientation)
4863 g_return_if_fail (GTK_IS_STYLE (style));
4864 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
4866 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
4870 gtk_paint_handle (GtkStyle *style,
4872 GtkStateType state_type,
4873 GtkShadowType shadow_type,
4876 const gchar *detail,
4881 GtkOrientation orientation)
4883 g_return_if_fail (GTK_IS_STYLE (style));
4884 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
4886 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
4890 gtk_paint_expander (GtkStyle *style,
4892 GtkStateType state_type,
4895 const gchar *detail,
4898 GtkExpanderStyle expander_style)
4900 g_return_if_fail (GTK_IS_STYLE (style));
4901 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
4903 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type, area,
4904 widget, detail, x, y, expander_style);
4908 gtk_paint_layout (GtkStyle *style,
4910 GtkStateType state_type,
4914 const gchar *detail,
4917 PangoLayout *layout)
4919 g_return_if_fail (GTK_IS_STYLE (style));
4920 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
4922 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text, area,
4923 widget, detail, x, y, layout);
4927 gtk_paint_resize_grip (GtkStyle *style,
4929 GtkStateType state_type,
4932 const gchar *detail,
4940 g_return_if_fail (GTK_IS_STYLE (style));
4941 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
4943 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
4944 area, widget, detail,
4945 edge, x, y, width, height);
4949 gtk_border_copy (const GtkBorder *border)
4951 return (GtkBorder *)g_memdup (border, sizeof (GtkBorder));
4955 gtk_border_free (GtkBorder *border)
4961 * gtk_style_get_font:
4962 * @style: a #GtkStyle
4964 * Gets the #GdkFont to use for the given style. This is
4965 * meant only as a replacement for direct access to style->font
4966 * and should not be used in new code. New code should
4967 * use style->font_desc instead.
4969 * Return value: the #GdkFont for the style. This font is owned
4970 * by the style; if you want to keep around a copy, you must
4971 * call gdk_font_ref().
4974 gtk_style_get_font (GtkStyle *style)
4976 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
4978 if (style->private_font && style->private_font_desc)
4980 if (!style->font_desc ||
4981 !pango_font_description_equal (style->private_font_desc, style->font_desc))
4983 gdk_font_unref (style->private_font);
4984 style->private_font = NULL;
4986 if (style->private_font_desc)
4988 pango_font_description_free (style->private_font_desc);
4989 style->private_font_desc = NULL;
4994 if (!style->private_font)
4996 if (style->font_desc)
4998 style->private_font = gdk_font_from_description (style->font_desc);
4999 style->private_font_desc = pango_font_description_copy (style->font_desc);
5002 if (!style->private_font)
5003 style->private_font = gdk_font_load ("fixed");
5005 if (!style->private_font)
5006 g_error ("Unable to load \"fixed\" font");
5009 return style->private_font;
5013 * gtk_style_set_font:
5014 * @style: a #GtkStyle.
5015 * @font: a #GdkFont, or %NULL to use the #GdkFont corresponding
5016 * to style->font_desc.
5018 * Sets the #GdkFont to use for a given style. This is
5019 * meant only as a replacement for direct access to style->font
5020 * and should not be used in new code. New code should
5021 * use style->font_desc instead.
5024 gtk_style_set_font (GtkStyle *style,
5029 g_return_if_fail (GTK_IS_STYLE (style));
5031 old_font = style->private_font;
5033 style->private_font = font;
5035 gdk_font_ref (font);
5038 gdk_font_unref (old_font);
5040 if (style->private_font_desc)
5042 pango_font_description_free (style->private_font_desc);
5043 style->private_font_desc = NULL;
5048 * _gtk_draw_insertion_cursor:
5049 * @drawable: a #GdkDrawable
5051 * @location: location where to draw the cursor (@location->width is ignored)
5052 * @dir: text direction for the cursor, used to decide whether to draw a
5053 * directional arrow on the cursor and in what direction. Unless both
5054 * strong and weak cursors are displayed, this should be %GTK_TEXT_DIR_NONE.
5056 * Draws a text caret on @drawable at @location. This is not a style function
5057 * but merely a convenience function for drawing the standard cursor shape.
5060 _gtk_draw_insertion_cursor (GdkDrawable *drawable,
5062 GdkRectangle *location,
5063 GtkTextDirection dir)
5065 gint stem_width = location->height / 30 + 1;
5066 gint arrow_width = stem_width + 1;
5070 for (i = 0; i < stem_width; i++)
5071 gdk_draw_line (drawable, gc,
5072 location->x + i - stem_width / 2, location->y,
5073 location->x + i - stem_width / 2, location->y + location->height);
5075 if (dir == GTK_TEXT_DIR_RTL)
5077 x = location->x - stem_width / 2 - 1;
5078 y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
5080 for (i = 0; i < arrow_width; i++)
5082 gdk_draw_line (drawable, gc,
5084 x, y + 2 * arrow_width - i - 1);
5088 else if (dir == GTK_TEXT_DIR_LTR)
5090 x = location->x + stem_width - stem_width / 2;
5091 y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
5093 for (i = 0; i < arrow_width; i++)
5095 gdk_draw_line (drawable, gc,
5097 x, y + 2 * arrow_width - i - 1);