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 --- */
49 /* --- prototypes --- */
50 static void gtk_style_init (GtkStyle *style);
51 static void gtk_style_class_init (GtkStyleClass *klass);
52 static void gtk_style_finalize (GObject *object);
53 static void gtk_style_realize (GtkStyle *style,
54 GdkColormap *colormap);
55 static void gtk_style_real_realize (GtkStyle *style);
56 static void gtk_style_real_unrealize (GtkStyle *style);
57 static void gtk_style_real_copy (GtkStyle *style,
59 static void gtk_style_real_set_background (GtkStyle *style,
61 GtkStateType state_type);
62 static GtkStyle *gtk_style_real_clone (GtkStyle *style);
63 static void gtk_style_real_init_from_rc (GtkStyle *style,
64 GtkRcStyle *rc_style);
65 static GdkPixbuf *gtk_default_render_icon (GtkStyle *style,
66 const GtkIconSource *source,
67 GtkTextDirection direction,
72 static void gtk_default_draw_hline (GtkStyle *style,
74 GtkStateType state_type,
81 static void gtk_default_draw_vline (GtkStyle *style,
83 GtkStateType state_type,
90 static void gtk_default_draw_shadow (GtkStyle *style,
92 GtkStateType state_type,
93 GtkShadowType shadow_type,
101 static void gtk_default_draw_polygon (GtkStyle *style,
103 GtkStateType state_type,
104 GtkShadowType shadow_type,
111 static void gtk_default_draw_arrow (GtkStyle *style,
113 GtkStateType state_type,
114 GtkShadowType shadow_type,
118 GtkArrowType arrow_type,
124 static void gtk_default_draw_diamond (GtkStyle *style,
126 GtkStateType state_type,
127 GtkShadowType shadow_type,
135 static void gtk_default_draw_string (GtkStyle *style,
137 GtkStateType state_type,
143 const gchar *string);
144 static void gtk_default_draw_box (GtkStyle *style,
146 GtkStateType state_type,
147 GtkShadowType shadow_type,
155 static void gtk_default_draw_flat_box (GtkStyle *style,
157 GtkStateType state_type,
158 GtkShadowType shadow_type,
166 static void gtk_default_draw_check (GtkStyle *style,
168 GtkStateType state_type,
169 GtkShadowType shadow_type,
177 static void gtk_default_draw_option (GtkStyle *style,
179 GtkStateType state_type,
180 GtkShadowType shadow_type,
188 static void gtk_default_draw_tab (GtkStyle *style,
190 GtkStateType state_type,
191 GtkShadowType shadow_type,
199 static void gtk_default_draw_shadow_gap (GtkStyle *style,
201 GtkStateType state_type,
202 GtkShadowType shadow_type,
210 GtkPositionType gap_side,
213 static void gtk_default_draw_box_gap (GtkStyle *style,
215 GtkStateType state_type,
216 GtkShadowType shadow_type,
224 GtkPositionType gap_side,
227 static void gtk_default_draw_extension (GtkStyle *style,
229 GtkStateType state_type,
230 GtkShadowType shadow_type,
238 GtkPositionType gap_side);
239 static void gtk_default_draw_focus (GtkStyle *style,
241 GtkStateType state_type,
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,
314 static void style_unrealize_cursor_gcs (GtkStyle *style);
316 static GdkFont *gtk_style_get_font_internal (GtkStyle *style);
319 * Data for default check and radio buttons
322 static const GtkRequisition default_option_indicator_size = { 7, 13 };
323 static const GtkBorder default_option_indicator_spacing = { 7, 5, 2, 2 };
325 #define INDICATOR_PART_SIZE 13
335 CHECK_INCONSISTENT_TEXT,
342 RADIO_INCONSISTENT_AA,
343 RADIO_INCONSISTENT_TEXT
347 * Extracted from check-13.png, width=13, height=13
349 static const guchar check_black_bits[] = {
350 0x00,0x00,0xfe,0x0f,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
351 0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x00,0x00,0x00,0x00};
352 static const guchar check_dark_bits[] = {
353 0xff,0x1f,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
354 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x00,0x00};
355 static const guchar 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,0x00,0x00};
358 static const guchar check_light_bits[] = {
359 0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
360 0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0xfe,0x1f,0x00,0x00};
361 static const guchar check_text_bits[] = {
362 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x03,0x80,0x01,0x80,0x00,0x58,
363 0x00,0x60,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
364 static const guchar check_aa_bits[] = {
365 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x58,0x00,0xa0,
366 0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
367 static const guchar check_base_bits[] = {
368 0x00,0x00,0x00,0x00,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,
369 0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0x00,0x00,0x00,0x00,0x00,0x00};
372 * Extracted from check-13-inconsistent.png, width=13, height=13
374 static const guchar check_inconsistent_text_bits[] = {
375 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,0x03,0xf8,
376 0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
379 * check_inconsistent_aa_bits is currently not used, since it is all zeros.
381 static const guchar check_inconsistent_aa_bits[] = {
382 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
383 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
387 * Extracted from radio-13.png, width=13, height=13
389 static const guchar radio_black_bits[] = {
390 0x00,0x00,0xf0,0x01,0x0c,0x02,0x04,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
391 0x00,0x02,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0d,0x08};
392 static const guchar radio_dark_bits[] = {
393 0xf0,0x00,0x0c,0x02,0x02,0x04,0x02,0x04,0x01,0x08,0x01,0x08,0x01,0x08,0x01,
394 0x08,0x00,0x08,0x02,0x04,0x0c,0x06,0xf0,0x01,0x00,0x00,0x00,0x00};
395 static const guchar radio_mid_bits[] = {
396 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
397 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
398 static const guchar radio_light_bits[] = {
399 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x10,0x00,
400 0x10,0x00,0x10,0x00,0x08,0x00,0x08,0x00,0x06,0xe0,0x01,0x00,0x00};
401 static const guchar radio_text_bits[] = {
402 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x00,0xf0,0x01,0xf0,0x01,0xf0,
403 0x01,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
406 * radio_aa_bits is currently not used, since it is all zeros.
408 static const guchar radio_aa_bits[] = {
409 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
410 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
412 static const guchar radio_base_bits[] = {
413 0x00,0x00,0x00,0x00,0xf0,0x01,0xf8,0x03,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,
414 0x07,0xfc,0x07,0xf8,0x03,0xf0,0x01,0x00,0x00,0x00,0x00,0x00,0x00};
417 * Extracted from radio-13.png, width=13, height=13
419 static const guchar radio_inconsistent_text_bits[] = {
420 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,0x03,0x00,
421 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
422 static const guchar radio_inconsistent_aa_bits[] = {
423 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,0x03,0x00,0x00,0xf8,
424 0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
428 GList *bmap_list; /* list of GdkBitmap */
429 } indicator_parts[] = {
430 { check_aa_bits, NULL },
431 { check_base_bits, NULL },
432 { check_black_bits, NULL },
433 { check_dark_bits, NULL },
434 { check_light_bits, NULL },
435 { check_mid_bits, NULL },
436 { check_text_bits, NULL },
437 { check_inconsistent_text_bits, NULL },
438 { radio_base_bits, NULL },
439 { radio_black_bits, NULL },
440 { radio_dark_bits, NULL },
441 { radio_light_bits, NULL },
442 { radio_mid_bits, NULL },
443 { radio_text_bits, NULL },
444 { radio_inconsistent_aa_bits, NULL },
445 { radio_inconsistent_text_bits, NULL },
448 /* --- variables --- */
449 static const GdkColor gtk_default_normal_fg = { 0, 0, 0, 0 };
450 static const GdkColor gtk_default_active_fg = { 0, 0, 0, 0 };
451 static const GdkColor gtk_default_prelight_fg = { 0, 0, 0, 0 };
452 static const GdkColor gtk_default_selected_fg = { 0, 0xffff, 0xffff, 0xffff };
453 static const GdkColor gtk_default_insensitive_fg = { 0, 0x7530, 0x7530, 0x7530 };
455 static const GdkColor gtk_default_normal_bg = { 0, 0xdcdc, 0xdada, 0xd5d5 };
456 static const GdkColor gtk_default_active_bg = { 0, 0xbaba, 0xb5b5, 0xabab };
457 static const GdkColor gtk_default_prelight_bg = { 0, 0xeeee, 0xebeb, 0xe7e7 };
458 static const GdkColor gtk_default_selected_bg = { 0, 0x4b4b, 0x6969, 0x8383 };
459 static const GdkColor gtk_default_insensitive_bg = { 0, 0xdcdc, 0xdada, 0xd5d5 };
460 static const GdkColor gtk_default_selected_base = { 0, 0x4b4b, 0x6969, 0x8383 };
461 static const GdkColor gtk_default_active_base = { 0, 0x8080, 0x7d7d, 0x7474 };
463 static gpointer parent_class = NULL;
466 /* --- functions --- */
468 gtk_style_get_type (void)
470 static GType style_type = 0;
474 static const GTypeInfo style_info =
476 sizeof (GtkStyleClass),
477 (GBaseInitFunc) NULL,
478 (GBaseFinalizeFunc) NULL,
479 (GClassInitFunc) gtk_style_class_init,
480 NULL, /* class_finalize */
481 NULL, /* class_data */
484 (GInstanceInitFunc) gtk_style_init,
487 style_type = g_type_register_static (G_TYPE_OBJECT, "GtkStyle",
495 * _gtk_style_init_for_settings:
496 * @style: a #GtkStyle
497 * @settings: a #GtkSettings
499 * Initializes the font description in @style accoridng to the default
500 * font name of @settings. This is called for gtk_style_new() with
501 * the settings for the default screen (if any); if we are creating
502 * a style for a particular screen, we then call it again in a
503 * location where we know the correct settings.
504 * The reason for this is that gtk_rc_style_create_style() doesn't
505 * take the screen for an argument.
508 _gtk_style_init_for_settings (GtkStyle *style,
509 GtkSettings *settings)
511 const gchar *font_name = _gtk_rc_context_get_default_font_name (settings);
513 if (style->font_desc)
514 pango_font_description_free (style->font_desc);
516 style->font_desc = pango_font_description_from_string (font_name);
518 if (!pango_font_description_get_family (style->font_desc))
520 g_warning ("Default font does not have a family set");
521 pango_font_description_set_family (style->font_desc, "Sans");
523 if (pango_font_description_get_size (style->font_desc) <= 0)
525 g_warning ("Default font does not have a positive size");
526 pango_font_description_set_size (style->font_desc, 10 * PANGO_SCALE);
531 gtk_style_init (GtkStyle *style)
535 GtkSettings *settings = gtk_settings_get_default ();
538 _gtk_style_init_for_settings (style, settings);
540 style->font_desc = pango_font_description_from_string ("Sans 10");
542 style->attach_count = 0;
543 style->colormap = NULL;
546 style->black.red = 0;
547 style->black.green = 0;
548 style->black.blue = 0;
550 style->white.red = 65535;
551 style->white.green = 65535;
552 style->white.blue = 65535;
554 style->black_gc = NULL;
555 style->white_gc = NULL;
557 style->fg[GTK_STATE_NORMAL] = gtk_default_normal_fg;
558 style->fg[GTK_STATE_ACTIVE] = gtk_default_active_fg;
559 style->fg[GTK_STATE_PRELIGHT] = gtk_default_prelight_fg;
560 style->fg[GTK_STATE_SELECTED] = gtk_default_selected_fg;
561 style->fg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
563 style->bg[GTK_STATE_NORMAL] = gtk_default_normal_bg;
564 style->bg[GTK_STATE_ACTIVE] = gtk_default_active_bg;
565 style->bg[GTK_STATE_PRELIGHT] = gtk_default_prelight_bg;
566 style->bg[GTK_STATE_SELECTED] = gtk_default_selected_bg;
567 style->bg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg;
569 for (i = 0; i < 4; i++)
571 style->text[i] = style->fg[i];
572 style->base[i] = style->white;
575 style->base[GTK_STATE_SELECTED] = gtk_default_selected_base;
576 style->text[GTK_STATE_SELECTED] = style->white;
577 style->base[GTK_STATE_ACTIVE] = gtk_default_active_base;
578 style->text[GTK_STATE_ACTIVE] = style->white;
579 style->base[GTK_STATE_INSENSITIVE] = gtk_default_prelight_bg;
580 style->text[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
582 for (i = 0; i < 5; i++)
583 style->bg_pixmap[i] = NULL;
585 style->rc_style = NULL;
587 for (i = 0; i < 5; i++)
589 style->fg_gc[i] = NULL;
590 style->bg_gc[i] = NULL;
591 style->light_gc[i] = NULL;
592 style->dark_gc[i] = NULL;
593 style->mid_gc[i] = NULL;
594 style->text_gc[i] = NULL;
595 style->base_gc[i] = NULL;
596 style->text_aa_gc[i] = NULL;
599 style->xthickness = 2;
600 style->ythickness = 2;
602 style->property_cache = NULL;
606 gtk_style_class_init (GtkStyleClass *klass)
608 GObjectClass *object_class = G_OBJECT_CLASS (klass);
610 parent_class = g_type_class_peek_parent (klass);
612 object_class->finalize = gtk_style_finalize;
614 klass->clone = gtk_style_real_clone;
615 klass->copy = gtk_style_real_copy;
616 klass->init_from_rc = gtk_style_real_init_from_rc;
617 klass->realize = gtk_style_real_realize;
618 klass->unrealize = gtk_style_real_unrealize;
619 klass->set_background = gtk_style_real_set_background;
620 klass->render_icon = gtk_default_render_icon;
622 klass->draw_hline = gtk_default_draw_hline;
623 klass->draw_vline = gtk_default_draw_vline;
624 klass->draw_shadow = gtk_default_draw_shadow;
625 klass->draw_polygon = gtk_default_draw_polygon;
626 klass->draw_arrow = gtk_default_draw_arrow;
627 klass->draw_diamond = gtk_default_draw_diamond;
628 klass->draw_string = gtk_default_draw_string;
629 klass->draw_box = gtk_default_draw_box;
630 klass->draw_flat_box = gtk_default_draw_flat_box;
631 klass->draw_check = gtk_default_draw_check;
632 klass->draw_option = gtk_default_draw_option;
633 klass->draw_tab = gtk_default_draw_tab;
634 klass->draw_shadow_gap = gtk_default_draw_shadow_gap;
635 klass->draw_box_gap = gtk_default_draw_box_gap;
636 klass->draw_extension = gtk_default_draw_extension;
637 klass->draw_focus = gtk_default_draw_focus;
638 klass->draw_slider = gtk_default_draw_slider;
639 klass->draw_handle = gtk_default_draw_handle;
640 klass->draw_expander = gtk_default_draw_expander;
641 klass->draw_layout = gtk_default_draw_layout;
642 klass->draw_resize_grip = gtk_default_draw_resize_grip;
646 clear_property_cache (GtkStyle *style)
648 if (style->property_cache)
652 for (i = 0; i < style->property_cache->len; i++)
654 PropertyValue *node = &g_array_index (style->property_cache, PropertyValue, i);
656 g_param_spec_unref (node->pspec);
657 g_value_unset (&node->value);
659 g_array_free (style->property_cache, TRUE);
660 style->property_cache = NULL;
665 gtk_style_finalize (GObject *object)
667 GtkStyle *style = GTK_STYLE (object);
669 g_return_if_fail (style->attach_count == 0);
671 clear_property_cache (style);
675 if (style->styles->data != style)
676 g_slist_remove (style->styles, style);
679 GSList *tmp_list = style->styles->next;
683 GTK_STYLE (tmp_list->data)->styles = style->styles->next;
684 tmp_list = tmp_list->next;
686 g_slist_free_1 (style->styles);
690 pango_font_description_free (style->font_desc);
692 if (style->private_font)
693 gdk_font_unref (style->private_font);
695 if (style->private_font_desc)
696 pango_font_description_free (style->private_font_desc);
699 gtk_rc_style_unref (style->rc_style);
701 G_OBJECT_CLASS (parent_class)->finalize (object);
706 gtk_style_copy (GtkStyle *style)
710 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
712 new_style = GTK_STYLE_GET_CLASS (style)->clone (style);
713 GTK_STYLE_GET_CLASS (style)->copy (new_style, style);
719 gtk_style_duplicate (GtkStyle *style)
723 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
725 new_style = gtk_style_copy (style);
727 style->styles = g_slist_append (style->styles, new_style);
728 new_style->styles = style->styles;
735 * @returns: a new #GtkStyle.
737 * Creates a new #GtkStyle.
744 style = g_object_new (GTK_TYPE_STYLE, NULL);
751 * @style: a #GtkStyle.
752 * @window: a #GdkWindow.
753 * @returns: Either @style, or a newly-created #GtkStyle.
754 * If the style is newly created, the style parameter
755 * will be dereferenced, and the new style will have
756 * a reference count belonging to the caller.
758 * Attaches a style to a window; this process allocates the
759 * colors and creates the GC's for the style - it specializes
760 * it to a particular visual and colormap. The process may
761 * involve the creation of a new style if the style has already
762 * been attached to a window with a different style and colormap.
765 * FIXME: The sequence -
766 * create a style => s1
767 * attach s1 to v1, c1 => s1
768 * attach s1 to v2, c2 => s2
769 * detach s1 from v1, c1
770 * attach s1 to v2, c2 => s3
771 * results in two separate, unlinked styles s2 and s3 which
772 * are identical and could be shared. To fix this, we would
773 * want to never remove a style from the list of linked
774 * styles as long as as it has a reference count. However, the
775 * disadvantage of doing it this way means that we would need two
776 * passes through the linked list when attaching (one to check for
777 * matching styles, one to look for empty unattached styles - but
778 * it will almost never be longer than 2 elements.
781 gtk_style_attach (GtkStyle *style,
785 GtkStyle *new_style = NULL;
786 GdkColormap *colormap;
788 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
789 g_return_val_if_fail (window != NULL, NULL);
791 colormap = gdk_drawable_get_colormap (window);
794 style->styles = g_slist_append (NULL, style);
796 styles = style->styles;
799 new_style = styles->data;
801 if (new_style->attach_count == 0)
803 gtk_style_realize (new_style, colormap);
806 else if (new_style->colormap == colormap)
810 styles = styles->next;
815 new_style = gtk_style_duplicate (style);
816 if (gdk_colormap_get_screen (style->colormap) != gdk_colormap_get_screen (colormap) &&
817 new_style->private_font)
819 gdk_font_unref (new_style->private_font);
820 new_style->private_font = NULL;
822 gtk_style_realize (new_style, colormap);
825 /* A style gets a refcount from being attached */
826 if (new_style->attach_count == 0)
827 g_object_ref (new_style);
829 /* Another refcount belongs to the parent */
830 if (style != new_style)
832 g_object_unref (style);
833 g_object_ref (new_style);
836 new_style->attach_count++;
842 gtk_style_detach (GtkStyle *style)
844 g_return_if_fail (GTK_IS_STYLE (style));
846 style->attach_count -= 1;
847 if (style->attach_count == 0)
849 GTK_STYLE_GET_CLASS (style)->unrealize (style);
851 g_object_unref (style->colormap);
852 style->colormap = NULL;
854 if (style->private_font_desc)
856 if (style->private_font)
858 gdk_font_unref (style->private_font);
859 style->private_font = NULL;
862 pango_font_description_free (style->private_font_desc);
863 style->private_font_desc = NULL;
866 g_object_unref (style);
872 * @style: a #GtkStyle.
875 * Deprecated equivalent of g_object_ref().
878 gtk_style_ref (GtkStyle *style)
880 return (GtkStyle *) g_object_ref (style);
885 * @style: a #GtkStyle.
887 * Deprecated equivalent of g_object_unref().
890 gtk_style_unref (GtkStyle *style)
892 g_object_unref (style);
896 gtk_style_realize (GtkStyle *style,
897 GdkColormap *colormap)
899 g_return_if_fail (GTK_IS_STYLE (style));
900 g_return_if_fail (GDK_IS_COLORMAP (colormap));
902 style->colormap = g_object_ref (colormap);
903 style->depth = gdk_colormap_get_visual (colormap)->depth;
905 GTK_STYLE_GET_CLASS (style)->realize (style);
909 gtk_style_lookup_icon_set (GtkStyle *style,
910 const char *stock_id)
914 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
915 g_return_val_if_fail (stock_id != NULL, NULL);
917 iter = style->icon_factories;
920 GtkIconSet *icon_set = gtk_icon_factory_lookup (GTK_ICON_FACTORY (iter->data),
925 iter = g_slist_next (iter);
928 return gtk_icon_factory_lookup_default (stock_id);
933 * @style: a #GtkStyle
934 * @window: a #GdkWindow
935 * @state_type: a state
936 * @x1: the starting x coordinate
937 * @x2: the ending x coordinate
938 * @y: the y coordinate
940 * Draws a horizontal line from (@x1, @y) to (@x2, @y) in @window
941 * using the given style and state.
943 * Deprecated: Use gtk_paint_hline() instead.
946 gtk_draw_hline (GtkStyle *style,
948 GtkStateType state_type,
953 g_return_if_fail (GTK_IS_STYLE (style));
954 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
956 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, NULL, NULL, NULL, x1, x2, y);
962 * @style: a #GtkStyle
963 * @window: a #GdkWindow
964 * @state_type: a state
965 * @y1_: the starting y coordinate
966 * @y2_: the ending y coordinate
967 * @x: the x coordinate
969 * Draws a vertical line from (@x, @y1_) to (@x, @y2_) in @window
970 * using the given style and state.
972 * Deprecated: Use gtk_paint_vline() instead.
975 gtk_draw_vline (GtkStyle *style,
977 GtkStateType state_type,
982 g_return_if_fail (GTK_IS_STYLE (style));
983 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
985 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, NULL, NULL, NULL, y1_, y2_, x);
990 * @style: a #GtkStyle
991 * @window: a #GdkWindow
992 * @state_type: a state
993 * @shadow_type: type of shadow to draw
994 * @x: x origin of the rectangle
995 * @y: y origin of the rectangle
996 * @width: width of the rectangle
997 * @height: width of the rectangle
999 * Draws a shadow around the given rectangle in @window
1000 * using the given style and state and shadow type.
1002 * Deprecated: Use gtk_paint_shadow() instead.
1005 gtk_draw_shadow (GtkStyle *style,
1007 GtkStateType state_type,
1008 GtkShadowType shadow_type,
1014 g_return_if_fail (GTK_IS_STYLE (style));
1015 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
1017 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1022 * @style: a #GtkStyle
1023 * @window: a #GdkWindow
1024 * @state_type: a state
1025 * @shadow_type: type of shadow to draw
1026 * @points: an array of #GdkPoint<!-- -->s
1027 * @npoints: length of @points
1028 * @fill: %TRUE if the polygon should be filled
1030 * Draws a polygon on @window with the given parameters.
1032 * Deprecated: Use gtk_paint_polygon() instead.
1035 gtk_draw_polygon (GtkStyle *style,
1037 GtkStateType state_type,
1038 GtkShadowType shadow_type,
1043 g_return_if_fail (GTK_IS_STYLE (style));
1044 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_polygon != NULL);
1046 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, NULL, NULL, NULL, points, npoints, fill);
1051 * @style: a #GtkStyle
1052 * @window: a #GdkWindow
1053 * @state_type: a state
1054 * @shadow_type: the type of shadow to draw
1055 * @arrow_type: the type of arrow to draw
1056 * @fill: %TRUE if the arrow tip should be filled
1057 * @x: x origin of the rectangle to draw the arrow in
1058 * @y: y origin of the rectangle to draw the arrow in
1059 * @width: width of the rectangle to draw the arrow in
1060 * @height: height of the rectangle to draw the arrow in
1062 * Draws an arrow in the given rectangle on @window using the given
1063 * parameters. @arrow_type determines the direction of the arrow.
1065 * Deprecated: Use gtk_paint_arrow() instead.
1068 gtk_draw_arrow (GtkStyle *style,
1070 GtkStateType state_type,
1071 GtkShadowType shadow_type,
1072 GtkArrowType arrow_type,
1079 g_return_if_fail (GTK_IS_STYLE (style));
1080 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
1082 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, NULL, NULL, NULL, arrow_type, fill, x, y, width, height);
1087 * @style: a #GtkStyle
1088 * @window: a #GdkWindow
1089 * @state_type: a state
1090 * @shadow_type: the type of shadow to draw
1091 * @x: x origin of the rectangle to draw the diamond in
1092 * @y: y origin of the rectangle to draw the diamond in
1093 * @width: width of the rectangle to draw the diamond in
1094 * @height: height of the rectangle to draw the diamond in
1096 * Draws a diamond in the given rectangle on @window using the given
1099 * Deprecated: Use gtk_paint_diamond() instead.
1102 gtk_draw_diamond (GtkStyle *style,
1104 GtkStateType state_type,
1105 GtkShadowType shadow_type,
1111 g_return_if_fail (GTK_IS_STYLE (style));
1112 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
1114 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1119 * @style: a #GtkStyle
1120 * @window: a #GdkWindow
1121 * @state_type: a state
1124 * @string: the string to draw
1126 * Draws a text string on @window with the given parameters.
1128 * Deprecated: Use gtk_paint_layout() instead.
1131 gtk_draw_string (GtkStyle *style,
1133 GtkStateType state_type,
1136 const gchar *string)
1138 g_return_if_fail (GTK_IS_STYLE (style));
1139 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
1141 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, NULL, NULL, NULL, x, y, string);
1146 * @style: a #GtkStyle
1147 * @window: a #GdkWindow
1148 * @state_type: a state
1149 * @shadow_type: the type of shadow to draw
1150 * @x: x origin of the box
1151 * @y: y origin of the box
1152 * @width: the width of the box
1153 * @height: the height of the box
1155 * Draws a box on @window with the given parameters.
1157 * Deprecated: Use gtk_paint_box() instead.
1160 gtk_draw_box (GtkStyle *style,
1162 GtkStateType state_type,
1163 GtkShadowType shadow_type,
1169 g_return_if_fail (GTK_IS_STYLE (style));
1170 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
1172 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1176 * gtk_draw_flat_box:
1177 * @style: a #GtkStyle
1178 * @window: a #GdkWindow
1179 * @state_type: a state
1180 * @shadow_type: the type of shadow to draw
1181 * @x: x origin of the box
1182 * @y: y origin of the box
1183 * @width: the width of the box
1184 * @height: the height of the box
1186 * Draws a flat box on @window with the given parameters.
1188 * Deprecated: Use gtk_paint_flat_box() instead.
1191 gtk_draw_flat_box (GtkStyle *style,
1193 GtkStateType state_type,
1194 GtkShadowType shadow_type,
1200 g_return_if_fail (GTK_IS_STYLE (style));
1201 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
1203 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1208 * @style: a #GtkStyle
1209 * @window: a #GdkWindow
1210 * @state_type: a state
1211 * @shadow_type: the type of shadow to draw
1212 * @x: x origin of the rectangle to draw the check in
1213 * @y: y origin of the rectangle to draw the check in
1214 * @width: the width of the rectangle to draw the check in
1215 * @height: the height of the rectangle to draw the check in
1217 * Draws a check button indicator in the given rectangle on @window with
1218 * the given parameters.
1220 * Deprecated: Use gtk_paint_check() instead.
1223 gtk_draw_check (GtkStyle *style,
1225 GtkStateType state_type,
1226 GtkShadowType shadow_type,
1232 g_return_if_fail (GTK_IS_STYLE (style));
1233 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
1235 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1240 * @style: a #GtkStyle
1241 * @window: a #GdkWindow
1242 * @state_type: a state
1243 * @shadow_type: the type of shadow to draw
1244 * @x: x origin of the rectangle to draw the option in
1245 * @y: y origin of the rectangle to draw the option in
1246 * @width: the width of the rectangle to draw the option in
1247 * @height: the height of the rectangle to draw the option in
1249 * Draws a radio button indicator in the given rectangle on @window with
1250 * the given parameters.
1252 * Deprecated: Use gtk_paint_option() instead.
1255 gtk_draw_option (GtkStyle *style,
1257 GtkStateType state_type,
1258 GtkShadowType shadow_type,
1264 g_return_if_fail (GTK_IS_STYLE (style));
1265 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
1267 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1272 * @style: a #GtkStyle
1273 * @window: a #GdkWindow
1274 * @state_type: a state
1275 * @shadow_type: the type of shadow to draw
1276 * @x: x origin of the rectangle to draw the tab in
1277 * @y: y origin of the rectangle to draw the tab in
1278 * @width: the width of the rectangle to draw the tab in
1279 * @height: the height of the rectangle to draw the tab in
1281 * Draws an option menu tab (i.e. the up and down pointing arrows)
1282 * in the given rectangle on @window using the given parameters.
1284 * Deprecated: Use gtk_paint_tab() instead.
1287 gtk_draw_tab (GtkStyle *style,
1289 GtkStateType state_type,
1290 GtkShadowType shadow_type,
1296 g_return_if_fail (GTK_IS_STYLE (style));
1297 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
1299 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1303 * gtk_draw_shadow_gap:
1304 * @style: a #GtkStyle
1305 * @window: a #GdkWindow
1306 * @state_type: a state
1307 * @shadow_type: type of shadow to draw
1308 * @x: x origin of the rectangle
1309 * @y: y origin of the rectangle
1310 * @width: width of the rectangle
1311 * @height: width of the rectangle
1312 * @gap_side: side in which to leave the gap
1313 * @gap_x: starting position of the gap
1314 * @gap_width: width of the gap
1316 * Draws a shadow around the given rectangle in @window
1317 * using the given style and state and shadow type, leaving a
1320 * Deprecated: Use gtk_paint_shadow_gap() instead.
1323 gtk_draw_shadow_gap (GtkStyle *style,
1325 GtkStateType state_type,
1326 GtkShadowType shadow_type,
1331 GtkPositionType gap_side,
1335 g_return_if_fail (GTK_IS_STYLE (style));
1336 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
1338 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);
1343 * @style: a #GtkStyle
1344 * @window: a #GdkWindow
1345 * @state_type: a state
1346 * @shadow_type: type of shadow to draw
1347 * @x: x origin of the rectangle
1348 * @y: y origin of the rectangle
1349 * @width: width of the rectangle
1350 * @height: width of the rectangle
1351 * @gap_side: side in which to leave the gap
1352 * @gap_x: starting position of the gap
1353 * @gap_width: width of the gap
1355 * Draws a box in @window using the given style and state and shadow type,
1356 * leaving a gap in one side.
1358 * Deprecated: Use gtk_paint_box_gap() instead.
1361 gtk_draw_box_gap (GtkStyle *style,
1363 GtkStateType state_type,
1364 GtkShadowType shadow_type,
1369 GtkPositionType gap_side,
1373 g_return_if_fail (GTK_IS_STYLE (style));
1374 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
1376 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);
1380 * gtk_draw_extension:
1381 * @style: a #GtkStyle
1382 * @window: a #GdkWindow
1383 * @state_type: a state
1384 * @shadow_type: type of shadow to draw
1385 * @x: x origin of the extension
1386 * @y: y origin of the extension
1387 * @width: width of the extension
1388 * @height: width of the extension
1389 * @gap_side: the side on to which the extension is attached
1391 * Draws an extension, i.e. a notebook tab.
1393 * Deprecated: Use gtk_paint_extension() instead.
1396 gtk_draw_extension (GtkStyle *style,
1398 GtkStateType state_type,
1399 GtkShadowType shadow_type,
1404 GtkPositionType gap_side)
1406 g_return_if_fail (GTK_IS_STYLE (style));
1407 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
1409 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side);
1414 * @style: a #GtkStyle
1415 * @window: a #GdkWindow
1416 * @x: the x origin of the rectangle around which to draw a focus indicator
1417 * @y: the y origin of the rectangle around which to draw a focus indicator
1418 * @width: the width of the rectangle around which to draw a focus indicator
1419 * @height: the height of the rectangle around which to draw a focus indicator
1421 * Draws a focus indicator around the given rectangle on @window using the
1424 * Deprecated: Use gtk_paint_focus() instead.
1427 gtk_draw_focus (GtkStyle *style,
1434 g_return_if_fail (GTK_IS_STYLE (style));
1435 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
1437 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, GTK_STATE_NORMAL, NULL, NULL, NULL, x, y, width, height);
1441 gtk_draw_slider (GtkStyle *style,
1443 GtkStateType state_type,
1444 GtkShadowType shadow_type,
1449 GtkOrientation orientation)
1451 g_return_if_fail (GTK_IS_STYLE (style));
1452 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
1454 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
1459 * @style: a #GtkStyle
1460 * @window: a #GdkWindow
1461 * @state_type: a state
1462 * @shadow_type: type of shadow to draw
1463 * @x: x origin of the handle
1464 * @y: y origin of the handle
1465 * @width: with of the handle
1466 * @height: height of the handle
1467 * @orientation: the orientation of the handle
1469 * Draws a handle as used in #GtkHandleBox and #GtkPaned.
1471 * Deprecated: Use gtk_paint_handle() instead.
1474 gtk_draw_handle (GtkStyle *style,
1476 GtkStateType state_type,
1477 GtkShadowType shadow_type,
1482 GtkOrientation orientation)
1484 g_return_if_fail (GTK_IS_STYLE (style));
1485 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
1487 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
1491 * gtk_draw_expander:
1492 * @style: a #GtkStyle
1493 * @window: a #GdkWindow
1494 * @state_type: a state
1495 * @x: the x position to draw the expander at
1496 * @y: the y position to draw the expander at
1497 * @expander_style: the style to draw the expander in
1499 * Draws an expander as used in #GtkTreeView.
1501 * Deprecated: Use gtk_paint_expander() instead.
1504 gtk_draw_expander (GtkStyle *style,
1506 GtkStateType state_type,
1509 GtkExpanderStyle expander_style)
1511 g_return_if_fail (GTK_IS_STYLE (style));
1512 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
1514 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type,
1516 x, y, expander_style);
1520 gtk_draw_layout (GtkStyle *style,
1522 GtkStateType state_type,
1526 PangoLayout *layout)
1528 g_return_if_fail (GTK_IS_STYLE (style));
1529 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
1531 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text,
1537 * gtk_draw_resize_grip:
1538 * @style: a #GtkStyle
1539 * @window: a #GdkWindow
1540 * @state_type: a state
1541 * @edge: the edge in which to draw the resize grip
1542 * @x: the x origin of the rectangle in which to draw the resize grip
1543 * @y: the y origin of the rectangle in which to draw the resize grip
1544 * @width: the width of the rectangle in which to draw the resize grip
1545 * @height: the height of the rectangle in which to draw the resize grip
1547 * Draws a resize grip in the given rectangle on @window using the given
1550 * Deprecated: Use gtk_paint_resize_grip() instead.
1553 gtk_draw_resize_grip (GtkStyle *style,
1555 GtkStateType state_type,
1562 g_return_if_fail (GTK_IS_STYLE (style));
1563 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
1565 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
1568 x, y, width, height);
1573 * gtk_style_set_background:
1574 * @style: a #GtkStyle
1575 * @window: a #GdkWindow
1576 * @state_type: a state
1578 * Sets the background of @window to the background color or pixmap
1579 * specified by @style for the given state.
1582 gtk_style_set_background (GtkStyle *style,
1584 GtkStateType state_type)
1586 g_return_if_fail (GTK_IS_STYLE (style));
1587 g_return_if_fail (window != NULL);
1589 GTK_STYLE_GET_CLASS (style)->set_background (style, window, state_type);
1592 /* Default functions */
1594 gtk_style_real_clone (GtkStyle *style)
1596 return GTK_STYLE (g_object_new (G_OBJECT_TYPE (style), NULL));
1600 gtk_style_real_copy (GtkStyle *style,
1605 for (i = 0; i < 5; i++)
1607 style->fg[i] = src->fg[i];
1608 style->bg[i] = src->bg[i];
1609 style->text[i] = src->text[i];
1610 style->base[i] = src->base[i];
1612 style->bg_pixmap[i] = src->bg_pixmap[i];
1615 if (style->private_font)
1616 gdk_font_unref (style->private_font);
1617 style->private_font = src->private_font;
1618 if (style->private_font)
1619 gdk_font_ref (style->private_font);
1621 if (style->font_desc)
1622 pango_font_description_free (style->font_desc);
1624 style->font_desc = pango_font_description_copy (src->font_desc);
1626 style->font_desc = NULL;
1628 style->xthickness = src->xthickness;
1629 style->ythickness = src->ythickness;
1631 if (style->rc_style)
1632 gtk_rc_style_unref (style->rc_style);
1633 style->rc_style = src->rc_style;
1635 gtk_rc_style_ref (src->rc_style);
1637 /* don't copy, just clear cache */
1638 clear_property_cache (style);
1642 gtk_style_real_init_from_rc (GtkStyle *style,
1643 GtkRcStyle *rc_style)
1647 /* cache _should_ be still empty */
1648 clear_property_cache (style);
1650 if (rc_style->font_desc)
1651 pango_font_description_merge (style->font_desc, rc_style->font_desc, TRUE);
1653 for (i = 0; i < 5; i++)
1655 if (rc_style->color_flags[i] & GTK_RC_FG)
1656 style->fg[i] = rc_style->fg[i];
1657 if (rc_style->color_flags[i] & GTK_RC_BG)
1658 style->bg[i] = rc_style->bg[i];
1659 if (rc_style->color_flags[i] & GTK_RC_TEXT)
1660 style->text[i] = rc_style->text[i];
1661 if (rc_style->color_flags[i] & GTK_RC_BASE)
1662 style->base[i] = rc_style->base[i];
1665 if (rc_style->xthickness >= 0)
1666 style->xthickness = rc_style->xthickness;
1667 if (rc_style->ythickness >= 0)
1668 style->ythickness = rc_style->ythickness;
1670 if (rc_style->icon_factories)
1674 style->icon_factories = g_slist_copy (rc_style->icon_factories);
1676 iter = style->icon_factories;
1677 while (iter != NULL)
1679 g_object_ref (iter->data);
1680 iter = g_slist_next (iter);
1686 style_property_values_cmp (gconstpointer bsearch_node1,
1687 gconstpointer bsearch_node2)
1689 const PropertyValue *val1 = bsearch_node1;
1690 const PropertyValue *val2 = bsearch_node2;
1692 if (val1->widget_type == val2->widget_type)
1693 return val1->pspec < val2->pspec ? -1 : val1->pspec == val2->pspec ? 0 : 1;
1695 return val1->widget_type < val2->widget_type ? -1 : 1;
1699 _gtk_style_peek_property_value (GtkStyle *style,
1702 GtkRcPropertyParser parser)
1704 PropertyValue *pcache, key = { 0, NULL, { 0, } };
1705 const GtkRcProperty *rcprop = NULL;
1708 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1709 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), NULL);
1710 g_return_val_if_fail (g_type_is_a (pspec->owner_type, GTK_TYPE_WIDGET), NULL);
1711 g_return_val_if_fail (g_type_is_a (widget_type, pspec->owner_type), NULL);
1713 key.widget_type = widget_type;
1716 /* need value cache array */
1717 if (!style->property_cache)
1718 style->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
1721 pcache = bsearch (&key,
1722 style->property_cache->data, style->property_cache->len,
1723 sizeof (PropertyValue), style_property_values_cmp);
1725 return &pcache->value;
1729 while (i < style->property_cache->len &&
1730 style_property_values_cmp (&key, &g_array_index (style->property_cache, PropertyValue, i)) >= 0)
1733 g_array_insert_val (style->property_cache, i, key);
1734 pcache = &g_array_index (style->property_cache, PropertyValue, i);
1736 /* cache miss, initialize value type, then set contents */
1737 g_param_spec_ref (pcache->pspec);
1738 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1740 /* value provided by rc style? */
1741 if (style->rc_style)
1743 GQuark prop_quark = g_quark_from_string (pspec->name);
1747 rcprop = _gtk_rc_style_lookup_rc_property (style->rc_style,
1748 g_type_qname (widget_type),
1752 widget_type = g_type_parent (widget_type);
1754 while (g_type_is_a (widget_type, pspec->owner_type));
1757 /* when supplied by rc style, we need to convert */
1758 if (rcprop && !_gtk_settings_parse_convert (parser, &rcprop->value,
1759 pspec, &pcache->value))
1761 gchar *contents = g_strdup_value_contents (&rcprop->value);
1763 g_message ("%s: failed to retrieve property `%s::%s' of type `%s' from rc file value \"%s\" of type `%s'",
1765 g_type_name (pspec->owner_type), pspec->name,
1766 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1768 G_VALUE_TYPE_NAME (&rcprop->value));
1770 rcprop = NULL; /* needs default */
1773 /* not supplied by rc style (or conversion failed), revert to default */
1775 g_param_value_set_default (pspec, &pcache->value);
1777 return &pcache->value;
1781 load_bg_image (GdkColormap *colormap,
1783 const gchar *filename)
1785 if (strcmp (filename, "<parent>") == 0)
1786 return (GdkPixmap*) GDK_PARENT_RELATIVE;
1789 return gdk_pixmap_colormap_create_from_xpm (NULL, colormap, NULL,
1796 gtk_style_real_realize (GtkStyle *style)
1798 GdkGCValues gc_values;
1799 GdkGCValuesMask gc_values_mask;
1803 for (i = 0; i < 5; i++)
1805 gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT);
1806 gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT);
1808 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
1809 style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
1810 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
1812 style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
1813 style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
1814 style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;
1817 style->black.red = 0x0000;
1818 style->black.green = 0x0000;
1819 style->black.blue = 0x0000;
1820 gdk_colormap_alloc_color (style->colormap, &style->black, FALSE, TRUE);
1822 style->white.red = 0xffff;
1823 style->white.green = 0xffff;
1824 style->white.blue = 0xffff;
1825 gdk_colormap_alloc_color (style->colormap, &style->white, FALSE, TRUE);
1827 gc_values_mask = GDK_GC_FOREGROUND;
1829 gc_values.foreground = style->black;
1830 style->black_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1832 gc_values.foreground = style->white;
1833 style->white_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1835 for (i = 0; i < 5; i++)
1837 if (style->rc_style && style->rc_style->bg_pixmap_name[i])
1838 style->bg_pixmap[i] = load_bg_image (style->colormap,
1840 style->rc_style->bg_pixmap_name[i]);
1842 if (!gdk_colormap_alloc_color (style->colormap, &style->fg[i], FALSE, TRUE))
1843 g_warning ("unable to allocate color: ( %d %d %d )",
1844 style->fg[i].red, style->fg[i].green, style->fg[i].blue);
1845 if (!gdk_colormap_alloc_color (style->colormap, &style->bg[i], FALSE, TRUE))
1846 g_warning ("unable to allocate color: ( %d %d %d )",
1847 style->bg[i].red, style->bg[i].green, style->bg[i].blue);
1848 if (!gdk_colormap_alloc_color (style->colormap, &style->light[i], FALSE, TRUE))
1849 g_warning ("unable to allocate color: ( %d %d %d )",
1850 style->light[i].red, style->light[i].green, style->light[i].blue);
1851 if (!gdk_colormap_alloc_color (style->colormap, &style->dark[i], FALSE, TRUE))
1852 g_warning ("unable to allocate color: ( %d %d %d )",
1853 style->dark[i].red, style->dark[i].green, style->dark[i].blue);
1854 if (!gdk_colormap_alloc_color (style->colormap, &style->mid[i], FALSE, TRUE))
1855 g_warning ("unable to allocate color: ( %d %d %d )",
1856 style->mid[i].red, style->mid[i].green, style->mid[i].blue);
1857 if (!gdk_colormap_alloc_color (style->colormap, &style->text[i], FALSE, TRUE))
1858 g_warning ("unable to allocate color: ( %d %d %d )",
1859 style->text[i].red, style->text[i].green, style->text[i].blue);
1860 if (!gdk_colormap_alloc_color (style->colormap, &style->base[i], FALSE, TRUE))
1861 g_warning ("unable to allocate color: ( %d %d %d )",
1862 style->base[i].red, style->base[i].green, style->base[i].blue);
1863 if (!gdk_colormap_alloc_color (style->colormap, &style->text_aa[i], FALSE, TRUE))
1864 g_warning ("unable to allocate color: ( %d %d %d )",
1865 style->text_aa[i].red, style->text_aa[i].green, style->text_aa[i].blue);
1867 gc_values.foreground = style->fg[i];
1868 style->fg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1870 gc_values.foreground = style->bg[i];
1871 style->bg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1873 gc_values.foreground = style->light[i];
1874 style->light_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1876 gc_values.foreground = style->dark[i];
1877 style->dark_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1879 gc_values.foreground = style->mid[i];
1880 style->mid_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1882 gc_values.foreground = style->text[i];
1883 style->text_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1885 gc_values.foreground = style->base[i];
1886 style->base_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1888 gc_values.foreground = style->text_aa[i];
1889 style->text_aa_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1894 gtk_style_real_unrealize (GtkStyle *style)
1898 gtk_gc_release (style->black_gc);
1899 gtk_gc_release (style->white_gc);
1901 for (i = 0; i < 5; i++)
1903 gtk_gc_release (style->fg_gc[i]);
1904 gtk_gc_release (style->bg_gc[i]);
1905 gtk_gc_release (style->light_gc[i]);
1906 gtk_gc_release (style->dark_gc[i]);
1907 gtk_gc_release (style->mid_gc[i]);
1908 gtk_gc_release (style->text_gc[i]);
1909 gtk_gc_release (style->base_gc[i]);
1910 gtk_gc_release (style->text_aa_gc[i]);
1912 if (style->bg_pixmap[i] && style->bg_pixmap[i] != (GdkPixmap*) GDK_PARENT_RELATIVE)
1913 g_object_unref (style->bg_pixmap[i]);
1916 gdk_colormap_free_colors (style->colormap, style->fg, 5);
1917 gdk_colormap_free_colors (style->colormap, style->bg, 5);
1918 gdk_colormap_free_colors (style->colormap, style->light, 5);
1919 gdk_colormap_free_colors (style->colormap, style->dark, 5);
1920 gdk_colormap_free_colors (style->colormap, style->mid, 5);
1921 gdk_colormap_free_colors (style->colormap, style->text, 5);
1922 gdk_colormap_free_colors (style->colormap, style->base, 5);
1923 gdk_colormap_free_colors (style->colormap, style->text_aa, 5);
1925 style_unrealize_cursor_gcs (style);
1929 gtk_style_real_set_background (GtkStyle *style,
1931 GtkStateType state_type)
1934 gint parent_relative;
1936 if (style->bg_pixmap[state_type])
1938 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1941 parent_relative = TRUE;
1945 pixmap = style->bg_pixmap[state_type];
1946 parent_relative = FALSE;
1949 gdk_window_set_back_pixmap (window, pixmap, parent_relative);
1952 gdk_window_set_background (window, &style->bg[state_type]);
1956 * gtk_style_render_icon:
1957 * @style: a #GtkStyle
1958 * @source: the #GtkIconSource specifying the icon to render
1959 * @direction: a text direction
1961 * @size: the size to render the icon at. A size of (GtkIconSize)-1
1962 * means render at the size of the source and don't scale.
1963 * @widget: the widget
1964 * @detail: a style detail
1965 * @returns: a newly-created #GdkPixbuf containing the rendered icon
1967 * Renders the icon specified by @source at the given @size
1968 * according to the given parameters and returns the result in a
1972 gtk_style_render_icon (GtkStyle *style,
1973 const GtkIconSource *source,
1974 GtkTextDirection direction,
1978 const gchar *detail)
1982 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1983 g_return_val_if_fail (GTK_STYLE_GET_CLASS (style)->render_icon != NULL, NULL);
1985 pixbuf = GTK_STYLE_GET_CLASS (style)->render_icon (style, source, direction, state,
1986 size, widget, detail);
1988 g_return_val_if_fail (pixbuf != NULL, NULL);
1993 /* Default functions */
1995 gtk_style_apply_default_background (GtkStyle *style,
1998 GtkStateType state_type,
2005 GdkRectangle new_rect, old_rect;
2011 old_rect.width = width;
2012 old_rect.height = height;
2014 if (!gdk_rectangle_intersect (area, &old_rect, &new_rect))
2021 new_rect.width = width;
2022 new_rect.height = height;
2025 if (!style->bg_pixmap[state_type] ||
2026 GDK_IS_PIXMAP (window) ||
2027 (!set_bg && style->bg_pixmap[state_type] != (GdkPixmap*) GDK_PARENT_RELATIVE))
2029 GdkGC *gc = style->bg_gc[state_type];
2031 if (style->bg_pixmap[state_type])
2033 gdk_gc_set_fill (gc, GDK_TILED);
2034 gdk_gc_set_tile (gc, style->bg_pixmap[state_type]);
2037 gdk_draw_rectangle (window, gc, TRUE,
2038 new_rect.x, new_rect.y, new_rect.width, new_rect.height);
2039 if (style->bg_pixmap[state_type])
2040 gdk_gc_set_fill (gc, GDK_SOLID);
2046 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
2047 gdk_window_set_back_pixmap (window, NULL, TRUE);
2049 gdk_window_set_back_pixmap (window, style->bg_pixmap[state_type], FALSE);
2052 gdk_window_clear_area (window,
2053 new_rect.x, new_rect.y,
2054 new_rect.width, new_rect.height);
2059 scale_or_ref (GdkPixbuf *src,
2063 if (width == gdk_pixbuf_get_width (src) &&
2064 height == gdk_pixbuf_get_height (src))
2066 return g_object_ref (src);
2070 return gdk_pixbuf_scale_simple (src,
2072 GDK_INTERP_BILINEAR);
2077 gtk_default_render_icon (GtkStyle *style,
2078 const GtkIconSource *source,
2079 GtkTextDirection direction,
2083 const gchar *detail)
2089 GdkPixbuf *base_pixbuf;
2091 GtkSettings *settings;
2093 /* Oddly, style can be NULL in this function, because
2094 * GtkIconSet can be used without a style and if so
2095 * it uses this function.
2098 base_pixbuf = gtk_icon_source_get_pixbuf (source);
2100 g_return_val_if_fail (base_pixbuf != NULL, NULL);
2102 if (widget && gtk_widget_has_screen (widget))
2104 screen = gtk_widget_get_screen (widget);
2105 settings = gtk_settings_get_for_screen (screen);
2107 else if (style->colormap)
2109 screen = gdk_colormap_get_screen (style->colormap);
2110 settings = gtk_settings_get_for_screen (screen);
2114 settings = gtk_settings_get_default ();
2115 GTK_NOTE (MULTIHEAD,
2116 g_warning ("Using the default screen for gtk_default_render_icon()"));
2120 if (size != (GtkIconSize) -1 && !gtk_icon_size_lookup_for_settings (settings, size, &width, &height))
2122 g_warning (G_STRLOC ": invalid icon size '%d'", size);
2126 /* If the size was wildcarded, and we're allowed to scale, then scale; otherwise,
2129 if (size != (GtkIconSize)-1 && gtk_icon_source_get_size_wildcarded (source))
2130 scaled = scale_or_ref (base_pixbuf, width, height);
2132 scaled = g_object_ref (base_pixbuf);
2134 /* If the state was wildcarded, then generate a state. */
2135 if (gtk_icon_source_get_state_wildcarded (source))
2137 if (state == GTK_STATE_INSENSITIVE)
2139 stated = gdk_pixbuf_copy (scaled);
2141 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
2144 g_object_unref (scaled);
2146 else if (state == GTK_STATE_PRELIGHT)
2148 stated = gdk_pixbuf_copy (scaled);
2150 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
2153 g_object_unref (scaled);
2167 sanitize_size (GdkWindow *window,
2171 if ((*width == -1) && (*height == -1))
2172 gdk_drawable_get_size (window, width, height);
2173 else if (*width == -1)
2174 gdk_drawable_get_size (window, width, NULL);
2175 else if (*height == -1)
2176 gdk_drawable_get_size (window, NULL, height);
2180 get_indicator_for_screen (GdkDrawable *drawable,
2184 GdkScreen *screen = gdk_drawable_get_screen (drawable);
2188 tmp_list = indicator_parts[part].bmap_list;
2191 bitmap = tmp_list->data;
2193 if (gdk_drawable_get_screen (bitmap) == screen)
2196 tmp_list = tmp_list->next;
2199 bitmap = gdk_bitmap_create_from_data (drawable,
2200 (gchar *)indicator_parts[part].bits,
2201 INDICATOR_PART_SIZE, INDICATOR_PART_SIZE);
2202 indicator_parts[part].bmap_list = g_list_prepend (indicator_parts[part].bmap_list, bitmap);
2208 draw_part (GdkDrawable *drawable,
2216 gdk_gc_set_clip_rectangle (gc, area);
2218 gdk_gc_set_ts_origin (gc, x, y);
2219 gdk_gc_set_stipple (gc, get_indicator_for_screen (drawable, part));
2220 gdk_gc_set_fill (gc, GDK_STIPPLED);
2222 gdk_draw_rectangle (drawable, gc, TRUE, x, y, INDICATOR_PART_SIZE, INDICATOR_PART_SIZE);
2224 gdk_gc_set_fill (gc, GDK_SOLID);
2227 gdk_gc_set_clip_rectangle (gc, NULL);
2231 gtk_default_draw_hline (GtkStyle *style,
2233 GtkStateType state_type,
2236 const gchar *detail,
2241 gint thickness_light;
2242 gint thickness_dark;
2245 g_return_if_fail (GTK_IS_STYLE (style));
2246 g_return_if_fail (window != NULL);
2248 thickness_light = style->ythickness / 2;
2249 thickness_dark = style->ythickness - thickness_light;
2253 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
2254 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
2257 if (detail && !strcmp (detail, "label"))
2259 if (state_type == GTK_STATE_INSENSITIVE)
2260 gdk_draw_line (window, style->white_gc, x1 + 1, y + 1, x2 + 1, y + 1);
2261 gdk_draw_line (window, style->fg_gc[state_type], x1, y, x2, y);
2265 for (i = 0; i < thickness_dark; i++)
2267 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x2 - i - 1, y + i);
2268 gdk_draw_line (window, style->light_gc[state_type], x2 - i, y + i, x2, y + i);
2271 y += thickness_dark;
2272 for (i = 0; i < thickness_light; i++)
2274 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x1 + thickness_light - i - 1, y + i);
2275 gdk_draw_line (window, style->light_gc[state_type], x1 + thickness_light - i, y + i, x2, y + i);
2281 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
2282 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
2288 gtk_default_draw_vline (GtkStyle *style,
2290 GtkStateType state_type,
2293 const gchar *detail,
2298 gint thickness_light;
2299 gint thickness_dark;
2302 g_return_if_fail (GTK_IS_STYLE (style));
2303 g_return_if_fail (window != NULL);
2305 thickness_light = style->xthickness / 2;
2306 thickness_dark = style->xthickness - thickness_light;
2310 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
2311 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
2313 for (i = 0; i < thickness_dark; i++)
2315 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y2 - i - 1);
2316 gdk_draw_line (window, style->light_gc[state_type], x + i, y2 - i, x + i, y2);
2319 x += thickness_dark;
2320 for (i = 0; i < thickness_light; i++)
2322 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y1 + thickness_light - i - 1);
2323 gdk_draw_line (window, style->light_gc[state_type], x + i, y1 + thickness_light - i, x + i, y2);
2327 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
2328 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
2333 draw_thin_shadow (GtkStyle *style,
2344 sanitize_size (window, &width, &height);
2346 gc1 = style->light_gc[state];
2347 gc2 = style->dark_gc[state];
2351 gdk_gc_set_clip_rectangle (gc1, area);
2352 gdk_gc_set_clip_rectangle (gc2, area);
2355 gdk_draw_line (window, gc1,
2356 x, y + height - 1, x + width - 1, y + height - 1);
2357 gdk_draw_line (window, gc1,
2358 x + width - 1, y, x + width - 1, y + height - 1);
2360 gdk_draw_line (window, gc2,
2361 x, y, x + width - 2, y);
2362 gdk_draw_line (window, gc2,
2363 x, y, x, y + height - 2);
2367 gdk_gc_set_clip_rectangle (gc1, NULL);
2368 gdk_gc_set_clip_rectangle (gc2, NULL);
2373 draw_spinbutton_shadow (GtkStyle *style,
2376 GtkTextDirection direction,
2383 sanitize_size (window, &width, &height);
2387 gdk_gc_set_clip_rectangle (style->black_gc, area);
2388 gdk_gc_set_clip_rectangle (style->bg_gc[state], area);
2389 gdk_gc_set_clip_rectangle (style->dark_gc[state], area);
2390 gdk_gc_set_clip_rectangle (style->light_gc[state], area);
2393 if (direction == GTK_TEXT_DIR_LTR)
2395 gdk_draw_line (window, style->dark_gc[state],
2396 x, y, x + width - 1, y);
2397 gdk_draw_line (window, style->black_gc,
2398 x, y + 1, x + width - 2, y + 1);
2399 gdk_draw_line (window, style->black_gc,
2400 x + width - 2, y + 2, x + width - 2, y + height - 3);
2401 gdk_draw_line (window, style->light_gc[state],
2402 x + width - 1, y + 1, x + width - 1, y + height - 2);
2403 gdk_draw_line (window, style->light_gc[state],
2404 x, y + height - 1, x + width - 1, y + height - 1);
2405 gdk_draw_line (window, style->bg_gc[state],
2406 x, y + height - 2, x + width - 2, y + height - 2);
2407 gdk_draw_line (window, style->black_gc,
2408 x, y + 2, x, y + height - 3);
2412 gdk_draw_line (window, style->dark_gc[state],
2413 x, y, x + width - 1, y);
2414 gdk_draw_line (window, style->dark_gc[state],
2415 x, y + 1, x, y + height - 1);
2416 gdk_draw_line (window, style->black_gc,
2417 x + 1, y + 1, x + width - 1, y + 1);
2418 gdk_draw_line (window, style->black_gc,
2419 x + 1, y + 2, x + 1, y + height - 2);
2420 gdk_draw_line (window, style->black_gc,
2421 x + width - 1, y + 2, x + width - 1, y + height - 3);
2422 gdk_draw_line (window, style->light_gc[state],
2423 x + 1, y + height - 1, x + width - 1, y + height - 1);
2424 gdk_draw_line (window, style->bg_gc[state],
2425 x + 2, y + height - 2, x + width - 1, y + height - 2);
2430 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2431 gdk_gc_set_clip_rectangle (style->bg_gc[state], NULL);
2432 gdk_gc_set_clip_rectangle (style->dark_gc[state], NULL);
2433 gdk_gc_set_clip_rectangle (style->light_gc[state], NULL);
2438 draw_menu_shadow (GtkStyle *style,
2447 if (style->ythickness > 0)
2449 if (style->ythickness > 1)
2451 gdk_draw_line (window, style->dark_gc[state],
2452 x + 1, y + height - 2, x + width - 2, y + height - 2);
2453 gdk_draw_line (window, style->black_gc,
2454 x, y + height - 1, x + width - 1, y + height - 1);
2458 gdk_draw_line (window, style->dark_gc[state],
2459 x + 1, y + height - 1, x + width - 1, y + height - 1);
2463 if (style->xthickness > 0)
2465 if (style->xthickness > 1)
2467 gdk_draw_line (window, style->dark_gc[state],
2468 x + width - 2, y + 1, x + width - 2, y + height - 2);
2470 gdk_draw_line (window, style->black_gc,
2471 x + width - 1, y, x + width - 1, y + height - 1);
2475 gdk_draw_line (window, style->dark_gc[state],
2476 x + width - 1, y + 1, x + width - 1, y + height - 1);
2480 /* Light around top and left */
2482 if (style->ythickness > 0)
2483 gdk_draw_line (window, style->black_gc,
2484 x, y, x + width - 2, y);
2485 if (style->xthickness > 0)
2486 gdk_draw_line (window, style->black_gc,
2487 x, y, x, y + height - 2);
2489 if (style->ythickness > 1)
2490 gdk_draw_line (window, style->light_gc[state],
2491 x + 1, y + 1, x + width - 3, y + 1);
2492 if (style->xthickness > 1)
2493 gdk_draw_line (window, style->light_gc[state],
2494 x + 1, y + 1, x + 1, y + height - 3);
2498 gtk_default_draw_shadow (GtkStyle *style,
2500 GtkStateType state_type,
2501 GtkShadowType shadow_type,
2504 const gchar *detail,
2512 gint thickness_light;
2513 gint thickness_dark;
2516 g_return_if_fail (GTK_IS_STYLE (style));
2517 g_return_if_fail (window != NULL);
2519 if (shadow_type == GTK_SHADOW_IN)
2521 if (detail && (strcmp (detail, "buttondefault") == 0))
2523 sanitize_size (window, &width, &height);
2525 gdk_draw_rectangle (window, style->black_gc, FALSE,
2526 x, y, width - 1, height - 1);
2530 if (detail && strcmp (detail, "trough") == 0)
2532 draw_thin_shadow (style, window, state_type, area,
2533 x, y, width, height);
2536 if (widget && GTK_IS_SPIN_BUTTON (widget) &&
2537 detail && strcmp (detail, "spinbutton") == 0)
2539 draw_spinbutton_shadow (style, window, state_type,
2540 gtk_widget_get_direction (widget), area, x, y, width, height);
2546 if (shadow_type == GTK_SHADOW_OUT && detail && strcmp (detail, "menu") == 0)
2548 draw_menu_shadow (style, window, state_type, area, x, y, width, height);
2552 sanitize_size (window, &width, &height);
2554 switch (shadow_type)
2556 case GTK_SHADOW_NONE:
2559 case GTK_SHADOW_ETCHED_IN:
2560 gc1 = style->light_gc[state_type];
2561 gc2 = style->dark_gc[state_type];
2563 case GTK_SHADOW_OUT:
2564 case GTK_SHADOW_ETCHED_OUT:
2565 gc1 = style->dark_gc[state_type];
2566 gc2 = style->light_gc[state_type];
2572 gdk_gc_set_clip_rectangle (gc1, area);
2573 gdk_gc_set_clip_rectangle (gc2, area);
2574 if (shadow_type == GTK_SHADOW_IN ||
2575 shadow_type == GTK_SHADOW_OUT)
2577 gdk_gc_set_clip_rectangle (style->black_gc, area);
2578 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2582 switch (shadow_type)
2584 case GTK_SHADOW_NONE:
2588 /* Light around right and bottom edge */
2590 if (style->ythickness > 0)
2591 gdk_draw_line (window, gc1,
2592 x, y + height - 1, x + width - 1, y + height - 1);
2593 if (style->xthickness > 0)
2594 gdk_draw_line (window, gc1,
2595 x + width - 1, y, x + width - 1, y + height - 1);
2597 if (style->ythickness > 1)
2598 gdk_draw_line (window, style->bg_gc[state_type],
2599 x + 1, y + height - 2, x + width - 2, y + height - 2);
2600 if (style->xthickness > 1)
2601 gdk_draw_line (window, style->bg_gc[state_type],
2602 x + width - 2, y + 1, x + width - 2, y + height - 2);
2604 /* Dark around left and top */
2606 if (style->ythickness > 1)
2607 gdk_draw_line (window, style->black_gc,
2608 x + 1, y + 1, x + width - 2, y + 1);
2609 if (style->xthickness > 1)
2610 gdk_draw_line (window, style->black_gc,
2611 x + 1, y + 1, x + 1, y + height - 2);
2613 if (style->ythickness > 0)
2614 gdk_draw_line (window, gc2,
2615 x, y, x + width - 1, y);
2616 if (style->xthickness > 0)
2617 gdk_draw_line (window, gc2,
2618 x, y, x, y + height - 1);
2621 case GTK_SHADOW_OUT:
2622 /* Dark around right and bottom edge */
2624 if (style->ythickness > 0)
2626 if (style->ythickness > 1)
2628 gdk_draw_line (window, gc1,
2629 x + 1, y + height - 2, x + width - 2, y + height - 2);
2630 gdk_draw_line (window, style->black_gc,
2631 x, y + height - 1, x + width - 1, y + height - 1);
2635 gdk_draw_line (window, gc1,
2636 x + 1, y + height - 1, x + width - 1, y + height - 1);
2640 if (style->xthickness > 0)
2642 if (style->xthickness > 1)
2644 gdk_draw_line (window, gc1,
2645 x + width - 2, y + 1, x + width - 2, y + height - 2);
2647 gdk_draw_line (window, style->black_gc,
2648 x + width - 1, y, x + width - 1, y + height - 1);
2652 gdk_draw_line (window, gc1,
2653 x + width - 1, y + 1, x + width - 1, y + height - 1);
2657 /* Light around top and left */
2659 if (style->ythickness > 0)
2660 gdk_draw_line (window, gc2,
2661 x, y, x + width - 2, y);
2662 if (style->xthickness > 0)
2663 gdk_draw_line (window, gc2,
2664 x, y, x, y + height - 2);
2666 if (style->ythickness > 1)
2667 gdk_draw_line (window, style->bg_gc[state_type],
2668 x + 1, y + 1, x + width - 3, y + 1);
2669 if (style->xthickness > 1)
2670 gdk_draw_line (window, style->bg_gc[state_type],
2671 x + 1, y + 1, x + 1, y + height - 3);
2674 case GTK_SHADOW_ETCHED_IN:
2675 case GTK_SHADOW_ETCHED_OUT:
2676 if (style->xthickness > 0)
2678 if (style->xthickness > 1)
2680 thickness_light = 1;
2683 for (i = 0; i < thickness_dark; i++)
2685 gdk_draw_line (window, gc1,
2689 y + height - i - 1);
2690 gdk_draw_line (window, gc2,
2694 y + height - i - 2);
2697 for (i = 0; i < thickness_light; i++)
2699 gdk_draw_line (window, gc1,
2700 x + thickness_dark + i,
2701 y + thickness_dark + i,
2702 x + thickness_dark + i,
2703 y + height - thickness_dark - i - 1);
2704 gdk_draw_line (window, gc2,
2705 x + width - thickness_light - i - 1,
2706 y + thickness_dark + i,
2707 x + width - thickness_light - i - 1,
2708 y + height - thickness_light - 1);
2713 gdk_draw_line (window,
2714 style->dark_gc[state_type],
2715 x, y, x, y + height);
2716 gdk_draw_line (window,
2717 style->dark_gc[state_type],
2718 x + width, y, x + width, y + height);
2722 if (style->ythickness > 0)
2724 if (style->ythickness > 1)
2726 thickness_light = 1;
2729 for (i = 0; i < thickness_dark; i++)
2731 gdk_draw_line (window, gc1,
2735 y + height - i - 1);
2737 gdk_draw_line (window, gc2,
2744 for (i = 0; i < thickness_light; i++)
2746 gdk_draw_line (window, gc1,
2747 x + thickness_dark + i,
2748 y + thickness_dark + i,
2749 x + width - thickness_dark - i - 2,
2750 y + thickness_dark + i);
2752 gdk_draw_line (window, gc2,
2753 x + thickness_dark + i,
2754 y + height - thickness_light - i - 1,
2755 x + width - thickness_light - 1,
2756 y + height - thickness_light - i - 1);
2761 gdk_draw_line (window,
2762 style->dark_gc[state_type],
2763 x, y, x + width, y);
2764 gdk_draw_line (window,
2765 style->dark_gc[state_type],
2766 x, y + height, x + width, y + height);
2773 if (shadow_type == GTK_SHADOW_IN &&
2774 widget && GTK_IS_SPIN_BUTTON (widget) &&
2775 detail && strcmp (detail, "entry") == 0)
2777 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
2779 gdk_draw_line (window,
2780 style->base_gc[state_type],
2781 x + width - 1, y + 2,
2782 x + width - 1, y + height - 3);
2783 gdk_draw_line (window,
2784 style->base_gc[state_type],
2785 x + width - 2, y + 2,
2786 x + width - 2, y + height - 3);
2787 gdk_draw_point (window,
2789 x + width - 1, y + 1);
2790 gdk_draw_point (window,
2791 style->bg_gc[state_type],
2792 x + width - 1, y + height - 2);
2796 gdk_draw_line (window,
2797 style->base_gc[state_type],
2800 gdk_draw_line (window,
2801 style->base_gc[state_type],
2803 x + 1, y + height - 3);
2804 gdk_draw_point (window,
2807 gdk_draw_line (window,
2808 style->bg_gc[state_type],
2810 x + 1, y + height - 2);
2811 gdk_draw_point (window,
2812 style->light_gc[state_type],
2820 gdk_gc_set_clip_rectangle (gc1, NULL);
2821 gdk_gc_set_clip_rectangle (gc2, NULL);
2822 if (shadow_type == GTK_SHADOW_IN ||
2823 shadow_type == GTK_SHADOW_OUT)
2825 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2826 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2832 gtk_default_draw_polygon (GtkStyle *style,
2834 GtkStateType state_type,
2835 GtkShadowType shadow_type,
2838 const gchar *detail,
2843 static const gdouble pi_over_4 = G_PI_4;
2844 static const gdouble pi_3_over_4 = G_PI_4 * 3;
2854 g_return_if_fail (GTK_IS_STYLE (style));
2855 g_return_if_fail (window != NULL);
2856 g_return_if_fail (points != NULL);
2858 switch (shadow_type)
2861 gc1 = style->bg_gc[state_type];
2862 gc2 = style->dark_gc[state_type];
2863 gc3 = style->light_gc[state_type];
2864 gc4 = style->black_gc;
2866 case GTK_SHADOW_ETCHED_IN:
2867 gc1 = style->light_gc[state_type];
2868 gc2 = style->dark_gc[state_type];
2869 gc3 = style->dark_gc[state_type];
2870 gc4 = style->light_gc[state_type];
2872 case GTK_SHADOW_OUT:
2873 gc1 = style->dark_gc[state_type];
2874 gc2 = style->light_gc[state_type];
2875 gc3 = style->black_gc;
2876 gc4 = style->bg_gc[state_type];
2878 case GTK_SHADOW_ETCHED_OUT:
2879 gc1 = style->dark_gc[state_type];
2880 gc2 = style->light_gc[state_type];
2881 gc3 = style->light_gc[state_type];
2882 gc4 = style->dark_gc[state_type];
2890 gdk_gc_set_clip_rectangle (gc1, area);
2891 gdk_gc_set_clip_rectangle (gc2, area);
2892 gdk_gc_set_clip_rectangle (gc3, area);
2893 gdk_gc_set_clip_rectangle (gc4, area);
2897 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, npoints);
2901 for (i = 0; i < npoints; i++)
2903 if ((points[i].x == points[i+1].x) &&
2904 (points[i].y == points[i+1].y))
2910 angle = atan2 (points[i+1].y - points[i].y,
2911 points[i+1].x - points[i].x);
2914 if ((angle > -pi_3_over_4) && (angle < pi_over_4))
2916 if (angle > -pi_over_4)
2927 gdk_draw_line (window, gc1,
2928 points[i].x-xadjust, points[i].y-yadjust,
2929 points[i+1].x-xadjust, points[i+1].y-yadjust);
2930 gdk_draw_line (window, gc3,
2931 points[i].x, points[i].y,
2932 points[i+1].x, points[i+1].y);
2936 if ((angle < -pi_3_over_4) || (angle > pi_3_over_4))
2947 gdk_draw_line (window, gc4,
2948 points[i].x+xadjust, points[i].y+yadjust,
2949 points[i+1].x+xadjust, points[i+1].y+yadjust);
2950 gdk_draw_line (window, gc2,
2951 points[i].x, points[i].y,
2952 points[i+1].x, points[i+1].y);
2958 gdk_gc_set_clip_rectangle (gc1, NULL);
2959 gdk_gc_set_clip_rectangle (gc2, NULL);
2960 gdk_gc_set_clip_rectangle (gc3, NULL);
2961 gdk_gc_set_clip_rectangle (gc4, NULL);
2966 draw_arrow (GdkWindow *window,
2969 GtkArrowType arrow_type,
2978 gdk_gc_set_clip_rectangle (gc, area);
2980 if (arrow_type == GTK_ARROW_DOWN)
2982 for (i = 0, j = 0; i < height; i++, j++)
2983 gdk_draw_line (window, gc, x + j, y + i, x + width - j - 1, y + i);
2985 else if (arrow_type == GTK_ARROW_UP)
2987 for (i = height - 1, j = 0; i >= 0; i--, j++)
2988 gdk_draw_line (window, gc, x + j, y + i, x + width - j - 1, y + i);
2990 else if (arrow_type == GTK_ARROW_LEFT)
2992 for (i = width - 1, j = 0; i >= 0; i--, j++)
2993 gdk_draw_line (window, gc, x + i, y + j, x + i, y + height - j - 1);
2995 else if (arrow_type == GTK_ARROW_RIGHT)
2997 for (i = 0, j = 0; i < width; i++, j++)
2998 gdk_draw_line (window, gc, x + i, y + j, x + i, y + height - j - 1);
3002 gdk_gc_set_clip_rectangle (gc, NULL);
3006 calculate_arrow_geometry (GtkArrowType arrow_type,
3018 case GTK_ARROW_DOWN:
3028 if (arrow_type == GTK_ARROW_DOWN)
3030 if (*height % 2 == 1 || h % 2 == 0)
3035 if (*height % 2 == 0 || h % 2 == 0)
3040 case GTK_ARROW_RIGHT:
3041 case GTK_ARROW_LEFT:
3051 if (arrow_type == GTK_ARROW_RIGHT)
3053 if (*width % 2 == 1 || w % 2 == 0)
3058 if (*width % 2 == 0 || w % 2 == 0)
3064 /* should not be reached */
3068 *x += (*width - w) / 2;
3069 *y += (*height - h) / 2;
3075 gtk_default_draw_arrow (GtkStyle *style,
3078 GtkShadowType shadow,
3081 const gchar *detail,
3082 GtkArrowType arrow_type,
3089 gint original_width, original_x;
3091 sanitize_size (window, &width, &height);
3093 original_width = width;
3096 calculate_arrow_geometry (arrow_type, &x, &y, &width, &height);
3098 if (detail && strcmp (detail, "menu_scroll_arrow_up") == 0)
3101 if (state == GTK_STATE_INSENSITIVE)
3102 draw_arrow (window, style->white_gc, area, arrow_type,
3103 x + 1, y + 1, width, height);
3104 draw_arrow (window, style->fg_gc[state], area, arrow_type,
3105 x, y, width, height);
3109 gtk_default_draw_diamond (GtkStyle *style,
3111 GtkStateType state_type,
3112 GtkShadowType shadow_type,
3115 const gchar *detail,
3123 GdkGC *outer_nw = NULL;
3124 GdkGC *outer_ne = NULL;
3125 GdkGC *outer_sw = NULL;
3126 GdkGC *outer_se = NULL;
3127 GdkGC *middle_nw = NULL;
3128 GdkGC *middle_ne = NULL;
3129 GdkGC *middle_sw = NULL;
3130 GdkGC *middle_se = NULL;
3131 GdkGC *inner_nw = NULL;
3132 GdkGC *inner_ne = NULL;
3133 GdkGC *inner_sw = NULL;
3134 GdkGC *inner_se = NULL;
3136 g_return_if_fail (GTK_IS_STYLE (style));
3137 g_return_if_fail (window != NULL);
3139 sanitize_size (window, &width, &height);
3141 half_width = width / 2;
3142 half_height = height / 2;
3146 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
3147 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
3148 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
3149 gdk_gc_set_clip_rectangle (style->black_gc, area);
3152 switch (shadow_type)
3155 inner_sw = inner_se = style->bg_gc[state_type];
3156 middle_sw = middle_se = style->light_gc[state_type];
3157 outer_sw = outer_se = style->light_gc[state_type];
3158 inner_nw = inner_ne = style->black_gc;
3159 middle_nw = middle_ne = style->dark_gc[state_type];
3160 outer_nw = outer_ne = style->dark_gc[state_type];
3163 case GTK_SHADOW_OUT:
3164 inner_sw = inner_se = style->dark_gc[state_type];
3165 middle_sw = middle_se = style->dark_gc[state_type];
3166 outer_sw = outer_se = style->black_gc;
3167 inner_nw = inner_ne = style->bg_gc[state_type];
3168 middle_nw = middle_ne = style->light_gc[state_type];
3169 outer_nw = outer_ne = style->light_gc[state_type];
3172 case GTK_SHADOW_ETCHED_IN:
3173 inner_sw = inner_se = style->bg_gc[state_type];
3174 middle_sw = middle_se = style->dark_gc[state_type];
3175 outer_sw = outer_se = style->light_gc[state_type];
3176 inner_nw = inner_ne = style->bg_gc[state_type];
3177 middle_nw = middle_ne = style->light_gc[state_type];
3178 outer_nw = outer_ne = style->dark_gc[state_type];
3181 case GTK_SHADOW_ETCHED_OUT:
3182 inner_sw = inner_se = style->bg_gc[state_type];
3183 middle_sw = middle_se = style->light_gc[state_type];
3184 outer_sw = outer_se = style->dark_gc[state_type];
3185 inner_nw = inner_ne = style->bg_gc[state_type];
3186 middle_nw = middle_ne = style->dark_gc[state_type];
3187 outer_nw = outer_ne = style->light_gc[state_type];
3197 gdk_draw_line (window, inner_sw,
3198 x + 2, y + half_height,
3199 x + half_width, y + height - 2);
3200 gdk_draw_line (window, inner_se,
3201 x + half_width, y + height - 2,
3202 x + width - 2, y + half_height);
3203 gdk_draw_line (window, middle_sw,
3204 x + 1, y + half_height,
3205 x + half_width, y + height - 1);
3206 gdk_draw_line (window, middle_se,
3207 x + half_width, y + height - 1,
3208 x + width - 1, y + half_height);
3209 gdk_draw_line (window, outer_sw,
3211 x + half_width, y + height);
3212 gdk_draw_line (window, outer_se,
3213 x + half_width, y + height,
3214 x + width, y + half_height);
3216 gdk_draw_line (window, inner_nw,
3217 x + 2, y + half_height,
3218 x + half_width, y + 2);
3219 gdk_draw_line (window, inner_ne,
3220 x + half_width, y + 2,
3221 x + width - 2, y + half_height);
3222 gdk_draw_line (window, middle_nw,
3223 x + 1, y + half_height,
3224 x + half_width, y + 1);
3225 gdk_draw_line (window, middle_ne,
3226 x + half_width, y + 1,
3227 x + width - 1, y + half_height);
3228 gdk_draw_line (window, outer_nw,
3231 gdk_draw_line (window, outer_ne,
3233 x + width, y + half_height);
3238 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
3239 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
3240 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
3241 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
3246 gtk_default_draw_string (GtkStyle *style,
3248 GtkStateType state_type,
3251 const gchar *detail,
3254 const gchar *string)
3256 GdkDisplay *display;
3258 g_return_if_fail (GTK_IS_STYLE (style));
3259 g_return_if_fail (window != NULL);
3261 display = gdk_drawable_get_display (window);
3265 gdk_gc_set_clip_rectangle (style->white_gc, area);
3266 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], area);
3269 if (state_type == GTK_STATE_INSENSITIVE)
3270 gdk_draw_string (window,
3271 gtk_style_get_font_internal (style),
3272 style->white_gc, x + 1, y + 1, string);
3274 gdk_draw_string (window,
3275 gtk_style_get_font_internal (style),
3276 style->fg_gc[state_type], x, y, string);
3280 gdk_gc_set_clip_rectangle (style->white_gc, NULL);
3281 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], NULL);
3286 option_menu_get_props (GtkWidget *widget,
3287 GtkRequisition *indicator_size,
3288 GtkBorder *indicator_spacing)
3290 GtkRequisition *tmp_size = NULL;
3291 GtkBorder *tmp_spacing = NULL;
3294 gtk_widget_style_get (widget,
3295 "indicator_size", &tmp_size,
3296 "indicator_spacing", &tmp_spacing,
3301 *indicator_size = *tmp_size;
3305 *indicator_size = default_option_indicator_size;
3309 *indicator_spacing = *tmp_spacing;
3310 g_free (tmp_spacing);
3313 *indicator_spacing = default_option_indicator_spacing;
3317 gtk_default_draw_box (GtkStyle *style,
3319 GtkStateType state_type,
3320 GtkShadowType shadow_type,
3323 const gchar *detail,
3329 gboolean is_spinbutton_box = FALSE;
3331 g_return_if_fail (GTK_IS_STYLE (style));
3332 g_return_if_fail (window != NULL);
3334 sanitize_size (window, &width, &height);
3336 if (widget && GTK_IS_SPIN_BUTTON (widget) && detail)
3338 if (strcmp (detail, "spinbutton_up") == 0)
3344 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3349 is_spinbutton_box = TRUE;
3351 else if (strcmp (detail, "spinbutton_down") == 0)
3356 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3361 is_spinbutton_box = TRUE;
3365 if (!style->bg_pixmap[state_type] ||
3366 GDK_IS_PIXMAP (window))
3369 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
3371 gdk_draw_rectangle (window, style->bg_gc[state_type], TRUE,
3372 x, y, width, height);
3374 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
3377 gtk_style_apply_default_background (style, window,
3378 widget && !GTK_WIDGET_NO_WINDOW (widget),
3379 state_type, area, x, y, width, height);
3381 if (is_spinbutton_box)
3386 lower_gc = style->dark_gc[state_type];
3387 if (shadow_type == GTK_SHADOW_OUT)
3388 upper_gc = style->light_gc[state_type];
3390 upper_gc = style->dark_gc[state_type];
3394 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
3395 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
3398 gdk_draw_line (window, upper_gc, x, y, x + width - 1, y);
3399 gdk_draw_line (window, lower_gc, x, y + height - 1, x + width - 1, y + height - 1);
3403 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
3404 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
3409 gtk_paint_shadow (style, window, state_type, shadow_type, area, widget, detail,
3410 x, y, width, height);
3412 if (detail && strcmp (detail, "optionmenu") == 0)
3414 GtkRequisition indicator_size;
3415 GtkBorder indicator_spacing;
3418 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
3420 sanitize_size (window, &width, &height);
3422 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3423 vline_x = x + indicator_size.width + indicator_spacing.left + indicator_spacing.right;
3425 vline_x = x + width - (indicator_size.width + indicator_spacing.left + indicator_spacing.right) - style->xthickness;
3427 gtk_paint_vline (style, window, state_type, area, widget,
3429 y + style->ythickness + 1,
3430 y + height - style->ythickness - 3,
3436 get_darkened_gc (GdkWindow *window,
3440 GdkColor src = *color;
3441 GdkColor shaded = *color;
3444 gc = gdk_gc_new (window);
3446 while (darken_count)
3448 gtk_style_shade (&src, &shaded, 0.93);
3453 gdk_gc_set_rgb_fg_color (gc, &shaded);
3459 gtk_default_draw_flat_box (GtkStyle *style,
3461 GtkStateType state_type,
3462 GtkShadowType shadow_type,
3465 const gchar *detail,
3472 GdkGC *freeme = NULL;
3474 g_return_if_fail (GTK_IS_STYLE (style));
3475 g_return_if_fail (window != NULL);
3477 sanitize_size (window, &width, &height);
3481 if (state_type == GTK_STATE_SELECTED)
3483 if (!strcmp ("text", detail))
3484 gc1 = style->bg_gc[GTK_STATE_SELECTED];
3485 else if (!strncmp ("cell_even", detail, strlen ("cell_even")) ||
3486 !strncmp ("cell_odd", detail, strlen ("cell_odd")))
3488 /* This has to be really broken; alex made me do it. -jrb */
3489 if (GTK_WIDGET_HAS_FOCUS (widget))
3490 gc1 = style->base_gc[state_type];
3492 gc1 = style->base_gc[GTK_STATE_ACTIVE];
3496 gc1 = style->bg_gc[state_type];
3501 if (!strcmp ("viewportbin", detail))
3502 gc1 = style->bg_gc[GTK_STATE_NORMAL];
3503 else if (!strcmp ("entry_bg", detail))
3504 gc1 = style->base_gc[state_type];
3506 /* For trees: even rows are base color, odd rows are a shade of
3507 * the base color, the sort column is a shade of the original color
3511 else if (!strcmp ("cell_even", detail) ||
3512 !strcmp ("cell_odd", detail) ||
3513 !strcmp ("cell_even_ruled", detail))
3515 GdkColor *color = NULL;
3517 gtk_widget_style_get (widget,
3518 "even_row_color", &color,
3523 freeme = get_darkened_gc (window, color, 0);
3526 gdk_color_free (color);
3529 gc1 = style->base_gc[state_type];
3531 else if (!strcmp ("cell_odd_ruled", detail))
3535 gtk_widget_style_get (widget,
3536 "odd_row_color", &color,
3541 freeme = get_darkened_gc (window, color, 0);
3544 gdk_color_free (color);
3548 gtk_widget_style_get (widget,
3549 "even_row_color", &color,
3554 freeme = get_darkened_gc (window, color, 1);
3555 gdk_color_free (color);
3558 freeme = get_darkened_gc (window, &style->base[state_type], 1);
3562 else if (!strcmp ("cell_even_sorted", detail) ||
3563 !strcmp ("cell_odd_sorted", detail) ||
3564 !strcmp ("cell_even_ruled_sorted", detail))
3566 GdkColor *color = NULL;
3568 if (!strcmp ("cell_odd_sorted", detail))
3569 gtk_widget_style_get (widget,
3570 "odd_row_color", &color,
3573 gtk_widget_style_get (widget,
3574 "even_row_color", &color,
3579 freeme = get_darkened_gc (window, color, 1);
3582 gdk_color_free (color);
3586 freeme = get_darkened_gc (window, &style->base[state_type], 1);
3590 else if (!strcmp ("cell_odd_ruled_sorted", detail))
3592 GdkColor *color = NULL;
3594 gtk_widget_style_get (widget,
3595 "odd_row_color", &color,
3600 freeme = get_darkened_gc (window, color, 1);
3603 gdk_color_free (color);
3607 gtk_widget_style_get (widget,
3608 "even_row_color", &color,
3613 freeme = get_darkened_gc (window, color, 2);
3614 gdk_color_free (color);
3617 freeme = get_darkened_gc (window, &style->base[state_type], 2);
3622 gc1 = style->bg_gc[state_type];
3626 gc1 = style->bg_gc[state_type];
3628 if (!style->bg_pixmap[state_type] || gc1 != style->bg_gc[state_type] ||
3629 GDK_IS_PIXMAP (window))
3632 gdk_gc_set_clip_rectangle (gc1, area);
3634 gdk_draw_rectangle (window, gc1, TRUE,
3635 x, y, width, height);
3637 if (detail && !strcmp ("tooltip", detail))
3638 gdk_draw_rectangle (window, style->black_gc, FALSE,
3639 x, y, width - 1, height - 1);
3642 gdk_gc_set_clip_rectangle (gc1, NULL);
3645 gtk_style_apply_default_background (style, window,
3646 widget && !GTK_WIDGET_NO_WINDOW (widget),
3647 state_type, area, x, y, width, height);
3651 g_object_unref (freeme);
3655 create_aa_gc (GdkWindow *window, GtkStyle *style, GtkStateType state_type)
3658 GdkGC *gc = gdk_gc_new (window);
3660 aa_color.red = (style->fg[state_type].red + style->bg[state_type].red) / 2;
3661 aa_color.green = (style->fg[state_type].green + style->bg[state_type].green) / 2;
3662 aa_color.blue = (style->fg[state_type].blue + style->bg[state_type].blue) / 2;
3664 gdk_gc_set_rgb_fg_color (gc, &aa_color);
3670 gtk_default_draw_check (GtkStyle *style,
3672 GtkStateType state_type,
3673 GtkShadowType shadow_type,
3676 const gchar *detail,
3682 if (detail && strcmp (detail, "cellcheck") == 0)
3684 gdk_draw_rectangle (window,
3685 widget->style->base_gc[state_type],
3689 gdk_draw_rectangle (window,
3690 widget->style->text_gc[state_type],
3695 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3696 y -= (((1 + INDICATOR_PART_SIZE - height) / 2) - 1);
3697 if (shadow_type == GTK_SHADOW_IN)
3699 draw_part (window, style->text_gc[state_type], area, x, y, CHECK_TEXT);
3700 draw_part (window, style->text_aa_gc[state_type], area, x, y, CHECK_AA);
3702 else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
3704 draw_part (window, style->text_gc[state_type], area, x, y, CHECK_INCONSISTENT_TEXT);
3709 GdkGC *free_me = NULL;
3715 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3716 y -= (1 + INDICATOR_PART_SIZE - height) / 2;
3718 if (strcmp (detail, "check") == 0) /* Menu item */
3720 text_gc = style->fg_gc[state_type];
3721 base_gc = style->bg_gc[state_type];
3722 aa_gc = free_me = create_aa_gc (window, style, state_type);
3726 if (state_type == GTK_STATE_ACTIVE)
3728 text_gc = style->fg_gc[state_type];
3729 base_gc = style->bg_gc[state_type];
3730 aa_gc = free_me = create_aa_gc (window, style, state_type);
3734 text_gc = style->text_gc[state_type];
3735 base_gc = style->base_gc[state_type];
3736 aa_gc = style->text_aa_gc[state_type];
3739 draw_part (window, base_gc, area, x, y, CHECK_BASE);
3740 draw_part (window, style->black_gc, area, x, y, CHECK_BLACK);
3741 draw_part (window, style->dark_gc[state_type], area, x, y, CHECK_DARK);
3742 draw_part (window, style->mid_gc[state_type], area, x, y, CHECK_MID);
3743 draw_part (window, style->light_gc[state_type], area, x, y, CHECK_LIGHT);
3746 if (shadow_type == GTK_SHADOW_IN)
3748 draw_part (window, text_gc, area, x, y, CHECK_TEXT);
3749 draw_part (window, aa_gc, area, x, y, CHECK_AA);
3751 else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
3753 draw_part (window, text_gc, area, x, y, CHECK_INCONSISTENT_TEXT);
3757 g_object_unref (free_me);
3762 gtk_default_draw_option (GtkStyle *style,
3764 GtkStateType state_type,
3765 GtkShadowType shadow_type,
3768 const gchar *detail,
3774 if (detail && strcmp (detail, "cellradio") == 0)
3776 gdk_draw_arc (window,
3777 widget->style->fg_gc[state_type],
3784 if (shadow_type == GTK_SHADOW_IN)
3786 gdk_draw_arc (window,
3787 widget->style->fg_gc[state_type],
3795 else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
3797 draw_part (window, widget->style->fg_gc[state_type],
3798 area, x, y, CHECK_INCONSISTENT_TEXT);
3803 GdkGC *free_me = NULL;
3809 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3810 y -= (1 + INDICATOR_PART_SIZE - height) / 2;
3812 if (strcmp (detail, "option") == 0) /* Menu item */
3814 text_gc = style->fg_gc[state_type];
3815 base_gc = style->bg_gc[state_type];
3816 aa_gc = free_me = create_aa_gc (window, style, state_type);
3820 if (state_type == GTK_STATE_ACTIVE)
3822 text_gc = style->fg_gc[state_type];
3823 base_gc = style->bg_gc[state_type];
3824 aa_gc = free_me = create_aa_gc (window, style, state_type);
3828 text_gc = style->text_gc[state_type];
3829 base_gc = style->base_gc[state_type];
3830 aa_gc = style->text_aa_gc[state_type];
3833 draw_part (window, base_gc, area, x, y, RADIO_BASE);
3834 draw_part (window, style->black_gc, area, x, y, RADIO_BLACK);
3835 draw_part (window, style->dark_gc[state_type], area, x, y, RADIO_DARK);
3836 draw_part (window, style->mid_gc[state_type], area, x, y, RADIO_MID);
3837 draw_part (window, style->light_gc[state_type], area, x, y, RADIO_LIGHT);
3840 if (shadow_type == GTK_SHADOW_IN)
3842 draw_part (window, text_gc, area, x, y, RADIO_TEXT);
3844 else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
3846 if (strcmp (detail, "option") == 0) /* Menu item */
3848 draw_part (window, text_gc, area, x, y, CHECK_INCONSISTENT_TEXT);
3852 draw_part (window, text_gc, area, x, y, RADIO_INCONSISTENT_TEXT);
3853 draw_part (window, aa_gc, area, x, y, RADIO_INCONSISTENT_AA);
3858 g_object_unref (free_me);
3863 gtk_default_draw_tab (GtkStyle *style,
3865 GtkStateType state_type,
3866 GtkShadowType shadow_type,
3869 const gchar *detail,
3875 #define ARROW_SPACE 4
3877 GtkRequisition indicator_size;
3878 GtkBorder indicator_spacing;
3881 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
3883 indicator_size.width += (indicator_size.width % 2) - 1;
3884 arrow_height = indicator_size.width / 2 + 1;
3886 x += (width - indicator_size.width) / 2;
3887 y += (height - (2 * arrow_height + ARROW_SPACE)) / 2;
3889 if (state_type == GTK_STATE_INSENSITIVE)
3891 draw_arrow (window, style->white_gc, area,
3892 GTK_ARROW_UP, x + 1, y + 1,
3893 indicator_size.width, arrow_height);
3895 draw_arrow (window, style->white_gc, area,
3896 GTK_ARROW_DOWN, x + 1, y + arrow_height + ARROW_SPACE + 1,
3897 indicator_size.width, arrow_height);
3900 draw_arrow (window, style->fg_gc[state_type], area,
3902 indicator_size.width, arrow_height);
3905 draw_arrow (window, style->fg_gc[state_type], area,
3906 GTK_ARROW_DOWN, x, y + arrow_height + ARROW_SPACE,
3907 indicator_size.width, arrow_height);
3911 gtk_default_draw_shadow_gap (GtkStyle *style,
3913 GtkStateType state_type,
3914 GtkShadowType shadow_type,
3917 const gchar *detail,
3922 GtkPositionType gap_side,
3931 g_return_if_fail (GTK_IS_STYLE (style));
3932 g_return_if_fail (window != NULL);
3934 sanitize_size (window, &width, &height);
3936 switch (shadow_type)
3938 case GTK_SHADOW_NONE:
3941 gc1 = style->dark_gc[state_type];
3942 gc2 = style->black_gc;
3943 gc3 = style->bg_gc[state_type];
3944 gc4 = style->light_gc[state_type];
3946 case GTK_SHADOW_ETCHED_IN:
3947 gc1 = style->dark_gc[state_type];
3948 gc2 = style->light_gc[state_type];
3949 gc3 = style->dark_gc[state_type];
3950 gc4 = style->light_gc[state_type];
3952 case GTK_SHADOW_OUT:
3953 gc1 = style->light_gc[state_type];
3954 gc2 = style->bg_gc[state_type];
3955 gc3 = style->dark_gc[state_type];
3956 gc4 = style->black_gc;
3958 case GTK_SHADOW_ETCHED_OUT:
3959 gc1 = style->light_gc[state_type];
3960 gc2 = style->dark_gc[state_type];
3961 gc3 = style->light_gc[state_type];
3962 gc4 = style->dark_gc[state_type];
3967 gdk_gc_set_clip_rectangle (gc1, area);
3968 gdk_gc_set_clip_rectangle (gc2, area);
3969 gdk_gc_set_clip_rectangle (gc3, area);
3970 gdk_gc_set_clip_rectangle (gc4, area);
3973 switch (shadow_type)
3975 case GTK_SHADOW_NONE:
3977 case GTK_SHADOW_OUT:
3978 case GTK_SHADOW_ETCHED_IN:
3979 case GTK_SHADOW_ETCHED_OUT:
3983 gdk_draw_line (window, gc1,
3984 x, y, x, y + height - 1);
3985 gdk_draw_line (window, gc2,
3986 x + 1, y, x + 1, y + height - 2);
3988 gdk_draw_line (window, gc3,
3989 x + 1, y + height - 2, x + width - 2, y + height - 2);
3990 gdk_draw_line (window, gc3,
3991 x + width - 2, y, x + width - 2, y + height - 2);
3992 gdk_draw_line (window, gc4,
3993 x, y + height - 1, x + width - 1, y + height - 1);
3994 gdk_draw_line (window, gc4,
3995 x + width - 1, y, x + width - 1, y + height - 1);
3998 gdk_draw_line (window, gc1,
3999 x, y, x + gap_x - 1, y);
4000 gdk_draw_line (window, gc2,
4001 x + 1, y + 1, x + gap_x - 1, y + 1);
4002 gdk_draw_line (window, gc2,
4003 x + gap_x, y, x + gap_x, y);
4005 if ((width - (gap_x + gap_width)) > 0)
4007 gdk_draw_line (window, gc1,
4008 x + gap_x + gap_width, y, x + width - 2, y);
4009 gdk_draw_line (window, gc2,
4010 x + gap_x + gap_width, y + 1, x + width - 3, y + 1);
4011 gdk_draw_line (window, gc2,
4012 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
4015 case GTK_POS_BOTTOM:
4016 gdk_draw_line (window, gc1,
4017 x, y, x + width - 1, y);
4018 gdk_draw_line (window, gc1,
4019 x, y, x, y + height - 1);
4020 gdk_draw_line (window, gc2,
4021 x + 1, y + 1, x + width - 2, y + 1);
4022 gdk_draw_line (window, gc2,
4023 x + 1, y + 1, x + 1, y + height - 1);
4025 gdk_draw_line (window, gc3,
4026 x + width - 2, y + 1, x + width - 2, y + height - 1);
4027 gdk_draw_line (window, gc4,
4028 x + width - 1, y, x + width - 1, y + height - 1);
4031 gdk_draw_line (window, gc4,
4032 x, y + height - 1, x + gap_x - 1, y + height - 1);
4033 gdk_draw_line (window, gc3,
4034 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
4035 gdk_draw_line (window, gc3,
4036 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
4038 if ((width - (gap_x + gap_width)) > 0)
4040 gdk_draw_line (window, gc4,
4041 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
4042 gdk_draw_line (window, gc3,
4043 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
4044 gdk_draw_line (window, gc3,
4045 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
4049 gdk_draw_line (window, gc1,
4050 x, y, x + width - 1, y);
4051 gdk_draw_line (window, gc2,
4052 x, y + 1, x + width - 2, y + 1);
4054 gdk_draw_line (window, gc3,
4055 x, y + height - 2, x + width - 2, y + height - 2);
4056 gdk_draw_line (window, gc3,
4057 x + width - 2, y + 1, x + width - 2, y + height - 2);
4058 gdk_draw_line (window, gc4,
4059 x, y + height - 1, x + width - 1, y + height - 1);
4060 gdk_draw_line (window, gc4,
4061 x + width - 1, y, x + width - 1, y + height - 1);
4064 gdk_draw_line (window, gc1,
4065 x, y, x, y + gap_x - 1);
4066 gdk_draw_line (window, gc2,
4067 x + 1, y + 1, x + 1, y + gap_x - 1);
4068 gdk_draw_line (window, gc2,
4069 x, y + gap_x, x, y + gap_x);
4071 if ((width - (gap_x + gap_width)) > 0)
4073 gdk_draw_line (window, gc1,
4074 x, y + gap_x + gap_width, x, y + height - 2);
4075 gdk_draw_line (window, gc2,
4076 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
4077 gdk_draw_line (window, gc2,
4078 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
4082 gdk_draw_line (window, gc1,
4083 x, y, x + width - 1, y);
4084 gdk_draw_line (window, gc1,
4085 x, y, x, y + height - 1);
4086 gdk_draw_line (window, gc2,
4087 x + 1, y + 1, x + width - 1, y + 1);
4088 gdk_draw_line (window, gc2,
4089 x + 1, y + 1, x + 1, y + height - 2);
4091 gdk_draw_line (window, gc3,
4092 x + 1, y + height - 2, x + width - 1, y + height - 2);
4093 gdk_draw_line (window, gc4,
4094 x, y + height - 1, x + width - 1, y + height - 1);
4097 gdk_draw_line (window, gc4,
4098 x + width - 1, y, x + width - 1, y + gap_x - 1);
4099 gdk_draw_line (window, gc3,
4100 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
4101 gdk_draw_line (window, gc3,
4102 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
4104 if ((width - (gap_x + gap_width)) > 0)
4106 gdk_draw_line (window, gc4,
4107 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
4108 gdk_draw_line (window, gc3,
4109 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
4110 gdk_draw_line (window, gc3,
4111 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
4119 gdk_gc_set_clip_rectangle (gc1, NULL);
4120 gdk_gc_set_clip_rectangle (gc2, NULL);
4121 gdk_gc_set_clip_rectangle (gc3, NULL);
4122 gdk_gc_set_clip_rectangle (gc4, NULL);
4127 gtk_default_draw_box_gap (GtkStyle *style,
4129 GtkStateType state_type,
4130 GtkShadowType shadow_type,
4133 const gchar *detail,
4138 GtkPositionType gap_side,
4147 g_return_if_fail (GTK_IS_STYLE (style));
4148 g_return_if_fail (window != NULL);
4150 gtk_style_apply_default_background (style, window,
4151 widget && !GTK_WIDGET_NO_WINDOW (widget),
4152 state_type, area, x, y, width, height);
4154 sanitize_size (window, &width, &height);
4156 switch (shadow_type)
4158 case GTK_SHADOW_NONE:
4161 gc1 = style->dark_gc[state_type];
4162 gc2 = style->black_gc;
4163 gc3 = style->bg_gc[state_type];
4164 gc4 = style->light_gc[state_type];
4166 case GTK_SHADOW_ETCHED_IN:
4167 gc1 = style->dark_gc[state_type];
4168 gc2 = style->light_gc[state_type];
4169 gc3 = style->dark_gc[state_type];
4170 gc4 = style->light_gc[state_type];
4172 case GTK_SHADOW_OUT:
4173 gc1 = style->light_gc[state_type];
4174 gc2 = style->bg_gc[state_type];
4175 gc3 = style->dark_gc[state_type];
4176 gc4 = style->black_gc;
4178 case GTK_SHADOW_ETCHED_OUT:
4179 gc1 = style->light_gc[state_type];
4180 gc2 = style->dark_gc[state_type];
4181 gc3 = style->light_gc[state_type];
4182 gc4 = style->dark_gc[state_type];
4188 gdk_gc_set_clip_rectangle (gc1, area);
4189 gdk_gc_set_clip_rectangle (gc2, area);
4190 gdk_gc_set_clip_rectangle (gc3, area);
4191 gdk_gc_set_clip_rectangle (gc4, area);
4194 switch (shadow_type)
4196 case GTK_SHADOW_NONE:
4198 case GTK_SHADOW_OUT:
4199 case GTK_SHADOW_ETCHED_IN:
4200 case GTK_SHADOW_ETCHED_OUT:
4204 gdk_draw_line (window, gc1,
4205 x, y, x, y + height - 1);
4206 gdk_draw_line (window, gc2,
4207 x + 1, y, x + 1, y + height - 2);
4209 gdk_draw_line (window, gc3,
4210 x + 1, y + height - 2, x + width - 2, y + height - 2);
4211 gdk_draw_line (window, gc3,
4212 x + width - 2, y, x + width - 2, y + height - 2);
4213 gdk_draw_line (window, gc4,
4214 x, y + height - 1, x + width - 1, y + height - 1);
4215 gdk_draw_line (window, gc4,
4216 x + width - 1, y, x + width - 1, y + height - 1);
4219 gdk_draw_line (window, gc1,
4220 x, y, x + gap_x - 1, y);
4221 gdk_draw_line (window, gc2,
4222 x + 1, y + 1, x + gap_x - 1, y + 1);
4223 gdk_draw_line (window, gc2,
4224 x + gap_x, y, x + gap_x, y);
4226 if ((width - (gap_x + gap_width)) > 0)
4228 gdk_draw_line (window, gc1,
4229 x + gap_x + gap_width, y, x + width - 2, y);
4230 gdk_draw_line (window, gc2,
4231 x + gap_x + gap_width, y + 1, x + width - 2, y + 1);
4232 gdk_draw_line (window, gc2,
4233 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
4236 case GTK_POS_BOTTOM:
4237 gdk_draw_line (window, gc1,
4238 x, y, x + width - 1, y);
4239 gdk_draw_line (window, gc1,
4240 x, y, x, y + height - 1);
4241 gdk_draw_line (window, gc2,
4242 x + 1, y + 1, x + width - 2, y + 1);
4243 gdk_draw_line (window, gc2,
4244 x + 1, y + 1, x + 1, y + height - 1);
4246 gdk_draw_line (window, gc3,
4247 x + width - 2, y + 1, x + width - 2, y + height - 1);
4248 gdk_draw_line (window, gc4,
4249 x + width - 1, y, x + width - 1, y + height - 1);
4252 gdk_draw_line (window, gc4,
4253 x, y + height - 1, x + gap_x - 1, y + height - 1);
4254 gdk_draw_line (window, gc3,
4255 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
4256 gdk_draw_line (window, gc3,
4257 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
4259 if ((width - (gap_x + gap_width)) > 0)
4261 gdk_draw_line (window, gc4,
4262 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
4263 gdk_draw_line (window, gc3,
4264 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
4265 gdk_draw_line (window, gc3,
4266 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
4270 gdk_draw_line (window, gc1,
4271 x, y, x + width - 1, y);
4272 gdk_draw_line (window, gc2,
4273 x, y + 1, x + width - 2, y + 1);
4275 gdk_draw_line (window, gc3,
4276 x, y + height - 2, x + width - 2, y + height - 2);
4277 gdk_draw_line (window, gc3,
4278 x + width - 2, y + 1, x + width - 2, y + height - 2);
4279 gdk_draw_line (window, gc4,
4280 x, y + height - 1, x + width - 1, y + height - 1);
4281 gdk_draw_line (window, gc4,
4282 x + width - 1, y, x + width - 1, y + height - 1);
4285 gdk_draw_line (window, gc1,
4286 x, y, x, y + gap_x - 1);
4287 gdk_draw_line (window, gc2,
4288 x + 1, y + 1, x + 1, y + gap_x - 1);
4289 gdk_draw_line (window, gc2,
4290 x, y + gap_x, x, y + gap_x);
4292 if ((width - (gap_x + gap_width)) > 0)
4294 gdk_draw_line (window, gc1,
4295 x, y + gap_x + gap_width, x, y + height - 2);
4296 gdk_draw_line (window, gc2,
4297 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
4298 gdk_draw_line (window, gc2,
4299 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
4303 gdk_draw_line (window, gc1,
4304 x, y, x + width - 1, y);
4305 gdk_draw_line (window, gc1,
4306 x, y, x, y + height - 1);
4307 gdk_draw_line (window, gc2,
4308 x + 1, y + 1, x + width - 1, y + 1);
4309 gdk_draw_line (window, gc2,
4310 x + 1, y + 1, x + 1, y + height - 2);
4312 gdk_draw_line (window, gc3,
4313 x + 1, y + height - 2, x + width - 1, y + height - 2);
4314 gdk_draw_line (window, gc4,
4315 x, y + height - 1, x + width - 1, y + height - 1);
4318 gdk_draw_line (window, gc4,
4319 x + width - 1, y, x + width - 1, y + gap_x - 1);
4320 gdk_draw_line (window, gc3,
4321 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
4322 gdk_draw_line (window, gc3,
4323 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
4325 if ((width - (gap_x + gap_width)) > 0)
4327 gdk_draw_line (window, gc4,
4328 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
4329 gdk_draw_line (window, gc3,
4330 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
4331 gdk_draw_line (window, gc3,
4332 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
4340 gdk_gc_set_clip_rectangle (gc1, NULL);
4341 gdk_gc_set_clip_rectangle (gc2, NULL);
4342 gdk_gc_set_clip_rectangle (gc3, NULL);
4343 gdk_gc_set_clip_rectangle (gc4, NULL);
4348 gtk_default_draw_extension (GtkStyle *style,
4350 GtkStateType state_type,
4351 GtkShadowType shadow_type,
4354 const gchar *detail,
4359 GtkPositionType gap_side)
4366 g_return_if_fail (GTK_IS_STYLE (style));
4367 g_return_if_fail (window != NULL);
4369 gtk_style_apply_default_background (style, window,
4370 widget && !GTK_WIDGET_NO_WINDOW (widget),
4371 GTK_STATE_NORMAL, area, x, y, width, height);
4373 sanitize_size (window, &width, &height);
4375 switch (shadow_type)
4377 case GTK_SHADOW_NONE:
4380 gc1 = style->dark_gc[state_type];
4381 gc2 = style->black_gc;
4382 gc3 = style->bg_gc[state_type];
4383 gc4 = style->light_gc[state_type];
4385 case GTK_SHADOW_ETCHED_IN:
4386 gc1 = style->dark_gc[state_type];
4387 gc2 = style->light_gc[state_type];
4388 gc3 = style->dark_gc[state_type];
4389 gc4 = style->light_gc[state_type];
4391 case GTK_SHADOW_OUT:
4392 gc1 = style->light_gc[state_type];
4393 gc2 = style->bg_gc[state_type];
4394 gc3 = style->dark_gc[state_type];
4395 gc4 = style->black_gc;
4397 case GTK_SHADOW_ETCHED_OUT:
4398 gc1 = style->light_gc[state_type];
4399 gc2 = style->dark_gc[state_type];
4400 gc3 = style->light_gc[state_type];
4401 gc4 = style->dark_gc[state_type];
4407 gdk_gc_set_clip_rectangle (gc1, area);
4408 gdk_gc_set_clip_rectangle (gc2, area);
4409 gdk_gc_set_clip_rectangle (gc3, area);
4410 gdk_gc_set_clip_rectangle (gc4, area);
4413 switch (shadow_type)
4415 case GTK_SHADOW_NONE:
4417 case GTK_SHADOW_OUT:
4418 case GTK_SHADOW_ETCHED_IN:
4419 case GTK_SHADOW_ETCHED_OUT:
4423 gtk_style_apply_default_background (style, window,
4424 widget && !GTK_WIDGET_NO_WINDOW (widget),
4426 x + style->xthickness,
4428 width - (2 * style->xthickness),
4429 height - (style->ythickness));
4430 gdk_draw_line (window, gc1,
4431 x, y, x, y + height - 2);
4432 gdk_draw_line (window, gc2,
4433 x + 1, y, x + 1, y + height - 2);
4435 gdk_draw_line (window, gc3,
4436 x + 2, y + height - 2, x + width - 2, y + height - 2);
4437 gdk_draw_line (window, gc3,
4438 x + width - 2, y, x + width - 2, y + height - 2);
4439 gdk_draw_line (window, gc4,
4440 x + 1, y + height - 1, x + width - 2, y + height - 1);
4441 gdk_draw_line (window, gc4,
4442 x + width - 1, y, x + width - 1, y + height - 2);
4444 case GTK_POS_BOTTOM:
4445 gtk_style_apply_default_background (style, window,
4446 widget && !GTK_WIDGET_NO_WINDOW (widget),
4448 x + style->xthickness,
4449 y + style->ythickness,
4450 width - (2 * style->xthickness),
4451 height - (style->ythickness));
4452 gdk_draw_line (window, gc1,
4453 x + 1, y, x + width - 2, y);
4454 gdk_draw_line (window, gc1,
4455 x, y + 1, x, y + height - 1);
4456 gdk_draw_line (window, gc2,
4457 x + 1, y + 1, x + width - 2, y + 1);
4458 gdk_draw_line (window, gc2,
4459 x + 1, y + 1, x + 1, y + height - 1);
4461 gdk_draw_line (window, gc3,
4462 x + width - 2, y + 2, x + width - 2, y + height - 1);
4463 gdk_draw_line (window, gc4,
4464 x + width - 1, y + 1, x + width - 1, y + height - 1);
4467 gtk_style_apply_default_background (style, window,
4468 widget && !GTK_WIDGET_NO_WINDOW (widget),
4471 y + style->ythickness,
4472 width - (style->xthickness),
4473 height - (2 * style->ythickness));
4474 gdk_draw_line (window, gc1,
4475 x, y, x + width - 2, y);
4476 gdk_draw_line (window, gc2,
4477 x + 1, y + 1, x + width - 2, y + 1);
4479 gdk_draw_line (window, gc3,
4480 x, y + height - 2, x + width - 2, y + height - 2);
4481 gdk_draw_line (window, gc3,
4482 x + width - 2, y + 2, x + width - 2, y + height - 2);
4483 gdk_draw_line (window, gc4,
4484 x, y + height - 1, x + width - 2, y + height - 1);
4485 gdk_draw_line (window, gc4,
4486 x + width - 1, y + 1, x + width - 1, y + height - 2);
4489 gtk_style_apply_default_background (style, window,
4490 widget && !GTK_WIDGET_NO_WINDOW (widget),
4492 x + style->xthickness,
4493 y + style->ythickness,
4494 width - (style->xthickness),
4495 height - (2 * style->ythickness));
4496 gdk_draw_line (window, gc1,
4497 x + 1, y, x + width - 1, y);
4498 gdk_draw_line (window, gc1,
4499 x, y + 1, x, y + height - 2);
4500 gdk_draw_line (window, gc2,
4501 x + 1, y + 1, x + width - 1, y + 1);
4502 gdk_draw_line (window, gc2,
4503 x + 1, y + 1, x + 1, y + height - 2);
4505 gdk_draw_line (window, gc3,
4506 x + 2, y + height - 2, x + width - 1, y + height - 2);
4507 gdk_draw_line (window, gc4,
4508 x + 1, y + height - 1, x + width - 1, y + height - 1);
4515 gdk_gc_set_clip_rectangle (gc1, NULL);
4516 gdk_gc_set_clip_rectangle (gc2, NULL);
4517 gdk_gc_set_clip_rectangle (gc3, NULL);
4518 gdk_gc_set_clip_rectangle (gc4, NULL);
4523 gtk_default_draw_focus (GtkStyle *style,
4525 GtkStateType state_type,
4528 const gchar *detail,
4536 gboolean free_dash_list = FALSE;
4537 gint line_width = 1;
4538 gint8 *dash_list = "\1\1";
4541 gc = style->fg_gc[state_type];
4545 gtk_widget_style_get (widget,
4546 "focus-line-width", &line_width,
4547 "focus-line-pattern", (gchar *)&dash_list,
4550 free_dash_list = TRUE;
4553 sanitize_size (window, &width, &height);
4556 gdk_gc_set_clip_rectangle (gc, area);
4558 gdk_gc_set_line_attributes (gc, line_width,
4559 dash_list[0] ? GDK_LINE_ON_OFF_DASH : GDK_LINE_SOLID,
4560 GDK_CAP_BUTT, GDK_JOIN_MITER);
4563 if (detail && !strcmp (detail, "add-mode"))
4569 free_dash_list = FALSE;
4572 points[0].x = x + line_width / 2;
4573 points[0].y = y + line_width / 2;
4574 points[1].x = x + width - line_width + line_width / 2;
4575 points[1].y = y + line_width / 2;
4576 points[2].x = x + width - line_width + line_width / 2;
4577 points[2].y = y + height - line_width + line_width / 2;
4578 points[3].x = x + line_width / 2;
4579 points[3].y = y + height - line_width + line_width / 2;
4580 points[4] = points[0];
4584 gdk_draw_lines (window, gc, points, 5);
4588 /* We go through all the pain below because the X rasterization
4589 * rules don't really work right for dashed lines if you
4590 * want continuity in segments that go between top/right
4591 * and left/bottom. For instance, a top left corner
4592 * with a 1-1 dash is drawn as:
4599 * This is because pixels on the top and left boundaries
4600 * of polygons are drawn, but not on the bottom and right.
4601 * So, if you have a line going up that turns the corner
4602 * and goes right, there is a one pixel shift in the pattern.
4604 * So, to fix this, we drawn the top and right in one call,
4605 * then the left and bottom in another call, fixing up
4606 * the dash offset for the second call ourselves to get
4607 * continuity at the upper left.
4609 * It's not perfect since we really should have a join at
4610 * the upper left and lower right instead of two intersecting
4611 * lines but that's only really apparent for no-dashes,
4612 * which (for this reason) are done as one polygon and
4613 * don't to through this code path.
4616 dash_len = strlen (dash_list);
4619 gdk_gc_set_dashes (gc, 0, dash_list, dash_len);
4621 gdk_draw_lines (window, gc, points, 3);
4623 /* We draw this line one farther over than it is "supposed" to
4624 * because of another rasterization problem ... if two 1 pixel
4625 * unjoined lines meet at the lower right, there will be a missing
4632 gint dash_pixels = 0;
4635 /* Adjust the dash offset for the bottom and left so we
4636 * match up at the upper left.
4638 for (i = 0; i < dash_len; i++)
4639 dash_pixels += dash_list[i];
4641 if (dash_len % 2 == 1)
4644 gdk_gc_set_dashes (gc, dash_pixels - (width + height - 2 * line_width) % dash_pixels, dash_list, dash_len);
4647 gdk_draw_lines (window, gc, points + 2, 3);
4650 gdk_gc_set_line_attributes (gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
4653 gdk_gc_set_clip_rectangle (gc, NULL);
4660 gtk_default_draw_slider (GtkStyle *style,
4662 GtkStateType state_type,
4663 GtkShadowType shadow_type,
4666 const gchar *detail,
4671 GtkOrientation orientation)
4673 g_return_if_fail (GTK_IS_STYLE (style));
4674 g_return_if_fail (window != NULL);
4676 sanitize_size (window, &width, &height);
4678 gtk_paint_box (style, window, state_type, shadow_type,
4679 area, widget, detail, x, y, width, height);
4682 (strcmp ("hscale", detail) == 0 ||
4683 strcmp ("vscale", detail) == 0))
4685 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4686 gtk_paint_vline (style, window, state_type, area, widget, detail,
4687 y + style->ythickness,
4688 y + height - style->ythickness - 1, x + width / 2);
4690 gtk_paint_hline (style, window, state_type, area, widget, detail,
4691 x + style->xthickness,
4692 x + width - style->xthickness - 1, y + height / 2);
4697 draw_dot (GdkWindow *window,
4705 size = CLAMP (size, 2, 3);
4709 gdk_draw_point (window, light_gc, x, y);
4710 gdk_draw_point (window, light_gc, x+1, y+1);
4712 else if (size == 3);
4714 gdk_draw_point (window, light_gc, x, y);
4715 gdk_draw_point (window, light_gc, x+1, y);
4716 gdk_draw_point (window, light_gc, x, y+1);
4717 gdk_draw_point (window, dark_gc, x+1, y+2);
4718 gdk_draw_point (window, dark_gc, x+2, y+1);
4719 gdk_draw_point (window, dark_gc, x+2, y+2);
4724 gtk_default_draw_handle (GtkStyle *style,
4726 GtkStateType state_type,
4727 GtkShadowType shadow_type,
4730 const gchar *detail,
4735 GtkOrientation orientation)
4738 gint xthick, ythick;
4739 GdkGC *light_gc, *dark_gc;
4744 g_return_if_fail (GTK_IS_STYLE (style));
4745 g_return_if_fail (window != NULL);
4747 sanitize_size (window, &width, &height);
4749 gtk_paint_box (style, window, state_type, shadow_type, area, widget,
4750 detail, x, y, width, height);
4753 if (!strcmp (detail, "paned"))
4755 /* we want to ignore the shadow border in paned widgets */
4759 light_gc = style->light_gc[state_type];
4760 dark_gc = style->black_gc;
4764 xthick = style->xthickness;
4765 ythick = style->ythickness;
4767 light_gc = style->light_gc[state_type];
4768 dark_gc = style->dark_gc[state_type];
4771 rect.x = x + xthick;
4772 rect.y = y + ythick;
4773 rect.width = width - (xthick * 2);
4774 rect.height = height - (ythick * 2);
4777 intersect = gdk_rectangle_intersect (area, &rect, &dest);
4787 gdk_gc_set_clip_rectangle (light_gc, &dest);
4788 gdk_gc_set_clip_rectangle (dark_gc, &dest);
4790 if (!strcmp (detail, "paned"))
4792 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4793 for (xx = x + width/2 - 15; xx <= x + width/2 + 15; xx += 5)
4794 draw_dot (window, light_gc, dark_gc, xx, y + height/2 - 1, 3);
4796 for (yy = y + height/2 - 15; yy <= y + height/2 + 15; yy += 5)
4797 draw_dot (window, light_gc, dark_gc, x + width/2 - 1, yy, 3);
4801 for (yy = y + ythick; yy < (y + height - ythick); yy += 3)
4802 for (xx = x + xthick; xx < (x + width - xthick); xx += 6)
4804 draw_dot (window, light_gc, dark_gc, xx, yy, 2);
4805 draw_dot (window, light_gc, dark_gc, xx + 3, yy + 1, 2);
4809 gdk_gc_set_clip_rectangle (light_gc, NULL);
4810 gdk_gc_set_clip_rectangle (dark_gc, NULL);
4814 create_expander_affine (gdouble affine[6],
4824 width = expander_size / 4.0;
4825 height = expander_size / 2.0;
4827 s = sin (degrees * G_PI / 180.0);
4828 c = cos (degrees * G_PI / 180.0);
4834 affine[4] = -width * c - height * -s + x;
4835 affine[5] = -width * s - height * c + y;
4839 apply_affine_on_point (double affine[6], GdkPoint *point)
4843 x = point->x * affine[0] + point->y * affine[2] + affine[4];
4844 y = point->x * affine[1] + point->y * affine[3] + affine[5];
4846 point->x = floor (x);
4847 point->y = floor (y);
4851 gtk_style_draw_polygon_with_gc (GdkWindow *window, GdkGC *gc, gint line_width,
4852 gboolean do_fill, GdkPoint *points, gint n_points)
4854 gdk_gc_set_line_attributes (gc, line_width,
4856 GDK_CAP_BUTT, GDK_JOIN_MITER);
4858 gdk_draw_polygon (window, gc, do_fill, points, n_points);
4859 gdk_gc_set_line_attributes (gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
4863 gtk_default_draw_expander (GtkStyle *style,
4865 GtkStateType state_type,
4868 const gchar *detail,
4871 GtkExpanderStyle expander_style)
4880 gtk_widget_style_get (widget,
4881 "expander_size", &expander_size,
4883 line_width = MAX (1, expander_size/7);
4887 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], area);
4888 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], area);
4891 expander_size -= (line_width * 2 - 2);
4892 points[0].x = line_width / 2;
4893 points[0].y = line_width / 2;
4894 points[1].x = expander_size / 2 + line_width / 2;
4895 points[1].y = expander_size / 2 + line_width / 2;
4896 points[2].x = line_width / 2;
4897 points[2].y = expander_size + line_width / 2;
4899 switch (expander_style)
4901 case GTK_EXPANDER_COLLAPSED:
4902 degrees = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ? 180 : 0;
4904 case GTK_EXPANDER_SEMI_COLLAPSED:
4905 degrees = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ? 150 : 30;
4907 case GTK_EXPANDER_SEMI_EXPANDED:
4908 degrees = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ? 120 : 60;
4910 case GTK_EXPANDER_EXPANDED:
4914 g_assert_not_reached ();
4917 create_expander_affine (affine, degrees, expander_size, x, y);
4919 for (i = 0; i < 3; i++)
4920 apply_affine_on_point (affine, &points[i]);
4922 if (state_type == GTK_STATE_PRELIGHT)
4924 gtk_style_draw_polygon_with_gc (window, style->fg_gc[GTK_STATE_NORMAL],
4925 1, TRUE, points, 3);
4927 else if (state_type == GTK_STATE_ACTIVE)
4929 gtk_style_draw_polygon_with_gc (window, style->light_gc[GTK_STATE_ACTIVE],
4930 1, TRUE, points, 3);
4931 gtk_style_draw_polygon_with_gc (window, style->fg_gc[GTK_STATE_NORMAL],
4932 line_width, FALSE, points, 3);
4936 gtk_style_draw_polygon_with_gc (window, style->base_gc[GTK_STATE_NORMAL],
4937 1, TRUE, points, 3);
4938 gtk_style_draw_polygon_with_gc (window, style->fg_gc[GTK_STATE_NORMAL],
4939 line_width, FALSE, points, 3);
4943 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], NULL);
4944 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], NULL);
4948 typedef struct _ByteRange ByteRange;
4957 range_new (guint start,
4960 ByteRange *br = g_new (ByteRange, 1);
4969 get_insensitive_layout (GdkDrawable *drawable,
4970 PangoLayout *layout)
4972 GSList *embossed_ranges = NULL;
4973 GSList *stippled_ranges = NULL;
4974 PangoLayoutIter *iter;
4975 GSList *tmp_list = NULL;
4976 PangoLayout *new_layout;
4977 PangoAttrList *attrs;
4978 GdkBitmap *stipple = NULL;
4980 iter = pango_layout_get_iter (layout);
4984 PangoLayoutRun *run;
4985 PangoAttribute *attr;
4986 gboolean need_stipple = FALSE;
4989 run = pango_layout_iter_get_run (iter);
4993 tmp_list = run->item->analysis.extra_attrs;
4995 while (tmp_list != NULL)
4997 attr = tmp_list->data;
4998 switch (attr->klass->type)
5000 case PANGO_ATTR_FOREGROUND:
5001 case PANGO_ATTR_BACKGROUND:
5002 need_stipple = TRUE;
5012 tmp_list = g_slist_next (tmp_list);
5015 br = range_new (run->item->offset, run->item->offset + run->item->length);
5018 stippled_ranges = g_slist_prepend (stippled_ranges, br);
5020 embossed_ranges = g_slist_prepend (embossed_ranges, br);
5023 while (pango_layout_iter_next_run (iter));
5025 pango_layout_iter_free (iter);
5027 new_layout = pango_layout_copy (layout);
5029 attrs = pango_layout_get_attributes (new_layout);
5033 /* Create attr list if there wasn't one */
5034 attrs = pango_attr_list_new ();
5035 pango_layout_set_attributes (new_layout, attrs);
5036 pango_attr_list_unref (attrs);
5039 tmp_list = embossed_ranges;
5040 while (tmp_list != NULL)
5042 PangoAttribute *attr;
5043 ByteRange *br = tmp_list->data;
5045 attr = gdk_pango_attr_embossed_new (TRUE);
5047 attr->start_index = br->start;
5048 attr->end_index = br->end;
5050 pango_attr_list_change (attrs, attr);
5054 tmp_list = g_slist_next (tmp_list);
5057 g_slist_free (embossed_ranges);
5059 tmp_list = stippled_ranges;
5060 while (tmp_list != NULL)
5062 PangoAttribute *attr;
5063 ByteRange *br = tmp_list->data;
5065 if (stipple == NULL)
5067 #define gray50_width 2
5068 #define gray50_height 2
5069 static const char gray50_bits[] = {
5073 stipple = gdk_bitmap_create_from_data (drawable,
5074 gray50_bits, gray50_width,
5078 attr = gdk_pango_attr_stipple_new (stipple);
5080 attr->start_index = br->start;
5081 attr->end_index = br->end;
5083 pango_attr_list_change (attrs, attr);
5087 tmp_list = g_slist_next (tmp_list);
5090 g_slist_free (stippled_ranges);
5093 g_object_unref (stipple);
5099 gtk_default_draw_layout (GtkStyle *style,
5101 GtkStateType state_type,
5105 const gchar *detail,
5108 PangoLayout *layout)
5112 g_return_if_fail (GTK_IS_STYLE (style));
5113 g_return_if_fail (window != NULL);
5115 gc = use_text ? style->text_gc[state_type] : style->fg_gc[state_type];
5118 gdk_gc_set_clip_rectangle (gc, area);
5120 if (state_type == GTK_STATE_INSENSITIVE)
5124 ins = get_insensitive_layout (window, layout);
5126 gdk_draw_layout (window, gc, x, y, ins);
5128 g_object_unref (ins);
5132 gdk_draw_layout (window, gc, x, y, layout);
5136 gdk_gc_set_clip_rectangle (gc, NULL);
5140 gtk_default_draw_resize_grip (GtkStyle *style,
5142 GtkStateType state_type,
5145 const gchar *detail,
5152 g_return_if_fail (GTK_IS_STYLE (style));
5153 g_return_if_fail (window != NULL);
5157 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
5158 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
5159 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
5164 case GDK_WINDOW_EDGE_NORTH_WEST:
5165 /* make it square */
5170 else if (height < width)
5175 case GDK_WINDOW_EDGE_NORTH:
5181 case GDK_WINDOW_EDGE_NORTH_EAST:
5182 /* make it square, aligning to top right */
5187 else if (height < width)
5189 x += (width - height);
5193 case GDK_WINDOW_EDGE_WEST:
5199 case GDK_WINDOW_EDGE_EAST:
5200 /* aligning to right */
5203 x += (width - height);
5207 case GDK_WINDOW_EDGE_SOUTH_WEST:
5208 /* make it square, aligning to bottom left */
5211 y += (height - width);
5214 else if (height < width)
5219 case GDK_WINDOW_EDGE_SOUTH:
5220 /* align to bottom */
5223 y += (height - width);
5227 case GDK_WINDOW_EDGE_SOUTH_EAST:
5228 /* make it square, aligning to bottom right */
5231 y += (height - width);
5234 else if (height < width)
5236 x += (width - height);
5241 g_assert_not_reached ();
5243 /* Clear background */
5244 gtk_style_apply_default_background (style, window, FALSE,
5246 x, y, width, height);
5250 case GDK_WINDOW_EDGE_WEST:
5251 case GDK_WINDOW_EDGE_EAST:
5257 while (xi < x + width)
5259 gdk_draw_line (window,
5260 style->light_gc[state_type],
5265 gdk_draw_line (window,
5266 style->dark_gc[state_type],
5274 case GDK_WINDOW_EDGE_NORTH:
5275 case GDK_WINDOW_EDGE_SOUTH:
5281 while (yi < y + height)
5283 gdk_draw_line (window,
5284 style->light_gc[state_type],
5289 gdk_draw_line (window,
5290 style->dark_gc[state_type],
5298 case GDK_WINDOW_EDGE_NORTH_WEST:
5307 gdk_draw_line (window,
5308 style->dark_gc[state_type],
5315 gdk_draw_line (window,
5316 style->dark_gc[state_type],
5323 gdk_draw_line (window,
5324 style->light_gc[state_type],
5334 case GDK_WINDOW_EDGE_NORTH_EAST:
5341 while (xi < (x + width - 3))
5343 gdk_draw_line (window,
5344 style->light_gc[state_type],
5351 gdk_draw_line (window,
5352 style->dark_gc[state_type],
5359 gdk_draw_line (window,
5360 style->dark_gc[state_type],
5369 case GDK_WINDOW_EDGE_SOUTH_WEST:
5378 gdk_draw_line (window,
5379 style->dark_gc[state_type],
5386 gdk_draw_line (window,
5387 style->dark_gc[state_type],
5394 gdk_draw_line (window,
5395 style->light_gc[state_type],
5405 case GDK_WINDOW_EDGE_SOUTH_EAST:
5412 while (xi < (x + width - 3))
5414 gdk_draw_line (window,
5415 style->light_gc[state_type],
5422 gdk_draw_line (window,
5423 style->dark_gc[state_type],
5430 gdk_draw_line (window,
5431 style->dark_gc[state_type],
5441 g_assert_not_reached ();
5447 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
5448 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
5449 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
5454 gtk_style_shade (GdkColor *a,
5462 red = (gdouble) a->red / 65535.0;
5463 green = (gdouble) a->green / 65535.0;
5464 blue = (gdouble) a->blue / 65535.0;
5466 rgb_to_hls (&red, &green, &blue);
5471 else if (green < 0.0)
5477 else if (blue < 0.0)
5480 hls_to_rgb (&red, &green, &blue);
5482 b->red = red * 65535.0;
5483 b->green = green * 65535.0;
5484 b->blue = blue * 65535.0;
5488 rgb_to_hls (gdouble *r,
5529 l = (max + min) / 2;
5536 s = (max - min) / (max + min);
5538 s = (max - min) / (2 - max - min);
5542 h = (green - blue) / delta;
5543 else if (green == max)
5544 h = 2 + (blue - red) / delta;
5545 else if (blue == max)
5546 h = 4 + (red - green) / delta;
5559 hls_to_rgb (gdouble *h,
5572 if (lightness <= 0.5)
5573 m2 = lightness * (1 + saturation);
5575 m2 = lightness + saturation - lightness * saturation;
5576 m1 = 2 * lightness - m2;
5578 if (saturation == 0)
5593 r = m1 + (m2 - m1) * hue / 60;
5597 r = m1 + (m2 - m1) * (240 - hue) / 60;
5608 g = m1 + (m2 - m1) * hue / 60;
5612 g = m1 + (m2 - m1) * (240 - hue) / 60;
5623 b = m1 + (m2 - m1) * hue / 60;
5627 b = m1 + (m2 - m1) * (240 - hue) / 60;
5640 * @style: a #GtkStyle
5641 * @window: a #GdkWindow
5642 * @state_type: a state
5643 * @area: rectangle to which the output is clipped
5644 * @widget: the widget
5645 * @detail: a style detail
5646 * @x1: the starting x coordinate
5647 * @x2: the ending x coordinate
5648 * @y: the y coordinate
5650 * Draws a horizontal line from (@x1, @y) to (@x2, @y) in @window
5651 * using the given style and state.
5654 gtk_paint_hline (GtkStyle *style,
5656 GtkStateType state_type,
5659 const gchar *detail,
5664 g_return_if_fail (GTK_IS_STYLE (style));
5665 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
5667 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, area, widget, detail, x1, x2, y);
5672 * @style: a #GtkStyle
5673 * @window: a #GdkWindow
5674 * @state_type: a state
5675 * @area: rectangle to which the output is clipped
5676 * @widget: the widget
5677 * @detail: a style detail
5678 * @y1_: the starting y coordinate
5679 * @y2_: the ending y coordinate
5680 * @x: the x coordinate
5682 * Draws a vertical line from (@x, @y1_) to (@x, @y2_) in @window
5683 * using the given style and state.
5686 gtk_paint_vline (GtkStyle *style,
5688 GtkStateType state_type,
5691 const gchar *detail,
5696 g_return_if_fail (GTK_IS_STYLE (style));
5697 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
5699 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, area, widget, detail, y1_, y2_, x);
5704 * @style: a #GtkStyle
5705 * @window: a #GdkWindow
5706 * @state_type: a state
5707 * @shadow_type: type of shadow to draw
5708 * @area: clip rectangle
5709 * @widget: the widget
5710 * @detail: a style detail
5711 * @x: x origin of the rectangle
5712 * @y: y origin of the rectangle
5713 * @width: width of the rectangle
5714 * @height: width of the rectangle
5716 * Draws a shadow around the given rectangle in @window
5717 * using the given style and state and shadow type.
5720 gtk_paint_shadow (GtkStyle *style,
5722 GtkStateType state_type,
5723 GtkShadowType shadow_type,
5726 const gchar *detail,
5732 g_return_if_fail (GTK_IS_STYLE (style));
5733 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
5735 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5739 * gtk_paint_polygon:
5740 * @style: a #GtkStyle
5741 * @window: a #GdkWindow
5742 * @state_type: a state
5743 * @shadow_type: type of shadow to draw
5744 * @area: clip rectangle
5745 * @widget: the widget
5746 * @detail: a style detail
5747 * @points: an array of #GdkPoint<!-- -->s
5748 * @npoints: length of @points
5749 * @fill: %TRUE if the polygon should be filled
5751 * Draws a polygon on @window with the given parameters.
5754 gtk_paint_polygon (GtkStyle *style,
5756 GtkStateType state_type,
5757 GtkShadowType shadow_type,
5760 const gchar *detail,
5765 g_return_if_fail (GTK_IS_STYLE (style));
5766 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
5768 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, area, widget, detail, points, npoints, fill);
5773 * @style: a #GtkStyle
5774 * @window: a #GdkWindow
5775 * @state_type: a state
5776 * @shadow_type: the type of shadow to draw
5777 * @area: clip rectangle
5778 * @widget: the widget
5779 * @detail: a style detail
5780 * @arrow_type: the type of arrow to draw
5781 * @fill: %TRUE if the arrow tip should be filled
5782 * @x: x origin of the rectangle to draw the arrow in
5783 * @y: y origin of the rectangle to draw the arrow in
5784 * @width: width of the rectangle to draw the arrow in
5785 * @height: height of the rectangle to draw the arrow in
5787 * Draws an arrow in the given rectangle on @window using the given
5788 * parameters. @arrow_type determines the direction of the arrow.
5791 gtk_paint_arrow (GtkStyle *style,
5793 GtkStateType state_type,
5794 GtkShadowType shadow_type,
5797 const gchar *detail,
5798 GtkArrowType arrow_type,
5805 g_return_if_fail (GTK_IS_STYLE (style));
5806 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
5808 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, area, widget, detail, arrow_type, fill, x, y, width, height);
5812 * gtk_paint_diamond:
5813 * @style: a #GtkStyle
5814 * @window: a #GdkWindow
5815 * @state_type: a state
5816 * @shadow_type: the type of shadow to draw
5817 * @area: clip rectangle
5818 * @widget: the widget
5819 * @detail: a style detail
5820 * @x: x origin of the rectangle to draw the diamond in
5821 * @y: y origin of the rectangle to draw the diamond in
5822 * @width: width of the rectangle to draw the diamond in
5823 * @height: height of the rectangle to draw the diamond in
5825 * Draws a diamond in the given rectangle on @window using the given
5829 gtk_paint_diamond (GtkStyle *style,
5831 GtkStateType state_type,
5832 GtkShadowType shadow_type,
5835 const gchar *detail,
5841 g_return_if_fail (GTK_IS_STYLE (style));
5842 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
5844 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5849 * @style: a #GtkStyle
5850 * @window: a #GdkWindow
5851 * @state_type: a state
5852 * @area: clip rectangle
5853 * @widget: the widget
5854 * @detail: a style detail
5857 * @string: the string to draw
5859 * Draws a text string on @window with the given parameters.
5861 * Deprecated: Use gtk_paint_layout() instead.
5864 gtk_paint_string (GtkStyle *style,
5866 GtkStateType state_type,
5869 const gchar *detail,
5872 const gchar *string)
5874 g_return_if_fail (GTK_IS_STYLE (style));
5875 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
5877 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, area, widget, detail, x, y, string);
5882 * @style: a #GtkStyle
5883 * @window: a #GdkWindow
5884 * @state_type: a state
5885 * @shadow_type: the type of shadow to draw
5886 * @area: clip rectangle
5887 * @widget: the widget
5888 * @detail: a style detail
5889 * @x: x origin of the box
5890 * @y: y origin of the box
5891 * @width: the width of the box
5892 * @height: the height of the box
5894 * Draws a box on @window with the given parameters.
5897 gtk_paint_box (GtkStyle *style,
5899 GtkStateType state_type,
5900 GtkShadowType shadow_type,
5903 const gchar *detail,
5909 g_return_if_fail (GTK_IS_STYLE (style));
5910 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
5912 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5916 * gtk_paint_flat_box:
5917 * @style: a #GtkStyle
5918 * @window: a #GdkWindow
5919 * @state_type: a state
5920 * @shadow_type: the type of shadow to draw
5921 * @area: clip rectangle
5922 * @widget: the widget
5923 * @detail: a style detail
5924 * @x: x origin of the box
5925 * @y: y origin of the box
5926 * @width: the width of the box
5927 * @height: the height of the box
5929 * Draws a flat box on @window with the given parameters.
5932 gtk_paint_flat_box (GtkStyle *style,
5934 GtkStateType state_type,
5935 GtkShadowType shadow_type,
5938 const gchar *detail,
5944 g_return_if_fail (GTK_IS_STYLE (style));
5945 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
5947 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5952 * @style: a #GtkStyle
5953 * @window: a #GdkWindow
5954 * @state_type: a state
5955 * @shadow_type: the type of shadow to draw
5956 * @area: clip rectangle
5957 * @widget: the widget
5958 * @detail: a style detail
5959 * @x: x origin of the rectangle to draw the check in
5960 * @y: y origin of the rectangle to draw the check in
5961 * @width: the width of the rectangle to draw the check in
5962 * @height: the height of the rectangle to draw the check in
5964 * Draws a check button indicator in the given rectangle on @window with
5965 * the given parameters.
5968 gtk_paint_check (GtkStyle *style,
5970 GtkStateType state_type,
5971 GtkShadowType shadow_type,
5974 const gchar *detail,
5980 g_return_if_fail (GTK_IS_STYLE (style));
5981 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
5983 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5988 * @style: a #GtkStyle
5989 * @window: a #GdkWindow
5990 * @state_type: a state
5991 * @shadow_type: the type of shadow to draw
5992 * @area: clip rectangle
5993 * @widget: the widget
5994 * @detail: a style detail
5995 * @x: x origin of the rectangle to draw the option in
5996 * @y: y origin of the rectangle to draw the option in
5997 * @width: the width of the rectangle to draw the option in
5998 * @height: the height of the rectangle to draw the option in
6000 * Draws a radio button indicator in the given rectangle on @window with
6001 * the given parameters.
6004 gtk_paint_option (GtkStyle *style,
6006 GtkStateType state_type,
6007 GtkShadowType shadow_type,
6010 const gchar *detail,
6016 g_return_if_fail (GTK_IS_STYLE (style));
6017 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
6019 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
6024 * @style: a #GtkStyle
6025 * @window: a #GdkWindow
6026 * @state_type: a state
6027 * @shadow_type: the type of shadow to draw
6028 * @area: clip rectangle
6029 * @widget: the widget
6030 * @detail: a style detail
6031 * @x: x origin of the rectangle to draw the tab in
6032 * @y: y origin of the rectangle to draw the tab in
6033 * @width: the width of the rectangle to draw the tab in
6034 * @height: the height of the rectangle to draw the tab in
6036 * Draws an option menu tab (i.e. the up and down pointing arrows)
6037 * in the given rectangle on @window using the given parameters.
6040 gtk_paint_tab (GtkStyle *style,
6042 GtkStateType state_type,
6043 GtkShadowType shadow_type,
6046 const gchar *detail,
6052 g_return_if_fail (GTK_IS_STYLE (style));
6053 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
6055 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
6059 * gtk_paint_shadow_gap:
6060 * @style: a #GtkStyle
6061 * @window: a #GdkWindow
6062 * @state_type: a state
6063 * @shadow_type: type of shadow to draw
6064 * @area: clip rectangle
6065 * @widget: the widget
6066 * @detail: a style detail
6067 * @x: x origin of the rectangle
6068 * @y: y origin of the rectangle
6069 * @width: width of the rectangle
6070 * @height: width of the rectangle
6071 * @gap_side: side in which to leave the gap
6072 * @gap_x: starting position of the gap
6073 * @gap_width: width of the gap
6075 * Draws a shadow around the given rectangle in @window
6076 * using the given style and state and shadow type, leaving a
6080 gtk_paint_shadow_gap (GtkStyle *style,
6082 GtkStateType state_type,
6083 GtkShadowType shadow_type,
6091 GtkPositionType gap_side,
6095 g_return_if_fail (GTK_IS_STYLE (style));
6096 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
6098 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);
6103 * gtk_paint_box_gap:
6104 * @style: a #GtkStyle
6105 * @window: a #GdkWindow
6106 * @state_type: a state
6107 * @shadow_type: type of shadow to draw
6108 * @area: clip rectangle
6109 * @widget: the widget
6110 * @detail: a style detail
6111 * @x: x origin of the rectangle
6112 * @y: y origin of the rectangle
6113 * @width: width of the rectangle
6114 * @height: width of the rectangle
6115 * @gap_side: side in which to leave the gap
6116 * @gap_x: starting position of the gap
6117 * @gap_width: width of the gap
6119 * Draws a box in @window using the given style and state and shadow type,
6120 * leaving a gap in one side.
6123 gtk_paint_box_gap (GtkStyle *style,
6125 GtkStateType state_type,
6126 GtkShadowType shadow_type,
6134 GtkPositionType gap_side,
6138 g_return_if_fail (GTK_IS_STYLE (style));
6139 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
6141 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);
6145 * gtk_paint_extension:
6146 * @style: a #GtkStyle
6147 * @window: a #GdkWindow
6148 * @state_type: a state
6149 * @shadow_type: type of shadow to draw
6150 * @area: clip rectangle
6151 * @widget: the widget
6152 * @detail: a style detail
6153 * @x: x origin of the extension
6154 * @y: y origin of the extension
6155 * @width: width of the extension
6156 * @height: width of the extension
6157 * @gap_side: the side on to which the extension is attached
6159 * Draws an extension, i.e. a notebook tab.
6162 gtk_paint_extension (GtkStyle *style,
6164 GtkStateType state_type,
6165 GtkShadowType shadow_type,
6173 GtkPositionType gap_side)
6175 g_return_if_fail (GTK_IS_STYLE (style));
6176 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
6178 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side);
6183 * @style: a #GtkStyle
6184 * @window: a #GdkWindow
6185 * @state_type: a state
6186 * @area: clip rectangle
6187 * @widget: the widget
6188 * @detail: a style detail
6189 * @x: the x origin of the rectangle around which to draw a focus indicator
6190 * @y: the y origin of the rectangle around which to draw a focus indicator
6191 * @width: the width of the rectangle around which to draw a focus indicator
6192 * @height: the height of the rectangle around which to draw a focus indicator
6194 * Draws a focus indicator around the given rectangle on @window using the
6198 gtk_paint_focus (GtkStyle *style,
6200 GtkStateType state_type,
6203 const gchar *detail,
6209 g_return_if_fail (GTK_IS_STYLE (style));
6210 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
6212 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, state_type, area, widget, detail, x, y, width, height);
6216 gtk_paint_slider (GtkStyle *style,
6218 GtkStateType state_type,
6219 GtkShadowType shadow_type,
6222 const gchar *detail,
6227 GtkOrientation orientation)
6229 g_return_if_fail (GTK_IS_STYLE (style));
6230 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
6232 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
6237 * @style: a #GtkStyle
6238 * @window: a #GdkWindow
6239 * @state_type: a state
6240 * @shadow_type: type of shadow to draw
6241 * @area: clip rectangle
6242 * @widget: the widget
6243 * @detail: a style detail
6244 * @x: x origin of the handle
6245 * @y: y origin of the handle
6246 * @width: with of the handle
6247 * @height: height of the handle
6248 * @orientation: the orientation of the handle
6250 * Draws a handle as used in #GtkHandleBox and #GtkPaned.
6253 gtk_paint_handle (GtkStyle *style,
6255 GtkStateType state_type,
6256 GtkShadowType shadow_type,
6259 const gchar *detail,
6264 GtkOrientation orientation)
6266 g_return_if_fail (GTK_IS_STYLE (style));
6267 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
6269 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
6273 * gtk_paint_expander:
6274 * @style: a #GtkStyle
6275 * @window: a #GdkWindow
6276 * @state_type: a state
6277 * @area: clip rectangle
6278 * @widget: the widget
6279 * @detail: a style detail
6280 * @x: the x position to draw the expander at
6281 * @y: the y position to draw the expander at
6282 * @expander_style: the style to draw the expander in
6284 * Draws an expander as used in #GtkTreeView.
6287 gtk_paint_expander (GtkStyle *style,
6289 GtkStateType state_type,
6292 const gchar *detail,
6295 GtkExpanderStyle expander_style)
6297 g_return_if_fail (GTK_IS_STYLE (style));
6298 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
6300 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type, area,
6301 widget, detail, x, y, expander_style);
6305 gtk_paint_layout (GtkStyle *style,
6307 GtkStateType state_type,
6311 const gchar *detail,
6314 PangoLayout *layout)
6316 g_return_if_fail (GTK_IS_STYLE (style));
6317 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
6319 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text, area,
6320 widget, detail, x, y, layout);
6324 * gtk_paint_resize_grip:
6325 * @style: a #GtkStyle
6326 * @window: a #GdkWindow
6327 * @state_type: a state
6328 * @area: clip rectangle
6329 * @widget: the widget
6330 * @detail: a style detail
6331 * @edge: the edge in which to draw the resize grip
6332 * @x: the x origin of the rectangle in which to draw the resize grip
6333 * @y: the y origin of the rectangle in which to draw the resize grip
6334 * @width: the width of the rectangle in which to draw the resize grip
6335 * @height: the height of the rectangle in which to draw the resize grip
6337 * Draws a resize grip in the given rectangle on @window using the given
6341 gtk_paint_resize_grip (GtkStyle *style,
6343 GtkStateType state_type,
6346 const gchar *detail,
6354 g_return_if_fail (GTK_IS_STYLE (style));
6355 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
6357 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
6358 area, widget, detail,
6359 edge, x, y, width, height);
6364 * @border_: a #GtkBorder.
6365 * @returns: a copy of @border_.
6367 * Copies a #GtkBorder structure.
6370 gtk_border_copy (const GtkBorder *border)
6372 return (GtkBorder *)g_memdup (border, sizeof (GtkBorder));
6377 * @border_: a #GtkBorder.
6379 * Frees a #GtkBorder structure.
6382 gtk_border_free (GtkBorder *border)
6388 gtk_border_get_type (void)
6390 static GType our_type = 0;
6393 our_type = g_boxed_type_register_static ("GtkBorder",
6394 (GBoxedCopyFunc) gtk_border_copy,
6395 (GBoxedFreeFunc) gtk_border_free);
6401 gtk_style_get_font_internal (GtkStyle *style)
6403 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
6405 if (style->private_font && style->private_font_desc)
6407 if (!style->font_desc ||
6408 !pango_font_description_equal (style->private_font_desc, style->font_desc))
6410 gdk_font_unref (style->private_font);
6411 style->private_font = NULL;
6413 if (style->private_font_desc)
6415 pango_font_description_free (style->private_font_desc);
6416 style->private_font_desc = NULL;
6421 if (!style->private_font)
6423 GdkDisplay *display;
6425 if (style->colormap)
6427 display = gdk_screen_get_display (gdk_colormap_get_screen (style->colormap));
6431 display = gdk_display_get_default ();
6432 GTK_NOTE (MULTIHEAD,
6433 g_warning ("gtk_style_get_font() should not be called on an unattached style"));
6436 if (style->font_desc)
6438 style->private_font = gdk_font_from_description_for_display (display, style->font_desc);
6439 style->private_font_desc = pango_font_description_copy (style->font_desc);
6442 if (!style->private_font)
6443 style->private_font = gdk_font_load_for_display (display, "fixed");
6445 if (!style->private_font)
6446 g_error ("Unable to load \"fixed\" font");
6449 return style->private_font;
6453 * gtk_style_get_font:
6454 * @style: a #GtkStyle
6456 * Gets the #GdkFont to use for the given style. This is
6457 * meant only as a replacement for direct access to @style->font
6458 * and should not be used in new code. New code should
6459 * use @style->font_desc instead.
6461 * Return value: the #GdkFont for the style. This font is owned
6462 * by the style; if you want to keep around a copy, you must
6463 * call gdk_font_ref().
6466 gtk_style_get_font (GtkStyle *style)
6468 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
6470 return gtk_style_get_font_internal (style);
6474 * gtk_style_set_font:
6475 * @style: a #GtkStyle.
6476 * @font: a #GdkFont, or %NULL to use the #GdkFont corresponding
6477 * to style->font_desc.
6479 * Sets the #GdkFont to use for a given style. This is
6480 * meant only as a replacement for direct access to style->font
6481 * and should not be used in new code. New code should
6482 * use style->font_desc instead.
6485 gtk_style_set_font (GtkStyle *style,
6490 g_return_if_fail (GTK_IS_STYLE (style));
6492 old_font = style->private_font;
6494 style->private_font = font;
6496 gdk_font_ref (font);
6499 gdk_font_unref (old_font);
6501 if (style->private_font_desc)
6503 pango_font_description_free (style->private_font_desc);
6504 style->private_font_desc = NULL;
6508 typedef struct _CursorInfo CursorInfo;
6514 GdkGC *secondary_gc;
6518 style_unrealize_cursor_gcs (GtkStyle *style)
6522 cursor_info = g_object_get_data (G_OBJECT (style), "gtk-style-cursor-info");
6525 if (cursor_info->primary_gc)
6526 gtk_gc_release (cursor_info->primary_gc);
6528 if (cursor_info->secondary_gc)
6529 gtk_gc_release (cursor_info->secondary_gc);
6531 g_free (cursor_info);
6532 g_object_set_data (G_OBJECT (style), "gtk-style-cursor-info", NULL);
6537 make_cursor_gc (GtkWidget *widget,
6538 const gchar *property_name,
6539 const GdkColor *fallback)
6541 GdkGCValues gc_values;
6542 GdkGCValuesMask gc_values_mask;
6543 GdkColor *cursor_color;
6545 gtk_widget_style_get (widget, property_name, &cursor_color, NULL);
6547 gc_values_mask = GDK_GC_FOREGROUND;
6550 gc_values.foreground = *cursor_color;
6551 gdk_color_free (cursor_color);
6554 gc_values.foreground = *fallback;
6556 gdk_rgb_find_color (widget->style->colormap, &gc_values.foreground);
6557 return gtk_gc_get (widget->style->depth, widget->style->colormap, &gc_values, gc_values_mask);
6561 * _gtk_get_insertion_cursor_gc:
6562 * @widget: a #GtkWidget
6563 * @is_primary: if the cursor should be the primary cursor color.
6565 * Get a GC suitable for drawing the primary or secondary text
6568 * Note: the return value is ref'ed because calls to this function
6569 * on other widgets could result in this the GC being released
6570 * which would be an unexpected side effect. If made public,
6571 * this function should possibly be called create_insertion_cursor_gc().
6573 * Return value: an appropriate #GdkGC. Call g_object_unref() on
6574 * the gc when you are done with it; this GC may be shared with
6575 * other users, so you must not modify the GC except for temporarily
6576 * setting the clip before drawing with the GC, and then unsetting the clip
6580 _gtk_get_insertion_cursor_gc (GtkWidget *widget,
6581 gboolean is_primary)
6583 CursorInfo *cursor_info;
6585 cursor_info = g_object_get_data (G_OBJECT (widget->style), "gtk-style-cursor-info");
6588 cursor_info = g_new (CursorInfo, 1);
6589 g_object_set_data (G_OBJECT (widget->style), "gtk-style-cursor-info", cursor_info);
6590 cursor_info->primary_gc = NULL;
6591 cursor_info->secondary_gc = NULL;
6592 cursor_info->for_type = G_TYPE_INVALID;
6595 /* We have to keep track of the type because gtk_widget_style_get()
6596 * can return different results when called on the same property and
6597 * same style but for different widgets. :-(. That is,
6598 * GtkEntry::cursor-color = "red" in a style will modify the cursor
6599 * color for entries but not for text view.
6601 if (cursor_info->for_type != G_OBJECT_TYPE (widget))
6603 cursor_info->for_type = G_OBJECT_TYPE (widget);
6604 if (cursor_info->primary_gc)
6606 gtk_gc_release (cursor_info->primary_gc);
6607 cursor_info->primary_gc = NULL;
6609 if (cursor_info->secondary_gc)
6611 gtk_gc_release (cursor_info->secondary_gc);
6612 cursor_info->secondary_gc = NULL;
6618 if (!cursor_info->primary_gc)
6619 cursor_info->primary_gc = make_cursor_gc (widget,
6621 &widget->style->black);
6623 return g_object_ref (cursor_info->primary_gc);
6627 static const GdkColor gray = { 0, 0x8888, 0x8888, 0x8888 };
6629 if (!cursor_info->secondary_gc)
6630 cursor_info->secondary_gc = make_cursor_gc (widget,
6631 "secondary-cursor-color",
6634 return g_object_ref (cursor_info->secondary_gc);
6639 * _gtk_draw_insertion_cursor:
6640 * @widget: a #GtkWidget
6641 * @drawable: a #GdkDrawable
6643 * @location: location where to draw the cursor (@location->width is ignored)
6644 * @direction: whether the cursor is left-to-right or
6645 * right-to-left. Should never be #GTK_TEXT_DIR_NONE
6646 * @draw_arrow: %TRUE to draw a directional arrow on the
6647 * cursor. Should be %FALSE unless the cursor is split.
6649 * Draws a text caret on @drawable at @location. This is not a style function
6650 * but merely a convenience function for drawing the standard cursor shape.
6653 _gtk_draw_insertion_cursor (GtkWidget *widget,
6654 GdkDrawable *drawable,
6656 GdkRectangle *location,
6657 GtkTextDirection direction,
6658 gboolean draw_arrow)
6664 gfloat cursor_aspect_ratio;
6667 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
6669 gtk_widget_style_get (widget, "cursor-aspect-ratio", &cursor_aspect_ratio, NULL);
6671 stem_width = location->height * cursor_aspect_ratio + 1;
6672 arrow_width = stem_width + 1;
6674 /* put (stem_width % 2) on the proper side of the cursor */
6675 if (direction == GTK_TEXT_DIR_LTR)
6676 offset = stem_width / 2;
6678 offset = stem_width - stem_width / 2;
6680 for (i = 0; i < stem_width; i++)
6681 gdk_draw_line (drawable, gc,
6682 location->x + i - offset, location->y,
6683 location->x + i - offset, location->y + location->height - 1);
6687 if (direction == GTK_TEXT_DIR_RTL)
6689 x = location->x - offset - 1;
6690 y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
6692 for (i = 0; i < arrow_width; i++)
6694 gdk_draw_line (drawable, gc,
6696 x, y + 2 * arrow_width - i - 1);
6700 else if (direction == GTK_TEXT_DIR_LTR)
6702 x = location->x + stem_width - offset;
6703 y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
6705 for (i = 0; i < arrow_width; i++)
6707 gdk_draw_line (drawable, gc,
6709 x, y + 2 * arrow_width - i - 1);