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

155 156 157
static guint text_cell_renderer_signals [LAST_SIGNAL];

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

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

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

  gchar *text;

  gdouble font_scale;

  gint rise;
  gint fixed_height_rows;
179
  gint width_chars;
180
  gint max_width_chars;
181
  gint wrap_width;
182

183
  guint in_entry_menu     : 1;
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
  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;
203 204
};

205
G_DEFINE_TYPE (GtkCellRendererText, gtk_cell_renderer_text, GTK_TYPE_CELL_RENDERER)
206 207 208 209

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

213 214
  celltext->priv = G_TYPE_INSTANCE_GET_PRIVATE (celltext,
                                                GTK_TYPE_CELL_RENDERER_TEXT,
215
                                                GtkCellRendererTextPrivate);
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
  /* Style props are set or not */

627
#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))
628

Matthias Clasen's avatar
x  
Matthias Clasen committed
629
  ADD_SET_PROP ("background-set", PROP_BACKGROUND_SET,
630 631
                P_("Background set"),
                P_("Whether this tag affects the background color"));
632

Matthias Clasen's avatar
x  
Matthias Clasen committed
633
  ADD_SET_PROP ("foreground-set", PROP_FOREGROUND_SET,
634 635
                P_("Foreground set"),
                P_("Whether this tag affects the foreground color"));
636
  
Matthias Clasen's avatar
x  
Matthias Clasen committed
637
  ADD_SET_PROP ("editable-set", PROP_EDITABLE_SET,
638 639
                P_("Editability set"),
                P_("Whether this tag affects text editability"));
640

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

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

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

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

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

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

Matthias Clasen's avatar
x  
Matthias Clasen committed
665
  ADD_SET_PROP ("scale-set", PROP_SCALE_SET,
666 667
                P_("Font scale set"),
                P_("Whether this tag scales the font size by a factor"));
Havoc Pennington's avatar
Havoc Pennington committed
668
  
Matthias Clasen's avatar
x  
Matthias Clasen committed
669
  ADD_SET_PROP ("rise-set", PROP_RISE_SET,
670 671
                P_("Rise set"),
                P_("Whether this tag affects the rise"));
672

Matthias Clasen's avatar
x  
Matthias Clasen committed
673
  ADD_SET_PROP ("strikethrough-set", PROP_STRIKETHROUGH_SET,
674 675
                P_("Strikethrough set"),
                P_("Whether this tag affects strikethrough"));
676

Matthias Clasen's avatar
x  
Matthias Clasen committed
677
  ADD_SET_PROP ("underline-set", PROP_UNDERLINE_SET,
678 679
                P_("Underline set"),
                P_("Whether this tag affects underlining"));
680

Matthias Clasen's avatar
x  
Matthias Clasen committed
681
  ADD_SET_PROP ("language-set", PROP_LANGUAGE_SET,
682 683
                P_("Language set"),
                P_("Whether this tag affects the language the text is rendered as"));
684

Matthias Clasen's avatar
x  
Matthias Clasen committed
685
  ADD_SET_PROP ("ellipsize-set", PROP_ELLIPSIZE_SET,
686
                P_("Ellipsize set"),
687
                P_("Whether this tag affects the ellipsize mode"));
688

689 690 691 692
  ADD_SET_PROP ("align-set", PROP_ALIGN_SET,
                P_("Align set"),
                P_("Whether this tag affects the alignment mode"));

693
  /**
694
   * GtkCellRendererText::edited:
695 696 697
   * @renderer: the object which received the signal
   * @path: the path identifying the edited cell
   * @new_text: the new text
698 699
   *
   * This signal is emitted after @renderer has been edited.
700 701 702
   *
   * It is the responsibility of the application to update the model
   * and store @new_text at the position indicated by @path.
703
   */
704
  text_cell_renderer_signals [EDITED] =
705
    g_signal_new (I_("edited"),
Manish Singh's avatar
Manish Singh committed
706 707 708 709 710 711 712 713
		  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);
714

715
  g_type_class_add_private (object_class, sizeof (GtkCellRendererTextPrivate));
716 717

  _gtk_cell_renderer_class_set_accessible_type (cell_class, GTK_TYPE_TEXT_CELL_ACCESSIBLE);
718 719 720 721 722 723
}

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

726
  pango_font_description_free (priv->font);
727

728
  g_free (priv->text);
729

730 731
  if (priv->extra_attrs)
    pango_attr_list_unref (priv->extra_attrs);
732

