gtktexttag.c 67.7 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
 * @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.
64 65 66 67
 *
 * For each property of #GtkTextTag, there is a "set" property, e.g.
 * "font-set" corresponds to "font". These "set" properties reflect
 * whether a property has been set or not.
68
 * They are maintained by GTK+ and you should not set them independently.
69 70
 */

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

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

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

enum {
  EVENT,
  LAST_SIGNAL
};

enum {
90
  PROP_0,
91
  /* Construct args */
92
  PROP_NAME,
93 94

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

  /* Behavior args */
  PROP_ACCUMULATIVE_MARGIN,
134
  
135
  /* Whether-a-style-arg-is-set args */
136 137 138 139 140 141 142 143
  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
144
  PROP_SCALE_SET,
145 146 147 148 149
  PROP_PIXELS_ABOVE_LINES_SET,
  PROP_PIXELS_BELOW_LINES_SET,
  PROP_PIXELS_INSIDE_WRAP_SET,
  PROP_EDITABLE_SET,
  PROP_WRAP_MODE_SET,
150
  PROP_JUSTIFICATION_SET,
151 152 153 154 155 156
  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
157
  PROP_BACKGROUND_FULL_HEIGHT_SET,
158 159 160
  PROP_LANGUAGE_SET,
  PROP_TABS_SET,
  PROP_INVISIBLE_SET,
161
  PROP_PARAGRAPH_BACKGROUND_SET,
162

163 164
  LAST_ARG
};
165 166 167 168
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
169
                                       GParamSpec      *pspec);
170 171 172
static void gtk_text_tag_get_property (GObject         *object,
                                       guint            prop_id,
                                       GValue          *value,
Tim Janik's avatar
Tim Janik committed
173
                                       GParamSpec      *pspec);
174

175 176
static guint signals[LAST_SIGNAL] = { 0 };

Matthias Clasen's avatar
Matthias Clasen committed
177
G_DEFINE_TYPE (GtkTextTag, gtk_text_tag, G_TYPE_OBJECT)
178 179 180 181

