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, 0xd6d6, 0xd6d6, 0xd6d6 };
456 static GdkColor gtk_default_active_bg = { 0, 0xc350, 0xc350, 0xc350 };
457 static GdkColor gtk_default_prelight_bg = { 0, 0xea60, 0xea60, 0xea60 };
458 static GdkColor gtk_default_selected_bg = { 0, 0, 0, 0x9c40 };
459 static GdkColor gtk_default_insensitive_bg = { 0, 0xd6d6, 0xd6d6, 0xd6d6 };
460 static GdkColor gtk_default_selected_base = { 0, 0xa4a4, 0xdfdf, 0xffff };
461 static GdkColor gtk_default_active_base = { 0, 0xbcbc, 0xd2d2, 0xeeee };
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->black;
577 style->base[GTK_STATE_ACTIVE] = gtk_default_active_base;
578 style->text[GTK_STATE_ACTIVE] = style->black;
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);
2290 * See http://bugzilla.gnome.org/show_bug.cgi?id=80229
2293 draw_spin_entry_shadow (GtkStyle *style,
2302 gint window_width, window_height;
2303 gboolean focus_inset;
2305 gdk_drawable_get_size (window, &window_width, &window_height);
2308 width = window_width;
2310 height = window_height;
2312 focus_inset = (width < window_width && height < window_height);
2316 gdk_gc_set_clip_rectangle (style->light_gc[state], area);
2317 gdk_gc_set_clip_rectangle (style->dark_gc[state], area);
2318 gdk_gc_set_clip_rectangle (style->black_gc, area);
2319 gdk_gc_set_clip_rectangle (style->bg_gc[state], area);
2320 gdk_gc_set_clip_rectangle (style->base_gc[state], area);
2323 gdk_draw_line (window, style->light_gc[state],
2324 x, y + height - 1, x + width - 1, y + height - 1);
2326 gdk_draw_line (window,
2327 style->base_gc[state],
2328 x + width - 1, y + 1, x + width - 1, y + height - 3);
2332 gdk_draw_line (window, style->bg_gc[state],
2333 x + 1, y + height - 2, x + width - 1, y + height - 2);
2334 gdk_draw_line (window,
2335 style->base_gc[state],
2336 x + width - 2, y + 1, x + width - 2, y + height - 3);
2338 gdk_draw_line (window, style->black_gc,
2339 x + 1, y + 1, x + width - 1, y + 1);
2340 gdk_draw_line (window, style->black_gc,
2341 x + 1, y + 1, x + 1, y + height - 2);
2344 gdk_draw_line (window, style->dark_gc[state],
2345 x, y, x + width - 1, y);
2346 gdk_draw_line (window, style->dark_gc[state],
2347 x, y, x, y + height - 1);
2351 gdk_gc_set_clip_rectangle (style->light_gc[state], NULL);
2352 gdk_gc_set_clip_rectangle (style->dark_gc[state], NULL);
2353 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2354 gdk_gc_set_clip_rectangle (style->bg_gc[state], NULL);
2355 gdk_gc_set_clip_rectangle (style->base_gc[state], NULL);
2361 draw_spinbutton_shadow (GtkStyle *style,
2364 GtkTextDirection direction,
2371 sanitize_size (window, &width, &height);
2375 gdk_gc_set_clip_rectangle (style->black_gc, area);
2376 gdk_gc_set_clip_rectangle (style->bg_gc[state], area);
2377 gdk_gc_set_clip_rectangle (style->dark_gc[state], area);
2378 gdk_gc_set_clip_rectangle (style->light_gc[state], area);
2381 if (direction == GTK_TEXT_DIR_LTR)
2383 gdk_draw_line (window, style->dark_gc[state],
2384 x, y, x + width - 1, y);
2385 gdk_draw_line (window, style->black_gc,
2386 x, y + 1, x + width - 2, y + 1);
2387 gdk_draw_line (window, style->black_gc,
2388 x + width - 2, y + 2, x + width - 2, y + height - 3);
2389 gdk_draw_line (window, style->light_gc[state],
2390 x + width - 1, y + 1, x + width - 1, y + height - 2);
2391 gdk_draw_line (window, style->light_gc[state],
2392 x, y + height - 1, x + width - 1, y + height - 1);
2393 gdk_draw_line (window, style->bg_gc[state],
2394 x, y + height - 2, x + width - 2, y + height - 2);
2395 gdk_draw_line (window, style->black_gc,
2396 x, y + 2, x, y + height - 3);
2400 gdk_draw_line (window, style->dark_gc[state],
2401 x, y, x + width - 1, y);
2402 gdk_draw_line (window, style->dark_gc[state],
2403 x, y + 1, x, y + height - 1);
2404 gdk_draw_line (window, style->black_gc,
2405 x + 1, y + 1, x + width - 1, y + 1);
2406 gdk_draw_line (window, style->black_gc,
2407 x + 1, y + 2, x + 1, y + height - 2);
2408 gdk_draw_line (window, style->black_gc,
2409 x + width - 1, y + 2, x + width - 1, y + height - 3);
2410 gdk_draw_line (window, style->light_gc[state],
2411 x + 1, y + height - 1, x + width - 1, y + height - 1);
2412 gdk_draw_line (window, style->bg_gc[state],
2413 x + 2, y + height - 2, x + width - 1, y + height - 2);
2418 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2419 gdk_gc_set_clip_rectangle (style->bg_gc[state], NULL);
2420 gdk_gc_set_clip_rectangle (style->dark_gc[state], NULL);
2421 gdk_gc_set_clip_rectangle (style->light_gc[state], NULL);
2426 gtk_default_draw_shadow (GtkStyle *style,
2428 GtkStateType state_type,
2429 GtkShadowType shadow_type,
2432 const gchar *detail,
2440 gint thickness_light;
2441 gint thickness_dark;
2444 g_return_if_fail (GTK_IS_STYLE (style));
2445 g_return_if_fail (window != NULL);
2447 if (shadow_type == GTK_SHADOW_IN)
2449 if (detail && (strcmp (detail, "buttondefault") == 0))
2451 sanitize_size (window, &width, &height);
2453 gdk_draw_rectangle (window, style->black_gc, FALSE,
2454 x, y, width - 1, height - 1);
2458 if (detail && strcmp (detail, "trough") == 0)
2460 draw_thin_shadow (style, window, state_type, area,
2461 x, y, width, height);
2464 if (widget && GTK_IS_SPIN_BUTTON (widget) &&
2465 detail && strcmp (detail, "spinbutton") == 0)
2467 draw_spinbutton_shadow (style, window, state_type,
2468 gtk_widget_get_direction (widget), area, x, y, width, height);
2474 sanitize_size (window, &width, &height);
2476 switch (shadow_type)
2478 case GTK_SHADOW_NONE:
2481 case GTK_SHADOW_ETCHED_IN:
2482 gc1 = style->light_gc[state_type];
2483 gc2 = style->dark_gc[state_type];
2485 case GTK_SHADOW_OUT:
2486 case GTK_SHADOW_ETCHED_OUT:
2487 gc1 = style->dark_gc[state_type];
2488 gc2 = style->light_gc[state_type];
2494 gdk_gc_set_clip_rectangle (gc1, area);
2495 gdk_gc_set_clip_rectangle (gc2, area);
2496 if (shadow_type == GTK_SHADOW_IN ||
2497 shadow_type == GTK_SHADOW_OUT)
2499 gdk_gc_set_clip_rectangle (style->black_gc, area);
2500 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2504 switch (shadow_type)
2506 case GTK_SHADOW_NONE:
2510 /* Light around right and bottom edge */
2512 if (style->ythickness > 0)
2513 gdk_draw_line (window, gc1,
2514 x, y + height - 1, x + width - 1, y + height - 1);
2515 if (style->xthickness > 0)
2516 gdk_draw_line (window, gc1,
2517 x + width - 1, y, x + width - 1, y + height - 1);
2519 if (style->ythickness > 1)
2520 gdk_draw_line (window, style->bg_gc[state_type],
2521 x + 1, y + height - 2, x + width - 2, y + height - 2);
2522 if (style->xthickness > 1)
2523 gdk_draw_line (window, style->bg_gc[state_type],
2524 x + width - 2, y + 1, x + width - 2, y + height - 2);
2526 /* Dark around left and top */
2528 if (style->ythickness > 1)
2529 gdk_draw_line (window, style->black_gc,
2530 x + 1, y + 1, x + width - 2, y + 1);
2531 if (style->xthickness > 1)
2532 gdk_draw_line (window, style->black_gc,
2533 x + 1, y + 1, x + 1, y + height - 2);
2535 if (style->ythickness > 0)
2536 gdk_draw_line (window, gc2,
2537 x, y, x + width - 1, y);
2538 if (style->xthickness > 0)
2539 gdk_draw_line (window, gc2,
2540 x, y, x, y + height - 1);
2543 case GTK_SHADOW_OUT:
2544 /* Dark around right and bottom edge */
2546 if (style->ythickness > 0)
2548 if (style->ythickness > 1)
2550 gdk_draw_line (window, gc1,
2551 x + 1, y + height - 2, x + width - 2, y + height - 2);
2552 gdk_draw_line (window, style->black_gc,
2553 x, y + height - 1, x + width - 1, y + height - 1);
2557 gdk_draw_line (window, gc1,
2558 x + 1, y + height - 1, x + width - 1, y + height - 1);
2562 if (style->xthickness > 0)
2564 if (style->xthickness > 1)
2566 gdk_draw_line (window, gc1,
2567 x + width - 2, y + 1, x + width - 2, y + height - 2);
2569 gdk_draw_line (window, style->black_gc,
2570 x + width - 1, y, x + width - 1, y + height - 1);
2574 gdk_draw_line (window, gc1,
2575 x + width - 1, y + 1, x + width - 1, y + height - 1);
2579 /* Light around top and left */
2581 if (style->ythickness > 0)
2582 gdk_draw_line (window, gc2,
2583 x, y, x + width - 2, y);
2584 if (style->xthickness > 0)
2585 gdk_draw_line (window, gc2,
2586 x, y, x, y + height - 2);
2588 if (style->ythickness > 1)
2589 gdk_draw_line (window, style->bg_gc[state_type],
2590 x + 1, y + 1, x + width - 3, y + 1);
2591 if (style->xthickness > 1)
2592 gdk_draw_line (window, style->bg_gc[state_type],
2593 x + 1, y + 1, x + 1, y + height - 3);
2596 case GTK_SHADOW_ETCHED_IN:
2597 case GTK_SHADOW_ETCHED_OUT:
2598 if (style->xthickness > 0)
2600 if (style->xthickness > 1)
2602 thickness_light = 1;
2605 for (i = 0; i < thickness_dark; i++)
2607 gdk_draw_line (window, gc1,
2611 y + height - i - 1);
2612 gdk_draw_line (window, gc2,
2616 y + height - i - 2);
2619 for (i = 0; i < thickness_light; i++)
2621 gdk_draw_line (window, gc1,
2622 x + thickness_dark + i,
2623 y + thickness_dark + i,
2624 x + thickness_dark + i,
2625 y + height - thickness_dark - i - 1);
2626 gdk_draw_line (window, gc2,
2627 x + width - thickness_light - i - 1,
2628 y + thickness_dark + i,
2629 x + width - thickness_light - i - 1,
2630 y + height - thickness_light - 1);
2635 gdk_draw_line (window,
2636 style->dark_gc[state_type],
2637 x, y, x, y + height);
2638 gdk_draw_line (window,
2639 style->dark_gc[state_type],
2640 x + width, y, x + width, y + height);
2644 if (style->ythickness > 0)
2646 if (style->ythickness > 1)
2648 thickness_light = 1;
2651 for (i = 0; i < thickness_dark; i++)
2653 gdk_draw_line (window, gc1,
2657 y + height - i - 1);
2659 gdk_draw_line (window, gc2,
2666 for (i = 0; i < thickness_light; i++)
2668 gdk_draw_line (window, gc1,
2669 x + thickness_dark + i,
2670 y + thickness_dark + i,
2671 x + width - thickness_dark - i - 2,
2672 y + thickness_dark + i);
2674 gdk_draw_line (window, gc2,
2675 x + thickness_dark + i,
2676 y + height - thickness_light - i - 1,
2677 x + width - thickness_light - 1,
2678 y + height - thickness_light - i - 1);
2683 gdk_draw_line (window,
2684 style->dark_gc[state_type],
2685 x, y, x + width, y);
2686 gdk_draw_line (window,
2687 style->dark_gc[state_type],
2688 x, y + height, x + width, y + height);
2695 if (shadow_type == GTK_SHADOW_IN &&
2696 widget && GTK_IS_SPIN_BUTTON (widget) &&
2697 detail && strcmp (detail, "entry") == 0)
2699 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
2701 gdk_draw_line (window,
2702 style->base_gc[state_type],
2703 x + width - 1, y + 2,
2704 x + width - 1, y + height - 3);
2705 gdk_draw_line (window,
2706 style->base_gc[state_type],
2707 x + width - 2, y + 2,
2708 x + width - 2, y + height - 3);
2709 gdk_draw_point (window,
2711 x + width - 1, y + 1);
2712 gdk_draw_point (window,
2713 style->bg_gc[state_type],
2714 x + width - 1, y + height - 2);
2718 gdk_draw_line (window,
2719 style->base_gc[state_type],
2722 gdk_draw_line (window,
2723 style->base_gc[state_type],
2725 x + 1, y + height - 3);
2726 gdk_draw_point (window,
2729 gdk_draw_line (window,
2730 style->bg_gc[state_type],
2732 x + 1, y + height - 2);
2733 gdk_draw_point (window,
2734 style->light_gc[state_type],
2742 gdk_gc_set_clip_rectangle (gc1, NULL);
2743 gdk_gc_set_clip_rectangle (gc2, NULL);
2744 if (shadow_type == GTK_SHADOW_IN ||
2745 shadow_type == GTK_SHADOW_OUT)
2747 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2748 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2754 gtk_default_draw_polygon (GtkStyle *style,
2756 GtkStateType state_type,
2757 GtkShadowType shadow_type,
2760 const gchar *detail,
2765 static const gdouble pi_over_4 = G_PI_4;
2766 static const gdouble pi_3_over_4 = G_PI_4 * 3;
2776 g_return_if_fail (GTK_IS_STYLE (style));
2777 g_return_if_fail (window != NULL);
2778 g_return_if_fail (points != NULL);
2780 switch (shadow_type)
2783 gc1 = style->bg_gc[state_type];
2784 gc2 = style->dark_gc[state_type];
2785 gc3 = style->light_gc[state_type];
2786 gc4 = style->black_gc;
2788 case GTK_SHADOW_ETCHED_IN:
2789 gc1 = style->light_gc[state_type];
2790 gc2 = style->dark_gc[state_type];
2791 gc3 = style->dark_gc[state_type];
2792 gc4 = style->light_gc[state_type];
2794 case GTK_SHADOW_OUT:
2795 gc1 = style->dark_gc[state_type];
2796 gc2 = style->light_gc[state_type];
2797 gc3 = style->black_gc;
2798 gc4 = style->bg_gc[state_type];
2800 case GTK_SHADOW_ETCHED_OUT:
2801 gc1 = style->dark_gc[state_type];
2802 gc2 = style->light_gc[state_type];
2803 gc3 = style->light_gc[state_type];
2804 gc4 = style->dark_gc[state_type];
2812 gdk_gc_set_clip_rectangle (gc1, area);
2813 gdk_gc_set_clip_rectangle (gc2, area);
2814 gdk_gc_set_clip_rectangle (gc3, area);
2815 gdk_gc_set_clip_rectangle (gc4, area);
2819 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, npoints);
2823 for (i = 0; i < npoints; i++)
2825 if ((points[i].x == points[i+1].x) &&
2826 (points[i].y == points[i+1].y))
2832 angle = atan2 (points[i+1].y - points[i].y,
2833 points[i+1].x - points[i].x);
2836 if ((angle > -pi_3_over_4) && (angle < pi_over_4))
2838 if (angle > -pi_over_4)
2849 gdk_draw_line (window, gc1,
2850 points[i].x-xadjust, points[i].y-yadjust,
2851 points[i+1].x-xadjust, points[i+1].y-yadjust);
2852 gdk_draw_line (window, gc3,
2853 points[i].x, points[i].y,
2854 points[i+1].x, points[i+1].y);
2858 if ((angle < -pi_3_over_4) || (angle > pi_3_over_4))
2869 gdk_draw_line (window, gc4,
2870 points[i].x+xadjust, points[i].y+yadjust,
2871 points[i+1].x+xadjust, points[i+1].y+yadjust);
2872 gdk_draw_line (window, gc2,
2873 points[i].x, points[i].y,
2874 points[i+1].x, points[i+1].y);
2880 gdk_gc_set_clip_rectangle (gc1, NULL);
2881 gdk_gc_set_clip_rectangle (gc2, NULL);
2882 gdk_gc_set_clip_rectangle (gc3, NULL);
2883 gdk_gc_set_clip_rectangle (gc4, NULL);
2888 draw_arrow (GdkWindow *window,
2891 GtkArrowType arrow_type,
2900 gdk_gc_set_clip_rectangle (gc, area);
2902 if (arrow_type == GTK_ARROW_DOWN)
2904 for (i = 0, j = 0; i < height; i++, j++)
2905 gdk_draw_line (window, gc, x + j, y + i, x + width - j - 1, y + i);
2907 else if (arrow_type == GTK_ARROW_UP)
2909 for (i = height - 1, j = 0; i >= 0; i--, j++)
2910 gdk_draw_line (window, gc, x + j, y + i, x + width - j - 1, y + i);
2912 else if (arrow_type == GTK_ARROW_LEFT)
2914 for (i = width - 1, j = 0; i >= 0; i--, j++)
2915 gdk_draw_line (window, gc, x + i, y + j, x + i, y + height - j - 1);
2917 else if (arrow_type == GTK_ARROW_RIGHT)
2919 for (i = 0, j = 0; i < width; i++, j++)
2920 gdk_draw_line (window, gc, x + i, y + j, x + i, y + height - j - 1);
2924 gdk_gc_set_clip_rectangle (gc, NULL);
2928 calculate_arrow_geometry (GtkArrowType arrow_type,
2940 case GTK_ARROW_DOWN:
2950 if (arrow_type == GTK_ARROW_DOWN)
2952 if (*height % 2 == 1 || h % 2 == 0)
2957 if (*height % 2 == 0 || h % 2 == 0)
2962 case GTK_ARROW_RIGHT:
2963 case GTK_ARROW_LEFT:
2973 if (arrow_type == GTK_ARROW_RIGHT)
2975 if (*width % 2 == 1 || w % 2 == 0)
2980 if (*width % 2 == 0 || w % 2 == 0)
2986 /* should not be reached */
2990 *x += (*width - w) / 2;
2991 *y += (*height - h) / 2;
2997 gtk_default_draw_arrow (GtkStyle *style,
3000 GtkShadowType shadow,
3003 const gchar *detail,
3004 GtkArrowType arrow_type,
3011 gint original_width, original_x;
3013 sanitize_size (window, &width, &height);
3015 original_width = width;
3018 calculate_arrow_geometry (arrow_type, &x, &y, &width, &height);
3020 if (detail && strcmp (detail, "menuitem") == 0
3021 && gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
3022 x = original_x + original_width - width;
3024 if (state == GTK_STATE_INSENSITIVE)
3025 draw_arrow (window, style->white_gc, area, arrow_type,
3026 x + 1, y + 1, width, height);
3027 draw_arrow (window, style->fg_gc[state], area, arrow_type,
3028 x, y, width, height);
3032 gtk_default_draw_diamond (GtkStyle *style,
3034 GtkStateType state_type,
3035 GtkShadowType shadow_type,
3038 const gchar *detail,
3046 GdkGC *outer_nw = NULL;
3047 GdkGC *outer_ne = NULL;
3048 GdkGC *outer_sw = NULL;
3049 GdkGC *outer_se = NULL;
3050 GdkGC *middle_nw = NULL;
3051 GdkGC *middle_ne = NULL;
3052 GdkGC *middle_sw = NULL;
3053 GdkGC *middle_se = NULL;
3054 GdkGC *inner_nw = NULL;
3055 GdkGC *inner_ne = NULL;
3056 GdkGC *inner_sw = NULL;
3057 GdkGC *inner_se = NULL;
3059 g_return_if_fail (GTK_IS_STYLE (style));
3060 g_return_if_fail (window != NULL);
3062 sanitize_size (window, &width, &height);
3064 half_width = width / 2;
3065 half_height = height / 2;
3069 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
3070 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
3071 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
3072 gdk_gc_set_clip_rectangle (style->black_gc, area);
3075 switch (shadow_type)
3078 inner_sw = inner_se = style->bg_gc[state_type];
3079 middle_sw = middle_se = style->light_gc[state_type];
3080 outer_sw = outer_se = style->light_gc[state_type];
3081 inner_nw = inner_ne = style->black_gc;
3082 middle_nw = middle_ne = style->dark_gc[state_type];
3083 outer_nw = outer_ne = style->dark_gc[state_type];
3086 case GTK_SHADOW_OUT:
3087 inner_sw = inner_se = style->dark_gc[state_type];
3088 middle_sw = middle_se = style->dark_gc[state_type];
3089 outer_sw = outer_se = style->black_gc;
3090 inner_nw = inner_ne = style->bg_gc[state_type];
3091 middle_nw = middle_ne = style->light_gc[state_type];
3092 outer_nw = outer_ne = style->light_gc[state_type];
3095 case GTK_SHADOW_ETCHED_IN:
3096 inner_sw = inner_se = style->bg_gc[state_type];
3097 middle_sw = middle_se = style->dark_gc[state_type];
3098 outer_sw = outer_se = style->light_gc[state_type];
3099 inner_nw = inner_ne = style->bg_gc[state_type];
3100 middle_nw = middle_ne = style->light_gc[state_type];
3101 outer_nw = outer_ne = style->dark_gc[state_type];
3104 case GTK_SHADOW_ETCHED_OUT:
3105 inner_sw = inner_se = style->bg_gc[state_type];
3106 middle_sw = middle_se = style->light_gc[state_type];
3107 outer_sw = outer_se = style->dark_gc[state_type];
3108 inner_nw = inner_ne = style->bg_gc[state_type];
3109 middle_nw = middle_ne = style->dark_gc[state_type];
3110 outer_nw = outer_ne = style->light_gc[state_type];
3120 gdk_draw_line (window, inner_sw,
3121 x + 2, y + half_height,
3122 x + half_width, y + height - 2);
3123 gdk_draw_line (window, inner_se,
3124 x + half_width, y + height - 2,
3125 x + width - 2, y + half_height);
3126 gdk_draw_line (window, middle_sw,
3127 x + 1, y + half_height,
3128 x + half_width, y + height - 1);
3129 gdk_draw_line (window, middle_se,
3130 x + half_width, y + height - 1,
3131 x + width - 1, y + half_height);
3132 gdk_draw_line (window, outer_sw,
3134 x + half_width, y + height);
3135 gdk_draw_line (window, outer_se,
3136 x + half_width, y + height,
3137 x + width, y + half_height);
3139 gdk_draw_line (window, inner_nw,
3140 x + 2, y + half_height,
3141 x + half_width, y + 2);
3142 gdk_draw_line (window, inner_ne,
3143 x + half_width, y + 2,
3144 x + width - 2, y + half_height);
3145 gdk_draw_line (window, middle_nw,
3146 x + 1, y + half_height,
3147 x + half_width, y + 1);
3148 gdk_draw_line (window, middle_ne,
3149 x + half_width, y + 1,
3150 x + width - 1, y + half_height);
3151 gdk_draw_line (window, outer_nw,
3154 gdk_draw_line (window, outer_ne,
3156 x + width, y + half_height);
3161 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
3162 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
3163 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
3164 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
3169 gtk_default_draw_string (GtkStyle *style,
3171 GtkStateType state_type,
3174 const gchar *detail,
3177 const gchar *string)
3179 GdkDisplay *display;
3181 g_return_if_fail (GTK_IS_STYLE (style));
3182 g_return_if_fail (window != NULL);
3184 display = gdk_drawable_get_display (window);
3188 gdk_gc_set_clip_rectangle (style->white_gc, area);
3189 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], area);
3192 if (state_type == GTK_STATE_INSENSITIVE)
3193 gdk_draw_string (window,
3194 gtk_style_get_font_internal (style),
3195 style->white_gc, x + 1, y + 1, string);
3197 gdk_draw_string (window,
3198 gtk_style_get_font_internal (style),
3199 style->fg_gc[state_type], x, y, string);
3203 gdk_gc_set_clip_rectangle (style->white_gc, NULL);
3204 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], NULL);
3209 option_menu_get_props (GtkWidget *widget,
3210 GtkRequisition *indicator_size,
3211 GtkBorder *indicator_spacing)
3213 GtkRequisition *tmp_size = NULL;
3214 GtkBorder *tmp_spacing = NULL;
3217 gtk_widget_style_get (widget,
3218 "indicator_size", &tmp_size,
3219 "indicator_spacing", &tmp_spacing,
3224 *indicator_size = *tmp_size;
3228 *indicator_size = default_option_indicator_size;
3232 *indicator_spacing = *tmp_spacing;
3233 g_free (tmp_spacing);
3236 *indicator_spacing = default_option_indicator_spacing;
3240 gtk_default_draw_box (GtkStyle *style,
3242 GtkStateType state_type,
3243 GtkShadowType shadow_type,
3246 const gchar *detail,
3252 gboolean is_spinbutton_box = FALSE;
3254 g_return_if_fail (GTK_IS_STYLE (style));
3255 g_return_if_fail (window != NULL);
3257 sanitize_size (window, &width, &height);
3259 if (widget && GTK_IS_SPIN_BUTTON (widget) && detail)
3261 if (strcmp (detail, "spinbutton_up") == 0)
3267 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3272 is_spinbutton_box = TRUE;
3274 else if (strcmp (detail, "spinbutton_down") == 0)
3279 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3284 is_spinbutton_box = TRUE;
3288 if (!style->bg_pixmap[state_type] ||
3289 GDK_IS_PIXMAP (window))
3292 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
3294 gdk_draw_rectangle (window, style->bg_gc[state_type], TRUE,
3295 x, y, width, height);
3297 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
3300 gtk_style_apply_default_background (style, window,
3301 widget && !GTK_WIDGET_NO_WINDOW (widget),
3302 state_type, area, x, y, width, height);
3304 if (is_spinbutton_box)
3309 lower_gc = style->dark_gc[state_type];
3310 if (shadow_type == GTK_SHADOW_OUT)
3311 upper_gc = style->light_gc[state_type];
3313 upper_gc = style->dark_gc[state_type];
3317 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
3318 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
3321 gdk_draw_line (window, upper_gc, x, y, x + width - 1, y);
3322 gdk_draw_line (window, lower_gc, x, y + height - 1, x + width - 1, y + height - 1);
3326 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
3327 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
3332 gtk_paint_shadow (style, window, state_type, shadow_type, area, widget, detail,
3333 x, y, width, height);
3335 if (detail && strcmp (detail, "optionmenu") == 0)
3337 GtkRequisition indicator_size;
3338 GtkBorder indicator_spacing;
3341 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
3343 sanitize_size (window, &width, &height);
3345 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3346 vline_x = x + indicator_size.width + indicator_spacing.left + indicator_spacing.right;
3348 vline_x = x + width - (indicator_size.width + indicator_spacing.left + indicator_spacing.right) - style->xthickness;
3350 gtk_paint_vline (style, window, state_type, area, widget,
3352 y + style->ythickness + 1,
3353 y + height - style->ythickness - 3,
3359 get_darkened_gc (GdkWindow *window,
3363 GdkColor src = *color;
3364 GdkColor shaded = *color;
3367 gc = gdk_gc_new (window);
3369 while (darken_count)
3371 gtk_style_shade (&src, &shaded, 0.93);
3376 gdk_gc_set_rgb_fg_color (gc, &shaded);
3382 gtk_default_draw_flat_box (GtkStyle *style,
3384 GtkStateType state_type,
3385 GtkShadowType shadow_type,
3388 const gchar *detail,
3395 GdkGC *freeme = NULL;
3397 g_return_if_fail (GTK_IS_STYLE (style));
3398 g_return_if_fail (window != NULL);
3400 sanitize_size (window, &width, &height);
3404 if (state_type == GTK_STATE_SELECTED)
3406 if (!strcmp ("text", detail))
3407 gc1 = style->bg_gc[GTK_STATE_SELECTED];
3408 else if (!strncmp ("cell_even", detail, strlen ("cell_even")) ||
3409 !strncmp ("cell_odd", detail, strlen ("cell_odd")))
3411 /* This has to be really broken; alex made me do it. -jrb */
3412 if (GTK_WIDGET_HAS_FOCUS (widget))
3413 gc1 = style->base_gc[state_type];
3415 gc1 = style->base_gc[GTK_STATE_ACTIVE];
3419 gc1 = style->bg_gc[state_type];
3424 if (!strcmp ("viewportbin", detail))
3425 gc1 = style->bg_gc[GTK_STATE_NORMAL];
3426 else if (!strcmp ("entry_bg", detail))
3427 gc1 = style->base_gc[state_type];
3429 /* For trees: even rows are base color, odd rows are a shade of
3430 * the base color, the sort column is a shade of the original color
3434 else if (!strcmp ("cell_even", detail) ||
3435 !strcmp ("cell_odd", detail) ||
3436 !strcmp ("cell_even_ruled", detail))
3438 GdkColor *color = NULL;
3440 gtk_widget_style_get (widget,
3441 "even_row_color", &color,
3446 freeme = get_darkened_gc (window, color, 0);
3449 gdk_color_free (color);
3452 gc1 = style->base_gc[state_type];
3454 else if (!strcmp ("cell_odd_ruled", detail))
3458 gtk_widget_style_get (widget,
3459 "odd_row_color", &color,
3464 freeme = get_darkened_gc (window, color, 0);
3467 gdk_color_free (color);
3471 gtk_widget_style_get (widget,
3472 "even_row_color", &color,
3477 freeme = get_darkened_gc (window, color, 1);
3478 gdk_color_free (color);
3481 freeme = get_darkened_gc (window, &style->base[state_type], 1);
3485 else if (!strcmp ("cell_even_sorted", detail) ||
3486 !strcmp ("cell_odd_sorted", detail) ||
3487 !strcmp ("cell_even_ruled_sorted", detail))
3489 GdkColor *color = NULL;
3491 if (!strcmp ("cell_odd_sorted", detail))
3492 gtk_widget_style_get (widget,
3493 "odd_row_color", &color,
3496 gtk_widget_style_get (widget,
3497 "even_row_color", &color,
3502 freeme = get_darkened_gc (window, color, 1);
3505 gdk_color_free (color);
3509 freeme = get_darkened_gc (window, &style->base[state_type], 1);
3513 else if (!strcmp ("cell_odd_ruled_sorted", detail))
3515 GdkColor *color = NULL;
3517 gtk_widget_style_get (widget,
3518 "odd_row_color", &color,
3523 freeme = get_darkened_gc (window, color, 1);
3526 gdk_color_free (color);
3530 gtk_widget_style_get (widget,
3531 "even_row_color", &color,
3536 freeme = get_darkened_gc (window, color, 2);
3537 gdk_color_free (color);
3540 freeme = get_darkened_gc (window, &style->base[state_type], 2);
3545 gc1 = style->bg_gc[state_type];
3549 gc1 = style->bg_gc[state_type];
3551 if (!style->bg_pixmap[state_type] || gc1 != style->bg_gc[state_type] ||
3552 GDK_IS_PIXMAP (window))
3555 gdk_gc_set_clip_rectangle (gc1, area);
3557 gdk_draw_rectangle (window, gc1, TRUE,
3558 x, y, width, height);
3560 if (detail && !strcmp ("tooltip", detail))
3561 gdk_draw_rectangle (window, style->black_gc, FALSE,
3562 x, y, width - 1, height - 1);
3565 gdk_gc_set_clip_rectangle (gc1, NULL);
3568 gtk_style_apply_default_background (style, window,
3569 widget && !GTK_WIDGET_NO_WINDOW (widget),
3570 state_type, area, x, y, width, height);
3574 g_object_unref (freeme);
3578 create_aa_gc (GdkWindow *window, GtkStyle *style, GtkStateType state_type)
3581 GdkGC *gc = gdk_gc_new (window);
3583 aa_color.red = (style->fg[state_type].red + style->bg[state_type].red) / 2;
3584 aa_color.green = (style->fg[state_type].green + style->bg[state_type].green) / 2;
3585 aa_color.blue = (style->fg[state_type].blue + style->bg[state_type].blue) / 2;
3587 gdk_gc_set_rgb_fg_color (gc, &aa_color);
3593 gtk_default_draw_check (GtkStyle *style,
3595 GtkStateType state_type,
3596 GtkShadowType shadow_type,
3599 const gchar *detail,
3605 if (detail && strcmp (detail, "cellcheck") == 0)
3607 gdk_draw_rectangle (window,
3608 widget->style->base_gc[state_type],
3612 gdk_draw_rectangle (window,
3613 widget->style->text_gc[state_type],
3618 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3619 y -= (((1 + INDICATOR_PART_SIZE - height) / 2) - 1);
3620 if (shadow_type == GTK_SHADOW_IN)
3622 draw_part (window, style->text_gc[state_type], area, x, y, CHECK_TEXT);
3623 draw_part (window, style->text_aa_gc[state_type], area, x, y, CHECK_AA);
3625 else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
3627 draw_part (window, style->text_gc[state_type], area, x, y, CHECK_INCONSISTENT_TEXT);
3632 GdkGC *free_me = NULL;
3638 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3639 y -= (1 + INDICATOR_PART_SIZE - height) / 2;
3641 if (strcmp (detail, "check") == 0) /* Menu item */
3643 text_gc = style->fg_gc[state_type];
3644 base_gc = style->bg_gc[state_type];
3645 aa_gc = free_me = create_aa_gc (window, style, state_type);
3649 if (state_type == GTK_STATE_ACTIVE)
3651 text_gc = style->fg_gc[state_type];
3652 base_gc = style->bg_gc[state_type];
3653 aa_gc = free_me = create_aa_gc (window, style, state_type);
3657 text_gc = style->text_gc[state_type];
3658 base_gc = style->base_gc[state_type];
3659 aa_gc = style->text_aa_gc[state_type];
3662 draw_part (window, base_gc, area, x, y, CHECK_BASE);
3663 draw_part (window, style->black_gc, area, x, y, CHECK_BLACK);
3664 draw_part (window, style->dark_gc[state_type], area, x, y, CHECK_DARK);
3665 draw_part (window, style->mid_gc[state_type], area, x, y, CHECK_MID);
3666 draw_part (window, style->light_gc[state_type], area, x, y, CHECK_LIGHT);
3669 if (shadow_type == GTK_SHADOW_IN)
3671 draw_part (window, text_gc, area, x, y, CHECK_TEXT);
3672 draw_part (window, aa_gc, area, x, y, CHECK_AA);
3674 else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
3676 draw_part (window, text_gc, area, x, y, CHECK_INCONSISTENT_TEXT);
3680 g_object_unref (G_OBJECT (free_me));
3685 gtk_default_draw_option (GtkStyle *style,
3687 GtkStateType state_type,
3688 GtkShadowType shadow_type,
3691 const gchar *detail,
3697 if (detail && strcmp (detail, "cellradio") == 0)
3699 gdk_draw_arc (window,
3700 widget->style->fg_gc[state_type],
3707 if (shadow_type == GTK_SHADOW_IN)
3709 gdk_draw_arc (window,
3710 widget->style->fg_gc[state_type],
3718 else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
3720 draw_part (window, widget->style->fg_gc[state_type],
3721 area, x, y, CHECK_INCONSISTENT_TEXT);
3726 GdkGC *free_me = NULL;
3732 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3733 y -= (1 + INDICATOR_PART_SIZE - height) / 2;
3735 if (strcmp (detail, "option") == 0) /* Menu item */
3737 text_gc = style->fg_gc[state_type];
3738 base_gc = style->bg_gc[state_type];
3739 aa_gc = free_me = create_aa_gc (window, style, state_type);
3743 if (state_type == GTK_STATE_ACTIVE)
3745 text_gc = style->fg_gc[state_type];
3746 base_gc = style->bg_gc[state_type];
3747 aa_gc = free_me = create_aa_gc (window, style, state_type);
3751 text_gc = style->text_gc[state_type];
3752 base_gc = style->base_gc[state_type];
3753 aa_gc = style->text_aa_gc[state_type];
3756 draw_part (window, base_gc, area, x, y, RADIO_BASE);
3757 draw_part (window, style->black_gc, area, x, y, RADIO_BLACK);
3758 draw_part (window, style->dark_gc[state_type], area, x, y, RADIO_DARK);
3759 draw_part (window, style->mid_gc[state_type], area, x, y, RADIO_MID);
3760 draw_part (window, style->light_gc[state_type], area, x, y, RADIO_LIGHT);
3763 if (shadow_type == GTK_SHADOW_IN)
3765 draw_part (window, text_gc, area, x, y, RADIO_TEXT);
3767 else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
3769 if (strcmp (detail, "option") == 0) /* Menu item */
3771 draw_part (window, text_gc, area, x, y, CHECK_INCONSISTENT_TEXT);
3775 draw_part (window, text_gc, area, x, y, RADIO_INCONSISTENT_TEXT);
3776 draw_part (window, aa_gc, area, x, y, RADIO_INCONSISTENT_AA);
3781 g_object_unref (G_OBJECT (free_me));
3786 gtk_default_draw_tab (GtkStyle *style,
3788 GtkStateType state_type,
3789 GtkShadowType shadow_type,
3792 const gchar *detail,
3798 #define ARROW_SPACE 4
3800 GtkRequisition indicator_size;
3801 GtkBorder indicator_spacing;
3804 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
3806 indicator_size.width += (indicator_size.width % 2) - 1;
3807 arrow_height = indicator_size.width / 2 + 1;
3809 x += (width - indicator_size.width) / 2;
3810 y += (height - (2 * arrow_height + ARROW_SPACE)) / 2;
3812 if (state_type == GTK_STATE_INSENSITIVE)
3814 draw_arrow (window, style->white_gc, area,
3815 GTK_ARROW_UP, x + 1, y + 1,
3816 indicator_size.width, arrow_height);
3818 draw_arrow (window, style->white_gc, area,
3819 GTK_ARROW_DOWN, x + 1, y + arrow_height + ARROW_SPACE + 1,
3820 indicator_size.width, arrow_height);
3823 draw_arrow (window, style->fg_gc[state_type], area,
3825 indicator_size.width, arrow_height);
3828 draw_arrow (window, style->fg_gc[state_type], area,
3829 GTK_ARROW_DOWN, x, y + arrow_height + ARROW_SPACE,
3830 indicator_size.width, arrow_height);
3834 gtk_default_draw_shadow_gap (GtkStyle *style,
3836 GtkStateType state_type,
3837 GtkShadowType shadow_type,
3840 const gchar *detail,
3845 GtkPositionType gap_side,
3854 g_return_if_fail (GTK_IS_STYLE (style));
3855 g_return_if_fail (window != NULL);
3857 sanitize_size (window, &width, &height);
3859 switch (shadow_type)
3861 case GTK_SHADOW_NONE:
3864 gc1 = style->dark_gc[state_type];
3865 gc2 = style->black_gc;
3866 gc3 = style->bg_gc[state_type];
3867 gc4 = style->light_gc[state_type];
3869 case GTK_SHADOW_ETCHED_IN:
3870 gc1 = style->dark_gc[state_type];
3871 gc2 = style->light_gc[state_type];
3872 gc3 = style->dark_gc[state_type];
3873 gc4 = style->light_gc[state_type];
3875 case GTK_SHADOW_OUT:
3876 gc1 = style->light_gc[state_type];
3877 gc2 = style->bg_gc[state_type];
3878 gc3 = style->dark_gc[state_type];
3879 gc4 = style->black_gc;
3881 case GTK_SHADOW_ETCHED_OUT:
3882 gc1 = style->light_gc[state_type];
3883 gc2 = style->dark_gc[state_type];
3884 gc3 = style->light_gc[state_type];
3885 gc4 = style->dark_gc[state_type];
3890 gdk_gc_set_clip_rectangle (gc1, area);
3891 gdk_gc_set_clip_rectangle (gc2, area);
3892 gdk_gc_set_clip_rectangle (gc3, area);
3893 gdk_gc_set_clip_rectangle (gc4, area);
3896 switch (shadow_type)
3898 case GTK_SHADOW_NONE:
3900 case GTK_SHADOW_OUT:
3901 case GTK_SHADOW_ETCHED_IN:
3902 case GTK_SHADOW_ETCHED_OUT:
3906 gdk_draw_line (window, gc1,
3907 x, y, x, y + height - 1);
3908 gdk_draw_line (window, gc2,
3909 x + 1, y, x + 1, y + height - 2);
3911 gdk_draw_line (window, gc3,
3912 x + 1, y + height - 2, x + width - 2, y + height - 2);
3913 gdk_draw_line (window, gc3,
3914 x + width - 2, y, x + width - 2, y + height - 2);
3915 gdk_draw_line (window, gc4,
3916 x, y + height - 1, x + width - 1, y + height - 1);
3917 gdk_draw_line (window, gc4,
3918 x + width - 1, y, x + width - 1, y + height - 1);
3921 gdk_draw_line (window, gc1,
3922 x, y, x + gap_x - 1, y);
3923 gdk_draw_line (window, gc2,
3924 x + 1, y + 1, x + gap_x - 1, y + 1);
3925 gdk_draw_line (window, gc2,
3926 x + gap_x, y, x + gap_x, y);
3928 if ((width - (gap_x + gap_width)) > 0)
3930 gdk_draw_line (window, gc1,
3931 x + gap_x + gap_width, y, x + width - 2, y);
3932 gdk_draw_line (window, gc2,
3933 x + gap_x + gap_width, y + 1, x + width - 3, y + 1);
3934 gdk_draw_line (window, gc2,
3935 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
3938 case GTK_POS_BOTTOM:
3939 gdk_draw_line (window, gc1,
3940 x, y, x + width - 1, y);
3941 gdk_draw_line (window, gc1,
3942 x, y, x, y + height - 1);
3943 gdk_draw_line (window, gc2,
3944 x + 1, y + 1, x + width - 2, y + 1);
3945 gdk_draw_line (window, gc2,
3946 x + 1, y + 1, x + 1, y + height - 1);
3948 gdk_draw_line (window, gc3,
3949 x + width - 2, y + 1, x + width - 2, y + height - 1);
3950 gdk_draw_line (window, gc4,
3951 x + width - 1, y, x + width - 1, y + height - 1);
3954 gdk_draw_line (window, gc4,
3955 x, y + height - 1, x + gap_x - 1, y + height - 1);
3956 gdk_draw_line (window, gc3,
3957 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
3958 gdk_draw_line (window, gc3,
3959 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
3961 if ((width - (gap_x + gap_width)) > 0)
3963 gdk_draw_line (window, gc4,
3964 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
3965 gdk_draw_line (window, gc3,
3966 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
3967 gdk_draw_line (window, gc3,
3968 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
3972 gdk_draw_line (window, gc1,
3973 x, y, x + width - 1, y);
3974 gdk_draw_line (window, gc2,
3975 x, y + 1, x + width - 2, y + 1);
3977 gdk_draw_line (window, gc3,
3978 x, y + height - 2, x + width - 2, y + height - 2);
3979 gdk_draw_line (window, gc3,
3980 x + width - 2, y + 1, x + width - 2, y + height - 2);
3981 gdk_draw_line (window, gc4,
3982 x, y + height - 1, x + width - 1, y + height - 1);
3983 gdk_draw_line (window, gc4,
3984 x + width - 1, y, x + width - 1, y + height - 1);
3987 gdk_draw_line (window, gc1,
3988 x, y, x, y + gap_x - 1);
3989 gdk_draw_line (window, gc2,
3990 x + 1, y + 1, x + 1, y + gap_x - 1);
3991 gdk_draw_line (window, gc2,
3992 x, y + gap_x, x, y + gap_x);
3994 if ((width - (gap_x + gap_width)) > 0)
3996 gdk_draw_line (window, gc1,
3997 x, y + gap_x + gap_width, x, y + height - 2);
3998 gdk_draw_line (window, gc2,
3999 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
4000 gdk_draw_line (window, gc2,
4001 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
4005 gdk_draw_line (window, gc1,
4006 x, y, x + width - 1, y);
4007 gdk_draw_line (window, gc1,
4008 x, y, x, y + height - 1);
4009 gdk_draw_line (window, gc2,
4010 x + 1, y + 1, x + width - 1, y + 1);
4011 gdk_draw_line (window, gc2,
4012 x + 1, y + 1, x + 1, y + height - 2);
4014 gdk_draw_line (window, gc3,
4015 x + 1, y + height - 2, x + width - 1, y + height - 2);
4016 gdk_draw_line (window, gc4,
4017 x, y + height - 1, x + width - 1, y + height - 1);
4020 gdk_draw_line (window, gc4,
4021 x + width - 1, y, x + width - 1, y + gap_x - 1);
4022 gdk_draw_line (window, gc3,
4023 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
4024 gdk_draw_line (window, gc3,
4025 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
4027 if ((width - (gap_x + gap_width)) > 0)
4029 gdk_draw_line (window, gc4,
4030 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
4031 gdk_draw_line (window, gc3,
4032 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
4033 gdk_draw_line (window, gc3,
4034 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
4042 gdk_gc_set_clip_rectangle (gc1, NULL);
4043 gdk_gc_set_clip_rectangle (gc2, NULL);
4044 gdk_gc_set_clip_rectangle (gc3, NULL);
4045 gdk_gc_set_clip_rectangle (gc4, NULL);
4050 gtk_default_draw_box_gap (GtkStyle *style,
4052 GtkStateType state_type,
4053 GtkShadowType shadow_type,
4056 const gchar *detail,
4061 GtkPositionType gap_side,
4070 g_return_if_fail (GTK_IS_STYLE (style));
4071 g_return_if_fail (window != NULL);
4073 gtk_style_apply_default_background (style, window,
4074 widget && !GTK_WIDGET_NO_WINDOW (widget),
4075 state_type, area, x, y, width, height);
4077 sanitize_size (window, &width, &height);
4079 switch (shadow_type)
4081 case GTK_SHADOW_NONE:
4084 gc1 = style->dark_gc[state_type];
4085 gc2 = style->black_gc;
4086 gc3 = style->bg_gc[state_type];
4087 gc4 = style->light_gc[state_type];
4089 case GTK_SHADOW_ETCHED_IN:
4090 gc1 = style->dark_gc[state_type];
4091 gc2 = style->light_gc[state_type];
4092 gc3 = style->dark_gc[state_type];
4093 gc4 = style->light_gc[state_type];
4095 case GTK_SHADOW_OUT:
4096 gc1 = style->light_gc[state_type];
4097 gc2 = style->bg_gc[state_type];
4098 gc3 = style->dark_gc[state_type];
4099 gc4 = style->black_gc;
4101 case GTK_SHADOW_ETCHED_OUT:
4102 gc1 = style->light_gc[state_type];
4103 gc2 = style->dark_gc[state_type];
4104 gc3 = style->light_gc[state_type];
4105 gc4 = style->dark_gc[state_type];
4111 gdk_gc_set_clip_rectangle (gc1, area);
4112 gdk_gc_set_clip_rectangle (gc2, area);
4113 gdk_gc_set_clip_rectangle (gc3, area);
4114 gdk_gc_set_clip_rectangle (gc4, area);
4117 switch (shadow_type)
4119 case GTK_SHADOW_NONE:
4121 case GTK_SHADOW_OUT:
4122 case GTK_SHADOW_ETCHED_IN:
4123 case GTK_SHADOW_ETCHED_OUT:
4127 gdk_draw_line (window, gc1,
4128 x, y, x, y + height - 1);
4129 gdk_draw_line (window, gc2,
4130 x + 1, y, x + 1, y + height - 2);
4132 gdk_draw_line (window, gc3,
4133 x + 1, y + height - 2, x + width - 2, y + height - 2);
4134 gdk_draw_line (window, gc3,
4135 x + width - 2, y, x + width - 2, y + height - 2);
4136 gdk_draw_line (window, gc4,
4137 x, y + height - 1, x + width - 1, y + height - 1);
4138 gdk_draw_line (window, gc4,
4139 x + width - 1, y, x + width - 1, y + height - 1);
4142 gdk_draw_line (window, gc1,
4143 x, y, x + gap_x - 1, y);
4144 gdk_draw_line (window, gc2,
4145 x + 1, y + 1, x + gap_x - 1, y + 1);
4146 gdk_draw_line (window, gc2,
4147 x + gap_x, y, x + gap_x, y);
4149 if ((width - (gap_x + gap_width)) > 0)
4151 gdk_draw_line (window, gc1,
4152 x + gap_x + gap_width, y, x + width - 2, y);
4153 gdk_draw_line (window, gc2,
4154 x + gap_x + gap_width, y + 1, x + width - 2, y + 1);
4155 gdk_draw_line (window, gc2,
4156 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
4159 case GTK_POS_BOTTOM:
4160 gdk_draw_line (window, gc1,
4161 x, y, x + width - 1, y);
4162 gdk_draw_line (window, gc1,
4163 x, y, x, y + height - 1);
4164 gdk_draw_line (window, gc2,
4165 x + 1, y + 1, x + width - 2, y + 1);
4166 gdk_draw_line (window, gc2,
4167 x + 1, y + 1, x + 1, y + height - 1);
4169 gdk_draw_line (window, gc3,
4170 x + width - 2, y + 1, x + width - 2, y + height - 1);
4171 gdk_draw_line (window, gc4,
4172 x + width - 1, y, x + width - 1, y + height - 1);
4175 gdk_draw_line (window, gc4,
4176 x, y + height - 1, x + gap_x - 1, y + height - 1);
4177 gdk_draw_line (window, gc3,
4178 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
4179 gdk_draw_line (window, gc3,
4180 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
4182 if ((width - (gap_x + gap_width)) > 0)
4184 gdk_draw_line (window, gc4,
4185 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
4186 gdk_draw_line (window, gc3,
4187 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
4188 gdk_draw_line (window, gc3,
4189 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
4193 gdk_draw_line (window, gc1,
4194 x, y, x + width - 1, y);
4195 gdk_draw_line (window, gc2,
4196 x, y + 1, x + width - 2, y + 1);
4198 gdk_draw_line (window, gc3,
4199 x, y + height - 2, x + width - 2, y + height - 2);
4200 gdk_draw_line (window, gc3,
4201 x + width - 2, y + 1, x + width - 2, y + height - 2);
4202 gdk_draw_line (window, gc4,
4203 x, y + height - 1, x + width - 1, y + height - 1);
4204 gdk_draw_line (window, gc4,
4205 x + width - 1, y, x + width - 1, y + height - 1);
4208 gdk_draw_line (window, gc1,
4209 x, y, x, y + gap_x - 1);
4210 gdk_draw_line (window, gc2,
4211 x + 1, y + 1, x + 1, y + gap_x - 1);
4212 gdk_draw_line (window, gc2,
4213 x, y + gap_x, x, y + gap_x);
4215 if ((width - (gap_x + gap_width)) > 0)
4217 gdk_draw_line (window, gc1,
4218 x, y + gap_x + gap_width, x, y + height - 2);
4219 gdk_draw_line (window, gc2,
4220 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
4221 gdk_draw_line (window, gc2,
4222 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
4226 gdk_draw_line (window, gc1,
4227 x, y, x + width - 1, y);
4228 gdk_draw_line (window, gc1,
4229 x, y, x, y + height - 1);
4230 gdk_draw_line (window, gc2,
4231 x + 1, y + 1, x + width - 1, y + 1);
4232 gdk_draw_line (window, gc2,
4233 x + 1, y + 1, x + 1, y + height - 2);
4235 gdk_draw_line (window, gc3,
4236 x + 1, y + height - 2, x + width - 1, y + height - 2);
4237 gdk_draw_line (window, gc4,
4238 x, y + height - 1, x + width - 1, y + height - 1);
4241 gdk_draw_line (window, gc4,
4242 x + width - 1, y, x + width - 1, y + gap_x - 1);
4243 gdk_draw_line (window, gc3,
4244 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
4245 gdk_draw_line (window, gc3,
4246 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
4248 if ((width - (gap_x + gap_width)) > 0)
4250 gdk_draw_line (window, gc4,
4251 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
4252 gdk_draw_line (window, gc3,
4253 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
4254 gdk_draw_line (window, gc3,
4255 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
4263 gdk_gc_set_clip_rectangle (gc1, NULL);
4264 gdk_gc_set_clip_rectangle (gc2, NULL);
4265 gdk_gc_set_clip_rectangle (gc3, NULL);
4266 gdk_gc_set_clip_rectangle (gc4, NULL);
4271 gtk_default_draw_extension (GtkStyle *style,
4273 GtkStateType state_type,
4274 GtkShadowType shadow_type,
4277 const gchar *detail,
4282 GtkPositionType gap_side)
4289 g_return_if_fail (GTK_IS_STYLE (style));
4290 g_return_if_fail (window != NULL);
4292 gtk_style_apply_default_background (style, window,
4293 widget && !GTK_WIDGET_NO_WINDOW (widget),
4294 GTK_STATE_NORMAL, area, x, y, width, height);
4296 sanitize_size (window, &width, &height);
4298 switch (shadow_type)
4300 case GTK_SHADOW_NONE:
4303 gc1 = style->dark_gc[state_type];
4304 gc2 = style->black_gc;
4305 gc3 = style->bg_gc[state_type];
4306 gc4 = style->light_gc[state_type];
4308 case GTK_SHADOW_ETCHED_IN:
4309 gc1 = style->dark_gc[state_type];
4310 gc2 = style->light_gc[state_type];
4311 gc3 = style->dark_gc[state_type];
4312 gc4 = style->light_gc[state_type];
4314 case GTK_SHADOW_OUT:
4315 gc1 = style->light_gc[state_type];
4316 gc2 = style->bg_gc[state_type];
4317 gc3 = style->dark_gc[state_type];
4318 gc4 = style->black_gc;
4320 case GTK_SHADOW_ETCHED_OUT:
4321 gc1 = style->light_gc[state_type];
4322 gc2 = style->dark_gc[state_type];
4323 gc3 = style->light_gc[state_type];
4324 gc4 = style->dark_gc[state_type];
4330 gdk_gc_set_clip_rectangle (gc1, area);
4331 gdk_gc_set_clip_rectangle (gc2, area);
4332 gdk_gc_set_clip_rectangle (gc3, area);
4333 gdk_gc_set_clip_rectangle (gc4, area);
4336 switch (shadow_type)
4338 case GTK_SHADOW_NONE:
4340 case GTK_SHADOW_OUT:
4341 case GTK_SHADOW_ETCHED_IN:
4342 case GTK_SHADOW_ETCHED_OUT:
4346 gtk_style_apply_default_background (style, window,
4347 widget && !GTK_WIDGET_NO_WINDOW (widget),
4349 x + style->xthickness,
4351 width - (2 * style->xthickness),
4352 height - (style->ythickness));
4353 gdk_draw_line (window, gc1,
4354 x, y, x, y + height - 2);
4355 gdk_draw_line (window, gc2,
4356 x + 1, y, x + 1, y + height - 2);
4358 gdk_draw_line (window, gc3,
4359 x + 2, y + height - 2, x + width - 2, y + height - 2);
4360 gdk_draw_line (window, gc3,
4361 x + width - 2, y, x + width - 2, y + height - 2);
4362 gdk_draw_line (window, gc4,
4363 x + 1, y + height - 1, x + width - 2, y + height - 1);
4364 gdk_draw_line (window, gc4,
4365 x + width - 1, y, x + width - 1, y + height - 2);
4367 case GTK_POS_BOTTOM:
4368 gtk_style_apply_default_background (style, window,
4369 widget && !GTK_WIDGET_NO_WINDOW (widget),
4371 x + style->xthickness,
4372 y + style->ythickness,
4373 width - (2 * style->xthickness),
4374 height - (style->ythickness));
4375 gdk_draw_line (window, gc1,
4376 x + 1, y, x + width - 2, y);
4377 gdk_draw_line (window, gc1,
4378 x, y + 1, x, y + height - 1);
4379 gdk_draw_line (window, gc2,
4380 x + 1, y + 1, x + width - 2, y + 1);
4381 gdk_draw_line (window, gc2,
4382 x + 1, y + 1, x + 1, y + height - 1);
4384 gdk_draw_line (window, gc3,
4385 x + width - 2, y + 2, x + width - 2, y + height - 1);
4386 gdk_draw_line (window, gc4,
4387 x + width - 1, y + 1, x + width - 1, y + height - 1);
4390 gtk_style_apply_default_background (style, window,
4391 widget && !GTK_WIDGET_NO_WINDOW (widget),
4394 y + style->ythickness,
4395 width - (style->xthickness),
4396 height - (2 * style->ythickness));
4397 gdk_draw_line (window, gc1,
4398 x, y, x + width - 2, y);
4399 gdk_draw_line (window, gc2,
4400 x + 1, y + 1, x + width - 2, y + 1);
4402 gdk_draw_line (window, gc3,
4403 x, y + height - 2, x + width - 2, y + height - 2);
4404 gdk_draw_line (window, gc3,
4405 x + width - 2, y + 2, x + width - 2, y + height - 2);
4406 gdk_draw_line (window, gc4,
4407 x, y + height - 1, x + width - 2, y + height - 1);
4408 gdk_draw_line (window, gc4,
4409 x + width - 1, y + 1, x + width - 1, y + height - 2);
4412 gtk_style_apply_default_background (style, window,
4413 widget && !GTK_WIDGET_NO_WINDOW (widget),
4415 x + style->xthickness,
4416 y + style->ythickness,
4417 width - (style->xthickness),
4418 height - (2 * style->ythickness));
4419 gdk_draw_line (window, gc1,
4420 x + 1, y, x + width - 1, y);
4421 gdk_draw_line (window, gc1,
4422 x, y + 1, x, y + height - 2);
4423 gdk_draw_line (window, gc2,
4424 x + 1, y + 1, x + width - 1, y + 1);
4425 gdk_draw_line (window, gc2,
4426 x + 1, y + 1, x + 1, y + height - 2);
4428 gdk_draw_line (window, gc3,
4429 x + 2, y + height - 2, x + width - 1, y + height - 2);
4430 gdk_draw_line (window, gc4,
4431 x + 1, y + height - 1, x + width - 1, y + height - 1);
4438 gdk_gc_set_clip_rectangle (gc1, NULL);
4439 gdk_gc_set_clip_rectangle (gc2, NULL);
4440 gdk_gc_set_clip_rectangle (gc3, NULL);
4441 gdk_gc_set_clip_rectangle (gc4, NULL);
4446 gtk_default_draw_focus (GtkStyle *style,
4448 GtkStateType state_type,
4451 const gchar *detail,
4459 gboolean free_dash_list = FALSE;
4460 gint line_width = 1;
4461 gint8 *dash_list = "\1\1";
4464 gc = style->fg_gc[state_type];
4468 gtk_widget_style_get (widget,
4469 "focus-line-width", &line_width,
4470 "focus-line-pattern", (gchar *)&dash_list,
4473 free_dash_list = TRUE;
4476 sanitize_size (window, &width, &height);
4479 gdk_gc_set_clip_rectangle (gc, area);
4481 gdk_gc_set_line_attributes (gc, line_width,
4482 dash_list[0] ? GDK_LINE_ON_OFF_DASH : GDK_LINE_SOLID,
4483 GDK_CAP_BUTT, GDK_JOIN_MITER);
4486 if (detail && !strcmp (detail, "add-mode"))
4492 free_dash_list = FALSE;
4495 points[0].x = x + line_width / 2;
4496 points[0].y = y + line_width / 2;
4497 points[1].x = x + width - line_width + line_width / 2;
4498 points[1].y = y + line_width / 2;
4499 points[2].x = x + width - line_width + line_width / 2;
4500 points[2].y = y + height - line_width + line_width / 2;
4501 points[3].x = x + line_width / 2;
4502 points[3].y = y + height - line_width + line_width / 2;
4503 points[4] = points[0];
4507 gdk_draw_lines (window, gc, points, 5);
4511 /* We go through all the pain below because the X rasterization
4512 * rules don't really work right for dashed lines if you
4513 * want continuity in segments that go between top/right
4514 * and left/bottom. For instance, a top left corner
4515 * with a 1-1 dash is drawn as:
4522 * This is because pixels on the top and left boundaries
4523 * of polygons are drawn, but not on the bottom and right.
4524 * So, if you have a line going up that turns the corner
4525 * and goes right, there is a one pixel shift in the pattern.
4527 * So, to fix this, we drawn the top and right in one call,
4528 * then the left and bottom in another call, fixing up
4529 * the dash offset for the second call ourselves to get
4530 * continuity at the upper left.
4532 * It's not perfect since we really should have a join at
4533 * the upper left and lower right instead of two intersecting
4534 * lines but that's only really apparent for no-dashes,
4535 * which (for this reason) are done as one polygon and
4536 * don't to through this code path.
4539 dash_len = strlen (dash_list);
4542 gdk_gc_set_dashes (gc, 0, dash_list, dash_len);
4544 gdk_draw_lines (window, gc, points, 3);
4546 /* We draw this line one farther over than it is "supposed" to
4547 * because of another rasterization problem ... if two 1 pixel
4548 * unjoined lines meet at the lower right, there will be a missing
4555 gint dash_pixels = 0;
4558 /* Adjust the dash offset for the bottom and left so we
4559 * match up at the upper left.
4561 for (i = 0; i < dash_len; i++)
4562 dash_pixels += dash_list[i];
4564 if (dash_len % 2 == 1)
4567 gdk_gc_set_dashes (gc, dash_pixels - (width + height - 2 * line_width) % dash_pixels, dash_list, dash_len);
4570 gdk_draw_lines (window, gc, points + 2, 3);
4573 gdk_gc_set_line_attributes (gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
4576 gdk_gc_set_clip_rectangle (gc, NULL);
4583 gtk_default_draw_slider (GtkStyle *style,
4585 GtkStateType state_type,
4586 GtkShadowType shadow_type,
4589 const gchar *detail,
4594 GtkOrientation orientation)
4596 g_return_if_fail (GTK_IS_STYLE (style));
4597 g_return_if_fail (window != NULL);
4599 sanitize_size (window, &width, &height);
4601 gtk_paint_box (style, window, state_type, shadow_type,
4602 area, widget, detail, x, y, width, height);
4605 (strcmp ("hscale", detail) == 0 ||
4606 strcmp ("vscale", detail) == 0))
4608 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4609 gtk_paint_vline (style, window, state_type, area, widget, detail,
4610 y + style->ythickness,
4611 y + height - style->ythickness - 1, x + width / 2);
4613 gtk_paint_hline (style, window, state_type, area, widget, detail,
4614 x + style->xthickness,
4615 x + width - style->xthickness - 1, y + height / 2);
4620 draw_dot (GdkWindow *window,
4628 size = CLAMP (size, 2, 3);
4632 gdk_draw_point (window, light_gc, x, y);
4633 gdk_draw_point (window, light_gc, x+1, y+1);
4635 else if (size == 3);
4637 gdk_draw_point (window, light_gc, x, y);
4638 gdk_draw_point (window, light_gc, x+1, y);
4639 gdk_draw_point (window, light_gc, x, y+1);
4640 gdk_draw_point (window, dark_gc, x+1, y+2);
4641 gdk_draw_point (window, dark_gc, x+2, y+1);
4642 gdk_draw_point (window, dark_gc, x+2, y+2);
4647 gtk_default_draw_handle (GtkStyle *style,
4649 GtkStateType state_type,
4650 GtkShadowType shadow_type,
4653 const gchar *detail,
4658 GtkOrientation orientation)
4661 gint xthick, ythick;
4662 GdkGC *light_gc, *dark_gc;
4667 g_return_if_fail (GTK_IS_STYLE (style));
4668 g_return_if_fail (window != NULL);
4670 sanitize_size (window, &width, &height);
4672 gtk_paint_box (style, window, state_type, shadow_type, area, widget,
4673 detail, x, y, width, height);
4676 if (!strcmp (detail, "paned"))
4678 /* we want to ignore the shadow border in paned widgets */
4682 light_gc = style->light_gc[state_type];
4683 dark_gc = style->black_gc;
4687 xthick = style->xthickness;
4688 ythick = style->ythickness;
4690 light_gc = style->light_gc[state_type];
4691 dark_gc = style->dark_gc[state_type];
4694 rect.x = x + xthick;
4695 rect.y = y + ythick;
4696 rect.width = width - (xthick * 2);
4697 rect.height = height - (ythick * 2);
4700 intersect = gdk_rectangle_intersect (area, &rect, &dest);
4710 gdk_gc_set_clip_rectangle (light_gc, &dest);
4711 gdk_gc_set_clip_rectangle (dark_gc, &dest);
4713 if (!strcmp (detail, "paned"))
4715 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4716 for (xx = x + width/2 - 15; xx <= x + width/2 + 15; xx += 5)
4717 draw_dot (window, light_gc, dark_gc, xx, y + height/2 - 1, 3);
4719 for (yy = y + height/2 - 15; yy <= y + height/2 + 15; yy += 5)
4720 draw_dot (window, light_gc, dark_gc, x + width/2 - 1, yy, 3);
4724 for (yy = y + ythick; yy < (y + height - ythick); yy += 3)
4725 for (xx = x + xthick; xx < (x + width - xthick); xx += 6)
4727 draw_dot (window, light_gc, dark_gc, xx, yy, 2);
4728 draw_dot (window, light_gc, dark_gc, xx + 3, yy + 1, 2);
4732 gdk_gc_set_clip_rectangle (light_gc, NULL);
4733 gdk_gc_set_clip_rectangle (dark_gc, NULL);
4737 create_expander_affine (gdouble affine[6],
4747 width = expander_size / 4.0;
4748 height = expander_size / 2.0;
4750 s = sin (degrees * G_PI / 180.0);
4751 c = cos (degrees * G_PI / 180.0);
4757 affine[4] = -width * c - height * -s + x;
4758 affine[5] = -width * s - height * c + y;
4762 apply_affine_on_point (double affine[6], GdkPoint *point)
4766 x = point->x * affine[0] + point->y * affine[2] + affine[4];
4767 y = point->x * affine[1] + point->y * affine[3] + affine[5];
4774 gtk_style_draw_polygon_with_gc (GdkWindow *window, GdkGC *gc, gint line_width,
4775 gboolean do_fill, GdkPoint *points, gint n_points)
4777 gdk_gc_set_line_attributes (gc, line_width,
4779 GDK_CAP_BUTT, GDK_JOIN_MITER);
4781 gdk_draw_polygon (window, gc, do_fill, points, n_points);
4782 gdk_gc_set_line_attributes (gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
4786 gtk_default_draw_expander (GtkStyle *style,
4788 GtkStateType state_type,
4791 const gchar *detail,
4794 GtkExpanderStyle expander_style)
4803 gtk_widget_style_get (widget,
4804 "expander_size", &expander_size,
4806 line_width = MAX (1, expander_size/7);
4810 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], area);
4811 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], area);
4814 expander_size -= (line_width * 2 - 2);
4815 points[0].x = line_width / 2;
4816 points[0].y = line_width / 2;
4817 points[1].x = expander_size / 2 + line_width / 2;
4818 points[1].y = expander_size / 2 + line_width / 2;
4819 points[2].x = line_width / 2;
4820 points[2].y = expander_size + line_width / 2;
4822 switch (expander_style)
4824 case GTK_EXPANDER_COLLAPSED:
4825 degrees = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ? 180 : 0;
4827 case GTK_EXPANDER_SEMI_COLLAPSED:
4828 degrees = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ? 150 : 30;
4830 case GTK_EXPANDER_SEMI_EXPANDED:
4831 degrees = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ? 120 : 60;
4833 case GTK_EXPANDER_EXPANDED:
4837 g_assert_not_reached ();
4840 create_expander_affine (affine, degrees, expander_size, x, y);
4842 for (i = 0; i < 3; i++)
4843 apply_affine_on_point (affine, &points[i]);
4845 if (state_type == GTK_STATE_PRELIGHT)
4847 gtk_style_draw_polygon_with_gc (window, style->fg_gc[GTK_STATE_NORMAL],
4848 1, TRUE, points, 3);
4850 else if (state_type == GTK_STATE_ACTIVE)
4852 gtk_style_draw_polygon_with_gc (window, style->light_gc[GTK_STATE_ACTIVE],
4853 1, TRUE, points, 3);
4854 gtk_style_draw_polygon_with_gc (window, style->fg_gc[GTK_STATE_NORMAL],
4855 line_width, FALSE, points, 3);
4859 gtk_style_draw_polygon_with_gc (window, style->base_gc[GTK_STATE_NORMAL],
4860 1, TRUE, points, 3);
4861 gtk_style_draw_polygon_with_gc (window, style->fg_gc[GTK_STATE_NORMAL],
4862 line_width, FALSE, points, 3);
4866 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], NULL);
4867 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], NULL);
4871 typedef struct _ByteRange ByteRange;
4880 range_new (guint start,
4883 ByteRange *br = g_new (ByteRange, 1);
4892 get_insensitive_layout (GdkDrawable *drawable,
4893 PangoLayout *layout)
4895 GSList *embossed_ranges = NULL;
4896 GSList *stippled_ranges = NULL;
4897 PangoLayoutIter *iter;
4898 GSList *tmp_list = NULL;
4899 PangoLayout *new_layout;
4900 PangoAttrList *attrs;
4901 GdkBitmap *stipple = NULL;
4903 iter = pango_layout_get_iter (layout);
4907 PangoLayoutRun *run;
4908 PangoAttribute *attr;
4909 gboolean need_stipple = FALSE;
4912 run = pango_layout_iter_get_run (iter);
4916 tmp_list = run->item->analysis.extra_attrs;
4918 while (tmp_list != NULL)
4920 attr = tmp_list->data;
4921 switch (attr->klass->type)
4923 case PANGO_ATTR_FOREGROUND:
4924 case PANGO_ATTR_BACKGROUND:
4925 need_stipple = TRUE;
4935 tmp_list = g_slist_next (tmp_list);
4938 br = range_new (run->item->offset, run->item->offset + run->item->length);
4941 stippled_ranges = g_slist_prepend (stippled_ranges, br);
4943 embossed_ranges = g_slist_prepend (embossed_ranges, br);
4946 while (pango_layout_iter_next_run (iter));
4948 pango_layout_iter_free (iter);
4950 new_layout = pango_layout_copy (layout);
4952 attrs = pango_layout_get_attributes (new_layout);
4956 /* Create attr list if there wasn't one */
4957 attrs = pango_attr_list_new ();
4958 pango_layout_set_attributes (new_layout, attrs);
4959 pango_attr_list_unref (attrs);
4962 tmp_list = embossed_ranges;
4963 while (tmp_list != NULL)
4965 PangoAttribute *attr;
4966 ByteRange *br = tmp_list->data;
4968 attr = gdk_pango_attr_embossed_new (TRUE);
4970 attr->start_index = br->start;
4971 attr->end_index = br->end;
4973 pango_attr_list_change (attrs, attr);
4977 tmp_list = g_slist_next (tmp_list);
4980 g_slist_free (embossed_ranges);
4982 tmp_list = stippled_ranges;
4983 while (tmp_list != NULL)
4985 PangoAttribute *attr;
4986 ByteRange *br = tmp_list->data;
4988 if (stipple == NULL)
4990 #define gray50_width 2
4991 #define gray50_height 2
4992 static char gray50_bits[] = {
4996 stipple = gdk_bitmap_create_from_data (drawable,
4997 gray50_bits, gray50_width,
5001 attr = gdk_pango_attr_stipple_new (stipple);
5003 attr->start_index = br->start;
5004 attr->end_index = br->end;
5006 pango_attr_list_change (attrs, attr);
5010 tmp_list = g_slist_next (tmp_list);
5013 g_slist_free (stippled_ranges);
5016 g_object_unref (stipple);
5022 gtk_default_draw_layout (GtkStyle *style,
5024 GtkStateType state_type,
5028 const gchar *detail,
5031 PangoLayout *layout)
5035 g_return_if_fail (GTK_IS_STYLE (style));
5036 g_return_if_fail (window != NULL);
5038 gc = use_text ? style->text_gc[state_type] : style->fg_gc[state_type];
5041 gdk_gc_set_clip_rectangle (gc, area);
5043 if (state_type == GTK_STATE_INSENSITIVE)
5047 ins = get_insensitive_layout (window, layout);
5049 gdk_draw_layout (window, gc, x, y, ins);
5051 g_object_unref (ins);
5055 gdk_draw_layout (window, gc, x, y, layout);
5059 gdk_gc_set_clip_rectangle (gc, NULL);
5063 gtk_default_draw_resize_grip (GtkStyle *style,
5065 GtkStateType state_type,
5068 const gchar *detail,
5075 g_return_if_fail (GTK_IS_STYLE (style));
5076 g_return_if_fail (window != NULL);
5080 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
5081 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
5082 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
5087 case GDK_WINDOW_EDGE_NORTH_WEST:
5088 /* make it square */
5093 else if (height < width)
5098 case GDK_WINDOW_EDGE_NORTH:
5104 case GDK_WINDOW_EDGE_NORTH_EAST:
5105 /* make it square, aligning to top right */
5110 else if (height < width)
5112 x += (width - height);
5116 case GDK_WINDOW_EDGE_WEST:
5122 case GDK_WINDOW_EDGE_EAST:
5123 /* aligning to right */
5126 x += (width - height);
5130 case GDK_WINDOW_EDGE_SOUTH_WEST:
5131 /* make it square, aligning to bottom left */
5134 y += (height - width);
5137 else if (height < width)
5142 case GDK_WINDOW_EDGE_SOUTH:
5143 /* align to bottom */
5146 y += (height - width);
5150 case GDK_WINDOW_EDGE_SOUTH_EAST:
5151 /* make it square, aligning to bottom right */
5154 y += (height - width);
5157 else if (height < width)
5159 x += (width - height);
5164 g_assert_not_reached ();
5166 /* Clear background */
5167 gtk_style_apply_default_background (style, window, FALSE,
5169 x, y, width, height);
5173 case GDK_WINDOW_EDGE_WEST:
5174 case GDK_WINDOW_EDGE_EAST:
5180 while (xi < x + width)
5182 gdk_draw_line (window,
5183 style->light_gc[state_type],
5188 gdk_draw_line (window,
5189 style->dark_gc[state_type],
5197 case GDK_WINDOW_EDGE_NORTH:
5198 case GDK_WINDOW_EDGE_SOUTH:
5204 while (yi < y + height)
5206 gdk_draw_line (window,
5207 style->light_gc[state_type],
5212 gdk_draw_line (window,
5213 style->dark_gc[state_type],
5221 case GDK_WINDOW_EDGE_NORTH_WEST:
5230 gdk_draw_line (window,
5231 style->dark_gc[state_type],
5238 gdk_draw_line (window,
5239 style->dark_gc[state_type],
5246 gdk_draw_line (window,
5247 style->light_gc[state_type],
5257 case GDK_WINDOW_EDGE_NORTH_EAST:
5264 while (xi < (x + width - 3))
5266 gdk_draw_line (window,
5267 style->light_gc[state_type],
5274 gdk_draw_line (window,
5275 style->dark_gc[state_type],
5282 gdk_draw_line (window,
5283 style->dark_gc[state_type],
5292 case GDK_WINDOW_EDGE_SOUTH_WEST:
5301 gdk_draw_line (window,
5302 style->dark_gc[state_type],
5309 gdk_draw_line (window,
5310 style->dark_gc[state_type],
5317 gdk_draw_line (window,
5318 style->light_gc[state_type],
5328 case GDK_WINDOW_EDGE_SOUTH_EAST:
5335 while (xi < (x + width - 3))
5337 gdk_draw_line (window,
5338 style->light_gc[state_type],
5345 gdk_draw_line (window,
5346 style->dark_gc[state_type],
5353 gdk_draw_line (window,
5354 style->dark_gc[state_type],
5364 g_assert_not_reached ();
5370 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
5371 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
5372 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
5377 gtk_style_shade (GdkColor *a,
5385 red = (gdouble) a->red / 65535.0;
5386 green = (gdouble) a->green / 65535.0;
5387 blue = (gdouble) a->blue / 65535.0;
5389 rgb_to_hls (&red, &green, &blue);
5394 else if (green < 0.0)
5400 else if (blue < 0.0)
5403 hls_to_rgb (&red, &green, &blue);
5405 b->red = red * 65535.0;
5406 b->green = green * 65535.0;
5407 b->blue = blue * 65535.0;
5411 rgb_to_hls (gdouble *r,
5452 l = (max + min) / 2;
5459 s = (max - min) / (max + min);
5461 s = (max - min) / (2 - max - min);
5465 h = (green - blue) / delta;
5466 else if (green == max)
5467 h = 2 + (blue - red) / delta;
5468 else if (blue == max)
5469 h = 4 + (red - green) / delta;
5482 hls_to_rgb (gdouble *h,
5495 if (lightness <= 0.5)
5496 m2 = lightness * (1 + saturation);
5498 m2 = lightness + saturation - lightness * saturation;
5499 m1 = 2 * lightness - m2;
5501 if (saturation == 0)
5516 r = m1 + (m2 - m1) * hue / 60;
5520 r = m1 + (m2 - m1) * (240 - hue) / 60;
5531 g = m1 + (m2 - m1) * hue / 60;
5535 g = m1 + (m2 - m1) * (240 - hue) / 60;
5546 b = m1 + (m2 - m1) * hue / 60;
5550 b = m1 + (m2 - m1) * (240 - hue) / 60;
5563 * @style: a #GtkStyle
5564 * @window: a #GdkWindow
5565 * @state_type: a state
5566 * @area: rectangle to which the output is clipped
5569 * @x1: the starting x coordinate
5570 * @x2: the ending x coordinate
5571 * @y: the y coordinate
5573 * Draws a horizontal line from (@x1, @y) to (@x2, @y) in @window
5574 * using the given style and state.
5577 gtk_paint_hline (GtkStyle *style,
5579 GtkStateType state_type,
5582 const gchar *detail,
5587 g_return_if_fail (GTK_IS_STYLE (style));
5588 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
5590 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, area, widget, detail, x1, x2, y);
5595 * @style: a #GtkStyle
5596 * @window: a #GdkWindow
5597 * @state_type: a state
5598 * @area: rectangle to which the output is clipped
5601 * @y1_: the starting y coordinate
5602 * @y2_: the ending y coordinate
5603 * @x: the x coordinate
5605 * Draws a vertical line from (@x, @y1_) to (@x, @y2_) in @window
5606 * using the given style and state.
5609 gtk_paint_vline (GtkStyle *style,
5611 GtkStateType state_type,
5614 const gchar *detail,
5619 g_return_if_fail (GTK_IS_STYLE (style));
5620 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
5622 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, area, widget, detail, y1, y2, x);
5626 gtk_paint_shadow (GtkStyle *style,
5628 GtkStateType state_type,
5629 GtkShadowType shadow_type,
5632 const gchar *detail,
5638 g_return_if_fail (GTK_IS_STYLE (style));
5639 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
5641 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5645 gtk_paint_polygon (GtkStyle *style,
5647 GtkStateType state_type,
5648 GtkShadowType shadow_type,
5651 const gchar *detail,
5656 g_return_if_fail (GTK_IS_STYLE (style));
5657 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
5659 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, area, widget, detail, points, npoints, fill);
5663 gtk_paint_arrow (GtkStyle *style,
5665 GtkStateType state_type,
5666 GtkShadowType shadow_type,
5669 const gchar *detail,
5670 GtkArrowType arrow_type,
5677 g_return_if_fail (GTK_IS_STYLE (style));
5678 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
5680 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, area, widget, detail, arrow_type, fill, x, y, width, height);
5684 gtk_paint_diamond (GtkStyle *style,
5686 GtkStateType state_type,
5687 GtkShadowType shadow_type,
5690 const gchar *detail,
5696 g_return_if_fail (GTK_IS_STYLE (style));
5697 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
5699 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5704 * @style: a #GtkStyle
5705 * @window: a #GdkWindow
5706 * @state_type: a state
5707 * @area: clip rectangle
5708 * @widget: the widget
5709 * @detail: a style detail
5712 * @string: the string to draw
5714 * Draws a text string on @window with the given parameters.
5716 * This function is deprecated, use gtk_paint_layout() instead.
5719 gtk_paint_string (GtkStyle *style,
5721 GtkStateType state_type,
5724 const gchar *detail,
5727 const gchar *string)
5729 g_return_if_fail (GTK_IS_STYLE (style));
5730 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
5732 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, area, widget, detail, x, y, string);
5736 gtk_paint_box (GtkStyle *style,
5738 GtkStateType state_type,
5739 GtkShadowType shadow_type,
5742 const gchar *detail,
5748 g_return_if_fail (GTK_IS_STYLE (style));
5749 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
5751 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5755 gtk_paint_flat_box (GtkStyle *style,
5757 GtkStateType state_type,
5758 GtkShadowType shadow_type,
5761 const gchar *detail,
5767 g_return_if_fail (GTK_IS_STYLE (style));
5768 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
5770 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5774 gtk_paint_check (GtkStyle *style,
5776 GtkStateType state_type,
5777 GtkShadowType shadow_type,
5780 const gchar *detail,
5786 g_return_if_fail (GTK_IS_STYLE (style));
5787 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
5789 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5793 gtk_paint_option (GtkStyle *style,
5795 GtkStateType state_type,
5796 GtkShadowType shadow_type,
5799 const gchar *detail,
5805 g_return_if_fail (GTK_IS_STYLE (style));
5806 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
5808 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5812 gtk_paint_tab (GtkStyle *style,
5814 GtkStateType state_type,
5815 GtkShadowType shadow_type,
5818 const gchar *detail,
5824 g_return_if_fail (GTK_IS_STYLE (style));
5825 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
5827 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5831 gtk_paint_shadow_gap (GtkStyle *style,
5833 GtkStateType state_type,
5834 GtkShadowType shadow_type,
5842 GtkPositionType gap_side,
5846 g_return_if_fail (GTK_IS_STYLE (style));
5847 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
5849 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);
5854 gtk_paint_box_gap (GtkStyle *style,
5856 GtkStateType state_type,
5857 GtkShadowType shadow_type,
5865 GtkPositionType gap_side,
5869 g_return_if_fail (GTK_IS_STYLE (style));
5870 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
5872 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);
5876 gtk_paint_extension (GtkStyle *style,
5878 GtkStateType state_type,
5879 GtkShadowType shadow_type,
5887 GtkPositionType gap_side)
5889 g_return_if_fail (GTK_IS_STYLE (style));
5890 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
5892 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side);
5896 gtk_paint_focus (GtkStyle *style,
5898 GtkStateType state_type,
5901 const gchar *detail,
5907 g_return_if_fail (GTK_IS_STYLE (style));
5908 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
5910 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, state_type, area, widget, detail, x, y, width, height);
5914 gtk_paint_slider (GtkStyle *style,
5916 GtkStateType state_type,
5917 GtkShadowType shadow_type,
5920 const gchar *detail,
5925 GtkOrientation orientation)
5927 g_return_if_fail (GTK_IS_STYLE (style));
5928 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
5930 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
5934 gtk_paint_handle (GtkStyle *style,
5936 GtkStateType state_type,
5937 GtkShadowType shadow_type,
5940 const gchar *detail,
5945 GtkOrientation orientation)
5947 g_return_if_fail (GTK_IS_STYLE (style));
5948 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
5950 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
5954 gtk_paint_expander (GtkStyle *style,
5956 GtkStateType state_type,
5959 const gchar *detail,
5962 GtkExpanderStyle expander_style)
5964 g_return_if_fail (GTK_IS_STYLE (style));
5965 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
5967 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type, area,
5968 widget, detail, x, y, expander_style);
5972 gtk_paint_layout (GtkStyle *style,
5974 GtkStateType state_type,
5978 const gchar *detail,
5981 PangoLayout *layout)
5983 g_return_if_fail (GTK_IS_STYLE (style));
5984 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
5986 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text, area,
5987 widget, detail, x, y, layout);
5991 gtk_paint_resize_grip (GtkStyle *style,
5993 GtkStateType state_type,
5996 const gchar *detail,
6004 g_return_if_fail (GTK_IS_STYLE (style));
6005 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
6007 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
6008 area, widget, detail,
6009 edge, x, y, width, height);
6014 * @border_: a #GtkBorder.
6015 * @returns: a copy of @border_.
6017 * Copies a #GtkBorder structure.
6020 gtk_border_copy (const GtkBorder *border)
6022 return (GtkBorder *)g_memdup (border, sizeof (GtkBorder));
6027 * @border_: a #GtkBorder.
6029 * Frees a #GtkBorder structure.
6032 gtk_border_free (GtkBorder *border)
6038 gtk_border_get_type (void)
6040 static GType our_type = 0;
6043 our_type = g_boxed_type_register_static ("GtkBorder",
6044 (GBoxedCopyFunc) gtk_border_copy,
6045 (GBoxedFreeFunc) gtk_border_free);
6051 gtk_style_get_font_internal (GtkStyle *style)
6053 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
6055 if (style->private_font && style->private_font_desc)
6057 if (!style->font_desc ||
6058 !pango_font_description_equal (style->private_font_desc, style->font_desc))
6060 gdk_font_unref (style->private_font);
6061 style->private_font = NULL;
6063 if (style->private_font_desc)
6065 pango_font_description_free (style->private_font_desc);
6066 style->private_font_desc = NULL;
6071 if (!style->private_font)
6073 GdkDisplay *display;
6075 if (style->colormap)
6077 display = gdk_screen_get_display (gdk_colormap_get_screen (style->colormap));
6081 display = gdk_display_get_default ();
6082 GTK_NOTE (MULTIHEAD,
6083 g_warning ("gtk_style_get_font() should not be called on an unattached style"));
6086 if (style->font_desc)
6088 style->private_font = gdk_font_from_description_for_display (display, style->font_desc);
6089 style->private_font_desc = pango_font_description_copy (style->font_desc);
6092 if (!style->private_font)
6093 style->private_font = gdk_font_load_for_display (display, "fixed");
6095 if (!style->private_font)
6096 g_error ("Unable to load \"fixed\" font");
6099 return style->private_font;
6103 * gtk_style_get_font:
6104 * @style: a #GtkStyle
6106 * Gets the #GdkFont to use for the given style. This is
6107 * meant only as a replacement for direct access to @style->font
6108 * and should not be used in new code. New code should
6109 * use @style->font_desc instead.
6111 * Return value: the #GdkFont for the style. This font is owned
6112 * by the style; if you want to keep around a copy, you must
6113 * call gdk_font_ref().
6116 gtk_style_get_font (GtkStyle *style)
6118 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
6120 return gtk_style_get_font_internal (style);
6124 * gtk_style_set_font:
6125 * @style: a #GtkStyle.
6126 * @font: a #GdkFont, or %NULL to use the #GdkFont corresponding
6127 * to style->font_desc.
6129 * Sets the #GdkFont to use for a given style. This is
6130 * meant only as a replacement for direct access to style->font
6131 * and should not be used in new code. New code should
6132 * use style->font_desc instead.
6135 gtk_style_set_font (GtkStyle *style,
6140 g_return_if_fail (GTK_IS_STYLE (style));
6142 old_font = style->private_font;
6144 style->private_font = font;
6146 gdk_font_ref (font);
6149 gdk_font_unref (old_font);
6151 if (style->private_font_desc)
6153 pango_font_description_free (style->private_font_desc);
6154 style->private_font_desc = NULL;
6158 typedef struct _CursorInfo CursorInfo;
6164 GdkGC *secondary_gc;
6168 style_unrealize_cursor_gcs (GtkStyle *style)
6172 cursor_info = g_object_get_data (G_OBJECT (style), "gtk-style-cursor-info");
6175 if (cursor_info->primary_gc)
6176 gtk_gc_release (cursor_info->primary_gc);
6178 if (cursor_info->secondary_gc)
6179 gtk_gc_release (cursor_info->secondary_gc);
6181 g_free (cursor_info);
6182 g_object_set_data (G_OBJECT (style), "gtk-style-cursor-info", NULL);
6187 make_cursor_gc (GtkWidget *widget,
6188 const gchar *property_name,
6191 GdkGCValues gc_values;
6192 GdkGCValuesMask gc_values_mask;
6193 GdkColor *cursor_color;
6195 gtk_widget_style_get (widget, property_name, &cursor_color, NULL);
6197 gc_values_mask = GDK_GC_FOREGROUND;
6200 gc_values.foreground = *cursor_color;
6201 gdk_color_free (cursor_color);
6204 gc_values.foreground = *fallback;
6206 gdk_rgb_find_color (widget->style->colormap, &gc_values.foreground);
6207 return gtk_gc_get (widget->style->depth, widget->style->colormap, &gc_values, gc_values_mask);
6211 * _gtk_get_insertion_cursor_gc:
6212 * @widget: a #GtkWidget
6213 * @is_primary: if the cursor should be the primary cursor color.
6215 * Get a GC suitable for drawing the primary or secondary text
6218 * Note: the return value is ref'ed because calls to this function
6219 * on other widgets could result in this the GC being released
6220 * which would be an unexpected side effect. If made public,
6221 * this function should possibly be called create_insertion_cursor_gc().
6223 * Return value: an appropriate #GdkGC. Call g_object_unref() on
6224 * the gc when you are done with it; this GC may be shared with
6225 * other users, so you must not modify the GC except for temporarily
6226 * setting the clip before drawing with the GC, and then unsetting the clip
6230 _gtk_get_insertion_cursor_gc (GtkWidget *widget,
6231 gboolean is_primary)
6233 CursorInfo *cursor_info;
6235 cursor_info = g_object_get_data (G_OBJECT (widget->style), "gtk-style-cursor-info");
6238 cursor_info = g_new (CursorInfo, 1);
6239 g_object_set_data (G_OBJECT (widget->style), "gtk-style-cursor-info", cursor_info);
6240 cursor_info->primary_gc = NULL;
6241 cursor_info->secondary_gc = NULL;
6242 cursor_info->for_type = G_TYPE_INVALID;
6245 /* We have to keep track of the type because gtk_widget_style_get()
6246 * can return different results when called on the same property and
6247 * same style but for different widgets. :-(. That is,
6248 * GtkEntry::cursor-color = "red" in a style will modify the cursor
6249 * color for entries but not for text view.
6251 if (cursor_info->for_type != G_OBJECT_TYPE (widget))
6253 cursor_info->for_type = G_OBJECT_TYPE (widget);
6254 if (cursor_info->primary_gc)
6256 gtk_gc_release (cursor_info->primary_gc);
6257 cursor_info->primary_gc = NULL;
6259 if (cursor_info->secondary_gc)
6261 gtk_gc_release (cursor_info->secondary_gc);
6262 cursor_info->secondary_gc = NULL;
6268 if (!cursor_info->primary_gc)
6269 cursor_info->primary_gc = make_cursor_gc (widget,
6271 &widget->style->black);
6273 return g_object_ref (cursor_info->primary_gc);
6277 static GdkColor gray = { 0, 0x8888, 0x8888, 0x8888 };
6279 if (!cursor_info->secondary_gc)
6280 cursor_info->secondary_gc = make_cursor_gc (widget,
6281 "secondary-cursor-color",
6284 return g_object_ref (cursor_info->secondary_gc);
6289 * _gtk_draw_insertion_cursor:
6290 * @widget: a #GtkWidget
6291 * @drawable: a #GdkDrawable
6293 * @location: location where to draw the cursor (@location->width is ignored)
6294 * @direction: whether the cursor is left-to-right or
6295 * right-to-left. Should never be #GTK_TEXT_DIR_NONE
6296 * @draw_arrow: %TRUE to draw a directional arrow on the
6297 * cursor. Should be %FALSE unless the cursor is split.
6299 * Draws a text caret on @drawable at @location. This is not a style function
6300 * but merely a convenience function for drawing the standard cursor shape.
6303 _gtk_draw_insertion_cursor (GtkWidget *widget,
6304 GdkDrawable *drawable,
6306 GdkRectangle *location,
6307 GtkTextDirection direction,
6308 gboolean draw_arrow)
6314 gfloat cursor_aspect_ratio;
6317 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
6319 gtk_widget_style_get (widget, "cursor-aspect-ratio", &cursor_aspect_ratio, NULL);
6321 stem_width = location->height * cursor_aspect_ratio + 1;
6322 arrow_width = stem_width + 1;
6324 /* put (stem_width % 2) on the proper side of the cursor */
6325 if (direction == GTK_TEXT_DIR_LTR)
6326 offset = stem_width / 2;
6328 offset = stem_width - stem_width / 2;
6330 for (i = 0; i < stem_width; i++)
6331 gdk_draw_line (drawable, gc,
6332 location->x + i - offset, location->y,
6333 location->x + i - offset, location->y + location->height - 1);
6337 if (direction == GTK_TEXT_DIR_RTL)
6339 x = location->x - offset - 1;
6340 y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
6342 for (i = 0; i < arrow_width; i++)
6344 gdk_draw_line (drawable, gc,
6346 x, y + 2 * arrow_width - i - 1);
6350 else if (direction == GTK_TEXT_DIR_LTR)
6352 x = location->x + stem_width - offset;
6353 y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
6355 for (i = 0; i < arrow_width; i++)
6357 gdk_draw_line (drawable, gc,
6359 x, y + 2 * arrow_width - i - 1);