gtkcellrenderertext.c 72.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* gtkcellrenderertext.c
 * Copyright (C) 2000  Red Hat, Inc.,  Jonathan Blandford <jrb@redhat.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
Javier Jardón's avatar
Javier Jardón committed
15
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 17
 */

18
#include "config.h"
19

20
#include "gtkcellrenderertext.h"
21 22 23

#include <stdlib.h>

24 25
#include "gtkeditable.h"
#include "gtkentry.h"
26
#include "gtksizerequest.h"
27
#include "gtkmarshalers.h"
28
#include "gtkintl.h"
29
#include "gtkprivate.h"
30
#include "gtktreeprivate.h"
31
#include "a11y/gtktextcellaccessible.h"
32

33

34 35 36 37 38 39 40 41 42 43 44 45 46 47
/**
 * SECTION:gtkcellrenderertext
 * @Short_description: Renders text in a cell
 * @Title: GtkCellRendererText
 *
 * A #GtkCellRendererText renders a given text in its cell, using the font, color and
 * style information provided by its properties. The text will be ellipsized if it is
 * too long and the #GtkCellRendererText:ellipsize property allows it.
 *
 * If the #GtkCellRenderer:mode is %GTK_CELL_RENDERER_MODE_EDITABLE,
 * the #GtkCellRendererText allows to edit its text using an entry.
 */


48
static void gtk_cell_renderer_text_finalize   (GObject                  *object);
49

50 51 52
static void gtk_cell_renderer_text_get_property  (GObject                  *object,
						  guint                     param_id,
						  GValue                   *value,
Tim Janik's avatar
Tim Janik committed
53
						  GParamSpec               *pspec);
54 55 56
static void gtk_cell_renderer_text_set_property  (GObject                  *object,
						  guint                     param_id,
						  const GValue             *value,
Tim Janik's avatar
Tim Janik committed
57
						  GParamSpec               *pspec);
58
static void gtk_cell_renderer_text_render     (GtkCellRenderer          *cell,
59
					       cairo_t                  *cr,
60
					       GtkWidget                *widget,
61 62
					       const GdkRectangle       *background_area,
					       const GdkRectangle       *cell_area,
63
					       GtkCellRendererState      flags);
64

65 66 67
static GtkCellEditable *gtk_cell_renderer_text_start_editing (GtkCellRenderer      *cell,
							      GdkEvent             *event,
							      GtkWidget            *widget,
68
							      const gchar          *path,
69 70
							      const GdkRectangle   *background_area,
							      const GdkRectangle   *cell_area,
71
							      GtkCellRendererState  flags);
72

73 74 75 76 77 78 79 80 81 82 83 84 85
static void       gtk_cell_renderer_text_get_preferred_width            (GtkCellRenderer       *cell,
                                                                         GtkWidget             *widget,
                                                                         gint                  *minimal_size,
                                                                         gint                  *natural_size);
static void       gtk_cell_renderer_text_get_preferred_height           (GtkCellRenderer       *cell,
                                                                         GtkWidget             *widget,
                                                                         gint                  *minimal_size,
                                                                         gint                  *natural_size);
static void       gtk_cell_renderer_text_get_preferred_height_for_width (GtkCellRenderer       *cell,
                                                                         GtkWidget             *widget,
                                                                         gint                   width,
                                                                         gint                  *minimum_height,
                                                                         gint                  *natural_height);
86 87 88 89 90 91 92
static void       gtk_cell_renderer_text_get_aligned_area               (GtkCellRenderer       *cell,
									 GtkWidget             *widget,
									 GtkCellRendererState   flags,
									 const GdkRectangle    *cell_area,
									 GdkRectangle          *aligned_area);


93

94 95 96 97
enum {
  EDITED,
  LAST_SIGNAL
};
98

99
enum {
100 101
  PROP_0,

102
  PROP_TEXT,
103
  PROP_MARKUP,
104
  PROP_ATTRIBUTES,
105
  PROP_SINGLE_PARAGRAPH_MODE,
106
  PROP_WIDTH_CHARS,
107
  PROP_MAX_WIDTH_CHARS,
108
  PROP_WRAP_WIDTH,
109
  PROP_ALIGN,
110 111
  PROP_PLACEHOLDER_TEXT,

112
  /* Style args */
113 114
  PROP_BACKGROUND,
  PROP_FOREGROUND,
115
  PROP_BACKGROUND_GDK,
116
  PROP_FOREGROUND_GDK,
117 118
  PROP_BACKGROUND_RGBA,
  PROP_FOREGROUND_RGBA,
119 120 121 122 123 124 125 126 127
  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
128
  PROP_SCALE,
129
  PROP_EDITABLE,
130 131
  PROP_STRIKETHROUGH,
  PROP_UNDERLINE,
132
  PROP_RISE,
133
  PROP_LANGUAGE,
134
  PROP_ELLIPSIZE,
135
  PROP_WRAP_MODE,
136 137 138 139 140 141 142 143 144 145
  
  /* Whether-a-style-arg-is-set args */
  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
146
  PROP_SCALE_SET,
147 148 149
  PROP_EDITABLE_SET,
  PROP_STRIKETHROUGH_SET,
  PROP_UNDERLINE_SET,
150
  PROP_RISE_SET,
151
  PROP_LANGUAGE_SET,
152 153
  PROP_ELLIPSIZE_SET,
  PROP_ALIGN_SET
154 155
};

156 157 158
static guint text_cell_renderer_signals [LAST_SIGNAL];

#define GTK_CELL_RENDERER_TEXT_PATH "gtk-cell-renderer-text-path"
159

