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"
87 PROP_PIXELS_ABOVE_LINES,
88 PROP_PIXELS_BELOW_LINES,
89 PROP_PIXELS_INSIDE_WRAP,
100 PROP_BACKGROUND_FULL_HEIGHT,
104 PROP_PARAGRAPH_BACKGROUND,
105 PROP_PARAGRAPH_BACKGROUND_GDK,
108 PROP_ACCUMULATIVE_MARGIN,
110 /* Whether-a-style-arg-is-set args */
120 PROP_PIXELS_ABOVE_LINES_SET,
121 PROP_PIXELS_BELOW_LINES_SET,
122 PROP_PIXELS_INSIDE_WRAP_SET,
125 PROP_JUSTIFICATION_SET,
126 PROP_LEFT_MARGIN_SET,
128 PROP_STRIKETHROUGH_SET,
129 PROP_RIGHT_MARGIN_SET,
132 PROP_BACKGROUND_FULL_HEIGHT_SET,
136 PROP_PARAGRAPH_BACKGROUND_SET,
140 static void gtk_text_tag_finalize (GObject *object);
141 static void gtk_text_tag_set_property (GObject *object,
145 static void gtk_text_tag_get_property (GObject *object,
150 static guint signals[LAST_SIGNAL] = { 0 };
152 G_DEFINE_TYPE (GtkTextTag, gtk_text_tag, G_TYPE_OBJECT)
155 gtk_text_tag_class_init (GtkTextTagClass *klass)
157 GObjectClass *object_class = G_OBJECT_CLASS (klass);
159 object_class->set_property = gtk_text_tag_set_property;
160 object_class->get_property = gtk_text_tag_get_property;
162 object_class->finalize = gtk_text_tag_finalize;
165 g_object_class_install_property (object_class,
167 g_param_spec_string ("name",
169 P_("Name used to refer to the text tag. NULL for anonymous tags"),
171 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
175 g_object_class_install_property (object_class,
177 g_param_spec_string ("background",
178 P_("Background color name"),
179 P_("Background color as a string"),
181 GTK_PARAM_WRITABLE));
183 g_object_class_install_property (object_class,
185 g_param_spec_boxed ("background-gdk",
186 P_("Background color"),
187 P_("Background color as a (possibly unallocated) GdkColor"),
189 GTK_PARAM_READWRITE));
191 g_object_class_install_property (object_class,
192 PROP_BACKGROUND_FULL_HEIGHT,
193 g_param_spec_boolean ("background-full-height",
194 P_("Background full height"),
195 P_("Whether the background color fills the entire line height or only the height of the tagged characters"),
197 GTK_PARAM_READWRITE));
199 g_object_class_install_property (object_class,
201 g_param_spec_string ("foreground",
202 P_("Foreground color name"),
203 P_("Foreground color as a string"),
205 GTK_PARAM_WRITABLE));
207 g_object_class_install_property (object_class,
209 g_param_spec_boxed ("foreground-gdk",
210 P_("Foreground color"),
211 P_("Foreground color as a (possibly unallocated) GdkColor"),
213 GTK_PARAM_READWRITE));
215 g_object_class_install_property (object_class,
217 g_param_spec_enum ("direction",
218 P_("Text direction"),
219 P_("Text direction, e.g. right-to-left or left-to-right"),
220 GTK_TYPE_TEXT_DIRECTION,
222 GTK_PARAM_READWRITE));
224 g_object_class_install_property (object_class,
226 g_param_spec_boolean ("editable",
228 P_("Whether the text can be modified by the user"),
230 GTK_PARAM_READWRITE));
235 * Font description as string, e.g. \"Sans Italic 12\".
237 * Note that the initial value of this property depends on
238 * the internals of #PangoFontDescription.
240 g_object_class_install_property (object_class,
242 g_param_spec_string ("font",
244 P_("Font description as a string, e.g. \"Sans Italic 12\""),
246 GTK_PARAM_READWRITE));
248 g_object_class_install_property (object_class,
250 g_param_spec_boxed ("font-desc",
252 P_("Font description as a PangoFontDescription struct"),
253 PANGO_TYPE_FONT_DESCRIPTION,
254 GTK_PARAM_READWRITE));
256 g_object_class_install_property (object_class,
258 g_param_spec_string ("family",
260 P_("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
262 GTK_PARAM_READWRITE));
264 g_object_class_install_property (object_class,
266 g_param_spec_enum ("style",
268 P_("Font style as a PangoStyle, e.g. PANGO_STYLE_ITALIC"),
271 GTK_PARAM_READWRITE));
273 g_object_class_install_property (object_class,
275 g_param_spec_enum ("variant",
277 P_("Font variant as a PangoVariant, e.g. PANGO_VARIANT_SMALL_CAPS"),
279 PANGO_VARIANT_NORMAL,
280 GTK_PARAM_READWRITE));
282 g_object_class_install_property (object_class,
284 g_param_spec_int ("weight",
286 P_("Font weight as an integer, see predefined values in PangoWeight; for example, PANGO_WEIGHT_BOLD"),
290 GTK_PARAM_READWRITE));
293 g_object_class_install_property (object_class,
295 g_param_spec_enum ("stretch",
297 P_("Font stretch as a PangoStretch, e.g. PANGO_STRETCH_CONDENSED"),
299 PANGO_STRETCH_NORMAL,
300 GTK_PARAM_READWRITE));
302 g_object_class_install_property (object_class,
304 g_param_spec_int ("size",
306 P_("Font size in Pango units"),
310 GTK_PARAM_READWRITE));
312 g_object_class_install_property (object_class,
314 g_param_spec_double ("scale",
316 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"),
320 GTK_PARAM_READWRITE));
322 g_object_class_install_property (object_class,
324 g_param_spec_double ("size-points",
326 P_("Font size in points"),
330 GTK_PARAM_READWRITE));
332 g_object_class_install_property (object_class,
334 g_param_spec_enum ("justification",
336 P_("Left, right, or center justification"),
337 GTK_TYPE_JUSTIFICATION,
339 GTK_PARAM_READWRITE));
342 * GtkTextTag:language:
344 * The language this text is in, as an ISO code. Pango can use this as a
345 * hint when rendering the text. If not set, an appropriate default will be
348 * Note that the initial value of this property depends on the current
349 * locale, see also gtk_get_default_language().
351 g_object_class_install_property (object_class,
353 g_param_spec_string ("language",
355 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."),
357 GTK_PARAM_READWRITE));
359 g_object_class_install_property (object_class,
361 g_param_spec_int ("left-margin",
363 P_("Width of the left margin in pixels"),
367 GTK_PARAM_READWRITE));
369 g_object_class_install_property (object_class,
371 g_param_spec_int ("right-margin",
373 P_("Width of the right margin in pixels"),
377 GTK_PARAM_READWRITE));
380 g_object_class_install_property (object_class,
382 g_param_spec_int ("indent",
384 P_("Amount to indent the paragraph, in pixels"),
388 GTK_PARAM_READWRITE));
391 g_object_class_install_property (object_class,
393 g_param_spec_int ("rise",
395 P_("Offset of text above the baseline (below the baseline if rise is negative) in Pango units"),
399 GTK_PARAM_READWRITE));
401 g_object_class_install_property (object_class,
402 PROP_PIXELS_ABOVE_LINES,
403 g_param_spec_int ("pixels-above-lines",
404 P_("Pixels above lines"),
405 P_("Pixels of blank space above paragraphs"),
409 GTK_PARAM_READWRITE));
411 g_object_class_install_property (object_class,
412 PROP_PIXELS_BELOW_LINES,
413 g_param_spec_int ("pixels-below-lines",
414 P_("Pixels below lines"),
415 P_("Pixels of blank space below paragraphs"),
419 GTK_PARAM_READWRITE));
421 g_object_class_install_property (object_class,
422 PROP_PIXELS_INSIDE_WRAP,
423 g_param_spec_int ("pixels-inside-wrap",
424 P_("Pixels inside wrap"),
425 P_("Pixels of blank space between wrapped lines in a paragraph"),
429 GTK_PARAM_READWRITE));
431 g_object_class_install_property (object_class,
433 g_param_spec_boolean ("strikethrough",
435 P_("Whether to strike through the text"),
437 GTK_PARAM_READWRITE));
439 g_object_class_install_property (object_class,
441 g_param_spec_enum ("underline",
443 P_("Style of underline for this text"),
444 PANGO_TYPE_UNDERLINE,
445 PANGO_UNDERLINE_NONE,
446 GTK_PARAM_READWRITE));
448 g_object_class_install_property (object_class,
450 g_param_spec_enum ("wrap-mode",
452 P_("Whether to wrap lines never, at word boundaries, or at character boundaries"),
455 GTK_PARAM_READWRITE));
458 g_object_class_install_property (object_class,
460 g_param_spec_boxed ("tabs",
462 P_("Custom tabs for this text"),
463 PANGO_TYPE_TAB_ARRAY,
464 GTK_PARAM_READWRITE));
467 * GtkTextTag:invisible:
469 * Whether this text is hidden.
471 * Note that there may still be problems with the support for invisible
472 * text, in particular when navigating programmatically inside a buffer
473 * containing invisible segments.
477 g_object_class_install_property (object_class,
479 g_param_spec_boolean ("invisible",
481 P_("Whether this text is hidden."),
483 GTK_PARAM_READWRITE));
486 * GtkTextTag:paragraph-background:
488 * The paragraph background color as a string.
492 g_object_class_install_property (object_class,
493 PROP_PARAGRAPH_BACKGROUND,
494 g_param_spec_string ("paragraph-background",
495 P_("Paragraph background color name"),
496 P_("Paragraph background color as a string"),
498 GTK_PARAM_WRITABLE));
501 * GtkTextTag:paragraph-background-gdk:
503 * The paragraph background color as a as a (possibly unallocated)
508 g_object_class_install_property (object_class,
509 PROP_PARAGRAPH_BACKGROUND_GDK,
510 g_param_spec_boxed ("paragraph-background-gdk",
511 P_("Paragraph background color"),
512 P_("Paragraph background color as a (possibly unallocated) GdkColor"),
514 GTK_PARAM_READWRITE));
517 * GtkTextTag:accumulative-margin:
519 * Whether the margins accumulate or override each other.
521 * When set to %TRUE the margins of this tag are added to the margins
522 * of any other non-accumulative margins present. When set to %FALSE
523 * the margins override one another (the default).
527 g_object_class_install_property (object_class,
528 PROP_ACCUMULATIVE_MARGIN,
529 g_param_spec_boolean ("accumulative-margin",
530 P_("Margin Accumulates"),
531 P_("Whether left and right margins accumulate."),
533 GTK_PARAM_READWRITE));
535 /* Style props are set or not */
537 #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))
539 ADD_SET_PROP ("background-set", PROP_BACKGROUND_SET,
540 P_("Background set"),
541 P_("Whether this tag affects the background color"));
543 ADD_SET_PROP ("background-full-height-set", PROP_BACKGROUND_FULL_HEIGHT_SET,
544 P_("Background full height set"),
545 P_("Whether this tag affects background height"));
547 ADD_SET_PROP ("foreground-set", PROP_FOREGROUND_SET,
548 P_("Foreground set"),
549 P_("Whether this tag affects the foreground color"));
551 ADD_SET_PROP ("editable-set", PROP_EDITABLE_SET,
552 P_("Editability set"),
553 P_("Whether this tag affects text editability"));
555 ADD_SET_PROP ("family-set", PROP_FAMILY_SET,
556 P_("Font family set"),
557 P_("Whether this tag affects the font family"));
559 ADD_SET_PROP ("style-set", PROP_STYLE_SET,
560 P_("Font style set"),
561 P_("Whether this tag affects the font style"));
563 ADD_SET_PROP ("variant-set", PROP_VARIANT_SET,
564 P_("Font variant set"),
565 P_("Whether this tag affects the font variant"));
567 ADD_SET_PROP ("weight-set", PROP_WEIGHT_SET,
568 P_("Font weight set"),
569 P_("Whether this tag affects the font weight"));
571 ADD_SET_PROP ("stretch-set", PROP_STRETCH_SET,
572 P_("Font stretch set"),
573 P_("Whether this tag affects the font stretch"));
575 ADD_SET_PROP ("size-set", PROP_SIZE_SET,
577 P_("Whether this tag affects the font size"));
579 ADD_SET_PROP ("scale-set", PROP_SCALE_SET,
580 P_("Font scale set"),
581 P_("Whether this tag scales the font size by a factor"));
583 ADD_SET_PROP ("justification-set", PROP_JUSTIFICATION_SET,
584 P_("Justification set"),
585 P_("Whether this tag affects paragraph justification"));
587 ADD_SET_PROP ("language-set", PROP_LANGUAGE_SET,
589 P_("Whether this tag affects the language the text is rendered as"));
591 ADD_SET_PROP ("left-margin-set", PROP_LEFT_MARGIN_SET,
592 P_("Left margin set"),
593 P_("Whether this tag affects the left margin"));
595 ADD_SET_PROP ("indent-set", PROP_INDENT_SET,
597 P_("Whether this tag affects indentation"));
599 ADD_SET_PROP ("rise-set", PROP_RISE_SET,
601 P_("Whether this tag affects the rise"));
603 ADD_SET_PROP ("pixels-above-lines-set", PROP_PIXELS_ABOVE_LINES_SET,
604 P_("Pixels above lines set"),
605 P_("Whether this tag affects the number of pixels above lines"));
607 ADD_SET_PROP ("pixels-below-lines-set", PROP_PIXELS_BELOW_LINES_SET,
608 P_("Pixels below lines set"),
609 P_("Whether this tag affects the number of pixels above lines"));
611 ADD_SET_PROP ("pixels-inside-wrap-set", PROP_PIXELS_INSIDE_WRAP_SET,
612 P_("Pixels inside wrap set"),
613 P_("Whether this tag affects the number of pixels between wrapped lines"));
615 ADD_SET_PROP ("strikethrough-set", PROP_STRIKETHROUGH_SET,
616 P_("Strikethrough set"),
617 P_("Whether this tag affects strikethrough"));
619 ADD_SET_PROP ("right-margin-set", PROP_RIGHT_MARGIN_SET,
620 P_("Right margin set"),
621 P_("Whether this tag affects the right margin"));
623 ADD_SET_PROP ("underline-set", PROP_UNDERLINE_SET,
625 P_("Whether this tag affects underlining"));
627 ADD_SET_PROP ("wrap-mode-set", PROP_WRAP_MODE_SET,
629 P_("Whether this tag affects line wrap mode"));
631 ADD_SET_PROP ("tabs-set", PROP_TABS_SET,
633 P_("Whether this tag affects tabs"));
635 ADD_SET_PROP ("invisible-set", PROP_INVISIBLE_SET,
637 P_("Whether this tag affects text visibility"));
639 ADD_SET_PROP ("paragraph-background-set", PROP_PARAGRAPH_BACKGROUND_SET,
640 P_("Paragraph background set"),
641 P_("Whether this tag affects the paragraph background color"));
645 * @tag: the #GtkTextTag on which the signal is emitted
646 * @object: the object the event was fired from (typically a #GtkTextView)
647 * @event: the event which triggered the signal
648 * @iter: a #GtkTextIter pointing at the location the event occured
650 * The ::event signal is emitted when an event occurs on a region of the
651 * buffer marked with this tag.
653 * Returns: %TRUE to stop other handlers from being invoked for the
654 * event. %FALSE to propagate the event further.
657 g_signal_new (I_("event"),
658 G_OBJECT_CLASS_TYPE (object_class),
660 G_STRUCT_OFFSET (GtkTextTagClass, event),
661 _gtk_boolean_handled_accumulator, NULL,
662 _gtk_marshal_BOOLEAN__OBJECT_BOXED_BOXED,
666 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE,
671 gtk_text_tag_init (GtkTextTag *text_tag)
673 text_tag->values = gtk_text_attributes_new ();
678 * @name: (allow-none): tag name, or %NULL
680 * Creates a #GtkTextTag. Configure the tag using object arguments,
681 * i.e. using g_object_set().
683 * Return value: a new #GtkTextTag
686 gtk_text_tag_new (const gchar *name)
690 tag = g_object_new (GTK_TYPE_TEXT_TAG, "name", name, NULL);
696 gtk_text_tag_finalize (GObject *object)
698 GtkTextTag *text_tag;
700 text_tag = GTK_TEXT_TAG (object);
702 g_assert (!text_tag->values->realized);
705 gtk_text_tag_table_remove (text_tag->table, text_tag);
707 g_assert (text_tag->table == NULL);
709 gtk_text_attributes_unref (text_tag->values);
710 text_tag->values = NULL;
712 g_free (text_tag->name);
713 text_tag->name = NULL;
715 G_OBJECT_CLASS (gtk_text_tag_parent_class)->finalize (object);
719 set_bg_color (GtkTextTag *tag, GdkColor *color)
723 if (!tag->bg_color_set)
725 tag->bg_color_set = TRUE;
726 g_object_notify (G_OBJECT (tag), "background-set");
729 tag->values->appearance.bg_color = *color;
733 if (tag->bg_color_set)
735 tag->bg_color_set = FALSE;
736 g_object_notify (G_OBJECT (tag), "background-set");
742 set_fg_color (GtkTextTag *tag, GdkColor *color)
746 if (!tag->fg_color_set)
748 tag->fg_color_set = TRUE;
749 g_object_notify (G_OBJECT (tag), "foreground-set");
751 tag->values->appearance.fg_color = *color;
755 if (tag->fg_color_set)
757 tag->fg_color_set = FALSE;
758 g_object_notify (G_OBJECT (tag), "foreground-set");
764 set_pg_bg_color (GtkTextTag *tag, GdkColor *color)
768 if (!tag->pg_bg_color_set)
770 tag->pg_bg_color_set = TRUE;
771 g_object_notify (G_OBJECT (tag), "paragraph-background-set");
774 gdk_color_free (tag->values->pg_bg_color);
776 tag->values->pg_bg_color = gdk_color_copy (color);
780 if (tag->pg_bg_color_set)
782 tag->pg_bg_color_set = FALSE;
783 g_object_notify (G_OBJECT (tag), "paragraph-background-set");
784 gdk_color_free (tag->values->pg_bg_color);
787 tag->values->pg_bg_color = NULL;
792 get_property_font_set_mask (guint prop_id)
796 case PROP_FAMILY_SET:
797 return PANGO_FONT_MASK_FAMILY;
799 return PANGO_FONT_MASK_STYLE;
800 case PROP_VARIANT_SET:
801 return PANGO_FONT_MASK_VARIANT;
802 case PROP_WEIGHT_SET:
803 return PANGO_FONT_MASK_WEIGHT;
804 case PROP_STRETCH_SET:
805 return PANGO_FONT_MASK_STRETCH;
807 return PANGO_FONT_MASK_SIZE;
814 set_font_desc_fields (PangoFontDescription *desc,
815 PangoFontMask to_set)
817 PangoFontMask changed_mask = 0;
819 if (to_set & PANGO_FONT_MASK_FAMILY)
821 const char *family = pango_font_description_get_family (desc);
825 changed_mask |= PANGO_FONT_MASK_FAMILY;
828 pango_font_description_set_family (desc, family);
830 if (to_set & PANGO_FONT_MASK_STYLE)
831 pango_font_description_set_style (desc, pango_font_description_get_style (desc));
832 if (to_set & PANGO_FONT_MASK_VARIANT)
833 pango_font_description_set_variant (desc, pango_font_description_get_variant (desc));
834 if (to_set & PANGO_FONT_MASK_WEIGHT)
835 pango_font_description_set_weight (desc, pango_font_description_get_weight (desc));
836 if (to_set & PANGO_FONT_MASK_STRETCH)
837 pango_font_description_set_stretch (desc, pango_font_description_get_stretch (desc));
838 if (to_set & PANGO_FONT_MASK_SIZE)
840 gint size = pango_font_description_get_size (desc);
843 size = 10 * PANGO_SCALE;
844 changed_mask |= PANGO_FONT_MASK_SIZE;
847 pango_font_description_set_size (desc, size);
854 notify_set_changed (GObject *object,
855 PangoFontMask changed_mask)
857 if (changed_mask & PANGO_FONT_MASK_FAMILY)
858 g_object_notify (object, "family-set");
859 if (changed_mask & PANGO_FONT_MASK_STYLE)
860 g_object_notify (object, "style-set");
861 if (changed_mask & PANGO_FONT_MASK_VARIANT)
862 g_object_notify (object, "variant-set");
863 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
864 g_object_notify (object, "weight-set");
865 if (changed_mask & PANGO_FONT_MASK_STRETCH)
866 g_object_notify (object, "stretch-set");
867 if (changed_mask & PANGO_FONT_MASK_SIZE)
868 g_object_notify (object, "size-set");
872 notify_fields_changed (GObject *object,
873 PangoFontMask changed_mask)
875 if (changed_mask & PANGO_FONT_MASK_FAMILY)
876 g_object_notify (object, "family");
877 if (changed_mask & PANGO_FONT_MASK_STYLE)
878 g_object_notify (object, "style");
879 if (changed_mask & PANGO_FONT_MASK_VARIANT)
880 g_object_notify (object, "variant");
881 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
882 g_object_notify (object, "weight");
883 if (changed_mask & PANGO_FONT_MASK_STRETCH)
884 g_object_notify (object, "stretch");
885 if (changed_mask & PANGO_FONT_MASK_SIZE)
886 g_object_notify (object, "size");
890 set_font_description (GtkTextTag *text_tag,
891 PangoFontDescription *font_desc)
893 GObject *object = G_OBJECT (text_tag);
894 PangoFontDescription *new_font_desc;
895 PangoFontMask old_mask, new_mask, changed_mask, set_changed_mask;
898 new_font_desc = pango_font_description_copy (font_desc);
900 new_font_desc = pango_font_description_new ();
902 if (text_tag->values->font)
903 old_mask = pango_font_description_get_set_fields (text_tag->values->font);
907 new_mask = pango_font_description_get_set_fields (new_font_desc);
909 changed_mask = old_mask | new_mask;
910 set_changed_mask = old_mask ^ new_mask;
912 if (text_tag->values->font)
913 pango_font_description_free (text_tag->values->font);
914 text_tag->values->font = new_font_desc;
916 g_object_freeze_notify (object);
918 g_object_notify (object, "font-desc");
919 g_object_notify (object, "font");
921 if (changed_mask & PANGO_FONT_MASK_FAMILY)
922 g_object_notify (object, "family");
923 if (changed_mask & PANGO_FONT_MASK_STYLE)
924 g_object_notify (object, "style");
925 if (changed_mask & PANGO_FONT_MASK_VARIANT)
926 g_object_notify (object, "variant");
927 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
928 g_object_notify (object, "weight");
929 if (changed_mask & PANGO_FONT_MASK_STRETCH)
930 g_object_notify (object, "stretch");
931 if (changed_mask & PANGO_FONT_MASK_SIZE)
933 g_object_notify (object, "size");
934 g_object_notify (object, "size-points");
937 notify_set_changed (object, set_changed_mask);
939 g_object_thaw_notify (object);
943 gtk_text_tag_ensure_font (GtkTextTag *text_tag)
945 if (!text_tag->values->font)
946 text_tag->values->font = pango_font_description_new ();
950 gtk_text_tag_set_property (GObject *object,
955 GtkTextTag *text_tag;
956 gboolean size_changed = FALSE;
958 text_tag = GTK_TEXT_TAG (object);
960 g_return_if_fail (!text_tag->values->realized);
965 g_return_if_fail (text_tag->name == NULL);
966 text_tag->name = g_value_dup_string (value);
969 case PROP_BACKGROUND:
973 if (!g_value_get_string (value))
974 set_bg_color (text_tag, NULL); /* reset to background_set to FALSE */
975 else if (gdk_color_parse (g_value_get_string (value), &color))
976 set_bg_color (text_tag, &color);
978 g_warning ("Don't know color `%s'", g_value_get_string (value));
980 g_object_notify (object, "background-gdk");
984 case PROP_FOREGROUND:
988 if (!g_value_get_string (value))
989 set_fg_color (text_tag, NULL); /* reset to foreground_set to FALSE */
990 else if (gdk_color_parse (g_value_get_string (value), &color))
991 set_fg_color (text_tag, &color);
993 g_warning ("Don't know color `%s'", g_value_get_string (value));
995 g_object_notify (object, "foreground-gdk");
999 case PROP_BACKGROUND_GDK:
1001 GdkColor *color = g_value_get_boxed (value);
1003 set_bg_color (text_tag, color);
1007 case PROP_FOREGROUND_GDK:
1009 GdkColor *color = g_value_get_boxed (value);
1011 set_fg_color (text_tag, color);
1017 PangoFontDescription *font_desc = NULL;
1020 name = g_value_get_string (value);
1023 font_desc = pango_font_description_from_string (name);
1025 set_font_description (text_tag, font_desc);
1027 pango_font_description_free (font_desc);
1029 size_changed = TRUE;
1033 case PROP_FONT_DESC:
1035 PangoFontDescription *font_desc;
1037 font_desc = g_value_get_boxed (value);
1039 set_font_description (text_tag, font_desc);
1041 size_changed = TRUE;
1051 case PROP_SIZE_POINTS:
1053 PangoFontMask old_set_mask;
1055 gtk_text_tag_ensure_font (text_tag);
1056 old_set_mask = pango_font_description_get_set_fields (text_tag->values->font);
1061 pango_font_description_set_family (text_tag->values->font,
1062 g_value_get_string (value));
1065 pango_font_description_set_style (text_tag->values->font,
1066 g_value_get_enum (value));
1069 pango_font_description_set_variant (text_tag->values->font,
1070 g_value_get_enum (value));
1073 pango_font_description_set_weight (text_tag->values->font,
1074 g_value_get_int (value));
1077 pango_font_description_set_stretch (text_tag->values->font,
1078 g_value_get_enum (value));
1081 pango_font_description_set_size (text_tag->values->font,
1082 g_value_get_int (value));
1083 g_object_notify (object, "size-points");
1085 case PROP_SIZE_POINTS:
1086 pango_font_description_set_size (text_tag->values->font,
1087 g_value_get_double (value) * PANGO_SCALE);
1088 g_object_notify (object, "size");
1092 size_changed = TRUE;
1093 notify_set_changed (object, old_set_mask & pango_font_description_get_set_fields (text_tag->values->font));
1094 g_object_notify (object, "font-desc");
1095 g_object_notify (object, "font");
1101 text_tag->values->font_scale = g_value_get_double (value);
1102 text_tag->scale_set = TRUE;
1103 g_object_notify (object, "scale-set");
1104 size_changed = TRUE;
1107 case PROP_PIXELS_ABOVE_LINES:
1108 text_tag->pixels_above_lines_set = TRUE;
1109 text_tag->values->pixels_above_lines = g_value_get_int (value);
1110 g_object_notify (object, "pixels-above-lines-set");
1111 size_changed = TRUE;
1114 case PROP_PIXELS_BELOW_LINES:
1115 text_tag->pixels_below_lines_set = TRUE;
1116 text_tag->values->pixels_below_lines = g_value_get_int (value);
1117 g_object_notify (object, "pixels-below-lines-set");
1118 size_changed = TRUE;
1121 case PROP_PIXELS_INSIDE_WRAP:
1122 text_tag->pixels_inside_wrap_set = TRUE;
1123 text_tag->values->pixels_inside_wrap = g_value_get_int (value);
1124 g_object_notify (object, "pixels-inside-wrap-set");
1125 size_changed = TRUE;
1129 text_tag->editable_set = TRUE;
1130 text_tag->values->editable = g_value_get_boolean (value);
1131 g_object_notify (object, "editable-set");
1134 case PROP_WRAP_MODE:
1135 text_tag->wrap_mode_set = TRUE;
1136 text_tag->values->wrap_mode = g_value_get_enum (value);
1137 g_object_notify (object, "wrap-mode-set");
1138 size_changed = TRUE;
1141 case PROP_JUSTIFICATION:
1142 text_tag->justification_set = TRUE;
1143 text_tag->values->justification = g_value_get_enum (value);
1144 g_object_notify (object, "justification-set");
1145 size_changed = TRUE;
1148 case PROP_DIRECTION:
1149 text_tag->values->direction = g_value_get_enum (value);
1152 case PROP_LEFT_MARGIN:
1153 text_tag->left_margin_set = TRUE;
1154 text_tag->values->left_margin = g_value_get_int (value);
1155 g_object_notify (object, "left-margin-set");
1156 size_changed = TRUE;
1160 text_tag->indent_set = TRUE;
1161 text_tag->values->indent = g_value_get_int (value);
1162 g_object_notify (object, "indent-set");
1163 size_changed = TRUE;
1166 case PROP_STRIKETHROUGH:
1167 text_tag->strikethrough_set = TRUE;
1168 text_tag->values->appearance.strikethrough = g_value_get_boolean (value);
1169 g_object_notify (object, "strikethrough-set");
1172 case PROP_RIGHT_MARGIN:
1173 text_tag->right_margin_set = TRUE;
1174 text_tag->values->right_margin = g_value_get_int (value);
1175 g_object_notify (object, "right-margin-set");
1176 size_changed = TRUE;
1179 case PROP_UNDERLINE:
1180 text_tag->underline_set = TRUE;
1181 text_tag->values->appearance.underline = g_value_get_enum (value);
1182 g_object_notify (object, "underline-set");
1186 text_tag->rise_set = TRUE;
1187 text_tag->values->appearance.rise = g_value_get_int (value);
1188 g_object_notify (object, "rise-set");
1189 size_changed = TRUE;
1192 case PROP_BACKGROUND_FULL_HEIGHT:
1193 text_tag->bg_full_height_set = TRUE;
1194 text_tag->values->bg_full_height = g_value_get_boolean (value);
1195 g_object_notify (object, "background-full-height-set");
1199 text_tag->language_set = TRUE;
1200 text_tag->values->language = pango_language_from_string (g_value_get_string (value));
1201 g_object_notify (object, "language-set");
1205 text_tag->tabs_set = TRUE;
1207 if (text_tag->values->tabs)
1208 pango_tab_array_free (text_tag->values->tabs);
1210 /* FIXME I'm not sure if this is a memleak or not */
1211 text_tag->values->tabs =
1212 pango_tab_array_copy (g_value_get_boxed (value));
1214 g_object_notify (object, "tabs-set");
1216 size_changed = TRUE;
1219 case PROP_INVISIBLE:
1220 text_tag->invisible_set = TRUE;
1221 text_tag->values->invisible = g_value_get_boolean (value);
1222 g_object_notify (object, "invisible-set");
1223 size_changed = TRUE;
1226 case PROP_PARAGRAPH_BACKGROUND:
1230 if (!g_value_get_string (value))
1231 set_pg_bg_color (text_tag, NULL); /* reset to paragraph_background_set to FALSE */
1232 else if (gdk_color_parse (g_value_get_string (value), &color))
1233 set_pg_bg_color (text_tag, &color);
1235 g_warning ("Don't know color `%s'", g_value_get_string (value));
1237 g_object_notify (object, "paragraph-background-gdk");
1241 case PROP_PARAGRAPH_BACKGROUND_GDK:
1243 GdkColor *color = g_value_get_boxed (value);
1245 set_pg_bg_color (text_tag, color);
1249 case PROP_ACCUMULATIVE_MARGIN:
1250 text_tag->accumulative_margin = g_value_get_boolean (value);
1251 g_object_notify (object, "accumulative-margin");
1252 size_changed = TRUE;
1255 /* Whether the value should be used... */
1257 case PROP_BACKGROUND_SET:
1258 text_tag->bg_color_set = g_value_get_boolean (value);
1261 case PROP_FOREGROUND_SET:
1262 text_tag->fg_color_set = g_value_get_boolean (value);
1265 case PROP_FAMILY_SET:
1266 case PROP_STYLE_SET:
1267 case PROP_VARIANT_SET:
1268 case PROP_WEIGHT_SET:
1269 case PROP_STRETCH_SET:
1271 if (!g_value_get_boolean (value))
1273 if (text_tag->values->font)
1274 pango_font_description_unset_fields (text_tag->values->font,
1275 get_property_font_set_mask (prop_id));
1279 PangoFontMask changed_mask;
1281 gtk_text_tag_ensure_font (text_tag);
1282 changed_mask = set_font_desc_fields (text_tag->values->font,
1283 get_property_font_set_mask (prop_id));
1284 notify_fields_changed (G_OBJECT (text_tag), changed_mask);
1288 case PROP_SCALE_SET:
1289 text_tag->scale_set = g_value_get_boolean (value);
1290 size_changed = TRUE;
1293 case PROP_PIXELS_ABOVE_LINES_SET:
1294 text_tag->pixels_above_lines_set = g_value_get_boolean (value);
1295 size_changed = TRUE;
1298 case PROP_PIXELS_BELOW_LINES_SET:
1299 text_tag->pixels_below_lines_set = g_value_get_boolean (value);
1300 size_changed = TRUE;
1303 case PROP_PIXELS_INSIDE_WRAP_SET:
1304 text_tag->pixels_inside_wrap_set = g_value_get_boolean (value);
1305 size_changed = TRUE;
1308 case PROP_EDITABLE_SET:
1309 text_tag->editable_set = g_value_get_boolean (value);
1312 case PROP_WRAP_MODE_SET:
1313 text_tag->wrap_mode_set = g_value_get_boolean (value);
1314 size_changed = TRUE;
1317 case PROP_JUSTIFICATION_SET:
1318 text_tag->justification_set = g_value_get_boolean (value);
1319 size_changed = TRUE;
1322 case PROP_LEFT_MARGIN_SET:
1323 text_tag->left_margin_set = g_value_get_boolean (value);
1324 size_changed = TRUE;
1327 case PROP_INDENT_SET:
1328 text_tag->indent_set = g_value_get_boolean (value);
1329 size_changed = TRUE;
1332 case PROP_STRIKETHROUGH_SET:
1333 text_tag->strikethrough_set = g_value_get_boolean (value);
1336 case PROP_RIGHT_MARGIN_SET:
1337 text_tag->right_margin_set = g_value_get_boolean (value);
1338 size_changed = TRUE;
1341 case PROP_UNDERLINE_SET:
1342 text_tag->underline_set = g_value_get_boolean (value);
1346 text_tag->rise_set = g_value_get_boolean (value);
1347 size_changed = TRUE;
1350 case PROP_BACKGROUND_FULL_HEIGHT_SET:
1351 text_tag->bg_full_height_set = g_value_get_boolean (value);
1354 case PROP_LANGUAGE_SET:
1355 text_tag->language_set = g_value_get_boolean (value);
1356 size_changed = TRUE;
1360 text_tag->tabs_set = g_value_get_boolean (value);
1361 size_changed = TRUE;
1364 case PROP_INVISIBLE_SET:
1365 text_tag->invisible_set = g_value_get_boolean (value);
1366 size_changed = TRUE;
1369 case PROP_PARAGRAPH_BACKGROUND_SET:
1370 text_tag->pg_bg_color_set = g_value_get_boolean (value);
1374 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1378 /* FIXME I would like to do this after all set_property in a single
1379 * g_object_set () have been called. But an idle function won't
1380 * work; we need to emit when the tag is changed, not when we get
1381 * around to the event loop. So blah, we eat some inefficiency.
1384 /* This is also somewhat weird since we emit another object's
1385 * signal here, but the two objects are already tightly bound.
1388 if (text_tag->table)
1389 g_signal_emit_by_name (text_tag->table,
1391 text_tag, size_changed);
1395 gtk_text_tag_get_property (GObject *object,
1402 tag = GTK_TEXT_TAG (object);
1407 g_value_set_string (value, tag->name);
1410 case PROP_BACKGROUND_GDK:
1411 g_value_set_boxed (value, &tag->values->appearance.bg_color);
1414 case PROP_FOREGROUND_GDK:
1415 g_value_set_boxed (value, &tag->values->appearance.fg_color);
1422 gtk_text_tag_ensure_font (tag);
1424 str = pango_font_description_to_string (tag->values->font);
1425 g_value_take_string (value, str);
1429 case PROP_FONT_DESC:
1430 gtk_text_tag_ensure_font (tag);
1431 g_value_set_boxed (value, tag->values->font);
1440 case PROP_SIZE_POINTS:
1441 gtk_text_tag_ensure_font (tag);
1445 g_value_set_string (value, pango_font_description_get_family (tag->values->font));
1449 g_value_set_enum (value, pango_font_description_get_style (tag->values->font));
1453 g_value_set_enum (value, pango_font_description_get_variant (tag->values->font));
1457 g_value_set_int (value, pango_font_description_get_weight (tag->values->font));
1461 g_value_set_enum (value, pango_font_description_get_stretch (tag->values->font));
1465 g_value_set_int (value, pango_font_description_get_size (tag->values->font));
1468 case PROP_SIZE_POINTS:
1469 g_value_set_double (value, ((double)pango_font_description_get_size (tag->values->font)) / (double)PANGO_SCALE);
1475 g_value_set_double (value, tag->values->font_scale);
1478 case PROP_PIXELS_ABOVE_LINES:
1479 g_value_set_int (value, tag->values->pixels_above_lines);
1482 case PROP_PIXELS_BELOW_LINES:
1483 g_value_set_int (value, tag->values->pixels_below_lines);
1486 case PROP_PIXELS_INSIDE_WRAP:
1487 g_value_set_int (value, tag->values->pixels_inside_wrap);
1491 g_value_set_boolean (value, tag->values->editable);
1494 case PROP_WRAP_MODE:
1495 g_value_set_enum (value, tag->values->wrap_mode);
1498 case PROP_JUSTIFICATION:
1499 g_value_set_enum (value, tag->values->justification);
1502 case PROP_DIRECTION:
1503 g_value_set_enum (value, tag->values->direction);
1506 case PROP_LEFT_MARGIN:
1507 g_value_set_int (value, tag->values->left_margin);
1511 g_value_set_int (value, tag->values->indent);
1514 case PROP_STRIKETHROUGH:
1515 g_value_set_boolean (value, tag->values->appearance.strikethrough);
1518 case PROP_RIGHT_MARGIN:
1519 g_value_set_int (value, tag->values->right_margin);
1522 case PROP_UNDERLINE:
1523 g_value_set_enum (value, tag->values->appearance.underline);
1527 g_value_set_int (value, tag->values->appearance.rise);
1530 case PROP_BACKGROUND_FULL_HEIGHT:
1531 g_value_set_boolean (value, tag->values->bg_full_height);
1535 g_value_set_string (value, pango_language_to_string (tag->values->language));
1539 if (tag->values->tabs)
1540 g_value_set_boxed (value, tag->values->tabs);
1543 case PROP_INVISIBLE:
1544 g_value_set_boolean (value, tag->values->invisible);
1547 case PROP_PARAGRAPH_BACKGROUND_GDK:
1548 g_value_set_boxed (value, tag->values->pg_bg_color);
1551 case PROP_ACCUMULATIVE_MARGIN:
1552 g_value_set_boolean (value, tag->accumulative_margin);
1555 case PROP_BACKGROUND_SET:
1556 g_value_set_boolean (value, tag->bg_color_set);
1559 case PROP_FOREGROUND_SET:
1560 g_value_set_boolean (value, tag->fg_color_set);
1563 case PROP_FAMILY_SET:
1564 case PROP_STYLE_SET:
1565 case PROP_VARIANT_SET:
1566 case PROP_WEIGHT_SET:
1567 case PROP_STRETCH_SET:
1570 PangoFontMask set_mask = tag->values->font ? pango_font_description_get_set_fields (tag->values->font) : 0;
1571 PangoFontMask test_mask = get_property_font_set_mask (prop_id);
1572 g_value_set_boolean (value, (set_mask & test_mask) != 0);
1577 case PROP_SCALE_SET:
1578 g_value_set_boolean (value, tag->scale_set);
1581 case PROP_PIXELS_ABOVE_LINES_SET:
1582 g_value_set_boolean (value, tag->pixels_above_lines_set);
1585 case PROP_PIXELS_BELOW_LINES_SET:
1586 g_value_set_boolean (value, tag->pixels_below_lines_set);
1589 case PROP_PIXELS_INSIDE_WRAP_SET:
1590 g_value_set_boolean (value, tag->pixels_inside_wrap_set);
1593 case PROP_EDITABLE_SET:
1594 g_value_set_boolean (value, tag->editable_set);
1597 case PROP_WRAP_MODE_SET:
1598 g_value_set_boolean (value, tag->wrap_mode_set);
1601 case PROP_JUSTIFICATION_SET:
1602 g_value_set_boolean (value, tag->justification_set);
1605 case PROP_LEFT_MARGIN_SET:
1606 g_value_set_boolean (value, tag->left_margin_set);
1609 case PROP_INDENT_SET:
1610 g_value_set_boolean (value, tag->indent_set);
1613 case PROP_STRIKETHROUGH_SET:
1614 g_value_set_boolean (value, tag->strikethrough_set);
1617 case PROP_RIGHT_MARGIN_SET:
1618 g_value_set_boolean (value, tag->right_margin_set);
1621 case PROP_UNDERLINE_SET:
1622 g_value_set_boolean (value, tag->underline_set);
1626 g_value_set_boolean (value, tag->rise_set);
1629 case PROP_BACKGROUND_FULL_HEIGHT_SET:
1630 g_value_set_boolean (value, tag->bg_full_height_set);
1633 case PROP_LANGUAGE_SET:
1634 g_value_set_boolean (value, tag->language_set);
1638 g_value_set_boolean (value, tag->tabs_set);
1641 case PROP_INVISIBLE_SET:
1642 g_value_set_boolean (value, tag->invisible_set);
1645 case PROP_PARAGRAPH_BACKGROUND_SET:
1646 g_value_set_boolean (value, tag->pg_bg_color_set);
1649 case PROP_BACKGROUND:
1650 case PROP_FOREGROUND:
1651 case PROP_PARAGRAPH_BACKGROUND:
1652 g_warning ("'foreground', 'background' and 'paragraph_background' properties are not readable, use 'foreground_gdk', 'background_gdk' and 'paragraph_background_gdk'");
1654 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1670 delta_priority_foreach (GtkTextTag *tag, gpointer user_data)
1672 DeltaData *dd = user_data;
1674 if (tag->priority >= dd->low && tag->priority <= dd->high)
1675 tag->priority += dd->delta;
1679 * gtk_text_tag_get_priority:
1680 * @tag: a #GtkTextTag
1682 * Get the tag priority.
1684 * Return value: The tag's priority.
1687 gtk_text_tag_get_priority (GtkTextTag *tag)
1689 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), 0);
1691 return tag->priority;
1695 * gtk_text_tag_set_priority:
1696 * @tag: a #GtkTextTag
1697 * @priority: the new priority
1699 * Sets the priority of a #GtkTextTag. Valid priorities are
1700 * start at 0 and go to one less than gtk_text_tag_table_get_size().
1701 * Each tag in a table has a unique priority; setting the priority
1702 * of one tag shifts the priorities of all the other tags in the
1703 * table to maintain a unique priority for each tag. Higher priority
1704 * tags "win" if two tags both set the same text attribute. When adding
1705 * a tag to a tag table, it will be assigned the highest priority in
1706 * the table by default; so normally the precedence of a set of tags
1707 * is the order in which they were added to the table, or created with
1708 * gtk_text_buffer_create_tag(), which adds the tag to the buffer's table
1712 gtk_text_tag_set_priority (GtkTextTag *tag,
1717 g_return_if_fail (GTK_IS_TEXT_TAG (tag));
1718 g_return_if_fail (tag->table != NULL);
1719 g_return_if_fail (priority >= 0);
1720 g_return_if_fail (priority < gtk_text_tag_table_get_size (tag->table));
1722 if (priority == tag->priority)
1725 if (priority < tag->priority)
1728 dd.high = tag->priority - 1;
1733 dd.low = tag->priority + 1;
1738 gtk_text_tag_table_foreach (tag->table,
1739 delta_priority_foreach,
1742 tag->priority = priority;
1746 * gtk_text_tag_event:
1747 * @tag: a #GtkTextTag
1748 * @event_object: object that received the event, such as a widget
1750 * @iter: location where the event was received
1752 * Emits the "event" signal on the #GtkTextTag.
1754 * Return value: result of signal emission (whether the event was handled)
1757 gtk_text_tag_event (GtkTextTag *tag,
1758 GObject *event_object,
1760 const GtkTextIter *iter)
1762 gboolean retval = FALSE;
1764 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
1765 g_return_val_if_fail (G_IS_OBJECT (event_object), FALSE);
1766 g_return_val_if_fail (event != NULL, FALSE);
1780 tag_sort_func (gconstpointer first, gconstpointer second)
1782 GtkTextTag *tag1, *tag2;
1784 tag1 = * (GtkTextTag **) first;
1785 tag2 = * (GtkTextTag **) second;
1786 return tag1->priority - tag2->priority;
1790 _gtk_text_tag_array_sort (GtkTextTag** tag_array_p,
1795 GtkTextTag **maxPtrPtr, *tmp;
1797 g_return_if_fail (tag_array_p != NULL);
1798 g_return_if_fail (len > 0);
1804 GtkTextTag **iter = tag_array_p;
1806 for (i = len-1; i > 0; i--, iter++) {
1807 maxPtrPtr = tag = iter;
1808 prio = tag[0]->priority;
1809 for (j = i, tag++; j > 0; j--, tag++) {
1810 if (tag[0]->priority < prio) {
1811 prio = tag[0]->priority;
1820 qsort ((void *) tag_array_p, (unsigned) len, sizeof (GtkTextTag *),
1826 printf ("Sorted tag array: \n");
1830 GtkTextTag *t = tag_array_p[i];
1831 printf (" %s priority %d\n", t->name, t->priority);
1844 * gtk_text_attributes_new:
1846 * Creates a #GtkTextAttributes, which describes
1847 * a set of properties on some text.
1849 * Return value: a new #GtkTextAttributes
1852 gtk_text_attributes_new (void)
1854 GtkTextAttributes *values;
1856 values = g_new0 (GtkTextAttributes, 1);
1858 /* 0 is a valid value for most of the struct */
1860 values->refcount = 1;
1862 values->language = gtk_get_default_language ();
1864 values->font_scale = 1.0;
1866 values->editable = TRUE;
1872 * gtk_text_attributes_copy:
1873 * @src: a #GtkTextAttributes to be copied
1875 * Copies @src and returns a new #GtkTextAttributes.
1877 * Return value: a copy of @src
1880 gtk_text_attributes_copy (GtkTextAttributes *src)
1882 GtkTextAttributes *dest;
1884 dest = gtk_text_attributes_new ();
1885 gtk_text_attributes_copy_values (src, dest);
1891 gtk_text_attributes_get_type (void)
1893 static GType our_type = 0;
1896 our_type = g_boxed_type_register_static (I_("GtkTextAttributes"),
1897 (GBoxedCopyFunc) gtk_text_attributes_ref,
1898 (GBoxedFreeFunc) gtk_text_attributes_unref);
1904 * gtk_text_attributes_copy_values:
1905 * @src: a #GtkTextAttributes
1906 * @dest: another #GtkTextAttributes
1908 * Copies the values from @src to @dest so that @dest has the same values
1909 * as @src. Frees existing values in @dest.
1912 gtk_text_attributes_copy_values (GtkTextAttributes *src,
1913 GtkTextAttributes *dest)
1915 guint orig_refcount;
1917 g_return_if_fail (!dest->realized);
1925 pango_font_description_free (dest->font);
1928 orig_refcount = dest->refcount;
1933 dest->tabs = pango_tab_array_copy (src->tabs);
1935 dest->language = src->language;
1938 dest->font = pango_font_description_copy (src->font);
1940 if (src->pg_bg_color)
1941 dest->pg_bg_color = gdk_color_copy (src->pg_bg_color);
1943 dest->refcount = orig_refcount;
1944 dest->realized = FALSE;
1948 * gtk_text_attributes_ref:
1949 * @values: a #GtkTextAttributes
1951 * Increments the reference count on @values.
1953 * Returns: the #GtkTextAttributes that were passed in
1956 gtk_text_attributes_ref (GtkTextAttributes *values)
1958 g_return_val_if_fail (values != NULL, NULL);
1960 values->refcount += 1;
1966 * gtk_text_attributes_unref:
1967 * @values: a #GtkTextAttributes
1969 * Decrements the reference count on @values, freeing the structure
1970 * if the reference count reaches 0.
1973 gtk_text_attributes_unref (GtkTextAttributes *values)
1975 g_return_if_fail (values != NULL);
1976 g_return_if_fail (values->refcount > 0);
1978 values->refcount -= 1;
1980 if (values->refcount == 0)
1982 g_assert (!values->realized);
1985 pango_tab_array_free (values->tabs);
1988 pango_font_description_free (values->font);
1990 if (values->pg_bg_color)
1991 gdk_color_free (values->pg_bg_color);
1998 _gtk_text_attributes_realize (GtkTextAttributes *values,
2002 g_return_if_fail (values != NULL);
2003 g_return_if_fail (values->refcount > 0);
2004 g_return_if_fail (!values->realized);
2006 /* It is wrong to use this colormap, FIXME */
2007 gdk_colormap_alloc_color (cmap,
2008 &values->appearance.fg_color,
2011 gdk_colormap_alloc_color (cmap,
2012 &values->appearance.bg_color,
2015 if (values->pg_bg_color)
2016 gdk_colormap_alloc_color (cmap,
2017 values->pg_bg_color,
2020 values->realized = TRUE;
2024 _gtk_text_attributes_unrealize (GtkTextAttributes *values,
2028 g_return_if_fail (values != NULL);
2029 g_return_if_fail (values->refcount > 0);
2030 g_return_if_fail (values->realized);
2032 gdk_colormap_free_colors (cmap,
2033 &values->appearance.fg_color, 1);
2036 gdk_colormap_free_colors (cmap,
2037 &values->appearance.bg_color, 1);
2039 values->appearance.fg_color.pixel = 0;
2040 values->appearance.bg_color.pixel = 0;
2042 if (values->pg_bg_color)
2044 gdk_colormap_free_colors (cmap, values->pg_bg_color, 1);
2046 values->pg_bg_color->pixel = 0;
2049 values->realized = FALSE;
2053 _gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest,
2059 guint left_margin_accumulative = 0;
2060 guint right_margin_accumulative = 0;
2062 g_return_if_fail (!dest->realized);
2066 GtkTextTag *tag = tags[n];
2067 GtkTextAttributes *vals = tag->values;
2069 g_assert (tag->table != NULL);
2071 g_assert (tags[n]->priority > tags[n-1]->priority);
2073 if (tag->bg_color_set)
2075 dest->appearance.bg_color = vals->appearance.bg_color;
2077 dest->appearance.draw_bg = TRUE;
2079 if (tag->fg_color_set)
2080 dest->appearance.fg_color = vals->appearance.fg_color;
2082 if (tag->pg_bg_color_set)
2084 dest->pg_bg_color = gdk_color_copy (vals->pg_bg_color);
2090 pango_font_description_merge (dest->font, vals->font, TRUE);
2092 dest->font = pango_font_description_copy (vals->font);
2095 /* multiply all the scales together to get a composite */
2097 dest->font_scale *= vals->font_scale;
2099 if (tag->justification_set)
2100 dest->justification = vals->justification;
2102 if (vals->direction != GTK_TEXT_DIR_NONE)
2103 dest->direction = vals->direction;
2105 if (tag->left_margin_set)
2107 if (tag->accumulative_margin)
2108 left_margin_accumulative += vals->left_margin;
2110 dest->left_margin = vals->left_margin;
2113 if (tag->indent_set)
2114 dest->indent = vals->indent;
2117 dest->appearance.rise = vals->appearance.rise;
2119 if (tag->right_margin_set)
2121 if (tag->accumulative_margin)
2122 right_margin_accumulative += vals->right_margin;
2124 dest->right_margin = vals->right_margin;
2127 if (tag->pixels_above_lines_set)
2128 dest->pixels_above_lines = vals->pixels_above_lines;
2130 if (tag->pixels_below_lines_set)
2131 dest->pixels_below_lines = vals->pixels_below_lines;
2133 if (tag->pixels_inside_wrap_set)
2134 dest->pixels_inside_wrap = vals->pixels_inside_wrap;
2139 pango_tab_array_free (dest->tabs);
2140 dest->tabs = pango_tab_array_copy (vals->tabs);
2143 if (tag->wrap_mode_set)
2144 dest->wrap_mode = vals->wrap_mode;
2146 if (tag->underline_set)
2147 dest->appearance.underline = vals->appearance.underline;
2149 if (tag->strikethrough_set)
2150 dest->appearance.strikethrough = vals->appearance.strikethrough;
2152 if (tag->invisible_set)
2153 dest->invisible = vals->invisible;
2155 if (tag->editable_set)
2156 dest->editable = vals->editable;
2158 if (tag->bg_full_height_set)
2159 dest->bg_full_height = vals->bg_full_height;
2161 if (tag->language_set)
2162 dest->language = vals->language;
2167 dest->left_margin += left_margin_accumulative;
2168 dest->right_margin += right_margin_accumulative;
2172 _gtk_text_tag_affects_size (GtkTextTag *tag)
2174 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
2177 (tag->values->font && pango_font_description_get_set_fields (tag->values->font) != 0) ||
2179 tag->justification_set ||
2180 tag->left_margin_set ||
2183 tag->right_margin_set ||
2184 tag->pixels_above_lines_set ||
2185 tag->pixels_below_lines_set ||
2186 tag->pixels_inside_wrap_set ||
2188 tag->underline_set ||
2189 tag->wrap_mode_set ||
2194 _gtk_text_tag_affects_nonsize_appearance (GtkTextTag *tag)
2196 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
2199 tag->bg_color_set ||
2200 tag->fg_color_set ||
2201 tag->strikethrough_set ||
2202 tag->bg_full_height_set ||
2203 tag->pg_bg_color_set;