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 (gdk_color_parse (g_value_get_string (value), &color))
1006 set_bg_color (text_tag, &color);
1008 g_warning ("Don't know color `%s'", g_value_get_string (value));
1010 g_object_notify (object, "background-gdk");
1014 case PROP_FOREGROUND:
1018 if (gdk_color_parse (g_value_get_string (value), &color))
1019 set_fg_color (text_tag, &color);
1021 g_warning ("Don't know color `%s'", g_value_get_string (value));
1023 g_object_notify (object, "foreground-gdk");
1027 case PROP_BACKGROUND_GDK:
1029 GdkColor *color = g_value_get_boxed (value);
1031 set_bg_color (text_tag, color);
1035 case PROP_FOREGROUND_GDK:
1037 GdkColor *color = g_value_get_boxed (value);
1039 set_fg_color (text_tag, color);
1043 case PROP_BACKGROUND_STIPPLE:
1045 GdkBitmap *bitmap = g_value_get_object (value);
1047 text_tag->bg_stipple_set = TRUE;
1048 g_object_notify (object, "background-stipple-set");
1050 if (text_tag->values->appearance.bg_stipple != bitmap)
1053 g_object_ref (bitmap);
1055 if (text_tag->values->appearance.bg_stipple)
1056 g_object_unref (text_tag->values->appearance.bg_stipple);
1058 text_tag->values->appearance.bg_stipple = bitmap;
1063 case PROP_FOREGROUND_STIPPLE:
1065 GdkBitmap *bitmap = g_value_get_object (value);
1067 text_tag->fg_stipple_set = TRUE;
1068 g_object_notify (object, "foreground-stipple-set");
1070 if (text_tag->values->appearance.fg_stipple != bitmap)
1073 g_object_ref (bitmap);
1075 if (text_tag->values->appearance.fg_stipple)
1076 g_object_unref (text_tag->values->appearance.fg_stipple);
1078 text_tag->values->appearance.fg_stipple = bitmap;
1085 PangoFontDescription *font_desc = NULL;
1088 name = g_value_get_string (value);
1091 font_desc = pango_font_description_from_string (name);
1093 set_font_description (text_tag, font_desc);
1095 pango_font_description_free (font_desc);
1097 size_changed = TRUE;
1101 case PROP_FONT_DESC:
1103 PangoFontDescription *font_desc;
1105 font_desc = g_value_get_boxed (value);
1107 set_font_description (text_tag, font_desc);
1109 size_changed = TRUE;
1119 case PROP_SIZE_POINTS:
1121 PangoFontMask old_set_mask;
1123 gtk_text_tag_ensure_font (text_tag);
1124 old_set_mask = pango_font_description_get_set_fields (text_tag->values->font);
1129 pango_font_description_set_family (text_tag->values->font,
1130 g_value_get_string (value));
1133 pango_font_description_set_style (text_tag->values->font,
1134 g_value_get_enum (value));
1137 pango_font_description_set_variant (text_tag->values->font,
1138 g_value_get_enum (value));
1141 pango_font_description_set_weight (text_tag->values->font,
1142 g_value_get_int (value));
1145 pango_font_description_set_stretch (text_tag->values->font,
1146 g_value_get_enum (value));
1149 pango_font_description_set_size (text_tag->values->font,
1150 g_value_get_int (value));
1151 g_object_notify (object, "size-points");
1153 case PROP_SIZE_POINTS:
1154 pango_font_description_set_size (text_tag->values->font,
1155 g_value_get_double (value) * PANGO_SCALE);
1156 g_object_notify (object, "size");
1160 size_changed = TRUE;
1161 notify_set_changed (object, old_set_mask & pango_font_description_get_set_fields (text_tag->values->font));
1162 g_object_notify (object, "font-desc");
1163 g_object_notify (object, "font");
1169 text_tag->values->font_scale = g_value_get_double (value);
1170 text_tag->scale_set = TRUE;
1171 g_object_notify (object, "scale-set");
1172 size_changed = TRUE;
1175 case PROP_PIXELS_ABOVE_LINES:
1176 text_tag->pixels_above_lines_set = TRUE;
1177 text_tag->values->pixels_above_lines = g_value_get_int (value);
1178 g_object_notify (object, "pixels-above-lines-set");
1179 size_changed = TRUE;
1182 case PROP_PIXELS_BELOW_LINES:
1183 text_tag->pixels_below_lines_set = TRUE;
1184 text_tag->values->pixels_below_lines = g_value_get_int (value);
1185 g_object_notify (object, "pixels-below-lines-set");
1186 size_changed = TRUE;
1189 case PROP_PIXELS_INSIDE_WRAP:
1190 text_tag->pixels_inside_wrap_set = TRUE;
1191 text_tag->values->pixels_inside_wrap = g_value_get_int (value);
1192 g_object_notify (object, "pixels-inside-wrap-set");
1193 size_changed = TRUE;
1197 text_tag->editable_set = TRUE;
1198 text_tag->values->editable = g_value_get_boolean (value);
1199 g_object_notify (object, "editable-set");
1202 case PROP_WRAP_MODE:
1203 text_tag->wrap_mode_set = TRUE;
1204 text_tag->values->wrap_mode = g_value_get_enum (value);
1205 g_object_notify (object, "wrap-mode-set");
1206 size_changed = TRUE;
1209 case PROP_JUSTIFICATION:
1210 text_tag->justification_set = TRUE;
1211 text_tag->values->justification = g_value_get_enum (value);
1212 g_object_notify (object, "justification-set");
1213 size_changed = TRUE;
1216 case PROP_DIRECTION:
1217 text_tag->values->direction = g_value_get_enum (value);
1220 case PROP_LEFT_MARGIN:
1221 text_tag->left_margin_set = TRUE;
1222 text_tag->values->left_margin = g_value_get_int (value);
1223 g_object_notify (object, "left-margin-set");
1224 size_changed = TRUE;
1228 text_tag->indent_set = TRUE;
1229 text_tag->values->indent = g_value_get_int (value);
1230 g_object_notify (object, "indent-set");
1231 size_changed = TRUE;
1234 case PROP_STRIKETHROUGH:
1235 text_tag->strikethrough_set = TRUE;
1236 text_tag->values->appearance.strikethrough = g_value_get_boolean (value);
1237 g_object_notify (object, "strikethrough-set");
1240 case PROP_RIGHT_MARGIN:
1241 text_tag->right_margin_set = TRUE;
1242 text_tag->values->right_margin = g_value_get_int (value);
1243 g_object_notify (object, "right-margin-set");
1244 size_changed = TRUE;
1247 case PROP_UNDERLINE:
1248 text_tag->underline_set = TRUE;
1249 text_tag->values->appearance.underline = g_value_get_enum (value);
1250 g_object_notify (object, "underline-set");
1254 text_tag->rise_set = TRUE;
1255 text_tag->values->appearance.rise = g_value_get_int (value);
1256 g_object_notify (object, "rise-set");
1257 size_changed = TRUE;
1260 case PROP_BACKGROUND_FULL_HEIGHT:
1261 text_tag->bg_full_height_set = TRUE;
1262 text_tag->values->bg_full_height = g_value_get_boolean (value);
1263 g_object_notify (object, "background-full-height-set");
1267 text_tag->language_set = TRUE;
1268 text_tag->values->language = pango_language_from_string (g_value_get_string (value));
1269 g_object_notify (object, "language-set");
1273 text_tag->tabs_set = TRUE;
1275 if (text_tag->values->tabs)
1276 pango_tab_array_free (text_tag->values->tabs);
1278 /* FIXME I'm not sure if this is a memleak or not */
1279 text_tag->values->tabs =
1280 pango_tab_array_copy (g_value_get_boxed (value));
1282 g_object_notify (object, "tabs-set");
1284 size_changed = TRUE;
1287 case PROP_INVISIBLE:
1288 text_tag->invisible_set = TRUE;
1289 text_tag->values->invisible = g_value_get_boolean (value);
1290 g_object_notify (object, "invisible-set");
1291 size_changed = TRUE;
1294 case PROP_PARAGRAPH_BACKGROUND:
1298 if (gdk_color_parse (g_value_get_string (value), &color))
1299 set_pg_bg_color (text_tag, &color);
1301 g_warning ("Don't know color `%s'", g_value_get_string (value));
1303 g_object_notify (object, "paragraph-background-gdk");
1307 case PROP_PARAGRAPH_BACKGROUND_GDK:
1309 GdkColor *color = g_value_get_boxed (value);
1311 set_pg_bg_color (text_tag, color);
1315 case PROP_ACCUMULATIVE_MARGIN:
1316 text_tag->accumulative_margin = g_value_get_boolean (value);
1317 g_object_notify (object, "accumulative-margin");
1318 size_changed = TRUE;
1321 /* Whether the value should be used... */
1323 case PROP_BACKGROUND_SET:
1324 text_tag->bg_color_set = g_value_get_boolean (value);
1327 case PROP_FOREGROUND_SET:
1328 text_tag->fg_color_set = g_value_get_boolean (value);
1331 case PROP_BACKGROUND_STIPPLE_SET:
1332 text_tag->bg_stipple_set = g_value_get_boolean (value);
1333 if (!text_tag->bg_stipple_set &&
1334 text_tag->values->appearance.bg_stipple)
1336 g_object_unref (text_tag->values->appearance.bg_stipple);
1337 text_tag->values->appearance.bg_stipple = NULL;
1341 case PROP_FOREGROUND_STIPPLE_SET:
1342 text_tag->fg_stipple_set = g_value_get_boolean (value);
1343 if (!text_tag->fg_stipple_set &&
1344 text_tag->values->appearance.fg_stipple)
1346 g_object_unref (text_tag->values->appearance.fg_stipple);
1347 text_tag->values->appearance.fg_stipple = NULL;
1351 case PROP_FAMILY_SET:
1352 case PROP_STYLE_SET:
1353 case PROP_VARIANT_SET:
1354 case PROP_WEIGHT_SET:
1355 case PROP_STRETCH_SET:
1357 if (!g_value_get_boolean (value))
1359 if (text_tag->values->font)
1360 pango_font_description_unset_fields (text_tag->values->font,
1361 get_property_font_set_mask (prop_id));
1365 PangoFontMask changed_mask;
1367 gtk_text_tag_ensure_font (text_tag);
1368 changed_mask = set_font_desc_fields (text_tag->values->font,
1369 get_property_font_set_mask (prop_id));
1370 notify_fields_changed (G_OBJECT (text_tag), changed_mask);
1374 case PROP_SCALE_SET:
1375 text_tag->scale_set = g_value_get_boolean (value);
1376 size_changed = TRUE;
1379 case PROP_PIXELS_ABOVE_LINES_SET:
1380 text_tag->pixels_above_lines_set = g_value_get_boolean (value);
1381 size_changed = TRUE;
1384 case PROP_PIXELS_BELOW_LINES_SET:
1385 text_tag->pixels_below_lines_set = g_value_get_boolean (value);
1386 size_changed = TRUE;
1389 case PROP_PIXELS_INSIDE_WRAP_SET:
1390 text_tag->pixels_inside_wrap_set = g_value_get_boolean (value);
1391 size_changed = TRUE;
1394 case PROP_EDITABLE_SET:
1395 text_tag->editable_set = g_value_get_boolean (value);
1398 case PROP_WRAP_MODE_SET:
1399 text_tag->wrap_mode_set = g_value_get_boolean (value);
1400 size_changed = TRUE;
1403 case PROP_JUSTIFICATION_SET:
1404 text_tag->justification_set = g_value_get_boolean (value);
1405 size_changed = TRUE;
1408 case PROP_LEFT_MARGIN_SET:
1409 text_tag->left_margin_set = g_value_get_boolean (value);
1410 size_changed = TRUE;
1413 case PROP_INDENT_SET:
1414 text_tag->indent_set = g_value_get_boolean (value);
1415 size_changed = TRUE;
1418 case PROP_STRIKETHROUGH_SET:
1419 text_tag->strikethrough_set = g_value_get_boolean (value);
1422 case PROP_RIGHT_MARGIN_SET:
1423 text_tag->right_margin_set = g_value_get_boolean (value);
1424 size_changed = TRUE;
1427 case PROP_UNDERLINE_SET:
1428 text_tag->underline_set = g_value_get_boolean (value);
1432 text_tag->rise_set = g_value_get_boolean (value);
1433 size_changed = TRUE;
1436 case PROP_BACKGROUND_FULL_HEIGHT_SET:
1437 text_tag->bg_full_height_set = g_value_get_boolean (value);
1440 case PROP_LANGUAGE_SET:
1441 text_tag->language_set = g_value_get_boolean (value);
1442 size_changed = TRUE;
1446 text_tag->tabs_set = g_value_get_boolean (value);
1447 size_changed = TRUE;
1450 case PROP_INVISIBLE_SET:
1451 text_tag->invisible_set = g_value_get_boolean (value);
1452 size_changed = TRUE;
1455 case PROP_PARAGRAPH_BACKGROUND_SET:
1456 text_tag->pg_bg_color_set = g_value_get_boolean (value);
1460 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1464 /* FIXME I would like to do this after all set_property in a single
1465 * g_object_set () have been called. But an idle function won't
1466 * work; we need to emit when the tag is changed, not when we get
1467 * around to the event loop. So blah, we eat some inefficiency.
1470 /* This is also somewhat weird since we emit another object's
1471 * signal here, but the two objects are already tightly bound.
1474 if (text_tag->table)
1475 g_signal_emit_by_name (text_tag->table,
1477 text_tag, size_changed);
1481 gtk_text_tag_get_property (GObject *object,
1488 tag = GTK_TEXT_TAG (object);
1493 g_value_set_string (value, tag->name);
1496 case PROP_BACKGROUND_GDK:
1497 g_value_set_boxed (value, &tag->values->appearance.bg_color);
1500 case PROP_FOREGROUND_GDK:
1501 g_value_set_boxed (value, &tag->values->appearance.fg_color);
1504 case PROP_BACKGROUND_STIPPLE:
1505 if (tag->bg_stipple_set)
1506 g_value_set_object (value, tag->values->appearance.bg_stipple);
1509 case PROP_FOREGROUND_STIPPLE:
1510 if (tag->fg_stipple_set)
1511 g_value_set_object (value, tag->values->appearance.fg_stipple);
1518 gtk_text_tag_ensure_font (tag);
1520 str = pango_font_description_to_string (tag->values->font);
1521 g_value_take_string (value, str);
1525 case PROP_FONT_DESC:
1526 gtk_text_tag_ensure_font (tag);
1527 g_value_set_boxed (value, tag->values->font);
1536 case PROP_SIZE_POINTS:
1537 gtk_text_tag_ensure_font (tag);
1541 g_value_set_string (value, pango_font_description_get_family (tag->values->font));
1545 g_value_set_enum (value, pango_font_description_get_style (tag->values->font));
1549 g_value_set_enum (value, pango_font_description_get_variant (tag->values->font));
1553 g_value_set_int (value, pango_font_description_get_weight (tag->values->font));
1557 g_value_set_enum (value, pango_font_description_get_stretch (tag->values->font));
1561 g_value_set_int (value, pango_font_description_get_size (tag->values->font));
1564 case PROP_SIZE_POINTS:
1565 g_value_set_double (value, ((double)pango_font_description_get_size (tag->values->font)) / (double)PANGO_SCALE);
1571 g_value_set_double (value, tag->values->font_scale);
1574 case PROP_PIXELS_ABOVE_LINES:
1575 g_value_set_int (value, tag->values->pixels_above_lines);
1578 case PROP_PIXELS_BELOW_LINES:
1579 g_value_set_int (value, tag->values->pixels_below_lines);
1582 case PROP_PIXELS_INSIDE_WRAP:
1583 g_value_set_int (value, tag->values->pixels_inside_wrap);
1587 g_value_set_boolean (value, tag->values->editable);
1590 case PROP_WRAP_MODE:
1591 g_value_set_enum (value, tag->values->wrap_mode);
1594 case PROP_JUSTIFICATION:
1595 g_value_set_enum (value, tag->values->justification);
1598 case PROP_DIRECTION:
1599 g_value_set_enum (value, tag->values->direction);
1602 case PROP_LEFT_MARGIN:
1603 g_value_set_int (value, tag->values->left_margin);
1607 g_value_set_int (value, tag->values->indent);
1610 case PROP_STRIKETHROUGH:
1611 g_value_set_boolean (value, tag->values->appearance.strikethrough);
1614 case PROP_RIGHT_MARGIN:
1615 g_value_set_int (value, tag->values->right_margin);
1618 case PROP_UNDERLINE:
1619 g_value_set_enum (value, tag->values->appearance.underline);
1623 g_value_set_int (value, tag->values->appearance.rise);
1626 case PROP_BACKGROUND_FULL_HEIGHT:
1627 g_value_set_boolean (value, tag->values->bg_full_height);
1631 g_value_set_string (value, pango_language_to_string (tag->values->language));
1635 if (tag->values->tabs)
1636 g_value_set_boxed (value, tag->values->tabs);
1639 case PROP_INVISIBLE:
1640 g_value_set_boolean (value, tag->values->invisible);
1643 case PROP_PARAGRAPH_BACKGROUND_GDK:
1644 g_value_set_boxed (value, tag->values->pg_bg_color);
1647 case PROP_ACCUMULATIVE_MARGIN:
1648 g_value_set_boolean (value, tag->accumulative_margin);
1651 case PROP_BACKGROUND_SET:
1652 g_value_set_boolean (value, tag->bg_color_set);
1655 case PROP_FOREGROUND_SET:
1656 g_value_set_boolean (value, tag->fg_color_set);
1659 case PROP_BACKGROUND_STIPPLE_SET:
1660 g_value_set_boolean (value, tag->bg_stipple_set);
1663 case PROP_FOREGROUND_STIPPLE_SET:
1664 g_value_set_boolean (value, tag->fg_stipple_set);
1667 case PROP_FAMILY_SET:
1668 case PROP_STYLE_SET:
1669 case PROP_VARIANT_SET:
1670 case PROP_WEIGHT_SET:
1671 case PROP_STRETCH_SET:
1674 PangoFontMask set_mask = tag->values->font ? pango_font_description_get_set_fields (tag->values->font) : 0;
1675 PangoFontMask test_mask = get_property_font_set_mask (prop_id);
1676 g_value_set_boolean (value, (set_mask & test_mask) != 0);
1681 case PROP_SCALE_SET:
1682 g_value_set_boolean (value, tag->scale_set);
1685 case PROP_PIXELS_ABOVE_LINES_SET:
1686 g_value_set_boolean (value, tag->pixels_above_lines_set);
1689 case PROP_PIXELS_BELOW_LINES_SET:
1690 g_value_set_boolean (value, tag->pixels_below_lines_set);
1693 case PROP_PIXELS_INSIDE_WRAP_SET:
1694 g_value_set_boolean (value, tag->pixels_inside_wrap_set);
1697 case PROP_EDITABLE_SET:
1698 g_value_set_boolean (value, tag->editable_set);
1701 case PROP_WRAP_MODE_SET:
1702 g_value_set_boolean (value, tag->wrap_mode_set);
1705 case PROP_JUSTIFICATION_SET:
1706 g_value_set_boolean (value, tag->justification_set);
1709 case PROP_LEFT_MARGIN_SET:
1710 g_value_set_boolean (value, tag->left_margin_set);
1713 case PROP_INDENT_SET:
1714 g_value_set_boolean (value, tag->indent_set);
1717 case PROP_STRIKETHROUGH_SET:
1718 g_value_set_boolean (value, tag->strikethrough_set);
1721 case PROP_RIGHT_MARGIN_SET:
1722 g_value_set_boolean (value, tag->right_margin_set);
1725 case PROP_UNDERLINE_SET:
1726 g_value_set_boolean (value, tag->underline_set);
1730 g_value_set_boolean (value, tag->rise_set);
1733 case PROP_BACKGROUND_FULL_HEIGHT_SET:
1734 g_value_set_boolean (value, tag->bg_full_height_set);
1737 case PROP_LANGUAGE_SET:
1738 g_value_set_boolean (value, tag->language_set);
1742 g_value_set_boolean (value, tag->tabs_set);
1745 case PROP_INVISIBLE_SET:
1746 g_value_set_boolean (value, tag->invisible_set);
1749 case PROP_PARAGRAPH_BACKGROUND_SET:
1750 g_value_set_boolean (value, tag->pg_bg_color_set);
1753 case PROP_BACKGROUND:
1754 case PROP_FOREGROUND:
1755 case PROP_PARAGRAPH_BACKGROUND:
1756 g_warning ("'foreground', 'background' and 'paragraph_background' properties are not readable, use 'foreground_gdk', 'background_gdk' and 'paragraph_background_gdk'");
1758 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1774 delta_priority_foreach (GtkTextTag *tag, gpointer user_data)
1776 DeltaData *dd = user_data;
1778 if (tag->priority >= dd->low && tag->priority <= dd->high)
1779 tag->priority += dd->delta;
1783 * gtk_text_tag_get_priority:
1784 * @tag: a #GtkTextTag
1786 * Get the tag priority.
1788 * Return value: The tag's priority.
1791 gtk_text_tag_get_priority (GtkTextTag *tag)
1793 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), 0);
1795 return tag->priority;
1799 * gtk_text_tag_set_priority:
1800 * @tag: a #GtkTextTag
1801 * @priority: the new priority
1803 * Sets the priority of a #GtkTextTag. Valid priorities are
1804 * start at 0 and go to one less than gtk_text_tag_table_get_size().
1805 * Each tag in a table has a unique priority; setting the priority
1806 * of one tag shifts the priorities of all the other tags in the
1807 * table to maintain a unique priority for each tag. Higher priority
1808 * tags "win" if two tags both set the same text attribute. When adding
1809 * a tag to a tag table, it will be assigned the highest priority in
1810 * the table by default; so normally the precedence of a set of tags
1811 * is the order in which they were added to the table, or created with
1812 * gtk_text_buffer_create_tag(), which adds the tag to the buffer's table
1816 gtk_text_tag_set_priority (GtkTextTag *tag,
1821 g_return_if_fail (GTK_IS_TEXT_TAG (tag));
1822 g_return_if_fail (tag->table != NULL);
1823 g_return_if_fail (priority >= 0);
1824 g_return_if_fail (priority < gtk_text_tag_table_get_size (tag->table));
1826 if (priority == tag->priority)
1829 if (priority < tag->priority)
1832 dd.high = tag->priority - 1;
1837 dd.low = tag->priority + 1;
1842 gtk_text_tag_table_foreach (tag->table,
1843 delta_priority_foreach,
1846 tag->priority = priority;
1850 * gtk_text_tag_event:
1851 * @tag: a #GtkTextTag
1852 * @event_object: object that received the event, such as a widget
1854 * @iter: location where the event was received
1856 * Emits the "event" signal on the #GtkTextTag.
1858 * Return value: result of signal emission (whether the event was handled)
1861 gtk_text_tag_event (GtkTextTag *tag,
1862 GObject *event_object,
1864 const GtkTextIter *iter)
1866 gboolean retval = FALSE;
1868 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
1869 g_return_val_if_fail (G_IS_OBJECT (event_object), FALSE);
1870 g_return_val_if_fail (event != NULL, FALSE);
1884 tag_sort_func (gconstpointer first, gconstpointer second)
1886 GtkTextTag *tag1, *tag2;
1888 tag1 = * (GtkTextTag **) first;
1889 tag2 = * (GtkTextTag **) second;
1890 return tag1->priority - tag2->priority;
1894 _gtk_text_tag_array_sort (GtkTextTag** tag_array_p,
1899 GtkTextTag **maxPtrPtr, *tmp;
1901 g_return_if_fail (tag_array_p != NULL);
1902 g_return_if_fail (len > 0);
1908 GtkTextTag **iter = tag_array_p;
1910 for (i = len-1; i > 0; i--, iter++) {
1911 maxPtrPtr = tag = iter;
1912 prio = tag[0]->priority;
1913 for (j = i, tag++; j > 0; j--, tag++) {
1914 if (tag[0]->priority < prio) {
1915 prio = tag[0]->priority;
1924 qsort ((void *) tag_array_p, (unsigned) len, sizeof (GtkTextTag *),
1930 printf ("Sorted tag array: \n");
1934 GtkTextTag *t = tag_array_p[i];
1935 printf (" %s priority %d\n", t->name, t->priority);
1948 * gtk_text_attributes_new:
1950 * Creates a #GtkTextAttributes, which describes
1951 * a set of properties on some text.
1953 * Return value: a new #GtkTextAttributes
1956 gtk_text_attributes_new (void)
1958 GtkTextAttributes *values;
1960 values = g_new0 (GtkTextAttributes, 1);
1962 /* 0 is a valid value for most of the struct */
1964 values->refcount = 1;
1966 values->language = gtk_get_default_language ();
1968 values->font_scale = 1.0;
1970 values->editable = TRUE;
1976 * gtk_text_attributes_copy:
1977 * @src: a #GtkTextAttributes to be copied
1979 * Copies @src and returns a new #GtkTextAttributes.
1981 * Return value: a copy of @src
1984 gtk_text_attributes_copy (GtkTextAttributes *src)
1986 GtkTextAttributes *dest;
1988 dest = gtk_text_attributes_new ();
1989 gtk_text_attributes_copy_values (src, dest);
1995 gtk_text_attributes_get_type (void)
1997 static GType our_type = 0;
2000 our_type = g_boxed_type_register_static (I_("GtkTextAttributes"),
2001 (GBoxedCopyFunc) gtk_text_attributes_ref,
2002 (GBoxedFreeFunc) gtk_text_attributes_unref);
2008 * gtk_text_attributes_copy_values:
2009 * @src: a #GtkTextAttributes
2010 * @dest: another #GtkTextAttributes
2012 * Copies the values from @src to @dest so that @dest has the same values
2013 * as @src. Frees existing values in @dest.
2016 gtk_text_attributes_copy_values (GtkTextAttributes *src,
2017 GtkTextAttributes *dest)
2019 guint orig_refcount;
2021 g_return_if_fail (!dest->realized);
2028 if (src->appearance.bg_stipple)
2029 g_object_ref (src->appearance.bg_stipple);
2031 if (src->appearance.fg_stipple)
2032 g_object_ref (src->appearance.fg_stipple);
2036 if (dest->appearance.bg_stipple)
2037 g_object_unref (dest->appearance.bg_stipple);
2039 if (dest->appearance.fg_stipple)
2040 g_object_unref (dest->appearance.fg_stipple);
2043 pango_font_description_free (dest->font);
2046 orig_refcount = dest->refcount;
2051 dest->tabs = pango_tab_array_copy (src->tabs);
2053 dest->language = src->language;
2056 dest->font = pango_font_description_copy (src->font);
2058 if (src->pg_bg_color)
2059 dest->pg_bg_color = gdk_color_copy (src->pg_bg_color);
2061 dest->refcount = orig_refcount;
2062 dest->realized = FALSE;
2066 * gtk_text_attributes_ref:
2067 * @values: a #GtkTextAttributes
2069 * Increments the reference count on @values.
2071 * Returns: the #GtkTextAttributes that were passed in
2074 gtk_text_attributes_ref (GtkTextAttributes *values)
2076 g_return_val_if_fail (values != NULL, NULL);
2078 values->refcount += 1;
2084 * gtk_text_attributes_unref:
2085 * @values: a #GtkTextAttributes
2087 * Decrements the reference count on @values, freeing the structure
2088 * if the reference count reaches 0.
2091 gtk_text_attributes_unref (GtkTextAttributes *values)
2093 g_return_if_fail (values != NULL);
2094 g_return_if_fail (values->refcount > 0);
2096 values->refcount -= 1;
2098 if (values->refcount == 0)
2100 g_assert (!values->realized);
2102 if (values->appearance.bg_stipple)
2103 g_object_unref (values->appearance.bg_stipple);
2105 if (values->appearance.fg_stipple)
2106 g_object_unref (values->appearance.fg_stipple);
2109 pango_tab_array_free (values->tabs);
2112 pango_font_description_free (values->font);
2114 if (values->pg_bg_color)
2115 gdk_color_free (values->pg_bg_color);
2122 _gtk_text_attributes_realize (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 /* It is wrong to use this colormap, FIXME */
2131 gdk_colormap_alloc_color (cmap,
2132 &values->appearance.fg_color,
2135 gdk_colormap_alloc_color (cmap,
2136 &values->appearance.bg_color,
2139 if (values->pg_bg_color)
2140 gdk_colormap_alloc_color (cmap,
2141 values->pg_bg_color,
2144 values->realized = TRUE;
2148 _gtk_text_attributes_unrealize (GtkTextAttributes *values,
2152 g_return_if_fail (values != NULL);
2153 g_return_if_fail (values->refcount > 0);
2154 g_return_if_fail (values->realized);
2156 gdk_colormap_free_colors (cmap,
2157 &values->appearance.fg_color, 1);
2160 gdk_colormap_free_colors (cmap,
2161 &values->appearance.bg_color, 1);
2163 values->appearance.fg_color.pixel = 0;
2164 values->appearance.bg_color.pixel = 0;
2166 if (values->pg_bg_color)
2168 gdk_colormap_free_colors (cmap, values->pg_bg_color, 1);
2170 values->pg_bg_color->pixel = 0;
2173 values->realized = FALSE;
2177 _gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest,
2183 guint left_margin_accumulative = 0;
2184 guint right_margin_accumulative = 0;
2186 g_return_if_fail (!dest->realized);
2190 GtkTextTag *tag = tags[n];
2191 GtkTextAttributes *vals = tag->values;
2193 g_assert (tag->table != NULL);
2195 g_assert (tags[n]->priority > tags[n-1]->priority);
2197 if (tag->bg_color_set)
2199 dest->appearance.bg_color = vals->appearance.bg_color;
2201 dest->appearance.draw_bg = TRUE;
2203 if (tag->fg_color_set)
2204 dest->appearance.fg_color = vals->appearance.fg_color;
2206 if (tag->pg_bg_color_set)
2208 dest->pg_bg_color = gdk_color_copy (vals->pg_bg_color);
2211 if (tag->bg_stipple_set)
2213 g_object_ref (vals->appearance.bg_stipple);
2214 if (dest->appearance.bg_stipple)
2215 g_object_unref (dest->appearance.bg_stipple);
2216 dest->appearance.bg_stipple = vals->appearance.bg_stipple;
2218 dest->appearance.draw_bg = TRUE;
2221 if (tag->fg_stipple_set)
2223 g_object_ref (vals->appearance.fg_stipple);
2224 if (dest->appearance.fg_stipple)
2225 g_object_unref (dest->appearance.fg_stipple);
2226 dest->appearance.fg_stipple = vals->appearance.fg_stipple;
2232 pango_font_description_merge (dest->font, vals->font, TRUE);
2234 dest->font = pango_font_description_copy (vals->font);
2237 /* multiply all the scales together to get a composite */
2239 dest->font_scale *= vals->font_scale;
2241 if (tag->justification_set)
2242 dest->justification = vals->justification;
2244 if (vals->direction != GTK_TEXT_DIR_NONE)
2245 dest->direction = vals->direction;
2247 if (tag->left_margin_set)
2249 if (tag->accumulative_margin)
2250 left_margin_accumulative += vals->left_margin;
2252 dest->left_margin = vals->left_margin;
2255 if (tag->indent_set)
2256 dest->indent = vals->indent;
2259 dest->appearance.rise = vals->appearance.rise;
2261 if (tag->right_margin_set)
2263 if (tag->accumulative_margin)
2264 right_margin_accumulative += vals->right_margin;
2266 dest->right_margin = vals->right_margin;
2269 if (tag->pixels_above_lines_set)
2270 dest->pixels_above_lines = vals->pixels_above_lines;
2272 if (tag->pixels_below_lines_set)
2273 dest->pixels_below_lines = vals->pixels_below_lines;
2275 if (tag->pixels_inside_wrap_set)
2276 dest->pixels_inside_wrap = vals->pixels_inside_wrap;
2281 pango_tab_array_free (dest->tabs);
2282 dest->tabs = pango_tab_array_copy (vals->tabs);
2285 if (tag->wrap_mode_set)
2286 dest->wrap_mode = vals->wrap_mode;
2288 if (tag->underline_set)
2289 dest->appearance.underline = vals->appearance.underline;
2291 if (tag->strikethrough_set)
2292 dest->appearance.strikethrough = vals->appearance.strikethrough;
2294 if (tag->invisible_set)
2295 dest->invisible = vals->invisible;
2297 if (tag->editable_set)
2298 dest->editable = vals->editable;
2300 if (tag->bg_full_height_set)
2301 dest->bg_full_height = vals->bg_full_height;
2303 if (tag->language_set)
2304 dest->language = vals->language;
2309 dest->left_margin += left_margin_accumulative;
2310 dest->right_margin += right_margin_accumulative;
2314 _gtk_text_tag_affects_size (GtkTextTag *tag)
2316 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
2319 (tag->values->font && pango_font_description_get_set_fields (tag->values->font) != 0) ||
2321 tag->justification_set ||
2322 tag->left_margin_set ||
2325 tag->right_margin_set ||
2326 tag->pixels_above_lines_set ||
2327 tag->pixels_below_lines_set ||
2328 tag->pixels_inside_wrap_set ||
2330 tag->underline_set ||
2331 tag->wrap_mode_set ||
2336 _gtk_text_tag_affects_nonsize_appearance (GtkTextTag *tag)
2338 g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
2341 tag->bg_color_set ||
2342 tag->bg_stipple_set ||
2343 tag->fg_color_set ||
2344 tag->fg_stipple_set ||
2345 tag->strikethrough_set ||
2346 tag->bg_full_height_set ||
2347 tag->pg_bg_color_set;
2350 #define __GTK_TEXT_TAG_C__
2351 #include "gtkaliasdef.c"