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"
57 #include "gtkmarshalers.h"
58 #include "gtkprivate.h"
79 PROP_BACKGROUND_STIPPLE,
80 PROP_FOREGROUND_STIPPLE,
91 PROP_PIXELS_ABOVE_LINES,
92 PROP_PIXELS_BELOW_LINES,
93 PROP_PIXELS_INSIDE_WRAP,
104 PROP_BACKGROUND_FULL_HEIGHT,
108 PROP_PARAGRAPH_BACKGROUND,
109 PROP_PARAGRAPH_BACKGROUND_GDK,
111 /* Whether-a-style-arg-is-set args */
114 PROP_BACKGROUND_STIPPLE_SET,
115 PROP_FOREGROUND_STIPPLE_SET,
123 PROP_PIXELS_ABOVE_LINES_SET,
124 PROP_PIXELS_BELOW_LINES_SET,
125 PROP_PIXELS_INSIDE_WRAP_SET,
128 PROP_JUSTIFICATION_SET,
129 PROP_LEFT_MARGIN_SET,
131 PROP_STRIKETHROUGH_SET,
132 PROP_RIGHT_MARGIN_SET,
135 PROP_BACKGROUND_FULL_HEIGHT_SET,
139 PROP_PARAGRAPH_BACKGROUND_SET,
143 static void gtk_text_tag_init (GtkTextTag *text_tag);
144 static void gtk_text_tag_class_init (GtkTextTagClass *klass);
145 static void gtk_text_tag_finalize (GObject *object);
146 static void gtk_text_tag_set_property (GObject *object,
150 static void gtk_text_tag_get_property (GObject *object,
155 static GObjectClass *parent_class = NULL;
156 static guint signals[LAST_SIGNAL] = { 0 };
159 gtk_text_tag_get_type (void)
161 static GType our_type = 0;
165 static const GTypeInfo our_info =
167 sizeof (GtkTextTagClass),
168 (GBaseInitFunc) NULL,
169 (GBaseFinalizeFunc) NULL,
170 (GClassInitFunc) gtk_text_tag_class_init,
171 NULL, /* class_finalize */
172 NULL, /* class_data */
175 (GInstanceInitFunc) gtk_text_tag_init
178 our_type = g_type_register_static (G_TYPE_OBJECT, "GtkTextTag",
186 gtk_text_tag_class_init (GtkTextTagClass *klass)
188 GObjectClass *object_class = G_OBJECT_CLASS (klass);
190 parent_class = g_type_class_peek_parent (klass);
192 object_class->set_property = gtk_text_tag_set_property;
193 object_class->get_property = gtk_text_tag_get_property;
195 object_class->finalize = gtk_text_tag_finalize;
198 g_object_class_install_property (object_class,
200 g_param_spec_string ("name",
202 P_("Name used to refer to the text tag. NULL for anonymous tags"),
204 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
208 g_object_class_install_property (object_class,
210 g_param_spec_string ("background",
211 P_("Background color name"),
212 P_("Background color as a string"),
214 GTK_PARAM_WRITABLE));
216 g_object_class_install_property (object_class,
218 g_param_spec_boxed ("background-gdk",
219 P_("Background color"),
220 P_("Background color as a (possibly unallocated) GdkColor"),
222 GTK_PARAM_READWRITE));
224 g_object_class_install_property (object_class,
225 PROP_BACKGROUND_FULL_HEIGHT,
226 g_param_spec_boolean ("background-full-height",
227 P_("Background full height"),
228 P_("Whether the background color fills the entire line height or only the height of the tagged characters"),
230 GTK_PARAM_READWRITE));
233 g_object_class_install_property (object_class,
234 PROP_BACKGROUND_STIPPLE,
235 g_param_spec_object ("background-stipple",
236 P_("Background stipple mask"),
237 P_("Bitmap to use as a mask when drawing the text background"),
239 GTK_PARAM_READWRITE));
242 g_object_class_install_property (object_class,
244 g_param_spec_string ("foreground",
245 P_("Foreground color name"),
246 P_("Foreground color as a string"),
248 GTK_PARAM_WRITABLE));
250 g_object_class_install_property (object_class,
252 g_param_spec_boxed ("foreground-gdk",
253 P_("Foreground color"),
254 P_("Foreground color as a (possibly unallocated) GdkColor"),
256 GTK_PARAM_READWRITE));
259 g_object_class_install_property (object_class,
260 PROP_FOREGROUND_STIPPLE,
261 g_param_spec_object ("foreground-stipple",
262 P_("Foreground stipple mask"),
263 P_("Bitmap to use as a mask when drawing the text foreground"),
265 GTK_PARAM_READWRITE));
267 g_object_class_install_property (object_class,
269 g_param_spec_enum ("direction",
270 P_("Text direction"),
271 P_("Text direction, e.g. right-to-left or left-to-right"),
272 GTK_TYPE_TEXT_DIRECTION,
274 GTK_PARAM_READWRITE));
276 g_object_class_install_property (object_class,
278 g_param_spec_boolean ("editable",
280 P_("Whether the text can be modified by the user"),
282 GTK_PARAM_READWRITE));
284 g_object_class_install_property (object_class,
286 g_param_spec_string ("font",
288 P_("Font description as a string, e.g. \"Sans Italic 12\""),
290 GTK_PARAM_READWRITE));
292 g_object_class_install_property (object_class,
294 g_param_spec_boxed ("font-desc",
296 P_("Font description as a PangoFontDescription struct"),
297 PANGO_TYPE_FONT_DESCRIPTION,
298 GTK_PARAM_READWRITE));
301 g_object_class_install_property (object_class,
303 g_param_spec_string ("family",
305 P_("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
307 GTK_PARAM_READWRITE));
309 g_object_class_install_property (object_class,
311 g_param_spec_enum ("style",
313 P_("Font style as a PangoStyle, e.g. PANGO_STYLE_ITALIC"),
316 GTK_PARAM_READWRITE));
318 g_object_class_install_property (object_class,
320 g_param_spec_enum ("variant",
322 P_("Font variant as a PangoVariant, e.g. PANGO_VARIANT_SMALL_CAPS"),
324 PANGO_VARIANT_NORMAL,
325 GTK_PARAM_READWRITE));
327 g_object_class_install_property (object_class,
329 g_param_spec_int ("weight",
331 P_("Font weight as an integer, see predefined values in PangoWeight; for example, PANGO_WEIGHT_BOLD"),
335 GTK_PARAM_READWRITE));
338 g_object_class_install_property (object_class,
340 g_param_spec_enum ("stretch",
342 P_("Font stretch as a PangoStretch, e.g. PANGO_STRETCH_CONDENSED"),
344 PANGO_STRETCH_NORMAL,
345 GTK_PARAM_READWRITE));
347 g_object_class_install_property (object_class,
349 g_param_spec_int ("size",
351 P_("Font size in Pango units"),
355 GTK_PARAM_READWRITE));
357 g_object_class_install_property (object_class,
359 g_param_spec_double ("scale",
361 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"),
365 GTK_PARAM_READWRITE));
367 g_object_class_install_property (object_class,
369 g_param_spec_double ("size-points",
371 P_("Font size in points"),
375 GTK_PARAM_READWRITE));
377 g_object_class_install_property (object_class,
379 g_param_spec_enum ("justification",
381 P_("Left, right, or center justification"),
382 GTK_TYPE_JUSTIFICATION,
384 GTK_PARAM_READWRITE));
386 g_object_class_install_property (object_class,
388 g_param_spec_string ("language",
390 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."),
392 GTK_PARAM_READWRITE));
394 g_object_class_install_property (object_class,
396 g_param_spec_int ("left-margin",
398 P_("Width of the left margin in pixels"),
402 GTK_PARAM_READWRITE));
404 g_object_class_install_property (object_class,
406 g_param_spec_int ("right-margin",
408 P_("Width of the right margin in pixels"),
412 GTK_PARAM_READWRITE));
415 g_object_class_install_property (object_class,
417 g_param_spec_int ("indent",
419 P_("Amount to indent the paragraph, in pixels"),
423 GTK_PARAM_READWRITE));
426 g_object_class_install_property (object_class,
428 g_param_spec_int ("rise",
430 P_("Offset of text above the baseline (below the baseline if rise is negative) in Pango units"),
434 GTK_PARAM_READWRITE));
436 g_object_class_install_property (object_class,
437 PROP_PIXELS_ABOVE_LINES,
438 g_param_spec_int ("pixels-above-lines",
439 P_("Pixels above lines"),
440 P_("Pixels of blank space above paragraphs"),
444 GTK_PARAM_READWRITE));
446 g_object_class_install_property (object_class,
447 PROP_PIXELS_BELOW_LINES,
448 g_param_spec_int ("pixels-below-lines",
449 P_("Pixels below lines"),
450 P_("Pixels of blank space below paragraphs"),
454 GTK_PARAM_READWRITE));
456 g_object_class_install_property (object_class,
457 PROP_PIXELS_INSIDE_WRAP,
458 g_param_spec_int ("pixels-inside-wrap",
459 P_("Pixels inside wrap"),
460 P_("Pixels of blank space between wrapped lines in a paragraph"),
464 GTK_PARAM_READWRITE));
466 g_object_class_install_property (object_class,
468 g_param_spec_boolean ("strikethrough",
470 P_("Whether to strike through the text"),
472 GTK_PARAM_READWRITE));
474 g_object_class_install_property (object_class,
476 g_param_spec_enum ("underline",
478 P_("Style of underline for this text"),
479 PANGO_TYPE_UNDERLINE,
480 PANGO_UNDERLINE_NONE,
481 GTK_PARAM_READWRITE));
483 g_object_class_install_property (object_class,
485 g_param_spec_enum ("wrap-mode",
487 P_("Whether to wrap lines never, at word boundaries, or at character boundaries"),
490 GTK_PARAM_READWRITE));
493 g_object_class_install_property (object_class,
495 g_param_spec_boxed ("tabs",
497 P_("Custom tabs for this text"),
498 PANGO_TYPE_TAB_ARRAY,
499 GTK_PARAM_READWRITE));
501 g_object_class_install_property (object_class,
503 g_param_spec_boolean ("invisible",
505 P_("Whether this text is hidden. Not implemented in GTK 2.0"),
507 GTK_PARAM_READWRITE));
510 * GtkTextTag:paragraph-background:
512 * The paragraph background color as a string.
516 g_object_class_install_property (object_class,
517 PROP_PARAGRAPH_BACKGROUND,
518 g_param_spec_string ("paragraph-background",
519 P_("Paragraph background color name"),
520 P_("Paragraph background color as a string"),
522 GTK_PARAM_WRITABLE));
525 * GtkTextTag:paragraph-background-gdk:
527 * The paragraph background color as a as a (possibly unallocated)
532 g_object_class_install_property (object_class,
533 PROP_PARAGRAPH_BACKGROUND_GDK,
534 g_param_spec_boxed ("paragraph-background-gdk",
535 P_("Paragraph background color"),
536 P_("Paragraph background color as a (possibly unallocated) GdkColor"),
538 GTK_PARAM_READWRITE));
540 /* Style props are set or not */
542 #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))
544 ADD_SET_PROP ("background-set", PROP_BACKGROUND_SET,
545 P_("Background set"),
546 P_("Whether this tag affects the background color"));
548 ADD_SET_PROP ("background-full-height-set", PROP_BACKGROUND_FULL_HEIGHT_SET,
549 P_("Background full height set"),
550 P_("Whether this tag affects background height"));
552 ADD_SET_PROP ("background-stipple-set", PROP_BACKGROUND_STIPPLE_SET,
553 P_("Background stipple set"),
554 P_("Whether this tag affects the background stipple"));
556 ADD_SET_PROP ("foreground-set", PROP_FOREGROUND_SET,
557 P_("Foreground set"),
558 P_("Whether this tag affects the foreground color"));
560 ADD_SET_PROP ("foreground-stipple-set", PROP_FOREGROUND_STIPPLE_SET,
561 P_("Foreground stipple set"),
562 P_("Whether this tag affects the foreground stipple"));
564 ADD_SET_PROP ("editable-set", PROP_EDITABLE_SET,
565 P_("Editability set"),
566 P_("Whether this tag affects text editability"));
568 ADD_SET_PROP ("family-set", PROP_FAMILY_SET,
569 P_("Font family set"),
570 P_("Whether this tag affects the font family"));
572 ADD_SET_PROP ("style-set", PROP_STYLE_SET,
573 P_("Font style set"),
574 P_("Whether this tag affects the font style"));
576 ADD_SET_PROP ("variant-set", PROP_VARIANT_SET,
577 P_("Font variant set"),
578 P_("Whether this tag affects the font variant"));
580 ADD_SET_PROP ("weight-set", PROP_WEIGHT_SET,
581 P_("Font weight set"),
582 P_("Whether this tag affects the font weight"));
584 ADD_SET_PROP ("stretch-set", PROP_STRETCH_SET,
585 P_("Font stretch set"),
586 P_("Whether this tag affects the font stretch"));
588 ADD_SET_PROP ("size-set", PROP_SIZE_SET,
590 P_("Whether this tag affects the font size"));
592 ADD_SET_PROP ("scale-set", PROP_SCALE_SET,
593 P_("Font scale set"),
594 P_("Whether this tag scales the font size by a factor"));
596 ADD_SET_PROP ("justification-set", PROP_JUSTIFICATION_SET,
597 P_("Justification set"),
598 P_("Whether this tag affects paragraph justification"));
600 ADD_SET_PROP ("language-set", PROP_LANGUAGE_SET,
602 P_("Whether this tag affects the language the text is rendered as"));
604 ADD_SET_PROP ("left-margin-set", PROP_LEFT_MARGIN_SET,
605 P_("Left margin set"),
606 P_("Whether this tag affects the left margin"));
608 ADD_SET_PROP ("indent-set", PROP_INDENT_SET,
610 P_("Whether this tag affects indentation"));
612 ADD_SET_PROP ("rise-set", PROP_RISE_SET,
614 P_("Whether this tag affects the rise"));
616 ADD_SET_PROP ("pixels-above-lines-set", PROP_PIXELS_ABOVE_LINES_SET,
617 P_("Pixels above lines set"),
618 P_("Whether this tag affects the number of pixels above lines"));
620 ADD_SET_PROP ("pixels-below-lines-set", PROP_PIXELS_BELOW_LINES_SET,
621 P_("Pixels below lines set"),
622 P_("Whether this tag affects the number of pixels above lines"));
624 ADD_SET_PROP ("pixels-inside-wrap-set", PROP_PIXELS_INSIDE_WRAP_SET,
625 P_("Pixels inside wrap set"),
626 P_("Whether this tag affects the number of pixels between wrapped lines"));
628 ADD_SET_PROP ("strikethrough-set", PROP_STRIKETHROUGH_SET,
629 P_("Strikethrough set"),
630 P_("Whether this tag affects strikethrough"));
632 ADD_SET_PROP ("right-margin-set", PROP_RIGHT_MARGIN_SET,
633 P_("Right margin set"),
634 P_("Whether this tag affects the right margin"));
636 ADD_SET_PROP ("underline-set", PROP_UNDERLINE_SET,
638 P_("Whether this tag affects underlining"));
640 ADD_SET_PROP ("wrap-mode-set", PROP_WRAP_MODE_SET,
642 P_("Whether this tag affects line wrap mode"));
644 ADD_SET_PROP ("tabs-set", PROP_TABS_SET,
646 P_("Whether this tag affects tabs"));
648 ADD_SET_PROP ("invisible-set", PROP_INVISIBLE_SET,
650 P_("Whether this tag affects text visibility"));
652 ADD_SET_PROP ("paragraph-background-set", PROP_PARAGRAPH_BACKGROUND_SET,
653 P_("Paragraph background set"),
654 P_("Whether this tag affects the paragraph background color"));
657 g_signal_new ("event",
658 G_OBJECT_CLASS_TYPE (object_class),
660 G_STRUCT_OFFSET (GtkTextTagClass, event),
661 _gtk_boolean_handled_accumulator, NULL,
662 _gtk_marshal_BOOLEAN__OBJECT_BOXED_BOXED,
666 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE,
671 gtk_text_tag_init (GtkTextTag *text_tag)
673 /* 0 is basically a fine way to initialize everything in the
676 text_tag->values = gtk_text_attributes_new ();
681 * @name: tag name, or %NULL
683 * Creates a #GtkTextTag. Configure the tag using object arguments,
684 * i.e. using g_object_set().
686 * Return value: a new #GtkTextTag
689 gtk_text_tag_new (const gchar *name)
693 tag = g_object_new (GTK_TYPE_TEXT_TAG, "name", name, NULL);
699 gtk_text_tag_finalize (GObject *object)
701 GtkTextTag *text_tag;
703 text_tag = GTK_TEXT_TAG (object);
705 g_assert (!text_tag->values->realized);
708 gtk_text_tag_table_remove (text_tag->table, text_tag);
710 g_assert (text_tag->table == NULL);
712 gtk_text_attributes_unref (text_tag->values);
713 text_tag->values = NULL;
715 g_free (text_tag->name);
716 text_tag->name = NULL;
718 (* G_OBJECT_CLASS (parent_class)->finalize) (object);
722 set_bg_color (GtkTextTag *tag, GdkColor *color)
726 if (!tag->bg_color_set)
728 tag->bg_color_set = TRUE;
729 g_object_notify (G_OBJECT (tag), "background-set");
732 tag->values->appearance.bg_color = *color;
736 if (tag->bg_color_set)
738 tag->bg_color_set = FALSE;
739 g_object_notify (G_OBJECT (tag), "background-set");
745 set_fg_color (GtkTextTag *tag, GdkColor *color)
749 if (!tag->fg_color_set)
751 tag->fg_color_set = TRUE;
752 g_object_notify (G_OBJECT (tag), "foreground-set");
754 tag->values->appearance.fg_color = *color;
758 if (tag->fg_color_set)
760 tag->fg_color_set = FALSE;
761 g_object_notify (G_OBJECT (tag), "foreground-set");
767 set_pg_bg_color (GtkTextTag *tag, GdkColor *color)
771 if (!tag->pg_bg_color_set)
773 tag->pg_bg_color_set = TRUE;
774 g_object_notify (G_OBJECT (tag), "paragraph-background-set");
777 gdk_color_free (tag->values->pg_bg_color);
779 tag->values->pg_bg_color = gdk_color_copy (color);
783 if (tag->pg_bg_color_set)
785 tag->pg_bg_color_set = FALSE;
786 g_object_notify (G_OBJECT (tag), "paragraph-background-set");
787 gdk_color_free (tag->values->pg_bg_color);
790 tag->values->pg_bg_color = NULL;
795 get_property_font_set_mask (guint prop_id)
799 case PROP_FAMILY_SET:
800 return PANGO_FONT_MASK_FAMILY;
802 return PANGO_FONT_MASK_STYLE;
803 case PROP_VARIANT_SET:
804 return PANGO_FONT_MASK_VARIANT;
805 case PROP_WEIGHT_SET:
806 return PANGO_FONT_MASK_WEIGHT;
807 case PROP_STRETCH_SET:
808 return PANGO_FONT_MASK_STRETCH;
810 return PANGO_FONT_MASK_SIZE;
817 set_font_desc_fields (PangoFontDescription *desc,
818 PangoFontMask to_set)
820 PangoFontMask changed_mask = 0;
822 if (to_set & PANGO_FONT_MASK_FAMILY)
824 const char *family = pango_font_description_get_family (desc);
828 changed_mask |= PANGO_FONT_MASK_FAMILY;
831 pango_font_description_set_family (desc, family);
833 if (to_set & PANGO_FONT_MASK_STYLE)
834 pango_font_description_set_style (desc, pango_font_description_get_style (desc));
835 if (to_set & PANGO_FONT_MASK_VARIANT)
836 pango_font_description_set_variant (desc, pango_font_description_get_variant (desc));
837 if (to_set & PANGO_FONT_MASK_WEIGHT)
838 pango_font_description_set_weight (desc, pango_font_description_get_weight (desc));
839 if (to_set & PANGO_FONT_MASK_STRETCH)
840 pango_font_description_set_stretch (desc, pango_font_description_get_stretch (desc));
841 if (to_set & PANGO_FONT_MASK_SIZE)
843 gint size = pango_font_description_get_size (desc);
846 size = 10 * PANGO_SCALE;
847 changed_mask |= PANGO_FONT_MASK_SIZE;
850 pango_font_description_set_size (desc, size);
857 notify_set_changed (GObject *object,
858 PangoFontMask changed_mask)
860 if (changed_mask & PANGO_FONT_MASK_FAMILY)
861 g_object_notify (object, "family-set");
862 if (changed_mask & PANGO_FONT_MASK_STYLE)
863 g_object_notify (object, "style-set");
864 if (changed_mask & PANGO_FONT_MASK_VARIANT)
865 g_object_notify (object, "variant-set");
866 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
867 g_object_notify (object, "weight-set");
868 if (changed_mask & PANGO_FONT_MASK_STRETCH)
869 g_object_notify (object, "stretch-set");
870 if (changed_mask & PANGO_FONT_MASK_SIZE)
871 g_object_notify (object, "size-set");
875 notify_fields_changed (GObject *object,
876 PangoFontMask changed_mask)
878 if (changed_mask & PANGO_FONT_MASK_FAMILY)
879 g_object_notify (object, "family");
880 if (changed_mask & PANGO_FONT_MASK_STYLE)
881 g_object_notify (object, "style");
882 if (changed_mask & PANGO_FONT_MASK_VARIANT)
883 g_object_notify (object, "variant");
884 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
885 g_object_notify (object, "weight");
886 if (changed_mask & PANGO_FONT_MASK_STRETCH)
887 g_object_notify (object, "stretch");
888 if (changed_mask & PANGO_FONT_MASK_SIZE)
889 g_object_notify (object, "size");
893 set_font_description (GtkTextTag *text_tag,
894 PangoFontDescription *font_desc)
896 GObject *object = G_OBJECT (text_tag);
897 PangoFontDescription *new_font_desc;
898 PangoFontMask old_mask, new_mask, changed_mask, set_changed_mask;
901 new_font_desc = pango_font_description_copy (font_desc);
903 new_font_desc = pango_font_description_new ();
905 if (text_tag->values->font)
906 old_mask = pango_font_description_get_set_fields (text_tag->values->font);
910 new_mask = pango_font_description_get_set_fields (new_font_desc);
912 changed_mask = old_mask | new_mask;
913 set_changed_mask = old_mask ^ new_mask;
915 if (text_tag->values->font)
916 pango_font_description_free (text_tag->values->font);
917 text_tag->values->font = new_font_desc;
919 g_object_freeze_notify (object);
921 g_object_notify (object, "font-desc");
922 g_object_notify (object, "font");
924 if (changed_mask & PANGO_FONT_MASK_FAMILY)
925 g_object_notify (object, "family");
926 if (changed_mask & PANGO_FONT_MASK_STYLE)
927 g_object_notify (object, "style");
928 if (changed_mask & PANGO_FONT_MASK_VARIANT)
929 g_object_notify (object, "variant");
930 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
931 g_object_notify (object, "weight");
932 if (changed_mask & PANGO_FONT_MASK_STRETCH)
933 g_object_notify (object, "stretch");
934 if (changed_mask & PANGO_FONT_MASK_SIZE)
936 g_object_notify (object, "size");
937 g_object_notify (object, "size-points");
940 notify_set_changed (object, set_changed_mask);
942 g_object_thaw_notify (object);
946 gtk_text_tag_ensure_font (GtkTextTag *text_tag)
948 if (!text_tag->values->font)
949 text_tag->values->font = pango_font_description_new ();
953 gtk_text_tag_set_property (GObject *object,
958 GtkTextTag *text_tag;
959 gboolean size_changed = FALSE;
961 text_tag = GTK_TEXT_TAG (object);
963 g_return_if_fail (!text_tag->values->realized);
968 g_return_if_fail (text_tag->name == NULL);
969 text_tag->name = g_strdup (g_value_get_string (value));
972 case PROP_BACKGROUND:
976 if (gdk_color_parse (g_value_get_string (value), &color))
977 set_bg_color (text_tag, &color);
979 g_warning ("Don't know color `%s'", g_value_get_string (value));
981 g_object_notify (object, "background-gdk");
985 case PROP_FOREGROUND:
989 if (gdk_color_parse (g_value_get_string (value), &color))
990 set_fg_color (text_tag, &color);
992 g_warning ("Don't know color `%s'", g_value_get_string (value));
994 g_object_notify (object, "foreground-gdk");
998 case PROP_BACKGROUND_GDK:
1000 GdkColor *color = g_value_get_boxed (value);
1002 set_bg_color (text_tag, color);
1006 case PROP_FOREGROUND_GDK:
1008 GdkColor *color = g_value_get_boxed (value);
1010 set_fg_color (text_tag, color);
1014 case PROP_BACKGROUND_STIPPLE:
1016 GdkBitmap *bitmap = g_value_get_object (value);
1018 text_tag->bg_stipple_set = TRUE;
1019 g_object_notify (object, "background-stipple-set");
1021 if (text_tag->values->appearance.bg_stipple != bitmap)
1024 g_object_ref (bitmap);
1026 if (text_tag->values->appearance.bg_stipple)
1027 g_object_unref (text_tag->values->appearance.bg_stipple);
1029 text_tag->values->appearance.bg_stipple = bitmap;
1034 case PROP_FOREGROUND_STIPPLE:
1036 GdkBitmap *bitmap = g_value_get_object (value);
1038 text_tag->fg_stipple_set = TRUE;
1039 g_object_notify (object, "foreground-stipple-set");
1041 if (text_tag->values->appearance.fg_stipple != bitmap)
1044 g_object_ref (bitmap);
1046 if (text_tag->values->appearance.fg_stipple)
1047 g_object_unref (text_tag->values->appearance.fg_stipple);
1049 text_tag->values->appearance.fg_stipple = bitmap;
1056 PangoFontDescription *font_desc = NULL;
1059 name = g_value_get_string (value);
1062 font_desc = pango_font_description_from_string (name);
1064 set_font_description (text_tag, font_desc);
1066 pango_font_description_free (font_desc);
1068 size_changed = TRUE;
1072 case PROP_FONT_DESC:
1074 PangoFontDescription *font_desc;
1076 font_desc = g_value_get_boxed (value);
1078 set_font_description (text_tag, font_desc);
1080 size_changed = TRUE;
1090 case PROP_SIZE_POINTS:
1092 PangoFontMask old_set_mask;
1094 gtk_text_tag_ensure_font (text_tag);
1095 old_set_mask = pango_font_description_get_set_fields (text_tag->values->font);
1100 pango_font_description_set_family (text_tag->values->font,
1101 g_value_get_string (value));
1104 pango_font_description_set_style (text_tag->values->font,
1105 g_value_get_enum (value));
1108 pango_font_description_set_variant (text_tag->values->font,
1109 g_value_get_enum (value));
1112 pango_font_description_set_weight (text_tag->values->font,
1113 g_value_get_int (value));
1116 pango_font_description_set_stretch (text_tag->values->font,
1117 g_value_get_enum (value));
1120 pango_font_description_set_size (text_tag->values->font,
1121 g_value_get_int (value));
1122 g_object_notify (object, "size-points");
1124 case PROP_SIZE_POINTS:
1125 pango_font_description_set_size (text_tag->values->font,
1126 g_value_get_double (value) * PANGO_SCALE);
1127 g_object_notify (object, "size");
1131 size_changed = TRUE;
1132 notify_set_changed (object, old_set_mask & pango_font_description_get_set_fields (text_tag->values->font));
1133 g_object_notify (object, "font-desc");
1134 g_object_notify (object, "font");
1140 text_tag->values->font_scale = g_value_get_double (value);
1141 text_tag->scale_set = TRUE;
1142 g_object_notify (object, "scale-set");
1143 size_changed = TRUE;
1146 case PROP_PIXELS_ABOVE_LINES:
1147 text_tag->pixels_above_lines_set = TRUE;
1148 text_tag->values->pixels_above_lines = g_value_get_int (value);
1149 g_object_notify (object, "pixels-above-lines-set");
1150 size_changed = TRUE;
1153 case PROP_PIXELS_BELOW_LINES:
1154 text_tag->pixels_below_lines_set = TRUE;
1155 text_tag->values->pixels_below_lines = g_value_get_int (value);
1156 g_object_notify (object, "pixels-below-lines-set");
1157 size_changed = TRUE;
1160 case PROP_PIXELS_INSIDE_WRAP:
1161 text_tag->pixels_inside_wrap_set = TRUE;
1162 text_tag->values->pixels_inside_wrap = g_value_get_int (value);
1163 g_object_notify (object, "pixels-inside-wrap-set");
1164 size_changed = TRUE;
1168 text_tag->editable_set = TRUE;
1169 text_tag->values->editable = g_value_get_boolean (value);
1170 g_object_notify (object, "editable-set");
1173 case PROP_WRAP_MODE:
1174 text_tag->wrap_mode_set = TRUE;
1175 text_tag->values->wrap_mode = g_value_get_enum (value);
1176 g_object_notify (object, "wrap-mode-set");
1177 size_changed = TRUE;
1180 case PROP_JUSTIFICATION:
1181 text_tag->justification_set = TRUE;
1182 text_tag->values->justification = g_value_get_enum (value);
1183 g_object_notify (object, "justification-set");
1184 size_changed = TRUE;
1187 case PROP_DIRECTION:
1188 text_tag->values->direction = g_value_get_enum (value);
1191 case PROP_LEFT_MARGIN:
1192 text_tag->left_margin_set = TRUE;
1193 text_tag->values->left_margin = g_value_get_int (value);
1194 g_object_notify (object, "left-margin-set");
1195 size_changed = TRUE;
1199 text_tag->indent_set = TRUE;
1200 text_tag->values->indent = g_value_get_int (value);
1201 g_object_notify (object, "indent-set");
1202 size_changed = TRUE;
1205 case PROP_STRIKETHROUGH:
1206 text_tag->strikethrough_set = TRUE;
1207 text_tag->values->appearance.strikethrough = g_value_get_boolean (value);
1208 g_object_notify (object, "strikethrough-set");
1211 case PROP_RIGHT_MARGIN:
1212 text_tag->right_margin_set = TRUE;
1213 text_tag->values->right_margin = g_value_get_int (value);
1214 g_object_notify (object, "right-margin-set");
1215 size_changed = TRUE;
1218 case PROP_UNDERLINE:
1219 text_tag->underline_set = TRUE;
1220 text_tag->values->appearance.underline = g_value_get_enum (value);
1221 g_object_notify (object, "underline-set");
1225 text_tag->rise_set = TRUE;
1226 text_tag->values->appearance.rise = g_value_get_int (value);
1227 g_object_notify (object, "rise-set");
1228 size_changed = TRUE;
1231 case PROP_BACKGROUND_FULL_HEIGHT:
1232 text_tag->bg_full_height_set = TRUE;
1233 text_tag->values->bg_full_height = g_value_get_boolean (value);
1234 g_object_notify (object, "background-full-height-set");
1238 text_tag->language_set = TRUE;
1239 text_tag->values->language = pango_language_from_string (g_value_get_string (value));
1240 g_object_notify (object, "language-set");
1244 text_tag->tabs_set = TRUE;
1246 if (text_tag->values->tabs)
1247 pango_tab_array_free (text_tag->values->tabs);
1249 /* FIXME I'm not sure if this is a memleak or not */
1250 text_tag->values->tabs =
1251 pango_tab_array_copy (g_value_get_boxed (value));
1253 g_object_notify (object, "tabs-set");
1255 size_changed = TRUE;
1258 case PROP_INVISIBLE:
1259 g_warning ("The \"invisible\" property on GtkTextTag is not supported for GTK 2.0, it will be added in a future release. see http://bugzilla.gnome.org bug #66194 for status.");
1260 text_tag->invisible_set = TRUE;
1261 text_tag->values->invisible = g_value_get_boolean (value);
1262 g_object_notify (object, "invisible-set");
1263 size_changed = TRUE;
1266 case PROP_PARAGRAPH_BACKGROUND:
1270 if (gdk_color_parse (g_value_get_string (value), &color))
1271 set_pg_bg_color (text_tag, &color);
1273 g_warning ("Don't know color `%s'", g_value_get_string (value));
1275 g_object_notify (object, "paragraph-background-gdk");
1279 case PROP_PARAGRAPH_BACKGROUND_GDK:
1281 GdkColor *color = g_value_get_boxed (value);
1283 set_pg_bg_color (text_tag, color);
1287 /* Whether the value should be used... */
1289 case PROP_BACKGROUND_SET:
1290 text_tag->bg_color_set = g_value_get_boolean (value);
1293 case PROP_FOREGROUND_SET:
1294 text_tag->fg_color_set = g_value_get_boolean (value);
1297 case PROP_BACKGROUND_STIPPLE_SET:
1298 text_tag->bg_stipple_set = g_value_get_boolean (value);
1299 if (!text_tag->bg_stipple_set &&
1300 text_tag->values->appearance.bg_stipple)
1302 g_object_unref (text_tag->values->appearance.bg_stipple);
1303 text_tag->values->appearance.bg_stipple = NULL;
1307 case PROP_FOREGROUND_STIPPLE_SET:
1308 text_tag->fg_stipple_set = g_value_get_boolean (value);
1309 if (!text_tag->fg_stipple_set &&
1310 text_tag->values->appearance.fg_stipple)
1312 g_object_unref (text_tag->values->appearance.fg_stipple);
1313 text_tag->values->appearance.fg_stipple = NULL;
1317 case PROP_FAMILY_SET:
1318 case PROP_STYLE_SET:
1319 case PROP_VARIANT_SET:
1320 case PROP_WEIGHT_SET:
1321 case PROP_STRETCH_SET:
1323 if (!g_value_get_boolean (value))
1325 if (text_tag->values->font)
1326 pango_font_description_unset_fields (text_tag->values->font,
1327 get_property_font_set_mask (prop_id));
1331 PangoFontMask changed_mask;
1333 gtk_text_tag_ensure_font (text_tag);
1334 changed_mask = set_font_desc_fields (text_tag->values->font,
1335 get_property_font_set_mask (prop_id));
1336 notify_fields_changed (G_OBJECT (text_tag), changed_mask);
1340 case PROP_SCALE_SET:
1341 text_tag->scale_set = g_value_get_boolean (value);
1342 size_changed = TRUE;
1345 case PROP_PIXELS_ABOVE_LINES_SET:
1346 text_tag->pixels_above_lines_set = g_value_get_boolean (value);
1347 size_changed = TRUE;
1350 case PROP_PIXELS_BELOW_LINES_SET:
1351 text_tag->pixels_below_lines_set = g_value_get_boolean (value);
1352 size_changed = TRUE;
1355 case PROP_PIXELS_INSIDE_WRAP_SET:
1356 text_tag->pixels_inside_wrap_set = g_value_get_boolean (value);
1357 size_changed = TRUE;
1360 case PROP_EDITABLE_SET:
1361 text_tag->editable_set = g_value_get_boolean (value);
1364 case PROP_WRAP_MODE_SET:
1365 text_tag->wrap_mode_set = g_value_get_boolean (value);
1366 size_changed = TRUE;
1369 case PROP_JUSTIFICATION_SET:
1370 text_tag->justification_set = g_value_get_boolean (value);
1371 size_changed = TRUE;
1374 case PROP_LEFT_MARGIN_SET:
1375 text_tag->left_margin_set = g_value_get_boolean (value);
1376 size_changed = TRUE;
1379 case PROP_INDENT_SET:
1380 text_tag->indent_set = g_value_get_boolean (value);
1381 size_changed = TRUE;
1384 case PROP_STRIKETHROUGH_SET:
1385 text_tag->strikethrough_set = g_value_get_boolean (value);
1388 case PROP_RIGHT_MARGIN_SET:
1389 text_tag->right_margin_set = g_value_get_boolean (value);
1390 size_changed = TRUE;
1393 case PROP_UNDERLINE_SET:
1394 text_tag->underline_set = g_value_get_boolean (value);
1398 text_tag->rise_set = g_value_get_boolean (value);
1399 size_changed = TRUE;
1402 case PROP_BACKGROUND_FULL_HEIGHT_SET:
1403 text_tag->bg_full_height_set = g_value_get_boolean (value);
1406 case PROP_LANGUAGE_SET:
1407 text_tag->language_set = g_value_get_boolean (value);
1408 size_changed = TRUE;
1412 text_tag->tabs_set = g_value_get_boolean (value);
1413 size_changed = TRUE;
1416 case PROP_INVISIBLE_SET:
1417 text_tag->invisible_set = g_value_get_boolean (value);
1418 size_changed = TRUE;
1421 case PROP_PARAGRAPH_BACKGROUND_SET:
1422 text_tag->pg_bg_color_set = g_value_get_boolean (value);
1426 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1430 /* FIXME I would like to do this after all set_property in a single
1431 * g_object_set () have been called. But an idle function won't
1432 * work; we need to emit when the tag is changed, not when we get
1433 * around to the event loop. So blah, we eat some inefficiency.
1436 /* This is also somewhat weird since we emit another object's
1437 * signal here, but the two objects are already tightly bound.
1440 if (text_tag->table)
1441 g_signal_emit_by_name (text_tag->table,
1443 text_tag, size_changed);
1447 gtk_text_tag_get_property (GObject *object,
1454 tag = GTK_TEXT_TAG (object);
1459 g_value_set_string (value, tag->name);
1462 case PROP_BACKGROUND_GDK:
1463 g_value_set_boxed (value, &tag->values->appearance.bg_color);
1466 case PROP_FOREGROUND_GDK:
1467 g_value_set_boxed (value, &tag->values->appearance.fg_color);
1470 case PROP_BACKGROUND_STIPPLE:
1471 if (tag->bg_stipple_set)
1472 g_value_set_object (value, tag->values->appearance.bg_stipple);
1475 case PROP_FOREGROUND_STIPPLE:
1476 if (tag->fg_stipple_set)
1477 g_value_set_object (value, tag->values->appearance.fg_stipple);
1482 /* FIXME GValue imposes a totally gratuitous string copy
1483 * here, we could just hand off string ownership
1487 gtk_text_tag_ensure_font (tag);
1489 str = pango_font_description_to_string (tag->values->font);
1490 g_value_set_string (value, str);
1495 case PROP_FONT_DESC:
1496 gtk_text_tag_ensure_font (tag);
1497 g_value_set_boxed (value, tag->values->font);
1506 case PROP_SIZE_POINTS:
1507 gtk_text_tag_ensure_font (tag);
1511 g_value_set_string (value, pango_font_description_get_family (tag->values->font));
1515 g_value_set_enum (value, pango_font_description_get_style (tag->values->font));
1519 g_value_set_enum (value, pango_font_description_get_variant (tag->values->font));
1523 g_value_set_int (value, pango_font_description_get_weight (tag->values->font));
1527 g_value_set_enum (value, pango_font_description_get_stretch (tag->values->font));
1531 g_value_set_int (value, pango_font_description_get_size (tag->values->font));
1534 case PROP_SIZE_POINTS:
1535 g_value_set_double (value, ((double)pango_font_description_get_size (tag->values->font)) / (double)PANGO_SCALE);
1541 g_value_set_double (value, tag->values->font_scale);
1544 case PROP_PIXELS_ABOVE_LINES:
1545 g_value_set_int (value, tag->values->pixels_above_lines);
1548 case PROP_PIXELS_BELOW_LINES:
1549 g_value_set_int (value, tag->values->pixels_below_lines);
1552 case PROP_PIXELS_INSIDE_WRAP:
1553 g_value_set_int (value, tag->values->pixels_inside_wrap);
1557 g_value_set_boolean (value, tag->values->editable);
1560 case PROP_WRAP_MODE:
1561 g_value_set_enum (value, tag->values->wrap_mode);
1564 case PROP_JUSTIFICATION:
1565 g_value_set_enum (value, tag->values->justification);
1568 case PROP_DIRECTION:
1569 g_value_set_enum (value, tag->values->direction);
1572 case PROP_LEFT_MARGIN:
1573 g_value_set_int (value, tag->values->left_margin);
1577 g_value_set_int (value, tag->values->indent);
1580 case PROP_STRIKETHROUGH:
1581 g_value_set_boolean (value, tag->values->appearance.strikethrough);
1584 case PROP_RIGHT_MARGIN:
1585 g_value_set_int (value, tag->values->right_margin);
1588 case PROP_UNDERLINE:
1589 g_value_set_enum (value, tag->values->appearance.underline);
1593 g_value_set_int (value, tag->values->appearance.rise);
1596 case PROP_BACKGROUND_FULL_HEIGHT:
1597 g_value_set_boolean (value, tag->values->bg_full_height);
1601 g_value_set_string (value, pango_language_to_string (tag->values->language));
1605 if (tag->values->tabs)
1606 g_value_set_boxed (value, tag->values->tabs);
1609 case PROP_INVISIBLE:
1610 g_value_set_boolean (value, tag->values->invisible);
1613 case PROP_PARAGRAPH_BACKGROUND_GDK:
1614 g_value_set_boxed (value, tag->values->pg_bg_color);
1617 case PROP_BACKGROUND_SET:
1618 g_value_set_boolean (value, tag->bg_color_set);
1621 case PROP_FOREGROUND_SET:
1622 g_value_set_boolean (value, tag->fg_color_set);
1625 case PROP_BACKGROUND_STIPPLE_SET:
1626 g_value_set_boolean (value, tag->bg_stipple_set);
1629 case PROP_FOREGROUND_STIPPLE_SET:
1630 g_value_set_boolean (value, tag->fg_stipple_set);
1633 case PROP_FAMILY_SET:
1634 case PROP_STYLE_SET:
1635 case PROP_VARIANT_SET:
1636 case PROP_WEIGHT_SET:
1637 case PROP_STRETCH_SET:
1640 PangoFontMask set_mask = tag->values->font ? pango_font_description_get_set_fields (tag->values->font) : 0;
1641 PangoFontMask test_mask = get_property_font_set_mask (prop_id);
1642 g_value_set_boolean (value, (set_mask & test_mask) != 0);
1647 case PROP_SCALE_SET:
1648 g_value_set_boolean (value, tag->scale_set);
1651 case PROP_PIXELS_ABOVE_LINES_SET:
1652 g_value_set_boolean (value, tag->pixels_above_lines_set);
1655 case PROP_PIXELS_BELOW_LINES_SET:
1656 g_value_set_boolean (value, tag->pixels_below_lines_set);
1659 case PROP_PIXELS_INSIDE_WRAP_SET:
1660 g_value_set_boolean (value, tag->pixels_inside_wrap_set);
1663 case PROP_EDITABLE_SET:
1664 g_value_set_boolean (value, tag->editable_set);
1667 case PROP_WRAP_MODE_SET:
1668 g_value_set_boolean (value, tag->wrap_mode_set);
1671 case PROP_JUSTIFICATION_SET:
1672 g_value_set_boolean (value, tag->justification_set);
1675 case PROP_LEFT_MARGIN_SET:
1676 g_value_set_boolean (value, tag->left_margin_set);
1679 case PROP_INDENT_SET:
1680 g_value_set_boolean (value, tag->indent_set);
1683 case PROP_STRIKETHROUGH_SET:
1684 g_value_set_boolean (value, tag->strikethrough_set);
1687 case PROP_RIGHT_MARGIN_SET:
1688 g_value_set_boolean (value, tag->right_margin_set);
1691 case PROP_UNDERLINE_SET:
1692 g_value_set_boolean (value, tag->underline_set);
1696 g_value_set_boolean (value, tag->rise_set);
1699 case PROP_BACKGROUND_FULL_HEIGHT_SET:
1700 g_value_set_boolean (value, tag->bg_full_height_set);
1703 case PROP_LANGUAGE_SET:
1704 g_value_set_boolean (value, tag->language_set);
1708 g_value_set_boolean (value, tag->tabs_set);
1711 case PROP_INVISIBLE_SET:
1712 g_value_set_boolean (value, tag->invisible_set);
1715 case PROP_PARAGRAPH_BACKGROUND_SET:
1716 g_value_set_boolean (value, tag->pg_bg_color_set);
1719 case PROP_BACKGROUND:
1720 case PROP_FOREGROUND:
1721 case PROP_PARAGRAPH_BACKGROUND:
1722 g_warning ("'foreground', 'background' and 'paragraph_background' properties are not readable, use 'foreground_gdk', 'background_gdk' and 'paragraph_background_gdk'");
1724 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1740 delta_priority_foreach (GtkTextTag *tag, gpointer user_data)
1742 DeltaData *dd = user_data;
1744 if (tag->priority >= dd->low && tag->priority <= dd->high)
1745 tag->priority += dd->delta;
1749 * gtk_text_tag_get_priority:
1750 * @tag: a #GtkTextTag
1752 * Get the tag priority.
1754 * Return value: The tag's priority.
1757 gtk_text_tag_get_priority (GtkTextTag *tag)
1759 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), 0);
1761 return tag->priority;
1765 * gtk_text_tag_set_priority:
1766 * @tag: a #GtkTextTag
1767 * @priority: the new priority
1769 * Sets the priority of a #GtkTextTag. Valid priorities are
1770 * start at 0 and go to one less than gtk_text_tag_table_get_size().
1771 * Each tag in a table has a unique priority; setting the priority
1772 * of one tag shifts the priorities of all the other tags in the
1773 * table to maintain a unique priority for each tag. Higher priority
1774 * tags "win" if two tags both set the same text attribute. When adding
1775 * a tag to a tag table, it will be assigned the highest priority in
1776 * the table by default; so normally the precedence of a set of tags
1777 * is the order in which they were added to the table, or created with
1778 * gtk_text_buffer_create_tag(), which adds the tag to the buffer's table
1782 gtk_text_tag_set_priority (GtkTextTag *tag,
1787 g_return_if_fail (GTK_IS_TEXT_TAG (tag));
1788 g_return_if_fail (tag->table != NULL);
1789 g_return_if_fail (priority >= 0);
1790 g_return_if_fail (priority < gtk_text_tag_table_get_size (tag->table));
1792 if (priority == tag->priority)
1795 if (priority < tag->priority)
1798 dd.high = tag->priority - 1;
1803 dd.low = tag->priority + 1;
1808 gtk_text_tag_table_foreach (tag->table,
1809 delta_priority_foreach,
1812 tag->priority = priority;
1816 * gtk_text_tag_event:
1817 * @tag: a #GtkTextTag
1818 * @event_object: object that received the event, such as a widget
1820 * @iter: location where the event was received
1822 * Emits the "event" signal on the #GtkTextTag.
1824 * Return value: result of signal emission (whether the event was handled)
1827 gtk_text_tag_event (GtkTextTag *tag,
1828 GObject *event_object,
1830 const GtkTextIter *iter)
1832 gboolean retval = FALSE;
1834 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
1835 g_return_val_if_fail (G_IS_OBJECT (event_object), FALSE);
1836 g_return_val_if_fail (event != NULL, FALSE);
1850 tag_sort_func (gconstpointer first, gconstpointer second)
1852 GtkTextTag *tag1, *tag2;
1854 tag1 = * (GtkTextTag **) first;
1855 tag2 = * (GtkTextTag **) second;
1856 return tag1->priority - tag2->priority;
1860 _gtk_text_tag_array_sort (GtkTextTag** tag_array_p,
1865 GtkTextTag **maxPtrPtr, *tmp;
1867 g_return_if_fail (tag_array_p != NULL);
1868 g_return_if_fail (len > 0);
1874 GtkTextTag **iter = tag_array_p;
1876 for (i = len-1; i > 0; i--, iter++) {
1877 maxPtrPtr = tag = iter;
1878 prio = tag[0]->priority;
1879 for (j = i, tag++; j > 0; j--, tag++) {
1880 if (tag[0]->priority < prio) {
1881 prio = tag[0]->priority;
1890 qsort ((void *) tag_array_p, (unsigned) len, sizeof (GtkTextTag *),
1896 printf ("Sorted tag array: \n");
1900 GtkTextTag *t = tag_array_p[i];
1901 printf (" %s priority %d\n", t->name, t->priority);
1914 * gtk_text_attributes_new:
1916 * Creates a #GtkTextAttributes, which describes
1917 * a set of properties on some text.
1919 * Return value: a new #GtkTextAttributes
1922 gtk_text_attributes_new (void)
1924 GtkTextAttributes *values;
1926 values = g_new0 (GtkTextAttributes, 1);
1928 /* 0 is a valid value for most of the struct */
1930 values->refcount = 1;
1932 values->language = gtk_get_default_language ();
1934 values->font_scale = 1.0;
1940 * gtk_text_attributes_copy:
1941 * @src: a #GtkTextAttributes to be copied
1943 * Copies @src and returns a new #GtkTextAttributes.
1945 * Return value: a copy of @src
1948 gtk_text_attributes_copy (GtkTextAttributes *src)
1950 GtkTextAttributes *dest;
1952 dest = gtk_text_attributes_new ();
1953 gtk_text_attributes_copy_values (src, dest);
1959 gtk_text_attributes_get_type (void)
1961 static GType our_type = 0;
1964 our_type = g_boxed_type_register_static ("GtkTextAttributes",
1965 (GBoxedCopyFunc) gtk_text_attributes_ref,
1966 (GBoxedFreeFunc) gtk_text_attributes_unref);
1972 * gtk_text_attributes_copy_values:
1973 * @src: a #GtkTextAttributes
1974 * @dest: another #GtkTextAttributes
1976 * Copies the values from @src to @dest so that @dest has the same values
1977 * as @src. Frees existing values in @dest.
1980 gtk_text_attributes_copy_values (GtkTextAttributes *src,
1981 GtkTextAttributes *dest)
1983 guint orig_refcount;
1985 g_return_if_fail (!dest->realized);
1992 if (src->appearance.bg_stipple)
1993 g_object_ref (src->appearance.bg_stipple);
1995 if (src->appearance.fg_stipple)
1996 g_object_ref (src->appearance.fg_stipple);
2000 if (dest->appearance.bg_stipple)
2001 g_object_unref (dest->appearance.bg_stipple);
2003 if (dest->appearance.fg_stipple)
2004 g_object_unref (dest->appearance.fg_stipple);
2007 pango_font_description_free (dest->font);
2010 orig_refcount = dest->refcount;
2015 dest->tabs = pango_tab_array_copy (src->tabs);
2017 dest->language = src->language;
2020 dest->font = pango_font_description_copy (src->font);
2022 if (src->pg_bg_color)
2023 dest->pg_bg_color = gdk_color_copy (src->pg_bg_color);
2025 dest->refcount = orig_refcount;
2026 dest->realized = FALSE;
2030 * gtk_text_attributes_ref:
2031 * @values: a #GtkTextAttributes
2033 * Increments the reference count on @values.
2036 gtk_text_attributes_ref (GtkTextAttributes *values)
2038 g_return_if_fail (values != NULL);
2040 values->refcount += 1;
2044 * gtk_text_attributes_unref:
2045 * @values: a #GtkTextAttributes
2047 * Decrements the reference count on @values, freeing the structure
2048 * if the reference count reaches 0.
2051 gtk_text_attributes_unref (GtkTextAttributes *values)
2053 g_return_if_fail (values != NULL);
2054 g_return_if_fail (values->refcount > 0);
2056 values->refcount -= 1;
2058 if (values->refcount == 0)
2060 g_assert (!values->realized);
2062 if (values->appearance.bg_stipple)
2063 g_object_unref (values->appearance.bg_stipple);
2065 if (values->appearance.fg_stipple)
2066 g_object_unref (values->appearance.fg_stipple);
2069 pango_tab_array_free (values->tabs);
2072 pango_font_description_free (values->font);
2074 if (values->pg_bg_color)
2075 gdk_color_free (values->pg_bg_color);
2082 _gtk_text_attributes_realize (GtkTextAttributes *values,
2086 g_return_if_fail (values != NULL);
2087 g_return_if_fail (values->refcount > 0);
2088 g_return_if_fail (!values->realized);
2090 /* It is wrong to use this colormap, FIXME */
2091 gdk_colormap_alloc_color (cmap,
2092 &values->appearance.fg_color,
2095 gdk_colormap_alloc_color (cmap,
2096 &values->appearance.bg_color,
2099 if (values->pg_bg_color)
2100 gdk_colormap_alloc_color (cmap,
2101 values->pg_bg_color,
2104 values->realized = TRUE;
2108 _gtk_text_attributes_unrealize (GtkTextAttributes *values,
2112 g_return_if_fail (values != NULL);
2113 g_return_if_fail (values->refcount > 0);
2114 g_return_if_fail (values->realized);
2116 gdk_colormap_free_colors (cmap,
2117 &values->appearance.fg_color, 1);
2120 gdk_colormap_free_colors (cmap,
2121 &values->appearance.bg_color, 1);
2123 values->appearance.fg_color.pixel = 0;
2124 values->appearance.bg_color.pixel = 0;
2126 if (values->pg_bg_color)
2128 gdk_colormap_free_colors (cmap, values->pg_bg_color, 1);
2130 values->pg_bg_color->pixel = 0;
2133 values->realized = FALSE;
2137 _gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest,
2143 g_return_if_fail (!dest->realized);
2147 GtkTextTag *tag = tags[n];
2148 GtkTextAttributes *vals = tag->values;
2150 g_assert (tag->table != NULL);
2152 g_assert (tags[n]->priority > tags[n-1]->priority);
2154 if (tag->bg_color_set)
2156 dest->appearance.bg_color = vals->appearance.bg_color;
2158 dest->appearance.draw_bg = TRUE;
2160 if (tag->fg_color_set)
2161 dest->appearance.fg_color = vals->appearance.fg_color;
2163 if (tag->pg_bg_color_set)
2165 dest->pg_bg_color = gdk_color_copy (vals->pg_bg_color);
2168 if (tag->bg_stipple_set)
2170 g_object_ref (vals->appearance.bg_stipple);
2171 if (dest->appearance.bg_stipple)
2172 g_object_unref (dest->appearance.bg_stipple);
2173 dest->appearance.bg_stipple = vals->appearance.bg_stipple;
2175 dest->appearance.draw_bg = TRUE;
2178 if (tag->fg_stipple_set)
2180 g_object_ref (vals->appearance.fg_stipple);
2181 if (dest->appearance.fg_stipple)
2182 g_object_unref (dest->appearance.fg_stipple);
2183 dest->appearance.fg_stipple = vals->appearance.fg_stipple;
2189 pango_font_description_merge (dest->font, vals->font, TRUE);
2191 dest->font = pango_font_description_copy (vals->font);
2194 /* multiply all the scales together to get a composite */
2196 dest->font_scale *= vals->font_scale;
2198 if (tag->justification_set)
2199 dest->justification = vals->justification;
2201 if (vals->direction != GTK_TEXT_DIR_NONE)
2202 dest->direction = vals->direction;
2204 if (tag->left_margin_set)
2205 dest->left_margin = vals->left_margin;
2207 if (tag->indent_set)
2208 dest->indent = vals->indent;
2211 dest->appearance.rise = vals->appearance.rise;
2213 if (tag->right_margin_set)
2214 dest->right_margin = vals->right_margin;
2216 if (tag->pixels_above_lines_set)
2217 dest->pixels_above_lines = vals->pixels_above_lines;
2219 if (tag->pixels_below_lines_set)
2220 dest->pixels_below_lines = vals->pixels_below_lines;
2222 if (tag->pixels_inside_wrap_set)
2223 dest->pixels_inside_wrap = vals->pixels_inside_wrap;
2228 pango_tab_array_free (dest->tabs);
2229 dest->tabs = pango_tab_array_copy (vals->tabs);
2232 if (tag->wrap_mode_set)
2233 dest->wrap_mode = vals->wrap_mode;
2235 if (tag->underline_set)
2236 dest->appearance.underline = vals->appearance.underline;
2238 if (tag->strikethrough_set)
2239 dest->appearance.strikethrough = vals->appearance.strikethrough;
2241 if (tag->invisible_set)
2242 dest->invisible = vals->invisible;
2244 if (tag->editable_set)
2245 dest->editable = vals->editable;
2247 if (tag->bg_full_height_set)
2248 dest->bg_full_height = vals->bg_full_height;
2250 if (tag->language_set)
2251 dest->language = vals->language;
2258 _gtk_text_tag_affects_size (GtkTextTag *tag)
2260 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
2263 (tag->values->font && pango_font_description_get_set_fields (tag->values->font) != 0) ||
2265 tag->justification_set ||
2266 tag->left_margin_set ||
2269 tag->right_margin_set ||
2270 tag->pixels_above_lines_set ||
2271 tag->pixels_below_lines_set ||
2272 tag->pixels_inside_wrap_set ||
2274 tag->underline_set ||
2275 tag->wrap_mode_set ||
2280 _gtk_text_tag_affects_nonsize_appearance (GtkTextTag *tag)
2282 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
2285 tag->bg_color_set ||
2286 tag->bg_stipple_set ||
2287 tag->fg_color_set ||
2288 tag->fg_stipple_set ||
2289 tag->strikethrough_set ||
2290 tag->bg_full_height_set ||
2291 tag->pg_bg_color_set;
2294 #define __GTK_TEXT_TAG_C__
2295 #include "gtkaliasdef.c"