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 "gtkcellareaboxcontext.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 GtkCellAreaContext *context,
56 GtkCellRenderer *renderer,
57 const GdkRectangle *cell_area,
58 GdkRectangle *allocation);
59 static gint gtk_cell_area_box_event (GtkCellArea *area,
60 GtkCellAreaContext *context,
63 const GdkRectangle *cell_area,
64 GtkCellRendererState flags);
65 static void gtk_cell_area_box_render (GtkCellArea *area,
66 GtkCellAreaContext *context,
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 GtkCellAreaContext *gtk_cell_area_box_create_context (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 GtkCellAreaContext *context,
90 static void gtk_cell_area_box_get_preferred_height (GtkCellArea *area,
91 GtkCellAreaContext *context,
94 gint *natural_height);
95 static void gtk_cell_area_box_get_preferred_height_for_width (GtkCellArea *area,
96 GtkCellAreaContext *context,
100 gint *natural_height);
101 static void gtk_cell_area_box_get_preferred_width_for_height (GtkCellArea *area,
102 GtkCellAreaContext *context,
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 context_weak_notify (GtkCellAreaBox *box,
162 GtkCellAreaBoxContext *dead_context);
163 static void flush_contexts (GtkCellAreaBox *box);
164 static void init_context_groups (GtkCellAreaBox *box);
165 static void init_context_group (GtkCellAreaBox *box,
166 GtkCellAreaBoxContext *context);
167 static GSList *get_allocated_cells (GtkCellAreaBox *box,
168 GtkCellAreaBoxContext *context,
170 gint orientation_size);
173 struct _GtkCellAreaBoxPrivate
175 GtkOrientation orientation;
198 G_DEFINE_TYPE_WITH_CODE (GtkCellAreaBox, gtk_cell_area_box, GTK_TYPE_CELL_AREA,
199 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
200 gtk_cell_area_box_cell_layout_init)
201 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL));
203 #define OPPOSITE_ORIENTATION(orientation) \
204 ((orientation) == GTK_ORIENTATION_HORIZONTAL ? \
205 GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL)
208 gtk_cell_area_box_init (GtkCellAreaBox *box)
210 GtkCellAreaBoxPrivate *priv;
212 box->priv = G_TYPE_INSTANCE_GET_PRIVATE (box,
213 GTK_TYPE_CELL_AREA_BOX,
214 GtkCellAreaBoxPrivate);
217 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
218 priv->groups = g_array_new (FALSE, TRUE, sizeof (CellGroup));
220 priv->contexts = NULL;
225 gtk_cell_area_box_class_init (GtkCellAreaBoxClass *class)
227 GObjectClass *object_class = G_OBJECT_CLASS (class);
228 GtkCellAreaClass *area_class = GTK_CELL_AREA_CLASS (class);
231 object_class->finalize = gtk_cell_area_box_finalize;
232 object_class->dispose = gtk_cell_area_box_dispose;
233 object_class->set_property = gtk_cell_area_box_set_property;
234 object_class->get_property = gtk_cell_area_box_get_property;
236 /* GtkCellAreaClass */
237 area_class->add = gtk_cell_area_box_add;
238 area_class->remove = gtk_cell_area_box_remove;
239 area_class->forall = gtk_cell_area_box_forall;
240 area_class->get_cell_allocation = gtk_cell_area_box_get_cell_allocation;
241 area_class->event = gtk_cell_area_box_event;
242 area_class->render = gtk_cell_area_box_render;
243 area_class->set_cell_property = gtk_cell_area_box_set_cell_property;
244 area_class->get_cell_property = gtk_cell_area_box_get_cell_property;
246 area_class->create_context = gtk_cell_area_box_create_context;
247 area_class->get_request_mode = gtk_cell_area_box_get_request_mode;
248 area_class->get_preferred_width = gtk_cell_area_box_get_preferred_width;
249 area_class->get_preferred_height = gtk_cell_area_box_get_preferred_height;
250 area_class->get_preferred_height_for_width = gtk_cell_area_box_get_preferred_height_for_width;
251 area_class->get_preferred_width_for_height = gtk_cell_area_box_get_preferred_width_for_height;
253 area_class->focus = gtk_cell_area_box_focus;
256 g_object_class_override_property (object_class, PROP_ORIENTATION, "orientation");
258 g_object_class_install_property (object_class,
260 g_param_spec_int ("spacing",
262 P_("Space which is inserted between cells"),
266 GTK_PARAM_READWRITE));
268 /* Cell Properties */
269 gtk_cell_area_class_install_cell_property (area_class,
274 P_("Whether the cell expands"),
276 GTK_PARAM_READWRITE));
278 gtk_cell_area_class_install_cell_property (area_class,
283 P_("Whether cell should align with adjacent rows"),
285 GTK_PARAM_READWRITE));
287 gtk_cell_area_class_install_cell_property (area_class,
292 P_("A GtkPackType indicating whether the cell is packed with "
293 "reference to the start or end of the cell area"),
294 GTK_TYPE_PACK_TYPE, GTK_PACK_START,
295 GTK_PARAM_READWRITE));
297 g_type_class_add_private (object_class, sizeof (GtkCellAreaBoxPrivate));
301 /*************************************************************
302 * CellInfo/CellGroup basics and convenience functions *
303 *************************************************************/
305 cell_info_new (GtkCellRenderer *renderer,
310 CellInfo *info = g_slice_new (CellInfo);
312 info->renderer = g_object_ref_sink (renderer);
314 info->expand = expand;
321 cell_info_free (CellInfo *info)
323 g_object_unref (info->renderer);
325 g_slice_free (CellInfo, info);
329 cell_info_find (CellInfo *info,
330 GtkCellRenderer *renderer)
332 return (info->renderer == renderer) ? 0 : -1;
335 static AllocatedCell *
336 allocated_cell_new (GtkCellRenderer *renderer,
340 AllocatedCell *cell = g_slice_new (AllocatedCell);
342 cell->renderer = renderer;
343 cell->position = position;
350 allocated_cell_free (AllocatedCell *cell)
352 g_slice_free (AllocatedCell, cell);
356 list_consecutive_cells (GtkCellAreaBox *box)
358 GtkCellAreaBoxPrivate *priv = box->priv;
359 GList *l, *consecutive_cells = NULL, *pack_end_cells = NULL;
362 /* List cells in consecutive order taking their
363 * PACK_START/PACK_END options into account
365 for (l = priv->cells; l; l = l->next)
369 if (info->pack == GTK_PACK_START)
370 consecutive_cells = g_list_prepend (consecutive_cells, info);
373 for (l = priv->cells; l; l = l->next)
377 if (info->pack == GTK_PACK_END)
378 pack_end_cells = g_list_prepend (pack_end_cells, info);
381 consecutive_cells = g_list_reverse (consecutive_cells);
382 consecutive_cells = g_list_concat (consecutive_cells, pack_end_cells);
384 return consecutive_cells;
388 cell_groups_clear (GtkCellAreaBox *box)
390 GtkCellAreaBoxPrivate *priv = box->priv;
393 for (i = 0; i < priv->groups->len; i++)
395 CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
397 g_list_free (group->cells);
400 g_array_set_size (priv->groups, 0);
404 cell_groups_rebuild (GtkCellAreaBox *box)
406 GtkCellAreaBoxPrivate *priv = box->priv;
407 CellGroup group = { 0, };
408 CellGroup *group_ptr;
412 cell_groups_clear (box);
417 cells = list_consecutive_cells (box);
419 /* First group is implied */
420 g_array_append_val (priv->groups, group);
421 group_ptr = &g_array_index (priv->groups, CellGroup, id);
423 for (l = cells; l; l = l->next)
425 CellInfo *info = l->data;
427 /* A new group starts with any aligned cell, the first group is implied */
428 if (info->align && l != cells)
430 memset (&group, 0x0, sizeof (CellGroup));
433 g_array_append_val (priv->groups, group);
434 group_ptr = &g_array_index (priv->groups, CellGroup, id);
437 group_ptr->cells = g_list_prepend (group_ptr->cells, info);
438 group_ptr->n_cells++;
440 /* A group expands if it contains any expand cells */
442 group_ptr->expand_cells++;
447 for (id = 0; id < priv->groups->len; id++)
449 group_ptr = &g_array_index (priv->groups, CellGroup, id);
451 group_ptr->cells = g_list_reverse (group_ptr->cells);
454 /* Contexts need to be updated with the new grouping information */
455 init_context_groups (box);
459 count_visible_cells (CellGroup *group,
463 gint visible_cells = 0;
464 gint n_expand_cells = 0;
466 for (l = group->cells; l; l = l->next)
468 CellInfo *info = l->data;
470 if (gtk_cell_renderer_get_visible (info->renderer))
480 *expand_cells = n_expand_cells;
482 return visible_cells;
486 count_expand_groups (GtkCellAreaBox *box)
488 GtkCellAreaBoxPrivate *priv = box->priv;
490 gint expand_groups = 0;
492 for (i = 0; i < priv->groups->len; i++)
494 CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
496 if (group->expand_cells > 0)
500 return expand_groups;
504 context_weak_notify (GtkCellAreaBox *box,
505 GtkCellAreaBoxContext *dead_context)
507 GtkCellAreaBoxPrivate *priv = box->priv;
509 priv->contexts = g_slist_remove (priv->contexts, dead_context);
513 init_context_group (GtkCellAreaBox *box,
514 GtkCellAreaBoxContext *context)
516 GtkCellAreaBoxPrivate *priv = box->priv;
517 gint *expand_groups, i;
519 expand_groups = g_new (gboolean, priv->groups->len);
521 for (i = 0; i < priv->groups->len; i++)
523 CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
525 expand_groups[i] = (group->expand_cells > 0);
528 /* This call implies flushing the request info */
529 gtk_cell_area_box_init_groups (context, priv->groups->len, expand_groups);
530 g_free (expand_groups);
534 init_context_groups (GtkCellAreaBox *box)
536 GtkCellAreaBoxPrivate *priv = box->priv;
539 /* When the box's groups are reconstructed, contexts need to
542 for (l = priv->contexts; l; l = l->next)
544 GtkCellAreaBoxContext *context = l->data;
546 init_context_group (box, context);
551 flush_contexts (GtkCellAreaBox *box)
553 GtkCellAreaBoxPrivate *priv = box->priv;
556 /* When the box layout changes, contexts need to
557 * be flushed and sizes for the box get requested again
559 for (l = priv->contexts; l; l = l->next)
561 GtkCellAreaContext *context = l->data;
563 gtk_cell_area_context_flush (context);
567 /* Returns an allocation for each cell in the orientation of the box,
568 * used in ->render()/->event() implementations to get a straight-forward
569 * list of allocated cells to operate on.
572 get_allocated_cells (GtkCellAreaBox *box,
573 GtkCellAreaBoxContext *context,
575 gint orientation_size)
577 GtkCellAreaBoxAllocation *group_allocs;
578 GtkCellArea *area = GTK_CELL_AREA (box);
579 GtkCellAreaBoxPrivate *priv = box->priv;
581 GSList *allocated_cells = NULL;
583 gboolean free_allocs = FALSE;
585 group_allocs = gtk_cell_area_box_context_get_orientation_allocs (context, &n_allocs);
588 group_allocs = gtk_cell_area_box_context_allocate (context, orientation_size, &n_allocs);
592 for (i = 0; i < n_allocs; i++)
594 /* We dont always allocate all groups, sometimes the requested group has only invisible
595 * cells for every row, hence the usage of group_allocs[i].group_idx here
597 CellGroup *group = &g_array_index (priv->groups, CellGroup, group_allocs[i].group_idx);
599 /* Exception for single cell groups */
600 if (group->n_cells == 1)
602 CellInfo *info = group->cells->data;
603 AllocatedCell *cell =
604 allocated_cell_new (info->renderer, group_allocs[i].position, group_allocs[i].size);
606 allocated_cells = g_slist_prepend (allocated_cells, cell);
610 GtkRequestedSize *sizes;
611 gint avail_size, position;
612 gint visible_cells, expand_cells;
613 gint extra_size, extra_extra;
615 visible_cells = count_visible_cells (group, &expand_cells);
617 /* If this row has no visible cells in this group, just
618 * skip the allocation */
619 if (visible_cells == 0)
622 /* Offset the allocation to the group position and allocate into
623 * the group's available size */
624 position = group_allocs[i].position;
625 avail_size = group_allocs[i].size;
627 sizes = g_new (GtkRequestedSize, visible_cells);
629 for (j = 0, cell_list = group->cells; cell_list; cell_list = cell_list->next)
631 CellInfo *info = cell_list->data;
633 if (!gtk_cell_renderer_get_visible (info->renderer))
636 gtk_cell_area_request_renderer (area, info->renderer,
639 &sizes[j].minimum_size,
640 &sizes[j].natural_size);
642 sizes[j].data = info;
643 avail_size -= sizes[j].minimum_size;
648 /* Distribute cells naturally within the group */
649 avail_size -= (visible_cells - 1) * priv->spacing;
650 avail_size = gtk_distribute_natural_allocation (avail_size, visible_cells, sizes);
652 /* Calculate/distribute expand for cells */
653 if (expand_cells > 0)
655 extra_size = avail_size / expand_cells;
656 extra_extra = avail_size % expand_cells;
659 extra_size = extra_extra = 0;
661 /* Create the allocated cells (loop only over visible cells here) */
662 for (j = 0; j < visible_cells; j++)
664 CellInfo *info = sizes[j].data;
669 sizes[j].minimum_size += extra_size;
672 sizes[j].minimum_size++;
677 cell = allocated_cell_new (info->renderer, position, sizes[j].minimum_size);
679 allocated_cells = g_slist_prepend (allocated_cells, cell);
681 position += sizes[j].minimum_size;
682 position += priv->spacing;
690 g_free (group_allocs);
692 /* Note it might not be important to reverse the list here at all,
693 * we have the correct positions, no need to allocate from left to right */
694 return g_slist_reverse (allocated_cells);
697 /*************************************************************
699 *************************************************************/
701 gtk_cell_area_box_finalize (GObject *object)
703 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (object);
704 GtkCellAreaBoxPrivate *priv = box->priv;
707 /* Unref/free the context list */
708 for (l = priv->contexts; l; l = l->next)
709 g_object_weak_unref (G_OBJECT (l->data), (GWeakNotify)context_weak_notify, box);
711 g_slist_free (priv->contexts);
712 priv->contexts = NULL;
714 /* Free the cell grouping info */
715 cell_groups_clear (box);
716 g_array_free (priv->groups, TRUE);
718 G_OBJECT_CLASS (gtk_cell_area_box_parent_class)->finalize (object);
722 gtk_cell_area_box_dispose (GObject *object)
724 G_OBJECT_CLASS (gtk_cell_area_box_parent_class)->dispose (object);
728 gtk_cell_area_box_set_property (GObject *object,
733 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (object);
737 case PROP_ORIENTATION:
738 box->priv->orientation = g_value_get_enum (value);
740 /* Notify that size needs to be requested again */
741 flush_contexts (box);
744 gtk_cell_area_box_set_spacing (box, g_value_get_int (value));
747 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
753 gtk_cell_area_box_get_property (GObject *object,
758 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (object);
762 case PROP_ORIENTATION:
763 g_value_set_enum (value, box->priv->orientation);
766 g_value_set_int (value, gtk_cell_area_box_get_spacing (box));
769 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
774 /*************************************************************
776 *************************************************************/
778 gtk_cell_area_box_add (GtkCellArea *area,
779 GtkCellRenderer *renderer)
781 gtk_cell_area_box_pack_start (GTK_CELL_AREA_BOX (area),
782 renderer, FALSE, TRUE);
786 gtk_cell_area_box_remove (GtkCellArea *area,
787 GtkCellRenderer *renderer)
789 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
790 GtkCellAreaBoxPrivate *priv = box->priv;
793 node = g_list_find_custom (priv->cells, renderer,
794 (GCompareFunc)cell_info_find);
798 CellInfo *info = node->data;
800 cell_info_free (info);
802 priv->cells = g_list_delete_link (priv->cells, node);
804 /* Reconstruct cell groups */
805 cell_groups_rebuild (box);
808 g_warning ("Trying to remove a cell renderer that is not present GtkCellAreaBox");
812 gtk_cell_area_box_forall (GtkCellArea *area,
813 GtkCellCallback callback,
814 gpointer callback_data)
816 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
817 GtkCellAreaBoxPrivate *priv = box->priv;
820 for (list = priv->cells; list; list = list->next)
822 CellInfo *info = list->data;
824 callback (info->renderer, callback_data);
829 gtk_cell_area_box_get_cell_allocation (GtkCellArea *area,
830 GtkCellAreaContext *context,
832 GtkCellRenderer *renderer,
833 const GdkRectangle *cell_area,
834 GdkRectangle *allocation)
836 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
837 GtkCellAreaBoxPrivate *priv = box->priv;
838 GtkCellAreaBoxContext *box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
839 GSList *allocated_cells, *l;
841 *allocation = *cell_area;
843 /* Get a list of cells with allocation sizes decided regardless
844 * of alignments and pack order etc. */
845 allocated_cells = get_allocated_cells (box, box_context, widget,
846 priv->orientation == GTK_ORIENTATION_HORIZONTAL ?
847 cell_area->width : cell_area->height);
849 for (l = allocated_cells; l; l = l->next)
851 AllocatedCell *cell = l->data;
853 if (cell->renderer == renderer)
855 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
857 allocation->x = cell_area->x + cell->position;
858 allocation->width = cell->size;
862 allocation->y = cell_area->y + cell->position;
863 allocation->height = cell->size;
870 g_slist_foreach (allocated_cells, (GFunc)allocated_cell_free, NULL);
871 g_slist_free (allocated_cells);
881 gtk_cell_area_box_event (GtkCellArea *area,
882 GtkCellAreaContext *context,
885 const GdkRectangle *cell_area,
886 GtkCellRendererState flags)
890 /* First let the parent class handle activation of cells via keystrokes */
892 GTK_CELL_AREA_CLASS (gtk_cell_area_box_parent_class)->event (area, context, widget,
893 event, cell_area, flags);
898 /* Also detect mouse events, for mouse events we need to allocate the renderers
899 * and find which renderer needs to be activated.
901 if (event->type == GDK_BUTTON_PRESS)
903 GdkEventButton *button_event = (GdkEventButton *)event;
905 if (button_event->button == 1)
907 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
908 GtkCellAreaBoxPrivate *priv = box->priv;
909 GtkCellAreaBoxContext *box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
910 GSList *allocated_cells, *l;
911 GdkRectangle cell_background, inner_area;
912 gint event_x, event_y;
914 /* We may need some semantics to tell us the offset of the event
915 * window we are handling events for (i.e. GtkTreeView has a bin_window) */
916 event_x = button_event->x;
917 event_y = button_event->y;
919 cell_background = *cell_area;
921 /* Get a list of cells with allocation sizes decided regardless
922 * of alignments and pack order etc. */
923 allocated_cells = get_allocated_cells (box, box_context, widget,
924 priv->orientation == GTK_ORIENTATION_HORIZONTAL ?
925 cell_area->width : cell_area->height);
927 for (l = allocated_cells; l; l = l->next)
929 AllocatedCell *cell = l->data;
931 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
933 cell_background.x = cell_area->x + cell->position;
934 cell_background.width = cell->size;
938 cell_background.y = cell_area->y + cell->position;
939 cell_background.height = cell->size;
942 /* Remove margins from the background area to produce the cell area
944 gtk_cell_area_inner_cell_area (area, widget, &cell_background, &inner_area);
946 if (event_x >= inner_area.x && event_x <= inner_area.x + inner_area.width &&
947 event_y >= inner_area.y && event_y <= inner_area.y + inner_area.height)
949 GtkCellRenderer *event_renderer = NULL;
951 if (gtk_cell_renderer_can_focus (cell->renderer))
952 event_renderer = cell->renderer;
955 GtkCellRenderer *focus_renderer;
957 /* A renderer can have focus siblings but that renderer might not be
958 * focusable for every row... so we go on to check can_focus here. */
959 focus_renderer = gtk_cell_area_get_focus_from_sibling (area, cell->renderer);
961 if (focus_renderer && gtk_cell_renderer_can_focus (focus_renderer))
962 event_renderer = focus_renderer;
967 if (gtk_cell_area_get_edited_cell (area))
969 /* XXX Was it really canceled in this case ? */
970 gtk_cell_area_stop_editing (area, TRUE);
971 gtk_cell_area_set_focus_cell (area, event_renderer);
976 /* If we are activating via a focus sibling, we need to fix the
978 if (event_renderer != cell->renderer)
979 gtk_cell_area_inner_cell_area (area, widget, cell_area, &cell_background);
981 gtk_cell_area_set_focus_cell (area, event_renderer);
983 retval = gtk_cell_area_activate_cell (area, widget, event_renderer,
984 event, &cell_background, flags);
990 g_slist_foreach (allocated_cells, (GFunc)allocated_cell_free, NULL);
991 g_slist_free (allocated_cells);
999 gtk_cell_area_box_render (GtkCellArea *area,
1000 GtkCellAreaContext *context,
1003 const GdkRectangle *background_area,
1004 const GdkRectangle *cell_area,
1005 GtkCellRendererState flags,
1006 gboolean paint_focus)
1008 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1009 GtkCellAreaBoxPrivate *priv = box->priv;
1010 GtkCellAreaBoxContext *box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
1011 GSList *allocated_cells, *l;
1012 GdkRectangle cell_background, inner_area;
1013 GtkCellRenderer *focus_cell = NULL;
1014 GdkRectangle focus_rect = { 0, };
1015 gboolean first_focus_cell = TRUE;
1017 if (flags & GTK_CELL_RENDERER_FOCUSED)
1019 focus_cell = gtk_cell_area_get_focus_cell (area);
1020 flags &= ~GTK_CELL_RENDERER_FOCUSED;
1023 cell_background = *cell_area;
1025 /* Get a list of cells with allocation sizes decided regardless
1026 * of alignments and pack order etc. */
1027 allocated_cells = get_allocated_cells (box, box_context, widget,
1028 priv->orientation == GTK_ORIENTATION_HORIZONTAL ?
1029 cell_area->width : cell_area->height);
1031 for (l = allocated_cells; l; l = l->next)
1033 AllocatedCell *cell = l->data;
1034 GtkCellRendererState cell_fields = 0;
1035 GdkRectangle render_background;
1037 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1039 cell_background.x = cell_area->x + cell->position;
1040 cell_background.width = cell->size;
1044 cell_background.y = cell_area->y + cell->position;
1045 cell_background.height = cell->size;
1048 /* Remove margins from the background area to produce the cell area
1050 gtk_cell_area_inner_cell_area (area, widget, &cell_background, &inner_area);
1052 /* Add portions of the background_area to the cell_background
1053 * to create the render_background */
1054 render_background = cell_background;
1056 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1058 if (l == allocated_cells)
1060 render_background.width += render_background.x - background_area->x;
1061 render_background.x = background_area->x;
1064 if (l->next == NULL)
1065 render_background.width =
1066 background_area->width - (render_background.x - background_area->x);
1068 render_background.y = background_area->y;
1069 render_background.height = background_area->height;
1073 if (l == allocated_cells)
1075 render_background.height += render_background.y - background_area->y;
1076 render_background.y = background_area->y;
1079 if (l->next == NULL)
1080 render_background.height =
1081 background_area->height - (render_background.y - background_area->y);
1083 render_background.x = background_area->x;
1084 render_background.width = background_area->width;
1088 (cell->renderer == focus_cell ||
1089 gtk_cell_area_is_focus_sibling (area, focus_cell, cell->renderer)))
1091 cell_fields |= GTK_CELL_RENDERER_FOCUSED;
1095 GdkRectangle cell_focus;
1097 gtk_cell_renderer_get_aligned_area (cell->renderer, widget, flags, &inner_area, &cell_focus);
1099 /* Accumulate the focus rectangle for all focus siblings */
1100 if (first_focus_cell)
1102 focus_rect = cell_focus;
1103 first_focus_cell = FALSE;
1106 gdk_rectangle_union (&focus_rect, &cell_focus, &focus_rect);
1110 /* We have to do some per-cell considerations for the 'flags'
1111 * for focus handling */
1112 gtk_cell_renderer_render (cell->renderer, cr, widget,
1113 &render_background, &inner_area,
1114 flags | cell_fields);
1117 if (paint_focus && focus_rect.width != 0 && focus_rect.height != 0)
1119 GtkStateType renderer_state =
1120 flags & GTK_CELL_RENDERER_SELECTED ? GTK_STATE_SELECTED :
1121 (flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT :
1122 (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL));
1124 gtk_paint_focus (gtk_widget_get_style (widget), cr,
1125 renderer_state, widget,
1126 gtk_cell_area_get_style_detail (area),
1127 focus_rect.x, focus_rect.y,
1128 focus_rect.width, focus_rect.height);
1132 g_slist_foreach (allocated_cells, (GFunc)allocated_cell_free, NULL);
1133 g_slist_free (allocated_cells);
1137 gtk_cell_area_box_set_cell_property (GtkCellArea *area,
1138 GtkCellRenderer *renderer,
1140 const GValue *value,
1143 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1144 GtkCellAreaBoxPrivate *priv = box->priv;
1147 gboolean rebuild = FALSE;
1149 GtkPackType pack_type;
1151 node = g_list_find_custom (priv->cells, renderer,
1152 (GCompareFunc)cell_info_find);
1160 case CELL_PROP_EXPAND:
1161 val = g_value_get_boolean (value);
1163 if (info->expand != val)
1170 case CELL_PROP_ALIGN:
1171 val = g_value_get_boolean (value);
1173 if (info->align != val)
1180 case CELL_PROP_PACK_TYPE:
1181 pack_type = g_value_get_enum (value);
1183 if (info->pack != pack_type)
1185 info->pack = pack_type;
1190 GTK_CELL_AREA_WARN_INVALID_CHILD_PROPERTY_ID (area, prop_id, pspec);
1194 /* Groups need to be rebuilt */
1196 cell_groups_rebuild (box);
1200 gtk_cell_area_box_get_cell_property (GtkCellArea *area,
1201 GtkCellRenderer *renderer,
1206 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1207 GtkCellAreaBoxPrivate *priv = box->priv;
1211 node = g_list_find_custom (priv->cells, renderer,
1212 (GCompareFunc)cell_info_find);
1220 case CELL_PROP_EXPAND:
1221 g_value_set_boolean (value, info->expand);
1224 case CELL_PROP_ALIGN:
1225 g_value_set_boolean (value, info->align);
1228 case CELL_PROP_PACK_TYPE:
1229 g_value_set_enum (value, info->pack);
1232 GTK_CELL_AREA_WARN_INVALID_CHILD_PROPERTY_ID (area, prop_id, pspec);
1238 static GtkCellAreaContext *
1239 gtk_cell_area_box_create_context (GtkCellArea *area)
1241 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1242 GtkCellAreaBoxPrivate *priv = box->priv;
1243 GtkCellAreaContext *context =
1244 (GtkCellAreaContext *)g_object_new (GTK_TYPE_CELL_AREA_BOX_CONTEXT,
1245 "area", area, NULL);
1247 priv->contexts = g_slist_prepend (priv->contexts, context);
1249 g_object_weak_ref (G_OBJECT (context), (GWeakNotify)context_weak_notify, box);
1251 /* Tell the new group about our cell layout */
1252 init_context_group (box, GTK_CELL_AREA_BOX_CONTEXT (context));
1257 static GtkSizeRequestMode
1258 gtk_cell_area_box_get_request_mode (GtkCellArea *area)
1260 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1261 GtkCellAreaBoxPrivate *priv = box->priv;
1263 return (priv->orientation) == GTK_ORIENTATION_HORIZONTAL ?
1264 GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH :
1265 GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT;
1269 compute_size (GtkCellAreaBox *box,
1270 GtkOrientation orientation,
1271 GtkCellAreaBoxContext *context,
1277 GtkCellAreaBoxPrivate *priv = box->priv;
1278 GtkCellArea *area = GTK_CELL_AREA (box);
1284 for (i = 0; i < priv->groups->len; i++)
1286 CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
1287 gint group_min_size = 0;
1288 gint group_nat_size = 0;
1290 for (list = group->cells; list; list = list->next)
1292 CellInfo *info = list->data;
1293 gint renderer_min_size, renderer_nat_size;
1295 if (!gtk_cell_renderer_get_visible (info->renderer))
1298 gtk_cell_area_request_renderer (area, info->renderer, orientation, widget, for_size,
1299 &renderer_min_size, &renderer_nat_size);
1301 if (orientation == priv->orientation)
1305 min_size += priv->spacing;
1306 nat_size += priv->spacing;
1309 if (group_min_size > 0)
1311 group_min_size += priv->spacing;
1312 group_nat_size += priv->spacing;
1315 min_size += renderer_min_size;
1316 nat_size += renderer_nat_size;
1317 group_min_size += renderer_min_size;
1318 group_nat_size += renderer_nat_size;
1322 min_size = MAX (min_size, renderer_min_size);
1323 nat_size = MAX (nat_size, renderer_nat_size);
1324 group_min_size = MAX (group_min_size, renderer_min_size);
1325 group_nat_size = MAX (group_nat_size, renderer_nat_size);
1329 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1332 gtk_cell_area_box_context_push_group_width (context, group->id, group_min_size, group_nat_size);
1334 gtk_cell_area_box_context_push_group_width_for_height (context, group->id, for_size,
1335 group_min_size, group_nat_size);
1340 gtk_cell_area_box_context_push_group_height (context, group->id, group_min_size, group_nat_size);
1342 gtk_cell_area_box_context_push_group_height_for_width (context, group->id, for_size,
1343 group_min_size, group_nat_size);
1347 *minimum_size = min_size;
1348 *natural_size = nat_size;
1352 get_group_sizes (GtkCellArea *area,
1354 GtkOrientation orientation,
1358 GtkRequestedSize *sizes;
1362 *n_sizes = count_visible_cells (group, NULL);
1363 sizes = g_new (GtkRequestedSize, *n_sizes);
1365 for (l = group->cells, i = 0; l; l = l->next)
1367 CellInfo *info = l->data;
1369 if (!gtk_cell_renderer_get_visible (info->renderer))
1372 sizes[i].data = info;
1374 gtk_cell_area_request_renderer (area, info->renderer,
1375 orientation, widget, -1,
1376 &sizes[i].minimum_size,
1377 &sizes[i].natural_size);
1386 compute_group_size_for_opposing_orientation (GtkCellAreaBox *box,
1393 GtkCellAreaBoxPrivate *priv = box->priv;
1394 GtkCellArea *area = GTK_CELL_AREA (box);
1396 /* Exception for single cell groups */
1397 if (group->n_cells == 1)
1399 CellInfo *info = group->cells->data;
1401 gtk_cell_area_request_renderer (area, info->renderer,
1402 OPPOSITE_ORIENTATION (priv->orientation),
1403 widget, for_size, minimum_size, natural_size);
1407 GtkRequestedSize *orientation_sizes;
1410 gint avail_size = for_size;
1411 gint extra_size, extra_extra;
1412 gint min_size = 0, nat_size = 0;
1414 orientation_sizes = get_group_sizes (area, group, priv->orientation, widget, &n_sizes);
1416 /* First naturally allocate the cells in the group into the for_size */
1417 avail_size -= (n_sizes - 1) * priv->spacing;
1418 for (i = 0; i < n_sizes; i++)
1419 avail_size -= orientation_sizes[i].minimum_size;
1421 avail_size = gtk_distribute_natural_allocation (avail_size, n_sizes, orientation_sizes);
1423 /* Calculate/distribute expand for cells */
1424 if (group->expand_cells > 0)
1426 extra_size = avail_size / group->expand_cells;
1427 extra_extra = avail_size % group->expand_cells;
1430 extra_size = extra_extra = 0;
1432 for (i = 0; i < n_sizes; i++)
1434 gint cell_min, cell_nat;
1436 info = orientation_sizes[i].data;
1440 orientation_sizes[i].minimum_size += extra_size;
1443 orientation_sizes[i].minimum_size++;
1448 gtk_cell_area_request_renderer (area, info->renderer,
1449 OPPOSITE_ORIENTATION (priv->orientation),
1451 orientation_sizes[i].minimum_size,
1452 &cell_min, &cell_nat);
1454 min_size = MAX (min_size, cell_min);
1455 nat_size = MAX (nat_size, cell_nat);
1458 *minimum_size = min_size;
1459 *natural_size = nat_size;
1461 g_free (orientation_sizes);
1466 compute_size_for_opposing_orientation (GtkCellAreaBox *box,
1467 GtkCellAreaBoxContext *context,
1473 GtkCellAreaBoxPrivate *priv = box->priv;
1475 GtkRequestedSize *orientation_sizes;
1476 gint n_groups, n_expand_groups, i;
1477 gint avail_size = for_size;
1478 gint extra_size, extra_extra;
1479 gint min_size = 0, nat_size = 0;
1481 n_expand_groups = count_expand_groups (box);
1483 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1484 orientation_sizes = gtk_cell_area_box_context_get_widths (context, &n_groups);
1486 orientation_sizes = gtk_cell_area_box_context_get_heights (context, &n_groups);
1488 /* First start by naturally allocating space among groups of cells */
1489 avail_size -= (n_groups - 1) * priv->spacing;
1490 for (i = 0; i < n_groups; i++)
1491 avail_size -= orientation_sizes[i].minimum_size;
1493 avail_size = gtk_distribute_natural_allocation (avail_size, n_groups, orientation_sizes);
1495 /* Calculate/distribute expand for groups */
1496 if (n_expand_groups > 0)
1498 extra_size = avail_size / n_expand_groups;
1499 extra_extra = avail_size % n_expand_groups;
1502 extra_size = extra_extra = 0;
1504 /* Now we need to naturally allocate sizes for cells in each group
1505 * and push the height-for-width for each group accordingly while accumulating
1506 * the overall height-for-width for this row.
1508 for (i = 0; i < n_groups; i++)
1510 gint group_min, group_nat;
1511 gint group_idx = GPOINTER_TO_INT (orientation_sizes[i].data);
1513 group = &g_array_index (priv->groups, CellGroup, group_idx);
1515 if (group->expand_cells > 0)
1517 orientation_sizes[i].minimum_size += extra_size;
1520 orientation_sizes[i].minimum_size++;
1525 /* Now we have the allocation for the group, request it's height-for-width */
1526 compute_group_size_for_opposing_orientation (box, group, widget,
1527 orientation_sizes[i].minimum_size,
1528 &group_min, &group_nat);
1530 min_size = MAX (min_size, group_min);
1531 nat_size = MAX (nat_size, group_nat);
1533 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1535 gtk_cell_area_box_context_push_group_height_for_width (context, group_idx, for_size,
1536 group_min, group_nat);
1540 gtk_cell_area_box_context_push_group_width_for_height (context, group_idx, for_size,
1541 group_min, group_nat);
1545 *minimum_size = min_size;
1546 *natural_size = nat_size;
1548 g_free (orientation_sizes);
1554 gtk_cell_area_box_get_preferred_width (GtkCellArea *area,
1555 GtkCellAreaContext *context,
1557 gint *minimum_width,
1558 gint *natural_width)
1560 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1561 GtkCellAreaBoxContext *box_context;
1562 gint min_width, nat_width;
1564 g_return_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (context));
1566 box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
1568 /* Compute the size of all renderers for current row data,
1569 * bumping cell alignments in the context along the way */
1570 compute_size (box, GTK_ORIENTATION_HORIZONTAL,
1571 box_context, widget, -1, &min_width, &nat_width);
1574 *minimum_width = min_width;
1577 *natural_width = nat_width;
1581 gtk_cell_area_box_get_preferred_height (GtkCellArea *area,
1582 GtkCellAreaContext *context,
1584 gint *minimum_height,
1585 gint *natural_height)
1587 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1588 GtkCellAreaBoxContext *box_context;
1589 gint min_height, nat_height;
1591 g_return_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (context));
1593 box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
1595 /* Compute the size of all renderers for current row data,
1596 * bumping cell alignments in the context along the way */
1597 compute_size (box, GTK_ORIENTATION_VERTICAL,
1598 box_context, widget, -1, &min_height, &nat_height);
1601 *minimum_height = min_height;
1604 *natural_height = nat_height;
1608 gtk_cell_area_box_get_preferred_height_for_width (GtkCellArea *area,
1609 GtkCellAreaContext *context,
1612 gint *minimum_height,
1613 gint *natural_height)
1615 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1616 GtkCellAreaBoxContext *box_context;
1617 GtkCellAreaBoxPrivate *priv;
1618 gint min_height, nat_height;
1620 g_return_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (context));
1622 box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
1625 if (priv->orientation == GTK_ORIENTATION_VERTICAL)
1627 /* Add up vertical requests of height for width and push the overall
1628 * cached sizes for alignments */
1629 compute_size (box, priv->orientation, box_context, widget, width, &min_height, &nat_height);
1633 /* Juice: virtually allocate cells into the for_width using the
1634 * alignments and then return the overall height for that width, and cache it */
1635 compute_size_for_opposing_orientation (box, box_context, widget, width, &min_height, &nat_height);
1639 *minimum_height = min_height;
1642 *natural_height = nat_height;
1646 gtk_cell_area_box_get_preferred_width_for_height (GtkCellArea *area,
1647 GtkCellAreaContext *context,
1650 gint *minimum_width,
1651 gint *natural_width)
1653 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1654 GtkCellAreaBoxContext *box_context;
1655 GtkCellAreaBoxPrivate *priv;
1656 gint min_width, nat_width;
1658 g_return_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (context));
1660 box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
1663 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1665 /* Add up horizontal requests of width for height and push the overall
1666 * cached sizes for alignments */
1667 compute_size (box, priv->orientation, box_context, widget, height, &min_width, &nat_width);
1671 /* Juice: horizontally allocate cells into the for_height using the
1672 * alignments and then return the overall width for that height, and cache it */
1673 compute_size_for_opposing_orientation (box, box_context, widget, height, &min_width, &nat_width);
1677 *minimum_width = min_width;
1680 *natural_width = nat_width;
1684 gtk_cell_area_box_focus (GtkCellArea *area,
1685 GtkDirectionType direction)
1687 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
1688 GtkCellAreaBoxPrivate *priv = box->priv;
1689 gint cycle = FOCUS_NONE;
1690 gboolean cycled_focus = FALSE;
1691 GtkCellRenderer *focus_cell;
1693 focus_cell = gtk_cell_area_get_focus_cell (area);
1697 case GTK_DIR_TAB_FORWARD:
1700 case GTK_DIR_TAB_BACKWARD:
1704 if (priv->orientation == GTK_ORIENTATION_VERTICAL || !focus_cell)
1708 if (priv->orientation == GTK_ORIENTATION_VERTICAL || !focus_cell)
1712 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL || !focus_cell)
1716 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL || !focus_cell)
1723 if (cycle != FOCUS_NONE)
1725 gboolean found_cell = FALSE;
1729 /* If there is no focused cell, focus on the first (or last) one in the list */
1733 for (i = (cycle == FOCUS_NEXT) ? 0 : priv->groups->len -1;
1734 cycled_focus == FALSE && i >= 0 && i < priv->groups->len;
1735 i = (cycle == FOCUS_NEXT) ? i + 1 : i - 1)
1737 CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
1739 for (list = (cycle == FOCUS_NEXT) ? g_list_first (group->cells) : g_list_last (group->cells);
1740 list; list = (cycle == FOCUS_NEXT) ? list->next : list->prev)
1742 CellInfo *info = list->data;
1744 if (info->renderer == focus_cell)
1746 else if (found_cell)
1748 if (gtk_cell_renderer_can_focus (info->renderer))
1750 gtk_cell_area_set_focus_cell (area, info->renderer);
1752 cycled_focus = TRUE;
1761 gtk_cell_area_set_focus_cell (area, NULL);
1763 return cycled_focus;
1767 /*************************************************************
1768 * GtkCellLayoutIface *
1769 *************************************************************/
1771 gtk_cell_area_box_cell_layout_init (GtkCellLayoutIface *iface)
1773 iface->pack_start = gtk_cell_area_box_layout_pack_start;
1774 iface->pack_end = gtk_cell_area_box_layout_pack_end;
1775 iface->reorder = gtk_cell_area_box_layout_reorder;
1779 gtk_cell_area_box_layout_pack_start (GtkCellLayout *cell_layout,
1780 GtkCellRenderer *renderer,
1783 gtk_cell_area_box_pack_start (GTK_CELL_AREA_BOX (cell_layout), renderer, expand, TRUE);
1787 gtk_cell_area_box_layout_pack_end (GtkCellLayout *cell_layout,
1788 GtkCellRenderer *renderer,
1791 gtk_cell_area_box_pack_end (GTK_CELL_AREA_BOX (cell_layout), renderer, expand, TRUE);
1795 gtk_cell_area_box_layout_reorder (GtkCellLayout *cell_layout,
1796 GtkCellRenderer *renderer,
1799 GtkCellAreaBox *box = GTK_CELL_AREA_BOX (cell_layout);
1800 GtkCellAreaBoxPrivate *priv = box->priv;
1804 node = g_list_find_custom (priv->cells, renderer,
1805 (GCompareFunc)cell_info_find);
1811 priv->cells = g_list_delete_link (priv->cells, node);
1812 priv->cells = g_list_insert (priv->cells, info, position);
1814 cell_groups_rebuild (box);
1818 /*************************************************************
1820 *************************************************************/
1822 gtk_cell_area_box_new (void)
1824 return (GtkCellArea *)g_object_new (GTK_TYPE_CELL_AREA_BOX, NULL);
1828 gtk_cell_area_box_pack_start (GtkCellAreaBox *box,
1829 GtkCellRenderer *renderer,
1833 GtkCellAreaBoxPrivate *priv;
1836 g_return_if_fail (GTK_IS_CELL_AREA_BOX (box));
1837 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1841 if (g_list_find_custom (priv->cells, renderer,
1842 (GCompareFunc)cell_info_find))
1844 g_warning ("Refusing to add the same cell renderer to a GtkCellAreaBox twice");
1848 info = cell_info_new (renderer, GTK_PACK_START, expand, align);
1850 priv->cells = g_list_append (priv->cells, info);
1852 cell_groups_rebuild (box);
1856 gtk_cell_area_box_pack_end (GtkCellAreaBox *box,
1857 GtkCellRenderer *renderer,
1861 GtkCellAreaBoxPrivate *priv;
1864 g_return_if_fail (GTK_IS_CELL_AREA_BOX (box));
1865 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1869 if (g_list_find_custom (priv->cells, renderer,
1870 (GCompareFunc)cell_info_find))
1872 g_warning ("Refusing to add the same cell renderer to a GtkCellArea twice");
1876 info = cell_info_new (renderer, GTK_PACK_END, expand, align);
1878 priv->cells = g_list_append (priv->cells, info);
1880 cell_groups_rebuild (box);
1884 gtk_cell_area_box_get_spacing (GtkCellAreaBox *box)
1886 g_return_val_if_fail (GTK_IS_CELL_AREA_BOX (box), 0);
1888 return box->priv->spacing;
1892 gtk_cell_area_box_set_spacing (GtkCellAreaBox *box,
1895 GtkCellAreaBoxPrivate *priv;
1897 g_return_if_fail (GTK_IS_CELL_AREA_BOX (box));
1901 if (priv->spacing != spacing)
1903 priv->spacing = spacing;
1905 g_object_notify (G_OBJECT (box), "spacing");
1907 /* Notify that size needs to be requested again */
1908 flush_contexts (box);