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