3 * Copyright (C) 2010 Openismus GmbH
6 * Tristan Van Berkom <tristanvb@openismus.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
26 #include "gtkorientable.h"
27 #include "gtkcelllayout.h"
28 #include "gtkcellareabox.h"
29 #include "gtkcellareaboxiter.h"
30 #include "gtkprivate.h"
34 static void gtk_cell_area_box_finalize (GObject *object);
35 static void gtk_cell_area_box_dispose (GObject *object);
36 static void gtk_cell_area_box_set_property (GObject *object,
40 static void gtk_cell_area_box_get_property (GObject *object,
45 /* GtkCellAreaClass */
46 static void gtk_cell_area_box_add (GtkCellArea *area,
47 GtkCellRenderer *renderer);
48 static void gtk_cell_area_box_remove (GtkCellArea *area,
49 GtkCellRenderer *renderer);
50 static void gtk_cell_area_box_forall (GtkCellArea *area,
51 GtkCellCallback callback,
52 gpointer callback_data);
53 static gint gtk_cell_area_box_event (GtkCellArea *area,
54 GtkCellAreaIter *iter,
57 const GdkRectangle *cell_area);
58 static void gtk_cell_area_box_render (GtkCellArea *area,
59 GtkCellAreaIter *iter,
62 const GdkRectangle *cell_area);
64 static GtkCellAreaIter *gtk_cell_area_box_create_iter (GtkCellArea *area);
65 static GtkSizeRequestMode gtk_cell_area_box_get_request_mode (GtkCellArea *area);
66 static void gtk_cell_area_box_get_preferred_width (GtkCellArea *area,
67 GtkCellAreaIter *iter,
71 static void gtk_cell_area_box_get_preferred_height (GtkCellArea *area,
72 GtkCellAreaIter *iter,
75 gint *natural_height);
76 static void gtk_cell_area_box_get_preferred_height_for_width (GtkCellArea *area,
77 GtkCellAreaIter *iter,
81 gint *natural_height);
82 static void gtk_cell_area_box_get_preferred_width_for_height (GtkCellArea *area,
83 GtkCellAreaIter *iter,
89 /* GtkCellLayoutIface */
90 static void gtk_cell_area_box_cell_layout_init (GtkCellLayoutIface *iface);
91 static void gtk_cell_area_box_layout_pack_start (GtkCellLayout *cell_layout,
92 GtkCellRenderer *renderer,
94 static void gtk_cell_area_box_layout_pack_end (GtkCellLayout *cell_layout,
95 GtkCellRenderer *renderer,
97 static void gtk_cell_area_box_layout_reorder (GtkCellLayout *cell_layout,
98 GtkCellRenderer *renderer,
102 /* CellInfo/CellGroup metadata handling and convenience functions */
104 GtkCellRenderer *renderer;
106 guint expand : 1; /* Whether the cell expands */
107 guint pack : 1; /* Whether the cell is packed from the start or end */
108 guint align : 1; /* Whether to align this cell's position with adjacent rows */
118 static CellInfo *cell_info_new (GtkCellRenderer *renderer,
122 static void cell_info_free (CellInfo *info);
123 static gint cell_info_find (CellInfo *info,
124 GtkCellRenderer *renderer);
126 static CellGroup *cell_group_new (guint id);
127 static void cell_group_free (CellGroup *group);
129 static GList *list_consecutive_cells (GtkCellAreaBox *box);
130 static GList *construct_cell_groups (GtkCellAreaBox *box);
131 static gint count_expand_groups (GtkCellAreaBox *box);
132 static gint count_expand_cells (CellGroup *group);
133 static void iter_weak_notify (GtkCellAreaBox *box,
134 GtkCellAreaBoxIter *dead_iter);
135 static void flush_iters (GtkCellAreaBox *box);
136 static void init_iter_groups (GtkCellAreaBox *box);
137 static void init_iter_group (GtkCellAreaBox *box,
138 GtkCellAreaBoxIter *iter);
141 struct _GtkCellAreaBoxPrivate
143 GtkOrientation orientation;
159 G_DEFINE_TYPE_WITH_CODE (GtkCellAreaBox, gtk_cell_area_box, GTK_TYPE_CELL_AREA,
160 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
161 gtk_cell_area_box_cell_layout_init)
162 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL));
164 #define OPPOSITE_ORIENTATION(orientation) \
165 ((orientation) == GTK_ORIENTATION_HORIZONTAL ? \
166 GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL)
169 gtk_cell_area_box_init (GtkCellAreaBox *box)
171 GtkCellAreaBoxPrivate *priv;
173 box->priv = G_TYPE_INSTANCE_GET_PRIVATE (box,
174 GTK_TYPE_CELL_AREA_BOX,
175 GtkCellAreaBoxPrivate);
178 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
186 gtk_cell_area_box_class_init (GtkCellAreaBoxClass *class)
188 GObjectClass *object_class = G_OBJECT_CLASS (class);
189 GtkCellAreaClass *area_class = GTK_CELL_AREA_CLASS (class);
192 object_class->finalize = gtk_cell_area_box_finalize;
193 object_class->dispose = gtk_cell_area_box_dispose;
194 object_class->set_property = gtk_cell_area_box_set_property;
195 object_class->get_property = gtk_cell_area_box_get_property;
197 /* GtkCellAreaClass */
198 area_class->add = gtk_cell_area_box_add;
199 area_class->remove = gtk_cell_area_box_remove;
200 area_class->forall = gtk_cell_area_box_forall;
201 area_class->event = gtk_cell_area_box_event;
202 area_class->render = gtk_cell_area_box_render;
204 area_class->create_iter = gtk_cell_area_box_create_iter;
205 area_class->get_request_mode = gtk_cell_area_box_get_request_mode;
206 area_class->get_preferred_width = gtk_cell_area_box_get_preferred_width;
207 area_class->get_preferred_height = gtk_cell_area_box_get_preferred_height;
208 area_class->get_preferred_height_for_width = gtk_cell_area_box_get_preferred_height_for_width;
209 area_class->get_preferred_width_for_height = gtk_cell_area_box_get_preferred_width_for_height;
211 g_object_class_override_property (object_class, PROP_ORIENTATION, "orientation");
213 g_object_class_install_property (object_class,
215 g_param_spec_int ("spacing",
217 P_("Space which is inserted between cells"),
221 GTK_PARAM_READWRITE));
223 g_type_class_add_private (object_class, sizeof (GtkCellAreaBoxPrivate));
227 /*************************************************************
228 * CellInfo/CellGroup basics and convenience functions *
229 *************************************************************/
231 cell_info_new (GtkCellRenderer *renderer,
236 CellInfo *info = g_slice_new (CellInfo);
238 info->renderer = g_object_ref_sink (renderer);
240 info->expand = expand;
247 cell_info_free (CellInfo *info)
249 g_object_unref (info->renderer);
251 g_slice_free (CellInfo, info);
255 cell_info_find (CellInfo *info,
256 GtkCellRenderer *renderer)
258 return (info->renderer == renderer) ? 0 : -1;
262 cell_group_new (guint id)
264 CellGroup *group = g_slice_new0 (CellGroup);
272 cell_group_free (CellGroup *group)
274 g_list_free (group->cells);
275 g_slice_free (CellGroup, group);
279 list_consecutive_cells (GtkCellAreaBox *box)
281 GtkCellAreaBoxPrivate *priv = box->priv;
282 GList *l, *consecutive_cells = NULL, *pack_end_cells = NULL;
285 /* List cells in consecutive order taking their
286 * PACK_START/PACK_END options into account
288 for (l = priv->cells; l; l = l->next)
292 if (info->pack == GTK_PACK_START)
293 consecutive_cells = g_list_prepend (consecutive_cells, info);
296 for (l = priv->cells; l; l = l->next)
300 if (info->pack == GTK_PACK_END)
301 pack_end_cells = g_list_prepend (pack_end_cells, info);
304 consecutive_cells = g_list_reverse (consecutive_cells);
305 consecutive_cells = g_list_concat (consecutive_cells, pack_end_cells);
307 return consecutive_cells;
311 construct_cell_groups (GtkCellAreaBox *box)
313 GtkCellAreaBoxPrivate *priv = box->priv;
316 GList *groups = NULL;
322 cells = list_consecutive_cells (box);
323 group = cell_group_new (id++);
324 groups = g_list_prepend (groups, group);
326 for (l = cells; l; l = l->next)
328 CellInfo *info = l->data;
330 /* A new group starts with any aligned cell, the first group is implied */
331 if (info->align && l != cells)
333 group = cell_group_new (id++);
334 groups = g_list_prepend (groups, group);
337 group->cells = g_list_prepend (group->cells, info);
339 /* A group expands if it contains any expand cells */
341 group->expand = TRUE;
346 for (l = cells; l; l = l->next)
349 group->cells = g_list_reverse (group->cells);
352 return g_list_reverse (groups);
356 count_expand_groups (GtkCellAreaBox *box)
358 GtkCellAreaBoxPrivate *priv = box->priv;
360 gint expand_groups = 0;
362 for (l = priv->groups; l; l = l->next)
364 CellGroup *group = l->data;
370 return expand_groups;
374 count_expand_cells (CellGroup *group)
377 gint expand_cells = 0;
382 for (l = group->cells; l; l = l->next)
384 CellInfo *info = l->data;
394 iter_weak_notify (GtkCellAreaBox *box,
395 GtkCellAreaBoxIter *dead_iter)
397 GtkCellAreaBoxPrivate *priv = box->priv;
399 priv->iters = g_slist_remove (priv->iters, dead_iter);
403 init_iter_group (GtkCellAreaBox *box,
404 GtkCellAreaBoxIter *iter)
406 GtkCellAreaBoxPrivate *priv = box->priv;
407 gint n_groups, *expand_groups, i;
410 n_groups = g_list_length (priv->groups);
411 expand_groups = g_new (gboolean, n_groups);
413 for (i = 0, l = priv->groups; l; l = l->next, i++)
415 CellGroup *group = l->data;
417 expand_groups[i] = group->expand;
420 gtk_cell_area_box_init_groups (iter, n_groups, expand_groups);
421 g_free (expand_groups);
425 init_iter_groups (GtkCellAreaBox *box)
427 GtkCellAreaBoxPrivate *priv = box->priv;
430 /* When the box's groups are reconstructed, iters need to
433 for (l = priv->iters; l; l = l->next)
435 GtkCellAreaBoxIter *iter = l->data;
437 init_iter_group (box, iter);
442 flush_iters (GtkCellAreaBox *box)
444 GtkCellAreaBoxPrivate *priv = box->priv;
447 /* When the box layout changes, iters need to
448 * be flushed and sizes for the box get requested again
450 for (l = priv->iters; l; l = l->next)
452 GtkCellAreaIter *iter = l->data;
454 gtk_cell_area_iter_flush (iter);
458 /*************************************************************
460 *************************************************************/
462 gtk_cell_area_box_finalize (GObject *object)
464 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (object);
465 GtkCellAreaBoxPrivate *priv = box->priv;
468 for (l = priv->iters; l; l = l->next)
469 g_object_weak_unref (G_OBJECT (l->data), (GWeakNotify)iter_weak_notify, box);
471 g_slist_free (priv->iters);
473 G_OBJECT_CLASS (gtk_cell_area_box_parent_class)->finalize (object);
477 gtk_cell_area_box_dispose (GObject *object)
479 G_OBJECT_CLASS (gtk_cell_area_box_parent_class)->dispose (object);
483 gtk_cell_area_box_set_property (GObject *object,
488 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (object);
492 case PROP_ORIENTATION:
493 box->priv->orientation = g_value_get_enum (value);
495 /* Notify that size needs to be requested again */
499 gtk_cell_area_box_set_spacing (box, g_value_get_int (value));
502 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
508 gtk_cell_area_box_get_property (GObject *object,
513 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (object);
517 case PROP_ORIENTATION:
518 g_value_set_enum (value, box->priv->orientation);
521 g_value_set_int (value, gtk_cell_area_box_get_spacing (box));
524 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
529 /*************************************************************
531 *************************************************************/
533 gtk_cell_area_box_add (GtkCellArea *area,
534 GtkCellRenderer *renderer)
536 gtk_cell_area_box_pack_start (GTK_CELL_AREA_BOX (area),
537 renderer, FALSE, TRUE);
541 gtk_cell_area_box_remove (GtkCellArea *area,
542 GtkCellRenderer *renderer)
544 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
545 GtkCellAreaBoxPrivate *priv = box->priv;
548 node = g_list_find_custom (priv->cells, renderer,
549 (GCompareFunc)cell_info_find);
553 CellInfo *info = node->data;
555 cell_info_free (info);
557 priv->cells = g_list_delete_link (priv->cells, node);
559 /* Reconstruct cell groups */
560 g_list_foreach (priv->groups, (GFunc)cell_group_free, NULL);
561 g_list_free (priv->groups);
562 priv->groups = construct_cell_groups (box);
564 /* Reinitialize groups on iters */
565 init_iter_groups (box);
568 g_warning ("Trying to remove a cell renderer that is not present GtkCellAreaBox");
572 gtk_cell_area_box_forall (GtkCellArea *area,
573 GtkCellCallback callback,
574 gpointer callback_data)
576 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
577 GtkCellAreaBoxPrivate *priv = box->priv;
580 for (list = priv->cells; list; list = list->next)
582 CellInfo *info = list->data;
584 callback (info->renderer, callback_data);
589 gtk_cell_area_box_event (GtkCellArea *area,
590 GtkCellAreaIter *iter,
593 const GdkRectangle *cell_area)
601 gtk_cell_area_box_render (GtkCellArea *area,
602 GtkCellAreaIter *iter,
605 const GdkRectangle *cell_area)
610 static GtkCellAreaIter *
611 gtk_cell_area_box_create_iter (GtkCellArea *area)
613 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
614 GtkCellAreaBoxPrivate *priv = box->priv;
615 GtkCellAreaIter *iter =
616 (GtkCellAreaIter *)g_object_new (GTK_TYPE_CELL_AREA_BOX_ITER, NULL);
618 priv->iters = g_slist_prepend (priv->iters, iter);
620 g_object_weak_ref (G_OBJECT (iter), (GWeakNotify)iter_weak_notify, box);
622 /* Tell the new group about our cell layout */
623 init_iter_group (box, GTK_CELL_AREA_BOX_ITER (iter));
628 static GtkSizeRequestMode
629 gtk_cell_area_box_get_request_mode (GtkCellArea *area)
631 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
632 GtkCellAreaBoxPrivate *priv = box->priv;
634 return (priv->orientation) == GTK_ORIENTATION_HORIZONTAL ?
635 GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH :
636 GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT;
640 get_renderer_size (GtkCellRenderer *renderer,
641 GtkOrientation orientation,
647 if (orientation == GTK_ORIENTATION_HORIZONTAL)
650 gtk_cell_renderer_get_preferred_width (renderer, widget, minimum_size, natural_size);
652 gtk_cell_renderer_get_preferred_width_for_height (renderer, widget, for_size,
653 minimum_size, natural_size);
655 else /* GTK_ORIENTATION_VERTICAL */
658 gtk_cell_renderer_get_preferred_height (renderer, widget, minimum_size, natural_size);
660 gtk_cell_renderer_get_preferred_height_for_width (renderer, widget, for_size,
661 minimum_size, natural_size);
666 compute_size (GtkCellAreaBox *box,
667 GtkOrientation orientation,
668 GtkCellAreaBoxIter *iter,
674 GtkCellAreaBoxPrivate *priv = box->priv;
677 GList *cell_list, *group_list;
681 for (group_list = priv->groups; group_list; group_list = group_list->next)
683 gint group_min_size = 0;
684 gint group_nat_size = 0;
686 group = group_list->data;
688 for (cell_list = group->cells; cell_list; cell_list = cell_list->next)
690 gint renderer_min_size, renderer_nat_size;
692 info = cell_list->data;
694 get_renderer_size (info->renderer, orientation, widget, for_size,
695 &renderer_min_size, &renderer_nat_size);
697 if (orientation == priv->orientation)
701 min_size += priv->spacing;
702 nat_size += priv->spacing;
705 if (group_min_size > 0)
707 group_min_size += priv->spacing;
708 group_nat_size += priv->spacing;
711 min_size += renderer_min_size;
712 nat_size += renderer_nat_size;
713 group_min_size += renderer_min_size;
714 group_nat_size += renderer_nat_size;
718 min_size = MAX (min_size, renderer_min_size);
719 nat_size = MAX (nat_size, renderer_nat_size);
720 group_min_size = MAX (group_min_size, renderer_min_size);
721 group_nat_size = MAX (group_nat_size, renderer_nat_size);
725 if (orientation == GTK_ORIENTATION_HORIZONTAL)
728 gtk_cell_area_box_iter_push_group_width (iter, group->id, group_min_size, group_nat_size);
730 gtk_cell_area_box_iter_push_group_width_for_height (iter, group->id, for_size,
731 group_min_size, group_nat_size);
736 gtk_cell_area_box_iter_push_group_height (iter, group->id, group_min_size, group_nat_size);
738 gtk_cell_area_box_iter_push_group_height_for_width (iter, group->id, for_size,
739 group_min_size, group_nat_size);
743 *minimum_size = min_size;
744 *natural_size = nat_size;
748 get_group_sizes (CellGroup *group,
749 GtkOrientation orientation,
753 GtkRequestedSize *sizes;
757 *n_sizes = g_list_length (group->cells);
758 sizes = g_new (GtkRequestedSize, *n_sizes);
760 for (l = group->cells, i = 0; l; l = l->next, i++)
762 CellInfo *info = l->data;
764 sizes[i].data = info;
766 get_renderer_size (info->renderer,
767 orientation, widget, -1,
768 &sizes[i].minimum_size,
769 &sizes[i].natural_size);
776 compute_group_size_for_opposing_orientation (GtkCellAreaBox *box,
783 GtkCellAreaBoxPrivate *priv = box->priv;
785 /* Exception for single cell groups */
786 if (!group->cells->next)
788 CellInfo *info = group->cells->data;
790 get_renderer_size (info->renderer,
791 OPPOSITE_ORIENTATION (priv->orientation),
792 widget, for_size, minimum_size, natural_size);
796 GtkRequestedSize *orientation_sizes;
799 gint n_expand_cells = count_expand_cells (group);
800 gint avail_size = for_size;
801 gint extra_size, extra_extra;
802 gint min_size = 0, nat_size = 0;
804 orientation_sizes = get_group_sizes (group, priv->orientation, widget, &n_sizes);
806 /* First naturally allocate the cells in the group into the for_size */
807 avail_size -= (n_sizes - 1) * priv->spacing;
808 for (i = 0; i < n_sizes; i++)
809 avail_size -= orientation_sizes[i].minimum_size;
811 avail_size = gtk_distribute_natural_allocation (avail_size, n_sizes, orientation_sizes);
813 /* Calculate/distribute expand for cells */
814 if (n_expand_cells > 0)
816 extra_size = avail_size / n_expand_cells;
817 extra_extra = avail_size % n_expand_cells;
820 extra_size = extra_extra = 0;
822 for (i = 0; i < n_sizes; i++)
824 gint cell_min, cell_nat;
826 info = orientation_sizes[i].data;
830 orientation_sizes[i].minimum_size += extra_size;
833 orientation_sizes[i].minimum_size++;
838 get_renderer_size (info->renderer,
839 OPPOSITE_ORIENTATION (priv->orientation),
841 orientation_sizes[i].minimum_size,
842 &cell_min, &cell_nat);
844 min_size = MAX (min_size, cell_min);
845 nat_size = MAX (nat_size, cell_nat);
848 *minimum_size = min_size;
849 *natural_size = nat_size;
851 g_free (orientation_sizes);
856 compute_size_for_opposing_orientation (GtkCellAreaBox *box,
857 GtkCellAreaBoxIter *iter,
863 GtkCellAreaBoxPrivate *priv = box->priv;
866 GtkRequestedSize *orientation_sizes;
867 gint n_groups, n_expand_groups, i;
868 gint avail_size = for_size;
869 gint extra_size, extra_extra;
870 gint min_size = 0, nat_size = 0;
872 n_expand_groups = count_expand_groups (box);
874 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
875 orientation_sizes = gtk_cell_area_box_iter_get_widths (iter, &n_groups);
877 orientation_sizes = gtk_cell_area_box_iter_get_heights (iter, &n_groups);
879 /* First start by naturally allocating space among groups of cells */
880 avail_size -= (n_groups - 1) * priv->spacing;
881 for (i = 0; i < n_groups; i++)
882 avail_size -= orientation_sizes[i].minimum_size;
884 avail_size = gtk_distribute_natural_allocation (avail_size, n_groups, orientation_sizes);
886 /* Calculate/distribute expand for groups */
887 if (n_expand_groups > 0)
889 extra_size = avail_size / n_expand_groups;
890 extra_extra = avail_size % n_expand_groups;
893 extra_size = extra_extra = 0;
895 /* Now we need to naturally allocate sizes for cells in each group
896 * and push the height-for-width for each group accordingly while accumulating
897 * the overall height-for-width for this row.
899 for (group_list = priv->groups; group_list; group_list = group_list->next)
901 gint group_min, group_nat;
903 group = group_list->data;
907 orientation_sizes[group->id].minimum_size += extra_size;
910 orientation_sizes[group->id].minimum_size++;
915 /* Now we have the allocation for the group, request it's height-for-width */
916 compute_group_size_for_opposing_orientation (box, group, widget,
917 orientation_sizes[group->id].minimum_size,
918 &group_min, &group_nat);
920 min_size = MAX (min_size, group_min);
921 nat_size = MAX (nat_size, group_nat);
923 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
925 gtk_cell_area_box_iter_push_group_height_for_width (iter, group->id, for_size,
926 group_min, group_nat);
930 gtk_cell_area_box_iter_push_group_width_for_height (iter, group->id, for_size,
931 group_min, group_nat);
935 *minimum_size = min_size;
936 *natural_size = nat_size;
938 g_free (orientation_sizes);
944 gtk_cell_area_box_get_preferred_width (GtkCellArea *area,
945 GtkCellAreaIter *iter,
950 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
951 GtkCellAreaBoxIter *box_iter;
952 gint min_width, nat_width;
954 g_return_if_fail (GTK_IS_CELL_AREA_BOX_ITER (iter));
956 box_iter = GTK_CELL_AREA_BOX_ITER (iter);
958 /* Compute the size of all renderers for current row data,
959 * bumping cell alignments in the iter along the way */
960 compute_size (box, GTK_ORIENTATION_HORIZONTAL,
961 box_iter, widget, -1, &min_width, &nat_width);
964 *minimum_width = min_width;
967 *natural_width = nat_width;
971 gtk_cell_area_box_get_preferred_height (GtkCellArea *area,
972 GtkCellAreaIter *iter,
974 gint *minimum_height,
975 gint *natural_height)
977 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
978 GtkCellAreaBoxIter *box_iter;
979 gint min_height, nat_height;
981 g_return_if_fail (GTK_IS_CELL_AREA_BOX_ITER (iter));
983 box_iter = GTK_CELL_AREA_BOX_ITER (iter);
985 /* Compute the size of all renderers for current row data,
986 * bumping cell alignments in the iter along the way */
987 compute_size (box, GTK_ORIENTATION_VERTICAL,
988 box_iter, widget, -1, &min_height, &nat_height);
991 *minimum_height = min_height;
994 *natural_height = nat_height;
998 gtk_cell_area_box_get_preferred_height_for_width (GtkCellArea *area,
999 GtkCellAreaIter *iter,
1002 gint *minimum_height,
1003 gint *natural_height)
1005 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1006 GtkCellAreaBoxIter *box_iter;
1007 GtkCellAreaBoxPrivate *priv;
1008 gint min_height, nat_height;
1010 g_return_if_fail (GTK_IS_CELL_AREA_BOX_ITER (iter));
1012 box_iter = GTK_CELL_AREA_BOX_ITER (iter);
1015 if (priv->orientation == GTK_ORIENTATION_VERTICAL)
1017 /* Add up vertical requests of height for width and push the overall
1018 * cached sizes for alignments */
1019 compute_size (box, priv->orientation, box_iter, widget, width, &min_height, &nat_height);
1023 /* Juice: virtually allocate cells into the for_width using the
1024 * alignments and then return the overall height for that width, and cache it */
1025 compute_size_for_opposing_orientation (box, box_iter, widget, width, &min_height, &nat_height);
1029 *minimum_height = min_height;
1032 *natural_height = nat_height;
1036 gtk_cell_area_box_get_preferred_width_for_height (GtkCellArea *area,
1037 GtkCellAreaIter *iter,
1040 gint *minimum_width,
1041 gint *natural_width)
1043 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1044 GtkCellAreaBoxIter *box_iter;
1045 GtkCellAreaBoxPrivate *priv;
1046 gint min_width, nat_width;
1048 g_return_if_fail (GTK_IS_CELL_AREA_BOX_ITER (iter));
1050 box_iter = GTK_CELL_AREA_BOX_ITER (iter);
1053 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1055 /* Add up horizontal requests of width for height and push the overall
1056 * cached sizes for alignments */
1057 compute_size (box, priv->orientation, box_iter, widget, height, &min_width, &nat_width);
1061 /* Juice: horizontally allocate cells into the for_height using the
1062 * alignments and then return the overall width for that height, and cache it */
1063 compute_size_for_opposing_orientation (box, box_iter, widget, height, &min_width, &nat_width);
1067 *minimum_width = min_width;
1070 *natural_width = nat_width;
1074 /*************************************************************
1075 * GtkCellLayoutIface *
1076 *************************************************************/
1078 gtk_cell_area_box_cell_layout_init (GtkCellLayoutIface *iface)
1080 iface->pack_start = gtk_cell_area_box_layout_pack_start;
1081 iface->pack_end = gtk_cell_area_box_layout_pack_end;
1082 iface->reorder = gtk_cell_area_box_layout_reorder;
1086 gtk_cell_area_box_layout_pack_start (GtkCellLayout *cell_layout,
1087 GtkCellRenderer *renderer,
1090 gtk_cell_area_box_pack_start (GTK_CELL_AREA_BOX (cell_layout), renderer, expand, TRUE);
1094 gtk_cell_area_box_layout_pack_end (GtkCellLayout *cell_layout,
1095 GtkCellRenderer *renderer,
1098 gtk_cell_area_box_pack_end (GTK_CELL_AREA_BOX (cell_layout), renderer, expand, TRUE);
1102 gtk_cell_area_box_layout_reorder (GtkCellLayout *cell_layout,
1103 GtkCellRenderer *renderer,
1106 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (cell_layout);
1107 GtkCellAreaBoxPrivate *priv = box->priv;
1111 node = g_list_find_custom (priv->cells, renderer,
1112 (GCompareFunc)cell_info_find);
1118 priv->cells = g_list_delete_link (priv->cells, node);
1119 priv->cells = g_list_insert (priv->cells, info, position);
1121 /* Reconstruct cell groups */
1122 g_list_foreach (priv->groups, (GFunc)cell_group_free, NULL);
1123 g_list_free (priv->groups);
1124 priv->groups = construct_cell_groups (box);
1126 /* Reinitialize groups on iters */
1127 init_iter_groups (box);
1131 /*************************************************************
1133 *************************************************************/
1135 gtk_cell_area_box_new (void)
1137 return (GtkCellArea *)g_object_new (GTK_TYPE_CELL_AREA_BOX, NULL);
1141 gtk_cell_area_box_pack_start (GtkCellAreaBox *box,
1142 GtkCellRenderer *renderer,
1146 GtkCellAreaBoxPrivate *priv;
1149 g_return_if_fail (GTK_IS_CELL_AREA_BOX (box));
1150 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1154 if (g_list_find_custom (priv->cells, renderer,
1155 (GCompareFunc)cell_info_find))
1157 g_warning ("Refusing to add the same cell renderer to a GtkCellAreaBox twice");
1161 info = cell_info_new (renderer, GTK_PACK_START, expand, align);
1163 priv->cells = g_list_append (priv->cells, info);
1165 /* Reconstruct cell groups */
1166 g_list_foreach (priv->groups, (GFunc)cell_group_free, NULL);
1167 g_list_free (priv->groups);
1168 priv->groups = construct_cell_groups (box);
1170 /* Reinitialize groups on iters */
1171 init_iter_groups (box);
1175 gtk_cell_area_box_pack_end (GtkCellAreaBox *box,
1176 GtkCellRenderer *renderer,
1180 GtkCellAreaBoxPrivate *priv;
1183 g_return_if_fail (GTK_IS_CELL_AREA_BOX (box));
1184 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1188 if (g_list_find_custom (priv->cells, renderer,
1189 (GCompareFunc)cell_info_find))
1191 g_warning ("Refusing to add the same cell renderer to a GtkCellArea twice");
1195 info = cell_info_new (renderer, GTK_PACK_END, expand, align);
1197 priv->cells = g_list_append (priv->cells, info);
1199 /* Reconstruct cell groups */
1200 g_list_foreach (priv->groups, (GFunc)cell_group_free, NULL);
1201 g_list_free (priv->groups);
1202 priv->groups = construct_cell_groups (box);
1204 /* Reinitialize groups on iters */
1205 init_iter_groups (box);
1209 gtk_cell_area_box_get_spacing (GtkCellAreaBox *box)
1211 g_return_val_if_fail (GTK_IS_CELL_AREA_BOX (box), 0);
1213 return box->priv->spacing;
1217 gtk_cell_area_box_set_spacing (GtkCellAreaBox *box,
1220 GtkCellAreaBoxPrivate *priv;
1222 g_return_if_fail (GTK_IS_CELL_AREA_BOX (box));
1226 if (priv->spacing != spacing)
1228 priv->spacing = spacing;
1230 g_object_notify (G_OBJECT (box), "spacing");
1232 /* Notify that size needs to be requested again */