1 /* gtktexttag.c - text tag object
3 * Copyright (c) 1992-1994 The Regents of the University of California.
4 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
5 * Copyright (c) 2000 Red Hat, Inc.
6 * Tk -> Gtk port by Havoc Pennington <hp@redhat.com>
8 * This software is copyrighted by the Regents of the University of
9 * California, Sun Microsystems, Inc., and other parties. The
10 * following terms apply to all files associated with the software
11 * unless explicitly disclaimed in individual files.
13 * The authors hereby grant permission to use, copy, modify,
14 * distribute, and license this software and its documentation for any
15 * purpose, provided that existing copyright notices are retained in
16 * all copies and that this notice is included verbatim in any
17 * distributions. No written agreement, license, or royalty fee is
18 * required for any of the authorized uses. Modifications to this
19 * software may be copyrighted by their authors and need not follow
20 * the licensing terms described here, provided that the new terms are
21 * clearly indicated on the first page of each file where they apply.
23 * IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY
24 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
25 * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION,
26 * OR ANY DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED
27 * OF THE POSSIBILITY OF SUCH DAMAGE.
29 * THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
30 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
31 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
32 * NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS,
33 * AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
34 * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
36 * GOVERNMENT USE: If you are acquiring this software on behalf of the
37 * U.S. government, the Government shall have only "Restricted Rights"
38 * in the software and related documentation as defined in the Federal
39 * Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you
40 * are acquiring the software on behalf of the Department of Defense,
41 * the software shall be classified as "Commercial Computer Software"
42 * and the Government shall have only "Restricted Rights" as defined
43 * in Clause 252.227-7013 (c) (1) of DFARs. Notwithstanding the
44 * foregoing, the authors grant the U.S. Government and others acting
45 * in its behalf permission to use and distribute the software in
46 * accordance with the terms specified in this license.
52 #include "gtktexttag.h"
53 #include "gtktexttypes.h"
54 #include "gtktexttagtable.h"
56 #include "gtkmarshalers.h"
57 #include "gtkprivate.h"
78 PROP_BACKGROUND_STIPPLE,
79 PROP_FOREGROUND_STIPPLE,
90 PROP_PIXELS_ABOVE_LINES,
91 PROP_PIXELS_BELOW_LINES,
92 PROP_PIXELS_INSIDE_WRAP,
103 PROP_BACKGROUND_FULL_HEIGHT,
107 PROP_PARAGRAPH_BACKGROUND,
108 PROP_PARAGRAPH_BACKGROUND_GDK,
111 PROP_ACCUMULATIVE_MARGIN,
113 /* Whether-a-style-arg-is-set args */
116 PROP_BACKGROUND_STIPPLE_SET,
117 PROP_FOREGROUND_STIPPLE_SET,
125 PROP_PIXELS_ABOVE_LINES_SET,
126 PROP_PIXELS_BELOW_LINES_SET,
127 PROP_PIXELS_INSIDE_WRAP_SET,
130 PROP_JUSTIFICATION_SET,
131 PROP_LEFT_MARGIN_SET,
133 PROP_STRIKETHROUGH_SET,
134 PROP_RIGHT_MARGIN_SET,
137 PROP_BACKGROUND_FULL_HEIGHT_SET,
141 PROP_PARAGRAPH_BACKGROUND_SET,
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 guint signals[LAST_SIGNAL] = { 0 };
157 G_DEFINE_TYPE (GtkTextTag, gtk_text_tag, G_TYPE_OBJECT)
160 gtk_text_tag_class_init (GtkTextTagClass *klass)
162 GObjectClass *object_class = G_OBJECT_CLASS (klass);
164 object_class->set_property = gtk_text_tag_set_property;
165 object_class->get_property = gtk_text_tag_get_property;
167 object_class->finalize = gtk_text_tag_finalize;
170 g_object_class_install_property (object_class,
172 g_param_spec_string ("name",
174 P_("Name used to refer to the text tag. NULL for anonymous tags"),
176 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
180 g_object_class_install_property (object_class,
182 g_param_spec_string ("background",
183 P_("Background color name"),
184 P_("Background color as a string"),
186 GTK_PARAM_WRITABLE));
188 g_object_class_install_property (object_class,
190 g_param_spec_boxed ("background-gdk",
191 P_("Background color"),
192 P_("Background color as a (possibly unallocated) GdkColor"),
194 GTK_PARAM_READWRITE));
196 g_object_class_install_property (object_class,
197 PROP_BACKGROUND_FULL_HEIGHT,
198 g_param_spec_boolean ("background-full-height",
199 P_("Background full height"),
200 P_("Whether the background color fills the entire line height or only the height of the tagged characters"),
202 GTK_PARAM_READWRITE));
205 g_object_class_install_property (object_class,
206 PROP_BACKGROUND_STIPPLE,
207 g_param_spec_object ("background-stipple",
208 P_("Background stipple mask"),
209 P_("Bitmap to use as a mask when drawing the text background"),
211 GTK_PARAM_READWRITE));
214 g_object_class_install_property (object_class,
216 g_param_spec_string ("foreground",
217 P_("Foreground color name"),
218 P_("Foreground color as a string"),
220 GTK_PARAM_WRITABLE));
222 g_object_class_install_property (object_class,
224 g_param_spec_boxed ("foreground-gdk",
225 P_("Foreground color"),
226 P_("Foreground color as a (possibly unallocated) GdkColor"),
228 GTK_PARAM_READWRITE));
231 g_object_class_install_property (object_class,
232 PROP_FOREGROUND_STIPPLE,
233 g_param_spec_object ("foreground-stipple",
234 P_("Foreground stipple mask"),
235 P_("Bitmap to use as a mask when drawing the text foreground"),
237 GTK_PARAM_READWRITE));
239 g_object_class_install_property (object_class,
241 g_param_spec_enum ("direction",
242 P_("Text direction"),
243 P_("Text direction, e.g. right-to-left or left-to-right"),
244 GTK_TYPE_TEXT_DIRECTION,
246 GTK_PARAM_READWRITE));
248 g_object_class_install_property (object_class,
250 g_param_spec_boolean ("editable",
252 P_("Whether the text can be modified by the user"),
254 GTK_PARAM_READWRITE));
259 * Font description as string, e.g. \"Sans Italic 12\".
261 * Note that the initial value of this property depends on
262 * the internals of #PangoFontDescription.
264 g_object_class_install_property (object_class,
266 g_param_spec_string ("font",
268 P_("Font description as a string, e.g. \"Sans Italic 12\""),
270 GTK_PARAM_READWRITE));
272 g_object_class_install_property (object_class,
274 g_param_spec_boxed ("font-desc",
276 P_("Font description as a PangoFontDescription struct"),
277 PANGO_TYPE_FONT_DESCRIPTION,
278 GTK_PARAM_READWRITE));
280 g_object_class_install_property (object_class,
282 g_param_spec_string ("family",
284 P_("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
286 GTK_PARAM_READWRITE));
288 g_object_class_install_property (object_class,
290 g_param_spec_enum ("style",
292 P_("Font style as a PangoStyle, e.g. PANGO_STYLE_ITALIC"),
295 GTK_PARAM_READWRITE));
297 g_object_class_install_property (object_class,
299 g_param_spec_enum ("variant",
301 P_("Font variant as a PangoVariant, e.g. PANGO_VARIANT_SMALL_CAPS"),
303 PANGO_VARIANT_NORMAL,
304 GTK_PARAM_READWRITE));
306 g_object_class_install_property (object_class,
308 g_param_spec_int ("weight",
310 P_("Font weight as an integer, see predefined values in PangoWeight; for example, PANGO_WEIGHT_BOLD"),
314 GTK_PARAM_READWRITE));
317 g_object_class_install_property (object_class,
319 g_param_spec_enum ("stretch",
321 P_("Font stretch as a PangoStretch, e.g. PANGO_STRETCH_CONDENSED"),
323 PANGO_STRETCH_NORMAL,
324 GTK_PARAM_READWRITE));
326 g_object_class_install_property (object_class,
328 g_param_spec_int ("size",
330 P_("Font size in Pango units"),
334 GTK_PARAM_READWRITE));
336 g_object_class_install_property (object_class,
338 g_param_spec_double ("scale",
340 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"),
344 GTK_PARAM_READWRITE));
346 g_object_class_install_property (object_class,
348 g_param_spec_double ("size-points",
350 P_("Font size in points"),
354 GTK_PARAM_READWRITE));
356 g_object_class_install_property (object_class,
358 g_param_spec_enum ("justification",
360 P_("Left, right, or center justification"),
361 GTK_TYPE_JUSTIFICATION,
363 GTK_PARAM_READWRITE));
366 * GtkTextTag:language:
368 * The language this text is in, as an ISO code. Pango can use this as a
369 * hint when rendering the text. If not set, an appropriate default will be
372 * Note that the initial value of this property depends on the current
373 * locale, see also gtk_get_default_language().
375 g_object_class_install_property (object_class,
377 g_param_spec_string ("language",
379 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."),
381 GTK_PARAM_READWRITE));
383 g_object_class_install_property (object_class,
385 g_param_spec_int ("left-margin",
387 P_("Width of the left margin in pixels"),
391 GTK_PARAM_READWRITE));
393 g_object_class_install_property (object_class,
395 g_param_spec_int ("right-margin",
397 P_("Width of the right margin in pixels"),
401 GTK_PARAM_READWRITE));
404 g_object_class_install_property (object_class,
406 g_param_spec_int ("indent",
408 P_("Amount to indent the paragraph, in pixels"),
412 GTK_PARAM_READWRITE));
415 g_object_class_install_property (object_class,
417 g_param_spec_int ("rise",
419 P_("Offset of text above the baseline (below the baseline if rise is negative) in Pango units"),
423 GTK_PARAM_READWRITE));
425 g_object_class_install_property (object_class,
426 PROP_PIXELS_ABOVE_LINES,
427 g_param_spec_int ("pixels-above-lines",
428 P_("Pixels above lines"),
429 P_("Pixels of blank space above paragraphs"),
433 GTK_PARAM_READWRITE));
435 g_object_class_install_property (object_class,
436 PROP_PIXELS_BELOW_LINES,
437 g_param_spec_int ("pixels-below-lines",
438 P_("Pixels below lines"),
439 P_("Pixels of blank space below paragraphs"),
443 GTK_PARAM_READWRITE));
445 g_object_class_install_property (object_class,
446 PROP_PIXELS_INSIDE_WRAP,
447 g_param_spec_int ("pixels-inside-wrap",
448 P_("Pixels inside wrap"),
449 P_("Pixels of blank space between wrapped lines in a paragraph"),
453 GTK_PARAM_READWRITE));
455 g_object_class_install_property (object_class,
457 g_param_spec_boolean ("strikethrough",
459 P_("Whether to strike through the text"),
461 GTK_PARAM_READWRITE));
463 g_object_class_install_property (object_class,
465 g_param_spec_enum ("underline",
467 P_("Style of underline for this text"),
468 PANGO_TYPE_UNDERLINE,
469 PANGO_UNDERLINE_NONE,
470 GTK_PARAM_READWRITE));
472 g_object_class_install_property (object_class,
474 g_param_spec_enum ("wrap-mode",
476 P_("Whether to wrap lines never, at word boundaries, or at character boundaries"),
479 GTK_PARAM_READWRITE));
482 g_object_class_install_property (object_class,
484 g_param_spec_boxed ("tabs",
486 P_("Custom tabs for this text"),
487 PANGO_TYPE_TAB_ARRAY,
488 GTK_PARAM_READWRITE));
491 * GtkTextTag:invisible:
493 * Whether this text is hidden.
495 * Note that there may still be problems with the support for invisible
496 * text, in particular when navigating programmatically inside a buffer
497 * containing invisible segments.
501 g_object_class_install_property (object_class,
503 g_param_spec_boolean ("invisible",
505 P_("Whether this text is hidden."),
507 GTK_PARAM_READWRITE));
510 * GtkTextTag:paragraph-background:
512 * The paragraph background color as a string.
516 g_object_class_install_property (object_class,
517 PROP_PARAGRAPH_BACKGROUND,
518 g_param_spec_string ("paragraph-background",
519 P_("Paragraph background color name"),
520 P_("Paragraph background color as a string"),
522 GTK_PARAM_WRITABLE));
525 * GtkTextTag:paragraph-background-gdk:
527 * The paragraph background color as a as a (possibly unallocated)
532 g_object_class_install_property (object_class,
533 PROP_PARAGRAPH_BACKGROUND_GDK,
534 g_param_spec_boxed ("paragraph-background-gdk",
535 P_("Paragraph background color"),
536 P_("Paragraph background color as a (possibly unallocated) GdkColor"),
538 GTK_PARAM_READWRITE));
541 * GtkTextTag:accumulative-margin:
543 * Whether the margins accumulate or override each other.
545 * When set to %TRUE the margins of this tag are added to the margins
546 * of any other non-accumulative margins present. When set to %FALSE
547 * the margins override one another (the default).
551 g_object_class_install_property (object_class,
552 PROP_ACCUMULATIVE_MARGIN,
553 g_param_spec_boolean ("accumulative-margin",
554 P_("Margin Accumulates"),
555 P_("Whether left and right margins accumulate."),
557 GTK_PARAM_READWRITE));
559 /* Style props are set or not */
561 #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))
563 ADD_SET_PROP ("background-set", PROP_BACKGROUND_SET,
564 P_("Background set"),
565 P_("Whether this tag affects the background color"));
567 ADD_SET_PROP ("background-full-height-set", PROP_BACKGROUND_FULL_HEIGHT_SET,
568 P_("Background full height set"),
569 P_("Whether this tag affects background height"));
571 ADD_SET_PROP ("background-stipple-set", PROP_BACKGROUND_STIPPLE_SET,
572 P_("Background stipple set"),
573 P_("Whether this tag affects the background stipple"));
575 ADD_SET_PROP ("foreground-set", PROP_FOREGROUND_SET,
576 P_("Foreground set"),
577 P_("Whether this tag affects the foreground color"));
579 ADD_SET_PROP ("foreground-stipple-set", PROP_FOREGROUND_STIPPLE_SET,
580 P_("Foreground stipple set"),
581 P_("Whether this tag affects the foreground stipple"));
583 ADD_SET_PROP ("editable-set", PROP_EDITABLE_SET,
584 P_("Editability set"),
585 P_("Whether this tag affects text editability"));
587 ADD_SET_PROP ("family-set", PROP_FAMILY_SET,
588 P_("Font family set"),
589 P_("Whether this tag affects the font family"));
591 ADD_SET_PROP ("style-set", PROP_STYLE_SET,
592 P_("Font style set"),
593 P_("Whether this tag affects the font style"));
595 ADD_SET_PROP ("variant-set", PROP_VARIANT_SET,
596 P_("Font variant set"),
597 P_("Whether this tag affects the font variant"));
599 ADD_SET_PROP ("weight-set", PROP_WEIGHT_SET,
600 P_("Font weight set"),
601 P_("Whether this tag affects the font weight"));
603 ADD_SET_PROP ("stretch-set", PROP_STRETCH_SET,
604 P_("Font stretch set"),
605 P_("Whether this tag affects the font stretch"));
607 ADD_SET_PROP ("size-set", PROP_SIZE_SET,
609 P_("Whether this tag affects the font size"));
611 ADD_SET_PROP ("scale-set", PROP_SCALE_SET,
612 P_("Font scale set"),
613 P_("Whether this tag scales the font size by a factor"));
615 ADD_SET_PROP ("justification-set", PROP_JUSTIFICATION_SET,
616 P_("Justification set"),
617 P_("Whether this tag affects paragraph justification"));
619 ADD_SET_PROP ("language-set", PROP_LANGUAGE_SET,
621 P_("Whether this tag affects the language the text is rendered as"));
623 ADD_SET_PROP ("left-margin-set", PROP_LEFT_MARGIN_SET,
624 P_("Left margin set"),
625 P_("Whether this tag affects the left margin"));
627 ADD_SET_PROP ("indent-set", PROP_INDENT_SET,
629 P_("Whether this tag affects indentation"));
631 ADD_SET_PROP ("rise-set", PROP_RISE_SET,
633 P_("Whether this tag affects the rise"));
635 ADD_SET_PROP ("pixels-above-lines-set", PROP_PIXELS_ABOVE_LINES_SET,
636 P_("Pixels above lines set"),
637 P_("Whether this tag affects the number of pixels above lines"));
639 ADD_SET_PROP ("pixels-below-lines-set", PROP_PIXELS_BELOW_LINES_SET,
640 P_("Pixels below lines set"),
641 P_("Whether this tag affects the number of pixels above lines"));
643 ADD_SET_PROP ("pixels-inside-wrap-set", PROP_PIXELS_INSIDE_WRAP_SET,
644 P_("Pixels inside wrap set"),
645 P_("Whether this tag affects the number of pixels between wrapped lines"));
647 ADD_SET_PROP ("strikethrough-set", PROP_STRIKETHROUGH_SET,
648 P_("Strikethrough set"),
649 P_("Whether this tag affects strikethrough"));
651 ADD_SET_PROP ("right-margin-set", PROP_RIGHT_MARGIN_SET,
652 P_("Right margin set"),
653 P_("Whether this tag affects the right margin"));
655 ADD_SET_PROP ("underline-set", PROP_UNDERLINE_SET,
657 P_("Whether this tag affects underlining"));
659 ADD_SET_PROP ("wrap-mode-set", PROP_WRAP_MODE_SET,
661 P_("Whether this tag affects line wrap mode"));
663 ADD_SET_PROP ("tabs-set", PROP_TABS_SET,
665 P_("Whether this tag affects tabs"));
667 ADD_SET_PROP ("invisible-set", PROP_INVISIBLE_SET,
669 P_("Whether this tag affects text visibility"));
671 ADD_SET_PROP ("paragraph-background-set", PROP_PARAGRAPH_BACKGROUND_SET,
672 P_("Paragraph background set"),
673 P_("Whether this tag affects the paragraph background color"));
677 * @tag: the #GtkTextTag on which the signal is emitted
678 * @object: the object the event was fired from (typically a #GtkTextView)
679 * @event: the event which triggered the signal
680 * @iter: a #GtkTextIter pointing at the location the event occured
682 * The ::event signal is emitted when an event occurs on a region of the
683 * buffer marked with this tag.
685 * Returns: %TRUE to stop other handlers from being invoked for the
686 * event. %FALSE to propagate the event further.
689 g_signal_new (I_("event"),
690 G_OBJECT_CLASS_TYPE (object_class),
692 G_STRUCT_OFFSET (GtkTextTagClass, event),
693 _gtk_boolean_handled_accumulator, NULL,
694 _gtk_marshal_BOOLEAN__OBJECT_BOXED_BOXED,
698 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE,
703 gtk_text_tag_init (GtkTextTag *text_tag)
705 text_tag->values = gtk_text_attributes_new ();
710 * @name: tag name, or %NULL
712 * Creates a #GtkTextTag. Configure the tag using object arguments,
713 * i.e. using g_object_set().
715 * Return value: a new #GtkTextTag
718 gtk_text_tag_new (const gchar *name)
722 tag = g_object_new (GTK_TYPE_TEXT_TAG, "name", name, NULL);
728 gtk_text_tag_finalize (GObject *object)
730 GtkTextTag *text_tag;
732 text_tag = GTK_TEXT_TAG (object);
734 g_assert (!text_tag->values->realized);
737 gtk_text_tag_table_remove (text_tag->table, text_tag);
739 g_assert (text_tag->table == NULL);
741 gtk_text_attributes_unref (text_tag->values);
742 text_tag->values = NULL;
744 g_free (text_tag->name);
745 text_tag->name = NULL;
747 G_OBJECT_CLASS (gtk_text_tag_parent_class)->finalize (object);
751 set_bg_color (GtkTextTag *tag, GdkColor *color)
755 if (!tag->bg_color_set)
757 tag->bg_color_set = TRUE;
758 g_object_notify (G_OBJECT (tag), "background-set");
761 tag->values->appearance.bg_color = *color;
765 if (tag->bg_color_set)
767 tag->bg_color_set = FALSE;
768 g_object_notify (G_OBJECT (tag), "background-set");
774 set_fg_color (GtkTextTag *tag, GdkColor *color)
778 if (!tag->fg_color_set)
780 tag->fg_color_set = TRUE;
781 g_object_notify (G_OBJECT (tag), "foreground-set");
783 tag->values->appearance.fg_color = *color;
787 if (tag->fg_color_set)
789 tag->fg_color_set = FALSE;
790 g_object_notify (G_OBJECT (tag), "foreground-set");
796 set_pg_bg_color (GtkTextTag *tag, GdkColor *color)
800 if (!tag->pg_bg_color_set)
802 tag->pg_bg_color_set = TRUE;
803 g_object_notify (G_OBJECT (tag), "paragraph-background-set");
806 gdk_color_free (tag->values->pg_bg_color);
808 tag->values->pg_bg_color = gdk_color_copy (color);
812 if (tag->pg_bg_color_set)
814 tag->pg_bg_color_set = FALSE;
815 g_object_notify (G_OBJECT (tag), "paragraph-background-set");
816 gdk_color_free (tag->values->pg_bg_color);
819 tag->values->pg_bg_color = NULL;
824 get_property_font_set_mask (guint prop_id)
828 case PROP_FAMILY_SET:
829 return PANGO_FONT_MASK_FAMILY;
831 return PANGO_FONT_MASK_STYLE;
832 case PROP_VARIANT_SET:
833 return PANGO_FONT_MASK_VARIANT;
834 case PROP_WEIGHT_SET:
835 return PANGO_FONT_MASK_WEIGHT;
836 case PROP_STRETCH_SET:
837 return PANGO_FONT_MASK_STRETCH;
839 return PANGO_FONT_MASK_SIZE;
846 set_font_desc_fields (PangoFontDescription *desc,
847 PangoFontMask to_set)
849 PangoFontMask changed_mask = 0;
851 if (to_set & PANGO_FONT_MASK_FAMILY)
853 const char *family = pango_font_description_get_family (desc);
857 changed_mask |= PANGO_FONT_MASK_FAMILY;
860 pango_font_description_set_family (desc, family);
862 if (to_set & PANGO_FONT_MASK_STYLE)
863 pango_font_description_set_style (desc, pango_font_description_get_style (desc));
864 if (to_set & PANGO_FONT_MASK_VARIANT)
865 pango_font_description_set_variant (desc, pango_font_description_get_variant (desc));
866 if (to_set & PANGO_FONT_MASK_WEIGHT)
867 pango_font_description_set_weight (desc, pango_font_description_get_weight (desc));
868 if (to_set & PANGO_FONT_MASK_STRETCH)
869 pango_font_description_set_stretch (desc, pango_font_description_get_stretch (desc));
870 if (to_set & PANGO_FONT_MASK_SIZE)
872 gint size = pango_font_description_get_size (desc);
875 size = 10 * PANGO_SCALE;
876 changed_mask |= PANGO_FONT_MASK_SIZE;
879 pango_font_description_set_size (desc, size);
886 notify_set_changed (GObject *object,
887 PangoFontMask changed_mask)
889 if (changed_mask & PANGO_FONT_MASK_FAMILY)
890 g_object_notify (object, "family-set");
891 if (changed_mask & PANGO_FONT_MASK_STYLE)
892 g_object_notify (object, "style-set");
893 if (changed_mask & PANGO_FONT_MASK_VARIANT)
894 g_object_notify (object, "variant-set");
895 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
896 g_object_notify (object, "weight-set");
897 if (changed_mask & PANGO_FONT_MASK_STRETCH)
898 g_object_notify (object, "stretch-set");
899 if (changed_mask & PANGO_FONT_MASK_SIZE)
900 g_object_notify (object, "size-set");
904 notify_fields_changed (GObject *object,
905 PangoFontMask changed_mask)
907 if (changed_mask & PANGO_FONT_MASK_FAMILY)
908 g_object_notify (object, "family");
909 if (changed_mask & PANGO_FONT_MASK_STYLE)
910 g_object_notify (object, "style");
911 if (changed_mask & PANGO_FONT_MASK_VARIANT)
912 g_object_notify (object, "variant");
913 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
914 g_object_notify (object, "weight");
915 if (changed_mask & PANGO_FONT_MASK_STRETCH)
916 g_object_notify (object, "stretch");
917 if (changed_mask & PANGO_FONT_MASK_SIZE)
918 g_object_notify (object, "size");
922 set_font_description (GtkTextTag *text_tag,
923 PangoFontDescription *font_desc)
925 GObject *object = G_OBJECT (text_tag);
926 PangoFontDescription *new_font_desc;
927 PangoFontMask old_mask, new_mask, changed_mask, set_changed_mask;
930 new_font_desc = pango_font_description_copy (font_desc);
932 new_font_desc = pango_font_description_new ();
934 if (text_tag->values->font)
935 old_mask = pango_font_description_get_set_fields (text_tag->values->font);
939 new_mask = pango_font_description_get_set_fields (new_font_desc);
941 changed_mask = old_mask | new_mask;
942 set_changed_mask = old_mask ^ new_mask;
944 if (text_tag->values->font)
945 pango_font_description_free (text_tag->values->font);
946 text_tag->values->font = new_font_desc;
948 g_object_freeze_notify (object);
950 g_object_notify (object, "font-desc");
951 g_object_notify (object, "font");
953 if (changed_mask & PANGO_FONT_MASK_FAMILY)
954 g_object_notify (object, "family");
955 if (changed_mask & PANGO_FONT_MASK_STYLE)
956 g_object_notify (object, "style");
957 if (changed_mask & PANGO_FONT_MASK_VARIANT)
958 g_object_notify (object, "variant");
959 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
960 g_object_notify (object, "weight");
961 if (changed_mask & PANGO_FONT_MASK_STRETCH)
962 g_object_notify (object, "stretch");
963 if (changed_mask & PANGO_FONT_MASK_SIZE)
965 g_object_notify (object, "size");
966 g_object_notify (object, "size-points");
969 notify_set_changed (object, set_changed_mask);
971 g_object_thaw_notify (object);
975 gtk_text_tag_ensure_font (GtkTextTag *text_tag)
977 if (!text_tag->values->font)
978 text_tag->values->font = pango_font_description_new ();
982 gtk_text_tag_set_property (GObject *object,
987 GtkTextTag *text_tag;
988 gboolean size_changed = FALSE;
990 text_tag = GTK_TEXT_TAG (object);
992 g_return_if_fail (!text_tag->values->realized);
997 g_return_if_fail (text_tag->name == NULL);
998 text_tag->name = g_strdup (g_value_get_string (value));
1001 case PROP_BACKGROUND:
1005 if (!g_value_get_string (value))
1006 set_bg_color (text_tag, NULL); /* reset to background_set to FALSE */
1007 else if (gdk_color_parse (g_value_get_string (value), &color))
1008 set_bg_color (text_tag, &color);
1010 g_warning ("Don't know color `%s'", g_value_get_string (value));
1012 g_object_notify (object, "background-gdk");
1016 case PROP_FOREGROUND:
1020 if (!g_value_get_string (value))
1021 set_fg_color (text_tag, NULL); /* reset to foreground_set to FALSE */
1022 else if (gdk_color_parse (g_value_get_string (value), &color))
1023 set_fg_color (text_tag, &color);
1025 g_warning ("Don't know color `%s'", g_value_get_string (value));
1027 g_object_notify (object, "foreground-gdk");
1031 case PROP_BACKGROUND_GDK:
1033 GdkColor *color = g_value_get_boxed (value);
1035 set_bg_color (text_tag, color);
1039 case PROP_FOREGROUND_GDK:
1041 GdkColor *color = g_value_get_boxed (value);
1043 set_fg_color (text_tag, color);
1047 case PROP_BACKGROUND_STIPPLE:
1049 GdkBitmap *bitmap = g_value_get_object (value);
1051 text_tag->bg_stipple_set = TRUE;
1052 g_object_notify (object, "background-stipple-set");
1054 if (text_tag->values->appearance.bg_stipple != bitmap)
1057 g_object_ref (bitmap);
1059 if (text_tag->values->appearance.bg_stipple)
1060 g_object_unref (text_tag->values->appearance.bg_stipple);
1062 text_tag->values->appearance.bg_stipple = bitmap;
1067 case PROP_FOREGROUND_STIPPLE:
1069 GdkBitmap *bitmap = g_value_get_object (value);
1071 text_tag->fg_stipple_set = TRUE;
1072 g_object_notify (object, "foreground-stipple-set");
1074 if (text_tag->values->appearance.fg_stipple != bitmap)
1077 g_object_ref (bitmap);
1079 if (text_tag->values->appearance.fg_stipple)
1080 g_object_unref (text_tag->values->appearance.fg_stipple);
1082 text_tag->values->appearance.fg_stipple = bitmap;
1089 PangoFontDescription *font_desc = NULL;
1092 name = g_value_get_string (value);
1095 font_desc = pango_font_description_from_string (name);
1097 set_font_description (text_tag, font_desc);
1099 pango_font_description_free (font_desc);
1101 size_changed = TRUE;
1105 case PROP_FONT_DESC:
1107 PangoFontDescription *font_desc;
1109 font_desc = g_value_get_boxed (value);
1111 set_font_description (text_tag, font_desc);
1113 size_changed = TRUE;
1123 case PROP_SIZE_POINTS:
1125 PangoFontMask old_set_mask;
1127 gtk_text_tag_ensure_font (text_tag);
1128 old_set_mask = pango_font_description_get_set_fields (text_tag->values->font);
1133 pango_font_description_set_family (text_tag->values->font,
1134 g_value_get_string (value));
1137 pango_font_description_set_style (text_tag->values->font,
1138 g_value_get_enum (value));
1141 pango_font_description_set_variant (text_tag->values->font,
1142 g_value_get_enum (value));
1145 pango_font_description_set_weight (text_tag->values->font,
1146 g_value_get_int (value));
1149 pango_font_description_set_stretch (text_tag->values->font,
1150 g_value_get_enum (value));
1153 pango_font_description_set_size (text_tag->values->font,
1154 g_value_get_int (value));
1155 g_object_notify (object, "size-points");
1157 case PROP_SIZE_POINTS:
1158 pango_font_description_set_size (text_tag->values->font,
1159 g_value_get_double (value) * PANGO_SCALE);
1160 g_object_notify (object, "size");
1164 size_changed = TRUE;
1165 notify_set_changed (object, old_set_mask & pango_font_description_get_set_fields (text_tag->values->font));
1166 g_object_notify (object, "font-desc");
1167 g_object_notify (object, "font");
1173 text_tag->values->font_scale = g_value_get_double (value);
1174 text_tag->scale_set = TRUE;
1175 g_object_notify (object, "scale-set");
1176 size_changed = TRUE;
1179 case PROP_PIXELS_ABOVE_LINES:
1180 text_tag->pixels_above_lines_set = TRUE;
1181 text_tag->values->pixels_above_lines = g_value_get_int (value);
1182 g_object_notify (object, "pixels-above-lines-set");
1183 size_changed = TRUE;
1186 case PROP_PIXELS_BELOW_LINES:
1187 text_tag->pixels_below_lines_set = TRUE;
1188 text_tag->values->pixels_below_lines = g_value_get_int (value);
1189 g_object_notify (object, "pixels-below-lines-set");
1190 size_changed = TRUE;
1193 case PROP_PIXELS_INSIDE_WRAP:
1194 text_tag->pixels_inside_wrap_set = TRUE;
1195 text_tag->values->pixels_inside_wrap = g_value_get_int (value);
1196 g_object_notify (object, "pixels-inside-wrap-set");
1197 size_changed = TRUE;
1201 text_tag->editable_set = TRUE;
1202 text_tag->values->editable = g_value_get_boolean (value);
1203 g_object_notify (object, "editable-set");
1206 case PROP_WRAP_MODE:
1207 text_tag->wrap_mode_set = TRUE;
1208 text_tag->values->wrap_mode = g_value_get_enum (value);
1209 g_object_notify (object, "wrap-mode-set");
1210 size_changed = TRUE;
1213 case PROP_JUSTIFICATION:
1214 text_tag->justification_set = TRUE;
1215 text_tag->values->justification = g_value_get_enum (value);
1216 g_object_notify (object, "justification-set");
1217 size_changed = TRUE;
1220 case PROP_DIRECTION:
1221 text_tag->values->direction = g_value_get_enum (value);
1224 case PROP_LEFT_MARGIN:
1225 text_tag->left_margin_set = TRUE;
1226 text_tag->values->left_margin = g_value_get_int (value);
1227 g_object_notify (object, "left-margin-set");
1228 size_changed = TRUE;
1232 text_tag->indent_set = TRUE;
1233 text_tag->values->indent = g_value_get_int (value);
1234 g_object_notify (object, "indent-set");
1235 size_changed = TRUE;
1238 case PROP_STRIKETHROUGH:
1239 text_tag->strikethrough_set = TRUE;
1240 text_tag->values->appearance.strikethrough = g_value_get_boolean (value);
1241 g_object_notify (object, "strikethrough-set");
1244 case PROP_RIGHT_MARGIN:
1245 text_tag->right_margin_set = TRUE;
1246 text_tag->values->right_margin = g_value_get_int (value);
1247 g_object_notify (object, "right-margin-set");
1248 size_changed = TRUE;
1251 case PROP_UNDERLINE:
1252 text_tag->underline_set = TRUE;
1253 text_tag->values->appearance.underline = g_value_get_enum (value);
1254 g_object_notify (object, "underline-set");
1258 text_tag->rise_set = TRUE;
1259 text_tag->values->appearance.rise = g_value_get_int (value);
1260 g_object_notify (object, "rise-set");
1261 size_changed = TRUE;
1264 case PROP_BACKGROUND_FULL_HEIGHT:
1265 text_tag->bg_full_height_set = TRUE;
1266 text_tag->values->bg_full_height = g_value_get_boolean (value);
1267 g_object_notify (object, "background-full-height-set");
1271 text_tag->language_set = TRUE;
1272 text_tag->values->language = pango_language_from_string (g_value_get_string (value));
1273 g_object_notify (object, "language-set");
1277 text_tag->tabs_set = TRUE;
1279 if (text_tag->values->tabs)
1280 pango_tab_array_free (text_tag->values->tabs);
1282 /* FIXME I'm not sure if this is a memleak or not */
1283 text_tag->values->tabs =
1284 pango_tab_array_copy (g_value_get_boxed (value));
1286 g_object_notify (object, "tabs-set");
1288 size_changed = TRUE;
1291 case PROP_INVISIBLE:
1292 text_tag->invisible_set = TRUE;
1293 text_tag->values->invisible = g_value_get_boolean (value);
1294 g_object_notify (object, "invisible-set");
1295 size_changed = TRUE;
1298 case PROP_PARAGRAPH_BACKGROUND:
1302 if (!g_value_get_string (value))
1303 set_pg_bg_color (text_tag, NULL); /* reset to paragraph_background_set to FALSE */
1304 else if (gdk_color_parse (g_value_get_string (value), &color))
1305 set_pg_bg_color (text_tag, &color);
1307 g_warning ("Don't know color `%s'", g_value_get_string (value));
1309 g_object_notify (object, "paragraph-background-gdk");
1313 case PROP_PARAGRAPH_BACKGROUND_GDK:
1315 GdkColor *color = g_value_get_boxed (value);
1317 set_pg_bg_color (text_tag, color);
1321 case PROP_ACCUMULATIVE_MARGIN:
1322 text_tag->accumulative_margin = g_value_get_boolean (value);
1323 g_object_notify (object, "accumulative-margin");
1324 size_changed = TRUE;
1327 /* Whether the value should be used... */
1329 case PROP_BACKGROUND_SET:
1330 text_tag->bg_color_set = g_value_get_boolean (value);
1333 case PROP_FOREGROUND_SET:
1334 text_tag->fg_color_set = g_value_get_boolean (value);
1337 case PROP_BACKGROUND_STIPPLE_SET:
1338 text_tag->bg_stipple_set = g_value_get_boolean (value);
1339 if (!text_tag->bg_stipple_set &&
1340 text_tag->values->appearance.bg_stipple)
1342 g_object_unref (text_tag->values->appearance.bg_stipple);
1343 text_tag->values->appearance.bg_stipple = NULL;
1347 case PROP_FOREGROUND_STIPPLE_SET:
1348 text_tag->fg_stipple_set = g_value_get_boolean (value);
1349 if (!text_tag->fg_stipple_set &&
1350 text_tag->values->appearance.fg_stipple)
1352 g_object_unref (text_tag->values->appearance.fg_stipple);
1353 text_tag->values->appearance.fg_stipple = NULL;
1357 case PROP_FAMILY_SET:
1358 case PROP_STYLE_SET:
1359 case PROP_VARIANT_SET:
1360 case PROP_WEIGHT_SET:
1361 case PROP_STRETCH_SET:
1363 if (!g_value_get_boolean (value))
1365 if (text_tag->values->font)
1366 pango_font_description_unset_fields (text_tag->values->font,
1367 get_property_font_set_mask (prop_id));
1371 PangoFontMask changed_mask;
1373 gtk_text_tag_ensure_font (text_tag);
1374 changed_mask = set_font_desc_fields (text_tag->values->font,
1375 get_property_font_set_mask (prop_id));
1376 notify_fields_changed (G_OBJECT (text_tag), changed_mask);
1380 case PROP_SCALE_SET:
1381 text_tag->scale_set = g_value_get_boolean (value);
1382 size_changed = TRUE;
1385 case PROP_PIXELS_ABOVE_LINES_SET:
1386 text_tag->pixels_above_lines_set = g_value_get_boolean (value);
1387 size_changed = TRUE;
1390 case PROP_PIXELS_BELOW_LINES_SET:
1391 text_tag->pixels_below_lines_set = g_value_get_boolean (value);
1392 size_changed = TRUE;
1395 case PROP_PIXELS_INSIDE_WRAP_SET:
1396 text_tag->pixels_inside_wrap_set = g_value_get_boolean (value);
1397 size_changed = TRUE;
1400 case PROP_EDITABLE_SET:
1401 text_tag->editable_set = g_value_get_boolean (value);
1404 case PROP_WRAP_MODE_SET:
1405 text_tag->wrap_mode_set = g_value_get_boolean (value);
1406 size_changed = TRUE;
1409 case PROP_JUSTIFICATION_SET:
1410 text_tag->justification_set = g_value_get_boolean (value);
1411 size_changed = TRUE;
1414 case PROP_LEFT_MARGIN_SET:
1415 text_tag->left_margin_set = g_value_get_boolean (value);
1416 size_changed = TRUE;
1419 case PROP_INDENT_SET:
1420 text_tag->indent_set = g_value_get_boolean (value);
1421 size_changed = TRUE;
1424 case PROP_STRIKETHROUGH_SET:
1425 text_tag->strikethrough_set = g_value_get_boolean (value);
1428 case PROP_RIGHT_MARGIN_SET:
1429 text_tag->right_margin_set = g_value_get_boolean (value);
1430 size_changed = TRUE;
1433 case PROP_UNDERLINE_SET:
1434 text_tag->underline_set = g_value_get_boolean (value);
1438 text_tag->rise_set = g_value_get_boolean (value);
1439 size_changed = TRUE;
1442 case PROP_BACKGROUND_FULL_HEIGHT_SET:
1443 text_tag->bg_full_height_set = g_value_get_boolean (value);
1446 case PROP_LANGUAGE_SET:
1447 text_tag->language_set = g_value_get_boolean (value);
1448 size_changed = TRUE;
1452 text_tag->tabs_set = g_value_get_boolean (value);
1453 size_changed = TRUE;
1456 case PROP_INVISIBLE_SET:
1457 text_tag->invisible_set = g_value_get_boolean (value);
1458 size_changed = TRUE;
1461 case PROP_PARAGRAPH_BACKGROUND_SET:
1462 text_tag->pg_bg_color_set = g_value_get_boolean (value);
1466 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1470 /* FIXME I would like to do this after all set_property in a single
1471 * g_object_set () have been called. But an idle function won't
1472 * work; we need to emit when the tag is changed, not when we get
1473 * around to the event loop. So blah, we eat some inefficiency.
1476 /* This is also somewhat weird since we emit another object's
1477 * signal here, but the two objects are already tightly bound.
1480 if (text_tag->table)
1481 g_signal_emit_by_name (text_tag->table,
1483 text_tag, size_changed);
1487 gtk_text_tag_get_property (GObject *object,
1494 tag = GTK_TEXT_TAG (object);
1499 g_value_set_string (value, tag->name);
1502 case PROP_BACKGROUND_GDK:
1503 g_value_set_boxed (value, &tag->values->appearance.bg_color);
1506 case PROP_FOREGROUND_GDK:
1507 g_value_set_boxed (value, &tag->values->appearance.fg_color);
1510 case PROP_BACKGROUND_STIPPLE:
1511 if (tag->bg_stipple_set)
1512 g_value_set_object (value, tag->values->appearance.bg_stipple);
1515 case PROP_FOREGROUND_STIPPLE:
1516 if (tag->fg_stipple_set)
1517 g_value_set_object (value, tag->values->appearance.fg_stipple);
1524 gtk_text_tag_ensure_font (tag);
1526 str = pango_font_description_to_string (tag->values->font);
1527 g_value_take_string (value, str);
1531 case PROP_FONT_DESC:
1532 gtk_text_tag_ensure_font (tag);
1533 g_value_set_boxed (value, tag->values->font);
1542 case PROP_SIZE_POINTS:
1543 gtk_text_tag_ensure_font (tag);
1547 g_value_set_string (value, pango_font_description_get_family (tag->values->font));
1551 g_value_set_enum (value, pango_font_description_get_style (tag->values->font));
1555 g_value_set_enum (value, pango_font_description_get_variant (tag->values->font));
1559 g_value_set_int (value, pango_font_description_get_weight (tag->values->font));
1563 g_value_set_enum (value, pango_font_description_get_stretch (tag->values->font));
1567 g_value_set_int (value, pango_font_description_get_size (tag->values->font));
1570 case PROP_SIZE_POINTS:
1571 g_value_set_double (value, ((double)pango_font_description_get_size (tag->values->font)) / (double)PANGO_SCALE);
1577 g_value_set_double (value, tag->values->font_scale);
1580 case PROP_PIXELS_ABOVE_LINES:
1581 g_value_set_int (value, tag->values->pixels_above_lines);
1584 case PROP_PIXELS_BELOW_LINES:
1585 g_value_set_int (value, tag->values->pixels_below_lines);
1588 case PROP_PIXELS_INSIDE_WRAP:
1589 g_value_set_int (value, tag->values->pixels_inside_wrap);
1593 g_value_set_boolean (value, tag->values->editable);
1596 case PROP_WRAP_MODE:
1597 g_value_set_enum (value, tag->values->wrap_mode);
1600 case PROP_JUSTIFICATION:
1601 g_value_set_enum (value, tag->values->justification);
1604 case PROP_DIRECTION:
1605 g_value_set_enum (value, tag->values->direction);
1608 case PROP_LEFT_MARGIN:
1609 g_value_set_int (value, tag->values->left_margin);
1613 g_value_set_int (value, tag->values->indent);
1616 case PROP_STRIKETHROUGH:
1617 g_value_set_boolean (value, tag->values->appearance.strikethrough);
1620 case PROP_RIGHT_MARGIN:
1621 g_value_set_int (value, tag->values->right_margin);
1624 case PROP_UNDERLINE:
1625 g_value_set_enum (value, tag->values->appearance.underline);
1629 g_value_set_int (value, tag->values->appearance.rise);
1632 case PROP_BACKGROUND_FULL_HEIGHT:
1633 g_value_set_boolean (value, tag->values->bg_full_height);
1637 g_value_set_string (value, pango_language_to_string (tag->values->language));
1641 if (tag->values->tabs)
1642 g_value_set_boxed (value, tag->values->tabs);
1645 case PROP_INVISIBLE:
1646 g_value_set_boolean (value, tag->values->invisible);
1649 case PROP_PARAGRAPH_BACKGROUND_GDK:
1650 g_value_set_boxed (value, tag->values->pg_bg_color);
1653 case PROP_ACCUMULATIVE_MARGIN:
1654 g_value_set_boolean (value, tag->accumulative_margin);
1657 case PROP_BACKGROUND_SET:
1658 g_value_set_boolean (value, tag->bg_color_set);
1661 case PROP_FOREGROUND_SET:
1662 g_value_set_boolean (value, tag->fg_color_set);
1665 case PROP_BACKGROUND_STIPPLE_SET:
1666 g_value_set_boolean (value, tag->bg_stipple_set);
1669 case PROP_FOREGROUND_STIPPLE_SET:
1670 g_value_set_boolean (value, tag->fg_stipple_set);
1673 case PROP_FAMILY_SET:
1674 case PROP_STYLE_SET:
1675 case PROP_VARIANT_SET:
1676 case PROP_WEIGHT_SET:
1677 case PROP_STRETCH_SET:
1680 PangoFontMask set_mask = tag->values->font ? pango_font_description_get_set_fields (tag->values->font) : 0;
1681 PangoFontMask test_mask = get_property_font_set_mask (prop_id);
1682 g_value_set_boolean (value, (set_mask & test_mask) != 0);
1687 case PROP_SCALE_SET:
1688 g_value_set_boolean (value, tag->scale_set);
1691 case PROP_PIXELS_ABOVE_LINES_SET:
1692 g_value_set_boolean (value, tag->pixels_above_lines_set);
1695 case PROP_PIXELS_BELOW_LINES_SET:
1696 g_value_set_boolean (value, tag->pixels_below_lines_set);
1699 case PROP_PIXELS_INSIDE_WRAP_SET:
1700 g_value_set_boolean (value, tag->pixels_inside_wrap_set);
1703 case PROP_EDITABLE_SET:
1704 g_value_set_boolean (value, tag->editable_set);
1707 case PROP_WRAP_MODE_SET:
1708 g_value_set_boolean (value, tag->wrap_mode_set);
1711 case PROP_JUSTIFICATION_SET:
1712 g_value_set_boolean (value, tag->justification_set);
1715 case PROP_LEFT_MARGIN_SET:
1716 g_value_set_boolean (value, tag->left_margin_set);
1719 case PROP_INDENT_SET:
1720 g_value_set_boolean (value, tag->indent_set);
1723 case PROP_STRIKETHROUGH_SET:
1724 g_value_set_boolean (value, tag->strikethrough_set);
1727 case PROP_RIGHT_MARGIN_SET:
1728 g_value_set_boolean (value, tag->right_margin_set);
1731 case PROP_UNDERLINE_SET:
1732 g_value_set_boolean (value, tag->underline_set);
1736 g_value_set_boolean (value, tag->rise_set);
1739 case PROP_BACKGROUND_FULL_HEIGHT_SET:
1740 g_value_set_boolean (value, tag->bg_full_height_set);
1743 case PROP_LANGUAGE_SET:
1744 g_value_set_boolean (value, tag->language_set);
1748 g_value_set_boolean (value, tag->tabs_set);
1751 case PROP_INVISIBLE_SET:
1752 g_value_set_boolean (value, tag->invisible_set);
1755 case PROP_PARAGRAPH_BACKGROUND_SET:
1756 g_value_set_boolean (value, tag->pg_bg_color_set);
1759 case PROP_BACKGROUND:
1760 case PROP_FOREGROUND:
1761 case PROP_PARAGRAPH_BACKGROUND:
1762 g_warning ("'foreground', 'background' and 'paragraph_background' properties are not readable, use 'foreground_gdk', 'background_gdk' and 'paragraph_background_gdk'");
1764 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1780 delta_priority_foreach (GtkTextTag *tag, gpointer user_data)
1782 DeltaData *dd = user_data;
1784 if (tag->priority >= dd->low && tag->priority <= dd->high)
1785 tag->priority += dd->delta;
1789 * gtk_text_tag_get_priority:
1790 * @tag: a #GtkTextTag
1792 * Get the tag priority.
1794 * Return value: The tag's priority.
1797 gtk_text_tag_get_priority (GtkTextTag *tag)
1799 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), 0);
1801 return tag->priority;
1805 * gtk_text_tag_set_priority:
1806 * @tag: a #GtkTextTag
1807 * @priority: the new priority
1809 * Sets the priority of a #GtkTextTag. Valid priorities are
1810 * start at 0 and go to one less than gtk_text_tag_table_get_size().
1811 * Each tag in a table has a unique priority; setting the priority
1812 * of one tag shifts the priorities of all the other tags in the
1813 * table to maintain a unique priority for each tag. Higher priority
1814 * tags "win" if two tags both set the same text attribute. When adding
1815 * a tag to a tag table, it will be assigned the highest priority in
1816 * the table by default; so normally the precedence of a set of tags
1817 * is the order in which they were added to the table, or created with
1818 * gtk_text_buffer_create_tag(), which adds the tag to the buffer's table
1822 gtk_text_tag_set_priority (GtkTextTag *tag,
1827 g_return_if_fail (GTK_IS_TEXT_TAG (tag));
1828 g_return_if_fail (tag->table != NULL);
1829 g_return_if_fail (priority >= 0);
1830 g_return_if_fail (priority < gtk_text_tag_table_get_size (tag->table));
1832 if (priority == tag->priority)
1835 if (priority < tag->priority)
1838 dd.high = tag->priority - 1;
1843 dd.low = tag->priority + 1;
1848 gtk_text_tag_table_foreach (tag->table,
1849 delta_priority_foreach,
1852 tag->priority = priority;
1856 * gtk_text_tag_event:
1857 * @tag: a #GtkTextTag
1858 * @event_object: object that received the event, such as a widget
1860 * @iter: location where the event was received
1862 * Emits the "event" signal on the #GtkTextTag.
1864 * Return value: result of signal emission (whether the event was handled)
1867 gtk_text_tag_event (GtkTextTag *tag,
1868 GObject *event_object,
1870 const GtkTextIter *iter)
1872 gboolean retval = FALSE;
1874 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
1875 g_return_val_if_fail (G_IS_OBJECT (event_object), FALSE);
1876 g_return_val_if_fail (event != NULL, FALSE);
1890 tag_sort_func (gconstpointer first, gconstpointer second)
1892 GtkTextTag *tag1, *tag2;
1894 tag1 = * (GtkTextTag **) first;
1895 tag2 = * (GtkTextTag **) second;
1896 return tag1->priority - tag2->priority;
1900 _gtk_text_tag_array_sort (GtkTextTag** tag_array_p,
1905 GtkTextTag **maxPtrPtr, *tmp;
1907 g_return_if_fail (tag_array_p != NULL);
1908 g_return_if_fail (len > 0);
1914 GtkTextTag **iter = tag_array_p;
1916 for (i = len-1; i > 0; i--, iter++) {
1917 maxPtrPtr = tag = iter;
1918 prio = tag[0]->priority;
1919 for (j = i, tag++; j > 0; j--, tag++) {
1920 if (tag[0]->priority < prio) {
1921 prio = tag[0]->priority;
1930 qsort ((void *) tag_array_p, (unsigned) len, sizeof (GtkTextTag *),
1936 printf ("Sorted tag array: \n");
1940 GtkTextTag *t = tag_array_p[i];
1941 printf (" %s priority %d\n", t->name, t->priority);
1954 * gtk_text_attributes_new:
1956 * Creates a #GtkTextAttributes, which describes
1957 * a set of properties on some text.
1959 * Return value: a new #GtkTextAttributes
1962 gtk_text_attributes_new (void)
1964 GtkTextAttributes *values;
1966 values = g_new0 (GtkTextAttributes, 1);
1968 /* 0 is a valid value for most of the struct */
1970 values->refcount = 1;
1972 values->language = gtk_get_default_language ();
1974 values->font_scale = 1.0;
1976 values->editable = TRUE;
1982 * gtk_text_attributes_copy:
1983 * @src: a #GtkTextAttributes to be copied
1985 * Copies @src and returns a new #GtkTextAttributes.
1987 * Return value: a copy of @src
1990 gtk_text_attributes_copy (GtkTextAttributes *src)
1992 GtkTextAttributes *dest;
1994 dest = gtk_text_attributes_new ();
1995 gtk_text_attributes_copy_values (src, dest);
2001 gtk_text_attributes_get_type (void)
2003 static GType our_type = 0;
2006 our_type = g_boxed_type_register_static (I_("GtkTextAttributes"),
2007 (GBoxedCopyFunc) gtk_text_attributes_ref,
2008 (GBoxedFreeFunc) gtk_text_attributes_unref);
2014 * gtk_text_attributes_copy_values:
2015 * @src: a #GtkTextAttributes
2016 * @dest: another #GtkTextAttributes
2018 * Copies the values from @src to @dest so that @dest has the same values
2019 * as @src. Frees existing values in @dest.
2022 gtk_text_attributes_copy_values (GtkTextAttributes *src,
2023 GtkTextAttributes *dest)
2025 guint orig_refcount;
2027 g_return_if_fail (!dest->realized);
2034 if (src->appearance.bg_stipple)
2035 g_object_ref (src->appearance.bg_stipple);
2037 if (src->appearance.fg_stipple)
2038 g_object_ref (src->appearance.fg_stipple);
2042 if (dest->appearance.bg_stipple)
2043 g_object_unref (dest->appearance.bg_stipple);
2045 if (dest->appearance.fg_stipple)
2046 g_object_unref (dest->appearance.fg_stipple);
2049 pango_font_description_free (dest->font);
2052 orig_refcount = dest->refcount;
2057 dest->tabs = pango_tab_array_copy (src->tabs);
2059 dest->language = src->language;
2062 dest->font = pango_font_description_copy (src->font);
2064 if (src->pg_bg_color)
2065 dest->pg_bg_color = gdk_color_copy (src->pg_bg_color);
2067 dest->refcount = orig_refcount;
2068 dest->realized = FALSE;
2072 * gtk_text_attributes_ref:
2073 * @values: a #GtkTextAttributes
2075 * Increments the reference count on @values.
2077 * Returns: the #GtkTextAttributes that were passed in
2080 gtk_text_attributes_ref (GtkTextAttributes *values)
2082 g_return_val_if_fail (values != NULL, NULL);
2084 values->refcount += 1;
2090 * gtk_text_attributes_unref:
2091 * @values: a #GtkTextAttributes
2093 * Decrements the reference count on @values, freeing the structure
2094 * if the reference count reaches 0.
2097 gtk_text_attributes_unref (GtkTextAttributes *values)
2099 g_return_if_fail (values != NULL);
2100 g_return_if_fail (values->refcount > 0);
2102 values->refcount -= 1;
2104 if (values->refcount == 0)
2106 g_assert (!values->realized);
2108 if (values->appearance.bg_stipple)
2109 g_object_unref (values->appearance.bg_stipple);
2111 if (values->appearance.fg_stipple)
2112 g_object_unref (values->appearance.fg_stipple);
2115 pango_tab_array_free (values->tabs);
2118 pango_font_description_free (values->font);
2120 if (values->pg_bg_color)
2121 gdk_color_free (values->pg_bg_color);
2128 _gtk_text_attributes_realize (GtkTextAttributes *values,
2132 g_return_if_fail (values != NULL);
2133 g_return_if_fail (values->refcount > 0);
2134 g_return_if_fail (!values->realized);
2136 /* It is wrong to use this colormap, FIXME */
2137 gdk_colormap_alloc_color (cmap,
2138 &values->appearance.fg_color,
2141 gdk_colormap_alloc_color (cmap,
2142 &values->appearance.bg_color,
2145 if (values->pg_bg_color)
2146 gdk_colormap_alloc_color (cmap,
2147 values->pg_bg_color,
2150 values->realized = TRUE;
2154 _gtk_text_attributes_unrealize (GtkTextAttributes *values,
2158 g_return_if_fail (values != NULL);
2159 g_return_if_fail (values->refcount > 0);
2160 g_return_if_fail (values->realized);
2162 gdk_colormap_free_colors (cmap,
2163 &values->appearance.fg_color, 1);
2166 gdk_colormap_free_colors (cmap,
2167 &values->appearance.bg_color, 1);
2169 values->appearance.fg_color.pixel = 0;
2170 values->appearance.bg_color.pixel = 0;
2172 if (values->pg_bg_color)
2174 gdk_colormap_free_colors (cmap, values->pg_bg_color, 1);
2176 values->pg_bg_color->pixel = 0;
2179 values->realized = FALSE;
2183 _gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest,
2189 guint left_margin_accumulative = 0;
2190 guint right_margin_accumulative = 0;
2192 g_return_if_fail (!dest->realized);
2196 GtkTextTag *tag = tags[n];
2197 GtkTextAttributes *vals = tag->values;
2199 g_assert (tag->table != NULL);
2201 g_assert (tags[n]->priority > tags[n-1]->priority);
2203 if (tag->bg_color_set)
2205 dest->appearance.bg_color = vals->appearance.bg_color;
2207 dest->appearance.draw_bg = TRUE;
2209 if (tag->fg_color_set)
2210 dest->appearance.fg_color = vals->appearance.fg_color;
2212 if (tag->pg_bg_color_set)
2214 dest->pg_bg_color = gdk_color_copy (vals->pg_bg_color);
2217 if (tag->bg_stipple_set)
2219 g_object_ref (vals->appearance.bg_stipple);
2220 if (dest->appearance.bg_stipple)
2221 g_object_unref (dest->appearance.bg_stipple);
2222 dest->appearance.bg_stipple = vals->appearance.bg_stipple;
2224 dest->appearance.draw_bg = TRUE;
2227 if (tag->fg_stipple_set)
2229 g_object_ref (vals->appearance.fg_stipple);
2230 if (dest->appearance.fg_stipple)
2231 g_object_unref (dest->appearance.fg_stipple);
2232 dest->appearance.fg_stipple = vals->appearance.fg_stipple;
2238 pango_font_description_merge (dest->font, vals->font, TRUE);
2240 dest->font = pango_font_description_copy (vals->font);
2243 /* multiply all the scales together to get a composite */
2245 dest->font_scale *= vals->font_scale;
2247 if (tag->justification_set)
2248 dest->justification = vals->justification;
2250 if (vals->direction != GTK_TEXT_DIR_NONE)
2251 dest->direction = vals->direction;
2253 if (tag->left_margin_set)
2255 if (tag->accumulative_margin)
2256 left_margin_accumulative += vals->left_margin;
2258 dest->left_margin = vals->left_margin;
2261 if (tag->indent_set)
2262 dest->indent = vals->indent;
2265 dest->appearance.rise = vals->appearance.rise;
2267 if (tag->right_margin_set)
2269 if (tag->accumulative_margin)
2270 right_margin_accumulative += vals->right_margin;
2272 dest->right_margin = vals->right_margin;
2275 if (tag->pixels_above_lines_set)
2276 dest->pixels_above_lines = vals->pixels_above_lines;
2278 if (tag->pixels_below_lines_set)
2279 dest->pixels_below_lines = vals->pixels_below_lines;
2281 if (tag->pixels_inside_wrap_set)
2282 dest->pixels_inside_wrap = vals->pixels_inside_wrap;
2287 pango_tab_array_free (dest->tabs);
2288 dest->tabs = pango_tab_array_copy (vals->tabs);
2291 if (tag->wrap_mode_set)
2292 dest->wrap_mode = vals->wrap_mode;
2294 if (tag->underline_set)
2295 dest->appearance.underline = vals->appearance.underline;
2297 if (tag->strikethrough_set)
2298 dest->appearance.strikethrough = vals->appearance.strikethrough;
2300 if (tag->invisible_set)
2301 dest->invisible = vals->invisible;
2303 if (tag->editable_set)
2304 dest->editable = vals->editable;
2306 if (tag->bg_full_height_set)
2307 dest->bg_full_height = vals->bg_full_height;
2309 if (tag->language_set)
2310 dest->language = vals->language;
2315 dest->left_margin += left_margin_accumulative;
2316 dest->right_margin += right_margin_accumulative;
2320 _gtk_text_tag_affects_size (GtkTextTag *tag)
2322 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
2325 (tag->values->font && pango_font_description_get_set_fields (tag->values->font) != 0) ||
2327 tag->justification_set ||
2328 tag->left_margin_set ||
2331 tag->right_margin_set ||
2332 tag->pixels_above_lines_set ||
2333 tag->pixels_below_lines_set ||
2334 tag->pixels_inside_wrap_set ||
2336 tag->underline_set ||
2337 tag->wrap_mode_set ||
2342 _gtk_text_tag_affects_nonsize_appearance (GtkTextTag *tag)
2344 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
2347 tag->bg_color_set ||
2348 tag->bg_stipple_set ||
2349 tag->fg_color_set ||
2350 tag->fg_stipple_set ||
2351 tag->strikethrough_set ||
2352 tag->bg_full_height_set ||
2353 tag->pg_bg_color_set;
2356 #define __GTK_TEXT_TAG_C__
2357 #include "gtkaliasdef.c"