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. You can call
235 * gtk_cell_area_stop_editing() at any time to cancel any cell editing
236 * that is currently in progress.
238 * The #GtkCellArea drives keyboard focus from cell to cell in a way similar
239 * to #GtkWidget. For layouting widgets that support giving focus to cells it's
240 * important to remember to pass %GTK_CELL_RENDERER_FOCUSED to the area functions
241 * for the row that has focus and to tell the area to paint the focus at render
244 * Layouting widgets that accept focus on cells should implement the #GtkWidgetClass.focus()
245 * virtual method. The layouting widget is always responsible for knowing where
246 * #GtkTreeModel rows are rendered inside the widget, so at #GtkWidgetClass.focus() time
247 * the layouting widget should use the #GtkCellArea methods to navigate focus inside the
248 * area and then observe the GtkDirectionType to pass the focus to adjacent rows and
251 * A basic example of how the #GtkWidgetClass.focus() virtual method should be implemented:
253 * <title>Implementing keyboard focus navigation when displaying rows from top to bottom.</title>
256 * foo_focus (GtkWidget *widget,
257 * GtkDirectionType direction)
259 * Foo *foo = FOO (widget);
260 * FooPrivate *priv = foo->priv;
262 * gboolean have_focus = FALSE;
264 * focus_row = priv->focus_row;
266 * if (!gtk_widget_has_focus (widget))
267 * gtk_widget_grab_focus (widget);
269 * valid = gtk_tree_model_iter_nth_child (priv->model, &iter, NULL, priv->focus_row);
272 * gtk_cell_area_apply_attributes (priv->area, priv->model, &iter, FALSE, FALSE);
274 * if (gtk_cell_area_focus (priv->area, direction))
276 * priv->focus_row = focus_row;
282 * if (direction == GTK_DIR_RIGHT ||
283 * direction == GTK_DIR_LEFT)
285 * else if (direction == GTK_DIR_UP ||
286 * direction == GTK_DIR_TAB_BACKWARD)
288 * if (focus_row == 0)
293 * valid = gtk_tree_model_iter_nth_child (priv->model, &iter, NULL, focus_row);
298 * if (focus_row == last_row)
303 * valid = gtk_tree_model_iter_next (priv->model, &iter);
314 * <refsect2 id="cell-properties">
315 * <title>Cell Properties</title>
317 * The #GtkCellArea introduces <emphasis>cell properties</emphasis> for #GtkCellRenderers in very
318 * much the same way that #GtkContainer introduces <link linkend="child-properties">child properties</link>
319 * for #GtkWidgets. This provides some general interfaces for defining the relationship cell areas
320 * have with thier cells. For instance in a #GtkCellAreaBox a cell might "expand" and recieve extra
321 * space when the area is allocated more than it's full natural request, or a cell might be configured
322 * to "align" with adjacent rows which were requested and rendered with the same #GtkCellAreaContext.
324 * Use gtk_cell_area_class_install_cell_property() to install cell properties
325 * for a cell area class and gtk_cell_area_class_find_cell_property() or
326 * gtk_cell_area_class_list_cell_properties() to get information about existing
329 * To set the value of a cell property, use gtk_cell_area_cell_set_property(),
330 * gtk_cell_area_cell_set() or gtk_cell_area_cell_set_valist().
331 * To obtain the value of a cell property, use
332 * gtk_cell_area_cell_get_property(), gtk_cell_area_cell_get() or
333 * gtk_cell_area_cell_get_valist().
346 #include "gtkcelllayout.h"
347 #include "gtkcellarea.h"
348 #include "gtkcellareacontext.h"
349 #include "gtkmarshalers.h"
350 #include "gtkprivate.h"
352 #include <gobject/gvaluecollector.h>
356 static void gtk_cell_area_dispose (GObject *object);
357 static void gtk_cell_area_finalize (GObject *object);
358 static void gtk_cell_area_set_property (GObject *object,
362 static void gtk_cell_area_get_property (GObject *object,
367 /* GtkCellAreaClass */
368 static gint gtk_cell_area_real_event (GtkCellArea *area,
369 GtkCellAreaContext *context,
372 const GdkRectangle *cell_area,
373 GtkCellRendererState flags);
374 static void gtk_cell_area_real_apply_attributes (GtkCellArea *area,
375 GtkTreeModel *tree_model,
377 gboolean is_expander,
378 gboolean is_expanded);
379 static void gtk_cell_area_real_get_preferred_height_for_width (GtkCellArea *area,
380 GtkCellAreaContext *context,
383 gint *minimum_height,
384 gint *natural_height);
385 static void gtk_cell_area_real_get_preferred_width_for_height (GtkCellArea *area,
386 GtkCellAreaContext *context,
390 gint *natural_width);
391 static gboolean gtk_cell_area_real_is_activatable (GtkCellArea *area);
392 static gboolean gtk_cell_area_real_activate (GtkCellArea *area,
393 GtkCellAreaContext *context,
395 const GdkRectangle *cell_area,
396 GtkCellRendererState flags);
398 /* GtkCellLayoutIface */
399 static void gtk_cell_area_cell_layout_init (GtkCellLayoutIface *iface);
400 static void gtk_cell_area_pack_default (GtkCellLayout *cell_layout,
401 GtkCellRenderer *renderer,
403 static void gtk_cell_area_clear (GtkCellLayout *cell_layout);
404 static void gtk_cell_area_add_attribute (GtkCellLayout *cell_layout,
405 GtkCellRenderer *renderer,
406 const gchar *attribute,
408 static void gtk_cell_area_set_cell_data_func (GtkCellLayout *cell_layout,
409 GtkCellRenderer *cell,
410 GtkCellLayoutDataFunc func,
412 GDestroyNotify destroy);
413 static void gtk_cell_area_clear_attributes (GtkCellLayout *cell_layout,
414 GtkCellRenderer *renderer);
415 static void gtk_cell_area_reorder (GtkCellLayout *cell_layout,
416 GtkCellRenderer *cell,
418 static GList *gtk_cell_area_get_cells (GtkCellLayout *cell_layout);
421 /* Used in foreach loop to check if a child renderer is present */
423 GtkCellRenderer *renderer;
424 gboolean has_renderer;
427 /* Attribute/Cell metadata */
429 const gchar *attribute;
436 GtkCellLayoutDataFunc func;
438 GDestroyNotify destroy;
441 static CellInfo *cell_info_new (GtkCellLayoutDataFunc func,
443 GDestroyNotify destroy);
444 static void cell_info_free (CellInfo *info);
445 static CellAttribute *cell_attribute_new (GtkCellRenderer *renderer,
446 const gchar *attribute,
448 static void cell_attribute_free (CellAttribute *attribute);
449 static gint cell_attribute_find (CellAttribute *cell_attribute,
450 const gchar *attribute);
452 /* Internal functions/signal emissions */
453 static void gtk_cell_area_add_editable (GtkCellArea *area,
454 GtkCellRenderer *renderer,
455 GtkCellEditable *editable,
456 GdkRectangle *cell_area);
457 static void gtk_cell_area_remove_editable (GtkCellArea *area,
458 GtkCellRenderer *renderer,
459 GtkCellEditable *editable);
460 static void gtk_cell_area_set_edit_widget (GtkCellArea *area,
461 GtkCellEditable *editable);
462 static void gtk_cell_area_set_edited_cell (GtkCellArea *area,
463 GtkCellRenderer *renderer);
466 /* Struct to pass data along while looping over
467 * cell renderers to apply attributes
473 gboolean is_expander;
474 gboolean is_expanded;
477 struct _GtkCellAreaPrivate
479 /* The GtkCellArea bookkeeps any connected
480 * attributes in this hash table.
482 GHashTable *cell_info;
484 /* Current path is saved as a side-effect
485 * of gtk_cell_area_apply_attributes() */
488 /* Current cell being edited and editable widget used */
489 GtkCellEditable *edit_widget;
490 GtkCellRenderer *edited_cell;
492 /* Signal connections to the editable widget */
493 gulong remove_widget_id;
495 /* Currently focused cell */
496 GtkCellRenderer *focus_cell;
498 /* Tracking which cells are focus siblings of focusable cells */
499 GHashTable *focus_siblings;
501 /* Detail string to pass to gtk_paint_*() functions */
513 SIGNAL_APPLY_ATTRIBUTES,
515 SIGNAL_REMOVE_EDITABLE,
516 SIGNAL_FOCUS_CHANGED,
520 /* Keep the paramspec pool internal, no need to deliver notifications
521 * on cells. at least no percieved need for now */
522 static GParamSpecPool *cell_property_pool = NULL;
523 static guint cell_area_signals[LAST_SIGNAL] = { 0 };
525 #define PARAM_SPEC_PARAM_ID(pspec) ((pspec)->param_id)
526 #define PARAM_SPEC_SET_PARAM_ID(pspec, id) ((pspec)->param_id = (id))
529 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GtkCellArea, gtk_cell_area, G_TYPE_INITIALLY_UNOWNED,
530 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
531 gtk_cell_area_cell_layout_init));
534 gtk_cell_area_init (GtkCellArea *area)
536 GtkCellAreaPrivate *priv;
538 area->priv = G_TYPE_INSTANCE_GET_PRIVATE (area,
543 priv->cell_info = g_hash_table_new_full (g_direct_hash,
546 (GDestroyNotify)cell_info_free);
548 priv->focus_siblings = g_hash_table_new_full (g_direct_hash,
551 (GDestroyNotify)g_list_free);
553 priv->focus_cell = NULL;
554 priv->edited_cell = NULL;
555 priv->edit_widget = NULL;
557 priv->remove_widget_id = 0;
561 gtk_cell_area_class_init (GtkCellAreaClass *class)
563 GObjectClass *object_class = G_OBJECT_CLASS (class);
566 object_class->dispose = gtk_cell_area_dispose;
567 object_class->finalize = gtk_cell_area_finalize;
568 object_class->get_property = gtk_cell_area_get_property;
569 object_class->set_property = gtk_cell_area_set_property;
573 class->remove = NULL;
574 class->foreach = NULL;
575 class->event = gtk_cell_area_real_event;
576 class->render = NULL;
577 class->apply_attributes = gtk_cell_area_real_apply_attributes;
580 class->create_context = NULL;
581 class->get_request_mode = NULL;
582 class->get_preferred_width = NULL;
583 class->get_preferred_height = NULL;
584 class->get_preferred_height_for_width = gtk_cell_area_real_get_preferred_height_for_width;
585 class->get_preferred_width_for_height = gtk_cell_area_real_get_preferred_width_for_height;
588 class->is_activatable = gtk_cell_area_real_is_activatable;
589 class->activate = gtk_cell_area_real_activate;
594 * GtkCellArea::apply-attributes:
595 * @area: the #GtkCellArea to apply the attributes to
596 * @model: the #GtkTreeModel to apply the attributes from
597 * @iter: the #GtkTreeIter indicating which row to apply the attributes of
598 * @is_expander: whether the view shows children for this row
599 * @is_expanded: whether the view is currently showing the children of this row
601 * This signal is emitted whenever applying attributes to @area from @model
605 cell_area_signals[SIGNAL_APPLY_ATTRIBUTES] =
606 g_signal_new (I_("apply-attributes"),
607 G_OBJECT_CLASS_TYPE (object_class),
609 G_STRUCT_OFFSET (GtkCellAreaClass, apply_attributes),
611 _gtk_marshal_VOID__OBJECT_BOXED_BOOLEAN_BOOLEAN,
619 * GtkCellArea::add-editable:
620 * @area: the #GtkCellArea where editing started
621 * @renderer: the #GtkCellRenderer that started the edited
622 * @editable: the #GtkCellEditable widget to add
623 * @cell_area: the #GtkWidget relative #GdkRectangle coordinates
624 * where @editable should be added
625 * @path: the #GtkTreePath string this edit was initiated for
627 * Indicates that editing has started on @renderer and that @editable
628 * should be added to the owning cell layouting widget at @cell_area.
632 cell_area_signals[SIGNAL_ADD_EDITABLE] =
633 g_signal_new (I_("add-editable"),
634 G_OBJECT_CLASS_TYPE (object_class),
636 0, /* No class closure here */
638 _gtk_marshal_VOID__OBJECT_OBJECT_BOXED_STRING,
640 GTK_TYPE_CELL_RENDERER,
641 GTK_TYPE_CELL_EDITABLE,
647 * GtkCellArea::remove-editable:
648 * @area: the #GtkCellArea where editing finished
649 * @renderer: the #GtkCellRenderer that finished editeding
650 * @editable: the #GtkCellEditable widget to remove
652 * Indicates that editing finished on @renderer and that @editable
653 * should be removed from the owning cell layouting widget.
657 cell_area_signals[SIGNAL_REMOVE_EDITABLE] =
658 g_signal_new (I_("remove-editable"),
659 G_OBJECT_CLASS_TYPE (object_class),
661 0, /* No class closure here */
663 _gtk_marshal_VOID__OBJECT_OBJECT,
665 GTK_TYPE_CELL_RENDERER,
666 GTK_TYPE_CELL_EDITABLE);
669 * GtkCellArea::focus-changed:
670 * @area: the #GtkCellArea where focus changed
671 * @renderer: the #GtkCellRenderer that has focus
672 * @path: the current #GtkTreePath string set for @area
674 * Indicates that focus changed on this @area. This signal
675 * is emitted either as a result of focus handling or event
678 * It's possible that the signal is emitted even if the
679 * currently focused renderer did not change, this is
680 * because focus may change to the same renderer in the
681 * same cell area for a different row of data.
685 cell_area_signals[SIGNAL_FOCUS_CHANGED] =
686 g_signal_new (I_("focus-changed"),
687 G_OBJECT_CLASS_TYPE (object_class),
689 0, /* No class closure here */
691 _gtk_marshal_VOID__OBJECT_STRING,
693 GTK_TYPE_CELL_RENDERER,
698 * GtkCellArea:focus-cell:
700 * The cell in the area that currently has focus
704 g_object_class_install_property (object_class,
709 P_("The cell which currently has focus"),
710 GTK_TYPE_CELL_RENDERER,
711 GTK_PARAM_READWRITE));
714 * GtkCellArea:edited-cell:
716 * The cell in the area that is currently edited
718 * This property is read-only and only changes as
719 * a result of a call gtk_cell_area_activate_cell().
723 g_object_class_install_property (object_class,
728 P_("The cell which is currently being edited"),
729 GTK_TYPE_CELL_RENDERER,
733 * GtkCellArea:edit-widget:
735 * The widget currently editing the edited cell
737 * This property is read-only and only changes as
738 * a result of a call gtk_cell_area_activate_cell().
742 g_object_class_install_property (object_class,
747 P_("The widget currently editing the edited cell"),
748 GTK_TYPE_CELL_RENDERER,
751 /* Pool for Cell Properties */
752 if (!cell_property_pool)
753 cell_property_pool = g_param_spec_pool_new (FALSE);
755 g_type_class_add_private (object_class, sizeof (GtkCellAreaPrivate));
758 /*************************************************************
760 *************************************************************/
762 cell_info_new (GtkCellLayoutDataFunc func,
764 GDestroyNotify destroy)
766 CellInfo *info = g_slice_new0 (CellInfo);
770 info->destroy = destroy;
776 cell_info_free (CellInfo *info)
779 info->destroy (info->data);
781 g_slist_foreach (info->attributes, (GFunc)cell_attribute_free, NULL);
782 g_slist_free (info->attributes);
784 g_slice_free (CellInfo, info);
787 static CellAttribute *
788 cell_attribute_new (GtkCellRenderer *renderer,
789 const gchar *attribute,
794 /* Check if the attribute really exists and point to
795 * the property string installed on the cell renderer
796 * class (dont dup the string)
798 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (renderer), attribute);
802 CellAttribute *cell_attribute = g_slice_new (CellAttribute);
804 cell_attribute->attribute = pspec->name;
805 cell_attribute->column = column;
807 return cell_attribute;
814 cell_attribute_free (CellAttribute *attribute)
816 g_slice_free (CellAttribute, attribute);
819 /* GCompareFunc for g_slist_find_custom() */
821 cell_attribute_find (CellAttribute *cell_attribute,
822 const gchar *attribute)
824 return g_strcmp0 (cell_attribute->attribute, attribute);
827 /*************************************************************
829 *************************************************************/
831 gtk_cell_area_finalize (GObject *object)
833 GtkCellArea *area = GTK_CELL_AREA (object);
834 GtkCellAreaPrivate *priv = area->priv;
836 /* All cell renderers should already be removed at this point,
837 * just kill our (empty) hash tables here.
839 g_hash_table_destroy (priv->cell_info);
840 g_hash_table_destroy (priv->focus_siblings);
842 g_free (priv->current_path);
844 G_OBJECT_CLASS (gtk_cell_area_parent_class)->finalize (object);
849 gtk_cell_area_dispose (GObject *object)
851 /* This removes every cell renderer that may be added to the GtkCellArea,
852 * subclasses should be breaking references to the GtkCellRenderers
855 gtk_cell_layout_clear (GTK_CELL_LAYOUT (object));
857 /* Remove any ref to a focused/edited cell */
858 gtk_cell_area_set_focus_cell (GTK_CELL_AREA (object), NULL);
859 gtk_cell_area_set_edited_cell (GTK_CELL_AREA (object), NULL);
860 gtk_cell_area_set_edit_widget (GTK_CELL_AREA (object), NULL);
862 G_OBJECT_CLASS (gtk_cell_area_parent_class)->dispose (object);
866 gtk_cell_area_set_property (GObject *object,
871 GtkCellArea *area = GTK_CELL_AREA (object);
875 case PROP_FOCUS_CELL:
876 gtk_cell_area_set_focus_cell (area, (GtkCellRenderer *)g_value_get_object (value));
879 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
885 gtk_cell_area_get_property (GObject *object,
890 GtkCellArea *area = GTK_CELL_AREA (object);
891 GtkCellAreaPrivate *priv = area->priv;
895 case PROP_FOCUS_CELL:
896 g_value_set_object (value, priv->focus_cell);
898 case PROP_EDITED_CELL:
899 g_value_set_object (value, priv->edited_cell);
901 case PROP_EDIT_WIDGET:
902 g_value_set_object (value, priv->edit_widget);
905 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
910 /*************************************************************
912 *************************************************************/
914 gtk_cell_area_real_event (GtkCellArea *area,
915 GtkCellAreaContext *context,
918 const GdkRectangle *cell_area,
919 GtkCellRendererState flags)
921 GtkCellAreaPrivate *priv = area->priv;
923 if (event->type == GDK_KEY_PRESS && (flags & GTK_CELL_RENDERER_FOCUSED) != 0)
925 GdkEventKey *key_event = (GdkEventKey *)event;
927 /* Cancel any edits in progress */
928 if (priv->edited_cell && (key_event->keyval == GDK_KEY_Escape))
930 gtk_cell_area_stop_editing (area, TRUE);
939 apply_cell_attributes (GtkCellRenderer *renderer,
943 CellAttribute *attribute;
945 GValue value = { 0, };
946 gboolean is_expander;
947 gboolean is_expanded;
949 g_object_freeze_notify (G_OBJECT (renderer));
951 /* Whether a row expands or is presently expanded can only be
952 * provided by the view (as these states can vary across views
953 * accessing the same model).
955 g_object_get (renderer, "is-expander", &is_expander, NULL);
956 if (is_expander != data->is_expander)
957 g_object_set (renderer, "is-expander", data->is_expander, NULL);
959 g_object_get (renderer, "is-expanded", &is_expanded, NULL);
960 if (is_expanded != data->is_expanded)
961 g_object_set (renderer, "is-expanded", data->is_expanded, NULL);
963 /* Apply the attributes directly to the renderer */
964 for (list = info->attributes; list; list = list->next)
966 attribute = list->data;
968 gtk_tree_model_get_value (data->model, data->iter, attribute->column, &value);
969 g_object_set_property (G_OBJECT (renderer), attribute->attribute, &value);
970 g_value_unset (&value);
973 /* Call any GtkCellLayoutDataFunc that may have been set by the user
976 info->func (GTK_CELL_LAYOUT (data->area), renderer,
977 data->model, data->iter, info->data);
979 g_object_thaw_notify (G_OBJECT (renderer));
983 gtk_cell_area_real_apply_attributes (GtkCellArea *area,
984 GtkTreeModel *tree_model,
986 gboolean is_expander,
987 gboolean is_expanded)
990 GtkCellAreaPrivate *priv;
996 /* Feed in data needed to apply to every renderer */
998 data.model = tree_model;
1000 data.is_expander = is_expander;
1001 data.is_expanded = is_expanded;
1003 /* Go over any cells that have attributes or custom GtkCellLayoutDataFuncs and
1004 * apply the data from the treemodel */
1005 g_hash_table_foreach (priv->cell_info, (GHFunc)apply_cell_attributes, &data);
1007 /* Update the currently applied path */
1008 g_free (priv->current_path);
1009 path = gtk_tree_model_get_path (tree_model, iter);
1010 priv->current_path = gtk_tree_path_to_string (path);
1011 gtk_tree_path_free (path);
1015 gtk_cell_area_real_get_preferred_height_for_width (GtkCellArea *area,
1016 GtkCellAreaContext *context,
1019 gint *minimum_height,
1020 gint *natural_height)
1022 /* If the area doesnt do height-for-width, fallback on base preferred height */
1023 GTK_CELL_AREA_GET_CLASS (area)->get_preferred_width (area, context, widget, minimum_height, natural_height);
1027 gtk_cell_area_real_get_preferred_width_for_height (GtkCellArea *area,
1028 GtkCellAreaContext *context,
1031 gint *minimum_width,
1032 gint *natural_width)
1034 /* If the area doesnt do width-for-height, fallback on base preferred width */
1035 GTK_CELL_AREA_GET_CLASS (area)->get_preferred_width (area, context, widget, minimum_width, natural_width);
1039 get_is_activatable (GtkCellRenderer *renderer,
1040 gboolean *activatable)
1043 if (gtk_cell_renderer_is_activatable (renderer))
1044 *activatable = TRUE;
1046 return *activatable;
1050 gtk_cell_area_real_is_activatable (GtkCellArea *area)
1052 gboolean activatable = FALSE;
1054 /* Checks if any renderer can focus for the currently applied
1057 * Subclasses can override this in the case that they are also
1058 * rendering widgets as well as renderers.
1060 gtk_cell_area_foreach (area, (GtkCellCallback)get_is_activatable, &activatable);
1066 gtk_cell_area_real_activate (GtkCellArea *area,
1067 GtkCellAreaContext *context,
1069 const GdkRectangle *cell_area,
1070 GtkCellRendererState flags)
1072 GtkCellAreaPrivate *priv = area->priv;
1073 GdkRectangle background_area;
1074 GtkCellRenderer *activate_cell = NULL;
1076 if (priv->focus_cell)
1077 activate_cell = priv->focus_cell;
1082 /* GtkTreeView sometimes wants to activate a cell when no
1083 * cells are in focus.
1085 cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (area));
1086 for (l = cells; l && !activate_cell; l = l->next)
1088 GtkCellRenderer *renderer = l->data;
1090 if (gtk_cell_renderer_is_activatable (renderer))
1091 activate_cell = renderer;
1093 g_list_free (cells);
1099 /* Get the allocation of the focused cell.
1101 gtk_cell_area_get_cell_allocation (area, context, widget, activate_cell,
1102 cell_area, &background_area);
1104 /* Activate or Edit the cell
1106 * Currently just not sending an event, renderers afaics dont use
1107 * the event argument anyway, worst case is we can synthesize one.
1109 if (gtk_cell_area_activate_cell (area, widget, activate_cell, NULL,
1110 &background_area, flags))
1117 /*************************************************************
1118 * GtkCellLayoutIface *
1119 *************************************************************/
1121 gtk_cell_area_cell_layout_init (GtkCellLayoutIface *iface)
1123 iface->pack_start = gtk_cell_area_pack_default;
1124 iface->pack_end = gtk_cell_area_pack_default;
1125 iface->clear = gtk_cell_area_clear;
1126 iface->add_attribute = gtk_cell_area_add_attribute;
1127 iface->set_cell_data_func = gtk_cell_area_set_cell_data_func;
1128 iface->clear_attributes = gtk_cell_area_clear_attributes;
1129 iface->reorder = gtk_cell_area_reorder;
1130 iface->get_cells = gtk_cell_area_get_cells;
1134 gtk_cell_area_pack_default (GtkCellLayout *cell_layout,
1135 GtkCellRenderer *renderer,
1138 gtk_cell_area_add (GTK_CELL_AREA (cell_layout), renderer);
1142 gtk_cell_area_clear (GtkCellLayout *cell_layout)
1144 GtkCellArea *area = GTK_CELL_AREA (cell_layout);
1146 gtk_cell_layout_get_cells (cell_layout);
1148 for (l = cells; l; l = l->next)
1150 GtkCellRenderer *renderer = l->data;
1151 gtk_cell_area_remove (area, renderer);
1154 g_list_free (cells);
1158 gtk_cell_area_add_attribute (GtkCellLayout *cell_layout,
1159 GtkCellRenderer *renderer,
1160 const gchar *attribute,
1163 gtk_cell_area_attribute_connect (GTK_CELL_AREA (cell_layout),
1164 renderer, attribute, column);
1168 gtk_cell_area_set_cell_data_func (GtkCellLayout *cell_layout,
1169 GtkCellRenderer *renderer,
1170 GtkCellLayoutDataFunc func,
1172 GDestroyNotify destroy)
1174 GtkCellArea *area = GTK_CELL_AREA (cell_layout);
1175 GtkCellAreaPrivate *priv = area->priv;
1178 info = g_hash_table_lookup (priv->cell_info, renderer);
1182 if (info->destroy && info->data)
1183 info->destroy (info->data);
1188 info->data = func_data;
1189 info->destroy = destroy;
1195 info->destroy = NULL;
1200 info = cell_info_new (func, func_data, destroy);
1202 g_hash_table_insert (priv->cell_info, renderer, info);
1207 gtk_cell_area_clear_attributes (GtkCellLayout *cell_layout,
1208 GtkCellRenderer *renderer)
1210 GtkCellArea *area = GTK_CELL_AREA (cell_layout);
1211 GtkCellAreaPrivate *priv = area->priv;
1214 info = g_hash_table_lookup (priv->cell_info, renderer);
1218 g_slist_foreach (info->attributes, (GFunc)cell_attribute_free, NULL);
1219 g_slist_free (info->attributes);
1221 info->attributes = NULL;
1226 gtk_cell_area_reorder (GtkCellLayout *cell_layout,
1227 GtkCellRenderer *cell,
1230 g_warning ("GtkCellLayout::reorder not implemented for `%s'",
1231 g_type_name (G_TYPE_FROM_INSTANCE (cell_layout)));
1235 accum_cells (GtkCellRenderer *renderer,
1238 *accum = g_list_prepend (*accum, renderer);
1244 gtk_cell_area_get_cells (GtkCellLayout *cell_layout)
1246 GList *cells = NULL;
1248 gtk_cell_area_foreach (GTK_CELL_AREA (cell_layout),
1249 (GtkCellCallback)accum_cells,
1252 return g_list_reverse (cells);
1256 /*************************************************************
1258 *************************************************************/
1261 * gtk_cell_area_add:
1262 * @area: a #GtkCellArea
1263 * @renderer: the #GtkCellRenderer to add to @area
1265 * Adds @renderer to @area with the default child cell properties.
1270 gtk_cell_area_add (GtkCellArea *area,
1271 GtkCellRenderer *renderer)
1273 GtkCellAreaClass *class;
1275 g_return_if_fail (GTK_IS_CELL_AREA (area));
1276 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1278 class = GTK_CELL_AREA_GET_CLASS (area);
1281 class->add (area, renderer);
1283 g_warning ("GtkCellAreaClass::add not implemented for `%s'",
1284 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1288 * gtk_cell_area_remove:
1289 * @area: a #GtkCellArea
1290 * @renderer: the #GtkCellRenderer to remove from @area
1292 * Removes @renderer from @area.
1297 gtk_cell_area_remove (GtkCellArea *area,
1298 GtkCellRenderer *renderer)
1300 GtkCellAreaClass *class;
1301 GtkCellAreaPrivate *priv;
1302 GList *renderers, *l;
1304 g_return_if_fail (GTK_IS_CELL_AREA (area));
1305 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1307 class = GTK_CELL_AREA_GET_CLASS (area);
1310 /* Remove any custom attributes and custom cell data func here first */
1311 g_hash_table_remove (priv->cell_info, renderer);
1313 /* Remove focus siblings of this renderer */
1314 g_hash_table_remove (priv->focus_siblings, renderer);
1316 /* Remove this renderer from any focus renderer's sibling list */
1317 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (area));
1319 for (l = renderers; l; l = l->next)
1321 GtkCellRenderer *focus_renderer = l->data;
1323 if (gtk_cell_area_is_focus_sibling (area, focus_renderer, renderer))
1325 gtk_cell_area_remove_focus_sibling (area, focus_renderer, renderer);
1330 g_list_free (renderers);
1333 class->remove (area, renderer);
1335 g_warning ("GtkCellAreaClass::remove not implemented for `%s'",
1336 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1340 get_has_renderer (GtkCellRenderer *renderer,
1341 HasRendererCheck *check)
1343 if (renderer == check->renderer)
1344 check->has_renderer = TRUE;
1346 return check->has_renderer;
1350 * gtk_cell_area_has_renderer:
1351 * @area: a #GtkCellArea
1352 * @renderer: the #GtkCellRenderer to check
1354 * Checks if @area contains @renderer.
1356 * Return value: %TRUE if @renderer is in the @area.
1361 gtk_cell_area_has_renderer (GtkCellArea *area,
1362 GtkCellRenderer *renderer)
1364 HasRendererCheck check = { renderer, FALSE };
1366 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
1367 g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), FALSE);
1369 gtk_cell_area_foreach (area, (GtkCellCallback)get_has_renderer, &check);
1371 return check.has_renderer;
1375 * gtk_cell_area_foreach:
1376 * @area: a #GtkCellArea
1377 * @callback: the #GtkCellCallback to call
1378 * @callback_data: user provided data pointer
1380 * Calls @callback for every #GtkCellRenderer in @area.
1385 gtk_cell_area_foreach (GtkCellArea *area,
1386 GtkCellCallback callback,
1387 gpointer callback_data)
1389 GtkCellAreaClass *class;
1391 g_return_if_fail (GTK_IS_CELL_AREA (area));
1392 g_return_if_fail (callback != NULL);
1394 class = GTK_CELL_AREA_GET_CLASS (area);
1397 class->foreach (area, callback, callback_data);
1399 g_warning ("GtkCellAreaClass::foreach not implemented for `%s'",
1400 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1404 * gtk_cell_area_get_cell_allocation:
1405 * @area: a #GtkCellArea
1406 * @context: the #GtkCellAreaContext used to hold sizes for @area.
1407 * @widget: the #GtkWidget that @area is rendering on
1408 * @renderer: the #GtkCellRenderer to get the allocation for
1409 * @cell_area: the whole allocated area for @area in @widget
1411 * @allocation: (out): where to store the allocation for @renderer
1413 * Derives the allocation of @renderer inside @area if @area
1414 * were to be renderered in @cell_area.
1419 gtk_cell_area_get_cell_allocation (GtkCellArea *area,
1420 GtkCellAreaContext *context,
1422 GtkCellRenderer *renderer,
1423 const GdkRectangle *cell_area,
1424 GdkRectangle *allocation)
1426 GtkCellAreaClass *class;
1428 g_return_if_fail (GTK_IS_CELL_AREA (area));
1429 g_return_if_fail (GTK_IS_CELL_AREA_CONTEXT (context));
1430 g_return_if_fail (GTK_IS_WIDGET (widget));
1431 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1432 g_return_if_fail (cell_area != NULL);
1433 g_return_if_fail (allocation != NULL);
1435 class = GTK_CELL_AREA_GET_CLASS (area);
1437 if (class->get_cell_allocation)
1438 class->get_cell_allocation (area, context, widget, renderer, cell_area, allocation);
1440 g_warning ("GtkCellAreaClass::get_cell_allocation not implemented for `%s'",
1441 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1445 * gtk_cell_area_event:
1446 * @area: a #GtkCellArea
1447 * @context: the #GtkCellAreaContext for this row of data.
1448 * @widget: the #GtkWidget that @area is rendering to
1449 * @event: the #GdkEvent to handle
1450 * @cell_area: the @widget relative coordinates for @area
1451 * @flags: the #GtkCellRendererState for @area in this row.
1453 * Delegates event handling to a #GtkCellArea.
1455 * Return value: %TRUE if the event was handled by @area.
1460 gtk_cell_area_event (GtkCellArea *area,
1461 GtkCellAreaContext *context,
1464 const GdkRectangle *cell_area,
1465 GtkCellRendererState flags)
1467 GtkCellAreaClass *class;
1469 g_return_val_if_fail (GTK_IS_CELL_AREA (area), 0);
1470 g_return_val_if_fail (GTK_IS_CELL_AREA_CONTEXT (context), 0);
1471 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
1472 g_return_val_if_fail (event != NULL, 0);
1473 g_return_val_if_fail (cell_area != NULL, 0);
1475 class = GTK_CELL_AREA_GET_CLASS (area);
1478 return class->event (area, context, widget, event, cell_area, flags);
1480 g_warning ("GtkCellAreaClass::event not implemented for `%s'",
1481 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1486 * gtk_cell_area_render:
1487 * @area: a #GtkCellArea
1488 * @context: the #GtkCellAreaContext for this row of data.
1489 * @widget: the #GtkWidget that @area is rendering to
1490 * @cr: the #cairo_t to render with
1491 * @background_area: the @widget relative coordinates for @area's background
1492 * @cell_area: the @widget relative coordinates for @area
1493 * @flags: the #GtkCellRendererState for @area in this row.
1494 * @paint_focus: whether @area should paint focus on focused cells for focused rows or not.
1496 * Renders @area's cells according to @area's layout onto @widget at
1497 * the given coordinates.
1502 gtk_cell_area_render (GtkCellArea *area,
1503 GtkCellAreaContext *context,
1506 const GdkRectangle *background_area,
1507 const GdkRectangle *cell_area,
1508 GtkCellRendererState flags,
1509 gboolean paint_focus)
1511 GtkCellAreaClass *class;
1513 g_return_if_fail (GTK_IS_CELL_AREA (area));
1514 g_return_if_fail (GTK_IS_CELL_AREA_CONTEXT (context));
1515 g_return_if_fail (GTK_IS_WIDGET (widget));
1516 g_return_if_fail (cr != NULL);
1517 g_return_if_fail (background_area != NULL);
1518 g_return_if_fail (cell_area != NULL);
1520 class = GTK_CELL_AREA_GET_CLASS (area);
1523 class->render (area, context, widget, cr, background_area, cell_area, flags, paint_focus);
1525 g_warning ("GtkCellAreaClass::render not implemented for `%s'",
1526 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1530 * gtk_cell_area_set_style_detail:
1531 * @area: a #GtkCellArea
1532 * @detail: the #GtkStyle detail string to set
1534 * Sets the detail string used in any gtk_paint_*() functions
1540 gtk_cell_area_set_style_detail (GtkCellArea *area,
1541 const gchar *detail)
1543 GtkCellAreaPrivate *priv;
1545 g_return_if_fail (GTK_IS_CELL_AREA (area));
1549 if (g_strcmp0 (priv->style_detail, detail) != 0)
1551 g_free (priv->style_detail);
1552 priv->style_detail = g_strdup (detail);
1557 * gtk_cell_area_get_style_detail:
1558 * @area: a #GtkCellArea
1560 * Gets the detail string used in any gtk_paint_*() functions
1563 * Return value: the detail string, the string belongs to the area and should not be freed.
1567 G_CONST_RETURN gchar *
1568 gtk_cell_area_get_style_detail (GtkCellArea *area)
1570 GtkCellAreaPrivate *priv;
1572 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
1576 return priv->style_detail;
1579 /*************************************************************
1581 *************************************************************/
1583 * gtk_cell_area_create_context:
1584 * @area: a #GtkCellArea
1586 * Creates a #GtkCellAreaContext to be used with @area for
1587 * all purposes. #GtkCellAreaContext stores geometry information
1588 * for rows for which it was operated on, it is important to use
1589 * the same context for the same row of data at all times (i.e.
1590 * one should render and handle events with the same #GtkCellAreaContext
1591 * which was used to request the size of those rows of data).
1593 * Return value: (transfer full): a newly created #GtkCellAreaContext which can be used with @area.
1597 GtkCellAreaContext *
1598 gtk_cell_area_create_context (GtkCellArea *area)
1600 GtkCellAreaClass *class;
1602 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
1604 class = GTK_CELL_AREA_GET_CLASS (area);
1606 if (class->create_context)
1607 return class->create_context (area);
1609 g_warning ("GtkCellAreaClass::create_context not implemented for `%s'",
1610 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1617 * gtk_cell_area_get_request_mode:
1618 * @area: a #GtkCellArea
1620 * Gets whether the area prefers a height-for-width layout
1621 * or a width-for-height layout.
1623 * Return value: The #GtkSizeRequestMode preferred by @area.
1628 gtk_cell_area_get_request_mode (GtkCellArea *area)
1630 GtkCellAreaClass *class;
1632 g_return_val_if_fail (GTK_IS_CELL_AREA (area),
1633 GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH);
1635 class = GTK_CELL_AREA_GET_CLASS (area);
1637 if (class->get_request_mode)
1638 return class->get_request_mode (area);
1640 g_warning ("GtkCellAreaClass::get_request_mode not implemented for `%s'",
1641 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1643 return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
1647 * gtk_cell_area_get_preferred_width:
1648 * @area: a #GtkCellArea
1649 * @context: the #GtkCellAreaContext to perform this request with
1650 * @widget: the #GtkWidget where @area will be rendering
1651 * @minimum_width: (out) (allow-none): location to store the minimum width, or %NULL
1652 * @natural_width: (out) (allow-none): location to store the natural width, or %NULL
1654 * Retrieves a cell area's initial minimum and natural width.
1656 * @area will store some geometrical information in @context along the way,
1657 * when requesting sizes over an arbitrary number of rows, its not important
1658 * to check the @minimum_width and @natural_width of this call but rather to
1659 * consult gtk_cell_area_context_get_preferred_width() after a series of
1665 gtk_cell_area_get_preferred_width (GtkCellArea *area,
1666 GtkCellAreaContext *context,
1668 gint *minimum_width,
1669 gint *natural_width)
1671 GtkCellAreaClass *class;
1673 g_return_if_fail (GTK_IS_CELL_AREA (area));
1674 g_return_if_fail (GTK_IS_WIDGET (widget));
1676 class = GTK_CELL_AREA_GET_CLASS (area);
1678 if (class->get_preferred_width)
1679 class->get_preferred_width (area, context, widget, minimum_width, natural_width);
1681 g_warning ("GtkCellAreaClass::get_preferred_width not implemented for `%s'",
1682 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1686 * gtk_cell_area_get_preferred_height_for_width:
1687 * @area: a #GtkCellArea
1688 * @context: the #GtkCellAreaContext which has already been requested for widths.
1689 * @widget: the #GtkWidget where @area will be rendering
1690 * @width: the width for which to check the height of this area
1691 * @minimum_height: (out) (allow-none): location to store the minimum height, or %NULL
1692 * @natural_height: (out) (allow-none): location to store the natural height, or %NULL
1694 * Retrieves a cell area's minimum and natural height if it would be given
1695 * the specified @width.
1697 * @area stores some geometrical information in @context along the way
1698 * while calling gtk_cell_area_get_preferred_width(), it's important to
1699 * perform a series of gtk_cell_area_get_preferred_width() requests with
1700 * @context first and then call gtk_cell_area_get_preferred_height_for_width()
1701 * on each cell area individually to get the height for width of each
1702 * fully requested row.
1704 * If at some point, the width of a single row changes, it should be
1705 * requested with gtk_cell_area_get_preferred_width() again and then
1706 * the full width of the requested rows checked again with
1707 * gtk_cell_area_context_get_preferred_width().
1712 gtk_cell_area_get_preferred_height_for_width (GtkCellArea *area,
1713 GtkCellAreaContext *context,
1716 gint *minimum_height,
1717 gint *natural_height)
1719 GtkCellAreaClass *class;
1721 g_return_if_fail (GTK_IS_CELL_AREA (area));
1722 g_return_if_fail (GTK_IS_WIDGET (widget));
1724 class = GTK_CELL_AREA_GET_CLASS (area);
1725 class->get_preferred_height_for_width (area, context, widget, width, minimum_height, natural_height);
1730 * gtk_cell_area_get_preferred_height:
1731 * @area: a #GtkCellArea
1732 * @context: the #GtkCellAreaContext to perform this request with
1733 * @widget: the #GtkWidget where @area will be rendering
1734 * @minimum_height: (out) (allow-none): location to store the minimum height, or %NULL
1735 * @natural_height: (out) (allow-none): location to store the natural height, or %NULL
1737 * Retrieves a cell area's initial minimum and natural height.
1739 * @area will store some geometrical information in @context along the way,
1740 * when requesting sizes over an arbitrary number of rows, its not important
1741 * to check the @minimum_height and @natural_height of this call but rather to
1742 * consult gtk_cell_area_context_get_preferred_height() after a series of
1748 gtk_cell_area_get_preferred_height (GtkCellArea *area,
1749 GtkCellAreaContext *context,
1751 gint *minimum_height,
1752 gint *natural_height)
1754 GtkCellAreaClass *class;
1756 g_return_if_fail (GTK_IS_CELL_AREA (area));
1757 g_return_if_fail (GTK_IS_WIDGET (widget));
1759 class = GTK_CELL_AREA_GET_CLASS (area);
1761 if (class->get_preferred_height)
1762 class->get_preferred_height (area, context, widget, minimum_height, natural_height);
1764 g_warning ("GtkCellAreaClass::get_preferred_height not implemented for `%s'",
1765 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1769 * gtk_cell_area_get_preferred_width_for_height:
1770 * @area: a #GtkCellArea
1771 * @context: the #GtkCellAreaContext which has already been requested for widths.
1772 * @widget: the #GtkWidget where @area will be rendering
1773 * @height: the height for which to check the width of this area
1774 * @minimum_width: (out) (allow-none): location to store the minimum width, or %NULL
1775 * @natural_width: (out) (allow-none): location to store the natural width, or %NULL
1777 * Retrieves a cell area's minimum and natural width if it would be given
1778 * the specified @height.
1780 * @area stores some geometrical information in @context along the way
1781 * while calling gtk_cell_area_get_preferred_height(), it's important to
1782 * perform a series of gtk_cell_area_get_preferred_height() requests with
1783 * @context first and then call gtk_cell_area_get_preferred_width_for_height()
1784 * on each cell area individually to get the height for width of each
1785 * fully requested row.
1787 * If at some point, the height of a single row changes, it should be
1788 * requested with gtk_cell_area_get_preferred_height() again and then
1789 * the full height of the requested rows checked again with
1790 * gtk_cell_area_context_get_preferred_height().
1795 gtk_cell_area_get_preferred_width_for_height (GtkCellArea *area,
1796 GtkCellAreaContext *context,
1799 gint *minimum_width,
1800 gint *natural_width)
1802 GtkCellAreaClass *class;
1804 g_return_if_fail (GTK_IS_CELL_AREA (area));
1805 g_return_if_fail (GTK_IS_WIDGET (widget));
1807 class = GTK_CELL_AREA_GET_CLASS (area);
1808 class->get_preferred_width_for_height (area, context, widget, height, minimum_width, natural_width);
1811 /*************************************************************
1813 *************************************************************/
1816 * gtk_cell_area_attribute_connect:
1817 * @area: a #GtkCellArea
1818 * @renderer: the #GtkCellRenderer to connect an attribute for
1819 * @attribute: the attribute name
1820 * @column: the #GtkTreeModel column to fetch attribute values from
1822 * Connects an @attribute to apply values from @column for the
1823 * #GtkTreeModel in use.
1828 gtk_cell_area_attribute_connect (GtkCellArea *area,
1829 GtkCellRenderer *renderer,
1830 const gchar *attribute,
1833 GtkCellAreaPrivate *priv;
1835 CellAttribute *cell_attribute;
1837 g_return_if_fail (GTK_IS_CELL_AREA (area));
1838 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1839 g_return_if_fail (attribute != NULL);
1840 g_return_if_fail (gtk_cell_area_has_renderer (area, renderer));
1843 info = g_hash_table_lookup (priv->cell_info, renderer);
1847 info = cell_info_new (NULL, NULL, NULL);
1849 g_hash_table_insert (priv->cell_info, renderer, info);
1855 /* Check we are not adding the same attribute twice */
1856 if ((node = g_slist_find_custom (info->attributes, attribute,
1857 (GCompareFunc)cell_attribute_find)) != NULL)
1859 cell_attribute = node->data;
1861 g_warning ("Cannot connect attribute `%s' for cell renderer class `%s' "
1862 "since `%s' is already attributed to column %d",
1864 g_type_name (G_TYPE_FROM_INSTANCE (area)),
1865 attribute, cell_attribute->column);
1870 cell_attribute = cell_attribute_new (renderer, attribute, column);
1872 if (!cell_attribute)
1874 g_warning ("Cannot connect attribute `%s' for cell renderer class `%s' "
1875 "since attribute does not exist",
1877 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1881 info->attributes = g_slist_prepend (info->attributes, cell_attribute);
1885 * gtk_cell_area_attribute_disconnect:
1886 * @area: a #GtkCellArea
1887 * @renderer: the #GtkCellRenderer to disconnect an attribute for
1888 * @attribute: the attribute name
1890 * Disconnects @attribute for the @renderer in @area so that
1891 * attribute will no longer be updated with values from the
1897 gtk_cell_area_attribute_disconnect (GtkCellArea *area,
1898 GtkCellRenderer *renderer,
1899 const gchar *attribute)
1901 GtkCellAreaPrivate *priv;
1903 CellAttribute *cell_attribute;
1906 g_return_if_fail (GTK_IS_CELL_AREA (area));
1907 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1908 g_return_if_fail (attribute != NULL);
1909 g_return_if_fail (gtk_cell_area_has_renderer (area, renderer));
1912 info = g_hash_table_lookup (priv->cell_info, renderer);
1916 node = g_slist_find_custom (info->attributes, attribute,
1917 (GCompareFunc)cell_attribute_find);
1920 cell_attribute = node->data;
1922 cell_attribute_free (cell_attribute);
1924 info->attributes = g_slist_delete_link (info->attributes, node);
1930 * gtk_cell_area_apply_attributes
1931 * @area: a #GtkCellArea
1932 * @tree_model: the #GtkTreeModel to pull values from
1933 * @iter: the #GtkTreeIter in @tree_model to apply values for
1934 * @is_expander: whether @iter has children
1935 * @is_expanded: whether @iter is expanded in the view and
1936 * children are visible
1938 * Applies any connected attributes to the renderers in
1939 * @area by pulling the values from @tree_model.
1944 gtk_cell_area_apply_attributes (GtkCellArea *area,
1945 GtkTreeModel *tree_model,
1947 gboolean is_expander,
1948 gboolean is_expanded)
1950 g_return_if_fail (GTK_IS_CELL_AREA (area));
1951 g_return_if_fail (GTK_IS_TREE_MODEL (tree_model));
1952 g_return_if_fail (iter != NULL);
1954 g_signal_emit (area, cell_area_signals[SIGNAL_APPLY_ATTRIBUTES], 0,
1955 tree_model, iter, is_expander, is_expanded);
1959 * gtk_cell_area_get_current_path_string:
1960 * @area: a #GtkCellArea
1962 * Gets the current #GtkTreePath string for the currently
1963 * applied #GtkTreeIter, this is implicitly updated when
1964 * gtk_cell_area_apply_attributes() is called and can be
1965 * used to interact with renderers from #GtkCellArea
1968 * Return value: The current #GtkTreePath string for the current
1969 * attributes applied to @area. This string belongs to the area and
1970 * should not be freed.
1974 G_CONST_RETURN gchar *
1975 gtk_cell_area_get_current_path_string (GtkCellArea *area)
1977 GtkCellAreaPrivate *priv;
1979 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
1983 return priv->current_path;
1987 /*************************************************************
1988 * API: Cell Properties *
1989 *************************************************************/
1991 * gtk_cell_area_class_install_cell_property:
1992 * @aclass: a #GtkCellAreaClass
1993 * @property_id: the id for the property
1994 * @pspec: the #GParamSpec for the property
1996 * Installs a cell property on a cell area class.
2001 gtk_cell_area_class_install_cell_property (GtkCellAreaClass *aclass,
2005 g_return_if_fail (GTK_IS_CELL_AREA_CLASS (aclass));
2006 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
2007 if (pspec->flags & G_PARAM_WRITABLE)
2008 g_return_if_fail (aclass->set_cell_property != NULL);
2009 if (pspec->flags & G_PARAM_READABLE)
2010 g_return_if_fail (aclass->get_cell_property != NULL);
2011 g_return_if_fail (property_id > 0);
2012 g_return_if_fail (PARAM_SPEC_PARAM_ID (pspec) == 0); /* paranoid */
2013 g_return_if_fail ((pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY)) == 0);
2015 if (g_param_spec_pool_lookup (cell_property_pool, pspec->name, G_OBJECT_CLASS_TYPE (aclass), TRUE))
2017 g_warning (G_STRLOC ": class `%s' already contains a cell property named `%s'",
2018 G_OBJECT_CLASS_NAME (aclass), pspec->name);
2021 g_param_spec_ref (pspec);
2022 g_param_spec_sink (pspec);
2023 PARAM_SPEC_SET_PARAM_ID (pspec, property_id);
2024 g_param_spec_pool_insert (cell_property_pool, pspec, G_OBJECT_CLASS_TYPE (aclass));
2028 * gtk_cell_area_class_find_cell_property:
2029 * @aclass: a #GtkCellAreaClass
2030 * @property_name: the name of the child property to find
2032 * Finds a cell property of a cell area class by name.
2034 * Return value: (allow-none): the #GParamSpec of the child property or %NULL if @aclass has no
2035 * child property with that name.
2040 gtk_cell_area_class_find_cell_property (GtkCellAreaClass *aclass,
2041 const gchar *property_name)
2043 g_return_val_if_fail (GTK_IS_CELL_AREA_CLASS (aclass), NULL);
2044 g_return_val_if_fail (property_name != NULL, NULL);
2046 return g_param_spec_pool_lookup (cell_property_pool,
2048 G_OBJECT_CLASS_TYPE (aclass),
2053 * gtk_cell_area_class_list_cell_properties:
2054 * @aclass: a #GtkCellAreaClass
2055 * @n_properties: location to return the number of cell properties found
2057 * Returns all cell properties of a cell area class.
2059 * Return value: a newly allocated %NULL-terminated array of #GParamSpec*.
2060 * The array must be freed with g_free().
2065 gtk_cell_area_class_list_cell_properties (GtkCellAreaClass *aclass,
2066 guint *n_properties)
2068 GParamSpec **pspecs;
2071 g_return_val_if_fail (GTK_IS_CELL_AREA_CLASS (aclass), NULL);
2073 pspecs = g_param_spec_pool_list (cell_property_pool,
2074 G_OBJECT_CLASS_TYPE (aclass),
2083 * gtk_cell_area_add_with_properties:
2084 * @area: a #GtkCellArea
2085 * @renderer: a #GtkCellRenderer to be placed inside @area
2086 * @first_prop_name: the name of the first cell property to set
2087 * @Varargs: a %NULL-terminated list of property names and values, starting
2088 * with @first_prop_name
2090 * Adds @renderer to @area, setting cell properties at the same time.
2091 * See gtk_cell_area_add() and gtk_cell_area_child_set() for more details.
2096 gtk_cell_area_add_with_properties (GtkCellArea *area,
2097 GtkCellRenderer *renderer,
2098 const gchar *first_prop_name,
2101 GtkCellAreaClass *class;
2103 g_return_if_fail (GTK_IS_CELL_AREA (area));
2104 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2106 class = GTK_CELL_AREA_GET_CLASS (area);
2112 class->add (area, renderer);
2114 va_start (var_args, first_prop_name);
2115 gtk_cell_area_cell_set_valist (area, renderer, first_prop_name, var_args);
2119 g_warning ("GtkCellAreaClass::add not implemented for `%s'",
2120 g_type_name (G_TYPE_FROM_INSTANCE (area)));
2124 * gtk_cell_area_cell_set:
2125 * @area: a #GtkCellArea
2126 * @renderer: a #GtkCellRenderer which is a cell inside @area
2127 * @first_prop_name: the name of the first cell property to set
2128 * @Varargs: a %NULL-terminated list of property names and values, starting
2129 * with @first_prop_name
2131 * Sets one or more cell properties for @cell in @area.
2136 gtk_cell_area_cell_set (GtkCellArea *area,
2137 GtkCellRenderer *renderer,
2138 const gchar *first_prop_name,
2143 g_return_if_fail (GTK_IS_CELL_AREA (area));
2144 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2146 va_start (var_args, first_prop_name);
2147 gtk_cell_area_cell_set_valist (area, renderer, first_prop_name, var_args);
2152 * gtk_cell_area_cell_get:
2153 * @area: a #GtkCellArea
2154 * @renderer: a #GtkCellRenderer which is inside @area
2155 * @first_prop_name: the name of the first cell property to get
2156 * @Varargs: return location for the first cell property, followed
2157 * optionally by more name/return location pairs, followed by %NULL
2159 * Gets the values of one or more cell properties for @renderer in @area.
2164 gtk_cell_area_cell_get (GtkCellArea *area,
2165 GtkCellRenderer *renderer,
2166 const gchar *first_prop_name,
2171 g_return_if_fail (GTK_IS_CELL_AREA (area));
2172 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2174 va_start (var_args, first_prop_name);
2175 gtk_cell_area_cell_get_valist (area, renderer, first_prop_name, var_args);
2180 area_get_cell_property (GtkCellArea *area,
2181 GtkCellRenderer *renderer,
2185 GtkCellAreaClass *class = g_type_class_peek (pspec->owner_type);
2187 class->get_cell_property (area, renderer, PARAM_SPEC_PARAM_ID (pspec), value, pspec);
2191 area_set_cell_property (GtkCellArea *area,
2192 GtkCellRenderer *renderer,
2194 const GValue *value)
2196 GValue tmp_value = { 0, };
2197 GtkCellAreaClass *class = g_type_class_peek (pspec->owner_type);
2199 /* provide a copy to work from, convert (if necessary) and validate */
2200 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2201 if (!g_value_transform (value, &tmp_value))
2202 g_warning ("unable to set cell property `%s' of type `%s' from value of type `%s'",
2204 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
2205 G_VALUE_TYPE_NAME (value));
2206 else if (g_param_value_validate (pspec, &tmp_value) && !(pspec->flags & G_PARAM_LAX_VALIDATION))
2208 gchar *contents = g_strdup_value_contents (value);
2210 g_warning ("value \"%s\" of type `%s' is invalid for property `%s' of type `%s'",
2212 G_VALUE_TYPE_NAME (value),
2214 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
2219 class->set_cell_property (area, renderer, PARAM_SPEC_PARAM_ID (pspec), &tmp_value, pspec);
2221 g_value_unset (&tmp_value);
2225 * gtk_cell_area_cell_set_valist:
2226 * @area: a #GtkCellArea
2227 * @renderer: a #GtkCellRenderer which inside @area
2228 * @first_property_name: the name of the first cell property to set
2229 * @var_args: a %NULL-terminated list of property names and values, starting
2230 * with @first_prop_name
2232 * Sets one or more cell properties for @renderer in @area.
2237 gtk_cell_area_cell_set_valist (GtkCellArea *area,
2238 GtkCellRenderer *renderer,
2239 const gchar *first_property_name,
2244 g_return_if_fail (GTK_IS_CELL_AREA (area));
2245 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2247 name = first_property_name;
2250 GValue value = { 0, };
2251 gchar *error = NULL;
2253 g_param_spec_pool_lookup (cell_property_pool, name,
2254 G_OBJECT_TYPE (area), TRUE);
2257 g_warning ("%s: cell area class `%s' has no cell property named `%s'",
2258 G_STRLOC, G_OBJECT_TYPE_NAME (area), name);
2261 if (!(pspec->flags & G_PARAM_WRITABLE))
2263 g_warning ("%s: cell property `%s' of cell area class `%s' is not writable",
2264 G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
2268 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2269 G_VALUE_COLLECT (&value, var_args, 0, &error);
2272 g_warning ("%s: %s", G_STRLOC, error);
2275 /* we purposely leak the value here, it might not be
2276 * in a sane state if an error condition occoured
2280 area_set_cell_property (area, renderer, pspec, &value);
2281 g_value_unset (&value);
2282 name = va_arg (var_args, gchar*);
2287 * gtk_cell_area_cell_get_valist:
2288 * @area: a #GtkCellArea
2289 * @renderer: a #GtkCellRenderer inside @area
2290 * @first_property_name: the name of the first property to get
2291 * @var_args: return location for the first property, followed
2292 * optionally by more name/return location pairs, followed by %NULL
2294 * Gets the values of one or more cell properties for @renderer in @area.
2299 gtk_cell_area_cell_get_valist (GtkCellArea *area,
2300 GtkCellRenderer *renderer,
2301 const gchar *first_property_name,
2306 g_return_if_fail (GTK_IS_CELL_AREA (area));
2307 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2309 name = first_property_name;
2312 GValue value = { 0, };
2316 pspec = g_param_spec_pool_lookup (cell_property_pool, name,
2317 G_OBJECT_TYPE (area), TRUE);
2320 g_warning ("%s: cell area class `%s' has no cell property named `%s'",
2321 G_STRLOC, G_OBJECT_TYPE_NAME (area), name);
2324 if (!(pspec->flags & G_PARAM_READABLE))
2326 g_warning ("%s: cell property `%s' of cell area class `%s' is not readable",
2327 G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
2331 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2332 area_get_cell_property (area, renderer, pspec, &value);
2333 G_VALUE_LCOPY (&value, var_args, 0, &error);
2336 g_warning ("%s: %s", G_STRLOC, error);
2338 g_value_unset (&value);
2341 g_value_unset (&value);
2342 name = va_arg (var_args, gchar*);
2347 * gtk_cell_area_cell_set_property:
2348 * @area: a #GtkCellArea
2349 * @renderer: a #GtkCellRenderer inside @area
2350 * @property_name: the name of the cell property to set
2351 * @value: the value to set the cell property to
2353 * Sets a cell property for @renderer in @area.
2358 gtk_cell_area_cell_set_property (GtkCellArea *area,
2359 GtkCellRenderer *renderer,
2360 const gchar *property_name,
2361 const GValue *value)
2365 g_return_if_fail (GTK_IS_CELL_AREA (area));
2366 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2367 g_return_if_fail (property_name != NULL);
2368 g_return_if_fail (G_IS_VALUE (value));
2370 pspec = g_param_spec_pool_lookup (cell_property_pool, property_name,
2371 G_OBJECT_TYPE (area), TRUE);
2373 g_warning ("%s: cell area class `%s' has no cell property named `%s'",
2374 G_STRLOC, G_OBJECT_TYPE_NAME (area), property_name);
2375 else if (!(pspec->flags & G_PARAM_WRITABLE))
2376 g_warning ("%s: cell property `%s' of cell area class `%s' is not writable",
2377 G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
2380 area_set_cell_property (area, renderer, pspec, value);
2385 * gtk_cell_area_cell_get_property:
2386 * @area: a #GtkCellArea
2387 * @renderer: a #GtkCellRenderer inside @area
2388 * @property_name: the name of the property to get
2389 * @value: a location to return the value
2391 * Gets the value of a cell property for @renderer in @area.
2396 gtk_cell_area_cell_get_property (GtkCellArea *area,
2397 GtkCellRenderer *renderer,
2398 const gchar *property_name,
2403 g_return_if_fail (GTK_IS_CELL_AREA (area));
2404 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2405 g_return_if_fail (property_name != NULL);
2406 g_return_if_fail (G_IS_VALUE (value));
2408 pspec = g_param_spec_pool_lookup (cell_property_pool, property_name,
2409 G_OBJECT_TYPE (area), TRUE);
2411 g_warning ("%s: cell area class `%s' has no cell property named `%s'",
2412 G_STRLOC, G_OBJECT_TYPE_NAME (area), property_name);
2413 else if (!(pspec->flags & G_PARAM_READABLE))
2414 g_warning ("%s: cell property `%s' of cell area class `%s' is not readable",
2415 G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
2418 GValue *prop_value, tmp_value = { 0, };
2420 /* auto-conversion of the callers value type
2422 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
2424 g_value_reset (value);
2427 else if (!g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
2429 g_warning ("can't retrieve cell property `%s' of type `%s' as value of type `%s'",
2431 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
2432 G_VALUE_TYPE_NAME (value));
2437 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2438 prop_value = &tmp_value;
2441 area_get_cell_property (area, renderer, pspec, prop_value);
2443 if (prop_value != value)
2445 g_value_transform (prop_value, value);
2446 g_value_unset (&tmp_value);
2451 /*************************************************************
2453 *************************************************************/
2456 * gtk_cell_area_is_activatable:
2457 * @area: a #GtkCellArea
2459 * Returns whether the area can do anything when activated,
2460 * after applying new attributes to @area.
2462 * Return value: whether @area can do anything when activated.
2467 gtk_cell_area_is_activatable (GtkCellArea *area)
2469 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2471 return GTK_CELL_AREA_GET_CLASS (area)->is_activatable (area);
2475 * gtk_cell_area_focus:
2476 * @area: a #GtkCellArea
2477 * @direction: the #GtkDirectionType
2479 * This should be called by the @area's owning layout widget
2480 * when focus is to be passed to @area, or moved within @area
2481 * for a given @direction and row data.
2483 * Implementing #GtkCellArea classes should implement this
2484 * method to receive and navigate focus in it's own way particular
2485 * to how it lays out cells.
2487 * Return value: %TRUE if focus remains inside @area as a result of this call.
2492 gtk_cell_area_focus (GtkCellArea *area,
2493 GtkDirectionType direction)
2495 GtkCellAreaClass *class;
2497 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2499 class = GTK_CELL_AREA_GET_CLASS (area);
2502 return class->focus (area, direction);
2504 g_warning ("GtkCellAreaClass::focus not implemented for `%s'",
2505 g_type_name (G_TYPE_FROM_INSTANCE (area)));
2511 * gtk_cell_area_activate:
2512 * @area: a #GtkCellArea
2513 * @context: the #GtkCellAreaContext in context with the current row data
2514 * @widget: the #GtkWidget that @area is rendering on
2515 * @cell_area: the size and location of @area relative to @widget's allocation
2516 * @flags: the #GtkCellRendererState flags for @area for this row of data.
2518 * Activates @area, usually by activating the currently focused
2519 * cell, however some subclasses which embed widgets in the area
2520 * can also activate a widget if it currently has the focus.
2522 * Return value: Whether @area was successfully activated.
2527 gtk_cell_area_activate (GtkCellArea *area,
2528 GtkCellAreaContext *context,
2530 const GdkRectangle *cell_area,
2531 GtkCellRendererState flags)
2533 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2535 return GTK_CELL_AREA_GET_CLASS (area)->activate (area, context, widget, cell_area, flags);
2540 * gtk_cell_area_set_focus_cell:
2541 * @area: a #GtkCellArea
2542 * @focus_cell: the #GtkCellRenderer to give focus to
2544 * This is generally called from #GtkCellArea implementations
2545 * either gtk_cell_area_grab_focus() or gtk_cell_area_update_focus()
2546 * is called. It's also up to the #GtkCellArea implementation
2547 * to update the focused cell when receiving events from
2548 * gtk_cell_area_event() appropriately.
2553 gtk_cell_area_set_focus_cell (GtkCellArea *area,
2554 GtkCellRenderer *renderer)
2556 GtkCellAreaPrivate *priv;
2558 g_return_if_fail (GTK_IS_CELL_AREA (area));
2559 g_return_if_fail (renderer == NULL || GTK_IS_CELL_RENDERER (renderer));
2563 if (priv->focus_cell != renderer)
2565 if (priv->focus_cell)
2566 g_object_unref (priv->focus_cell);
2568 priv->focus_cell = renderer;
2570 if (priv->focus_cell)
2571 g_object_ref (priv->focus_cell);
2573 g_object_notify (G_OBJECT (area), "focus-cell");
2576 /* Signal that the current focus renderer for this path changed
2577 * (it may be that the focus cell did not change, but the row
2578 * may have changed so we need to signal it) */
2579 g_signal_emit (area, cell_area_signals[SIGNAL_FOCUS_CHANGED], 0,
2580 priv->focus_cell, priv->current_path);
2585 * gtk_cell_area_get_focus_cell:
2586 * @area: a #GtkCellArea
2588 * Retrieves the currently focused cell for @area
2590 * Return value: the currently focused cell in @area.
2595 gtk_cell_area_get_focus_cell (GtkCellArea *area)
2597 GtkCellAreaPrivate *priv;
2599 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
2603 return priv->focus_cell;
2607 /*************************************************************
2608 * API: Focus Siblings *
2609 *************************************************************/
2612 * gtk_cell_area_add_focus_sibling:
2613 * @area: a #GtkCellArea
2614 * @renderer: the #GtkCellRenderer expected to have focus
2615 * @sibling: the #GtkCellRenderer to add to @renderer's focus area
2617 * Adds @sibling to @renderer's focusable area, focus will be drawn
2618 * around @renderer and all of it's siblings if @renderer can
2619 * focus for a given row.
2621 * Events handled by focus siblings can also activate the given
2622 * focusable @renderer.
2627 gtk_cell_area_add_focus_sibling (GtkCellArea *area,
2628 GtkCellRenderer *renderer,
2629 GtkCellRenderer *sibling)
2631 GtkCellAreaPrivate *priv;
2634 g_return_if_fail (GTK_IS_CELL_AREA (area));
2635 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2636 g_return_if_fail (GTK_IS_CELL_RENDERER (sibling));
2637 g_return_if_fail (renderer != sibling);
2638 g_return_if_fail (gtk_cell_area_has_renderer (area, renderer));
2639 g_return_if_fail (gtk_cell_area_has_renderer (area, sibling));
2640 g_return_if_fail (!gtk_cell_area_is_focus_sibling (area, renderer, sibling));
2642 /* XXX We should also check that sibling is not in any other renderer's sibling
2643 * list already, a renderer can be sibling of only one focusable renderer
2649 siblings = g_hash_table_lookup (priv->focus_siblings, renderer);
2652 siblings = g_list_append (siblings, sibling);
2655 siblings = g_list_append (siblings, sibling);
2656 g_hash_table_insert (priv->focus_siblings, renderer, siblings);
2661 * gtk_cell_area_remove_focus_sibling:
2662 * @area: a #GtkCellArea
2663 * @renderer: the #GtkCellRenderer expected to have focus
2664 * @sibling: the #GtkCellRenderer to remove from @renderer's focus area
2666 * Removes @sibling from @renderer's focus sibling list
2667 * (see gtk_cell_area_add_focus_sibling()).
2672 gtk_cell_area_remove_focus_sibling (GtkCellArea *area,
2673 GtkCellRenderer *renderer,
2674 GtkCellRenderer *sibling)
2676 GtkCellAreaPrivate *priv;
2679 g_return_if_fail (GTK_IS_CELL_AREA (area));
2680 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2681 g_return_if_fail (GTK_IS_CELL_RENDERER (sibling));
2682 g_return_if_fail (gtk_cell_area_is_focus_sibling (area, renderer, sibling));
2686 siblings = g_hash_table_lookup (priv->focus_siblings, renderer);
2688 siblings = g_list_copy (siblings);
2689 siblings = g_list_remove (siblings, sibling);
2692 g_hash_table_remove (priv->focus_siblings, renderer);
2694 g_hash_table_insert (priv->focus_siblings, renderer, siblings);
2698 * gtk_cell_area_is_focus_sibling:
2699 * @area: a #GtkCellArea
2700 * @renderer: the #GtkCellRenderer expected to have focus
2701 * @sibling: the #GtkCellRenderer to check against @renderer's sibling list
2703 * Returns %TRUE if @sibling is one of @renderer's focus siblings
2704 * (see gtk_cell_area_add_focus_sibling()).
2709 gtk_cell_area_is_focus_sibling (GtkCellArea *area,
2710 GtkCellRenderer *renderer,
2711 GtkCellRenderer *sibling)
2713 GtkCellAreaPrivate *priv;
2714 GList *siblings, *l;
2716 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2717 g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), FALSE);
2718 g_return_val_if_fail (GTK_IS_CELL_RENDERER (sibling), FALSE);
2722 siblings = g_hash_table_lookup (priv->focus_siblings, renderer);
2724 for (l = siblings; l; l = l->next)
2726 GtkCellRenderer *a_sibling = l->data;
2728 if (a_sibling == sibling)
2736 * gtk_cell_area_get_focus_siblings:
2737 * @area: a #GtkCellArea
2738 * @renderer: the #GtkCellRenderer expected to have focus
2740 * Gets the focus sibling cell renderers for @renderer.
2742 * Return value: (element-type GtkCellRenderer) (transfer none): A #GList of #GtkCellRenderers.
2743 * The returned list is internal and should not be freed.
2748 gtk_cell_area_get_focus_siblings (GtkCellArea *area,
2749 GtkCellRenderer *renderer)
2751 GtkCellAreaPrivate *priv;
2753 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
2754 g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), NULL);
2758 return g_hash_table_lookup (priv->focus_siblings, renderer);
2762 * gtk_cell_area_get_focus_from_sibling:
2763 * @area: a #GtkCellArea
2764 * @renderer: the #GtkCellRenderer
2766 * Gets the #GtkCellRenderer which is expected to be focusable
2767 * for which @renderer is, or may be a sibling.
2769 * This is handy for #GtkCellArea subclasses when handling events,
2770 * after determining the renderer at the event location it can
2771 * then chose to activate the focus cell for which the event
2772 * cell may have been a sibling.
2774 * Return value: the #GtkCellRenderer for which @renderer is a sibling, or %NULL.
2779 gtk_cell_area_get_focus_from_sibling (GtkCellArea *area,
2780 GtkCellRenderer *renderer)
2782 GtkCellRenderer *ret_renderer = NULL;
2783 GList *renderers, *l;
2785 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
2786 g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), NULL);
2788 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (area));
2790 for (l = renderers; l; l = l->next)
2792 GtkCellRenderer *a_renderer = l->data;
2795 for (list = gtk_cell_area_get_focus_siblings (area, a_renderer);
2796 list; list = list->next)
2798 GtkCellRenderer *sibling_renderer = list->data;
2800 if (sibling_renderer == renderer)
2802 ret_renderer = a_renderer;
2807 g_list_free (renderers);
2809 return ret_renderer;
2812 /*************************************************************
2813 * API: Cell Activation/Editing *
2814 *************************************************************/
2816 gtk_cell_area_add_editable (GtkCellArea *area,
2817 GtkCellRenderer *renderer,
2818 GtkCellEditable *editable,
2819 GdkRectangle *cell_area)
2821 g_signal_emit (area, cell_area_signals[SIGNAL_ADD_EDITABLE], 0,
2822 renderer, editable, cell_area, area->priv->current_path);
2826 gtk_cell_area_remove_editable (GtkCellArea *area,
2827 GtkCellRenderer *renderer,
2828 GtkCellEditable *editable)
2830 g_signal_emit (area, cell_area_signals[SIGNAL_REMOVE_EDITABLE], 0, renderer, editable);
2834 cell_area_remove_widget_cb (GtkCellEditable *editable,
2837 GtkCellAreaPrivate *priv = area->priv;
2839 g_assert (priv->edit_widget == editable);
2840 g_assert (priv->edited_cell != NULL);
2842 gtk_cell_area_remove_editable (area, priv->edited_cell, priv->edit_widget);
2844 /* Now that we're done with editing the widget and it can be removed,
2845 * remove our references to the widget and disconnect handlers */
2846 gtk_cell_area_set_edited_cell (area, NULL);
2847 gtk_cell_area_set_edit_widget (area, NULL);
2851 gtk_cell_area_set_edited_cell (GtkCellArea *area,
2852 GtkCellRenderer *renderer)
2854 GtkCellAreaPrivate *priv;
2856 g_return_if_fail (GTK_IS_CELL_AREA (area));
2857 g_return_if_fail (renderer == NULL || GTK_IS_CELL_RENDERER (renderer));
2861 if (priv->edited_cell != renderer)
2863 if (priv->edited_cell)
2864 g_object_unref (priv->edited_cell);
2866 priv->edited_cell = renderer;
2868 if (priv->edited_cell)
2869 g_object_ref (priv->edited_cell);
2871 g_object_notify (G_OBJECT (area), "edited-cell");
2876 gtk_cell_area_set_edit_widget (GtkCellArea *area,
2877 GtkCellEditable *editable)
2879 GtkCellAreaPrivate *priv;
2881 g_return_if_fail (GTK_IS_CELL_AREA (area));
2882 g_return_if_fail (editable == NULL || GTK_IS_CELL_EDITABLE (editable));
2886 if (priv->edit_widget != editable)
2888 if (priv->edit_widget)
2890 g_signal_handler_disconnect (priv->edit_widget, priv->remove_widget_id);
2892 g_object_unref (priv->edit_widget);
2895 priv->edit_widget = editable;
2897 if (priv->edit_widget)
2899 priv->remove_widget_id =
2900 g_signal_connect (priv->edit_widget, "remove-widget",
2901 G_CALLBACK (cell_area_remove_widget_cb), area);
2903 g_object_ref (priv->edit_widget);
2906 g_object_notify (G_OBJECT (area), "edit-widget");
2911 * gtk_cell_area_get_edited_cell:
2912 * @area: a #GtkCellArea
2914 * Gets the #GtkCellRenderer in @area that is currently
2917 * Return value: The currently edited #GtkCellRenderer
2922 gtk_cell_area_get_edited_cell (GtkCellArea *area)
2924 GtkCellAreaPrivate *priv;
2926 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
2930 return priv->edited_cell;
2934 * gtk_cell_area_get_edit_widget:
2935 * @area: a #GtkCellArea
2937 * Gets the #GtkCellEditable widget currently used
2938 * to edit the currently edited cell.
2940 * Return value: The currently active #GtkCellEditable widget
2945 gtk_cell_area_get_edit_widget (GtkCellArea *area)
2947 GtkCellAreaPrivate *priv;
2949 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
2953 return priv->edit_widget;
2957 * gtk_cell_area_activate_cell:
2958 * @area: a #GtkCellArea
2959 * @widget: the #GtkWidget that @area is rendering onto
2960 * @renderer: the #GtkCellRenderer in @area to activate
2961 * @event: the #GdkEvent for which cell activation should occur
2962 * @cell_area: the #GdkRectangle in @widget relative coordinates
2963 * of @renderer for the current row.
2964 * @flags: the #GtkCellRendererState for @renderer
2966 * This is used by #GtkCellArea subclasses when handling events
2967 * to activate cells, the base #GtkCellArea class activates cells
2968 * for keyboard events for free in it's own GtkCellArea->activate()
2971 * Return value: whether cell activation was successful
2976 gtk_cell_area_activate_cell (GtkCellArea *area,
2978 GtkCellRenderer *renderer,
2980 const GdkRectangle *cell_area,
2981 GtkCellRendererState flags)
2983 GtkCellRendererMode mode;
2984 GdkRectangle inner_area;
2985 GtkCellAreaPrivate *priv;
2987 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2988 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2989 g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), FALSE);
2990 g_return_val_if_fail (cell_area != NULL, FALSE);
2994 /* Remove margins from the background area to produce the cell area.
2996 gtk_cell_area_inner_cell_area (area, widget, cell_area, &inner_area);
2998 g_object_get (renderer, "mode", &mode, NULL);
3000 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
3002 if (gtk_cell_renderer_activate (renderer,
3010 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
3012 GtkCellEditable *editable_widget;
3015 gtk_cell_renderer_start_editing (renderer,
3022 if (editable_widget != NULL)
3024 g_return_val_if_fail (GTK_IS_CELL_EDITABLE (editable_widget), FALSE);
3026 gtk_cell_area_set_edited_cell (area, renderer);
3027 gtk_cell_area_set_edit_widget (area, editable_widget);
3029 /* Signal that editing started so that callers can get
3030 * a handle on the editable_widget */
3031 gtk_cell_area_add_editable (area, priv->focus_cell, editable_widget, &inner_area);
3033 /* If the signal was successfully handled start the editing */
3034 if (gtk_widget_get_parent (GTK_WIDGET (editable_widget)))
3036 gtk_cell_editable_start_editing (editable_widget, NULL);
3037 gtk_widget_grab_focus (GTK_WIDGET (editable_widget));
3041 /* Otherwise clear the editing state and fire a warning */
3042 gtk_cell_area_set_edited_cell (area, NULL);
3043 gtk_cell_area_set_edit_widget (area, NULL);
3045 g_warning ("GtkCellArea::add-editable fired in the dark, no cell editing was started.");
3056 * gtk_cell_area_stop_editing:
3057 * @area: a #GtkCellArea
3058 * @canceled: whether editing was canceled.
3060 * Explicitly stops the editing of the currently
3061 * edited cell (see gtk_cell_area_get_edited_cell()).
3063 * If @canceled is %TRUE, the cell renderer will emit
3064 * the ::editing-canceled signal.
3069 gtk_cell_area_stop_editing (GtkCellArea *area,
3072 GtkCellAreaPrivate *priv;
3074 g_return_if_fail (GTK_IS_CELL_AREA (area));
3078 if (priv->edited_cell)
3080 GtkCellEditable *edit_widget = g_object_ref (priv->edit_widget);
3081 GtkCellRenderer *edit_cell = g_object_ref (priv->edited_cell);
3083 /* Stop editing of the cell renderer */
3084 gtk_cell_renderer_stop_editing (priv->edited_cell, canceled);
3086 /* Remove any references to the editable widget */
3087 gtk_cell_area_set_edited_cell (area, NULL);
3088 gtk_cell_area_set_edit_widget (area, NULL);
3090 /* Send the remove-widget signal explicitly (this is done after setting
3091 * the edit cell/widget NULL to avoid feedback)
3093 gtk_cell_area_remove_editable (area, edit_cell, edit_widget);
3094 g_object_unref (edit_cell);
3095 g_object_unref (edit_widget);
3099 /*************************************************************
3100 * API: Convenience for area implementations *
3101 *************************************************************/
3104 * gtk_cell_area_inner_cell_area:
3105 * @area: a #GtkCellArea
3106 * @widget: the #GtkWidget that @area is rendering onto
3107 * @cell_area: the @widget relative coordinates where one of @area's cells
3109 * @inner_area: (out): the return location for the inner cell area
3111 * This is a convenience function for #GtkCellArea implementations
3112 * to get the inner area where a given #GtkCellRenderer will be
3113 * rendered. It removes any padding previously added by gtk_cell_area_request_renderer().
3118 gtk_cell_area_inner_cell_area (GtkCellArea *area,
3120 const GdkRectangle *cell_area,
3121 GdkRectangle *inner_area)
3123 gint focus_line_width;
3125 g_return_if_fail (GTK_IS_CELL_AREA (area));
3126 g_return_if_fail (GTK_IS_WIDGET (widget));
3127 g_return_if_fail (cell_area != NULL);
3128 g_return_if_fail (inner_area != NULL);
3130 gtk_widget_style_get (widget, "focus-line-width", &focus_line_width, NULL);
3132 *inner_area = *cell_area;
3134 inner_area->x += focus_line_width;
3135 inner_area->width -= focus_line_width * 2;
3136 inner_area->y += focus_line_width;
3137 inner_area->height -= focus_line_width * 2;
3141 * gtk_cell_area_request_renderer:
3142 * @area: a #GtkCellArea
3143 * @renderer: the #GtkCellRenderer to request size for
3144 * @orientation: the #GtkOrientation in which to request size
3145 * @widget: the #GtkWidget that @area is rendering onto
3146 * @for_size: the allocation contextual size to request for, or -1 if
3147 * the base request for the orientation is to be returned.
3148 * @minimum_size: (out) (allow-none): location to store the minimum size, or %NULL
3149 * @natural_size: (out) (allow-none): location to store the natural size, or %NULL
3151 * This is a convenience function for #GtkCellArea implementations
3152 * to request size for cell renderers. It's important to use this
3153 * function to request size and then use gtk_cell_area_inner_cell_area()
3154 * at render and event time since this function will add padding
3155 * around the cell for focus painting.
3160 gtk_cell_area_request_renderer (GtkCellArea *area,
3161 GtkCellRenderer *renderer,
3162 GtkOrientation orientation,
3168 GtkCellAreaPrivate *priv;
3169 gint focus_line_width;
3171 g_return_if_fail (GTK_IS_CELL_AREA (area));
3172 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
3173 g_return_if_fail (GTK_IS_WIDGET (widget));
3174 g_return_if_fail (minimum_size != NULL);
3175 g_return_if_fail (natural_size != NULL);
3179 gtk_widget_style_get (widget, "focus-line-width", &focus_line_width, NULL);
3181 focus_line_width *= 2;
3183 if (orientation == GTK_ORIENTATION_HORIZONTAL)
3186 gtk_cell_renderer_get_preferred_width (renderer, widget, minimum_size, natural_size);
3189 for_size = MAX (0, for_size - focus_line_width);
3191 gtk_cell_renderer_get_preferred_width_for_height (renderer, widget, for_size,
3192 minimum_size, natural_size);
3195 else /* GTK_ORIENTATION_VERTICAL */
3198 gtk_cell_renderer_get_preferred_height (renderer, widget, minimum_size, natural_size);
3201 for_size = MAX (0, for_size - focus_line_width);
3203 gtk_cell_renderer_get_preferred_height_for_width (renderer, widget, for_size,
3204 minimum_size, natural_size);
3208 *minimum_size += focus_line_width;
3209 *natural_size += focus_line_width;