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 * SECTION:gtkcellareabox
27 * @Short_Description: A cell area that renders #GtkCellRenderers into a row or a column
28 * @Title: GtkCellAreaBox
30 * The #GtkCellAreaBox renders cell renderers into a row or a column depending on
31 * its #GtkOrientation.
33 * GtkCellAreaBox uses a notion of <emphasis>packing</emphasis>. Packing
34 * refers to adding cell renderers with reference to a particular position
35 * in a #GtkCellAreaBox. There are two reference positions: the
36 * <emphasis>start</emphasis> and the <emphasis>end</emphasis> of the box.
37 * When the #GtkCellAreaBox is oriented in the %GTK_ORIENTATION_VERTICAL orientation,
38 * the start is defined as the top of the box and the end is defined as the bottom.
39 * In the %GTK_ORIENTATION_HORIZONTAL orientation start is defined as the
40 * left side and the end is defined as the right side.
42 * Alignments of #GtkCellRenderers rendered in adjacent rows can be configured
43 * by configuring the #GtkCellAreaBox:align child cell property with
44 * gtk_cell_area_cell_set_property() or by specifying the "align" argument
45 * to gtk_cell_area_box_pack_start() and gtk_cell_area_box_pack_end().
50 #include "gtkorientable.h"
51 #include "gtkcelllayout.h"
52 #include "gtkcellareabox.h"
53 #include "gtkcellareaboxcontext.h"
54 #include "gtkprivate.h"
58 static void gtk_cell_area_box_finalize (GObject *object);
59 static void gtk_cell_area_box_dispose (GObject *object);
60 static void gtk_cell_area_box_set_property (GObject *object,
64 static void gtk_cell_area_box_get_property (GObject *object,
69 /* GtkCellAreaClass */
70 static void gtk_cell_area_box_add (GtkCellArea *area,
71 GtkCellRenderer *renderer);
72 static void gtk_cell_area_box_remove (GtkCellArea *area,
73 GtkCellRenderer *renderer);
74 static void gtk_cell_area_box_foreach (GtkCellArea *area,
75 GtkCellCallback callback,
76 gpointer callback_data);
77 static void gtk_cell_area_box_foreach_alloc (GtkCellArea *area,
78 GtkCellAreaContext *context,
80 const GdkRectangle *cell_area,
81 const GdkRectangle *background_area,
82 GtkCellAllocCallback callback,
83 gpointer callback_data);
84 static void gtk_cell_area_box_set_cell_property (GtkCellArea *area,
85 GtkCellRenderer *renderer,
89 static void gtk_cell_area_box_get_cell_property (GtkCellArea *area,
90 GtkCellRenderer *renderer,
94 static GtkCellAreaContext *gtk_cell_area_box_create_context (GtkCellArea *area);
95 static GtkSizeRequestMode gtk_cell_area_box_get_request_mode (GtkCellArea *area);
96 static void gtk_cell_area_box_get_preferred_width (GtkCellArea *area,
97 GtkCellAreaContext *context,
100 gint *natural_width);
101 static void gtk_cell_area_box_get_preferred_height (GtkCellArea *area,
102 GtkCellAreaContext *context,
104 gint *minimum_height,
105 gint *natural_height);
106 static void gtk_cell_area_box_get_preferred_height_for_width (GtkCellArea *area,
107 GtkCellAreaContext *context,
110 gint *minimum_height,
111 gint *natural_height);
112 static void gtk_cell_area_box_get_preferred_width_for_height (GtkCellArea *area,
113 GtkCellAreaContext *context,
117 gint *natural_width);
118 static gboolean gtk_cell_area_box_focus (GtkCellArea *area,
119 GtkDirectionType direction);
121 /* GtkCellLayoutIface */
122 static void gtk_cell_area_box_cell_layout_init (GtkCellLayoutIface *iface);
123 static void gtk_cell_area_box_layout_pack_start (GtkCellLayout *cell_layout,
124 GtkCellRenderer *renderer,
126 static void gtk_cell_area_box_layout_pack_end (GtkCellLayout *cell_layout,
127 GtkCellRenderer *renderer,
129 static void gtk_cell_area_box_layout_reorder (GtkCellLayout *cell_layout,
130 GtkCellRenderer *renderer,
132 static void gtk_cell_area_box_focus_changed (GtkCellArea *area,
134 GtkCellAreaBox *box);
137 /* CellInfo/CellGroup metadata handling and convenience functions */
139 GtkCellRenderer *renderer;
141 guint expand : 1; /* Whether the cell expands */
142 guint pack : 1; /* Whether the cell is packed from the start or end */
143 guint align : 1; /* Whether to align this cell's position with adjacent rows */
151 guint expand_cells : 8;
155 GtkCellRenderer *renderer;
161 static CellInfo *cell_info_new (GtkCellRenderer *renderer,
165 static void cell_info_free (CellInfo *info);
166 static gint cell_info_find (CellInfo *info,
167 GtkCellRenderer *renderer);
169 static AllocatedCell *allocated_cell_new (GtkCellRenderer *renderer,
172 static void allocated_cell_free (AllocatedCell *cell);
173 static GList *list_consecutive_cells (GtkCellAreaBox *box);
174 static gint count_expand_groups (GtkCellAreaBox *box);
175 static void context_weak_notify (GtkCellAreaBox *box,
176 GtkCellAreaBoxContext *dead_context);
177 static void reset_contexts (GtkCellAreaBox *box);
178 static void init_context_groups (GtkCellAreaBox *box);
179 static void init_context_group (GtkCellAreaBox *box,
180 GtkCellAreaBoxContext *context);
181 static GSList *get_allocated_cells (GtkCellAreaBox *box,
182 GtkCellAreaBoxContext *context,
188 struct _GtkCellAreaBoxPrivate
190 GtkOrientation orientation;
192 /* We hold on to the previously focused cell when navigating
193 * up and down in a horizontal box (or left and right on a vertical one)
194 * this way we always re-enter the last focused cell. */
195 GtkCellRenderer *last_focus_cell;
196 gulong focus_cell_id;
205 /* We hold on to the rtl state from a widget we are requested for
206 * so that we can navigate focus correctly */
223 G_DEFINE_TYPE_WITH_CODE (GtkCellAreaBox, gtk_cell_area_box, GTK_TYPE_CELL_AREA,
224 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
225 gtk_cell_area_box_cell_layout_init)
226 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL));
228 #define OPPOSITE_ORIENTATION(orientation) \
229 ((orientation) == GTK_ORIENTATION_HORIZONTAL ? \
230 GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL)
233 gtk_cell_area_box_init (GtkCellAreaBox *box)
235 GtkCellAreaBoxPrivate *priv;
237 box->priv = G_TYPE_INSTANCE_GET_PRIVATE (box,
238 GTK_TYPE_CELL_AREA_BOX,
239 GtkCellAreaBoxPrivate);
242 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
243 priv->groups = g_array_new (FALSE, TRUE, sizeof (CellGroup));
245 priv->contexts = NULL;
249 /* Watch whenever focus is given to a cell, even if it's not with keynav,
250 * this way we remember upon entry of the area where focus was last time around */
251 priv->focus_cell_id = g_signal_connect (box, "notify::focus-cell",
252 G_CALLBACK (gtk_cell_area_box_focus_changed), box);
256 gtk_cell_area_box_class_init (GtkCellAreaBoxClass *class)
258 GObjectClass *object_class = G_OBJECT_CLASS (class);
259 GtkCellAreaClass *area_class = GTK_CELL_AREA_CLASS (class);
262 object_class->finalize = gtk_cell_area_box_finalize;
263 object_class->dispose = gtk_cell_area_box_dispose;
264 object_class->set_property = gtk_cell_area_box_set_property;
265 object_class->get_property = gtk_cell_area_box_get_property;
267 /* GtkCellAreaClass */
268 area_class->add = gtk_cell_area_box_add;
269 area_class->remove = gtk_cell_area_box_remove;
270 area_class->foreach = gtk_cell_area_box_foreach;
271 area_class->foreach_alloc = gtk_cell_area_box_foreach_alloc;
272 area_class->set_cell_property = gtk_cell_area_box_set_cell_property;
273 area_class->get_cell_property = gtk_cell_area_box_get_cell_property;
275 area_class->create_context = gtk_cell_area_box_create_context;
276 area_class->get_request_mode = gtk_cell_area_box_get_request_mode;
277 area_class->get_preferred_width = gtk_cell_area_box_get_preferred_width;
278 area_class->get_preferred_height = gtk_cell_area_box_get_preferred_height;
279 area_class->get_preferred_height_for_width = gtk_cell_area_box_get_preferred_height_for_width;
280 area_class->get_preferred_width_for_height = gtk_cell_area_box_get_preferred_width_for_height;
282 area_class->focus = gtk_cell_area_box_focus;
285 g_object_class_override_property (object_class, PROP_ORIENTATION, "orientation");
288 * GtkCellAreaBox:spacing:
290 * The amount of space to reserve between cells.
294 g_object_class_install_property (object_class,
296 g_param_spec_int ("spacing",
298 P_("Space which is inserted between cells"),
302 GTK_PARAM_READWRITE));
304 /* Cell Properties */
306 * GtkCellAreaBox:expand:
308 * Whether the cell renderer should receive extra space when the area receives
309 * more than its natural size.
313 gtk_cell_area_class_install_cell_property (area_class,
318 P_("Whether the cell expands"),
320 GTK_PARAM_READWRITE));
323 * GtkCellAreaBox:align:
325 * Whether the cell renderer should be aligned in adjacent rows.
329 gtk_cell_area_class_install_cell_property (area_class,
334 P_("Whether cell should align with adjacent rows"),
336 GTK_PARAM_READWRITE));
339 * GtkCellAreaBox:pack-type:
341 * A GtkPackType indicating whether the cell renderer is packed with reference to the
342 * start or end of the area.
346 gtk_cell_area_class_install_cell_property (area_class,
351 P_("A GtkPackType indicating whether the cell is packed with "
352 "reference to the start or end of the cell area"),
353 GTK_TYPE_PACK_TYPE, GTK_PACK_START,
354 GTK_PARAM_READWRITE));
356 g_type_class_add_private (object_class, sizeof (GtkCellAreaBoxPrivate));
360 /*************************************************************
361 * CellInfo/CellGroup basics and convenience functions *
362 *************************************************************/
364 cell_info_new (GtkCellRenderer *renderer,
369 CellInfo *info = g_slice_new (CellInfo);
371 info->renderer = g_object_ref_sink (renderer);
373 info->expand = expand;
380 cell_info_free (CellInfo *info)
382 g_object_unref (info->renderer);
384 g_slice_free (CellInfo, info);
388 cell_info_find (CellInfo *info,
389 GtkCellRenderer *renderer)
391 return (info->renderer == renderer) ? 0 : -1;
394 static AllocatedCell *
395 allocated_cell_new (GtkCellRenderer *renderer,
399 AllocatedCell *cell = g_slice_new (AllocatedCell);
401 cell->renderer = renderer;
402 cell->position = position;
409 allocated_cell_free (AllocatedCell *cell)
411 g_slice_free (AllocatedCell, cell);
415 list_consecutive_cells (GtkCellAreaBox *box)
417 GtkCellAreaBoxPrivate *priv = box->priv;
418 GList *l, *consecutive_cells = NULL, *pack_end_cells = NULL;
421 /* List cells in consecutive order taking their
422 * PACK_START/PACK_END options into account
424 for (l = priv->cells; l; l = l->next)
428 if (info->pack == GTK_PACK_START)
429 consecutive_cells = g_list_prepend (consecutive_cells, info);
432 for (l = priv->cells; l; l = l->next)
436 if (info->pack == GTK_PACK_END)
437 pack_end_cells = g_list_prepend (pack_end_cells, info);
440 consecutive_cells = g_list_reverse (consecutive_cells);
441 consecutive_cells = g_list_concat (consecutive_cells, pack_end_cells);
443 return consecutive_cells;
447 cell_groups_clear (GtkCellAreaBox *box)
449 GtkCellAreaBoxPrivate *priv = box->priv;
452 for (i = 0; i < priv->groups->len; i++)
454 CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
456 g_list_free (group->cells);
459 g_array_set_size (priv->groups, 0);
463 cell_groups_rebuild (GtkCellAreaBox *box)
465 GtkCellAreaBoxPrivate *priv = box->priv;
466 CellGroup group = { 0, };
467 CellGroup *group_ptr;
471 cell_groups_clear (box);
476 cells = list_consecutive_cells (box);
478 /* First group is implied */
479 g_array_append_val (priv->groups, group);
480 group_ptr = &g_array_index (priv->groups, CellGroup, id);
482 for (l = cells; l; l = l->next)
484 CellInfo *info = l->data;
486 /* A new group starts with any aligned cell, the first group is implied */
487 if (info->align && l != cells)
489 memset (&group, 0x0, sizeof (CellGroup));
492 g_array_append_val (priv->groups, group);
493 group_ptr = &g_array_index (priv->groups, CellGroup, id);
496 group_ptr->cells = g_list_prepend (group_ptr->cells, info);
497 group_ptr->n_cells++;
499 /* A group expands if it contains any expand cells */
501 group_ptr->expand_cells++;
506 for (id = 0; id < priv->groups->len; id++)
508 group_ptr = &g_array_index (priv->groups, CellGroup, id);
510 group_ptr->cells = g_list_reverse (group_ptr->cells);
513 /* Contexts need to be updated with the new grouping information */
514 init_context_groups (box);
518 count_visible_cells (CellGroup *group,
522 gint visible_cells = 0;
523 gint n_expand_cells = 0;
525 for (l = group->cells; l; l = l->next)
527 CellInfo *info = l->data;
529 if (gtk_cell_renderer_get_visible (info->renderer))
539 *expand_cells = n_expand_cells;
541 return visible_cells;
545 count_expand_groups (GtkCellAreaBox *box)
547 GtkCellAreaBoxPrivate *priv = box->priv;
549 gint expand_groups = 0;
551 for (i = 0; i < priv->groups->len; i++)
553 CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
555 if (group->expand_cells > 0)
559 return expand_groups;
563 context_weak_notify (GtkCellAreaBox *box,
564 GtkCellAreaBoxContext *dead_context)
566 GtkCellAreaBoxPrivate *priv = box->priv;
568 priv->contexts = g_slist_remove (priv->contexts, dead_context);
572 init_context_group (GtkCellAreaBox *box,
573 GtkCellAreaBoxContext *context)
575 GtkCellAreaBoxPrivate *priv = box->priv;
576 gint *expand_groups, i;
578 expand_groups = g_new (gboolean, priv->groups->len);
580 for (i = 0; i < priv->groups->len; i++)
582 CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
584 expand_groups[i] = (group->expand_cells > 0);
587 /* This call implies reseting the request info */
588 gtk_cell_area_box_init_groups (context, priv->groups->len, expand_groups);
589 g_free (expand_groups);
593 init_context_groups (GtkCellAreaBox *box)
595 GtkCellAreaBoxPrivate *priv = box->priv;
598 /* When the box's groups are reconstructed, contexts need to
601 for (l = priv->contexts; l; l = l->next)
603 GtkCellAreaBoxContext *context = l->data;
605 init_context_group (box, context);
610 reset_contexts (GtkCellAreaBox *box)
612 GtkCellAreaBoxPrivate *priv = box->priv;
615 /* When the box layout changes, contexts need to
616 * be reset and sizes for the box get requested again
618 for (l = priv->contexts; l; l = l->next)
620 GtkCellAreaContext *context = l->data;
622 gtk_cell_area_context_reset (context);
626 /* Fall back on a completely unaligned dynamic allocation of cells
627 * when not allocated for the said orientation, alignment of cells
628 * is not done when each area gets a different size in the orientation
632 allocate_cells_manually (GtkCellAreaBox *box,
637 GtkCellAreaBoxPrivate *priv = box->priv;
639 GSList *allocated_cells = NULL;
640 GtkRequestedSize *sizes;
642 gint nvisible = 0, nexpand = 0, group_expand;
643 gint avail_size, extra_size, extra_extra, full_size;
644 gint position = 0, for_size;
650 /* For vertical oriented boxes, we just let the cell renderers realign themselves for rtl */
651 rtl = (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
652 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
654 cells = list_consecutive_cells (box);
656 /* Count the visible and expand cells */
657 for (i = 0; i < priv->groups->len; i++)
659 CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
661 nvisible += count_visible_cells (group, &group_expand);
662 nexpand += group_expand;
671 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
673 full_size = avail_size = width;
678 full_size = avail_size = height;
682 /* Go ahead and collect the requests on the fly */
683 sizes = g_new0 (GtkRequestedSize, nvisible);
684 for (l = cells, i = 0; l; l = l->next)
686 CellInfo *info = l->data;
688 if (!gtk_cell_renderer_get_visible (info->renderer))
691 gtk_cell_area_request_renderer (GTK_CELL_AREA (box), info->renderer,
694 &sizes[i].minimum_size,
695 &sizes[i].natural_size);
697 avail_size -= sizes[i].minimum_size;
699 sizes[i].data = info;
704 /* Naturally distribute the allocation */
705 avail_size -= (nvisible - 1) * priv->spacing;
707 avail_size = gtk_distribute_natural_allocation (avail_size, nvisible, sizes);
711 /* Calculate/distribute expand for cells */
714 extra_size = avail_size / nexpand;
715 extra_extra = avail_size % nexpand;
718 extra_size = extra_extra = 0;
720 /* Create the allocated cells */
721 for (i = 0; i < nvisible; i++)
723 CellInfo *info = sizes[i].data;
728 sizes[i].minimum_size += extra_size;
731 sizes[i].minimum_size++;
737 cell = allocated_cell_new (info->renderer,
738 full_size - (position + sizes[i].minimum_size),
739 sizes[i].minimum_size);
741 cell = allocated_cell_new (info->renderer, position, sizes[i].minimum_size);
743 allocated_cells = g_slist_prepend (allocated_cells, cell);
745 position += sizes[i].minimum_size;
746 position += priv->spacing;
752 /* Note it might not be important to reverse the list here at all,
753 * we have the correct positions, no need to allocate from left to right */
754 return g_slist_reverse (allocated_cells);
757 /* Returns an allocation for each cell in the orientation of the box,
758 * used in ->render()/->event() implementations to get a straight-forward
759 * list of allocated cells to operate on.
762 get_allocated_cells (GtkCellAreaBox *box,
763 GtkCellAreaBoxContext *context,
768 GtkCellAreaBoxAllocation *group_allocs;
769 GtkCellArea *area = GTK_CELL_AREA (box);
770 GtkCellAreaBoxPrivate *priv = box->priv;
772 GSList *allocated_cells = NULL;
774 gint for_size, full_size;
777 group_allocs = gtk_cell_area_box_context_get_orientation_allocs (context, &n_allocs);
779 return allocate_cells_manually (box, widget, width, height);
781 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
792 /* For vertical oriented boxes, we just let the cell renderers realign themselves for rtl */
793 rtl = (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
794 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
796 for (i = 0; i < n_allocs; i++)
798 /* We dont always allocate all groups, sometimes the requested group has only invisible
799 * cells for every row, hence the usage of group_allocs[i].group_idx here
801 CellGroup *group = &g_array_index (priv->groups, CellGroup, group_allocs[i].group_idx);
803 /* Exception for single cell groups */
804 if (group->n_cells == 1)
806 CellInfo *info = group->cells->data;
810 cell = allocated_cell_new (info->renderer,
811 full_size - (group_allocs[i].position + group_allocs[i].size),
812 group_allocs[i].size);
814 cell = allocated_cell_new (info->renderer, group_allocs[i].position, group_allocs[i].size);
816 allocated_cells = g_slist_prepend (allocated_cells, cell);
820 GtkRequestedSize *sizes;
821 gint avail_size, position;
822 gint visible_cells, expand_cells;
823 gint extra_size, extra_extra;
825 visible_cells = count_visible_cells (group, &expand_cells);
827 /* If this row has no visible cells in this group, just
828 * skip the allocation */
829 if (visible_cells == 0)
832 /* Offset the allocation to the group position and allocate into
833 * the group's available size */
834 position = group_allocs[i].position;
835 avail_size = group_allocs[i].size;
837 sizes = g_new (GtkRequestedSize, visible_cells);
839 for (j = 0, cell_list = group->cells; cell_list; cell_list = cell_list->next)
841 CellInfo *info = cell_list->data;
843 if (!gtk_cell_renderer_get_visible (info->renderer))
846 gtk_cell_area_request_renderer (area, info->renderer,
849 &sizes[j].minimum_size,
850 &sizes[j].natural_size);
852 sizes[j].data = info;
853 avail_size -= sizes[j].minimum_size;
858 /* Distribute cells naturally within the group */
859 avail_size -= (visible_cells - 1) * priv->spacing;
861 avail_size = gtk_distribute_natural_allocation (avail_size, visible_cells, sizes);
865 /* Calculate/distribute expand for cells */
866 if (expand_cells > 0)
868 extra_size = avail_size / expand_cells;
869 extra_extra = avail_size % expand_cells;
872 extra_size = extra_extra = 0;
874 /* Create the allocated cells (loop only over visible cells here) */
875 for (j = 0; j < visible_cells; j++)
877 CellInfo *info = sizes[j].data;
882 sizes[j].minimum_size += extra_size;
885 sizes[j].minimum_size++;
891 cell = allocated_cell_new (info->renderer,
892 full_size - (position + sizes[j].minimum_size),
893 sizes[j].minimum_size);
895 cell = allocated_cell_new (info->renderer, position, sizes[j].minimum_size);
897 allocated_cells = g_slist_prepend (allocated_cells, cell);
899 position += sizes[j].minimum_size;
900 position += priv->spacing;
907 /* Note it might not be important to reverse the list here at all,
908 * we have the correct positions, no need to allocate from left to right */
909 return g_slist_reverse (allocated_cells);
914 gtk_cell_area_box_focus_changed (GtkCellArea *area,
918 if (gtk_cell_area_get_focus_cell (area))
919 box->priv->last_focus_cell = gtk_cell_area_get_focus_cell (area);
922 /*************************************************************
924 *************************************************************/
926 gtk_cell_area_box_finalize (GObject *object)
928 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (object);
929 GtkCellAreaBoxPrivate *priv = box->priv;
932 /* Unref/free the context list */
933 for (l = priv->contexts; l; l = l->next)
934 g_object_weak_unref (G_OBJECT (l->data), (GWeakNotify)context_weak_notify, box);
936 g_slist_free (priv->contexts);
937 priv->contexts = NULL;
939 /* Free the cell grouping info */
940 cell_groups_clear (box);
941 g_array_free (priv->groups, TRUE);
943 G_OBJECT_CLASS (gtk_cell_area_box_parent_class)->finalize (object);
947 gtk_cell_area_box_dispose (GObject *object)
949 G_OBJECT_CLASS (gtk_cell_area_box_parent_class)->dispose (object);
953 gtk_cell_area_box_set_property (GObject *object,
958 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (object);
962 case PROP_ORIENTATION:
963 box->priv->orientation = g_value_get_enum (value);
965 /* Notify that size needs to be requested again */
966 reset_contexts (box);
969 gtk_cell_area_box_set_spacing (box, g_value_get_int (value));
972 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
978 gtk_cell_area_box_get_property (GObject *object,
983 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (object);
987 case PROP_ORIENTATION:
988 g_value_set_enum (value, box->priv->orientation);
991 g_value_set_int (value, gtk_cell_area_box_get_spacing (box));
994 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
999 /*************************************************************
1000 * GtkCellAreaClass *
1001 *************************************************************/
1003 gtk_cell_area_box_add (GtkCellArea *area,
1004 GtkCellRenderer *renderer)
1006 gtk_cell_area_box_pack_start (GTK_CELL_AREA_BOX (area),
1007 renderer, FALSE, TRUE);
1011 gtk_cell_area_box_remove (GtkCellArea *area,
1012 GtkCellRenderer *renderer)
1014 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1015 GtkCellAreaBoxPrivate *priv = box->priv;
1018 if (priv->last_focus_cell == renderer)
1019 priv->last_focus_cell = NULL;
1021 node = g_list_find_custom (priv->cells, renderer,
1022 (GCompareFunc)cell_info_find);
1026 CellInfo *info = node->data;
1028 cell_info_free (info);
1030 priv->cells = g_list_delete_link (priv->cells, node);
1032 /* Reconstruct cell groups */
1033 cell_groups_rebuild (box);
1036 g_warning ("Trying to remove a cell renderer that is not present GtkCellAreaBox");
1040 gtk_cell_area_box_foreach (GtkCellArea *area,
1041 GtkCellCallback callback,
1042 gpointer callback_data)
1044 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1045 GtkCellAreaBoxPrivate *priv = box->priv;
1048 for (list = priv->cells; list; list = list->next)
1050 CellInfo *info = list->data;
1052 if (callback (info->renderer, callback_data))
1058 gtk_cell_area_box_foreach_alloc (GtkCellArea *area,
1059 GtkCellAreaContext *context,
1061 const GdkRectangle *cell_area,
1062 const GdkRectangle *background_area,
1063 GtkCellAllocCallback callback,
1064 gpointer callback_data)
1066 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1067 GtkCellAreaBoxPrivate *priv = box->priv;
1068 GtkCellAreaBoxContext *box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
1069 GSList *allocated_cells, *l;
1070 GdkRectangle cell_alloc, cell_background;
1073 rtl = (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
1074 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1076 cell_alloc = *cell_area;
1078 /* Get a list of cells with allocation sizes decided regardless
1079 * of alignments and pack order etc. */
1080 allocated_cells = get_allocated_cells (box, box_context, widget,
1081 cell_area->width, cell_area->height);
1083 for (l = allocated_cells; l; l = l->next)
1085 AllocatedCell *cell = l->data;
1087 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1089 cell_alloc.x = cell_area->x + cell->position;
1090 cell_alloc.width = cell->size;
1094 cell_alloc.y = cell_area->y + cell->position;
1095 cell_alloc.height = cell->size;
1098 /* Stop iterating over cells if they flow out of the render area,
1099 * this can happen because the render area can actually be
1100 * smaller than the requested area (treeview columns can
1101 * be user resizable and can be resized to be smaller than
1102 * the actual requested area). */
1103 if (cell_alloc.x > cell_area->x + cell_area->width ||
1104 cell_alloc.x + cell_alloc.width < cell_area->x ||
1105 cell_alloc.y > cell_area->y + cell_area->height)
1108 /* Special case for the last cell (or first cell in rtl)... let the last cell consume
1109 * the remaining space in the area (the last cell is allowed to consume the remaining
1110 * space if the space given for rendering is actually larger than allocation, this can
1111 * happen in the expander GtkTreeViewColumn where only the deepest depth column
1112 * receives the allocation... shallow columns recieve more width). */
1117 /* Fill the leading space for the first cell in the area (still last in the list) */
1118 cell_alloc.width = (cell_alloc.x - cell_area->x) + cell_alloc.width;
1119 cell_alloc.x = cell_area->x;
1123 cell_alloc.width = cell_area->x + cell_area->width - cell_alloc.x;
1124 cell_alloc.height = cell_area->y + cell_area->height - cell_alloc.y;
1129 /* If the cell we are rendering doesnt fit into the remaining space, clip it
1130 * so that the underlying renderer has a chance to deal with it (for instance
1131 * text renderers get a chance to ellipsize).
1133 if (cell_alloc.x + cell_alloc.width > cell_area->x + cell_area->width)
1134 cell_alloc.width = cell_area->x + cell_area->width - cell_alloc.x;
1136 if (cell_alloc.y + cell_alloc.height > cell_area->y + cell_area->height)
1137 cell_alloc.height = cell_area->y + cell_area->height - cell_alloc.y;
1140 /* Add portions of the background_area to the cell_alloc
1141 * to create the cell_background */
1142 cell_background = cell_alloc;
1144 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1146 if (l == allocated_cells)
1148 cell_background.width += cell_background.x - background_area->x;
1149 cell_background.x = background_area->x;
1152 if (l->next == NULL)
1153 cell_background.width =
1154 background_area->width - (cell_background.x - background_area->x);
1156 cell_background.y = background_area->y;
1157 cell_background.height = background_area->height;
1161 if (l == allocated_cells)
1163 cell_background.height += cell_background.y - background_area->y;
1164 cell_background.y = background_area->y;
1167 if (l->next == NULL)
1168 cell_background.height =
1169 background_area->height - (cell_background.y - background_area->y);
1171 cell_background.x = background_area->x;
1172 cell_background.width = background_area->width;
1175 if (callback (cell->renderer, &cell_alloc, &cell_background, callback_data))
1179 g_slist_foreach (allocated_cells, (GFunc)allocated_cell_free, NULL);
1180 g_slist_free (allocated_cells);
1184 gtk_cell_area_box_set_cell_property (GtkCellArea *area,
1185 GtkCellRenderer *renderer,
1187 const GValue *value,
1190 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1191 GtkCellAreaBoxPrivate *priv = box->priv;
1194 gboolean rebuild = FALSE;
1196 GtkPackType pack_type;
1198 node = g_list_find_custom (priv->cells, renderer,
1199 (GCompareFunc)cell_info_find);
1207 case CELL_PROP_EXPAND:
1208 val = g_value_get_boolean (value);
1210 if (info->expand != val)
1217 case CELL_PROP_ALIGN:
1218 val = g_value_get_boolean (value);
1220 if (info->align != val)
1227 case CELL_PROP_PACK_TYPE:
1228 pack_type = g_value_get_enum (value);
1230 if (info->pack != pack_type)
1232 info->pack = pack_type;
1237 GTK_CELL_AREA_WARN_INVALID_CELL_PROPERTY_ID (area, prop_id, pspec);
1241 /* Groups need to be rebuilt */
1243 cell_groups_rebuild (box);
1247 gtk_cell_area_box_get_cell_property (GtkCellArea *area,
1248 GtkCellRenderer *renderer,
1253 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1254 GtkCellAreaBoxPrivate *priv = box->priv;
1258 node = g_list_find_custom (priv->cells, renderer,
1259 (GCompareFunc)cell_info_find);
1267 case CELL_PROP_EXPAND:
1268 g_value_set_boolean (value, info->expand);
1271 case CELL_PROP_ALIGN:
1272 g_value_set_boolean (value, info->align);
1275 case CELL_PROP_PACK_TYPE:
1276 g_value_set_enum (value, info->pack);
1279 GTK_CELL_AREA_WARN_INVALID_CELL_PROPERTY_ID (area, prop_id, pspec);
1285 static GtkCellAreaContext *
1286 gtk_cell_area_box_create_context (GtkCellArea *area)
1288 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1289 GtkCellAreaBoxPrivate *priv = box->priv;
1290 GtkCellAreaContext *context =
1291 (GtkCellAreaContext *)g_object_new (GTK_TYPE_CELL_AREA_BOX_CONTEXT,
1292 "area", area, NULL);
1294 priv->contexts = g_slist_prepend (priv->contexts, context);
1296 g_object_weak_ref (G_OBJECT (context), (GWeakNotify)context_weak_notify, box);
1298 /* Tell the new group about our cell layout */
1299 init_context_group (box, GTK_CELL_AREA_BOX_CONTEXT (context));
1304 static GtkSizeRequestMode
1305 gtk_cell_area_box_get_request_mode (GtkCellArea *area)
1307 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1308 GtkCellAreaBoxPrivate *priv = box->priv;
1310 return (priv->orientation) == GTK_ORIENTATION_HORIZONTAL ?
1311 GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH :
1312 GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT;
1316 compute_size (GtkCellAreaBox *box,
1317 GtkOrientation orientation,
1318 GtkCellAreaBoxContext *context,
1324 GtkCellAreaBoxPrivate *priv = box->priv;
1325 GtkCellArea *area = GTK_CELL_AREA (box);
1331 for (i = 0; i < priv->groups->len; i++)
1333 CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
1334 gint group_min_size = 0;
1335 gint group_nat_size = 0;
1337 for (list = group->cells; list; list = list->next)
1339 CellInfo *info = list->data;
1340 gint renderer_min_size, renderer_nat_size;
1342 if (!gtk_cell_renderer_get_visible (info->renderer))
1345 gtk_cell_area_request_renderer (area, info->renderer, orientation, widget, for_size,
1346 &renderer_min_size, &renderer_nat_size);
1348 if (orientation == priv->orientation)
1352 min_size += priv->spacing;
1353 nat_size += priv->spacing;
1356 if (group_min_size > 0)
1358 group_min_size += priv->spacing;
1359 group_nat_size += priv->spacing;
1362 min_size += renderer_min_size;
1363 nat_size += renderer_nat_size;
1364 group_min_size += renderer_min_size;
1365 group_nat_size += renderer_nat_size;
1369 min_size = MAX (min_size, renderer_min_size);
1370 nat_size = MAX (nat_size, renderer_nat_size);
1371 group_min_size = MAX (group_min_size, renderer_min_size);
1372 group_nat_size = MAX (group_nat_size, renderer_nat_size);
1376 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1379 gtk_cell_area_box_context_push_group_width (context, group->id, group_min_size, group_nat_size);
1381 gtk_cell_area_box_context_push_group_width_for_height (context, group->id, for_size,
1382 group_min_size, group_nat_size);
1387 gtk_cell_area_box_context_push_group_height (context, group->id, group_min_size, group_nat_size);
1389 gtk_cell_area_box_context_push_group_height_for_width (context, group->id, for_size,
1390 group_min_size, group_nat_size);
1394 *minimum_size = min_size;
1395 *natural_size = nat_size;
1397 /* Update rtl state for focus navigation to work */
1398 priv->rtl = (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
1399 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1403 get_group_sizes (GtkCellArea *area,
1405 GtkOrientation orientation,
1409 GtkRequestedSize *sizes;
1413 *n_sizes = count_visible_cells (group, NULL);
1414 sizes = g_new (GtkRequestedSize, *n_sizes);
1416 for (l = group->cells, i = 0; l; l = l->next)
1418 CellInfo *info = l->data;
1420 if (!gtk_cell_renderer_get_visible (info->renderer))
1423 sizes[i].data = info;
1425 gtk_cell_area_request_renderer (area, info->renderer,
1426 orientation, widget, -1,
1427 &sizes[i].minimum_size,
1428 &sizes[i].natural_size);
1437 compute_group_size_for_opposing_orientation (GtkCellAreaBox *box,
1444 GtkCellAreaBoxPrivate *priv = box->priv;
1445 GtkCellArea *area = GTK_CELL_AREA (box);
1447 /* Exception for single cell groups */
1448 if (group->n_cells == 1)
1450 CellInfo *info = group->cells->data;
1452 gtk_cell_area_request_renderer (area, info->renderer,
1453 OPPOSITE_ORIENTATION (priv->orientation),
1454 widget, for_size, minimum_size, natural_size);
1458 GtkRequestedSize *orientation_sizes;
1461 gint avail_size = for_size;
1462 gint extra_size, extra_extra;
1463 gint min_size = 0, nat_size = 0;
1465 orientation_sizes = get_group_sizes (area, group, priv->orientation, widget, &n_sizes);
1467 /* First naturally allocate the cells in the group into the for_size */
1468 avail_size -= (n_sizes - 1) * priv->spacing;
1469 for (i = 0; i < n_sizes; i++)
1470 avail_size -= orientation_sizes[i].minimum_size;
1473 avail_size = gtk_distribute_natural_allocation (avail_size, n_sizes, orientation_sizes);
1477 /* Calculate/distribute expand for cells */
1478 if (group->expand_cells > 0)
1480 extra_size = avail_size / group->expand_cells;
1481 extra_extra = avail_size % group->expand_cells;
1484 extra_size = extra_extra = 0;
1486 for (i = 0; i < n_sizes; i++)
1488 gint cell_min, cell_nat;
1490 info = orientation_sizes[i].data;
1494 orientation_sizes[i].minimum_size += extra_size;
1497 orientation_sizes[i].minimum_size++;
1502 gtk_cell_area_request_renderer (area, info->renderer,
1503 OPPOSITE_ORIENTATION (priv->orientation),
1505 orientation_sizes[i].minimum_size,
1506 &cell_min, &cell_nat);
1508 min_size = MAX (min_size, cell_min);
1509 nat_size = MAX (nat_size, cell_nat);
1512 *minimum_size = min_size;
1513 *natural_size = nat_size;
1515 g_free (orientation_sizes);
1520 compute_size_for_opposing_orientation (GtkCellAreaBox *box,
1521 GtkCellAreaBoxContext *context,
1527 GtkCellAreaBoxPrivate *priv = box->priv;
1529 GtkRequestedSize *orientation_sizes;
1530 gint n_groups, n_expand_groups, i;
1531 gint avail_size = for_size;
1532 gint extra_size, extra_extra;
1533 gint min_size = 0, nat_size = 0;
1535 n_expand_groups = count_expand_groups (box);
1537 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1538 orientation_sizes = gtk_cell_area_box_context_get_widths (context, &n_groups);
1540 orientation_sizes = gtk_cell_area_box_context_get_heights (context, &n_groups);
1542 /* First start by naturally allocating space among groups of cells */
1543 avail_size -= (n_groups - 1) * priv->spacing;
1544 for (i = 0; i < n_groups; i++)
1545 avail_size -= orientation_sizes[i].minimum_size;
1548 avail_size = gtk_distribute_natural_allocation (avail_size, n_groups, orientation_sizes);
1552 /* Calculate/distribute expand for groups */
1553 if (n_expand_groups > 0)
1555 extra_size = avail_size / n_expand_groups;
1556 extra_extra = avail_size % n_expand_groups;
1559 extra_size = extra_extra = 0;
1561 /* Now we need to naturally allocate sizes for cells in each group
1562 * and push the height-for-width for each group accordingly while accumulating
1563 * the overall height-for-width for this row.
1565 for (i = 0; i < n_groups; i++)
1567 gint group_min, group_nat;
1568 gint group_idx = GPOINTER_TO_INT (orientation_sizes[i].data);
1570 group = &g_array_index (priv->groups, CellGroup, group_idx);
1572 if (group->expand_cells > 0)
1574 orientation_sizes[i].minimum_size += extra_size;
1577 orientation_sizes[i].minimum_size++;
1582 /* Now we have the allocation for the group, request it's height-for-width */
1583 compute_group_size_for_opposing_orientation (box, group, widget,
1584 orientation_sizes[i].minimum_size,
1585 &group_min, &group_nat);
1587 min_size = MAX (min_size, group_min);
1588 nat_size = MAX (nat_size, group_nat);
1590 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1592 gtk_cell_area_box_context_push_group_height_for_width (context, group_idx, for_size,
1593 group_min, group_nat);
1597 gtk_cell_area_box_context_push_group_width_for_height (context, group_idx, for_size,
1598 group_min, group_nat);
1602 *minimum_size = min_size;
1603 *natural_size = nat_size;
1605 g_free (orientation_sizes);
1607 /* Update rtl state for focus navigation to work */
1608 priv->rtl = (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
1609 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1615 gtk_cell_area_box_get_preferred_width (GtkCellArea *area,
1616 GtkCellAreaContext *context,
1618 gint *minimum_width,
1619 gint *natural_width)
1621 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1622 GtkCellAreaBoxContext *box_context;
1623 gint min_width, nat_width;
1625 g_return_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (context));
1627 box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
1629 /* Compute the size of all renderers for current row data,
1630 * bumping cell alignments in the context along the way */
1631 compute_size (box, GTK_ORIENTATION_HORIZONTAL,
1632 box_context, widget, -1, &min_width, &nat_width);
1635 *minimum_width = min_width;
1638 *natural_width = nat_width;
1642 gtk_cell_area_box_get_preferred_height (GtkCellArea *area,
1643 GtkCellAreaContext *context,
1645 gint *minimum_height,
1646 gint *natural_height)
1648 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1649 GtkCellAreaBoxContext *box_context;
1650 gint min_height, nat_height;
1652 g_return_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (context));
1654 box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
1656 /* Compute the size of all renderers for current row data,
1657 * bumping cell alignments in the context along the way */
1658 compute_size (box, GTK_ORIENTATION_VERTICAL,
1659 box_context, widget, -1, &min_height, &nat_height);
1662 *minimum_height = min_height;
1665 *natural_height = nat_height;
1669 gtk_cell_area_box_get_preferred_height_for_width (GtkCellArea *area,
1670 GtkCellAreaContext *context,
1673 gint *minimum_height,
1674 gint *natural_height)
1676 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1677 GtkCellAreaBoxContext *box_context;
1678 GtkCellAreaBoxPrivate *priv;
1679 gint min_height, nat_height;
1681 g_return_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (context));
1683 box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
1686 if (priv->orientation == GTK_ORIENTATION_VERTICAL)
1688 /* Add up vertical requests of height for width and push the overall
1689 * cached sizes for alignments */
1690 compute_size (box, priv->orientation, box_context, widget, width, &min_height, &nat_height);
1694 /* Juice: virtually allocate cells into the for_width using the
1695 * alignments and then return the overall height for that width, and cache it */
1696 compute_size_for_opposing_orientation (box, box_context, widget, width, &min_height, &nat_height);
1700 *minimum_height = min_height;
1703 *natural_height = nat_height;
1707 gtk_cell_area_box_get_preferred_width_for_height (GtkCellArea *area,
1708 GtkCellAreaContext *context,
1711 gint *minimum_width,
1712 gint *natural_width)
1714 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1715 GtkCellAreaBoxContext *box_context;
1716 GtkCellAreaBoxPrivate *priv;
1717 gint min_width, nat_width;
1719 g_return_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (context));
1721 box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
1724 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1726 /* Add up horizontal requests of width for height and push the overall
1727 * cached sizes for alignments */
1728 compute_size (box, priv->orientation, box_context, widget, height, &min_width, &nat_width);
1732 /* Juice: horizontally allocate cells into the for_height using the
1733 * alignments and then return the overall width for that height, and cache it */
1734 compute_size_for_opposing_orientation (box, box_context, widget, height, &min_width, &nat_width);
1738 *minimum_width = min_width;
1741 *natural_width = nat_width;
1752 gtk_cell_area_box_focus (GtkCellArea *area,
1753 GtkDirectionType direction)
1755 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1756 GtkCellAreaBoxPrivate *priv = box->priv;
1757 gint cycle = FOCUS_NONE;
1758 gboolean cycled_focus = FALSE;
1759 GtkCellRenderer *focus_cell;
1761 focus_cell = gtk_cell_area_get_focus_cell (area);
1763 /* Special case, when there is no activatable cell, focus
1764 * is painted around the entire area... in this case we
1765 * let focus leave the area directly.
1767 if (focus_cell && !gtk_cell_area_is_activatable (area))
1769 gtk_cell_area_set_focus_cell (area, NULL);
1775 case GTK_DIR_TAB_FORWARD:
1776 cycle = priv->rtl ? FOCUS_PREV : FOCUS_NEXT;
1778 case GTK_DIR_TAB_BACKWARD:
1779 cycle = priv->rtl ? FOCUS_NEXT : FOCUS_PREV;
1782 if (priv->orientation == GTK_ORIENTATION_VERTICAL || !priv->last_focus_cell)
1784 else if (!focus_cell)
1785 cycle = FOCUS_LAST_CELL;
1788 if (priv->orientation == GTK_ORIENTATION_VERTICAL || !priv->last_focus_cell)
1790 else if (!focus_cell)
1791 cycle = FOCUS_LAST_CELL;
1794 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL || !priv->last_focus_cell)
1795 cycle = priv->rtl ? FOCUS_NEXT : FOCUS_PREV;
1796 else if (!focus_cell)
1797 cycle = FOCUS_LAST_CELL;
1800 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL || !priv->last_focus_cell)
1801 cycle = priv->rtl ? FOCUS_PREV : FOCUS_NEXT;
1802 else if (!focus_cell)
1803 cycle = FOCUS_LAST_CELL;
1809 if (cycle == FOCUS_LAST_CELL)
1811 gtk_cell_area_set_focus_cell (area, priv->last_focus_cell);
1812 cycled_focus = TRUE;
1814 else if (cycle != FOCUS_NONE)
1816 gboolean found_cell = FALSE;
1820 /* If there is no focused cell, focus on the first (or last) one in the list */
1824 for (i = (cycle == FOCUS_NEXT) ? 0 : priv->groups->len -1;
1825 cycled_focus == FALSE && i >= 0 && i < priv->groups->len;
1826 i = (cycle == FOCUS_NEXT) ? i + 1 : i - 1)
1828 CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
1830 for (list = (cycle == FOCUS_NEXT) ? g_list_first (group->cells) : g_list_last (group->cells);
1831 cycled_focus == FALSE && list; list = (cycle == FOCUS_NEXT) ? list->next : list->prev)
1833 CellInfo *info = list->data;
1835 if (info->renderer == focus_cell)
1837 else if (found_cell && /* Dont give focus to cells that are siblings to a focus cell */
1838 gtk_cell_area_get_focus_from_sibling (area, info->renderer) == NULL)
1840 gtk_cell_area_set_focus_cell (area, info->renderer);
1841 cycled_focus = TRUE;
1848 gtk_cell_area_set_focus_cell (area, NULL);
1850 return cycled_focus;
1854 /*************************************************************
1855 * GtkCellLayoutIface *
1856 *************************************************************/
1858 gtk_cell_area_box_cell_layout_init (GtkCellLayoutIface *iface)
1860 iface->pack_start = gtk_cell_area_box_layout_pack_start;
1861 iface->pack_end = gtk_cell_area_box_layout_pack_end;
1862 iface->reorder = gtk_cell_area_box_layout_reorder;
1866 gtk_cell_area_box_layout_pack_start (GtkCellLayout *cell_layout,
1867 GtkCellRenderer *renderer,
1870 gtk_cell_area_box_pack_start (GTK_CELL_AREA_BOX (cell_layout), renderer, expand, TRUE);
1874 gtk_cell_area_box_layout_pack_end (GtkCellLayout *cell_layout,
1875 GtkCellRenderer *renderer,
1878 gtk_cell_area_box_pack_end (GTK_CELL_AREA_BOX (cell_layout), renderer, expand, TRUE);
1882 gtk_cell_area_box_layout_reorder (GtkCellLayout *cell_layout,
1883 GtkCellRenderer *renderer,
1886 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (cell_layout);
1887 GtkCellAreaBoxPrivate *priv = box->priv;
1891 node = g_list_find_custom (priv->cells, renderer,
1892 (GCompareFunc)cell_info_find);
1898 priv->cells = g_list_delete_link (priv->cells, node);
1899 priv->cells = g_list_insert (priv->cells, info, position);
1901 cell_groups_rebuild (box);
1905 /*************************************************************
1907 *************************************************************/
1909 * gtk_cell_area_box_new:
1911 * Creates a new #GtkCellAreaBox.
1913 * Return value: a newly created #GtkCellAreaBox
1916 gtk_cell_area_box_new (void)
1918 return (GtkCellArea *)g_object_new (GTK_TYPE_CELL_AREA_BOX, NULL);
1922 * gtk_cell_area_box_pack_start:
1923 * @box: a #GtkCellAreaBox
1924 * @renderer: the #GtkCellRenderer to add
1925 * @expand: whether @renderer should receive extra space when the area receives
1926 * more than its natural size
1927 * @align: whether @renderer should be aligned in adjacent rows.
1929 * Adds @renderer to @box, packed with reference to the start of @box.
1931 * The @renderer is packed after any other #GtkCellRenderer packed with reference
1932 * to the start of @box.
1937 gtk_cell_area_box_pack_start (GtkCellAreaBox *box,
1938 GtkCellRenderer *renderer,
1942 GtkCellAreaBoxPrivate *priv;
1945 g_return_if_fail (GTK_IS_CELL_AREA_BOX (box));
1946 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1950 if (g_list_find_custom (priv->cells, renderer,
1951 (GCompareFunc)cell_info_find))
1953 g_warning ("Refusing to add the same cell renderer to a GtkCellAreaBox twice");
1957 info = cell_info_new (renderer, GTK_PACK_START, expand, align);
1959 priv->cells = g_list_append (priv->cells, info);
1961 cell_groups_rebuild (box);
1965 * gtk_cell_area_box_pack_end:
1966 * @box: a #GtkCellAreaBox
1967 * @renderer: the #GtkCellRenderer to add
1968 * @expand: whether @renderer should receive extra space when the area receives
1969 * more than its natural size
1970 * @align: whether @renderer should be aligned in adjacent rows.
1972 * Adds @renderer to @box, packed with reference to the end of @box.
1974 * The @renderer is packed after (away from end of) any other #GtkCellRenderer
1975 * packed with reference to the end of @box.
1980 gtk_cell_area_box_pack_end (GtkCellAreaBox *box,
1981 GtkCellRenderer *renderer,
1985 GtkCellAreaBoxPrivate *priv;
1988 g_return_if_fail (GTK_IS_CELL_AREA_BOX (box));
1989 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1993 if (g_list_find_custom (priv->cells, renderer,
1994 (GCompareFunc)cell_info_find))
1996 g_warning ("Refusing to add the same cell renderer to a GtkCellArea twice");
2000 info = cell_info_new (renderer, GTK_PACK_END, expand, align);
2002 priv->cells = g_list_append (priv->cells, info);
2004 cell_groups_rebuild (box);
2008 * gtk_cell_area_box_get_spacing:
2009 * @box: a #GtkCellAreaBox
2011 * Gets the spacing added between cell renderers.
2013 * Return value: the space added between cell renderers in @box.
2018 gtk_cell_area_box_get_spacing (GtkCellAreaBox *box)
2020 g_return_val_if_fail (GTK_IS_CELL_AREA_BOX (box), 0);
2022 return box->priv->spacing;
2026 * gtk_cell_area_box_set_spacing:
2027 * @box: a #GtkCellAreaBox
2028 * @spacing: the space to add between #GtkCellRenderers
2030 * Sets the spacing to add between cell renderers in @box.
2035 gtk_cell_area_box_set_spacing (GtkCellAreaBox *box,
2038 GtkCellAreaBoxPrivate *priv;
2040 g_return_if_fail (GTK_IS_CELL_AREA_BOX (box));
2044 if (priv->spacing != spacing)
2046 priv->spacing = spacing;
2048 g_object_notify (G_OBJECT (box), "spacing");
2050 /* Notify that size needs to be requested again */
2051 reset_contexts (box);