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