static void
gtk_text_tag_class_init (GtkTextTagClass *klass)
{
182
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
183

184 185 186 187
  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;
188

189
  /* Construct */
190 191 192
  g_object_class_install_property (object_class,
                                   PROP_NAME,
                                   g_param_spec_string ("name",
193 194
                                                        P_("Tag name"),
                                                        P_("Name used to refer to the text tag. NULL for anonymous tags"),
195
                                                        NULL,
196
                                                        GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
197 198

  /* Style args */
199 200 201 202

  g_object_class_install_property (object_class,
                                   PROP_BACKGROUND,
                                   g_param_spec_string ("background",
203 204
                                                        P_("Background color name"),
                                                        P_("Background color as a string"),
205
                                                        NULL,
206
                                                        GTK_PARAM_WRITABLE));
207

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

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

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

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

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

284 285 286
  g_object_class_install_property (object_class,
                                   PROP_DIRECTION,
                                   g_param_spec_enum ("direction",
287 288
                                                      P_("Text direction"),
                                                      P_("Text direction, e.g. right-to-left or left-to-right"),
289
                                                      GTK_TYPE_TEXT_DIRECTION,
290
                                                      GTK_TEXT_DIR_NONE,
291
                                                      GTK_PARAM_READWRITE));
292 293 294 295

  g_object_class_install_property (object_class,
                                   PROP_EDITABLE,
                                   g_param_spec_boolean ("editable",
296 297
                                                         P_("Editable"),
                                                         P_("Whether the text can be modified by the user"),
298
                                                         TRUE,
299
                                                         GTK_PARAM_READWRITE));
300

301 302 303 304 305 306 307 308
  /**
   * 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.
   */
309 310 311
  g_object_class_install_property (object_class,
                                   PROP_FONT,
                                   g_param_spec_string ("font",
312 313
                                                        P_("Font"),
                                                        P_("Font description as a string, e.g. \"Sans Italic 12\""),
314
                                                        NULL,
315
                                                        GTK_PARAM_READWRITE));
316 317 318

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

  g_object_class_install_property (object_class,
                                   PROP_STYLE,
                                   g_param_spec_enum ("style",
336 337
                                                      P_("Font style"),
                                                      P_("Font style as a PangoStyle, e.g. PANGO_STYLE_ITALIC"),
338 339
                                                      PANGO_TYPE_STYLE,
                                                      PANGO_STYLE_NORMAL,
340
                                                      GTK_PARAM_READWRITE));
341 342 343 344

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

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

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

  g_object_class_install_property (object_class,
402 403
                                   PROP_JUSTIFICATION,
                                   g_param_spec_enum ("justification",
404 405
                                                      P_("Justification"),
                                                      P_("Left, right, or center justification"),
406 407
                                                      GTK_TYPE_JUSTIFICATION,
                                                      GTK_JUSTIFY_LEFT,
408
                                                      GTK_PARAM_READWRITE));
409 410 411 412 413 414 415 416 417 418 419

  /**
   * 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().
   */
420 421 422
  g_object_class_install_property (object_class,
                                   PROP_LANGUAGE,
                                   g_param_spec_string ("language",
423
                                                        P_("Language"),
424
                                                        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."),
425
                                                        NULL,
426
                                                        GTK_PARAM_READWRITE));  
427 428 429

  g_object_class_install_property (object_class,
                                   PROP_LEFT_MARGIN,
Matthias Clasen's avatar
x  
Matthias Clasen committed
430
                                   g_param_spec_int ("left-margin",
431 432
                                                     P_("Left margin"),
                                                     P_("Width of the left margin in pixels"),
433 434 435
                                                     0,
                                                     G_MAXINT,
                                                     0,
436
                                                     GTK_PARAM_READWRITE));
437 438 439

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

  
  g_object_class_install_property (object_class,
                                   PROP_INDENT,
                                   g_param_spec_int ("indent",
452 453
                                                     P_("Indent"),
                                                     P_("Amount to indent the paragraph, in pixels"),
454
                                                     G_MININT,
455 456
                                                     G_MAXINT,
                                                     0,
457
                                                     GTK_PARAM_READWRITE));
458 459 460 461 462

  
  g_object_class_install_property (object_class,
                                   PROP_RISE,
                                   g_param_spec_int ("rise",
463
                                                     P_("Rise"),
464
                                                     P_("Offset of text above the baseline (below the baseline if rise is negative) in Pango units"),
465
						     G_MININT,
466 467
                                                     G_MAXINT,
                                                     0,
468
                                                     GTK_PARAM_READWRITE));
469 470 471

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

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

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

  g_object_class_install_property (object_class,
                                   PROP_TABS,
                                   g_param_spec_boxed ("tabs",
530 531
                                                       P_("Tabs"),
                                                       P_("Custom tabs for this text"),
532
                                                       PANGO_TYPE_TAB_ARRAY,
533
                                                       GTK_PARAM_READWRITE));
534
  
535 536 537 538 539 540 541 542 543 544 545
  /**
   * 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
   */
546 547 548
  g_object_class_install_property (object_class,
                                   PROP_INVISIBLE,
                                   g_param_spec_boolean ("invisible",
549
                                                         P_("Invisible"),
550
                                                         P_("Whether this text is hidden."),
551
                                                         FALSE,
552
                                                         GTK_PARAM_READWRITE));
553

554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571
  /**
   * 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:
   *
572
   * The paragraph background color as a as a #GdkColor.
573 574
   *
   * Since: 2.8
575 576
   *
   * Deprecated: 3.4: Use #GtkTextTag:paragraph-background-rgba instead.
577 578 579 580 581
   */
  g_object_class_install_property (object_class,
                                   PROP_PARAGRAPH_BACKGROUND_GDK,
                                   g_param_spec_boxed ("paragraph-background-gdk",
                                                       P_("Paragraph background color"),
582
                                                       P_("Paragraph background color as a GdkColor"),
583
                                                       GDK_TYPE_COLOR,
584
                                                       GTK_PARAM_READWRITE | G_PARAM_DEPRECATED));
585

586 587 588
  /**
   * GtkTextTag:paragraph-background-rgba:
   *
589
   * The paragraph background color as a as a #GdkRGBA.
590 591 592 593 594 595
   *
   * 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
596 597
                                                       P_("Paragraph background RGBA"),
                                                       P_("Paragraph background RGBA as a GdkRGBA"),
598 599 600
                                                       GDK_TYPE_RGBA,
                                                       GTK_PARAM_READWRITE));

601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
  /**
   * 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));

620 621
  /* Style props are set or not */

622
#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))
623

Matthias Clasen's avatar
x  
Matthias Clasen committed
624
  ADD_SET_PROP ("background-set", PROP_BACKGROUND_SET,
625 626
                P_("Background set"),
                P_("Whether this tag affects the background color"));
627
  
Matthias Clasen's avatar
x  
Matthias Clasen committed
628
  ADD_SET_PROP ("background-full-height-set", PROP_BACKGROUND_FULL_HEIGHT_SET,
629 630
                P_("Background full height set"),
                P_("Whether this tag affects background height"));
631

Matthias Clasen's avatar
x  
Matthias Clasen committed
632
  ADD_SET_PROP ("foreground-set", PROP_FOREGROUND_SET,
633 634
                P_("Foreground set"),
                P_("Whether this tag affects the foreground color"));
635

Matthias Clasen's avatar
x  
Matthias Clasen committed
636
  ADD_SET_PROP ("editable-set", PROP_EDITABLE_SET,
637 638
                P_("Editability set"),
                P_("Whether this tag affects text editability"));
639

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

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

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

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

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

Matthias Clasen's avatar
x  
Matthias Clasen committed
660
  ADD_SET_PROP ("size-set", PROP_SIZE_SET,
661 662
                P_("Font size set"),
                P_("Whether this tag affects the font size"));
663

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

Matthias Clasen's avatar
x  
Matthias Clasen committed
676
  ADD_SET_PROP ("left-margin-set", PROP_LEFT_MARGIN_SET,
677 678
                P_("Left margin set"),
                P_("Whether this tag affects the left margin"));
679

Matthias Clasen's avatar
x  
Matthias Clasen committed
680
  ADD_SET_PROP ("indent-set", PROP_INDENT_SET,
681 682
                P_("Indent set"),
                P_("Whether this tag affects indentation"));
683

Matthias Clasen's avatar
x  
Matthias Clasen committed
684
  ADD_SET_PROP ("rise-set", PROP_RISE_SET,
685 686
                P_("Rise set"),
                P_("Whether this tag affects the rise"));
687

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

Matthias Clasen's avatar
x  
Matthias Clasen committed
692
  ADD_SET_PROP ("pixels-below-lines-set", PROP_PIXELS_BELOW_LINES_SET,
693 694
                P_("Pixels below lines set"),
                P_("Whether this tag affects the number of pixels above lines"));
695

Matthias Clasen's avatar
x  
Matthias Clasen committed
696
  ADD_SET_PROP ("pixels-inside-wrap-set", PROP_PIXELS_INSIDE_WRAP_SET,
697 698
                P_("Pixels inside wrap set"),
                P_("Whether this tag affects the number of pixels between wrapped lines"));
699

Matthias Clasen's avatar
x  
Matthias Clasen committed
700
  ADD_SET_PROP ("strikethrough-set", PROP_STRIKETHROUGH_SET,
701 702
                P_("Strikethrough set"),
                P_("Whether this tag affects strikethrough"));
703
  
Matthias Clasen's avatar
x  
Matthias Clasen committed
704
  ADD_SET_PROP ("right-margin-set", PROP_RIGHT_MARGIN_SET,
705 706
                P_("Right margin set"),
                P_("Whether this tag affects the right margin"));
707

Matthias Clasen's avatar
x  
Matthias Clasen committed
708
  ADD_SET_PROP ("underline-set", PROP_UNDERLINE_SET,
709 710
                P_("Underline set"),
                P_("Whether this tag affects underlining"));
711

Matthias Clasen's avatar
x  
Matthias Clasen committed
712
  ADD_SET_PROP ("wrap-mode-set", PROP_WRAP_MODE_SET,
713 714
                P_("Wrap mode set"),
                P_("Whether this tag affects line wrap mode"));
715

Matthias Clasen's avatar
x  
Matthias Clasen committed
716
  ADD_SET_PROP ("tabs-set", PROP_TABS_SET,
717 718
                P_("Tabs set"),
                P_("Whether this tag affects tabs"));
719

Matthias Clasen's avatar
x  
Matthias Clasen committed
720
  ADD_SET_PROP ("invisible-set", PROP_INVISIBLE_SET,
721 722
                P_("Invisible set"),
                P_("Whether this tag affects text visibility"));
723

724 725 726
  ADD_SET_PROP ("paragraph-background-set", PROP_PARAGRAPH_BACKGROUND_SET,
                P_("Paragraph background set"),
                P_("Whether this tag affects the paragraph background color"));
727 728 729 730 731 732 733 734 735 736 737 738 739 740

  /**
   * 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.
   */
741
  signals[EVENT] =
742
    g_signal_new (I_("event"),
743 744
                  G_OBJECT_CLASS_TYPE (object_class),
                  G_SIGNAL_RUN_LAST,
Manish Singh's avatar
Manish Singh committed
745
                  G_STRUCT_OFFSET (GtkTextTagClass, event),
746
                  _gtk_boolean_handled_accumulator, NULL,
747
                  _gtk_marshal_BOOLEAN__OBJECT_BOXED_BOXED,
748 749 750
                  G_TYPE_BOOLEAN,
                  3,
                  G_TYPE_OBJECT,
751
                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE,
752
                  GTK_TYPE_TEXT_ITER);
753 754

  g_type_class_add_private (klass, sizeof (GtkTextTagPrivate));
755 756
}

757
static void
758
gtk_text_tag_init (GtkTextTag *text_tag)
759
{
760 761 762 763 764 765 766 767
  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 ();
768 769
}

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

Manish Singh's avatar
Manish Singh committed
784
  tag = g_object_new (GTK_TYPE_TEXT_TAG, "name", name, NULL);
785 786 787 788 789

  return tag;
}

static void
790
gtk_text_tag_finalize (GObject *object)
791
{
792 793
  GtkTextTag *text_tag = GTK_TEXT_TAG (object);
  GtkTextTagPrivate *priv = text_tag->priv;
794

795 796
  if (priv->table)
    gtk_text_tag_table_remove (priv->table, text_tag);
797

798
  g_assert (priv->table == NULL);
799

800 801
  gtk_text_attributes_unref (priv->values);
  priv->values = NULL;
802

803 804
  g_free (priv->name);
  priv->name = NULL;
805

806
  G_OBJECT_CLASS (gtk_text_tag_parent_class)->finalize (object);
807 808
}

809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827
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;
}

