gtkcellrenderertext.c 60.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/* 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
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

20
#include <config.h>
21 22
#include <stdlib.h>
#include "gtkcellrenderertext.h"
23 24
#include "gtkeditable.h"
#include "gtkentry.h"
25
#include "gtkmarshalers.h"
26
#include "gtkintl.h"
27
#include "gtkprivate.h"
28
#include "gtktreeprivate.h"
29
#include "gtkalias.h"
30

Havoc Pennington's avatar
Havoc Pennington committed
31
static void gtk_cell_renderer_text_finalize   (GObject                  *object);
32

33 34 35
static void gtk_cell_renderer_text_get_property  (GObject                  *object,
						  guint                     param_id,
						  GValue                   *value,
Tim Janik's avatar
Tim Janik committed
36
						  GParamSpec               *pspec);
37 38 39
static void gtk_cell_renderer_text_set_property  (GObject                  *object,
						  guint                     param_id,
						  const GValue             *value,
Tim Janik's avatar
Tim Janik committed
40
						  GParamSpec               *pspec);
41 42
static void gtk_cell_renderer_text_get_size   (GtkCellRenderer          *cell,
					       GtkWidget                *widget,
43 44 45
					       GdkRectangle             *cell_area,
					       gint                     *x_offset,
					       gint                     *y_offset,
46 47 48 49 50 51 52 53
					       gint                     *width,
					       gint                     *height);
static void gtk_cell_renderer_text_render     (GtkCellRenderer          *cell,
					       GdkWindow                *window,
					       GtkWidget                *widget,
					       GdkRectangle             *background_area,
					       GdkRectangle             *cell_area,
					       GdkRectangle             *expose_area,
54
					       GtkCellRendererState      flags);
55

56 57 58
static GtkCellEditable *gtk_cell_renderer_text_start_editing (GtkCellRenderer      *cell,
							      GdkEvent             *event,
							      GtkWidget            *widget,
59
							      const gchar          *path,
60 61 62
							      GdkRectangle         *background_area,
							      GdkRectangle         *cell_area,
							      GtkCellRendererState  flags);
63

64 65 66 67
enum {
  EDITED,
  LAST_SIGNAL
};
Havoc Pennington's avatar
Havoc Pennington committed
68

69
enum {
Havoc Pennington's avatar
Havoc Pennington committed
70 71
  PROP_0,

72
  PROP_TEXT,
Alexander Larsson's avatar
Alexander Larsson committed
73
  PROP_MARKUP,
74
  PROP_ATTRIBUTES,
75
  PROP_SINGLE_PARAGRAPH_MODE,
76
  PROP_WIDTH_CHARS,
77
  PROP_WRAP_WIDTH,
78
  PROP_ALIGN,
Havoc Pennington's avatar
Havoc Pennington committed
79 80
  
  /* Style args */
81 82
  PROP_BACKGROUND,
  PROP_FOREGROUND,
Havoc Pennington's avatar
Havoc Pennington committed
83
  PROP_BACKGROUND_GDK,
84
  PROP_FOREGROUND_GDK,
Havoc Pennington's avatar
Havoc Pennington committed
85 86 87 88 89 90 91 92 93
  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
94
  PROP_SCALE,
Havoc Pennington's avatar
Havoc Pennington committed
95
  PROP_EDITABLE,
96 97
  PROP_STRIKETHROUGH,
  PROP_UNDERLINE,
Havoc Pennington's avatar
Havoc Pennington committed
98
  PROP_RISE,
99
  PROP_LANGUAGE,
100
  PROP_ELLIPSIZE,
101
  PROP_WRAP_MODE,
