gtktexttag.c 78.2 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
 * @Title: GtkTextTag
 * @Short_description: A tag that can be applied to text in a GtkTextBuffer
 *
55 56 57
 * You may wish to begin by reading the
 * [text widget conceptual overview][TextWidget]
 * which gives an overview of all the objects and
58 59 60 61 62 63
 * 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.
64
 * See “gtk3-demo” for numerous examples.
65
 *
66 67
 * For each property of #GtkTextTag, there is a “set” property, e.g.
 * “font-set” corresponds to “font”. These “set” properties reflect
68
 * whether a property has been set or not.
69
 * They are maintained by GTK+ and you should not set them independently.
70 71
 */

72
#include "config.h"
73 74 75 76

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

77
#include "gtktextattributesprivate.h"
78 79 80
#include "gtktexttag.h"
#include "gtktexttypes.h"
#include "gtktexttagtable.h"
81
#include "gtkintl.h"
82
#include "gtkmarshalers.h"
83
#include "gtkprivate.h"
84
#include "gtktypebuiltins.h"
85 86 87 88 89 90 91

enum {
  EVENT,
  LAST_SIGNAL
};

enum {
92
  PROP_0,
93
  /* Construct args */
94
  PROP_NAME,
95 96

  /* Style args */
97 98 99 100
  PROP_BACKGROUND,
  PROP_FOREGROUND,
  PROP_BACKGROUND_GDK,
  PROP_FOREGROUND_GDK,
101 102
  PROP_BACKGROUND_RGBA,
  PROP_FOREGROUND_RGBA,
103 104 105 106 107 108 109 110 111
  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
112
  PROP_SCALE,
113 114 115 116 117
  PROP_PIXELS_ABOVE_LINES,
  PROP_PIXELS_BELOW_LINES,
  PROP_PIXELS_INSIDE_WRAP,
  PROP_EDITABLE,
  PROP_WRAP_MODE,
118
  PROP_JUSTIFICATION,
119 120 121 122
  PROP_DIRECTION,
  PROP_LEFT_MARGIN,
  PROP_INDENT,
  PROP_STRIKETHROUGH,
123
  PROP_STRIKETHROUGH_RGBA,
124 125
  PROP_RIGHT_MARGIN,
  PROP_UNDERLINE,
126
  PROP_UNDERLINE_RGBA,
127
  PROP_RISE,
Soeren Sandmann's avatar
Soeren Sandmann committed
128
  PROP_BACKGROUND_FULL_HEIGHT,
129 130 131
  PROP_LANGUAGE,
  PROP_TABS,
  PROP_INVISIBLE,
132 133
  PROP_PARAGRAPH_BACKGROUND,
  PROP_PARAGRAPH_BACKGROUND_GDK,
134
  PROP_PARAGRAPH_BACKGROUND_RGBA,
135 136
  PROP_FALLBACK,
  PROP_LETTER_SPACING,
137
  PROP_FONT_FEATURES,
138 139 140

  /* Behavior args */
  PROP_ACCUMULATIVE_MARGIN,
141

142
  /* Whether-a-style-arg-is-set args */
143 144 145 146 147 148 149 150
  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
151
  PROP_SCALE_SET,
152 153 154 155 156
  PROP_PIXELS_ABOVE_LINES_SET,
  PROP_PIXELS_BELOW_LINES_SET,
  PROP_PIXELS_INSIDE_WRAP_SET,
  PROP_EDITABLE_SET,
  PROP_WRAP_MODE_SET,
157
  PROP_JUSTIFICATION_SET,
158 159 160
  PROP_LEFT_MARGIN_SET,
  PROP_INDENT_SET,
  PROP_STRIKETHROUGH_SET,
161
  PROP_STRIKETHROUGH_RGBA_SET,
162 163
  PROP_RIGHT_MARGIN_SET,
  PROP_UNDERLINE_SET,
164
  PROP_UNDERLINE_RGBA_SET,
165
  PROP_RISE_SET,
Soeren Sandmann's avatar
Soeren Sandmann committed
166
  PROP_BACKGROUND_FULL_HEIGHT_SET,
167 168 169
  PROP_LANGUAGE_SET,
  PROP_TABS_SET,
  PROP_INVISIBLE_SET,
170
  PROP_PARAGRAPH_BACKGROUND_SET,
171 172
  PROP_FALLBACK_SET,
  PROP_LETTER_SPACING_SET,
173
  PROP_FONT_FEATURES_SET,
174

175 176
  LAST_ARG
};
177 178 179 180
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
181
                                       GParamSpec      *pspec);
182 183 184
static void gtk_text_tag_get_property (GObject         *object,
                                       guint            prop_id,
                                       GValue          *value,
Tim Janik's avatar
Tim Janik committed
185
                                       GParamSpec      *pspec);
186

187 188
static guint signals[LAST_SIGNAL] = { 0 };

189
G_DEFINE_TYPE_WITH_PRIVATE (GtkTextTag, gtk_text_tag, G_TYPE_OBJECT)
190 191 192 193