733 734 735
  if (priv->language)
    g_object_unref (priv->language);

736
  G_OBJECT_CLASS (gtk_cell_renderer_text_parent_class)->finalize (object);
737 738
}

739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760
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;
}

761
static void
762 763 764
gtk_cell_renderer_text_get_property (GObject        *object,
				     guint           param_id,
				     GValue         *value,
Tim Janik's avatar
Tim Janik committed
765
				     GParamSpec     *pspec)
766 767
{
  GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object);
768
  GtkCellRendererTextPrivate *priv = celltext->priv;
769 770 771 772

  switch (param_id)
    {
    case PROP_TEXT:
773
      g_value_set_string (value, priv->text);
774
      break;
775 776

    case PROP_ATTRIBUTES:
777
      g_value_set_boxed (value, priv->extra_attrs);
778 779
      break;

780 781 782 783
    case PROP_SINGLE_PARAGRAPH_MODE:
      g_value_set_boolean (value, priv->single_paragraph);
      break;

784 785 786
    case PROP_BACKGROUND_GDK:
      {
        GdkColor color;
787 788 789 790 791

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

792 793
        g_value_set_boxed (value, &color);
      }
794
      break;
795 796 797 798

    case PROP_FOREGROUND_GDK:
      {
        GdkColor color;
799 800 801 802 803

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

804 805 806 807
        g_value_set_boxed (value, &color);
      }
      break;

808 809 810 811 812 813 814 815
    case PROP_BACKGROUND_RGBA:
      g_value_set_boxed (value, &priv->background);
      break;

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

816
    case PROP_FONT:
817
        g_value_take_string (value, pango_font_description_to_string (priv->font));
818
      break;
819 820
      
    case PROP_FONT_DESC:
821
      g_value_set_boxed (value, priv->font);
822 823 824
      break;

    case PROP_FAMILY:
825
      g_value_set_string (value, pango_font_description_get_family (priv->font));
826 827 828
      break;

    case PROP_STYLE:
829
      g_value_set_enum (value, pango_font_description_get_style (priv->font));
830 831 832
      break;

    case PROP_VARIANT:
833
      g_value_set_enum (value, pango_font_description_get_variant (priv->font));
834 835 836
      break;

    case PROP_WEIGHT:
837
      g_value_set_int (value, pango_font_description_get_weight (priv->font));
838 839 840
      break;

    case PROP_STRETCH:
841
      g_value_set_enum (value, pango_font_description_get_stretch (priv->font));
842 843 844
      break;

    case PROP_SIZE:
845
      g_value_set_int (value, pango_font_description_get_size (priv->font));
846 847 848
      break;

    case PROP_SIZE_POINTS:
849
      g_value_set_double (value, ((double)pango_font_description_get_size (priv->font)) / (double)PANGO_SCALE);
850 851
      break;

Havoc Pennington's avatar
Havoc Pennington committed
852
    case PROP_SCALE:
853
      g_value_set_double (value, priv->font_scale);
Havoc Pennington's avatar
Havoc Pennington committed
854 855
      break;
      
856
    case PROP_EDITABLE:
857
      g_value_set_boolean (value, priv->editable);
858
      break;
859 860

    case PROP_STRIKETHROUGH:
861
      g_value_set_boolean (value, priv->strikethrough);
862 863 864
      break;

    case PROP_UNDERLINE:
865
      g_value_set_enum (value, priv->underline_style);
866 867 868
      break;

    case PROP_RISE:
869
      g_value_set_int (value, priv->rise);
870 871
      break;  

872
    case PROP_LANGUAGE:
873
      g_value_set_static_string (value, pango_language_to_string (priv->language));
874 875
      break;

876 877 878 879
    case PROP_ELLIPSIZE:
      g_value_set_enum (value, priv->ellipsize);
      break;
      
880 881 882 883 884 885 886 887
    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;
      
888 889 890 891
    case PROP_ALIGN:
      g_value_set_enum (value, priv->align);
      break;

892
    case PROP_BACKGROUND_SET:
893
      g_value_set_boolean (value, priv->background_set);
894 895 896
      break;

    case PROP_FOREGROUND_SET:
897
      g_value_set_boolean (value, priv->foreground_set);
898 899 900 901 902 903 904 905
      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:
906 907
      {
	PangoFontMask mask = get_property_font_set_mask (param_id);
908
	g_value_set_boolean (value, (pango_font_description_get_set_fields (priv->font) & mask) != 0);
909 910
	
	break;
911
      }
912

Havoc Pennington's avatar
Havoc Pennington committed
913
    case PROP_SCALE_SET:
914
      g_value_set_boolean (value, priv->scale_set);
Havoc Pennington's avatar
Havoc Pennington committed
915 916
      break;
      
917
    case PROP_EDITABLE_SET:
918
      g_value_set_boolean (value, priv->editable_set);
919 920 921
      break;

    case PROP_STRIKETHROUGH_SET:
922
      g_value_set_boolean (value, priv->strikethrough_set);
923 924 925
      break;

    case PROP_UNDERLINE_SET:
926
      g_value_set_boolean (value, priv->underline_set);
927 928 929
      break;

    case  PROP_RISE_SET:
930
      g_value_set_boolean (value, priv->rise_set);
931
      break;
932 933 934 935

    case PROP_LANGUAGE_SET:
      g_value_set_boolean (value, priv->language_set);
      break;
936 937 938 939

    case PROP_ELLIPSIZE_SET:
      g_value_set_boolean (value, priv->ellipsize_set);
      break;
940 941 942 943

    case PROP_ALIGN_SET:
      g_value_set_boolean (value, priv->align_set);
      break;
944
      
945 946 947 948
    case PROP_WIDTH_CHARS:
      g_value_set_int (value, priv->width_chars);
      break;  

949 950 951 952
    case PROP_MAX_WIDTH_CHARS:
      g_value_set_int (value, priv->max_width_chars);
      break;  

953 954
    case PROP_BACKGROUND:
    case PROP_FOREGROUND:
955
    case PROP_MARKUP:
956
    default:
957
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
958 959 960 961 962
      break;
    }
}