Havoc Pennington's avatar
Havoc Pennington committed
102 103 104 105 106 107 108 109 110 111
  
  /* 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
112
  PROP_SCALE_SET,
Havoc Pennington's avatar
Havoc Pennington committed
113 114 115
  PROP_EDITABLE_SET,
  PROP_STRIKETHROUGH_SET,
  PROP_UNDERLINE_SET,
116
  PROP_RISE_SET,
117
  PROP_LANGUAGE_SET,
118 119
  PROP_ELLIPSIZE_SET,
  PROP_ALIGN_SET
120 121
};

122 123 124
static guint text_cell_renderer_signals [LAST_SIGNAL];

#define GTK_CELL_RENDERER_TEXT_PATH "gtk-cell-renderer-text-path"
Havoc Pennington's avatar
Havoc Pennington committed
125

126 127 128 129 130 131
#define GTK_CELL_RENDERER_TEXT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_CELL_RENDERER_TEXT, GtkCellRendererTextPrivate))

typedef struct _GtkCellRendererTextPrivate GtkCellRendererTextPrivate;
struct _GtkCellRendererTextPrivate
{
  guint single_paragraph : 1;
132
  guint language_set : 1;
133
  guint markup_set : 1;
134
  guint ellipsize_set : 1;
135
  guint align_set : 1;
136
  
137
  gulong focus_out_id;
138
  PangoLanguage *language;
139
  PangoEllipsizeMode ellipsize;
140
  PangoWrapMode wrap_mode;
141
  PangoAlignment align;
142
  
143 144 145
  gulong populate_popup_id;
  gulong entry_menu_popdown_timeout;
  gboolean in_entry_menu;
146 147
  
  gint width_chars;
148
  gint wrap_width;
149
  
150
  GtkWidget *entry;
151 152
};

Matthias Clasen's avatar
Matthias Clasen committed
153
G_DEFINE_TYPE (GtkCellRendererText, gtk_cell_renderer_text, GTK_TYPE_CELL_RENDERER)
154 155 156 157

static void
gtk_cell_renderer_text_init (GtkCellRendererText *celltext)
{
158 159 160 161
  GtkCellRendererTextPrivate *priv;

  priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (celltext);

162 163 164 165
  GTK_CELL_RENDERER (celltext)->xalign = 0.0;
  GTK_CELL_RENDERER (celltext)->yalign = 0.5;
  GTK_CELL_RENDERER (celltext)->xpad = 2;
  GTK_CELL_RENDERER (celltext)->ypad = 2;
166
  celltext->font_scale = 1.0;
167
  celltext->fixed_height_rows = -1;
168
  celltext->font = pango_font_description_new ();
169 170

  priv->width_chars = -1;
171
  priv->wrap_width = -1;
172
  priv->wrap_mode = PANGO_WRAP_CHAR;
173
  priv->align = PANGO_ALIGN_LEFT;
174
  priv->align_set = FALSE;
175 176 177 178 179 180 181 182
}

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);

Havoc Pennington's avatar
Havoc Pennington committed
183 184
  object_class->finalize = gtk_cell_renderer_text_finalize;
  
185 186
  object_class->get_property = gtk_cell_renderer_text_get_property;
  object_class->set_property = gtk_cell_renderer_text_set_property;
187 188 189

  cell_class->get_size = gtk_cell_renderer_text_get_size;
  cell_class->render = gtk_cell_renderer_text_render;
190
  cell_class->start_editing = gtk_cell_renderer_text_start_editing;
191

192
  g_object_class_install_property (object_class,
Havoc Pennington's avatar
Havoc Pennington committed
193 194
                                   PROP_TEXT,
                                   g_param_spec_string ("text",
195 196
                                                        P_("Text"),
                                                        P_("Text to render"),
Havoc Pennington's avatar
Havoc Pennington committed
197
                                                        NULL,
198
                                                        GTK_PARAM_READWRITE));
199
  
Alexander Larsson's avatar
Alexander Larsson committed
200 201 202
  g_object_class_install_property (object_class,
                                   PROP_MARKUP,
                                   g_param_spec_string ("markup",
203 204
                                                        P_("Markup"),
                                                        P_("Marked up text to render"),
Alexander Larsson's avatar
Alexander Larsson committed
205
                                                        NULL,
206
                                                        GTK_PARAM_WRITABLE));
207

208
  g_object_class_install_property (object_class,
209 210
				   PROP_ATTRIBUTES,
				   g_param_spec_boxed ("attributes",
211 212
						       P_("Attributes"),
						       P_("A list of style attributes to apply to the text of the renderer"),
213
						       PANGO_TYPE_ATTR_LIST,
214
						       GTK_PARAM_READWRITE));
215 216 217

  g_object_class_install_property (object_class,
                                   PROP_SINGLE_PARAGRAPH_MODE,
Matthias Clasen's avatar
x  
Matthias Clasen committed
218
                                   g_param_spec_boolean ("single-paragraph-mode",
219 220
                                                         P_("Single Paragraph Mode"),
                                                         P_("Whether or not to keep all text in a single paragraph"),
221
                                                         FALSE,
222
                                                         GTK_PARAM_READWRITE));
223

Alexander Larsson's avatar
Alexander Larsson committed
224
  
225
  g_object_class_install_property (object_class,
Havoc Pennington's avatar
Havoc Pennington committed
226 227
                                   PROP_BACKGROUND,
                                   g_param_spec_string ("background",
228 229
                                                        P_("Background color name"),
                                                        P_("Background color as a string"),
Havoc Pennington's avatar
Havoc Pennington committed
230
                                                        NULL,
231
                                                        GTK_PARAM_WRITABLE));
Havoc Pennington's avatar
Havoc Pennington committed
232 233 234

  g_object_class_install_property (object_class,
                                   PROP_BACKGROUND_GDK,
Matthias Clasen's avatar
x  
Matthias Clasen committed
235
                                   g_param_spec_boxed ("background-gdk",
236 237
                                                       P_("Background color"),
                                                       P_("Background color as a GdkColor"),
238
                                                       GDK_TYPE_COLOR,
239
                                                       GTK_PARAM_READWRITE));  
Havoc Pennington's avatar
Havoc Pennington committed
240 241 242 243

  g_object_class_install_property (object_class,
                                   PROP_FOREGROUND,
                                   g_param_spec_string ("foreground",
244 245
                                                        P_("Foreground color name"),
                                                        P_("Foreground color as a string"),
Havoc Pennington's avatar
Havoc Pennington committed
246
                                                        NULL,
247
                                                        GTK_PARAM_WRITABLE));
Havoc Pennington's avatar
Havoc Pennington committed
248 249 250

  g_object_class_install_property (object_class,
                                   PROP_FOREGROUND_GDK,
Matthias Clasen's avatar
x  
Matthias Clasen committed
251
                                   g_param_spec_boxed ("foreground-gdk",
252 253
                                                       P_("Foreground color"),
                                                       P_("Foreground color as a GdkColor"),
254
                                                       GDK_TYPE_COLOR,
255
                                                       GTK_PARAM_READWRITE));
Havoc Pennington's avatar
Havoc Pennington committed
256 257 258 259 260


  g_object_class_install_property (object_class,
                                   PROP_EDITABLE,
                                   g_param_spec_boolean ("editable",
261 262
                                                         P_("Editable"),
                                                         P_("Whether the text can be modified by the user"),
Kristian Rietveld's avatar
Kristian Rietveld committed
263
                                                         FALSE,
264
                                                         GTK_PARAM_READWRITE));
Havoc Pennington's avatar
Havoc Pennington committed
265 266 267 268

  g_object_class_install_property (object_class,
                                   PROP_FONT,
                                   g_param_spec_string ("font",
269
                                                        P_("Font"),
270
                                                        P_("Font description as a string, e.g. \"Sans Italic 12\""),
Havoc Pennington's avatar
Havoc Pennington committed
271
                                                        NULL,
272
                                                        GTK_PARAM_READWRITE));
Havoc Pennington's avatar
Havoc Pennington committed
273

274
  g_object_class_install_property (object_class,
Havoc Pennington's avatar
Havoc Pennington committed
275
                                   PROP_FONT_DESC,
Matthias Clasen's avatar
x  
Matthias Clasen committed
276
                                   g_param_spec_boxed ("font-desc",
277 278
                                                       P_("Font"),
                                                       P_("Font description as a PangoFontDescription struct"),
279
                                                       PANGO_TYPE_FONT_DESCRIPTION,
280
                                                       GTK_PARAM_READWRITE));
Havoc Pennington's avatar
Havoc Pennington committed
281

282 283
  
  g_object_class_install_property (object_class,
Havoc Pennington's avatar
Havoc Pennington committed
284 285
                                   PROP_FAMILY,
                                   g_param_spec_string ("family",
286 287
                                                        P_("Font family"),
                                                        P_("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
Havoc Pennington's avatar
Havoc Pennington committed
288
                                                        NULL,
289
                                                        GTK_PARAM_READWRITE));
Havoc Pennington's avatar
Havoc Pennington committed
290 291 292 293

  g_object_class_install_property (object_class,
                                   PROP_STYLE,
                                   g_param_spec_enum ("style",
294 295
                                                      P_("Font style"),
                                                      P_("Font style"),
Havoc Pennington's avatar
Havoc Pennington committed
296 297
                                                      PANGO_TYPE_STYLE,
                                                      PANGO_STYLE_NORMAL,
298
                                                      GTK_PARAM_READWRITE));
Havoc Pennington's avatar
Havoc Pennington committed
299 300 301 302

  g_object_class_install_property (object_class,
                                   PROP_VARIANT,
                                   g_param_spec_enum ("variant",
303 304
                                                     P_("Font variant"),
                                                     P_("Font variant"),
Havoc Pennington's avatar
Havoc Pennington committed
305 306
                                                      PANGO_TYPE_VARIANT,
                                                      PANGO_VARIANT_NORMAL,
307
                                                      GTK_PARAM_READWRITE));
308 309
  
  g_object_class_install_property (object_class,
Havoc Pennington's avatar
Havoc Pennington committed
310
                                   PROP_WEIGHT,
CEST's avatar
-)  
CEST committed
311
                                   g_param_spec_int ("weight",
312 313
                                                     P_("Font weight"),
                                                     P_("Font weight"),
CEST's avatar
-)  
CEST committed
314 315
                                                     0,
                                                     G_MAXINT,
Havoc Pennington's avatar
Havoc Pennington committed
316
                                                     PANGO_WEIGHT_NORMAL,
317
                                                     GTK_PARAM_READWRITE));
Havoc Pennington's avatar
Havoc Pennington committed
318

CEST's avatar
-)  
CEST committed
319
   g_object_class_install_property (object_class,
Havoc Pennington's avatar
Havoc Pennington committed
320 321
                                   PROP_STRETCH,
                                   g_param_spec_enum ("stretch",
322 323
                                                      P_("Font stretch"),
                                                      P_("Font stretch"),
Havoc Pennington's avatar
Havoc Pennington committed
324 325
                                                      PANGO_TYPE_STRETCH,
                                                      PANGO_STRETCH_NORMAL,
326
                                                      GTK_PARAM_READWRITE));
327 328
  
  g_object_class_install_property (object_class,
Havoc Pennington's avatar
Havoc Pennington committed
329 330
                                   PROP_SIZE,
                                   g_param_spec_int ("size",
331 332
                                                     P_("Font size"),
                                                     P_("Font size"),
Havoc Pennington's avatar
Havoc Pennington committed
333 334 335
                                                     0,
                                                     G_MAXINT,
                                                     0,
336
                                                     GTK_PARAM_READWRITE));
Havoc Pennington's avatar
Havoc Pennington committed
337 338 339

  g_object_class_install_property (object_class,
                                   PROP_SIZE_POINTS,
Matthias Clasen's avatar
x  
Matthias Clasen committed
340
                                   g_param_spec_double ("size-points",
341 342
                                                        P_("Font points"),
                                                        P_("Font size in points"),
Havoc Pennington's avatar
Havoc Pennington committed
343 344 345
                                                        0.0,
                                                        G_MAXDOUBLE,
                                                        0.0,
346
                                                        GTK_PARAM_READWRITE));  
Havoc Pennington's avatar
Havoc Pennington committed
347 348 349 350

  g_object_class_install_property (object_class,
                                   PROP_SCALE,
                                   g_param_spec_double ("scale",
351 352
                                                        P_("Font scale"),
                                                        P_("Font scaling factor"),
Havoc Pennington's avatar
Havoc Pennington committed
353 354 355
                                                        0.0,
                                                        G_MAXDOUBLE,
                                                        1.0,
356
                                                        GTK_PARAM_READWRITE));
357 358
  
  g_object_class_install_property (object_class,
Havoc Pennington's avatar
Havoc Pennington committed
359 360
                                   PROP_RISE,
                                   g_param_spec_int ("rise",
361
                                                     P_("Rise"),
362 363
                                                     P_("Offset of text above the baseline "
							"(below the baseline if rise is negative)"),
Havoc Pennington's avatar
Havoc Pennington committed
364 365 366
                                                     -G_MAXINT,
                                                     G_MAXINT,
                                                     0,
367
                                                     GTK_PARAM_READWRITE));
Havoc Pennington's avatar
Havoc Pennington committed
368 369 370 371 372


  g_object_class_install_property (object_class,
                                   PROP_STRIKETHROUGH,
                                   g_param_spec_boolean ("strikethrough",
373 374
                                                         P_("Strikethrough"),
                                                         P_("Whether to strike through the text"),
Havoc Pennington's avatar
Havoc Pennington committed
375
                                                         FALSE,
376
                                                         GTK_PARAM_READWRITE));
377 378
  
  g_object_class_install_property (object_class,
Havoc Pennington's avatar
Havoc Pennington committed
379 380
                                   PROP_UNDERLINE,
                                   g_param_spec_enum ("underline",
381 382
                                                      P_("Underline"),
                                                      P_("Style of underline for this text"),
Havoc Pennington's avatar
Havoc Pennington committed
383 384
                                                      PANGO_TYPE_UNDERLINE,
                                                      PANGO_UNDERLINE_NONE,
385
                                                      GTK_PARAM_READWRITE));
Havoc Pennington's avatar
Havoc Pennington committed
386

387 388 389
  g_object_class_install_property (object_class,
                                   PROP_LANGUAGE,
                                   g_param_spec_string ("language",
390
                                                        P_("Language"),
391 392 393
                                                        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"),
394
                                                        NULL,
395
                                                        GTK_PARAM_READWRITE));
396 397


398 399 400 401 402 403 404 405 406 407
  /**
   * 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
   */
