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));
204 * GtkTextTag:background-gdk:
206 * Background color as a #GdkColor.
208 * Deprecated: 3.4: Use #GtkTextTag:background-rgba instead.
210 g_object_class_install_property (object_class,
212 g_param_spec_boxed ("background-gdk",
213 P_("Background color"),
214 P_("Background color as a GdkColor"),
216 GTK_PARAM_READWRITE | G_PARAM_DEPRECATED));
219 * GtkTextTag:background-rgba:
221 * Background color as a #GdkRGBA.
225 g_object_class_install_property (object_class,
226 PROP_BACKGROUND_RGBA,
227 g_param_spec_boxed ("background-rgba",
228 P_("Background RGBA"),
229 P_("Background color as a GdkRGBA"),
231 GTK_PARAM_READWRITE));
233 g_object_class_install_property (object_class,
234 PROP_BACKGROUND_FULL_HEIGHT,
235 g_param_spec_boolean ("background-full-height",
236 P_("Background full height"),
237 P_("Whether the background color fills the entire line height or only the height of the tagged characters"),
239 GTK_PARAM_READWRITE));
241 g_object_class_install_property (object_class,
243 g_param_spec_string ("foreground",
244 P_("Foreground color name"),
245 P_("Foreground color as a string"),
247 GTK_PARAM_WRITABLE));
250 * GtkTextTag:foreground-gdk:
252 * Foreground color as a #GdkColor.
254 * Deprecated: 3.4: Use #GtkTextTag:foreground-rgba instead.
256 g_object_class_install_property (object_class,
258 g_param_spec_boxed ("foreground-gdk",
259 P_("Foreground color"),
260 P_("Foreground color as a GdkColor"),
262 GTK_PARAM_READWRITE | G_PARAM_DEPRECATED));
265 * GtkTextTag:foreground-rgba:
267 * Foreground color as a #GdkRGBA.
271 g_object_class_install_property (object_class,
272 PROP_FOREGROUND_RGBA,
273 g_param_spec_boxed ("foreground-rgba",
274 P_("Foreground RGBA"),
275 P_("Foreground color as a GdkRGBA"),
277 GTK_PARAM_READWRITE));
279 g_object_class_install_property (object_class,
281 g_param_spec_enum ("direction",
282 P_("Text direction"),
283 P_("Text direction, e.g. right-to-left or left-to-right"),
284 GTK_TYPE_TEXT_DIRECTION,
286 GTK_PARAM_READWRITE));
288 g_object_class_install_property (object_class,
290 g_param_spec_boolean ("editable",
292 P_("Whether the text can be modified by the user"),
294 GTK_PARAM_READWRITE));
299 * Font description as string, e.g. \"Sans Italic 12\".
301 * Note that the initial value of this property depends on
302 * the internals of #PangoFontDescription.
304 g_object_class_install_property (object_class,
306 g_param_spec_string ("font",
308 P_("Font description as a string, e.g. \"Sans Italic 12\""),
310 GTK_PARAM_READWRITE));
312 g_object_class_install_property (object_class,
314 g_param_spec_boxed ("font-desc",
316 P_("Font description as a PangoFontDescription struct"),
317 PANGO_TYPE_FONT_DESCRIPTION,
318 GTK_PARAM_READWRITE));
320 g_object_class_install_property (object_class,
322 g_param_spec_string ("family",
324 P_("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
326 GTK_PARAM_READWRITE));
328 g_object_class_install_property (object_class,
330 g_param_spec_enum ("style",
332 P_("Font style as a PangoStyle, e.g. PANGO_STYLE_ITALIC"),
335 GTK_PARAM_READWRITE));
337 g_object_class_install_property (object_class,
339 g_param_spec_enum ("variant",
341 P_("Font variant as a PangoVariant, e.g. PANGO_VARIANT_SMALL_CAPS"),
343 PANGO_VARIANT_NORMAL,
344 GTK_PARAM_READWRITE));
346 g_object_class_install_property (object_class,
348 g_param_spec_int ("weight",
350 P_("Font weight as an integer, see predefined values in PangoWeight; for example, PANGO_WEIGHT_BOLD"),
354 GTK_PARAM_READWRITE));
357 g_object_class_install_property (object_class,
359 g_param_spec_enum ("stretch",
361 P_("Font stretch as a PangoStretch, e.g. PANGO_STRETCH_CONDENSED"),
363 PANGO_STRETCH_NORMAL,
364 GTK_PARAM_READWRITE));
366 g_object_class_install_property (object_class,
368 g_param_spec_int ("size",
370 P_("Font size in Pango units"),
374 GTK_PARAM_READWRITE));
376 g_object_class_install_property (object_class,
378 g_param_spec_double ("scale",
380 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"),
384 GTK_PARAM_READWRITE));
386 g_object_class_install_property (object_class,
388 g_param_spec_double ("size-points",
390 P_("Font size in points"),
394 GTK_PARAM_READWRITE));
396 g_object_class_install_property (object_class,
398 g_param_spec_enum ("justification",
400 P_("Left, right, or center justification"),
401 GTK_TYPE_JUSTIFICATION,
403 GTK_PARAM_READWRITE));
406 * GtkTextTag:language:
408 * The language this text is in, as an ISO code. Pango can use this as a
409 * hint when rendering the text. If not set, an appropriate default will be
412 * Note that the initial value of this property depends on the current
413 * locale, see also gtk_get_default_language().
415 g_object_class_install_property (object_class,
417 g_param_spec_string ("language",
419 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."),
421 GTK_PARAM_READWRITE));
423 g_object_class_install_property (object_class,
425 g_param_spec_int ("left-margin",
427 P_("Width of the left margin in pixels"),
431 GTK_PARAM_READWRITE));
433 g_object_class_install_property (object_class,
435 g_param_spec_int ("right-margin",
437 P_("Width of the right margin in pixels"),
441 GTK_PARAM_READWRITE));
444 g_object_class_install_property (object_class,
446 g_param_spec_int ("indent",
448 P_("Amount to indent the paragraph, in pixels"),
452 GTK_PARAM_READWRITE));
455 g_object_class_install_property (object_class,
457 g_param_spec_int ("rise",
459 P_("Offset of text above the baseline (below the baseline if rise is negative) in Pango units"),
463 GTK_PARAM_READWRITE));
465 g_object_class_install_property (object_class,
466 PROP_PIXELS_ABOVE_LINES,
467 g_param_spec_int ("pixels-above-lines",
468 P_("Pixels above lines"),
469 P_("Pixels of blank space above paragraphs"),
473 GTK_PARAM_READWRITE));
475 g_object_class_install_property (object_class,
476 PROP_PIXELS_BELOW_LINES,
477 g_param_spec_int ("pixels-below-lines",
478 P_("Pixels below lines"),
479 P_("Pixels of blank space below paragraphs"),
483 GTK_PARAM_READWRITE));
485 g_object_class_install_property (object_class,
486 PROP_PIXELS_INSIDE_WRAP,
487 g_param_spec_int ("pixels-inside-wrap",
488 P_("Pixels inside wrap"),
489 P_("Pixels of blank space between wrapped lines in a paragraph"),
493 GTK_PARAM_READWRITE));
495 g_object_class_install_property (object_class,
497 g_param_spec_boolean ("strikethrough",
499 P_("Whether to strike through the text"),
501 GTK_PARAM_READWRITE));
503 g_object_class_install_property (object_class,
505 g_param_spec_enum ("underline",
507 P_("Style of underline for this text"),
508 PANGO_TYPE_UNDERLINE,
509 PANGO_UNDERLINE_NONE,
510 GTK_PARAM_READWRITE));
512 g_object_class_install_property (object_class,
514 g_param_spec_enum ("wrap-mode",
516 P_("Whether to wrap lines never, at word boundaries, or at character boundaries"),
519 GTK_PARAM_READWRITE));
522 g_object_class_install_property (object_class,
524 g_param_spec_boxed ("tabs",
526 P_("Custom tabs for this text"),
527 PANGO_TYPE_TAB_ARRAY,
528 GTK_PARAM_READWRITE));
531 * GtkTextTag:invisible:
533 * Whether this text is hidden.
535 * Note that there may still be problems with the support for invisible
536 * text, in particular when navigating programmatically inside a buffer
537 * containing invisible segments.
541 g_object_class_install_property (object_class,
543 g_param_spec_boolean ("invisible",
545 P_("Whether this text is hidden."),
547 GTK_PARAM_READWRITE));
550 * GtkTextTag:paragraph-background:
552 * The paragraph background color as a string.
556 g_object_class_install_property (object_class,
557 PROP_PARAGRAPH_BACKGROUND,
558 g_param_spec_string ("paragraph-background",
559 P_("Paragraph background color name"),
560 P_("Paragraph background color as a string"),
562 GTK_PARAM_WRITABLE));
565 * GtkTextTag:paragraph-background-gdk:
567 * The paragraph background color as a as a #GdkColor.
571 * Deprecated: 3.4: Use #GtkTextTag:paragraph-background-rgba instead.
573 g_object_class_install_property (object_class,
574 PROP_PARAGRAPH_BACKGROUND_GDK,
575 g_param_spec_boxed ("paragraph-background-gdk",
576 P_("Paragraph background color"),
577 P_("Paragraph background color as a GdkColor"),
579 GTK_PARAM_READWRITE | G_PARAM_DEPRECATED));
582 * GtkTextTag:paragraph-background-rgba:
584 * The paragraph background color as a as a #GdkRGBA.
588 g_object_class_install_property (object_class,
589 PROP_PARAGRAPH_BACKGROUND_RGBA,
590 g_param_spec_boxed ("paragraph-background-rgba",
591 P_("Paragraph background RGBA"),
592 P_("Paragraph background RGBA as a GdkRGBA"),
594 GTK_PARAM_READWRITE));
597 * GtkTextTag:accumulative-margin:
599 * Whether the margins accumulate or override each other.
601 * When set to %TRUE the margins of this tag are added to the margins
602 * of any other non-accumulative margins present. When set to %FALSE
603 * the margins override one another (the default).
607 g_object_class_install_property (object_class,
608 PROP_ACCUMULATIVE_MARGIN,
609 g_param_spec_boolean ("accumulative-margin",
610 P_("Margin Accumulates"),
611 P_("Whether left and right margins accumulate."),
613 GTK_PARAM_READWRITE));
615 /* Style props are set or not */
617 #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))
619 ADD_SET_PROP ("background-set", PROP_BACKGROUND_SET,
620 P_("Background set"),
621 P_("Whether this tag affects the background color"));
623 ADD_SET_PROP ("background-full-height-set", PROP_BACKGROUND_FULL_HEIGHT_SET,
624 P_("Background full height set"),
625 P_("Whether this tag affects background height"));
627 ADD_SET_PROP ("foreground-set", PROP_FOREGROUND_SET,
628 P_("Foreground set"),
629 P_("Whether this tag affects the foreground color"));
631 ADD_SET_PROP ("editable-set", PROP_EDITABLE_SET,
632 P_("Editability set"),
633 P_("Whether this tag affects text editability"));
635 ADD_SET_PROP ("family-set", PROP_FAMILY_SET,
636 P_("Font family set"),
637 P_("Whether this tag affects the font family"));
639 ADD_SET_PROP ("style-set", PROP_STYLE_SET,
640 P_("Font style set"),
641 P_("Whether this tag affects the font style"));
643 ADD_SET_PROP ("variant-set", PROP_VARIANT_SET,
644 P_("Font variant set"),
645 P_("Whether this tag affects the font variant"));
647 ADD_SET_PROP ("weight-set", PROP_WEIGHT_SET,
648 P_("Font weight set"),
649 P_("Whether this tag affects the font weight"));
651 ADD_SET_PROP ("stretch-set", PROP_STRETCH_SET,
652 P_("Font stretch set"),
653 P_("Whether this tag affects the font stretch"));
655 ADD_SET_PROP ("size-set", PROP_SIZE_SET,
657 P_("Whether this tag affects the font size"));
659 ADD_SET_PROP ("scale-set", PROP_SCALE_SET,
660 P_("Font scale set"),
661 P_("Whether this tag scales the font size by a factor"));
663 ADD_SET_PROP ("justification-set", PROP_JUSTIFICATION_SET,
664 P_("Justification set"),
665 P_("Whether this tag affects paragraph justification"));
667 ADD_SET_PROP ("language-set", PROP_LANGUAGE_SET,
669 P_("Whether this tag affects the language the text is rendered as"));
671 ADD_SET_PROP ("left-margin-set", PROP_LEFT_MARGIN_SET,
672 P_("Left margin set"),
673 P_("Whether this tag affects the left margin"));
675 ADD_SET_PROP ("indent-set", PROP_INDENT_SET,
677 P_("Whether this tag affects indentation"));
679 ADD_SET_PROP ("rise-set", PROP_RISE_SET,
681 P_("Whether this tag affects the rise"));
683 ADD_SET_PROP ("pixels-above-lines-set", PROP_PIXELS_ABOVE_LINES_SET,
684 P_("Pixels above lines set"),
685 P_("Whether this tag affects the number of pixels above lines"));
687 ADD_SET_PROP ("pixels-below-lines-set", PROP_PIXELS_BELOW_LINES_SET,
688 P_("Pixels below lines set"),
689 P_("Whether this tag affects the number of pixels above lines"));
691 ADD_SET_PROP ("pixels-inside-wrap-set", PROP_PIXELS_INSIDE_WRAP_SET,
692 P_("Pixels inside wrap set"),
693 P_("Whether this tag affects the number of pixels between wrapped lines"));
695 ADD_SET_PROP ("strikethrough-set", PROP_STRIKETHROUGH_SET,
696 P_("Strikethrough set"),
697 P_("Whether this tag affects strikethrough"));
699 ADD_SET_PROP ("right-margin-set", PROP_RIGHT_MARGIN_SET,
700 P_("Right margin set"),
701 P_("Whether this tag affects the right margin"));
703 ADD_SET_PROP ("underline-set", PROP_UNDERLINE_SET,
705 P_("Whether this tag affects underlining"));
707 ADD_SET_PROP ("wrap-mode-set", PROP_WRAP_MODE_SET,
709 P_("Whether this tag affects line wrap mode"));
711 ADD_SET_PROP ("tabs-set", PROP_TABS_SET,
713 P_("Whether this tag affects tabs"));
715 ADD_SET_PROP ("invisible-set", PROP_INVISIBLE_SET,
717 P_("Whether this tag affects text visibility"));
719 ADD_SET_PROP ("paragraph-background-set", PROP_PARAGRAPH_BACKGROUND_SET,
720 P_("Paragraph background set"),
721 P_("Whether this tag affects the paragraph background color"));
725 * @tag: the #GtkTextTag on which the signal is emitted
726 * @object: the object the event was fired from (typically a #GtkTextView)
727 * @event: the event which triggered the signal
728 * @iter: a #GtkTextIter pointing at the location the event occured
730 * The ::event signal is emitted when an event occurs on a region of the
731 * buffer marked with this tag.
733 * Returns: %TRUE to stop other handlers from being invoked for the
734 * event. %FALSE to propagate the event further.
737 g_signal_new (I_("event"),
738 G_OBJECT_CLASS_TYPE (object_class),
740 G_STRUCT_OFFSET (GtkTextTagClass, event),
741 _gtk_boolean_handled_accumulator, NULL,
742 _gtk_marshal_BOOLEAN__OBJECT_BOXED_BOXED,
746 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE,
749 g_type_class_add_private (klass, sizeof (GtkTextTagPrivate));
753 gtk_text_tag_init (GtkTextTag *text_tag)
755 GtkTextTagPrivate *priv;
757 text_tag->priv = G_TYPE_INSTANCE_GET_PRIVATE (text_tag,
760 priv = text_tag->priv;
762 priv->values = gtk_text_attributes_new ();
767 * @name: (allow-none): tag name, or %NULL
769 * Creates a #GtkTextTag. Configure the tag using object arguments,
770 * i.e. using g_object_set().
772 * Return value: a new #GtkTextTag
775 gtk_text_tag_new (const gchar *name)
779 tag = g_object_new (GTK_TYPE_TEXT_TAG, "name", name, NULL);
785 gtk_text_tag_finalize (GObject *object)
787 GtkTextTag *text_tag = GTK_TEXT_TAG (object);
788 GtkTextTagPrivate *priv = text_tag->priv;
791 gtk_text_tag_table_remove (priv->table, text_tag);
793 g_assert (priv->table == NULL);
795 gtk_text_attributes_unref (priv->values);
801 G_OBJECT_CLASS (gtk_text_tag_parent_class)->finalize (object);
805 copy_rgba_to_gdk_color (GdkRGBA *src,
808 dest->red = CLAMP (src->red, 0.0, 1.0) * 65535.0;
809 dest->green = CLAMP (src->green, 0.0, 1.0) * 65535.0;
810 dest->blue = CLAMP (src->blue, 0.0, 1.0) * 65535.0;
814 copy_gdk_color_to_rgba (GdkColor *src,
817 dest->red = src->red / 65535.;
818 dest->green = src->green / 65535.;
819 dest->blue = src->blue / 65535.;
824 set_bg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
826 GtkTextTagPrivate *priv = tag->priv;
828 if (priv->values->appearance.rgba[0])
829 gdk_rgba_free (priv->values->appearance.rgba[0]);
831 priv->values->appearance.rgba[0] = NULL;
835 if (!priv->bg_color_set)
837 priv->bg_color_set = TRUE;
838 g_object_notify (G_OBJECT (tag), "background-set");
841 priv->values->appearance.rgba[0] = gdk_rgba_copy (rgba);
843 copy_rgba_to_gdk_color (rgba, &priv->values->appearance.bg_color);
847 if (priv->bg_color_set)
849 priv->bg_color_set = FALSE;
850 g_object_notify (G_OBJECT (tag), "background-set");
856 set_fg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
858 GtkTextTagPrivate *priv = tag->priv;
860 if (priv->values->appearance.rgba[1])
861 gdk_rgba_free (priv->values->appearance.rgba[1]);
863 priv->values->appearance.rgba[1] = NULL;
867 if (!priv->fg_color_set)
869 priv->fg_color_set = TRUE;
870 g_object_notify (G_OBJECT (tag), "foreground-set");
873 priv->values->appearance.rgba[1] = gdk_rgba_copy (rgba);
875 copy_rgba_to_gdk_color (rgba, &priv->values->appearance.fg_color);
879 if (priv->fg_color_set)
881 priv->fg_color_set = FALSE;
882 g_object_notify (G_OBJECT (tag), "foreground-set");
888 set_pg_bg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
890 GtkTextTagPrivate *priv = tag->priv;
892 if (priv->values->pg_bg_rgba)
893 gdk_rgba_free (priv->values->pg_bg_rgba);
895 if (priv->values->pg_bg_color)
896 gdk_color_free (priv->values->pg_bg_color);
898 priv->values->pg_bg_rgba = NULL;
899 priv->values->pg_bg_color = NULL;
903 GdkColor color = { 0, };
905 if (!priv->pg_bg_color_set)
907 priv->pg_bg_color_set = TRUE;
908 g_object_notify (G_OBJECT (tag), "paragraph-background-set");
911 priv->values->pg_bg_rgba = gdk_rgba_copy (rgba);
913 copy_rgba_to_gdk_color (rgba, &color);
914 priv->values->pg_bg_color = gdk_color_copy (&color);
918 if (priv->pg_bg_color_set)
920 priv->pg_bg_color_set = FALSE;
921 g_object_notify (G_OBJECT (tag), "paragraph-background-set");
928 set_bg_color (GtkTextTag *tag, GdkColor *color)
934 copy_gdk_color_to_rgba (color, &rgba);
935 set_bg_rgba (tag, &rgba);
938 set_bg_rgba (tag, NULL);
942 set_fg_color (GtkTextTag *tag, GdkColor *color)
948 copy_gdk_color_to_rgba (color, &rgba);
949 set_fg_rgba (tag, &rgba);
952 set_fg_rgba (tag, NULL);
956 set_pg_bg_color (GtkTextTag *tag, GdkColor *color)
962 copy_gdk_color_to_rgba (color, &rgba);
963 set_pg_bg_rgba (tag, &rgba);
966 set_pg_bg_rgba (tag, NULL);
970 get_property_font_set_mask (guint prop_id)
974 case PROP_FAMILY_SET:
975 return PANGO_FONT_MASK_FAMILY;
977 return PANGO_FONT_MASK_STYLE;
978 case PROP_VARIANT_SET:
979 return PANGO_FONT_MASK_VARIANT;
980 case PROP_WEIGHT_SET:
981 return PANGO_FONT_MASK_WEIGHT;
982 case PROP_STRETCH_SET:
983 return PANGO_FONT_MASK_STRETCH;
985 return PANGO_FONT_MASK_SIZE;
992 set_font_desc_fields (PangoFontDescription *desc,
993 PangoFontMask to_set)
995 PangoFontMask changed_mask = 0;
997 if (to_set & PANGO_FONT_MASK_FAMILY)
999 const char *family = pango_font_description_get_family (desc);
1003 changed_mask |= PANGO_FONT_MASK_FAMILY;
1006 pango_font_description_set_family (desc, family);
1008 if (to_set & PANGO_FONT_MASK_STYLE)
1009 pango_font_description_set_style (desc, pango_font_description_get_style (desc));
1010 if (to_set & PANGO_FONT_MASK_VARIANT)
1011 pango_font_description_set_variant (desc, pango_font_description_get_variant (desc));
1012 if (to_set & PANGO_FONT_MASK_WEIGHT)
1013 pango_font_description_set_weight (desc, pango_font_description_get_weight (desc));
1014 if (to_set & PANGO_FONT_MASK_STRETCH)
1015 pango_font_description_set_stretch (desc, pango_font_description_get_stretch (desc));
1016 if (to_set & PANGO_FONT_MASK_SIZE)
1018 gint size = pango_font_description_get_size (desc);
1021 size = 10 * PANGO_SCALE;
1022 changed_mask |= PANGO_FONT_MASK_SIZE;
1025 pango_font_description_set_size (desc, size);
1028 return changed_mask;
1032 notify_set_changed (GObject *object,
1033 PangoFontMask changed_mask)
1035 if (changed_mask & PANGO_FONT_MASK_FAMILY)
1036 g_object_notify (object, "family-set");
1037 if (changed_mask & PANGO_FONT_MASK_STYLE)
1038 g_object_notify (object, "style-set");
1039 if (changed_mask & PANGO_FONT_MASK_VARIANT)
1040 g_object_notify (object, "variant-set");
1041 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
1042 g_object_notify (object, "weight-set");
1043 if (changed_mask & PANGO_FONT_MASK_STRETCH)
1044 g_object_notify (object, "stretch-set");
1045 if (changed_mask & PANGO_FONT_MASK_SIZE)
1046 g_object_notify (object, "size-set");
1050 notify_fields_changed (GObject *object,
1051 PangoFontMask changed_mask)
1053 if (changed_mask & PANGO_FONT_MASK_FAMILY)
1054 g_object_notify (object, "family");
1055 if (changed_mask & PANGO_FONT_MASK_STYLE)
1056 g_object_notify (object, "style");
1057 if (changed_mask & PANGO_FONT_MASK_VARIANT)
1058 g_object_notify (object, "variant");
1059 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
1060 g_object_notify (object, "weight");
1061 if (changed_mask & PANGO_FONT_MASK_STRETCH)
1062 g_object_notify (object, "stretch");
1063 if (changed_mask & PANGO_FONT_MASK_SIZE)
1064 g_object_notify (object, "size");
1068 set_font_description (GtkTextTag *text_tag,
1069 PangoFontDescription *font_desc)
1071 GtkTextTagPrivate *priv = text_tag->priv;
1072 GObject *object = G_OBJECT (text_tag);
1073 PangoFontDescription *new_font_desc;
1074 PangoFontMask old_mask, new_mask, changed_mask, set_changed_mask;
1077 new_font_desc = pango_font_description_copy (font_desc);
1079 new_font_desc = pango_font_description_new ();
1081 if (priv->values->font)
1082 old_mask = pango_font_description_get_set_fields (priv->values->font);
1086 new_mask = pango_font_description_get_set_fields (new_font_desc);
1088 changed_mask = old_mask | new_mask;
1089 set_changed_mask = old_mask ^ new_mask;
1091 if (priv->values->font)
1092 pango_font_description_free (priv->values->font);
1093 priv->values->font = new_font_desc;
1095 g_object_freeze_notify (object);
1097 g_object_notify (object, "font-desc");
1098 g_object_notify (object, "font");
1100 if (changed_mask & PANGO_FONT_MASK_FAMILY)
1101 g_object_notify (object, "family");
1102 if (changed_mask & PANGO_FONT_MASK_STYLE)
1103 g_object_notify (object, "style");
1104 if (changed_mask & PANGO_FONT_MASK_VARIANT)
1105 g_object_notify (object, "variant");
1106 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
1107 g_object_notify (object, "weight");
1108 if (changed_mask & PANGO_FONT_MASK_STRETCH)
1109 g_object_notify (object, "stretch");
1110 if (changed_mask & PANGO_FONT_MASK_SIZE)
1112 g_object_notify (object, "size");
1113 g_object_notify (object, "size-points");
1116 notify_set_changed (object, set_changed_mask);
1118 g_object_thaw_notify (object);
1122 gtk_text_tag_ensure_font (GtkTextTag *text_tag)
1124 GtkTextTagPrivate *priv = text_tag->priv;
1126 if (!priv->values->font)
1127 priv->values->font = pango_font_description_new ();
1131 gtk_text_tag_set_property (GObject *object,
1133 const GValue *value,
1136 GtkTextTag *text_tag = GTK_TEXT_TAG (object);
1137 GtkTextTagPrivate *priv = text_tag->priv;
1138 gboolean size_changed = FALSE;
1143 g_return_if_fail (priv->name == NULL);
1144 priv->name = g_value_dup_string (value);
1147 case PROP_BACKGROUND:
1151 if (!g_value_get_string (value))
1152 set_bg_rgba (text_tag, NULL); /* reset background_set to FALSE */
1153 else if (gdk_rgba_parse (&rgba, g_value_get_string (value)))
1154 set_bg_rgba (text_tag, &rgba);
1156 g_warning ("Don't know color `%s'", g_value_get_string (value));
1158 g_object_notify (object, "background-gdk");
1162 case PROP_FOREGROUND:
1166 if (!g_value_get_string (value))
1167 set_fg_rgba (text_tag, NULL); /* reset to foreground_set to FALSE */
1168 else if (gdk_rgba_parse (&rgba, g_value_get_string (value)))
1169 set_fg_rgba (text_tag, &rgba);
1171 g_warning ("Don't know color `%s'", g_value_get_string (value));
1173 g_object_notify (object, "foreground-gdk");
1177 case PROP_BACKGROUND_GDK:
1179 GdkColor *color = g_value_get_boxed (value);
1181 set_bg_color (text_tag, color);
1185 case PROP_FOREGROUND_GDK:
1187 GdkColor *color = g_value_get_boxed (value);
1189 set_fg_color (text_tag, color);
1193 case PROP_BACKGROUND_RGBA:
1195 GdkRGBA *color = g_value_get_boxed (value);
1197 set_bg_rgba (text_tag, color);
1201 case PROP_FOREGROUND_RGBA:
1203 GdkRGBA *color = g_value_get_boxed (value);
1205 set_fg_rgba (text_tag, color);
1211 PangoFontDescription *font_desc = NULL;
1214 name = g_value_get_string (value);
1217 font_desc = pango_font_description_from_string (name);
1219 set_font_description (text_tag, font_desc);
1221 pango_font_description_free (font_desc);
1223 size_changed = TRUE;
1227 case PROP_FONT_DESC:
1229 PangoFontDescription *font_desc;
1231 font_desc = g_value_get_boxed (value);
1233 set_font_description (text_tag, font_desc);
1235 size_changed = TRUE;
1245 case PROP_SIZE_POINTS:
1247 PangoFontMask old_set_mask;
1249 gtk_text_tag_ensure_font (text_tag);
1250 old_set_mask = pango_font_description_get_set_fields (priv->values->font);
1255 pango_font_description_set_family (priv->values->font,
1256 g_value_get_string (value));
1259 pango_font_description_set_style (priv->values->font,
1260 g_value_get_enum (value));
1263 pango_font_description_set_variant (priv->values->font,
1264 g_value_get_enum (value));
1267 pango_font_description_set_weight (priv->values->font,
1268 g_value_get_int (value));
1271 pango_font_description_set_stretch (priv->values->font,
1272 g_value_get_enum (value));
1275 pango_font_description_set_size (priv->values->font,
1276 g_value_get_int (value));
1277 g_object_notify (object, "size-points");
1279 case PROP_SIZE_POINTS:
1280 pango_font_description_set_size (priv->values->font,
1281 g_value_get_double (value) * PANGO_SCALE);
1282 g_object_notify (object, "size");
1286 size_changed = TRUE;
1287 notify_set_changed (object, old_set_mask & pango_font_description_get_set_fields (priv->values->font));
1288 g_object_notify (object, "font-desc");
1289 g_object_notify (object, "font");
1295 priv->values->font_scale = g_value_get_double (value);
1296 priv->scale_set = TRUE;
1297 g_object_notify (object, "scale-set");
1298 size_changed = TRUE;
1301 case PROP_PIXELS_ABOVE_LINES:
1302 priv->pixels_above_lines_set = TRUE;
1303 priv->values->pixels_above_lines = g_value_get_int (value);
1304 g_object_notify (object, "pixels-above-lines-set");
1305 size_changed = TRUE;
1308 case PROP_PIXELS_BELOW_LINES:
1309 priv->pixels_below_lines_set = TRUE;
1310 priv->values->pixels_below_lines = g_value_get_int (value);
1311 g_object_notify (object, "pixels-below-lines-set");
1312 size_changed = TRUE;
1315 case PROP_PIXELS_INSIDE_WRAP:
1316 priv->pixels_inside_wrap_set = TRUE;
1317 priv->values->pixels_inside_wrap = g_value_get_int (value);
1318 g_object_notify (object, "pixels-inside-wrap-set");
1319 size_changed = TRUE;
1323 priv->editable_set = TRUE;
1324 priv->values->editable = g_value_get_boolean (value);
1325 g_object_notify (object, "editable-set");
1328 case PROP_WRAP_MODE:
1329 priv->wrap_mode_set = TRUE;
1330 priv->values->wrap_mode = g_value_get_enum (value);
1331 g_object_notify (object, "wrap-mode-set");
1332 size_changed = TRUE;
1335 case PROP_JUSTIFICATION:
1336 priv->justification_set = TRUE;
1337 priv->values->justification = g_value_get_enum (value);
1338 g_object_notify (object, "justification-set");
1339 size_changed = TRUE;
1342 case PROP_DIRECTION:
1343 priv->values->direction = g_value_get_enum (value);
1346 case PROP_LEFT_MARGIN:
1347 priv->left_margin_set = TRUE;
1348 priv->values->left_margin = g_value_get_int (value);
1349 g_object_notify (object, "left-margin-set");
1350 size_changed = TRUE;
1354 priv->indent_set = TRUE;
1355 priv->values->indent = g_value_get_int (value);
1356 g_object_notify (object, "indent-set");
1357 size_changed = TRUE;
1360 case PROP_STRIKETHROUGH:
1361 priv->strikethrough_set = TRUE;
1362 priv->values->appearance.strikethrough = g_value_get_boolean (value);
1363 g_object_notify (object, "strikethrough-set");
1366 case PROP_RIGHT_MARGIN:
1367 priv->right_margin_set = TRUE;
1368 priv->values->right_margin = g_value_get_int (value);
1369 g_object_notify (object, "right-margin-set");
1370 size_changed = TRUE;
1373 case PROP_UNDERLINE:
1374 priv->underline_set = TRUE;
1375 priv->values->appearance.underline = g_value_get_enum (value);
1376 g_object_notify (object, "underline-set");
1380 priv->rise_set = TRUE;
1381 priv->values->appearance.rise = g_value_get_int (value);
1382 g_object_notify (object, "rise-set");
1383 size_changed = TRUE;
1386 case PROP_BACKGROUND_FULL_HEIGHT:
1387 priv->bg_full_height_set = TRUE;
1388 priv->values->bg_full_height = g_value_get_boolean (value);
1389 g_object_notify (object, "background-full-height-set");
1393 priv->language_set = TRUE;
1394 priv->values->language = pango_language_from_string (g_value_get_string (value));
1395 g_object_notify (object, "language-set");
1399 priv->tabs_set = TRUE;
1401 if (priv->values->tabs)
1402 pango_tab_array_free (priv->values->tabs);
1404 /* FIXME I'm not sure if this is a memleak or not */
1405 priv->values->tabs =
1406 pango_tab_array_copy (g_value_get_boxed (value));
1408 g_object_notify (object, "tabs-set");
1410 size_changed = TRUE;
1413 case PROP_INVISIBLE:
1414 priv->invisible_set = TRUE;
1415 priv->values->invisible = g_value_get_boolean (value);
1416 g_object_notify (object, "invisible-set");
1417 size_changed = TRUE;
1420 case PROP_PARAGRAPH_BACKGROUND:
1424 if (!g_value_get_string (value))
1425 set_pg_bg_rgba (text_tag, NULL); /* reset paragraph_background_set to FALSE */
1426 else if (gdk_rgba_parse (&rgba, g_value_get_string (value)))
1427 set_pg_bg_rgba (text_tag, &rgba);
1429 g_warning ("Don't know color `%s'", g_value_get_string (value));
1431 g_object_notify (object, "paragraph-background-gdk");
1435 case PROP_PARAGRAPH_BACKGROUND_GDK:
1437 GdkColor *color = g_value_get_boxed (value);
1439 set_pg_bg_color (text_tag, color);
1443 case PROP_PARAGRAPH_BACKGROUND_RGBA:
1445 GdkRGBA *color = g_value_get_boxed (value);
1447 set_pg_bg_rgba (text_tag, color);
1451 case PROP_ACCUMULATIVE_MARGIN:
1452 priv->accumulative_margin = g_value_get_boolean (value);
1453 g_object_notify (object, "accumulative-margin");
1454 size_changed = TRUE;
1457 /* Whether the value should be used... */
1459 case PROP_BACKGROUND_SET:
1460 priv->bg_color_set = g_value_get_boolean (value);
1463 case PROP_FOREGROUND_SET:
1464 priv->fg_color_set = g_value_get_boolean (value);
1467 case PROP_FAMILY_SET:
1468 case PROP_STYLE_SET:
1469 case PROP_VARIANT_SET:
1470 case PROP_WEIGHT_SET:
1471 case PROP_STRETCH_SET:
1473 if (!g_value_get_boolean (value))
1475 if (priv->values->font)
1476 pango_font_description_unset_fields (priv->values->font,
1477 get_property_font_set_mask (prop_id));
1481 PangoFontMask changed_mask;
1483 gtk_text_tag_ensure_font (text_tag);
1484 changed_mask = set_font_desc_fields (priv->values->font,
1485 get_property_font_set_mask (prop_id));
1486 notify_fields_changed (G_OBJECT (text_tag), changed_mask);
1490 case PROP_SCALE_SET:
1491 priv->scale_set = g_value_get_boolean (value);
1492 size_changed = TRUE;
1495 case PROP_PIXELS_ABOVE_LINES_SET:
1496 priv->pixels_above_lines_set = g_value_get_boolean (value);
1497 size_changed = TRUE;
1500 case PROP_PIXELS_BELOW_LINES_SET:
1501 priv->pixels_below_lines_set = g_value_get_boolean (value);
1502 size_changed = TRUE;
1505 case PROP_PIXELS_INSIDE_WRAP_SET:
1506 priv->pixels_inside_wrap_set = g_value_get_boolean (value);
1507 size_changed = TRUE;
1510 case PROP_EDITABLE_SET:
1511 priv->editable_set = g_value_get_boolean (value);
1514 case PROP_WRAP_MODE_SET:
1515 priv->wrap_mode_set = g_value_get_boolean (value);
1516 size_changed = TRUE;
1519 case PROP_JUSTIFICATION_SET:
1520 priv->justification_set = g_value_get_boolean (value);
1521 size_changed = TRUE;
1524 case PROP_LEFT_MARGIN_SET:
1525 priv->left_margin_set = g_value_get_boolean (value);
1526 size_changed = TRUE;
1529 case PROP_INDENT_SET:
1530 priv->indent_set = g_value_get_boolean (value);
1531 size_changed = TRUE;
1534 case PROP_STRIKETHROUGH_SET:
1535 priv->strikethrough_set = g_value_get_boolean (value);
1538 case PROP_RIGHT_MARGIN_SET:
1539 priv->right_margin_set = g_value_get_boolean (value);
1540 size_changed = TRUE;
1543 case PROP_UNDERLINE_SET:
1544 priv->underline_set = g_value_get_boolean (value);
1548 priv->rise_set = g_value_get_boolean (value);
1549 size_changed = TRUE;
1552 case PROP_BACKGROUND_FULL_HEIGHT_SET:
1553 priv->bg_full_height_set = g_value_get_boolean (value);
1556 case PROP_LANGUAGE_SET:
1557 priv->language_set = g_value_get_boolean (value);
1558 size_changed = TRUE;
1562 priv->tabs_set = g_value_get_boolean (value);
1563 size_changed = TRUE;
1566 case PROP_INVISIBLE_SET:
1567 priv->invisible_set = g_value_get_boolean (value);
1568 size_changed = TRUE;
1571 case PROP_PARAGRAPH_BACKGROUND_SET:
1572 priv->pg_bg_color_set = g_value_get_boolean (value);
1576 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1580 /* FIXME I would like to do this after all set_property in a single
1581 * g_object_set () have been called. But an idle function won't
1582 * work; we need to emit when the tag is changed, not when we get
1583 * around to the event loop. So blah, we eat some inefficiency.
1586 /* This is also somewhat weird since we emit another object's
1587 * signal here, but the two objects are already tightly bound.
1591 g_signal_emit_by_name (priv->table,
1593 text_tag, size_changed);
1597 gtk_text_tag_get_property (GObject *object,
1602 GtkTextTag *tag = GTK_TEXT_TAG (object);
1603 GtkTextTagPrivate *priv = tag->priv;
1608 g_value_set_string (value, priv->name);
1611 case PROP_BACKGROUND_GDK:
1612 g_value_set_boxed (value, &priv->values->appearance.bg_color);
1615 case PROP_BACKGROUND_RGBA:
1616 g_value_set_boxed (value, priv->values->appearance.rgba[0]);
1619 case PROP_FOREGROUND_GDK:
1620 g_value_set_boxed (value, &priv->values->appearance.fg_color);
1623 case PROP_FOREGROUND_RGBA:
1624 g_value_set_boxed (value, priv->values->appearance.rgba[1]);
1631 gtk_text_tag_ensure_font (tag);
1633 str = pango_font_description_to_string (priv->values->font);
1634 g_value_take_string (value, str);
1638 case PROP_FONT_DESC:
1639 gtk_text_tag_ensure_font (tag);
1640 g_value_set_boxed (value, priv->values->font);
1649 case PROP_SIZE_POINTS:
1650 gtk_text_tag_ensure_font (tag);
1654 g_value_set_string (value, pango_font_description_get_family (priv->values->font));
1658 g_value_set_enum (value, pango_font_description_get_style (priv->values->font));
1662 g_value_set_enum (value, pango_font_description_get_variant (priv->values->font));
1666 g_value_set_int (value, pango_font_description_get_weight (priv->values->font));
1670 g_value_set_enum (value, pango_font_description_get_stretch (priv->values->font));
1674 g_value_set_int (value, pango_font_description_get_size (priv->values->font));
1677 case PROP_SIZE_POINTS:
1678 g_value_set_double (value, ((double)pango_font_description_get_size (priv->values->font)) / (double)PANGO_SCALE);
1684 g_value_set_double (value, priv->values->font_scale);
1687 case PROP_PIXELS_ABOVE_LINES:
1688 g_value_set_int (value, priv->values->pixels_above_lines);
1691 case PROP_PIXELS_BELOW_LINES:
1692 g_value_set_int (value, priv->values->pixels_below_lines);
1695 case PROP_PIXELS_INSIDE_WRAP:
1696 g_value_set_int (value, priv->values->pixels_inside_wrap);
1700 g_value_set_boolean (value, priv->values->editable);
1703 case PROP_WRAP_MODE:
1704 g_value_set_enum (value, priv->values->wrap_mode);
1707 case PROP_JUSTIFICATION:
1708 g_value_set_enum (value, priv->values->justification);
1711 case PROP_DIRECTION:
1712 g_value_set_enum (value, priv->values->direction);
1715 case PROP_LEFT_MARGIN:
1716 g_value_set_int (value, priv->values->left_margin);
1720 g_value_set_int (value, priv->values->indent);
1723 case PROP_STRIKETHROUGH:
1724 g_value_set_boolean (value, priv->values->appearance.strikethrough);
1727 case PROP_RIGHT_MARGIN:
1728 g_value_set_int (value, priv->values->right_margin);
1731 case PROP_UNDERLINE:
1732 g_value_set_enum (value, priv->values->appearance.underline);
1736 g_value_set_int (value, priv->values->appearance.rise);
1739 case PROP_BACKGROUND_FULL_HEIGHT:
1740 g_value_set_boolean (value, priv->values->bg_full_height);
1744 g_value_set_string (value, pango_language_to_string (priv->values->language));
1748 if (priv->values->tabs)
1749 g_value_set_boxed (value, priv->values->tabs);
1752 case PROP_INVISIBLE:
1753 g_value_set_boolean (value, priv->values->invisible);
1756 case PROP_PARAGRAPH_BACKGROUND_GDK:
1757 g_value_set_boxed (value, priv->values->pg_bg_color);
1760 case PROP_PARAGRAPH_BACKGROUND_RGBA:
1761 g_value_set_boxed (value, priv->values->pg_bg_rgba);
1764 case PROP_ACCUMULATIVE_MARGIN:
1765 g_value_set_boolean (value, priv->accumulative_margin);
1768 case PROP_BACKGROUND_SET:
1769 g_value_set_boolean (value, priv->bg_color_set);
1772 case PROP_FOREGROUND_SET:
1773 g_value_set_boolean (value, priv->fg_color_set);
1776 case PROP_FAMILY_SET:
1777 case PROP_STYLE_SET:
1778 case PROP_VARIANT_SET:
1779 case PROP_WEIGHT_SET:
1780 case PROP_STRETCH_SET:
1783 PangoFontMask set_mask = priv->values->font ? pango_font_description_get_set_fields (priv->values->font) : 0;
1784 PangoFontMask test_mask = get_property_font_set_mask (prop_id);
1785 g_value_set_boolean (value, (set_mask & test_mask) != 0);
1790 case PROP_SCALE_SET:
1791 g_value_set_boolean (value, priv->scale_set);
1794 case PROP_PIXELS_ABOVE_LINES_SET:
1795 g_value_set_boolean (value, priv->pixels_above_lines_set);
1798 case PROP_PIXELS_BELOW_LINES_SET:
1799 g_value_set_boolean (value, priv->pixels_below_lines_set);
1802 case PROP_PIXELS_INSIDE_WRAP_SET:
1803 g_value_set_boolean (value, priv->pixels_inside_wrap_set);
1806 case PROP_EDITABLE_SET:
1807 g_value_set_boolean (value, priv->editable_set);
1810 case PROP_WRAP_MODE_SET:
1811 g_value_set_boolean (value, priv->wrap_mode_set);
1814 case PROP_JUSTIFICATION_SET:
1815 g_value_set_boolean (value, priv->justification_set);
1818 case PROP_LEFT_MARGIN_SET:
1819 g_value_set_boolean (value, priv->left_margin_set);
1822 case PROP_INDENT_SET:
1823 g_value_set_boolean (value, priv->indent_set);
1826 case PROP_STRIKETHROUGH_SET:
1827 g_value_set_boolean (value, priv->strikethrough_set);
1830 case PROP_RIGHT_MARGIN_SET:
1831 g_value_set_boolean (value, priv->right_margin_set);
1834 case PROP_UNDERLINE_SET:
1835 g_value_set_boolean (value, priv->underline_set);
1839 g_value_set_boolean (value, priv->rise_set);
1842 case PROP_BACKGROUND_FULL_HEIGHT_SET:
1843 g_value_set_boolean (value, priv->bg_full_height_set);
1846 case PROP_LANGUAGE_SET:
1847 g_value_set_boolean (value, priv->language_set);
1851 g_value_set_boolean (value, priv->tabs_set);
1854 case PROP_INVISIBLE_SET:
1855 g_value_set_boolean (value, priv->invisible_set);
1858 case PROP_PARAGRAPH_BACKGROUND_SET:
1859 g_value_set_boolean (value, priv->pg_bg_color_set);
1862 case PROP_BACKGROUND:
1863 case PROP_FOREGROUND:
1864 case PROP_PARAGRAPH_BACKGROUND:
1865 g_warning ("'foreground', 'background' and 'paragraph_background' properties are not readable, use 'foreground_gdk', 'background_gdk' and 'paragraph_background_gdk'");
1868 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1884 delta_priority_foreach (GtkTextTag *tag, gpointer user_data)
1886 GtkTextTagPrivate *priv = tag->priv;
1887 DeltaData *dd = user_data;
1889 if (priv->priority >= dd->low && priv->priority <= dd->high)
1890 priv->priority += dd->delta;
1894 * gtk_text_tag_get_priority:
1895 * @tag: a #GtkTextTag
1897 * Get the tag priority.
1899 * Return value: The tag's priority.
1902 gtk_text_tag_get_priority (GtkTextTag *tag)
1904 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), 0);
1906 return tag->priv->priority;
1910 * gtk_text_tag_set_priority:
1911 * @tag: a #GtkTextTag
1912 * @priority: the new priority
1914 * Sets the priority of a #GtkTextTag. Valid priorities are
1915 * start at 0 and go to one less than gtk_text_tag_table_get_size().
1916 * Each tag in a table has a unique priority; setting the priority
1917 * of one tag shifts the priorities of all the other tags in the
1918 * table to maintain a unique priority for each tag. Higher priority
1919 * tags "win" if two tags both set the same text attribute. When adding
1920 * a tag to a tag table, it will be assigned the highest priority in
1921 * the table by default; so normally the precedence of a set of tags
1922 * is the order in which they were added to the table, or created with
1923 * gtk_text_buffer_create_tag(), which adds the tag to the buffer's table
1927 gtk_text_tag_set_priority (GtkTextTag *tag,
1930 GtkTextTagPrivate *priv;
1933 g_return_if_fail (GTK_IS_TEXT_TAG (tag));
1937 g_return_if_fail (priv->table != NULL);
1938 g_return_if_fail (priority >= 0);
1939 g_return_if_fail (priority < gtk_text_tag_table_get_size (priv->table));
1941 if (priority == priv->priority)
1944 if (priority < priv->priority)
1947 dd.high = priv->priority - 1;
1952 dd.low = priv->priority + 1;
1957 gtk_text_tag_table_foreach (priv->table,
1958 delta_priority_foreach,
1961 priv->priority = priority;
1965 * gtk_text_tag_event:
1966 * @tag: a #GtkTextTag
1967 * @event_object: object that received the event, such as a widget
1969 * @iter: location where the event was received
1971 * Emits the "event" signal on the #GtkTextTag.
1973 * Return value: result of signal emission (whether the event was handled)
1976 gtk_text_tag_event (GtkTextTag *tag,
1977 GObject *event_object,
1979 const GtkTextIter *iter)
1981 gboolean retval = FALSE;
1983 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
1984 g_return_val_if_fail (G_IS_OBJECT (event_object), FALSE);
1985 g_return_val_if_fail (event != NULL, FALSE);
1999 tag_sort_func (gconstpointer first, gconstpointer second)
2001 GtkTextTag *tag1, *tag2;
2003 tag1 = * (GtkTextTag **) first;
2004 tag2 = * (GtkTextTag **) second;
2005 return tag1->priv->priority - tag2->priv->priority;
2009 _gtk_text_tag_array_sort (GtkTextTag** tag_array_p,
2014 GtkTextTag **maxPtrPtr, *tmp;
2016 g_return_if_fail (tag_array_p != NULL);
2017 g_return_if_fail (len > 0);
2023 GtkTextTag **iter = tag_array_p;
2025 for (i = len-1; i > 0; i--, iter++) {
2026 maxPtrPtr = tag = iter;
2027 prio = tag[0]->priv->priority;
2028 for (j = i, tag++; j > 0; j--, tag++) {
2029 if (tag[0]->priv->priority < prio) {
2030 prio = tag[0]->priv->priority;
2039 qsort ((void *) tag_array_p, (unsigned) len, sizeof (GtkTextTag *),
2045 printf ("Sorted tag array: \n");
2049 GtkTextTag *t = tag_array_p[i];
2050 printf (" %s priority %d\n", t->name, t->priority);