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.
56 #include "gtktexttag.h"
57 #include "gtktexttypes.h"
58 #include "gtktexttagtable.h"
60 #include "gtkmarshalers.h"
61 #include "gtkprivate.h"
62 #include "gtktypebuiltins.h"
89 PROP_PIXELS_ABOVE_LINES,
90 PROP_PIXELS_BELOW_LINES,
91 PROP_PIXELS_INSIDE_WRAP,
102 PROP_BACKGROUND_FULL_HEIGHT,
106 PROP_PARAGRAPH_BACKGROUND,
107 PROP_PARAGRAPH_BACKGROUND_GDK,
110 PROP_ACCUMULATIVE_MARGIN,
112 /* Whether-a-style-arg-is-set args */
122 PROP_PIXELS_ABOVE_LINES_SET,
123 PROP_PIXELS_BELOW_LINES_SET,
124 PROP_PIXELS_INSIDE_WRAP_SET,
127 PROP_JUSTIFICATION_SET,
128 PROP_LEFT_MARGIN_SET,
130 PROP_STRIKETHROUGH_SET,
131 PROP_RIGHT_MARGIN_SET,
134 PROP_BACKGROUND_FULL_HEIGHT_SET,
138 PROP_PARAGRAPH_BACKGROUND_SET,
142 static void gtk_text_tag_finalize (GObject *object);
143 static void gtk_text_tag_set_property (GObject *object,
147 static void gtk_text_tag_get_property (GObject *object,
152 static guint signals[LAST_SIGNAL] = { 0 };
154 G_DEFINE_TYPE (GtkTextTag, gtk_text_tag, G_TYPE_OBJECT)
157 gtk_text_tag_class_init (GtkTextTagClass *klass)
159 GObjectClass *object_class = G_OBJECT_CLASS (klass);
161 object_class->set_property = gtk_text_tag_set_property;
162 object_class->get_property = gtk_text_tag_get_property;
164 object_class->finalize = gtk_text_tag_finalize;
167 g_object_class_install_property (object_class,
169 g_param_spec_string ("name",
171 P_("Name used to refer to the text tag. NULL for anonymous tags"),
173 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
177 g_object_class_install_property (object_class,
179 g_param_spec_string ("background",
180 P_("Background color name"),
181 P_("Background color as a string"),
183 GTK_PARAM_WRITABLE));
185 g_object_class_install_property (object_class,
187 g_param_spec_boxed ("background-gdk",
188 P_("Background color"),
189 P_("Background color as a (possibly unallocated) GdkColor"),
191 GTK_PARAM_READWRITE));
193 g_object_class_install_property (object_class,
194 PROP_BACKGROUND_FULL_HEIGHT,
195 g_param_spec_boolean ("background-full-height",
196 P_("Background full height"),
197 P_("Whether the background color fills the entire line height or only the height of the tagged characters"),
199 GTK_PARAM_READWRITE));
201 g_object_class_install_property (object_class,
203 g_param_spec_string ("foreground",
204 P_("Foreground color name"),
205 P_("Foreground color as a string"),
207 GTK_PARAM_WRITABLE));
209 g_object_class_install_property (object_class,
211 g_param_spec_boxed ("foreground-gdk",
212 P_("Foreground color"),
213 P_("Foreground color as a (possibly unallocated) GdkColor"),
215 GTK_PARAM_READWRITE));
217 g_object_class_install_property (object_class,
219 g_param_spec_enum ("direction",
220 P_("Text direction"),
221 P_("Text direction, e.g. right-to-left or left-to-right"),
222 GTK_TYPE_TEXT_DIRECTION,
224 GTK_PARAM_READWRITE));
226 g_object_class_install_property (object_class,
228 g_param_spec_boolean ("editable",
230 P_("Whether the text can be modified by the user"),
232 GTK_PARAM_READWRITE));
237 * Font description as string, e.g. \"Sans Italic 12\".
239 * Note that the initial value of this property depends on
240 * the internals of #PangoFontDescription.
242 g_object_class_install_property (object_class,
244 g_param_spec_string ("font",
246 P_("Font description as a string, e.g. \"Sans Italic 12\""),
248 GTK_PARAM_READWRITE));
250 g_object_class_install_property (object_class,
252 g_param_spec_boxed ("font-desc",
254 P_("Font description as a PangoFontDescription struct"),
255 PANGO_TYPE_FONT_DESCRIPTION,
256 GTK_PARAM_READWRITE));
258 g_object_class_install_property (object_class,
260 g_param_spec_string ("family",
262 P_("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
264 GTK_PARAM_READWRITE));
266 g_object_class_install_property (object_class,
268 g_param_spec_enum ("style",
270 P_("Font style as a PangoStyle, e.g. PANGO_STYLE_ITALIC"),
273 GTK_PARAM_READWRITE));
275 g_object_class_install_property (object_class,
277 g_param_spec_enum ("variant",
279 P_("Font variant as a PangoVariant, e.g. PANGO_VARIANT_SMALL_CAPS"),
281 PANGO_VARIANT_NORMAL,
282 GTK_PARAM_READWRITE));
284 g_object_class_install_property (object_class,
286 g_param_spec_int ("weight",
288 P_("Font weight as an integer, see predefined values in PangoWeight; for example, PANGO_WEIGHT_BOLD"),
292 GTK_PARAM_READWRITE));
295 g_object_class_install_property (object_class,
297 g_param_spec_enum ("stretch",
299 P_("Font stretch as a PangoStretch, e.g. PANGO_STRETCH_CONDENSED"),
301 PANGO_STRETCH_NORMAL,
302 GTK_PARAM_READWRITE));
304 g_object_class_install_property (object_class,
306 g_param_spec_int ("size",
308 P_("Font size in Pango units"),
312 GTK_PARAM_READWRITE));
314 g_object_class_install_property (object_class,
316 g_param_spec_double ("scale",
318 P_("Font size as a scale factor relative to the default font size. This properly adapts to theme changes etc. so is recommended. Pango predefines some scales such as PANGO_SCALE_X_LARGE"),
322 GTK_PARAM_READWRITE));
324 g_object_class_install_property (object_class,
326 g_param_spec_double ("size-points",
328 P_("Font size in points"),
332 GTK_PARAM_READWRITE));
334 g_object_class_install_property (object_class,
336 g_param_spec_enum ("justification",
338 P_("Left, right, or center justification"),
339 GTK_TYPE_JUSTIFICATION,
341 GTK_PARAM_READWRITE));
344 * GtkTextTag:language:
346 * The language this text is in, as an ISO code. Pango can use this as a
347 * hint when rendering the text. If not set, an appropriate default will be
350 * Note that the initial value of this property depends on the current
351 * locale, see also gtk_get_default_language().
353 g_object_class_install_property (object_class,
355 g_param_spec_string ("language",
357 P_("The language this text is in, as an ISO code. Pango can use this as a hint when rendering the text. If not set, an appropriate default will be used."),
359 GTK_PARAM_READWRITE));
361 g_object_class_install_property (object_class,
363 g_param_spec_int ("left-margin",
365 P_("Width of the left margin in pixels"),
369 GTK_PARAM_READWRITE));
371 g_object_class_install_property (object_class,
373 g_param_spec_int ("right-margin",
375 P_("Width of the right margin in pixels"),
379 GTK_PARAM_READWRITE));
382 g_object_class_install_property (object_class,
384 g_param_spec_int ("indent",
386 P_("Amount to indent the paragraph, in pixels"),
390 GTK_PARAM_READWRITE));
393 g_object_class_install_property (object_class,
395 g_param_spec_int ("rise",
397 P_("Offset of text above the baseline (below the baseline if rise is negative) in Pango units"),
401 GTK_PARAM_READWRITE));
403 g_object_class_install_property (object_class,
404 PROP_PIXELS_ABOVE_LINES,
405 g_param_spec_int ("pixels-above-lines",
406 P_("Pixels above lines"),
407 P_("Pixels of blank space above paragraphs"),
411 GTK_PARAM_READWRITE));
413 g_object_class_install_property (object_class,
414 PROP_PIXELS_BELOW_LINES,
415 g_param_spec_int ("pixels-below-lines",
416 P_("Pixels below lines"),
417 P_("Pixels of blank space below paragraphs"),
421 GTK_PARAM_READWRITE));
423 g_object_class_install_property (object_class,
424 PROP_PIXELS_INSIDE_WRAP,
425 g_param_spec_int ("pixels-inside-wrap",
426 P_("Pixels inside wrap"),
427 P_("Pixels of blank space between wrapped lines in a paragraph"),
431 GTK_PARAM_READWRITE));
433 g_object_class_install_property (object_class,
435 g_param_spec_boolean ("strikethrough",
437 P_("Whether to strike through the text"),
439 GTK_PARAM_READWRITE));
441 g_object_class_install_property (object_class,
443 g_param_spec_enum ("underline",
445 P_("Style of underline for this text"),
446 PANGO_TYPE_UNDERLINE,
447 PANGO_UNDERLINE_NONE,
448 GTK_PARAM_READWRITE));
450 g_object_class_install_property (object_class,
452 g_param_spec_enum ("wrap-mode",
454 P_("Whether to wrap lines never, at word boundaries, or at character boundaries"),
457 GTK_PARAM_READWRITE));
460 g_object_class_install_property (object_class,
462 g_param_spec_boxed ("tabs",
464 P_("Custom tabs for this text"),
465 PANGO_TYPE_TAB_ARRAY,
466 GTK_PARAM_READWRITE));
469 * GtkTextTag:invisible:
471 * Whether this text is hidden.
473 * Note that there may still be problems with the support for invisible
474 * text, in particular when navigating programmatically inside a buffer
475 * containing invisible segments.
479 g_object_class_install_property (object_class,
481 g_param_spec_boolean ("invisible",
483 P_("Whether this text is hidden."),
485 GTK_PARAM_READWRITE));
488 * GtkTextTag:paragraph-background:
490 * The paragraph background color as a string.
494 g_object_class_install_property (object_class,
495 PROP_PARAGRAPH_BACKGROUND,
496 g_param_spec_string ("paragraph-background",
497 P_("Paragraph background color name"),
498 P_("Paragraph background color as a string"),
500 GTK_PARAM_WRITABLE));
503 * GtkTextTag:paragraph-background-gdk:
505 * The paragraph background color as a as a (possibly unallocated)
510 g_object_class_install_property (object_class,
511 PROP_PARAGRAPH_BACKGROUND_GDK,
512 g_param_spec_boxed ("paragraph-background-gdk",
513 P_("Paragraph background color"),
514 P_("Paragraph background color as a (possibly unallocated) GdkColor"),
516 GTK_PARAM_READWRITE));
519 * GtkTextTag:accumulative-margin:
521 * Whether the margins accumulate or override each other.
523 * When set to %TRUE the margins of this tag are added to the margins
524 * of any other non-accumulative margins present. When set to %FALSE
525 * the margins override one another (the default).
529 g_object_class_install_property (object_class,
530 PROP_ACCUMULATIVE_MARGIN,
531 g_param_spec_boolean ("accumulative-margin",
532 P_("Margin Accumulates"),
533 P_("Whether left and right margins accumulate."),
535 GTK_PARAM_READWRITE));
537 /* Style props are set or not */
539 #define ADD_SET_PROP(propname, propval, nick, blurb) g_object_class_install_property (object_class, propval, g_param_spec_boolean (propname, nick, blurb, FALSE, GTK_PARAM_READWRITE))
541 ADD_SET_PROP ("background-set", PROP_BACKGROUND_SET,
542 P_("Background set"),
543 P_("Whether this tag affects the background color"));
545 ADD_SET_PROP ("background-full-height-set", PROP_BACKGROUND_FULL_HEIGHT_SET,
546 P_("Background full height set"),
547 P_("Whether this tag affects background height"));
549 ADD_SET_PROP ("foreground-set", PROP_FOREGROUND_SET,
550 P_("Foreground set"),
551 P_("Whether this tag affects the foreground color"));
553 ADD_SET_PROP ("editable-set", PROP_EDITABLE_SET,
554 P_("Editability set"),
555 P_("Whether this tag affects text editability"));
557 ADD_SET_PROP ("family-set", PROP_FAMILY_SET,
558 P_("Font family set"),
559 P_("Whether this tag affects the font family"));
561 ADD_SET_PROP ("style-set", PROP_STYLE_SET,
562 P_("Font style set"),
563 P_("Whether this tag affects the font style"));
565 ADD_SET_PROP ("variant-set", PROP_VARIANT_SET,
566 P_("Font variant set"),
567 P_("Whether this tag affects the font variant"));
569 ADD_SET_PROP ("weight-set", PROP_WEIGHT_SET,
570 P_("Font weight set"),
571 P_("Whether this tag affects the font weight"));
573 ADD_SET_PROP ("stretch-set", PROP_STRETCH_SET,
574 P_("Font stretch set"),
575 P_("Whether this tag affects the font stretch"));
577 ADD_SET_PROP ("size-set", PROP_SIZE_SET,
579 P_("Whether this tag affects the font size"));
581 ADD_SET_PROP ("scale-set", PROP_SCALE_SET,
582 P_("Font scale set"),
583 P_("Whether this tag scales the font size by a factor"));
585 ADD_SET_PROP ("justification-set", PROP_JUSTIFICATION_SET,
586 P_("Justification set"),
587 P_("Whether this tag affects paragraph justification"));
589 ADD_SET_PROP ("language-set", PROP_LANGUAGE_SET,
591 P_("Whether this tag affects the language the text is rendered as"));
593 ADD_SET_PROP ("left-margin-set", PROP_LEFT_MARGIN_SET,
594 P_("Left margin set"),
595 P_("Whether this tag affects the left margin"));
597 ADD_SET_PROP ("indent-set", PROP_INDENT_SET,
599 P_("Whether this tag affects indentation"));
601 ADD_SET_PROP ("rise-set", PROP_RISE_SET,
603 P_("Whether this tag affects the rise"));
605 ADD_SET_PROP ("pixels-above-lines-set", PROP_PIXELS_ABOVE_LINES_SET,
606 P_("Pixels above lines set"),
607 P_("Whether this tag affects the number of pixels above lines"));
609 ADD_SET_PROP ("pixels-below-lines-set", PROP_PIXELS_BELOW_LINES_SET,
610 P_("Pixels below lines set"),
611 P_("Whether this tag affects the number of pixels above lines"));
613 ADD_SET_PROP ("pixels-inside-wrap-set", PROP_PIXELS_INSIDE_WRAP_SET,
614 P_("Pixels inside wrap set"),
615 P_("Whether this tag affects the number of pixels between wrapped lines"));
617 ADD_SET_PROP ("strikethrough-set", PROP_STRIKETHROUGH_SET,
618 P_("Strikethrough set"),
619 P_("Whether this tag affects strikethrough"));
621 ADD_SET_PROP ("right-margin-set", PROP_RIGHT_MARGIN_SET,
622 P_("Right margin set"),
623 P_("Whether this tag affects the right margin"));
625 ADD_SET_PROP ("underline-set", PROP_UNDERLINE_SET,
627 P_("Whether this tag affects underlining"));
629 ADD_SET_PROP ("wrap-mode-set", PROP_WRAP_MODE_SET,
631 P_("Whether this tag affects line wrap mode"));
633 ADD_SET_PROP ("tabs-set", PROP_TABS_SET,
635 P_("Whether this tag affects tabs"));
637 ADD_SET_PROP ("invisible-set", PROP_INVISIBLE_SET,
639 P_("Whether this tag affects text visibility"));
641 ADD_SET_PROP ("paragraph-background-set", PROP_PARAGRAPH_BACKGROUND_SET,
642 P_("Paragraph background set"),
643 P_("Whether this tag affects the paragraph background color"));
647 * @tag: the #GtkTextTag on which the signal is emitted
648 * @object: the object the event was fired from (typically a #GtkTextView)
649 * @event: the event which triggered the signal
650 * @iter: a #GtkTextIter pointing at the location the event occured
652 * The ::event signal is emitted when an event occurs on a region of the
653 * buffer marked with this tag.
655 * Returns: %TRUE to stop other handlers from being invoked for the
656 * event. %FALSE to propagate the event further.
659 g_signal_new (I_("event"),
660 G_OBJECT_CLASS_TYPE (object_class),
662 G_STRUCT_OFFSET (GtkTextTagClass, event),
663 _gtk_boolean_handled_accumulator, NULL,
664 _gtk_marshal_BOOLEAN__OBJECT_BOXED_BOXED,
668 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE,
671 g_type_class_add_private (klass, sizeof (GtkTextTagPrivate));
675 gtk_text_tag_init (GtkTextTag *text_tag)
677 GtkTextTagPrivate *priv;
679 text_tag->priv = G_TYPE_INSTANCE_GET_PRIVATE (text_tag,
682 priv = text_tag->priv;
684 priv->values = gtk_text_attributes_new ();
689 * @name: (allow-none): tag name, or %NULL
691 * Creates a #GtkTextTag. Configure the tag using object arguments,
692 * i.e. using g_object_set().
694 * Return value: a new #GtkTextTag
697 gtk_text_tag_new (const gchar *name)
701 tag = g_object_new (GTK_TYPE_TEXT_TAG, "name", name, NULL);
707 gtk_text_tag_finalize (GObject *object)
709 GtkTextTag *text_tag = GTK_TEXT_TAG (object);
710 GtkTextTagPrivate *priv = text_tag->priv;
713 gtk_text_tag_table_remove (priv->table, text_tag);
715 g_assert (priv->table == NULL);
717 gtk_text_attributes_unref (priv->values);
723 G_OBJECT_CLASS (gtk_text_tag_parent_class)->finalize (object);
727 set_bg_color (GtkTextTag *tag, GdkColor *color)
729 GtkTextTagPrivate *priv = tag->priv;
733 if (!priv->bg_color_set)
735 priv->bg_color_set = TRUE;
736 g_object_notify (G_OBJECT (tag), "background-set");
739 priv->values->appearance.bg_color = *color;
743 if (priv->bg_color_set)
745 priv->bg_color_set = FALSE;
746 g_object_notify (G_OBJECT (tag), "background-set");
752 set_fg_color (GtkTextTag *tag, GdkColor *color)
754 GtkTextTagPrivate *priv = tag->priv;
758 if (!priv->fg_color_set)
760 priv->fg_color_set = TRUE;
761 g_object_notify (G_OBJECT (tag), "foreground-set");
763 priv->values->appearance.fg_color = *color;
767 if (priv->fg_color_set)
769 priv->fg_color_set = FALSE;
770 g_object_notify (G_OBJECT (tag), "foreground-set");
776 set_pg_bg_color (GtkTextTag *tag, GdkColor *color)
778 GtkTextTagPrivate *priv = tag->priv;
782 if (!priv->pg_bg_color_set)
784 priv->pg_bg_color_set = TRUE;
785 g_object_notify (G_OBJECT (tag), "paragraph-background-set");
788 gdk_color_free (priv->values->pg_bg_color);
790 priv->values->pg_bg_color = gdk_color_copy (color);
794 if (priv->pg_bg_color_set)
796 priv->pg_bg_color_set = FALSE;
797 g_object_notify (G_OBJECT (tag), "paragraph-background-set");
798 gdk_color_free (priv->values->pg_bg_color);
801 priv->values->pg_bg_color = NULL;
806 get_property_font_set_mask (guint prop_id)
810 case PROP_FAMILY_SET:
811 return PANGO_FONT_MASK_FAMILY;
813 return PANGO_FONT_MASK_STYLE;
814 case PROP_VARIANT_SET:
815 return PANGO_FONT_MASK_VARIANT;
816 case PROP_WEIGHT_SET:
817 return PANGO_FONT_MASK_WEIGHT;
818 case PROP_STRETCH_SET:
819 return PANGO_FONT_MASK_STRETCH;
821 return PANGO_FONT_MASK_SIZE;
828 set_font_desc_fields (PangoFontDescription *desc,
829 PangoFontMask to_set)
831 PangoFontMask changed_mask = 0;
833 if (to_set & PANGO_FONT_MASK_FAMILY)
835 const char *family = pango_font_description_get_family (desc);
839 changed_mask |= PANGO_FONT_MASK_FAMILY;
842 pango_font_description_set_family (desc, family);
844 if (to_set & PANGO_FONT_MASK_STYLE)
845 pango_font_description_set_style (desc, pango_font_description_get_style (desc));
846 if (to_set & PANGO_FONT_MASK_VARIANT)
847 pango_font_description_set_variant (desc, pango_font_description_get_variant (desc));
848 if (to_set & PANGO_FONT_MASK_WEIGHT)
849 pango_font_description_set_weight (desc, pango_font_description_get_weight (desc));
850 if (to_set & PANGO_FONT_MASK_STRETCH)
851 pango_font_description_set_stretch (desc, pango_font_description_get_stretch (desc));
852 if (to_set & PANGO_FONT_MASK_SIZE)
854 gint size = pango_font_description_get_size (desc);
857 size = 10 * PANGO_SCALE;
858 changed_mask |= PANGO_FONT_MASK_SIZE;
861 pango_font_description_set_size (desc, size);
868 notify_set_changed (GObject *object,
869 PangoFontMask changed_mask)
871 if (changed_mask & PANGO_FONT_MASK_FAMILY)
872 g_object_notify (object, "family-set");
873 if (changed_mask & PANGO_FONT_MASK_STYLE)
874 g_object_notify (object, "style-set");
875 if (changed_mask & PANGO_FONT_MASK_VARIANT)
876 g_object_notify (object, "variant-set");
877 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
878 g_object_notify (object, "weight-set");
879 if (changed_mask & PANGO_FONT_MASK_STRETCH)
880 g_object_notify (object, "stretch-set");
881 if (changed_mask & PANGO_FONT_MASK_SIZE)
882 g_object_notify (object, "size-set");
886 notify_fields_changed (GObject *object,
887 PangoFontMask changed_mask)
889 if (changed_mask & PANGO_FONT_MASK_FAMILY)
890 g_object_notify (object, "family");
891 if (changed_mask & PANGO_FONT_MASK_STYLE)
892 g_object_notify (object, "style");
893 if (changed_mask & PANGO_FONT_MASK_VARIANT)
894 g_object_notify (object, "variant");
895 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
896 g_object_notify (object, "weight");
897 if (changed_mask & PANGO_FONT_MASK_STRETCH)
898 g_object_notify (object, "stretch");
899 if (changed_mask & PANGO_FONT_MASK_SIZE)
900 g_object_notify (object, "size");
904 set_font_description (GtkTextTag *text_tag,
905 PangoFontDescription *font_desc)
907 GtkTextTagPrivate *priv = text_tag->priv;
908 GObject *object = G_OBJECT (text_tag);
909 PangoFontDescription *new_font_desc;
910 PangoFontMask old_mask, new_mask, changed_mask, set_changed_mask;
913 new_font_desc = pango_font_description_copy (font_desc);
915 new_font_desc = pango_font_description_new ();
917 if (priv->values->font)
918 old_mask = pango_font_description_get_set_fields (priv->values->font);
922 new_mask = pango_font_description_get_set_fields (new_font_desc);
924 changed_mask = old_mask | new_mask;
925 set_changed_mask = old_mask ^ new_mask;
927 if (priv->values->font)
928 pango_font_description_free (priv->values->font);
929 priv->values->font = new_font_desc;
931 g_object_freeze_notify (object);
933 g_object_notify (object, "font-desc");
934 g_object_notify (object, "font");
936 if (changed_mask & PANGO_FONT_MASK_FAMILY)
937 g_object_notify (object, "family");
938 if (changed_mask & PANGO_FONT_MASK_STYLE)
939 g_object_notify (object, "style");
940 if (changed_mask & PANGO_FONT_MASK_VARIANT)
941 g_object_notify (object, "variant");
942 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
943 g_object_notify (object, "weight");
944 if (changed_mask & PANGO_FONT_MASK_STRETCH)
945 g_object_notify (object, "stretch");
946 if (changed_mask & PANGO_FONT_MASK_SIZE)
948 g_object_notify (object, "size");
949 g_object_notify (object, "size-points");
952 notify_set_changed (object, set_changed_mask);
954 g_object_thaw_notify (object);
958 gtk_text_tag_ensure_font (GtkTextTag *text_tag)
960 GtkTextTagPrivate *priv = text_tag->priv;
962 if (!priv->values->font)
963 priv->values->font = pango_font_description_new ();
967 gtk_text_tag_set_property (GObject *object,
972 GtkTextTag *text_tag = GTK_TEXT_TAG (object);
973 GtkTextTagPrivate *priv = text_tag->priv;
974 gboolean size_changed = FALSE;
979 g_return_if_fail (priv->name == NULL);
980 priv->name = g_value_dup_string (value);
983 case PROP_BACKGROUND:
987 if (!g_value_get_string (value))
988 set_bg_color (text_tag, NULL); /* reset to background_set to FALSE */
989 else if (gdk_color_parse (g_value_get_string (value), &color))
990 set_bg_color (text_tag, &color);
992 g_warning ("Don't know color `%s'", g_value_get_string (value));
994 g_object_notify (object, "background-gdk");
998 case PROP_FOREGROUND:
1002 if (!g_value_get_string (value))
1003 set_fg_color (text_tag, NULL); /* reset to foreground_set to FALSE */
1004 else if (gdk_color_parse (g_value_get_string (value), &color))
1005 set_fg_color (text_tag, &color);
1007 g_warning ("Don't know color `%s'", g_value_get_string (value));
1009 g_object_notify (object, "foreground-gdk");
1013 case PROP_BACKGROUND_GDK:
1015 GdkColor *color = g_value_get_boxed (value);
1017 set_bg_color (text_tag, color);
1021 case PROP_FOREGROUND_GDK:
1023 GdkColor *color = g_value_get_boxed (value);
1025 set_fg_color (text_tag, color);
1031 PangoFontDescription *font_desc = NULL;
1034 name = g_value_get_string (value);
1037 font_desc = pango_font_description_from_string (name);
1039 set_font_description (text_tag, font_desc);
1041 pango_font_description_free (font_desc);
1043 size_changed = TRUE;
1047 case PROP_FONT_DESC:
1049 PangoFontDescription *font_desc;
1051 font_desc = g_value_get_boxed (value);
1053 set_font_description (text_tag, font_desc);
1055 size_changed = TRUE;
1065 case PROP_SIZE_POINTS:
1067 PangoFontMask old_set_mask;
1069 gtk_text_tag_ensure_font (text_tag);
1070 old_set_mask = pango_font_description_get_set_fields (priv->values->font);
1075 pango_font_description_set_family (priv->values->font,
1076 g_value_get_string (value));
1079 pango_font_description_set_style (priv->values->font,
1080 g_value_get_enum (value));
1083 pango_font_description_set_variant (priv->values->font,
1084 g_value_get_enum (value));
1087 pango_font_description_set_weight (priv->values->font,
1088 g_value_get_int (value));
1091 pango_font_description_set_stretch (priv->values->font,
1092 g_value_get_enum (value));
1095 pango_font_description_set_size (priv->values->font,
1096 g_value_get_int (value));
1097 g_object_notify (object, "size-points");
1099 case PROP_SIZE_POINTS:
1100 pango_font_description_set_size (priv->values->font,
1101 g_value_get_double (value) * PANGO_SCALE);
1102 g_object_notify (object, "size");
1106 size_changed = TRUE;
1107 notify_set_changed (object, old_set_mask & pango_font_description_get_set_fields (priv->values->font));
1108 g_object_notify (object, "font-desc");
1109 g_object_notify (object, "font");
1115 priv->values->font_scale = g_value_get_double (value);
1116 priv->scale_set = TRUE;
1117 g_object_notify (object, "scale-set");
1118 size_changed = TRUE;
1121 case PROP_PIXELS_ABOVE_LINES:
1122 priv->pixels_above_lines_set = TRUE;
1123 priv->values->pixels_above_lines = g_value_get_int (value);
1124 g_object_notify (object, "pixels-above-lines-set");
1125 size_changed = TRUE;
1128 case PROP_PIXELS_BELOW_LINES:
1129 priv->pixels_below_lines_set = TRUE;
1130 priv->values->pixels_below_lines = g_value_get_int (value);
1131 g_object_notify (object, "pixels-below-lines-set");
1132 size_changed = TRUE;
1135 case PROP_PIXELS_INSIDE_WRAP:
1136 priv->pixels_inside_wrap_set = TRUE;
1137 priv->values->pixels_inside_wrap = g_value_get_int (value);
1138 g_object_notify (object, "pixels-inside-wrap-set");
1139 size_changed = TRUE;
1143 priv->editable_set = TRUE;
1144 priv->values->editable = g_value_get_boolean (value);
1145 g_object_notify (object, "editable-set");
1148 case PROP_WRAP_MODE:
1149 priv->wrap_mode_set = TRUE;
1150 priv->values->wrap_mode = g_value_get_enum (value);
1151 g_object_notify (object, "wrap-mode-set");
1152 size_changed = TRUE;
1155 case PROP_JUSTIFICATION:
1156 priv->justification_set = TRUE;
1157 priv->values->justification = g_value_get_enum (value);
1158 g_object_notify (object, "justification-set");
1159 size_changed = TRUE;
1162 case PROP_DIRECTION:
1163 priv->values->direction = g_value_get_enum (value);
1166 case PROP_LEFT_MARGIN:
1167 priv->left_margin_set = TRUE;
1168 priv->values->left_margin = g_value_get_int (value);
1169 g_object_notify (object, "left-margin-set");
1170 size_changed = TRUE;
1174 priv->indent_set = TRUE;
1175 priv->values->indent = g_value_get_int (value);
1176 g_object_notify (object, "indent-set");
1177 size_changed = TRUE;
1180 case PROP_STRIKETHROUGH:
1181 priv->strikethrough_set = TRUE;
1182 priv->values->appearance.strikethrough = g_value_get_boolean (value);
1183 g_object_notify (object, "strikethrough-set");
1186 case PROP_RIGHT_MARGIN:
1187 priv->right_margin_set = TRUE;
1188 priv->values->right_margin = g_value_get_int (value);
1189 g_object_notify (object, "right-margin-set");
1190 size_changed = TRUE;
1193 case PROP_UNDERLINE:
1194 priv->underline_set = TRUE;
1195 priv->values->appearance.underline = g_value_get_enum (value);
1196 g_object_notify (object, "underline-set");
1200 priv->rise_set = TRUE;
1201 priv->values->appearance.rise = g_value_get_int (value);
1202 g_object_notify (object, "rise-set");
1203 size_changed = TRUE;
1206 case PROP_BACKGROUND_FULL_HEIGHT:
1207 priv->bg_full_height_set = TRUE;
1208 priv->values->bg_full_height = g_value_get_boolean (value);
1209 g_object_notify (object, "background-full-height-set");
1213 priv->language_set = TRUE;
1214 priv->values->language = pango_language_from_string (g_value_get_string (value));
1215 g_object_notify (object, "language-set");
1219 priv->tabs_set = TRUE;
1221 if (priv->values->tabs)
1222 pango_tab_array_free (priv->values->tabs);
1224 /* FIXME I'm not sure if this is a memleak or not */
1225 priv->values->tabs =
1226 pango_tab_array_copy (g_value_get_boxed (value));
1228 g_object_notify (object, "tabs-set");
1230 size_changed = TRUE;
1233 case PROP_INVISIBLE:
1234 priv->invisible_set = TRUE;
1235 priv->values->invisible = g_value_get_boolean (value);
1236 g_object_notify (object, "invisible-set");
1237 size_changed = TRUE;
1240 case PROP_PARAGRAPH_BACKGROUND:
1244 if (!g_value_get_string (value))
1245 set_pg_bg_color (text_tag, NULL); /* reset to paragraph_background_set to FALSE */
1246 else if (gdk_color_parse (g_value_get_string (value), &color))
1247 set_pg_bg_color (text_tag, &color);
1249 g_warning ("Don't know color `%s'", g_value_get_string (value));
1251 g_object_notify (object, "paragraph-background-gdk");
1255 case PROP_PARAGRAPH_BACKGROUND_GDK:
1257 GdkColor *color = g_value_get_boxed (value);
1259 set_pg_bg_color (text_tag, color);
1263 case PROP_ACCUMULATIVE_MARGIN:
1264 priv->accumulative_margin = g_value_get_boolean (value);
1265 g_object_notify (object, "accumulative-margin");
1266 size_changed = TRUE;
1269 /* Whether the value should be used... */
1271 case PROP_BACKGROUND_SET:
1272 priv->bg_color_set = g_value_get_boolean (value);
1275 case PROP_FOREGROUND_SET:
1276 priv->fg_color_set = g_value_get_boolean (value);
1279 case PROP_FAMILY_SET:
1280 case PROP_STYLE_SET:
1281 case PROP_VARIANT_SET:
1282 case PROP_WEIGHT_SET:
1283 case PROP_STRETCH_SET:
1285 if (!g_value_get_boolean (value))
1287 if (priv->values->font)
1288 pango_font_description_unset_fields (priv->values->font,
1289 get_property_font_set_mask (prop_id));
1293 PangoFontMask changed_mask;
1295 gtk_text_tag_ensure_font (text_tag);
1296 changed_mask = set_font_desc_fields (priv->values->font,
1297 get_property_font_set_mask (prop_id));
1298 notify_fields_changed (G_OBJECT (text_tag), changed_mask);
1302 case PROP_SCALE_SET:
1303 priv->scale_set = g_value_get_boolean (value);
1304 size_changed = TRUE;
1307 case PROP_PIXELS_ABOVE_LINES_SET:
1308 priv->pixels_above_lines_set = g_value_get_boolean (value);
1309 size_changed = TRUE;
1312 case PROP_PIXELS_BELOW_LINES_SET:
1313 priv->pixels_below_lines_set = g_value_get_boolean (value);
1314 size_changed = TRUE;
1317 case PROP_PIXELS_INSIDE_WRAP_SET:
1318 priv->pixels_inside_wrap_set = g_value_get_boolean (value);
1319 size_changed = TRUE;
1322 case PROP_EDITABLE_SET:
1323 priv->editable_set = g_value_get_boolean (value);
1326 case PROP_WRAP_MODE_SET:
1327 priv->wrap_mode_set = g_value_get_boolean (value);
1328 size_changed = TRUE;
1331 case PROP_JUSTIFICATION_SET:
1332 priv->justification_set = g_value_get_boolean (value);
1333 size_changed = TRUE;
1336 case PROP_LEFT_MARGIN_SET:
1337 priv->left_margin_set = g_value_get_boolean (value);
1338 size_changed = TRUE;
1341 case PROP_INDENT_SET:
1342 priv->indent_set = g_value_get_boolean (value);
1343 size_changed = TRUE;
1346 case PROP_STRIKETHROUGH_SET:
1347 priv->strikethrough_set = g_value_get_boolean (value);
1350 case PROP_RIGHT_MARGIN_SET:
1351 priv->right_margin_set = g_value_get_boolean (value);
1352 size_changed = TRUE;
1355 case PROP_UNDERLINE_SET:
1356 priv->underline_set = g_value_get_boolean (value);
1360 priv->rise_set = g_value_get_boolean (value);
1361 size_changed = TRUE;
1364 case PROP_BACKGROUND_FULL_HEIGHT_SET:
1365 priv->bg_full_height_set = g_value_get_boolean (value);
1368 case PROP_LANGUAGE_SET:
1369 priv->language_set = g_value_get_boolean (value);
1370 size_changed = TRUE;
1374 priv->tabs_set = g_value_get_boolean (value);
1375 size_changed = TRUE;
1378 case PROP_INVISIBLE_SET:
1379 priv->invisible_set = g_value_get_boolean (value);
1380 size_changed = TRUE;
1383 case PROP_PARAGRAPH_BACKGROUND_SET:
1384 priv->pg_bg_color_set = g_value_get_boolean (value);
1388 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1392 /* FIXME I would like to do this after all set_property in a single
1393 * g_object_set () have been called. But an idle function won't
1394 * work; we need to emit when the tag is changed, not when we get
1395 * around to the event loop. So blah, we eat some inefficiency.
1398 /* This is also somewhat weird since we emit another object's
1399 * signal here, but the two objects are already tightly bound.
1403 g_signal_emit_by_name (priv->table,
1405 text_tag, size_changed);
1409 gtk_text_tag_get_property (GObject *object,
1414 GtkTextTag *tag = GTK_TEXT_TAG (object);
1415 GtkTextTagPrivate *priv = tag->priv;
1420 g_value_set_string (value, priv->name);
1423 case PROP_BACKGROUND_GDK:
1424 g_value_set_boxed (value, &priv->values->appearance.bg_color);
1427 case PROP_FOREGROUND_GDK:
1428 g_value_set_boxed (value, &priv->values->appearance.fg_color);
1435 gtk_text_tag_ensure_font (tag);
1437 str = pango_font_description_to_string (priv->values->font);
1438 g_value_take_string (value, str);
1442 case PROP_FONT_DESC:
1443 gtk_text_tag_ensure_font (tag);
1444 g_value_set_boxed (value, priv->values->font);
1453 case PROP_SIZE_POINTS:
1454 gtk_text_tag_ensure_font (tag);
1458 g_value_set_string (value, pango_font_description_get_family (priv->values->font));
1462 g_value_set_enum (value, pango_font_description_get_style (priv->values->font));
1466 g_value_set_enum (value, pango_font_description_get_variant (priv->values->font));
1470 g_value_set_int (value, pango_font_description_get_weight (priv->values->font));
1474 g_value_set_enum (value, pango_font_description_get_stretch (priv->values->font));
1478 g_value_set_int (value, pango_font_description_get_size (priv->values->font));
1481 case PROP_SIZE_POINTS:
1482 g_value_set_double (value, ((double)pango_font_description_get_size (priv->values->font)) / (double)PANGO_SCALE);
1488 g_value_set_double (value, priv->values->font_scale);
1491 case PROP_PIXELS_ABOVE_LINES:
1492 g_value_set_int (value, priv->values->pixels_above_lines);
1495 case PROP_PIXELS_BELOW_LINES:
1496 g_value_set_int (value, priv->values->pixels_below_lines);
1499 case PROP_PIXELS_INSIDE_WRAP:
1500 g_value_set_int (value, priv->values->pixels_inside_wrap);
1504 g_value_set_boolean (value, priv->values->editable);
1507 case PROP_WRAP_MODE:
1508 g_value_set_enum (value, priv->values->wrap_mode);
1511 case PROP_JUSTIFICATION:
1512 g_value_set_enum (value, priv->values->justification);
1515 case PROP_DIRECTION:
1516 g_value_set_enum (value, priv->values->direction);
1519 case PROP_LEFT_MARGIN:
1520 g_value_set_int (value, priv->values->left_margin);
1524 g_value_set_int (value, priv->values->indent);
1527 case PROP_STRIKETHROUGH:
1528 g_value_set_boolean (value, priv->values->appearance.strikethrough);
1531 case PROP_RIGHT_MARGIN:
1532 g_value_set_int (value, priv->values->right_margin);
1535 case PROP_UNDERLINE:
1536 g_value_set_enum (value, priv->values->appearance.underline);
1540 g_value_set_int (value, priv->values->appearance.rise);
1543 case PROP_BACKGROUND_FULL_HEIGHT:
1544 g_value_set_boolean (value, priv->values->bg_full_height);
1548 g_value_set_string (value, pango_language_to_string (priv->values->language));
1552 if (priv->values->tabs)
1553 g_value_set_boxed (value, priv->values->tabs);
1556 case PROP_INVISIBLE:
1557 g_value_set_boolean (value, priv->values->invisible);
1560 case PROP_PARAGRAPH_BACKGROUND_GDK:
1561 g_value_set_boxed (value, priv->values->pg_bg_color);
1564 case PROP_ACCUMULATIVE_MARGIN:
1565 g_value_set_boolean (value, priv->accumulative_margin);
1568 case PROP_BACKGROUND_SET:
1569 g_value_set_boolean (value, priv->bg_color_set);
1572 case PROP_FOREGROUND_SET:
1573 g_value_set_boolean (value, priv->fg_color_set);
1576 case PROP_FAMILY_SET:
1577 case PROP_STYLE_SET:
1578 case PROP_VARIANT_SET:
1579 case PROP_WEIGHT_SET:
1580 case PROP_STRETCH_SET:
1583 PangoFontMask set_mask = priv->values->font ? pango_font_description_get_set_fields (priv->values->font) : 0;
1584 PangoFontMask test_mask = get_property_font_set_mask (prop_id);
1585 g_value_set_boolean (value, (set_mask & test_mask) != 0);
1590 case PROP_SCALE_SET:
1591 g_value_set_boolean (value, priv->scale_set);
1594 case PROP_PIXELS_ABOVE_LINES_SET:
1595 g_value_set_boolean (value, priv->pixels_above_lines_set);
1598 case PROP_PIXELS_BELOW_LINES_SET:
1599 g_value_set_boolean (value, priv->pixels_below_lines_set);
1602 case PROP_PIXELS_INSIDE_WRAP_SET:
1603 g_value_set_boolean (value, priv->pixels_inside_wrap_set);
1606 case PROP_EDITABLE_SET:
1607 g_value_set_boolean (value, priv->editable_set);
1610 case PROP_WRAP_MODE_SET:
1611 g_value_set_boolean (value, priv->wrap_mode_set);
1614 case PROP_JUSTIFICATION_SET:
1615 g_value_set_boolean (value, priv->justification_set);
1618 case PROP_LEFT_MARGIN_SET:
1619 g_value_set_boolean (value, priv->left_margin_set);
1622 case PROP_INDENT_SET:
1623 g_value_set_boolean (value, priv->indent_set);
1626 case PROP_STRIKETHROUGH_SET:
1627 g_value_set_boolean (value, priv->strikethrough_set);
1630 case PROP_RIGHT_MARGIN_SET:
1631 g_value_set_boolean (value, priv->right_margin_set);
1634 case PROP_UNDERLINE_SET:
1635 g_value_set_boolean (value, priv->underline_set);
1639 g_value_set_boolean (value, priv->rise_set);
1642 case PROP_BACKGROUND_FULL_HEIGHT_SET:
1643 g_value_set_boolean (value, priv->bg_full_height_set);
1646 case PROP_LANGUAGE_SET:
1647 g_value_set_boolean (value, priv->language_set);
1651 g_value_set_boolean (value, priv->tabs_set);
1654 case PROP_INVISIBLE_SET:
1655 g_value_set_boolean (value, priv->invisible_set);
1658 case PROP_PARAGRAPH_BACKGROUND_SET:
1659 g_value_set_boolean (value, priv->pg_bg_color_set);
1662 case PROP_BACKGROUND:
1663 case PROP_FOREGROUND:
1664 case PROP_PARAGRAPH_BACKGROUND:
1665 g_warning ("'foreground', 'background' and 'paragraph_background' properties are not readable, use 'foreground_gdk', 'background_gdk' and 'paragraph_background_gdk'");
1667 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1683 delta_priority_foreach (GtkTextTag *tag, gpointer user_data)
1685 GtkTextTagPrivate *priv = tag->priv;
1686 DeltaData *dd = user_data;
1688 if (priv->priority >= dd->low && priv->priority <= dd->high)
1689 priv->priority += dd->delta;
1693 * gtk_text_tag_get_priority:
1694 * @tag: a #GtkTextTag
1696 * Get the tag priority.
1698 * Return value: The tag's priority.
1701 gtk_text_tag_get_priority (GtkTextTag *tag)
1703 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), 0);
1705 return tag->priv->priority;
1709 * gtk_text_tag_set_priority:
1710 * @tag: a #GtkTextTag
1711 * @priority: the new priority
1713 * Sets the priority of a #GtkTextTag. Valid priorities are
1714 * start at 0 and go to one less than gtk_text_tag_table_get_size().
1715 * Each tag in a table has a unique priority; setting the priority
1716 * of one tag shifts the priorities of all the other tags in the
1717 * table to maintain a unique priority for each tag. Higher priority
1718 * tags "win" if two tags both set the same text attribute. When adding
1719 * a tag to a tag table, it will be assigned the highest priority in
1720 * the table by default; so normally the precedence of a set of tags
1721 * is the order in which they were added to the table, or created with
1722 * gtk_text_buffer_create_tag(), which adds the tag to the buffer's table
1726 gtk_text_tag_set_priority (GtkTextTag *tag,
1729 GtkTextTagPrivate *priv;
1732 g_return_if_fail (GTK_IS_TEXT_TAG (tag));
1736 g_return_if_fail (priv->table != NULL);
1737 g_return_if_fail (priority >= 0);
1738 g_return_if_fail (priority < gtk_text_tag_table_get_size (priv->table));
1740 if (priority == priv->priority)
1743 if (priority < priv->priority)
1746 dd.high = priv->priority - 1;
1751 dd.low = priv->priority + 1;
1756 gtk_text_tag_table_foreach (priv->table,
1757 delta_priority_foreach,
1760 priv->priority = priority;
1764 * gtk_text_tag_event:
1765 * @tag: a #GtkTextTag
1766 * @event_object: object that received the event, such as a widget
1768 * @iter: location where the event was received
1770 * Emits the "event" signal on the #GtkTextTag.
1772 * Return value: result of signal emission (whether the event was handled)
1775 gtk_text_tag_event (GtkTextTag *tag,
1776 GObject *event_object,
1778 const GtkTextIter *iter)
1780 gboolean retval = FALSE;
1782 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
1783 g_return_val_if_fail (G_IS_OBJECT (event_object), FALSE);
1784 g_return_val_if_fail (event != NULL, FALSE);
1798 tag_sort_func (gconstpointer first, gconstpointer second)
1800 GtkTextTag *tag1, *tag2;
1802 tag1 = * (GtkTextTag **) first;
1803 tag2 = * (GtkTextTag **) second;
1804 return tag1->priv->priority - tag2->priv->priority;
1808 _gtk_text_tag_array_sort (GtkTextTag** tag_array_p,
1813 GtkTextTag **maxPtrPtr, *tmp;
1815 g_return_if_fail (tag_array_p != NULL);
1816 g_return_if_fail (len > 0);
1822 GtkTextTag **iter = tag_array_p;
1824 for (i = len-1; i > 0; i--, iter++) {
1825 maxPtrPtr = tag = iter;
1826 prio = tag[0]->priv->priority;
1827 for (j = i, tag++; j > 0; j--, tag++) {
1828 if (tag[0]->priv->priority < prio) {
1829 prio = tag[0]->priv->priority;
1838 qsort ((void *) tag_array_p, (unsigned) len, sizeof (GtkTextTag *),
1844 printf ("Sorted tag array: \n");
1848 GtkTextTag *t = tag_array_p[i];
1849 printf (" %s priority %d\n", t->name, t->priority);
1862 * gtk_text_attributes_new:
1864 * Creates a #GtkTextAttributes, which describes
1865 * a set of properties on some text.
1867 * Return value: a new #GtkTextAttributes
1870 gtk_text_attributes_new (void)
1872 GtkTextAttributes *values;
1874 values = g_new0 (GtkTextAttributes, 1);
1876 /* 0 is a valid value for most of the struct */
1878 values->refcount = 1;
1880 values->language = gtk_get_default_language ();
1882 values->font_scale = 1.0;
1884 values->editable = TRUE;
1890 * gtk_text_attributes_copy:
1891 * @src: a #GtkTextAttributes to be copied
1893 * Copies @src and returns a new #GtkTextAttributes.
1895 * Return value: a copy of @src
1898 gtk_text_attributes_copy (GtkTextAttributes *src)
1900 GtkTextAttributes *dest;
1902 dest = gtk_text_attributes_new ();
1903 gtk_text_attributes_copy_values (src, dest);
1908 G_DEFINE_BOXED_TYPE (GtkTextAttributes, gtk_text_attributes,
1909 gtk_text_attributes_ref,
1910 gtk_text_attributes_unref)
1913 * gtk_text_attributes_copy_values:
1914 * @src: a #GtkTextAttributes
1915 * @dest: another #GtkTextAttributes
1917 * Copies the values from @src to @dest so that @dest has the same values
1918 * as @src. Frees existing values in @dest.
1921 gtk_text_attributes_copy_values (GtkTextAttributes *src,
1922 GtkTextAttributes *dest)
1924 guint orig_refcount;
1932 pango_font_description_free (dest->font);
1935 orig_refcount = dest->refcount;
1940 dest->tabs = pango_tab_array_copy (src->tabs);
1942 dest->language = src->language;
1945 dest->font = pango_font_description_copy (src->font);
1947 if (src->pg_bg_color)
1948 dest->pg_bg_color = gdk_color_copy (src->pg_bg_color);
1950 dest->refcount = orig_refcount;
1954 * gtk_text_attributes_ref:
1955 * @values: a #GtkTextAttributes
1957 * Increments the reference count on @values.
1959 * Returns: the #GtkTextAttributes that were passed in
1962 gtk_text_attributes_ref (GtkTextAttributes *values)
1964 g_return_val_if_fail (values != NULL, NULL);
1966 values->refcount += 1;
1972 * gtk_text_attributes_unref:
1973 * @values: a #GtkTextAttributes
1975 * Decrements the reference count on @values, freeing the structure
1976 * if the reference count reaches 0.
1979 gtk_text_attributes_unref (GtkTextAttributes *values)
1981 g_return_if_fail (values != NULL);
1982 g_return_if_fail (values->refcount > 0);
1984 values->refcount -= 1;
1986 if (values->refcount == 0)
1989 pango_tab_array_free (values->tabs);
1992 pango_font_description_free (values->font);
1994 if (values->pg_bg_color)
1995 gdk_color_free (values->pg_bg_color);
2002 _gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest,
2008 guint left_margin_accumulative = 0;
2009 guint right_margin_accumulative = 0;
2013 GtkTextTag *tag = tags[n];
2014 GtkTextAttributes *vals = tag->priv->values;
2016 g_assert (tag->priv->table != NULL);
2018 g_assert (tags[n]->priv->priority > tags[n-1]->priv->priority);
2020 if (tag->priv->bg_color_set)
2022 dest->appearance.bg_color = vals->appearance.bg_color;
2024 dest->appearance.draw_bg = TRUE;
2026 if (tag->priv->fg_color_set)
2027 dest->appearance.fg_color = vals->appearance.fg_color;
2029 if (tag->priv->pg_bg_color_set)
2031 dest->pg_bg_color = gdk_color_copy (vals->pg_bg_color);
2037 pango_font_description_merge (dest->font, vals->font, TRUE);
2039 dest->font = pango_font_description_copy (vals->font);
2042 /* multiply all the scales together to get a composite */
2043 if (tag->priv->scale_set)
2044 dest->font_scale *= vals->font_scale;
2046 if (tag->priv->justification_set)
2047 dest->justification = vals->justification;
2049 if (vals->direction != GTK_TEXT_DIR_NONE)
2050 dest->direction = vals->direction;
2052 if (tag->priv->left_margin_set)
2054 if (tag->priv->accumulative_margin)
2055 left_margin_accumulative += vals->left_margin;
2057 dest->left_margin = vals->left_margin;
2060 if (tag->priv->indent_set)
2061 dest->indent = vals->indent;
2063 if (tag->priv->rise_set)
2064 dest->appearance.rise = vals->appearance.rise;
2066 if (tag->priv->right_margin_set)
2068 if (tag->priv->accumulative_margin)
2069 right_margin_accumulative += vals->right_margin;
2071 dest->right_margin = vals->right_margin;
2074 if (tag->priv->pixels_above_lines_set)
2075 dest->pixels_above_lines = vals->pixels_above_lines;
2077 if (tag->priv->pixels_below_lines_set)
2078 dest->pixels_below_lines = vals->pixels_below_lines;
2080 if (tag->priv->pixels_inside_wrap_set)
2081 dest->pixels_inside_wrap = vals->pixels_inside_wrap;
2083 if (tag->priv->tabs_set)
2086 pango_tab_array_free (dest->tabs);
2087 dest->tabs = pango_tab_array_copy (vals->tabs);
2090 if (tag->priv->wrap_mode_set)
2091 dest->wrap_mode = vals->wrap_mode;
2093 if (tag->priv->underline_set)
2094 dest->appearance.underline = vals->appearance.underline;
2096 if (tag->priv->strikethrough_set)
2097 dest->appearance.strikethrough = vals->appearance.strikethrough;
2099 if (tag->priv->invisible_set)
2100 dest->invisible = vals->invisible;
2102 if (tag->priv->editable_set)
2103 dest->editable = vals->editable;
2105 if (tag->priv->bg_full_height_set)
2106 dest->bg_full_height = vals->bg_full_height;
2108 if (tag->priv->language_set)
2109 dest->language = vals->language;
2114 dest->left_margin += left_margin_accumulative;
2115 dest->right_margin += right_margin_accumulative;
2119 _gtk_text_tag_affects_size (GtkTextTag *tag)
2121 GtkTextTagPrivate *priv = tag->priv;
2124 (priv->values->font && pango_font_description_get_set_fields (priv->values->font) != 0) ||
2126 priv->justification_set ||
2127 priv->left_margin_set ||
2130 priv->right_margin_set ||
2131 priv->pixels_above_lines_set ||
2132 priv->pixels_below_lines_set ||
2133 priv->pixels_inside_wrap_set ||
2135 priv->underline_set ||
2136 priv->wrap_mode_set ||
2137 priv->invisible_set;
2141 _gtk_text_tag_affects_nonsize_appearance (GtkTextTag *tag)
2143 GtkTextTagPrivate *priv = tag->priv;
2146 priv->bg_color_set ||
2147 priv->fg_color_set ||
2148 priv->strikethrough_set ||
2149 priv->bg_full_height_set ||
2150 priv->pg_bg_color_set;