1 /* gtktexttag.c - text tag object
3 * Copyright (c) 1992-1994 The Regents of the University of California.
4 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
5 * Copyright (c) 2000 Red Hat, Inc.
6 * Tk -> Gtk port by Havoc Pennington <hp@redhat.com>
8 * This software is copyrighted by the Regents of the University of
9 * California, Sun Microsystems, Inc., and other parties. The
10 * following terms apply to all files associated with the software
11 * unless explicitly disclaimed in individual files.
13 * The authors hereby grant permission to use, copy, modify,
14 * distribute, and license this software and its documentation for any
15 * purpose, provided that existing copyright notices are retained in
16 * all copies and that this notice is included verbatim in any
17 * distributions. No written agreement, license, or royalty fee is
18 * required for any of the authorized uses. Modifications to this
19 * software may be copyrighted by their authors and need not follow
20 * the licensing terms described here, provided that the new terms are
21 * clearly indicated on the first page of each file where they apply.
23 * IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY
24 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
25 * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION,
26 * OR ANY DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED
27 * OF THE POSSIBILITY OF SUCH DAMAGE.
29 * THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
30 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
31 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
32 * NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS,
33 * AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
34 * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
36 * GOVERNMENT USE: If you are acquiring this software on behalf of the
37 * U.S. government, the Government shall have only "Restricted Rights"
38 * in the software and related documentation as defined in the Federal
39 * Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you
40 * are acquiring the software on behalf of the Department of Defense,
41 * the software shall be classified as "Commercial Computer Software"
42 * and the Government shall have only "Restricted Rights" as defined
43 * in Clause 252.227-7013 (c) (1) of DFARs. Notwithstanding the
44 * foregoing, the authors grant the U.S. Government and others acting
45 * in its behalf permission to use and distribute the software in
46 * accordance with the terms specified in this license.
52 #include "gtktexttag.h"
53 #include "gtktexttypes.h"
54 #include "gtktexttagtable.h"
57 #include "gtkmarshalers.h"
77 PROP_BACKGROUND_STIPPLE,
78 PROP_FOREGROUND_STIPPLE,
89 PROP_PIXELS_ABOVE_LINES,
90 PROP_PIXELS_BELOW_LINES,
91 PROP_PIXELS_INSIDE_WRAP,
107 /* Whether-a-style-arg-is-set args */
110 PROP_BACKGROUND_STIPPLE_SET,
111 PROP_FOREGROUND_STIPPLE_SET,
119 PROP_PIXELS_ABOVE_LINES_SET,
120 PROP_PIXELS_BELOW_LINES_SET,
121 PROP_PIXELS_INSIDE_WRAP_SET,
124 PROP_JUSTIFICATION_SET,
125 PROP_LEFT_MARGIN_SET,
127 PROP_STRIKETHROUGH_SET,
128 PROP_RIGHT_MARGIN_SET,
131 PROP_BG_FULL_HEIGHT_SET,
138 static void gtk_text_tag_init (GtkTextTag *text_tag);
139 static void gtk_text_tag_class_init (GtkTextTagClass *klass);
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 GObjectClass *parent_class = NULL;
151 static guint signals[LAST_SIGNAL] = { 0 };
154 gtk_text_tag_get_type (void)
156 static GType our_type = 0;
160 static const GTypeInfo our_info =
162 sizeof (GtkTextTagClass),
163 (GBaseInitFunc) NULL,
164 (GBaseFinalizeFunc) NULL,
165 (GClassInitFunc) gtk_text_tag_class_init,
166 NULL, /* class_finalize */
167 NULL, /* class_data */
170 (GInstanceInitFunc) gtk_text_tag_init
173 our_type = g_type_register_static (G_TYPE_OBJECT, "GtkTextTag",
181 gtk_text_tag_class_init (GtkTextTagClass *klass)
183 GObjectClass *object_class = G_OBJECT_CLASS (klass);
185 parent_class = g_type_class_peek_parent (klass);
187 object_class->set_property = gtk_text_tag_set_property;
188 object_class->get_property = gtk_text_tag_get_property;
190 object_class->finalize = gtk_text_tag_finalize;
193 g_object_class_install_property (object_class,
195 g_param_spec_string ("name",
197 P_("Name used to refer to the text tag. NULL for anonymous tags"),
199 G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
203 g_object_class_install_property (object_class,
205 g_param_spec_string ("background",
206 P_("Background color name"),
207 P_("Background color as a string"),
211 g_object_class_install_property (object_class,
213 g_param_spec_boxed ("background_gdk",
214 P_("Background color"),
215 P_("Background color as a (possibly unallocated) GdkColor"),
217 G_PARAM_READABLE | G_PARAM_WRITABLE));
219 g_object_class_install_property (object_class,
221 g_param_spec_boolean ("background_full_height",
222 P_("Background full height"),
223 P_("Whether the background color fills the entire line height or only the height of the tagged characters"),
225 G_PARAM_READABLE | G_PARAM_WRITABLE));
228 g_object_class_install_property (object_class,
229 PROP_BACKGROUND_STIPPLE,
230 g_param_spec_object ("background_stipple",
231 P_("Background stipple mask"),
232 P_("Bitmap to use as a mask when drawing the text background"),
234 G_PARAM_READABLE | G_PARAM_WRITABLE));
237 g_object_class_install_property (object_class,
239 g_param_spec_string ("foreground",
240 P_("Foreground color name"),
241 P_("Foreground color as a string"),
245 g_object_class_install_property (object_class,
247 g_param_spec_boxed ("foreground_gdk",
248 P_("Foreground color"),
249 P_("Foreground color as a (possibly unallocated) GdkColor"),
251 G_PARAM_READABLE | G_PARAM_WRITABLE));
254 g_object_class_install_property (object_class,
255 PROP_FOREGROUND_STIPPLE,
256 g_param_spec_object ("foreground_stipple",
257 P_("Foreground stipple mask"),
258 P_("Bitmap to use as a mask when drawing the text foreground"),
260 G_PARAM_READABLE | G_PARAM_WRITABLE));
262 g_object_class_install_property (object_class,
264 g_param_spec_enum ("direction",
265 P_("Text direction"),
266 P_("Text direction, e.g. right-to-left or left-to-right"),
267 GTK_TYPE_TEXT_DIRECTION,
269 G_PARAM_READABLE | G_PARAM_WRITABLE));
271 g_object_class_install_property (object_class,
273 g_param_spec_boolean ("editable",
275 P_("Whether the text can be modified by the user"),
277 G_PARAM_READABLE | G_PARAM_WRITABLE));
279 g_object_class_install_property (object_class,
281 g_param_spec_string ("font",
283 P_("Font description as a string, e.g. \"Sans Italic 12\""),
285 G_PARAM_READABLE | G_PARAM_WRITABLE));
287 g_object_class_install_property (object_class,
289 g_param_spec_boxed ("font_desc",
291 P_("Font description as a PangoFontDescription struct"),
292 PANGO_TYPE_FONT_DESCRIPTION,
293 G_PARAM_READABLE | G_PARAM_WRITABLE));
296 g_object_class_install_property (object_class,
298 g_param_spec_string ("family",
300 P_("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
302 G_PARAM_READABLE | G_PARAM_WRITABLE));
304 g_object_class_install_property (object_class,
306 g_param_spec_enum ("style",
308 P_("Font style as a PangoStyle, e.g. PANGO_STYLE_ITALIC"),
311 G_PARAM_READABLE | G_PARAM_WRITABLE));
313 g_object_class_install_property (object_class,
315 g_param_spec_enum ("variant",
317 P_("Font variant as a PangoVariant, e.g. PANGO_VARIANT_SMALL_CAPS"),
319 PANGO_VARIANT_NORMAL,
320 G_PARAM_READABLE | G_PARAM_WRITABLE));
322 g_object_class_install_property (object_class,
324 g_param_spec_int ("weight",
326 P_("Font weight as an integer, see predefined values in PangoWeight; for example, PANGO_WEIGHT_BOLD"),
330 G_PARAM_READABLE | G_PARAM_WRITABLE));
333 g_object_class_install_property (object_class,
335 g_param_spec_enum ("stretch",
337 P_("Font stretch as a PangoStretch, e.g. PANGO_STRETCH_CONDENSED"),
339 PANGO_STRETCH_NORMAL,
340 G_PARAM_READABLE | G_PARAM_WRITABLE));
342 g_object_class_install_property (object_class,
344 g_param_spec_int ("size",
346 P_("Font size in Pango units"),
350 G_PARAM_READABLE | G_PARAM_WRITABLE));
352 g_object_class_install_property (object_class,
354 g_param_spec_double ("scale",
356 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"),
360 G_PARAM_READABLE | G_PARAM_WRITABLE));
362 g_object_class_install_property (object_class,
364 g_param_spec_double ("size_points",
366 P_("Font size in points"),
370 G_PARAM_READABLE | G_PARAM_WRITABLE));
372 g_object_class_install_property (object_class,
374 g_param_spec_enum ("justification",
376 P_("Left, right, or center justification"),
377 GTK_TYPE_JUSTIFICATION,
379 G_PARAM_READABLE | G_PARAM_WRITABLE));
381 g_object_class_install_property (object_class,
383 g_param_spec_string ("language",
385 P_("The language this text is in, as an ISO code. Pango can use this as a hint when rendering the text. If you don't understand this parameter, you probably don't need it"),
387 G_PARAM_READABLE | G_PARAM_WRITABLE));
389 g_object_class_install_property (object_class,
391 g_param_spec_int ("left_margin",
393 P_("Width of the left margin in pixels"),
397 G_PARAM_READABLE | G_PARAM_WRITABLE));
399 g_object_class_install_property (object_class,
401 g_param_spec_int ("right_margin",
403 P_("Width of the right margin in pixels"),
407 G_PARAM_READABLE | G_PARAM_WRITABLE));
410 g_object_class_install_property (object_class,
412 g_param_spec_int ("indent",
414 P_("Amount to indent the paragraph, in pixels"),
418 G_PARAM_READABLE | G_PARAM_WRITABLE));
421 g_object_class_install_property (object_class,
423 g_param_spec_int ("rise",
425 P_("Offset of text above the baseline (below the baseline if rise is negative) in pixels"),
429 G_PARAM_READABLE | G_PARAM_WRITABLE));
431 g_object_class_install_property (object_class,
432 PROP_PIXELS_ABOVE_LINES,
433 g_param_spec_int ("pixels_above_lines",
434 P_("Pixels above lines"),
435 P_("Pixels of blank space above paragraphs"),
439 G_PARAM_READABLE | G_PARAM_WRITABLE));
441 g_object_class_install_property (object_class,
442 PROP_PIXELS_BELOW_LINES,
443 g_param_spec_int ("pixels_below_lines",
444 P_("Pixels below lines"),
445 P_("Pixels of blank space below paragraphs"),
449 G_PARAM_READABLE | G_PARAM_WRITABLE));
451 g_object_class_install_property (object_class,
452 PROP_PIXELS_INSIDE_WRAP,
453 g_param_spec_int ("pixels_inside_wrap",
454 P_("Pixels inside wrap"),
455 P_("Pixels of blank space between wrapped lines in a paragraph"),
459 G_PARAM_READABLE | G_PARAM_WRITABLE));
461 g_object_class_install_property (object_class,
463 g_param_spec_boolean ("strikethrough",
465 P_("Whether to strike through the text"),
467 G_PARAM_READABLE | G_PARAM_WRITABLE));
469 g_object_class_install_property (object_class,
471 g_param_spec_enum ("underline",
473 P_("Style of underline for this text"),
474 PANGO_TYPE_UNDERLINE,
475 PANGO_UNDERLINE_NONE,
476 G_PARAM_READABLE | G_PARAM_WRITABLE));
478 g_object_class_install_property (object_class,
480 g_param_spec_enum ("wrap_mode",
482 P_("Whether to wrap lines never, at word boundaries, or at character boundaries"),
485 G_PARAM_READABLE | G_PARAM_WRITABLE));
488 g_object_class_install_property (object_class,
490 g_param_spec_boxed ("tabs",
492 P_("Custom tabs for this text"),
493 PANGO_TYPE_TAB_ARRAY,
494 G_PARAM_READABLE | G_PARAM_WRITABLE));
496 g_object_class_install_property (object_class,
498 g_param_spec_boolean ("invisible",
500 P_("Whether this text is hidden. Not implemented in GTK 2.0"),
502 G_PARAM_READABLE | G_PARAM_WRITABLE));
504 /* Style props are set or not */
506 #define ADD_SET_PROP(propname, propval, nick, blurb) g_object_class_install_property (object_class, propval, g_param_spec_boolean (propname, nick, blurb, FALSE, G_PARAM_READABLE | G_PARAM_WRITABLE))
508 ADD_SET_PROP ("background_set", PROP_BACKGROUND_SET,
509 P_("Background set"),
510 P_("Whether this tag affects the background color"));
512 ADD_SET_PROP ("background_full_height_set", PROP_BG_FULL_HEIGHT_SET,
513 P_("Background full height set"),
514 P_("Whether this tag affects background height"));
516 ADD_SET_PROP ("background_stipple_set", PROP_BACKGROUND_STIPPLE_SET,
517 P_("Background stipple set"),
518 P_("Whether this tag affects the background stipple"));
520 ADD_SET_PROP ("foreground_set", PROP_FOREGROUND_SET,
521 P_("Foreground set"),
522 P_("Whether this tag affects the foreground color"));
524 ADD_SET_PROP ("foreground_stipple_set", PROP_FOREGROUND_STIPPLE_SET,
525 P_("Foreground stipple set"),
526 P_("Whether this tag affects the foreground stipple"));
528 ADD_SET_PROP ("editable_set", PROP_EDITABLE_SET,
529 P_("Editability set"),
530 P_("Whether this tag affects text editability"));
532 ADD_SET_PROP ("family_set", PROP_FAMILY_SET,
533 P_("Font family set"),
534 P_("Whether this tag affects the font family"));
536 ADD_SET_PROP ("style_set", PROP_STYLE_SET,
537 P_("Font style set"),
538 P_("Whether this tag affects the font style"));
540 ADD_SET_PROP ("variant_set", PROP_VARIANT_SET,
541 P_("Font variant set"),
542 P_("Whether this tag affects the font variant"));
544 ADD_SET_PROP ("weight_set", PROP_WEIGHT_SET,
545 P_("Font weight set"),
546 P_("Whether this tag affects the font weight"));
548 ADD_SET_PROP ("stretch_set", PROP_STRETCH_SET,
549 P_("Font stretch set"),
550 P_("Whether this tag affects the font stretch"));
552 ADD_SET_PROP ("size_set", PROP_SIZE_SET,
554 P_("Whether this tag affects the font size"));
556 ADD_SET_PROP ("scale_set", PROP_SCALE_SET,
557 P_("Font scale set"),
558 P_("Whether this tag scales the font size by a factor"));
560 ADD_SET_PROP ("justification_set", PROP_JUSTIFICATION_SET,
561 P_("Justification set"),
562 P_("Whether this tag affects paragraph justification"));
564 ADD_SET_PROP ("language_set", PROP_LANGUAGE_SET,
566 P_("Whether this tag affects the language the text is rendered as"));
568 ADD_SET_PROP ("left_margin_set", PROP_LEFT_MARGIN_SET,
569 P_("Left margin set"),
570 P_("Whether this tag affects the left margin"));
572 ADD_SET_PROP ("indent_set", PROP_INDENT_SET,
574 P_("Whether this tag affects indentation"));
576 ADD_SET_PROP ("rise_set", PROP_RISE_SET,
578 P_("Whether this tag affects the rise"));
580 ADD_SET_PROP ("pixels_above_lines_set", PROP_PIXELS_ABOVE_LINES_SET,
581 P_("Pixels above lines set"),
582 P_("Whether this tag affects the number of pixels above lines"));
584 ADD_SET_PROP ("pixels_below_lines_set", PROP_PIXELS_BELOW_LINES_SET,
585 P_("Pixels below lines set"),
586 P_("Whether this tag affects the number of pixels above lines"));
588 ADD_SET_PROP ("pixels_inside_wrap_set", PROP_PIXELS_INSIDE_WRAP_SET,
589 P_("Pixels inside wrap set"),
590 P_("Whether this tag affects the number of pixels between wrapped lines"));
592 ADD_SET_PROP ("strikethrough_set", PROP_STRIKETHROUGH_SET,
593 P_("Strikethrough set"),
594 P_("Whether this tag affects strikethrough"));
596 ADD_SET_PROP ("right_margin_set", PROP_RIGHT_MARGIN_SET,
597 P_("Right margin set"),
598 P_("Whether this tag affects the right margin"));
600 ADD_SET_PROP ("underline_set", PROP_UNDERLINE_SET,
602 P_("Whether this tag affects underlining"));
604 ADD_SET_PROP ("wrap_mode_set", PROP_WRAP_MODE_SET,
606 P_("Whether this tag affects line wrap mode"));
608 ADD_SET_PROP ("tabs_set", PROP_TABS_SET,
610 P_("Whether this tag affects tabs"));
612 ADD_SET_PROP ("invisible_set", PROP_INVISIBLE_SET,
614 P_("Whether this tag affects text visibility"));
617 g_signal_new ("event",
618 G_OBJECT_CLASS_TYPE (object_class),
620 G_STRUCT_OFFSET (GtkTextTagClass, event),
621 _gtk_boolean_handled_accumulator, NULL,
622 _gtk_marshal_BOOLEAN__OBJECT_BOXED_BOXED,
626 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE,
631 gtk_text_tag_init (GtkTextTag *text_tag)
633 /* 0 is basically a fine way to initialize everything in the
636 text_tag->values = gtk_text_attributes_new ();
641 * @name: tag name, or %NULL
643 * Creates a #GtkTextTag. Configure the tag using object arguments,
644 * i.e. using g_object_set().
646 * Return value: a new #GtkTextTag
649 gtk_text_tag_new (const gchar *name)
653 tag = g_object_new (GTK_TYPE_TEXT_TAG, "name", name, NULL);
659 gtk_text_tag_finalize (GObject *object)
661 GtkTextTag *text_tag;
663 text_tag = GTK_TEXT_TAG (object);
665 g_assert (!text_tag->values->realized);
668 gtk_text_tag_table_remove (text_tag->table, text_tag);
670 g_assert (text_tag->table == NULL);
672 gtk_text_attributes_unref (text_tag->values);
673 text_tag->values = NULL;
675 g_free (text_tag->name);
676 text_tag->name = NULL;
678 (* G_OBJECT_CLASS (parent_class)->finalize) (object);
682 set_bg_color (GtkTextTag *tag, GdkColor *color)
686 if (!tag->bg_color_set)
688 tag->bg_color_set = TRUE;
689 g_object_notify (G_OBJECT (tag), "background_set");
692 tag->values->appearance.bg_color = *color;
696 if (tag->bg_color_set)
698 tag->bg_color_set = FALSE;
699 g_object_notify (G_OBJECT (tag), "background_set");
705 set_fg_color (GtkTextTag *tag, GdkColor *color)
709 if (!tag->fg_color_set)
711 tag->fg_color_set = TRUE;
712 g_object_notify (G_OBJECT (tag), "foreground_set");
714 tag->values->appearance.fg_color = *color;
718 if (tag->fg_color_set)
720 tag->fg_color_set = FALSE;
721 g_object_notify (G_OBJECT (tag), "foreground_set");
727 get_property_font_set_mask (guint prop_id)
731 case PROP_FAMILY_SET:
732 return PANGO_FONT_MASK_FAMILY;
734 return PANGO_FONT_MASK_STYLE;
735 case PROP_VARIANT_SET:
736 return PANGO_FONT_MASK_VARIANT;
737 case PROP_WEIGHT_SET:
738 return PANGO_FONT_MASK_WEIGHT;
739 case PROP_STRETCH_SET:
740 return PANGO_FONT_MASK_STRETCH;
742 return PANGO_FONT_MASK_SIZE;
749 set_font_desc_fields (PangoFontDescription *desc,
750 PangoFontMask to_set)
752 PangoFontMask changed_mask = 0;
754 if (to_set & PANGO_FONT_MASK_FAMILY)
756 const char *family = pango_font_description_get_family (desc);
760 changed_mask |= PANGO_FONT_MASK_FAMILY;
763 pango_font_description_set_family (desc, family);
765 if (to_set & PANGO_FONT_MASK_STYLE)
766 pango_font_description_set_style (desc, pango_font_description_get_style (desc));
767 if (to_set & PANGO_FONT_MASK_VARIANT)
768 pango_font_description_set_variant (desc, pango_font_description_get_variant (desc));
769 if (to_set & PANGO_FONT_MASK_WEIGHT)
770 pango_font_description_set_weight (desc, pango_font_description_get_weight (desc));
771 if (to_set & PANGO_FONT_MASK_STRETCH)
772 pango_font_description_set_stretch (desc, pango_font_description_get_stretch (desc));
773 if (to_set & PANGO_FONT_MASK_SIZE)
775 gint size = pango_font_description_get_size (desc);
778 size = 10 * PANGO_SCALE;
779 changed_mask |= PANGO_FONT_MASK_SIZE;
782 pango_font_description_set_size (desc, size);
789 notify_set_changed (GObject *object,
790 PangoFontMask changed_mask)
792 if (changed_mask & PANGO_FONT_MASK_FAMILY)
793 g_object_notify (object, "family_set");
794 if (changed_mask & PANGO_FONT_MASK_STYLE)
795 g_object_notify (object, "style_set");
796 if (changed_mask & PANGO_FONT_MASK_VARIANT)
797 g_object_notify (object, "variant_set");
798 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
799 g_object_notify (object, "weight_set");
800 if (changed_mask & PANGO_FONT_MASK_STRETCH)
801 g_object_notify (object, "stretch_set");
802 if (changed_mask & PANGO_FONT_MASK_SIZE)
803 g_object_notify (object, "size_set");
807 notify_fields_changed (GObject *object,
808 PangoFontMask changed_mask)
810 if (changed_mask & PANGO_FONT_MASK_FAMILY)
811 g_object_notify (object, "family");
812 if (changed_mask & PANGO_FONT_MASK_STYLE)
813 g_object_notify (object, "style");
814 if (changed_mask & PANGO_FONT_MASK_VARIANT)
815 g_object_notify (object, "variant");
816 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
817 g_object_notify (object, "weight");
818 if (changed_mask & PANGO_FONT_MASK_STRETCH)
819 g_object_notify (object, "stretch");
820 if (changed_mask & PANGO_FONT_MASK_SIZE)
821 g_object_notify (object, "size");
825 set_font_description (GtkTextTag *text_tag,
826 PangoFontDescription *font_desc)
828 GObject *object = G_OBJECT (text_tag);
829 PangoFontDescription *new_font_desc;
830 PangoFontMask old_mask, new_mask, changed_mask, set_changed_mask;
833 new_font_desc = pango_font_description_copy (font_desc);
835 new_font_desc = pango_font_description_new ();
837 if (text_tag->values->font)
838 old_mask = pango_font_description_get_set_fields (text_tag->values->font);
842 new_mask = pango_font_description_get_set_fields (new_font_desc);
844 changed_mask = old_mask | new_mask;
845 set_changed_mask = old_mask ^ new_mask;
847 if (text_tag->values->font)
848 pango_font_description_free (text_tag->values->font);
849 text_tag->values->font = new_font_desc;
851 g_object_freeze_notify (object);
853 g_object_notify (object, "font_desc");
854 g_object_notify (object, "font");
856 if (changed_mask & PANGO_FONT_MASK_FAMILY)
857 g_object_notify (object, "family");
858 if (changed_mask & PANGO_FONT_MASK_STYLE)
859 g_object_notify (object, "style");
860 if (changed_mask & PANGO_FONT_MASK_VARIANT)
861 g_object_notify (object, "variant");
862 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
863 g_object_notify (object, "weight");
864 if (changed_mask & PANGO_FONT_MASK_STRETCH)
865 g_object_notify (object, "stretch");
866 if (changed_mask & PANGO_FONT_MASK_SIZE)
868 g_object_notify (object, "size");
869 g_object_notify (object, "size_points");
872 notify_set_changed (object, set_changed_mask);
874 g_object_thaw_notify (object);
878 gtk_text_tag_ensure_font (GtkTextTag *text_tag)
880 if (!text_tag->values->font)
881 text_tag->values->font = pango_font_description_new ();
885 gtk_text_tag_set_property (GObject *object,
890 GtkTextTag *text_tag;
891 gboolean size_changed = FALSE;
893 text_tag = GTK_TEXT_TAG (object);
895 g_return_if_fail (!text_tag->values->realized);
900 g_return_if_fail (text_tag->name == NULL);
901 text_tag->name = g_strdup (g_value_get_string (value));
904 case PROP_BACKGROUND:
908 if (gdk_color_parse (g_value_get_string (value), &color))
909 set_bg_color (text_tag, &color);
911 g_warning ("Don't know color `%s'", g_value_get_string (value));
913 g_object_notify (object, "background_gdk");
917 case PROP_FOREGROUND:
921 if (gdk_color_parse (g_value_get_string (value), &color))
922 set_fg_color (text_tag, &color);
924 g_warning ("Don't know color `%s'", g_value_get_string (value));
926 g_object_notify (object, "foreground_gdk");
930 case PROP_BACKGROUND_GDK:
932 GdkColor *color = g_value_get_boxed (value);
934 set_bg_color (text_tag, color);
938 case PROP_FOREGROUND_GDK:
940 GdkColor *color = g_value_get_boxed (value);
942 set_fg_color (text_tag, color);
946 case PROP_BACKGROUND_STIPPLE:
948 GdkBitmap *bitmap = g_value_get_object (value);
950 text_tag->bg_stipple_set = TRUE;
951 g_object_notify (object, "background_stipple_set");
953 if (text_tag->values->appearance.bg_stipple != bitmap)
956 g_object_ref (bitmap);
958 if (text_tag->values->appearance.bg_stipple)
959 g_object_unref (text_tag->values->appearance.bg_stipple);
961 text_tag->values->appearance.bg_stipple = bitmap;
966 case PROP_FOREGROUND_STIPPLE:
968 GdkBitmap *bitmap = g_value_get_object (value);
970 text_tag->fg_stipple_set = TRUE;
971 g_object_notify (object, "foreground_stipple_set");
973 if (text_tag->values->appearance.fg_stipple != bitmap)
976 g_object_ref (bitmap);
978 if (text_tag->values->appearance.fg_stipple)
979 g_object_unref (text_tag->values->appearance.fg_stipple);
981 text_tag->values->appearance.fg_stipple = bitmap;
988 PangoFontDescription *font_desc = NULL;
991 name = g_value_get_string (value);
994 font_desc = pango_font_description_from_string (name);
996 set_font_description (text_tag, font_desc);
998 pango_font_description_free (font_desc);
1000 size_changed = TRUE;
1004 case PROP_FONT_DESC:
1006 PangoFontDescription *font_desc;
1008 font_desc = g_value_get_boxed (value);
1010 set_font_description (text_tag, font_desc);
1012 size_changed = TRUE;
1022 case PROP_SIZE_POINTS:
1024 PangoFontMask old_set_mask;
1026 gtk_text_tag_ensure_font (text_tag);
1027 old_set_mask = pango_font_description_get_set_fields (text_tag->values->font);
1032 pango_font_description_set_family (text_tag->values->font,
1033 g_value_get_string (value));
1036 pango_font_description_set_style (text_tag->values->font,
1037 g_value_get_enum (value));
1040 pango_font_description_set_variant (text_tag->values->font,
1041 g_value_get_enum (value));
1044 pango_font_description_set_weight (text_tag->values->font,
1045 g_value_get_int (value));
1048 pango_font_description_set_stretch (text_tag->values->font,
1049 g_value_get_enum (value));
1052 pango_font_description_set_size (text_tag->values->font,
1053 g_value_get_int (value));
1054 g_object_notify (object, "size_points");
1056 case PROP_SIZE_POINTS:
1057 pango_font_description_set_size (text_tag->values->font,
1058 g_value_get_double (value) * PANGO_SCALE);
1059 g_object_notify (object, "size");
1063 size_changed = TRUE;
1064 notify_set_changed (object, old_set_mask & pango_font_description_get_set_fields (text_tag->values->font));
1065 g_object_notify (object, "font_desc");
1066 g_object_notify (object, "font");
1072 text_tag->values->font_scale = g_value_get_double (value);
1073 text_tag->scale_set = TRUE;
1074 g_object_notify (object, "scale_set");
1075 size_changed = TRUE;
1078 case PROP_PIXELS_ABOVE_LINES:
1079 text_tag->pixels_above_lines_set = TRUE;
1080 text_tag->values->pixels_above_lines = g_value_get_int (value);
1081 g_object_notify (object, "pixels_above_lines_set");
1082 size_changed = TRUE;
1085 case PROP_PIXELS_BELOW_LINES:
1086 text_tag->pixels_below_lines_set = TRUE;
1087 text_tag->values->pixels_below_lines = g_value_get_int (value);
1088 g_object_notify (object, "pixels_below_lines_set");
1089 size_changed = TRUE;
1092 case PROP_PIXELS_INSIDE_WRAP:
1093 text_tag->pixels_inside_wrap_set = TRUE;
1094 text_tag->values->pixels_inside_wrap = g_value_get_int (value);
1095 g_object_notify (object, "pixels_inside_wrap_set");
1096 size_changed = TRUE;
1100 text_tag->editable_set = TRUE;
1101 text_tag->values->editable = g_value_get_boolean (value);
1102 g_object_notify (object, "editable_set");
1105 case PROP_WRAP_MODE:
1106 text_tag->wrap_mode_set = TRUE;
1107 text_tag->values->wrap_mode = g_value_get_enum (value);
1108 g_object_notify (object, "wrap_mode_set");
1109 size_changed = TRUE;
1112 case PROP_JUSTIFICATION:
1113 text_tag->justification_set = TRUE;
1114 text_tag->values->justification = g_value_get_enum (value);
1115 g_object_notify (object, "justification_set");
1116 size_changed = TRUE;
1119 case PROP_DIRECTION:
1120 text_tag->values->direction = g_value_get_enum (value);
1123 case PROP_LEFT_MARGIN:
1124 text_tag->left_margin_set = TRUE;
1125 text_tag->values->left_margin = g_value_get_int (value);
1126 g_object_notify (object, "left_margin_set");
1127 size_changed = TRUE;
1131 text_tag->indent_set = TRUE;
1132 text_tag->values->indent = g_value_get_int (value);
1133 g_object_notify (object, "indent_set");
1134 size_changed = TRUE;
1137 case PROP_STRIKETHROUGH:
1138 text_tag->strikethrough_set = TRUE;
1139 text_tag->values->appearance.strikethrough = g_value_get_boolean (value);
1140 g_object_notify (object, "strikethrough_set");
1143 case PROP_RIGHT_MARGIN:
1144 text_tag->right_margin_set = TRUE;
1145 text_tag->values->right_margin = g_value_get_int (value);
1146 g_object_notify (object, "right_margin_set");
1147 size_changed = TRUE;
1150 case PROP_UNDERLINE:
1151 text_tag->underline_set = TRUE;
1152 text_tag->values->appearance.underline = g_value_get_enum (value);
1153 g_object_notify (object, "underline_set");
1157 text_tag->rise_set = TRUE;
1158 text_tag->values->appearance.rise = g_value_get_int (value);
1159 g_object_notify (object, "rise_set");
1160 size_changed = TRUE;
1163 case PROP_BG_FULL_HEIGHT:
1164 text_tag->bg_full_height_set = TRUE;
1165 text_tag->values->bg_full_height = g_value_get_boolean (value);
1166 g_object_notify (object, "background_full_height_set");
1170 text_tag->language_set = TRUE;
1171 text_tag->values->language = pango_language_from_string (g_value_get_string (value));
1172 g_object_notify (object, "language_set");
1176 text_tag->tabs_set = TRUE;
1178 if (text_tag->values->tabs)
1179 pango_tab_array_free (text_tag->values->tabs);
1181 /* FIXME I'm not sure if this is a memleak or not */
1182 text_tag->values->tabs =
1183 pango_tab_array_copy (g_value_get_boxed (value));
1185 g_object_notify (object, "tabs_set");
1187 size_changed = TRUE;
1190 case PROP_INVISIBLE:
1191 g_warning ("The \"invisible\" property on GtkTextTag is not supported for GTK 2.0, it will be added in a future release. see http://bugzilla.gnome.org bug #66194 for status.");
1192 text_tag->invisible_set = TRUE;
1193 text_tag->values->invisible = g_value_get_boolean (value);
1194 g_object_notify (object, "invisible_set");
1195 size_changed = TRUE;
1198 /* Whether the value should be used... */
1200 case PROP_BACKGROUND_SET:
1201 text_tag->bg_color_set = g_value_get_boolean (value);
1204 case PROP_FOREGROUND_SET:
1205 text_tag->fg_color_set = g_value_get_boolean (value);
1208 case PROP_BACKGROUND_STIPPLE_SET:
1209 text_tag->bg_stipple_set = g_value_get_boolean (value);
1210 if (!text_tag->bg_stipple_set &&
1211 text_tag->values->appearance.bg_stipple)
1213 g_object_unref (text_tag->values->appearance.bg_stipple);
1214 text_tag->values->appearance.bg_stipple = NULL;
1218 case PROP_FOREGROUND_STIPPLE_SET:
1219 text_tag->fg_stipple_set = g_value_get_boolean (value);
1220 if (!text_tag->fg_stipple_set &&
1221 text_tag->values->appearance.fg_stipple)
1223 g_object_unref (text_tag->values->appearance.fg_stipple);
1224 text_tag->values->appearance.fg_stipple = NULL;
1228 case PROP_FAMILY_SET:
1229 case PROP_STYLE_SET:
1230 case PROP_VARIANT_SET:
1231 case PROP_WEIGHT_SET:
1232 case PROP_STRETCH_SET:
1234 if (!g_value_get_boolean (value))
1236 if (text_tag->values->font)
1237 pango_font_description_unset_fields (text_tag->values->font,
1238 get_property_font_set_mask (prop_id));
1242 PangoFontMask changed_mask;
1244 gtk_text_tag_ensure_font (text_tag);
1245 changed_mask = set_font_desc_fields (text_tag->values->font,
1246 get_property_font_set_mask (prop_id));
1247 notify_fields_changed (G_OBJECT (text_tag), changed_mask);
1251 case PROP_SCALE_SET:
1252 text_tag->scale_set = g_value_get_boolean (value);
1253 size_changed = TRUE;
1256 case PROP_PIXELS_ABOVE_LINES_SET:
1257 text_tag->pixels_above_lines_set = g_value_get_boolean (value);
1258 size_changed = TRUE;
1261 case PROP_PIXELS_BELOW_LINES_SET:
1262 text_tag->pixels_below_lines_set = g_value_get_boolean (value);
1263 size_changed = TRUE;
1266 case PROP_PIXELS_INSIDE_WRAP_SET:
1267 text_tag->pixels_inside_wrap_set = g_value_get_boolean (value);
1268 size_changed = TRUE;
1271 case PROP_EDITABLE_SET:
1272 text_tag->editable_set = g_value_get_boolean (value);
1275 case PROP_WRAP_MODE_SET:
1276 text_tag->wrap_mode_set = g_value_get_boolean (value);
1277 size_changed = TRUE;
1280 case PROP_JUSTIFICATION_SET:
1281 text_tag->justification_set = g_value_get_boolean (value);
1282 size_changed = TRUE;
1285 case PROP_LEFT_MARGIN_SET:
1286 text_tag->left_margin_set = g_value_get_boolean (value);
1287 size_changed = TRUE;
1290 case PROP_INDENT_SET:
1291 text_tag->indent_set = g_value_get_boolean (value);
1292 size_changed = TRUE;
1295 case PROP_STRIKETHROUGH_SET:
1296 text_tag->strikethrough_set = g_value_get_boolean (value);
1299 case PROP_RIGHT_MARGIN_SET:
1300 text_tag->right_margin_set = g_value_get_boolean (value);
1301 size_changed = TRUE;
1304 case PROP_UNDERLINE_SET:
1305 text_tag->underline_set = g_value_get_boolean (value);
1309 text_tag->rise_set = g_value_get_boolean (value);
1310 size_changed = TRUE;
1313 case PROP_BG_FULL_HEIGHT_SET:
1314 text_tag->bg_full_height_set = g_value_get_boolean (value);
1317 case PROP_LANGUAGE_SET:
1318 text_tag->language_set = g_value_get_boolean (value);
1319 size_changed = TRUE;
1323 text_tag->tabs_set = g_value_get_boolean (value);
1324 size_changed = TRUE;
1327 case PROP_INVISIBLE_SET:
1328 text_tag->invisible_set = g_value_get_boolean (value);
1329 size_changed = TRUE;
1333 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1337 /* FIXME I would like to do this after all set_property in a single
1338 * g_object_set () have been called. But an idle function won't
1339 * work; we need to emit when the tag is changed, not when we get
1340 * around to the event loop. So blah, we eat some inefficiency.
1343 /* This is also somewhat weird since we emit another object's
1344 * signal here, but the two objects are already tightly bound.
1347 if (text_tag->table)
1348 g_signal_emit_by_name (text_tag->table,
1350 text_tag, size_changed);
1354 gtk_text_tag_get_property (GObject *object,
1361 tag = GTK_TEXT_TAG (object);
1366 g_value_set_string (value, tag->name);
1369 case PROP_BACKGROUND_GDK:
1370 g_value_set_boxed (value, &tag->values->appearance.bg_color);
1373 case PROP_FOREGROUND_GDK:
1374 g_value_set_boxed (value, &tag->values->appearance.fg_color);
1377 case PROP_BACKGROUND_STIPPLE:
1378 if (tag->bg_stipple_set)
1379 g_value_set_boxed (value, tag->values->appearance.bg_stipple);
1382 case PROP_FOREGROUND_STIPPLE:
1383 if (tag->fg_stipple_set)
1384 g_value_set_boxed (value, tag->values->appearance.fg_stipple);
1389 /* FIXME GValue imposes a totally gratuitous string copy
1390 * here, we could just hand off string ownership
1394 gtk_text_tag_ensure_font (tag);
1396 str = pango_font_description_to_string (tag->values->font);
1397 g_value_set_string (value, str);
1402 case PROP_FONT_DESC:
1403 gtk_text_tag_ensure_font (tag);
1404 g_value_set_boxed (value, tag->values->font);
1413 case PROP_SIZE_POINTS:
1414 gtk_text_tag_ensure_font (tag);
1418 g_value_set_string (value, pango_font_description_get_family (tag->values->font));
1422 g_value_set_enum (value, pango_font_description_get_style (tag->values->font));
1426 g_value_set_enum (value, pango_font_description_get_variant (tag->values->font));
1430 g_value_set_int (value, pango_font_description_get_weight (tag->values->font));
1434 g_value_set_enum (value, pango_font_description_get_stretch (tag->values->font));
1438 g_value_set_int (value, pango_font_description_get_size (tag->values->font));
1441 case PROP_SIZE_POINTS:
1442 g_value_set_double (value, ((double)pango_font_description_get_size (tag->values->font)) / (double)PANGO_SCALE);
1448 g_value_set_double (value, tag->values->font_scale);
1451 case PROP_PIXELS_ABOVE_LINES:
1452 g_value_set_int (value, tag->values->pixels_above_lines);
1455 case PROP_PIXELS_BELOW_LINES:
1456 g_value_set_int (value, tag->values->pixels_below_lines);
1459 case PROP_PIXELS_INSIDE_WRAP:
1460 g_value_set_int (value, tag->values->pixels_inside_wrap);
1464 g_value_set_boolean (value, tag->values->editable);
1467 case PROP_WRAP_MODE:
1468 g_value_set_enum (value, tag->values->wrap_mode);
1471 case PROP_JUSTIFICATION:
1472 g_value_set_enum (value, tag->values->justification);
1475 case PROP_DIRECTION:
1476 g_value_set_enum (value, tag->values->direction);
1479 case PROP_LEFT_MARGIN:
1480 g_value_set_int (value, tag->values->left_margin);
1484 g_value_set_int (value, tag->values->indent);
1487 case PROP_STRIKETHROUGH:
1488 g_value_set_boolean (value, tag->values->appearance.strikethrough);
1491 case PROP_RIGHT_MARGIN:
1492 g_value_set_int (value, tag->values->right_margin);
1495 case PROP_UNDERLINE:
1496 g_value_set_enum (value, tag->values->appearance.underline);
1500 g_value_set_int (value, tag->values->appearance.rise);
1503 case PROP_BG_FULL_HEIGHT:
1504 g_value_set_boolean (value, tag->values->bg_full_height);
1508 g_value_set_string (value, pango_language_to_string (tag->values->language));
1512 if (tag->values->tabs)
1513 g_value_set_boxed (value, tag->values->tabs);
1516 case PROP_INVISIBLE:
1517 g_value_set_boolean (value, tag->values->invisible);
1520 case PROP_BACKGROUND_SET:
1521 g_value_set_boolean (value, tag->bg_color_set);
1524 case PROP_FOREGROUND_SET:
1525 g_value_set_boolean (value, tag->fg_color_set);
1528 case PROP_BACKGROUND_STIPPLE_SET:
1529 g_value_set_boolean (value, tag->bg_stipple_set);
1532 case PROP_FOREGROUND_STIPPLE_SET:
1533 g_value_set_boolean (value, tag->fg_stipple_set);
1536 case PROP_FAMILY_SET:
1537 case PROP_STYLE_SET:
1538 case PROP_VARIANT_SET:
1539 case PROP_WEIGHT_SET:
1540 case PROP_STRETCH_SET:
1543 PangoFontMask set_mask = tag->values->font ? pango_font_description_get_set_fields (tag->values->font) : 0;
1544 PangoFontMask test_mask = get_property_font_set_mask (prop_id);
1545 g_value_set_boolean (value, (set_mask & test_mask) != 0);
1550 case PROP_SCALE_SET:
1551 g_value_set_boolean (value, tag->scale_set);
1554 case PROP_PIXELS_ABOVE_LINES_SET:
1555 g_value_set_boolean (value, tag->pixels_above_lines_set);
1558 case PROP_PIXELS_BELOW_LINES_SET:
1559 g_value_set_boolean (value, tag->pixels_below_lines_set);
1562 case PROP_PIXELS_INSIDE_WRAP_SET:
1563 g_value_set_boolean (value, tag->pixels_inside_wrap_set);
1566 case PROP_EDITABLE_SET:
1567 g_value_set_boolean (value, tag->editable_set);
1570 case PROP_WRAP_MODE_SET:
1571 g_value_set_boolean (value, tag->wrap_mode_set);
1574 case PROP_JUSTIFICATION_SET:
1575 g_value_set_boolean (value, tag->justification_set);
1578 case PROP_LEFT_MARGIN_SET:
1579 g_value_set_boolean (value, tag->left_margin_set);
1582 case PROP_INDENT_SET:
1583 g_value_set_boolean (value, tag->indent_set);
1586 case PROP_STRIKETHROUGH_SET:
1587 g_value_set_boolean (value, tag->strikethrough_set);
1590 case PROP_RIGHT_MARGIN_SET:
1591 g_value_set_boolean (value, tag->right_margin_set);
1594 case PROP_UNDERLINE_SET:
1595 g_value_set_boolean (value, tag->underline_set);
1599 g_value_set_boolean (value, tag->rise_set);
1602 case PROP_BG_FULL_HEIGHT_SET:
1603 g_value_set_boolean (value, tag->bg_full_height_set);
1606 case PROP_LANGUAGE_SET:
1607 g_value_set_boolean (value, tag->language_set);
1611 g_value_set_boolean (value, tag->tabs_set);
1614 case PROP_INVISIBLE_SET:
1615 g_value_set_boolean (value, tag->invisible_set);
1618 case PROP_BACKGROUND:
1619 case PROP_FOREGROUND:
1620 g_warning ("'foreground' and 'background' properties are not readable, use 'foreground_gdk' and 'background_gdk'");
1622 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1638 delta_priority_foreach (GtkTextTag *tag, gpointer user_data)
1640 DeltaData *dd = user_data;
1642 if (tag->priority >= dd->low && tag->priority <= dd->high)
1643 tag->priority += dd->delta;
1647 * gtk_text_tag_get_priority:
1648 * @tag: a #GtkTextTag
1650 * Get the tag priority.
1652 * Return value: The tag's priority.
1655 gtk_text_tag_get_priority (GtkTextTag *tag)
1657 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), 0);
1659 return tag->priority;
1663 * gtk_text_tag_set_priority:
1664 * @tag: a #GtkTextTag
1665 * @priority: the new priority
1667 * Sets the priority of a #GtkTextTag. Valid priorities are
1668 * start at 0 and go to one less than gtk_text_tag_table_get_size().
1669 * Each tag in a table has a unique priority; setting the priority
1670 * of one tag shifts the priorities of all the other tags in the
1671 * table to maintain a unique priority for each tag. Higher priority
1672 * tags "win" if two tags both set the same text attribute. When adding
1673 * a tag to a tag table, it will be assigned the highest priority in
1674 * the table by default; so normally the precedence of a set of tags
1675 * is the order in which they were added to the table, or created with
1676 * gtk_text_buffer_create_tag(), which adds the tag to the buffer's table
1680 gtk_text_tag_set_priority (GtkTextTag *tag,
1685 g_return_if_fail (GTK_IS_TEXT_TAG (tag));
1686 g_return_if_fail (tag->table != NULL);
1687 g_return_if_fail (priority >= 0);
1688 g_return_if_fail (priority < gtk_text_tag_table_get_size (tag->table));
1690 if (priority == tag->priority)
1693 if (priority < tag->priority)
1696 dd.high = tag->priority - 1;
1701 dd.low = tag->priority + 1;
1706 gtk_text_tag_table_foreach (tag->table,
1707 delta_priority_foreach,
1710 tag->priority = priority;
1714 * gtk_text_tag_event:
1715 * @tag: a #GtkTextTag
1716 * @event_object: object that received the event, such as a widget
1718 * @iter: location where the event was received
1720 * Emits the "event" signal on the #GtkTextTag.
1722 * Return value: result of signal emission (whether the event was handled)
1725 gtk_text_tag_event (GtkTextTag *tag,
1726 GObject *event_object,
1728 const GtkTextIter *iter)
1730 gboolean retval = FALSE;
1732 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
1733 g_return_val_if_fail (G_IS_OBJECT (event_object), FALSE);
1734 g_return_val_if_fail (event != NULL, FALSE);
1748 tag_sort_func (gconstpointer first, gconstpointer second)
1750 GtkTextTag *tag1, *tag2;
1752 tag1 = * (GtkTextTag **) first;
1753 tag2 = * (GtkTextTag **) second;
1754 return tag1->priority - tag2->priority;
1758 _gtk_text_tag_array_sort (GtkTextTag** tag_array_p,
1763 GtkTextTag **maxPtrPtr, *tmp;
1765 g_return_if_fail (tag_array_p != NULL);
1766 g_return_if_fail (len > 0);
1772 GtkTextTag **iter = tag_array_p;
1774 for (i = len-1; i > 0; i--, iter++) {
1775 maxPtrPtr = tag = iter;
1776 prio = tag[0]->priority;
1777 for (j = i, tag++; j > 0; j--, tag++) {
1778 if (tag[0]->priority < prio) {
1779 prio = tag[0]->priority;
1788 qsort ((void *) tag_array_p, (unsigned) len, sizeof (GtkTextTag *),
1794 printf ("Sorted tag array: \n");
1798 GtkTextTag *t = tag_array_p[i];
1799 printf (" %s priority %d\n", t->name, t->priority);
1812 * gtk_text_attributes_new:
1814 * Creates a #GtkTextAttributes, which describes
1815 * a set of properties on some text.
1817 * Return value: a new #GtkTextAttributes
1820 gtk_text_attributes_new (void)
1822 GtkTextAttributes *values;
1824 values = g_new0 (GtkTextAttributes, 1);
1826 /* 0 is a valid value for most of the struct */
1828 values->refcount = 1;
1830 values->language = gtk_get_default_language ();
1832 values->font_scale = 1.0;
1838 * gtk_text_attributes_copy:
1839 * @src: a #GtkTextAttributes to be copied
1841 * Copies @src and returns a new #GtkTextAttributes.
1843 * Return value: a copy of @src
1846 gtk_text_attributes_copy (GtkTextAttributes *src)
1848 GtkTextAttributes *dest;
1850 dest = gtk_text_attributes_new ();
1851 gtk_text_attributes_copy_values (src, dest);
1857 gtk_text_attributes_get_type (void)
1859 static GType our_type = 0;
1862 our_type = g_boxed_type_register_static ("GtkTextAttributes",
1863 (GBoxedCopyFunc) gtk_text_attributes_ref,
1864 (GBoxedFreeFunc) gtk_text_attributes_unref);
1870 * gtk_text_attributes_copy_values:
1871 * @src: a #GtkTextAttributes
1872 * @dest: another #GtkTextAttributes
1874 * Copies the values from @src to @dest so that @dest has the same values
1875 * as @src. Frees existing values in @dest.
1878 gtk_text_attributes_copy_values (GtkTextAttributes *src,
1879 GtkTextAttributes *dest)
1881 guint orig_refcount;
1883 g_return_if_fail (!dest->realized);
1890 if (src->appearance.bg_stipple)
1891 g_object_ref (src->appearance.bg_stipple);
1893 if (src->appearance.fg_stipple)
1894 g_object_ref (src->appearance.fg_stipple);
1898 if (dest->appearance.bg_stipple)
1899 g_object_unref (dest->appearance.bg_stipple);
1901 if (dest->appearance.fg_stipple)
1902 g_object_unref (dest->appearance.fg_stipple);
1905 pango_font_description_free (dest->font);
1908 orig_refcount = dest->refcount;
1913 dest->tabs = pango_tab_array_copy (src->tabs);
1915 dest->language = src->language;
1918 dest->font = pango_font_description_copy (src->font);
1920 dest->refcount = orig_refcount;
1921 dest->realized = FALSE;
1925 * gtk_text_attributes_ref:
1926 * @values: a #GtkTextAttributes
1928 * Increments the reference count on @values.
1931 gtk_text_attributes_ref (GtkTextAttributes *values)
1933 g_return_if_fail (values != NULL);
1935 values->refcount += 1;
1939 * gtk_text_attributes_unref:
1940 * @values: a #GtkTextAttributes
1942 * Decrements the reference count on @values, freeing the structure
1943 * if the reference count reaches 0.
1946 gtk_text_attributes_unref (GtkTextAttributes *values)
1948 g_return_if_fail (values != NULL);
1949 g_return_if_fail (values->refcount > 0);
1951 values->refcount -= 1;
1953 if (values->refcount == 0)
1955 g_assert (!values->realized);
1957 if (values->appearance.bg_stipple)
1958 g_object_unref (values->appearance.bg_stipple);
1960 if (values->appearance.fg_stipple)
1961 g_object_unref (values->appearance.fg_stipple);
1964 pango_tab_array_free (values->tabs);
1967 pango_font_description_free (values->font);
1974 _gtk_text_attributes_realize (GtkTextAttributes *values,
1978 g_return_if_fail (values != NULL);
1979 g_return_if_fail (values->refcount > 0);
1980 g_return_if_fail (!values->realized);
1982 /* It is wrong to use this colormap, FIXME */
1983 gdk_colormap_alloc_color (cmap,
1984 &values->appearance.fg_color,
1987 gdk_colormap_alloc_color (cmap,
1988 &values->appearance.bg_color,
1991 values->realized = TRUE;
1995 _gtk_text_attributes_unrealize (GtkTextAttributes *values,
1999 g_return_if_fail (values != NULL);
2000 g_return_if_fail (values->refcount > 0);
2001 g_return_if_fail (values->realized);
2003 gdk_colormap_free_colors (cmap,
2004 &values->appearance.fg_color, 1);
2007 gdk_colormap_free_colors (cmap,
2008 &values->appearance.bg_color, 1);
2010 values->appearance.fg_color.pixel = 0;
2011 values->appearance.bg_color.pixel = 0;
2013 values->realized = FALSE;
2017 _gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest,
2023 g_return_if_fail (!dest->realized);
2027 GtkTextTag *tag = tags[n];
2028 GtkTextAttributes *vals = tag->values;
2030 g_assert (tag->table != NULL);
2032 g_assert (tags[n]->priority > tags[n-1]->priority);
2034 if (tag->bg_color_set)
2036 dest->appearance.bg_color = vals->appearance.bg_color;
2038 dest->appearance.draw_bg = TRUE;
2040 if (tag->fg_color_set)
2041 dest->appearance.fg_color = vals->appearance.fg_color;
2043 if (tag->bg_stipple_set)
2045 g_object_ref (vals->appearance.bg_stipple);
2046 if (dest->appearance.bg_stipple)
2047 g_object_unref (dest->appearance.bg_stipple);
2048 dest->appearance.bg_stipple = vals->appearance.bg_stipple;
2050 dest->appearance.draw_bg = TRUE;
2053 if (tag->fg_stipple_set)
2055 g_object_ref (vals->appearance.fg_stipple);
2056 if (dest->appearance.fg_stipple)
2057 g_object_unref (dest->appearance.fg_stipple);
2058 dest->appearance.fg_stipple = vals->appearance.fg_stipple;
2064 pango_font_description_merge (dest->font, vals->font, TRUE);
2066 dest->font = pango_font_description_copy (vals->font);
2069 /* multiply all the scales together to get a composite */
2071 dest->font_scale *= vals->font_scale;
2073 if (tag->justification_set)
2074 dest->justification = vals->justification;
2076 if (vals->direction != GTK_TEXT_DIR_NONE)
2077 dest->direction = vals->direction;
2079 if (tag->left_margin_set)
2080 dest->left_margin = vals->left_margin;
2082 if (tag->indent_set)
2083 dest->indent = vals->indent;
2086 dest->appearance.rise = vals->appearance.rise;
2088 if (tag->right_margin_set)
2089 dest->right_margin = vals->right_margin;
2091 if (tag->pixels_above_lines_set)
2092 dest->pixels_above_lines = vals->pixels_above_lines;
2094 if (tag->pixels_below_lines_set)
2095 dest->pixels_below_lines = vals->pixels_below_lines;
2097 if (tag->pixels_inside_wrap_set)
2098 dest->pixels_inside_wrap = vals->pixels_inside_wrap;
2103 pango_tab_array_free (dest->tabs);
2104 dest->tabs = pango_tab_array_copy (vals->tabs);
2107 if (tag->wrap_mode_set)
2108 dest->wrap_mode = vals->wrap_mode;
2110 if (tag->underline_set)
2111 dest->appearance.underline = vals->appearance.underline;
2113 if (tag->strikethrough_set)
2114 dest->appearance.strikethrough = vals->appearance.strikethrough;
2116 if (tag->invisible_set)
2117 dest->invisible = vals->invisible;
2119 if (tag->editable_set)
2120 dest->editable = vals->editable;
2122 if (tag->bg_full_height_set)
2123 dest->bg_full_height = vals->bg_full_height;
2125 if (tag->language_set)
2126 dest->language = vals->language;
2133 _gtk_text_tag_affects_size (GtkTextTag *tag)
2135 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
2138 (tag->values->font && pango_font_description_get_set_fields (tag->values->font) != 0) ||
2140 tag->justification_set ||
2141 tag->left_margin_set ||
2144 tag->right_margin_set ||
2145 tag->pixels_above_lines_set ||
2146 tag->pixels_below_lines_set ||
2147 tag->pixels_inside_wrap_set ||
2149 tag->underline_set ||
2150 tag->wrap_mode_set ||
2155 _gtk_text_tag_affects_nonsize_appearance (GtkTextTag *tag)
2157 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
2160 tag->bg_color_set ||
2161 tag->bg_stipple_set ||
2162 tag->fg_color_set ||
2163 tag->fg_stipple_set ||
2164 tag->strikethrough_set ||
2165 tag->bg_full_height_set;