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, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "config.h"
19 #include "gtkcellrenderer.h"
20 #include "gtkintl.h"
21 #include "gtkmarshalers.h"
22 #include "gtktypebuiltins.h"
23 #include "gtkprivate.h"
24 #include "gtktreeprivate.h"
25 #include "a11y/gtkrenderercellaccessible.h"
26 
27 
28 /**
29  * SECTION:gtkcellrenderer
30  * @Short_description: An object for rendering a single cell
31  * @Title: GtkCellRenderer
32  * @See_also: #GtkCellEditable
33  *
34  * The #GtkCellRenderer is a base class of a set of objects used for
35  * rendering a cell to a #cairo_t.  These objects are used primarily by
36  * the #GtkTreeView widget, though they aren’t tied to them in any
37  * specific way.  It is worth noting that #GtkCellRenderer is not a
38  * #GtkWidget and cannot be treated as such.
39  *
40  * The primary use of a #GtkCellRenderer is for drawing a certain graphical
41  * elements on a #cairo_t. Typically, one cell renderer is used to
42  * draw many cells on the screen.  To this extent, it isn’t expected that a
43  * CellRenderer keep any permanent state around.  Instead, any state is set
44  * just prior to use using #GObjects property system.  Then, the
45  * cell is measured using gtk_cell_renderer_get_size(). Finally, the cell
46  * is rendered in the correct location using gtk_cell_renderer_render().
47  *
48  * There are a number of rules that must be followed when writing a new
49  * #GtkCellRenderer.  First and foremost, it’s important that a certain set
50  * of properties will always yield a cell renderer of the same size,
51  * barring a #GtkStyle change.  The #GtkCellRenderer also has a number of
52  * generic properties that are expected to be honored by all children.
53  *
54  * Beyond merely rendering a cell, cell renderers can optionally
55  * provide active user interface elements. A cell renderer can be
56  * “activatable” like #GtkCellRendererToggle,
57  * which toggles when it gets activated by a mouse click, or it can be
58  * “editable” like #GtkCellRendererText, which
59  * allows the user to edit the text using a widget implementing the
60  * #GtkCellEditable interface, e.g. #GtkEntry.
61  * To make a cell renderer activatable or editable, you have to
62  * implement the #GtkCellRendererClass.activate or
63  * #GtkCellRendererClass.start_editing virtual functions, respectively.
64  *
65  * Many properties of #GtkCellRenderer and its subclasses have a
66  * corresponding “set” property, e.g. “cell-background-set” corresponds
67  * to “cell-background”. These “set” properties reflect whether a property
68  * has been set or not. You should not set them independently.
69  */
70 
71 
72 #define DEBUG_CELL_SIZE_REQUEST 0
73 
74 static void gtk_cell_renderer_init          (GtkCellRenderer      *cell);
75 static void gtk_cell_renderer_class_init    (GtkCellRendererClass *class);
76 static void gtk_cell_renderer_get_property  (GObject              *object,
77 					     guint                 param_id,
78 					     GValue               *value,
79 					     GParamSpec           *pspec);
80 static void gtk_cell_renderer_set_property  (GObject              *object,
81 					     guint                 param_id,
82 					     const GValue         *value,
83 					     GParamSpec           *pspec);
84 static void set_cell_bg_color               (GtkCellRenderer      *cell,
85 					     GdkRGBA              *rgba);
86 
87 /* Fallback GtkCellRenderer    implementation to use remaining ->get_size() implementations */
88 static GtkSizeRequestMode gtk_cell_renderer_real_get_request_mode(GtkCellRenderer         *cell);
89 static void gtk_cell_renderer_real_get_preferred_width           (GtkCellRenderer         *cell,
90                                                                   GtkWidget               *widget,
91                                                                   gint                    *minimum_size,
92                                                                   gint                    *natural_size);
93 static void gtk_cell_renderer_real_get_preferred_height          (GtkCellRenderer         *cell,
94                                                                   GtkWidget               *widget,
95                                                                   gint                    *minimum_size,
96                                                                   gint                    *natural_size);
97 static void gtk_cell_renderer_real_get_preferred_height_for_width(GtkCellRenderer         *cell,
98                                                                   GtkWidget               *widget,
99                                                                   gint                     width,
100                                                                   gint                    *minimum_height,
101                                                                   gint                    *natural_height);
102 static void gtk_cell_renderer_real_get_preferred_width_for_height(GtkCellRenderer         *cell,
103                                                                   GtkWidget               *widget,
104                                                                   gint                     height,
105                                                                   gint                    *minimum_width,
106                                                                   gint                    *natural_width);
107 static void gtk_cell_renderer_real_get_aligned_area              (GtkCellRenderer         *cell,
108 								  GtkWidget               *widget,
109 								  GtkCellRendererState     flags,
110 								  const GdkRectangle      *cell_area,
111 								  GdkRectangle            *aligned_area);
112 
113 
114 struct _GtkCellRendererPrivate
115 {
116   gfloat xalign;
117   gfloat yalign;
118 
119   gint width;
120   gint height;
121 
122   guint16 xpad;
123   guint16 ypad;
124 
125   guint mode                : 2;
126   guint visible             : 1;
127   guint is_expander         : 1;
128   guint is_expanded         : 1;
129   guint cell_background_set : 1;
130   guint sensitive           : 1;
131   guint editing             : 1;
132 
133   GdkRGBA cell_background;
134 };
135 
136 struct _GtkCellRendererClassPrivate
137 {
138   GType accessible_type;
139 };
140 
141 enum {
142   PROP_0,
143   PROP_MODE,
144   PROP_VISIBLE,
145   PROP_SENSITIVE,
146   PROP_XALIGN,
147   PROP_YALIGN,
148   PROP_XPAD,
149   PROP_YPAD,
150   PROP_WIDTH,
151   PROP_HEIGHT,
152   PROP_IS_EXPANDER,
153   PROP_IS_EXPANDED,
154   PROP_CELL_BACKGROUND,
155   PROP_CELL_BACKGROUND_GDK,
156   PROP_CELL_BACKGROUND_RGBA,
157   PROP_CELL_BACKGROUND_SET,
158   PROP_EDITING
159 };
160 
161 /* Signal IDs */
162 enum {
163   EDITING_CANCELED,
164   EDITING_STARTED,
165   LAST_SIGNAL
166 };
167 
168 static gint GtkCellRenderer_private_offset;
169 static guint  cell_renderer_signals[LAST_SIGNAL] = { 0 };
170 
171 static inline gpointer
gtk_cell_renderer_get_instance_private(GtkCellRenderer * self)172 gtk_cell_renderer_get_instance_private (GtkCellRenderer *self)
173 {
174   return (G_STRUCT_MEMBER_P (self, GtkCellRenderer_private_offset));
175 }
176 
177 static void
gtk_cell_renderer_init(GtkCellRenderer * cell)178 gtk_cell_renderer_init (GtkCellRenderer *cell)
179 {
180   GtkCellRendererPrivate *priv;
181 
182   cell->priv = gtk_cell_renderer_get_instance_private (cell);
183   priv = cell->priv;
184 
185   priv->mode = GTK_CELL_RENDERER_MODE_INERT;
186   priv->visible = TRUE;
187   priv->width = -1;
188   priv->height = -1;
189   priv->xalign = 0.5;
190   priv->yalign = 0.5;
191   priv->xpad = 0;
192   priv->ypad = 0;
193   priv->sensitive = TRUE;
194   priv->is_expander = FALSE;
195   priv->is_expanded = FALSE;
196   priv->editing = FALSE;
197 }
198 
199 static void
gtk_cell_renderer_class_init(GtkCellRendererClass * class)200 gtk_cell_renderer_class_init (GtkCellRendererClass *class)
201 {
202   GObjectClass *object_class = G_OBJECT_CLASS (class);
203 
204   object_class->get_property = gtk_cell_renderer_get_property;
205   object_class->set_property = gtk_cell_renderer_set_property;
206 
207   class->render = NULL;
208   class->get_size = NULL;
209   class->get_request_mode               = gtk_cell_renderer_real_get_request_mode;
210   class->get_preferred_width            = gtk_cell_renderer_real_get_preferred_width;
211   class->get_preferred_height           = gtk_cell_renderer_real_get_preferred_height;
212   class->get_preferred_width_for_height = gtk_cell_renderer_real_get_preferred_width_for_height;
213   class->get_preferred_height_for_width = gtk_cell_renderer_real_get_preferred_height_for_width;
214   class->get_aligned_area               = gtk_cell_renderer_real_get_aligned_area;
215 
216   /**
217    * GtkCellRenderer::editing-canceled:
218    * @renderer: the object which received the signal
219    *
220    * This signal gets emitted when the user cancels the process of editing a
221    * cell.  For example, an editable cell renderer could be written to cancel
222    * editing when the user presses Escape.
223    *
224    * See also: gtk_cell_renderer_stop_editing().
225    *
226    * Since: 2.4
227    */
228   cell_renderer_signals[EDITING_CANCELED] =
229     g_signal_new (I_("editing-canceled"),
230 		  G_OBJECT_CLASS_TYPE (object_class),
231 		  G_SIGNAL_RUN_FIRST,
232 		  G_STRUCT_OFFSET (GtkCellRendererClass, editing_canceled),
233 		  NULL, NULL,
234 		  NULL,
235 		  G_TYPE_NONE, 0);
236 
237   /**
238    * GtkCellRenderer::editing-started:
239    * @renderer: the object which received the signal
240    * @editable: the #GtkCellEditable
241    * @path: the path identifying the edited cell
242    *
243    * This signal gets emitted when a cell starts to be edited.
244    * The intended use of this signal is to do special setup
245    * on @editable, e.g. adding a #GtkEntryCompletion or setting
246    * up additional columns in a #GtkComboBox.
247    *
248    * See gtk_cell_editable_start_editing() for information on the lifecycle of
249    * the @editable and a way to do setup that doesn’t depend on the @renderer.
250    *
251    * Note that GTK+ doesn't guarantee that cell renderers will
252    * continue to use the same kind of widget for editing in future
253    * releases, therefore you should check the type of @editable
254    * before doing any specific setup, as in the following example:
255    * |[<!-- language="C" -->
256    * static void
257    * text_editing_started (GtkCellRenderer *cell,
258    *                       GtkCellEditable *editable,
259    *                       const gchar     *path,
260    *                       gpointer         data)
261    * {
262    *   if (GTK_IS_ENTRY (editable))
263    *     {
264    *       GtkEntry *entry = GTK_ENTRY (editable);
265    *
266    *       // ... create a GtkEntryCompletion
267    *
268    *       gtk_entry_set_completion (entry, completion);
269    *     }
270    * }
271    * ]|
272    *
273    * Since: 2.6
274    */
275   cell_renderer_signals[EDITING_STARTED] =
276     g_signal_new (I_("editing-started"),
277 		  G_OBJECT_CLASS_TYPE (object_class),
278 		  G_SIGNAL_RUN_FIRST,
279 		  G_STRUCT_OFFSET (GtkCellRendererClass, editing_started),
280 		  NULL, NULL,
281 		  _gtk_marshal_VOID__OBJECT_STRING,
282 		  G_TYPE_NONE, 2,
283 		  GTK_TYPE_CELL_EDITABLE,
284 		  G_TYPE_STRING);
285   g_signal_set_va_marshaller (cell_renderer_signals[EDITING_STARTED],
286                               G_TYPE_FROM_CLASS (object_class),
287                               _gtk_marshal_VOID__OBJECT_STRINGv);
288 
289   g_object_class_install_property (object_class,
290 				   PROP_MODE,
291 				   g_param_spec_enum ("mode",
292 						      P_("mode"),
293 						      P_("Editable mode of the CellRenderer"),
294 						      GTK_TYPE_CELL_RENDERER_MODE,
295 						      GTK_CELL_RENDERER_MODE_INERT,
296 						      GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
297 
298   g_object_class_install_property (object_class,
299 				   PROP_VISIBLE,
300 				   g_param_spec_boolean ("visible",
301 							 P_("visible"),
302 							 P_("Display the cell"),
303 							 TRUE,
304 							 GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
305   g_object_class_install_property (object_class,
306 				   PROP_SENSITIVE,
307 				   g_param_spec_boolean ("sensitive",
308 							 P_("Sensitive"),
309 							 P_("Display the cell sensitive"),
310 							 TRUE,
311 							 GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
312 
313   g_object_class_install_property (object_class,
314 				   PROP_XALIGN,
315 				   g_param_spec_float ("xalign",
316 						       P_("xalign"),
317 						       P_("The x-align"),
318 						       0.0,
319 						       1.0,
320 						       0.5,
321 						       GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
322 
323   g_object_class_install_property (object_class,
324 				   PROP_YALIGN,
325 				   g_param_spec_float ("yalign",
326 						       P_("yalign"),
327 						       P_("The y-align"),
328 						       0.0,
329 						       1.0,
330 						       0.5,
331 						       GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
332 
333   g_object_class_install_property (object_class,
334 				   PROP_XPAD,
335 				   g_param_spec_uint ("xpad",
336 						      P_("xpad"),
337 						      P_("The xpad"),
338 						      0,
339 						      G_MAXUINT,
340 						      0,
341 						      GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
342 
343   g_object_class_install_property (object_class,
344 				   PROP_YPAD,
345 				   g_param_spec_uint ("ypad",
346 						      P_("ypad"),
347 						      P_("The ypad"),
348 						      0,
349 						      G_MAXUINT,
350 						      0,
351 						      GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
352 
353   g_object_class_install_property (object_class,
354 				   PROP_WIDTH,
355 				   g_param_spec_int ("width",
356 						     P_("width"),
357 						     P_("The fixed width"),
358 						     -1,
359 						     G_MAXINT,
360 						     -1,
361 						     GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
362 
363   g_object_class_install_property (object_class,
364 				   PROP_HEIGHT,
365 				   g_param_spec_int ("height",
366 						     P_("height"),
367 						     P_("The fixed height"),
368 						     -1,
369 						     G_MAXINT,
370 						     -1,
371 						     GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
372 
373   g_object_class_install_property (object_class,
374 				   PROP_IS_EXPANDER,
375 				   g_param_spec_boolean ("is-expander",
376 							 P_("Is Expander"),
377 							 P_("Row has children"),
378 							 FALSE,
379 							 GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
380 
381 
382   g_object_class_install_property (object_class,
383 				   PROP_IS_EXPANDED,
384 				   g_param_spec_boolean ("is-expanded",
385 							 P_("Is Expanded"),
386 							 P_("Row is an expander row, and is expanded"),
387 							 FALSE,
388 							 GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
389 
390   g_object_class_install_property (object_class,
391 				   PROP_CELL_BACKGROUND,
392 				   g_param_spec_string ("cell-background",
393 							P_("Cell background color name"),
394 							P_("Cell background color as a string"),
395 							NULL,
396 							GTK_PARAM_WRITABLE));
397 
398   /**
399    * GtkCellRenderer:cell-background-gdk:
400    *
401    * Cell background as a #GdkColor
402    *
403    * Deprecated: 3.4: Use #GtkCellRenderer:cell-background-rgba instead.
404    */
405 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
406   g_object_class_install_property (object_class,
407 				   PROP_CELL_BACKGROUND_GDK,
408 				   g_param_spec_boxed ("cell-background-gdk",
409 						       P_("Cell background color"),
410 						       P_("Cell background color as a GdkColor"),
411 						       GDK_TYPE_COLOR,
412 						       GTK_PARAM_READWRITE|G_PARAM_DEPRECATED));
413 G_GNUC_END_IGNORE_DEPRECATIONS
414   /**
415    * GtkCellRenderer:cell-background-rgba:
416    *
417    * Cell background as a #GdkRGBA
418    *
419    * Since: 3.0
420    */
421   g_object_class_install_property (object_class,
422 				   PROP_CELL_BACKGROUND_RGBA,
423 				   g_param_spec_boxed ("cell-background-rgba",
424 						       P_("Cell background RGBA color"),
425 						       P_("Cell background color as a GdkRGBA"),
426 						       GDK_TYPE_RGBA,
427 						       GTK_PARAM_READWRITE));
428 
429   g_object_class_install_property (object_class,
430 				   PROP_EDITING,
431 				   g_param_spec_boolean ("editing",
432 							 P_("Editing"),
433 							 P_("Whether the cell renderer is currently in editing mode"),
434 							 FALSE,
435 							 GTK_PARAM_READABLE));
436 
437 
438 #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|G_PARAM_EXPLICIT_NOTIFY))
439 
440   ADD_SET_PROP ("cell-background-set", PROP_CELL_BACKGROUND_SET,
441                 P_("Cell background set"),
442                 P_("Whether the cell background color is set"));
443 
444   if (GtkCellRenderer_private_offset != 0)
445     g_type_class_adjust_private_offset (class, &GtkCellRenderer_private_offset);
446 
447   gtk_cell_renderer_class_set_accessible_type (class, GTK_TYPE_RENDERER_CELL_ACCESSIBLE);
448 }
449 
450 static void
gtk_cell_renderer_base_class_init(gpointer g_class)451 gtk_cell_renderer_base_class_init (gpointer g_class)
452 {
453   GtkCellRendererClass *klass = g_class;
454 
455   klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_CELL_RENDERER, GtkCellRendererClassPrivate);
456 }
457 
458 GType
gtk_cell_renderer_get_type(void)459 gtk_cell_renderer_get_type (void)
460 {
461   static GType cell_renderer_type = 0;
462 
463   if (G_UNLIKELY (cell_renderer_type == 0))
464     {
465       const GTypeInfo cell_renderer_info =
466       {
467 	sizeof (GtkCellRendererClass),
468 	gtk_cell_renderer_base_class_init,
469         NULL,
470 	(GClassInitFunc) gtk_cell_renderer_class_init,
471 	NULL,		/* class_finalize */
472 	NULL,		/* class_init */
473 	sizeof (GtkWidget),
474 	0,		/* n_preallocs */
475 	(GInstanceInitFunc) gtk_cell_renderer_init,
476 	NULL,		/* value_table */
477       };
478       cell_renderer_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkCellRenderer",
479                                                    &cell_renderer_info, G_TYPE_FLAG_ABSTRACT);
480 
481       GtkCellRenderer_private_offset =
482         g_type_add_instance_private (cell_renderer_type, sizeof (GtkCellRendererPrivate));
483       g_type_add_class_private (cell_renderer_type, sizeof (GtkCellRendererClassPrivate));
484     }
485 
486   return cell_renderer_type;
487 }
488 
489 static void
gtk_cell_renderer_get_property(GObject * object,guint param_id,GValue * value,GParamSpec * pspec)490 gtk_cell_renderer_get_property (GObject     *object,
491 				guint        param_id,
492 				GValue      *value,
493 				GParamSpec  *pspec)
494 {
495   GtkCellRenderer *cell = GTK_CELL_RENDERER (object);
496   GtkCellRendererPrivate *priv = cell->priv;
497 
498   switch (param_id)
499     {
500     case PROP_MODE:
501       g_value_set_enum (value, priv->mode);
502       break;
503     case PROP_VISIBLE:
504       g_value_set_boolean (value, priv->visible);
505       break;
506     case PROP_SENSITIVE:
507       g_value_set_boolean (value, priv->sensitive);
508       break;
509     case PROP_EDITING:
510       g_value_set_boolean (value, priv->editing);
511       break;
512     case PROP_XALIGN:
513       g_value_set_float (value, priv->xalign);
514       break;
515     case PROP_YALIGN:
516       g_value_set_float (value, priv->yalign);
517       break;
518     case PROP_XPAD:
519       g_value_set_uint (value, priv->xpad);
520       break;
521     case PROP_YPAD:
522       g_value_set_uint (value, priv->ypad);
523       break;
524     case PROP_WIDTH:
525       g_value_set_int (value, priv->width);
526       break;
527     case PROP_HEIGHT:
528       g_value_set_int (value, priv->height);
529       break;
530     case PROP_IS_EXPANDER:
531       g_value_set_boolean (value, priv->is_expander);
532       break;
533     case PROP_IS_EXPANDED:
534       g_value_set_boolean (value, priv->is_expanded);
535       break;
536     case PROP_CELL_BACKGROUND_GDK:
537       {
538 	GdkColor color;
539 
540 	color.red = (guint16) (priv->cell_background.red * 65535);
541 	color.green = (guint16) (priv->cell_background.green * 65535);
542 	color.blue = (guint16) (priv->cell_background.blue * 65535);
543 
544 	g_value_set_boxed (value, &color);
545       }
546       break;
547     case PROP_CELL_BACKGROUND_RGBA:
548       g_value_set_boxed (value, &priv->cell_background);
549       break;
550     case PROP_CELL_BACKGROUND_SET:
551       g_value_set_boolean (value, priv->cell_background_set);
552       break;
553     case PROP_CELL_BACKGROUND:
554     default:
555       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
556       break;
557     }
558 
559 }
560 
561 static void
gtk_cell_renderer_set_property(GObject * object,guint param_id,const GValue * value,GParamSpec * pspec)562 gtk_cell_renderer_set_property (GObject      *object,
563 				guint         param_id,
564 				const GValue *value,
565 				GParamSpec   *pspec)
566 {
567   GtkCellRenderer *cell = GTK_CELL_RENDERER (object);
568   GtkCellRendererPrivate *priv = cell->priv;
569 
570   switch (param_id)
571     {
572     case PROP_MODE:
573       if (priv->mode != g_value_get_enum (value))
574         {
575           priv->mode = g_value_get_enum (value);
576           g_object_notify_by_pspec (object, pspec);
577         }
578       break;
579     case PROP_VISIBLE:
580       if (priv->visible != g_value_get_boolean (value))
581         {
582           priv->visible = g_value_get_boolean (value);
583           g_object_notify_by_pspec (object, pspec);
584         }
585       break;
586     case PROP_SENSITIVE:
587       if (priv->sensitive != g_value_get_boolean (value))
588         {
589           priv->sensitive = g_value_get_boolean (value);
590           g_object_notify_by_pspec (object, pspec);
591         }
592       break;
593     case PROP_XALIGN:
594       if (priv->xalign != g_value_get_float (value))
595         {
596           priv->xalign = g_value_get_float (value);
597           g_object_notify_by_pspec (object, pspec);
598         }
599       break;
600     case PROP_YALIGN:
601       if (priv->yalign != g_value_get_float (value))
602         {
603           priv->yalign = g_value_get_float (value);
604           g_object_notify_by_pspec (object, pspec);
605         }
606       break;
607     case PROP_XPAD:
608       if (priv->xpad != g_value_get_uint (value))
609         {
610           priv->xpad = g_value_get_uint (value);
611           g_object_notify_by_pspec (object, pspec);
612         }
613       break;
614     case PROP_YPAD:
615       if (priv->ypad != g_value_get_uint (value))
616         {
617           priv->ypad = g_value_get_uint (value);
618           g_object_notify_by_pspec (object, pspec);
619         }
620       break;
621     case PROP_WIDTH:
622       if (priv->width != g_value_get_int (value))
623         {
624           priv->width = g_value_get_int (value);
625           g_object_notify_by_pspec (object, pspec);
626         }
627       break;
628     case PROP_HEIGHT:
629       if (priv->height != g_value_get_int (value))
630         {
631           priv->height = g_value_get_int (value);
632           g_object_notify_by_pspec (object, pspec);
633         }
634       break;
635     case PROP_IS_EXPANDER:
636       if (priv->is_expander != g_value_get_boolean (value))
637         {
638           priv->is_expander = g_value_get_boolean (value);
639           g_object_notify_by_pspec (object, pspec);
640         }
641       break;
642     case PROP_IS_EXPANDED:
643       if (priv->is_expanded != g_value_get_boolean (value))
644         {
645           priv->is_expanded = g_value_get_boolean (value);
646           g_object_notify_by_pspec (object, pspec);
647         }
648       break;
649     case PROP_CELL_BACKGROUND:
650       {
651         GdkRGBA rgba;
652 
653         if (!g_value_get_string (value))
654           set_cell_bg_color (cell, NULL);
655         else if (gdk_rgba_parse (&rgba, g_value_get_string (value)))
656           set_cell_bg_color (cell, &rgba);
657         else
658           g_warning ("Don't know color '%s'", g_value_get_string (value));
659 
660         g_object_notify (object, "cell-background");
661       }
662       break;
663     case PROP_CELL_BACKGROUND_GDK:
664       {
665         GdkColor *color;
666 
667         color = g_value_get_boxed (value);
668         if (color)
669           {
670             GdkRGBA rgba;
671 
672             rgba.red = color->red / 65535.;
673             rgba.green = color->green / 65535.;
674             rgba.blue = color->blue / 65535.;
675             rgba.alpha = 1;
676 
677             set_cell_bg_color (cell, &rgba);
678           }
679         else
680           {
681             set_cell_bg_color (cell, NULL);
682           }
683         g_object_notify (object, "cell-background-gdk");
684       }
685       break;
686     case PROP_CELL_BACKGROUND_RGBA:
687       set_cell_bg_color (cell, g_value_get_boxed (value));
688       break;
689     case PROP_CELL_BACKGROUND_SET:
690       if (priv->cell_background_set != g_value_get_boolean (value))
691         {
692           priv->cell_background_set = g_value_get_boolean (value);
693           g_object_notify (object, "cell-background-set");
694         }
695       break;
696     default:
697       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
698       break;
699     }
700 }
701 
702 static void
set_cell_bg_color(GtkCellRenderer * cell,GdkRGBA * rgba)703 set_cell_bg_color (GtkCellRenderer *cell,
704                    GdkRGBA         *rgba)
705 {
706   GtkCellRendererPrivate *priv = cell->priv;
707 
708   if (rgba)
709     {
710       if (!priv->cell_background_set)
711         {
712           priv->cell_background_set = TRUE;
713           g_object_notify (G_OBJECT (cell), "cell-background-set");
714         }
715 
716       priv->cell_background = *rgba;
717     }
718   else
719     {
720       if (priv->cell_background_set)
721         {
722 	  priv->cell_background_set = FALSE;
723 	  g_object_notify (G_OBJECT (cell), "cell-background-set");
724 	}
725     }
726   g_object_notify (G_OBJECT (cell), "cell-background-rgba");
727 }
728 
729 /**
730  * gtk_cell_renderer_get_size:
731  * @cell: a #GtkCellRenderer
732  * @widget: the widget the renderer is rendering to
733  * @cell_area: (allow-none): The area a cell will be allocated, or %NULL
734  * @x_offset: (out) (allow-none): location to return x offset of cell relative to @cell_area, or %NULL
735  * @y_offset: (out) (allow-none): location to return y offset of cell relative to @cell_area, or %NULL
736  * @width: (out) (allow-none): location to return width needed to render a cell, or %NULL
737  * @height: (out) (allow-none): location to return height needed to render a cell, or %NULL
738  *
739  * Obtains the width and height needed to render the cell. Used by view
740  * widgets to determine the appropriate size for the cell_area passed to
741  * gtk_cell_renderer_render().  If @cell_area is not %NULL, fills in the
742  * x and y offsets (if set) of the cell relative to this location.
743  *
744  * Please note that the values set in @width and @height, as well as those
745  * in @x_offset and @y_offset are inclusive of the xpad and ypad properties.
746  *
747  *
748  * Deprecated: 3.0: Use gtk_cell_renderer_get_preferred_size() instead.
749  **/
750 void
gtk_cell_renderer_get_size(GtkCellRenderer * cell,GtkWidget * widget,const GdkRectangle * cell_area,gint * x_offset,gint * y_offset,gint * width,gint * height)751 gtk_cell_renderer_get_size (GtkCellRenderer    *cell,
752 			    GtkWidget          *widget,
753 			    const GdkRectangle *cell_area,
754 			    gint               *x_offset,
755 			    gint               *y_offset,
756 			    gint               *width,
757 			    gint               *height)
758 {
759   GtkRequisition request;
760 
761   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
762 
763   gtk_cell_renderer_get_preferred_size (cell, widget, &request, NULL);
764 
765   if (width)
766     *width = request.width;
767 
768   if (height)
769     *height = request.height;
770 
771   if (cell_area)
772     _gtk_cell_renderer_calc_offset (cell, cell_area, gtk_widget_get_direction (widget),
773                                     request.width, request.height, x_offset, y_offset);
774 }
775 
776 /**
777  * gtk_cell_renderer_render:
778  * @cell: a #GtkCellRenderer
779  * @cr: a cairo context to draw to
780  * @widget: the widget owning @window
781  * @background_area: entire cell area (including tree expanders and maybe
782  *    padding on the sides)
783  * @cell_area: area normally rendered by a cell renderer
784  * @flags: flags that affect rendering
785  *
786  * Invokes the virtual render function of the #GtkCellRenderer. The three
787  * passed-in rectangles are areas in @cr. Most renderers will draw within
788  * @cell_area; the xalign, yalign, xpad, and ypad fields of the #GtkCellRenderer
789  * should be honored with respect to @cell_area. @background_area includes the
790  * blank space around the cell, and also the area containing the tree expander;
791  * so the @background_area rectangles for all cells tile to cover the entire
792  * @window.
793  **/
794 void
gtk_cell_renderer_render(GtkCellRenderer * cell,cairo_t * cr,GtkWidget * widget,const GdkRectangle * background_area,const GdkRectangle * cell_area,GtkCellRendererState flags)795 gtk_cell_renderer_render (GtkCellRenderer      *cell,
796                           cairo_t              *cr,
797                           GtkWidget            *widget,
798                           const GdkRectangle   *background_area,
799                           const GdkRectangle   *cell_area,
800                           GtkCellRendererState  flags)
801 {
802   gboolean selected = FALSE;
803   GtkCellRendererPrivate *priv = cell->priv;
804   GtkStyleContext *context;
805   GtkStateFlags state;
806 
807   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
808   g_return_if_fail (GTK_CELL_RENDERER_GET_CLASS (cell)->render != NULL);
809   g_return_if_fail (cr != NULL);
810 
811   selected = (flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED;
812 
813   cairo_save (cr);
814 
815   if (priv->cell_background_set && !selected)
816     {
817       gdk_cairo_rectangle (cr, background_area);
818       gdk_cairo_set_source_rgba (cr, &priv->cell_background);
819       cairo_fill (cr);
820     }
821 
822   gdk_cairo_rectangle (cr, background_area);
823   cairo_clip (cr);
824 
825   context = gtk_widget_get_style_context (widget);
826 
827   gtk_style_context_save (context);
828   gtk_style_context_add_class (context, GTK_STYLE_CLASS_CELL);
829 
830   state = gtk_cell_renderer_get_state (cell, widget, flags);
831   gtk_style_context_set_state (context, state);
832 
833   GTK_CELL_RENDERER_GET_CLASS (cell)->render (cell,
834                                               cr,
835 					      widget,
836 					      background_area,
837 					      cell_area,
838 					      flags);
839   gtk_style_context_restore (context);
840   cairo_restore (cr);
841 }
842 
843 /**
844  * gtk_cell_renderer_activate:
845  * @cell: a #GtkCellRenderer
846  * @event: a #GdkEvent
847  * @widget: widget that received the event
848  * @path: widget-dependent string representation of the event location;
849  *    e.g. for #GtkTreeView, a string representation of #GtkTreePath
850  * @background_area: background area as passed to gtk_cell_renderer_render()
851  * @cell_area: cell area as passed to gtk_cell_renderer_render()
852  * @flags: render flags
853  *
854  * Passes an activate event to the cell renderer for possible processing.
855  * Some cell renderers may use events; for example, #GtkCellRendererToggle
856  * toggles when it gets a mouse click.
857  *
858  * Returns: %TRUE if the event was consumed/handled
859  **/
860 gboolean
gtk_cell_renderer_activate(GtkCellRenderer * cell,GdkEvent * event,GtkWidget * widget,const gchar * path,const GdkRectangle * background_area,const GdkRectangle * cell_area,GtkCellRendererState flags)861 gtk_cell_renderer_activate (GtkCellRenderer      *cell,
862 			    GdkEvent             *event,
863 			    GtkWidget            *widget,
864 			    const gchar          *path,
865 			    const GdkRectangle   *background_area,
866 			    const GdkRectangle   *cell_area,
867 			    GtkCellRendererState  flags)
868 {
869   GtkCellRendererPrivate *priv;
870 
871   g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
872 
873   priv = cell->priv;
874 
875   if (priv->mode != GTK_CELL_RENDERER_MODE_ACTIVATABLE)
876     return FALSE;
877 
878   if (GTK_CELL_RENDERER_GET_CLASS (cell)->activate == NULL)
879     return FALSE;
880 
881   return GTK_CELL_RENDERER_GET_CLASS (cell)->activate (cell,
882 						       event,
883 						       widget,
884 						       path,
885 						       (GdkRectangle *) background_area,
886 						       (GdkRectangle *) cell_area,
887 						       flags);
888 }
889 
890 /**
891  * gtk_cell_renderer_start_editing:
892  * @cell: a #GtkCellRenderer
893  * @event: (nullable): a #GdkEvent
894  * @widget: widget that received the event
895  * @path: widget-dependent string representation of the event location;
896  *    e.g. for #GtkTreeView, a string representation of #GtkTreePath
897  * @background_area: background area as passed to gtk_cell_renderer_render()
898  * @cell_area: cell area as passed to gtk_cell_renderer_render()
899  * @flags: render flags
900  *
901  * Starts editing the contents of this @cell, through a new #GtkCellEditable
902  * widget created by the #GtkCellRendererClass.start_editing virtual function.
903  *
904  * Returns: (nullable) (transfer none): A new #GtkCellEditable for editing this
905  *   @cell, or %NULL if editing is not possible
906  **/
907 GtkCellEditable *
gtk_cell_renderer_start_editing(GtkCellRenderer * cell,GdkEvent * event,GtkWidget * widget,const gchar * path,const GdkRectangle * background_area,const GdkRectangle * cell_area,GtkCellRendererState flags)908 gtk_cell_renderer_start_editing (GtkCellRenderer      *cell,
909 				 GdkEvent             *event,
910 				 GtkWidget            *widget,
911 				 const gchar          *path,
912 				 const GdkRectangle   *background_area,
913 				 const GdkRectangle   *cell_area,
914 				 GtkCellRendererState  flags)
915 
916 {
917   GtkCellRendererPrivate *priv;
918   GtkCellEditable *editable;
919 
920   g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), NULL);
921 
922   priv = cell->priv;
923 
924   if (priv->mode != GTK_CELL_RENDERER_MODE_EDITABLE)
925     return NULL;
926 
927   if (GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing == NULL)
928     return NULL;
929 
930   editable = GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing (cell,
931 								event,
932 								widget,
933 								path,
934 								(GdkRectangle *) background_area,
935 								(GdkRectangle *) cell_area,
936 								flags);
937   if (editable == NULL)
938     return NULL;
939 
940   gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (editable)),
941                                GTK_STYLE_CLASS_CELL);
942 
943   g_signal_emit (cell,
944 		 cell_renderer_signals[EDITING_STARTED], 0,
945 		 editable, path);
946 
947   priv->editing = TRUE;
948 
949   return editable;
950 }
951 
952 /**
953  * gtk_cell_renderer_set_fixed_size:
954  * @cell: A #GtkCellRenderer
955  * @width: the width of the cell renderer, or -1
956  * @height: the height of the cell renderer, or -1
957  *
958  * Sets the renderer size to be explicit, independent of the properties set.
959  **/
960 void
gtk_cell_renderer_set_fixed_size(GtkCellRenderer * cell,gint width,gint height)961 gtk_cell_renderer_set_fixed_size (GtkCellRenderer *cell,
962 				  gint             width,
963 				  gint             height)
964 {
965   GtkCellRendererPrivate *priv;
966 
967   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
968   g_return_if_fail (width >= -1 && height >= -1);
969 
970   priv = cell->priv;
971 
972   if ((width != priv->width) || (height != priv->height))
973     {
974       g_object_freeze_notify (G_OBJECT (cell));
975 
976       if (width != priv->width)
977         {
978           priv->width = width;
979           g_object_notify (G_OBJECT (cell), "width");
980         }
981 
982       if (height != priv->height)
983         {
984           priv->height = height;
985           g_object_notify (G_OBJECT (cell), "height");
986         }
987 
988       g_object_thaw_notify (G_OBJECT (cell));
989     }
990 }
991 
992 /**
993  * gtk_cell_renderer_get_fixed_size:
994  * @cell: A #GtkCellRenderer
995  * @width: (out) (allow-none): location to fill in with the fixed width of the cell, or %NULL
996  * @height: (out) (allow-none): location to fill in with the fixed height of the cell, or %NULL
997  *
998  * Fills in @width and @height with the appropriate size of @cell.
999  **/
1000 void
gtk_cell_renderer_get_fixed_size(GtkCellRenderer * cell,gint * width,gint * height)1001 gtk_cell_renderer_get_fixed_size (GtkCellRenderer *cell,
1002 				  gint            *width,
1003 				  gint            *height)
1004 {
1005   GtkCellRendererPrivate *priv;
1006 
1007   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1008 
1009   priv = cell->priv;
1010 
1011   if (width)
1012     *width = priv->width;
1013   if (height)
1014     *height = priv->height;
1015 }
1016 
1017 /**
1018  * gtk_cell_renderer_set_alignment:
1019  * @cell: A #GtkCellRenderer
1020  * @xalign: the x alignment of the cell renderer
1021  * @yalign: the y alignment of the cell renderer
1022  *
1023  * Sets the renderer’s alignment within its available space.
1024  *
1025  * Since: 2.18
1026  **/
1027 void
gtk_cell_renderer_set_alignment(GtkCellRenderer * cell,gfloat xalign,gfloat yalign)1028 gtk_cell_renderer_set_alignment (GtkCellRenderer *cell,
1029                                  gfloat           xalign,
1030                                  gfloat           yalign)
1031 {
1032   GtkCellRendererPrivate *priv;
1033 
1034   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1035   g_return_if_fail (xalign >= 0.0 && xalign <= 1.0);
1036   g_return_if_fail (yalign >= 0.0 && yalign <= 1.0);
1037 
1038   priv = cell->priv;
1039 
1040   if ((xalign != priv->xalign) || (yalign != priv->yalign))
1041     {
1042       g_object_freeze_notify (G_OBJECT (cell));
1043 
1044       if (xalign != priv->xalign)
1045         {
1046           priv->xalign = xalign;
1047           g_object_notify (G_OBJECT (cell), "xalign");
1048         }
1049 
1050       if (yalign != priv->yalign)
1051         {
1052           priv->yalign = yalign;
1053           g_object_notify (G_OBJECT (cell), "yalign");
1054         }
1055 
1056       g_object_thaw_notify (G_OBJECT (cell));
1057     }
1058 }
1059 
1060 /**
1061  * gtk_cell_renderer_get_alignment:
1062  * @cell: A #GtkCellRenderer
1063  * @xalign: (out) (allow-none): location to fill in with the x alignment of the cell, or %NULL
1064  * @yalign: (out) (allow-none): location to fill in with the y alignment of the cell, or %NULL
1065  *
1066  * Fills in @xalign and @yalign with the appropriate values of @cell.
1067  *
1068  * Since: 2.18
1069  **/
1070 void
gtk_cell_renderer_get_alignment(GtkCellRenderer * cell,gfloat * xalign,gfloat * yalign)1071 gtk_cell_renderer_get_alignment (GtkCellRenderer *cell,
1072                                  gfloat          *xalign,
1073                                  gfloat          *yalign)
1074 {
1075   GtkCellRendererPrivate *priv;
1076 
1077   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1078 
1079   priv = cell->priv;
1080 
1081   if (xalign)
1082     *xalign = priv->xalign;
1083   if (yalign)
1084     *yalign = priv->yalign;
1085 }
1086 
1087 /**
1088  * gtk_cell_renderer_set_padding:
1089  * @cell: A #GtkCellRenderer
1090  * @xpad: the x padding of the cell renderer
1091  * @ypad: the y padding of the cell renderer
1092  *
1093  * Sets the renderer’s padding.
1094  *
1095  * Since: 2.18
1096  **/
1097 void
gtk_cell_renderer_set_padding(GtkCellRenderer * cell,gint xpad,gint ypad)1098 gtk_cell_renderer_set_padding (GtkCellRenderer *cell,
1099                                gint             xpad,
1100                                gint             ypad)
1101 {
1102   GtkCellRendererPrivate *priv;
1103 
1104   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1105   g_return_if_fail (xpad >= 0 && ypad >= 0);
1106 
1107   priv = cell->priv;
1108 
1109   if ((xpad != priv->xpad) || (ypad != priv->ypad))
1110     {
1111       g_object_freeze_notify (G_OBJECT (cell));
1112 
1113       if (xpad != priv->xpad)
1114         {
1115           priv->xpad = xpad;
1116           g_object_notify (G_OBJECT (cell), "xpad");
1117         }
1118 
1119       if (ypad != priv->ypad)
1120         {
1121           priv->ypad = ypad;
1122           g_object_notify (G_OBJECT (cell), "ypad");
1123         }
1124 
1125       g_object_thaw_notify (G_OBJECT (cell));
1126     }
1127 }
1128 
1129 /**
1130  * gtk_cell_renderer_get_padding:
1131  * @cell: A #GtkCellRenderer
1132  * @xpad: (out) (allow-none): location to fill in with the x padding of the cell, or %NULL
1133  * @ypad: (out) (allow-none): location to fill in with the y padding of the cell, or %NULL
1134  *
1135  * Fills in @xpad and @ypad with the appropriate values of @cell.
1136  *
1137  * Since: 2.18
1138  **/
1139 void
gtk_cell_renderer_get_padding(GtkCellRenderer * cell,gint * xpad,gint * ypad)1140 gtk_cell_renderer_get_padding (GtkCellRenderer *cell,
1141                                gint            *xpad,
1142                                gint            *ypad)
1143 {
1144   GtkCellRendererPrivate *priv;
1145 
1146   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1147 
1148   priv = cell->priv;
1149 
1150   if (xpad)
1151     *xpad = priv->xpad;
1152   if (ypad)
1153     *ypad = priv->ypad;
1154 }
1155 
1156 /**
1157  * gtk_cell_renderer_set_visible:
1158  * @cell: A #GtkCellRenderer
1159  * @visible: the visibility of the cell
1160  *
1161  * Sets the cell renderer’s visibility.
1162  *
1163  * Since: 2.18
1164  **/
1165 void
gtk_cell_renderer_set_visible(GtkCellRenderer * cell,gboolean visible)1166 gtk_cell_renderer_set_visible (GtkCellRenderer *cell,
1167                                gboolean         visible)
1168 {
1169   GtkCellRendererPrivate *priv;
1170 
1171   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1172 
1173   priv = cell->priv;
1174 
1175   if (priv->visible != visible)
1176     {
1177       priv->visible = visible ? TRUE : FALSE;
1178       g_object_notify (G_OBJECT (cell), "visible");
1179     }
1180 }
1181 
1182 /**
1183  * gtk_cell_renderer_get_visible:
1184  * @cell: A #GtkCellRenderer
1185  *
1186  * Returns the cell renderer’s visibility.
1187  *
1188  * Returns: %TRUE if the cell renderer is visible
1189  *
1190  * Since: 2.18
1191  */
1192 gboolean
gtk_cell_renderer_get_visible(GtkCellRenderer * cell)1193 gtk_cell_renderer_get_visible (GtkCellRenderer *cell)
1194 {
1195   g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
1196 
1197   return cell->priv->visible;
1198 }
1199 
1200 /**
1201  * gtk_cell_renderer_set_sensitive:
1202  * @cell: A #GtkCellRenderer
1203  * @sensitive: the sensitivity of the cell
1204  *
1205  * Sets the cell renderer’s sensitivity.
1206  *
1207  * Since: 2.18
1208  **/
1209 void
gtk_cell_renderer_set_sensitive(GtkCellRenderer * cell,gboolean sensitive)1210 gtk_cell_renderer_set_sensitive (GtkCellRenderer *cell,
1211                                  gboolean         sensitive)
1212 {
1213   GtkCellRendererPrivate *priv;
1214 
1215   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1216 
1217   priv = cell->priv;
1218 
1219   if (priv->sensitive != sensitive)
1220     {
1221       priv->sensitive = sensitive ? TRUE : FALSE;
1222       g_object_notify (G_OBJECT (cell), "sensitive");
1223     }
1224 }
1225 
1226 /**
1227  * gtk_cell_renderer_get_sensitive:
1228  * @cell: A #GtkCellRenderer
1229  *
1230  * Returns the cell renderer’s sensitivity.
1231  *
1232  * Returns: %TRUE if the cell renderer is sensitive
1233  *
1234  * Since: 2.18
1235  */
1236 gboolean
gtk_cell_renderer_get_sensitive(GtkCellRenderer * cell)1237 gtk_cell_renderer_get_sensitive (GtkCellRenderer *cell)
1238 {
1239   g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
1240 
1241   return cell->priv->sensitive;
1242 }
1243 
1244 
1245 /**
1246  * gtk_cell_renderer_is_activatable:
1247  * @cell: A #GtkCellRenderer
1248  *
1249  * Checks whether the cell renderer can do something when activated.
1250  *
1251  * Returns: %TRUE if the cell renderer can do anything when activated
1252  *
1253  * Since: 3.0
1254  */
1255 gboolean
gtk_cell_renderer_is_activatable(GtkCellRenderer * cell)1256 gtk_cell_renderer_is_activatable (GtkCellRenderer *cell)
1257 {
1258   GtkCellRendererPrivate *priv;
1259 
1260   g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
1261 
1262   priv = cell->priv;
1263 
1264   return (priv->visible &&
1265           (priv->mode == GTK_CELL_RENDERER_MODE_EDITABLE ||
1266            priv->mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE));
1267 }
1268 
1269 
1270 /**
1271  * gtk_cell_renderer_stop_editing:
1272  * @cell: A #GtkCellRenderer
1273  * @canceled: %TRUE if the editing has been canceled
1274  *
1275  * Informs the cell renderer that the editing is stopped.
1276  * If @canceled is %TRUE, the cell renderer will emit the
1277  * #GtkCellRenderer::editing-canceled signal.
1278  *
1279  * This function should be called by cell renderer implementations
1280  * in response to the #GtkCellEditable::editing-done signal of
1281  * #GtkCellEditable.
1282  *
1283  * Since: 2.6
1284  **/
1285 void
gtk_cell_renderer_stop_editing(GtkCellRenderer * cell,gboolean canceled)1286 gtk_cell_renderer_stop_editing (GtkCellRenderer *cell,
1287 				gboolean         canceled)
1288 {
1289   GtkCellRendererPrivate *priv;
1290 
1291   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1292 
1293   priv = cell->priv;
1294 
1295   if (priv->editing)
1296     {
1297       priv->editing = FALSE;
1298       if (canceled)
1299 	g_signal_emit (cell, cell_renderer_signals[EDITING_CANCELED], 0);
1300     }
1301 }
1302 
1303 static void
gtk_cell_renderer_real_get_preferred_size(GtkCellRenderer * cell,GtkWidget * widget,GtkOrientation orientation,gint * minimum_size,gint * natural_size)1304 gtk_cell_renderer_real_get_preferred_size (GtkCellRenderer   *cell,
1305                                            GtkWidget         *widget,
1306                                            GtkOrientation     orientation,
1307                                            gint              *minimum_size,
1308                                            gint              *natural_size)
1309 {
1310   GtkRequisition min_req;
1311 
1312   /* Fallback on the old API to get the size. */
1313   if (GTK_CELL_RENDERER_GET_CLASS (cell)->get_size)
1314     GTK_CELL_RENDERER_GET_CLASS (cell)->get_size (GTK_CELL_RENDERER (cell), widget, NULL, NULL, NULL,
1315 						  &min_req.width, &min_req.height);
1316   else
1317     {
1318       min_req.width = 0;
1319       min_req.height = 0;
1320     }
1321 
1322   if (orientation == GTK_ORIENTATION_HORIZONTAL)
1323     {
1324       if (minimum_size)
1325 	*minimum_size = min_req.width;
1326 
1327       if (natural_size)
1328 	*natural_size = min_req.width;
1329     }
1330   else
1331     {
1332       if (minimum_size)
1333 	*minimum_size = min_req.height;
1334 
1335       if (natural_size)
1336 	*natural_size = min_req.height;
1337     }
1338 }
1339 
1340 static GtkSizeRequestMode
gtk_cell_renderer_real_get_request_mode(GtkCellRenderer * cell)1341 gtk_cell_renderer_real_get_request_mode (GtkCellRenderer *cell)
1342 {
1343   /* By default cell renderers are height-for-width. */
1344   return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
1345 }
1346 
1347 static void
gtk_cell_renderer_real_get_preferred_width(GtkCellRenderer * cell,GtkWidget * widget,gint * minimum_size,gint * natural_size)1348 gtk_cell_renderer_real_get_preferred_width (GtkCellRenderer *cell,
1349                                             GtkWidget       *widget,
1350                                             gint            *minimum_size,
1351                                             gint            *natural_size)
1352 {
1353   gtk_cell_renderer_real_get_preferred_size (cell, widget, GTK_ORIENTATION_HORIZONTAL,
1354                                              minimum_size, natural_size);
1355 }
1356 
1357 static void
gtk_cell_renderer_real_get_preferred_height(GtkCellRenderer * cell,GtkWidget * widget,gint * minimum_size,gint * natural_size)1358 gtk_cell_renderer_real_get_preferred_height (GtkCellRenderer *cell,
1359                                              GtkWidget       *widget,
1360                                              gint            *minimum_size,
1361                                              gint            *natural_size)
1362 {
1363   gtk_cell_renderer_real_get_preferred_size (cell, widget, GTK_ORIENTATION_VERTICAL,
1364                                              minimum_size, natural_size);
1365 }
1366 
1367 
1368 static void
gtk_cell_renderer_real_get_preferred_height_for_width(GtkCellRenderer * cell,GtkWidget * widget,gint width,gint * minimum_height,gint * natural_height)1369 gtk_cell_renderer_real_get_preferred_height_for_width (GtkCellRenderer *cell,
1370                                                        GtkWidget       *widget,
1371                                                        gint             width,
1372                                                        gint            *minimum_height,
1373                                                        gint            *natural_height)
1374 {
1375   /* Fall back on the height reported from ->get_size() */
1376   gtk_cell_renderer_get_preferred_height (cell, widget, minimum_height, natural_height);
1377 }
1378 
1379 static void
gtk_cell_renderer_real_get_preferred_width_for_height(GtkCellRenderer * cell,GtkWidget * widget,gint height,gint * minimum_width,gint * natural_width)1380 gtk_cell_renderer_real_get_preferred_width_for_height (GtkCellRenderer *cell,
1381                                                        GtkWidget       *widget,
1382                                                        gint             height,
1383                                                        gint            *minimum_width,
1384                                                        gint            *natural_width)
1385 {
1386   /* Fall back on the width reported from ->get_size() */
1387   gtk_cell_renderer_get_preferred_width (cell, widget, minimum_width, natural_width);
1388 }
1389 
1390 
1391 /* Default implementation assumes that a cell renderer will never use more
1392  * space than its natural size (this is fine for toggles and pixbufs etc
1393  * but needs to be overridden from wrapping/ellipsizing text renderers) */
1394 static void
gtk_cell_renderer_real_get_aligned_area(GtkCellRenderer * cell,GtkWidget * widget,GtkCellRendererState flags,const GdkRectangle * cell_area,GdkRectangle * aligned_area)1395 gtk_cell_renderer_real_get_aligned_area (GtkCellRenderer         *cell,
1396 					 GtkWidget               *widget,
1397 					 GtkCellRendererState     flags,
1398 					 const GdkRectangle      *cell_area,
1399 					 GdkRectangle            *aligned_area)
1400 {
1401   gint opposite_size, x_offset, y_offset;
1402   gint natural_size;
1403 
1404   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1405   g_return_if_fail (GTK_IS_WIDGET (widget));
1406   g_return_if_fail (cell_area != NULL);
1407   g_return_if_fail (aligned_area != NULL);
1408 
1409   *aligned_area = *cell_area;
1410 
1411   /* Trim up the aligned size */
1412   if (gtk_cell_renderer_get_request_mode (cell) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
1413     {
1414       gtk_cell_renderer_get_preferred_width (cell, widget,
1415 					     NULL, &natural_size);
1416 
1417       aligned_area->width = MIN (aligned_area->width, natural_size);
1418 
1419       gtk_cell_renderer_get_preferred_height_for_width (cell, widget,
1420 							aligned_area->width,
1421 							NULL, &opposite_size);
1422 
1423       aligned_area->height = MIN (opposite_size, aligned_area->height);
1424     }
1425   else
1426     {
1427       gtk_cell_renderer_get_preferred_height (cell, widget,
1428 					      NULL, &natural_size);
1429 
1430       aligned_area->height = MIN (aligned_area->width, natural_size);
1431 
1432       gtk_cell_renderer_get_preferred_width_for_height (cell, widget,
1433 							aligned_area->height,
1434 							NULL, &opposite_size);
1435 
1436       aligned_area->width = MIN (opposite_size, aligned_area->width);
1437     }
1438 
1439   /* offset the cell position */
1440   _gtk_cell_renderer_calc_offset (cell, cell_area,
1441 				  gtk_widget_get_direction (widget),
1442 				  aligned_area->width,
1443 				  aligned_area->height,
1444 				  &x_offset, &y_offset);
1445 
1446   aligned_area->x += x_offset;
1447   aligned_area->y += y_offset;
1448 }
1449 
1450 
1451 /* An internal convenience function for some containers to peek at the
1452  * cell alignment in a target allocation (used to draw focus and align
1453  * cells in the icon view).
1454  *
1455  * Note this is only a trivial “align * (allocation - request)” operation.
1456  */
1457 void
_gtk_cell_renderer_calc_offset(GtkCellRenderer * cell,const GdkRectangle * cell_area,GtkTextDirection direction,gint width,gint height,gint * x_offset,gint * y_offset)1458 _gtk_cell_renderer_calc_offset    (GtkCellRenderer      *cell,
1459 				   const GdkRectangle   *cell_area,
1460 				   GtkTextDirection      direction,
1461 				   gint                  width,
1462 				   gint                  height,
1463 				   gint                 *x_offset,
1464 				   gint                 *y_offset)
1465 {
1466   GtkCellRendererPrivate *priv;
1467 
1468   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1469   g_return_if_fail (cell_area != NULL);
1470   g_return_if_fail (x_offset || y_offset);
1471 
1472   priv = cell->priv;
1473 
1474   if (x_offset)
1475     {
1476       *x_offset = (((direction == GTK_TEXT_DIR_RTL) ?
1477 		    (1.0 - priv->xalign) : priv->xalign) *
1478 		   (cell_area->width - width));
1479       *x_offset = MAX (*x_offset, 0);
1480     }
1481   if (y_offset)
1482     {
1483       *y_offset = (priv->yalign *
1484 		   (cell_area->height - height));
1485       *y_offset = MAX (*y_offset, 0);
1486     }
1487 }
1488 
1489 /**
1490  * gtk_cell_renderer_get_request_mode:
1491  * @cell: a #GtkCellRenderer    instance
1492  *
1493  * Gets whether the cell renderer prefers a height-for-width layout
1494  * or a width-for-height layout.
1495  *
1496  * Returns: The #GtkSizeRequestMode preferred by this renderer.
1497  *
1498  * Since: 3.0
1499  */
1500 GtkSizeRequestMode
gtk_cell_renderer_get_request_mode(GtkCellRenderer * cell)1501 gtk_cell_renderer_get_request_mode (GtkCellRenderer *cell)
1502 {
1503   g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
1504 
1505   return GTK_CELL_RENDERER_GET_CLASS (cell)->get_request_mode (cell);
1506 }
1507 
1508 /**
1509  * gtk_cell_renderer_get_preferred_width:
1510  * @cell: a #GtkCellRenderer instance
1511  * @widget: the #GtkWidget this cell will be rendering to
1512  * @minimum_size: (out) (allow-none): location to store the minimum size, or %NULL
1513  * @natural_size: (out) (allow-none): location to store the natural size, or %NULL
1514  *
1515  * Retreives a renderer’s natural size when rendered to @widget.
1516  *
1517  * Since: 3.0
1518  */
1519 void
gtk_cell_renderer_get_preferred_width(GtkCellRenderer * cell,GtkWidget * widget,gint * minimum_size,gint * natural_size)1520 gtk_cell_renderer_get_preferred_width (GtkCellRenderer *cell,
1521                                        GtkWidget       *widget,
1522                                        gint            *minimum_size,
1523                                        gint            *natural_size)
1524 {
1525   GtkCellRendererClass *klass;
1526   gint width;
1527 
1528   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1529   g_return_if_fail (GTK_IS_WIDGET (widget));
1530   g_return_if_fail (NULL != minimum_size || NULL != natural_size);
1531 
1532   gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), &width, NULL);
1533 
1534   if (width < 0)
1535     {
1536       klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1537       klass->get_preferred_width (cell, widget, minimum_size, natural_size);
1538     }
1539   else
1540     {
1541       if (minimum_size)
1542 	*minimum_size = width;
1543       if (natural_size)
1544 	*natural_size = width;
1545     }
1546 
1547 #if DEBUG_CELL_SIZE_REQUEST
1548   g_message ("%s returning minimum width: %d and natural width: %d",
1549 	     G_OBJECT_TYPE_NAME (cell),
1550 	     minimum_size ? *minimum_size : 20000,
1551 	     natural_size ? *natural_size : 20000);
1552 #endif
1553 }
1554 
1555 
1556 /**
1557  * gtk_cell_renderer_get_preferred_height:
1558  * @cell: a #GtkCellRenderer instance
1559  * @widget: the #GtkWidget this cell will be rendering to
1560  * @minimum_size: (out) (allow-none): location to store the minimum size, or %NULL
1561  * @natural_size: (out) (allow-none): location to store the natural size, or %NULL
1562  *
1563  * Retreives a renderer’s natural size when rendered to @widget.
1564  *
1565  * Since: 3.0
1566  */
1567 void
gtk_cell_renderer_get_preferred_height(GtkCellRenderer * cell,GtkWidget * widget,gint * minimum_size,gint * natural_size)1568 gtk_cell_renderer_get_preferred_height (GtkCellRenderer *cell,
1569                                         GtkWidget       *widget,
1570                                         gint            *minimum_size,
1571                                         gint            *natural_size)
1572 {
1573   GtkCellRendererClass *klass;
1574   gint height;
1575 
1576   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1577   g_return_if_fail (GTK_IS_WIDGET (widget));
1578   g_return_if_fail (NULL != minimum_size || NULL != natural_size);
1579 
1580   gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), NULL, &height);
1581 
1582   if (height < 0)
1583     {
1584       klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1585       klass->get_preferred_height (cell, widget, minimum_size, natural_size);
1586     }
1587   else
1588     {
1589       if (minimum_size)
1590 	*minimum_size = height;
1591       if (natural_size)
1592 	*natural_size = height;
1593     }
1594 
1595 #if DEBUG_CELL_SIZE_REQUEST
1596   g_message ("%s returning minimum height: %d and natural height: %d",
1597 	     G_OBJECT_TYPE_NAME (cell),
1598 	     minimum_size ? *minimum_size : 20000,
1599 	     natural_size ? *natural_size : 20000);
1600 #endif
1601 }
1602 
1603 
1604 /**
1605  * gtk_cell_renderer_get_preferred_width_for_height:
1606  * @cell: a #GtkCellRenderer instance
1607  * @widget: the #GtkWidget this cell will be rendering to
1608  * @height: the size which is available for allocation
1609  * @minimum_width: (out) (allow-none): location for storing the minimum size, or %NULL
1610  * @natural_width: (out) (allow-none): location for storing the preferred size, or %NULL
1611  *
1612  * Retreives a cell renderers’s minimum and natural width if it were rendered to
1613  * @widget with the specified @height.
1614  *
1615  * Since: 3.0
1616  */
1617 void
gtk_cell_renderer_get_preferred_width_for_height(GtkCellRenderer * cell,GtkWidget * widget,gint height,gint * minimum_width,gint * natural_width)1618 gtk_cell_renderer_get_preferred_width_for_height (GtkCellRenderer *cell,
1619                                                   GtkWidget       *widget,
1620                                                   gint             height,
1621                                                   gint            *minimum_width,
1622                                                   gint            *natural_width)
1623 {
1624   GtkCellRendererClass *klass;
1625   gint width;
1626 
1627   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1628   g_return_if_fail (GTK_IS_WIDGET (widget));
1629   g_return_if_fail (NULL != minimum_width || NULL != natural_width);
1630 
1631   gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), &width, NULL);
1632 
1633   if (width < 0)
1634     {
1635       klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1636       klass->get_preferred_width_for_height (cell, widget, height, minimum_width, natural_width);
1637     }
1638   else
1639     {
1640       if (minimum_width)
1641 	*minimum_width = width;
1642       if (natural_width)
1643 	*natural_width = width;
1644     }
1645 
1646 #if DEBUG_CELL_SIZE_REQUEST
1647   g_message ("%s width for height: %d is minimum %d and natural: %d",
1648 	     G_OBJECT_TYPE_NAME (cell), height,
1649 	     minimum_width ? *minimum_width : 20000,
1650 	     natural_width ? *natural_width : 20000);
1651 #endif
1652 }
1653 
1654 /**
1655  * gtk_cell_renderer_get_preferred_height_for_width:
1656  * @cell: a #GtkCellRenderer instance
1657  * @widget: the #GtkWidget this cell will be rendering to
1658  * @width: the size which is available for allocation
1659  * @minimum_height: (out) (allow-none): location for storing the minimum size, or %NULL
1660  * @natural_height: (out) (allow-none): location for storing the preferred size, or %NULL
1661  *
1662  * Retreives a cell renderers’s minimum and natural height if it were rendered to
1663  * @widget with the specified @width.
1664  *
1665  * Since: 3.0
1666  */
1667 void
gtk_cell_renderer_get_preferred_height_for_width(GtkCellRenderer * cell,GtkWidget * widget,gint width,gint * minimum_height,gint * natural_height)1668 gtk_cell_renderer_get_preferred_height_for_width (GtkCellRenderer *cell,
1669                                                   GtkWidget       *widget,
1670                                                   gint             width,
1671                                                   gint            *minimum_height,
1672                                                   gint            *natural_height)
1673 {
1674   GtkCellRendererClass *klass;
1675   gint height;
1676 
1677   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1678   g_return_if_fail (GTK_IS_WIDGET (widget));
1679   g_return_if_fail (NULL != minimum_height || NULL != natural_height);
1680 
1681   gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (cell), NULL, &height);
1682 
1683   if (height < 0)
1684     {
1685       klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1686       klass->get_preferred_height_for_width (cell, widget, width, minimum_height, natural_height);
1687     }
1688   else
1689     {
1690       if (minimum_height)
1691 	*minimum_height = height;
1692       if (natural_height)
1693 	*natural_height = height;
1694     }
1695 
1696 #if DEBUG_CELL_SIZE_REQUEST
1697   g_message ("%s height for width: %d is minimum %d and natural: %d",
1698 	     G_OBJECT_TYPE_NAME (cell), width,
1699 	     minimum_height ? *minimum_height : 20000,
1700 	     natural_height ? *natural_height : 20000);
1701 #endif
1702 }
1703 
1704 /**
1705  * gtk_cell_renderer_get_preferred_size:
1706  * @cell: a #GtkCellRenderer instance
1707  * @widget: the #GtkWidget this cell will be rendering to
1708  * @minimum_size: (out) (allow-none): location for storing the minimum size, or %NULL
1709  * @natural_size: (out) (allow-none): location for storing the natural size, or %NULL
1710  *
1711  * Retrieves the minimum and natural size of a cell taking
1712  * into account the widget’s preference for height-for-width management.
1713  *
1714  * Since: 3.0
1715  */
1716 void
gtk_cell_renderer_get_preferred_size(GtkCellRenderer * cell,GtkWidget * widget,GtkRequisition * minimum_size,GtkRequisition * natural_size)1717 gtk_cell_renderer_get_preferred_size (GtkCellRenderer *cell,
1718                                       GtkWidget       *widget,
1719                                       GtkRequisition  *minimum_size,
1720                                       GtkRequisition  *natural_size)
1721 {
1722   gint min_width, nat_width;
1723   gint min_height, nat_height;
1724 
1725   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1726 
1727   if (gtk_cell_renderer_get_request_mode (cell) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
1728     {
1729       gtk_cell_renderer_get_preferred_width (cell, widget, &min_width, &nat_width);
1730 
1731       if (minimum_size)
1732 	{
1733 	  minimum_size->width = min_width;
1734 	  gtk_cell_renderer_get_preferred_height_for_width (cell, widget, min_width,
1735                                                             &minimum_size->height, NULL);
1736 	}
1737 
1738       if (natural_size)
1739 	{
1740 	  natural_size->width = nat_width;
1741 	  gtk_cell_renderer_get_preferred_height_for_width (cell, widget, nat_width,
1742                                                             NULL, &natural_size->height);
1743 	}
1744     }
1745   else /* GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT */
1746     {
1747       gtk_cell_renderer_get_preferred_height (cell, widget, &min_height, &nat_height);
1748 
1749       if (minimum_size)
1750 	{
1751 	  minimum_size->height = min_height;
1752 	  gtk_cell_renderer_get_preferred_width_for_height (cell, widget, min_height,
1753                                                             &minimum_size->width, NULL);
1754 	}
1755 
1756       if (natural_size)
1757 	{
1758 	  natural_size->height = nat_height;
1759 	  gtk_cell_renderer_get_preferred_width_for_height (cell, widget, nat_height,
1760                                                             NULL, &natural_size->width);
1761 	}
1762     }
1763 }
1764 
1765 /**
1766  * gtk_cell_renderer_get_aligned_area:
1767  * @cell: a #GtkCellRenderer instance
1768  * @widget: the #GtkWidget this cell will be rendering to
1769  * @flags: render flags
1770  * @cell_area: cell area which would be passed to gtk_cell_renderer_render()
1771  * @aligned_area: (out): the return location for the space inside @cell_area
1772  *                that would acually be used to render.
1773  *
1774  * Gets the aligned area used by @cell inside @cell_area. Used for finding
1775  * the appropriate edit and focus rectangle.
1776  *
1777  * Since: 3.0
1778  */
1779 void
gtk_cell_renderer_get_aligned_area(GtkCellRenderer * cell,GtkWidget * widget,GtkCellRendererState flags,const GdkRectangle * cell_area,GdkRectangle * aligned_area)1780 gtk_cell_renderer_get_aligned_area (GtkCellRenderer      *cell,
1781 				    GtkWidget            *widget,
1782 				    GtkCellRendererState  flags,
1783 				    const GdkRectangle   *cell_area,
1784 				    GdkRectangle         *aligned_area)
1785 {
1786   GtkCellRendererClass *klass;
1787 
1788   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
1789   g_return_if_fail (GTK_IS_WIDGET (widget));
1790   g_return_if_fail (cell_area != NULL);
1791   g_return_if_fail (aligned_area != NULL);
1792 
1793   klass = GTK_CELL_RENDERER_GET_CLASS (cell);
1794   klass->get_aligned_area (cell, widget, flags, cell_area, aligned_area);
1795 
1796   g_assert (aligned_area->x >= cell_area->x && aligned_area->x <= cell_area->x + cell_area->width);
1797   g_assert (aligned_area->y >= cell_area->y && aligned_area->y <= cell_area->y + cell_area->height);
1798   g_assert ((aligned_area->x - cell_area->x) + aligned_area->width <= cell_area->width);
1799   g_assert ((aligned_area->y - cell_area->y) + aligned_area->height <= cell_area->height);
1800 }
1801 
1802 /**
1803  * gtk_cell_renderer_get_state:
1804  * @cell: (nullable): a #GtkCellRenderer, or %NULL
1805  * @widget: (nullable): a #GtkWidget, or %NULL
1806  * @cell_state: cell renderer state
1807  *
1808  * Translates the cell renderer state to #GtkStateFlags,
1809  * based on the cell renderer and widget sensitivity, and
1810  * the given #GtkCellRendererState.
1811  *
1812  * Returns: the widget state flags applying to @cell
1813  *
1814  * Since: 3.0
1815  **/
1816 GtkStateFlags
gtk_cell_renderer_get_state(GtkCellRenderer * cell,GtkWidget * widget,GtkCellRendererState cell_state)1817 gtk_cell_renderer_get_state (GtkCellRenderer      *cell,
1818 			     GtkWidget            *widget,
1819 			     GtkCellRendererState  cell_state)
1820 {
1821   GtkStateFlags state = 0;
1822 
1823   g_return_val_if_fail (!cell || GTK_IS_CELL_RENDERER (cell), 0);
1824   g_return_val_if_fail (!widget || GTK_IS_WIDGET (widget), 0);
1825 
1826   if (widget)
1827     state |= gtk_widget_get_state_flags (widget);
1828 
1829   state &= ~(GTK_STATE_FLAG_FOCUSED | GTK_STATE_FLAG_PRELIGHT | GTK_STATE_FLAG_SELECTED | GTK_STATE_FLAG_DROP_ACTIVE);
1830 
1831   if ((state & GTK_STATE_FLAG_INSENSITIVE) != 0 ||
1832       (cell && !gtk_cell_renderer_get_sensitive (cell)) ||
1833       (cell_state & GTK_CELL_RENDERER_INSENSITIVE) != 0)
1834     {
1835       state |= GTK_STATE_FLAG_INSENSITIVE;
1836     }
1837   else
1838     {
1839       if ((widget && gtk_widget_has_focus (widget)) &&
1840           (cell_state & GTK_CELL_RENDERER_FOCUSED) != 0)
1841         state |= GTK_STATE_FLAG_FOCUSED;
1842 
1843       if ((cell_state & GTK_CELL_RENDERER_PRELIT) != 0)
1844         state |= GTK_STATE_FLAG_PRELIGHT;
1845     }
1846 
1847   if ((cell_state & GTK_CELL_RENDERER_SELECTED) != 0)
1848     state |= GTK_STATE_FLAG_SELECTED;
1849 
1850   return state;
1851 }
1852 
1853 /**
1854  * gtk_cell_renderer_class_set_accessible_type:
1855  * @renderer_class: class to set the accessible type for
1856  * @type: The object type that implements the accessible for @widget_class.
1857  *     The type must be a subtype of #GtkRendererCellAccessible
1858  *
1859  * Sets the type to be used for creating accessibles for cells rendered by
1860  * cell renderers of @renderer_class. Note that multiple accessibles will
1861  * be created.
1862  *
1863  * This function should only be called from class init functions of cell
1864  * renderers.
1865  **/
1866 void
gtk_cell_renderer_class_set_accessible_type(GtkCellRendererClass * renderer_class,GType type)1867 gtk_cell_renderer_class_set_accessible_type (GtkCellRendererClass *renderer_class,
1868                                              GType                 type)
1869 {
1870   GtkCellRendererClassPrivate *priv;
1871 
1872   g_return_if_fail (GTK_IS_CELL_RENDERER_CLASS (renderer_class));
1873   g_return_if_fail (g_type_is_a (type, GTK_TYPE_RENDERER_CELL_ACCESSIBLE));
1874 
1875   priv = renderer_class->priv;
1876 
1877   priv->accessible_type = type;
1878 }
1879 
1880 GType
_gtk_cell_renderer_get_accessible_type(GtkCellRenderer * renderer)1881 _gtk_cell_renderer_get_accessible_type (GtkCellRenderer *renderer)
1882 {
1883   g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), GTK_TYPE_RENDERER_CELL_ACCESSIBLE);
1884 
1885   return GTK_CELL_RENDERER_GET_CLASS (renderer)->priv->accessible_type;
1886 }
1887 
1888