408 409 410 411
  g_object_class_install_property (object_class,
                                   PROP_ELLIPSIZE,
                                   g_param_spec_enum ("ellipsize",
						      P_("Ellipsize"),
412 413
						      P_("The preferred place to ellipsize the string, "
							 "if the cell renderer does not have enough room "
414
							 "to display the entire string"),
415 416
						      PANGO_TYPE_ELLIPSIZE_MODE,
						      PANGO_ELLIPSIZE_NONE,
417
						      GTK_PARAM_READWRITE));
418 419 420 421 422 423 424 425 426 427 428 429

  /**
   * 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
430
                                   g_param_spec_int ("width-chars",
431 432 433 434 435
                                                     P_("Width In Characters"),
                                                     P_("The desired width of the label, in characters"),
                                                     -1,
                                                     G_MAXINT,
                                                     -1,
436
                                                     GTK_PARAM_READWRITE));
437
  
438 439 440
  /**
   * GtkCellRendererText:wrap-mode:
   *
441 442 443
   * 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.
444 445 446 447 448
   *
   * Since: 2.8
   */
  g_object_class_install_property (object_class,
                                   PROP_WRAP_MODE,
Matthias Clasen's avatar
x  
Matthias Clasen committed
449
                                   g_param_spec_enum ("wrap-mode",
450 451 452 453 454 455
						      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,
456
						      GTK_PARAM_READWRITE));