160
struct _GtkCellRendererTextPrivate
161
{
162 163 164
  GtkWidget *entry;

  PangoAttrList        *extra_attrs;
165 166
  GdkRGBA               foreground;
  GdkRGBA               background;
167
  PangoAlignment        align;
168 169 170 171 172 173 174
  PangoEllipsizeMode    ellipsize;
  PangoFontDescription *font;
  PangoLanguage        *language;
  PangoUnderline        underline_style;
  PangoWrapMode         wrap_mode;

  gchar *text;
175
  gchar *placeholder_text;
176 177 178 179 180

  gdouble font_scale;

  gint rise;
  gint fixed_height_rows;
181
  gint width_chars;
182
  gint max_width_chars;
183
  gint wrap_width;
184

185
  guint in_entry_menu     : 1;
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
  guint strikethrough     : 1;
  guint editable          : 1;
  guint scale_set         : 1;
  guint foreground_set    : 1;
  guint background_set    : 1;
  guint underline_set     : 1;
  guint rise_set          : 1;
  guint strikethrough_set : 1;
  guint editable_set      : 1;
  guint calc_fixed_height : 1;
  guint single_paragraph  : 1;
  guint language_set      : 1;
  guint markup_set        : 1;
  guint ellipsize_set     : 1;
  guint align_set         : 1;

  gulong focus_out_id;
  gulong populate_popup_id;
  gulong entry_menu_popdown_timeout;
205 206
};

207
G_DEFINE_TYPE_WITH_PRIVATE (GtkCellRendererText, gtk_cell_renderer_text, GTK_TYPE_CELL_RENDERER)
208 209 210 211

static void
gtk_cell_renderer_text_init (GtkCellRendererText *celltext)
{
212
  GtkCellRendererTextPrivate *priv;
213
  GtkCellRenderer *cell = GTK_CELL_RENDERER (celltext);
214

215
  celltext->priv = gtk_cell_renderer_text_get_instance_private (celltext);
216
  priv = celltext->priv;
217

218 219
  gtk_cell_renderer_set_alignment (cell, 0.0, 0.5);
  gtk_cell_renderer_set_padding (cell, 2, 2);
220 221 222
  priv->font_scale = 1.0;
  priv->fixed_height_rows = -1;
  priv->font = pango_font_description_new ();
223 224

  priv->width_chars = -1;
225
  priv->max_width_chars = -1;
226
  priv->wrap_width = -1;
227
  priv->wrap_mode = PANGO_WRAP_CHAR;
228
  priv->align = PANGO_ALIGN_LEFT;
229
  priv->align_set = FALSE;
230 231 232 233 234 235 236 237
}

