]> Pileus Git - ~andy/gtk/blob - gtk/gtkcellview.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / gtk / gtkcellview.c
1 /* gtkellview.c
2  * Copyright (C) 2002, 2003  Kristian Rietveld <kris@gtk.org>
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 <string.h>
20 #include "gtkcellview.h"
21 #include "gtkcelllayout.h"
22 #include "gtkcellareabox.h"
23 #include "gtkintl.h"
24 #include "gtkcellrenderertext.h"
25 #include "gtkcellrendererpixbuf.h"
26 #include "gtkprivate.h"
27 #include "gtkorientableprivate.h"
28 #include <gobject/gmarshal.h>
29 #include "gtkbuildable.h"
30
31
32 /**
33  * SECTION:gtkcellview
34  * @Short_description: A widget displaying a single row of a GtkTreeModel
35  * @Title: GtkCellView
36  *
37  * A #GtkCellView displays a single row of a #GtkTreeModel using a #GtkCellArea
38  * and #GtkCellAreaContext. A #GtkCellAreaContext can be provided to the 
39  * #GtkCellView at construction time in order to keep the cellview in context
40  * of a group of cell views, this ensures that the renderers displayed will
41  * be properly aligned with eachother (like the aligned cells in the menus
42  * of #GtkComboBox).
43  *
44  * #GtkCellView is #GtkOrientable in order to decide in which orientation
45  * the underlying #GtkCellAreaContext should be allocated. Taking the #GtkComboBox
46  * menu as an example, cellviews should be oriented horizontally if the menus are
47  * listed top-to-bottom and thus all share the same width but may have separate
48  * individual heights (left-to-right menus should be allocated vertically since
49  * they all share the same height but may have variable widths).
50  */
51
52 static GObject    *gtk_cell_view_constructor              (GType                  type,
53                                                            guint                  n_construct_properties,
54                                                            GObjectConstructParam *construct_properties);
55 static void        gtk_cell_view_get_property             (GObject           *object,
56                                                            guint             param_id,
57                                                            GValue           *value,
58                                                            GParamSpec       *pspec);
59 static void        gtk_cell_view_set_property             (GObject          *object,
60                                                            guint             param_id,
61                                                            const GValue     *value,
62                                                            GParamSpec       *pspec);
63 static void        gtk_cell_view_finalize                 (GObject          *object);
64 static void        gtk_cell_view_dispose                  (GObject          *object);
65 static void        gtk_cell_view_size_allocate            (GtkWidget        *widget,
66                                                            GtkAllocation    *allocation);
67 static gboolean    gtk_cell_view_draw                     (GtkWidget        *widget,
68                                                            cairo_t          *cr);
69 static void        gtk_cell_view_set_value                (GtkCellView     *cell_view,
70                                                            GtkCellRenderer *renderer,
71                                                            gchar           *property,
72                                                            GValue          *value);
73 static void        gtk_cell_view_set_cell_data            (GtkCellView      *cell_view);
74
75 /* celllayout */
76 static void        gtk_cell_view_cell_layout_init         (GtkCellLayoutIface *iface);
77 static GtkCellArea *gtk_cell_view_cell_layout_get_area         (GtkCellLayout         *layout);
78
79
80 /* buildable */
81 static void       gtk_cell_view_buildable_init                 (GtkBuildableIface     *iface);
82 static gboolean   gtk_cell_view_buildable_custom_tag_start     (GtkBuildable          *buildable,
83                                                                 GtkBuilder            *builder,
84                                                                 GObject               *child,
85                                                                 const gchar           *tagname,
86                                                                 GMarkupParser         *parser,
87                                                                 gpointer              *data);
88 static void       gtk_cell_view_buildable_custom_tag_end       (GtkBuildable          *buildable,
89                                                                 GtkBuilder            *builder,
90                                                                 GObject               *child,
91                                                                 const gchar           *tagname,
92                                                                 gpointer              *data);
93
94 static GtkSizeRequestMode gtk_cell_view_get_request_mode       (GtkWidget             *widget);
95 static void       gtk_cell_view_get_preferred_width            (GtkWidget             *widget,
96                                                                 gint                  *minimum_size,
97                                                                 gint                  *natural_size);
98 static void       gtk_cell_view_get_preferred_height           (GtkWidget             *widget,
99                                                                 gint                  *minimum_size,
100                                                                 gint                  *natural_size);
101 static void       gtk_cell_view_get_preferred_width_for_height (GtkWidget             *widget,
102                                                                 gint                   avail_size,
103                                                                 gint                  *minimum_size,
104                                                                 gint                  *natural_size);
105 static void       gtk_cell_view_get_preferred_height_for_width (GtkWidget             *widget,
106                                                                 gint                   avail_size,
107                                                                 gint                  *minimum_size,
108                                                                 gint                  *natural_size);
109
110 static void       context_size_changed_cb                      (GtkCellAreaContext   *context,
111                                                                 GParamSpec           *pspec,
112                                                                 GtkWidget            *view);
113 static void       row_changed_cb                               (GtkTreeModel         *model,
114                                                                 GtkTreePath          *path,
115                                                                 GtkTreeIter          *iter,
116                                                                 GtkCellView          *view);
117
118
119 struct _GtkCellViewPrivate
120 {
121   GtkTreeModel        *model;
122   GtkTreeRowReference *displayed_row;
123
124   GtkCellArea         *area;
125   GtkCellAreaContext  *context;
126
127   GdkRGBA              background;
128
129   gulong               size_changed_id;
130   gulong               row_changed_id;
131
132   GtkOrientation       orientation;
133
134   guint                background_set : 1;
135   guint                draw_sensitive : 1;
136   guint                fit_model      : 1;
137 };
138
139 static GtkBuildableIface *parent_buildable_iface;
140
141 enum
142 {
143   PROP_0,
144   PROP_ORIENTATION,
145   PROP_BACKGROUND,
146   PROP_BACKGROUND_GDK,
147   PROP_BACKGROUND_RGBA,
148   PROP_BACKGROUND_SET,
149   PROP_MODEL,
150   PROP_CELL_AREA,
151   PROP_CELL_AREA_CONTEXT,
152   PROP_DRAW_SENSITIVE,
153   PROP_FIT_MODEL
154 };
155
156 G_DEFINE_TYPE_WITH_CODE (GtkCellView, gtk_cell_view, GTK_TYPE_WIDGET, 
157                          G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
158                                                 gtk_cell_view_cell_layout_init)
159                          G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
160                                                 gtk_cell_view_buildable_init)
161                          G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL));
162
163 static void
164 gtk_cell_view_class_init (GtkCellViewClass *klass)
165 {
166   GObjectClass   *gobject_class = G_OBJECT_CLASS (klass);
167   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
168
169   gobject_class->constructor = gtk_cell_view_constructor;
170   gobject_class->get_property = gtk_cell_view_get_property;
171   gobject_class->set_property = gtk_cell_view_set_property;
172   gobject_class->finalize = gtk_cell_view_finalize;
173   gobject_class->dispose = gtk_cell_view_dispose;
174
175   widget_class->draw                           = gtk_cell_view_draw;
176   widget_class->size_allocate                  = gtk_cell_view_size_allocate;
177   widget_class->get_request_mode               = gtk_cell_view_get_request_mode;
178   widget_class->get_preferred_width            = gtk_cell_view_get_preferred_width;
179   widget_class->get_preferred_height           = gtk_cell_view_get_preferred_height;
180   widget_class->get_preferred_width_for_height = gtk_cell_view_get_preferred_width_for_height;
181   widget_class->get_preferred_height_for_width = gtk_cell_view_get_preferred_height_for_width;
182
183   /* properties */
184   g_object_class_override_property (gobject_class, PROP_ORIENTATION, "orientation");
185
186   g_object_class_install_property (gobject_class,
187                                    PROP_BACKGROUND,
188                                    g_param_spec_string ("background",
189                                                         P_("Background color name"),
190                                                         P_("Background color as a string"),
191                                                         NULL,
192                                                         GTK_PARAM_WRITABLE));
193
194   /**
195    * GtkCellView:background-gdk:
196    *
197    * The background color as a #GdkColor
198    *
199    * Deprecated: 3.4: Use #GtkCellView:background-rgba instead.
200    */
201   g_object_class_install_property (gobject_class,
202                                    PROP_BACKGROUND_GDK,
203                                    g_param_spec_boxed ("background-gdk",
204                                                       P_("Background color"),
205                                                       P_("Background color as a GdkColor"),
206                                                       GDK_TYPE_COLOR,
207                                                       GTK_PARAM_READWRITE | G_PARAM_DEPRECATED));
208   /**
209    * GtkCellView:background-rgba:
210    *
211    * The background color as a #GdkRGBA
212    *
213    * Since: 3.0
214    */
215   g_object_class_install_property (gobject_class,
216                                    PROP_BACKGROUND_RGBA,
217                                    g_param_spec_boxed ("background-rgba",
218                                                       P_("Background RGBA color"),
219                                                       P_("Background color as a GdkRGBA"),
220                                                       GDK_TYPE_RGBA,
221                                                       GTK_PARAM_READWRITE));
222
223   /**
224    * GtkCellView:model:
225    *
226    * The model for cell view
227    *
228    * since 2.10
229    */
230   g_object_class_install_property (gobject_class,
231                                    PROP_MODEL,
232                                    g_param_spec_object  ("model",
233                                                          P_("CellView model"),
234                                                          P_("The model for cell view"),
235                                                          GTK_TYPE_TREE_MODEL,
236                                                          GTK_PARAM_READWRITE));
237
238
239   /**
240    * GtkCellView:cell-area:
241    *
242    * The #GtkCellArea rendering cells
243    *
244    * If no area is specified when creating the cell view with gtk_cell_view_new_with_context() 
245    * a horizontally oriented #GtkCellAreaBox will be used.
246    *
247    * since 3.0
248    */
249    g_object_class_install_property (gobject_class,
250                                     PROP_CELL_AREA,
251                                     g_param_spec_object ("cell-area",
252                                                          P_("Cell Area"),
253                                                          P_("The GtkCellArea used to layout cells"),
254                                                          GTK_TYPE_CELL_AREA,
255                                                          GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
256
257   /**
258    * GtkCellView:cell-area-context:
259    *
260    * The #GtkCellAreaContext used to compute the geometry of the cell view.
261    *
262    * A group of cell views can be assigned the same context in order to
263    * ensure the sizes and cell alignments match across all the views with
264    * the same context.
265    *
266    * #GtkComboBox menus uses this to assign the same context to all cell views
267    * in the menu items for a single menu (each submenu creates its own
268    * context since the size of each submenu does not depend on parent
269    * or sibling menus).
270    *
271    * since 3.0
272    */
273    g_object_class_install_property (gobject_class,
274                                     PROP_CELL_AREA_CONTEXT,
275                                     g_param_spec_object ("cell-area-context",
276                                                          P_("Cell Area Context"),
277                                                          P_("The GtkCellAreaContext used to "
278                                                             "compute the geometry of the cell view"),
279                                                          GTK_TYPE_CELL_AREA_CONTEXT,
280                                                          GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
281
282   /**
283    * GtkCellView:draw-sensitive:
284    *
285    * Whether all cells should be draw as sensitive for this view regardless
286    * of the actual cell properties (used to make menus with submenus appear
287    * sensitive when the items in submenus might be insensitive).
288    *
289    * since 3.0
290    */
291    g_object_class_install_property (gobject_class,
292                                     PROP_DRAW_SENSITIVE,
293                                     g_param_spec_boolean ("draw-sensitive",
294                                                           P_("Draw Sensitive"),
295                                                           P_("Whether to force cells to be drawn in a "
296                                                              "sensitive state"),
297                                                           FALSE,
298                                                           GTK_PARAM_READWRITE));
299
300   /**
301    * GtkCellView:fit-model:
302    *
303    * Whether the view should request enough space to always fit
304    * the size of every row in the model (used by the combo box to
305    * ensure the combo box size doesnt change when different items
306    * are selected).
307    *
308    * since 3.0
309    */
310    g_object_class_install_property (gobject_class,
311                                     PROP_FIT_MODEL,
312                                     g_param_spec_boolean ("fit-model",
313                                                           P_("Fit Model"),
314                                                           P_("Whether to request enough space for "
315                                                              "every row in the model"),
316                                                           FALSE,
317                                                           GTK_PARAM_READWRITE));
318
319   
320 #define ADD_SET_PROP(propname, propval, nick, blurb) g_object_class_install_property (gobject_class, propval, g_param_spec_boolean (propname, nick, blurb, FALSE, GTK_PARAM_READWRITE))
321
322   ADD_SET_PROP ("background-set", PROP_BACKGROUND_SET,
323                 P_("Background set"),
324                 P_("Whether this tag affects the background color"));
325
326   g_type_class_add_private (gobject_class, sizeof (GtkCellViewPrivate));
327 }
328
329 static void
330 gtk_cell_view_buildable_init (GtkBuildableIface *iface)
331 {
332   parent_buildable_iface = g_type_interface_peek_parent (iface);
333   iface->add_child = _gtk_cell_layout_buildable_add_child;
334   iface->custom_tag_start = gtk_cell_view_buildable_custom_tag_start;
335   iface->custom_tag_end = gtk_cell_view_buildable_custom_tag_end;
336 }
337
338 static void
339 gtk_cell_view_cell_layout_init (GtkCellLayoutIface *iface)
340 {
341   iface->get_area = gtk_cell_view_cell_layout_get_area;
342 }
343
344 static GObject *
345 gtk_cell_view_constructor (GType                  type,
346                            guint                  n_construct_properties,
347                            GObjectConstructParam *construct_properties)
348 {
349   GObject            *object;
350   GtkCellView        *view;
351   GtkCellViewPrivate *priv;
352
353   object = G_OBJECT_CLASS (gtk_cell_view_parent_class)->constructor
354     (type, n_construct_properties, construct_properties);
355
356   view = GTK_CELL_VIEW (object);
357   priv = view->priv;
358
359   if (!priv->area)
360     {
361       priv->area = gtk_cell_area_box_new ();
362       g_object_ref_sink (priv->area);
363     }
364
365   if (!priv->context)
366     priv->context = gtk_cell_area_create_context (priv->area);
367
368   priv->size_changed_id =
369     g_signal_connect (priv->context, "notify",
370                       G_CALLBACK (context_size_changed_cb), view);
371
372   return object;
373 }
374
375 static void
376 gtk_cell_view_get_property (GObject    *object,
377                             guint       param_id,
378                             GValue     *value,
379                             GParamSpec *pspec)
380 {
381   GtkCellView *view = GTK_CELL_VIEW (object);
382
383   switch (param_id)
384     {
385     case PROP_ORIENTATION:
386       g_value_set_enum (value, view->priv->orientation);
387       break;
388     case PROP_BACKGROUND_GDK:
389       {
390         GdkColor color;
391         
392         color.red = (guint) (view->priv->background.red * 65535);
393         color.green = (guint) (view->priv->background.green * 65535);
394         color.blue = (guint) (view->priv->background.blue * 65535);
395         color.pixel = 0;
396         
397         g_value_set_boxed (value, &color);
398       }
399       break;
400     case PROP_BACKGROUND_RGBA:
401       g_value_set_boxed (value, &view->priv->background);
402       break;
403     case PROP_BACKGROUND_SET:
404       g_value_set_boolean (value, view->priv->background_set);
405       break;
406     case PROP_MODEL:
407       g_value_set_object (value, view->priv->model);
408       break;
409     case PROP_CELL_AREA:
410       g_value_set_object (value, view->priv->area);
411       break;
412     case PROP_CELL_AREA_CONTEXT:
413       g_value_set_object (value, view->priv->context);
414       break;
415     case PROP_DRAW_SENSITIVE:
416       g_value_set_boolean (value, view->priv->draw_sensitive);
417       break;
418     case PROP_FIT_MODEL:
419       g_value_set_boolean (value, view->priv->fit_model);
420       break;
421     default:
422       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
423       break;
424     }
425 }
426
427 static void
428 gtk_cell_view_set_property (GObject      *object,
429                             guint         param_id,
430                             const GValue *value,
431                             GParamSpec   *pspec)
432 {
433   GtkCellView *view = GTK_CELL_VIEW (object);
434   GtkCellViewPrivate *priv = view->priv;
435   GtkCellArea *area;
436   GtkCellAreaContext *context;
437
438   switch (param_id)
439     {
440     case PROP_ORIENTATION:
441       priv->orientation = g_value_get_enum (value);
442       if (priv->context)
443         gtk_cell_area_context_reset (priv->context);
444
445       _gtk_orientable_set_style_classes (GTK_ORIENTABLE (object));
446       break;
447     case PROP_BACKGROUND:
448       {
449         GdkRGBA color;
450
451         if (!g_value_get_string (value))
452           gtk_cell_view_set_background_rgba (view, NULL);
453         else if (gdk_rgba_parse (&color, g_value_get_string (value)))
454           gtk_cell_view_set_background_rgba (view, &color);
455         else
456           g_warning ("Don't know color `%s'", g_value_get_string (value));
457
458         g_object_notify (object, "background-rgba");
459         g_object_notify (object, "background-gdk");
460       }
461       break;
462     case PROP_BACKGROUND_GDK:
463       {
464         GdkColor *color;
465         GdkRGBA rgba;
466
467         color = g_value_get_boxed (value);
468
469         rgba.red = color->red / 65535.0;
470         rgba.green = color->green / 65535.0;
471         rgba.blue = color->blue / 65535.0;
472         rgba.alpha = 1.0;
473
474         gtk_cell_view_set_background_rgba (view, &rgba);
475       }
476       break;
477     case PROP_BACKGROUND_RGBA:
478       gtk_cell_view_set_background_rgba (view, g_value_get_boxed (value));
479       break;
480     case PROP_BACKGROUND_SET:
481       view->priv->background_set = g_value_get_boolean (value);
482       break;
483     case PROP_MODEL:
484       gtk_cell_view_set_model (view, g_value_get_object (value));
485       break;
486     case PROP_CELL_AREA:
487       /* Construct-only, can only be assigned once */
488       area = g_value_get_object (value);
489
490       if (area)
491         {
492           if (priv->area != NULL)
493             {
494               g_warning ("cell-area has already been set, ignoring construct property");
495               g_object_ref_sink (area);
496               g_object_unref (area);
497             }
498           else
499             priv->area = g_object_ref_sink (area);
500         }
501       break;
502     case PROP_CELL_AREA_CONTEXT:
503       /* Construct-only, can only be assigned once */
504       context = g_value_get_object (value);
505
506       if (context)
507         {
508           if (priv->context != NULL)
509             {
510               g_warning ("cell-area-context has already been set, ignoring construct property");
511               g_object_ref_sink (context);
512               g_object_unref (context);
513             }
514           else
515             priv->context = g_object_ref (context);
516         }
517       break;
518
519     case PROP_DRAW_SENSITIVE:
520       gtk_cell_view_set_draw_sensitive (view, g_value_get_boolean (value));
521       break;
522
523     case PROP_FIT_MODEL:
524       gtk_cell_view_set_fit_model (view, g_value_get_boolean (value));
525       break;
526
527     default:
528         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
529         break;
530     }
531 }
532
533 static void
534 gtk_cell_view_init (GtkCellView *cellview)
535 {
536   GtkCellViewPrivate *priv;
537
538   cellview->priv = G_TYPE_INSTANCE_GET_PRIVATE (cellview,
539                                                 GTK_TYPE_CELL_VIEW,
540                                                 GtkCellViewPrivate);
541   priv = cellview->priv;
542
543   gtk_widget_set_has_window (GTK_WIDGET (cellview), FALSE);
544
545   priv->orientation = GTK_ORIENTATION_HORIZONTAL;
546 }
547
548 static void
549 gtk_cell_view_finalize (GObject *object)
550 {
551   GtkCellView *cellview = GTK_CELL_VIEW (object);
552
553   if (cellview->priv->displayed_row)
554      gtk_tree_row_reference_free (cellview->priv->displayed_row);
555
556   G_OBJECT_CLASS (gtk_cell_view_parent_class)->finalize (object);
557 }
558
559 static void
560 gtk_cell_view_dispose (GObject *object)
561 {
562   GtkCellView *cellview = GTK_CELL_VIEW (object);
563
564   gtk_cell_view_set_model (cellview, NULL);
565
566   if (cellview->priv->area)
567     {
568       g_object_unref (cellview->priv->area);
569       cellview->priv->area = NULL;
570     }
571
572   if (cellview->priv->context)
573     {
574       g_signal_handler_disconnect (cellview->priv->context, cellview->priv->size_changed_id);
575
576       g_object_unref (cellview->priv->context);
577       cellview->priv->context = NULL;
578       cellview->priv->size_changed_id = 0;
579     }
580
581   G_OBJECT_CLASS (gtk_cell_view_parent_class)->dispose (object);
582 }
583
584 static void
585 gtk_cell_view_size_allocate (GtkWidget     *widget,
586                              GtkAllocation *allocation)
587 {
588   GtkCellView        *cellview = GTK_CELL_VIEW (widget);
589   GtkCellViewPrivate *priv = cellview->priv;
590   gint                alloc_width, alloc_height;
591
592   gtk_widget_set_allocation (widget, allocation);
593
594   gtk_cell_area_context_get_allocation (priv->context, &alloc_width, &alloc_height);
595
596   /* The first cell view in context is responsible for allocating the context at allocate time 
597    * (or the cellview has its own context and is not grouped with any other cell views) 
598    *
599    * If the cellview is in "fit model" mode, we assume it's not in context and needs to
600    * allocate every time.
601    */
602   if (priv->fit_model)
603     gtk_cell_area_context_allocate (priv->context, allocation->width, allocation->height);
604   else if (alloc_width != allocation->width && priv->orientation == GTK_ORIENTATION_HORIZONTAL)
605     gtk_cell_area_context_allocate (priv->context, allocation->width, -1);
606   else if (alloc_height != allocation->height && priv->orientation == GTK_ORIENTATION_VERTICAL)
607     gtk_cell_area_context_allocate (priv->context, -1, allocation->height);
608 }
609
610 static void
611 gtk_cell_view_request_model (GtkCellView        *cellview,
612                              GtkTreeIter        *parent,
613                              GtkOrientation      orientation,
614                              gint                for_size,
615                              gint               *minimum_size,
616                              gint               *natural_size)
617 {
618   GtkCellViewPrivate *priv = cellview->priv;
619   GtkTreeIter         iter;
620   gboolean            valid;
621
622   if (!priv->model)
623     return;
624
625   valid = gtk_tree_model_iter_children (priv->model, &iter, parent);
626   while (valid)
627     {
628       gint min, nat;
629
630       gtk_cell_area_apply_attributes (priv->area, priv->model, &iter, FALSE, FALSE);
631
632       if (orientation == GTK_ORIENTATION_HORIZONTAL)
633         {
634           if (for_size < 0)
635             gtk_cell_area_get_preferred_width (priv->area, priv->context, 
636                                                GTK_WIDGET (cellview), &min, &nat);
637           else
638             gtk_cell_area_get_preferred_width_for_height (priv->area, priv->context, 
639                                                           GTK_WIDGET (cellview), for_size, &min, &nat);
640         }
641       else
642         {
643           if (for_size < 0)
644             gtk_cell_area_get_preferred_height (priv->area, priv->context, 
645                                                 GTK_WIDGET (cellview), &min, &nat);
646           else
647             gtk_cell_area_get_preferred_height_for_width (priv->area, priv->context, 
648                                                           GTK_WIDGET (cellview), for_size, &min, &nat);
649         }
650
651       *minimum_size = MAX (min, *minimum_size);
652       *natural_size = MAX (nat, *natural_size);
653
654       /* Recurse into children when they exist */
655       gtk_cell_view_request_model (cellview, &iter, orientation, for_size, minimum_size, natural_size);
656
657       valid = gtk_tree_model_iter_next (priv->model, &iter);
658     }
659 }
660
661 static GtkSizeRequestMode 
662 gtk_cell_view_get_request_mode (GtkWidget *widget)
663 {
664   GtkCellView        *cellview = GTK_CELL_VIEW (widget);
665   GtkCellViewPrivate *priv = cellview->priv;
666
667   return gtk_cell_area_get_request_mode (priv->area);
668 }
669
670 static void
671 gtk_cell_view_get_preferred_width  (GtkWidget *widget,
672                                     gint      *minimum_size,
673                                     gint      *natural_size)
674 {
675   GtkCellView        *cellview = GTK_CELL_VIEW (widget);
676   GtkCellViewPrivate *priv = cellview->priv;
677
678   g_signal_handler_block (priv->context, priv->size_changed_id);
679
680   if (priv->fit_model)
681     {
682       gint min = 0, nat = 0;
683       gtk_cell_view_request_model (cellview, NULL, GTK_ORIENTATION_HORIZONTAL, -1, &min, &nat);
684     }
685   else
686     {
687       if (cellview->priv->displayed_row)
688         gtk_cell_view_set_cell_data (cellview);
689
690       gtk_cell_area_get_preferred_width (priv->area, priv->context, widget, NULL, NULL);
691     }
692
693   gtk_cell_area_context_get_preferred_width (priv->context, minimum_size, natural_size);
694
695   g_signal_handler_unblock (priv->context, priv->size_changed_id);
696 }
697
698 static void       
699 gtk_cell_view_get_preferred_height (GtkWidget *widget,
700                                     gint      *minimum_size,
701                                     gint      *natural_size)
702 {
703   GtkCellView        *cellview = GTK_CELL_VIEW (widget);
704   GtkCellViewPrivate *priv = cellview->priv;
705
706   g_signal_handler_block (priv->context, priv->size_changed_id);
707
708   if (priv->fit_model)
709     {
710       gint min = 0, nat = 0;
711       gtk_cell_view_request_model (cellview, NULL, GTK_ORIENTATION_VERTICAL, -1, &min, &nat);
712     }
713   else
714     {
715       if (cellview->priv->displayed_row)
716         gtk_cell_view_set_cell_data (cellview);
717       
718       gtk_cell_area_get_preferred_height (priv->area, priv->context, widget, NULL, NULL);
719     }
720
721   gtk_cell_area_context_get_preferred_height (priv->context, minimum_size, natural_size);
722
723   g_signal_handler_unblock (priv->context, priv->size_changed_id);
724 }
725
726 static void       
727 gtk_cell_view_get_preferred_width_for_height (GtkWidget *widget,
728                                               gint       for_size,
729                                               gint      *minimum_size,
730                                               gint      *natural_size)
731 {
732   GtkCellView        *cellview = GTK_CELL_VIEW (widget);
733   GtkCellViewPrivate *priv = cellview->priv;
734
735   if (priv->fit_model)
736     {
737       gint min = 0, nat = 0;
738       gtk_cell_view_request_model (cellview, NULL, GTK_ORIENTATION_HORIZONTAL, for_size, &min, &nat);
739
740       *minimum_size = min;
741       *natural_size = nat;
742     }
743   else
744     {
745       if (cellview->priv->displayed_row)
746         gtk_cell_view_set_cell_data (cellview);
747
748       gtk_cell_area_get_preferred_width_for_height (priv->area, priv->context, widget, 
749                                                     for_size, minimum_size, natural_size);
750     }
751 }
752
753 static void       
754 gtk_cell_view_get_preferred_height_for_width (GtkWidget *widget,
755                                               gint       for_size,
756                                               gint      *minimum_size,
757                                               gint      *natural_size)
758 {
759   GtkCellView        *cellview = GTK_CELL_VIEW (widget);
760   GtkCellViewPrivate *priv = cellview->priv;
761
762   if (priv->fit_model)
763     {
764       gint min = 0, nat = 0;
765       gtk_cell_view_request_model (cellview, NULL, GTK_ORIENTATION_VERTICAL, for_size, &min, &nat);
766
767       *minimum_size = min;
768       *natural_size = nat;
769     }
770   else
771     {
772       if (cellview->priv->displayed_row)
773         gtk_cell_view_set_cell_data (cellview);
774
775       gtk_cell_area_get_preferred_height_for_width (priv->area, priv->context, widget, 
776                                                     for_size, minimum_size, natural_size);
777     }
778 }
779
780 static gboolean
781 gtk_cell_view_draw (GtkWidget *widget,
782                     cairo_t   *cr)
783 {
784   GtkCellView *cellview;
785   GdkRectangle area;
786   GtkCellRendererState state;
787
788   cellview = GTK_CELL_VIEW (widget);
789
790   /* render cells */
791   area.x = 0;
792   area.y = 0;
793   area.width  = gtk_widget_get_allocated_width (widget);
794   area.height = gtk_widget_get_allocated_height (widget);
795
796   /* "blank" background */
797   if (cellview->priv->background_set)
798     {
799       gdk_cairo_rectangle (cr, &area);
800       gdk_cairo_set_source_rgba (cr, &cellview->priv->background);
801       cairo_fill (cr);
802     }
803
804   /* set cell data (if available) */
805   if (cellview->priv->displayed_row)
806     gtk_cell_view_set_cell_data (cellview);
807   else if (cellview->priv->model)
808     return FALSE;
809
810   if (gtk_widget_get_state_flags (widget) & GTK_STATE_FLAG_PRELIGHT)
811     state = GTK_CELL_RENDERER_PRELIT;
812   else
813     state = 0;
814       
815   /* Render the cells */
816   gtk_cell_area_render (cellview->priv->area, cellview->priv->context, 
817                         widget, cr, &area, &area, state, FALSE);
818
819   return FALSE;
820 }
821
822 static void
823 gtk_cell_view_set_cell_data (GtkCellView *cell_view)
824 {
825   GtkTreeIter iter;
826   GtkTreePath *path;
827
828   g_return_if_fail (cell_view->priv->displayed_row != NULL);
829
830   path = gtk_tree_row_reference_get_path (cell_view->priv->displayed_row);
831   if (!path)
832     return;
833
834   gtk_tree_model_get_iter (cell_view->priv->model, &iter, path);
835   gtk_tree_path_free (path);
836
837   gtk_cell_area_apply_attributes (cell_view->priv->area, 
838                                   cell_view->priv->model, 
839                                   &iter, FALSE, FALSE);
840
841   if (cell_view->priv->draw_sensitive)
842     {
843       GList *l, *cells = 
844         gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (cell_view->priv->area));
845
846       for (l = cells; l; l = l->next)
847         {
848           GObject *renderer = l->data;
849
850           g_object_set (renderer, "sensitive", TRUE, NULL);
851         }
852       g_list_free (cells);
853     }
854 }
855
856 /* GtkCellLayout implementation */
857 static GtkCellArea *
858 gtk_cell_view_cell_layout_get_area (GtkCellLayout   *layout)
859 {
860   GtkCellView *cellview = GTK_CELL_VIEW (layout);
861   GtkCellViewPrivate *priv = cellview->priv;
862
863   if (G_UNLIKELY (!priv->area))
864     {
865       priv->area = gtk_cell_area_box_new ();
866       g_object_ref_sink (priv->area);
867     }
868
869   return priv->area;
870 }
871
872 /* GtkBuildable implementation */
873 static gboolean
874 gtk_cell_view_buildable_custom_tag_start (GtkBuildable  *buildable,
875                                           GtkBuilder    *builder,
876                                           GObject       *child,
877                                           const gchar   *tagname,
878                                           GMarkupParser *parser,
879                                           gpointer      *data)
880 {
881   if (parent_buildable_iface->custom_tag_start &&
882       parent_buildable_iface->custom_tag_start (buildable, builder, child,
883                                                 tagname, parser, data))
884     return TRUE;
885
886   return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
887                                                       tagname, parser, data);
888 }
889
890 static void
891 gtk_cell_view_buildable_custom_tag_end (GtkBuildable *buildable,
892                                         GtkBuilder   *builder,
893                                         GObject      *child,
894                                         const gchar  *tagname,
895                                         gpointer     *data)
896 {
897   if (_gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
898                                                  data))
899     return;
900   else if (parent_buildable_iface->custom_tag_end)
901     parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,
902                                             data);
903 }
904
905 static void
906 context_size_changed_cb (GtkCellAreaContext  *context,
907                          GParamSpec          *pspec,
908                          GtkWidget           *view)
909 {
910   if (!strcmp (pspec->name, "minimum-width") ||
911       !strcmp (pspec->name, "natural-width") ||
912       !strcmp (pspec->name, "minimum-height") ||
913       !strcmp (pspec->name, "natural-height"))
914     gtk_widget_queue_resize (view);
915 }
916
917 static void
918 row_changed_cb (GtkTreeModel         *model,
919                 GtkTreePath          *path,
920                 GtkTreeIter          *iter,
921                 GtkCellView          *view)
922 {
923   GtkTreePath *row_path;
924
925   if (view->priv->displayed_row)
926     {
927       row_path = 
928         gtk_tree_row_reference_get_path (view->priv->displayed_row);
929
930       if (row_path)
931         {
932           /* Resize everything in our context if our row changed */
933           if (gtk_tree_path_compare (row_path, path) == 0)
934             gtk_cell_area_context_reset (view->priv->context);
935
936           gtk_tree_path_free (row_path);
937         }
938     }
939 }
940
941 /**
942  * gtk_cell_view_new:
943  *
944  * Creates a new #GtkCellView widget.
945  *
946  * Return value: A newly created #GtkCellView widget.
947  *
948  * Since: 2.6
949  */
950 GtkWidget *
951 gtk_cell_view_new (void)
952 {
953   GtkCellView *cellview;
954
955   cellview = g_object_new (gtk_cell_view_get_type (), NULL);
956
957   return GTK_WIDGET (cellview);
958 }
959
960
961 /**
962  * gtk_cell_view_new_with_context:
963  * @area: the #GtkCellArea to layout cells
964  * @context: the #GtkCellAreaContext in which to calculate cell geometry
965  *
966  * Creates a new #GtkCellView widget with a specific #GtkCellArea
967  * to layout cells and a specific #GtkCellAreaContext.
968  *
969  * Specifying the same context for a handfull of cells lets
970  * the underlying area synchronize the geometry for those cells,
971  * in this way alignments with cellviews for other rows are
972  * possible.
973  *
974  * Return value: A newly created #GtkCellView widget.
975  *
976  * Since: 2.6
977  */
978 GtkWidget *
979 gtk_cell_view_new_with_context (GtkCellArea        *area,
980                                 GtkCellAreaContext *context)
981 {
982   g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
983   g_return_val_if_fail (context == NULL || GTK_IS_CELL_AREA_CONTEXT (context), NULL);
984
985   return (GtkWidget *)g_object_new (GTK_TYPE_CELL_VIEW, 
986                                     "cell-area", area,
987                                     "cell-area-context", context,
988                                     NULL);
989 }
990
991 /**
992  * gtk_cell_view_new_with_text:
993  * @text: the text to display in the cell view
994  *
995  * Creates a new #GtkCellView widget, adds a #GtkCellRendererText 
996  * to it, and makes it show @text.
997  *
998  * Return value: A newly created #GtkCellView widget.
999  *
1000  * Since: 2.6
1001  */
1002 GtkWidget *
1003 gtk_cell_view_new_with_text (const gchar *text)
1004 {
1005   GtkCellView *cellview;
1006   GtkCellRenderer *renderer;
1007   GValue value = G_VALUE_INIT;
1008
1009   cellview = GTK_CELL_VIEW (gtk_cell_view_new ());
1010
1011   renderer = gtk_cell_renderer_text_new ();
1012   gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cellview),
1013                               renderer, TRUE);
1014
1015   g_value_init (&value, G_TYPE_STRING);
1016   g_value_set_string (&value, text);
1017   gtk_cell_view_set_value (cellview, renderer, "text", &value);
1018   g_value_unset (&value);
1019
1020   return GTK_WIDGET (cellview);
1021 }
1022
1023 /**
1024  * gtk_cell_view_new_with_markup:
1025  * @markup: the text to display in the cell view
1026  *
1027  * Creates a new #GtkCellView widget, adds a #GtkCellRendererText 
1028  * to it, and makes it show @markup. The text can be
1029  * marked up with the <link linkend="PangoMarkupFormat">Pango text 
1030  * markup language</link>.
1031  *
1032  * Return value: A newly created #GtkCellView widget.
1033  *
1034  * Since: 2.6
1035  */
1036 GtkWidget *
1037 gtk_cell_view_new_with_markup (const gchar *markup)
1038 {
1039   GtkCellView *cellview;
1040   GtkCellRenderer *renderer;
1041   GValue value = G_VALUE_INIT;
1042
1043   cellview = GTK_CELL_VIEW (gtk_cell_view_new ());
1044
1045   renderer = gtk_cell_renderer_text_new ();
1046   gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cellview),
1047                               renderer, TRUE);
1048
1049   g_value_init (&value, G_TYPE_STRING);
1050   g_value_set_string (&value, markup);
1051   gtk_cell_view_set_value (cellview, renderer, "markup", &value);
1052   g_value_unset (&value);
1053
1054   return GTK_WIDGET (cellview);
1055 }
1056
1057 /**
1058  * gtk_cell_view_new_with_pixbuf:
1059  * @pixbuf: the image to display in the cell view
1060  *
1061  * Creates a new #GtkCellView widget, adds a #GtkCellRendererPixbuf
1062  * to it, and makes it show @pixbuf.
1063  *
1064  * Return value: A newly created #GtkCellView widget.
1065  *
1066  * Since: 2.6
1067  */
1068 GtkWidget *
1069 gtk_cell_view_new_with_pixbuf (GdkPixbuf *pixbuf)
1070 {
1071   GtkCellView *cellview;
1072   GtkCellRenderer *renderer;
1073   GValue value = G_VALUE_INIT;
1074
1075   cellview = GTK_CELL_VIEW (gtk_cell_view_new ());
1076
1077   renderer = gtk_cell_renderer_pixbuf_new ();
1078   gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cellview),
1079                               renderer, TRUE);
1080
1081   g_value_init (&value, GDK_TYPE_PIXBUF);
1082   g_value_set_object (&value, pixbuf);
1083   gtk_cell_view_set_value (cellview, renderer, "pixbuf", &value);
1084   g_value_unset (&value);
1085
1086   return GTK_WIDGET (cellview);
1087 }
1088
1089 /**
1090  * gtk_cell_view_set_value:
1091  * @cell_view: a #GtkCellView widget
1092  * @renderer: one of the renderers of @cell_view
1093  * @property: the name of the property of @renderer to set
1094  * @value: the new value to set the property to
1095  * 
1096  * Sets a property of a cell renderer of @cell_view, and
1097  * makes sure the display of @cell_view is updated.
1098  *
1099  * Since: 2.6
1100  */
1101 static void
1102 gtk_cell_view_set_value (GtkCellView     *cell_view,
1103                          GtkCellRenderer *renderer,
1104                          gchar           *property,
1105                          GValue          *value)
1106 {
1107   g_object_set_property (G_OBJECT (renderer), property, value);
1108
1109   /* force resize and redraw */
1110   gtk_widget_queue_resize (GTK_WIDGET (cell_view));
1111   gtk_widget_queue_draw (GTK_WIDGET (cell_view));
1112 }
1113
1114 /**
1115  * gtk_cell_view_set_model:
1116  * @cell_view: a #GtkCellView
1117  * @model: (allow-none): a #GtkTreeModel
1118  *
1119  * Sets the model for @cell_view.  If @cell_view already has a model
1120  * set, it will remove it before setting the new model.  If @model is
1121  * %NULL, then it will unset the old model.
1122  *
1123  * Since: 2.6
1124  */
1125 void
1126 gtk_cell_view_set_model (GtkCellView  *cell_view,
1127                          GtkTreeModel *model)
1128 {
1129   g_return_if_fail (GTK_IS_CELL_VIEW (cell_view));
1130   g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
1131
1132   if (cell_view->priv->model)
1133     {
1134       g_signal_handler_disconnect (cell_view->priv->model, 
1135                                    cell_view->priv->row_changed_id);
1136       cell_view->priv->row_changed_id = 0;
1137
1138       if (cell_view->priv->displayed_row)
1139         gtk_tree_row_reference_free (cell_view->priv->displayed_row);
1140       cell_view->priv->displayed_row = NULL;
1141
1142       g_object_unref (cell_view->priv->model);
1143     }
1144
1145   cell_view->priv->model = model;
1146
1147   if (cell_view->priv->model)
1148     {
1149       g_object_ref (cell_view->priv->model);
1150
1151       cell_view->priv->row_changed_id = 
1152         g_signal_connect (cell_view->priv->model, "row-changed",
1153                           G_CALLBACK (row_changed_cb), cell_view);
1154     }
1155 }
1156
1157 /**
1158  * gtk_cell_view_get_model:
1159  * @cell_view: a #GtkCellView
1160  *
1161  * Returns the model for @cell_view. If no model is used %NULL is
1162  * returned.
1163  *
1164  * Returns: (transfer none): a #GtkTreeModel used or %NULL
1165  *
1166  * Since: 2.16
1167  **/
1168 GtkTreeModel *
1169 gtk_cell_view_get_model (GtkCellView *cell_view)
1170 {
1171   g_return_val_if_fail (GTK_IS_CELL_VIEW (cell_view), NULL);
1172
1173   return cell_view->priv->model;
1174 }
1175
1176 /**
1177  * gtk_cell_view_set_displayed_row:
1178  * @cell_view: a #GtkCellView
1179  * @path: (allow-none): a #GtkTreePath or %NULL to unset.
1180  *
1181  * Sets the row of the model that is currently displayed
1182  * by the #GtkCellView. If the path is unset, then the
1183  * contents of the cellview "stick" at their last value;
1184  * this is not normally a desired result, but may be
1185  * a needed intermediate state if say, the model for
1186  * the #GtkCellView becomes temporarily empty.
1187  *
1188  * Since: 2.6
1189  **/
1190 void
1191 gtk_cell_view_set_displayed_row (GtkCellView *cell_view,
1192                                  GtkTreePath *path)
1193 {
1194   g_return_if_fail (GTK_IS_CELL_VIEW (cell_view));
1195   g_return_if_fail (GTK_IS_TREE_MODEL (cell_view->priv->model));
1196
1197   if (cell_view->priv->displayed_row)
1198     gtk_tree_row_reference_free (cell_view->priv->displayed_row);
1199
1200   if (path)
1201     {
1202       cell_view->priv->displayed_row =
1203         gtk_tree_row_reference_new (cell_view->priv->model, path);
1204     }
1205   else
1206     cell_view->priv->displayed_row = NULL;
1207
1208   /* force resize and redraw */
1209   gtk_widget_queue_resize (GTK_WIDGET (cell_view));
1210   gtk_widget_queue_draw (GTK_WIDGET (cell_view));
1211 }
1212
1213 /**
1214  * gtk_cell_view_get_displayed_row:
1215  * @cell_view: a #GtkCellView
1216  *
1217  * Returns a #GtkTreePath referring to the currently 
1218  * displayed row. If no row is currently displayed, 
1219  * %NULL is returned.
1220  *
1221  * Returns: the currently displayed row or %NULL
1222  *
1223  * Since: 2.6
1224  */
1225 GtkTreePath *
1226 gtk_cell_view_get_displayed_row (GtkCellView *cell_view)
1227 {
1228   g_return_val_if_fail (GTK_IS_CELL_VIEW (cell_view), NULL);
1229
1230   if (!cell_view->priv->displayed_row)
1231     return NULL;
1232
1233   return gtk_tree_row_reference_get_path (cell_view->priv->displayed_row);
1234 }
1235
1236 /**
1237  * gtk_cell_view_get_size_of_row:
1238  * @cell_view: a #GtkCellView
1239  * @path: a #GtkTreePath 
1240  * @requisition: (out): return location for the size 
1241  *
1242  * Sets @requisition to the size needed by @cell_view to display 
1243  * the model row pointed to by @path.
1244  * 
1245  * Return value: %TRUE
1246  *
1247  * Since: 2.6
1248  * 
1249  * Deprecated: 3.0: Combo box formerly used this to calculate the
1250  * sizes for cellviews, now you can achieve this by either using
1251  * the #GtkCellView:fit-model property or by setting the currently
1252  * displayed row of the #GtkCellView and using gtk_widget_get_preferred_size().
1253  */
1254 gboolean
1255 gtk_cell_view_get_size_of_row (GtkCellView    *cell_view,
1256                                GtkTreePath    *path,
1257                                GtkRequisition *requisition)
1258 {
1259   GtkTreeRowReference *tmp;
1260   GtkRequisition req;
1261
1262   g_return_val_if_fail (GTK_IS_CELL_VIEW (cell_view), FALSE);
1263   g_return_val_if_fail (path != NULL, FALSE);
1264
1265   tmp = cell_view->priv->displayed_row;
1266   cell_view->priv->displayed_row =
1267     gtk_tree_row_reference_new (cell_view->priv->model, path);
1268
1269   gtk_widget_get_preferred_width (GTK_WIDGET (cell_view), &req.width, NULL);
1270   gtk_widget_get_preferred_height_for_width (GTK_WIDGET (cell_view), req.width, &req.height, NULL);
1271
1272   gtk_tree_row_reference_free (cell_view->priv->displayed_row);
1273   cell_view->priv->displayed_row = tmp;
1274
1275   if (requisition)
1276     *requisition = req;
1277
1278   return TRUE;
1279 }
1280
1281 /**
1282  * gtk_cell_view_set_background_color:
1283  * @cell_view: a #GtkCellView
1284  * @color: the new background color
1285  *
1286  * Sets the background color of @view.
1287  *
1288  * Since: 2.6
1289  *
1290  * Deprecated: 3.4: Use gtk_cell_view_set_background_rgba() instead.
1291  */
1292 void
1293 gtk_cell_view_set_background_color (GtkCellView    *cell_view,
1294                                     const GdkColor *color)
1295 {
1296   g_return_if_fail (GTK_IS_CELL_VIEW (cell_view));
1297
1298   if (color)
1299     {
1300       if (!cell_view->priv->background_set)
1301         {
1302           cell_view->priv->background_set = TRUE;
1303           g_object_notify (G_OBJECT (cell_view), "background-set");
1304         }
1305
1306       cell_view->priv->background.red = color->red / 65535.;
1307       cell_view->priv->background.green = color->green / 65535.;
1308       cell_view->priv->background.blue = color->blue / 65535.;
1309       cell_view->priv->background.alpha = 1;
1310     }
1311   else
1312     {
1313       if (cell_view->priv->background_set)
1314         {
1315           cell_view->priv->background_set = FALSE;
1316           g_object_notify (G_OBJECT (cell_view), "background-set");
1317         }
1318     }
1319
1320   gtk_widget_queue_draw (GTK_WIDGET (cell_view));
1321 }
1322
1323 /**
1324  * gtk_cell_view_set_background_rgba:
1325  * @cell_view: a #GtkCellView
1326  * @rgba: the new background color
1327  *
1328  * Sets the background color of @cell_view.
1329  *
1330  * Since: 3.0
1331  */
1332 void
1333 gtk_cell_view_set_background_rgba (GtkCellView   *cell_view,
1334                                    const GdkRGBA *rgba)
1335 {
1336   g_return_if_fail (GTK_IS_CELL_VIEW (cell_view));
1337
1338   if (rgba)
1339     {
1340       if (!cell_view->priv->background_set)
1341         {
1342           cell_view->priv->background_set = TRUE;
1343           g_object_notify (G_OBJECT (cell_view), "background-set");
1344         }
1345
1346       cell_view->priv->background = *rgba;
1347     }
1348   else
1349     {
1350       if (cell_view->priv->background_set)
1351         {
1352           cell_view->priv->background_set = FALSE;
1353           g_object_notify (G_OBJECT (cell_view), "background-set");
1354         }
1355     }
1356
1357   gtk_widget_queue_draw (GTK_WIDGET (cell_view));
1358 }
1359
1360 /**
1361  * gtk_cell_view_get_draw_sensitive:
1362  * @cell_view: a #GtkCellView
1363  *
1364  * Gets whether @cell_view is configured to draw all of its
1365  * cells in a sensitive state.
1366  *
1367  * Return value: whether @cell_view draws all of its
1368  * cells in a sensitive state
1369  *
1370  * Since: 3.0
1371  */
1372 gboolean
1373 gtk_cell_view_get_draw_sensitive (GtkCellView     *cell_view)
1374 {
1375   GtkCellViewPrivate *priv;
1376
1377   g_return_val_if_fail (GTK_IS_CELL_VIEW (cell_view), FALSE);
1378
1379   priv = cell_view->priv;
1380
1381   return priv->draw_sensitive;
1382 }
1383
1384 /**
1385  * gtk_cell_view_set_draw_sensitive:
1386  * @cell_view: a #GtkCellView
1387  * @draw_sensitive: whether to draw all cells in a sensitive state.
1388  *
1389  * Sets whether @cell_view should draw all of its
1390  * cells in a sensitive state, this is used by #GtkComboBox menus
1391  * to ensure that rows with insensitive cells that contain
1392  * children appear sensitive in the parent menu item.
1393  *
1394  * Since: 3.0
1395  */
1396 void
1397 gtk_cell_view_set_draw_sensitive (GtkCellView     *cell_view,
1398                                   gboolean         draw_sensitive)
1399 {
1400   GtkCellViewPrivate *priv;
1401
1402   g_return_if_fail (GTK_IS_CELL_VIEW (cell_view));
1403
1404   priv = cell_view->priv;
1405
1406   if (priv->draw_sensitive != draw_sensitive)
1407     {
1408       priv->draw_sensitive = draw_sensitive;
1409
1410       g_object_notify (G_OBJECT (cell_view), "draw-sensitive");
1411     }
1412 }
1413
1414 /**
1415  * gtk_cell_view_get_fit_model:
1416  * @cell_view: a #GtkCellView
1417  *
1418  * Gets whether @cell_view is configured to request space
1419  * to fit the entire #GtkTreeModel.
1420  *
1421  * Return value: whether @cell_view requests space to fit
1422  * the entire #GtkTreeModel.
1423  *
1424  * Since: 3.0
1425  */
1426 gboolean
1427 gtk_cell_view_get_fit_model (GtkCellView     *cell_view)
1428 {
1429   GtkCellViewPrivate *priv;
1430
1431   g_return_val_if_fail (GTK_IS_CELL_VIEW (cell_view), FALSE);
1432
1433   priv = cell_view->priv;
1434
1435   return priv->fit_model;
1436 }
1437
1438 /**
1439  * gtk_cell_view_set_fit_model:
1440  * @cell_view: a #GtkCellView
1441  * @fit_model: whether @cell_view should request space for the whole model.
1442  *
1443  * Sets whether @cell_view should request space to fit the entire #GtkTreeModel.
1444  *
1445  * This is used by #GtkComboBox to ensure that the cell view displayed on
1446  * the combo box's button always gets enough space and does not resize
1447  * when selection changes.
1448  *
1449  * Since: 3.0
1450  */
1451 void
1452 gtk_cell_view_set_fit_model (GtkCellView *cell_view,
1453                              gboolean     fit_model)
1454 {
1455   GtkCellViewPrivate *priv;
1456
1457   g_return_if_fail (GTK_IS_CELL_VIEW (cell_view));
1458
1459   priv = cell_view->priv;
1460
1461   if (priv->fit_model != fit_model)
1462     {
1463       priv->fit_model = fit_model;
1464
1465       gtk_cell_area_context_reset (cell_view->priv->context);
1466
1467       g_object_notify (G_OBJECT (cell_view), "fit-model");
1468     }
1469 }