static void
gtk_text_tag_class_init (GtkTextTagClass *klass)
{
194
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
195

196 197 198 199
  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;
200

201
  /* Construct */
202 203 204
  g_object_class_install_property (object_class,
                                   PROP_NAME,
                                   g_param_spec_string ("name",
205 206
                                                        P_("Tag name"),
                                                        P_("Name used to refer to the text tag. NULL for anonymous tags"),
207
                                                        NULL,
208
                                                        GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
209 210

  /* Style args */
211 212 213 214

  g_object_class_install_property (object_class,
                                   PROP_BACKGROUND,
                                   g_param_spec_string ("background",
215 216
                                                        P_("Background color name"),
                                                        P_("Background color as a string"),
217
                                                        NULL,
218
                                                        GTK_PARAM_WRITABLE));
219

220 221 222 223 224 225 226
  /**
   * GtkTextTag:background-gdk:
   *
   * Background color as a #GdkColor.
   *
   * Deprecated: 3.4: Use #GtkTextTag:background-rgba instead.
   */
227 228
  g_object_class_install_property (object_class,
                                   PROP_BACKGROUND_GDK,
Matthias Clasen's avatar
x  
Matthias Clasen committed
229
                                   g_param_spec_boxed ("background-gdk",
230
                                                       P_("Background color"),
231
                                                       P_("Background color as a GdkColor"),
Matthias Clasen's avatar
Matthias Clasen committed
232
                                                       g_type_from_name ("GdkColor"),
233
                                                       GTK_PARAM_READWRITE | G_PARAM_DEPRECATED));
234

235 236 237
  /**
   * GtkTextTag:background-rgba:
   *
238
   * Background color as a #GdkRGBA.
239 240 241
   *
   * Since: 3.2
   */
242 243 244
  g_object_class_install_property (object_class,
                                   PROP_BACKGROUND_RGBA,
                                   g_param_spec_boxed ("background-rgba",
Rachid BM's avatar
Rachid BM committed
245
                                                       P_("Background RGBA"),
246
                                                       P_("Background color as a GdkRGBA"),
247 248 249
                                                       GDK_TYPE_RGBA,
                                                       GTK_PARAM_READWRITE));

250
  g_object_class_install_property (object_class,
Soeren Sandmann's avatar
Soeren Sandmann committed
251
                                   PROP_BACKGROUND_FULL_HEIGHT,
Matthias Clasen's avatar
x  
Matthias Clasen committed
252
                                   g_param_spec_boolean ("background-full-height",
253 254
                                                         P_("Background full height"),
                                                         P_("Whether the background color fills the entire line height or only the height of the tagged characters"),
255
                                                         FALSE,
256
                                                         GTK_PARAM_READWRITE));
257
  
258 259 260
  g_object_class_install_property (object_class,
                                   PROP_FOREGROUND,
                                   g_param_spec_string ("foreground",
261 262
                                                        P_("Foreground color name"),
                                                        P_("Foreground color as a string"),
263
                                                        NULL,
264
                                                        GTK_PARAM_WRITABLE));
265

266 267 268 269 270 271 272
  /**
   * GtkTextTag:foreground-gdk:
   *
   * Foreground color as a #GdkColor.
   *
   * Deprecated: 3.4: Use #GtkTextTag:foreground-rgba instead.
   */
273 274
  g_object_class_install_property (object_class,
                                   PROP_FOREGROUND_GDK,
Matthias Clasen's avatar
x  
Matthias Clasen committed
275
                                   g_param_spec_boxed ("foreground-gdk",
276
                                                       P_("Foreground color"),
277
                                                       P_("Foreground color as a GdkColor"),
Matthias Clasen's avatar
Matthias Clasen committed
278
                                                       g_type_from_name ("GdkColor"),
279
                                                       GTK_PARAM_READWRITE | G_PARAM_DEPRECATED));
280

281 282 283
  /**
   * GtkTextTag:foreground-rgba:
   *
284
   * Foreground color as a #GdkRGBA.
285 286 287
   *
   * Since: 3.2
   */
288 289 290
  g_object_class_install_property (object_class,
                                   PROP_FOREGROUND_RGBA,
                                   g_param_spec_boxed ("foreground-rgba",
Rachid BM's avatar
Rachid BM committed
291
                                                       P_("Foreground RGBA"),
292
                                                       P_("Foreground color as a GdkRGBA"),
293 294 295
                                                       GDK_TYPE_RGBA,
                                                       GTK_PARAM_READWRITE));

296 297 298
  g_object_class_install_property (object_class,
                                   PROP_DIRECTION,
                                   g_param_spec_enum ("direction",
299 300
                                                      P_("Text direction"),
                                                      P_("Text direction, e.g. right-to-left or left-to-right"),
301
                                                      GTK_TYPE_TEXT_DIRECTION,
302
                                                      GTK_TEXT_DIR_NONE,
303
                                                      GTK_PARAM_READWRITE));
304 305 306 307

  g_object_class_install_property (object_class,
                                   PROP_EDITABLE,
                                   g_param_spec_boolean ("editable",
308 309
                                                         P_("Editable"),
                                                         P_("Whether the text can be modified by the user"),
310
                                                         TRUE,
311
                                                         GTK_PARAM_READWRITE));
312

313 314 315 316 317 318 319 320
  /**
   * 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.
   */
321 322 323
  g_object_class_install_property (object_class,
                                   PROP_FONT,
                                   g_param_spec_string ("font",
324 325
                                                        P_("Font"),
                                                        P_("Font description as a string, e.g. \"Sans Italic 12\""),
326
                                                        NULL,
327
                                                        GTK_PARAM_READWRITE));
328 329 330

  g_object_class_install_property (object_class,
                                   PROP_FONT_DESC,
Matthias Clasen's avatar
x  
Matthias Clasen committed
331
                                   g_param_spec_boxed ("font-desc",
332 333
                                                       P_("Font"),
                                                       P_("Font description as a PangoFontDescription struct"),
334
                                                       PANGO_TYPE_FONT_DESCRIPTION,
335
                                                       GTK_PARAM_READWRITE));
336 337 338 339
  
  g_object_class_install_property (object_class,
                                   PROP_FAMILY,
                                   g_param_spec_string ("family",
340 341
                                                        P_("Font family"),
                                                        P_("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
342
                                                        NULL,
343
                                                        GTK_PARAM_READWRITE));
344 345 346 347

  g_object_class_install_property (object_class,
                                   PROP_STYLE,
                                   g_param_spec_enum ("style",
348 349
                                                      P_("Font style"),
                                                      P_("Font style as a PangoStyle, e.g. PANGO_STYLE_ITALIC"),
350 351
                                                      PANGO_TYPE_STYLE,
                                                      PANGO_STYLE_NORMAL,
352
                                                      GTK_PARAM_READWRITE));
353 354 355 356

  g_object_class_install_property (object_class,
                                   PROP_VARIANT,
                                   g_param_spec_enum ("variant",
357 358
                                                     P_("Font variant"),
                                                     P_("Font variant as a PangoVariant, e.g. PANGO_VARIANT_SMALL_CAPS"),
359 360
                                                      PANGO_TYPE_VARIANT,
                                                      PANGO_VARIANT_NORMAL,
361
                                                      GTK_PARAM_READWRITE));
362 363 364 365
  
  g_object_class_install_property (object_class,
                                   PROP_WEIGHT,
                                   g_param_spec_int ("weight",
366 367
                                                     P_("Font weight"),
                                                     P_("Font weight as an integer, see predefined values in PangoWeight; for example, PANGO_WEIGHT_BOLD"),
368 369 370
                                                     0,
                                                     G_MAXINT,
                                                     PANGO_WEIGHT_NORMAL,
371
                                                     GTK_PARAM_READWRITE));
372 373 374 375 376
  

  g_object_class_install_property (object_class,
                                   PROP_STRETCH,
                                   g_param_spec_enum ("stretch",
377 378
                                                      P_("Font stretch"),
                                                      P_("Font stretch as a PangoStretch, e.g. PANGO_STRETCH_CONDENSED"),
379 380
                                                      PANGO_TYPE_STRETCH,
                                                      PANGO_STRETCH_NORMAL,
381
                                                      GTK_PARAM_READWRITE));
382 383 384 385
  
  g_object_class_install_property (object_class,
                                   PROP_SIZE,
                                   g_param_spec_int ("size",
386 387
                                                     P_("Font size"),
                                                     P_("Font size in Pango units"),
388 389 390
                                                     0,
                                                     G_MAXINT,
                                                     0,
391
                                                     GTK_PARAM_READWRITE));
392

Havoc Pennington's avatar
Havoc Pennington committed
393 394 395
  g_object_class_install_property (object_class,
                                   PROP_SCALE,
                                   g_param_spec_double ("scale",
396 397
                                                        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
398 399 400
                                                        0.0,
                                                        G_MAXDOUBLE,
                                                        1.0,
401
                                                        GTK_PARAM_READWRITE));
Havoc Pennington's avatar
Havoc Pennington committed
402
  
403 404
  g_object_class_install_property (object_class,
                                   PROP_SIZE_POINTS,
Matthias Clasen's avatar
x  
Matthias Clasen committed
405
                                   g_param_spec_double ("size-points",
406 407
                                                        P_("Font points"),
                                                        P_("Font size in points"),
408 409 410
                                                        0.0,
                                                        G_MAXDOUBLE,
                                                        0.0,
411
                                                        GTK_PARAM_READWRITE));  
412 413

  g_object_class_install_property (object_class,
414 415
                                   PROP_JUSTIFICATION,
                                   g_param_spec_enum ("justification",
416 417
                                                      P_("Justification"),
                                                      P_("Left, right, or center justification"),
418 419
                                                      GTK_TYPE_JUSTIFICATION,
                                                      GTK_JUSTIFY_LEFT,
420
                                                      GTK_PARAM_READWRITE));
421 422 423 424 425 426 427 428 429 430 431

  /**
   * 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().
   */
432 433 434
  g_object_class_install_property (object_class,
                                   PROP_LANGUAGE,
                                   g_param_spec_string ("language",
435
                                                        P_("Language"),
436
                                                        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."),
437
                                                        NULL,
438
                                                        GTK_PARAM_READWRITE));  
439 440 441

  g_object_class_install_property (object_class,
                                   PROP_LEFT_MARGIN,
Matthias Clasen's avatar
x  
Matthias Clasen committed
442
                                   g_param_spec_int ("left-margin",
443 444
                                                     P_("Left margin"),
                                                     P_("Width of the left margin in pixels"),
445 446 447
                                                     0,
                                                     G_MAXINT,
                                                     0,
448
                                                     GTK_PARAM_READWRITE));
449 450 451

  g_object_class_install_property (object_class,
                                   PROP_RIGHT_MARGIN,
Matthias Clasen's avatar
x  
Matthias Clasen committed
452
                                   g_param_spec_int ("right-margin",
453 454
                                                     P_("Right margin"),
                                                     P_("Width of the right margin in pixels"),
455 456 457
                                                     0,
                                                     G_MAXINT,
                                                     0,
458
                                                     GTK_PARAM_READWRITE));
459 460 461 462 463

  
  g_object_class_install_property (object_class,
                                   PROP_INDENT,
                                   g_param_spec_int ("indent",
464 465
                                                     P_("Indent"),
                                                     P_("Amount to indent the paragraph, in pixels"),
466
                                                     G_MININT,
467 468
                                                     G_MAXINT,
                                                     0,
469
                                                     GTK_PARAM_READWRITE));
470 471 472 473 474

  
  g_object_class_install_property (object_class,
                                   PROP_RISE,
                                   g_param_spec_int ("rise",
475
                                                     P_("Rise"),
476
                                                     P_("Offset of text above the baseline (below the baseline if rise is negative) in Pango units"),
477
						     G_MININT,
478 479
                                                     G_MAXINT,
                                                     0,
480
                                                     GTK_PARAM_READWRITE));
481 482 483

  g_object_class_install_property (object_class,
                                   PROP_PIXELS_ABOVE_LINES,
Matthias Clasen's avatar
x  
Matthias Clasen committed
484
                                   g_param_spec_int ("pixels-above-lines",
485 486
                                                     P_("Pixels above lines"),
                                                     P_("Pixels of blank space above paragraphs"),
487 488 489
                                                     0,
                                                     G_MAXINT,
                                                     0,
490
                                                     GTK_PARAM_READWRITE));
491 492 493
  
  g_object_class_install_property (object_class,
                                   PROP_PIXELS_BELOW_LINES,
Matthias Clasen's avatar
x  
Matthias Clasen committed
494
                                   g_param_spec_int ("pixels-below-lines",
495 496
                                                     P_("Pixels below lines"),
                                                     P_("Pixels of blank space below paragraphs"),
497 498 499
                                                     0,
                                                     G_MAXINT,
                                                     0,
500
                                                     GTK_PARAM_READWRITE));
501 502 503

  g_object_class_install_property (object_class,
                                   PROP_PIXELS_INSIDE_WRAP,
Matthias Clasen's avatar
x  
Matthias Clasen committed
504
                                   g_param_spec_int ("pixels-inside-wrap",
505 506
                                                     P_("Pixels inside wrap"),
                                                     P_("Pixels of blank space between wrapped lines in a paragraph"),
507 508 509
                                                     0,
                                                     G_MAXINT,
                                                     0,
510
                                                     GTK_PARAM_READWRITE));
511 512 513 514

  g_object_class_install_property (object_class,
                                   PROP_STRIKETHROUGH,
                                   g_param_spec_boolean ("strikethrough",
515 516
                                                         P_("Strikethrough"),
                                                         P_("Whether to strike through the text"),
517
                                                         FALSE,
518
                                                         GTK_PARAM_READWRITE));
519 520 521 522
  
  g_object_class_install_property (object_class,
                                   PROP_UNDERLINE,
                                   g_param_spec_enum ("underline",
523 524
                                                      P_("Underline"),
                                                      P_("Style of underline for this text"),
525 526
                                                      PANGO_TYPE_UNDERLINE,
                                                      PANGO_UNDERLINE_NONE,
527
                                                      GTK_PARAM_READWRITE));
528 529 530 531 532 533 534 535 536 537 538

  /**
   * GtkTextTag:underline-rgba:
   *
   * This property modifies the color of underlines. If not set, underlines
   * will use the forground color.
   *
   * If #GtkTextTag:underline is set to %PANGO_UNDERLINE_ERROR, an alternate
   * color may be applied instead of the foreground. Setting this property
   * will always override those defaults.
   *
539
   * Since: 3.16
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
   */
  g_object_class_install_property (object_class,
                                   PROP_UNDERLINE_RGBA,
                                   g_param_spec_boxed ("underline-rgba",
                                                       P_("Underline RGBA"),
                                                       P_("Color of underline for this text"),
                                                       GDK_TYPE_RGBA,
                                                       GTK_PARAM_READWRITE));

  /**
   * GtkTextTag:strikethrough-rgba:
   *
   * This property modifies the color of strikeouts. If not set, strikeouts
   * will use the forground color.
   *
555
   * Since: 3.16
556 557 558 559
   */
  g_object_class_install_property (object_class,
                                   PROP_STRIKETHROUGH_RGBA,
                                   g_param_spec_boxed ("strikethrough-rgba",
560 561
                                                       P_("Strikethrough RGBA"),
                                                       P_("Color of strikethrough for this text"),
562 563 564
                                                       GDK_TYPE_RGBA,
                                                       GTK_PARAM_READWRITE));

565 566
  g_object_class_install_property (object_class,
                                   PROP_WRAP_MODE,
Matthias Clasen's avatar
x  
Matthias Clasen committed
567
                                   g_param_spec_enum ("wrap-mode",
568 569
                                                     P_("Wrap mode"),
                                                     P_("Whether to wrap lines never, at word boundaries, or at character boundaries"),
570
                                                      GTK_TYPE_WRAP_MODE,
571
                                                      GTK_WRAP_NONE,
572
                                                      GTK_PARAM_READWRITE));
573 574 575 576 577
  

  g_object_class_install_property (object_class,
                                   PROP_TABS,
                                   g_param_spec_boxed ("tabs",
578 579
                                                       P_("Tabs"),
                                                       P_("Custom tabs for this text"),
580
                                                       PANGO_TYPE_TAB_ARRAY,
581
                                                       GTK_PARAM_READWRITE));
582
  
583 584 585 586 587 588 589 590 591 592 593
  /**
   * 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
   */
594 595 596
  g_object_class_install_property (object_class,
                                   PROP_INVISIBLE,
                                   g_param_spec_boolean ("invisible",
597
                                                         P_("Invisible"),
598
                                                         P_("Whether this text is hidden."),
599
                                                         FALSE,
600
                                                         GTK_PARAM_READWRITE));
601

602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
  /**
   * 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:
   *
Volker Sobek's avatar
Volker Sobek committed
620
   * The paragraph background color as a #GdkColor.
621 622
   *
   * Since: 2.8
623 624
   *
   * Deprecated: 3.4: Use #GtkTextTag:paragraph-background-rgba instead.
625 626 627 628 629
   */
  g_object_class_install_property (object_class,
                                   PROP_PARAGRAPH_BACKGROUND_GDK,
                                   g_param_spec_boxed ("paragraph-background-gdk",
                                                       P_("Paragraph background color"),
630
                                                       P_("Paragraph background color as a GdkColor"),
Matthias Clasen's avatar
Matthias Clasen committed
631
                                                       g_type_from_name ("GdkColor"),
632
                                                       GTK_PARAM_READWRITE | G_PARAM_DEPRECATED));
633

634 635 636
  /**
   * GtkTextTag:paragraph-background-rgba:
   *
Volker Sobek's avatar
Volker Sobek committed
637
   * The paragraph background color as a #GdkRGBA.
638 639 640 641 642 643
   *
   * 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
644 645
                                                       P_("Paragraph background RGBA"),
                                                       P_("Paragraph background RGBA as a GdkRGBA"),
646 647 648
                                                       GDK_TYPE_RGBA,
                                                       GTK_PARAM_READWRITE));

649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680
  /**
   * GtkTextTag:fallback:
   *
   * Whether font fallback is enabled.
   *
   * When set to %TRUE, other fonts will be substituted
   * where the current font is missing glyphs.
   *
   * Since: 3.16
   */
  g_object_class_install_property (object_class,
                                   PROP_FALLBACK,
                                   g_param_spec_boolean ("fallback",
                                                         P_("Fallback"),
                                                         P_("Whether font fallback is enabled."),
                                                         TRUE,
                                                         GTK_PARAM_READWRITE));

  /**
   * GtkTextTag:letter-spacing:
   *
   * Extra spacing between graphemes, in Pango units.
   *
   * Since: 3.16
   */
  g_object_class_install_property (object_class,
                                   PROP_LETTER_SPACING,
                                   g_param_spec_int ("letter-spacing",
                                                     P_("Letter Spacing"),
                                                     P_("Extra spacing between graphemes"),
                                                     0, G_MAXINT, 0,
                                                     GTK_PARAM_READWRITE));
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696

  /**
   * GtkTextTag:font-features:
   *
   * OpenType font features, as a string.
   *
   * Since: 3.18
   */
  g_object_class_install_property (object_class,
                                   PROP_FONT_FEATURES,
                                   g_param_spec_string ("font-features",
                                                        P_("Font Features"),
                                                        P_("OpenType Font Features to use"),
                                                        NULL,
                                                        GTK_PARAM_READWRITE));

697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
  /**
   * 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));

716 717
  /* Style props are set or not */

718
#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))
719

Matthias Clasen's avatar
x  
Matthias Clasen committed
720
  ADD_SET_PROP ("background-set", PROP_BACKGROUND_SET,
721 722
                P_("Background set"),
                P_("Whether this tag affects the background color"));
723
  
Matthias Clasen's avatar
x  
Matthias Clasen committed
724
  ADD_SET_PROP ("background-full-height-set", PROP_BACKGROUND_FULL_HEIGHT_SET,
725 726
                P_("Background full height set"),
                P_("Whether this tag affects background height"));
727

Matthias Clasen's avatar
x  
Matthias Clasen committed
728
  ADD_SET_PROP ("foreground-set", PROP_FOREGROUND_SET,
729 730
                P_("Foreground set"),
                P_("Whether this tag affects the foreground color"));
731

Matthias Clasen's avatar
x  
Matthias Clasen committed
732
  ADD_SET_PROP ("editable-set", PROP_EDITABLE_SET,
733 734
                P_("Editability set"),
                P_("Whether this tag affects text editability"));
735

Matthias Clasen's avatar
x  
Matthias Clasen committed
736
  ADD_SET_PROP ("family-set", PROP_FAMILY_SET,
737 738
                P_("Font family set"),
                P_("Whether this tag affects the font family"));  
739

Matthias Clasen's avatar
x  
Matthias Clasen committed
740
  ADD_SET_PROP ("style-set", PROP_STYLE_SET,
741 742
                P_("Font style set"),
                P_("Whether this tag affects the font style"));
743

Matthias Clasen's avatar
x  
Matthias Clasen committed
744
  ADD_SET_PROP ("variant-set", PROP_VARIANT_SET,
745 746
                P_("Font variant set"),
                P_("Whether this tag affects the font variant"));
747

Matthias Clasen's avatar
x  
Matthias Clasen committed
748
  ADD_SET_PROP ("weight-set", PROP_WEIGHT_SET,
749 750
                P_("Font weight set"),
                P_("Whether this tag affects the font weight"));
751

Matthias Clasen's avatar
x  
Matthias Clasen committed
752
  ADD_SET_PROP ("stretch-set", PROP_STRETCH_SET,
753 754
                P_("Font stretch set"),
                P_("Whether this tag affects the font stretch"));
755

Matthias Clasen's avatar
x  
Matthias Clasen committed
756
  ADD_SET_PROP ("size-set", PROP_SIZE_SET,
757 758
                P_("Font size set"),
                P_("Whether this tag affects the font size"));
759

Matthias Clasen's avatar
x  
Matthias Clasen committed
760
  ADD_SET_PROP ("scale-set", PROP_SCALE_SET,
761 762
                P_("Font scale set"),
                P_("Whether this tag scales the font size by a factor"));
Havoc Pennington's avatar
Havoc Pennington committed
763
  
Matthias Clasen's avatar
x  
Matthias Clasen committed
764
  ADD_SET_PROP ("justification-set", PROP_JUSTIFICATION_SET,
765 766
                P_("Justification set"),
                P_("Whether this tag affects paragraph justification"));
Havoc Pennington's avatar
Havoc Pennington committed
767
  
Matthias Clasen's avatar
x  
Matthias Clasen committed
768
  ADD_SET_PROP ("language-set", PROP_LANGUAGE_SET,
769 770
                P_("Language set"),
                P_("Whether this tag affects the language the text is rendered as"));
771

Matthias Clasen's avatar
x  
Matthias Clasen committed
772
  ADD_SET_PROP ("left-margin-set", PROP_LEFT_MARGIN_SET,
773 774
                P_("Left margin set"),
                P_("Whether this tag affects the left margin"));
775

Matthias Clasen's avatar
x  
Matthias Clasen committed
776
  ADD_SET_PROP ("indent-set", PROP_INDENT_SET,
777 778
                P_("Indent set"),
                P_("Whether this tag affects indentation"));
779

Matthias Clasen's avatar
x  
Matthias Clasen committed
780
  ADD_SET_PROP ("rise-set", PROP_RISE_SET,
781 782
                P_("Rise set"),
                P_("Whether this tag affects the rise"));
783

Matthias Clasen's avatar
x  
Matthias Clasen committed
784
  ADD_SET_PROP ("pixels-above-lines-set", PROP_PIXELS_ABOVE_LINES_SET,
785 786
                P_("Pixels above lines set"),
                P_("Whether this tag affects the number of pixels above lines"));
787

Matthias Clasen's avatar
x  
Matthias Clasen committed
788
  ADD_SET_PROP ("pixels-below-lines-set", PROP_PIXELS_BELOW_LINES_SET,
789 790
                P_("Pixels below lines set"),
                P_("Whether this tag affects the number of pixels above lines"));
791

Matthias Clasen's avatar
x  
Matthias Clasen committed
792
  ADD_SET_PROP ("pixels-inside-wrap-set", PROP_PIXELS_INSIDE_WRAP_SET,
793 794
                P_("Pixels inside wrap set"),
                P_("Whether this tag affects the number of pixels between wrapped lines"));
795

Matthias Clasen's avatar
x  
Matthias Clasen committed
796
  ADD_SET_PROP ("strikethrough-set", PROP_STRIKETHROUGH_SET,
797 798
                P_("Strikethrough set"),
                P_("Whether this tag affects strikethrough"));
799
  
Matthias Clasen's avatar
x  
Matthias Clasen committed
800
  ADD_SET_PROP ("right-margin-set", PROP_RIGHT_MARGIN_SET,
801 802
                P_("Right margin set"),
                P_("Whether this tag affects the right margin"));
803

Matthias Clasen's avatar
x  
Matthias Clasen committed
804
  ADD_SET_PROP ("underline-set", PROP_UNDERLINE_SET,
805 806
                P_("Underline set"),
                P_("Whether this tag affects underlining"));
807

808 809 810 811 812
  /**
   * GtkTextTag:underline-rgba-set:
   *
   * If the #GtkTextTag:underline-rgba property has been set.
   *
813
   * Since: 3.16
814 815 816 817 818 819 820 821 822 823
   */
  ADD_SET_PROP ("underline-rgba-set", PROP_UNDERLINE_RGBA_SET,
                P_("Underline RGBA set"),
                P_("Whether this tag affects underlining color"));

  /**
   * GtkTextTag:strikethrough-rgba-set:
   *
   * If the #GtkTextTag:strikethrough-rgba property has been set.
   *
824
   * Since: 3.16
825 826 827 828 829
   */
  ADD_SET_PROP ("strikethrough-rgba-set", PROP_STRIKETHROUGH_RGBA_SET,
                P_("Strikethrough RGBA set"),
                P_("Whether this tag affects strikethrough color"));

Matthias Clasen's avatar
x  
Matthias Clasen committed
830
  ADD_SET_PROP ("wrap-mode-set", PROP_WRAP_MODE_SET,
831 832
                P_("Wrap mode set"),
                P_("Whether this tag affects line wrap mode"));
833

Matthias Clasen's avatar
x  
Matthias Clasen committed
834
  ADD_SET_PROP ("tabs-set", PROP_TABS_SET,
835 836
                P_("Tabs set"),
                P_("Whether this tag affects tabs"));
837

Matthias Clasen's avatar
x  
Matthias Clasen committed
838
  ADD_SET_PROP ("invisible-set", PROP_INVISIBLE_SET,
839 840
                P_("Invisible set"),
                P_("Whether this tag affects text visibility"));
841

842 843 844
  ADD_SET_PROP ("paragraph-background-set", PROP_PARAGRAPH_BACKGROUND_SET,
                P_("Paragraph background set"),
                P_("Whether this tag affects the paragraph background color"));
845

846 847 848 849 850 851 852 853
  ADD_SET_PROP ("fallback-set", PROP_FALLBACK_SET,
                P_("Fallback set"),
                P_("Whether this tag affects font fallback"));

  ADD_SET_PROP ("letter-spacing-set", PROP_LETTER_SPACING_SET,
                P_("Letter spacing set"),
                P_("Whether this tag affects letter spacing"));

854 855 856 857
  ADD_SET_PROP ("font-features-set", PROP_FONT_FEATURES_SET,
                P_("Font features set"),
                P_("Whether this tag affects font features"));

858 859 860 861 862
  /**
   * 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
Matthias Clasen's avatar
Matthias Clasen committed
863
   * @iter: a #GtkTextIter pointing at the location the event occurred
864 865 866 867 868 869 870
   *
   * 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.
   */
871
  signals[EVENT] =
872
    g_signal_new (I_("event"),
873 874
                  G_OBJECT_CLASS_TYPE (object_class),
                  G_SIGNAL_RUN_LAST,
Manish Singh's avatar
Manish Singh committed
875
                  G_STRUCT_OFFSET (GtkTextTagClass, event),
876
                  _gtk_boolean_handled_accumulator, NULL,
877
                  _gtk_marshal_BOOLEAN__OBJECT_BOXED_BOXED,
878 879 880
                  G_TYPE_BOOLEAN,
                  3,
                  G_TYPE_OBJECT,
881
                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE,
882
                  GTK_TYPE_TEXT_ITER);
883 884 885
  g_signal_set_va_marshaller (signals[EVENT],
                              G_OBJECT_CLASS_TYPE (object_class),
                              _gtk_marshal_BOOLEAN__OBJECT_BOXED_BOXEDv);
886 887
}

888
static void
889
gtk_text_tag_init (GtkTextTag *text_tag)
890
{
891 892
  text_tag->priv = gtk_text_tag_get_instance_private (text_tag);
  text_tag->priv->values = gtk_text_attributes_new ();
893 894
}

895 896
/**
 * gtk_text_tag_new:
897
 * @name: (allow-none): tag name, or %NULL
898 899 900 901
 * 
 * Creates a #GtkTextTag. Configure the tag using object arguments,
 * i.e. using g_object_set().
 * 
902
 * Returns: a new #GtkTextTag
903
 **/
904 905 906 907 908
GtkTextTag*
gtk_text_tag_new (const gchar *name)
{
  GtkTextTag *tag;

Manish Singh's avatar
Manish Singh committed
909
  tag = g_object_new (GTK_TYPE_TEXT_TAG, "name", name, NULL);
910 911 912 913 914

  return tag;
}

static void
915
gtk_text_tag_finalize (GObject *object)
916
{
917 918
  GtkTextTag *text_tag = GTK_TEXT_TAG (object);
  GtkTextTagPrivate *priv = text_tag->priv;
919

920 921
  if (priv->table)
    gtk_text_tag_table_remove (priv->table, text_tag);
922

923
  g_assert (priv->table == NULL);
924

925 926
  gtk_text_attributes_unref (priv->values);
  priv->values = NULL;
927

928 929
  g_free (priv->name);
  priv->name = NULL;
930

931
  G_OBJECT_CLASS (gtk_text_tag_parent_class)->finalize (object);
932 933
}

934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952
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;
}

953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012
static void
set_underline_rgba (GtkTextTag    *tag,
                    const GdkRGBA *rgba)
{
  GtkTextTagPrivate *priv = tag->priv;

  if (rgba)
    {
      GTK_TEXT_APPEARANCE_SET_UNDERLINE_RGBA (&priv->values->appearance, rgba);

      if (!GTK_TEXT_APPEARANCE_GET_UNDERLINE_RGBA_SET (&priv->values->appearance))
        {
          GTK_TEXT_APPEARANCE_SET_UNDERLINE_RGBA_SET (&priv->values->appearance, TRUE);
          g_object_notify (G_OBJECT (tag), "underline-rgba-set");
        }
    }
  else
    {
      GdkRGBA black = { 0 };

      GTK_TEXT_APPEARANCE_SET_UNDERLINE_RGBA (&priv->values->appearance, &black);

      if (GTK_TEXT_APPEARANCE_GET_UNDERLINE_RGBA_SET (&priv->values->appearance))
        {
          GTK_TEXT_APPEARANCE_SET_UNDERLINE_RGBA_SET (&priv->values->appearance, FALSE);
          g_object_notify (G_OBJECT (tag), "underline-rgba-set");
        }
    }
}

static void
set_strikethrough_rgba (GtkTextTag    *tag,
                        const GdkRGBA *rgba)
{
  GtkTextTagPrivate *priv = tag->priv;

  if (rgba)
    {
      GTK_TEXT_APPEARANCE_SET_STRIKETHROUGH_RGBA (&priv->values->appearance, rgba);

      if (!GTK_TEXT_APPEARANCE_GET_STRIKETHROUGH_RGBA_SET (&priv->values->appearance))
        {
          GTK_TEXT_APPEARANCE_SET_STRIKETHROUGH_RGBA_SET (&priv->values->appearance, TRUE);
          g_object_notify (G_OBJECT (tag), "strikethrough-rgba-set");
        }
    }
  else
    {
      GdkRGBA black = { 0 };

      GTK_TEXT_APPEARANCE_SET_STRIKETHROUGH_RGBA (&priv->values->appearance, &black);

      if (GTK_TEXT_APPEARANCE_GET_STRIKETHROUGH_RGBA_SET (&priv->values->appearance))
        {
          GTK_TEXT_APPEARANCE_SET_STRIKETHROUGH_RGBA_SET (&priv->values->appearance, FALSE);
          g_object_notify (G_OBJECT (tag), "strikethrough-rgba-set");
        }
    }
}

1013
static void
1014
set_bg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
1015
{
1016 1017
  GtkTextTagPrivate *priv = tag->priv;

1018 1019 1020 1021 1022 1023
  if (priv->values->appearance.rgba[0])
    gdk_rgba_free (priv->values->appearance.rgba[0]);

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

  if (rgba)
1024
    {
1025
      if (!priv->bg_color_set)
Havoc Pennington's avatar
Havoc Pennington committed
1026
        {
1027
          priv->bg_color_set = TRUE;
1028
          g_object_notify (G_OBJECT (tag), "background-set");
Havoc Pennington's avatar
Havoc Pennington committed
1029
        }
1030

1031
      priv->values->appearance.rgba[0] = gdk_rgba_copy (rgba);
1032 1033

      copy_rgba_to_gdk_color (rgba, &priv->values->appearance.bg_color);
1034 1035 1036
    }
  else
    {
1037
      if (priv->bg_color_set)
Havoc Pennington's avatar
Havoc Pennington committed
1038
        {
1039
          priv->bg_color_set = FALSE;
1040
          g_object_notify (G_OBJECT (tag), "background-set");
Havoc Pennington's avatar
Havoc Pennington committed
1041
        }
1042 1043 1044 1045
    }
}

static void
1046
set_fg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
1047
{
1048 1049
  GtkTextTagPrivate *priv = tag->priv;

1050 1051 1052 1053 1054 1055
  if (priv->values->appearance.rgba[1])
    gdk_rgba_free (priv->values->appearance.rgba[1]);

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

  if (rgba)
1056
    {
1057
      if (!priv->fg_color_set)
Havoc Pennington's avatar
Havoc Pennington committed
1058
        {
1059
          priv->fg_color_set = TRUE;
1060
          g_object_notify (G_OBJECT (tag), "foreground-set");
Havoc Pennington's avatar
Havoc Pennington committed
1061
        }
1062 1063

      priv->values->appearance.rgba[1] = gdk_rgba_copy (rgba);
1064 1065

      copy_rgba_to_gdk_color (rgba, &priv->values->appearance.fg_color);
1066 1067 1068
    }
  else
    {
1069
      if (priv->fg_color_set)
Havoc Pennington's avatar
Havoc Pennington committed
1070
        {
1071
          priv->fg_color_set = FALSE;
1072
          g_object_notify (G_OBJECT (tag), "foreground-set");
Havoc Pennington's avatar
Havoc Pennington committed
1073
        }
1074 1075 1076
    }
}

1077
static void
1078
set_pg_bg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
1079
{
1080 1081
  GtkTextTagPrivate *priv = tag->priv;

1082 1083 1084
  if (priv->values->pg_bg_rgba)
    gdk_rgba_free (priv->values->pg_bg_rgba);

Matthias Clasen's avatar
Matthias Clasen committed
1085
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
1086 1087
  if (priv->values->pg_bg_color)
    gdk_color_free (priv->values->pg_bg_color);
Matthias Clasen's avatar
Matthias Clasen committed
1088
G_GNUC_END_IGNORE_DEPRECATIONS
1089

1090
  priv->values->pg_bg_rgba = NULL;
1091
  priv->values->pg_bg_color = NULL;
1092 1093

  if (rgba)
1094
    {
1095 1096
      GdkColor color = { 0, };

1097
      if (!priv->pg_bg_color_set)
1098
        {
1099
          priv->pg_bg_color_set = TRUE;
1100 1101 1102
          g_object_notify (G_OBJECT (tag), "paragraph-background-set");
        }

1103
      priv->values->pg_bg_rgba = gdk_rgba_copy (rgba);
1104 1105

      copy_rgba_to_gdk_color (rgba, &color);
Matthias Clasen's avatar
Matthias Clasen committed
1106
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
1107
      priv->values->pg_bg_color = gdk_color_copy (&color);
Matthias Clasen's avatar
Matthias Clasen committed
1108
G_GNUC_END_IGNORE_DEPRECATIONS
1109 1110 1111
    }
  else
    {
1112
      if (priv->pg_bg_color_set)
1113
        {
1114
          priv->pg_bg_color_set = FALSE;
1115 1116
          g_object_notify (G_OBJECT (tag), "paragraph-background-set");
        }
1117 1118
    }
}
1119

1120 1121 1122 1123 1124 1125 1126 1127

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

1128
      copy_gdk_color_to_rgba (color, &rgba);
1129
      set_bg_rgba (tag, &rgba);
1130
    }
1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141
  else
    set_bg_rgba (tag, NULL);
}

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