static void
gtk_cell_renderer_text_class_init (GtkCellRendererTextClass *class)
{
  GObjectClass *object_class = G_OBJECT_CLASS (class);
  GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (class);

238 239
  object_class->finalize = gtk_cell_renderer_text_finalize;
  
240 241
  object_class->get_property = gtk_cell_renderer_text_get_property;
  object_class->set_property = gtk_cell_renderer_text_set_property;
242 243

  cell_class->render = gtk_cell_renderer_text_render;
244
  cell_class->start_editing = gtk_cell_renderer_text_start_editing;
245 246 247
  cell_class->get_preferred_width = gtk_cell_renderer_text_get_preferred_width;
  cell_class->get_preferred_height = gtk_cell_renderer_text_get_preferred_height;
  cell_class->get_preferred_height_for_width = gtk_cell_renderer_text_get_preferred_height_for_width;
248
  cell_class->get_aligned_area = gtk_cell_renderer_text_get_aligned_area;
249

250
  g_object_class_install_property (object_class,
251 252
                                   PROP_TEXT,
                                   g_param_spec_string ("text",
253 254
                                                        P_("Text"),
                                                        P_("Text to render"),
255
                                                        NULL,
256
                                                        GTK_PARAM_READWRITE));
257
  
258 259 260
  g_object_class_install_property (object_class,
                                   PROP_MARKUP,
                                   g_param_spec_string ("markup",
261 262
                                                        P_("Markup"),
                                                        P_("Marked up text to render"),
263
                                                        NULL,
264
                                                        GTK_PARAM_WRITABLE));
265

266
  g_object_class_install_property (object_class,
267 268
				   PROP_ATTRIBUTES,
				   g_param_spec_boxed ("attributes",
269 270
						       P_("Attributes"),
						       P_("A list of style attributes to apply to the text of the renderer"),
271
						       PANGO_TYPE_ATTR_LIST,
272
						       GTK_PARAM_READWRITE));
273 274 275

  g_object_class_install_property (object_class,
                                   PROP_SINGLE_PARAGRAPH_MODE,
Matthias Clasen's avatar
x  
Matthias Clasen committed
276
                                   g_param_spec_boolean ("single-paragraph-mode",
277
                                                         P_("Single Paragraph Mode"),
278
                                                         P_("Whether to keep all text in a single paragraph"),
279
                                                         FALSE,
280
                                                         GTK_PARAM_READWRITE));
281

282
  
283
  g_object_class_install_property (object_class,
284 285
                                   PROP_BACKGROUND,
                                   g_param_spec_string ("background",
286 287
                                                        P_("Background color name"),
                                                        P_("Background color as a string"),
288
                                                        NULL,
289
                                                        GTK_PARAM_WRITABLE));
290

291 292 293 294 295 296 297
  /**
   * GtkCellRendererText:background-gdk:
   *
   * Background color as a #GdkColor
   *
   * Deprecated: 3.4: Use #GtkCellRendererText:background-rgba instead.
   */
298 299
  g_object_class_install_property (object_class,
                                   PROP_BACKGROUND_GDK,
Matthias Clasen's avatar
x  
Matthias Clasen committed
300
                                   g_param_spec_boxed ("background-gdk",
301 302
                                                       P_("Background color"),
                                                       P_("Background color as a GdkColor"),
303
                                                       GDK_TYPE_COLOR,
304
                                                       GTK_PARAM_READWRITE | G_PARAM_DEPRECATED));
305

306 307 308 309 310 311 312 313 314 315 316 317 318 319
  /**
   * GtkCellRendererText:background-rgba:
   *
   * Background color as a #GdkRGBA
   *
   * Since: 3.0
   */
  g_object_class_install_property (object_class,
                                   PROP_BACKGROUND_RGBA,
                                   g_param_spec_boxed ("background-rgba",
                                                       P_("Background color as RGBA"),
                                                       P_("Background color as a GdkRGBA"),
                                                       GDK_TYPE_RGBA,
                                                       GTK_PARAM_READWRITE));
320 321 322
  g_object_class_install_property (object_class,
                                   PROP_FOREGROUND,
                                   g_param_spec_string ("foreground",
323 324
                                                        P_("Foreground color name"),
                                                        P_("Foreground color as a string"),
325
                                                        NULL,
326
                                                        GTK_PARAM_WRITABLE));
327

328 329 330 331 332 333 334
  /**
   * GtkCellRendererText:foreground-gdk:
   *
   * Foreground color as a #GdkColor
   *
   * Deprecated: 3.4: Use #GtkCellRendererText:foreground-rgba instead.
   */
335 336
  g_object_class_install_property (object_class,
                                   PROP_FOREGROUND_GDK,
Matthias Clasen's avatar
x  
Matthias Clasen committed
337
                                   g_param_spec_boxed ("foreground-gdk",
338 339
                                                       P_("Foreground color"),
                                                       P_("Foreground color as a GdkColor"),
340
                                                       GDK_TYPE_COLOR,
341
                                                       GTK_PARAM_READWRITE | G_PARAM_DEPRECATED));
342

343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
  /**
   * GtkCellRendererText:foreground-rgba:
   *
   * Foreground color as a #GdkRGBA
   *
   * Since: 3.0
   */
  g_object_class_install_property (object_class,
                                   PROP_FOREGROUND_RGBA,
                                   g_param_spec_boxed ("foreground-rgba",
                                                       P_("Foreground color as RGBA"),
                                                       P_("Foreground color as a GdkRGBA"),
                                                       GDK_TYPE_RGBA,
                                                       GTK_PARAM_READWRITE));

358 359 360 361

  g_object_class_install_property (object_class,
                                   PROP_EDITABLE,
                                   g_param_spec_boolean ("editable",
362 363
                                                         P_("Editable"),
                                                         P_("Whether the text can be modified by the user"),
Kristian Rietveld's avatar
Kristian Rietveld committed
364
                                                         FALSE,
365
                                                         GTK_PARAM_READWRITE));
366 367 368 369

  g_object_class_install_property (object_class,
                                   PROP_FONT,
                                   g_param_spec_string ("font",
370
                                                        P_("Font"),
371
                                                        P_("Font description as a string, e.g. \"Sans Italic 12\""),
372
                                                        NULL,
373
                                                        GTK_PARAM_READWRITE));
374

375
  g_object_class_install_property (object_class,
376
                                   PROP_FONT_DESC,
Matthias Clasen's avatar
x  
Matthias Clasen committed
377
                                   g_param_spec_boxed ("font-desc",
378 379
                                                       P_("Font"),
                                                       P_("Font description as a PangoFontDescription struct"),
380
                                                       PANGO_TYPE_FONT_DESCRIPTION,
381
                                                       GTK_PARAM_READWRITE));
382

383 384
  
  g_object_class_install_property (object_class,
385 386
                                   PROP_FAMILY,
                                   g_param_spec_string ("family",
387 388
                                                        P_("Font family"),
                                                        P_("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
389
                                                        NULL,
390
                                                        GTK_PARAM_READWRITE));
391 392 393 394

  g_object_class_install_property (object_class,
                                   PROP_STYLE,
                                   g_param_spec_enum ("style",
395 396
                                                      P_("Font style"),
                                                      P_("Font style"),
397 398
                                                      PANGO_TYPE_STYLE,
                                                      PANGO_STYLE_NORMAL,
399
                                                      GTK_PARAM_READWRITE));
400 401 402 403

  g_object_class_install_property (object_class,
                                   PROP_VARIANT,
                                   g_param_spec_enum ("variant",
404 405
                                                     P_("Font variant"),
                                                     P_("Font variant"),
406 407
                                                      PANGO_TYPE_VARIANT,
                                                      PANGO_VARIANT_NORMAL,
408
                                                      GTK_PARAM_READWRITE));
409 410
  
  g_object_class_install_property (object_class,
411
                                   PROP_WEIGHT,
CEST's avatar
CEST committed
412
                                   g_param_spec_int ("weight",
413 414
                                                     P_("Font weight"),
                                                     P_("Font weight"),
CEST's avatar
CEST committed
415 416
                                                     0,
                                                     G_MAXINT,
417
                                                     PANGO_WEIGHT_NORMAL,
418
                                                     GTK_PARAM_READWRITE));
419

CEST's avatar
CEST committed
420
   g_object_class_install_property (object_class,
421 422
                                   PROP_STRETCH,
                                   g_param_spec_enum ("stretch",
423 424
                                                      P_("Font stretch"),
                                                      P_("Font stretch"),
425 426
                                                      PANGO_TYPE_STRETCH,
                                                      PANGO_STRETCH_NORMAL,
427
                                                      GTK_PARAM_READWRITE));
428 429
  
  g_object_class_install_property (object_class,
430 431
                                   PROP_SIZE,
                                   g_param_spec_int ("size",
432 433
                                                     P_("Font size"),
                                                     P_("Font size"),
434 435 436
                                                     0,
                                                     G_MAXINT,
                                                     0,
437
                                                     GTK_PARAM_READWRITE));
438 439 440

  g_object_class_install_property (object_class,
                                   PROP_SIZE_POINTS,
Matthias Clasen's avatar
x  
Matthias Clasen committed
441
                                   g_param_spec_double ("size-points",
442 443
                                                        P_("Font points"),
                                                        P_("Font size in points"),
444 445 446
                                                        0.0,
                                                        G_MAXDOUBLE,
                                                        0.0,
447
                                                        GTK_PARAM_READWRITE));  
Havoc Pennington's avatar
Havoc Pennington committed
448 449 450 451

  g_object_class_install_property (object_class,
                                   PROP_SCALE,
                                   g_param_spec_double ("scale",
452 453
                                                        P_("Font scale"),
                                                        P_("Font scaling factor"),
Havoc Pennington's avatar
Havoc Pennington committed
454 455 456
                                                        0.0,
                                                        G_MAXDOUBLE,
                                                        1.0,
457
                                                        GTK_PARAM_READWRITE));
458 459
  
  g_object_class_install_property (object_class,
460 461
                                   PROP_RISE,
                                   g_param_spec_int ("rise",
462
                                                     P_("Rise"),
463 464
                                                     P_("Offset of text above the baseline "
							"(below the baseline if rise is negative)"),
465 466 467
                                                     -G_MAXINT,
                                                     G_MAXINT,
                                                     0,
468
                                                     GTK_PARAM_READWRITE));
469 470 471 472 473


  g_object_class_install_property (object_class,
                                   PROP_STRIKETHROUGH,
                                   g_param_spec_boolean ("strikethrough",
474 475
                                                         P_("Strikethrough"),
                                                         P_("Whether to strike through the text"),
476
                                                         FALSE,
477
                                                         GTK_PARAM_READWRITE));
478 479
  
  g_object_class_install_property (object_class,
480 481
                                   PROP_UNDERLINE,
                                   g_param_spec_enum ("underline",
482 483
                                                      P_("Underline"),
                                                      P_("Style of underline for this text"),
484 485
                                                      PANGO_TYPE_UNDERLINE,
                                                      PANGO_UNDERLINE_NONE,
486
                                                      GTK_PARAM_READWRITE));
487

488 489 490
  g_object_class_install_property (object_class,
                                   PROP_LANGUAGE,
                                   g_param_spec_string ("language",
491
                                                        P_("Language"),
492 493 494
                                                        P_("The language this text is in, as an ISO code. "
							   "Pango can use this as a hint when rendering the text. "
							   "If you don't understand this parameter, you probably don't need it"),
495
                                                        NULL,
496
                                                        GTK_PARAM_READWRITE));
497 498


499 500 501 502 503 504 505 506 507 508
  /**
   * GtkCellRendererText:ellipsize:
   *
   * Specifies the preferred place to ellipsize the string, if the cell renderer 
   * does not have enough room to display the entire string. Setting it to 
   * %PANGO_ELLIPSIZE_NONE turns off ellipsizing. See the wrap-width property
   * for another way of making the text fit into a given width.
   *
   * Since: 2.6
   */
509 510 511 512
  g_object_class_install_property (object_class,
                                   PROP_ELLIPSIZE,
                                   g_param_spec_enum ("ellipsize",
						      P_("Ellipsize"),
513 514
						      P_("The preferred place to ellipsize the string, "
							 "if the cell renderer does not have enough room "
515
							 "to display the entire string"),
516 517
						      PANGO_TYPE_ELLIPSIZE_MODE,
						      PANGO_ELLIPSIZE_NONE,
518
						      GTK_PARAM_READWRITE));
519 520 521 522 523 524 525 526 527 528 529 530

  /**
   * GtkCellRendererText:width-chars:
   * 
   * The desired width of the cell, in characters. If this property is set to
   * -1, the width will be calculated automatically, otherwise the cell will
   * request either 3 characters or the property value, whichever is greater.
   * 
   * Since: 2.6
   **/
  g_object_class_install_property (object_class,
                                   PROP_WIDTH_CHARS,
Matthias Clasen's avatar
x  
Matthias Clasen committed
531
                                   g_param_spec_int ("width-chars",
532 533 534 535 536
                                                     P_("Width In Characters"),
                                                     P_("The desired width of the label, in characters"),
                                                     -1,
                                                     G_MAXINT,
                                                     -1,
537
                                                     GTK_PARAM_READWRITE));
538
  
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563

  /**
   * GtkCellRendererText:max-width-chars:
   * 
   * The desired maximum width of the cell, in characters. If this property 
   * is set to -1, the width will be calculated automatically.
   *
   * For cell renderers that ellipsize or wrap text; this property
   * controls the maximum reported width of the cell. The
   * cell should not receive any greater allocation unless it is
   * set to expand in its #GtkCellLayout and all of the cell's siblings
   * have received their natural width.
   *
   * Since: 3.0
   **/
  g_object_class_install_property (object_class,
                                   PROP_MAX_WIDTH_CHARS,
                                   g_param_spec_int ("max-width-chars",
                                                     P_("Maximum Width In Characters"),
                                                     P_("The maximum width of the cell, in characters"),
                                                     -1,
                                                     G_MAXINT,
                                                     -1,
                                                     GTK_PARAM_READWRITE));
  
564 565 566
  /**
   * GtkCellRendererText:wrap-mode:
   *
567 568 569
   * Specifies how to break the string into multiple lines, if the cell 
   * renderer does not have enough room to display the entire string. 
   * This property has no effect unless the wrap-width property is set.
570 571 572 573 574
   *
   * Since: 2.8
   */
  g_object_class_install_property (object_class,
                                   PROP_WRAP_MODE,
Matthias Clasen's avatar
x  
Matthias Clasen committed
575
                                   g_param_spec_enum ("wrap-mode",
576 577 578 579 580 581
						      P_("Wrap mode"),
						      P_("How to break the string into multiple lines, "
							 "if the cell renderer does not have enough room "
							 "to display the entire string"),
						      PANGO_TYPE_WRAP_MODE,
						      PANGO_WRAP_CHAR,
582
						      GTK_PARAM_READWRITE));
583 584 585 586

  /**
   * GtkCellRendererText:wrap-width:
   *
587
   * Specifies the minimum width at which the text is wrapped. The wrap-mode property can 
588 589 590 591 592 593 594
   * be used to influence at what character positions the line breaks can be placed.
   * Setting wrap-width to -1 turns wrapping off.
   *
   * Since: 2.8
   */
  g_object_class_install_property (object_class,
				   PROP_WRAP_WIDTH,
Matthias Clasen's avatar
x  
Matthias Clasen committed
595
				   g_param_spec_int ("wrap-width",
596 597 598 599 600
						     P_("Wrap width"),
						     P_("The width at which the text is wrapped"),
						     -1,
						     G_MAXINT,
						     -1,
601
						     GTK_PARAM_READWRITE));
602

603 604 605
  /**
   * GtkCellRendererText:alignment:
   *
606 607 608 609 610
   * Specifies how to align the lines of text with respect to each other. 
   *
   * Note that this property describes how to align the lines of text in 
   * case there are several of them. The "xalign" property of #GtkCellRenderer, 
   * on the other hand, sets the horizontal alignment of the whole text.
611 612 613 614 615 616 617 618 619 620 621
   *
   * Since: 2.10
   */
  g_object_class_install_property (object_class,
                                   PROP_ALIGN,
                                   g_param_spec_enum ("alignment",
						      P_("Alignment"),
						      P_("How to align the lines"),
						      PANGO_TYPE_ALIGNMENT,
						      PANGO_ALIGN_LEFT,
						      GTK_PARAM_READWRITE));
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637

  /**
   * GtkCellRendererText:placeholder-text:
   *
   * The text that will be displayed in the #GtkCellRenderer if
   * #GtkCellRendererText:editable is %TRUE and the cell is empty.
   *
   * Since 3.6
   */
  g_object_class_install_property (object_class,
                                   PROP_PLACEHOLDER_TEXT,
                                   g_param_spec_string ("placeholder-text",
                                                        P_("Placeholder text"),
                                                        P_("Text rendered when an editable cell is empty"),
                                                        NULL,
                                                        GTK_PARAM_READWRITE));
638 639


640 641
  /* Style props are set or not */

642
#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))
643

Matthias Clasen's avatar
x  
Matthias Clasen committed
644
  ADD_SET_PROP ("background-set", PROP_BACKGROUND_SET,
645 646
                P_("Background set"),
                P_("Whether this tag affects the background color"));
647

Matthias Clasen's avatar
x  
Matthias Clasen committed
648
  ADD_SET_PROP ("foreground-set", PROP_FOREGROUND_SET,
649 650
                P_("Foreground set"),
                P_("Whether this tag affects the foreground color"));
651
  
Matthias Clasen's avatar
x  
Matthias Clasen committed
652
  ADD_SET_PROP ("editable-set", PROP_EDITABLE_SET,
653 654
                P_("Editability set"),
                P_("Whether this tag affects text editability"));
655

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

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

Matthias Clasen's avatar
x  
Matthias Clasen committed
664
  ADD_SET_PROP ("variant-set", PROP_VARIANT_SET,
665 666
                P_("Font variant set"),
                P_("Whether this tag affects the font variant"));
667

Matthias Clasen's avatar
x  
Matthias Clasen committed
668
  ADD_SET_PROP ("weight-set", PROP_WEIGHT_SET,
669 670
                P_("Font weight set"),
                P_("Whether this tag affects the font weight"));
671

Matthias Clasen's avatar
x  
Matthias Clasen committed
672
  ADD_SET_PROP ("stretch-set", PROP_STRETCH_SET,
673 674
                P_("Font stretch set"),
                P_("Whether this tag affects the font stretch"));
675

Matthias Clasen's avatar
x  
Matthias Clasen committed
676
  ADD_SET_PROP ("size-set", PROP_SIZE_SET,
677 678
                P_("Font size set"),
                P_("Whether this tag affects the font size"));
679

Matthias Clasen's avatar
x  
Matthias Clasen committed
680
  ADD_SET_PROP ("scale-set", PROP_SCALE_SET,
681 682
                P_("Font scale set"),
                P_("Whether this tag scales the font size by a factor"));
Havoc Pennington's avatar
Havoc Pennington committed
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 ("strikethrough-set", PROP_STRIKETHROUGH_SET,
689 690
                P_("Strikethrough set"),
                P_("Whether this tag affects strikethrough"));
691

Matthias Clasen's avatar
x  
Matthias Clasen committed
692
  ADD_SET_PROP ("underline-set", PROP_UNDERLINE_SET,
693 694
                P_("Underline set"),
                P_("Whether this tag affects underlining"));
695

Matthias Clasen's avatar
x  
Matthias Clasen committed
696
  ADD_SET_PROP ("language-set", PROP_LANGUAGE_SET,
697 698
                P_("Language set"),
                P_("Whether this tag affects the language the text is rendered as"));
699

Matthias Clasen's avatar
x  
Matthias Clasen committed
700
  ADD_SET_PROP ("ellipsize-set", PROP_ELLIPSIZE_SET,
701
                P_("Ellipsize set"),
702
                P_("Whether this tag affects the ellipsize mode"));
703

704 705 706 707
  ADD_SET_PROP ("align-set", PROP_ALIGN_SET,
                P_("Align set"),
                P_("Whether this tag affects the alignment mode"));

708
  /**
709
   * GtkCellRendererText::edited:
710 711 712
   * @renderer: the object which received the signal
   * @path: the path identifying the edited cell
   * @new_text: the new text
713 714
   *
   * This signal is emitted after @renderer has been edited.
715 716 717
   *
   * It is the responsibility of the application to update the model
   * and store @new_text at the position indicated by @path.
718
   */
719
  text_cell_renderer_signals [EDITED] =
720
    g_signal_new (I_("edited"),
Manish Singh's avatar
Manish Singh committed
721 722 723 724 725 726 727 728
		  G_OBJECT_CLASS_TYPE (object_class),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GtkCellRendererTextClass, edited),
		  NULL, NULL,
		  _gtk_marshal_VOID__STRING_STRING,
		  G_TYPE_NONE, 2,
		  G_TYPE_STRING,
		  G_TYPE_STRING);
729

730
  gtk_cell_renderer_class_set_accessible_type (cell_class, GTK_TYPE_TEXT_CELL_ACCESSIBLE);
731 732 733 734 735 736
}

