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.
65 * For each property of #GtkTextTag, there is a "set" property, e.g.
66 * "font-set" corresponds to "font". These "set" properties reflect
67 * whether a property has been set or not.
68 * They are maintained by GTK+ and you should not set them independently.
76 #include "gtktexttag.h"
77 #include "gtktexttypes.h"
78 #include "gtktexttagtable.h"
80 #include "gtkmarshalers.h"
81 #include "gtkprivate.h"
82 #include "gtktypebuiltins.h"
100 PROP_FOREGROUND_RGBA,
111 PROP_PIXELS_ABOVE_LINES,
112 PROP_PIXELS_BELOW_LINES,
113 PROP_PIXELS_INSIDE_WRAP,
124 PROP_BACKGROUND_FULL_HEIGHT,
128 PROP_PARAGRAPH_BACKGROUND,
129 PROP_PARAGRAPH_BACKGROUND_GDK,
130 PROP_PARAGRAPH_BACKGROUND_RGBA,
133 PROP_ACCUMULATIVE_MARGIN,
135 /* Whether-a-style-arg-is-set args */
145 PROP_PIXELS_ABOVE_LINES_SET,
146 PROP_PIXELS_BELOW_LINES_SET,
147 PROP_PIXELS_INSIDE_WRAP_SET,
150 PROP_JUSTIFICATION_SET,
151 PROP_LEFT_MARGIN_SET,
153 PROP_STRIKETHROUGH_SET,
154 PROP_RIGHT_MARGIN_SET,
157 PROP_BACKGROUND_FULL_HEIGHT_SET,
161 PROP_PARAGRAPH_BACKGROUND_SET,
165 static void gtk_text_tag_finalize (GObject *object);
166 static void gtk_text_tag_set_property (GObject *object,
170 static void gtk_text_tag_get_property (GObject *object,
175 static guint signals[LAST_SIGNAL] = { 0 };
177 G_DEFINE_TYPE (GtkTextTag, gtk_text_tag, G_TYPE_OBJECT)
180 gtk_text_tag_class_init (GtkTextTagClass *klass)
182 GObjectClass *object_class = G_OBJECT_CLASS (klass);
184 object_class->set_property = gtk_text_tag_set_property;
185 object_class->get_property = gtk_text_tag_get_property;
187 object_class->finalize = gtk_text_tag_finalize;
190 g_object_class_install_property (object_class,
192 g_param_spec_string ("name",
194 P_("Name used to refer to the text tag. NULL for anonymous tags"),
196 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
200 g_object_class_install_property (object_class,
202 g_param_spec_string ("background",
203 P_("Background color name"),
204 P_("Background color as a string"),
206 GTK_PARAM_WRITABLE));
209 * GtkTextTag:background-gdk:
211 * Background color as a #GdkColor.
213 * Deprecated: 3.4: Use #GtkTextTag:background-rgba instead.
215 g_object_class_install_property (object_class,
217 g_param_spec_boxed ("background-gdk",
218 P_("Background color"),
219 P_("Background color as a GdkColor"),
221 GTK_PARAM_READWRITE | G_PARAM_DEPRECATED));
224 * GtkTextTag:background-rgba:
226 * Background color as a #GdkRGBA.
230 g_object_class_install_property (object_class,
231 PROP_BACKGROUND_RGBA,
232 g_param_spec_boxed ("background-rgba",
233 P_("Background RGBA"),
234 P_("Background color as a GdkRGBA"),
236 GTK_PARAM_READWRITE));
238 g_object_class_install_property (object_class,
239 PROP_BACKGROUND_FULL_HEIGHT,
240 g_param_spec_boolean ("background-full-height",
241 P_("Background full height"),
242 P_("Whether the background color fills the entire line height or only the height of the tagged characters"),
244 GTK_PARAM_READWRITE));
246 g_object_class_install_property (object_class,
248 g_param_spec_string ("foreground",
249 P_("Foreground color name"),
250 P_("Foreground color as a string"),
252 GTK_PARAM_WRITABLE));
255 * GtkTextTag:foreground-gdk:
257 * Foreground color as a #GdkColor.
259 * Deprecated: 3.4: Use #GtkTextTag:foreground-rgba instead.
261 g_object_class_install_property (object_class,
263 g_param_spec_boxed ("foreground-gdk",
264 P_("Foreground color"),
265 P_("Foreground color as a GdkColor"),
267 GTK_PARAM_READWRITE | G_PARAM_DEPRECATED));
270 * GtkTextTag:foreground-rgba:
272 * Foreground color as a #GdkRGBA.
276 g_object_class_install_property (object_class,
277 PROP_FOREGROUND_RGBA,
278 g_param_spec_boxed ("foreground-rgba",
279 P_("Foreground RGBA"),
280 P_("Foreground color as a GdkRGBA"),
282 GTK_PARAM_READWRITE));
284 g_object_class_install_property (object_class,
286 g_param_spec_enum ("direction",
287 P_("Text direction"),
288 P_("Text direction, e.g. right-to-left or left-to-right"),
289 GTK_TYPE_TEXT_DIRECTION,
291 GTK_PARAM_READWRITE));
293 g_object_class_install_property (object_class,
295 g_param_spec_boolean ("editable",
297 P_("Whether the text can be modified by the user"),
299 GTK_PARAM_READWRITE));
304 * Font description as string, e.g. \"Sans Italic 12\".
306 * Note that the initial value of this property depends on
307 * the internals of #PangoFontDescription.
309 g_object_class_install_property (object_class,
311 g_param_spec_string ("font",
313 P_("Font description as a string, e.g. \"Sans Italic 12\""),
315 GTK_PARAM_READWRITE));
317 g_object_class_install_property (object_class,
319 g_param_spec_boxed ("font-desc",
321 P_("Font description as a PangoFontDescription struct"),
322 PANGO_TYPE_FONT_DESCRIPTION,
323 GTK_PARAM_READWRITE));
325 g_object_class_install_property (object_class,
327 g_param_spec_string ("family",
329 P_("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
331 GTK_PARAM_READWRITE));
333 g_object_class_install_property (object_class,
335 g_param_spec_enum ("style",
337 P_("Font style as a PangoStyle, e.g. PANGO_STYLE_ITALIC"),
340 GTK_PARAM_READWRITE));
342 g_object_class_install_property (object_class,
344 g_param_spec_enum ("variant",
346 P_("Font variant as a PangoVariant, e.g. PANGO_VARIANT_SMALL_CAPS"),
348 PANGO_VARIANT_NORMAL,
349 GTK_PARAM_READWRITE));
351 g_object_class_install_property (object_class,
353 g_param_spec_int ("weight",
355 P_("Font weight as an integer, see predefined values in PangoWeight; for example, PANGO_WEIGHT_BOLD"),
359 GTK_PARAM_READWRITE));
362 g_object_class_install_property (object_class,
364 g_param_spec_enum ("stretch",
366 P_("Font stretch as a PangoStretch, e.g. PANGO_STRETCH_CONDENSED"),
368 PANGO_STRETCH_NORMAL,
369 GTK_PARAM_READWRITE));
371 g_object_class_install_property (object_class,
373 g_param_spec_int ("size",
375 P_("Font size in Pango units"),
379 GTK_PARAM_READWRITE));
381 g_object_class_install_property (object_class,
383 g_param_spec_double ("scale",
385 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"),
389 GTK_PARAM_READWRITE));
391 g_object_class_install_property (object_class,
393 g_param_spec_double ("size-points",
395 P_("Font size in points"),
399 GTK_PARAM_READWRITE));
401 g_object_class_install_property (object_class,
403 g_param_spec_enum ("justification",
405 P_("Left, right, or center justification"),
406 GTK_TYPE_JUSTIFICATION,
408 GTK_PARAM_READWRITE));
411 * GtkTextTag:language:
413 * The language this text is in, as an ISO code. Pango can use this as a
414 * hint when rendering the text. If not set, an appropriate default will be
417 * Note that the initial value of this property depends on the current
418 * locale, see also gtk_get_default_language().
420 g_object_class_install_property (object_class,
422 g_param_spec_string ("language",
424 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."),
426 GTK_PARAM_READWRITE));
428 g_object_class_install_property (object_class,
430 g_param_spec_int ("left-margin",
432 P_("Width of the left margin in pixels"),
436 GTK_PARAM_READWRITE));
438 g_object_class_install_property (object_class,
440 g_param_spec_int ("right-margin",
442 P_("Width of the right margin in pixels"),
446 GTK_PARAM_READWRITE));
449 g_object_class_install_property (object_class,
451 g_param_spec_int ("indent",
453 P_("Amount to indent the paragraph, in pixels"),
457 GTK_PARAM_READWRITE));
460 g_object_class_install_property (object_class,
462 g_param_spec_int ("rise",
464 P_("Offset of text above the baseline (below the baseline if rise is negative) in Pango units"),
468 GTK_PARAM_READWRITE));
470 g_object_class_install_property (object_class,
471 PROP_PIXELS_ABOVE_LINES,
472 g_param_spec_int ("pixels-above-lines",
473 P_("Pixels above lines"),
474 P_("Pixels of blank space above paragraphs"),
478 GTK_PARAM_READWRITE));
480 g_object_class_install_property (object_class,
481 PROP_PIXELS_BELOW_LINES,
482 g_param_spec_int ("pixels-below-lines",
483 P_("Pixels below lines"),
484 P_("Pixels of blank space below paragraphs"),
488 GTK_PARAM_READWRITE));
490 g_object_class_install_property (object_class,
491 PROP_PIXELS_INSIDE_WRAP,
492 g_param_spec_int ("pixels-inside-wrap",
493 P_("Pixels inside wrap"),
494 P_("Pixels of blank space between wrapped lines in a paragraph"),
498 GTK_PARAM_READWRITE));
500 g_object_class_install_property (object_class,
502 g_param_spec_boolean ("strikethrough",
504 P_("Whether to strike through the text"),
506 GTK_PARAM_READWRITE));
508 g_object_class_install_property (object_class,
510 g_param_spec_enum ("underline",
512 P_("Style of underline for this text"),
513 PANGO_TYPE_UNDERLINE,
514 PANGO_UNDERLINE_NONE,
515 GTK_PARAM_READWRITE));
517 g_object_class_install_property (object_class,
519 g_param_spec_enum ("wrap-mode",
521 P_("Whether to wrap lines never, at word boundaries, or at character boundaries"),
524 GTK_PARAM_READWRITE));
527 g_object_class_install_property (object_class,
529 g_param_spec_boxed ("tabs",
531 P_("Custom tabs for this text"),
532 PANGO_TYPE_TAB_ARRAY,
533 GTK_PARAM_READWRITE));
536 * GtkTextTag:invisible:
538 * Whether this text is hidden.
540 * Note that there may still be problems with the support for invisible
541 * text, in particular when navigating programmatically inside a buffer
542 * containing invisible segments.
546 g_object_class_install_property (object_class,
548 g_param_spec_boolean ("invisible",
550 P_("Whether this text is hidden."),
552 GTK_PARAM_READWRITE));
555 * GtkTextTag:paragraph-background:
557 * The paragraph background color as a string.
561 g_object_class_install_property (object_class,
562 PROP_PARAGRAPH_BACKGROUND,
563 g_param_spec_string ("paragraph-background",
564 P_("Paragraph background color name"),
565 P_("Paragraph background color as a string"),
567 GTK_PARAM_WRITABLE));
570 * GtkTextTag:paragraph-background-gdk:
572 * The paragraph background color as a as a #GdkColor.
576 * Deprecated: 3.4: Use #GtkTextTag:paragraph-background-rgba instead.
578 g_object_class_install_property (object_class,
579 PROP_PARAGRAPH_BACKGROUND_GDK,
580 g_param_spec_boxed ("paragraph-background-gdk",
581 P_("Paragraph background color"),
582 P_("Paragraph background color as a GdkColor"),
584 GTK_PARAM_READWRITE | G_PARAM_DEPRECATED));
587 * GtkTextTag:paragraph-background-rgba:
589 * The paragraph background color as a as a #GdkRGBA.
593 g_object_class_install_property (object_class,
594 PROP_PARAGRAPH_BACKGROUND_RGBA,
595 g_param_spec_boxed ("paragraph-background-rgba",
596 P_("Paragraph background RGBA"),
597 P_("Paragraph background RGBA as a GdkRGBA"),
599 GTK_PARAM_READWRITE));
602 * GtkTextTag:accumulative-margin:
604 * Whether the margins accumulate or override each other.
606 * When set to %TRUE the margins of this tag are added to the margins
607 * of any other non-accumulative margins present. When set to %FALSE
608 * the margins override one another (the default).
612 g_object_class_install_property (object_class,
613 PROP_ACCUMULATIVE_MARGIN,
614 g_param_spec_boolean ("accumulative-margin",
615 P_("Margin Accumulates"),
616 P_("Whether left and right margins accumulate."),
618 GTK_PARAM_READWRITE));
620 /* Style props are set or not */
622 #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))
624 ADD_SET_PROP ("background-set", PROP_BACKGROUND_SET,
625 P_("Background set"),
626 P_("Whether this tag affects the background color"));
628 ADD_SET_PROP ("background-full-height-set", PROP_BACKGROUND_FULL_HEIGHT_SET,
629 P_("Background full height set"),
630 P_("Whether this tag affects background height"));
632 ADD_SET_PROP ("foreground-set", PROP_FOREGROUND_SET,
633 P_("Foreground set"),
634 P_("Whether this tag affects the foreground color"));
636 ADD_SET_PROP ("editable-set", PROP_EDITABLE_SET,
637 P_("Editability set"),
638 P_("Whether this tag affects text editability"));
640 ADD_SET_PROP ("family-set", PROP_FAMILY_SET,
641 P_("Font family set"),
642 P_("Whether this tag affects the font family"));
644 ADD_SET_PROP ("style-set", PROP_STYLE_SET,
645 P_("Font style set"),
646 P_("Whether this tag affects the font style"));
648 ADD_SET_PROP ("variant-set", PROP_VARIANT_SET,
649 P_("Font variant set"),
650 P_("Whether this tag affects the font variant"));
652 ADD_SET_PROP ("weight-set", PROP_WEIGHT_SET,
653 P_("Font weight set"),
654 P_("Whether this tag affects the font weight"));
656 ADD_SET_PROP ("stretch-set", PROP_STRETCH_SET,
657 P_("Font stretch set"),
658 P_("Whether this tag affects the font stretch"));
660 ADD_SET_PROP ("size-set", PROP_SIZE_SET,
662 P_("Whether this tag affects the font size"));
664 ADD_SET_PROP ("scale-set", PROP_SCALE_SET,
665 P_("Font scale set"),
666 P_("Whether this tag scales the font size by a factor"));
668 ADD_SET_PROP ("justification-set", PROP_JUSTIFICATION_SET,
669 P_("Justification set"),
670 P_("Whether this tag affects paragraph justification"));
672 ADD_SET_PROP ("language-set", PROP_LANGUAGE_SET,
674 P_("Whether this tag affects the language the text is rendered as"));
676 ADD_SET_PROP ("left-margin-set", PROP_LEFT_MARGIN_SET,
677 P_("Left margin set"),
678 P_("Whether this tag affects the left margin"));
680 ADD_SET_PROP ("indent-set", PROP_INDENT_SET,
682 P_("Whether this tag affects indentation"));
684 ADD_SET_PROP ("rise-set", PROP_RISE_SET,
686 P_("Whether this tag affects the rise"));
688 ADD_SET_PROP ("pixels-above-lines-set", PROP_PIXELS_ABOVE_LINES_SET,
689 P_("Pixels above lines set"),
690 P_("Whether this tag affects the number of pixels above lines"));
692 ADD_SET_PROP ("pixels-below-lines-set", PROP_PIXELS_BELOW_LINES_SET,
693 P_("Pixels below lines set"),
694 P_("Whether this tag affects the number of pixels above lines"));
696 ADD_SET_PROP ("pixels-inside-wrap-set", PROP_PIXELS_INSIDE_WRAP_SET,
697 P_("Pixels inside wrap set"),
698 P_("Whether this tag affects the number of pixels between wrapped lines"));
700 ADD_SET_PROP ("strikethrough-set", PROP_STRIKETHROUGH_SET,
701 P_("Strikethrough set"),
702 P_("Whether this tag affects strikethrough"));
704 ADD_SET_PROP ("right-margin-set", PROP_RIGHT_MARGIN_SET,
705 P_("Right margin set"),
706 P_("Whether this tag affects the right margin"));
708 ADD_SET_PROP ("underline-set", PROP_UNDERLINE_SET,
710 P_("Whether this tag affects underlining"));
712 ADD_SET_PROP ("wrap-mode-set", PROP_WRAP_MODE_SET,
714 P_("Whether this tag affects line wrap mode"));
716 ADD_SET_PROP ("tabs-set", PROP_TABS_SET,
718 P_("Whether this tag affects tabs"));
720 ADD_SET_PROP ("invisible-set", PROP_INVISIBLE_SET,
722 P_("Whether this tag affects text visibility"));
724 ADD_SET_PROP ("paragraph-background-set", PROP_PARAGRAPH_BACKGROUND_SET,
725 P_("Paragraph background set"),
726 P_("Whether this tag affects the paragraph background color"));
730 * @tag: the #GtkTextTag on which the signal is emitted
731 * @object: the object the event was fired from (typically a #GtkTextView)
732 * @event: the event which triggered the signal
733 * @iter: a #GtkTextIter pointing at the location the event occured
735 * The ::event signal is emitted when an event occurs on a region of the
736 * buffer marked with this tag.
738 * Returns: %TRUE to stop other handlers from being invoked for the
739 * event. %FALSE to propagate the event further.
742 g_signal_new (I_("event"),
743 G_OBJECT_CLASS_TYPE (object_class),
745 G_STRUCT_OFFSET (GtkTextTagClass, event),
746 _gtk_boolean_handled_accumulator, NULL,
747 _gtk_marshal_BOOLEAN__OBJECT_BOXED_BOXED,
751 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE,
754 g_type_class_add_private (klass, sizeof (GtkTextTagPrivate));
758 gtk_text_tag_init (GtkTextTag *text_tag)
760 GtkTextTagPrivate *priv;
762 text_tag->priv = G_TYPE_INSTANCE_GET_PRIVATE (text_tag,
765 priv = text_tag->priv;
767 priv->values = gtk_text_attributes_new ();
772 * @name: (allow-none): tag name, or %NULL
774 * Creates a #GtkTextTag. Configure the tag using object arguments,
775 * i.e. using g_object_set().
777 * Return value: a new #GtkTextTag
780 gtk_text_tag_new (const gchar *name)
784 tag = g_object_new (GTK_TYPE_TEXT_TAG, "name", name, NULL);
790 gtk_text_tag_finalize (GObject *object)
792 GtkTextTag *text_tag = GTK_TEXT_TAG (object);
793 GtkTextTagPrivate *priv = text_tag->priv;
796 gtk_text_tag_table_remove (priv->table, text_tag);
798 g_assert (priv->table == NULL);
800 gtk_text_attributes_unref (priv->values);
806 G_OBJECT_CLASS (gtk_text_tag_parent_class)->finalize (object);
810 copy_rgba_to_gdk_color (GdkRGBA *src,
813 dest->red = CLAMP (src->red, 0.0, 1.0) * 65535.0;
814 dest->green = CLAMP (src->green, 0.0, 1.0) * 65535.0;
815 dest->blue = CLAMP (src->blue, 0.0, 1.0) * 65535.0;
819 copy_gdk_color_to_rgba (GdkColor *src,
822 dest->red = src->red / 65535.;
823 dest->green = src->green / 65535.;
824 dest->blue = src->blue / 65535.;
829 set_bg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
831 GtkTextTagPrivate *priv = tag->priv;
833 if (priv->values->appearance.rgba[0])
834 gdk_rgba_free (priv->values->appearance.rgba[0]);
836 priv->values->appearance.rgba[0] = NULL;
840 if (!priv->bg_color_set)
842 priv->bg_color_set = TRUE;
843 g_object_notify (G_OBJECT (tag), "background-set");
846 priv->values->appearance.rgba[0] = gdk_rgba_copy (rgba);
848 copy_rgba_to_gdk_color (rgba, &priv->values->appearance.bg_color);
852 if (priv->bg_color_set)
854 priv->bg_color_set = FALSE;
855 g_object_notify (G_OBJECT (tag), "background-set");
861 set_fg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
863 GtkTextTagPrivate *priv = tag->priv;
865 if (priv->values->appearance.rgba[1])
866 gdk_rgba_free (priv->values->appearance.rgba[1]);
868 priv->values->appearance.rgba[1] = NULL;
872 if (!priv->fg_color_set)
874 priv->fg_color_set = TRUE;
875 g_object_notify (G_OBJECT (tag), "foreground-set");
878 priv->values->appearance.rgba[1] = gdk_rgba_copy (rgba);
880 copy_rgba_to_gdk_color (rgba, &priv->values->appearance.fg_color);
884 if (priv->fg_color_set)
886 priv->fg_color_set = FALSE;
887 g_object_notify (G_OBJECT (tag), "foreground-set");
893 set_pg_bg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
895 GtkTextTagPrivate *priv = tag->priv;
897 if (priv->values->pg_bg_rgba)
898 gdk_rgba_free (priv->values->pg_bg_rgba);
900 if (priv->values->pg_bg_color)
901 gdk_color_free (priv->values->pg_bg_color);
903 priv->values->pg_bg_rgba = NULL;
904 priv->values->pg_bg_color = NULL;
908 GdkColor color = { 0, };
910 if (!priv->pg_bg_color_set)
912 priv->pg_bg_color_set = TRUE;
913 g_object_notify (G_OBJECT (tag), "paragraph-background-set");
916 priv->values->pg_bg_rgba = gdk_rgba_copy (rgba);
918 copy_rgba_to_gdk_color (rgba, &color);
919 priv->values->pg_bg_color = gdk_color_copy (&color);
923 if (priv->pg_bg_color_set)
925 priv->pg_bg_color_set = FALSE;
926 g_object_notify (G_OBJECT (tag), "paragraph-background-set");
933 set_bg_color (GtkTextTag *tag, GdkColor *color)
939 copy_gdk_color_to_rgba (color, &rgba);
940 set_bg_rgba (tag, &rgba);
943 set_bg_rgba (tag, NULL);
947 set_fg_color (GtkTextTag *tag, GdkColor *color)
953 copy_gdk_color_to_rgba (color, &rgba);
954 set_fg_rgba (tag, &rgba);
957 set_fg_rgba (tag, NULL);
961 set_pg_bg_color (GtkTextTag *tag, GdkColor *color)
967 copy_gdk_color_to_rgba (color, &rgba);
968 set_pg_bg_rgba (tag, &rgba);
971 set_pg_bg_rgba (tag, NULL);
975 get_property_font_set_mask (guint prop_id)
979 case PROP_FAMILY_SET:
980 return PANGO_FONT_MASK_FAMILY;
982 return PANGO_FONT_MASK_STYLE;
983 case PROP_VARIANT_SET:
984 return PANGO_FONT_MASK_VARIANT;
985 case PROP_WEIGHT_SET:
986 return PANGO_FONT_MASK_WEIGHT;
987 case PROP_STRETCH_SET:
988 return PANGO_FONT_MASK_STRETCH;
990 return PANGO_FONT_MASK_SIZE;
997 set_font_desc_fields (PangoFontDescription *desc,
998 PangoFontMask to_set)
1000 PangoFontMask changed_mask = 0;
1002 if (to_set & PANGO_FONT_MASK_FAMILY)
1004 const char *family = pango_font_description_get_family (desc);
1008 changed_mask |= PANGO_FONT_MASK_FAMILY;
1011 pango_font_description_set_family (desc, family);
1013 if (to_set & PANGO_FONT_MASK_STYLE)
1014 pango_font_description_set_style (desc, pango_font_description_get_style (desc));
1015 if (to_set & PANGO_FONT_MASK_VARIANT)
1016 pango_font_description_set_variant (desc, pango_font_description_get_variant (desc));
1017 if (to_set & PANGO_FONT_MASK_WEIGHT)
1018 pango_font_description_set_weight (desc, pango_font_description_get_weight (desc));
1019 if (to_set & PANGO_FONT_MASK_STRETCH)
1020 pango_font_description_set_stretch (desc, pango_font_description_get_stretch (desc));
1021 if (to_set & PANGO_FONT_MASK_SIZE)
1023 gint size = pango_font_description_get_size (desc);
1026 size = 10 * PANGO_SCALE;
1027 changed_mask |= PANGO_FONT_MASK_SIZE;
1030 pango_font_description_set_size (desc, size);
1033 return changed_mask;
1037 notify_set_changed (GObject *object,
1038 PangoFontMask changed_mask)
1040 if (changed_mask & PANGO_FONT_MASK_FAMILY)
1041 g_object_notify (object, "family-set");
1042 if (changed_mask & PANGO_FONT_MASK_STYLE)
1043 g_object_notify (object, "style-set");
1044 if (changed_mask & PANGO_FONT_MASK_VARIANT)
1045 g_object_notify (object, "variant-set");
1046 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
1047 g_object_notify (object, "weight-set");
1048 if (changed_mask & PANGO_FONT_MASK_STRETCH)
1049 g_object_notify (object, "stretch-set");
1050 if (changed_mask & PANGO_FONT_MASK_SIZE)
1051 g_object_notify (object, "size-set");
1055 notify_fields_changed (GObject *object,
1056 PangoFontMask changed_mask)
1058 if (changed_mask & PANGO_FONT_MASK_FAMILY)
1059 g_object_notify (object, "family");
1060 if (changed_mask & PANGO_FONT_MASK_STYLE)
1061 g_object_notify (object, "style");
1062 if (changed_mask & PANGO_FONT_MASK_VARIANT)
1063 g_object_notify (object, "variant");
1064 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
1065 g_object_notify (object, "weight");
1066 if (changed_mask & PANGO_FONT_MASK_STRETCH)
1067 g_object_notify (object, "stretch");
1068 if (changed_mask & PANGO_FONT_MASK_SIZE)
1069 g_object_notify (object, "size");
1073 set_font_description (GtkTextTag *text_tag,
1074 PangoFontDescription *font_desc)
1076 GtkTextTagPrivate *priv = text_tag->priv;
1077 GObject *object = G_OBJECT (text_tag);
1078 PangoFontDescription *new_font_desc;
1079 PangoFontMask old_mask, new_mask, changed_mask, set_changed_mask;
1082 new_font_desc = pango_font_description_copy (font_desc);
1084 new_font_desc = pango_font_description_new ();
1086 if (priv->values->font)
1087 old_mask = pango_font_description_get_set_fields (priv->values->font);
1091 new_mask = pango_font_description_get_set_fields (new_font_desc);
1093 changed_mask = old_mask | new_mask;
1094 set_changed_mask = old_mask ^ new_mask;
1096 if (priv->values->font)
1097 pango_font_description_free (priv->values->font);
1098 priv->values->font = new_font_desc;
1100 g_object_freeze_notify (object);
1102 g_object_notify (object, "font-desc");
1103 g_object_notify (object, "font");
1105 if (changed_mask & PANGO_FONT_MASK_FAMILY)
1106 g_object_notify (object, "family");
1107 if (changed_mask & PANGO_FONT_MASK_STYLE)
1108 g_object_notify (object, "style");
1109 if (changed_mask & PANGO_FONT_MASK_VARIANT)
1110 g_object_notify (object, "variant");
1111 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
1112 g_object_notify (object, "weight");
1113 if (changed_mask & PANGO_FONT_MASK_STRETCH)
1114 g_object_notify (object, "stretch");
1115 if (changed_mask & PANGO_FONT_MASK_SIZE)
1117 g_object_notify (object, "size");
1118 g_object_notify (object, "size-points");
1121 notify_set_changed (object, set_changed_mask);
1123 g_object_thaw_notify (object);
1127 gtk_text_tag_ensure_font (GtkTextTag *text_tag)
1129 GtkTextTagPrivate *priv = text_tag->priv;
1131 if (!priv->values->font)
1132 priv->values->font = pango_font_description_new ();
1136 gtk_text_tag_set_property (GObject *object,
1138 const GValue *value,
1141 GtkTextTag *text_tag = GTK_TEXT_TAG (object);
1142 GtkTextTagPrivate *priv = text_tag->priv;
1143 gboolean size_changed = FALSE;
1148 g_return_if_fail (priv->name == NULL);
1149 priv->name = g_value_dup_string (value);
1152 case PROP_BACKGROUND:
1156 if (!g_value_get_string (value))
1157 set_bg_rgba (text_tag, NULL); /* reset background_set to FALSE */
1158 else if (gdk_rgba_parse (&rgba, g_value_get_string (value)))
1159 set_bg_rgba (text_tag, &rgba);
1161 g_warning ("Don't know color `%s'", g_value_get_string (value));
1163 g_object_notify (object, "background-gdk");
1167 case PROP_FOREGROUND:
1171 if (!g_value_get_string (value))
1172 set_fg_rgba (text_tag, NULL); /* reset to foreground_set to FALSE */
1173 else if (gdk_rgba_parse (&rgba, g_value_get_string (value)))
1174 set_fg_rgba (text_tag, &rgba);
1176 g_warning ("Don't know color `%s'", g_value_get_string (value));
1178 g_object_notify (object, "foreground-gdk");
1182 case PROP_BACKGROUND_GDK:
1184 GdkColor *color = g_value_get_boxed (value);
1186 set_bg_color (text_tag, color);
1190 case PROP_FOREGROUND_GDK:
1192 GdkColor *color = g_value_get_boxed (value);
1194 set_fg_color (text_tag, color);
1198 case PROP_BACKGROUND_RGBA:
1200 GdkRGBA *color = g_value_get_boxed (value);
1202 set_bg_rgba (text_tag, color);
1206 case PROP_FOREGROUND_RGBA:
1208 GdkRGBA *color = g_value_get_boxed (value);
1210 set_fg_rgba (text_tag, color);
1216 PangoFontDescription *font_desc = NULL;
1219 name = g_value_get_string (value);
1222 font_desc = pango_font_description_from_string (name);
1224 set_font_description (text_tag, font_desc);
1226 pango_font_description_free (font_desc);
1228 size_changed = TRUE;
1232 case PROP_FONT_DESC:
1234 PangoFontDescription *font_desc;
1236 font_desc = g_value_get_boxed (value);
1238 set_font_description (text_tag, font_desc);
1240 size_changed = TRUE;
1250 case PROP_SIZE_POINTS:
1252 PangoFontMask old_set_mask;
1254 gtk_text_tag_ensure_font (text_tag);
1255 old_set_mask = pango_font_description_get_set_fields (priv->values->font);
1260 pango_font_description_set_family (priv->values->font,
1261 g_value_get_string (value));
1264 pango_font_description_set_style (priv->values->font,
1265 g_value_get_enum (value));
1268 pango_font_description_set_variant (priv->values->font,
1269 g_value_get_enum (value));
1272 pango_font_description_set_weight (priv->values->font,
1273 g_value_get_int (value));
1276 pango_font_description_set_stretch (priv->values->font,
1277 g_value_get_enum (value));
1280 pango_font_description_set_size (priv->values->font,
1281 g_value_get_int (value));
1282 g_object_notify (object, "size-points");
1284 case PROP_SIZE_POINTS:
1285 pango_font_description_set_size (priv->values->font,
1286 g_value_get_double (value) * PANGO_SCALE);
1287 g_object_notify (object, "size");
1291 size_changed = TRUE;
1292 notify_set_changed (object, old_set_mask & pango_font_description_get_set_fields (priv->values->font));
1293 g_object_notify (object, "font-desc");
1294 g_object_notify (object, "font");
1300 priv->values->font_scale = g_value_get_double (value);
1301 priv->scale_set = TRUE;
1302 g_object_notify (object, "scale-set");
1303 size_changed = TRUE;
1306 case PROP_PIXELS_ABOVE_LINES:
1307 priv->pixels_above_lines_set = TRUE;
1308 priv->values->pixels_above_lines = g_value_get_int (value);
1309 g_object_notify (object, "pixels-above-lines-set");
1310 size_changed = TRUE;
1313 case PROP_PIXELS_BELOW_LINES:
1314 priv->pixels_below_lines_set = TRUE;
1315 priv->values->pixels_below_lines = g_value_get_int (value);
1316 g_object_notify (object, "pixels-below-lines-set");
1317 size_changed = TRUE;
1320 case PROP_PIXELS_INSIDE_WRAP:
1321 priv->pixels_inside_wrap_set = TRUE;
1322 priv->values->pixels_inside_wrap = g_value_get_int (value);
1323 g_object_notify (object, "pixels-inside-wrap-set");
1324 size_changed = TRUE;
1328 priv->editable_set = TRUE;
1329 priv->values->editable = g_value_get_boolean (value);
1330 g_object_notify (object, "editable-set");
1333 case PROP_WRAP_MODE:
1334 priv->wrap_mode_set = TRUE;
1335 priv->values->wrap_mode = g_value_get_enum (value);
1336 g_object_notify (object, "wrap-mode-set");
1337 size_changed = TRUE;
1340 case PROP_JUSTIFICATION:
1341 priv->justification_set = TRUE;
1342 priv->values->justification = g_value_get_enum (value);
1343 g_object_notify (object, "justification-set");
1344 size_changed = TRUE;
1347 case PROP_DIRECTION:
1348 priv->values->direction = g_value_get_enum (value);
1351 case PROP_LEFT_MARGIN:
1352 priv->left_margin_set = TRUE;
1353 priv->values->left_margin = g_value_get_int (value);
1354 g_object_notify (object, "left-margin-set");
1355 size_changed = TRUE;
1359 priv->indent_set = TRUE;
1360 priv->values->indent = g_value_get_int (value);
1361 g_object_notify (object, "indent-set");
1362 size_changed = TRUE;
1365 case PROP_STRIKETHROUGH:
1366 priv->strikethrough_set = TRUE;
1367 priv->values->appearance.strikethrough = g_value_get_boolean (value);
1368 g_object_notify (object, "strikethrough-set");
1371 case PROP_RIGHT_MARGIN:
1372 priv->right_margin_set = TRUE;
1373 priv->values->right_margin = g_value_get_int (value);
1374 g_object_notify (object, "right-margin-set");
1375 size_changed = TRUE;
1378 case PROP_UNDERLINE:
1379 priv->underline_set = TRUE;
1380 priv->values->appearance.underline = g_value_get_enum (value);
1381 g_object_notify (object, "underline-set");
1385 priv->rise_set = TRUE;
1386 priv->values->appearance.rise = g_value_get_int (value);
1387 g_object_notify (object, "rise-set");
1388 size_changed = TRUE;
1391 case PROP_BACKGROUND_FULL_HEIGHT:
1392 priv->bg_full_height_set = TRUE;
1393 priv->values->bg_full_height = g_value_get_boolean (value);
1394 g_object_notify (object, "background-full-height-set");
1398 priv->language_set = TRUE;
1399 priv->values->language = pango_language_from_string (g_value_get_string (value));
1400 g_object_notify (object, "language-set");
1404 priv->tabs_set = TRUE;
1406 if (priv->values->tabs)
1407 pango_tab_array_free (priv->values->tabs);
1409 /* FIXME I'm not sure if this is a memleak or not */
1410 priv->values->tabs =
1411 pango_tab_array_copy (g_value_get_boxed (value));
1413 g_object_notify (object, "tabs-set");
1415 size_changed = TRUE;
1418 case PROP_INVISIBLE:
1419 priv->invisible_set = TRUE;
1420 priv->values->invisible = g_value_get_boolean (value);
1421 g_object_notify (object, "invisible-set");
1422 size_changed = TRUE;
1425 case PROP_PARAGRAPH_BACKGROUND:
1429 if (!g_value_get_string (value))
1430 set_pg_bg_rgba (text_tag, NULL); /* reset paragraph_background_set to FALSE */
1431 else if (gdk_rgba_parse (&rgba, g_value_get_string (value)))
1432 set_pg_bg_rgba (text_tag, &rgba);
1434 g_warning ("Don't know color `%s'", g_value_get_string (value));
1436 g_object_notify (object, "paragraph-background-gdk");
1440 case PROP_PARAGRAPH_BACKGROUND_GDK:
1442 GdkColor *color = g_value_get_boxed (value);
1444 set_pg_bg_color (text_tag, color);
1448 case PROP_PARAGRAPH_BACKGROUND_RGBA:
1450 GdkRGBA *color = g_value_get_boxed (value);
1452 set_pg_bg_rgba (text_tag, color);
1456 case PROP_ACCUMULATIVE_MARGIN:
1457 priv->accumulative_margin = g_value_get_boolean (value);
1458 g_object_notify (object, "accumulative-margin");
1459 size_changed = TRUE;
1462 /* Whether the value should be used... */
1464 case PROP_BACKGROUND_SET:
1465 priv->bg_color_set = g_value_get_boolean (value);
1468 case PROP_FOREGROUND_SET:
1469 priv->fg_color_set = g_value_get_boolean (value);
1472 case PROP_FAMILY_SET:
1473 case PROP_STYLE_SET:
1474 case PROP_VARIANT_SET:
1475 case PROP_WEIGHT_SET:
1476 case PROP_STRETCH_SET:
1478 if (!g_value_get_boolean (value))
1480 if (priv->values->font)
1481 pango_font_description_unset_fields (priv->values->font,
1482 get_property_font_set_mask (prop_id));
1486 PangoFontMask changed_mask;
1488 gtk_text_tag_ensure_font (text_tag);
1489 changed_mask = set_font_desc_fields (priv->values->font,
1490 get_property_font_set_mask (prop_id));
1491 notify_fields_changed (G_OBJECT (text_tag), changed_mask);
1495 case PROP_SCALE_SET:
1496 priv->scale_set = g_value_get_boolean (value);
1497 size_changed = TRUE;
1500 case PROP_PIXELS_ABOVE_LINES_SET:
1501 priv->pixels_above_lines_set = g_value_get_boolean (value);
1502 size_changed = TRUE;
1505 case PROP_PIXELS_BELOW_LINES_SET:
1506 priv->pixels_below_lines_set = g_value_get_boolean (value);
1507 size_changed = TRUE;
1510 case PROP_PIXELS_INSIDE_WRAP_SET:
1511 priv->pixels_inside_wrap_set = g_value_get_boolean (value);
1512 size_changed = TRUE;
1515 case PROP_EDITABLE_SET:
1516 priv->editable_set = g_value_get_boolean (value);
1519 case PROP_WRAP_MODE_SET:
1520 priv->wrap_mode_set = g_value_get_boolean (value);
1521 size_changed = TRUE;
1524 case PROP_JUSTIFICATION_SET:
1525 priv->justification_set = g_value_get_boolean (value);
1526 size_changed = TRUE;
1529 case PROP_LEFT_MARGIN_SET:
1530 priv->left_margin_set = g_value_get_boolean (value);
1531 size_changed = TRUE;
1534 case PROP_INDENT_SET:
1535 priv->indent_set = g_value_get_boolean (value);
1536 size_changed = TRUE;
1539 case PROP_STRIKETHROUGH_SET:
1540 priv->strikethrough_set = g_value_get_boolean (value);
1543 case PROP_RIGHT_MARGIN_SET:
1544 priv->right_margin_set = g_value_get_boolean (value);
1545 size_changed = TRUE;
1548 case PROP_UNDERLINE_SET:
1549 priv->underline_set = g_value_get_boolean (value);
1553 priv->rise_set = g_value_get_boolean (value);
1554 size_changed = TRUE;
1557 case PROP_BACKGROUND_FULL_HEIGHT_SET:
1558 priv->bg_full_height_set = g_value_get_boolean (value);
1561 case PROP_LANGUAGE_SET:
1562 priv->language_set = g_value_get_boolean (value);
1563 size_changed = TRUE;
1567 priv->tabs_set = g_value_get_boolean (value);
1568 size_changed = TRUE;
1571 case PROP_INVISIBLE_SET:
1572 priv->invisible_set = g_value_get_boolean (value);
1573 size_changed = TRUE;
1576 case PROP_PARAGRAPH_BACKGROUND_SET:
1577 priv->pg_bg_color_set = g_value_get_boolean (value);
1581 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1585 /* FIXME I would like to do this after all set_property in a single
1586 * g_object_set () have been called. But an idle function won't
1587 * work; we need to emit when the tag is changed, not when we get
1588 * around to the event loop. So blah, we eat some inefficiency.
1591 /* This is also somewhat weird since we emit another object's
1592 * signal here, but the two objects are already tightly bound.
1596 g_signal_emit_by_name (priv->table,
1598 text_tag, size_changed);
1602 gtk_text_tag_get_property (GObject *object,
1607 GtkTextTag *tag = GTK_TEXT_TAG (object);
1608 GtkTextTagPrivate *priv = tag->priv;
1613 g_value_set_string (value, priv->name);
1616 case PROP_BACKGROUND_GDK:
1617 g_value_set_boxed (value, &priv->values->appearance.bg_color);
1620 case PROP_BACKGROUND_RGBA:
1621 g_value_set_boxed (value, priv->values->appearance.rgba[0]);
1624 case PROP_FOREGROUND_GDK:
1625 g_value_set_boxed (value, &priv->values->appearance.fg_color);
1628 case PROP_FOREGROUND_RGBA:
1629 g_value_set_boxed (value, priv->values->appearance.rgba[1]);
1636 gtk_text_tag_ensure_font (tag);
1638 str = pango_font_description_to_string (priv->values->font);
1639 g_value_take_string (value, str);
1643 case PROP_FONT_DESC:
1644 gtk_text_tag_ensure_font (tag);
1645 g_value_set_boxed (value, priv->values->font);
1654 case PROP_SIZE_POINTS:
1655 gtk_text_tag_ensure_font (tag);
1659 g_value_set_string (value, pango_font_description_get_family (priv->values->font));
1663 g_value_set_enum (value, pango_font_description_get_style (priv->values->font));
1667 g_value_set_enum (value, pango_font_description_get_variant (priv->values->font));
1671 g_value_set_int (value, pango_font_description_get_weight (priv->values->font));
1675 g_value_set_enum (value, pango_font_description_get_stretch (priv->values->font));
1679 g_value_set_int (value, pango_font_description_get_size (priv->values->font));
1682 case PROP_SIZE_POINTS:
1683 g_value_set_double (value, ((double)pango_font_description_get_size (priv->values->font)) / (double)PANGO_SCALE);
1689 g_value_set_double (value, priv->values->font_scale);
1692 case PROP_PIXELS_ABOVE_LINES:
1693 g_value_set_int (value, priv->values->pixels_above_lines);
1696 case PROP_PIXELS_BELOW_LINES:
1697 g_value_set_int (value, priv->values->pixels_below_lines);
1700 case PROP_PIXELS_INSIDE_WRAP:
1701 g_value_set_int (value, priv->values->pixels_inside_wrap);
1705 g_value_set_boolean (value, priv->values->editable);
1708 case PROP_WRAP_MODE:
1709 g_value_set_enum (value, priv->values->wrap_mode);
1712 case PROP_JUSTIFICATION:
1713 g_value_set_enum (value, priv->values->justification);
1716 case PROP_DIRECTION:
1717 g_value_set_enum (value, priv->values->direction);
1720 case PROP_LEFT_MARGIN:
1721 g_value_set_int (value, priv->values->left_margin);
1725 g_value_set_int (value, priv->values->indent);
1728 case PROP_STRIKETHROUGH:
1729 g_value_set_boolean (value, priv->values->appearance.strikethrough);
1732 case PROP_RIGHT_MARGIN:
1733 g_value_set_int (value, priv->values->right_margin);
1736 case PROP_UNDERLINE:
1737 g_value_set_enum (value, priv->values->appearance.underline);
1741 g_value_set_int (value, priv->values->appearance.rise);
1744 case PROP_BACKGROUND_FULL_HEIGHT:
1745 g_value_set_boolean (value, priv->values->bg_full_height);
1749 g_value_set_string (value, pango_language_to_string (priv->values->language));
1753 if (priv->values->tabs)
1754 g_value_set_boxed (value, priv->values->tabs);
1757 case PROP_INVISIBLE:
1758 g_value_set_boolean (value, priv->values->invisible);
1761 case PROP_PARAGRAPH_BACKGROUND_GDK:
1762 g_value_set_boxed (value, priv->values->pg_bg_color);
1765 case PROP_PARAGRAPH_BACKGROUND_RGBA:
1766 g_value_set_boxed (value, priv->values->pg_bg_rgba);
1769 case PROP_ACCUMULATIVE_MARGIN:
1770 g_value_set_boolean (value, priv->accumulative_margin);
1773 case PROP_BACKGROUND_SET:
1774 g_value_set_boolean (value, priv->bg_color_set);
1777 case PROP_FOREGROUND_SET:
1778 g_value_set_boolean (value, priv->fg_color_set);
1781 case PROP_FAMILY_SET:
1782 case PROP_STYLE_SET:
1783 case PROP_VARIANT_SET:
1784 case PROP_WEIGHT_SET:
1785 case PROP_STRETCH_SET:
1788 PangoFontMask set_mask = priv->values->font ? pango_font_description_get_set_fields (priv->values->font) : 0;
1789 PangoFontMask test_mask = get_property_font_set_mask (prop_id);
1790 g_value_set_boolean (value, (set_mask & test_mask) != 0);
1795 case PROP_SCALE_SET:
1796 g_value_set_boolean (value, priv->scale_set);
1799 case PROP_PIXELS_ABOVE_LINES_SET:
1800 g_value_set_boolean (value, priv->pixels_above_lines_set);
1803 case PROP_PIXELS_BELOW_LINES_SET:
1804 g_value_set_boolean (value, priv->pixels_below_lines_set);
1807 case PROP_PIXELS_INSIDE_WRAP_SET:
1808 g_value_set_boolean (value, priv->pixels_inside_wrap_set);
1811 case PROP_EDITABLE_SET:
1812 g_value_set_boolean (value, priv->editable_set);
1815 case PROP_WRAP_MODE_SET:
1816 g_value_set_boolean (value, priv->wrap_mode_set);
1819 case PROP_JUSTIFICATION_SET:
1820 g_value_set_boolean (value, priv->justification_set);
1823 case PROP_LEFT_MARGIN_SET:
1824 g_value_set_boolean (value, priv->left_margin_set);
1827 case PROP_INDENT_SET:
1828 g_value_set_boolean (value, priv->indent_set);
1831 case PROP_STRIKETHROUGH_SET:
1832 g_value_set_boolean (value, priv->strikethrough_set);
1835 case PROP_RIGHT_MARGIN_SET:
1836 g_value_set_boolean (value, priv->right_margin_set);
1839 case PROP_UNDERLINE_SET:
1840 g_value_set_boolean (value, priv->underline_set);
1844 g_value_set_boolean (value, priv->rise_set);
1847 case PROP_BACKGROUND_FULL_HEIGHT_SET:
1848 g_value_set_boolean (value, priv->bg_full_height_set);
1851 case PROP_LANGUAGE_SET:
1852 g_value_set_boolean (value, priv->language_set);
1856 g_value_set_boolean (value, priv->tabs_set);
1859 case PROP_INVISIBLE_SET:
1860 g_value_set_boolean (value, priv->invisible_set);
1863 case PROP_PARAGRAPH_BACKGROUND_SET:
1864 g_value_set_boolean (value, priv->pg_bg_color_set);
1867 case PROP_BACKGROUND:
1868 case PROP_FOREGROUND:
1869 case PROP_PARAGRAPH_BACKGROUND:
1870 g_warning ("'foreground', 'background' and 'paragraph_background' properties are not readable, use 'foreground_gdk', 'background_gdk' and 'paragraph_background_gdk'");
1873 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1889 delta_priority_foreach (GtkTextTag *tag, gpointer user_data)
1891 GtkTextTagPrivate *priv = tag->priv;
1892 DeltaData *dd = user_data;
1894 if (priv->priority >= dd->low && priv->priority <= dd->high)
1895 priv->priority += dd->delta;
1899 * gtk_text_tag_get_priority:
1900 * @tag: a #GtkTextTag
1902 * Get the tag priority.
1904 * Return value: The tag's priority.
1907 gtk_text_tag_get_priority (GtkTextTag *tag)
1909 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), 0);
1911 return tag->priv->priority;
1915 * gtk_text_tag_set_priority:
1916 * @tag: a #GtkTextTag
1917 * @priority: the new priority
1919 * Sets the priority of a #GtkTextTag. Valid priorities are
1920 * start at 0 and go to one less than gtk_text_tag_table_get_size().
1921 * Each tag in a table has a unique priority; setting the priority
1922 * of one tag shifts the priorities of all the other tags in the
1923 * table to maintain a unique priority for each tag. Higher priority
1924 * tags "win" if two tags both set the same text attribute. When adding
1925 * a tag to a tag table, it will be assigned the highest priority in
1926 * the table by default; so normally the precedence of a set of tags
1927 * is the order in which they were added to the table, or created with
1928 * gtk_text_buffer_create_tag(), which adds the tag to the buffer's table
1932 gtk_text_tag_set_priority (GtkTextTag *tag,
1935 GtkTextTagPrivate *priv;
1938 g_return_if_fail (GTK_IS_TEXT_TAG (tag));
1942 g_return_if_fail (priv->table != NULL);
1943 g_return_if_fail (priority >= 0);
1944 g_return_if_fail (priority < gtk_text_tag_table_get_size (priv->table));
1946 if (priority == priv->priority)
1949 if (priority < priv->priority)
1952 dd.high = priv->priority - 1;
1957 dd.low = priv->priority + 1;
1962 gtk_text_tag_table_foreach (priv->table,
1963 delta_priority_foreach,
1966 priv->priority = priority;
1970 * gtk_text_tag_event:
1971 * @tag: a #GtkTextTag
1972 * @event_object: object that received the event, such as a widget
1974 * @iter: location where the event was received
1976 * Emits the "event" signal on the #GtkTextTag.
1978 * Return value: result of signal emission (whether the event was handled)
1981 gtk_text_tag_event (GtkTextTag *tag,
1982 GObject *event_object,
1984 const GtkTextIter *iter)
1986 gboolean retval = FALSE;
1988 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
1989 g_return_val_if_fail (G_IS_OBJECT (event_object), FALSE);
1990 g_return_val_if_fail (event != NULL, FALSE);
2004 tag_sort_func (gconstpointer first, gconstpointer second)
2006 GtkTextTag *tag1, *tag2;
2008 tag1 = * (GtkTextTag **) first;
2009 tag2 = * (GtkTextTag **) second;
2010 return tag1->priv->priority - tag2->priv->priority;
2014 _gtk_text_tag_array_sort (GtkTextTag** tag_array_p,
2019 GtkTextTag **maxPtrPtr, *tmp;
2021 g_return_if_fail (tag_array_p != NULL);
2022 g_return_if_fail (len > 0);
2028 GtkTextTag **iter = tag_array_p;
2030 for (i = len-1; i > 0; i--, iter++) {
2031 maxPtrPtr = tag = iter;
2032 prio = tag[0]->priv->priority;
2033 for (j = i, tag++; j > 0; j--, tag++) {
2034 if (tag[0]->priv->priority < prio) {
2035 prio = tag[0]->priv->priority;
2044 qsort ((void *) tag_array_p, (unsigned) len, sizeof (GtkTextTag *),
2050 printf ("Sorted tag array: \n");
2054 GtkTextTag *t = tag_array_p[i];
2055 printf (" %s priority %d\n", t->name, t->priority);