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