828
static void
829
set_bg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
830
{
831 832
  GtkTextTagPrivate *priv = tag->priv;

833 834 835 836 837 838
  if (priv->values->appearance.rgba[0])
    gdk_rgba_free (priv->values->appearance.rgba[0]);

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

  if (rgba)
839
    {
840
      if (!priv->bg_color_set)
Havoc Pennington's avatar
Havoc Pennington committed
841
        {
842
          priv->bg_color_set = TRUE;
843
          g_object_notify (G_OBJECT (tag), "background-set");
Havoc Pennington's avatar
Havoc Pennington committed
844
        }
845

846
      priv->values->appearance.rgba[0] = gdk_rgba_copy (rgba);
847 848

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

static void
861
set_fg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
862
{
863 864
  GtkTextTagPrivate *priv = tag->priv;

865 866 867 868 869 870
  if (priv->values->appearance.rgba[1])
    gdk_rgba_free (priv->values->appearance.rgba[1]);

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

  if (rgba)
871
    {
872
      if (!priv->fg_color_set)
Havoc Pennington's avatar
Havoc Pennington committed
873
        {
874
          priv->fg_color_set = TRUE;
875
          g_object_notify (G_OBJECT (tag), "foreground-set");
Havoc Pennington's avatar
Havoc Pennington committed
876
        }
877 878

      priv->values->appearance.rgba[1] = gdk_rgba_copy (rgba);
879 880

      copy_rgba_to_gdk_color (rgba, &priv->values->appearance.fg_color);
881 882 883
    }
  else
    {
884
      if (priv->fg_color_set)
Havoc Pennington's avatar
Havoc Pennington committed
885
        {
886
          priv->fg_color_set = FALSE;
887
          g_object_notify (G_OBJECT (tag), "foreground-set");
Havoc Pennington's avatar
Havoc Pennington committed
888
        }
889 890 891
    }
}

892
static void
893
set_pg_bg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
894
{
895 896
  GtkTextTagPrivate *priv = tag->priv;

897 898 899
  if (priv->values->pg_bg_rgba)
    gdk_rgba_free (priv->values->pg_bg_rgba);

900 901 902
  if (priv->values->pg_bg_color)
    gdk_color_free (priv->values->pg_bg_color);

903
  priv->values->pg_bg_rgba = NULL;
904
  priv->values->pg_bg_color = NULL;
905 906

  if (rgba)
907
    {
908 909
      GdkColor color = { 0, };

910
      if (!priv->pg_bg_color_set)
911
        {
912
          priv->pg_bg_color_set = TRUE;
913 914 915
          g_object_notify (G_OBJECT (tag), "paragraph-background-set");
        }

916
      priv->values->pg_bg_rgba = gdk_rgba_copy (rgba);
917 918 919

      copy_rgba_to_gdk_color (rgba, &color);
      priv->values->pg_bg_color = gdk_color_copy (&color);
920 921 922
    }
  else
    {
923
      if (priv->pg_bg_color_set)
924
        {
925
          priv->pg_bg_color_set = FALSE;
926 927
          g_object_notify (G_OBJECT (tag), "paragraph-background-set");
        }
928 929
    }
}
930

931 932 933 934 935 936 937 938

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

939
      copy_gdk_color_to_rgba (color, &rgba);
940
      set_bg_rgba (tag, &rgba);
941
    }
942 943 944 945 946 947 948 949 950 951 952
  else
    set_bg_rgba (tag, NULL);
}

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

