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"
58 #include "gtkprivate.h"
79 PROP_BACKGROUND_STIPPLE,
80 PROP_FOREGROUND_STIPPLE,
91 PROP_PIXELS_ABOVE_LINES,
92 PROP_PIXELS_BELOW_LINES,
93 PROP_PIXELS_INSIDE_WRAP,
104 PROP_BACKGROUND_FULL_HEIGHT,
108 PROP_PARAGRAPH_BACKGROUND,
109 PROP_PARAGRAPH_BACKGROUND_GDK,
111 /* Whether-a-style-arg-is-set args */
114 PROP_BACKGROUND_STIPPLE_SET,
115 PROP_FOREGROUND_STIPPLE_SET,
123 PROP_PIXELS_ABOVE_LINES_SET,
124 PROP_PIXELS_BELOW_LINES_SET,
125 PROP_PIXELS_INSIDE_WRAP_SET,
128 PROP_JUSTIFICATION_SET,
129 PROP_LEFT_MARGIN_SET,
131 PROP_STRIKETHROUGH_SET,
132 PROP_RIGHT_MARGIN_SET,
135 PROP_BACKGROUND_FULL_HEIGHT_SET,
139 PROP_PARAGRAPH_BACKGROUND_SET,
143 static void gtk_text_tag_init (GtkTextTag *text_tag);
144 static void gtk_text_tag_class_init (GtkTextTagClass *klass);
145 static void gtk_text_tag_finalize (GObject *object);
146 static void gtk_text_tag_set_property (GObject *object,
150 static void gtk_text_tag_get_property (GObject *object,
155 static GObjectClass *parent_class = NULL;
156 static guint signals[LAST_SIGNAL] = { 0 };
159 gtk_text_tag_get_type (void)
161 static GType our_type = 0;
165 static const GTypeInfo our_info =
167 sizeof (GtkTextTagClass),
168 (GBaseInitFunc) NULL,
169 (GBaseFinalizeFunc) NULL,
170 (GClassInitFunc) gtk_text_tag_class_init,
171 NULL, /* class_finalize */
172 NULL, /* class_data */
175 (GInstanceInitFunc) gtk_text_tag_init
178 our_type = g_type_register_static (G_TYPE_OBJECT, I_("GtkTextTag"),
186 gtk_text_tag_class_init (GtkTextTagClass *klass)
188 GObjectClass *object_class = G_OBJECT_CLASS (klass);
190 parent_class = g_type_class_peek_parent (klass);
192 object_class->set_property = gtk_text_tag_set_property;
193 object_class->get_property = gtk_text_tag_get_property;
195 object_class->finalize = gtk_text_tag_finalize;
198 g_object_class_install_property (object_class,
200 g_param_spec_string ("name",
202 P_("Name used to refer to the text tag. NULL for anonymous tags"),
204 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
208 g_object_class_install_property (object_class,
210 g_param_spec_string ("background",
211 P_("Background color name"),
212 P_("Background color as a string"),
214 GTK_PARAM_WRITABLE));
216 g_object_class_install_property (object_class,
218 g_param_spec_boxed ("background-gdk",
219 P_("Background color"),
220 P_("Background color as a (possibly unallocated) GdkColor"),
222 GTK_PARAM_READWRITE));
224 g_object_class_install_property (object_class,
225 PROP_BACKGROUND_FULL_HEIGHT,
226 g_param_spec_boolean ("background-full-height",
227 P_("Background full height"),
228 P_("Whether the background color fills the entire line height or only the height of the tagged characters"),
230 GTK_PARAM_READWRITE));
233 g_object_class_install_property (object_class,
234 PROP_BACKGROUND_STIPPLE,
235 g_param_spec_object ("background-stipple",
236 P_("Background stipple mask"),
237 P_("Bitmap to use as a mask when drawing the text background"),
239 GTK_PARAM_READWRITE));
242 g_object_class_install_property (object_class,
244 g_param_spec_string ("foreground",
245 P_("Foreground color name"),
246 P_("Foreground color as a string"),
248 GTK_PARAM_WRITABLE));
250 g_object_class_install_property (object_class,
252 g_param_spec_boxed ("foreground-gdk",
253 P_("Foreground color"),
254 P_("Foreground color as a (possibly unallocated) GdkColor"),
256 GTK_PARAM_READWRITE));
259 g_object_class_install_property (object_class,
260 PROP_FOREGROUND_STIPPLE,
261 g_param_spec_object ("foreground-stipple",
262 P_("Foreground stipple mask"),
263 P_("Bitmap to use as a mask when drawing the text foreground"),
265 GTK_PARAM_READWRITE));
267 g_object_class_install_property (object_class,
269 g_param_spec_enum ("direction",
270 P_("Text direction"),
271 P_("Text direction, e.g. right-to-left or left-to-right"),
272 GTK_TYPE_TEXT_DIRECTION,
274 GTK_PARAM_READWRITE));
276 g_object_class_install_property (object_class,
278 g_param_spec_boolean ("editable",
280 P_("Whether the text can be modified by the user"),
282 GTK_PARAM_READWRITE));
284 g_object_class_install_property (object_class,
286 g_param_spec_string ("font",
288 P_("Font description as a string, e.g. \"Sans Italic 12\""),
290 GTK_PARAM_READWRITE));
292 g_object_class_install_property (object_class,
294 g_param_spec_boxed ("font-desc",
296 P_("Font description as a PangoFontDescription struct"),
297 PANGO_TYPE_FONT_DESCRIPTION,
298 GTK_PARAM_READWRITE));
301 g_object_class_install_property (object_class,
303 g_param_spec_string ("family",
305 P_("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
307 GTK_PARAM_READWRITE));
309 g_object_class_install_property (object_class,
311 g_param_spec_enum ("style",
313 P_("Font style as a PangoStyle, e.g. PANGO_STYLE_ITALIC"),
316 GTK_PARAM_READWRITE));
318 g_object_class_install_property (object_class,
320 g_param_spec_enum ("variant",
322 P_("Font variant as a PangoVariant, e.g. PANGO_VARIANT_SMALL_CAPS"),
324 PANGO_VARIANT_NORMAL,
325 GTK_PARAM_READWRITE));
327 g_object_class_install_property (object_class,
329 g_param_spec_int ("weight",
331 P_("Font weight as an integer, see predefined values in PangoWeight; for example, PANGO_WEIGHT_BOLD"),
335 GTK_PARAM_READWRITE));
338 g_object_class_install_property (object_class,
340 g_param_spec_enum ("stretch",
342 P_("Font stretch as a PangoStretch, e.g. PANGO_STRETCH_CONDENSED"),
344 PANGO_STRETCH_NORMAL,
345 GTK_PARAM_READWRITE));
347 g_object_class_install_property (object_class,
349 g_param_spec_int ("size",
351 P_("Font size in Pango units"),
355 GTK_PARAM_READWRITE));
357 g_object_class_install_property (object_class,
359 g_param_spec_double ("scale",
361 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"),
365 GTK_PARAM_READWRITE));
367 g_object_class_install_property (object_class,
369 g_param_spec_double ("size-points",
371 P_("Font size in points"),
375 GTK_PARAM_READWRITE));
377 g_object_class_install_property (object_class,
379 g_param_spec_enum ("justification",
381 P_("Left, right, or center justification"),
382 GTK_TYPE_JUSTIFICATION,
384 GTK_PARAM_READWRITE));
386 g_object_class_install_property (object_class,
388 g_param_spec_string ("language",
390 P_("The language this text is in, as an ISO code. Pango can use this as a hint when rendering the text. If not set, an appropriate default will be used."),
392 GTK_PARAM_READWRITE));
394 g_object_class_install_property (object_class,
396 g_param_spec_int ("left-margin",
398 P_("Width of the left margin in pixels"),
402 GTK_PARAM_READWRITE));
404 g_object_class_install_property (object_class,
406 g_param_spec_int ("right-margin",
408 P_("Width of the right margin in pixels"),
412 GTK_PARAM_READWRITE));
415 g_object_class_install_property (object_class,
417 g_param_spec_int ("indent",
419 P_("Amount to indent the paragraph, in pixels"),
423 GTK_PARAM_READWRITE));
426 g_object_class_install_property (object_class,
428 g_param_spec_int ("rise",
430 P_("Offset of text above the baseline (below the baseline if rise is negative) in Pango units"),
434 GTK_PARAM_READWRITE));
436 g_object_class_install_property (object_class,
437 PROP_PIXELS_ABOVE_LINES,
438 g_param_spec_int ("pixels-above-lines",
439 P_("Pixels above lines"),
440 P_("Pixels of blank space above paragraphs"),
444 GTK_PARAM_READWRITE));
446 g_object_class_install_property (object_class,
447 PROP_PIXELS_BELOW_LINES,
448 g_param_spec_int ("pixels-below-lines",
449 P_("Pixels below lines"),
450 P_("Pixels of blank space below paragraphs"),
454 GTK_PARAM_READWRITE));
456 g_object_class_install_property (object_class,
457 PROP_PIXELS_INSIDE_WRAP,
458 g_param_spec_int ("pixels-inside-wrap",
459 P_("Pixels inside wrap"),
460 P_("Pixels of blank space between wrapped lines in a paragraph"),
464 GTK_PARAM_READWRITE));
466 g_object_class_install_property (object_class,
468 g_param_spec_boolean ("strikethrough",
470 P_("Whether to strike through the text"),
472 GTK_PARAM_READWRITE));
474 g_object_class_install_property (object_class,
476 g_param_spec_enum ("underline",
478 P_("Style of underline for this text"),
479 PANGO_TYPE_UNDERLINE,
480 PANGO_UNDERLINE_NONE,
481 GTK_PARAM_READWRITE));
483 g_object_class_install_property (object_class,
485 g_param_spec_enum ("wrap-mode",
487 P_("Whether to wrap lines never, at word boundaries, or at character boundaries"),
490 GTK_PARAM_READWRITE));
493 g_object_class_install_property (object_class,
495 g_param_spec_boxed ("tabs",
497 P_("Custom tabs for this text"),
498 PANGO_TYPE_TAB_ARRAY,
499 GTK_PARAM_READWRITE));
502 * GtkTextTag:invisible:
504 * Whether this text is hidden.
506 * Note that there may still be problems with the support for invisible
507 * text, in particular when navigating programmatically inside a buffer
508 * containing invisible segments.
512 g_object_class_install_property (object_class,
514 g_param_spec_boolean ("invisible",
516 P_("Whether this text is hidden."),
518 GTK_PARAM_READWRITE));
521 * GtkTextTag:paragraph-background:
523 * The paragraph background color as a string.
527 g_object_class_install_property (object_class,
528 PROP_PARAGRAPH_BACKGROUND,
529 g_param_spec_string ("paragraph-background",
530 P_("Paragraph background color name"),
531 P_("Paragraph background color as a string"),
533 GTK_PARAM_WRITABLE));
536 * GtkTextTag:paragraph-background-gdk:
538 * The paragraph background color as a as a (possibly unallocated)
543 g_object_class_install_property (object_class,
544 PROP_PARAGRAPH_BACKGROUND_GDK,
545 g_param_spec_boxed ("paragraph-background-gdk",
546 P_("Paragraph background color"),
547 P_("Paragraph background color as a (possibly unallocated) GdkColor"),
549 GTK_PARAM_READWRITE));
551 /* Style props are set or not */
553 #define ADD_SET_PROP(propname, propval, nick, blurb) g_object_class_install_property (object_class, propval, g_param_spec_boolean (propname, nick, blurb, FALSE, GTK_PARAM_READWRITE))
555 ADD_SET_PROP ("background-set", PROP_BACKGROUND_SET,
556 P_("Background set"),
557 P_("Whether this tag affects the background color"));
559 ADD_SET_PROP ("background-full-height-set", PROP_BACKGROUND_FULL_HEIGHT_SET,
560 P_("Background full height set"),
561 P_("Whether this tag affects background height"));
563 ADD_SET_PROP ("background-stipple-set", PROP_BACKGROUND_STIPPLE_SET,
564 P_("Background stipple set"),
565 P_("Whether this tag affects the background stipple"));
567 ADD_SET_PROP ("foreground-set", PROP_FOREGROUND_SET,
568 P_("Foreground set"),
569 P_("Whether this tag affects the foreground color"));
571 ADD_SET_PROP ("foreground-stipple-set", PROP_FOREGROUND_STIPPLE_SET,
572 P_("Foreground stipple set"),
573 P_("Whether this tag affects the foreground stipple"));
575 ADD_SET_PROP ("editable-set", PROP_EDITABLE_SET,
576 P_("Editability set"),
577 P_("Whether this tag affects text editability"));
579 ADD_SET_PROP ("family-set", PROP_FAMILY_SET,
580 P_("Font family set"),
581 P_("Whether this tag affects the font family"));
583 ADD_SET_PROP ("style-set", PROP_STYLE_SET,
584 P_("Font style set"),
585 P_("Whether this tag affects the font style"));
587 ADD_SET_PROP ("variant-set", PROP_VARIANT_SET,
588 P_("Font variant set"),
589 P_("Whether this tag affects the font variant"));
591 ADD_SET_PROP ("weight-set", PROP_WEIGHT_SET,
592 P_("Font weight set"),
593 P_("Whether this tag affects the font weight"));
595 ADD_SET_PROP ("stretch-set", PROP_STRETCH_SET,
596 P_("Font stretch set"),
597 P_("Whether this tag affects the font stretch"));
599 ADD_SET_PROP ("size-set", PROP_SIZE_SET,
601 P_("Whether this tag affects the font size"));
603 ADD_SET_PROP ("scale-set", PROP_SCALE_SET,
604 P_("Font scale set"),
605 P_("Whether this tag scales the font size by a factor"));
607 ADD_SET_PROP ("justification-set", PROP_JUSTIFICATION_SET,
608 P_("Justification set"),
609 P_("Whether this tag affects paragraph justification"));
611 ADD_SET_PROP ("language-set", PROP_LANGUAGE_SET,
613 P_("Whether this tag affects the language the text is rendered as"));
615 ADD_SET_PROP ("left-margin-set", PROP_LEFT_MARGIN_SET,
616 P_("Left margin set"),
617 P_("Whether this tag affects the left margin"));
619 ADD_SET_PROP ("indent-set", PROP_INDENT_SET,
621 P_("Whether this tag affects indentation"));
623 ADD_SET_PROP ("rise-set", PROP_RISE_SET,
625 P_("Whether this tag affects the rise"));
627 ADD_SET_PROP ("pixels-above-lines-set", PROP_PIXELS_ABOVE_LINES_SET,
628 P_("Pixels above lines set"),
629 P_("Whether this tag affects the number of pixels above lines"));
631 ADD_SET_PROP ("pixels-below-lines-set", PROP_PIXELS_BELOW_LINES_SET,
632 P_("Pixels below lines set"),
633 P_("Whether this tag affects the number of pixels above lines"));
635 ADD_SET_PROP ("pixels-inside-wrap-set", PROP_PIXELS_INSIDE_WRAP_SET,
636 P_("Pixels inside wrap set"),
637 P_("Whether this tag affects the number of pixels between wrapped lines"));
639 ADD_SET_PROP ("strikethrough-set", PROP_STRIKETHROUGH_SET,
640 P_("Strikethrough set"),
641 P_("Whether this tag affects strikethrough"));
643 ADD_SET_PROP ("right-margin-set", PROP_RIGHT_MARGIN_SET,
644 P_("Right margin set"),
645 P_("Whether this tag affects the right margin"));
647 ADD_SET_PROP ("underline-set", PROP_UNDERLINE_SET,
649 P_("Whether this tag affects underlining"));
651 ADD_SET_PROP ("wrap-mode-set", PROP_WRAP_MODE_SET,
653 P_("Whether this tag affects line wrap mode"));
655 ADD_SET_PROP ("tabs-set", PROP_TABS_SET,
657 P_("Whether this tag affects tabs"));
659 ADD_SET_PROP ("invisible-set", PROP_INVISIBLE_SET,
661 P_("Whether this tag affects text visibility"));
663 ADD_SET_PROP ("paragraph-background-set", PROP_PARAGRAPH_BACKGROUND_SET,
664 P_("Paragraph background set"),
665 P_("Whether this tag affects the paragraph background color"));
668 g_signal_new (I_("event"),
669 G_OBJECT_CLASS_TYPE (object_class),
671 G_STRUCT_OFFSET (GtkTextTagClass, event),
672 _gtk_boolean_handled_accumulator, NULL,
673 _gtk_marshal_BOOLEAN__OBJECT_BOXED_BOXED,
677 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE,
682 gtk_text_tag_init (GtkTextTag *text_tag)
684 /* 0 is basically a fine way to initialize everything in the
687 text_tag->values = gtk_text_attributes_new ();
692 * @name: tag name, or %NULL
694 * Creates a #GtkTextTag. Configure the tag using object arguments,
695 * i.e. using g_object_set().
697 * Return value: a new #GtkTextTag
700 gtk_text_tag_new (const gchar *name)
704 tag = g_object_new (GTK_TYPE_TEXT_TAG, "name", name, NULL);
710 gtk_text_tag_finalize (GObject *object)
712 GtkTextTag *text_tag;
714 text_tag = GTK_TEXT_TAG (object);
716 g_assert (!text_tag->values->realized);
719 gtk_text_tag_table_remove (text_tag->table, text_tag);
721 g_assert (text_tag->table == NULL);
723 gtk_text_attributes_unref (text_tag->values);
724 text_tag->values = NULL;
726 g_free (text_tag->name);
727 text_tag->name = NULL;
729 (* G_OBJECT_CLASS (parent_class)->finalize) (object);
733 set_bg_color (GtkTextTag *tag, GdkColor *color)
737 if (!tag->bg_color_set)
739 tag->bg_color_set = TRUE;
740 g_object_notify (G_OBJECT (tag), "background-set");
743 tag->values->appearance.bg_color = *color;
747 if (tag->bg_color_set)
749 tag->bg_color_set = FALSE;
750 g_object_notify (G_OBJECT (tag), "background-set");
756 set_fg_color (GtkTextTag *tag, GdkColor *color)
760 if (!tag->fg_color_set)
762 tag->fg_color_set = TRUE;
763 g_object_notify (G_OBJECT (tag), "foreground-set");
765 tag->values->appearance.fg_color = *color;
769 if (tag->fg_color_set)
771 tag->fg_color_set = FALSE;
772 g_object_notify (G_OBJECT (tag), "foreground-set");
778 set_pg_bg_color (GtkTextTag *tag, GdkColor *color)
782 if (!tag->pg_bg_color_set)
784 tag->pg_bg_color_set = TRUE;
785 g_object_notify (G_OBJECT (tag), "paragraph-background-set");
788 gdk_color_free (tag->values->pg_bg_color);
790 tag->values->pg_bg_color = gdk_color_copy (color);
794 if (tag->pg_bg_color_set)
796 tag->pg_bg_color_set = FALSE;
797 g_object_notify (G_OBJECT (tag), "paragraph-background-set");
798 gdk_color_free (tag->values->pg_bg_color);
801 tag->values->pg_bg_color = NULL;
806 get_property_font_set_mask (guint prop_id)
810 case PROP_FAMILY_SET:
811 return PANGO_FONT_MASK_FAMILY;
813 return PANGO_FONT_MASK_STYLE;
814 case PROP_VARIANT_SET:
815 return PANGO_FONT_MASK_VARIANT;
816 case PROP_WEIGHT_SET:
817 return PANGO_FONT_MASK_WEIGHT;
818 case PROP_STRETCH_SET:
819 return PANGO_FONT_MASK_STRETCH;
821 return PANGO_FONT_MASK_SIZE;
828 set_font_desc_fields (PangoFontDescription *desc,
829 PangoFontMask to_set)
831 PangoFontMask changed_mask = 0;
833 if (to_set & PANGO_FONT_MASK_FAMILY)
835 const char *family = pango_font_description_get_family (desc);
839 changed_mask |= PANGO_FONT_MASK_FAMILY;
842 pango_font_description_set_family (desc, family);
844 if (to_set & PANGO_FONT_MASK_STYLE)
845 pango_font_description_set_style (desc, pango_font_description_get_style (desc));
846 if (to_set & PANGO_FONT_MASK_VARIANT)
847 pango_font_description_set_variant (desc, pango_font_description_get_variant (desc));
848 if (to_set & PANGO_FONT_MASK_WEIGHT)
849 pango_font_description_set_weight (desc, pango_font_description_get_weight (desc));
850 if (to_set & PANGO_FONT_MASK_STRETCH)
851 pango_font_description_set_stretch (desc, pango_font_description_get_stretch (desc));
852 if (to_set & PANGO_FONT_MASK_SIZE)
854 gint size = pango_font_description_get_size (desc);
857 size = 10 * PANGO_SCALE;
858 changed_mask |= PANGO_FONT_MASK_SIZE;
861 pango_font_description_set_size (desc, size);
868 notify_set_changed (GObject *object,
869 PangoFontMask changed_mask)
871 if (changed_mask & PANGO_FONT_MASK_FAMILY)
872 g_object_notify (object, "family-set");
873 if (changed_mask & PANGO_FONT_MASK_STYLE)
874 g_object_notify (object, "style-set");
875 if (changed_mask & PANGO_FONT_MASK_VARIANT)
876 g_object_notify (object, "variant-set");
877 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
878 g_object_notify (object, "weight-set");
879 if (changed_mask & PANGO_FONT_MASK_STRETCH)
880 g_object_notify (object, "stretch-set");
881 if (changed_mask & PANGO_FONT_MASK_SIZE)
882 g_object_notify (object, "size-set");
886 notify_fields_changed (GObject *object,
887 PangoFontMask changed_mask)
889 if (changed_mask & PANGO_FONT_MASK_FAMILY)
890 g_object_notify (object, "family");
891 if (changed_mask & PANGO_FONT_MASK_STYLE)
892 g_object_notify (object, "style");
893 if (changed_mask & PANGO_FONT_MASK_VARIANT)
894 g_object_notify (object, "variant");
895 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
896 g_object_notify (object, "weight");
897 if (changed_mask & PANGO_FONT_MASK_STRETCH)
898 g_object_notify (object, "stretch");
899 if (changed_mask & PANGO_FONT_MASK_SIZE)
900 g_object_notify (object, "size");
904 set_font_description (GtkTextTag *text_tag,
905 PangoFontDescription *font_desc)
907 GObject *object = G_OBJECT (text_tag);
908 PangoFontDescription *new_font_desc;
909 PangoFontMask old_mask, new_mask, changed_mask, set_changed_mask;
912 new_font_desc = pango_font_description_copy (font_desc);
914 new_font_desc = pango_font_description_new ();
916 if (text_tag->values->font)
917 old_mask = pango_font_description_get_set_fields (text_tag->values->font);
921 new_mask = pango_font_description_get_set_fields (new_font_desc);
923 changed_mask = old_mask | new_mask;
924 set_changed_mask = old_mask ^ new_mask;
926 if (text_tag->values->font)
927 pango_font_description_free (text_tag->values->font);
928 text_tag->values->font = new_font_desc;
930 g_object_freeze_notify (object);
932 g_object_notify (object, "font-desc");
933 g_object_notify (object, "font");
935 if (changed_mask & PANGO_FONT_MASK_FAMILY)
936 g_object_notify (object, "family");
937 if (changed_mask & PANGO_FONT_MASK_STYLE)
938 g_object_notify (object, "style");
939 if (changed_mask & PANGO_FONT_MASK_VARIANT)
940 g_object_notify (object, "variant");
941 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
942 g_object_notify (object, "weight");
943 if (changed_mask & PANGO_FONT_MASK_STRETCH)
944 g_object_notify (object, "stretch");
945 if (changed_mask & PANGO_FONT_MASK_SIZE)
947 g_object_notify (object, "size");
948 g_object_notify (object, "size-points");
951 notify_set_changed (object, set_changed_mask);
953 g_object_thaw_notify (object);
957 gtk_text_tag_ensure_font (GtkTextTag *text_tag)
959 if (!text_tag->values->font)
960 text_tag->values->font = pango_font_description_new ();
964 gtk_text_tag_set_property (GObject *object,
969 GtkTextTag *text_tag;
970 gboolean size_changed = FALSE;
972 text_tag = GTK_TEXT_TAG (object);
974 g_return_if_fail (!text_tag->values->realized);
979 g_return_if_fail (text_tag->name == NULL);
980 text_tag->name = g_strdup (g_value_get_string (value));
983 case PROP_BACKGROUND:
987 if (gdk_color_parse (g_value_get_string (value), &color))
988 set_bg_color (text_tag, &color);
990 g_warning ("Don't know color `%s'", g_value_get_string (value));
992 g_object_notify (object, "background-gdk");
996 case PROP_FOREGROUND:
1000 if (gdk_color_parse (g_value_get_string (value), &color))
1001 set_fg_color (text_tag, &color);
1003 g_warning ("Don't know color `%s'", g_value_get_string (value));
1005 g_object_notify (object, "foreground-gdk");
1009 case PROP_BACKGROUND_GDK:
1011 GdkColor *color = g_value_get_boxed (value);
1013 set_bg_color (text_tag, color);
1017 case PROP_FOREGROUND_GDK:
1019 GdkColor *color = g_value_get_boxed (value);
1021 set_fg_color (text_tag, color);
1025 case PROP_BACKGROUND_STIPPLE:
1027 GdkBitmap *bitmap = g_value_get_object (value);
1029 text_tag->bg_stipple_set = TRUE;
1030 g_object_notify (object, "background-stipple-set");
1032 if (text_tag->values->appearance.bg_stipple != bitmap)
1035 g_object_ref (bitmap);
1037 if (text_tag->values->appearance.bg_stipple)
1038 g_object_unref (text_tag->values->appearance.bg_stipple);
1040 text_tag->values->appearance.bg_stipple = bitmap;
1045 case PROP_FOREGROUND_STIPPLE:
1047 GdkBitmap *bitmap = g_value_get_object (value);
1049 text_tag->fg_stipple_set = TRUE;
1050 g_object_notify (object, "foreground-stipple-set");
1052 if (text_tag->values->appearance.fg_stipple != bitmap)
1055 g_object_ref (bitmap);
1057 if (text_tag->values->appearance.fg_stipple)
1058 g_object_unref (text_tag->values->appearance.fg_stipple);
1060 text_tag->values->appearance.fg_stipple = bitmap;
1067 PangoFontDescription *font_desc = NULL;
1070 name = g_value_get_string (value);
1073 font_desc = pango_font_description_from_string (name);
1075 set_font_description (text_tag, font_desc);
1077 pango_font_description_free (font_desc);
1079 size_changed = TRUE;
1083 case PROP_FONT_DESC:
1085 PangoFontDescription *font_desc;
1087 font_desc = g_value_get_boxed (value);
1089 set_font_description (text_tag, font_desc);
1091 size_changed = TRUE;
1101 case PROP_SIZE_POINTS:
1103 PangoFontMask old_set_mask;
1105 gtk_text_tag_ensure_font (text_tag);
1106 old_set_mask = pango_font_description_get_set_fields (text_tag->values->font);
1111 pango_font_description_set_family (text_tag->values->font,
1112 g_value_get_string (value));
1115 pango_font_description_set_style (text_tag->values->font,
1116 g_value_get_enum (value));
1119 pango_font_description_set_variant (text_tag->values->font,
1120 g_value_get_enum (value));
1123 pango_font_description_set_weight (text_tag->values->font,
1124 g_value_get_int (value));
1127 pango_font_description_set_stretch (text_tag->values->font,
1128 g_value_get_enum (value));
1131 pango_font_description_set_size (text_tag->values->font,
1132 g_value_get_int (value));
1133 g_object_notify (object, "size-points");
1135 case PROP_SIZE_POINTS:
1136 pango_font_description_set_size (text_tag->values->font,
1137 g_value_get_double (value) * PANGO_SCALE);
1138 g_object_notify (object, "size");
1142 size_changed = TRUE;
1143 notify_set_changed (object, old_set_mask & pango_font_description_get_set_fields (text_tag->values->font));
1144 g_object_notify (object, "font-desc");
1145 g_object_notify (object, "font");
1151 text_tag->values->font_scale = g_value_get_double (value);
1152 text_tag->scale_set = TRUE;
1153 g_object_notify (object, "scale-set");
1154 size_changed = TRUE;
1157 case PROP_PIXELS_ABOVE_LINES:
1158 text_tag->pixels_above_lines_set = TRUE;
1159 text_tag->values->pixels_above_lines = g_value_get_int (value);
1160 g_object_notify (object, "pixels-above-lines-set");
1161 size_changed = TRUE;
1164 case PROP_PIXELS_BELOW_LINES:
1165 text_tag->pixels_below_lines_set = TRUE;
1166 text_tag->values->pixels_below_lines = g_value_get_int (value);
1167 g_object_notify (object, "pixels-below-lines-set");
1168 size_changed = TRUE;
1171 case PROP_PIXELS_INSIDE_WRAP:
1172 text_tag->pixels_inside_wrap_set = TRUE;
1173 text_tag->values->pixels_inside_wrap = g_value_get_int (value);
1174 g_object_notify (object, "pixels-inside-wrap-set");
1175 size_changed = TRUE;
1179 text_tag->editable_set = TRUE;
1180 text_tag->values->editable = g_value_get_boolean (value);
1181 g_object_notify (object, "editable-set");
1184 case PROP_WRAP_MODE:
1185 text_tag->wrap_mode_set = TRUE;
1186 text_tag->values->wrap_mode = g_value_get_enum (value);
1187 g_object_notify (object, "wrap-mode-set");
1188 size_changed = TRUE;
1191 case PROP_JUSTIFICATION:
1192 text_tag->justification_set = TRUE;
1193 text_tag->values->justification = g_value_get_enum (value);
1194 g_object_notify (object, "justification-set");
1195 size_changed = TRUE;
1198 case PROP_DIRECTION:
1199 text_tag->values->direction = g_value_get_enum (value);
1202 case PROP_LEFT_MARGIN:
1203 text_tag->left_margin_set = TRUE;
1204 text_tag->values->left_margin = g_value_get_int (value);
1205 g_object_notify (object, "left-margin-set");
1206 size_changed = TRUE;
1210 text_tag->indent_set = TRUE;
1211 text_tag->values->indent = g_value_get_int (value);
1212 g_object_notify (object, "indent-set");
1213 size_changed = TRUE;
1216 case PROP_STRIKETHROUGH:
1217 text_tag->strikethrough_set = TRUE;
1218 text_tag->values->appearance.strikethrough = g_value_get_boolean (value);
1219 g_object_notify (object, "strikethrough-set");
1222 case PROP_RIGHT_MARGIN:
1223 text_tag->right_margin_set = TRUE;
1224 text_tag->values->right_margin = g_value_get_int (value);
1225 g_object_notify (object, "right-margin-set");
1226 size_changed = TRUE;
1229 case PROP_UNDERLINE:
1230 text_tag->underline_set = TRUE;
1231 text_tag->values->appearance.underline = g_value_get_enum (value);
1232 g_object_notify (object, "underline-set");
1236 text_tag->rise_set = TRUE;
1237 text_tag->values->appearance.rise = g_value_get_int (value);
1238 g_object_notify (object, "rise-set");
1239 size_changed = TRUE;
1242 case PROP_BACKGROUND_FULL_HEIGHT:
1243 text_tag->bg_full_height_set = TRUE;
1244 text_tag->values->bg_full_height = g_value_get_boolean (value);
1245 g_object_notify (object, "background-full-height-set");
1249 text_tag->language_set = TRUE;
1250 text_tag->values->language = pango_language_from_string (g_value_get_string (value));
1251 g_object_notify (object, "language-set");
1255 text_tag->tabs_set = TRUE;
1257 if (text_tag->values->tabs)
1258 pango_tab_array_free (text_tag->values->tabs);
1260 /* FIXME I'm not sure if this is a memleak or not */
1261 text_tag->values->tabs =
1262 pango_tab_array_copy (g_value_get_boxed (value));
1264 g_object_notify (object, "tabs-set");
1266 size_changed = TRUE;
1269 case PROP_INVISIBLE:
1270 text_tag->invisible_set = TRUE;
1271 text_tag->values->invisible = g_value_get_boolean (value);
1272 g_object_notify (object, "invisible-set");
1273 size_changed = TRUE;
1276 case PROP_PARAGRAPH_BACKGROUND:
1280 if (gdk_color_parse (g_value_get_string (value), &color))
1281 set_pg_bg_color (text_tag, &color);
1283 g_warning ("Don't know color `%s'", g_value_get_string (value));
1285 g_object_notify (object, "paragraph-background-gdk");
1289 case PROP_PARAGRAPH_BACKGROUND_GDK:
1291 GdkColor *color = g_value_get_boxed (value);
1293 set_pg_bg_color (text_tag, color);
1297 /* Whether the value should be used... */
1299 case PROP_BACKGROUND_SET:
1300 text_tag->bg_color_set = g_value_get_boolean (value);
1303 case PROP_FOREGROUND_SET:
1304 text_tag->fg_color_set = g_value_get_boolean (value);
1307 case PROP_BACKGROUND_STIPPLE_SET:
1308 text_tag->bg_stipple_set = g_value_get_boolean (value);
1309 if (!text_tag->bg_stipple_set &&
1310 text_tag->values->appearance.bg_stipple)
1312 g_object_unref (text_tag->values->appearance.bg_stipple);
1313 text_tag->values->appearance.bg_stipple = NULL;
1317 case PROP_FOREGROUND_STIPPLE_SET:
1318 text_tag->fg_stipple_set = g_value_get_boolean (value);
1319 if (!text_tag->fg_stipple_set &&
1320 text_tag->values->appearance.fg_stipple)
1322 g_object_unref (text_tag->values->appearance.fg_stipple);
1323 text_tag->values->appearance.fg_stipple = NULL;
1327 case PROP_FAMILY_SET:
1328 case PROP_STYLE_SET:
1329 case PROP_VARIANT_SET:
1330 case PROP_WEIGHT_SET:
1331 case PROP_STRETCH_SET:
1333 if (!g_value_get_boolean (value))
1335 if (text_tag->values->font)
1336 pango_font_description_unset_fields (text_tag->values->font,
1337 get_property_font_set_mask (prop_id));
1341 PangoFontMask changed_mask;
1343 gtk_text_tag_ensure_font (text_tag);
1344 changed_mask = set_font_desc_fields (text_tag->values->font,
1345 get_property_font_set_mask (prop_id));
1346 notify_fields_changed (G_OBJECT (text_tag), changed_mask);
1350 case PROP_SCALE_SET:
1351 text_tag->scale_set = g_value_get_boolean (value);
1352 size_changed = TRUE;
1355 case PROP_PIXELS_ABOVE_LINES_SET:
1356 text_tag->pixels_above_lines_set = g_value_get_boolean (value);
1357 size_changed = TRUE;
1360 case PROP_PIXELS_BELOW_LINES_SET:
1361 text_tag->pixels_below_lines_set = g_value_get_boolean (value);
1362 size_changed = TRUE;
1365 case PROP_PIXELS_INSIDE_WRAP_SET:
1366 text_tag->pixels_inside_wrap_set = g_value_get_boolean (value);
1367 size_changed = TRUE;
1370 case PROP_EDITABLE_SET:
1371 text_tag->editable_set = g_value_get_boolean (value);
1374 case PROP_WRAP_MODE_SET:
1375 text_tag->wrap_mode_set = g_value_get_boolean (value);
1376 size_changed = TRUE;
1379 case PROP_JUSTIFICATION_SET:
1380 text_tag->justification_set = g_value_get_boolean (value);
1381 size_changed = TRUE;
1384 case PROP_LEFT_MARGIN_SET:
1385 text_tag->left_margin_set = g_value_get_boolean (value);
1386 size_changed = TRUE;
1389 case PROP_INDENT_SET:
1390 text_tag->indent_set = g_value_get_boolean (value);
1391 size_changed = TRUE;
1394 case PROP_STRIKETHROUGH_SET:
1395 text_tag->strikethrough_set = g_value_get_boolean (value);
1398 case PROP_RIGHT_MARGIN_SET:
1399 text_tag->right_margin_set = g_value_get_boolean (value);
1400 size_changed = TRUE;
1403 case PROP_UNDERLINE_SET:
1404 text_tag->underline_set = g_value_get_boolean (value);
1408 text_tag->rise_set = g_value_get_boolean (value);
1409 size_changed = TRUE;
1412 case PROP_BACKGROUND_FULL_HEIGHT_SET:
1413 text_tag->bg_full_height_set = g_value_get_boolean (value);
1416 case PROP_LANGUAGE_SET:
1417 text_tag->language_set = g_value_get_boolean (value);
1418 size_changed = TRUE;
1422 text_tag->tabs_set = g_value_get_boolean (value);
1423 size_changed = TRUE;
1426 case PROP_INVISIBLE_SET:
1427 text_tag->invisible_set = g_value_get_boolean (value);
1428 size_changed = TRUE;
1431 case PROP_PARAGRAPH_BACKGROUND_SET:
1432 text_tag->pg_bg_color_set = g_value_get_boolean (value);
1436 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1440 /* FIXME I would like to do this after all set_property in a single
1441 * g_object_set () have been called. But an idle function won't
1442 * work; we need to emit when the tag is changed, not when we get
1443 * around to the event loop. So blah, we eat some inefficiency.
1446 /* This is also somewhat weird since we emit another object's
1447 * signal here, but the two objects are already tightly bound.
1450 if (text_tag->table)
1451 g_signal_emit_by_name (text_tag->table,
1453 text_tag, size_changed);
1457 gtk_text_tag_get_property (GObject *object,
1464 tag = GTK_TEXT_TAG (object);
1469 g_value_set_string (value, tag->name);
1472 case PROP_BACKGROUND_GDK:
1473 g_value_set_boxed (value, &tag->values->appearance.bg_color);
1476 case PROP_FOREGROUND_GDK:
1477 g_value_set_boxed (value, &tag->values->appearance.fg_color);
1480 case PROP_BACKGROUND_STIPPLE:
1481 if (tag->bg_stipple_set)
1482 g_value_set_object (value, tag->values->appearance.bg_stipple);
1485 case PROP_FOREGROUND_STIPPLE:
1486 if (tag->fg_stipple_set)
1487 g_value_set_object (value, tag->values->appearance.fg_stipple);
1492 /* FIXME GValue imposes a totally gratuitous string copy
1493 * here, we could just hand off string ownership
1497 gtk_text_tag_ensure_font (tag);
1499 str = pango_font_description_to_string (tag->values->font);
1500 g_value_set_string (value, str);
1505 case PROP_FONT_DESC:
1506 gtk_text_tag_ensure_font (tag);
1507 g_value_set_boxed (value, tag->values->font);
1516 case PROP_SIZE_POINTS:
1517 gtk_text_tag_ensure_font (tag);
1521 g_value_set_string (value, pango_font_description_get_family (tag->values->font));
1525 g_value_set_enum (value, pango_font_description_get_style (tag->values->font));
1529 g_value_set_enum (value, pango_font_description_get_variant (tag->values->font));
1533 g_value_set_int (value, pango_font_description_get_weight (tag->values->font));
1537 g_value_set_enum (value, pango_font_description_get_stretch (tag->values->font));
1541 g_value_set_int (value, pango_font_description_get_size (tag->values->font));
1544 case PROP_SIZE_POINTS:
1545 g_value_set_double (value, ((double)pango_font_description_get_size (tag->values->font)) / (double)PANGO_SCALE);
1551 g_value_set_double (value, tag->values->font_scale);
1554 case PROP_PIXELS_ABOVE_LINES:
1555 g_value_set_int (value, tag->values->pixels_above_lines);
1558 case PROP_PIXELS_BELOW_LINES:
1559 g_value_set_int (value, tag->values->pixels_below_lines);
1562 case PROP_PIXELS_INSIDE_WRAP:
1563 g_value_set_int (value, tag->values->pixels_inside_wrap);
1567 g_value_set_boolean (value, tag->values->editable);
1570 case PROP_WRAP_MODE:
1571 g_value_set_enum (value, tag->values->wrap_mode);
1574 case PROP_JUSTIFICATION:
1575 g_value_set_enum (value, tag->values->justification);
1578 case PROP_DIRECTION:
1579 g_value_set_enum (value, tag->values->direction);
1582 case PROP_LEFT_MARGIN:
1583 g_value_set_int (value, tag->values->left_margin);
1587 g_value_set_int (value, tag->values->indent);
1590 case PROP_STRIKETHROUGH:
1591 g_value_set_boolean (value, tag->values->appearance.strikethrough);
1594 case PROP_RIGHT_MARGIN:
1595 g_value_set_int (value, tag->values->right_margin);
1598 case PROP_UNDERLINE:
1599 g_value_set_enum (value, tag->values->appearance.underline);
1603 g_value_set_int (value, tag->values->appearance.rise);
1606 case PROP_BACKGROUND_FULL_HEIGHT:
1607 g_value_set_boolean (value, tag->values->bg_full_height);
1611 g_value_set_string (value, pango_language_to_string (tag->values->language));
1615 if (tag->values->tabs)
1616 g_value_set_boxed (value, tag->values->tabs);
1619 case PROP_INVISIBLE:
1620 g_value_set_boolean (value, tag->values->invisible);
1623 case PROP_PARAGRAPH_BACKGROUND_GDK:
1624 g_value_set_boxed (value, tag->values->pg_bg_color);
1627 case PROP_BACKGROUND_SET:
1628 g_value_set_boolean (value, tag->bg_color_set);
1631 case PROP_FOREGROUND_SET:
1632 g_value_set_boolean (value, tag->fg_color_set);
1635 case PROP_BACKGROUND_STIPPLE_SET:
1636 g_value_set_boolean (value, tag->bg_stipple_set);
1639 case PROP_FOREGROUND_STIPPLE_SET:
1640 g_value_set_boolean (value, tag->fg_stipple_set);
1643 case PROP_FAMILY_SET:
1644 case PROP_STYLE_SET:
1645 case PROP_VARIANT_SET:
1646 case PROP_WEIGHT_SET:
1647 case PROP_STRETCH_SET:
1650 PangoFontMask set_mask = tag->values->font ? pango_font_description_get_set_fields (tag->values->font) : 0;
1651 PangoFontMask test_mask = get_property_font_set_mask (prop_id);
1652 g_value_set_boolean (value, (set_mask & test_mask) != 0);
1657 case PROP_SCALE_SET:
1658 g_value_set_boolean (value, tag->scale_set);
1661 case PROP_PIXELS_ABOVE_LINES_SET:
1662 g_value_set_boolean (value, tag->pixels_above_lines_set);
1665 case PROP_PIXELS_BELOW_LINES_SET:
1666 g_value_set_boolean (value, tag->pixels_below_lines_set);
1669 case PROP_PIXELS_INSIDE_WRAP_SET:
1670 g_value_set_boolean (value, tag->pixels_inside_wrap_set);
1673 case PROP_EDITABLE_SET:
1674 g_value_set_boolean (value, tag->editable_set);
1677 case PROP_WRAP_MODE_SET:
1678 g_value_set_boolean (value, tag->wrap_mode_set);
1681 case PROP_JUSTIFICATION_SET:
1682 g_value_set_boolean (value, tag->justification_set);
1685 case PROP_LEFT_MARGIN_SET:
1686 g_value_set_boolean (value, tag->left_margin_set);
1689 case PROP_INDENT_SET:
1690 g_value_set_boolean (value, tag->indent_set);
1693 case PROP_STRIKETHROUGH_SET:
1694 g_value_set_boolean (value, tag->strikethrough_set);
1697 case PROP_RIGHT_MARGIN_SET:
1698 g_value_set_boolean (value, tag->right_margin_set);
1701 case PROP_UNDERLINE_SET:
1702 g_value_set_boolean (value, tag->underline_set);
1706 g_value_set_boolean (value, tag->rise_set);
1709 case PROP_BACKGROUND_FULL_HEIGHT_SET:
1710 g_value_set_boolean (value, tag->bg_full_height_set);
1713 case PROP_LANGUAGE_SET:
1714 g_value_set_boolean (value, tag->language_set);
1718 g_value_set_boolean (value, tag->tabs_set);
1721 case PROP_INVISIBLE_SET:
1722 g_value_set_boolean (value, tag->invisible_set);
1725 case PROP_PARAGRAPH_BACKGROUND_SET:
1726 g_value_set_boolean (value, tag->pg_bg_color_set);
1729 case PROP_BACKGROUND:
1730 case PROP_FOREGROUND:
1731 case PROP_PARAGRAPH_BACKGROUND:
1732 g_warning ("'foreground', 'background' and 'paragraph_background' properties are not readable, use 'foreground_gdk', 'background_gdk' and 'paragraph_background_gdk'");
1734 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1750 delta_priority_foreach (GtkTextTag *tag, gpointer user_data)
1752 DeltaData *dd = user_data;
1754 if (tag->priority >= dd->low && tag->priority <= dd->high)
1755 tag->priority += dd->delta;
1759 * gtk_text_tag_get_priority:
1760 * @tag: a #GtkTextTag
1762 * Get the tag priority.
1764 * Return value: The tag's priority.
1767 gtk_text_tag_get_priority (GtkTextTag *tag)
1769 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), 0);
1771 return tag->priority;
1775 * gtk_text_tag_set_priority:
1776 * @tag: a #GtkTextTag
1777 * @priority: the new priority
1779 * Sets the priority of a #GtkTextTag. Valid priorities are
1780 * start at 0 and go to one less than gtk_text_tag_table_get_size().
1781 * Each tag in a table has a unique priority; setting the priority
1782 * of one tag shifts the priorities of all the other tags in the
1783 * table to maintain a unique priority for each tag. Higher priority
1784 * tags "win" if two tags both set the same text attribute. When adding
1785 * a tag to a tag table, it will be assigned the highest priority in
1786 * the table by default; so normally the precedence of a set of tags
1787 * is the order in which they were added to the table, or created with
1788 * gtk_text_buffer_create_tag(), which adds the tag to the buffer's table
1792 gtk_text_tag_set_priority (GtkTextTag *tag,
1797 g_return_if_fail (GTK_IS_TEXT_TAG (tag));
1798 g_return_if_fail (tag->table != NULL);
1799 g_return_if_fail (priority >= 0);
1800 g_return_if_fail (priority < gtk_text_tag_table_get_size (tag->table));
1802 if (priority == tag->priority)
1805 if (priority < tag->priority)
1808 dd.high = tag->priority - 1;
1813 dd.low = tag->priority + 1;
1818 gtk_text_tag_table_foreach (tag->table,
1819 delta_priority_foreach,
1822 tag->priority = priority;
1826 * gtk_text_tag_event:
1827 * @tag: a #GtkTextTag
1828 * @event_object: object that received the event, such as a widget
1830 * @iter: location where the event was received
1832 * Emits the "event" signal on the #GtkTextTag.
1834 * Return value: result of signal emission (whether the event was handled)
1837 gtk_text_tag_event (GtkTextTag *tag,
1838 GObject *event_object,
1840 const GtkTextIter *iter)
1842 gboolean retval = FALSE;
1844 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
1845 g_return_val_if_fail (G_IS_OBJECT (event_object), FALSE);
1846 g_return_val_if_fail (event != NULL, FALSE);
1860 tag_sort_func (gconstpointer first, gconstpointer second)
1862 GtkTextTag *tag1, *tag2;
1864 tag1 = * (GtkTextTag **) first;
1865 tag2 = * (GtkTextTag **) second;
1866 return tag1->priority - tag2->priority;
1870 _gtk_text_tag_array_sort (GtkTextTag** tag_array_p,
1875 GtkTextTag **maxPtrPtr, *tmp;
1877 g_return_if_fail (tag_array_p != NULL);
1878 g_return_if_fail (len > 0);
1884 GtkTextTag **iter = tag_array_p;
1886 for (i = len-1; i > 0; i--, iter++) {
1887 maxPtrPtr = tag = iter;
1888 prio = tag[0]->priority;
1889 for (j = i, tag++; j > 0; j--, tag++) {
1890 if (tag[0]->priority < prio) {
1891 prio = tag[0]->priority;
1900 qsort ((void *) tag_array_p, (unsigned) len, sizeof (GtkTextTag *),
1906 printf ("Sorted tag array: \n");
1910 GtkTextTag *t = tag_array_p[i];
1911 printf (" %s priority %d\n", t->name, t->priority);
1924 * gtk_text_attributes_new:
1926 * Creates a #GtkTextAttributes, which describes
1927 * a set of properties on some text.
1929 * Return value: a new #GtkTextAttributes
1932 gtk_text_attributes_new (void)
1934 GtkTextAttributes *values;
1936 values = g_new0 (GtkTextAttributes, 1);
1938 /* 0 is a valid value for most of the struct */
1940 values->refcount = 1;
1942 values->language = gtk_get_default_language ();
1944 values->font_scale = 1.0;
1950 * gtk_text_attributes_copy:
1951 * @src: a #GtkTextAttributes to be copied
1953 * Copies @src and returns a new #GtkTextAttributes.
1955 * Return value: a copy of @src
1958 gtk_text_attributes_copy (GtkTextAttributes *src)
1960 GtkTextAttributes *dest;
1962 dest = gtk_text_attributes_new ();
1963 gtk_text_attributes_copy_values (src, dest);
1969 gtk_text_attributes_get_type (void)
1971 static GType our_type = 0;
1974 our_type = g_boxed_type_register_static (I_("GtkTextAttributes"),
1975 (GBoxedCopyFunc) gtk_text_attributes_ref,
1976 (GBoxedFreeFunc) gtk_text_attributes_unref);
1982 * gtk_text_attributes_copy_values:
1983 * @src: a #GtkTextAttributes
1984 * @dest: another #GtkTextAttributes
1986 * Copies the values from @src to @dest so that @dest has the same values
1987 * as @src. Frees existing values in @dest.
1990 gtk_text_attributes_copy_values (GtkTextAttributes *src,
1991 GtkTextAttributes *dest)
1993 guint orig_refcount;
1995 g_return_if_fail (!dest->realized);
2002 if (src->appearance.bg_stipple)
2003 g_object_ref (src->appearance.bg_stipple);
2005 if (src->appearance.fg_stipple)
2006 g_object_ref (src->appearance.fg_stipple);
2010 if (dest->appearance.bg_stipple)
2011 g_object_unref (dest->appearance.bg_stipple);
2013 if (dest->appearance.fg_stipple)
2014 g_object_unref (dest->appearance.fg_stipple);
2017 pango_font_description_free (dest->font);
2020 orig_refcount = dest->refcount;
2025 dest->tabs = pango_tab_array_copy (src->tabs);
2027 dest->language = src->language;
2030 dest->font = pango_font_description_copy (src->font);
2032 if (src->pg_bg_color)
2033 dest->pg_bg_color = gdk_color_copy (src->pg_bg_color);
2035 dest->refcount = orig_refcount;
2036 dest->realized = FALSE;
2040 * gtk_text_attributes_ref:
2041 * @values: a #GtkTextAttributes
2043 * Increments the reference count on @values.
2045 * Returns: the #GtkTextAttributes that were passed in
2048 gtk_text_attributes_ref (GtkTextAttributes *values)
2050 g_return_val_if_fail (values != NULL, NULL);
2052 values->refcount += 1;
2058 * gtk_text_attributes_unref:
2059 * @values: a #GtkTextAttributes
2061 * Decrements the reference count on @values, freeing the structure
2062 * if the reference count reaches 0.
2065 gtk_text_attributes_unref (GtkTextAttributes *values)
2067 g_return_if_fail (values != NULL);
2068 g_return_if_fail (values->refcount > 0);
2070 values->refcount -= 1;
2072 if (values->refcount == 0)
2074 g_assert (!values->realized);
2076 if (values->appearance.bg_stipple)
2077 g_object_unref (values->appearance.bg_stipple);
2079 if (values->appearance.fg_stipple)
2080 g_object_unref (values->appearance.fg_stipple);
2083 pango_tab_array_free (values->tabs);
2086 pango_font_description_free (values->font);
2088 if (values->pg_bg_color)
2089 gdk_color_free (values->pg_bg_color);
2096 _gtk_text_attributes_realize (GtkTextAttributes *values,
2100 g_return_if_fail (values != NULL);
2101 g_return_if_fail (values->refcount > 0);
2102 g_return_if_fail (!values->realized);
2104 /* It is wrong to use this colormap, FIXME */
2105 gdk_colormap_alloc_color (cmap,
2106 &values->appearance.fg_color,
2109 gdk_colormap_alloc_color (cmap,
2110 &values->appearance.bg_color,
2113 if (values->pg_bg_color)
2114 gdk_colormap_alloc_color (cmap,
2115 values->pg_bg_color,
2118 values->realized = TRUE;
2122 _gtk_text_attributes_unrealize (GtkTextAttributes *values,
2126 g_return_if_fail (values != NULL);
2127 g_return_if_fail (values->refcount > 0);
2128 g_return_if_fail (values->realized);
2130 gdk_colormap_free_colors (cmap,
2131 &values->appearance.fg_color, 1);
2134 gdk_colormap_free_colors (cmap,
2135 &values->appearance.bg_color, 1);
2137 values->appearance.fg_color.pixel = 0;
2138 values->appearance.bg_color.pixel = 0;
2140 if (values->pg_bg_color)
2142 gdk_colormap_free_colors (cmap, values->pg_bg_color, 1);
2144 values->pg_bg_color->pixel = 0;
2147 values->realized = FALSE;
2151 _gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest,
2157 g_return_if_fail (!dest->realized);
2161 GtkTextTag *tag = tags[n];
2162 GtkTextAttributes *vals = tag->values;
2164 g_assert (tag->table != NULL);
2166 g_assert (tags[n]->priority > tags[n-1]->priority);
2168 if (tag->bg_color_set)
2170 dest->appearance.bg_color = vals->appearance.bg_color;
2172 dest->appearance.draw_bg = TRUE;
2174 if (tag->fg_color_set)
2175 dest->appearance.fg_color = vals->appearance.fg_color;
2177 if (tag->pg_bg_color_set)
2179 dest->pg_bg_color = gdk_color_copy (vals->pg_bg_color);
2182 if (tag->bg_stipple_set)
2184 g_object_ref (vals->appearance.bg_stipple);
2185 if (dest->appearance.bg_stipple)
2186 g_object_unref (dest->appearance.bg_stipple);
2187 dest->appearance.bg_stipple = vals->appearance.bg_stipple;
2189 dest->appearance.draw_bg = TRUE;
2192 if (tag->fg_stipple_set)
2194 g_object_ref (vals->appearance.fg_stipple);
2195 if (dest->appearance.fg_stipple)
2196 g_object_unref (dest->appearance.fg_stipple);
2197 dest->appearance.fg_stipple = vals->appearance.fg_stipple;
2203 pango_font_description_merge (dest->font, vals->font, TRUE);
2205 dest->font = pango_font_description_copy (vals->font);
2208 /* multiply all the scales together to get a composite */
2210 dest->font_scale *= vals->font_scale;
2212 if (tag->justification_set)
2213 dest->justification = vals->justification;
2215 if (vals->direction != GTK_TEXT_DIR_NONE)
2216 dest->direction = vals->direction;
2218 if (tag->left_margin_set)
2219 dest->left_margin = vals->left_margin;
2221 if (tag->indent_set)
2222 dest->indent = vals->indent;
2225 dest->appearance.rise = vals->appearance.rise;
2227 if (tag->right_margin_set)
2228 dest->right_margin = vals->right_margin;
2230 if (tag->pixels_above_lines_set)
2231 dest->pixels_above_lines = vals->pixels_above_lines;
2233 if (tag->pixels_below_lines_set)
2234 dest->pixels_below_lines = vals->pixels_below_lines;
2236 if (tag->pixels_inside_wrap_set)
2237 dest->pixels_inside_wrap = vals->pixels_inside_wrap;
2242 pango_tab_array_free (dest->tabs);
2243 dest->tabs = pango_tab_array_copy (vals->tabs);
2246 if (tag->wrap_mode_set)
2247 dest->wrap_mode = vals->wrap_mode;
2249 if (tag->underline_set)
2250 dest->appearance.underline = vals->appearance.underline;
2252 if (tag->strikethrough_set)
2253 dest->appearance.strikethrough = vals->appearance.strikethrough;
2255 if (tag->invisible_set)
2256 dest->invisible = vals->invisible;
2258 if (tag->editable_set)
2259 dest->editable = vals->editable;
2261 if (tag->bg_full_height_set)
2262 dest->bg_full_height = vals->bg_full_height;
2264 if (tag->language_set)
2265 dest->language = vals->language;
2272 _gtk_text_tag_affects_size (GtkTextTag *tag)
2274 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
2277 (tag->values->font && pango_font_description_get_set_fields (tag->values->font) != 0) ||
2279 tag->justification_set ||
2280 tag->left_margin_set ||
2283 tag->right_margin_set ||
2284 tag->pixels_above_lines_set ||
2285 tag->pixels_below_lines_set ||
2286 tag->pixels_inside_wrap_set ||
2288 tag->underline_set ||
2289 tag->wrap_mode_set ||
2294 _gtk_text_tag_affects_nonsize_appearance (GtkTextTag *tag)
2296 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
2299 tag->bg_color_set ||
2300 tag->bg_stipple_set ||
2301 tag->fg_color_set ||
2302 tag->fg_stipple_set ||
2303 tag->strikethrough_set ||
2304 tag->bg_full_height_set ||
2305 tag->pg_bg_color_set;
2308 #define __GTK_TEXT_TAG_C__
2309 #include "gtkaliasdef.c"