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