static void
gtk_cell_renderer_text_finalize (GObject *object)
{
  GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object);
737
  GtkCellRendererTextPrivate *priv = celltext->priv;
738

739
  pango_font_description_free (priv->font);
740

741
  g_free (priv->text);
742
  g_free (priv->placeholder_text);
743

744 745
  if (priv->extra_attrs)
    pango_attr_list_unref (priv->extra_attrs);
746

747 748 749
  if (priv->language)
    g_object_unref (priv->language);

750 751
  g_clear_object (&priv->entry);

752
  G_OBJECT_CLASS (gtk_cell_renderer_text_parent_class)->finalize (object);
753 754
}

755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776
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;
}

777
static void
778 779 780
gtk_cell_renderer_text_get_property (GObject        *object,
				     guint           param_id,
				     GValue         *value,
Tim Janik's avatar
Tim Janik committed
781
				     GParamSpec     *pspec)
782 783
{
  GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object);
784
  GtkCellRendererTextPrivate *priv = celltext->priv;
785 786 787 788

  switch (param_id)
    {
    case PROP_TEXT:
789
      g_value_set_string (value, priv->text);
790
      break;
791 792

    case PROP_ATTRIBUTES:
793
      g_value_set_boxed (value, priv->extra_attrs);
794 795
      break;

796 797 798 799
    case PROP_SINGLE_PARAGRAPH_MODE:
      g_value_set_boolean (value, priv->single_paragraph);
      break;

800 801 802
    case PROP_BACKGROUND_GDK:
      {
        GdkColor color;
803 804 805 806 807

        color.red = (guint16) (priv->background.red * 65535);
        color.green = (guint16) (priv->background.green * 65535);
        color.blue = (guint16) (priv->background.blue * 65535);

808 809
        g_value_set_boxed (value, &color);
      }
810
      break;
811 812 813 814

    case PROP_FOREGROUND_GDK:
      {
        GdkColor color;
815 816 817 818 819

        color.red = (guint16) (priv->foreground.red * 65535);
        color.green = (guint16) (priv->foreground.green * 65535);
        color.blue = (guint16) (priv->foreground.blue * 65535);

820 821 822 823
        g_value_set_boxed (value, &color);
      }
      break;

824 825 826 827 828 829 830 831
    case PROP_BACKGROUND_RGBA:
      g_value_set_boxed (value, &priv->background);
      break;

    case PROP_FOREGROUND_RGBA:
      g_value_set_boxed (value, &priv->foreground);
      break;

832
    case PROP_FONT:
833
        g_value_take_string (value, pango_font_description_to_string (priv->font));
834
      break;
835 836
      
    case PROP_FONT_DESC:
837
      g_value_set_boxed (value, priv->font);
838 839 840
      break;

    case PROP_FAMILY:
841
      g_value_set_string (value, pango_font_description_get_family (priv->font));
842 843 844
      break;

    case PROP_STYLE:
845
      g_value_set_enum (value, pango_font_description_get_style (priv->font));
846 847 848
      break;

    case PROP_VARIANT:
849
      g_value_set_enum (value, pango_font_description_get_variant (priv->font));
850 851 852
      break;

    case PROP_WEIGHT:
853
      g_value_set_int (value, pango_font_description_get_weight (priv->font));
854 855 856
      break;

    case PROP_STRETCH:
857
      g_value_set_enum (value, pango_font_description_get_stretch (priv->font));
858 859 860
      break;

    case PROP_SIZE:
861
      g_value_set_int (value, pango_font_description_get_size (priv->font));
862 863 864
      break;

    case PROP_SIZE_POINTS:
865
      g_value_set_double (value, ((double)pango_font_description_get_size (priv->font)) / (double)PANGO_SCALE);
866 867
      break;

Havoc Pennington's avatar
Havoc Pennington committed
868
    case PROP_SCALE:
869
      g_value_set_double (value, priv->font_scale);
Havoc Pennington's avatar
Havoc Pennington committed
870 871
      break;
      
872
    case PROP_EDITABLE:
873
      g_value_set_boolean (value, priv->editable);
874
      break;
875 876

    case PROP_STRIKETHROUGH:
877
      g_value_set_boolean (value, priv->strikethrough);
878 879 880
      break;

    case PROP_UNDERLINE:
881
      g_value_set_enum (value, priv->underline_style);
882 883 884
      break;

    case PROP_RISE:
885
      g_value_set_int (value, priv->rise);
886 887
      break;  

888
    case PROP_LANGUAGE:
889
      g_value_set_static_string (value, pango_language_to_string (priv->language));
890 891
      break;

892 893 894 895
    case PROP_ELLIPSIZE:
      g_value_set_enum (value, priv->ellipsize);
      break;
      
896 897 898 899 900 901 902 903
    case PROP_WRAP_MODE:
      g_value_set_enum (value, priv->wrap_mode);
      break;

    case PROP_WRAP_WIDTH:
      g_value_set_int (value, priv->wrap_width);
      break;
      
904 905 906 907
    case PROP_ALIGN:
      g_value_set_enum (value, priv->align);
      break;

908
    case PROP_BACKGROUND_SET:
909
      g_value_set_boolean (value, priv->background_set);
910 911 912
      break;

    case PROP_FOREGROUND_SET:
913
      g_value_set_boolean (value, priv->foreground_set);
914 915 916 917 918 919 920 921
      break;

    case PROP_FAMILY_SET:
    case PROP_STYLE_SET:
    case PROP_VARIANT_SET:
    case PROP_WEIGHT_SET:
    case PROP_STRETCH_SET:
    case PROP_SIZE_SET:
922 923
      {
	PangoFontMask mask = get_property_font_set_mask (param_id);
924
	g_value_set_boolean (value, (pango_font_description_get_set_fields (priv->font) & mask) != 0);
925 926
	
	break;
927
      }
928

Havoc Pennington's avatar
Havoc Pennington committed
929
    case PROP_SCALE_SET:
930
      g_value_set_boolean (value, priv->scale_set);
Havoc Pennington's avatar
Havoc Pennington committed
931 932
      break;
      
933
    case PROP_EDITABLE_SET:
934
      g_value_set_boolean (value, priv->editable_set);
935 936 937
      break;

    case PROP_STRIKETHROUGH_SET:
938
      g_value_set_boolean (value, priv->strikethrough_set);
939 940 941
      break;

    case PROP_UNDERLINE_SET:
942
      g_value_set_boolean (value, priv->underline_set);
943 944 945
      break;

    case  PROP_RISE_SET:
946
      g_value_set_boolean (value, priv->rise_set);
947
      break;
948 949 950 951

    case PROP_LANGUAGE_SET:
      g_value_set_boolean (value, priv->language_set);
      break;
952 953 954 955

    case PROP_ELLIPSIZE_SET:
      g_value_set_boolean (value, priv->ellipsize_set);
      break;
956 957 958 959

    case PROP_ALIGN_SET:
      g_value_set_boolean (value, priv->align_set);
      break;
960
      
961 962 963 964
    case PROP_WIDTH_CHARS:
      g_value_set_int (value, priv->width_chars);
      break;  

965 966 967 968
    case PROP_MAX_WIDTH_CHARS:
      g_value_set_int (value, priv->max_width_chars);
      break;  

969 970 971 972
    case PROP_PLACEHOLDER_TEXT:
      g_value_set_string (value, priv->placeholder_text);
      break;

973 974
    case PROP_BACKGROUND:
    case PROP_FOREGROUND:
975
    case PROP_MARKUP:
976
    default:
977
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
978 979 980 981 982
      break;
    }
}


