1 /* gtktexttag.c - text tag object
3 * Copyright (c) 1992-1994 The Regents of the University of California.
4 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
5 * Copyright (c) 2000 Red Hat, Inc.
6 * Tk -> Gtk port by Havoc Pennington <hp@redhat.com>
8 * This software is copyrighted by the Regents of the University of
9 * California, Sun Microsystems, Inc., and other parties. The
10 * following terms apply to all files associated with the software
11 * unless explicitly disclaimed in individual files.
13 * The authors hereby grant permission to use, copy, modify,
14 * distribute, and license this software and its documentation for any
15 * purpose, provided that existing copyright notices are retained in
16 * all copies and that this notice is included verbatim in any
17 * distributions. No written agreement, license, or royalty fee is
18 * required for any of the authorized uses. Modifications to this
19 * software may be copyrighted by their authors and need not follow
20 * the licensing terms described here, provided that the new terms are
21 * clearly indicated on the first page of each file where they apply.
23 * IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY
24 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
25 * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION,
26 * OR ANY DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED
27 * OF THE POSSIBILITY OF SUCH DAMAGE.
29 * THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
30 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
31 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
32 * NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS,
33 * AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
34 * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
36 * GOVERNMENT USE: If you are acquiring this software on behalf of the
37 * U.S. government, the Government shall have only "Restricted Rights"
38 * in the software and related documentation as defined in the Federal
39 * Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you
40 * are acquiring the software on behalf of the Department of Defense,
41 * the software shall be classified as "Commercial Computer Software"
42 * and the Government shall have only "Restricted Rights" as defined
43 * in Clause 252.227-7013 (c) (1) of DFARs. Notwithstanding the
44 * foregoing, the authors grant the U.S. Government and others acting
45 * in its behalf permission to use and distribute the software in
46 * accordance with the terms specified in this license.
51 #include "gtktexttag.h"
52 #include "gtktexttypes.h"
53 #include "gtktexttagtable.h"
54 #include "gtksignal.h"
57 #include "gtktypebuiltins.h"
77 PROP_BACKGROUND_STIPPLE,
78 PROP_FOREGROUND_STIPPLE,
88 PROP_PIXELS_ABOVE_LINES,
89 PROP_PIXELS_BELOW_LINES,
90 PROP_PIXELS_INSIDE_WRAP,
106 /* Whether-a-style-arg-is-set args */
109 PROP_BACKGROUND_STIPPLE_SET,
110 PROP_FOREGROUND_STIPPLE_SET,
117 PROP_PIXELS_ABOVE_LINES_SET,
118 PROP_PIXELS_BELOW_LINES_SET,
119 PROP_PIXELS_INSIDE_WRAP_SET,
122 PROP_JUSTIFICATION_SET,
123 PROP_LEFT_MARGIN_SET,
125 PROP_STRIKETHROUGH_SET,
126 PROP_RIGHT_MARGIN_SET,
129 PROP_BG_FULL_HEIGHT_SET,
136 static void gtk_text_tag_init (GtkTextTag *text_tag);
137 static void gtk_text_tag_class_init (GtkTextTagClass *klass);
138 static void gtk_text_tag_finalize (GObject *object);
139 static void gtk_text_tag_set_property (GObject *object,
143 const gchar *trailer);
144 static void gtk_text_tag_get_property (GObject *object,
148 const gchar *trailer);
150 static GObjectClass *parent_class = NULL;
151 static guint signals[LAST_SIGNAL] = { 0 };
154 gtk_text_tag_get_type (void)
156 static GType our_type = 0;
160 static const GTypeInfo our_info =
162 sizeof (GtkTextTagClass),
163 (GBaseInitFunc) NULL,
164 (GBaseFinalizeFunc) NULL,
165 (GClassInitFunc) gtk_text_tag_class_init,
166 NULL, /* class_finalize */
167 NULL, /* class_data */
170 (GInstanceInitFunc) gtk_text_tag_init
173 our_type = g_type_register_static (G_TYPE_OBJECT,
183 gtk_text_tag_class_init (GtkTextTagClass *klass)
185 GObjectClass *object_class = G_OBJECT_CLASS (klass);
187 parent_class = g_type_class_peek_parent (klass);
189 object_class->set_property = gtk_text_tag_set_property;
190 object_class->get_property = gtk_text_tag_get_property;
192 object_class->finalize = gtk_text_tag_finalize;
195 g_object_class_install_property (object_class,
197 g_param_spec_string ("name",
199 _("Name used to refer to the text tag"),
201 G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
205 g_object_class_install_property (object_class,
207 g_param_spec_string ("background",
208 _("Background color name"),
209 _("Background color as a string"),
213 g_object_class_install_property (object_class,
215 g_param_spec_boxed ("background_gdk",
216 _("Background color"),
217 _("Background color as a GdkColor"),
219 G_PARAM_READABLE | G_PARAM_WRITABLE));
221 g_object_class_install_property (object_class,
223 g_param_spec_boolean ("background_full_height",
224 _("Background full height"),
225 _("Whether the background color fills the entire line height or only the height of the tagged characters"),
227 G_PARAM_READABLE | G_PARAM_WRITABLE));
230 g_object_class_install_property (object_class,
231 PROP_BACKGROUND_STIPPLE,
232 g_param_spec_object ("background_stipple",
233 _("Background stipple mask"),
234 _("Bitmap to use as a mask when drawing the text background"),
236 G_PARAM_READABLE | G_PARAM_WRITABLE));
239 g_object_class_install_property (object_class,
241 g_param_spec_string ("foreground",
242 _("Foreground color name"),
243 _("Foreground color as a string"),
247 g_object_class_install_property (object_class,
249 g_param_spec_boxed ("foreground_gdk",
250 _("Foreground color"),
251 _("Foreground color as a GdkColor"),
253 G_PARAM_READABLE | G_PARAM_WRITABLE));
256 g_object_class_install_property (object_class,
257 PROP_FOREGROUND_STIPPLE,
258 g_param_spec_object ("foreground_stipple",
259 _("Foreground stipple mask"),
260 _("Bitmap to use as a mask when drawing the text foreground"),
262 G_PARAM_READABLE | G_PARAM_WRITABLE));
264 g_object_class_install_property (object_class,
266 g_param_spec_enum ("direction",
268 _("Text direction, e.g. right-to-left or left-to-right"),
269 GTK_TYPE_TEXT_DIRECTION,
271 G_PARAM_READABLE | G_PARAM_WRITABLE));
273 g_object_class_install_property (object_class,
275 g_param_spec_boolean ("editable",
277 _("Whether the text can be modified by the user"),
279 G_PARAM_READABLE | G_PARAM_WRITABLE));
281 g_object_class_install_property (object_class,
283 g_param_spec_string ("font",
285 _("Font description as a string"),
287 G_PARAM_READABLE | G_PARAM_WRITABLE));
289 g_object_class_install_property (object_class,
291 g_param_spec_boxed ("font_desc",
293 _("Font description as a PangoFontDescription struct"),
294 GTK_TYPE_PANGO_FONT_DESCRIPTION,
295 G_PARAM_READABLE | G_PARAM_WRITABLE));
298 g_object_class_install_property (object_class,
300 g_param_spec_string ("family",
302 _("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
304 G_PARAM_READABLE | G_PARAM_WRITABLE));
306 g_object_class_install_property (object_class,
308 g_param_spec_enum ("style",
313 G_PARAM_READABLE | G_PARAM_WRITABLE));
315 g_object_class_install_property (object_class,
317 g_param_spec_enum ("variant",
321 PANGO_VARIANT_NORMAL,
322 G_PARAM_READABLE | G_PARAM_WRITABLE));
324 g_object_class_install_property (object_class,
326 g_param_spec_int ("weight",
332 G_PARAM_READABLE | G_PARAM_WRITABLE));
335 g_object_class_install_property (object_class,
337 g_param_spec_enum ("stretch",
341 PANGO_STRETCH_NORMAL,
342 G_PARAM_READABLE | G_PARAM_WRITABLE));
344 g_object_class_install_property (object_class,
346 g_param_spec_int ("size",
352 G_PARAM_READABLE | G_PARAM_WRITABLE));
354 g_object_class_install_property (object_class,
356 g_param_spec_double ("size_points",
358 _("Font size in points"),
362 G_PARAM_READABLE | G_PARAM_WRITABLE));
364 g_object_class_install_property (object_class,
366 g_param_spec_enum ("justification",
368 _("Left, right, or center justification"),
369 GTK_TYPE_JUSTIFICATION,
371 G_PARAM_READABLE | G_PARAM_WRITABLE));
373 g_object_class_install_property (object_class,
375 g_param_spec_string ("language",
377 _("Language engine code to use for rendering the text"),
379 G_PARAM_READABLE | G_PARAM_WRITABLE));
381 g_object_class_install_property (object_class,
383 g_param_spec_int ("left_margin",
385 _("Width of the left margin in pixels"),
389 G_PARAM_READABLE | G_PARAM_WRITABLE));
391 g_object_class_install_property (object_class,
393 g_param_spec_int ("right_margin",
395 _("Width of the right margin in pixels"),
399 G_PARAM_READABLE | G_PARAM_WRITABLE));
402 g_object_class_install_property (object_class,
404 g_param_spec_int ("indent",
406 _("Amount to indent the paragraph, in pixels"),
410 G_PARAM_READABLE | G_PARAM_WRITABLE));
413 g_object_class_install_property (object_class,
415 g_param_spec_int ("rise",
417 _("Offset of text above the baseline (below the baseline if rise is negative)"),
421 G_PARAM_READABLE | G_PARAM_WRITABLE));
423 g_object_class_install_property (object_class,
424 PROP_PIXELS_ABOVE_LINES,
425 g_param_spec_int ("pixels_above_lines",
426 _("Pixels above lines"),
427 _("Pixels of blank space above paragraphs"),
431 G_PARAM_READABLE | G_PARAM_WRITABLE));
433 g_object_class_install_property (object_class,
434 PROP_PIXELS_BELOW_LINES,
435 g_param_spec_int ("pixels_below_lines",
436 _("Pixels below lines"),
437 _("Pixels of blank space below paragraphs"),
441 G_PARAM_READABLE | G_PARAM_WRITABLE));
443 g_object_class_install_property (object_class,
444 PROP_PIXELS_INSIDE_WRAP,
445 g_param_spec_int ("pixels_inside_wrap",
446 _("Pixels inside wrap"),
447 _("Pixels of blank space between wrapped lines in a paragraph"),
451 G_PARAM_READABLE | G_PARAM_WRITABLE));
453 g_object_class_install_property (object_class,
455 g_param_spec_boolean ("strikethrough",
457 _("Whether to strike through the text"),
459 G_PARAM_READABLE | G_PARAM_WRITABLE));
461 g_object_class_install_property (object_class,
463 g_param_spec_enum ("underline",
465 _("Style of underline for this text"),
466 PANGO_TYPE_UNDERLINE,
467 PANGO_UNDERLINE_NONE,
468 G_PARAM_READABLE | G_PARAM_WRITABLE));
470 g_object_class_install_property (object_class,
472 g_param_spec_enum ("wrap_mode",
474 _("Whether to wrap lines never, at word boundaries, or at character boundaries"),
477 G_PARAM_READABLE | G_PARAM_WRITABLE));
480 g_object_class_install_property (object_class,
482 g_param_spec_boxed ("tabs",
484 _("Custom tabs for this text"),
485 GTK_TYPE_PANGO_TAB_ARRAY,
486 G_PARAM_READABLE | G_PARAM_WRITABLE));
488 g_object_class_install_property (object_class,
490 g_param_spec_boolean ("invisible",
492 _("Whether this text is hidden"),
494 G_PARAM_READABLE | G_PARAM_WRITABLE));
496 /* Style props are set or not */
498 #define ADD_SET_PROP(propname, propval, nick, blurb) g_object_class_install_property (object_class, propval, g_param_spec_boolean (propname, nick, blurb, FALSE, G_PARAM_READABLE | G_PARAM_WRITABLE))
500 ADD_SET_PROP ("background_set", PROP_BACKGROUND_SET,
502 _("Whether this tag affects the background color"));
504 ADD_SET_PROP ("background_full_height_set", PROP_BG_FULL_HEIGHT_SET,
505 _("Background full height set"),
506 _("Whether this tag affects background height"));
508 ADD_SET_PROP ("background_stipple_set", PROP_BACKGROUND_STIPPLE_SET,
509 _("Background stipple set"),
510 _("Whether this tag affects the background stipple"));
512 ADD_SET_PROP ("foreground_set", PROP_FOREGROUND_SET,
514 _("Whether this tag affects the foreground color"));
516 ADD_SET_PROP ("foreground_stipple_set", PROP_FOREGROUND_STIPPLE_SET,
517 _("Foreground stipple set"),
518 _("Whether this tag affects the foreground stipple"));
520 ADD_SET_PROP ("editable_set", PROP_EDITABLE_SET,
521 _("Editability set"),
522 _("Whether this tag affects text editability"));
524 ADD_SET_PROP ("family_set", PROP_FAMILY_SET,
525 _("Font family set"),
526 _("Whether this tag affects the font family"));
528 ADD_SET_PROP ("style_set", PROP_STYLE_SET,
530 _("Whether this tag affects the font style"));
532 ADD_SET_PROP ("variant_set", PROP_VARIANT_SET,
533 _("Font variant set"),
534 _("Whether this tag affects the font variant"));
536 ADD_SET_PROP ("weight_set", PROP_WEIGHT_SET,
537 _("Font weight set"),
538 _("Whether this tag affects the font weight"));
540 ADD_SET_PROP ("stretch_set", PROP_STRETCH_SET,
541 _("Font stretch set"),
542 _("Whether this tag affects the font stretch"));
544 ADD_SET_PROP ("size_set", PROP_SIZE_SET,
546 _("Whether this tag affects the font size"));
548 ADD_SET_PROP ("justification_set", PROP_JUSTIFICATION_SET,
549 _("Justification set"),
550 _("Whether this tag affects paragraph justification"));
552 ADD_SET_PROP ("language_set", PROP_LANGUAGE_SET,
554 _("Whether this tag affects the language the text is rendered as"));
556 ADD_SET_PROP ("left_margin_set", PROP_LEFT_MARGIN_SET,
557 _("Left margin set"),
558 _("Whether this tag affects the left margin"));
560 ADD_SET_PROP ("indent_set", PROP_INDENT_SET,
562 _("Whether this tag affects indentation"));
564 ADD_SET_PROP ("rise_set", PROP_RISE_SET,
566 _("Whether this tag affects the rise"));
568 ADD_SET_PROP ("pixels_above_lines_set", PROP_PIXELS_ABOVE_LINES_SET,
569 _("Pixels above lines set"),
570 _("Whether this tag affects the number of pixels above lines"));
572 ADD_SET_PROP ("pixels_below_lines_set", PROP_PIXELS_BELOW_LINES_SET,
573 _("Pixels below lines set"),
574 _("Whether this tag affects the number of pixels above lines"));
576 ADD_SET_PROP ("pixels_inside_wrap_set", PROP_PIXELS_INSIDE_WRAP_SET,
577 _("Pixels inside wrap set"),
578 _("Whether this tag affects the number of pixels between wrapped lines"));
580 ADD_SET_PROP ("strikethrough_set", PROP_STRIKETHROUGH_SET,
581 _("Strikethrough set"),
582 _("Whether this tag affects strikethrough"));
584 ADD_SET_PROP ("right_margin_set", PROP_RIGHT_MARGIN_SET,
585 _("Right margin set"),
586 _("Whether this tag affects the right margin"));
588 ADD_SET_PROP ("underline_set", PROP_UNDERLINE_SET,
590 _("Whether this tag affects underlining"));
592 ADD_SET_PROP ("wrap_mode_set", PROP_WRAP_MODE_SET,
594 _("Whether this tag affects line wrap mode"));
596 ADD_SET_PROP ("tabs_set", PROP_TABS_SET,
598 _("Whether this tag affects tabs"));
600 ADD_SET_PROP ("invisible_set", PROP_INVISIBLE_SET,
602 _("Whether this tag affects text visibility"));
605 g_signal_newc ("event",
606 G_TYPE_FROM_CLASS (object_class),
608 GTK_SIGNAL_OFFSET (GtkTextTagClass, event),
610 gtk_marshal_INT__OBJECT_BOXED_BOXED,
619 gtk_text_tag_init (GtkTextTag *text_tag)
621 /* 0 is basically a fine way to initialize everything in the
624 text_tag->values = gtk_text_attributes_new ();
629 * @name: tag name, or %NULL
631 * Creates a #GtkTextTag. Configure the tag using object arguments,
632 * i.e. using g_object_set().
634 * Return value: a new #GtkTextTag
637 gtk_text_tag_new (const gchar *name)
641 tag = GTK_TEXT_TAG (g_object_new (gtk_text_tag_get_type (),
649 gtk_text_tag_finalize (GObject *object)
651 GtkTextTag *text_tag;
653 text_tag = GTK_TEXT_TAG (object);
655 g_assert (!text_tag->values->realized);
658 gtk_text_tag_table_remove (text_tag->table, text_tag);
660 g_assert (text_tag->table == NULL);
662 gtk_text_attributes_unref (text_tag->values);
663 text_tag->values = NULL;
665 g_free (text_tag->name);
666 text_tag->name = NULL;
668 (* G_OBJECT_CLASS (parent_class)->finalize) (object);
672 set_bg_color (GtkTextTag *tag, GdkColor *color)
676 if (!tag->bg_color_set)
678 tag->bg_color_set = TRUE;
679 g_object_notify (G_OBJECT (tag), "background_set");
682 tag->values->appearance.bg_color = *color;
686 if (tag->bg_color_set)
688 tag->bg_color_set = FALSE;
689 g_object_notify (G_OBJECT (tag), "background_set");
695 set_fg_color (GtkTextTag *tag, GdkColor *color)
699 if (!tag->fg_color_set)
701 tag->fg_color_set = TRUE;
702 g_object_notify (G_OBJECT (tag), "foreground_set");
704 tag->values->appearance.fg_color = *color;
708 if (tag->fg_color_set)
710 tag->fg_color_set = FALSE;
711 g_object_notify (G_OBJECT (tag), "foreground_set");
717 set_font_description (GtkTextTag *text_tag,
718 PangoFontDescription *font_desc)
720 if (font_desc != NULL)
722 /* pango_font_description_from_string() will sometimes return
723 * a NULL family or -1 size, so handle those cases.
726 if (font_desc->family_name)
727 g_object_set (G_OBJECT (text_tag),
728 "family", font_desc->family_name,
731 if (font_desc->size >= 0)
732 g_object_set (G_OBJECT (text_tag),
733 "size", font_desc->size,
736 g_object_set (G_OBJECT (text_tag),
737 "style", font_desc->style,
738 "variant", font_desc->variant,
739 "weight", font_desc->weight,
740 "stretch", font_desc->stretch,
745 if (text_tag->family_set)
747 text_tag->family_set = FALSE;
748 g_object_notify (G_OBJECT (text_tag), "family_set");
750 if (text_tag->style_set)
752 text_tag->style_set = FALSE;
753 g_object_notify (G_OBJECT (text_tag), "style_set");
755 if (text_tag->variant_set)
757 text_tag->variant_set = FALSE;
758 g_object_notify (G_OBJECT (text_tag), "variant_set");
760 if (text_tag->weight_set)
762 text_tag->weight_set = FALSE;
763 g_object_notify (G_OBJECT (text_tag), "weight_set");
765 if (text_tag->stretch_set)
767 text_tag->stretch_set = FALSE;
768 g_object_notify (G_OBJECT (text_tag), "stretch_set");
770 if (text_tag->size_set)
772 text_tag->size_set = FALSE;
773 g_object_notify (G_OBJECT (text_tag), "size_set");
779 gtk_text_tag_set_property (GObject *object,
783 const gchar *trailer)
785 GtkTextTag *text_tag;
786 gboolean size_changed = FALSE;
788 text_tag = GTK_TEXT_TAG (object);
790 g_return_if_fail (!text_tag->values->realized);
795 g_return_if_fail (text_tag->name == NULL);
796 text_tag->name = g_strdup (g_value_get_string (value));
799 case PROP_BACKGROUND:
803 if (gdk_color_parse (g_value_get_string (value), &color))
804 set_bg_color (text_tag, &color);
806 g_warning ("Don't know color `%s'", g_value_get_string (value));
808 g_object_notify (G_OBJECT (text_tag), "background_gdk");
812 case PROP_FOREGROUND:
816 if (gdk_color_parse (g_value_get_string (value), &color))
817 set_fg_color (text_tag, &color);
819 g_warning ("Don't know color `%s'", g_value_get_string (value));
821 g_object_notify (G_OBJECT (text_tag), "foreground_gdk");
825 case PROP_BACKGROUND_GDK:
827 GdkColor *color = g_value_get_as_pointer (value);
828 set_bg_color (text_tag, color);
832 case PROP_FOREGROUND_GDK:
834 GdkColor *color = g_value_get_as_pointer (value);
835 set_fg_color (text_tag, color);
839 case PROP_BACKGROUND_STIPPLE:
841 GdkBitmap *bitmap = g_value_get_as_pointer (value);
843 text_tag->bg_stipple_set = TRUE;
844 g_object_notify (G_OBJECT (text_tag), "background_stipple_set");
846 if (text_tag->values->appearance.bg_stipple != bitmap)
849 gdk_bitmap_ref (bitmap);
851 if (text_tag->values->appearance.bg_stipple)
852 gdk_bitmap_unref (text_tag->values->appearance.bg_stipple);
854 text_tag->values->appearance.bg_stipple = bitmap;
859 case PROP_FOREGROUND_STIPPLE:
861 GdkBitmap *bitmap = g_value_get_as_pointer (value);
863 text_tag->fg_stipple_set = TRUE;
864 g_object_notify (G_OBJECT (text_tag), "foreground_stipple_set");
866 if (text_tag->values->appearance.fg_stipple != bitmap)
869 gdk_bitmap_ref (bitmap);
871 if (text_tag->values->appearance.fg_stipple)
872 gdk_bitmap_unref (text_tag->values->appearance.fg_stipple);
874 text_tag->values->appearance.fg_stipple = bitmap;
881 PangoFontDescription *font_desc = NULL;
884 name = g_value_get_string (value);
887 font_desc = pango_font_description_from_string (name);
889 set_font_description (text_tag, font_desc);
892 pango_font_description_free (font_desc);
900 PangoFontDescription *font_desc;
902 font_desc = g_value_get_as_pointer (value);
904 set_font_description (text_tag, font_desc);
911 if (text_tag->values->font.family_name)
912 g_free (text_tag->values->font.family_name);
913 text_tag->values->font.family_name = g_strdup (g_value_get_string (value));
914 text_tag->family_set = TRUE;
915 g_object_notify (G_OBJECT (text_tag), "family_set");
916 g_object_notify (G_OBJECT (text_tag), "font_desc");
917 g_object_notify (G_OBJECT (text_tag), "font");
922 text_tag->values->font.style = g_value_get_enum (value);
923 text_tag->style_set = TRUE;
924 g_object_notify (G_OBJECT (text_tag), "style_set");
925 g_object_notify (G_OBJECT (text_tag), "font_desc");
926 g_object_notify (G_OBJECT (text_tag), "font");
931 text_tag->values->font.variant = g_value_get_enum (value);
932 text_tag->variant_set = TRUE;
933 g_object_notify (G_OBJECT (text_tag), "variant_set");
934 g_object_notify (G_OBJECT (text_tag), "font_desc");
935 g_object_notify (G_OBJECT (text_tag), "font");
940 text_tag->values->font.weight = g_value_get_int (value);
941 text_tag->weight_set = TRUE;
942 g_object_notify (G_OBJECT (text_tag), "weight_set");
943 g_object_notify (G_OBJECT (text_tag), "font_desc");
944 g_object_notify (G_OBJECT (text_tag), "font");
949 text_tag->values->font.stretch = g_value_get_enum (value);
950 text_tag->stretch_set = TRUE;
951 g_object_notify (G_OBJECT (text_tag), "stretch_set");
952 g_object_notify (G_OBJECT (text_tag), "font_desc");
953 g_object_notify (G_OBJECT (text_tag), "font");
958 text_tag->values->font.size = g_value_get_int (value);
959 text_tag->size_set = TRUE;
960 g_object_notify (G_OBJECT (text_tag), "size_points");
961 g_object_notify (G_OBJECT (text_tag), "size_set");
962 g_object_notify (G_OBJECT (text_tag), "font_desc");
963 g_object_notify (G_OBJECT (text_tag), "font");
967 case PROP_SIZE_POINTS:
968 text_tag->values->font.size = g_value_get_double (value) * PANGO_SCALE;
969 text_tag->size_set = TRUE;
970 g_object_notify (G_OBJECT (text_tag), "size");
971 g_object_notify (G_OBJECT (text_tag), "size_set");
972 g_object_notify (G_OBJECT (text_tag), "font_desc");
973 g_object_notify (G_OBJECT (text_tag), "font");
977 case PROP_PIXELS_ABOVE_LINES:
978 text_tag->pixels_above_lines_set = TRUE;
979 text_tag->values->pixels_above_lines = g_value_get_int (value);
980 g_object_notify (G_OBJECT (text_tag), "pixels_above_lines_set");
984 case PROP_PIXELS_BELOW_LINES:
985 text_tag->pixels_below_lines_set = TRUE;
986 text_tag->values->pixels_below_lines = g_value_get_int (value);
987 g_object_notify (G_OBJECT (text_tag), "pixels_below_lines_set");
991 case PROP_PIXELS_INSIDE_WRAP:
992 text_tag->pixels_inside_wrap_set = TRUE;
993 text_tag->values->pixels_inside_wrap = g_value_get_int (value);
994 g_object_notify (G_OBJECT (text_tag), "pixels_inside_wrap_set");
999 text_tag->editable_set = TRUE;
1000 text_tag->values->editable = g_value_get_boolean (value);
1001 g_object_notify (G_OBJECT (text_tag), "editable_set");
1004 case PROP_WRAP_MODE:
1005 text_tag->wrap_mode_set = TRUE;
1006 text_tag->values->wrap_mode = g_value_get_enum (value);
1007 g_object_notify (G_OBJECT (text_tag), "wrap_mode_set");
1008 size_changed = TRUE;
1011 case PROP_JUSTIFICATION:
1012 text_tag->justification_set = TRUE;
1013 text_tag->values->justification = g_value_get_enum (value);
1014 g_object_notify (G_OBJECT (text_tag), "justification_set");
1015 size_changed = TRUE;
1018 case PROP_DIRECTION:
1019 text_tag->values->direction = g_value_get_enum (value);
1022 case PROP_LEFT_MARGIN:
1023 text_tag->left_margin_set = TRUE;
1024 text_tag->values->left_margin = g_value_get_int (value);
1025 g_object_notify (G_OBJECT (text_tag), "left_margin_set");
1026 size_changed = TRUE;
1030 text_tag->indent_set = TRUE;
1031 text_tag->values->indent = g_value_get_int (value);
1032 g_object_notify (G_OBJECT (text_tag), "indent_set");
1033 size_changed = TRUE;
1036 case PROP_STRIKETHROUGH:
1037 text_tag->strikethrough_set = TRUE;
1038 text_tag->values->appearance.strikethrough = g_value_get_boolean (value);
1039 g_object_notify (G_OBJECT (text_tag), "strikethrough_set");
1042 case PROP_RIGHT_MARGIN:
1043 text_tag->right_margin_set = TRUE;
1044 text_tag->values->right_margin = g_value_get_int (value);
1045 g_object_notify (G_OBJECT (text_tag), "right_margin_set");
1046 size_changed = TRUE;
1049 case PROP_UNDERLINE:
1050 text_tag->underline_set = TRUE;
1051 text_tag->values->appearance.underline = g_value_get_enum (value);
1052 g_object_notify (G_OBJECT (text_tag), "underline_set");
1056 text_tag->rise_set = TRUE;
1057 text_tag->values->appearance.rise = g_value_get_int (value);
1058 g_object_notify (G_OBJECT (text_tag), "rise_set");
1059 size_changed = TRUE;
1062 case PROP_BG_FULL_HEIGHT:
1063 text_tag->bg_full_height_set = TRUE;
1064 text_tag->values->bg_full_height = g_value_get_boolean (value);
1065 g_object_notify (G_OBJECT (text_tag), "bg_full_height_set");
1069 text_tag->language_set = TRUE;
1070 text_tag->values->language = g_strdup (g_value_get_string (value));
1071 g_object_notify (G_OBJECT (text_tag), "language_set");
1075 text_tag->tabs_set = TRUE;
1077 if (text_tag->values->tabs)
1078 pango_tab_array_free (text_tag->values->tabs);
1080 /* FIXME I'm not sure if this is a memleak or not */
1081 text_tag->values->tabs =
1082 pango_tab_array_copy (g_value_get_as_pointer (value));
1084 g_object_notify (G_OBJECT (text_tag), "tabs_set");
1086 size_changed = TRUE;
1089 case PROP_INVISIBLE:
1090 text_tag->invisible_set = TRUE;
1091 text_tag->values->invisible = g_value_get_boolean (value);
1092 g_object_notify (G_OBJECT (text_tag), "invisible_set");
1093 size_changed = TRUE;
1096 /* Whether the value should be used... */
1098 case PROP_BACKGROUND_SET:
1099 text_tag->bg_color_set = g_value_get_boolean (value);
1102 case PROP_FOREGROUND_SET:
1103 text_tag->fg_color_set = g_value_get_boolean (value);
1106 case PROP_BACKGROUND_STIPPLE_SET:
1107 text_tag->bg_stipple_set = g_value_get_boolean (value);
1108 if (!text_tag->bg_stipple_set &&
1109 text_tag->values->appearance.bg_stipple)
1111 g_object_unref (G_OBJECT (text_tag->values->appearance.bg_stipple));
1112 text_tag->values->appearance.bg_stipple = NULL;
1116 case PROP_FOREGROUND_STIPPLE_SET:
1117 text_tag->fg_stipple_set = g_value_get_boolean (value);
1118 if (!text_tag->fg_stipple_set &&
1119 text_tag->values->appearance.fg_stipple)
1121 g_object_unref (G_OBJECT (text_tag->values->appearance.fg_stipple));
1122 text_tag->values->appearance.fg_stipple = NULL;
1126 case PROP_FAMILY_SET:
1127 text_tag->family_set = g_value_get_boolean (value);
1128 size_changed = TRUE;
1131 case PROP_STYLE_SET:
1132 text_tag->style_set = g_value_get_boolean (value);
1133 size_changed = TRUE;
1136 case PROP_VARIANT_SET:
1137 text_tag->variant_set = g_value_get_boolean (value);
1138 size_changed = TRUE;
1141 case PROP_WEIGHT_SET:
1142 text_tag->weight_set = g_value_get_boolean (value);
1143 size_changed = TRUE;
1146 case PROP_STRETCH_SET:
1147 text_tag->stretch_set = g_value_get_boolean (value);
1148 size_changed = TRUE;
1152 text_tag->size_set = g_value_get_boolean (value);
1153 size_changed = TRUE;
1156 case PROP_PIXELS_ABOVE_LINES_SET:
1157 text_tag->pixels_above_lines_set = g_value_get_boolean (value);
1158 size_changed = TRUE;
1161 case PROP_PIXELS_BELOW_LINES_SET:
1162 text_tag->pixels_below_lines_set = g_value_get_boolean (value);
1163 size_changed = TRUE;
1166 case PROP_PIXELS_INSIDE_WRAP_SET:
1167 text_tag->pixels_inside_wrap_set = g_value_get_boolean (value);
1168 size_changed = TRUE;
1171 case PROP_EDITABLE_SET:
1172 text_tag->editable_set = g_value_get_boolean (value);
1175 case PROP_WRAP_MODE_SET:
1176 text_tag->wrap_mode_set = g_value_get_boolean (value);
1177 size_changed = TRUE;
1180 case PROP_JUSTIFICATION_SET:
1181 text_tag->justification_set = g_value_get_boolean (value);
1182 size_changed = TRUE;
1185 case PROP_LEFT_MARGIN_SET:
1186 text_tag->left_margin_set = g_value_get_boolean (value);
1187 size_changed = TRUE;
1190 case PROP_INDENT_SET:
1191 text_tag->indent_set = g_value_get_boolean (value);
1192 size_changed = TRUE;
1195 case PROP_STRIKETHROUGH_SET:
1196 text_tag->strikethrough_set = g_value_get_boolean (value);
1199 case PROP_RIGHT_MARGIN_SET:
1200 text_tag->right_margin_set = g_value_get_boolean (value);
1201 size_changed = TRUE;
1204 case PROP_UNDERLINE_SET:
1205 text_tag->underline_set = g_value_get_boolean (value);
1209 text_tag->rise_set = g_value_get_boolean (value);
1210 size_changed = TRUE;
1213 case PROP_BG_FULL_HEIGHT_SET:
1214 text_tag->bg_full_height_set = g_value_get_boolean (value);
1217 case PROP_LANGUAGE_SET:
1218 text_tag->language_set = g_value_get_boolean (value);
1219 size_changed = TRUE;
1223 text_tag->tabs_set = g_value_get_boolean (value);
1224 size_changed = TRUE;
1227 case PROP_INVISIBLE_SET:
1228 text_tag->invisible_set = g_value_get_boolean (value);
1229 size_changed = TRUE;
1233 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1237 /* FIXME I would like to do this after all set_property in a single
1238 * g_object_set () have been called. But an idle function won't
1239 * work; we need to emit when the tag is changed, not when we get
1240 * around to the event loop. So blah, we eat some inefficiency.
1243 /* This is also somewhat weird since we emit another object's
1244 * signal here, but the two objects are already tightly bound.
1247 if (text_tag->table)
1248 g_signal_emit_by_name (G_OBJECT (text_tag->table),
1250 text_tag, size_changed);
1254 get_color_arg (GValue *value, GdkColor *orig)
1258 color = g_new (GdkColor, 1);
1260 g_value_init (value, GTK_TYPE_GDK_COLOR);
1261 g_value_set_boxed (value, color);
1265 gtk_text_tag_get_property (GObject *object,
1269 const gchar *trailer)
1273 tag = GTK_TEXT_TAG (object);
1278 g_value_set_string (value, tag->name);
1281 case PROP_BACKGROUND_GDK:
1282 get_color_arg (value, &tag->values->appearance.bg_color);
1285 case PROP_FOREGROUND_GDK:
1286 get_color_arg (value, &tag->values->appearance.fg_color);
1289 case PROP_BACKGROUND_STIPPLE:
1290 if (tag->bg_stipple_set)
1291 g_value_set_boxed (value, tag->values->appearance.bg_stipple);
1294 case PROP_FOREGROUND_STIPPLE:
1295 if (tag->fg_stipple_set)
1296 g_value_set_boxed (value, tag->values->appearance.fg_stipple);
1301 /* FIXME GValue imposes a totally gratuitous string copy
1302 * here, we could just hand off string ownership
1304 gchar *str = pango_font_description_to_string (&tag->values->font);
1305 g_value_set_string (value, str);
1310 case PROP_FONT_DESC:
1311 g_value_set_boxed (value, &tag->values->font);
1315 g_value_set_string (value, tag->values->font.family_name);
1319 g_value_set_enum (value, tag->values->font.style);
1323 g_value_set_enum (value, tag->values->font.variant);
1327 g_value_set_int (value, tag->values->font.weight);
1331 g_value_set_enum (value, tag->values->font.stretch);
1335 g_value_set_int (value, tag->values->font.size);
1338 case PROP_SIZE_POINTS:
1339 g_value_set_double (value, ((double)tag->values->font.size) / (double)PANGO_SCALE);
1342 case PROP_PIXELS_ABOVE_LINES:
1343 g_value_set_int (value, tag->values->pixels_above_lines);
1346 case PROP_PIXELS_BELOW_LINES:
1347 g_value_set_int (value, tag->values->pixels_below_lines);
1350 case PROP_PIXELS_INSIDE_WRAP:
1351 g_value_set_int (value, tag->values->pixels_inside_wrap);
1355 g_value_set_boolean (value, tag->values->editable);
1358 case PROP_WRAP_MODE:
1359 g_value_set_enum (value, tag->values->wrap_mode);
1362 case PROP_JUSTIFICATION:
1363 g_value_set_enum (value, tag->values->justification);
1366 case PROP_DIRECTION:
1367 g_value_set_enum (value, tag->values->direction);
1370 case PROP_LEFT_MARGIN:
1371 g_value_set_int (value, tag->values->left_margin);
1375 g_value_set_int (value, tag->values->indent);
1378 case PROP_STRIKETHROUGH:
1379 g_value_set_boolean (value, tag->values->appearance.strikethrough);
1382 case PROP_RIGHT_MARGIN:
1383 g_value_set_int (value, tag->values->right_margin);
1386 case PROP_UNDERLINE:
1387 g_value_set_enum (value, tag->values->appearance.underline);
1391 g_value_set_int (value, tag->values->appearance.rise);
1394 case PROP_BG_FULL_HEIGHT:
1395 g_value_set_boolean (value, tag->values->bg_full_height);
1399 g_value_set_string (value, tag->values->language);
1403 if (tag->values->tabs)
1404 g_value_set_boxed (value, tag->values->tabs);
1407 case PROP_INVISIBLE:
1408 g_value_set_boolean (value, tag->values->invisible);
1411 case PROP_BACKGROUND_SET:
1412 g_value_set_boolean (value, tag->bg_color_set);
1415 case PROP_FOREGROUND_SET:
1416 g_value_set_boolean (value, tag->fg_color_set);
1419 case PROP_BACKGROUND_STIPPLE_SET:
1420 g_value_set_boolean (value, tag->bg_stipple_set);
1423 case PROP_FOREGROUND_STIPPLE_SET:
1424 g_value_set_boolean (value, tag->fg_stipple_set);
1427 case PROP_FAMILY_SET:
1428 g_value_set_boolean (value, tag->family_set);
1431 case PROP_STYLE_SET:
1432 g_value_set_boolean (value, tag->style_set);
1435 case PROP_VARIANT_SET:
1436 g_value_set_boolean (value, tag->variant_set);
1439 case PROP_WEIGHT_SET:
1440 g_value_set_boolean (value, tag->weight_set);
1443 case PROP_STRETCH_SET:
1444 g_value_set_boolean (value, tag->stretch_set);
1448 g_value_set_boolean (value, tag->size_set);
1451 case PROP_PIXELS_ABOVE_LINES_SET:
1452 g_value_set_boolean (value, tag->pixels_above_lines_set);
1455 case PROP_PIXELS_BELOW_LINES_SET:
1456 g_value_set_boolean (value, tag->pixels_below_lines_set);
1459 case PROP_PIXELS_INSIDE_WRAP_SET:
1460 g_value_set_boolean (value, tag->pixels_inside_wrap_set);
1463 case PROP_EDITABLE_SET:
1464 g_value_set_boolean (value, tag->editable_set);
1467 case PROP_WRAP_MODE_SET:
1468 g_value_set_boolean (value, tag->wrap_mode_set);
1471 case PROP_JUSTIFICATION_SET:
1472 g_value_set_boolean (value, tag->justification_set);
1475 case PROP_LEFT_MARGIN_SET:
1476 g_value_set_boolean (value, tag->left_margin_set);
1479 case PROP_INDENT_SET:
1480 g_value_set_boolean (value, tag->indent_set);
1483 case PROP_STRIKETHROUGH_SET:
1484 g_value_set_boolean (value, tag->strikethrough_set);
1487 case PROP_RIGHT_MARGIN_SET:
1488 g_value_set_boolean (value, tag->right_margin_set);
1491 case PROP_UNDERLINE_SET:
1492 g_value_set_boolean (value, tag->underline_set);
1496 g_value_set_boolean (value, tag->rise_set);
1499 case PROP_BG_FULL_HEIGHT_SET:
1500 g_value_set_boolean (value, tag->bg_full_height_set);
1503 case PROP_LANGUAGE_SET:
1504 g_value_set_boolean (value, tag->language_set);
1508 g_value_set_boolean (value, tag->tabs_set);
1511 case PROP_INVISIBLE_SET:
1512 g_value_set_boolean (value, tag->invisible_set);
1515 case PROP_BACKGROUND:
1516 case PROP_FOREGROUND:
1517 g_warning ("'foreground' and 'background' properties are not readable, use 'foreground_gdk' and 'background_gdk'");
1519 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1535 delta_priority_foreach (GtkTextTag *tag, gpointer user_data)
1537 DeltaData *dd = user_data;
1539 if (tag->priority >= dd->low && tag->priority <= dd->high)
1540 tag->priority += dd->delta;
1544 * gtk_text_tag_get_priority:
1545 * @tag: a #GtkTextTag
1547 * Get the tag priority.
1549 * Return value: The tag's priority.
1552 gtk_text_tag_get_priority (GtkTextTag *tag)
1554 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), 0);
1556 return tag->priority;
1560 * gtk_text_tag_set_priority:
1561 * @tag: a #GtkTextTag
1562 * @priority: the new priority
1564 * Sets the priority of a #GtkTextTag. Valid priorities are
1565 * start at 0 and go to one less than gtk_text_tag_table_size().
1566 * Each tag in a table has a unique priority; setting the priority
1567 * of one tag shifts the priorities of all the other tags in the
1568 * table to maintain a unique priority for each tag. Higher priority
1569 * tags "win" if two tags both set the same text attribute. When adding
1570 * a tag to a tag table, it will be assigned the highest priority in
1571 * the table by default; so normally the precedence of a set of tags
1572 * is the order in which they were added to the table, or created with
1573 * gtk_text_buffer_create_tag(), which adds the tag to the buffer's table
1577 gtk_text_tag_set_priority (GtkTextTag *tag,
1582 g_return_if_fail (GTK_IS_TEXT_TAG (tag));
1583 g_return_if_fail (tag->table != NULL);
1584 g_return_if_fail (priority >= 0);
1585 g_return_if_fail (priority < gtk_text_tag_table_size (tag->table));
1587 if (priority == tag->priority)
1590 if (priority < tag->priority)
1593 dd.high = tag->priority - 1;
1598 dd.low = tag->priority + 1;
1603 gtk_text_tag_table_foreach (tag->table,
1604 delta_priority_foreach,
1607 tag->priority = priority;
1611 * gtk_text_tag_event:
1612 * @tag: a #GtkTextTag
1613 * @event_object: object that received the event, such as a widget
1615 * @iter: location where the event was received
1617 * Emits the "event" signal on the #GtkTextTag.
1619 * Return value: result of signal emission (whether the event was handled)
1622 gtk_text_tag_event (GtkTextTag *tag,
1623 GObject *event_object,
1625 const GtkTextIter *iter)
1627 gint retval = FALSE;
1629 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
1630 g_return_val_if_fail (GTK_IS_OBJECT (event_object), FALSE);
1631 g_return_val_if_fail (event != NULL, FALSE);
1633 g_signal_emit (G_OBJECT (tag),
1645 tag_sort_func (gconstpointer first, gconstpointer second)
1647 GtkTextTag *tag1, *tag2;
1649 tag1 = * (GtkTextTag **) first;
1650 tag2 = * (GtkTextTag **) second;
1651 return tag1->priority - tag2->priority;
1655 _gtk_text_tag_array_sort (GtkTextTag** tag_array_p,
1660 GtkTextTag **maxPtrPtr, *tmp;
1662 g_return_if_fail (tag_array_p != NULL);
1663 g_return_if_fail (len > 0);
1669 GtkTextTag **iter = tag_array_p;
1671 for (i = len-1; i > 0; i--, iter++) {
1672 maxPtrPtr = tag = iter;
1673 prio = tag[0]->priority;
1674 for (j = i, tag++; j > 0; j--, tag++) {
1675 if (tag[0]->priority < prio) {
1676 prio = tag[0]->priority;
1685 qsort ((void *) tag_array_p, (unsigned) len, sizeof (GtkTextTag *),
1691 printf ("Sorted tag array: \n");
1695 GtkTextTag *t = tag_array_p[i];
1696 printf (" %s priority %d\n", t->name, t->priority);
1709 * gtk_text_attributes_new:
1711 * Creates a #GtkTextAttributes, which describes
1712 * a set of properties on some text.
1714 * Return value: a new #GtkTextAttributes
1717 gtk_text_attributes_new (void)
1719 GtkTextAttributes *values;
1721 values = g_new0 (GtkTextAttributes, 1);
1723 /* 0 is a valid value for most of the struct */
1725 values->refcount = 1;
1727 values->language = gtk_get_default_language ();
1733 * gtk_text_attributes_copy:
1734 * @src: a #GtkTextAttributes to be copied
1736 * Copies @src and returns a new #GtkTextAttributes.
1738 * Return value: a copy of @src
1741 gtk_text_attributes_copy (GtkTextAttributes *src)
1743 GtkTextAttributes *dest;
1745 dest = gtk_text_attributes_new ();
1746 gtk_text_attributes_copy_values (src, dest);
1752 * gtk_text_attributes_copy_values:
1753 * @src: a #GtkTextAttributes
1754 * @dest: another #GtkTextAttributes
1756 * Copies the values from @src to @dest so that @dest has the same values
1757 * as @src. Frees existing values in @dest.
1760 gtk_text_attributes_copy_values (GtkTextAttributes *src,
1761 GtkTextAttributes *dest)
1763 guint orig_refcount;
1765 g_return_if_fail (!dest->realized);
1772 if (src->appearance.bg_stipple)
1773 gdk_bitmap_ref (src->appearance.bg_stipple);
1775 if (src->appearance.fg_stipple)
1776 gdk_bitmap_ref (src->appearance.fg_stipple);
1780 if (dest->appearance.bg_stipple)
1781 gdk_bitmap_unref (dest->appearance.bg_stipple);
1783 if (dest->appearance.fg_stipple)
1784 gdk_bitmap_unref (dest->appearance.fg_stipple);
1787 g_free (dest->language);
1789 if (dest->font.family_name)
1790 g_free (dest->font.family_name);
1793 orig_refcount = dest->refcount;
1798 dest->tabs = pango_tab_array_copy (src->tabs);
1800 dest->language = g_strdup (src->language);
1802 dest->font.family_name = g_strdup (src->font.family_name);
1804 dest->refcount = orig_refcount;
1805 dest->realized = FALSE;
1809 * gtk_text_attributes_ref:
1810 * @values: a #GtkTextAttributes
1812 * Increments the reference count on @values.
1815 gtk_text_attributes_ref (GtkTextAttributes *values)
1817 g_return_if_fail (values != NULL);
1819 values->refcount += 1;
1823 * gtk_text_attributes_unref:
1824 * @values: a #GtkTextAttributes
1826 * Decrements the reference count on @values, freeing the structure
1827 * if the reference count reaches 0.
1830 gtk_text_attributes_unref (GtkTextAttributes *values)
1832 g_return_if_fail (values != NULL);
1833 g_return_if_fail (values->refcount > 0);
1835 values->refcount -= 1;
1837 if (values->refcount == 0)
1839 g_assert (!values->realized);
1841 if (values->appearance.bg_stipple)
1842 gdk_bitmap_unref (values->appearance.bg_stipple);
1844 if (values->appearance.fg_stipple)
1845 gdk_bitmap_unref (values->appearance.fg_stipple);
1848 pango_tab_array_free (values->tabs);
1850 if (values->language)
1851 g_free (values->language);
1853 if (values->font.family_name)
1854 g_free (values->font.family_name);
1861 _gtk_text_attributes_realize (GtkTextAttributes *values,
1865 g_return_if_fail (values != NULL);
1866 g_return_if_fail (values->refcount > 0);
1867 g_return_if_fail (!values->realized);
1869 /* It is wrong to use this colormap, FIXME */
1870 gdk_colormap_alloc_color (cmap,
1871 &values->appearance.fg_color,
1874 gdk_colormap_alloc_color (cmap,
1875 &values->appearance.bg_color,
1878 values->realized = TRUE;
1882 _gtk_text_attributes_unrealize (GtkTextAttributes *values,
1886 g_return_if_fail (values != NULL);
1887 g_return_if_fail (values->refcount > 0);
1888 g_return_if_fail (values->realized);
1890 gdk_colormap_free_colors (cmap,
1891 &values->appearance.fg_color, 1);
1894 gdk_colormap_free_colors (cmap,
1895 &values->appearance.bg_color, 1);
1897 values->appearance.fg_color.pixel = 0;
1898 values->appearance.bg_color.pixel = 0;
1900 values->realized = FALSE;
1904 _gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest,
1910 g_return_if_fail (!dest->realized);
1914 GtkTextTag *tag = tags[n];
1915 GtkTextAttributes *vals = tag->values;
1918 g_assert (tags[n]->priority > tags[n-1]->priority);
1920 if (tag->bg_color_set)
1922 dest->appearance.bg_color = vals->appearance.bg_color;
1924 dest->appearance.draw_bg = TRUE;
1926 if (tag->fg_color_set)
1927 dest->appearance.fg_color = vals->appearance.fg_color;
1929 if (tag->bg_stipple_set)
1931 gdk_bitmap_ref (vals->appearance.bg_stipple);
1932 if (dest->appearance.bg_stipple)
1933 gdk_bitmap_unref (dest->appearance.bg_stipple);
1934 dest->appearance.bg_stipple = vals->appearance.bg_stipple;
1936 dest->appearance.draw_bg = TRUE;
1939 if (tag->fg_stipple_set)
1941 gdk_bitmap_ref (vals->appearance.fg_stipple);
1942 if (dest->appearance.fg_stipple)
1943 gdk_bitmap_unref (dest->appearance.fg_stipple);
1944 dest->appearance.fg_stipple = vals->appearance.fg_stipple;
1947 if (tag->family_set)
1949 if (dest->font.family_name)
1950 g_free (dest->font.family_name);
1952 dest->font.family_name = g_strdup (vals->font.family_name);
1956 dest->font.style = vals->font.style;
1958 if (tag->variant_set)
1959 dest->font.variant = vals->font.variant;
1961 if (tag->weight_set)
1962 dest->font.weight = vals->font.weight;
1964 if (tag->stretch_set)
1965 dest->font.stretch = vals->font.stretch;
1968 dest->font.size = vals->font.size;
1970 if (tag->justification_set)
1971 dest->justification = vals->justification;
1973 if (vals->direction != GTK_TEXT_DIR_NONE)
1974 dest->direction = vals->direction;
1976 if (tag->left_margin_set)
1977 dest->left_margin = vals->left_margin;
1979 if (tag->indent_set)
1980 dest->indent = vals->indent;
1983 dest->appearance.rise = vals->appearance.rise;
1985 if (tag->right_margin_set)
1986 dest->right_margin = vals->right_margin;
1988 if (tag->pixels_above_lines_set)
1989 dest->pixels_above_lines = vals->pixels_above_lines;
1991 if (tag->pixels_below_lines_set)
1992 dest->pixels_below_lines = vals->pixels_below_lines;
1994 if (tag->pixels_inside_wrap_set)
1995 dest->pixels_inside_wrap = vals->pixels_inside_wrap;
2000 pango_tab_array_free (dest->tabs);
2001 dest->tabs = pango_tab_array_copy (vals->tabs);
2004 if (tag->wrap_mode_set)
2005 dest->wrap_mode = vals->wrap_mode;
2007 if (tag->underline_set)
2008 dest->appearance.underline = vals->appearance.underline;
2010 if (tag->strikethrough_set)
2011 dest->appearance.strikethrough = vals->appearance.strikethrough;
2013 if (tag->invisible_set)
2014 dest->invisible = vals->invisible;
2016 if (tag->editable_set)
2017 dest->editable = vals->editable;
2019 if (tag->bg_full_height_set)
2020 dest->bg_full_height = vals->bg_full_height;
2022 if (tag->language_set)
2024 g_free (dest->language);
2025 dest->language = g_strdup (vals->language);
2033 _gtk_text_tag_affects_size (GtkTextTag *tag)
2035 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
2044 tag->justification_set ||
2045 tag->left_margin_set ||
2048 tag->right_margin_set ||
2049 tag->pixels_above_lines_set ||
2050 tag->pixels_below_lines_set ||
2051 tag->pixels_inside_wrap_set ||
2053 tag->underline_set ||
2054 tag->wrap_mode_set ||
2059 _gtk_text_tag_affects_nonsize_appearance (GtkTextTag *tag)
2061 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
2064 tag->bg_color_set ||
2065 tag->bg_stipple_set ||
2066 tag->fg_color_set ||
2067 tag->fg_stipple_set ||
2068 tag->strikethrough_set ||
2069 tag->bg_full_height_set;