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