983 984
static void
set_bg_color (GtkCellRendererText *celltext,
985
              GdkRGBA             *rgba)
986
{
987
  GtkCellRendererTextPrivate *priv = celltext->priv;
988

989
  if (rgba)
990
    {
991
      if (!priv->background_set)
992
        {
993
          priv->background_set = TRUE;
994
          g_object_notify (G_OBJECT (celltext), "background-set");
995
        }
996 997

      priv->background = *rgba;
998 999 1000
    }
  else
    {
1001
      if (priv->background_set)
1002
        {
1003
          priv->background_set = FALSE;
1004
          g_object_notify (G_OBJECT (celltext), "background-set");
1005 1006 1007 1008 1009 1010 1011
        }
    }
}


static void
set_fg_color (GtkCellRendererText *celltext,
1012
              GdkRGBA             *rgba)
1013
{
1014
  GtkCellRendererTextPrivate *priv = celltext->priv;
1015

1016
  if (rgba)
1017
    {
1018
      if (!priv->foreground_set)
1019
        {
1020
          priv->foreground_set = TRUE;
1021
          g_object_notify (G_OBJECT (celltext), "foreground-set");
1022
        }
1023 1024

      priv->foreground = *rgba;
1025 1026 1027
    }
  else
    {
1028
      if (priv->foreground_set)
1029
        {
1030
          priv->foreground_set = FALSE;
1031
          g_object_notify (G_OBJECT (celltext), "foreground-set");
1032 1033 1034 1035
        }
    }
}