457 458 459 460 461 462 463 464 465 466 467 468

  /**
   * GtkCellRendererText:wrap-width:
   *
   * Specifies the width at which the text is wrapped. The wrap-mode property can 
   * 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
469
				   g_param_spec_int ("wrap-width",
470 471 472 473 474
						     P_("Wrap width"),
						     P_("The width at which the text is wrapped"),
						     -1,
						     G_MAXINT,
						     -1,
475
						     GTK_PARAM_READWRITE));
476

477 478 479
  /**
   * GtkCellRendererText:alignment:
   *
480 481 482 483 484
   * 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.
485 486 487 488 489 490 491 492 493 494 495
   *
   * 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));
496
  
Havoc Pennington's avatar
Havoc Pennington committed
497 498
  /* Style props are set or not */

499
#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))
Havoc Pennington's avatar
Havoc Pennington committed
500

Matthias Clasen's avatar
x  
Matthias Clasen committed
501
  ADD_SET_PROP ("background-set", PROP_BACKGROUND_SET,
502 503
                P_("Background set"),
                P_("Whether this tag affects the background color"));
Havoc Pennington's avatar
Havoc Pennington committed
504

Matthias Clasen's avatar
x  
Matthias Clasen committed
505
  ADD_SET_PROP ("foreground-set", PROP_FOREGROUND_SET,
506 507
                P_("Foreground set"),
                P_("Whether this tag affects the foreground color"));
Havoc Pennington's avatar
Havoc Pennington committed
508
  
Matthias Clasen's avatar
x  
Matthias Clasen committed
509
  ADD_SET_PROP ("editable-set", PROP_EDITABLE_SET,
510 511
                P_("Editability set"),
                P_("Whether this tag affects text editability"));
Havoc Pennington's avatar
Havoc Pennington committed
512

Matthias Clasen's avatar
x  
Matthias Clasen committed
513
  ADD_SET_PROP ("family-set", PROP_FAMILY_SET,
514 515
                P_("Font family set"),
                P_("Whether this tag affects the font family"));  
Havoc Pennington's avatar
Havoc Pennington committed
516

Matthias Clasen's avatar
x  
Matthias Clasen committed
517
  ADD_SET_PROP ("style-set", PROP_STYLE_SET,
518 519
                P_("Font style set"),
                P_("Whether this tag affects the font style"));
Havoc Pennington's avatar
Havoc Pennington committed
520

Matthias Clasen's avatar
x  
Matthias Clasen committed
521
  ADD_SET_PROP ("variant-set", PROP_VARIANT_SET,
522 523
                P_("Font variant set"),
                P_("Whether this tag affects the font variant"));
Havoc Pennington's avatar
Havoc Pennington committed
524

Matthias Clasen's avatar
x  
Matthias Clasen committed
525
  ADD_SET_PROP ("weight-set", PROP_WEIGHT_SET,
526 527
                P_("Font weight set"),
                P_("Whether this tag affects the font weight"));