1142
      copy_gdk_color_to_rgba (color, &rgba);
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155
      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;

1156
      copy_gdk_color_to_rgba (color, &rgba);
1157 1158 1159 1160
      set_pg_bg_rgba (tag, &rgba);
    }
  else
    set_pg_bg_rgba (tag, NULL);
1161 1162
}

1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184
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;
}

1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224
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;
}

1225 1226 1227 1228 1229
static void
notify_set_changed (GObject       *object,
		    PangoFontMask  changed_mask)
{
  if (changed_mask & PANGO_FONT_MASK_FAMILY)
1230
    g_object_notify (object, "family-set");
1231
  if (changed_mask & PANGO_FONT_MASK_STYLE)
1232
    g_object_notify (object, "style-set");
1233
  if (changed_mask & PANGO_FONT_MASK_VARIANT)
1234
    g_object_notify (object, "variant-set");
1235
  if (changed_mask & PANGO_FONT_MASK_WEIGHT)
1236
    g_object_notify (object, "weight-set");
1237
  if (changed_mask & PANGO_FONT_MASK_STRETCH)
1238
    g_object_notify (object, "stretch-set");
1239
  if (changed_mask & PANGO_FONT_MASK_SIZE)
1240
    g_object_notify (object, "size-set");
1241 1242
}

