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