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 char 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 char 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 char 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 char 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 char 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 char 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 char 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 char 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 char 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-ssp.png, width=13, height=13
383 static char 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,0x00,0x00};
386 static char radio_dark_bits[] = {
387 0xf0,0x00,0x0c,0x02,0x02,0x04,0x02,0x04,0x01,0x08,0x01,0x08,0x01,0x08,0x01,
388 0x08,0x00,0x04,0x02,0x04,0x0c,0x03,0xf0,0x00,0x00,0x00,0x00,0x00};
389 static char 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 char radio_light_bits[] = {
393 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
394 0x10,0x00,0x08,0x00,0x08,0x00,0x04,0x00,0x03,0xf0,0x00,0x00,0x00};
395 static char 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};
398 static char radio_aa_bits[] = {
399 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
400 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
401 static char radio_base_bits[] = {
402 0x00,0x00,0x00,0x00,0xf0,0x01,0xf8,0x03,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,
403 0x07,0xfc,0x03,0xf8,0x03,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
405 * Extracted from radio-13-inconsistent-ssp.png, width=13, height=13
407 static char radio_inconsistent_text_bits[] = {
408 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,0x03,0x00,
409 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
410 static char radio_inconsistent_aa_bits[] = {
411 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,0x03,0x00,0x00,0xf8,
412 0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
416 GList *bmap_list; /* list of GdkBitmap */
417 } indicator_parts[] = {
418 { check_aa_bits, NULL },
419 { check_base_bits, NULL },
420 { check_black_bits, NULL },
421 { check_dark_bits, NULL },
422 { check_light_bits, NULL },
423 { check_mid_bits, NULL },
424 { check_text_bits, NULL },
425 { check_inconsistent_aa_bits, NULL },
426 { check_inconsistent_text_bits, NULL },
427 { radio_base_bits, NULL },
428 { radio_black_bits, NULL },
429 { radio_dark_bits, NULL },
430 { radio_light_bits, NULL },
431 { radio_mid_bits, NULL },
432 { radio_text_bits, NULL },
433 { radio_inconsistent_aa_bits, NULL },
434 { radio_inconsistent_text_bits, NULL },
437 /* --- variables --- */
438 static GdkColor gtk_default_normal_fg = { 0, 0, 0, 0 };
439 static GdkColor gtk_default_active_fg = { 0, 0, 0, 0 };
440 static GdkColor gtk_default_prelight_fg = { 0, 0, 0, 0 };
441 static GdkColor gtk_default_selected_fg = { 0, 0xffff, 0xffff, 0xffff };
442 static GdkColor gtk_default_insensitive_fg = { 0, 0x7530, 0x7530, 0x7530 };
444 static GdkColor gtk_default_normal_bg = { 0, 0xd6d6, 0xd6d6, 0xd6d6 };
445 static GdkColor gtk_default_active_bg = { 0, 0xc350, 0xc350, 0xc350 };
446 static GdkColor gtk_default_prelight_bg = { 0, 0xea60, 0xea60, 0xea60 };
447 static GdkColor gtk_default_selected_bg = { 0, 0, 0, 0x9c40 };
448 static GdkColor gtk_default_insensitive_bg = { 0, 0xd6d6, 0xd6d6, 0xd6d6 };
449 static GdkColor gtk_default_selected_base = { 0, 0xa4a4, 0xdfdf, 0xffff };
450 static GdkColor gtk_default_active_base = { 0, 0xbcbc, 0xd2d2, 0xeeee };
452 static gpointer parent_class = NULL;
455 /* --- functions --- */
457 gtk_style_get_type (void)
459 static GType style_type = 0;
463 static const GTypeInfo style_info =
465 sizeof (GtkStyleClass),
466 (GBaseInitFunc) NULL,
467 (GBaseFinalizeFunc) NULL,
468 (GClassInitFunc) gtk_style_class_init,
469 NULL, /* class_finalize */
470 NULL, /* class_data */
473 (GInstanceInitFunc) gtk_style_init,
476 style_type = g_type_register_static (G_TYPE_OBJECT,
485 gtk_style_init (GtkStyle *style)
488 const gchar *font_name = _gtk_rc_context_get_default_font_name (gtk_settings_get_default ());
490 style->font_desc = pango_font_description_from_string (font_name);
492 if (!pango_font_description_get_family (style->font_desc))
494 g_warning ("Default font does not have a family set");
495 pango_font_description_set_family (style->font_desc, "Sans");
497 if (pango_font_description_get_size (style->font_desc) <= 0)
499 g_warning ("Default font does not have a positive size");
500 pango_font_description_set_size (style->font_desc, 10 * PANGO_SCALE);
503 style->attach_count = 0;
504 style->colormap = NULL;
507 style->black.red = 0;
508 style->black.green = 0;
509 style->black.blue = 0;
511 style->white.red = 65535;
512 style->white.green = 65535;
513 style->white.blue = 65535;
515 style->black_gc = NULL;
516 style->white_gc = NULL;
518 style->fg[GTK_STATE_NORMAL] = gtk_default_normal_fg;
519 style->fg[GTK_STATE_ACTIVE] = gtk_default_active_fg;
520 style->fg[GTK_STATE_PRELIGHT] = gtk_default_prelight_fg;
521 style->fg[GTK_STATE_SELECTED] = gtk_default_selected_fg;
522 style->fg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
524 style->bg[GTK_STATE_NORMAL] = gtk_default_normal_bg;
525 style->bg[GTK_STATE_ACTIVE] = gtk_default_active_bg;
526 style->bg[GTK_STATE_PRELIGHT] = gtk_default_prelight_bg;
527 style->bg[GTK_STATE_SELECTED] = gtk_default_selected_bg;
528 style->bg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg;
530 for (i = 0; i < 4; i++)
532 style->text[i] = style->fg[i];
533 style->base[i] = style->white;
536 style->base[GTK_STATE_SELECTED] = gtk_default_selected_base;
537 style->text[GTK_STATE_SELECTED] = style->black;
538 style->base[GTK_STATE_ACTIVE] = gtk_default_active_base;
539 style->text[GTK_STATE_ACTIVE] = style->black;
540 style->base[GTK_STATE_INSENSITIVE] = gtk_default_prelight_bg;
541 style->text[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
543 for (i = 0; i < 5; i++)
544 style->bg_pixmap[i] = NULL;
546 style->rc_style = NULL;
548 for (i = 0; i < 5; i++)
550 style->fg_gc[i] = NULL;
551 style->bg_gc[i] = NULL;
552 style->light_gc[i] = NULL;
553 style->dark_gc[i] = NULL;
554 style->mid_gc[i] = NULL;
555 style->text_gc[i] = NULL;
556 style->base_gc[i] = NULL;
557 style->text_aa_gc[i] = NULL;
560 style->xthickness = 2;
561 style->ythickness = 2;
563 style->property_cache = NULL;
567 gtk_style_class_init (GtkStyleClass *klass)
569 GObjectClass *object_class = G_OBJECT_CLASS (klass);
571 parent_class = g_type_class_peek_parent (klass);
573 object_class->finalize = gtk_style_finalize;
575 klass->clone = gtk_style_real_clone;
576 klass->copy = gtk_style_real_copy;
577 klass->init_from_rc = gtk_style_real_init_from_rc;
578 klass->realize = gtk_style_real_realize;
579 klass->unrealize = gtk_style_real_unrealize;
580 klass->set_background = gtk_style_real_set_background;
581 klass->render_icon = gtk_default_render_icon;
583 klass->draw_hline = gtk_default_draw_hline;
584 klass->draw_vline = gtk_default_draw_vline;
585 klass->draw_shadow = gtk_default_draw_shadow;
586 klass->draw_polygon = gtk_default_draw_polygon;
587 klass->draw_arrow = gtk_default_draw_arrow;
588 klass->draw_diamond = gtk_default_draw_diamond;
589 klass->draw_string = gtk_default_draw_string;
590 klass->draw_box = gtk_default_draw_box;
591 klass->draw_flat_box = gtk_default_draw_flat_box;
592 klass->draw_check = gtk_default_draw_check;
593 klass->draw_option = gtk_default_draw_option;
594 klass->draw_tab = gtk_default_draw_tab;
595 klass->draw_shadow_gap = gtk_default_draw_shadow_gap;
596 klass->draw_box_gap = gtk_default_draw_box_gap;
597 klass->draw_extension = gtk_default_draw_extension;
598 klass->draw_focus = gtk_default_draw_focus;
599 klass->draw_slider = gtk_default_draw_slider;
600 klass->draw_handle = gtk_default_draw_handle;
601 klass->draw_expander = gtk_default_draw_expander;
602 klass->draw_layout = gtk_default_draw_layout;
603 klass->draw_resize_grip = gtk_default_draw_resize_grip;
607 clear_property_cache (GtkStyle *style)
609 if (style->property_cache)
613 for (i = 0; i < style->property_cache->len; i++)
615 PropertyValue *node = &g_array_index (style->property_cache, PropertyValue, i);
617 g_param_spec_unref (node->pspec);
618 g_value_unset (&node->value);
620 g_array_free (style->property_cache, TRUE);
621 style->property_cache = NULL;
626 gtk_style_finalize (GObject *object)
628 GtkStyle *style = GTK_STYLE (object);
630 g_return_if_fail (style->attach_count == 0);
632 clear_property_cache (style);
636 if (style->styles->data != style)
637 g_slist_remove (style->styles, style);
640 GSList *tmp_list = style->styles->next;
644 GTK_STYLE (tmp_list->data)->styles = style->styles->next;
645 tmp_list = tmp_list->next;
647 g_slist_free_1 (style->styles);
651 pango_font_description_free (style->font_desc);
653 if (style->private_font)
654 gdk_font_unref (style->private_font);
656 if (style->private_font_desc)
657 pango_font_description_free (style->private_font_desc);
660 gtk_rc_style_unref (style->rc_style);
662 G_OBJECT_CLASS (parent_class)->finalize (object);
667 gtk_style_copy (GtkStyle *style)
671 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
673 new_style = GTK_STYLE_GET_CLASS (style)->clone (style);
674 GTK_STYLE_GET_CLASS (style)->copy (new_style, style);
680 gtk_style_duplicate (GtkStyle *style)
684 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
686 new_style = gtk_style_copy (style);
688 style->styles = g_slist_append (style->styles, new_style);
689 new_style->styles = style->styles;
696 * @returns: a new #GtkStyle.
698 * Creates a new #GtkStyle.
705 style = g_object_new (GTK_TYPE_STYLE, NULL);
712 * @style: a #GtkStyle.
713 * @window: a #GtkWindow.
714 * @returns: Either @style, or a newly-created #GtkStyle.
715 * If the style is newly created, the style parameter
716 * will be dereferenced, and the new style will have
717 * a reference count belonging to the caller.
719 * Attaches a style to a window; this process allocates the
720 * colors and creates the GC's for the style - it specializes
721 * it to a particular visual and colormap. The process may
722 * involve the creation of a new style if the style has already
723 * been attached to a window with a different style and colormap.
726 * FIXME: The sequence -
727 * create a style => s1
728 * attach s1 to v1, c1 => s1
729 * attach s1 to v2, c2 => s2
730 * detach s1 from v1, c1
731 * attach s1 to v2, c2 => s3
732 * results in two separate, unlinked styles s2 and s3 which
733 * are identical and could be shared. To fix this, we would
734 * want to never remove a style from the list of linked
735 * styles as long as as it has a reference count. However, the
736 * disadvantage of doing it this way means that we would need two
737 * passes through the linked list when attaching (one to check for
738 * matching styles, one to look for empty unattached styles - but
739 * it will almost never be longer than 2 elements.
742 gtk_style_attach (GtkStyle *style,
746 GtkStyle *new_style = NULL;
747 GdkColormap *colormap;
749 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
750 g_return_val_if_fail (window != NULL, NULL);
752 colormap = gdk_window_get_colormap (window);
755 style->styles = g_slist_append (NULL, style);
757 styles = style->styles;
760 new_style = styles->data;
762 if (new_style->attach_count == 0)
764 gtk_style_realize (new_style, colormap);
767 else if (new_style->colormap == colormap)
771 styles = styles->next;
776 new_style = gtk_style_duplicate (style);
777 if (style->colormap->screen != colormap->screen &&
778 new_style->private_font)
780 gdk_font_unref (new_style->private_font);
781 new_style->private_font = NULL;
783 gtk_style_realize (new_style, colormap);
786 /* A style gets a refcount from being attached */
787 if (new_style->attach_count == 0)
788 g_object_ref (new_style);
790 /* Another refcount belongs to the parent */
791 if (style != new_style)
793 g_object_unref (style);
794 g_object_ref (new_style);
797 new_style->attach_count++;
803 gtk_style_detach (GtkStyle *style)
805 g_return_if_fail (GTK_IS_STYLE (style));
807 style->attach_count -= 1;
808 if (style->attach_count == 0)
810 GTK_STYLE_GET_CLASS (style)->unrealize (style);
812 gdk_colormap_unref (style->colormap);
813 style->colormap = NULL;
815 g_object_unref (style);
821 * @style: a #GtkStyle.
824 * Deprecated equivalent of g_object_ref().
827 gtk_style_ref (GtkStyle *style)
829 return (GtkStyle *) g_object_ref (G_OBJECT (style));
834 * @style: a #GtkStyle.
836 * Deprecated equivalent of g_object_unref().
839 gtk_style_unref (GtkStyle *style)
841 g_object_unref (G_OBJECT (style));
845 gtk_style_realize (GtkStyle *style,
846 GdkColormap *colormap)
848 g_return_if_fail (GTK_IS_STYLE (style));
849 g_return_if_fail (GDK_IS_COLORMAP (colormap));
851 style->colormap = gdk_colormap_ref (colormap);
852 style->depth = gdk_colormap_get_visual (colormap)->depth;
854 GTK_STYLE_GET_CLASS (style)->realize (style);
858 gtk_style_lookup_icon_set (GtkStyle *style,
859 const char *stock_id)
863 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
864 g_return_val_if_fail (stock_id != NULL, NULL);
866 iter = style->icon_factories;
869 GtkIconSet *icon_set = gtk_icon_factory_lookup (GTK_ICON_FACTORY (iter->data),
874 iter = g_slist_next (iter);
877 return gtk_icon_factory_lookup_default (stock_id);
882 * @style: a #GtkStyle
883 * @window: a #GdkWindow
884 * @state_type: a state
885 * @x1: the starting x coordinate
886 * @x2: the ending x coordinate
887 * @y: the y coordinate
889 * Draws a horizontal line from (@x1, @y) to (@x2, @y) in @window
890 * using the given style and state.
892 * This function is deprecated, use gtk_paint_hline() instead.
895 gtk_draw_hline (GtkStyle *style,
897 GtkStateType state_type,
902 g_return_if_fail (GTK_IS_STYLE (style));
903 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
905 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, NULL, NULL, NULL, x1, x2, y);
911 * @style: a #GtkStyle
912 * @window: a #GdkWindow
913 * @state_type: a state
914 * @y1: the starting y coordinate
915 * @y2: the ending y coordinate
916 * @x: the x coordinate
918 * Draws a vertical line from (@x, @y1) to (@x, @y2) in @window
919 * using the given style and state.
921 * This function is deprecated, use gtk_paint_vline() instead.
924 gtk_draw_vline (GtkStyle *style,
926 GtkStateType state_type,
931 g_return_if_fail (GTK_IS_STYLE (style));
932 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
934 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, NULL, NULL, NULL, y1, y2, x);
939 * @style: a #GtkStyle
940 * @window: a #GdkWindow
941 * @state_type: a state
942 * @shadow_type: type of shadow to draw
943 * @x: x origin of the rectangle
944 * @y: y origin of the rectangle
945 * @width: width of the rectangle
946 * @height: width of the rectangle
948 * Draws a shadow around the given rectangle in @window
949 * using the given style and state and shadow type.
951 * This function is deprecated, use gtk_paint_shadow() instead.
954 gtk_draw_shadow (GtkStyle *style,
956 GtkStateType state_type,
957 GtkShadowType shadow_type,
963 g_return_if_fail (GTK_IS_STYLE (style));
964 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
966 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
971 * @style: a #GtkStyle
972 * @window: a #GdkWindow
973 * @state_type: a state
974 * @shadow_type: type of shadow to draw
975 * @points: an array of #GdkPoint<!-- -->s
976 * @npoints: length of @points
977 * @fill: %TRUE if the polygon should be filled
979 * Draws a polygon on @window with the given parameters.
981 * This function is deprecated, use gtk_paint_polygon() instead.
984 gtk_draw_polygon (GtkStyle *style,
986 GtkStateType state_type,
987 GtkShadowType shadow_type,
992 g_return_if_fail (GTK_IS_STYLE (style));
993 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_polygon != NULL);
995 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, NULL, NULL, NULL, points, npoints, fill);
1000 * @style: a #GtkStyle
1001 * @window: a #GdkWindow
1002 * @state_type: a state
1003 * @shadow_type: the type of shadow to draw
1004 * @arrow_type: the type of arrow to draw
1005 * @fill: %TRUE if the arrow tip should be filled
1006 * @x: x origin of the rectangle to draw the arrow in
1007 * @y: y origin of the rectangle to draw the arrow in
1008 * @width: width of the rectangle to draw the arrow in
1009 * @height: height of the rectangle to draw the arrow in
1011 * Draws an arrow in the given rectangle on @window using the given
1012 * parameters. @arrow_type determines the direction of the arrow.
1014 * This function is deprecated, use gtk_paint_arrow() instead.
1017 gtk_draw_arrow (GtkStyle *style,
1019 GtkStateType state_type,
1020 GtkShadowType shadow_type,
1021 GtkArrowType arrow_type,
1028 g_return_if_fail (GTK_IS_STYLE (style));
1029 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
1031 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, NULL, NULL, NULL, arrow_type, fill, x, y, width, height);
1036 * @style: a #GtkStyle
1037 * @window: a #GdkWindow
1038 * @state_type: a state
1039 * @shadow_type: the type of shadow to draw
1040 * @x: x origin of the rectangle to draw the diamond in
1041 * @y: y origin of the rectangle to draw the diamond in
1042 * @width: width of the rectangle to draw the diamond in
1043 * @height: height of the rectangle to draw the diamond in
1045 * Draws a diamond in the given rectangle on @window using the given parameters.
1047 * This function is deprecated, use gtk_paint_diamond() instead.
1050 gtk_draw_diamond (GtkStyle *style,
1052 GtkStateType state_type,
1053 GtkShadowType shadow_type,
1059 g_return_if_fail (GTK_IS_STYLE (style));
1060 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
1062 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1067 * @style: a #GtkStyle
1068 * @window: a #GdkWindow
1069 * @state_type: a state
1072 * @string: the string to draw
1074 * Draws a text string on @window with the given parameters.
1076 * This function is deprecated, use gtk_paint_layout() instead.
1079 gtk_draw_string (GtkStyle *style,
1081 GtkStateType state_type,
1084 const gchar *string)
1086 g_return_if_fail (GTK_IS_STYLE (style));
1087 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
1089 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, NULL, NULL, NULL, x, y, string);
1094 * @style: a #GtkStyle
1095 * @window: a #GdkWindow
1096 * @state_type: a state
1097 * @shadow_type: the type of shadow to draw
1098 * @x: x origin of the box
1099 * @y: y origin of the box
1100 * @width: the width of the box
1101 * @height: the height of the box
1103 * Draws a box on @window with the given parameters.
1105 * This function is deprecated, use gtk_paint_box() instead.
1108 gtk_draw_box (GtkStyle *style,
1110 GtkStateType state_type,
1111 GtkShadowType shadow_type,
1117 g_return_if_fail (GTK_IS_STYLE (style));
1118 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
1120 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1124 * gtk_draw_flat_box:
1125 * @style: a #GtkStyle
1126 * @window: a #GdkWindow
1127 * @state_type: a state
1128 * @shadow_type: the type of shadow to draw
1129 * @x: x origin of the box
1130 * @y: y origin of the box
1131 * @width: the width of the box
1132 * @height: the height of the box
1134 * Draws a flat box on @window with the given parameters.
1136 * This function is deprecated, use gtk_paint_flat_box() instead.
1139 gtk_draw_flat_box (GtkStyle *style,
1141 GtkStateType state_type,
1142 GtkShadowType shadow_type,
1148 g_return_if_fail (GTK_IS_STYLE (style));
1149 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
1151 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1156 * @style: a #GtkStyle
1157 * @window: a #GdkWindow
1158 * @state_type: a state
1159 * @shadow_type: the type of shadow to draw
1160 * @x: x origin of the rectangle to draw the check in
1161 * @y: y origin of the rectangle to draw the check in
1162 * @width: the width of the rectangle to draw the check in
1163 * @height: the height of the rectangle to draw the check in
1165 * Draws a check button indicator in the given rectangle on @window with
1166 * the given parameters.
1168 * This function is deprecated, use gtk_paint_check() instead.
1171 gtk_draw_check (GtkStyle *style,
1173 GtkStateType state_type,
1174 GtkShadowType shadow_type,
1180 g_return_if_fail (GTK_IS_STYLE (style));
1181 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
1183 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1188 * @style: a #GtkStyle
1189 * @window: a #GdkWindow
1190 * @state_type: a state
1191 * @shadow_type: the type of shadow to draw
1192 * @x: x origin of the rectangle to draw the option in
1193 * @y: y origin of the rectangle to draw the option in
1194 * @width: the width of the rectangle to draw the option in
1195 * @height: the height of the rectangle to draw the option in
1197 * Draws a radio button indicator in the given rectangle on @window with
1198 * the given parameters.
1200 * This function is deprecated, use gtk_paint_option() instead.
1203 gtk_draw_option (GtkStyle *style,
1205 GtkStateType state_type,
1206 GtkShadowType shadow_type,
1212 g_return_if_fail (GTK_IS_STYLE (style));
1213 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
1215 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1220 * @style: a #GtkStyle
1221 * @window: a #GdkWindow
1222 * @state_type: a state
1223 * @shadow_type: the type of shadow to draw
1224 * @x: x origin of the rectangle to draw the tab in
1225 * @y: y origin of the rectangle to draw the tab in
1226 * @width: the width of the rectangle to draw the tab in
1227 * @height: the height of the rectangle to draw the tab in
1229 * Draws an option menu tab (i.e. the up and down pointing arrows)
1230 * in the given rectangle on @window using the given parameters.
1232 * This function is deprecated, use gtk_paint_tab() instead.
1235 gtk_draw_tab (GtkStyle *style,
1237 GtkStateType state_type,
1238 GtkShadowType shadow_type,
1244 g_return_if_fail (GTK_IS_STYLE (style));
1245 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
1247 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1251 gtk_draw_shadow_gap (GtkStyle *style,
1253 GtkStateType state_type,
1254 GtkShadowType shadow_type,
1259 GtkPositionType gap_side,
1263 g_return_if_fail (GTK_IS_STYLE (style));
1264 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
1266 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);
1270 gtk_draw_box_gap (GtkStyle *style,
1272 GtkStateType state_type,
1273 GtkShadowType shadow_type,
1278 GtkPositionType gap_side,
1282 g_return_if_fail (GTK_IS_STYLE (style));
1283 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
1285 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);
1289 gtk_draw_extension (GtkStyle *style,
1291 GtkStateType state_type,
1292 GtkShadowType shadow_type,
1297 GtkPositionType gap_side)
1299 g_return_if_fail (GTK_IS_STYLE (style));
1300 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
1302 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side);
1307 * @style: a #GtkStyle
1308 * @window: a #GdkWindow
1309 * @x: the x origin of the rectangle around which to draw a focus indicator
1310 * @y: the y origin of the rectangle around which to draw a focus indicator
1311 * @width: the width of the rectangle around which to draw a focus indicator
1312 * @height: the height of the rectangle around which to draw a focus indicator
1314 * Draws a focus indicator around the given rectangle on @window using the
1317 * This function is deprecated, use gtk_paint_focus() instead.
1320 gtk_draw_focus (GtkStyle *style,
1327 g_return_if_fail (GTK_IS_STYLE (style));
1328 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
1330 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, GTK_STATE_NORMAL, NULL, NULL, NULL, x, y, width, height);
1334 gtk_draw_slider (GtkStyle *style,
1336 GtkStateType state_type,
1337 GtkShadowType shadow_type,
1342 GtkOrientation orientation)
1344 g_return_if_fail (GTK_IS_STYLE (style));
1345 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
1347 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
1351 gtk_draw_handle (GtkStyle *style,
1353 GtkStateType state_type,
1354 GtkShadowType shadow_type,
1359 GtkOrientation orientation)
1361 g_return_if_fail (GTK_IS_STYLE (style));
1362 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
1364 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
1368 gtk_draw_expander (GtkStyle *style,
1370 GtkStateType state_type,
1373 GtkExpanderStyle expander_style)
1375 g_return_if_fail (GTK_IS_STYLE (style));
1376 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
1378 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type,
1380 x, y, expander_style);
1384 gtk_draw_layout (GtkStyle *style,
1386 GtkStateType state_type,
1390 PangoLayout *layout)
1392 g_return_if_fail (GTK_IS_STYLE (style));
1393 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
1395 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text,
1401 * gtk_draw_resize_grip:
1402 * @style: a #GtkStyle
1403 * @window: a #GdkWindow
1404 * @state_type: a state
1405 * @edge: the edge in which to draw the resize grip, currently only
1406 * %GTK_WINDOW_EDGE_SOUTH_EAST is implemented
1407 * @x: the x origin of the rectangle in which to draw the resize grip
1408 * @y: the y origin of the rectangle in which to draw the resize grip
1409 * @width: the width of the rectangle in which to draw the resize grip
1410 * @height: the height of the rectangle in which to draw the resize grip
1412 * Draws a resize grip in the given rectangle on @window using the given
1415 * This function is deprecated, use gtk_paint_resize_grip() instead.
1418 gtk_draw_resize_grip (GtkStyle *style,
1420 GtkStateType state_type,
1427 g_return_if_fail (GTK_IS_STYLE (style));
1428 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
1430 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
1433 x, y, width, height);
1438 * gtk_style_set_background:
1439 * @style: a #GtkStyle
1440 * @window: a #GdkWindow
1441 * @state_type: a state
1443 * Sets the background of @window to the background color or pixmap
1444 * specified by @style for the given state.
1447 gtk_style_set_background (GtkStyle *style,
1449 GtkStateType state_type)
1451 g_return_if_fail (GTK_IS_STYLE (style));
1452 g_return_if_fail (window != NULL);
1454 GTK_STYLE_GET_CLASS (style)->set_background (style, window, state_type);
1457 /* Default functions */
1459 gtk_style_real_clone (GtkStyle *style)
1461 return GTK_STYLE (g_object_new (G_OBJECT_TYPE (style), NULL));
1465 gtk_style_real_copy (GtkStyle *style,
1470 for (i = 0; i < 5; i++)
1472 style->fg[i] = src->fg[i];
1473 style->bg[i] = src->bg[i];
1474 style->text[i] = src->text[i];
1475 style->base[i] = src->base[i];
1477 style->bg_pixmap[i] = src->bg_pixmap[i];
1480 if (style->private_font)
1481 gdk_font_unref (style->private_font);
1482 style->private_font = src->private_font;
1483 if (style->private_font)
1484 gdk_font_ref (style->private_font);
1486 if (style->font_desc)
1487 pango_font_description_free (style->font_desc);
1489 style->font_desc = pango_font_description_copy (src->font_desc);
1491 style->font_desc = NULL;
1493 style->xthickness = src->xthickness;
1494 style->ythickness = src->ythickness;
1496 if (style->rc_style)
1497 gtk_rc_style_unref (style->rc_style);
1498 style->rc_style = src->rc_style;
1500 gtk_rc_style_ref (src->rc_style);
1502 /* don't copy, just clear cache */
1503 clear_property_cache (style);
1507 gtk_style_real_init_from_rc (GtkStyle *style,
1508 GtkRcStyle *rc_style)
1512 /* cache _should_ be still empty */
1513 clear_property_cache (style);
1515 if (rc_style->font_desc)
1516 pango_font_description_merge (style->font_desc, rc_style->font_desc, TRUE);
1518 for (i = 0; i < 5; i++)
1520 if (rc_style->color_flags[i] & GTK_RC_FG)
1521 style->fg[i] = rc_style->fg[i];
1522 if (rc_style->color_flags[i] & GTK_RC_BG)
1523 style->bg[i] = rc_style->bg[i];
1524 if (rc_style->color_flags[i] & GTK_RC_TEXT)
1525 style->text[i] = rc_style->text[i];
1526 if (rc_style->color_flags[i] & GTK_RC_BASE)
1527 style->base[i] = rc_style->base[i];
1530 if (rc_style->xthickness >= 0)
1531 style->xthickness = rc_style->xthickness;
1532 if (rc_style->ythickness >= 0)
1533 style->ythickness = rc_style->ythickness;
1535 if (rc_style->icon_factories)
1539 style->icon_factories = g_slist_copy (rc_style->icon_factories);
1541 iter = style->icon_factories;
1542 while (iter != NULL)
1544 g_object_ref (G_OBJECT (iter->data));
1546 iter = g_slist_next (iter);
1552 style_property_values_cmp (gconstpointer bsearch_node1,
1553 gconstpointer bsearch_node2)
1555 const PropertyValue *val1 = bsearch_node1;
1556 const PropertyValue *val2 = bsearch_node2;
1558 if (val1->widget_type == val2->widget_type)
1559 return val1->pspec < val2->pspec ? -1 : val1->pspec == val2->pspec ? 0 : 1;
1561 return val1->widget_type < val2->widget_type ? -1 : 1;
1565 _gtk_style_peek_property_value (GtkStyle *style,
1568 GtkRcPropertyParser parser)
1570 PropertyValue *pcache, key = { 0, NULL, { 0, } };
1571 const GtkRcProperty *rcprop = NULL;
1574 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1575 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), NULL);
1576 g_return_val_if_fail (g_type_is_a (pspec->owner_type, GTK_TYPE_WIDGET), NULL);
1577 g_return_val_if_fail (g_type_is_a (widget_type, pspec->owner_type), NULL);
1579 key.widget_type = widget_type;
1582 /* need value cache array */
1583 if (!style->property_cache)
1584 style->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
1587 pcache = bsearch (&key,
1588 style->property_cache->data, style->property_cache->len,
1589 sizeof (PropertyValue), style_property_values_cmp);
1591 return &pcache->value;
1595 while (i < style->property_cache->len &&
1596 style_property_values_cmp (&key, &g_array_index (style->property_cache, PropertyValue, i)) >= 0)
1599 g_array_insert_val (style->property_cache, i, key);
1600 pcache = &g_array_index (style->property_cache, PropertyValue, i);
1602 /* cache miss, initialize value type, then set contents */
1603 g_param_spec_ref (pcache->pspec);
1604 g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1606 /* value provided by rc style? */
1607 if (style->rc_style)
1609 GQuark prop_quark = g_quark_from_string (pspec->name);
1613 rcprop = _gtk_rc_style_lookup_rc_property (style->rc_style,
1614 g_type_qname (widget_type),
1618 widget_type = g_type_parent (widget_type);
1620 while (g_type_is_a (widget_type, pspec->owner_type));
1623 /* when supplied by rc style, we need to convert */
1624 if (rcprop && !_gtk_settings_parse_convert (parser, &rcprop->value,
1625 pspec, &pcache->value))
1627 gchar *contents = g_strdup_value_contents (&rcprop->value);
1629 g_message ("%s: failed to retrieve property `%s::%s' of type `%s' from rc file value \"%s\" of type `%s'",
1631 g_type_name (pspec->owner_type), pspec->name,
1632 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1634 G_VALUE_TYPE_NAME (&rcprop->value));
1636 rcprop = NULL; /* needs default */
1639 /* not supplied by rc style (or conversion failed), revert to default */
1641 g_param_value_set_default (pspec, &pcache->value);
1643 return &pcache->value;
1647 load_bg_image (GdkColormap *colormap,
1649 const gchar *filename)
1651 if (strcmp (filename, "<parent>") == 0)
1652 return (GdkPixmap*) GDK_PARENT_RELATIVE;
1655 return gdk_pixmap_colormap_create_from_xpm (NULL, colormap, NULL,
1662 gtk_style_real_realize (GtkStyle *style)
1664 GdkGCValues gc_values;
1665 GdkGCValuesMask gc_values_mask;
1669 for (i = 0; i < 5; i++)
1671 gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT);
1672 gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT);
1674 style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
1675 style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
1676 style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
1678 style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
1679 style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
1680 style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;
1683 gdk_color_black (style->colormap, &style->black);
1684 gdk_color_white (style->colormap, &style->white);
1686 gc_values_mask = GDK_GC_FOREGROUND;
1688 gc_values.foreground = style->black;
1689 style->black_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1691 gc_values.foreground = style->white;
1692 style->white_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1694 for (i = 0; i < 5; i++)
1696 if (style->rc_style && style->rc_style->bg_pixmap_name[i])
1697 style->bg_pixmap[i] = load_bg_image (style->colormap,
1699 style->rc_style->bg_pixmap_name[i]);
1701 if (!gdk_color_alloc (style->colormap, &style->fg[i]))
1702 g_warning ("unable to allocate color: ( %d %d %d )",
1703 style->fg[i].red, style->fg[i].green, style->fg[i].blue);
1704 if (!gdk_color_alloc (style->colormap, &style->bg[i]))
1705 g_warning ("unable to allocate color: ( %d %d %d )",
1706 style->bg[i].red, style->bg[i].green, style->bg[i].blue);
1707 if (!gdk_color_alloc (style->colormap, &style->light[i]))
1708 g_warning ("unable to allocate color: ( %d %d %d )",
1709 style->light[i].red, style->light[i].green, style->light[i].blue);
1710 if (!gdk_color_alloc (style->colormap, &style->dark[i]))
1711 g_warning ("unable to allocate color: ( %d %d %d )",
1712 style->dark[i].red, style->dark[i].green, style->dark[i].blue);
1713 if (!gdk_color_alloc (style->colormap, &style->mid[i]))
1714 g_warning ("unable to allocate color: ( %d %d %d )",
1715 style->mid[i].red, style->mid[i].green, style->mid[i].blue);
1716 if (!gdk_color_alloc (style->colormap, &style->text[i]))
1717 g_warning ("unable to allocate color: ( %d %d %d )",
1718 style->text[i].red, style->text[i].green, style->text[i].blue);
1719 if (!gdk_color_alloc (style->colormap, &style->base[i]))
1720 g_warning ("unable to allocate color: ( %d %d %d )",
1721 style->base[i].red, style->base[i].green, style->base[i].blue);
1722 if (!gdk_color_alloc (style->colormap, &style->text_aa[i]))
1723 g_warning ("unable to allocate color: ( %d %d %d )",
1724 style->text_aa[i].red, style->text_aa[i].green, style->text_aa[i].blue);
1726 gc_values.foreground = style->fg[i];
1727 style->fg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1729 gc_values.foreground = style->bg[i];
1730 style->bg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1732 gc_values.foreground = style->light[i];
1733 style->light_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1735 gc_values.foreground = style->dark[i];
1736 style->dark_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1738 gc_values.foreground = style->mid[i];
1739 style->mid_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1741 gc_values.foreground = style->text[i];
1742 style->text_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1744 gc_values.foreground = style->base[i];
1745 style->base_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1747 gc_values.foreground = style->text_aa[i];
1748 style->text_aa_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
1753 gtk_style_real_unrealize (GtkStyle *style)
1757 gtk_gc_release (style->black_gc);
1758 gtk_gc_release (style->white_gc);
1760 for (i = 0; i < 5; i++)
1762 gtk_gc_release (style->fg_gc[i]);
1763 gtk_gc_release (style->bg_gc[i]);
1764 gtk_gc_release (style->light_gc[i]);
1765 gtk_gc_release (style->dark_gc[i]);
1766 gtk_gc_release (style->mid_gc[i]);
1767 gtk_gc_release (style->text_gc[i]);
1768 gtk_gc_release (style->base_gc[i]);
1769 gtk_gc_release (style->text_aa_gc[i]);
1771 if (style->bg_pixmap[i] && style->bg_pixmap[i] != (GdkPixmap*) GDK_PARENT_RELATIVE)
1772 gdk_pixmap_unref (style->bg_pixmap[i]);
1775 gdk_colormap_free_colors (style->colormap, style->fg, 5);
1776 gdk_colormap_free_colors (style->colormap, style->bg, 5);
1777 gdk_colormap_free_colors (style->colormap, style->light, 5);
1778 gdk_colormap_free_colors (style->colormap, style->dark, 5);
1779 gdk_colormap_free_colors (style->colormap, style->mid, 5);
1780 gdk_colormap_free_colors (style->colormap, style->text, 5);
1781 gdk_colormap_free_colors (style->colormap, style->base, 5);
1782 gdk_colormap_free_colors (style->colormap, style->text_aa, 5);
1784 style_unrealize_cursor_gcs (style);
1788 gtk_style_real_set_background (GtkStyle *style,
1790 GtkStateType state_type)
1793 gint parent_relative;
1795 if (style->bg_pixmap[state_type])
1797 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1800 parent_relative = TRUE;
1804 pixmap = style->bg_pixmap[state_type];
1805 parent_relative = FALSE;
1808 gdk_window_set_back_pixmap (window, pixmap, parent_relative);
1811 gdk_window_set_background (window, &style->bg[state_type]);
1815 * gtk_style_render_icon:
1816 * @style: a #GtkStyle
1817 * @source: the #GtkIconSource specifying the icon to render
1818 * @direction: a text direction
1820 * @size: the size to render the icon at. A size of (GtkIconSize)-1
1821 * means render at the size of the source and don't scale.
1822 * @widget: the widget
1823 * @detail: a style detail
1824 * @returns: a newly-created #GdkPixbuf containing the rendered icon
1826 * Renders the icon specified by @source at the given @size
1827 * according to the given parameters and returns the result in a
1831 gtk_style_render_icon (GtkStyle *style,
1832 const GtkIconSource *source,
1833 GtkTextDirection direction,
1837 const gchar *detail)
1841 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
1842 g_return_val_if_fail (GTK_STYLE_GET_CLASS (style)->render_icon != NULL, NULL);
1844 pixbuf = GTK_STYLE_GET_CLASS (style)->render_icon (style, source, direction, state,
1845 size, widget, detail);
1847 g_return_val_if_fail (pixbuf != NULL, NULL);
1852 /* Default functions */
1854 gtk_style_apply_default_background (GtkStyle *style,
1857 GtkStateType state_type,
1864 GdkRectangle new_rect, old_rect;
1870 old_rect.width = width;
1871 old_rect.height = height;
1873 if (!gdk_rectangle_intersect (area, &old_rect, &new_rect))
1880 new_rect.width = width;
1881 new_rect.height = height;
1884 if (!style->bg_pixmap[state_type] ||
1885 GDK_IS_PIXMAP (window) ||
1886 (!set_bg && style->bg_pixmap[state_type] != (GdkPixmap*) GDK_PARENT_RELATIVE))
1888 GdkGC *gc = style->bg_gc[state_type];
1890 if (style->bg_pixmap[state_type])
1892 gdk_gc_set_fill (gc, GDK_TILED);
1893 gdk_gc_set_tile (gc, style->bg_pixmap[state_type]);
1896 gdk_draw_rectangle (window, gc, TRUE,
1897 new_rect.x, new_rect.y, new_rect.width, new_rect.height);
1898 if (style->bg_pixmap[state_type])
1899 gdk_gc_set_fill (gc, GDK_SOLID);
1905 if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1906 gdk_window_set_back_pixmap (window, NULL, TRUE);
1908 gdk_window_set_back_pixmap (window, style->bg_pixmap[state_type], FALSE);
1911 gdk_window_clear_area (window,
1912 new_rect.x, new_rect.y,
1913 new_rect.width, new_rect.height);
1918 scale_or_ref (GdkPixbuf *src,
1922 if (width == gdk_pixbuf_get_width (src) &&
1923 height == gdk_pixbuf_get_height (src))
1925 gdk_pixbuf_ref (src);
1930 return gdk_pixbuf_scale_simple (src,
1932 GDK_INTERP_BILINEAR);
1937 gtk_default_render_icon (GtkStyle *style,
1938 const GtkIconSource *source,
1939 GtkTextDirection direction,
1943 const gchar *detail)
1949 GdkPixbuf *base_pixbuf;
1951 /* Oddly, style can be NULL in this function, because
1952 * GtkIconSet can be used without a style and if so
1953 * it uses this function.
1956 base_pixbuf = gtk_icon_source_get_pixbuf (source);
1958 g_return_val_if_fail (base_pixbuf != NULL, NULL);
1960 if (size != (GtkIconSize) -1 && !gtk_icon_size_lookup (size, &width, &height))
1962 g_warning (G_STRLOC ": invalid icon size `%d'", size);
1966 /* If the size was wildcarded, and we're allowed to scale, then scale; otherwise,
1969 if (size != (GtkIconSize)-1 && gtk_icon_source_get_size_wildcarded (source))
1970 scaled = scale_or_ref (base_pixbuf, width, height);
1972 scaled = GDK_PIXBUF (g_object_ref (G_OBJECT (base_pixbuf)));
1974 /* If the state was wildcarded, then generate a state. */
1975 if (gtk_icon_source_get_state_wildcarded (source))
1977 if (state == GTK_STATE_INSENSITIVE)
1979 stated = gdk_pixbuf_copy (scaled);
1981 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
1984 gdk_pixbuf_unref (scaled);
1986 else if (state == GTK_STATE_PRELIGHT)
1988 stated = gdk_pixbuf_copy (scaled);
1990 gdk_pixbuf_saturate_and_pixelate (scaled, stated,
1993 gdk_pixbuf_unref (scaled);
2007 sanitize_size (GdkWindow *window,
2011 if ((*width == -1) && (*height == -1))
2012 gdk_window_get_size (window, width, height);
2013 else if (*width == -1)
2014 gdk_window_get_size (window, width, NULL);
2015 else if (*height == -1)
2016 gdk_window_get_size (window, NULL, height);
2020 get_indicator_for_screen (GdkDrawable *drawable,
2024 GdkScreen *screen = gdk_drawable_get_screen (drawable);
2028 tmp_list = indicator_parts[part].bmap_list;
2031 bitmap = tmp_list->data;
2033 if (gdk_drawable_get_screen (bitmap) == screen)
2036 tmp_list = tmp_list->next;
2039 bitmap = gdk_bitmap_create_from_data (drawable,
2040 indicator_parts[part].bits,
2041 INDICATOR_PART_SIZE, INDICATOR_PART_SIZE);
2042 indicator_parts[part].bmap_list = g_list_prepend (indicator_parts[part].bmap_list, bitmap);
2048 draw_part (GdkDrawable *drawable,
2056 gdk_gc_set_clip_rectangle (gc, area);
2058 gdk_gc_set_ts_origin (gc, x, y);
2059 gdk_gc_set_stipple (gc, get_indicator_for_screen (drawable, part));
2060 gdk_gc_set_fill (gc, GDK_STIPPLED);
2062 gdk_draw_rectangle (drawable, gc, TRUE, x, y, INDICATOR_PART_SIZE, INDICATOR_PART_SIZE);
2064 gdk_gc_set_fill (gc, GDK_SOLID);
2067 gdk_gc_set_clip_rectangle (gc, NULL);
2071 gtk_default_draw_hline (GtkStyle *style,
2073 GtkStateType state_type,
2076 const gchar *detail,
2081 gint thickness_light;
2082 gint thickness_dark;
2085 g_return_if_fail (GTK_IS_STYLE (style));
2086 g_return_if_fail (window != NULL);
2088 thickness_light = style->ythickness / 2;
2089 thickness_dark = style->ythickness - thickness_light;
2093 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
2094 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
2097 if (detail && !strcmp (detail, "label"))
2099 if (state_type == GTK_STATE_INSENSITIVE)
2100 gdk_draw_line (window, style->white_gc, x1 + 1, y + 1, x2 + 1, y + 1);
2101 gdk_draw_line (window, style->fg_gc[state_type], x1, y, x2, y);
2105 for (i = 0; i < thickness_dark; i++)
2107 gdk_draw_line (window, style->light_gc[state_type], x2 - i - 1, y + i, x2, y + i);
2108 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x2 - i - 1, y + i);
2111 y += thickness_dark;
2112 for (i = 0; i < thickness_light; i++)
2114 gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x1 + thickness_light - i - 1, y + i);
2115 gdk_draw_line (window, style->light_gc[state_type], x1 + thickness_light - i - 1, y + i, x2, y + i);
2121 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
2122 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
2128 gtk_default_draw_vline (GtkStyle *style,
2130 GtkStateType state_type,
2133 const gchar *detail,
2138 gint thickness_light;
2139 gint thickness_dark;
2142 g_return_if_fail (GTK_IS_STYLE (style));
2143 g_return_if_fail (window != NULL);
2145 thickness_light = style->xthickness / 2;
2146 thickness_dark = style->xthickness - thickness_light;
2150 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
2151 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
2153 for (i = 0; i < thickness_dark; i++)
2155 gdk_draw_line (window, style->light_gc[state_type], x + i, y2 - i - 1, x + i, y2);
2156 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y2 - i - 1);
2159 x += thickness_dark;
2160 for (i = 0; i < thickness_light; i++)
2162 gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y1 + thickness_light - i);
2163 gdk_draw_line (window, style->light_gc[state_type], x + i, y1 + thickness_light - i, x + i, y2);
2167 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
2168 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
2174 draw_thin_shadow (GtkStyle *style,
2185 sanitize_size (window, &width, &height);
2187 gc1 = style->light_gc[state];
2188 gc2 = style->dark_gc[state];
2192 gdk_gc_set_clip_rectangle (gc1, area);
2193 gdk_gc_set_clip_rectangle (gc2, area);
2196 gdk_draw_line (window, gc1,
2197 x, y + height - 1, x + width - 1, y + height - 1);
2198 gdk_draw_line (window, gc1,
2199 x + width - 1, y, x + width - 1, y + height - 1);
2201 gdk_draw_line (window, gc2,
2202 x, y, x + width - 1, y);
2203 gdk_draw_line (window, gc2,
2204 x, y, x, y + height - 1);
2208 gdk_gc_set_clip_rectangle (gc1, NULL);
2209 gdk_gc_set_clip_rectangle (gc2, NULL);
2214 draw_spin_entry_shadow (GtkStyle *style,
2223 gint window_width, window_height;
2224 gboolean focus_inset;
2226 gdk_window_get_size (window, &window_width, &window_height);
2229 width = window_width;
2231 height = window_height;
2233 focus_inset = (width < window_width && height < window_height);
2237 gdk_gc_set_clip_rectangle (style->light_gc[state], area);
2238 gdk_gc_set_clip_rectangle (style->dark_gc[state], area);
2239 gdk_gc_set_clip_rectangle (style->black_gc, area);
2240 gdk_gc_set_clip_rectangle (style->bg_gc[state], area);
2241 gdk_gc_set_clip_rectangle (style->base_gc[state], area);
2244 gdk_draw_line (window, style->light_gc[state],
2245 x, y + height - 1, x + width - 1, y + height - 1);
2247 gdk_draw_line (window,
2248 style->base_gc[state],
2249 x + width - 1, y + 1, x + width - 1, y + height - 3);
2253 gdk_draw_line (window, style->bg_gc[state],
2254 x + 1, y + height - 2, x + width - 1, y + height - 2);
2255 gdk_draw_line (window,
2256 style->base_gc[state],
2257 x + width - 2, y + 1, x + width - 2, y + height - 3);
2259 gdk_draw_line (window, style->black_gc,
2260 x + 1, y + 1, x + width - 1, y + 1);
2261 gdk_draw_line (window, style->black_gc,
2262 x + 1, y + 1, x + 1, y + height - 2);
2265 gdk_draw_line (window, style->dark_gc[state],
2266 x, y, x + width - 1, y);
2267 gdk_draw_line (window, style->dark_gc[state],
2268 x, y, x, y + height - 1);
2272 gdk_gc_set_clip_rectangle (style->light_gc[state], NULL);
2273 gdk_gc_set_clip_rectangle (style->dark_gc[state], NULL);
2274 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2275 gdk_gc_set_clip_rectangle (style->bg_gc[state], NULL);
2276 gdk_gc_set_clip_rectangle (style->base_gc[state], NULL);
2281 draw_spinbutton_shadow (GtkStyle *style,
2284 GtkTextDirection direction,
2291 sanitize_size (window, &width, &height);
2295 gdk_gc_set_clip_rectangle (style->black_gc, area);
2296 gdk_gc_set_clip_rectangle (style->bg_gc[state], area);
2297 gdk_gc_set_clip_rectangle (style->dark_gc[state], area);
2298 gdk_gc_set_clip_rectangle (style->light_gc[state], area);
2301 if (direction == GTK_TEXT_DIR_LTR)
2303 gdk_draw_line (window, style->dark_gc[state],
2304 x, y, x + width - 1, y);
2305 gdk_draw_line (window, style->black_gc,
2306 x, y + 1, x + width - 2, y + 1);
2307 gdk_draw_line (window, style->black_gc,
2308 x + width - 2, y + 2, x + width - 2, y + height - 3);
2309 gdk_draw_line (window, style->light_gc[state],
2310 x + width - 1, y + 1, x + width - 1, y + height - 2);
2311 gdk_draw_line (window, style->light_gc[state],
2312 x, y + height - 1, x + width - 1, y + height - 1);
2313 gdk_draw_line (window, style->bg_gc[state],
2314 x, y + height - 2, x + width - 2, y + height - 2);
2315 gdk_draw_line (window, style->black_gc,
2316 x, y + 2, x, y + height - 3);
2320 gdk_draw_line (window, style->dark_gc[state],
2321 x, y, x + width - 1, y);
2322 gdk_draw_line (window, style->dark_gc[state],
2323 x, y + 1, x, y + height - 1);
2324 gdk_draw_line (window, style->black_gc,
2325 x + 1, y + 1, x + width - 1, y + 1);
2326 gdk_draw_line (window, style->black_gc,
2327 x + 1, y + 2, x + 1, y + height - 2);
2328 gdk_draw_line (window, style->black_gc,
2329 x + width - 1, y + 2, x + width - 1, y + height - 3);
2330 gdk_draw_line (window, style->light_gc[state],
2331 x + 1, y + height - 1, x + width - 1, y + height - 1);
2332 gdk_draw_line (window, style->bg_gc[state],
2333 x + 2, y + height - 2, x + width - 1, y + height - 2);
2338 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2339 gdk_gc_set_clip_rectangle (style->bg_gc[state], NULL);
2340 gdk_gc_set_clip_rectangle (style->dark_gc[state], NULL);
2341 gdk_gc_set_clip_rectangle (style->light_gc[state], NULL);
2346 gtk_default_draw_shadow (GtkStyle *style,
2348 GtkStateType state_type,
2349 GtkShadowType shadow_type,
2352 const gchar *detail,
2360 gint thickness_light;
2361 gint thickness_dark;
2364 g_return_if_fail (GTK_IS_STYLE (style));
2365 g_return_if_fail (window != NULL);
2367 if (shadow_type == GTK_SHADOW_IN)
2369 if (detail && (strcmp (detail, "buttondefault") == 0))
2371 sanitize_size (window, &width, &height);
2373 gdk_draw_rectangle (window, style->black_gc, FALSE,
2374 x, y, width - 1, height - 1);
2378 if (detail && strcmp (detail, "trough") == 0)
2380 draw_thin_shadow (style, window, state_type, area,
2381 x, y, width, height);
2384 if (widget && GTK_IS_SPIN_BUTTON (widget) &&
2385 detail && strcmp (detail, "spinbutton") == 0)
2387 draw_spinbutton_shadow (style, window, state_type,
2388 gtk_widget_get_direction (widget), area, x, y, width, height);
2394 sanitize_size (window, &width, &height);
2396 switch (shadow_type)
2398 case GTK_SHADOW_NONE:
2401 case GTK_SHADOW_ETCHED_IN:
2402 gc1 = style->light_gc[state_type];
2403 gc2 = style->dark_gc[state_type];
2405 case GTK_SHADOW_OUT:
2406 case GTK_SHADOW_ETCHED_OUT:
2407 gc1 = style->dark_gc[state_type];
2408 gc2 = style->light_gc[state_type];
2414 gdk_gc_set_clip_rectangle (gc1, area);
2415 gdk_gc_set_clip_rectangle (gc2, area);
2416 if (shadow_type == GTK_SHADOW_IN ||
2417 shadow_type == GTK_SHADOW_OUT)
2419 gdk_gc_set_clip_rectangle (style->black_gc, area);
2420 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2424 switch (shadow_type)
2426 case GTK_SHADOW_NONE:
2430 /* Light around right and bottom edge */
2432 if (style->ythickness > 0)
2433 gdk_draw_line (window, gc1,
2434 x, y + height - 1, x + width - 1, y + height - 1);
2435 if (style->xthickness > 0)
2436 gdk_draw_line (window, gc1,
2437 x + width - 1, y, x + width - 1, y + height - 1);
2439 if (style->ythickness > 1)
2440 gdk_draw_line (window, style->bg_gc[state_type],
2441 x + 1, y + height - 2, x + width - 2, y + height - 2);
2442 if (style->xthickness > 1)
2443 gdk_draw_line (window, style->bg_gc[state_type],
2444 x + width - 2, y + 1, x + width - 2, y + height - 2);
2446 /* Dark around left and top */
2448 if (style->ythickness > 1)
2449 gdk_draw_line (window, style->black_gc,
2450 x + 1, y + 1, x + width - 2, y + 1);
2451 if (style->xthickness > 1)
2452 gdk_draw_line (window, style->black_gc,
2453 x + 1, y + 1, x + 1, y + height - 2);
2455 if (style->ythickness > 0)
2456 gdk_draw_line (window, gc2,
2457 x, y, x + width - 1, y);
2458 if (style->xthickness > 0)
2459 gdk_draw_line (window, gc2,
2460 x, y, x, y + height - 1);
2463 case GTK_SHADOW_OUT:
2464 /* Dark around right and bottom edge */
2466 if (style->ythickness > 0)
2468 if (style->ythickness > 1)
2470 gdk_draw_line (window, gc1,
2471 x + 1, y + height - 2, x + width - 2, y + height - 2);
2472 gdk_draw_line (window, style->black_gc,
2473 x, y + height - 1, x + width - 1, y + height - 1);
2477 gdk_draw_line (window, gc1,
2478 x + 1, y + height - 1, x + width - 1, y + height - 1);
2482 if (style->xthickness > 0)
2484 if (style->xthickness > 1)
2486 gdk_draw_line (window, gc1,
2487 x + width - 2, y + 1, x + width - 2, y + height - 2);
2489 gdk_draw_line (window, style->black_gc,
2490 x + width - 1, y, x + width - 1, y + height - 1);
2494 gdk_draw_line (window, gc1,
2495 x + width - 1, y + 1, x + width - 1, y + height - 1);
2499 /* Light around top and left */
2501 if (style->ythickness > 0)
2502 gdk_draw_line (window, gc2,
2503 x, y, x + width - 1, y);
2504 if (style->xthickness > 0)
2505 gdk_draw_line (window, gc2,
2506 x, y, x, y + height - 1);
2508 if (style->ythickness > 1)
2509 gdk_draw_line (window, style->bg_gc[state_type],
2510 x + 1, y + 1, x + width - 2, y + 1);
2511 if (style->xthickness > 1)
2512 gdk_draw_line (window, style->bg_gc[state_type],
2513 x + 1, y + 1, x + 1, y + height - 2);
2516 case GTK_SHADOW_ETCHED_IN:
2517 case GTK_SHADOW_ETCHED_OUT:
2518 if (style->xthickness > 0)
2520 if (style->xthickness > 1)
2522 thickness_light = 1;
2525 for (i = 0; i < thickness_dark; i++)
2527 gdk_draw_line (window, gc1,
2531 y + height - i - 1);
2532 gdk_draw_line (window, gc2,
2536 y + height - i - 2);
2539 for (i = 0; i < thickness_light; i++)
2541 gdk_draw_line (window, gc1,
2542 x + thickness_dark + i,
2543 y + thickness_dark + i,
2544 x + thickness_dark + i,
2545 y + height - thickness_dark - i - 1);
2546 gdk_draw_line (window, gc2,
2547 x + width - thickness_light - i - 1,
2548 y + thickness_dark + i,
2549 x + width - thickness_light - i - 1,
2550 y + height - thickness_light - 1);
2555 gdk_draw_line (window,
2556 style->dark_gc[state_type],
2557 x, y, x, y + height);
2558 gdk_draw_line (window,
2559 style->dark_gc[state_type],
2560 x + width, y, x + width, y + height);
2564 if (style->ythickness > 0)
2566 if (style->ythickness > 1)
2568 thickness_light = 1;
2571 for (i = 0; i < thickness_dark; i++)
2573 gdk_draw_line (window, gc1,
2577 y + height - i - 1);
2579 gdk_draw_line (window, gc2,
2586 for (i = 0; i < thickness_light; i++)
2588 gdk_draw_line (window, gc1,
2589 x + thickness_dark + i,
2590 y + thickness_dark + i,
2591 x + width - thickness_dark - i - 1,
2592 y + thickness_dark + i);
2594 gdk_draw_line (window, gc2,
2595 x + thickness_dark + i,
2596 y + height - thickness_light - i - 1,
2597 x + width - thickness_light - 1,
2598 y + height - thickness_light - i - 1);
2603 gdk_draw_line (window,
2604 style->dark_gc[state_type],
2605 x, y, x + width, y);
2606 gdk_draw_line (window,
2607 style->dark_gc[state_type],
2608 x, y + height, x + width, y + height);
2615 if (shadow_type == GTK_SHADOW_IN &&
2616 widget && GTK_IS_SPIN_BUTTON (widget) &&
2617 detail && strcmp (detail, "entry") == 0)
2619 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
2621 gdk_draw_line (window,
2622 style->base_gc[state_type],
2623 x + width - 1, y + 2,
2624 x + width - 1, y + height - 3);
2625 gdk_draw_line (window,
2626 style->base_gc[state_type],
2627 x + width - 2, y + 2,
2628 x + width - 2, y + height - 3);
2629 gdk_draw_point (window,
2631 x + width - 1, y + 1);
2632 gdk_draw_point (window,
2633 style->bg_gc[state_type],
2634 x + width - 1, y + height - 2);
2638 gdk_draw_line (window,
2639 style->base_gc[state_type],
2642 gdk_draw_line (window,
2643 style->base_gc[state_type],
2645 x + 1, y + height - 3);
2646 gdk_draw_point (window,
2649 gdk_draw_line (window,
2650 style->bg_gc[state_type],
2652 x + 1, y + height - 2);
2653 gdk_draw_point (window,
2654 style->light_gc[state_type],
2662 gdk_gc_set_clip_rectangle (gc1, NULL);
2663 gdk_gc_set_clip_rectangle (gc2, NULL);
2664 if (shadow_type == GTK_SHADOW_IN ||
2665 shadow_type == GTK_SHADOW_OUT)
2667 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
2668 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
2674 gtk_default_draw_polygon (GtkStyle *style,
2676 GtkStateType state_type,
2677 GtkShadowType shadow_type,
2680 const gchar *detail,
2685 static const gdouble pi_over_4 = G_PI_4;
2686 static const gdouble pi_3_over_4 = G_PI_4 * 3;
2696 g_return_if_fail (GTK_IS_STYLE (style));
2697 g_return_if_fail (window != NULL);
2698 g_return_if_fail (points != NULL);
2700 switch (shadow_type)
2703 gc1 = style->bg_gc[state_type];
2704 gc2 = style->dark_gc[state_type];
2705 gc3 = style->light_gc[state_type];
2706 gc4 = style->black_gc;
2708 case GTK_SHADOW_ETCHED_IN:
2709 gc1 = style->light_gc[state_type];
2710 gc2 = style->dark_gc[state_type];
2711 gc3 = style->dark_gc[state_type];
2712 gc4 = style->light_gc[state_type];
2714 case GTK_SHADOW_OUT:
2715 gc1 = style->dark_gc[state_type];
2716 gc2 = style->light_gc[state_type];
2717 gc3 = style->black_gc;
2718 gc4 = style->bg_gc[state_type];
2720 case GTK_SHADOW_ETCHED_OUT:
2721 gc1 = style->dark_gc[state_type];
2722 gc2 = style->light_gc[state_type];
2723 gc3 = style->light_gc[state_type];
2724 gc4 = style->dark_gc[state_type];
2732 gdk_gc_set_clip_rectangle (gc1, area);
2733 gdk_gc_set_clip_rectangle (gc2, area);
2734 gdk_gc_set_clip_rectangle (gc3, area);
2735 gdk_gc_set_clip_rectangle (gc4, area);
2739 gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, npoints);
2743 for (i = 0; i < npoints; i++)
2745 if ((points[i].x == points[i+1].x) &&
2746 (points[i].y == points[i+1].y))
2752 angle = atan2 (points[i+1].y - points[i].y,
2753 points[i+1].x - points[i].x);
2756 if ((angle > -pi_3_over_4) && (angle < pi_over_4))
2758 if (angle > -pi_over_4)
2769 gdk_draw_line (window, gc1,
2770 points[i].x-xadjust, points[i].y-yadjust,
2771 points[i+1].x-xadjust, points[i+1].y-yadjust);
2772 gdk_draw_line (window, gc3,
2773 points[i].x, points[i].y,
2774 points[i+1].x, points[i+1].y);
2778 if ((angle < -pi_3_over_4) || (angle > pi_3_over_4))
2789 gdk_draw_line (window, gc4,
2790 points[i].x+xadjust, points[i].y+yadjust,
2791 points[i+1].x+xadjust, points[i+1].y+yadjust);
2792 gdk_draw_line (window, gc2,
2793 points[i].x, points[i].y,
2794 points[i+1].x, points[i+1].y);
2800 gdk_gc_set_clip_rectangle (gc1, NULL);
2801 gdk_gc_set_clip_rectangle (gc2, NULL);
2802 gdk_gc_set_clip_rectangle (gc3, NULL);
2803 gdk_gc_set_clip_rectangle (gc4, NULL);
2808 draw_arrow (GdkWindow *window,
2811 GtkArrowType arrow_type,
2820 gdk_gc_set_clip_rectangle (gc, area);
2822 if (arrow_type == GTK_ARROW_DOWN)
2824 for (i = 0, j = 0; i < height; i++, j++)
2825 gdk_draw_line (window, gc, x + j, y + i, x + width - j - 1, y + i);
2827 else if (arrow_type == GTK_ARROW_UP)
2829 for (i = height - 1, j = 0; i >= 0; i--, j++)
2830 gdk_draw_line (window, gc, x + j, y + i, x + width - j - 1, y + i);
2832 else if (arrow_type == GTK_ARROW_LEFT)
2834 for (i = width - 1, j = 0; i >= 0; i--, j++)
2835 gdk_draw_line (window, gc, x + i, y + j, x + i, y + height - j - 1);
2837 else if (arrow_type == GTK_ARROW_RIGHT)
2839 for (i = 0, j = 0; i < width; i++, j++)
2840 gdk_draw_line (window, gc, x + i, y + j, x + i, y + height - j - 1);
2844 gdk_gc_set_clip_rectangle (gc, NULL);
2848 calculate_arrow_geometry (GtkArrowType arrow_type,
2860 case GTK_ARROW_DOWN:
2870 if (arrow_type == GTK_ARROW_DOWN)
2872 if (*height % 2 == 1 || h % 2 == 0)
2877 if (*height % 2 == 0 || h % 2 == 0)
2882 case GTK_ARROW_RIGHT:
2883 case GTK_ARROW_LEFT:
2893 if (arrow_type == GTK_ARROW_RIGHT)
2895 if (*width % 2 == 1 || w % 2 == 0)
2900 if (*width % 2 == 0 || w % 2 == 0)
2906 /* should not be reached */
2910 *x += (*width - w) / 2;
2911 *y += (*height - h) / 2;
2917 gtk_default_draw_arrow (GtkStyle *style,
2920 GtkShadowType shadow,
2923 const gchar *detail,
2924 GtkArrowType arrow_type,
2931 gint original_width, original_x;
2933 sanitize_size (window, &width, &height);
2935 original_width = width;
2938 calculate_arrow_geometry (arrow_type, &x, &y, &width, &height);
2940 if (detail && strcmp (detail, "menuitem") == 0)
2941 x = original_x + original_width - width;
2943 if (state == GTK_STATE_INSENSITIVE)
2944 draw_arrow (window, style->white_gc, area, arrow_type,
2945 x + 1, y + 1, width, height);
2946 draw_arrow (window, style->fg_gc[state], area, arrow_type,
2947 x, y, width, height);
2951 gtk_default_draw_diamond (GtkStyle *style,
2953 GtkStateType state_type,
2954 GtkShadowType shadow_type,
2957 const gchar *detail,
2965 GdkGC *outer_nw = NULL;
2966 GdkGC *outer_ne = NULL;
2967 GdkGC *outer_sw = NULL;
2968 GdkGC *outer_se = NULL;
2969 GdkGC *middle_nw = NULL;
2970 GdkGC *middle_ne = NULL;
2971 GdkGC *middle_sw = NULL;
2972 GdkGC *middle_se = NULL;
2973 GdkGC *inner_nw = NULL;
2974 GdkGC *inner_ne = NULL;
2975 GdkGC *inner_sw = NULL;
2976 GdkGC *inner_se = NULL;
2978 g_return_if_fail (GTK_IS_STYLE (style));
2979 g_return_if_fail (window != NULL);
2981 sanitize_size (window, &width, &height);
2983 half_width = width / 2;
2984 half_height = height / 2;
2988 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
2989 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
2990 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
2991 gdk_gc_set_clip_rectangle (style->black_gc, area);
2994 switch (shadow_type)
2997 inner_sw = inner_se = style->bg_gc[state_type];
2998 middle_sw = middle_se = style->light_gc[state_type];
2999 outer_sw = outer_se = style->light_gc[state_type];
3000 inner_nw = inner_ne = style->black_gc;
3001 middle_nw = middle_ne = style->dark_gc[state_type];
3002 outer_nw = outer_ne = style->dark_gc[state_type];
3005 case GTK_SHADOW_OUT:
3006 inner_sw = inner_se = style->dark_gc[state_type];
3007 middle_sw = middle_se = style->dark_gc[state_type];
3008 outer_sw = outer_se = style->black_gc;
3009 inner_nw = inner_ne = style->bg_gc[state_type];
3010 middle_nw = middle_ne = style->light_gc[state_type];
3011 outer_nw = outer_ne = style->light_gc[state_type];
3014 case GTK_SHADOW_ETCHED_IN:
3015 inner_sw = inner_se = style->bg_gc[state_type];
3016 middle_sw = middle_se = style->dark_gc[state_type];
3017 outer_sw = outer_se = style->light_gc[state_type];
3018 inner_nw = inner_ne = style->bg_gc[state_type];
3019 middle_nw = middle_ne = style->light_gc[state_type];
3020 outer_nw = outer_ne = style->dark_gc[state_type];
3023 case GTK_SHADOW_ETCHED_OUT:
3024 inner_sw = inner_se = style->bg_gc[state_type];
3025 middle_sw = middle_se = style->light_gc[state_type];
3026 outer_sw = outer_se = style->dark_gc[state_type];
3027 inner_nw = inner_ne = style->bg_gc[state_type];
3028 middle_nw = middle_ne = style->dark_gc[state_type];
3029 outer_nw = outer_ne = style->light_gc[state_type];
3039 gdk_draw_line (window, inner_sw,
3040 x + 2, y + half_height,
3041 x + half_width, y + height - 2);
3042 gdk_draw_line (window, inner_se,
3043 x + half_width, y + height - 2,
3044 x + width - 2, y + half_height);
3045 gdk_draw_line (window, middle_sw,
3046 x + 1, y + half_height,
3047 x + half_width, y + height - 1);
3048 gdk_draw_line (window, middle_se,
3049 x + half_width, y + height - 1,
3050 x + width - 1, y + half_height);
3051 gdk_draw_line (window, outer_sw,
3053 x + half_width, y + height);
3054 gdk_draw_line (window, outer_se,
3055 x + half_width, y + height,
3056 x + width, y + half_height);
3058 gdk_draw_line (window, inner_nw,
3059 x + 2, y + half_height,
3060 x + half_width, y + 2);
3061 gdk_draw_line (window, inner_ne,
3062 x + half_width, y + 2,
3063 x + width - 2, y + half_height);
3064 gdk_draw_line (window, middle_nw,
3065 x + 1, y + half_height,
3066 x + half_width, y + 1);
3067 gdk_draw_line (window, middle_ne,
3068 x + half_width, y + 1,
3069 x + width - 1, y + half_height);
3070 gdk_draw_line (window, outer_nw,
3073 gdk_draw_line (window, outer_ne,
3075 x + width, y + half_height);
3080 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
3081 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
3082 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
3083 gdk_gc_set_clip_rectangle (style->black_gc, NULL);
3088 gtk_default_draw_string (GtkStyle *style,
3090 GtkStateType state_type,
3093 const gchar *detail,
3096 const gchar *string)
3098 GdkDisplay *display;
3100 g_return_if_fail (GTK_IS_STYLE (style));
3101 g_return_if_fail (window != NULL);
3103 display = gdk_drawable_get_display (window);
3107 gdk_gc_set_clip_rectangle (style->white_gc, area);
3108 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], area);
3111 if (state_type == GTK_STATE_INSENSITIVE)
3112 gdk_draw_string (window,
3113 gtk_style_get_font_for_display (display, style),
3114 style->white_gc, x + 1, y + 1, string);
3116 gdk_draw_string (window,
3117 gtk_style_get_font_for_display (display, style),
3118 style->fg_gc[state_type], x, y, string);
3122 gdk_gc_set_clip_rectangle (style->white_gc, NULL);
3123 gdk_gc_set_clip_rectangle (style->fg_gc[state_type], NULL);
3128 option_menu_get_props (GtkWidget *widget,
3129 GtkRequisition *indicator_size,
3130 GtkBorder *indicator_spacing)
3132 GtkRequisition *tmp_size = NULL;
3133 GtkBorder *tmp_spacing = NULL;
3136 gtk_widget_style_get (widget,
3137 "indicator_size", &tmp_size,
3138 "indicator_spacing", &tmp_spacing,
3143 *indicator_size = *tmp_size;
3147 *indicator_size = default_option_indicator_size;
3151 *indicator_spacing = *tmp_spacing;
3152 g_free (tmp_spacing);
3155 *indicator_spacing = default_option_indicator_spacing;
3159 gtk_default_draw_box (GtkStyle *style,
3161 GtkStateType state_type,
3162 GtkShadowType shadow_type,
3165 const gchar *detail,
3171 gboolean is_spinbutton_box = FALSE;
3173 g_return_if_fail (GTK_IS_STYLE (style));
3174 g_return_if_fail (window != NULL);
3176 sanitize_size (window, &width, &height);
3178 if (widget && GTK_IS_SPIN_BUTTON (widget) && detail)
3180 if (strcmp (detail, "spinbutton_up") == 0)
3186 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3191 is_spinbutton_box = TRUE;
3193 else if (strcmp (detail, "spinbutton_down") == 0)
3198 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
3203 is_spinbutton_box = TRUE;
3207 if (!style->bg_pixmap[state_type] ||
3208 GDK_IS_PIXMAP (window))
3211 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
3213 gdk_draw_rectangle (window, style->bg_gc[state_type], TRUE,
3214 x, y, width, height);
3216 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
3219 gtk_style_apply_default_background (style, window,
3220 widget && !GTK_WIDGET_NO_WINDOW (widget),
3221 state_type, area, x, y, width, height);
3223 if (is_spinbutton_box)
3228 lower_gc = style->dark_gc[state_type];
3229 if (shadow_type == GTK_SHADOW_OUT)
3230 upper_gc = style->light_gc[state_type];
3232 upper_gc = style->dark_gc[state_type];
3236 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
3237 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
3240 gdk_draw_line (window, upper_gc, x, y, x + width - 1, y);
3241 gdk_draw_line (window, lower_gc, x, y + height - 1, x + width - 1, y + height - 1);
3245 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
3246 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
3251 gtk_paint_shadow (style, window, state_type, shadow_type, area, widget, detail,
3252 x, y, width, height);
3254 if (detail && strcmp (detail, "optionmenu") == 0)
3256 GtkRequisition indicator_size;
3257 GtkBorder indicator_spacing;
3259 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
3261 sanitize_size (window, &width, &height);
3263 gtk_paint_vline (style, window, state_type, area, widget,
3265 y + style->ythickness + 1,
3266 y + height - style->ythickness - 3,
3267 x + width - (indicator_size.width + indicator_spacing.left + indicator_spacing.right) - style->xthickness);
3272 get_darkened_gc (GdkWindow *window,
3276 GdkColor src = *color;
3280 gc = gdk_gc_new (window);
3282 while (darken_count)
3284 gtk_style_shade (&src, &shaded, 0.93);
3289 gdk_gc_set_rgb_fg_color (gc, &shaded);
3295 gtk_default_draw_flat_box (GtkStyle *style,
3297 GtkStateType state_type,
3298 GtkShadowType shadow_type,
3301 const gchar *detail,
3308 GdkGC *freeme = NULL;
3310 g_return_if_fail (GTK_IS_STYLE (style));
3311 g_return_if_fail (window != NULL);
3313 sanitize_size (window, &width, &height);
3317 if (state_type == GTK_STATE_SELECTED)
3319 if (!strcmp ("text", detail))
3320 gc1 = style->bg_gc[GTK_STATE_SELECTED];
3321 else if (!strncmp ("cell_even", detail, strlen ("cell_even")) ||
3322 !strncmp ("cell_odd", detail, strlen ("cell_odd")))
3324 /* This has to be really broken; alex made me do it. -jrb */
3325 if (GTK_WIDGET_HAS_FOCUS (widget))
3326 gc1 = style->base_gc[state_type];
3328 gc1 = style->base_gc[GTK_STATE_ACTIVE];
3332 gc1 = style->bg_gc[state_type];
3337 if (!strcmp ("viewportbin", detail))
3338 gc1 = style->bg_gc[GTK_STATE_NORMAL];
3339 else if (!strcmp ("entry_bg", detail))
3340 gc1 = style->base_gc[state_type];
3342 /* For trees: even rows are base color, odd rows are a shade of
3343 * the base color, the sort column is a shade of the original color
3347 /* FIXME when we have style properties, clean this up.
3350 else if (!strcmp ("cell_even", detail) ||
3351 !strcmp ("cell_odd", detail) ||
3352 !strcmp ("cell_even_ruled", detail))
3354 gc1 = style->base_gc[state_type];
3356 else if (!strcmp ("cell_even_sorted", detail) ||
3357 !strcmp ("cell_odd_sorted", detail) ||
3358 !strcmp ("cell_odd_ruled", detail) ||
3359 !strcmp ("cell_even_ruled_sorted", detail))
3361 freeme = get_darkened_gc (window, &style->base[state_type], 1);
3364 else if (!strcmp ("cell_odd_ruled_sorted", detail))
3366 freeme = get_darkened_gc (window, &style->base[state_type], 2);
3370 gc1 = style->bg_gc[state_type];
3374 gc1 = style->bg_gc[state_type];
3376 if (!style->bg_pixmap[state_type] || gc1 != style->bg_gc[state_type] ||
3377 GDK_IS_PIXMAP (window))
3380 gdk_gc_set_clip_rectangle (gc1, area);
3382 gdk_draw_rectangle (window, gc1, TRUE,
3383 x, y, width, height);
3385 if (detail && !strcmp ("tooltip", detail))
3386 gdk_draw_rectangle (window, style->black_gc, FALSE,
3387 x, y, width - 1, height - 1);
3390 gdk_gc_set_clip_rectangle (gc1, NULL);
3393 gtk_style_apply_default_background (style, window,
3394 widget && !GTK_WIDGET_NO_WINDOW (widget),
3395 state_type, area, x, y, width, height);
3399 g_object_unref (G_OBJECT (freeme));
3403 gtk_default_draw_check (GtkStyle *style,
3405 GtkStateType state_type,
3406 GtkShadowType shadow_type,
3409 const gchar *detail,
3415 if (detail && strcmp (detail, "cellcheck") == 0)
3417 gdk_draw_rectangle (window,
3418 widget->style->base_gc[state_type],
3422 gdk_draw_rectangle (window,
3423 widget->style->text_gc[state_type],
3428 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3429 y -= (((1 + INDICATOR_PART_SIZE - height) / 2) - 1);
3430 if (shadow_type == GTK_SHADOW_IN)
3432 draw_part (window, style->text_gc[state_type], area, x, y, CHECK_TEXT);
3433 draw_part (window, style->text_aa_gc[state_type], area, x, y, CHECK_AA);
3438 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3439 y -= (1 + INDICATOR_PART_SIZE - height) / 2;
3441 if (strcmp (detail, "check") == 0) /* Menu item */
3443 if (shadow_type == GTK_SHADOW_IN)
3445 draw_part (window, style->black_gc, area, x, y, CHECK_TEXT);
3446 draw_part (window, style->dark_gc[state_type], area, x, y, CHECK_AA);
3448 else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
3450 draw_part (window, style->black_gc, area, x, y, CHECK_INCONSISTENT_TEXT);
3451 draw_part (window, style->dark_gc[state_type], area, x, y, CHECK_INCONSISTENT_AA);
3456 GdkGC *base_gc = style->base_gc[state_type];
3458 if (state_type == GTK_STATE_ACTIVE)
3459 base_gc = style->bg_gc[GTK_STATE_ACTIVE];
3461 draw_part (window, base_gc, area, x, y, CHECK_BASE);
3462 draw_part (window, style->black_gc, area, x, y, CHECK_BLACK);
3463 draw_part (window, style->dark_gc[state_type], area, x, y, CHECK_DARK);
3464 draw_part (window, style->mid_gc[state_type], area, x, y, CHECK_MID);
3465 draw_part (window, style->light_gc[state_type], area, x, y, CHECK_LIGHT);
3467 if (shadow_type == GTK_SHADOW_IN)
3469 draw_part (window, style->text_gc[state_type], area, x, y, CHECK_TEXT);
3470 draw_part (window, style->text_aa_gc[state_type], area, x, y, CHECK_AA);
3472 else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
3474 draw_part (window, style->text_gc[state_type], area, x, y, CHECK_INCONSISTENT_TEXT);
3475 draw_part (window, style->text_aa_gc[state_type], area, x, y, CHECK_INCONSISTENT_AA);
3483 gtk_default_draw_option (GtkStyle *style,
3485 GtkStateType state_type,
3486 GtkShadowType shadow_type,
3489 const gchar *detail,
3495 if (detail && strcmp (detail, "cellradio") == 0)
3497 gdk_draw_arc (window,
3498 widget->style->fg_gc[state_type],
3505 if (shadow_type == GTK_SHADOW_IN)
3507 gdk_draw_arc (window,
3508 widget->style->fg_gc[state_type],
3519 x -= (1 + INDICATOR_PART_SIZE - width) / 2;
3520 y -= (1 + INDICATOR_PART_SIZE - height) / 2;
3522 if (strcmp (detail, "option") == 0) /* Menu item */
3524 if (shadow_type == GTK_SHADOW_IN)
3526 draw_part (window, style->fg_gc[state_type], area, x, y, RADIO_TEXT);
3528 else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
3530 draw_part (window, style->black_gc, area, x, y, CHECK_INCONSISTENT_TEXT);
3531 draw_part (window, style->dark_gc[state_type], area, x, y, CHECK_INCONSISTENT_AA);
3536 GdkGC *base_gc = style->base_gc[state_type];
3538 if (state_type == GTK_STATE_ACTIVE)
3539 base_gc = style->bg_gc[GTK_STATE_ACTIVE];
3541 draw_part (window, base_gc, area, x, y, RADIO_BASE);
3542 draw_part (window, style->black_gc, area, x, y, RADIO_BLACK);
3543 draw_part (window, style->dark_gc[state_type], area, x, y, RADIO_DARK);
3544 draw_part (window, style->mid_gc[state_type], area, x, y, RADIO_MID);
3545 draw_part (window, style->light_gc[state_type], area, x, y, RADIO_LIGHT);
3547 if (shadow_type == GTK_SHADOW_IN)
3549 draw_part (window, style->text_gc[state_type], area, x, y, RADIO_TEXT);
3551 else if (shadow_type == GTK_SHADOW_ETCHED_IN) /* inconsistent */
3553 draw_part (window, style->text_aa_gc[state_type], area, x, y, RADIO_INCONSISTENT_AA);
3554 draw_part (window, style->text_gc[state_type], area, x, y, RADIO_INCONSISTENT_TEXT);
3561 gtk_default_draw_tab (GtkStyle *style,
3563 GtkStateType state_type,
3564 GtkShadowType shadow_type,
3567 const gchar *detail,
3573 #define ARROW_SPACE 4
3575 GtkRequisition indicator_size;
3576 GtkBorder indicator_spacing;
3579 option_menu_get_props (widget, &indicator_size, &indicator_spacing);
3581 indicator_size.width += (indicator_size.width % 2) - 1;
3582 arrow_height = indicator_size.width / 2 + 1;
3584 x += (width - indicator_size.width) / 2;
3585 y += (height - (2 * arrow_height + ARROW_SPACE)) / 2;
3587 if (state_type == GTK_STATE_INSENSITIVE)
3589 draw_arrow (window, style->white_gc, area,
3590 GTK_ARROW_UP, x + 1, y + 1,
3591 indicator_size.width, arrow_height);
3593 draw_arrow (window, style->white_gc, area,
3594 GTK_ARROW_DOWN, x + 1, y + arrow_height + ARROW_SPACE + 1,
3595 indicator_size.width, arrow_height);
3598 draw_arrow (window, style->fg_gc[state_type], area,
3600 indicator_size.width, arrow_height);
3603 draw_arrow (window, style->fg_gc[state_type], area,
3604 GTK_ARROW_DOWN, x, y + arrow_height + ARROW_SPACE,
3605 indicator_size.width, arrow_height);
3609 gtk_default_draw_shadow_gap (GtkStyle *style,
3611 GtkStateType state_type,
3612 GtkShadowType shadow_type,
3615 const gchar *detail,
3620 GtkPositionType gap_side,
3629 g_return_if_fail (GTK_IS_STYLE (style));
3630 g_return_if_fail (window != NULL);
3632 sanitize_size (window, &width, &height);
3634 switch (shadow_type)
3636 case GTK_SHADOW_NONE:
3639 gc1 = style->dark_gc[state_type];
3640 gc2 = style->black_gc;
3641 gc3 = style->bg_gc[state_type];
3642 gc4 = style->light_gc[state_type];
3644 case GTK_SHADOW_ETCHED_IN:
3645 gc1 = style->dark_gc[state_type];
3646 gc2 = style->light_gc[state_type];
3647 gc3 = style->dark_gc[state_type];
3648 gc4 = style->light_gc[state_type];
3650 case GTK_SHADOW_OUT:
3651 gc1 = style->light_gc[state_type];
3652 gc2 = style->bg_gc[state_type];
3653 gc3 = style->dark_gc[state_type];
3654 gc4 = style->black_gc;
3656 case GTK_SHADOW_ETCHED_OUT:
3657 gc1 = style->light_gc[state_type];
3658 gc2 = style->dark_gc[state_type];
3659 gc3 = style->light_gc[state_type];
3660 gc4 = style->dark_gc[state_type];
3665 gdk_gc_set_clip_rectangle (gc1, area);
3666 gdk_gc_set_clip_rectangle (gc2, area);
3667 gdk_gc_set_clip_rectangle (gc3, area);
3668 gdk_gc_set_clip_rectangle (gc4, area);
3671 switch (shadow_type)
3673 case GTK_SHADOW_NONE:
3675 case GTK_SHADOW_OUT:
3676 case GTK_SHADOW_ETCHED_IN:
3677 case GTK_SHADOW_ETCHED_OUT:
3681 gdk_draw_line (window, gc1,
3682 x, y, x, y + height - 1);
3683 gdk_draw_line (window, gc2,
3684 x + 1, y, x + 1, y + height - 2);
3686 gdk_draw_line (window, gc3,
3687 x + 1, y + height - 2, x + width - 2, y + height - 2);
3688 gdk_draw_line (window, gc3,
3689 x + width - 2, y, x + width - 2, y + height - 2);
3690 gdk_draw_line (window, gc4,
3691 x, y + height - 1, x + width - 1, y + height - 1);
3692 gdk_draw_line (window, gc4,
3693 x + width - 1, y, x + width - 1, y + height - 1);
3696 gdk_draw_line (window, gc1,
3697 x, y, x + gap_x - 1, y);
3698 gdk_draw_line (window, gc2,
3699 x + 1, y + 1, x + gap_x - 1, y + 1);
3700 gdk_draw_line (window, gc2,
3701 x + gap_x, y, x + gap_x, y);
3703 if ((width - (gap_x + gap_width)) > 0)
3705 gdk_draw_line (window, gc1,
3706 x + gap_x + gap_width, y, x + width - 2, y);
3707 gdk_draw_line (window, gc2,
3708 x + gap_x + gap_width, y + 1, x + width - 3, y + 1);
3709 gdk_draw_line (window, gc2,
3710 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
3713 case GTK_POS_BOTTOM:
3714 gdk_draw_line (window, gc1,
3715 x, y, x + width - 1, y);
3716 gdk_draw_line (window, gc1,
3717 x, y, x, y + height - 1);
3718 gdk_draw_line (window, gc2,
3719 x + 1, y + 1, x + width - 2, y + 1);
3720 gdk_draw_line (window, gc2,
3721 x + 1, y + 1, x + 1, y + height - 1);
3723 gdk_draw_line (window, gc3,
3724 x + width - 2, y + 1, x + width - 2, y + height - 1);
3725 gdk_draw_line (window, gc4,
3726 x + width - 1, y, x + width - 1, y + height - 1);
3729 gdk_draw_line (window, gc4,
3730 x, y + height - 1, x + gap_x - 1, y + height - 1);
3731 gdk_draw_line (window, gc3,
3732 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
3733 gdk_draw_line (window, gc3,
3734 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
3736 if ((width - (gap_x + gap_width)) > 0)
3738 gdk_draw_line (window, gc4,
3739 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
3740 gdk_draw_line (window, gc3,
3741 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
3742 gdk_draw_line (window, gc3,
3743 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
3747 gdk_draw_line (window, gc1,
3748 x, y, x + width - 1, y);
3749 gdk_draw_line (window, gc2,
3750 x, y + 1, x + width - 2, y + 1);
3752 gdk_draw_line (window, gc3,
3753 x, y + height - 2, x + width - 2, y + height - 2);
3754 gdk_draw_line (window, gc3,
3755 x + width - 2, y + 1, x + width - 2, y + height - 2);
3756 gdk_draw_line (window, gc4,
3757 x, y + height - 1, x + width - 1, y + height - 1);
3758 gdk_draw_line (window, gc4,
3759 x + width - 1, y, x + width - 1, y + height - 1);
3762 gdk_draw_line (window, gc1,
3763 x, y, x, y + gap_x - 1);
3764 gdk_draw_line (window, gc2,
3765 x + 1, y + 1, x + 1, y + gap_x - 1);
3766 gdk_draw_line (window, gc2,
3767 x, y + gap_x, x, y + gap_x);
3769 if ((width - (gap_x + gap_width)) > 0)
3771 gdk_draw_line (window, gc1,
3772 x, y + gap_x + gap_width, x, y + height - 2);
3773 gdk_draw_line (window, gc2,
3774 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
3775 gdk_draw_line (window, gc2,
3776 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
3780 gdk_draw_line (window, gc1,
3781 x, y, x + width - 1, y);
3782 gdk_draw_line (window, gc1,
3783 x, y, x, y + height - 1);
3784 gdk_draw_line (window, gc2,
3785 x + 1, y + 1, x + width - 1, y + 1);
3786 gdk_draw_line (window, gc2,
3787 x + 1, y + 1, x + 1, y + height - 2);
3789 gdk_draw_line (window, gc3,
3790 x + 1, y + height - 2, x + width - 1, y + height - 2);
3791 gdk_draw_line (window, gc4,
3792 x, y + height - 1, x + width - 1, y + height - 1);
3795 gdk_draw_line (window, gc4,
3796 x + width - 1, y, x + width - 1, y + gap_x - 1);
3797 gdk_draw_line (window, gc3,
3798 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
3799 gdk_draw_line (window, gc3,
3800 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
3802 if ((width - (gap_x + gap_width)) > 0)
3804 gdk_draw_line (window, gc4,
3805 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
3806 gdk_draw_line (window, gc3,
3807 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
3808 gdk_draw_line (window, gc3,
3809 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
3817 gdk_gc_set_clip_rectangle (gc1, NULL);
3818 gdk_gc_set_clip_rectangle (gc2, NULL);
3819 gdk_gc_set_clip_rectangle (gc3, NULL);
3820 gdk_gc_set_clip_rectangle (gc4, NULL);
3825 gtk_default_draw_box_gap (GtkStyle *style,
3827 GtkStateType state_type,
3828 GtkShadowType shadow_type,
3831 const gchar *detail,
3836 GtkPositionType gap_side,
3845 g_return_if_fail (GTK_IS_STYLE (style));
3846 g_return_if_fail (window != NULL);
3848 gtk_style_apply_default_background (style, window,
3849 widget && !GTK_WIDGET_NO_WINDOW (widget),
3850 state_type, area, x, y, width, height);
3852 sanitize_size (window, &width, &height);
3854 switch (shadow_type)
3856 case GTK_SHADOW_NONE:
3859 gc1 = style->dark_gc[state_type];
3860 gc2 = style->black_gc;
3861 gc3 = style->bg_gc[state_type];
3862 gc4 = style->light_gc[state_type];
3864 case GTK_SHADOW_ETCHED_IN:
3865 gc1 = style->dark_gc[state_type];
3866 gc2 = style->light_gc[state_type];
3867 gc3 = style->dark_gc[state_type];
3868 gc4 = style->light_gc[state_type];
3870 case GTK_SHADOW_OUT:
3871 gc1 = style->light_gc[state_type];
3872 gc2 = style->bg_gc[state_type];
3873 gc3 = style->dark_gc[state_type];
3874 gc4 = style->black_gc;
3876 case GTK_SHADOW_ETCHED_OUT:
3877 gc1 = style->light_gc[state_type];
3878 gc2 = style->dark_gc[state_type];
3879 gc3 = style->light_gc[state_type];
3880 gc4 = style->dark_gc[state_type];
3886 gdk_gc_set_clip_rectangle (gc1, area);
3887 gdk_gc_set_clip_rectangle (gc2, area);
3888 gdk_gc_set_clip_rectangle (gc3, area);
3889 gdk_gc_set_clip_rectangle (gc4, area);
3892 switch (shadow_type)
3894 case GTK_SHADOW_NONE:
3896 case GTK_SHADOW_OUT:
3897 case GTK_SHADOW_ETCHED_IN:
3898 case GTK_SHADOW_ETCHED_OUT:
3902 gdk_draw_line (window, gc1,
3903 x, y, x, y + height - 1);
3904 gdk_draw_line (window, gc2,
3905 x + 1, y, x + 1, y + height - 2);
3907 gdk_draw_line (window, gc3,
3908 x + 1, y + height - 2, x + width - 2, y + height - 2);
3909 gdk_draw_line (window, gc3,
3910 x + width - 2, y, x + width - 2, y + height - 2);
3911 gdk_draw_line (window, gc4,
3912 x, y + height - 1, x + width - 1, y + height - 1);
3913 gdk_draw_line (window, gc4,
3914 x + width - 1, y, x + width - 1, y + height - 1);
3917 gdk_draw_line (window, gc1,
3918 x, y, x + gap_x - 1, y);
3919 gdk_draw_line (window, gc2,
3920 x + 1, y + 1, x + gap_x - 1, y + 1);
3921 gdk_draw_line (window, gc2,
3922 x + gap_x, y, x + gap_x, y);
3924 if ((width - (gap_x + gap_width)) > 0)
3926 gdk_draw_line (window, gc1,
3927 x + gap_x + gap_width, y, x + width - 2, y);
3928 gdk_draw_line (window, gc2,
3929 x + gap_x + gap_width, y + 1, x + width - 2, y + 1);
3930 gdk_draw_line (window, gc2,
3931 x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
3934 case GTK_POS_BOTTOM:
3935 gdk_draw_line (window, gc1,
3936 x, y, x + width - 1, y);
3937 gdk_draw_line (window, gc1,
3938 x, y, x, y + height - 1);
3939 gdk_draw_line (window, gc2,
3940 x + 1, y + 1, x + width - 2, y + 1);
3941 gdk_draw_line (window, gc2,
3942 x + 1, y + 1, x + 1, y + height - 1);
3944 gdk_draw_line (window, gc3,
3945 x + width - 2, y + 1, x + width - 2, y + height - 1);
3946 gdk_draw_line (window, gc4,
3947 x + width - 1, y, x + width - 1, y + height - 1);
3950 gdk_draw_line (window, gc4,
3951 x, y + height - 1, x + gap_x - 1, y + height - 1);
3952 gdk_draw_line (window, gc3,
3953 x + 1, y + height - 2, x + gap_x - 1, y + height - 2);
3954 gdk_draw_line (window, gc3,
3955 x + gap_x, y + height - 1, x + gap_x, y + height - 1);
3957 if ((width - (gap_x + gap_width)) > 0)
3959 gdk_draw_line (window, gc4,
3960 x + gap_x + gap_width, y + height - 1, x + width - 2, y + height - 1);
3961 gdk_draw_line (window, gc3,
3962 x + gap_x + gap_width, y + height - 2, x + width - 2, y + height - 2);
3963 gdk_draw_line (window, gc3,
3964 x + gap_x + gap_width - 1, y + height - 1, x + gap_x + gap_width - 1, y + height - 1);
3968 gdk_draw_line (window, gc1,
3969 x, y, x + width - 1, y);
3970 gdk_draw_line (window, gc2,
3971 x, y + 1, x + width - 2, y + 1);
3973 gdk_draw_line (window, gc3,
3974 x, y + height - 2, x + width - 2, y + height - 2);
3975 gdk_draw_line (window, gc3,
3976 x + width - 2, y + 1, x + width - 2, y + height - 2);
3977 gdk_draw_line (window, gc4,
3978 x, y + height - 1, x + width - 1, y + height - 1);
3979 gdk_draw_line (window, gc4,
3980 x + width - 1, y, x + width - 1, y + height - 1);
3983 gdk_draw_line (window, gc1,
3984 x, y, x, y + gap_x - 1);
3985 gdk_draw_line (window, gc2,
3986 x + 1, y + 1, x + 1, y + gap_x - 1);
3987 gdk_draw_line (window, gc2,
3988 x, y + gap_x, x, y + gap_x);
3990 if ((width - (gap_x + gap_width)) > 0)
3992 gdk_draw_line (window, gc1,
3993 x, y + gap_x + gap_width, x, y + height - 2);
3994 gdk_draw_line (window, gc2,
3995 x + 1, y + gap_x + gap_width, x + 1, y + height - 2);
3996 gdk_draw_line (window, gc2,
3997 x, y + gap_x + gap_width - 1, x, y + gap_x + gap_width - 1);
4001 gdk_draw_line (window, gc1,
4002 x, y, x + width - 1, y);
4003 gdk_draw_line (window, gc1,
4004 x, y, x, y + height - 1);
4005 gdk_draw_line (window, gc2,
4006 x + 1, y + 1, x + width - 1, y + 1);
4007 gdk_draw_line (window, gc2,
4008 x + 1, y + 1, x + 1, y + height - 2);
4010 gdk_draw_line (window, gc3,
4011 x + 1, y + height - 2, x + width - 1, y + height - 2);
4012 gdk_draw_line (window, gc4,
4013 x, y + height - 1, x + width - 1, y + height - 1);
4016 gdk_draw_line (window, gc4,
4017 x + width - 1, y, x + width - 1, y + gap_x - 1);
4018 gdk_draw_line (window, gc3,
4019 x + width - 2, y + 1, x + width - 2, y + gap_x - 1);
4020 gdk_draw_line (window, gc3,
4021 x + width - 1, y + gap_x, x + width - 1, y + gap_x);
4023 if ((width - (gap_x + gap_width)) > 0)
4025 gdk_draw_line (window, gc4,
4026 x + width - 1, y + gap_x + gap_width, x + width - 1, y + height - 2);
4027 gdk_draw_line (window, gc3,
4028 x + width - 2, y + gap_x + gap_width, x + width - 2, y + height - 2);
4029 gdk_draw_line (window, gc3,
4030 x + width - 1, y + gap_x + gap_width - 1, x + width - 1, y + gap_x + gap_width - 1);
4038 gdk_gc_set_clip_rectangle (gc1, NULL);
4039 gdk_gc_set_clip_rectangle (gc2, NULL);
4040 gdk_gc_set_clip_rectangle (gc3, NULL);
4041 gdk_gc_set_clip_rectangle (gc4, NULL);
4046 gtk_default_draw_extension (GtkStyle *style,
4048 GtkStateType state_type,
4049 GtkShadowType shadow_type,
4052 const gchar *detail,
4057 GtkPositionType gap_side)
4064 g_return_if_fail (GTK_IS_STYLE (style));
4065 g_return_if_fail (window != NULL);
4067 gtk_style_apply_default_background (style, window,
4068 widget && !GTK_WIDGET_NO_WINDOW (widget),
4069 GTK_STATE_NORMAL, area, x, y, width, height);
4071 sanitize_size (window, &width, &height);
4073 switch (shadow_type)
4075 case GTK_SHADOW_NONE:
4078 gc1 = style->dark_gc[state_type];
4079 gc2 = style->black_gc;
4080 gc3 = style->bg_gc[state_type];
4081 gc4 = style->light_gc[state_type];
4083 case GTK_SHADOW_ETCHED_IN:
4084 gc1 = style->dark_gc[state_type];
4085 gc2 = style->light_gc[state_type];
4086 gc3 = style->dark_gc[state_type];
4087 gc4 = style->light_gc[state_type];
4089 case GTK_SHADOW_OUT:
4090 gc1 = style->light_gc[state_type];
4091 gc2 = style->bg_gc[state_type];
4092 gc3 = style->dark_gc[state_type];
4093 gc4 = style->black_gc;
4095 case GTK_SHADOW_ETCHED_OUT:
4096 gc1 = style->light_gc[state_type];
4097 gc2 = style->dark_gc[state_type];
4098 gc3 = style->light_gc[state_type];
4099 gc4 = style->dark_gc[state_type];
4105 gdk_gc_set_clip_rectangle (gc1, area);
4106 gdk_gc_set_clip_rectangle (gc2, area);
4107 gdk_gc_set_clip_rectangle (gc3, area);
4108 gdk_gc_set_clip_rectangle (gc4, area);
4111 switch (shadow_type)
4113 case GTK_SHADOW_NONE:
4115 case GTK_SHADOW_OUT:
4116 case GTK_SHADOW_ETCHED_IN:
4117 case GTK_SHADOW_ETCHED_OUT:
4121 gtk_style_apply_default_background (style, window,
4122 widget && !GTK_WIDGET_NO_WINDOW (widget),
4124 x + style->xthickness,
4126 width - (2 * style->xthickness),
4127 height - (style->ythickness));
4128 gdk_draw_line (window, gc1,
4129 x, y, x, y + height - 2);
4130 gdk_draw_line (window, gc2,
4131 x + 1, y, x + 1, y + height - 2);
4133 gdk_draw_line (window, gc3,
4134 x + 2, y + height - 2, x + width - 2, y + height - 2);
4135 gdk_draw_line (window, gc3,
4136 x + width - 2, y, x + width - 2, y + height - 2);
4137 gdk_draw_line (window, gc4,
4138 x + 1, y + height - 1, x + width - 2, y + height - 1);
4139 gdk_draw_line (window, gc4,
4140 x + width - 1, y, x + width - 1, y + height - 2);
4142 case GTK_POS_BOTTOM:
4143 gtk_style_apply_default_background (style, window,
4144 widget && !GTK_WIDGET_NO_WINDOW (widget),
4146 x + style->xthickness,
4147 y + style->ythickness,
4148 width - (2 * style->xthickness),
4149 height - (style->ythickness));
4150 gdk_draw_line (window, gc1,
4151 x + 1, y, x + width - 2, y);
4152 gdk_draw_line (window, gc1,
4153 x, y + 1, x, y + height - 1);
4154 gdk_draw_line (window, gc2,
4155 x + 1, y + 1, x + width - 2, y + 1);
4156 gdk_draw_line (window, gc2,
4157 x + 1, y + 1, x + 1, y + height - 1);
4159 gdk_draw_line (window, gc3,
4160 x + width - 2, y + 2, x + width - 2, y + height - 1);
4161 gdk_draw_line (window, gc4,
4162 x + width - 1, y + 1, x + width - 1, y + height - 1);
4165 gtk_style_apply_default_background (style, window,
4166 widget && !GTK_WIDGET_NO_WINDOW (widget),
4169 y + style->ythickness,
4170 width - (style->xthickness),
4171 height - (2 * style->ythickness));
4172 gdk_draw_line (window, gc1,
4173 x, y, x + width - 2, y);
4174 gdk_draw_line (window, gc2,
4175 x + 1, y + 1, x + width - 2, y + 1);
4177 gdk_draw_line (window, gc3,
4178 x, y + height - 2, x + width - 2, y + height - 2);
4179 gdk_draw_line (window, gc3,
4180 x + width - 2, y + 2, x + width - 2, y + height - 2);
4181 gdk_draw_line (window, gc4,
4182 x, y + height - 1, x + width - 2, y + height - 1);
4183 gdk_draw_line (window, gc4,
4184 x + width - 1, y + 1, x + width - 1, y + height - 2);
4187 gtk_style_apply_default_background (style, window,
4188 widget && !GTK_WIDGET_NO_WINDOW (widget),
4190 x + style->xthickness,
4191 y + style->ythickness,
4192 width - (style->xthickness),
4193 height - (2 * style->ythickness));
4194 gdk_draw_line (window, gc1,
4195 x + 1, y, x + width - 1, y);
4196 gdk_draw_line (window, gc1,
4197 x, y + 1, x, y + height - 2);
4198 gdk_draw_line (window, gc2,
4199 x + 1, y + 1, x + width - 1, y + 1);
4200 gdk_draw_line (window, gc2,
4201 x + 1, y + 1, x + 1, y + height - 2);
4203 gdk_draw_line (window, gc3,
4204 x + 2, y + height - 2, x + width - 1, y + height - 2);
4205 gdk_draw_line (window, gc4,
4206 x + 1, y + height - 1, x + width - 1, y + height - 1);
4213 gdk_gc_set_clip_rectangle (gc1, NULL);
4214 gdk_gc_set_clip_rectangle (gc2, NULL);
4215 gdk_gc_set_clip_rectangle (gc3, NULL);
4216 gdk_gc_set_clip_rectangle (gc4, NULL);
4221 gtk_default_draw_focus (GtkStyle *style,
4223 GtkStateType state_type,
4226 const gchar *detail,
4234 gboolean free_dash_list = FALSE;
4235 gint line_width = 1;
4236 gchar *dash_list = "\1\1";
4239 gc = style->fg_gc[state_type];
4243 gtk_widget_style_get (widget,
4244 "focus-line-width", &line_width,
4245 "focus-line-pattern", (gchar *)&dash_list,
4248 free_dash_list = TRUE;
4251 sanitize_size (window, &width, &height);
4254 gdk_gc_set_clip_rectangle (gc, area);
4256 gdk_gc_set_line_attributes (gc, line_width,
4257 dash_list[0] ? GDK_LINE_ON_OFF_DASH : GDK_LINE_SOLID,
4258 GDK_CAP_BUTT, GDK_JOIN_MITER);
4261 if (detail && !strcmp (detail, "add-mode"))
4267 free_dash_list = FALSE;
4270 points[0].x = x + line_width / 2;
4271 points[0].y = y + line_width / 2;
4272 points[1].x = x + width - line_width + line_width / 2;
4273 points[1].y = y + line_width / 2;
4274 points[2].x = x + width - line_width + line_width / 2;
4275 points[2].y = y + height - line_width + line_width / 2;
4276 points[3].x = x + line_width / 2;
4277 points[3].y = y + height - line_width + line_width / 2;
4278 points[4] = points[0];
4282 gdk_draw_lines (window, gc, points, 5);
4286 /* We go through all the pain below because the X rasterization
4287 * rules don't really work right for dashed lines if you
4288 * want continuity in segments that go between top/right
4289 * and left/bottom. For instance, a top left corner
4290 * with a 1-1 dash is drawn as:
4297 * This is because pixels on the top and left boundaries
4298 * of polygons are drawn, but not on the bottom and right.
4299 * So, if you have a line going up that turns the corner
4300 * and goes right, there is a one pixel shift in the pattern.
4302 * So, to fix this, we drawn the top and right in one call,
4303 * then the left and bottom in another call, fixing up
4304 * the dash offset for the second call ourselves to get
4305 * continuity at the upper left.
4307 * It's not perfect since we really should have a join at
4308 * the upper left and lower right instead of two intersecting
4309 * lines but that's only really apparent for no-dashes,
4310 * which (for this reason) are done as one polygon and
4311 * don't to through this code path.
4314 dash_len = strlen (dash_list);
4317 gdk_gc_set_dashes (gc, 0, dash_list, dash_len);
4319 gdk_draw_lines (window, gc, points, 3);
4321 /* We draw this line one farther over than it is "supposed" to
4322 * because of another rasterization problem ... if two 1 pixel
4323 * unjoined lines meet at the lower right, there will be a missing
4330 gint dash_pixels = 0;
4333 /* Adjust the dash offset for the bottom and left so we
4334 * match up at the upper left.
4336 for (i = 0; i < dash_len; i++)
4337 dash_pixels += dash_list[i];
4339 if (dash_len % 2 == 1)
4342 gdk_gc_set_dashes (gc, dash_pixels - (width + height - 2 * line_width) % dash_pixels, dash_list, dash_len);
4345 gdk_draw_lines (window, gc, points + 2, 3);
4348 gdk_gc_set_line_attributes (gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
4351 gdk_gc_set_clip_rectangle (gc, NULL);
4358 gtk_default_draw_slider (GtkStyle *style,
4360 GtkStateType state_type,
4361 GtkShadowType shadow_type,
4364 const gchar *detail,
4369 GtkOrientation orientation)
4371 g_return_if_fail (GTK_IS_STYLE (style));
4372 g_return_if_fail (window != NULL);
4374 sanitize_size (window, &width, &height);
4376 gtk_paint_box (style, window, state_type, shadow_type,
4377 area, widget, detail, x, y, width, height);
4380 (strcmp ("hscale", detail) == 0 ||
4381 strcmp ("vscale", detail) == 0))
4383 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4384 gtk_paint_vline (style, window, state_type, area, widget, detail,
4385 y + style->ythickness,
4386 y + height - style->ythickness - 1, x + width / 2);
4388 gtk_paint_hline (style, window, state_type, area, widget, detail,
4389 x + style->xthickness,
4390 x + width - style->xthickness - 1, y + height / 2);
4395 draw_dot (GdkWindow *window,
4403 size = CLAMP (size, 2, 3);
4407 gdk_draw_point (window, light_gc, x, y);
4408 gdk_draw_point (window, light_gc, x+1, y+1);
4410 else if (size == 3);
4412 gdk_draw_point (window, light_gc, x, y);
4413 gdk_draw_point (window, light_gc, x+1, y);
4414 gdk_draw_point (window, light_gc, x, y+1);
4415 gdk_draw_point (window, dark_gc, x+1, y+2);
4416 gdk_draw_point (window, dark_gc, x+2, y+1);
4417 gdk_draw_point (window, dark_gc, x+2, y+2);
4422 gtk_default_draw_handle (GtkStyle *style,
4424 GtkStateType state_type,
4425 GtkShadowType shadow_type,
4428 const gchar *detail,
4433 GtkOrientation orientation)
4436 gint xthick, ythick;
4437 GdkGC *light_gc, *dark_gc;
4442 g_return_if_fail (GTK_IS_STYLE (style));
4443 g_return_if_fail (window != NULL);
4445 sanitize_size (window, &width, &height);
4447 gtk_paint_box (style, window, state_type, shadow_type, area, widget,
4448 detail, x, y, width, height);
4451 if (!strcmp (detail, "paned"))
4453 /* we want to ignore the shadow border in paned widgets */
4457 light_gc = style->light_gc[state_type];
4458 dark_gc = style->black_gc;
4462 xthick = style->xthickness;
4463 ythick = style->ythickness;
4465 light_gc = style->light_gc[state_type];
4466 dark_gc = style->dark_gc[state_type];
4469 rect.x = x + xthick;
4470 rect.y = y + ythick;
4471 rect.width = width - (xthick * 2);
4472 rect.height = height - (ythick * 2);
4475 intersect = gdk_rectangle_intersect (area, &rect, &dest);
4485 gdk_gc_set_clip_rectangle (light_gc, &dest);
4486 gdk_gc_set_clip_rectangle (dark_gc, &dest);
4488 if (!strcmp (detail, "paned"))
4490 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4491 for (xx = x + width/2 - 15; xx <= x + width/2 + 15; xx += 5)
4492 draw_dot (window, light_gc, dark_gc, xx, y + height/2 - 1, 3);
4494 for (yy = y + height/2 - 15; yy <= y + height/2 + 15; yy += 5)
4495 draw_dot (window, light_gc, dark_gc, x + width/2 - 1, yy, 3);
4499 for (yy = y + ythick; yy < (y + height - ythick); yy += 3)
4500 for (xx = x + xthick; xx < (x + width - xthick); xx += 6)
4502 draw_dot (window, light_gc, dark_gc, xx, yy, 2);
4503 draw_dot (window, light_gc, dark_gc, xx + 3, yy + 1, 2);
4507 gdk_gc_set_clip_rectangle (light_gc, NULL);
4508 gdk_gc_set_clip_rectangle (dark_gc, NULL);
4512 create_expander_affine (gdouble affine[6],
4522 width = expander_size / 4.0;
4523 height = expander_size / 2.0;
4525 s = sin (degrees * G_PI / 180.0);
4526 c = cos (degrees * G_PI / 180.0);
4532 affine[4] = -width * c - height * -s + x;
4533 affine[5] = -width * s - height * c + y;
4537 apply_affine_on_point (double affine[6], GdkPoint *point)
4541 x = point->x * affine[0] + point->y * affine[2] + affine[4];
4542 y = point->x * affine[1] + point->y * affine[3] + affine[5];
4549 gtk_style_draw_polygon_with_gc (GdkWindow *window, GdkGC *gc, gint line_width,
4550 gboolean do_fill, GdkPoint *points, gint n_points)
4552 gdk_gc_set_line_attributes (gc, line_width,
4554 GDK_CAP_BUTT, GDK_JOIN_MITER);
4556 gdk_draw_polygon (window, gc, do_fill, points, n_points);
4557 gdk_gc_set_line_attributes (gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
4561 gtk_default_draw_expander (GtkStyle *style,
4563 GtkStateType state_type,
4566 const gchar *detail,
4569 GtkExpanderStyle expander_style)
4578 gtk_widget_style_get (widget,
4579 "expander_size", &expander_size,
4581 line_width = MAX (1, expander_size/7);
4585 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], area);
4586 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], area);
4589 expander_size -= (line_width * 2 - 2);
4590 points[0].x = line_width / 2;
4591 points[0].y = line_width / 2;
4592 points[1].x = expander_size / 2 + line_width / 2;
4593 points[1].y = expander_size / 2 + line_width / 2;
4594 points[2].x = line_width / 2;
4595 points[2].y = expander_size + line_width / 2;
4597 switch (expander_style)
4599 case GTK_EXPANDER_COLLAPSED:
4600 degrees = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ? 180 : 0;
4602 case GTK_EXPANDER_SEMI_COLLAPSED:
4603 degrees = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ? 150 : 30;
4605 case GTK_EXPANDER_SEMI_EXPANDED:
4606 degrees = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ? 120 : 60;
4608 case GTK_EXPANDER_EXPANDED:
4612 g_assert_not_reached ();
4615 create_expander_affine (affine, degrees, expander_size, x, y);
4617 for (i = 0; i < 3; i++)
4618 apply_affine_on_point (affine, &points[i]);
4620 if (state_type == GTK_STATE_PRELIGHT)
4622 gtk_style_draw_polygon_with_gc (window, style->fg_gc[GTK_STATE_NORMAL],
4623 1, TRUE, points, 3);
4625 else if (state_type == GTK_STATE_ACTIVE)
4627 gtk_style_draw_polygon_with_gc (window, style->light_gc[GTK_STATE_ACTIVE],
4628 1, TRUE, points, 3);
4629 gtk_style_draw_polygon_with_gc (window, style->fg_gc[GTK_STATE_NORMAL],
4630 line_width, FALSE, points, 3);
4634 gtk_style_draw_polygon_with_gc (window, style->base_gc[GTK_STATE_NORMAL],
4635 1, TRUE, points, 3);
4636 gtk_style_draw_polygon_with_gc (window, style->fg_gc[GTK_STATE_NORMAL],
4637 line_width, FALSE, points, 3);
4641 gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], NULL);
4642 gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], NULL);
4646 typedef struct _ByteRange ByteRange;
4655 range_new (guint start,
4658 ByteRange *br = g_new (ByteRange, 1);
4667 get_insensitive_layout (GdkDrawable *drawable,
4668 PangoLayout *layout)
4670 GSList *embossed_ranges = NULL;
4671 GSList *stippled_ranges = NULL;
4672 PangoLayoutIter *iter;
4673 GSList *tmp_list = NULL;
4674 PangoLayout *new_layout;
4675 PangoAttrList *attrs;
4676 GdkBitmap *stipple = NULL;
4678 iter = pango_layout_get_iter (layout);
4682 PangoLayoutRun *run;
4683 PangoAttribute *attr;
4684 gboolean need_stipple = FALSE;
4687 run = pango_layout_iter_get_run (iter);
4691 tmp_list = run->item->analysis.extra_attrs;
4693 while (tmp_list != NULL)
4695 attr = tmp_list->data;
4696 switch (attr->klass->type)
4698 case PANGO_ATTR_FOREGROUND:
4699 case PANGO_ATTR_BACKGROUND:
4700 need_stipple = TRUE;
4710 tmp_list = g_slist_next (tmp_list);
4713 br = range_new (run->item->offset, run->item->offset + run->item->length);
4716 stippled_ranges = g_slist_prepend (stippled_ranges, br);
4718 embossed_ranges = g_slist_prepend (embossed_ranges, br);
4721 while (pango_layout_iter_next_run (iter));
4723 pango_layout_iter_free (iter);
4725 new_layout = pango_layout_copy (layout);
4727 attrs = pango_layout_get_attributes (new_layout);
4731 /* Create attr list if there wasn't one */
4732 attrs = pango_attr_list_new ();
4733 pango_layout_set_attributes (new_layout, attrs);
4734 pango_attr_list_unref (attrs);
4737 tmp_list = embossed_ranges;
4738 while (tmp_list != NULL)
4740 PangoAttribute *attr;
4741 ByteRange *br = tmp_list->data;
4743 attr = gdk_pango_attr_embossed_new (TRUE);
4745 attr->start_index = br->start;
4746 attr->end_index = br->end;
4748 pango_attr_list_change (attrs, attr);
4752 tmp_list = g_slist_next (tmp_list);
4755 g_slist_free (embossed_ranges);
4757 tmp_list = stippled_ranges;
4758 while (tmp_list != NULL)
4760 PangoAttribute *attr;
4761 ByteRange *br = tmp_list->data;
4763 if (stipple == NULL)
4765 #define gray50_width 2
4766 #define gray50_height 2
4767 static char gray50_bits[] = {
4771 stipple = gdk_bitmap_create_from_data (drawable,
4772 gray50_bits, gray50_width,
4776 attr = gdk_pango_attr_stipple_new (stipple);
4778 attr->start_index = br->start;
4779 attr->end_index = br->end;
4781 pango_attr_list_change (attrs, attr);
4785 tmp_list = g_slist_next (tmp_list);
4788 g_slist_free (stippled_ranges);
4791 g_object_unref (G_OBJECT (stipple));
4797 gtk_default_draw_layout (GtkStyle *style,
4799 GtkStateType state_type,
4803 const gchar *detail,
4806 PangoLayout *layout)
4810 g_return_if_fail (GTK_IS_STYLE (style));
4811 g_return_if_fail (window != NULL);
4813 gc = use_text ? style->text_gc[state_type] : style->fg_gc[state_type];
4816 gdk_gc_set_clip_rectangle (gc, area);
4818 if (state_type == GTK_STATE_INSENSITIVE)
4822 ins = get_insensitive_layout (window, layout);
4824 gdk_draw_layout (window, gc, x, y, ins);
4826 g_object_unref (G_OBJECT (ins));
4830 gdk_draw_layout (window, gc, x, y, layout);
4834 gdk_gc_set_clip_rectangle (gc, NULL);
4838 gtk_default_draw_resize_grip (GtkStyle *style,
4840 GtkStateType state_type,
4843 const gchar *detail,
4850 g_return_if_fail (GTK_IS_STYLE (style));
4851 g_return_if_fail (window != NULL);
4855 gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
4856 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
4857 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
4860 /* make it square, aligning to bottom right */
4863 y += (height - width);
4866 else if (height < width)
4868 x += (width - height);
4872 /* Clear background */
4873 gtk_style_apply_default_background (style, window, FALSE,
4875 x, y, width, height);
4879 case GDK_WINDOW_EDGE_SOUTH_EAST:
4886 while (xi < (x + width - 3))
4888 gdk_draw_line (window,
4889 style->light_gc[state_type],
4896 gdk_draw_line (window,
4897 style->dark_gc[state_type],
4904 gdk_draw_line (window,
4905 style->dark_gc[state_type],
4915 g_assert_not_reached ();
4921 gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
4922 gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
4923 gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
4928 gtk_style_shade (GdkColor *a,
4936 red = (gdouble) a->red / 65535.0;
4937 green = (gdouble) a->green / 65535.0;
4938 blue = (gdouble) a->blue / 65535.0;
4940 rgb_to_hls (&red, &green, &blue);
4945 else if (green < 0.0)
4951 else if (blue < 0.0)
4954 hls_to_rgb (&red, &green, &blue);
4956 b->red = red * 65535.0;
4957 b->green = green * 65535.0;
4958 b->blue = blue * 65535.0;
4962 rgb_to_hls (gdouble *r,
5003 l = (max + min) / 2;
5010 s = (max - min) / (max + min);
5012 s = (max - min) / (2 - max - min);
5016 h = (green - blue) / delta;
5017 else if (green == max)
5018 h = 2 + (blue - red) / delta;
5019 else if (blue == max)
5020 h = 4 + (red - green) / delta;
5033 hls_to_rgb (gdouble *h,
5046 if (lightness <= 0.5)
5047 m2 = lightness * (1 + saturation);
5049 m2 = lightness + saturation - lightness * saturation;
5050 m1 = 2 * lightness - m2;
5052 if (saturation == 0)
5067 r = m1 + (m2 - m1) * hue / 60;
5071 r = m1 + (m2 - m1) * (240 - hue) / 60;
5082 g = m1 + (m2 - m1) * hue / 60;
5086 g = m1 + (m2 - m1) * (240 - hue) / 60;
5097 b = m1 + (m2 - m1) * hue / 60;
5101 b = m1 + (m2 - m1) * (240 - hue) / 60;
5114 * @style: a #GtkStyle
5115 * @window: a #GdkWindow
5116 * @state_type: a state
5117 * @area: rectangle to which the output is clipped
5120 * @x1: the starting x coordinate
5121 * @x2: the ending x coordinate
5122 * @y: the y coordinate
5124 * Draws a horizontal line from (@x1, @y) to (@x2, @y) in @window
5125 * using the given style and state.
5128 gtk_paint_hline (GtkStyle *style,
5130 GtkStateType state_type,
5133 const gchar *detail,
5138 g_return_if_fail (GTK_IS_STYLE (style));
5139 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
5141 GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, area, widget, detail, x1, x2, y);
5146 * @style: a #GtkStyle
5147 * @window: a #GdkWindow
5148 * @state_type: a state
5149 * @area: rectangle to which the output is clipped
5152 * @y1: the starting y coordinate
5153 * @y2: the ending y coordinate
5154 * @x: the x coordinate
5156 * Draws a vertical line from (@x, @y1) to (@x, @y1) in @window
5157 * using the given style and state.
5160 gtk_paint_vline (GtkStyle *style,
5162 GtkStateType state_type,
5165 const gchar *detail,
5170 g_return_if_fail (GTK_IS_STYLE (style));
5171 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
5173 GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, area, widget, detail, y1, y2, x);
5177 gtk_paint_shadow (GtkStyle *style,
5179 GtkStateType state_type,
5180 GtkShadowType shadow_type,
5183 const gchar *detail,
5189 g_return_if_fail (GTK_IS_STYLE (style));
5190 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
5192 GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5196 gtk_paint_polygon (GtkStyle *style,
5198 GtkStateType state_type,
5199 GtkShadowType shadow_type,
5202 const gchar *detail,
5207 g_return_if_fail (GTK_IS_STYLE (style));
5208 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
5210 GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, area, widget, detail, points, npoints, fill);
5214 gtk_paint_arrow (GtkStyle *style,
5216 GtkStateType state_type,
5217 GtkShadowType shadow_type,
5220 const gchar *detail,
5221 GtkArrowType arrow_type,
5228 g_return_if_fail (GTK_IS_STYLE (style));
5229 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
5231 GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, area, widget, detail, arrow_type, fill, x, y, width, height);
5235 gtk_paint_diamond (GtkStyle *style,
5237 GtkStateType state_type,
5238 GtkShadowType shadow_type,
5241 const gchar *detail,
5247 g_return_if_fail (GTK_IS_STYLE (style));
5248 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
5250 GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5255 * @style: a #GtkStyle
5256 * @window: a #GdkWindow
5257 * @state_type: a state
5258 * @area: clip rectangle
5259 * @widget: the widget
5260 * @detail: a style detail
5263 * @string: the string to draw
5265 * Draws a text string on @window with the given parameters.
5267 * This function is deprecated, use gtk_paint_layout() instead.
5270 gtk_paint_string (GtkStyle *style,
5272 GtkStateType state_type,
5275 const gchar *detail,
5278 const gchar *string)
5280 g_return_if_fail (GTK_IS_STYLE (style));
5281 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
5283 GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, area, widget, detail, x, y, string);
5287 gtk_paint_box (GtkStyle *style,
5289 GtkStateType state_type,
5290 GtkShadowType shadow_type,
5293 const gchar *detail,
5299 g_return_if_fail (GTK_IS_STYLE (style));
5300 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box != NULL);
5302 GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5306 gtk_paint_flat_box (GtkStyle *style,
5308 GtkStateType state_type,
5309 GtkShadowType shadow_type,
5312 const gchar *detail,
5318 g_return_if_fail (GTK_IS_STYLE (style));
5319 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_flat_box != NULL);
5321 GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5325 gtk_paint_check (GtkStyle *style,
5327 GtkStateType state_type,
5328 GtkShadowType shadow_type,
5331 const gchar *detail,
5337 g_return_if_fail (GTK_IS_STYLE (style));
5338 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
5340 GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5344 gtk_paint_option (GtkStyle *style,
5346 GtkStateType state_type,
5347 GtkShadowType shadow_type,
5350 const gchar *detail,
5356 g_return_if_fail (GTK_IS_STYLE (style));
5357 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
5359 GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5363 gtk_paint_tab (GtkStyle *style,
5365 GtkStateType state_type,
5366 GtkShadowType shadow_type,
5369 const gchar *detail,
5375 g_return_if_fail (GTK_IS_STYLE (style));
5376 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
5378 GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
5382 gtk_paint_shadow_gap (GtkStyle *style,
5384 GtkStateType state_type,
5385 GtkShadowType shadow_type,
5393 GtkPositionType gap_side,
5397 g_return_if_fail (GTK_IS_STYLE (style));
5398 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
5400 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);
5405 gtk_paint_box_gap (GtkStyle *style,
5407 GtkStateType state_type,
5408 GtkShadowType shadow_type,
5416 GtkPositionType gap_side,
5420 g_return_if_fail (GTK_IS_STYLE (style));
5421 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
5423 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);
5427 gtk_paint_extension (GtkStyle *style,
5429 GtkStateType state_type,
5430 GtkShadowType shadow_type,
5438 GtkPositionType gap_side)
5440 g_return_if_fail (GTK_IS_STYLE (style));
5441 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
5443 GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side);
5447 gtk_paint_focus (GtkStyle *style,
5449 GtkStateType state_type,
5452 const gchar *detail,
5458 g_return_if_fail (GTK_IS_STYLE (style));
5459 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
5461 GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, state_type, area, widget, detail, x, y, width, height);
5465 gtk_paint_slider (GtkStyle *style,
5467 GtkStateType state_type,
5468 GtkShadowType shadow_type,
5471 const gchar *detail,
5476 GtkOrientation orientation)
5478 g_return_if_fail (GTK_IS_STYLE (style));
5479 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
5481 GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
5485 gtk_paint_handle (GtkStyle *style,
5487 GtkStateType state_type,
5488 GtkShadowType shadow_type,
5491 const gchar *detail,
5496 GtkOrientation orientation)
5498 g_return_if_fail (GTK_IS_STYLE (style));
5499 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
5501 GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
5505 gtk_paint_expander (GtkStyle *style,
5507 GtkStateType state_type,
5510 const gchar *detail,
5513 GtkExpanderStyle expander_style)
5515 g_return_if_fail (GTK_IS_STYLE (style));
5516 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
5518 GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type, area,
5519 widget, detail, x, y, expander_style);
5523 gtk_paint_layout (GtkStyle *style,
5525 GtkStateType state_type,
5529 const gchar *detail,
5532 PangoLayout *layout)
5534 g_return_if_fail (GTK_IS_STYLE (style));
5535 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
5537 GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text, area,
5538 widget, detail, x, y, layout);
5542 gtk_paint_resize_grip (GtkStyle *style,
5544 GtkStateType state_type,
5547 const gchar *detail,
5555 g_return_if_fail (GTK_IS_STYLE (style));
5556 g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);
5558 GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
5559 area, widget, detail,
5560 edge, x, y, width, height);
5565 * @border: a #GtkBorder.
5566 * @returns: a copy of @border.
5568 * Copies a #GtkBorder structure.
5571 gtk_border_copy (const GtkBorder *border)
5573 return (GtkBorder *)g_memdup (border, sizeof (GtkBorder));
5578 * @border: a #GtkBorder.
5580 * Frees a #GtkBorder structure.
5583 gtk_border_free (GtkBorder *border)
5589 gtk_border_get_type (void)
5591 static GType our_type = 0;
5594 our_type = g_boxed_type_register_static ("GtkTypeBorder",
5595 (GBoxedCopyFunc) gtk_border_copy,
5596 (GBoxedFreeFunc) gtk_border_free);
5602 * gtk_style_get_font_for_display:
5603 * @display : a #GdkDisplay
5604 * @style: a #GtkStyle
5606 * Gets the #GdkFont to use for the given style. This is
5607 * meant only as a replacement for direct access to style->font
5608 * and should not be used in new code. New code should
5609 * use style->font_desc instead.
5611 * Return value: the #GdkFont for the style. This font is owned
5612 * by the style; if you want to keep around a copy, you must
5613 * call gdk_font_ref().
5616 gtk_style_get_font_for_display (GdkDisplay *display,
5619 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
5620 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
5622 if (style->private_font && style->private_font_desc)
5624 if (!style->font_desc ||
5625 !pango_font_description_equal (style->private_font_desc, style->font_desc))
5627 gdk_font_unref (style->private_font);
5628 style->private_font = NULL;
5630 if (style->private_font_desc)
5632 pango_font_description_free (style->private_font_desc);
5633 style->private_font_desc = NULL;
5638 if (!style->private_font)
5640 if (style->font_desc)
5642 /* no colormap, no screen */
5643 style->private_font = gdk_font_from_description_for_display (display, style->font_desc);
5644 style->private_font_desc = pango_font_description_copy (style->font_desc);
5647 if (!style->private_font)
5648 style->private_font = gdk_font_load_for_display (display, "fixed");
5650 if (!style->private_font)
5651 g_error ("Unable to load \"fixed\" font");
5654 return style->private_font;
5658 * gtk_style_get_font:
5659 * @style: a #GtkStyle
5661 * Gets the #GdkFont to use for the given style. This is
5662 * meant only as a replacement for direct access to @style->font
5663 * and should not be used in new code. New code should
5664 * use @style->font_desc instead.
5666 * Return value: the #GdkFont for the style. This font is owned
5667 * by the style; if you want to keep around a copy, you must
5668 * call gdk_font_ref().
5671 gtk_style_get_font (GtkStyle *style)
5673 g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
5675 return gtk_style_get_font_for_display (gdk_get_default_display (), style);
5679 * gtk_style_set_font:
5680 * @style: a #GtkStyle.
5681 * @font: a #GdkFont, or %NULL to use the #GdkFont corresponding
5682 * to style->font_desc.
5684 * Sets the #GdkFont to use for a given style. This is
5685 * meant only as a replacement for direct access to style->font
5686 * and should not be used in new code. New code should
5687 * use style->font_desc instead.
5690 gtk_style_set_font (GtkStyle *style,
5695 g_return_if_fail (GTK_IS_STYLE (style));
5697 old_font = style->private_font;
5699 style->private_font = font;
5701 gdk_font_ref (font);
5704 gdk_font_unref (old_font);
5706 if (style->private_font_desc)
5708 pango_font_description_free (style->private_font_desc);
5709 style->private_font_desc = NULL;
5713 typedef struct _CursorInfo CursorInfo;
5719 GdkGC *secondary_gc;
5723 style_unrealize_cursor_gcs (GtkStyle *style)
5727 cursor_info = g_object_get_data (G_OBJECT (style), "gtk-style-cursor-info");
5730 if (cursor_info->primary_gc)
5731 gtk_gc_release (cursor_info->primary_gc);
5733 if (cursor_info->secondary_gc)
5734 gtk_gc_release (cursor_info->secondary_gc);
5736 g_free (cursor_info);
5737 g_object_set_data (G_OBJECT (style), "gtk-style-cursor-info", NULL);
5742 make_cursor_gc (GtkWidget *widget,
5743 const gchar *property_name,
5746 GdkGCValues gc_values;
5747 GdkGCValuesMask gc_values_mask;
5748 GdkColor *cursor_color;
5750 gtk_widget_style_get (widget, property_name, &cursor_color, NULL);
5752 gc_values_mask = GDK_GC_FOREGROUND;
5755 gc_values.foreground = *cursor_color;
5756 gdk_color_free (cursor_color);
5759 gc_values.foreground = *fallback;
5761 gdk_rgb_find_color (widget->style->colormap, &gc_values.foreground);
5762 return gtk_gc_get (widget->style->depth, widget->style->colormap, &gc_values, gc_values_mask);
5766 * _gtk_get_insertion_cursor_gc:
5767 * @widget: a #GtkWidget
5768 * @is_primary: if the cursor should be the primary cursor color.
5770 * Get a GC suitable for drawing the primary or secondary text
5773 * Note: the return value is ref'ed because calls to this function
5774 * on other widgets could result in this the GC being released
5775 * which would be an unexpected side effect. If made public,
5776 * this function should possibly be called create_insertion_cursor_gc().
5778 * Return value: an appropriate #GdkGC. Call g_object_unref() on
5779 * the gc when you are done with it; this GC may be shared with
5780 * other users, so you must not modify the GC except for temporarily
5781 * setting the clip before drawing with the GC, and then unsetting the clip
5785 _gtk_get_insertion_cursor_gc (GtkWidget *widget,
5786 gboolean is_primary)
5788 CursorInfo *cursor_info;
5790 cursor_info = g_object_get_data (G_OBJECT (widget->style), "gtk-style-cursor-info");
5793 cursor_info = g_new (CursorInfo, 1);
5794 g_object_set_data (G_OBJECT (widget->style), "gtk-style-cursor-info", cursor_info);
5795 cursor_info->primary_gc = NULL;
5796 cursor_info->secondary_gc = NULL;
5797 cursor_info->for_type = G_TYPE_INVALID;
5800 /* We have to keep track of the type because gtk_widget_style_get()
5801 * can return different results when called on the same property and
5802 * same style but for different widgets. :-(. That is,
5803 * GtkEntry::cursor-color = "red" in a style will modify the cursor
5804 * color for entries but not for text view.
5806 if (cursor_info->for_type != G_OBJECT_TYPE (widget))
5808 cursor_info->for_type = G_OBJECT_TYPE (widget);
5809 if (cursor_info->primary_gc)
5811 gtk_gc_release (cursor_info->primary_gc);
5812 cursor_info->primary_gc = NULL;
5814 if (cursor_info->secondary_gc)
5816 gtk_gc_release (cursor_info->secondary_gc);
5817 cursor_info->secondary_gc = NULL;
5823 if (!cursor_info->primary_gc)
5824 cursor_info->primary_gc = make_cursor_gc (widget,
5826 &widget->style->black);
5828 return g_object_ref (cursor_info->primary_gc);
5832 static GdkColor gray = { 0, 0x8888, 0x8888, 0x8888 };
5834 if (!cursor_info->secondary_gc)
5835 cursor_info->secondary_gc = make_cursor_gc (widget,
5836 "secondary-cursor-color",
5839 return g_object_ref (cursor_info->secondary_gc);
5844 * _gtk_draw_insertion_cursor:
5845 * @widget: a #GtkWidget
5846 * @drawable: a #GdkDrawable
5848 * @location: location where to draw the cursor (@location->width is ignored)
5849 * @direction: whether the cursor is left-to-right or
5850 * right-to-left. Should never be #GTK_TEXT_DIR_NONE
5851 * @draw_arrow: %TRUE to draw a directional arrow on the
5852 * cursor. Should be %FALSE unless the cursor is split.
5854 * Draws a text caret on @drawable at @location. This is not a style function
5855 * but merely a convenience function for drawing the standard cursor shape.
5858 _gtk_draw_insertion_cursor (GtkWidget *widget,
5859 GdkDrawable *drawable,
5861 GdkRectangle *location,
5862 GtkTextDirection direction,
5863 gboolean draw_arrow)
5869 gfloat cursor_aspect_ratio;
5872 g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
5874 gtk_widget_style_get (widget, "cursor-aspect-ratio", &cursor_aspect_ratio, NULL);
5876 stem_width = location->height * cursor_aspect_ratio + 1;
5877 arrow_width = stem_width + 1;
5879 /* put (stem_width % 2) on the proper side of the cursor */
5880 if (direction == GTK_TEXT_DIR_LTR)
5881 offset = stem_width / 2;
5883 offset = stem_width - stem_width / 2;
5885 for (i = 0; i < stem_width; i++)
5886 gdk_draw_line (drawable, gc,
5887 location->x + i - offset, location->y,
5888 location->x + i - offset, location->y + location->height - 1);
5892 if (direction == GTK_TEXT_DIR_RTL)
5894 x = location->x - offset - 1;
5895 y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
5897 for (i = 0; i < arrow_width; i++)
5899 gdk_draw_line (drawable, gc,
5901 x, y + 2 * arrow_width - i - 1);
5905 else if (direction == GTK_TEXT_DIR_LTR)
5907 x = location->x + stem_width - offset;
5908 y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
5910 for (i = 0; i < arrow_width; i++)
5912 gdk_draw_line (drawable, gc,
5914 x, y + 2 * arrow_width - i - 1);