1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075
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;
}

1076 1077 1078 1079 1080
static void
notify_set_changed (GObject       *object,
		    PangoFontMask  changed_mask)
{
  if (changed_mask & PANGO_FONT_MASK_FAMILY)
1081
    g_object_notify (object, "family-set");
1082
  if (changed_mask & PANGO_FONT_MASK_STYLE)
1083
    g_object_notify (object, "style-set");
1084
  if (changed_mask & PANGO_FONT_MASK_VARIANT)
1085
    g_object_notify (object, "variant-set");
1086
  if (changed_mask & PANGO_FONT_MASK_WEIGHT)
1087
    g_object_notify (object, "weight-set");
1088
  if (changed_mask & PANGO_FONT_MASK_STRETCH)
1089
    g_object_notify (object, "stretch-set");
1090
  if (changed_mask & PANGO_FONT_MASK_SIZE)
1091
    g_object_notify (object, "size-set");
1092 1093
}

1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111
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");
}

1112 1113 1114 1115
static void
set_font_description (GtkCellRendererText  *celltext,
                      PangoFontDescription *font_desc)
{
1116
  GtkCellRendererTextPrivate *priv = celltext->priv;
1117 1118 1119 1120 1121 1122
  GObject *object = G_OBJECT (celltext);
  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);