Havoc Pennington's avatar
Havoc Pennington committed
528

Matthias Clasen's avatar
x  
Matthias Clasen committed
529
  ADD_SET_PROP ("stretch-set", PROP_STRETCH_SET,
530 531
                P_("Font stretch set"),
                P_("Whether this tag affects the font stretch"));
Havoc Pennington's avatar
Havoc Pennington committed
532

Matthias Clasen's avatar
x  
Matthias Clasen committed
533
  ADD_SET_PROP ("size-set", PROP_SIZE_SET,
534 535
                P_("Font size set"),
                P_("Whether this tag affects the font size"));
Havoc Pennington's avatar
Havoc Pennington committed
536

Matthias Clasen's avatar
x  
Matthias Clasen committed
537
  ADD_SET_PROP ("scale-set", PROP_SCALE_SET,
538 539
                P_("Font scale set"),
                P_("Whether this tag scales the font size by a factor"));
Havoc Pennington's avatar
Havoc Pennington committed
540
  
Matthias Clasen's avatar
x  
Matthias Clasen committed
541
  ADD_SET_PROP ("rise-set", PROP_RISE_SET,
542 543
                P_("Rise set"),
                P_("Whether this tag affects the rise"));
Havoc Pennington's avatar
Havoc Pennington committed
544

Matthias Clasen's avatar
x  
Matthias Clasen committed
545
  ADD_SET_PROP ("strikethrough-set", PROP_STRIKETHROUGH_SET,
546 547
                P_("Strikethrough set"),
                P_("Whether this tag affects strikethrough"));
Havoc Pennington's avatar
Havoc Pennington committed
548

Matthias Clasen's avatar
x  
Matthias Clasen committed
549
  ADD_SET_PROP ("underline-set", PROP_UNDERLINE_SET,
550 551
                P_("Underline set"),
                P_("Whether this tag affects underlining"));
552

Matthias Clasen's avatar
x  
Matthias Clasen committed
553
  ADD_SET_PROP ("language-set", PROP_LANGUAGE_SET,
554 555
                P_("Language set"),
                P_("Whether this tag affects the language the text is rendered as"));
556

Matthias Clasen's avatar
x  
Matthias Clasen committed
557
  ADD_SET_PROP ("ellipsize-set", PROP_ELLIPSIZE_SET,
558
                P_("Ellipsize set"),
559
                P_("Whether this tag affects the ellipsize mode"));
560

561 562 563 564
  ADD_SET_PROP ("align-set", PROP_ALIGN_SET,
                P_("Align set"),
                P_("Whether this tag affects the alignment mode"));

565 566
  /**
   * GtkCellRendererText::edited
Matthias Clasen's avatar
Matthias Clasen committed
567 568 569
   * @renderer: the object which received the signal
   * @path: the path identifying the edited cell
   * @new_text: the new text
570 571
   *
   * This signal is emitted after @renderer has been edited.
Matthias Clasen's avatar
Matthias Clasen committed
572 573 574
   *
   * It is the responsibility of the application to update the model
   * and store @new_text at the position indicated by @path.
575
   */
576
  text_cell_renderer_signals [EDITED] =
Matthias Clasen's avatar
Matthias Clasen committed
577
    g_signal_new (I_("edited"),
Manish Singh's avatar
Manish Singh committed
578 579 580 581 582 583 584 585
		  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);
586

587
  g_type_class_add_private (object_class, sizeof (GtkCellRendererTextPrivate));
Havoc Pennington's avatar
Havoc Pennington committed
588 589 590 591 592 593
}

static void
gtk_cell_renderer_text_finalize (GObject *object)
{
  GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object);
594 595 596
  GtkCellRendererTextPrivate *priv;

  priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (object);
Havoc Pennington's avatar
Havoc Pennington committed
597

598
  pango_font_description_free (celltext->font);
Havoc Pennington's avatar
Havoc Pennington committed
599

600
  g_free (celltext->text);
Alexander Larsson's avatar
Alexander Larsson committed
601 602 603 604

  if (celltext->extra_attrs)
    pango_attr_list_unref (celltext->extra_attrs);

605 606 607
  if (priv->language)
    g_object_unref (priv->language);

Matthias Clasen's avatar
Matthias Clasen committed
608
  (* G_OBJECT_CLASS (gtk_cell_renderer_text_parent_class)->finalize) (object);
609 610
}

611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632
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;
}

633
static void
634 635 636
gtk_cell_renderer_text_get_property (GObject        *object,
				     guint           param_id,
				     GValue         *value,
Tim Janik's avatar
Tim Janik committed
637
				     GParamSpec     *pspec)
638 639
{
  GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object);
640 641 642
  GtkCellRendererTextPrivate *priv;

  priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (object);
