1 /* gtktexttag.c - text tag object
3 * Copyright (c) 1992-1994 The Regents of the University of California.
4 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
5 * Copyright (c) 2000 Red Hat, Inc.
6 * Tk -> Gtk port by Havoc Pennington <hp@redhat.com>
8 * This software is copyrighted by the Regents of the University of
9 * California, Sun Microsystems, Inc., and other parties. The
10 * following terms apply to all files associated with the software
11 * unless explicitly disclaimed in individual files.
13 * The authors hereby grant permission to use, copy, modify,
14 * distribute, and license this software and its documentation for any
15 * purpose, provided that existing copyright notices are retained in
16 * all copies and that this notice is included verbatim in any
17 * distributions. No written agreement, license, or royalty fee is
18 * required for any of the authorized uses. Modifications to this
19 * software may be copyrighted by their authors and need not follow
20 * the licensing terms described here, provided that the new terms are
21 * clearly indicated on the first page of each file where they apply.
23 * IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY
24 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
25 * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION,
26 * OR ANY DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED
27 * OF THE POSSIBILITY OF SUCH DAMAGE.
29 * THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
30 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
31 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
32 * NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS,
33 * AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
34 * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
36 * GOVERNMENT USE: If you are acquiring this software on behalf of the
37 * U.S. government, the Government shall have only "Restricted Rights"
38 * in the software and related documentation as defined in the Federal
39 * Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you
40 * are acquiring the software on behalf of the Department of Defense,
41 * the software shall be classified as "Commercial Computer Software"
42 * and the Government shall have only "Restricted Rights" as defined
43 * in Clause 252.227-7013 (c) (1) of DFARs. Notwithstanding the
44 * foregoing, the authors grant the U.S. Government and others acting
45 * in its behalf permission to use and distribute the software in
46 * accordance with the terms specified in this license.
53 * @Short_description: A tag that can be applied to text in a GtkTextBuffer
55 * You may wish to begin by reading the <link linkend="TextWidget">text widget
56 * conceptual overview</link> which gives an overview of all the objects and
57 * data types related to the text widget and how they work together.
59 * Tags should be in the #GtkTextTagTable for a given #GtkTextBuffer
60 * before using them with that buffer.
62 * gtk_text_buffer_create_tag() is the best way to create tags.
63 * See <application>gtk3-demo</application> for numerous examples.
71 #include "gtkmainprivate.h"
72 #include "gtktexttag.h"
73 #include "gtktexttypes.h"
74 #include "gtktexttagtable.h"
76 #include "gtkmarshalers.h"
77 #include "gtkprivate.h"
78 #include "gtktypebuiltins.h"
107 PROP_PIXELS_ABOVE_LINES,
108 PROP_PIXELS_BELOW_LINES,
109 PROP_PIXELS_INSIDE_WRAP,
120 PROP_BACKGROUND_FULL_HEIGHT,
124 PROP_PARAGRAPH_BACKGROUND,
125 PROP_PARAGRAPH_BACKGROUND_GDK,
126 PROP_PARAGRAPH_BACKGROUND_RGBA,
129 PROP_ACCUMULATIVE_MARGIN,
131 /* Whether-a-style-arg-is-set args */
141 PROP_PIXELS_ABOVE_LINES_SET,
142 PROP_PIXELS_BELOW_LINES_SET,
143 PROP_PIXELS_INSIDE_WRAP_SET,
146 PROP_JUSTIFICATION_SET,
147 PROP_LEFT_MARGIN_SET,
149 PROP_STRIKETHROUGH_SET,
150 PROP_RIGHT_MARGIN_SET,
153 PROP_BACKGROUND_FULL_HEIGHT_SET,
157 PROP_PARAGRAPH_BACKGROUND_SET,
161 static void gtk_text_tag_finalize (GObject *object);
162 static void gtk_text_tag_set_property (GObject *object,
166 static void gtk_text_tag_get_property (GObject *object,
171 static guint signals[LAST_SIGNAL] = { 0 };
173 G_DEFINE_TYPE (GtkTextTag, gtk_text_tag, G_TYPE_OBJECT)
176 gtk_text_tag_class_init (GtkTextTagClass *klass)
178 GObjectClass *object_class = G_OBJECT_CLASS (klass);
180 object_class->set_property = gtk_text_tag_set_property;
181 object_class->get_property = gtk_text_tag_get_property;
183 object_class->finalize = gtk_text_tag_finalize;
186 g_object_class_install_property (object_class,
188 g_param_spec_string ("name",
190 P_("Name used to refer to the text tag. NULL for anonymous tags"),
192 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
196 g_object_class_install_property (object_class,
198 g_param_spec_string ("background",
199 P_("Background color name"),
200 P_("Background color as a string"),
202 GTK_PARAM_WRITABLE));
204 g_object_class_install_property (object_class,
206 g_param_spec_boxed ("background-gdk",
207 P_("Background color"),
208 P_("Background color as a GdkColor"),
210 GTK_PARAM_READWRITE));
213 * GtkTextTag:background-rgba:
215 * Background color as a #GdkRGBA.
219 g_object_class_install_property (object_class,
220 PROP_BACKGROUND_RGBA,
221 g_param_spec_boxed ("background-rgba",
222 P_("Background rgba"),
223 P_("Background color as a GdkRGBA"),
225 GTK_PARAM_READWRITE));
227 g_object_class_install_property (object_class,
228 PROP_BACKGROUND_FULL_HEIGHT,
229 g_param_spec_boolean ("background-full-height",
230 P_("Background full height"),
231 P_("Whether the background color fills the entire line height or only the height of the tagged characters"),
233 GTK_PARAM_READWRITE));
235 g_object_class_install_property (object_class,
237 g_param_spec_string ("foreground",
238 P_("Foreground color name"),
239 P_("Foreground color as a string"),
241 GTK_PARAM_WRITABLE));
243 g_object_class_install_property (object_class,
245 g_param_spec_boxed ("foreground-gdk",
246 P_("Foreground color"),
247 P_("Foreground color as a GdkColor"),
249 GTK_PARAM_READWRITE));
252 * GtkTextTag:foreground-rgba:
254 * Foreground color as a #GdkRGBA.
258 g_object_class_install_property (object_class,
259 PROP_FOREGROUND_RGBA,
260 g_param_spec_boxed ("foreground-rgba",
261 P_("Foreground rgba"),
262 P_("Foreground color as a GdkRGBA"),
264 GTK_PARAM_READWRITE));
266 g_object_class_install_property (object_class,
268 g_param_spec_enum ("direction",
269 P_("Text direction"),
270 P_("Text direction, e.g. right-to-left or left-to-right"),
271 GTK_TYPE_TEXT_DIRECTION,
273 GTK_PARAM_READWRITE));
275 g_object_class_install_property (object_class,
277 g_param_spec_boolean ("editable",
279 P_("Whether the text can be modified by the user"),
281 GTK_PARAM_READWRITE));
286 * Font description as string, e.g. \"Sans Italic 12\".
288 * Note that the initial value of this property depends on
289 * the internals of #PangoFontDescription.
291 g_object_class_install_property (object_class,
293 g_param_spec_string ("font",
295 P_("Font description as a string, e.g. \"Sans Italic 12\""),
297 GTK_PARAM_READWRITE));
299 g_object_class_install_property (object_class,
301 g_param_spec_boxed ("font-desc",
303 P_("Font description as a PangoFontDescription struct"),
304 PANGO_TYPE_FONT_DESCRIPTION,
305 GTK_PARAM_READWRITE));
307 g_object_class_install_property (object_class,
309 g_param_spec_string ("family",
311 P_("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
313 GTK_PARAM_READWRITE));
315 g_object_class_install_property (object_class,
317 g_param_spec_enum ("style",
319 P_("Font style as a PangoStyle, e.g. PANGO_STYLE_ITALIC"),
322 GTK_PARAM_READWRITE));
324 g_object_class_install_property (object_class,
326 g_param_spec_enum ("variant",
328 P_("Font variant as a PangoVariant, e.g. PANGO_VARIANT_SMALL_CAPS"),
330 PANGO_VARIANT_NORMAL,
331 GTK_PARAM_READWRITE));
333 g_object_class_install_property (object_class,
335 g_param_spec_int ("weight",
337 P_("Font weight as an integer, see predefined values in PangoWeight; for example, PANGO_WEIGHT_BOLD"),
341 GTK_PARAM_READWRITE));
344 g_object_class_install_property (object_class,
346 g_param_spec_enum ("stretch",
348 P_("Font stretch as a PangoStretch, e.g. PANGO_STRETCH_CONDENSED"),
350 PANGO_STRETCH_NORMAL,
351 GTK_PARAM_READWRITE));
353 g_object_class_install_property (object_class,
355 g_param_spec_int ("size",
357 P_("Font size in Pango units"),
361 GTK_PARAM_READWRITE));
363 g_object_class_install_property (object_class,
365 g_param_spec_double ("scale",
367 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"),
371 GTK_PARAM_READWRITE));
373 g_object_class_install_property (object_class,
375 g_param_spec_double ("size-points",
377 P_("Font size in points"),
381 GTK_PARAM_READWRITE));
383 g_object_class_install_property (object_class,
385 g_param_spec_enum ("justification",
387 P_("Left, right, or center justification"),
388 GTK_TYPE_JUSTIFICATION,
390 GTK_PARAM_READWRITE));
393 * GtkTextTag:language:
395 * The language this text is in, as an ISO code. Pango can use this as a
396 * hint when rendering the text. If not set, an appropriate default will be
399 * Note that the initial value of this property depends on the current
400 * locale, see also gtk_get_default_language().
402 g_object_class_install_property (object_class,
404 g_param_spec_string ("language",
406 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."),
408 GTK_PARAM_READWRITE));
410 g_object_class_install_property (object_class,
412 g_param_spec_int ("left-margin",
414 P_("Width of the left margin in pixels"),
418 GTK_PARAM_READWRITE));
420 g_object_class_install_property (object_class,
422 g_param_spec_int ("right-margin",
424 P_("Width of the right margin in pixels"),
428 GTK_PARAM_READWRITE));
431 g_object_class_install_property (object_class,
433 g_param_spec_int ("indent",
435 P_("Amount to indent the paragraph, in pixels"),
439 GTK_PARAM_READWRITE));
442 g_object_class_install_property (object_class,
444 g_param_spec_int ("rise",
446 P_("Offset of text above the baseline (below the baseline if rise is negative) in Pango units"),
450 GTK_PARAM_READWRITE));
452 g_object_class_install_property (object_class,
453 PROP_PIXELS_ABOVE_LINES,
454 g_param_spec_int ("pixels-above-lines",
455 P_("Pixels above lines"),
456 P_("Pixels of blank space above paragraphs"),
460 GTK_PARAM_READWRITE));
462 g_object_class_install_property (object_class,
463 PROP_PIXELS_BELOW_LINES,
464 g_param_spec_int ("pixels-below-lines",
465 P_("Pixels below lines"),
466 P_("Pixels of blank space below paragraphs"),
470 GTK_PARAM_READWRITE));
472 g_object_class_install_property (object_class,
473 PROP_PIXELS_INSIDE_WRAP,
474 g_param_spec_int ("pixels-inside-wrap",
475 P_("Pixels inside wrap"),
476 P_("Pixels of blank space between wrapped lines in a paragraph"),
480 GTK_PARAM_READWRITE));
482 g_object_class_install_property (object_class,
484 g_param_spec_boolean ("strikethrough",
486 P_("Whether to strike through the text"),
488 GTK_PARAM_READWRITE));
490 g_object_class_install_property (object_class,
492 g_param_spec_enum ("underline",
494 P_("Style of underline for this text"),
495 PANGO_TYPE_UNDERLINE,
496 PANGO_UNDERLINE_NONE,
497 GTK_PARAM_READWRITE));
499 g_object_class_install_property (object_class,
501 g_param_spec_enum ("wrap-mode",
503 P_("Whether to wrap lines never, at word boundaries, or at character boundaries"),
506 GTK_PARAM_READWRITE));
509 g_object_class_install_property (object_class,
511 g_param_spec_boxed ("tabs",
513 P_("Custom tabs for this text"),
514 PANGO_TYPE_TAB_ARRAY,
515 GTK_PARAM_READWRITE));
518 * GtkTextTag:invisible:
520 * Whether this text is hidden.
522 * Note that there may still be problems with the support for invisible
523 * text, in particular when navigating programmatically inside a buffer
524 * containing invisible segments.
528 g_object_class_install_property (object_class,
530 g_param_spec_boolean ("invisible",
532 P_("Whether this text is hidden."),
534 GTK_PARAM_READWRITE));
537 * GtkTextTag:paragraph-background:
539 * The paragraph background color as a string.
543 g_object_class_install_property (object_class,
544 PROP_PARAGRAPH_BACKGROUND,
545 g_param_spec_string ("paragraph-background",
546 P_("Paragraph background color name"),
547 P_("Paragraph background color as a string"),
549 GTK_PARAM_WRITABLE));
552 * GtkTextTag:paragraph-background-gdk:
554 * The paragraph background color as a as a #GdkColor.
558 g_object_class_install_property (object_class,
559 PROP_PARAGRAPH_BACKGROUND_GDK,
560 g_param_spec_boxed ("paragraph-background-gdk",
561 P_("Paragraph background color"),
562 P_("Paragraph background color as a GdkColor"),
564 GTK_PARAM_READWRITE));
567 * GtkTextTag:paragraph-background-rgba:
569 * The paragraph background color as a as a #GdkRGBA.
573 g_object_class_install_property (object_class,
574 PROP_PARAGRAPH_BACKGROUND_RGBA,
575 g_param_spec_boxed ("paragraph-background-rgba",
576 P_("Paragraph background rgba"),
577 P_("Paragraph background rgba as a GdkRGBA"),
579 GTK_PARAM_READWRITE));
582 * GtkTextTag:accumulative-margin:
584 * Whether the margins accumulate or override each other.
586 * When set to %TRUE the margins of this tag are added to the margins
587 * of any other non-accumulative margins present. When set to %FALSE
588 * the margins override one another (the default).
592 g_object_class_install_property (object_class,
593 PROP_ACCUMULATIVE_MARGIN,
594 g_param_spec_boolean ("accumulative-margin",
595 P_("Margin Accumulates"),
596 P_("Whether left and right margins accumulate."),
598 GTK_PARAM_READWRITE));
600 /* Style props are set or not */
602 #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))
604 ADD_SET_PROP ("background-set", PROP_BACKGROUND_SET,
605 P_("Background set"),
606 P_("Whether this tag affects the background color"));
608 ADD_SET_PROP ("background-full-height-set", PROP_BACKGROUND_FULL_HEIGHT_SET,
609 P_("Background full height set"),
610 P_("Whether this tag affects background height"));
612 ADD_SET_PROP ("foreground-set", PROP_FOREGROUND_SET,
613 P_("Foreground set"),
614 P_("Whether this tag affects the foreground color"));
616 ADD_SET_PROP ("editable-set", PROP_EDITABLE_SET,
617 P_("Editability set"),
618 P_("Whether this tag affects text editability"));
620 ADD_SET_PROP ("family-set", PROP_FAMILY_SET,
621 P_("Font family set"),
622 P_("Whether this tag affects the font family"));
624 ADD_SET_PROP ("style-set", PROP_STYLE_SET,
625 P_("Font style set"),
626 P_("Whether this tag affects the font style"));
628 ADD_SET_PROP ("variant-set", PROP_VARIANT_SET,
629 P_("Font variant set"),
630 P_("Whether this tag affects the font variant"));
632 ADD_SET_PROP ("weight-set", PROP_WEIGHT_SET,
633 P_("Font weight set"),
634 P_("Whether this tag affects the font weight"));
636 ADD_SET_PROP ("stretch-set", PROP_STRETCH_SET,
637 P_("Font stretch set"),
638 P_("Whether this tag affects the font stretch"));
640 ADD_SET_PROP ("size-set", PROP_SIZE_SET,
642 P_("Whether this tag affects the font size"));
644 ADD_SET_PROP ("scale-set", PROP_SCALE_SET,
645 P_("Font scale set"),
646 P_("Whether this tag scales the font size by a factor"));
648 ADD_SET_PROP ("justification-set", PROP_JUSTIFICATION_SET,
649 P_("Justification set"),
650 P_("Whether this tag affects paragraph justification"));
652 ADD_SET_PROP ("language-set", PROP_LANGUAGE_SET,
654 P_("Whether this tag affects the language the text is rendered as"));
656 ADD_SET_PROP ("left-margin-set", PROP_LEFT_MARGIN_SET,
657 P_("Left margin set"),
658 P_("Whether this tag affects the left margin"));
660 ADD_SET_PROP ("indent-set", PROP_INDENT_SET,
662 P_("Whether this tag affects indentation"));
664 ADD_SET_PROP ("rise-set", PROP_RISE_SET,
666 P_("Whether this tag affects the rise"));
668 ADD_SET_PROP ("pixels-above-lines-set", PROP_PIXELS_ABOVE_LINES_SET,
669 P_("Pixels above lines set"),
670 P_("Whether this tag affects the number of pixels above lines"));
672 ADD_SET_PROP ("pixels-below-lines-set", PROP_PIXELS_BELOW_LINES_SET,
673 P_("Pixels below lines set"),
674 P_("Whether this tag affects the number of pixels above lines"));
676 ADD_SET_PROP ("pixels-inside-wrap-set", PROP_PIXELS_INSIDE_WRAP_SET,
677 P_("Pixels inside wrap set"),
678 P_("Whether this tag affects the number of pixels between wrapped lines"));
680 ADD_SET_PROP ("strikethrough-set", PROP_STRIKETHROUGH_SET,
681 P_("Strikethrough set"),
682 P_("Whether this tag affects strikethrough"));
684 ADD_SET_PROP ("right-margin-set", PROP_RIGHT_MARGIN_SET,
685 P_("Right margin set"),
686 P_("Whether this tag affects the right margin"));
688 ADD_SET_PROP ("underline-set", PROP_UNDERLINE_SET,
690 P_("Whether this tag affects underlining"));
692 ADD_SET_PROP ("wrap-mode-set", PROP_WRAP_MODE_SET,
694 P_("Whether this tag affects line wrap mode"));
696 ADD_SET_PROP ("tabs-set", PROP_TABS_SET,
698 P_("Whether this tag affects tabs"));
700 ADD_SET_PROP ("invisible-set", PROP_INVISIBLE_SET,
702 P_("Whether this tag affects text visibility"));
704 ADD_SET_PROP ("paragraph-background-set", PROP_PARAGRAPH_BACKGROUND_SET,
705 P_("Paragraph background set"),
706 P_("Whether this tag affects the paragraph background color"));
710 * @tag: the #GtkTextTag on which the signal is emitted
711 * @object: the object the event was fired from (typically a #GtkTextView)
712 * @event: the event which triggered the signal
713 * @iter: a #GtkTextIter pointing at the location the event occured
715 * The ::event signal is emitted when an event occurs on a region of the
716 * buffer marked with this tag.
718 * Returns: %TRUE to stop other handlers from being invoked for the
719 * event. %FALSE to propagate the event further.
722 g_signal_new (I_("event"),
723 G_OBJECT_CLASS_TYPE (object_class),
725 G_STRUCT_OFFSET (GtkTextTagClass, event),
726 _gtk_boolean_handled_accumulator, NULL,
727 _gtk_marshal_BOOLEAN__OBJECT_BOXED_BOXED,
731 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE,
734 g_type_class_add_private (klass, sizeof (GtkTextTagPrivate));
738 gtk_text_tag_init (GtkTextTag *text_tag)
740 GtkTextTagPrivate *priv;
742 text_tag->priv = G_TYPE_INSTANCE_GET_PRIVATE (text_tag,
745 priv = text_tag->priv;
747 priv->values = gtk_text_attributes_new ();
752 * @name: (allow-none): tag name, or %NULL
754 * Creates a #GtkTextTag. Configure the tag using object arguments,
755 * i.e. using g_object_set().
757 * Return value: a new #GtkTextTag
760 gtk_text_tag_new (const gchar *name)
764 tag = g_object_new (GTK_TYPE_TEXT_TAG, "name", name, NULL);
770 gtk_text_tag_finalize (GObject *object)
772 GtkTextTag *text_tag = GTK_TEXT_TAG (object);
773 GtkTextTagPrivate *priv = text_tag->priv;
776 gtk_text_tag_table_remove (priv->table, text_tag);
778 g_assert (priv->table == NULL);
780 gtk_text_attributes_unref (priv->values);
786 G_OBJECT_CLASS (gtk_text_tag_parent_class)->finalize (object);
790 copy_rgba_to_gdk_color (GdkRGBA *src,
793 dest->red = CLAMP (src->red, 0.0, 1.0) * 65535.0;
794 dest->green = CLAMP (src->green, 0.0, 1.0) * 65535.0;
795 dest->blue = CLAMP (src->blue, 0.0, 1.0) * 65535.0;
799 copy_gdk_color_to_rgba (GdkColor *src,
802 dest->red = src->red / 65535.;
803 dest->green = src->green / 65535.;
804 dest->blue = src->blue / 65535.;
809 set_bg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
811 GtkTextTagPrivate *priv = tag->priv;
813 if (priv->values->appearance.rgba[0])
814 gdk_rgba_free (priv->values->appearance.rgba[0]);
816 priv->values->appearance.rgba[0] = NULL;
820 if (!priv->bg_color_set)
822 priv->bg_color_set = TRUE;
823 g_object_notify (G_OBJECT (tag), "background-set");
826 priv->values->appearance.rgba[0] = gdk_rgba_copy (rgba);
828 copy_rgba_to_gdk_color (rgba, &priv->values->appearance.bg_color);
832 if (priv->bg_color_set)
834 priv->bg_color_set = FALSE;
835 g_object_notify (G_OBJECT (tag), "background-set");
841 set_fg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
843 GtkTextTagPrivate *priv = tag->priv;
845 if (priv->values->appearance.rgba[1])
846 gdk_rgba_free (priv->values->appearance.rgba[1]);
848 priv->values->appearance.rgba[1] = NULL;
852 if (!priv->fg_color_set)
854 priv->fg_color_set = TRUE;
855 g_object_notify (G_OBJECT (tag), "foreground-set");
858 priv->values->appearance.rgba[1] = gdk_rgba_copy (rgba);
860 copy_rgba_to_gdk_color (rgba, &priv->values->appearance.fg_color);
864 if (priv->fg_color_set)
866 priv->fg_color_set = FALSE;
867 g_object_notify (G_OBJECT (tag), "foreground-set");
873 set_pg_bg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
875 GtkTextTagPrivate *priv = tag->priv;
877 if (priv->values->pg_bg_rgba)
878 gdk_rgba_free (priv->values->pg_bg_rgba);
880 if (priv->values->pg_bg_color)
881 gdk_color_free (priv->values->pg_bg_color);
883 priv->values->pg_bg_rgba = NULL;
884 priv->values->pg_bg_color = NULL;
888 GdkColor color = { 0, };
890 if (!priv->pg_bg_color_set)
892 priv->pg_bg_color_set = TRUE;
893 g_object_notify (G_OBJECT (tag), "paragraph-background-set");
896 priv->values->pg_bg_rgba = gdk_rgba_copy (rgba);
898 copy_rgba_to_gdk_color (rgba, &color);
899 priv->values->pg_bg_color = gdk_color_copy (&color);
903 if (priv->pg_bg_color_set)
905 priv->pg_bg_color_set = FALSE;
906 g_object_notify (G_OBJECT (tag), "paragraph-background-set");
913 set_bg_color (GtkTextTag *tag, GdkColor *color)
919 copy_gdk_color_to_rgba (color, &rgba);
920 set_bg_rgba (tag, &rgba);
923 set_bg_rgba (tag, NULL);
927 set_fg_color (GtkTextTag *tag, GdkColor *color)
933 copy_gdk_color_to_rgba (color, &rgba);
934 set_fg_rgba (tag, &rgba);
937 set_fg_rgba (tag, NULL);
941 set_pg_bg_color (GtkTextTag *tag, GdkColor *color)
947 copy_gdk_color_to_rgba (color, &rgba);
948 set_pg_bg_rgba (tag, &rgba);
951 set_pg_bg_rgba (tag, NULL);
955 get_property_font_set_mask (guint prop_id)
959 case PROP_FAMILY_SET:
960 return PANGO_FONT_MASK_FAMILY;
962 return PANGO_FONT_MASK_STYLE;
963 case PROP_VARIANT_SET:
964 return PANGO_FONT_MASK_VARIANT;
965 case PROP_WEIGHT_SET:
966 return PANGO_FONT_MASK_WEIGHT;
967 case PROP_STRETCH_SET:
968 return PANGO_FONT_MASK_STRETCH;
970 return PANGO_FONT_MASK_SIZE;
977 set_font_desc_fields (PangoFontDescription *desc,
978 PangoFontMask to_set)
980 PangoFontMask changed_mask = 0;
982 if (to_set & PANGO_FONT_MASK_FAMILY)
984 const char *family = pango_font_description_get_family (desc);
988 changed_mask |= PANGO_FONT_MASK_FAMILY;
991 pango_font_description_set_family (desc, family);
993 if (to_set & PANGO_FONT_MASK_STYLE)
994 pango_font_description_set_style (desc, pango_font_description_get_style (desc));
995 if (to_set & PANGO_FONT_MASK_VARIANT)
996 pango_font_description_set_variant (desc, pango_font_description_get_variant (desc));
997 if (to_set & PANGO_FONT_MASK_WEIGHT)
998 pango_font_description_set_weight (desc, pango_font_description_get_weight (desc));
999 if (to_set & PANGO_FONT_MASK_STRETCH)
1000 pango_font_description_set_stretch (desc, pango_font_description_get_stretch (desc));
1001 if (to_set & PANGO_FONT_MASK_SIZE)
1003 gint size = pango_font_description_get_size (desc);
1006 size = 10 * PANGO_SCALE;
1007 changed_mask |= PANGO_FONT_MASK_SIZE;
1010 pango_font_description_set_size (desc, size);
1013 return changed_mask;
1017 notify_set_changed (GObject *object,
1018 PangoFontMask changed_mask)
1020 if (changed_mask & PANGO_FONT_MASK_FAMILY)
1021 g_object_notify (object, "family-set");
1022 if (changed_mask & PANGO_FONT_MASK_STYLE)
1023 g_object_notify (object, "style-set");
1024 if (changed_mask & PANGO_FONT_MASK_VARIANT)
1025 g_object_notify (object, "variant-set");
1026 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
1027 g_object_notify (object, "weight-set");
1028 if (changed_mask & PANGO_FONT_MASK_STRETCH)
1029 g_object_notify (object, "stretch-set");
1030 if (changed_mask & PANGO_FONT_MASK_SIZE)
1031 g_object_notify (object, "size-set");
1035 notify_fields_changed (GObject *object,
1036 PangoFontMask changed_mask)
1038 if (changed_mask & PANGO_FONT_MASK_FAMILY)
1039 g_object_notify (object, "family");
1040 if (changed_mask & PANGO_FONT_MASK_STYLE)
1041 g_object_notify (object, "style");
1042 if (changed_mask & PANGO_FONT_MASK_VARIANT)
1043 g_object_notify (object, "variant");
1044 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
1045 g_object_notify (object, "weight");
1046 if (changed_mask & PANGO_FONT_MASK_STRETCH)
1047 g_object_notify (object, "stretch");
1048 if (changed_mask & PANGO_FONT_MASK_SIZE)
1049 g_object_notify (object, "size");
1053 set_font_description (GtkTextTag *text_tag,
1054 PangoFontDescription *font_desc)
1056 GtkTextTagPrivate *priv = text_tag->priv;
1057 GObject *object = G_OBJECT (text_tag);
1058 PangoFontDescription *new_font_desc;
1059 PangoFontMask old_mask, new_mask, changed_mask, set_changed_mask;
1062 new_font_desc = pango_font_description_copy (font_desc);
1064 new_font_desc = pango_font_description_new ();
1066 if (priv->values->font)
1067 old_mask = pango_font_description_get_set_fields (priv->values->font);
1071 new_mask = pango_font_description_get_set_fields (new_font_desc);
1073 changed_mask = old_mask | new_mask;
1074 set_changed_mask = old_mask ^ new_mask;
1076 if (priv->values->font)
1077 pango_font_description_free (priv->values->font);
1078 priv->values->font = new_font_desc;
1080 g_object_freeze_notify (object);
1082 g_object_notify (object, "font-desc");
1083 g_object_notify (object, "font");
1085 if (changed_mask & PANGO_FONT_MASK_FAMILY)
1086 g_object_notify (object, "family");
1087 if (changed_mask & PANGO_FONT_MASK_STYLE)
1088 g_object_notify (object, "style");
1089 if (changed_mask & PANGO_FONT_MASK_VARIANT)
1090 g_object_notify (object, "variant");
1091 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
1092 g_object_notify (object, "weight");
1093 if (changed_mask & PANGO_FONT_MASK_STRETCH)
1094 g_object_notify (object, "stretch");
1095 if (changed_mask & PANGO_FONT_MASK_SIZE)
1097 g_object_notify (object, "size");
1098 g_object_notify (object, "size-points");
1101 notify_set_changed (object, set_changed_mask);
1103 g_object_thaw_notify (object);
1107 gtk_text_tag_ensure_font (GtkTextTag *text_tag)
1109 GtkTextTagPrivate *priv = text_tag->priv;
1111 if (!priv->values->font)
1112 priv->values->font = pango_font_description_new ();
1116 gtk_text_tag_set_property (GObject *object,
1118 const GValue *value,
1121 GtkTextTag *text_tag = GTK_TEXT_TAG (object);
1122 GtkTextTagPrivate *priv = text_tag->priv;
1123 gboolean size_changed = FALSE;
1128 g_return_if_fail (priv->name == NULL);
1129 priv->name = g_value_dup_string (value);
1132 case PROP_BACKGROUND:
1136 if (!g_value_get_string (value))
1137 set_bg_rgba (text_tag, NULL); /* reset background_set to FALSE */
1138 else if (gdk_rgba_parse (&rgba, g_value_get_string (value)))
1139 set_bg_rgba (text_tag, &rgba);
1141 g_warning ("Don't know color `%s'", g_value_get_string (value));
1143 g_object_notify (object, "background-gdk");
1147 case PROP_FOREGROUND:
1151 if (!g_value_get_string (value))
1152 set_fg_rgba (text_tag, NULL); /* reset to foreground_set to FALSE */
1153 else if (gdk_rgba_parse (&rgba, g_value_get_string (value)))
1154 set_fg_rgba (text_tag, &rgba);
1156 g_warning ("Don't know color `%s'", g_value_get_string (value));
1158 g_object_notify (object, "foreground-gdk");
1162 case PROP_BACKGROUND_GDK:
1164 GdkColor *color = g_value_get_boxed (value);
1166 set_bg_color (text_tag, color);
1170 case PROP_FOREGROUND_GDK:
1172 GdkColor *color = g_value_get_boxed (value);
1174 set_fg_color (text_tag, color);
1178 case PROP_BACKGROUND_RGBA:
1180 GdkRGBA *color = g_value_get_boxed (value);
1182 set_bg_rgba (text_tag, color);
1186 case PROP_FOREGROUND_RGBA:
1188 GdkRGBA *color = g_value_get_boxed (value);
1190 set_fg_rgba (text_tag, color);
1196 PangoFontDescription *font_desc = NULL;
1199 name = g_value_get_string (value);
1202 font_desc = pango_font_description_from_string (name);
1204 set_font_description (text_tag, font_desc);
1206 pango_font_description_free (font_desc);
1208 size_changed = TRUE;
1212 case PROP_FONT_DESC:
1214 PangoFontDescription *font_desc;
1216 font_desc = g_value_get_boxed (value);
1218 set_font_description (text_tag, font_desc);
1220 size_changed = TRUE;
1230 case PROP_SIZE_POINTS:
1232 PangoFontMask old_set_mask;
1234 gtk_text_tag_ensure_font (text_tag);
1235 old_set_mask = pango_font_description_get_set_fields (priv->values->font);
1240 pango_font_description_set_family (priv->values->font,
1241 g_value_get_string (value));
1244 pango_font_description_set_style (priv->values->font,
1245 g_value_get_enum (value));
1248 pango_font_description_set_variant (priv->values->font,
1249 g_value_get_enum (value));
1252 pango_font_description_set_weight (priv->values->font,
1253 g_value_get_int (value));
1256 pango_font_description_set_stretch (priv->values->font,
1257 g_value_get_enum (value));
1260 pango_font_description_set_size (priv->values->font,
1261 g_value_get_int (value));
1262 g_object_notify (object, "size-points");
1264 case PROP_SIZE_POINTS:
1265 pango_font_description_set_size (priv->values->font,
1266 g_value_get_double (value) * PANGO_SCALE);
1267 g_object_notify (object, "size");
1271 size_changed = TRUE;
1272 notify_set_changed (object, old_set_mask & pango_font_description_get_set_fields (priv->values->font));
1273 g_object_notify (object, "font-desc");
1274 g_object_notify (object, "font");
1280 priv->values->font_scale = g_value_get_double (value);
1281 priv->scale_set = TRUE;
1282 g_object_notify (object, "scale-set");
1283 size_changed = TRUE;
1286 case PROP_PIXELS_ABOVE_LINES:
1287 priv->pixels_above_lines_set = TRUE;
1288 priv->values->pixels_above_lines = g_value_get_int (value);
1289 g_object_notify (object, "pixels-above-lines-set");
1290 size_changed = TRUE;
1293 case PROP_PIXELS_BELOW_LINES:
1294 priv->pixels_below_lines_set = TRUE;
1295 priv->values->pixels_below_lines = g_value_get_int (value);
1296 g_object_notify (object, "pixels-below-lines-set");
1297 size_changed = TRUE;
1300 case PROP_PIXELS_INSIDE_WRAP:
1301 priv->pixels_inside_wrap_set = TRUE;
1302 priv->values->pixels_inside_wrap = g_value_get_int (value);
1303 g_object_notify (object, "pixels-inside-wrap-set");
1304 size_changed = TRUE;
1308 priv->editable_set = TRUE;
1309 priv->values->editable = g_value_get_boolean (value);
1310 g_object_notify (object, "editable-set");
1313 case PROP_WRAP_MODE:
1314 priv->wrap_mode_set = TRUE;
1315 priv->values->wrap_mode = g_value_get_enum (value);
1316 g_object_notify (object, "wrap-mode-set");
1317 size_changed = TRUE;
1320 case PROP_JUSTIFICATION:
1321 priv->justification_set = TRUE;
1322 priv->values->justification = g_value_get_enum (value);
1323 g_object_notify (object, "justification-set");
1324 size_changed = TRUE;
1327 case PROP_DIRECTION:
1328 priv->values->direction = g_value_get_enum (value);
1331 case PROP_LEFT_MARGIN:
1332 priv->left_margin_set = TRUE;
1333 priv->values->left_margin = g_value_get_int (value);
1334 g_object_notify (object, "left-margin-set");
1335 size_changed = TRUE;
1339 priv->indent_set = TRUE;
1340 priv->values->indent = g_value_get_int (value);
1341 g_object_notify (object, "indent-set");
1342 size_changed = TRUE;
1345 case PROP_STRIKETHROUGH:
1346 priv->strikethrough_set = TRUE;
1347 priv->values->appearance.strikethrough = g_value_get_boolean (value);
1348 g_object_notify (object, "strikethrough-set");
1351 case PROP_RIGHT_MARGIN:
1352 priv->right_margin_set = TRUE;
1353 priv->values->right_margin = g_value_get_int (value);
1354 g_object_notify (object, "right-margin-set");
1355 size_changed = TRUE;
1358 case PROP_UNDERLINE:
1359 priv->underline_set = TRUE;
1360 priv->values->appearance.underline = g_value_get_enum (value);
1361 g_object_notify (object, "underline-set");
1365 priv->rise_set = TRUE;
1366 priv->values->appearance.rise = g_value_get_int (value);
1367 g_object_notify (object, "rise-set");
1368 size_changed = TRUE;
1371 case PROP_BACKGROUND_FULL_HEIGHT:
1372 priv->bg_full_height_set = TRUE;
1373 priv->values->bg_full_height = g_value_get_boolean (value);
1374 g_object_notify (object, "background-full-height-set");
1378 priv->language_set = TRUE;
1379 priv->values->language = pango_language_from_string (g_value_get_string (value));
1380 g_object_notify (object, "language-set");
1384 priv->tabs_set = TRUE;
1386 if (priv->values->tabs)
1387 pango_tab_array_free (priv->values->tabs);
1389 /* FIXME I'm not sure if this is a memleak or not */
1390 priv->values->tabs =
1391 pango_tab_array_copy (g_value_get_boxed (value));
1393 g_object_notify (object, "tabs-set");
1395 size_changed = TRUE;
1398 case PROP_INVISIBLE:
1399 priv->invisible_set = TRUE;
1400 priv->values->invisible = g_value_get_boolean (value);
1401 g_object_notify (object, "invisible-set");
1402 size_changed = TRUE;
1405 case PROP_PARAGRAPH_BACKGROUND:
1409 if (!g_value_get_string (value))
1410 set_pg_bg_rgba (text_tag, NULL); /* reset paragraph_background_set to FALSE */
1411 else if (gdk_rgba_parse (&rgba, g_value_get_string (value)))
1412 set_pg_bg_rgba (text_tag, &rgba);
1414 g_warning ("Don't know color `%s'", g_value_get_string (value));
1416 g_object_notify (object, "paragraph-background-gdk");
1420 case PROP_PARAGRAPH_BACKGROUND_GDK:
1422 GdkColor *color = g_value_get_boxed (value);
1424 set_pg_bg_color (text_tag, color);
1428 case PROP_PARAGRAPH_BACKGROUND_RGBA:
1430 GdkRGBA *color = g_value_get_boxed (value);
1432 set_pg_bg_rgba (text_tag, color);
1436 case PROP_ACCUMULATIVE_MARGIN:
1437 priv->accumulative_margin = g_value_get_boolean (value);
1438 g_object_notify (object, "accumulative-margin");
1439 size_changed = TRUE;
1442 /* Whether the value should be used... */
1444 case PROP_BACKGROUND_SET:
1445 priv->bg_color_set = g_value_get_boolean (value);
1448 case PROP_FOREGROUND_SET:
1449 priv->fg_color_set = g_value_get_boolean (value);
1452 case PROP_FAMILY_SET:
1453 case PROP_STYLE_SET:
1454 case PROP_VARIANT_SET:
1455 case PROP_WEIGHT_SET:
1456 case PROP_STRETCH_SET:
1458 if (!g_value_get_boolean (value))
1460 if (priv->values->font)
1461 pango_font_description_unset_fields (priv->values->font,
1462 get_property_font_set_mask (prop_id));
1466 PangoFontMask changed_mask;
1468 gtk_text_tag_ensure_font (text_tag);
1469 changed_mask = set_font_desc_fields (priv->values->font,
1470 get_property_font_set_mask (prop_id));
1471 notify_fields_changed (G_OBJECT (text_tag), changed_mask);
1475 case PROP_SCALE_SET:
1476 priv->scale_set = g_value_get_boolean (value);
1477 size_changed = TRUE;
1480 case PROP_PIXELS_ABOVE_LINES_SET:
1481 priv->pixels_above_lines_set = g_value_get_boolean (value);
1482 size_changed = TRUE;
1485 case PROP_PIXELS_BELOW_LINES_SET:
1486 priv->pixels_below_lines_set = g_value_get_boolean (value);
1487 size_changed = TRUE;
1490 case PROP_PIXELS_INSIDE_WRAP_SET:
1491 priv->pixels_inside_wrap_set = g_value_get_boolean (value);
1492 size_changed = TRUE;
1495 case PROP_EDITABLE_SET:
1496 priv->editable_set = g_value_get_boolean (value);
1499 case PROP_WRAP_MODE_SET:
1500 priv->wrap_mode_set = g_value_get_boolean (value);
1501 size_changed = TRUE;
1504 case PROP_JUSTIFICATION_SET:
1505 priv->justification_set = g_value_get_boolean (value);
1506 size_changed = TRUE;
1509 case PROP_LEFT_MARGIN_SET:
1510 priv->left_margin_set = g_value_get_boolean (value);
1511 size_changed = TRUE;
1514 case PROP_INDENT_SET:
1515 priv->indent_set = g_value_get_boolean (value);
1516 size_changed = TRUE;
1519 case PROP_STRIKETHROUGH_SET:
1520 priv->strikethrough_set = g_value_get_boolean (value);
1523 case PROP_RIGHT_MARGIN_SET:
1524 priv->right_margin_set = g_value_get_boolean (value);
1525 size_changed = TRUE;
1528 case PROP_UNDERLINE_SET:
1529 priv->underline_set = g_value_get_boolean (value);
1533 priv->rise_set = g_value_get_boolean (value);
1534 size_changed = TRUE;
1537 case PROP_BACKGROUND_FULL_HEIGHT_SET:
1538 priv->bg_full_height_set = g_value_get_boolean (value);
1541 case PROP_LANGUAGE_SET:
1542 priv->language_set = g_value_get_boolean (value);
1543 size_changed = TRUE;
1547 priv->tabs_set = g_value_get_boolean (value);
1548 size_changed = TRUE;
1551 case PROP_INVISIBLE_SET:
1552 priv->invisible_set = g_value_get_boolean (value);
1553 size_changed = TRUE;
1556 case PROP_PARAGRAPH_BACKGROUND_SET:
1557 priv->pg_bg_color_set = g_value_get_boolean (value);
1561 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1565 /* FIXME I would like to do this after all set_property in a single
1566 * g_object_set () have been called. But an idle function won't
1567 * work; we need to emit when the tag is changed, not when we get
1568 * around to the event loop. So blah, we eat some inefficiency.
1571 /* This is also somewhat weird since we emit another object's
1572 * signal here, but the two objects are already tightly bound.
1576 g_signal_emit_by_name (priv->table,
1578 text_tag, size_changed);
1582 gtk_text_tag_get_property (GObject *object,
1587 GtkTextTag *tag = GTK_TEXT_TAG (object);
1588 GtkTextTagPrivate *priv = tag->priv;
1593 g_value_set_string (value, priv->name);
1596 case PROP_BACKGROUND_GDK:
1597 g_value_set_boxed (value, &priv->values->appearance.bg_color);
1600 case PROP_BACKGROUND_RGBA:
1601 g_value_set_boxed (value, priv->values->appearance.rgba[0]);
1604 case PROP_FOREGROUND_GDK:
1605 g_value_set_boxed (value, &priv->values->appearance.fg_color);
1608 case PROP_FOREGROUND_RGBA:
1609 g_value_set_boxed (value, priv->values->appearance.rgba[1]);
1616 gtk_text_tag_ensure_font (tag);
1618 str = pango_font_description_to_string (priv->values->font);
1619 g_value_take_string (value, str);
1623 case PROP_FONT_DESC:
1624 gtk_text_tag_ensure_font (tag);
1625 g_value_set_boxed (value, priv->values->font);
1634 case PROP_SIZE_POINTS:
1635 gtk_text_tag_ensure_font (tag);
1639 g_value_set_string (value, pango_font_description_get_family (priv->values->font));
1643 g_value_set_enum (value, pango_font_description_get_style (priv->values->font));
1647 g_value_set_enum (value, pango_font_description_get_variant (priv->values->font));
1651 g_value_set_int (value, pango_font_description_get_weight (priv->values->font));
1655 g_value_set_enum (value, pango_font_description_get_stretch (priv->values->font));
1659 g_value_set_int (value, pango_font_description_get_size (priv->values->font));
1662 case PROP_SIZE_POINTS:
1663 g_value_set_double (value, ((double)pango_font_description_get_size (priv->values->font)) / (double)PANGO_SCALE);
1669 g_value_set_double (value, priv->values->font_scale);
1672 case PROP_PIXELS_ABOVE_LINES:
1673 g_value_set_int (value, priv->values->pixels_above_lines);
1676 case PROP_PIXELS_BELOW_LINES:
1677 g_value_set_int (value, priv->values->pixels_below_lines);
1680 case PROP_PIXELS_INSIDE_WRAP:
1681 g_value_set_int (value, priv->values->pixels_inside_wrap);
1685 g_value_set_boolean (value, priv->values->editable);
1688 case PROP_WRAP_MODE:
1689 g_value_set_enum (value, priv->values->wrap_mode);
1692 case PROP_JUSTIFICATION:
1693 g_value_set_enum (value, priv->values->justification);
1696 case PROP_DIRECTION:
1697 g_value_set_enum (value, priv->values->direction);
1700 case PROP_LEFT_MARGIN:
1701 g_value_set_int (value, priv->values->left_margin);
1705 g_value_set_int (value, priv->values->indent);
1708 case PROP_STRIKETHROUGH:
1709 g_value_set_boolean (value, priv->values->appearance.strikethrough);
1712 case PROP_RIGHT_MARGIN:
1713 g_value_set_int (value, priv->values->right_margin);
1716 case PROP_UNDERLINE:
1717 g_value_set_enum (value, priv->values->appearance.underline);
1721 g_value_set_int (value, priv->values->appearance.rise);
1724 case PROP_BACKGROUND_FULL_HEIGHT:
1725 g_value_set_boolean (value, priv->values->bg_full_height);
1729 g_value_set_string (value, pango_language_to_string (priv->values->language));
1733 if (priv->values->tabs)
1734 g_value_set_boxed (value, priv->values->tabs);
1737 case PROP_INVISIBLE:
1738 g_value_set_boolean (value, priv->values->invisible);
1741 case PROP_PARAGRAPH_BACKGROUND_GDK:
1742 g_value_set_boxed (value, priv->values->pg_bg_color);
1745 case PROP_PARAGRAPH_BACKGROUND_RGBA:
1746 g_value_set_boxed (value, priv->values->pg_bg_rgba);
1749 case PROP_ACCUMULATIVE_MARGIN:
1750 g_value_set_boolean (value, priv->accumulative_margin);
1753 case PROP_BACKGROUND_SET:
1754 g_value_set_boolean (value, priv->bg_color_set);
1757 case PROP_FOREGROUND_SET:
1758 g_value_set_boolean (value, priv->fg_color_set);
1761 case PROP_FAMILY_SET:
1762 case PROP_STYLE_SET:
1763 case PROP_VARIANT_SET:
1764 case PROP_WEIGHT_SET:
1765 case PROP_STRETCH_SET:
1768 PangoFontMask set_mask = priv->values->font ? pango_font_description_get_set_fields (priv->values->font) : 0;
1769 PangoFontMask test_mask = get_property_font_set_mask (prop_id);
1770 g_value_set_boolean (value, (set_mask & test_mask) != 0);
1775 case PROP_SCALE_SET:
1776 g_value_set_boolean (value, priv->scale_set);
1779 case PROP_PIXELS_ABOVE_LINES_SET:
1780 g_value_set_boolean (value, priv->pixels_above_lines_set);
1783 case PROP_PIXELS_BELOW_LINES_SET:
1784 g_value_set_boolean (value, priv->pixels_below_lines_set);
1787 case PROP_PIXELS_INSIDE_WRAP_SET:
1788 g_value_set_boolean (value, priv->pixels_inside_wrap_set);
1791 case PROP_EDITABLE_SET:
1792 g_value_set_boolean (value, priv->editable_set);
1795 case PROP_WRAP_MODE_SET:
1796 g_value_set_boolean (value, priv->wrap_mode_set);
1799 case PROP_JUSTIFICATION_SET:
1800 g_value_set_boolean (value, priv->justification_set);
1803 case PROP_LEFT_MARGIN_SET:
1804 g_value_set_boolean (value, priv->left_margin_set);
1807 case PROP_INDENT_SET:
1808 g_value_set_boolean (value, priv->indent_set);
1811 case PROP_STRIKETHROUGH_SET:
1812 g_value_set_boolean (value, priv->strikethrough_set);
1815 case PROP_RIGHT_MARGIN_SET:
1816 g_value_set_boolean (value, priv->right_margin_set);
1819 case PROP_UNDERLINE_SET:
1820 g_value_set_boolean (value, priv->underline_set);
1824 g_value_set_boolean (value, priv->rise_set);
1827 case PROP_BACKGROUND_FULL_HEIGHT_SET:
1828 g_value_set_boolean (value, priv->bg_full_height_set);
1831 case PROP_LANGUAGE_SET:
1832 g_value_set_boolean (value, priv->language_set);
1836 g_value_set_boolean (value, priv->tabs_set);
1839 case PROP_INVISIBLE_SET:
1840 g_value_set_boolean (value, priv->invisible_set);
1843 case PROP_PARAGRAPH_BACKGROUND_SET:
1844 g_value_set_boolean (value, priv->pg_bg_color_set);
1847 case PROP_BACKGROUND:
1848 case PROP_FOREGROUND:
1849 case PROP_PARAGRAPH_BACKGROUND:
1850 g_warning ("'foreground', 'background' and 'paragraph_background' properties are not readable, use 'foreground_gdk', 'background_gdk' and 'paragraph_background_gdk'");
1852 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1868 delta_priority_foreach (GtkTextTag *tag, gpointer user_data)
1870 GtkTextTagPrivate *priv = tag->priv;
1871 DeltaData *dd = user_data;
1873 if (priv->priority >= dd->low && priv->priority <= dd->high)
1874 priv->priority += dd->delta;
1878 * gtk_text_tag_get_priority:
1879 * @tag: a #GtkTextTag
1881 * Get the tag priority.
1883 * Return value: The tag's priority.
1886 gtk_text_tag_get_priority (GtkTextTag *tag)
1888 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), 0);
1890 return tag->priv->priority;
1894 * gtk_text_tag_set_priority:
1895 * @tag: a #GtkTextTag
1896 * @priority: the new priority
1898 * Sets the priority of a #GtkTextTag. Valid priorities are
1899 * start at 0 and go to one less than gtk_text_tag_table_get_size().
1900 * Each tag in a table has a unique priority; setting the priority
1901 * of one tag shifts the priorities of all the other tags in the
1902 * table to maintain a unique priority for each tag. Higher priority
1903 * tags "win" if two tags both set the same text attribute. When adding
1904 * a tag to a tag table, it will be assigned the highest priority in
1905 * the table by default; so normally the precedence of a set of tags
1906 * is the order in which they were added to the table, or created with
1907 * gtk_text_buffer_create_tag(), which adds the tag to the buffer's table
1911 gtk_text_tag_set_priority (GtkTextTag *tag,
1914 GtkTextTagPrivate *priv;
1917 g_return_if_fail (GTK_IS_TEXT_TAG (tag));
1921 g_return_if_fail (priv->table != NULL);
1922 g_return_if_fail (priority >= 0);
1923 g_return_if_fail (priority < gtk_text_tag_table_get_size (priv->table));
1925 if (priority == priv->priority)
1928 if (priority < priv->priority)
1931 dd.high = priv->priority - 1;
1936 dd.low = priv->priority + 1;
1941 gtk_text_tag_table_foreach (priv->table,
1942 delta_priority_foreach,
1945 priv->priority = priority;
1949 * gtk_text_tag_event:
1950 * @tag: a #GtkTextTag
1951 * @event_object: object that received the event, such as a widget
1953 * @iter: location where the event was received
1955 * Emits the "event" signal on the #GtkTextTag.
1957 * Return value: result of signal emission (whether the event was handled)
1960 gtk_text_tag_event (GtkTextTag *tag,
1961 GObject *event_object,
1963 const GtkTextIter *iter)
1965 gboolean retval = FALSE;
1967 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
1968 g_return_val_if_fail (G_IS_OBJECT (event_object), FALSE);
1969 g_return_val_if_fail (event != NULL, FALSE);
1983 tag_sort_func (gconstpointer first, gconstpointer second)
1985 GtkTextTag *tag1, *tag2;
1987 tag1 = * (GtkTextTag **) first;
1988 tag2 = * (GtkTextTag **) second;
1989 return tag1->priv->priority - tag2->priv->priority;
1993 _gtk_text_tag_array_sort (GtkTextTag** tag_array_p,
1998 GtkTextTag **maxPtrPtr, *tmp;
2000 g_return_if_fail (tag_array_p != NULL);
2001 g_return_if_fail (len > 0);
2007 GtkTextTag **iter = tag_array_p;
2009 for (i = len-1; i > 0; i--, iter++) {
2010 maxPtrPtr = tag = iter;
2011 prio = tag[0]->priv->priority;
2012 for (j = i, tag++; j > 0; j--, tag++) {
2013 if (tag[0]->priv->priority < prio) {
2014 prio = tag[0]->priv->priority;
2023 qsort ((void *) tag_array_p, (unsigned) len, sizeof (GtkTextTag *),
2029 printf ("Sorted tag array: \n");
2033 GtkTextTag *t = tag_array_p[i];
2034 printf (" %s priority %d\n", t->name, t->priority);