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