643 644 645 646 647 648

  switch (param_id)
    {
    case PROP_TEXT:
      g_value_set_string (value, celltext->text);
      break;
649 650 651 652 653

    case PROP_ATTRIBUTES:
      g_value_set_boxed (value, celltext->extra_attrs);
      break;

654 655 656 657
    case PROP_SINGLE_PARAGRAPH_MODE:
      g_value_set_boolean (value, priv->single_paragraph);
      break;

Havoc Pennington's avatar
Havoc Pennington committed
658 659 660 661 662 663 664 665 666 667
    case PROP_BACKGROUND_GDK:
      {
        GdkColor color;
        
        color.red = celltext->background.red;
        color.green = celltext->background.green;
        color.blue = celltext->background.blue;
        
        g_value_set_boxed (value, &color);
      }
668
      break;
Havoc Pennington's avatar
Havoc Pennington committed
669 670 671 672 673 674 675 676 677 678 679 680 681 682

    case PROP_FOREGROUND_GDK:
      {
        GdkColor color;
        
        color.red = celltext->foreground.red;
        color.green = celltext->foreground.green;
        color.blue = celltext->foreground.blue;
        
        g_value_set_boxed (value, &color);
      }
      break;

    case PROP_FONT:
Michael Natterer's avatar
Michael Natterer committed
683
        g_value_take_string (value, pango_font_description_to_string (celltext->font));
684
      break;
Havoc Pennington's avatar
Havoc Pennington committed
685 686
      
    case PROP_FONT_DESC:
687
      g_value_set_boxed (value, celltext->font);
Havoc Pennington's avatar
Havoc Pennington committed
688 689 690
      break;

    case PROP_FAMILY:
691
      g_value_set_string (value, pango_font_description_get_family (celltext->font));
Havoc Pennington's avatar
Havoc Pennington committed
692 693 694
      break;

    case PROP_STYLE:
695
      g_value_set_enum (value, pango_font_description_get_style (celltext->font));
Havoc Pennington's avatar
Havoc Pennington committed
696 697 698
      break;

    case PROP_VARIANT:
699
      g_value_set_enum (value, pango_font_description_get_variant (celltext->font));
Havoc Pennington's avatar
Havoc Pennington committed
700 701 702
      break;

    case PROP_WEIGHT:
703
      g_value_set_int (value, pango_font_description_get_weight (celltext->font));
Havoc Pennington's avatar
Havoc Pennington committed
704 705 706
      break;

    case PROP_STRETCH:
707
      g_value_set_enum (value, pango_font_description_get_stretch (celltext->font));
Havoc Pennington's avatar
Havoc Pennington committed
708 709 710
      break;

    case PROP_SIZE:
711
      g_value_set_int (value, pango_font_description_get_size (celltext->font));
Havoc Pennington's avatar
Havoc Pennington committed
712 713 714
      break;

    case PROP_SIZE_POINTS:
715
      g_value_set_double (value, ((double)pango_font_description_get_size (celltext->font)) / (double)PANGO_SCALE);
Havoc Pennington's avatar
Havoc Pennington committed
716 717
      break;

Havoc Pennington's avatar
Havoc Pennington committed
718 719 720 721
    case PROP_SCALE:
      g_value_set_double (value, celltext->font_scale);
      break;
      
722 723 724
    case PROP_EDITABLE:
      g_value_set_boolean (value, celltext->editable);
      break;
Havoc Pennington's avatar
Havoc Pennington committed
725 726 727 728 729 730 731 732 733 734 735 736 737

    case PROP_STRIKETHROUGH:
      g_value_set_boolean (value, celltext->strikethrough);
      break;

    case PROP_UNDERLINE:
      g_value_set_enum (value, celltext->underline_style);
      break;

    case PROP_RISE:
      g_value_set_int (value, celltext->rise);
      break;  

738
    case PROP_LANGUAGE:
739
      g_value_set_static_string (value, pango_language_to_string (priv->language));
740 741
      break;

742 743 744 745
    case PROP_ELLIPSIZE:
      g_value_set_enum (value, priv->ellipsize);
      break;
      
746 747 748 749 750 751 752 753
    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;
      
754 755 756 757
    case PROP_ALIGN:
      g_value_set_enum (value, priv->align);
      break;

Havoc Pennington's avatar
Havoc Pennington committed
758 759 760 761 762 763 764 765 766 767 768 769 770 771
    case PROP_BACKGROUND_SET:
      g_value_set_boolean (value, celltext->background_set);
      break;

    case PROP_FOREGROUND_SET:
      g_value_set_boolean (value, celltext->foreground_set);
      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:
772 773 774
      {
	PangoFontMask mask = get_property_font_set_mask (param_id);
	g_value_set_boolean (value, (pango_font_description_get_set_fields (celltext->font) & mask) != 0);
775 776
	
	break;
777
      }
Havoc Pennington's avatar
Havoc Pennington committed
778

Havoc Pennington's avatar
Havoc Pennington committed
779 780 781 782
    case PROP_SCALE_SET:
      g_value_set_boolean (value, celltext->scale_set);
      break;
      
Havoc Pennington's avatar
Havoc Pennington committed
783 784 785 786 787 788 789 790 791 792 793 794 795 796 797
    case PROP_EDITABLE_SET:
      g_value_set_boolean (value, celltext->editable_set);
      break;

    case PROP_STRIKETHROUGH_SET:
      g_value_set_boolean (value, celltext->strikethrough_set);
      break;

    case PROP_UNDERLINE_SET:
      g_value_set_boolean (value, celltext->underline_set);
      break;

    case  PROP_RISE_SET:
      g_value_set_boolean (value, celltext->rise_set);
      break;
798 799 800 801

    case PROP_LANGUAGE_SET:
      g_value_set_boolean (value, priv->language_set);
      break;
802 803 804 805

    case PROP_ELLIPSIZE_SET:
      g_value_set_boolean (value, priv->ellipsize_set);
      break;
806 807 808 809

    case PROP_ALIGN_SET:
      g_value_set_boolean (value, priv->align_set);
      break;
Havoc Pennington's avatar
Havoc Pennington committed
810
      
811 812 813 814
    case PROP_WIDTH_CHARS:
      g_value_set_int (value, priv->width_chars);
      break;  

Havoc Pennington's avatar
Havoc Pennington committed
815 816
    case PROP_BACKGROUND:
    case PROP_FOREGROUND:
Alexander Larsson's avatar
Alexander Larsson committed
817
    case PROP_MARKUP:
818
    default:
819
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
820 821 822 823 824
      break;
    }
}


