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 "gtktexttag.h"
72 #include "gtktexttypes.h"
73 #include "gtktexttagtable.h"
75 #include "gtkmarshalers.h"
76 #include "gtkprivate.h"
77 #include "gtktypebuiltins.h"
106 PROP_PIXELS_ABOVE_LINES,
107 PROP_PIXELS_BELOW_LINES,
108 PROP_PIXELS_INSIDE_WRAP,
119 PROP_BACKGROUND_FULL_HEIGHT,
123 PROP_PARAGRAPH_BACKGROUND,
124 PROP_PARAGRAPH_BACKGROUND_GDK,
125 PROP_PARAGRAPH_BACKGROUND_RGBA,
128 PROP_ACCUMULATIVE_MARGIN,
130 /* Whether-a-style-arg-is-set args */
140 PROP_PIXELS_ABOVE_LINES_SET,
141 PROP_PIXELS_BELOW_LINES_SET,
142 PROP_PIXELS_INSIDE_WRAP_SET,
145 PROP_JUSTIFICATION_SET,
146 PROP_LEFT_MARGIN_SET,
148 PROP_STRIKETHROUGH_SET,
149 PROP_RIGHT_MARGIN_SET,
152 PROP_BACKGROUND_FULL_HEIGHT_SET,
156 PROP_PARAGRAPH_BACKGROUND_SET,
160 static void gtk_text_tag_finalize (GObject *object);
161 static void gtk_text_tag_set_property (GObject *object,
165 static void gtk_text_tag_get_property (GObject *object,
170 static guint signals[LAST_SIGNAL] = { 0 };
172 G_DEFINE_TYPE (GtkTextTag, gtk_text_tag, G_TYPE_OBJECT)
175 gtk_text_tag_class_init (GtkTextTagClass *klass)
177 GObjectClass *object_class = G_OBJECT_CLASS (klass);
179 object_class->set_property = gtk_text_tag_set_property;
180 object_class->get_property = gtk_text_tag_get_property;
182 object_class->finalize = gtk_text_tag_finalize;
185 g_object_class_install_property (object_class,
187 g_param_spec_string ("name",
189 P_("Name used to refer to the text tag. NULL for anonymous tags"),
191 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
195 g_object_class_install_property (object_class,
197 g_param_spec_string ("background",
198 P_("Background color name"),
199 P_("Background color as a string"),
201 GTK_PARAM_WRITABLE));
203 g_object_class_install_property (object_class,
205 g_param_spec_boxed ("background-gdk",
206 P_("Background color"),
207 P_("Background color as a GdkColor"),
209 GTK_PARAM_READWRITE));
212 * GtkTextTag:background-rgba:
214 * Background color as a #GdkRGBA.
218 g_object_class_install_property (object_class,
219 PROP_BACKGROUND_RGBA,
220 g_param_spec_boxed ("background-rgba",
221 P_("Background RGBA"),
222 P_("Background color as a GdkRGBA"),
224 GTK_PARAM_READWRITE));
226 g_object_class_install_property (object_class,
227 PROP_BACKGROUND_FULL_HEIGHT,
228 g_param_spec_boolean ("background-full-height",
229 P_("Background full height"),
230 P_("Whether the background color fills the entire line height or only the height of the tagged characters"),
232 GTK_PARAM_READWRITE));
234 g_object_class_install_property (object_class,
236 g_param_spec_string ("foreground",
237 P_("Foreground color name"),
238 P_("Foreground color as a string"),
240 GTK_PARAM_WRITABLE));
242 g_object_class_install_property (object_class,
244 g_param_spec_boxed ("foreground-gdk",
245 P_("Foreground color"),
246 P_("Foreground color as a GdkColor"),
248 GTK_PARAM_READWRITE));
251 * GtkTextTag:foreground-rgba:
253 * Foreground color as a #GdkRGBA.
257 g_object_class_install_property (object_class,
258 PROP_FOREGROUND_RGBA,
259 g_param_spec_boxed ("foreground-rgba",
260 P_("Foreground RGBA"),
261 P_("Foreground color as a GdkRGBA"),
263 GTK_PARAM_READWRITE));
265 g_object_class_install_property (object_class,
267 g_param_spec_enum ("direction",
268 P_("Text direction"),
269 P_("Text direction, e.g. right-to-left or left-to-right"),
270 GTK_TYPE_TEXT_DIRECTION,
272 GTK_PARAM_READWRITE));
274 g_object_class_install_property (object_class,
276 g_param_spec_boolean ("editable",
278 P_("Whether the text can be modified by the user"),
280 GTK_PARAM_READWRITE));
285 * Font description as string, e.g. \"Sans Italic 12\".
287 * Note that the initial value of this property depends on
288 * the internals of #PangoFontDescription.
290 g_object_class_install_property (object_class,
292 g_param_spec_string ("font",
294 P_("Font description as a string, e.g. \"Sans Italic 12\""),
296 GTK_PARAM_READWRITE));
298 g_object_class_install_property (object_class,
300 g_param_spec_boxed ("font-desc",
302 P_("Font description as a PangoFontDescription struct"),
303 PANGO_TYPE_FONT_DESCRIPTION,
304 GTK_PARAM_READWRITE));
306 g_object_class_install_property (object_class,
308 g_param_spec_string ("family",
310 P_("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
312 GTK_PARAM_READWRITE));
314 g_object_class_install_property (object_class,
316 g_param_spec_enum ("style",
318 P_("Font style as a PangoStyle, e.g. PANGO_STYLE_ITALIC"),
321 GTK_PARAM_READWRITE));
323 g_object_class_install_property (object_class,
325 g_param_spec_enum ("variant",
327 P_("Font variant as a PangoVariant, e.g. PANGO_VARIANT_SMALL_CAPS"),
329 PANGO_VARIANT_NORMAL,
330 GTK_PARAM_READWRITE));
332 g_object_class_install_property (object_class,
334 g_param_spec_int ("weight",
336 P_("Font weight as an integer, see predefined values in PangoWeight; for example, PANGO_WEIGHT_BOLD"),
340 GTK_PARAM_READWRITE));
343 g_object_class_install_property (object_class,
345 g_param_spec_enum ("stretch",
347 P_("Font stretch as a PangoStretch, e.g. PANGO_STRETCH_CONDENSED"),
349 PANGO_STRETCH_NORMAL,
350 GTK_PARAM_READWRITE));
352 g_object_class_install_property (object_class,
354 g_param_spec_int ("size",
356 P_("Font size in Pango units"),
360 GTK_PARAM_READWRITE));
362 g_object_class_install_property (object_class,
364 g_param_spec_double ("scale",
366 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"),
370 GTK_PARAM_READWRITE));
372 g_object_class_install_property (object_class,
374 g_param_spec_double ("size-points",
376 P_("Font size in points"),
380 GTK_PARAM_READWRITE));
382 g_object_class_install_property (object_class,
384 g_param_spec_enum ("justification",
386 P_("Left, right, or center justification"),
387 GTK_TYPE_JUSTIFICATION,
389 GTK_PARAM_READWRITE));
392 * GtkTextTag:language:
394 * The language this text is in, as an ISO code. Pango can use this as a
395 * hint when rendering the text. If not set, an appropriate default will be
398 * Note that the initial value of this property depends on the current
399 * locale, see also gtk_get_default_language().
401 g_object_class_install_property (object_class,
403 g_param_spec_string ("language",
405 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."),
407 GTK_PARAM_READWRITE));
409 g_object_class_install_property (object_class,
411 g_param_spec_int ("left-margin",
413 P_("Width of the left margin in pixels"),
417 GTK_PARAM_READWRITE));
419 g_object_class_install_property (object_class,
421 g_param_spec_int ("right-margin",
423 P_("Width of the right margin in pixels"),
427 GTK_PARAM_READWRITE));
430 g_object_class_install_property (object_class,
432 g_param_spec_int ("indent",
434 P_("Amount to indent the paragraph, in pixels"),
438 GTK_PARAM_READWRITE));
441 g_object_class_install_property (object_class,
443 g_param_spec_int ("rise",
445 P_("Offset of text above the baseline (below the baseline if rise is negative) in Pango units"),
449 GTK_PARAM_READWRITE));
451 g_object_class_install_property (object_class,
452 PROP_PIXELS_ABOVE_LINES,
453 g_param_spec_int ("pixels-above-lines",
454 P_("Pixels above lines"),
455 P_("Pixels of blank space above paragraphs"),
459 GTK_PARAM_READWRITE));
461 g_object_class_install_property (object_class,
462 PROP_PIXELS_BELOW_LINES,
463 g_param_spec_int ("pixels-below-lines",
464 P_("Pixels below lines"),
465 P_("Pixels of blank space below paragraphs"),
469 GTK_PARAM_READWRITE));
471 g_object_class_install_property (object_class,
472 PROP_PIXELS_INSIDE_WRAP,
473 g_param_spec_int ("pixels-inside-wrap",
474 P_("Pixels inside wrap"),
475 P_("Pixels of blank space between wrapped lines in a paragraph"),
479 GTK_PARAM_READWRITE));
481 g_object_class_install_property (object_class,
483 g_param_spec_boolean ("strikethrough",
485 P_("Whether to strike through the text"),
487 GTK_PARAM_READWRITE));
489 g_object_class_install_property (object_class,
491 g_param_spec_enum ("underline",
493 P_("Style of underline for this text"),
494 PANGO_TYPE_UNDERLINE,
495 PANGO_UNDERLINE_NONE,
496 GTK_PARAM_READWRITE));
498 g_object_class_install_property (object_class,
500 g_param_spec_enum ("wrap-mode",
502 P_("Whether to wrap lines never, at word boundaries, or at character boundaries"),
505 GTK_PARAM_READWRITE));
508 g_object_class_install_property (object_class,
510 g_param_spec_boxed ("tabs",
512 P_("Custom tabs for this text"),
513 PANGO_TYPE_TAB_ARRAY,
514 GTK_PARAM_READWRITE));
517 * GtkTextTag:invisible:
519 * Whether this text is hidden.
521 * Note that there may still be problems with the support for invisible
522 * text, in particular when navigating programmatically inside a buffer
523 * containing invisible segments.
527 g_object_class_install_property (object_class,
529 g_param_spec_boolean ("invisible",
531 P_("Whether this text is hidden."),
533 GTK_PARAM_READWRITE));
536 * GtkTextTag:paragraph-background:
538 * The paragraph background color as a string.
542 g_object_class_install_property (object_class,
543 PROP_PARAGRAPH_BACKGROUND,
544 g_param_spec_string ("paragraph-background",
545 P_("Paragraph background color name"),
546 P_("Paragraph background color as a string"),
548 GTK_PARAM_WRITABLE));
551 * GtkTextTag:paragraph-background-gdk:
553 * The paragraph background color as a as a #GdkColor.
557 g_object_class_install_property (object_class,
558 PROP_PARAGRAPH_BACKGROUND_GDK,
559 g_param_spec_boxed ("paragraph-background-gdk",
560 P_("Paragraph background color"),
561 P_("Paragraph background color as a GdkColor"),
563 GTK_PARAM_READWRITE));
566 * GtkTextTag:paragraph-background-rgba:
568 * The paragraph background color as a as a #GdkRGBA.
572 g_object_class_install_property (object_class,
573 PROP_PARAGRAPH_BACKGROUND_RGBA,
574 g_param_spec_boxed ("paragraph-background-rgba",
575 P_("Paragraph background RGBA"),
576 P_("Paragraph background RGBA as a GdkRGBA"),
578 GTK_PARAM_READWRITE));
581 * GtkTextTag:accumulative-margin:
583 * Whether the margins accumulate or override each other.
585 * When set to %TRUE the margins of this tag are added to the margins
586 * of any other non-accumulative margins present. When set to %FALSE
587 * the margins override one another (the default).
591 g_object_class_install_property (object_class,
592 PROP_ACCUMULATIVE_MARGIN,
593 g_param_spec_boolean ("accumulative-margin",
594 P_("Margin Accumulates"),
595 P_("Whether left and right margins accumulate."),
597 GTK_PARAM_READWRITE));
599 /* Style props are set or not */
601 #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))
603 ADD_SET_PROP ("background-set", PROP_BACKGROUND_SET,
604 P_("Background set"),
605 P_("Whether this tag affects the background color"));
607 ADD_SET_PROP ("background-full-height-set", PROP_BACKGROUND_FULL_HEIGHT_SET,
608 P_("Background full height set"),
609 P_("Whether this tag affects background height"));
611 ADD_SET_PROP ("foreground-set", PROP_FOREGROUND_SET,
612 P_("Foreground set"),
613 P_("Whether this tag affects the foreground color"));
615 ADD_SET_PROP ("editable-set", PROP_EDITABLE_SET,
616 P_("Editability set"),
617 P_("Whether this tag affects text editability"));
619 ADD_SET_PROP ("family-set", PROP_FAMILY_SET,
620 P_("Font family set"),
621 P_("Whether this tag affects the font family"));
623 ADD_SET_PROP ("style-set", PROP_STYLE_SET,
624 P_("Font style set"),
625 P_("Whether this tag affects the font style"));
627 ADD_SET_PROP ("variant-set", PROP_VARIANT_SET,
628 P_("Font variant set"),
629 P_("Whether this tag affects the font variant"));
631 ADD_SET_PROP ("weight-set", PROP_WEIGHT_SET,
632 P_("Font weight set"),
633 P_("Whether this tag affects the font weight"));
635 ADD_SET_PROP ("stretch-set", PROP_STRETCH_SET,
636 P_("Font stretch set"),
637 P_("Whether this tag affects the font stretch"));
639 ADD_SET_PROP ("size-set", PROP_SIZE_SET,
641 P_("Whether this tag affects the font size"));
643 ADD_SET_PROP ("scale-set", PROP_SCALE_SET,
644 P_("Font scale set"),
645 P_("Whether this tag scales the font size by a factor"));
647 ADD_SET_PROP ("justification-set", PROP_JUSTIFICATION_SET,
648 P_("Justification set"),
649 P_("Whether this tag affects paragraph justification"));
651 ADD_SET_PROP ("language-set", PROP_LANGUAGE_SET,
653 P_("Whether this tag affects the language the text is rendered as"));
655 ADD_SET_PROP ("left-margin-set", PROP_LEFT_MARGIN_SET,
656 P_("Left margin set"),
657 P_("Whether this tag affects the left margin"));
659 ADD_SET_PROP ("indent-set", PROP_INDENT_SET,
661 P_("Whether this tag affects indentation"));
663 ADD_SET_PROP ("rise-set", PROP_RISE_SET,
665 P_("Whether this tag affects the rise"));
667 ADD_SET_PROP ("pixels-above-lines-set", PROP_PIXELS_ABOVE_LINES_SET,
668 P_("Pixels above lines set"),
669 P_("Whether this tag affects the number of pixels above lines"));
671 ADD_SET_PROP ("pixels-below-lines-set", PROP_PIXELS_BELOW_LINES_SET,
672 P_("Pixels below lines set"),
673 P_("Whether this tag affects the number of pixels above lines"));
675 ADD_SET_PROP ("pixels-inside-wrap-set", PROP_PIXELS_INSIDE_WRAP_SET,
676 P_("Pixels inside wrap set"),
677 P_("Whether this tag affects the number of pixels between wrapped lines"));
679 ADD_SET_PROP ("strikethrough-set", PROP_STRIKETHROUGH_SET,
680 P_("Strikethrough set"),
681 P_("Whether this tag affects strikethrough"));
683 ADD_SET_PROP ("right-margin-set", PROP_RIGHT_MARGIN_SET,
684 P_("Right margin set"),
685 P_("Whether this tag affects the right margin"));
687 ADD_SET_PROP ("underline-set", PROP_UNDERLINE_SET,
689 P_("Whether this tag affects underlining"));
691 ADD_SET_PROP ("wrap-mode-set", PROP_WRAP_MODE_SET,
693 P_("Whether this tag affects line wrap mode"));
695 ADD_SET_PROP ("tabs-set", PROP_TABS_SET,
697 P_("Whether this tag affects tabs"));
699 ADD_SET_PROP ("invisible-set", PROP_INVISIBLE_SET,
701 P_("Whether this tag affects text visibility"));
703 ADD_SET_PROP ("paragraph-background-set", PROP_PARAGRAPH_BACKGROUND_SET,
704 P_("Paragraph background set"),
705 P_("Whether this tag affects the paragraph background color"));
709 * @tag: the #GtkTextTag on which the signal is emitted
710 * @object: the object the event was fired from (typically a #GtkTextView)
711 * @event: the event which triggered the signal
712 * @iter: a #GtkTextIter pointing at the location the event occured
714 * The ::event signal is emitted when an event occurs on a region of the
715 * buffer marked with this tag.
717 * Returns: %TRUE to stop other handlers from being invoked for the
718 * event. %FALSE to propagate the event further.
721 g_signal_new (I_("event"),
722 G_OBJECT_CLASS_TYPE (object_class),
724 G_STRUCT_OFFSET (GtkTextTagClass, event),
725 _gtk_boolean_handled_accumulator, NULL,
726 _gtk_marshal_BOOLEAN__OBJECT_BOXED_BOXED,
730 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE,
733 g_type_class_add_private (klass, sizeof (GtkTextTagPrivate));
737 gtk_text_tag_init (GtkTextTag *text_tag)
739 GtkTextTagPrivate *priv;
741 text_tag->priv = G_TYPE_INSTANCE_GET_PRIVATE (text_tag,
744 priv = text_tag->priv;
746 priv->values = gtk_text_attributes_new ();
751 * @name: (allow-none): tag name, or %NULL
753 * Creates a #GtkTextTag. Configure the tag using object arguments,
754 * i.e. using g_object_set().
756 * Return value: a new #GtkTextTag
759 gtk_text_tag_new (const gchar *name)
763 tag = g_object_new (GTK_TYPE_TEXT_TAG, "name", name, NULL);
769 gtk_text_tag_finalize (GObject *object)
771 GtkTextTag *text_tag = GTK_TEXT_TAG (object);
772 GtkTextTagPrivate *priv = text_tag->priv;
775 gtk_text_tag_table_remove (priv->table, text_tag);
777 g_assert (priv->table == NULL);
779 gtk_text_attributes_unref (priv->values);
785 G_OBJECT_CLASS (gtk_text_tag_parent_class)->finalize (object);
789 copy_rgba_to_gdk_color (GdkRGBA *src,
792 dest->red = CLAMP (src->red, 0.0, 1.0) * 65535.0;
793 dest->green = CLAMP (src->green, 0.0, 1.0) * 65535.0;
794 dest->blue = CLAMP (src->blue, 0.0, 1.0) * 65535.0;
798 copy_gdk_color_to_rgba (GdkColor *src,
801 dest->red = src->red / 65535.;
802 dest->green = src->green / 65535.;
803 dest->blue = src->blue / 65535.;
808 set_bg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
810 GtkTextTagPrivate *priv = tag->priv;
812 if (priv->values->appearance.rgba[0])
813 gdk_rgba_free (priv->values->appearance.rgba[0]);
815 priv->values->appearance.rgba[0] = NULL;
819 if (!priv->bg_color_set)
821 priv->bg_color_set = TRUE;
822 g_object_notify (G_OBJECT (tag), "background-set");
825 priv->values->appearance.rgba[0] = gdk_rgba_copy (rgba);
827 copy_rgba_to_gdk_color (rgba, &priv->values->appearance.bg_color);
831 if (priv->bg_color_set)
833 priv->bg_color_set = FALSE;
834 g_object_notify (G_OBJECT (tag), "background-set");
840 set_fg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
842 GtkTextTagPrivate *priv = tag->priv;
844 if (priv->values->appearance.rgba[1])
845 gdk_rgba_free (priv->values->appearance.rgba[1]);
847 priv->values->appearance.rgba[1] = NULL;
851 if (!priv->fg_color_set)
853 priv->fg_color_set = TRUE;
854 g_object_notify (G_OBJECT (tag), "foreground-set");
857 priv->values->appearance.rgba[1] = gdk_rgba_copy (rgba);
859 copy_rgba_to_gdk_color (rgba, &priv->values->appearance.fg_color);
863 if (priv->fg_color_set)
865 priv->fg_color_set = FALSE;
866 g_object_notify (G_OBJECT (tag), "foreground-set");
872 set_pg_bg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
874 GtkTextTagPrivate *priv = tag->priv;
876 if (priv->values->pg_bg_rgba)
877 gdk_rgba_free (priv->values->pg_bg_rgba);
879 if (priv->values->pg_bg_color)
880 gdk_color_free (priv->values->pg_bg_color);
882 priv->values->pg_bg_rgba = NULL;
883 priv->values->pg_bg_color = NULL;
887 GdkColor color = { 0, };
889 if (!priv->pg_bg_color_set)
891 priv->pg_bg_color_set = TRUE;
892 g_object_notify (G_OBJECT (tag), "paragraph-background-set");
895 priv->values->pg_bg_rgba = gdk_rgba_copy (rgba);
897 copy_rgba_to_gdk_color (rgba, &color);
898 priv->values->pg_bg_color = gdk_color_copy (&color);
902 if (priv->pg_bg_color_set)
904 priv->pg_bg_color_set = FALSE;
905 g_object_notify (G_OBJECT (tag), "paragraph-background-set");
912 set_bg_color (GtkTextTag *tag, GdkColor *color)
918 copy_gdk_color_to_rgba (color, &rgba);
919 set_bg_rgba (tag, &rgba);
922 set_bg_rgba (tag, NULL);
926 set_fg_color (GtkTextTag *tag, GdkColor *color)
932 copy_gdk_color_to_rgba (color, &rgba);
933 set_fg_rgba (tag, &rgba);
936 set_fg_rgba (tag, NULL);
940 set_pg_bg_color (GtkTextTag *tag, GdkColor *color)
946 copy_gdk_color_to_rgba (color, &rgba);
947 set_pg_bg_rgba (tag, &rgba);
950 set_pg_bg_rgba (tag, NULL);
954 get_property_font_set_mask (guint prop_id)
958 case PROP_FAMILY_SET:
959 return PANGO_FONT_MASK_FAMILY;
961 return PANGO_FONT_MASK_STYLE;
962 case PROP_VARIANT_SET:
963 return PANGO_FONT_MASK_VARIANT;
964 case PROP_WEIGHT_SET:
965 return PANGO_FONT_MASK_WEIGHT;
966 case PROP_STRETCH_SET:
967 return PANGO_FONT_MASK_STRETCH;
969 return PANGO_FONT_MASK_SIZE;
976 set_font_desc_fields (PangoFontDescription *desc,
977 PangoFontMask to_set)
979 PangoFontMask changed_mask = 0;
981 if (to_set & PANGO_FONT_MASK_FAMILY)
983 const char *family = pango_font_description_get_family (desc);
987 changed_mask |= PANGO_FONT_MASK_FAMILY;
990 pango_font_description_set_family (desc, family);
992 if (to_set & PANGO_FONT_MASK_STYLE)
993 pango_font_description_set_style (desc, pango_font_description_get_style (desc));
994 if (to_set & PANGO_FONT_MASK_VARIANT)
995 pango_font_description_set_variant (desc, pango_font_description_get_variant (desc));
996 if (to_set & PANGO_FONT_MASK_WEIGHT)
997 pango_font_description_set_weight (desc, pango_font_description_get_weight (desc));
998 if (to_set & PANGO_FONT_MASK_STRETCH)
999 pango_font_description_set_stretch (desc, pango_font_description_get_stretch (desc));
1000 if (to_set & PANGO_FONT_MASK_SIZE)
1002 gint size = pango_font_description_get_size (desc);
1005 size = 10 * PANGO_SCALE;
1006 changed_mask |= PANGO_FONT_MASK_SIZE;
1009 pango_font_description_set_size (desc, size);
1012 return changed_mask;
1016 notify_set_changed (GObject *object,
1017 PangoFontMask changed_mask)
1019 if (changed_mask & PANGO_FONT_MASK_FAMILY)
1020 g_object_notify (object, "family-set");
1021 if (changed_mask & PANGO_FONT_MASK_STYLE)
1022 g_object_notify (object, "style-set");
1023 if (changed_mask & PANGO_FONT_MASK_VARIANT)
1024 g_object_notify (object, "variant-set");
1025 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
1026 g_object_notify (object, "weight-set");
1027 if (changed_mask & PANGO_FONT_MASK_STRETCH)
1028 g_object_notify (object, "stretch-set");
1029 if (changed_mask & PANGO_FONT_MASK_SIZE)
1030 g_object_notify (object, "size-set");
1034 notify_fields_changed (GObject *object,
1035 PangoFontMask changed_mask)
1037 if (changed_mask & PANGO_FONT_MASK_FAMILY)
1038 g_object_notify (object, "family");
1039 if (changed_mask & PANGO_FONT_MASK_STYLE)
1040 g_object_notify (object, "style");
1041 if (changed_mask & PANGO_FONT_MASK_VARIANT)
1042 g_object_notify (object, "variant");
1043 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
1044 g_object_notify (object, "weight");
1045 if (changed_mask & PANGO_FONT_MASK_STRETCH)
1046 g_object_notify (object, "stretch");
1047 if (changed_mask & PANGO_FONT_MASK_SIZE)
1048 g_object_notify (object, "size");
1052 set_font_description (GtkTextTag *text_tag,
1053 PangoFontDescription *font_desc)
1055 GtkTextTagPrivate *priv = text_tag->priv;
1056 GObject *object = G_OBJECT (text_tag);
1057 PangoFontDescription *new_font_desc;
1058 PangoFontMask old_mask, new_mask, changed_mask, set_changed_mask;
1061 new_font_desc = pango_font_description_copy (font_desc);
1063 new_font_desc = pango_font_description_new ();
1065 if (priv->values->font)
1066 old_mask = pango_font_description_get_set_fields (priv->values->font);
1070 new_mask = pango_font_description_get_set_fields (new_font_desc);
1072 changed_mask = old_mask | new_mask;
1073 set_changed_mask = old_mask ^ new_mask;
1075 if (priv->values->font)
1076 pango_font_description_free (priv->values->font);
1077 priv->values->font = new_font_desc;
1079 g_object_freeze_notify (object);
1081 g_object_notify (object, "font-desc");
1082 g_object_notify (object, "font");
1084 if (changed_mask & PANGO_FONT_MASK_FAMILY)
1085 g_object_notify (object, "family");
1086 if (changed_mask & PANGO_FONT_MASK_STYLE)
1087 g_object_notify (object, "style");
1088 if (changed_mask & PANGO_FONT_MASK_VARIANT)
1089 g_object_notify (object, "variant");
1090 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
1091 g_object_notify (object, "weight");
1092 if (changed_mask & PANGO_FONT_MASK_STRETCH)
1093 g_object_notify (object, "stretch");
1094 if (changed_mask & PANGO_FONT_MASK_SIZE)
1096 g_object_notify (object, "size");
1097 g_object_notify (object, "size-points");
1100 notify_set_changed (object, set_changed_mask);
1102 g_object_thaw_notify (object);
1106 gtk_text_tag_ensure_font (GtkTextTag *text_tag)
1108 GtkTextTagPrivate *priv = text_tag->priv;
1110 if (!priv->values->font)
1111 priv->values->font = pango_font_description_new ();
1115 gtk_text_tag_set_property (GObject *object,
1117 const GValue *value,
1120 GtkTextTag *text_tag = GTK_TEXT_TAG (object);
1121 GtkTextTagPrivate *priv = text_tag->priv;
1122 gboolean size_changed = FALSE;
1127 g_return_if_fail (priv->name == NULL);
1128 priv->name = g_value_dup_string (value);
1131 case PROP_BACKGROUND:
1135 if (!g_value_get_string (value))
1136 set_bg_rgba (text_tag, NULL); /* reset background_set to FALSE */
1137 else if (gdk_rgba_parse (&rgba, g_value_get_string (value)))
1138 set_bg_rgba (text_tag, &rgba);
1140 g_warning ("Don't know color `%s'", g_value_get_string (value));
1142 g_object_notify (object, "background-gdk");
1146 case PROP_FOREGROUND:
1150 if (!g_value_get_string (value))
1151 set_fg_rgba (text_tag, NULL); /* reset to foreground_set to FALSE */
1152 else if (gdk_rgba_parse (&rgba, g_value_get_string (value)))
1153 set_fg_rgba (text_tag, &rgba);
1155 g_warning ("Don't know color `%s'", g_value_get_string (value));
1157 g_object_notify (object, "foreground-gdk");
1161 case PROP_BACKGROUND_GDK:
1163 GdkColor *color = g_value_get_boxed (value);
1165 set_bg_color (text_tag, color);
1169 case PROP_FOREGROUND_GDK:
1171 GdkColor *color = g_value_get_boxed (value);
1173 set_fg_color (text_tag, color);
1177 case PROP_BACKGROUND_RGBA:
1179 GdkRGBA *color = g_value_get_boxed (value);
1181 set_bg_rgba (text_tag, color);
1185 case PROP_FOREGROUND_RGBA:
1187 GdkRGBA *color = g_value_get_boxed (value);
1189 set_fg_rgba (text_tag, color);
1195 PangoFontDescription *font_desc = NULL;
1198 name = g_value_get_string (value);
1201 font_desc = pango_font_description_from_string (name);
1203 set_font_description (text_tag, font_desc);
1205 pango_font_description_free (font_desc);
1207 size_changed = TRUE;
1211 case PROP_FONT_DESC:
1213 PangoFontDescription *font_desc;
1215 font_desc = g_value_get_boxed (value);
1217 set_font_description (text_tag, font_desc);
1219 size_changed = TRUE;
1229 case PROP_SIZE_POINTS:
1231 PangoFontMask old_set_mask;
1233 gtk_text_tag_ensure_font (text_tag);
1234 old_set_mask = pango_font_description_get_set_fields (priv->values->font);
1239 pango_font_description_set_family (priv->values->font,
1240 g_value_get_string (value));
1243 pango_font_description_set_style (priv->values->font,
1244 g_value_get_enum (value));
1247 pango_font_description_set_variant (priv->values->font,
1248 g_value_get_enum (value));
1251 pango_font_description_set_weight (priv->values->font,
1252 g_value_get_int (value));
1255 pango_font_description_set_stretch (priv->values->font,
1256 g_value_get_enum (value));
1259 pango_font_description_set_size (priv->values->font,
1260 g_value_get_int (value));
1261 g_object_notify (object, "size-points");
1263 case PROP_SIZE_POINTS:
1264 pango_font_description_set_size (priv->values->font,
1265 g_value_get_double (value) * PANGO_SCALE);
1266 g_object_notify (object, "size");
1270 size_changed = TRUE;
1271 notify_set_changed (object, old_set_mask & pango_font_description_get_set_fields (priv->values->font));
1272 g_object_notify (object, "font-desc");
1273 g_object_notify (object, "font");
1279 priv->values->font_scale = g_value_get_double (value);
1280 priv->scale_set = TRUE;
1281 g_object_notify (object, "scale-set");
1282 size_changed = TRUE;
1285 case PROP_PIXELS_ABOVE_LINES:
1286 priv->pixels_above_lines_set = TRUE;
1287 priv->values->pixels_above_lines = g_value_get_int (value);
1288 g_object_notify (object, "pixels-above-lines-set");
1289 size_changed = TRUE;
1292 case PROP_PIXELS_BELOW_LINES:
1293 priv->pixels_below_lines_set = TRUE;
1294 priv->values->pixels_below_lines = g_value_get_int (value);
1295 g_object_notify (object, "pixels-below-lines-set");
1296 size_changed = TRUE;
1299 case PROP_PIXELS_INSIDE_WRAP:
1300 priv->pixels_inside_wrap_set = TRUE;
1301 priv->values->pixels_inside_wrap = g_value_get_int (value);
1302 g_object_notify (object, "pixels-inside-wrap-set");
1303 size_changed = TRUE;
1307 priv->editable_set = TRUE;
1308 priv->values->editable = g_value_get_boolean (value);
1309 g_object_notify (object, "editable-set");
1312 case PROP_WRAP_MODE:
1313 priv->wrap_mode_set = TRUE;
1314 priv->values->wrap_mode = g_value_get_enum (value);
1315 g_object_notify (object, "wrap-mode-set");
1316 size_changed = TRUE;
1319 case PROP_JUSTIFICATION:
1320 priv->justification_set = TRUE;
1321 priv->values->justification = g_value_get_enum (value);
1322 g_object_notify (object, "justification-set");
1323 size_changed = TRUE;
1326 case PROP_DIRECTION:
1327 priv->values->direction = g_value_get_enum (value);
1330 case PROP_LEFT_MARGIN:
1331 priv->left_margin_set = TRUE;
1332 priv->values->left_margin = g_value_get_int (value);
1333 g_object_notify (object, "left-margin-set");
1334 size_changed = TRUE;
1338 priv->indent_set = TRUE;
1339 priv->values->indent = g_value_get_int (value);
1340 g_object_notify (object, "indent-set");
1341 size_changed = TRUE;
1344 case PROP_STRIKETHROUGH:
1345 priv->strikethrough_set = TRUE;
1346 priv->values->appearance.strikethrough = g_value_get_boolean (value);
1347 g_object_notify (object, "strikethrough-set");
1350 case PROP_RIGHT_MARGIN:
1351 priv->right_margin_set = TRUE;
1352 priv->values->right_margin = g_value_get_int (value);
1353 g_object_notify (object, "right-margin-set");
1354 size_changed = TRUE;
1357 case PROP_UNDERLINE:
1358 priv->underline_set = TRUE;
1359 priv->values->appearance.underline = g_value_get_enum (value);
1360 g_object_notify (object, "underline-set");
1364 priv->rise_set = TRUE;
1365 priv->values->appearance.rise = g_value_get_int (value);
1366 g_object_notify (object, "rise-set");
1367 size_changed = TRUE;
1370 case PROP_BACKGROUND_FULL_HEIGHT:
1371 priv->bg_full_height_set = TRUE;
1372 priv->values->bg_full_height = g_value_get_boolean (value);
1373 g_object_notify (object, "background-full-height-set");
1377 priv->language_set = TRUE;
1378 priv->values->language = pango_language_from_string (g_value_get_string (value));
1379 g_object_notify (object, "language-set");
1383 priv->tabs_set = TRUE;
1385 if (priv->values->tabs)
1386 pango_tab_array_free (priv->values->tabs);
1388 /* FIXME I'm not sure if this is a memleak or not */
1389 priv->values->tabs =
1390 pango_tab_array_copy (g_value_get_boxed (value));
1392 g_object_notify (object, "tabs-set");
1394 size_changed = TRUE;
1397 case PROP_INVISIBLE:
1398 priv->invisible_set = TRUE;
1399 priv->values->invisible = g_value_get_boolean (value);
1400 g_object_notify (object, "invisible-set");
1401 size_changed = TRUE;
1404 case PROP_PARAGRAPH_BACKGROUND:
1408 if (!g_value_get_string (value))
1409 set_pg_bg_rgba (text_tag, NULL); /* reset paragraph_background_set to FALSE */
1410 else if (gdk_rgba_parse (&rgba, g_value_get_string (value)))
1411 set_pg_bg_rgba (text_tag, &rgba);
1413 g_warning ("Don't know color `%s'", g_value_get_string (value));
1415 g_object_notify (object, "paragraph-background-gdk");
1419 case PROP_PARAGRAPH_BACKGROUND_GDK:
1421 GdkColor *color = g_value_get_boxed (value);
1423 set_pg_bg_color (text_tag, color);
1427 case PROP_PARAGRAPH_BACKGROUND_RGBA:
1429 GdkRGBA *color = g_value_get_boxed (value);
1431 set_pg_bg_rgba (text_tag, color);
1435 case PROP_ACCUMULATIVE_MARGIN:
1436 priv->accumulative_margin = g_value_get_boolean (value);
1437 g_object_notify (object, "accumulative-margin");
1438 size_changed = TRUE;
1441 /* Whether the value should be used... */
1443 case PROP_BACKGROUND_SET:
1444 priv->bg_color_set = g_value_get_boolean (value);
1447 case PROP_FOREGROUND_SET:
1448 priv->fg_color_set = g_value_get_boolean (value);
1451 case PROP_FAMILY_SET:
1452 case PROP_STYLE_SET:
1453 case PROP_VARIANT_SET:
1454 case PROP_WEIGHT_SET:
1455 case PROP_STRETCH_SET:
1457 if (!g_value_get_boolean (value))
1459 if (priv->values->font)
1460 pango_font_description_unset_fields (priv->values->font,
1461 get_property_font_set_mask (prop_id));
1465 PangoFontMask changed_mask;
1467 gtk_text_tag_ensure_font (text_tag);
1468 changed_mask = set_font_desc_fields (priv->values->font,
1469 get_property_font_set_mask (prop_id));
1470 notify_fields_changed (G_OBJECT (text_tag), changed_mask);
1474 case PROP_SCALE_SET:
1475 priv->scale_set = g_value_get_boolean (value);
1476 size_changed = TRUE;
1479 case PROP_PIXELS_ABOVE_LINES_SET:
1480 priv->pixels_above_lines_set = g_value_get_boolean (value);
1481 size_changed = TRUE;
1484 case PROP_PIXELS_BELOW_LINES_SET:
1485 priv->pixels_below_lines_set = g_value_get_boolean (value);
1486 size_changed = TRUE;
1489 case PROP_PIXELS_INSIDE_WRAP_SET:
1490 priv->pixels_inside_wrap_set = g_value_get_boolean (value);
1491 size_changed = TRUE;
1494 case PROP_EDITABLE_SET:
1495 priv->editable_set = g_value_get_boolean (value);
1498 case PROP_WRAP_MODE_SET:
1499 priv->wrap_mode_set = g_value_get_boolean (value);
1500 size_changed = TRUE;
1503 case PROP_JUSTIFICATION_SET:
1504 priv->justification_set = g_value_get_boolean (value);
1505 size_changed = TRUE;
1508 case PROP_LEFT_MARGIN_SET:
1509 priv->left_margin_set = g_value_get_boolean (value);
1510 size_changed = TRUE;
1513 case PROP_INDENT_SET:
1514 priv->indent_set = g_value_get_boolean (value);
1515 size_changed = TRUE;
1518 case PROP_STRIKETHROUGH_SET:
1519 priv->strikethrough_set = g_value_get_boolean (value);
1522 case PROP_RIGHT_MARGIN_SET:
1523 priv->right_margin_set = g_value_get_boolean (value);
1524 size_changed = TRUE;
1527 case PROP_UNDERLINE_SET:
1528 priv->underline_set = g_value_get_boolean (value);
1532 priv->rise_set = g_value_get_boolean (value);
1533 size_changed = TRUE;
1536 case PROP_BACKGROUND_FULL_HEIGHT_SET:
1537 priv->bg_full_height_set = g_value_get_boolean (value);
1540 case PROP_LANGUAGE_SET:
1541 priv->language_set = g_value_get_boolean (value);
1542 size_changed = TRUE;
1546 priv->tabs_set = g_value_get_boolean (value);
1547 size_changed = TRUE;
1550 case PROP_INVISIBLE_SET:
1551 priv->invisible_set = g_value_get_boolean (value);
1552 size_changed = TRUE;
1555 case PROP_PARAGRAPH_BACKGROUND_SET:
1556 priv->pg_bg_color_set = g_value_get_boolean (value);
1560 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1564 /* FIXME I would like to do this after all set_property in a single
1565 * g_object_set () have been called. But an idle function won't
1566 * work; we need to emit when the tag is changed, not when we get
1567 * around to the event loop. So blah, we eat some inefficiency.
1570 /* This is also somewhat weird since we emit another object's
1571 * signal here, but the two objects are already tightly bound.
1575 g_signal_emit_by_name (priv->table,
1577 text_tag, size_changed);
1581 gtk_text_tag_get_property (GObject *object,
1586 GtkTextTag *tag = GTK_TEXT_TAG (object);
1587 GtkTextTagPrivate *priv = tag->priv;
1592 g_value_set_string (value, priv->name);
1595 case PROP_BACKGROUND_GDK:
1596 g_value_set_boxed (value, &priv->values->appearance.bg_color);
1599 case PROP_BACKGROUND_RGBA:
1600 g_value_set_boxed (value, priv->values->appearance.rgba[0]);
1603 case PROP_FOREGROUND_GDK:
1604 g_value_set_boxed (value, &priv->values->appearance.fg_color);
1607 case PROP_FOREGROUND_RGBA:
1608 g_value_set_boxed (value, priv->values->appearance.rgba[1]);
1615 gtk_text_tag_ensure_font (tag);
1617 str = pango_font_description_to_string (priv->values->font);
1618 g_value_take_string (value, str);
1622 case PROP_FONT_DESC:
1623 gtk_text_tag_ensure_font (tag);
1624 g_value_set_boxed (value, priv->values->font);
1633 case PROP_SIZE_POINTS:
1634 gtk_text_tag_ensure_font (tag);
1638 g_value_set_string (value, pango_font_description_get_family (priv->values->font));
1642 g_value_set_enum (value, pango_font_description_get_style (priv->values->font));
1646 g_value_set_enum (value, pango_font_description_get_variant (priv->values->font));
1650 g_value_set_int (value, pango_font_description_get_weight (priv->values->font));
1654 g_value_set_enum (value, pango_font_description_get_stretch (priv->values->font));
1658 g_value_set_int (value, pango_font_description_get_size (priv->values->font));
1661 case PROP_SIZE_POINTS:
1662 g_value_set_double (value, ((double)pango_font_description_get_size (priv->values->font)) / (double)PANGO_SCALE);
1668 g_value_set_double (value, priv->values->font_scale);
1671 case PROP_PIXELS_ABOVE_LINES:
1672 g_value_set_int (value, priv->values->pixels_above_lines);
1675 case PROP_PIXELS_BELOW_LINES:
1676 g_value_set_int (value, priv->values->pixels_below_lines);
1679 case PROP_PIXELS_INSIDE_WRAP:
1680 g_value_set_int (value, priv->values->pixels_inside_wrap);
1684 g_value_set_boolean (value, priv->values->editable);
1687 case PROP_WRAP_MODE:
1688 g_value_set_enum (value, priv->values->wrap_mode);
1691 case PROP_JUSTIFICATION:
1692 g_value_set_enum (value, priv->values->justification);
1695 case PROP_DIRECTION:
1696 g_value_set_enum (value, priv->values->direction);
1699 case PROP_LEFT_MARGIN:
1700 g_value_set_int (value, priv->values->left_margin);
1704 g_value_set_int (value, priv->values->indent);
1707 case PROP_STRIKETHROUGH:
1708 g_value_set_boolean (value, priv->values->appearance.strikethrough);
1711 case PROP_RIGHT_MARGIN:
1712 g_value_set_int (value, priv->values->right_margin);
1715 case PROP_UNDERLINE:
1716 g_value_set_enum (value, priv->values->appearance.underline);
1720 g_value_set_int (value, priv->values->appearance.rise);
1723 case PROP_BACKGROUND_FULL_HEIGHT:
1724 g_value_set_boolean (value, priv->values->bg_full_height);
1728 g_value_set_string (value, pango_language_to_string (priv->values->language));
1732 if (priv->values->tabs)
1733 g_value_set_boxed (value, priv->values->tabs);
1736 case PROP_INVISIBLE:
1737 g_value_set_boolean (value, priv->values->invisible);
1740 case PROP_PARAGRAPH_BACKGROUND_GDK:
1741 g_value_set_boxed (value, priv->values->pg_bg_color);
1744 case PROP_PARAGRAPH_BACKGROUND_RGBA:
1745 g_value_set_boxed (value, priv->values->pg_bg_rgba);
1748 case PROP_ACCUMULATIVE_MARGIN:
1749 g_value_set_boolean (value, priv->accumulative_margin);
1752 case PROP_BACKGROUND_SET:
1753 g_value_set_boolean (value, priv->bg_color_set);
1756 case PROP_FOREGROUND_SET:
1757 g_value_set_boolean (value, priv->fg_color_set);
1760 case PROP_FAMILY_SET:
1761 case PROP_STYLE_SET:
1762 case PROP_VARIANT_SET:
1763 case PROP_WEIGHT_SET:
1764 case PROP_STRETCH_SET:
1767 PangoFontMask set_mask = priv->values->font ? pango_font_description_get_set_fields (priv->values->font) : 0;
1768 PangoFontMask test_mask = get_property_font_set_mask (prop_id);
1769 g_value_set_boolean (value, (set_mask & test_mask) != 0);
1774 case PROP_SCALE_SET:
1775 g_value_set_boolean (value, priv->scale_set);
1778 case PROP_PIXELS_ABOVE_LINES_SET:
1779 g_value_set_boolean (value, priv->pixels_above_lines_set);
1782 case PROP_PIXELS_BELOW_LINES_SET:
1783 g_value_set_boolean (value, priv->pixels_below_lines_set);
1786 case PROP_PIXELS_INSIDE_WRAP_SET:
1787 g_value_set_boolean (value, priv->pixels_inside_wrap_set);
1790 case PROP_EDITABLE_SET:
1791 g_value_set_boolean (value, priv->editable_set);
1794 case PROP_WRAP_MODE_SET:
1795 g_value_set_boolean (value, priv->wrap_mode_set);
1798 case PROP_JUSTIFICATION_SET:
1799 g_value_set_boolean (value, priv->justification_set);
1802 case PROP_LEFT_MARGIN_SET:
1803 g_value_set_boolean (value, priv->left_margin_set);
1806 case PROP_INDENT_SET:
1807 g_value_set_boolean (value, priv->indent_set);
1810 case PROP_STRIKETHROUGH_SET:
1811 g_value_set_boolean (value, priv->strikethrough_set);
1814 case PROP_RIGHT_MARGIN_SET:
1815 g_value_set_boolean (value, priv->right_margin_set);
1818 case PROP_UNDERLINE_SET:
1819 g_value_set_boolean (value, priv->underline_set);
1823 g_value_set_boolean (value, priv->rise_set);
1826 case PROP_BACKGROUND_FULL_HEIGHT_SET:
1827 g_value_set_boolean (value, priv->bg_full_height_set);
1830 case PROP_LANGUAGE_SET:
1831 g_value_set_boolean (value, priv->language_set);
1835 g_value_set_boolean (value, priv->tabs_set);
1838 case PROP_INVISIBLE_SET:
1839 g_value_set_boolean (value, priv->invisible_set);
1842 case PROP_PARAGRAPH_BACKGROUND_SET:
1843 g_value_set_boolean (value, priv->pg_bg_color_set);
1846 case PROP_BACKGROUND:
1847 case PROP_FOREGROUND:
1848 case PROP_PARAGRAPH_BACKGROUND:
1849 g_warning ("'foreground', 'background' and 'paragraph_background' properties are not readable, use 'foreground_gdk', 'background_gdk' and 'paragraph_background_gdk'");
1852 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1868 delta_priority_foreach (GtkTextTag *tag, gpointer user_data)
1870 GtkTextTagPrivate *priv = tag->priv;
1871 DeltaData *dd = user_data;
1873 if (priv->priority >= dd->low && priv->priority <= dd->high)
1874 priv->priority += dd->delta;
1878 * gtk_text_tag_get_priority:
1879 * @tag: a #GtkTextTag
1881 * Get the tag priority.
1883 * Return value: The tag's priority.
1886 gtk_text_tag_get_priority (GtkTextTag *tag)
1888 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), 0);
1890 return tag->priv->priority;
1894 * gtk_text_tag_set_priority:
1895 * @tag: a #GtkTextTag
1896 * @priority: the new priority
1898 * Sets the priority of a #GtkTextTag. Valid priorities are
1899 * start at 0 and go to one less than gtk_text_tag_table_get_size().
1900 * Each tag in a table has a unique priority; setting the priority
1901 * of one tag shifts the priorities of all the other tags in the
1902 * table to maintain a unique priority for each tag. Higher priority
1903 * tags "win" if two tags both set the same text attribute. When adding
1904 * a tag to a tag table, it will be assigned the highest priority in
1905 * the table by default; so normally the precedence of a set of tags
1906 * is the order in which they were added to the table, or created with
1907 * gtk_text_buffer_create_tag(), which adds the tag to the buffer's table
1911 gtk_text_tag_set_priority (GtkTextTag *tag,
1914 GtkTextTagPrivate *priv;
1917 g_return_if_fail (GTK_IS_TEXT_TAG (tag));
1921 g_return_if_fail (priv->table != NULL);
1922 g_return_if_fail (priority >= 0);
1923 g_return_if_fail (priority < gtk_text_tag_table_get_size (priv->table));
1925 if (priority == priv->priority)
1928 if (priority < priv->priority)
1931 dd.high = priv->priority - 1;
1936 dd.low = priv->priority + 1;
1941 gtk_text_tag_table_foreach (priv->table,
1942 delta_priority_foreach,
1945 priv->priority = priority;
1949 * gtk_text_tag_event:
1950 * @tag: a #GtkTextTag
1951 * @event_object: object that received the event, such as a widget
1953 * @iter: location where the event was received
1955 * Emits the "event" signal on the #GtkTextTag.
1957 * Return value: result of signal emission (whether the event was handled)
1960 gtk_text_tag_event (GtkTextTag *tag,
1961 GObject *event_object,
1963 const GtkTextIter *iter)
1965 gboolean retval = FALSE;
1967 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
1968 g_return_val_if_fail (G_IS_OBJECT (event_object), FALSE);
1969 g_return_val_if_fail (event != NULL, FALSE);
1983 tag_sort_func (gconstpointer first, gconstpointer second)
1985 GtkTextTag *tag1, *tag2;
1987 tag1 = * (GtkTextTag **) first;
1988 tag2 = * (GtkTextTag **) second;
1989 return tag1->priv->priority - tag2->priv->priority;
1993 _gtk_text_tag_array_sort (GtkTextTag** tag_array_p,
1998 GtkTextTag **maxPtrPtr, *tmp;
2000 g_return_if_fail (tag_array_p != NULL);
2001 g_return_if_fail (len > 0);
2007 GtkTextTag **iter = tag_array_p;
2009 for (i = len-1; i > 0; i--, iter++) {
2010 maxPtrPtr = tag = iter;
2011 prio = tag[0]->priv->priority;
2012 for (j = i, tag++; j > 0; j--, tag++) {
2013 if (tag[0]->priv->priority < prio) {
2014 prio = tag[0]->priv->priority;
2023 qsort ((void *) tag_array_p, (unsigned) len, sizeof (GtkTextTag *),
2029 printf ("Sorted tag array: \n");
2033 GtkTextTag *t = tag_array_p[i];
2034 printf (" %s priority %d\n", t->name, t->priority);