953
      copy_gdk_color_to_rgba (color, &rgba);
954 955 956 957 958 959 960 961 962 963 964 965 966
      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;

967
      copy_gdk_color_to_rgba (color, &rgba);
968 969 970 971
      set_pg_bg_rgba (tag, &rgba);
    }
  else
    set_pg_bg_rgba (tag, NULL);
972 973
}

974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995
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;
}

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 1031 1032 1033 1034 1035
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;
}

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

1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071
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");
}

1072 1073 1074 1075
static void
set_font_description (GtkTextTag           *text_tag,
                      PangoFontDescription *font_desc)
{
1076
  GtkTextTagPrivate *priv = text_tag->priv;
1077 1078 1079 1080 1081 1082 1083 1084 1085
  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 ();

1086 1087
  if (priv->values->font)
    old_mask = pango_font_description_get_set_fields (priv->values->font);
1088
  else
1089 1090 1091 1092 1093 1094 1095
    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;

1096 1097 1098 1099
  if (priv->values->font)
    pango_font_description_free (priv->values->font);
  priv->values->font = new_font_desc;

1100 1101
  g_object_freeze_notify (object);

1102
  g_object_notify (object, "font-desc");
1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115
  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
1116
    {
1117
      g_object_notify (object, "size");
1118
      g_object_notify (object, "size-points");
1119
    }
1120 1121 1122 1123 1124 1125 1126 1127 1128

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

static void
gtk_text_tag_ensure_font (GtkTextTag *text_tag)
{
1129 1130 1131 1132
  GtkTextTagPrivate *priv = text_tag->priv;

  if (!priv->values->font)
    priv->values->font = pango_font_description_new ();
1133 1134
}

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

1145
  switch (prop_id)
1146
    {
1147
    case PROP_NAME:
1148 1149
      g_return_if_fail (priv->name == NULL);
      priv->name = g_value_dup_string (value);
1150 1151
      break;

1152
    case PROP_BACKGROUND:
1153
      {
1154
        GdkRGBA rgba;
1155

1156
        if (!g_value_get_string (value))
1157 1158 1159
          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);
1160
        else
1161
          g_warning ("Don't know color `%s'", g_value_get_string (value));
1162

1163
        g_object_notify (object, "background-gdk");
1164 1165 1166
      }
      break;

1167
    case PROP_FOREGROUND:
1168
      {
1169
        GdkRGBA rgba;
1170

1171
        if (!g_value_get_string (value))
1172 1173 1174
          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);
1175
        else
1176
          g_warning ("Don't know color `%s'", g_value_get_string (value));
1177

1178
        g_object_notify (object, "foreground-gdk");
1179 1180
      }
      break;
