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, currently only
1457 * %GTK_WINDOW_EDGE_SOUTH_EAST is implemented
1458 * @x: the x origin of the rectangle in which to draw the resize grip
1459 * @y: the y origin of the rectangle in which to draw the resize grip
1460 * @width: the width of the rectangle in which to draw the resize grip
1461 * @height: the height of the rectangle in which to draw the resize grip
1463 * Draws a resize grip in the given rectangle on @window using the given
1466 * This function is deprecated, use gtk_paint_resize_grip() instead.
1469 gtk_draw_resize_grip (GtkStyle *style,
1471 GtkStateType state_type,
1478 g_return_if_fail (GTK_IS_STYLE (style));
1479 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
1481 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
1484 x, y, width, height);
1489 * gtk_style_set_background:
1490 * @style: a #GtkStyle
1491 * @window: a #GdkWindow
1492 * @state_type: a state
1494 * Sets the background of @window to the background color or pixmap
1495 * specified by @style for the given state.
1498 gtk_style_set_background (GtkStyle *style,
1500 GtkStateType state_type)
1502 g_return_if_fail (GTK_IS_STYLE (style));
1503 g_return_if_fail (window != NULL);
1505 GTK_STYLE_GET_CLASS (style)->set_background (style, window, state_type);
1508 /* Default functions */
1510 gtk_style_real_clone (GtkStyle *style)
1512 return GTK_STYLE (g_object_new (G_OBJECT_TYPE (style), NULL));
1516 gtk_style_real_copy (GtkStyle *style,
1521 for (i = 0; i < 5; i++)
1523 style->fg[i] = src->fg[i];
1524 style->bg[i] = src->bg[i];
1525 style->text[i] = src->text[i];
1526 style->base[i] = src->base[i];
1528 style->bg_pixmap[i] = src->bg_pixmap[i];
1531 if (style->private_font)
1532 gdk_font_unref (style->private_font);
1533 style->private_font = src->private_font;
1534 if (style->private_font)
1535 gdk_font_ref (style->private_font);
1537 if (style->font_desc)
1538 pango_font_description_free (style->font_desc);
1540 style->font_desc = pango_font_description_copy (src->font_desc);
1542 style->font_desc = NULL;
1544 style->xthickness = src->xthickness;
1545 style->ythickness = src->ythickness;
1547 if (style->rc_style)
1548 gtk_rc_style_unref (style->rc_style);
1549 style->rc_style = src->rc_style;
1551 gtk_rc_style_ref (src->rc_style);
1553 /* don't copy, just clear cache */
1554 clear_property_cache (style);
1558 gtk_style_real_init_from_rc (GtkStyle *style,
1559 GtkRcStyle *rc_style)
1563 /* cache _should_ be still empty */
1564 clear_property_cache (style);
1566 if (rc_style->font_desc)
1567 pango_font_description_merge (style->font_desc, rc_style->font_desc, TRUE);
1569 for (i = 0; i < 5; i++)
1571 if (rc_style->color_flags[i] & GTK_RC_FG)
1572 style->fg[i] = rc_style->fg[i];
1573 if (rc_style->color_flags[i] & GTK_RC_BG)
1574 style->bg[i] = rc_style->bg[i];
1575 if (rc_style->color_flags[i] & GTK_RC_TEXT)
1576 style->text[i] = rc_style->text[i];
1577 if (rc_style->color_flags[i] & GTK_RC_BASE)
1578 style->base[i] = rc_style->base[i];
1581 if (rc_style->xthickness >= 0)
1582 style->xthickness = rc_style->xthickness;
1583 if (rc_style->ythickness >= 0)
1584 style->ythickness = rc_style->ythickness;
1586 if (rc_style->icon_factories)
1590 style->icon_factories = g_slist_copy (rc_style->icon_factories);
1592 iter = style->icon_factories;
1593 while (iter != NULL)
1595 g_object_ref (iter->data);
1596 iter = g_slist_next (iter);
1602 style_property_values_cmp (gconstpointer bsearch_node1,
1603 gconstpointer bsearch_node2)
1605 const PropertyValue *val1 = bsearch_node1;
1606 const PropertyValue *val2 = bsearch_node2;
1608 if (val1->widget_type == val2->widget_type)
1609 return val1->pspec < val2->pspec ? -1 : val1->pspec == val2->pspec ? 0 : 1;
1611 return val1->widget_type < val2->widget_type ? -1 : 1;
1615 _gtk_style_peek_property_value (GtkStyle *style,
1618 GtkRcPropertyParser parser)
1620 PropertyValue *pcache, key = { 0, NULL, { 0, } };
1621 const GtkRcProperty *rcprop = NULL;
1624 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1625 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), NULL);
1626 g_return_val_if_fail (g_type_is_a (pspec->owner_type, GTK_TYPE_WIDGET), NULL);
1627 g_return_val_if_fail (g_type_is_a (widget_type, pspec->owner_type), NULL);
1629 key.widget_type = widget_type;
1632 /* need value cache array */
1633 if (!style->property_cache)
1634 style->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
1637 pcache = bsearch (&key,
1638 style->property_cache->data, style->property_cache->len,
1639 sizeof (PropertyValue), style_property_values_cmp);
1641 return &pcache->value;
1645 while (i < style->property_cache->len &&
1646 style_property_values_cmp (&key, &g_array_index (style->property_cache, PropertyValue, i)) >= 0)
1649 g_array_insert_val (style->property_cache, i, key);
1650 pcache = &g_array_index (style->property_cache, PropertyValue, i);
1652 /* cache miss, initialize value type, then set contents */
1653 g_param_spec_ref (pcache->pspec);
1654 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1656 /* value provided by rc style? */
1657 if (style->rc_style)
1659 GQuark prop_quark = g_quark_from_string (pspec->name);
1663 rcprop = _gtk_rc_style_lookup_rc_property (style->rc_style,
1664 g_type_qname (widget_type),
1668 widget_type = g_type_parent (widget_type);
1670 while (g_type_is_a (widget_type, pspec->owner_type));
1673 /* when supplied by rc style, we need to convert */
1674 if (rcprop && !_gtk_settings_parse_convert (parser, &rcprop->value,
1675 pspec, &pcache->value))
1677 gchar *contents = g_strdup_value_contents (&rcprop->value);
1679 g_message ("%s: failed to retrieve property `%s::%s' of type `%s' from rc file value \"%s\" of type `%s'",
1681 g_type_name (pspec->owner_type), pspec->name,
1682 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1684 G_VALUE_TYPE_NAME (&rcprop->value));
1686 rcprop = NULL; /* needs default */
1689 /* not supplied by rc style (or conversion failed), revert to default */
1691 g_param_value_set_default (pspec, &pcache->value);
1693 return &pcache->value;
1697 load_bg_image (GdkColormap *colormap,
1699 const gchar *filename)
1701 if (strcmp (filename, "<parent>") == 0)
1702 return (GdkPixmap*) GDK_PARENT_RELATIVE;
1705 return gdk_pixmap_colormap_create_from_xpm (NULL, colormap, NULL,
1712 gtk_style_real_realize (GtkStyle *style)
1714 GdkGCValues gc_values;
1715 GdkGCValuesMask gc_values_mask;
1719 for (i = 0; i < 5; i++)
1721 gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT);
1722 gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT);
1724 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
1725 style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
1726 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
1728 style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
1729 style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
1730 style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;
1733 style->black.red = 0x0000;
1734 style->black.green = 0x0000;
1735 style->black.blue = 0x0000;
1736 gdk_colormap_alloc_color (style->colormap, &style->black, FALSE, TRUE);
1738 style->white.red = 0xffff;
1739 style->white.green = 0xffff;
1740 style->white.blue = 0xffff;
1741 gdk_colormap_alloc_color (style->colormap, &style->white, FALSE, TRUE);
1743 gc_values_mask = GDK_GC_FOREGROUND;
1745 gc_values.foreground = style->black;
1746 style->black_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1748 gc_values.foreground = style->white;
1749 style->white_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1751 for (i = 0; i < 5; i++)
1753 if (style->rc_style && style->rc_style->bg_pixmap_name[i])
1754 style->bg_pixmap[i] = load_bg_image (style->colormap,
1756 style->rc_style->bg_pixmap_name[i]);
1758 if (!gdk_colormap_alloc_color (style->colormap, &style->fg[i], FALSE, TRUE))
1759 g_warning ("unable to allocate color: ( %d %d %d )",
1760 style->fg[i].red, style->fg[i].green, style->fg[i].blue);
1761 if (!gdk_colormap_alloc_color (style->colormap, &style->bg[i], FALSE, TRUE))
1762 g_warning ("unable to allocate color: ( %d %d %d )",
1763 style->bg[i].red, style->bg[i].green, style->bg[i].blue);
1764 if (!gdk_colormap_alloc_color (style->colormap, &style->light[i], FALSE, TRUE))
1765 g_warning ("unable to allocate color: ( %d %d %d )",
1766 style->light[i].red, style->light[i].green, style->light[i].blue);
1767 if (!gdk_colormap_alloc_color (style->colormap, &style->dark[i], FALSE, TRUE))
1768 g_warning ("unable to allocate color: ( %d %d %d )",
1769 style->dark[i].red, style->dark[i].green, style->dark[i].blue);
1770 if (!gdk_colormap_alloc_color (style->colormap, &style->mid[i], FALSE, TRUE))
1771 g_warning ("unable to allocate color: ( %d %d %d )",
1772 style->mid[i].red, style->mid[i].green, style->mid[i].blue);
1773 if (!gdk_colormap_alloc_color (style->colormap, &style->text[i], FALSE, TRUE))
1774 g_warning ("unable to allocate color: ( %d %d %d )",
1775 style->text[i].red, style->text[i].green, style->text[i].blue);
1776 if (!gdk_colormap_alloc_color (style->colormap, &style->base[i], FALSE, TRUE))
1777 g_warning ("unable to allocate color: ( %d %d %d )",
1778 style->base[i].red, style->base[i].green, style->base[i].blue);
1779 if (!gdk_colormap_alloc_color (style->colormap, &style->text_aa[i], FALSE, TRUE))
1780 g_warning ("unable to allocate color: ( %d %d %d )",
1781 style->text_aa[i].red, style->text_aa[i].green, style->text_aa[i].blue);
1783 gc_values.foreground = style->fg[i];
1784 style->fg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1786 gc_values.foreground = style->bg[i];
1787 style->bg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1789 gc_values.foreground = style->light[i];
1790 style->light_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1792 gc_values.foreground = style->dark[i];
1793 style->dark_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1795 gc_values.foreground = style->mid[i];
1796 style->mid_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1798 gc_values.foreground = style->text[i];
1799 style->text_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1801 gc_values.foreground = style->base[i];
1802 style->base_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1804 gc_values.foreground = style->text_aa[i];
1805 style->text_aa_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1810 gtk_style_real_unrealize (GtkStyle *style)
1814 gtk_gc_release (style->black_gc);
1815 gtk_gc_release (style->white_gc);
1817 for (i = 0; i < 5; i++)
1819 gtk_gc_release (style->fg_gc[i]);
1820 gtk_gc_release (style->bg_gc[i]);
1821 gtk_gc_release (style->light_gc[i]);
1822 gtk_gc_release (style->dark_gc[i]);
1823 gtk_gc_release (style->mid_gc[i]);
1824 gtk_gc_release (style->text_gc[i]);
1825 gtk_gc_release (style->base_gc[i]);
1826 gtk_gc_release (style->text_aa_gc[i]);
1828 if (style->bg_pixmap[i] && style->bg_pixmap[i] != (GdkPixmap*) GDK_PARENT_RELATIVE)
1829 g_object_unref (style->bg_pixmap[i]);
1832 gdk_colormap_free_colors (style->colormap, style->fg, 5);
1833 gdk_colormap_free_colors (style->colormap, style->bg, 5);
1834 gdk_colormap_free_colors (style->colormap, style->light, 5);
1835 gdk_colormap_free_colors (style->colormap, style->dark, 5);
1836 gdk_colormap_free_colors (style->colormap, style->mid, 5);
1837 gdk_colormap_free_colors (style->colormap, style->text, 5);
1838 gdk_colormap_free_colors (style->colormap, style->base, 5);
1839 gdk_colormap_free_colors (style->colormap, style->text_aa, 5);
1841 style_unrealize_cursor_gcs (style);
1845 gtk_style_real_set_background (GtkStyle *style,
1847 GtkStateType state_type)
1850 gint parent_relative;
1852 if (style->bg_pixmap[state_type])
1854 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1857 parent_relative = TRUE;
1861 pixmap = style->bg_pixmap[state_type];
1862 parent_relative = FALSE;
1865 gdk_window_set_back_pixmap (window, pixmap, parent_relative);
1868 gdk_window_set_background (window, &style->bg[state_type]);
1872 * gtk_style_render_icon:
1873 * @style: a #GtkStyle
1874 * @source: the #GtkIconSource specifying the icon to render
1875 * @direction: a text direction
1877 * @size: the size to render the icon at. A size of (GtkIconSize)-1
1878 * means render at the size of the source and don't scale.
1879 * @widget: the widget
1880 * @detail: a style detail
1881 * @returns: a newly-created #GdkPixbuf containing the rendered icon
1883 * Renders the icon specified by @source at the given @size
1884 * according to the given parameters and returns the result in a
1888 gtk_style_render_icon (GtkStyle *style,
1889 const GtkIconSource *source,
1890 GtkTextDirection direction,
1894 const gchar *detail)
1898 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1899 g_return_val_if_fail (GTK_STYLE_GET_CLASS (style)->render_icon != NULL, NULL);
1901 pixbuf = GTK_STYLE_GET_CLASS (style)->render_icon (style, source, direction, state,
1902 size, widget, detail);
1904 g_return_val_if_fail (pixbuf != NULL, NULL);
1909 /* Default functions */
1911 gtk_style_apply_default_background (GtkStyle *style,
1914 GtkStateType state_type,
1921 GdkRectangle new_rect, old_rect;
1927 old_rect.width = width;
1928 old_rect.height = height;
1930 if (!gdk_rectangle_intersect (area, &old_rect, &new_rect))
1937 new_rect.width = width;
1938 new_rect.height = height;
1941 if (!style->bg_pixmap[state_type] ||
1942 GDK_IS_PIXMAP (window) ||
1943 (!set_bg && style->bg_pixmap[state_type] != (GdkPixmap*) GDK_PARENT_RELATIVE))
1945 GdkGC *gc = style->bg_gc[state_type];
1947 if (style->bg_pixmap[state_type])
1949 gdk_gc_set_fill (gc, GDK_TILED);
1950 gdk_gc_set_tile (gc, style->bg_pixmap[state_type]);
1953 gdk_draw_rectangle (window, gc, TRUE,
1954 new_rect.x, new_rect.y, new_rect.width, new_rect.height);
1955 if (style->bg_pixmap[state_type])
1956 gdk_gc_set_fill (gc, GDK_SOLID);
1962 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1963 gdk_window_set_back_pixmap (window, NULL, TRUE);
1965 gdk_window_set_back_pixmap (window, style->bg_pixmap[state_type], FALSE);
1968 gdk_window_clear_area (window,
1969 new_rect.x, new_rect.y,
1970 new_rect.width, new_rect.height);
1975 scale_or_ref (GdkPixbuf *src,
1979 if (width == gdk_pixbuf_get_width (src) &&
1980 height == gdk_pixbuf_get_height (src))
1982 return g_object_ref (src);
1986 return gdk_pixbuf_scale_simple (src,
1988 GDK_INTERP_BILINEAR);
1993 gtk_default_render_icon (GtkStyle *style,
1994 const GtkIconSource *source,
1995 GtkTextDirection direction,
1999 const gchar *detail)
2005 GdkPixbuf *base_pixbuf;
2007 GtkSettings *settings;
2009 /* Oddly, style can be NULL in this function, because
2010 * GtkIconSet can be used without a style and if so
2011 * it uses this function.
2014 base_pixbuf = gtk_icon_source_get_pixbuf (source);
2016 g_return_val_if_fail (base_pixbuf != NULL, NULL);
2018 if (widget && gtk_widget_has_screen (widget))
2020 screen = gtk_widget_get_screen (widget);
2021 settings = gtk_settings_get_for_screen (screen);
2023 else if (style->colormap)
2025 screen = gdk_colormap_get_screen (style->colormap);
2026 settings = gtk_settings_get_for_screen (screen);
2030 settings = gtk_settings_get_default ();
2031 GTK_NOTE (MULTIHEAD,
2032 g_warning ("Using the default screen for gtk_default_render_icon()"));
2036 if (size != (GtkIconSize) -1 && !gtk_icon_size_lookup_for_settings (settings, size, &width, &height))
2038 g_warning (G_STRLOC ": invalid icon size '%d'", size);
2042 /* If the size was wildcarded, and we're allowed to scale, then scale; otherwise,
2045 if (size != (GtkIconSize)-1 && gtk_icon_source_get_size_wildcarded (source))
2046 scaled = scale_or_ref (base_pixbuf, width, height);
2048 scaled = g_object_ref (base_pixbuf);
2050 /* If the state was wildcarded, then generate a state. */
2051 if (gtk_icon_source_get_state_wildcarded (source))
2053 if (state == GTK_STATE_INSENSITIVE)
2055 stated = gdk_pixbuf_copy (scaled);
2057 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
2060 g_object_unref (scaled);
2062 else if (state == GTK_STATE_PRELIGHT)
2064 stated = gdk_pixbuf_copy (scaled);
2066 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
2069 g_object_unref (scaled);
2083 sanitize_size (GdkWindow *window,
2087 if ((*width == -1) && (*height == -1))
2088 gdk_drawable_get_size (window, width, height);
2089 else if (*width == -1)
2090 gdk_drawable_get_size (window, width, NULL);
2091 else if (*height == -1)
2092 gdk_drawable_get_size (window, NULL, height);
2096 get_indicator_for_screen (GdkDrawable *drawable,
2100 GdkScreen *screen = gdk_drawable_get_screen (drawable);
2104 tmp_list = indicator_parts[part].bmap_list;
2107 bitmap = tmp_list->data;
2109 if (gdk_drawable_get_screen (bitmap) == screen)
2112 tmp_list = tmp_list->next;
2115 bitmap = gdk_bitmap_create_from_data (drawable,
2116 (gchar *)indicator_parts[part].bits,
2117 INDICATOR_PART_SIZE, INDICATOR_PART_SIZE);
2118 indicator_parts[part].bmap_list = g_list_prepend (indicator_parts[part].bmap_list, bitmap);
2124 draw_part (GdkDrawable *drawable,
2132 gdk_gc_set_clip_rectangle (gc, area);
2134 gdk_gc_set_ts_origin (gc, x, y);
2135 gdk_gc_set_stipple (gc, get_indicator_for_screen (drawable, part));
2136 gdk_gc_set_fill (gc, GDK_STIPPLED);
2138 gdk_draw_rectangle (drawable, gc, TRUE, x, y, INDICATOR_PART_SIZE, INDICATOR_PART_SIZE);
2140 gdk_gc_set_fill (gc, GDK_SOLID);
2143 gdk_gc_set_clip_rectangle (gc, NULL);
2147 gtk_default_draw_hline (GtkStyle *style,
2149 GtkStateType state_type,
2152 const gchar *detail,
2157 gint thickness_light;
2158 gint thickness_dark;
2161 g_return_if_fail (GTK_IS_STYLE (style));
2162 g_return_if_fail (window != NULL);
2164 thickness_light = style->ythickness / 2;
2165 thickness_dark = style->ythickness - thickness_light;
2169 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
2170 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
2173 if (detail && !strcmp (detail, "label"))
2175 if (state_type == GTK_STATE_INSENSITIVE)
2176 gdk_draw_line (window, style->white_gc, x1 + 1, y + 1, x2 + 1, y + 1);
2177 gdk_draw_line (window, style->fg_gc[state_type], x1, y, x2, y);
2181 for (i = 0; i < thickness_dark; i++)
2183 gdk_draw_line (window, style->light_gc[state_type], x2 - i - 1, y + i, x2, y + i);
2184 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x2 - i - 1, y + i);
2187 y += thickness_dark;
2188 for (i = 0; i < thickness_light; i++)
2190 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x1 + thickness_light - i - 1, y + i);
2191 gdk_draw_line (window, style->light_gc[state_type], x1 + thickness_light - i - 1, y + i, x2, y + i);
2197 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
2198 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
2204 gtk_default_draw_vline (GtkStyle *style,
2206 GtkStateType state_type,
2209 const gchar *detail,
2214 gint thickness_light;
2215 gint thickness_dark;
2218 g_return_if_fail (GTK_IS_STYLE (style));
2219 g_return_if_fail (window != NULL);
2221 thickness_light = style->xthickness / 2;
2222 thickness_dark = style->xthickness - thickness_light;
2226 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
2227 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
2229 for (i = 0; i < thickness_dark; i++)
2231 gdk_draw_line (window, style->light_gc[state_type], x + i, y2 - i - 1, x + i, y2);
2232 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y2 - i - 1);
2235 x += thickness_dark;
2236 for (i = 0; i < thickness_light; i++)
2238 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y1 + thickness_light - i);
2239 gdk_draw_line (window, style->light_gc[state_type], x + i, y1 + thickness_light - i, x + i, y2);
2243 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
2244 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
2250 draw_thin_shadow (GtkStyle *style,
2261 sanitize_size (window, &width, &height);
2263 gc1 = style->light_gc[state];
2264 gc2 = style->dark_gc[state];
2268 gdk_gc_set_clip_rectangle (gc1, area);
2269 gdk_gc_set_clip_rectangle (gc2, area);
2272 gdk_draw_line (window, gc1,
2273 x, y + height - 1, x + width - 1, y + height - 1);
2274 gdk_draw_line (window, gc1,
2275 x + width - 1, y, x + width - 1, y + height - 1);
2277 gdk_draw_line (window, gc2,
2278 x, y, x + width - 2, y);
2279 gdk_draw_line (window, gc2,
2280 x, y, x, y + height - 2);
2284 gdk_gc_set_clip_rectangle (gc1, NULL);
2285 gdk_gc_set_clip_rectangle (gc2, NULL);
2291 * See http://bugzilla.gnome.org/show_bug.cgi?id=80229
2294 draw_spin_entry_shadow (GtkStyle *style,
2303 gint window_width, window_height;
2304 gboolean focus_inset;
2306 gdk_drawable_get_size (window, &window_width, &window_height);
2309 width = window_width;
2311 height = window_height;
2313 focus_inset = (width < window_width && height < window_height);
2317 gdk_gc_set_clip_rectangle (style->light_gc[state], area);
2318 gdk_gc_set_clip_rectangle (style->dark_gc[state], area);
2319 gdk_gc_set_clip_rectangle (style->black_gc, area);
2320 gdk_gc_set_clip_rectangle (style->bg_gc[state], area);
2321 gdk_gc_set_clip_rectangle (style->base_gc[state], area);
2324 gdk_draw_line (window, style->light_gc[state],
2325 x, y + height - 1, x + width - 1, y + height - 1);
2327 gdk_draw_line (window,
2328 style->base_gc[state],
2329 x + width - 1, y + 1, x + width - 1, y + height - 3);
2333 gdk_draw_line (window, style->bg_gc[state],
2334 x + 1, y + height - 2, x + width - 1, y + height - 2);
2335 gdk_draw_line (window,
2336 style->base_gc[state],
2337 x + width - 2, y + 1, x + width - 2, y + height - 3);
2339 gdk_draw_line (window, style->black_gc,
2340 x + 1, y + 1, x + width - 1, y + 1);
2341 gdk_draw_line (window, style->black_gc,
2342 x + 1, y + 1, x + 1, y + height - 2);
2345 gdk_draw_line (window, style->dark_gc[state],
2346 x, y, x + width - 1, y);
2347 gdk_draw_line (window, style->dark_gc[state],
2348 x, y, x, y + height - 1);
2352 gdk_gc_set_clip_rectangle (style->light_gc[state], NULL);
2353 gdk_gc_set_clip_rectangle (style->dark_gc[state], NULL);
2354 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2355 gdk_gc_set_clip_rectangle (style->bg_gc[state], NULL);
2356 gdk_gc_set_clip_rectangle (style->base_gc[state], NULL);
2362 draw_spinbutton_shadow (GtkStyle *style,
2365 GtkTextDirection direction,
2372 sanitize_size (window, &width, &height);
2376 gdk_gc_set_clip_rectangle (style->black_gc, area);
2377 gdk_gc_set_clip_rectangle (style->bg_gc[state], area);
2378 gdk_gc_set_clip_rectangle (style->dark_gc[state], area);
2379 gdk_gc_set_clip_rectangle (style->light_gc[state], area);
2382 if (direction == GTK_TEXT_DIR_LTR)
2384 gdk_draw_line (window, style->dark_gc[state],
2385 x, y, x + width - 1, y);
2386 gdk_draw_line (window, style->black_gc,
2387 x, y + 1, x + width - 2, y + 1);
2388 gdk_draw_line (window, style->black_gc,
2389 x + width - 2, y + 2, x + width - 2, y + height - 3);
2390 gdk_draw_line (window, style->light_gc[state],
2391 x + width - 1, y + 1, x + width - 1, y + height - 2);
2392 gdk_draw_line (window, style->light_gc[state],
2393 x, y + height - 1, x + width - 1, y + height - 1);
2394 gdk_draw_line (window, style->bg_gc[state],
2395 x, y + height - 2, x + width - 2, y + height - 2);
2396 gdk_draw_line (window, style->black_gc,
2397 x, y + 2, x, y + height - 3);
2401 gdk_draw_line (window, style->dark_gc[state],
2402 x, y, x + width - 1, y);
2403 gdk_draw_line (window, style->dark_gc[state],
2404 x, y + 1, x, y + height - 1);
2405 gdk_draw_line (window, style->black_gc,
2406 x + 1, y + 1, x + width - 1, y + 1);
2407 gdk_draw_line (window, style->black_gc,
2408 x + 1, y + 2, x + 1, y + height - 2);
2409 gdk_draw_line (window, style->black_gc,
2410 x + width - 1, y + 2, x + width - 1, y + height - 3);
2411 gdk_draw_line (window, style->light_gc[state],
2412 x + 1, y + height - 1, x + width - 1, y + height - 1);
2413 gdk_draw_line (window, style->bg_gc[state],
2414 x + 2, y + height - 2, x + width - 1, y + height - 2);
2419 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2420 gdk_gc_set_clip_rectangle (style->bg_gc[state], NULL);
2421 gdk_gc_set_clip_rectangle (style->dark_gc[state], NULL);
2422 gdk_gc_set_clip_rectangle (style->light_gc[state], NULL);
2427 gtk_default_draw_shadow (GtkStyle *style,
2429 GtkStateType state_type,
2430 GtkShadowType shadow_type,
2433 const gchar *detail,
2441 gint thickness_light;
2442 gint thickness_dark;
2445 g_return_if_fail (GTK_IS_STYLE (style));
2446 g_return_if_fail (window != NULL);
2448 if (shadow_type == GTK_SHADOW_IN)
2450 if (detail && (strcmp (detail, "buttondefault") == 0))
2452 sanitize_size (window, &width, &height);
2454 gdk_draw_rectangle (window, style->black_gc, FALSE,
2455 x, y, width - 1, height - 1);
2459 if (detail && strcmp (detail, "trough") == 0)
2461 draw_thin_shadow (style, window, state_type, area,
2462 x, y, width, height);
2465 if (widget && GTK_IS_SPIN_BUTTON (widget) &&
2466 detail && strcmp (detail, "spinbutton") == 0)
2468 draw_spinbutton_shadow (style, window, state_type,
2469 gtk_widget_get_direction (widget), area, x, y, width, height);
2475 sanitize_size (window, &width, &height);
2477 switch (shadow_type)
2479 case GTK_SHADOW_NONE:
2482 case GTK_SHADOW_ETCHED_IN:
2483 gc1 = style->light_gc[state_type];
2484 gc2 = style->dark_gc[state_type];
2486 case GTK_SHADOW_OUT:
2487 case GTK_SHADOW_ETCHED_OUT:
2488 gc1 = style->dark_gc[state_type];
2489 gc2 = style->light_gc[state_type];
2495 gdk_gc_set_clip_rectangle (gc1, area);
2496 gdk_gc_set_clip_rectangle (gc2, area);
2497 if (shadow_type == GTK_SHADOW_IN ||
2498 shadow_type == GTK_SHADOW_OUT)
2500 gdk_gc_set_clip_rectangle (style->black_gc, area);
2501 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2505 switch (shadow_type)
2507 case GTK_SHADOW_NONE:
2511 /* Light around right and bottom edge */
2513 if (style->ythickness > 0)
2514 gdk_draw_line (window, gc1,
2515 x, y + height - 1, x + width - 1, y + height - 1);
2516 if (style->xthickness > 0)
2517 gdk_draw_line (window, gc1,
2518 x + width - 1, y, x + width - 1, y + height - 1);
2520 if (style->ythickness > 1)
2521 gdk_draw_line (window, style->bg_gc[state_type],
2522 x + 1, y + height - 2, x + width - 2, y + height - 2);
2523 if (style->xthickness > 1)
2524 gdk_draw_line (window, style->bg_gc[state_type],
2525 x + width - 2, y + 1, x + width - 2, y + height - 2);
2527 /* Dark around left and top */
2529 if (style->ythickness > 1)
2530 gdk_draw_line (window, style->black_gc,
2531 x + 1, y + 1, x + width - 2, y + 1);
2532 if (style->xthickness > 1)
2533 gdk_draw_line (window, style->black_gc,
2534 x + 1, y + 1, x + 1, y + height - 2);
2536 if (style->ythickness > 0)
2537 gdk_draw_line (window, gc2,
2538 x, y, x + width - 1, y);
2539 if (style->xthickness > 0)
2540 gdk_draw_line (window, gc2,
2541 x, y, x, y + height - 1);
2544 case GTK_SHADOW_OUT:
2545 /* Dark around right and bottom edge */
2547 if (style->ythickness > 0)
2549 if (style->ythickness > 1)
2551 gdk_draw_line (window, gc1,
2552 x + 1, y + height - 2, x + width - 2, y + height - 2);
2553 gdk_draw_line (window, style->black_gc,
2554 x, y + height - 1, x + width - 1, y + height - 1);
2558 gdk_draw_line (window, gc1,
2559 x + 1, y + height - 1, x + width - 1, y + height - 1);
2563 if (style->xthickness > 0)
2565 if (style->xthickness > 1)
2567 gdk_draw_line (window, gc1,
2568 x + width - 2, y + 1, x + width - 2, y + height - 2);
2570 gdk_draw_line (window, style->black_gc,
2571 x + width - 1, y, x + width - 1, y + height - 1);
2575 gdk_draw_line (window, gc1,
2576 x + width - 1, y + 1, x + width - 1, y + height - 1);
2580 /* Light around top and left */
2582 if (style->ythickness > 0)
2583 gdk_draw_line (window, gc2,
2584 x, y, x + width - 2, y);
2585 if (style->xthickness > 0)
2586 gdk_draw_line (window, gc2,
2587 x, y, x, y + height - 2);
2589 if (style->ythickness > 1)
2590 gdk_draw_line (window, style->bg_gc[state_type],
2591 x + 1, y + 1, x + width - 3, y + 1);
2592 if (style->xthickness > 1)
2593 gdk_draw_line (window, style->bg_gc[state_type],
2594 x + 1, y + 1, x + 1, y + height - 3);
2597 case GTK_SHADOW_ETCHED_IN:
2598 case GTK_SHADOW_ETCHED_OUT:
2599 if (style->xthickness > 0)
2601 if (style->xthickness > 1)
2603 thickness_light = 1;
2606 for (i = 0; i < thickness_dark; i++)
2608 gdk_draw_line (window, gc1,
2612 y + height - i - 1);
2613 gdk_draw_line (window, gc2,
2617 y + height - i - 2);
2620 for (i = 0; i < thickness_light; i++)
2622 gdk_draw_line (window, gc1,
2623 x + thickness_dark + i,
2624 y + thickness_dark + i,
2625 x + thickness_dark + i,
2626 y + height - thickness_dark - i - 1);
2627 gdk_draw_line (window, gc2,
2628 x + width - thickness_light - i - 1,
2629 y + thickness_dark + i,
2630 x + width - thickness_light - i - 1,
2631 y + height - thickness_light - 1);
2636 gdk_draw_line (window,
2637 style->dark_gc[state_type],
2638 x, y, x, y + height);
2639 gdk_draw_line (window,
2640 style->dark_gc[state_type],
2641 x + width, y, x + width, y + height);
2645 if (style->ythickness > 0)
2647 if (style->ythickness > 1)
2649 thickness_light = 1;
2652 for (i = 0; i < thickness_dark; i++)
2654 gdk_draw_line (window, gc1,
2658 y + height - i - 1);
2660 gdk_draw_line (window, gc2,
2667 for (i = 0; i < thickness_light; i++)
2669 gdk_draw_line (window, gc1,
2670 x + thickness_dark + i,
2671 y + thickness_dark + i,
2672 x + width - thickness_dark - i - 2,
2673 y + thickness_dark + i);
2675 gdk_draw_line (window, gc2,
2676 x + thickness_dark + i,
2677 y + height - thickness_light - i - 1,
2678 x + width - thickness_light - 1,
2679 y + height - thickness_light - i - 1);
2684 gdk_draw_line (window,
2685 style->dark_gc[state_type],
2686 x, y, x + width, y);
2687 gdk_draw_line (window,
2688 style->dark_gc[state_type],
2689 x, y + height, x + width, y + height);
2696 if (shadow_type == GTK_SHADOW_IN &&
2697 widget && GTK_IS_SPIN_BUTTON (widget) &&
2698 detail && strcmp (detail, "entry") == 0)
2700 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
2702 gdk_draw_line (window,
2703 style->base_gc[state_type],
2704 x + width - 1, y + 2,
2705 x + width - 1, y + height - 3);
2706 gdk_draw_line (window,
2707 style->base_gc[state_type],
2708 x + width - 2, y + 2,
2709 x + width - 2, y + height - 3);
2710 gdk_draw_point (window,
2712 x + width - 1, y + 1);
2713 gdk_draw_point (window,
2714 style->bg_gc[state_type],
2715 x + width - 1, y + height - 2);
2719 gdk_draw_line (window,
2720 style->base_gc[state_type],
2723 gdk_draw_line (window,
2724 style->base_gc[state_type],
2726 x + 1, y + height - 3);
2727 gdk_draw_point (window,
2730 gdk_draw_line (window,
2731 style->bg_gc[state_type],
2733 x + 1, y + height - 2);
2734 gdk_draw_point (window,
2735 style->light_gc[state_type],
2743 gdk_gc_set_clip_rectangle (gc1, NULL);
2744 gdk_gc_set_clip_rectangle (gc2, NULL);
2745 if (shadow_type == GTK_SHADOW_IN ||
2746 shadow_type == GTK_SHADOW_OUT)
2748 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2749 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2755 gtk_default_draw_polygon (GtkStyle *style,
2757 GtkStateType state_type,
2758 GtkShadowType shadow_type,
2761 const gchar *detail,
2766 static const gdouble pi_over_4 = G_PI_4;
2767 static const gdouble pi_3_over_4 = G_PI_4 * 3;
2777 g_return_if_fail (GTK_IS_STYLE (style));
2778 g_return_if_fail (window != NULL);
2779 g_return_if_fail (points != NULL);
2781 switch (shadow_type)
2784 gc1 = style->bg_gc[state_type];
2785 gc2 = style->dark_gc[state_type];
2786 gc3 = style->light_gc[state_type];
2787 gc4 = style->black_gc;
2789 case GTK_SHADOW_ETCHED_IN:
2790 gc1 = style->light_gc[state_type];
2791 gc2 = style->dark_gc[state_type];
2792 gc3 = style->dark_gc[state_type];
2793 gc4 = style->light_gc[state_type];
2795 case GTK_SHADOW_OUT:
2796 gc1 = style->dark_gc[state_type];
2797 gc2 = style->light_gc[state_type];
2798 gc3 = style->black_gc;
2799 gc4 = style->bg_gc[state_type];
2801 case GTK_SHADOW_ETCHED_OUT:
2802 gc1 = style->dark_gc[state_type];
2803 gc2 = style->light_gc[state_type];
2804 gc3 = style->light_gc[state_type];
2805 gc4 = style->dark_gc[state_type];
2813 gdk_gc_set_clip_rectangle (gc1, area);
2814 gdk_gc_set_clip_rectangle (gc2, area);
2815 gdk_gc_set_clip_rectangle (gc3, area);
2816 gdk_gc_set_clip_rectangle (gc4, area);
2820 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, npoints);
2824 for (i = 0; i < npoints; i++)
2826 if ((points[i].x == points[i+1].x) &&
2827 (points[i].y == points[i+1].y))
2833 angle = atan2 (points[i+1].y - points[i].y,
2834 points[i+1].x - points[i].x);
2837 if ((angle > -pi_3_over_4) && (angle < pi_over_4))
2839 if (angle > -pi_over_4)
2850 gdk_draw_line (window, gc1,
2851 points[i].x-xadjust, points[i].y-yadjust,
2852 points[i+1].x-xadjust, points[i+1].y-yadjust);
2853 gdk_draw_line (window, gc3,
2854 points[i].x, points[i].y,
2855 points[i+1].x, points[i+1].y);
2859 if ((angle < -pi_3_over_4) || (angle > pi_3_over_4))
2870 gdk_draw_line (window, gc4,
2871 points[i].x+xadjust, points[i].y+yadjust,
2872 points[i+1].x+xadjust, points[i+1].y+yadjust);
2873 gdk_draw_line (window, gc2,
2874 points[i].x, points[i].y,
2875 points[i+1].x, points[i+1].y);
2881 gdk_gc_set_clip_rectangle (gc1, NULL);
2882 gdk_gc_set_clip_rectangle (gc2, NULL);
2883 gdk_gc_set_clip_rectangle (gc3, NULL);
2884 gdk_gc_set_clip_rectangle (gc4, NULL);
2889 draw_arrow (GdkWindow *window,
2892 GtkArrowType arrow_type,
2901 gdk_gc_set_clip_rectangle (gc, area);
2903 if (arrow_type == GTK_ARROW_DOWN)
2905 for (i = 0, j = 0; i < height; i++, j++)
2906 gdk_draw_line (window, gc, x + j, y + i, x + width - j - 1, y + i);
2908 else if (arrow_type == GTK_ARROW_UP)
2910 for (i = height - 1, j = 0; i >= 0; i--, j++)
2911 gdk_draw_line (window, gc, x + j, y + i, x + width - j - 1, y + i);
2913 else if (arrow_type == GTK_ARROW_LEFT)
2915 for (i = width - 1, j = 0; i >= 0; i--, j++)
2916 gdk_draw_line (window, gc, x + i, y + j, x + i, y + height - j - 1);
2918 else if (arrow_type == GTK_ARROW_RIGHT)
2920 for (i = 0, j = 0; i < width; i++, j++)
2921 gdk_draw_line (window, gc, x + i, y + j, x + i, y + height - j - 1);
2925 gdk_gc_set_clip_rectangle (gc, NULL);
2929 calculate_arrow_geometry (GtkArrowType arrow_type,
2941 case GTK_ARROW_DOWN:
2951 if (arrow_type == GTK_ARROW_DOWN)
2953 if (*height % 2 == 1 || h % 2 == 0)
2958 if (*height % 2 == 0 || h % 2 == 0)
2963 case GTK_ARROW_RIGHT:
2964 case GTK_ARROW_LEFT:
2974 if (arrow_type == GTK_ARROW_RIGHT)
2976 if (*width % 2 == 1 || w % 2 == 0)
2981 if (*width % 2 == 0 || w % 2 == 0)
2987 /* should not be reached */
2991 *x += (*width - w) / 2;
2992 *y += (*height - h) / 2;
2998 gtk_default_draw_arrow (GtkStyle *style,
3001 GtkShadowType shadow,
3004 const gchar *detail,
3005 GtkArrowType arrow_type,
3012 gint original_width, original_x;
3014 sanitize_size (window, &width, &height);
3016 original_width = width;
3019 calculate_arrow_geometry (arrow_type, &x, &y, &width, &height);
3021 if (detail && strcmp (detail, "menuitem") == 0
3022 && gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
3023 x = original_x + original_width - width;
3025 if (state == GTK_STATE_INSENSITIVE)
3026 draw_arrow (window, style->white_gc, area, arrow_type,
3027 x + 1, y + 1, width, height);
3028 draw_arrow (window, style->fg_gc[state], area, arrow_type,
3029 x, y, width, height);
3033 gtk_default_draw_diamond (GtkStyle *style,
3035 GtkStateType state_type,
3036 GtkShadowType shadow_type,
3039 const gchar *detail,
3047 GdkGC *outer_nw = NULL;
3048 GdkGC *outer_ne = NULL;
3049 GdkGC *outer_sw = NULL;
3050 GdkGC *outer_se = NULL;
3051 GdkGC *middle_nw = NULL;
3052 GdkGC *middle_ne = NULL;
3053 GdkGC *middle_sw = NULL;
3054 GdkGC *middle_se = NULL;
3055 GdkGC *inner_nw = NULL;
3056 GdkGC *inner_ne = NULL;
3057 GdkGC *inner_sw = NULL;
3058 GdkGC *inner_se = NULL;
3060 g_return_if_fail (GTK_IS_STYLE (style));
3061 g_return_if_fail (window != NULL);
3063 sanitize_size (window, &width, &height);
3065 half_width = width / 2;
3066 half_height = height / 2;
3070 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
3071 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
3072 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
3073 gdk_gc_set_clip_rectangle (style->black_gc, area);
3076 switch (shadow_type)
3079 inner_sw = inner_se = style->bg_gc[state_type];
3080 middle_sw = middle_se = style->light_gc[state_type];
3081 outer_sw = outer_se = style->light_gc[state_type];
3082 inner_nw = inner_ne = style->black_gc;
3083 middle_nw = middle_ne = style->dark_gc[state_type];
3084 outer_nw = outer_ne = style->dark_gc[state_type];
3087 case GTK_SHADOW_OUT:
3088 inner_sw = inner_se = style->dark_gc[state_type];
3089 middle_sw = middle_se = style->dark_gc[state_type];
3090 outer_sw = outer_se = style->black_gc;
3091 inner_nw = inner_ne = style->bg_gc[state_type];
3092 middle_nw = middle_ne = style->light_gc[state_type];
3093 outer_nw = outer_ne = style->light_gc[state_type];
3096 case GTK_SHADOW_ETCHED_IN:
3097 inner_sw = inner_se = style->bg_gc[state_type];
3098 middle_sw = middle_se = style->dark_gc[state_type];
3099 outer_sw = outer_se = style->light_gc[state_type];
3100 inner_nw = inner_ne = style->bg_gc[state_type];
3101 middle_nw = middle_ne = style->light_gc[state_type];
3102 outer_nw = outer_ne = style->dark_gc[state_type];
3105 case GTK_SHADOW_ETCHED_OUT:
3106 inner_sw = inner_se = style->bg_gc[state_type];
3107 middle_sw = middle_se = style->light_gc[state_type];
3108 outer_sw = outer_se = style->dark_gc[state_type];
3109 inner_nw = inner_ne = style->bg_gc[state_type];
3110 middle_nw = middle_ne = style->dark_gc[state_type];
3111 outer_nw = outer_ne = style->light_gc[state_type];
3121 gdk_draw_line (window, inner_sw,
3122 x + 2, y + half_height,
3123 x + half_width, y + height - 2);
3124 gdk_draw_line (window, inner_se,
3125 x + half_width, y + height - 2,
3126 x + width - 2, y + half_height);
3127 gdk_draw_line (window, middle_sw,
3128 x + 1, y + half_height,
3129 x + half_width, y + height - 1);
3130 gdk_draw_line (window, middle_se,
3131 x + half_width, y + height - 1,
3132 x + width - 1, y + half_height);
3133 gdk_draw_line (window, outer_sw,
3135 x + half_width, y + height);
3136 gdk_draw_line (window, outer_se,
3137 x + half_width, y + height,
3138 x + width, y + half_height);
3140 gdk_draw_line (window, inner_nw,
3141 x + 2, y + half_height,
3142 x + half_width, y + 2);
3143 gdk_draw_line (window, inner_ne,
3144 x + half_width, y + 2,
3145 x + width - 2, y + half_height);
3146 gdk_draw_line (window, middle_nw,
3147 x + 1, y + half_height,
3148 x + half_width, y + 1);
3149 gdk_draw_line (window, middle_ne,
3150 x + half_width, y + 1,
3151 x + width - 1, y + half_height);
3152 gdk_draw_line (window, outer_nw,
3155 gdk_draw_line (window, outer_ne,
3157 x + width, y + half_height);
3162 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
3163 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
3164 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
3165 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
3170 gtk_default_draw_string (GtkStyle *style,
3172 GtkStateType state_type,
3175 const gchar *detail,
3178 const gchar *string)
3180 GdkDisplay *display;
3182 g_return_if_fail (GTK_IS_STYLE (style));
3183 g_return_if_fail (window != NULL);
3185 display = gdk_drawable_get_display (window);
3189 gdk_gc_set_clip_rectangle (style->white_gc, area);
3190 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], area);
3193 if (state_type == GTK_STATE_INSENSITIVE)
3194 gdk_draw_string (window,
3195 gtk_style_get_font_internal (style),
3196 style->white_gc, x + 1, y + 1, string);
3198 gdk_draw_string (window,
3199 gtk_style_get_font_internal (style),
3200 style->fg_gc[state_type], x, y, string);
3204 gdk_gc_set_clip_rectangle (style->white_gc, NULL);
3205 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], NULL);
3210 option_menu_get_props (GtkWidget *widget,
3211 GtkRequisition *indicator_size,
3212 GtkBorder *indicator_spacing)
3214 GtkRequisition *tmp_size = NULL;
3215 GtkBorder *tmp_spacing = NULL;
3218 gtk_widget_style_get (widget,
3219 "indicator_size", &tmp_size,
3220 "indicator_spacing", &tmp_spacing,
3225 *indicator_size = *tmp_size;
3229 *indicator_size = default_option_indicator_size;
3233 *indicator_spacing = *tmp_spacing;
3234 g_free (tmp_spacing);
3237 *indicator_spacing = default_option_indicator_spacing;
3241 gtk_default_draw_box (GtkStyle *style,
3243 GtkStateType state_type,
3244 GtkShadowType shadow_type,
3247 const gchar *detail,
3253 gboolean is_spinbutton_box = FALSE;
3255 g_return_if_fail (GTK_IS_STYLE (style));
3256 g_return_if_fail (window != NULL);
3258 sanitize_size (window, &width, &height);
3260 if (widget && GTK_IS_SPIN_BUTTON (widget) && detail)
3262 if (strcmp (detail, "spinbutton_up") == 0)
3268 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3273 is_spinbutton_box = TRUE;
3275 else if (strcmp (detail, "spinbutton_down") == 0)
3280 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3285 is_spinbutton_box = TRUE;
3289 if (!style->bg_pixmap[state_type] ||
3290 GDK_IS_PIXMAP (window))
3293 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
3295 gdk_draw_rectangle (window, style->bg_gc[state_type], TRUE,
3296 x, y, width, height);
3298 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
3301 gtk_style_apply_default_background (style, window,
3302 widget && !GTK_WIDGET_NO_WINDOW (widget),
3303 state_type, area, x, y, width, height);
3305 if (is_spinbutton_box)
3310 lower_gc = style->dark_gc[state_type];
3311 if (shadow_type == GTK_SHADOW_OUT)
3312 upper_gc = style->light_gc[state_type];
3314 upper_gc = style->dark_gc[state_type];
3318 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
3319 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
3322 gdk_draw_line (window, upper_gc, x, y, x + width - 1, y);
3323 gdk_draw_line (window, lower_gc, x, y + height - 1, x + width - 1, y + height - 1);
3327 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
3328 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
3333 gtk_paint_shadow (style, window, state_type, shadow_type, area, widget, detail,
3334 x, y, width, height);
3336 if (detail && strcmp (detail, "optionmenu") == 0)
3338 GtkRequisition indicator_size;
3339 GtkBorder indicator_spacing;
3342 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
3344 sanitize_size (window, &width, &height);
3346 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3347 vline_x = x + indicator_size.width + indicator_spacing.left + indicator_spacing.right;
3349 vline_x = x + width - (indicator_size.width + indicator_spacing.left + indicator_spacing.right) - style->xthickness;
3351 gtk_paint_vline (style, window, state_type, area, widget,
3353 y + style->ythickness + 1,
3354 y + height - style->ythickness - 3,
3360 get_darkened_gc (GdkWindow *window,
3364 GdkColor src = *color;
3365 GdkColor shaded = *color;
3368 gc = gdk_gc_new (window);
3370 while (darken_count)
3372 gtk_style_shade (&src, &shaded, 0.93);
3377 gdk_gc_set_rgb_fg_color (gc, &shaded);
3383 gtk_default_draw_flat_box (GtkStyle *style,
3385 GtkStateType state_type,
3386 GtkShadowType shadow_type,
3389 const gchar *detail,
3396 GdkGC *freeme = NULL;
3398 g_return_if_fail (GTK_IS_STYLE (style));
3399 g_return_if_fail (window != NULL);
3401 sanitize_size (window, &width, &height);
3405 if (state_type == GTK_STATE_SELECTED)
3407 if (!strcmp ("text", detail))
3408 gc1 = style->bg_gc[GTK_STATE_SELECTED];
3409 else if (!strncmp ("cell_even", detail, strlen ("cell_even")) ||
3410 !strncmp ("cell_odd", detail, strlen ("cell_odd")))
3412 /* This has to be really broken; alex made me do it. -jrb */
3413 if (GTK_WIDGET_HAS_FOCUS (widget))
3414 gc1 = style->base_gc[state_type];
3416 gc1 = style->base_gc[GTK_STATE_ACTIVE];
3420 gc1 = style->bg_gc[state_type];
3425 if (!strcmp ("viewportbin", detail))
3426 gc1 = style->bg_gc[GTK_STATE_NORMAL];
3427 else if (!strcmp ("entry_bg", detail))
3428 gc1 = style->base_gc[state_type];
3430 /* For trees: even rows are base color, odd rows are a shade of
3431 * the base color, the sort column is a shade of the original color
3435 else if (!strcmp ("cell_even", detail) ||
3436 !strcmp ("cell_odd", detail) ||
3437 !strcmp ("cell_even_ruled", detail))
3439 GdkColor *color = NULL;
3441 gtk_widget_style_get (widget,
3442 "even_row_color", &color,
3447 freeme = get_darkened_gc (window, color, 0);
3450 gdk_color_free (color);
3453 gc1 = style->base_gc[state_type];
3455 else if (!strcmp ("cell_odd_ruled", detail))
3459 gtk_widget_style_get (widget,
3460 "odd_row_color", &color,
3465 freeme = get_darkened_gc (window, color, 0);
3468 gdk_color_free (color);
3472 gtk_widget_style_get (widget,
3473 "even_row_color", &color,
3478 freeme = get_darkened_gc (window, color, 1);
3479 gdk_color_free (color);
3482 freeme = get_darkened_gc (window, &style->base[state_type], 1);
3486 else if (!strcmp ("cell_even_sorted", detail) ||
3487 !strcmp ("cell_odd_sorted", detail) ||
3488 !strcmp ("cell_even_ruled_sorted", detail))
3490 GdkColor *color = NULL;
3492 if (!strcmp ("cell_odd_sorted", detail))
3493 gtk_widget_style_get (widget,
3494 "odd_row_color", &color,
3497 gtk_widget_style_get (widget,
3498 "even_row_color", &color,
3503 freeme = get_darkened_gc (window, color, 1);
3506 gdk_color_free (color);
3510 freeme = get_darkened_gc (window, &style->base[state_type], 1);
3514 else if (!strcmp ("cell_odd_ruled_sorted", detail))
3516 GdkColor *color = NULL;
3518 gtk_widget_style_get (widget,
3519 "odd_row_color", &color,
3524 freeme = get_darkened_gc (window, color, 1);
3527 gdk_color_free (color);
3531 gtk_widget_style_get (widget,
3532 "even_row_color", &color,
3537 freeme = get_darkened_gc (window, color, 2);
3538 gdk_color_free (color);
3541 freeme = get_darkened_gc (window, &style->base[state_type], 2);
3546 gc1 = style->bg_gc[state_type];
3550 gc1 = style->bg_gc[state_type];
3552 if (!style->bg_pixmap[state_type] || gc1 != style->bg_gc[state_type] ||
3553 GDK_IS_PIXMAP (window))
3556 gdk_gc_set_clip_rectangle (gc1, area);
3558 gdk_draw_rectangle (window, gc1, TRUE,
3559 x, y, width, height);
3561 if (detail && !strcmp ("tooltip", detail))
3562 gdk_draw_rectangle (window, style->black_gc, FALSE,
3563 x, y, width - 1, height - 1);
3566 gdk_gc_set_clip_rectangle (gc1, NULL);
3569 gtk_style_apply_default_background (style, window,
3570 widget && !GTK_WIDGET_NO_WINDOW (widget),
3571 state_type, area, x, y, width, height);
3575 g_object_unref (freeme);
3579 create_aa_gc (GdkWindow *window, GtkStyle *style, GtkStateType state_type)
3582 GdkGC *gc = gdk_gc_new (window);
3584 aa_color.red = (style->fg[state_type].red + style->bg[state_type].red) / 2;
3585 aa_color.green = (style->fg[state_type].green + style->bg[state_type].green) / 2;
3586 aa_color.blue = (style->fg[state_type].blue + style->bg[state_type].blue) / 2;
3588 gdk_gc_set_rgb_fg_color (gc, &aa_color);
3594 gtk_default_draw_check (GtkStyle *style,
3596 GtkStateType state_type,
3597 GtkShadowType shadow_type,
3600 const gchar *detail,
3606 if (detail && strcmp (detail, "cellcheck") == 0)
3608 gdk_draw_rectangle (window,
3609 widget->style->base_gc[state_type],
3613 gdk_draw_rectangle (window,
3614 widget->style->text_gc[state_type],
3619 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3620 y -= (((1 + INDICATOR_PART_SIZE - height) / 2) - 1);
3621 if (shadow_type == GTK_SHADOW_IN)
3623 draw_part (window, style->text_gc[state_type], area, x, y, CHECK_TEXT);
3624 draw_part (window, style->text_aa_gc[state_type], area, x, y, CHECK_AA);
3629 GdkGC *free_me = NULL;
3635 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3636 y -= (1 + INDICATOR_PART_SIZE - height) / 2;
3638 if (strcmp (detail, "check") == 0) /* Menu item */
3640 text_gc = style->fg_gc[state_type];
3641 base_gc = style->bg_gc[state_type];
3642 aa_gc = free_me = create_aa_gc (window, style, state_type);
3646 if (state_type == GTK_STATE_ACTIVE)
3648 text_gc = style->fg_gc[state_type];
3649 base_gc = style->bg_gc[state_type];
3650 aa_gc = free_me = create_aa_gc (window, style, state_type);
3654 text_gc = style->text_gc[state_type];
3655 base_gc = style->base_gc[state_type];
3656 aa_gc = style->text_aa_gc[state_type];
3659 draw_part (window, base_gc, area, x, y, CHECK_BASE);
3660 draw_part (window, style->black_gc, area, x, y, CHECK_BLACK);
3661 draw_part (window, style->dark_gc[state_type], area, x, y, CHECK_DARK);
3662 draw_part (window, style->mid_gc[state_type], area, x, y, CHECK_MID);
3663 draw_part (window, style->light_gc[state_type], area, x, y, CHECK_LIGHT);
3666 if (shadow_type == GTK_SHADOW_IN)
3668 draw_part (window, text_gc, area, x, y, CHECK_TEXT);
3669 draw_part (window, aa_gc, area, x, y, CHECK_AA);
3671 else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
3673 draw_part (window, text_gc, area, x, y, CHECK_INCONSISTENT_TEXT);
3677 g_object_unref (G_OBJECT (free_me));
3682 gtk_default_draw_option (GtkStyle *style,
3684 GtkStateType state_type,
3685 GtkShadowType shadow_type,
3688 const gchar *detail,
3694 if (detail && strcmp (detail, "cellradio") == 0)
3696 gdk_draw_arc (window,
3697 widget->style->fg_gc[state_type],
3704 if (shadow_type == GTK_SHADOW_IN)
3706 gdk_draw_arc (window,
3707 widget->style->fg_gc[state_type],
3718 GdkGC *free_me = NULL;
3724 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3725 y -= (1 + INDICATOR_PART_SIZE - height) / 2;
3727 if (strcmp (detail, "option") == 0) /* Menu item */
3729 text_gc = style->fg_gc[state_type];
3730 base_gc = style->bg_gc[state_type];
3731 aa_gc = free_me = create_aa_gc (window, style, state_type);
3735 if (state_type == GTK_STATE_ACTIVE)
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 text_gc = style->text_gc[state_type];
3744 base_gc = style->base_gc[state_type];
3745 aa_gc = style->text_aa_gc[state_type];
3748 draw_part (window, base_gc, area, x, y, RADIO_BASE);
3749 draw_part (window, style->black_gc, area, x, y, RADIO_BLACK);
3750 draw_part (window, style->dark_gc[state_type], area, x, y, RADIO_DARK);
3751 draw_part (window, style->mid_gc[state_type], area, x, y, RADIO_MID);
3752 draw_part (window, style->light_gc[state_type], area, x, y, RADIO_LIGHT);
3755 if (shadow_type == GTK_SHADOW_IN)
3757 draw_part (window, text_gc, area, x, y, RADIO_TEXT);
3759 else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
3761 if (strcmp (detail, "option") == 0) /* Menu item */
3763 draw_part (window, text_gc, area, x, y, CHECK_INCONSISTENT_TEXT);
3767 draw_part (window, text_gc, area, x, y, RADIO_INCONSISTENT_TEXT);
3768 draw_part (window, aa_gc, area, x, y, RADIO_INCONSISTENT_AA);
3773 g_object_unref (G_OBJECT (free_me));
3778 gtk_default_draw_tab (GtkStyle *style,
3780 GtkStateType state_type,
3781 GtkShadowType shadow_type,
3784 const gchar *detail,
3790 #define ARROW_SPACE 4
3792 GtkRequisition indicator_size;
3793 GtkBorder indicator_spacing;
3796 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
3798 indicator_size.width += (indicator_size.width % 2) - 1;
3799 arrow_height = indicator_size.width / 2 + 1;
3801 x += (width - indicator_size.width) / 2;
3802 y += (height - (2 * arrow_height + ARROW_SPACE)) / 2;
3804 if (state_type == GTK_STATE_INSENSITIVE)
3806 draw_arrow (window, style->white_gc, area,
3807 GTK_ARROW_UP, x + 1, y + 1,
3808 indicator_size.width, arrow_height);
3810 draw_arrow (window, style->white_gc, area,
3811 GTK_ARROW_DOWN, x + 1, y + arrow_height + ARROW_SPACE + 1,
3812 indicator_size.width, arrow_height);
3815 draw_arrow (window, style->fg_gc[state_type], area,
3817 indicator_size.width, arrow_height);
3820 draw_arrow (window, style->fg_gc[state_type], area,
3821 GTK_ARROW_DOWN, x, y + arrow_height + ARROW_SPACE,
3822 indicator_size.width, arrow_height);
3826 gtk_default_draw_shadow_gap (GtkStyle *style,
3828 GtkStateType state_type,
3829 GtkShadowType shadow_type,
3832 const gchar *detail,
3837 GtkPositionType gap_side,
3846 g_return_if_fail (GTK_IS_STYLE (style));
3847 g_return_if_fail (window != NULL);
3849 sanitize_size (window, &width, &height);
3851 switch (shadow_type)
3853 case GTK_SHADOW_NONE:
3856 gc1 = style->dark_gc[state_type];
3857 gc2 = style->black_gc;
3858 gc3 = style->bg_gc[state_type];
3859 gc4 = style->light_gc[state_type];
3861 case GTK_SHADOW_ETCHED_IN:
3862 gc1 = style->dark_gc[state_type];
3863 gc2 = style->light_gc[state_type];
3864 gc3 = style->dark_gc[state_type];
3865 gc4 = style->light_gc[state_type];
3867 case GTK_SHADOW_OUT:
3868 gc1 = style->light_gc[state_type];
3869 gc2 = style->bg_gc[state_type];
3870 gc3 = style->dark_gc[state_type];
3871 gc4 = style->black_gc;
3873 case GTK_SHADOW_ETCHED_OUT:
3874 gc1 = style->light_gc[state_type];
3875 gc2 = style->dark_gc[state_type];
3876 gc3 = style->light_gc[state_type];
3877 gc4 = style->dark_gc[state_type];
3882 gdk_gc_set_clip_rectangle (gc1, area);
3883 gdk_gc_set_clip_rectangle (gc2, area);
3884 gdk_gc_set_clip_rectangle (gc3, area);
3885 gdk_gc_set_clip_rectangle (gc4, area);
3888 switch (shadow_type)
3890 case GTK_SHADOW_NONE:
3892 case GTK_SHADOW_OUT:
3893 case GTK_SHADOW_ETCHED_IN:
3894 case GTK_SHADOW_ETCHED_OUT:
3898 gdk_draw_line (window, gc1,
3899 x, y, x, y + height - 1);
3900 gdk_draw_line (window, gc2,
3901 x + 1, y, x + 1, y + height - 2);
3903 gdk_draw_line (window, gc3,
3904 x + 1, y + height - 2, x + width - 2, y + height - 2);
3905 gdk_draw_line (window, gc3,
3906 x + width - 2, y, x + width - 2, y + height - 2);
3907 gdk_draw_line (window, gc4,
3908 x, y + height - 1, x + width - 1, y + height - 1);
3909 gdk_draw_line (window, gc4,
3910 x + width - 1, y, x + width - 1, y + height - 1);
3913 gdk_draw_line (window, gc1,
3914 x, y, x + gap_x - 1, y);
3915 gdk_draw_line (window, gc2,
3916 x + 1, y + 1, x + gap_x - 1, y + 1);
3917 gdk_draw_line (window, gc2,
3918 x + gap_x, y, x + gap_x, y);
3920 if ((width - (gap_x + gap_width)) > 0)
3922 gdk_draw_line (window, gc1,
3923 x + gap_x + gap_width, y, x + width - 2, y);
3924 gdk_draw_line (window, gc2,
3925 x + gap_x + gap_width, y + 1, x + width - 3, y + 1);
3926 gdk_draw_line (window, gc2,
3927 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
3930 case GTK_POS_BOTTOM:
3931 gdk_draw_line (window, gc1,
3932 x, y, x + width - 1, y);
3933 gdk_draw_line (window, gc1,
3934 x, y, x, y + height - 1);
3935 gdk_draw_line (window, gc2,
3936 x + 1, y + 1, x + width - 2, y + 1);
3937 gdk_draw_line (window, gc2,
3938 x + 1, y + 1, x + 1, y + height - 1);
3940 gdk_draw_line (window, gc3,
3941 x + width - 2, y + 1, x + width - 2, y + height - 1);
3942 gdk_draw_line (window, gc4,
3943 x + width - 1, y, x + width - 1, y + height - 1);
3946 gdk_draw_line (window, gc4,
3947 x, y + height - 1, x + gap_x - 1, y + height - 1);
3948 gdk_draw_line (window, gc3,
3949 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
3950 gdk_draw_line (window, gc3,
3951 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
3953 if ((width - (gap_x + gap_width)) > 0)
3955 gdk_draw_line (window, gc4,
3956 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
3957 gdk_draw_line (window, gc3,
3958 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
3959 gdk_draw_line (window, gc3,
3960 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
3964 gdk_draw_line (window, gc1,
3965 x, y, x + width - 1, y);
3966 gdk_draw_line (window, gc2,
3967 x, y + 1, x + width - 2, y + 1);
3969 gdk_draw_line (window, gc3,
3970 x, y + height - 2, x + width - 2, y + height - 2);
3971 gdk_draw_line (window, gc3,
3972 x + width - 2, y + 1, x + width - 2, y + height - 2);
3973 gdk_draw_line (window, gc4,
3974 x, y + height - 1, x + width - 1, y + height - 1);
3975 gdk_draw_line (window, gc4,
3976 x + width - 1, y, x + width - 1, y + height - 1);
3979 gdk_draw_line (window, gc1,
3980 x, y, x, y + gap_x - 1);
3981 gdk_draw_line (window, gc2,
3982 x + 1, y + 1, x + 1, y + gap_x - 1);
3983 gdk_draw_line (window, gc2,
3984 x, y + gap_x, x, y + gap_x);
3986 if ((width - (gap_x + gap_width)) > 0)
3988 gdk_draw_line (window, gc1,
3989 x, y + gap_x + gap_width, x, y + height - 2);
3990 gdk_draw_line (window, gc2,
3991 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
3992 gdk_draw_line (window, gc2,
3993 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
3997 gdk_draw_line (window, gc1,
3998 x, y, x + width - 1, y);
3999 gdk_draw_line (window, gc1,
4000 x, y, x, y + height - 1);
4001 gdk_draw_line (window, gc2,
4002 x + 1, y + 1, x + width - 1, y + 1);
4003 gdk_draw_line (window, gc2,
4004 x + 1, y + 1, x + 1, y + height - 2);
4006 gdk_draw_line (window, gc3,
4007 x + 1, y + height - 2, x + width - 1, y + height - 2);
4008 gdk_draw_line (window, gc4,
4009 x, y + height - 1, x + width - 1, y + height - 1);
4012 gdk_draw_line (window, gc4,
4013 x + width - 1, y, x + width - 1, y + gap_x - 1);
4014 gdk_draw_line (window, gc3,
4015 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
4016 gdk_draw_line (window, gc3,
4017 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
4019 if ((width - (gap_x + gap_width)) > 0)
4021 gdk_draw_line (window, gc4,
4022 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
4023 gdk_draw_line (window, gc3,
4024 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
4025 gdk_draw_line (window, gc3,
4026 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
4034 gdk_gc_set_clip_rectangle (gc1, NULL);
4035 gdk_gc_set_clip_rectangle (gc2, NULL);
4036 gdk_gc_set_clip_rectangle (gc3, NULL);
4037 gdk_gc_set_clip_rectangle (gc4, NULL);
4042 gtk_default_draw_box_gap (GtkStyle *style,
4044 GtkStateType state_type,
4045 GtkShadowType shadow_type,
4048 const gchar *detail,
4053 GtkPositionType gap_side,
4062 g_return_if_fail (GTK_IS_STYLE (style));
4063 g_return_if_fail (window != NULL);
4065 gtk_style_apply_default_background (style, window,
4066 widget && !GTK_WIDGET_NO_WINDOW (widget),
4067 state_type, area, x, y, width, height);
4069 sanitize_size (window, &width, &height);
4071 switch (shadow_type)
4073 case GTK_SHADOW_NONE:
4076 gc1 = style->dark_gc[state_type];
4077 gc2 = style->black_gc;
4078 gc3 = style->bg_gc[state_type];
4079 gc4 = style->light_gc[state_type];
4081 case GTK_SHADOW_ETCHED_IN:
4082 gc1 = style->dark_gc[state_type];
4083 gc2 = style->light_gc[state_type];
4084 gc3 = style->dark_gc[state_type];
4085 gc4 = style->light_gc[state_type];
4087 case GTK_SHADOW_OUT:
4088 gc1 = style->light_gc[state_type];
4089 gc2 = style->bg_gc[state_type];
4090 gc3 = style->dark_gc[state_type];
4091 gc4 = style->black_gc;
4093 case GTK_SHADOW_ETCHED_OUT:
4094 gc1 = style->light_gc[state_type];
4095 gc2 = style->dark_gc[state_type];
4096 gc3 = style->light_gc[state_type];
4097 gc4 = style->dark_gc[state_type];
4103 gdk_gc_set_clip_rectangle (gc1, area);
4104 gdk_gc_set_clip_rectangle (gc2, area);
4105 gdk_gc_set_clip_rectangle (gc3, area);
4106 gdk_gc_set_clip_rectangle (gc4, area);
4109 switch (shadow_type)
4111 case GTK_SHADOW_NONE:
4113 case GTK_SHADOW_OUT:
4114 case GTK_SHADOW_ETCHED_IN:
4115 case GTK_SHADOW_ETCHED_OUT:
4119 gdk_draw_line (window, gc1,
4120 x, y, x, y + height - 1);
4121 gdk_draw_line (window, gc2,
4122 x + 1, y, x + 1, y + height - 2);
4124 gdk_draw_line (window, gc3,
4125 x + 1, y + height - 2, x + width - 2, y + height - 2);
4126 gdk_draw_line (window, gc3,
4127 x + width - 2, y, x + width - 2, y + height - 2);
4128 gdk_draw_line (window, gc4,
4129 x, y + height - 1, x + width - 1, y + height - 1);
4130 gdk_draw_line (window, gc4,
4131 x + width - 1, y, x + width - 1, y + height - 1);
4134 gdk_draw_line (window, gc1,
4135 x, y, x + gap_x - 1, y);
4136 gdk_draw_line (window, gc2,
4137 x + 1, y + 1, x + gap_x - 1, y + 1);
4138 gdk_draw_line (window, gc2,
4139 x + gap_x, y, x + gap_x, y);
4141 if ((width - (gap_x + gap_width)) > 0)
4143 gdk_draw_line (window, gc1,
4144 x + gap_x + gap_width, y, x + width - 2, y);
4145 gdk_draw_line (window, gc2,
4146 x + gap_x + gap_width, y + 1, x + width - 2, y + 1);
4147 gdk_draw_line (window, gc2,
4148 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
4151 case GTK_POS_BOTTOM:
4152 gdk_draw_line (window, gc1,
4153 x, y, x + width - 1, y);
4154 gdk_draw_line (window, gc1,
4155 x, y, x, y + height - 1);
4156 gdk_draw_line (window, gc2,
4157 x + 1, y + 1, x + width - 2, y + 1);
4158 gdk_draw_line (window, gc2,
4159 x + 1, y + 1, x + 1, y + height - 1);
4161 gdk_draw_line (window, gc3,
4162 x + width - 2, y + 1, x + width - 2, y + height - 1);
4163 gdk_draw_line (window, gc4,
4164 x + width - 1, y, x + width - 1, y + height - 1);
4167 gdk_draw_line (window, gc4,
4168 x, y + height - 1, x + gap_x - 1, y + height - 1);
4169 gdk_draw_line (window, gc3,
4170 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
4171 gdk_draw_line (window, gc3,
4172 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
4174 if ((width - (gap_x + gap_width)) > 0)
4176 gdk_draw_line (window, gc4,
4177 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
4178 gdk_draw_line (window, gc3,
4179 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
4180 gdk_draw_line (window, gc3,
4181 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
4185 gdk_draw_line (window, gc1,
4186 x, y, x + width - 1, y);
4187 gdk_draw_line (window, gc2,
4188 x, y + 1, x + width - 2, y + 1);
4190 gdk_draw_line (window, gc3,
4191 x, y + height - 2, x + width - 2, y + height - 2);
4192 gdk_draw_line (window, gc3,
4193 x + width - 2, y + 1, x + width - 2, y + height - 2);
4194 gdk_draw_line (window, gc4,
4195 x, y + height - 1, x + width - 1, y + height - 1);
4196 gdk_draw_line (window, gc4,
4197 x + width - 1, y, x + width - 1, y + height - 1);
4200 gdk_draw_line (window, gc1,
4201 x, y, x, y + gap_x - 1);
4202 gdk_draw_line (window, gc2,
4203 x + 1, y + 1, x + 1, y + gap_x - 1);
4204 gdk_draw_line (window, gc2,
4205 x, y + gap_x, x, y + gap_x);
4207 if ((width - (gap_x + gap_width)) > 0)
4209 gdk_draw_line (window, gc1,
4210 x, y + gap_x + gap_width, x, y + height - 2);
4211 gdk_draw_line (window, gc2,
4212 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
4213 gdk_draw_line (window, gc2,
4214 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
4218 gdk_draw_line (window, gc1,
4219 x, y, x + width - 1, y);
4220 gdk_draw_line (window, gc1,
4221 x, y, x, y + height - 1);
4222 gdk_draw_line (window, gc2,
4223 x + 1, y + 1, x + width - 1, y + 1);
4224 gdk_draw_line (window, gc2,
4225 x + 1, y + 1, x + 1, y + height - 2);
4227 gdk_draw_line (window, gc3,
4228 x + 1, y + height - 2, x + width - 1, y + height - 2);
4229 gdk_draw_line (window, gc4,
4230 x, y + height - 1, x + width - 1, y + height - 1);
4233 gdk_draw_line (window, gc4,
4234 x + width - 1, y, x + width - 1, y + gap_x - 1);
4235 gdk_draw_line (window, gc3,
4236 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
4237 gdk_draw_line (window, gc3,
4238 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
4240 if ((width - (gap_x + gap_width)) > 0)
4242 gdk_draw_line (window, gc4,
4243 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
4244 gdk_draw_line (window, gc3,
4245 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
4246 gdk_draw_line (window, gc3,
4247 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
4255 gdk_gc_set_clip_rectangle (gc1, NULL);
4256 gdk_gc_set_clip_rectangle (gc2, NULL);
4257 gdk_gc_set_clip_rectangle (gc3, NULL);
4258 gdk_gc_set_clip_rectangle (gc4, NULL);
4263 gtk_default_draw_extension (GtkStyle *style,
4265 GtkStateType state_type,
4266 GtkShadowType shadow_type,
4269 const gchar *detail,
4274 GtkPositionType gap_side)
4281 g_return_if_fail (GTK_IS_STYLE (style));
4282 g_return_if_fail (window != NULL);
4284 gtk_style_apply_default_background (style, window,
4285 widget && !GTK_WIDGET_NO_WINDOW (widget),
4286 GTK_STATE_NORMAL, area, x, y, width, height);
4288 sanitize_size (window, &width, &height);
4290 switch (shadow_type)
4292 case GTK_SHADOW_NONE:
4295 gc1 = style->dark_gc[state_type];
4296 gc2 = style->black_gc;
4297 gc3 = style->bg_gc[state_type];
4298 gc4 = style->light_gc[state_type];
4300 case GTK_SHADOW_ETCHED_IN:
4301 gc1 = style->dark_gc[state_type];
4302 gc2 = style->light_gc[state_type];
4303 gc3 = style->dark_gc[state_type];
4304 gc4 = style->light_gc[state_type];
4306 case GTK_SHADOW_OUT:
4307 gc1 = style->light_gc[state_type];
4308 gc2 = style->bg_gc[state_type];
4309 gc3 = style->dark_gc[state_type];
4310 gc4 = style->black_gc;
4312 case GTK_SHADOW_ETCHED_OUT:
4313 gc1 = style->light_gc[state_type];
4314 gc2 = style->dark_gc[state_type];
4315 gc3 = style->light_gc[state_type];
4316 gc4 = style->dark_gc[state_type];
4322 gdk_gc_set_clip_rectangle (gc1, area);
4323 gdk_gc_set_clip_rectangle (gc2, area);
4324 gdk_gc_set_clip_rectangle (gc3, area);
4325 gdk_gc_set_clip_rectangle (gc4, area);
4328 switch (shadow_type)
4330 case GTK_SHADOW_NONE:
4332 case GTK_SHADOW_OUT:
4333 case GTK_SHADOW_ETCHED_IN:
4334 case GTK_SHADOW_ETCHED_OUT:
4338 gtk_style_apply_default_background (style, window,
4339 widget && !GTK_WIDGET_NO_WINDOW (widget),
4341 x + style->xthickness,
4343 width - (2 * style->xthickness),
4344 height - (style->ythickness));
4345 gdk_draw_line (window, gc1,
4346 x, y, x, y + height - 2);
4347 gdk_draw_line (window, gc2,
4348 x + 1, y, x + 1, y + height - 2);
4350 gdk_draw_line (window, gc3,
4351 x + 2, y + height - 2, x + width - 2, y + height - 2);
4352 gdk_draw_line (window, gc3,
4353 x + width - 2, y, x + width - 2, y + height - 2);
4354 gdk_draw_line (window, gc4,
4355 x + 1, y + height - 1, x + width - 2, y + height - 1);
4356 gdk_draw_line (window, gc4,
4357 x + width - 1, y, x + width - 1, y + height - 2);
4359 case GTK_POS_BOTTOM:
4360 gtk_style_apply_default_background (style, window,
4361 widget && !GTK_WIDGET_NO_WINDOW (widget),
4363 x + style->xthickness,
4364 y + style->ythickness,
4365 width - (2 * style->xthickness),
4366 height - (style->ythickness));
4367 gdk_draw_line (window, gc1,
4368 x + 1, y, x + width - 2, y);
4369 gdk_draw_line (window, gc1,
4370 x, y + 1, x, y + height - 1);
4371 gdk_draw_line (window, gc2,
4372 x + 1, y + 1, x + width - 2, y + 1);
4373 gdk_draw_line (window, gc2,
4374 x + 1, y + 1, x + 1, y + height - 1);
4376 gdk_draw_line (window, gc3,
4377 x + width - 2, y + 2, x + width - 2, y + height - 1);
4378 gdk_draw_line (window, gc4,
4379 x + width - 1, y + 1, x + width - 1, y + height - 1);
4382 gtk_style_apply_default_background (style, window,
4383 widget && !GTK_WIDGET_NO_WINDOW (widget),
4386 y + style->ythickness,
4387 width - (style->xthickness),
4388 height - (2 * style->ythickness));
4389 gdk_draw_line (window, gc1,
4390 x, y, x + width - 2, y);
4391 gdk_draw_line (window, gc2,
4392 x + 1, y + 1, x + width - 2, y + 1);
4394 gdk_draw_line (window, gc3,
4395 x, y + height - 2, x + width - 2, y + height - 2);
4396 gdk_draw_line (window, gc3,
4397 x + width - 2, y + 2, x + width - 2, y + height - 2);
4398 gdk_draw_line (window, gc4,
4399 x, y + height - 1, x + width - 2, y + height - 1);
4400 gdk_draw_line (window, gc4,
4401 x + width - 1, y + 1, x + width - 1, y + height - 2);
4404 gtk_style_apply_default_background (style, window,
4405 widget && !GTK_WIDGET_NO_WINDOW (widget),
4407 x + style->xthickness,
4408 y + style->ythickness,
4409 width - (style->xthickness),
4410 height - (2 * style->ythickness));
4411 gdk_draw_line (window, gc1,
4412 x + 1, y, x + width - 1, y);
4413 gdk_draw_line (window, gc1,
4414 x, y + 1, x, y + height - 2);
4415 gdk_draw_line (window, gc2,
4416 x + 1, y + 1, x + width - 1, y + 1);
4417 gdk_draw_line (window, gc2,
4418 x + 1, y + 1, x + 1, y + height - 2);
4420 gdk_draw_line (window, gc3,
4421 x + 2, y + height - 2, x + width - 1, y + height - 2);
4422 gdk_draw_line (window, gc4,
4423 x + 1, y + height - 1, x + width - 1, y + height - 1);
4430 gdk_gc_set_clip_rectangle (gc1, NULL);
4431 gdk_gc_set_clip_rectangle (gc2, NULL);
4432 gdk_gc_set_clip_rectangle (gc3, NULL);
4433 gdk_gc_set_clip_rectangle (gc4, NULL);
4438 gtk_default_draw_focus (GtkStyle *style,
4440 GtkStateType state_type,
4443 const gchar *detail,
4451 gboolean free_dash_list = FALSE;
4452 gint line_width = 1;
4453 gint8 *dash_list = "\1\1";
4456 gc = style->fg_gc[state_type];
4460 gtk_widget_style_get (widget,
4461 "focus-line-width", &line_width,
4462 "focus-line-pattern", (gchar *)&dash_list,
4465 free_dash_list = TRUE;
4468 sanitize_size (window, &width, &height);
4471 gdk_gc_set_clip_rectangle (gc, area);
4473 gdk_gc_set_line_attributes (gc, line_width,
4474 dash_list[0] ? GDK_LINE_ON_OFF_DASH : GDK_LINE_SOLID,
4475 GDK_CAP_BUTT, GDK_JOIN_MITER);
4478 if (detail && !strcmp (detail, "add-mode"))
4484 free_dash_list = FALSE;
4487 points[0].x = x + line_width / 2;
4488 points[0].y = y + line_width / 2;
4489 points[1].x = x + width - line_width + line_width / 2;
4490 points[1].y = y + line_width / 2;
4491 points[2].x = x + width - line_width + line_width / 2;
4492 points[2].y = y + height - line_width + line_width / 2;
4493 points[3].x = x + line_width / 2;
4494 points[3].y = y + height - line_width + line_width / 2;
4495 points[4] = points[0];
4499 gdk_draw_lines (window, gc, points, 5);
4503 /* We go through all the pain below because the X rasterization
4504 * rules don't really work right for dashed lines if you
4505 * want continuity in segments that go between top/right
4506 * and left/bottom. For instance, a top left corner
4507 * with a 1-1 dash is drawn as:
4514 * This is because pixels on the top and left boundaries
4515 * of polygons are drawn, but not on the bottom and right.
4516 * So, if you have a line going up that turns the corner
4517 * and goes right, there is a one pixel shift in the pattern.
4519 * So, to fix this, we drawn the top and right in one call,
4520 * then the left and bottom in another call, fixing up
4521 * the dash offset for the second call ourselves to get
4522 * continuity at the upper left.
4524 * It's not perfect since we really should have a join at
4525 * the upper left and lower right instead of two intersecting
4526 * lines but that's only really apparent for no-dashes,
4527 * which (for this reason) are done as one polygon and
4528 * don't to through this code path.
4531 dash_len = strlen (dash_list);
4534 gdk_gc_set_dashes (gc, 0, dash_list, dash_len);
4536 gdk_draw_lines (window, gc, points, 3);
4538 /* We draw this line one farther over than it is "supposed" to
4539 * because of another rasterization problem ... if two 1 pixel
4540 * unjoined lines meet at the lower right, there will be a missing
4547 gint dash_pixels = 0;
4550 /* Adjust the dash offset for the bottom and left so we
4551 * match up at the upper left.
4553 for (i = 0; i < dash_len; i++)
4554 dash_pixels += dash_list[i];
4556 if (dash_len % 2 == 1)
4559 gdk_gc_set_dashes (gc, dash_pixels - (width + height - 2 * line_width) % dash_pixels, dash_list, dash_len);
4562 gdk_draw_lines (window, gc, points + 2, 3);
4565 gdk_gc_set_line_attributes (gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
4568 gdk_gc_set_clip_rectangle (gc, NULL);
4575 gtk_default_draw_slider (GtkStyle *style,
4577 GtkStateType state_type,
4578 GtkShadowType shadow_type,
4581 const gchar *detail,
4586 GtkOrientation orientation)
4588 g_return_if_fail (GTK_IS_STYLE (style));
4589 g_return_if_fail (window != NULL);
4591 sanitize_size (window, &width, &height);
4593 gtk_paint_box (style, window, state_type, shadow_type,
4594 area, widget, detail, x, y, width, height);
4597 (strcmp ("hscale", detail) == 0 ||
4598 strcmp ("vscale", detail) == 0))
4600 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4601 gtk_paint_vline (style, window, state_type, area, widget, detail,
4602 y + style->ythickness,
4603 y + height - style->ythickness - 1, x + width / 2);
4605 gtk_paint_hline (style, window, state_type, area, widget, detail,
4606 x + style->xthickness,
4607 x + width - style->xthickness - 1, y + height / 2);
4612 draw_dot (GdkWindow *window,
4620 size = CLAMP (size, 2, 3);
4624 gdk_draw_point (window, light_gc, x, y);
4625 gdk_draw_point (window, light_gc, x+1, y+1);
4627 else if (size == 3);
4629 gdk_draw_point (window, light_gc, x, y);
4630 gdk_draw_point (window, light_gc, x+1, y);
4631 gdk_draw_point (window, light_gc, x, y+1);
4632 gdk_draw_point (window, dark_gc, x+1, y+2);
4633 gdk_draw_point (window, dark_gc, x+2, y+1);
4634 gdk_draw_point (window, dark_gc, x+2, y+2);
4639 gtk_default_draw_handle (GtkStyle *style,
4641 GtkStateType state_type,
4642 GtkShadowType shadow_type,
4645 const gchar *detail,
4650 GtkOrientation orientation)
4653 gint xthick, ythick;
4654 GdkGC *light_gc, *dark_gc;
4659 g_return_if_fail (GTK_IS_STYLE (style));
4660 g_return_if_fail (window != NULL);
4662 sanitize_size (window, &width, &height);
4664 gtk_paint_box (style, window, state_type, shadow_type, area, widget,
4665 detail, x, y, width, height);
4668 if (!strcmp (detail, "paned"))
4670 /* we want to ignore the shadow border in paned widgets */
4674 light_gc = style->light_gc[state_type];
4675 dark_gc = style->black_gc;
4679 xthick = style->xthickness;
4680 ythick = style->ythickness;
4682 light_gc = style->light_gc[state_type];
4683 dark_gc = style->dark_gc[state_type];
4686 rect.x = x + xthick;
4687 rect.y = y + ythick;
4688 rect.width = width - (xthick * 2);
4689 rect.height = height - (ythick * 2);
4692 intersect = gdk_rectangle_intersect (area, &rect, &dest);
4702 gdk_gc_set_clip_rectangle (light_gc, &dest);
4703 gdk_gc_set_clip_rectangle (dark_gc, &dest);
4705 if (!strcmp (detail, "paned"))
4707 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4708 for (xx = x + width/2 - 15; xx <= x + width/2 + 15; xx += 5)
4709 draw_dot (window, light_gc, dark_gc, xx, y + height/2 - 1, 3);
4711 for (yy = y + height/2 - 15; yy <= y + height/2 + 15; yy += 5)
4712 draw_dot (window, light_gc, dark_gc, x + width/2 - 1, yy, 3);
4716 for (yy = y + ythick; yy < (y + height - ythick); yy += 3)
4717 for (xx = x + xthick; xx < (x + width - xthick); xx += 6)
4719 draw_dot (window, light_gc, dark_gc, xx, yy, 2);
4720 draw_dot (window, light_gc, dark_gc, xx + 3, yy + 1, 2);
4724 gdk_gc_set_clip_rectangle (light_gc, NULL);
4725 gdk_gc_set_clip_rectangle (dark_gc, NULL);
4729 create_expander_affine (gdouble affine[6],
4739 width = expander_size / 4.0;
4740 height = expander_size / 2.0;
4742 s = sin (degrees * G_PI / 180.0);
4743 c = cos (degrees * G_PI / 180.0);
4749 affine[4] = -width * c - height * -s + x;
4750 affine[5] = -width * s - height * c + y;
4754 apply_affine_on_point (double affine[6], GdkPoint *point)
4758 x = point->x * affine[0] + point->y * affine[2] + affine[4];
4759 y = point->x * affine[1] + point->y * affine[3] + affine[5];
4766 gtk_style_draw_polygon_with_gc (GdkWindow *window, GdkGC *gc, gint line_width,
4767 gboolean do_fill, GdkPoint *points, gint n_points)
4769 gdk_gc_set_line_attributes (gc, line_width,
4771 GDK_CAP_BUTT, GDK_JOIN_MITER);
4773 gdk_draw_polygon (window, gc, do_fill, points, n_points);
4774 gdk_gc_set_line_attributes (gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
4778 gtk_default_draw_expander (GtkStyle *style,
4780 GtkStateType state_type,
4783 const gchar *detail,
4786 GtkExpanderStyle expander_style)
4795 gtk_widget_style_get (widget,
4796 "expander_size", &expander_size,
4798 line_width = MAX (1, expander_size/7);
4802 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], area);
4803 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], area);
4806 expander_size -= (line_width * 2 - 2);
4807 points[0].x = line_width / 2;
4808 points[0].y = line_width / 2;
4809 points[1].x = expander_size / 2 + line_width / 2;
4810 points[1].y = expander_size / 2 + line_width / 2;
4811 points[2].x = line_width / 2;
4812 points[2].y = expander_size + line_width / 2;
4814 switch (expander_style)
4816 case GTK_EXPANDER_COLLAPSED:
4817 degrees = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ? 180 : 0;
4819 case GTK_EXPANDER_SEMI_COLLAPSED:
4820 degrees = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ? 150 : 30;
4822 case GTK_EXPANDER_SEMI_EXPANDED:
4823 degrees = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ? 120 : 60;
4825 case GTK_EXPANDER_EXPANDED:
4829 g_assert_not_reached ();
4832 create_expander_affine (affine, degrees, expander_size, x, y);
4834 for (i = 0; i < 3; i++)
4835 apply_affine_on_point (affine, &points[i]);
4837 if (state_type == GTK_STATE_PRELIGHT)
4839 gtk_style_draw_polygon_with_gc (window, style->fg_gc[GTK_STATE_NORMAL],
4840 1, TRUE, points, 3);
4842 else if (state_type == GTK_STATE_ACTIVE)
4844 gtk_style_draw_polygon_with_gc (window, style->light_gc[GTK_STATE_ACTIVE],
4845 1, TRUE, points, 3);
4846 gtk_style_draw_polygon_with_gc (window, style->fg_gc[GTK_STATE_NORMAL],
4847 line_width, FALSE, points, 3);
4851 gtk_style_draw_polygon_with_gc (window, style->base_gc[GTK_STATE_NORMAL],
4852 1, TRUE, points, 3);
4853 gtk_style_draw_polygon_with_gc (window, style->fg_gc[GTK_STATE_NORMAL],
4854 line_width, FALSE, points, 3);
4858 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], NULL);
4859 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], NULL);
4863 typedef struct _ByteRange ByteRange;
4872 range_new (guint start,
4875 ByteRange *br = g_new (ByteRange, 1);
4884 get_insensitive_layout (GdkDrawable *drawable,
4885 PangoLayout *layout)
4887 GSList *embossed_ranges = NULL;
4888 GSList *stippled_ranges = NULL;
4889 PangoLayoutIter *iter;
4890 GSList *tmp_list = NULL;
4891 PangoLayout *new_layout;
4892 PangoAttrList *attrs;
4893 GdkBitmap *stipple = NULL;
4895 iter = pango_layout_get_iter (layout);
4899 PangoLayoutRun *run;
4900 PangoAttribute *attr;
4901 gboolean need_stipple = FALSE;
4904 run = pango_layout_iter_get_run (iter);
4908 tmp_list = run->item->analysis.extra_attrs;
4910 while (tmp_list != NULL)
4912 attr = tmp_list->data;
4913 switch (attr->klass->type)
4915 case PANGO_ATTR_FOREGROUND:
4916 case PANGO_ATTR_BACKGROUND:
4917 need_stipple = TRUE;
4927 tmp_list = g_slist_next (tmp_list);
4930 br = range_new (run->item->offset, run->item->offset + run->item->length);
4933 stippled_ranges = g_slist_prepend (stippled_ranges, br);
4935 embossed_ranges = g_slist_prepend (embossed_ranges, br);
4938 while (pango_layout_iter_next_run (iter));
4940 pango_layout_iter_free (iter);
4942 new_layout = pango_layout_copy (layout);
4944 attrs = pango_layout_get_attributes (new_layout);
4948 /* Create attr list if there wasn't one */
4949 attrs = pango_attr_list_new ();
4950 pango_layout_set_attributes (new_layout, attrs);
4951 pango_attr_list_unref (attrs);
4954 tmp_list = embossed_ranges;
4955 while (tmp_list != NULL)
4957 PangoAttribute *attr;
4958 ByteRange *br = tmp_list->data;
4960 attr = gdk_pango_attr_embossed_new (TRUE);
4962 attr->start_index = br->start;
4963 attr->end_index = br->end;
4965 pango_attr_list_change (attrs, attr);
4969 tmp_list = g_slist_next (tmp_list);
4972 g_slist_free (embossed_ranges);
4974 tmp_list = stippled_ranges;
4975 while (tmp_list != NULL)
4977 PangoAttribute *attr;
4978 ByteRange *br = tmp_list->data;
4980 if (stipple == NULL)
4982 #define gray50_width 2
4983 #define gray50_height 2
4984 static char gray50_bits[] = {
4988 stipple = gdk_bitmap_create_from_data (drawable,
4989 gray50_bits, gray50_width,
4993 attr = gdk_pango_attr_stipple_new (stipple);
4995 attr->start_index = br->start;
4996 attr->end_index = br->end;
4998 pango_attr_list_change (attrs, attr);
5002 tmp_list = g_slist_next (tmp_list);
5005 g_slist_free (stippled_ranges);
5008 g_object_unref (stipple);
5014 gtk_default_draw_layout (GtkStyle *style,
5016 GtkStateType state_type,
5020 const gchar *detail,
5023 PangoLayout *layout)
5027 g_return_if_fail (GTK_IS_STYLE (style));
5028 g_return_if_fail (window != NULL);
5030 gc = use_text ? style->text_gc[state_type] : style->fg_gc[state_type];
5033 gdk_gc_set_clip_rectangle (gc, area);
5035 if (state_type == GTK_STATE_INSENSITIVE)
5039 ins = get_insensitive_layout (window, layout);
5041 gdk_draw_layout (window, gc, x, y, ins);
5043 g_object_unref (ins);
5047 gdk_draw_layout (window, gc, x, y, layout);
5051 gdk_gc_set_clip_rectangle (gc, NULL);
5055 gtk_default_draw_resize_grip (GtkStyle *style,
5057 GtkStateType state_type,
5060 const gchar *detail,
5067 g_return_if_fail (GTK_IS_STYLE (style));
5068 g_return_if_fail (window != NULL);
5072 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
5073 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
5074 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
5079 case GDK_WINDOW_EDGE_NORTH_WEST:
5080 /* make it square */
5085 else if (height < width)
5090 case GDK_WINDOW_EDGE_NORTH:
5096 case GDK_WINDOW_EDGE_NORTH_EAST:
5097 /* make it square, aligning to top right */
5102 else if (height < width)
5104 x += (width - height);
5108 case GDK_WINDOW_EDGE_WEST:
5114 case GDK_WINDOW_EDGE_EAST:
5115 /* aligning to right */
5118 x += (width - height);
5122 case GDK_WINDOW_EDGE_SOUTH_WEST:
5123 /* make it square, aligning to bottom left */
5126 y += (height - width);
5129 else if (height < width)
5134 case GDK_WINDOW_EDGE_SOUTH:
5135 /* align to bottom */
5138 y += (height - width);
5142 case GDK_WINDOW_EDGE_SOUTH_EAST:
5143 /* make it square, aligning to bottom right */
5146 y += (height - width);
5149 else if (height < width)
5151 x += (width - height);
5156 g_assert_not_reached ();
5158 /* Clear background */
5159 gtk_style_apply_default_background (style, window, FALSE,
5161 x, y, width, height);
5165 case GDK_WINDOW_EDGE_WEST:
5166 case GDK_WINDOW_EDGE_EAST:
5172 while (xi < x + width)
5174 gdk_draw_line (window,
5175 style->light_gc[state_type],
5180 gdk_draw_line (window,
5181 style->dark_gc[state_type],
5189 case GDK_WINDOW_EDGE_NORTH:
5190 case GDK_WINDOW_EDGE_SOUTH:
5196 while (yi < y + height)
5198 gdk_draw_line (window,
5199 style->light_gc[state_type],
5204 gdk_draw_line (window,
5205 style->dark_gc[state_type],
5213 case GDK_WINDOW_EDGE_NORTH_WEST:
5222 gdk_draw_line (window,
5223 style->dark_gc[state_type],
5230 gdk_draw_line (window,
5231 style->dark_gc[state_type],
5238 gdk_draw_line (window,
5239 style->light_gc[state_type],
5249 case GDK_WINDOW_EDGE_NORTH_EAST:
5256 while (xi < (x + width - 3))
5258 gdk_draw_line (window,
5259 style->light_gc[state_type],
5266 gdk_draw_line (window,
5267 style->dark_gc[state_type],
5274 gdk_draw_line (window,
5275 style->dark_gc[state_type],
5284 case GDK_WINDOW_EDGE_SOUTH_WEST:
5293 gdk_draw_line (window,
5294 style->dark_gc[state_type],
5301 gdk_draw_line (window,
5302 style->dark_gc[state_type],
5309 gdk_draw_line (window,
5310 style->light_gc[state_type],
5320 case GDK_WINDOW_EDGE_SOUTH_EAST:
5327 while (xi < (x + width - 3))
5329 gdk_draw_line (window,
5330 style->light_gc[state_type],
5337 gdk_draw_line (window,
5338 style->dark_gc[state_type],
5345 gdk_draw_line (window,
5346 style->dark_gc[state_type],
5356 g_assert_not_reached ();
5362 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
5363 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
5364 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
5369 gtk_style_shade (GdkColor *a,
5377 red = (gdouble) a->red / 65535.0;
5378 green = (gdouble) a->green / 65535.0;
5379 blue = (gdouble) a->blue / 65535.0;
5381 rgb_to_hls (&red, &green, &blue);
5386 else if (green < 0.0)
5392 else if (blue < 0.0)
5395 hls_to_rgb (&red, &green, &blue);
5397 b->red = red * 65535.0;
5398 b->green = green * 65535.0;
5399 b->blue = blue * 65535.0;
5403 rgb_to_hls (gdouble *r,
5444 l = (max + min) / 2;
5451 s = (max - min) / (max + min);
5453 s = (max - min) / (2 - max - min);
5457 h = (green - blue) / delta;
5458 else if (green == max)
5459 h = 2 + (blue - red) / delta;
5460 else if (blue == max)
5461 h = 4 + (red - green) / delta;
5474 hls_to_rgb (gdouble *h,
5487 if (lightness <= 0.5)
5488 m2 = lightness * (1 + saturation);
5490 m2 = lightness + saturation - lightness * saturation;
5491 m1 = 2 * lightness - m2;
5493 if (saturation == 0)
5508 r = m1 + (m2 - m1) * hue / 60;
5512 r = m1 + (m2 - m1) * (240 - hue) / 60;
5523 g = m1 + (m2 - m1) * hue / 60;
5527 g = m1 + (m2 - m1) * (240 - hue) / 60;
5538 b = m1 + (m2 - m1) * hue / 60;
5542 b = m1 + (m2 - m1) * (240 - hue) / 60;
5555 * @style: a #GtkStyle
5556 * @window: a #GdkWindow
5557 * @state_type: a state
5558 * @area: rectangle to which the output is clipped
5561 * @x1: the starting x coordinate
5562 * @x2: the ending x coordinate
5563 * @y: the y coordinate
5565 * Draws a horizontal line from (@x1, @y) to (@x2, @y) in @window
5566 * using the given style and state.
5569 gtk_paint_hline (GtkStyle *style,
5571 GtkStateType state_type,
5574 const gchar *detail,
5579 g_return_if_fail (GTK_IS_STYLE (style));
5580 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
5582 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, area, widget, detail, x1, x2, y);
5587 * @style: a #GtkStyle
5588 * @window: a #GdkWindow
5589 * @state_type: a state
5590 * @area: rectangle to which the output is clipped
5593 * @y1_: the starting y coordinate
5594 * @y2_: the ending y coordinate
5595 * @x: the x coordinate
5597 * Draws a vertical line from (@x, @y1_) to (@x, @y2_) in @window
5598 * using the given style and state.
5601 gtk_paint_vline (GtkStyle *style,
5603 GtkStateType state_type,
5606 const gchar *detail,
5611 g_return_if_fail (GTK_IS_STYLE (style));
5612 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
5614 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, area, widget, detail, y1, y2, x);
5618 gtk_paint_shadow (GtkStyle *style,
5620 GtkStateType state_type,
5621 GtkShadowType shadow_type,
5624 const gchar *detail,
5630 g_return_if_fail (GTK_IS_STYLE (style));
5631 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
5633 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5637 gtk_paint_polygon (GtkStyle *style,
5639 GtkStateType state_type,
5640 GtkShadowType shadow_type,
5643 const gchar *detail,
5648 g_return_if_fail (GTK_IS_STYLE (style));
5649 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
5651 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, area, widget, detail, points, npoints, fill);
5655 gtk_paint_arrow (GtkStyle *style,
5657 GtkStateType state_type,
5658 GtkShadowType shadow_type,
5661 const gchar *detail,
5662 GtkArrowType arrow_type,
5669 g_return_if_fail (GTK_IS_STYLE (style));
5670 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
5672 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, area, widget, detail, arrow_type, fill, x, y, width, height);
5676 gtk_paint_diamond (GtkStyle *style,
5678 GtkStateType state_type,
5679 GtkShadowType shadow_type,
5682 const gchar *detail,
5688 g_return_if_fail (GTK_IS_STYLE (style));
5689 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
5691 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5696 * @style: a #GtkStyle
5697 * @window: a #GdkWindow
5698 * @state_type: a state
5699 * @area: clip rectangle
5700 * @widget: the widget
5701 * @detail: a style detail
5704 * @string: the string to draw
5706 * Draws a text string on @window with the given parameters.
5708 * This function is deprecated, use gtk_paint_layout() instead.
5711 gtk_paint_string (GtkStyle *style,
5713 GtkStateType state_type,
5716 const gchar *detail,
5719 const gchar *string)
5721 g_return_if_fail (GTK_IS_STYLE (style));
5722 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
5724 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, area, widget, detail, x, y, string);
5728 gtk_paint_box (GtkStyle *style,
5730 GtkStateType state_type,
5731 GtkShadowType shadow_type,
5734 const gchar *detail,
5740 g_return_if_fail (GTK_IS_STYLE (style));
5741 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
5743 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5747 gtk_paint_flat_box (GtkStyle *style,
5749 GtkStateType state_type,
5750 GtkShadowType shadow_type,
5753 const gchar *detail,
5759 g_return_if_fail (GTK_IS_STYLE (style));
5760 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
5762 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5766 gtk_paint_check (GtkStyle *style,
5768 GtkStateType state_type,
5769 GtkShadowType shadow_type,
5772 const gchar *detail,
5778 g_return_if_fail (GTK_IS_STYLE (style));
5779 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
5781 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5785 gtk_paint_option (GtkStyle *style,
5787 GtkStateType state_type,
5788 GtkShadowType shadow_type,
5791 const gchar *detail,
5797 g_return_if_fail (GTK_IS_STYLE (style));
5798 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
5800 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5804 gtk_paint_tab (GtkStyle *style,
5806 GtkStateType state_type,
5807 GtkShadowType shadow_type,
5810 const gchar *detail,
5816 g_return_if_fail (GTK_IS_STYLE (style));
5817 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
5819 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5823 gtk_paint_shadow_gap (GtkStyle *style,
5825 GtkStateType state_type,
5826 GtkShadowType shadow_type,
5834 GtkPositionType gap_side,
5838 g_return_if_fail (GTK_IS_STYLE (style));
5839 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
5841 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);
5846 gtk_paint_box_gap (GtkStyle *style,
5848 GtkStateType state_type,
5849 GtkShadowType shadow_type,
5857 GtkPositionType gap_side,
5861 g_return_if_fail (GTK_IS_STYLE (style));
5862 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
5864 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);
5868 gtk_paint_extension (GtkStyle *style,
5870 GtkStateType state_type,
5871 GtkShadowType shadow_type,
5879 GtkPositionType gap_side)
5881 g_return_if_fail (GTK_IS_STYLE (style));
5882 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
5884 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side);
5888 gtk_paint_focus (GtkStyle *style,
5890 GtkStateType state_type,
5893 const gchar *detail,
5899 g_return_if_fail (GTK_IS_STYLE (style));
5900 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
5902 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, state_type, area, widget, detail, x, y, width, height);
5906 gtk_paint_slider (GtkStyle *style,
5908 GtkStateType state_type,
5909 GtkShadowType shadow_type,
5912 const gchar *detail,
5917 GtkOrientation orientation)
5919 g_return_if_fail (GTK_IS_STYLE (style));
5920 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
5922 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
5926 gtk_paint_handle (GtkStyle *style,
5928 GtkStateType state_type,
5929 GtkShadowType shadow_type,
5932 const gchar *detail,
5937 GtkOrientation orientation)
5939 g_return_if_fail (GTK_IS_STYLE (style));
5940 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
5942 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
5946 gtk_paint_expander (GtkStyle *style,
5948 GtkStateType state_type,
5951 const gchar *detail,
5954 GtkExpanderStyle expander_style)
5956 g_return_if_fail (GTK_IS_STYLE (style));
5957 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
5959 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type, area,
5960 widget, detail, x, y, expander_style);
5964 gtk_paint_layout (GtkStyle *style,
5966 GtkStateType state_type,
5970 const gchar *detail,
5973 PangoLayout *layout)
5975 g_return_if_fail (GTK_IS_STYLE (style));
5976 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
5978 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text, area,
5979 widget, detail, x, y, layout);
5983 gtk_paint_resize_grip (GtkStyle *style,
5985 GtkStateType state_type,
5988 const gchar *detail,
5996 g_return_if_fail (GTK_IS_STYLE (style));
5997 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
5999 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
6000 area, widget, detail,
6001 edge, x, y, width, height);
6006 * @border_: a #GtkBorder.
6007 * @returns: a copy of @border_.
6009 * Copies a #GtkBorder structure.
6012 gtk_border_copy (const GtkBorder *border)
6014 return (GtkBorder *)g_memdup (border, sizeof (GtkBorder));
6019 * @border_: a #GtkBorder.
6021 * Frees a #GtkBorder structure.
6024 gtk_border_free (GtkBorder *border)
6030 gtk_border_get_type (void)
6032 static GType our_type = 0;
6035 our_type = g_boxed_type_register_static ("GtkBorder",
6036 (GBoxedCopyFunc) gtk_border_copy,
6037 (GBoxedFreeFunc) gtk_border_free);
6043 gtk_style_get_font_internal (GtkStyle *style)
6045 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
6047 if (style->private_font && style->private_font_desc)
6049 if (!style->font_desc ||
6050 !pango_font_description_equal (style->private_font_desc, style->font_desc))
6052 gdk_font_unref (style->private_font);
6053 style->private_font = NULL;
6055 if (style->private_font_desc)
6057 pango_font_description_free (style->private_font_desc);
6058 style->private_font_desc = NULL;
6063 if (!style->private_font)
6065 GdkDisplay *display;
6067 if (style->colormap)
6069 display = gdk_screen_get_display (gdk_colormap_get_screen (style->colormap));
6073 display = gdk_display_get_default ();
6074 GTK_NOTE (MULTIHEAD,
6075 g_warning ("gtk_style_get_font() should not be called on an unattached style"));
6078 if (style->font_desc)
6080 style->private_font = gdk_font_from_description_for_display (display, style->font_desc);
6081 style->private_font_desc = pango_font_description_copy (style->font_desc);
6084 if (!style->private_font)
6085 style->private_font = gdk_font_load_for_display (display, "fixed");
6087 if (!style->private_font)
6088 g_error ("Unable to load \"fixed\" font");
6091 return style->private_font;
6095 * gtk_style_get_font:
6096 * @style: a #GtkStyle
6098 * Gets the #GdkFont to use for the given style. This is
6099 * meant only as a replacement for direct access to @style->font
6100 * and should not be used in new code. New code should
6101 * use @style->font_desc instead.
6103 * Return value: the #GdkFont for the style. This font is owned
6104 * by the style; if you want to keep around a copy, you must
6105 * call gdk_font_ref().
6108 gtk_style_get_font (GtkStyle *style)
6110 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
6112 return gtk_style_get_font_internal (style);
6116 * gtk_style_set_font:
6117 * @style: a #GtkStyle.
6118 * @font: a #GdkFont, or %NULL to use the #GdkFont corresponding
6119 * to style->font_desc.
6121 * Sets the #GdkFont to use for a given style. This is
6122 * meant only as a replacement for direct access to style->font
6123 * and should not be used in new code. New code should
6124 * use style->font_desc instead.
6127 gtk_style_set_font (GtkStyle *style,
6132 g_return_if_fail (GTK_IS_STYLE (style));
6134 old_font = style->private_font;
6136 style->private_font = font;
6138 gdk_font_ref (font);
6141 gdk_font_unref (old_font);
6143 if (style->private_font_desc)
6145 pango_font_description_free (style->private_font_desc);
6146 style->private_font_desc = NULL;
6150 typedef struct _CursorInfo CursorInfo;
6156 GdkGC *secondary_gc;
6160 style_unrealize_cursor_gcs (GtkStyle *style)
6164 cursor_info = g_object_get_data (G_OBJECT (style), "gtk-style-cursor-info");
6167 if (cursor_info->primary_gc)
6168 gtk_gc_release (cursor_info->primary_gc);
6170 if (cursor_info->secondary_gc)
6171 gtk_gc_release (cursor_info->secondary_gc);
6173 g_free (cursor_info);
6174 g_object_set_data (G_OBJECT (style), "gtk-style-cursor-info", NULL);
6179 make_cursor_gc (GtkWidget *widget,
6180 const gchar *property_name,
6183 GdkGCValues gc_values;
6184 GdkGCValuesMask gc_values_mask;
6185 GdkColor *cursor_color;
6187 gtk_widget_style_get (widget, property_name, &cursor_color, NULL);
6189 gc_values_mask = GDK_GC_FOREGROUND;
6192 gc_values.foreground = *cursor_color;
6193 gdk_color_free (cursor_color);
6196 gc_values.foreground = *fallback;
6198 gdk_rgb_find_color (widget->style->colormap, &gc_values.foreground);
6199 return gtk_gc_get (widget->style->depth, widget->style->colormap, &gc_values, gc_values_mask);
6203 * _gtk_get_insertion_cursor_gc:
6204 * @widget: a #GtkWidget
6205 * @is_primary: if the cursor should be the primary cursor color.
6207 * Get a GC suitable for drawing the primary or secondary text
6210 * Note: the return value is ref'ed because calls to this function
6211 * on other widgets could result in this the GC being released
6212 * which would be an unexpected side effect. If made public,
6213 * this function should possibly be called create_insertion_cursor_gc().
6215 * Return value: an appropriate #GdkGC. Call g_object_unref() on
6216 * the gc when you are done with it; this GC may be shared with
6217 * other users, so you must not modify the GC except for temporarily
6218 * setting the clip before drawing with the GC, and then unsetting the clip
6222 _gtk_get_insertion_cursor_gc (GtkWidget *widget,
6223 gboolean is_primary)
6225 CursorInfo *cursor_info;
6227 cursor_info = g_object_get_data (G_OBJECT (widget->style), "gtk-style-cursor-info");
6230 cursor_info = g_new (CursorInfo, 1);
6231 g_object_set_data (G_OBJECT (widget->style), "gtk-style-cursor-info", cursor_info);
6232 cursor_info->primary_gc = NULL;
6233 cursor_info->secondary_gc = NULL;
6234 cursor_info->for_type = G_TYPE_INVALID;
6237 /* We have to keep track of the type because gtk_widget_style_get()
6238 * can return different results when called on the same property and
6239 * same style but for different widgets. :-(. That is,
6240 * GtkEntry::cursor-color = "red" in a style will modify the cursor
6241 * color for entries but not for text view.
6243 if (cursor_info->for_type != G_OBJECT_TYPE (widget))
6245 cursor_info->for_type = G_OBJECT_TYPE (widget);
6246 if (cursor_info->primary_gc)
6248 gtk_gc_release (cursor_info->primary_gc);
6249 cursor_info->primary_gc = NULL;
6251 if (cursor_info->secondary_gc)
6253 gtk_gc_release (cursor_info->secondary_gc);
6254 cursor_info->secondary_gc = NULL;
6260 if (!cursor_info->primary_gc)
6261 cursor_info->primary_gc = make_cursor_gc (widget,
6263 &widget->style->black);
6265 return g_object_ref (cursor_info->primary_gc);
6269 static GdkColor gray = { 0, 0x8888, 0x8888, 0x8888 };
6271 if (!cursor_info->secondary_gc)
6272 cursor_info->secondary_gc = make_cursor_gc (widget,
6273 "secondary-cursor-color",
6276 return g_object_ref (cursor_info->secondary_gc);
6281 * _gtk_draw_insertion_cursor:
6282 * @widget: a #GtkWidget
6283 * @drawable: a #GdkDrawable
6285 * @location: location where to draw the cursor (@location->width is ignored)
6286 * @direction: whether the cursor is left-to-right or
6287 * right-to-left. Should never be #GTK_TEXT_DIR_NONE
6288 * @draw_arrow: %TRUE to draw a directional arrow on the
6289 * cursor. Should be %FALSE unless the cursor is split.
6291 * Draws a text caret on @drawable at @location. This is not a style function
6292 * but merely a convenience function for drawing the standard cursor shape.
6295 _gtk_draw_insertion_cursor (GtkWidget *widget,
6296 GdkDrawable *drawable,
6298 GdkRectangle *location,
6299 GtkTextDirection direction,
6300 gboolean draw_arrow)
6306 gfloat cursor_aspect_ratio;
6309 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
6311 gtk_widget_style_get (widget, "cursor-aspect-ratio", &cursor_aspect_ratio, NULL);
6313 stem_width = location->height * cursor_aspect_ratio + 1;
6314 arrow_width = stem_width + 1;
6316 /* put (stem_width % 2) on the proper side of the cursor */
6317 if (direction == GTK_TEXT_DIR_LTR)
6318 offset = stem_width / 2;
6320 offset = stem_width - stem_width / 2;
6322 for (i = 0; i < stem_width; i++)
6323 gdk_draw_line (drawable, gc,
6324 location->x + i - offset, location->y,
6325 location->x + i - offset, location->y + location->height - 1);
6329 if (direction == GTK_TEXT_DIR_RTL)
6331 x = location->x - offset - 1;
6332 y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
6334 for (i = 0; i < arrow_width; i++)
6336 gdk_draw_line (drawable, gc,
6338 x, y + 2 * arrow_width - i - 1);
6342 else if (direction == GTK_TEXT_DIR_LTR)
6344 x = location->x + stem_width - offset;
6345 y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
6347 for (i = 0; i < arrow_width; i++)
6349 gdk_draw_line (drawable, gc,
6351 x, y + 2 * arrow_width - i - 1);