]> Pileus Git - ~andy/gtk/blob - gtk/gtkcellrenderer.c
: Mark param spec strings as static.
[~andy/gtk] / gtk / gtkcellrenderer.c
1 /* gtkcellrenderer.c
2  * Copyright (C) 2000  Red Hat, Inc. Jonathan Blandford
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 <config.h>
21 #include "gtkcellrenderer.h"
22 #include "gtkintl.h"
23 #include "gtkmarshalers.h"
24 #include "gtktreeprivate.h"
25 #include "gtkalias.h"
26
27 static void gtk_cell_renderer_init       (GtkCellRenderer      *cell);
28 static void gtk_cell_renderer_class_init (GtkCellRendererClass *class);
29 static void gtk_cell_renderer_get_property  (GObject              *object,
30                                              guint                 param_id,
31                                              GValue               *value,
32                                              GParamSpec           *pspec);
33 static void gtk_cell_renderer_set_property  (GObject              *object,
34                                              guint                 param_id,
35                                              const GValue         *value,
36                                              GParamSpec           *pspec);
37 static void set_cell_bg_color               (GtkCellRenderer      *cell,
38                                              GdkColor             *color);
39
40
41 #define GTK_CELL_RENDERER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_CELL_RENDERER, GtkCellRendererPrivate))
42
43 typedef struct _GtkCellRendererPrivate GtkCellRendererPrivate;
44 struct _GtkCellRendererPrivate
45 {
46   GdkColor cell_background;
47 };
48
49
50 enum {
51   PROP_ZERO,
52   PROP_MODE,
53   PROP_VISIBLE,
54   PROP_SENSITIVE,
55   PROP_XALIGN,
56   PROP_YALIGN,
57   PROP_XPAD,
58   PROP_YPAD,
59   PROP_WIDTH,
60   PROP_HEIGHT,
61   PROP_IS_EXPANDER,
62   PROP_IS_EXPANDED,
63   PROP_CELL_BACKGROUND,
64   PROP_CELL_BACKGROUND_GDK,
65   PROP_CELL_BACKGROUND_SET
66 };
67
68 /* Signal IDs */
69 enum {
70   EDITING_CANCELED,
71   EDITING_STARTED,
72   LAST_SIGNAL
73 };
74
75 static guint cell_renderer_signals[LAST_SIGNAL] = { 0 };
76
77
78 GType
79 gtk_cell_renderer_get_type (void)
80 {
81   static GType cell_type = 0;
82
83   if (!cell_type)
84     {
85       static const GTypeInfo cell_info =
86       {
87         sizeof (GtkCellRendererClass),
88         NULL,           /* base_init */
89         NULL,           /* base_finalize */
90         (GClassInitFunc) gtk_cell_renderer_class_init,
91         NULL,           /* class_finalize */
92         NULL,           /* class_data */
93         sizeof (GtkCellRenderer),
94         0,              /* n_preallocs */
95         (GInstanceInitFunc) gtk_cell_renderer_init,
96         NULL,           /* value_table */
97       };
98
99       cell_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkCellRenderer", 
100                                           &cell_info, G_TYPE_FLAG_ABSTRACT);
101     }
102
103   return cell_type;
104 }
105
106 static void
107 gtk_cell_renderer_init (GtkCellRenderer *cell)
108 {
109   cell->mode = GTK_CELL_RENDERER_MODE_INERT;
110   cell->visible = TRUE;
111   cell->width = -1;
112   cell->height = -1;
113   cell->xalign = 0.5;
114   cell->yalign = 0.5;
115   cell->xpad = 0;
116   cell->ypad = 0;
117   cell->sensitive = TRUE;
118   cell->is_expander = FALSE;
119   cell->is_expanded = FALSE;
120   cell->editing = FALSE;
121 }
122
123 static void
124 gtk_cell_renderer_class_init (GtkCellRendererClass *class)
125 {
126   GObjectClass *object_class = G_OBJECT_CLASS (class);
127
128   object_class->get_property = gtk_cell_renderer_get_property;
129   object_class->set_property = gtk_cell_renderer_set_property;
130
131   class->render = NULL;
132   class->get_size = NULL;
133
134   /**
135    * GtkCellRenderer::editing-canceled:
136    * @renderer: the object which received the signal
137    *
138    * This signal gets emitted when the user cancels the process of editing a
139    * cell.  For example, an editable cell renderer could be written to cancel
140    * editing when the user presses Escape. 
141    *
142    * See also: gtk_cell_renderer_editing_canceled()
143    *
144    * Since: 2.4
145    */
146   cell_renderer_signals[EDITING_CANCELED] =
147     g_signal_new ("editing-canceled",
148                   G_OBJECT_CLASS_TYPE (object_class),
149                   G_SIGNAL_RUN_FIRST,
150                   G_STRUCT_OFFSET (GtkCellRendererClass, editing_canceled),
151                   NULL, NULL,
152                   _gtk_marshal_VOID__VOID,
153                   G_TYPE_NONE, 0);
154
155   /**
156    * GtkCellRenderer::editing-started:
157    * @renderer: the object which received the signal
158    * @editable: the #GtkCellEditable
159    * @path: the path identifying the edited cell
160    *
161    * This signal gets emitted when a cell starts to be edited.
162    * The indended use of this signal is to do special setup
163    * on @editable, e.g. adding a #GtkEntryCompletion or setting
164    * up additional columns in a #GtkComboBox.
165    *
166    * Note that GTK+ doesn't guarantee that cell renderers will
167    * continue to use the same kind of widget for editing in future
168    * releases, therefore you should check the type of @editable
169    * before doing any specific setup, as in the following example:
170    *
171    * <informalexample><programlisting>
172    * static void
173    * text_editing_started (GtkCellRenderer *cell,
174    *                       GtkCellEditable *editable,
175    *                       const gchar     *path,
176    *                       gpointer         data)
177    * {
178    *   if (GTK_IS_ENTRY (editable)) 
179    *     {
180    *       GtkEntry *entry = GTK_ENTRY (editable);
181    *       <!-- -->
182    *       /<!-- -->* ... create a GtkEntryCompletion *<!-- -->/
183    *       <!-- -->
184    *       gtk_entry_set_completion (entry, completion);
185    *     }
186    * }
187    * </programlisting></informalexample>
188    *
189    * Since: 2.6
190    */
191   cell_renderer_signals[EDITING_STARTED] =
192     g_signal_new ("editing-started",
193                   G_OBJECT_CLASS_TYPE (object_class),
194                   G_SIGNAL_RUN_FIRST,
195                   G_STRUCT_OFFSET (GtkCellRendererClass, editing_started),
196                   NULL, NULL,
197                   _gtk_marshal_VOID__OBJECT_STRING,
198                   G_TYPE_NONE, 2,
199                   GTK_TYPE_CELL_EDITABLE,
200                   G_TYPE_STRING);
201
202 #define STATIC_STRINGS G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
203
204   g_object_class_install_property (object_class,
205                                    PROP_MODE,
206                                    g_param_spec_enum ("mode",
207                                                       P_("mode"),
208                                                       P_("Editable mode of the CellRenderer"),
209                                                       GTK_TYPE_CELL_RENDERER_MODE,
210                                                       GTK_CELL_RENDERER_MODE_INERT,
211                                                       G_PARAM_READWRITE | STATIC_STRINGS));
212
213   g_object_class_install_property (object_class,
214                                    PROP_VISIBLE,
215                                    g_param_spec_boolean ("visible",
216                                                          P_("visible"),
217                                                          P_("Display the cell"),
218                                                          TRUE,
219                                                          G_PARAM_READWRITE | STATIC_STRINGS));
220   g_object_class_install_property (object_class,
221                                    PROP_SENSITIVE,
222                                    g_param_spec_boolean ("sensitive",
223                                                          P_("Sensitive"),
224                                                          P_("Display the cell sensitive"),
225                                                          TRUE,
226                                                          G_PARAM_READWRITE | STATIC_STRINGS));
227
228   g_object_class_install_property (object_class,
229                                    PROP_XALIGN,
230                                    g_param_spec_float ("xalign",
231                                                        P_("xalign"),
232                                                        P_("The x-align"),
233                                                        0.0,
234                                                        1.0,
235                                                        0.5,
236                                                        G_PARAM_READWRITE | STATIC_STRINGS));
237
238   g_object_class_install_property (object_class,
239                                    PROP_YALIGN,
240                                    g_param_spec_float ("yalign",
241                                                        P_("yalign"),
242                                                        P_("The y-align"),
243                                                        0.0,
244                                                        1.0,
245                                                        0.5,
246                                                        G_PARAM_READWRITE | STATIC_STRINGS));
247
248   g_object_class_install_property (object_class,
249                                    PROP_XPAD,
250                                    g_param_spec_uint ("xpad",
251                                                       P_("xpad"),
252                                                       P_("The xpad"),
253                                                       0,
254                                                       G_MAXUINT,
255                                                       0,
256                                                       G_PARAM_READWRITE | STATIC_STRINGS));
257
258   g_object_class_install_property (object_class,
259                                    PROP_YPAD,
260                                    g_param_spec_uint ("ypad",
261                                                       P_("ypad"),
262                                                       P_("The ypad"),
263                                                       0,
264                                                       G_MAXUINT,
265                                                       0,
266                                                       G_PARAM_READWRITE | STATIC_STRINGS));
267
268   g_object_class_install_property (object_class,
269                                    PROP_WIDTH,
270                                    g_param_spec_int ("width",
271                                                      P_("width"),
272                                                      P_("The fixed width"),
273                                                      -1,
274                                                      G_MAXINT,
275                                                      -1,
276                                                      G_PARAM_READWRITE | STATIC_STRINGS));
277
278   g_object_class_install_property (object_class,
279                                    PROP_HEIGHT,
280                                    g_param_spec_int ("height",
281                                                      P_("height"),
282                                                      P_("The fixed height"),
283                                                      -1,
284                                                      G_MAXINT,
285                                                      -1,
286                                                      G_PARAM_READWRITE | STATIC_STRING));
287
288   g_object_class_install_property (object_class,
289                                    PROP_IS_EXPANDER,
290                                    g_param_spec_boolean ("is-expander",
291                                                          P_("Is Expander"),
292                                                          P_("Row has children"),
293                                                          FALSE,
294                                                          G_PARAM_READWRITE | STATIC_STRINGS));
295
296
297   g_object_class_install_property (object_class,
298                                    PROP_IS_EXPANDED,
299                                    g_param_spec_boolean ("is-expanded",
300                                                          P_("Is Expanded"),
301                                                          P_("Row is an expander row, and is expanded"),
302                                                          FALSE,
303                                                          G_PARAM_READWRITE | STATIC_STRINGS));
304
305   g_object_class_install_property (object_class,
306                                    PROP_CELL_BACKGROUND,
307                                    g_param_spec_string ("cell-background",
308                                                         P_("Cell background color name"),
309                                                         P_("Cell background color as a string"),
310                                                         NULL,
311                                                         G_PARAM_WRITABLE | STATIC_STRINGS));
312
313   g_object_class_install_property (object_class,
314                                    PROP_CELL_BACKGROUND_GDK,
315                                    g_param_spec_boxed ("cell-background-gdk",
316                                                        P_("Cell background color"),
317                                                        P_("Cell background color as a GdkColor"),
318                                                        GDK_TYPE_COLOR,
319                                                        G_PARAM_READWRITE | STATIC_STRINGS));
320
321
322 #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_READWRITE | STATIC_STRINGS))
323
324   ADD_SET_PROP ("cell-background-set", PROP_CELL_BACKGROUND_SET,
325                 P_("Cell background set"),
326                 P_("Whether this tag affects the cell background color"));
327
328   g_type_class_add_private (object_class, sizeof (GtkCellRendererPrivate));
329 }
330
331 static void
332 gtk_cell_renderer_get_property (GObject     *object,
333                                 guint        param_id,
334                                 GValue      *value,
335                                 GParamSpec  *pspec)
336 {
337   GtkCellRenderer *cell = GTK_CELL_RENDERER (object);
338   GtkCellRendererPrivate *priv = GTK_CELL_RENDERER_GET_PRIVATE (object);
339
340   switch (param_id)
341     {
342     case PROP_MODE:
343       g_value_set_enum (value, cell->mode);
344       break;
345     case PROP_VISIBLE:
346       g_value_set_boolean (value, cell->visible);
347       break;
348     case PROP_SENSITIVE:
349       g_value_set_boolean (value, cell->sensitive);
350       break;
351     case PROP_XALIGN:
352       g_value_set_float (value, cell->xalign);
353       break;
354     case PROP_YALIGN:
355       g_value_set_float (value, cell->yalign);
356       break;
357     case PROP_XPAD:
358       g_value_set_uint (value, cell->xpad);
359       break;
360     case PROP_YPAD:
361       g_value_set_uint (value, cell->ypad);
362       break;
363     case PROP_WIDTH:
364       g_value_set_int (value, cell->width);
365       break;
366     case PROP_HEIGHT:
367       g_value_set_int (value, cell->height);
368       break;
369     case PROP_IS_EXPANDER:
370       g_value_set_boolean (value, cell->is_expander);
371       break;
372     case PROP_IS_EXPANDED:
373       g_value_set_boolean (value, cell->is_expanded);
374       break;
375     case PROP_CELL_BACKGROUND_GDK:
376       {
377         GdkColor color;
378
379         color.red = priv->cell_background.red;
380         color.green = priv->cell_background.green;
381         color.blue = priv->cell_background.blue;
382
383         g_value_set_boxed (value, &color);
384       }
385       break;
386     case PROP_CELL_BACKGROUND_SET:
387       g_value_set_boolean (value, cell->cell_background_set);
388       break;
389     case PROP_CELL_BACKGROUND:
390     default:
391       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
392       break;
393     }
394
395 }
396
397 static void
398 gtk_cell_renderer_set_property (GObject      *object,
399                                 guint         param_id,
400                                 const GValue *value,
401                                 GParamSpec   *pspec)
402 {
403   GtkCellRenderer *cell = GTK_CELL_RENDERER (object);
404
405   switch (param_id)
406     {
407     case PROP_MODE:
408       cell->mode = g_value_get_enum (value);
409       break;
410     case PROP_VISIBLE:
411       cell->visible = g_value_get_boolean (value);
412       break;
413     case PROP_SENSITIVE:
414       cell->sensitive = g_value_get_boolean (value);
415       break;
416     case PROP_XALIGN:
417       cell->xalign = g_value_get_float (value);
418       break;
419     case PROP_YALIGN:
420       cell->yalign = g_value_get_float (value);
421       break;
422     case PROP_XPAD:
423       cell->xpad = g_value_get_uint (value);
424       break;
425     case PROP_YPAD:
426       cell->ypad = g_value_get_uint (value);
427       break;
428     case PROP_WIDTH:
429       cell->width = g_value_get_int (value);
430       break;
431     case PROP_HEIGHT:
432       cell->height = g_value_get_int (value);
433       break;
434     case PROP_IS_EXPANDER:
435       cell->is_expander = g_value_get_boolean (value);
436       break;
437     case PROP_IS_EXPANDED:
438       cell->is_expanded = g_value_get_boolean (value);
439       break;
440     case PROP_CELL_BACKGROUND:
441       {
442         GdkColor color;
443
444         if (!g_value_get_string (value))
445           set_cell_bg_color (cell, NULL);
446         else if (gdk_color_parse (g_value_get_string (value), &color))
447           set_cell_bg_color (cell, &color);
448         else
449           g_warning ("Don't know color `%s'", g_value_get_string (value));
450
451         g_object_notify (object, "cell_background_gdk");
452       }
453       break;
454     case PROP_CELL_BACKGROUND_GDK:
455       set_cell_bg_color (cell, g_value_get_boxed (value));
456       break;
457     case PROP_CELL_BACKGROUND_SET:
458       cell->cell_background_set = g_value_get_boolean (value);
459       break;
460     default:
461       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
462       break;
463     }
464 }
465
466 static void
467 set_cell_bg_color (GtkCellRenderer *cell,
468                    GdkColor        *color)
469 {
470   GtkCellRendererPrivate *priv = GTK_CELL_RENDERER_GET_PRIVATE (cell);
471
472   if (color)
473     {
474       if (!cell->cell_background_set)
475         {
476           cell->cell_background_set = TRUE;
477           g_object_notify (G_OBJECT (cell), "cell_background_set");
478         }
479
480       priv->cell_background.red = color->red;
481       priv->cell_background.green = color->green;
482       priv->cell_background.blue = color->blue;
483     }
484   else
485     {
486       if (cell->cell_background_set)
487         {
488           cell->cell_background_set = FALSE;
489           g_object_notify (G_OBJECT (cell), "cell_background_set");
490         }
491     }
492 }
493
494 /**
495  * gtk_cell_renderer_get_size:
496  * @cell: a #GtkCellRenderer
497  * @widget: the widget the renderer is rendering to
498  * @cell_area: The area a cell will be allocated, or %NULL
499  * @x_offset: location to return x offset of cell relative to @cell_area, or %NULL
500  * @y_offset: location to return y offset of cell relative to @cell_area, or %NULL
501  * @width: location to return width needed to render a cell, or %NULL
502  * @height: location to return height needed to render a cell, or %NULL
503  *
504  * Obtains the width and height needed to render the cell. Used by view widgets
505  * to determine the appropriate size for the cell_area passed to
506  * gtk_cell_renderer_render().  If @cell_area is not %NULL, fills in the x and y
507  * offsets (if set) of the cell relative to this location.  Please note that the
508  * values set in @width and @height, as well as those in @x_offset and @y_offset
509  * are inclusive of the xpad and ypad properties.
510  **/
511 void
512 gtk_cell_renderer_get_size (GtkCellRenderer *cell,
513                             GtkWidget       *widget,
514                             GdkRectangle    *cell_area,
515                             gint            *x_offset,
516                             gint            *y_offset,
517                             gint            *width,
518                             gint            *height)
519 {
520   gint *real_width = width;
521   gint *real_height = height;
522
523   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
524   g_return_if_fail (GTK_CELL_RENDERER_GET_CLASS (cell)->get_size != NULL);
525
526   if (width && cell->width != -1)
527     {
528       real_width = NULL;
529       *width = cell->width;
530     }
531   if (height && cell->height != -1)
532     {
533       real_height = NULL;
534       *height = cell->height;
535     }
536
537   GTK_CELL_RENDERER_GET_CLASS (cell)->get_size (cell,
538                                                 widget,
539                                                 cell_area,
540                                                 x_offset,
541                                                 y_offset,
542                                                 real_width,
543                                                 real_height);
544 }
545
546 /**
547  * gtk_cell_renderer_render:
548  * @cell: a #GtkCellRenderer
549  * @window: a #GdkDrawable to draw to
550  * @widget: the widget owning @window
551  * @background_area: entire cell area (including tree expanders and maybe padding on the sides)
552  * @cell_area: area normally rendered by a cell renderer
553  * @expose_area: area that actually needs updating
554  * @flags: flags that affect rendering
555  *
556  * Invokes the virtual render function of the #GtkCellRenderer. The three
557  * passed-in rectangles are areas of @window. Most renderers will draw within
558  * @cell_area; the xalign, yalign, xpad, and ypad fields of the #GtkCellRenderer
559  * should be honored with respect to @cell_area. @background_area includes the
560  * blank space around the cell, and also the area containing the tree expander;
561  * so the @background_area rectangles for all cells tile to cover the entire
562  * @window.  @expose_area is a clip rectangle.
563  *
564  **/
565 void
566 gtk_cell_renderer_render (GtkCellRenderer     *cell,
567                           GdkWindow           *window,
568                           GtkWidget           *widget,
569                           GdkRectangle        *background_area,
570                           GdkRectangle        *cell_area,
571                           GdkRectangle        *expose_area,
572                           GtkCellRendererState flags)
573 {
574   gboolean selected = FALSE;
575   GtkCellRendererPrivate *priv = GTK_CELL_RENDERER_GET_PRIVATE (cell);
576
577   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
578   g_return_if_fail (GTK_CELL_RENDERER_GET_CLASS (cell)->render != NULL);
579
580   selected = (flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED;
581
582   if (cell->cell_background_set && !selected)
583     {
584       GdkColor color;
585       GdkGC *gc;
586
587       color.red = priv->cell_background.red;
588       color.green = priv->cell_background.green;
589       color.blue = priv->cell_background.blue;
590
591       gc = gdk_gc_new (window);
592       gdk_gc_set_rgb_fg_color (gc, &color);
593       gdk_draw_rectangle (window, gc, TRUE,
594                           background_area->x, background_area->y,
595                           background_area->width, background_area->height);
596       g_object_unref (gc);
597     }
598
599   GTK_CELL_RENDERER_GET_CLASS (cell)->render (cell,
600                                               window,
601                                               widget,
602                                               background_area,
603                                               cell_area,
604                                               expose_area,
605                                               flags);
606 }
607
608 /**
609  * gtk_cell_renderer_activate:
610  * @cell: a #GtkCellRenderer
611  * @event: a #GdkEvent
612  * @widget: widget that received the event
613  * @path: widget-dependent string representation of the event location; e.g. for #GtkTreeView, a string representation of #GtkTreePath
614  * @background_area: background area as passed to @gtk_cell_renderer_render
615  * @cell_area: cell area as passed to @gtk_cell_renderer_render
616  * @flags: render flags
617  *
618  * Passes an activate event to the cell renderer for possible processing.  Some
619  * cell renderers may use events; for example, #GtkCellRendererToggle toggles
620  * when it gets a mouse click.
621  *
622  * Return value: %TRUE if the event was consumed/handled
623  **/
624 gboolean
625 gtk_cell_renderer_activate (GtkCellRenderer      *cell,
626                             GdkEvent             *event,
627                             GtkWidget            *widget,
628                             const gchar          *path,
629                             GdkRectangle         *background_area,
630                             GdkRectangle         *cell_area,
631                             GtkCellRendererState  flags)
632 {
633   g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
634
635   if (cell->mode != GTK_CELL_RENDERER_MODE_ACTIVATABLE)
636     return FALSE;
637
638   if (GTK_CELL_RENDERER_GET_CLASS (cell)->activate == NULL)
639     return FALSE;
640
641   return GTK_CELL_RENDERER_GET_CLASS (cell)->activate (cell,
642                                                        event,
643                                                        widget,
644                                                        path,
645                                                        background_area,
646                                                        cell_area,
647                                                        flags);
648 }
649
650 /**
651  * gtk_cell_renderer_start_editing:
652  * @cell: a #GtkCellRenderer
653  * @event: a #GdkEvent
654  * @widget: widget that received the event
655  * @path: widget-dependent string representation of the event location; e.g. for #GtkTreeView, a string representation of #GtkTreePath
656  * @background_area: background area as passed to @gtk_cell_renderer_render
657  * @cell_area: cell area as passed to @gtk_cell_renderer_render
658  * @flags: render flags
659  * 
660  * Passes an activate event to the cell renderer for possible processing.
661  * 
662  * Return value: A new #GtkCellEditable, or %NULL
663  **/
664 GtkCellEditable *
665 gtk_cell_renderer_start_editing (GtkCellRenderer      *cell,
666                                  GdkEvent             *event,
667                                  GtkWidget            *widget,
668                                  const gchar          *path,
669                                  GdkRectangle         *background_area,
670                                  GdkRectangle         *cell_area,
671                                  GtkCellRendererState  flags)
672
673 {
674   GtkCellEditable *editable;
675
676   g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), NULL);
677
678   if (cell->mode != GTK_CELL_RENDERER_MODE_EDITABLE)
679     return NULL;
680
681   if (GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing == NULL)
682     return NULL;
683
684   editable = GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing (cell,
685                                                                 event,
686                                                                 widget,
687                                                                 path,
688                                                                 background_area,
689                                                                 cell_area,
690                                                                 flags);
691
692   g_signal_emit (cell, 
693                  cell_renderer_signals[EDITING_STARTED], 0,
694                  editable, path);
695
696   cell->editing = TRUE;
697
698   return editable;
699 }
700
701 /**
702  * gtk_cell_renderer_set_fixed_size:
703  * @cell: A #GtkCellRenderer
704  * @width: the width of the cell renderer, or -1
705  * @height: the height of the cell renderer, or -1
706  * 
707  * Sets the renderer size to be explicit, independent of the properties set.
708  **/
709 void
710 gtk_cell_renderer_set_fixed_size (GtkCellRenderer *cell,
711                                   gint             width,
712                                   gint             height)
713 {
714   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
715   g_return_if_fail (width >= -1 && height >= -1);
716
717   if ((width != cell->width) || (height != cell->height))
718     {
719       g_object_freeze_notify (G_OBJECT (cell));
720
721       if (width != cell->width)
722         {
723           cell->width = width;
724           g_object_notify (G_OBJECT (cell), "width");
725         }
726
727       if (height != cell->height)
728         {
729           cell->height = height;
730           g_object_notify (G_OBJECT (cell), "height");
731         }
732
733       g_object_thaw_notify (G_OBJECT (cell));
734     }
735 }
736
737 /**
738  * gtk_cell_renderer_get_fixed_size:
739  * @cell: A #GtkCellRenderer
740  * @width: location to fill in with the fixed width of the widget, or %NULL
741  * @height: location to fill in with the fixed height of the widget, or %NULL
742  * 
743  * Fills in @width and @height with the appropriate size of @cell.
744  **/
745 void
746 gtk_cell_renderer_get_fixed_size (GtkCellRenderer *cell,
747                                   gint            *width,
748                                   gint            *height)
749 {
750   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
751
752   if (width)
753     (* width) = cell->width;
754   if (height)
755     (* height) = cell->height;
756 }
757
758 /**
759  * gtk_cell_renderer_editing_canceled:
760  * @cell: A #GtkCellRenderer
761  * 
762  * Causes the cell renderer to emit the "editing-canceled" signal.  This
763  * function is for use only by implementations of cell renderers that need to
764  * notify the client program that an editing process was canceled and the
765  * changes were not committed.
766  *
767  * Since: 2.4
768  * Deprecated: Use gtk_cell_renderer_stop_editing() instead
769  **/
770 void
771 gtk_cell_renderer_editing_canceled (GtkCellRenderer *cell)
772 {
773   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
774
775   gtk_cell_renderer_stop_editing (cell, TRUE);
776 }
777
778 /**
779  * gtk_cell_renderer_stop_editing:
780  * @cell: A #GtkCellRenderer
781  * @canceled: %TRUE if the editing has been canceled
782  * 
783  * Informs the cell renderer that the editing is stopped.
784  * If @canceled is %TRUE, the cell renderer will emit the "editing-canceled" 
785  * signal. This function should be called by cell renderer implementations 
786  * in response to the "editing-done" signal of #GtkCellEditable.
787  *
788  * Since: 2.6
789  **/
790 void
791 gtk_cell_renderer_stop_editing (GtkCellRenderer *cell,
792                                 gboolean         canceled)
793 {
794   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
795
796   if (cell->editing)
797     {
798       cell->editing = FALSE;
799       if (canceled)
800         g_signal_emit (cell, cell_renderer_signals[EDITING_CANCELED], 0);
801     }
802 }
803
804 #define __GTK_CELL_RENDERER_C__
805 #include "gtkaliasdef.c"