]> Pileus Git - ~andy/gtk/blob - gtk/gtktexttag.c
82fdc836f2be1449c68088a2b3c90e26bcc45e5b
[~andy/gtk] / gtk / gtktexttag.c
1 /* gtktexttag.c - text tag object
2  *
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>
7  *
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.
12  *
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.
22  *
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.
28  *
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.
35  *
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.
47  *
48  */
49
50 #include "gtkmain.h"
51 #include "gtktexttag.h"
52 #include "gtktexttypes.h"
53 #include "gtktexttagtable.h"
54 #include "gtksignal.h"
55 #include "gtkmain.h"
56 #include "gtkintl.h"
57 #include "gtkmarshalers.h"
58 #include "gtktypebuiltins.h"
59
60 #include <stdlib.h>
61 #include <string.h>
62
63 enum {
64   EVENT,
65   LAST_SIGNAL
66 };
67
68 enum {
69   PROP_0,
70   /* Construct args */
71   PROP_NAME,
72
73   /* Style args */
74   PROP_BACKGROUND,
75   PROP_FOREGROUND,
76   PROP_BACKGROUND_GDK,
77   PROP_FOREGROUND_GDK,
78   PROP_BACKGROUND_STIPPLE,
79   PROP_FOREGROUND_STIPPLE,
80   PROP_FONT,
81   PROP_FONT_DESC,
82   PROP_FAMILY,
83   PROP_STYLE,
84   PROP_VARIANT,
85   PROP_WEIGHT,
86   PROP_STRETCH,
87   PROP_SIZE,
88   PROP_SIZE_POINTS,
89   PROP_SCALE,
90   PROP_PIXELS_ABOVE_LINES,
91   PROP_PIXELS_BELOW_LINES,
92   PROP_PIXELS_INSIDE_WRAP,
93   PROP_EDITABLE,
94   PROP_WRAP_MODE,
95   PROP_JUSTIFICATION,
96   PROP_DIRECTION,
97   PROP_LEFT_MARGIN,
98   PROP_INDENT,
99   PROP_STRIKETHROUGH,
100   PROP_RIGHT_MARGIN,
101   PROP_UNDERLINE,
102   PROP_RISE,
103   PROP_BG_FULL_HEIGHT,
104   PROP_LANGUAGE,
105   PROP_TABS,
106   PROP_INVISIBLE,
107   
108   /* Whether-a-style-arg-is-set args */
109   PROP_BACKGROUND_SET,
110   PROP_FOREGROUND_SET,
111   PROP_BACKGROUND_STIPPLE_SET,
112   PROP_FOREGROUND_STIPPLE_SET,
113   PROP_FAMILY_SET,
114   PROP_STYLE_SET,
115   PROP_VARIANT_SET,
116   PROP_WEIGHT_SET,
117   PROP_STRETCH_SET,
118   PROP_SIZE_SET,
119   PROP_SCALE_SET,
120   PROP_PIXELS_ABOVE_LINES_SET,
121   PROP_PIXELS_BELOW_LINES_SET,
122   PROP_PIXELS_INSIDE_WRAP_SET,
123   PROP_EDITABLE_SET,
124   PROP_WRAP_MODE_SET,
125   PROP_JUSTIFICATION_SET,
126   PROP_LEFT_MARGIN_SET,
127   PROP_INDENT_SET,
128   PROP_STRIKETHROUGH_SET,
129   PROP_RIGHT_MARGIN_SET,
130   PROP_UNDERLINE_SET,
131   PROP_RISE_SET,
132   PROP_BG_FULL_HEIGHT_SET,
133   PROP_LANGUAGE_SET,
134   PROP_TABS_SET,
135   PROP_INVISIBLE_SET,
136
137   LAST_ARG
138 };
139 static void gtk_text_tag_init         (GtkTextTag      *text_tag);
140 static void gtk_text_tag_class_init   (GtkTextTagClass *klass);
141 static void gtk_text_tag_finalize     (GObject         *object);
142 static void gtk_text_tag_set_property (GObject         *object,
143                                        guint            prop_id,
144                                        const GValue    *value,
145                                        GParamSpec      *pspec);
146 static void gtk_text_tag_get_property (GObject         *object,
147                                        guint            prop_id,
148                                        GValue          *value,
149                                        GParamSpec      *pspec);
150
151 static GObjectClass *parent_class = NULL;
152 static guint signals[LAST_SIGNAL] = { 0 };
153
154 GType
155 gtk_text_tag_get_type (void)
156 {
157   static GType our_type = 0;
158
159   if (our_type == 0)
160     {
161       static const GTypeInfo our_info =
162       {
163         sizeof (GtkTextTagClass),
164         (GBaseInitFunc) NULL,
165         (GBaseFinalizeFunc) NULL,
166         (GClassInitFunc) gtk_text_tag_class_init,
167         NULL,           /* class_finalize */
168         NULL,           /* class_data */
169         sizeof (GtkTextTag),
170         0,              /* n_preallocs */
171         (GInstanceInitFunc) gtk_text_tag_init
172       };
173
174       our_type = g_type_register_static (G_TYPE_OBJECT,
175                                          "GtkTextTag",
176                                          &our_info,
177                                          0);
178     }
179
180   return our_type;
181 }
182
183 static void
184 gtk_text_tag_class_init (GtkTextTagClass *klass)
185 {
186   GObjectClass *object_class = G_OBJECT_CLASS (klass);
187
188   parent_class = g_type_class_peek_parent (klass);
189
190   object_class->set_property = gtk_text_tag_set_property;
191   object_class->get_property = gtk_text_tag_get_property;
192   
193   object_class->finalize = gtk_text_tag_finalize;
194
195   /* Construct */
196   g_object_class_install_property (object_class,
197                                    PROP_NAME,
198                                    g_param_spec_string ("name",
199                                                         _("Tag name"),
200                                                         _("Name used to refer to the text tag"),
201                                                         NULL,
202                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
203
204   /* Style args */
205
206   g_object_class_install_property (object_class,
207                                    PROP_BACKGROUND,
208                                    g_param_spec_string ("background",
209                                                         _("Background color name"),
210                                                         _("Background color as a string"),
211                                                         NULL,
212                                                         G_PARAM_WRITABLE));
213
214   g_object_class_install_property (object_class,
215                                    PROP_BACKGROUND_GDK,
216                                    g_param_spec_boxed ("background_gdk",
217                                                        _("Background color"),
218                                                        _("Background color as a GdkColor"),
219                                                        GDK_TYPE_COLOR,
220                                                        G_PARAM_READABLE | G_PARAM_WRITABLE));
221
222   g_object_class_install_property (object_class,
223                                    PROP_BG_FULL_HEIGHT,
224                                    g_param_spec_boolean ("background_full_height",
225                                                          _("Background full height"),
226                                                          _("Whether the background color fills the entire line height or only the height of the tagged characters"),
227                                                          FALSE,
228                                                          G_PARAM_READABLE | G_PARAM_WRITABLE));
229
230   
231   g_object_class_install_property (object_class,
232                                    PROP_BACKGROUND_STIPPLE,
233                                    g_param_spec_object ("background_stipple",
234                                                         _("Background stipple mask"),
235                                                         _("Bitmap to use as a mask when drawing the text background"),
236                                                         GDK_TYPE_PIXMAP,
237                                                         G_PARAM_READABLE | G_PARAM_WRITABLE));  
238
239
240   g_object_class_install_property (object_class,
241                                    PROP_FOREGROUND,
242                                    g_param_spec_string ("foreground",
243                                                         _("Foreground color name"),
244                                                         _("Foreground color as a string"),
245                                                         NULL,
246                                                         G_PARAM_WRITABLE));
247
248   g_object_class_install_property (object_class,
249                                    PROP_FOREGROUND_GDK,
250                                    g_param_spec_boxed ("foreground_gdk",
251                                                        _("Foreground color"),
252                                                        _("Foreground color as a GdkColor"),
253                                                        GDK_TYPE_COLOR,
254                                                        G_PARAM_READABLE | G_PARAM_WRITABLE));
255
256   
257   g_object_class_install_property (object_class,
258                                    PROP_FOREGROUND_STIPPLE,
259                                    g_param_spec_object ("foreground_stipple",
260                                                         _("Foreground stipple mask"),
261                                                         _("Bitmap to use as a mask when drawing the text foreground"),
262                                                         GDK_TYPE_PIXMAP,
263                                                         G_PARAM_READABLE | G_PARAM_WRITABLE));  
264   
265   g_object_class_install_property (object_class,
266                                    PROP_DIRECTION,
267                                    g_param_spec_enum ("direction",
268                                                       _("Text direction"),
269                                                       _("Text direction, e.g. right-to-left or left-to-right"),
270                                                       GTK_TYPE_TEXT_DIRECTION,
271                                                       GTK_TEXT_DIR_LTR,
272                                                       G_PARAM_READABLE | G_PARAM_WRITABLE));
273
274   g_object_class_install_property (object_class,
275                                    PROP_EDITABLE,
276                                    g_param_spec_boolean ("editable",
277                                                          _("Editable"),
278                                                          _("Whether the text can be modified by the user"),
279                                                          TRUE,
280                                                          G_PARAM_READABLE | G_PARAM_WRITABLE));
281
282   g_object_class_install_property (object_class,
283                                    PROP_FONT,
284                                    g_param_spec_string ("font",
285                                                         _("Font"),
286                                                         _("Font description as a string"),
287                                                         NULL,
288                                                         G_PARAM_READABLE | G_PARAM_WRITABLE));
289
290   g_object_class_install_property (object_class,
291                                    PROP_FONT_DESC,
292                                    g_param_spec_boxed ("font_desc",
293                                                        _("Font"),
294                                                        _("Font description as a PangoFontDescription struct"),
295                                                        PANGO_TYPE_FONT_DESCRIPTION,
296                                                        G_PARAM_READABLE | G_PARAM_WRITABLE));
297
298   
299   g_object_class_install_property (object_class,
300                                    PROP_FAMILY,
301                                    g_param_spec_string ("family",
302                                                         _("Font family"),
303                                                         _("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
304                                                         NULL,
305                                                         G_PARAM_READABLE | G_PARAM_WRITABLE));
306
307   g_object_class_install_property (object_class,
308                                    PROP_STYLE,
309                                    g_param_spec_enum ("style",
310                                                       _("Font style"),
311                                                       _("Font style"),
312                                                       PANGO_TYPE_STYLE,
313                                                       PANGO_STYLE_NORMAL,
314                                                       G_PARAM_READABLE | G_PARAM_WRITABLE));
315
316   g_object_class_install_property (object_class,
317                                    PROP_VARIANT,
318                                    g_param_spec_enum ("variant",
319                                                      _("Font variant"),
320                                                      _("Font variant"),
321                                                       PANGO_TYPE_VARIANT,
322                                                       PANGO_VARIANT_NORMAL,
323                                                       G_PARAM_READABLE | G_PARAM_WRITABLE));
324   
325   g_object_class_install_property (object_class,
326                                    PROP_WEIGHT,
327                                    g_param_spec_int ("weight",
328                                                      _("Font weight"),
329                                                      _("Font weight"),
330                                                      0,
331                                                      G_MAXINT,
332                                                      PANGO_WEIGHT_NORMAL,
333                                                      G_PARAM_READABLE | G_PARAM_WRITABLE));
334   
335
336   g_object_class_install_property (object_class,
337                                    PROP_STRETCH,
338                                    g_param_spec_enum ("stretch",
339                                                       _("Font stretch"),
340                                                       _("Font stretch"),
341                                                       PANGO_TYPE_STRETCH,
342                                                       PANGO_STRETCH_NORMAL,
343                                                       G_PARAM_READABLE | G_PARAM_WRITABLE));
344   
345   g_object_class_install_property (object_class,
346                                    PROP_SIZE,
347                                    g_param_spec_int ("size",
348                                                      _("Font size"),
349                                                      _("Font size"),
350                                                      0,
351                                                      G_MAXINT,
352                                                      0,
353                                                      G_PARAM_READABLE | G_PARAM_WRITABLE));
354
355   g_object_class_install_property (object_class,
356                                    PROP_SCALE,
357                                    g_param_spec_double ("scale",
358                                                         _("Font scale"),
359                                                         _("Font scale"),
360                                                         0.0,
361                                                         G_MAXDOUBLE,
362                                                         1.0,
363                                                         G_PARAM_READABLE | G_PARAM_WRITABLE));
364   
365   g_object_class_install_property (object_class,
366                                    PROP_SIZE_POINTS,
367                                    g_param_spec_double ("size_points",
368                                                         _("Font points"),
369                                                         _("Font size in points"),
370                                                         0.0,
371                                                         G_MAXDOUBLE,
372                                                         0.0,
373                                                         G_PARAM_READABLE | G_PARAM_WRITABLE));  
374
375   g_object_class_install_property (object_class,
376                                    PROP_JUSTIFICATION,
377                                    g_param_spec_enum ("justification",
378                                                       _("Justification"),
379                                                       _("Left, right, or center justification"),
380                                                       GTK_TYPE_JUSTIFICATION,
381                                                       GTK_JUSTIFY_LEFT,
382                                                       G_PARAM_READABLE | G_PARAM_WRITABLE));
383   
384   g_object_class_install_property (object_class,
385                                    PROP_LANGUAGE,
386                                    g_param_spec_string ("language",
387                                                         _("Language"),
388                                                         _("Language engine code to use for rendering the text"),
389                                                         NULL,
390                                                         G_PARAM_READABLE | G_PARAM_WRITABLE));  
391
392   g_object_class_install_property (object_class,
393                                    PROP_LEFT_MARGIN,
394                                    g_param_spec_int ("left_margin",
395                                                      _("Left margin"),
396                                                      _("Width of the left margin in pixels"),
397                                                      0,
398                                                      G_MAXINT,
399                                                      0,
400                                                      G_PARAM_READABLE | G_PARAM_WRITABLE));
401
402   g_object_class_install_property (object_class,
403                                    PROP_RIGHT_MARGIN,
404                                    g_param_spec_int ("right_margin",
405                                                      _("Right margin"),
406                                                      _("Width of the right margin in pixels"),
407                                                      0,
408                                                      G_MAXINT,
409                                                      0,
410                                                      G_PARAM_READABLE | G_PARAM_WRITABLE));
411
412   
413   g_object_class_install_property (object_class,
414                                    PROP_INDENT,
415                                    g_param_spec_int ("indent",
416                                                      _("Indent"),
417                                                      _("Amount to indent the paragraph, in pixels"),
418                                                      G_MININT,
419                                                      G_MAXINT,
420                                                      0,
421                                                      G_PARAM_READABLE | G_PARAM_WRITABLE));
422
423   
424   g_object_class_install_property (object_class,
425                                    PROP_RISE,
426                                    g_param_spec_int ("rise",
427                                                      _("Rise"),
428                                                      _("Offset of text above the baseline (below the baseline if rise is negative)"),
429                                                      G_MININT,
430                                                      G_MAXINT,
431                                                      0,
432                                                      G_PARAM_READABLE | G_PARAM_WRITABLE));
433
434   g_object_class_install_property (object_class,
435                                    PROP_PIXELS_ABOVE_LINES,
436                                    g_param_spec_int ("pixels_above_lines",
437                                                      _("Pixels above lines"),
438                                                      _("Pixels of blank space above paragraphs"),
439                                                      0,
440                                                      G_MAXINT,
441                                                      0,
442                                                      G_PARAM_READABLE | G_PARAM_WRITABLE));
443   
444   g_object_class_install_property (object_class,
445                                    PROP_PIXELS_BELOW_LINES,
446                                    g_param_spec_int ("pixels_below_lines",
447                                                      _("Pixels below lines"),
448                                                      _("Pixels of blank space below paragraphs"),
449                                                      0,
450                                                      G_MAXINT,
451                                                      0,
452                                                      G_PARAM_READABLE | G_PARAM_WRITABLE));
453
454   g_object_class_install_property (object_class,
455                                    PROP_PIXELS_INSIDE_WRAP,
456                                    g_param_spec_int ("pixels_inside_wrap",
457                                                      _("Pixels inside wrap"),
458                                                      _("Pixels of blank space between wrapped lines in a paragraph"),
459                                                      0,
460                                                      G_MAXINT,
461                                                      0,
462                                                      G_PARAM_READABLE | G_PARAM_WRITABLE));
463
464   g_object_class_install_property (object_class,
465                                    PROP_STRIKETHROUGH,
466                                    g_param_spec_boolean ("strikethrough",
467                                                          _("Strikethrough"),
468                                                          _("Whether to strike through the text"),
469                                                          FALSE,
470                                                          G_PARAM_READABLE | G_PARAM_WRITABLE));
471   
472   g_object_class_install_property (object_class,
473                                    PROP_UNDERLINE,
474                                    g_param_spec_enum ("underline",
475                                                       _("Underline"),
476                                                       _("Style of underline for this text"),
477                                                       PANGO_TYPE_UNDERLINE,
478                                                       PANGO_UNDERLINE_NONE,
479                                                       G_PARAM_READABLE | G_PARAM_WRITABLE));
480   
481   g_object_class_install_property (object_class,
482                                    PROP_WRAP_MODE,
483                                    g_param_spec_enum ("wrap_mode",
484                                                      _("Wrap mode"),
485                                                      _("Whether to wrap lines never, at word boundaries, or at character boundaries"),
486                                                       GTK_TYPE_WRAP_MODE,
487                                                       GTK_WRAP_NONE,
488                                                       G_PARAM_READABLE | G_PARAM_WRITABLE));
489   
490
491   g_object_class_install_property (object_class,
492                                    PROP_TABS,
493                                    g_param_spec_boxed ("tabs",
494                                                        _("Tabs"),
495                                                        _("Custom tabs for this text"),
496                                                        PANGO_TYPE_TAB_ARRAY,
497                                                        G_PARAM_READABLE | G_PARAM_WRITABLE));
498   
499   g_object_class_install_property (object_class,
500                                    PROP_INVISIBLE,
501                                    g_param_spec_boolean ("invisible",
502                                                          _("Invisible"),
503                                                          _("Whether this text is hidden"),
504                                                          FALSE,
505                                                          G_PARAM_READABLE | G_PARAM_WRITABLE));
506
507   /* Style props are set or not */
508
509 #define ADD_SET_PROP(propname, propval, nick, blurb) g_object_class_install_property (object_class, propval, g_param_spec_boolean (propname, nick, blurb, FALSE, G_PARAM_READABLE | G_PARAM_WRITABLE))
510
511   ADD_SET_PROP ("background_set", PROP_BACKGROUND_SET,
512                 _("Background set"),
513                 _("Whether this tag affects the background color"));
514   
515   ADD_SET_PROP ("background_full_height_set", PROP_BG_FULL_HEIGHT_SET,
516                 _("Background full height set"),
517                 _("Whether this tag affects background height"));
518
519   ADD_SET_PROP ("background_stipple_set", PROP_BACKGROUND_STIPPLE_SET,
520                 _("Background stipple set"),
521                 _("Whether this tag affects the background stipple"));  
522
523   ADD_SET_PROP ("foreground_set", PROP_FOREGROUND_SET,
524                 _("Foreground set"),
525                 _("Whether this tag affects the foreground color"));
526
527   ADD_SET_PROP ("foreground_stipple_set", PROP_FOREGROUND_STIPPLE_SET,
528                 _("Foreground stipple set"),
529                 _("Whether this tag affects the foreground stipple"));
530   
531   ADD_SET_PROP ("editable_set", PROP_EDITABLE_SET,
532                 _("Editability set"),
533                 _("Whether this tag affects text editability"));
534
535   ADD_SET_PROP ("family_set", PROP_FAMILY_SET,
536                 _("Font family set"),
537                 _("Whether this tag affects the font family"));  
538
539   ADD_SET_PROP ("style_set", PROP_STYLE_SET,
540                 _("Font style set"),
541                 _("Whether this tag affects the font style"));
542
543   ADD_SET_PROP ("variant_set", PROP_VARIANT_SET,
544                 _("Font variant set"),
545                 _("Whether this tag affects the font variant"));
546
547   ADD_SET_PROP ("weight_set", PROP_WEIGHT_SET,
548                 _("Font weight set"),
549                 _("Whether this tag affects the font weight"));
550
551   ADD_SET_PROP ("stretch_set", PROP_STRETCH_SET,
552                 _("Font stretch set"),
553                 _("Whether this tag affects the font stretch"));
554
555   ADD_SET_PROP ("size_set", PROP_SIZE_SET,
556                 _("Font size set"),
557                 _("Whether this tag affects the font size"));
558
559   ADD_SET_PROP ("scale_set", PROP_SCALE_SET,
560                 _("Font scale set"),
561                 _("Whether this tag scales the font size by a factor"));
562   
563   ADD_SET_PROP ("justification_set", PROP_JUSTIFICATION_SET,
564                 _("Justification set"),
565                 _("Whether this tag affects paragraph justification"));
566   
567   ADD_SET_PROP ("language_set", PROP_LANGUAGE_SET,
568                 _("Language set"),
569                 _("Whether this tag affects the language the text is rendered as"));
570
571   ADD_SET_PROP ("left_margin_set", PROP_LEFT_MARGIN_SET,
572                 _("Left margin set"),
573                 _("Whether this tag affects the left margin"));
574
575   ADD_SET_PROP ("indent_set", PROP_INDENT_SET,
576                 _("Indent set"),
577                 _("Whether this tag affects indentation"));
578
579   ADD_SET_PROP ("rise_set", PROP_RISE_SET,
580                 _("Rise set"),
581                 _("Whether this tag affects the rise"));
582
583   ADD_SET_PROP ("pixels_above_lines_set", PROP_PIXELS_ABOVE_LINES_SET,
584                 _("Pixels above lines set"),
585                 _("Whether this tag affects the number of pixels above lines"));
586
587   ADD_SET_PROP ("pixels_below_lines_set", PROP_PIXELS_BELOW_LINES_SET,
588                 _("Pixels below lines set"),
589                 _("Whether this tag affects the number of pixels above lines"));
590
591   ADD_SET_PROP ("pixels_inside_wrap_set", PROP_PIXELS_INSIDE_WRAP_SET,
592                 _("Pixels inside wrap set"),
593                 _("Whether this tag affects the number of pixels between wrapped lines"));
594
595   ADD_SET_PROP ("strikethrough_set", PROP_STRIKETHROUGH_SET,
596                 _("Strikethrough set"),
597                 _("Whether this tag affects strikethrough"));
598   
599   ADD_SET_PROP ("right_margin_set", PROP_RIGHT_MARGIN_SET,
600                 _("Right margin set"),
601                 _("Whether this tag affects the right margin"));
602
603   ADD_SET_PROP ("underline_set", PROP_UNDERLINE_SET,
604                 _("Underline set"),
605                 _("Whether this tag affects underlining"));
606
607   ADD_SET_PROP ("wrap_mode_set", PROP_WRAP_MODE_SET,
608                 _("Wrap mode set"),
609                 _("Whether this tag affects line wrap mode"));
610
611   ADD_SET_PROP ("tabs_set", PROP_TABS_SET,
612                 _("Tabs set"),
613                 _("Whether this tag affects tabs"));
614
615   ADD_SET_PROP ("invisible_set", PROP_INVISIBLE_SET,
616                 _("Invisible set"),
617                 _("Whether this tag affects text visibility"));
618
619   signals[EVENT] =
620     g_signal_new ("event",
621                   G_OBJECT_CLASS_TYPE (object_class),
622                   G_SIGNAL_RUN_LAST,
623                   GTK_SIGNAL_OFFSET (GtkTextTagClass, event),
624                   _gtk_boolean_handled_accumulator, NULL,
625                   _gtk_marshal_BOOLEAN__OBJECT_BOXED_BOXED,
626                   G_TYPE_BOOLEAN,
627                   3,
628                   G_TYPE_OBJECT,
629                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE,
630                   GTK_TYPE_TEXT_ITER);
631 }
632
633 static void
634 gtk_text_tag_init (GtkTextTag *text_tag)
635 {
636   /* 0 is basically a fine way to initialize everything in the
637      entire struct */
638   
639   text_tag->values = gtk_text_attributes_new ();
640 }
641
642 /**
643  * gtk_text_tag_new:
644  * @name: tag name, or %NULL
645  * 
646  * Creates a #GtkTextTag. Configure the tag using object arguments,
647  * i.e. using g_object_set().
648  * 
649  * Return value: a new #GtkTextTag
650  **/
651 GtkTextTag*
652 gtk_text_tag_new (const gchar *name)
653 {
654   GtkTextTag *tag;
655
656   tag = GTK_TEXT_TAG (g_object_new (gtk_text_tag_get_type (),
657                                     "name", name,
658                                     NULL));
659
660   return tag;
661 }
662
663 static void
664 gtk_text_tag_finalize (GObject *object)
665 {
666   GtkTextTag *text_tag;
667
668   text_tag = GTK_TEXT_TAG (object);
669
670   g_assert (!text_tag->values->realized);
671
672   if (text_tag->table)
673     gtk_text_tag_table_remove (text_tag->table, text_tag);
674
675   g_assert (text_tag->table == NULL);
676
677   gtk_text_attributes_unref (text_tag->values);
678   text_tag->values = NULL;
679   
680   g_free (text_tag->name);
681   text_tag->name = NULL;
682
683   (* G_OBJECT_CLASS (parent_class)->finalize) (object);
684 }
685
686 static void
687 set_bg_color (GtkTextTag *tag, GdkColor *color)
688 {
689   if (color)
690     {
691       if (!tag->bg_color_set)
692         {
693           tag->bg_color_set = TRUE;
694           g_object_notify (G_OBJECT (tag), "background_set");
695         }
696       
697       tag->values->appearance.bg_color = *color;
698     }
699   else
700     {
701       if (tag->bg_color_set)
702         {
703           tag->bg_color_set = FALSE;
704           g_object_notify (G_OBJECT (tag), "background_set");
705         }
706     }
707 }
708
709 static void
710 set_fg_color (GtkTextTag *tag, GdkColor *color)
711 {
712   if (color)
713     {
714       if (!tag->fg_color_set)
715         {
716           tag->fg_color_set = TRUE;
717           g_object_notify (G_OBJECT (tag), "foreground_set");
718         }
719       tag->values->appearance.fg_color = *color;
720     }
721   else
722     {
723       if (tag->fg_color_set)
724         {
725           tag->fg_color_set = FALSE;
726           g_object_notify (G_OBJECT (tag), "foreground_set");
727         }
728     }
729 }
730
731 static PangoFontMask
732 get_property_font_set_mask (guint prop_id)
733 {
734   switch (prop_id)
735     {
736     case PROP_FAMILY_SET:
737       return PANGO_FONT_MASK_FAMILY;
738     case PROP_STYLE_SET:
739       return PANGO_FONT_MASK_STYLE;
740     case PROP_VARIANT_SET:
741       return PANGO_FONT_MASK_VARIANT;
742     case PROP_WEIGHT_SET:
743       return PANGO_FONT_MASK_WEIGHT;
744     case PROP_STRETCH_SET:
745       return PANGO_FONT_MASK_STRETCH;
746     case PROP_SIZE_SET:
747       return PANGO_FONT_MASK_SIZE;
748     }
749
750   return 0;
751 }
752
753 static PangoFontMask
754 set_font_desc_fields (PangoFontDescription *desc,
755                       PangoFontMask         to_set)
756 {
757   PangoFontMask changed_mask = 0;
758   
759   if (to_set & PANGO_FONT_MASK_FAMILY)
760     {
761       const char *family = pango_font_description_get_family (desc);
762       if (!family)
763         {
764           family = "sans";
765           changed_mask |= PANGO_FONT_MASK_FAMILY;
766         }
767
768       pango_font_description_set_family (desc, family);
769     }
770   if (to_set & PANGO_FONT_MASK_STYLE)
771     pango_font_description_set_style (desc, pango_font_description_get_style (desc));
772   if (to_set & PANGO_FONT_MASK_VARIANT)
773     pango_font_description_set_variant (desc, pango_font_description_get_variant (desc));
774   if (to_set & PANGO_FONT_MASK_WEIGHT)
775     pango_font_description_set_weight (desc, pango_font_description_get_weight (desc));
776   if (to_set & PANGO_FONT_MASK_STRETCH)
777     pango_font_description_set_stretch (desc, pango_font_description_get_stretch (desc));
778   if (to_set & PANGO_FONT_MASK_SIZE)
779     {
780       gint size = pango_font_description_get_size (desc);
781       if (size <= 0)
782         {
783           size = 10 * PANGO_SCALE;
784           changed_mask |= PANGO_FONT_MASK_SIZE;
785         }
786       
787       pango_font_description_set_size (desc, size);
788     }
789
790   return changed_mask;
791 }
792
793 static void
794 notify_set_changed (GObject       *object,
795                     PangoFontMask  changed_mask)
796 {
797   if (changed_mask & PANGO_FONT_MASK_FAMILY)
798     g_object_notify (object, "family_set");
799   if (changed_mask & PANGO_FONT_MASK_STYLE)
800     g_object_notify (object, "style_set");
801   if (changed_mask & PANGO_FONT_MASK_VARIANT)
802     g_object_notify (object, "variant_set");
803   if (changed_mask & PANGO_FONT_MASK_WEIGHT)
804     g_object_notify (object, "weight_set");
805   if (changed_mask & PANGO_FONT_MASK_STRETCH)
806     g_object_notify (object, "stretch_set");
807   if (changed_mask & PANGO_FONT_MASK_SIZE)
808     g_object_notify (object, "size_set");
809 }
810
811 static void
812 notify_fields_changed (GObject       *object,
813                        PangoFontMask  changed_mask)
814 {
815   if (changed_mask & PANGO_FONT_MASK_FAMILY)
816     g_object_notify (object, "family");
817   if (changed_mask & PANGO_FONT_MASK_STYLE)
818     g_object_notify (object, "style");
819   if (changed_mask & PANGO_FONT_MASK_VARIANT)
820     g_object_notify (object, "variant");
821   if (changed_mask & PANGO_FONT_MASK_WEIGHT)
822     g_object_notify (object, "weight");
823   if (changed_mask & PANGO_FONT_MASK_STRETCH)
824     g_object_notify (object, "stretch");
825   if (changed_mask & PANGO_FONT_MASK_SIZE)
826     g_object_notify (object, "size");
827 }
828
829 static void
830 set_font_description (GtkTextTag           *text_tag,
831                       PangoFontDescription *font_desc)
832 {
833   GObject *object = G_OBJECT (text_tag);
834   PangoFontDescription *new_font_desc;
835   PangoFontMask old_mask, new_mask, changed_mask, set_changed_mask;
836   
837   if (font_desc)
838     new_font_desc = pango_font_description_copy (font_desc);
839   else
840     new_font_desc = pango_font_description_new ();
841
842   if (text_tag->values->font)
843     old_mask = pango_font_description_get_set_fields (text_tag->values->font);
844   else
845     old_mask = 0;
846   
847   new_mask = pango_font_description_get_set_fields (new_font_desc);
848
849   changed_mask = old_mask | new_mask;
850   set_changed_mask = old_mask ^ new_mask;
851
852   if (text_tag->values->font)
853     pango_font_description_free (text_tag->values->font);
854   text_tag->values->font = new_font_desc;
855   
856   g_object_freeze_notify (object);
857
858   g_object_notify (object, "font_desc");
859   g_object_notify (object, "font");
860   
861   if (changed_mask & PANGO_FONT_MASK_FAMILY)
862     g_object_notify (object, "family");
863   if (changed_mask & PANGO_FONT_MASK_STYLE)
864     g_object_notify (object, "style");
865   if (changed_mask & PANGO_FONT_MASK_VARIANT)
866     g_object_notify (object, "variant");
867   if (changed_mask & PANGO_FONT_MASK_WEIGHT)
868     g_object_notify (object, "weight");
869   if (changed_mask & PANGO_FONT_MASK_STRETCH)
870     g_object_notify (object, "stretch");
871   if (changed_mask & PANGO_FONT_MASK_SIZE)
872     {
873       g_object_notify (object, "size");
874       g_object_notify (object, "size_points");
875     }
876
877   notify_set_changed (object, set_changed_mask);
878   
879   g_object_thaw_notify (object);
880 }
881
882 static void
883 gtk_text_tag_ensure_font (GtkTextTag *text_tag)
884 {
885   if (!text_tag->values->font)
886     text_tag->values->font = pango_font_description_new ();
887 }
888
889 static void
890 gtk_text_tag_set_property (GObject      *object,
891                            guint         prop_id,
892                            const GValue *value,
893                            GParamSpec   *pspec)
894 {
895   GtkTextTag *text_tag;
896   gboolean size_changed = FALSE;
897
898   text_tag = GTK_TEXT_TAG (object);
899
900   g_return_if_fail (!text_tag->values->realized);
901
902   switch (prop_id)
903     {
904     case PROP_NAME:
905       g_return_if_fail (text_tag->name == NULL);
906       text_tag->name = g_strdup (g_value_get_string (value));
907       break;
908
909     case PROP_BACKGROUND:
910       {
911         GdkColor color;
912
913         if (gdk_color_parse (g_value_get_string (value), &color))
914           set_bg_color (text_tag, &color);
915         else
916           g_warning ("Don't know color `%s'", g_value_get_string (value));
917
918         g_object_notify (object, "background_gdk");
919       }
920       break;
921
922     case PROP_FOREGROUND:
923       {
924         GdkColor color;
925
926         if (gdk_color_parse (g_value_get_string (value), &color))
927           set_fg_color (text_tag, &color);
928         else
929           g_warning ("Don't know color `%s'", g_value_get_string (value));
930
931         g_object_notify (object, "foreground_gdk");
932       }
933       break;
934
935     case PROP_BACKGROUND_GDK:
936       {
937         GdkColor *color = g_value_get_boxed (value);
938
939         set_bg_color (text_tag, color);
940       }
941       break;
942
943     case PROP_FOREGROUND_GDK:
944       {
945         GdkColor *color = g_value_get_boxed (value);
946
947         set_fg_color (text_tag, color);
948       }
949       break;
950
951     case PROP_BACKGROUND_STIPPLE:
952       {
953         GdkBitmap *bitmap = g_value_get_object (value);
954
955         text_tag->bg_stipple_set = TRUE;
956         g_object_notify (object, "background_stipple_set");
957         
958         if (text_tag->values->appearance.bg_stipple != bitmap)
959           {
960             if (bitmap != NULL)
961               gdk_bitmap_ref (bitmap);
962
963             if (text_tag->values->appearance.bg_stipple)
964               gdk_bitmap_unref (text_tag->values->appearance.bg_stipple);
965
966             text_tag->values->appearance.bg_stipple = bitmap;
967           }
968       }
969       break;
970
971     case PROP_FOREGROUND_STIPPLE:
972       {
973         GdkBitmap *bitmap = g_value_get_object (value);
974
975         text_tag->fg_stipple_set = TRUE;
976         g_object_notify (object, "foreground_stipple_set");
977
978         if (text_tag->values->appearance.fg_stipple != bitmap)
979           {
980             if (bitmap != NULL)
981               gdk_bitmap_ref (bitmap);
982
983             if (text_tag->values->appearance.fg_stipple)
984               gdk_bitmap_unref (text_tag->values->appearance.fg_stipple);
985
986             text_tag->values->appearance.fg_stipple = bitmap;
987           }
988       }
989       break;
990
991     case PROP_FONT:
992       {
993         PangoFontDescription *font_desc = NULL;
994         const gchar *name;
995
996         name = g_value_get_string (value);
997
998         if (name)
999           font_desc = pango_font_description_from_string (name);
1000
1001         set_font_description (text_tag, font_desc);
1002         
1003         size_changed = TRUE;
1004       }
1005       break;
1006
1007     case PROP_FONT_DESC:
1008       {
1009         PangoFontDescription *font_desc;
1010
1011         font_desc = g_value_get_boxed (value);
1012
1013         set_font_description (text_tag, font_desc);
1014
1015         size_changed = TRUE;
1016       }
1017       break;
1018
1019     case PROP_FAMILY:
1020     case PROP_STYLE:
1021     case PROP_VARIANT:
1022     case PROP_WEIGHT:
1023     case PROP_STRETCH:
1024     case PROP_SIZE:
1025     case PROP_SIZE_POINTS:
1026       {
1027         PangoFontMask old_set_mask;
1028
1029         gtk_text_tag_ensure_font (text_tag);
1030         old_set_mask = pango_font_description_get_set_fields (text_tag->values->font);
1031  
1032         switch (prop_id)
1033           {
1034           case PROP_FAMILY:
1035             pango_font_description_set_family (text_tag->values->font,
1036                                                g_value_get_string (value));
1037             break;
1038           case PROP_STYLE:
1039             pango_font_description_set_style (text_tag->values->font,
1040                                               g_value_get_enum (value));
1041             break;
1042           case PROP_VARIANT:
1043             pango_font_description_set_variant (text_tag->values->font,
1044                                                 g_value_get_enum (value));
1045             break;
1046           case PROP_WEIGHT:
1047             pango_font_description_set_weight (text_tag->values->font,
1048                                                g_value_get_int (value));
1049             break;
1050           case PROP_STRETCH:
1051             pango_font_description_set_stretch (text_tag->values->font,
1052                                                 g_value_get_enum (value));
1053             break;
1054           case PROP_SIZE:
1055             pango_font_description_set_size (text_tag->values->font,
1056                                              g_value_get_int (value));
1057             g_object_notify (object, "size_points");
1058             break;
1059           case PROP_SIZE_POINTS:
1060             pango_font_description_set_size (text_tag->values->font,
1061                                              g_value_get_double (value) * PANGO_SCALE);
1062             g_object_notify (object, "size");
1063             break;
1064           }
1065
1066         size_changed = TRUE;
1067         notify_set_changed (object, old_set_mask & pango_font_description_get_set_fields (text_tag->values->font));
1068         g_object_notify (object, "font_desc");
1069         g_object_notify (object, "font");
1070
1071         break;
1072       }
1073       
1074     case PROP_SCALE:
1075       text_tag->values->font_scale = g_value_get_double (value);
1076       text_tag->scale_set = TRUE;
1077       g_object_notify (object, "scale_set");
1078       size_changed = TRUE;
1079       break;
1080       
1081     case PROP_PIXELS_ABOVE_LINES:
1082       text_tag->pixels_above_lines_set = TRUE;
1083       text_tag->values->pixels_above_lines = g_value_get_int (value);
1084       g_object_notify (object, "pixels_above_lines_set");
1085       size_changed = TRUE;
1086       break;
1087
1088     case PROP_PIXELS_BELOW_LINES:
1089       text_tag->pixels_below_lines_set = TRUE;
1090       text_tag->values->pixels_below_lines = g_value_get_int (value);
1091       g_object_notify (object, "pixels_below_lines_set");
1092       size_changed = TRUE;
1093       break;
1094
1095     case PROP_PIXELS_INSIDE_WRAP:
1096       text_tag->pixels_inside_wrap_set = TRUE;
1097       text_tag->values->pixels_inside_wrap = g_value_get_int (value);
1098       g_object_notify (object, "pixels_inside_wrap_set");
1099       size_changed = TRUE;
1100       break;
1101
1102     case PROP_EDITABLE:
1103       text_tag->editable_set = TRUE;
1104       text_tag->values->editable = g_value_get_boolean (value);
1105       g_object_notify (object, "editable_set");
1106       break;
1107
1108     case PROP_WRAP_MODE:
1109       text_tag->wrap_mode_set = TRUE;
1110       text_tag->values->wrap_mode = g_value_get_enum (value);
1111       g_object_notify (object, "wrap_mode_set");
1112       size_changed = TRUE;
1113       break;
1114
1115     case PROP_JUSTIFICATION:
1116       text_tag->justification_set = TRUE;
1117       text_tag->values->justification = g_value_get_enum (value);
1118       g_object_notify (object, "justification_set");
1119       size_changed = TRUE;
1120       break;
1121
1122     case PROP_DIRECTION:
1123       text_tag->values->direction = g_value_get_enum (value);
1124       break;
1125
1126     case PROP_LEFT_MARGIN:
1127       text_tag->left_margin_set = TRUE;
1128       text_tag->values->left_margin = g_value_get_int (value);
1129       g_object_notify (object, "left_margin_set");
1130       size_changed = TRUE;
1131       break;
1132
1133     case PROP_INDENT:
1134       text_tag->indent_set = TRUE;
1135       text_tag->values->indent = g_value_get_int (value);
1136       g_object_notify (object, "indent_set");
1137       size_changed = TRUE;
1138       break;
1139
1140     case PROP_STRIKETHROUGH:
1141       text_tag->strikethrough_set = TRUE;
1142       text_tag->values->appearance.strikethrough = g_value_get_boolean (value);
1143       g_object_notify (object, "strikethrough_set");
1144       break;
1145
1146     case PROP_RIGHT_MARGIN:
1147       text_tag->right_margin_set = TRUE;
1148       text_tag->values->right_margin = g_value_get_int (value);
1149       g_object_notify (object, "right_margin_set");
1150       size_changed = TRUE;
1151       break;
1152
1153     case PROP_UNDERLINE:
1154       text_tag->underline_set = TRUE;
1155       text_tag->values->appearance.underline = g_value_get_enum (value);
1156       g_object_notify (object, "underline_set");
1157       break;
1158
1159     case PROP_RISE:
1160       text_tag->rise_set = TRUE;
1161       text_tag->values->appearance.rise = g_value_get_int (value);
1162       g_object_notify (object, "rise_set");
1163       size_changed = TRUE;      
1164       break;
1165
1166     case PROP_BG_FULL_HEIGHT:
1167       text_tag->bg_full_height_set = TRUE;
1168       text_tag->values->bg_full_height = g_value_get_boolean (value);
1169       g_object_notify (object, "bg_full_height_set");
1170       break;
1171
1172     case PROP_LANGUAGE:
1173       text_tag->language_set = TRUE;
1174       text_tag->values->language = pango_language_from_string (g_value_get_string (value));
1175       g_object_notify (object, "language_set");
1176       break;
1177
1178     case PROP_TABS:
1179       text_tag->tabs_set = TRUE;
1180
1181       if (text_tag->values->tabs)
1182         pango_tab_array_free (text_tag->values->tabs);
1183
1184       /* FIXME I'm not sure if this is a memleak or not */
1185       text_tag->values->tabs =
1186         pango_tab_array_copy (g_value_get_boxed (value));
1187
1188       g_object_notify (object, "tabs_set");
1189       
1190       size_changed = TRUE;
1191       break;
1192
1193     case PROP_INVISIBLE:
1194       text_tag->invisible_set = TRUE;
1195       text_tag->values->invisible = g_value_get_boolean (value);
1196       g_object_notify (object, "invisible_set");
1197       size_changed = TRUE;
1198       break;
1199       
1200       /* Whether the value should be used... */
1201
1202     case PROP_BACKGROUND_SET:
1203       text_tag->bg_color_set = g_value_get_boolean (value);
1204       break;
1205
1206     case PROP_FOREGROUND_SET:
1207       text_tag->fg_color_set = g_value_get_boolean (value);
1208       break;
1209
1210     case PROP_BACKGROUND_STIPPLE_SET:
1211       text_tag->bg_stipple_set = g_value_get_boolean (value);
1212       if (!text_tag->bg_stipple_set &&
1213           text_tag->values->appearance.bg_stipple)
1214         {
1215           g_object_unref (G_OBJECT (text_tag->values->appearance.bg_stipple));
1216           text_tag->values->appearance.bg_stipple = NULL;
1217         }
1218       break;
1219
1220     case PROP_FOREGROUND_STIPPLE_SET:
1221       text_tag->fg_stipple_set = g_value_get_boolean (value);
1222       if (!text_tag->fg_stipple_set &&
1223           text_tag->values->appearance.fg_stipple)
1224         {
1225           g_object_unref (G_OBJECT (text_tag->values->appearance.fg_stipple));
1226           text_tag->values->appearance.fg_stipple = NULL;
1227         }
1228       break;
1229
1230     case PROP_FAMILY_SET:
1231     case PROP_STYLE_SET:
1232     case PROP_VARIANT_SET:
1233     case PROP_WEIGHT_SET:
1234     case PROP_STRETCH_SET:
1235     case PROP_SIZE_SET:
1236       if (!g_value_get_boolean (value))
1237         {
1238           if (text_tag->values->font)
1239             pango_font_description_unset_fields (text_tag->values->font,
1240                                                  get_property_font_set_mask (prop_id));
1241         }
1242       else
1243         {
1244           PangoFontMask changed_mask;
1245           
1246           gtk_text_tag_ensure_font (text_tag);
1247           changed_mask = set_font_desc_fields (text_tag->values->font,
1248                                                get_property_font_set_mask (prop_id));
1249           notify_fields_changed (G_OBJECT (text_tag), changed_mask);
1250         }
1251       break;
1252
1253     case PROP_SCALE_SET:
1254       text_tag->scale_set = g_value_get_boolean (value);
1255       size_changed = TRUE;
1256       break;
1257       
1258     case PROP_PIXELS_ABOVE_LINES_SET:
1259       text_tag->pixels_above_lines_set = g_value_get_boolean (value);
1260       size_changed = TRUE;
1261       break;
1262
1263     case PROP_PIXELS_BELOW_LINES_SET:
1264       text_tag->pixels_below_lines_set = g_value_get_boolean (value);
1265       size_changed = TRUE;
1266       break;
1267
1268     case PROP_PIXELS_INSIDE_WRAP_SET:
1269       text_tag->pixels_inside_wrap_set = g_value_get_boolean (value);
1270       size_changed = TRUE;
1271       break;
1272
1273     case PROP_EDITABLE_SET:
1274       text_tag->editable_set = g_value_get_boolean (value);
1275       break;
1276
1277     case PROP_WRAP_MODE_SET:
1278       text_tag->wrap_mode_set = g_value_get_boolean (value);
1279       size_changed = TRUE;
1280       break;
1281
1282     case PROP_JUSTIFICATION_SET:
1283       text_tag->justification_set = g_value_get_boolean (value);
1284       size_changed = TRUE;
1285       break;
1286       
1287     case PROP_LEFT_MARGIN_SET:
1288       text_tag->left_margin_set = g_value_get_boolean (value);
1289       size_changed = TRUE;
1290       break;
1291
1292     case PROP_INDENT_SET:
1293       text_tag->indent_set = g_value_get_boolean (value);
1294       size_changed = TRUE;
1295       break;
1296
1297     case PROP_STRIKETHROUGH_SET:
1298       text_tag->strikethrough_set = g_value_get_boolean (value);
1299       break;
1300
1301     case PROP_RIGHT_MARGIN_SET:
1302       text_tag->right_margin_set = g_value_get_boolean (value);
1303       size_changed = TRUE;
1304       break;
1305
1306     case PROP_UNDERLINE_SET:
1307       text_tag->underline_set = g_value_get_boolean (value);
1308       break;
1309
1310     case PROP_RISE_SET:
1311       text_tag->rise_set = g_value_get_boolean (value);
1312       size_changed = TRUE;
1313       break;
1314
1315     case PROP_BG_FULL_HEIGHT_SET:
1316       text_tag->bg_full_height_set = g_value_get_boolean (value);
1317       break;
1318
1319     case PROP_LANGUAGE_SET:
1320       text_tag->language_set = g_value_get_boolean (value);
1321       size_changed = TRUE;
1322       break;
1323
1324     case PROP_TABS_SET:
1325       text_tag->tabs_set = g_value_get_boolean (value);
1326       size_changed = TRUE;
1327       break;
1328
1329     case PROP_INVISIBLE_SET:
1330       text_tag->invisible_set = g_value_get_boolean (value);
1331       size_changed = TRUE;
1332       break;
1333       
1334     default:
1335       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1336       break;
1337     }
1338
1339   /* FIXME I would like to do this after all set_property in a single
1340    * g_object_set () have been called. But an idle function won't
1341    * work; we need to emit when the tag is changed, not when we get
1342    * around to the event loop. So blah, we eat some inefficiency.
1343    */
1344
1345   /* This is also somewhat weird since we emit another object's
1346    * signal here, but the two objects are already tightly bound.
1347    */
1348
1349   if (text_tag->table)
1350     g_signal_emit_by_name (G_OBJECT (text_tag->table),
1351                            "tag_changed",
1352                            text_tag, size_changed);
1353 }
1354
1355 static void
1356 get_color_arg (GValue *value, GdkColor *orig)
1357 {
1358   GdkColor *color;
1359
1360   color = g_new (GdkColor, 1);
1361   *color = *orig;
1362   g_value_init (value, GDK_TYPE_COLOR);
1363   g_value_set_boxed (value, color);
1364 }
1365
1366 static void
1367 gtk_text_tag_get_property (GObject      *object,
1368                            guint         prop_id,
1369                            GValue       *value,
1370                            GParamSpec   *pspec)
1371 {
1372   GtkTextTag *tag;
1373
1374   tag = GTK_TEXT_TAG (object);
1375
1376   switch (prop_id)
1377     {
1378     case PROP_NAME:
1379       g_value_set_string (value, tag->name);
1380       break;
1381
1382     case PROP_BACKGROUND_GDK:
1383       get_color_arg (value, &tag->values->appearance.bg_color);
1384       break;
1385
1386     case PROP_FOREGROUND_GDK:
1387       get_color_arg (value, &tag->values->appearance.fg_color);
1388       break;
1389
1390     case PROP_BACKGROUND_STIPPLE:
1391       if (tag->bg_stipple_set)
1392         g_value_set_boxed (value, tag->values->appearance.bg_stipple);
1393       break;
1394
1395     case PROP_FOREGROUND_STIPPLE:
1396       if (tag->fg_stipple_set)
1397         g_value_set_boxed (value, tag->values->appearance.fg_stipple);
1398       break;
1399
1400     case PROP_FONT:
1401         {
1402           /* FIXME GValue imposes a totally gratuitous string copy
1403            * here, we could just hand off string ownership
1404            */
1405           gchar *str;
1406
1407           gtk_text_tag_ensure_font (tag);
1408           
1409           str = pango_font_description_to_string (tag->values->font);
1410           g_value_set_string (value, str);
1411           g_free (str);
1412         }
1413       break;
1414
1415     case PROP_FONT_DESC:
1416       gtk_text_tag_ensure_font (tag);
1417       g_value_set_boxed (value, tag->values->font);
1418       break;
1419
1420     case PROP_FAMILY:
1421     case PROP_STYLE:
1422     case PROP_VARIANT:
1423     case PROP_WEIGHT:
1424     case PROP_STRETCH:
1425     case PROP_SIZE:
1426     case PROP_SIZE_POINTS:
1427       gtk_text_tag_ensure_font (tag);
1428       switch (prop_id)
1429         {
1430         case PROP_FAMILY:
1431           g_value_set_string (value, pango_font_description_get_family (tag->values->font));
1432           break;
1433           
1434         case PROP_STYLE:
1435           g_value_set_enum (value, pango_font_description_get_style (tag->values->font));
1436           break;
1437           
1438         case PROP_VARIANT:
1439           g_value_set_enum (value, pango_font_description_get_variant (tag->values->font));
1440           break;
1441           
1442         case PROP_WEIGHT:
1443           g_value_set_int (value, pango_font_description_get_weight (tag->values->font));
1444           break;
1445           
1446         case PROP_STRETCH:
1447           g_value_set_enum (value, pango_font_description_get_stretch (tag->values->font));
1448           break;
1449           
1450         case PROP_SIZE:
1451           g_value_set_int (value, pango_font_description_get_size (tag->values->font));
1452           break;
1453           
1454         case PROP_SIZE_POINTS:
1455           g_value_set_double (value, ((double)pango_font_description_get_size (tag->values->font)) / (double)PANGO_SCALE);
1456           break;
1457         }
1458       break;
1459       
1460     case PROP_SCALE:
1461       g_value_set_double (value, tag->values->font_scale);
1462       break;
1463       
1464     case PROP_PIXELS_ABOVE_LINES:
1465       g_value_set_int (value,  tag->values->pixels_above_lines);
1466       break;
1467
1468     case PROP_PIXELS_BELOW_LINES:
1469       g_value_set_int (value,  tag->values->pixels_below_lines);
1470       break;
1471
1472     case PROP_PIXELS_INSIDE_WRAP:
1473       g_value_set_int (value,  tag->values->pixels_inside_wrap);
1474       break;
1475
1476     case PROP_EDITABLE:
1477       g_value_set_boolean (value, tag->values->editable);
1478       break;
1479
1480     case PROP_WRAP_MODE:
1481       g_value_set_enum (value, tag->values->wrap_mode);
1482       break;
1483
1484     case PROP_JUSTIFICATION:
1485       g_value_set_enum (value, tag->values->justification);
1486       break;
1487
1488     case PROP_DIRECTION:
1489       g_value_set_enum (value, tag->values->direction);
1490       break;
1491       
1492     case PROP_LEFT_MARGIN:
1493       g_value_set_int (value,  tag->values->left_margin);
1494       break;
1495
1496     case PROP_INDENT:
1497       g_value_set_int (value,  tag->values->indent);
1498       break;
1499
1500     case PROP_STRIKETHROUGH:
1501       g_value_set_boolean (value, tag->values->appearance.strikethrough);
1502       break;
1503
1504     case PROP_RIGHT_MARGIN:
1505       g_value_set_int (value, tag->values->right_margin);
1506       break;
1507
1508     case PROP_UNDERLINE:
1509       g_value_set_enum (value, tag->values->appearance.underline);
1510       break;
1511
1512     case PROP_RISE:
1513       g_value_set_int (value, tag->values->appearance.rise);
1514       break;
1515
1516     case PROP_BG_FULL_HEIGHT:
1517       g_value_set_boolean (value, tag->values->bg_full_height);
1518       break;
1519
1520     case PROP_LANGUAGE:
1521       g_value_set_string (value, pango_language_to_string (tag->values->language));
1522       break;
1523
1524     case PROP_TABS:
1525       if (tag->values->tabs)
1526         g_value_set_boxed (value, tag->values->tabs);
1527       break;
1528
1529     case PROP_INVISIBLE:
1530       g_value_set_boolean (value, tag->values->invisible);
1531       break;
1532       
1533     case PROP_BACKGROUND_SET:
1534       g_value_set_boolean (value, tag->bg_color_set);
1535       break;
1536
1537     case PROP_FOREGROUND_SET:
1538       g_value_set_boolean (value, tag->fg_color_set);
1539       break;
1540
1541     case PROP_BACKGROUND_STIPPLE_SET:
1542       g_value_set_boolean (value, tag->bg_stipple_set);
1543       break;
1544
1545     case PROP_FOREGROUND_STIPPLE_SET:
1546       g_value_set_boolean (value, tag->fg_stipple_set);
1547       break;
1548
1549     case PROP_FAMILY_SET:
1550     case PROP_STYLE_SET:
1551     case PROP_VARIANT_SET:
1552     case PROP_WEIGHT_SET:
1553     case PROP_STRETCH_SET:
1554     case PROP_SIZE_SET:
1555       {
1556         PangoFontMask set_mask = tag->values->font ? pango_font_description_get_set_fields (tag->values->font) : 0;
1557         PangoFontMask test_mask = get_property_font_set_mask (prop_id);
1558         g_value_set_boolean (value, (set_mask & test_mask) != 0);
1559
1560         break;
1561       }
1562
1563     case PROP_SCALE_SET:
1564       g_value_set_boolean (value, tag->scale_set);
1565       break;
1566       
1567     case PROP_PIXELS_ABOVE_LINES_SET:
1568       g_value_set_boolean (value, tag->pixels_above_lines_set);
1569       break;
1570
1571     case PROP_PIXELS_BELOW_LINES_SET:
1572       g_value_set_boolean (value, tag->pixels_below_lines_set);
1573       break;
1574
1575     case PROP_PIXELS_INSIDE_WRAP_SET:
1576       g_value_set_boolean (value, tag->pixels_inside_wrap_set);
1577       break;
1578
1579     case PROP_EDITABLE_SET:
1580       g_value_set_boolean (value, tag->editable_set);
1581       break;
1582
1583     case PROP_WRAP_MODE_SET:
1584       g_value_set_boolean (value, tag->wrap_mode_set);
1585       break;
1586
1587     case PROP_JUSTIFICATION_SET:
1588       g_value_set_boolean (value, tag->justification_set);
1589       break;
1590       
1591     case PROP_LEFT_MARGIN_SET:
1592       g_value_set_boolean (value, tag->left_margin_set);
1593       break;
1594
1595     case PROP_INDENT_SET:
1596       g_value_set_boolean (value, tag->indent_set);
1597       break;
1598
1599     case PROP_STRIKETHROUGH_SET:
1600       g_value_set_boolean (value, tag->strikethrough_set);
1601       break;
1602
1603     case PROP_RIGHT_MARGIN_SET:
1604       g_value_set_boolean (value, tag->right_margin_set);
1605       break;
1606
1607     case PROP_UNDERLINE_SET:
1608       g_value_set_boolean (value, tag->underline_set);
1609       break;
1610
1611     case PROP_RISE_SET:
1612       g_value_set_boolean (value, tag->rise_set);
1613       break;
1614
1615     case PROP_BG_FULL_HEIGHT_SET:
1616       g_value_set_boolean (value, tag->bg_full_height_set);
1617       break;
1618
1619     case PROP_LANGUAGE_SET:
1620       g_value_set_boolean (value, tag->language_set);
1621       break;
1622
1623     case PROP_TABS_SET:
1624       g_value_set_boolean (value, tag->tabs_set);
1625       break;
1626
1627     case PROP_INVISIBLE_SET:
1628       g_value_set_boolean (value, tag->invisible_set);
1629       break;
1630       
1631     case PROP_BACKGROUND:
1632     case PROP_FOREGROUND:
1633       g_warning ("'foreground' and 'background' properties are not readable, use 'foreground_gdk' and 'background_gdk'");
1634     default:
1635       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1636       break;
1637     }
1638 }
1639
1640 /*
1641  * Tag operations
1642  */
1643
1644 typedef struct {
1645   gint high;
1646   gint low;
1647   gint delta;
1648 } DeltaData;
1649
1650 static void
1651 delta_priority_foreach (GtkTextTag *tag, gpointer user_data)
1652 {
1653   DeltaData *dd = user_data;
1654
1655   if (tag->priority >= dd->low && tag->priority <= dd->high)
1656     tag->priority += dd->delta;
1657 }
1658
1659 /**
1660  * gtk_text_tag_get_priority:
1661  * @tag: a #GtkTextTag
1662  * 
1663  * Get the tag priority.
1664  * 
1665  * Return value: The tag's priority.
1666  **/
1667 gint
1668 gtk_text_tag_get_priority (GtkTextTag *tag)
1669 {
1670   g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), 0);
1671
1672   return tag->priority;
1673 }
1674
1675 /**
1676  * gtk_text_tag_set_priority:
1677  * @tag: a #GtkTextTag
1678  * @priority: the new priority
1679  * 
1680  * Sets the priority of a #GtkTextTag. Valid priorities are
1681  * start at 0 and go to one less than gtk_text_tag_table_get_size().
1682  * Each tag in a table has a unique priority; setting the priority
1683  * of one tag shifts the priorities of all the other tags in the
1684  * table to maintain a unique priority for each tag. Higher priority
1685  * tags "win" if two tags both set the same text attribute. When adding
1686  * a tag to a tag table, it will be assigned the highest priority in
1687  * the table by default; so normally the precedence of a set of tags
1688  * is the order in which they were added to the table, or created with
1689  * gtk_text_buffer_create_tag(), which adds the tag to the buffer's table
1690  * automatically.
1691  **/
1692 void
1693 gtk_text_tag_set_priority (GtkTextTag *tag,
1694                            gint        priority)
1695 {
1696   DeltaData dd;
1697
1698   g_return_if_fail (GTK_IS_TEXT_TAG (tag));
1699   g_return_if_fail (tag->table != NULL);
1700   g_return_if_fail (priority >= 0);
1701   g_return_if_fail (priority < gtk_text_tag_table_get_size (tag->table));
1702
1703   if (priority == tag->priority)
1704     return;
1705
1706   if (priority < tag->priority)
1707     {
1708       dd.low = priority;
1709       dd.high = tag->priority - 1;
1710       dd.delta = 1;
1711     }
1712   else
1713     {
1714       dd.low = tag->priority + 1;
1715       dd.high = priority;
1716       dd.delta = -1;
1717     }
1718
1719   gtk_text_tag_table_foreach (tag->table,
1720                               delta_priority_foreach,
1721                               &dd);
1722
1723   tag->priority = priority;
1724 }
1725
1726 /**
1727  * gtk_text_tag_event:
1728  * @tag: a #GtkTextTag
1729  * @event_object: object that received the event, such as a widget
1730  * @event: the event
1731  * @iter: location where the event was received
1732  * 
1733  * Emits the "event" signal on the #GtkTextTag.
1734  * 
1735  * Return value: result of signal emission (whether the event was handled)
1736  **/
1737 gboolean
1738 gtk_text_tag_event (GtkTextTag        *tag,
1739                     GObject           *event_object,
1740                     GdkEvent          *event,
1741                     const GtkTextIter *iter)
1742 {
1743   gboolean retval = FALSE;
1744
1745   g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
1746   g_return_val_if_fail (G_IS_OBJECT (event_object), FALSE);
1747   g_return_val_if_fail (event != NULL, FALSE);
1748
1749   g_signal_emit (G_OBJECT (tag),
1750                  signals[EVENT],
1751                  0,
1752                  event_object,
1753                  event,
1754                  iter,
1755                  &retval);
1756
1757   return retval;
1758 }
1759
1760 static int
1761 tag_sort_func (gconstpointer first, gconstpointer second)
1762 {
1763   GtkTextTag *tag1, *tag2;
1764
1765   tag1 = * (GtkTextTag **) first;
1766   tag2 = * (GtkTextTag **) second;
1767   return tag1->priority - tag2->priority;
1768 }
1769
1770 void
1771 _gtk_text_tag_array_sort (GtkTextTag** tag_array_p,
1772                           guint len)
1773 {
1774   int i, j, prio;
1775   GtkTextTag **tag;
1776   GtkTextTag **maxPtrPtr, *tmp;
1777
1778   g_return_if_fail (tag_array_p != NULL);
1779   g_return_if_fail (len > 0);
1780
1781   if (len < 2) {
1782     return;
1783   }
1784   if (len < 20) {
1785     GtkTextTag **iter = tag_array_p;
1786
1787     for (i = len-1; i > 0; i--, iter++) {
1788       maxPtrPtr = tag = iter;
1789       prio = tag[0]->priority;
1790       for (j = i, tag++; j > 0; j--, tag++) {
1791         if (tag[0]->priority < prio) {
1792           prio = tag[0]->priority;
1793           maxPtrPtr = tag;
1794         }
1795       }
1796       tmp = *maxPtrPtr;
1797       *maxPtrPtr = *iter;
1798       *iter = tmp;
1799     }
1800   } else {
1801     qsort ((void *) tag_array_p, (unsigned) len, sizeof (GtkTextTag *),
1802            tag_sort_func);
1803   }
1804
1805 #if 0
1806   {
1807     printf ("Sorted tag array: \n");
1808     i = 0;
1809     while (i < len)
1810       {
1811         GtkTextTag *t = tag_array_p[i];
1812         printf ("  %s priority %d\n", t->name, t->priority);
1813
1814         ++i;
1815       }
1816   }
1817 #endif
1818 }
1819
1820 /*
1821  * Attributes
1822  */
1823
1824 /**
1825  * gtk_text_attributes_new:
1826  * 
1827  * Creates a #GtkTextAttributes, which describes
1828  * a set of properties on some text.
1829  * 
1830  * Return value: a new #GtkTextAttributes
1831  **/
1832 GtkTextAttributes*
1833 gtk_text_attributes_new (void)
1834 {
1835   GtkTextAttributes *values;
1836
1837   values = g_new0 (GtkTextAttributes, 1);
1838
1839   /* 0 is a valid value for most of the struct */
1840
1841   values->refcount = 1;
1842
1843   values->language = gtk_get_default_language ();
1844
1845   values->font_scale = 1.0;
1846   
1847   return values;
1848 }
1849
1850 /**
1851  * gtk_text_attributes_copy:
1852  * @src: a #GtkTextAttributes to be copied
1853  * 
1854  * Copies @src and returns a new #GtkTextAttributes.
1855  * 
1856  * Return value: a copy of @src
1857  **/
1858 GtkTextAttributes*
1859 gtk_text_attributes_copy (GtkTextAttributes *src)
1860 {
1861   GtkTextAttributes *dest;
1862
1863   dest = gtk_text_attributes_new ();
1864   gtk_text_attributes_copy_values (src, dest);
1865
1866   return dest;
1867 }
1868
1869 /**
1870  * gtk_text_attributes_copy_values:
1871  * @src: a #GtkTextAttributes
1872  * @dest: another #GtkTextAttributes
1873  * 
1874  * Copies the values from @src to @dest so that @dest has the same values
1875  * as @src. Frees existing values in @dest.
1876  **/
1877 void
1878 gtk_text_attributes_copy_values (GtkTextAttributes *src,
1879                                  GtkTextAttributes *dest)
1880 {
1881   guint orig_refcount;
1882
1883   g_return_if_fail (!dest->realized);
1884
1885   if (src == dest)
1886     return;
1887
1888   /* Add refs */
1889
1890   if (src->appearance.bg_stipple)
1891     gdk_bitmap_ref (src->appearance.bg_stipple);
1892
1893   if (src->appearance.fg_stipple)
1894     gdk_bitmap_ref (src->appearance.fg_stipple);
1895
1896   /* Remove refs */
1897
1898   if (dest->appearance.bg_stipple)
1899     gdk_bitmap_unref (dest->appearance.bg_stipple);
1900
1901   if (dest->appearance.fg_stipple)
1902     gdk_bitmap_unref (dest->appearance.fg_stipple);
1903
1904   if (dest->font)
1905     pango_font_description_free (dest->font);
1906   
1907   /* Copy */
1908   orig_refcount = dest->refcount;
1909
1910   *dest = *src;
1911
1912   if (src->tabs)
1913     dest->tabs = pango_tab_array_copy (src->tabs);
1914
1915   dest->language = src->language;
1916
1917   if (dest->font)
1918     dest->font = pango_font_description_copy (src->font);
1919   
1920   dest->refcount = orig_refcount;
1921   dest->realized = FALSE;
1922 }
1923
1924 /**
1925  * gtk_text_attributes_ref:
1926  * @values: a #GtkTextAttributes
1927  * 
1928  * Increments the reference count on @values.
1929  **/
1930 void
1931 gtk_text_attributes_ref (GtkTextAttributes *values)
1932 {
1933   g_return_if_fail (values != NULL);
1934
1935   values->refcount += 1;
1936 }
1937
1938 /**
1939  * gtk_text_attributes_unref:
1940  * @values: a #GtkTextAttributes
1941  * 
1942  * Decrements the reference count on @values, freeing the structure
1943  * if the reference count reaches 0.
1944  **/
1945 void
1946 gtk_text_attributes_unref (GtkTextAttributes *values)
1947 {
1948   g_return_if_fail (values != NULL);
1949   g_return_if_fail (values->refcount > 0);
1950
1951   values->refcount -= 1;
1952
1953   if (values->refcount == 0)
1954     {
1955       g_assert (!values->realized);
1956
1957       if (values->appearance.bg_stipple)
1958         gdk_bitmap_unref (values->appearance.bg_stipple);
1959
1960       if (values->appearance.fg_stipple)
1961         gdk_bitmap_unref (values->appearance.fg_stipple);
1962
1963       if (values->tabs)
1964         pango_tab_array_free (values->tabs);
1965
1966       if (values->font)
1967         pango_font_description_free (values->font);
1968       
1969       g_free (values);
1970     }
1971 }
1972
1973 void
1974 _gtk_text_attributes_realize (GtkTextAttributes *values,
1975                               GdkColormap *cmap,
1976                               GdkVisual *visual)
1977 {
1978   g_return_if_fail (values != NULL);
1979   g_return_if_fail (values->refcount > 0);
1980   g_return_if_fail (!values->realized);
1981
1982   /* It is wrong to use this colormap, FIXME */
1983   gdk_colormap_alloc_color (cmap,
1984                             &values->appearance.fg_color,
1985                             FALSE, TRUE);
1986
1987   gdk_colormap_alloc_color (cmap,
1988                             &values->appearance.bg_color,
1989                             FALSE, TRUE);
1990
1991   values->realized = TRUE;
1992 }
1993
1994 void
1995 _gtk_text_attributes_unrealize (GtkTextAttributes *values,
1996                                 GdkColormap *cmap,
1997                                 GdkVisual *visual)
1998 {
1999   g_return_if_fail (values != NULL);
2000   g_return_if_fail (values->refcount > 0);
2001   g_return_if_fail (values->realized);
2002
2003   gdk_colormap_free_colors (cmap,
2004                             &values->appearance.fg_color, 1);
2005
2006
2007   gdk_colormap_free_colors (cmap,
2008                             &values->appearance.bg_color, 1);
2009
2010   values->appearance.fg_color.pixel = 0;
2011   values->appearance.bg_color.pixel = 0;
2012
2013   values->realized = FALSE;
2014 }
2015
2016 void
2017 _gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest,
2018                                      GtkTextTag**       tags,
2019                                      guint              n_tags)
2020 {
2021   guint n = 0;
2022
2023   g_return_if_fail (!dest->realized);
2024
2025   while (n < n_tags)
2026     {
2027       GtkTextTag *tag = tags[n];
2028       GtkTextAttributes *vals = tag->values;
2029
2030       g_assert (tag->table != NULL);
2031       if (n > 0)
2032         g_assert (tags[n]->priority > tags[n-1]->priority);
2033
2034       if (tag->bg_color_set)
2035         {
2036           dest->appearance.bg_color = vals->appearance.bg_color;
2037
2038           dest->appearance.draw_bg = TRUE;
2039         }
2040       if (tag->fg_color_set)
2041         dest->appearance.fg_color = vals->appearance.fg_color;
2042       
2043       if (tag->bg_stipple_set)
2044         {
2045           gdk_bitmap_ref (vals->appearance.bg_stipple);
2046           if (dest->appearance.bg_stipple)
2047             gdk_bitmap_unref (dest->appearance.bg_stipple);
2048           dest->appearance.bg_stipple = vals->appearance.bg_stipple;
2049
2050           dest->appearance.draw_bg = TRUE;
2051         }
2052
2053       if (tag->fg_stipple_set)
2054         {
2055           gdk_bitmap_ref (vals->appearance.fg_stipple);
2056           if (dest->appearance.fg_stipple)
2057             gdk_bitmap_unref (dest->appearance.fg_stipple);
2058           dest->appearance.fg_stipple = vals->appearance.fg_stipple;
2059         }
2060
2061       if (vals->font)
2062         {
2063           if (dest->font)
2064             pango_font_description_merge (dest->font, vals->font, TRUE);
2065           else
2066             dest->font = pango_font_description_copy (vals->font);
2067         }
2068
2069       /* multiply all the scales together to get a composite */
2070       if (tag->scale_set)
2071         dest->font_scale *= vals->font_scale;
2072       
2073       if (tag->justification_set)
2074         dest->justification = vals->justification;
2075
2076       if (vals->direction != GTK_TEXT_DIR_NONE)
2077         dest->direction = vals->direction;
2078
2079       if (tag->left_margin_set)
2080         dest->left_margin = vals->left_margin;
2081
2082       if (tag->indent_set)
2083         dest->indent = vals->indent;
2084
2085       if (tag->rise_set)
2086         dest->appearance.rise = vals->appearance.rise;
2087
2088       if (tag->right_margin_set)
2089         dest->right_margin = vals->right_margin;
2090
2091       if (tag->pixels_above_lines_set)
2092         dest->pixels_above_lines = vals->pixels_above_lines;
2093
2094       if (tag->pixels_below_lines_set)
2095         dest->pixels_below_lines = vals->pixels_below_lines;
2096
2097       if (tag->pixels_inside_wrap_set)
2098         dest->pixels_inside_wrap = vals->pixels_inside_wrap;
2099
2100       if (tag->tabs_set)
2101         {
2102           if (dest->tabs)
2103             pango_tab_array_free (dest->tabs);
2104           dest->tabs = pango_tab_array_copy (vals->tabs);
2105         }
2106
2107       if (tag->wrap_mode_set)
2108         dest->wrap_mode = vals->wrap_mode;
2109
2110       if (tag->underline_set)
2111         dest->appearance.underline = vals->appearance.underline;
2112
2113       if (tag->strikethrough_set)
2114         dest->appearance.strikethrough = vals->appearance.strikethrough;
2115
2116       if (tag->invisible_set)
2117         dest->invisible = vals->invisible;
2118
2119       if (tag->editable_set)
2120         dest->editable = vals->editable;
2121
2122       if (tag->bg_full_height_set)
2123         dest->bg_full_height = vals->bg_full_height;
2124
2125       if (tag->language_set)
2126         dest->language = vals->language;
2127
2128       ++n;
2129     }
2130 }
2131
2132 gboolean
2133 _gtk_text_tag_affects_size (GtkTextTag *tag)
2134 {
2135   g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
2136
2137   return
2138     (tag->values->font && pango_font_description_get_set_fields (tag->values->font) != 0) ||
2139     tag->scale_set ||
2140     tag->justification_set ||
2141     tag->left_margin_set ||
2142     tag->indent_set ||
2143     tag->rise_set ||
2144     tag->right_margin_set ||
2145     tag->pixels_above_lines_set ||
2146     tag->pixels_below_lines_set ||
2147     tag->pixels_inside_wrap_set ||
2148     tag->tabs_set ||
2149     tag->underline_set ||
2150     tag->wrap_mode_set ||
2151     tag->invisible_set;
2152 }
2153
2154 gboolean
2155 _gtk_text_tag_affects_nonsize_appearance (GtkTextTag *tag)
2156 {
2157   g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
2158
2159   return
2160     tag->bg_color_set ||
2161     tag->bg_stipple_set ||
2162     tag->fg_color_set ||
2163     tag->fg_stipple_set ||
2164     tag->strikethrough_set ||
2165     tag->bg_full_height_set;
2166 }