1123
  else
1124 1125
    new_font_desc = pango_font_description_new ();

1126
  old_mask = pango_font_description_get_set_fields (priv->font);
1127 1128 1129 1130 1131
  new_mask = pango_font_description_get_set_fields (new_font_desc);

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

1132 1133
  pango_font_description_free (priv->font);
  priv->font = new_font_desc;
1134 1135 1136
  
  g_object_freeze_notify (object);

1137
  g_object_notify (object, "font-desc");
1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150
  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)
1151
    {
1152
      g_object_notify (object, "size");
1153
      g_object_notify (object, "size-points");
1154
    }
1155 1156 1157 1158

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

1161
static void
1162 1163 1164
gtk_cell_renderer_text_set_property (GObject      *object,
				     guint         param_id,
				     const GValue *value,
Tim Janik's avatar
Tim Janik committed
1165
				     GParamSpec   *pspec)
1166 1167
{
  GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object);
1168
  GtkCellRendererTextPrivate *priv = celltext->priv;
1169 1170 1171 1172

  switch (param_id)
    {
    case PROP_TEXT:
1173
      g_free (priv->text);
1174 1175 1176

      if (priv->markup_set)
        {
1177 1178 1179
          if (priv->extra_attrs)
            pango_attr_list_unref (priv->extra_attrs);
          priv->extra_attrs = NULL;
1180 1181 1182
          priv->markup_set = FALSE;
        }

1183
      priv->text = g_value_dup_string (value);
1184
      g_object_notify (object, "text");
1185
      break;
1186 1187

    case PROP_ATTRIBUTES:
1188 1189
      if (priv->extra_attrs)
	pango_attr_list_unref (priv->extra_attrs);
1190

1191 1192 1193
      priv->extra_attrs = g_value_get_boxed (value);
      if (priv->extra_attrs)
        pango_attr_list_ref (priv->extra_attrs);
1194
      break;
1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210
    case PROP_MARKUP:
      {
	const gchar *str;
	gchar *text = NULL;
	GError *error = NULL;
	PangoAttrList *attrs = NULL;

	str = g_value_get_string (value);
	if (str && !pango_parse_markup (str,
					-1,
					0,
					&attrs,
					&text,
					NULL,
					&error))
	  {
1211
	    g_warning ("Failed to set text from markup due to error parsing markup: %s",
1212 1213 1214 1215
		       error->message);
	    g_error_free (error);
	    return;
	  }
Kristian Rietveld's avatar
Kristian Rietveld committed
1216

1217
	g_free (priv->text);
Kristian Rietveld's avatar
Kristian Rietveld committed
1218

1219 1220
	if (priv->extra_attrs)
	  pango_attr_list_unref (priv->extra_attrs);
Kristian Rietveld's avatar
Kristian Rietveld committed
1221

1222 1223
	priv->text = text;
	priv->extra_attrs = attrs;
1224
        priv->markup_set = TRUE;
1225 1226
      }
      break;
1227 1228 1229 1230

    case PROP_SINGLE_PARAGRAPH_MODE:
      priv->single_paragraph = g_value_get_boolean (value);
      break;
1231
      
1232
    case PROP_BACKGROUND:
1233
      {
1234
        GdkRGBA rgba;
1235

1236
        if (!g_value_get_string (value))
1237
          set_bg_color (celltext, NULL);       /* reset to background_set to FALSE */
1238
        else if (gdk_rgba_parse (&rgba, g_value_get_string (value)))
1239
          set_bg_color (celltext, &rgba);
1240 1241 1242
        else
          g_warning ("Don't know color `%s'", g_value_get_string (value));

1243
        g_object_notify (object, "background-gdk");
1244
      }
1245
      break;
1246
      
1247
    case PROP_FOREGROUND:
1248
      {
1249
        GdkRGBA rgba;
1250

1251 1252
        if (!g_value_get_string (value))
          set_fg_color (celltext, NULL);       /* reset to foreground_set to FALSE */
1253
        else if (gdk_rgba_parse (&rgba, g_value_get_string (value)))
1254
          set_fg_color (celltext, &rgba);
1255 1256 1257
        else
          g_warning ("Don't know color `%s'", g_value_get_string (value));

1258
        g_object_notify (object, "foreground-gdk");
1259 1260 1261 1262
      }
      break;

    case PROP_BACKGROUND_GDK:
1263 1264 1265 1266
      {
        GdkColor *color;

        color = g_value_get_boxed (value);