gtktexttag.c 67.4 KB
Newer Older
1
/* gtktexttag.c - text tag object
2
 *
3 4 5 6 7 8 9 10 11
 * Copyright (c) 1992-1994 The Regents of the University of California.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 2000      Red Hat, Inc.
 * Tk -> Gtk port by Havoc Pennington <hp@redhat.com>
 *
 * This software is copyrighted by the Regents of the University of
 * California, Sun Microsystems, Inc., and other parties.  The
 * following terms apply to all files associated with the software
 * unless explicitly disclaimed in individual files.
12
 *
13 14 15 16 17 18 19 20 21
 * The authors hereby grant permission to use, copy, modify,
 * distribute, and license this software and its documentation for any
 * purpose, provided that existing copyright notices are retained in
 * all copies and that this notice is included verbatim in any
 * distributions. No written agreement, license, or royalty fee is
 * required for any of the authorized uses.  Modifications to this
 * software may be copyrighted by their authors and need not follow
 * the licensing terms described here, provided that the new terms are
 * clearly indicated on the first page of each file where they apply.
22
 *
23 24 25 26 27
 * IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY
 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
 * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION,
 * OR ANY DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
28
 *
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
 * THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
 * NON-INFRINGEMENT.  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS,
 * AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
 * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 * GOVERNMENT USE: If you are acquiring this software on behalf of the
 * U.S. government, the Government shall have only "Restricted Rights"
 * in the software and related documentation as defined in the Federal
 * Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2).  If you
 * are acquiring the software on behalf of the Department of Defense,
 * the software shall be classified as "Commercial Computer Software"
 * and the Government shall have only "Restricted Rights" as defined
 * in Clause 252.227-7013 (c) (1) of DFARs.  Notwithstanding the
 * foregoing, the authors grant the U.S. Government and others acting
 * in its behalf permission to use and distribute the software in
 * accordance with the terms specified in this license.
47
 *
48 49
 */

50
/**
Matthias Clasen's avatar
Matthias Clasen committed
51
 * SECTION:gtktexttag
52 53 54 55 56 57 58 59 60 61 62 63 64 65
 * @Title: GtkTextTag
 * @Short_description: A tag that can be applied to text in a GtkTextBuffer
 *
 * You may wish to begin by reading the <link linkend="TextWidget">text widget
 * conceptual overview</link> which gives an overview of all the objects and
 * data types related to the text widget and how they work together.
 *
 * Tags should be in the #GtkTextTagTable for a given #GtkTextBuffer
 * before using them with that buffer.
 *
 * gtk_text_buffer_create_tag() is the best way to create tags.
 * See <application>gtk3-demo</application> for numerous examples.
 */

66
#include "config.h"
67 68 69 70

#include <stdlib.h>
#include <string.h>

71 72 73
#include "gtktexttag.h"
#include "gtktexttypes.h"
#include "gtktexttagtable.h"
74
#include "gtkintl.h"
75
#include "gtkmarshalers.h"
76
#include "gtkprivate.h"
77
#include "gtktypebuiltins.h"
78 79 80 81 82 83 84

enum {
  EVENT,
  LAST_SIGNAL
};

enum {
85
  PROP_0,
86
  /* Construct args */
87
  PROP_NAME,
88 89

  /* Style args */
90 91 92 93
  PROP_BACKGROUND,
  PROP_FOREGROUND,
  PROP_BACKGROUND_GDK,
  PROP_FOREGROUND_GDK,
94 95
  PROP_BACKGROUND_RGBA,
  PROP_FOREGROUND_RGBA,
96 97 98 99 100 101 102 103 104
  PROP_FONT,
  PROP_FONT_DESC,
  PROP_FAMILY,
  PROP_STYLE,
  PROP_VARIANT,
  PROP_WEIGHT,
  PROP_STRETCH,
  PROP_SIZE,
  PROP_SIZE_POINTS,
Havoc Pennington's avatar
Havoc Pennington committed
105
  PROP_SCALE,
106 107 108 109 110
  PROP_PIXELS_ABOVE_LINES,
  PROP_PIXELS_BELOW_LINES,
  PROP_PIXELS_INSIDE_WRAP,
  PROP_EDITABLE,
  PROP_WRAP_MODE,
111
  PROP_JUSTIFICATION,
112 113 114 115 116 117 118
  PROP_DIRECTION,
  PROP_LEFT_MARGIN,
  PROP_INDENT,
  PROP_STRIKETHROUGH,
  PROP_RIGHT_MARGIN,
  PROP_UNDERLINE,
  PROP_RISE,
Soeren Sandmann's avatar
Soeren Sandmann committed
119
  PROP_BACKGROUND_FULL_HEIGHT,
120 121 122
  PROP_LANGUAGE,
  PROP_TABS,
  PROP_INVISIBLE,
123 124
  PROP_PARAGRAPH_BACKGROUND,
  PROP_PARAGRAPH_BACKGROUND_GDK,
125
  PROP_PARAGRAPH_BACKGROUND_RGBA,
126 127 128

  /* Behavior args */
  PROP_ACCUMULATIVE_MARGIN,
129
  
130
  /* Whether-a-style-arg-is-set args */
131 132 133 134 135 136 137 138
  PROP_BACKGROUND_SET,
  PROP_FOREGROUND_SET,
  PROP_FAMILY_SET,
  PROP_STYLE_SET,
  PROP_VARIANT_SET,
  PROP_WEIGHT_SET,
  PROP_STRETCH_SET,
  PROP_SIZE_SET,
Havoc Pennington's avatar
Havoc Pennington committed
139
  PROP_SCALE_SET,
140 141 142 143 144
  PROP_PIXELS_ABOVE_LINES_SET,
  PROP_PIXELS_BELOW_LINES_SET,
  PROP_PIXELS_INSIDE_WRAP_SET,
  PROP_EDITABLE_SET,
  PROP_WRAP_MODE_SET,
145
  PROP_JUSTIFICATION_SET,
146 147 148 149 150 151
  PROP_LEFT_MARGIN_SET,
  PROP_INDENT_SET,
  PROP_STRIKETHROUGH_SET,
  PROP_RIGHT_MARGIN_SET,
  PROP_UNDERLINE_SET,
  PROP_RISE_SET,
Soeren Sandmann's avatar
Soeren Sandmann committed
152
  PROP_BACKGROUND_FULL_HEIGHT_SET,
153 154 155
  PROP_LANGUAGE_SET,
  PROP_TABS_SET,
  PROP_INVISIBLE_SET,
156
  PROP_PARAGRAPH_BACKGROUND_SET,
157

158 159
  LAST_ARG
};
160 161 162 163
static void gtk_text_tag_finalize     (GObject         *object);
static void gtk_text_tag_set_property (GObject         *object,
                                       guint            prop_id,
                                       const GValue    *value,
Tim Janik's avatar
Tim Janik committed
164
                                       GParamSpec      *pspec);
