]> Pileus Git - ~andy/gtk/blob - gtk/gtkcellview.c
cellview: Port to Cairo rendering
[~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   gtk_widget_set_allocation (widget, 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   GtkAllocation allocation;
433   GList *list;
434   GtkCellView *cellview;
435   GdkRectangle area;
436   GtkCellRendererState state;
437   gboolean rtl = (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL);
438   GtkPackType packing;
439   cairo_t *cr;
440
441   cellview = GTK_CELL_VIEW (widget);
442
443   if (!gtk_widget_is_drawable (widget))
444     return FALSE;
445
446   gtk_widget_get_allocation (widget, &allocation);
447   cr = gdk_cairo_create (event->window);
448   gdk_cairo_region (cr, event->region);
449   cairo_clip (cr);
450
451   /* "blank" background */
452   if (cellview->priv->background_set)
453     {
454       gdk_cairo_rectangle (cr, &allocation);
455       cairo_set_source_rgb (cr,
456                             cellview->priv->background.red / 65535.,
457                             cellview->priv->background.green / 65535.,
458                             cellview->priv->background.blue / 65535.);
459       cairo_fill (cr);
460     }
461
462   /* set cell data (if available) */
463   if (cellview->priv->displayed_row)
464     gtk_cell_view_set_cell_data (cellview);
465   else if (cellview->priv->model)
466     {
467       cairo_destroy (cr);
468       return FALSE;
469     }
470
471   /* render cells */
472   area = allocation;
473
474   /* we draw on our very own window, initialize x and y to zero */
475   area.y = allocation.y;
476
477   if (gtk_widget_get_state (widget) == GTK_STATE_PRELIGHT)
478     state = GTK_CELL_RENDERER_PRELIT;
479   else if (gtk_widget_get_state (widget) == GTK_STATE_INSENSITIVE)
480     state = GTK_CELL_RENDERER_INSENSITIVE;
481   else
482     state = 0;
483       
484   for (packing = GTK_PACK_START; packing <= GTK_PACK_END; ++packing)
485     {
486       if (packing == GTK_PACK_START)
487         area.x = allocation.x + (rtl ? allocation.width : 0);
488       else
489         area.x = rtl ? allocation.x : (allocation.x + allocation.width);
490
491       for (list = cellview->priv->cell_list; list; list = list->next)
492         {
493           GtkCellViewCellInfo *info = (GtkCellViewCellInfo *)list->data;
494
495           if (info->pack != packing)
496             continue;
497
498           if (!gtk_cell_renderer_get_visible (info->cell))
499             continue;
500
501           area.width = info->real_width;
502
503           if ((packing == GTK_PACK_START && rtl) ||
504               (packing == GTK_PACK_END && !rtl))
505             area.x -= area.width;
506
507           gtk_cell_renderer_render_cairo (info->cell,
508                                           cr,
509                                           widget,
510                                           /* FIXME! */
511                                           &area, &area, state);
512
513           if ((packing == GTK_PACK_START && !rtl) ||
514               (packing == GTK_PACK_END && rtl))
515             {
516               area.x += area.width;
517               area.x += cellview->priv->spacing;
518             }
519           else
520             area.x -= cellview->priv->spacing;
521         }
522     }
523
524   cairo_destroy (cr);
525
526   return FALSE;
527 }
528
529 static GtkCellViewCellInfo *
530 gtk_cell_view_get_cell_info (GtkCellView     *cellview,
531                              GtkCellRenderer *renderer)
532 {
533   GList *i;
534
535   for (i = cellview->priv->cell_list; i; i = i->next)
536     {
537       GtkCellViewCellInfo *info = (GtkCellViewCellInfo *)i->data;
538
539       if (info->cell == renderer)
540         return info;
541     }
542
543   return NULL;
544 }
545
546 static void
547 gtk_cell_view_set_cell_data (GtkCellView *cell_view)
548 {
549   GList *i;
550   GtkTreeIter iter;
551   GtkTreePath *path;
552
553   g_return_if_fail (cell_view->priv->displayed_row != NULL);
554
555   path = gtk_tree_row_reference_get_path (cell_view->priv->displayed_row);
556   if (!path)
557     return;
558
559   gtk_tree_model_get_iter (cell_view->priv->model, &iter, path);
560   gtk_tree_path_free (path);
561
562   for (i = cell_view->priv->cell_list; i; i = i->next)
563     {
564       GSList *j;
565       GtkCellViewCellInfo *info = i->data;
566
567       g_object_freeze_notify (G_OBJECT (info->cell));
568
569       for (j = info->attributes; j && j->next; j = j->next->next)
570         {
571           gchar *property = j->data;
572           gint column = GPOINTER_TO_INT (j->next->data);
573           GValue value = {0, };
574
575           gtk_tree_model_get_value (cell_view->priv->model, &iter,
576                                     column, &value);
577           g_object_set_property (G_OBJECT (info->cell),
578                                  property, &value);
579           g_value_unset (&value);
580         }
581
582       if (info->func)
583         (* info->func) (GTK_CELL_LAYOUT (cell_view),
584                         info->cell,
585                         cell_view->priv->model,
586                         &iter,
587                         info->func_data);
588
589       g_object_thaw_notify (G_OBJECT (info->cell));
590     }
591 }
592
593 /* GtkCellLayout implementation */
594 static void
595 gtk_cell_view_cell_layout_pack_start (GtkCellLayout   *layout,
596                                       GtkCellRenderer *renderer,
597                                       gboolean         expand)
598 {
599   GtkCellViewCellInfo *info;
600   GtkCellView *cellview = GTK_CELL_VIEW (layout);
601
602   g_return_if_fail (!gtk_cell_view_get_cell_info (cellview, renderer));
603
604   g_object_ref_sink (renderer);
605
606   info = g_slice_new0 (GtkCellViewCellInfo);
607   info->cell = renderer;
608   info->expand = expand ? TRUE : FALSE;
609   info->pack = GTK_PACK_START;
610
611   cellview->priv->cell_list = g_list_append (cellview->priv->cell_list, info);
612
613   gtk_widget_queue_resize (GTK_WIDGET (cellview));
614 }
615
616 static void
617 gtk_cell_view_cell_layout_pack_end (GtkCellLayout   *layout,
618                                     GtkCellRenderer *renderer,
619                                     gboolean         expand)
620 {
621   GtkCellViewCellInfo *info;
622   GtkCellView *cellview = GTK_CELL_VIEW (layout);
623
624   g_return_if_fail (!gtk_cell_view_get_cell_info (cellview, renderer));
625
626   g_object_ref_sink (renderer);
627
628   info = g_slice_new0 (GtkCellViewCellInfo);
629   info->cell = renderer;
630   info->expand = expand ? TRUE : FALSE;
631   info->pack = GTK_PACK_END;
632
633   cellview->priv->cell_list = g_list_append (cellview->priv->cell_list, info);
634
635   gtk_widget_queue_resize (GTK_WIDGET (cellview));
636 }
637
638 static void
639 gtk_cell_view_cell_layout_add_attribute (GtkCellLayout   *layout,
640                                          GtkCellRenderer *renderer,
641                                          const gchar     *attribute,
642                                          gint             column)
643 {
644   GtkCellViewCellInfo *info;
645   GtkCellView *cellview = GTK_CELL_VIEW (layout);
646
647   info = gtk_cell_view_get_cell_info (cellview, renderer);
648   g_return_if_fail (info != NULL);
649
650   info->attributes = g_slist_prepend (info->attributes,
651                                       GINT_TO_POINTER (column));
652   info->attributes = g_slist_prepend (info->attributes,
653                                       g_strdup (attribute));
654 }
655
656 static void
657 gtk_cell_view_cell_layout_clear (GtkCellLayout *layout)
658 {
659   GtkCellView *cellview = GTK_CELL_VIEW (layout);
660
661   while (cellview->priv->cell_list)
662     {
663       GtkCellViewCellInfo *info = (GtkCellViewCellInfo *)cellview->priv->cell_list->data;
664
665       gtk_cell_view_cell_layout_clear_attributes (layout, info->cell);
666       g_object_unref (info->cell);
667       g_slice_free (GtkCellViewCellInfo, info);
668       cellview->priv->cell_list = g_list_delete_link (cellview->priv->cell_list, 
669                                                       cellview->priv->cell_list);
670     }
671 }
672
673 static void
674 gtk_cell_view_cell_layout_set_cell_data_func (GtkCellLayout         *layout,
675                                               GtkCellRenderer       *cell,
676                                               GtkCellLayoutDataFunc  func,
677                                               gpointer               func_data,
678                                               GDestroyNotify         destroy)
679 {
680   GtkCellView *cellview = GTK_CELL_VIEW (layout);
681   GtkCellViewCellInfo *info;
682
683   info = gtk_cell_view_get_cell_info (cellview, cell);
684   g_return_if_fail (info != NULL);
685
686   if (info->destroy)
687     {
688       GDestroyNotify d = info->destroy;
689
690       info->destroy = NULL;
691       d (info->func_data);
692     }
693
694   info->func = func;
695   info->func_data = func_data;
696   info->destroy = destroy;
697 }
698
699 static void
700 gtk_cell_view_cell_layout_clear_attributes (GtkCellLayout   *layout,
701                                             GtkCellRenderer *renderer)
702 {
703   GtkCellView *cellview = GTK_CELL_VIEW (layout);
704   GtkCellViewCellInfo *info;
705   GSList *list;
706
707   info = gtk_cell_view_get_cell_info (cellview, renderer);
708   if (info != NULL)
709     {
710       list = info->attributes;
711       while (list && list->next)
712         {
713           g_free (list->data);
714           list = list->next->next;
715         }
716       
717       g_slist_free (info->attributes);
718       info->attributes = NULL;
719     }
720 }
721
722 static void
723 gtk_cell_view_cell_layout_reorder (GtkCellLayout   *layout,
724                                    GtkCellRenderer *cell,
725                                    gint             position)
726 {
727   GtkCellView *cellview = GTK_CELL_VIEW (layout);
728   GtkCellViewCellInfo *info;
729   GList *link;
730
731   info = gtk_cell_view_get_cell_info (cellview, cell);
732
733   g_return_if_fail (info != NULL);
734   g_return_if_fail (position >= 0);
735
736   link = g_list_find (cellview->priv->cell_list, info);
737
738   g_return_if_fail (link != NULL);
739
740   cellview->priv->cell_list = g_list_delete_link (cellview->priv->cell_list,
741                                                   link);
742   cellview->priv->cell_list = g_list_insert (cellview->priv->cell_list,
743                                              info, position);
744
745   gtk_widget_queue_draw (GTK_WIDGET (cellview));
746 }
747
748 /**
749  * gtk_cell_view_new:
750  *
751  * Creates a new #GtkCellView widget.
752  *
753  * Return value: A newly created #GtkCellView widget.
754  *
755  * Since: 2.6
756  */
757 GtkWidget *
758 gtk_cell_view_new (void)
759 {
760   GtkCellView *cellview;
761
762   cellview = g_object_new (gtk_cell_view_get_type (), NULL);
763
764   return GTK_WIDGET (cellview);
765 }
766
767 /**
768  * gtk_cell_view_new_with_text:
769  * @text: the text to display in the cell view
770  *
771  * Creates a new #GtkCellView widget, adds a #GtkCellRendererText 
772  * to it, and makes its show @text.
773  *
774  * Return value: A newly created #GtkCellView widget.
775  *
776  * Since: 2.6
777  */
778 GtkWidget *
779 gtk_cell_view_new_with_text (const gchar *text)
780 {
781   GtkCellView *cellview;
782   GtkCellRenderer *renderer;
783   GValue value = {0, };
784
785   cellview = GTK_CELL_VIEW (gtk_cell_view_new ());
786
787   renderer = gtk_cell_renderer_text_new ();
788   gtk_cell_view_cell_layout_pack_start (GTK_CELL_LAYOUT (cellview),
789                                         renderer, TRUE);
790
791   g_value_init (&value, G_TYPE_STRING);
792   g_value_set_string (&value, text);
793   gtk_cell_view_set_value (cellview, renderer, "text", &value);
794   g_value_unset (&value);
795
796   return GTK_WIDGET (cellview);
797 }
798
799 /**
800  * gtk_cell_view_new_with_markup:
801  * @markup: the text to display in the cell view
802  *
803  * Creates a new #GtkCellView widget, adds a #GtkCellRendererText 
804  * to it, and makes it show @markup. The text can be
805  * marked up with the <link linkend="PangoMarkupFormat">Pango text 
806  * markup language</link>.
807  *
808  * Return value: A newly created #GtkCellView widget.
809  *
810  * Since: 2.6
811  */
812 GtkWidget *
813 gtk_cell_view_new_with_markup (const gchar *markup)
814 {
815   GtkCellView *cellview;
816   GtkCellRenderer *renderer;
817   GValue value = {0, };
818
819   cellview = GTK_CELL_VIEW (gtk_cell_view_new ());
820
821   renderer = gtk_cell_renderer_text_new ();
822   gtk_cell_view_cell_layout_pack_start (GTK_CELL_LAYOUT (cellview),
823                                         renderer, TRUE);
824
825   g_value_init (&value, G_TYPE_STRING);
826   g_value_set_string (&value, markup);
827   gtk_cell_view_set_value (cellview, renderer, "markup", &value);
828   g_value_unset (&value);
829
830   return GTK_WIDGET (cellview);
831 }
832
833 /**
834  * gtk_cell_view_new_with_pixbuf:
835  * @pixbuf: the image to display in the cell view
836  *
837  * Creates a new #GtkCellView widget, adds a #GtkCellRendererPixbuf 
838  * to it, and makes its show @pixbuf. 
839  *
840  * Return value: A newly created #GtkCellView widget.
841  *
842  * Since: 2.6
843  */
844 GtkWidget *
845 gtk_cell_view_new_with_pixbuf (GdkPixbuf *pixbuf)
846 {
847   GtkCellView *cellview;
848   GtkCellRenderer *renderer;
849   GValue value = {0, };
850
851   cellview = GTK_CELL_VIEW (gtk_cell_view_new ());
852
853   renderer = gtk_cell_renderer_pixbuf_new ();
854   gtk_cell_view_cell_layout_pack_start (GTK_CELL_LAYOUT (cellview),
855                                         renderer, TRUE);
856
857   g_value_init (&value, GDK_TYPE_PIXBUF);
858   g_value_set_object (&value, pixbuf);
859   gtk_cell_view_set_value (cellview, renderer, "pixbuf", &value);
860   g_value_unset (&value);
861
862   return GTK_WIDGET (cellview);
863 }
864
865 /**
866  * gtk_cell_view_set_value:
867  * @cell_view: a #GtkCellView widget
868  * @renderer: one of the renderers of @cell_view
869  * @property: the name of the property of @renderer to set
870  * @value: the new value to set the property to
871  * 
872  * Sets a property of a cell renderer of @cell_view, and
873  * makes sure the display of @cell_view is updated.
874  *
875  * Since: 2.6
876  */
877 static void
878 gtk_cell_view_set_value (GtkCellView     *cell_view,
879                          GtkCellRenderer *renderer,
880                          gchar           *property,
881                          GValue          *value)
882 {
883   g_object_set_property (G_OBJECT (renderer), property, value);
884
885   /* force resize and redraw */
886   gtk_widget_queue_resize (GTK_WIDGET (cell_view));
887   gtk_widget_queue_draw (GTK_WIDGET (cell_view));
888 }
889
890 /**
891  * gtk_cell_view_set_model:
892  * @cell_view: a #GtkCellView
893  * @model: (allow-none): a #GtkTreeModel
894  *
895  * Sets the model for @cell_view.  If @cell_view already has a model
896  * set, it will remove it before setting the new model.  If @model is
897  * %NULL, then it will unset the old model.
898  *
899  * Since: 2.6
900  */
901 void
902 gtk_cell_view_set_model (GtkCellView  *cell_view,
903                          GtkTreeModel *model)
904 {
905   g_return_if_fail (GTK_IS_CELL_VIEW (cell_view));
906   g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
907
908   if (cell_view->priv->model)
909     {
910       if (cell_view->priv->displayed_row)
911         gtk_tree_row_reference_free (cell_view->priv->displayed_row);
912       cell_view->priv->displayed_row = NULL;
913
914       g_object_unref (cell_view->priv->model);
915       cell_view->priv->model = NULL;
916     }
917
918   cell_view->priv->model = model;
919
920   if (cell_view->priv->model)
921     g_object_ref (cell_view->priv->model);
922 }
923
924 /**
925  * gtk_cell_view_get_model:
926  * @cell_view: a #GtkCellView
927  *
928  * Returns the model for @cell_view. If no model is used %NULL is
929  * returned.
930  *
931  * Returns: (transfer none): a #GtkTreeModel used or %NULL
932  *
933  * Since: 2.16
934  **/
935 GtkTreeModel *
936 gtk_cell_view_get_model (GtkCellView *cell_view)
937 {
938   g_return_val_if_fail (GTK_IS_CELL_VIEW (cell_view), NULL);
939
940   return cell_view->priv->model;
941 }
942
943 /**
944  * gtk_cell_view_set_displayed_row:
945  * @cell_view: a #GtkCellView
946  * @path: (allow-none): a #GtkTreePath or %NULL to unset.
947  *
948  * Sets the row of the model that is currently displayed
949  * by the #GtkCellView. If the path is unset, then the
950  * contents of the cellview "stick" at their last value;
951  * this is not normally a desired result, but may be
952  * a needed intermediate state if say, the model for
953  * the #GtkCellView becomes temporarily empty.
954  *
955  * Since: 2.6
956  **/
957 void
958 gtk_cell_view_set_displayed_row (GtkCellView *cell_view,
959                                  GtkTreePath *path)
960 {
961   g_return_if_fail (GTK_IS_CELL_VIEW (cell_view));
962   g_return_if_fail (GTK_IS_TREE_MODEL (cell_view->priv->model));
963
964   if (cell_view->priv->displayed_row)
965     gtk_tree_row_reference_free (cell_view->priv->displayed_row);
966
967   if (path)
968     {
969       cell_view->priv->displayed_row =
970         gtk_tree_row_reference_new (cell_view->priv->model, path);
971     }
972   else
973     cell_view->priv->displayed_row = NULL;
974
975   /* force resize and redraw */
976   gtk_widget_queue_resize (GTK_WIDGET (cell_view));
977   gtk_widget_queue_draw (GTK_WIDGET (cell_view));
978 }
979
980 /**
981  * gtk_cell_view_get_displayed_row:
982  * @cell_view: a #GtkCellView
983  *
984  * Returns a #GtkTreePath referring to the currently 
985  * displayed row. If no row is currently displayed, 
986  * %NULL is returned.
987  *
988  * Returns: the currently displayed row or %NULL
989  *
990  * Since: 2.6
991  */
992 GtkTreePath *
993 gtk_cell_view_get_displayed_row (GtkCellView *cell_view)
994 {
995   g_return_val_if_fail (GTK_IS_CELL_VIEW (cell_view), NULL);
996
997   if (!cell_view->priv->displayed_row)
998     return NULL;
999
1000   return gtk_tree_row_reference_get_path (cell_view->priv->displayed_row);
1001 }
1002
1003 /**
1004  * gtk_cell_view_get_size_of_row:
1005  * @cell_view: a #GtkCellView
1006  * @path: a #GtkTreePath 
1007  * @requisition: return location for the size 
1008  *
1009  * Sets @requisition to the size needed by @cell_view to display 
1010  * the model row pointed to by @path.
1011  * 
1012  * Return value: %TRUE
1013  *
1014  * Since: 2.6
1015  * 
1016  * Deprecated: 3.0: Use gtk_cell_view_get_desired_width_of_row() and
1017  * gtk_cell_view_get_desired_height_for_width_of_row() instead.
1018  */
1019 gboolean
1020 gtk_cell_view_get_size_of_row (GtkCellView    *cell_view,
1021                                GtkTreePath    *path,
1022                                GtkRequisition *requisition)
1023 {
1024   GtkRequisition req;
1025
1026   g_return_val_if_fail (GTK_IS_CELL_VIEW (cell_view), FALSE);
1027   g_return_val_if_fail (path != NULL, FALSE);
1028
1029   /* Return the minimum height for the minimum width */
1030   gtk_cell_view_get_desired_width_of_row (cell_view, path, &req.width, NULL);
1031   gtk_cell_view_get_desired_height_for_width_of_row (cell_view, path, req.width, &req.height, NULL);
1032
1033   if (requisition)
1034     *requisition = req;
1035
1036   return TRUE;
1037 }
1038
1039
1040 /**
1041  * gtk_cell_view_get_desired_width_of_row:
1042  * @cell_view: a #GtkCellView
1043  * @path: a #GtkTreePath 
1044  * @minimum_size: location to store the minimum size 
1045  * @natural_size: location to store the natural size 
1046  *
1047  * Sets @minimum_size and @natural_size to the width desired by @cell_view 
1048  * to display the model row pointed to by @path.
1049  * 
1050  * Since: 3.0
1051  */
1052 void
1053 gtk_cell_view_get_desired_width_of_row (GtkCellView     *cell_view,
1054                                         GtkTreePath     *path,
1055                                         gint            *minimum_size,
1056                                         gint            *natural_size)
1057 {
1058   GtkTreeRowReference *tmp;
1059
1060   g_return_if_fail (GTK_IS_CELL_VIEW (cell_view));
1061   g_return_if_fail (path != NULL);
1062   g_return_if_fail (minimum_size != NULL || natural_size != NULL);
1063
1064   tmp = cell_view->priv->displayed_row;
1065   cell_view->priv->displayed_row =
1066     gtk_tree_row_reference_new (cell_view->priv->model, path);
1067
1068   gtk_cell_view_get_width (GTK_SIZE_REQUEST (cell_view), minimum_size, natural_size);
1069
1070   gtk_tree_row_reference_free (cell_view->priv->displayed_row);
1071   cell_view->priv->displayed_row = tmp;
1072
1073   /* Restore active size (this will restore the cellrenderer info->width/requested_width's) */
1074   gtk_cell_view_get_width (GTK_SIZE_REQUEST (cell_view), NULL, NULL);
1075 }
1076
1077
1078 /**
1079  * gtk_cell_view_get_desired_height_for_width_of_row:
1080  * @cell_view: a #GtkCellView
1081  * @path: a #GtkTreePath 
1082  * @avail_size: available width
1083  * @minimum_size: location to store the minimum height 
1084  * @natural_size: location to store the natural height
1085  *
1086  * Sets @minimum_size and @natural_size to the height desired by @cell_view 
1087  * if it were allocated a width of @avail_size to display the model row 
1088  * pointed to by @path.
1089  * 
1090  * Since: 3.0
1091  */
1092 void
1093 gtk_cell_view_get_desired_height_for_width_of_row (GtkCellView     *cell_view,
1094                                                    GtkTreePath     *path,
1095                                                    gint             avail_size,
1096                                                    gint            *minimum_size,
1097                                                    gint            *natural_size)
1098 {
1099   GtkTreeRowReference *tmp;
1100
1101   g_return_if_fail (GTK_IS_CELL_VIEW (cell_view));
1102   g_return_if_fail (path != NULL);
1103   g_return_if_fail (minimum_size != NULL || natural_size != NULL);
1104
1105   tmp = cell_view->priv->displayed_row;
1106   cell_view->priv->displayed_row =
1107     gtk_tree_row_reference_new (cell_view->priv->model, path);
1108
1109   /* Then get the collective height_for_width based on the cached values */
1110   gtk_cell_view_get_height_for_width (GTK_SIZE_REQUEST (cell_view), avail_size, minimum_size, natural_size);
1111
1112   gtk_tree_row_reference_free (cell_view->priv->displayed_row);
1113   cell_view->priv->displayed_row = tmp;
1114
1115   /* Restore active size (this will restore the cellrenderer info->width/requested_width's) */
1116   gtk_cell_view_get_width (GTK_SIZE_REQUEST (cell_view), NULL, NULL);
1117 }
1118
1119 /**
1120  * gtk_cell_view_set_background_color:
1121  * @cell_view: a #GtkCellView
1122  * @color: the new background color
1123  *
1124  * Sets the background color of @view.
1125  *
1126  * Since: 2.6
1127  */
1128 void
1129 gtk_cell_view_set_background_color (GtkCellView    *cell_view,
1130                                     const GdkColor *color)
1131 {
1132   g_return_if_fail (GTK_IS_CELL_VIEW (cell_view));
1133
1134   if (color)
1135     {
1136       if (!cell_view->priv->background_set)
1137         {
1138           cell_view->priv->background_set = TRUE;
1139           g_object_notify (G_OBJECT (cell_view), "background-set");
1140         }
1141
1142       cell_view->priv->background = *color;
1143     }
1144   else
1145     {
1146       if (cell_view->priv->background_set)
1147         {
1148           cell_view->priv->background_set = FALSE;
1149           g_object_notify (G_OBJECT (cell_view), "background-set");
1150         }
1151     }
1152
1153   gtk_widget_queue_draw (GTK_WIDGET (cell_view));
1154 }
1155
1156 static GList *
1157 gtk_cell_view_cell_layout_get_cells (GtkCellLayout *layout)
1158 {
1159   GtkCellView *cell_view = GTK_CELL_VIEW (layout);
1160   GList *retval = NULL, *list;
1161
1162   g_return_val_if_fail (cell_view != NULL, NULL);
1163
1164   gtk_cell_view_set_cell_data (cell_view);
1165
1166   for (list = cell_view->priv->cell_list; list; list = list->next)
1167     {
1168       GtkCellViewCellInfo *info = (GtkCellViewCellInfo *)list->data;
1169
1170       retval = g_list_prepend (retval, info->cell);
1171     }
1172
1173   return g_list_reverse (retval);
1174 }
1175
1176 static gboolean
1177 gtk_cell_view_buildable_custom_tag_start (GtkBuildable  *buildable,
1178                                           GtkBuilder    *builder,
1179                                           GObject       *child,
1180                                           const gchar   *tagname,
1181                                           GMarkupParser *parser,
1182                                           gpointer      *data)
1183 {
1184   if (parent_buildable_iface->custom_tag_start &&
1185       parent_buildable_iface->custom_tag_start (buildable, builder, child,
1186                                                 tagname, parser, data))
1187     return TRUE;
1188
1189   return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
1190                                                       tagname, parser, data);
1191 }
1192
1193 static void
1194 gtk_cell_view_buildable_custom_tag_end (GtkBuildable *buildable,
1195                                         GtkBuilder   *builder,
1196                                         GObject      *child,
1197                                         const gchar  *tagname,
1198                                         gpointer     *data)
1199 {
1200   if (strcmp (tagname, "attributes") == 0)
1201     _gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
1202                                                data);
1203   else if (parent_buildable_iface->custom_tag_end)
1204     parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,
1205                                             data);
1206 }
1207
1208 static void
1209 gtk_cell_view_size_request_init (GtkSizeRequestIface *iface)
1210 {
1211   iface->get_width            = gtk_cell_view_get_width;
1212   iface->get_height           = gtk_cell_view_get_height;
1213   iface->get_width_for_height = gtk_cell_view_get_width_for_height;
1214   iface->get_height_for_width = gtk_cell_view_get_height_for_width;
1215 }
1216
1217 static void
1218 gtk_cell_view_get_width  (GtkSizeRequest      *widget,
1219                           gint                *minimum_size,
1220                           gint                *natural_size)
1221 {
1222   GList *list;
1223   gint cell_min, cell_nat;
1224   gboolean first_cell = TRUE;
1225   GtkCellView *cellview = GTK_CELL_VIEW (widget);
1226   gint minimum, natural;
1227
1228   minimum = natural = 0;
1229
1230   if (cellview->priv->displayed_row)
1231     gtk_cell_view_set_cell_data (cellview);
1232
1233   for (list = cellview->priv->cell_list; list; list = list->next)
1234     {
1235       GtkCellViewCellInfo *info = (GtkCellViewCellInfo *)list->data;
1236
1237       if (gtk_cell_renderer_get_visible (info->cell))
1238         {
1239           
1240           if (!first_cell)
1241             {
1242               minimum += cellview->priv->spacing;
1243               natural += cellview->priv->spacing;
1244             }
1245
1246           gtk_cell_size_request_get_width (GTK_CELL_SIZE_REQUEST (info->cell),
1247                                            GTK_WIDGET (cellview), &cell_min, &cell_nat);
1248           
1249           info->requested_width = cell_min;
1250           info->natural_width   = cell_nat;
1251           
1252           minimum += info->requested_width;
1253           natural += info->natural_width;
1254
1255           first_cell = FALSE;
1256         }
1257     }
1258
1259   if (minimum_size)
1260     *minimum_size = minimum;
1261
1262   if (natural_size)
1263     *natural_size = natural;
1264 }
1265
1266 static void       
1267 gtk_cell_view_get_height (GtkSizeRequest      *widget,
1268                           gint                *minimum_size,
1269                           gint                *natural_size)
1270 {
1271   gint minimum_width;
1272
1273   /* CellViews only need to respond to height-for-width mode (cellview is pretty much
1274    * an implementation detail of GtkComboBox) */
1275   gtk_cell_view_get_width (widget, &minimum_width, NULL);
1276   gtk_cell_view_get_height_for_width (widget, minimum_width, minimum_size, natural_size);
1277 }
1278
1279 static void       
1280 gtk_cell_view_get_width_for_height (GtkSizeRequest      *widget,
1281                                     gint                 for_size,
1282                                     gint                *minimum_size,
1283                                     gint                *natural_size)
1284 {
1285   /* CellViews only need to respond to height-for-width mode (cellview is pretty much
1286    * an implementation detail of GtkComboBox) */
1287   gtk_cell_view_get_width (widget, minimum_size, natural_size);
1288 }
1289
1290 static void       
1291 gtk_cell_view_get_height_for_width (GtkSizeRequest      *widget,
1292                                     gint                 for_size,
1293                                     gint                *minimum_size,
1294                                     gint                *natural_size)
1295 {
1296   GtkCellView      *cellview = GTK_CELL_VIEW (widget);
1297   GList            *list;
1298   GtkRequestedSize *sizes;
1299   GArray           *array;
1300   gint              minimum, natural, avail_size;
1301   gboolean          first_cell = TRUE;
1302   gint              n_expand_cells = 0;
1303   gint              extra_per_cell, extra_extra, i;
1304
1305   minimum = natural = 0;
1306   avail_size = for_size;
1307
1308   array = g_array_new (0, TRUE, sizeof (GtkRequestedSize));
1309
1310   if (cellview->priv->displayed_row)
1311     gtk_cell_view_set_cell_data (cellview);
1312
1313   /* First allocate the right width to all cells */
1314   for (list = cellview->priv->cell_list; list; list = list->next)
1315     {
1316       GtkCellViewCellInfo *info = (GtkCellViewCellInfo *)list->data;
1317
1318       if (gtk_cell_renderer_get_visible (info->cell))
1319         {
1320           GtkRequestedSize requested;
1321
1322           gtk_cell_size_request_get_width (GTK_CELL_SIZE_REQUEST (info->cell),
1323                                            GTK_WIDGET (cellview), 
1324                                            &requested.minimum_size, 
1325                                            &requested.natural_size);
1326
1327           requested.data = info;
1328           g_array_append_val (array, requested);
1329
1330           avail_size -= requested.minimum_size;
1331
1332           if (!first_cell)
1333             avail_size -= cellview->priv->spacing;
1334
1335           first_cell = FALSE;
1336
1337           if (info->expand)
1338             n_expand_cells++;
1339         }
1340     }
1341
1342   sizes      = (GtkRequestedSize *)array->data;
1343   avail_size = gtk_distribute_natural_allocation (MAX (0, avail_size), array->len, sizes);
1344
1345   /* Deal with any expand space... */
1346   if (n_expand_cells > 0)
1347     {
1348       extra_per_cell = avail_size / n_expand_cells;
1349       extra_extra    = avail_size % n_expand_cells;
1350     }
1351   else
1352     /* Everything just left-aligned if no cells expand */
1353     extra_per_cell = extra_extra = 0;
1354
1355   /* Now get the height for the real width of each cell */
1356   for (i = 0, list = cellview->priv->cell_list; list; list = list->next)
1357     {
1358       GtkCellViewCellInfo *info = (GtkCellViewCellInfo *)list->data;
1359       gint cell_minimum, cell_natural;
1360
1361       if (gtk_cell_renderer_get_visible (info->cell))
1362         {
1363           gint cell_width = sizes[i].minimum_size;
1364
1365           g_assert (sizes[i].data == info);
1366
1367           if (info->expand)
1368             {
1369               cell_width += extra_per_cell;
1370               if (extra_extra)
1371                 {
1372                   cell_width++;
1373                   extra_extra--;
1374                 }
1375             }
1376
1377           /* Get the height for the real width of this cell */
1378           gtk_cell_size_request_get_height_for_width (GTK_CELL_SIZE_REQUEST (info->cell),
1379                                                       GTK_WIDGET (widget),
1380                                                       cell_width, &cell_minimum, &cell_natural);
1381
1382           minimum = MAX (minimum, cell_minimum);
1383           natural = MAX (natural, cell_natural);
1384
1385           /* increment sizes[] index for visible cells */
1386           i++;
1387         }
1388     }
1389
1390   g_array_free (array, TRUE);
1391
1392   if (minimum_size)
1393     *minimum_size = minimum;
1394   if (natural_size)
1395     *natural_size = natural;
1396 }