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