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 their 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_render (GtkCellArea *area,
375 GtkCellAreaContext *context,
378 const GdkRectangle *background_area,
379 const GdkRectangle *cell_area,
380 GtkCellRendererState flags,
381 gboolean paint_focus);
382 static void gtk_cell_area_real_apply_attributes (GtkCellArea *area,
383 GtkTreeModel *tree_model,
385 gboolean is_expander,
386 gboolean is_expanded);
387 static void gtk_cell_area_real_get_preferred_height_for_width (GtkCellArea *area,
388 GtkCellAreaContext *context,
391 gint *minimum_height,
392 gint *natural_height);
393 static void gtk_cell_area_real_get_preferred_width_for_height (GtkCellArea *area,
394 GtkCellAreaContext *context,
398 gint *natural_width);
399 static gboolean gtk_cell_area_real_is_activatable (GtkCellArea *area);
400 static gboolean gtk_cell_area_real_activate (GtkCellArea *area,
401 GtkCellAreaContext *context,
403 const GdkRectangle *cell_area,
404 GtkCellRendererState flags);
406 /* GtkCellLayoutIface */
407 static void gtk_cell_area_cell_layout_init (GtkCellLayoutIface *iface);
408 static void gtk_cell_area_pack_default (GtkCellLayout *cell_layout,
409 GtkCellRenderer *renderer,
411 static void gtk_cell_area_clear (GtkCellLayout *cell_layout);
412 static void gtk_cell_area_add_attribute (GtkCellLayout *cell_layout,
413 GtkCellRenderer *renderer,
414 const gchar *attribute,
416 static void gtk_cell_area_set_cell_data_func (GtkCellLayout *cell_layout,
417 GtkCellRenderer *cell,
418 GtkCellLayoutDataFunc func,
420 GDestroyNotify destroy);
421 static void gtk_cell_area_clear_attributes (GtkCellLayout *cell_layout,
422 GtkCellRenderer *renderer);
423 static void gtk_cell_area_reorder (GtkCellLayout *cell_layout,
424 GtkCellRenderer *cell,
426 static GList *gtk_cell_area_get_cells (GtkCellLayout *cell_layout);
429 /* Used in foreach loop to check if a child renderer is present */
431 GtkCellRenderer *renderer;
432 gboolean has_renderer;
435 /* Used in foreach loop to get a cell's allocation */
437 GtkCellRenderer *renderer;
438 GdkRectangle allocation;
439 } RendererAllocationData;
441 /* Used in foreach loop to render cells */
446 GdkRectangle focus_rect;
447 GtkCellRendererState render_flags;
448 guint paint_focus : 1;
450 guint first_focus : 1;
453 /* Used in foreach loop to get a cell by position */
457 GtkCellRenderer *renderer;
458 GdkRectangle cell_area;
459 } CellByPositionData;
461 /* Attribute/Cell metadata */
463 const gchar *attribute;
470 GtkCellLayoutDataFunc func;
472 GDestroyNotify destroy;
475 static CellInfo *cell_info_new (GtkCellLayoutDataFunc func,
477 GDestroyNotify destroy);
478 static void cell_info_free (CellInfo *info);
479 static CellAttribute *cell_attribute_new (GtkCellRenderer *renderer,
480 const gchar *attribute,
482 static void cell_attribute_free (CellAttribute *attribute);
483 static gint cell_attribute_find (CellAttribute *cell_attribute,
484 const gchar *attribute);
486 /* Internal functions/signal emissions */
487 static void gtk_cell_area_add_editable (GtkCellArea *area,
488 GtkCellRenderer *renderer,
489 GtkCellEditable *editable,
490 const GdkRectangle *cell_area);
491 static void gtk_cell_area_remove_editable (GtkCellArea *area,
492 GtkCellRenderer *renderer,
493 GtkCellEditable *editable);
494 static void gtk_cell_area_set_edit_widget (GtkCellArea *area,
495 GtkCellEditable *editable);
496 static void gtk_cell_area_set_edited_cell (GtkCellArea *area,
497 GtkCellRenderer *renderer);
500 /* Struct to pass data along while looping over
501 * cell renderers to apply attributes
507 gboolean is_expander;
508 gboolean is_expanded;
511 struct _GtkCellAreaPrivate
513 /* The GtkCellArea bookkeeps any connected
514 * attributes in this hash table.
516 GHashTable *cell_info;
518 /* Current path is saved as a side-effect
519 * of gtk_cell_area_apply_attributes() */
522 /* Current cell being edited and editable widget used */
523 GtkCellEditable *edit_widget;
524 GtkCellRenderer *edited_cell;
526 /* Signal connections to the editable widget */
527 gulong remove_widget_id;
529 /* Currently focused cell */
530 GtkCellRenderer *focus_cell;
532 /* Tracking which cells are focus siblings of focusable cells */
533 GHashTable *focus_siblings;
535 /* Detail string to pass to gtk_paint_*() functions */
547 SIGNAL_APPLY_ATTRIBUTES,
549 SIGNAL_REMOVE_EDITABLE,
550 SIGNAL_FOCUS_CHANGED,
554 /* Keep the paramspec pool internal, no need to deliver notifications
555 * on cells. at least no percieved need for now */
556 static GParamSpecPool *cell_property_pool = NULL;
557 static guint cell_area_signals[LAST_SIGNAL] = { 0 };
559 #define PARAM_SPEC_PARAM_ID(pspec) ((pspec)->param_id)
560 #define PARAM_SPEC_SET_PARAM_ID(pspec, id) ((pspec)->param_id = (id))
563 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GtkCellArea, gtk_cell_area, G_TYPE_INITIALLY_UNOWNED,
564 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
565 gtk_cell_area_cell_layout_init));
568 gtk_cell_area_init (GtkCellArea *area)
570 GtkCellAreaPrivate *priv;
572 area->priv = G_TYPE_INSTANCE_GET_PRIVATE (area,
577 priv->cell_info = g_hash_table_new_full (g_direct_hash,
580 (GDestroyNotify)cell_info_free);
582 priv->focus_siblings = g_hash_table_new_full (g_direct_hash,
585 (GDestroyNotify)g_list_free);
587 priv->focus_cell = NULL;
588 priv->edited_cell = NULL;
589 priv->edit_widget = NULL;
591 priv->remove_widget_id = 0;
595 gtk_cell_area_class_init (GtkCellAreaClass *class)
597 GObjectClass *object_class = G_OBJECT_CLASS (class);
600 object_class->dispose = gtk_cell_area_dispose;
601 object_class->finalize = gtk_cell_area_finalize;
602 object_class->get_property = gtk_cell_area_get_property;
603 object_class->set_property = gtk_cell_area_set_property;
607 class->remove = NULL;
608 class->foreach = NULL;
609 class->event = gtk_cell_area_real_event;
610 class->render = gtk_cell_area_real_render;
611 class->apply_attributes = gtk_cell_area_real_apply_attributes;
614 class->create_context = NULL;
615 class->get_request_mode = NULL;
616 class->get_preferred_width = NULL;
617 class->get_preferred_height = NULL;
618 class->get_preferred_height_for_width = gtk_cell_area_real_get_preferred_height_for_width;
619 class->get_preferred_width_for_height = gtk_cell_area_real_get_preferred_width_for_height;
622 class->is_activatable = gtk_cell_area_real_is_activatable;
623 class->activate = gtk_cell_area_real_activate;
628 * GtkCellArea::apply-attributes:
629 * @area: the #GtkCellArea to apply the attributes to
630 * @model: the #GtkTreeModel to apply the attributes from
631 * @iter: the #GtkTreeIter indicating which row to apply the attributes of
632 * @is_expander: whether the view shows children for this row
633 * @is_expanded: whether the view is currently showing the children of this row
635 * This signal is emitted whenever applying attributes to @area from @model
639 cell_area_signals[SIGNAL_APPLY_ATTRIBUTES] =
640 g_signal_new (I_("apply-attributes"),
641 G_OBJECT_CLASS_TYPE (object_class),
643 G_STRUCT_OFFSET (GtkCellAreaClass, apply_attributes),
645 _gtk_marshal_VOID__OBJECT_BOXED_BOOLEAN_BOOLEAN,
653 * GtkCellArea::add-editable:
654 * @area: the #GtkCellArea where editing started
655 * @renderer: the #GtkCellRenderer that started the edited
656 * @editable: the #GtkCellEditable widget to add
657 * @cell_area: the #GtkWidget relative #GdkRectangle coordinates
658 * where @editable should be added
659 * @path: the #GtkTreePath string this edit was initiated for
661 * Indicates that editing has started on @renderer and that @editable
662 * should be added to the owning cell layouting widget at @cell_area.
666 cell_area_signals[SIGNAL_ADD_EDITABLE] =
667 g_signal_new (I_("add-editable"),
668 G_OBJECT_CLASS_TYPE (object_class),
670 0, /* No class closure here */
672 _gtk_marshal_VOID__OBJECT_OBJECT_BOXED_STRING,
674 GTK_TYPE_CELL_RENDERER,
675 GTK_TYPE_CELL_EDITABLE,
681 * GtkCellArea::remove-editable:
682 * @area: the #GtkCellArea where editing finished
683 * @renderer: the #GtkCellRenderer that finished editeding
684 * @editable: the #GtkCellEditable widget to remove
686 * Indicates that editing finished on @renderer and that @editable
687 * should be removed from the owning cell layouting widget.
691 cell_area_signals[SIGNAL_REMOVE_EDITABLE] =
692 g_signal_new (I_("remove-editable"),
693 G_OBJECT_CLASS_TYPE (object_class),
695 0, /* No class closure here */
697 _gtk_marshal_VOID__OBJECT_OBJECT,
699 GTK_TYPE_CELL_RENDERER,
700 GTK_TYPE_CELL_EDITABLE);
703 * GtkCellArea::focus-changed:
704 * @area: the #GtkCellArea where focus changed
705 * @renderer: the #GtkCellRenderer that has focus
706 * @path: the current #GtkTreePath string set for @area
708 * Indicates that focus changed on this @area. This signal
709 * is emitted either as a result of focus handling or event
712 * It's possible that the signal is emitted even if the
713 * currently focused renderer did not change, this is
714 * because focus may change to the same renderer in the
715 * same cell area for a different row of data.
719 cell_area_signals[SIGNAL_FOCUS_CHANGED] =
720 g_signal_new (I_("focus-changed"),
721 G_OBJECT_CLASS_TYPE (object_class),
723 0, /* No class closure here */
725 _gtk_marshal_VOID__OBJECT_STRING,
727 GTK_TYPE_CELL_RENDERER,
732 * GtkCellArea:focus-cell:
734 * The cell in the area that currently has focus
738 g_object_class_install_property (object_class,
743 P_("The cell which currently has focus"),
744 GTK_TYPE_CELL_RENDERER,
745 GTK_PARAM_READWRITE));
748 * GtkCellArea:edited-cell:
750 * The cell in the area that is currently edited
752 * This property is read-only and only changes as
753 * a result of a call gtk_cell_area_activate_cell().
757 g_object_class_install_property (object_class,
762 P_("The cell which is currently being edited"),
763 GTK_TYPE_CELL_RENDERER,
767 * GtkCellArea:edit-widget:
769 * The widget currently editing the edited cell
771 * This property is read-only and only changes as
772 * a result of a call gtk_cell_area_activate_cell().
776 g_object_class_install_property (object_class,
781 P_("The widget currently editing the edited cell"),
782 GTK_TYPE_CELL_RENDERER,
785 /* Pool for Cell Properties */
786 if (!cell_property_pool)
787 cell_property_pool = g_param_spec_pool_new (FALSE);
789 g_type_class_add_private (object_class, sizeof (GtkCellAreaPrivate));
792 /*************************************************************
794 *************************************************************/
796 cell_info_new (GtkCellLayoutDataFunc func,
798 GDestroyNotify destroy)
800 CellInfo *info = g_slice_new0 (CellInfo);
804 info->destroy = destroy;
810 cell_info_free (CellInfo *info)
813 info->destroy (info->data);
815 g_slist_foreach (info->attributes, (GFunc)cell_attribute_free, NULL);
816 g_slist_free (info->attributes);
818 g_slice_free (CellInfo, info);
821 static CellAttribute *
822 cell_attribute_new (GtkCellRenderer *renderer,
823 const gchar *attribute,
828 /* Check if the attribute really exists and point to
829 * the property string installed on the cell renderer
830 * class (dont dup the string)
832 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (renderer), attribute);
836 CellAttribute *cell_attribute = g_slice_new (CellAttribute);
838 cell_attribute->attribute = pspec->name;
839 cell_attribute->column = column;
841 return cell_attribute;
848 cell_attribute_free (CellAttribute *attribute)
850 g_slice_free (CellAttribute, attribute);
853 /* GCompareFunc for g_slist_find_custom() */
855 cell_attribute_find (CellAttribute *cell_attribute,
856 const gchar *attribute)
858 return g_strcmp0 (cell_attribute->attribute, attribute);
861 /*************************************************************
863 *************************************************************/
865 gtk_cell_area_finalize (GObject *object)
867 GtkCellArea *area = GTK_CELL_AREA (object);
868 GtkCellAreaPrivate *priv = area->priv;
870 /* All cell renderers should already be removed at this point,
871 * just kill our (empty) hash tables here.
873 g_hash_table_destroy (priv->cell_info);
874 g_hash_table_destroy (priv->focus_siblings);
876 g_free (priv->current_path);
878 G_OBJECT_CLASS (gtk_cell_area_parent_class)->finalize (object);
883 gtk_cell_area_dispose (GObject *object)
885 /* This removes every cell renderer that may be added to the GtkCellArea,
886 * subclasses should be breaking references to the GtkCellRenderers
889 gtk_cell_layout_clear (GTK_CELL_LAYOUT (object));
891 /* Remove any ref to a focused/edited cell */
892 gtk_cell_area_set_focus_cell (GTK_CELL_AREA (object), NULL);
893 gtk_cell_area_set_edited_cell (GTK_CELL_AREA (object), NULL);
894 gtk_cell_area_set_edit_widget (GTK_CELL_AREA (object), NULL);
896 G_OBJECT_CLASS (gtk_cell_area_parent_class)->dispose (object);
900 gtk_cell_area_set_property (GObject *object,
905 GtkCellArea *area = GTK_CELL_AREA (object);
909 case PROP_FOCUS_CELL:
910 gtk_cell_area_set_focus_cell (area, (GtkCellRenderer *)g_value_get_object (value));
913 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
919 gtk_cell_area_get_property (GObject *object,
924 GtkCellArea *area = GTK_CELL_AREA (object);
925 GtkCellAreaPrivate *priv = area->priv;
929 case PROP_FOCUS_CELL:
930 g_value_set_object (value, priv->focus_cell);
932 case PROP_EDITED_CELL:
933 g_value_set_object (value, priv->edited_cell);
935 case PROP_EDIT_WIDGET:
936 g_value_set_object (value, priv->edit_widget);
939 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
944 /*************************************************************
946 *************************************************************/
948 gtk_cell_area_real_event (GtkCellArea *area,
949 GtkCellAreaContext *context,
952 const GdkRectangle *cell_area,
953 GtkCellRendererState flags)
955 GtkCellAreaPrivate *priv = area->priv;
956 gboolean retval = FALSE;
958 if (event->type == GDK_KEY_PRESS && (flags & GTK_CELL_RENDERER_FOCUSED) != 0)
960 GdkEventKey *key_event = (GdkEventKey *)event;
962 /* Cancel any edits in progress */
963 if (priv->edited_cell && (key_event->keyval == GDK_KEY_Escape))
965 gtk_cell_area_stop_editing (area, TRUE);
969 else if (event->type == GDK_BUTTON_PRESS)
971 GdkEventButton *button_event = (GdkEventButton *)event;
973 if (button_event->button == 1)
975 GtkCellRenderer *renderer = NULL;
976 GtkCellRenderer *focus_renderer;
977 GdkRectangle alloc_area;
978 gint event_x, event_y;
980 /* We may need some semantics to tell us the offset of the event
981 * window we are handling events for (i.e. GtkTreeView has a bin_window) */
982 event_x = button_event->x;
983 event_y = button_event->y;
985 /* Dont try to search for an event coordinate that is not in the area, that will
986 * trigger a runtime warning.
988 if (event_x >= cell_area->x && event_x <= cell_area->x + cell_area->width &&
989 event_y >= cell_area->y && event_y <= cell_area->y + cell_area->height)
991 gtk_cell_area_get_cell_at_position (area, context, widget,
992 cell_area, event_x, event_y,
997 focus_renderer = gtk_cell_area_get_focus_from_sibling (area, renderer);
999 focus_renderer = renderer;
1001 /* If we're already editing, cancel it and set focus */
1002 if (gtk_cell_area_get_edited_cell (area))
1004 /* XXX Was it really canceled in this case ? */
1005 gtk_cell_area_stop_editing (area, TRUE);
1006 gtk_cell_area_set_focus_cell (area, focus_renderer);
1011 /* If we are activating via a focus sibling,
1012 * we need to fetch the right cell area for the real event renderer */
1013 if (focus_renderer != renderer)
1014 gtk_cell_area_get_cell_allocation (area, context, widget, focus_renderer,
1015 cell_area, &alloc_area);
1017 gtk_cell_area_set_focus_cell (area, focus_renderer);
1018 retval = gtk_cell_area_activate_cell (area, widget, focus_renderer,
1019 event, &alloc_area, flags);
1029 render_cell (GtkCellRenderer *renderer,
1030 const GdkRectangle *cell_area,
1031 const GdkRectangle *cell_background,
1032 CellRenderData *data)
1034 GtkCellRenderer *focus_cell;
1035 GtkCellRendererState flags;
1036 GdkRectangle inner_area;
1038 focus_cell = gtk_cell_area_get_focus_cell (data->area);
1039 flags = data->render_flags;
1041 gtk_cell_area_inner_cell_area (data->area, data->widget, cell_area, &inner_area);
1043 if ((flags & GTK_CELL_RENDERER_FOCUSED) &&
1046 (renderer == focus_cell ||
1047 gtk_cell_area_is_focus_sibling (data->area, focus_cell, renderer)))))
1049 GdkRectangle cell_focus;
1051 gtk_cell_renderer_get_aligned_area (renderer, data->widget, flags, &inner_area, &cell_focus);
1053 if (data->first_focus)
1055 data->first_focus = FALSE;
1056 data->focus_rect = cell_focus;
1060 gdk_rectangle_union (&data->focus_rect, &cell_focus, &data->focus_rect);
1064 flags &= ~GTK_CELL_RENDERER_FOCUSED;
1066 gtk_cell_renderer_render (renderer, data->cr, data->widget,
1067 cell_background, &inner_area, flags);
1073 gtk_cell_area_real_render (GtkCellArea *area,
1074 GtkCellAreaContext *context,
1077 const GdkRectangle *background_area,
1078 const GdkRectangle *cell_area,
1079 GtkCellRendererState flags,
1080 gboolean paint_focus)
1082 CellRenderData render_data =
1093 /* Make sure we dont paint a focus rectangle while there
1094 * is an editable widget in play
1096 if (gtk_cell_area_get_edited_cell (area))
1097 render_data.paint_focus = FALSE;
1099 /* If no cell can activate but the caller wants focus painted,
1100 * then we paint focus around all cells */
1101 if ((flags & GTK_CELL_RENDERER_FOCUSED) != 0 && paint_focus &&
1102 !gtk_cell_area_is_activatable (area))
1103 render_data.focus_all = TRUE;
1105 gtk_cell_area_foreach_alloc (area, context, widget, cell_area, background_area,
1106 (GtkCellAllocCallback)render_cell, &render_data);
1108 if (render_data.paint_focus &&
1109 render_data.focus_rect.width != 0 &&
1110 render_data.focus_rect.height != 0)
1112 GtkStateType renderer_state =
1113 flags & GTK_CELL_RENDERER_SELECTED ? GTK_STATE_SELECTED :
1114 (flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT :
1115 (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL));
1117 gtk_paint_focus (gtk_widget_get_style (widget), cr,
1118 renderer_state, widget,
1119 gtk_cell_area_get_style_detail (area),
1120 render_data.focus_rect.x, render_data.focus_rect.y,
1121 render_data.focus_rect.width, render_data.focus_rect.height);
1126 apply_cell_attributes (GtkCellRenderer *renderer,
1128 AttributeData *data)
1130 CellAttribute *attribute;
1132 GValue value = { 0, };
1133 gboolean is_expander;
1134 gboolean is_expanded;
1136 g_object_freeze_notify (G_OBJECT (renderer));
1138 /* Whether a row expands or is presently expanded can only be
1139 * provided by the view (as these states can vary across views
1140 * accessing the same model).
1142 g_object_get (renderer, "is-expander", &is_expander, NULL);
1143 if (is_expander != data->is_expander)
1144 g_object_set (renderer, "is-expander", data->is_expander, NULL);
1146 g_object_get (renderer, "is-expanded", &is_expanded, NULL);
1147 if (is_expanded != data->is_expanded)
1148 g_object_set (renderer, "is-expanded", data->is_expanded, NULL);
1150 /* Apply the attributes directly to the renderer */
1151 for (list = info->attributes; list; list = list->next)
1153 attribute = list->data;
1155 gtk_tree_model_get_value (data->model, data->iter, attribute->column, &value);
1156 g_object_set_property (G_OBJECT (renderer), attribute->attribute, &value);
1157 g_value_unset (&value);
1160 /* Call any GtkCellLayoutDataFunc that may have been set by the user
1163 info->func (GTK_CELL_LAYOUT (data->area), renderer,
1164 data->model, data->iter, info->data);
1166 g_object_thaw_notify (G_OBJECT (renderer));
1170 gtk_cell_area_real_apply_attributes (GtkCellArea *area,
1171 GtkTreeModel *tree_model,
1173 gboolean is_expander,
1174 gboolean is_expanded)
1177 GtkCellAreaPrivate *priv;
1183 /* Feed in data needed to apply to every renderer */
1185 data.model = tree_model;
1187 data.is_expander = is_expander;
1188 data.is_expanded = is_expanded;
1190 /* Go over any cells that have attributes or custom GtkCellLayoutDataFuncs and
1191 * apply the data from the treemodel */
1192 g_hash_table_foreach (priv->cell_info, (GHFunc)apply_cell_attributes, &data);
1194 /* Update the currently applied path */
1195 g_free (priv->current_path);
1196 path = gtk_tree_model_get_path (tree_model, iter);
1197 priv->current_path = gtk_tree_path_to_string (path);
1198 gtk_tree_path_free (path);
1202 gtk_cell_area_real_get_preferred_height_for_width (GtkCellArea *area,
1203 GtkCellAreaContext *context,
1206 gint *minimum_height,
1207 gint *natural_height)
1209 /* If the area doesnt do height-for-width, fallback on base preferred height */
1210 GTK_CELL_AREA_GET_CLASS (area)->get_preferred_width (area, context, widget, minimum_height, natural_height);
1214 gtk_cell_area_real_get_preferred_width_for_height (GtkCellArea *area,
1215 GtkCellAreaContext *context,
1218 gint *minimum_width,
1219 gint *natural_width)
1221 /* If the area doesnt do width-for-height, fallback on base preferred width */
1222 GTK_CELL_AREA_GET_CLASS (area)->get_preferred_width (area, context, widget, minimum_width, natural_width);
1226 get_is_activatable (GtkCellRenderer *renderer,
1227 gboolean *activatable)
1230 if (gtk_cell_renderer_is_activatable (renderer))
1231 *activatable = TRUE;
1233 return *activatable;
1237 gtk_cell_area_real_is_activatable (GtkCellArea *area)
1239 gboolean activatable = FALSE;
1241 /* Checks if any renderer can focus for the currently applied
1244 * Subclasses can override this in the case that they are also
1245 * rendering widgets as well as renderers.
1247 gtk_cell_area_foreach (area, (GtkCellCallback)get_is_activatable, &activatable);
1253 gtk_cell_area_real_activate (GtkCellArea *area,
1254 GtkCellAreaContext *context,
1256 const GdkRectangle *cell_area,
1257 GtkCellRendererState flags)
1259 GtkCellAreaPrivate *priv = area->priv;
1260 GdkRectangle background_area;
1261 GtkCellRenderer *activate_cell = NULL;
1263 if (priv->focus_cell)
1264 activate_cell = priv->focus_cell;
1269 /* GtkTreeView sometimes wants to activate a cell when no
1270 * cells are in focus.
1272 cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (area));
1273 for (l = cells; l && !activate_cell; l = l->next)
1275 GtkCellRenderer *renderer = l->data;
1277 if (gtk_cell_renderer_is_activatable (renderer))
1278 activate_cell = renderer;
1280 g_list_free (cells);
1286 /* Get the allocation of the focused cell.
1288 gtk_cell_area_get_cell_allocation (area, context, widget, activate_cell,
1289 cell_area, &background_area);
1291 /* Activate or Edit the cell
1293 * Currently just not sending an event, renderers afaics dont use
1294 * the event argument anyway, worst case is we can synthesize one.
1296 if (gtk_cell_area_activate_cell (area, widget, activate_cell, NULL,
1297 &background_area, flags))
1304 /*************************************************************
1305 * GtkCellLayoutIface *
1306 *************************************************************/
1308 gtk_cell_area_cell_layout_init (GtkCellLayoutIface *iface)
1310 iface->pack_start = gtk_cell_area_pack_default;
1311 iface->pack_end = gtk_cell_area_pack_default;
1312 iface->clear = gtk_cell_area_clear;
1313 iface->add_attribute = gtk_cell_area_add_attribute;
1314 iface->set_cell_data_func = gtk_cell_area_set_cell_data_func;
1315 iface->clear_attributes = gtk_cell_area_clear_attributes;
1316 iface->reorder = gtk_cell_area_reorder;
1317 iface->get_cells = gtk_cell_area_get_cells;
1321 gtk_cell_area_pack_default (GtkCellLayout *cell_layout,
1322 GtkCellRenderer *renderer,
1325 gtk_cell_area_add (GTK_CELL_AREA (cell_layout), renderer);
1329 gtk_cell_area_clear (GtkCellLayout *cell_layout)
1331 GtkCellArea *area = GTK_CELL_AREA (cell_layout);
1333 gtk_cell_layout_get_cells (cell_layout);
1335 for (l = cells; l; l = l->next)
1337 GtkCellRenderer *renderer = l->data;
1338 gtk_cell_area_remove (area, renderer);
1341 g_list_free (cells);
1345 gtk_cell_area_add_attribute (GtkCellLayout *cell_layout,
1346 GtkCellRenderer *renderer,
1347 const gchar *attribute,
1350 gtk_cell_area_attribute_connect (GTK_CELL_AREA (cell_layout),
1351 renderer, attribute, column);
1355 gtk_cell_area_set_cell_data_func (GtkCellLayout *cell_layout,
1356 GtkCellRenderer *renderer,
1357 GtkCellLayoutDataFunc func,
1359 GDestroyNotify destroy)
1361 GtkCellArea *area = GTK_CELL_AREA (cell_layout);
1362 GtkCellAreaPrivate *priv = area->priv;
1365 info = g_hash_table_lookup (priv->cell_info, renderer);
1369 if (info->destroy && info->data)
1370 info->destroy (info->data);
1375 info->data = func_data;
1376 info->destroy = destroy;
1382 info->destroy = NULL;
1387 info = cell_info_new (func, func_data, destroy);
1389 g_hash_table_insert (priv->cell_info, renderer, info);
1394 gtk_cell_area_clear_attributes (GtkCellLayout *cell_layout,
1395 GtkCellRenderer *renderer)
1397 GtkCellArea *area = GTK_CELL_AREA (cell_layout);
1398 GtkCellAreaPrivate *priv = area->priv;
1401 info = g_hash_table_lookup (priv->cell_info, renderer);
1405 g_slist_foreach (info->attributes, (GFunc)cell_attribute_free, NULL);
1406 g_slist_free (info->attributes);
1408 info->attributes = NULL;
1413 gtk_cell_area_reorder (GtkCellLayout *cell_layout,
1414 GtkCellRenderer *cell,
1417 g_warning ("GtkCellLayout::reorder not implemented for `%s'",
1418 g_type_name (G_TYPE_FROM_INSTANCE (cell_layout)));
1422 accum_cells (GtkCellRenderer *renderer,
1425 *accum = g_list_prepend (*accum, renderer);
1431 gtk_cell_area_get_cells (GtkCellLayout *cell_layout)
1433 GList *cells = NULL;
1435 gtk_cell_area_foreach (GTK_CELL_AREA (cell_layout),
1436 (GtkCellCallback)accum_cells,
1439 return g_list_reverse (cells);
1443 /*************************************************************
1445 *************************************************************/
1448 * gtk_cell_area_add:
1449 * @area: a #GtkCellArea
1450 * @renderer: the #GtkCellRenderer to add to @area
1452 * Adds @renderer to @area with the default child cell properties.
1457 gtk_cell_area_add (GtkCellArea *area,
1458 GtkCellRenderer *renderer)
1460 GtkCellAreaClass *class;
1462 g_return_if_fail (GTK_IS_CELL_AREA (area));
1463 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1465 class = GTK_CELL_AREA_GET_CLASS (area);
1468 class->add (area, renderer);
1470 g_warning ("GtkCellAreaClass::add not implemented for `%s'",
1471 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1475 * gtk_cell_area_remove:
1476 * @area: a #GtkCellArea
1477 * @renderer: the #GtkCellRenderer to remove from @area
1479 * Removes @renderer from @area.
1484 gtk_cell_area_remove (GtkCellArea *area,
1485 GtkCellRenderer *renderer)
1487 GtkCellAreaClass *class;
1488 GtkCellAreaPrivate *priv;
1489 GList *renderers, *l;
1491 g_return_if_fail (GTK_IS_CELL_AREA (area));
1492 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1494 class = GTK_CELL_AREA_GET_CLASS (area);
1497 /* Remove any custom attributes and custom cell data func here first */
1498 g_hash_table_remove (priv->cell_info, renderer);
1500 /* Remove focus siblings of this renderer */
1501 g_hash_table_remove (priv->focus_siblings, renderer);
1503 /* Remove this renderer from any focus renderer's sibling list */
1504 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (area));
1506 for (l = renderers; l; l = l->next)
1508 GtkCellRenderer *focus_renderer = l->data;
1510 if (gtk_cell_area_is_focus_sibling (area, focus_renderer, renderer))
1512 gtk_cell_area_remove_focus_sibling (area, focus_renderer, renderer);
1517 g_list_free (renderers);
1520 class->remove (area, renderer);
1522 g_warning ("GtkCellAreaClass::remove not implemented for `%s'",
1523 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1527 get_has_renderer (GtkCellRenderer *renderer,
1528 HasRendererCheck *check)
1530 if (renderer == check->renderer)
1531 check->has_renderer = TRUE;
1533 return check->has_renderer;
1537 * gtk_cell_area_has_renderer:
1538 * @area: a #GtkCellArea
1539 * @renderer: the #GtkCellRenderer to check
1541 * Checks if @area contains @renderer.
1543 * Return value: %TRUE if @renderer is in the @area.
1548 gtk_cell_area_has_renderer (GtkCellArea *area,
1549 GtkCellRenderer *renderer)
1551 HasRendererCheck check = { renderer, FALSE };
1553 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
1554 g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), FALSE);
1556 gtk_cell_area_foreach (area, (GtkCellCallback)get_has_renderer, &check);
1558 return check.has_renderer;
1562 * gtk_cell_area_foreach:
1563 * @area: a #GtkCellArea
1564 * @callback: the #GtkCellCallback to call
1565 * @callback_data: user provided data pointer
1567 * Calls @callback for every #GtkCellRenderer in @area.
1572 gtk_cell_area_foreach (GtkCellArea *area,
1573 GtkCellCallback callback,
1574 gpointer callback_data)
1576 GtkCellAreaClass *class;
1578 g_return_if_fail (GTK_IS_CELL_AREA (area));
1579 g_return_if_fail (callback != NULL);
1581 class = GTK_CELL_AREA_GET_CLASS (area);
1584 class->foreach (area, callback, callback_data);
1586 g_warning ("GtkCellAreaClass::foreach not implemented for `%s'",
1587 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1591 * gtk_cell_area_foreach_alloc:
1592 * @area: a #GtkCellArea
1593 * @context: the #GtkCellAreaContext for this row of data.
1594 * @widget: the #GtkWidget that @area is rendering to
1595 * @cell_area: the @widget relative coordinates and size for @area
1596 * @background_area: the @widget relative coordinates of the background area
1597 * @callback: the #GtkCellAllocCallback to call
1598 * @callback_data: user provided data pointer
1600 * Calls @callback for every #GtkCellRenderer in @area with the
1601 * allocated rectangle inside @cell_area.
1606 gtk_cell_area_foreach_alloc (GtkCellArea *area,
1607 GtkCellAreaContext *context,
1609 const GdkRectangle *cell_area,
1610 const GdkRectangle *background_area,
1611 GtkCellAllocCallback callback,
1612 gpointer callback_data)
1614 GtkCellAreaClass *class;
1616 g_return_if_fail (GTK_IS_CELL_AREA (area));
1617 g_return_if_fail (GTK_IS_CELL_AREA_CONTEXT (context));
1618 g_return_if_fail (GTK_IS_WIDGET (widget));
1619 g_return_if_fail (cell_area != NULL);
1620 g_return_if_fail (callback != NULL);
1622 class = GTK_CELL_AREA_GET_CLASS (area);
1624 if (class->foreach_alloc)
1625 class->foreach_alloc (area, context, widget, cell_area, background_area, callback, callback_data);
1627 g_warning ("GtkCellAreaClass::foreach_alloc not implemented for `%s'",
1628 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1632 * gtk_cell_area_event:
1633 * @area: a #GtkCellArea
1634 * @context: the #GtkCellAreaContext for this row of data.
1635 * @widget: the #GtkWidget that @area is rendering to
1636 * @event: the #GdkEvent to handle
1637 * @cell_area: the @widget relative coordinates for @area
1638 * @flags: the #GtkCellRendererState for @area in this row.
1640 * Delegates event handling to a #GtkCellArea.
1642 * Return value: %TRUE if the event was handled by @area.
1647 gtk_cell_area_event (GtkCellArea *area,
1648 GtkCellAreaContext *context,
1651 const GdkRectangle *cell_area,
1652 GtkCellRendererState flags)
1654 GtkCellAreaClass *class;
1656 g_return_val_if_fail (GTK_IS_CELL_AREA (area), 0);
1657 g_return_val_if_fail (GTK_IS_CELL_AREA_CONTEXT (context), 0);
1658 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
1659 g_return_val_if_fail (event != NULL, 0);
1660 g_return_val_if_fail (cell_area != NULL, 0);
1662 class = GTK_CELL_AREA_GET_CLASS (area);
1665 return class->event (area, context, widget, event, cell_area, flags);
1667 g_warning ("GtkCellAreaClass::event not implemented for `%s'",
1668 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1673 * gtk_cell_area_render:
1674 * @area: a #GtkCellArea
1675 * @context: the #GtkCellAreaContext for this row of data.
1676 * @widget: the #GtkWidget that @area is rendering to
1677 * @cr: the #cairo_t to render with
1678 * @background_area: the @widget relative coordinates for @area's background
1679 * @cell_area: the @widget relative coordinates for @area
1680 * @flags: the #GtkCellRendererState for @area in this row.
1681 * @paint_focus: whether @area should paint focus on focused cells for focused rows or not.
1683 * Renders @area's cells according to @area's layout onto @widget at
1684 * the given coordinates.
1689 gtk_cell_area_render (GtkCellArea *area,
1690 GtkCellAreaContext *context,
1693 const GdkRectangle *background_area,
1694 const GdkRectangle *cell_area,
1695 GtkCellRendererState flags,
1696 gboolean paint_focus)
1698 GtkCellAreaClass *class;
1700 g_return_if_fail (GTK_IS_CELL_AREA (area));
1701 g_return_if_fail (GTK_IS_CELL_AREA_CONTEXT (context));
1702 g_return_if_fail (GTK_IS_WIDGET (widget));
1703 g_return_if_fail (cr != NULL);
1704 g_return_if_fail (background_area != NULL);
1705 g_return_if_fail (cell_area != NULL);
1707 class = GTK_CELL_AREA_GET_CLASS (area);
1710 class->render (area, context, widget, cr, background_area, cell_area, flags, paint_focus);
1712 g_warning ("GtkCellAreaClass::render not implemented for `%s'",
1713 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1717 * gtk_cell_area_set_style_detail:
1718 * @area: a #GtkCellArea
1719 * @detail: the #GtkStyle detail string to set
1721 * Sets the detail string used in any gtk_paint_*() functions
1727 gtk_cell_area_set_style_detail (GtkCellArea *area,
1728 const gchar *detail)
1730 GtkCellAreaPrivate *priv;
1732 g_return_if_fail (GTK_IS_CELL_AREA (area));
1736 if (g_strcmp0 (priv->style_detail, detail) != 0)
1738 g_free (priv->style_detail);
1739 priv->style_detail = g_strdup (detail);
1744 * gtk_cell_area_get_style_detail:
1745 * @area: a #GtkCellArea
1747 * Gets the detail string used in any gtk_paint_*() functions
1750 * Return value: the detail string, the string belongs to the area and should not be freed.
1754 G_CONST_RETURN gchar *
1755 gtk_cell_area_get_style_detail (GtkCellArea *area)
1757 GtkCellAreaPrivate *priv;
1759 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
1763 return priv->style_detail;
1767 get_cell_allocation (GtkCellRenderer *renderer,
1768 const GdkRectangle *cell_area,
1769 const GdkRectangle *cell_background,
1770 RendererAllocationData *data)
1772 if (data->renderer == renderer)
1773 data->allocation = *cell_area;
1775 return (data->renderer == renderer);
1779 * gtk_cell_area_get_cell_allocation:
1780 * @area: a #GtkCellArea
1781 * @context: the #GtkCellAreaContext used to hold sizes for @area.
1782 * @widget: the #GtkWidget that @area is rendering on
1783 * @renderer: the #GtkCellRenderer to get the allocation for
1784 * @cell_area: the whole allocated area for @area in @widget
1786 * @allocation: (out): where to store the allocation for @renderer
1788 * Derives the allocation of @renderer inside @area if @area
1789 * were to be renderered in @cell_area.
1794 gtk_cell_area_get_cell_allocation (GtkCellArea *area,
1795 GtkCellAreaContext *context,
1797 GtkCellRenderer *renderer,
1798 const GdkRectangle *cell_area,
1799 GdkRectangle *allocation)
1801 RendererAllocationData data = { renderer, { 0, } };
1803 g_return_if_fail (GTK_IS_CELL_AREA (area));
1804 g_return_if_fail (GTK_IS_CELL_AREA_CONTEXT (context));
1805 g_return_if_fail (GTK_IS_WIDGET (widget));
1806 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1807 g_return_if_fail (cell_area != NULL);
1808 g_return_if_fail (allocation != NULL);
1810 gtk_cell_area_foreach_alloc (area, context, widget, cell_area, cell_area,
1811 (GtkCellAllocCallback)get_cell_allocation, &data);
1813 *allocation = data.allocation;
1817 get_cell_by_position (GtkCellRenderer *renderer,
1818 const GdkRectangle *cell_area,
1819 const GdkRectangle *cell_background,
1820 CellByPositionData *data)
1822 if (data->x >= cell_area->x && data->x < cell_area->x + cell_area->width &&
1823 data->y >= cell_area->y && data->y < cell_area->y + cell_area->height)
1825 data->renderer = renderer;
1826 data->cell_area = *cell_area;
1829 return (data->renderer != NULL);
1833 * gtk_cell_area_get_cell_at_position:
1834 * @area: a #GtkCellArea
1835 * @context: the #GtkCellAreaContext used to hold sizes for @area.
1836 * @widget: the #GtkWidget that @area is rendering on
1837 * @cell_area: the whole allocated area for @area in @widget
1839 * @x: the x position
1840 * @y: the y position
1841 * @alloc_area: (out) (allow-none): where to store the inner allocated area of the
1842 * returned cell renderer, or %NULL.
1844 * Gets the #GtkCellRenderer at @x and @y coordinates inside @area and optionally
1845 * returns the full cell allocation for it inside @cell_area.
1847 * Returns value: the #GtkCellRenderer at @x and @y.
1852 gtk_cell_area_get_cell_at_position (GtkCellArea *area,
1853 GtkCellAreaContext *context,
1855 const GdkRectangle *cell_area,
1858 GdkRectangle *alloc_area)
1860 CellByPositionData data = { x, y, NULL, { 0, } };
1862 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
1863 g_return_val_if_fail (GTK_IS_CELL_AREA_CONTEXT (context), NULL);
1864 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1865 g_return_val_if_fail (cell_area != NULL, NULL);
1866 g_return_val_if_fail (x >= cell_area->x && x <= cell_area->x + cell_area->width, NULL);
1867 g_return_val_if_fail (y >= cell_area->y && y <= cell_area->y + cell_area->height, NULL);
1869 gtk_cell_area_foreach_alloc (area, context, widget, cell_area, cell_area,
1870 (GtkCellAllocCallback)get_cell_by_position, &data);
1873 *alloc_area = data.cell_area;
1875 return data.renderer;
1878 /*************************************************************
1880 *************************************************************/
1882 * gtk_cell_area_create_context:
1883 * @area: a #GtkCellArea
1885 * Creates a #GtkCellAreaContext to be used with @area for
1886 * all purposes. #GtkCellAreaContext stores geometry information
1887 * for rows for which it was operated on, it is important to use
1888 * the same context for the same row of data at all times (i.e.
1889 * one should render and handle events with the same #GtkCellAreaContext
1890 * which was used to request the size of those rows of data).
1892 * Return value: (transfer full): a newly created #GtkCellAreaContext which can be used with @area.
1896 GtkCellAreaContext *
1897 gtk_cell_area_create_context (GtkCellArea *area)
1899 GtkCellAreaClass *class;
1901 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
1903 class = GTK_CELL_AREA_GET_CLASS (area);
1905 if (class->create_context)
1906 return class->create_context (area);
1908 g_warning ("GtkCellAreaClass::create_context not implemented for `%s'",
1909 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1916 * gtk_cell_area_get_request_mode:
1917 * @area: a #GtkCellArea
1919 * Gets whether the area prefers a height-for-width layout
1920 * or a width-for-height layout.
1922 * Return value: The #GtkSizeRequestMode preferred by @area.
1927 gtk_cell_area_get_request_mode (GtkCellArea *area)
1929 GtkCellAreaClass *class;
1931 g_return_val_if_fail (GTK_IS_CELL_AREA (area),
1932 GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH);
1934 class = GTK_CELL_AREA_GET_CLASS (area);
1936 if (class->get_request_mode)
1937 return class->get_request_mode (area);
1939 g_warning ("GtkCellAreaClass::get_request_mode not implemented for `%s'",
1940 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1942 return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
1946 * gtk_cell_area_get_preferred_width:
1947 * @area: a #GtkCellArea
1948 * @context: the #GtkCellAreaContext to perform this request with
1949 * @widget: the #GtkWidget where @area will be rendering
1950 * @minimum_width: (out) (allow-none): location to store the minimum width, or %NULL
1951 * @natural_width: (out) (allow-none): location to store the natural width, or %NULL
1953 * Retrieves a cell area's initial minimum and natural width.
1955 * @area will store some geometrical information in @context along the way,
1956 * when requesting sizes over an arbitrary number of rows, its not important
1957 * to check the @minimum_width and @natural_width of this call but rather to
1958 * consult gtk_cell_area_context_get_preferred_width() after a series of
1964 gtk_cell_area_get_preferred_width (GtkCellArea *area,
1965 GtkCellAreaContext *context,
1967 gint *minimum_width,
1968 gint *natural_width)
1970 GtkCellAreaClass *class;
1972 g_return_if_fail (GTK_IS_CELL_AREA (area));
1973 g_return_if_fail (GTK_IS_WIDGET (widget));
1975 class = GTK_CELL_AREA_GET_CLASS (area);
1977 if (class->get_preferred_width)
1978 class->get_preferred_width (area, context, widget, minimum_width, natural_width);
1980 g_warning ("GtkCellAreaClass::get_preferred_width not implemented for `%s'",
1981 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1985 * gtk_cell_area_get_preferred_height_for_width:
1986 * @area: a #GtkCellArea
1987 * @context: the #GtkCellAreaContext which has already been requested for widths.
1988 * @widget: the #GtkWidget where @area will be rendering
1989 * @width: the width for which to check the height of this area
1990 * @minimum_height: (out) (allow-none): location to store the minimum height, or %NULL
1991 * @natural_height: (out) (allow-none): location to store the natural height, or %NULL
1993 * Retrieves a cell area's minimum and natural height if it would be given
1994 * the specified @width.
1996 * @area stores some geometrical information in @context along the way
1997 * while calling gtk_cell_area_get_preferred_width(), it's important to
1998 * perform a series of gtk_cell_area_get_preferred_width() requests with
1999 * @context first and then call gtk_cell_area_get_preferred_height_for_width()
2000 * on each cell area individually to get the height for width of each
2001 * fully requested row.
2003 * If at some point, the width of a single row changes, it should be
2004 * requested with gtk_cell_area_get_preferred_width() again and then
2005 * the full width of the requested rows checked again with
2006 * gtk_cell_area_context_get_preferred_width().
2011 gtk_cell_area_get_preferred_height_for_width (GtkCellArea *area,
2012 GtkCellAreaContext *context,
2015 gint *minimum_height,
2016 gint *natural_height)
2018 GtkCellAreaClass *class;
2020 g_return_if_fail (GTK_IS_CELL_AREA (area));
2021 g_return_if_fail (GTK_IS_WIDGET (widget));
2023 class = GTK_CELL_AREA_GET_CLASS (area);
2024 class->get_preferred_height_for_width (area, context, widget, width, minimum_height, natural_height);
2029 * gtk_cell_area_get_preferred_height:
2030 * @area: a #GtkCellArea
2031 * @context: the #GtkCellAreaContext to perform this request with
2032 * @widget: the #GtkWidget where @area will be rendering
2033 * @minimum_height: (out) (allow-none): location to store the minimum height, or %NULL
2034 * @natural_height: (out) (allow-none): location to store the natural height, or %NULL
2036 * Retrieves a cell area's initial minimum and natural height.
2038 * @area will store some geometrical information in @context along the way,
2039 * when requesting sizes over an arbitrary number of rows, its not important
2040 * to check the @minimum_height and @natural_height of this call but rather to
2041 * consult gtk_cell_area_context_get_preferred_height() after a series of
2047 gtk_cell_area_get_preferred_height (GtkCellArea *area,
2048 GtkCellAreaContext *context,
2050 gint *minimum_height,
2051 gint *natural_height)
2053 GtkCellAreaClass *class;
2055 g_return_if_fail (GTK_IS_CELL_AREA (area));
2056 g_return_if_fail (GTK_IS_WIDGET (widget));
2058 class = GTK_CELL_AREA_GET_CLASS (area);
2060 if (class->get_preferred_height)
2061 class->get_preferred_height (area, context, widget, minimum_height, natural_height);
2063 g_warning ("GtkCellAreaClass::get_preferred_height not implemented for `%s'",
2064 g_type_name (G_TYPE_FROM_INSTANCE (area)));
2068 * gtk_cell_area_get_preferred_width_for_height:
2069 * @area: a #GtkCellArea
2070 * @context: the #GtkCellAreaContext which has already been requested for widths.
2071 * @widget: the #GtkWidget where @area will be rendering
2072 * @height: the height for which to check the width of this area
2073 * @minimum_width: (out) (allow-none): location to store the minimum width, or %NULL
2074 * @natural_width: (out) (allow-none): location to store the natural width, or %NULL
2076 * Retrieves a cell area's minimum and natural width if it would be given
2077 * the specified @height.
2079 * @area stores some geometrical information in @context along the way
2080 * while calling gtk_cell_area_get_preferred_height(), it's important to
2081 * perform a series of gtk_cell_area_get_preferred_height() requests with
2082 * @context first and then call gtk_cell_area_get_preferred_width_for_height()
2083 * on each cell area individually to get the height for width of each
2084 * fully requested row.
2086 * If at some point, the height of a single row changes, it should be
2087 * requested with gtk_cell_area_get_preferred_height() again and then
2088 * the full height of the requested rows checked again with
2089 * gtk_cell_area_context_get_preferred_height().
2094 gtk_cell_area_get_preferred_width_for_height (GtkCellArea *area,
2095 GtkCellAreaContext *context,
2098 gint *minimum_width,
2099 gint *natural_width)
2101 GtkCellAreaClass *class;
2103 g_return_if_fail (GTK_IS_CELL_AREA (area));
2104 g_return_if_fail (GTK_IS_WIDGET (widget));
2106 class = GTK_CELL_AREA_GET_CLASS (area);
2107 class->get_preferred_width_for_height (area, context, widget, height, minimum_width, natural_width);
2110 /*************************************************************
2112 *************************************************************/
2115 * gtk_cell_area_attribute_connect:
2116 * @area: a #GtkCellArea
2117 * @renderer: the #GtkCellRenderer to connect an attribute for
2118 * @attribute: the attribute name
2119 * @column: the #GtkTreeModel column to fetch attribute values from
2121 * Connects an @attribute to apply values from @column for the
2122 * #GtkTreeModel in use.
2127 gtk_cell_area_attribute_connect (GtkCellArea *area,
2128 GtkCellRenderer *renderer,
2129 const gchar *attribute,
2132 GtkCellAreaPrivate *priv;
2134 CellAttribute *cell_attribute;
2136 g_return_if_fail (GTK_IS_CELL_AREA (area));
2137 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2138 g_return_if_fail (attribute != NULL);
2139 g_return_if_fail (gtk_cell_area_has_renderer (area, renderer));
2142 info = g_hash_table_lookup (priv->cell_info, renderer);
2146 info = cell_info_new (NULL, NULL, NULL);
2148 g_hash_table_insert (priv->cell_info, renderer, info);
2154 /* Check we are not adding the same attribute twice */
2155 if ((node = g_slist_find_custom (info->attributes, attribute,
2156 (GCompareFunc)cell_attribute_find)) != NULL)
2158 cell_attribute = node->data;
2160 g_warning ("Cannot connect attribute `%s' for cell renderer class `%s' "
2161 "since `%s' is already attributed to column %d",
2163 g_type_name (G_TYPE_FROM_INSTANCE (area)),
2164 attribute, cell_attribute->column);
2169 cell_attribute = cell_attribute_new (renderer, attribute, column);
2171 if (!cell_attribute)
2173 g_warning ("Cannot connect attribute `%s' for cell renderer class `%s' "
2174 "since attribute does not exist",
2176 g_type_name (G_TYPE_FROM_INSTANCE (area)));
2180 info->attributes = g_slist_prepend (info->attributes, cell_attribute);
2184 * gtk_cell_area_attribute_disconnect:
2185 * @area: a #GtkCellArea
2186 * @renderer: the #GtkCellRenderer to disconnect an attribute for
2187 * @attribute: the attribute name
2189 * Disconnects @attribute for the @renderer in @area so that
2190 * attribute will no longer be updated with values from the
2196 gtk_cell_area_attribute_disconnect (GtkCellArea *area,
2197 GtkCellRenderer *renderer,
2198 const gchar *attribute)
2200 GtkCellAreaPrivate *priv;
2202 CellAttribute *cell_attribute;
2205 g_return_if_fail (GTK_IS_CELL_AREA (area));
2206 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2207 g_return_if_fail (attribute != NULL);
2208 g_return_if_fail (gtk_cell_area_has_renderer (area, renderer));
2211 info = g_hash_table_lookup (priv->cell_info, renderer);
2215 node = g_slist_find_custom (info->attributes, attribute,
2216 (GCompareFunc)cell_attribute_find);
2219 cell_attribute = node->data;
2221 cell_attribute_free (cell_attribute);
2223 info->attributes = g_slist_delete_link (info->attributes, node);
2229 * gtk_cell_area_apply_attributes
2230 * @area: a #GtkCellArea
2231 * @tree_model: the #GtkTreeModel to pull values from
2232 * @iter: the #GtkTreeIter in @tree_model to apply values for
2233 * @is_expander: whether @iter has children
2234 * @is_expanded: whether @iter is expanded in the view and
2235 * children are visible
2237 * Applies any connected attributes to the renderers in
2238 * @area by pulling the values from @tree_model.
2243 gtk_cell_area_apply_attributes (GtkCellArea *area,
2244 GtkTreeModel *tree_model,
2246 gboolean is_expander,
2247 gboolean is_expanded)
2249 g_return_if_fail (GTK_IS_CELL_AREA (area));
2250 g_return_if_fail (GTK_IS_TREE_MODEL (tree_model));
2251 g_return_if_fail (iter != NULL);
2253 g_signal_emit (area, cell_area_signals[SIGNAL_APPLY_ATTRIBUTES], 0,
2254 tree_model, iter, is_expander, is_expanded);
2258 * gtk_cell_area_get_current_path_string:
2259 * @area: a #GtkCellArea
2261 * Gets the current #GtkTreePath string for the currently
2262 * applied #GtkTreeIter, this is implicitly updated when
2263 * gtk_cell_area_apply_attributes() is called and can be
2264 * used to interact with renderers from #GtkCellArea
2267 * Return value: The current #GtkTreePath string for the current
2268 * attributes applied to @area. This string belongs to the area and
2269 * should not be freed.
2273 G_CONST_RETURN gchar *
2274 gtk_cell_area_get_current_path_string (GtkCellArea *area)
2276 GtkCellAreaPrivate *priv;
2278 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
2282 return priv->current_path;
2286 /*************************************************************
2287 * API: Cell Properties *
2288 *************************************************************/
2290 * gtk_cell_area_class_install_cell_property:
2291 * @aclass: a #GtkCellAreaClass
2292 * @property_id: the id for the property
2293 * @pspec: the #GParamSpec for the property
2295 * Installs a cell property on a cell area class.
2300 gtk_cell_area_class_install_cell_property (GtkCellAreaClass *aclass,
2304 g_return_if_fail (GTK_IS_CELL_AREA_CLASS (aclass));
2305 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
2306 if (pspec->flags & G_PARAM_WRITABLE)
2307 g_return_if_fail (aclass->set_cell_property != NULL);
2308 if (pspec->flags & G_PARAM_READABLE)
2309 g_return_if_fail (aclass->get_cell_property != NULL);
2310 g_return_if_fail (property_id > 0);
2311 g_return_if_fail (PARAM_SPEC_PARAM_ID (pspec) == 0); /* paranoid */
2312 g_return_if_fail ((pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY)) == 0);
2314 if (g_param_spec_pool_lookup (cell_property_pool, pspec->name, G_OBJECT_CLASS_TYPE (aclass), TRUE))
2316 g_warning (G_STRLOC ": class `%s' already contains a cell property named `%s'",
2317 G_OBJECT_CLASS_NAME (aclass), pspec->name);
2320 g_param_spec_ref (pspec);
2321 g_param_spec_sink (pspec);
2322 PARAM_SPEC_SET_PARAM_ID (pspec, property_id);
2323 g_param_spec_pool_insert (cell_property_pool, pspec, G_OBJECT_CLASS_TYPE (aclass));
2327 * gtk_cell_area_class_find_cell_property:
2328 * @aclass: a #GtkCellAreaClass
2329 * @property_name: the name of the child property to find
2331 * Finds a cell property of a cell area class by name.
2333 * Return value: (allow-none): the #GParamSpec of the child property or %NULL if @aclass has no
2334 * child property with that name.
2339 gtk_cell_area_class_find_cell_property (GtkCellAreaClass *aclass,
2340 const gchar *property_name)
2342 g_return_val_if_fail (GTK_IS_CELL_AREA_CLASS (aclass), NULL);
2343 g_return_val_if_fail (property_name != NULL, NULL);
2345 return g_param_spec_pool_lookup (cell_property_pool,
2347 G_OBJECT_CLASS_TYPE (aclass),
2352 * gtk_cell_area_class_list_cell_properties:
2353 * @aclass: a #GtkCellAreaClass
2354 * @n_properties: location to return the number of cell properties found
2356 * Returns all cell properties of a cell area class.
2358 * Return value: a newly allocated %NULL-terminated array of #GParamSpec*.
2359 * The array must be freed with g_free().
2364 gtk_cell_area_class_list_cell_properties (GtkCellAreaClass *aclass,
2365 guint *n_properties)
2367 GParamSpec **pspecs;
2370 g_return_val_if_fail (GTK_IS_CELL_AREA_CLASS (aclass), NULL);
2372 pspecs = g_param_spec_pool_list (cell_property_pool,
2373 G_OBJECT_CLASS_TYPE (aclass),
2382 * gtk_cell_area_add_with_properties:
2383 * @area: a #GtkCellArea
2384 * @renderer: a #GtkCellRenderer to be placed inside @area
2385 * @first_prop_name: the name of the first cell property to set
2386 * @Varargs: a %NULL-terminated list of property names and values, starting
2387 * with @first_prop_name
2389 * Adds @renderer to @area, setting cell properties at the same time.
2390 * See gtk_cell_area_add() and gtk_cell_area_child_set() for more details.
2395 gtk_cell_area_add_with_properties (GtkCellArea *area,
2396 GtkCellRenderer *renderer,
2397 const gchar *first_prop_name,
2400 GtkCellAreaClass *class;
2402 g_return_if_fail (GTK_IS_CELL_AREA (area));
2403 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2405 class = GTK_CELL_AREA_GET_CLASS (area);
2411 class->add (area, renderer);
2413 va_start (var_args, first_prop_name);
2414 gtk_cell_area_cell_set_valist (area, renderer, first_prop_name, var_args);
2418 g_warning ("GtkCellAreaClass::add not implemented for `%s'",
2419 g_type_name (G_TYPE_FROM_INSTANCE (area)));
2423 * gtk_cell_area_cell_set:
2424 * @area: a #GtkCellArea
2425 * @renderer: a #GtkCellRenderer which is a cell inside @area
2426 * @first_prop_name: the name of the first cell property to set
2427 * @Varargs: a %NULL-terminated list of property names and values, starting
2428 * with @first_prop_name
2430 * Sets one or more cell properties for @cell in @area.
2435 gtk_cell_area_cell_set (GtkCellArea *area,
2436 GtkCellRenderer *renderer,
2437 const gchar *first_prop_name,
2442 g_return_if_fail (GTK_IS_CELL_AREA (area));
2443 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2445 va_start (var_args, first_prop_name);
2446 gtk_cell_area_cell_set_valist (area, renderer, first_prop_name, var_args);
2451 * gtk_cell_area_cell_get:
2452 * @area: a #GtkCellArea
2453 * @renderer: a #GtkCellRenderer which is inside @area
2454 * @first_prop_name: the name of the first cell property to get
2455 * @Varargs: return location for the first cell property, followed
2456 * optionally by more name/return location pairs, followed by %NULL
2458 * Gets the values of one or more cell properties for @renderer in @area.
2463 gtk_cell_area_cell_get (GtkCellArea *area,
2464 GtkCellRenderer *renderer,
2465 const gchar *first_prop_name,
2470 g_return_if_fail (GTK_IS_CELL_AREA (area));
2471 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2473 va_start (var_args, first_prop_name);
2474 gtk_cell_area_cell_get_valist (area, renderer, first_prop_name, var_args);
2479 area_get_cell_property (GtkCellArea *area,
2480 GtkCellRenderer *renderer,
2484 GtkCellAreaClass *class = g_type_class_peek (pspec->owner_type);
2486 class->get_cell_property (area, renderer, PARAM_SPEC_PARAM_ID (pspec), value, pspec);
2490 area_set_cell_property (GtkCellArea *area,
2491 GtkCellRenderer *renderer,
2493 const GValue *value)
2495 GValue tmp_value = { 0, };
2496 GtkCellAreaClass *class = g_type_class_peek (pspec->owner_type);
2498 /* provide a copy to work from, convert (if necessary) and validate */
2499 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2500 if (!g_value_transform (value, &tmp_value))
2501 g_warning ("unable to set cell property `%s' of type `%s' from value of type `%s'",
2503 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
2504 G_VALUE_TYPE_NAME (value));
2505 else if (g_param_value_validate (pspec, &tmp_value) && !(pspec->flags & G_PARAM_LAX_VALIDATION))
2507 gchar *contents = g_strdup_value_contents (value);
2509 g_warning ("value \"%s\" of type `%s' is invalid for property `%s' of type `%s'",
2511 G_VALUE_TYPE_NAME (value),
2513 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
2518 class->set_cell_property (area, renderer, PARAM_SPEC_PARAM_ID (pspec), &tmp_value, pspec);
2520 g_value_unset (&tmp_value);
2524 * gtk_cell_area_cell_set_valist:
2525 * @area: a #GtkCellArea
2526 * @renderer: a #GtkCellRenderer which inside @area
2527 * @first_property_name: the name of the first cell property to set
2528 * @var_args: a %NULL-terminated list of property names and values, starting
2529 * with @first_prop_name
2531 * Sets one or more cell properties for @renderer in @area.
2536 gtk_cell_area_cell_set_valist (GtkCellArea *area,
2537 GtkCellRenderer *renderer,
2538 const gchar *first_property_name,
2543 g_return_if_fail (GTK_IS_CELL_AREA (area));
2544 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2546 name = first_property_name;
2549 GValue value = { 0, };
2550 gchar *error = NULL;
2552 g_param_spec_pool_lookup (cell_property_pool, name,
2553 G_OBJECT_TYPE (area), TRUE);
2556 g_warning ("%s: cell area class `%s' has no cell property named `%s'",
2557 G_STRLOC, G_OBJECT_TYPE_NAME (area), name);
2560 if (!(pspec->flags & G_PARAM_WRITABLE))
2562 g_warning ("%s: cell property `%s' of cell area class `%s' is not writable",
2563 G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
2567 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2568 G_VALUE_COLLECT (&value, var_args, 0, &error);
2571 g_warning ("%s: %s", G_STRLOC, error);
2574 /* we purposely leak the value here, it might not be
2575 * in a sane state if an error condition occoured
2579 area_set_cell_property (area, renderer, pspec, &value);
2580 g_value_unset (&value);
2581 name = va_arg (var_args, gchar*);
2586 * gtk_cell_area_cell_get_valist:
2587 * @area: a #GtkCellArea
2588 * @renderer: a #GtkCellRenderer inside @area
2589 * @first_property_name: the name of the first property to get
2590 * @var_args: return location for the first property, followed
2591 * optionally by more name/return location pairs, followed by %NULL
2593 * Gets the values of one or more cell properties for @renderer in @area.
2598 gtk_cell_area_cell_get_valist (GtkCellArea *area,
2599 GtkCellRenderer *renderer,
2600 const gchar *first_property_name,
2605 g_return_if_fail (GTK_IS_CELL_AREA (area));
2606 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2608 name = first_property_name;
2611 GValue value = { 0, };
2615 pspec = g_param_spec_pool_lookup (cell_property_pool, name,
2616 G_OBJECT_TYPE (area), TRUE);
2619 g_warning ("%s: cell area class `%s' has no cell property named `%s'",
2620 G_STRLOC, G_OBJECT_TYPE_NAME (area), name);
2623 if (!(pspec->flags & G_PARAM_READABLE))
2625 g_warning ("%s: cell property `%s' of cell area class `%s' is not readable",
2626 G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
2630 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2631 area_get_cell_property (area, renderer, pspec, &value);
2632 G_VALUE_LCOPY (&value, var_args, 0, &error);
2635 g_warning ("%s: %s", G_STRLOC, error);
2637 g_value_unset (&value);
2640 g_value_unset (&value);
2641 name = va_arg (var_args, gchar*);
2646 * gtk_cell_area_cell_set_property:
2647 * @area: a #GtkCellArea
2648 * @renderer: a #GtkCellRenderer inside @area
2649 * @property_name: the name of the cell property to set
2650 * @value: the value to set the cell property to
2652 * Sets a cell property for @renderer in @area.
2657 gtk_cell_area_cell_set_property (GtkCellArea *area,
2658 GtkCellRenderer *renderer,
2659 const gchar *property_name,
2660 const GValue *value)
2664 g_return_if_fail (GTK_IS_CELL_AREA (area));
2665 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2666 g_return_if_fail (property_name != NULL);
2667 g_return_if_fail (G_IS_VALUE (value));
2669 pspec = g_param_spec_pool_lookup (cell_property_pool, property_name,
2670 G_OBJECT_TYPE (area), TRUE);
2672 g_warning ("%s: cell area class `%s' has no cell property named `%s'",
2673 G_STRLOC, G_OBJECT_TYPE_NAME (area), property_name);
2674 else if (!(pspec->flags & G_PARAM_WRITABLE))
2675 g_warning ("%s: cell property `%s' of cell area class `%s' is not writable",
2676 G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
2679 area_set_cell_property (area, renderer, pspec, value);
2684 * gtk_cell_area_cell_get_property:
2685 * @area: a #GtkCellArea
2686 * @renderer: a #GtkCellRenderer inside @area
2687 * @property_name: the name of the property to get
2688 * @value: a location to return the value
2690 * Gets the value of a cell property for @renderer in @area.
2695 gtk_cell_area_cell_get_property (GtkCellArea *area,
2696 GtkCellRenderer *renderer,
2697 const gchar *property_name,
2702 g_return_if_fail (GTK_IS_CELL_AREA (area));
2703 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2704 g_return_if_fail (property_name != NULL);
2705 g_return_if_fail (G_IS_VALUE (value));
2707 pspec = g_param_spec_pool_lookup (cell_property_pool, property_name,
2708 G_OBJECT_TYPE (area), TRUE);
2710 g_warning ("%s: cell area class `%s' has no cell property named `%s'",
2711 G_STRLOC, G_OBJECT_TYPE_NAME (area), property_name);
2712 else if (!(pspec->flags & G_PARAM_READABLE))
2713 g_warning ("%s: cell property `%s' of cell area class `%s' is not readable",
2714 G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
2717 GValue *prop_value, tmp_value = { 0, };
2719 /* auto-conversion of the callers value type
2721 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
2723 g_value_reset (value);
2726 else if (!g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
2728 g_warning ("can't retrieve cell property `%s' of type `%s' as value of type `%s'",
2730 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
2731 G_VALUE_TYPE_NAME (value));
2736 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2737 prop_value = &tmp_value;
2740 area_get_cell_property (area, renderer, pspec, prop_value);
2742 if (prop_value != value)
2744 g_value_transform (prop_value, value);
2745 g_value_unset (&tmp_value);
2750 /*************************************************************
2752 *************************************************************/
2755 * gtk_cell_area_is_activatable:
2756 * @area: a #GtkCellArea
2758 * Returns whether the area can do anything when activated,
2759 * after applying new attributes to @area.
2761 * Return value: whether @area can do anything when activated.
2766 gtk_cell_area_is_activatable (GtkCellArea *area)
2768 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2770 return GTK_CELL_AREA_GET_CLASS (area)->is_activatable (area);
2774 * gtk_cell_area_focus:
2775 * @area: a #GtkCellArea
2776 * @direction: the #GtkDirectionType
2778 * This should be called by the @area's owning layout widget
2779 * when focus is to be passed to @area, or moved within @area
2780 * for a given @direction and row data.
2782 * Implementing #GtkCellArea classes should implement this
2783 * method to receive and navigate focus in it's own way particular
2784 * to how it lays out cells.
2786 * Return value: %TRUE if focus remains inside @area as a result of this call.
2791 gtk_cell_area_focus (GtkCellArea *area,
2792 GtkDirectionType direction)
2794 GtkCellAreaClass *class;
2796 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2798 class = GTK_CELL_AREA_GET_CLASS (area);
2801 return class->focus (area, direction);
2803 g_warning ("GtkCellAreaClass::focus not implemented for `%s'",
2804 g_type_name (G_TYPE_FROM_INSTANCE (area)));
2810 * gtk_cell_area_activate:
2811 * @area: a #GtkCellArea
2812 * @context: the #GtkCellAreaContext in context with the current row data
2813 * @widget: the #GtkWidget that @area is rendering on
2814 * @cell_area: the size and location of @area relative to @widget's allocation
2815 * @flags: the #GtkCellRendererState flags for @area for this row of data.
2817 * Activates @area, usually by activating the currently focused
2818 * cell, however some subclasses which embed widgets in the area
2819 * can also activate a widget if it currently has the focus.
2821 * Return value: Whether @area was successfully activated.
2826 gtk_cell_area_activate (GtkCellArea *area,
2827 GtkCellAreaContext *context,
2829 const GdkRectangle *cell_area,
2830 GtkCellRendererState flags)
2832 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2834 return GTK_CELL_AREA_GET_CLASS (area)->activate (area, context, widget, cell_area, flags);
2839 * gtk_cell_area_set_focus_cell:
2840 * @area: a #GtkCellArea
2841 * @focus_cell: the #GtkCellRenderer to give focus to
2843 * This is generally called from #GtkCellArea implementations
2844 * either gtk_cell_area_grab_focus() or gtk_cell_area_update_focus()
2845 * is called. It's also up to the #GtkCellArea implementation
2846 * to update the focused cell when receiving events from
2847 * gtk_cell_area_event() appropriately.
2852 gtk_cell_area_set_focus_cell (GtkCellArea *area,
2853 GtkCellRenderer *renderer)
2855 GtkCellAreaPrivate *priv;
2857 g_return_if_fail (GTK_IS_CELL_AREA (area));
2858 g_return_if_fail (renderer == NULL || GTK_IS_CELL_RENDERER (renderer));
2862 if (priv->focus_cell != renderer)
2864 if (priv->focus_cell)
2865 g_object_unref (priv->focus_cell);
2867 priv->focus_cell = renderer;
2869 if (priv->focus_cell)
2870 g_object_ref (priv->focus_cell);
2872 g_object_notify (G_OBJECT (area), "focus-cell");
2875 /* Signal that the current focus renderer for this path changed
2876 * (it may be that the focus cell did not change, but the row
2877 * may have changed so we need to signal it) */
2878 g_signal_emit (area, cell_area_signals[SIGNAL_FOCUS_CHANGED], 0,
2879 priv->focus_cell, priv->current_path);
2884 * gtk_cell_area_get_focus_cell:
2885 * @area: a #GtkCellArea
2887 * Retrieves the currently focused cell for @area
2889 * Return value: the currently focused cell in @area.
2894 gtk_cell_area_get_focus_cell (GtkCellArea *area)
2896 GtkCellAreaPrivate *priv;
2898 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
2902 return priv->focus_cell;
2906 /*************************************************************
2907 * API: Focus Siblings *
2908 *************************************************************/
2911 * gtk_cell_area_add_focus_sibling:
2912 * @area: a #GtkCellArea
2913 * @renderer: the #GtkCellRenderer expected to have focus
2914 * @sibling: the #GtkCellRenderer to add to @renderer's focus area
2916 * Adds @sibling to @renderer's focusable area, focus will be drawn
2917 * around @renderer and all of it's siblings if @renderer can
2918 * focus for a given row.
2920 * Events handled by focus siblings can also activate the given
2921 * focusable @renderer.
2926 gtk_cell_area_add_focus_sibling (GtkCellArea *area,
2927 GtkCellRenderer *renderer,
2928 GtkCellRenderer *sibling)
2930 GtkCellAreaPrivate *priv;
2933 g_return_if_fail (GTK_IS_CELL_AREA (area));
2934 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2935 g_return_if_fail (GTK_IS_CELL_RENDERER (sibling));
2936 g_return_if_fail (renderer != sibling);
2937 g_return_if_fail (gtk_cell_area_has_renderer (area, renderer));
2938 g_return_if_fail (gtk_cell_area_has_renderer (area, sibling));
2939 g_return_if_fail (!gtk_cell_area_is_focus_sibling (area, renderer, sibling));
2941 /* XXX We should also check that sibling is not in any other renderer's sibling
2942 * list already, a renderer can be sibling of only one focusable renderer
2948 siblings = g_hash_table_lookup (priv->focus_siblings, renderer);
2951 siblings = g_list_append (siblings, sibling);
2954 siblings = g_list_append (siblings, sibling);
2955 g_hash_table_insert (priv->focus_siblings, renderer, siblings);
2960 * gtk_cell_area_remove_focus_sibling:
2961 * @area: a #GtkCellArea
2962 * @renderer: the #GtkCellRenderer expected to have focus
2963 * @sibling: the #GtkCellRenderer to remove from @renderer's focus area
2965 * Removes @sibling from @renderer's focus sibling list
2966 * (see gtk_cell_area_add_focus_sibling()).
2971 gtk_cell_area_remove_focus_sibling (GtkCellArea *area,
2972 GtkCellRenderer *renderer,
2973 GtkCellRenderer *sibling)
2975 GtkCellAreaPrivate *priv;
2978 g_return_if_fail (GTK_IS_CELL_AREA (area));
2979 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2980 g_return_if_fail (GTK_IS_CELL_RENDERER (sibling));
2981 g_return_if_fail (gtk_cell_area_is_focus_sibling (area, renderer, sibling));
2985 siblings = g_hash_table_lookup (priv->focus_siblings, renderer);
2987 siblings = g_list_copy (siblings);
2988 siblings = g_list_remove (siblings, sibling);
2991 g_hash_table_remove (priv->focus_siblings, renderer);
2993 g_hash_table_insert (priv->focus_siblings, renderer, siblings);
2997 * gtk_cell_area_is_focus_sibling:
2998 * @area: a #GtkCellArea
2999 * @renderer: the #GtkCellRenderer expected to have focus
3000 * @sibling: the #GtkCellRenderer to check against @renderer's sibling list
3002 * Returns %TRUE if @sibling is one of @renderer's focus siblings
3003 * (see gtk_cell_area_add_focus_sibling()).
3008 gtk_cell_area_is_focus_sibling (GtkCellArea *area,
3009 GtkCellRenderer *renderer,
3010 GtkCellRenderer *sibling)
3012 GtkCellAreaPrivate *priv;
3013 GList *siblings, *l;
3015 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
3016 g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), FALSE);
3017 g_return_val_if_fail (GTK_IS_CELL_RENDERER (sibling), FALSE);
3021 siblings = g_hash_table_lookup (priv->focus_siblings, renderer);
3023 for (l = siblings; l; l = l->next)
3025 GtkCellRenderer *a_sibling = l->data;
3027 if (a_sibling == sibling)
3035 * gtk_cell_area_get_focus_siblings:
3036 * @area: a #GtkCellArea
3037 * @renderer: the #GtkCellRenderer expected to have focus
3039 * Gets the focus sibling cell renderers for @renderer.
3041 * Return value: (element-type GtkCellRenderer) (transfer none): A #GList of #GtkCellRenderers.
3042 * The returned list is internal and should not be freed.
3047 gtk_cell_area_get_focus_siblings (GtkCellArea *area,
3048 GtkCellRenderer *renderer)
3050 GtkCellAreaPrivate *priv;
3052 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
3053 g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), NULL);
3057 return g_hash_table_lookup (priv->focus_siblings, renderer);
3061 * gtk_cell_area_get_focus_from_sibling:
3062 * @area: a #GtkCellArea
3063 * @renderer: the #GtkCellRenderer
3065 * Gets the #GtkCellRenderer which is expected to be focusable
3066 * for which @renderer is, or may be a sibling.
3068 * This is handy for #GtkCellArea subclasses when handling events,
3069 * after determining the renderer at the event location it can
3070 * then chose to activate the focus cell for which the event
3071 * cell may have been a sibling.
3073 * Return value: the #GtkCellRenderer for which @renderer is a sibling, or %NULL.
3078 gtk_cell_area_get_focus_from_sibling (GtkCellArea *area,
3079 GtkCellRenderer *renderer)
3081 GtkCellRenderer *ret_renderer = NULL;
3082 GList *renderers, *l;
3084 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
3085 g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), NULL);
3087 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (area));
3089 for (l = renderers; l; l = l->next)
3091 GtkCellRenderer *a_renderer = l->data;
3094 for (list = gtk_cell_area_get_focus_siblings (area, a_renderer);
3095 list; list = list->next)
3097 GtkCellRenderer *sibling_renderer = list->data;
3099 if (sibling_renderer == renderer)
3101 ret_renderer = a_renderer;
3106 g_list_free (renderers);
3108 return ret_renderer;
3111 /*************************************************************
3112 * API: Cell Activation/Editing *
3113 *************************************************************/
3115 gtk_cell_area_add_editable (GtkCellArea *area,
3116 GtkCellRenderer *renderer,
3117 GtkCellEditable *editable,
3118 const GdkRectangle *cell_area)
3120 g_signal_emit (area, cell_area_signals[SIGNAL_ADD_EDITABLE], 0,
3121 renderer, editable, cell_area, area->priv->current_path);
3125 gtk_cell_area_remove_editable (GtkCellArea *area,
3126 GtkCellRenderer *renderer,
3127 GtkCellEditable *editable)
3129 g_signal_emit (area, cell_area_signals[SIGNAL_REMOVE_EDITABLE], 0, renderer, editable);
3133 cell_area_remove_widget_cb (GtkCellEditable *editable,
3136 GtkCellAreaPrivate *priv = area->priv;
3138 g_assert (priv->edit_widget == editable);
3139 g_assert (priv->edited_cell != NULL);
3141 gtk_cell_area_remove_editable (area, priv->edited_cell, priv->edit_widget);
3143 /* Now that we're done with editing the widget and it can be removed,
3144 * remove our references to the widget and disconnect handlers */
3145 gtk_cell_area_set_edited_cell (area, NULL);
3146 gtk_cell_area_set_edit_widget (area, NULL);
3150 gtk_cell_area_set_edited_cell (GtkCellArea *area,
3151 GtkCellRenderer *renderer)
3153 GtkCellAreaPrivate *priv;
3155 g_return_if_fail (GTK_IS_CELL_AREA (area));
3156 g_return_if_fail (renderer == NULL || GTK_IS_CELL_RENDERER (renderer));
3160 if (priv->edited_cell != renderer)
3162 if (priv->edited_cell)
3163 g_object_unref (priv->edited_cell);
3165 priv->edited_cell = renderer;
3167 if (priv->edited_cell)
3168 g_object_ref (priv->edited_cell);
3170 g_object_notify (G_OBJECT (area), "edited-cell");
3175 gtk_cell_area_set_edit_widget (GtkCellArea *area,
3176 GtkCellEditable *editable)
3178 GtkCellAreaPrivate *priv;
3180 g_return_if_fail (GTK_IS_CELL_AREA (area));
3181 g_return_if_fail (editable == NULL || GTK_IS_CELL_EDITABLE (editable));
3185 if (priv->edit_widget != editable)
3187 if (priv->edit_widget)
3189 g_signal_handler_disconnect (priv->edit_widget, priv->remove_widget_id);
3191 g_object_unref (priv->edit_widget);
3194 priv->edit_widget = editable;
3196 if (priv->edit_widget)
3198 priv->remove_widget_id =
3199 g_signal_connect (priv->edit_widget, "remove-widget",
3200 G_CALLBACK (cell_area_remove_widget_cb), area);
3202 g_object_ref (priv->edit_widget);
3205 g_object_notify (G_OBJECT (area), "edit-widget");
3210 * gtk_cell_area_get_edited_cell:
3211 * @area: a #GtkCellArea
3213 * Gets the #GtkCellRenderer in @area that is currently
3216 * Return value: The currently edited #GtkCellRenderer
3221 gtk_cell_area_get_edited_cell (GtkCellArea *area)
3223 GtkCellAreaPrivate *priv;
3225 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
3229 return priv->edited_cell;
3233 * gtk_cell_area_get_edit_widget:
3234 * @area: a #GtkCellArea
3236 * Gets the #GtkCellEditable widget currently used
3237 * to edit the currently edited cell.
3239 * Return value: The currently active #GtkCellEditable widget
3244 gtk_cell_area_get_edit_widget (GtkCellArea *area)
3246 GtkCellAreaPrivate *priv;
3248 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
3252 return priv->edit_widget;
3256 * gtk_cell_area_activate_cell:
3257 * @area: a #GtkCellArea
3258 * @widget: the #GtkWidget that @area is rendering onto
3259 * @renderer: the #GtkCellRenderer in @area to activate
3260 * @event: the #GdkEvent for which cell activation should occur
3261 * @cell_area: the #GdkRectangle in @widget relative coordinates
3262 * of @renderer for the current row.
3263 * @flags: the #GtkCellRendererState for @renderer
3265 * This is used by #GtkCellArea subclasses when handling events
3266 * to activate cells, the base #GtkCellArea class activates cells
3267 * for keyboard events for free in it's own GtkCellArea->activate()
3270 * Return value: whether cell activation was successful
3275 gtk_cell_area_activate_cell (GtkCellArea *area,
3277 GtkCellRenderer *renderer,
3279 const GdkRectangle *cell_area,
3280 GtkCellRendererState flags)
3282 GtkCellRendererMode mode;
3283 GtkCellAreaPrivate *priv;
3285 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
3286 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3287 g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), FALSE);
3288 g_return_val_if_fail (cell_area != NULL, FALSE);
3292 g_object_get (renderer, "mode", &mode, NULL);
3294 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
3296 if (gtk_cell_renderer_activate (renderer,
3304 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
3306 GtkCellEditable *editable_widget;
3309 gtk_cell_renderer_start_editing (renderer,
3316 if (editable_widget != NULL)
3318 g_return_val_if_fail (GTK_IS_CELL_EDITABLE (editable_widget), FALSE);
3320 gtk_cell_area_set_edited_cell (area, renderer);
3321 gtk_cell_area_set_edit_widget (area, editable_widget);
3323 /* Signal that editing started so that callers can get
3324 * a handle on the editable_widget */
3325 gtk_cell_area_add_editable (area, priv->focus_cell, editable_widget, cell_area);
3327 /* If the signal was successfully handled start the editing */
3328 if (gtk_widget_get_parent (GTK_WIDGET (editable_widget)))
3330 gtk_cell_editable_start_editing (editable_widget, NULL);
3331 gtk_widget_grab_focus (GTK_WIDGET (editable_widget));
3335 /* Otherwise clear the editing state and fire a warning */
3336 gtk_cell_area_set_edited_cell (area, NULL);
3337 gtk_cell_area_set_edit_widget (area, NULL);
3339 g_warning ("GtkCellArea::add-editable fired in the dark, no cell editing was started.");
3350 * gtk_cell_area_stop_editing:
3351 * @area: a #GtkCellArea
3352 * @canceled: whether editing was canceled.
3354 * Explicitly stops the editing of the currently
3355 * edited cell (see gtk_cell_area_get_edited_cell()).
3357 * If @canceled is %TRUE, the cell renderer will emit
3358 * the ::editing-canceled signal.
3363 gtk_cell_area_stop_editing (GtkCellArea *area,
3366 GtkCellAreaPrivate *priv;
3368 g_return_if_fail (GTK_IS_CELL_AREA (area));
3372 if (priv->edited_cell)
3374 GtkCellEditable *edit_widget = g_object_ref (priv->edit_widget);
3375 GtkCellRenderer *edit_cell = g_object_ref (priv->edited_cell);
3377 /* Stop editing of the cell renderer */
3378 gtk_cell_renderer_stop_editing (priv->edited_cell, canceled);
3380 /* Remove any references to the editable widget */
3381 gtk_cell_area_set_edited_cell (area, NULL);
3382 gtk_cell_area_set_edit_widget (area, NULL);
3384 /* Send the remove-widget signal explicitly (this is done after setting
3385 * the edit cell/widget NULL to avoid feedback)
3387 gtk_cell_area_remove_editable (area, edit_cell, edit_widget);
3388 g_object_unref (edit_cell);
3389 g_object_unref (edit_widget);
3393 /*************************************************************
3394 * API: Convenience for area implementations *
3395 *************************************************************/
3398 * gtk_cell_area_inner_cell_area:
3399 * @area: a #GtkCellArea
3400 * @widget: the #GtkWidget that @area is rendering onto
3401 * @cell_area: the @widget relative coordinates where one of @area's cells
3403 * @inner_area: (out): the return location for the inner cell area
3405 * This is a convenience function for #GtkCellArea implementations
3406 * to get the inner area where a given #GtkCellRenderer will be
3407 * rendered. It removes any padding previously added by gtk_cell_area_request_renderer().
3412 gtk_cell_area_inner_cell_area (GtkCellArea *area,
3414 const GdkRectangle *cell_area,
3415 GdkRectangle *inner_area)
3417 gint focus_line_width;
3419 g_return_if_fail (GTK_IS_CELL_AREA (area));
3420 g_return_if_fail (GTK_IS_WIDGET (widget));
3421 g_return_if_fail (cell_area != NULL);
3422 g_return_if_fail (inner_area != NULL);
3424 gtk_widget_style_get (widget, "focus-line-width", &focus_line_width, NULL);
3426 *inner_area = *cell_area;
3428 inner_area->x += focus_line_width;
3429 inner_area->width -= focus_line_width * 2;
3430 inner_area->y += focus_line_width;
3431 inner_area->height -= focus_line_width * 2;
3435 * gtk_cell_area_request_renderer:
3436 * @area: a #GtkCellArea
3437 * @renderer: the #GtkCellRenderer to request size for
3438 * @orientation: the #GtkOrientation in which to request size
3439 * @widget: the #GtkWidget that @area is rendering onto
3440 * @for_size: the allocation contextual size to request for, or -1 if
3441 * the base request for the orientation is to be returned.
3442 * @minimum_size: (out) (allow-none): location to store the minimum size, or %NULL
3443 * @natural_size: (out) (allow-none): location to store the natural size, or %NULL
3445 * This is a convenience function for #GtkCellArea implementations
3446 * to request size for cell renderers. It's important to use this
3447 * function to request size and then use gtk_cell_area_inner_cell_area()
3448 * at render and event time since this function will add padding
3449 * around the cell for focus painting.
3454 gtk_cell_area_request_renderer (GtkCellArea *area,
3455 GtkCellRenderer *renderer,
3456 GtkOrientation orientation,
3462 GtkCellAreaPrivate *priv;
3463 gint focus_line_width;
3465 g_return_if_fail (GTK_IS_CELL_AREA (area));
3466 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
3467 g_return_if_fail (GTK_IS_WIDGET (widget));
3468 g_return_if_fail (minimum_size != NULL);
3469 g_return_if_fail (natural_size != NULL);
3473 gtk_widget_style_get (widget, "focus-line-width", &focus_line_width, NULL);
3475 focus_line_width *= 2;
3477 if (orientation == GTK_ORIENTATION_HORIZONTAL)
3480 gtk_cell_renderer_get_preferred_width (renderer, widget, minimum_size, natural_size);
3483 for_size = MAX (0, for_size - focus_line_width);
3485 gtk_cell_renderer_get_preferred_width_for_height (renderer, widget, for_size,
3486 minimum_size, natural_size);
3489 else /* GTK_ORIENTATION_VERTICAL */
3492 gtk_cell_renderer_get_preferred_height (renderer, widget, minimum_size, natural_size);
3495 for_size = MAX (0, for_size - focus_line_width);
3497 gtk_cell_renderer_get_preferred_height_for_width (renderer, widget, for_size,
3498 minimum_size, natural_size);
3502 *minimum_size += focus_line_width;
3503 *natural_size += focus_line_width;