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);
317 * Data for default check and radio buttons
320 static GtkRequisition default_option_indicator_size = { 7, 13 };
321 static GtkBorder default_option_indicator_spacing = { 7, 5, 2, 2 };
323 #define INDICATOR_PART_SIZE 13
333 CHECK_INCONSISTENT_AA,
334 CHECK_INCONSISTENT_TEXT,
341 RADIO_INCONSISTENT_AA,
342 RADIO_INCONSISTENT_TEXT
346 * Extracted from check-13.png, width=13, height=13
348 static guchar check_black_bits[] = {
349 0x00,0x00,0xfe,0x0f,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
350 0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x00,0x00,0x00,0x00};
351 static guchar check_dark_bits[] = {
352 0xff,0x1f,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
353 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x00,0x00};
354 static guchar check_mid_bits[] = {
355 0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,
356 0x08,0x00,0x08,0x00,0x08,0x00,0x08,0xfc,0x0f,0x00,0x00,0x00,0x00};
357 static guchar check_light_bits[] = {
358 0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
359 0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0xfe,0x1f,0x00,0x00};
360 static guchar check_text_bits[] = {
361 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x03,0x80,0x01,0x80,0x00,0x58,
362 0x00,0x60,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
363 static guchar check_aa_bits[] = {
364 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x58,0x00,0xa0,
365 0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
366 static guchar check_base_bits[] = {
367 0x00,0x00,0x00,0x00,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,
368 0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0x00,0x00,0x00,0x00,0x00,0x00};
371 * Extracted from check-13-inconsistent-ssp.png, width=13, height=13
373 static guchar check_inconsistent_text_bits[] = {
374 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,0x03,0xf8,
375 0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
376 static guchar check_inconsistent_aa_bits[] = {
377 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
378 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
381 * Extracted from radio-13.png, width=13, height=13
383 static guchar radio_black_bits[] = {
384 0x00,0x00,0xf0,0x01,0x0c,0x02,0x04,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
385 0x00,0x02,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0d,0x08};
386 static guchar radio_dark_bits[] = {
387 0xf0,0x00,0x0c,0x02,0x02,0x04,0x02,0x04,0x01,0x08,0x01,0x08,0x01,0x08,0x01,
388 0x08,0x00,0x08,0x02,0x04,0x0c,0x06,0xf0,0x01,0x00,0x00,0x00,0x00};
389 static guchar radio_mid_bits[] = {
390 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
391 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
392 static guchar radio_light_bits[] = {
393 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x10,0x00,
394 0x10,0x00,0x10,0x00,0x08,0x00,0x08,0x00,0x06,0xe0,0x01,0x00,0x00};
395 static guchar radio_text_bits[] = {
396 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x00,0xf0,0x01,0xf0,0x01,0xf0,
397 0x01,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
400 * radio_aa_bits is currently not used, since it is all zeros.
402 static guchar radio_aa_bits[] = {
403 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
404 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
406 static guchar radio_base_bits[] = {
407 0x00,0x00,0x00,0x00,0xf0,0x01,0xf8,0x03,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,
408 0x07,0xfc,0x07,0xf8,0x03,0xf0,0x01,0x00,0x00,0x00,0x00,0x00,0x00};
411 * Extracted from radio-13.png, width=13, height=13
413 static guchar radio_inconsistent_text_bits[] = {
414 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,0x03,0x00,
415 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
416 static guchar radio_inconsistent_aa_bits[] = {
417 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,0x03,0x00,0x00,0xf8,
418 0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
422 GList *bmap_list; /* list of GdkBitmap */
423 } indicator_parts[] = {
424 { check_aa_bits, NULL },
425 { check_base_bits, NULL },
426 { check_black_bits, NULL },
427 { check_dark_bits, NULL },
428 { check_light_bits, NULL },
429 { check_mid_bits, NULL },
430 { check_text_bits, NULL },
431 { check_inconsistent_aa_bits, NULL },
432 { check_inconsistent_text_bits, NULL },
433 { radio_base_bits, NULL },
434 { radio_black_bits, NULL },
435 { radio_dark_bits, NULL },
436 { radio_light_bits, NULL },
437 { radio_mid_bits, NULL },
438 { radio_text_bits, NULL },
439 { radio_inconsistent_aa_bits, NULL },
440 { radio_inconsistent_text_bits, NULL },
443 /* --- variables --- */
444 static GdkColor gtk_default_normal_fg = { 0, 0, 0, 0 };
445 static GdkColor gtk_default_active_fg = { 0, 0, 0, 0 };
446 static GdkColor gtk_default_prelight_fg = { 0, 0, 0, 0 };
447 static GdkColor gtk_default_selected_fg = { 0, 0xffff, 0xffff, 0xffff };
448 static GdkColor gtk_default_insensitive_fg = { 0, 0x7530, 0x7530, 0x7530 };
450 static GdkColor gtk_default_normal_bg = { 0, 0xd6d6, 0xd6d6, 0xd6d6 };
451 static GdkColor gtk_default_active_bg = { 0, 0xc350, 0xc350, 0xc350 };
452 static GdkColor gtk_default_prelight_bg = { 0, 0xea60, 0xea60, 0xea60 };
453 static GdkColor gtk_default_selected_bg = { 0, 0, 0, 0x9c40 };
454 static GdkColor gtk_default_insensitive_bg = { 0, 0xd6d6, 0xd6d6, 0xd6d6 };
455 static GdkColor gtk_default_selected_base = { 0, 0xa4a4, 0xdfdf, 0xffff };
456 static GdkColor gtk_default_active_base = { 0, 0xbcbc, 0xd2d2, 0xeeee };
458 static gpointer parent_class = NULL;
461 /* --- functions --- */
463 gtk_style_get_type (void)
465 static GType style_type = 0;
469 static const GTypeInfo style_info =
471 sizeof (GtkStyleClass),
472 (GBaseInitFunc) NULL,
473 (GBaseFinalizeFunc) NULL,
474 (GClassInitFunc) gtk_style_class_init,
475 NULL, /* class_finalize */
476 NULL, /* class_data */
479 (GInstanceInitFunc) gtk_style_init,
482 style_type = g_type_register_static (G_TYPE_OBJECT, "GtkStyle",
490 * _gtk_style_init_for_settings:
491 * @style: a #GtkStyle
492 * @settings: a #GtkSettings
494 * Initializes the font description in @style accoridng to the default
495 * font name of @settings. This is called for gtk_style_new() with
496 * the settings for the default screen (if any); if we are creating
497 * a style for a particular screen, we then call it again in a
498 * location where we know the correct settings.
499 * The reason for this is that gtk_rc_style_create_style() doesn't
500 * take the screen for an argument.
503 _gtk_style_init_for_settings (GtkStyle *style,
504 GtkSettings *settings)
506 const gchar *font_name = _gtk_rc_context_get_default_font_name (settings);
508 if (style->font_desc)
509 pango_font_description_free (style->font_desc);
511 style->font_desc = pango_font_description_from_string (font_name);
513 if (!pango_font_description_get_family (style->font_desc))
515 g_warning ("Default font does not have a family set");
516 pango_font_description_set_family (style->font_desc, "Sans");
518 if (pango_font_description_get_size (style->font_desc) <= 0)
520 g_warning ("Default font does not have a positive size");
521 pango_font_description_set_size (style->font_desc, 10 * PANGO_SCALE);
526 gtk_style_init (GtkStyle *style)
530 GtkSettings *settings = gtk_settings_get_default ();
533 _gtk_style_init_for_settings (style, settings);
535 style->font_desc = pango_font_description_from_string ("Sans 10");
537 style->attach_count = 0;
538 style->colormap = NULL;
541 style->black.red = 0;
542 style->black.green = 0;
543 style->black.blue = 0;
545 style->white.red = 65535;
546 style->white.green = 65535;
547 style->white.blue = 65535;
549 style->black_gc = NULL;
550 style->white_gc = NULL;
552 style->fg[GTK_STATE_NORMAL] = gtk_default_normal_fg;
553 style->fg[GTK_STATE_ACTIVE] = gtk_default_active_fg;
554 style->fg[GTK_STATE_PRELIGHT] = gtk_default_prelight_fg;
555 style->fg[GTK_STATE_SELECTED] = gtk_default_selected_fg;
556 style->fg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
558 style->bg[GTK_STATE_NORMAL] = gtk_default_normal_bg;
559 style->bg[GTK_STATE_ACTIVE] = gtk_default_active_bg;
560 style->bg[GTK_STATE_PRELIGHT] = gtk_default_prelight_bg;
561 style->bg[GTK_STATE_SELECTED] = gtk_default_selected_bg;
562 style->bg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg;
564 for (i = 0; i < 4; i++)
566 style->text[i] = style->fg[i];
567 style->base[i] = style->white;
570 style->base[GTK_STATE_SELECTED] = gtk_default_selected_base;
571 style->text[GTK_STATE_SELECTED] = style->black;
572 style->base[GTK_STATE_ACTIVE] = gtk_default_active_base;
573 style->text[GTK_STATE_ACTIVE] = style->black;
574 style->base[GTK_STATE_INSENSITIVE] = gtk_default_prelight_bg;
575 style->text[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
577 for (i = 0; i < 5; i++)
578 style->bg_pixmap[i] = NULL;
580 style->rc_style = NULL;
582 for (i = 0; i < 5; i++)
584 style->fg_gc[i] = NULL;
585 style->bg_gc[i] = NULL;
586 style->light_gc[i] = NULL;
587 style->dark_gc[i] = NULL;
588 style->mid_gc[i] = NULL;
589 style->text_gc[i] = NULL;
590 style->base_gc[i] = NULL;
591 style->text_aa_gc[i] = NULL;
594 style->xthickness = 2;
595 style->ythickness = 2;
597 style->property_cache = NULL;
601 gtk_style_class_init (GtkStyleClass *klass)
603 GObjectClass *object_class = G_OBJECT_CLASS (klass);
605 parent_class = g_type_class_peek_parent (klass);
607 object_class->finalize = gtk_style_finalize;
609 klass->clone = gtk_style_real_clone;
610 klass->copy = gtk_style_real_copy;
611 klass->init_from_rc = gtk_style_real_init_from_rc;
612 klass->realize = gtk_style_real_realize;
613 klass->unrealize = gtk_style_real_unrealize;
614 klass->set_background = gtk_style_real_set_background;
615 klass->render_icon = gtk_default_render_icon;
617 klass->draw_hline = gtk_default_draw_hline;
618 klass->draw_vline = gtk_default_draw_vline;
619 klass->draw_shadow = gtk_default_draw_shadow;
620 klass->draw_polygon = gtk_default_draw_polygon;
621 klass->draw_arrow = gtk_default_draw_arrow;
622 klass->draw_diamond = gtk_default_draw_diamond;
623 klass->draw_string = gtk_default_draw_string;
624 klass->draw_box = gtk_default_draw_box;
625 klass->draw_flat_box = gtk_default_draw_flat_box;
626 klass->draw_check = gtk_default_draw_check;
627 klass->draw_option = gtk_default_draw_option;
628 klass->draw_tab = gtk_default_draw_tab;
629 klass->draw_shadow_gap = gtk_default_draw_shadow_gap;
630 klass->draw_box_gap = gtk_default_draw_box_gap;
631 klass->draw_extension = gtk_default_draw_extension;
632 klass->draw_focus = gtk_default_draw_focus;
633 klass->draw_slider = gtk_default_draw_slider;
634 klass->draw_handle = gtk_default_draw_handle;
635 klass->draw_expander = gtk_default_draw_expander;
636 klass->draw_layout = gtk_default_draw_layout;
637 klass->draw_resize_grip = gtk_default_draw_resize_grip;
641 clear_property_cache (GtkStyle *style)
643 if (style->property_cache)
647 for (i = 0; i < style->property_cache->len; i++)
649 PropertyValue *node = &g_array_index (style->property_cache, PropertyValue, i);
651 g_param_spec_unref (node->pspec);
652 g_value_unset (&node->value);
654 g_array_free (style->property_cache, TRUE);
655 style->property_cache = NULL;
660 gtk_style_finalize (GObject *object)
662 GtkStyle *style = GTK_STYLE (object);
664 g_return_if_fail (style->attach_count == 0);
666 clear_property_cache (style);
670 if (style->styles->data != style)
671 g_slist_remove (style->styles, style);
674 GSList *tmp_list = style->styles->next;
678 GTK_STYLE (tmp_list->data)->styles = style->styles->next;
679 tmp_list = tmp_list->next;
681 g_slist_free_1 (style->styles);
685 pango_font_description_free (style->font_desc);
687 if (style->private_font)
688 gdk_font_unref (style->private_font);
690 if (style->private_font_desc)
691 pango_font_description_free (style->private_font_desc);
694 gtk_rc_style_unref (style->rc_style);
696 G_OBJECT_CLASS (parent_class)->finalize (object);
701 gtk_style_copy (GtkStyle *style)
705 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
707 new_style = GTK_STYLE_GET_CLASS (style)->clone (style);
708 GTK_STYLE_GET_CLASS (style)->copy (new_style, style);
714 gtk_style_duplicate (GtkStyle *style)
718 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
720 new_style = gtk_style_copy (style);
722 style->styles = g_slist_append (style->styles, new_style);
723 new_style->styles = style->styles;
730 * @returns: a new #GtkStyle.
732 * Creates a new #GtkStyle.
739 style = g_object_new (GTK_TYPE_STYLE, NULL);
746 * @style: a #GtkStyle.
747 * @window: a #GtkWindow.
748 * @returns: Either @style, or a newly-created #GtkStyle.
749 * If the style is newly created, the style parameter
750 * will be dereferenced, and the new style will have
751 * a reference count belonging to the caller.
753 * Attaches a style to a window; this process allocates the
754 * colors and creates the GC's for the style - it specializes
755 * it to a particular visual and colormap. The process may
756 * involve the creation of a new style if the style has already
757 * been attached to a window with a different style and colormap.
760 * FIXME: The sequence -
761 * create a style => s1
762 * attach s1 to v1, c1 => s1
763 * attach s1 to v2, c2 => s2
764 * detach s1 from v1, c1
765 * attach s1 to v2, c2 => s3
766 * results in two separate, unlinked styles s2 and s3 which
767 * are identical and could be shared. To fix this, we would
768 * want to never remove a style from the list of linked
769 * styles as long as as it has a reference count. However, the
770 * disadvantage of doing it this way means that we would need two
771 * passes through the linked list when attaching (one to check for
772 * matching styles, one to look for empty unattached styles - but
773 * it will almost never be longer than 2 elements.
776 gtk_style_attach (GtkStyle *style,
780 GtkStyle *new_style = NULL;
781 GdkColormap *colormap;
783 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
784 g_return_val_if_fail (window != NULL, NULL);
786 colormap = gdk_drawable_get_colormap (window);
789 style->styles = g_slist_append (NULL, style);
791 styles = style->styles;
794 new_style = styles->data;
796 if (new_style->attach_count == 0)
798 gtk_style_realize (new_style, colormap);
801 else if (new_style->colormap == colormap)
805 styles = styles->next;
810 new_style = gtk_style_duplicate (style);
811 if (gdk_colormap_get_screen (style->colormap) != gdk_colormap_get_screen (colormap) &&
812 new_style->private_font)
814 gdk_font_unref (new_style->private_font);
815 new_style->private_font = NULL;
817 gtk_style_realize (new_style, colormap);
820 /* A style gets a refcount from being attached */
821 if (new_style->attach_count == 0)
822 g_object_ref (new_style);
824 /* Another refcount belongs to the parent */
825 if (style != new_style)
827 g_object_unref (style);
828 g_object_ref (new_style);
831 new_style->attach_count++;
837 gtk_style_detach (GtkStyle *style)
839 g_return_if_fail (GTK_IS_STYLE (style));
841 style->attach_count -= 1;
842 if (style->attach_count == 0)
844 GTK_STYLE_GET_CLASS (style)->unrealize (style);
846 g_object_unref (style->colormap);
847 style->colormap = NULL;
849 if (style->private_font_desc)
851 if (style->private_font)
853 gdk_font_unref (style->private_font);
854 style->private_font = NULL;
857 pango_font_description_free (style->private_font_desc);
858 style->private_font_desc = NULL;
861 g_object_unref (style);
867 * @style: a #GtkStyle.
870 * Deprecated equivalent of g_object_ref().
873 gtk_style_ref (GtkStyle *style)
875 return (GtkStyle *) g_object_ref (style);
880 * @style: a #GtkStyle.
882 * Deprecated equivalent of g_object_unref().
885 gtk_style_unref (GtkStyle *style)
887 g_object_unref (style);
891 gtk_style_realize (GtkStyle *style,
892 GdkColormap *colormap)
894 g_return_if_fail (GTK_IS_STYLE (style));
895 g_return_if_fail (GDK_IS_COLORMAP (colormap));
897 style->colormap = g_object_ref (colormap);
898 style->depth = gdk_colormap_get_visual (colormap)->depth;
900 GTK_STYLE_GET_CLASS (style)->realize (style);
904 gtk_style_lookup_icon_set (GtkStyle *style,
905 const char *stock_id)
909 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
910 g_return_val_if_fail (stock_id != NULL, NULL);
912 iter = style->icon_factories;
915 GtkIconSet *icon_set = gtk_icon_factory_lookup (GTK_ICON_FACTORY (iter->data),
920 iter = g_slist_next (iter);
923 return gtk_icon_factory_lookup_default (stock_id);
928 * @style: a #GtkStyle
929 * @window: a #GdkWindow
930 * @state_type: a state
931 * @x1: the starting x coordinate
932 * @x2: the ending x coordinate
933 * @y: the y coordinate
935 * Draws a horizontal line from (@x1, @y) to (@x2, @y) in @window
936 * using the given style and state.
938 * This function is deprecated, use gtk_paint_hline() instead.
941 gtk_draw_hline (GtkStyle *style,
943 GtkStateType state_type,
948 g_return_if_fail (GTK_IS_STYLE (style));
949 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
951 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, NULL, NULL, NULL, x1, x2, y);
957 * @style: a #GtkStyle
958 * @window: a #GdkWindow
959 * @state_type: a state
960 * @y1_: the starting y coordinate
961 * @y2_: the ending y coordinate
962 * @x: the x coordinate
964 * Draws a vertical line from (@x, @y1_) to (@x, @y2_) in @window
965 * using the given style and state.
967 * This function is deprecated, use gtk_paint_vline() instead.
970 gtk_draw_vline (GtkStyle *style,
972 GtkStateType state_type,
977 g_return_if_fail (GTK_IS_STYLE (style));
978 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
980 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, NULL, NULL, NULL, y1, y2, x);
985 * @style: a #GtkStyle
986 * @window: a #GdkWindow
987 * @state_type: a state
988 * @shadow_type: type of shadow to draw
989 * @x: x origin of the rectangle
990 * @y: y origin of the rectangle
991 * @width: width of the rectangle
992 * @height: width of the rectangle
994 * Draws a shadow around the given rectangle in @window
995 * using the given style and state and shadow type.
997 * This function is deprecated, use gtk_paint_shadow() instead.
1000 gtk_draw_shadow (GtkStyle *style,
1002 GtkStateType state_type,
1003 GtkShadowType shadow_type,
1009 g_return_if_fail (GTK_IS_STYLE (style));
1010 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
1012 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1017 * @style: a #GtkStyle
1018 * @window: a #GdkWindow
1019 * @state_type: a state
1020 * @shadow_type: type of shadow to draw
1021 * @points: an array of #GdkPoint<!-- -->s
1022 * @npoints: length of @points
1023 * @fill: %TRUE if the polygon should be filled
1025 * Draws a polygon on @window with the given parameters.
1027 * This function is deprecated, use gtk_paint_polygon() instead.
1030 gtk_draw_polygon (GtkStyle *style,
1032 GtkStateType state_type,
1033 GtkShadowType shadow_type,
1038 g_return_if_fail (GTK_IS_STYLE (style));
1039 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_polygon != NULL);
1041 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, NULL, NULL, NULL, points, npoints, fill);
1046 * @style: a #GtkStyle
1047 * @window: a #GdkWindow
1048 * @state_type: a state
1049 * @shadow_type: the type of shadow to draw
1050 * @arrow_type: the type of arrow to draw
1051 * @fill: %TRUE if the arrow tip should be filled
1052 * @x: x origin of the rectangle to draw the arrow in
1053 * @y: y origin of the rectangle to draw the arrow in
1054 * @width: width of the rectangle to draw the arrow in
1055 * @height: height of the rectangle to draw the arrow in
1057 * Draws an arrow in the given rectangle on @window using the given
1058 * parameters. @arrow_type determines the direction of the arrow.
1060 * This function is deprecated, use gtk_paint_arrow() instead.
1063 gtk_draw_arrow (GtkStyle *style,
1065 GtkStateType state_type,
1066 GtkShadowType shadow_type,
1067 GtkArrowType arrow_type,
1074 g_return_if_fail (GTK_IS_STYLE (style));
1075 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
1077 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, NULL, NULL, NULL, arrow_type, fill, x, y, width, height);
1082 * @style: a #GtkStyle
1083 * @window: a #GdkWindow
1084 * @state_type: a state
1085 * @shadow_type: the type of shadow to draw
1086 * @x: x origin of the rectangle to draw the diamond in
1087 * @y: y origin of the rectangle to draw the diamond in
1088 * @width: width of the rectangle to draw the diamond in
1089 * @height: height of the rectangle to draw the diamond in
1091 * Draws a diamond in the given rectangle on @window using the given parameters.
1093 * This function is deprecated, use gtk_paint_diamond() instead.
1096 gtk_draw_diamond (GtkStyle *style,
1098 GtkStateType state_type,
1099 GtkShadowType shadow_type,
1105 g_return_if_fail (GTK_IS_STYLE (style));
1106 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
1108 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1113 * @style: a #GtkStyle
1114 * @window: a #GdkWindow
1115 * @state_type: a state
1118 * @string: the string to draw
1120 * Draws a text string on @window with the given parameters.
1122 * This function is deprecated, use gtk_paint_layout() instead.
1125 gtk_draw_string (GtkStyle *style,
1127 GtkStateType state_type,
1130 const gchar *string)
1132 g_return_if_fail (GTK_IS_STYLE (style));
1133 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
1135 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, NULL, NULL, NULL, x, y, string);
1140 * @style: a #GtkStyle
1141 * @window: a #GdkWindow
1142 * @state_type: a state
1143 * @shadow_type: the type of shadow to draw
1144 * @x: x origin of the box
1145 * @y: y origin of the box
1146 * @width: the width of the box
1147 * @height: the height of the box
1149 * Draws a box on @window with the given parameters.
1151 * This function is deprecated, use gtk_paint_box() instead.
1154 gtk_draw_box (GtkStyle *style,
1156 GtkStateType state_type,
1157 GtkShadowType shadow_type,
1163 g_return_if_fail (GTK_IS_STYLE (style));
1164 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
1166 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1170 * gtk_draw_flat_box:
1171 * @style: a #GtkStyle
1172 * @window: a #GdkWindow
1173 * @state_type: a state
1174 * @shadow_type: the type of shadow to draw
1175 * @x: x origin of the box
1176 * @y: y origin of the box
1177 * @width: the width of the box
1178 * @height: the height of the box
1180 * Draws a flat box on @window with the given parameters.
1182 * This function is deprecated, use gtk_paint_flat_box() instead.
1185 gtk_draw_flat_box (GtkStyle *style,
1187 GtkStateType state_type,
1188 GtkShadowType shadow_type,
1194 g_return_if_fail (GTK_IS_STYLE (style));
1195 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
1197 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1202 * @style: a #GtkStyle
1203 * @window: a #GdkWindow
1204 * @state_type: a state
1205 * @shadow_type: the type of shadow to draw
1206 * @x: x origin of the rectangle to draw the check in
1207 * @y: y origin of the rectangle to draw the check in
1208 * @width: the width of the rectangle to draw the check in
1209 * @height: the height of the rectangle to draw the check in
1211 * Draws a check button indicator in the given rectangle on @window with
1212 * the given parameters.
1214 * This function is deprecated, use gtk_paint_check() instead.
1217 gtk_draw_check (GtkStyle *style,
1219 GtkStateType state_type,
1220 GtkShadowType shadow_type,
1226 g_return_if_fail (GTK_IS_STYLE (style));
1227 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
1229 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1234 * @style: a #GtkStyle
1235 * @window: a #GdkWindow
1236 * @state_type: a state
1237 * @shadow_type: the type of shadow to draw
1238 * @x: x origin of the rectangle to draw the option in
1239 * @y: y origin of the rectangle to draw the option in
1240 * @width: the width of the rectangle to draw the option in
1241 * @height: the height of the rectangle to draw the option in
1243 * Draws a radio button indicator in the given rectangle on @window with
1244 * the given parameters.
1246 * This function is deprecated, use gtk_paint_option() instead.
1249 gtk_draw_option (GtkStyle *style,
1251 GtkStateType state_type,
1252 GtkShadowType shadow_type,
1258 g_return_if_fail (GTK_IS_STYLE (style));
1259 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
1261 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1266 * @style: a #GtkStyle
1267 * @window: a #GdkWindow
1268 * @state_type: a state
1269 * @shadow_type: the type of shadow to draw
1270 * @x: x origin of the rectangle to draw the tab in
1271 * @y: y origin of the rectangle to draw the tab in
1272 * @width: the width of the rectangle to draw the tab in
1273 * @height: the height of the rectangle to draw the tab in
1275 * Draws an option menu tab (i.e. the up and down pointing arrows)
1276 * in the given rectangle on @window using the given parameters.
1278 * This function is deprecated, use gtk_paint_tab() instead.
1281 gtk_draw_tab (GtkStyle *style,
1283 GtkStateType state_type,
1284 GtkShadowType shadow_type,
1290 g_return_if_fail (GTK_IS_STYLE (style));
1291 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
1293 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1297 gtk_draw_shadow_gap (GtkStyle *style,
1299 GtkStateType state_type,
1300 GtkShadowType shadow_type,
1305 GtkPositionType gap_side,
1309 g_return_if_fail (GTK_IS_STYLE (style));
1310 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
1312 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);
1316 gtk_draw_box_gap (GtkStyle *style,
1318 GtkStateType state_type,
1319 GtkShadowType shadow_type,
1324 GtkPositionType gap_side,
1328 g_return_if_fail (GTK_IS_STYLE (style));
1329 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
1331 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);
1335 gtk_draw_extension (GtkStyle *style,
1337 GtkStateType state_type,
1338 GtkShadowType shadow_type,
1343 GtkPositionType gap_side)
1345 g_return_if_fail (GTK_IS_STYLE (style));
1346 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
1348 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side);
1353 * @style: a #GtkStyle
1354 * @window: a #GdkWindow
1355 * @x: the x origin of the rectangle around which to draw a focus indicator
1356 * @y: the y origin of the rectangle around which to draw a focus indicator
1357 * @width: the width of the rectangle around which to draw a focus indicator
1358 * @height: the height of the rectangle around which to draw a focus indicator
1360 * Draws a focus indicator around the given rectangle on @window using the
1363 * This function is deprecated, use gtk_paint_focus() instead.
1366 gtk_draw_focus (GtkStyle *style,
1373 g_return_if_fail (GTK_IS_STYLE (style));
1374 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
1376 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, GTK_STATE_NORMAL, NULL, NULL, NULL, x, y, width, height);
1380 gtk_draw_slider (GtkStyle *style,
1382 GtkStateType state_type,
1383 GtkShadowType shadow_type,
1388 GtkOrientation orientation)
1390 g_return_if_fail (GTK_IS_STYLE (style));
1391 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
1393 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
1397 gtk_draw_handle (GtkStyle *style,
1399 GtkStateType state_type,
1400 GtkShadowType shadow_type,
1405 GtkOrientation orientation)
1407 g_return_if_fail (GTK_IS_STYLE (style));
1408 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
1410 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
1414 gtk_draw_expander (GtkStyle *style,
1416 GtkStateType state_type,
1419 GtkExpanderStyle expander_style)
1421 g_return_if_fail (GTK_IS_STYLE (style));
1422 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
1424 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type,
1426 x, y, expander_style);
1430 gtk_draw_layout (GtkStyle *style,
1432 GtkStateType state_type,
1436 PangoLayout *layout)
1438 g_return_if_fail (GTK_IS_STYLE (style));
1439 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
1441 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text,
1447 * gtk_draw_resize_grip:
1448 * @style: a #GtkStyle
1449 * @window: a #GdkWindow
1450 * @state_type: a state
1451 * @edge: the edge in which to draw the resize grip, currently only
1452 * %GTK_WINDOW_EDGE_SOUTH_EAST is implemented
1453 * @x: the x origin of the rectangle in which to draw the resize grip
1454 * @y: the y origin of the rectangle in which to draw the resize grip
1455 * @width: the width of the rectangle in which to draw the resize grip
1456 * @height: the height of the rectangle in which to draw the resize grip
1458 * Draws a resize grip in the given rectangle on @window using the given
1461 * This function is deprecated, use gtk_paint_resize_grip() instead.
1464 gtk_draw_resize_grip (GtkStyle *style,
1466 GtkStateType state_type,
1473 g_return_if_fail (GTK_IS_STYLE (style));
1474 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
1476 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
1479 x, y, width, height);
1484 * gtk_style_set_background:
1485 * @style: a #GtkStyle
1486 * @window: a #GdkWindow
1487 * @state_type: a state
1489 * Sets the background of @window to the background color or pixmap
1490 * specified by @style for the given state.
1493 gtk_style_set_background (GtkStyle *style,
1495 GtkStateType state_type)
1497 g_return_if_fail (GTK_IS_STYLE (style));
1498 g_return_if_fail (window != NULL);
1500 GTK_STYLE_GET_CLASS (style)->set_background (style, window, state_type);
1503 /* Default functions */
1505 gtk_style_real_clone (GtkStyle *style)
1507 return GTK_STYLE (g_object_new (G_OBJECT_TYPE (style), NULL));
1511 gtk_style_real_copy (GtkStyle *style,
1516 for (i = 0; i < 5; i++)
1518 style->fg[i] = src->fg[i];
1519 style->bg[i] = src->bg[i];
1520 style->text[i] = src->text[i];
1521 style->base[i] = src->base[i];
1523 style->bg_pixmap[i] = src->bg_pixmap[i];
1526 if (style->private_font)
1527 gdk_font_unref (style->private_font);
1528 style->private_font = src->private_font;
1529 if (style->private_font)
1530 gdk_font_ref (style->private_font);
1532 if (style->font_desc)
1533 pango_font_description_free (style->font_desc);
1535 style->font_desc = pango_font_description_copy (src->font_desc);
1537 style->font_desc = NULL;
1539 style->xthickness = src->xthickness;
1540 style->ythickness = src->ythickness;
1542 if (style->rc_style)
1543 gtk_rc_style_unref (style->rc_style);
1544 style->rc_style = src->rc_style;
1546 gtk_rc_style_ref (src->rc_style);
1548 /* don't copy, just clear cache */
1549 clear_property_cache (style);
1553 gtk_style_real_init_from_rc (GtkStyle *style,
1554 GtkRcStyle *rc_style)
1558 /* cache _should_ be still empty */
1559 clear_property_cache (style);
1561 if (rc_style->font_desc)
1562 pango_font_description_merge (style->font_desc, rc_style->font_desc, TRUE);
1564 for (i = 0; i < 5; i++)
1566 if (rc_style->color_flags[i] & GTK_RC_FG)
1567 style->fg[i] = rc_style->fg[i];
1568 if (rc_style->color_flags[i] & GTK_RC_BG)
1569 style->bg[i] = rc_style->bg[i];
1570 if (rc_style->color_flags[i] & GTK_RC_TEXT)
1571 style->text[i] = rc_style->text[i];
1572 if (rc_style->color_flags[i] & GTK_RC_BASE)
1573 style->base[i] = rc_style->base[i];
1576 if (rc_style->xthickness >= 0)
1577 style->xthickness = rc_style->xthickness;
1578 if (rc_style->ythickness >= 0)
1579 style->ythickness = rc_style->ythickness;
1581 if (rc_style->icon_factories)
1585 style->icon_factories = g_slist_copy (rc_style->icon_factories);
1587 iter = style->icon_factories;
1588 while (iter != NULL)
1590 g_object_ref (iter->data);
1591 iter = g_slist_next (iter);
1597 style_property_values_cmp (gconstpointer bsearch_node1,
1598 gconstpointer bsearch_node2)
1600 const PropertyValue *val1 = bsearch_node1;
1601 const PropertyValue *val2 = bsearch_node2;
1603 if (val1->widget_type == val2->widget_type)
1604 return val1->pspec < val2->pspec ? -1 : val1->pspec == val2->pspec ? 0 : 1;
1606 return val1->widget_type < val2->widget_type ? -1 : 1;
1610 _gtk_style_peek_property_value (GtkStyle *style,
1613 GtkRcPropertyParser parser)
1615 PropertyValue *pcache, key = { 0, NULL, { 0, } };
1616 const GtkRcProperty *rcprop = NULL;
1619 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1620 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), NULL);
1621 g_return_val_if_fail (g_type_is_a (pspec->owner_type, GTK_TYPE_WIDGET), NULL);
1622 g_return_val_if_fail (g_type_is_a (widget_type, pspec->owner_type), NULL);
1624 key.widget_type = widget_type;
1627 /* need value cache array */
1628 if (!style->property_cache)
1629 style->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
1632 pcache = bsearch (&key,
1633 style->property_cache->data, style->property_cache->len,
1634 sizeof (PropertyValue), style_property_values_cmp);
1636 return &pcache->value;
1640 while (i < style->property_cache->len &&
1641 style_property_values_cmp (&key, &g_array_index (style->property_cache, PropertyValue, i)) >= 0)
1644 g_array_insert_val (style->property_cache, i, key);
1645 pcache = &g_array_index (style->property_cache, PropertyValue, i);
1647 /* cache miss, initialize value type, then set contents */
1648 g_param_spec_ref (pcache->pspec);
1649 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1651 /* value provided by rc style? */
1652 if (style->rc_style)
1654 GQuark prop_quark = g_quark_from_string (pspec->name);
1658 rcprop = _gtk_rc_style_lookup_rc_property (style->rc_style,
1659 g_type_qname (widget_type),
1663 widget_type = g_type_parent (widget_type);
1665 while (g_type_is_a (widget_type, pspec->owner_type));
1668 /* when supplied by rc style, we need to convert */
1669 if (rcprop && !_gtk_settings_parse_convert (parser, &rcprop->value,
1670 pspec, &pcache->value))
1672 gchar *contents = g_strdup_value_contents (&rcprop->value);
1674 g_message ("%s: failed to retrieve property `%s::%s' of type `%s' from rc file value \"%s\" of type `%s'",
1676 g_type_name (pspec->owner_type), pspec->name,
1677 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1679 G_VALUE_TYPE_NAME (&rcprop->value));
1681 rcprop = NULL; /* needs default */
1684 /* not supplied by rc style (or conversion failed), revert to default */
1686 g_param_value_set_default (pspec, &pcache->value);
1688 return &pcache->value;
1692 load_bg_image (GdkColormap *colormap,
1694 const gchar *filename)
1696 if (strcmp (filename, "<parent>") == 0)
1697 return (GdkPixmap*) GDK_PARENT_RELATIVE;
1700 return gdk_pixmap_colormap_create_from_xpm (NULL, colormap, NULL,
1707 gtk_style_real_realize (GtkStyle *style)
1709 GdkGCValues gc_values;
1710 GdkGCValuesMask gc_values_mask;
1714 for (i = 0; i < 5; i++)
1716 gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT);
1717 gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT);
1719 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
1720 style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
1721 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
1723 style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
1724 style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
1725 style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;
1728 style->black.red = 0x0000;
1729 style->black.green = 0x0000;
1730 style->black.blue = 0x0000;
1731 gdk_colormap_alloc_color (style->colormap, &style->black, FALSE, TRUE);
1733 style->white.red = 0xffff;
1734 style->white.green = 0xffff;
1735 style->white.blue = 0xffff;
1736 gdk_colormap_alloc_color (style->colormap, &style->white, FALSE, TRUE);
1738 gc_values_mask = GDK_GC_FOREGROUND;
1740 gc_values.foreground = style->black;
1741 style->black_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1743 gc_values.foreground = style->white;
1744 style->white_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1746 for (i = 0; i < 5; i++)
1748 if (style->rc_style && style->rc_style->bg_pixmap_name[i])
1749 style->bg_pixmap[i] = load_bg_image (style->colormap,
1751 style->rc_style->bg_pixmap_name[i]);
1753 if (!gdk_colormap_alloc_color (style->colormap, &style->fg[i], FALSE, TRUE))
1754 g_warning ("unable to allocate color: ( %d %d %d )",
1755 style->fg[i].red, style->fg[i].green, style->fg[i].blue);
1756 if (!gdk_colormap_alloc_color (style->colormap, &style->bg[i], FALSE, TRUE))
1757 g_warning ("unable to allocate color: ( %d %d %d )",
1758 style->bg[i].red, style->bg[i].green, style->bg[i].blue);
1759 if (!gdk_colormap_alloc_color (style->colormap, &style->light[i], FALSE, TRUE))
1760 g_warning ("unable to allocate color: ( %d %d %d )",
1761 style->light[i].red, style->light[i].green, style->light[i].blue);
1762 if (!gdk_colormap_alloc_color (style->colormap, &style->dark[i], FALSE, TRUE))
1763 g_warning ("unable to allocate color: ( %d %d %d )",
1764 style->dark[i].red, style->dark[i].green, style->dark[i].blue);
1765 if (!gdk_colormap_alloc_color (style->colormap, &style->mid[i], FALSE, TRUE))
1766 g_warning ("unable to allocate color: ( %d %d %d )",
1767 style->mid[i].red, style->mid[i].green, style->mid[i].blue);
1768 if (!gdk_colormap_alloc_color (style->colormap, &style->text[i], FALSE, TRUE))
1769 g_warning ("unable to allocate color: ( %d %d %d )",
1770 style->text[i].red, style->text[i].green, style->text[i].blue);
1771 if (!gdk_colormap_alloc_color (style->colormap, &style->base[i], FALSE, TRUE))
1772 g_warning ("unable to allocate color: ( %d %d %d )",
1773 style->base[i].red, style->base[i].green, style->base[i].blue);
1774 if (!gdk_colormap_alloc_color (style->colormap, &style->text_aa[i], FALSE, TRUE))
1775 g_warning ("unable to allocate color: ( %d %d %d )",
1776 style->text_aa[i].red, style->text_aa[i].green, style->text_aa[i].blue);
1778 gc_values.foreground = style->fg[i];
1779 style->fg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1781 gc_values.foreground = style->bg[i];
1782 style->bg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1784 gc_values.foreground = style->light[i];
1785 style->light_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1787 gc_values.foreground = style->dark[i];
1788 style->dark_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1790 gc_values.foreground = style->mid[i];
1791 style->mid_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1793 gc_values.foreground = style->text[i];
1794 style->text_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1796 gc_values.foreground = style->base[i];
1797 style->base_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1799 gc_values.foreground = style->text_aa[i];
1800 style->text_aa_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1805 gtk_style_real_unrealize (GtkStyle *style)
1809 gtk_gc_release (style->black_gc);
1810 gtk_gc_release (style->white_gc);
1812 for (i = 0; i < 5; i++)
1814 gtk_gc_release (style->fg_gc[i]);
1815 gtk_gc_release (style->bg_gc[i]);
1816 gtk_gc_release (style->light_gc[i]);
1817 gtk_gc_release (style->dark_gc[i]);
1818 gtk_gc_release (style->mid_gc[i]);
1819 gtk_gc_release (style->text_gc[i]);
1820 gtk_gc_release (style->base_gc[i]);
1821 gtk_gc_release (style->text_aa_gc[i]);
1823 if (style->bg_pixmap[i] && style->bg_pixmap[i] != (GdkPixmap*) GDK_PARENT_RELATIVE)
1824 g_object_unref (style->bg_pixmap[i]);
1827 gdk_colormap_free_colors (style->colormap, style->fg, 5);
1828 gdk_colormap_free_colors (style->colormap, style->bg, 5);
1829 gdk_colormap_free_colors (style->colormap, style->light, 5);
1830 gdk_colormap_free_colors (style->colormap, style->dark, 5);
1831 gdk_colormap_free_colors (style->colormap, style->mid, 5);
1832 gdk_colormap_free_colors (style->colormap, style->text, 5);
1833 gdk_colormap_free_colors (style->colormap, style->base, 5);
1834 gdk_colormap_free_colors (style->colormap, style->text_aa, 5);
1836 style_unrealize_cursor_gcs (style);
1840 gtk_style_real_set_background (GtkStyle *style,
1842 GtkStateType state_type)
1845 gint parent_relative;
1847 if (style->bg_pixmap[state_type])
1849 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1852 parent_relative = TRUE;
1856 pixmap = style->bg_pixmap[state_type];
1857 parent_relative = FALSE;
1860 gdk_window_set_back_pixmap (window, pixmap, parent_relative);
1863 gdk_window_set_background (window, &style->bg[state_type]);
1867 * gtk_style_render_icon:
1868 * @style: a #GtkStyle
1869 * @source: the #GtkIconSource specifying the icon to render
1870 * @direction: a text direction
1872 * @size: the size to render the icon at. A size of (GtkIconSize)-1
1873 * means render at the size of the source and don't scale.
1874 * @widget: the widget
1875 * @detail: a style detail
1876 * @returns: a newly-created #GdkPixbuf containing the rendered icon
1878 * Renders the icon specified by @source at the given @size
1879 * according to the given parameters and returns the result in a
1883 gtk_style_render_icon (GtkStyle *style,
1884 const GtkIconSource *source,
1885 GtkTextDirection direction,
1889 const gchar *detail)
1893 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1894 g_return_val_if_fail (GTK_STYLE_GET_CLASS (style)->render_icon != NULL, NULL);
1896 pixbuf = GTK_STYLE_GET_CLASS (style)->render_icon (style, source, direction, state,
1897 size, widget, detail);
1899 g_return_val_if_fail (pixbuf != NULL, NULL);
1904 /* Default functions */
1906 gtk_style_apply_default_background (GtkStyle *style,
1909 GtkStateType state_type,
1916 GdkRectangle new_rect, old_rect;
1922 old_rect.width = width;
1923 old_rect.height = height;
1925 if (!gdk_rectangle_intersect (area, &old_rect, &new_rect))
1932 new_rect.width = width;
1933 new_rect.height = height;
1936 if (!style->bg_pixmap[state_type] ||
1937 GDK_IS_PIXMAP (window) ||
1938 (!set_bg && style->bg_pixmap[state_type] != (GdkPixmap*) GDK_PARENT_RELATIVE))
1940 GdkGC *gc = style->bg_gc[state_type];
1942 if (style->bg_pixmap[state_type])
1944 gdk_gc_set_fill (gc, GDK_TILED);
1945 gdk_gc_set_tile (gc, style->bg_pixmap[state_type]);
1948 gdk_draw_rectangle (window, gc, TRUE,
1949 new_rect.x, new_rect.y, new_rect.width, new_rect.height);
1950 if (style->bg_pixmap[state_type])
1951 gdk_gc_set_fill (gc, GDK_SOLID);
1957 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1958 gdk_window_set_back_pixmap (window, NULL, TRUE);
1960 gdk_window_set_back_pixmap (window, style->bg_pixmap[state_type], FALSE);
1963 gdk_window_clear_area (window,
1964 new_rect.x, new_rect.y,
1965 new_rect.width, new_rect.height);
1970 scale_or_ref (GdkPixbuf *src,
1974 if (width == gdk_pixbuf_get_width (src) &&
1975 height == gdk_pixbuf_get_height (src))
1977 return g_object_ref (src);
1981 return gdk_pixbuf_scale_simple (src,
1983 GDK_INTERP_BILINEAR);
1988 gtk_default_render_icon (GtkStyle *style,
1989 const GtkIconSource *source,
1990 GtkTextDirection direction,
1994 const gchar *detail)
2000 GdkPixbuf *base_pixbuf;
2002 GtkSettings *settings;
2004 /* Oddly, style can be NULL in this function, because
2005 * GtkIconSet can be used without a style and if so
2006 * it uses this function.
2009 base_pixbuf = gtk_icon_source_get_pixbuf (source);
2011 g_return_val_if_fail (base_pixbuf != NULL, NULL);
2013 if (widget && gtk_widget_has_screen (widget))
2015 screen = gtk_widget_get_screen (widget);
2016 settings = gtk_settings_get_for_screen (screen);
2018 else if (style->colormap)
2020 screen = gdk_colormap_get_screen (style->colormap);
2021 settings = gtk_settings_get_for_screen (screen);
2025 settings = gtk_settings_get_default ();
2026 GTK_NOTE (MULTIHEAD,
2027 g_warning ("Using the default screen for gtk_default_render_icon()"));
2031 if (size != (GtkIconSize) -1 && !gtk_icon_size_lookup_for_settings (settings, size, &width, &height))
2033 g_warning (G_STRLOC ": invalid icon size '%d'", size);
2037 /* If the size was wildcarded, and we're allowed to scale, then scale; otherwise,
2040 if (size != (GtkIconSize)-1 && gtk_icon_source_get_size_wildcarded (source))
2041 scaled = scale_or_ref (base_pixbuf, width, height);
2043 scaled = g_object_ref (base_pixbuf);
2045 /* If the state was wildcarded, then generate a state. */
2046 if (gtk_icon_source_get_state_wildcarded (source))
2048 if (state == GTK_STATE_INSENSITIVE)
2050 stated = gdk_pixbuf_copy (scaled);
2052 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
2055 g_object_unref (scaled);
2057 else if (state == GTK_STATE_PRELIGHT)
2059 stated = gdk_pixbuf_copy (scaled);
2061 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
2064 g_object_unref (scaled);
2078 sanitize_size (GdkWindow *window,
2082 if ((*width == -1) && (*height == -1))
2083 gdk_drawable_get_size (window, width, height);
2084 else if (*width == -1)
2085 gdk_drawable_get_size (window, width, NULL);
2086 else if (*height == -1)
2087 gdk_drawable_get_size (window, NULL, height);
2091 get_indicator_for_screen (GdkDrawable *drawable,
2095 GdkScreen *screen = gdk_drawable_get_screen (drawable);
2099 tmp_list = indicator_parts[part].bmap_list;
2102 bitmap = tmp_list->data;
2104 if (gdk_drawable_get_screen (bitmap) == screen)
2107 tmp_list = tmp_list->next;
2110 bitmap = gdk_bitmap_create_from_data (drawable,
2111 (gchar *)indicator_parts[part].bits,
2112 INDICATOR_PART_SIZE, INDICATOR_PART_SIZE);
2113 indicator_parts[part].bmap_list = g_list_prepend (indicator_parts[part].bmap_list, bitmap);
2119 draw_part (GdkDrawable *drawable,
2127 gdk_gc_set_clip_rectangle (gc, area);
2129 gdk_gc_set_ts_origin (gc, x, y);
2130 gdk_gc_set_stipple (gc, get_indicator_for_screen (drawable, part));
2131 gdk_gc_set_fill (gc, GDK_STIPPLED);
2133 gdk_draw_rectangle (drawable, gc, TRUE, x, y, INDICATOR_PART_SIZE, INDICATOR_PART_SIZE);
2135 gdk_gc_set_fill (gc, GDK_SOLID);
2138 gdk_gc_set_clip_rectangle (gc, NULL);
2142 gtk_default_draw_hline (GtkStyle *style,
2144 GtkStateType state_type,
2147 const gchar *detail,
2152 gint thickness_light;
2153 gint thickness_dark;
2156 g_return_if_fail (GTK_IS_STYLE (style));
2157 g_return_if_fail (window != NULL);
2159 thickness_light = style->ythickness / 2;
2160 thickness_dark = style->ythickness - thickness_light;
2164 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
2165 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
2168 if (detail && !strcmp (detail, "label"))
2170 if (state_type == GTK_STATE_INSENSITIVE)
2171 gdk_draw_line (window, style->white_gc, x1 + 1, y + 1, x2 + 1, y + 1);
2172 gdk_draw_line (window, style->fg_gc[state_type], x1, y, x2, y);
2176 for (i = 0; i < thickness_dark; i++)
2178 gdk_draw_line (window, style->light_gc[state_type], x2 - i - 1, y + i, x2, y + i);
2179 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x2 - i - 1, y + i);
2182 y += thickness_dark;
2183 for (i = 0; i < thickness_light; i++)
2185 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x1 + thickness_light - i - 1, y + i);
2186 gdk_draw_line (window, style->light_gc[state_type], x1 + thickness_light - i - 1, y + i, x2, y + i);
2192 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
2193 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
2199 gtk_default_draw_vline (GtkStyle *style,
2201 GtkStateType state_type,
2204 const gchar *detail,
2209 gint thickness_light;
2210 gint thickness_dark;
2213 g_return_if_fail (GTK_IS_STYLE (style));
2214 g_return_if_fail (window != NULL);
2216 thickness_light = style->xthickness / 2;
2217 thickness_dark = style->xthickness - thickness_light;
2221 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
2222 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
2224 for (i = 0; i < thickness_dark; i++)
2226 gdk_draw_line (window, style->light_gc[state_type], x + i, y2 - i - 1, x + i, y2);
2227 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y2 - i - 1);
2230 x += thickness_dark;
2231 for (i = 0; i < thickness_light; i++)
2233 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y1 + thickness_light - i);
2234 gdk_draw_line (window, style->light_gc[state_type], x + i, y1 + thickness_light - i, x + i, y2);
2238 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
2239 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
2245 draw_thin_shadow (GtkStyle *style,
2256 sanitize_size (window, &width, &height);
2258 gc1 = style->light_gc[state];
2259 gc2 = style->dark_gc[state];
2263 gdk_gc_set_clip_rectangle (gc1, area);
2264 gdk_gc_set_clip_rectangle (gc2, area);
2267 gdk_draw_line (window, gc1,
2268 x, y + height - 1, x + width - 1, y + height - 1);
2269 gdk_draw_line (window, gc1,
2270 x + width - 1, y, x + width - 1, y + height - 1);
2272 gdk_draw_line (window, gc2,
2273 x, y, x + width - 2, y);
2274 gdk_draw_line (window, gc2,
2275 x, y, x, y + height - 2);
2279 gdk_gc_set_clip_rectangle (gc1, NULL);
2280 gdk_gc_set_clip_rectangle (gc2, NULL);
2286 * See http://bugzilla.gnome.org/show_bug.cgi?id=80229
2289 draw_spin_entry_shadow (GtkStyle *style,
2298 gint window_width, window_height;
2299 gboolean focus_inset;
2301 gdk_drawable_get_size (window, &window_width, &window_height);
2304 width = window_width;
2306 height = window_height;
2308 focus_inset = (width < window_width && height < window_height);
2312 gdk_gc_set_clip_rectangle (style->light_gc[state], area);
2313 gdk_gc_set_clip_rectangle (style->dark_gc[state], area);
2314 gdk_gc_set_clip_rectangle (style->black_gc, area);
2315 gdk_gc_set_clip_rectangle (style->bg_gc[state], area);
2316 gdk_gc_set_clip_rectangle (style->base_gc[state], area);
2319 gdk_draw_line (window, style->light_gc[state],
2320 x, y + height - 1, x + width - 1, y + height - 1);
2322 gdk_draw_line (window,
2323 style->base_gc[state],
2324 x + width - 1, y + 1, x + width - 1, y + height - 3);
2328 gdk_draw_line (window, style->bg_gc[state],
2329 x + 1, y + height - 2, x + width - 1, y + height - 2);
2330 gdk_draw_line (window,
2331 style->base_gc[state],
2332 x + width - 2, y + 1, x + width - 2, y + height - 3);
2334 gdk_draw_line (window, style->black_gc,
2335 x + 1, y + 1, x + width - 1, y + 1);
2336 gdk_draw_line (window, style->black_gc,
2337 x + 1, y + 1, x + 1, y + height - 2);
2340 gdk_draw_line (window, style->dark_gc[state],
2341 x, y, x + width - 1, y);
2342 gdk_draw_line (window, style->dark_gc[state],
2343 x, y, x, y + height - 1);
2347 gdk_gc_set_clip_rectangle (style->light_gc[state], NULL);
2348 gdk_gc_set_clip_rectangle (style->dark_gc[state], NULL);
2349 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2350 gdk_gc_set_clip_rectangle (style->bg_gc[state], NULL);
2351 gdk_gc_set_clip_rectangle (style->base_gc[state], NULL);
2357 draw_spinbutton_shadow (GtkStyle *style,
2360 GtkTextDirection direction,
2367 sanitize_size (window, &width, &height);
2371 gdk_gc_set_clip_rectangle (style->black_gc, area);
2372 gdk_gc_set_clip_rectangle (style->bg_gc[state], area);
2373 gdk_gc_set_clip_rectangle (style->dark_gc[state], area);
2374 gdk_gc_set_clip_rectangle (style->light_gc[state], area);
2377 if (direction == GTK_TEXT_DIR_LTR)
2379 gdk_draw_line (window, style->dark_gc[state],
2380 x, y, x + width - 1, y);
2381 gdk_draw_line (window, style->black_gc,
2382 x, y + 1, x + width - 2, y + 1);
2383 gdk_draw_line (window, style->black_gc,
2384 x + width - 2, y + 2, x + width - 2, y + height - 3);
2385 gdk_draw_line (window, style->light_gc[state],
2386 x + width - 1, y + 1, x + width - 1, y + height - 2);
2387 gdk_draw_line (window, style->light_gc[state],
2388 x, y + height - 1, x + width - 1, y + height - 1);
2389 gdk_draw_line (window, style->bg_gc[state],
2390 x, y + height - 2, x + width - 2, y + height - 2);
2391 gdk_draw_line (window, style->black_gc,
2392 x, y + 2, x, y + height - 3);
2396 gdk_draw_line (window, style->dark_gc[state],
2397 x, y, x + width - 1, y);
2398 gdk_draw_line (window, style->dark_gc[state],
2399 x, y + 1, x, y + height - 1);
2400 gdk_draw_line (window, style->black_gc,
2401 x + 1, y + 1, x + width - 1, y + 1);
2402 gdk_draw_line (window, style->black_gc,
2403 x + 1, y + 2, x + 1, y + height - 2);
2404 gdk_draw_line (window, style->black_gc,
2405 x + width - 1, y + 2, x + width - 1, y + height - 3);
2406 gdk_draw_line (window, style->light_gc[state],
2407 x + 1, y + height - 1, x + width - 1, y + height - 1);
2408 gdk_draw_line (window, style->bg_gc[state],
2409 x + 2, y + height - 2, x + width - 1, y + height - 2);
2414 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2415 gdk_gc_set_clip_rectangle (style->bg_gc[state], NULL);
2416 gdk_gc_set_clip_rectangle (style->dark_gc[state], NULL);
2417 gdk_gc_set_clip_rectangle (style->light_gc[state], NULL);
2422 gtk_default_draw_shadow (GtkStyle *style,
2424 GtkStateType state_type,
2425 GtkShadowType shadow_type,
2428 const gchar *detail,
2436 gint thickness_light;
2437 gint thickness_dark;
2440 g_return_if_fail (GTK_IS_STYLE (style));
2441 g_return_if_fail (window != NULL);
2443 if (shadow_type == GTK_SHADOW_IN)
2445 if (detail && (strcmp (detail, "buttondefault") == 0))
2447 sanitize_size (window, &width, &height);
2449 gdk_draw_rectangle (window, style->black_gc, FALSE,
2450 x, y, width - 1, height - 1);
2454 if (detail && strcmp (detail, "trough") == 0)
2456 draw_thin_shadow (style, window, state_type, area,
2457 x, y, width, height);
2460 if (widget && GTK_IS_SPIN_BUTTON (widget) &&
2461 detail && strcmp (detail, "spinbutton") == 0)
2463 draw_spinbutton_shadow (style, window, state_type,
2464 gtk_widget_get_direction (widget), area, x, y, width, height);
2470 sanitize_size (window, &width, &height);
2472 switch (shadow_type)
2474 case GTK_SHADOW_NONE:
2477 case GTK_SHADOW_ETCHED_IN:
2478 gc1 = style->light_gc[state_type];
2479 gc2 = style->dark_gc[state_type];
2481 case GTK_SHADOW_OUT:
2482 case GTK_SHADOW_ETCHED_OUT:
2483 gc1 = style->dark_gc[state_type];
2484 gc2 = style->light_gc[state_type];
2490 gdk_gc_set_clip_rectangle (gc1, area);
2491 gdk_gc_set_clip_rectangle (gc2, area);
2492 if (shadow_type == GTK_SHADOW_IN ||
2493 shadow_type == GTK_SHADOW_OUT)
2495 gdk_gc_set_clip_rectangle (style->black_gc, area);
2496 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2500 switch (shadow_type)
2502 case GTK_SHADOW_NONE:
2506 /* Light around right and bottom edge */
2508 if (style->ythickness > 0)
2509 gdk_draw_line (window, gc1,
2510 x, y + height - 1, x + width - 1, y + height - 1);
2511 if (style->xthickness > 0)
2512 gdk_draw_line (window, gc1,
2513 x + width - 1, y, x + width - 1, y + height - 1);
2515 if (style->ythickness > 1)
2516 gdk_draw_line (window, style->bg_gc[state_type],
2517 x + 1, y + height - 2, x + width - 2, y + height - 2);
2518 if (style->xthickness > 1)
2519 gdk_draw_line (window, style->bg_gc[state_type],
2520 x + width - 2, y + 1, x + width - 2, y + height - 2);
2522 /* Dark around left and top */
2524 if (style->ythickness > 1)
2525 gdk_draw_line (window, style->black_gc,
2526 x + 1, y + 1, x + width - 2, y + 1);
2527 if (style->xthickness > 1)
2528 gdk_draw_line (window, style->black_gc,
2529 x + 1, y + 1, x + 1, y + height - 2);
2531 if (style->ythickness > 0)
2532 gdk_draw_line (window, gc2,
2533 x, y, x + width - 1, y);
2534 if (style->xthickness > 0)
2535 gdk_draw_line (window, gc2,
2536 x, y, x, y + height - 1);
2539 case GTK_SHADOW_OUT:
2540 /* Dark around right and bottom edge */
2542 if (style->ythickness > 0)
2544 if (style->ythickness > 1)
2546 gdk_draw_line (window, gc1,
2547 x + 1, y + height - 2, x + width - 2, y + height - 2);
2548 gdk_draw_line (window, style->black_gc,
2549 x, y + height - 1, x + width - 1, y + height - 1);
2553 gdk_draw_line (window, gc1,
2554 x + 1, y + height - 1, x + width - 1, y + height - 1);
2558 if (style->xthickness > 0)
2560 if (style->xthickness > 1)
2562 gdk_draw_line (window, gc1,
2563 x + width - 2, y + 1, x + width - 2, y + height - 2);
2565 gdk_draw_line (window, style->black_gc,
2566 x + width - 1, y, x + width - 1, y + height - 1);
2570 gdk_draw_line (window, gc1,
2571 x + width - 1, y + 1, x + width - 1, y + height - 1);
2575 /* Light around top and left */
2577 if (style->ythickness > 0)
2578 gdk_draw_line (window, gc2,
2579 x, y, x + width - 2, y);
2580 if (style->xthickness > 0)
2581 gdk_draw_line (window, gc2,
2582 x, y, x, y + height - 2);
2584 if (style->ythickness > 1)
2585 gdk_draw_line (window, style->bg_gc[state_type],
2586 x + 1, y + 1, x + width - 3, y + 1);
2587 if (style->xthickness > 1)
2588 gdk_draw_line (window, style->bg_gc[state_type],
2589 x + 1, y + 1, x + 1, y + height - 3);
2592 case GTK_SHADOW_ETCHED_IN:
2593 case GTK_SHADOW_ETCHED_OUT:
2594 if (style->xthickness > 0)
2596 if (style->xthickness > 1)
2598 thickness_light = 1;
2601 for (i = 0; i < thickness_dark; i++)
2603 gdk_draw_line (window, gc1,
2607 y + height - i - 1);
2608 gdk_draw_line (window, gc2,
2612 y + height - i - 2);
2615 for (i = 0; i < thickness_light; i++)
2617 gdk_draw_line (window, gc1,
2618 x + thickness_dark + i,
2619 y + thickness_dark + i,
2620 x + thickness_dark + i,
2621 y + height - thickness_dark - i - 1);
2622 gdk_draw_line (window, gc2,
2623 x + width - thickness_light - i - 1,
2624 y + thickness_dark + i,
2625 x + width - thickness_light - i - 1,
2626 y + height - thickness_light - 1);
2631 gdk_draw_line (window,
2632 style->dark_gc[state_type],
2633 x, y, x, y + height);
2634 gdk_draw_line (window,
2635 style->dark_gc[state_type],
2636 x + width, y, x + width, y + height);
2640 if (style->ythickness > 0)
2642 if (style->ythickness > 1)
2644 thickness_light = 1;
2647 for (i = 0; i < thickness_dark; i++)
2649 gdk_draw_line (window, gc1,
2653 y + height - i - 1);
2655 gdk_draw_line (window, gc2,
2662 for (i = 0; i < thickness_light; i++)
2664 gdk_draw_line (window, gc1,
2665 x + thickness_dark + i,
2666 y + thickness_dark + i,
2667 x + width - thickness_dark - i - 2,
2668 y + thickness_dark + i);
2670 gdk_draw_line (window, gc2,
2671 x + thickness_dark + i,
2672 y + height - thickness_light - i - 1,
2673 x + width - thickness_light - 1,
2674 y + height - thickness_light - i - 1);
2679 gdk_draw_line (window,
2680 style->dark_gc[state_type],
2681 x, y, x + width, y);
2682 gdk_draw_line (window,
2683 style->dark_gc[state_type],
2684 x, y + height, x + width, y + height);
2691 if (shadow_type == GTK_SHADOW_IN &&
2692 widget && GTK_IS_SPIN_BUTTON (widget) &&
2693 detail && strcmp (detail, "entry") == 0)
2695 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
2697 gdk_draw_line (window,
2698 style->base_gc[state_type],
2699 x + width - 1, y + 2,
2700 x + width - 1, y + height - 3);
2701 gdk_draw_line (window,
2702 style->base_gc[state_type],
2703 x + width - 2, y + 2,
2704 x + width - 2, y + height - 3);
2705 gdk_draw_point (window,
2707 x + width - 1, y + 1);
2708 gdk_draw_point (window,
2709 style->bg_gc[state_type],
2710 x + width - 1, y + height - 2);
2714 gdk_draw_line (window,
2715 style->base_gc[state_type],
2718 gdk_draw_line (window,
2719 style->base_gc[state_type],
2721 x + 1, y + height - 3);
2722 gdk_draw_point (window,
2725 gdk_draw_line (window,
2726 style->bg_gc[state_type],
2728 x + 1, y + height - 2);
2729 gdk_draw_point (window,
2730 style->light_gc[state_type],
2738 gdk_gc_set_clip_rectangle (gc1, NULL);
2739 gdk_gc_set_clip_rectangle (gc2, NULL);
2740 if (shadow_type == GTK_SHADOW_IN ||
2741 shadow_type == GTK_SHADOW_OUT)
2743 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2744 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2750 gtk_default_draw_polygon (GtkStyle *style,
2752 GtkStateType state_type,
2753 GtkShadowType shadow_type,
2756 const gchar *detail,
2761 static const gdouble pi_over_4 = G_PI_4;
2762 static const gdouble pi_3_over_4 = G_PI_4 * 3;
2772 g_return_if_fail (GTK_IS_STYLE (style));
2773 g_return_if_fail (window != NULL);
2774 g_return_if_fail (points != NULL);
2776 switch (shadow_type)
2779 gc1 = style->bg_gc[state_type];
2780 gc2 = style->dark_gc[state_type];
2781 gc3 = style->light_gc[state_type];
2782 gc4 = style->black_gc;
2784 case GTK_SHADOW_ETCHED_IN:
2785 gc1 = style->light_gc[state_type];
2786 gc2 = style->dark_gc[state_type];
2787 gc3 = style->dark_gc[state_type];
2788 gc4 = style->light_gc[state_type];
2790 case GTK_SHADOW_OUT:
2791 gc1 = style->dark_gc[state_type];
2792 gc2 = style->light_gc[state_type];
2793 gc3 = style->black_gc;
2794 gc4 = style->bg_gc[state_type];
2796 case GTK_SHADOW_ETCHED_OUT:
2797 gc1 = style->dark_gc[state_type];
2798 gc2 = style->light_gc[state_type];
2799 gc3 = style->light_gc[state_type];
2800 gc4 = style->dark_gc[state_type];
2808 gdk_gc_set_clip_rectangle (gc1, area);
2809 gdk_gc_set_clip_rectangle (gc2, area);
2810 gdk_gc_set_clip_rectangle (gc3, area);
2811 gdk_gc_set_clip_rectangle (gc4, area);
2815 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, npoints);
2819 for (i = 0; i < npoints; i++)
2821 if ((points[i].x == points[i+1].x) &&
2822 (points[i].y == points[i+1].y))
2828 angle = atan2 (points[i+1].y - points[i].y,
2829 points[i+1].x - points[i].x);
2832 if ((angle > -pi_3_over_4) && (angle < pi_over_4))
2834 if (angle > -pi_over_4)
2845 gdk_draw_line (window, gc1,
2846 points[i].x-xadjust, points[i].y-yadjust,
2847 points[i+1].x-xadjust, points[i+1].y-yadjust);
2848 gdk_draw_line (window, gc3,
2849 points[i].x, points[i].y,
2850 points[i+1].x, points[i+1].y);
2854 if ((angle < -pi_3_over_4) || (angle > pi_3_over_4))
2865 gdk_draw_line (window, gc4,
2866 points[i].x+xadjust, points[i].y+yadjust,
2867 points[i+1].x+xadjust, points[i+1].y+yadjust);
2868 gdk_draw_line (window, gc2,
2869 points[i].x, points[i].y,
2870 points[i+1].x, points[i+1].y);
2876 gdk_gc_set_clip_rectangle (gc1, NULL);
2877 gdk_gc_set_clip_rectangle (gc2, NULL);
2878 gdk_gc_set_clip_rectangle (gc3, NULL);
2879 gdk_gc_set_clip_rectangle (gc4, NULL);
2884 draw_arrow (GdkWindow *window,
2887 GtkArrowType arrow_type,
2896 gdk_gc_set_clip_rectangle (gc, area);
2898 if (arrow_type == GTK_ARROW_DOWN)
2900 for (i = 0, j = 0; i < height; i++, j++)
2901 gdk_draw_line (window, gc, x + j, y + i, x + width - j - 1, y + i);
2903 else if (arrow_type == GTK_ARROW_UP)
2905 for (i = height - 1, j = 0; i >= 0; 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_LEFT)
2910 for (i = width - 1, j = 0; i >= 0; i--, j++)
2911 gdk_draw_line (window, gc, x + i, y + j, x + i, y + height - j - 1);
2913 else if (arrow_type == GTK_ARROW_RIGHT)
2915 for (i = 0, j = 0; i < width; i++, j++)
2916 gdk_draw_line (window, gc, x + i, y + j, x + i, y + height - j - 1);
2920 gdk_gc_set_clip_rectangle (gc, NULL);
2924 calculate_arrow_geometry (GtkArrowType arrow_type,
2936 case GTK_ARROW_DOWN:
2946 if (arrow_type == GTK_ARROW_DOWN)
2948 if (*height % 2 == 1 || h % 2 == 0)
2953 if (*height % 2 == 0 || h % 2 == 0)
2958 case GTK_ARROW_RIGHT:
2959 case GTK_ARROW_LEFT:
2969 if (arrow_type == GTK_ARROW_RIGHT)
2971 if (*width % 2 == 1 || w % 2 == 0)
2976 if (*width % 2 == 0 || w % 2 == 0)
2982 /* should not be reached */
2986 *x += (*width - w) / 2;
2987 *y += (*height - h) / 2;
2993 gtk_default_draw_arrow (GtkStyle *style,
2996 GtkShadowType shadow,
2999 const gchar *detail,
3000 GtkArrowType arrow_type,
3007 gint original_width, original_x;
3009 sanitize_size (window, &width, &height);
3011 original_width = width;
3014 calculate_arrow_geometry (arrow_type, &x, &y, &width, &height);
3016 if (detail && strcmp (detail, "menuitem") == 0
3017 && gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
3018 x = original_x + original_width - width;
3020 if (state == GTK_STATE_INSENSITIVE)
3021 draw_arrow (window, style->white_gc, area, arrow_type,
3022 x + 1, y + 1, width, height);
3023 draw_arrow (window, style->fg_gc[state], area, arrow_type,
3024 x, y, width, height);
3028 gtk_default_draw_diamond (GtkStyle *style,
3030 GtkStateType state_type,
3031 GtkShadowType shadow_type,
3034 const gchar *detail,
3042 GdkGC *outer_nw = NULL;
3043 GdkGC *outer_ne = NULL;
3044 GdkGC *outer_sw = NULL;
3045 GdkGC *outer_se = NULL;
3046 GdkGC *middle_nw = NULL;
3047 GdkGC *middle_ne = NULL;
3048 GdkGC *middle_sw = NULL;
3049 GdkGC *middle_se = NULL;
3050 GdkGC *inner_nw = NULL;
3051 GdkGC *inner_ne = NULL;
3052 GdkGC *inner_sw = NULL;
3053 GdkGC *inner_se = NULL;
3055 g_return_if_fail (GTK_IS_STYLE (style));
3056 g_return_if_fail (window != NULL);
3058 sanitize_size (window, &width, &height);
3060 half_width = width / 2;
3061 half_height = height / 2;
3065 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
3066 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
3067 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
3068 gdk_gc_set_clip_rectangle (style->black_gc, area);
3071 switch (shadow_type)
3074 inner_sw = inner_se = style->bg_gc[state_type];
3075 middle_sw = middle_se = style->light_gc[state_type];
3076 outer_sw = outer_se = style->light_gc[state_type];
3077 inner_nw = inner_ne = style->black_gc;
3078 middle_nw = middle_ne = style->dark_gc[state_type];
3079 outer_nw = outer_ne = style->dark_gc[state_type];
3082 case GTK_SHADOW_OUT:
3083 inner_sw = inner_se = style->dark_gc[state_type];
3084 middle_sw = middle_se = style->dark_gc[state_type];
3085 outer_sw = outer_se = style->black_gc;
3086 inner_nw = inner_ne = style->bg_gc[state_type];
3087 middle_nw = middle_ne = style->light_gc[state_type];
3088 outer_nw = outer_ne = style->light_gc[state_type];
3091 case GTK_SHADOW_ETCHED_IN:
3092 inner_sw = inner_se = style->bg_gc[state_type];
3093 middle_sw = middle_se = style->dark_gc[state_type];
3094 outer_sw = outer_se = style->light_gc[state_type];
3095 inner_nw = inner_ne = style->bg_gc[state_type];
3096 middle_nw = middle_ne = style->light_gc[state_type];
3097 outer_nw = outer_ne = style->dark_gc[state_type];
3100 case GTK_SHADOW_ETCHED_OUT:
3101 inner_sw = inner_se = style->bg_gc[state_type];
3102 middle_sw = middle_se = style->light_gc[state_type];
3103 outer_sw = outer_se = style->dark_gc[state_type];
3104 inner_nw = inner_ne = style->bg_gc[state_type];
3105 middle_nw = middle_ne = style->dark_gc[state_type];
3106 outer_nw = outer_ne = style->light_gc[state_type];
3116 gdk_draw_line (window, inner_sw,
3117 x + 2, y + half_height,
3118 x + half_width, y + height - 2);
3119 gdk_draw_line (window, inner_se,
3120 x + half_width, y + height - 2,
3121 x + width - 2, y + half_height);
3122 gdk_draw_line (window, middle_sw,
3123 x + 1, y + half_height,
3124 x + half_width, y + height - 1);
3125 gdk_draw_line (window, middle_se,
3126 x + half_width, y + height - 1,
3127 x + width - 1, y + half_height);
3128 gdk_draw_line (window, outer_sw,
3130 x + half_width, y + height);
3131 gdk_draw_line (window, outer_se,
3132 x + half_width, y + height,
3133 x + width, y + half_height);
3135 gdk_draw_line (window, inner_nw,
3136 x + 2, y + half_height,
3137 x + half_width, y + 2);
3138 gdk_draw_line (window, inner_ne,
3139 x + half_width, y + 2,
3140 x + width - 2, y + half_height);
3141 gdk_draw_line (window, middle_nw,
3142 x + 1, y + half_height,
3143 x + half_width, y + 1);
3144 gdk_draw_line (window, middle_ne,
3145 x + half_width, y + 1,
3146 x + width - 1, y + half_height);
3147 gdk_draw_line (window, outer_nw,
3150 gdk_draw_line (window, outer_ne,
3152 x + width, y + half_height);
3157 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
3158 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
3159 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
3160 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
3165 gtk_default_draw_string (GtkStyle *style,
3167 GtkStateType state_type,
3170 const gchar *detail,
3173 const gchar *string)
3175 GdkDisplay *display;
3177 g_return_if_fail (GTK_IS_STYLE (style));
3178 g_return_if_fail (window != NULL);
3180 display = gdk_drawable_get_display (window);
3184 gdk_gc_set_clip_rectangle (style->white_gc, area);
3185 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], area);
3188 if (state_type == GTK_STATE_INSENSITIVE)
3189 gdk_draw_string (window,
3190 gtk_style_get_font (style),
3191 style->white_gc, x + 1, y + 1, string);
3193 gdk_draw_string (window,
3194 gtk_style_get_font (style),
3195 style->fg_gc[state_type], x, y, string);
3199 gdk_gc_set_clip_rectangle (style->white_gc, NULL);
3200 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], NULL);
3205 option_menu_get_props (GtkWidget *widget,
3206 GtkRequisition *indicator_size,
3207 GtkBorder *indicator_spacing)
3209 GtkRequisition *tmp_size = NULL;
3210 GtkBorder *tmp_spacing = NULL;
3213 gtk_widget_style_get (widget,
3214 "indicator_size", &tmp_size,
3215 "indicator_spacing", &tmp_spacing,
3220 *indicator_size = *tmp_size;
3224 *indicator_size = default_option_indicator_size;
3228 *indicator_spacing = *tmp_spacing;
3229 g_free (tmp_spacing);
3232 *indicator_spacing = default_option_indicator_spacing;
3236 gtk_default_draw_box (GtkStyle *style,
3238 GtkStateType state_type,
3239 GtkShadowType shadow_type,
3242 const gchar *detail,
3248 gboolean is_spinbutton_box = FALSE;
3250 g_return_if_fail (GTK_IS_STYLE (style));
3251 g_return_if_fail (window != NULL);
3253 sanitize_size (window, &width, &height);
3255 if (widget && GTK_IS_SPIN_BUTTON (widget) && detail)
3257 if (strcmp (detail, "spinbutton_up") == 0)
3263 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3268 is_spinbutton_box = TRUE;
3270 else if (strcmp (detail, "spinbutton_down") == 0)
3275 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3280 is_spinbutton_box = TRUE;
3284 if (!style->bg_pixmap[state_type] ||
3285 GDK_IS_PIXMAP (window))
3288 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
3290 gdk_draw_rectangle (window, style->bg_gc[state_type], TRUE,
3291 x, y, width, height);
3293 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
3296 gtk_style_apply_default_background (style, window,
3297 widget && !GTK_WIDGET_NO_WINDOW (widget),
3298 state_type, area, x, y, width, height);
3300 if (is_spinbutton_box)
3305 lower_gc = style->dark_gc[state_type];
3306 if (shadow_type == GTK_SHADOW_OUT)
3307 upper_gc = style->light_gc[state_type];
3309 upper_gc = style->dark_gc[state_type];
3313 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
3314 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
3317 gdk_draw_line (window, upper_gc, x, y, x + width - 1, y);
3318 gdk_draw_line (window, lower_gc, x, y + height - 1, x + width - 1, y + height - 1);
3322 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
3323 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
3328 gtk_paint_shadow (style, window, state_type, shadow_type, area, widget, detail,
3329 x, y, width, height);
3331 if (detail && strcmp (detail, "optionmenu") == 0)
3333 GtkRequisition indicator_size;
3334 GtkBorder indicator_spacing;
3337 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
3339 sanitize_size (window, &width, &height);
3341 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3342 vline_x = x + indicator_size.width + indicator_spacing.left + indicator_spacing.right;
3344 vline_x = x + width - (indicator_size.width + indicator_spacing.left + indicator_spacing.right) - style->xthickness;
3346 gtk_paint_vline (style, window, state_type, area, widget,
3348 y + style->ythickness + 1,
3349 y + height - style->ythickness - 3,
3355 get_darkened_gc (GdkWindow *window,
3359 GdkColor src = *color;
3360 GdkColor shaded = *color;
3363 gc = gdk_gc_new (window);
3365 while (darken_count)
3367 gtk_style_shade (&src, &shaded, 0.93);
3372 gdk_gc_set_rgb_fg_color (gc, &shaded);
3378 gtk_default_draw_flat_box (GtkStyle *style,
3380 GtkStateType state_type,
3381 GtkShadowType shadow_type,
3384 const gchar *detail,
3391 GdkGC *freeme = NULL;
3393 g_return_if_fail (GTK_IS_STYLE (style));
3394 g_return_if_fail (window != NULL);
3396 sanitize_size (window, &width, &height);
3400 if (state_type == GTK_STATE_SELECTED)
3402 if (!strcmp ("text", detail))
3403 gc1 = style->bg_gc[GTK_STATE_SELECTED];
3404 else if (!strncmp ("cell_even", detail, strlen ("cell_even")) ||
3405 !strncmp ("cell_odd", detail, strlen ("cell_odd")))
3407 /* This has to be really broken; alex made me do it. -jrb */
3408 if (GTK_WIDGET_HAS_FOCUS (widget))
3409 gc1 = style->base_gc[state_type];
3411 gc1 = style->base_gc[GTK_STATE_ACTIVE];
3415 gc1 = style->bg_gc[state_type];
3420 if (!strcmp ("viewportbin", detail))
3421 gc1 = style->bg_gc[GTK_STATE_NORMAL];
3422 else if (!strcmp ("entry_bg", detail))
3423 gc1 = style->base_gc[state_type];
3425 /* For trees: even rows are base color, odd rows are a shade of
3426 * the base color, the sort column is a shade of the original color
3430 else if (!strcmp ("cell_even", detail) ||
3431 !strcmp ("cell_odd", detail) ||
3432 !strcmp ("cell_even_ruled", detail))
3434 GdkColor *color = NULL;
3436 gtk_widget_style_get (widget,
3437 "even_row_color", &color,
3442 freeme = get_darkened_gc (window, color, 0);
3445 gdk_color_free (color);
3448 gc1 = style->base_gc[state_type];
3450 else if (!strcmp ("cell_odd_ruled", detail))
3454 gtk_widget_style_get (widget,
3455 "odd_row_color", &color,
3460 freeme = get_darkened_gc (window, color, 0);
3463 gdk_color_free (color);
3467 gtk_widget_style_get (widget,
3468 "even_row_color", &color,
3473 freeme = get_darkened_gc (window, color, 1);
3474 gdk_color_free (color);
3477 freeme = get_darkened_gc (window, &style->base[state_type], 1);
3481 else if (!strcmp ("cell_even_sorted", detail) ||
3482 !strcmp ("cell_odd_sorted", detail) ||
3483 !strcmp ("cell_even_ruled_sorted", detail))
3485 GdkColor *color = NULL;
3487 if (!strcmp ("cell_odd_sorted", detail))
3488 gtk_widget_style_get (widget,
3489 "odd_row_color", &color,
3492 gtk_widget_style_get (widget,
3493 "even_row_color", &color,
3498 freeme = get_darkened_gc (window, color, 1);
3501 gdk_color_free (color);
3505 freeme = get_darkened_gc (window, &style->base[state_type], 1);
3509 else if (!strcmp ("cell_odd_ruled_sorted", detail))
3511 GdkColor *color = NULL;
3513 gtk_widget_style_get (widget,
3514 "odd_row_color", &color,
3519 freeme = get_darkened_gc (window, color, 1);
3522 gdk_color_free (color);
3526 gtk_widget_style_get (widget,
3527 "even_row_color", &color,
3532 freeme = get_darkened_gc (window, color, 2);
3533 gdk_color_free (color);
3536 freeme = get_darkened_gc (window, &style->base[state_type], 2);
3541 gc1 = style->bg_gc[state_type];
3545 gc1 = style->bg_gc[state_type];
3547 if (!style->bg_pixmap[state_type] || gc1 != style->bg_gc[state_type] ||
3548 GDK_IS_PIXMAP (window))
3551 gdk_gc_set_clip_rectangle (gc1, area);
3553 gdk_draw_rectangle (window, gc1, TRUE,
3554 x, y, width, height);
3556 if (detail && !strcmp ("tooltip", detail))
3557 gdk_draw_rectangle (window, style->black_gc, FALSE,
3558 x, y, width - 1, height - 1);
3561 gdk_gc_set_clip_rectangle (gc1, NULL);
3564 gtk_style_apply_default_background (style, window,
3565 widget && !GTK_WIDGET_NO_WINDOW (widget),
3566 state_type, area, x, y, width, height);
3570 g_object_unref (freeme);
3574 gtk_default_draw_check (GtkStyle *style,
3576 GtkStateType state_type,
3577 GtkShadowType shadow_type,
3580 const gchar *detail,
3586 if (detail && strcmp (detail, "cellcheck") == 0)
3588 gdk_draw_rectangle (window,
3589 widget->style->base_gc[state_type],
3593 gdk_draw_rectangle (window,
3594 widget->style->text_gc[state_type],
3599 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3600 y -= (((1 + INDICATOR_PART_SIZE - height) / 2) - 1);
3601 if (shadow_type == GTK_SHADOW_IN)
3603 draw_part (window, style->text_gc[state_type], area, x, y, CHECK_TEXT);
3604 draw_part (window, style->text_aa_gc[state_type], area, x, y, CHECK_AA);
3609 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3610 y -= (1 + INDICATOR_PART_SIZE - height) / 2;
3612 if (strcmp (detail, "check") == 0) /* Menu item */
3614 if (shadow_type == GTK_SHADOW_IN)
3616 draw_part (window, style->black_gc, area, x, y, CHECK_TEXT);
3617 draw_part (window, style->dark_gc[state_type], area, x, y, CHECK_AA);
3619 else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
3621 draw_part (window, style->black_gc, area, x, y, CHECK_INCONSISTENT_TEXT);
3622 draw_part (window, style->dark_gc[state_type], area, x, y, CHECK_INCONSISTENT_AA);
3627 GdkGC *base_gc = style->base_gc[state_type];
3629 if (state_type == GTK_STATE_ACTIVE)
3630 base_gc = style->bg_gc[GTK_STATE_ACTIVE];
3632 draw_part (window, base_gc, area, x, y, CHECK_BASE);
3633 draw_part (window, style->black_gc, area, x, y, CHECK_BLACK);
3634 draw_part (window, style->dark_gc[state_type], area, x, y, CHECK_DARK);
3635 draw_part (window, style->mid_gc[state_type], area, x, y, CHECK_MID);
3636 draw_part (window, style->light_gc[state_type], area, x, y, CHECK_LIGHT);
3638 if (shadow_type == GTK_SHADOW_IN)
3640 draw_part (window, style->text_gc[state_type], area, x, y, CHECK_TEXT);
3641 draw_part (window, style->text_aa_gc[state_type], area, x, y, CHECK_AA);
3643 else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
3645 draw_part (window, style->text_gc[state_type], area, x, y, CHECK_INCONSISTENT_TEXT);
3646 draw_part (window, style->text_aa_gc[state_type], area, x, y, CHECK_INCONSISTENT_AA);
3654 gtk_default_draw_option (GtkStyle *style,
3656 GtkStateType state_type,
3657 GtkShadowType shadow_type,
3660 const gchar *detail,
3666 if (detail && strcmp (detail, "cellradio") == 0)
3668 gdk_draw_arc (window,
3669 widget->style->fg_gc[state_type],
3676 if (shadow_type == GTK_SHADOW_IN)
3678 gdk_draw_arc (window,
3679 widget->style->fg_gc[state_type],
3690 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3691 y -= (1 + INDICATOR_PART_SIZE - height) / 2;
3693 if (strcmp (detail, "option") == 0) /* Menu item */
3695 if (shadow_type == GTK_SHADOW_IN)
3697 draw_part (window, style->fg_gc[state_type], area, x, y, RADIO_TEXT);
3699 else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
3701 draw_part (window, style->black_gc, area, x, y, CHECK_INCONSISTENT_TEXT);
3702 draw_part (window, style->dark_gc[state_type], area, x, y, CHECK_INCONSISTENT_AA);
3707 GdkGC *base_gc = style->base_gc[state_type];
3709 if (state_type == GTK_STATE_ACTIVE)
3710 base_gc = style->bg_gc[GTK_STATE_ACTIVE];
3712 draw_part (window, base_gc, area, x, y, RADIO_BASE);
3713 draw_part (window, style->black_gc, area, x, y, RADIO_BLACK);
3714 draw_part (window, style->dark_gc[state_type], area, x, y, RADIO_DARK);
3715 draw_part (window, style->mid_gc[state_type], area, x, y, RADIO_MID);
3716 draw_part (window, style->light_gc[state_type], area, x, y, RADIO_LIGHT);
3718 if (shadow_type == GTK_SHADOW_IN)
3720 draw_part (window, style->text_gc[state_type], area, x, y, RADIO_TEXT);
3722 else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
3724 draw_part (window, style->text_aa_gc[state_type], area, x, y, RADIO_INCONSISTENT_AA);
3725 draw_part (window, style->text_gc[state_type], area, x, y, RADIO_INCONSISTENT_TEXT);
3732 gtk_default_draw_tab (GtkStyle *style,
3734 GtkStateType state_type,
3735 GtkShadowType shadow_type,
3738 const gchar *detail,
3744 #define ARROW_SPACE 4
3746 GtkRequisition indicator_size;
3747 GtkBorder indicator_spacing;
3750 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
3752 indicator_size.width += (indicator_size.width % 2) - 1;
3753 arrow_height = indicator_size.width / 2 + 1;
3755 x += (width - indicator_size.width) / 2;
3756 y += (height - (2 * arrow_height + ARROW_SPACE)) / 2;
3758 if (state_type == GTK_STATE_INSENSITIVE)
3760 draw_arrow (window, style->white_gc, area,
3761 GTK_ARROW_UP, x + 1, y + 1,
3762 indicator_size.width, arrow_height);
3764 draw_arrow (window, style->white_gc, area,
3765 GTK_ARROW_DOWN, x + 1, y + arrow_height + ARROW_SPACE + 1,
3766 indicator_size.width, arrow_height);
3769 draw_arrow (window, style->fg_gc[state_type], area,
3771 indicator_size.width, arrow_height);
3774 draw_arrow (window, style->fg_gc[state_type], area,
3775 GTK_ARROW_DOWN, x, y + arrow_height + ARROW_SPACE,
3776 indicator_size.width, arrow_height);
3780 gtk_default_draw_shadow_gap (GtkStyle *style,
3782 GtkStateType state_type,
3783 GtkShadowType shadow_type,
3786 const gchar *detail,
3791 GtkPositionType gap_side,
3800 g_return_if_fail (GTK_IS_STYLE (style));
3801 g_return_if_fail (window != NULL);
3803 sanitize_size (window, &width, &height);
3805 switch (shadow_type)
3807 case GTK_SHADOW_NONE:
3810 gc1 = style->dark_gc[state_type];
3811 gc2 = style->black_gc;
3812 gc3 = style->bg_gc[state_type];
3813 gc4 = style->light_gc[state_type];
3815 case GTK_SHADOW_ETCHED_IN:
3816 gc1 = style->dark_gc[state_type];
3817 gc2 = style->light_gc[state_type];
3818 gc3 = style->dark_gc[state_type];
3819 gc4 = style->light_gc[state_type];
3821 case GTK_SHADOW_OUT:
3822 gc1 = style->light_gc[state_type];
3823 gc2 = style->bg_gc[state_type];
3824 gc3 = style->dark_gc[state_type];
3825 gc4 = style->black_gc;
3827 case GTK_SHADOW_ETCHED_OUT:
3828 gc1 = style->light_gc[state_type];
3829 gc2 = style->dark_gc[state_type];
3830 gc3 = style->light_gc[state_type];
3831 gc4 = style->dark_gc[state_type];
3836 gdk_gc_set_clip_rectangle (gc1, area);
3837 gdk_gc_set_clip_rectangle (gc2, area);
3838 gdk_gc_set_clip_rectangle (gc3, area);
3839 gdk_gc_set_clip_rectangle (gc4, area);
3842 switch (shadow_type)
3844 case GTK_SHADOW_NONE:
3846 case GTK_SHADOW_OUT:
3847 case GTK_SHADOW_ETCHED_IN:
3848 case GTK_SHADOW_ETCHED_OUT:
3852 gdk_draw_line (window, gc1,
3853 x, y, x, y + height - 1);
3854 gdk_draw_line (window, gc2,
3855 x + 1, y, x + 1, y + height - 2);
3857 gdk_draw_line (window, gc3,
3858 x + 1, y + height - 2, x + width - 2, y + height - 2);
3859 gdk_draw_line (window, gc3,
3860 x + width - 2, y, x + width - 2, y + height - 2);
3861 gdk_draw_line (window, gc4,
3862 x, y + height - 1, x + width - 1, y + height - 1);
3863 gdk_draw_line (window, gc4,
3864 x + width - 1, y, x + width - 1, y + height - 1);
3867 gdk_draw_line (window, gc1,
3868 x, y, x + gap_x - 1, y);
3869 gdk_draw_line (window, gc2,
3870 x + 1, y + 1, x + gap_x - 1, y + 1);
3871 gdk_draw_line (window, gc2,
3872 x + gap_x, y, x + gap_x, y);
3874 if ((width - (gap_x + gap_width)) > 0)
3876 gdk_draw_line (window, gc1,
3877 x + gap_x + gap_width, y, x + width - 2, y);
3878 gdk_draw_line (window, gc2,
3879 x + gap_x + gap_width, y + 1, x + width - 3, y + 1);
3880 gdk_draw_line (window, gc2,
3881 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
3884 case GTK_POS_BOTTOM:
3885 gdk_draw_line (window, gc1,
3886 x, y, x + width - 1, y);
3887 gdk_draw_line (window, gc1,
3888 x, y, x, y + height - 1);
3889 gdk_draw_line (window, gc2,
3890 x + 1, y + 1, x + width - 2, y + 1);
3891 gdk_draw_line (window, gc2,
3892 x + 1, y + 1, x + 1, y + height - 1);
3894 gdk_draw_line (window, gc3,
3895 x + width - 2, y + 1, x + width - 2, y + height - 1);
3896 gdk_draw_line (window, gc4,
3897 x + width - 1, y, x + width - 1, y + height - 1);
3900 gdk_draw_line (window, gc4,
3901 x, y + height - 1, x + gap_x - 1, y + height - 1);
3902 gdk_draw_line (window, gc3,
3903 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
3904 gdk_draw_line (window, gc3,
3905 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
3907 if ((width - (gap_x + gap_width)) > 0)
3909 gdk_draw_line (window, gc4,
3910 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
3911 gdk_draw_line (window, gc3,
3912 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
3913 gdk_draw_line (window, gc3,
3914 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
3918 gdk_draw_line (window, gc1,
3919 x, y, x + width - 1, y);
3920 gdk_draw_line (window, gc2,
3921 x, y + 1, x + width - 2, y + 1);
3923 gdk_draw_line (window, gc3,
3924 x, y + height - 2, x + width - 2, y + height - 2);
3925 gdk_draw_line (window, gc3,
3926 x + width - 2, y + 1, x + width - 2, y + height - 2);
3927 gdk_draw_line (window, gc4,
3928 x, y + height - 1, x + width - 1, y + height - 1);
3929 gdk_draw_line (window, gc4,
3930 x + width - 1, y, x + width - 1, y + height - 1);
3933 gdk_draw_line (window, gc1,
3934 x, y, x, y + gap_x - 1);
3935 gdk_draw_line (window, gc2,
3936 x + 1, y + 1, x + 1, y + gap_x - 1);
3937 gdk_draw_line (window, gc2,
3938 x, y + gap_x, x, y + gap_x);
3940 if ((width - (gap_x + gap_width)) > 0)
3942 gdk_draw_line (window, gc1,
3943 x, y + gap_x + gap_width, x, y + height - 2);
3944 gdk_draw_line (window, gc2,
3945 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
3946 gdk_draw_line (window, gc2,
3947 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
3951 gdk_draw_line (window, gc1,
3952 x, y, x + width - 1, y);
3953 gdk_draw_line (window, gc1,
3954 x, y, x, y + height - 1);
3955 gdk_draw_line (window, gc2,
3956 x + 1, y + 1, x + width - 1, y + 1);
3957 gdk_draw_line (window, gc2,
3958 x + 1, y + 1, x + 1, y + height - 2);
3960 gdk_draw_line (window, gc3,
3961 x + 1, y + height - 2, x + width - 1, y + height - 2);
3962 gdk_draw_line (window, gc4,
3963 x, y + height - 1, x + width - 1, y + height - 1);
3966 gdk_draw_line (window, gc4,
3967 x + width - 1, y, x + width - 1, y + gap_x - 1);
3968 gdk_draw_line (window, gc3,
3969 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
3970 gdk_draw_line (window, gc3,
3971 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
3973 if ((width - (gap_x + gap_width)) > 0)
3975 gdk_draw_line (window, gc4,
3976 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
3977 gdk_draw_line (window, gc3,
3978 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
3979 gdk_draw_line (window, gc3,
3980 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
3988 gdk_gc_set_clip_rectangle (gc1, NULL);
3989 gdk_gc_set_clip_rectangle (gc2, NULL);
3990 gdk_gc_set_clip_rectangle (gc3, NULL);
3991 gdk_gc_set_clip_rectangle (gc4, NULL);
3996 gtk_default_draw_box_gap (GtkStyle *style,
3998 GtkStateType state_type,
3999 GtkShadowType shadow_type,
4002 const gchar *detail,
4007 GtkPositionType gap_side,
4016 g_return_if_fail (GTK_IS_STYLE (style));
4017 g_return_if_fail (window != NULL);
4019 gtk_style_apply_default_background (style, window,
4020 widget && !GTK_WIDGET_NO_WINDOW (widget),
4021 state_type, area, x, y, width, height);
4023 sanitize_size (window, &width, &height);
4025 switch (shadow_type)
4027 case GTK_SHADOW_NONE:
4030 gc1 = style->dark_gc[state_type];
4031 gc2 = style->black_gc;
4032 gc3 = style->bg_gc[state_type];
4033 gc4 = style->light_gc[state_type];
4035 case GTK_SHADOW_ETCHED_IN:
4036 gc1 = style->dark_gc[state_type];
4037 gc2 = style->light_gc[state_type];
4038 gc3 = style->dark_gc[state_type];
4039 gc4 = style->light_gc[state_type];
4041 case GTK_SHADOW_OUT:
4042 gc1 = style->light_gc[state_type];
4043 gc2 = style->bg_gc[state_type];
4044 gc3 = style->dark_gc[state_type];
4045 gc4 = style->black_gc;
4047 case GTK_SHADOW_ETCHED_OUT:
4048 gc1 = style->light_gc[state_type];
4049 gc2 = style->dark_gc[state_type];
4050 gc3 = style->light_gc[state_type];
4051 gc4 = style->dark_gc[state_type];
4057 gdk_gc_set_clip_rectangle (gc1, area);
4058 gdk_gc_set_clip_rectangle (gc2, area);
4059 gdk_gc_set_clip_rectangle (gc3, area);
4060 gdk_gc_set_clip_rectangle (gc4, area);
4063 switch (shadow_type)
4065 case GTK_SHADOW_NONE:
4067 case GTK_SHADOW_OUT:
4068 case GTK_SHADOW_ETCHED_IN:
4069 case GTK_SHADOW_ETCHED_OUT:
4073 gdk_draw_line (window, gc1,
4074 x, y, x, y + height - 1);
4075 gdk_draw_line (window, gc2,
4076 x + 1, y, x + 1, y + height - 2);
4078 gdk_draw_line (window, gc3,
4079 x + 1, y + height - 2, x + width - 2, y + height - 2);
4080 gdk_draw_line (window, gc3,
4081 x + width - 2, y, x + width - 2, y + height - 2);
4082 gdk_draw_line (window, gc4,
4083 x, y + height - 1, x + width - 1, y + height - 1);
4084 gdk_draw_line (window, gc4,
4085 x + width - 1, y, x + width - 1, y + height - 1);
4088 gdk_draw_line (window, gc1,
4089 x, y, x + gap_x - 1, y);
4090 gdk_draw_line (window, gc2,
4091 x + 1, y + 1, x + gap_x - 1, y + 1);
4092 gdk_draw_line (window, gc2,
4093 x + gap_x, y, x + gap_x, y);
4095 if ((width - (gap_x + gap_width)) > 0)
4097 gdk_draw_line (window, gc1,
4098 x + gap_x + gap_width, y, x + width - 2, y);
4099 gdk_draw_line (window, gc2,
4100 x + gap_x + gap_width, y + 1, x + width - 2, y + 1);
4101 gdk_draw_line (window, gc2,
4102 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
4105 case GTK_POS_BOTTOM:
4106 gdk_draw_line (window, gc1,
4107 x, y, x + width - 1, y);
4108 gdk_draw_line (window, gc1,
4109 x, y, x, y + height - 1);
4110 gdk_draw_line (window, gc2,
4111 x + 1, y + 1, x + width - 2, y + 1);
4112 gdk_draw_line (window, gc2,
4113 x + 1, y + 1, x + 1, y + height - 1);
4115 gdk_draw_line (window, gc3,
4116 x + width - 2, y + 1, x + width - 2, y + height - 1);
4117 gdk_draw_line (window, gc4,
4118 x + width - 1, y, x + width - 1, y + height - 1);
4121 gdk_draw_line (window, gc4,
4122 x, y + height - 1, x + gap_x - 1, y + height - 1);
4123 gdk_draw_line (window, gc3,
4124 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
4125 gdk_draw_line (window, gc3,
4126 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
4128 if ((width - (gap_x + gap_width)) > 0)
4130 gdk_draw_line (window, gc4,
4131 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
4132 gdk_draw_line (window, gc3,
4133 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
4134 gdk_draw_line (window, gc3,
4135 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
4139 gdk_draw_line (window, gc1,
4140 x, y, x + width - 1, y);
4141 gdk_draw_line (window, gc2,
4142 x, y + 1, x + width - 2, y + 1);
4144 gdk_draw_line (window, gc3,
4145 x, y + height - 2, x + width - 2, y + height - 2);
4146 gdk_draw_line (window, gc3,
4147 x + width - 2, y + 1, x + width - 2, y + height - 2);
4148 gdk_draw_line (window, gc4,
4149 x, y + height - 1, x + width - 1, y + height - 1);
4150 gdk_draw_line (window, gc4,
4151 x + width - 1, y, x + width - 1, y + height - 1);
4154 gdk_draw_line (window, gc1,
4155 x, y, x, y + gap_x - 1);
4156 gdk_draw_line (window, gc2,
4157 x + 1, y + 1, x + 1, y + gap_x - 1);
4158 gdk_draw_line (window, gc2,
4159 x, y + gap_x, x, y + gap_x);
4161 if ((width - (gap_x + gap_width)) > 0)
4163 gdk_draw_line (window, gc1,
4164 x, y + gap_x + gap_width, x, y + height - 2);
4165 gdk_draw_line (window, gc2,
4166 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
4167 gdk_draw_line (window, gc2,
4168 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
4172 gdk_draw_line (window, gc1,
4173 x, y, x + width - 1, y);
4174 gdk_draw_line (window, gc1,
4175 x, y, x, y + height - 1);
4176 gdk_draw_line (window, gc2,
4177 x + 1, y + 1, x + width - 1, y + 1);
4178 gdk_draw_line (window, gc2,
4179 x + 1, y + 1, x + 1, y + height - 2);
4181 gdk_draw_line (window, gc3,
4182 x + 1, y + height - 2, x + width - 1, y + height - 2);
4183 gdk_draw_line (window, gc4,
4184 x, y + height - 1, x + width - 1, y + height - 1);
4187 gdk_draw_line (window, gc4,
4188 x + width - 1, y, x + width - 1, y + gap_x - 1);
4189 gdk_draw_line (window, gc3,
4190 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
4191 gdk_draw_line (window, gc3,
4192 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
4194 if ((width - (gap_x + gap_width)) > 0)
4196 gdk_draw_line (window, gc4,
4197 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
4198 gdk_draw_line (window, gc3,
4199 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
4200 gdk_draw_line (window, gc3,
4201 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
4209 gdk_gc_set_clip_rectangle (gc1, NULL);
4210 gdk_gc_set_clip_rectangle (gc2, NULL);
4211 gdk_gc_set_clip_rectangle (gc3, NULL);
4212 gdk_gc_set_clip_rectangle (gc4, NULL);
4217 gtk_default_draw_extension (GtkStyle *style,
4219 GtkStateType state_type,
4220 GtkShadowType shadow_type,
4223 const gchar *detail,
4228 GtkPositionType gap_side)
4235 g_return_if_fail (GTK_IS_STYLE (style));
4236 g_return_if_fail (window != NULL);
4238 gtk_style_apply_default_background (style, window,
4239 widget && !GTK_WIDGET_NO_WINDOW (widget),
4240 GTK_STATE_NORMAL, area, x, y, width, height);
4242 sanitize_size (window, &width, &height);
4244 switch (shadow_type)
4246 case GTK_SHADOW_NONE:
4249 gc1 = style->dark_gc[state_type];
4250 gc2 = style->black_gc;
4251 gc3 = style->bg_gc[state_type];
4252 gc4 = style->light_gc[state_type];
4254 case GTK_SHADOW_ETCHED_IN:
4255 gc1 = style->dark_gc[state_type];
4256 gc2 = style->light_gc[state_type];
4257 gc3 = style->dark_gc[state_type];
4258 gc4 = style->light_gc[state_type];
4260 case GTK_SHADOW_OUT:
4261 gc1 = style->light_gc[state_type];
4262 gc2 = style->bg_gc[state_type];
4263 gc3 = style->dark_gc[state_type];
4264 gc4 = style->black_gc;
4266 case GTK_SHADOW_ETCHED_OUT:
4267 gc1 = style->light_gc[state_type];
4268 gc2 = style->dark_gc[state_type];
4269 gc3 = style->light_gc[state_type];
4270 gc4 = style->dark_gc[state_type];
4276 gdk_gc_set_clip_rectangle (gc1, area);
4277 gdk_gc_set_clip_rectangle (gc2, area);
4278 gdk_gc_set_clip_rectangle (gc3, area);
4279 gdk_gc_set_clip_rectangle (gc4, area);
4282 switch (shadow_type)
4284 case GTK_SHADOW_NONE:
4286 case GTK_SHADOW_OUT:
4287 case GTK_SHADOW_ETCHED_IN:
4288 case GTK_SHADOW_ETCHED_OUT:
4292 gtk_style_apply_default_background (style, window,
4293 widget && !GTK_WIDGET_NO_WINDOW (widget),
4295 x + style->xthickness,
4297 width - (2 * style->xthickness),
4298 height - (style->ythickness));
4299 gdk_draw_line (window, gc1,
4300 x, y, x, y + height - 2);
4301 gdk_draw_line (window, gc2,
4302 x + 1, y, x + 1, y + height - 2);
4304 gdk_draw_line (window, gc3,
4305 x + 2, y + height - 2, x + width - 2, y + height - 2);
4306 gdk_draw_line (window, gc3,
4307 x + width - 2, y, x + width - 2, y + height - 2);
4308 gdk_draw_line (window, gc4,
4309 x + 1, y + height - 1, x + width - 2, y + height - 1);
4310 gdk_draw_line (window, gc4,
4311 x + width - 1, y, x + width - 1, y + height - 2);
4313 case GTK_POS_BOTTOM:
4314 gtk_style_apply_default_background (style, window,
4315 widget && !GTK_WIDGET_NO_WINDOW (widget),
4317 x + style->xthickness,
4318 y + style->ythickness,
4319 width - (2 * style->xthickness),
4320 height - (style->ythickness));
4321 gdk_draw_line (window, gc1,
4322 x + 1, y, x + width - 2, y);
4323 gdk_draw_line (window, gc1,
4324 x, y + 1, x, y + height - 1);
4325 gdk_draw_line (window, gc2,
4326 x + 1, y + 1, x + width - 2, y + 1);
4327 gdk_draw_line (window, gc2,
4328 x + 1, y + 1, x + 1, y + height - 1);
4330 gdk_draw_line (window, gc3,
4331 x + width - 2, y + 2, x + width - 2, y + height - 1);
4332 gdk_draw_line (window, gc4,
4333 x + width - 1, y + 1, x + width - 1, y + height - 1);
4336 gtk_style_apply_default_background (style, window,
4337 widget && !GTK_WIDGET_NO_WINDOW (widget),
4340 y + style->ythickness,
4341 width - (style->xthickness),
4342 height - (2 * style->ythickness));
4343 gdk_draw_line (window, gc1,
4344 x, y, x + width - 2, y);
4345 gdk_draw_line (window, gc2,
4346 x + 1, y + 1, x + width - 2, y + 1);
4348 gdk_draw_line (window, gc3,
4349 x, y + height - 2, x + width - 2, y + height - 2);
4350 gdk_draw_line (window, gc3,
4351 x + width - 2, y + 2, x + width - 2, y + height - 2);
4352 gdk_draw_line (window, gc4,
4353 x, y + height - 1, x + width - 2, y + height - 1);
4354 gdk_draw_line (window, gc4,
4355 x + width - 1, y + 1, x + width - 1, y + height - 2);
4358 gtk_style_apply_default_background (style, window,
4359 widget && !GTK_WIDGET_NO_WINDOW (widget),
4361 x + style->xthickness,
4362 y + style->ythickness,
4363 width - (style->xthickness),
4364 height - (2 * style->ythickness));
4365 gdk_draw_line (window, gc1,
4366 x + 1, y, x + width - 1, y);
4367 gdk_draw_line (window, gc1,
4368 x, y + 1, x, y + height - 2);
4369 gdk_draw_line (window, gc2,
4370 x + 1, y + 1, x + width - 1, y + 1);
4371 gdk_draw_line (window, gc2,
4372 x + 1, y + 1, x + 1, y + height - 2);
4374 gdk_draw_line (window, gc3,
4375 x + 2, y + height - 2, x + width - 1, y + height - 2);
4376 gdk_draw_line (window, gc4,
4377 x + 1, y + height - 1, x + width - 1, y + height - 1);
4384 gdk_gc_set_clip_rectangle (gc1, NULL);
4385 gdk_gc_set_clip_rectangle (gc2, NULL);
4386 gdk_gc_set_clip_rectangle (gc3, NULL);
4387 gdk_gc_set_clip_rectangle (gc4, NULL);
4392 gtk_default_draw_focus (GtkStyle *style,
4394 GtkStateType state_type,
4397 const gchar *detail,
4405 gboolean free_dash_list = FALSE;
4406 gint line_width = 1;
4407 gint8 *dash_list = "\1\1";
4410 gc = style->fg_gc[state_type];
4414 gtk_widget_style_get (widget,
4415 "focus-line-width", &line_width,
4416 "focus-line-pattern", (gchar *)&dash_list,
4419 free_dash_list = TRUE;
4422 sanitize_size (window, &width, &height);
4425 gdk_gc_set_clip_rectangle (gc, area);
4427 gdk_gc_set_line_attributes (gc, line_width,
4428 dash_list[0] ? GDK_LINE_ON_OFF_DASH : GDK_LINE_SOLID,
4429 GDK_CAP_BUTT, GDK_JOIN_MITER);
4432 if (detail && !strcmp (detail, "add-mode"))
4438 free_dash_list = FALSE;
4441 points[0].x = x + line_width / 2;
4442 points[0].y = y + line_width / 2;
4443 points[1].x = x + width - line_width + line_width / 2;
4444 points[1].y = y + line_width / 2;
4445 points[2].x = x + width - line_width + line_width / 2;
4446 points[2].y = y + height - line_width + line_width / 2;
4447 points[3].x = x + line_width / 2;
4448 points[3].y = y + height - line_width + line_width / 2;
4449 points[4] = points[0];
4453 gdk_draw_lines (window, gc, points, 5);
4457 /* We go through all the pain below because the X rasterization
4458 * rules don't really work right for dashed lines if you
4459 * want continuity in segments that go between top/right
4460 * and left/bottom. For instance, a top left corner
4461 * with a 1-1 dash is drawn as:
4468 * This is because pixels on the top and left boundaries
4469 * of polygons are drawn, but not on the bottom and right.
4470 * So, if you have a line going up that turns the corner
4471 * and goes right, there is a one pixel shift in the pattern.
4473 * So, to fix this, we drawn the top and right in one call,
4474 * then the left and bottom in another call, fixing up
4475 * the dash offset for the second call ourselves to get
4476 * continuity at the upper left.
4478 * It's not perfect since we really should have a join at
4479 * the upper left and lower right instead of two intersecting
4480 * lines but that's only really apparent for no-dashes,
4481 * which (for this reason) are done as one polygon and
4482 * don't to through this code path.
4485 dash_len = strlen (dash_list);
4488 gdk_gc_set_dashes (gc, 0, dash_list, dash_len);
4490 gdk_draw_lines (window, gc, points, 3);
4492 /* We draw this line one farther over than it is "supposed" to
4493 * because of another rasterization problem ... if two 1 pixel
4494 * unjoined lines meet at the lower right, there will be a missing
4501 gint dash_pixels = 0;
4504 /* Adjust the dash offset for the bottom and left so we
4505 * match up at the upper left.
4507 for (i = 0; i < dash_len; i++)
4508 dash_pixels += dash_list[i];
4510 if (dash_len % 2 == 1)
4513 gdk_gc_set_dashes (gc, dash_pixels - (width + height - 2 * line_width) % dash_pixels, dash_list, dash_len);
4516 gdk_draw_lines (window, gc, points + 2, 3);
4519 gdk_gc_set_line_attributes (gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
4522 gdk_gc_set_clip_rectangle (gc, NULL);
4529 gtk_default_draw_slider (GtkStyle *style,
4531 GtkStateType state_type,
4532 GtkShadowType shadow_type,
4535 const gchar *detail,
4540 GtkOrientation orientation)
4542 g_return_if_fail (GTK_IS_STYLE (style));
4543 g_return_if_fail (window != NULL);
4545 sanitize_size (window, &width, &height);
4547 gtk_paint_box (style, window, state_type, shadow_type,
4548 area, widget, detail, x, y, width, height);
4551 (strcmp ("hscale", detail) == 0 ||
4552 strcmp ("vscale", detail) == 0))
4554 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4555 gtk_paint_vline (style, window, state_type, area, widget, detail,
4556 y + style->ythickness,
4557 y + height - style->ythickness - 1, x + width / 2);
4559 gtk_paint_hline (style, window, state_type, area, widget, detail,
4560 x + style->xthickness,
4561 x + width - style->xthickness - 1, y + height / 2);
4566 draw_dot (GdkWindow *window,
4574 size = CLAMP (size, 2, 3);
4578 gdk_draw_point (window, light_gc, x, y);
4579 gdk_draw_point (window, light_gc, x+1, y+1);
4581 else if (size == 3);
4583 gdk_draw_point (window, light_gc, x, y);
4584 gdk_draw_point (window, light_gc, x+1, y);
4585 gdk_draw_point (window, light_gc, x, y+1);
4586 gdk_draw_point (window, dark_gc, x+1, y+2);
4587 gdk_draw_point (window, dark_gc, x+2, y+1);
4588 gdk_draw_point (window, dark_gc, x+2, y+2);
4593 gtk_default_draw_handle (GtkStyle *style,
4595 GtkStateType state_type,
4596 GtkShadowType shadow_type,
4599 const gchar *detail,
4604 GtkOrientation orientation)
4607 gint xthick, ythick;
4608 GdkGC *light_gc, *dark_gc;
4613 g_return_if_fail (GTK_IS_STYLE (style));
4614 g_return_if_fail (window != NULL);
4616 sanitize_size (window, &width, &height);
4618 gtk_paint_box (style, window, state_type, shadow_type, area, widget,
4619 detail, x, y, width, height);
4622 if (!strcmp (detail, "paned"))
4624 /* we want to ignore the shadow border in paned widgets */
4628 light_gc = style->light_gc[state_type];
4629 dark_gc = style->black_gc;
4633 xthick = style->xthickness;
4634 ythick = style->ythickness;
4636 light_gc = style->light_gc[state_type];
4637 dark_gc = style->dark_gc[state_type];
4640 rect.x = x + xthick;
4641 rect.y = y + ythick;
4642 rect.width = width - (xthick * 2);
4643 rect.height = height - (ythick * 2);
4646 intersect = gdk_rectangle_intersect (area, &rect, &dest);
4656 gdk_gc_set_clip_rectangle (light_gc, &dest);
4657 gdk_gc_set_clip_rectangle (dark_gc, &dest);
4659 if (!strcmp (detail, "paned"))
4661 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4662 for (xx = x + width/2 - 15; xx <= x + width/2 + 15; xx += 5)
4663 draw_dot (window, light_gc, dark_gc, xx, y + height/2 - 1, 3);
4665 for (yy = y + height/2 - 15; yy <= y + height/2 + 15; yy += 5)
4666 draw_dot (window, light_gc, dark_gc, x + width/2 - 1, yy, 3);
4670 for (yy = y + ythick; yy < (y + height - ythick); yy += 3)
4671 for (xx = x + xthick; xx < (x + width - xthick); xx += 6)
4673 draw_dot (window, light_gc, dark_gc, xx, yy, 2);
4674 draw_dot (window, light_gc, dark_gc, xx + 3, yy + 1, 2);
4678 gdk_gc_set_clip_rectangle (light_gc, NULL);
4679 gdk_gc_set_clip_rectangle (dark_gc, NULL);
4683 create_expander_affine (gdouble affine[6],
4693 width = expander_size / 4.0;
4694 height = expander_size / 2.0;
4696 s = sin (degrees * G_PI / 180.0);
4697 c = cos (degrees * G_PI / 180.0);
4703 affine[4] = -width * c - height * -s + x;
4704 affine[5] = -width * s - height * c + y;
4708 apply_affine_on_point (double affine[6], GdkPoint *point)
4712 x = point->x * affine[0] + point->y * affine[2] + affine[4];
4713 y = point->x * affine[1] + point->y * affine[3] + affine[5];
4720 gtk_style_draw_polygon_with_gc (GdkWindow *window, GdkGC *gc, gint line_width,
4721 gboolean do_fill, GdkPoint *points, gint n_points)
4723 gdk_gc_set_line_attributes (gc, line_width,
4725 GDK_CAP_BUTT, GDK_JOIN_MITER);
4727 gdk_draw_polygon (window, gc, do_fill, points, n_points);
4728 gdk_gc_set_line_attributes (gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
4732 gtk_default_draw_expander (GtkStyle *style,
4734 GtkStateType state_type,
4737 const gchar *detail,
4740 GtkExpanderStyle expander_style)
4749 gtk_widget_style_get (widget,
4750 "expander_size", &expander_size,
4752 line_width = MAX (1, expander_size/7);
4756 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], area);
4757 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], area);
4760 expander_size -= (line_width * 2 - 2);
4761 points[0].x = line_width / 2;
4762 points[0].y = line_width / 2;
4763 points[1].x = expander_size / 2 + line_width / 2;
4764 points[1].y = expander_size / 2 + line_width / 2;
4765 points[2].x = line_width / 2;
4766 points[2].y = expander_size + line_width / 2;
4768 switch (expander_style)
4770 case GTK_EXPANDER_COLLAPSED:
4771 degrees = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ? 180 : 0;
4773 case GTK_EXPANDER_SEMI_COLLAPSED:
4774 degrees = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ? 150 : 30;
4776 case GTK_EXPANDER_SEMI_EXPANDED:
4777 degrees = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ? 120 : 60;
4779 case GTK_EXPANDER_EXPANDED:
4783 g_assert_not_reached ();
4786 create_expander_affine (affine, degrees, expander_size, x, y);
4788 for (i = 0; i < 3; i++)
4789 apply_affine_on_point (affine, &points[i]);
4791 if (state_type == GTK_STATE_PRELIGHT)
4793 gtk_style_draw_polygon_with_gc (window, style->fg_gc[GTK_STATE_NORMAL],
4794 1, TRUE, points, 3);
4796 else if (state_type == GTK_STATE_ACTIVE)
4798 gtk_style_draw_polygon_with_gc (window, style->light_gc[GTK_STATE_ACTIVE],
4799 1, TRUE, points, 3);
4800 gtk_style_draw_polygon_with_gc (window, style->fg_gc[GTK_STATE_NORMAL],
4801 line_width, FALSE, points, 3);
4805 gtk_style_draw_polygon_with_gc (window, style->base_gc[GTK_STATE_NORMAL],
4806 1, TRUE, points, 3);
4807 gtk_style_draw_polygon_with_gc (window, style->fg_gc[GTK_STATE_NORMAL],
4808 line_width, FALSE, points, 3);
4812 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], NULL);
4813 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], NULL);
4817 typedef struct _ByteRange ByteRange;
4826 range_new (guint start,
4829 ByteRange *br = g_new (ByteRange, 1);
4838 get_insensitive_layout (GdkDrawable *drawable,
4839 PangoLayout *layout)
4841 GSList *embossed_ranges = NULL;
4842 GSList *stippled_ranges = NULL;
4843 PangoLayoutIter *iter;
4844 GSList *tmp_list = NULL;
4845 PangoLayout *new_layout;
4846 PangoAttrList *attrs;
4847 GdkBitmap *stipple = NULL;
4849 iter = pango_layout_get_iter (layout);
4853 PangoLayoutRun *run;
4854 PangoAttribute *attr;
4855 gboolean need_stipple = FALSE;
4858 run = pango_layout_iter_get_run (iter);
4862 tmp_list = run->item->analysis.extra_attrs;
4864 while (tmp_list != NULL)
4866 attr = tmp_list->data;
4867 switch (attr->klass->type)
4869 case PANGO_ATTR_FOREGROUND:
4870 case PANGO_ATTR_BACKGROUND:
4871 need_stipple = TRUE;
4881 tmp_list = g_slist_next (tmp_list);
4884 br = range_new (run->item->offset, run->item->offset + run->item->length);
4887 stippled_ranges = g_slist_prepend (stippled_ranges, br);
4889 embossed_ranges = g_slist_prepend (embossed_ranges, br);
4892 while (pango_layout_iter_next_run (iter));
4894 pango_layout_iter_free (iter);
4896 new_layout = pango_layout_copy (layout);
4898 attrs = pango_layout_get_attributes (new_layout);
4902 /* Create attr list if there wasn't one */
4903 attrs = pango_attr_list_new ();
4904 pango_layout_set_attributes (new_layout, attrs);
4905 pango_attr_list_unref (attrs);
4908 tmp_list = embossed_ranges;
4909 while (tmp_list != NULL)
4911 PangoAttribute *attr;
4912 ByteRange *br = tmp_list->data;
4914 attr = gdk_pango_attr_embossed_new (TRUE);
4916 attr->start_index = br->start;
4917 attr->end_index = br->end;
4919 pango_attr_list_change (attrs, attr);
4923 tmp_list = g_slist_next (tmp_list);
4926 g_slist_free (embossed_ranges);
4928 tmp_list = stippled_ranges;
4929 while (tmp_list != NULL)
4931 PangoAttribute *attr;
4932 ByteRange *br = tmp_list->data;
4934 if (stipple == NULL)
4936 #define gray50_width 2
4937 #define gray50_height 2
4938 static char gray50_bits[] = {
4942 stipple = gdk_bitmap_create_from_data (drawable,
4943 gray50_bits, gray50_width,
4947 attr = gdk_pango_attr_stipple_new (stipple);
4949 attr->start_index = br->start;
4950 attr->end_index = br->end;
4952 pango_attr_list_change (attrs, attr);
4956 tmp_list = g_slist_next (tmp_list);
4959 g_slist_free (stippled_ranges);
4962 g_object_unref (stipple);
4968 gtk_default_draw_layout (GtkStyle *style,
4970 GtkStateType state_type,
4974 const gchar *detail,
4977 PangoLayout *layout)
4981 g_return_if_fail (GTK_IS_STYLE (style));
4982 g_return_if_fail (window != NULL);
4984 gc = use_text ? style->text_gc[state_type] : style->fg_gc[state_type];
4987 gdk_gc_set_clip_rectangle (gc, area);
4989 if (state_type == GTK_STATE_INSENSITIVE)
4993 ins = get_insensitive_layout (window, layout);
4995 gdk_draw_layout (window, gc, x, y, ins);
4997 g_object_unref (ins);
5001 gdk_draw_layout (window, gc, x, y, layout);
5005 gdk_gc_set_clip_rectangle (gc, NULL);
5009 gtk_default_draw_resize_grip (GtkStyle *style,
5011 GtkStateType state_type,
5014 const gchar *detail,
5021 g_return_if_fail (GTK_IS_STYLE (style));
5022 g_return_if_fail (window != NULL);
5026 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
5027 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
5028 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
5033 case GDK_WINDOW_EDGE_NORTH_WEST:
5034 /* make it square */
5039 else if (height < width)
5044 case GDK_WINDOW_EDGE_NORTH:
5050 case GDK_WINDOW_EDGE_NORTH_EAST:
5051 /* make it square, aligning to top right */
5056 else if (height < width)
5058 x += (width - height);
5062 case GDK_WINDOW_EDGE_WEST:
5068 case GDK_WINDOW_EDGE_EAST:
5069 /* aligning to right */
5072 x += (width - height);
5076 case GDK_WINDOW_EDGE_SOUTH_WEST:
5077 /* make it square, aligning to bottom left */
5080 y += (height - width);
5083 else if (height < width)
5088 case GDK_WINDOW_EDGE_SOUTH:
5089 /* align to bottom */
5092 y += (height - width);
5096 case GDK_WINDOW_EDGE_SOUTH_EAST:
5097 /* make it square, aligning to bottom right */
5100 y += (height - width);
5103 else if (height < width)
5105 x += (width - height);
5110 g_assert_not_reached ();
5112 /* Clear background */
5113 gtk_style_apply_default_background (style, window, FALSE,
5115 x, y, width, height);
5119 case GDK_WINDOW_EDGE_WEST:
5120 case GDK_WINDOW_EDGE_EAST:
5126 while (xi < x + width)
5128 gdk_draw_line (window,
5129 style->light_gc[state_type],
5134 gdk_draw_line (window,
5135 style->dark_gc[state_type],
5143 case GDK_WINDOW_EDGE_NORTH:
5144 case GDK_WINDOW_EDGE_SOUTH:
5150 while (yi < y + height)
5152 gdk_draw_line (window,
5153 style->light_gc[state_type],
5158 gdk_draw_line (window,
5159 style->dark_gc[state_type],
5167 case GDK_WINDOW_EDGE_NORTH_WEST:
5176 gdk_draw_line (window,
5177 style->dark_gc[state_type],
5184 gdk_draw_line (window,
5185 style->dark_gc[state_type],
5192 gdk_draw_line (window,
5193 style->light_gc[state_type],
5203 case GDK_WINDOW_EDGE_NORTH_EAST:
5210 while (xi < (x + width - 3))
5212 gdk_draw_line (window,
5213 style->light_gc[state_type],
5220 gdk_draw_line (window,
5221 style->dark_gc[state_type],
5228 gdk_draw_line (window,
5229 style->dark_gc[state_type],
5238 case GDK_WINDOW_EDGE_SOUTH_WEST:
5247 gdk_draw_line (window,
5248 style->dark_gc[state_type],
5255 gdk_draw_line (window,
5256 style->dark_gc[state_type],
5263 gdk_draw_line (window,
5264 style->light_gc[state_type],
5274 case GDK_WINDOW_EDGE_SOUTH_EAST:
5281 while (xi < (x + width - 3))
5283 gdk_draw_line (window,
5284 style->light_gc[state_type],
5291 gdk_draw_line (window,
5292 style->dark_gc[state_type],
5299 gdk_draw_line (window,
5300 style->dark_gc[state_type],
5310 g_assert_not_reached ();
5316 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
5317 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
5318 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
5323 gtk_style_shade (GdkColor *a,
5331 red = (gdouble) a->red / 65535.0;
5332 green = (gdouble) a->green / 65535.0;
5333 blue = (gdouble) a->blue / 65535.0;
5335 rgb_to_hls (&red, &green, &blue);
5340 else if (green < 0.0)
5346 else if (blue < 0.0)
5349 hls_to_rgb (&red, &green, &blue);
5351 b->red = red * 65535.0;
5352 b->green = green * 65535.0;
5353 b->blue = blue * 65535.0;
5357 rgb_to_hls (gdouble *r,
5398 l = (max + min) / 2;
5405 s = (max - min) / (max + min);
5407 s = (max - min) / (2 - max - min);
5411 h = (green - blue) / delta;
5412 else if (green == max)
5413 h = 2 + (blue - red) / delta;
5414 else if (blue == max)
5415 h = 4 + (red - green) / delta;
5428 hls_to_rgb (gdouble *h,
5441 if (lightness <= 0.5)
5442 m2 = lightness * (1 + saturation);
5444 m2 = lightness + saturation - lightness * saturation;
5445 m1 = 2 * lightness - m2;
5447 if (saturation == 0)
5462 r = m1 + (m2 - m1) * hue / 60;
5466 r = m1 + (m2 - m1) * (240 - hue) / 60;
5477 g = m1 + (m2 - m1) * hue / 60;
5481 g = m1 + (m2 - m1) * (240 - hue) / 60;
5492 b = m1 + (m2 - m1) * hue / 60;
5496 b = m1 + (m2 - m1) * (240 - hue) / 60;
5509 * @style: a #GtkStyle
5510 * @window: a #GdkWindow
5511 * @state_type: a state
5512 * @area: rectangle to which the output is clipped
5515 * @x1: the starting x coordinate
5516 * @x2: the ending x coordinate
5517 * @y: the y coordinate
5519 * Draws a horizontal line from (@x1, @y) to (@x2, @y) in @window
5520 * using the given style and state.
5523 gtk_paint_hline (GtkStyle *style,
5525 GtkStateType state_type,
5528 const gchar *detail,
5533 g_return_if_fail (GTK_IS_STYLE (style));
5534 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
5536 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, area, widget, detail, x1, x2, y);
5541 * @style: a #GtkStyle
5542 * @window: a #GdkWindow
5543 * @state_type: a state
5544 * @area: rectangle to which the output is clipped
5547 * @y1_: the starting y coordinate
5548 * @y2_: the ending y coordinate
5549 * @x: the x coordinate
5551 * Draws a vertical line from (@x, @y1_) to (@x, @y2_) in @window
5552 * using the given style and state.
5555 gtk_paint_vline (GtkStyle *style,
5557 GtkStateType state_type,
5560 const gchar *detail,
5565 g_return_if_fail (GTK_IS_STYLE (style));
5566 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
5568 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, area, widget, detail, y1, y2, x);
5572 gtk_paint_shadow (GtkStyle *style,
5574 GtkStateType state_type,
5575 GtkShadowType shadow_type,
5578 const gchar *detail,
5584 g_return_if_fail (GTK_IS_STYLE (style));
5585 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
5587 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5591 gtk_paint_polygon (GtkStyle *style,
5593 GtkStateType state_type,
5594 GtkShadowType shadow_type,
5597 const gchar *detail,
5602 g_return_if_fail (GTK_IS_STYLE (style));
5603 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
5605 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, area, widget, detail, points, npoints, fill);
5609 gtk_paint_arrow (GtkStyle *style,
5611 GtkStateType state_type,
5612 GtkShadowType shadow_type,
5615 const gchar *detail,
5616 GtkArrowType arrow_type,
5623 g_return_if_fail (GTK_IS_STYLE (style));
5624 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
5626 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, area, widget, detail, arrow_type, fill, x, y, width, height);
5630 gtk_paint_diamond (GtkStyle *style,
5632 GtkStateType state_type,
5633 GtkShadowType shadow_type,
5636 const gchar *detail,
5642 g_return_if_fail (GTK_IS_STYLE (style));
5643 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
5645 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5650 * @style: a #GtkStyle
5651 * @window: a #GdkWindow
5652 * @state_type: a state
5653 * @area: clip rectangle
5654 * @widget: the widget
5655 * @detail: a style detail
5658 * @string: the string to draw
5660 * Draws a text string on @window with the given parameters.
5662 * This function is deprecated, use gtk_paint_layout() instead.
5665 gtk_paint_string (GtkStyle *style,
5667 GtkStateType state_type,
5670 const gchar *detail,
5673 const gchar *string)
5675 g_return_if_fail (GTK_IS_STYLE (style));
5676 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
5678 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, area, widget, detail, x, y, string);
5682 gtk_paint_box (GtkStyle *style,
5684 GtkStateType state_type,
5685 GtkShadowType shadow_type,
5688 const gchar *detail,
5694 g_return_if_fail (GTK_IS_STYLE (style));
5695 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
5697 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5701 gtk_paint_flat_box (GtkStyle *style,
5703 GtkStateType state_type,
5704 GtkShadowType shadow_type,
5707 const gchar *detail,
5713 g_return_if_fail (GTK_IS_STYLE (style));
5714 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
5716 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5720 gtk_paint_check (GtkStyle *style,
5722 GtkStateType state_type,
5723 GtkShadowType shadow_type,
5726 const gchar *detail,
5732 g_return_if_fail (GTK_IS_STYLE (style));
5733 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
5735 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5739 gtk_paint_option (GtkStyle *style,
5741 GtkStateType state_type,
5742 GtkShadowType shadow_type,
5745 const gchar *detail,
5751 g_return_if_fail (GTK_IS_STYLE (style));
5752 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
5754 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5758 gtk_paint_tab (GtkStyle *style,
5760 GtkStateType state_type,
5761 GtkShadowType shadow_type,
5764 const gchar *detail,
5770 g_return_if_fail (GTK_IS_STYLE (style));
5771 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
5773 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5777 gtk_paint_shadow_gap (GtkStyle *style,
5779 GtkStateType state_type,
5780 GtkShadowType shadow_type,
5788 GtkPositionType gap_side,
5792 g_return_if_fail (GTK_IS_STYLE (style));
5793 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
5795 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);
5800 gtk_paint_box_gap (GtkStyle *style,
5802 GtkStateType state_type,
5803 GtkShadowType shadow_type,
5811 GtkPositionType gap_side,
5815 g_return_if_fail (GTK_IS_STYLE (style));
5816 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
5818 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);
5822 gtk_paint_extension (GtkStyle *style,
5824 GtkStateType state_type,
5825 GtkShadowType shadow_type,
5833 GtkPositionType gap_side)
5835 g_return_if_fail (GTK_IS_STYLE (style));
5836 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
5838 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side);
5842 gtk_paint_focus (GtkStyle *style,
5844 GtkStateType state_type,
5847 const gchar *detail,
5853 g_return_if_fail (GTK_IS_STYLE (style));
5854 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
5856 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, state_type, area, widget, detail, x, y, width, height);
5860 gtk_paint_slider (GtkStyle *style,
5862 GtkStateType state_type,
5863 GtkShadowType shadow_type,
5866 const gchar *detail,
5871 GtkOrientation orientation)
5873 g_return_if_fail (GTK_IS_STYLE (style));
5874 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
5876 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
5880 gtk_paint_handle (GtkStyle *style,
5882 GtkStateType state_type,
5883 GtkShadowType shadow_type,
5886 const gchar *detail,
5891 GtkOrientation orientation)
5893 g_return_if_fail (GTK_IS_STYLE (style));
5894 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
5896 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
5900 gtk_paint_expander (GtkStyle *style,
5902 GtkStateType state_type,
5905 const gchar *detail,
5908 GtkExpanderStyle expander_style)
5910 g_return_if_fail (GTK_IS_STYLE (style));
5911 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
5913 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type, area,
5914 widget, detail, x, y, expander_style);
5918 gtk_paint_layout (GtkStyle *style,
5920 GtkStateType state_type,
5924 const gchar *detail,
5927 PangoLayout *layout)
5929 g_return_if_fail (GTK_IS_STYLE (style));
5930 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
5932 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text, area,
5933 widget, detail, x, y, layout);
5937 gtk_paint_resize_grip (GtkStyle *style,
5939 GtkStateType state_type,
5942 const gchar *detail,
5950 g_return_if_fail (GTK_IS_STYLE (style));
5951 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
5953 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
5954 area, widget, detail,
5955 edge, x, y, width, height);
5960 * @border_: a #GtkBorder.
5961 * @returns: a copy of @border_.
5963 * Copies a #GtkBorder structure.
5966 gtk_border_copy (const GtkBorder *border)
5968 return (GtkBorder *)g_memdup (border, sizeof (GtkBorder));
5973 * @border_: a #GtkBorder.
5975 * Frees a #GtkBorder structure.
5978 gtk_border_free (GtkBorder *border)
5984 gtk_border_get_type (void)
5986 static GType our_type = 0;
5989 our_type = g_boxed_type_register_static ("GtkBorder",
5990 (GBoxedCopyFunc) gtk_border_copy,
5991 (GBoxedFreeFunc) gtk_border_free);
5997 * gtk_style_get_font:
5998 * @style: a #GtkStyle
6000 * Gets the #GdkFont to use for the given style. This is
6001 * meant only as a replacement for direct access to @style->font
6002 * and should not be used in new code. New code should
6003 * use @style->font_desc instead.
6005 * Return value: the #GdkFont for the style. This font is owned
6006 * by the style; if you want to keep around a copy, you must
6007 * call gdk_font_ref().
6010 gtk_style_get_font (GtkStyle *style)
6012 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
6014 if (style->private_font && style->private_font_desc)
6016 if (!style->font_desc ||
6017 !pango_font_description_equal (style->private_font_desc, style->font_desc))
6019 gdk_font_unref (style->private_font);
6020 style->private_font = NULL;
6022 if (style->private_font_desc)
6024 pango_font_description_free (style->private_font_desc);
6025 style->private_font_desc = NULL;
6030 if (!style->private_font)
6032 GdkDisplay *display;
6034 if (style->colormap)
6036 display = gdk_screen_get_display (gdk_colormap_get_screen (style->colormap));
6040 display = gdk_display_get_default ();
6041 GTK_NOTE (MULTIHEAD,
6042 g_warning ("gtk_style_get_font() should not be called on an unattached style"));
6045 if (style->font_desc)
6047 style->private_font = gdk_font_from_description_for_display (display, style->font_desc);
6048 style->private_font_desc = pango_font_description_copy (style->font_desc);
6051 if (!style->private_font)
6052 style->private_font = gdk_font_load_for_display (display, "fixed");
6054 if (!style->private_font)
6055 g_error ("Unable to load \"fixed\" font");
6058 return style->private_font;
6062 * gtk_style_set_font:
6063 * @style: a #GtkStyle.
6064 * @font: a #GdkFont, or %NULL to use the #GdkFont corresponding
6065 * to style->font_desc.
6067 * Sets the #GdkFont to use for a given style. This is
6068 * meant only as a replacement for direct access to style->font
6069 * and should not be used in new code. New code should
6070 * use style->font_desc instead.
6073 gtk_style_set_font (GtkStyle *style,
6078 g_return_if_fail (GTK_IS_STYLE (style));
6080 old_font = style->private_font;
6082 style->private_font = font;
6084 gdk_font_ref (font);
6087 gdk_font_unref (old_font);
6089 if (style->private_font_desc)
6091 pango_font_description_free (style->private_font_desc);
6092 style->private_font_desc = NULL;
6096 typedef struct _CursorInfo CursorInfo;
6102 GdkGC *secondary_gc;
6106 style_unrealize_cursor_gcs (GtkStyle *style)
6110 cursor_info = g_object_get_data (G_OBJECT (style), "gtk-style-cursor-info");
6113 if (cursor_info->primary_gc)
6114 gtk_gc_release (cursor_info->primary_gc);
6116 if (cursor_info->secondary_gc)
6117 gtk_gc_release (cursor_info->secondary_gc);
6119 g_free (cursor_info);
6120 g_object_set_data (G_OBJECT (style), "gtk-style-cursor-info", NULL);
6125 make_cursor_gc (GtkWidget *widget,
6126 const gchar *property_name,
6129 GdkGCValues gc_values;
6130 GdkGCValuesMask gc_values_mask;
6131 GdkColor *cursor_color;
6133 gtk_widget_style_get (widget, property_name, &cursor_color, NULL);
6135 gc_values_mask = GDK_GC_FOREGROUND;
6138 gc_values.foreground = *cursor_color;
6139 gdk_color_free (cursor_color);
6142 gc_values.foreground = *fallback;
6144 gdk_rgb_find_color (widget->style->colormap, &gc_values.foreground);
6145 return gtk_gc_get (widget->style->depth, widget->style->colormap, &gc_values, gc_values_mask);
6149 * _gtk_get_insertion_cursor_gc:
6150 * @widget: a #GtkWidget
6151 * @is_primary: if the cursor should be the primary cursor color.
6153 * Get a GC suitable for drawing the primary or secondary text
6156 * Note: the return value is ref'ed because calls to this function
6157 * on other widgets could result in this the GC being released
6158 * which would be an unexpected side effect. If made public,
6159 * this function should possibly be called create_insertion_cursor_gc().
6161 * Return value: an appropriate #GdkGC. Call g_object_unref() on
6162 * the gc when you are done with it; this GC may be shared with
6163 * other users, so you must not modify the GC except for temporarily
6164 * setting the clip before drawing with the GC, and then unsetting the clip
6168 _gtk_get_insertion_cursor_gc (GtkWidget *widget,
6169 gboolean is_primary)
6171 CursorInfo *cursor_info;
6173 cursor_info = g_object_get_data (G_OBJECT (widget->style), "gtk-style-cursor-info");
6176 cursor_info = g_new (CursorInfo, 1);
6177 g_object_set_data (G_OBJECT (widget->style), "gtk-style-cursor-info", cursor_info);
6178 cursor_info->primary_gc = NULL;
6179 cursor_info->secondary_gc = NULL;
6180 cursor_info->for_type = G_TYPE_INVALID;
6183 /* We have to keep track of the type because gtk_widget_style_get()
6184 * can return different results when called on the same property and
6185 * same style but for different widgets. :-(. That is,
6186 * GtkEntry::cursor-color = "red" in a style will modify the cursor
6187 * color for entries but not for text view.
6189 if (cursor_info->for_type != G_OBJECT_TYPE (widget))
6191 cursor_info->for_type = G_OBJECT_TYPE (widget);
6192 if (cursor_info->primary_gc)
6194 gtk_gc_release (cursor_info->primary_gc);
6195 cursor_info->primary_gc = NULL;
6197 if (cursor_info->secondary_gc)
6199 gtk_gc_release (cursor_info->secondary_gc);
6200 cursor_info->secondary_gc = NULL;
6206 if (!cursor_info->primary_gc)
6207 cursor_info->primary_gc = make_cursor_gc (widget,
6209 &widget->style->black);
6211 return g_object_ref (cursor_info->primary_gc);
6215 static GdkColor gray = { 0, 0x8888, 0x8888, 0x8888 };
6217 if (!cursor_info->secondary_gc)
6218 cursor_info->secondary_gc = make_cursor_gc (widget,
6219 "secondary-cursor-color",
6222 return g_object_ref (cursor_info->secondary_gc);
6227 * _gtk_draw_insertion_cursor:
6228 * @widget: a #GtkWidget
6229 * @drawable: a #GdkDrawable
6231 * @location: location where to draw the cursor (@location->width is ignored)
6232 * @direction: whether the cursor is left-to-right or
6233 * right-to-left. Should never be #GTK_TEXT_DIR_NONE
6234 * @draw_arrow: %TRUE to draw a directional arrow on the
6235 * cursor. Should be %FALSE unless the cursor is split.
6237 * Draws a text caret on @drawable at @location. This is not a style function
6238 * but merely a convenience function for drawing the standard cursor shape.
6241 _gtk_draw_insertion_cursor (GtkWidget *widget,
6242 GdkDrawable *drawable,
6244 GdkRectangle *location,
6245 GtkTextDirection direction,
6246 gboolean draw_arrow)
6252 gfloat cursor_aspect_ratio;
6255 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
6257 gtk_widget_style_get (widget, "cursor-aspect-ratio", &cursor_aspect_ratio, NULL);
6259 stem_width = location->height * cursor_aspect_ratio + 1;
6260 arrow_width = stem_width + 1;
6262 /* put (stem_width % 2) on the proper side of the cursor */
6263 if (direction == GTK_TEXT_DIR_LTR)
6264 offset = stem_width / 2;
6266 offset = stem_width - stem_width / 2;
6268 for (i = 0; i < stem_width; i++)
6269 gdk_draw_line (drawable, gc,
6270 location->x + i - offset, location->y,
6271 location->x + i - offset, location->y + location->height - 1);
6275 if (direction == GTK_TEXT_DIR_RTL)
6277 x = location->x - offset - 1;
6278 y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
6280 for (i = 0; i < arrow_width; i++)
6282 gdk_draw_line (drawable, gc,
6284 x, y + 2 * arrow_width - i - 1);
6288 else if (direction == GTK_TEXT_DIR_LTR)
6290 x = location->x + stem_width - offset;
6291 y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
6293 for (i = 0; i < arrow_width; i++)
6295 gdk_draw_line (drawable, gc,
6297 x, y + 2 * arrow_width - i - 1);