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"));
654 g_signal_new (I_("event"),
655 G_OBJECT_CLASS_TYPE (object_class),
657 G_STRUCT_OFFSET (GtkTextTagClass, event),
658 _gtk_boolean_handled_accumulator, NULL,
659 _gtk_marshal_BOOLEAN__OBJECT_BOXED_BOXED,
663 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE,
668 gtk_text_tag_init (GtkTextTag *text_tag)
670 text_tag->values = gtk_text_attributes_new ();
675 * @name: tag name, or %NULL
677 * Creates a #GtkTextTag. Configure the tag using object arguments,
678 * i.e. using g_object_set().
680 * Return value: a new #GtkTextTag
683 gtk_text_tag_new (const gchar *name)
687 tag = g_object_new (GTK_TYPE_TEXT_TAG, "name", name, NULL);
693 gtk_text_tag_finalize (GObject *object)
695 GtkTextTag *text_tag;
697 text_tag = GTK_TEXT_TAG (object);
699 g_assert (!text_tag->values->realized);
702 gtk_text_tag_table_remove (text_tag->table, text_tag);
704 g_assert (text_tag->table == NULL);
706 gtk_text_attributes_unref (text_tag->values);
707 text_tag->values = NULL;
709 g_free (text_tag->name);
710 text_tag->name = NULL;
712 (* G_OBJECT_CLASS (gtk_text_tag_parent_class)->finalize) (object);
716 set_bg_color (GtkTextTag *tag, GdkColor *color)
720 if (!tag->bg_color_set)
722 tag->bg_color_set = TRUE;
723 g_object_notify (G_OBJECT (tag), "background-set");
726 tag->values->appearance.bg_color = *color;
730 if (tag->bg_color_set)
732 tag->bg_color_set = FALSE;
733 g_object_notify (G_OBJECT (tag), "background-set");
739 set_fg_color (GtkTextTag *tag, GdkColor *color)
743 if (!tag->fg_color_set)
745 tag->fg_color_set = TRUE;
746 g_object_notify (G_OBJECT (tag), "foreground-set");
748 tag->values->appearance.fg_color = *color;
752 if (tag->fg_color_set)
754 tag->fg_color_set = FALSE;
755 g_object_notify (G_OBJECT (tag), "foreground-set");
761 set_pg_bg_color (GtkTextTag *tag, GdkColor *color)
765 if (!tag->pg_bg_color_set)
767 tag->pg_bg_color_set = TRUE;
768 g_object_notify (G_OBJECT (tag), "paragraph-background-set");
771 gdk_color_free (tag->values->pg_bg_color);
773 tag->values->pg_bg_color = gdk_color_copy (color);
777 if (tag->pg_bg_color_set)
779 tag->pg_bg_color_set = FALSE;
780 g_object_notify (G_OBJECT (tag), "paragraph-background-set");
781 gdk_color_free (tag->values->pg_bg_color);
784 tag->values->pg_bg_color = NULL;
789 get_property_font_set_mask (guint prop_id)
793 case PROP_FAMILY_SET:
794 return PANGO_FONT_MASK_FAMILY;
796 return PANGO_FONT_MASK_STYLE;
797 case PROP_VARIANT_SET:
798 return PANGO_FONT_MASK_VARIANT;
799 case PROP_WEIGHT_SET:
800 return PANGO_FONT_MASK_WEIGHT;
801 case PROP_STRETCH_SET:
802 return PANGO_FONT_MASK_STRETCH;
804 return PANGO_FONT_MASK_SIZE;
811 set_font_desc_fields (PangoFontDescription *desc,
812 PangoFontMask to_set)
814 PangoFontMask changed_mask = 0;
816 if (to_set & PANGO_FONT_MASK_FAMILY)
818 const char *family = pango_font_description_get_family (desc);
822 changed_mask |= PANGO_FONT_MASK_FAMILY;
825 pango_font_description_set_family (desc, family);
827 if (to_set & PANGO_FONT_MASK_STYLE)
828 pango_font_description_set_style (desc, pango_font_description_get_style (desc));
829 if (to_set & PANGO_FONT_MASK_VARIANT)
830 pango_font_description_set_variant (desc, pango_font_description_get_variant (desc));
831 if (to_set & PANGO_FONT_MASK_WEIGHT)
832 pango_font_description_set_weight (desc, pango_font_description_get_weight (desc));
833 if (to_set & PANGO_FONT_MASK_STRETCH)
834 pango_font_description_set_stretch (desc, pango_font_description_get_stretch (desc));
835 if (to_set & PANGO_FONT_MASK_SIZE)
837 gint size = pango_font_description_get_size (desc);
840 size = 10 * PANGO_SCALE;
841 changed_mask |= PANGO_FONT_MASK_SIZE;
844 pango_font_description_set_size (desc, size);
851 notify_set_changed (GObject *object,
852 PangoFontMask changed_mask)
854 if (changed_mask & PANGO_FONT_MASK_FAMILY)
855 g_object_notify (object, "family-set");
856 if (changed_mask & PANGO_FONT_MASK_STYLE)
857 g_object_notify (object, "style-set");
858 if (changed_mask & PANGO_FONT_MASK_VARIANT)
859 g_object_notify (object, "variant-set");
860 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
861 g_object_notify (object, "weight-set");
862 if (changed_mask & PANGO_FONT_MASK_STRETCH)
863 g_object_notify (object, "stretch-set");
864 if (changed_mask & PANGO_FONT_MASK_SIZE)
865 g_object_notify (object, "size-set");
869 notify_fields_changed (GObject *object,
870 PangoFontMask changed_mask)
872 if (changed_mask & PANGO_FONT_MASK_FAMILY)
873 g_object_notify (object, "family");
874 if (changed_mask & PANGO_FONT_MASK_STYLE)
875 g_object_notify (object, "style");
876 if (changed_mask & PANGO_FONT_MASK_VARIANT)
877 g_object_notify (object, "variant");
878 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
879 g_object_notify (object, "weight");
880 if (changed_mask & PANGO_FONT_MASK_STRETCH)
881 g_object_notify (object, "stretch");
882 if (changed_mask & PANGO_FONT_MASK_SIZE)
883 g_object_notify (object, "size");
887 set_font_description (GtkTextTag *text_tag,
888 PangoFontDescription *font_desc)
890 GObject *object = G_OBJECT (text_tag);
891 PangoFontDescription *new_font_desc;
892 PangoFontMask old_mask, new_mask, changed_mask, set_changed_mask;
895 new_font_desc = pango_font_description_copy (font_desc);
897 new_font_desc = pango_font_description_new ();
899 if (text_tag->values->font)
900 old_mask = pango_font_description_get_set_fields (text_tag->values->font);
904 new_mask = pango_font_description_get_set_fields (new_font_desc);
906 changed_mask = old_mask | new_mask;
907 set_changed_mask = old_mask ^ new_mask;
909 if (text_tag->values->font)
910 pango_font_description_free (text_tag->values->font);
911 text_tag->values->font = new_font_desc;
913 g_object_freeze_notify (object);
915 g_object_notify (object, "font-desc");
916 g_object_notify (object, "font");
918 if (changed_mask & PANGO_FONT_MASK_FAMILY)
919 g_object_notify (object, "family");
920 if (changed_mask & PANGO_FONT_MASK_STYLE)
921 g_object_notify (object, "style");
922 if (changed_mask & PANGO_FONT_MASK_VARIANT)
923 g_object_notify (object, "variant");
924 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
925 g_object_notify (object, "weight");
926 if (changed_mask & PANGO_FONT_MASK_STRETCH)
927 g_object_notify (object, "stretch");
928 if (changed_mask & PANGO_FONT_MASK_SIZE)
930 g_object_notify (object, "size");
931 g_object_notify (object, "size-points");
934 notify_set_changed (object, set_changed_mask);
936 g_object_thaw_notify (object);
940 gtk_text_tag_ensure_font (GtkTextTag *text_tag)
942 if (!text_tag->values->font)
943 text_tag->values->font = pango_font_description_new ();
947 gtk_text_tag_set_property (GObject *object,
952 GtkTextTag *text_tag;
953 gboolean size_changed = FALSE;
955 text_tag = GTK_TEXT_TAG (object);
957 g_return_if_fail (!text_tag->values->realized);
962 g_return_if_fail (text_tag->name == NULL);
963 text_tag->name = g_strdup (g_value_get_string (value));
966 case PROP_BACKGROUND:
970 if (gdk_color_parse (g_value_get_string (value), &color))
971 set_bg_color (text_tag, &color);
973 g_warning ("Don't know color `%s'", g_value_get_string (value));
975 g_object_notify (object, "background-gdk");
979 case PROP_FOREGROUND:
983 if (gdk_color_parse (g_value_get_string (value), &color))
984 set_fg_color (text_tag, &color);
986 g_warning ("Don't know color `%s'", g_value_get_string (value));
988 g_object_notify (object, "foreground-gdk");
992 case PROP_BACKGROUND_GDK:
994 GdkColor *color = g_value_get_boxed (value);
996 set_bg_color (text_tag, color);
1000 case PROP_FOREGROUND_GDK:
1002 GdkColor *color = g_value_get_boxed (value);
1004 set_fg_color (text_tag, color);
1008 case PROP_BACKGROUND_STIPPLE:
1010 GdkBitmap *bitmap = g_value_get_object (value);
1012 text_tag->bg_stipple_set = TRUE;
1013 g_object_notify (object, "background-stipple-set");
1015 if (text_tag->values->appearance.bg_stipple != bitmap)
1018 g_object_ref (bitmap);
1020 if (text_tag->values->appearance.bg_stipple)
1021 g_object_unref (text_tag->values->appearance.bg_stipple);
1023 text_tag->values->appearance.bg_stipple = bitmap;
1028 case PROP_FOREGROUND_STIPPLE:
1030 GdkBitmap *bitmap = g_value_get_object (value);
1032 text_tag->fg_stipple_set = TRUE;
1033 g_object_notify (object, "foreground-stipple-set");
1035 if (text_tag->values->appearance.fg_stipple != bitmap)
1038 g_object_ref (bitmap);
1040 if (text_tag->values->appearance.fg_stipple)
1041 g_object_unref (text_tag->values->appearance.fg_stipple);
1043 text_tag->values->appearance.fg_stipple = bitmap;
1050 PangoFontDescription *font_desc = NULL;
1053 name = g_value_get_string (value);
1056 font_desc = pango_font_description_from_string (name);
1058 set_font_description (text_tag, font_desc);
1060 pango_font_description_free (font_desc);
1062 size_changed = TRUE;
1066 case PROP_FONT_DESC:
1068 PangoFontDescription *font_desc;
1070 font_desc = g_value_get_boxed (value);
1072 set_font_description (text_tag, font_desc);
1074 size_changed = TRUE;
1084 case PROP_SIZE_POINTS:
1086 PangoFontMask old_set_mask;
1088 gtk_text_tag_ensure_font (text_tag);
1089 old_set_mask = pango_font_description_get_set_fields (text_tag->values->font);
1094 pango_font_description_set_family (text_tag->values->font,
1095 g_value_get_string (value));
1098 pango_font_description_set_style (text_tag->values->font,
1099 g_value_get_enum (value));
1102 pango_font_description_set_variant (text_tag->values->font,
1103 g_value_get_enum (value));
1106 pango_font_description_set_weight (text_tag->values->font,
1107 g_value_get_int (value));
1110 pango_font_description_set_stretch (text_tag->values->font,
1111 g_value_get_enum (value));
1114 pango_font_description_set_size (text_tag->values->font,
1115 g_value_get_int (value));
1116 g_object_notify (object, "size-points");
1118 case PROP_SIZE_POINTS:
1119 pango_font_description_set_size (text_tag->values->font,
1120 g_value_get_double (value) * PANGO_SCALE);
1121 g_object_notify (object, "size");
1125 size_changed = TRUE;
1126 notify_set_changed (object, old_set_mask & pango_font_description_get_set_fields (text_tag->values->font));
1127 g_object_notify (object, "font-desc");
1128 g_object_notify (object, "font");
1134 text_tag->values->font_scale = g_value_get_double (value);
1135 text_tag->scale_set = TRUE;
1136 g_object_notify (object, "scale-set");
1137 size_changed = TRUE;
1140 case PROP_PIXELS_ABOVE_LINES:
1141 text_tag->pixels_above_lines_set = TRUE;
1142 text_tag->values->pixels_above_lines = g_value_get_int (value);
1143 g_object_notify (object, "pixels-above-lines-set");
1144 size_changed = TRUE;
1147 case PROP_PIXELS_BELOW_LINES:
1148 text_tag->pixels_below_lines_set = TRUE;
1149 text_tag->values->pixels_below_lines = g_value_get_int (value);
1150 g_object_notify (object, "pixels-below-lines-set");
1151 size_changed = TRUE;
1154 case PROP_PIXELS_INSIDE_WRAP:
1155 text_tag->pixels_inside_wrap_set = TRUE;
1156 text_tag->values->pixels_inside_wrap = g_value_get_int (value);
1157 g_object_notify (object, "pixels-inside-wrap-set");
1158 size_changed = TRUE;
1162 text_tag->editable_set = TRUE;
1163 text_tag->values->editable = g_value_get_boolean (value);
1164 g_object_notify (object, "editable-set");
1167 case PROP_WRAP_MODE:
1168 text_tag->wrap_mode_set = TRUE;
1169 text_tag->values->wrap_mode = g_value_get_enum (value);
1170 g_object_notify (object, "wrap-mode-set");
1171 size_changed = TRUE;
1174 case PROP_JUSTIFICATION:
1175 text_tag->justification_set = TRUE;
1176 text_tag->values->justification = g_value_get_enum (value);
1177 g_object_notify (object, "justification-set");
1178 size_changed = TRUE;
1181 case PROP_DIRECTION:
1182 text_tag->values->direction = g_value_get_enum (value);
1185 case PROP_LEFT_MARGIN:
1186 text_tag->left_margin_set = TRUE;
1187 text_tag->values->left_margin = g_value_get_int (value);
1188 g_object_notify (object, "left-margin-set");
1189 size_changed = TRUE;
1193 text_tag->indent_set = TRUE;
1194 text_tag->values->indent = g_value_get_int (value);
1195 g_object_notify (object, "indent-set");
1196 size_changed = TRUE;
1199 case PROP_STRIKETHROUGH:
1200 text_tag->strikethrough_set = TRUE;
1201 text_tag->values->appearance.strikethrough = g_value_get_boolean (value);
1202 g_object_notify (object, "strikethrough-set");
1205 case PROP_RIGHT_MARGIN:
1206 text_tag->right_margin_set = TRUE;
1207 text_tag->values->right_margin = g_value_get_int (value);
1208 g_object_notify (object, "right-margin-set");
1209 size_changed = TRUE;
1212 case PROP_UNDERLINE:
1213 text_tag->underline_set = TRUE;
1214 text_tag->values->appearance.underline = g_value_get_enum (value);
1215 g_object_notify (object, "underline-set");
1219 text_tag->rise_set = TRUE;
1220 text_tag->values->appearance.rise = g_value_get_int (value);
1221 g_object_notify (object, "rise-set");
1222 size_changed = TRUE;
1225 case PROP_BACKGROUND_FULL_HEIGHT:
1226 text_tag->bg_full_height_set = TRUE;
1227 text_tag->values->bg_full_height = g_value_get_boolean (value);
1228 g_object_notify (object, "background-full-height-set");
1232 text_tag->language_set = TRUE;
1233 text_tag->values->language = pango_language_from_string (g_value_get_string (value));
1234 g_object_notify (object, "language-set");
1238 text_tag->tabs_set = TRUE;
1240 if (text_tag->values->tabs)
1241 pango_tab_array_free (text_tag->values->tabs);
1243 /* FIXME I'm not sure if this is a memleak or not */
1244 text_tag->values->tabs =
1245 pango_tab_array_copy (g_value_get_boxed (value));
1247 g_object_notify (object, "tabs-set");
1249 size_changed = TRUE;
1252 case PROP_INVISIBLE:
1253 text_tag->invisible_set = TRUE;
1254 text_tag->values->invisible = g_value_get_boolean (value);
1255 g_object_notify (object, "invisible-set");
1256 size_changed = TRUE;
1259 case PROP_PARAGRAPH_BACKGROUND:
1263 if (gdk_color_parse (g_value_get_string (value), &color))
1264 set_pg_bg_color (text_tag, &color);
1266 g_warning ("Don't know color `%s'", g_value_get_string (value));
1268 g_object_notify (object, "paragraph-background-gdk");
1272 case PROP_PARAGRAPH_BACKGROUND_GDK:
1274 GdkColor *color = g_value_get_boxed (value);
1276 set_pg_bg_color (text_tag, color);
1280 /* Whether the value should be used... */
1282 case PROP_BACKGROUND_SET:
1283 text_tag->bg_color_set = g_value_get_boolean (value);
1286 case PROP_FOREGROUND_SET:
1287 text_tag->fg_color_set = g_value_get_boolean (value);
1290 case PROP_BACKGROUND_STIPPLE_SET:
1291 text_tag->bg_stipple_set = g_value_get_boolean (value);
1292 if (!text_tag->bg_stipple_set &&
1293 text_tag->values->appearance.bg_stipple)
1295 g_object_unref (text_tag->values->appearance.bg_stipple);
1296 text_tag->values->appearance.bg_stipple = NULL;
1300 case PROP_FOREGROUND_STIPPLE_SET:
1301 text_tag->fg_stipple_set = g_value_get_boolean (value);
1302 if (!text_tag->fg_stipple_set &&
1303 text_tag->values->appearance.fg_stipple)
1305 g_object_unref (text_tag->values->appearance.fg_stipple);
1306 text_tag->values->appearance.fg_stipple = NULL;
1310 case PROP_FAMILY_SET:
1311 case PROP_STYLE_SET:
1312 case PROP_VARIANT_SET:
1313 case PROP_WEIGHT_SET:
1314 case PROP_STRETCH_SET:
1316 if (!g_value_get_boolean (value))
1318 if (text_tag->values->font)
1319 pango_font_description_unset_fields (text_tag->values->font,
1320 get_property_font_set_mask (prop_id));
1324 PangoFontMask changed_mask;
1326 gtk_text_tag_ensure_font (text_tag);
1327 changed_mask = set_font_desc_fields (text_tag->values->font,
1328 get_property_font_set_mask (prop_id));
1329 notify_fields_changed (G_OBJECT (text_tag), changed_mask);
1333 case PROP_SCALE_SET:
1334 text_tag->scale_set = g_value_get_boolean (value);
1335 size_changed = TRUE;
1338 case PROP_PIXELS_ABOVE_LINES_SET:
1339 text_tag->pixels_above_lines_set = g_value_get_boolean (value);
1340 size_changed = TRUE;
1343 case PROP_PIXELS_BELOW_LINES_SET:
1344 text_tag->pixels_below_lines_set = g_value_get_boolean (value);
1345 size_changed = TRUE;
1348 case PROP_PIXELS_INSIDE_WRAP_SET:
1349 text_tag->pixels_inside_wrap_set = g_value_get_boolean (value);
1350 size_changed = TRUE;
1353 case PROP_EDITABLE_SET:
1354 text_tag->editable_set = g_value_get_boolean (value);
1357 case PROP_WRAP_MODE_SET:
1358 text_tag->wrap_mode_set = g_value_get_boolean (value);
1359 size_changed = TRUE;
1362 case PROP_JUSTIFICATION_SET:
1363 text_tag->justification_set = g_value_get_boolean (value);
1364 size_changed = TRUE;
1367 case PROP_LEFT_MARGIN_SET:
1368 text_tag->left_margin_set = g_value_get_boolean (value);
1369 size_changed = TRUE;
1372 case PROP_INDENT_SET:
1373 text_tag->indent_set = g_value_get_boolean (value);
1374 size_changed = TRUE;
1377 case PROP_STRIKETHROUGH_SET:
1378 text_tag->strikethrough_set = g_value_get_boolean (value);
1381 case PROP_RIGHT_MARGIN_SET:
1382 text_tag->right_margin_set = g_value_get_boolean (value);
1383 size_changed = TRUE;
1386 case PROP_UNDERLINE_SET:
1387 text_tag->underline_set = g_value_get_boolean (value);
1391 text_tag->rise_set = g_value_get_boolean (value);
1392 size_changed = TRUE;
1395 case PROP_BACKGROUND_FULL_HEIGHT_SET:
1396 text_tag->bg_full_height_set = g_value_get_boolean (value);
1399 case PROP_LANGUAGE_SET:
1400 text_tag->language_set = g_value_get_boolean (value);
1401 size_changed = TRUE;
1405 text_tag->tabs_set = g_value_get_boolean (value);
1406 size_changed = TRUE;
1409 case PROP_INVISIBLE_SET:
1410 text_tag->invisible_set = g_value_get_boolean (value);
1411 size_changed = TRUE;
1414 case PROP_PARAGRAPH_BACKGROUND_SET:
1415 text_tag->pg_bg_color_set = g_value_get_boolean (value);
1419 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1423 /* FIXME I would like to do this after all set_property in a single
1424 * g_object_set () have been called. But an idle function won't
1425 * work; we need to emit when the tag is changed, not when we get
1426 * around to the event loop. So blah, we eat some inefficiency.
1429 /* This is also somewhat weird since we emit another object's
1430 * signal here, but the two objects are already tightly bound.
1433 if (text_tag->table)
1434 g_signal_emit_by_name (text_tag->table,
1436 text_tag, size_changed);
1440 gtk_text_tag_get_property (GObject *object,
1447 tag = GTK_TEXT_TAG (object);
1452 g_value_set_string (value, tag->name);
1455 case PROP_BACKGROUND_GDK:
1456 g_value_set_boxed (value, &tag->values->appearance.bg_color);
1459 case PROP_FOREGROUND_GDK:
1460 g_value_set_boxed (value, &tag->values->appearance.fg_color);
1463 case PROP_BACKGROUND_STIPPLE:
1464 if (tag->bg_stipple_set)
1465 g_value_set_object (value, tag->values->appearance.bg_stipple);
1468 case PROP_FOREGROUND_STIPPLE:
1469 if (tag->fg_stipple_set)
1470 g_value_set_object (value, tag->values->appearance.fg_stipple);
1477 gtk_text_tag_ensure_font (tag);
1479 str = pango_font_description_to_string (tag->values->font);
1480 g_value_take_string (value, str);
1484 case PROP_FONT_DESC:
1485 gtk_text_tag_ensure_font (tag);
1486 g_value_set_boxed (value, tag->values->font);
1495 case PROP_SIZE_POINTS:
1496 gtk_text_tag_ensure_font (tag);
1500 g_value_set_string (value, pango_font_description_get_family (tag->values->font));
1504 g_value_set_enum (value, pango_font_description_get_style (tag->values->font));
1508 g_value_set_enum (value, pango_font_description_get_variant (tag->values->font));
1512 g_value_set_int (value, pango_font_description_get_weight (tag->values->font));
1516 g_value_set_enum (value, pango_font_description_get_stretch (tag->values->font));
1520 g_value_set_int (value, pango_font_description_get_size (tag->values->font));
1523 case PROP_SIZE_POINTS:
1524 g_value_set_double (value, ((double)pango_font_description_get_size (tag->values->font)) / (double)PANGO_SCALE);
1530 g_value_set_double (value, tag->values->font_scale);
1533 case PROP_PIXELS_ABOVE_LINES:
1534 g_value_set_int (value, tag->values->pixels_above_lines);
1537 case PROP_PIXELS_BELOW_LINES:
1538 g_value_set_int (value, tag->values->pixels_below_lines);
1541 case PROP_PIXELS_INSIDE_WRAP:
1542 g_value_set_int (value, tag->values->pixels_inside_wrap);
1546 g_value_set_boolean (value, tag->values->editable);
1549 case PROP_WRAP_MODE:
1550 g_value_set_enum (value, tag->values->wrap_mode);
1553 case PROP_JUSTIFICATION:
1554 g_value_set_enum (value, tag->values->justification);
1557 case PROP_DIRECTION:
1558 g_value_set_enum (value, tag->values->direction);
1561 case PROP_LEFT_MARGIN:
1562 g_value_set_int (value, tag->values->left_margin);
1566 g_value_set_int (value, tag->values->indent);
1569 case PROP_STRIKETHROUGH:
1570 g_value_set_boolean (value, tag->values->appearance.strikethrough);
1573 case PROP_RIGHT_MARGIN:
1574 g_value_set_int (value, tag->values->right_margin);
1577 case PROP_UNDERLINE:
1578 g_value_set_enum (value, tag->values->appearance.underline);
1582 g_value_set_int (value, tag->values->appearance.rise);
1585 case PROP_BACKGROUND_FULL_HEIGHT:
1586 g_value_set_boolean (value, tag->values->bg_full_height);
1590 g_value_set_string (value, pango_language_to_string (tag->values->language));
1594 if (tag->values->tabs)
1595 g_value_set_boxed (value, tag->values->tabs);
1598 case PROP_INVISIBLE:
1599 g_value_set_boolean (value, tag->values->invisible);
1602 case PROP_PARAGRAPH_BACKGROUND_GDK:
1603 g_value_set_boxed (value, tag->values->pg_bg_color);
1606 case PROP_BACKGROUND_SET:
1607 g_value_set_boolean (value, tag->bg_color_set);
1610 case PROP_FOREGROUND_SET:
1611 g_value_set_boolean (value, tag->fg_color_set);
1614 case PROP_BACKGROUND_STIPPLE_SET:
1615 g_value_set_boolean (value, tag->bg_stipple_set);
1618 case PROP_FOREGROUND_STIPPLE_SET:
1619 g_value_set_boolean (value, tag->fg_stipple_set);
1622 case PROP_FAMILY_SET:
1623 case PROP_STYLE_SET:
1624 case PROP_VARIANT_SET:
1625 case PROP_WEIGHT_SET:
1626 case PROP_STRETCH_SET:
1629 PangoFontMask set_mask = tag->values->font ? pango_font_description_get_set_fields (tag->values->font) : 0;
1630 PangoFontMask test_mask = get_property_font_set_mask (prop_id);
1631 g_value_set_boolean (value, (set_mask & test_mask) != 0);
1636 case PROP_SCALE_SET:
1637 g_value_set_boolean (value, tag->scale_set);
1640 case PROP_PIXELS_ABOVE_LINES_SET:
1641 g_value_set_boolean (value, tag->pixels_above_lines_set);
1644 case PROP_PIXELS_BELOW_LINES_SET:
1645 g_value_set_boolean (value, tag->pixels_below_lines_set);
1648 case PROP_PIXELS_INSIDE_WRAP_SET:
1649 g_value_set_boolean (value, tag->pixels_inside_wrap_set);
1652 case PROP_EDITABLE_SET:
1653 g_value_set_boolean (value, tag->editable_set);
1656 case PROP_WRAP_MODE_SET:
1657 g_value_set_boolean (value, tag->wrap_mode_set);
1660 case PROP_JUSTIFICATION_SET:
1661 g_value_set_boolean (value, tag->justification_set);
1664 case PROP_LEFT_MARGIN_SET:
1665 g_value_set_boolean (value, tag->left_margin_set);
1668 case PROP_INDENT_SET:
1669 g_value_set_boolean (value, tag->indent_set);
1672 case PROP_STRIKETHROUGH_SET:
1673 g_value_set_boolean (value, tag->strikethrough_set);
1676 case PROP_RIGHT_MARGIN_SET:
1677 g_value_set_boolean (value, tag->right_margin_set);
1680 case PROP_UNDERLINE_SET:
1681 g_value_set_boolean (value, tag->underline_set);
1685 g_value_set_boolean (value, tag->rise_set);
1688 case PROP_BACKGROUND_FULL_HEIGHT_SET:
1689 g_value_set_boolean (value, tag->bg_full_height_set);
1692 case PROP_LANGUAGE_SET:
1693 g_value_set_boolean (value, tag->language_set);
1697 g_value_set_boolean (value, tag->tabs_set);
1700 case PROP_INVISIBLE_SET:
1701 g_value_set_boolean (value, tag->invisible_set);
1704 case PROP_PARAGRAPH_BACKGROUND_SET:
1705 g_value_set_boolean (value, tag->pg_bg_color_set);
1708 case PROP_BACKGROUND:
1709 case PROP_FOREGROUND:
1710 case PROP_PARAGRAPH_BACKGROUND:
1711 g_warning ("'foreground', 'background' and 'paragraph_background' properties are not readable, use 'foreground_gdk', 'background_gdk' and 'paragraph_background_gdk'");
1713 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1729 delta_priority_foreach (GtkTextTag *tag, gpointer user_data)
1731 DeltaData *dd = user_data;
1733 if (tag->priority >= dd->low && tag->priority <= dd->high)
1734 tag->priority += dd->delta;
1738 * gtk_text_tag_get_priority:
1739 * @tag: a #GtkTextTag
1741 * Get the tag priority.
1743 * Return value: The tag's priority.
1746 gtk_text_tag_get_priority (GtkTextTag *tag)
1748 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), 0);
1750 return tag->priority;
1754 * gtk_text_tag_set_priority:
1755 * @tag: a #GtkTextTag
1756 * @priority: the new priority
1758 * Sets the priority of a #GtkTextTag. Valid priorities are
1759 * start at 0 and go to one less than gtk_text_tag_table_get_size().
1760 * Each tag in a table has a unique priority; setting the priority
1761 * of one tag shifts the priorities of all the other tags in the
1762 * table to maintain a unique priority for each tag. Higher priority
1763 * tags "win" if two tags both set the same text attribute. When adding
1764 * a tag to a tag table, it will be assigned the highest priority in
1765 * the table by default; so normally the precedence of a set of tags
1766 * is the order in which they were added to the table, or created with
1767 * gtk_text_buffer_create_tag(), which adds the tag to the buffer's table
1771 gtk_text_tag_set_priority (GtkTextTag *tag,
1776 g_return_if_fail (GTK_IS_TEXT_TAG (tag));
1777 g_return_if_fail (tag->table != NULL);
1778 g_return_if_fail (priority >= 0);
1779 g_return_if_fail (priority < gtk_text_tag_table_get_size (tag->table));
1781 if (priority == tag->priority)
1784 if (priority < tag->priority)
1787 dd.high = tag->priority - 1;
1792 dd.low = tag->priority + 1;
1797 gtk_text_tag_table_foreach (tag->table,
1798 delta_priority_foreach,
1801 tag->priority = priority;
1805 * gtk_text_tag_event:
1806 * @tag: a #GtkTextTag
1807 * @event_object: object that received the event, such as a widget
1809 * @iter: location where the event was received
1811 * Emits the "event" signal on the #GtkTextTag.
1813 * Return value: result of signal emission (whether the event was handled)
1816 gtk_text_tag_event (GtkTextTag *tag,
1817 GObject *event_object,
1819 const GtkTextIter *iter)
1821 gboolean retval = FALSE;
1823 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
1824 g_return_val_if_fail (G_IS_OBJECT (event_object), FALSE);
1825 g_return_val_if_fail (event != NULL, FALSE);
1839 tag_sort_func (gconstpointer first, gconstpointer second)
1841 GtkTextTag *tag1, *tag2;
1843 tag1 = * (GtkTextTag **) first;
1844 tag2 = * (GtkTextTag **) second;
1845 return tag1->priority - tag2->priority;
1849 _gtk_text_tag_array_sort (GtkTextTag** tag_array_p,
1854 GtkTextTag **maxPtrPtr, *tmp;
1856 g_return_if_fail (tag_array_p != NULL);
1857 g_return_if_fail (len > 0);
1863 GtkTextTag **iter = tag_array_p;
1865 for (i = len-1; i > 0; i--, iter++) {
1866 maxPtrPtr = tag = iter;
1867 prio = tag[0]->priority;
1868 for (j = i, tag++; j > 0; j--, tag++) {
1869 if (tag[0]->priority < prio) {
1870 prio = tag[0]->priority;
1879 qsort ((void *) tag_array_p, (unsigned) len, sizeof (GtkTextTag *),
1885 printf ("Sorted tag array: \n");
1889 GtkTextTag *t = tag_array_p[i];
1890 printf (" %s priority %d\n", t->name, t->priority);
1903 * gtk_text_attributes_new:
1905 * Creates a #GtkTextAttributes, which describes
1906 * a set of properties on some text.
1908 * Return value: a new #GtkTextAttributes
1911 gtk_text_attributes_new (void)
1913 GtkTextAttributes *values;
1915 values = g_new0 (GtkTextAttributes, 1);
1917 /* 0 is a valid value for most of the struct */
1919 values->refcount = 1;
1921 values->language = gtk_get_default_language ();
1923 values->font_scale = 1.0;
1925 values->editable = TRUE;
1931 * gtk_text_attributes_copy:
1932 * @src: a #GtkTextAttributes to be copied
1934 * Copies @src and returns a new #GtkTextAttributes.
1936 * Return value: a copy of @src
1939 gtk_text_attributes_copy (GtkTextAttributes *src)
1941 GtkTextAttributes *dest;
1943 dest = gtk_text_attributes_new ();
1944 gtk_text_attributes_copy_values (src, dest);
1950 gtk_text_attributes_get_type (void)
1952 static GType our_type = 0;
1955 our_type = g_boxed_type_register_static (I_("GtkTextAttributes"),
1956 (GBoxedCopyFunc) gtk_text_attributes_ref,
1957 (GBoxedFreeFunc) gtk_text_attributes_unref);
1963 * gtk_text_attributes_copy_values:
1964 * @src: a #GtkTextAttributes
1965 * @dest: another #GtkTextAttributes
1967 * Copies the values from @src to @dest so that @dest has the same values
1968 * as @src. Frees existing values in @dest.
1971 gtk_text_attributes_copy_values (GtkTextAttributes *src,
1972 GtkTextAttributes *dest)
1974 guint orig_refcount;
1976 g_return_if_fail (!dest->realized);
1983 if (src->appearance.bg_stipple)
1984 g_object_ref (src->appearance.bg_stipple);
1986 if (src->appearance.fg_stipple)
1987 g_object_ref (src->appearance.fg_stipple);
1991 if (dest->appearance.bg_stipple)
1992 g_object_unref (dest->appearance.bg_stipple);
1994 if (dest->appearance.fg_stipple)
1995 g_object_unref (dest->appearance.fg_stipple);
1998 pango_font_description_free (dest->font);
2001 orig_refcount = dest->refcount;
2006 dest->tabs = pango_tab_array_copy (src->tabs);
2008 dest->language = src->language;
2011 dest->font = pango_font_description_copy (src->font);
2013 if (src->pg_bg_color)
2014 dest->pg_bg_color = gdk_color_copy (src->pg_bg_color);
2016 dest->refcount = orig_refcount;
2017 dest->realized = FALSE;
2021 * gtk_text_attributes_ref:
2022 * @values: a #GtkTextAttributes
2024 * Increments the reference count on @values.
2026 * Returns: the #GtkTextAttributes that were passed in
2029 gtk_text_attributes_ref (GtkTextAttributes *values)
2031 g_return_val_if_fail (values != NULL, NULL);
2033 values->refcount += 1;
2039 * gtk_text_attributes_unref:
2040 * @values: a #GtkTextAttributes
2042 * Decrements the reference count on @values, freeing the structure
2043 * if the reference count reaches 0.
2046 gtk_text_attributes_unref (GtkTextAttributes *values)
2048 g_return_if_fail (values != NULL);
2049 g_return_if_fail (values->refcount > 0);
2051 values->refcount -= 1;
2053 if (values->refcount == 0)
2055 g_assert (!values->realized);
2057 if (values->appearance.bg_stipple)
2058 g_object_unref (values->appearance.bg_stipple);
2060 if (values->appearance.fg_stipple)
2061 g_object_unref (values->appearance.fg_stipple);
2064 pango_tab_array_free (values->tabs);
2067 pango_font_description_free (values->font);
2069 if (values->pg_bg_color)
2070 gdk_color_free (values->pg_bg_color);
2077 _gtk_text_attributes_realize (GtkTextAttributes *values,
2081 g_return_if_fail (values != NULL);
2082 g_return_if_fail (values->refcount > 0);
2083 g_return_if_fail (!values->realized);
2085 /* It is wrong to use this colormap, FIXME */
2086 gdk_colormap_alloc_color (cmap,
2087 &values->appearance.fg_color,
2090 gdk_colormap_alloc_color (cmap,
2091 &values->appearance.bg_color,
2094 if (values->pg_bg_color)
2095 gdk_colormap_alloc_color (cmap,
2096 values->pg_bg_color,
2099 values->realized = TRUE;
2103 _gtk_text_attributes_unrealize (GtkTextAttributes *values,
2107 g_return_if_fail (values != NULL);
2108 g_return_if_fail (values->refcount > 0);
2109 g_return_if_fail (values->realized);
2111 gdk_colormap_free_colors (cmap,
2112 &values->appearance.fg_color, 1);
2115 gdk_colormap_free_colors (cmap,
2116 &values->appearance.bg_color, 1);
2118 values->appearance.fg_color.pixel = 0;
2119 values->appearance.bg_color.pixel = 0;
2121 if (values->pg_bg_color)
2123 gdk_colormap_free_colors (cmap, values->pg_bg_color, 1);
2125 values->pg_bg_color->pixel = 0;
2128 values->realized = FALSE;
2132 _gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest,
2138 g_return_if_fail (!dest->realized);
2142 GtkTextTag *tag = tags[n];
2143 GtkTextAttributes *vals = tag->values;
2145 g_assert (tag->table != NULL);
2147 g_assert (tags[n]->priority > tags[n-1]->priority);
2149 if (tag->bg_color_set)
2151 dest->appearance.bg_color = vals->appearance.bg_color;
2153 dest->appearance.draw_bg = TRUE;
2155 if (tag->fg_color_set)
2156 dest->appearance.fg_color = vals->appearance.fg_color;
2158 if (tag->pg_bg_color_set)
2160 dest->pg_bg_color = gdk_color_copy (vals->pg_bg_color);
2163 if (tag->bg_stipple_set)
2165 g_object_ref (vals->appearance.bg_stipple);
2166 if (dest->appearance.bg_stipple)
2167 g_object_unref (dest->appearance.bg_stipple);
2168 dest->appearance.bg_stipple = vals->appearance.bg_stipple;
2170 dest->appearance.draw_bg = TRUE;
2173 if (tag->fg_stipple_set)
2175 g_object_ref (vals->appearance.fg_stipple);
2176 if (dest->appearance.fg_stipple)
2177 g_object_unref (dest->appearance.fg_stipple);
2178 dest->appearance.fg_stipple = vals->appearance.fg_stipple;
2184 pango_font_description_merge (dest->font, vals->font, TRUE);
2186 dest->font = pango_font_description_copy (vals->font);
2189 /* multiply all the scales together to get a composite */
2191 dest->font_scale *= vals->font_scale;
2193 if (tag->justification_set)
2194 dest->justification = vals->justification;
2196 if (vals->direction != GTK_TEXT_DIR_NONE)
2197 dest->direction = vals->direction;
2199 if (tag->left_margin_set)
2200 dest->left_margin = vals->left_margin;
2202 if (tag->indent_set)
2203 dest->indent = vals->indent;
2206 dest->appearance.rise = vals->appearance.rise;
2208 if (tag->right_margin_set)
2209 dest->right_margin = vals->right_margin;
2211 if (tag->pixels_above_lines_set)
2212 dest->pixels_above_lines = vals->pixels_above_lines;
2214 if (tag->pixels_below_lines_set)
2215 dest->pixels_below_lines = vals->pixels_below_lines;
2217 if (tag->pixels_inside_wrap_set)
2218 dest->pixels_inside_wrap = vals->pixels_inside_wrap;
2223 pango_tab_array_free (dest->tabs);
2224 dest->tabs = pango_tab_array_copy (vals->tabs);
2227 if (tag->wrap_mode_set)
2228 dest->wrap_mode = vals->wrap_mode;
2230 if (tag->underline_set)
2231 dest->appearance.underline = vals->appearance.underline;
2233 if (tag->strikethrough_set)
2234 dest->appearance.strikethrough = vals->appearance.strikethrough;
2236 if (tag->invisible_set)
2237 dest->invisible = vals->invisible;
2239 if (tag->editable_set)
2240 dest->editable = vals->editable;
2242 if (tag->bg_full_height_set)
2243 dest->bg_full_height = vals->bg_full_height;
2245 if (tag->language_set)
2246 dest->language = vals->language;
2253 _gtk_text_tag_affects_size (GtkTextTag *tag)
2255 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
2258 (tag->values->font && pango_font_description_get_set_fields (tag->values->font) != 0) ||
2260 tag->justification_set ||
2261 tag->left_margin_set ||
2264 tag->right_margin_set ||
2265 tag->pixels_above_lines_set ||
2266 tag->pixels_below_lines_set ||
2267 tag->pixels_inside_wrap_set ||
2269 tag->underline_set ||
2270 tag->wrap_mode_set ||
2275 _gtk_text_tag_affects_nonsize_appearance (GtkTextTag *tag)
2277 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
2280 tag->bg_color_set ||
2281 tag->bg_stipple_set ||
2282 tag->fg_color_set ||
2283 tag->fg_stipple_set ||
2284 tag->strikethrough_set ||
2285 tag->bg_full_height_set ||
2286 tag->pg_bg_color_set;
2289 #define __GTK_TEXT_TAG_C__
2290 #include "gtkaliasdef.c"