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.
52 #include "gtktexttag.h"
53 #include "gtktexttypes.h"
54 #include "gtktexttagtable.h"
56 #include "gtkmarshalers.h"
57 #include "gtkprivate.h"
78 PROP_BACKGROUND_STIPPLE,
79 PROP_FOREGROUND_STIPPLE,
90 PROP_PIXELS_ABOVE_LINES,
91 PROP_PIXELS_BELOW_LINES,
92 PROP_PIXELS_INSIDE_WRAP,
103 PROP_BACKGROUND_FULL_HEIGHT,
107 PROP_PARAGRAPH_BACKGROUND,
108 PROP_PARAGRAPH_BACKGROUND_GDK,
110 /* Whether-a-style-arg-is-set args */
113 PROP_BACKGROUND_STIPPLE_SET,
114 PROP_FOREGROUND_STIPPLE_SET,
122 PROP_PIXELS_ABOVE_LINES_SET,
123 PROP_PIXELS_BELOW_LINES_SET,
124 PROP_PIXELS_INSIDE_WRAP_SET,
127 PROP_JUSTIFICATION_SET,
128 PROP_LEFT_MARGIN_SET,
130 PROP_STRIKETHROUGH_SET,
131 PROP_RIGHT_MARGIN_SET,
134 PROP_BACKGROUND_FULL_HEIGHT_SET,
138 PROP_PARAGRAPH_BACKGROUND_SET,
142 static void gtk_text_tag_finalize (GObject *object);
143 static void gtk_text_tag_set_property (GObject *object,
147 static void gtk_text_tag_get_property (GObject *object,
152 static guint signals[LAST_SIGNAL] = { 0 };
154 G_DEFINE_TYPE (GtkTextTag, gtk_text_tag, G_TYPE_OBJECT)
157 gtk_text_tag_class_init (GtkTextTagClass *klass)
159 GObjectClass *object_class = G_OBJECT_CLASS (klass);
161 object_class->set_property = gtk_text_tag_set_property;
162 object_class->get_property = gtk_text_tag_get_property;
164 object_class->finalize = gtk_text_tag_finalize;
167 g_object_class_install_property (object_class,
169 g_param_spec_string ("name",
171 P_("Name used to refer to the text tag. NULL for anonymous tags"),
173 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
177 g_object_class_install_property (object_class,
179 g_param_spec_string ("background",
180 P_("Background color name"),
181 P_("Background color as a string"),
183 GTK_PARAM_WRITABLE));
185 g_object_class_install_property (object_class,
187 g_param_spec_boxed ("background-gdk",
188 P_("Background color"),
189 P_("Background color as a (possibly unallocated) GdkColor"),
191 GTK_PARAM_READWRITE));
193 g_object_class_install_property (object_class,
194 PROP_BACKGROUND_FULL_HEIGHT,
195 g_param_spec_boolean ("background-full-height",
196 P_("Background full height"),
197 P_("Whether the background color fills the entire line height or only the height of the tagged characters"),
199 GTK_PARAM_READWRITE));
202 g_object_class_install_property (object_class,
203 PROP_BACKGROUND_STIPPLE,
204 g_param_spec_object ("background-stipple",
205 P_("Background stipple mask"),
206 P_("Bitmap to use as a mask when drawing the text background"),
208 GTK_PARAM_READWRITE));
211 g_object_class_install_property (object_class,
213 g_param_spec_string ("foreground",
214 P_("Foreground color name"),
215 P_("Foreground color as a string"),
217 GTK_PARAM_WRITABLE));
219 g_object_class_install_property (object_class,
221 g_param_spec_boxed ("foreground-gdk",
222 P_("Foreground color"),
223 P_("Foreground color as a (possibly unallocated) GdkColor"),
225 GTK_PARAM_READWRITE));
228 g_object_class_install_property (object_class,
229 PROP_FOREGROUND_STIPPLE,
230 g_param_spec_object ("foreground-stipple",
231 P_("Foreground stipple mask"),
232 P_("Bitmap to use as a mask when drawing the text foreground"),
234 GTK_PARAM_READWRITE));
236 g_object_class_install_property (object_class,
238 g_param_spec_enum ("direction",
239 P_("Text direction"),
240 P_("Text direction, e.g. right-to-left or left-to-right"),
241 GTK_TYPE_TEXT_DIRECTION,
243 GTK_PARAM_READWRITE));
245 g_object_class_install_property (object_class,
247 g_param_spec_boolean ("editable",
249 P_("Whether the text can be modified by the user"),
251 GTK_PARAM_READWRITE));
256 * Font description as string, e.g. \"Sans Italic 12\".
258 * Note that the initial value of this property depends on
259 * the internals of #PangoFontDescription.
261 g_object_class_install_property (object_class,
263 g_param_spec_string ("font",
265 P_("Font description as a string, e.g. \"Sans Italic 12\""),
267 GTK_PARAM_READWRITE));
269 g_object_class_install_property (object_class,
271 g_param_spec_boxed ("font-desc",
273 P_("Font description as a PangoFontDescription struct"),
274 PANGO_TYPE_FONT_DESCRIPTION,
275 GTK_PARAM_READWRITE));
277 g_object_class_install_property (object_class,
279 g_param_spec_string ("family",
281 P_("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
283 GTK_PARAM_READWRITE));
285 g_object_class_install_property (object_class,
287 g_param_spec_enum ("style",
289 P_("Font style as a PangoStyle, e.g. PANGO_STYLE_ITALIC"),
292 GTK_PARAM_READWRITE));
294 g_object_class_install_property (object_class,
296 g_param_spec_enum ("variant",
298 P_("Font variant as a PangoVariant, e.g. PANGO_VARIANT_SMALL_CAPS"),
300 PANGO_VARIANT_NORMAL,
301 GTK_PARAM_READWRITE));
303 g_object_class_install_property (object_class,
305 g_param_spec_int ("weight",
307 P_("Font weight as an integer, see predefined values in PangoWeight; for example, PANGO_WEIGHT_BOLD"),
311 GTK_PARAM_READWRITE));
314 g_object_class_install_property (object_class,
316 g_param_spec_enum ("stretch",
318 P_("Font stretch as a PangoStretch, e.g. PANGO_STRETCH_CONDENSED"),
320 PANGO_STRETCH_NORMAL,
321 GTK_PARAM_READWRITE));
323 g_object_class_install_property (object_class,
325 g_param_spec_int ("size",
327 P_("Font size in Pango units"),
331 GTK_PARAM_READWRITE));
333 g_object_class_install_property (object_class,
335 g_param_spec_double ("scale",
337 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"),
341 GTK_PARAM_READWRITE));
343 g_object_class_install_property (object_class,
345 g_param_spec_double ("size-points",
347 P_("Font size in points"),
351 GTK_PARAM_READWRITE));
353 g_object_class_install_property (object_class,
355 g_param_spec_enum ("justification",
357 P_("Left, right, or center justification"),
358 GTK_TYPE_JUSTIFICATION,
360 GTK_PARAM_READWRITE));
363 * GtkTextTag:language:
365 * The language this text is in, as an ISO code. Pango can use this as a
366 * hint when rendering the text. If not set, an appropriate default will be
369 * Note that the initial value of this property depends on the current
370 * locale, see also gtk_get_default_language().
372 g_object_class_install_property (object_class,
374 g_param_spec_string ("language",
376 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."),
378 GTK_PARAM_READWRITE));
380 g_object_class_install_property (object_class,
382 g_param_spec_int ("left-margin",
384 P_("Width of the left margin in pixels"),
388 GTK_PARAM_READWRITE));
390 g_object_class_install_property (object_class,
392 g_param_spec_int ("right-margin",
394 P_("Width of the right margin in pixels"),
398 GTK_PARAM_READWRITE));
401 g_object_class_install_property (object_class,
403 g_param_spec_int ("indent",
405 P_("Amount to indent the paragraph, in pixels"),
409 GTK_PARAM_READWRITE));
412 g_object_class_install_property (object_class,
414 g_param_spec_int ("rise",
416 P_("Offset of text above the baseline (below the baseline if rise is negative) in Pango units"),
420 GTK_PARAM_READWRITE));
422 g_object_class_install_property (object_class,
423 PROP_PIXELS_ABOVE_LINES,
424 g_param_spec_int ("pixels-above-lines",
425 P_("Pixels above lines"),
426 P_("Pixels of blank space above paragraphs"),
430 GTK_PARAM_READWRITE));
432 g_object_class_install_property (object_class,
433 PROP_PIXELS_BELOW_LINES,
434 g_param_spec_int ("pixels-below-lines",
435 P_("Pixels below lines"),
436 P_("Pixels of blank space below paragraphs"),
440 GTK_PARAM_READWRITE));
442 g_object_class_install_property (object_class,
443 PROP_PIXELS_INSIDE_WRAP,
444 g_param_spec_int ("pixels-inside-wrap",
445 P_("Pixels inside wrap"),
446 P_("Pixels of blank space between wrapped lines in a paragraph"),
450 GTK_PARAM_READWRITE));
452 g_object_class_install_property (object_class,
454 g_param_spec_boolean ("strikethrough",
456 P_("Whether to strike through the text"),
458 GTK_PARAM_READWRITE));
460 g_object_class_install_property (object_class,
462 g_param_spec_enum ("underline",
464 P_("Style of underline for this text"),
465 PANGO_TYPE_UNDERLINE,
466 PANGO_UNDERLINE_NONE,
467 GTK_PARAM_READWRITE));
469 g_object_class_install_property (object_class,
471 g_param_spec_enum ("wrap-mode",
473 P_("Whether to wrap lines never, at word boundaries, or at character boundaries"),
476 GTK_PARAM_READWRITE));
479 g_object_class_install_property (object_class,
481 g_param_spec_boxed ("tabs",
483 P_("Custom tabs for this text"),
484 PANGO_TYPE_TAB_ARRAY,
485 GTK_PARAM_READWRITE));
488 * GtkTextTag:invisible:
490 * Whether this text is hidden.
492 * Note that there may still be problems with the support for invisible
493 * text, in particular when navigating programmatically inside a buffer
494 * containing invisible segments.
498 g_object_class_install_property (object_class,
500 g_param_spec_boolean ("invisible",
502 P_("Whether this text is hidden."),
504 GTK_PARAM_READWRITE));
507 * GtkTextTag:paragraph-background:
509 * The paragraph background color as a string.
513 g_object_class_install_property (object_class,
514 PROP_PARAGRAPH_BACKGROUND,
515 g_param_spec_string ("paragraph-background",
516 P_("Paragraph background color name"),
517 P_("Paragraph background color as a string"),
519 GTK_PARAM_WRITABLE));
522 * GtkTextTag:paragraph-background-gdk:
524 * The paragraph background color as a as a (possibly unallocated)
529 g_object_class_install_property (object_class,
530 PROP_PARAGRAPH_BACKGROUND_GDK,
531 g_param_spec_boxed ("paragraph-background-gdk",
532 P_("Paragraph background color"),
533 P_("Paragraph background color as a (possibly unallocated) GdkColor"),
535 GTK_PARAM_READWRITE));
537 /* Style props are set or not */
539 #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))
541 ADD_SET_PROP ("background-set", PROP_BACKGROUND_SET,
542 P_("Background set"),
543 P_("Whether this tag affects the background color"));
545 ADD_SET_PROP ("background-full-height-set", PROP_BACKGROUND_FULL_HEIGHT_SET,
546 P_("Background full height set"),
547 P_("Whether this tag affects background height"));
549 ADD_SET_PROP ("background-stipple-set", PROP_BACKGROUND_STIPPLE_SET,
550 P_("Background stipple set"),
551 P_("Whether this tag affects the background stipple"));
553 ADD_SET_PROP ("foreground-set", PROP_FOREGROUND_SET,
554 P_("Foreground set"),
555 P_("Whether this tag affects the foreground color"));
557 ADD_SET_PROP ("foreground-stipple-set", PROP_FOREGROUND_STIPPLE_SET,
558 P_("Foreground stipple set"),
559 P_("Whether this tag affects the foreground stipple"));
561 ADD_SET_PROP ("editable-set", PROP_EDITABLE_SET,
562 P_("Editability set"),
563 P_("Whether this tag affects text editability"));
565 ADD_SET_PROP ("family-set", PROP_FAMILY_SET,
566 P_("Font family set"),
567 P_("Whether this tag affects the font family"));
569 ADD_SET_PROP ("style-set", PROP_STYLE_SET,
570 P_("Font style set"),
571 P_("Whether this tag affects the font style"));
573 ADD_SET_PROP ("variant-set", PROP_VARIANT_SET,
574 P_("Font variant set"),
575 P_("Whether this tag affects the font variant"));
577 ADD_SET_PROP ("weight-set", PROP_WEIGHT_SET,
578 P_("Font weight set"),
579 P_("Whether this tag affects the font weight"));
581 ADD_SET_PROP ("stretch-set", PROP_STRETCH_SET,
582 P_("Font stretch set"),
583 P_("Whether this tag affects the font stretch"));
585 ADD_SET_PROP ("size-set", PROP_SIZE_SET,
587 P_("Whether this tag affects the font size"));
589 ADD_SET_PROP ("scale-set", PROP_SCALE_SET,
590 P_("Font scale set"),
591 P_("Whether this tag scales the font size by a factor"));
593 ADD_SET_PROP ("justification-set", PROP_JUSTIFICATION_SET,
594 P_("Justification set"),
595 P_("Whether this tag affects paragraph justification"));
597 ADD_SET_PROP ("language-set", PROP_LANGUAGE_SET,
599 P_("Whether this tag affects the language the text is rendered as"));
601 ADD_SET_PROP ("left-margin-set", PROP_LEFT_MARGIN_SET,
602 P_("Left margin set"),
603 P_("Whether this tag affects the left margin"));
605 ADD_SET_PROP ("indent-set", PROP_INDENT_SET,
607 P_("Whether this tag affects indentation"));
609 ADD_SET_PROP ("rise-set", PROP_RISE_SET,
611 P_("Whether this tag affects the rise"));
613 ADD_SET_PROP ("pixels-above-lines-set", PROP_PIXELS_ABOVE_LINES_SET,
614 P_("Pixels above lines set"),
615 P_("Whether this tag affects the number of pixels above lines"));
617 ADD_SET_PROP ("pixels-below-lines-set", PROP_PIXELS_BELOW_LINES_SET,
618 P_("Pixels below lines set"),
619 P_("Whether this tag affects the number of pixels above lines"));
621 ADD_SET_PROP ("pixels-inside-wrap-set", PROP_PIXELS_INSIDE_WRAP_SET,
622 P_("Pixels inside wrap set"),
623 P_("Whether this tag affects the number of pixels between wrapped lines"));
625 ADD_SET_PROP ("strikethrough-set", PROP_STRIKETHROUGH_SET,
626 P_("Strikethrough set"),
627 P_("Whether this tag affects strikethrough"));
629 ADD_SET_PROP ("right-margin-set", PROP_RIGHT_MARGIN_SET,
630 P_("Right margin set"),
631 P_("Whether this tag affects the right margin"));
633 ADD_SET_PROP ("underline-set", PROP_UNDERLINE_SET,
635 P_("Whether this tag affects underlining"));
637 ADD_SET_PROP ("wrap-mode-set", PROP_WRAP_MODE_SET,
639 P_("Whether this tag affects line wrap mode"));
641 ADD_SET_PROP ("tabs-set", PROP_TABS_SET,
643 P_("Whether this tag affects tabs"));
645 ADD_SET_PROP ("invisible-set", PROP_INVISIBLE_SET,
647 P_("Whether this tag affects text visibility"));
649 ADD_SET_PROP ("paragraph-background-set", PROP_PARAGRAPH_BACKGROUND_SET,
650 P_("Paragraph background set"),
651 P_("Whether this tag affects the paragraph background color"));
655 * @tag: the #GtkTextTag on which the signal is emitted
656 * @object: the object the event was fired from (typically a #GtkTextView)
657 * @event: the event which triggered the signal
658 * @iter: a #GtkTextIter pointing at the location the event occured
660 * The ::event signal is emitted when an event occurs on a region of the
661 * buffer marked with this tag.
663 * Returns: %TRUE to stop other handlers from being invoked for the
664 * event. %FALSE to propagate the event further.
667 g_signal_new (I_("event"),
668 G_OBJECT_CLASS_TYPE (object_class),
670 G_STRUCT_OFFSET (GtkTextTagClass, event),
671 _gtk_boolean_handled_accumulator, NULL,
672 _gtk_marshal_BOOLEAN__OBJECT_BOXED_BOXED,
676 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE,
681 gtk_text_tag_init (GtkTextTag *text_tag)
683 text_tag->values = gtk_text_attributes_new ();
688 * @name: tag name, or %NULL
690 * Creates a #GtkTextTag. Configure the tag using object arguments,
691 * i.e. using g_object_set().
693 * Return value: a new #GtkTextTag
696 gtk_text_tag_new (const gchar *name)
700 tag = g_object_new (GTK_TYPE_TEXT_TAG, "name", name, NULL);
706 gtk_text_tag_finalize (GObject *object)
708 GtkTextTag *text_tag;
710 text_tag = GTK_TEXT_TAG (object);
712 g_assert (!text_tag->values->realized);
715 gtk_text_tag_table_remove (text_tag->table, text_tag);
717 g_assert (text_tag->table == NULL);
719 gtk_text_attributes_unref (text_tag->values);
720 text_tag->values = NULL;
722 g_free (text_tag->name);
723 text_tag->name = NULL;
725 (* G_OBJECT_CLASS (gtk_text_tag_parent_class)->finalize) (object);
729 set_bg_color (GtkTextTag *tag, GdkColor *color)
733 if (!tag->bg_color_set)
735 tag->bg_color_set = TRUE;
736 g_object_notify (G_OBJECT (tag), "background-set");
739 tag->values->appearance.bg_color = *color;
743 if (tag->bg_color_set)
745 tag->bg_color_set = FALSE;
746 g_object_notify (G_OBJECT (tag), "background-set");
752 set_fg_color (GtkTextTag *tag, GdkColor *color)
756 if (!tag->fg_color_set)
758 tag->fg_color_set = TRUE;
759 g_object_notify (G_OBJECT (tag), "foreground-set");
761 tag->values->appearance.fg_color = *color;
765 if (tag->fg_color_set)
767 tag->fg_color_set = FALSE;
768 g_object_notify (G_OBJECT (tag), "foreground-set");
774 set_pg_bg_color (GtkTextTag *tag, GdkColor *color)
778 if (!tag->pg_bg_color_set)
780 tag->pg_bg_color_set = TRUE;
781 g_object_notify (G_OBJECT (tag), "paragraph-background-set");
784 gdk_color_free (tag->values->pg_bg_color);
786 tag->values->pg_bg_color = gdk_color_copy (color);
790 if (tag->pg_bg_color_set)
792 tag->pg_bg_color_set = FALSE;
793 g_object_notify (G_OBJECT (tag), "paragraph-background-set");
794 gdk_color_free (tag->values->pg_bg_color);
797 tag->values->pg_bg_color = NULL;
802 get_property_font_set_mask (guint prop_id)
806 case PROP_FAMILY_SET:
807 return PANGO_FONT_MASK_FAMILY;
809 return PANGO_FONT_MASK_STYLE;
810 case PROP_VARIANT_SET:
811 return PANGO_FONT_MASK_VARIANT;
812 case PROP_WEIGHT_SET:
813 return PANGO_FONT_MASK_WEIGHT;
814 case PROP_STRETCH_SET:
815 return PANGO_FONT_MASK_STRETCH;
817 return PANGO_FONT_MASK_SIZE;
824 set_font_desc_fields (PangoFontDescription *desc,
825 PangoFontMask to_set)
827 PangoFontMask changed_mask = 0;
829 if (to_set & PANGO_FONT_MASK_FAMILY)
831 const char *family = pango_font_description_get_family (desc);
835 changed_mask |= PANGO_FONT_MASK_FAMILY;
838 pango_font_description_set_family (desc, family);
840 if (to_set & PANGO_FONT_MASK_STYLE)
841 pango_font_description_set_style (desc, pango_font_description_get_style (desc));
842 if (to_set & PANGO_FONT_MASK_VARIANT)
843 pango_font_description_set_variant (desc, pango_font_description_get_variant (desc));
844 if (to_set & PANGO_FONT_MASK_WEIGHT)
845 pango_font_description_set_weight (desc, pango_font_description_get_weight (desc));
846 if (to_set & PANGO_FONT_MASK_STRETCH)
847 pango_font_description_set_stretch (desc, pango_font_description_get_stretch (desc));
848 if (to_set & PANGO_FONT_MASK_SIZE)
850 gint size = pango_font_description_get_size (desc);
853 size = 10 * PANGO_SCALE;
854 changed_mask |= PANGO_FONT_MASK_SIZE;
857 pango_font_description_set_size (desc, size);
864 notify_set_changed (GObject *object,
865 PangoFontMask changed_mask)
867 if (changed_mask & PANGO_FONT_MASK_FAMILY)
868 g_object_notify (object, "family-set");
869 if (changed_mask & PANGO_FONT_MASK_STYLE)
870 g_object_notify (object, "style-set");
871 if (changed_mask & PANGO_FONT_MASK_VARIANT)
872 g_object_notify (object, "variant-set");
873 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
874 g_object_notify (object, "weight-set");
875 if (changed_mask & PANGO_FONT_MASK_STRETCH)
876 g_object_notify (object, "stretch-set");
877 if (changed_mask & PANGO_FONT_MASK_SIZE)
878 g_object_notify (object, "size-set");
882 notify_fields_changed (GObject *object,
883 PangoFontMask changed_mask)
885 if (changed_mask & PANGO_FONT_MASK_FAMILY)
886 g_object_notify (object, "family");
887 if (changed_mask & PANGO_FONT_MASK_STYLE)
888 g_object_notify (object, "style");
889 if (changed_mask & PANGO_FONT_MASK_VARIANT)
890 g_object_notify (object, "variant");
891 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
892 g_object_notify (object, "weight");
893 if (changed_mask & PANGO_FONT_MASK_STRETCH)
894 g_object_notify (object, "stretch");
895 if (changed_mask & PANGO_FONT_MASK_SIZE)
896 g_object_notify (object, "size");
900 set_font_description (GtkTextTag *text_tag,
901 PangoFontDescription *font_desc)
903 GObject *object = G_OBJECT (text_tag);
904 PangoFontDescription *new_font_desc;
905 PangoFontMask old_mask, new_mask, changed_mask, set_changed_mask;
908 new_font_desc = pango_font_description_copy (font_desc);
910 new_font_desc = pango_font_description_new ();
912 if (text_tag->values->font)
913 old_mask = pango_font_description_get_set_fields (text_tag->values->font);
917 new_mask = pango_font_description_get_set_fields (new_font_desc);
919 changed_mask = old_mask | new_mask;
920 set_changed_mask = old_mask ^ new_mask;
922 if (text_tag->values->font)
923 pango_font_description_free (text_tag->values->font);
924 text_tag->values->font = new_font_desc;
926 g_object_freeze_notify (object);
928 g_object_notify (object, "font-desc");
929 g_object_notify (object, "font");
931 if (changed_mask & PANGO_FONT_MASK_FAMILY)
932 g_object_notify (object, "family");
933 if (changed_mask & PANGO_FONT_MASK_STYLE)
934 g_object_notify (object, "style");
935 if (changed_mask & PANGO_FONT_MASK_VARIANT)
936 g_object_notify (object, "variant");
937 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
938 g_object_notify (object, "weight");
939 if (changed_mask & PANGO_FONT_MASK_STRETCH)
940 g_object_notify (object, "stretch");
941 if (changed_mask & PANGO_FONT_MASK_SIZE)
943 g_object_notify (object, "size");
944 g_object_notify (object, "size-points");
947 notify_set_changed (object, set_changed_mask);
949 g_object_thaw_notify (object);
953 gtk_text_tag_ensure_font (GtkTextTag *text_tag)
955 if (!text_tag->values->font)
956 text_tag->values->font = pango_font_description_new ();
960 gtk_text_tag_set_property (GObject *object,
965 GtkTextTag *text_tag;
966 gboolean size_changed = FALSE;
968 text_tag = GTK_TEXT_TAG (object);
970 g_return_if_fail (!text_tag->values->realized);
975 g_return_if_fail (text_tag->name == NULL);
976 text_tag->name = g_strdup (g_value_get_string (value));
979 case PROP_BACKGROUND:
983 if (gdk_color_parse (g_value_get_string (value), &color))
984 set_bg_color (text_tag, &color);
986 g_warning ("Don't know color `%s'", g_value_get_string (value));
988 g_object_notify (object, "background-gdk");
992 case PROP_FOREGROUND:
996 if (gdk_color_parse (g_value_get_string (value), &color))
997 set_fg_color (text_tag, &color);
999 g_warning ("Don't know color `%s'", g_value_get_string (value));
1001 g_object_notify (object, "foreground-gdk");
1005 case PROP_BACKGROUND_GDK:
1007 GdkColor *color = g_value_get_boxed (value);
1009 set_bg_color (text_tag, color);
1013 case PROP_FOREGROUND_GDK:
1015 GdkColor *color = g_value_get_boxed (value);
1017 set_fg_color (text_tag, color);
1021 case PROP_BACKGROUND_STIPPLE:
1023 GdkBitmap *bitmap = g_value_get_object (value);
1025 text_tag->bg_stipple_set = TRUE;
1026 g_object_notify (object, "background-stipple-set");
1028 if (text_tag->values->appearance.bg_stipple != bitmap)
1031 g_object_ref (bitmap);
1033 if (text_tag->values->appearance.bg_stipple)
1034 g_object_unref (text_tag->values->appearance.bg_stipple);
1036 text_tag->values->appearance.bg_stipple = bitmap;
1041 case PROP_FOREGROUND_STIPPLE:
1043 GdkBitmap *bitmap = g_value_get_object (value);
1045 text_tag->fg_stipple_set = TRUE;
1046 g_object_notify (object, "foreground-stipple-set");
1048 if (text_tag->values->appearance.fg_stipple != bitmap)
1051 g_object_ref (bitmap);
1053 if (text_tag->values->appearance.fg_stipple)
1054 g_object_unref (text_tag->values->appearance.fg_stipple);
1056 text_tag->values->appearance.fg_stipple = bitmap;
1063 PangoFontDescription *font_desc = NULL;
1066 name = g_value_get_string (value);
1069 font_desc = pango_font_description_from_string (name);
1071 set_font_description (text_tag, font_desc);
1073 pango_font_description_free (font_desc);
1075 size_changed = TRUE;
1079 case PROP_FONT_DESC:
1081 PangoFontDescription *font_desc;
1083 font_desc = g_value_get_boxed (value);
1085 set_font_description (text_tag, font_desc);
1087 size_changed = TRUE;
1097 case PROP_SIZE_POINTS:
1099 PangoFontMask old_set_mask;
1101 gtk_text_tag_ensure_font (text_tag);
1102 old_set_mask = pango_font_description_get_set_fields (text_tag->values->font);
1107 pango_font_description_set_family (text_tag->values->font,
1108 g_value_get_string (value));
1111 pango_font_description_set_style (text_tag->values->font,
1112 g_value_get_enum (value));
1115 pango_font_description_set_variant (text_tag->values->font,
1116 g_value_get_enum (value));
1119 pango_font_description_set_weight (text_tag->values->font,
1120 g_value_get_int (value));
1123 pango_font_description_set_stretch (text_tag->values->font,
1124 g_value_get_enum (value));
1127 pango_font_description_set_size (text_tag->values->font,
1128 g_value_get_int (value));
1129 g_object_notify (object, "size-points");
1131 case PROP_SIZE_POINTS:
1132 pango_font_description_set_size (text_tag->values->font,
1133 g_value_get_double (value) * PANGO_SCALE);
1134 g_object_notify (object, "size");
1138 size_changed = TRUE;
1139 notify_set_changed (object, old_set_mask & pango_font_description_get_set_fields (text_tag->values->font));
1140 g_object_notify (object, "font-desc");
1141 g_object_notify (object, "font");
1147 text_tag->values->font_scale = g_value_get_double (value);
1148 text_tag->scale_set = TRUE;
1149 g_object_notify (object, "scale-set");
1150 size_changed = TRUE;
1153 case PROP_PIXELS_ABOVE_LINES:
1154 text_tag->pixels_above_lines_set = TRUE;
1155 text_tag->values->pixels_above_lines = g_value_get_int (value);
1156 g_object_notify (object, "pixels-above-lines-set");
1157 size_changed = TRUE;
1160 case PROP_PIXELS_BELOW_LINES:
1161 text_tag->pixels_below_lines_set = TRUE;
1162 text_tag->values->pixels_below_lines = g_value_get_int (value);
1163 g_object_notify (object, "pixels-below-lines-set");
1164 size_changed = TRUE;
1167 case PROP_PIXELS_INSIDE_WRAP:
1168 text_tag->pixels_inside_wrap_set = TRUE;
1169 text_tag->values->pixels_inside_wrap = g_value_get_int (value);
1170 g_object_notify (object, "pixels-inside-wrap-set");
1171 size_changed = TRUE;
1175 text_tag->editable_set = TRUE;
1176 text_tag->values->editable = g_value_get_boolean (value);
1177 g_object_notify (object, "editable-set");
1180 case PROP_WRAP_MODE:
1181 text_tag->wrap_mode_set = TRUE;
1182 text_tag->values->wrap_mode = g_value_get_enum (value);
1183 g_object_notify (object, "wrap-mode-set");
1184 size_changed = TRUE;
1187 case PROP_JUSTIFICATION:
1188 text_tag->justification_set = TRUE;
1189 text_tag->values->justification = g_value_get_enum (value);
1190 g_object_notify (object, "justification-set");
1191 size_changed = TRUE;
1194 case PROP_DIRECTION:
1195 text_tag->values->direction = g_value_get_enum (value);
1198 case PROP_LEFT_MARGIN:
1199 text_tag->left_margin_set = TRUE;
1200 text_tag->values->left_margin = g_value_get_int (value);
1201 g_object_notify (object, "left-margin-set");
1202 size_changed = TRUE;
1206 text_tag->indent_set = TRUE;
1207 text_tag->values->indent = g_value_get_int (value);
1208 g_object_notify (object, "indent-set");
1209 size_changed = TRUE;
1212 case PROP_STRIKETHROUGH:
1213 text_tag->strikethrough_set = TRUE;
1214 text_tag->values->appearance.strikethrough = g_value_get_boolean (value);
1215 g_object_notify (object, "strikethrough-set");
1218 case PROP_RIGHT_MARGIN:
1219 text_tag->right_margin_set = TRUE;
1220 text_tag->values->right_margin = g_value_get_int (value);
1221 g_object_notify (object, "right-margin-set");
1222 size_changed = TRUE;
1225 case PROP_UNDERLINE:
1226 text_tag->underline_set = TRUE;
1227 text_tag->values->appearance.underline = g_value_get_enum (value);
1228 g_object_notify (object, "underline-set");
1232 text_tag->rise_set = TRUE;
1233 text_tag->values->appearance.rise = g_value_get_int (value);
1234 g_object_notify (object, "rise-set");
1235 size_changed = TRUE;
1238 case PROP_BACKGROUND_FULL_HEIGHT:
1239 text_tag->bg_full_height_set = TRUE;
1240 text_tag->values->bg_full_height = g_value_get_boolean (value);
1241 g_object_notify (object, "background-full-height-set");
1245 text_tag->language_set = TRUE;
1246 text_tag->values->language = pango_language_from_string (g_value_get_string (value));
1247 g_object_notify (object, "language-set");
1251 text_tag->tabs_set = TRUE;
1253 if (text_tag->values->tabs)
1254 pango_tab_array_free (text_tag->values->tabs);
1256 /* FIXME I'm not sure if this is a memleak or not */
1257 text_tag->values->tabs =
1258 pango_tab_array_copy (g_value_get_boxed (value));
1260 g_object_notify (object, "tabs-set");
1262 size_changed = TRUE;
1265 case PROP_INVISIBLE:
1266 text_tag->invisible_set = TRUE;
1267 text_tag->values->invisible = g_value_get_boolean (value);
1268 g_object_notify (object, "invisible-set");
1269 size_changed = TRUE;
1272 case PROP_PARAGRAPH_BACKGROUND:
1276 if (gdk_color_parse (g_value_get_string (value), &color))
1277 set_pg_bg_color (text_tag, &color);
1279 g_warning ("Don't know color `%s'", g_value_get_string (value));
1281 g_object_notify (object, "paragraph-background-gdk");
1285 case PROP_PARAGRAPH_BACKGROUND_GDK:
1287 GdkColor *color = g_value_get_boxed (value);
1289 set_pg_bg_color (text_tag, color);
1293 /* Whether the value should be used... */
1295 case PROP_BACKGROUND_SET:
1296 text_tag->bg_color_set = g_value_get_boolean (value);
1299 case PROP_FOREGROUND_SET:
1300 text_tag->fg_color_set = g_value_get_boolean (value);
1303 case PROP_BACKGROUND_STIPPLE_SET:
1304 text_tag->bg_stipple_set = g_value_get_boolean (value);
1305 if (!text_tag->bg_stipple_set &&
1306 text_tag->values->appearance.bg_stipple)
1308 g_object_unref (text_tag->values->appearance.bg_stipple);
1309 text_tag->values->appearance.bg_stipple = NULL;
1313 case PROP_FOREGROUND_STIPPLE_SET:
1314 text_tag->fg_stipple_set = g_value_get_boolean (value);
1315 if (!text_tag->fg_stipple_set &&
1316 text_tag->values->appearance.fg_stipple)
1318 g_object_unref (text_tag->values->appearance.fg_stipple);
1319 text_tag->values->appearance.fg_stipple = NULL;
1323 case PROP_FAMILY_SET:
1324 case PROP_STYLE_SET:
1325 case PROP_VARIANT_SET:
1326 case PROP_WEIGHT_SET:
1327 case PROP_STRETCH_SET:
1329 if (!g_value_get_boolean (value))
1331 if (text_tag->values->font)
1332 pango_font_description_unset_fields (text_tag->values->font,
1333 get_property_font_set_mask (prop_id));
1337 PangoFontMask changed_mask;
1339 gtk_text_tag_ensure_font (text_tag);
1340 changed_mask = set_font_desc_fields (text_tag->values->font,
1341 get_property_font_set_mask (prop_id));
1342 notify_fields_changed (G_OBJECT (text_tag), changed_mask);
1346 case PROP_SCALE_SET:
1347 text_tag->scale_set = g_value_get_boolean (value);
1348 size_changed = TRUE;
1351 case PROP_PIXELS_ABOVE_LINES_SET:
1352 text_tag->pixels_above_lines_set = g_value_get_boolean (value);
1353 size_changed = TRUE;
1356 case PROP_PIXELS_BELOW_LINES_SET:
1357 text_tag->pixels_below_lines_set = g_value_get_boolean (value);
1358 size_changed = TRUE;
1361 case PROP_PIXELS_INSIDE_WRAP_SET:
1362 text_tag->pixels_inside_wrap_set = g_value_get_boolean (value);
1363 size_changed = TRUE;
1366 case PROP_EDITABLE_SET:
1367 text_tag->editable_set = g_value_get_boolean (value);
1370 case PROP_WRAP_MODE_SET:
1371 text_tag->wrap_mode_set = g_value_get_boolean (value);
1372 size_changed = TRUE;
1375 case PROP_JUSTIFICATION_SET:
1376 text_tag->justification_set = g_value_get_boolean (value);
1377 size_changed = TRUE;
1380 case PROP_LEFT_MARGIN_SET:
1381 text_tag->left_margin_set = g_value_get_boolean (value);
1382 size_changed = TRUE;
1385 case PROP_INDENT_SET:
1386 text_tag->indent_set = g_value_get_boolean (value);
1387 size_changed = TRUE;
1390 case PROP_STRIKETHROUGH_SET:
1391 text_tag->strikethrough_set = g_value_get_boolean (value);
1394 case PROP_RIGHT_MARGIN_SET:
1395 text_tag->right_margin_set = g_value_get_boolean (value);
1396 size_changed = TRUE;
1399 case PROP_UNDERLINE_SET:
1400 text_tag->underline_set = g_value_get_boolean (value);
1404 text_tag->rise_set = g_value_get_boolean (value);
1405 size_changed = TRUE;
1408 case PROP_BACKGROUND_FULL_HEIGHT_SET:
1409 text_tag->bg_full_height_set = g_value_get_boolean (value);
1412 case PROP_LANGUAGE_SET:
1413 text_tag->language_set = g_value_get_boolean (value);
1414 size_changed = TRUE;
1418 text_tag->tabs_set = g_value_get_boolean (value);
1419 size_changed = TRUE;
1422 case PROP_INVISIBLE_SET:
1423 text_tag->invisible_set = g_value_get_boolean (value);
1424 size_changed = TRUE;
1427 case PROP_PARAGRAPH_BACKGROUND_SET:
1428 text_tag->pg_bg_color_set = g_value_get_boolean (value);
1432 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1436 /* FIXME I would like to do this after all set_property in a single
1437 * g_object_set () have been called. But an idle function won't
1438 * work; we need to emit when the tag is changed, not when we get
1439 * around to the event loop. So blah, we eat some inefficiency.
1442 /* This is also somewhat weird since we emit another object's
1443 * signal here, but the two objects are already tightly bound.
1446 if (text_tag->table)
1447 g_signal_emit_by_name (text_tag->table,
1449 text_tag, size_changed);
1453 gtk_text_tag_get_property (GObject *object,
1460 tag = GTK_TEXT_TAG (object);
1465 g_value_set_string (value, tag->name);
1468 case PROP_BACKGROUND_GDK:
1469 g_value_set_boxed (value, &tag->values->appearance.bg_color);
1472 case PROP_FOREGROUND_GDK:
1473 g_value_set_boxed (value, &tag->values->appearance.fg_color);
1476 case PROP_BACKGROUND_STIPPLE:
1477 if (tag->bg_stipple_set)
1478 g_value_set_object (value, tag->values->appearance.bg_stipple);
1481 case PROP_FOREGROUND_STIPPLE:
1482 if (tag->fg_stipple_set)
1483 g_value_set_object (value, tag->values->appearance.fg_stipple);
1490 gtk_text_tag_ensure_font (tag);
1492 str = pango_font_description_to_string (tag->values->font);
1493 g_value_take_string (value, str);
1497 case PROP_FONT_DESC:
1498 gtk_text_tag_ensure_font (tag);
1499 g_value_set_boxed (value, tag->values->font);
1508 case PROP_SIZE_POINTS:
1509 gtk_text_tag_ensure_font (tag);
1513 g_value_set_string (value, pango_font_description_get_family (tag->values->font));
1517 g_value_set_enum (value, pango_font_description_get_style (tag->values->font));
1521 g_value_set_enum (value, pango_font_description_get_variant (tag->values->font));
1525 g_value_set_int (value, pango_font_description_get_weight (tag->values->font));
1529 g_value_set_enum (value, pango_font_description_get_stretch (tag->values->font));
1533 g_value_set_int (value, pango_font_description_get_size (tag->values->font));
1536 case PROP_SIZE_POINTS:
1537 g_value_set_double (value, ((double)pango_font_description_get_size (tag->values->font)) / (double)PANGO_SCALE);
1543 g_value_set_double (value, tag->values->font_scale);
1546 case PROP_PIXELS_ABOVE_LINES:
1547 g_value_set_int (value, tag->values->pixels_above_lines);
1550 case PROP_PIXELS_BELOW_LINES:
1551 g_value_set_int (value, tag->values->pixels_below_lines);
1554 case PROP_PIXELS_INSIDE_WRAP:
1555 g_value_set_int (value, tag->values->pixels_inside_wrap);
1559 g_value_set_boolean (value, tag->values->editable);
1562 case PROP_WRAP_MODE:
1563 g_value_set_enum (value, tag->values->wrap_mode);
1566 case PROP_JUSTIFICATION:
1567 g_value_set_enum (value, tag->values->justification);
1570 case PROP_DIRECTION:
1571 g_value_set_enum (value, tag->values->direction);
1574 case PROP_LEFT_MARGIN:
1575 g_value_set_int (value, tag->values->left_margin);
1579 g_value_set_int (value, tag->values->indent);
1582 case PROP_STRIKETHROUGH:
1583 g_value_set_boolean (value, tag->values->appearance.strikethrough);
1586 case PROP_RIGHT_MARGIN:
1587 g_value_set_int (value, tag->values->right_margin);
1590 case PROP_UNDERLINE:
1591 g_value_set_enum (value, tag->values->appearance.underline);
1595 g_value_set_int (value, tag->values->appearance.rise);
1598 case PROP_BACKGROUND_FULL_HEIGHT:
1599 g_value_set_boolean (value, tag->values->bg_full_height);
1603 g_value_set_string (value, pango_language_to_string (tag->values->language));
1607 if (tag->values->tabs)
1608 g_value_set_boxed (value, tag->values->tabs);
1611 case PROP_INVISIBLE:
1612 g_value_set_boolean (value, tag->values->invisible);
1615 case PROP_PARAGRAPH_BACKGROUND_GDK:
1616 g_value_set_boxed (value, tag->values->pg_bg_color);
1619 case PROP_BACKGROUND_SET:
1620 g_value_set_boolean (value, tag->bg_color_set);
1623 case PROP_FOREGROUND_SET:
1624 g_value_set_boolean (value, tag->fg_color_set);
1627 case PROP_BACKGROUND_STIPPLE_SET:
1628 g_value_set_boolean (value, tag->bg_stipple_set);
1631 case PROP_FOREGROUND_STIPPLE_SET:
1632 g_value_set_boolean (value, tag->fg_stipple_set);
1635 case PROP_FAMILY_SET:
1636 case PROP_STYLE_SET:
1637 case PROP_VARIANT_SET:
1638 case PROP_WEIGHT_SET:
1639 case PROP_STRETCH_SET:
1642 PangoFontMask set_mask = tag->values->font ? pango_font_description_get_set_fields (tag->values->font) : 0;
1643 PangoFontMask test_mask = get_property_font_set_mask (prop_id);
1644 g_value_set_boolean (value, (set_mask & test_mask) != 0);
1649 case PROP_SCALE_SET:
1650 g_value_set_boolean (value, tag->scale_set);
1653 case PROP_PIXELS_ABOVE_LINES_SET:
1654 g_value_set_boolean (value, tag->pixels_above_lines_set);
1657 case PROP_PIXELS_BELOW_LINES_SET:
1658 g_value_set_boolean (value, tag->pixels_below_lines_set);
1661 case PROP_PIXELS_INSIDE_WRAP_SET:
1662 g_value_set_boolean (value, tag->pixels_inside_wrap_set);
1665 case PROP_EDITABLE_SET:
1666 g_value_set_boolean (value, tag->editable_set);
1669 case PROP_WRAP_MODE_SET:
1670 g_value_set_boolean (value, tag->wrap_mode_set);
1673 case PROP_JUSTIFICATION_SET:
1674 g_value_set_boolean (value, tag->justification_set);
1677 case PROP_LEFT_MARGIN_SET:
1678 g_value_set_boolean (value, tag->left_margin_set);
1681 case PROP_INDENT_SET:
1682 g_value_set_boolean (value, tag->indent_set);
1685 case PROP_STRIKETHROUGH_SET:
1686 g_value_set_boolean (value, tag->strikethrough_set);
1689 case PROP_RIGHT_MARGIN_SET:
1690 g_value_set_boolean (value, tag->right_margin_set);
1693 case PROP_UNDERLINE_SET:
1694 g_value_set_boolean (value, tag->underline_set);
1698 g_value_set_boolean (value, tag->rise_set);
1701 case PROP_BACKGROUND_FULL_HEIGHT_SET:
1702 g_value_set_boolean (value, tag->bg_full_height_set);
1705 case PROP_LANGUAGE_SET:
1706 g_value_set_boolean (value, tag->language_set);
1710 g_value_set_boolean (value, tag->tabs_set);
1713 case PROP_INVISIBLE_SET:
1714 g_value_set_boolean (value, tag->invisible_set);
1717 case PROP_PARAGRAPH_BACKGROUND_SET:
1718 g_value_set_boolean (value, tag->pg_bg_color_set);
1721 case PROP_BACKGROUND:
1722 case PROP_FOREGROUND:
1723 case PROP_PARAGRAPH_BACKGROUND:
1724 g_warning ("'foreground', 'background' and 'paragraph_background' properties are not readable, use 'foreground_gdk', 'background_gdk' and 'paragraph_background_gdk'");
1726 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1742 delta_priority_foreach (GtkTextTag *tag, gpointer user_data)
1744 DeltaData *dd = user_data;
1746 if (tag->priority >= dd->low && tag->priority <= dd->high)
1747 tag->priority += dd->delta;
1751 * gtk_text_tag_get_priority:
1752 * @tag: a #GtkTextTag
1754 * Get the tag priority.
1756 * Return value: The tag's priority.
1759 gtk_text_tag_get_priority (GtkTextTag *tag)
1761 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), 0);
1763 return tag->priority;
1767 * gtk_text_tag_set_priority:
1768 * @tag: a #GtkTextTag
1769 * @priority: the new priority
1771 * Sets the priority of a #GtkTextTag. Valid priorities are
1772 * start at 0 and go to one less than gtk_text_tag_table_get_size().
1773 * Each tag in a table has a unique priority; setting the priority
1774 * of one tag shifts the priorities of all the other tags in the
1775 * table to maintain a unique priority for each tag. Higher priority
1776 * tags "win" if two tags both set the same text attribute. When adding
1777 * a tag to a tag table, it will be assigned the highest priority in
1778 * the table by default; so normally the precedence of a set of tags
1779 * is the order in which they were added to the table, or created with
1780 * gtk_text_buffer_create_tag(), which adds the tag to the buffer's table
1784 gtk_text_tag_set_priority (GtkTextTag *tag,
1789 g_return_if_fail (GTK_IS_TEXT_TAG (tag));
1790 g_return_if_fail (tag->table != NULL);
1791 g_return_if_fail (priority >= 0);
1792 g_return_if_fail (priority < gtk_text_tag_table_get_size (tag->table));
1794 if (priority == tag->priority)
1797 if (priority < tag->priority)
1800 dd.high = tag->priority - 1;
1805 dd.low = tag->priority + 1;
1810 gtk_text_tag_table_foreach (tag->table,
1811 delta_priority_foreach,
1814 tag->priority = priority;
1818 * gtk_text_tag_event:
1819 * @tag: a #GtkTextTag
1820 * @event_object: object that received the event, such as a widget
1822 * @iter: location where the event was received
1824 * Emits the "event" signal on the #GtkTextTag.
1826 * Return value: result of signal emission (whether the event was handled)
1829 gtk_text_tag_event (GtkTextTag *tag,
1830 GObject *event_object,
1832 const GtkTextIter *iter)
1834 gboolean retval = FALSE;
1836 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
1837 g_return_val_if_fail (G_IS_OBJECT (event_object), FALSE);
1838 g_return_val_if_fail (event != NULL, FALSE);
1852 tag_sort_func (gconstpointer first, gconstpointer second)
1854 GtkTextTag *tag1, *tag2;
1856 tag1 = * (GtkTextTag **) first;
1857 tag2 = * (GtkTextTag **) second;
1858 return tag1->priority - tag2->priority;
1862 _gtk_text_tag_array_sort (GtkTextTag** tag_array_p,
1867 GtkTextTag **maxPtrPtr, *tmp;
1869 g_return_if_fail (tag_array_p != NULL);
1870 g_return_if_fail (len > 0);
1876 GtkTextTag **iter = tag_array_p;
1878 for (i = len-1; i > 0; i--, iter++) {
1879 maxPtrPtr = tag = iter;
1880 prio = tag[0]->priority;
1881 for (j = i, tag++; j > 0; j--, tag++) {
1882 if (tag[0]->priority < prio) {
1883 prio = tag[0]->priority;
1892 qsort ((void *) tag_array_p, (unsigned) len, sizeof (GtkTextTag *),
1898 printf ("Sorted tag array: \n");
1902 GtkTextTag *t = tag_array_p[i];
1903 printf (" %s priority %d\n", t->name, t->priority);
1916 * gtk_text_attributes_new:
1918 * Creates a #GtkTextAttributes, which describes
1919 * a set of properties on some text.
1921 * Return value: a new #GtkTextAttributes
1924 gtk_text_attributes_new (void)
1926 GtkTextAttributes *values;
1928 values = g_new0 (GtkTextAttributes, 1);
1930 /* 0 is a valid value for most of the struct */
1932 values->refcount = 1;
1934 values->language = gtk_get_default_language ();
1936 values->font_scale = 1.0;
1938 values->editable = TRUE;
1944 * gtk_text_attributes_copy:
1945 * @src: a #GtkTextAttributes to be copied
1947 * Copies @src and returns a new #GtkTextAttributes.
1949 * Return value: a copy of @src
1952 gtk_text_attributes_copy (GtkTextAttributes *src)
1954 GtkTextAttributes *dest;
1956 dest = gtk_text_attributes_new ();
1957 gtk_text_attributes_copy_values (src, dest);
1963 gtk_text_attributes_get_type (void)
1965 static GType our_type = 0;
1968 our_type = g_boxed_type_register_static (I_("GtkTextAttributes"),
1969 (GBoxedCopyFunc) gtk_text_attributes_ref,
1970 (GBoxedFreeFunc) gtk_text_attributes_unref);
1976 * gtk_text_attributes_copy_values:
1977 * @src: a #GtkTextAttributes
1978 * @dest: another #GtkTextAttributes
1980 * Copies the values from @src to @dest so that @dest has the same values
1981 * as @src. Frees existing values in @dest.
1984 gtk_text_attributes_copy_values (GtkTextAttributes *src,
1985 GtkTextAttributes *dest)
1987 guint orig_refcount;
1989 g_return_if_fail (!dest->realized);
1996 if (src->appearance.bg_stipple)
1997 g_object_ref (src->appearance.bg_stipple);
1999 if (src->appearance.fg_stipple)
2000 g_object_ref (src->appearance.fg_stipple);
2004 if (dest->appearance.bg_stipple)
2005 g_object_unref (dest->appearance.bg_stipple);
2007 if (dest->appearance.fg_stipple)
2008 g_object_unref (dest->appearance.fg_stipple);
2011 pango_font_description_free (dest->font);
2014 orig_refcount = dest->refcount;
2019 dest->tabs = pango_tab_array_copy (src->tabs);
2021 dest->language = src->language;
2024 dest->font = pango_font_description_copy (src->font);
2026 if (src->pg_bg_color)
2027 dest->pg_bg_color = gdk_color_copy (src->pg_bg_color);
2029 dest->refcount = orig_refcount;
2030 dest->realized = FALSE;
2034 * gtk_text_attributes_ref:
2035 * @values: a #GtkTextAttributes
2037 * Increments the reference count on @values.
2039 * Returns: the #GtkTextAttributes that were passed in
2042 gtk_text_attributes_ref (GtkTextAttributes *values)
2044 g_return_val_if_fail (values != NULL, NULL);
2046 values->refcount += 1;
2052 * gtk_text_attributes_unref:
2053 * @values: a #GtkTextAttributes
2055 * Decrements the reference count on @values, freeing the structure
2056 * if the reference count reaches 0.
2059 gtk_text_attributes_unref (GtkTextAttributes *values)
2061 g_return_if_fail (values != NULL);
2062 g_return_if_fail (values->refcount > 0);
2064 values->refcount -= 1;
2066 if (values->refcount == 0)
2068 g_assert (!values->realized);
2070 if (values->appearance.bg_stipple)
2071 g_object_unref (values->appearance.bg_stipple);
2073 if (values->appearance.fg_stipple)
2074 g_object_unref (values->appearance.fg_stipple);
2077 pango_tab_array_free (values->tabs);
2080 pango_font_description_free (values->font);
2082 if (values->pg_bg_color)
2083 gdk_color_free (values->pg_bg_color);
2090 _gtk_text_attributes_realize (GtkTextAttributes *values,
2094 g_return_if_fail (values != NULL);
2095 g_return_if_fail (values->refcount > 0);
2096 g_return_if_fail (!values->realized);
2098 /* It is wrong to use this colormap, FIXME */
2099 gdk_colormap_alloc_color (cmap,
2100 &values->appearance.fg_color,
2103 gdk_colormap_alloc_color (cmap,
2104 &values->appearance.bg_color,
2107 if (values->pg_bg_color)
2108 gdk_colormap_alloc_color (cmap,
2109 values->pg_bg_color,
2112 values->realized = TRUE;
2116 _gtk_text_attributes_unrealize (GtkTextAttributes *values,
2120 g_return_if_fail (values != NULL);
2121 g_return_if_fail (values->refcount > 0);
2122 g_return_if_fail (values->realized);
2124 gdk_colormap_free_colors (cmap,
2125 &values->appearance.fg_color, 1);
2128 gdk_colormap_free_colors (cmap,
2129 &values->appearance.bg_color, 1);
2131 values->appearance.fg_color.pixel = 0;
2132 values->appearance.bg_color.pixel = 0;
2134 if (values->pg_bg_color)
2136 gdk_colormap_free_colors (cmap, values->pg_bg_color, 1);
2138 values->pg_bg_color->pixel = 0;
2141 values->realized = FALSE;
2145 _gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest,
2151 g_return_if_fail (!dest->realized);
2155 GtkTextTag *tag = tags[n];
2156 GtkTextAttributes *vals = tag->values;
2158 g_assert (tag->table != NULL);
2160 g_assert (tags[n]->priority > tags[n-1]->priority);
2162 if (tag->bg_color_set)
2164 dest->appearance.bg_color = vals->appearance.bg_color;
2166 dest->appearance.draw_bg = TRUE;
2168 if (tag->fg_color_set)
2169 dest->appearance.fg_color = vals->appearance.fg_color;
2171 if (tag->pg_bg_color_set)
2173 dest->pg_bg_color = gdk_color_copy (vals->pg_bg_color);
2176 if (tag->bg_stipple_set)
2178 g_object_ref (vals->appearance.bg_stipple);
2179 if (dest->appearance.bg_stipple)
2180 g_object_unref (dest->appearance.bg_stipple);
2181 dest->appearance.bg_stipple = vals->appearance.bg_stipple;
2183 dest->appearance.draw_bg = TRUE;
2186 if (tag->fg_stipple_set)
2188 g_object_ref (vals->appearance.fg_stipple);
2189 if (dest->appearance.fg_stipple)
2190 g_object_unref (dest->appearance.fg_stipple);
2191 dest->appearance.fg_stipple = vals->appearance.fg_stipple;
2197 pango_font_description_merge (dest->font, vals->font, TRUE);
2199 dest->font = pango_font_description_copy (vals->font);
2202 /* multiply all the scales together to get a composite */
2204 dest->font_scale *= vals->font_scale;
2206 if (tag->justification_set)
2207 dest->justification = vals->justification;
2209 if (vals->direction != GTK_TEXT_DIR_NONE)
2210 dest->direction = vals->direction;
2212 if (tag->left_margin_set)
2213 dest->left_margin = vals->left_margin;
2215 if (tag->indent_set)
2216 dest->indent = vals->indent;
2219 dest->appearance.rise = vals->appearance.rise;
2221 if (tag->right_margin_set)
2222 dest->right_margin = vals->right_margin;
2224 if (tag->pixels_above_lines_set)
2225 dest->pixels_above_lines = vals->pixels_above_lines;
2227 if (tag->pixels_below_lines_set)
2228 dest->pixels_below_lines = vals->pixels_below_lines;
2230 if (tag->pixels_inside_wrap_set)
2231 dest->pixels_inside_wrap = vals->pixels_inside_wrap;
2236 pango_tab_array_free (dest->tabs);
2237 dest->tabs = pango_tab_array_copy (vals->tabs);
2240 if (tag->wrap_mode_set)
2241 dest->wrap_mode = vals->wrap_mode;
2243 if (tag->underline_set)
2244 dest->appearance.underline = vals->appearance.underline;
2246 if (tag->strikethrough_set)
2247 dest->appearance.strikethrough = vals->appearance.strikethrough;
2249 if (tag->invisible_set)
2250 dest->invisible = vals->invisible;
2252 if (tag->editable_set)
2253 dest->editable = vals->editable;
2255 if (tag->bg_full_height_set)
2256 dest->bg_full_height = vals->bg_full_height;
2258 if (tag->language_set)
2259 dest->language = vals->language;
2266 _gtk_text_tag_affects_size (GtkTextTag *tag)
2268 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
2271 (tag->values->font && pango_font_description_get_set_fields (tag->values->font) != 0) ||
2273 tag->justification_set ||
2274 tag->left_margin_set ||
2277 tag->right_margin_set ||
2278 tag->pixels_above_lines_set ||
2279 tag->pixels_below_lines_set ||
2280 tag->pixels_inside_wrap_set ||
2282 tag->underline_set ||
2283 tag->wrap_mode_set ||
2288 _gtk_text_tag_affects_nonsize_appearance (GtkTextTag *tag)
2290 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
2293 tag->bg_color_set ||
2294 tag->bg_stipple_set ||
2295 tag->fg_color_set ||
2296 tag->fg_stipple_set ||
2297 tag->strikethrough_set ||
2298 tag->bg_full_height_set ||
2299 tag->pg_bg_color_set;
2302 #define __GTK_TEXT_TAG_C__
2303 #include "gtkaliasdef.c"