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