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 GtkRequisition default_option_indicator_size = { 7, 13 };
323 static 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 GdkColor gtk_default_normal_fg = { 0, 0, 0, 0 };
450 static GdkColor gtk_default_active_fg = { 0, 0, 0, 0 };
451 static GdkColor gtk_default_prelight_fg = { 0, 0, 0, 0 };
452 static GdkColor gtk_default_selected_fg = { 0, 0xffff, 0xffff, 0xffff };
453 static GdkColor gtk_default_insensitive_fg = { 0, 0x7530, 0x7530, 0x7530 };
455 static GdkColor gtk_default_normal_bg = { 0, 0xdcdc, 0xdada, 0xd5d5 };
456 static GdkColor gtk_default_active_bg = { 0, 0xbaba, 0xb5b5, 0xabab };
457 static GdkColor gtk_default_prelight_bg = { 0, 0xeeee, 0xebeb, 0xe7e7 };
458 static GdkColor gtk_default_selected_bg = { 0, 0x4b4b, 0x6969, 0x8383 };
459 static GdkColor gtk_default_insensitive_bg = { 0, 0xdcdc, 0xdada, 0xd5d5 };
460 static GdkColor gtk_default_selected_base = { 0, 0x4b4b, 0x6969, 0x8383 };
461 static 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 #GtkWindow.
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 * This function is 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 * This function is 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 * This function is 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 * This function is 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 * This function is 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 parameters.
1098 * This function is deprecated, use gtk_paint_diamond() instead.
1101 gtk_draw_diamond (GtkStyle *style,
1103 GtkStateType state_type,
1104 GtkShadowType shadow_type,
1110 g_return_if_fail (GTK_IS_STYLE (style));
1111 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
1113 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1118 * @style: a #GtkStyle
1119 * @window: a #GdkWindow
1120 * @state_type: a state
1123 * @string: the string to draw
1125 * Draws a text string on @window with the given parameters.
1127 * This function is deprecated, use gtk_paint_layout() instead.
1130 gtk_draw_string (GtkStyle *style,
1132 GtkStateType state_type,
1135 const gchar *string)
1137 g_return_if_fail (GTK_IS_STYLE (style));
1138 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
1140 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, NULL, NULL, NULL, x, y, string);
1145 * @style: a #GtkStyle
1146 * @window: a #GdkWindow
1147 * @state_type: a state
1148 * @shadow_type: the type of shadow to draw
1149 * @x: x origin of the box
1150 * @y: y origin of the box
1151 * @width: the width of the box
1152 * @height: the height of the box
1154 * Draws a box on @window with the given parameters.
1156 * This function is deprecated, use gtk_paint_box() instead.
1159 gtk_draw_box (GtkStyle *style,
1161 GtkStateType state_type,
1162 GtkShadowType shadow_type,
1168 g_return_if_fail (GTK_IS_STYLE (style));
1169 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
1171 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1175 * gtk_draw_flat_box:
1176 * @style: a #GtkStyle
1177 * @window: a #GdkWindow
1178 * @state_type: a state
1179 * @shadow_type: the type of shadow to draw
1180 * @x: x origin of the box
1181 * @y: y origin of the box
1182 * @width: the width of the box
1183 * @height: the height of the box
1185 * Draws a flat box on @window with the given parameters.
1187 * This function is deprecated, use gtk_paint_flat_box() instead.
1190 gtk_draw_flat_box (GtkStyle *style,
1192 GtkStateType state_type,
1193 GtkShadowType shadow_type,
1199 g_return_if_fail (GTK_IS_STYLE (style));
1200 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
1202 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1207 * @style: a #GtkStyle
1208 * @window: a #GdkWindow
1209 * @state_type: a state
1210 * @shadow_type: the type of shadow to draw
1211 * @x: x origin of the rectangle to draw the check in
1212 * @y: y origin of the rectangle to draw the check in
1213 * @width: the width of the rectangle to draw the check in
1214 * @height: the height of the rectangle to draw the check in
1216 * Draws a check button indicator in the given rectangle on @window with
1217 * the given parameters.
1219 * This function is deprecated, use gtk_paint_check() instead.
1222 gtk_draw_check (GtkStyle *style,
1224 GtkStateType state_type,
1225 GtkShadowType shadow_type,
1231 g_return_if_fail (GTK_IS_STYLE (style));
1232 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
1234 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1239 * @style: a #GtkStyle
1240 * @window: a #GdkWindow
1241 * @state_type: a state
1242 * @shadow_type: the type of shadow to draw
1243 * @x: x origin of the rectangle to draw the option in
1244 * @y: y origin of the rectangle to draw the option in
1245 * @width: the width of the rectangle to draw the option in
1246 * @height: the height of the rectangle to draw the option in
1248 * Draws a radio button indicator in the given rectangle on @window with
1249 * the given parameters.
1251 * This function is deprecated, use gtk_paint_option() instead.
1254 gtk_draw_option (GtkStyle *style,
1256 GtkStateType state_type,
1257 GtkShadowType shadow_type,
1263 g_return_if_fail (GTK_IS_STYLE (style));
1264 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
1266 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1271 * @style: a #GtkStyle
1272 * @window: a #GdkWindow
1273 * @state_type: a state
1274 * @shadow_type: the type of shadow to draw
1275 * @x: x origin of the rectangle to draw the tab in
1276 * @y: y origin of the rectangle to draw the tab in
1277 * @width: the width of the rectangle to draw the tab in
1278 * @height: the height of the rectangle to draw the tab in
1280 * Draws an option menu tab (i.e. the up and down pointing arrows)
1281 * in the given rectangle on @window using the given parameters.
1283 * This function is deprecated, use gtk_paint_tab() instead.
1286 gtk_draw_tab (GtkStyle *style,
1288 GtkStateType state_type,
1289 GtkShadowType shadow_type,
1295 g_return_if_fail (GTK_IS_STYLE (style));
1296 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
1298 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1302 gtk_draw_shadow_gap (GtkStyle *style,
1304 GtkStateType state_type,
1305 GtkShadowType shadow_type,
1310 GtkPositionType gap_side,
1314 g_return_if_fail (GTK_IS_STYLE (style));
1315 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
1317 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);
1321 gtk_draw_box_gap (GtkStyle *style,
1323 GtkStateType state_type,
1324 GtkShadowType shadow_type,
1329 GtkPositionType gap_side,
1333 g_return_if_fail (GTK_IS_STYLE (style));
1334 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
1336 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);
1340 gtk_draw_extension (GtkStyle *style,
1342 GtkStateType state_type,
1343 GtkShadowType shadow_type,
1348 GtkPositionType gap_side)
1350 g_return_if_fail (GTK_IS_STYLE (style));
1351 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
1353 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side);
1358 * @style: a #GtkStyle
1359 * @window: a #GdkWindow
1360 * @x: the x origin of the rectangle around which to draw a focus indicator
1361 * @y: the y origin of the rectangle around which to draw a focus indicator
1362 * @width: the width of the rectangle around which to draw a focus indicator
1363 * @height: the height of the rectangle around which to draw a focus indicator
1365 * Draws a focus indicator around the given rectangle on @window using the
1368 * This function is deprecated, use gtk_paint_focus() instead.
1371 gtk_draw_focus (GtkStyle *style,
1378 g_return_if_fail (GTK_IS_STYLE (style));
1379 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
1381 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, GTK_STATE_NORMAL, NULL, NULL, NULL, x, y, width, height);
1385 gtk_draw_slider (GtkStyle *style,
1387 GtkStateType state_type,
1388 GtkShadowType shadow_type,
1393 GtkOrientation orientation)
1395 g_return_if_fail (GTK_IS_STYLE (style));
1396 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
1398 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
1402 gtk_draw_handle (GtkStyle *style,
1404 GtkStateType state_type,
1405 GtkShadowType shadow_type,
1410 GtkOrientation orientation)
1412 g_return_if_fail (GTK_IS_STYLE (style));
1413 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
1415 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
1419 gtk_draw_expander (GtkStyle *style,
1421 GtkStateType state_type,
1424 GtkExpanderStyle expander_style)
1426 g_return_if_fail (GTK_IS_STYLE (style));
1427 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
1429 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type,
1431 x, y, expander_style);
1435 gtk_draw_layout (GtkStyle *style,
1437 GtkStateType state_type,
1441 PangoLayout *layout)
1443 g_return_if_fail (GTK_IS_STYLE (style));
1444 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
1446 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text,
1452 * gtk_draw_resize_grip:
1453 * @style: a #GtkStyle
1454 * @window: a #GdkWindow
1455 * @state_type: a state
1456 * @edge: the edge in which to draw the resize grip
1457 * @x: the x origin of the rectangle in which to draw the resize grip
1458 * @y: the y origin of the rectangle in which to draw the resize grip
1459 * @width: the width of the rectangle in which to draw the resize grip
1460 * @height: the height of the rectangle in which to draw the resize grip
1462 * Draws a resize grip in the given rectangle on @window using the given
1465 * This function is deprecated, use gtk_paint_resize_grip() instead.
1468 gtk_draw_resize_grip (GtkStyle *style,
1470 GtkStateType state_type,
1477 g_return_if_fail (GTK_IS_STYLE (style));
1478 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
1480 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
1483 x, y, width, height);
1488 * gtk_style_set_background:
1489 * @style: a #GtkStyle
1490 * @window: a #GdkWindow
1491 * @state_type: a state
1493 * Sets the background of @window to the background color or pixmap
1494 * specified by @style for the given state.
1497 gtk_style_set_background (GtkStyle *style,
1499 GtkStateType state_type)
1501 g_return_if_fail (GTK_IS_STYLE (style));
1502 g_return_if_fail (window != NULL);
1504 GTK_STYLE_GET_CLASS (style)->set_background (style, window, state_type);
1507 /* Default functions */
1509 gtk_style_real_clone (GtkStyle *style)
1511 return GTK_STYLE (g_object_new (G_OBJECT_TYPE (style), NULL));
1515 gtk_style_real_copy (GtkStyle *style,
1520 for (i = 0; i < 5; i++)
1522 style->fg[i] = src->fg[i];
1523 style->bg[i] = src->bg[i];
1524 style->text[i] = src->text[i];
1525 style->base[i] = src->base[i];
1527 style->bg_pixmap[i] = src->bg_pixmap[i];
1530 if (style->private_font)
1531 gdk_font_unref (style->private_font);
1532 style->private_font = src->private_font;
1533 if (style->private_font)
1534 gdk_font_ref (style->private_font);
1536 if (style->font_desc)
1537 pango_font_description_free (style->font_desc);
1539 style->font_desc = pango_font_description_copy (src->font_desc);
1541 style->font_desc = NULL;
1543 style->xthickness = src->xthickness;
1544 style->ythickness = src->ythickness;
1546 if (style->rc_style)
1547 gtk_rc_style_unref (style->rc_style);
1548 style->rc_style = src->rc_style;
1550 gtk_rc_style_ref (src->rc_style);
1552 /* don't copy, just clear cache */
1553 clear_property_cache (style);
1557 gtk_style_real_init_from_rc (GtkStyle *style,
1558 GtkRcStyle *rc_style)
1562 /* cache _should_ be still empty */
1563 clear_property_cache (style);
1565 if (rc_style->font_desc)
1566 pango_font_description_merge (style->font_desc, rc_style->font_desc, TRUE);
1568 for (i = 0; i < 5; i++)
1570 if (rc_style->color_flags[i] & GTK_RC_FG)
1571 style->fg[i] = rc_style->fg[i];
1572 if (rc_style->color_flags[i] & GTK_RC_BG)
1573 style->bg[i] = rc_style->bg[i];
1574 if (rc_style->color_flags[i] & GTK_RC_TEXT)
1575 style->text[i] = rc_style->text[i];
1576 if (rc_style->color_flags[i] & GTK_RC_BASE)
1577 style->base[i] = rc_style->base[i];
1580 if (rc_style->xthickness >= 0)
1581 style->xthickness = rc_style->xthickness;
1582 if (rc_style->ythickness >= 0)
1583 style->ythickness = rc_style->ythickness;
1585 if (rc_style->icon_factories)
1589 style->icon_factories = g_slist_copy (rc_style->icon_factories);
1591 iter = style->icon_factories;
1592 while (iter != NULL)
1594 g_object_ref (iter->data);
1595 iter = g_slist_next (iter);
1601 style_property_values_cmp (gconstpointer bsearch_node1,
1602 gconstpointer bsearch_node2)
1604 const PropertyValue *val1 = bsearch_node1;
1605 const PropertyValue *val2 = bsearch_node2;
1607 if (val1->widget_type == val2->widget_type)
1608 return val1->pspec < val2->pspec ? -1 : val1->pspec == val2->pspec ? 0 : 1;
1610 return val1->widget_type < val2->widget_type ? -1 : 1;
1614 _gtk_style_peek_property_value (GtkStyle *style,
1617 GtkRcPropertyParser parser)
1619 PropertyValue *pcache, key = { 0, NULL, { 0, } };
1620 const GtkRcProperty *rcprop = NULL;
1623 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1624 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), NULL);
1625 g_return_val_if_fail (g_type_is_a (pspec->owner_type, GTK_TYPE_WIDGET), NULL);
1626 g_return_val_if_fail (g_type_is_a (widget_type, pspec->owner_type), NULL);
1628 key.widget_type = widget_type;
1631 /* need value cache array */
1632 if (!style->property_cache)
1633 style->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
1636 pcache = bsearch (&key,
1637 style->property_cache->data, style->property_cache->len,
1638 sizeof (PropertyValue), style_property_values_cmp);
1640 return &pcache->value;
1644 while (i < style->property_cache->len &&
1645 style_property_values_cmp (&key, &g_array_index (style->property_cache, PropertyValue, i)) >= 0)
1648 g_array_insert_val (style->property_cache, i, key);
1649 pcache = &g_array_index (style->property_cache, PropertyValue, i);
1651 /* cache miss, initialize value type, then set contents */
1652 g_param_spec_ref (pcache->pspec);
1653 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1655 /* value provided by rc style? */
1656 if (style->rc_style)
1658 GQuark prop_quark = g_quark_from_string (pspec->name);
1662 rcprop = _gtk_rc_style_lookup_rc_property (style->rc_style,
1663 g_type_qname (widget_type),
1667 widget_type = g_type_parent (widget_type);
1669 while (g_type_is_a (widget_type, pspec->owner_type));
1672 /* when supplied by rc style, we need to convert */
1673 if (rcprop && !_gtk_settings_parse_convert (parser, &rcprop->value,
1674 pspec, &pcache->value))
1676 gchar *contents = g_strdup_value_contents (&rcprop->value);
1678 g_message ("%s: failed to retrieve property `%s::%s' of type `%s' from rc file value \"%s\" of type `%s'",
1680 g_type_name (pspec->owner_type), pspec->name,
1681 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1683 G_VALUE_TYPE_NAME (&rcprop->value));
1685 rcprop = NULL; /* needs default */
1688 /* not supplied by rc style (or conversion failed), revert to default */
1690 g_param_value_set_default (pspec, &pcache->value);
1692 return &pcache->value;
1696 load_bg_image (GdkColormap *colormap,
1698 const gchar *filename)
1700 if (strcmp (filename, "<parent>") == 0)
1701 return (GdkPixmap*) GDK_PARENT_RELATIVE;
1704 return gdk_pixmap_colormap_create_from_xpm (NULL, colormap, NULL,
1711 gtk_style_real_realize (GtkStyle *style)
1713 GdkGCValues gc_values;
1714 GdkGCValuesMask gc_values_mask;
1718 for (i = 0; i < 5; i++)
1720 gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT);
1721 gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT);
1723 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
1724 style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
1725 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
1727 style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
1728 style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
1729 style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;
1732 style->black.red = 0x0000;
1733 style->black.green = 0x0000;
1734 style->black.blue = 0x0000;
1735 gdk_colormap_alloc_color (style->colormap, &style->black, FALSE, TRUE);
1737 style->white.red = 0xffff;
1738 style->white.green = 0xffff;
1739 style->white.blue = 0xffff;
1740 gdk_colormap_alloc_color (style->colormap, &style->white, FALSE, TRUE);
1742 gc_values_mask = GDK_GC_FOREGROUND;
1744 gc_values.foreground = style->black;
1745 style->black_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1747 gc_values.foreground = style->white;
1748 style->white_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1750 for (i = 0; i < 5; i++)
1752 if (style->rc_style && style->rc_style->bg_pixmap_name[i])
1753 style->bg_pixmap[i] = load_bg_image (style->colormap,
1755 style->rc_style->bg_pixmap_name[i]);
1757 if (!gdk_colormap_alloc_color (style->colormap, &style->fg[i], FALSE, TRUE))
1758 g_warning ("unable to allocate color: ( %d %d %d )",
1759 style->fg[i].red, style->fg[i].green, style->fg[i].blue);
1760 if (!gdk_colormap_alloc_color (style->colormap, &style->bg[i], FALSE, TRUE))
1761 g_warning ("unable to allocate color: ( %d %d %d )",
1762 style->bg[i].red, style->bg[i].green, style->bg[i].blue);
1763 if (!gdk_colormap_alloc_color (style->colormap, &style->light[i], FALSE, TRUE))
1764 g_warning ("unable to allocate color: ( %d %d %d )",
1765 style->light[i].red, style->light[i].green, style->light[i].blue);
1766 if (!gdk_colormap_alloc_color (style->colormap, &style->dark[i], FALSE, TRUE))
1767 g_warning ("unable to allocate color: ( %d %d %d )",
1768 style->dark[i].red, style->dark[i].green, style->dark[i].blue);
1769 if (!gdk_colormap_alloc_color (style->colormap, &style->mid[i], FALSE, TRUE))
1770 g_warning ("unable to allocate color: ( %d %d %d )",
1771 style->mid[i].red, style->mid[i].green, style->mid[i].blue);
1772 if (!gdk_colormap_alloc_color (style->colormap, &style->text[i], FALSE, TRUE))
1773 g_warning ("unable to allocate color: ( %d %d %d )",
1774 style->text[i].red, style->text[i].green, style->text[i].blue);
1775 if (!gdk_colormap_alloc_color (style->colormap, &style->base[i], FALSE, TRUE))
1776 g_warning ("unable to allocate color: ( %d %d %d )",
1777 style->base[i].red, style->base[i].green, style->base[i].blue);
1778 if (!gdk_colormap_alloc_color (style->colormap, &style->text_aa[i], FALSE, TRUE))
1779 g_warning ("unable to allocate color: ( %d %d %d )",
1780 style->text_aa[i].red, style->text_aa[i].green, style->text_aa[i].blue);
1782 gc_values.foreground = style->fg[i];
1783 style->fg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1785 gc_values.foreground = style->bg[i];
1786 style->bg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1788 gc_values.foreground = style->light[i];
1789 style->light_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1791 gc_values.foreground = style->dark[i];
1792 style->dark_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1794 gc_values.foreground = style->mid[i];
1795 style->mid_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1797 gc_values.foreground = style->text[i];
1798 style->text_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1800 gc_values.foreground = style->base[i];
1801 style->base_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1803 gc_values.foreground = style->text_aa[i];
1804 style->text_aa_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1809 gtk_style_real_unrealize (GtkStyle *style)
1813 gtk_gc_release (style->black_gc);
1814 gtk_gc_release (style->white_gc);
1816 for (i = 0; i < 5; i++)
1818 gtk_gc_release (style->fg_gc[i]);
1819 gtk_gc_release (style->bg_gc[i]);
1820 gtk_gc_release (style->light_gc[i]);
1821 gtk_gc_release (style->dark_gc[i]);
1822 gtk_gc_release (style->mid_gc[i]);
1823 gtk_gc_release (style->text_gc[i]);
1824 gtk_gc_release (style->base_gc[i]);
1825 gtk_gc_release (style->text_aa_gc[i]);
1827 if (style->bg_pixmap[i] && style->bg_pixmap[i] != (GdkPixmap*) GDK_PARENT_RELATIVE)
1828 g_object_unref (style->bg_pixmap[i]);
1831 gdk_colormap_free_colors (style->colormap, style->fg, 5);
1832 gdk_colormap_free_colors (style->colormap, style->bg, 5);
1833 gdk_colormap_free_colors (style->colormap, style->light, 5);
1834 gdk_colormap_free_colors (style->colormap, style->dark, 5);
1835 gdk_colormap_free_colors (style->colormap, style->mid, 5);
1836 gdk_colormap_free_colors (style->colormap, style->text, 5);
1837 gdk_colormap_free_colors (style->colormap, style->base, 5);
1838 gdk_colormap_free_colors (style->colormap, style->text_aa, 5);
1840 style_unrealize_cursor_gcs (style);
1844 gtk_style_real_set_background (GtkStyle *style,
1846 GtkStateType state_type)
1849 gint parent_relative;
1851 if (style->bg_pixmap[state_type])
1853 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1856 parent_relative = TRUE;
1860 pixmap = style->bg_pixmap[state_type];
1861 parent_relative = FALSE;
1864 gdk_window_set_back_pixmap (window, pixmap, parent_relative);
1867 gdk_window_set_background (window, &style->bg[state_type]);
1871 * gtk_style_render_icon:
1872 * @style: a #GtkStyle
1873 * @source: the #GtkIconSource specifying the icon to render
1874 * @direction: a text direction
1876 * @size: the size to render the icon at. A size of (GtkIconSize)-1
1877 * means render at the size of the source and don't scale.
1878 * @widget: the widget
1879 * @detail: a style detail
1880 * @returns: a newly-created #GdkPixbuf containing the rendered icon
1882 * Renders the icon specified by @source at the given @size
1883 * according to the given parameters and returns the result in a
1887 gtk_style_render_icon (GtkStyle *style,
1888 const GtkIconSource *source,
1889 GtkTextDirection direction,
1893 const gchar *detail)
1897 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1898 g_return_val_if_fail (GTK_STYLE_GET_CLASS (style)->render_icon != NULL, NULL);
1900 pixbuf = GTK_STYLE_GET_CLASS (style)->render_icon (style, source, direction, state,
1901 size, widget, detail);
1903 g_return_val_if_fail (pixbuf != NULL, NULL);
1908 /* Default functions */
1910 gtk_style_apply_default_background (GtkStyle *style,
1913 GtkStateType state_type,
1920 GdkRectangle new_rect, old_rect;
1926 old_rect.width = width;
1927 old_rect.height = height;
1929 if (!gdk_rectangle_intersect (area, &old_rect, &new_rect))
1936 new_rect.width = width;
1937 new_rect.height = height;
1940 if (!style->bg_pixmap[state_type] ||
1941 GDK_IS_PIXMAP (window) ||
1942 (!set_bg && style->bg_pixmap[state_type] != (GdkPixmap*) GDK_PARENT_RELATIVE))
1944 GdkGC *gc = style->bg_gc[state_type];
1946 if (style->bg_pixmap[state_type])
1948 gdk_gc_set_fill (gc, GDK_TILED);
1949 gdk_gc_set_tile (gc, style->bg_pixmap[state_type]);
1952 gdk_draw_rectangle (window, gc, TRUE,
1953 new_rect.x, new_rect.y, new_rect.width, new_rect.height);
1954 if (style->bg_pixmap[state_type])
1955 gdk_gc_set_fill (gc, GDK_SOLID);
1961 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1962 gdk_window_set_back_pixmap (window, NULL, TRUE);
1964 gdk_window_set_back_pixmap (window, style->bg_pixmap[state_type], FALSE);
1967 gdk_window_clear_area (window,
1968 new_rect.x, new_rect.y,
1969 new_rect.width, new_rect.height);
1974 scale_or_ref (GdkPixbuf *src,
1978 if (width == gdk_pixbuf_get_width (src) &&
1979 height == gdk_pixbuf_get_height (src))
1981 return g_object_ref (src);
1985 return gdk_pixbuf_scale_simple (src,
1987 GDK_INTERP_BILINEAR);
1992 gtk_default_render_icon (GtkStyle *style,
1993 const GtkIconSource *source,
1994 GtkTextDirection direction,
1998 const gchar *detail)
2004 GdkPixbuf *base_pixbuf;
2006 GtkSettings *settings;
2008 /* Oddly, style can be NULL in this function, because
2009 * GtkIconSet can be used without a style and if so
2010 * it uses this function.
2013 base_pixbuf = gtk_icon_source_get_pixbuf (source);
2015 g_return_val_if_fail (base_pixbuf != NULL, NULL);
2017 if (widget && gtk_widget_has_screen (widget))
2019 screen = gtk_widget_get_screen (widget);
2020 settings = gtk_settings_get_for_screen (screen);
2022 else if (style->colormap)
2024 screen = gdk_colormap_get_screen (style->colormap);
2025 settings = gtk_settings_get_for_screen (screen);
2029 settings = gtk_settings_get_default ();
2030 GTK_NOTE (MULTIHEAD,
2031 g_warning ("Using the default screen for gtk_default_render_icon()"));
2035 if (size != (GtkIconSize) -1 && !gtk_icon_size_lookup_for_settings (settings, size, &width, &height))
2037 g_warning (G_STRLOC ": invalid icon size '%d'", size);
2041 /* If the size was wildcarded, and we're allowed to scale, then scale; otherwise,
2044 if (size != (GtkIconSize)-1 && gtk_icon_source_get_size_wildcarded (source))
2045 scaled = scale_or_ref (base_pixbuf, width, height);
2047 scaled = g_object_ref (base_pixbuf);
2049 /* If the state was wildcarded, then generate a state. */
2050 if (gtk_icon_source_get_state_wildcarded (source))
2052 if (state == GTK_STATE_INSENSITIVE)
2054 stated = gdk_pixbuf_copy (scaled);
2056 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
2059 g_object_unref (scaled);
2061 else if (state == GTK_STATE_PRELIGHT)
2063 stated = gdk_pixbuf_copy (scaled);
2065 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
2068 g_object_unref (scaled);
2082 sanitize_size (GdkWindow *window,
2086 if ((*width == -1) && (*height == -1))
2087 gdk_drawable_get_size (window, width, height);
2088 else if (*width == -1)
2089 gdk_drawable_get_size (window, width, NULL);
2090 else if (*height == -1)
2091 gdk_drawable_get_size (window, NULL, height);
2095 get_indicator_for_screen (GdkDrawable *drawable,
2099 GdkScreen *screen = gdk_drawable_get_screen (drawable);
2103 tmp_list = indicator_parts[part].bmap_list;
2106 bitmap = tmp_list->data;
2108 if (gdk_drawable_get_screen (bitmap) == screen)
2111 tmp_list = tmp_list->next;
2114 bitmap = gdk_bitmap_create_from_data (drawable,
2115 (gchar *)indicator_parts[part].bits,
2116 INDICATOR_PART_SIZE, INDICATOR_PART_SIZE);
2117 indicator_parts[part].bmap_list = g_list_prepend (indicator_parts[part].bmap_list, bitmap);
2123 draw_part (GdkDrawable *drawable,
2131 gdk_gc_set_clip_rectangle (gc, area);
2133 gdk_gc_set_ts_origin (gc, x, y);
2134 gdk_gc_set_stipple (gc, get_indicator_for_screen (drawable, part));
2135 gdk_gc_set_fill (gc, GDK_STIPPLED);
2137 gdk_draw_rectangle (drawable, gc, TRUE, x, y, INDICATOR_PART_SIZE, INDICATOR_PART_SIZE);
2139 gdk_gc_set_fill (gc, GDK_SOLID);
2142 gdk_gc_set_clip_rectangle (gc, NULL);
2146 gtk_default_draw_hline (GtkStyle *style,
2148 GtkStateType state_type,
2151 const gchar *detail,
2156 gint thickness_light;
2157 gint thickness_dark;
2160 g_return_if_fail (GTK_IS_STYLE (style));
2161 g_return_if_fail (window != NULL);
2163 thickness_light = style->ythickness / 2;
2164 thickness_dark = style->ythickness - thickness_light;
2168 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
2169 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
2172 if (detail && !strcmp (detail, "label"))
2174 if (state_type == GTK_STATE_INSENSITIVE)
2175 gdk_draw_line (window, style->white_gc, x1 + 1, y + 1, x2 + 1, y + 1);
2176 gdk_draw_line (window, style->fg_gc[state_type], x1, y, x2, y);
2180 for (i = 0; i < thickness_dark; i++)
2182 gdk_draw_line (window, style->light_gc[state_type], x2 - i - 1, y + i, x2, y + i);
2183 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x2 - i - 1, y + i);
2186 y += thickness_dark;
2187 for (i = 0; i < thickness_light; i++)
2189 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x1 + thickness_light - i - 1, y + i);
2190 gdk_draw_line (window, style->light_gc[state_type], x1 + thickness_light - i - 1, y + i, x2, y + i);
2196 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
2197 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
2203 gtk_default_draw_vline (GtkStyle *style,
2205 GtkStateType state_type,
2208 const gchar *detail,
2213 gint thickness_light;
2214 gint thickness_dark;
2217 g_return_if_fail (GTK_IS_STYLE (style));
2218 g_return_if_fail (window != NULL);
2220 thickness_light = style->xthickness / 2;
2221 thickness_dark = style->xthickness - thickness_light;
2225 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
2226 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
2228 for (i = 0; i < thickness_dark; i++)
2230 gdk_draw_line (window, style->light_gc[state_type], x + i, y2 - i - 1, x + i, y2);
2231 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y2 - i - 1);
2234 x += thickness_dark;
2235 for (i = 0; i < thickness_light; i++)
2237 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y1 + thickness_light - i);
2238 gdk_draw_line (window, style->light_gc[state_type], x + i, y1 + thickness_light - i, x + i, y2);
2242 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
2243 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
2249 draw_thin_shadow (GtkStyle *style,
2260 sanitize_size (window, &width, &height);
2262 gc1 = style->light_gc[state];
2263 gc2 = style->dark_gc[state];
2267 gdk_gc_set_clip_rectangle (gc1, area);
2268 gdk_gc_set_clip_rectangle (gc2, area);
2271 gdk_draw_line (window, gc1,
2272 x, y + height - 1, x + width - 1, y + height - 1);
2273 gdk_draw_line (window, gc1,
2274 x + width - 1, y, x + width - 1, y + height - 1);
2276 gdk_draw_line (window, gc2,
2277 x, y, x + width - 2, y);
2278 gdk_draw_line (window, gc2,
2279 x, y, x, y + height - 2);
2283 gdk_gc_set_clip_rectangle (gc1, NULL);
2284 gdk_gc_set_clip_rectangle (gc2, NULL);
2289 draw_spinbutton_shadow (GtkStyle *style,
2292 GtkTextDirection direction,
2299 sanitize_size (window, &width, &height);
2303 gdk_gc_set_clip_rectangle (style->black_gc, area);
2304 gdk_gc_set_clip_rectangle (style->bg_gc[state], area);
2305 gdk_gc_set_clip_rectangle (style->dark_gc[state], area);
2306 gdk_gc_set_clip_rectangle (style->light_gc[state], area);
2309 if (direction == GTK_TEXT_DIR_LTR)
2311 gdk_draw_line (window, style->dark_gc[state],
2312 x, y, x + width - 1, y);
2313 gdk_draw_line (window, style->black_gc,
2314 x, y + 1, x + width - 2, y + 1);
2315 gdk_draw_line (window, style->black_gc,
2316 x + width - 2, y + 2, x + width - 2, y + height - 3);
2317 gdk_draw_line (window, style->light_gc[state],
2318 x + width - 1, y + 1, x + width - 1, y + height - 2);
2319 gdk_draw_line (window, style->light_gc[state],
2320 x, y + height - 1, x + width - 1, y + height - 1);
2321 gdk_draw_line (window, style->bg_gc[state],
2322 x, y + height - 2, x + width - 2, y + height - 2);
2323 gdk_draw_line (window, style->black_gc,
2324 x, y + 2, x, y + height - 3);
2328 gdk_draw_line (window, style->dark_gc[state],
2329 x, y, x + width - 1, y);
2330 gdk_draw_line (window, style->dark_gc[state],
2331 x, y + 1, x, y + height - 1);
2332 gdk_draw_line (window, style->black_gc,
2333 x + 1, y + 1, x + width - 1, y + 1);
2334 gdk_draw_line (window, style->black_gc,
2335 x + 1, y + 2, x + 1, y + height - 2);
2336 gdk_draw_line (window, style->black_gc,
2337 x + width - 1, y + 2, x + width - 1, y + height - 3);
2338 gdk_draw_line (window, style->light_gc[state],
2339 x + 1, y + height - 1, x + width - 1, y + height - 1);
2340 gdk_draw_line (window, style->bg_gc[state],
2341 x + 2, y + height - 2, x + width - 1, y + height - 2);
2346 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2347 gdk_gc_set_clip_rectangle (style->bg_gc[state], NULL);
2348 gdk_gc_set_clip_rectangle (style->dark_gc[state], NULL);
2349 gdk_gc_set_clip_rectangle (style->light_gc[state], NULL);
2354 gtk_default_draw_shadow (GtkStyle *style,
2356 GtkStateType state_type,
2357 GtkShadowType shadow_type,
2360 const gchar *detail,
2368 gint thickness_light;
2369 gint thickness_dark;
2372 g_return_if_fail (GTK_IS_STYLE (style));
2373 g_return_if_fail (window != NULL);
2375 if (shadow_type == GTK_SHADOW_IN)
2377 if (detail && (strcmp (detail, "buttondefault") == 0))
2379 sanitize_size (window, &width, &height);
2381 gdk_draw_rectangle (window, style->black_gc, FALSE,
2382 x, y, width - 1, height - 1);
2386 if (detail && strcmp (detail, "trough") == 0)
2388 draw_thin_shadow (style, window, state_type, area,
2389 x, y, width, height);
2392 if (widget && GTK_IS_SPIN_BUTTON (widget) &&
2393 detail && strcmp (detail, "spinbutton") == 0)
2395 draw_spinbutton_shadow (style, window, state_type,
2396 gtk_widget_get_direction (widget), area, x, y, width, height);
2402 sanitize_size (window, &width, &height);
2404 switch (shadow_type)
2406 case GTK_SHADOW_NONE:
2409 case GTK_SHADOW_ETCHED_IN:
2410 gc1 = style->light_gc[state_type];
2411 gc2 = style->dark_gc[state_type];
2413 case GTK_SHADOW_OUT:
2414 case GTK_SHADOW_ETCHED_OUT:
2415 gc1 = style->dark_gc[state_type];
2416 gc2 = style->light_gc[state_type];
2422 gdk_gc_set_clip_rectangle (gc1, area);
2423 gdk_gc_set_clip_rectangle (gc2, area);
2424 if (shadow_type == GTK_SHADOW_IN ||
2425 shadow_type == GTK_SHADOW_OUT)
2427 gdk_gc_set_clip_rectangle (style->black_gc, area);
2428 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2432 switch (shadow_type)
2434 case GTK_SHADOW_NONE:
2438 /* Light around right and bottom edge */
2440 if (style->ythickness > 0)
2441 gdk_draw_line (window, gc1,
2442 x, y + height - 1, x + width - 1, y + height - 1);
2443 if (style->xthickness > 0)
2444 gdk_draw_line (window, gc1,
2445 x + width - 1, y, x + width - 1, y + height - 1);
2447 if (style->ythickness > 1)
2448 gdk_draw_line (window, style->bg_gc[state_type],
2449 x + 1, y + height - 2, x + width - 2, y + height - 2);
2450 if (style->xthickness > 1)
2451 gdk_draw_line (window, style->bg_gc[state_type],
2452 x + width - 2, y + 1, x + width - 2, y + height - 2);
2454 /* Dark around left and top */
2456 if (style->ythickness > 1)
2457 gdk_draw_line (window, style->black_gc,
2458 x + 1, y + 1, x + width - 2, y + 1);
2459 if (style->xthickness > 1)
2460 gdk_draw_line (window, style->black_gc,
2461 x + 1, y + 1, x + 1, y + height - 2);
2463 if (style->ythickness > 0)
2464 gdk_draw_line (window, gc2,
2465 x, y, x + width - 1, y);
2466 if (style->xthickness > 0)
2467 gdk_draw_line (window, gc2,
2468 x, y, x, y + height - 1);
2471 case GTK_SHADOW_OUT:
2472 /* Dark around right and bottom edge */
2474 if (style->ythickness > 0)
2476 if (style->ythickness > 1)
2478 gdk_draw_line (window, gc1,
2479 x + 1, y + height - 2, x + width - 2, y + height - 2);
2480 gdk_draw_line (window, style->black_gc,
2481 x, y + height - 1, x + width - 1, y + height - 1);
2485 gdk_draw_line (window, gc1,
2486 x + 1, y + height - 1, x + width - 1, y + height - 1);
2490 if (style->xthickness > 0)
2492 if (style->xthickness > 1)
2494 gdk_draw_line (window, gc1,
2495 x + width - 2, y + 1, x + width - 2, y + height - 2);
2497 gdk_draw_line (window, style->black_gc,
2498 x + width - 1, y, x + width - 1, y + height - 1);
2502 gdk_draw_line (window, gc1,
2503 x + width - 1, y + 1, x + width - 1, y + height - 1);
2507 /* Light around top and left */
2509 if (style->ythickness > 0)
2510 gdk_draw_line (window, gc2,
2511 x, y, x + width - 2, y);
2512 if (style->xthickness > 0)
2513 gdk_draw_line (window, gc2,
2514 x, y, x, y + height - 2);
2516 if (style->ythickness > 1)
2517 gdk_draw_line (window, style->bg_gc[state_type],
2518 x + 1, y + 1, x + width - 3, y + 1);
2519 if (style->xthickness > 1)
2520 gdk_draw_line (window, style->bg_gc[state_type],
2521 x + 1, y + 1, x + 1, y + height - 3);
2524 case GTK_SHADOW_ETCHED_IN:
2525 case GTK_SHADOW_ETCHED_OUT:
2526 if (style->xthickness > 0)
2528 if (style->xthickness > 1)
2530 thickness_light = 1;
2533 for (i = 0; i < thickness_dark; i++)
2535 gdk_draw_line (window, gc1,
2539 y + height - i - 1);
2540 gdk_draw_line (window, gc2,
2544 y + height - i - 2);
2547 for (i = 0; i < thickness_light; i++)
2549 gdk_draw_line (window, gc1,
2550 x + thickness_dark + i,
2551 y + thickness_dark + i,
2552 x + thickness_dark + i,
2553 y + height - thickness_dark - i - 1);
2554 gdk_draw_line (window, gc2,
2555 x + width - thickness_light - i - 1,
2556 y + thickness_dark + i,
2557 x + width - thickness_light - i - 1,
2558 y + height - thickness_light - 1);
2563 gdk_draw_line (window,
2564 style->dark_gc[state_type],
2565 x, y, x, y + height);
2566 gdk_draw_line (window,
2567 style->dark_gc[state_type],
2568 x + width, y, x + width, y + height);
2572 if (style->ythickness > 0)
2574 if (style->ythickness > 1)
2576 thickness_light = 1;
2579 for (i = 0; i < thickness_dark; i++)
2581 gdk_draw_line (window, gc1,
2585 y + height - i - 1);
2587 gdk_draw_line (window, gc2,
2594 for (i = 0; i < thickness_light; i++)
2596 gdk_draw_line (window, gc1,
2597 x + thickness_dark + i,
2598 y + thickness_dark + i,
2599 x + width - thickness_dark - i - 2,
2600 y + thickness_dark + i);
2602 gdk_draw_line (window, gc2,
2603 x + thickness_dark + i,
2604 y + height - thickness_light - i - 1,
2605 x + width - thickness_light - 1,
2606 y + height - thickness_light - i - 1);
2611 gdk_draw_line (window,
2612 style->dark_gc[state_type],
2613 x, y, x + width, y);
2614 gdk_draw_line (window,
2615 style->dark_gc[state_type],
2616 x, y + height, x + width, y + height);
2623 if (shadow_type == GTK_SHADOW_IN &&
2624 widget && GTK_IS_SPIN_BUTTON (widget) &&
2625 detail && strcmp (detail, "entry") == 0)
2627 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
2629 gdk_draw_line (window,
2630 style->base_gc[state_type],
2631 x + width - 1, y + 2,
2632 x + width - 1, y + height - 3);
2633 gdk_draw_line (window,
2634 style->base_gc[state_type],
2635 x + width - 2, y + 2,
2636 x + width - 2, y + height - 3);
2637 gdk_draw_point (window,
2639 x + width - 1, y + 1);
2640 gdk_draw_point (window,
2641 style->bg_gc[state_type],
2642 x + width - 1, y + height - 2);
2646 gdk_draw_line (window,
2647 style->base_gc[state_type],
2650 gdk_draw_line (window,
2651 style->base_gc[state_type],
2653 x + 1, y + height - 3);
2654 gdk_draw_point (window,
2657 gdk_draw_line (window,
2658 style->bg_gc[state_type],
2660 x + 1, y + height - 2);
2661 gdk_draw_point (window,
2662 style->light_gc[state_type],
2670 gdk_gc_set_clip_rectangle (gc1, NULL);
2671 gdk_gc_set_clip_rectangle (gc2, NULL);
2672 if (shadow_type == GTK_SHADOW_IN ||
2673 shadow_type == GTK_SHADOW_OUT)
2675 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2676 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2682 gtk_default_draw_polygon (GtkStyle *style,
2684 GtkStateType state_type,
2685 GtkShadowType shadow_type,
2688 const gchar *detail,
2693 static const gdouble pi_over_4 = G_PI_4;
2694 static const gdouble pi_3_over_4 = G_PI_4 * 3;
2704 g_return_if_fail (GTK_IS_STYLE (style));
2705 g_return_if_fail (window != NULL);
2706 g_return_if_fail (points != NULL);
2708 switch (shadow_type)
2711 gc1 = style->bg_gc[state_type];
2712 gc2 = style->dark_gc[state_type];
2713 gc3 = style->light_gc[state_type];
2714 gc4 = style->black_gc;
2716 case GTK_SHADOW_ETCHED_IN:
2717 gc1 = style->light_gc[state_type];
2718 gc2 = style->dark_gc[state_type];
2719 gc3 = style->dark_gc[state_type];
2720 gc4 = style->light_gc[state_type];
2722 case GTK_SHADOW_OUT:
2723 gc1 = style->dark_gc[state_type];
2724 gc2 = style->light_gc[state_type];
2725 gc3 = style->black_gc;
2726 gc4 = style->bg_gc[state_type];
2728 case GTK_SHADOW_ETCHED_OUT:
2729 gc1 = style->dark_gc[state_type];
2730 gc2 = style->light_gc[state_type];
2731 gc3 = style->light_gc[state_type];
2732 gc4 = style->dark_gc[state_type];
2740 gdk_gc_set_clip_rectangle (gc1, area);
2741 gdk_gc_set_clip_rectangle (gc2, area);
2742 gdk_gc_set_clip_rectangle (gc3, area);
2743 gdk_gc_set_clip_rectangle (gc4, area);
2747 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, npoints);
2751 for (i = 0; i < npoints; i++)
2753 if ((points[i].x == points[i+1].x) &&
2754 (points[i].y == points[i+1].y))
2760 angle = atan2 (points[i+1].y - points[i].y,
2761 points[i+1].x - points[i].x);
2764 if ((angle > -pi_3_over_4) && (angle < pi_over_4))
2766 if (angle > -pi_over_4)
2777 gdk_draw_line (window, gc1,
2778 points[i].x-xadjust, points[i].y-yadjust,
2779 points[i+1].x-xadjust, points[i+1].y-yadjust);
2780 gdk_draw_line (window, gc3,
2781 points[i].x, points[i].y,
2782 points[i+1].x, points[i+1].y);
2786 if ((angle < -pi_3_over_4) || (angle > pi_3_over_4))
2797 gdk_draw_line (window, gc4,
2798 points[i].x+xadjust, points[i].y+yadjust,
2799 points[i+1].x+xadjust, points[i+1].y+yadjust);
2800 gdk_draw_line (window, gc2,
2801 points[i].x, points[i].y,
2802 points[i+1].x, points[i+1].y);
2808 gdk_gc_set_clip_rectangle (gc1, NULL);
2809 gdk_gc_set_clip_rectangle (gc2, NULL);
2810 gdk_gc_set_clip_rectangle (gc3, NULL);
2811 gdk_gc_set_clip_rectangle (gc4, NULL);
2816 draw_arrow (GdkWindow *window,
2819 GtkArrowType arrow_type,
2828 gdk_gc_set_clip_rectangle (gc, area);
2830 if (arrow_type == GTK_ARROW_DOWN)
2832 for (i = 0, j = 0; i < height; i++, j++)
2833 gdk_draw_line (window, gc, x + j, y + i, x + width - j - 1, y + i);
2835 else if (arrow_type == GTK_ARROW_UP)
2837 for (i = height - 1, j = 0; i >= 0; i--, j++)
2838 gdk_draw_line (window, gc, x + j, y + i, x + width - j - 1, y + i);
2840 else if (arrow_type == GTK_ARROW_LEFT)
2842 for (i = width - 1, j = 0; i >= 0; i--, j++)
2843 gdk_draw_line (window, gc, x + i, y + j, x + i, y + height - j - 1);
2845 else if (arrow_type == GTK_ARROW_RIGHT)
2847 for (i = 0, j = 0; i < width; i++, j++)
2848 gdk_draw_line (window, gc, x + i, y + j, x + i, y + height - j - 1);
2852 gdk_gc_set_clip_rectangle (gc, NULL);
2856 calculate_arrow_geometry (GtkArrowType arrow_type,
2868 case GTK_ARROW_DOWN:
2878 if (arrow_type == GTK_ARROW_DOWN)
2880 if (*height % 2 == 1 || h % 2 == 0)
2885 if (*height % 2 == 0 || h % 2 == 0)
2890 case GTK_ARROW_RIGHT:
2891 case GTK_ARROW_LEFT:
2901 if (arrow_type == GTK_ARROW_RIGHT)
2903 if (*width % 2 == 1 || w % 2 == 0)
2908 if (*width % 2 == 0 || w % 2 == 0)
2914 /* should not be reached */
2918 *x += (*width - w) / 2;
2919 *y += (*height - h) / 2;
2925 gtk_default_draw_arrow (GtkStyle *style,
2928 GtkShadowType shadow,
2931 const gchar *detail,
2932 GtkArrowType arrow_type,
2939 gint original_width, original_x;
2941 sanitize_size (window, &width, &height);
2943 original_width = width;
2946 calculate_arrow_geometry (arrow_type, &x, &y, &width, &height);
2948 if (detail && strcmp (detail, "menuitem") == 0
2949 && gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
2950 x = original_x + original_width - width;
2952 if (state == GTK_STATE_INSENSITIVE)
2953 draw_arrow (window, style->white_gc, area, arrow_type,
2954 x + 1, y + 1, width, height);
2955 draw_arrow (window, style->fg_gc[state], area, arrow_type,
2956 x, y, width, height);
2960 gtk_default_draw_diamond (GtkStyle *style,
2962 GtkStateType state_type,
2963 GtkShadowType shadow_type,
2966 const gchar *detail,
2974 GdkGC *outer_nw = NULL;
2975 GdkGC *outer_ne = NULL;
2976 GdkGC *outer_sw = NULL;
2977 GdkGC *outer_se = NULL;
2978 GdkGC *middle_nw = NULL;
2979 GdkGC *middle_ne = NULL;
2980 GdkGC *middle_sw = NULL;
2981 GdkGC *middle_se = NULL;
2982 GdkGC *inner_nw = NULL;
2983 GdkGC *inner_ne = NULL;
2984 GdkGC *inner_sw = NULL;
2985 GdkGC *inner_se = NULL;
2987 g_return_if_fail (GTK_IS_STYLE (style));
2988 g_return_if_fail (window != NULL);
2990 sanitize_size (window, &width, &height);
2992 half_width = width / 2;
2993 half_height = height / 2;
2997 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
2998 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2999 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
3000 gdk_gc_set_clip_rectangle (style->black_gc, area);
3003 switch (shadow_type)
3006 inner_sw = inner_se = style->bg_gc[state_type];
3007 middle_sw = middle_se = style->light_gc[state_type];
3008 outer_sw = outer_se = style->light_gc[state_type];
3009 inner_nw = inner_ne = style->black_gc;
3010 middle_nw = middle_ne = style->dark_gc[state_type];
3011 outer_nw = outer_ne = style->dark_gc[state_type];
3014 case GTK_SHADOW_OUT:
3015 inner_sw = inner_se = style->dark_gc[state_type];
3016 middle_sw = middle_se = style->dark_gc[state_type];
3017 outer_sw = outer_se = style->black_gc;
3018 inner_nw = inner_ne = style->bg_gc[state_type];
3019 middle_nw = middle_ne = style->light_gc[state_type];
3020 outer_nw = outer_ne = style->light_gc[state_type];
3023 case GTK_SHADOW_ETCHED_IN:
3024 inner_sw = inner_se = style->bg_gc[state_type];
3025 middle_sw = middle_se = style->dark_gc[state_type];
3026 outer_sw = outer_se = style->light_gc[state_type];
3027 inner_nw = inner_ne = style->bg_gc[state_type];
3028 middle_nw = middle_ne = style->light_gc[state_type];
3029 outer_nw = outer_ne = style->dark_gc[state_type];
3032 case GTK_SHADOW_ETCHED_OUT:
3033 inner_sw = inner_se = style->bg_gc[state_type];
3034 middle_sw = middle_se = style->light_gc[state_type];
3035 outer_sw = outer_se = style->dark_gc[state_type];
3036 inner_nw = inner_ne = style->bg_gc[state_type];
3037 middle_nw = middle_ne = style->dark_gc[state_type];
3038 outer_nw = outer_ne = style->light_gc[state_type];
3048 gdk_draw_line (window, inner_sw,
3049 x + 2, y + half_height,
3050 x + half_width, y + height - 2);
3051 gdk_draw_line (window, inner_se,
3052 x + half_width, y + height - 2,
3053 x + width - 2, y + half_height);
3054 gdk_draw_line (window, middle_sw,
3055 x + 1, y + half_height,
3056 x + half_width, y + height - 1);
3057 gdk_draw_line (window, middle_se,
3058 x + half_width, y + height - 1,
3059 x + width - 1, y + half_height);
3060 gdk_draw_line (window, outer_sw,
3062 x + half_width, y + height);
3063 gdk_draw_line (window, outer_se,
3064 x + half_width, y + height,
3065 x + width, y + half_height);
3067 gdk_draw_line (window, inner_nw,
3068 x + 2, y + half_height,
3069 x + half_width, y + 2);
3070 gdk_draw_line (window, inner_ne,
3071 x + half_width, y + 2,
3072 x + width - 2, y + half_height);
3073 gdk_draw_line (window, middle_nw,
3074 x + 1, y + half_height,
3075 x + half_width, y + 1);
3076 gdk_draw_line (window, middle_ne,
3077 x + half_width, y + 1,
3078 x + width - 1, y + half_height);
3079 gdk_draw_line (window, outer_nw,
3082 gdk_draw_line (window, outer_ne,
3084 x + width, y + half_height);
3089 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
3090 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
3091 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
3092 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
3097 gtk_default_draw_string (GtkStyle *style,
3099 GtkStateType state_type,
3102 const gchar *detail,
3105 const gchar *string)
3107 GdkDisplay *display;
3109 g_return_if_fail (GTK_IS_STYLE (style));
3110 g_return_if_fail (window != NULL);
3112 display = gdk_drawable_get_display (window);
3116 gdk_gc_set_clip_rectangle (style->white_gc, area);
3117 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], area);
3120 if (state_type == GTK_STATE_INSENSITIVE)
3121 gdk_draw_string (window,
3122 gtk_style_get_font_internal (style),
3123 style->white_gc, x + 1, y + 1, string);
3125 gdk_draw_string (window,
3126 gtk_style_get_font_internal (style),
3127 style->fg_gc[state_type], x, y, string);
3131 gdk_gc_set_clip_rectangle (style->white_gc, NULL);
3132 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], NULL);
3137 option_menu_get_props (GtkWidget *widget,
3138 GtkRequisition *indicator_size,
3139 GtkBorder *indicator_spacing)
3141 GtkRequisition *tmp_size = NULL;
3142 GtkBorder *tmp_spacing = NULL;
3145 gtk_widget_style_get (widget,
3146 "indicator_size", &tmp_size,
3147 "indicator_spacing", &tmp_spacing,
3152 *indicator_size = *tmp_size;
3156 *indicator_size = default_option_indicator_size;
3160 *indicator_spacing = *tmp_spacing;
3161 g_free (tmp_spacing);
3164 *indicator_spacing = default_option_indicator_spacing;
3168 gtk_default_draw_box (GtkStyle *style,
3170 GtkStateType state_type,
3171 GtkShadowType shadow_type,
3174 const gchar *detail,
3180 gboolean is_spinbutton_box = FALSE;
3182 g_return_if_fail (GTK_IS_STYLE (style));
3183 g_return_if_fail (window != NULL);
3185 sanitize_size (window, &width, &height);
3187 if (widget && GTK_IS_SPIN_BUTTON (widget) && detail)
3189 if (strcmp (detail, "spinbutton_up") == 0)
3195 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3200 is_spinbutton_box = TRUE;
3202 else if (strcmp (detail, "spinbutton_down") == 0)
3207 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3212 is_spinbutton_box = TRUE;
3216 if (!style->bg_pixmap[state_type] ||
3217 GDK_IS_PIXMAP (window))
3220 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
3222 gdk_draw_rectangle (window, style->bg_gc[state_type], TRUE,
3223 x, y, width, height);
3225 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
3228 gtk_style_apply_default_background (style, window,
3229 widget && !GTK_WIDGET_NO_WINDOW (widget),
3230 state_type, area, x, y, width, height);
3232 if (is_spinbutton_box)
3237 lower_gc = style->dark_gc[state_type];
3238 if (shadow_type == GTK_SHADOW_OUT)
3239 upper_gc = style->light_gc[state_type];
3241 upper_gc = style->dark_gc[state_type];
3245 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
3246 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
3249 gdk_draw_line (window, upper_gc, x, y, x + width - 1, y);
3250 gdk_draw_line (window, lower_gc, x, y + height - 1, x + width - 1, y + height - 1);
3254 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
3255 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
3260 gtk_paint_shadow (style, window, state_type, shadow_type, area, widget, detail,
3261 x, y, width, height);
3263 if (detail && strcmp (detail, "optionmenu") == 0)
3265 GtkRequisition indicator_size;
3266 GtkBorder indicator_spacing;
3269 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
3271 sanitize_size (window, &width, &height);
3273 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3274 vline_x = x + indicator_size.width + indicator_spacing.left + indicator_spacing.right;
3276 vline_x = x + width - (indicator_size.width + indicator_spacing.left + indicator_spacing.right) - style->xthickness;
3278 gtk_paint_vline (style, window, state_type, area, widget,
3280 y + style->ythickness + 1,
3281 y + height - style->ythickness - 3,
3287 get_darkened_gc (GdkWindow *window,
3291 GdkColor src = *color;
3292 GdkColor shaded = *color;
3295 gc = gdk_gc_new (window);
3297 while (darken_count)
3299 gtk_style_shade (&src, &shaded, 0.93);
3304 gdk_gc_set_rgb_fg_color (gc, &shaded);
3310 gtk_default_draw_flat_box (GtkStyle *style,
3312 GtkStateType state_type,
3313 GtkShadowType shadow_type,
3316 const gchar *detail,
3323 GdkGC *freeme = NULL;
3325 g_return_if_fail (GTK_IS_STYLE (style));
3326 g_return_if_fail (window != NULL);
3328 sanitize_size (window, &width, &height);
3332 if (state_type == GTK_STATE_SELECTED)
3334 if (!strcmp ("text", detail))
3335 gc1 = style->bg_gc[GTK_STATE_SELECTED];
3336 else if (!strncmp ("cell_even", detail, strlen ("cell_even")) ||
3337 !strncmp ("cell_odd", detail, strlen ("cell_odd")))
3339 /* This has to be really broken; alex made me do it. -jrb */
3340 if (GTK_WIDGET_HAS_FOCUS (widget))
3341 gc1 = style->base_gc[state_type];
3343 gc1 = style->base_gc[GTK_STATE_ACTIVE];
3347 gc1 = style->bg_gc[state_type];
3352 if (!strcmp ("viewportbin", detail))
3353 gc1 = style->bg_gc[GTK_STATE_NORMAL];
3354 else if (!strcmp ("entry_bg", detail))
3355 gc1 = style->base_gc[state_type];
3357 /* For trees: even rows are base color, odd rows are a shade of
3358 * the base color, the sort column is a shade of the original color
3362 else if (!strcmp ("cell_even", detail) ||
3363 !strcmp ("cell_odd", detail) ||
3364 !strcmp ("cell_even_ruled", detail))
3366 GdkColor *color = NULL;
3368 gtk_widget_style_get (widget,
3369 "even_row_color", &color,
3374 freeme = get_darkened_gc (window, color, 0);
3377 gdk_color_free (color);
3380 gc1 = style->base_gc[state_type];
3382 else if (!strcmp ("cell_odd_ruled", detail))
3386 gtk_widget_style_get (widget,
3387 "odd_row_color", &color,
3392 freeme = get_darkened_gc (window, color, 0);
3395 gdk_color_free (color);
3399 gtk_widget_style_get (widget,
3400 "even_row_color", &color,
3405 freeme = get_darkened_gc (window, color, 1);
3406 gdk_color_free (color);
3409 freeme = get_darkened_gc (window, &style->base[state_type], 1);
3413 else if (!strcmp ("cell_even_sorted", detail) ||
3414 !strcmp ("cell_odd_sorted", detail) ||
3415 !strcmp ("cell_even_ruled_sorted", detail))
3417 GdkColor *color = NULL;
3419 if (!strcmp ("cell_odd_sorted", detail))
3420 gtk_widget_style_get (widget,
3421 "odd_row_color", &color,
3424 gtk_widget_style_get (widget,
3425 "even_row_color", &color,
3430 freeme = get_darkened_gc (window, color, 1);
3433 gdk_color_free (color);
3437 freeme = get_darkened_gc (window, &style->base[state_type], 1);
3441 else if (!strcmp ("cell_odd_ruled_sorted", detail))
3443 GdkColor *color = NULL;
3445 gtk_widget_style_get (widget,
3446 "odd_row_color", &color,
3451 freeme = get_darkened_gc (window, color, 1);
3454 gdk_color_free (color);
3458 gtk_widget_style_get (widget,
3459 "even_row_color", &color,
3464 freeme = get_darkened_gc (window, color, 2);
3465 gdk_color_free (color);
3468 freeme = get_darkened_gc (window, &style->base[state_type], 2);
3473 gc1 = style->bg_gc[state_type];
3477 gc1 = style->bg_gc[state_type];
3479 if (!style->bg_pixmap[state_type] || gc1 != style->bg_gc[state_type] ||
3480 GDK_IS_PIXMAP (window))
3483 gdk_gc_set_clip_rectangle (gc1, area);
3485 gdk_draw_rectangle (window, gc1, TRUE,
3486 x, y, width, height);
3488 if (detail && !strcmp ("tooltip", detail))
3489 gdk_draw_rectangle (window, style->black_gc, FALSE,
3490 x, y, width - 1, height - 1);
3493 gdk_gc_set_clip_rectangle (gc1, NULL);
3496 gtk_style_apply_default_background (style, window,
3497 widget && !GTK_WIDGET_NO_WINDOW (widget),
3498 state_type, area, x, y, width, height);
3502 g_object_unref (freeme);
3506 create_aa_gc (GdkWindow *window, GtkStyle *style, GtkStateType state_type)
3509 GdkGC *gc = gdk_gc_new (window);
3511 aa_color.red = (style->fg[state_type].red + style->bg[state_type].red) / 2;
3512 aa_color.green = (style->fg[state_type].green + style->bg[state_type].green) / 2;
3513 aa_color.blue = (style->fg[state_type].blue + style->bg[state_type].blue) / 2;
3515 gdk_gc_set_rgb_fg_color (gc, &aa_color);
3521 gtk_default_draw_check (GtkStyle *style,
3523 GtkStateType state_type,
3524 GtkShadowType shadow_type,
3527 const gchar *detail,
3533 if (detail && strcmp (detail, "cellcheck") == 0)
3535 gdk_draw_rectangle (window,
3536 widget->style->base_gc[state_type],
3540 gdk_draw_rectangle (window,
3541 widget->style->text_gc[state_type],
3546 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3547 y -= (((1 + INDICATOR_PART_SIZE - height) / 2) - 1);
3548 if (shadow_type == GTK_SHADOW_IN)
3550 draw_part (window, style->text_gc[state_type], area, x, y, CHECK_TEXT);
3551 draw_part (window, style->text_aa_gc[state_type], area, x, y, CHECK_AA);
3553 else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
3555 draw_part (window, style->text_gc[state_type], area, x, y, CHECK_INCONSISTENT_TEXT);
3560 GdkGC *free_me = NULL;
3566 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3567 y -= (1 + INDICATOR_PART_SIZE - height) / 2;
3569 if (strcmp (detail, "check") == 0) /* Menu item */
3571 text_gc = style->fg_gc[state_type];
3572 base_gc = style->bg_gc[state_type];
3573 aa_gc = free_me = create_aa_gc (window, style, state_type);
3577 if (state_type == GTK_STATE_ACTIVE)
3579 text_gc = style->fg_gc[state_type];
3580 base_gc = style->bg_gc[state_type];
3581 aa_gc = free_me = create_aa_gc (window, style, state_type);
3585 text_gc = style->text_gc[state_type];
3586 base_gc = style->base_gc[state_type];
3587 aa_gc = style->text_aa_gc[state_type];
3590 draw_part (window, base_gc, area, x, y, CHECK_BASE);
3591 draw_part (window, style->black_gc, area, x, y, CHECK_BLACK);
3592 draw_part (window, style->dark_gc[state_type], area, x, y, CHECK_DARK);
3593 draw_part (window, style->mid_gc[state_type], area, x, y, CHECK_MID);
3594 draw_part (window, style->light_gc[state_type], area, x, y, CHECK_LIGHT);
3597 if (shadow_type == GTK_SHADOW_IN)
3599 draw_part (window, text_gc, area, x, y, CHECK_TEXT);
3600 draw_part (window, aa_gc, area, x, y, CHECK_AA);
3602 else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
3604 draw_part (window, text_gc, area, x, y, CHECK_INCONSISTENT_TEXT);
3608 g_object_unref (G_OBJECT (free_me));
3613 gtk_default_draw_option (GtkStyle *style,
3615 GtkStateType state_type,
3616 GtkShadowType shadow_type,
3619 const gchar *detail,
3625 if (detail && strcmp (detail, "cellradio") == 0)
3627 gdk_draw_arc (window,
3628 widget->style->fg_gc[state_type],
3635 if (shadow_type == GTK_SHADOW_IN)
3637 gdk_draw_arc (window,
3638 widget->style->fg_gc[state_type],
3646 else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
3648 draw_part (window, widget->style->fg_gc[state_type],
3649 area, x, y, CHECK_INCONSISTENT_TEXT);
3654 GdkGC *free_me = NULL;
3660 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3661 y -= (1 + INDICATOR_PART_SIZE - height) / 2;
3663 if (strcmp (detail, "option") == 0) /* Menu item */
3665 text_gc = style->fg_gc[state_type];
3666 base_gc = style->bg_gc[state_type];
3667 aa_gc = free_me = create_aa_gc (window, style, state_type);
3671 if (state_type == GTK_STATE_ACTIVE)
3673 text_gc = style->fg_gc[state_type];
3674 base_gc = style->bg_gc[state_type];
3675 aa_gc = free_me = create_aa_gc (window, style, state_type);
3679 text_gc = style->text_gc[state_type];
3680 base_gc = style->base_gc[state_type];
3681 aa_gc = style->text_aa_gc[state_type];
3684 draw_part (window, base_gc, area, x, y, RADIO_BASE);
3685 draw_part (window, style->black_gc, area, x, y, RADIO_BLACK);
3686 draw_part (window, style->dark_gc[state_type], area, x, y, RADIO_DARK);
3687 draw_part (window, style->mid_gc[state_type], area, x, y, RADIO_MID);
3688 draw_part (window, style->light_gc[state_type], area, x, y, RADIO_LIGHT);
3691 if (shadow_type == GTK_SHADOW_IN)
3693 draw_part (window, text_gc, area, x, y, RADIO_TEXT);
3695 else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
3697 if (strcmp (detail, "option") == 0) /* Menu item */
3699 draw_part (window, text_gc, area, x, y, CHECK_INCONSISTENT_TEXT);
3703 draw_part (window, text_gc, area, x, y, RADIO_INCONSISTENT_TEXT);
3704 draw_part (window, aa_gc, area, x, y, RADIO_INCONSISTENT_AA);
3709 g_object_unref (G_OBJECT (free_me));
3714 gtk_default_draw_tab (GtkStyle *style,
3716 GtkStateType state_type,
3717 GtkShadowType shadow_type,
3720 const gchar *detail,
3726 #define ARROW_SPACE 4
3728 GtkRequisition indicator_size;
3729 GtkBorder indicator_spacing;
3732 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
3734 indicator_size.width += (indicator_size.width % 2) - 1;
3735 arrow_height = indicator_size.width / 2 + 1;
3737 x += (width - indicator_size.width) / 2;
3738 y += (height - (2 * arrow_height + ARROW_SPACE)) / 2;
3740 if (state_type == GTK_STATE_INSENSITIVE)
3742 draw_arrow (window, style->white_gc, area,
3743 GTK_ARROW_UP, x + 1, y + 1,
3744 indicator_size.width, arrow_height);
3746 draw_arrow (window, style->white_gc, area,
3747 GTK_ARROW_DOWN, x + 1, y + arrow_height + ARROW_SPACE + 1,
3748 indicator_size.width, arrow_height);
3751 draw_arrow (window, style->fg_gc[state_type], area,
3753 indicator_size.width, arrow_height);
3756 draw_arrow (window, style->fg_gc[state_type], area,
3757 GTK_ARROW_DOWN, x, y + arrow_height + ARROW_SPACE,
3758 indicator_size.width, arrow_height);
3762 gtk_default_draw_shadow_gap (GtkStyle *style,
3764 GtkStateType state_type,
3765 GtkShadowType shadow_type,
3768 const gchar *detail,
3773 GtkPositionType gap_side,
3782 g_return_if_fail (GTK_IS_STYLE (style));
3783 g_return_if_fail (window != NULL);
3785 sanitize_size (window, &width, &height);
3787 switch (shadow_type)
3789 case GTK_SHADOW_NONE:
3792 gc1 = style->dark_gc[state_type];
3793 gc2 = style->black_gc;
3794 gc3 = style->bg_gc[state_type];
3795 gc4 = style->light_gc[state_type];
3797 case GTK_SHADOW_ETCHED_IN:
3798 gc1 = style->dark_gc[state_type];
3799 gc2 = style->light_gc[state_type];
3800 gc3 = style->dark_gc[state_type];
3801 gc4 = style->light_gc[state_type];
3803 case GTK_SHADOW_OUT:
3804 gc1 = style->light_gc[state_type];
3805 gc2 = style->bg_gc[state_type];
3806 gc3 = style->dark_gc[state_type];
3807 gc4 = style->black_gc;
3809 case GTK_SHADOW_ETCHED_OUT:
3810 gc1 = style->light_gc[state_type];
3811 gc2 = style->dark_gc[state_type];
3812 gc3 = style->light_gc[state_type];
3813 gc4 = style->dark_gc[state_type];
3818 gdk_gc_set_clip_rectangle (gc1, area);
3819 gdk_gc_set_clip_rectangle (gc2, area);
3820 gdk_gc_set_clip_rectangle (gc3, area);
3821 gdk_gc_set_clip_rectangle (gc4, area);
3824 switch (shadow_type)
3826 case GTK_SHADOW_NONE:
3828 case GTK_SHADOW_OUT:
3829 case GTK_SHADOW_ETCHED_IN:
3830 case GTK_SHADOW_ETCHED_OUT:
3834 gdk_draw_line (window, gc1,
3835 x, y, x, y + height - 1);
3836 gdk_draw_line (window, gc2,
3837 x + 1, y, x + 1, y + height - 2);
3839 gdk_draw_line (window, gc3,
3840 x + 1, y + height - 2, x + width - 2, y + height - 2);
3841 gdk_draw_line (window, gc3,
3842 x + width - 2, y, x + width - 2, y + height - 2);
3843 gdk_draw_line (window, gc4,
3844 x, y + height - 1, x + width - 1, y + height - 1);
3845 gdk_draw_line (window, gc4,
3846 x + width - 1, y, x + width - 1, y + height - 1);
3849 gdk_draw_line (window, gc1,
3850 x, y, x + gap_x - 1, y);
3851 gdk_draw_line (window, gc2,
3852 x + 1, y + 1, x + gap_x - 1, y + 1);
3853 gdk_draw_line (window, gc2,
3854 x + gap_x, y, x + gap_x, y);
3856 if ((width - (gap_x + gap_width)) > 0)
3858 gdk_draw_line (window, gc1,
3859 x + gap_x + gap_width, y, x + width - 2, y);
3860 gdk_draw_line (window, gc2,
3861 x + gap_x + gap_width, y + 1, x + width - 3, y + 1);
3862 gdk_draw_line (window, gc2,
3863 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
3866 case GTK_POS_BOTTOM:
3867 gdk_draw_line (window, gc1,
3868 x, y, x + width - 1, y);
3869 gdk_draw_line (window, gc1,
3870 x, y, x, y + height - 1);
3871 gdk_draw_line (window, gc2,
3872 x + 1, y + 1, x + width - 2, y + 1);
3873 gdk_draw_line (window, gc2,
3874 x + 1, y + 1, x + 1, y + height - 1);
3876 gdk_draw_line (window, gc3,
3877 x + width - 2, y + 1, x + width - 2, y + height - 1);
3878 gdk_draw_line (window, gc4,
3879 x + width - 1, y, x + width - 1, y + height - 1);
3882 gdk_draw_line (window, gc4,
3883 x, y + height - 1, x + gap_x - 1, y + height - 1);
3884 gdk_draw_line (window, gc3,
3885 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
3886 gdk_draw_line (window, gc3,
3887 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
3889 if ((width - (gap_x + gap_width)) > 0)
3891 gdk_draw_line (window, gc4,
3892 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
3893 gdk_draw_line (window, gc3,
3894 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
3895 gdk_draw_line (window, gc3,
3896 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
3900 gdk_draw_line (window, gc1,
3901 x, y, x + width - 1, y);
3902 gdk_draw_line (window, gc2,
3903 x, y + 1, x + width - 2, y + 1);
3905 gdk_draw_line (window, gc3,
3906 x, y + height - 2, x + width - 2, y + height - 2);
3907 gdk_draw_line (window, gc3,
3908 x + width - 2, y + 1, x + width - 2, y + height - 2);
3909 gdk_draw_line (window, gc4,
3910 x, y + height - 1, x + width - 1, y + height - 1);
3911 gdk_draw_line (window, gc4,
3912 x + width - 1, y, x + width - 1, y + height - 1);
3915 gdk_draw_line (window, gc1,
3916 x, y, x, y + gap_x - 1);
3917 gdk_draw_line (window, gc2,
3918 x + 1, y + 1, x + 1, y + gap_x - 1);
3919 gdk_draw_line (window, gc2,
3920 x, y + gap_x, x, y + gap_x);
3922 if ((width - (gap_x + gap_width)) > 0)
3924 gdk_draw_line (window, gc1,
3925 x, y + gap_x + gap_width, x, y + height - 2);
3926 gdk_draw_line (window, gc2,
3927 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
3928 gdk_draw_line (window, gc2,
3929 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
3933 gdk_draw_line (window, gc1,
3934 x, y, x + width - 1, y);
3935 gdk_draw_line (window, gc1,
3936 x, y, x, y + height - 1);
3937 gdk_draw_line (window, gc2,
3938 x + 1, y + 1, x + width - 1, y + 1);
3939 gdk_draw_line (window, gc2,
3940 x + 1, y + 1, x + 1, y + height - 2);
3942 gdk_draw_line (window, gc3,
3943 x + 1, y + height - 2, x + width - 1, y + height - 2);
3944 gdk_draw_line (window, gc4,
3945 x, y + height - 1, x + width - 1, y + height - 1);
3948 gdk_draw_line (window, gc4,
3949 x + width - 1, y, x + width - 1, y + gap_x - 1);
3950 gdk_draw_line (window, gc3,
3951 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
3952 gdk_draw_line (window, gc3,
3953 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
3955 if ((width - (gap_x + gap_width)) > 0)
3957 gdk_draw_line (window, gc4,
3958 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
3959 gdk_draw_line (window, gc3,
3960 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
3961 gdk_draw_line (window, gc3,
3962 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
3970 gdk_gc_set_clip_rectangle (gc1, NULL);
3971 gdk_gc_set_clip_rectangle (gc2, NULL);
3972 gdk_gc_set_clip_rectangle (gc3, NULL);
3973 gdk_gc_set_clip_rectangle (gc4, NULL);
3978 gtk_default_draw_box_gap (GtkStyle *style,
3980 GtkStateType state_type,
3981 GtkShadowType shadow_type,
3984 const gchar *detail,
3989 GtkPositionType gap_side,
3998 g_return_if_fail (GTK_IS_STYLE (style));
3999 g_return_if_fail (window != NULL);
4001 gtk_style_apply_default_background (style, window,
4002 widget && !GTK_WIDGET_NO_WINDOW (widget),
4003 state_type, area, x, y, width, height);
4005 sanitize_size (window, &width, &height);
4007 switch (shadow_type)
4009 case GTK_SHADOW_NONE:
4012 gc1 = style->dark_gc[state_type];
4013 gc2 = style->black_gc;
4014 gc3 = style->bg_gc[state_type];
4015 gc4 = style->light_gc[state_type];
4017 case GTK_SHADOW_ETCHED_IN:
4018 gc1 = style->dark_gc[state_type];
4019 gc2 = style->light_gc[state_type];
4020 gc3 = style->dark_gc[state_type];
4021 gc4 = style->light_gc[state_type];
4023 case GTK_SHADOW_OUT:
4024 gc1 = style->light_gc[state_type];
4025 gc2 = style->bg_gc[state_type];
4026 gc3 = style->dark_gc[state_type];
4027 gc4 = style->black_gc;
4029 case GTK_SHADOW_ETCHED_OUT:
4030 gc1 = style->light_gc[state_type];
4031 gc2 = style->dark_gc[state_type];
4032 gc3 = style->light_gc[state_type];
4033 gc4 = style->dark_gc[state_type];
4039 gdk_gc_set_clip_rectangle (gc1, area);
4040 gdk_gc_set_clip_rectangle (gc2, area);
4041 gdk_gc_set_clip_rectangle (gc3, area);
4042 gdk_gc_set_clip_rectangle (gc4, area);
4045 switch (shadow_type)
4047 case GTK_SHADOW_NONE:
4049 case GTK_SHADOW_OUT:
4050 case GTK_SHADOW_ETCHED_IN:
4051 case GTK_SHADOW_ETCHED_OUT:
4055 gdk_draw_line (window, gc1,
4056 x, y, x, y + height - 1);
4057 gdk_draw_line (window, gc2,
4058 x + 1, y, x + 1, y + height - 2);
4060 gdk_draw_line (window, gc3,
4061 x + 1, y + height - 2, x + width - 2, y + height - 2);
4062 gdk_draw_line (window, gc3,
4063 x + width - 2, y, x + width - 2, y + height - 2);
4064 gdk_draw_line (window, gc4,
4065 x, y + height - 1, x + width - 1, y + height - 1);
4066 gdk_draw_line (window, gc4,
4067 x + width - 1, y, x + width - 1, y + height - 1);
4070 gdk_draw_line (window, gc1,
4071 x, y, x + gap_x - 1, y);
4072 gdk_draw_line (window, gc2,
4073 x + 1, y + 1, x + gap_x - 1, y + 1);
4074 gdk_draw_line (window, gc2,
4075 x + gap_x, y, x + gap_x, y);
4077 if ((width - (gap_x + gap_width)) > 0)
4079 gdk_draw_line (window, gc1,
4080 x + gap_x + gap_width, y, x + width - 2, y);
4081 gdk_draw_line (window, gc2,
4082 x + gap_x + gap_width, y + 1, x + width - 2, y + 1);
4083 gdk_draw_line (window, gc2,
4084 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
4087 case GTK_POS_BOTTOM:
4088 gdk_draw_line (window, gc1,
4089 x, y, x + width - 1, y);
4090 gdk_draw_line (window, gc1,
4091 x, y, x, y + height - 1);
4092 gdk_draw_line (window, gc2,
4093 x + 1, y + 1, x + width - 2, y + 1);
4094 gdk_draw_line (window, gc2,
4095 x + 1, y + 1, x + 1, y + height - 1);
4097 gdk_draw_line (window, gc3,
4098 x + width - 2, y + 1, x + width - 2, y + height - 1);
4099 gdk_draw_line (window, gc4,
4100 x + width - 1, y, x + width - 1, y + height - 1);
4103 gdk_draw_line (window, gc4,
4104 x, y + height - 1, x + gap_x - 1, y + height - 1);
4105 gdk_draw_line (window, gc3,
4106 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
4107 gdk_draw_line (window, gc3,
4108 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
4110 if ((width - (gap_x + gap_width)) > 0)
4112 gdk_draw_line (window, gc4,
4113 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
4114 gdk_draw_line (window, gc3,
4115 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
4116 gdk_draw_line (window, gc3,
4117 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
4121 gdk_draw_line (window, gc1,
4122 x, y, x + width - 1, y);
4123 gdk_draw_line (window, gc2,
4124 x, y + 1, x + width - 2, y + 1);
4126 gdk_draw_line (window, gc3,
4127 x, y + height - 2, x + width - 2, y + height - 2);
4128 gdk_draw_line (window, gc3,
4129 x + width - 2, y + 1, x + width - 2, y + height - 2);
4130 gdk_draw_line (window, gc4,
4131 x, y + height - 1, x + width - 1, y + height - 1);
4132 gdk_draw_line (window, gc4,
4133 x + width - 1, y, x + width - 1, y + height - 1);
4136 gdk_draw_line (window, gc1,
4137 x, y, x, y + gap_x - 1);
4138 gdk_draw_line (window, gc2,
4139 x + 1, y + 1, x + 1, y + gap_x - 1);
4140 gdk_draw_line (window, gc2,
4141 x, y + gap_x, x, y + gap_x);
4143 if ((width - (gap_x + gap_width)) > 0)
4145 gdk_draw_line (window, gc1,
4146 x, y + gap_x + gap_width, x, y + height - 2);
4147 gdk_draw_line (window, gc2,
4148 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
4149 gdk_draw_line (window, gc2,
4150 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
4154 gdk_draw_line (window, gc1,
4155 x, y, x + width - 1, y);
4156 gdk_draw_line (window, gc1,
4157 x, y, x, y + height - 1);
4158 gdk_draw_line (window, gc2,
4159 x + 1, y + 1, x + width - 1, y + 1);
4160 gdk_draw_line (window, gc2,
4161 x + 1, y + 1, x + 1, y + height - 2);
4163 gdk_draw_line (window, gc3,
4164 x + 1, y + height - 2, x + width - 1, y + height - 2);
4165 gdk_draw_line (window, gc4,
4166 x, y + height - 1, x + width - 1, y + height - 1);
4169 gdk_draw_line (window, gc4,
4170 x + width - 1, y, x + width - 1, y + gap_x - 1);
4171 gdk_draw_line (window, gc3,
4172 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
4173 gdk_draw_line (window, gc3,
4174 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
4176 if ((width - (gap_x + gap_width)) > 0)
4178 gdk_draw_line (window, gc4,
4179 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
4180 gdk_draw_line (window, gc3,
4181 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
4182 gdk_draw_line (window, gc3,
4183 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
4191 gdk_gc_set_clip_rectangle (gc1, NULL);
4192 gdk_gc_set_clip_rectangle (gc2, NULL);
4193 gdk_gc_set_clip_rectangle (gc3, NULL);
4194 gdk_gc_set_clip_rectangle (gc4, NULL);
4199 gtk_default_draw_extension (GtkStyle *style,
4201 GtkStateType state_type,
4202 GtkShadowType shadow_type,
4205 const gchar *detail,
4210 GtkPositionType gap_side)
4217 g_return_if_fail (GTK_IS_STYLE (style));
4218 g_return_if_fail (window != NULL);
4220 gtk_style_apply_default_background (style, window,
4221 widget && !GTK_WIDGET_NO_WINDOW (widget),
4222 GTK_STATE_NORMAL, area, x, y, width, height);
4224 sanitize_size (window, &width, &height);
4226 switch (shadow_type)
4228 case GTK_SHADOW_NONE:
4231 gc1 = style->dark_gc[state_type];
4232 gc2 = style->black_gc;
4233 gc3 = style->bg_gc[state_type];
4234 gc4 = style->light_gc[state_type];
4236 case GTK_SHADOW_ETCHED_IN:
4237 gc1 = style->dark_gc[state_type];
4238 gc2 = style->light_gc[state_type];
4239 gc3 = style->dark_gc[state_type];
4240 gc4 = style->light_gc[state_type];
4242 case GTK_SHADOW_OUT:
4243 gc1 = style->light_gc[state_type];
4244 gc2 = style->bg_gc[state_type];
4245 gc3 = style->dark_gc[state_type];
4246 gc4 = style->black_gc;
4248 case GTK_SHADOW_ETCHED_OUT:
4249 gc1 = style->light_gc[state_type];
4250 gc2 = style->dark_gc[state_type];
4251 gc3 = style->light_gc[state_type];
4252 gc4 = style->dark_gc[state_type];
4258 gdk_gc_set_clip_rectangle (gc1, area);
4259 gdk_gc_set_clip_rectangle (gc2, area);
4260 gdk_gc_set_clip_rectangle (gc3, area);
4261 gdk_gc_set_clip_rectangle (gc4, area);
4264 switch (shadow_type)
4266 case GTK_SHADOW_NONE:
4268 case GTK_SHADOW_OUT:
4269 case GTK_SHADOW_ETCHED_IN:
4270 case GTK_SHADOW_ETCHED_OUT:
4274 gtk_style_apply_default_background (style, window,
4275 widget && !GTK_WIDGET_NO_WINDOW (widget),
4277 x + style->xthickness,
4279 width - (2 * style->xthickness),
4280 height - (style->ythickness));
4281 gdk_draw_line (window, gc1,
4282 x, y, x, y + height - 2);
4283 gdk_draw_line (window, gc2,
4284 x + 1, y, x + 1, y + height - 2);
4286 gdk_draw_line (window, gc3,
4287 x + 2, y + height - 2, x + width - 2, y + height - 2);
4288 gdk_draw_line (window, gc3,
4289 x + width - 2, y, x + width - 2, y + height - 2);
4290 gdk_draw_line (window, gc4,
4291 x + 1, y + height - 1, x + width - 2, y + height - 1);
4292 gdk_draw_line (window, gc4,
4293 x + width - 1, y, x + width - 1, y + height - 2);
4295 case GTK_POS_BOTTOM:
4296 gtk_style_apply_default_background (style, window,
4297 widget && !GTK_WIDGET_NO_WINDOW (widget),
4299 x + style->xthickness,
4300 y + style->ythickness,
4301 width - (2 * style->xthickness),
4302 height - (style->ythickness));
4303 gdk_draw_line (window, gc1,
4304 x + 1, y, x + width - 2, y);
4305 gdk_draw_line (window, gc1,
4306 x, y + 1, x, y + height - 1);
4307 gdk_draw_line (window, gc2,
4308 x + 1, y + 1, x + width - 2, y + 1);
4309 gdk_draw_line (window, gc2,
4310 x + 1, y + 1, x + 1, y + height - 1);
4312 gdk_draw_line (window, gc3,
4313 x + width - 2, y + 2, x + width - 2, y + height - 1);
4314 gdk_draw_line (window, gc4,
4315 x + width - 1, y + 1, x + width - 1, y + height - 1);
4318 gtk_style_apply_default_background (style, window,
4319 widget && !GTK_WIDGET_NO_WINDOW (widget),
4322 y + style->ythickness,
4323 width - (style->xthickness),
4324 height - (2 * style->ythickness));
4325 gdk_draw_line (window, gc1,
4326 x, y, x + width - 2, y);
4327 gdk_draw_line (window, gc2,
4328 x + 1, y + 1, x + width - 2, y + 1);
4330 gdk_draw_line (window, gc3,
4331 x, y + height - 2, x + width - 2, y + height - 2);
4332 gdk_draw_line (window, gc3,
4333 x + width - 2, y + 2, x + width - 2, y + height - 2);
4334 gdk_draw_line (window, gc4,
4335 x, y + height - 1, x + width - 2, y + height - 1);
4336 gdk_draw_line (window, gc4,
4337 x + width - 1, y + 1, x + width - 1, y + height - 2);
4340 gtk_style_apply_default_background (style, window,
4341 widget && !GTK_WIDGET_NO_WINDOW (widget),
4343 x + style->xthickness,
4344 y + style->ythickness,
4345 width - (style->xthickness),
4346 height - (2 * style->ythickness));
4347 gdk_draw_line (window, gc1,
4348 x + 1, y, x + width - 1, y);
4349 gdk_draw_line (window, gc1,
4350 x, y + 1, x, y + height - 2);
4351 gdk_draw_line (window, gc2,
4352 x + 1, y + 1, x + width - 1, y + 1);
4353 gdk_draw_line (window, gc2,
4354 x + 1, y + 1, x + 1, y + height - 2);
4356 gdk_draw_line (window, gc3,
4357 x + 2, y + height - 2, x + width - 1, y + height - 2);
4358 gdk_draw_line (window, gc4,
4359 x + 1, y + height - 1, x + width - 1, y + height - 1);
4366 gdk_gc_set_clip_rectangle (gc1, NULL);
4367 gdk_gc_set_clip_rectangle (gc2, NULL);
4368 gdk_gc_set_clip_rectangle (gc3, NULL);
4369 gdk_gc_set_clip_rectangle (gc4, NULL);
4374 gtk_default_draw_focus (GtkStyle *style,
4376 GtkStateType state_type,
4379 const gchar *detail,
4387 gboolean free_dash_list = FALSE;
4388 gint line_width = 1;
4389 gint8 *dash_list = "\1\1";
4392 gc = style->fg_gc[state_type];
4396 gtk_widget_style_get (widget,
4397 "focus-line-width", &line_width,
4398 "focus-line-pattern", (gchar *)&dash_list,
4401 free_dash_list = TRUE;
4404 sanitize_size (window, &width, &height);
4407 gdk_gc_set_clip_rectangle (gc, area);
4409 gdk_gc_set_line_attributes (gc, line_width,
4410 dash_list[0] ? GDK_LINE_ON_OFF_DASH : GDK_LINE_SOLID,
4411 GDK_CAP_BUTT, GDK_JOIN_MITER);
4414 if (detail && !strcmp (detail, "add-mode"))
4420 free_dash_list = FALSE;
4423 points[0].x = x + line_width / 2;
4424 points[0].y = y + line_width / 2;
4425 points[1].x = x + width - line_width + line_width / 2;
4426 points[1].y = y + line_width / 2;
4427 points[2].x = x + width - line_width + line_width / 2;
4428 points[2].y = y + height - line_width + line_width / 2;
4429 points[3].x = x + line_width / 2;
4430 points[3].y = y + height - line_width + line_width / 2;
4431 points[4] = points[0];
4435 gdk_draw_lines (window, gc, points, 5);
4439 /* We go through all the pain below because the X rasterization
4440 * rules don't really work right for dashed lines if you
4441 * want continuity in segments that go between top/right
4442 * and left/bottom. For instance, a top left corner
4443 * with a 1-1 dash is drawn as:
4450 * This is because pixels on the top and left boundaries
4451 * of polygons are drawn, but not on the bottom and right.
4452 * So, if you have a line going up that turns the corner
4453 * and goes right, there is a one pixel shift in the pattern.
4455 * So, to fix this, we drawn the top and right in one call,
4456 * then the left and bottom in another call, fixing up
4457 * the dash offset for the second call ourselves to get
4458 * continuity at the upper left.
4460 * It's not perfect since we really should have a join at
4461 * the upper left and lower right instead of two intersecting
4462 * lines but that's only really apparent for no-dashes,
4463 * which (for this reason) are done as one polygon and
4464 * don't to through this code path.
4467 dash_len = strlen (dash_list);
4470 gdk_gc_set_dashes (gc, 0, dash_list, dash_len);
4472 gdk_draw_lines (window, gc, points, 3);
4474 /* We draw this line one farther over than it is "supposed" to
4475 * because of another rasterization problem ... if two 1 pixel
4476 * unjoined lines meet at the lower right, there will be a missing
4483 gint dash_pixels = 0;
4486 /* Adjust the dash offset for the bottom and left so we
4487 * match up at the upper left.
4489 for (i = 0; i < dash_len; i++)
4490 dash_pixels += dash_list[i];
4492 if (dash_len % 2 == 1)
4495 gdk_gc_set_dashes (gc, dash_pixels - (width + height - 2 * line_width) % dash_pixels, dash_list, dash_len);
4498 gdk_draw_lines (window, gc, points + 2, 3);
4501 gdk_gc_set_line_attributes (gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
4504 gdk_gc_set_clip_rectangle (gc, NULL);
4511 gtk_default_draw_slider (GtkStyle *style,
4513 GtkStateType state_type,
4514 GtkShadowType shadow_type,
4517 const gchar *detail,
4522 GtkOrientation orientation)
4524 g_return_if_fail (GTK_IS_STYLE (style));
4525 g_return_if_fail (window != NULL);
4527 sanitize_size (window, &width, &height);
4529 gtk_paint_box (style, window, state_type, shadow_type,
4530 area, widget, detail, x, y, width, height);
4533 (strcmp ("hscale", detail) == 0 ||
4534 strcmp ("vscale", detail) == 0))
4536 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4537 gtk_paint_vline (style, window, state_type, area, widget, detail,
4538 y + style->ythickness,
4539 y + height - style->ythickness - 1, x + width / 2);
4541 gtk_paint_hline (style, window, state_type, area, widget, detail,
4542 x + style->xthickness,
4543 x + width - style->xthickness - 1, y + height / 2);
4548 draw_dot (GdkWindow *window,
4556 size = CLAMP (size, 2, 3);
4560 gdk_draw_point (window, light_gc, x, y);
4561 gdk_draw_point (window, light_gc, x+1, y+1);
4563 else if (size == 3);
4565 gdk_draw_point (window, light_gc, x, y);
4566 gdk_draw_point (window, light_gc, x+1, y);
4567 gdk_draw_point (window, light_gc, x, y+1);
4568 gdk_draw_point (window, dark_gc, x+1, y+2);
4569 gdk_draw_point (window, dark_gc, x+2, y+1);
4570 gdk_draw_point (window, dark_gc, x+2, y+2);
4575 gtk_default_draw_handle (GtkStyle *style,
4577 GtkStateType state_type,
4578 GtkShadowType shadow_type,
4581 const gchar *detail,
4586 GtkOrientation orientation)
4589 gint xthick, ythick;
4590 GdkGC *light_gc, *dark_gc;
4595 g_return_if_fail (GTK_IS_STYLE (style));
4596 g_return_if_fail (window != NULL);
4598 sanitize_size (window, &width, &height);
4600 gtk_paint_box (style, window, state_type, shadow_type, area, widget,
4601 detail, x, y, width, height);
4604 if (!strcmp (detail, "paned"))
4606 /* we want to ignore the shadow border in paned widgets */
4610 light_gc = style->light_gc[state_type];
4611 dark_gc = style->black_gc;
4615 xthick = style->xthickness;
4616 ythick = style->ythickness;
4618 light_gc = style->light_gc[state_type];
4619 dark_gc = style->dark_gc[state_type];
4622 rect.x = x + xthick;
4623 rect.y = y + ythick;
4624 rect.width = width - (xthick * 2);
4625 rect.height = height - (ythick * 2);
4628 intersect = gdk_rectangle_intersect (area, &rect, &dest);
4638 gdk_gc_set_clip_rectangle (light_gc, &dest);
4639 gdk_gc_set_clip_rectangle (dark_gc, &dest);
4641 if (!strcmp (detail, "paned"))
4643 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4644 for (xx = x + width/2 - 15; xx <= x + width/2 + 15; xx += 5)
4645 draw_dot (window, light_gc, dark_gc, xx, y + height/2 - 1, 3);
4647 for (yy = y + height/2 - 15; yy <= y + height/2 + 15; yy += 5)
4648 draw_dot (window, light_gc, dark_gc, x + width/2 - 1, yy, 3);
4652 for (yy = y + ythick; yy < (y + height - ythick); yy += 3)
4653 for (xx = x + xthick; xx < (x + width - xthick); xx += 6)
4655 draw_dot (window, light_gc, dark_gc, xx, yy, 2);
4656 draw_dot (window, light_gc, dark_gc, xx + 3, yy + 1, 2);
4660 gdk_gc_set_clip_rectangle (light_gc, NULL);
4661 gdk_gc_set_clip_rectangle (dark_gc, NULL);
4665 create_expander_affine (gdouble affine[6],
4675 width = expander_size / 4.0;
4676 height = expander_size / 2.0;
4678 s = sin (degrees * G_PI / 180.0);
4679 c = cos (degrees * G_PI / 180.0);
4685 affine[4] = -width * c - height * -s + x;
4686 affine[5] = -width * s - height * c + y;
4690 apply_affine_on_point (double affine[6], GdkPoint *point)
4694 x = point->x * affine[0] + point->y * affine[2] + affine[4];
4695 y = point->x * affine[1] + point->y * affine[3] + affine[5];
4702 gtk_style_draw_polygon_with_gc (GdkWindow *window, GdkGC *gc, gint line_width,
4703 gboolean do_fill, GdkPoint *points, gint n_points)
4705 gdk_gc_set_line_attributes (gc, line_width,
4707 GDK_CAP_BUTT, GDK_JOIN_MITER);
4709 gdk_draw_polygon (window, gc, do_fill, points, n_points);
4710 gdk_gc_set_line_attributes (gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
4714 gtk_default_draw_expander (GtkStyle *style,
4716 GtkStateType state_type,
4719 const gchar *detail,
4722 GtkExpanderStyle expander_style)
4731 gtk_widget_style_get (widget,
4732 "expander_size", &expander_size,
4734 line_width = MAX (1, expander_size/7);
4738 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], area);
4739 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], area);
4742 expander_size -= (line_width * 2 - 2);
4743 points[0].x = line_width / 2;
4744 points[0].y = line_width / 2;
4745 points[1].x = expander_size / 2 + line_width / 2;
4746 points[1].y = expander_size / 2 + line_width / 2;
4747 points[2].x = line_width / 2;
4748 points[2].y = expander_size + line_width / 2;
4750 switch (expander_style)
4752 case GTK_EXPANDER_COLLAPSED:
4753 degrees = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ? 180 : 0;
4755 case GTK_EXPANDER_SEMI_COLLAPSED:
4756 degrees = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ? 150 : 30;
4758 case GTK_EXPANDER_SEMI_EXPANDED:
4759 degrees = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ? 120 : 60;
4761 case GTK_EXPANDER_EXPANDED:
4765 g_assert_not_reached ();
4768 create_expander_affine (affine, degrees, expander_size, x, y);
4770 for (i = 0; i < 3; i++)
4771 apply_affine_on_point (affine, &points[i]);
4773 if (state_type == GTK_STATE_PRELIGHT)
4775 gtk_style_draw_polygon_with_gc (window, style->fg_gc[GTK_STATE_NORMAL],
4776 1, TRUE, points, 3);
4778 else if (state_type == GTK_STATE_ACTIVE)
4780 gtk_style_draw_polygon_with_gc (window, style->light_gc[GTK_STATE_ACTIVE],
4781 1, TRUE, points, 3);
4782 gtk_style_draw_polygon_with_gc (window, style->fg_gc[GTK_STATE_NORMAL],
4783 line_width, FALSE, points, 3);
4787 gtk_style_draw_polygon_with_gc (window, style->base_gc[GTK_STATE_NORMAL],
4788 1, TRUE, points, 3);
4789 gtk_style_draw_polygon_with_gc (window, style->fg_gc[GTK_STATE_NORMAL],
4790 line_width, FALSE, points, 3);
4794 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], NULL);
4795 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], NULL);
4799 typedef struct _ByteRange ByteRange;
4808 range_new (guint start,
4811 ByteRange *br = g_new (ByteRange, 1);
4820 get_insensitive_layout (GdkDrawable *drawable,
4821 PangoLayout *layout)
4823 GSList *embossed_ranges = NULL;
4824 GSList *stippled_ranges = NULL;
4825 PangoLayoutIter *iter;
4826 GSList *tmp_list = NULL;
4827 PangoLayout *new_layout;
4828 PangoAttrList *attrs;
4829 GdkBitmap *stipple = NULL;
4831 iter = pango_layout_get_iter (layout);
4835 PangoLayoutRun *run;
4836 PangoAttribute *attr;
4837 gboolean need_stipple = FALSE;
4840 run = pango_layout_iter_get_run (iter);
4844 tmp_list = run->item->analysis.extra_attrs;
4846 while (tmp_list != NULL)
4848 attr = tmp_list->data;
4849 switch (attr->klass->type)
4851 case PANGO_ATTR_FOREGROUND:
4852 case PANGO_ATTR_BACKGROUND:
4853 need_stipple = TRUE;
4863 tmp_list = g_slist_next (tmp_list);
4866 br = range_new (run->item->offset, run->item->offset + run->item->length);
4869 stippled_ranges = g_slist_prepend (stippled_ranges, br);
4871 embossed_ranges = g_slist_prepend (embossed_ranges, br);
4874 while (pango_layout_iter_next_run (iter));
4876 pango_layout_iter_free (iter);
4878 new_layout = pango_layout_copy (layout);
4880 attrs = pango_layout_get_attributes (new_layout);
4884 /* Create attr list if there wasn't one */
4885 attrs = pango_attr_list_new ();
4886 pango_layout_set_attributes (new_layout, attrs);
4887 pango_attr_list_unref (attrs);
4890 tmp_list = embossed_ranges;
4891 while (tmp_list != NULL)
4893 PangoAttribute *attr;
4894 ByteRange *br = tmp_list->data;
4896 attr = gdk_pango_attr_embossed_new (TRUE);
4898 attr->start_index = br->start;
4899 attr->end_index = br->end;
4901 pango_attr_list_change (attrs, attr);
4905 tmp_list = g_slist_next (tmp_list);
4908 g_slist_free (embossed_ranges);
4910 tmp_list = stippled_ranges;
4911 while (tmp_list != NULL)
4913 PangoAttribute *attr;
4914 ByteRange *br = tmp_list->data;
4916 if (stipple == NULL)
4918 #define gray50_width 2
4919 #define gray50_height 2
4920 static char gray50_bits[] = {
4924 stipple = gdk_bitmap_create_from_data (drawable,
4925 gray50_bits, gray50_width,
4929 attr = gdk_pango_attr_stipple_new (stipple);
4931 attr->start_index = br->start;
4932 attr->end_index = br->end;
4934 pango_attr_list_change (attrs, attr);
4938 tmp_list = g_slist_next (tmp_list);
4941 g_slist_free (stippled_ranges);
4944 g_object_unref (stipple);
4950 gtk_default_draw_layout (GtkStyle *style,
4952 GtkStateType state_type,
4956 const gchar *detail,
4959 PangoLayout *layout)
4963 g_return_if_fail (GTK_IS_STYLE (style));
4964 g_return_if_fail (window != NULL);
4966 gc = use_text ? style->text_gc[state_type] : style->fg_gc[state_type];
4969 gdk_gc_set_clip_rectangle (gc, area);
4971 if (state_type == GTK_STATE_INSENSITIVE)
4975 ins = get_insensitive_layout (window, layout);
4977 gdk_draw_layout (window, gc, x, y, ins);
4979 g_object_unref (ins);
4983 gdk_draw_layout (window, gc, x, y, layout);
4987 gdk_gc_set_clip_rectangle (gc, NULL);
4991 gtk_default_draw_resize_grip (GtkStyle *style,
4993 GtkStateType state_type,
4996 const gchar *detail,
5003 g_return_if_fail (GTK_IS_STYLE (style));
5004 g_return_if_fail (window != NULL);
5008 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
5009 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
5010 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
5015 case GDK_WINDOW_EDGE_NORTH_WEST:
5016 /* make it square */
5021 else if (height < width)
5026 case GDK_WINDOW_EDGE_NORTH:
5032 case GDK_WINDOW_EDGE_NORTH_EAST:
5033 /* make it square, aligning to top right */
5038 else if (height < width)
5040 x += (width - height);
5044 case GDK_WINDOW_EDGE_WEST:
5050 case GDK_WINDOW_EDGE_EAST:
5051 /* aligning to right */
5054 x += (width - height);
5058 case GDK_WINDOW_EDGE_SOUTH_WEST:
5059 /* make it square, aligning to bottom left */
5062 y += (height - width);
5065 else if (height < width)
5070 case GDK_WINDOW_EDGE_SOUTH:
5071 /* align to bottom */
5074 y += (height - width);
5078 case GDK_WINDOW_EDGE_SOUTH_EAST:
5079 /* make it square, aligning to bottom right */
5082 y += (height - width);
5085 else if (height < width)
5087 x += (width - height);
5092 g_assert_not_reached ();
5094 /* Clear background */
5095 gtk_style_apply_default_background (style, window, FALSE,
5097 x, y, width, height);
5101 case GDK_WINDOW_EDGE_WEST:
5102 case GDK_WINDOW_EDGE_EAST:
5108 while (xi < x + width)
5110 gdk_draw_line (window,
5111 style->light_gc[state_type],
5116 gdk_draw_line (window,
5117 style->dark_gc[state_type],
5125 case GDK_WINDOW_EDGE_NORTH:
5126 case GDK_WINDOW_EDGE_SOUTH:
5132 while (yi < y + height)
5134 gdk_draw_line (window,
5135 style->light_gc[state_type],
5140 gdk_draw_line (window,
5141 style->dark_gc[state_type],
5149 case GDK_WINDOW_EDGE_NORTH_WEST:
5158 gdk_draw_line (window,
5159 style->dark_gc[state_type],
5166 gdk_draw_line (window,
5167 style->dark_gc[state_type],
5174 gdk_draw_line (window,
5175 style->light_gc[state_type],
5185 case GDK_WINDOW_EDGE_NORTH_EAST:
5192 while (xi < (x + width - 3))
5194 gdk_draw_line (window,
5195 style->light_gc[state_type],
5202 gdk_draw_line (window,
5203 style->dark_gc[state_type],
5210 gdk_draw_line (window,
5211 style->dark_gc[state_type],
5220 case GDK_WINDOW_EDGE_SOUTH_WEST:
5229 gdk_draw_line (window,
5230 style->dark_gc[state_type],
5237 gdk_draw_line (window,
5238 style->dark_gc[state_type],
5245 gdk_draw_line (window,
5246 style->light_gc[state_type],
5256 case GDK_WINDOW_EDGE_SOUTH_EAST:
5263 while (xi < (x + width - 3))
5265 gdk_draw_line (window,
5266 style->light_gc[state_type],
5273 gdk_draw_line (window,
5274 style->dark_gc[state_type],
5281 gdk_draw_line (window,
5282 style->dark_gc[state_type],
5292 g_assert_not_reached ();
5298 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
5299 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
5300 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
5305 gtk_style_shade (GdkColor *a,
5313 red = (gdouble) a->red / 65535.0;
5314 green = (gdouble) a->green / 65535.0;
5315 blue = (gdouble) a->blue / 65535.0;
5317 rgb_to_hls (&red, &green, &blue);
5322 else if (green < 0.0)
5328 else if (blue < 0.0)
5331 hls_to_rgb (&red, &green, &blue);
5333 b->red = red * 65535.0;
5334 b->green = green * 65535.0;
5335 b->blue = blue * 65535.0;
5339 rgb_to_hls (gdouble *r,
5380 l = (max + min) / 2;
5387 s = (max - min) / (max + min);
5389 s = (max - min) / (2 - max - min);
5393 h = (green - blue) / delta;
5394 else if (green == max)
5395 h = 2 + (blue - red) / delta;
5396 else if (blue == max)
5397 h = 4 + (red - green) / delta;
5410 hls_to_rgb (gdouble *h,
5423 if (lightness <= 0.5)
5424 m2 = lightness * (1 + saturation);
5426 m2 = lightness + saturation - lightness * saturation;
5427 m1 = 2 * lightness - m2;
5429 if (saturation == 0)
5444 r = m1 + (m2 - m1) * hue / 60;
5448 r = m1 + (m2 - m1) * (240 - hue) / 60;
5459 g = m1 + (m2 - m1) * hue / 60;
5463 g = m1 + (m2 - m1) * (240 - hue) / 60;
5474 b = m1 + (m2 - m1) * hue / 60;
5478 b = m1 + (m2 - m1) * (240 - hue) / 60;
5491 * @style: a #GtkStyle
5492 * @window: a #GdkWindow
5493 * @state_type: a state
5494 * @area: rectangle to which the output is clipped
5497 * @x1: the starting x coordinate
5498 * @x2: the ending x coordinate
5499 * @y: the y coordinate
5501 * Draws a horizontal line from (@x1, @y) to (@x2, @y) in @window
5502 * using the given style and state.
5505 gtk_paint_hline (GtkStyle *style,
5507 GtkStateType state_type,
5510 const gchar *detail,
5515 g_return_if_fail (GTK_IS_STYLE (style));
5516 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
5518 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, area, widget, detail, x1, x2, y);
5523 * @style: a #GtkStyle
5524 * @window: a #GdkWindow
5525 * @state_type: a state
5526 * @area: rectangle to which the output is clipped
5529 * @y1_: the starting y coordinate
5530 * @y2_: the ending y coordinate
5531 * @x: the x coordinate
5533 * Draws a vertical line from (@x, @y1_) to (@x, @y2_) in @window
5534 * using the given style and state.
5537 gtk_paint_vline (GtkStyle *style,
5539 GtkStateType state_type,
5542 const gchar *detail,
5547 g_return_if_fail (GTK_IS_STYLE (style));
5548 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
5550 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, area, widget, detail, y1, y2, x);
5554 gtk_paint_shadow (GtkStyle *style,
5556 GtkStateType state_type,
5557 GtkShadowType shadow_type,
5560 const gchar *detail,
5566 g_return_if_fail (GTK_IS_STYLE (style));
5567 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
5569 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5573 gtk_paint_polygon (GtkStyle *style,
5575 GtkStateType state_type,
5576 GtkShadowType shadow_type,
5579 const gchar *detail,
5584 g_return_if_fail (GTK_IS_STYLE (style));
5585 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
5587 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, area, widget, detail, points, npoints, fill);
5591 gtk_paint_arrow (GtkStyle *style,
5593 GtkStateType state_type,
5594 GtkShadowType shadow_type,
5597 const gchar *detail,
5598 GtkArrowType arrow_type,
5605 g_return_if_fail (GTK_IS_STYLE (style));
5606 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
5608 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, area, widget, detail, arrow_type, fill, x, y, width, height);
5612 gtk_paint_diamond (GtkStyle *style,
5614 GtkStateType state_type,
5615 GtkShadowType shadow_type,
5618 const gchar *detail,
5624 g_return_if_fail (GTK_IS_STYLE (style));
5625 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
5627 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5632 * @style: a #GtkStyle
5633 * @window: a #GdkWindow
5634 * @state_type: a state
5635 * @area: clip rectangle
5636 * @widget: the widget
5637 * @detail: a style detail
5640 * @string: the string to draw
5642 * Draws a text string on @window with the given parameters.
5644 * This function is deprecated, use gtk_paint_layout() instead.
5647 gtk_paint_string (GtkStyle *style,
5649 GtkStateType state_type,
5652 const gchar *detail,
5655 const gchar *string)
5657 g_return_if_fail (GTK_IS_STYLE (style));
5658 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
5660 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, area, widget, detail, x, y, string);
5664 gtk_paint_box (GtkStyle *style,
5666 GtkStateType state_type,
5667 GtkShadowType shadow_type,
5670 const gchar *detail,
5676 g_return_if_fail (GTK_IS_STYLE (style));
5677 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
5679 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5683 gtk_paint_flat_box (GtkStyle *style,
5685 GtkStateType state_type,
5686 GtkShadowType shadow_type,
5689 const gchar *detail,
5695 g_return_if_fail (GTK_IS_STYLE (style));
5696 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
5698 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5702 gtk_paint_check (GtkStyle *style,
5704 GtkStateType state_type,
5705 GtkShadowType shadow_type,
5708 const gchar *detail,
5714 g_return_if_fail (GTK_IS_STYLE (style));
5715 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
5717 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5721 gtk_paint_option (GtkStyle *style,
5723 GtkStateType state_type,
5724 GtkShadowType shadow_type,
5727 const gchar *detail,
5733 g_return_if_fail (GTK_IS_STYLE (style));
5734 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
5736 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5740 gtk_paint_tab (GtkStyle *style,
5742 GtkStateType state_type,
5743 GtkShadowType shadow_type,
5746 const gchar *detail,
5752 g_return_if_fail (GTK_IS_STYLE (style));
5753 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
5755 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5759 gtk_paint_shadow_gap (GtkStyle *style,
5761 GtkStateType state_type,
5762 GtkShadowType shadow_type,
5770 GtkPositionType gap_side,
5774 g_return_if_fail (GTK_IS_STYLE (style));
5775 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
5777 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);
5782 gtk_paint_box_gap (GtkStyle *style,
5784 GtkStateType state_type,
5785 GtkShadowType shadow_type,
5793 GtkPositionType gap_side,
5797 g_return_if_fail (GTK_IS_STYLE (style));
5798 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
5800 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);
5804 gtk_paint_extension (GtkStyle *style,
5806 GtkStateType state_type,
5807 GtkShadowType shadow_type,
5815 GtkPositionType gap_side)
5817 g_return_if_fail (GTK_IS_STYLE (style));
5818 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
5820 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side);
5824 gtk_paint_focus (GtkStyle *style,
5826 GtkStateType state_type,
5829 const gchar *detail,
5835 g_return_if_fail (GTK_IS_STYLE (style));
5836 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
5838 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, state_type, area, widget, detail, x, y, width, height);
5842 gtk_paint_slider (GtkStyle *style,
5844 GtkStateType state_type,
5845 GtkShadowType shadow_type,
5848 const gchar *detail,
5853 GtkOrientation orientation)
5855 g_return_if_fail (GTK_IS_STYLE (style));
5856 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
5858 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
5862 gtk_paint_handle (GtkStyle *style,
5864 GtkStateType state_type,
5865 GtkShadowType shadow_type,
5868 const gchar *detail,
5873 GtkOrientation orientation)
5875 g_return_if_fail (GTK_IS_STYLE (style));
5876 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
5878 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
5882 gtk_paint_expander (GtkStyle *style,
5884 GtkStateType state_type,
5887 const gchar *detail,
5890 GtkExpanderStyle expander_style)
5892 g_return_if_fail (GTK_IS_STYLE (style));
5893 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
5895 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type, area,
5896 widget, detail, x, y, expander_style);
5900 gtk_paint_layout (GtkStyle *style,
5902 GtkStateType state_type,
5906 const gchar *detail,
5909 PangoLayout *layout)
5911 g_return_if_fail (GTK_IS_STYLE (style));
5912 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
5914 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text, area,
5915 widget, detail, x, y, layout);
5919 gtk_paint_resize_grip (GtkStyle *style,
5921 GtkStateType state_type,
5924 const gchar *detail,
5932 g_return_if_fail (GTK_IS_STYLE (style));
5933 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
5935 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
5936 area, widget, detail,
5937 edge, x, y, width, height);
5942 * @border_: a #GtkBorder.
5943 * @returns: a copy of @border_.
5945 * Copies a #GtkBorder structure.
5948 gtk_border_copy (const GtkBorder *border)
5950 return (GtkBorder *)g_memdup (border, sizeof (GtkBorder));
5955 * @border_: a #GtkBorder.
5957 * Frees a #GtkBorder structure.
5960 gtk_border_free (GtkBorder *border)
5966 gtk_border_get_type (void)
5968 static GType our_type = 0;
5971 our_type = g_boxed_type_register_static ("GtkBorder",
5972 (GBoxedCopyFunc) gtk_border_copy,
5973 (GBoxedFreeFunc) gtk_border_free);
5979 gtk_style_get_font_internal (GtkStyle *style)
5981 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
5983 if (style->private_font && style->private_font_desc)
5985 if (!style->font_desc ||
5986 !pango_font_description_equal (style->private_font_desc, style->font_desc))
5988 gdk_font_unref (style->private_font);
5989 style->private_font = NULL;
5991 if (style->private_font_desc)
5993 pango_font_description_free (style->private_font_desc);
5994 style->private_font_desc = NULL;
5999 if (!style->private_font)
6001 GdkDisplay *display;
6003 if (style->colormap)
6005 display = gdk_screen_get_display (gdk_colormap_get_screen (style->colormap));
6009 display = gdk_display_get_default ();
6010 GTK_NOTE (MULTIHEAD,
6011 g_warning ("gtk_style_get_font() should not be called on an unattached style"));
6014 if (style->font_desc)
6016 style->private_font = gdk_font_from_description_for_display (display, style->font_desc);
6017 style->private_font_desc = pango_font_description_copy (style->font_desc);
6020 if (!style->private_font)
6021 style->private_font = gdk_font_load_for_display (display, "fixed");
6023 if (!style->private_font)
6024 g_error ("Unable to load \"fixed\" font");
6027 return style->private_font;
6031 * gtk_style_get_font:
6032 * @style: a #GtkStyle
6034 * Gets the #GdkFont to use for the given style. This is
6035 * meant only as a replacement for direct access to @style->font
6036 * and should not be used in new code. New code should
6037 * use @style->font_desc instead.
6039 * Return value: the #GdkFont for the style. This font is owned
6040 * by the style; if you want to keep around a copy, you must
6041 * call gdk_font_ref().
6044 gtk_style_get_font (GtkStyle *style)
6046 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
6048 return gtk_style_get_font_internal (style);
6052 * gtk_style_set_font:
6053 * @style: a #GtkStyle.
6054 * @font: a #GdkFont, or %NULL to use the #GdkFont corresponding
6055 * to style->font_desc.
6057 * Sets the #GdkFont to use for a given style. This is
6058 * meant only as a replacement for direct access to style->font
6059 * and should not be used in new code. New code should
6060 * use style->font_desc instead.
6063 gtk_style_set_font (GtkStyle *style,
6068 g_return_if_fail (GTK_IS_STYLE (style));
6070 old_font = style->private_font;
6072 style->private_font = font;
6074 gdk_font_ref (font);
6077 gdk_font_unref (old_font);
6079 if (style->private_font_desc)
6081 pango_font_description_free (style->private_font_desc);
6082 style->private_font_desc = NULL;
6086 typedef struct _CursorInfo CursorInfo;
6092 GdkGC *secondary_gc;
6096 style_unrealize_cursor_gcs (GtkStyle *style)
6100 cursor_info = g_object_get_data (G_OBJECT (style), "gtk-style-cursor-info");
6103 if (cursor_info->primary_gc)
6104 gtk_gc_release (cursor_info->primary_gc);
6106 if (cursor_info->secondary_gc)
6107 gtk_gc_release (cursor_info->secondary_gc);
6109 g_free (cursor_info);
6110 g_object_set_data (G_OBJECT (style), "gtk-style-cursor-info", NULL);
6115 make_cursor_gc (GtkWidget *widget,
6116 const gchar *property_name,
6119 GdkGCValues gc_values;
6120 GdkGCValuesMask gc_values_mask;
6121 GdkColor *cursor_color;
6123 gtk_widget_style_get (widget, property_name, &cursor_color, NULL);
6125 gc_values_mask = GDK_GC_FOREGROUND;
6128 gc_values.foreground = *cursor_color;
6129 gdk_color_free (cursor_color);
6132 gc_values.foreground = *fallback;
6134 gdk_rgb_find_color (widget->style->colormap, &gc_values.foreground);
6135 return gtk_gc_get (widget->style->depth, widget->style->colormap, &gc_values, gc_values_mask);
6139 * _gtk_get_insertion_cursor_gc:
6140 * @widget: a #GtkWidget
6141 * @is_primary: if the cursor should be the primary cursor color.
6143 * Get a GC suitable for drawing the primary or secondary text
6146 * Note: the return value is ref'ed because calls to this function
6147 * on other widgets could result in this the GC being released
6148 * which would be an unexpected side effect. If made public,
6149 * this function should possibly be called create_insertion_cursor_gc().
6151 * Return value: an appropriate #GdkGC. Call g_object_unref() on
6152 * the gc when you are done with it; this GC may be shared with
6153 * other users, so you must not modify the GC except for temporarily
6154 * setting the clip before drawing with the GC, and then unsetting the clip
6158 _gtk_get_insertion_cursor_gc (GtkWidget *widget,
6159 gboolean is_primary)
6161 CursorInfo *cursor_info;
6163 cursor_info = g_object_get_data (G_OBJECT (widget->style), "gtk-style-cursor-info");
6166 cursor_info = g_new (CursorInfo, 1);
6167 g_object_set_data (G_OBJECT (widget->style), "gtk-style-cursor-info", cursor_info);
6168 cursor_info->primary_gc = NULL;
6169 cursor_info->secondary_gc = NULL;
6170 cursor_info->for_type = G_TYPE_INVALID;
6173 /* We have to keep track of the type because gtk_widget_style_get()
6174 * can return different results when called on the same property and
6175 * same style but for different widgets. :-(. That is,
6176 * GtkEntry::cursor-color = "red" in a style will modify the cursor
6177 * color for entries but not for text view.
6179 if (cursor_info->for_type != G_OBJECT_TYPE (widget))
6181 cursor_info->for_type = G_OBJECT_TYPE (widget);
6182 if (cursor_info->primary_gc)
6184 gtk_gc_release (cursor_info->primary_gc);
6185 cursor_info->primary_gc = NULL;
6187 if (cursor_info->secondary_gc)
6189 gtk_gc_release (cursor_info->secondary_gc);
6190 cursor_info->secondary_gc = NULL;
6196 if (!cursor_info->primary_gc)
6197 cursor_info->primary_gc = make_cursor_gc (widget,
6199 &widget->style->black);
6201 return g_object_ref (cursor_info->primary_gc);
6205 static GdkColor gray = { 0, 0x8888, 0x8888, 0x8888 };
6207 if (!cursor_info->secondary_gc)
6208 cursor_info->secondary_gc = make_cursor_gc (widget,
6209 "secondary-cursor-color",
6212 return g_object_ref (cursor_info->secondary_gc);
6217 * _gtk_draw_insertion_cursor:
6218 * @widget: a #GtkWidget
6219 * @drawable: a #GdkDrawable
6221 * @location: location where to draw the cursor (@location->width is ignored)
6222 * @direction: whether the cursor is left-to-right or
6223 * right-to-left. Should never be #GTK_TEXT_DIR_NONE
6224 * @draw_arrow: %TRUE to draw a directional arrow on the
6225 * cursor. Should be %FALSE unless the cursor is split.
6227 * Draws a text caret on @drawable at @location. This is not a style function
6228 * but merely a convenience function for drawing the standard cursor shape.
6231 _gtk_draw_insertion_cursor (GtkWidget *widget,
6232 GdkDrawable *drawable,
6234 GdkRectangle *location,
6235 GtkTextDirection direction,
6236 gboolean draw_arrow)
6242 gfloat cursor_aspect_ratio;
6245 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
6247 gtk_widget_style_get (widget, "cursor-aspect-ratio", &cursor_aspect_ratio, NULL);
6249 stem_width = location->height * cursor_aspect_ratio + 1;
6250 arrow_width = stem_width + 1;
6252 /* put (stem_width % 2) on the proper side of the cursor */
6253 if (direction == GTK_TEXT_DIR_LTR)
6254 offset = stem_width / 2;
6256 offset = stem_width - stem_width / 2;
6258 for (i = 0; i < stem_width; i++)
6259 gdk_draw_line (drawable, gc,
6260 location->x + i - offset, location->y,
6261 location->x + i - offset, location->y + location->height - 1);
6265 if (direction == GTK_TEXT_DIR_RTL)
6267 x = location->x - offset - 1;
6268 y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
6270 for (i = 0; i < arrow_width; i++)
6272 gdk_draw_line (drawable, gc,
6274 x, y + 2 * arrow_width - i - 1);
6278 else if (direction == GTK_TEXT_DIR_LTR)
6280 x = location->x + stem_width - offset;
6281 y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
6283 for (i = 0; i < arrow_width; i++)
6285 gdk_draw_line (drawable, gc,
6287 x, y + 2 * arrow_width - i - 1);