Havoc Pennington's avatar
Havoc Pennington committed
825 826 827 828 829 830 831 832 833
static void
set_bg_color (GtkCellRendererText *celltext,
              GdkColor            *color)
{
  if (color)
    {
      if (!celltext->background_set)
        {
          celltext->background_set = TRUE;
834
          g_object_notify (G_OBJECT (celltext), "background-set");
Havoc Pennington's avatar
Havoc Pennington committed
835 836 837 838 839 840 841 842 843 844 845
        }
      
      celltext->background.red = color->red;
      celltext->background.green = color->green;
      celltext->background.blue = color->blue;
    }
  else
    {
      if (celltext->background_set)
        {
          celltext->background_set = FALSE;
846
          g_object_notify (G_OBJECT (celltext), "background-set");
Havoc Pennington's avatar
Havoc Pennington committed
847 848 849 850 851 852 853 854 855 856 857 858 859 860
        }
    }
}


static void
set_fg_color (GtkCellRendererText *celltext,
              GdkColor            *color)
{
  if (color)
    {
      if (!celltext->foreground_set)
        {
          celltext->foreground_set = TRUE;
861
          g_object_notify (G_OBJECT (celltext), "foreground-set");
Havoc Pennington's avatar
Havoc Pennington committed
862 863 864 865 866 867 868 869 870 871 872
        }
      
      celltext->foreground.red = color->red;
      celltext->foreground.green = color->green;
      celltext->foreground.blue = color->blue;
    }
  else
    {
      if (celltext->foreground_set)
        {
          celltext->foreground_set = FALSE;
873
          g_object_notify (G_OBJECT (celltext), "foreground-set");
Havoc Pennington's avatar
Havoc Pennington committed
874 875 876 877
        }
    }
}

878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917
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;
}

918 919 920 921 922
static void
notify_set_changed (GObject       *object,
		    PangoFontMask  changed_mask)
{
  if (changed_mask & PANGO_FONT_MASK_FAMILY)
923
    g_object_notify (object, "family-set");
924
  if (changed_mask & PANGO_FONT_MASK_STYLE)
925
    g_object_notify (object, "style-set");
926
  if (changed_mask & PANGO_FONT_MASK_VARIANT)
927
    g_object_notify (object, "variant-set");
928
  if (changed_mask & PANGO_FONT_MASK_WEIGHT)
929
    g_object_notify (object, "weight-set");
930
  if (changed_mask & PANGO_FONT_MASK_STRETCH)
931
    g_object_notify (object, "stretch-set");
932
  if (changed_mask & PANGO_FONT_MASK_SIZE)
933
    g_object_notify (object, "size-set");
934 935
}

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

Havoc Pennington's avatar
Havoc Pennington committed
954 955 956 957
static void
set_font_description (GtkCellRendererText  *celltext,
                      PangoFontDescription *font_desc)
{
958 959 960 961 962 963
  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);
Havoc Pennington's avatar
Havoc Pennington committed
964
  else
965 966 967 968 969 970 971 972 973 974 975 976 977
    new_font_desc = pango_font_description_new ();

  old_mask = pango_font_description_get_set_fields (celltext->font);
  new_mask = pango_font_description_get_set_fields (new_font_desc);

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

  pango_font_description_free (celltext->font);
  celltext->font = new_font_desc;
  
  g_object_freeze_notify (object);

978
  g_object_notify (object, "font-desc");
979 980 981 982 983 984 985 986 987 988 989 990 991
  g_object_notify (object, "font");
  
  if (changed_mask & PANGO_FONT_MASK_FAMILY)
    g_object_notify (object, "family");
  if (changed_mask & PANGO_FONT_MASK_STYLE)
    g_object_notify (object, "style");
  if (changed_mask & PANGO_FONT_MASK_VARIANT)
    g_object_notify (object, "variant");
  if (changed_mask & PANGO_FONT_MASK_WEIGHT)
    g_object_notify (object, "weight");
  if (changed_mask & PANGO_FONT_MASK_STRETCH)
    g_object_notify (object, "stretch");
  if (changed_mask & PANGO_FONT_MASK_SIZE)
Havoc Pennington's avatar
Havoc Pennington committed
992
    {
993
      g_object_notify (object, "size");
994
      g_object_notify (object, "size-points");
Havoc Pennington's avatar
Havoc Pennington committed
995
    }
996 997 998 999

  notify_set_changed (object, set_changed_mask);
  
  g_object_thaw_notify (object);
Havoc Pennington's avatar
Havoc Pennington committed
1000 1001
}

1002
static void
1003 1004 1005
gtk_cell_renderer_text_set_property (GObject      *object,
				     guint         param_id,
				     const GValue *value,
Tim Janik's avatar
Tim Janik committed
1006
				     GParamSpec   *pspec)
1007 1008
{
  GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object);
1009 1010 1011
  GtkCellRendererTextPrivate *priv;

  priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (object);
1012 1013 1014 1015

  switch (param_id)
    {
    case PROP_TEXT:
1016
      g_free (celltext->text);
1017 1018 1019 1020 1021 1022 1023 1024 1025

      if (priv->markup_set)
        {
          if (celltext->extra_attrs)
            pango_attr_list_unref (celltext->extra_attrs);
          celltext->extra_attrs = NULL;
          priv->markup_set = FALSE;
        }

Havoc Pennington's avatar
Havoc Pennington committed
1026
      celltext->text = g_strdup (g_value_get_string (value));
1027
      g_object_notify (object, "text");
1028
      break;
1029 1030 1031 1032 1033 1034

    case PROP_ATTRIBUTES:
      if (celltext->extra_attrs)
	pango_attr_list_unref (celltext->extra_attrs);

      celltext->extra_attrs = g_value_get_boxed (value);
1035 1036
      if (celltext->extra_attrs)
        pango_attr_list_ref (celltext->extra_attrs);
1037
      break;
Alexander Larsson's avatar
Alexander Larsson committed
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053
    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))
	  {
1054
	    g_warning ("Failed to set text from markup due to error parsing markup: %s",
Alexander Larsson's avatar
Alexander Larsson committed
1055 1056 1057 1058
		       error->message);
	    g_error_free (error);
	    return;
	  }
