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
30 * (also referred to as "layouting widgets") to interface with an
31 * arbitrary number of #GtkCellRenderers and interact with the user
32 * for a given #GtkTreeModel row.
34 * The cell area handles events, focus navigation, drawing and
35 * size requests and allocations for a given row of data.
37 * Usually users dont have to interact with the #GtkCellArea directly
38 * unless they are implementing a cell layouting widget themselves.
40 * <refsect2 id="cell-area-geometry-management">
41 * <title>Requesting area sizes</title>
43 * As outlined in <link linkend="geometry-management">GtkWidget's
44 * geometry management section</link>, GTK+ uses a height-for-width
45 * geometry management system to compute the sizes of widgets and user
46 * interfaces. #GtkCellArea uses the same semantics to calculate the
47 * size of an area for an arbitrary number of #GtkTreeModel rows.
49 * When requesting the size of a cell area one needs to calculate
50 * the size for a handful of rows, this will be done differently by
51 * different layouting widgets. For instance a #GtkTreeViewColumn
52 * always lines up the areas from top to bottom while a #GtkIconView
53 * on the other hand might enforce that all areas received the same
54 * width and wrap the areas around, requesting height for more cell
55 * areas when allocated less width.
57 * It's also important for areas to maintain some cell
58 * alignments with areas rendered for adjacent rows (cells can
59 * appear "columnized" inside an area even when the size of
60 * cells are different in each row). For this reason the #GtkCellArea
61 * uses a #GtkCellAreaContext object to store the alignments
62 * and sizes along the way (as well as the overall largest minimum
63 * and natural size for all the rows which have been calculated
64 * with the said context).
66 * The #GtkCellAreaContext is an opaque object specific to the
67 * #GtkCellArea which created it (see gtk_cell_area_create_context()).
68 * The owning cell layouting widget can create as many contexts as
69 * it wishes to calculate sizes of rows which should receive the
70 * same size in at least one orientation (horizontally or vertically),
71 * however it's important that the same #GtkCellAreaContext which
72 * was used to request the sizes for a given #GtkTreeModel row be
73 * used when rendering or processing events for that row.
75 * In order to request the width of all the rows at the root level
76 * of a #GtkTreeModel one would do the following:
78 * <title>Requesting the width of a handful of GtkTreeModel rows</title>
84 * valid = gtk_tree_model_get_iter_first (model, &iter);
87 * gtk_cell_area_apply_attributes (area, model, &iter, FALSE, FALSE);
88 * gtk_cell_area_get_preferred_width (area, context, widget, NULL, NULL);
90 * valid = gtk_tree_model_iter_next (model, &iter);
92 * gtk_cell_area_context_get_preferred_width (context, &minimum_width, &natural_width);
95 * Note that in this example it's not important to observe the
96 * returned minimum and natural width of the area for each row
97 * unless the cell layouting object is actually interested in the
98 * widths of individual rows. The overall width is however stored
99 * in the accompanying #GtkCellAreaContext object and can be consulted
102 * This can be useful since #GtkCellLayout widgets usually have to
103 * support requesting and rendering rows in treemodels with an
104 * exceedingly large amount of rows. The #GtkCellLayout widget in
105 * that case would calculate the required width of the rows in an
106 * idle or timeout source (see g_timeout_add()) and when the widget
107 * is requested its actual width in #GtkWidgetClass.get_preferred_width()
108 * it can simply consult the width accumulated so far in the
109 * #GtkCellAreaContext object.
111 * A simple example where rows are rendered from top to bottom and
112 * take up the full width of the layouting widget would look like:
114 * <title>A typical get_preferred_width() implementation</title>
117 * foo_get_preferred_width (GtkWidget *widget,
118 * gint *minimum_size,
119 * gint *natural_size)
121 * Foo *foo = FOO (widget);
122 * FooPrivate *priv = foo->priv;
124 * foo_ensure_at_least_one_handfull_of_rows_have_been_requested (foo);
126 * gtk_cell_area_context_get_preferred_width (priv->context, minimum_size, natural_size);
130 * In the above example the Foo widget has to make sure that some
131 * row sizes have been calculated (the amount of rows that Foo judged
132 * was appropriate to request space for in a single timeout iteration)
133 * before simply returning the amount of space required by the area via
134 * the #GtkCellAreaContext.
136 * Requesting the height for width (or width for height) of an area is
137 * a similar task except in this case the #GtkCellAreaContext does not
138 * store the data (actually, it does not know how much space the layouting
139 * widget plans to allocate it for every row, it's up to the layouting
140 * widget to render each row of data with the appropriate height and
141 * width which was requested by the #GtkCellArea).
143 * In order to request the height for width of all the rows at the
144 * root level of a #GtkTreeModel one would do the following:
146 * <title>Requesting the height for width of a handful of GtkTreeModel rows</title>
149 * gint minimum_height;
150 * gint natural_height;
151 * gint full_minimum_height = 0;
152 * gint full_natural_height = 0;
154 * valid = gtk_tree_model_get_iter_first (model, &iter);
157 * gtk_cell_area_apply_attributes (area, model, &iter, FALSE, FALSE);
158 * gtk_cell_area_get_preferred_height_for_width (area, context, widget,
159 * width, &minimum_height, &natural_height);
161 * if (width_is_for_allocation)
162 * cache_row_height (&iter, minimum_height, natural_height);
164 * full_minimum_height += minimum_height;
165 * full_natural_height += natural_height;
167 * valid = gtk_tree_model_iter_next (model, &iter);
171 * Note that in the above example we would need to cache the heights
172 * returned for each row so that we would know what sizes to render the
173 * areas for each row. However we would only want to really cache the
174 * heights if the request is intended for the layouting widgets real
177 * In some cases the layouting widget is requested the height for an
178 * arbitrary for_width, this is a special case for layouting widgets
179 * who need to request size for tens of thousands of rows. For this
180 * case it's only important that the layouting widget calculate
181 * one reasonably sized chunk of rows and return that height
182 * synchronously. The reasoning here is that any layouting widget is
183 * at least capable of synchronously calculating enough height to fill
184 * the screen height (or scrolled window height) in response to a single
185 * call to #GtkWidgetClass.get_preferred_height_for_width(). Returning
186 * a perfect height for width that is larger than the screen area is
187 * inconsequential since after the layouting receives an allocation
188 * from a scrolled window it simply continues to drive the the scrollbar
189 * values while more and more height is required for the row heights
190 * that are calculated in the background.
193 * <refsect2 id="cell-area-rendering">
194 * <title>Rendering Areas</title>
196 * Once area sizes have been aquired at least for the rows in the
197 * visible area of the layouting widget they can be rendered at
198 * #GtkWidgetClass.draw() time.
200 * A crude example of how to render all the rows at the root level
203 * <title>Requesting the width of a handful of GtkTreeModel rows</title>
205 * GtkAllocation allocation;
206 * GdkRectangle cell_area = { 0, };
208 * gint minimum_width;
209 * gint natural_width;
211 * gtk_widget_get_allocation (widget, &allocation);
212 * cell_area.width = allocation.width;
214 * valid = gtk_tree_model_get_iter_first (model, &iter);
217 * cell_area.height = get_cached_height_for_row (&iter);
219 * gtk_cell_area_apply_attributes (area, model, &iter, FALSE, FALSE);
220 * gtk_cell_area_render (area, context, widget, cr,
221 * &cell_area, &cell_area, state_flags, FALSE);
223 * cell_area.y += cell_area.height;
225 * valid = gtk_tree_model_iter_next (model, &iter);
229 * Note that the cached height in this example really depends on how
230 * the layouting widget works. The layouting widget might decide to
231 * give every row it's minimum or natural height or, if the model content
232 * is expected to fit inside the layouting widget without scrolling, it
233 * would make sense to calculate the allocation for each row at
234 * #GtkWidget::size-allocate time using gtk_distribute_natural_allocation().
237 * <refsect2 id="cell-area-events-and-focus">
238 * <title>Handling Events and Driving Keyboard Focus</title>
240 * Passing events to the area is as simple as handling events on any
241 * normal widget and then passing them to the gtk_cell_area_event()
242 * API as they come in. Usually #GtkCellArea is only interested in
243 * button events, however some customized derived areas can be implemented
244 * who are interested in handling other events. Handling an event can
245 * trigger the #GtkCellArea::focus-changed signal to fire; as well as
246 * #GtkCellArea::add-editable in the case that an editable cell was
247 * clicked and needs to start editing. You can call
248 * gtk_cell_area_stop_editing() at any time to cancel any cell editing
249 * that is currently in progress.
251 * The #GtkCellArea drives keyboard focus from cell to cell in a way
252 * similar to #GtkWidget. For layouting widgets that support giving
253 * focus to cells it's important to remember to pass %GTK_CELL_RENDERER_FOCUSED
254 * to the area functions for the row that has focus and to tell the
255 * area to paint the focus at render time.
257 * Layouting widgets that accept focus on cells should implement the
258 * #GtkWidgetClass.focus() virtual method. The layouting widget is always
259 * responsible for knowing where #GtkTreeModel rows are rendered inside
260 * the widget, so at #GtkWidgetClass.focus() time the layouting widget
261 * should use the #GtkCellArea methods to navigate focus inside the area
262 * and then observe the GtkDirectionType to pass the focus to adjacent
265 * A basic example of how the #GtkWidgetClass.focus() virtual method
266 * should be implemented:
268 * <title>Implementing keyboard focus navigation</title>
271 * foo_focus (GtkWidget *widget,
272 * GtkDirectionType direction)
274 * Foo *foo = FOO (widget);
275 * FooPrivate *priv = foo->priv;
277 * gboolean have_focus = FALSE;
279 * focus_row = priv->focus_row;
281 * if (!gtk_widget_has_focus (widget))
282 * gtk_widget_grab_focus (widget);
284 * valid = gtk_tree_model_iter_nth_child (priv->model, &iter, NULL, priv->focus_row);
287 * gtk_cell_area_apply_attributes (priv->area, priv->model, &iter, FALSE, FALSE);
289 * if (gtk_cell_area_focus (priv->area, direction))
291 * priv->focus_row = focus_row;
297 * if (direction == GTK_DIR_RIGHT ||
298 * direction == GTK_DIR_LEFT)
300 * else if (direction == GTK_DIR_UP ||
301 * direction == GTK_DIR_TAB_BACKWARD)
303 * if (focus_row == 0)
308 * valid = gtk_tree_model_iter_nth_child (priv->model, &iter, NULL, focus_row);
313 * if (focus_row == last_row)
318 * valid = gtk_tree_model_iter_next (priv->model, &iter);
327 * Note that the layouting widget is responsible for matching the
328 * GtkDirectionType values to the way it lays out its cells.
331 * <refsect2 id="cell-properties">
332 * <title>Cell Properties</title>
334 * The #GtkCellArea introduces <emphasis>cell properties</emphasis>
335 * for #GtkCellRenderers in very much the same way that #GtkContainer
336 * introduces <link linkend="child-properties">child properties</link>
337 * for #GtkWidgets. This provides some general interfaces for defining
338 * the relationship cell areas have with their cells. For instance in a
339 * #GtkCellAreaBox a cell might "expand" and receive extra space when
340 * the area is allocated more than it's full natural request, or a cell
341 * might be configured to "align" with adjacent rows which were requested
342 * and rendered with the same #GtkCellAreaContext.
344 * Use gtk_cell_area_class_install_cell_property() to install cell
345 * properties for a cell area class and gtk_cell_area_class_find_cell_property()
346 * or gtk_cell_area_class_list_cell_properties() to get information about
347 * existing cell properties.
349 * To set the value of a cell property, use gtk_cell_area_cell_set_property(),
350 * gtk_cell_area_cell_set() or gtk_cell_area_cell_set_valist(). To obtain
351 * the value of a cell property, use gtk_cell_area_cell_get_property(),
352 * gtk_cell_area_cell_get() or gtk_cell_area_cell_get_valist().
364 #include "gtkcelllayout.h"
365 #include "gtkcellarea.h"
366 #include "gtkcellareacontext.h"
367 #include "gtkmarshalers.h"
368 #include "gtkprivate.h"
370 #include <gobject/gvaluecollector.h>
374 static void gtk_cell_area_dispose (GObject *object);
375 static void gtk_cell_area_finalize (GObject *object);
376 static void gtk_cell_area_set_property (GObject *object,
380 static void gtk_cell_area_get_property (GObject *object,
385 /* GtkCellAreaClass */
386 static gint gtk_cell_area_real_event (GtkCellArea *area,
387 GtkCellAreaContext *context,
390 const GdkRectangle *cell_area,
391 GtkCellRendererState flags);
392 static void gtk_cell_area_real_render (GtkCellArea *area,
393 GtkCellAreaContext *context,
396 const GdkRectangle *background_area,
397 const GdkRectangle *cell_area,
398 GtkCellRendererState flags,
399 gboolean paint_focus);
400 static void gtk_cell_area_real_apply_attributes (GtkCellArea *area,
401 GtkTreeModel *tree_model,
403 gboolean is_expander,
404 gboolean is_expanded);
405 static void gtk_cell_area_real_get_preferred_height_for_width (GtkCellArea *area,
406 GtkCellAreaContext *context,
409 gint *minimum_height,
410 gint *natural_height);
411 static void gtk_cell_area_real_get_preferred_width_for_height (GtkCellArea *area,
412 GtkCellAreaContext *context,
416 gint *natural_width);
417 static gboolean gtk_cell_area_real_is_activatable (GtkCellArea *area);
418 static gboolean gtk_cell_area_real_activate (GtkCellArea *area,
419 GtkCellAreaContext *context,
421 const GdkRectangle *cell_area,
422 GtkCellRendererState flags,
425 /* GtkCellLayoutIface */
426 static void gtk_cell_area_cell_layout_init (GtkCellLayoutIface *iface);
427 static void gtk_cell_area_pack_default (GtkCellLayout *cell_layout,
428 GtkCellRenderer *renderer,
430 static void gtk_cell_area_clear (GtkCellLayout *cell_layout);
431 static void gtk_cell_area_add_attribute (GtkCellLayout *cell_layout,
432 GtkCellRenderer *renderer,
433 const gchar *attribute,
435 static void gtk_cell_area_set_cell_data_func (GtkCellLayout *cell_layout,
436 GtkCellRenderer *cell,
437 GtkCellLayoutDataFunc func,
439 GDestroyNotify destroy);
440 static void gtk_cell_area_clear_attributes (GtkCellLayout *cell_layout,
441 GtkCellRenderer *renderer);
442 static void gtk_cell_area_reorder (GtkCellLayout *cell_layout,
443 GtkCellRenderer *cell,
445 static GList *gtk_cell_area_get_cells (GtkCellLayout *cell_layout);
446 static GtkCellArea *gtk_cell_area_get_area (GtkCellLayout *cell_layout);
448 /* GtkBuildableIface */
449 static void gtk_cell_area_buildable_init (GtkBuildableIface *iface);
450 static void gtk_cell_area_buildable_custom_tag_end (GtkBuildable *buildable,
453 const gchar *tagname,
456 /* Used in foreach loop to check if a child renderer is present */
458 GtkCellRenderer *renderer;
459 gboolean has_renderer;
462 /* Used in foreach loop to get a cell's allocation */
464 GtkCellRenderer *renderer;
465 GdkRectangle allocation;
466 } RendererAllocationData;
468 /* Used in foreach loop to render cells */
473 GdkRectangle focus_rect;
474 GtkCellRendererState render_flags;
475 guint paint_focus : 1;
477 guint first_focus : 1;
480 /* Used in foreach loop to get a cell by position */
484 GtkCellRenderer *renderer;
485 GdkRectangle cell_area;
486 } CellByPositionData;
488 /* Attribute/Cell metadata */
490 const gchar *attribute;
497 GtkCellLayoutDataFunc func;
499 GDestroyNotify destroy;
500 GtkCellLayout *proxy;
503 static CellInfo *cell_info_new (GtkCellLayoutDataFunc func,
505 GDestroyNotify destroy);
506 static void cell_info_free (CellInfo *info);
507 static CellAttribute *cell_attribute_new (GtkCellRenderer *renderer,
508 const gchar *attribute,
510 static void cell_attribute_free (CellAttribute *attribute);
511 static gint cell_attribute_find (CellAttribute *cell_attribute,
512 const gchar *attribute);
514 /* Internal functions/signal emissions */
515 static void gtk_cell_area_add_editable (GtkCellArea *area,
516 GtkCellRenderer *renderer,
517 GtkCellEditable *editable,
518 const GdkRectangle *cell_area);
519 static void gtk_cell_area_remove_editable (GtkCellArea *area,
520 GtkCellRenderer *renderer,
521 GtkCellEditable *editable);
522 static void gtk_cell_area_set_edit_widget (GtkCellArea *area,
523 GtkCellEditable *editable);
524 static void gtk_cell_area_set_edited_cell (GtkCellArea *area,
525 GtkCellRenderer *renderer);
528 /* Struct to pass data along while looping over
529 * cell renderers to apply attributes
535 gboolean is_expander;
536 gboolean is_expanded;
539 struct _GtkCellAreaPrivate
541 /* The GtkCellArea bookkeeps any connected
542 * attributes in this hash table.
544 GHashTable *cell_info;
546 /* Current path is saved as a side-effect
547 * of gtk_cell_area_apply_attributes()
551 /* Current cell being edited and editable widget used */
552 GtkCellEditable *edit_widget;
553 GtkCellRenderer *edited_cell;
555 /* Signal connections to the editable widget */
556 gulong remove_widget_id;
558 /* Currently focused cell */
559 GtkCellRenderer *focus_cell;
561 /* Tracking which cells are focus siblings of focusable cells */
562 GHashTable *focus_siblings;
573 SIGNAL_APPLY_ATTRIBUTES,
575 SIGNAL_REMOVE_EDITABLE,
576 SIGNAL_FOCUS_CHANGED,
580 /* Keep the paramspec pool internal, no need to deliver notifications
581 * on cells. at least no perceived need for now
583 static GParamSpecPool *cell_property_pool = NULL;
584 static guint cell_area_signals[LAST_SIGNAL] = { 0 };
586 #define PARAM_SPEC_PARAM_ID(pspec) ((pspec)->param_id)
587 #define PARAM_SPEC_SET_PARAM_ID(pspec, id) ((pspec)->param_id = (id))
589 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GtkCellArea, gtk_cell_area, G_TYPE_INITIALLY_UNOWNED,
590 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
591 gtk_cell_area_cell_layout_init)
592 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
593 gtk_cell_area_buildable_init))
596 gtk_cell_area_init (GtkCellArea *area)
598 GtkCellAreaPrivate *priv;
600 area->priv = G_TYPE_INSTANCE_GET_PRIVATE (area,
605 priv->cell_info = g_hash_table_new_full (g_direct_hash,
608 (GDestroyNotify)cell_info_free);
610 priv->focus_siblings = g_hash_table_new_full (g_direct_hash,
613 (GDestroyNotify)g_list_free);
615 priv->focus_cell = NULL;
616 priv->edited_cell = NULL;
617 priv->edit_widget = NULL;
619 priv->remove_widget_id = 0;
623 gtk_cell_area_class_init (GtkCellAreaClass *class)
625 GObjectClass *object_class = G_OBJECT_CLASS (class);
628 object_class->dispose = gtk_cell_area_dispose;
629 object_class->finalize = gtk_cell_area_finalize;
630 object_class->get_property = gtk_cell_area_get_property;
631 object_class->set_property = gtk_cell_area_set_property;
635 class->remove = NULL;
636 class->foreach = NULL;
637 class->event = gtk_cell_area_real_event;
638 class->render = gtk_cell_area_real_render;
639 class->apply_attributes = gtk_cell_area_real_apply_attributes;
642 class->create_context = NULL;
643 class->get_request_mode = NULL;
644 class->get_preferred_width = NULL;
645 class->get_preferred_height = NULL;
646 class->get_preferred_height_for_width = gtk_cell_area_real_get_preferred_height_for_width;
647 class->get_preferred_width_for_height = gtk_cell_area_real_get_preferred_width_for_height;
650 class->is_activatable = gtk_cell_area_real_is_activatable;
651 class->activate = gtk_cell_area_real_activate;
656 * GtkCellArea::apply-attributes:
657 * @area: the #GtkCellArea to apply the attributes to
658 * @model: the #GtkTreeModel to apply the attributes from
659 * @iter: the #GtkTreeIter indicating which row to apply the attributes of
660 * @is_expander: whether the view shows children for this row
661 * @is_expanded: whether the view is currently showing the children of this row
663 * This signal is emitted whenever applying attributes to @area from @model
667 cell_area_signals[SIGNAL_APPLY_ATTRIBUTES] =
668 g_signal_new (I_("apply-attributes"),
669 G_OBJECT_CLASS_TYPE (object_class),
671 G_STRUCT_OFFSET (GtkCellAreaClass, apply_attributes),
673 _gtk_marshal_VOID__OBJECT_BOXED_BOOLEAN_BOOLEAN,
681 * GtkCellArea::add-editable:
682 * @area: the #GtkCellArea where editing started
683 * @renderer: the #GtkCellRenderer that started the edited
684 * @editable: the #GtkCellEditable widget to add
685 * @cell_area: the #GtkWidget relative #GdkRectangle coordinates
686 * where @editable should be added
687 * @path: the #GtkTreePath string this edit was initiated for
689 * Indicates that editing has started on @renderer and that @editable
690 * should be added to the owning cell layouting widget at @cell_area.
694 cell_area_signals[SIGNAL_ADD_EDITABLE] =
695 g_signal_new (I_("add-editable"),
696 G_OBJECT_CLASS_TYPE (object_class),
698 0, /* No class closure here */
700 _gtk_marshal_VOID__OBJECT_OBJECT_BOXED_STRING,
702 GTK_TYPE_CELL_RENDERER,
703 GTK_TYPE_CELL_EDITABLE,
709 * GtkCellArea::remove-editable:
710 * @area: the #GtkCellArea where editing finished
711 * @renderer: the #GtkCellRenderer that finished editeding
712 * @editable: the #GtkCellEditable widget to remove
714 * Indicates that editing finished on @renderer and that @editable
715 * should be removed from the owning cell layouting widget.
719 cell_area_signals[SIGNAL_REMOVE_EDITABLE] =
720 g_signal_new (I_("remove-editable"),
721 G_OBJECT_CLASS_TYPE (object_class),
723 0, /* No class closure here */
725 _gtk_marshal_VOID__OBJECT_OBJECT,
727 GTK_TYPE_CELL_RENDERER,
728 GTK_TYPE_CELL_EDITABLE);
731 * GtkCellArea::focus-changed:
732 * @area: the #GtkCellArea where focus changed
733 * @renderer: the #GtkCellRenderer that has focus
734 * @path: the current #GtkTreePath string set for @area
736 * Indicates that focus changed on this @area. This signal
737 * is emitted either as a result of focus handling or event
740 * It's possible that the signal is emitted even if the
741 * currently focused renderer did not change, this is
742 * because focus may change to the same renderer in the
743 * same cell area for a different row of data.
747 cell_area_signals[SIGNAL_FOCUS_CHANGED] =
748 g_signal_new (I_("focus-changed"),
749 G_OBJECT_CLASS_TYPE (object_class),
751 0, /* No class closure here */
753 _gtk_marshal_VOID__OBJECT_STRING,
755 GTK_TYPE_CELL_RENDERER,
760 * GtkCellArea:focus-cell:
762 * The cell in the area that currently has focus
766 g_object_class_install_property (object_class,
771 P_("The cell which currently has focus"),
772 GTK_TYPE_CELL_RENDERER,
773 GTK_PARAM_READWRITE));
776 * GtkCellArea:edited-cell:
778 * The cell in the area that is currently edited
780 * This property is read-only and only changes as
781 * a result of a call gtk_cell_area_activate_cell().
785 g_object_class_install_property (object_class,
790 P_("The cell which is currently being edited"),
791 GTK_TYPE_CELL_RENDERER,
795 * GtkCellArea:edit-widget:
797 * The widget currently editing the edited cell
799 * This property is read-only and only changes as
800 * a result of a call gtk_cell_area_activate_cell().
804 g_object_class_install_property (object_class,
809 P_("The widget currently editing the edited cell"),
810 GTK_TYPE_CELL_EDITABLE,
813 /* Pool for Cell Properties */
814 if (!cell_property_pool)
815 cell_property_pool = g_param_spec_pool_new (FALSE);
817 g_type_class_add_private (object_class, sizeof (GtkCellAreaPrivate));
820 /*************************************************************
822 *************************************************************/
824 cell_info_new (GtkCellLayoutDataFunc func,
826 GDestroyNotify destroy)
828 CellInfo *info = g_slice_new0 (CellInfo);
832 info->destroy = destroy;
838 cell_info_free (CellInfo *info)
841 info->destroy (info->data);
843 g_slist_foreach (info->attributes, (GFunc)cell_attribute_free, NULL);
844 g_slist_free (info->attributes);
846 g_slice_free (CellInfo, info);
849 static CellAttribute *
850 cell_attribute_new (GtkCellRenderer *renderer,
851 const gchar *attribute,
856 /* Check if the attribute really exists and point to
857 * the property string installed on the cell renderer
858 * class (dont dup the string)
860 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (renderer), attribute);
864 CellAttribute *cell_attribute = g_slice_new (CellAttribute);
866 cell_attribute->attribute = pspec->name;
867 cell_attribute->column = column;
869 return cell_attribute;
876 cell_attribute_free (CellAttribute *attribute)
878 g_slice_free (CellAttribute, attribute);
881 /* GCompareFunc for g_slist_find_custom() */
883 cell_attribute_find (CellAttribute *cell_attribute,
884 const gchar *attribute)
886 return g_strcmp0 (cell_attribute->attribute, attribute);
889 /*************************************************************
891 *************************************************************/
893 gtk_cell_area_finalize (GObject *object)
895 GtkCellArea *area = GTK_CELL_AREA (object);
896 GtkCellAreaPrivate *priv = area->priv;
898 /* All cell renderers should already be removed at this point,
899 * just kill our (empty) hash tables here.
901 g_hash_table_destroy (priv->cell_info);
902 g_hash_table_destroy (priv->focus_siblings);
904 g_free (priv->current_path);
906 G_OBJECT_CLASS (gtk_cell_area_parent_class)->finalize (object);
911 gtk_cell_area_dispose (GObject *object)
913 /* This removes every cell renderer that may be added to the GtkCellArea,
914 * subclasses should be breaking references to the GtkCellRenderers
917 gtk_cell_layout_clear (GTK_CELL_LAYOUT (object));
919 /* Remove any ref to a focused/edited cell */
920 gtk_cell_area_set_focus_cell (GTK_CELL_AREA (object), NULL);
921 gtk_cell_area_set_edited_cell (GTK_CELL_AREA (object), NULL);
922 gtk_cell_area_set_edit_widget (GTK_CELL_AREA (object), NULL);
924 G_OBJECT_CLASS (gtk_cell_area_parent_class)->dispose (object);
928 gtk_cell_area_set_property (GObject *object,
933 GtkCellArea *area = GTK_CELL_AREA (object);
937 case PROP_FOCUS_CELL:
938 gtk_cell_area_set_focus_cell (area, (GtkCellRenderer *)g_value_get_object (value));
941 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
947 gtk_cell_area_get_property (GObject *object,
952 GtkCellArea *area = GTK_CELL_AREA (object);
953 GtkCellAreaPrivate *priv = area->priv;
957 case PROP_FOCUS_CELL:
958 g_value_set_object (value, priv->focus_cell);
960 case PROP_EDITED_CELL:
961 g_value_set_object (value, priv->edited_cell);
963 case PROP_EDIT_WIDGET:
964 g_value_set_object (value, priv->edit_widget);
967 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
972 /*************************************************************
974 *************************************************************/
976 gtk_cell_area_real_event (GtkCellArea *area,
977 GtkCellAreaContext *context,
980 const GdkRectangle *cell_area,
981 GtkCellRendererState flags)
983 GtkCellAreaPrivate *priv = area->priv;
984 gboolean retval = FALSE;
986 if (event->type == GDK_KEY_PRESS && (flags & GTK_CELL_RENDERER_FOCUSED) != 0)
988 GdkEventKey *key_event = (GdkEventKey *)event;
990 /* Cancel any edits in progress */
991 if (priv->edited_cell && (key_event->keyval == GDK_KEY_Escape))
993 gtk_cell_area_stop_editing (area, TRUE);
997 else if (event->type == GDK_BUTTON_PRESS)
999 GdkEventButton *button_event = (GdkEventButton *)event;
1001 if (button_event->button == 1)
1003 GtkCellRenderer *renderer = NULL;
1004 GtkCellRenderer *focus_renderer;
1005 GdkRectangle alloc_area;
1006 gint event_x, event_y;
1008 /* We may need some semantics to tell us the offset of the event
1009 * window we are handling events for (i.e. GtkTreeView has a bin_window) */
1010 event_x = button_event->x;
1011 event_y = button_event->y;
1013 /* Dont try to search for an event coordinate that is not in the area, that will
1014 * trigger a runtime warning.
1016 if (event_x >= cell_area->x && event_x <= cell_area->x + cell_area->width &&
1017 event_y >= cell_area->y && event_y <= cell_area->y + cell_area->height)
1019 gtk_cell_area_get_cell_at_position (area, context, widget,
1020 cell_area, event_x, event_y,
1025 focus_renderer = gtk_cell_area_get_focus_from_sibling (area, renderer);
1026 if (!focus_renderer)
1027 focus_renderer = renderer;
1029 /* If we're already editing, cancel it and set focus */
1030 if (gtk_cell_area_get_edited_cell (area))
1032 /* XXX Was it really canceled in this case ? */
1033 gtk_cell_area_stop_editing (area, TRUE);
1034 gtk_cell_area_set_focus_cell (area, focus_renderer);
1039 /* If we are activating via a focus sibling,
1040 * we need to fetch the right cell area for the real event renderer */
1041 if (focus_renderer != renderer)
1042 gtk_cell_area_get_cell_allocation (area, context, widget, focus_renderer,
1043 cell_area, &alloc_area);
1045 gtk_cell_area_set_focus_cell (area, focus_renderer);
1046 retval = gtk_cell_area_activate_cell (area, widget, focus_renderer,
1047 event, &alloc_area, flags);
1057 render_cell (GtkCellRenderer *renderer,
1058 const GdkRectangle *cell_area,
1059 const GdkRectangle *cell_background,
1060 CellRenderData *data)
1062 GtkCellRenderer *focus_cell;
1063 GtkCellRendererState flags;
1064 GdkRectangle inner_area;
1066 focus_cell = gtk_cell_area_get_focus_cell (data->area);
1067 flags = data->render_flags;
1069 gtk_cell_area_inner_cell_area (data->area, data->widget, cell_area, &inner_area);
1071 if ((flags & GTK_CELL_RENDERER_FOCUSED) &&
1074 (renderer == focus_cell ||
1075 gtk_cell_area_is_focus_sibling (data->area, focus_cell, renderer)))))
1077 gint focus_line_width;
1078 GdkRectangle cell_focus;
1080 gtk_cell_renderer_get_aligned_area (renderer, data->widget, flags, &inner_area, &cell_focus);
1082 gtk_widget_style_get (data->widget,
1083 "focus-line-width", &focus_line_width,
1086 /* The focus rectangle is located around the aligned area of the cell */
1087 cell_focus.x -= focus_line_width;
1088 cell_focus.y -= focus_line_width;
1089 cell_focus.width += 2 * focus_line_width;
1090 cell_focus.height += 2 * focus_line_width;
1092 if (data->first_focus)
1094 data->first_focus = FALSE;
1095 data->focus_rect = cell_focus;
1099 gdk_rectangle_union (&data->focus_rect, &cell_focus, &data->focus_rect);
1103 gtk_cell_renderer_render (renderer, data->cr, data->widget,
1104 cell_background, &inner_area, flags);
1110 gtk_cell_area_real_render (GtkCellArea *area,
1111 GtkCellAreaContext *context,
1114 const GdkRectangle *background_area,
1115 const GdkRectangle *cell_area,
1116 GtkCellRendererState flags,
1117 gboolean paint_focus)
1119 CellRenderData render_data =
1130 /* Make sure we dont paint a focus rectangle while there
1131 * is an editable widget in play
1133 if (gtk_cell_area_get_edited_cell (area))
1134 render_data.paint_focus = FALSE;
1136 /* If no cell can activate but the caller wants focus painted,
1137 * then we paint focus around all cells */
1138 if ((flags & GTK_CELL_RENDERER_FOCUSED) != 0 && paint_focus &&
1139 !gtk_cell_area_is_activatable (area))
1140 render_data.focus_all = TRUE;
1142 gtk_cell_area_foreach_alloc (area, context, widget, cell_area, background_area,
1143 (GtkCellAllocCallback)render_cell, &render_data);
1145 if (render_data.paint_focus &&
1146 render_data.focus_rect.width != 0 &&
1147 render_data.focus_rect.height != 0)
1149 GtkStyleContext *style_context;
1150 GtkStateFlags renderer_state = 0;
1152 style_context = gtk_widget_get_style_context (widget);
1153 gtk_style_context_save (style_context);
1155 renderer_state = gtk_cell_renderer_get_state (NULL, widget, flags);
1156 gtk_style_context_set_state (style_context, renderer_state);
1160 gdk_cairo_rectangle (cr, background_area);
1163 gtk_render_focus (style_context, cr,
1164 render_data.focus_rect.x, render_data.focus_rect.y,
1165 render_data.focus_rect.width, render_data.focus_rect.height);
1167 gtk_style_context_restore (style_context);
1173 apply_cell_attributes (GtkCellRenderer *renderer,
1175 AttributeData *data)
1177 CellAttribute *attribute;
1179 GValue value = { 0, };
1180 gboolean is_expander;
1181 gboolean is_expanded;
1183 g_object_freeze_notify (G_OBJECT (renderer));
1185 /* Whether a row expands or is presently expanded can only be
1186 * provided by the view (as these states can vary across views
1187 * accessing the same model).
1189 g_object_get (renderer, "is-expander", &is_expander, NULL);
1190 if (is_expander != data->is_expander)
1191 g_object_set (renderer, "is-expander", data->is_expander, NULL);
1193 g_object_get (renderer, "is-expanded", &is_expanded, NULL);
1194 if (is_expanded != data->is_expanded)
1195 g_object_set (renderer, "is-expanded", data->is_expanded, NULL);
1197 /* Apply the attributes directly to the renderer */
1198 for (list = info->attributes; list; list = list->next)
1200 attribute = list->data;
1202 gtk_tree_model_get_value (data->model, data->iter, attribute->column, &value);
1203 g_object_set_property (G_OBJECT (renderer), attribute->attribute, &value);
1204 g_value_unset (&value);
1207 /* Call any GtkCellLayoutDataFunc that may have been set by the user
1210 info->func (info->proxy ? info->proxy : GTK_CELL_LAYOUT (data->area), renderer,
1211 data->model, data->iter, info->data);
1213 g_object_thaw_notify (G_OBJECT (renderer));
1217 gtk_cell_area_real_apply_attributes (GtkCellArea *area,
1218 GtkTreeModel *tree_model,
1220 gboolean is_expander,
1221 gboolean is_expanded)
1224 GtkCellAreaPrivate *priv;
1230 /* Feed in data needed to apply to every renderer */
1232 data.model = tree_model;
1234 data.is_expander = is_expander;
1235 data.is_expanded = is_expanded;
1237 /* Go over any cells that have attributes or custom GtkCellLayoutDataFuncs and
1238 * apply the data from the treemodel */
1239 g_hash_table_foreach (priv->cell_info, (GHFunc)apply_cell_attributes, &data);
1241 /* Update the currently applied path */
1242 g_free (priv->current_path);
1243 path = gtk_tree_model_get_path (tree_model, iter);
1244 priv->current_path = gtk_tree_path_to_string (path);
1245 gtk_tree_path_free (path);
1249 gtk_cell_area_real_get_preferred_height_for_width (GtkCellArea *area,
1250 GtkCellAreaContext *context,
1253 gint *minimum_height,
1254 gint *natural_height)
1256 /* If the area doesnt do height-for-width, fallback on base preferred height */
1257 GTK_CELL_AREA_GET_CLASS (area)->get_preferred_width (area, context, widget, minimum_height, natural_height);
1261 gtk_cell_area_real_get_preferred_width_for_height (GtkCellArea *area,
1262 GtkCellAreaContext *context,
1265 gint *minimum_width,
1266 gint *natural_width)
1268 /* If the area doesnt do width-for-height, fallback on base preferred width */
1269 GTK_CELL_AREA_GET_CLASS (area)->get_preferred_width (area, context, widget, minimum_width, natural_width);
1273 get_is_activatable (GtkCellRenderer *renderer,
1274 gboolean *activatable)
1277 if (gtk_cell_renderer_is_activatable (renderer))
1278 *activatable = TRUE;
1280 return *activatable;
1284 gtk_cell_area_real_is_activatable (GtkCellArea *area)
1286 gboolean activatable = FALSE;
1288 /* Checks if any renderer can focus for the currently applied
1291 * Subclasses can override this in the case that they are also
1292 * rendering widgets as well as renderers.
1294 gtk_cell_area_foreach (area, (GtkCellCallback)get_is_activatable, &activatable);
1300 gtk_cell_area_real_activate (GtkCellArea *area,
1301 GtkCellAreaContext *context,
1303 const GdkRectangle *cell_area,
1304 GtkCellRendererState flags,
1307 GtkCellAreaPrivate *priv = area->priv;
1308 GdkRectangle renderer_area;
1309 GtkCellRenderer *activate_cell = NULL;
1310 GtkCellRendererMode mode;
1312 if (priv->focus_cell)
1314 g_object_get (priv->focus_cell, "mode", &mode, NULL);
1316 if (gtk_cell_renderer_get_visible (priv->focus_cell) &&
1317 (edit_only ? mode == GTK_CELL_RENDERER_MODE_EDITABLE :
1318 mode != GTK_CELL_RENDERER_MODE_INERT))
1319 activate_cell = priv->focus_cell;
1325 /* GtkTreeView sometimes wants to activate a cell when no
1326 * cells are in focus.
1328 cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (area));
1329 for (l = cells; l && !activate_cell; l = l->next)
1331 GtkCellRenderer *renderer = l->data;
1333 g_object_get (renderer, "mode", &mode, NULL);
1335 if (gtk_cell_renderer_get_visible (renderer) &&
1336 (edit_only ? mode == GTK_CELL_RENDERER_MODE_EDITABLE :
1337 mode != GTK_CELL_RENDERER_MODE_INERT))
1338 activate_cell = renderer;
1340 g_list_free (cells);
1345 /* Get the allocation of the focused cell.
1347 gtk_cell_area_get_cell_allocation (area, context, widget, activate_cell,
1348 cell_area, &renderer_area);
1350 /* Activate or Edit the cell
1352 * Currently just not sending an event, renderers afaics dont use
1353 * the event argument anyway, worst case is we can synthesize one.
1355 if (gtk_cell_area_activate_cell (area, widget, activate_cell, NULL,
1356 &renderer_area, flags))
1363 /*************************************************************
1364 * GtkCellLayoutIface *
1365 *************************************************************/
1367 gtk_cell_area_cell_layout_init (GtkCellLayoutIface *iface)
1369 iface->pack_start = gtk_cell_area_pack_default;
1370 iface->pack_end = gtk_cell_area_pack_default;
1371 iface->clear = gtk_cell_area_clear;
1372 iface->add_attribute = gtk_cell_area_add_attribute;
1373 iface->set_cell_data_func = gtk_cell_area_set_cell_data_func;
1374 iface->clear_attributes = gtk_cell_area_clear_attributes;
1375 iface->reorder = gtk_cell_area_reorder;
1376 iface->get_cells = gtk_cell_area_get_cells;
1377 iface->get_area = gtk_cell_area_get_area;
1381 gtk_cell_area_pack_default (GtkCellLayout *cell_layout,
1382 GtkCellRenderer *renderer,
1385 gtk_cell_area_add (GTK_CELL_AREA (cell_layout), renderer);
1389 gtk_cell_area_clear (GtkCellLayout *cell_layout)
1391 GtkCellArea *area = GTK_CELL_AREA (cell_layout);
1393 gtk_cell_layout_get_cells (cell_layout);
1395 for (l = cells; l; l = l->next)
1397 GtkCellRenderer *renderer = l->data;
1398 gtk_cell_area_remove (area, renderer);
1401 g_list_free (cells);
1405 gtk_cell_area_add_attribute (GtkCellLayout *cell_layout,
1406 GtkCellRenderer *renderer,
1407 const gchar *attribute,
1410 gtk_cell_area_attribute_connect (GTK_CELL_AREA (cell_layout),
1411 renderer, attribute, column);
1415 gtk_cell_area_set_cell_data_func (GtkCellLayout *cell_layout,
1416 GtkCellRenderer *renderer,
1417 GtkCellLayoutDataFunc func,
1419 GDestroyNotify destroy)
1421 GtkCellArea *area = GTK_CELL_AREA (cell_layout);
1423 _gtk_cell_area_set_cell_data_func_with_proxy (area, renderer, (GFunc)func, func_data, destroy, NULL);
1427 gtk_cell_area_clear_attributes (GtkCellLayout *cell_layout,
1428 GtkCellRenderer *renderer)
1430 GtkCellArea *area = GTK_CELL_AREA (cell_layout);
1431 GtkCellAreaPrivate *priv = area->priv;
1434 info = g_hash_table_lookup (priv->cell_info, renderer);
1438 g_slist_foreach (info->attributes, (GFunc)cell_attribute_free, NULL);
1439 g_slist_free (info->attributes);
1441 info->attributes = NULL;
1446 gtk_cell_area_reorder (GtkCellLayout *cell_layout,
1447 GtkCellRenderer *cell,
1450 g_warning ("GtkCellLayout::reorder not implemented for `%s'",
1451 g_type_name (G_TYPE_FROM_INSTANCE (cell_layout)));
1455 accum_cells (GtkCellRenderer *renderer,
1458 *accum = g_list_prepend (*accum, renderer);
1464 gtk_cell_area_get_cells (GtkCellLayout *cell_layout)
1466 GList *cells = NULL;
1468 gtk_cell_area_foreach (GTK_CELL_AREA (cell_layout),
1469 (GtkCellCallback)accum_cells,
1472 return g_list_reverse (cells);
1475 static GtkCellArea *
1476 gtk_cell_area_get_area (GtkCellLayout *cell_layout)
1478 return GTK_CELL_AREA (cell_layout);
1481 /*************************************************************
1482 * GtkBuildableIface *
1483 *************************************************************/
1485 gtk_cell_area_buildable_init (GtkBuildableIface *iface)
1487 iface->add_child = _gtk_cell_layout_buildable_add_child;
1488 iface->custom_tag_start = _gtk_cell_layout_buildable_custom_tag_start;
1489 iface->custom_tag_end = gtk_cell_area_buildable_custom_tag_end;
1493 gtk_cell_area_buildable_custom_tag_end (GtkBuildable *buildable,
1494 GtkBuilder *builder,
1496 const gchar *tagname,
1499 /* Just ignore the boolean return from here */
1500 _gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname, data);
1503 /*************************************************************
1505 *************************************************************/
1508 * gtk_cell_area_add:
1509 * @area: a #GtkCellArea
1510 * @renderer: the #GtkCellRenderer to add to @area
1512 * Adds @renderer to @area with the default child cell properties.
1517 gtk_cell_area_add (GtkCellArea *area,
1518 GtkCellRenderer *renderer)
1520 GtkCellAreaClass *class;
1522 g_return_if_fail (GTK_IS_CELL_AREA (area));
1523 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1525 class = GTK_CELL_AREA_GET_CLASS (area);
1528 class->add (area, renderer);
1530 g_warning ("GtkCellAreaClass::add not implemented for `%s'",
1531 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1535 * gtk_cell_area_remove:
1536 * @area: a #GtkCellArea
1537 * @renderer: the #GtkCellRenderer to remove from @area
1539 * Removes @renderer from @area.
1544 gtk_cell_area_remove (GtkCellArea *area,
1545 GtkCellRenderer *renderer)
1547 GtkCellAreaClass *class;
1548 GtkCellAreaPrivate *priv;
1549 GList *renderers, *l;
1551 g_return_if_fail (GTK_IS_CELL_AREA (area));
1552 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1554 class = GTK_CELL_AREA_GET_CLASS (area);
1557 /* Remove any custom attributes and custom cell data func here first */
1558 g_hash_table_remove (priv->cell_info, renderer);
1560 /* Remove focus siblings of this renderer */
1561 g_hash_table_remove (priv->focus_siblings, renderer);
1563 /* Remove this renderer from any focus renderer's sibling list */
1564 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (area));
1566 for (l = renderers; l; l = l->next)
1568 GtkCellRenderer *focus_renderer = l->data;
1570 if (gtk_cell_area_is_focus_sibling (area, focus_renderer, renderer))
1572 gtk_cell_area_remove_focus_sibling (area, focus_renderer, renderer);
1577 g_list_free (renderers);
1580 class->remove (area, renderer);
1582 g_warning ("GtkCellAreaClass::remove not implemented for `%s'",
1583 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1587 get_has_renderer (GtkCellRenderer *renderer,
1588 HasRendererCheck *check)
1590 if (renderer == check->renderer)
1591 check->has_renderer = TRUE;
1593 return check->has_renderer;
1597 * gtk_cell_area_has_renderer:
1598 * @area: a #GtkCellArea
1599 * @renderer: the #GtkCellRenderer to check
1601 * Checks if @area contains @renderer.
1603 * Return value: %TRUE if @renderer is in the @area.
1608 gtk_cell_area_has_renderer (GtkCellArea *area,
1609 GtkCellRenderer *renderer)
1611 HasRendererCheck check = { renderer, FALSE };
1613 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
1614 g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), FALSE);
1616 gtk_cell_area_foreach (area, (GtkCellCallback)get_has_renderer, &check);
1618 return check.has_renderer;
1622 * gtk_cell_area_foreach:
1623 * @area: a #GtkCellArea
1624 * @callback: (scope call): the #GtkCellCallback to call
1625 * @callback_data: user provided data pointer
1627 * Calls @callback for every #GtkCellRenderer in @area.
1632 gtk_cell_area_foreach (GtkCellArea *area,
1633 GtkCellCallback callback,
1634 gpointer callback_data)
1636 GtkCellAreaClass *class;
1638 g_return_if_fail (GTK_IS_CELL_AREA (area));
1639 g_return_if_fail (callback != NULL);
1641 class = GTK_CELL_AREA_GET_CLASS (area);
1644 class->foreach (area, callback, callback_data);
1646 g_warning ("GtkCellAreaClass::foreach not implemented for `%s'",
1647 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1651 * gtk_cell_area_foreach_alloc:
1652 * @area: a #GtkCellArea
1653 * @context: the #GtkCellAreaContext for this row of data.
1654 * @widget: the #GtkWidget that @area is rendering to
1655 * @cell_area: the @widget relative coordinates and size for @area
1656 * @background_area: the @widget relative coordinates of the background area
1657 * @callback: (scope call): the #GtkCellAllocCallback to call
1658 * @callback_data: user provided data pointer
1660 * Calls @callback for every #GtkCellRenderer in @area with the
1661 * allocated rectangle inside @cell_area.
1666 gtk_cell_area_foreach_alloc (GtkCellArea *area,
1667 GtkCellAreaContext *context,
1669 const GdkRectangle *cell_area,
1670 const GdkRectangle *background_area,
1671 GtkCellAllocCallback callback,
1672 gpointer callback_data)
1674 GtkCellAreaClass *class;
1676 g_return_if_fail (GTK_IS_CELL_AREA (area));
1677 g_return_if_fail (GTK_IS_CELL_AREA_CONTEXT (context));
1678 g_return_if_fail (GTK_IS_WIDGET (widget));
1679 g_return_if_fail (cell_area != NULL);
1680 g_return_if_fail (callback != NULL);
1682 class = GTK_CELL_AREA_GET_CLASS (area);
1684 if (class->foreach_alloc)
1685 class->foreach_alloc (area, context, widget, cell_area, background_area, callback, callback_data);
1687 g_warning ("GtkCellAreaClass::foreach_alloc not implemented for `%s'",
1688 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1692 * gtk_cell_area_event:
1693 * @area: a #GtkCellArea
1694 * @context: the #GtkCellAreaContext for this row of data.
1695 * @widget: the #GtkWidget that @area is rendering to
1696 * @event: the #GdkEvent to handle
1697 * @cell_area: the @widget relative coordinates for @area
1698 * @flags: the #GtkCellRendererState for @area in this row.
1700 * Delegates event handling to a #GtkCellArea.
1702 * Return value: %TRUE if the event was handled by @area.
1707 gtk_cell_area_event (GtkCellArea *area,
1708 GtkCellAreaContext *context,
1711 const GdkRectangle *cell_area,
1712 GtkCellRendererState flags)
1714 GtkCellAreaClass *class;
1716 g_return_val_if_fail (GTK_IS_CELL_AREA (area), 0);
1717 g_return_val_if_fail (GTK_IS_CELL_AREA_CONTEXT (context), 0);
1718 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
1719 g_return_val_if_fail (event != NULL, 0);
1720 g_return_val_if_fail (cell_area != NULL, 0);
1722 class = GTK_CELL_AREA_GET_CLASS (area);
1725 return class->event (area, context, widget, event, cell_area, flags);
1727 g_warning ("GtkCellAreaClass::event not implemented for `%s'",
1728 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1733 * gtk_cell_area_render:
1734 * @area: a #GtkCellArea
1735 * @context: the #GtkCellAreaContext for this row of data.
1736 * @widget: the #GtkWidget that @area is rendering to
1737 * @cr: the #cairo_t to render with
1738 * @background_area: the @widget relative coordinates for @area's background
1739 * @cell_area: the @widget relative coordinates for @area
1740 * @flags: the #GtkCellRendererState for @area in this row.
1741 * @paint_focus: whether @area should paint focus on focused cells for focused rows or not.
1743 * Renders @area's cells according to @area's layout onto @widget at
1744 * the given coordinates.
1749 gtk_cell_area_render (GtkCellArea *area,
1750 GtkCellAreaContext *context,
1753 const GdkRectangle *background_area,
1754 const GdkRectangle *cell_area,
1755 GtkCellRendererState flags,
1756 gboolean paint_focus)
1758 GtkCellAreaClass *class;
1760 g_return_if_fail (GTK_IS_CELL_AREA (area));
1761 g_return_if_fail (GTK_IS_CELL_AREA_CONTEXT (context));
1762 g_return_if_fail (GTK_IS_WIDGET (widget));
1763 g_return_if_fail (cr != NULL);
1764 g_return_if_fail (background_area != NULL);
1765 g_return_if_fail (cell_area != NULL);
1767 class = GTK_CELL_AREA_GET_CLASS (area);
1770 class->render (area, context, widget, cr, background_area, cell_area, flags, paint_focus);
1772 g_warning ("GtkCellAreaClass::render not implemented for `%s'",
1773 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1777 get_cell_allocation (GtkCellRenderer *renderer,
1778 const GdkRectangle *cell_area,
1779 const GdkRectangle *cell_background,
1780 RendererAllocationData *data)
1782 if (data->renderer == renderer)
1783 data->allocation = *cell_area;
1785 return (data->renderer == renderer);
1789 * gtk_cell_area_get_cell_allocation:
1790 * @area: a #GtkCellArea
1791 * @context: the #GtkCellAreaContext used to hold sizes for @area.
1792 * @widget: the #GtkWidget that @area is rendering on
1793 * @renderer: the #GtkCellRenderer to get the allocation for
1794 * @cell_area: the whole allocated area for @area in @widget
1796 * @allocation: (out): where to store the allocation for @renderer
1798 * Derives the allocation of @renderer inside @area if @area
1799 * were to be renderered in @cell_area.
1804 gtk_cell_area_get_cell_allocation (GtkCellArea *area,
1805 GtkCellAreaContext *context,
1807 GtkCellRenderer *renderer,
1808 const GdkRectangle *cell_area,
1809 GdkRectangle *allocation)
1811 RendererAllocationData data = { renderer, { 0, } };
1813 g_return_if_fail (GTK_IS_CELL_AREA (area));
1814 g_return_if_fail (GTK_IS_CELL_AREA_CONTEXT (context));
1815 g_return_if_fail (GTK_IS_WIDGET (widget));
1816 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1817 g_return_if_fail (cell_area != NULL);
1818 g_return_if_fail (allocation != NULL);
1820 gtk_cell_area_foreach_alloc (area, context, widget, cell_area, cell_area,
1821 (GtkCellAllocCallback)get_cell_allocation, &data);
1823 *allocation = data.allocation;
1827 get_cell_by_position (GtkCellRenderer *renderer,
1828 const GdkRectangle *cell_area,
1829 const GdkRectangle *cell_background,
1830 CellByPositionData *data)
1832 if (data->x >= cell_area->x && data->x < cell_area->x + cell_area->width &&
1833 data->y >= cell_area->y && data->y < cell_area->y + cell_area->height)
1835 data->renderer = renderer;
1836 data->cell_area = *cell_area;
1839 return (data->renderer != NULL);
1843 * gtk_cell_area_get_cell_at_position:
1844 * @area: a #GtkCellArea
1845 * @context: the #GtkCellAreaContext used to hold sizes for @area.
1846 * @widget: the #GtkWidget that @area is rendering on
1847 * @cell_area: the whole allocated area for @area in @widget
1849 * @x: the x position
1850 * @y: the y position
1851 * @alloc_area: (out) (allow-none): where to store the inner allocated area of the
1852 * returned cell renderer, or %NULL.
1854 * Gets the #GtkCellRenderer at @x and @y coordinates inside @area and optionally
1855 * returns the full cell allocation for it inside @cell_area.
1857 * Return value: (transfer none): the #GtkCellRenderer at @x and @y.
1862 gtk_cell_area_get_cell_at_position (GtkCellArea *area,
1863 GtkCellAreaContext *context,
1865 const GdkRectangle *cell_area,
1868 GdkRectangle *alloc_area)
1870 CellByPositionData data = { x, y, NULL, { 0, } };
1872 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
1873 g_return_val_if_fail (GTK_IS_CELL_AREA_CONTEXT (context), NULL);
1874 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1875 g_return_val_if_fail (cell_area != NULL, NULL);
1876 g_return_val_if_fail (x >= cell_area->x && x <= cell_area->x + cell_area->width, NULL);
1877 g_return_val_if_fail (y >= cell_area->y && y <= cell_area->y + cell_area->height, NULL);
1879 gtk_cell_area_foreach_alloc (area, context, widget, cell_area, cell_area,
1880 (GtkCellAllocCallback)get_cell_by_position, &data);
1883 *alloc_area = data.cell_area;
1885 return data.renderer;
1888 /*************************************************************
1890 *************************************************************/
1892 * gtk_cell_area_create_context:
1893 * @area: a #GtkCellArea
1895 * Creates a #GtkCellAreaContext to be used with @area for
1896 * all purposes. #GtkCellAreaContext stores geometry information
1897 * for rows for which it was operated on, it is important to use
1898 * the same context for the same row of data at all times (i.e.
1899 * one should render and handle events with the same #GtkCellAreaContext
1900 * which was used to request the size of those rows of data).
1902 * Return value: (transfer full): a newly created #GtkCellAreaContext which can be used with @area.
1906 GtkCellAreaContext *
1907 gtk_cell_area_create_context (GtkCellArea *area)
1909 GtkCellAreaClass *class;
1911 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
1913 class = GTK_CELL_AREA_GET_CLASS (area);
1915 if (class->create_context)
1916 return class->create_context (area);
1918 g_warning ("GtkCellAreaClass::create_context not implemented for `%s'",
1919 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1925 * gtk_cell_area_copy_context:
1926 * @area: a #GtkCellArea
1927 * @context: the #GtkCellAreaContext to copy
1929 * This is sometimes needed for cases where rows need to share
1930 * alignments in one orientation but may be separately grouped
1931 * in the opposing orientation.
1933 * For instance, #GtkIconView creates all icons (rows) to have
1934 * the same width and the cells theirin to have the same
1935 * horizontal alignments. However each row of icons may have
1936 * a separate collective height. #GtkIconView uses this to
1937 * request the heights of each row based on a context which
1938 * was already used to request all the row widths that are
1941 * Return value: (transfer full): a newly created #GtkCellAreaContext copy of @context.
1945 GtkCellAreaContext *
1946 gtk_cell_area_copy_context (GtkCellArea *area,
1947 GtkCellAreaContext *context)
1949 GtkCellAreaClass *class;
1951 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
1952 g_return_val_if_fail (GTK_IS_CELL_AREA_CONTEXT (context), NULL);
1954 class = GTK_CELL_AREA_GET_CLASS (area);
1956 if (class->copy_context)
1957 return class->copy_context (area, context);
1959 g_warning ("GtkCellAreaClass::copy_context not implemented for `%s'",
1960 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1966 * gtk_cell_area_get_request_mode:
1967 * @area: a #GtkCellArea
1969 * Gets whether the area prefers a height-for-width layout
1970 * or a width-for-height layout.
1972 * Return value: The #GtkSizeRequestMode preferred by @area.
1977 gtk_cell_area_get_request_mode (GtkCellArea *area)
1979 GtkCellAreaClass *class;
1981 g_return_val_if_fail (GTK_IS_CELL_AREA (area),
1982 GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH);
1984 class = GTK_CELL_AREA_GET_CLASS (area);
1986 if (class->get_request_mode)
1987 return class->get_request_mode (area);
1989 g_warning ("GtkCellAreaClass::get_request_mode not implemented for `%s'",
1990 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1992 return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
1996 * gtk_cell_area_get_preferred_width:
1997 * @area: a #GtkCellArea
1998 * @context: the #GtkCellAreaContext to perform this request with
1999 * @widget: the #GtkWidget where @area will be rendering
2000 * @minimum_width: (out) (allow-none): location to store the minimum width, or %NULL
2001 * @natural_width: (out) (allow-none): location to store the natural width, or %NULL
2003 * Retrieves a cell area's initial minimum and natural width.
2005 * @area will store some geometrical information in @context along the way,
2006 * when requesting sizes over an arbitrary number of rows, its not important
2007 * to check the @minimum_width and @natural_width of this call but rather to
2008 * consult gtk_cell_area_context_get_preferred_width() after a series of
2014 gtk_cell_area_get_preferred_width (GtkCellArea *area,
2015 GtkCellAreaContext *context,
2017 gint *minimum_width,
2018 gint *natural_width)
2020 GtkCellAreaClass *class;
2022 g_return_if_fail (GTK_IS_CELL_AREA (area));
2023 g_return_if_fail (GTK_IS_WIDGET (widget));
2025 class = GTK_CELL_AREA_GET_CLASS (area);
2027 if (class->get_preferred_width)
2028 class->get_preferred_width (area, context, widget, minimum_width, natural_width);
2030 g_warning ("GtkCellAreaClass::get_preferred_width not implemented for `%s'",
2031 g_type_name (G_TYPE_FROM_INSTANCE (area)));
2035 * gtk_cell_area_get_preferred_height_for_width:
2036 * @area: a #GtkCellArea
2037 * @context: the #GtkCellAreaContext which has already been requested for widths.
2038 * @widget: the #GtkWidget where @area will be rendering
2039 * @width: the width for which to check the height of this area
2040 * @minimum_height: (out) (allow-none): location to store the minimum height, or %NULL
2041 * @natural_height: (out) (allow-none): location to store the natural height, or %NULL
2043 * Retrieves a cell area's minimum and natural height if it would be given
2044 * the specified @width.
2046 * @area stores some geometrical information in @context along the way
2047 * while calling gtk_cell_area_get_preferred_width(), it's important to
2048 * perform a series of gtk_cell_area_get_preferred_width() requests with
2049 * @context first and then call gtk_cell_area_get_preferred_height_for_width()
2050 * on each cell area individually to get the height for width of each
2051 * fully requested row.
2053 * If at some point, the width of a single row changes, it should be
2054 * requested with gtk_cell_area_get_preferred_width() again and then
2055 * the full width of the requested rows checked again with
2056 * gtk_cell_area_context_get_preferred_width().
2061 gtk_cell_area_get_preferred_height_for_width (GtkCellArea *area,
2062 GtkCellAreaContext *context,
2065 gint *minimum_height,
2066 gint *natural_height)
2068 GtkCellAreaClass *class;
2070 g_return_if_fail (GTK_IS_CELL_AREA (area));
2071 g_return_if_fail (GTK_IS_WIDGET (widget));
2073 class = GTK_CELL_AREA_GET_CLASS (area);
2074 class->get_preferred_height_for_width (area, context, widget, width, minimum_height, natural_height);
2079 * gtk_cell_area_get_preferred_height:
2080 * @area: a #GtkCellArea
2081 * @context: the #GtkCellAreaContext to perform this request with
2082 * @widget: the #GtkWidget where @area will be rendering
2083 * @minimum_height: (out) (allow-none): location to store the minimum height, or %NULL
2084 * @natural_height: (out) (allow-none): location to store the natural height, or %NULL
2086 * Retrieves a cell area's initial minimum and natural height.
2088 * @area will store some geometrical information in @context along the way,
2089 * when requesting sizes over an arbitrary number of rows, its not important
2090 * to check the @minimum_height and @natural_height of this call but rather to
2091 * consult gtk_cell_area_context_get_preferred_height() after a series of
2097 gtk_cell_area_get_preferred_height (GtkCellArea *area,
2098 GtkCellAreaContext *context,
2100 gint *minimum_height,
2101 gint *natural_height)
2103 GtkCellAreaClass *class;
2105 g_return_if_fail (GTK_IS_CELL_AREA (area));
2106 g_return_if_fail (GTK_IS_WIDGET (widget));
2108 class = GTK_CELL_AREA_GET_CLASS (area);
2110 if (class->get_preferred_height)
2111 class->get_preferred_height (area, context, widget, minimum_height, natural_height);
2113 g_warning ("GtkCellAreaClass::get_preferred_height not implemented for `%s'",
2114 g_type_name (G_TYPE_FROM_INSTANCE (area)));
2118 * gtk_cell_area_get_preferred_width_for_height:
2119 * @area: a #GtkCellArea
2120 * @context: the #GtkCellAreaContext which has already been requested for widths.
2121 * @widget: the #GtkWidget where @area will be rendering
2122 * @height: the height for which to check the width of this area
2123 * @minimum_width: (out) (allow-none): location to store the minimum width, or %NULL
2124 * @natural_width: (out) (allow-none): location to store the natural width, or %NULL
2126 * Retrieves a cell area's minimum and natural width if it would be given
2127 * the specified @height.
2129 * @area stores some geometrical information in @context along the way
2130 * while calling gtk_cell_area_get_preferred_height(), it's important to
2131 * perform a series of gtk_cell_area_get_preferred_height() requests with
2132 * @context first and then call gtk_cell_area_get_preferred_width_for_height()
2133 * on each cell area individually to get the height for width of each
2134 * fully requested row.
2136 * If at some point, the height of a single row changes, it should be
2137 * requested with gtk_cell_area_get_preferred_height() again and then
2138 * the full height of the requested rows checked again with
2139 * gtk_cell_area_context_get_preferred_height().
2144 gtk_cell_area_get_preferred_width_for_height (GtkCellArea *area,
2145 GtkCellAreaContext *context,
2148 gint *minimum_width,
2149 gint *natural_width)
2151 GtkCellAreaClass *class;
2153 g_return_if_fail (GTK_IS_CELL_AREA (area));
2154 g_return_if_fail (GTK_IS_WIDGET (widget));
2156 class = GTK_CELL_AREA_GET_CLASS (area);
2157 class->get_preferred_width_for_height (area, context, widget, height, minimum_width, natural_width);
2160 /*************************************************************
2162 *************************************************************/
2165 * gtk_cell_area_attribute_connect:
2166 * @area: a #GtkCellArea
2167 * @renderer: the #GtkCellRenderer to connect an attribute for
2168 * @attribute: the attribute name
2169 * @column: the #GtkTreeModel column to fetch attribute values from
2171 * Connects an @attribute to apply values from @column for the
2172 * #GtkTreeModel in use.
2177 gtk_cell_area_attribute_connect (GtkCellArea *area,
2178 GtkCellRenderer *renderer,
2179 const gchar *attribute,
2182 GtkCellAreaPrivate *priv;
2184 CellAttribute *cell_attribute;
2186 g_return_if_fail (GTK_IS_CELL_AREA (area));
2187 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2188 g_return_if_fail (attribute != NULL);
2189 g_return_if_fail (gtk_cell_area_has_renderer (area, renderer));
2192 info = g_hash_table_lookup (priv->cell_info, renderer);
2196 info = cell_info_new (NULL, NULL, NULL);
2198 g_hash_table_insert (priv->cell_info, renderer, info);
2204 /* Check we are not adding the same attribute twice */
2205 if ((node = g_slist_find_custom (info->attributes, attribute,
2206 (GCompareFunc)cell_attribute_find)) != NULL)
2208 cell_attribute = node->data;
2210 g_warning ("Cannot connect attribute `%s' for cell renderer class `%s' "
2211 "since `%s' is already attributed to column %d",
2213 g_type_name (G_TYPE_FROM_INSTANCE (area)),
2214 attribute, cell_attribute->column);
2219 cell_attribute = cell_attribute_new (renderer, attribute, column);
2221 if (!cell_attribute)
2223 g_warning ("Cannot connect attribute `%s' for cell renderer class `%s' "
2224 "since attribute does not exist",
2226 g_type_name (G_TYPE_FROM_INSTANCE (area)));
2230 info->attributes = g_slist_prepend (info->attributes, cell_attribute);
2234 * gtk_cell_area_attribute_disconnect:
2235 * @area: a #GtkCellArea
2236 * @renderer: the #GtkCellRenderer to disconnect an attribute for
2237 * @attribute: the attribute name
2239 * Disconnects @attribute for the @renderer in @area so that
2240 * attribute will no longer be updated with values from the
2246 gtk_cell_area_attribute_disconnect (GtkCellArea *area,
2247 GtkCellRenderer *renderer,
2248 const gchar *attribute)
2250 GtkCellAreaPrivate *priv;
2252 CellAttribute *cell_attribute;
2255 g_return_if_fail (GTK_IS_CELL_AREA (area));
2256 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2257 g_return_if_fail (attribute != NULL);
2258 g_return_if_fail (gtk_cell_area_has_renderer (area, renderer));
2261 info = g_hash_table_lookup (priv->cell_info, renderer);
2265 node = g_slist_find_custom (info->attributes, attribute,
2266 (GCompareFunc)cell_attribute_find);
2269 cell_attribute = node->data;
2271 cell_attribute_free (cell_attribute);
2273 info->attributes = g_slist_delete_link (info->attributes, node);
2279 * gtk_cell_area_apply_attributes
2280 * @area: a #GtkCellArea
2281 * @tree_model: the #GtkTreeModel to pull values from
2282 * @iter: the #GtkTreeIter in @tree_model to apply values for
2283 * @is_expander: whether @iter has children
2284 * @is_expanded: whether @iter is expanded in the view and
2285 * children are visible
2287 * Applies any connected attributes to the renderers in
2288 * @area by pulling the values from @tree_model.
2293 gtk_cell_area_apply_attributes (GtkCellArea *area,
2294 GtkTreeModel *tree_model,
2296 gboolean is_expander,
2297 gboolean is_expanded)
2299 g_return_if_fail (GTK_IS_CELL_AREA (area));
2300 g_return_if_fail (GTK_IS_TREE_MODEL (tree_model));
2301 g_return_if_fail (iter != NULL);
2303 g_signal_emit (area, cell_area_signals[SIGNAL_APPLY_ATTRIBUTES], 0,
2304 tree_model, iter, is_expander, is_expanded);
2308 * gtk_cell_area_get_current_path_string:
2309 * @area: a #GtkCellArea
2311 * Gets the current #GtkTreePath string for the currently
2312 * applied #GtkTreeIter, this is implicitly updated when
2313 * gtk_cell_area_apply_attributes() is called and can be
2314 * used to interact with renderers from #GtkCellArea
2317 * Return value: The current #GtkTreePath string for the current
2318 * attributes applied to @area. This string belongs to the area and
2319 * should not be freed.
2323 G_CONST_RETURN gchar *
2324 gtk_cell_area_get_current_path_string (GtkCellArea *area)
2326 GtkCellAreaPrivate *priv;
2328 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
2332 return priv->current_path;
2336 /*************************************************************
2337 * API: Cell Properties *
2338 *************************************************************/
2340 * gtk_cell_area_class_install_cell_property:
2341 * @aclass: a #GtkCellAreaClass
2342 * @property_id: the id for the property
2343 * @pspec: the #GParamSpec for the property
2345 * Installs a cell property on a cell area class.
2350 gtk_cell_area_class_install_cell_property (GtkCellAreaClass *aclass,
2354 g_return_if_fail (GTK_IS_CELL_AREA_CLASS (aclass));
2355 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
2356 if (pspec->flags & G_PARAM_WRITABLE)
2357 g_return_if_fail (aclass->set_cell_property != NULL);
2358 if (pspec->flags & G_PARAM_READABLE)
2359 g_return_if_fail (aclass->get_cell_property != NULL);
2360 g_return_if_fail (property_id > 0);
2361 g_return_if_fail (PARAM_SPEC_PARAM_ID (pspec) == 0); /* paranoid */
2362 g_return_if_fail ((pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY)) == 0);
2364 if (g_param_spec_pool_lookup (cell_property_pool, pspec->name, G_OBJECT_CLASS_TYPE (aclass), TRUE))
2366 g_warning (G_STRLOC ": class `%s' already contains a cell property named `%s'",
2367 G_OBJECT_CLASS_NAME (aclass), pspec->name);
2370 g_param_spec_ref (pspec);
2371 g_param_spec_sink (pspec);
2372 PARAM_SPEC_SET_PARAM_ID (pspec, property_id);
2373 g_param_spec_pool_insert (cell_property_pool, pspec, G_OBJECT_CLASS_TYPE (aclass));
2377 * gtk_cell_area_class_find_cell_property:
2378 * @aclass: a #GtkCellAreaClass
2379 * @property_name: the name of the child property to find
2381 * Finds a cell property of a cell area class by name.
2383 * Return value: (transfer none): the #GParamSpec of the child property
2384 * or %NULL if @aclass has no child property with that name.
2389 gtk_cell_area_class_find_cell_property (GtkCellAreaClass *aclass,
2390 const gchar *property_name)
2392 g_return_val_if_fail (GTK_IS_CELL_AREA_CLASS (aclass), NULL);
2393 g_return_val_if_fail (property_name != NULL, NULL);
2395 return g_param_spec_pool_lookup (cell_property_pool,
2397 G_OBJECT_CLASS_TYPE (aclass),
2402 * gtk_cell_area_class_list_cell_properties:
2403 * @aclass: a #GtkCellAreaClass
2404 * @n_properties: location to return the number of cell properties found
2406 * Returns all cell properties of a cell area class.
2408 * Return value: (array length=n_properties) (transfer container): a newly
2409 * allocated %NULL-terminated array of #GParamSpec*. The array
2410 * must be freed with g_free().
2415 gtk_cell_area_class_list_cell_properties (GtkCellAreaClass *aclass,
2416 guint *n_properties)
2418 GParamSpec **pspecs;
2421 g_return_val_if_fail (GTK_IS_CELL_AREA_CLASS (aclass), NULL);
2423 pspecs = g_param_spec_pool_list (cell_property_pool,
2424 G_OBJECT_CLASS_TYPE (aclass),
2433 * gtk_cell_area_add_with_properties:
2434 * @area: a #GtkCellArea
2435 * @renderer: a #GtkCellRenderer to be placed inside @area
2436 * @first_prop_name: the name of the first cell property to set
2437 * @Varargs: a %NULL-terminated list of property names and values, starting
2438 * with @first_prop_name
2440 * Adds @renderer to @area, setting cell properties at the same time.
2441 * See gtk_cell_area_add() and gtk_cell_area_cell_set() for more details.
2446 gtk_cell_area_add_with_properties (GtkCellArea *area,
2447 GtkCellRenderer *renderer,
2448 const gchar *first_prop_name,
2451 GtkCellAreaClass *class;
2453 g_return_if_fail (GTK_IS_CELL_AREA (area));
2454 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2456 class = GTK_CELL_AREA_GET_CLASS (area);
2462 class->add (area, renderer);
2464 va_start (var_args, first_prop_name);
2465 gtk_cell_area_cell_set_valist (area, renderer, first_prop_name, var_args);
2469 g_warning ("GtkCellAreaClass::add not implemented for `%s'",
2470 g_type_name (G_TYPE_FROM_INSTANCE (area)));
2474 * gtk_cell_area_cell_set:
2475 * @area: a #GtkCellArea
2476 * @renderer: a #GtkCellRenderer which is a cell inside @area
2477 * @first_prop_name: the name of the first cell property to set
2478 * @Varargs: a %NULL-terminated list of property names and values, starting
2479 * with @first_prop_name
2481 * Sets one or more cell properties for @cell in @area.
2486 gtk_cell_area_cell_set (GtkCellArea *area,
2487 GtkCellRenderer *renderer,
2488 const gchar *first_prop_name,
2493 g_return_if_fail (GTK_IS_CELL_AREA (area));
2494 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2496 va_start (var_args, first_prop_name);
2497 gtk_cell_area_cell_set_valist (area, renderer, first_prop_name, var_args);
2502 * gtk_cell_area_cell_get:
2503 * @area: a #GtkCellArea
2504 * @renderer: a #GtkCellRenderer which is inside @area
2505 * @first_prop_name: the name of the first cell property to get
2506 * @Varargs: return location for the first cell property, followed
2507 * optionally by more name/return location pairs, followed by %NULL
2509 * Gets the values of one or more cell properties for @renderer in @area.
2514 gtk_cell_area_cell_get (GtkCellArea *area,
2515 GtkCellRenderer *renderer,
2516 const gchar *first_prop_name,
2521 g_return_if_fail (GTK_IS_CELL_AREA (area));
2522 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2524 va_start (var_args, first_prop_name);
2525 gtk_cell_area_cell_get_valist (area, renderer, first_prop_name, var_args);
2530 area_get_cell_property (GtkCellArea *area,
2531 GtkCellRenderer *renderer,
2535 GtkCellAreaClass *class = g_type_class_peek (pspec->owner_type);
2537 class->get_cell_property (area, renderer, PARAM_SPEC_PARAM_ID (pspec), value, pspec);
2541 area_set_cell_property (GtkCellArea *area,
2542 GtkCellRenderer *renderer,
2544 const GValue *value)
2546 GValue tmp_value = { 0, };
2547 GtkCellAreaClass *class = g_type_class_peek (pspec->owner_type);
2549 /* provide a copy to work from, convert (if necessary) and validate */
2550 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2551 if (!g_value_transform (value, &tmp_value))
2552 g_warning ("unable to set cell property `%s' of type `%s' from value of type `%s'",
2554 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
2555 G_VALUE_TYPE_NAME (value));
2556 else if (g_param_value_validate (pspec, &tmp_value) && !(pspec->flags & G_PARAM_LAX_VALIDATION))
2558 gchar *contents = g_strdup_value_contents (value);
2560 g_warning ("value \"%s\" of type `%s' is invalid for property `%s' of type `%s'",
2562 G_VALUE_TYPE_NAME (value),
2564 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
2569 class->set_cell_property (area, renderer, PARAM_SPEC_PARAM_ID (pspec), &tmp_value, pspec);
2571 g_value_unset (&tmp_value);
2575 * gtk_cell_area_cell_set_valist:
2576 * @area: a #GtkCellArea
2577 * @renderer: a #GtkCellRenderer which inside @area
2578 * @first_property_name: the name of the first cell property to set
2579 * @var_args: a %NULL-terminated list of property names and values, starting
2580 * with @first_prop_name
2582 * Sets one or more cell properties for @renderer in @area.
2587 gtk_cell_area_cell_set_valist (GtkCellArea *area,
2588 GtkCellRenderer *renderer,
2589 const gchar *first_property_name,
2594 g_return_if_fail (GTK_IS_CELL_AREA (area));
2595 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2597 name = first_property_name;
2600 GValue value = { 0, };
2601 gchar *error = NULL;
2603 g_param_spec_pool_lookup (cell_property_pool, name,
2604 G_OBJECT_TYPE (area), TRUE);
2607 g_warning ("%s: cell area class `%s' has no cell property named `%s'",
2608 G_STRLOC, G_OBJECT_TYPE_NAME (area), name);
2611 if (!(pspec->flags & G_PARAM_WRITABLE))
2613 g_warning ("%s: cell property `%s' of cell area class `%s' is not writable",
2614 G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
2618 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2619 G_VALUE_COLLECT (&value, var_args, 0, &error);
2622 g_warning ("%s: %s", G_STRLOC, error);
2625 /* we purposely leak the value here, it might not be
2626 * in a sane state if an error condition occoured
2630 area_set_cell_property (area, renderer, pspec, &value);
2631 g_value_unset (&value);
2632 name = va_arg (var_args, gchar*);
2637 * gtk_cell_area_cell_get_valist:
2638 * @area: a #GtkCellArea
2639 * @renderer: a #GtkCellRenderer inside @area
2640 * @first_property_name: the name of the first property to get
2641 * @var_args: return location for the first property, followed
2642 * optionally by more name/return location pairs, followed by %NULL
2644 * Gets the values of one or more cell properties for @renderer in @area.
2649 gtk_cell_area_cell_get_valist (GtkCellArea *area,
2650 GtkCellRenderer *renderer,
2651 const gchar *first_property_name,
2656 g_return_if_fail (GTK_IS_CELL_AREA (area));
2657 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2659 name = first_property_name;
2662 GValue value = { 0, };
2666 pspec = g_param_spec_pool_lookup (cell_property_pool, name,
2667 G_OBJECT_TYPE (area), TRUE);
2670 g_warning ("%s: cell area class `%s' has no cell property named `%s'",
2671 G_STRLOC, G_OBJECT_TYPE_NAME (area), name);
2674 if (!(pspec->flags & G_PARAM_READABLE))
2676 g_warning ("%s: cell property `%s' of cell area class `%s' is not readable",
2677 G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
2681 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2682 area_get_cell_property (area, renderer, pspec, &value);
2683 G_VALUE_LCOPY (&value, var_args, 0, &error);
2686 g_warning ("%s: %s", G_STRLOC, error);
2688 g_value_unset (&value);
2691 g_value_unset (&value);
2692 name = va_arg (var_args, gchar*);
2697 * gtk_cell_area_cell_set_property:
2698 * @area: a #GtkCellArea
2699 * @renderer: a #GtkCellRenderer inside @area
2700 * @property_name: the name of the cell property to set
2701 * @value: the value to set the cell property to
2703 * Sets a cell property for @renderer in @area.
2708 gtk_cell_area_cell_set_property (GtkCellArea *area,
2709 GtkCellRenderer *renderer,
2710 const gchar *property_name,
2711 const GValue *value)
2715 g_return_if_fail (GTK_IS_CELL_AREA (area));
2716 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2717 g_return_if_fail (property_name != NULL);
2718 g_return_if_fail (G_IS_VALUE (value));
2720 pspec = g_param_spec_pool_lookup (cell_property_pool, property_name,
2721 G_OBJECT_TYPE (area), TRUE);
2723 g_warning ("%s: cell area class `%s' has no cell property named `%s'",
2724 G_STRLOC, G_OBJECT_TYPE_NAME (area), property_name);
2725 else if (!(pspec->flags & G_PARAM_WRITABLE))
2726 g_warning ("%s: cell property `%s' of cell area class `%s' is not writable",
2727 G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
2730 area_set_cell_property (area, renderer, pspec, value);
2735 * gtk_cell_area_cell_get_property:
2736 * @area: a #GtkCellArea
2737 * @renderer: a #GtkCellRenderer inside @area
2738 * @property_name: the name of the property to get
2739 * @value: a location to return the value
2741 * Gets the value of a cell property for @renderer in @area.
2746 gtk_cell_area_cell_get_property (GtkCellArea *area,
2747 GtkCellRenderer *renderer,
2748 const gchar *property_name,
2753 g_return_if_fail (GTK_IS_CELL_AREA (area));
2754 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2755 g_return_if_fail (property_name != NULL);
2756 g_return_if_fail (G_IS_VALUE (value));
2758 pspec = g_param_spec_pool_lookup (cell_property_pool, property_name,
2759 G_OBJECT_TYPE (area), TRUE);
2761 g_warning ("%s: cell area class `%s' has no cell property named `%s'",
2762 G_STRLOC, G_OBJECT_TYPE_NAME (area), property_name);
2763 else if (!(pspec->flags & G_PARAM_READABLE))
2764 g_warning ("%s: cell property `%s' of cell area class `%s' is not readable",
2765 G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
2768 GValue *prop_value, tmp_value = { 0, };
2770 /* auto-conversion of the callers value type
2772 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
2774 g_value_reset (value);
2777 else if (!g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
2779 g_warning ("can't retrieve cell property `%s' of type `%s' as value of type `%s'",
2781 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
2782 G_VALUE_TYPE_NAME (value));
2787 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2788 prop_value = &tmp_value;
2791 area_get_cell_property (area, renderer, pspec, prop_value);
2793 if (prop_value != value)
2795 g_value_transform (prop_value, value);
2796 g_value_unset (&tmp_value);
2801 /*************************************************************
2803 *************************************************************/
2806 * gtk_cell_area_is_activatable:
2807 * @area: a #GtkCellArea
2809 * Returns whether the area can do anything when activated,
2810 * after applying new attributes to @area.
2812 * Return value: whether @area can do anything when activated.
2817 gtk_cell_area_is_activatable (GtkCellArea *area)
2819 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2821 return GTK_CELL_AREA_GET_CLASS (area)->is_activatable (area);
2825 * gtk_cell_area_focus:
2826 * @area: a #GtkCellArea
2827 * @direction: the #GtkDirectionType
2829 * This should be called by the @area's owning layout widget
2830 * when focus is to be passed to @area, or moved within @area
2831 * for a given @direction and row data.
2833 * Implementing #GtkCellArea classes should implement this
2834 * method to receive and navigate focus in it's own way particular
2835 * to how it lays out cells.
2837 * Return value: %TRUE if focus remains inside @area as a result of this call.
2842 gtk_cell_area_focus (GtkCellArea *area,
2843 GtkDirectionType direction)
2845 GtkCellAreaClass *class;
2847 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2849 class = GTK_CELL_AREA_GET_CLASS (area);
2852 return class->focus (area, direction);
2854 g_warning ("GtkCellAreaClass::focus not implemented for `%s'",
2855 g_type_name (G_TYPE_FROM_INSTANCE (area)));
2861 * gtk_cell_area_activate:
2862 * @area: a #GtkCellArea
2863 * @context: the #GtkCellAreaContext in context with the current row data
2864 * @widget: the #GtkWidget that @area is rendering on
2865 * @cell_area: the size and location of @area relative to @widget's allocation
2866 * @flags: the #GtkCellRendererState flags for @area for this row of data.
2867 * @edit_only: if %TRUE then only cell renderers that are %GTK_CELL_RENDERER_MODE_EDITABLE
2868 * will be activated.
2870 * Activates @area, usually by activating the currently focused
2871 * cell, however some subclasses which embed widgets in the area
2872 * can also activate a widget if it currently has the focus.
2874 * Return value: Whether @area was successfully activated.
2879 gtk_cell_area_activate (GtkCellArea *area,
2880 GtkCellAreaContext *context,
2882 const GdkRectangle *cell_area,
2883 GtkCellRendererState flags,
2886 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2888 return GTK_CELL_AREA_GET_CLASS (area)->activate (area, context, widget, cell_area, flags, edit_only);
2893 * gtk_cell_area_set_focus_cell:
2894 * @area: a #GtkCellArea
2895 * @renderer: the #GtkCellRenderer to give focus to
2897 * Explicitly sets the currently focused cell to @renderer.
2899 * This is generally called by implementations of
2900 * #GtkCellAreaClass.focus() or #GtkCellAreaClass.event(),
2901 * however it can also be used to implement functions such
2902 * as gtk_tree_view_set_cursor_on_cell().
2907 gtk_cell_area_set_focus_cell (GtkCellArea *area,
2908 GtkCellRenderer *renderer)
2910 GtkCellAreaPrivate *priv;
2912 g_return_if_fail (GTK_IS_CELL_AREA (area));
2913 g_return_if_fail (renderer == NULL || GTK_IS_CELL_RENDERER (renderer));
2917 if (priv->focus_cell != renderer)
2919 if (priv->focus_cell)
2920 g_object_unref (priv->focus_cell);
2922 priv->focus_cell = renderer;
2924 if (priv->focus_cell)
2925 g_object_ref (priv->focus_cell);
2927 g_object_notify (G_OBJECT (area), "focus-cell");
2930 /* Signal that the current focus renderer for this path changed
2931 * (it may be that the focus cell did not change, but the row
2932 * may have changed so we need to signal it) */
2933 g_signal_emit (area, cell_area_signals[SIGNAL_FOCUS_CHANGED], 0,
2934 priv->focus_cell, priv->current_path);
2939 * gtk_cell_area_get_focus_cell:
2940 * @area: a #GtkCellArea
2942 * Retrieves the currently focused cell for @area
2944 * Return value: (transfer none): the currently focused cell in @area.
2949 gtk_cell_area_get_focus_cell (GtkCellArea *area)
2951 GtkCellAreaPrivate *priv;
2953 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
2957 return priv->focus_cell;
2961 /*************************************************************
2962 * API: Focus Siblings *
2963 *************************************************************/
2966 * gtk_cell_area_add_focus_sibling:
2967 * @area: a #GtkCellArea
2968 * @renderer: the #GtkCellRenderer expected to have focus
2969 * @sibling: the #GtkCellRenderer to add to @renderer's focus area
2971 * Adds @sibling to @renderer's focusable area, focus will be drawn
2972 * around @renderer and all of it's siblings if @renderer can
2973 * focus for a given row.
2975 * Events handled by focus siblings can also activate the given
2976 * focusable @renderer.
2981 gtk_cell_area_add_focus_sibling (GtkCellArea *area,
2982 GtkCellRenderer *renderer,
2983 GtkCellRenderer *sibling)
2985 GtkCellAreaPrivate *priv;
2988 g_return_if_fail (GTK_IS_CELL_AREA (area));
2989 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2990 g_return_if_fail (GTK_IS_CELL_RENDERER (sibling));
2991 g_return_if_fail (renderer != sibling);
2992 g_return_if_fail (gtk_cell_area_has_renderer (area, renderer));
2993 g_return_if_fail (gtk_cell_area_has_renderer (area, sibling));
2994 g_return_if_fail (!gtk_cell_area_is_focus_sibling (area, renderer, sibling));
2996 /* XXX We should also check that sibling is not in any other renderer's sibling
2997 * list already, a renderer can be sibling of only one focusable renderer
3003 siblings = g_hash_table_lookup (priv->focus_siblings, renderer);
3006 siblings = g_list_append (siblings, sibling);
3009 siblings = g_list_append (siblings, sibling);
3010 g_hash_table_insert (priv->focus_siblings, renderer, siblings);
3015 * gtk_cell_area_remove_focus_sibling:
3016 * @area: a #GtkCellArea
3017 * @renderer: the #GtkCellRenderer expected to have focus
3018 * @sibling: the #GtkCellRenderer to remove from @renderer's focus area
3020 * Removes @sibling from @renderer's focus sibling list
3021 * (see gtk_cell_area_add_focus_sibling()).
3026 gtk_cell_area_remove_focus_sibling (GtkCellArea *area,
3027 GtkCellRenderer *renderer,
3028 GtkCellRenderer *sibling)
3030 GtkCellAreaPrivate *priv;
3033 g_return_if_fail (GTK_IS_CELL_AREA (area));
3034 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
3035 g_return_if_fail (GTK_IS_CELL_RENDERER (sibling));
3036 g_return_if_fail (gtk_cell_area_is_focus_sibling (area, renderer, sibling));
3040 siblings = g_hash_table_lookup (priv->focus_siblings, renderer);
3042 siblings = g_list_copy (siblings);
3043 siblings = g_list_remove (siblings, sibling);
3046 g_hash_table_remove (priv->focus_siblings, renderer);
3048 g_hash_table_insert (priv->focus_siblings, renderer, siblings);
3052 * gtk_cell_area_is_focus_sibling:
3053 * @area: a #GtkCellArea
3054 * @renderer: the #GtkCellRenderer expected to have focus
3055 * @sibling: the #GtkCellRenderer to check against @renderer's sibling list
3057 * Returns %TRUE if @sibling is one of @renderer's focus siblings
3058 * (see gtk_cell_area_add_focus_sibling()).
3063 gtk_cell_area_is_focus_sibling (GtkCellArea *area,
3064 GtkCellRenderer *renderer,
3065 GtkCellRenderer *sibling)
3067 GtkCellAreaPrivate *priv;
3068 GList *siblings, *l;
3070 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
3071 g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), FALSE);
3072 g_return_val_if_fail (GTK_IS_CELL_RENDERER (sibling), FALSE);
3076 siblings = g_hash_table_lookup (priv->focus_siblings, renderer);
3078 for (l = siblings; l; l = l->next)
3080 GtkCellRenderer *a_sibling = l->data;
3082 if (a_sibling == sibling)
3090 * gtk_cell_area_get_focus_siblings:
3091 * @area: a #GtkCellArea
3092 * @renderer: the #GtkCellRenderer expected to have focus
3094 * Gets the focus sibling cell renderers for @renderer.
3096 * Return value: (element-type GtkCellRenderer) (transfer none): A #GList of #GtkCellRenderers.
3097 * The returned list is internal and should not be freed.
3102 gtk_cell_area_get_focus_siblings (GtkCellArea *area,
3103 GtkCellRenderer *renderer)
3105 GtkCellAreaPrivate *priv;
3107 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
3108 g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), NULL);
3112 return g_hash_table_lookup (priv->focus_siblings, renderer);
3116 * gtk_cell_area_get_focus_from_sibling:
3117 * @area: a #GtkCellArea
3118 * @renderer: the #GtkCellRenderer
3120 * Gets the #GtkCellRenderer which is expected to be focusable
3121 * for which @renderer is, or may be a sibling.
3123 * This is handy for #GtkCellArea subclasses when handling events,
3124 * after determining the renderer at the event location it can
3125 * then chose to activate the focus cell for which the event
3126 * cell may have been a sibling.
3128 * Return value: (transfer none): the #GtkCellRenderer for which @renderer
3129 * is a sibling, or %NULL.
3134 gtk_cell_area_get_focus_from_sibling (GtkCellArea *area,
3135 GtkCellRenderer *renderer)
3137 GtkCellRenderer *ret_renderer = NULL;
3138 GList *renderers, *l;
3140 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
3141 g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), NULL);
3143 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (area));
3145 for (l = renderers; l; l = l->next)
3147 GtkCellRenderer *a_renderer = l->data;
3150 for (list = gtk_cell_area_get_focus_siblings (area, a_renderer);
3151 list; list = list->next)
3153 GtkCellRenderer *sibling_renderer = list->data;
3155 if (sibling_renderer == renderer)
3157 ret_renderer = a_renderer;
3162 g_list_free (renderers);
3164 return ret_renderer;
3167 /*************************************************************
3168 * API: Cell Activation/Editing *
3169 *************************************************************/
3171 gtk_cell_area_add_editable (GtkCellArea *area,
3172 GtkCellRenderer *renderer,
3173 GtkCellEditable *editable,
3174 const GdkRectangle *cell_area)
3176 g_signal_emit (area, cell_area_signals[SIGNAL_ADD_EDITABLE], 0,
3177 renderer, editable, cell_area, area->priv->current_path);
3181 gtk_cell_area_remove_editable (GtkCellArea *area,
3182 GtkCellRenderer *renderer,
3183 GtkCellEditable *editable)
3185 g_signal_emit (area, cell_area_signals[SIGNAL_REMOVE_EDITABLE], 0, renderer, editable);
3189 cell_area_remove_widget_cb (GtkCellEditable *editable,
3192 GtkCellAreaPrivate *priv = area->priv;
3194 g_assert (priv->edit_widget == editable);
3195 g_assert (priv->edited_cell != NULL);
3197 gtk_cell_area_remove_editable (area, priv->edited_cell, priv->edit_widget);
3199 /* Now that we're done with editing the widget and it can be removed,
3200 * remove our references to the widget and disconnect handlers */
3201 gtk_cell_area_set_edited_cell (area, NULL);
3202 gtk_cell_area_set_edit_widget (area, NULL);
3206 gtk_cell_area_set_edited_cell (GtkCellArea *area,
3207 GtkCellRenderer *renderer)
3209 GtkCellAreaPrivate *priv;
3211 g_return_if_fail (GTK_IS_CELL_AREA (area));
3212 g_return_if_fail (renderer == NULL || GTK_IS_CELL_RENDERER (renderer));
3216 if (priv->edited_cell != renderer)
3218 if (priv->edited_cell)
3219 g_object_unref (priv->edited_cell);
3221 priv->edited_cell = renderer;
3223 if (priv->edited_cell)
3224 g_object_ref (priv->edited_cell);
3226 g_object_notify (G_OBJECT (area), "edited-cell");
3231 gtk_cell_area_set_edit_widget (GtkCellArea *area,
3232 GtkCellEditable *editable)
3234 GtkCellAreaPrivate *priv;
3236 g_return_if_fail (GTK_IS_CELL_AREA (area));
3237 g_return_if_fail (editable == NULL || GTK_IS_CELL_EDITABLE (editable));
3241 if (priv->edit_widget != editable)
3243 if (priv->edit_widget)
3245 g_signal_handler_disconnect (priv->edit_widget, priv->remove_widget_id);
3247 g_object_unref (priv->edit_widget);
3250 priv->edit_widget = editable;
3252 if (priv->edit_widget)
3254 priv->remove_widget_id =
3255 g_signal_connect (priv->edit_widget, "remove-widget",
3256 G_CALLBACK (cell_area_remove_widget_cb), area);
3258 g_object_ref (priv->edit_widget);
3261 g_object_notify (G_OBJECT (area), "edit-widget");
3266 * gtk_cell_area_get_edited_cell:
3267 * @area: a #GtkCellArea
3269 * Gets the #GtkCellRenderer in @area that is currently
3272 * Return value: (transfer none): The currently edited #GtkCellRenderer
3277 gtk_cell_area_get_edited_cell (GtkCellArea *area)
3279 GtkCellAreaPrivate *priv;
3281 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
3285 return priv->edited_cell;
3289 * gtk_cell_area_get_edit_widget:
3290 * @area: a #GtkCellArea
3292 * Gets the #GtkCellEditable widget currently used
3293 * to edit the currently edited cell.
3295 * Return value: (transfer none): The currently active #GtkCellEditable widget
3300 gtk_cell_area_get_edit_widget (GtkCellArea *area)
3302 GtkCellAreaPrivate *priv;
3304 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
3308 return priv->edit_widget;
3312 * gtk_cell_area_activate_cell:
3313 * @area: a #GtkCellArea
3314 * @widget: the #GtkWidget that @area is rendering onto
3315 * @renderer: the #GtkCellRenderer in @area to activate
3316 * @event: the #GdkEvent for which cell activation should occur
3317 * @cell_area: the #GdkRectangle in @widget relative coordinates
3318 * of @renderer for the current row.
3319 * @flags: the #GtkCellRendererState for @renderer
3321 * This is used by #GtkCellArea subclasses when handling events
3322 * to activate cells, the base #GtkCellArea class activates cells
3323 * for keyboard events for free in it's own GtkCellArea->activate()
3326 * Return value: whether cell activation was successful
3331 gtk_cell_area_activate_cell (GtkCellArea *area,
3333 GtkCellRenderer *renderer,
3335 const GdkRectangle *cell_area,
3336 GtkCellRendererState flags)
3338 GtkCellRendererMode mode;
3339 GtkCellAreaPrivate *priv;
3341 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
3342 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3343 g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), FALSE);
3344 g_return_val_if_fail (cell_area != NULL, FALSE);
3348 if (!gtk_cell_renderer_get_sensitive (renderer))
3351 g_object_get (renderer, "mode", &mode, NULL);
3353 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
3355 if (gtk_cell_renderer_activate (renderer,
3363 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
3365 GtkCellEditable *editable_widget;
3366 GdkRectangle inner_area;
3368 gtk_cell_area_inner_cell_area (area, widget, cell_area, &inner_area);
3371 gtk_cell_renderer_start_editing (renderer,
3378 if (editable_widget != NULL)
3380 g_return_val_if_fail (GTK_IS_CELL_EDITABLE (editable_widget), FALSE);
3382 gtk_cell_area_set_edited_cell (area, renderer);
3383 gtk_cell_area_set_edit_widget (area, editable_widget);
3385 /* Signal that editing started so that callers can get
3386 * a handle on the editable_widget */
3387 gtk_cell_area_add_editable (area, priv->focus_cell, editable_widget, cell_area);
3389 /* If the signal was successfully handled start the editing */
3390 if (gtk_widget_get_parent (GTK_WIDGET (editable_widget)))
3392 gtk_cell_editable_start_editing (editable_widget, NULL);
3393 gtk_widget_grab_focus (GTK_WIDGET (editable_widget));
3397 /* Otherwise clear the editing state and fire a warning */
3398 gtk_cell_area_set_edited_cell (area, NULL);
3399 gtk_cell_area_set_edit_widget (area, NULL);
3401 g_warning ("GtkCellArea::add-editable fired in the dark, no cell editing was started.");
3412 * gtk_cell_area_stop_editing:
3413 * @area: a #GtkCellArea
3414 * @canceled: whether editing was canceled.
3416 * Explicitly stops the editing of the currently
3417 * edited cell (see gtk_cell_area_get_edited_cell()).
3419 * If @canceled is %TRUE, the cell renderer will emit
3420 * the ::editing-canceled signal.
3425 gtk_cell_area_stop_editing (GtkCellArea *area,
3428 GtkCellAreaPrivate *priv;
3430 g_return_if_fail (GTK_IS_CELL_AREA (area));
3434 if (priv->edited_cell)
3436 GtkCellEditable *edit_widget = g_object_ref (priv->edit_widget);
3437 GtkCellRenderer *edit_cell = g_object_ref (priv->edited_cell);
3439 /* Stop editing of the cell renderer */
3440 gtk_cell_renderer_stop_editing (priv->edited_cell, canceled);
3442 /* Remove any references to the editable widget */
3443 gtk_cell_area_set_edited_cell (area, NULL);
3444 gtk_cell_area_set_edit_widget (area, NULL);
3446 /* Send the remove-widget signal explicitly (this is done after setting
3447 * the edit cell/widget NULL to avoid feedback)
3449 gtk_cell_area_remove_editable (area, edit_cell, edit_widget);
3450 g_object_unref (edit_cell);
3451 g_object_unref (edit_widget);
3455 /*************************************************************
3456 * API: Convenience for area implementations *
3457 *************************************************************/
3460 * gtk_cell_area_inner_cell_area:
3461 * @area: a #GtkCellArea
3462 * @widget: the #GtkWidget that @area is rendering onto
3463 * @cell_area: the @widget relative coordinates where one of @area's cells
3465 * @inner_area: (out): the return location for the inner cell area
3467 * This is a convenience function for #GtkCellArea implementations
3468 * to get the inner area where a given #GtkCellRenderer will be
3469 * rendered. It removes any padding previously added by gtk_cell_area_request_renderer().
3474 gtk_cell_area_inner_cell_area (GtkCellArea *area,
3476 const GdkRectangle *cell_area,
3477 GdkRectangle *inner_area)
3479 gint focus_line_width;
3481 g_return_if_fail (GTK_IS_CELL_AREA (area));
3482 g_return_if_fail (GTK_IS_WIDGET (widget));
3483 g_return_if_fail (cell_area != NULL);
3484 g_return_if_fail (inner_area != NULL);
3486 gtk_widget_style_get (widget, "focus-line-width", &focus_line_width, NULL);
3488 *inner_area = *cell_area;
3490 inner_area->x += focus_line_width;
3491 inner_area->width -= focus_line_width * 2;
3492 inner_area->y += focus_line_width;
3493 inner_area->height -= focus_line_width * 2;
3497 * gtk_cell_area_request_renderer:
3498 * @area: a #GtkCellArea
3499 * @renderer: the #GtkCellRenderer to request size for
3500 * @orientation: the #GtkOrientation in which to request size
3501 * @widget: the #GtkWidget that @area is rendering onto
3502 * @for_size: the allocation contextual size to request for, or -1 if
3503 * the base request for the orientation is to be returned.
3504 * @minimum_size: (out) (allow-none): location to store the minimum size, or %NULL
3505 * @natural_size: (out) (allow-none): location to store the natural size, or %NULL
3507 * This is a convenience function for #GtkCellArea implementations
3508 * to request size for cell renderers. It's important to use this
3509 * function to request size and then use gtk_cell_area_inner_cell_area()
3510 * at render and event time since this function will add padding
3511 * around the cell for focus painting.
3516 gtk_cell_area_request_renderer (GtkCellArea *area,
3517 GtkCellRenderer *renderer,
3518 GtkOrientation orientation,
3524 gint focus_line_width;
3526 g_return_if_fail (GTK_IS_CELL_AREA (area));
3527 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
3528 g_return_if_fail (GTK_IS_WIDGET (widget));
3529 g_return_if_fail (minimum_size != NULL);
3530 g_return_if_fail (natural_size != NULL);
3532 gtk_widget_style_get (widget, "focus-line-width", &focus_line_width, NULL);
3534 focus_line_width *= 2;
3536 if (orientation == GTK_ORIENTATION_HORIZONTAL)
3539 gtk_cell_renderer_get_preferred_width (renderer, widget, minimum_size, natural_size);
3542 for_size = MAX (0, for_size - focus_line_width);
3544 gtk_cell_renderer_get_preferred_width_for_height (renderer, widget, for_size,
3545 minimum_size, natural_size);
3548 else /* GTK_ORIENTATION_VERTICAL */
3551 gtk_cell_renderer_get_preferred_height (renderer, widget, minimum_size, natural_size);
3554 for_size = MAX (0, for_size - focus_line_width);
3556 gtk_cell_renderer_get_preferred_height_for_width (renderer, widget, for_size,
3557 minimum_size, natural_size);
3561 *minimum_size += focus_line_width;
3562 *natural_size += focus_line_width;
3566 _gtk_cell_area_set_cell_data_func_with_proxy (GtkCellArea *area,
3567 GtkCellRenderer *cell,
3570 GDestroyNotify destroy,
3573 GtkCellAreaPrivate *priv;
3576 g_return_if_fail (GTK_IS_CELL_AREA (area));
3577 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
3581 info = g_hash_table_lookup (priv->cell_info, cell);
3583 /* Note we do not take a reference to the proxy, the proxy is a GtkCellLayout
3584 * that is forwarding it's implementation to a delegate GtkCellArea therefore
3585 * it's life-cycle is longer than the area's life cycle.
3589 if (info->destroy && info->data)
3590 info->destroy (info->data);
3594 info->func = (GtkCellLayoutDataFunc)func;
3595 info->data = func_data;
3596 info->destroy = destroy;
3597 info->proxy = proxy;
3603 info->destroy = NULL;
3609 info = cell_info_new ((GtkCellLayoutDataFunc)func, func_data, destroy);
3610 info->proxy = proxy;
3612 g_hash_table_insert (priv->cell_info, cell, info);