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"
77 PROP_BACKGROUND_STIPPLE,
78 PROP_FOREGROUND_STIPPLE,
89 PROP_PIXELS_ABOVE_LINES,
90 PROP_PIXELS_BELOW_LINES,
91 PROP_PIXELS_INSIDE_WRAP,
102 PROP_BACKGROUND_FULL_HEIGHT,
106 PROP_PARAGRAPH_BACKGROUND,
107 PROP_PARAGRAPH_BACKGROUND_GDK,
110 PROP_ACCUMULATIVE_MARGIN,
112 /* Whether-a-style-arg-is-set args */
115 PROP_BACKGROUND_STIPPLE_SET,
116 PROP_FOREGROUND_STIPPLE_SET,
124 PROP_PIXELS_ABOVE_LINES_SET,
125 PROP_PIXELS_BELOW_LINES_SET,
126 PROP_PIXELS_INSIDE_WRAP_SET,
129 PROP_JUSTIFICATION_SET,
130 PROP_LEFT_MARGIN_SET,
132 PROP_STRIKETHROUGH_SET,
133 PROP_RIGHT_MARGIN_SET,
136 PROP_BACKGROUND_FULL_HEIGHT_SET,
140 PROP_PARAGRAPH_BACKGROUND_SET,
144 static void gtk_text_tag_finalize (GObject *object);
145 static void gtk_text_tag_set_property (GObject *object,
149 static void gtk_text_tag_get_property (GObject *object,
154 static guint signals[LAST_SIGNAL] = { 0 };
156 G_DEFINE_TYPE (GtkTextTag, gtk_text_tag, G_TYPE_OBJECT)
159 gtk_text_tag_class_init (GtkTextTagClass *klass)
161 GObjectClass *object_class = G_OBJECT_CLASS (klass);
163 object_class->set_property = gtk_text_tag_set_property;
164 object_class->get_property = gtk_text_tag_get_property;
166 object_class->finalize = gtk_text_tag_finalize;
169 g_object_class_install_property (object_class,
171 g_param_spec_string ("name",
173 P_("Name used to refer to the text tag. NULL for anonymous tags"),
175 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
179 g_object_class_install_property (object_class,
181 g_param_spec_string ("background",
182 P_("Background color name"),
183 P_("Background color as a string"),
185 GTK_PARAM_WRITABLE));
187 g_object_class_install_property (object_class,
189 g_param_spec_boxed ("background-gdk",
190 P_("Background color"),
191 P_("Background color as a (possibly unallocated) GdkColor"),
193 GTK_PARAM_READWRITE));
195 g_object_class_install_property (object_class,
196 PROP_BACKGROUND_FULL_HEIGHT,
197 g_param_spec_boolean ("background-full-height",
198 P_("Background full height"),
199 P_("Whether the background color fills the entire line height or only the height of the tagged characters"),
201 GTK_PARAM_READWRITE));
204 g_object_class_install_property (object_class,
205 PROP_BACKGROUND_STIPPLE,
206 g_param_spec_object ("background-stipple",
207 P_("Background stipple mask"),
208 P_("Bitmap to use as a mask when drawing the text background"),
210 GTK_PARAM_READWRITE));
213 g_object_class_install_property (object_class,
215 g_param_spec_string ("foreground",
216 P_("Foreground color name"),
217 P_("Foreground color as a string"),
219 GTK_PARAM_WRITABLE));
221 g_object_class_install_property (object_class,
223 g_param_spec_boxed ("foreground-gdk",
224 P_("Foreground color"),
225 P_("Foreground color as a (possibly unallocated) GdkColor"),
227 GTK_PARAM_READWRITE));
230 g_object_class_install_property (object_class,
231 PROP_FOREGROUND_STIPPLE,
232 g_param_spec_object ("foreground-stipple",
233 P_("Foreground stipple mask"),
234 P_("Bitmap to use as a mask when drawing the text foreground"),
236 GTK_PARAM_READWRITE));
238 g_object_class_install_property (object_class,
240 g_param_spec_enum ("direction",
241 P_("Text direction"),
242 P_("Text direction, e.g. right-to-left or left-to-right"),
243 GTK_TYPE_TEXT_DIRECTION,
245 GTK_PARAM_READWRITE));
247 g_object_class_install_property (object_class,
249 g_param_spec_boolean ("editable",
251 P_("Whether the text can be modified by the user"),
253 GTK_PARAM_READWRITE));
258 * Font description as string, e.g. \"Sans Italic 12\".
260 * Note that the initial value of this property depends on
261 * the internals of #PangoFontDescription.
263 g_object_class_install_property (object_class,
265 g_param_spec_string ("font",
267 P_("Font description as a string, e.g. \"Sans Italic 12\""),
269 GTK_PARAM_READWRITE));
271 g_object_class_install_property (object_class,
273 g_param_spec_boxed ("font-desc",
275 P_("Font description as a PangoFontDescription struct"),
276 PANGO_TYPE_FONT_DESCRIPTION,
277 GTK_PARAM_READWRITE));
279 g_object_class_install_property (object_class,
281 g_param_spec_string ("family",
283 P_("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
285 GTK_PARAM_READWRITE));
287 g_object_class_install_property (object_class,
289 g_param_spec_enum ("style",
291 P_("Font style as a PangoStyle, e.g. PANGO_STYLE_ITALIC"),
294 GTK_PARAM_READWRITE));
296 g_object_class_install_property (object_class,
298 g_param_spec_enum ("variant",
300 P_("Font variant as a PangoVariant, e.g. PANGO_VARIANT_SMALL_CAPS"),
302 PANGO_VARIANT_NORMAL,
303 GTK_PARAM_READWRITE));
305 g_object_class_install_property (object_class,
307 g_param_spec_int ("weight",
309 P_("Font weight as an integer, see predefined values in PangoWeight; for example, PANGO_WEIGHT_BOLD"),
313 GTK_PARAM_READWRITE));
316 g_object_class_install_property (object_class,
318 g_param_spec_enum ("stretch",
320 P_("Font stretch as a PangoStretch, e.g. PANGO_STRETCH_CONDENSED"),
322 PANGO_STRETCH_NORMAL,
323 GTK_PARAM_READWRITE));
325 g_object_class_install_property (object_class,
327 g_param_spec_int ("size",
329 P_("Font size in Pango units"),
333 GTK_PARAM_READWRITE));
335 g_object_class_install_property (object_class,
337 g_param_spec_double ("scale",
339 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"),
343 GTK_PARAM_READWRITE));
345 g_object_class_install_property (object_class,
347 g_param_spec_double ("size-points",
349 P_("Font size in points"),
353 GTK_PARAM_READWRITE));
355 g_object_class_install_property (object_class,
357 g_param_spec_enum ("justification",
359 P_("Left, right, or center justification"),
360 GTK_TYPE_JUSTIFICATION,
362 GTK_PARAM_READWRITE));
365 * GtkTextTag:language:
367 * The language this text is in, as an ISO code. Pango can use this as a
368 * hint when rendering the text. If not set, an appropriate default will be
371 * Note that the initial value of this property depends on the current
372 * locale, see also gtk_get_default_language().
374 g_object_class_install_property (object_class,
376 g_param_spec_string ("language",
378 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."),
380 GTK_PARAM_READWRITE));
382 g_object_class_install_property (object_class,
384 g_param_spec_int ("left-margin",
386 P_("Width of the left margin in pixels"),
390 GTK_PARAM_READWRITE));
392 g_object_class_install_property (object_class,
394 g_param_spec_int ("right-margin",
396 P_("Width of the right margin in pixels"),
400 GTK_PARAM_READWRITE));
403 g_object_class_install_property (object_class,
405 g_param_spec_int ("indent",
407 P_("Amount to indent the paragraph, in pixels"),
411 GTK_PARAM_READWRITE));
414 g_object_class_install_property (object_class,
416 g_param_spec_int ("rise",
418 P_("Offset of text above the baseline (below the baseline if rise is negative) in Pango units"),
422 GTK_PARAM_READWRITE));
424 g_object_class_install_property (object_class,
425 PROP_PIXELS_ABOVE_LINES,
426 g_param_spec_int ("pixels-above-lines",
427 P_("Pixels above lines"),
428 P_("Pixels of blank space above paragraphs"),
432 GTK_PARAM_READWRITE));
434 g_object_class_install_property (object_class,
435 PROP_PIXELS_BELOW_LINES,
436 g_param_spec_int ("pixels-below-lines",
437 P_("Pixels below lines"),
438 P_("Pixels of blank space below paragraphs"),
442 GTK_PARAM_READWRITE));
444 g_object_class_install_property (object_class,
445 PROP_PIXELS_INSIDE_WRAP,
446 g_param_spec_int ("pixels-inside-wrap",
447 P_("Pixels inside wrap"),
448 P_("Pixels of blank space between wrapped lines in a paragraph"),
452 GTK_PARAM_READWRITE));
454 g_object_class_install_property (object_class,
456 g_param_spec_boolean ("strikethrough",
458 P_("Whether to strike through the text"),
460 GTK_PARAM_READWRITE));
462 g_object_class_install_property (object_class,
464 g_param_spec_enum ("underline",
466 P_("Style of underline for this text"),
467 PANGO_TYPE_UNDERLINE,
468 PANGO_UNDERLINE_NONE,
469 GTK_PARAM_READWRITE));
471 g_object_class_install_property (object_class,
473 g_param_spec_enum ("wrap-mode",
475 P_("Whether to wrap lines never, at word boundaries, or at character boundaries"),
478 GTK_PARAM_READWRITE));
481 g_object_class_install_property (object_class,
483 g_param_spec_boxed ("tabs",
485 P_("Custom tabs for this text"),
486 PANGO_TYPE_TAB_ARRAY,
487 GTK_PARAM_READWRITE));
490 * GtkTextTag:invisible:
492 * Whether this text is hidden.
494 * Note that there may still be problems with the support for invisible
495 * text, in particular when navigating programmatically inside a buffer
496 * containing invisible segments.
500 g_object_class_install_property (object_class,
502 g_param_spec_boolean ("invisible",
504 P_("Whether this text is hidden."),
506 GTK_PARAM_READWRITE));
509 * GtkTextTag:paragraph-background:
511 * The paragraph background color as a string.
515 g_object_class_install_property (object_class,
516 PROP_PARAGRAPH_BACKGROUND,
517 g_param_spec_string ("paragraph-background",
518 P_("Paragraph background color name"),
519 P_("Paragraph background color as a string"),
521 GTK_PARAM_WRITABLE));
524 * GtkTextTag:paragraph-background-gdk:
526 * The paragraph background color as a as a (possibly unallocated)
531 g_object_class_install_property (object_class,
532 PROP_PARAGRAPH_BACKGROUND_GDK,
533 g_param_spec_boxed ("paragraph-background-gdk",
534 P_("Paragraph background color"),
535 P_("Paragraph background color as a (possibly unallocated) GdkColor"),
537 GTK_PARAM_READWRITE));
540 * GtkTextTag:accumulative-margin:
542 * Whether the margins accumulate or override each other.
544 * When set to %TRUE the margins of this tag are added to the margins
545 * of any other non-accumulative margins present. When set to %FALSE
546 * the margins override one another (the default).
550 g_object_class_install_property (object_class,
551 PROP_ACCUMULATIVE_MARGIN,
552 g_param_spec_boolean ("accumulative-margin",
553 P_("Margin Accumulates"),
554 P_("Whether left and right margins accumulate."),
556 GTK_PARAM_READWRITE));
558 /* Style props are set or not */
560 #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))
562 ADD_SET_PROP ("background-set", PROP_BACKGROUND_SET,
563 P_("Background set"),
564 P_("Whether this tag affects the background color"));
566 ADD_SET_PROP ("background-full-height-set", PROP_BACKGROUND_FULL_HEIGHT_SET,
567 P_("Background full height set"),
568 P_("Whether this tag affects background height"));
570 ADD_SET_PROP ("background-stipple-set", PROP_BACKGROUND_STIPPLE_SET,
571 P_("Background stipple set"),
572 P_("Whether this tag affects the background stipple"));
574 ADD_SET_PROP ("foreground-set", PROP_FOREGROUND_SET,
575 P_("Foreground set"),
576 P_("Whether this tag affects the foreground color"));
578 ADD_SET_PROP ("foreground-stipple-set", PROP_FOREGROUND_STIPPLE_SET,
579 P_("Foreground stipple set"),
580 P_("Whether this tag affects the foreground stipple"));
582 ADD_SET_PROP ("editable-set", PROP_EDITABLE_SET,
583 P_("Editability set"),
584 P_("Whether this tag affects text editability"));
586 ADD_SET_PROP ("family-set", PROP_FAMILY_SET,
587 P_("Font family set"),
588 P_("Whether this tag affects the font family"));
590 ADD_SET_PROP ("style-set", PROP_STYLE_SET,
591 P_("Font style set"),
592 P_("Whether this tag affects the font style"));
594 ADD_SET_PROP ("variant-set", PROP_VARIANT_SET,
595 P_("Font variant set"),
596 P_("Whether this tag affects the font variant"));
598 ADD_SET_PROP ("weight-set", PROP_WEIGHT_SET,
599 P_("Font weight set"),
600 P_("Whether this tag affects the font weight"));
602 ADD_SET_PROP ("stretch-set", PROP_STRETCH_SET,
603 P_("Font stretch set"),
604 P_("Whether this tag affects the font stretch"));
606 ADD_SET_PROP ("size-set", PROP_SIZE_SET,
608 P_("Whether this tag affects the font size"));
610 ADD_SET_PROP ("scale-set", PROP_SCALE_SET,
611 P_("Font scale set"),
612 P_("Whether this tag scales the font size by a factor"));
614 ADD_SET_PROP ("justification-set", PROP_JUSTIFICATION_SET,
615 P_("Justification set"),
616 P_("Whether this tag affects paragraph justification"));
618 ADD_SET_PROP ("language-set", PROP_LANGUAGE_SET,
620 P_("Whether this tag affects the language the text is rendered as"));
622 ADD_SET_PROP ("left-margin-set", PROP_LEFT_MARGIN_SET,
623 P_("Left margin set"),
624 P_("Whether this tag affects the left margin"));
626 ADD_SET_PROP ("indent-set", PROP_INDENT_SET,
628 P_("Whether this tag affects indentation"));
630 ADD_SET_PROP ("rise-set", PROP_RISE_SET,
632 P_("Whether this tag affects the rise"));
634 ADD_SET_PROP ("pixels-above-lines-set", PROP_PIXELS_ABOVE_LINES_SET,
635 P_("Pixels above lines set"),
636 P_("Whether this tag affects the number of pixels above lines"));
638 ADD_SET_PROP ("pixels-below-lines-set", PROP_PIXELS_BELOW_LINES_SET,
639 P_("Pixels below lines set"),
640 P_("Whether this tag affects the number of pixels above lines"));
642 ADD_SET_PROP ("pixels-inside-wrap-set", PROP_PIXELS_INSIDE_WRAP_SET,
643 P_("Pixels inside wrap set"),
644 P_("Whether this tag affects the number of pixels between wrapped lines"));
646 ADD_SET_PROP ("strikethrough-set", PROP_STRIKETHROUGH_SET,
647 P_("Strikethrough set"),
648 P_("Whether this tag affects strikethrough"));
650 ADD_SET_PROP ("right-margin-set", PROP_RIGHT_MARGIN_SET,
651 P_("Right margin set"),
652 P_("Whether this tag affects the right margin"));
654 ADD_SET_PROP ("underline-set", PROP_UNDERLINE_SET,
656 P_("Whether this tag affects underlining"));
658 ADD_SET_PROP ("wrap-mode-set", PROP_WRAP_MODE_SET,
660 P_("Whether this tag affects line wrap mode"));
662 ADD_SET_PROP ("tabs-set", PROP_TABS_SET,
664 P_("Whether this tag affects tabs"));
666 ADD_SET_PROP ("invisible-set", PROP_INVISIBLE_SET,
668 P_("Whether this tag affects text visibility"));
670 ADD_SET_PROP ("paragraph-background-set", PROP_PARAGRAPH_BACKGROUND_SET,
671 P_("Paragraph background set"),
672 P_("Whether this tag affects the paragraph background color"));
676 * @tag: the #GtkTextTag on which the signal is emitted
677 * @object: the object the event was fired from (typically a #GtkTextView)
678 * @event: the event which triggered the signal
679 * @iter: a #GtkTextIter pointing at the location the event occured
681 * The ::event signal is emitted when an event occurs on a region of the
682 * buffer marked with this tag.
684 * Returns: %TRUE to stop other handlers from being invoked for the
685 * event. %FALSE to propagate the event further.
688 g_signal_new (I_("event"),
689 G_OBJECT_CLASS_TYPE (object_class),
691 G_STRUCT_OFFSET (GtkTextTagClass, event),
692 _gtk_boolean_handled_accumulator, NULL,
693 _gtk_marshal_BOOLEAN__OBJECT_BOXED_BOXED,
697 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE,
702 gtk_text_tag_init (GtkTextTag *text_tag)
704 text_tag->values = gtk_text_attributes_new ();
709 * @name: (allow-none): tag name, or %NULL
711 * Creates a #GtkTextTag. Configure the tag using object arguments,
712 * i.e. using g_object_set().
714 * Return value: a new #GtkTextTag
717 gtk_text_tag_new (const gchar *name)
721 tag = g_object_new (GTK_TYPE_TEXT_TAG, "name", name, NULL);
727 gtk_text_tag_finalize (GObject *object)
729 GtkTextTag *text_tag;
731 text_tag = GTK_TEXT_TAG (object);
733 g_assert (!text_tag->values->realized);
736 gtk_text_tag_table_remove (text_tag->table, text_tag);
738 g_assert (text_tag->table == NULL);
740 gtk_text_attributes_unref (text_tag->values);
741 text_tag->values = NULL;
743 g_free (text_tag->name);
744 text_tag->name = NULL;
746 G_OBJECT_CLASS (gtk_text_tag_parent_class)->finalize (object);
750 set_bg_color (GtkTextTag *tag, GdkColor *color)
754 if (!tag->bg_color_set)
756 tag->bg_color_set = TRUE;
757 g_object_notify (G_OBJECT (tag), "background-set");
760 tag->values->appearance.bg_color = *color;
764 if (tag->bg_color_set)
766 tag->bg_color_set = FALSE;
767 g_object_notify (G_OBJECT (tag), "background-set");
773 set_fg_color (GtkTextTag *tag, GdkColor *color)
777 if (!tag->fg_color_set)
779 tag->fg_color_set = TRUE;
780 g_object_notify (G_OBJECT (tag), "foreground-set");
782 tag->values->appearance.fg_color = *color;
786 if (tag->fg_color_set)
788 tag->fg_color_set = FALSE;
789 g_object_notify (G_OBJECT (tag), "foreground-set");
795 set_pg_bg_color (GtkTextTag *tag, GdkColor *color)
799 if (!tag->pg_bg_color_set)
801 tag->pg_bg_color_set = TRUE;
802 g_object_notify (G_OBJECT (tag), "paragraph-background-set");
805 gdk_color_free (tag->values->pg_bg_color);
807 tag->values->pg_bg_color = gdk_color_copy (color);
811 if (tag->pg_bg_color_set)
813 tag->pg_bg_color_set = FALSE;
814 g_object_notify (G_OBJECT (tag), "paragraph-background-set");
815 gdk_color_free (tag->values->pg_bg_color);
818 tag->values->pg_bg_color = NULL;
823 get_property_font_set_mask (guint prop_id)
827 case PROP_FAMILY_SET:
828 return PANGO_FONT_MASK_FAMILY;
830 return PANGO_FONT_MASK_STYLE;
831 case PROP_VARIANT_SET:
832 return PANGO_FONT_MASK_VARIANT;
833 case PROP_WEIGHT_SET:
834 return PANGO_FONT_MASK_WEIGHT;
835 case PROP_STRETCH_SET:
836 return PANGO_FONT_MASK_STRETCH;
838 return PANGO_FONT_MASK_SIZE;
845 set_font_desc_fields (PangoFontDescription *desc,
846 PangoFontMask to_set)
848 PangoFontMask changed_mask = 0;
850 if (to_set & PANGO_FONT_MASK_FAMILY)
852 const char *family = pango_font_description_get_family (desc);
856 changed_mask |= PANGO_FONT_MASK_FAMILY;
859 pango_font_description_set_family (desc, family);
861 if (to_set & PANGO_FONT_MASK_STYLE)
862 pango_font_description_set_style (desc, pango_font_description_get_style (desc));
863 if (to_set & PANGO_FONT_MASK_VARIANT)
864 pango_font_description_set_variant (desc, pango_font_description_get_variant (desc));
865 if (to_set & PANGO_FONT_MASK_WEIGHT)
866 pango_font_description_set_weight (desc, pango_font_description_get_weight (desc));
867 if (to_set & PANGO_FONT_MASK_STRETCH)
868 pango_font_description_set_stretch (desc, pango_font_description_get_stretch (desc));
869 if (to_set & PANGO_FONT_MASK_SIZE)
871 gint size = pango_font_description_get_size (desc);
874 size = 10 * PANGO_SCALE;
875 changed_mask |= PANGO_FONT_MASK_SIZE;
878 pango_font_description_set_size (desc, size);
885 notify_set_changed (GObject *object,
886 PangoFontMask changed_mask)
888 if (changed_mask & PANGO_FONT_MASK_FAMILY)
889 g_object_notify (object, "family-set");
890 if (changed_mask & PANGO_FONT_MASK_STYLE)
891 g_object_notify (object, "style-set");
892 if (changed_mask & PANGO_FONT_MASK_VARIANT)
893 g_object_notify (object, "variant-set");
894 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
895 g_object_notify (object, "weight-set");
896 if (changed_mask & PANGO_FONT_MASK_STRETCH)
897 g_object_notify (object, "stretch-set");
898 if (changed_mask & PANGO_FONT_MASK_SIZE)
899 g_object_notify (object, "size-set");
903 notify_fields_changed (GObject *object,
904 PangoFontMask changed_mask)
906 if (changed_mask & PANGO_FONT_MASK_FAMILY)
907 g_object_notify (object, "family");
908 if (changed_mask & PANGO_FONT_MASK_STYLE)
909 g_object_notify (object, "style");
910 if (changed_mask & PANGO_FONT_MASK_VARIANT)
911 g_object_notify (object, "variant");
912 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
913 g_object_notify (object, "weight");
914 if (changed_mask & PANGO_FONT_MASK_STRETCH)
915 g_object_notify (object, "stretch");
916 if (changed_mask & PANGO_FONT_MASK_SIZE)
917 g_object_notify (object, "size");
921 set_font_description (GtkTextTag *text_tag,
922 PangoFontDescription *font_desc)
924 GObject *object = G_OBJECT (text_tag);
925 PangoFontDescription *new_font_desc;
926 PangoFontMask old_mask, new_mask, changed_mask, set_changed_mask;
929 new_font_desc = pango_font_description_copy (font_desc);
931 new_font_desc = pango_font_description_new ();
933 if (text_tag->values->font)
934 old_mask = pango_font_description_get_set_fields (text_tag->values->font);
938 new_mask = pango_font_description_get_set_fields (new_font_desc);
940 changed_mask = old_mask | new_mask;
941 set_changed_mask = old_mask ^ new_mask;
943 if (text_tag->values->font)
944 pango_font_description_free (text_tag->values->font);
945 text_tag->values->font = new_font_desc;
947 g_object_freeze_notify (object);
949 g_object_notify (object, "font-desc");
950 g_object_notify (object, "font");
952 if (changed_mask & PANGO_FONT_MASK_FAMILY)
953 g_object_notify (object, "family");
954 if (changed_mask & PANGO_FONT_MASK_STYLE)
955 g_object_notify (object, "style");
956 if (changed_mask & PANGO_FONT_MASK_VARIANT)
957 g_object_notify (object, "variant");
958 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
959 g_object_notify (object, "weight");
960 if (changed_mask & PANGO_FONT_MASK_STRETCH)
961 g_object_notify (object, "stretch");
962 if (changed_mask & PANGO_FONT_MASK_SIZE)
964 g_object_notify (object, "size");
965 g_object_notify (object, "size-points");
968 notify_set_changed (object, set_changed_mask);
970 g_object_thaw_notify (object);
974 gtk_text_tag_ensure_font (GtkTextTag *text_tag)
976 if (!text_tag->values->font)
977 text_tag->values->font = pango_font_description_new ();
981 gtk_text_tag_set_property (GObject *object,
986 GtkTextTag *text_tag;
987 gboolean size_changed = FALSE;
989 text_tag = GTK_TEXT_TAG (object);
991 g_return_if_fail (!text_tag->values->realized);
996 g_return_if_fail (text_tag->name == NULL);
997 text_tag->name = g_value_dup_string (value);
1000 case PROP_BACKGROUND:
1004 if (!g_value_get_string (value))
1005 set_bg_color (text_tag, NULL); /* reset to background_set to FALSE */
1006 else if (gdk_color_parse (g_value_get_string (value), &color))
1007 set_bg_color (text_tag, &color);
1009 g_warning ("Don't know color `%s'", g_value_get_string (value));
1011 g_object_notify (object, "background-gdk");
1015 case PROP_FOREGROUND:
1019 if (!g_value_get_string (value))
1020 set_fg_color (text_tag, NULL); /* reset to foreground_set to FALSE */
1021 else if (gdk_color_parse (g_value_get_string (value), &color))
1022 set_fg_color (text_tag, &color);
1024 g_warning ("Don't know color `%s'", g_value_get_string (value));
1026 g_object_notify (object, "foreground-gdk");
1030 case PROP_BACKGROUND_GDK:
1032 GdkColor *color = g_value_get_boxed (value);
1034 set_bg_color (text_tag, color);
1038 case PROP_FOREGROUND_GDK:
1040 GdkColor *color = g_value_get_boxed (value);
1042 set_fg_color (text_tag, color);
1046 case PROP_BACKGROUND_STIPPLE:
1048 GdkBitmap *bitmap = g_value_get_object (value);
1050 text_tag->bg_stipple_set = TRUE;
1051 g_object_notify (object, "background-stipple-set");
1053 if (text_tag->values->appearance.bg_stipple != bitmap)
1056 g_object_ref (bitmap);
1058 if (text_tag->values->appearance.bg_stipple)
1059 g_object_unref (text_tag->values->appearance.bg_stipple);
1061 text_tag->values->appearance.bg_stipple = bitmap;
1066 case PROP_FOREGROUND_STIPPLE:
1068 GdkBitmap *bitmap = g_value_get_object (value);
1070 text_tag->fg_stipple_set = TRUE;
1071 g_object_notify (object, "foreground-stipple-set");
1073 if (text_tag->values->appearance.fg_stipple != bitmap)
1076 g_object_ref (bitmap);
1078 if (text_tag->values->appearance.fg_stipple)
1079 g_object_unref (text_tag->values->appearance.fg_stipple);
1081 text_tag->values->appearance.fg_stipple = bitmap;
1088 PangoFontDescription *font_desc = NULL;
1091 name = g_value_get_string (value);
1094 font_desc = pango_font_description_from_string (name);
1096 set_font_description (text_tag, font_desc);
1098 pango_font_description_free (font_desc);
1100 size_changed = TRUE;
1104 case PROP_FONT_DESC:
1106 PangoFontDescription *font_desc;
1108 font_desc = g_value_get_boxed (value);
1110 set_font_description (text_tag, font_desc);
1112 size_changed = TRUE;
1122 case PROP_SIZE_POINTS:
1124 PangoFontMask old_set_mask;
1126 gtk_text_tag_ensure_font (text_tag);
1127 old_set_mask = pango_font_description_get_set_fields (text_tag->values->font);
1132 pango_font_description_set_family (text_tag->values->font,
1133 g_value_get_string (value));
1136 pango_font_description_set_style (text_tag->values->font,
1137 g_value_get_enum (value));
1140 pango_font_description_set_variant (text_tag->values->font,
1141 g_value_get_enum (value));
1144 pango_font_description_set_weight (text_tag->values->font,
1145 g_value_get_int (value));
1148 pango_font_description_set_stretch (text_tag->values->font,
1149 g_value_get_enum (value));
1152 pango_font_description_set_size (text_tag->values->font,
1153 g_value_get_int (value));
1154 g_object_notify (object, "size-points");
1156 case PROP_SIZE_POINTS:
1157 pango_font_description_set_size (text_tag->values->font,
1158 g_value_get_double (value) * PANGO_SCALE);
1159 g_object_notify (object, "size");
1163 size_changed = TRUE;
1164 notify_set_changed (object, old_set_mask & pango_font_description_get_set_fields (text_tag->values->font));
1165 g_object_notify (object, "font-desc");
1166 g_object_notify (object, "font");
1172 text_tag->values->font_scale = g_value_get_double (value);
1173 text_tag->scale_set = TRUE;
1174 g_object_notify (object, "scale-set");
1175 size_changed = TRUE;
1178 case PROP_PIXELS_ABOVE_LINES:
1179 text_tag->pixels_above_lines_set = TRUE;
1180 text_tag->values->pixels_above_lines = g_value_get_int (value);
1181 g_object_notify (object, "pixels-above-lines-set");
1182 size_changed = TRUE;
1185 case PROP_PIXELS_BELOW_LINES:
1186 text_tag->pixels_below_lines_set = TRUE;
1187 text_tag->values->pixels_below_lines = g_value_get_int (value);
1188 g_object_notify (object, "pixels-below-lines-set");
1189 size_changed = TRUE;
1192 case PROP_PIXELS_INSIDE_WRAP:
1193 text_tag->pixels_inside_wrap_set = TRUE;
1194 text_tag->values->pixels_inside_wrap = g_value_get_int (value);
1195 g_object_notify (object, "pixels-inside-wrap-set");
1196 size_changed = TRUE;
1200 text_tag->editable_set = TRUE;
1201 text_tag->values->editable = g_value_get_boolean (value);
1202 g_object_notify (object, "editable-set");
1205 case PROP_WRAP_MODE:
1206 text_tag->wrap_mode_set = TRUE;
1207 text_tag->values->wrap_mode = g_value_get_enum (value);
1208 g_object_notify (object, "wrap-mode-set");
1209 size_changed = TRUE;
1212 case PROP_JUSTIFICATION:
1213 text_tag->justification_set = TRUE;
1214 text_tag->values->justification = g_value_get_enum (value);
1215 g_object_notify (object, "justification-set");
1216 size_changed = TRUE;
1219 case PROP_DIRECTION:
1220 text_tag->values->direction = g_value_get_enum (value);
1223 case PROP_LEFT_MARGIN:
1224 text_tag->left_margin_set = TRUE;
1225 text_tag->values->left_margin = g_value_get_int (value);
1226 g_object_notify (object, "left-margin-set");
1227 size_changed = TRUE;
1231 text_tag->indent_set = TRUE;
1232 text_tag->values->indent = g_value_get_int (value);
1233 g_object_notify (object, "indent-set");
1234 size_changed = TRUE;
1237 case PROP_STRIKETHROUGH:
1238 text_tag->strikethrough_set = TRUE;
1239 text_tag->values->appearance.strikethrough = g_value_get_boolean (value);
1240 g_object_notify (object, "strikethrough-set");
1243 case PROP_RIGHT_MARGIN:
1244 text_tag->right_margin_set = TRUE;
1245 text_tag->values->right_margin = g_value_get_int (value);
1246 g_object_notify (object, "right-margin-set");
1247 size_changed = TRUE;
1250 case PROP_UNDERLINE:
1251 text_tag->underline_set = TRUE;
1252 text_tag->values->appearance.underline = g_value_get_enum (value);
1253 g_object_notify (object, "underline-set");
1257 text_tag->rise_set = TRUE;
1258 text_tag->values->appearance.rise = g_value_get_int (value);
1259 g_object_notify (object, "rise-set");
1260 size_changed = TRUE;
1263 case PROP_BACKGROUND_FULL_HEIGHT:
1264 text_tag->bg_full_height_set = TRUE;
1265 text_tag->values->bg_full_height = g_value_get_boolean (value);
1266 g_object_notify (object, "background-full-height-set");
1270 text_tag->language_set = TRUE;
1271 text_tag->values->language = pango_language_from_string (g_value_get_string (value));
1272 g_object_notify (object, "language-set");
1276 text_tag->tabs_set = TRUE;
1278 if (text_tag->values->tabs)
1279 pango_tab_array_free (text_tag->values->tabs);
1281 /* FIXME I'm not sure if this is a memleak or not */
1282 text_tag->values->tabs =
1283 pango_tab_array_copy (g_value_get_boxed (value));
1285 g_object_notify (object, "tabs-set");
1287 size_changed = TRUE;
1290 case PROP_INVISIBLE:
1291 text_tag->invisible_set = TRUE;
1292 text_tag->values->invisible = g_value_get_boolean (value);
1293 g_object_notify (object, "invisible-set");
1294 size_changed = TRUE;
1297 case PROP_PARAGRAPH_BACKGROUND:
1301 if (!g_value_get_string (value))
1302 set_pg_bg_color (text_tag, NULL); /* reset to paragraph_background_set to FALSE */
1303 else if (gdk_color_parse (g_value_get_string (value), &color))
1304 set_pg_bg_color (text_tag, &color);
1306 g_warning ("Don't know color `%s'", g_value_get_string (value));
1308 g_object_notify (object, "paragraph-background-gdk");
1312 case PROP_PARAGRAPH_BACKGROUND_GDK:
1314 GdkColor *color = g_value_get_boxed (value);
1316 set_pg_bg_color (text_tag, color);
1320 case PROP_ACCUMULATIVE_MARGIN:
1321 text_tag->accumulative_margin = g_value_get_boolean (value);
1322 g_object_notify (object, "accumulative-margin");
1323 size_changed = TRUE;
1326 /* Whether the value should be used... */
1328 case PROP_BACKGROUND_SET:
1329 text_tag->bg_color_set = g_value_get_boolean (value);
1332 case PROP_FOREGROUND_SET:
1333 text_tag->fg_color_set = g_value_get_boolean (value);
1336 case PROP_BACKGROUND_STIPPLE_SET:
1337 text_tag->bg_stipple_set = g_value_get_boolean (value);
1338 if (!text_tag->bg_stipple_set &&
1339 text_tag->values->appearance.bg_stipple)
1341 g_object_unref (text_tag->values->appearance.bg_stipple);
1342 text_tag->values->appearance.bg_stipple = NULL;
1346 case PROP_FOREGROUND_STIPPLE_SET:
1347 text_tag->fg_stipple_set = g_value_get_boolean (value);
1348 if (!text_tag->fg_stipple_set &&
1349 text_tag->values->appearance.fg_stipple)
1351 g_object_unref (text_tag->values->appearance.fg_stipple);
1352 text_tag->values->appearance.fg_stipple = NULL;
1356 case PROP_FAMILY_SET:
1357 case PROP_STYLE_SET:
1358 case PROP_VARIANT_SET:
1359 case PROP_WEIGHT_SET:
1360 case PROP_STRETCH_SET:
1362 if (!g_value_get_boolean (value))
1364 if (text_tag->values->font)
1365 pango_font_description_unset_fields (text_tag->values->font,
1366 get_property_font_set_mask (prop_id));
1370 PangoFontMask changed_mask;
1372 gtk_text_tag_ensure_font (text_tag);
1373 changed_mask = set_font_desc_fields (text_tag->values->font,
1374 get_property_font_set_mask (prop_id));
1375 notify_fields_changed (G_OBJECT (text_tag), changed_mask);
1379 case PROP_SCALE_SET:
1380 text_tag->scale_set = g_value_get_boolean (value);
1381 size_changed = TRUE;
1384 case PROP_PIXELS_ABOVE_LINES_SET:
1385 text_tag->pixels_above_lines_set = g_value_get_boolean (value);
1386 size_changed = TRUE;
1389 case PROP_PIXELS_BELOW_LINES_SET:
1390 text_tag->pixels_below_lines_set = g_value_get_boolean (value);
1391 size_changed = TRUE;
1394 case PROP_PIXELS_INSIDE_WRAP_SET:
1395 text_tag->pixels_inside_wrap_set = g_value_get_boolean (value);
1396 size_changed = TRUE;
1399 case PROP_EDITABLE_SET:
1400 text_tag->editable_set = g_value_get_boolean (value);
1403 case PROP_WRAP_MODE_SET:
1404 text_tag->wrap_mode_set = g_value_get_boolean (value);
1405 size_changed = TRUE;
1408 case PROP_JUSTIFICATION_SET:
1409 text_tag->justification_set = g_value_get_boolean (value);
1410 size_changed = TRUE;
1413 case PROP_LEFT_MARGIN_SET:
1414 text_tag->left_margin_set = g_value_get_boolean (value);
1415 size_changed = TRUE;
1418 case PROP_INDENT_SET:
1419 text_tag->indent_set = g_value_get_boolean (value);
1420 size_changed = TRUE;
1423 case PROP_STRIKETHROUGH_SET:
1424 text_tag->strikethrough_set = g_value_get_boolean (value);
1427 case PROP_RIGHT_MARGIN_SET:
1428 text_tag->right_margin_set = g_value_get_boolean (value);
1429 size_changed = TRUE;
1432 case PROP_UNDERLINE_SET:
1433 text_tag->underline_set = g_value_get_boolean (value);
1437 text_tag->rise_set = g_value_get_boolean (value);
1438 size_changed = TRUE;
1441 case PROP_BACKGROUND_FULL_HEIGHT_SET:
1442 text_tag->bg_full_height_set = g_value_get_boolean (value);
1445 case PROP_LANGUAGE_SET:
1446 text_tag->language_set = g_value_get_boolean (value);
1447 size_changed = TRUE;
1451 text_tag->tabs_set = g_value_get_boolean (value);
1452 size_changed = TRUE;
1455 case PROP_INVISIBLE_SET:
1456 text_tag->invisible_set = g_value_get_boolean (value);
1457 size_changed = TRUE;
1460 case PROP_PARAGRAPH_BACKGROUND_SET:
1461 text_tag->pg_bg_color_set = g_value_get_boolean (value);
1465 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1469 /* FIXME I would like to do this after all set_property in a single
1470 * g_object_set () have been called. But an idle function won't
1471 * work; we need to emit when the tag is changed, not when we get
1472 * around to the event loop. So blah, we eat some inefficiency.
1475 /* This is also somewhat weird since we emit another object's
1476 * signal here, but the two objects are already tightly bound.
1479 if (text_tag->table)
1480 g_signal_emit_by_name (text_tag->table,
1482 text_tag, size_changed);
1486 gtk_text_tag_get_property (GObject *object,
1493 tag = GTK_TEXT_TAG (object);
1498 g_value_set_string (value, tag->name);
1501 case PROP_BACKGROUND_GDK:
1502 g_value_set_boxed (value, &tag->values->appearance.bg_color);
1505 case PROP_FOREGROUND_GDK:
1506 g_value_set_boxed (value, &tag->values->appearance.fg_color);
1509 case PROP_BACKGROUND_STIPPLE:
1510 if (tag->bg_stipple_set)
1511 g_value_set_object (value, tag->values->appearance.bg_stipple);
1514 case PROP_FOREGROUND_STIPPLE:
1515 if (tag->fg_stipple_set)
1516 g_value_set_object (value, tag->values->appearance.fg_stipple);
1523 gtk_text_tag_ensure_font (tag);
1525 str = pango_font_description_to_string (tag->values->font);
1526 g_value_take_string (value, str);
1530 case PROP_FONT_DESC:
1531 gtk_text_tag_ensure_font (tag);
1532 g_value_set_boxed (value, tag->values->font);
1541 case PROP_SIZE_POINTS:
1542 gtk_text_tag_ensure_font (tag);
1546 g_value_set_string (value, pango_font_description_get_family (tag->values->font));
1550 g_value_set_enum (value, pango_font_description_get_style (tag->values->font));
1554 g_value_set_enum (value, pango_font_description_get_variant (tag->values->font));
1558 g_value_set_int (value, pango_font_description_get_weight (tag->values->font));
1562 g_value_set_enum (value, pango_font_description_get_stretch (tag->values->font));
1566 g_value_set_int (value, pango_font_description_get_size (tag->values->font));
1569 case PROP_SIZE_POINTS:
1570 g_value_set_double (value, ((double)pango_font_description_get_size (tag->values->font)) / (double)PANGO_SCALE);
1576 g_value_set_double (value, tag->values->font_scale);
1579 case PROP_PIXELS_ABOVE_LINES:
1580 g_value_set_int (value, tag->values->pixels_above_lines);
1583 case PROP_PIXELS_BELOW_LINES:
1584 g_value_set_int (value, tag->values->pixels_below_lines);
1587 case PROP_PIXELS_INSIDE_WRAP:
1588 g_value_set_int (value, tag->values->pixels_inside_wrap);
1592 g_value_set_boolean (value, tag->values->editable);
1595 case PROP_WRAP_MODE:
1596 g_value_set_enum (value, tag->values->wrap_mode);
1599 case PROP_JUSTIFICATION:
1600 g_value_set_enum (value, tag->values->justification);
1603 case PROP_DIRECTION:
1604 g_value_set_enum (value, tag->values->direction);
1607 case PROP_LEFT_MARGIN:
1608 g_value_set_int (value, tag->values->left_margin);
1612 g_value_set_int (value, tag->values->indent);
1615 case PROP_STRIKETHROUGH:
1616 g_value_set_boolean (value, tag->values->appearance.strikethrough);
1619 case PROP_RIGHT_MARGIN:
1620 g_value_set_int (value, tag->values->right_margin);
1623 case PROP_UNDERLINE:
1624 g_value_set_enum (value, tag->values->appearance.underline);
1628 g_value_set_int (value, tag->values->appearance.rise);
1631 case PROP_BACKGROUND_FULL_HEIGHT:
1632 g_value_set_boolean (value, tag->values->bg_full_height);
1636 g_value_set_string (value, pango_language_to_string (tag->values->language));
1640 if (tag->values->tabs)
1641 g_value_set_boxed (value, tag->values->tabs);
1644 case PROP_INVISIBLE:
1645 g_value_set_boolean (value, tag->values->invisible);
1648 case PROP_PARAGRAPH_BACKGROUND_GDK:
1649 g_value_set_boxed (value, tag->values->pg_bg_color);
1652 case PROP_ACCUMULATIVE_MARGIN:
1653 g_value_set_boolean (value, tag->accumulative_margin);
1656 case PROP_BACKGROUND_SET:
1657 g_value_set_boolean (value, tag->bg_color_set);
1660 case PROP_FOREGROUND_SET:
1661 g_value_set_boolean (value, tag->fg_color_set);
1664 case PROP_BACKGROUND_STIPPLE_SET:
1665 g_value_set_boolean (value, tag->bg_stipple_set);
1668 case PROP_FOREGROUND_STIPPLE_SET:
1669 g_value_set_boolean (value, tag->fg_stipple_set);
1672 case PROP_FAMILY_SET:
1673 case PROP_STYLE_SET:
1674 case PROP_VARIANT_SET:
1675 case PROP_WEIGHT_SET:
1676 case PROP_STRETCH_SET:
1679 PangoFontMask set_mask = tag->values->font ? pango_font_description_get_set_fields (tag->values->font) : 0;
1680 PangoFontMask test_mask = get_property_font_set_mask (prop_id);
1681 g_value_set_boolean (value, (set_mask & test_mask) != 0);
1686 case PROP_SCALE_SET:
1687 g_value_set_boolean (value, tag->scale_set);
1690 case PROP_PIXELS_ABOVE_LINES_SET:
1691 g_value_set_boolean (value, tag->pixels_above_lines_set);
1694 case PROP_PIXELS_BELOW_LINES_SET:
1695 g_value_set_boolean (value, tag->pixels_below_lines_set);
1698 case PROP_PIXELS_INSIDE_WRAP_SET:
1699 g_value_set_boolean (value, tag->pixels_inside_wrap_set);
1702 case PROP_EDITABLE_SET:
1703 g_value_set_boolean (value, tag->editable_set);
1706 case PROP_WRAP_MODE_SET:
1707 g_value_set_boolean (value, tag->wrap_mode_set);
1710 case PROP_JUSTIFICATION_SET:
1711 g_value_set_boolean (value, tag->justification_set);
1714 case PROP_LEFT_MARGIN_SET:
1715 g_value_set_boolean (value, tag->left_margin_set);
1718 case PROP_INDENT_SET:
1719 g_value_set_boolean (value, tag->indent_set);
1722 case PROP_STRIKETHROUGH_SET:
1723 g_value_set_boolean (value, tag->strikethrough_set);
1726 case PROP_RIGHT_MARGIN_SET:
1727 g_value_set_boolean (value, tag->right_margin_set);
1730 case PROP_UNDERLINE_SET:
1731 g_value_set_boolean (value, tag->underline_set);
1735 g_value_set_boolean (value, tag->rise_set);
1738 case PROP_BACKGROUND_FULL_HEIGHT_SET:
1739 g_value_set_boolean (value, tag->bg_full_height_set);
1742 case PROP_LANGUAGE_SET:
1743 g_value_set_boolean (value, tag->language_set);
1747 g_value_set_boolean (value, tag->tabs_set);
1750 case PROP_INVISIBLE_SET:
1751 g_value_set_boolean (value, tag->invisible_set);
1754 case PROP_PARAGRAPH_BACKGROUND_SET:
1755 g_value_set_boolean (value, tag->pg_bg_color_set);
1758 case PROP_BACKGROUND:
1759 case PROP_FOREGROUND:
1760 case PROP_PARAGRAPH_BACKGROUND:
1761 g_warning ("'foreground', 'background' and 'paragraph_background' properties are not readable, use 'foreground_gdk', 'background_gdk' and 'paragraph_background_gdk'");
1763 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1779 delta_priority_foreach (GtkTextTag *tag, gpointer user_data)
1781 DeltaData *dd = user_data;
1783 if (tag->priority >= dd->low && tag->priority <= dd->high)
1784 tag->priority += dd->delta;
1788 * gtk_text_tag_get_priority:
1789 * @tag: a #GtkTextTag
1791 * Get the tag priority.
1793 * Return value: The tag's priority.
1796 gtk_text_tag_get_priority (GtkTextTag *tag)
1798 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), 0);
1800 return tag->priority;
1804 * gtk_text_tag_set_priority:
1805 * @tag: a #GtkTextTag
1806 * @priority: the new priority
1808 * Sets the priority of a #GtkTextTag. Valid priorities are
1809 * start at 0 and go to one less than gtk_text_tag_table_get_size().
1810 * Each tag in a table has a unique priority; setting the priority
1811 * of one tag shifts the priorities of all the other tags in the
1812 * table to maintain a unique priority for each tag. Higher priority
1813 * tags "win" if two tags both set the same text attribute. When adding
1814 * a tag to a tag table, it will be assigned the highest priority in
1815 * the table by default; so normally the precedence of a set of tags
1816 * is the order in which they were added to the table, or created with
1817 * gtk_text_buffer_create_tag(), which adds the tag to the buffer's table
1821 gtk_text_tag_set_priority (GtkTextTag *tag,
1826 g_return_if_fail (GTK_IS_TEXT_TAG (tag));
1827 g_return_if_fail (tag->table != NULL);
1828 g_return_if_fail (priority >= 0);
1829 g_return_if_fail (priority < gtk_text_tag_table_get_size (tag->table));
1831 if (priority == tag->priority)
1834 if (priority < tag->priority)
1837 dd.high = tag->priority - 1;
1842 dd.low = tag->priority + 1;
1847 gtk_text_tag_table_foreach (tag->table,
1848 delta_priority_foreach,
1851 tag->priority = priority;
1855 * gtk_text_tag_event:
1856 * @tag: a #GtkTextTag
1857 * @event_object: object that received the event, such as a widget
1859 * @iter: location where the event was received
1861 * Emits the "event" signal on the #GtkTextTag.
1863 * Return value: result of signal emission (whether the event was handled)
1866 gtk_text_tag_event (GtkTextTag *tag,
1867 GObject *event_object,
1869 const GtkTextIter *iter)
1871 gboolean retval = FALSE;
1873 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
1874 g_return_val_if_fail (G_IS_OBJECT (event_object), FALSE);
1875 g_return_val_if_fail (event != NULL, FALSE);
1889 tag_sort_func (gconstpointer first, gconstpointer second)
1891 GtkTextTag *tag1, *tag2;
1893 tag1 = * (GtkTextTag **) first;
1894 tag2 = * (GtkTextTag **) second;
1895 return tag1->priority - tag2->priority;
1899 _gtk_text_tag_array_sort (GtkTextTag** tag_array_p,
1904 GtkTextTag **maxPtrPtr, *tmp;
1906 g_return_if_fail (tag_array_p != NULL);
1907 g_return_if_fail (len > 0);
1913 GtkTextTag **iter = tag_array_p;
1915 for (i = len-1; i > 0; i--, iter++) {
1916 maxPtrPtr = tag = iter;
1917 prio = tag[0]->priority;
1918 for (j = i, tag++; j > 0; j--, tag++) {
1919 if (tag[0]->priority < prio) {
1920 prio = tag[0]->priority;
1929 qsort ((void *) tag_array_p, (unsigned) len, sizeof (GtkTextTag *),
1935 printf ("Sorted tag array: \n");
1939 GtkTextTag *t = tag_array_p[i];
1940 printf (" %s priority %d\n", t->name, t->priority);
1953 * gtk_text_attributes_new:
1955 * Creates a #GtkTextAttributes, which describes
1956 * a set of properties on some text.
1958 * Return value: a new #GtkTextAttributes
1961 gtk_text_attributes_new (void)
1963 GtkTextAttributes *values;
1965 values = g_new0 (GtkTextAttributes, 1);
1967 /* 0 is a valid value for most of the struct */
1969 values->refcount = 1;
1971 values->language = gtk_get_default_language ();
1973 values->font_scale = 1.0;
1975 values->editable = TRUE;
1981 * gtk_text_attributes_copy:
1982 * @src: a #GtkTextAttributes to be copied
1984 * Copies @src and returns a new #GtkTextAttributes.
1986 * Return value: a copy of @src
1989 gtk_text_attributes_copy (GtkTextAttributes *src)
1991 GtkTextAttributes *dest;
1993 dest = gtk_text_attributes_new ();
1994 gtk_text_attributes_copy_values (src, dest);
2000 gtk_text_attributes_get_type (void)
2002 static GType our_type = 0;
2005 our_type = g_boxed_type_register_static (I_("GtkTextAttributes"),
2006 (GBoxedCopyFunc) gtk_text_attributes_ref,
2007 (GBoxedFreeFunc) gtk_text_attributes_unref);
2013 * gtk_text_attributes_copy_values:
2014 * @src: a #GtkTextAttributes
2015 * @dest: another #GtkTextAttributes
2017 * Copies the values from @src to @dest so that @dest has the same values
2018 * as @src. Frees existing values in @dest.
2021 gtk_text_attributes_copy_values (GtkTextAttributes *src,
2022 GtkTextAttributes *dest)
2024 guint orig_refcount;
2026 g_return_if_fail (!dest->realized);
2033 if (src->appearance.bg_stipple)
2034 g_object_ref (src->appearance.bg_stipple);
2036 if (src->appearance.fg_stipple)
2037 g_object_ref (src->appearance.fg_stipple);
2041 if (dest->appearance.bg_stipple)
2042 g_object_unref (dest->appearance.bg_stipple);
2044 if (dest->appearance.fg_stipple)
2045 g_object_unref (dest->appearance.fg_stipple);
2048 pango_font_description_free (dest->font);
2051 orig_refcount = dest->refcount;
2056 dest->tabs = pango_tab_array_copy (src->tabs);
2058 dest->language = src->language;
2061 dest->font = pango_font_description_copy (src->font);
2063 if (src->pg_bg_color)
2064 dest->pg_bg_color = gdk_color_copy (src->pg_bg_color);
2066 dest->refcount = orig_refcount;
2067 dest->realized = FALSE;
2071 * gtk_text_attributes_ref:
2072 * @values: a #GtkTextAttributes
2074 * Increments the reference count on @values.
2076 * Returns: the #GtkTextAttributes that were passed in
2079 gtk_text_attributes_ref (GtkTextAttributes *values)
2081 g_return_val_if_fail (values != NULL, NULL);
2083 values->refcount += 1;
2089 * gtk_text_attributes_unref:
2090 * @values: a #GtkTextAttributes
2092 * Decrements the reference count on @values, freeing the structure
2093 * if the reference count reaches 0.
2096 gtk_text_attributes_unref (GtkTextAttributes *values)
2098 g_return_if_fail (values != NULL);
2099 g_return_if_fail (values->refcount > 0);
2101 values->refcount -= 1;
2103 if (values->refcount == 0)
2105 g_assert (!values->realized);
2107 if (values->appearance.bg_stipple)
2108 g_object_unref (values->appearance.bg_stipple);
2110 if (values->appearance.fg_stipple)
2111 g_object_unref (values->appearance.fg_stipple);
2114 pango_tab_array_free (values->tabs);
2117 pango_font_description_free (values->font);
2119 if (values->pg_bg_color)
2120 gdk_color_free (values->pg_bg_color);
2127 _gtk_text_attributes_realize (GtkTextAttributes *values,
2131 g_return_if_fail (values != NULL);
2132 g_return_if_fail (values->refcount > 0);
2133 g_return_if_fail (!values->realized);
2135 /* It is wrong to use this colormap, FIXME */
2136 gdk_colormap_alloc_color (cmap,
2137 &values->appearance.fg_color,
2140 gdk_colormap_alloc_color (cmap,
2141 &values->appearance.bg_color,
2144 if (values->pg_bg_color)
2145 gdk_colormap_alloc_color (cmap,
2146 values->pg_bg_color,
2149 values->realized = TRUE;
2153 _gtk_text_attributes_unrealize (GtkTextAttributes *values,
2157 g_return_if_fail (values != NULL);
2158 g_return_if_fail (values->refcount > 0);
2159 g_return_if_fail (values->realized);
2161 gdk_colormap_free_colors (cmap,
2162 &values->appearance.fg_color, 1);
2165 gdk_colormap_free_colors (cmap,
2166 &values->appearance.bg_color, 1);
2168 values->appearance.fg_color.pixel = 0;
2169 values->appearance.bg_color.pixel = 0;
2171 if (values->pg_bg_color)
2173 gdk_colormap_free_colors (cmap, values->pg_bg_color, 1);
2175 values->pg_bg_color->pixel = 0;
2178 values->realized = FALSE;
2182 _gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest,
2188 guint left_margin_accumulative = 0;
2189 guint right_margin_accumulative = 0;
2191 g_return_if_fail (!dest->realized);
2195 GtkTextTag *tag = tags[n];
2196 GtkTextAttributes *vals = tag->values;
2198 g_assert (tag->table != NULL);
2200 g_assert (tags[n]->priority > tags[n-1]->priority);
2202 if (tag->bg_color_set)
2204 dest->appearance.bg_color = vals->appearance.bg_color;
2206 dest->appearance.draw_bg = TRUE;
2208 if (tag->fg_color_set)
2209 dest->appearance.fg_color = vals->appearance.fg_color;
2211 if (tag->pg_bg_color_set)
2213 dest->pg_bg_color = gdk_color_copy (vals->pg_bg_color);
2216 if (tag->bg_stipple_set)
2218 g_object_ref (vals->appearance.bg_stipple);
2219 if (dest->appearance.bg_stipple)
2220 g_object_unref (dest->appearance.bg_stipple);
2221 dest->appearance.bg_stipple = vals->appearance.bg_stipple;
2223 dest->appearance.draw_bg = TRUE;
2226 if (tag->fg_stipple_set)
2228 g_object_ref (vals->appearance.fg_stipple);
2229 if (dest->appearance.fg_stipple)
2230 g_object_unref (dest->appearance.fg_stipple);
2231 dest->appearance.fg_stipple = vals->appearance.fg_stipple;
2237 pango_font_description_merge (dest->font, vals->font, TRUE);
2239 dest->font = pango_font_description_copy (vals->font);
2242 /* multiply all the scales together to get a composite */
2244 dest->font_scale *= vals->font_scale;
2246 if (tag->justification_set)
2247 dest->justification = vals->justification;
2249 if (vals->direction != GTK_TEXT_DIR_NONE)
2250 dest->direction = vals->direction;
2252 if (tag->left_margin_set)
2254 if (tag->accumulative_margin)
2255 left_margin_accumulative += vals->left_margin;
2257 dest->left_margin = vals->left_margin;
2260 if (tag->indent_set)
2261 dest->indent = vals->indent;
2264 dest->appearance.rise = vals->appearance.rise;
2266 if (tag->right_margin_set)
2268 if (tag->accumulative_margin)
2269 right_margin_accumulative += vals->right_margin;
2271 dest->right_margin = vals->right_margin;
2274 if (tag->pixels_above_lines_set)
2275 dest->pixels_above_lines = vals->pixels_above_lines;
2277 if (tag->pixels_below_lines_set)
2278 dest->pixels_below_lines = vals->pixels_below_lines;
2280 if (tag->pixels_inside_wrap_set)
2281 dest->pixels_inside_wrap = vals->pixels_inside_wrap;
2286 pango_tab_array_free (dest->tabs);
2287 dest->tabs = pango_tab_array_copy (vals->tabs);
2290 if (tag->wrap_mode_set)
2291 dest->wrap_mode = vals->wrap_mode;
2293 if (tag->underline_set)
2294 dest->appearance.underline = vals->appearance.underline;
2296 if (tag->strikethrough_set)
2297 dest->appearance.strikethrough = vals->appearance.strikethrough;
2299 if (tag->invisible_set)
2300 dest->invisible = vals->invisible;
2302 if (tag->editable_set)
2303 dest->editable = vals->editable;
2305 if (tag->bg_full_height_set)
2306 dest->bg_full_height = vals->bg_full_height;
2308 if (tag->language_set)
2309 dest->language = vals->language;
2314 dest->left_margin += left_margin_accumulative;
2315 dest->right_margin += right_margin_accumulative;
2319 _gtk_text_tag_affects_size (GtkTextTag *tag)
2321 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
2324 (tag->values->font && pango_font_description_get_set_fields (tag->values->font) != 0) ||
2326 tag->justification_set ||
2327 tag->left_margin_set ||
2330 tag->right_margin_set ||
2331 tag->pixels_above_lines_set ||
2332 tag->pixels_below_lines_set ||
2333 tag->pixels_inside_wrap_set ||
2335 tag->underline_set ||
2336 tag->wrap_mode_set ||
2341 _gtk_text_tag_affects_nonsize_appearance (GtkTextTag *tag)
2343 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
2346 tag->bg_color_set ||
2347 tag->bg_stipple_set ||
2348 tag->fg_color_set ||
2349 tag->fg_stipple_set ||
2350 tag->strikethrough_set ||
2351 tag->bg_full_height_set ||
2352 tag->pg_bg_color_set;