1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260
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");
}

1261 1262 1263 1264
static void
set_font_description (GtkTextTag           *text_tag,
                      PangoFontDescription *font_desc)
{
1265
  GtkTextTagPrivate *priv = text_tag->priv;
1266 1267 1268 1269 1270 1271 1272 1273 1274
  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 ();

1275 1276
  if (priv->values->font)
    old_mask = pango_font_description_get_set_fields (priv->values->font);
1277
  else
1278 1279 1280 1281 1282 1283 1284
    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;

1285 1286 1287 1288
  if (priv->values->font)
    pango_font_description_free (priv->values->font);
  priv->values->font = new_font_desc;

1289 1290
  g_object_freeze_notify (object);

1291
  g_object_notify (object, "font-desc");
1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304
  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
1305
    {
1306
      g_object_notify (object, "size");
1307
      g_object_notify (object, "size-points");
1308
    }
1309 1310 1311 1312 1313 1314 1315 1316 1317

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

static void
gtk_text_tag_ensure_font (GtkTextTag *text_tag)
{
1318 1319 1320 1321
  GtkTextTagPrivate *priv = text_tag->priv;

  if (!priv->values->font)
    priv->values->font = pango_font_description_new ();
1322 1323
}

1324
static void
1325 1326 1327
gtk_text_tag_set_property (GObject      *object,
                           guint         prop_id,
                           const GValue *value,
Tim Janik's avatar
Tim Janik committed
1328
                           GParamSpec   *pspec)
1329
{
1330 1331
  GtkTextTag *text_tag = GTK_TEXT_TAG (object);
  GtkTextTagPrivate *priv = text_tag->priv;
1332
<