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 void gtk_cell_area_box_get_cell_allocation (GtkCellArea *area,
54 GtkCellAreaIter *iter,
56 GtkCellRenderer *renderer,
57 const GdkRectangle *cell_area,
58 GdkRectangle *allocation);
59 static gint gtk_cell_area_box_event (GtkCellArea *area,
60 GtkCellAreaIter *iter,
63 const GdkRectangle *cell_area,
64 GtkCellRendererState flags);
65 static void gtk_cell_area_box_render (GtkCellArea *area,
66 GtkCellAreaIter *iter,
69 const GdkRectangle *background_area,
70 const GdkRectangle *cell_area,
71 GtkCellRendererState flags,
72 gboolean paint_focus);
73 static void gtk_cell_area_box_set_cell_property (GtkCellArea *area,
74 GtkCellRenderer *renderer,
78 static void gtk_cell_area_box_get_cell_property (GtkCellArea *area,
79 GtkCellRenderer *renderer,
83 static GtkCellAreaIter *gtk_cell_area_box_create_iter (GtkCellArea *area);
84 static GtkSizeRequestMode gtk_cell_area_box_get_request_mode (GtkCellArea *area);
85 static void gtk_cell_area_box_get_preferred_width (GtkCellArea *area,
86 GtkCellAreaIter *iter,
90 static void gtk_cell_area_box_get_preferred_height (GtkCellArea *area,
91 GtkCellAreaIter *iter,
94 gint *natural_height);
95 static void gtk_cell_area_box_get_preferred_height_for_width (GtkCellArea *area,
96 GtkCellAreaIter *iter,
100 gint *natural_height);
101 static void gtk_cell_area_box_get_preferred_width_for_height (GtkCellArea *area,
102 GtkCellAreaIter *iter,
106 gint *natural_width);
107 static gboolean gtk_cell_area_box_focus (GtkCellArea *area,
108 GtkDirectionType direction);
110 /* GtkCellLayoutIface */
111 static void gtk_cell_area_box_cell_layout_init (GtkCellLayoutIface *iface);
112 static void gtk_cell_area_box_layout_pack_start (GtkCellLayout *cell_layout,
113 GtkCellRenderer *renderer,
115 static void gtk_cell_area_box_layout_pack_end (GtkCellLayout *cell_layout,
116 GtkCellRenderer *renderer,
118 static void gtk_cell_area_box_layout_reorder (GtkCellLayout *cell_layout,
119 GtkCellRenderer *renderer,
123 /* CellInfo/CellGroup metadata handling and convenience functions */
125 GtkCellRenderer *renderer;
127 guint expand : 1; /* Whether the cell expands */
128 guint pack : 1; /* Whether the cell is packed from the start or end */
129 guint align : 1; /* Whether to align this cell's position with adjacent rows */
137 guint expand_cells : 8;
141 GtkCellRenderer *renderer;
147 static CellInfo *cell_info_new (GtkCellRenderer *renderer,
151 static void cell_info_free (CellInfo *info);
152 static gint cell_info_find (CellInfo *info,
153 GtkCellRenderer *renderer);
155 static AllocatedCell *allocated_cell_new (GtkCellRenderer *renderer,
158 static void allocated_cell_free (AllocatedCell *cell);
159 static GList *list_consecutive_cells (GtkCellAreaBox *box);
160 static gint count_expand_groups (GtkCellAreaBox *box);
161 static void iter_weak_notify (GtkCellAreaBox *box,
162 GtkCellAreaBoxIter *dead_iter);
163 static void flush_iters (GtkCellAreaBox *box);
164 static void init_iter_groups (GtkCellAreaBox *box);
165 static void init_iter_group (GtkCellAreaBox *box,
166 GtkCellAreaBoxIter *iter);
167 static GSList *get_allocated_cells (GtkCellAreaBox *box,
168 GtkCellAreaBoxIter *iter,
172 struct _GtkCellAreaBoxPrivate
174 GtkOrientation orientation;
197 G_DEFINE_TYPE_WITH_CODE (GtkCellAreaBox, gtk_cell_area_box, GTK_TYPE_CELL_AREA,
198 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
199 gtk_cell_area_box_cell_layout_init)
200 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL));
202 #define OPPOSITE_ORIENTATION(orientation) \
203 ((orientation) == GTK_ORIENTATION_HORIZONTAL ? \
204 GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL)
207 gtk_cell_area_box_init (GtkCellAreaBox *box)
209 GtkCellAreaBoxPrivate *priv;
211 box->priv = G_TYPE_INSTANCE_GET_PRIVATE (box,
212 GTK_TYPE_CELL_AREA_BOX,
213 GtkCellAreaBoxPrivate);
216 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
217 priv->groups = g_array_new (FALSE, TRUE, sizeof (CellGroup));
224 gtk_cell_area_box_class_init (GtkCellAreaBoxClass *class)
226 GObjectClass *object_class = G_OBJECT_CLASS (class);
227 GtkCellAreaClass *area_class = GTK_CELL_AREA_CLASS (class);
230 object_class->finalize = gtk_cell_area_box_finalize;
231 object_class->dispose = gtk_cell_area_box_dispose;
232 object_class->set_property = gtk_cell_area_box_set_property;
233 object_class->get_property = gtk_cell_area_box_get_property;
235 /* GtkCellAreaClass */
236 area_class->add = gtk_cell_area_box_add;
237 area_class->remove = gtk_cell_area_box_remove;
238 area_class->forall = gtk_cell_area_box_forall;
239 area_class->get_cell_allocation = gtk_cell_area_box_get_cell_allocation;
240 area_class->event = gtk_cell_area_box_event;
241 area_class->render = gtk_cell_area_box_render;
242 area_class->set_cell_property = gtk_cell_area_box_set_cell_property;
243 area_class->get_cell_property = gtk_cell_area_box_get_cell_property;
245 area_class->create_iter = gtk_cell_area_box_create_iter;
246 area_class->get_request_mode = gtk_cell_area_box_get_request_mode;
247 area_class->get_preferred_width = gtk_cell_area_box_get_preferred_width;
248 area_class->get_preferred_height = gtk_cell_area_box_get_preferred_height;
249 area_class->get_preferred_height_for_width = gtk_cell_area_box_get_preferred_height_for_width;
250 area_class->get_preferred_width_for_height = gtk_cell_area_box_get_preferred_width_for_height;
252 area_class->focus = gtk_cell_area_box_focus;
255 g_object_class_override_property (object_class, PROP_ORIENTATION, "orientation");
257 g_object_class_install_property (object_class,
259 g_param_spec_int ("spacing",
261 P_("Space which is inserted between cells"),
265 GTK_PARAM_READWRITE));
267 /* Cell Properties */
268 gtk_cell_area_class_install_cell_property (area_class,
273 P_("Whether the cell expands"),
275 GTK_PARAM_READWRITE));
277 gtk_cell_area_class_install_cell_property (area_class,
282 P_("Whether cell should align with adjacent rows"),
284 GTK_PARAM_READWRITE));
286 gtk_cell_area_class_install_cell_property (area_class,
291 P_("A GtkPackType indicating whether the cell is packed with "
292 "reference to the start or end of the cell area"),
293 GTK_TYPE_PACK_TYPE, GTK_PACK_START,
294 GTK_PARAM_READWRITE));
296 g_type_class_add_private (object_class, sizeof (GtkCellAreaBoxPrivate));
300 /*************************************************************
301 * CellInfo/CellGroup basics and convenience functions *
302 *************************************************************/
304 cell_info_new (GtkCellRenderer *renderer,
309 CellInfo *info = g_slice_new (CellInfo);
311 info->renderer = g_object_ref_sink (renderer);
313 info->expand = expand;
320 cell_info_free (CellInfo *info)
322 g_object_unref (info->renderer);
324 g_slice_free (CellInfo, info);
328 cell_info_find (CellInfo *info,
329 GtkCellRenderer *renderer)
331 return (info->renderer == renderer) ? 0 : -1;
334 static AllocatedCell *
335 allocated_cell_new (GtkCellRenderer *renderer,
339 AllocatedCell *cell = g_slice_new (AllocatedCell);
341 cell->renderer = renderer;
342 cell->position = position;
349 allocated_cell_free (AllocatedCell *cell)
351 g_slice_free (AllocatedCell, cell);
355 list_consecutive_cells (GtkCellAreaBox *box)
357 GtkCellAreaBoxPrivate *priv = box->priv;
358 GList *l, *consecutive_cells = NULL, *pack_end_cells = NULL;
361 /* List cells in consecutive order taking their
362 * PACK_START/PACK_END options into account
364 for (l = priv->cells; l; l = l->next)
368 if (info->pack == GTK_PACK_START)
369 consecutive_cells = g_list_prepend (consecutive_cells, info);
372 for (l = priv->cells; l; l = l->next)
376 if (info->pack == GTK_PACK_END)
377 pack_end_cells = g_list_prepend (pack_end_cells, info);
380 consecutive_cells = g_list_reverse (consecutive_cells);
381 consecutive_cells = g_list_concat (consecutive_cells, pack_end_cells);
383 return consecutive_cells;
387 cell_groups_clear (GtkCellAreaBox *box)
389 GtkCellAreaBoxPrivate *priv = box->priv;
392 for (i = 0; i < priv->groups->len; i++)
394 CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
396 g_list_free (group->cells);
399 g_array_set_size (priv->groups, 0);
403 cell_groups_rebuild (GtkCellAreaBox *box)
405 GtkCellAreaBoxPrivate *priv = box->priv;
406 CellGroup group = { 0, };
407 CellGroup *group_ptr;
411 cell_groups_clear (box);
416 cells = list_consecutive_cells (box);
418 /* First group is implied */
419 g_array_append_val (priv->groups, group);
420 group_ptr = &g_array_index (priv->groups, CellGroup, id);
422 for (l = cells; l; l = l->next)
424 CellInfo *info = l->data;
426 /* A new group starts with any aligned cell, the first group is implied */
427 if (info->align && l != cells)
429 memset (&group, 0x0, sizeof (CellGroup));
432 g_array_append_val (priv->groups, group);
433 group_ptr = &g_array_index (priv->groups, CellGroup, id);
436 group_ptr->cells = g_list_prepend (group_ptr->cells, info);
437 group_ptr->n_cells++;
439 /* A group expands if it contains any expand cells */
441 group_ptr->expand_cells++;
446 for (id = 0; id < priv->groups->len; id++)
448 group_ptr = &g_array_index (priv->groups, CellGroup, id);
450 group_ptr->cells = g_list_reverse (group_ptr->cells);
453 /* Iters need to be updated with the new grouping information */
454 init_iter_groups (box);
458 count_visible_cells (CellGroup *group,
462 gint visible_cells = 0;
463 gint n_expand_cells = 0;
465 for (l = group->cells; l; l = l->next)
467 CellInfo *info = l->data;
469 if (gtk_cell_renderer_get_visible (info->renderer))
479 *expand_cells = n_expand_cells;
481 return visible_cells;
485 count_expand_groups (GtkCellAreaBox *box)
487 GtkCellAreaBoxPrivate *priv = box->priv;
489 gint expand_groups = 0;
491 for (i = 0; i < priv->groups->len; i++)
493 CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
495 if (group->expand_cells > 0)
499 return expand_groups;
503 iter_weak_notify (GtkCellAreaBox *box,
504 GtkCellAreaBoxIter *dead_iter)
506 GtkCellAreaBoxPrivate *priv = box->priv;
508 priv->iters = g_slist_remove (priv->iters, dead_iter);
512 init_iter_group (GtkCellAreaBox *box,
513 GtkCellAreaBoxIter *iter)
515 GtkCellAreaBoxPrivate *priv = box->priv;
516 gint *expand_groups, i;
518 expand_groups = g_new (gboolean, priv->groups->len);
520 for (i = 0; i < priv->groups->len; i++)
522 CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
524 expand_groups[i] = (group->expand_cells > 0);
527 /* This call implies flushing the request info */
528 gtk_cell_area_box_init_groups (iter, priv->groups->len, expand_groups);
529 g_free (expand_groups);
533 init_iter_groups (GtkCellAreaBox *box)
535 GtkCellAreaBoxPrivate *priv = box->priv;
538 /* When the box's groups are reconstructed, iters need to
541 for (l = priv->iters; l; l = l->next)
543 GtkCellAreaBoxIter *iter = l->data;
545 init_iter_group (box, iter);
550 flush_iters (GtkCellAreaBox *box)
552 GtkCellAreaBoxPrivate *priv = box->priv;
555 /* When the box layout changes, iters need to
556 * be flushed and sizes for the box get requested again
558 for (l = priv->iters; l; l = l->next)
560 GtkCellAreaIter *iter = l->data;
562 gtk_cell_area_iter_flush (iter);
566 /* Returns an allocation for each cell in the orientation of the box,
567 * used in ->render()/->event() implementations to get a straight-forward
568 * list of allocated cells to operate on.
571 get_allocated_cells (GtkCellAreaBox *box,
572 GtkCellAreaBoxIter *iter,
575 const GtkCellAreaBoxAllocation *group_allocs;
576 GtkCellArea *area = GTK_CELL_AREA (box);
577 GtkCellAreaBoxPrivate *priv = box->priv;
579 GSList *allocated_cells = NULL;
582 group_allocs = gtk_cell_area_box_iter_get_orientation_allocs (iter, &n_allocs);
585 g_warning ("Trying to operate on an unallocated GtkCellAreaIter, "
586 "GtkCellAreaBox requires that the iter be allocated at least "
587 "in the orientation of the box");
591 for (i = 0; i < n_allocs; i++)
593 /* We dont always allocate all groups, sometimes the requested group has only invisible
594 * cells for every row, hence the usage of group_allocs[i].group_idx here
596 CellGroup *group = &g_array_index (priv->groups, CellGroup, group_allocs[i].group_idx);
598 /* Exception for single cell groups */
599 if (group->n_cells == 1)
601 CellInfo *info = group->cells->data;
602 AllocatedCell *cell =
603 allocated_cell_new (info->renderer, group_allocs[i].position, group_allocs[i].size);
605 allocated_cells = g_slist_prepend (allocated_cells, cell);
609 GtkRequestedSize *sizes;
610 gint avail_size, position;
611 gint visible_cells, expand_cells;
612 gint extra_size, extra_extra;
614 visible_cells = count_visible_cells (group, &expand_cells);
616 /* If this row has no visible cells in this group, just
617 * skip the allocation */
618 if (visible_cells == 0)
621 /* Offset the allocation to the group position and allocate into
622 * the group's available size */
623 position = group_allocs[i].position;
624 avail_size = group_allocs[i].size;
626 sizes = g_new (GtkRequestedSize, visible_cells);
628 for (j = 0, cell_list = group->cells; cell_list; cell_list = cell_list->next)
630 CellInfo *info = cell_list->data;
632 if (!gtk_cell_renderer_get_visible (info->renderer))
635 gtk_cell_area_request_renderer (area, info->renderer,
638 &sizes[j].minimum_size,
639 &sizes[j].natural_size);
641 sizes[j].data = info;
642 avail_size -= sizes[j].minimum_size;
647 /* Distribute cells naturally within the group */
648 avail_size -= (visible_cells - 1) * priv->spacing;
649 avail_size = gtk_distribute_natural_allocation (avail_size, visible_cells, sizes);
651 /* Calculate/distribute expand for cells */
652 if (expand_cells > 0)
654 extra_size = avail_size / expand_cells;
655 extra_extra = avail_size % expand_cells;
658 extra_size = extra_extra = 0;
660 /* Create the allocated cells (loop only over visible cells here) */
661 for (j = 0; j < visible_cells; j++)
663 CellInfo *info = sizes[j].data;
668 sizes[j].minimum_size += extra_size;
671 sizes[j].minimum_size++;
676 cell = allocated_cell_new (info->renderer, position, sizes[j].minimum_size);
678 allocated_cells = g_slist_prepend (allocated_cells, cell);
680 position += sizes[j].minimum_size;
681 position += priv->spacing;
688 /* Note it might not be important to reverse the list here at all,
689 * we have the correct positions, no need to allocate from left to right */
690 return g_slist_reverse (allocated_cells);
693 /*************************************************************
695 *************************************************************/
697 gtk_cell_area_box_finalize (GObject *object)
699 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (object);
700 GtkCellAreaBoxPrivate *priv = box->priv;
703 /* Unref/free the iter list */
704 for (l = priv->iters; l; l = l->next)
705 g_object_weak_unref (G_OBJECT (l->data), (GWeakNotify)iter_weak_notify, box);
707 g_slist_free (priv->iters);
710 /* Free the cell grouping info */
711 cell_groups_clear (box);
712 g_array_free (priv->groups, TRUE);
714 G_OBJECT_CLASS (gtk_cell_area_box_parent_class)->finalize (object);
718 gtk_cell_area_box_dispose (GObject *object)
720 G_OBJECT_CLASS (gtk_cell_area_box_parent_class)->dispose (object);
724 gtk_cell_area_box_set_property (GObject *object,
729 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (object);
733 case PROP_ORIENTATION:
734 box->priv->orientation = g_value_get_enum (value);
736 /* Notify that size needs to be requested again */
740 gtk_cell_area_box_set_spacing (box, g_value_get_int (value));
743 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
749 gtk_cell_area_box_get_property (GObject *object,
754 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (object);
758 case PROP_ORIENTATION:
759 g_value_set_enum (value, box->priv->orientation);
762 g_value_set_int (value, gtk_cell_area_box_get_spacing (box));
765 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
770 /*************************************************************
772 *************************************************************/
774 gtk_cell_area_box_add (GtkCellArea *area,
775 GtkCellRenderer *renderer)
777 gtk_cell_area_box_pack_start (GTK_CELL_AREA_BOX (area),
778 renderer, FALSE, TRUE);
782 gtk_cell_area_box_remove (GtkCellArea *area,
783 GtkCellRenderer *renderer)
785 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
786 GtkCellAreaBoxPrivate *priv = box->priv;
789 node = g_list_find_custom (priv->cells, renderer,
790 (GCompareFunc)cell_info_find);
794 CellInfo *info = node->data;
796 cell_info_free (info);
798 priv->cells = g_list_delete_link (priv->cells, node);
800 /* Reconstruct cell groups */
801 cell_groups_rebuild (box);
804 g_warning ("Trying to remove a cell renderer that is not present GtkCellAreaBox");
808 gtk_cell_area_box_forall (GtkCellArea *area,
809 GtkCellCallback callback,
810 gpointer callback_data)
812 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
813 GtkCellAreaBoxPrivate *priv = box->priv;
816 for (list = priv->cells; list; list = list->next)
818 CellInfo *info = list->data;
820 callback (info->renderer, callback_data);
825 gtk_cell_area_box_get_cell_allocation (GtkCellArea *area,
826 GtkCellAreaIter *iter,
828 GtkCellRenderer *renderer,
829 const GdkRectangle *cell_area,
830 GdkRectangle *allocation)
832 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
833 GtkCellAreaBoxPrivate *priv = box->priv;
834 GtkCellAreaBoxIter *box_iter = GTK_CELL_AREA_BOX_ITER (iter);
835 GSList *allocated_cells, *l;
837 *allocation = *cell_area;
839 /* Get a list of cells with allocation sizes decided regardless
840 * of alignments and pack order etc. */
841 allocated_cells = get_allocated_cells (box, box_iter, widget);
843 for (l = allocated_cells; l; l = l->next)
845 AllocatedCell *cell = l->data;
847 if (cell->renderer == renderer)
849 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
851 allocation->x = cell_area->x + cell->position;
852 allocation->width = cell->size;
856 allocation->y = cell_area->y + cell->position;
857 allocation->height = cell->size;
864 g_slist_foreach (allocated_cells, (GFunc)allocated_cell_free, NULL);
865 g_slist_free (allocated_cells);
875 gtk_cell_area_box_event (GtkCellArea *area,
876 GtkCellAreaIter *iter,
879 const GdkRectangle *cell_area,
880 GtkCellRendererState flags)
884 /* First let the parent class handle activation of cells via keystrokes */
886 GTK_CELL_AREA_CLASS (gtk_cell_area_box_parent_class)->event (area, iter, widget,
887 event, cell_area, flags);
892 /* Also detect mouse events, for mouse events we need to allocate the renderers
893 * and find which renderer needs to be activated.
895 if (event->type == GDK_BUTTON_PRESS)
897 GdkEventButton *button_event = (GdkEventButton *)event;
899 if (button_event->button == 1)
901 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
902 GtkCellAreaBoxPrivate *priv = box->priv;
903 GtkCellAreaBoxIter *box_iter = GTK_CELL_AREA_BOX_ITER (iter);
904 GSList *allocated_cells, *l;
905 GdkRectangle cell_background, inner_area;
906 GtkAllocation allocation;
907 gint event_x, event_y;
909 gtk_widget_get_allocation (widget, &allocation);
911 /* We may need some semantics to tell us the offset of the event
912 * window we are handling events for (i.e. GtkTreeView has a bin_window) */
913 event_x = button_event->x;
914 event_y = button_event->y;
916 cell_background = *cell_area;
918 /* Get a list of cells with allocation sizes decided regardless
919 * of alignments and pack order etc. */
920 allocated_cells = get_allocated_cells (box, box_iter, widget);
922 for (l = allocated_cells; l; l = l->next)
924 AllocatedCell *cell = l->data;
926 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
928 cell_background.x = cell_area->x + cell->position;
929 cell_background.width = cell->size;
933 cell_background.y = cell_area->y + cell->position;
934 cell_background.height = cell->size;
937 /* Remove margins from the background area to produce the cell area
939 gtk_cell_area_inner_cell_area (area, &cell_background, &inner_area);
941 if (event_x >= inner_area.x && event_x <= inner_area.x + inner_area.width &&
942 event_y >= inner_area.y && event_y <= inner_area.y + inner_area.height)
944 GtkCellRenderer *event_renderer = NULL;
946 if (gtk_cell_renderer_can_focus (cell->renderer))
947 event_renderer = cell->renderer;
950 GtkCellRenderer *focus_renderer;
952 /* A renderer can have focus siblings but that renderer might not be
953 * focusable for every row... so we go on to check can_focus here. */
954 focus_renderer = gtk_cell_area_get_focus_from_sibling (area, cell->renderer);
956 if (focus_renderer && gtk_cell_renderer_can_focus (focus_renderer))
957 event_renderer = focus_renderer;
962 if (gtk_cell_area_get_edited_cell (area))
964 /* XXX Was it really canceled in this case ? */
965 gtk_cell_area_stop_editing (area, TRUE);
966 gtk_cell_area_set_focus_cell (area, event_renderer);
971 /* If we are activating via a focus sibling, we need to fix the
973 if (event_renderer != cell->renderer)
974 gtk_cell_area_inner_cell_area (area, cell_area, &cell_background);
976 gtk_cell_area_set_focus_cell (area, event_renderer);
978 retval = gtk_cell_area_activate_cell (area, widget, event_renderer,
979 event, &cell_background, flags);
985 g_slist_foreach (allocated_cells, (GFunc)allocated_cell_free, NULL);
986 g_slist_free (allocated_cells);
994 gtk_cell_area_box_render (GtkCellArea *area,
995 GtkCellAreaIter *iter,
998 const GdkRectangle *background_area,
999 const GdkRectangle *cell_area,
1000 GtkCellRendererState flags,
1001 gboolean paint_focus)
1003 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1004 GtkCellAreaBoxPrivate *priv = box->priv;
1005 GtkCellAreaBoxIter *box_iter = GTK_CELL_AREA_BOX_ITER (iter);
1006 GSList *allocated_cells, *l;
1007 GdkRectangle cell_background, inner_area;
1008 GtkCellRenderer *focus_cell = NULL;
1009 GdkRectangle focus_rect = { 0, };
1010 gboolean first_focus_cell = TRUE;
1012 if (flags & GTK_CELL_RENDERER_FOCUSED)
1014 focus_cell = gtk_cell_area_get_focus_cell (area);
1015 flags &= ~GTK_CELL_RENDERER_FOCUSED;
1018 cell_background = *cell_area;
1020 /* Get a list of cells with allocation sizes decided regardless
1021 * of alignments and pack order etc. */
1022 allocated_cells = get_allocated_cells (box, box_iter, widget);
1024 for (l = allocated_cells; l; l = l->next)
1026 AllocatedCell *cell = l->data;
1027 GtkCellRendererState cell_fields = 0;
1029 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1031 cell_background.x = cell_area->x + cell->position;
1032 cell_background.width = cell->size;
1036 cell_background.y = cell_area->y + cell->position;
1037 cell_background.height = cell->size;
1040 /* Remove margins from the background area to produce the cell area
1042 gtk_cell_area_inner_cell_area (area, &cell_background, &inner_area);
1044 /* XXX TODO Here after getting the inner area of the cell background,
1045 * add portions of the background area to the cell background */
1048 (cell->renderer == focus_cell ||
1049 gtk_cell_area_is_focus_sibling (area, focus_cell, cell->renderer)))
1051 cell_fields |= GTK_CELL_RENDERER_FOCUSED;
1055 GdkRectangle cell_focus;
1056 gint opposite_size, x_offset, y_offset;
1058 cell_focus = inner_area;
1060 /* Trim up the focus size */
1061 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1063 gtk_cell_renderer_get_preferred_height_for_width (cell->renderer, widget,
1065 NULL, &opposite_size);
1067 cell_focus.height = MIN (opposite_size, cell_focus.height);
1071 gtk_cell_renderer_get_preferred_width_for_height (cell->renderer, widget,
1073 NULL, &opposite_size);
1075 cell_focus.width = MIN (opposite_size, cell_focus.width);
1078 /* offset the cell position */
1079 _gtk_cell_renderer_calc_offset (cell->renderer, &inner_area, GTK_TEXT_DIR_LTR,
1080 cell_focus.width, cell_focus.height,
1081 &x_offset, &y_offset);
1083 cell_focus.x += x_offset;
1084 cell_focus.y += y_offset;
1086 /* Accumulate the focus rectangle for all focus siblings */
1087 if (first_focus_cell)
1089 focus_rect = cell_focus;
1090 first_focus_cell = FALSE;
1093 gdk_rectangle_union (&focus_rect, &cell_focus, &focus_rect);
1097 /* We have to do some per-cell considerations for the 'flags'
1098 * for focus handling */
1099 gtk_cell_renderer_render (cell->renderer, cr, widget,
1100 &cell_background, &inner_area,
1101 flags | cell_fields);
1104 if (paint_focus && focus_rect.width != 0 && focus_rect.height != 0)
1106 GtkStateType renderer_state =
1107 flags & GTK_CELL_RENDERER_SELECTED ? GTK_STATE_SELECTED :
1108 (flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT :
1109 (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL));
1111 gtk_paint_focus (gtk_widget_get_style (widget),
1114 /* XXX This hint should be a property on GtkCellArea I suppose */
1123 g_slist_foreach (allocated_cells, (GFunc)allocated_cell_free, NULL);
1124 g_slist_free (allocated_cells);
1128 gtk_cell_area_box_set_cell_property (GtkCellArea *area,
1129 GtkCellRenderer *renderer,
1131 const GValue *value,
1134 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1135 GtkCellAreaBoxPrivate *priv = box->priv;
1138 gboolean rebuild = FALSE;
1140 GtkPackType pack_type;
1142 node = g_list_find_custom (priv->cells, renderer,
1143 (GCompareFunc)cell_info_find);
1151 case CELL_PROP_EXPAND:
1152 val = g_value_get_boolean (value);
1154 if (info->expand != val)
1161 case CELL_PROP_ALIGN:
1162 val = g_value_get_boolean (value);
1164 if (info->align != val)
1171 case CELL_PROP_PACK_TYPE:
1172 pack_type = g_value_get_enum (value);
1174 if (info->pack != pack_type)
1176 info->pack = pack_type;
1181 GTK_CELL_AREA_WARN_INVALID_CHILD_PROPERTY_ID (area, prop_id, pspec);
1185 /* Groups need to be rebuilt */
1187 cell_groups_rebuild (box);
1191 gtk_cell_area_box_get_cell_property (GtkCellArea *area,
1192 GtkCellRenderer *renderer,
1197 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1198 GtkCellAreaBoxPrivate *priv = box->priv;
1202 node = g_list_find_custom (priv->cells, renderer,
1203 (GCompareFunc)cell_info_find);
1211 case CELL_PROP_EXPAND:
1212 g_value_set_boolean (value, info->expand);
1215 case CELL_PROP_ALIGN:
1216 g_value_set_boolean (value, info->align);
1219 case CELL_PROP_PACK_TYPE:
1220 g_value_set_enum (value, info->pack);
1223 GTK_CELL_AREA_WARN_INVALID_CHILD_PROPERTY_ID (area, prop_id, pspec);
1229 static GtkCellAreaIter *
1230 gtk_cell_area_box_create_iter (GtkCellArea *area)
1232 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1233 GtkCellAreaBoxPrivate *priv = box->priv;
1234 GtkCellAreaIter *iter =
1235 (GtkCellAreaIter *)g_object_new (GTK_TYPE_CELL_AREA_BOX_ITER,
1236 "area", area, NULL);
1238 priv->iters = g_slist_prepend (priv->iters, iter);
1240 g_object_weak_ref (G_OBJECT (iter), (GWeakNotify)iter_weak_notify, box);
1242 /* Tell the new group about our cell layout */
1243 init_iter_group (box, GTK_CELL_AREA_BOX_ITER (iter));
1248 static GtkSizeRequestMode
1249 gtk_cell_area_box_get_request_mode (GtkCellArea *area)
1251 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1252 GtkCellAreaBoxPrivate *priv = box->priv;
1254 return (priv->orientation) == GTK_ORIENTATION_HORIZONTAL ?
1255 GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH :
1256 GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT;
1260 compute_size (GtkCellAreaBox *box,
1261 GtkOrientation orientation,
1262 GtkCellAreaBoxIter *iter,
1268 GtkCellAreaBoxPrivate *priv = box->priv;
1269 GtkCellArea *area = GTK_CELL_AREA (box);
1275 for (i = 0; i < priv->groups->len; i++)
1277 CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
1278 gint group_min_size = 0;
1279 gint group_nat_size = 0;
1281 for (list = group->cells; list; list = list->next)
1283 CellInfo *info = list->data;
1284 gint renderer_min_size, renderer_nat_size;
1286 if (!gtk_cell_renderer_get_visible (info->renderer))
1289 gtk_cell_area_request_renderer (area, info->renderer, orientation, widget, for_size,
1290 &renderer_min_size, &renderer_nat_size);
1292 if (orientation == priv->orientation)
1296 min_size += priv->spacing;
1297 nat_size += priv->spacing;
1300 if (group_min_size > 0)
1302 group_min_size += priv->spacing;
1303 group_nat_size += priv->spacing;
1306 min_size += renderer_min_size;
1307 nat_size += renderer_nat_size;
1308 group_min_size += renderer_min_size;
1309 group_nat_size += renderer_nat_size;
1313 min_size = MAX (min_size, renderer_min_size);
1314 nat_size = MAX (nat_size, renderer_nat_size);
1315 group_min_size = MAX (group_min_size, renderer_min_size);
1316 group_nat_size = MAX (group_nat_size, renderer_nat_size);
1320 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1323 gtk_cell_area_box_iter_push_group_width (iter, group->id, group_min_size, group_nat_size);
1325 gtk_cell_area_box_iter_push_group_width_for_height (iter, group->id, for_size,
1326 group_min_size, group_nat_size);
1331 gtk_cell_area_box_iter_push_group_height (iter, group->id, group_min_size, group_nat_size);
1333 gtk_cell_area_box_iter_push_group_height_for_width (iter, group->id, for_size,
1334 group_min_size, group_nat_size);
1338 *minimum_size = min_size;
1339 *natural_size = nat_size;
1343 get_group_sizes (GtkCellArea *area,
1345 GtkOrientation orientation,
1349 GtkRequestedSize *sizes;
1353 *n_sizes = count_visible_cells (group, NULL);
1354 sizes = g_new (GtkRequestedSize, *n_sizes);
1356 for (l = group->cells, i = 0; l; l = l->next)
1358 CellInfo *info = l->data;
1360 if (!gtk_cell_renderer_get_visible (info->renderer))
1363 sizes[i].data = info;
1365 gtk_cell_area_request_renderer (area, info->renderer,
1366 orientation, widget, -1,
1367 &sizes[i].minimum_size,
1368 &sizes[i].natural_size);
1377 compute_group_size_for_opposing_orientation (GtkCellAreaBox *box,
1384 GtkCellAreaBoxPrivate *priv = box->priv;
1385 GtkCellArea *area = GTK_CELL_AREA (box);
1387 /* Exception for single cell groups */
1388 if (group->n_cells == 1)
1390 CellInfo *info = group->cells->data;
1392 gtk_cell_area_request_renderer (area, info->renderer,
1393 OPPOSITE_ORIENTATION (priv->orientation),
1394 widget, for_size, minimum_size, natural_size);
1398 GtkRequestedSize *orientation_sizes;
1401 gint avail_size = for_size;
1402 gint extra_size, extra_extra;
1403 gint min_size = 0, nat_size = 0;
1405 orientation_sizes = get_group_sizes (area, group, priv->orientation, widget, &n_sizes);
1407 /* First naturally allocate the cells in the group into the for_size */
1408 avail_size -= (n_sizes - 1) * priv->spacing;
1409 for (i = 0; i < n_sizes; i++)
1410 avail_size -= orientation_sizes[i].minimum_size;
1412 avail_size = gtk_distribute_natural_allocation (avail_size, n_sizes, orientation_sizes);
1414 /* Calculate/distribute expand for cells */
1415 if (group->expand_cells > 0)
1417 extra_size = avail_size / group->expand_cells;
1418 extra_extra = avail_size % group->expand_cells;
1421 extra_size = extra_extra = 0;
1423 for (i = 0; i < n_sizes; i++)
1425 gint cell_min, cell_nat;
1427 info = orientation_sizes[i].data;
1431 orientation_sizes[i].minimum_size += extra_size;
1434 orientation_sizes[i].minimum_size++;
1439 gtk_cell_area_request_renderer (area, info->renderer,
1440 OPPOSITE_ORIENTATION (priv->orientation),
1442 orientation_sizes[i].minimum_size,
1443 &cell_min, &cell_nat);
1445 min_size = MAX (min_size, cell_min);
1446 nat_size = MAX (nat_size, cell_nat);
1449 *minimum_size = min_size;
1450 *natural_size = nat_size;
1452 g_free (orientation_sizes);
1457 compute_size_for_opposing_orientation (GtkCellAreaBox *box,
1458 GtkCellAreaBoxIter *iter,
1464 GtkCellAreaBoxPrivate *priv = box->priv;
1466 GtkRequestedSize *orientation_sizes;
1467 gint n_groups, n_expand_groups, i;
1468 gint avail_size = for_size;
1469 gint extra_size, extra_extra;
1470 gint min_size = 0, nat_size = 0;
1472 n_expand_groups = count_expand_groups (box);
1474 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1475 orientation_sizes = gtk_cell_area_box_iter_get_widths (iter, &n_groups);
1477 orientation_sizes = gtk_cell_area_box_iter_get_heights (iter, &n_groups);
1479 /* First start by naturally allocating space among groups of cells */
1480 avail_size -= (n_groups - 1) * priv->spacing;
1481 for (i = 0; i < n_groups; i++)
1482 avail_size -= orientation_sizes[i].minimum_size;
1484 avail_size = gtk_distribute_natural_allocation (avail_size, n_groups, orientation_sizes);
1486 /* Calculate/distribute expand for groups */
1487 if (n_expand_groups > 0)
1489 extra_size = avail_size / n_expand_groups;
1490 extra_extra = avail_size % n_expand_groups;
1493 extra_size = extra_extra = 0;
1495 /* Now we need to naturally allocate sizes for cells in each group
1496 * and push the height-for-width for each group accordingly while accumulating
1497 * the overall height-for-width for this row.
1499 for (i = 0; i < n_groups; i++)
1501 gint group_min, group_nat;
1502 gint group_idx = GPOINTER_TO_INT (orientation_sizes[i].data);
1504 group = &g_array_index (priv->groups, CellGroup, group_idx);
1506 if (group->expand_cells > 0)
1508 orientation_sizes[i].minimum_size += extra_size;
1511 orientation_sizes[i].minimum_size++;
1516 /* Now we have the allocation for the group, request it's height-for-width */
1517 compute_group_size_for_opposing_orientation (box, group, widget,
1518 orientation_sizes[i].minimum_size,
1519 &group_min, &group_nat);
1521 min_size = MAX (min_size, group_min);
1522 nat_size = MAX (nat_size, group_nat);
1524 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1526 gtk_cell_area_box_iter_push_group_height_for_width (iter, group_idx, for_size,
1527 group_min, group_nat);
1531 gtk_cell_area_box_iter_push_group_width_for_height (iter, group_idx, for_size,
1532 group_min, group_nat);
1536 *minimum_size = min_size;
1537 *natural_size = nat_size;
1539 g_free (orientation_sizes);
1545 gtk_cell_area_box_get_preferred_width (GtkCellArea *area,
1546 GtkCellAreaIter *iter,
1548 gint *minimum_width,
1549 gint *natural_width)
1551 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1552 GtkCellAreaBoxIter *box_iter;
1553 gint min_width, nat_width;
1555 g_return_if_fail (GTK_IS_CELL_AREA_BOX_ITER (iter));
1557 box_iter = GTK_CELL_AREA_BOX_ITER (iter);
1559 /* Compute the size of all renderers for current row data,
1560 * bumping cell alignments in the iter along the way */
1561 compute_size (box, GTK_ORIENTATION_HORIZONTAL,
1562 box_iter, widget, -1, &min_width, &nat_width);
1565 *minimum_width = min_width;
1568 *natural_width = nat_width;
1572 gtk_cell_area_box_get_preferred_height (GtkCellArea *area,
1573 GtkCellAreaIter *iter,
1575 gint *minimum_height,
1576 gint *natural_height)
1578 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1579 GtkCellAreaBoxIter *box_iter;
1580 gint min_height, nat_height;
1582 g_return_if_fail (GTK_IS_CELL_AREA_BOX_ITER (iter));
1584 box_iter = GTK_CELL_AREA_BOX_ITER (iter);
1586 /* Compute the size of all renderers for current row data,
1587 * bumping cell alignments in the iter along the way */
1588 compute_size (box, GTK_ORIENTATION_VERTICAL,
1589 box_iter, widget, -1, &min_height, &nat_height);
1592 *minimum_height = min_height;
1595 *natural_height = nat_height;
1599 gtk_cell_area_box_get_preferred_height_for_width (GtkCellArea *area,
1600 GtkCellAreaIter *iter,
1603 gint *minimum_height,
1604 gint *natural_height)
1606 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1607 GtkCellAreaBoxIter *box_iter;
1608 GtkCellAreaBoxPrivate *priv;
1609 gint min_height, nat_height;
1611 g_return_if_fail (GTK_IS_CELL_AREA_BOX_ITER (iter));
1613 box_iter = GTK_CELL_AREA_BOX_ITER (iter);
1616 if (priv->orientation == GTK_ORIENTATION_VERTICAL)
1618 /* Add up vertical requests of height for width and push the overall
1619 * cached sizes for alignments */
1620 compute_size (box, priv->orientation, box_iter, widget, width, &min_height, &nat_height);
1624 /* Juice: virtually allocate cells into the for_width using the
1625 * alignments and then return the overall height for that width, and cache it */
1626 compute_size_for_opposing_orientation (box, box_iter, widget, width, &min_height, &nat_height);
1630 *minimum_height = min_height;
1633 *natural_height = nat_height;
1637 gtk_cell_area_box_get_preferred_width_for_height (GtkCellArea *area,
1638 GtkCellAreaIter *iter,
1641 gint *minimum_width,
1642 gint *natural_width)
1644 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1645 GtkCellAreaBoxIter *box_iter;
1646 GtkCellAreaBoxPrivate *priv;
1647 gint min_width, nat_width;
1649 g_return_if_fail (GTK_IS_CELL_AREA_BOX_ITER (iter));
1651 box_iter = GTK_CELL_AREA_BOX_ITER (iter);
1654 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1656 /* Add up horizontal requests of width for height and push the overall
1657 * cached sizes for alignments */
1658 compute_size (box, priv->orientation, box_iter, widget, height, &min_width, &nat_width);
1662 /* Juice: horizontally allocate cells into the for_height using the
1663 * alignments and then return the overall width for that height, and cache it */
1664 compute_size_for_opposing_orientation (box, box_iter, widget, height, &min_width, &nat_width);
1668 *minimum_width = min_width;
1671 *natural_width = nat_width;
1675 gtk_cell_area_box_focus (GtkCellArea *area,
1676 GtkDirectionType direction)
1678 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1679 GtkCellAreaBoxPrivate *priv = box->priv;
1680 gint cycle = FOCUS_NONE;
1681 gboolean cycled_focus = FALSE;
1682 GtkCellRenderer *focus_cell;
1684 focus_cell = gtk_cell_area_get_focus_cell (area);
1688 case GTK_DIR_TAB_FORWARD:
1691 case GTK_DIR_TAB_BACKWARD:
1695 if (priv->orientation == GTK_ORIENTATION_VERTICAL || !focus_cell)
1699 if (priv->orientation == GTK_ORIENTATION_VERTICAL || !focus_cell)
1703 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL || !focus_cell)
1707 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL || !focus_cell)
1714 if (cycle != FOCUS_NONE)
1716 gboolean found_cell = FALSE;
1720 /* If there is no focused cell, focus on the first (or last) one in the list */
1724 for (i = (cycle == FOCUS_NEXT) ? 0 : priv->groups->len -1;
1725 cycled_focus == FALSE && i >= 0 && i < priv->groups->len;
1726 i = (cycle == FOCUS_NEXT) ? i + 1 : i - 1)
1728 CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
1730 for (list = (cycle == FOCUS_NEXT) ? g_list_first (group->cells) : g_list_last (group->cells);
1731 list; list = (cycle == FOCUS_NEXT) ? list->next : list->prev)
1733 CellInfo *info = list->data;
1735 if (info->renderer == focus_cell)
1737 else if (found_cell)
1739 if (gtk_cell_renderer_can_focus (info->renderer))
1741 gtk_cell_area_set_focus_cell (area, info->renderer);
1743 cycled_focus = TRUE;
1752 gtk_cell_area_set_focus_cell (area, NULL);
1754 return cycled_focus;
1758 /*************************************************************
1759 * GtkCellLayoutIface *
1760 *************************************************************/
1762 gtk_cell_area_box_cell_layout_init (GtkCellLayoutIface *iface)
1764 iface->pack_start = gtk_cell_area_box_layout_pack_start;
1765 iface->pack_end = gtk_cell_area_box_layout_pack_end;
1766 iface->reorder = gtk_cell_area_box_layout_reorder;
1770 gtk_cell_area_box_layout_pack_start (GtkCellLayout *cell_layout,
1771 GtkCellRenderer *renderer,
1774 gtk_cell_area_box_pack_start (GTK_CELL_AREA_BOX (cell_layout), renderer, expand, TRUE);
1778 gtk_cell_area_box_layout_pack_end (GtkCellLayout *cell_layout,
1779 GtkCellRenderer *renderer,
1782 gtk_cell_area_box_pack_end (GTK_CELL_AREA_BOX (cell_layout), renderer, expand, TRUE);
1786 gtk_cell_area_box_layout_reorder (GtkCellLayout *cell_layout,
1787 GtkCellRenderer *renderer,
1790 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (cell_layout);
1791 GtkCellAreaBoxPrivate *priv = box->priv;
1795 node = g_list_find_custom (priv->cells, renderer,
1796 (GCompareFunc)cell_info_find);
1802 priv->cells = g_list_delete_link (priv->cells, node);
1803 priv->cells = g_list_insert (priv->cells, info, position);
1805 cell_groups_rebuild (box);
1809 /*************************************************************
1811 *************************************************************/
1813 gtk_cell_area_box_new (void)
1815 return (GtkCellArea *)g_object_new (GTK_TYPE_CELL_AREA_BOX, NULL);
1819 gtk_cell_area_box_pack_start (GtkCellAreaBox *box,
1820 GtkCellRenderer *renderer,
1824 GtkCellAreaBoxPrivate *priv;
1827 g_return_if_fail (GTK_IS_CELL_AREA_BOX (box));
1828 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1832 if (g_list_find_custom (priv->cells, renderer,
1833 (GCompareFunc)cell_info_find))
1835 g_warning ("Refusing to add the same cell renderer to a GtkCellAreaBox twice");
1839 info = cell_info_new (renderer, GTK_PACK_START, expand, align);
1841 priv->cells = g_list_append (priv->cells, info);
1843 cell_groups_rebuild (box);
1847 gtk_cell_area_box_pack_end (GtkCellAreaBox *box,
1848 GtkCellRenderer *renderer,
1852 GtkCellAreaBoxPrivate *priv;
1855 g_return_if_fail (GTK_IS_CELL_AREA_BOX (box));
1856 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1860 if (g_list_find_custom (priv->cells, renderer,
1861 (GCompareFunc)cell_info_find))
1863 g_warning ("Refusing to add the same cell renderer to a GtkCellArea twice");
1867 info = cell_info_new (renderer, GTK_PACK_END, expand, align);
1869 priv->cells = g_list_append (priv->cells, info);
1871 cell_groups_rebuild (box);
1875 gtk_cell_area_box_get_spacing (GtkCellAreaBox *box)
1877 g_return_val_if_fail (GTK_IS_CELL_AREA_BOX (box), 0);
1879 return box->priv->spacing;
1883 gtk_cell_area_box_set_spacing (GtkCellAreaBox *box,
1886 GtkCellAreaBoxPrivate *priv;
1888 g_return_if_fail (GTK_IS_CELL_AREA_BOX (box));
1892 if (priv->spacing != spacing)
1894 priv->spacing = spacing;
1896 g_object_notify (G_OBJECT (box), "spacing");
1898 /* Notify that size needs to be requested again */