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 GtkCellAreaIter *dead_iter);
135 static void flush_iters (GtkCellAreaBox *box);
137 struct _GtkCellAreaBoxPrivate
139 GtkOrientation orientation;
155 G_DEFINE_TYPE_WITH_CODE (GtkCellAreaBox, gtk_cell_area_box, GTK_TYPE_CELL_AREA,
156 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
157 gtk_cell_area_box_cell_layout_init)
158 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL));
160 #define OPPOSITE_ORIENTATION(orientation) \
161 ((orientation) == GTK_ORIENTATION_HORIZONTAL ? \
162 GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL)
165 gtk_cell_area_box_init (GtkCellAreaBox *box)
167 GtkCellAreaBoxPrivate *priv;
169 box->priv = G_TYPE_INSTANCE_GET_PRIVATE (box,
170 GTK_TYPE_CELL_AREA_BOX,
171 GtkCellAreaBoxPrivate);
174 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
182 gtk_cell_area_box_class_init (GtkCellAreaBoxClass *class)
184 GObjectClass *object_class = G_OBJECT_CLASS (class);
185 GtkCellAreaClass *area_class = GTK_CELL_AREA_CLASS (class);
188 object_class->finalize = gtk_cell_area_box_finalize;
189 object_class->dispose = gtk_cell_area_box_dispose;
190 object_class->set_property = gtk_cell_area_box_set_property;
191 object_class->get_property = gtk_cell_area_box_get_property;
193 /* GtkCellAreaClass */
194 area_class->add = gtk_cell_area_box_add;
195 area_class->remove = gtk_cell_area_box_remove;
196 area_class->forall = gtk_cell_area_box_forall;
197 area_class->event = gtk_cell_area_box_event;
198 area_class->render = gtk_cell_area_box_render;
200 area_class->create_iter = gtk_cell_area_box_create_iter;
201 area_class->get_request_mode = gtk_cell_area_box_get_request_mode;
202 area_class->get_preferred_width = gtk_cell_area_box_get_preferred_width;
203 area_class->get_preferred_height = gtk_cell_area_box_get_preferred_height;
204 area_class->get_preferred_height_for_width = gtk_cell_area_box_get_preferred_height_for_width;
205 area_class->get_preferred_width_for_height = gtk_cell_area_box_get_preferred_width_for_height;
207 g_object_class_override_property (object_class, PROP_ORIENTATION, "orientation");
209 g_object_class_install_property (object_class,
211 g_param_spec_int ("spacing",
213 P_("Space which is inserted between cells"),
217 GTK_PARAM_READWRITE));
219 g_type_class_add_private (object_class, sizeof (GtkCellAreaBoxPrivate));
223 /*************************************************************
224 * CellInfo/CellGroup basics and convenience functions *
225 *************************************************************/
227 cell_info_new (GtkCellRenderer *renderer,
232 CellInfo *info = g_slice_new (CellInfo);
234 info->renderer = g_object_ref_sink (renderer);
236 info->expand = expand;
243 cell_info_free (CellInfo *info)
245 g_object_unref (info->renderer);
247 g_slice_free (CellInfo, info);
251 cell_info_find (CellInfo *info,
252 GtkCellRenderer *renderer)
254 return (info->renderer == renderer) ? 0 : -1;
258 cell_group_new (guint id)
260 CellGroup *group = g_slice_new0 (CellGroup);
268 cell_group_free (CellGroup *group)
270 g_list_free (group->cells);
271 g_slice_free (CellGroup, group);
275 list_consecutive_cells (GtkCellAreaBox *box)
277 GtkCellAreaBoxPrivate *priv = box->priv;
278 GList *l, *consecutive_cells = NULL, *pack_end_cells = NULL;
281 /* List cells in consecutive order taking their
282 * PACK_START/PACK_END options into account
284 for (l = priv->cells; l; l = l->next)
288 if (info->pack == GTK_PACK_START)
289 consecutive_cells = g_list_prepend (consecutive_cells, info);
292 for (l = priv->cells; l; l = l->next)
296 if (info->pack == GTK_PACK_END)
297 pack_end_cells = g_list_prepend (pack_end_cells, info);
300 consecutive_cells = g_list_reverse (consecutive_cells);
301 consecutive_cells = g_list_concat (consecutive_cells, pack_end_cells);
303 return consecutive_cells;
307 construct_cell_groups (GtkCellAreaBox *box)
309 GtkCellAreaBoxPrivate *priv = box->priv;
312 GList *groups = NULL;
318 cells = list_consecutive_cells (box);
319 group = cell_group_new (id++);
320 groups = g_list_prepend (groups, group);
322 for (l = cells; l; l = l->next)
324 CellInfo *info = l->data;
326 /* A new group starts with any aligned cell, the first group is implied */
327 if (info->align && l != cells)
329 group = cell_group_new (id++);
330 groups = g_list_prepend (groups, group);
333 group->cells = g_list_prepend (group->cells, info);
335 /* A group expands if it contains any expand cells */
337 group->expand = TRUE;
342 for (l = cells; l; l = l->next)
345 group->cells = g_list_reverse (group->cells);
348 return g_list_reverse (groups);
352 count_expand_groups (GtkCellAreaBox *box)
354 GtkCellAreaBoxPrivate *priv = box->priv;
356 gint expand_groups = 0;
358 for (l = priv->groups; l; l = l->next)
360 CellGroup *group = l->data;
366 return expand_groups;
370 count_expand_cells (CellGroup *group)
373 gint expand_cells = 0;
378 for (l = group->cells; l; l = l->next)
380 CellInfo *info = l->data;
390 iter_weak_notify (GtkCellAreaBox *box,
391 GtkCellAreaIter *dead_iter)
393 GtkCellAreaBoxPrivate *priv = box->priv;
395 priv->iters = g_slist_remove (priv->iters, dead_iter);
399 flush_iters (GtkCellAreaBox *box)
401 GtkCellAreaBoxPrivate *priv = box->priv;
404 /* When the box layout changes, iters need to
405 * be flushed and sizes for the box get requested again
407 for (l = priv->iters; l; l = l->next)
409 GtkCellAreaIter *iter = l->data;
411 gtk_cell_area_iter_flush (iter);
416 /* XXX This guy makes an allocation to be stored and retrieved from the iter */
417 GtkCellAreaBoxAllocation *
418 gtk_cell_area_box_allocate (GtkCellAreaBox *box,
419 GtkCellAreaBoxIter *iter,
423 GtkCellAreaBoxPrivate *priv = box->priv;
426 GtkRequestedSize *orientation_sizes;
427 gint n_groups, n_expand_groups, i;
428 gint avail_size = size;
429 gint extra_size, extra_extra;
431 GtkCellAreaBoxAllocation *allocs;
433 n_expand_groups = count_expand_groups (box);
435 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
436 orientation_sizes = gtk_cell_area_box_iter_get_widths (iter, &n_groups);
438 orientation_sizes = gtk_cell_area_box_iter_get_heights (iter, &n_groups);
440 /* First start by naturally allocating space among groups of cells */
441 avail_size -= (n_groups - 1) * priv->spacing;
442 for (i = 0; i < n_groups; i++)
443 avail_size -= orientation_sizes[i].minimum_size;
445 avail_size = gtk_distribute_natural_allocation (avail_size, n_groups, orientation_sizes);
447 /* Calculate/distribute expand for groups */
448 if (n_expand_groups > 0)
450 extra_size = avail_size / n_expand_groups;
451 extra_extra = avail_size % n_expand_groups;
454 extra_size = extra_extra = 0;
456 allocs = g_new (GtkCellAreaBoxAllocation, n_groups);
458 for (position = 0, group_list = priv->groups; group_list; group_list = group_list->next)
460 group = group_list->data;
462 allocs[group->id].position = position;
463 allocs[group->id].size = orientation_sizes[group->id].minimum_size;
467 allocs[group->id].size += extra_size;
470 allocs[group->id].size++;
475 position += allocs[group->id].size;
476 position += priv->spacing;
479 g_free (orientation_sizes);
482 *n_allocs = n_groups;
488 /*************************************************************
490 *************************************************************/
492 gtk_cell_area_box_finalize (GObject *object)
494 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (object);
495 GtkCellAreaBoxPrivate *priv = box->priv;
498 for (l = priv->iters; l; l = l->next)
499 g_object_weak_unref (G_OBJECT (l->data), (GWeakNotify)iter_weak_notify, box);
501 g_slist_free (priv->iters);
503 G_OBJECT_CLASS (gtk_cell_area_box_parent_class)->finalize (object);
507 gtk_cell_area_box_dispose (GObject *object)
509 G_OBJECT_CLASS (gtk_cell_area_box_parent_class)->dispose (object);
513 gtk_cell_area_box_set_property (GObject *object,
518 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (object);
523 gtk_cell_area_box_set_spacing (box, g_value_get_int (value));
526 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
532 gtk_cell_area_box_get_property (GObject *object,
537 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (object);
542 g_value_set_int (value, gtk_cell_area_box_get_spacing (box));
545 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
550 /*************************************************************
552 *************************************************************/
554 gtk_cell_area_box_add (GtkCellArea *area,
555 GtkCellRenderer *renderer)
557 gtk_cell_area_box_pack_start (GTK_CELL_AREA_BOX (area),
558 renderer, FALSE, TRUE);
562 gtk_cell_area_box_remove (GtkCellArea *area,
563 GtkCellRenderer *renderer)
565 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
566 GtkCellAreaBoxPrivate *priv = box->priv;
569 node = g_list_find_custom (priv->cells, renderer,
570 (GCompareFunc)cell_info_find);
574 CellInfo *info = node->data;
576 cell_info_free (info);
578 priv->cells = g_list_delete_link (priv->cells, node);
580 /* Reconstruct cell groups */
581 g_list_foreach (priv->groups, (GFunc)cell_group_free, NULL);
582 g_list_free (priv->groups);
583 priv->groups = construct_cell_groups (box);
585 /* Notify that size needs to be requested again */
589 g_warning ("Trying to remove a cell renderer that is not present GtkCellAreaBox");
593 gtk_cell_area_box_forall (GtkCellArea *area,
594 GtkCellCallback callback,
595 gpointer callback_data)
597 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
598 GtkCellAreaBoxPrivate *priv = box->priv;
601 for (list = priv->cells; list; list = list->next)
603 CellInfo *info = list->data;
605 callback (info->renderer, callback_data);
610 gtk_cell_area_box_event (GtkCellArea *area,
611 GtkCellAreaIter *iter,
614 const GdkRectangle *cell_area)
622 gtk_cell_area_box_render (GtkCellArea *area,
623 GtkCellAreaIter *iter,
626 const GdkRectangle *cell_area)
631 static GtkCellAreaIter *
632 gtk_cell_area_box_create_iter (GtkCellArea *area)
634 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
635 GtkCellAreaBoxPrivate *priv = box->priv;
636 GtkCellAreaIter *iter =
637 (GtkCellAreaIter *)g_object_new (GTK_TYPE_CELL_AREA_BOX_ITER, NULL);
639 priv->iters = g_slist_prepend (priv->iters, iter);
641 g_object_weak_ref (G_OBJECT (iter), (GWeakNotify)iter_weak_notify, box);
646 static GtkSizeRequestMode
647 gtk_cell_area_box_get_request_mode (GtkCellArea *area)
649 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
650 GtkCellAreaBoxPrivate *priv = box->priv;
652 return (priv->orientation) == GTK_ORIENTATION_HORIZONTAL ?
653 GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH :
654 GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT;
658 get_renderer_size (GtkCellRenderer *renderer,
659 GtkOrientation orientation,
665 if (orientation == GTK_ORIENTATION_HORIZONTAL)
668 gtk_cell_renderer_get_preferred_width (renderer, widget, minimum_size, natural_size);
670 gtk_cell_renderer_get_preferred_width_for_height (renderer, widget, for_size,
671 minimum_size, natural_size);
673 else /* GTK_ORIENTATION_VERTICAL */
676 gtk_cell_renderer_get_preferred_height (renderer, widget, minimum_size, natural_size);
678 gtk_cell_renderer_get_preferred_height_for_width (renderer, widget, for_size,
679 minimum_size, natural_size);
684 compute_size (GtkCellAreaBox *box,
685 GtkOrientation orientation,
686 GtkCellAreaBoxIter *iter,
692 GtkCellAreaBoxPrivate *priv = box->priv;
695 GList *cell_list, *group_list;
699 for (group_list = priv->groups; group_list; group_list = group_list->next)
701 gint group_min_size = 0;
702 gint group_nat_size = 0;
704 group = group_list->data;
706 for (cell_list = group->cells; cell_list; cell_list = cell_list->next)
708 gint renderer_min_size, renderer_nat_size;
710 info = cell_list->data;
712 get_renderer_size (info->renderer, orientation, widget, for_size,
713 &renderer_min_size, &renderer_nat_size);
715 if (orientation == priv->orientation)
719 min_size += priv->spacing;
720 nat_size += priv->spacing;
723 if (group_min_size > 0)
725 group_min_size += priv->spacing;
726 group_nat_size += priv->spacing;
729 min_size += renderer_min_size;
730 nat_size += renderer_nat_size;
731 group_min_size += renderer_min_size;
732 group_nat_size += renderer_nat_size;
736 min_size = MAX (min_size, renderer_min_size);
737 nat_size = MAX (nat_size, renderer_nat_size);
738 group_min_size = MAX (group_min_size, renderer_min_size);
739 group_nat_size = MAX (group_nat_size, renderer_nat_size);
743 if (orientation == GTK_ORIENTATION_HORIZONTAL)
746 gtk_cell_area_box_iter_push_group_width (iter, group->id, group_min_size, group_nat_size);
748 gtk_cell_area_box_iter_push_group_width_for_height (iter, group->id, for_size,
749 group_min_size, group_nat_size);
754 gtk_cell_area_box_iter_push_group_height (iter, group->id, group_min_size, group_nat_size);
756 gtk_cell_area_box_iter_push_group_height_for_width (iter, group->id, for_size,
757 group_min_size, group_nat_size);
761 *minimum_size = min_size;
762 *natural_size = nat_size;
766 get_group_sizes (CellGroup *group,
767 GtkOrientation orientation,
771 GtkRequestedSize *sizes;
775 *n_sizes = g_list_length (group->cells);
776 sizes = g_new (GtkRequestedSize, *n_sizes);
778 for (l = group->cells, i = 0; l; l = l->next, i++)
780 CellInfo *info = l->data;
782 sizes[i].data = info;
784 get_renderer_size (info->renderer,
785 orientation, widget, -1,
786 &sizes[i].minimum_size,
787 &sizes[i].natural_size);
794 compute_group_size_for_opposing_orientation (GtkCellAreaBox *box,
801 GtkCellAreaBoxPrivate *priv = box->priv;
803 /* Exception for single cell groups */
804 if (!group->cells->next)
806 CellInfo *info = group->cells->data;
808 get_renderer_size (info->renderer,
809 OPPOSITE_ORIENTATION (priv->orientation),
810 widget, for_size, minimum_size, natural_size);
814 GtkRequestedSize *orientation_sizes;
817 gint n_expand_cells = count_expand_cells (group);
818 gint avail_size = for_size;
819 gint extra_size, extra_extra;
820 gint min_size = 0, nat_size = 0;
822 orientation_sizes = get_group_sizes (group, priv->orientation, widget, &n_sizes);
824 /* First naturally allocate the cells in the group into the for_size */
825 avail_size -= (n_sizes - 1) * priv->spacing;
826 for (i = 0; i < n_sizes; i++)
827 avail_size -= orientation_sizes[i].minimum_size;
829 avail_size = gtk_distribute_natural_allocation (avail_size, n_sizes, orientation_sizes);
831 /* Calculate/distribute expand for cells */
832 if (n_expand_cells > 0)
834 extra_size = avail_size / n_expand_cells;
835 extra_extra = avail_size % n_expand_cells;
838 extra_size = extra_extra = 0;
840 for (i = 0; i < n_sizes; i++)
842 gint cell_min, cell_nat;
844 info = orientation_sizes[i].data;
848 orientation_sizes[i].minimum_size += extra_size;
851 orientation_sizes[i].minimum_size++;
856 get_renderer_size (info->renderer,
857 OPPOSITE_ORIENTATION (priv->orientation),
859 orientation_sizes[i].minimum_size,
860 &cell_min, &cell_nat);
862 min_size = MAX (min_size, cell_min);
863 nat_size = MAX (nat_size, cell_nat);
866 *minimum_size = min_size;
867 *natural_size = nat_size;
869 g_free (orientation_sizes);
874 compute_size_for_opposing_orientation (GtkCellAreaBox *box,
875 GtkCellAreaBoxIter *iter,
881 GtkCellAreaBoxPrivate *priv = box->priv;
884 GtkRequestedSize *orientation_sizes;
885 gint n_groups, n_expand_groups, i;
886 gint avail_size = for_size;
887 gint extra_size, extra_extra;
888 gint min_size = 0, nat_size = 0;
890 n_expand_groups = count_expand_groups (box);
892 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
893 orientation_sizes = gtk_cell_area_box_iter_get_widths (iter, &n_groups);
895 orientation_sizes = gtk_cell_area_box_iter_get_heights (iter, &n_groups);
897 /* First start by naturally allocating space among groups of cells */
898 avail_size -= (n_groups - 1) * priv->spacing;
899 for (i = 0; i < n_groups; i++)
900 avail_size -= orientation_sizes[i].minimum_size;
902 avail_size = gtk_distribute_natural_allocation (avail_size, n_groups, orientation_sizes);
904 /* Calculate/distribute expand for groups */
905 if (n_expand_groups > 0)
907 extra_size = avail_size / n_expand_groups;
908 extra_extra = avail_size % n_expand_groups;
911 extra_size = extra_extra = 0;
913 /* Now we need to naturally allocate sizes for cells in each group
914 * and push the height-for-width for each group accordingly while accumulating
915 * the overall height-for-width for this row.
917 for (group_list = priv->groups; group_list; group_list = group_list->next)
919 gint group_min, group_nat;
921 group = group_list->data;
925 orientation_sizes[group->id].minimum_size += extra_size;
928 orientation_sizes[group->id].minimum_size++;
933 /* Now we have the allocation for the group, request it's height-for-width */
934 compute_group_size_for_opposing_orientation (box, group, widget,
935 orientation_sizes[group->id].minimum_size,
936 &group_min, &group_nat);
938 min_size = MAX (min_size, group_min);
939 nat_size = MAX (nat_size, group_nat);
941 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
943 gtk_cell_area_box_iter_push_group_height_for_width (iter, group->id, for_size,
944 group_min, group_nat);
948 gtk_cell_area_box_iter_push_group_width_for_height (iter, group->id, for_size,
949 group_min, group_nat);
953 *minimum_size = min_size;
954 *natural_size = nat_size;
956 g_free (orientation_sizes);
962 gtk_cell_area_box_get_preferred_width (GtkCellArea *area,
963 GtkCellAreaIter *iter,
968 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
969 GtkCellAreaBoxIter *box_iter;
970 gint min_width, nat_width;
972 g_return_if_fail (GTK_IS_CELL_AREA_BOX_ITER (iter));
974 box_iter = GTK_CELL_AREA_BOX_ITER (iter);
976 /* Compute the size of all renderers for current row data,
977 * bumping cell alignments in the iter along the way */
978 compute_size (box, GTK_ORIENTATION_HORIZONTAL,
979 box_iter, widget, -1, &min_width, &nat_width);
982 *minimum_width = min_width;
985 *natural_width = nat_width;
989 gtk_cell_area_box_get_preferred_height (GtkCellArea *area,
990 GtkCellAreaIter *iter,
992 gint *minimum_height,
993 gint *natural_height)
995 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
996 GtkCellAreaBoxIter *box_iter;
997 gint min_height, nat_height;
999 g_return_if_fail (GTK_IS_CELL_AREA_BOX_ITER (iter));
1001 box_iter = GTK_CELL_AREA_BOX_ITER (iter);
1003 /* Compute the size of all renderers for current row data,
1004 * bumping cell alignments in the iter along the way */
1005 compute_size (box, GTK_ORIENTATION_VERTICAL,
1006 box_iter, widget, -1, &min_height, &nat_height);
1009 *minimum_height = min_height;
1012 *natural_height = nat_height;
1016 gtk_cell_area_box_get_preferred_height_for_width (GtkCellArea *area,
1017 GtkCellAreaIter *iter,
1020 gint *minimum_height,
1021 gint *natural_height)
1023 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1024 GtkCellAreaBoxIter *box_iter;
1025 GtkCellAreaBoxPrivate *priv;
1026 gint min_height, nat_height;
1028 g_return_if_fail (GTK_IS_CELL_AREA_BOX_ITER (iter));
1030 box_iter = GTK_CELL_AREA_BOX_ITER (iter);
1033 if (priv->orientation == GTK_ORIENTATION_VERTICAL)
1035 /* Add up vertical requests of height for width and push the overall
1036 * cached sizes for alignments */
1037 compute_size (box, priv->orientation, box_iter, widget, width, &min_height, &nat_height);
1041 /* Juice: virtually allocate cells into the for_width using the
1042 * alignments and then return the overall height for that width, and cache it */
1043 compute_size_for_opposing_orientation (box, box_iter, widget, width, &min_height, &nat_height);
1047 *minimum_height = min_height;
1050 *natural_height = nat_height;
1054 gtk_cell_area_box_get_preferred_width_for_height (GtkCellArea *area,
1055 GtkCellAreaIter *iter,
1058 gint *minimum_width,
1059 gint *natural_width)
1061 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1062 GtkCellAreaBoxIter *box_iter;
1063 GtkCellAreaBoxPrivate *priv;
1064 gint min_width, nat_width;
1066 g_return_if_fail (GTK_IS_CELL_AREA_BOX_ITER (iter));
1068 box_iter = GTK_CELL_AREA_BOX_ITER (iter);
1071 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1073 /* Add up horizontal requests of width for height and push the overall
1074 * cached sizes for alignments */
1075 compute_size (box, priv->orientation, box_iter, widget, height, &min_width, &nat_width);
1079 /* Juice: horizontally allocate cells into the for_height using the
1080 * alignments and then return the overall width for that height, and cache it */
1081 compute_size_for_opposing_orientation (box, box_iter, widget, height, &min_width, &nat_width);
1085 *minimum_width = min_width;
1088 *natural_width = nat_width;
1092 /*************************************************************
1093 * GtkCellLayoutIface *
1094 *************************************************************/
1096 gtk_cell_area_box_cell_layout_init (GtkCellLayoutIface *iface)
1098 iface->pack_start = gtk_cell_area_box_layout_pack_start;
1099 iface->pack_end = gtk_cell_area_box_layout_pack_end;
1100 iface->reorder = gtk_cell_area_box_layout_reorder;
1104 gtk_cell_area_box_layout_pack_start (GtkCellLayout *cell_layout,
1105 GtkCellRenderer *renderer,
1108 gtk_cell_area_box_pack_start (GTK_CELL_AREA_BOX (cell_layout), renderer, expand, TRUE);
1112 gtk_cell_area_box_layout_pack_end (GtkCellLayout *cell_layout,
1113 GtkCellRenderer *renderer,
1116 gtk_cell_area_box_pack_end (GTK_CELL_AREA_BOX (cell_layout), renderer, expand, TRUE);
1120 gtk_cell_area_box_layout_reorder (GtkCellLayout *cell_layout,
1121 GtkCellRenderer *renderer,
1124 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (cell_layout);
1125 GtkCellAreaBoxPrivate *priv = box->priv;
1129 node = g_list_find_custom (priv->cells, renderer,
1130 (GCompareFunc)cell_info_find);
1136 priv->cells = g_list_delete_link (priv->cells, node);
1137 priv->cells = g_list_insert (priv->cells, info, position);
1139 /* Reconstruct cell groups */
1140 g_list_foreach (priv->groups, (GFunc)cell_group_free, NULL);
1141 g_list_free (priv->groups);
1142 priv->groups = construct_cell_groups (box);
1144 /* Notify that size needs to be requested again */
1149 /*************************************************************
1151 *************************************************************/
1153 gtk_cell_area_box_new (void)
1155 return (GtkCellArea *)g_object_new (GTK_TYPE_CELL_AREA_BOX, NULL);
1159 gtk_cell_area_box_pack_start (GtkCellAreaBox *box,
1160 GtkCellRenderer *renderer,
1164 GtkCellAreaBoxPrivate *priv;
1167 g_return_if_fail (GTK_IS_CELL_AREA_BOX (box));
1168 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1172 if (g_list_find_custom (priv->cells, renderer,
1173 (GCompareFunc)cell_info_find))
1175 g_warning ("Refusing to add the same cell renderer to a GtkCellAreaBox twice");
1179 info = cell_info_new (renderer, GTK_PACK_START, expand, align);
1181 priv->cells = g_list_append (priv->cells, info);
1183 /* Reconstruct cell groups */
1184 g_list_foreach (priv->groups, (GFunc)cell_group_free, NULL);
1185 g_list_free (priv->groups);
1186 priv->groups = construct_cell_groups (box);
1188 /* Notify that size needs to be requested again */
1193 gtk_cell_area_box_pack_end (GtkCellAreaBox *box,
1194 GtkCellRenderer *renderer,
1198 GtkCellAreaBoxPrivate *priv;
1201 g_return_if_fail (GTK_IS_CELL_AREA_BOX (box));
1202 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1206 if (g_list_find_custom (priv->cells, renderer,
1207 (GCompareFunc)cell_info_find))
1209 g_warning ("Refusing to add the same cell renderer to a GtkCellArea twice");
1213 info = cell_info_new (renderer, GTK_PACK_END, expand, align);
1215 priv->cells = g_list_append (priv->cells, info);
1217 /* Reconstruct cell groups */
1218 g_list_foreach (priv->groups, (GFunc)cell_group_free, NULL);
1219 g_list_free (priv->groups);
1220 priv->groups = construct_cell_groups (box);
1222 /* Notify that size needs to be requested again */
1227 gtk_cell_area_box_get_spacing (GtkCellAreaBox *box)
1229 g_return_val_if_fail (GTK_IS_CELL_AREA_BOX (box), 0);
1231 return box->priv->spacing;
1235 gtk_cell_area_box_set_spacing (GtkCellAreaBox *box,
1238 GtkCellAreaBoxPrivate *priv;
1240 g_return_if_fail (GTK_IS_CELL_AREA_BOX (box));
1244 if (priv->spacing != spacing)
1246 priv->spacing = spacing;
1248 g_object_notify (G_OBJECT (box), "spacing");
1250 /* Notify that size needs to be requested again */