165 166 167
static void gtk_text_tag_get_property (GObject         *object,
                                       guint            prop_id,
                                       GValue          *value,
Tim Janik's avatar
Tim Janik committed
168
                                       GParamSpec      *pspec);
169

170 171
static guint signals[LAST_SIGNAL] = { 0 };

Matthias Clasen's avatar
Matthias Clasen committed
172
G_DEFINE_TYPE (GtkTextTag, gtk_text_tag, G_TYPE_OBJECT)
173 174 175 176

static void
gtk_text_tag_class_init (GtkTextTagClass *klass)
{
177
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
178

179 180 181 182
  object_class->set_property = gtk_text_tag_set_property;
  object_class->get_property = gtk_text_tag_get_property;
  
  object_class->finalize = gtk_text_tag_finalize;
183

184
  /* Construct */
185 186 187
  g_object_class_install_property (object_class,
                                   PROP_NAME,
                                   g_param_spec_string ("name",
188 189
                                                        P_("Tag name"),
                                                        P_("Name used to refer to the text tag. NULL for anonymous tags"),
190
                                                        NULL,
191
                                                        GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
192 193

  /* Style args */
194 195 196 197

  g_object_class_install_property (object_class,
                                   PROP_BACKGROUND,
                                   g_param_spec_string ("background",
198 199
                                                        P_("Background color name"),
                                                        P_("Background color as a string"),
200
                                                        NULL,
201
                                                        GTK_PARAM_WRITABLE));
202

203 204 205 206 207 208 209
  /**
   * GtkTextTag:background-gdk:
   *
   * Background color as a #GdkColor.
   *
   * Deprecated: 3.4: Use #GtkTextTag:background-rgba instead.
   */
210 211
  g_object_class_install_property (object_class,
                                   PROP_BACKGROUND_GDK,
Matthias Clasen's avatar
x  
Matthias Clasen committed
212
                                   g_param_spec_boxed ("background-gdk",
213
                                                       P_("Background color"),
214
                                                       P_("Background color as a GdkColor"),
215
                                                       GDK_TYPE_COLOR,
216
                                                       GTK_PARAM_READWRITE | G_PARAM_DEPRECATED));
217

218 219 220
  /**
   * GtkTextTag:background-rgba:
   *
221
   * Background color as a #GdkRGBA.
222 223 224
   *
   * Since: 3.2
   */
225 226 227
  g_object_class_install_property (object_class,
                                   PROP_BACKGROUND_RGBA,
                                   g_param_spec_boxed ("background-rgba",
Rachid BM's avatar
Rachid BM committed
228
                                                       P_("Background RGBA"),
229
                                                       P_("Background color as a GdkRGBA"),
230 231 232
                                                       GDK_TYPE_RGBA,
                                                       GTK_PARAM_READWRITE));

233
  g_object_class_install_property (object_class,
Soeren Sandmann's avatar
Soeren Sandmann committed
234
                                   PROP_BACKGROUND_FULL_HEIGHT,
Matthias Clasen's avatar
x  
Matthias Clasen committed
235
                                   g_param_spec_boolean ("background-full-height",
236 237
                                                         P_("Background full height"),
                                                         P_("Whether the background color fills the entire line height or only the height of the tagged characters"),
238
                                                         FALSE,
239
                                                         GTK_PARAM_READWRITE));
240
  
241 242 243
  g_object_class_install_property (object_class,
                                   PROP_FOREGROUND,
                                   g_param_spec_string ("foreground",
244 245
                                                        P_("Foreground color name"),
                                                        P_("Foreground color as a string"),
246
                                                        NULL,
247
                                                        GTK_PARAM_WRITABLE));
248

249 250 251 252 253 254 255
  /**
   * GtkTextTag:foreground-gdk:
   *
   * Foreground color as a #GdkColor.
   *
   * Deprecated: 3.4: Use #GtkTextTag:foreground-rgba instead.
   */
256 257
  g_object_class_install_property (object_class,
                                   PROP_FOREGROUND_GDK,
Matthias Clasen's avatar
x  
Matthias Clasen committed
258
                                   g_param_spec_boxed ("foreground-gdk",
259
                                                       P_("Foreground color"),
260
                                                       P_("Foreground color as a GdkColor"),
261
                                                       GDK_TYPE_COLOR,
262
                                                       GTK_PARAM_READWRITE | G_PARAM_DEPRECATED));
263

264 265 266
  /**
   * GtkTextTag:foreground-rgba:
   *
267
   * Foreground color as a #GdkRGBA.
268 269 270
   *
   * Since: 3.2
   */
271 272 273
  g_object_class_install_property (object_class,
                                   PROP_FOREGROUND_RGBA,
                                   g_param_spec_boxed ("foreground-rgba",
Rachid BM's avatar
Rachid BM committed
274
                                                       P_("Foreground RGBA"),
275
                                                       P_("Foreground color as a GdkRGBA"),
276 277 278
                                                       GDK_TYPE_RGBA,
                                                       GTK_PARAM_READWRITE));

279 280 281
  g_object_class_install_property (object_class,
                                   PROP_DIRECTION,
                                   g_param_spec_enum ("direction",
282 283
                                                      P_("Text direction"),
                                                      P_("Text direction, e.g. right-to-left or left-to-right"),
284
                                                      GTK_TYPE_TEXT_DIRECTION,
285
                                                      GTK_TEXT_DIR_NONE,
286
                                                      GTK_PARAM_READWRITE));
287 288 289 290

  g_object_class_install_property (object_class,
                                   PROP_EDITABLE,
                                   g_param_spec_boolean ("editable",
291 292
                                                         P_("Editable"),
                                                         P_("Whether the text can be modified by the user"),
293
                                                         TRUE,
294
                                                         GTK_PARAM_READWRITE));
295

296 297 298 299 300 301 302 303
  /**
   * GtkTextTag:font:
   *
   * Font description as string, e.g. \"Sans Italic 12\". 
   *
   * Note that the initial value of this property depends on
   * the internals of #PangoFontDescription.
   */
304 305 306
  g_object_class_install_property (object_class,
                                   PROP_FONT,
                                   g_param_spec_string ("font",
307 308
                                                        P_("Font"),
                                                        P_("Font description as a string, e.g. \"Sans Italic 12\""),
309
                                                        NULL,
310
                                                        GTK_PARAM_READWRITE));
311 312 313

  g_object_class_install_property (object_class,
                                   PROP_FONT_DESC,
Matthias Clasen's avatar
x  
Matthias Clasen committed
314
                                   g_param_spec_boxed ("font-desc",
315 316
                                                       P_("Font"),
                                                       P_("Font description as a PangoFontDescription struct"),
317
                                                       PANGO_TYPE_FONT_DESCRIPTION,
318
                                                       GTK_PARAM_READWRITE));
319 320 321 322
  
  g_object_class_install_property (object_class,
                                   PROP_FAMILY,
                                   g_param_spec_string ("family",
323 324
                                                        P_("Font family"),
                                                        P_("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
325
                                                        NULL,
326
                                                        GTK_PARAM_READWRITE));
327 328 329 330

  g_object_class_install_property (object_class,
                                   PROP_STYLE,
                                   g_param_spec_enum ("style",
331 332
                                                      P_("Font style"),
                                                      P_("Font style as a PangoStyle, e.g. PANGO_STYLE_ITALIC"),
333 334
                                                      PANGO_TYPE_STYLE,
                                                      PANGO_STYLE_NORMAL,
335
                                                      GTK_PARAM_READWRITE));
336 337 338 339

  g_object_class_install_property (object_class,
                                   PROP_VARIANT,
                                   g_param_spec_enum ("variant",
340 341
                                                     P_("Font variant"),
                                                     P_("Font variant as a PangoVariant, e.g. PANGO_VARIANT_SMALL_CAPS"),
342 343
                                                      PANGO_TYPE_VARIANT,
                                                      PANGO_VARIANT_NORMAL,
344
                                                      GTK_PARAM_READWRITE));
345 346 347 348
  
  g_object_class_install_property (object_class,
                                   PROP_WEIGHT,
                                   g_param_spec_int ("weight",
349 350
                                                     P_("Font weight"),
                                                     P_("Font weight as an integer, see predefined values in PangoWeight; for example, PANGO_WEIGHT_BOLD"),
351 352 353
                                                     0,
                                                     G_MAXINT,
                                                     PANGO_WEIGHT_NORMAL,
354
                                                     GTK_PARAM_READWRITE));
355 356 357 358 359
  

  g_object_class_install_property (object_class,
                                   PROP_STRETCH,
                                   g_param_spec_enum ("stretch",
360 361
                                                      P_("Font stretch"),
                                                      P_("Font stretch as a PangoStretch, e.g. PANGO_STRETCH_CONDENSED"),
362 363
                                                      PANGO_TYPE_STRETCH,
                                                      PANGO_STRETCH_NORMAL,
364
                                                      GTK_PARAM_READWRITE));
365 366 367 368
  
  g_object_class_install_property (object_class,
                                   PROP_SIZE,
                                   g_param_spec_int ("size",
369 370
                                                     P_("Font size"),
                                                     P_("Font size in Pango units"),
371 372 373
                                                     0,
                                                     G_MAXINT,
                                                     0,
374
                                                     GTK_PARAM_READWRITE));
375

Havoc Pennington's avatar
Havoc Pennington committed
376 377 378
  g_object_class_install_property (object_class,
                                   PROP_SCALE,
                                   g_param_spec_double ("scale",
379 380
                                                        P_("Font scale"),
                                                        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"),
Havoc Pennington's avatar
Havoc Pennington committed
381 382 383
                                                        0.0,
                                                        G_MAXDOUBLE,
                                                        1.0,
384
                                                        GTK_PARAM_READWRITE));
Havoc Pennington's avatar
Havoc Pennington committed
385
  
386 387
  g_object_class_install_property (object_class,
                                   PROP_SIZE_POINTS,
Matthias Clasen's avatar
x  
Matthias Clasen committed
388
                                   g_param_spec_double ("size-points",
389 390
                                                        P_("Font points"),
                                                        P_("Font size in points"),
391 392 393
                                                        0.0,
                                                        G_MAXDOUBLE,
                                                        0.0,
394
                                                        GTK_PARAM_READWRITE));  
395 396

  g_object_class_install_property (object_class,
397 398
                                   PROP_JUSTIFICATION,
                                   g_param_spec_enum ("justification",
399 400
                                                      P_("Justification"),
                                                      P_("Left, right, or center justification"),
401 402
                                                      GTK_TYPE_JUSTIFICATION,
                                                      GTK_JUSTIFY_LEFT,
403
                                                      GTK_PARAM_READWRITE));
404 405 406 407 408 409 410 411 412 413 414

  /**
   * GtkTextTag:language:
   *
   * 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.
   *
   * Note that the initial value of this property depends on the current
   * locale, see also gtk_get_default_language().
   */
415 416 417
  g_object_class_install_property (object_class,
                                   PROP_LANGUAGE,
                                   g_param_spec_string ("language",
418
                                                        P_("Language"),
419
                                                        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."),
420
                                                        NULL,
421
                                                        GTK_PARAM_READWRITE));  
422 423 424

  g_object_class_install_property (object_class,
                                   PROP_LEFT_MARGIN,
Matthias Clasen's avatar
x  
Matthias Clasen committed
425
                                   g_param_spec_int ("left-margin",
426 427
                                                     P_("Left margin"),
                                                     P_("Width of the left margin in pixels"),
428 429 430
                                                     0,
                                                     G_MAXINT,
                                                     0,
431
                                                     GTK_PARAM_READWRITE));
432 433 434

  g_object_class_install_property (object_class,
                                   PROP_RIGHT_MARGIN,
Matthias Clasen's avatar
x  
Matthias Clasen committed
435
                                   g_param_spec_int ("right-margin",
436 437
                                                     P_("Right margin"),
                                                     P_("Width of the right margin in pixels"),
438 439 440
                                                     0,
                                                     G_MAXINT,
                                                     0,
441
                                                     GTK_PARAM_READWRITE));
442 443 444 445 446

  
  g_object_class_install_property (object_class,
                                   PROP_INDENT,
                                   g_param_spec_int ("indent",
447 448
                                                     P_("Indent"),
                                                     P_("Amount to indent the paragraph, in pixels"),
449
                                                     G_MININT,
450 451
                                                     G_MAXINT,
                                                     0,
452
                                                     GTK_PARAM_READWRITE));
453 454 455 456 457

  
  g_object_class_install_property (object_class,
                                   PROP_RISE,
                                   g_param_spec_int ("rise",
458
                                                     P_("Rise"),
459
                                                     P_("Offset of text above the baseline (below the baseline if rise is negative) in Pango units"),
460
						     G_MININT,
461 462
                                                     G_MAXINT,
                                                     0,
463
                                                     GTK_PARAM_READWRITE));
464 465 466

  g_object_class_install_property (object_class,
                                   PROP_PIXELS_ABOVE_LINES,
Matthias Clasen's avatar
x  
Matthias Clasen committed
467
                                   g_param_spec_int ("pixels-above-lines",
468 469
                                                     P_("Pixels above lines"),
                                                     P_("Pixels of blank space above paragraphs"),
470 471 472
                                                     0,
                                                     G_MAXINT,
                                                     0,
473
                                                     GTK_PARAM_READWRITE));
474 475 476
  
  g_object_class_install_property (object_class,
                                   PROP_PIXELS_BELOW_LINES,
Matthias Clasen's avatar
x  
Matthias Clasen committed
477
                                   g_param_spec_int ("pixels-below-lines",
478 479
                                                     P_("Pixels below lines"),
                                                     P_("Pixels of blank space below paragraphs"),
480 481 482
                                                     0,
                                                     G_MAXINT,
                                                     0,
483
                                                     GTK_PARAM_READWRITE));
484 485 486

  g_object_class_install_property (object_class,
                                   PROP_PIXELS_INSIDE_WRAP,
Matthias Clasen's avatar
x  
Matthias Clasen committed
487
                                   g_param_spec_int ("pixels-inside-wrap",
488 489
                                                     P_("Pixels inside wrap"),
                                                     P_("Pixels of blank space between wrapped lines in a paragraph"),
490 491 492
                                                     0,
                                                     G_MAXINT,
                                                     0,
493
                                                     GTK_PARAM_READWRITE));
494 495 496 497

  g_object_class_install_property (object_class,
                                   PROP_STRIKETHROUGH,
                                   g_param_spec_boolean ("strikethrough",
498 499
                                                         P_("Strikethrough"),
                                                         P_("Whether to strike through the text"),
500
                                                         FALSE,
501
                                                         GTK_PARAM_READWRITE));
502 503 504 505
  
  g_object_class_install_property (object_class,
                                   PROP_UNDERLINE,
                                   g_param_spec_enum ("underline",
506 507
                                                      P_("Underline"),
                                                      P_("Style of underline for this text"),
508 509
                                                      PANGO_TYPE_UNDERLINE,
                                                      PANGO_UNDERLINE_NONE,
510
                                                      GTK_PARAM_READWRITE));
511 512 513
  
  g_object_class_install_property (object_class,
                                   PROP_WRAP_MODE,
Matthias Clasen's avatar
x  
Matthias Clasen committed
514
                                   g_param_spec_enum ("wrap-mode",
515 516
                                                     P_("Wrap mode"),
                                                     P_("Whether to wrap lines never, at word boundaries, or at character boundaries"),
517
                                                      GTK_TYPE_WRAP_MODE,
518
                                                      GTK_WRAP_NONE,
519
                                                      GTK_PARAM_READWRITE));
520 521 522 523 524
  

  g_object_class_install_property (object_class,
                                   PROP_TABS,
                                   g_param_spec_boxed ("tabs",
525 526
                                                       P_("Tabs"),
                                                       P_("Custom tabs for this text"),
527
                                                       PANGO_TYPE_TAB_ARRAY,
528
                                                       GTK_PARAM_READWRITE));
529
  
530 531 532 533 534 535 536 537 538 539 540
  /**
   * GtkTextTag:invisible:
   *
   * Whether this text is hidden.
   *
   * Note that there may still be problems with the support for invisible 
   * text, in particular when navigating programmatically inside a buffer
   * containing invisible segments. 
   *
   * Since: 2.8
   */
541 542 543
  g_object_class_install_property (object_class,
                                   PROP_INVISIBLE,
                                   g_param_spec_boolean ("invisible",
544
                                                         P_("Invisible"),
545
                                                         P_("Whether this text is hidden."),
546
                                                         FALSE,
547
                                                         GTK_PARAM_READWRITE));
548

549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566
  /**
   * GtkTextTag:paragraph-background:
   *
   * The paragraph background color as a string.
   *
   * Since: 2.8
   */
  g_object_class_install_property (object_class,
                                   PROP_PARAGRAPH_BACKGROUND,
                                   g_param_spec_string ("paragraph-background",
                                                        P_("Paragraph background color name"),
                                                        P_("Paragraph background color as a string"),
                                                        NULL,
                                                        GTK_PARAM_WRITABLE));

  /**
   * GtkTextTag:paragraph-background-gdk:
   *
567
   * The paragraph background color as a as a #GdkColor.
568 569
   *
   * Since: 2.8
570 571
   *
   * Deprecated: 3.4: Use #GtkTextTag:paragraph-background-rgba instead.
572 573 574 575 576
   */
  g_object_class_install_property (object_class,
                                   PROP_PARAGRAPH_BACKGROUND_GDK,
                                   g_param_spec_boxed ("paragraph-background-gdk",
                                                       P_("Paragraph background color"),
577
                                                       P_("Paragraph background color as a GdkColor"),
578
                                                       GDK_TYPE_COLOR,
579
                                                       GTK_PARAM_READWRITE | G_PARAM_DEPRECATED));
580

581 582 583
  /**
   * GtkTextTag:paragraph-background-rgba:
   *
584
   * The paragraph background color as a as a #GdkRGBA.
585 586 587 588 589 590
   *
   * Since: 3.2
   */
  g_object_class_install_property (object_class,
                                   PROP_PARAGRAPH_BACKGROUND_RGBA,
                                   g_param_spec_boxed ("paragraph-background-rgba",
Rachid BM's avatar
Rachid BM committed
591 592
                                                       P_("Paragraph background RGBA"),
                                                       P_("Paragraph background RGBA as a GdkRGBA"),
593 594 595
                                                       GDK_TYPE_RGBA,
                                                       GTK_PARAM_READWRITE));

596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614
  /**
   * GtkTextTag:accumulative-margin:
   *
   * Whether the margins accumulate or override each other.
   *
   * When set to %TRUE the margins of this tag are added to the margins 
   * of any other non-accumulative margins present. When set to %FALSE 
   * the margins override one another (the default).
   *
   * Since: 2.12
   */
  g_object_class_install_property (object_class,
                                   PROP_ACCUMULATIVE_MARGIN,
                                   g_param_spec_boolean ("accumulative-margin",
                                                         P_("Margin Accumulates"),
                                                         P_("Whether left and right margins accumulate."),
                                                         FALSE,
                                                         GTK_PARAM_READWRITE));

615 616
  /* Style props are set or not */

617
#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))
618

Matthias Clasen's avatar
x  
Matthias Clasen committed
619
  ADD_SET_PROP ("background-set", PROP_BACKGROUND_SET,
620 621
                P_("Background set"),
                P_("Whether this tag affects the background color"));
622
  
Matthias Clasen's avatar
x  
Matthias Clasen committed
623
  ADD_SET_PROP ("background-full-height-set", PROP_BACKGROUND_FULL_HEIGHT_SET,
624 625
                P_("Background full height set"),
                P_("Whether this tag affects background height"));
626

Matthias Clasen's avatar
x  
Matthias Clasen committed
627
  ADD_SET_PROP ("foreground-set", PROP_FOREGROUND_SET,
628 629
                P_("Foreground set"),
                P_("Whether this tag affects the foreground color"));
630

Matthias Clasen's avatar
x  
Matthias Clasen committed
631
  ADD_SET_PROP ("editable-set", PROP_EDITABLE_SET,
632 633
                P_("Editability set"),
                P_("Whether this tag affects text editability"));
634

Matthias Clasen's avatar
x  
Matthias Clasen committed
635
  ADD_SET_PROP ("family-set", PROP_FAMILY_SET,
636 637
                P_("Font family set"),
                P_("Whether this tag affects the font family"));  
638

Matthias Clasen's avatar
x  
Matthias Clasen committed
639
  ADD_SET_PROP ("style-set", PROP_STYLE_SET,
640 641
                P_("Font style set"),
                P_("Whether this tag affects the font style"));
642

Matthias Clasen's avatar
x  
Matthias Clasen committed
643
  ADD_SET_PROP ("variant-set", PROP_VARIANT_SET,
644 645
                P_("Font variant set"),
                P_("Whether this tag affects the font variant"));
646

Matthias Clasen's avatar
x  
Matthias Clasen committed
647
  ADD_SET_PROP ("weight-set", PROP_WEIGHT_SET,
648 649
                P_("Font weight set"),
                P_("Whether this tag affects the font weight"));
650

Matthias Clasen's avatar
x  
Matthias Clasen committed
651
  ADD_SET_PROP ("stretch-set", PROP_STRETCH_SET,
652 653
                P_("Font stretch set"),
                P_("Whether this tag affects the font stretch"));
654

Matthias Clasen's avatar
x  
Matthias Clasen committed
655
  ADD_SET_PROP ("size-set", PROP_SIZE_SET,
656 657
                P_("Font size set"),
                P_("Whether this tag affects the font size"));
658

Matthias Clasen's avatar
x  
Matthias Clasen committed
659
  ADD_SET_PROP ("scale-set", PROP_SCALE_SET,
660 661
                P_("Font scale set"),
                P_("Whether this tag scales the font size by a factor"));
Havoc Pennington's avatar
Havoc Pennington committed
662
  
Matthias Clasen's avatar
x  
Matthias Clasen committed
663
  ADD_SET_PROP ("justification-set", PROP_JUSTIFICATION_SET,
664 665
                P_("Justification set"),
                P_("Whether this tag affects paragraph justification"));
Havoc Pennington's avatar
Havoc Pennington committed
666
  
Matthias Clasen's avatar
x  
Matthias Clasen committed
667
  ADD_SET_PROP ("language-set", PROP_LANGUAGE_SET,
668 669
                P_("Language set"),
                P_("Whether this tag affects the language the text is rendered as"));
670

Matthias Clasen's avatar
x  
Matthias Clasen committed
671
  ADD_SET_PROP ("left-margin-set", PROP_LEFT_MARGIN_SET,
672 673
                P_("Left margin set"),
                P_("Whether this tag affects the left margin"));
674

Matthias Clasen's avatar
x  
Matthias Clasen committed
675
  ADD_SET_PROP ("indent-set", PROP_INDENT_SET,
676 677
                P_("Indent set"),
                P_("Whether this tag affects indentation"));
678

Matthias Clasen's avatar
x  
Matthias Clasen committed
679
  ADD_SET_PROP ("rise-set", PROP_RISE_SET,
680 681
                P_("Rise set"),
                P_("Whether this tag affects the rise"));
682

Matthias Clasen's avatar
x  
Matthias Clasen committed
683
  ADD_SET_PROP ("pixels-above-lines-set", PROP_PIXELS_ABOVE_LINES_SET,
684 685
                P_("Pixels above lines set"),
                P_("Whether this tag affects the number of pixels above lines"));
686

Matthias Clasen's avatar
x  
Matthias Clasen committed
687
  ADD_SET_PROP ("pixels-below-lines-set", PROP_PIXELS_BELOW_LINES_SET,
688 689
                P_("Pixels below lines set"),
                P_("Whether this tag affects the number of pixels above lines"));
690

Matthias Clasen's avatar
x  
Matthias Clasen committed
691
  ADD_SET_PROP ("pixels-inside-wrap-set", PROP_PIXELS_INSIDE_WRAP_SET,
692 693
                P_("Pixels inside wrap set"),
                P_("Whether this tag affects the number of pixels between wrapped lines"));
694

Matthias Clasen's avatar
x  
Matthias Clasen committed
695
  ADD_SET_PROP ("strikethrough-set", PROP_STRIKETHROUGH_SET,
696 697
                P_("Strikethrough set"),
                P_("Whether this tag affects strikethrough"));
698
  
Matthias Clasen's avatar
x  
Matthias Clasen committed
699
  ADD_SET_PROP ("right-margin-set", PROP_RIGHT_MARGIN_SET,
700 701
                P_("Right margin set"),
                P_("Whether this tag affects the right margin"));
702

Matthias Clasen's avatar
x  
Matthias Clasen committed
703
  ADD_SET_PROP ("underline-set", PROP_UNDERLINE_SET,
704 705
                P_("Underline set"),
                P_("Whether this tag affects underlining"));
706

Matthias Clasen's avatar
x  
Matthias Clasen committed
707
  ADD_SET_PROP ("wrap-mode-set", PROP_WRAP_MODE_SET,
708 709
                P_("Wrap mode set"),
                P_("Whether this tag affects line wrap mode"));
710

Matthias Clasen's avatar
x  
Matthias Clasen committed
711
  ADD_SET_PROP ("tabs-set", PROP_TABS_SET,
712 713
                P_("Tabs set"),
                P_("Whether this tag affects tabs"));
714

Matthias Clasen's avatar
x  
Matthias Clasen committed
715
  ADD_SET_PROP ("invisible-set", PROP_INVISIBLE_SET,
716 717
                P_("Invisible set"),
                P_("Whether this tag affects text visibility"));
718

719 720 721
  ADD_SET_PROP ("paragraph-background-set", PROP_PARAGRAPH_BACKGROUND_SET,
                P_("Paragraph background set"),
                P_("Whether this tag affects the paragraph background color"));
722 723 724 725 726 727 728 729 730 731 732 733 734 735

  /**
   * GtkTextTag::event:
   * @tag: the #GtkTextTag on which the signal is emitted
   * @object: the object the event was fired from (typically a #GtkTextView)
   * @event: the event which triggered the signal
   * @iter: a #GtkTextIter pointing at the location the event occured
   *
   * The ::event signal is emitted when an event occurs on a region of the
   * buffer marked with this tag.
   *
   * Returns: %TRUE to stop other handlers from being invoked for the
   * event. %FALSE to propagate the event further.
   */
736
  signals[EVENT] =
737
    g_signal_new (I_("event"),
738 739
                  G_OBJECT_CLASS_TYPE (object_class),
                  G_SIGNAL_RUN_LAST,
Manish Singh's avatar
Manish Singh committed
740
                  G_STRUCT_OFFSET (GtkTextTagClass, event),
741
                  _gtk_boolean_handled_accumulator, NULL,
742
                  _gtk_marshal_BOOLEAN__OBJECT_BOXED_BOXED,
743 744 745
                  G_TYPE_BOOLEAN,
                  3,
                  G_TYPE_OBJECT,
746
                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE,
747
                  GTK_TYPE_TEXT_ITER);
748 749

  g_type_class_add_private (klass, sizeof (GtkTextTagPrivate));
750 751
}

752
static void
753
gtk_text_tag_init (GtkTextTag *text_tag)
754
{
755 756 757 758 759 760 761 762
  GtkTextTagPrivate *priv;

  text_tag->priv = G_TYPE_INSTANCE_GET_PRIVATE (text_tag,
                                                GTK_TYPE_TEXT_TAG,
                                                GtkTextTagPrivate);
  priv = text_tag->priv;

  priv->values = gtk_text_attributes_new ();
763 764
}

765 766
/**
 * gtk_text_tag_new:
767
 * @name: (allow-none): tag name, or %NULL
768 769 770 771 772 773
 * 
 * Creates a #GtkTextTag. Configure the tag using object arguments,
 * i.e. using g_object_set().
 * 
 * Return value: a new #GtkTextTag
 **/
774 775 776 777 778
GtkTextTag*
gtk_text_tag_new (const gchar *name)
{
  GtkTextTag *tag;

Manish Singh's avatar
Manish Singh committed
779
  tag = g_object_new (GTK_TYPE_TEXT_TAG, "name", name, NULL);
780 781 782 783 784

  return tag;
}

static void
785
gtk_text_tag_finalize (GObject *object)
786
{
787 788
  GtkTextTag *text_tag = GTK_TEXT_TAG (object);
  GtkTextTagPrivate *priv = text_tag->priv;
789

790 791
  if (priv->table)
    gtk_text_tag_table_remove (priv->table, text_tag);
792

793
  g_assert (priv->table == NULL);
794

795 796
  gtk_text_attributes_unref (priv->values);
  priv->values = NULL;
797

798 799
  g_free (priv->name);
  priv->name = NULL;
800

801
  G_OBJECT_CLASS (gtk_text_tag_parent_class)->finalize (object);
802 803
}

804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822
static void
copy_rgba_to_gdk_color (GdkRGBA  *src,
			GdkColor *dest)
{
  dest->red   = CLAMP (src->red,   0.0, 1.0) * 65535.0;
  dest->green = CLAMP (src->green, 0.0, 1.0) * 65535.0;
  dest->blue  = CLAMP (src->blue,  0.0, 1.0) * 65535.0;
}

static void
copy_gdk_color_to_rgba (GdkColor *src,
			GdkRGBA  *dest)
{
  dest->red   = src->red / 65535.;
  dest->green = src->green / 65535.;
  dest->blue  = src->blue / 65535.;
  dest->alpha = 1;
}

823
static void
824
set_bg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
825
{
826 827
  GtkTextTagPrivate *priv = tag->priv;

828 829 830 831 832 833
  if (priv->values->appearance.rgba[0])
    gdk_rgba_free (priv->values->appearance.rgba[0]);

  priv->values->appearance.rgba[0] = NULL;

  if (rgba)
834
    {
835
      if (!priv->bg_color_set)
Havoc Pennington's avatar
Havoc Pennington committed
836
        {
837
          priv->bg_color_set = TRUE;
838
          g_object_notify (G_OBJECT (tag), "background-set");
Havoc Pennington's avatar
Havoc Pennington committed
839
        }
840

841
      priv->values->appearance.rgba[0] = gdk_rgba_copy (rgba);
842 843

      copy_rgba_to_gdk_color (rgba, &priv->values->appearance.bg_color);
844 845 846
    }
  else
    {
847
      if (priv->bg_color_set)
Havoc Pennington's avatar
Havoc Pennington committed
848
        {
849
          priv->bg_color_set = FALSE;
850
          g_object_notify (G_OBJECT (tag), "background-set");
Havoc Pennington's avatar
Havoc Pennington committed
851
        }
852 853 854 855
    }
}

static void
856
set_fg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
857
{
858 859
  GtkTextTagPrivate *priv = tag->priv;

860 861 862 863 864 865
  if (priv->values->appearance.rgba[1])
    gdk_rgba_free (priv->values->appearance.rgba[1]);

  priv->values->appearance.rgba[1] = NULL;

  if (rgba)
866
    {
867
      if (!priv->fg_color_set)
Havoc Pennington's avatar
Havoc Pennington committed
868
        {
869
          priv->fg_color_set = TRUE;
870
          g_object_notify (G_OBJECT (tag), "foreground-set");
Havoc Pennington's avatar
Havoc Pennington committed
871
        }
872 873

      priv->values->appearance.rgba[1] = gdk_rgba_copy (rgba);
874 875

      copy_rgba_to_gdk_color (rgba, &priv->values->appearance.fg_color);
876 877 878
    }
  else
    {
879
      if (priv->fg_color_set)
Havoc Pennington's avatar
Havoc Pennington committed
880
        {
881
          priv->fg_color_set = FALSE;
882
          g_object_notify (G_OBJECT (tag), "foreground-set");
Havoc Pennington's avatar
Havoc Pennington committed
883
        }
884 885 886
    }
}

887
static void
888
set_pg_bg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
889
{
890 891
  GtkTextTagPrivate *priv = tag->priv;

892 893 894
  if (priv->values->pg_bg_rgba)
    gdk_rgba_free (priv->values->pg_bg_rgba);

895 896 897
  if (priv->values->pg_bg_color)
    gdk_color_free (priv->values->pg_bg_color);

898
  priv->values->pg_bg_rgba = NULL;
899
  priv->values->pg_bg_color = NULL;
900 901

  if (rgba)
902
    {
903 904
      GdkColor color = { 0, };

905
      if (!priv->pg_bg_color_set)
906
        {
907
          priv->pg_bg_color_set = TRUE;
908 909 910
          g_object_notify (G_OBJECT (tag), "paragraph-background-set");
        }

911
      priv->values->pg_bg_rgba = gdk_rgba_copy (rgba);
912 913 914

      copy_rgba_to_gdk_color (rgba, &color);
      priv->values->pg_bg_color = gdk_color_copy (&color);
915 916 917
    }
  else
    {
918
      if (priv->pg_bg_color_set)
919
        {
920
          priv->pg_bg_color_set = FALSE;
921 922
          g_object_notify (G_OBJECT (tag), "paragraph-background-set");
        }
923 924
    }
}
925

926 927 928 929 930 931 932 933

static void
set_bg_color (GtkTextTag *tag, GdkColor *color)
{
  if (color)
    {
      GdkRGBA rgba;

934
      copy_gdk_color_to_rgba (color, &rgba);
935
      set_bg_rgba (tag, &rgba);
936
    }
937 938 939 940 941 942 943 944 945 946 947
  else
    set_bg_rgba (tag, NULL);
}

static void
set_fg_color (GtkTextTag *tag, GdkColor *color)
{
  if (color)
    {
      GdkRGBA rgba;

948
      copy_gdk_color_to_rgba (color, &rgba);
949 950 951 952 953 954 955 956 957 958 959 960 961
      set_fg_rgba (tag, &rgba);
    }
  else
    set_fg_rgba (tag, NULL);
}

static void
set_pg_bg_color (GtkTextTag *tag, GdkColor *color)
{
  if (color)
    {
      GdkRGBA rgba;

962
      copy_gdk_color_to_rgba (color, &rgba);
963 964 965 966
      set_pg_bg_rgba (tag, &rgba);
    }
  else
    set_pg_bg_rgba (tag, NULL);
967 968
}

969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990
static PangoFontMask
get_property_font_set_mask (guint prop_id)
{
  switch (prop_id)
    {
    case PROP_FAMILY_SET:
      return PANGO_FONT_MASK_FAMILY;
    case PROP_STYLE_SET:
      return PANGO_FONT_MASK_STYLE;
    case PROP_VARIANT_SET:
      return PANGO_FONT_MASK_VARIANT;
    case PROP_WEIGHT_SET:
      return PANGO_FONT_MASK_WEIGHT;
    case PROP_STRETCH_SET:
      return PANGO_FONT_MASK_STRETCH;
    case PROP_SIZE_SET:
      return PANGO_FONT_MASK_SIZE;
    }

  return 0;
}

991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
static PangoFontMask
set_font_desc_fields (PangoFontDescription *desc,
		      PangoFontMask         to_set)
{
  PangoFontMask changed_mask = 0;
  
  if (to_set & PANGO_FONT_MASK_FAMILY)
    {
      const char *family = pango_font_description_get_family (desc);
      if (!family)
	{
	  family = "sans";
	  changed_mask |= PANGO_FONT_MASK_FAMILY;
	}

      pango_font_description_set_family (desc, family);
    }
  if (to_set & PANGO_FONT_MASK_STYLE)
    pango_font_description_set_style (desc, pango_font_description_get_style (desc));
  if (to_set & PANGO_FONT_MASK_VARIANT)
    pango_font_description_set_variant (desc, pango_font_description_get_variant (desc));
  if (to_set & PANGO_FONT_MASK_WEIGHT)
    pango_font_description_set_weight (desc, pango_font_description_get_weight (desc));
  if (to_set & PANGO_FONT_MASK_STRETCH)
    pango_font_description_set_stretch (desc, pango_font_description_get_stretch (desc));
  if (to_set & PANGO_FONT_MASK_SIZE)
    {
      gint size = pango_font_description_get_size (desc);
      if (size <= 0)
	{
	  size = 10 * PANGO_SCALE;
	  changed_mask |= PANGO_FONT_MASK_SIZE;
	}
      
      pango_font_description_set_size (desc, size);
    }

  return changed_mask;
}

1031 1032 1033 1034 1035
static void
notify_set_changed (GObject       *object,
		    PangoFontMask  changed_mask)
{
  if (changed_mask & PANGO_FONT_MASK_FAMILY)
1036
    g_object_notify (object, "family-set");
1037
  if (changed_mask & PANGO_FONT_MASK_STYLE)
1038
    g_object_notify (object, "style-set");
1039
  if (changed_mask & PANGO_FONT_MASK_VARIANT)
1040
    g_object_notify (object, "variant-set");
1041
  if (changed_mask & PANGO_FONT_MASK_WEIGHT)
1042
    g_object_notify (object, "weight-set");
1043
  if (changed_mask & PANGO_FONT_MASK_STRETCH)
1044
    g_object_notify (object, "stretch-set");
1045
  if (changed_mask & PANGO_FONT_MASK_SIZE)
1046
    g_object_notify (object, "size-set");
1047 1048
}

1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066
static void
notify_fields_changed (GObject       *object,
		       PangoFontMask  changed_mask)
{
  if (changed_mask & PANGO_FONT_MASK_FAMILY)
    g_object_notify (object, "family");
  if (changed_mask & PANGO_FONT_MASK_STYLE)
    g_object_notify (object, "style");
  if (changed_mask & PANGO_FONT_MASK_VARIANT)
    g_object_notify (object, "variant");
  if (changed_mask & PANGO_FONT_MASK_WEIGHT)
    g_object_notify (object, "weight");
  if (changed_mask & PANGO_FONT_MASK_STRETCH)
    g_object_notify (object, "stretch");
  if (changed_mask & PANGO_FONT_MASK_SIZE)
    g_object_notify (object, "size");
}

1067 1068 1069 1070
static void
set_font_description (GtkTextTag           *text_tag,
                      PangoFontDescription *font_desc)
{
1071
  GtkTextTagPrivate *priv = text_tag->priv;
1072 1073 1074 1075 1076 1077 1078 1079 1080
  GObject *object = G_OBJECT (text_tag);
  PangoFontDescription *new_font_desc;
  PangoFontMask old_mask, new_mask, changed_mask, set_changed_mask;
  
  if (font_desc)
    new_font_desc = pango_font_description_copy (font_desc);
  else
    new_font_desc = pango_font_description_new ();

1081 1082
  if (priv->values->font)
    old_mask = pango_font_description_get_set_fields (priv->values->font);
1083
  else
1084 1085 1086 1087 1088 1089 1090
    old_mask = 0;
  
  new_mask = pango_font_description_get_set_fields (new_font_desc);

  changed_mask = old_mask | new_mask;
  set_changed_mask = old_mask ^ new_mask;

1091 1092 1093 1094
  if (priv->values->font)
    pango_font_description_free (priv->values->font);
  priv->values->font = new_font_desc;

1095 1096
  g_object_freeze_notify (object);

1097
  g_object_notify (object, "font-desc");
1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110
  g_object_notify (object, "font");
  
  if (changed_mask & PANGO_FONT_MASK_FAMILY)
    g_object_notify (object, "family");
  if (changed_mask & PANGO_FONT_MASK_STYLE)
    g_object_notify (object, "style");
  if (changed_mask & PANGO_FONT_MASK_VARIANT)
    g_object_notify (object, "variant");
  if (changed_mask & PANGO_FONT_MASK_WEIGHT)
    g_object_notify (object, "weight");
  if (changed_mask & PANGO_FONT_MASK_STRETCH)
    g_object_notify (object, "stretch");
  if (changed_mask & PANGO_FONT_MASK_SIZE)
Havoc Pennington's avatar
Havoc Pennington committed
1111
    {
1112
      g_object_notify (object, "size");
1113
      g_object_notify (object, "size-points");
1114
    }
1115 1116 1117 1118 1119 1120 1121 1122 1123

  notify_set_changed (object, set_changed_mask);
  
  g_object_thaw_notify (object);
}

static void
gtk_text_tag_ensure_font (GtkTextTag *text_tag)
{
1124 1125 1126 1127
  GtkTextTagPrivate *priv = text_tag->priv;

  if (!priv->values->font)
    priv->values->font = pango_font_description_new ();
1128 1129
}

1130
static void
1131 1132 1133
gtk_text_tag_set_property (GObject      *object,
                           guint         prop_id,
                           const GValue *value,
Tim Janik's avatar
Tim Janik committed
1134
                           GParamSpec   *pspec)
1135
{
1136 1137
  GtkTextTag *text_tag = GTK_TEXT_TAG (object);
  GtkTextTagPrivate *priv = text_tag->priv;
1138
  gboolean size_changed = FALSE;
1139

1140
  switch (prop_id)
1141
    {
1142
    case PROP_NAME:
1143 1144
      g_return_if_fail (priv->name == NULL);
      priv->name = g_value_dup_string (value);
1145 1146
      break;

1147
    case PROP_BACKGROUND:
1148
      {
1149
        GdkRGBA rgba;
1150

1151
        if (!g_value_get_string (value))
1152 1153 1154
          set_bg_rgba (text_tag, NULL);       /* reset background_set to FALSE */
        else if (gdk_rgba_parse (&rgba, g_value_get_string (value)))
          set_bg_rgba (text_tag, &rgba);
1155
        else
1156
          g_warning ("Don't know color `%s'", g_value_get_string (value));
1157

1158
        g_object_notify (object, "background-gdk");
1159 1160 1161
      }
      break;

1162
    case PROP_FOREGROUND:
1163
      {
1164
        GdkRGBA rgba;
1165

1166
        if (!g_value_get_string (value))
1167 1168 1169
          set_fg_rgba (text_tag, NULL);       /* reset to foreground_set to FALSE */
        else if (gdk_rgba_parse (&rgba, g_value_get_string (value)))
          set_fg_rgba (text_tag, &rgba);
1170
        else
1171
          g_warning ("Don't know color `%s'", g_value_get_string (value));
1172

1173
        g_object_notify (object, "foreground-gdk");
1174 1175
      }
      break;
1176

1177
    case PROP_BACKGROUND_GDK:
1178
      {
Tim Janik's avatar
Tim Janik committed
1179 1180
        GdkColor *color = g_value_get_boxed (value);

1181
        set_bg_color (text_tag, color);
1182 1183 1184
      }
      break;

1185
    case PROP_FOREGROUND_GDK:
1186
      {
Tim Janik's avatar
Tim Janik committed
1187 1188
        GdkColor *color = g_value_get_boxed (value);

1189
        set_fg_color (text_tag, color);
1190 1191 1192
      }
      break;

1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208
    case PROP_BACKGROUND_RGBA:
      {
        GdkRGBA *color = g_value_get_boxed (value);

        set_bg_rgba (text_tag, color);
      }
      break;

    case PROP_FOREGROUND_RGBA:
      {
        GdkRGBA *color = g_value_get_boxed (value);

        set_fg_rgba (text_tag, color);
      }
      break;

1209
    case PROP_FONT:
1210 1211 1212 1213
      {
        PangoFontDescription *font_desc = NULL;
        const gchar *name;

1214
        name = g_value_get_string (value);
1215 1216

        if (name)
1217 1218
          font_desc = pango_font_description_from_string (name);

1219
        set_font_description (text_tag, font_desc);
1220 1221
	if (font_desc)
	  pango_font_description_free (font_desc);
1222
        
1223 1224 1225 1226
        size_changed = TRUE;
      }
      break;

1227
    case PROP_FONT_DESC:
1228 1229 1230
      {
        PangoFontDescription *font_desc;

Tim Janik's avatar
Tim Janik committed
1231
        font_desc = g_value_get_boxed (value);
1232

1233
        set_font_description (text_tag, font_desc);
1234 1235 1236 1237 1238

        size_changed = TRUE;
      }
      break;

1239 1240 1241 1242 1243 1244
    case PROP_FAMILY:
    case PROP_STYLE:
    case PROP_VARIANT:
    case PROP_WEIGHT:
    case PROP_STRETCH:
    case PROP_SIZE:
1245 1246 1247 1248 1249
    case PROP_SIZE_POINTS:
      {
	PangoFontMask old_set_mask;

	gtk_text_tag_ensure_font (text_tag);
1250
	old_set_mask = pango_font_description_get_set_fields (priv->values->font);
1251 1252 1253 1254
 
	switch (prop_id)
	  {
	  case PROP_FAMILY:
1255
	    pango_font_description_set_family (priv->values->font,
1256 1257 1258
					       g_value_get_string (value));
	    break;
	  case PROP_STYLE:
1259
	    pango_font_description_set_style (priv->values->font,
1260 1261 1262
					      g_value_get_enum (value));
	    break;
	  case PROP_VARIANT:
1263
	    pango_font_description_set_variant (priv->values->font,