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