]> Pileus Git - ~andy/gtk/blob - gtk/gtkcellrenderertext.c
add more to the docs.
[~andy/gtk] / gtk / gtkcellrenderertext.c
1 /* gtkcellrenderertext.c
2  * Copyright (C) 2000  Red Hat, Inc.,  Jonathan Blandford <jrb@redhat.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include <stdlib.h>
21 #include "gtkcellrenderertext.h"
22 #include "gtkeditable.h"
23 #include "gtkentry.h"
24 #include "gtkmarshalers.h"
25 #include "gtkintl.h"
26
27 static void gtk_cell_renderer_text_init       (GtkCellRendererText      *celltext);
28 static void gtk_cell_renderer_text_class_init (GtkCellRendererTextClass *class);
29 static void gtk_cell_renderer_text_finalize   (GObject                  *object);
30
31 static void gtk_cell_renderer_text_get_property  (GObject                  *object,
32                                                   guint                     param_id,
33                                                   GValue                   *value,
34                                                   GParamSpec               *pspec);
35 static void gtk_cell_renderer_text_set_property  (GObject                  *object,
36                                                   guint                     param_id,
37                                                   const GValue             *value,
38                                                   GParamSpec               *pspec);
39 static void gtk_cell_renderer_text_get_size   (GtkCellRenderer          *cell,
40                                                GtkWidget                *widget,
41                                                GdkRectangle             *cell_area,
42                                                gint                     *x_offset,
43                                                gint                     *y_offset,
44                                                gint                     *width,
45                                                gint                     *height);
46 static void gtk_cell_renderer_text_render     (GtkCellRenderer          *cell,
47                                                GdkWindow                *window,
48                                                GtkWidget                *widget,
49                                                GdkRectangle             *background_area,
50                                                GdkRectangle             *cell_area,
51                                                GdkRectangle             *expose_area,
52                                                GtkCellRendererState      flags);
53
54 static GtkCellEditable *gtk_cell_renderer_text_start_editing (GtkCellRenderer      *cell,
55                                                               GdkEvent             *event,
56                                                               GtkWidget            *widget,
57                                                               const gchar          *path,
58                                                               GdkRectangle         *background_area,
59                                                               GdkRectangle         *cell_area,
60                                                               GtkCellRendererState  flags);
61
62 enum {
63   EDITED,
64   LAST_SIGNAL
65 };
66
67 enum {
68   PROP_0,
69
70   PROP_TEXT,
71   PROP_MARKUP,
72   PROP_ATTRIBUTES,
73   
74   /* Style args */
75   PROP_BACKGROUND,
76   PROP_FOREGROUND,
77   PROP_BACKGROUND_GDK,
78   PROP_FOREGROUND_GDK,
79   PROP_FONT,
80   PROP_FONT_DESC,
81   PROP_FAMILY,
82   PROP_STYLE,
83   PROP_VARIANT,
84   PROP_WEIGHT,
85   PROP_STRETCH,
86   PROP_SIZE,
87   PROP_SIZE_POINTS,
88   PROP_SCALE,
89   PROP_EDITABLE,
90   PROP_STRIKETHROUGH,
91   PROP_UNDERLINE,
92   PROP_RISE,
93   
94   /* Whether-a-style-arg-is-set args */
95   PROP_BACKGROUND_SET,
96   PROP_FOREGROUND_SET,
97   PROP_FAMILY_SET,
98   PROP_STYLE_SET,
99   PROP_VARIANT_SET,
100   PROP_WEIGHT_SET,
101   PROP_STRETCH_SET,
102   PROP_SIZE_SET,
103   PROP_SCALE_SET,
104   PROP_EDITABLE_SET,
105   PROP_STRIKETHROUGH_SET,
106   PROP_UNDERLINE_SET,
107   PROP_RISE_SET
108 };
109
110 static gpointer parent_class;
111 static guint text_cell_renderer_signals [LAST_SIGNAL];
112
113 #define GTK_CELL_RENDERER_TEXT_PATH "gtk-cell-renderer-text-path"
114
115 GType
116 gtk_cell_renderer_text_get_type (void)
117 {
118   static GType cell_text_type = 0;
119
120   if (!cell_text_type)
121     {
122       static const GTypeInfo cell_text_info =
123       {
124         sizeof (GtkCellRendererTextClass),
125         NULL,           /* base_init */
126         NULL,           /* base_finalize */
127         (GClassInitFunc) gtk_cell_renderer_text_class_init,
128         NULL,           /* class_finalize */
129         NULL,           /* class_data */
130         sizeof (GtkCellRendererText),
131         0,              /* n_preallocs */
132         (GInstanceInitFunc) gtk_cell_renderer_text_init,
133       };
134
135       cell_text_type =
136         g_type_register_static (GTK_TYPE_CELL_RENDERER, "GtkCellRendererText",
137                                 &cell_text_info, 0);
138     }
139
140   return cell_text_type;
141 }
142
143 static void
144 gtk_cell_renderer_text_init (GtkCellRendererText *celltext)
145 {
146   GTK_CELL_RENDERER (celltext)->xalign = 0.0;
147   GTK_CELL_RENDERER (celltext)->yalign = 0.5;
148   GTK_CELL_RENDERER (celltext)->xpad = 2;
149   GTK_CELL_RENDERER (celltext)->ypad = 2;
150   celltext->fixed_height_rows = -1;
151   celltext->font = pango_font_description_new ();
152 }
153
154 static void
155 gtk_cell_renderer_text_class_init (GtkCellRendererTextClass *class)
156 {
157   GObjectClass *object_class = G_OBJECT_CLASS (class);
158   GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (class);
159
160   parent_class = g_type_class_peek_parent (class);
161   
162   object_class->finalize = gtk_cell_renderer_text_finalize;
163   
164   object_class->get_property = gtk_cell_renderer_text_get_property;
165   object_class->set_property = gtk_cell_renderer_text_set_property;
166
167   cell_class->get_size = gtk_cell_renderer_text_get_size;
168   cell_class->render = gtk_cell_renderer_text_render;
169   cell_class->start_editing = gtk_cell_renderer_text_start_editing;
170   
171   g_object_class_install_property (object_class,
172                                    PROP_TEXT,
173                                    g_param_spec_string ("text",
174                                                         _("Text"),
175                                                         _("Text to render"),
176                                                         NULL,
177                                                         G_PARAM_READWRITE));
178   
179   g_object_class_install_property (object_class,
180                                    PROP_MARKUP,
181                                    g_param_spec_string ("markup",
182                                                         _("Markup"),
183                                                         _("Marked up text to render"),
184                                                         NULL,
185                                                         G_PARAM_WRITABLE));
186
187   g_object_class_install_property (object_class,
188                                    PROP_ATTRIBUTES,
189                                    g_param_spec_boxed ("attributes",
190                                                        _("Attributes"),
191                                                        _("A list of style attributes to apply to the text of the renderer"),
192                                                        PANGO_TYPE_ATTR_LIST,
193                                                        G_PARAM_READWRITE));
194   
195   g_object_class_install_property (object_class,
196                                    PROP_BACKGROUND,
197                                    g_param_spec_string ("background",
198                                                         _("Background color name"),
199                                                         _("Background color as a string"),
200                                                         NULL,
201                                                         G_PARAM_WRITABLE));
202
203   g_object_class_install_property (object_class,
204                                    PROP_BACKGROUND_GDK,
205                                    g_param_spec_boxed ("background_gdk",
206                                                        _("Background color"),
207                                                        _("Background color as a GdkColor"),
208                                                        GDK_TYPE_COLOR,
209                                                        G_PARAM_READABLE | G_PARAM_WRITABLE));  
210
211   g_object_class_install_property (object_class,
212                                    PROP_FOREGROUND,
213                                    g_param_spec_string ("foreground",
214                                                         _("Foreground color name"),
215                                                         _("Foreground color as a string"),
216                                                         NULL,
217                                                         G_PARAM_WRITABLE));
218
219   g_object_class_install_property (object_class,
220                                    PROP_FOREGROUND_GDK,
221                                    g_param_spec_boxed ("foreground_gdk",
222                                                        _("Foreground color"),
223                                                        _("Foreground color as a GdkColor"),
224                                                        GDK_TYPE_COLOR,
225                                                        G_PARAM_READABLE | G_PARAM_WRITABLE));
226
227
228   g_object_class_install_property (object_class,
229                                    PROP_EDITABLE,
230                                    g_param_spec_boolean ("editable",
231                                                          _("Editable"),
232                                                          _("Whether the text can be modified by the user"),
233                                                          FALSE,
234                                                          G_PARAM_READABLE | G_PARAM_WRITABLE));
235
236   g_object_class_install_property (object_class,
237                                    PROP_FONT,
238                                    g_param_spec_string ("font",
239                                                         _("Font"),
240                                                         _("Font description as a string"),
241                                                         NULL,
242                                                         G_PARAM_READABLE | G_PARAM_WRITABLE));
243
244   g_object_class_install_property (object_class,
245                                    PROP_FONT_DESC,
246                                    g_param_spec_boxed ("font_desc",
247                                                        _("Font"),
248                                                        _("Font description as a PangoFontDescription struct"),
249                                                        PANGO_TYPE_FONT_DESCRIPTION,
250                                                        G_PARAM_READABLE | G_PARAM_WRITABLE));
251
252   
253   g_object_class_install_property (object_class,
254                                    PROP_FAMILY,
255                                    g_param_spec_string ("family",
256                                                         _("Font family"),
257                                                         _("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
258                                                         NULL,
259                                                         G_PARAM_READABLE | G_PARAM_WRITABLE));
260
261   g_object_class_install_property (object_class,
262                                    PROP_STYLE,
263                                    g_param_spec_enum ("style",
264                                                       _("Font style"),
265                                                       _("Font style"),
266                                                       PANGO_TYPE_STYLE,
267                                                       PANGO_STYLE_NORMAL,
268                                                       G_PARAM_READABLE | G_PARAM_WRITABLE));
269
270   g_object_class_install_property (object_class,
271                                    PROP_VARIANT,
272                                    g_param_spec_enum ("variant",
273                                                      _("Font variant"),
274                                                      _("Font variant"),
275                                                       PANGO_TYPE_VARIANT,
276                                                       PANGO_VARIANT_NORMAL,
277                                                       G_PARAM_READABLE | G_PARAM_WRITABLE));
278   
279   g_object_class_install_property (object_class,
280                                    PROP_WEIGHT,
281                                    g_param_spec_int ("weight",
282                                                      _("Font weight"),
283                                                      _("Font weight"),
284                                                      0,
285                                                      G_MAXINT,
286                                                      PANGO_WEIGHT_NORMAL,
287                                                      G_PARAM_READABLE | G_PARAM_WRITABLE));
288
289    g_object_class_install_property (object_class,
290                                    PROP_STRETCH,
291                                    g_param_spec_enum ("stretch",
292                                                       _("Font stretch"),
293                                                       _("Font stretch"),
294                                                       PANGO_TYPE_STRETCH,
295                                                       PANGO_STRETCH_NORMAL,
296                                                       G_PARAM_READABLE | G_PARAM_WRITABLE));
297   
298   g_object_class_install_property (object_class,
299                                    PROP_SIZE,
300                                    g_param_spec_int ("size",
301                                                      _("Font size"),
302                                                      _("Font size"),
303                                                      0,
304                                                      G_MAXINT,
305                                                      0,
306                                                      G_PARAM_READABLE | G_PARAM_WRITABLE));
307
308   g_object_class_install_property (object_class,
309                                    PROP_SIZE_POINTS,
310                                    g_param_spec_double ("size_points",
311                                                         _("Font points"),
312                                                         _("Font size in points"),
313                                                         0.0,
314                                                         G_MAXDOUBLE,
315                                                         0.0,
316                                                         G_PARAM_READABLE | G_PARAM_WRITABLE));  
317
318   g_object_class_install_property (object_class,
319                                    PROP_SCALE,
320                                    g_param_spec_double ("scale",
321                                                         _("Font scale"),
322                                                         _("Font scaling factor"),
323                                                         0.0,
324                                                         G_MAXDOUBLE,
325                                                         1.0,
326                                                         G_PARAM_READABLE | G_PARAM_WRITABLE));
327   
328   g_object_class_install_property (object_class,
329                                    PROP_RISE,
330                                    g_param_spec_int ("rise",
331                                                      _("Rise"),
332                                                      _("Offset of text above the baseline (below the baseline if rise is negative)"),
333                                                      -G_MAXINT,
334                                                      G_MAXINT,
335                                                      0,
336                                                      G_PARAM_READABLE | G_PARAM_WRITABLE));
337
338
339   g_object_class_install_property (object_class,
340                                    PROP_STRIKETHROUGH,
341                                    g_param_spec_boolean ("strikethrough",
342                                                          _("Strikethrough"),
343                                                          _("Whether to strike through the text"),
344                                                          FALSE,
345                                                          G_PARAM_READABLE | G_PARAM_WRITABLE));
346   
347   g_object_class_install_property (object_class,
348                                    PROP_UNDERLINE,
349                                    g_param_spec_enum ("underline",
350                                                       _("Underline"),
351                                                       _("Style of underline for this text"),
352                                                       PANGO_TYPE_UNDERLINE,
353                                                       PANGO_UNDERLINE_NONE,
354                                                       G_PARAM_READABLE | G_PARAM_WRITABLE));
355
356   /* Style props are set or not */
357
358 #define ADD_SET_PROP(propname, propval, nick, blurb) g_object_class_install_property (object_class, propval, g_param_spec_boolean (propname, nick, blurb, FALSE, G_PARAM_READABLE | G_PARAM_WRITABLE))
359
360   ADD_SET_PROP ("background_set", PROP_BACKGROUND_SET,
361                 _("Background set"),
362                 _("Whether this tag affects the background color"));
363
364   ADD_SET_PROP ("foreground_set", PROP_FOREGROUND_SET,
365                 _("Foreground set"),
366                 _("Whether this tag affects the foreground color"));
367   
368   ADD_SET_PROP ("editable_set", PROP_EDITABLE_SET,
369                 _("Editability set"),
370                 _("Whether this tag affects text editability"));
371
372   ADD_SET_PROP ("family_set", PROP_FAMILY_SET,
373                 _("Font family set"),
374                 _("Whether this tag affects the font family"));  
375
376   ADD_SET_PROP ("style_set", PROP_STYLE_SET,
377                 _("Font style set"),
378                 _("Whether this tag affects the font style"));
379
380   ADD_SET_PROP ("variant_set", PROP_VARIANT_SET,
381                 _("Font variant set"),
382                 _("Whether this tag affects the font variant"));
383
384   ADD_SET_PROP ("weight_set", PROP_WEIGHT_SET,
385                 _("Font weight set"),
386                 _("Whether this tag affects the font weight"));
387
388   ADD_SET_PROP ("stretch_set", PROP_STRETCH_SET,
389                 _("Font stretch set"),
390                 _("Whether this tag affects the font stretch"));
391
392   ADD_SET_PROP ("size_set", PROP_SIZE_SET,
393                 _("Font size set"),
394                 _("Whether this tag affects the font size"));
395
396   ADD_SET_PROP ("scale_set", PROP_SCALE_SET,
397                 _("Font scale set"),
398                 _("Whether this tag scales the font size by a factor"));
399   
400   ADD_SET_PROP ("rise_set", PROP_RISE_SET,
401                 _("Rise set"),
402                 _("Whether this tag affects the rise"));
403
404   ADD_SET_PROP ("strikethrough_set", PROP_STRIKETHROUGH_SET,
405                 _("Strikethrough set"),
406                 _("Whether this tag affects strikethrough"));
407
408   ADD_SET_PROP ("underline_set", PROP_UNDERLINE_SET,
409                 _("Underline set"),
410                 _("Whether this tag affects underlining"));
411
412   text_cell_renderer_signals [EDITED] =
413     g_signal_new ("edited",
414                   G_OBJECT_CLASS_TYPE (object_class),
415                   G_SIGNAL_RUN_LAST,
416                   G_STRUCT_OFFSET (GtkCellRendererTextClass, edited),
417                   NULL, NULL,
418                   _gtk_marshal_VOID__STRING_STRING,
419                   G_TYPE_NONE, 2,
420                   G_TYPE_STRING,
421                   G_TYPE_STRING);
422
423 }
424
425 static void
426 gtk_cell_renderer_text_finalize (GObject *object)
427 {
428   GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object);
429
430   pango_font_description_free (celltext->font);
431
432   if (celltext->text)
433     g_free (celltext->text);
434
435   if (celltext->extra_attrs)
436     pango_attr_list_unref (celltext->extra_attrs);
437
438   (* G_OBJECT_CLASS (parent_class)->finalize) (object);
439 }
440
441 static PangoFontMask
442 get_property_font_set_mask (guint prop_id)
443 {
444   switch (prop_id)
445     {
446     case PROP_FAMILY_SET:
447       return PANGO_FONT_MASK_FAMILY;
448     case PROP_STYLE_SET:
449       return PANGO_FONT_MASK_STYLE;
450     case PROP_VARIANT_SET:
451       return PANGO_FONT_MASK_VARIANT;
452     case PROP_WEIGHT_SET:
453       return PANGO_FONT_MASK_WEIGHT;
454     case PROP_STRETCH_SET:
455       return PANGO_FONT_MASK_STRETCH;
456     case PROP_SIZE_SET:
457       return PANGO_FONT_MASK_SIZE;
458     }
459
460   return 0;
461 }
462
463 static void
464 gtk_cell_renderer_text_get_property (GObject        *object,
465                                      guint           param_id,
466                                      GValue         *value,
467                                      GParamSpec     *pspec)
468 {
469   GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object);
470
471   switch (param_id)
472     {
473     case PROP_TEXT:
474       g_value_set_string (value, celltext->text);
475       break;
476
477     case PROP_ATTRIBUTES:
478       g_value_set_boxed (value, celltext->extra_attrs);
479       break;
480
481     case PROP_BACKGROUND_GDK:
482       {
483         GdkColor color;
484         
485         color.red = celltext->background.red;
486         color.green = celltext->background.green;
487         color.blue = celltext->background.blue;
488         
489         g_value_set_boxed (value, &color);
490       }
491       break;
492
493     case PROP_FOREGROUND_GDK:
494       {
495         GdkColor color;
496         
497         color.red = celltext->foreground.red;
498         color.green = celltext->foreground.green;
499         color.blue = celltext->foreground.blue;
500         
501         g_value_set_boxed (value, &color);
502       }
503       break;
504
505     case PROP_FONT:
506       {
507         /* FIXME GValue imposes a totally gratuitous string copy
508          * here, we could just hand off string ownership
509          */
510         gchar *str = pango_font_description_to_string (celltext->font);
511         g_value_set_string (value, str);
512         g_free (str);
513       }
514       break;
515       
516     case PROP_FONT_DESC:
517       g_value_set_boxed (value, celltext->font);
518       break;
519
520     case PROP_FAMILY:
521       g_value_set_string (value, pango_font_description_get_family (celltext->font));
522       break;
523
524     case PROP_STYLE:
525       g_value_set_enum (value, pango_font_description_get_style (celltext->font));
526       break;
527
528     case PROP_VARIANT:
529       g_value_set_enum (value, pango_font_description_get_variant (celltext->font));
530       break;
531
532     case PROP_WEIGHT:
533       g_value_set_int (value, pango_font_description_get_weight (celltext->font));
534       break;
535
536     case PROP_STRETCH:
537       g_value_set_enum (value, pango_font_description_get_stretch (celltext->font));
538       break;
539
540     case PROP_SIZE:
541       g_value_set_int (value, pango_font_description_get_size (celltext->font));
542       break;
543
544     case PROP_SIZE_POINTS:
545       g_value_set_double (value, ((double)pango_font_description_get_size (celltext->font)) / (double)PANGO_SCALE);
546       break;
547
548     case PROP_SCALE:
549       g_value_set_double (value, celltext->font_scale);
550       break;
551       
552     case PROP_EDITABLE:
553       g_value_set_boolean (value, celltext->editable);
554       break;
555
556     case PROP_STRIKETHROUGH:
557       g_value_set_boolean (value, celltext->strikethrough);
558       break;
559
560     case PROP_UNDERLINE:
561       g_value_set_enum (value, celltext->underline_style);
562       break;
563
564     case PROP_RISE:
565       g_value_set_int (value, celltext->rise);
566       break;  
567
568     case PROP_BACKGROUND_SET:
569       g_value_set_boolean (value, celltext->background_set);
570       break;
571
572     case PROP_FOREGROUND_SET:
573       g_value_set_boolean (value, celltext->foreground_set);
574       break;
575
576     case PROP_FAMILY_SET:
577     case PROP_STYLE_SET:
578     case PROP_VARIANT_SET:
579     case PROP_WEIGHT_SET:
580     case PROP_STRETCH_SET:
581     case PROP_SIZE_SET:
582       {
583         PangoFontMask mask = get_property_font_set_mask (param_id);
584         g_value_set_boolean (value, (pango_font_description_get_set_fields (celltext->font) & mask) != 0);
585         
586         break;
587       }
588
589     case PROP_SCALE_SET:
590       g_value_set_boolean (value, celltext->scale_set);
591       break;
592       
593     case PROP_EDITABLE_SET:
594       g_value_set_boolean (value, celltext->editable_set);
595       break;
596
597     case PROP_STRIKETHROUGH_SET:
598       g_value_set_boolean (value, celltext->strikethrough_set);
599       break;
600
601     case PROP_UNDERLINE_SET:
602       g_value_set_boolean (value, celltext->underline_set);
603       break;
604
605     case  PROP_RISE_SET:
606       g_value_set_boolean (value, celltext->rise_set);
607       break;
608       
609     case PROP_BACKGROUND:
610     case PROP_FOREGROUND:
611     case PROP_MARKUP:
612     default:
613       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
614       break;
615     }
616 }
617
618
619 static void
620 set_bg_color (GtkCellRendererText *celltext,
621               GdkColor            *color)
622 {
623   if (color)
624     {
625       if (!celltext->background_set)
626         {
627           celltext->background_set = TRUE;
628           g_object_notify (G_OBJECT (celltext), "background_set");
629         }
630       
631       celltext->background.red = color->red;
632       celltext->background.green = color->green;
633       celltext->background.blue = color->blue;
634     }
635   else
636     {
637       if (celltext->background_set)
638         {
639           celltext->background_set = FALSE;
640           g_object_notify (G_OBJECT (celltext), "background_set");
641         }
642     }
643 }
644
645
646 static void
647 set_fg_color (GtkCellRendererText *celltext,
648               GdkColor            *color)
649 {
650   if (color)
651     {
652       if (!celltext->foreground_set)
653         {
654           celltext->foreground_set = TRUE;
655           g_object_notify (G_OBJECT (celltext), "foreground_set");
656         }
657       
658       celltext->foreground.red = color->red;
659       celltext->foreground.green = color->green;
660       celltext->foreground.blue = color->blue;
661     }
662   else
663     {
664       if (celltext->foreground_set)
665         {
666           celltext->foreground_set = FALSE;
667           g_object_notify (G_OBJECT (celltext), "foreground_set");
668         }
669     }
670 }
671
672 static PangoFontMask
673 set_font_desc_fields (PangoFontDescription *desc,
674                       PangoFontMask         to_set)
675 {
676   PangoFontMask changed_mask = 0;
677   
678   if (to_set & PANGO_FONT_MASK_FAMILY)
679     {
680       const char *family = pango_font_description_get_family (desc);
681       if (!family)
682         {
683           family = "sans";
684           changed_mask |= PANGO_FONT_MASK_FAMILY;
685         }
686
687       pango_font_description_set_family (desc, family);
688     }
689   if (to_set & PANGO_FONT_MASK_STYLE)
690     pango_font_description_set_style (desc, pango_font_description_get_style (desc));
691   if (to_set & PANGO_FONT_MASK_VARIANT)
692     pango_font_description_set_variant (desc, pango_font_description_get_variant (desc));
693   if (to_set & PANGO_FONT_MASK_WEIGHT)
694     pango_font_description_set_weight (desc, pango_font_description_get_weight (desc));
695   if (to_set & PANGO_FONT_MASK_STRETCH)
696     pango_font_description_set_stretch (desc, pango_font_description_get_stretch (desc));
697   if (to_set & PANGO_FONT_MASK_SIZE)
698     {
699       gint size = pango_font_description_get_size (desc);
700       if (size <= 0)
701         {
702           size = 10 * PANGO_SCALE;
703           changed_mask |= PANGO_FONT_MASK_SIZE;
704         }
705       
706       pango_font_description_set_size (desc, size);
707     }
708
709   return changed_mask;
710 }
711
712 static void
713 notify_set_changed (GObject       *object,
714                     PangoFontMask  changed_mask)
715 {
716   if (changed_mask & PANGO_FONT_MASK_FAMILY)
717     g_object_notify (object, "family_set");
718   if (changed_mask & PANGO_FONT_MASK_STYLE)
719     g_object_notify (object, "style_set");
720   if (changed_mask & PANGO_FONT_MASK_VARIANT)
721     g_object_notify (object, "variant_set");
722   if (changed_mask & PANGO_FONT_MASK_WEIGHT)
723     g_object_notify (object, "weight_set");
724   if (changed_mask & PANGO_FONT_MASK_STRETCH)
725     g_object_notify (object, "stretch_set");
726   if (changed_mask & PANGO_FONT_MASK_SIZE)
727     g_object_notify (object, "size_set");
728 }
729
730 static void
731 notify_fields_changed (GObject       *object,
732                        PangoFontMask  changed_mask)
733 {
734   if (changed_mask & PANGO_FONT_MASK_FAMILY)
735     g_object_notify (object, "family");
736   if (changed_mask & PANGO_FONT_MASK_STYLE)
737     g_object_notify (object, "style");
738   if (changed_mask & PANGO_FONT_MASK_VARIANT)
739     g_object_notify (object, "variant");
740   if (changed_mask & PANGO_FONT_MASK_WEIGHT)
741     g_object_notify (object, "weight");
742   if (changed_mask & PANGO_FONT_MASK_STRETCH)
743     g_object_notify (object, "stretch");
744   if (changed_mask & PANGO_FONT_MASK_SIZE)
745     g_object_notify (object, "size");
746 }
747
748 static void
749 set_font_description (GtkCellRendererText  *celltext,
750                       PangoFontDescription *font_desc)
751 {
752   GObject *object = G_OBJECT (celltext);
753   PangoFontDescription *new_font_desc;
754   PangoFontMask old_mask, new_mask, changed_mask, set_changed_mask;
755   
756   if (font_desc)
757     new_font_desc = pango_font_description_copy (font_desc);
758   else
759     new_font_desc = pango_font_description_new ();
760
761   old_mask = pango_font_description_get_set_fields (celltext->font);
762   new_mask = pango_font_description_get_set_fields (new_font_desc);
763
764   changed_mask = old_mask | new_mask;
765   set_changed_mask = old_mask ^ new_mask;
766
767   pango_font_description_free (celltext->font);
768   celltext->font = new_font_desc;
769   
770   g_object_freeze_notify (object);
771
772   g_object_notify (object, "font_desc");
773   g_object_notify (object, "font");
774   
775   if (changed_mask & PANGO_FONT_MASK_FAMILY)
776     g_object_notify (object, "family");
777   if (changed_mask & PANGO_FONT_MASK_STYLE)
778     g_object_notify (object, "style");
779   if (changed_mask & PANGO_FONT_MASK_VARIANT)
780     g_object_notify (object, "variant");
781   if (changed_mask & PANGO_FONT_MASK_WEIGHT)
782     g_object_notify (object, "weight");
783   if (changed_mask & PANGO_FONT_MASK_STRETCH)
784     g_object_notify (object, "stretch");
785   if (changed_mask & PANGO_FONT_MASK_SIZE)
786     {
787       g_object_notify (object, "size");
788       g_object_notify (object, "size_points");
789     }
790
791   notify_set_changed (object, set_changed_mask);
792   
793   g_object_thaw_notify (object);
794 }
795
796 static void
797 gtk_cell_renderer_text_set_property (GObject      *object,
798                                      guint         param_id,
799                                      const GValue *value,
800                                      GParamSpec   *pspec)
801 {
802   GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object);
803
804   switch (param_id)
805     {
806     case PROP_TEXT:
807       if (celltext->text)
808         g_free (celltext->text);
809       celltext->text = g_strdup (g_value_get_string (value));
810       g_object_notify (object, "text");
811       break;
812
813     case PROP_ATTRIBUTES:
814       if (celltext->extra_attrs)
815         pango_attr_list_unref (celltext->extra_attrs);
816
817       celltext->extra_attrs = g_value_get_boxed (value);
818       if (celltext->extra_attrs)
819         pango_attr_list_ref (celltext->extra_attrs);
820       break;
821     case PROP_MARKUP:
822       {
823         const gchar *str;
824         gchar *text = NULL;
825         GError *error = NULL;
826         PangoAttrList *attrs = NULL;
827         
828         if (celltext->text)
829           g_free (celltext->text);
830
831         if (celltext->extra_attrs)
832           pango_attr_list_unref (celltext->extra_attrs);
833
834         str = g_value_get_string (value);
835         if (str && !pango_parse_markup (str,
836                                         -1,
837                                         0,
838                                         &attrs,
839                                         &text,
840                                         NULL,
841                                         &error))
842           {
843             g_warning ("Failed to set cell text from markup due to error parsing markup: %s",
844                        error->message);
845             g_error_free (error);
846             return;
847           }
848         
849         celltext->text = text;
850         celltext->extra_attrs = attrs;
851       }
852       break;
853       
854     case PROP_BACKGROUND:
855       {
856         GdkColor color;
857
858         if (!g_value_get_string (value))
859           set_bg_color (celltext, NULL);       /* reset to backgrounmd_set to FALSE */
860         else if (gdk_color_parse (g_value_get_string (value), &color))
861           set_bg_color (celltext, &color);
862         else
863           g_warning ("Don't know color `%s'", g_value_get_string (value));
864
865         g_object_notify (object, "background_gdk");
866       }
867       break;
868       
869     case PROP_FOREGROUND:
870       {
871         GdkColor color;
872
873         if (!g_value_get_string (value))
874           set_fg_color (celltext, NULL);       /* reset to foreground_set to FALSE */
875         else if (gdk_color_parse (g_value_get_string (value), &color))
876           set_fg_color (celltext, &color);
877         else
878           g_warning ("Don't know color `%s'", g_value_get_string (value));
879
880         g_object_notify (object, "foreground_gdk");
881       }
882       break;
883
884     case PROP_BACKGROUND_GDK:
885       /* This notifies the GObject itself. */
886       set_bg_color (celltext, g_value_get_boxed (value));
887       break;
888
889     case PROP_FOREGROUND_GDK:
890       /* This notifies the GObject itself. */
891       set_fg_color (celltext, g_value_get_boxed (value));
892       break;
893
894     case PROP_FONT:
895       {
896         PangoFontDescription *font_desc = NULL;
897         const gchar *name;
898
899         name = g_value_get_string (value);
900
901         if (name)
902           font_desc = pango_font_description_from_string (name);
903
904         set_font_description (celltext, font_desc);
905         
906         if (celltext->fixed_height_rows != -1)
907           celltext->calc_fixed_height = TRUE;
908       }
909       break;
910
911     case PROP_FONT_DESC:
912       set_font_description (celltext, g_value_get_boxed (value));
913       
914       if (celltext->fixed_height_rows != -1)
915         celltext->calc_fixed_height = TRUE;
916       break;
917
918     case PROP_FAMILY:
919     case PROP_STYLE:
920     case PROP_VARIANT:
921     case PROP_WEIGHT:
922     case PROP_STRETCH:
923     case PROP_SIZE:
924     case PROP_SIZE_POINTS:
925       {
926         PangoFontMask old_set_mask = pango_font_description_get_set_fields (celltext->font);
927         
928         switch (param_id)
929           {
930           case PROP_FAMILY:
931             pango_font_description_set_family (celltext->font,
932                                                g_value_get_string (value));
933             break;
934           case PROP_STYLE:
935             pango_font_description_set_style (celltext->font,
936                                               g_value_get_enum (value));
937             break;
938           case PROP_VARIANT:
939             pango_font_description_set_variant (celltext->font,
940                                                 g_value_get_enum (value));
941             break;
942           case PROP_WEIGHT:
943             pango_font_description_set_weight (celltext->font,
944                                                g_value_get_int (value));
945             break;
946           case PROP_STRETCH:
947             pango_font_description_set_stretch (celltext->font,
948                                                 g_value_get_enum (value));
949             break;
950           case PROP_SIZE:
951             pango_font_description_set_size (celltext->font,
952                                              g_value_get_int (value));
953             g_object_notify (object, "size_points");
954             break;
955           case PROP_SIZE_POINTS:
956             pango_font_description_set_size (celltext->font,
957                                              g_value_get_double (value) * PANGO_SCALE);
958             g_object_notify (object, "size");
959             break;
960           }
961         
962         if (celltext->fixed_height_rows != -1)
963           celltext->calc_fixed_height = TRUE;
964         
965         notify_set_changed (object, old_set_mask & pango_font_description_get_set_fields (celltext->font));
966         g_object_notify (object, "font_desc");
967         g_object_notify (object, "font");
968
969         break;
970       }
971       
972     case PROP_SCALE:
973       celltext->font_scale = g_value_get_double (value);
974       celltext->scale_set = TRUE;
975       if (celltext->fixed_height_rows != -1)
976         celltext->calc_fixed_height = TRUE;
977       g_object_notify (object, "scale_set");
978       break;
979       
980     case PROP_EDITABLE:
981       celltext->editable = g_value_get_boolean (value);
982       celltext->editable_set = TRUE;
983       if (celltext->editable)
984         GTK_CELL_RENDERER (celltext)->mode = GTK_CELL_RENDERER_MODE_EDITABLE;
985       else
986         GTK_CELL_RENDERER (celltext)->mode = GTK_CELL_RENDERER_MODE_INERT;
987       g_object_notify (object, "editable_set");
988       break;
989
990     case PROP_STRIKETHROUGH:
991       celltext->strikethrough = g_value_get_boolean (value);
992       celltext->strikethrough_set = TRUE;
993       g_object_notify (object, "strikethrough_set");
994       break;
995
996     case PROP_UNDERLINE:
997       celltext->underline_style = g_value_get_enum (value);
998       celltext->underline_set = TRUE;
999       g_object_notify (object, "underline_set");
1000             
1001       break;
1002
1003     case PROP_RISE:
1004       celltext->rise = g_value_get_int (value);
1005       celltext->rise_set = TRUE;
1006       g_object_notify (object, "rise_set");
1007       if (celltext->fixed_height_rows != -1)
1008         celltext->calc_fixed_height = TRUE;
1009       break;  
1010
1011     case PROP_BACKGROUND_SET:
1012       celltext->background_set = g_value_get_boolean (value);
1013       break;
1014
1015     case PROP_FOREGROUND_SET:
1016       celltext->foreground_set = g_value_get_boolean (value);
1017       break;
1018
1019     case PROP_FAMILY_SET:
1020     case PROP_STYLE_SET:
1021     case PROP_VARIANT_SET:
1022     case PROP_WEIGHT_SET:
1023     case PROP_STRETCH_SET:
1024     case PROP_SIZE_SET:
1025       if (!g_value_get_boolean (value))
1026         {
1027           pango_font_description_unset_fields (celltext->font,
1028                                                get_property_font_set_mask (param_id));
1029         }
1030       else
1031         {
1032           PangoFontMask changed_mask;
1033           
1034           changed_mask = set_font_desc_fields (celltext->font,
1035                                                get_property_font_set_mask (param_id));
1036           notify_fields_changed (G_OBJECT (celltext), changed_mask);
1037         }
1038       break;
1039
1040     case PROP_SCALE_SET:
1041       celltext->scale_set = g_value_get_boolean (value);
1042       break;
1043       
1044     case PROP_EDITABLE_SET:
1045       celltext->editable_set = g_value_get_boolean (value);
1046       break;
1047
1048     case PROP_STRIKETHROUGH_SET:
1049       celltext->strikethrough_set = g_value_get_boolean (value);
1050       break;
1051
1052     case PROP_UNDERLINE_SET:
1053       celltext->underline_set = g_value_get_boolean (value);
1054       break;
1055
1056     case PROP_RISE_SET:
1057       celltext->rise_set = g_value_get_boolean (value);
1058       break;
1059
1060     default:
1061       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1062       break;
1063     }
1064 }
1065
1066 /**
1067  * gtk_cell_renderer_text_new:
1068  * 
1069  * Creates a new #GtkCellRendererText. Adjust how text is drawn using
1070  * object properties. Object properties can be
1071  * set globally (with g_object_set()). Also, with #GtkTreeViewColumn,
1072  * you can bind a property to a value in a #GtkTreeModel. For example,
1073  * you can bind the "text" property on the cell renderer to a string
1074  * value in the model, thus rendering a different string in each row
1075  * of the #GtkTreeView
1076  * 
1077  * Return value: the new cell renderer
1078  **/
1079 GtkCellRenderer *
1080 gtk_cell_renderer_text_new (void)
1081 {
1082   return g_object_new (GTK_TYPE_CELL_RENDERER_TEXT, NULL);
1083 }
1084
1085 static void
1086 add_attr (PangoAttrList  *attr_list,
1087           PangoAttribute *attr)
1088 {
1089   attr->start_index = 0;
1090   attr->end_index = G_MAXINT;
1091   
1092   pango_attr_list_insert (attr_list, attr);
1093 }
1094
1095 static PangoLayout*
1096 get_layout (GtkCellRendererText *celltext,
1097             GtkWidget           *widget,
1098             gboolean             will_render,
1099             GtkCellRendererState flags)
1100 {
1101   PangoAttrList *attr_list;
1102   PangoLayout *layout;
1103   PangoUnderline uline;
1104   
1105   layout = gtk_widget_create_pango_layout (widget, celltext->text);
1106
1107   if (celltext->extra_attrs)
1108     attr_list = pango_attr_list_copy (celltext->extra_attrs);
1109   else
1110     attr_list = pango_attr_list_new ();
1111
1112   if (will_render)
1113     {
1114       /* Add options that affect appearance but not size */
1115       
1116       /* note that background doesn't go here, since it affects
1117        * background_area not the PangoLayout area
1118        */
1119       
1120       if (celltext->foreground_set)
1121         {
1122           PangoColor color;
1123
1124           color = celltext->foreground;
1125           
1126           add_attr (attr_list,
1127                     pango_attr_foreground_new (color.red, color.green, color.blue));
1128         }
1129
1130       if (celltext->strikethrough_set)
1131         add_attr (attr_list,
1132                   pango_attr_strikethrough_new (celltext->strikethrough));
1133     }
1134
1135   add_attr (attr_list, pango_attr_font_desc_new (celltext->font));
1136
1137   if (celltext->scale_set &&
1138       celltext->font_scale != 1.0)
1139     add_attr (attr_list, pango_attr_scale_new (celltext->font_scale));
1140   
1141   if (celltext->underline_set)
1142     uline = celltext->underline_style;
1143   else
1144     uline = PANGO_UNDERLINE_NONE;
1145   
1146   if ((flags & GTK_CELL_RENDERER_PRELIT) == GTK_CELL_RENDERER_PRELIT)
1147     {
1148       switch (uline)
1149         {
1150         case PANGO_UNDERLINE_NONE:
1151           uline = PANGO_UNDERLINE_SINGLE;
1152           break;
1153
1154         case PANGO_UNDERLINE_SINGLE:
1155           uline = PANGO_UNDERLINE_DOUBLE;
1156           break;
1157
1158         default:
1159           break;
1160         }
1161     }
1162
1163   if (uline != PANGO_UNDERLINE_NONE)
1164     add_attr (attr_list, pango_attr_underline_new (celltext->underline_style));
1165
1166   if (celltext->rise_set)
1167     add_attr (attr_list, pango_attr_rise_new (celltext->rise));
1168   
1169   pango_layout_set_attributes (layout, attr_list);
1170   pango_layout_set_width (layout, -1);
1171
1172   pango_attr_list_unref (attr_list);
1173   
1174   return layout;
1175 }
1176
1177 static void
1178 gtk_cell_renderer_text_get_size (GtkCellRenderer *cell,
1179                                  GtkWidget       *widget,
1180                                  GdkRectangle    *cell_area,
1181                                  gint            *x_offset,
1182                                  gint            *y_offset,
1183                                  gint            *width,
1184                                  gint            *height)
1185 {
1186   GtkCellRendererText *celltext = (GtkCellRendererText *) cell;
1187   PangoRectangle rect;
1188   PangoLayout *layout;
1189
1190   if (celltext->calc_fixed_height)
1191     {
1192       PangoContext *context;
1193       PangoFontMetrics *metrics;
1194       PangoFontDescription *font_desc;
1195       gint row_height;
1196
1197       font_desc = pango_font_description_copy (widget->style->font_desc);
1198       pango_font_description_merge (font_desc, celltext->font, TRUE);
1199
1200       if (celltext->scale_set)
1201         pango_font_description_set_size (font_desc,
1202                                          celltext->font_scale * pango_font_description_get_size (font_desc));
1203
1204       context = gtk_widget_get_pango_context (widget);
1205
1206       metrics = pango_context_get_metrics (context,
1207                                            font_desc,
1208                                            pango_context_get_language (context));
1209       row_height = (pango_font_metrics_get_ascent (metrics) +
1210                     pango_font_metrics_get_descent (metrics));
1211       pango_font_metrics_unref (metrics);
1212       
1213       gtk_cell_renderer_set_fixed_size (cell,
1214                                         cell->width, 2*cell->ypad +
1215                                         celltext->fixed_height_rows * PANGO_PIXELS (row_height));
1216       
1217       if (height)
1218         {
1219           *height = cell->height;
1220           height = NULL;
1221         }
1222       celltext->calc_fixed_height = FALSE;
1223       if (width == NULL)
1224         return;
1225     }
1226   layout = get_layout (celltext, widget, FALSE, 0);
1227   pango_layout_get_pixel_extents (layout, NULL, &rect);
1228
1229   if (width)
1230     *width = GTK_CELL_RENDERER (celltext)->xpad * 2 + rect.width;
1231
1232   if (height)
1233     *height = GTK_CELL_RENDERER (celltext)->ypad * 2 + rect.height;
1234
1235   if (cell_area)
1236     {
1237       if (x_offset)
1238         {
1239           *x_offset = cell->xalign * (cell_area->width - rect.width - (2 * cell->xpad));
1240           *x_offset = MAX (*x_offset, 0);
1241         }
1242       if (y_offset)
1243         {
1244           *y_offset = cell->yalign * (cell_area->height - rect.height - (2 * cell->ypad));
1245           *y_offset = MAX (*y_offset, 0);
1246         }
1247     }
1248
1249   g_object_unref (layout);
1250 }
1251
1252 static void
1253 gtk_cell_renderer_text_render (GtkCellRenderer      *cell,
1254                                GdkWindow            *window,
1255                                GtkWidget            *widget,
1256                                GdkRectangle         *background_area,
1257                                GdkRectangle         *cell_area,
1258                                GdkRectangle         *expose_area,
1259                                GtkCellRendererState  flags)
1260
1261 {
1262   GtkCellRendererText *celltext = (GtkCellRendererText *) cell;
1263   PangoLayout *layout;
1264   GtkStateType state;
1265   gint x_offset;
1266   gint y_offset;
1267
1268   layout = get_layout (celltext, widget, TRUE, flags);
1269
1270   gtk_cell_renderer_text_get_size (cell, widget, cell_area, &x_offset, &y_offset, NULL, NULL);
1271
1272   if ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED)
1273     {
1274       if (GTK_WIDGET_HAS_FOCUS (widget))
1275         state = GTK_STATE_SELECTED;
1276       else
1277         state = GTK_STATE_ACTIVE;
1278     }
1279   else
1280     {
1281       if (GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE)
1282         state = GTK_STATE_INSENSITIVE;
1283       else
1284         state = GTK_STATE_NORMAL;
1285     }
1286
1287   if (celltext->background_set && state != GTK_STATE_SELECTED)
1288     {
1289       GdkColor color;
1290       GdkGC *gc;
1291       
1292       color.red = celltext->background.red;
1293       color.green = celltext->background.green;
1294       color.blue = celltext->background.blue;
1295
1296       gc = gdk_gc_new (window);
1297
1298       gdk_gc_set_rgb_fg_color (gc, &color);
1299       
1300       gdk_draw_rectangle (window,
1301                           gc,
1302                           TRUE,
1303                           background_area->x,
1304                           background_area->y,
1305                           background_area->width,
1306                           background_area->height);
1307
1308       g_object_unref (gc);
1309     }
1310
1311   gtk_paint_layout (widget->style,
1312                     window,
1313                     state,
1314                     TRUE,
1315                     cell_area,
1316                     widget,
1317                     "cellrenderertext",
1318                     cell_area->x + x_offset + cell->xpad,
1319                     cell_area->y + y_offset + cell->ypad,
1320                     layout);
1321
1322   g_object_unref (layout);
1323 }
1324
1325 static void
1326 gtk_cell_renderer_text_editing_done (GtkCellEditable *entry,
1327                                      gpointer         data)
1328 {
1329   const gchar *path;
1330   const gchar *new_text;
1331
1332   if (GTK_ENTRY (entry)->editing_canceled)
1333     return;
1334
1335   path = g_object_get_data (G_OBJECT (entry), GTK_CELL_RENDERER_TEXT_PATH);
1336   new_text = gtk_entry_get_text (GTK_ENTRY (entry));
1337
1338   g_signal_emit (data, text_cell_renderer_signals[EDITED], 0, path, new_text);
1339 }
1340
1341 static gboolean
1342 gtk_cell_renderer_text_focus_out_event (GtkWidget *entry,
1343                                         GdkEvent  *event,
1344                                         gpointer   data)
1345 {
1346   gtk_cell_renderer_text_editing_done (GTK_CELL_EDITABLE (entry), data);
1347
1348   /* entry needs focus-out-event */
1349   return FALSE;
1350 }
1351
1352 static GtkCellEditable *
1353 gtk_cell_renderer_text_start_editing (GtkCellRenderer      *cell,
1354                                       GdkEvent             *event,
1355                                       GtkWidget            *widget,
1356                                       const gchar          *path,
1357                                       GdkRectangle         *background_area,
1358                                       GdkRectangle         *cell_area,
1359                                       GtkCellRendererState  flags)
1360 {
1361   GtkCellRendererText *celltext;
1362   GtkWidget *entry;
1363   
1364   celltext = GTK_CELL_RENDERER_TEXT (cell);
1365
1366   /* If the cell isn't editable we return NULL. */
1367   if (celltext->editable == FALSE)
1368     return NULL;
1369
1370   entry = g_object_new (GTK_TYPE_ENTRY,
1371                         "has_frame", FALSE,
1372                         NULL);
1373
1374   gtk_entry_set_text (GTK_ENTRY (entry), celltext->text);
1375   g_object_set_data_full (G_OBJECT (entry), GTK_CELL_RENDERER_TEXT_PATH, g_strdup (path), g_free);
1376   
1377   gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
1378   
1379   gtk_widget_show (entry);
1380   g_signal_connect (entry,
1381                     "editing_done",
1382                     G_CALLBACK (gtk_cell_renderer_text_editing_done),
1383                     celltext);
1384   g_signal_connect (entry, "focus_out_event",
1385                     G_CALLBACK (gtk_cell_renderer_text_focus_out_event),
1386                     celltext);
1387
1388   return GTK_CELL_EDITABLE (entry);
1389
1390 }
1391
1392 /**
1393  * gtk_cell_renderer_text_set_fixed_height_from_font:
1394  * @renderer: A #GtkCellRendererText
1395  * @number_of_rows: Number of rows of text each cell renderer is allocated, or -1
1396  * 
1397  * Sets the height of a renderer to explicitly be determined by the "font" and
1398  * "y_pad" property set on it.  Further changes in these properties do not
1399  * affect the height, so they must be accompanied by a subsequent call to this
1400  * function.  Using this function is unflexible, and should really only be used
1401  * if calculating the size of a cell is too slow (ie, a massive number of cells
1402  * displayed).  If @number_of_rows is -1, then the fixed height is unset, and
1403  * the height is determined by the properties again.
1404  **/
1405 void
1406 gtk_cell_renderer_text_set_fixed_height_from_font (GtkCellRendererText *renderer,
1407                                                    gint                 number_of_rows)
1408 {
1409   g_return_if_fail (GTK_IS_CELL_RENDERER_TEXT (renderer));
1410   g_return_if_fail (number_of_rows == -1 || number_of_rows > 0);
1411
1412   if (number_of_rows == -1)
1413     {
1414       gtk_cell_renderer_set_fixed_size (GTK_CELL_RENDERER (renderer),
1415                                         GTK_CELL_RENDERER (renderer)->width,
1416                                         -1);
1417     }
1418   else
1419     {
1420       renderer->fixed_height_rows = number_of_rows;
1421       renderer->calc_fixed_height = TRUE;
1422     }
1423 }