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.
51 #include "gtktexttag.h"
52 #include "gtktexttypes.h"
53 #include "gtktexttagtable.h"
54 #include "gtksignal.h"
57 #include "gtkmarshalers.h"
58 #include "gtktypebuiltins.h"
78 PROP_BACKGROUND_STIPPLE,
79 PROP_FOREGROUND_STIPPLE,
90 PROP_PIXELS_ABOVE_LINES,
91 PROP_PIXELS_BELOW_LINES,
92 PROP_PIXELS_INSIDE_WRAP,
108 /* Whether-a-style-arg-is-set args */
111 PROP_BACKGROUND_STIPPLE_SET,
112 PROP_FOREGROUND_STIPPLE_SET,
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_BG_FULL_HEIGHT_SET,
139 static void gtk_text_tag_init (GtkTextTag *text_tag);
140 static void gtk_text_tag_class_init (GtkTextTagClass *klass);
141 static void gtk_text_tag_finalize (GObject *object);
142 static void gtk_text_tag_set_property (GObject *object,
146 static void gtk_text_tag_get_property (GObject *object,
151 static GObjectClass *parent_class = NULL;
152 static guint signals[LAST_SIGNAL] = { 0 };
155 gtk_text_tag_get_type (void)
157 static GType our_type = 0;
161 static const GTypeInfo our_info =
163 sizeof (GtkTextTagClass),
164 (GBaseInitFunc) NULL,
165 (GBaseFinalizeFunc) NULL,
166 (GClassInitFunc) gtk_text_tag_class_init,
167 NULL, /* class_finalize */
168 NULL, /* class_data */
171 (GInstanceInitFunc) gtk_text_tag_init
174 our_type = g_type_register_static (G_TYPE_OBJECT,
184 gtk_text_tag_class_init (GtkTextTagClass *klass)
186 GObjectClass *object_class = G_OBJECT_CLASS (klass);
188 parent_class = g_type_class_peek_parent (klass);
190 object_class->set_property = gtk_text_tag_set_property;
191 object_class->get_property = gtk_text_tag_get_property;
193 object_class->finalize = gtk_text_tag_finalize;
196 g_object_class_install_property (object_class,
198 g_param_spec_string ("name",
200 _("Name used to refer to the text tag"),
202 G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
206 g_object_class_install_property (object_class,
208 g_param_spec_string ("background",
209 _("Background color name"),
210 _("Background color as a string"),
214 g_object_class_install_property (object_class,
216 g_param_spec_boxed ("background_gdk",
217 _("Background color"),
218 _("Background color as a GdkColor"),
220 G_PARAM_READABLE | G_PARAM_WRITABLE));
222 g_object_class_install_property (object_class,
224 g_param_spec_boolean ("background_full_height",
225 _("Background full height"),
226 _("Whether the background color fills the entire line height or only the height of the tagged characters"),
228 G_PARAM_READABLE | G_PARAM_WRITABLE));
231 g_object_class_install_property (object_class,
232 PROP_BACKGROUND_STIPPLE,
233 g_param_spec_object ("background_stipple",
234 _("Background stipple mask"),
235 _("Bitmap to use as a mask when drawing the text background"),
237 G_PARAM_READABLE | G_PARAM_WRITABLE));
240 g_object_class_install_property (object_class,
242 g_param_spec_string ("foreground",
243 _("Foreground color name"),
244 _("Foreground color as a string"),
248 g_object_class_install_property (object_class,
250 g_param_spec_boxed ("foreground_gdk",
251 _("Foreground color"),
252 _("Foreground color as a GdkColor"),
254 G_PARAM_READABLE | G_PARAM_WRITABLE));
257 g_object_class_install_property (object_class,
258 PROP_FOREGROUND_STIPPLE,
259 g_param_spec_object ("foreground_stipple",
260 _("Foreground stipple mask"),
261 _("Bitmap to use as a mask when drawing the text foreground"),
263 G_PARAM_READABLE | G_PARAM_WRITABLE));
265 g_object_class_install_property (object_class,
267 g_param_spec_enum ("direction",
269 _("Text direction, e.g. right-to-left or left-to-right"),
270 GTK_TYPE_TEXT_DIRECTION,
272 G_PARAM_READABLE | G_PARAM_WRITABLE));
274 g_object_class_install_property (object_class,
276 g_param_spec_boolean ("editable",
278 _("Whether the text can be modified by the user"),
280 G_PARAM_READABLE | G_PARAM_WRITABLE));
282 g_object_class_install_property (object_class,
284 g_param_spec_string ("font",
286 _("Font description as a string"),
288 G_PARAM_READABLE | G_PARAM_WRITABLE));
290 g_object_class_install_property (object_class,
292 g_param_spec_boxed ("font_desc",
294 _("Font description as a PangoFontDescription struct"),
295 PANGO_TYPE_FONT_DESCRIPTION,
296 G_PARAM_READABLE | G_PARAM_WRITABLE));
299 g_object_class_install_property (object_class,
301 g_param_spec_string ("family",
303 _("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
305 G_PARAM_READABLE | G_PARAM_WRITABLE));
307 g_object_class_install_property (object_class,
309 g_param_spec_enum ("style",
314 G_PARAM_READABLE | G_PARAM_WRITABLE));
316 g_object_class_install_property (object_class,
318 g_param_spec_enum ("variant",
322 PANGO_VARIANT_NORMAL,
323 G_PARAM_READABLE | G_PARAM_WRITABLE));
325 g_object_class_install_property (object_class,
327 g_param_spec_int ("weight",
333 G_PARAM_READABLE | G_PARAM_WRITABLE));
336 g_object_class_install_property (object_class,
338 g_param_spec_enum ("stretch",
342 PANGO_STRETCH_NORMAL,
343 G_PARAM_READABLE | G_PARAM_WRITABLE));
345 g_object_class_install_property (object_class,
347 g_param_spec_int ("size",
353 G_PARAM_READABLE | G_PARAM_WRITABLE));
355 g_object_class_install_property (object_class,
357 g_param_spec_double ("scale",
363 G_PARAM_READABLE | G_PARAM_WRITABLE));
365 g_object_class_install_property (object_class,
367 g_param_spec_double ("size_points",
369 _("Font size in points"),
373 G_PARAM_READABLE | G_PARAM_WRITABLE));
375 g_object_class_install_property (object_class,
377 g_param_spec_enum ("justification",
379 _("Left, right, or center justification"),
380 GTK_TYPE_JUSTIFICATION,
382 G_PARAM_READABLE | G_PARAM_WRITABLE));
384 g_object_class_install_property (object_class,
386 g_param_spec_string ("language",
388 _("Language engine code to use for rendering the text"),
390 G_PARAM_READABLE | G_PARAM_WRITABLE));
392 g_object_class_install_property (object_class,
394 g_param_spec_int ("left_margin",
396 _("Width of the left margin in pixels"),
400 G_PARAM_READABLE | G_PARAM_WRITABLE));
402 g_object_class_install_property (object_class,
404 g_param_spec_int ("right_margin",
406 _("Width of the right margin in pixels"),
410 G_PARAM_READABLE | G_PARAM_WRITABLE));
413 g_object_class_install_property (object_class,
415 g_param_spec_int ("indent",
417 _("Amount to indent the paragraph, in pixels"),
421 G_PARAM_READABLE | G_PARAM_WRITABLE));
424 g_object_class_install_property (object_class,
426 g_param_spec_int ("rise",
428 _("Offset of text above the baseline (below the baseline if rise is negative)"),
432 G_PARAM_READABLE | G_PARAM_WRITABLE));
434 g_object_class_install_property (object_class,
435 PROP_PIXELS_ABOVE_LINES,
436 g_param_spec_int ("pixels_above_lines",
437 _("Pixels above lines"),
438 _("Pixels of blank space above paragraphs"),
442 G_PARAM_READABLE | G_PARAM_WRITABLE));
444 g_object_class_install_property (object_class,
445 PROP_PIXELS_BELOW_LINES,
446 g_param_spec_int ("pixels_below_lines",
447 _("Pixels below lines"),
448 _("Pixels of blank space below paragraphs"),
452 G_PARAM_READABLE | G_PARAM_WRITABLE));
454 g_object_class_install_property (object_class,
455 PROP_PIXELS_INSIDE_WRAP,
456 g_param_spec_int ("pixels_inside_wrap",
457 _("Pixels inside wrap"),
458 _("Pixels of blank space between wrapped lines in a paragraph"),
462 G_PARAM_READABLE | G_PARAM_WRITABLE));
464 g_object_class_install_property (object_class,
466 g_param_spec_boolean ("strikethrough",
468 _("Whether to strike through the text"),
470 G_PARAM_READABLE | G_PARAM_WRITABLE));
472 g_object_class_install_property (object_class,
474 g_param_spec_enum ("underline",
476 _("Style of underline for this text"),
477 PANGO_TYPE_UNDERLINE,
478 PANGO_UNDERLINE_NONE,
479 G_PARAM_READABLE | G_PARAM_WRITABLE));
481 g_object_class_install_property (object_class,
483 g_param_spec_enum ("wrap_mode",
485 _("Whether to wrap lines never, at word boundaries, or at character boundaries"),
488 G_PARAM_READABLE | G_PARAM_WRITABLE));
491 g_object_class_install_property (object_class,
493 g_param_spec_boxed ("tabs",
495 _("Custom tabs for this text"),
496 PANGO_TYPE_TAB_ARRAY,
497 G_PARAM_READABLE | G_PARAM_WRITABLE));
499 g_object_class_install_property (object_class,
501 g_param_spec_boolean ("invisible",
503 _("Whether this text is hidden"),
505 G_PARAM_READABLE | G_PARAM_WRITABLE));
507 /* Style props are set or not */
509 #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))
511 ADD_SET_PROP ("background_set", PROP_BACKGROUND_SET,
513 _("Whether this tag affects the background color"));
515 ADD_SET_PROP ("background_full_height_set", PROP_BG_FULL_HEIGHT_SET,
516 _("Background full height set"),
517 _("Whether this tag affects background height"));
519 ADD_SET_PROP ("background_stipple_set", PROP_BACKGROUND_STIPPLE_SET,
520 _("Background stipple set"),
521 _("Whether this tag affects the background stipple"));
523 ADD_SET_PROP ("foreground_set", PROP_FOREGROUND_SET,
525 _("Whether this tag affects the foreground color"));
527 ADD_SET_PROP ("foreground_stipple_set", PROP_FOREGROUND_STIPPLE_SET,
528 _("Foreground stipple set"),
529 _("Whether this tag affects the foreground stipple"));
531 ADD_SET_PROP ("editable_set", PROP_EDITABLE_SET,
532 _("Editability set"),
533 _("Whether this tag affects text editability"));
535 ADD_SET_PROP ("family_set", PROP_FAMILY_SET,
536 _("Font family set"),
537 _("Whether this tag affects the font family"));
539 ADD_SET_PROP ("style_set", PROP_STYLE_SET,
541 _("Whether this tag affects the font style"));
543 ADD_SET_PROP ("variant_set", PROP_VARIANT_SET,
544 _("Font variant set"),
545 _("Whether this tag affects the font variant"));
547 ADD_SET_PROP ("weight_set", PROP_WEIGHT_SET,
548 _("Font weight set"),
549 _("Whether this tag affects the font weight"));
551 ADD_SET_PROP ("stretch_set", PROP_STRETCH_SET,
552 _("Font stretch set"),
553 _("Whether this tag affects the font stretch"));
555 ADD_SET_PROP ("size_set", PROP_SIZE_SET,
557 _("Whether this tag affects the font size"));
559 ADD_SET_PROP ("scale_set", PROP_SCALE_SET,
561 _("Whether this tag scales the font size by a factor"));
563 ADD_SET_PROP ("justification_set", PROP_JUSTIFICATION_SET,
564 _("Justification set"),
565 _("Whether this tag affects paragraph justification"));
567 ADD_SET_PROP ("language_set", PROP_LANGUAGE_SET,
569 _("Whether this tag affects the language the text is rendered as"));
571 ADD_SET_PROP ("left_margin_set", PROP_LEFT_MARGIN_SET,
572 _("Left margin set"),
573 _("Whether this tag affects the left margin"));
575 ADD_SET_PROP ("indent_set", PROP_INDENT_SET,
577 _("Whether this tag affects indentation"));
579 ADD_SET_PROP ("rise_set", PROP_RISE_SET,
581 _("Whether this tag affects the rise"));
583 ADD_SET_PROP ("pixels_above_lines_set", PROP_PIXELS_ABOVE_LINES_SET,
584 _("Pixels above lines set"),
585 _("Whether this tag affects the number of pixels above lines"));
587 ADD_SET_PROP ("pixels_below_lines_set", PROP_PIXELS_BELOW_LINES_SET,
588 _("Pixels below lines set"),
589 _("Whether this tag affects the number of pixels above lines"));
591 ADD_SET_PROP ("pixels_inside_wrap_set", PROP_PIXELS_INSIDE_WRAP_SET,
592 _("Pixels inside wrap set"),
593 _("Whether this tag affects the number of pixels between wrapped lines"));
595 ADD_SET_PROP ("strikethrough_set", PROP_STRIKETHROUGH_SET,
596 _("Strikethrough set"),
597 _("Whether this tag affects strikethrough"));
599 ADD_SET_PROP ("right_margin_set", PROP_RIGHT_MARGIN_SET,
600 _("Right margin set"),
601 _("Whether this tag affects the right margin"));
603 ADD_SET_PROP ("underline_set", PROP_UNDERLINE_SET,
605 _("Whether this tag affects underlining"));
607 ADD_SET_PROP ("wrap_mode_set", PROP_WRAP_MODE_SET,
609 _("Whether this tag affects line wrap mode"));
611 ADD_SET_PROP ("tabs_set", PROP_TABS_SET,
613 _("Whether this tag affects tabs"));
615 ADD_SET_PROP ("invisible_set", PROP_INVISIBLE_SET,
617 _("Whether this tag affects text visibility"));
620 g_signal_new ("event",
621 G_OBJECT_CLASS_TYPE (object_class),
623 GTK_SIGNAL_OFFSET (GtkTextTagClass, event),
624 _gtk_boolean_handled_accumulator, NULL,
625 _gtk_marshal_BOOLEAN__OBJECT_BOXED_BOXED,
629 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE,
634 gtk_text_tag_init (GtkTextTag *text_tag)
636 /* 0 is basically a fine way to initialize everything in the
639 text_tag->values = gtk_text_attributes_new ();
644 * @name: tag name, or %NULL
646 * Creates a #GtkTextTag. Configure the tag using object arguments,
647 * i.e. using g_object_set().
649 * Return value: a new #GtkTextTag
652 gtk_text_tag_new (const gchar *name)
656 tag = GTK_TEXT_TAG (g_object_new (gtk_text_tag_get_type (),
664 gtk_text_tag_finalize (GObject *object)
666 GtkTextTag *text_tag;
668 text_tag = GTK_TEXT_TAG (object);
670 g_assert (!text_tag->values->realized);
673 gtk_text_tag_table_remove (text_tag->table, text_tag);
675 g_assert (text_tag->table == NULL);
677 gtk_text_attributes_unref (text_tag->values);
678 text_tag->values = NULL;
680 g_free (text_tag->name);
681 text_tag->name = NULL;
683 (* G_OBJECT_CLASS (parent_class)->finalize) (object);
687 set_bg_color (GtkTextTag *tag, GdkColor *color)
691 if (!tag->bg_color_set)
693 tag->bg_color_set = TRUE;
694 g_object_notify (G_OBJECT (tag), "background_set");
697 tag->values->appearance.bg_color = *color;
701 if (tag->bg_color_set)
703 tag->bg_color_set = FALSE;
704 g_object_notify (G_OBJECT (tag), "background_set");
710 set_fg_color (GtkTextTag *tag, GdkColor *color)
714 if (!tag->fg_color_set)
716 tag->fg_color_set = TRUE;
717 g_object_notify (G_OBJECT (tag), "foreground_set");
719 tag->values->appearance.fg_color = *color;
723 if (tag->fg_color_set)
725 tag->fg_color_set = FALSE;
726 g_object_notify (G_OBJECT (tag), "foreground_set");
732 get_property_font_set_mask (guint prop_id)
736 case PROP_FAMILY_SET:
737 return PANGO_FONT_MASK_FAMILY;
739 return PANGO_FONT_MASK_STYLE;
740 case PROP_VARIANT_SET:
741 return PANGO_FONT_MASK_VARIANT;
742 case PROP_WEIGHT_SET:
743 return PANGO_FONT_MASK_WEIGHT;
744 case PROP_STRETCH_SET:
745 return PANGO_FONT_MASK_STRETCH;
747 return PANGO_FONT_MASK_SIZE;
754 set_font_desc_fields (PangoFontDescription *desc,
755 PangoFontMask to_set)
757 PangoFontMask changed_mask = 0;
759 if (to_set & PANGO_FONT_MASK_FAMILY)
761 const char *family = pango_font_description_get_family (desc);
765 changed_mask |= PANGO_FONT_MASK_FAMILY;
768 pango_font_description_set_family (desc, family);
770 if (to_set & PANGO_FONT_MASK_STYLE)
771 pango_font_description_set_style (desc, pango_font_description_get_style (desc));
772 if (to_set & PANGO_FONT_MASK_VARIANT)
773 pango_font_description_set_variant (desc, pango_font_description_get_variant (desc));
774 if (to_set & PANGO_FONT_MASK_WEIGHT)
775 pango_font_description_set_weight (desc, pango_font_description_get_weight (desc));
776 if (to_set & PANGO_FONT_MASK_STRETCH)
777 pango_font_description_set_stretch (desc, pango_font_description_get_stretch (desc));
778 if (to_set & PANGO_FONT_MASK_SIZE)
780 gint size = pango_font_description_get_size (desc);
783 size = 10 * PANGO_SCALE;
784 changed_mask |= PANGO_FONT_MASK_SIZE;
787 pango_font_description_set_size (desc, size);
794 notify_set_changed (GObject *object,
795 PangoFontMask changed_mask)
797 if (changed_mask & PANGO_FONT_MASK_FAMILY)
798 g_object_notify (object, "family_set");
799 if (changed_mask & PANGO_FONT_MASK_STYLE)
800 g_object_notify (object, "style_set");
801 if (changed_mask & PANGO_FONT_MASK_VARIANT)
802 g_object_notify (object, "variant_set");
803 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
804 g_object_notify (object, "weight_set");
805 if (changed_mask & PANGO_FONT_MASK_STRETCH)
806 g_object_notify (object, "stretch_set");
807 if (changed_mask & PANGO_FONT_MASK_SIZE)
808 g_object_notify (object, "size_set");
812 notify_fields_changed (GObject *object,
813 PangoFontMask changed_mask)
815 if (changed_mask & PANGO_FONT_MASK_FAMILY)
816 g_object_notify (object, "family");
817 if (changed_mask & PANGO_FONT_MASK_STYLE)
818 g_object_notify (object, "style");
819 if (changed_mask & PANGO_FONT_MASK_VARIANT)
820 g_object_notify (object, "variant");
821 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
822 g_object_notify (object, "weight");
823 if (changed_mask & PANGO_FONT_MASK_STRETCH)
824 g_object_notify (object, "stretch");
825 if (changed_mask & PANGO_FONT_MASK_SIZE)
826 g_object_notify (object, "size");
830 set_font_description (GtkTextTag *text_tag,
831 PangoFontDescription *font_desc)
833 GObject *object = G_OBJECT (text_tag);
834 PangoFontDescription *new_font_desc;
835 PangoFontMask old_mask, new_mask, changed_mask, set_changed_mask;
838 new_font_desc = pango_font_description_copy (font_desc);
840 new_font_desc = pango_font_description_new ();
842 if (text_tag->values->font)
843 old_mask = pango_font_description_get_set_fields (text_tag->values->font);
847 new_mask = pango_font_description_get_set_fields (new_font_desc);
849 changed_mask = old_mask | new_mask;
850 set_changed_mask = old_mask ^ new_mask;
852 if (text_tag->values->font)
853 pango_font_description_free (text_tag->values->font);
854 text_tag->values->font = new_font_desc;
856 g_object_freeze_notify (object);
858 g_object_notify (object, "font_desc");
859 g_object_notify (object, "font");
861 if (changed_mask & PANGO_FONT_MASK_FAMILY)
862 g_object_notify (object, "family");
863 if (changed_mask & PANGO_FONT_MASK_STYLE)
864 g_object_notify (object, "style");
865 if (changed_mask & PANGO_FONT_MASK_VARIANT)
866 g_object_notify (object, "variant");
867 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
868 g_object_notify (object, "weight");
869 if (changed_mask & PANGO_FONT_MASK_STRETCH)
870 g_object_notify (object, "stretch");
871 if (changed_mask & PANGO_FONT_MASK_SIZE)
873 g_object_notify (object, "size");
874 g_object_notify (object, "size_points");
877 notify_set_changed (object, set_changed_mask);
879 g_object_thaw_notify (object);
883 gtk_text_tag_ensure_font (GtkTextTag *text_tag)
885 if (!text_tag->values->font)
886 text_tag->values->font = pango_font_description_new ();
890 gtk_text_tag_set_property (GObject *object,
895 GtkTextTag *text_tag;
896 gboolean size_changed = FALSE;
898 text_tag = GTK_TEXT_TAG (object);
900 g_return_if_fail (!text_tag->values->realized);
905 g_return_if_fail (text_tag->name == NULL);
906 text_tag->name = g_strdup (g_value_get_string (value));
909 case PROP_BACKGROUND:
913 if (gdk_color_parse (g_value_get_string (value), &color))
914 set_bg_color (text_tag, &color);
916 g_warning ("Don't know color `%s'", g_value_get_string (value));
918 g_object_notify (object, "background_gdk");
922 case PROP_FOREGROUND:
926 if (gdk_color_parse (g_value_get_string (value), &color))
927 set_fg_color (text_tag, &color);
929 g_warning ("Don't know color `%s'", g_value_get_string (value));
931 g_object_notify (object, "foreground_gdk");
935 case PROP_BACKGROUND_GDK:
937 GdkColor *color = g_value_get_boxed (value);
939 set_bg_color (text_tag, color);
943 case PROP_FOREGROUND_GDK:
945 GdkColor *color = g_value_get_boxed (value);
947 set_fg_color (text_tag, color);
951 case PROP_BACKGROUND_STIPPLE:
953 GdkBitmap *bitmap = g_value_get_object (value);
955 text_tag->bg_stipple_set = TRUE;
956 g_object_notify (object, "background_stipple_set");
958 if (text_tag->values->appearance.bg_stipple != bitmap)
961 gdk_bitmap_ref (bitmap);
963 if (text_tag->values->appearance.bg_stipple)
964 gdk_bitmap_unref (text_tag->values->appearance.bg_stipple);
966 text_tag->values->appearance.bg_stipple = bitmap;
971 case PROP_FOREGROUND_STIPPLE:
973 GdkBitmap *bitmap = g_value_get_object (value);
975 text_tag->fg_stipple_set = TRUE;
976 g_object_notify (object, "foreground_stipple_set");
978 if (text_tag->values->appearance.fg_stipple != bitmap)
981 gdk_bitmap_ref (bitmap);
983 if (text_tag->values->appearance.fg_stipple)
984 gdk_bitmap_unref (text_tag->values->appearance.fg_stipple);
986 text_tag->values->appearance.fg_stipple = bitmap;
993 PangoFontDescription *font_desc = NULL;
996 name = g_value_get_string (value);
999 font_desc = pango_font_description_from_string (name);
1001 set_font_description (text_tag, font_desc);
1003 pango_font_description_free (font_desc);
1005 size_changed = TRUE;
1009 case PROP_FONT_DESC:
1011 PangoFontDescription *font_desc;
1013 font_desc = g_value_get_boxed (value);
1015 set_font_description (text_tag, font_desc);
1017 size_changed = TRUE;
1027 case PROP_SIZE_POINTS:
1029 PangoFontMask old_set_mask;
1031 gtk_text_tag_ensure_font (text_tag);
1032 old_set_mask = pango_font_description_get_set_fields (text_tag->values->font);
1037 pango_font_description_set_family (text_tag->values->font,
1038 g_value_get_string (value));
1041 pango_font_description_set_style (text_tag->values->font,
1042 g_value_get_enum (value));
1045 pango_font_description_set_variant (text_tag->values->font,
1046 g_value_get_enum (value));
1049 pango_font_description_set_weight (text_tag->values->font,
1050 g_value_get_int (value));
1053 pango_font_description_set_stretch (text_tag->values->font,
1054 g_value_get_enum (value));
1057 pango_font_description_set_size (text_tag->values->font,
1058 g_value_get_int (value));
1059 g_object_notify (object, "size_points");
1061 case PROP_SIZE_POINTS:
1062 pango_font_description_set_size (text_tag->values->font,
1063 g_value_get_double (value) * PANGO_SCALE);
1064 g_object_notify (object, "size");
1068 size_changed = TRUE;
1069 notify_set_changed (object, old_set_mask & pango_font_description_get_set_fields (text_tag->values->font));
1070 g_object_notify (object, "font_desc");
1071 g_object_notify (object, "font");
1077 text_tag->values->font_scale = g_value_get_double (value);
1078 text_tag->scale_set = TRUE;
1079 g_object_notify (object, "scale_set");
1080 size_changed = TRUE;
1083 case PROP_PIXELS_ABOVE_LINES:
1084 text_tag->pixels_above_lines_set = TRUE;
1085 text_tag->values->pixels_above_lines = g_value_get_int (value);
1086 g_object_notify (object, "pixels_above_lines_set");
1087 size_changed = TRUE;
1090 case PROP_PIXELS_BELOW_LINES:
1091 text_tag->pixels_below_lines_set = TRUE;
1092 text_tag->values->pixels_below_lines = g_value_get_int (value);
1093 g_object_notify (object, "pixels_below_lines_set");
1094 size_changed = TRUE;
1097 case PROP_PIXELS_INSIDE_WRAP:
1098 text_tag->pixels_inside_wrap_set = TRUE;
1099 text_tag->values->pixels_inside_wrap = g_value_get_int (value);
1100 g_object_notify (object, "pixels_inside_wrap_set");
1101 size_changed = TRUE;
1105 text_tag->editable_set = TRUE;
1106 text_tag->values->editable = g_value_get_boolean (value);
1107 g_object_notify (object, "editable_set");
1110 case PROP_WRAP_MODE:
1111 text_tag->wrap_mode_set = TRUE;
1112 text_tag->values->wrap_mode = g_value_get_enum (value);
1113 g_object_notify (object, "wrap_mode_set");
1114 size_changed = TRUE;
1117 case PROP_JUSTIFICATION:
1118 text_tag->justification_set = TRUE;
1119 text_tag->values->justification = g_value_get_enum (value);
1120 g_object_notify (object, "justification_set");
1121 size_changed = TRUE;
1124 case PROP_DIRECTION:
1125 text_tag->values->direction = g_value_get_enum (value);
1128 case PROP_LEFT_MARGIN:
1129 text_tag->left_margin_set = TRUE;
1130 text_tag->values->left_margin = g_value_get_int (value);
1131 g_object_notify (object, "left_margin_set");
1132 size_changed = TRUE;
1136 text_tag->indent_set = TRUE;
1137 text_tag->values->indent = g_value_get_int (value);
1138 g_object_notify (object, "indent_set");
1139 size_changed = TRUE;
1142 case PROP_STRIKETHROUGH:
1143 text_tag->strikethrough_set = TRUE;
1144 text_tag->values->appearance.strikethrough = g_value_get_boolean (value);
1145 g_object_notify (object, "strikethrough_set");
1148 case PROP_RIGHT_MARGIN:
1149 text_tag->right_margin_set = TRUE;
1150 text_tag->values->right_margin = g_value_get_int (value);
1151 g_object_notify (object, "right_margin_set");
1152 size_changed = TRUE;
1155 case PROP_UNDERLINE:
1156 text_tag->underline_set = TRUE;
1157 text_tag->values->appearance.underline = g_value_get_enum (value);
1158 g_object_notify (object, "underline_set");
1162 text_tag->rise_set = TRUE;
1163 text_tag->values->appearance.rise = g_value_get_int (value);
1164 g_object_notify (object, "rise_set");
1165 size_changed = TRUE;
1168 case PROP_BG_FULL_HEIGHT:
1169 text_tag->bg_full_height_set = TRUE;
1170 text_tag->values->bg_full_height = g_value_get_boolean (value);
1171 g_object_notify (object, "bg_full_height_set");
1175 text_tag->language_set = TRUE;
1176 text_tag->values->language = pango_language_from_string (g_value_get_string (value));
1177 g_object_notify (object, "language_set");
1181 text_tag->tabs_set = TRUE;
1183 if (text_tag->values->tabs)
1184 pango_tab_array_free (text_tag->values->tabs);
1186 /* FIXME I'm not sure if this is a memleak or not */
1187 text_tag->values->tabs =
1188 pango_tab_array_copy (g_value_get_boxed (value));
1190 g_object_notify (object, "tabs_set");
1192 size_changed = TRUE;
1195 case PROP_INVISIBLE:
1196 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.");
1197 text_tag->invisible_set = TRUE;
1198 text_tag->values->invisible = g_value_get_boolean (value);
1199 g_object_notify (object, "invisible_set");
1200 size_changed = TRUE;
1203 /* Whether the value should be used... */
1205 case PROP_BACKGROUND_SET:
1206 text_tag->bg_color_set = g_value_get_boolean (value);
1209 case PROP_FOREGROUND_SET:
1210 text_tag->fg_color_set = g_value_get_boolean (value);
1213 case PROP_BACKGROUND_STIPPLE_SET:
1214 text_tag->bg_stipple_set = g_value_get_boolean (value);
1215 if (!text_tag->bg_stipple_set &&
1216 text_tag->values->appearance.bg_stipple)
1218 g_object_unref (G_OBJECT (text_tag->values->appearance.bg_stipple));
1219 text_tag->values->appearance.bg_stipple = NULL;
1223 case PROP_FOREGROUND_STIPPLE_SET:
1224 text_tag->fg_stipple_set = g_value_get_boolean (value);
1225 if (!text_tag->fg_stipple_set &&
1226 text_tag->values->appearance.fg_stipple)
1228 g_object_unref (G_OBJECT (text_tag->values->appearance.fg_stipple));
1229 text_tag->values->appearance.fg_stipple = NULL;
1233 case PROP_FAMILY_SET:
1234 case PROP_STYLE_SET:
1235 case PROP_VARIANT_SET:
1236 case PROP_WEIGHT_SET:
1237 case PROP_STRETCH_SET:
1239 if (!g_value_get_boolean (value))
1241 if (text_tag->values->font)
1242 pango_font_description_unset_fields (text_tag->values->font,
1243 get_property_font_set_mask (prop_id));
1247 PangoFontMask changed_mask;
1249 gtk_text_tag_ensure_font (text_tag);
1250 changed_mask = set_font_desc_fields (text_tag->values->font,
1251 get_property_font_set_mask (prop_id));
1252 notify_fields_changed (G_OBJECT (text_tag), changed_mask);
1256 case PROP_SCALE_SET:
1257 text_tag->scale_set = g_value_get_boolean (value);
1258 size_changed = TRUE;
1261 case PROP_PIXELS_ABOVE_LINES_SET:
1262 text_tag->pixels_above_lines_set = g_value_get_boolean (value);
1263 size_changed = TRUE;
1266 case PROP_PIXELS_BELOW_LINES_SET:
1267 text_tag->pixels_below_lines_set = g_value_get_boolean (value);
1268 size_changed = TRUE;
1271 case PROP_PIXELS_INSIDE_WRAP_SET:
1272 text_tag->pixels_inside_wrap_set = g_value_get_boolean (value);
1273 size_changed = TRUE;
1276 case PROP_EDITABLE_SET:
1277 text_tag->editable_set = g_value_get_boolean (value);
1280 case PROP_WRAP_MODE_SET:
1281 text_tag->wrap_mode_set = g_value_get_boolean (value);
1282 size_changed = TRUE;
1285 case PROP_JUSTIFICATION_SET:
1286 text_tag->justification_set = g_value_get_boolean (value);
1287 size_changed = TRUE;
1290 case PROP_LEFT_MARGIN_SET:
1291 text_tag->left_margin_set = g_value_get_boolean (value);
1292 size_changed = TRUE;
1295 case PROP_INDENT_SET:
1296 text_tag->indent_set = g_value_get_boolean (value);
1297 size_changed = TRUE;
1300 case PROP_STRIKETHROUGH_SET:
1301 text_tag->strikethrough_set = g_value_get_boolean (value);
1304 case PROP_RIGHT_MARGIN_SET:
1305 text_tag->right_margin_set = g_value_get_boolean (value);
1306 size_changed = TRUE;
1309 case PROP_UNDERLINE_SET:
1310 text_tag->underline_set = g_value_get_boolean (value);
1314 text_tag->rise_set = g_value_get_boolean (value);
1315 size_changed = TRUE;
1318 case PROP_BG_FULL_HEIGHT_SET:
1319 text_tag->bg_full_height_set = g_value_get_boolean (value);
1322 case PROP_LANGUAGE_SET:
1323 text_tag->language_set = g_value_get_boolean (value);
1324 size_changed = TRUE;
1328 text_tag->tabs_set = g_value_get_boolean (value);
1329 size_changed = TRUE;
1332 case PROP_INVISIBLE_SET:
1333 text_tag->invisible_set = g_value_get_boolean (value);
1334 size_changed = TRUE;
1338 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1342 /* FIXME I would like to do this after all set_property in a single
1343 * g_object_set () have been called. But an idle function won't
1344 * work; we need to emit when the tag is changed, not when we get
1345 * around to the event loop. So blah, we eat some inefficiency.
1348 /* This is also somewhat weird since we emit another object's
1349 * signal here, but the two objects are already tightly bound.
1352 if (text_tag->table)
1353 g_signal_emit_by_name (G_OBJECT (text_tag->table),
1355 text_tag, size_changed);
1359 get_color_arg (GValue *value, GdkColor *orig)
1363 color = g_new (GdkColor, 1);
1365 g_value_init (value, GDK_TYPE_COLOR);
1366 g_value_set_boxed (value, color);
1370 gtk_text_tag_get_property (GObject *object,
1377 tag = GTK_TEXT_TAG (object);
1382 g_value_set_string (value, tag->name);
1385 case PROP_BACKGROUND_GDK:
1386 get_color_arg (value, &tag->values->appearance.bg_color);
1389 case PROP_FOREGROUND_GDK:
1390 get_color_arg (value, &tag->values->appearance.fg_color);
1393 case PROP_BACKGROUND_STIPPLE:
1394 if (tag->bg_stipple_set)
1395 g_value_set_boxed (value, tag->values->appearance.bg_stipple);
1398 case PROP_FOREGROUND_STIPPLE:
1399 if (tag->fg_stipple_set)
1400 g_value_set_boxed (value, tag->values->appearance.fg_stipple);
1405 /* FIXME GValue imposes a totally gratuitous string copy
1406 * here, we could just hand off string ownership
1410 gtk_text_tag_ensure_font (tag);
1412 str = pango_font_description_to_string (tag->values->font);
1413 g_value_set_string (value, str);
1418 case PROP_FONT_DESC:
1419 gtk_text_tag_ensure_font (tag);
1420 g_value_set_boxed (value, tag->values->font);
1429 case PROP_SIZE_POINTS:
1430 gtk_text_tag_ensure_font (tag);
1434 g_value_set_string (value, pango_font_description_get_family (tag->values->font));
1438 g_value_set_enum (value, pango_font_description_get_style (tag->values->font));
1442 g_value_set_enum (value, pango_font_description_get_variant (tag->values->font));
1446 g_value_set_int (value, pango_font_description_get_weight (tag->values->font));
1450 g_value_set_enum (value, pango_font_description_get_stretch (tag->values->font));
1454 g_value_set_int (value, pango_font_description_get_size (tag->values->font));
1457 case PROP_SIZE_POINTS:
1458 g_value_set_double (value, ((double)pango_font_description_get_size (tag->values->font)) / (double)PANGO_SCALE);
1464 g_value_set_double (value, tag->values->font_scale);
1467 case PROP_PIXELS_ABOVE_LINES:
1468 g_value_set_int (value, tag->values->pixels_above_lines);
1471 case PROP_PIXELS_BELOW_LINES:
1472 g_value_set_int (value, tag->values->pixels_below_lines);
1475 case PROP_PIXELS_INSIDE_WRAP:
1476 g_value_set_int (value, tag->values->pixels_inside_wrap);
1480 g_value_set_boolean (value, tag->values->editable);
1483 case PROP_WRAP_MODE:
1484 g_value_set_enum (value, tag->values->wrap_mode);
1487 case PROP_JUSTIFICATION:
1488 g_value_set_enum (value, tag->values->justification);
1491 case PROP_DIRECTION:
1492 g_value_set_enum (value, tag->values->direction);
1495 case PROP_LEFT_MARGIN:
1496 g_value_set_int (value, tag->values->left_margin);
1500 g_value_set_int (value, tag->values->indent);
1503 case PROP_STRIKETHROUGH:
1504 g_value_set_boolean (value, tag->values->appearance.strikethrough);
1507 case PROP_RIGHT_MARGIN:
1508 g_value_set_int (value, tag->values->right_margin);
1511 case PROP_UNDERLINE:
1512 g_value_set_enum (value, tag->values->appearance.underline);
1516 g_value_set_int (value, tag->values->appearance.rise);
1519 case PROP_BG_FULL_HEIGHT:
1520 g_value_set_boolean (value, tag->values->bg_full_height);
1524 g_value_set_string (value, pango_language_to_string (tag->values->language));
1528 if (tag->values->tabs)
1529 g_value_set_boxed (value, tag->values->tabs);
1532 case PROP_INVISIBLE:
1533 g_value_set_boolean (value, tag->values->invisible);
1536 case PROP_BACKGROUND_SET:
1537 g_value_set_boolean (value, tag->bg_color_set);
1540 case PROP_FOREGROUND_SET:
1541 g_value_set_boolean (value, tag->fg_color_set);
1544 case PROP_BACKGROUND_STIPPLE_SET:
1545 g_value_set_boolean (value, tag->bg_stipple_set);
1548 case PROP_FOREGROUND_STIPPLE_SET:
1549 g_value_set_boolean (value, tag->fg_stipple_set);
1552 case PROP_FAMILY_SET:
1553 case PROP_STYLE_SET:
1554 case PROP_VARIANT_SET:
1555 case PROP_WEIGHT_SET:
1556 case PROP_STRETCH_SET:
1559 PangoFontMask set_mask = tag->values->font ? pango_font_description_get_set_fields (tag->values->font) : 0;
1560 PangoFontMask test_mask = get_property_font_set_mask (prop_id);
1561 g_value_set_boolean (value, (set_mask & test_mask) != 0);
1566 case PROP_SCALE_SET:
1567 g_value_set_boolean (value, tag->scale_set);
1570 case PROP_PIXELS_ABOVE_LINES_SET:
1571 g_value_set_boolean (value, tag->pixels_above_lines_set);
1574 case PROP_PIXELS_BELOW_LINES_SET:
1575 g_value_set_boolean (value, tag->pixels_below_lines_set);
1578 case PROP_PIXELS_INSIDE_WRAP_SET:
1579 g_value_set_boolean (value, tag->pixels_inside_wrap_set);
1582 case PROP_EDITABLE_SET:
1583 g_value_set_boolean (value, tag->editable_set);
1586 case PROP_WRAP_MODE_SET:
1587 g_value_set_boolean (value, tag->wrap_mode_set);
1590 case PROP_JUSTIFICATION_SET:
1591 g_value_set_boolean (value, tag->justification_set);
1594 case PROP_LEFT_MARGIN_SET:
1595 g_value_set_boolean (value, tag->left_margin_set);
1598 case PROP_INDENT_SET:
1599 g_value_set_boolean (value, tag->indent_set);
1602 case PROP_STRIKETHROUGH_SET:
1603 g_value_set_boolean (value, tag->strikethrough_set);
1606 case PROP_RIGHT_MARGIN_SET:
1607 g_value_set_boolean (value, tag->right_margin_set);
1610 case PROP_UNDERLINE_SET:
1611 g_value_set_boolean (value, tag->underline_set);
1615 g_value_set_boolean (value, tag->rise_set);
1618 case PROP_BG_FULL_HEIGHT_SET:
1619 g_value_set_boolean (value, tag->bg_full_height_set);
1622 case PROP_LANGUAGE_SET:
1623 g_value_set_boolean (value, tag->language_set);
1627 g_value_set_boolean (value, tag->tabs_set);
1630 case PROP_INVISIBLE_SET:
1631 g_value_set_boolean (value, tag->invisible_set);
1634 case PROP_BACKGROUND:
1635 case PROP_FOREGROUND:
1636 g_warning ("'foreground' and 'background' properties are not readable, use 'foreground_gdk' and 'background_gdk'");
1638 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1654 delta_priority_foreach (GtkTextTag *tag, gpointer user_data)
1656 DeltaData *dd = user_data;
1658 if (tag->priority >= dd->low && tag->priority <= dd->high)
1659 tag->priority += dd->delta;
1663 * gtk_text_tag_get_priority:
1664 * @tag: a #GtkTextTag
1666 * Get the tag priority.
1668 * Return value: The tag's priority.
1671 gtk_text_tag_get_priority (GtkTextTag *tag)
1673 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), 0);
1675 return tag->priority;
1679 * gtk_text_tag_set_priority:
1680 * @tag: a #GtkTextTag
1681 * @priority: the new priority
1683 * Sets the priority of a #GtkTextTag. Valid priorities are
1684 * start at 0 and go to one less than gtk_text_tag_table_get_size().
1685 * Each tag in a table has a unique priority; setting the priority
1686 * of one tag shifts the priorities of all the other tags in the
1687 * table to maintain a unique priority for each tag. Higher priority
1688 * tags "win" if two tags both set the same text attribute. When adding
1689 * a tag to a tag table, it will be assigned the highest priority in
1690 * the table by default; so normally the precedence of a set of tags
1691 * is the order in which they were added to the table, or created with
1692 * gtk_text_buffer_create_tag(), which adds the tag to the buffer's table
1696 gtk_text_tag_set_priority (GtkTextTag *tag,
1701 g_return_if_fail (GTK_IS_TEXT_TAG (tag));
1702 g_return_if_fail (tag->table != NULL);
1703 g_return_if_fail (priority >= 0);
1704 g_return_if_fail (priority < gtk_text_tag_table_get_size (tag->table));
1706 if (priority == tag->priority)
1709 if (priority < tag->priority)
1712 dd.high = tag->priority - 1;
1717 dd.low = tag->priority + 1;
1722 gtk_text_tag_table_foreach (tag->table,
1723 delta_priority_foreach,
1726 tag->priority = priority;
1730 * gtk_text_tag_event:
1731 * @tag: a #GtkTextTag
1732 * @event_object: object that received the event, such as a widget
1734 * @iter: location where the event was received
1736 * Emits the "event" signal on the #GtkTextTag.
1738 * Return value: result of signal emission (whether the event was handled)
1741 gtk_text_tag_event (GtkTextTag *tag,
1742 GObject *event_object,
1744 const GtkTextIter *iter)
1746 gboolean retval = FALSE;
1748 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
1749 g_return_val_if_fail (G_IS_OBJECT (event_object), FALSE);
1750 g_return_val_if_fail (event != NULL, FALSE);
1752 g_signal_emit (G_OBJECT (tag),
1764 tag_sort_func (gconstpointer first, gconstpointer second)
1766 GtkTextTag *tag1, *tag2;
1768 tag1 = * (GtkTextTag **) first;
1769 tag2 = * (GtkTextTag **) second;
1770 return tag1->priority - tag2->priority;
1774 _gtk_text_tag_array_sort (GtkTextTag** tag_array_p,
1779 GtkTextTag **maxPtrPtr, *tmp;
1781 g_return_if_fail (tag_array_p != NULL);
1782 g_return_if_fail (len > 0);
1788 GtkTextTag **iter = tag_array_p;
1790 for (i = len-1; i > 0; i--, iter++) {
1791 maxPtrPtr = tag = iter;
1792 prio = tag[0]->priority;
1793 for (j = i, tag++; j > 0; j--, tag++) {
1794 if (tag[0]->priority < prio) {
1795 prio = tag[0]->priority;
1804 qsort ((void *) tag_array_p, (unsigned) len, sizeof (GtkTextTag *),
1810 printf ("Sorted tag array: \n");
1814 GtkTextTag *t = tag_array_p[i];
1815 printf (" %s priority %d\n", t->name, t->priority);
1828 * gtk_text_attributes_new:
1830 * Creates a #GtkTextAttributes, which describes
1831 * a set of properties on some text.
1833 * Return value: a new #GtkTextAttributes
1836 gtk_text_attributes_new (void)
1838 GtkTextAttributes *values;
1840 values = g_new0 (GtkTextAttributes, 1);
1842 /* 0 is a valid value for most of the struct */
1844 values->refcount = 1;
1846 values->language = gtk_get_default_language ();
1848 values->font_scale = 1.0;
1854 * gtk_text_attributes_copy:
1855 * @src: a #GtkTextAttributes to be copied
1857 * Copies @src and returns a new #GtkTextAttributes.
1859 * Return value: a copy of @src
1862 gtk_text_attributes_copy (GtkTextAttributes *src)
1864 GtkTextAttributes *dest;
1866 dest = gtk_text_attributes_new ();
1867 gtk_text_attributes_copy_values (src, dest);
1873 * gtk_text_attributes_copy_values:
1874 * @src: a #GtkTextAttributes
1875 * @dest: another #GtkTextAttributes
1877 * Copies the values from @src to @dest so that @dest has the same values
1878 * as @src. Frees existing values in @dest.
1881 gtk_text_attributes_copy_values (GtkTextAttributes *src,
1882 GtkTextAttributes *dest)
1884 guint orig_refcount;
1886 g_return_if_fail (!dest->realized);
1893 if (src->appearance.bg_stipple)
1894 gdk_bitmap_ref (src->appearance.bg_stipple);
1896 if (src->appearance.fg_stipple)
1897 gdk_bitmap_ref (src->appearance.fg_stipple);
1901 if (dest->appearance.bg_stipple)
1902 gdk_bitmap_unref (dest->appearance.bg_stipple);
1904 if (dest->appearance.fg_stipple)
1905 gdk_bitmap_unref (dest->appearance.fg_stipple);
1908 pango_font_description_free (dest->font);
1911 orig_refcount = dest->refcount;
1916 dest->tabs = pango_tab_array_copy (src->tabs);
1918 dest->language = src->language;
1921 dest->font = pango_font_description_copy (src->font);
1923 dest->refcount = orig_refcount;
1924 dest->realized = FALSE;
1928 * gtk_text_attributes_ref:
1929 * @values: a #GtkTextAttributes
1931 * Increments the reference count on @values.
1934 gtk_text_attributes_ref (GtkTextAttributes *values)
1936 g_return_if_fail (values != NULL);
1938 values->refcount += 1;
1942 * gtk_text_attributes_unref:
1943 * @values: a #GtkTextAttributes
1945 * Decrements the reference count on @values, freeing the structure
1946 * if the reference count reaches 0.
1949 gtk_text_attributes_unref (GtkTextAttributes *values)
1951 g_return_if_fail (values != NULL);
1952 g_return_if_fail (values->refcount > 0);
1954 values->refcount -= 1;
1956 if (values->refcount == 0)
1958 g_assert (!values->realized);
1960 if (values->appearance.bg_stipple)
1961 gdk_bitmap_unref (values->appearance.bg_stipple);
1963 if (values->appearance.fg_stipple)
1964 gdk_bitmap_unref (values->appearance.fg_stipple);
1967 pango_tab_array_free (values->tabs);
1970 pango_font_description_free (values->font);
1977 _gtk_text_attributes_realize (GtkTextAttributes *values,
1981 g_return_if_fail (values != NULL);
1982 g_return_if_fail (values->refcount > 0);
1983 g_return_if_fail (!values->realized);
1985 /* It is wrong to use this colormap, FIXME */
1986 gdk_colormap_alloc_color (cmap,
1987 &values->appearance.fg_color,
1990 gdk_colormap_alloc_color (cmap,
1991 &values->appearance.bg_color,
1994 values->realized = TRUE;
1998 _gtk_text_attributes_unrealize (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 gdk_colormap_free_colors (cmap,
2007 &values->appearance.fg_color, 1);
2010 gdk_colormap_free_colors (cmap,
2011 &values->appearance.bg_color, 1);
2013 values->appearance.fg_color.pixel = 0;
2014 values->appearance.bg_color.pixel = 0;
2016 values->realized = FALSE;
2020 _gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest,
2026 g_return_if_fail (!dest->realized);
2030 GtkTextTag *tag = tags[n];
2031 GtkTextAttributes *vals = tag->values;
2033 g_assert (tag->table != NULL);
2035 g_assert (tags[n]->priority > tags[n-1]->priority);
2037 if (tag->bg_color_set)
2039 dest->appearance.bg_color = vals->appearance.bg_color;
2041 dest->appearance.draw_bg = TRUE;
2043 if (tag->fg_color_set)
2044 dest->appearance.fg_color = vals->appearance.fg_color;
2046 if (tag->bg_stipple_set)
2048 gdk_bitmap_ref (vals->appearance.bg_stipple);
2049 if (dest->appearance.bg_stipple)
2050 gdk_bitmap_unref (dest->appearance.bg_stipple);
2051 dest->appearance.bg_stipple = vals->appearance.bg_stipple;
2053 dest->appearance.draw_bg = TRUE;
2056 if (tag->fg_stipple_set)
2058 gdk_bitmap_ref (vals->appearance.fg_stipple);
2059 if (dest->appearance.fg_stipple)
2060 gdk_bitmap_unref (dest->appearance.fg_stipple);
2061 dest->appearance.fg_stipple = vals->appearance.fg_stipple;
2067 pango_font_description_merge (dest->font, vals->font, TRUE);
2069 dest->font = pango_font_description_copy (vals->font);
2072 /* multiply all the scales together to get a composite */
2074 dest->font_scale *= vals->font_scale;
2076 if (tag->justification_set)
2077 dest->justification = vals->justification;
2079 if (vals->direction != GTK_TEXT_DIR_NONE)
2080 dest->direction = vals->direction;
2082 if (tag->left_margin_set)
2083 dest->left_margin = vals->left_margin;
2085 if (tag->indent_set)
2086 dest->indent = vals->indent;
2089 dest->appearance.rise = vals->appearance.rise;
2091 if (tag->right_margin_set)
2092 dest->right_margin = vals->right_margin;
2094 if (tag->pixels_above_lines_set)
2095 dest->pixels_above_lines = vals->pixels_above_lines;
2097 if (tag->pixels_below_lines_set)
2098 dest->pixels_below_lines = vals->pixels_below_lines;
2100 if (tag->pixels_inside_wrap_set)
2101 dest->pixels_inside_wrap = vals->pixels_inside_wrap;
2106 pango_tab_array_free (dest->tabs);
2107 dest->tabs = pango_tab_array_copy (vals->tabs);
2110 if (tag->wrap_mode_set)
2111 dest->wrap_mode = vals->wrap_mode;
2113 if (tag->underline_set)
2114 dest->appearance.underline = vals->appearance.underline;
2116 if (tag->strikethrough_set)
2117 dest->appearance.strikethrough = vals->appearance.strikethrough;
2119 if (tag->invisible_set)
2120 dest->invisible = vals->invisible;
2122 if (tag->editable_set)
2123 dest->editable = vals->editable;
2125 if (tag->bg_full_height_set)
2126 dest->bg_full_height = vals->bg_full_height;
2128 if (tag->language_set)
2129 dest->language = vals->language;
2136 _gtk_text_tag_affects_size (GtkTextTag *tag)
2138 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
2141 (tag->values->font && pango_font_description_get_set_fields (tag->values->font) != 0) ||
2143 tag->justification_set ||
2144 tag->left_margin_set ||
2147 tag->right_margin_set ||
2148 tag->pixels_above_lines_set ||
2149 tag->pixels_below_lines_set ||
2150 tag->pixels_inside_wrap_set ||
2152 tag->underline_set ||
2153 tag->wrap_mode_set ||
2158 _gtk_text_tag_affects_nonsize_appearance (GtkTextTag *tag)
2160 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
2163 tag->bg_color_set ||
2164 tag->bg_stipple_set ||
2165 tag->fg_color_set ||
2166 tag->fg_stipple_set ||
2167 tag->strikethrough_set ||
2168 tag->bg_full_height_set;