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