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.
52 #include "gtktexttag.h"
53 #include "gtktexttypes.h"
54 #include "gtktexttagtable.h"
56 #include "gtkmarshalers.h"
57 #include "gtkprivate.h"
87 PROP_PIXELS_ABOVE_LINES,
88 PROP_PIXELS_BELOW_LINES,
89 PROP_PIXELS_INSIDE_WRAP,
100 PROP_BACKGROUND_FULL_HEIGHT,
104 PROP_PARAGRAPH_BACKGROUND,
105 PROP_PARAGRAPH_BACKGROUND_GDK,
108 PROP_ACCUMULATIVE_MARGIN,
110 /* Whether-a-style-arg-is-set args */
120 PROP_PIXELS_ABOVE_LINES_SET,
121 PROP_PIXELS_BELOW_LINES_SET,
122 PROP_PIXELS_INSIDE_WRAP_SET,
125 PROP_JUSTIFICATION_SET,
126 PROP_LEFT_MARGIN_SET,
128 PROP_STRIKETHROUGH_SET,
129 PROP_RIGHT_MARGIN_SET,
132 PROP_BACKGROUND_FULL_HEIGHT_SET,
136 PROP_PARAGRAPH_BACKGROUND_SET,
140 static void gtk_text_tag_finalize (GObject *object);
141 static void gtk_text_tag_set_property (GObject *object,
145 static void gtk_text_tag_get_property (GObject *object,
150 static guint signals[LAST_SIGNAL] = { 0 };
152 G_DEFINE_TYPE (GtkTextTag, gtk_text_tag, G_TYPE_OBJECT)
155 gtk_text_tag_class_init (GtkTextTagClass *klass)
157 GObjectClass *object_class = G_OBJECT_CLASS (klass);
159 object_class->set_property = gtk_text_tag_set_property;
160 object_class->get_property = gtk_text_tag_get_property;
162 object_class->finalize = gtk_text_tag_finalize;
165 g_object_class_install_property (object_class,
167 g_param_spec_string ("name",
169 P_("Name used to refer to the text tag. NULL for anonymous tags"),
171 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
175 g_object_class_install_property (object_class,
177 g_param_spec_string ("background",
178 P_("Background color name"),
179 P_("Background color as a string"),
181 GTK_PARAM_WRITABLE));
183 g_object_class_install_property (object_class,
185 g_param_spec_boxed ("background-gdk",
186 P_("Background color"),
187 P_("Background color as a (possibly unallocated) GdkColor"),
189 GTK_PARAM_READWRITE));
191 g_object_class_install_property (object_class,
192 PROP_BACKGROUND_FULL_HEIGHT,
193 g_param_spec_boolean ("background-full-height",
194 P_("Background full height"),
195 P_("Whether the background color fills the entire line height or only the height of the tagged characters"),
197 GTK_PARAM_READWRITE));
199 g_object_class_install_property (object_class,
201 g_param_spec_string ("foreground",
202 P_("Foreground color name"),
203 P_("Foreground color as a string"),
205 GTK_PARAM_WRITABLE));
207 g_object_class_install_property (object_class,
209 g_param_spec_boxed ("foreground-gdk",
210 P_("Foreground color"),
211 P_("Foreground color as a (possibly unallocated) GdkColor"),
213 GTK_PARAM_READWRITE));
215 g_object_class_install_property (object_class,
217 g_param_spec_enum ("direction",
218 P_("Text direction"),
219 P_("Text direction, e.g. right-to-left or left-to-right"),
220 GTK_TYPE_TEXT_DIRECTION,
222 GTK_PARAM_READWRITE));
224 g_object_class_install_property (object_class,
226 g_param_spec_boolean ("editable",
228 P_("Whether the text can be modified by the user"),
230 GTK_PARAM_READWRITE));
235 * Font description as string, e.g. \"Sans Italic 12\".
237 * Note that the initial value of this property depends on
238 * the internals of #PangoFontDescription.
240 g_object_class_install_property (object_class,
242 g_param_spec_string ("font",
244 P_("Font description as a string, e.g. \"Sans Italic 12\""),
246 GTK_PARAM_READWRITE));
248 g_object_class_install_property (object_class,
250 g_param_spec_boxed ("font-desc",
252 P_("Font description as a PangoFontDescription struct"),
253 PANGO_TYPE_FONT_DESCRIPTION,
254 GTK_PARAM_READWRITE));
256 g_object_class_install_property (object_class,
258 g_param_spec_string ("family",
260 P_("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
262 GTK_PARAM_READWRITE));
264 g_object_class_install_property (object_class,
266 g_param_spec_enum ("style",
268 P_("Font style as a PangoStyle, e.g. PANGO_STYLE_ITALIC"),
271 GTK_PARAM_READWRITE));
273 g_object_class_install_property (object_class,
275 g_param_spec_enum ("variant",
277 P_("Font variant as a PangoVariant, e.g. PANGO_VARIANT_SMALL_CAPS"),
279 PANGO_VARIANT_NORMAL,
280 GTK_PARAM_READWRITE));
282 g_object_class_install_property (object_class,
284 g_param_spec_int ("weight",
286 P_("Font weight as an integer, see predefined values in PangoWeight; for example, PANGO_WEIGHT_BOLD"),
290 GTK_PARAM_READWRITE));
293 g_object_class_install_property (object_class,
295 g_param_spec_enum ("stretch",
297 P_("Font stretch as a PangoStretch, e.g. PANGO_STRETCH_CONDENSED"),
299 PANGO_STRETCH_NORMAL,
300 GTK_PARAM_READWRITE));
302 g_object_class_install_property (object_class,
304 g_param_spec_int ("size",
306 P_("Font size in Pango units"),
310 GTK_PARAM_READWRITE));
312 g_object_class_install_property (object_class,
314 g_param_spec_double ("scale",
316 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"),
320 GTK_PARAM_READWRITE));
322 g_object_class_install_property (object_class,
324 g_param_spec_double ("size-points",
326 P_("Font size in points"),
330 GTK_PARAM_READWRITE));
332 g_object_class_install_property (object_class,
334 g_param_spec_enum ("justification",
336 P_("Left, right, or center justification"),
337 GTK_TYPE_JUSTIFICATION,
339 GTK_PARAM_READWRITE));
342 * GtkTextTag:language:
344 * The language this text is in, as an ISO code. Pango can use this as a
345 * hint when rendering the text. If not set, an appropriate default will be
348 * Note that the initial value of this property depends on the current
349 * locale, see also gtk_get_default_language().
351 g_object_class_install_property (object_class,
353 g_param_spec_string ("language",
355 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."),
357 GTK_PARAM_READWRITE));
359 g_object_class_install_property (object_class,
361 g_param_spec_int ("left-margin",
363 P_("Width of the left margin in pixels"),
367 GTK_PARAM_READWRITE));
369 g_object_class_install_property (object_class,
371 g_param_spec_int ("right-margin",
373 P_("Width of the right margin in pixels"),
377 GTK_PARAM_READWRITE));
380 g_object_class_install_property (object_class,
382 g_param_spec_int ("indent",
384 P_("Amount to indent the paragraph, in pixels"),
388 GTK_PARAM_READWRITE));
391 g_object_class_install_property (object_class,
393 g_param_spec_int ("rise",
395 P_("Offset of text above the baseline (below the baseline if rise is negative) in Pango units"),
399 GTK_PARAM_READWRITE));
401 g_object_class_install_property (object_class,
402 PROP_PIXELS_ABOVE_LINES,
403 g_param_spec_int ("pixels-above-lines",
404 P_("Pixels above lines"),
405 P_("Pixels of blank space above paragraphs"),
409 GTK_PARAM_READWRITE));
411 g_object_class_install_property (object_class,
412 PROP_PIXELS_BELOW_LINES,
413 g_param_spec_int ("pixels-below-lines",
414 P_("Pixels below lines"),
415 P_("Pixels of blank space below paragraphs"),
419 GTK_PARAM_READWRITE));
421 g_object_class_install_property (object_class,
422 PROP_PIXELS_INSIDE_WRAP,
423 g_param_spec_int ("pixels-inside-wrap",
424 P_("Pixels inside wrap"),
425 P_("Pixels of blank space between wrapped lines in a paragraph"),
429 GTK_PARAM_READWRITE));
431 g_object_class_install_property (object_class,
433 g_param_spec_boolean ("strikethrough",
435 P_("Whether to strike through the text"),
437 GTK_PARAM_READWRITE));
439 g_object_class_install_property (object_class,
441 g_param_spec_enum ("underline",
443 P_("Style of underline for this text"),
444 PANGO_TYPE_UNDERLINE,
445 PANGO_UNDERLINE_NONE,
446 GTK_PARAM_READWRITE));
448 g_object_class_install_property (object_class,
450 g_param_spec_enum ("wrap-mode",
452 P_("Whether to wrap lines never, at word boundaries, or at character boundaries"),
455 GTK_PARAM_READWRITE));
458 g_object_class_install_property (object_class,
460 g_param_spec_boxed ("tabs",
462 P_("Custom tabs for this text"),
463 PANGO_TYPE_TAB_ARRAY,
464 GTK_PARAM_READWRITE));
467 * GtkTextTag:invisible:
469 * Whether this text is hidden.
471 * Note that there may still be problems with the support for invisible
472 * text, in particular when navigating programmatically inside a buffer
473 * containing invisible segments.
477 g_object_class_install_property (object_class,
479 g_param_spec_boolean ("invisible",
481 P_("Whether this text is hidden."),
483 GTK_PARAM_READWRITE));
486 * GtkTextTag:paragraph-background:
488 * The paragraph background color as a string.
492 g_object_class_install_property (object_class,
493 PROP_PARAGRAPH_BACKGROUND,
494 g_param_spec_string ("paragraph-background",
495 P_("Paragraph background color name"),
496 P_("Paragraph background color as a string"),
498 GTK_PARAM_WRITABLE));
501 * GtkTextTag:paragraph-background-gdk:
503 * The paragraph background color as a as a (possibly unallocated)
508 g_object_class_install_property (object_class,
509 PROP_PARAGRAPH_BACKGROUND_GDK,
510 g_param_spec_boxed ("paragraph-background-gdk",
511 P_("Paragraph background color"),
512 P_("Paragraph background color as a (possibly unallocated) GdkColor"),
514 GTK_PARAM_READWRITE));
517 * GtkTextTag:accumulative-margin:
519 * Whether the margins accumulate or override each other.
521 * When set to %TRUE the margins of this tag are added to the margins
522 * of any other non-accumulative margins present. When set to %FALSE
523 * the margins override one another (the default).
527 g_object_class_install_property (object_class,
528 PROP_ACCUMULATIVE_MARGIN,
529 g_param_spec_boolean ("accumulative-margin",
530 P_("Margin Accumulates"),
531 P_("Whether left and right margins accumulate."),
533 GTK_PARAM_READWRITE));
535 /* Style props are set or not */
537 #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))
539 ADD_SET_PROP ("background-set", PROP_BACKGROUND_SET,
540 P_("Background set"),
541 P_("Whether this tag affects the background color"));
543 ADD_SET_PROP ("background-full-height-set", PROP_BACKGROUND_FULL_HEIGHT_SET,
544 P_("Background full height set"),
545 P_("Whether this tag affects background height"));
547 ADD_SET_PROP ("foreground-set", PROP_FOREGROUND_SET,
548 P_("Foreground set"),
549 P_("Whether this tag affects the foreground color"));
551 ADD_SET_PROP ("editable-set", PROP_EDITABLE_SET,
552 P_("Editability set"),
553 P_("Whether this tag affects text editability"));
555 ADD_SET_PROP ("family-set", PROP_FAMILY_SET,
556 P_("Font family set"),
557 P_("Whether this tag affects the font family"));
559 ADD_SET_PROP ("style-set", PROP_STYLE_SET,
560 P_("Font style set"),
561 P_("Whether this tag affects the font style"));
563 ADD_SET_PROP ("variant-set", PROP_VARIANT_SET,
564 P_("Font variant set"),
565 P_("Whether this tag affects the font variant"));
567 ADD_SET_PROP ("weight-set", PROP_WEIGHT_SET,
568 P_("Font weight set"),
569 P_("Whether this tag affects the font weight"));
571 ADD_SET_PROP ("stretch-set", PROP_STRETCH_SET,
572 P_("Font stretch set"),
573 P_("Whether this tag affects the font stretch"));
575 ADD_SET_PROP ("size-set", PROP_SIZE_SET,
577 P_("Whether this tag affects the font size"));
579 ADD_SET_PROP ("scale-set", PROP_SCALE_SET,
580 P_("Font scale set"),
581 P_("Whether this tag scales the font size by a factor"));
583 ADD_SET_PROP ("justification-set", PROP_JUSTIFICATION_SET,
584 P_("Justification set"),
585 P_("Whether this tag affects paragraph justification"));
587 ADD_SET_PROP ("language-set", PROP_LANGUAGE_SET,
589 P_("Whether this tag affects the language the text is rendered as"));
591 ADD_SET_PROP ("left-margin-set", PROP_LEFT_MARGIN_SET,
592 P_("Left margin set"),
593 P_("Whether this tag affects the left margin"));
595 ADD_SET_PROP ("indent-set", PROP_INDENT_SET,
597 P_("Whether this tag affects indentation"));
599 ADD_SET_PROP ("rise-set", PROP_RISE_SET,
601 P_("Whether this tag affects the rise"));
603 ADD_SET_PROP ("pixels-above-lines-set", PROP_PIXELS_ABOVE_LINES_SET,
604 P_("Pixels above lines set"),
605 P_("Whether this tag affects the number of pixels above lines"));
607 ADD_SET_PROP ("pixels-below-lines-set", PROP_PIXELS_BELOW_LINES_SET,
608 P_("Pixels below lines set"),
609 P_("Whether this tag affects the number of pixels above lines"));
611 ADD_SET_PROP ("pixels-inside-wrap-set", PROP_PIXELS_INSIDE_WRAP_SET,
612 P_("Pixels inside wrap set"),
613 P_("Whether this tag affects the number of pixels between wrapped lines"));
615 ADD_SET_PROP ("strikethrough-set", PROP_STRIKETHROUGH_SET,
616 P_("Strikethrough set"),
617 P_("Whether this tag affects strikethrough"));
619 ADD_SET_PROP ("right-margin-set", PROP_RIGHT_MARGIN_SET,
620 P_("Right margin set"),
621 P_("Whether this tag affects the right margin"));
623 ADD_SET_PROP ("underline-set", PROP_UNDERLINE_SET,
625 P_("Whether this tag affects underlining"));
627 ADD_SET_PROP ("wrap-mode-set", PROP_WRAP_MODE_SET,
629 P_("Whether this tag affects line wrap mode"));
631 ADD_SET_PROP ("tabs-set", PROP_TABS_SET,
633 P_("Whether this tag affects tabs"));
635 ADD_SET_PROP ("invisible-set", PROP_INVISIBLE_SET,
637 P_("Whether this tag affects text visibility"));
639 ADD_SET_PROP ("paragraph-background-set", PROP_PARAGRAPH_BACKGROUND_SET,
640 P_("Paragraph background set"),
641 P_("Whether this tag affects the paragraph background color"));
645 * @tag: the #GtkTextTag on which the signal is emitted
646 * @object: the object the event was fired from (typically a #GtkTextView)
647 * @event: the event which triggered the signal
648 * @iter: a #GtkTextIter pointing at the location the event occured
650 * The ::event signal is emitted when an event occurs on a region of the
651 * buffer marked with this tag.
653 * Returns: %TRUE to stop other handlers from being invoked for the
654 * event. %FALSE to propagate the event further.
657 g_signal_new (I_("event"),
658 G_OBJECT_CLASS_TYPE (object_class),
660 G_STRUCT_OFFSET (GtkTextTagClass, event),
661 _gtk_boolean_handled_accumulator, NULL,
662 _gtk_marshal_BOOLEAN__OBJECT_BOXED_BOXED,
666 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE,
671 gtk_text_tag_init (GtkTextTag *text_tag)
673 text_tag->values = gtk_text_attributes_new ();
678 * @name: (allow-none): tag name, or %NULL
680 * Creates a #GtkTextTag. Configure the tag using object arguments,
681 * i.e. using g_object_set().
683 * Return value: a new #GtkTextTag
686 gtk_text_tag_new (const gchar *name)
690 tag = g_object_new (GTK_TYPE_TEXT_TAG, "name", name, NULL);
696 gtk_text_tag_finalize (GObject *object)
698 GtkTextTag *text_tag;
700 text_tag = GTK_TEXT_TAG (object);
703 gtk_text_tag_table_remove (text_tag->table, text_tag);
705 g_assert (text_tag->table == NULL);
707 gtk_text_attributes_unref (text_tag->values);
708 text_tag->values = NULL;
710 g_free (text_tag->name);
711 text_tag->name = NULL;
713 G_OBJECT_CLASS (gtk_text_tag_parent_class)->finalize (object);
717 set_bg_color (GtkTextTag *tag, GdkColor *color)
721 if (!tag->bg_color_set)
723 tag->bg_color_set = TRUE;
724 g_object_notify (G_OBJECT (tag), "background-set");
727 tag->values->appearance.bg_color = *color;
731 if (tag->bg_color_set)
733 tag->bg_color_set = FALSE;
734 g_object_notify (G_OBJECT (tag), "background-set");
740 set_fg_color (GtkTextTag *tag, GdkColor *color)
744 if (!tag->fg_color_set)
746 tag->fg_color_set = TRUE;
747 g_object_notify (G_OBJECT (tag), "foreground-set");
749 tag->values->appearance.fg_color = *color;
753 if (tag->fg_color_set)
755 tag->fg_color_set = FALSE;
756 g_object_notify (G_OBJECT (tag), "foreground-set");
762 set_pg_bg_color (GtkTextTag *tag, GdkColor *color)
766 if (!tag->pg_bg_color_set)
768 tag->pg_bg_color_set = TRUE;
769 g_object_notify (G_OBJECT (tag), "paragraph-background-set");
772 gdk_color_free (tag->values->pg_bg_color);
774 tag->values->pg_bg_color = gdk_color_copy (color);
778 if (tag->pg_bg_color_set)
780 tag->pg_bg_color_set = FALSE;
781 g_object_notify (G_OBJECT (tag), "paragraph-background-set");
782 gdk_color_free (tag->values->pg_bg_color);
785 tag->values->pg_bg_color = NULL;
790 get_property_font_set_mask (guint prop_id)
794 case PROP_FAMILY_SET:
795 return PANGO_FONT_MASK_FAMILY;
797 return PANGO_FONT_MASK_STYLE;
798 case PROP_VARIANT_SET:
799 return PANGO_FONT_MASK_VARIANT;
800 case PROP_WEIGHT_SET:
801 return PANGO_FONT_MASK_WEIGHT;
802 case PROP_STRETCH_SET:
803 return PANGO_FONT_MASK_STRETCH;
805 return PANGO_FONT_MASK_SIZE;
812 set_font_desc_fields (PangoFontDescription *desc,
813 PangoFontMask to_set)
815 PangoFontMask changed_mask = 0;
817 if (to_set & PANGO_FONT_MASK_FAMILY)
819 const char *family = pango_font_description_get_family (desc);
823 changed_mask |= PANGO_FONT_MASK_FAMILY;
826 pango_font_description_set_family (desc, family);
828 if (to_set & PANGO_FONT_MASK_STYLE)
829 pango_font_description_set_style (desc, pango_font_description_get_style (desc));
830 if (to_set & PANGO_FONT_MASK_VARIANT)
831 pango_font_description_set_variant (desc, pango_font_description_get_variant (desc));
832 if (to_set & PANGO_FONT_MASK_WEIGHT)
833 pango_font_description_set_weight (desc, pango_font_description_get_weight (desc));
834 if (to_set & PANGO_FONT_MASK_STRETCH)
835 pango_font_description_set_stretch (desc, pango_font_description_get_stretch (desc));
836 if (to_set & PANGO_FONT_MASK_SIZE)
838 gint size = pango_font_description_get_size (desc);
841 size = 10 * PANGO_SCALE;
842 changed_mask |= PANGO_FONT_MASK_SIZE;
845 pango_font_description_set_size (desc, size);
852 notify_set_changed (GObject *object,
853 PangoFontMask changed_mask)
855 if (changed_mask & PANGO_FONT_MASK_FAMILY)
856 g_object_notify (object, "family-set");
857 if (changed_mask & PANGO_FONT_MASK_STYLE)
858 g_object_notify (object, "style-set");
859 if (changed_mask & PANGO_FONT_MASK_VARIANT)
860 g_object_notify (object, "variant-set");
861 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
862 g_object_notify (object, "weight-set");
863 if (changed_mask & PANGO_FONT_MASK_STRETCH)
864 g_object_notify (object, "stretch-set");
865 if (changed_mask & PANGO_FONT_MASK_SIZE)
866 g_object_notify (object, "size-set");
870 notify_fields_changed (GObject *object,
871 PangoFontMask changed_mask)
873 if (changed_mask & PANGO_FONT_MASK_FAMILY)
874 g_object_notify (object, "family");
875 if (changed_mask & PANGO_FONT_MASK_STYLE)
876 g_object_notify (object, "style");
877 if (changed_mask & PANGO_FONT_MASK_VARIANT)
878 g_object_notify (object, "variant");
879 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
880 g_object_notify (object, "weight");
881 if (changed_mask & PANGO_FONT_MASK_STRETCH)
882 g_object_notify (object, "stretch");
883 if (changed_mask & PANGO_FONT_MASK_SIZE)
884 g_object_notify (object, "size");
888 set_font_description (GtkTextTag *text_tag,
889 PangoFontDescription *font_desc)
891 GObject *object = G_OBJECT (text_tag);
892 PangoFontDescription *new_font_desc;
893 PangoFontMask old_mask, new_mask, changed_mask, set_changed_mask;
896 new_font_desc = pango_font_description_copy (font_desc);
898 new_font_desc = pango_font_description_new ();
900 if (text_tag->values->font)
901 old_mask = pango_font_description_get_set_fields (text_tag->values->font);
905 new_mask = pango_font_description_get_set_fields (new_font_desc);
907 changed_mask = old_mask | new_mask;
908 set_changed_mask = old_mask ^ new_mask;
910 if (text_tag->values->font)
911 pango_font_description_free (text_tag->values->font);
912 text_tag->values->font = new_font_desc;
914 g_object_freeze_notify (object);
916 g_object_notify (object, "font-desc");
917 g_object_notify (object, "font");
919 if (changed_mask & PANGO_FONT_MASK_FAMILY)
920 g_object_notify (object, "family");
921 if (changed_mask & PANGO_FONT_MASK_STYLE)
922 g_object_notify (object, "style");
923 if (changed_mask & PANGO_FONT_MASK_VARIANT)
924 g_object_notify (object, "variant");
925 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
926 g_object_notify (object, "weight");
927 if (changed_mask & PANGO_FONT_MASK_STRETCH)
928 g_object_notify (object, "stretch");
929 if (changed_mask & PANGO_FONT_MASK_SIZE)
931 g_object_notify (object, "size");
932 g_object_notify (object, "size-points");
935 notify_set_changed (object, set_changed_mask);
937 g_object_thaw_notify (object);
941 gtk_text_tag_ensure_font (GtkTextTag *text_tag)
943 if (!text_tag->values->font)
944 text_tag->values->font = pango_font_description_new ();
948 gtk_text_tag_set_property (GObject *object,
953 GtkTextTag *text_tag;
954 gboolean size_changed = FALSE;
956 text_tag = GTK_TEXT_TAG (object);
961 g_return_if_fail (text_tag->name == NULL);
962 text_tag->name = g_value_dup_string (value);
965 case PROP_BACKGROUND:
969 if (!g_value_get_string (value))
970 set_bg_color (text_tag, NULL); /* reset to background_set to FALSE */
971 else if (gdk_color_parse (g_value_get_string (value), &color))
972 set_bg_color (text_tag, &color);
974 g_warning ("Don't know color `%s'", g_value_get_string (value));
976 g_object_notify (object, "background-gdk");
980 case PROP_FOREGROUND:
984 if (!g_value_get_string (value))
985 set_fg_color (text_tag, NULL); /* reset to foreground_set to FALSE */
986 else if (gdk_color_parse (g_value_get_string (value), &color))
987 set_fg_color (text_tag, &color);
989 g_warning ("Don't know color `%s'", g_value_get_string (value));
991 g_object_notify (object, "foreground-gdk");
995 case PROP_BACKGROUND_GDK:
997 GdkColor *color = g_value_get_boxed (value);
999 set_bg_color (text_tag, color);
1003 case PROP_FOREGROUND_GDK:
1005 GdkColor *color = g_value_get_boxed (value);
1007 set_fg_color (text_tag, color);
1013 PangoFontDescription *font_desc = NULL;
1016 name = g_value_get_string (value);
1019 font_desc = pango_font_description_from_string (name);
1021 set_font_description (text_tag, font_desc);
1023 pango_font_description_free (font_desc);
1025 size_changed = TRUE;
1029 case PROP_FONT_DESC:
1031 PangoFontDescription *font_desc;
1033 font_desc = g_value_get_boxed (value);
1035 set_font_description (text_tag, font_desc);
1037 size_changed = TRUE;
1047 case PROP_SIZE_POINTS:
1049 PangoFontMask old_set_mask;
1051 gtk_text_tag_ensure_font (text_tag);
1052 old_set_mask = pango_font_description_get_set_fields (text_tag->values->font);
1057 pango_font_description_set_family (text_tag->values->font,
1058 g_value_get_string (value));
1061 pango_font_description_set_style (text_tag->values->font,
1062 g_value_get_enum (value));
1065 pango_font_description_set_variant (text_tag->values->font,
1066 g_value_get_enum (value));
1069 pango_font_description_set_weight (text_tag->values->font,
1070 g_value_get_int (value));
1073 pango_font_description_set_stretch (text_tag->values->font,
1074 g_value_get_enum (value));
1077 pango_font_description_set_size (text_tag->values->font,
1078 g_value_get_int (value));
1079 g_object_notify (object, "size-points");
1081 case PROP_SIZE_POINTS:
1082 pango_font_description_set_size (text_tag->values->font,
1083 g_value_get_double (value) * PANGO_SCALE);
1084 g_object_notify (object, "size");
1088 size_changed = TRUE;
1089 notify_set_changed (object, old_set_mask & pango_font_description_get_set_fields (text_tag->values->font));
1090 g_object_notify (object, "font-desc");
1091 g_object_notify (object, "font");
1097 text_tag->values->font_scale = g_value_get_double (value);
1098 text_tag->scale_set = TRUE;
1099 g_object_notify (object, "scale-set");
1100 size_changed = TRUE;
1103 case PROP_PIXELS_ABOVE_LINES:
1104 text_tag->pixels_above_lines_set = TRUE;
1105 text_tag->values->pixels_above_lines = g_value_get_int (value);
1106 g_object_notify (object, "pixels-above-lines-set");
1107 size_changed = TRUE;
1110 case PROP_PIXELS_BELOW_LINES:
1111 text_tag->pixels_below_lines_set = TRUE;
1112 text_tag->values->pixels_below_lines = g_value_get_int (value);
1113 g_object_notify (object, "pixels-below-lines-set");
1114 size_changed = TRUE;
1117 case PROP_PIXELS_INSIDE_WRAP:
1118 text_tag->pixels_inside_wrap_set = TRUE;
1119 text_tag->values->pixels_inside_wrap = g_value_get_int (value);
1120 g_object_notify (object, "pixels-inside-wrap-set");
1121 size_changed = TRUE;
1125 text_tag->editable_set = TRUE;
1126 text_tag->values->editable = g_value_get_boolean (value);
1127 g_object_notify (object, "editable-set");
1130 case PROP_WRAP_MODE:
1131 text_tag->wrap_mode_set = TRUE;
1132 text_tag->values->wrap_mode = g_value_get_enum (value);
1133 g_object_notify (object, "wrap-mode-set");
1134 size_changed = TRUE;
1137 case PROP_JUSTIFICATION:
1138 text_tag->justification_set = TRUE;
1139 text_tag->values->justification = g_value_get_enum (value);
1140 g_object_notify (object, "justification-set");
1141 size_changed = TRUE;
1144 case PROP_DIRECTION:
1145 text_tag->values->direction = g_value_get_enum (value);
1148 case PROP_LEFT_MARGIN:
1149 text_tag->left_margin_set = TRUE;
1150 text_tag->values->left_margin = g_value_get_int (value);
1151 g_object_notify (object, "left-margin-set");
1152 size_changed = TRUE;
1156 text_tag->indent_set = TRUE;
1157 text_tag->values->indent = g_value_get_int (value);
1158 g_object_notify (object, "indent-set");
1159 size_changed = TRUE;
1162 case PROP_STRIKETHROUGH:
1163 text_tag->strikethrough_set = TRUE;
1164 text_tag->values->appearance.strikethrough = g_value_get_boolean (value);
1165 g_object_notify (object, "strikethrough-set");
1168 case PROP_RIGHT_MARGIN:
1169 text_tag->right_margin_set = TRUE;
1170 text_tag->values->right_margin = g_value_get_int (value);
1171 g_object_notify (object, "right-margin-set");
1172 size_changed = TRUE;
1175 case PROP_UNDERLINE:
1176 text_tag->underline_set = TRUE;
1177 text_tag->values->appearance.underline = g_value_get_enum (value);
1178 g_object_notify (object, "underline-set");
1182 text_tag->rise_set = TRUE;
1183 text_tag->values->appearance.rise = g_value_get_int (value);
1184 g_object_notify (object, "rise-set");
1185 size_changed = TRUE;
1188 case PROP_BACKGROUND_FULL_HEIGHT:
1189 text_tag->bg_full_height_set = TRUE;
1190 text_tag->values->bg_full_height = g_value_get_boolean (value);
1191 g_object_notify (object, "background-full-height-set");
1195 text_tag->language_set = TRUE;
1196 text_tag->values->language = pango_language_from_string (g_value_get_string (value));
1197 g_object_notify (object, "language-set");
1201 text_tag->tabs_set = TRUE;
1203 if (text_tag->values->tabs)
1204 pango_tab_array_free (text_tag->values->tabs);
1206 /* FIXME I'm not sure if this is a memleak or not */
1207 text_tag->values->tabs =
1208 pango_tab_array_copy (g_value_get_boxed (value));
1210 g_object_notify (object, "tabs-set");
1212 size_changed = TRUE;
1215 case PROP_INVISIBLE:
1216 text_tag->invisible_set = TRUE;
1217 text_tag->values->invisible = g_value_get_boolean (value);
1218 g_object_notify (object, "invisible-set");
1219 size_changed = TRUE;
1222 case PROP_PARAGRAPH_BACKGROUND:
1226 if (!g_value_get_string (value))
1227 set_pg_bg_color (text_tag, NULL); /* reset to paragraph_background_set to FALSE */
1228 else if (gdk_color_parse (g_value_get_string (value), &color))
1229 set_pg_bg_color (text_tag, &color);
1231 g_warning ("Don't know color `%s'", g_value_get_string (value));
1233 g_object_notify (object, "paragraph-background-gdk");
1237 case PROP_PARAGRAPH_BACKGROUND_GDK:
1239 GdkColor *color = g_value_get_boxed (value);
1241 set_pg_bg_color (text_tag, color);
1245 case PROP_ACCUMULATIVE_MARGIN:
1246 text_tag->accumulative_margin = g_value_get_boolean (value);
1247 g_object_notify (object, "accumulative-margin");
1248 size_changed = TRUE;
1251 /* Whether the value should be used... */
1253 case PROP_BACKGROUND_SET:
1254 text_tag->bg_color_set = g_value_get_boolean (value);
1257 case PROP_FOREGROUND_SET:
1258 text_tag->fg_color_set = g_value_get_boolean (value);
1261 case PROP_FAMILY_SET:
1262 case PROP_STYLE_SET:
1263 case PROP_VARIANT_SET:
1264 case PROP_WEIGHT_SET:
1265 case PROP_STRETCH_SET:
1267 if (!g_value_get_boolean (value))
1269 if (text_tag->values->font)
1270 pango_font_description_unset_fields (text_tag->values->font,
1271 get_property_font_set_mask (prop_id));
1275 PangoFontMask changed_mask;
1277 gtk_text_tag_ensure_font (text_tag);
1278 changed_mask = set_font_desc_fields (text_tag->values->font,
1279 get_property_font_set_mask (prop_id));
1280 notify_fields_changed (G_OBJECT (text_tag), changed_mask);
1284 case PROP_SCALE_SET:
1285 text_tag->scale_set = g_value_get_boolean (value);
1286 size_changed = TRUE;
1289 case PROP_PIXELS_ABOVE_LINES_SET:
1290 text_tag->pixels_above_lines_set = g_value_get_boolean (value);
1291 size_changed = TRUE;
1294 case PROP_PIXELS_BELOW_LINES_SET:
1295 text_tag->pixels_below_lines_set = g_value_get_boolean (value);
1296 size_changed = TRUE;
1299 case PROP_PIXELS_INSIDE_WRAP_SET:
1300 text_tag->pixels_inside_wrap_set = g_value_get_boolean (value);
1301 size_changed = TRUE;
1304 case PROP_EDITABLE_SET:
1305 text_tag->editable_set = g_value_get_boolean (value);
1308 case PROP_WRAP_MODE_SET:
1309 text_tag->wrap_mode_set = g_value_get_boolean (value);
1310 size_changed = TRUE;
1313 case PROP_JUSTIFICATION_SET:
1314 text_tag->justification_set = g_value_get_boolean (value);
1315 size_changed = TRUE;
1318 case PROP_LEFT_MARGIN_SET:
1319 text_tag->left_margin_set = g_value_get_boolean (value);
1320 size_changed = TRUE;
1323 case PROP_INDENT_SET:
1324 text_tag->indent_set = g_value_get_boolean (value);
1325 size_changed = TRUE;
1328 case PROP_STRIKETHROUGH_SET:
1329 text_tag->strikethrough_set = g_value_get_boolean (value);
1332 case PROP_RIGHT_MARGIN_SET:
1333 text_tag->right_margin_set = g_value_get_boolean (value);
1334 size_changed = TRUE;
1337 case PROP_UNDERLINE_SET:
1338 text_tag->underline_set = g_value_get_boolean (value);
1342 text_tag->rise_set = g_value_get_boolean (value);
1343 size_changed = TRUE;
1346 case PROP_BACKGROUND_FULL_HEIGHT_SET:
1347 text_tag->bg_full_height_set = g_value_get_boolean (value);
1350 case PROP_LANGUAGE_SET:
1351 text_tag->language_set = g_value_get_boolean (value);
1352 size_changed = TRUE;
1356 text_tag->tabs_set = g_value_get_boolean (value);
1357 size_changed = TRUE;
1360 case PROP_INVISIBLE_SET:
1361 text_tag->invisible_set = g_value_get_boolean (value);
1362 size_changed = TRUE;
1365 case PROP_PARAGRAPH_BACKGROUND_SET:
1366 text_tag->pg_bg_color_set = g_value_get_boolean (value);
1370 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1374 /* FIXME I would like to do this after all set_property in a single
1375 * g_object_set () have been called. But an idle function won't
1376 * work; we need to emit when the tag is changed, not when we get
1377 * around to the event loop. So blah, we eat some inefficiency.
1380 /* This is also somewhat weird since we emit another object's
1381 * signal here, but the two objects are already tightly bound.
1384 if (text_tag->table)
1385 g_signal_emit_by_name (text_tag->table,
1387 text_tag, size_changed);
1391 gtk_text_tag_get_property (GObject *object,
1398 tag = GTK_TEXT_TAG (object);
1403 g_value_set_string (value, tag->name);
1406 case PROP_BACKGROUND_GDK:
1407 g_value_set_boxed (value, &tag->values->appearance.bg_color);
1410 case PROP_FOREGROUND_GDK:
1411 g_value_set_boxed (value, &tag->values->appearance.fg_color);
1418 gtk_text_tag_ensure_font (tag);
1420 str = pango_font_description_to_string (tag->values->font);
1421 g_value_take_string (value, str);
1425 case PROP_FONT_DESC:
1426 gtk_text_tag_ensure_font (tag);
1427 g_value_set_boxed (value, tag->values->font);
1436 case PROP_SIZE_POINTS:
1437 gtk_text_tag_ensure_font (tag);
1441 g_value_set_string (value, pango_font_description_get_family (tag->values->font));
1445 g_value_set_enum (value, pango_font_description_get_style (tag->values->font));
1449 g_value_set_enum (value, pango_font_description_get_variant (tag->values->font));
1453 g_value_set_int (value, pango_font_description_get_weight (tag->values->font));
1457 g_value_set_enum (value, pango_font_description_get_stretch (tag->values->font));
1461 g_value_set_int (value, pango_font_description_get_size (tag->values->font));
1464 case PROP_SIZE_POINTS:
1465 g_value_set_double (value, ((double)pango_font_description_get_size (tag->values->font)) / (double)PANGO_SCALE);
1471 g_value_set_double (value, tag->values->font_scale);
1474 case PROP_PIXELS_ABOVE_LINES:
1475 g_value_set_int (value, tag->values->pixels_above_lines);
1478 case PROP_PIXELS_BELOW_LINES:
1479 g_value_set_int (value, tag->values->pixels_below_lines);
1482 case PROP_PIXELS_INSIDE_WRAP:
1483 g_value_set_int (value, tag->values->pixels_inside_wrap);
1487 g_value_set_boolean (value, tag->values->editable);
1490 case PROP_WRAP_MODE:
1491 g_value_set_enum (value, tag->values->wrap_mode);
1494 case PROP_JUSTIFICATION:
1495 g_value_set_enum (value, tag->values->justification);
1498 case PROP_DIRECTION:
1499 g_value_set_enum (value, tag->values->direction);
1502 case PROP_LEFT_MARGIN:
1503 g_value_set_int (value, tag->values->left_margin);
1507 g_value_set_int (value, tag->values->indent);
1510 case PROP_STRIKETHROUGH:
1511 g_value_set_boolean (value, tag->values->appearance.strikethrough);
1514 case PROP_RIGHT_MARGIN:
1515 g_value_set_int (value, tag->values->right_margin);
1518 case PROP_UNDERLINE:
1519 g_value_set_enum (value, tag->values->appearance.underline);
1523 g_value_set_int (value, tag->values->appearance.rise);
1526 case PROP_BACKGROUND_FULL_HEIGHT:
1527 g_value_set_boolean (value, tag->values->bg_full_height);
1531 g_value_set_string (value, pango_language_to_string (tag->values->language));
1535 if (tag->values->tabs)
1536 g_value_set_boxed (value, tag->values->tabs);
1539 case PROP_INVISIBLE:
1540 g_value_set_boolean (value, tag->values->invisible);
1543 case PROP_PARAGRAPH_BACKGROUND_GDK:
1544 g_value_set_boxed (value, tag->values->pg_bg_color);
1547 case PROP_ACCUMULATIVE_MARGIN:
1548 g_value_set_boolean (value, tag->accumulative_margin);
1551 case PROP_BACKGROUND_SET:
1552 g_value_set_boolean (value, tag->bg_color_set);
1555 case PROP_FOREGROUND_SET:
1556 g_value_set_boolean (value, tag->fg_color_set);
1559 case PROP_FAMILY_SET:
1560 case PROP_STYLE_SET:
1561 case PROP_VARIANT_SET:
1562 case PROP_WEIGHT_SET:
1563 case PROP_STRETCH_SET:
1566 PangoFontMask set_mask = tag->values->font ? pango_font_description_get_set_fields (tag->values->font) : 0;
1567 PangoFontMask test_mask = get_property_font_set_mask (prop_id);
1568 g_value_set_boolean (value, (set_mask & test_mask) != 0);
1573 case PROP_SCALE_SET:
1574 g_value_set_boolean (value, tag->scale_set);
1577 case PROP_PIXELS_ABOVE_LINES_SET:
1578 g_value_set_boolean (value, tag->pixels_above_lines_set);
1581 case PROP_PIXELS_BELOW_LINES_SET:
1582 g_value_set_boolean (value, tag->pixels_below_lines_set);
1585 case PROP_PIXELS_INSIDE_WRAP_SET:
1586 g_value_set_boolean (value, tag->pixels_inside_wrap_set);
1589 case PROP_EDITABLE_SET:
1590 g_value_set_boolean (value, tag->editable_set);
1593 case PROP_WRAP_MODE_SET:
1594 g_value_set_boolean (value, tag->wrap_mode_set);
1597 case PROP_JUSTIFICATION_SET:
1598 g_value_set_boolean (value, tag->justification_set);
1601 case PROP_LEFT_MARGIN_SET:
1602 g_value_set_boolean (value, tag->left_margin_set);
1605 case PROP_INDENT_SET:
1606 g_value_set_boolean (value, tag->indent_set);
1609 case PROP_STRIKETHROUGH_SET:
1610 g_value_set_boolean (value, tag->strikethrough_set);
1613 case PROP_RIGHT_MARGIN_SET:
1614 g_value_set_boolean (value, tag->right_margin_set);
1617 case PROP_UNDERLINE_SET:
1618 g_value_set_boolean (value, tag->underline_set);
1622 g_value_set_boolean (value, tag->rise_set);
1625 case PROP_BACKGROUND_FULL_HEIGHT_SET:
1626 g_value_set_boolean (value, tag->bg_full_height_set);
1629 case PROP_LANGUAGE_SET:
1630 g_value_set_boolean (value, tag->language_set);
1634 g_value_set_boolean (value, tag->tabs_set);
1637 case PROP_INVISIBLE_SET:
1638 g_value_set_boolean (value, tag->invisible_set);
1641 case PROP_PARAGRAPH_BACKGROUND_SET:
1642 g_value_set_boolean (value, tag->pg_bg_color_set);
1645 case PROP_BACKGROUND:
1646 case PROP_FOREGROUND:
1647 case PROP_PARAGRAPH_BACKGROUND:
1648 g_warning ("'foreground', 'background' and 'paragraph_background' properties are not readable, use 'foreground_gdk', 'background_gdk' and 'paragraph_background_gdk'");
1650 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1666 delta_priority_foreach (GtkTextTag *tag, gpointer user_data)
1668 DeltaData *dd = user_data;
1670 if (tag->priority >= dd->low && tag->priority <= dd->high)
1671 tag->priority += dd->delta;
1675 * gtk_text_tag_get_priority:
1676 * @tag: a #GtkTextTag
1678 * Get the tag priority.
1680 * Return value: The tag's priority.
1683 gtk_text_tag_get_priority (GtkTextTag *tag)
1685 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), 0);
1687 return tag->priority;
1691 * gtk_text_tag_set_priority:
1692 * @tag: a #GtkTextTag
1693 * @priority: the new priority
1695 * Sets the priority of a #GtkTextTag. Valid priorities are
1696 * start at 0 and go to one less than gtk_text_tag_table_get_size().
1697 * Each tag in a table has a unique priority; setting the priority
1698 * of one tag shifts the priorities of all the other tags in the
1699 * table to maintain a unique priority for each tag. Higher priority
1700 * tags "win" if two tags both set the same text attribute. When adding
1701 * a tag to a tag table, it will be assigned the highest priority in
1702 * the table by default; so normally the precedence of a set of tags
1703 * is the order in which they were added to the table, or created with
1704 * gtk_text_buffer_create_tag(), which adds the tag to the buffer's table
1708 gtk_text_tag_set_priority (GtkTextTag *tag,
1713 g_return_if_fail (GTK_IS_TEXT_TAG (tag));
1714 g_return_if_fail (tag->table != NULL);
1715 g_return_if_fail (priority >= 0);
1716 g_return_if_fail (priority < gtk_text_tag_table_get_size (tag->table));
1718 if (priority == tag->priority)
1721 if (priority < tag->priority)
1724 dd.high = tag->priority - 1;
1729 dd.low = tag->priority + 1;
1734 gtk_text_tag_table_foreach (tag->table,
1735 delta_priority_foreach,
1738 tag->priority = priority;
1742 * gtk_text_tag_event:
1743 * @tag: a #GtkTextTag
1744 * @event_object: object that received the event, such as a widget
1746 * @iter: location where the event was received
1748 * Emits the "event" signal on the #GtkTextTag.
1750 * Return value: result of signal emission (whether the event was handled)
1753 gtk_text_tag_event (GtkTextTag *tag,
1754 GObject *event_object,
1756 const GtkTextIter *iter)
1758 gboolean retval = FALSE;
1760 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
1761 g_return_val_if_fail (G_IS_OBJECT (event_object), FALSE);
1762 g_return_val_if_fail (event != NULL, FALSE);
1776 tag_sort_func (gconstpointer first, gconstpointer second)
1778 GtkTextTag *tag1, *tag2;
1780 tag1 = * (GtkTextTag **) first;
1781 tag2 = * (GtkTextTag **) second;
1782 return tag1->priority - tag2->priority;
1786 _gtk_text_tag_array_sort (GtkTextTag** tag_array_p,
1791 GtkTextTag **maxPtrPtr, *tmp;
1793 g_return_if_fail (tag_array_p != NULL);
1794 g_return_if_fail (len > 0);
1800 GtkTextTag **iter = tag_array_p;
1802 for (i = len-1; i > 0; i--, iter++) {
1803 maxPtrPtr = tag = iter;
1804 prio = tag[0]->priority;
1805 for (j = i, tag++; j > 0; j--, tag++) {
1806 if (tag[0]->priority < prio) {
1807 prio = tag[0]->priority;
1816 qsort ((void *) tag_array_p, (unsigned) len, sizeof (GtkTextTag *),
1822 printf ("Sorted tag array: \n");
1826 GtkTextTag *t = tag_array_p[i];
1827 printf (" %s priority %d\n", t->name, t->priority);
1840 * gtk_text_attributes_new:
1842 * Creates a #GtkTextAttributes, which describes
1843 * a set of properties on some text.
1845 * Return value: a new #GtkTextAttributes
1848 gtk_text_attributes_new (void)
1850 GtkTextAttributes *values;
1852 values = g_new0 (GtkTextAttributes, 1);
1854 /* 0 is a valid value for most of the struct */
1856 values->refcount = 1;
1858 values->language = gtk_get_default_language ();
1860 values->font_scale = 1.0;
1862 values->editable = TRUE;
1868 * gtk_text_attributes_copy:
1869 * @src: a #GtkTextAttributes to be copied
1871 * Copies @src and returns a new #GtkTextAttributes.
1873 * Return value: a copy of @src
1876 gtk_text_attributes_copy (GtkTextAttributes *src)
1878 GtkTextAttributes *dest;
1880 dest = gtk_text_attributes_new ();
1881 gtk_text_attributes_copy_values (src, dest);
1886 G_DEFINE_BOXED_TYPE (GtkTextAttributes, gtk_text_attributes,
1887 gtk_text_attributes_ref,
1888 gtk_text_attributes_unref)
1891 * gtk_text_attributes_copy_values:
1892 * @src: a #GtkTextAttributes
1893 * @dest: another #GtkTextAttributes
1895 * Copies the values from @src to @dest so that @dest has the same values
1896 * as @src. Frees existing values in @dest.
1899 gtk_text_attributes_copy_values (GtkTextAttributes *src,
1900 GtkTextAttributes *dest)
1902 guint orig_refcount;
1910 pango_font_description_free (dest->font);
1913 orig_refcount = dest->refcount;
1918 dest->tabs = pango_tab_array_copy (src->tabs);
1920 dest->language = src->language;
1923 dest->font = pango_font_description_copy (src->font);
1925 if (src->pg_bg_color)
1926 dest->pg_bg_color = gdk_color_copy (src->pg_bg_color);
1928 dest->refcount = orig_refcount;
1932 * gtk_text_attributes_ref:
1933 * @values: a #GtkTextAttributes
1935 * Increments the reference count on @values.
1937 * Returns: the #GtkTextAttributes that were passed in
1940 gtk_text_attributes_ref (GtkTextAttributes *values)
1942 g_return_val_if_fail (values != NULL, NULL);
1944 values->refcount += 1;
1950 * gtk_text_attributes_unref:
1951 * @values: a #GtkTextAttributes
1953 * Decrements the reference count on @values, freeing the structure
1954 * if the reference count reaches 0.
1957 gtk_text_attributes_unref (GtkTextAttributes *values)
1959 g_return_if_fail (values != NULL);
1960 g_return_if_fail (values->refcount > 0);
1962 values->refcount -= 1;
1964 if (values->refcount == 0)
1967 pango_tab_array_free (values->tabs);
1970 pango_font_description_free (values->font);
1972 if (values->pg_bg_color)
1973 gdk_color_free (values->pg_bg_color);
1980 _gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest,
1986 guint left_margin_accumulative = 0;
1987 guint right_margin_accumulative = 0;
1991 GtkTextTag *tag = tags[n];
1992 GtkTextAttributes *vals = tag->values;
1994 g_assert (tag->table != NULL);
1996 g_assert (tags[n]->priority > tags[n-1]->priority);
1998 if (tag->bg_color_set)
2000 dest->appearance.bg_color = vals->appearance.bg_color;
2002 dest->appearance.draw_bg = TRUE;
2004 if (tag->fg_color_set)
2005 dest->appearance.fg_color = vals->appearance.fg_color;
2007 if (tag->pg_bg_color_set)
2009 dest->pg_bg_color = gdk_color_copy (vals->pg_bg_color);
2015 pango_font_description_merge (dest->font, vals->font, TRUE);
2017 dest->font = pango_font_description_copy (vals->font);
2020 /* multiply all the scales together to get a composite */
2022 dest->font_scale *= vals->font_scale;
2024 if (tag->justification_set)
2025 dest->justification = vals->justification;
2027 if (vals->direction != GTK_TEXT_DIR_NONE)
2028 dest->direction = vals->direction;
2030 if (tag->left_margin_set)
2032 if (tag->accumulative_margin)
2033 left_margin_accumulative += vals->left_margin;
2035 dest->left_margin = vals->left_margin;
2038 if (tag->indent_set)
2039 dest->indent = vals->indent;
2042 dest->appearance.rise = vals->appearance.rise;
2044 if (tag->right_margin_set)
2046 if (tag->accumulative_margin)
2047 right_margin_accumulative += vals->right_margin;
2049 dest->right_margin = vals->right_margin;
2052 if (tag->pixels_above_lines_set)
2053 dest->pixels_above_lines = vals->pixels_above_lines;
2055 if (tag->pixels_below_lines_set)
2056 dest->pixels_below_lines = vals->pixels_below_lines;
2058 if (tag->pixels_inside_wrap_set)
2059 dest->pixels_inside_wrap = vals->pixels_inside_wrap;
2064 pango_tab_array_free (dest->tabs);
2065 dest->tabs = pango_tab_array_copy (vals->tabs);
2068 if (tag->wrap_mode_set)
2069 dest->wrap_mode = vals->wrap_mode;
2071 if (tag->underline_set)
2072 dest->appearance.underline = vals->appearance.underline;
2074 if (tag->strikethrough_set)
2075 dest->appearance.strikethrough = vals->appearance.strikethrough;
2077 if (tag->invisible_set)
2078 dest->invisible = vals->invisible;
2080 if (tag->editable_set)
2081 dest->editable = vals->editable;
2083 if (tag->bg_full_height_set)
2084 dest->bg_full_height = vals->bg_full_height;
2086 if (tag->language_set)
2087 dest->language = vals->language;
2092 dest->left_margin += left_margin_accumulative;
2093 dest->right_margin += right_margin_accumulative;
2097 _gtk_text_tag_affects_size (GtkTextTag *tag)
2099 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
2102 (tag->values->font && pango_font_description_get_set_fields (tag->values->font) != 0) ||
2104 tag->justification_set ||
2105 tag->left_margin_set ||
2108 tag->right_margin_set ||
2109 tag->pixels_above_lines_set ||
2110 tag->pixels_below_lines_set ||
2111 tag->pixels_inside_wrap_set ||
2113 tag->underline_set ||
2114 tag->wrap_mode_set ||
2119 _gtk_text_tag_affects_nonsize_appearance (GtkTextTag *tag)
2121 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
2124 tag->bg_color_set ||
2125 tag->fg_color_set ||
2126 tag->strikethrough_set ||
2127 tag->bg_full_height_set ||
2128 tag->pg_bg_color_set;