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