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.
53 * @Short_description: A tag that can be applied to text in a GtkTextBuffer
55 * You may wish to begin by reading the <link linkend="TextWidget">text widget
56 * conceptual overview</link> which gives an overview of all the objects and
57 * data types related to the text widget and how they work together.
59 * Tags should be in the #GtkTextTagTable for a given #GtkTextBuffer
60 * before using them with that buffer.
62 * gtk_text_buffer_create_tag() is the best way to create tags.
63 * See <application>gtk3-demo</application> for numerous examples.
71 #include "gtkmainprivate.h"
72 #include "gtktexttag.h"
73 #include "gtktexttypes.h"
74 #include "gtktexttagtable.h"
76 #include "gtkmarshalers.h"
77 #include "gtkprivate.h"
78 #include "gtktypebuiltins.h"
107 PROP_PIXELS_ABOVE_LINES,
108 PROP_PIXELS_BELOW_LINES,
109 PROP_PIXELS_INSIDE_WRAP,
120 PROP_BACKGROUND_FULL_HEIGHT,
124 PROP_PARAGRAPH_BACKGROUND,
125 PROP_PARAGRAPH_BACKGROUND_GDK,
126 PROP_PARAGRAPH_BACKGROUND_RGBA,
129 PROP_ACCUMULATIVE_MARGIN,
131 /* Whether-a-style-arg-is-set args */
141 PROP_PIXELS_ABOVE_LINES_SET,
142 PROP_PIXELS_BELOW_LINES_SET,
143 PROP_PIXELS_INSIDE_WRAP_SET,
146 PROP_JUSTIFICATION_SET,
147 PROP_LEFT_MARGIN_SET,
149 PROP_STRIKETHROUGH_SET,
150 PROP_RIGHT_MARGIN_SET,
153 PROP_BACKGROUND_FULL_HEIGHT_SET,
157 PROP_PARAGRAPH_BACKGROUND_SET,
161 static void gtk_text_tag_finalize (GObject *object);
162 static void gtk_text_tag_set_property (GObject *object,
166 static void gtk_text_tag_get_property (GObject *object,
171 static guint signals[LAST_SIGNAL] = { 0 };
173 G_DEFINE_TYPE (GtkTextTag, gtk_text_tag, G_TYPE_OBJECT)
176 gtk_text_tag_class_init (GtkTextTagClass *klass)
178 GObjectClass *object_class = G_OBJECT_CLASS (klass);
180 object_class->set_property = gtk_text_tag_set_property;
181 object_class->get_property = gtk_text_tag_get_property;
183 object_class->finalize = gtk_text_tag_finalize;
186 g_object_class_install_property (object_class,
188 g_param_spec_string ("name",
190 P_("Name used to refer to the text tag. NULL for anonymous tags"),
192 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
196 g_object_class_install_property (object_class,
198 g_param_spec_string ("background",
199 P_("Background color name"),
200 P_("Background color as a string"),
202 GTK_PARAM_WRITABLE));
204 g_object_class_install_property (object_class,
206 g_param_spec_boxed ("background-gdk",
207 P_("Background color"),
208 P_("Background color as a (possibly unallocated) GdkColor"),
210 GTK_PARAM_READWRITE));
213 g_object_class_install_property (object_class,
214 PROP_BACKGROUND_RGBA,
215 g_param_spec_boxed ("background-rgba",
216 P_("Background rgba"),
217 P_("Background rgba as a (possibly unallocated) GdkRGBA"),
219 GTK_PARAM_READWRITE));
221 g_object_class_install_property (object_class,
222 PROP_BACKGROUND_FULL_HEIGHT,
223 g_param_spec_boolean ("background-full-height",
224 P_("Background full height"),
225 P_("Whether the background color fills the entire line height or only the height of the tagged characters"),
227 GTK_PARAM_READWRITE));
229 g_object_class_install_property (object_class,
231 g_param_spec_string ("foreground",
232 P_("Foreground color name"),
233 P_("Foreground color as a string"),
235 GTK_PARAM_WRITABLE));
237 g_object_class_install_property (object_class,
239 g_param_spec_boxed ("foreground-gdk",
240 P_("Foreground color"),
241 P_("Foreground color as a (possibly unallocated) GdkColor"),
243 GTK_PARAM_READWRITE));
245 g_object_class_install_property (object_class,
246 PROP_FOREGROUND_RGBA,
247 g_param_spec_boxed ("foreground-rgba",
248 P_("Foreground rgba"),
249 P_("Foreground rgba as a (possibly unallocated) GdkRGBA"),
251 GTK_PARAM_READWRITE));
253 g_object_class_install_property (object_class,
255 g_param_spec_enum ("direction",
256 P_("Text direction"),
257 P_("Text direction, e.g. right-to-left or left-to-right"),
258 GTK_TYPE_TEXT_DIRECTION,
260 GTK_PARAM_READWRITE));
262 g_object_class_install_property (object_class,
264 g_param_spec_boolean ("editable",
266 P_("Whether the text can be modified by the user"),
268 GTK_PARAM_READWRITE));
273 * Font description as string, e.g. \"Sans Italic 12\".
275 * Note that the initial value of this property depends on
276 * the internals of #PangoFontDescription.
278 g_object_class_install_property (object_class,
280 g_param_spec_string ("font",
282 P_("Font description as a string, e.g. \"Sans Italic 12\""),
284 GTK_PARAM_READWRITE));
286 g_object_class_install_property (object_class,
288 g_param_spec_boxed ("font-desc",
290 P_("Font description as a PangoFontDescription struct"),
291 PANGO_TYPE_FONT_DESCRIPTION,
292 GTK_PARAM_READWRITE));
294 g_object_class_install_property (object_class,
296 g_param_spec_string ("family",
298 P_("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
300 GTK_PARAM_READWRITE));
302 g_object_class_install_property (object_class,
304 g_param_spec_enum ("style",
306 P_("Font style as a PangoStyle, e.g. PANGO_STYLE_ITALIC"),
309 GTK_PARAM_READWRITE));
311 g_object_class_install_property (object_class,
313 g_param_spec_enum ("variant",
315 P_("Font variant as a PangoVariant, e.g. PANGO_VARIANT_SMALL_CAPS"),
317 PANGO_VARIANT_NORMAL,
318 GTK_PARAM_READWRITE));
320 g_object_class_install_property (object_class,
322 g_param_spec_int ("weight",
324 P_("Font weight as an integer, see predefined values in PangoWeight; for example, PANGO_WEIGHT_BOLD"),
328 GTK_PARAM_READWRITE));
331 g_object_class_install_property (object_class,
333 g_param_spec_enum ("stretch",
335 P_("Font stretch as a PangoStretch, e.g. PANGO_STRETCH_CONDENSED"),
337 PANGO_STRETCH_NORMAL,
338 GTK_PARAM_READWRITE));
340 g_object_class_install_property (object_class,
342 g_param_spec_int ("size",
344 P_("Font size in Pango units"),
348 GTK_PARAM_READWRITE));
350 g_object_class_install_property (object_class,
352 g_param_spec_double ("scale",
354 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"),
358 GTK_PARAM_READWRITE));
360 g_object_class_install_property (object_class,
362 g_param_spec_double ("size-points",
364 P_("Font size in points"),
368 GTK_PARAM_READWRITE));
370 g_object_class_install_property (object_class,
372 g_param_spec_enum ("justification",
374 P_("Left, right, or center justification"),
375 GTK_TYPE_JUSTIFICATION,
377 GTK_PARAM_READWRITE));
380 * GtkTextTag:language:
382 * The language this text is in, as an ISO code. Pango can use this as a
383 * hint when rendering the text. If not set, an appropriate default will be
386 * Note that the initial value of this property depends on the current
387 * locale, see also gtk_get_default_language().
389 g_object_class_install_property (object_class,
391 g_param_spec_string ("language",
393 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."),
395 GTK_PARAM_READWRITE));
397 g_object_class_install_property (object_class,
399 g_param_spec_int ("left-margin",
401 P_("Width of the left margin in pixels"),
405 GTK_PARAM_READWRITE));
407 g_object_class_install_property (object_class,
409 g_param_spec_int ("right-margin",
411 P_("Width of the right margin in pixels"),
415 GTK_PARAM_READWRITE));
418 g_object_class_install_property (object_class,
420 g_param_spec_int ("indent",
422 P_("Amount to indent the paragraph, in pixels"),
426 GTK_PARAM_READWRITE));
429 g_object_class_install_property (object_class,
431 g_param_spec_int ("rise",
433 P_("Offset of text above the baseline (below the baseline if rise is negative) in Pango units"),
437 GTK_PARAM_READWRITE));
439 g_object_class_install_property (object_class,
440 PROP_PIXELS_ABOVE_LINES,
441 g_param_spec_int ("pixels-above-lines",
442 P_("Pixels above lines"),
443 P_("Pixels of blank space above paragraphs"),
447 GTK_PARAM_READWRITE));
449 g_object_class_install_property (object_class,
450 PROP_PIXELS_BELOW_LINES,
451 g_param_spec_int ("pixels-below-lines",
452 P_("Pixels below lines"),
453 P_("Pixels of blank space below paragraphs"),
457 GTK_PARAM_READWRITE));
459 g_object_class_install_property (object_class,
460 PROP_PIXELS_INSIDE_WRAP,
461 g_param_spec_int ("pixels-inside-wrap",
462 P_("Pixels inside wrap"),
463 P_("Pixels of blank space between wrapped lines in a paragraph"),
467 GTK_PARAM_READWRITE));
469 g_object_class_install_property (object_class,
471 g_param_spec_boolean ("strikethrough",
473 P_("Whether to strike through the text"),
475 GTK_PARAM_READWRITE));
477 g_object_class_install_property (object_class,
479 g_param_spec_enum ("underline",
481 P_("Style of underline for this text"),
482 PANGO_TYPE_UNDERLINE,
483 PANGO_UNDERLINE_NONE,
484 GTK_PARAM_READWRITE));
486 g_object_class_install_property (object_class,
488 g_param_spec_enum ("wrap-mode",
490 P_("Whether to wrap lines never, at word boundaries, or at character boundaries"),
493 GTK_PARAM_READWRITE));
496 g_object_class_install_property (object_class,
498 g_param_spec_boxed ("tabs",
500 P_("Custom tabs for this text"),
501 PANGO_TYPE_TAB_ARRAY,
502 GTK_PARAM_READWRITE));
505 * GtkTextTag:invisible:
507 * Whether this text is hidden.
509 * Note that there may still be problems with the support for invisible
510 * text, in particular when navigating programmatically inside a buffer
511 * containing invisible segments.
515 g_object_class_install_property (object_class,
517 g_param_spec_boolean ("invisible",
519 P_("Whether this text is hidden."),
521 GTK_PARAM_READWRITE));
524 * GtkTextTag:paragraph-background:
526 * The paragraph background color as a string.
530 g_object_class_install_property (object_class,
531 PROP_PARAGRAPH_BACKGROUND,
532 g_param_spec_string ("paragraph-background",
533 P_("Paragraph background color name"),
534 P_("Paragraph background color as a string"),
536 GTK_PARAM_WRITABLE));
539 * GtkTextTag:paragraph-background-gdk:
541 * The paragraph background color as a as a (possibly unallocated)
546 g_object_class_install_property (object_class,
547 PROP_PARAGRAPH_BACKGROUND_GDK,
548 g_param_spec_boxed ("paragraph-background-gdk",
549 P_("Paragraph background color"),
550 P_("Paragraph background color as a (possibly unallocated) GdkColor"),
552 GTK_PARAM_READWRITE));
555 * GtkTextTag:paragraph-background-rgba:
557 * The paragraph background color as a as a (possibly unallocated)
562 g_object_class_install_property (object_class,
563 PROP_PARAGRAPH_BACKGROUND_RGBA,
564 g_param_spec_boxed ("paragraph-background-rgba",
565 P_("Paragraph background rgba"),
566 P_("Paragraph background rgba as a (possibly unallocated) GdkRGBA"),
568 GTK_PARAM_READWRITE));
571 * GtkTextTag:accumulative-margin:
573 * Whether the margins accumulate or override each other.
575 * When set to %TRUE the margins of this tag are added to the margins
576 * of any other non-accumulative margins present. When set to %FALSE
577 * the margins override one another (the default).
581 g_object_class_install_property (object_class,
582 PROP_ACCUMULATIVE_MARGIN,
583 g_param_spec_boolean ("accumulative-margin",
584 P_("Margin Accumulates"),
585 P_("Whether left and right margins accumulate."),
587 GTK_PARAM_READWRITE));
589 /* Style props are set or not */
591 #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))
593 ADD_SET_PROP ("background-set", PROP_BACKGROUND_SET,
594 P_("Background set"),
595 P_("Whether this tag affects the background color"));
597 ADD_SET_PROP ("background-full-height-set", PROP_BACKGROUND_FULL_HEIGHT_SET,
598 P_("Background full height set"),
599 P_("Whether this tag affects background height"));
601 ADD_SET_PROP ("foreground-set", PROP_FOREGROUND_SET,
602 P_("Foreground set"),
603 P_("Whether this tag affects the foreground color"));
605 ADD_SET_PROP ("editable-set", PROP_EDITABLE_SET,
606 P_("Editability set"),
607 P_("Whether this tag affects text editability"));
609 ADD_SET_PROP ("family-set", PROP_FAMILY_SET,
610 P_("Font family set"),
611 P_("Whether this tag affects the font family"));
613 ADD_SET_PROP ("style-set", PROP_STYLE_SET,
614 P_("Font style set"),
615 P_("Whether this tag affects the font style"));
617 ADD_SET_PROP ("variant-set", PROP_VARIANT_SET,
618 P_("Font variant set"),
619 P_("Whether this tag affects the font variant"));
621 ADD_SET_PROP ("weight-set", PROP_WEIGHT_SET,
622 P_("Font weight set"),
623 P_("Whether this tag affects the font weight"));
625 ADD_SET_PROP ("stretch-set", PROP_STRETCH_SET,
626 P_("Font stretch set"),
627 P_("Whether this tag affects the font stretch"));
629 ADD_SET_PROP ("size-set", PROP_SIZE_SET,
631 P_("Whether this tag affects the font size"));
633 ADD_SET_PROP ("scale-set", PROP_SCALE_SET,
634 P_("Font scale set"),
635 P_("Whether this tag scales the font size by a factor"));
637 ADD_SET_PROP ("justification-set", PROP_JUSTIFICATION_SET,
638 P_("Justification set"),
639 P_("Whether this tag affects paragraph justification"));
641 ADD_SET_PROP ("language-set", PROP_LANGUAGE_SET,
643 P_("Whether this tag affects the language the text is rendered as"));
645 ADD_SET_PROP ("left-margin-set", PROP_LEFT_MARGIN_SET,
646 P_("Left margin set"),
647 P_("Whether this tag affects the left margin"));
649 ADD_SET_PROP ("indent-set", PROP_INDENT_SET,
651 P_("Whether this tag affects indentation"));
653 ADD_SET_PROP ("rise-set", PROP_RISE_SET,
655 P_("Whether this tag affects the rise"));
657 ADD_SET_PROP ("pixels-above-lines-set", PROP_PIXELS_ABOVE_LINES_SET,
658 P_("Pixels above lines set"),
659 P_("Whether this tag affects the number of pixels above lines"));
661 ADD_SET_PROP ("pixels-below-lines-set", PROP_PIXELS_BELOW_LINES_SET,
662 P_("Pixels below lines set"),
663 P_("Whether this tag affects the number of pixels above lines"));
665 ADD_SET_PROP ("pixels-inside-wrap-set", PROP_PIXELS_INSIDE_WRAP_SET,
666 P_("Pixels inside wrap set"),
667 P_("Whether this tag affects the number of pixels between wrapped lines"));
669 ADD_SET_PROP ("strikethrough-set", PROP_STRIKETHROUGH_SET,
670 P_("Strikethrough set"),
671 P_("Whether this tag affects strikethrough"));
673 ADD_SET_PROP ("right-margin-set", PROP_RIGHT_MARGIN_SET,
674 P_("Right margin set"),
675 P_("Whether this tag affects the right margin"));
677 ADD_SET_PROP ("underline-set", PROP_UNDERLINE_SET,
679 P_("Whether this tag affects underlining"));
681 ADD_SET_PROP ("wrap-mode-set", PROP_WRAP_MODE_SET,
683 P_("Whether this tag affects line wrap mode"));
685 ADD_SET_PROP ("tabs-set", PROP_TABS_SET,
687 P_("Whether this tag affects tabs"));
689 ADD_SET_PROP ("invisible-set", PROP_INVISIBLE_SET,
691 P_("Whether this tag affects text visibility"));
693 ADD_SET_PROP ("paragraph-background-set", PROP_PARAGRAPH_BACKGROUND_SET,
694 P_("Paragraph background set"),
695 P_("Whether this tag affects the paragraph background color"));
699 * @tag: the #GtkTextTag on which the signal is emitted
700 * @object: the object the event was fired from (typically a #GtkTextView)
701 * @event: the event which triggered the signal
702 * @iter: a #GtkTextIter pointing at the location the event occured
704 * The ::event signal is emitted when an event occurs on a region of the
705 * buffer marked with this tag.
707 * Returns: %TRUE to stop other handlers from being invoked for the
708 * event. %FALSE to propagate the event further.
711 g_signal_new (I_("event"),
712 G_OBJECT_CLASS_TYPE (object_class),
714 G_STRUCT_OFFSET (GtkTextTagClass, event),
715 _gtk_boolean_handled_accumulator, NULL,
716 _gtk_marshal_BOOLEAN__OBJECT_BOXED_BOXED,
720 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE,
723 g_type_class_add_private (klass, sizeof (GtkTextTagPrivate));
727 gtk_text_tag_init (GtkTextTag *text_tag)
729 GtkTextTagPrivate *priv;
731 text_tag->priv = G_TYPE_INSTANCE_GET_PRIVATE (text_tag,
734 priv = text_tag->priv;
736 priv->values = gtk_text_attributes_new ();
741 * @name: (allow-none): tag name, or %NULL
743 * Creates a #GtkTextTag. Configure the tag using object arguments,
744 * i.e. using g_object_set().
746 * Return value: a new #GtkTextTag
749 gtk_text_tag_new (const gchar *name)
753 tag = g_object_new (GTK_TYPE_TEXT_TAG, "name", name, NULL);
759 gtk_text_tag_finalize (GObject *object)
761 GtkTextTag *text_tag = GTK_TEXT_TAG (object);
762 GtkTextTagPrivate *priv = text_tag->priv;
765 gtk_text_tag_table_remove (priv->table, text_tag);
767 g_assert (priv->table == NULL);
769 gtk_text_attributes_unref (priv->values);
775 G_OBJECT_CLASS (gtk_text_tag_parent_class)->finalize (object);
779 copy_rgba_to_gdk_color (GdkRGBA *src,
782 dest->red = CLAMP (src->red, 0.0, 1.0) * 65535.0;
783 dest->green = CLAMP (src->green, 0.0, 1.0) * 65535.0;
784 dest->blue = CLAMP (src->blue, 0.0, 1.0) * 65535.0;
788 copy_gdk_color_to_rgba (GdkColor *src,
791 dest->red = src->red / 65535.;
792 dest->green = src->green / 65535.;
793 dest->blue = src->blue / 65535.;
798 set_bg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
800 GtkTextTagPrivate *priv = tag->priv;
802 if (priv->values->appearance.rgba[0])
803 gdk_rgba_free (priv->values->appearance.rgba[0]);
805 priv->values->appearance.rgba[0] = NULL;
809 if (!priv->bg_color_set)
811 priv->bg_color_set = TRUE;
812 g_object_notify (G_OBJECT (tag), "background-set");
815 priv->values->appearance.rgba[0] = gdk_rgba_copy (rgba);
817 copy_rgba_to_gdk_color (rgba, &priv->values->appearance.bg_color);
821 if (priv->bg_color_set)
823 priv->bg_color_set = FALSE;
824 g_object_notify (G_OBJECT (tag), "background-set");
830 set_fg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
832 GtkTextTagPrivate *priv = tag->priv;
834 if (priv->values->appearance.rgba[1])
835 gdk_rgba_free (priv->values->appearance.rgba[1]);
837 priv->values->appearance.rgba[1] = NULL;
841 if (!priv->fg_color_set)
843 priv->fg_color_set = TRUE;
844 g_object_notify (G_OBJECT (tag), "foreground-set");
847 priv->values->appearance.rgba[1] = gdk_rgba_copy (rgba);
849 copy_rgba_to_gdk_color (rgba, &priv->values->appearance.fg_color);
853 if (priv->fg_color_set)
855 priv->fg_color_set = FALSE;
856 g_object_notify (G_OBJECT (tag), "foreground-set");
862 set_pg_bg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
864 GtkTextTagPrivate *priv = tag->priv;
866 if (priv->values->pg_bg_rgba)
867 gdk_rgba_free (priv->values->pg_bg_rgba);
869 if (priv->values->pg_bg_color)
870 gdk_color_free (priv->values->pg_bg_color);
872 priv->values->pg_bg_rgba = NULL;
873 priv->values->pg_bg_color = NULL;
877 GdkColor color = { 0, };
879 if (!priv->pg_bg_color_set)
881 priv->pg_bg_color_set = TRUE;
882 g_object_notify (G_OBJECT (tag), "paragraph-background-set");
885 priv->values->pg_bg_rgba = gdk_rgba_copy (rgba);
887 copy_rgba_to_gdk_color (rgba, &color);
888 priv->values->pg_bg_color = gdk_color_copy (&color);
892 if (priv->pg_bg_color_set)
894 priv->pg_bg_color_set = FALSE;
895 g_object_notify (G_OBJECT (tag), "paragraph-background-set");
902 set_bg_color (GtkTextTag *tag, GdkColor *color)
908 copy_gdk_color_to_rgba (color, &rgba);
909 set_bg_rgba (tag, &rgba);
912 set_bg_rgba (tag, NULL);
916 set_fg_color (GtkTextTag *tag, GdkColor *color)
922 copy_gdk_color_to_rgba (color, &rgba);
923 set_fg_rgba (tag, &rgba);
926 set_fg_rgba (tag, NULL);
930 set_pg_bg_color (GtkTextTag *tag, GdkColor *color)
936 copy_gdk_color_to_rgba (color, &rgba);
937 set_pg_bg_rgba (tag, &rgba);
940 set_pg_bg_rgba (tag, NULL);
944 get_property_font_set_mask (guint prop_id)
948 case PROP_FAMILY_SET:
949 return PANGO_FONT_MASK_FAMILY;
951 return PANGO_FONT_MASK_STYLE;
952 case PROP_VARIANT_SET:
953 return PANGO_FONT_MASK_VARIANT;
954 case PROP_WEIGHT_SET:
955 return PANGO_FONT_MASK_WEIGHT;
956 case PROP_STRETCH_SET:
957 return PANGO_FONT_MASK_STRETCH;
959 return PANGO_FONT_MASK_SIZE;
966 set_font_desc_fields (PangoFontDescription *desc,
967 PangoFontMask to_set)
969 PangoFontMask changed_mask = 0;
971 if (to_set & PANGO_FONT_MASK_FAMILY)
973 const char *family = pango_font_description_get_family (desc);
977 changed_mask |= PANGO_FONT_MASK_FAMILY;
980 pango_font_description_set_family (desc, family);
982 if (to_set & PANGO_FONT_MASK_STYLE)
983 pango_font_description_set_style (desc, pango_font_description_get_style (desc));
984 if (to_set & PANGO_FONT_MASK_VARIANT)
985 pango_font_description_set_variant (desc, pango_font_description_get_variant (desc));
986 if (to_set & PANGO_FONT_MASK_WEIGHT)
987 pango_font_description_set_weight (desc, pango_font_description_get_weight (desc));
988 if (to_set & PANGO_FONT_MASK_STRETCH)
989 pango_font_description_set_stretch (desc, pango_font_description_get_stretch (desc));
990 if (to_set & PANGO_FONT_MASK_SIZE)
992 gint size = pango_font_description_get_size (desc);
995 size = 10 * PANGO_SCALE;
996 changed_mask |= PANGO_FONT_MASK_SIZE;
999 pango_font_description_set_size (desc, size);
1002 return changed_mask;
1006 notify_set_changed (GObject *object,
1007 PangoFontMask changed_mask)
1009 if (changed_mask & PANGO_FONT_MASK_FAMILY)
1010 g_object_notify (object, "family-set");
1011 if (changed_mask & PANGO_FONT_MASK_STYLE)
1012 g_object_notify (object, "style-set");
1013 if (changed_mask & PANGO_FONT_MASK_VARIANT)
1014 g_object_notify (object, "variant-set");
1015 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
1016 g_object_notify (object, "weight-set");
1017 if (changed_mask & PANGO_FONT_MASK_STRETCH)
1018 g_object_notify (object, "stretch-set");
1019 if (changed_mask & PANGO_FONT_MASK_SIZE)
1020 g_object_notify (object, "size-set");
1024 notify_fields_changed (GObject *object,
1025 PangoFontMask changed_mask)
1027 if (changed_mask & PANGO_FONT_MASK_FAMILY)
1028 g_object_notify (object, "family");
1029 if (changed_mask & PANGO_FONT_MASK_STYLE)
1030 g_object_notify (object, "style");
1031 if (changed_mask & PANGO_FONT_MASK_VARIANT)
1032 g_object_notify (object, "variant");
1033 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
1034 g_object_notify (object, "weight");
1035 if (changed_mask & PANGO_FONT_MASK_STRETCH)
1036 g_object_notify (object, "stretch");
1037 if (changed_mask & PANGO_FONT_MASK_SIZE)
1038 g_object_notify (object, "size");
1042 set_font_description (GtkTextTag *text_tag,
1043 PangoFontDescription *font_desc)
1045 GtkTextTagPrivate *priv = text_tag->priv;
1046 GObject *object = G_OBJECT (text_tag);
1047 PangoFontDescription *new_font_desc;
1048 PangoFontMask old_mask, new_mask, changed_mask, set_changed_mask;
1051 new_font_desc = pango_font_description_copy (font_desc);
1053 new_font_desc = pango_font_description_new ();
1055 if (priv->values->font)
1056 old_mask = pango_font_description_get_set_fields (priv->values->font);
1060 new_mask = pango_font_description_get_set_fields (new_font_desc);
1062 changed_mask = old_mask | new_mask;
1063 set_changed_mask = old_mask ^ new_mask;
1065 if (priv->values->font)
1066 pango_font_description_free (priv->values->font);
1067 priv->values->font = new_font_desc;
1069 g_object_freeze_notify (object);
1071 g_object_notify (object, "font-desc");
1072 g_object_notify (object, "font");
1074 if (changed_mask & PANGO_FONT_MASK_FAMILY)
1075 g_object_notify (object, "family");
1076 if (changed_mask & PANGO_FONT_MASK_STYLE)
1077 g_object_notify (object, "style");
1078 if (changed_mask & PANGO_FONT_MASK_VARIANT)
1079 g_object_notify (object, "variant");
1080 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
1081 g_object_notify (object, "weight");
1082 if (changed_mask & PANGO_FONT_MASK_STRETCH)
1083 g_object_notify (object, "stretch");
1084 if (changed_mask & PANGO_FONT_MASK_SIZE)
1086 g_object_notify (object, "size");
1087 g_object_notify (object, "size-points");
1090 notify_set_changed (object, set_changed_mask);
1092 g_object_thaw_notify (object);
1096 gtk_text_tag_ensure_font (GtkTextTag *text_tag)
1098 GtkTextTagPrivate *priv = text_tag->priv;
1100 if (!priv->values->font)
1101 priv->values->font = pango_font_description_new ();
1105 gtk_text_tag_set_property (GObject *object,
1107 const GValue *value,
1110 GtkTextTag *text_tag = GTK_TEXT_TAG (object);
1111 GtkTextTagPrivate *priv = text_tag->priv;
1112 gboolean size_changed = FALSE;
1117 g_return_if_fail (priv->name == NULL);
1118 priv->name = g_value_dup_string (value);
1121 case PROP_BACKGROUND:
1125 if (!g_value_get_string (value))
1126 set_bg_rgba (text_tag, NULL); /* reset background_set to FALSE */
1127 else if (gdk_rgba_parse (&rgba, g_value_get_string (value)))
1128 set_bg_rgba (text_tag, &rgba);
1130 g_warning ("Don't know color `%s'", g_value_get_string (value));
1132 g_object_notify (object, "background-gdk");
1136 case PROP_FOREGROUND:
1140 if (!g_value_get_string (value))
1141 set_fg_rgba (text_tag, NULL); /* reset to foreground_set to FALSE */
1142 else if (gdk_rgba_parse (&rgba, g_value_get_string (value)))
1143 set_fg_rgba (text_tag, &rgba);
1145 g_warning ("Don't know color `%s'", g_value_get_string (value));
1147 g_object_notify (object, "foreground-gdk");
1151 case PROP_BACKGROUND_GDK:
1153 GdkColor *color = g_value_get_boxed (value);
1155 set_bg_color (text_tag, color);
1159 case PROP_FOREGROUND_GDK:
1161 GdkColor *color = g_value_get_boxed (value);
1163 set_fg_color (text_tag, color);
1167 case PROP_BACKGROUND_RGBA:
1169 GdkRGBA *color = g_value_get_boxed (value);
1171 set_bg_rgba (text_tag, color);
1175 case PROP_FOREGROUND_RGBA:
1177 GdkRGBA *color = g_value_get_boxed (value);
1179 set_fg_rgba (text_tag, color);
1185 PangoFontDescription *font_desc = NULL;
1188 name = g_value_get_string (value);
1191 font_desc = pango_font_description_from_string (name);
1193 set_font_description (text_tag, font_desc);
1195 pango_font_description_free (font_desc);
1197 size_changed = TRUE;
1201 case PROP_FONT_DESC:
1203 PangoFontDescription *font_desc;
1205 font_desc = g_value_get_boxed (value);
1207 set_font_description (text_tag, font_desc);
1209 size_changed = TRUE;
1219 case PROP_SIZE_POINTS:
1221 PangoFontMask old_set_mask;
1223 gtk_text_tag_ensure_font (text_tag);
1224 old_set_mask = pango_font_description_get_set_fields (priv->values->font);
1229 pango_font_description_set_family (priv->values->font,
1230 g_value_get_string (value));
1233 pango_font_description_set_style (priv->values->font,
1234 g_value_get_enum (value));
1237 pango_font_description_set_variant (priv->values->font,
1238 g_value_get_enum (value));
1241 pango_font_description_set_weight (priv->values->font,
1242 g_value_get_int (value));
1245 pango_font_description_set_stretch (priv->values->font,
1246 g_value_get_enum (value));
1249 pango_font_description_set_size (priv->values->font,
1250 g_value_get_int (value));
1251 g_object_notify (object, "size-points");
1253 case PROP_SIZE_POINTS:
1254 pango_font_description_set_size (priv->values->font,
1255 g_value_get_double (value) * PANGO_SCALE);
1256 g_object_notify (object, "size");
1260 size_changed = TRUE;
1261 notify_set_changed (object, old_set_mask & pango_font_description_get_set_fields (priv->values->font));
1262 g_object_notify (object, "font-desc");
1263 g_object_notify (object, "font");
1269 priv->values->font_scale = g_value_get_double (value);
1270 priv->scale_set = TRUE;
1271 g_object_notify (object, "scale-set");
1272 size_changed = TRUE;
1275 case PROP_PIXELS_ABOVE_LINES:
1276 priv->pixels_above_lines_set = TRUE;
1277 priv->values->pixels_above_lines = g_value_get_int (value);
1278 g_object_notify (object, "pixels-above-lines-set");
1279 size_changed = TRUE;
1282 case PROP_PIXELS_BELOW_LINES:
1283 priv->pixels_below_lines_set = TRUE;
1284 priv->values->pixels_below_lines = g_value_get_int (value);
1285 g_object_notify (object, "pixels-below-lines-set");
1286 size_changed = TRUE;
1289 case PROP_PIXELS_INSIDE_WRAP:
1290 priv->pixels_inside_wrap_set = TRUE;
1291 priv->values->pixels_inside_wrap = g_value_get_int (value);
1292 g_object_notify (object, "pixels-inside-wrap-set");
1293 size_changed = TRUE;
1297 priv->editable_set = TRUE;
1298 priv->values->editable = g_value_get_boolean (value);
1299 g_object_notify (object, "editable-set");
1302 case PROP_WRAP_MODE:
1303 priv->wrap_mode_set = TRUE;
1304 priv->values->wrap_mode = g_value_get_enum (value);
1305 g_object_notify (object, "wrap-mode-set");
1306 size_changed = TRUE;
1309 case PROP_JUSTIFICATION:
1310 priv->justification_set = TRUE;
1311 priv->values->justification = g_value_get_enum (value);
1312 g_object_notify (object, "justification-set");
1313 size_changed = TRUE;
1316 case PROP_DIRECTION:
1317 priv->values->direction = g_value_get_enum (value);
1320 case PROP_LEFT_MARGIN:
1321 priv->left_margin_set = TRUE;
1322 priv->values->left_margin = g_value_get_int (value);
1323 g_object_notify (object, "left-margin-set");
1324 size_changed = TRUE;
1328 priv->indent_set = TRUE;
1329 priv->values->indent = g_value_get_int (value);
1330 g_object_notify (object, "indent-set");
1331 size_changed = TRUE;
1334 case PROP_STRIKETHROUGH:
1335 priv->strikethrough_set = TRUE;
1336 priv->values->appearance.strikethrough = g_value_get_boolean (value);
1337 g_object_notify (object, "strikethrough-set");
1340 case PROP_RIGHT_MARGIN:
1341 priv->right_margin_set = TRUE;
1342 priv->values->right_margin = g_value_get_int (value);
1343 g_object_notify (object, "right-margin-set");
1344 size_changed = TRUE;
1347 case PROP_UNDERLINE:
1348 priv->underline_set = TRUE;
1349 priv->values->appearance.underline = g_value_get_enum (value);
1350 g_object_notify (object, "underline-set");
1354 priv->rise_set = TRUE;
1355 priv->values->appearance.rise = g_value_get_int (value);
1356 g_object_notify (object, "rise-set");
1357 size_changed = TRUE;
1360 case PROP_BACKGROUND_FULL_HEIGHT:
1361 priv->bg_full_height_set = TRUE;
1362 priv->values->bg_full_height = g_value_get_boolean (value);
1363 g_object_notify (object, "background-full-height-set");
1367 priv->language_set = TRUE;
1368 priv->values->language = pango_language_from_string (g_value_get_string (value));
1369 g_object_notify (object, "language-set");
1373 priv->tabs_set = TRUE;
1375 if (priv->values->tabs)
1376 pango_tab_array_free (priv->values->tabs);
1378 /* FIXME I'm not sure if this is a memleak or not */
1379 priv->values->tabs =
1380 pango_tab_array_copy (g_value_get_boxed (value));
1382 g_object_notify (object, "tabs-set");
1384 size_changed = TRUE;
1387 case PROP_INVISIBLE:
1388 priv->invisible_set = TRUE;
1389 priv->values->invisible = g_value_get_boolean (value);
1390 g_object_notify (object, "invisible-set");
1391 size_changed = TRUE;
1394 case PROP_PARAGRAPH_BACKGROUND:
1398 if (!g_value_get_string (value))
1399 set_pg_bg_rgba (text_tag, NULL); /* reset paragraph_background_set to FALSE */
1400 else if (gdk_rgba_parse (&rgba, g_value_get_string (value)))
1401 set_pg_bg_rgba (text_tag, &rgba);
1403 g_warning ("Don't know color `%s'", g_value_get_string (value));
1405 g_object_notify (object, "paragraph-background-gdk");
1409 case PROP_PARAGRAPH_BACKGROUND_GDK:
1411 GdkColor *color = g_value_get_boxed (value);
1413 set_pg_bg_color (text_tag, color);
1417 case PROP_PARAGRAPH_BACKGROUND_RGBA:
1419 GdkRGBA *color = g_value_get_boxed (value);
1421 set_pg_bg_rgba (text_tag, color);
1425 case PROP_ACCUMULATIVE_MARGIN:
1426 priv->accumulative_margin = g_value_get_boolean (value);
1427 g_object_notify (object, "accumulative-margin");
1428 size_changed = TRUE;
1431 /* Whether the value should be used... */
1433 case PROP_BACKGROUND_SET:
1434 priv->bg_color_set = g_value_get_boolean (value);
1437 case PROP_FOREGROUND_SET:
1438 priv->fg_color_set = g_value_get_boolean (value);
1441 case PROP_FAMILY_SET:
1442 case PROP_STYLE_SET:
1443 case PROP_VARIANT_SET:
1444 case PROP_WEIGHT_SET:
1445 case PROP_STRETCH_SET:
1447 if (!g_value_get_boolean (value))
1449 if (priv->values->font)
1450 pango_font_description_unset_fields (priv->values->font,
1451 get_property_font_set_mask (prop_id));
1455 PangoFontMask changed_mask;
1457 gtk_text_tag_ensure_font (text_tag);
1458 changed_mask = set_font_desc_fields (priv->values->font,
1459 get_property_font_set_mask (prop_id));
1460 notify_fields_changed (G_OBJECT (text_tag), changed_mask);
1464 case PROP_SCALE_SET:
1465 priv->scale_set = g_value_get_boolean (value);
1466 size_changed = TRUE;
1469 case PROP_PIXELS_ABOVE_LINES_SET:
1470 priv->pixels_above_lines_set = g_value_get_boolean (value);
1471 size_changed = TRUE;
1474 case PROP_PIXELS_BELOW_LINES_SET:
1475 priv->pixels_below_lines_set = g_value_get_boolean (value);
1476 size_changed = TRUE;
1479 case PROP_PIXELS_INSIDE_WRAP_SET:
1480 priv->pixels_inside_wrap_set = g_value_get_boolean (value);
1481 size_changed = TRUE;
1484 case PROP_EDITABLE_SET:
1485 priv->editable_set = g_value_get_boolean (value);
1488 case PROP_WRAP_MODE_SET:
1489 priv->wrap_mode_set = g_value_get_boolean (value);
1490 size_changed = TRUE;
1493 case PROP_JUSTIFICATION_SET:
1494 priv->justification_set = g_value_get_boolean (value);
1495 size_changed = TRUE;
1498 case PROP_LEFT_MARGIN_SET:
1499 priv->left_margin_set = g_value_get_boolean (value);
1500 size_changed = TRUE;
1503 case PROP_INDENT_SET:
1504 priv->indent_set = g_value_get_boolean (value);
1505 size_changed = TRUE;
1508 case PROP_STRIKETHROUGH_SET:
1509 priv->strikethrough_set = g_value_get_boolean (value);
1512 case PROP_RIGHT_MARGIN_SET:
1513 priv->right_margin_set = g_value_get_boolean (value);
1514 size_changed = TRUE;
1517 case PROP_UNDERLINE_SET:
1518 priv->underline_set = g_value_get_boolean (value);
1522 priv->rise_set = g_value_get_boolean (value);
1523 size_changed = TRUE;
1526 case PROP_BACKGROUND_FULL_HEIGHT_SET:
1527 priv->bg_full_height_set = g_value_get_boolean (value);
1530 case PROP_LANGUAGE_SET:
1531 priv->language_set = g_value_get_boolean (value);
1532 size_changed = TRUE;
1536 priv->tabs_set = g_value_get_boolean (value);
1537 size_changed = TRUE;
1540 case PROP_INVISIBLE_SET:
1541 priv->invisible_set = g_value_get_boolean (value);
1542 size_changed = TRUE;
1545 case PROP_PARAGRAPH_BACKGROUND_SET:
1546 priv->pg_bg_color_set = g_value_get_boolean (value);
1550 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1554 /* FIXME I would like to do this after all set_property in a single
1555 * g_object_set () have been called. But an idle function won't
1556 * work; we need to emit when the tag is changed, not when we get
1557 * around to the event loop. So blah, we eat some inefficiency.
1560 /* This is also somewhat weird since we emit another object's
1561 * signal here, but the two objects are already tightly bound.
1565 g_signal_emit_by_name (priv->table,
1567 text_tag, size_changed);
1571 gtk_text_tag_get_property (GObject *object,
1576 GtkTextTag *tag = GTK_TEXT_TAG (object);
1577 GtkTextTagPrivate *priv = tag->priv;
1582 g_value_set_string (value, priv->name);
1585 case PROP_BACKGROUND_GDK:
1586 g_value_set_boxed (value, &priv->values->appearance.bg_color);
1589 case PROP_BACKGROUND_RGBA:
1590 g_value_set_boxed (value, priv->values->appearance.rgba[0]);
1593 case PROP_FOREGROUND_GDK:
1594 g_value_set_boxed (value, &priv->values->appearance.fg_color);
1597 case PROP_FOREGROUND_RGBA:
1598 g_value_set_boxed (value, priv->values->appearance.rgba[1]);
1605 gtk_text_tag_ensure_font (tag);
1607 str = pango_font_description_to_string (priv->values->font);
1608 g_value_take_string (value, str);
1612 case PROP_FONT_DESC:
1613 gtk_text_tag_ensure_font (tag);
1614 g_value_set_boxed (value, priv->values->font);
1623 case PROP_SIZE_POINTS:
1624 gtk_text_tag_ensure_font (tag);
1628 g_value_set_string (value, pango_font_description_get_family (priv->values->font));
1632 g_value_set_enum (value, pango_font_description_get_style (priv->values->font));
1636 g_value_set_enum (value, pango_font_description_get_variant (priv->values->font));
1640 g_value_set_int (value, pango_font_description_get_weight (priv->values->font));
1644 g_value_set_enum (value, pango_font_description_get_stretch (priv->values->font));
1648 g_value_set_int (value, pango_font_description_get_size (priv->values->font));
1651 case PROP_SIZE_POINTS:
1652 g_value_set_double (value, ((double)pango_font_description_get_size (priv->values->font)) / (double)PANGO_SCALE);
1658 g_value_set_double (value, priv->values->font_scale);
1661 case PROP_PIXELS_ABOVE_LINES:
1662 g_value_set_int (value, priv->values->pixels_above_lines);
1665 case PROP_PIXELS_BELOW_LINES:
1666 g_value_set_int (value, priv->values->pixels_below_lines);
1669 case PROP_PIXELS_INSIDE_WRAP:
1670 g_value_set_int (value, priv->values->pixels_inside_wrap);
1674 g_value_set_boolean (value, priv->values->editable);
1677 case PROP_WRAP_MODE:
1678 g_value_set_enum (value, priv->values->wrap_mode);
1681 case PROP_JUSTIFICATION:
1682 g_value_set_enum (value, priv->values->justification);
1685 case PROP_DIRECTION:
1686 g_value_set_enum (value, priv->values->direction);
1689 case PROP_LEFT_MARGIN:
1690 g_value_set_int (value, priv->values->left_margin);
1694 g_value_set_int (value, priv->values->indent);
1697 case PROP_STRIKETHROUGH:
1698 g_value_set_boolean (value, priv->values->appearance.strikethrough);
1701 case PROP_RIGHT_MARGIN:
1702 g_value_set_int (value, priv->values->right_margin);
1705 case PROP_UNDERLINE:
1706 g_value_set_enum (value, priv->values->appearance.underline);
1710 g_value_set_int (value, priv->values->appearance.rise);
1713 case PROP_BACKGROUND_FULL_HEIGHT:
1714 g_value_set_boolean (value, priv->values->bg_full_height);
1718 g_value_set_string (value, pango_language_to_string (priv->values->language));
1722 if (priv->values->tabs)
1723 g_value_set_boxed (value, priv->values->tabs);
1726 case PROP_INVISIBLE:
1727 g_value_set_boolean (value, priv->values->invisible);
1730 case PROP_PARAGRAPH_BACKGROUND_GDK:
1731 g_value_set_boxed (value, priv->values->pg_bg_color);
1734 case PROP_PARAGRAPH_BACKGROUND_RGBA:
1735 g_value_set_boxed (value, priv->values->pg_bg_rgba);
1738 case PROP_ACCUMULATIVE_MARGIN:
1739 g_value_set_boolean (value, priv->accumulative_margin);
1742 case PROP_BACKGROUND_SET:
1743 g_value_set_boolean (value, priv->bg_color_set);
1746 case PROP_FOREGROUND_SET:
1747 g_value_set_boolean (value, priv->fg_color_set);
1750 case PROP_FAMILY_SET:
1751 case PROP_STYLE_SET:
1752 case PROP_VARIANT_SET:
1753 case PROP_WEIGHT_SET:
1754 case PROP_STRETCH_SET:
1757 PangoFontMask set_mask = priv->values->font ? pango_font_description_get_set_fields (priv->values->font) : 0;
1758 PangoFontMask test_mask = get_property_font_set_mask (prop_id);
1759 g_value_set_boolean (value, (set_mask & test_mask) != 0);
1764 case PROP_SCALE_SET:
1765 g_value_set_boolean (value, priv->scale_set);
1768 case PROP_PIXELS_ABOVE_LINES_SET:
1769 g_value_set_boolean (value, priv->pixels_above_lines_set);
1772 case PROP_PIXELS_BELOW_LINES_SET:
1773 g_value_set_boolean (value, priv->pixels_below_lines_set);
1776 case PROP_PIXELS_INSIDE_WRAP_SET:
1777 g_value_set_boolean (value, priv->pixels_inside_wrap_set);
1780 case PROP_EDITABLE_SET:
1781 g_value_set_boolean (value, priv->editable_set);
1784 case PROP_WRAP_MODE_SET:
1785 g_value_set_boolean (value, priv->wrap_mode_set);
1788 case PROP_JUSTIFICATION_SET:
1789 g_value_set_boolean (value, priv->justification_set);
1792 case PROP_LEFT_MARGIN_SET:
1793 g_value_set_boolean (value, priv->left_margin_set);
1796 case PROP_INDENT_SET:
1797 g_value_set_boolean (value, priv->indent_set);
1800 case PROP_STRIKETHROUGH_SET:
1801 g_value_set_boolean (value, priv->strikethrough_set);
1804 case PROP_RIGHT_MARGIN_SET:
1805 g_value_set_boolean (value, priv->right_margin_set);
1808 case PROP_UNDERLINE_SET:
1809 g_value_set_boolean (value, priv->underline_set);
1813 g_value_set_boolean (value, priv->rise_set);
1816 case PROP_BACKGROUND_FULL_HEIGHT_SET:
1817 g_value_set_boolean (value, priv->bg_full_height_set);
1820 case PROP_LANGUAGE_SET:
1821 g_value_set_boolean (value, priv->language_set);
1825 g_value_set_boolean (value, priv->tabs_set);
1828 case PROP_INVISIBLE_SET:
1829 g_value_set_boolean (value, priv->invisible_set);
1832 case PROP_PARAGRAPH_BACKGROUND_SET:
1833 g_value_set_boolean (value, priv->pg_bg_color_set);
1836 case PROP_BACKGROUND:
1837 case PROP_FOREGROUND:
1838 case PROP_PARAGRAPH_BACKGROUND:
1839 g_warning ("'foreground', 'background' and 'paragraph_background' properties are not readable, use 'foreground_gdk', 'background_gdk' and 'paragraph_background_gdk'");
1841 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1857 delta_priority_foreach (GtkTextTag *tag, gpointer user_data)
1859 GtkTextTagPrivate *priv = tag->priv;
1860 DeltaData *dd = user_data;
1862 if (priv->priority >= dd->low && priv->priority <= dd->high)
1863 priv->priority += dd->delta;
1867 * gtk_text_tag_get_priority:
1868 * @tag: a #GtkTextTag
1870 * Get the tag priority.
1872 * Return value: The tag's priority.
1875 gtk_text_tag_get_priority (GtkTextTag *tag)
1877 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), 0);
1879 return tag->priv->priority;
1883 * gtk_text_tag_set_priority:
1884 * @tag: a #GtkTextTag
1885 * @priority: the new priority
1887 * Sets the priority of a #GtkTextTag. Valid priorities are
1888 * start at 0 and go to one less than gtk_text_tag_table_get_size().
1889 * Each tag in a table has a unique priority; setting the priority
1890 * of one tag shifts the priorities of all the other tags in the
1891 * table to maintain a unique priority for each tag. Higher priority
1892 * tags "win" if two tags both set the same text attribute. When adding
1893 * a tag to a tag table, it will be assigned the highest priority in
1894 * the table by default; so normally the precedence of a set of tags
1895 * is the order in which they were added to the table, or created with
1896 * gtk_text_buffer_create_tag(), which adds the tag to the buffer's table
1900 gtk_text_tag_set_priority (GtkTextTag *tag,
1903 GtkTextTagPrivate *priv;
1906 g_return_if_fail (GTK_IS_TEXT_TAG (tag));
1910 g_return_if_fail (priv->table != NULL);
1911 g_return_if_fail (priority >= 0);
1912 g_return_if_fail (priority < gtk_text_tag_table_get_size (priv->table));
1914 if (priority == priv->priority)
1917 if (priority < priv->priority)
1920 dd.high = priv->priority - 1;
1925 dd.low = priv->priority + 1;
1930 gtk_text_tag_table_foreach (priv->table,
1931 delta_priority_foreach,
1934 priv->priority = priority;
1938 * gtk_text_tag_event:
1939 * @tag: a #GtkTextTag
1940 * @event_object: object that received the event, such as a widget
1942 * @iter: location where the event was received
1944 * Emits the "event" signal on the #GtkTextTag.
1946 * Return value: result of signal emission (whether the event was handled)
1949 gtk_text_tag_event (GtkTextTag *tag,
1950 GObject *event_object,
1952 const GtkTextIter *iter)
1954 gboolean retval = FALSE;
1956 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
1957 g_return_val_if_fail (G_IS_OBJECT (event_object), FALSE);
1958 g_return_val_if_fail (event != NULL, FALSE);
1972 tag_sort_func (gconstpointer first, gconstpointer second)
1974 GtkTextTag *tag1, *tag2;
1976 tag1 = * (GtkTextTag **) first;
1977 tag2 = * (GtkTextTag **) second;
1978 return tag1->priv->priority - tag2->priv->priority;
1982 _gtk_text_tag_array_sort (GtkTextTag** tag_array_p,
1987 GtkTextTag **maxPtrPtr, *tmp;
1989 g_return_if_fail (tag_array_p != NULL);
1990 g_return_if_fail (len > 0);
1996 GtkTextTag **iter = tag_array_p;
1998 for (i = len-1; i > 0; i--, iter++) {
1999 maxPtrPtr = tag = iter;
2000 prio = tag[0]->priv->priority;
2001 for (j = i, tag++; j > 0; j--, tag++) {
2002 if (tag[0]->priv->priority < prio) {
2003 prio = tag[0]->priv->priority;
2012 qsort ((void *) tag_array_p, (unsigned) len, sizeof (GtkTextTag *),
2018 printf ("Sorted tag array: \n");
2022 GtkTextTag *t = tag_array_p[i];
2023 printf (" %s priority %d\n", t->name, t->priority);