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 * @Short_Description: An abstract class for laying out #GtkCellRenderers
29 * The #GtkCellArea is an abstract class for #GtkCellLayout widgets (also referred
30 * to as "layouting widgets") to interface with an arbitrary number of #GtkCellRenderers
31 * and interact with the user for a given #GtkTreeModel row.
33 * The cell area handles events, focus navigation, drawing and wraps geometrical
34 * size requests and allocations for a given row of data.
36 * Usually users dont have to interact with the #GtkCellArea directly unless they
37 * are implementing a cell layouting widget themselves.
39 * <refsect2 id="cell-area-geometry-management">
40 * <title>Requesting area sizes</title>
42 * As outlined in <link linkend="geometry-management">GtkWidget's
43 * geometry management section</link>, GTK+ uses a height-for-width
44 * geometry managemen system to compute the sizes of widgets and user
45 * interfaces. #GtkCellArea uses the same semantics to calculate the
46 * size of an area for an arbitrary number of #GtkTreeModel rows.
48 * When requesting the size of a cell area one needs to calculate
49 * the size for a handful of rows, this will be done differently by
50 * different layouting widgets. For instance a #GtkTreeViewColumn
51 * always lines up the areas from top to bottom while a #GtkIconView
52 * on the other hand might enforce that all areas received the same
53 * width and wrap the areas around, requesting height for more cell
54 * areas when allocated less width.
56 * It's also important for areas to maintain some cell
57 * alignments with areas rendered for adjacent rows (cells can
58 * appear "columnized" inside an area even when the size of
59 * cells are different in each row). For this reason the #GtkCellArea
60 * uses a #GtkCellAreaContext object to store the alignments
61 * and sizes along the way (as well as the overall largest minimum
62 * and natural size for all the rows which have been calculated
63 * with the said context).
65 * The #GtkCellAreaContext is an opaque object specific to the
66 * #GtkCellArea which created it (see gtk_cell_area_create_context()).
67 * The owning cell layouting widget can create as many contexts as
68 * it wishes to calculate sizes of rows which should receive the
69 * same size in at least one orientation (horizontally or vertically),
70 * however it's important that the same #GtkCellAreaContext which
71 * was used to request the sizes for a given #GtkTreeModel row be
72 * used when rendering or processing events for that row.
74 * In order to request the width of all the rows at the root level
75 * of a #GtkTreeModel one would do the following:
77 * <title>Requesting the width of a hand full of GtkTreeModel rows.</title>
83 * valid = gtk_tree_model_get_iter_first (model, &iter);
86 * gtk_cell_area_apply_attributes (area, model, &iter, FALSE, FALSE);
87 * gtk_cell_area_get_preferred_width (area, context, widget, NULL, NULL);
89 * valid = gtk_tree_model_iter_next (model, &iter);
91 * gtk_cell_area_context_get_preferred_width (context, &minimum_width, &natural_width);
94 * Note that in this example it's not important to observe the returned minimum and
95 * natural width of the area for each row unless the cell layouting object is actually
96 * interested in the widths of individual rows. The overall width is however stored
97 * in the accompanying #GtkCellAreaContext object and can be consulted at any time.
99 * This can be useful since #GtkCellLayout widgets usually have to support requesting
100 * and rendering rows in treemodels with an exceedingly large amount of rows. The
101 * #GtkCellLayout widget in that case would calculate the required width of the rows
102 * in an idle or timeout source (see g_timeout_add()) and when the widget is requested
103 * its actual width in #GtkWidgetClass.get_preferred_width() it can simply consult the
104 * width accumulated so far in the #GtkCellAreaContext object.
106 * A simple example where rows are rendered from top to bottom and take up the full
107 * width of the layouting widget would look like:
109 * <title>A typical #GtkWidgetClass.get_preferred_width() for a layouting widget.</title>
112 * foo_get_preferred_width (GtkWidget *widget,
113 * gint *minimum_size,
114 * gint *natural_size)
116 * Foo *foo = FOO (widget);
117 * FooPrivate *priv = foo->priv;
119 * foo_ensure_at_least_one_handfull_of_rows_have_been_requested (foo);
121 * gtk_cell_area_context_get_preferred_width (priv->context, minimum_size, natural_size);
126 * In the above example the Foo widget has to make sure that some row sizes have
127 * been calculated (the amount of rows that Foo judged was appropriate to request
128 * space for in a single timeout iteration) before simply returning the amount
129 * of space required by the area via the #GtkCellAreaContext.
131 * Requesting the height for width (or width for height) of an area is a similar
132 * task except in this case the #GtkCellAreaContext does not store the data (actually
133 * it does not know how much space the layouting widget plans to allocate it for
134 * every row, it's up to the layouting widget to render each row of data with
135 * the appropriate height and width which was requested by the #GtkCellArea).
137 * In order to request the height for width of all the rows at the root level
138 * of a #GtkTreeModel one would do the following:
140 * <title>Requesting the height for width of a hand full of GtkTreeModel rows.</title>
143 * gint minimum_height;
144 * gint natural_height;
145 * gint full_minimum_height = 0;
146 * gint full_natural_height = 0;
148 * valid = gtk_tree_model_get_iter_first (model, &iter);
151 * gtk_cell_area_apply_attributes (area, model, &iter, FALSE, FALSE);
152 * gtk_cell_area_get_preferred_height_for_width (area, context, widget,
153 * width, &minimum_height, &natural_height);
155 * if (width_is_for_allocation)
156 * cache_row_height (&iter, minimum_height, natural_height);
158 * full_minimum_height += minimum_height;
159 * full_natural_height += natural_height;
161 * valid = gtk_tree_model_iter_next (model, &iter);
166 * Note that in the above example we would need to cache the heights returned for each
167 * treemodel row so that we would know what sizes to render the areas for each row. However
168 * we would only want to really cache the heights if the request is intended for the
169 * layouting widgets real allocation.
171 * In some cases the layouting widget is requested the height for an arbitrary for_width,
172 * this is a special case for layouting widgets who need to request size for tens of thousands
173 * of treemodel rows. For this case it's only important that the layouting widget calculate
174 * one reasonably sized chunk of rows and return that height synchronously. The reasoning here
175 * is that any layouting widget is at least capable of synchronously calculating enough
176 * height to fill the screen height (or scrolled window height) in response to a single call to
177 * #GtkWidgetClass.get_preferred_height_for_width(). Returning a perfect height for width that
178 * is larger than the screen area is inconsequential since after the layouting receives an
179 * allocation from a scrolled window it simply continues to drive the the scrollbar
180 * values while more and mode height is required for the row heights that are calculated
184 * <refsect2 id="cell-area-rendering">
185 * <title>Rendering Areas</title>
187 * Once area sizes have been aquired at least for the rows in the visible area of the
188 * layouting widget they can be rendered at #GtkWidgetClass.draw() time.
190 * A crued example of how to render all the rows at the root level runs as follows:
192 * <title>Requesting the width of a hand full of GtkTreeModel rows.</title>
194 * GtkAllocation allocation;
195 * GdkRectangle cell_area = { 0, };
197 * gint minimum_width;
198 * gint natural_width;
200 * gtk_widget_get_allocation (widget, &allocation);
201 * cell_area.width = allocation.width;
203 * valid = gtk_tree_model_get_iter_first (model, &iter);
206 * cell_area.height = get_cached_height_for_row (&iter);
208 * gtk_cell_area_apply_attributes (area, model, &iter, FALSE, FALSE);
209 * gtk_cell_area_render (area, context, widget, cr,
210 * &cell_area, &cell_area, state_flags, FALSE);
212 * cell_area.y += cell_area.height;
214 * valid = gtk_tree_model_iter_next (model, &iter);
218 * Note that the cached height in this example really depends on how the layouting
219 * widget works. The layouting widget might decide to give every row it's minimum
220 * or natural height or if the model content is expected to fit inside the layouting
221 * widget with no scrolled window it would make sense to calculate the allocation
222 * for each row at #GtkWidget.size_allocate() time using gtk_distribute_natural_allocation().
225 * <refsect2 id="cell-area-events-and-focus">
226 * <title>Handling Events and Driving Keyboard Focus</title>
228 * Passing events to the area is as simple as handling events on any normal
229 * widget and then passing them to the gtk_cell_area_event() api as they come
230 * in. Usually #GtkCellArea is only interested in button events, however some
231 * customized derived areas can be implemented who are interested in handling
232 * other events. Handling an event can trigger the #GtkCellArea::focus-changed
233 * signal to fire as well as #GtkCellArea::add-editable in the case that
234 * an editable cell was clicked and needs to start editing.
236 * The #GtkCellArea drives keyboard focus from cell to cell in a way similar
237 * to #GtkWidget. For layouting widgets that support giving focus to cells it's
238 * important to remember to pass %GTK_CELL_RENDERER_FOCUSED to the area functions
239 * for the row that has focus and to tell the area to paint the focus at render
242 * Layouting widgets that accept focus on cells should implement the #GtkWidgetClass.focus()
243 * virtual method. The layouting widget is always responsible for knowing where
244 * #GtkTreeModel rows are rendered inside the widget, so at #GtkWidgetClass.focus() time
245 * the layouting widget should use the #GtkCellArea methods to navigate focus inside the
246 * area and then observe the GtkDirectionType to pass the focus to adjacent rows and
249 * A basic example of how the #GtkWidgetClass.focus() virtual method should be implemented:
251 * <title>Implementing keyboard focus navigation when displaying rows from top to bottom.</title>
254 * foo_focus (GtkWidget *widget,
255 * GtkDirectionType direction)
257 * Foo *foo = FOO (widget);
258 * FooPrivate *priv = foo->priv;
260 * gboolean have_focus = FALSE;
262 * focus_row = priv->focus_row;
264 * if (!gtk_widget_has_focus (widget))
265 * gtk_widget_grab_focus (widget);
267 * valid = gtk_tree_model_iter_nth_child (priv->model, &iter, NULL, priv->focus_row);
270 * gtk_cell_area_apply_attributes (priv->area, priv->model, &iter, FALSE, FALSE);
272 * if (gtk_cell_area_focus (priv->area, direction))
274 * priv->focus_row = focus_row;
280 * if (direction == GTK_DIR_RIGHT ||
281 * direction == GTK_DIR_LEFT)
283 * else if (direction == GTK_DIR_UP ||
284 * direction == GTK_DIR_TAB_BACKWARD)
286 * if (focus_row == 0)
291 * valid = gtk_tree_model_iter_nth_child (priv->model, &iter, NULL, focus_row);
296 * if (focus_row == last_row)
301 * valid = gtk_tree_model_iter_next (priv->model, &iter);
322 #include "gtkcelllayout.h"
323 #include "gtkcellarea.h"
324 #include "gtkcellareacontext.h"
325 #include "gtkmarshalers.h"
326 #include "gtkprivate.h"
328 #include <gobject/gvaluecollector.h>
332 static void gtk_cell_area_dispose (GObject *object);
333 static void gtk_cell_area_finalize (GObject *object);
334 static void gtk_cell_area_set_property (GObject *object,
338 static void gtk_cell_area_get_property (GObject *object,
343 /* GtkCellAreaClass */
344 static gint gtk_cell_area_real_event (GtkCellArea *area,
345 GtkCellAreaContext *context,
348 const GdkRectangle *cell_area,
349 GtkCellRendererState flags);
350 static void gtk_cell_area_real_apply_attributes (GtkCellArea *area,
351 GtkTreeModel *tree_model,
353 gboolean is_expander,
354 gboolean is_expanded);
355 static void gtk_cell_area_real_get_preferred_height_for_width (GtkCellArea *area,
356 GtkCellAreaContext *context,
359 gint *minimum_height,
360 gint *natural_height);
361 static void gtk_cell_area_real_get_preferred_width_for_height (GtkCellArea *area,
362 GtkCellAreaContext *context,
366 gint *natural_width);
367 static gboolean gtk_cell_area_real_is_activatable (GtkCellArea *area);
368 static gboolean gtk_cell_area_real_activate (GtkCellArea *area,
369 GtkCellAreaContext *context,
371 const GdkRectangle *cell_area,
372 GtkCellRendererState flags);
374 /* GtkCellLayoutIface */
375 static void gtk_cell_area_cell_layout_init (GtkCellLayoutIface *iface);
376 static void gtk_cell_area_pack_default (GtkCellLayout *cell_layout,
377 GtkCellRenderer *renderer,
379 static void gtk_cell_area_clear (GtkCellLayout *cell_layout);
380 static void gtk_cell_area_add_attribute (GtkCellLayout *cell_layout,
381 GtkCellRenderer *renderer,
382 const gchar *attribute,
384 static void gtk_cell_area_set_cell_data_func (GtkCellLayout *cell_layout,
385 GtkCellRenderer *cell,
386 GtkCellLayoutDataFunc func,
388 GDestroyNotify destroy);
389 static void gtk_cell_area_clear_attributes (GtkCellLayout *cell_layout,
390 GtkCellRenderer *renderer);
391 static void gtk_cell_area_reorder (GtkCellLayout *cell_layout,
392 GtkCellRenderer *cell,
394 static GList *gtk_cell_area_get_cells (GtkCellLayout *cell_layout);
397 /* Used in forall loop to check if a child renderer is present */
399 GtkCellRenderer *renderer;
400 gboolean has_renderer;
403 /* Attribute/Cell metadata */
405 const gchar *attribute;
412 GtkCellLayoutDataFunc func;
414 GDestroyNotify destroy;
417 static CellInfo *cell_info_new (GtkCellLayoutDataFunc func,
419 GDestroyNotify destroy);
420 static void cell_info_free (CellInfo *info);
421 static CellAttribute *cell_attribute_new (GtkCellRenderer *renderer,
422 const gchar *attribute,
424 static void cell_attribute_free (CellAttribute *attribute);
425 static gint cell_attribute_find (CellAttribute *cell_attribute,
426 const gchar *attribute);
428 /* Internal functions/signal emissions */
429 static void gtk_cell_area_add_editable (GtkCellArea *area,
430 GtkCellRenderer *renderer,
431 GtkCellEditable *editable,
432 GdkRectangle *cell_area);
433 static void gtk_cell_area_remove_editable (GtkCellArea *area,
434 GtkCellRenderer *renderer,
435 GtkCellEditable *editable);
436 static void gtk_cell_area_set_edit_widget (GtkCellArea *area,
437 GtkCellEditable *editable);
438 static void gtk_cell_area_set_edited_cell (GtkCellArea *area,
439 GtkCellRenderer *renderer);
442 /* Struct to pass data along while looping over
443 * cell renderers to apply attributes
449 gboolean is_expander;
450 gboolean is_expanded;
453 struct _GtkCellAreaPrivate
455 /* The GtkCellArea bookkeeps any connected
456 * attributes in this hash table.
458 GHashTable *cell_info;
460 /* Current path is saved as a side-effect
461 * of gtk_cell_area_apply_attributes() */
464 /* Current cell being edited and editable widget used */
465 GtkCellEditable *edit_widget;
466 GtkCellRenderer *edited_cell;
468 /* Signal connections to the editable widget */
469 gulong remove_widget_id;
471 /* Currently focused cell */
472 GtkCellRenderer *focus_cell;
474 /* Tracking which cells are focus siblings of focusable cells */
475 GHashTable *focus_siblings;
477 /* Detail string to pass to gtk_paint_*() functions */
489 SIGNAL_APPLY_ATTRIBUTES,
491 SIGNAL_REMOVE_EDITABLE,
492 SIGNAL_FOCUS_CHANGED,
496 /* Keep the paramspec pool internal, no need to deliver notifications
497 * on cells. at least no percieved need for now */
498 static GParamSpecPool *cell_property_pool = NULL;
499 static guint cell_area_signals[LAST_SIGNAL] = { 0 };
501 #define PARAM_SPEC_PARAM_ID(pspec) ((pspec)->param_id)
502 #define PARAM_SPEC_SET_PARAM_ID(pspec, id) ((pspec)->param_id = (id))
505 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GtkCellArea, gtk_cell_area, G_TYPE_INITIALLY_UNOWNED,
506 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
507 gtk_cell_area_cell_layout_init));
510 gtk_cell_area_init (GtkCellArea *area)
512 GtkCellAreaPrivate *priv;
514 area->priv = G_TYPE_INSTANCE_GET_PRIVATE (area,
519 priv->cell_info = g_hash_table_new_full (g_direct_hash,
522 (GDestroyNotify)cell_info_free);
524 priv->focus_siblings = g_hash_table_new_full (g_direct_hash,
527 (GDestroyNotify)g_list_free);
529 priv->focus_cell = NULL;
530 priv->edited_cell = NULL;
531 priv->edit_widget = NULL;
533 priv->remove_widget_id = 0;
537 gtk_cell_area_class_init (GtkCellAreaClass *class)
539 GObjectClass *object_class = G_OBJECT_CLASS (class);
542 object_class->dispose = gtk_cell_area_dispose;
543 object_class->finalize = gtk_cell_area_finalize;
544 object_class->get_property = gtk_cell_area_get_property;
545 object_class->set_property = gtk_cell_area_set_property;
549 class->remove = NULL;
550 class->forall = NULL;
551 class->event = gtk_cell_area_real_event;
552 class->render = NULL;
553 class->apply_attributes = gtk_cell_area_real_apply_attributes;
556 class->create_context = NULL;
557 class->get_request_mode = NULL;
558 class->get_preferred_width = NULL;
559 class->get_preferred_height = NULL;
560 class->get_preferred_height_for_width = gtk_cell_area_real_get_preferred_height_for_width;
561 class->get_preferred_width_for_height = gtk_cell_area_real_get_preferred_width_for_height;
564 class->is_activatable = gtk_cell_area_real_is_activatable;
565 class->activate = gtk_cell_area_real_activate;
570 * GtkCellArea::apply-attributes:
571 * @area: the #GtkCellArea to apply the attributes to
572 * @model: the #GtkTreeModel to apply the attributes from
573 * @iter: the #GtkTreeIter indicating which row to apply the attributes of
574 * @is_expander: whether the view shows children for this row
575 * @is_expanded: whether the view is currently showing the children of this row
577 * This signal is emitted whenever applying attributes to @area from @model
581 cell_area_signals[SIGNAL_APPLY_ATTRIBUTES] =
582 g_signal_new (I_("apply-attributes"),
583 G_OBJECT_CLASS_TYPE (object_class),
585 G_STRUCT_OFFSET (GtkCellAreaClass, apply_attributes),
587 _gtk_marshal_VOID__OBJECT_BOXED_BOOLEAN_BOOLEAN,
595 * GtkCellArea::add-editable:
596 * @area: the #GtkCellArea where editing started
597 * @renderer: the #GtkCellRenderer that started the edited
598 * @editable: the #GtkCellEditable widget to add
599 * @cell_area: the #GtkWidget relative #GdkRectangle coordinates
600 * where @editable should be added
601 * @path: the #GtkTreePath string this edit was initiated for
603 * Indicates that editing has started on @renderer and that @editable
604 * should be added to the owning cell layouting widget at @cell_area.
608 cell_area_signals[SIGNAL_ADD_EDITABLE] =
609 g_signal_new (I_("add-editable"),
610 G_OBJECT_CLASS_TYPE (object_class),
612 0, /* No class closure here */
614 _gtk_marshal_VOID__OBJECT_OBJECT_BOXED_STRING,
616 GTK_TYPE_CELL_RENDERER,
617 GTK_TYPE_CELL_EDITABLE,
623 * GtkCellArea::remove-editable:
624 * @area: the #GtkCellArea where editing finished
625 * @renderer: the #GtkCellRenderer that finished editeding
626 * @editable: the #GtkCellEditable widget to remove
628 * Indicates that editing finished on @renderer and that @editable
629 * should be removed from the owning cell layouting widget.
633 cell_area_signals[SIGNAL_REMOVE_EDITABLE] =
634 g_signal_new (I_("remove-editable"),
635 G_OBJECT_CLASS_TYPE (object_class),
637 0, /* No class closure here */
639 _gtk_marshal_VOID__OBJECT_OBJECT,
641 GTK_TYPE_CELL_RENDERER,
642 GTK_TYPE_CELL_EDITABLE);
645 * GtkCellArea::focus-changed:
646 * @area: the #GtkCellArea where focus changed
647 * @renderer: the #GtkCellRenderer that has focus
648 * @path: the current #GtkTreePath string set for @area
650 * Indicates that focus changed on this @area. This signal
651 * is emitted either as a result of focus handling or event
654 * It's possible that the signal is emitted even if the
655 * currently focused renderer did not change, this is
656 * because focus may change to the same renderer in the
657 * same cell area for a different row of data.
661 cell_area_signals[SIGNAL_FOCUS_CHANGED] =
662 g_signal_new (I_("focus-changed"),
663 G_OBJECT_CLASS_TYPE (object_class),
665 0, /* No class closure here */
667 _gtk_marshal_VOID__OBJECT_STRING,
669 GTK_TYPE_CELL_RENDERER,
674 * GtkCellArea:focus-cell:
676 * The cell in the area that currently has focus
680 g_object_class_install_property (object_class,
685 P_("The cell which currently has focus"),
686 GTK_TYPE_CELL_RENDERER,
687 GTK_PARAM_READWRITE));
690 * GtkCellArea:edited-cell:
692 * The cell in the area that is currently edited
694 * This property is read-only and only changes as
695 * a result of a call gtk_cell_area_activate_cell().
699 g_object_class_install_property (object_class,
704 P_("The cell which is currently being edited"),
705 GTK_TYPE_CELL_RENDERER,
709 * GtkCellArea:edit-widget:
711 * The widget currently editing the edited cell
713 * This property is read-only and only changes as
714 * a result of a call gtk_cell_area_activate_cell().
718 g_object_class_install_property (object_class,
723 P_("The widget currently editing the edited cell"),
724 GTK_TYPE_CELL_RENDERER,
727 /* Pool for Cell Properties */
728 if (!cell_property_pool)
729 cell_property_pool = g_param_spec_pool_new (FALSE);
731 g_type_class_add_private (object_class, sizeof (GtkCellAreaPrivate));
734 /*************************************************************
736 *************************************************************/
738 cell_info_new (GtkCellLayoutDataFunc func,
740 GDestroyNotify destroy)
742 CellInfo *info = g_slice_new0 (CellInfo);
746 info->destroy = destroy;
752 cell_info_free (CellInfo *info)
755 info->destroy (info->data);
757 g_slist_foreach (info->attributes, (GFunc)cell_attribute_free, NULL);
758 g_slist_free (info->attributes);
760 g_slice_free (CellInfo, info);
763 static CellAttribute *
764 cell_attribute_new (GtkCellRenderer *renderer,
765 const gchar *attribute,
770 /* Check if the attribute really exists and point to
771 * the property string installed on the cell renderer
772 * class (dont dup the string)
774 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (renderer), attribute);
778 CellAttribute *cell_attribute = g_slice_new (CellAttribute);
780 cell_attribute->attribute = pspec->name;
781 cell_attribute->column = column;
783 return cell_attribute;
790 cell_attribute_free (CellAttribute *attribute)
792 g_slice_free (CellAttribute, attribute);
795 /* GCompareFunc for g_slist_find_custom() */
797 cell_attribute_find (CellAttribute *cell_attribute,
798 const gchar *attribute)
800 return g_strcmp0 (cell_attribute->attribute, attribute);
803 /*************************************************************
805 *************************************************************/
807 gtk_cell_area_finalize (GObject *object)
809 GtkCellArea *area = GTK_CELL_AREA (object);
810 GtkCellAreaPrivate *priv = area->priv;
812 /* All cell renderers should already be removed at this point,
813 * just kill our (empty) hash tables here.
815 g_hash_table_destroy (priv->cell_info);
816 g_hash_table_destroy (priv->focus_siblings);
818 g_free (priv->current_path);
820 G_OBJECT_CLASS (gtk_cell_area_parent_class)->finalize (object);
825 gtk_cell_area_dispose (GObject *object)
827 /* This removes every cell renderer that may be added to the GtkCellArea,
828 * subclasses should be breaking references to the GtkCellRenderers
831 gtk_cell_layout_clear (GTK_CELL_LAYOUT (object));
833 /* Remove any ref to a focused/edited cell */
834 gtk_cell_area_set_focus_cell (GTK_CELL_AREA (object), NULL);
835 gtk_cell_area_set_edited_cell (GTK_CELL_AREA (object), NULL);
836 gtk_cell_area_set_edit_widget (GTK_CELL_AREA (object), NULL);
838 G_OBJECT_CLASS (gtk_cell_area_parent_class)->dispose (object);
842 gtk_cell_area_set_property (GObject *object,
847 GtkCellArea *area = GTK_CELL_AREA (object);
851 case PROP_FOCUS_CELL:
852 gtk_cell_area_set_focus_cell (area, (GtkCellRenderer *)g_value_get_object (value));
855 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
861 gtk_cell_area_get_property (GObject *object,
866 GtkCellArea *area = GTK_CELL_AREA (object);
867 GtkCellAreaPrivate *priv = area->priv;
871 case PROP_FOCUS_CELL:
872 g_value_set_object (value, priv->focus_cell);
874 case PROP_EDITED_CELL:
875 g_value_set_object (value, priv->edited_cell);
877 case PROP_EDIT_WIDGET:
878 g_value_set_object (value, priv->edit_widget);
881 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
886 /*************************************************************
888 *************************************************************/
890 gtk_cell_area_real_event (GtkCellArea *area,
891 GtkCellAreaContext *context,
894 const GdkRectangle *cell_area,
895 GtkCellRendererState flags)
897 GtkCellAreaPrivate *priv = area->priv;
899 if (event->type == GDK_KEY_PRESS && (flags & GTK_CELL_RENDERER_FOCUSED) != 0)
901 GdkEventKey *key_event = (GdkEventKey *)event;
903 /* Cancel any edits in progress */
904 if (priv->edited_cell && (key_event->keyval == GDK_KEY_Escape))
906 gtk_cell_area_stop_editing (area, TRUE);
915 apply_cell_attributes (GtkCellRenderer *renderer,
919 CellAttribute *attribute;
921 GValue value = { 0, };
922 gboolean is_expander;
923 gboolean is_expanded;
925 g_object_freeze_notify (G_OBJECT (renderer));
927 /* Whether a row expands or is presently expanded can only be
928 * provided by the view (as these states can vary across views
929 * accessing the same model).
931 g_object_get (renderer, "is-expander", &is_expander, NULL);
932 if (is_expander != data->is_expander)
933 g_object_set (renderer, "is-expander", data->is_expander, NULL);
935 g_object_get (renderer, "is-expanded", &is_expanded, NULL);
936 if (is_expanded != data->is_expanded)
937 g_object_set (renderer, "is-expanded", data->is_expanded, NULL);
939 /* Apply the attributes directly to the renderer */
940 for (list = info->attributes; list; list = list->next)
942 attribute = list->data;
944 gtk_tree_model_get_value (data->model, data->iter, attribute->column, &value);
945 g_object_set_property (G_OBJECT (renderer), attribute->attribute, &value);
946 g_value_unset (&value);
949 /* Call any GtkCellLayoutDataFunc that may have been set by the user
952 info->func (GTK_CELL_LAYOUT (data->area), renderer,
953 data->model, data->iter, info->data);
955 g_object_thaw_notify (G_OBJECT (renderer));
959 gtk_cell_area_real_apply_attributes (GtkCellArea *area,
960 GtkTreeModel *tree_model,
962 gboolean is_expander,
963 gboolean is_expanded)
966 GtkCellAreaPrivate *priv;
972 /* Feed in data needed to apply to every renderer */
974 data.model = tree_model;
976 data.is_expander = is_expander;
977 data.is_expanded = is_expanded;
979 /* Go over any cells that have attributes or custom GtkCellLayoutDataFuncs and
980 * apply the data from the treemodel */
981 g_hash_table_foreach (priv->cell_info, (GHFunc)apply_cell_attributes, &data);
983 /* Update the currently applied path */
984 g_free (priv->current_path);
985 path = gtk_tree_model_get_path (tree_model, iter);
986 priv->current_path = gtk_tree_path_to_string (path);
987 gtk_tree_path_free (path);
991 gtk_cell_area_real_get_preferred_height_for_width (GtkCellArea *area,
992 GtkCellAreaContext *context,
995 gint *minimum_height,
996 gint *natural_height)
998 /* If the area doesnt do height-for-width, fallback on base preferred height */
999 GTK_CELL_AREA_GET_CLASS (area)->get_preferred_width (area, context, widget, minimum_height, natural_height);
1003 gtk_cell_area_real_get_preferred_width_for_height (GtkCellArea *area,
1004 GtkCellAreaContext *context,
1007 gint *minimum_width,
1008 gint *natural_width)
1010 /* If the area doesnt do width-for-height, fallback on base preferred width */
1011 GTK_CELL_AREA_GET_CLASS (area)->get_preferred_width (area, context, widget, minimum_width, natural_width);
1015 get_is_activatable (GtkCellRenderer *renderer,
1016 gboolean *activatable)
1019 if (gtk_cell_renderer_is_activatable (renderer))
1020 *activatable = TRUE;
1024 gtk_cell_area_real_is_activatable (GtkCellArea *area)
1026 gboolean activatable = FALSE;
1028 /* Checks if any renderer can focus for the currently applied
1031 * Subclasses can override this in the case that they are also
1032 * rendering widgets as well as renderers.
1034 gtk_cell_area_forall (area, (GtkCellCallback)get_is_activatable, &activatable);
1040 gtk_cell_area_real_activate (GtkCellArea *area,
1041 GtkCellAreaContext *context,
1043 const GdkRectangle *cell_area,
1044 GtkCellRendererState flags)
1046 GtkCellAreaPrivate *priv = area->priv;
1047 GdkRectangle background_area;
1048 GtkCellRenderer *activate_cell = NULL;
1050 if (priv->focus_cell)
1051 activate_cell = priv->focus_cell;
1056 /* GtkTreeView sometimes wants to activate a cell when no
1057 * cells are in focus.
1059 cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (area));
1060 for (l = cells; l && !activate_cell; l = l->next)
1062 GtkCellRenderer *renderer = l->data;
1064 if (gtk_cell_renderer_is_activatable (renderer))
1065 activate_cell = renderer;
1067 g_list_free (cells);
1073 /* Get the allocation of the focused cell.
1075 gtk_cell_area_get_cell_allocation (area, context, widget, activate_cell,
1076 cell_area, &background_area);
1078 /* Activate or Edit the cell
1080 * Currently just not sending an event, renderers afaics dont use
1081 * the event argument anyway, worst case is we can synthesize one.
1083 if (gtk_cell_area_activate_cell (area, widget, activate_cell, NULL,
1084 &background_area, flags))
1091 /*************************************************************
1092 * GtkCellLayoutIface *
1093 *************************************************************/
1095 gtk_cell_area_cell_layout_init (GtkCellLayoutIface *iface)
1097 iface->pack_start = gtk_cell_area_pack_default;
1098 iface->pack_end = gtk_cell_area_pack_default;
1099 iface->clear = gtk_cell_area_clear;
1100 iface->add_attribute = gtk_cell_area_add_attribute;
1101 iface->set_cell_data_func = gtk_cell_area_set_cell_data_func;
1102 iface->clear_attributes = gtk_cell_area_clear_attributes;
1103 iface->reorder = gtk_cell_area_reorder;
1104 iface->get_cells = gtk_cell_area_get_cells;
1108 gtk_cell_area_pack_default (GtkCellLayout *cell_layout,
1109 GtkCellRenderer *renderer,
1112 gtk_cell_area_add (GTK_CELL_AREA (cell_layout), renderer);
1116 gtk_cell_area_clear (GtkCellLayout *cell_layout)
1118 GtkCellArea *area = GTK_CELL_AREA (cell_layout);
1120 gtk_cell_layout_get_cells (cell_layout);
1122 for (l = cells; l; l = l->next)
1124 GtkCellRenderer *renderer = l->data;
1125 gtk_cell_area_remove (area, renderer);
1128 g_list_free (cells);
1132 gtk_cell_area_add_attribute (GtkCellLayout *cell_layout,
1133 GtkCellRenderer *renderer,
1134 const gchar *attribute,
1137 gtk_cell_area_attribute_connect (GTK_CELL_AREA (cell_layout),
1138 renderer, attribute, column);
1142 gtk_cell_area_set_cell_data_func (GtkCellLayout *cell_layout,
1143 GtkCellRenderer *renderer,
1144 GtkCellLayoutDataFunc func,
1146 GDestroyNotify destroy)
1148 GtkCellArea *area = GTK_CELL_AREA (cell_layout);
1149 GtkCellAreaPrivate *priv = area->priv;
1152 info = g_hash_table_lookup (priv->cell_info, renderer);
1156 if (info->destroy && info->data)
1157 info->destroy (info->data);
1162 info->data = func_data;
1163 info->destroy = destroy;
1169 info->destroy = NULL;
1174 info = cell_info_new (func, func_data, destroy);
1176 g_hash_table_insert (priv->cell_info, renderer, info);
1181 gtk_cell_area_clear_attributes (GtkCellLayout *cell_layout,
1182 GtkCellRenderer *renderer)
1184 GtkCellArea *area = GTK_CELL_AREA (cell_layout);
1185 GtkCellAreaPrivate *priv = area->priv;
1188 info = g_hash_table_lookup (priv->cell_info, renderer);
1192 g_slist_foreach (info->attributes, (GFunc)cell_attribute_free, NULL);
1193 g_slist_free (info->attributes);
1195 info->attributes = NULL;
1200 gtk_cell_area_reorder (GtkCellLayout *cell_layout,
1201 GtkCellRenderer *cell,
1204 g_warning ("GtkCellLayout::reorder not implemented for `%s'",
1205 g_type_name (G_TYPE_FROM_INSTANCE (cell_layout)));
1209 accum_cells (GtkCellRenderer *renderer,
1212 *accum = g_list_prepend (*accum, renderer);
1216 gtk_cell_area_get_cells (GtkCellLayout *cell_layout)
1218 GList *cells = NULL;
1220 gtk_cell_area_forall (GTK_CELL_AREA (cell_layout),
1221 (GtkCellCallback)accum_cells,
1224 return g_list_reverse (cells);
1228 /*************************************************************
1230 *************************************************************/
1233 * gtk_cell_area_add:
1234 * @area: a #GtkCellArea
1235 * @renderer: the #GtkCellRenderer to add to @area
1237 * Adds @renderer to @area with the default child cell properties.
1242 gtk_cell_area_add (GtkCellArea *area,
1243 GtkCellRenderer *renderer)
1245 GtkCellAreaClass *class;
1247 g_return_if_fail (GTK_IS_CELL_AREA (area));
1248 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1250 class = GTK_CELL_AREA_GET_CLASS (area);
1253 class->add (area, renderer);
1255 g_warning ("GtkCellAreaClass::add not implemented for `%s'",
1256 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1260 * gtk_cell_area_remove:
1261 * @area: a #GtkCellArea
1262 * @renderer: the #GtkCellRenderer to add to @area
1264 * Removes @renderer from @area.
1269 gtk_cell_area_remove (GtkCellArea *area,
1270 GtkCellRenderer *renderer)
1272 GtkCellAreaClass *class;
1273 GtkCellAreaPrivate *priv;
1274 GList *renderers, *l;
1276 g_return_if_fail (GTK_IS_CELL_AREA (area));
1277 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1279 class = GTK_CELL_AREA_GET_CLASS (area);
1282 /* Remove any custom attributes and custom cell data func here first */
1283 g_hash_table_remove (priv->cell_info, renderer);
1285 /* Remove focus siblings of this renderer */
1286 g_hash_table_remove (priv->focus_siblings, renderer);
1288 /* Remove this renderer from any focus renderer's sibling list */
1289 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (area));
1291 for (l = renderers; l; l = l->next)
1293 GtkCellRenderer *focus_renderer = l->data;
1295 if (gtk_cell_area_is_focus_sibling (area, focus_renderer, renderer))
1297 gtk_cell_area_remove_focus_sibling (area, focus_renderer, renderer);
1302 g_list_free (renderers);
1305 class->remove (area, renderer);
1307 g_warning ("GtkCellAreaClass::remove not implemented for `%s'",
1308 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1312 get_has_renderer (GtkCellRenderer *renderer,
1313 HasRendererCheck *check)
1315 if (renderer == check->renderer)
1316 check->has_renderer = TRUE;
1320 * gtk_cell_area_has_renderer:
1321 * @area: a #GtkCellArea
1322 * @renderer: the #GtkCellRenderer to check
1324 * Checks if @area contains @renderer.
1326 * Return value: %TRUE if @renderer is in the @area.
1331 gtk_cell_area_has_renderer (GtkCellArea *area,
1332 GtkCellRenderer *renderer)
1334 HasRendererCheck check = { renderer, FALSE };
1336 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
1337 g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), FALSE);
1339 gtk_cell_area_forall (area, (GtkCellCallback)get_has_renderer, &check);
1341 return check.has_renderer;
1345 * gtk_cell_area_forall:
1346 * @area: a #GtkCellArea
1347 * @callback: the #GtkCellCallback to call
1348 * @callback_data: user provided data pointer
1350 * Calls @callback for every #GtkCellRenderer in @area.
1355 gtk_cell_area_forall (GtkCellArea *area,
1356 GtkCellCallback callback,
1357 gpointer callback_data)
1359 GtkCellAreaClass *class;
1361 g_return_if_fail (GTK_IS_CELL_AREA (area));
1362 g_return_if_fail (callback != NULL);
1364 class = GTK_CELL_AREA_GET_CLASS (area);
1367 class->forall (area, callback, callback_data);
1369 g_warning ("GtkCellAreaClass::forall not implemented for `%s'",
1370 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1374 * gtk_cell_area_get_cell_allocation:
1375 * @area: a #GtkCellArea
1376 * @context: the #GtkCellAreaContext used to hold sizes for @area.
1377 * @widget: the #GtkWidget that @area is rendering on
1378 * @renderer: the #GtkCellRenderer to get the allocation for
1379 * @cell_area: the whole allocated area for @area in @widget
1381 * @allocation: (out): where to store the allocation for @renderer
1383 * Derives the allocation of @renderer inside @area if @area
1384 * were to be renderered in @cell_area.
1389 gtk_cell_area_get_cell_allocation (GtkCellArea *area,
1390 GtkCellAreaContext *context,
1392 GtkCellRenderer *renderer,
1393 const GdkRectangle *cell_area,
1394 GdkRectangle *allocation)
1396 GtkCellAreaClass *class;
1398 g_return_if_fail (GTK_IS_CELL_AREA (area));
1399 g_return_if_fail (GTK_IS_CELL_AREA_CONTEXT (context));
1400 g_return_if_fail (GTK_IS_WIDGET (widget));
1401 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1402 g_return_if_fail (cell_area != NULL);
1403 g_return_if_fail (allocation != NULL);
1405 class = GTK_CELL_AREA_GET_CLASS (area);
1407 if (class->get_cell_allocation)
1408 class->get_cell_allocation (area, context, widget, renderer, cell_area, allocation);
1410 g_warning ("GtkCellAreaClass::get_cell_allocation not implemented for `%s'",
1411 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1415 * gtk_cell_area_event:
1416 * @area: a #GtkCellArea
1417 * @context: the #GtkCellAreaContext for this row of data.
1418 * @widget: the #GtkWidget that @area is rendering to
1419 * @event: the #GdkEvent to handle
1420 * @cell_area: the @widget relative coordinates for @area
1421 * @flags: the #GtkCellRendererState for @area in this row.
1423 * Delegates event handling to a #GtkCellArea.
1425 * Return value: %TRUE if the event was handled by @area.
1430 gtk_cell_area_event (GtkCellArea *area,
1431 GtkCellAreaContext *context,
1434 const GdkRectangle *cell_area,
1435 GtkCellRendererState flags)
1437 GtkCellAreaClass *class;
1439 g_return_val_if_fail (GTK_IS_CELL_AREA (area), 0);
1440 g_return_val_if_fail (GTK_IS_CELL_AREA_CONTEXT (context), 0);
1441 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
1442 g_return_val_if_fail (event != NULL, 0);
1443 g_return_val_if_fail (cell_area != NULL, 0);
1445 class = GTK_CELL_AREA_GET_CLASS (area);
1448 return class->event (area, context, widget, event, cell_area, flags);
1450 g_warning ("GtkCellAreaClass::event not implemented for `%s'",
1451 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1456 * gtk_cell_area_render:
1457 * @area: a #GtkCellArea
1458 * @context: the #GtkCellAreaContext for this row of data.
1459 * @widget: the #GtkWidget that @area is rendering to
1460 * @cr: the #cairo_t to render with
1461 * @background_area: the @widget relative coordinates for @area's background
1462 * @cell_area: the @widget relative coordinates for @area
1463 * @flags: the #GtkCellRendererState for @area in this row.
1464 * @paint_focus: whether @area should paint focus on focused cells for focused rows or not.
1466 * Renders @area's cells according to @area's layout onto @widget at
1467 * the given coordinates.
1472 gtk_cell_area_render (GtkCellArea *area,
1473 GtkCellAreaContext *context,
1476 const GdkRectangle *background_area,
1477 const GdkRectangle *cell_area,
1478 GtkCellRendererState flags,
1479 gboolean paint_focus)
1481 GtkCellAreaClass *class;
1483 g_return_if_fail (GTK_IS_CELL_AREA (area));
1484 g_return_if_fail (GTK_IS_CELL_AREA_CONTEXT (context));
1485 g_return_if_fail (GTK_IS_WIDGET (widget));
1486 g_return_if_fail (cr != NULL);
1487 g_return_if_fail (background_area != NULL);
1488 g_return_if_fail (cell_area != NULL);
1490 class = GTK_CELL_AREA_GET_CLASS (area);
1493 class->render (area, context, widget, cr, background_area, cell_area, flags, paint_focus);
1495 g_warning ("GtkCellAreaClass::render not implemented for `%s'",
1496 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1500 * gtk_cell_area_set_style_detail:
1501 * @area: a #GtkCellArea
1502 * @detail: the #GtkStyle detail string to set
1504 * Sets the detail string used in any gtk_paint_*() functions
1510 gtk_cell_area_set_style_detail (GtkCellArea *area,
1511 const gchar *detail)
1513 GtkCellAreaPrivate *priv;
1515 g_return_if_fail (GTK_IS_CELL_AREA (area));
1519 if (g_strcmp0 (priv->style_detail, detail) != 0)
1521 g_free (priv->style_detail);
1522 priv->style_detail = g_strdup (detail);
1527 * gtk_cell_area_get_style_detail:
1528 * @area: a #GtkCellArea
1530 * Gets the detail string used in any gtk_paint_*() functions
1533 * Return value: the detail string, the string belongs to the area and should not be freed.
1537 G_CONST_RETURN gchar *
1538 gtk_cell_area_get_style_detail (GtkCellArea *area)
1540 GtkCellAreaPrivate *priv;
1542 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
1546 return priv->style_detail;
1549 /*************************************************************
1551 *************************************************************/
1553 * gtk_cell_area_create_context:
1554 * @area: a #GtkCellArea
1556 * Creates a #GtkCellAreaContext to be used with @area for
1557 * all purposes. #GtkCellAreaContext stores geometry information
1558 * for rows for which it was operated on, it is important to use
1559 * the same context for the same row of data at all times (i.e.
1560 * one should render and handle events with the same #GtkCellAreaContext
1561 * which was used to request the size of those rows of data).
1563 * Return value: (transfer full): a newly created #GtkCellAreaContext which can be used with @area.
1567 GtkCellAreaContext *
1568 gtk_cell_area_create_context (GtkCellArea *area)
1570 GtkCellAreaClass *class;
1572 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
1574 class = GTK_CELL_AREA_GET_CLASS (area);
1576 if (class->create_context)
1577 return class->create_context (area);
1579 g_warning ("GtkCellAreaClass::create_context not implemented for `%s'",
1580 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1587 * gtk_cell_area_get_request_mode:
1588 * @area: a #GtkCellArea
1590 * Gets whether the area prefers a height-for-width layout
1591 * or a width-for-height layout.
1593 * Return value: The #GtkSizeRequestMode preferred by @area.
1598 gtk_cell_area_get_request_mode (GtkCellArea *area)
1600 GtkCellAreaClass *class;
1602 g_return_val_if_fail (GTK_IS_CELL_AREA (area),
1603 GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH);
1605 class = GTK_CELL_AREA_GET_CLASS (area);
1607 if (class->get_request_mode)
1608 return class->get_request_mode (area);
1610 g_warning ("GtkCellAreaClass::get_request_mode not implemented for `%s'",
1611 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1613 return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
1617 * gtk_cell_area_get_preferred_width:
1618 * @area: a #GtkCellArea
1619 * @context: the #GtkCellAreaContext to perform this request with
1620 * @widget: the #GtkWidget where @area will be rendering
1621 * @minimum_width: (out) (allow-none): location to store the minimum width, or %NULL
1622 * @natural_width: (out) (allow-none): location to store the natural width, or %NULL
1624 * Retrieves a cell area's initial minimum and natural width.
1626 * @area will store some geometrical information in @context along the way,
1627 * when requesting sizes over an arbitrary number of rows, its not important
1628 * to check the @minimum_width and @natural_width of this call but rather to
1629 * consult gtk_cell_area_context_get_preferred_width() after a series of
1635 gtk_cell_area_get_preferred_width (GtkCellArea *area,
1636 GtkCellAreaContext *context,
1638 gint *minimum_width,
1639 gint *natural_width)
1641 GtkCellAreaClass *class;
1643 g_return_if_fail (GTK_IS_CELL_AREA (area));
1644 g_return_if_fail (GTK_IS_WIDGET (widget));
1646 class = GTK_CELL_AREA_GET_CLASS (area);
1648 if (class->get_preferred_width)
1649 class->get_preferred_width (area, context, widget, minimum_width, natural_width);
1651 g_warning ("GtkCellAreaClass::get_preferred_width not implemented for `%s'",
1652 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1656 * gtk_cell_area_get_preferred_height_for_width:
1657 * @area: a #GtkCellArea
1658 * @context: the #GtkCellAreaContext which has already been requested for widths.
1659 * @widget: the #GtkWidget where @area will be rendering
1660 * @width: the width for which to check the height of this area
1661 * @minimum_height: (out) (allow-none): location to store the minimum height, or %NULL
1662 * @natural_height: (out) (allow-none): location to store the natural height, or %NULL
1664 * Retrieves a cell area's minimum and natural height if it would be given
1665 * the specified @width.
1667 * @area stores some geometrical information in @context along the way
1668 * while calling gtk_cell_area_get_preferred_width(), it's important to
1669 * perform a series of gtk_cell_area_get_preferred_width() requests with
1670 * @context first and then call gtk_cell_area_get_preferred_height_for_width()
1671 * on each cell area individually to get the height for width of each
1672 * fully requested row.
1674 * If at some point, the width of a single row changes, it should be
1675 * requested with gtk_cell_area_get_preferred_width() again and then
1676 * the full width of the requested rows checked again with
1677 * gtk_cell_area_context_get_preferred_width().
1682 gtk_cell_area_get_preferred_height_for_width (GtkCellArea *area,
1683 GtkCellAreaContext *context,
1686 gint *minimum_height,
1687 gint *natural_height)
1689 GtkCellAreaClass *class;
1691 g_return_if_fail (GTK_IS_CELL_AREA (area));
1692 g_return_if_fail (GTK_IS_WIDGET (widget));
1694 class = GTK_CELL_AREA_GET_CLASS (area);
1695 class->get_preferred_height_for_width (area, context, widget, width, minimum_height, natural_height);
1700 * gtk_cell_area_get_preferred_height:
1701 * @area: a #GtkCellArea
1702 * @context: the #GtkCellAreaContext to perform this request with
1703 * @widget: the #GtkWidget where @area will be rendering
1704 * @minimum_height: (out) (allow-none): location to store the minimum height, or %NULL
1705 * @natural_height: (out) (allow-none): location to store the natural height, or %NULL
1707 * Retrieves a cell area's initial minimum and natural height.
1709 * @area will store some geometrical information in @context along the way,
1710 * when requesting sizes over an arbitrary number of rows, its not important
1711 * to check the @minimum_height and @natural_height of this call but rather to
1712 * consult gtk_cell_area_context_get_preferred_height() after a series of
1718 gtk_cell_area_get_preferred_height (GtkCellArea *area,
1719 GtkCellAreaContext *context,
1721 gint *minimum_height,
1722 gint *natural_height)
1724 GtkCellAreaClass *class;
1726 g_return_if_fail (GTK_IS_CELL_AREA (area));
1727 g_return_if_fail (GTK_IS_WIDGET (widget));
1729 class = GTK_CELL_AREA_GET_CLASS (area);
1731 if (class->get_preferred_height)
1732 class->get_preferred_height (area, context, widget, minimum_height, natural_height);
1734 g_warning ("GtkCellAreaClass::get_preferred_height not implemented for `%s'",
1735 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1739 * gtk_cell_area_get_preferred_width_for_height:
1740 * @area: a #GtkCellArea
1741 * @context: the #GtkCellAreaContext which has already been requested for widths.
1742 * @widget: the #GtkWidget where @area will be rendering
1743 * @height: the height for which to check the width of this area
1744 * @minimum_width: (out) (allow-none): location to store the minimum width, or %NULL
1745 * @natural_width: (out) (allow-none): location to store the natural width, or %NULL
1747 * Retrieves a cell area's minimum and natural width if it would be given
1748 * the specified @height.
1750 * @area stores some geometrical information in @context along the way
1751 * while calling gtk_cell_area_get_preferred_height(), it's important to
1752 * perform a series of gtk_cell_area_get_preferred_height() requests with
1753 * @context first and then call gtk_cell_area_get_preferred_width_for_height()
1754 * on each cell area individually to get the height for width of each
1755 * fully requested row.
1757 * If at some point, the height of a single row changes, it should be
1758 * requested with gtk_cell_area_get_preferred_height() again and then
1759 * the full height of the requested rows checked again with
1760 * gtk_cell_area_context_get_preferred_height().
1765 gtk_cell_area_get_preferred_width_for_height (GtkCellArea *area,
1766 GtkCellAreaContext *context,
1769 gint *minimum_width,
1770 gint *natural_width)
1772 GtkCellAreaClass *class;
1774 g_return_if_fail (GTK_IS_CELL_AREA (area));
1775 g_return_if_fail (GTK_IS_WIDGET (widget));
1777 class = GTK_CELL_AREA_GET_CLASS (area);
1778 class->get_preferred_width_for_height (area, context, widget, height, minimum_width, natural_width);
1781 /*************************************************************
1783 *************************************************************/
1786 * gtk_cell_area_attribute_connect:
1787 * @area: a #GtkCellArea
1788 * @renderer: the #GtkCellRenderer to connect an attribute for
1789 * @attribute: the attribute name
1790 * @column: the #GtkTreeModel column to fetch attribute values from
1792 * Connects an @attribute to apply values from @column for the
1793 * #GtkTreeModel in use.
1798 gtk_cell_area_attribute_connect (GtkCellArea *area,
1799 GtkCellRenderer *renderer,
1800 const gchar *attribute,
1803 GtkCellAreaPrivate *priv;
1805 CellAttribute *cell_attribute;
1807 g_return_if_fail (GTK_IS_CELL_AREA (area));
1808 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1809 g_return_if_fail (attribute != NULL);
1810 g_return_if_fail (gtk_cell_area_has_renderer (area, renderer));
1813 info = g_hash_table_lookup (priv->cell_info, renderer);
1817 info = cell_info_new (NULL, NULL, NULL);
1819 g_hash_table_insert (priv->cell_info, renderer, info);
1825 /* Check we are not adding the same attribute twice */
1826 if ((node = g_slist_find_custom (info->attributes, attribute,
1827 (GCompareFunc)cell_attribute_find)) != NULL)
1829 cell_attribute = node->data;
1831 g_warning ("Cannot connect attribute `%s' for cell renderer class `%s' "
1832 "since `%s' is already attributed to column %d",
1834 g_type_name (G_TYPE_FROM_INSTANCE (area)),
1835 attribute, cell_attribute->column);
1840 cell_attribute = cell_attribute_new (renderer, attribute, column);
1842 if (!cell_attribute)
1844 g_warning ("Cannot connect attribute `%s' for cell renderer class `%s' "
1845 "since attribute does not exist",
1847 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1851 info->attributes = g_slist_prepend (info->attributes, cell_attribute);
1855 * gtk_cell_area_attribute_disconnect:
1856 * @area: a #GtkCellArea
1857 * @renderer: the #GtkCellRenderer to disconnect an attribute for
1858 * @attribute: the attribute name
1860 * Disconnects @attribute for the @renderer in @area so that
1861 * attribute will no longer be updated with values from the
1867 gtk_cell_area_attribute_disconnect (GtkCellArea *area,
1868 GtkCellRenderer *renderer,
1869 const gchar *attribute)
1871 GtkCellAreaPrivate *priv;
1873 CellAttribute *cell_attribute;
1876 g_return_if_fail (GTK_IS_CELL_AREA (area));
1877 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1878 g_return_if_fail (attribute != NULL);
1879 g_return_if_fail (gtk_cell_area_has_renderer (area, renderer));
1882 info = g_hash_table_lookup (priv->cell_info, renderer);
1886 node = g_slist_find_custom (info->attributes, attribute,
1887 (GCompareFunc)cell_attribute_find);
1890 cell_attribute = node->data;
1892 cell_attribute_free (cell_attribute);
1894 info->attributes = g_slist_delete_link (info->attributes, node);
1900 * gtk_cell_area_apply_attributes
1901 * @area: a #GtkCellArea
1902 * @tree_model: the #GtkTreeModel to pull values from
1903 * @iter: the #GtkTreeIter in @tree_model to apply values for
1904 * @is_expander: whether @iter has children
1905 * @is_expanded: whether @iter is expanded in the view and
1906 * children are visible
1908 * Applies any connected attributes to the renderers in
1909 * @area by pulling the values from @tree_model.
1914 gtk_cell_area_apply_attributes (GtkCellArea *area,
1915 GtkTreeModel *tree_model,
1917 gboolean is_expander,
1918 gboolean is_expanded)
1920 g_return_if_fail (GTK_IS_CELL_AREA (area));
1921 g_return_if_fail (GTK_IS_TREE_MODEL (tree_model));
1922 g_return_if_fail (iter != NULL);
1924 g_signal_emit (area, cell_area_signals[SIGNAL_APPLY_ATTRIBUTES], 0,
1925 tree_model, iter, is_expander, is_expanded);
1929 * gtk_cell_area_get_current_path_string:
1930 * @area: a #GtkCellArea
1932 * Gets the current #GtkTreePath string for the currently
1933 * applied #GtkTreeIter, this is implicitly updated when
1934 * gtk_cell_area_apply_attributes() is called and can be
1935 * used to interact with renderers from #GtkCellArea
1938 * Return value: The current #GtkTreePath string for the current
1939 * attributes applied to @area. This string belongs to the area and
1940 * should not be freed.
1944 G_CONST_RETURN gchar *
1945 gtk_cell_area_get_current_path_string (GtkCellArea *area)
1947 GtkCellAreaPrivate *priv;
1949 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
1953 return priv->current_path;
1957 /*************************************************************
1958 * API: Cell Properties *
1959 *************************************************************/
1961 * gtk_cell_area_class_install_cell_property:
1962 * @aclass: a #GtkCellAreaClass
1963 * @property_id: the id for the property
1964 * @pspec: the #GParamSpec for the property
1966 * Installs a cell property on a cell area class.
1971 gtk_cell_area_class_install_cell_property (GtkCellAreaClass *aclass,
1975 g_return_if_fail (GTK_IS_CELL_AREA_CLASS (aclass));
1976 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1977 if (pspec->flags & G_PARAM_WRITABLE)
1978 g_return_if_fail (aclass->set_cell_property != NULL);
1979 if (pspec->flags & G_PARAM_READABLE)
1980 g_return_if_fail (aclass->get_cell_property != NULL);
1981 g_return_if_fail (property_id > 0);
1982 g_return_if_fail (PARAM_SPEC_PARAM_ID (pspec) == 0); /* paranoid */
1983 g_return_if_fail ((pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY)) == 0);
1985 if (g_param_spec_pool_lookup (cell_property_pool, pspec->name, G_OBJECT_CLASS_TYPE (aclass), TRUE))
1987 g_warning (G_STRLOC ": class `%s' already contains a cell property named `%s'",
1988 G_OBJECT_CLASS_NAME (aclass), pspec->name);
1991 g_param_spec_ref (pspec);
1992 g_param_spec_sink (pspec);
1993 PARAM_SPEC_SET_PARAM_ID (pspec, property_id);
1994 g_param_spec_pool_insert (cell_property_pool, pspec, G_OBJECT_CLASS_TYPE (aclass));
1998 * gtk_cell_area_class_find_cell_property:
1999 * @aclass: a #GtkCellAreaClass
2000 * @property_name: the name of the child property to find
2002 * Finds a cell property of a cell area class by name.
2004 * Return value: (allow-none): the #GParamSpec of the child property or %NULL if @aclass has no
2005 * child property with that name.
2010 gtk_cell_area_class_find_cell_property (GtkCellAreaClass *aclass,
2011 const gchar *property_name)
2013 g_return_val_if_fail (GTK_IS_CELL_AREA_CLASS (aclass), NULL);
2014 g_return_val_if_fail (property_name != NULL, NULL);
2016 return g_param_spec_pool_lookup (cell_property_pool,
2018 G_OBJECT_CLASS_TYPE (aclass),
2023 * gtk_cell_area_class_list_cell_properties:
2024 * @aclass: a #GtkCellAreaClass
2025 * @n_properties: location to return the number of cell properties found
2027 * Returns all cell properties of a cell area class.
2029 * Return value: a newly allocated %NULL-terminated array of #GParamSpec*.
2030 * The array must be freed with g_free().
2035 gtk_cell_area_class_list_cell_properties (GtkCellAreaClass *aclass,
2036 guint *n_properties)
2038 GParamSpec **pspecs;
2041 g_return_val_if_fail (GTK_IS_CELL_AREA_CLASS (aclass), NULL);
2043 pspecs = g_param_spec_pool_list (cell_property_pool,
2044 G_OBJECT_CLASS_TYPE (aclass),
2053 * gtk_cell_area_add_with_properties:
2054 * @area: a #GtkCellArea
2055 * @renderer: a #GtkCellRenderer to be placed inside @area
2056 * @first_prop_name: the name of the first cell property to set
2057 * @Varargs: a %NULL-terminated list of property names and values, starting
2058 * with @first_prop_name
2060 * Adds @renderer to @area, setting cell properties at the same time.
2061 * See gtk_cell_area_add() and gtk_cell_area_child_set() for more details.
2066 gtk_cell_area_add_with_properties (GtkCellArea *area,
2067 GtkCellRenderer *renderer,
2068 const gchar *first_prop_name,
2071 GtkCellAreaClass *class;
2073 g_return_if_fail (GTK_IS_CELL_AREA (area));
2074 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2076 class = GTK_CELL_AREA_GET_CLASS (area);
2082 class->add (area, renderer);
2084 va_start (var_args, first_prop_name);
2085 gtk_cell_area_cell_set_valist (area, renderer, first_prop_name, var_args);
2089 g_warning ("GtkCellAreaClass::add not implemented for `%s'",
2090 g_type_name (G_TYPE_FROM_INSTANCE (area)));
2094 * gtk_cell_area_cell_set:
2095 * @area: a #GtkCellArea
2096 * @renderer: a #GtkCellRenderer which is a cell inside @area
2097 * @first_prop_name: the name of the first cell property to set
2098 * @Varargs: a %NULL-terminated list of property names and values, starting
2099 * with @first_prop_name
2101 * Sets one or more cell properties for @cell in @area.
2106 gtk_cell_area_cell_set (GtkCellArea *area,
2107 GtkCellRenderer *renderer,
2108 const gchar *first_prop_name,
2113 g_return_if_fail (GTK_IS_CELL_AREA (area));
2114 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2116 va_start (var_args, first_prop_name);
2117 gtk_cell_area_cell_set_valist (area, renderer, first_prop_name, var_args);
2122 * gtk_cell_area_cell_get:
2123 * @area: a #GtkCellArea
2124 * @renderer: a #GtkCellRenderer which is inside @area
2125 * @first_prop_name: the name of the first cell property to get
2126 * @Varargs: return location for the first cell property, followed
2127 * optionally by more name/return location pairs, followed by %NULL
2129 * Gets the values of one or more cell properties for @renderer in @area.
2134 gtk_cell_area_cell_get (GtkCellArea *area,
2135 GtkCellRenderer *renderer,
2136 const gchar *first_prop_name,
2141 g_return_if_fail (GTK_IS_CELL_AREA (area));
2142 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2144 va_start (var_args, first_prop_name);
2145 gtk_cell_area_cell_get_valist (area, renderer, first_prop_name, var_args);
2150 area_get_cell_property (GtkCellArea *area,
2151 GtkCellRenderer *renderer,
2155 GtkCellAreaClass *class = g_type_class_peek (pspec->owner_type);
2157 class->get_cell_property (area, renderer, PARAM_SPEC_PARAM_ID (pspec), value, pspec);
2161 area_set_cell_property (GtkCellArea *area,
2162 GtkCellRenderer *renderer,
2164 const GValue *value)
2166 GValue tmp_value = { 0, };
2167 GtkCellAreaClass *class = g_type_class_peek (pspec->owner_type);
2169 /* provide a copy to work from, convert (if necessary) and validate */
2170 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2171 if (!g_value_transform (value, &tmp_value))
2172 g_warning ("unable to set cell property `%s' of type `%s' from value of type `%s'",
2174 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
2175 G_VALUE_TYPE_NAME (value));
2176 else if (g_param_value_validate (pspec, &tmp_value) && !(pspec->flags & G_PARAM_LAX_VALIDATION))
2178 gchar *contents = g_strdup_value_contents (value);
2180 g_warning ("value \"%s\" of type `%s' is invalid for property `%s' of type `%s'",
2182 G_VALUE_TYPE_NAME (value),
2184 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
2189 class->set_cell_property (area, renderer, PARAM_SPEC_PARAM_ID (pspec), &tmp_value, pspec);
2191 g_value_unset (&tmp_value);
2195 * gtk_cell_area_cell_set_valist:
2196 * @area: a #GtkCellArea
2197 * @renderer: a #GtkCellRenderer which inside @area
2198 * @first_property_name: the name of the first cell property to set
2199 * @var_args: a %NULL-terminated list of property names and values, starting
2200 * with @first_prop_name
2202 * Sets one or more cell properties for @renderer in @area.
2207 gtk_cell_area_cell_set_valist (GtkCellArea *area,
2208 GtkCellRenderer *renderer,
2209 const gchar *first_property_name,
2214 g_return_if_fail (GTK_IS_CELL_AREA (area));
2215 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2217 name = first_property_name;
2220 GValue value = { 0, };
2221 gchar *error = NULL;
2223 g_param_spec_pool_lookup (cell_property_pool, name,
2224 G_OBJECT_TYPE (area), TRUE);
2227 g_warning ("%s: cell area class `%s' has no cell property named `%s'",
2228 G_STRLOC, G_OBJECT_TYPE_NAME (area), name);
2231 if (!(pspec->flags & G_PARAM_WRITABLE))
2233 g_warning ("%s: cell property `%s' of cell area class `%s' is not writable",
2234 G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
2238 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2239 G_VALUE_COLLECT (&value, var_args, 0, &error);
2242 g_warning ("%s: %s", G_STRLOC, error);
2245 /* we purposely leak the value here, it might not be
2246 * in a sane state if an error condition occoured
2250 area_set_cell_property (area, renderer, pspec, &value);
2251 g_value_unset (&value);
2252 name = va_arg (var_args, gchar*);
2257 * gtk_cell_area_cell_get_valist:
2258 * @area: a #GtkCellArea
2259 * @renderer: a #GtkCellRenderer inside @area
2260 * @first_property_name: the name of the first property to get
2261 * @var_args: return location for the first property, followed
2262 * optionally by more name/return location pairs, followed by %NULL
2264 * Gets the values of one or more cell properties for @renderer in @area.
2269 gtk_cell_area_cell_get_valist (GtkCellArea *area,
2270 GtkCellRenderer *renderer,
2271 const gchar *first_property_name,
2276 g_return_if_fail (GTK_IS_CELL_AREA (area));
2277 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2279 name = first_property_name;
2282 GValue value = { 0, };
2286 pspec = g_param_spec_pool_lookup (cell_property_pool, name,
2287 G_OBJECT_TYPE (area), TRUE);
2290 g_warning ("%s: cell area class `%s' has no cell property named `%s'",
2291 G_STRLOC, G_OBJECT_TYPE_NAME (area), name);
2294 if (!(pspec->flags & G_PARAM_READABLE))
2296 g_warning ("%s: cell property `%s' of cell area class `%s' is not readable",
2297 G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
2301 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2302 area_get_cell_property (area, renderer, pspec, &value);
2303 G_VALUE_LCOPY (&value, var_args, 0, &error);
2306 g_warning ("%s: %s", G_STRLOC, error);
2308 g_value_unset (&value);
2311 g_value_unset (&value);
2312 name = va_arg (var_args, gchar*);
2317 * gtk_cell_area_cell_set_property:
2318 * @area: a #GtkCellArea
2319 * @renderer: a #GtkCellRenderer inside @area
2320 * @property_name: the name of the cell property to set
2321 * @value: the value to set the cell property to
2323 * Sets a cell property for @renderer in @area.
2328 gtk_cell_area_cell_set_property (GtkCellArea *area,
2329 GtkCellRenderer *renderer,
2330 const gchar *property_name,
2331 const GValue *value)
2335 g_return_if_fail (GTK_IS_CELL_AREA (area));
2336 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2337 g_return_if_fail (property_name != NULL);
2338 g_return_if_fail (G_IS_VALUE (value));
2340 pspec = g_param_spec_pool_lookup (cell_property_pool, property_name,
2341 G_OBJECT_TYPE (area), TRUE);
2343 g_warning ("%s: cell area class `%s' has no cell property named `%s'",
2344 G_STRLOC, G_OBJECT_TYPE_NAME (area), property_name);
2345 else if (!(pspec->flags & G_PARAM_WRITABLE))
2346 g_warning ("%s: cell property `%s' of cell area class `%s' is not writable",
2347 G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
2350 area_set_cell_property (area, renderer, pspec, value);
2355 * gtk_cell_area_cell_get_property:
2356 * @area: a #GtkCellArea
2357 * @renderer: a #GtkCellRenderer inside @area
2358 * @property_name: the name of the property to get
2359 * @value: a location to return the value
2361 * Gets the value of a cell property for @renderer in @area.
2366 gtk_cell_area_cell_get_property (GtkCellArea *area,
2367 GtkCellRenderer *renderer,
2368 const gchar *property_name,
2373 g_return_if_fail (GTK_IS_CELL_AREA (area));
2374 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2375 g_return_if_fail (property_name != NULL);
2376 g_return_if_fail (G_IS_VALUE (value));
2378 pspec = g_param_spec_pool_lookup (cell_property_pool, property_name,
2379 G_OBJECT_TYPE (area), TRUE);
2381 g_warning ("%s: cell area class `%s' has no cell property named `%s'",
2382 G_STRLOC, G_OBJECT_TYPE_NAME (area), property_name);
2383 else if (!(pspec->flags & G_PARAM_READABLE))
2384 g_warning ("%s: cell property `%s' of cell area class `%s' is not readable",
2385 G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
2388 GValue *prop_value, tmp_value = { 0, };
2390 /* auto-conversion of the callers value type
2392 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
2394 g_value_reset (value);
2397 else if (!g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
2399 g_warning ("can't retrieve cell property `%s' of type `%s' as value of type `%s'",
2401 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
2402 G_VALUE_TYPE_NAME (value));
2407 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2408 prop_value = &tmp_value;
2411 area_get_cell_property (area, renderer, pspec, prop_value);
2413 if (prop_value != value)
2415 g_value_transform (prop_value, value);
2416 g_value_unset (&tmp_value);
2421 /*************************************************************
2423 *************************************************************/
2426 * gtk_cell_area_is_activatable:
2427 * @area: a #GtkCellArea
2429 * Returns whether the area can do anything when activated,
2430 * after applying new attributes to @area.
2432 * Return value: whether @area can do anything when activated.
2437 gtk_cell_area_is_activatable (GtkCellArea *area)
2439 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2441 return GTK_CELL_AREA_GET_CLASS (area)->is_activatable (area);
2445 * gtk_cell_area_focus:
2446 * @area: a #GtkCellArea
2447 * @direction: the #GtkDirectionType
2449 * This should be called by the @area's owning layout widget
2450 * when focus is to be passed to @area, or moved within @area
2451 * for a given @direction and row data.
2453 * Implementing #GtkCellArea classes should implement this
2454 * method to receive and navigate focus in it's own way particular
2455 * to how it lays out cells.
2457 * Return value: %TRUE if focus remains inside @area as a result of this call.
2462 gtk_cell_area_focus (GtkCellArea *area,
2463 GtkDirectionType direction)
2465 GtkCellAreaClass *class;
2467 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2469 class = GTK_CELL_AREA_GET_CLASS (area);
2472 return class->focus (area, direction);
2474 g_warning ("GtkCellAreaClass::focus not implemented for `%s'",
2475 g_type_name (G_TYPE_FROM_INSTANCE (area)));
2481 * gtk_cell_area_activate:
2482 * @area: a #GtkCellArea
2483 * @context: the #GtkCellAreaContext in context with the current row data
2484 * @widget: the #GtkWidget that @area is rendering on
2485 * @cell_area: the size and location of @area relative to @widget's allocation
2486 * @flags: the #GtkCellRendererState flags for @area for this row of data.
2488 * Activates @area, usually by activating the currently focused
2489 * cell, however some subclasses which embed widgets in the area
2490 * can also activate a widget if it currently has the focus.
2492 * Return value: Whether @area was successfully activated.
2497 gtk_cell_area_activate (GtkCellArea *area,
2498 GtkCellAreaContext *context,
2500 const GdkRectangle *cell_area,
2501 GtkCellRendererState flags)
2503 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2505 return GTK_CELL_AREA_GET_CLASS (area)->activate (area, context, widget, cell_area, flags);
2510 * gtk_cell_area_set_focus_cell:
2511 * @area: a #GtkCellArea
2512 * @focus_cell: the #GtkCellRenderer to give focus to
2514 * This is generally called from #GtkCellArea implementations
2515 * either gtk_cell_area_grab_focus() or gtk_cell_area_update_focus()
2516 * is called. It's also up to the #GtkCellArea implementation
2517 * to update the focused cell when receiving events from
2518 * gtk_cell_area_event() appropriately.
2523 gtk_cell_area_set_focus_cell (GtkCellArea *area,
2524 GtkCellRenderer *renderer)
2526 GtkCellAreaPrivate *priv;
2528 g_return_if_fail (GTK_IS_CELL_AREA (area));
2529 g_return_if_fail (renderer == NULL || GTK_IS_CELL_RENDERER (renderer));
2533 if (priv->focus_cell != renderer)
2535 if (priv->focus_cell)
2536 g_object_unref (priv->focus_cell);
2538 priv->focus_cell = renderer;
2540 if (priv->focus_cell)
2541 g_object_ref (priv->focus_cell);
2543 g_object_notify (G_OBJECT (area), "focus-cell");
2546 /* Signal that the current focus renderer for this path changed
2547 * (it may be that the focus cell did not change, but the row
2548 * may have changed so we need to signal it) */
2549 g_signal_emit (area, cell_area_signals[SIGNAL_FOCUS_CHANGED], 0,
2550 priv->focus_cell, priv->current_path);
2555 * gtk_cell_area_get_focus_cell:
2556 * @area: a #GtkCellArea
2558 * Retrieves the currently focused cell for @area
2560 * Return value: the currently focused cell in @area.
2565 gtk_cell_area_get_focus_cell (GtkCellArea *area)
2567 GtkCellAreaPrivate *priv;
2569 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
2573 return priv->focus_cell;
2577 /*************************************************************
2578 * API: Focus Siblings *
2579 *************************************************************/
2582 * gtk_cell_area_add_focus_sibling:
2583 * @area: a #GtkCellArea
2584 * @renderer: the #GtkCellRenderer expected to have focus
2585 * @sibling: the #GtkCellRenderer to add to @renderer's focus area
2587 * Adds @sibling to @renderer's focusable area, focus will be drawn
2588 * around @renderer and all of it's siblings if @renderer can
2589 * focus for a given row.
2591 * Events handled by focus siblings can also activate the given
2592 * focusable @renderer.
2597 gtk_cell_area_add_focus_sibling (GtkCellArea *area,
2598 GtkCellRenderer *renderer,
2599 GtkCellRenderer *sibling)
2601 GtkCellAreaPrivate *priv;
2604 g_return_if_fail (GTK_IS_CELL_AREA (area));
2605 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2606 g_return_if_fail (GTK_IS_CELL_RENDERER (sibling));
2607 g_return_if_fail (renderer != sibling);
2608 g_return_if_fail (gtk_cell_area_has_renderer (area, renderer));
2609 g_return_if_fail (gtk_cell_area_has_renderer (area, sibling));
2610 g_return_if_fail (!gtk_cell_area_is_focus_sibling (area, renderer, sibling));
2612 /* XXX We should also check that sibling is not in any other renderer's sibling
2613 * list already, a renderer can be sibling of only one focusable renderer
2619 siblings = g_hash_table_lookup (priv->focus_siblings, renderer);
2622 siblings = g_list_append (siblings, sibling);
2625 siblings = g_list_append (siblings, sibling);
2626 g_hash_table_insert (priv->focus_siblings, renderer, siblings);
2631 * gtk_cell_area_remove_focus_sibling:
2632 * @area: a #GtkCellArea
2633 * @renderer: the #GtkCellRenderer expected to have focus
2634 * @sibling: the #GtkCellRenderer to remove from @renderer's focus area
2636 * Removes @sibling from @renderer's focus sibling list
2637 * (see gtk_cell_area_add_focus_sibling()).
2642 gtk_cell_area_remove_focus_sibling (GtkCellArea *area,
2643 GtkCellRenderer *renderer,
2644 GtkCellRenderer *sibling)
2646 GtkCellAreaPrivate *priv;
2649 g_return_if_fail (GTK_IS_CELL_AREA (area));
2650 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2651 g_return_if_fail (GTK_IS_CELL_RENDERER (sibling));
2652 g_return_if_fail (gtk_cell_area_is_focus_sibling (area, renderer, sibling));
2656 siblings = g_hash_table_lookup (priv->focus_siblings, renderer);
2658 siblings = g_list_copy (siblings);
2659 siblings = g_list_remove (siblings, sibling);
2662 g_hash_table_remove (priv->focus_siblings, renderer);
2664 g_hash_table_insert (priv->focus_siblings, renderer, siblings);
2668 * gtk_cell_area_is_focus_sibling:
2669 * @area: a #GtkCellArea
2670 * @renderer: the #GtkCellRenderer expected to have focus
2671 * @sibling: the #GtkCellRenderer to check against @renderer's sibling list
2673 * Returns %TRUE if @sibling is one of @renderer's focus siblings
2674 * (see gtk_cell_area_add_focus_sibling()).
2679 gtk_cell_area_is_focus_sibling (GtkCellArea *area,
2680 GtkCellRenderer *renderer,
2681 GtkCellRenderer *sibling)
2683 GtkCellAreaPrivate *priv;
2684 GList *siblings, *l;
2686 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2687 g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), FALSE);
2688 g_return_val_if_fail (GTK_IS_CELL_RENDERER (sibling), FALSE);
2692 siblings = g_hash_table_lookup (priv->focus_siblings, renderer);
2694 for (l = siblings; l; l = l->next)
2696 GtkCellRenderer *a_sibling = l->data;
2698 if (a_sibling == sibling)
2706 * gtk_cell_area_get_focus_siblings:
2707 * @area: a #GtkCellArea
2708 * @renderer: the #GtkCellRenderer expected to have focus
2710 * Gets the focus sibling cell renderers for @renderer.
2712 * Return value: (element-type GtkCellRenderer) (transfer none): A #GList of #GtkCellRenderers.
2713 * The returned list is internal and should not be freed.
2718 gtk_cell_area_get_focus_siblings (GtkCellArea *area,
2719 GtkCellRenderer *renderer)
2721 GtkCellAreaPrivate *priv;
2723 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
2724 g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), NULL);
2728 return g_hash_table_lookup (priv->focus_siblings, renderer);
2732 * gtk_cell_area_get_focus_from_sibling:
2733 * @area: a #GtkCellArea
2734 * @renderer: the #GtkCellRenderer
2736 * Gets the #GtkCellRenderer which is expected to be focusable
2737 * for which @renderer is, or may be a sibling.
2739 * This is handy for #GtkCellArea subclasses when handling events,
2740 * after determining the renderer at the event location it can
2741 * then chose to activate the focus cell for which the event
2742 * cell may have been a sibling.
2744 * Return value: the #GtkCellRenderer for which @renderer is a sibling, or %NULL.
2749 gtk_cell_area_get_focus_from_sibling (GtkCellArea *area,
2750 GtkCellRenderer *renderer)
2752 GtkCellRenderer *ret_renderer = NULL;
2753 GList *renderers, *l;
2755 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
2756 g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), NULL);
2758 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (area));
2760 for (l = renderers; l; l = l->next)
2762 GtkCellRenderer *a_renderer = l->data;
2765 for (list = gtk_cell_area_get_focus_siblings (area, a_renderer);
2766 list; list = list->next)
2768 GtkCellRenderer *sibling_renderer = list->data;
2770 if (sibling_renderer == renderer)
2772 ret_renderer = a_renderer;
2777 g_list_free (renderers);
2779 return ret_renderer;
2782 /*************************************************************
2783 * API: Cell Activation/Editing *
2784 *************************************************************/
2786 gtk_cell_area_add_editable (GtkCellArea *area,
2787 GtkCellRenderer *renderer,
2788 GtkCellEditable *editable,
2789 GdkRectangle *cell_area)
2791 g_signal_emit (area, cell_area_signals[SIGNAL_ADD_EDITABLE], 0,
2792 renderer, editable, cell_area, area->priv->current_path);
2796 gtk_cell_area_remove_editable (GtkCellArea *area,
2797 GtkCellRenderer *renderer,
2798 GtkCellEditable *editable)
2800 g_signal_emit (area, cell_area_signals[SIGNAL_REMOVE_EDITABLE], 0, renderer, editable);
2804 cell_area_remove_widget_cb (GtkCellEditable *editable,
2807 GtkCellAreaPrivate *priv = area->priv;
2809 g_assert (priv->edit_widget == editable);
2810 g_assert (priv->edited_cell != NULL);
2812 gtk_cell_area_remove_editable (area, priv->edited_cell, priv->edit_widget);
2814 /* Now that we're done with editing the widget and it can be removed,
2815 * remove our references to the widget and disconnect handlers */
2816 gtk_cell_area_set_edited_cell (area, NULL);
2817 gtk_cell_area_set_edit_widget (area, NULL);
2821 gtk_cell_area_set_edited_cell (GtkCellArea *area,
2822 GtkCellRenderer *renderer)
2824 GtkCellAreaPrivate *priv;
2826 g_return_if_fail (GTK_IS_CELL_AREA (area));
2827 g_return_if_fail (renderer == NULL || GTK_IS_CELL_RENDERER (renderer));
2831 if (priv->edited_cell != renderer)
2833 if (priv->edited_cell)
2834 g_object_unref (priv->edited_cell);
2836 priv->edited_cell = renderer;
2838 if (priv->edited_cell)
2839 g_object_ref (priv->edited_cell);
2841 g_object_notify (G_OBJECT (area), "edited-cell");
2846 gtk_cell_area_set_edit_widget (GtkCellArea *area,
2847 GtkCellEditable *editable)
2849 GtkCellAreaPrivate *priv;
2851 g_return_if_fail (GTK_IS_CELL_AREA (area));
2852 g_return_if_fail (editable == NULL || GTK_IS_CELL_EDITABLE (editable));
2856 if (priv->edit_widget != editable)
2858 if (priv->edit_widget)
2860 g_signal_handler_disconnect (priv->edit_widget, priv->remove_widget_id);
2862 g_object_unref (priv->edit_widget);
2865 priv->edit_widget = editable;
2867 if (priv->edit_widget)
2869 priv->remove_widget_id =
2870 g_signal_connect (priv->edit_widget, "remove-widget",
2871 G_CALLBACK (cell_area_remove_widget_cb), area);
2873 g_object_ref (priv->edit_widget);
2876 g_object_notify (G_OBJECT (area), "edit-widget");
2881 * gtk_cell_area_get_edited_cell:
2882 * @area: a #GtkCellArea
2884 * Gets the #GtkCellRenderer in @area that is currently
2887 * Return value: The currently edited #GtkCellRenderer
2892 gtk_cell_area_get_edited_cell (GtkCellArea *area)
2894 GtkCellAreaPrivate *priv;
2896 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
2900 return priv->edited_cell;
2904 * gtk_cell_area_get_edit_widget:
2905 * @area: a #GtkCellArea
2907 * Gets the #GtkCellEditable widget currently used
2908 * to edit the currently edited cell.
2910 * Return value: The currently active #GtkCellEditable widget
2915 gtk_cell_area_get_edit_widget (GtkCellArea *area)
2917 GtkCellAreaPrivate *priv;
2919 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
2923 return priv->edit_widget;
2927 * gtk_cell_area_activate_cell:
2928 * @area: a #GtkCellArea
2929 * @widget: the #GtkWidget that @area is rendering onto
2930 * @renderer: the #GtkCellRenderer in @area to activate
2931 * @event: the #GdkEvent for which cell activation should occur
2932 * @cell_area: the #GdkRectangle in @widget relative coordinates
2933 * of @renderer for the current row.
2934 * @flags: the #GtkCellRendererState for @renderer
2936 * This is used by #GtkCellArea subclasses when handling events
2937 * to activate cells, the base #GtkCellArea class activates cells
2938 * for keyboard events for free in it's own GtkCellArea->activate()
2941 * Return value: whether cell activation was successful
2946 gtk_cell_area_activate_cell (GtkCellArea *area,
2948 GtkCellRenderer *renderer,
2950 const GdkRectangle *cell_area,
2951 GtkCellRendererState flags)
2953 GtkCellRendererMode mode;
2954 GdkRectangle inner_area;
2955 GtkCellAreaPrivate *priv;
2957 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2958 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2959 g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), FALSE);
2960 g_return_val_if_fail (cell_area != NULL, FALSE);
2964 /* Remove margins from the background area to produce the cell area.
2966 * XXX Maybe have to do some rtl mode treatment here...
2968 gtk_cell_area_inner_cell_area (area, widget, cell_area, &inner_area);
2970 g_object_get (renderer, "mode", &mode, NULL);
2972 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2974 if (gtk_cell_renderer_activate (renderer,
2982 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2984 GtkCellEditable *editable_widget;
2987 gtk_cell_renderer_start_editing (renderer,
2994 if (editable_widget != NULL)
2996 g_return_val_if_fail (GTK_IS_CELL_EDITABLE (editable_widget), FALSE);
2998 gtk_cell_area_set_edited_cell (area, renderer);
2999 gtk_cell_area_set_edit_widget (area, editable_widget);
3001 /* Signal that editing started so that callers can get
3002 * a handle on the editable_widget */
3003 gtk_cell_area_add_editable (area, priv->focus_cell, editable_widget, &inner_area);
3005 /* If the signal was successfully handled start the editing */
3006 if (gtk_widget_get_parent (GTK_WIDGET (editable_widget)))
3008 gtk_cell_editable_start_editing (editable_widget, NULL);
3009 gtk_widget_grab_focus (GTK_WIDGET (editable_widget));
3013 /* Otherwise clear the editing state and fire a warning */
3014 gtk_cell_area_set_edited_cell (area, NULL);
3015 gtk_cell_area_set_edit_widget (area, NULL);
3017 g_warning ("GtkCellArea::add-editable fired in the dark, no cell editing was started.");
3028 * gtk_cell_area_stop_editing:
3029 * @area: a #GtkCellArea
3030 * @canceled: whether editing was canceled.
3032 * Explicitly stops the editing of the currently
3033 * edited cell (see gtk_cell_area_get_edited_cell()).
3035 * If @canceled is %TRUE, the cell renderer will emit
3036 * the ::editing-canceled signal.
3041 gtk_cell_area_stop_editing (GtkCellArea *area,
3044 GtkCellAreaPrivate *priv;
3046 g_return_if_fail (GTK_IS_CELL_AREA (area));
3050 if (priv->edited_cell)
3052 GtkCellEditable *edit_widget = g_object_ref (priv->edit_widget);
3053 GtkCellRenderer *edit_cell = g_object_ref (priv->edited_cell);
3055 /* Stop editing of the cell renderer */
3056 gtk_cell_renderer_stop_editing (priv->edited_cell, canceled);
3058 /* Remove any references to the editable widget */
3059 gtk_cell_area_set_edited_cell (area, NULL);
3060 gtk_cell_area_set_edit_widget (area, NULL);
3062 /* Send the remove-widget signal explicitly (this is done after setting
3063 * the edit cell/widget NULL to avoid feedback)
3065 gtk_cell_area_remove_editable (area, edit_cell, edit_widget);
3066 g_object_unref (edit_cell);
3067 g_object_unref (edit_widget);
3071 /*************************************************************
3072 * API: Convenience for area implementations *
3073 *************************************************************/
3076 * gtk_cell_area_inner_cell_area:
3077 * @area: a #GtkCellArea
3078 * @widget: the #GtkWidget that @area is rendering onto
3079 * @cell_area: the @widget relative coordinates where one of @area's cells
3081 * @inner_area: (out): the return location for the inner cell area
3083 * This is a convenience function for #GtkCellArea implementations
3084 * to get the inner area where a given #GtkCellRenderer will be
3085 * rendered. It removes any padding previously added by gtk_cell_area_request_renderer().
3090 gtk_cell_area_inner_cell_area (GtkCellArea *area,
3092 const GdkRectangle *cell_area,
3093 GdkRectangle *inner_area)
3095 gint focus_line_width;
3097 g_return_if_fail (GTK_IS_CELL_AREA (area));
3098 g_return_if_fail (GTK_IS_WIDGET (widget));
3099 g_return_if_fail (cell_area != NULL);
3100 g_return_if_fail (inner_area != NULL);
3102 gtk_widget_style_get (widget, "focus-line-width", &focus_line_width, NULL);
3104 *inner_area = *cell_area;
3106 inner_area->x += focus_line_width;
3107 inner_area->width -= focus_line_width * 2;
3108 inner_area->y += focus_line_width;
3109 inner_area->height -= focus_line_width * 2;
3113 * gtk_cell_area_request_renderer:
3114 * @area: a #GtkCellArea
3115 * @renderer: the #GtkCellRenderer to request size for
3116 * @orientation: the #GtkOrientation in which to request size
3117 * @widget: the #GtkWidget that @area is rendering onto
3118 * @for_size: the allocation contextual size to request for, or -1 if
3119 * the base request for the orientation is to be returned.
3120 * @minimum_size: (out) (allow-none): location to store the minimum size, or %NULL
3121 * @natural_size: (out) (allow-none): location to store the natural size, or %NULL
3123 * This is a convenience function for #GtkCellArea implementations
3124 * to request size for cell renderers. It's important to use this
3125 * function to request size and then use gtk_cell_area_inner_cell_area()
3126 * at render and event time since this function will add padding
3127 * around the cell for focus painting.
3132 gtk_cell_area_request_renderer (GtkCellArea *area,
3133 GtkCellRenderer *renderer,
3134 GtkOrientation orientation,
3140 GtkCellAreaPrivate *priv;
3141 gint focus_line_width;
3143 g_return_if_fail (GTK_IS_CELL_AREA (area));
3144 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
3145 g_return_if_fail (GTK_IS_WIDGET (widget));
3146 g_return_if_fail (minimum_size != NULL);
3147 g_return_if_fail (natural_size != NULL);
3151 gtk_widget_style_get (widget, "focus-line-width", &focus_line_width, NULL);
3153 focus_line_width *= 2;
3155 if (orientation == GTK_ORIENTATION_HORIZONTAL)
3158 gtk_cell_renderer_get_preferred_width (renderer, widget, minimum_size, natural_size);
3161 for_size = MAX (0, for_size - focus_line_width);
3163 gtk_cell_renderer_get_preferred_width_for_height (renderer, widget, for_size,
3164 minimum_size, natural_size);
3167 else /* GTK_ORIENTATION_VERTICAL */
3170 gtk_cell_renderer_get_preferred_height (renderer, widget, minimum_size, natural_size);
3173 for_size = MAX (0, for_size - focus_line_width);
3175 gtk_cell_renderer_get_preferred_height_for_width (renderer, widget, for_size,
3176 minimum_size, natural_size);
3180 *minimum_size += focus_line_width;
3181 *natural_size += focus_line_width;