1181

1182
    case PROP_BACKGROUND_GDK:
1183
      {
Tim Janik's avatar
Tim Janik committed
1184 1185
        GdkColor *color = g_value_get_boxed (value);

1186
        set_bg_color (text_tag, color);
1187 1188 1189
      }
      break;

1190
    case PROP_FOREGROUND_GDK:
1191
      {
Tim Janik's avatar
Tim Janik committed
1192 1193
        GdkColor *color = g_value_get_boxed (value);

1194
        set_fg_color (text_tag, color);
1195 1196 1197
      }
      break;

1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213
    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;

1214
    case PROP_FONT:
1215 1216 1217 1218
      {
        PangoFontDescription *font_desc = NULL;
        const gchar *name;

1219
        name = g_value_get_string (value);
1220 1221

        if (name)
1222 1223
          font_desc = pango_font_description_from_string (name);

1224
        set_font_description (text_tag, font_desc);
1225 1226
	if (font_desc)
	  pango_font_description_free (font_desc);
1227
        
1228 1229 1230 1231
        size_changed = TRUE;
      }
      break;

1232
    case PROP_FONT_DESC:
1233 1234 1235
      {
        PangoFontDescription *font_desc;

Tim Janik's avatar
Tim Janik committed
1236
        font_desc = g_value_get_boxed (value);
1237

1238
        set_font_description (text_tag, font_desc);
1239 1240 1241 1242 1243

        size_changed = TRUE;
      }
      break;

1244 1245 1246 1247 1248 1249
    case PROP_FAMILY:
    case PROP_STYLE:
    case PROP_VARIANT:
    case PROP_WEIGHT:
    case PROP_STRETCH:
    case PROP_SIZE:
1250 1251 1252 1253 1254
    case PROP_SIZE_POINTS:
      {
	PangoFontMask old_set_mask;

	gtk_text_tag_ensure_font (text_tag);
1255
	old_set_mask = pango_font_description_get_set_fields (priv->values->font);
1256 1257 1258 1259
 
	switch (prop_id)
	  {
	  case PROP_FAMILY:
1260
	    pango_font_description_set_family (priv->values->font,
1261 1262 1263
					       g_value_get_string (value));
	    break;
	  case PROP_STYLE:
1264
	    pango_font_description_set_style (priv->values->font,