963 964
static void
set_bg_color (GtkCellRendererText *celltext,
965
              GdkRGBA             *rgba)
966
{
967
  GtkCellRendererTextPrivate *priv = celltext->priv;
968

969
  if (rgba)
970
    {
971
      if (!priv->background_set)
972
        {
973
          priv->background_set = TRUE;
974
          g_object_notify (G_OBJECT (celltext), "background-set");
975
        }
976 977

      priv->background = *rgba;
978 979 980
    }
  else
    {
981
      if (priv->background_set)
982
        {
983
          priv->background_set = FALSE;
984
          g_object_notify (G_OBJECT (celltext), "background-set");
985 986 987 988 989 990 991
        }
    }
}


static void
set_fg_color (GtkCellRendererText *celltext,
992
              GdkRGBA             *rgba)
993
{
994
  GtkCellRendererTextPrivate *priv = celltext->priv;
995

996
  if (rgba)
997
    {
998
      if (!priv->foreground_set)
999
        {
1000
          priv->foreground_set = TRUE;
1001
          g_object_notify (G_OBJECT (celltext), "foreground-set");
1002
        }
1003 1004

      priv->foreground = *rgba;
1005 1006 1007
    }
  else
    {
1008
      if (priv->foreground_set)
1009
        {
1010
          priv->foreground_set = FALSE;
1011
          g_object_notify (G_OBJECT (celltext), "foreground-set");
1012 1013 1014 1015
        }
    }
}

1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055
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;
}

1056 1057 1058 1059 1060
static void
notify_set_changed (GObject       *object,
		    PangoFontMask  changed_mask)
{
  if (changed_mask & PANGO_FONT_MASK_FAMILY)
1061
    g_object_notify (object, "family-set");
1062
  if (changed_mask & PANGO_FONT_MASK_STYLE)
1063
    g_object_notify (object, "style-set");
1064
  if (changed_mask & PANGO_FONT_MASK_VARIANT)
1065
    g_object_notify (object, "variant-set");
1066
  if (changed_mask & PANGO_FONT_MASK_WEIGHT)
1067
    g_object_notify (object, "weight-set");
1068
  if (changed_mask & PANGO_FONT_MASK_STRETCH)
1069
    g_object_notify (object, "stretch-set");
1070
  if (changed_mask & PANGO_FONT_MASK_SIZE)
1071
    g_object_notify (object, "size-set");
1072 1073
}

1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091
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");
}

1092 1093 1094 1095
static void
set_font_description (GtkCellRendererText  *celltext,
                      PangoFontDescription *font_desc)
{
1096
  GtkCellRendererTextPrivate *priv = celltext->priv;
1097 1098 1099 1100 1101 1102
  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);
1103
  else
1104 1105
    new_font_desc = pango_font_description_new ();

1106
  old_mask = pango_font_description_get_set_fields (priv->font);
