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