Kristian Rietveld's avatar
Kristian Rietveld committed
1059

1060
	g_free (celltext->text);
Kristian Rietveld's avatar
Kristian Rietveld committed
1061 1062 1063 1064

	if (celltext->extra_attrs)
	  pango_attr_list_unref (celltext->extra_attrs);

Alexander Larsson's avatar
Alexander Larsson committed
1065 1066
	celltext->text = text;
	celltext->extra_attrs = attrs;
1067
        priv->markup_set = TRUE;
Alexander Larsson's avatar
Alexander Larsson committed
1068 1069
      }
      break;
1070 1071 1072 1073

    case PROP_SINGLE_PARAGRAPH_MODE:
      priv->single_paragraph = g_value_get_boolean (value);
      break;
Alexander Larsson's avatar
Alexander Larsson committed
1074
      
1075
    case PROP_BACKGROUND:
Havoc Pennington's avatar
Havoc Pennington committed
1076 1077 1078
      {
        GdkColor color;

1079
        if (!g_value_get_string (value))
1080
          set_bg_color (celltext, NULL);       /* reset to background_set to FALSE */
1081
        else if (gdk_color_parse (g_value_get_string (value), &color))
Havoc Pennington's avatar
Havoc Pennington committed
1082 1083 1084 1085
          set_bg_color (celltext, &color);
        else
          g_warning ("Don't know color `%s'", g_value_get_string (value));

1086
        g_object_notify (object, "background-gdk");
Havoc Pennington's avatar
Havoc Pennington committed
1087
      }
1088
      break;
Havoc Pennington's avatar
Havoc Pennington committed
1089
      
1090
    case PROP_FOREGROUND:
Havoc Pennington's avatar
Havoc Pennington committed
1091 1092 1093
      {
        GdkColor color;

1094 1095 1096 1097
        if (!g_value_get_string (value))
          set_fg_color (celltext, NULL);       /* reset to foreground_set to FALSE */
        else if (gdk_color_parse (g_value_get_string (value), &color))
          set_fg_color (celltext, &color);
Havoc Pennington's avatar
Havoc Pennington committed
1098 1099 1100
        else
          g_warning ("Don't know color `%s'", g_value_get_string (value));

1101
        g_object_notify (object, "foreground-gdk");
Havoc Pennington's avatar
Havoc Pennington committed
1102 1103 1104 1105
      }
      break;

    case PROP_BACKGROUND_GDK:
1106
      /* This notifies the GObject itself. */
Havoc Pennington's avatar
Havoc Pennington committed
1107
      set_bg_color (celltext, g_value_get_boxed (value));
1108
      break;
Havoc Pennington's avatar
Havoc Pennington committed
1109

1110
    case PROP_FOREGROUND_GDK:
1111
      /* This notifies the GObject itself. */
Havoc Pennington's avatar
Havoc Pennington committed
1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125
      set_fg_color (celltext, g_value_get_boxed (value));
      break;

    case PROP_FONT:
      {
        PangoFontDescription *font_desc = NULL;
        const gchar *name;

        name = g_value_get_string (value);

        if (name)
          font_desc = pango_font_description_from_string (name);

        set_font_description (celltext, font_desc);
1126 1127

	pango_font_description_free (font_desc);
Havoc Pennington's avatar
Havoc Pennington committed
1128
        
1129 1130
	if (celltext->fixed_height_rows != -1)
	  celltext->calc_fixed_height = TRUE;
Havoc Pennington's avatar
Havoc Pennington committed
1131 1132 1133 1134 1135
      }
      break;

    case PROP_FONT_DESC:
      set_font_description (celltext, g_value_get_boxed (value));
1136
      
1137 1138
      if (celltext->fixed_height_rows != -1)
	celltext->calc_fixed_height = TRUE;
Havoc Pennington's avatar
Havoc Pennington committed
1139 1140 1141 1142 1143 1144 1145 1146
      break;

    case PROP_FAMILY:
    case PROP_STYLE:
    case PROP_VARIANT:
    case PROP_WEIGHT:
    case PROP_STRETCH:
    case PROP_SIZE:
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166
    case PROP_SIZE_POINTS:
      {
	PangoFontMask old_set_mask = pango_font_description_get_set_fields (celltext->font);
	
	switch (param_id)
	  {
	  case PROP_FAMILY:
	    pango_font_description_set_family (celltext->font,
					       g_value_get_string (value));
	    break;
	  case PROP_STYLE:
	    pango_font_description_set_style (celltext->font,
					      g_value_get_enum (value));
	    break;
	  case PROP_VARIANT:
	    pango_font_description_set_variant (celltext->font,
						g_value_get_enum (value));
	    break;
	  case PROP_WEIGHT:
	    pango_font_description_set_weight (celltext->font,
CEST's avatar
-)  
CEST committed
1167
					       g_value_get_int (value));
1168 1169 1170 1171 1172 1173 1174 1175
	    break;
	  case PROP_STRETCH:
	    pango_font_description_set_stretch (celltext->font,
						g_value_get_enum (value));
	    break;
	  case PROP_SIZE:
	    pango_font_description_set_size (celltext->font,
					     g_value_get_int (value));
1176
	    g_object_notify (object, "size-points");