1107 1108 1109 1110 1111
  new_mask = pango_font_description_get_set_fields (new_font_desc);

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

1112 1113
  pango_font_description_free (priv->font);
  priv->font = new_font_desc;
1114 1115 1116
  
  g_object_freeze_notify (object);

1117
  g_object_notify (object, "font-desc");
1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130
  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)
1131
    {
1132
      g_object_notify (object, "size");
1133
      g_object_notify (object, "size-points");
1134
    }
1135 1136 1137 1138

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

1141
static void
1142 1143 1144
gtk_cell_renderer_text_set_property (GObject      *object,
				     guint         param_id,
				     const GValue *value,
Tim Janik's avatar
Tim Janik committed
1145
				     GParamSpec   *pspec)
1146 1147
{
  GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object);
1148
  GtkCellRendererTextPrivate *priv = celltext->priv;
1149 1150 1151 1152

  switch (param_id)
    {
    case PROP_TEXT:
1153
      g_free (priv->text);
1154 1155 1156

      if (priv->markup_set)
        {
1157 1158 1159
          if (priv->extra_attrs)
            pango_attr_list_unref (priv->extra_attrs);
          priv->extra_attrs = NULL;
1160 1161 1162
          priv->markup_set = FALSE;
        }

1163
      priv->text = g_value_dup_string (value);
1164
      g_object_notify (object, "text");
1165
      break;
1166 1167

    case PROP_ATTRIBUTES:
1168 1169
      if (priv->extra_attrs)
	pango_attr_list_unref (priv->extra_attrs);
1170

1171 1172 1173
      priv->extra_attrs = g_value_get_boxed (value);
      if (priv->extra_attrs)
        pango_attr_list_ref (priv->extra_attrs);
1174
      break;
1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190
    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))
	  {
1191
	    g_warning ("Failed to set text from markup due to error parsing markup: %s",
1192 1193 1194 1195
		       error->message);
	    g_error_free (error);
	    return;
	  }
Kristian Rietveld's avatar
Kristian Rietveld committed
1196

1197
	g_free (priv->text);
Kristian Rietveld's avatar
Kristian Rietveld committed
1198

1199 1200
	if (priv->extra_attrs)
	  pango_attr_list_unref (priv->extra_attrs);
Kristian Rietveld's avatar
Kristian Rietveld committed
1201

1202 1203
	priv->text = text;
	priv->extra_attrs = attrs;
1204
        priv->markup_set = TRUE;
1205 1206
      }
      break;
1207 1208 1209 1210

    case PROP_SINGLE_PARAGRAPH_MODE:
      priv->single_paragraph = g_value_get_boolean (value);
      break;
1211
      
1212
    case PROP_BACKGROUND:
1213
      {
1214
        GdkRGBA rgba;
1215

1216
        if (!g_value_get_string (value))
1217
          set_bg_color (celltext, NULL);       /* reset to background_set to FALSE */
1218
        else if (gdk_rgba_parse (&rgba, g_value_get_string (value)))
1219
          set_bg_color (celltext, &rgba);
1220 1221 1222
        else
          g_warning ("Don't know color `%s'", g_value_get_string (value));

1223
        g_object_notify (object, "background-gdk");
1224
      }
1225
      break;
1226
      
1227
    case PROP_FOREGROUND:
1228
      {
1229
        GdkRGBA rgba;
1230

1231 1232
        if (!g_value_get_string (value))
          set_fg_color (celltext, NULL);       /* reset to foreground_set to FALSE */
1233
        else if (gdk_rgba_parse (&rgba, g_value_get_string (value)))
1234
          set_fg_color (celltext, &rgba);
1235 1236 1237
        else
          g_warning ("Don't know color `%s'", g_value_get_string (value));

1238
        g_object_notify (object, "foreground-gdk");
1239 1240 1241 1242
      }
      break;

    case PROP_BACKGROUND_GDK:
1243 1244 1245 1246
      {
        GdkColor *color;

        color = g_value_get_boxed (value);
1247 1248 1249 1250 1251 1252 1253 1254
        if (color)
          {
            GdkRGBA rgba;

            rgba.red = color->red / 65535.;
            rgba.green = color->green / 65535.;
            rgba.blue = color->blue / 65535.;
            rgba.alpha = 1;
1255

1256 1257 1258 1259 1260 1261
            set_bg_color (celltext, &rgba);
          }
        else
          {
            set_bg_color (celltext, NULL);
          }
1262 1263 1264 1265 1266 1267 1268 1269
      }
      bre