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