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 laying out #GtkCellRenderers
30 * onto a given area of a #GtkWidget.
32 * The work of rendering #GtkCellRenderers can be very complicated; it involves
33 * requesting size for cells, driving keyboard focus from cell to cell, rendering
34 * the actual cells, painting the focus onto the currently focused cell and finally
35 * activating cells which are %GTK_CELL_RENDERER_MODE_ACTIVATABLE and editing cells
36 * which are %GTK_CELL_RENDERER_MODE_EDITABLE. The work is even more complex since
37 * a cell renderer as opposed to a widget, is used to interact with an arbitrary
38 * number of #GtkTreeModel rows instead of always displaying the same data.
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 managemen 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 #GtkCellArea one needs to calculate
50 * the size of a handful of rows, this will be done differently by
51 * different #GtkCellLayout 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 areas maintain a fixed width
54 * and then wrap the area around, thus requesting height for more
55 * areas when allocated less width.
57 * It's also important for #GtkCellAreas to maintain some cell
58 * alignments with areas rendered for different rows so that
59 * a handful of rendered rows can allocate the same size for
60 * a said cell across rows (and also to make sure to request
61 * an appropriate size for the largest row after requesting
62 * a hand full of rows). For this reason the #GtkCellArea
63 * uses a #GtkCellAreaContext object to store the alignments
64 * and sizes along the way.
66 * In order to request the width of all the rows at the root level
67 * of a #GtkTreeModel one would do the following:
69 * <title>Requesting the width of a hand full of GtkTreeModel rows.</title>
75 * valid = gtk_tree_model_get_iter_first (model, &iter);
78 * gtk_cell_area_apply_attributes (area, model, &iter, FALSE, FALSE);
79 * gtk_cell_area_get_preferred_width (area, context, widget, NULL, NULL);
81 * valid = gtk_tree_model_iter_next (model, &iter);
83 * gtk_cell_area_context_get_preferred_width (context, &minimum_width, &natural_width);
86 * Note that in this example it's not important to observe the returned minimum and
87 * natural width of the area for each row unless the cell layouting object is actually
88 * interested in the widths of individual rows. The overall width is however stored
89 * in the accompanying #GtkCellAreaContext object and can be consulted at any time.
91 * This can be useful since #GtkCellLayout widgets usually have to support requesting
92 * and rendering rows in treemodels with an exceedingly large amount of rows. The
93 * #GtkCellLayout widget in that case would calculate the required width of the rows
94 * in an idle or timeout source (see g_timeout_add()) and when the widget is requested
95 * its actual width in #GtkWidgetClass.get_preferred_width() it can simply consult the
96 * width accumulated so far in the #GtkCellAreaContext object.
98 * A simple example where rows are rendered from top to bottom and take up the full
99 * width of the layouting widget would look like:
101 * <title>Requesting the width of a hand full of GtkTreeModel rows.</title>
104 * foo_get_preferred_width (GtkWidget *widget,
105 * gint *minimum_size,
106 * gint *natural_size)
108 * Foo *foo = FOO (widget);
109 * FooPrivate *priv = foo->priv;
111 * foo_ensure_at_least_one_handfull_of_rows_have_been_requested (foo);
113 * gtk_cell_area_context_get_preferred_width (priv->context, minimum_size, natural_size);
118 * In the above example the Foo widget has to make sure that some row sizes have
119 * been calculated (the amount of rows that Foo judged was appropriate to request
120 * space for in a single timeout iteration) before simply returning the amount
121 * of space required by the area via the #GtkCellAreaContext.
123 * Requesting the height for width (or width for height) of an area is a similar
124 * task except in this case the #GtkCellAreaContext does not store the data (actually
125 * it does not know how much space the layouting widget plans to allocate it for
126 * every row, it's up to the layouting widget to render each row of data with
127 * the appropriate height and width which was requested by the #GtkCellArea).
129 * In order to request the height for width of all the rows at the root level
130 * of a #GtkTreeModel one would do the following:
132 * <title>Requesting the height for width of a hand full of GtkTreeModel rows.</title>
135 * gint minimum_height;
136 * gint natural_height;
137 * gint full_minimum_height = 0;
138 * gint full_natural_height = 0;
140 * valid = gtk_tree_model_get_iter_first (model, &iter);
143 * gtk_cell_area_apply_attributes (area, model, &iter, FALSE, FALSE);
144 * gtk_cell_area_get_preferred_height_for_width (area, context, widget,
145 * width, &minimum_height, &natural_height);
147 * if (width_is_for_allocation)
148 * cache_row_height (&iter, minimum_height, natural_height);
150 * full_minimum_height += minimum_height;
151 * full_natural_height += natural_height;
153 * valid = gtk_tree_model_iter_next (model, &iter);
158 * Note that in the above example we would need to cache the heights returned for each
159 * treemodel row so that we would know what sizes to render the areas for each row. However
160 * we would only want to really cache the heights if the request is intended for the
161 * layouting widgets real allocation.
163 * In some cases the layouting widget is requested the height for an arbitrary for_width,
164 * this is a special case for layouting widgets who need to request size for tens of thousands
165 * of treemodel rows. For this case it's only important that the layouting widget calculate
166 * one reasonably sized chunk of rows and return that height synchronously. The reasoning here
167 * is that any layouting widget is at least capable of synchronously calculating enough
168 * height to fill the screen height (or scrolled window height) in response to a single call to
169 * #GtkWidgetClass.get_preferred_height_for_width(). Returning a perfect height for width that
170 * is larger than the screen area is inconsequential since after the layouting receives an
171 * allocation from a scrolled window it simply continues to drive the the scrollbar
172 * values while more and mode height is required for the row heights that are calculated
176 * <refsect2 id="cell-area-rendering">
177 * <title>Rendering Areas</title>
179 * Once area sizes have been aquired at least for the rows in the visible area of the
180 * layouting widget they can be rendered at #GtkWidgetClass.draw() time.
182 * A crued example of how to render all the rows at the root level runs as follows:
184 * <title>Requesting the width of a hand full of GtkTreeModel rows.</title>
186 * GtkAllocation allocation;
187 * GdkRectangle cell_area = { 0, };
189 * gint minimum_width;
190 * gint natural_width;
192 * gtk_widget_get_allocation (widget, &allocation);
193 * cell_area.width = allocation.width;
195 * valid = gtk_tree_model_get_iter_first (model, &iter);
198 * cell_area.height = get_cached_height_for_row (&iter);
200 * gtk_cell_area_apply_attributes (area, model, &iter, FALSE, FALSE);
201 * gtk_cell_area_render (area, context, widget, cr,
202 * &cell_area, &cell_area, state_flags, FALSE);
204 * cell_area.y += cell_area.height;
206 * valid = gtk_tree_model_iter_next (model, &iter);
210 * Note that the cached height in this example really depends on how the layouting
211 * widget works. The layouting widget might decide to give every row it's minimum
212 * or natural height or if the model content is expected to fit inside the layouting
213 * widget with not scrolled window it would make sense to calculate the allocation
214 * for each row at #GtkWidget.size_allocate() time using gtk_distribute_natural_allocation().
217 * <refsect2 id="cell-area-events-and-focus">
218 * <title>Handling Events and Driving Keyboard Focus</title>
220 * Passing events to the area is as simple as handling events on any normal
221 * widget and then passing them to the gtk_cell_area_event() api as they come
222 * in. Usually #GtkCellArea is only interested in button events, however some
223 * customized derived areas can be implemented who are interested in handling
224 * other events. Handling an event can trigger the #GtkCellArea::focus-changed
225 * signal to fire as well as #GtkCellArea::add-editable in the case that
226 * an editable cell was clicked and needs to start editing.
228 * The #GtkCellArea drives keyboard focus from cell to cell in a way similar
229 * to #GtkWidget. For layouting widgets that support giving focus to cells it's
230 * important to remember to pass %GTK_CELL_RENDERER_FOCUSED to the area functions
231 * for the row that has focus and to tell the area to paint the focus at render
234 * Layouting widgets that accept focus on cells should implement the #GtkWidgetClass.focus()
235 * virtual method. The layouting widget is always responsible for knowing where
236 * #GtkTreeModel rows are rendered inside the widget, so at #GtkWidgetClass.focus() time
237 * the layouting widget should use the #GtkCellArea methods to navigate focus inside the
238 * area and then observe the GtkDirectionType to pass the focus to adjacent rows and
241 * A basic example of how the #GtkWidgetClass.focus() virtual method should be implemented:
243 * <title>Implementing keyboard focus navigation when displaying rows from top to bottom.</title>
246 * foo_focus (GtkWidget *widget,
247 * GtkDirectionType direction)
249 * Foo *foo = FOO (widget);
250 * FooPrivate *priv = foo->priv;
252 * gboolean have_focus = FALSE;
254 * focus_row = priv->focus_row;
256 * if (!gtk_widget_has_focus (widget))
257 * gtk_widget_grab_focus (widget);
259 * valid = gtk_tree_model_iter_nth_child (priv->model, &iter, NULL, priv->focus_row);
262 * gtk_cell_area_apply_attributes (priv->area, priv->model, &iter, FALSE, FALSE);
264 * if (gtk_cell_area_focus (priv->area, direction))
266 * priv->focus_row = focus_row;
272 * if (direction == GTK_DIR_RIGHT ||
273 * direction == GTK_DIR_LEFT)
275 * else if (direction == GTK_DIR_UP ||
276 * direction == GTK_DIR_TAB_BACKWARD)
278 * if (focus_row == 0)
283 * valid = gtk_tree_model_iter_nth_child (priv->model, &iter, NULL, focus_row);
288 * if (focus_row == last_row)
293 * valid = gtk_tree_model_iter_next (priv->model, &iter);
314 #include "gtkcelllayout.h"
315 #include "gtkcellarea.h"
316 #include "gtkcellareacontext.h"
317 #include "gtkmarshalers.h"
318 #include "gtkprivate.h"
320 #include <gobject/gvaluecollector.h>
324 static void gtk_cell_area_dispose (GObject *object);
325 static void gtk_cell_area_finalize (GObject *object);
326 static void gtk_cell_area_set_property (GObject *object,
330 static void gtk_cell_area_get_property (GObject *object,
335 /* GtkCellAreaClass */
336 static gint gtk_cell_area_real_event (GtkCellArea *area,
337 GtkCellAreaContext *context,
340 const GdkRectangle *cell_area,
341 GtkCellRendererState flags);
342 static void gtk_cell_area_real_apply_attributes (GtkCellArea *area,
343 GtkTreeModel *tree_model,
345 gboolean is_expander,
346 gboolean is_expanded);
347 static void gtk_cell_area_real_get_preferred_height_for_width (GtkCellArea *area,
348 GtkCellAreaContext *context,
351 gint *minimum_height,
352 gint *natural_height);
353 static void gtk_cell_area_real_get_preferred_width_for_height (GtkCellArea *area,
354 GtkCellAreaContext *context,
358 gint *natural_width);
359 static gboolean gtk_cell_area_real_is_activatable (GtkCellArea *area);
360 static gboolean gtk_cell_area_real_activate (GtkCellArea *area,
361 GtkCellAreaContext *context,
363 const GdkRectangle *cell_area,
364 GtkCellRendererState flags);
366 /* GtkCellLayoutIface */
367 static void gtk_cell_area_cell_layout_init (GtkCellLayoutIface *iface);
368 static void gtk_cell_area_pack_default (GtkCellLayout *cell_layout,
369 GtkCellRenderer *renderer,
371 static void gtk_cell_area_clear (GtkCellLayout *cell_layout);
372 static void gtk_cell_area_add_attribute (GtkCellLayout *cell_layout,
373 GtkCellRenderer *renderer,
374 const gchar *attribute,
376 static void gtk_cell_area_set_cell_data_func (GtkCellLayout *cell_layout,
377 GtkCellRenderer *cell,
378 GtkCellLayoutDataFunc func,
380 GDestroyNotify destroy);
381 static void gtk_cell_area_clear_attributes (GtkCellLayout *cell_layout,
382 GtkCellRenderer *renderer);
383 static void gtk_cell_area_reorder (GtkCellLayout *cell_layout,
384 GtkCellRenderer *cell,
386 static GList *gtk_cell_area_get_cells (GtkCellLayout *cell_layout);
389 /* Used in forall loop to check if a child renderer is present */
391 GtkCellRenderer *renderer;
392 gboolean has_renderer;
395 /* Attribute/Cell metadata */
397 const gchar *attribute;
404 GtkCellLayoutDataFunc func;
406 GDestroyNotify destroy;
409 static CellInfo *cell_info_new (GtkCellLayoutDataFunc func,
411 GDestroyNotify destroy);
412 static void cell_info_free (CellInfo *info);
413 static CellAttribute *cell_attribute_new (GtkCellRenderer *renderer,
414 const gchar *attribute,
416 static void cell_attribute_free (CellAttribute *attribute);
417 static gint cell_attribute_find (CellAttribute *cell_attribute,
418 const gchar *attribute);
420 /* Internal functions/signal emissions */
421 static void gtk_cell_area_add_editable (GtkCellArea *area,
422 GtkCellRenderer *renderer,
423 GtkCellEditable *editable,
424 GdkRectangle *cell_area);
425 static void gtk_cell_area_remove_editable (GtkCellArea *area,
426 GtkCellRenderer *renderer,
427 GtkCellEditable *editable);
428 static void gtk_cell_area_set_edit_widget (GtkCellArea *area,
429 GtkCellEditable *editable);
430 static void gtk_cell_area_set_edited_cell (GtkCellArea *area,
431 GtkCellRenderer *renderer);
434 /* Struct to pass data along while looping over
435 * cell renderers to apply attributes
441 gboolean is_expander;
442 gboolean is_expanded;
445 struct _GtkCellAreaPrivate
447 /* The GtkCellArea bookkeeps any connected
448 * attributes in this hash table.
450 GHashTable *cell_info;
452 /* Current path is saved as a side-effect
453 * of gtk_cell_area_apply_attributes() */
456 /* Current cell being edited and editable widget used */
457 GtkCellEditable *edit_widget;
458 GtkCellRenderer *edited_cell;
460 /* Signal connections to the editable widget */
461 gulong remove_widget_id;
463 /* Currently focused cell */
464 GtkCellRenderer *focus_cell;
466 /* Tracking which cells are focus siblings of focusable cells */
467 GHashTable *focus_siblings;
469 /* Detail string to pass to gtk_paint_*() functions */
481 SIGNAL_APPLY_ATTRIBUTES,
483 SIGNAL_REMOVE_EDITABLE,
484 SIGNAL_FOCUS_CHANGED,
488 /* Keep the paramspec pool internal, no need to deliver notifications
489 * on cells. at least no percieved need for now */
490 static GParamSpecPool *cell_property_pool = NULL;
491 static guint cell_area_signals[LAST_SIGNAL] = { 0 };
493 #define PARAM_SPEC_PARAM_ID(pspec) ((pspec)->param_id)
494 #define PARAM_SPEC_SET_PARAM_ID(pspec, id) ((pspec)->param_id = (id))
497 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GtkCellArea, gtk_cell_area, G_TYPE_INITIALLY_UNOWNED,
498 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
499 gtk_cell_area_cell_layout_init));
502 gtk_cell_area_init (GtkCellArea *area)
504 GtkCellAreaPrivate *priv;
506 area->priv = G_TYPE_INSTANCE_GET_PRIVATE (area,
511 priv->cell_info = g_hash_table_new_full (g_direct_hash,
514 (GDestroyNotify)cell_info_free);
516 priv->focus_siblings = g_hash_table_new_full (g_direct_hash,
519 (GDestroyNotify)g_list_free);
521 priv->focus_cell = NULL;
522 priv->edited_cell = NULL;
523 priv->edit_widget = NULL;
525 priv->remove_widget_id = 0;
529 gtk_cell_area_class_init (GtkCellAreaClass *class)
531 GObjectClass *object_class = G_OBJECT_CLASS (class);
534 object_class->dispose = gtk_cell_area_dispose;
535 object_class->finalize = gtk_cell_area_finalize;
536 object_class->get_property = gtk_cell_area_get_property;
537 object_class->set_property = gtk_cell_area_set_property;
541 class->remove = NULL;
542 class->forall = NULL;
543 class->event = gtk_cell_area_real_event;
544 class->render = NULL;
545 class->apply_attributes = gtk_cell_area_real_apply_attributes;
548 class->create_context = NULL;
549 class->get_request_mode = NULL;
550 class->get_preferred_width = NULL;
551 class->get_preferred_height = NULL;
552 class->get_preferred_height_for_width = gtk_cell_area_real_get_preferred_height_for_width;
553 class->get_preferred_width_for_height = gtk_cell_area_real_get_preferred_width_for_height;
556 class->is_activatable = gtk_cell_area_real_is_activatable;
557 class->activate = gtk_cell_area_real_activate;
562 * GtkCellArea::apply-attributes:
563 * @area: the #GtkCellArea to apply the attributes to
564 * @model: the #GtkTreeModel to apply the attributes from
565 * @iter: the #GtkTreeIter indicating which row to apply the attributes of
566 * @is_expander: whether the view shows children for this row
567 * @is_expanded: whether the view is currently showing the children of this row
569 * This signal is emitted whenever applying attributes to @area from @model
571 cell_area_signals[SIGNAL_APPLY_ATTRIBUTES] =
572 g_signal_new (I_("apply-attributes"),
573 G_OBJECT_CLASS_TYPE (object_class),
575 G_STRUCT_OFFSET (GtkCellAreaClass, apply_attributes),
577 _gtk_marshal_VOID__OBJECT_BOXED_BOOLEAN_BOOLEAN,
585 * GtkCellArea::add-editable:
586 * @area: the #GtkCellArea where editing started
587 * @renderer: the #GtkCellRenderer that started the edited
588 * @editable: the #GtkCellEditable widget to add
589 * @cell_area: the #GtkWidget relative #GdkRectangle coordinates
590 * where @editable should be added
591 * @path: the #GtkTreePath string this edit was initiated for
593 * Indicates that editing has started on @renderer and that @editable
594 * should be added to the owning cell layouting widget at @cell_area.
596 cell_area_signals[SIGNAL_ADD_EDITABLE] =
597 g_signal_new (I_("add-editable"),
598 G_OBJECT_CLASS_TYPE (object_class),
600 0, /* No class closure here */
602 _gtk_marshal_VOID__OBJECT_OBJECT_BOXED_STRING,
604 GTK_TYPE_CELL_RENDERER,
605 GTK_TYPE_CELL_EDITABLE,
611 * GtkCellArea::remove-editable:
612 * @area: the #GtkCellArea where editing finished
613 * @renderer: the #GtkCellRenderer that finished editeding
614 * @editable: the #GtkCellEditable widget to remove
616 * Indicates that editing finished on @renderer and that @editable
617 * should be removed from the owning cell layouting widget.
619 cell_area_signals[SIGNAL_REMOVE_EDITABLE] =
620 g_signal_new (I_("remove-editable"),
621 G_OBJECT_CLASS_TYPE (object_class),
623 0, /* No class closure here */
625 _gtk_marshal_VOID__OBJECT_OBJECT,
627 GTK_TYPE_CELL_RENDERER,
628 GTK_TYPE_CELL_EDITABLE);
631 * GtkCellArea::focus-changed:
632 * @area: the #GtkCellArea where focus changed
633 * @renderer: the #GtkCellRenderer that has focus
634 * @path: the current #GtkTreePath string set for @area
636 * Indicates that focus changed on this @area. This signal
637 * is emitted either as a result of focus handling or event
640 * It's possible that the signal is emitted even if the
641 * currently focused renderer did not change, this is
642 * because focus may change to the same renderer in the
643 * same cell area for a different row of data.
645 cell_area_signals[SIGNAL_FOCUS_CHANGED] =
646 g_signal_new (I_("focus-changed"),
647 G_OBJECT_CLASS_TYPE (object_class),
649 0, /* No class closure here */
651 _gtk_marshal_VOID__OBJECT_STRING,
653 GTK_TYPE_CELL_RENDERER,
658 * GtkCellArea:focus-cell:
660 * The cell in the area that currently has focus
662 g_object_class_install_property (object_class,
667 P_("The cell which currently has focus"),
668 GTK_TYPE_CELL_RENDERER,
669 GTK_PARAM_READWRITE));
672 * GtkCellArea:edited-cell:
674 * The cell in the area that is currently edited
676 * This property is read-only and only changes as
677 * a result of a call gtk_cell_area_activate_cell().
679 g_object_class_install_property (object_class,
684 P_("The cell which is currently being edited"),
685 GTK_TYPE_CELL_RENDERER,
689 * GtkCellArea:edit-widget:
691 * The widget currently editing the edited cell
693 * This property is read-only and only changes as
694 * a result of a call gtk_cell_area_activate_cell().
696 g_object_class_install_property (object_class,
701 P_("The widget currently editing the edited cell"),
702 GTK_TYPE_CELL_RENDERER,
705 /* Pool for Cell Properties */
706 if (!cell_property_pool)
707 cell_property_pool = g_param_spec_pool_new (FALSE);
709 g_type_class_add_private (object_class, sizeof (GtkCellAreaPrivate));
712 /*************************************************************
714 *************************************************************/
716 cell_info_new (GtkCellLayoutDataFunc func,
718 GDestroyNotify destroy)
720 CellInfo *info = g_slice_new0 (CellInfo);
724 info->destroy = destroy;
730 cell_info_free (CellInfo *info)
733 info->destroy (info->data);
735 g_slist_foreach (info->attributes, (GFunc)cell_attribute_free, NULL);
736 g_slist_free (info->attributes);
738 g_slice_free (CellInfo, info);
741 static CellAttribute *
742 cell_attribute_new (GtkCellRenderer *renderer,
743 const gchar *attribute,
748 /* Check if the attribute really exists and point to
749 * the property string installed on the cell renderer
750 * class (dont dup the string)
752 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (renderer), attribute);
756 CellAttribute *cell_attribute = g_slice_new (CellAttribute);
758 cell_attribute->attribute = pspec->name;
759 cell_attribute->column = column;
761 return cell_attribute;
768 cell_attribute_free (CellAttribute *attribute)
770 g_slice_free (CellAttribute, attribute);
773 /* GCompareFunc for g_slist_find_custom() */
775 cell_attribute_find (CellAttribute *cell_attribute,
776 const gchar *attribute)
778 return g_strcmp0 (cell_attribute->attribute, attribute);
781 /*************************************************************
783 *************************************************************/
785 gtk_cell_area_finalize (GObject *object)
787 GtkCellArea *area = GTK_CELL_AREA (object);
788 GtkCellAreaPrivate *priv = area->priv;
790 /* All cell renderers should already be removed at this point,
791 * just kill our (empty) hash tables here.
793 g_hash_table_destroy (priv->cell_info);
794 g_hash_table_destroy (priv->focus_siblings);
796 g_free (priv->current_path);
798 G_OBJECT_CLASS (gtk_cell_area_parent_class)->finalize (object);
803 gtk_cell_area_dispose (GObject *object)
805 /* This removes every cell renderer that may be added to the GtkCellArea,
806 * subclasses should be breaking references to the GtkCellRenderers
809 gtk_cell_layout_clear (GTK_CELL_LAYOUT (object));
811 /* Remove any ref to a focused/edited cell */
812 gtk_cell_area_set_focus_cell (GTK_CELL_AREA (object), NULL);
813 gtk_cell_area_set_edited_cell (GTK_CELL_AREA (object), NULL);
814 gtk_cell_area_set_edit_widget (GTK_CELL_AREA (object), NULL);
816 G_OBJECT_CLASS (gtk_cell_area_parent_class)->dispose (object);
820 gtk_cell_area_set_property (GObject *object,
825 GtkCellArea *area = GTK_CELL_AREA (object);
829 case PROP_FOCUS_CELL:
830 gtk_cell_area_set_focus_cell (area, (GtkCellRenderer *)g_value_get_object (value));
833 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
839 gtk_cell_area_get_property (GObject *object,
844 GtkCellArea *area = GTK_CELL_AREA (object);
845 GtkCellAreaPrivate *priv = area->priv;
849 case PROP_FOCUS_CELL:
850 g_value_set_object (value, priv->focus_cell);
852 case PROP_EDITED_CELL:
853 g_value_set_object (value, priv->edited_cell);
855 case PROP_EDIT_WIDGET:
856 g_value_set_object (value, priv->edit_widget);
859 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
864 /*************************************************************
866 *************************************************************/
868 gtk_cell_area_real_event (GtkCellArea *area,
869 GtkCellAreaContext *context,
872 const GdkRectangle *cell_area,
873 GtkCellRendererState flags)
875 GtkCellAreaPrivate *priv = area->priv;
877 if (event->type == GDK_KEY_PRESS && (flags & GTK_CELL_RENDERER_FOCUSED) != 0)
879 GdkEventKey *key_event = (GdkEventKey *)event;
881 /* Cancel any edits in progress */
882 if (priv->edited_cell && (key_event->keyval == GDK_KEY_Escape))
884 gtk_cell_area_stop_editing (area, TRUE);
893 apply_cell_attributes (GtkCellRenderer *renderer,
897 CellAttribute *attribute;
899 GValue value = { 0, };
900 gboolean is_expander;
901 gboolean is_expanded;
903 g_object_freeze_notify (G_OBJECT (renderer));
905 /* Whether a row expands or is presently expanded can only be
906 * provided by the view (as these states can vary across views
907 * accessing the same model).
909 g_object_get (renderer, "is-expander", &is_expander, NULL);
910 if (is_expander != data->is_expander)
911 g_object_set (renderer, "is-expander", data->is_expander, NULL);
913 g_object_get (renderer, "is-expanded", &is_expanded, NULL);
914 if (is_expanded != data->is_expanded)
915 g_object_set (renderer, "is-expanded", data->is_expanded, NULL);
917 /* Apply the attributes directly to the renderer */
918 for (list = info->attributes; list; list = list->next)
920 attribute = list->data;
922 gtk_tree_model_get_value (data->model, data->iter, attribute->column, &value);
923 g_object_set_property (G_OBJECT (renderer), attribute->attribute, &value);
924 g_value_unset (&value);
927 /* Call any GtkCellLayoutDataFunc that may have been set by the user
930 info->func (GTK_CELL_LAYOUT (data->area), renderer,
931 data->model, data->iter, info->data);
933 g_object_thaw_notify (G_OBJECT (renderer));
937 gtk_cell_area_real_apply_attributes (GtkCellArea *area,
938 GtkTreeModel *tree_model,
940 gboolean is_expander,
941 gboolean is_expanded)
944 GtkCellAreaPrivate *priv;
950 /* Feed in data needed to apply to every renderer */
952 data.model = tree_model;
954 data.is_expander = is_expander;
955 data.is_expanded = is_expanded;
957 /* Go over any cells that have attributes or custom GtkCellLayoutDataFuncs and
958 * apply the data from the treemodel */
959 g_hash_table_foreach (priv->cell_info, (GHFunc)apply_cell_attributes, &data);
961 /* Update the currently applied path */
962 g_free (priv->current_path);
963 path = gtk_tree_model_get_path (tree_model, iter);
964 priv->current_path = gtk_tree_path_to_string (path);
965 gtk_tree_path_free (path);
969 gtk_cell_area_real_get_preferred_height_for_width (GtkCellArea *area,
970 GtkCellAreaContext *context,
973 gint *minimum_height,
974 gint *natural_height)
976 /* If the area doesnt do height-for-width, fallback on base preferred height */
977 GTK_CELL_AREA_GET_CLASS (area)->get_preferred_width (area, context, widget, minimum_height, natural_height);
981 gtk_cell_area_real_get_preferred_width_for_height (GtkCellArea *area,
982 GtkCellAreaContext *context,
988 /* If the area doesnt do width-for-height, fallback on base preferred width */
989 GTK_CELL_AREA_GET_CLASS (area)->get_preferred_width (area, context, widget, minimum_width, natural_width);
993 get_is_activatable (GtkCellRenderer *renderer,
994 gboolean *activatable)
997 if (gtk_cell_renderer_is_activatable (renderer))
1002 gtk_cell_area_real_is_activatable (GtkCellArea *area)
1004 gboolean activatable = FALSE;
1006 /* Checks if any renderer can focus for the currently applied
1009 * Subclasses can override this in the case that they are also
1010 * rendering widgets as well as renderers.
1012 gtk_cell_area_forall (area, (GtkCellCallback)get_is_activatable, &activatable);
1018 gtk_cell_area_real_activate (GtkCellArea *area,
1019 GtkCellAreaContext *context,
1021 const GdkRectangle *cell_area,
1022 GtkCellRendererState flags)
1024 GtkCellAreaPrivate *priv = area->priv;
1025 GdkRectangle background_area;
1026 GtkCellRenderer *activate_cell = NULL;
1028 if (priv->focus_cell)
1029 activate_cell = priv->focus_cell;
1034 /* GtkTreeView sometimes wants to activate a cell when no
1035 * cells are in focus.
1037 cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (area));
1038 for (l = cells; l && !activate_cell; l = l->next)
1040 GtkCellRenderer *renderer = l->data;
1042 if (gtk_cell_renderer_is_activatable (renderer))
1043 activate_cell = renderer;
1045 g_list_free (cells);
1051 /* Get the allocation of the focused cell.
1053 gtk_cell_area_get_cell_allocation (area, context, widget, activate_cell,
1054 cell_area, &background_area);
1056 /* Activate or Edit the cell
1058 * Currently just not sending an event, renderers afaics dont use
1059 * the event argument anyway, worst case is we can synthesize one.
1061 if (gtk_cell_area_activate_cell (area, widget, activate_cell, NULL,
1062 &background_area, flags))
1069 /*************************************************************
1070 * GtkCellLayoutIface *
1071 *************************************************************/
1073 gtk_cell_area_cell_layout_init (GtkCellLayoutIface *iface)
1075 iface->pack_start = gtk_cell_area_pack_default;
1076 iface->pack_end = gtk_cell_area_pack_default;
1077 iface->clear = gtk_cell_area_clear;
1078 iface->add_attribute = gtk_cell_area_add_attribute;
1079 iface->set_cell_data_func = gtk_cell_area_set_cell_data_func;
1080 iface->clear_attributes = gtk_cell_area_clear_attributes;
1081 iface->reorder = gtk_cell_area_reorder;
1082 iface->get_cells = gtk_cell_area_get_cells;
1086 gtk_cell_area_pack_default (GtkCellLayout *cell_layout,
1087 GtkCellRenderer *renderer,
1090 gtk_cell_area_add (GTK_CELL_AREA (cell_layout), renderer);
1094 gtk_cell_area_clear (GtkCellLayout *cell_layout)
1096 GtkCellArea *area = GTK_CELL_AREA (cell_layout);
1098 gtk_cell_layout_get_cells (cell_layout);
1100 for (l = cells; l; l = l->next)
1102 GtkCellRenderer *renderer = l->data;
1103 gtk_cell_area_remove (area, renderer);
1106 g_list_free (cells);
1110 gtk_cell_area_add_attribute (GtkCellLayout *cell_layout,
1111 GtkCellRenderer *renderer,
1112 const gchar *attribute,
1115 gtk_cell_area_attribute_connect (GTK_CELL_AREA (cell_layout),
1116 renderer, attribute, column);
1120 gtk_cell_area_set_cell_data_func (GtkCellLayout *cell_layout,
1121 GtkCellRenderer *renderer,
1122 GtkCellLayoutDataFunc func,
1124 GDestroyNotify destroy)
1126 GtkCellArea *area = GTK_CELL_AREA (cell_layout);
1127 GtkCellAreaPrivate *priv = area->priv;
1130 info = g_hash_table_lookup (priv->cell_info, renderer);
1134 if (info->destroy && info->data)
1135 info->destroy (info->data);
1140 info->data = func_data;
1141 info->destroy = destroy;
1147 info->destroy = NULL;
1152 info = cell_info_new (func, func_data, destroy);
1154 g_hash_table_insert (priv->cell_info, renderer, info);
1159 gtk_cell_area_clear_attributes (GtkCellLayout *cell_layout,
1160 GtkCellRenderer *renderer)
1162 GtkCellArea *area = GTK_CELL_AREA (cell_layout);
1163 GtkCellAreaPrivate *priv = area->priv;
1166 info = g_hash_table_lookup (priv->cell_info, renderer);
1170 g_slist_foreach (info->attributes, (GFunc)cell_attribute_free, NULL);
1171 g_slist_free (info->attributes);
1173 info->attributes = NULL;
1178 gtk_cell_area_reorder (GtkCellLayout *cell_layout,
1179 GtkCellRenderer *cell,
1182 g_warning ("GtkCellLayout::reorder not implemented for `%s'",
1183 g_type_name (G_TYPE_FROM_INSTANCE (cell_layout)));
1187 accum_cells (GtkCellRenderer *renderer,
1190 *accum = g_list_prepend (*accum, renderer);
1194 gtk_cell_area_get_cells (GtkCellLayout *cell_layout)
1196 GList *cells = NULL;
1198 gtk_cell_area_forall (GTK_CELL_AREA (cell_layout),
1199 (GtkCellCallback)accum_cells,
1202 return g_list_reverse (cells);
1206 /*************************************************************
1208 *************************************************************/
1211 * gtk_cell_area_add:
1212 * @area: a #GtkCellArea
1213 * @renderer: the #GtkCellRenderer to add to @area
1215 * Adds @renderer to @area with the default child cell properties.
1218 gtk_cell_area_add (GtkCellArea *area,
1219 GtkCellRenderer *renderer)
1221 GtkCellAreaClass *class;
1223 g_return_if_fail (GTK_IS_CELL_AREA (area));
1224 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1226 class = GTK_CELL_AREA_GET_CLASS (area);
1229 class->add (area, renderer);
1231 g_warning ("GtkCellAreaClass::add not implemented for `%s'",
1232 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1236 * gtk_cell_area_remove:
1237 * @area: a #GtkCellArea
1238 * @renderer: the #GtkCellRenderer to add to @area
1240 * Removes @renderer from @area.
1243 gtk_cell_area_remove (GtkCellArea *area,
1244 GtkCellRenderer *renderer)
1246 GtkCellAreaClass *class;
1247 GtkCellAreaPrivate *priv;
1248 GList *renderers, *l;
1250 g_return_if_fail (GTK_IS_CELL_AREA (area));
1251 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1253 class = GTK_CELL_AREA_GET_CLASS (area);
1256 /* Remove any custom attributes and custom cell data func here first */
1257 g_hash_table_remove (priv->cell_info, renderer);
1259 /* Remove focus siblings of this renderer */
1260 g_hash_table_remove (priv->focus_siblings, renderer);
1262 /* Remove this renderer from any focus renderer's sibling list */
1263 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (area));
1265 for (l = renderers; l; l = l->next)
1267 GtkCellRenderer *focus_renderer = l->data;
1269 if (gtk_cell_area_is_focus_sibling (area, focus_renderer, renderer))
1271 gtk_cell_area_remove_focus_sibling (area, focus_renderer, renderer);
1276 g_list_free (renderers);
1279 class->remove (area, renderer);
1281 g_warning ("GtkCellAreaClass::remove not implemented for `%s'",
1282 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1286 get_has_renderer (GtkCellRenderer *renderer,
1287 HasRendererCheck *check)
1289 if (renderer == check->renderer)
1290 check->has_renderer = TRUE;
1294 * gtk_cell_area_has_renderer:
1295 * @area: a #GtkCellArea
1296 * @renderer: the #GtkCellRenderer to check
1298 * Checks if @area contains @renderer.
1300 * Returns: %TRUE if @renderer is in the @area.
1303 gtk_cell_area_has_renderer (GtkCellArea *area,
1304 GtkCellRenderer *renderer)
1306 HasRendererCheck check = { renderer, FALSE };
1308 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
1309 g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), FALSE);
1311 gtk_cell_area_forall (area, (GtkCellCallback)get_has_renderer, &check);
1313 return check.has_renderer;
1317 * gtk_cell_area_forall:
1318 * @area: a #GtkCellArea
1319 * @callback: the #GtkCellCallback to call
1320 * @callback_data: user provided data pointer
1322 * Calls @callback for every #GtkCellRenderer in @area.
1325 gtk_cell_area_forall (GtkCellArea *area,
1326 GtkCellCallback callback,
1327 gpointer callback_data)
1329 GtkCellAreaClass *class;
1331 g_return_if_fail (GTK_IS_CELL_AREA (area));
1332 g_return_if_fail (callback != NULL);
1334 class = GTK_CELL_AREA_GET_CLASS (area);
1337 class->forall (area, callback, callback_data);
1339 g_warning ("GtkCellAreaClass::forall not implemented for `%s'",
1340 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1344 * gtk_cell_area_get_cell_allocation:
1345 * @area: a #GtkCellArea
1346 * @context: the #GtkCellAreaContext used to hold sizes for @area.
1347 * @widget: the #GtkWidget that @area is rendering on
1348 * @renderer: the #GtkCellRenderer to get the allocation for
1349 * @cell_area: the whole allocated area for @area in @widget
1351 * @allocation: where to store the allocation for @renderer
1353 * Derives the allocation of @renderer inside @area if @area
1354 * were to be renderered in @cell_area.
1357 gtk_cell_area_get_cell_allocation (GtkCellArea *area,
1358 GtkCellAreaContext *context,
1360 GtkCellRenderer *renderer,
1361 const GdkRectangle *cell_area,
1362 GdkRectangle *allocation)
1364 GtkCellAreaClass *class;
1366 g_return_if_fail (GTK_IS_CELL_AREA (area));
1367 g_return_if_fail (GTK_IS_CELL_AREA_CONTEXT (context));
1368 g_return_if_fail (GTK_IS_WIDGET (widget));
1369 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1370 g_return_if_fail (cell_area != NULL);
1371 g_return_if_fail (allocation != NULL);
1373 class = GTK_CELL_AREA_GET_CLASS (area);
1375 if (class->get_cell_allocation)
1376 class->get_cell_allocation (area, context, widget, renderer, cell_area, allocation);
1378 g_warning ("GtkCellAreaClass::get_cell_allocation not implemented for `%s'",
1379 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1383 * gtk_cell_area_event:
1384 * @area: a #GtkCellArea
1385 * @context: the #GtkCellAreaContext for this row of data.
1386 * @widget: the #GtkWidget that @area is rendering to
1387 * @event: the #GdkEvent to handle
1388 * @cell_area: the @widget relative coordinates for @area
1389 * @flags: the #GtkCellRendererState for @area in this row.
1391 * Delegates event handling to a #GtkCellArea.
1393 * Returns: %TRUE if the event was handled by @area.
1396 gtk_cell_area_event (GtkCellArea *area,
1397 GtkCellAreaContext *context,
1400 const GdkRectangle *cell_area,
1401 GtkCellRendererState flags)
1403 GtkCellAreaClass *class;
1405 g_return_val_if_fail (GTK_IS_CELL_AREA (area), 0);
1406 g_return_val_if_fail (GTK_IS_CELL_AREA_CONTEXT (context), 0);
1407 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
1408 g_return_val_if_fail (event != NULL, 0);
1409 g_return_val_if_fail (cell_area != NULL, 0);
1411 class = GTK_CELL_AREA_GET_CLASS (area);
1414 return class->event (area, context, widget, event, cell_area, flags);
1416 g_warning ("GtkCellAreaClass::event not implemented for `%s'",
1417 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1422 * gtk_cell_area_render:
1423 * @area: a #GtkCellArea
1424 * @context: the #GtkCellAreaContext for this row of data.
1425 * @widget: the #GtkWidget that @area is rendering to
1426 * @cr: the #cairo_t to render with
1427 * @background_area: the @widget relative coordinates for @area's background
1428 * @cell_area: the @widget relative coordinates for @area
1429 * @flags: the #GtkCellRendererState for @area in this row.
1430 * @paint_focus: whether @area should paint focus on focused cells for focused rows or not.
1432 * Renders @area's cells according to @area's layout onto @widget at
1433 * the given coordinates.
1436 gtk_cell_area_render (GtkCellArea *area,
1437 GtkCellAreaContext *context,
1440 const GdkRectangle *background_area,
1441 const GdkRectangle *cell_area,
1442 GtkCellRendererState flags,
1443 gboolean paint_focus)
1445 GtkCellAreaClass *class;
1447 g_return_if_fail (GTK_IS_CELL_AREA (area));
1448 g_return_if_fail (GTK_IS_CELL_AREA_CONTEXT (context));
1449 g_return_if_fail (GTK_IS_WIDGET (widget));
1450 g_return_if_fail (cr != NULL);
1451 g_return_if_fail (background_area != NULL);
1452 g_return_if_fail (cell_area != NULL);
1454 class = GTK_CELL_AREA_GET_CLASS (area);
1457 class->render (area, context, widget, cr, background_area, cell_area, flags, paint_focus);
1459 g_warning ("GtkCellAreaClass::render not implemented for `%s'",
1460 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1464 * gtk_cell_area_set_style_detail:
1465 * @area: a #GtkCellArea
1466 * @detail: the #GtkStyle detail string to set
1468 * Sets the detail string used in any gtk_paint_*() functions
1472 gtk_cell_area_set_style_detail (GtkCellArea *area,
1473 const gchar *detail)
1475 GtkCellAreaPrivate *priv;
1477 g_return_if_fail (GTK_IS_CELL_AREA (area));
1481 if (g_strcmp0 (priv->style_detail, detail) != 0)
1483 g_free (priv->style_detail);
1484 priv->style_detail = g_strdup (detail);
1489 * gtk_cell_area_get_style_detail:
1490 * @area: a #GtkCellArea
1492 * Gets the detail string used in any gtk_paint_*() functions
1495 * Returns: the detail string.
1497 G_CONST_RETURN gchar *
1498 gtk_cell_area_get_style_detail (GtkCellArea *area)
1500 GtkCellAreaPrivate *priv;
1502 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
1506 return priv->style_detail;
1509 /*************************************************************
1511 *************************************************************/
1513 * gtk_cell_area_create_context:
1514 * @area: a #GtkCellArea
1516 * Creates a #GtkCellAreaContext to be used with @area for
1517 * all purposes. #GtkCellAreaContext stores geometry information
1518 * for rows for which it was operated on, it is important to use
1519 * the same context for the same row of data at all times (i.e.
1520 * one should render and handle events with the same #GtkCellAreaContext
1521 * which was used to request the size of those rows of data).
1523 * Returns: a newly created #GtkCellAreaContext which can be used with @area.
1525 GtkCellAreaContext *
1526 gtk_cell_area_create_context (GtkCellArea *area)
1528 GtkCellAreaClass *class;
1530 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
1532 class = GTK_CELL_AREA_GET_CLASS (area);
1534 if (class->create_context)
1535 return class->create_context (area);
1537 g_warning ("GtkCellAreaClass::create_context not implemented for `%s'",
1538 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1545 * gtk_cell_area_get_request_mode:
1546 * @area: a #GtkCellArea
1548 * Gets whether the area prefers a height-for-width layout
1549 * or a width-for-height layout.
1551 * Returns: The #GtkSizeRequestMode preferred by @area.
1556 gtk_cell_area_get_request_mode (GtkCellArea *area)
1558 GtkCellAreaClass *class;
1560 g_return_val_if_fail (GTK_IS_CELL_AREA (area),
1561 GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH);
1563 class = GTK_CELL_AREA_GET_CLASS (area);
1565 if (class->get_request_mode)
1566 return class->get_request_mode (area);
1568 g_warning ("GtkCellAreaClass::get_request_mode not implemented for `%s'",
1569 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1571 return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
1575 * gtk_cell_area_get_preferred_width:
1576 * @area: a #GtkCellArea
1577 * @context: the #GtkCellAreaContext to perform this request with
1578 * @widget: the #GtkWidget where @area will be rendering
1579 * @minimum_width: (out) (allow-none): location to store the minimum width, or %NULL
1580 * @natural_width: (out) (allow-none): location to store the natural width, or %NULL
1582 * Retrieves a cell area's initial minimum and natural width.
1584 * @area will store some geometrical information in @context along the way,
1585 * when requesting sizes over an arbitrary number of rows, its not important
1586 * to check the @minimum_width and @natural_width of this call but rather to
1587 * consult gtk_cell_area_context_get_preferred_width() after a series of
1594 gtk_cell_area_get_preferred_width (GtkCellArea *area,
1595 GtkCellAreaContext *context,
1597 gint *minimum_width,
1598 gint *natural_width)
1600 GtkCellAreaClass *class;
1602 g_return_if_fail (GTK_IS_CELL_AREA (area));
1603 g_return_if_fail (GTK_IS_WIDGET (widget));
1605 class = GTK_CELL_AREA_GET_CLASS (area);
1607 if (class->get_preferred_width)
1608 class->get_preferred_width (area, context, widget, minimum_width, natural_width);
1610 g_warning ("GtkCellAreaClass::get_preferred_width not implemented for `%s'",
1611 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1615 * gtk_cell_area_get_preferred_height_for_width:
1616 * @area: a #GtkCellArea
1617 * @context: the #GtkCellAreaContext which has already been requested for widths.
1618 * @widget: the #GtkWidget where @area will be rendering
1619 * @width: the width for which to check the height of this area
1620 * @minimum_height: (out) (allow-none): location to store the minimum height, or %NULL
1621 * @natural_height: (out) (allow-none): location to store the natural height, or %NULL
1623 * Retrieves a cell area's minimum and natural height if it would be given
1624 * the specified @width.
1626 * @area stores some geometrical information in @context along the way
1627 * while calling gtk_cell_area_get_preferred_width(), it's important to
1628 * perform a series of gtk_cell_area_get_preferred_width() requests with
1629 * @context first and then call gtk_cell_area_get_preferred_height_for_width()
1630 * on each cell area individually to get the height for width of each
1631 * fully requested row.
1633 * If at some point, the width of a single row changes, it should be
1634 * requested with gtk_cell_area_get_preferred_width() again and then
1635 * the full width of the requested rows checked again with
1636 * gtk_cell_area_context_get_preferred_width().
1641 gtk_cell_area_get_preferred_height_for_width (GtkCellArea *area,
1642 GtkCellAreaContext *context,
1645 gint *minimum_height,
1646 gint *natural_height)
1648 GtkCellAreaClass *class;
1650 g_return_if_fail (GTK_IS_CELL_AREA (area));
1651 g_return_if_fail (GTK_IS_WIDGET (widget));
1653 class = GTK_CELL_AREA_GET_CLASS (area);
1654 class->get_preferred_height_for_width (area, context, widget, width, minimum_height, natural_height);
1659 * gtk_cell_area_get_preferred_height:
1660 * @area: a #GtkCellArea
1661 * @context: the #GtkCellAreaContext to perform this request with
1662 * @widget: the #GtkWidget where @area will be rendering
1663 * @minimum_height: (out) (allow-none): location to store the minimum height, or %NULL
1664 * @natural_height: (out) (allow-none): location to store the natural height, or %NULL
1666 * Retrieves a cell area's initial minimum and natural height.
1668 * @area will store some geometrical information in @context along the way,
1669 * when requesting sizes over an arbitrary number of rows, its not important
1670 * to check the @minimum_height and @natural_height of this call but rather to
1671 * consult gtk_cell_area_context_get_preferred_height() after a series of
1677 gtk_cell_area_get_preferred_height (GtkCellArea *area,
1678 GtkCellAreaContext *context,
1680 gint *minimum_height,
1681 gint *natural_height)
1683 GtkCellAreaClass *class;
1685 g_return_if_fail (GTK_IS_CELL_AREA (area));
1686 g_return_if_fail (GTK_IS_WIDGET (widget));
1688 class = GTK_CELL_AREA_GET_CLASS (area);
1690 if (class->get_preferred_height)
1691 class->get_preferred_height (area, context, widget, minimum_height, natural_height);
1693 g_warning ("GtkCellAreaClass::get_preferred_height not implemented for `%s'",
1694 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1698 * gtk_cell_area_get_preferred_width_for_height:
1699 * @area: a #GtkCellArea
1700 * @context: the #GtkCellAreaContext which has already been requested for widths.
1701 * @widget: the #GtkWidget where @area will be rendering
1702 * @height: the height for which to check the width of this area
1703 * @minimum_width: (out) (allow-none): location to store the minimum width, or %NULL
1704 * @natural_width: (out) (allow-none): location to store the natural width, or %NULL
1706 * Retrieves a cell area's minimum and natural width if it would be given
1707 * the specified @height.
1709 * @area stores some geometrical information in @context along the way
1710 * while calling gtk_cell_area_get_preferred_height(), it's important to
1711 * perform a series of gtk_cell_area_get_preferred_height() requests with
1712 * @context first and then call gtk_cell_area_get_preferred_width_for_height()
1713 * on each cell area individually to get the height for width of each
1714 * fully requested row.
1716 * If at some point, the height of a single row changes, it should be
1717 * requested with gtk_cell_area_get_preferred_height() again and then
1718 * the full height of the requested rows checked again with
1719 * gtk_cell_area_context_get_preferred_height().
1724 gtk_cell_area_get_preferred_width_for_height (GtkCellArea *area,
1725 GtkCellAreaContext *context,
1728 gint *minimum_width,
1729 gint *natural_width)
1731 GtkCellAreaClass *class;
1733 g_return_if_fail (GTK_IS_CELL_AREA (area));
1734 g_return_if_fail (GTK_IS_WIDGET (widget));
1736 class = GTK_CELL_AREA_GET_CLASS (area);
1737 class->get_preferred_width_for_height (area, context, widget, height, minimum_width, natural_width);
1740 /*************************************************************
1742 *************************************************************/
1745 * gtk_cell_area_attribute_connect:
1746 * @area: a #GtkCellArea
1747 * @renderer: the #GtkCellRenderer to connect an attribute for
1748 * @attribute: the attribute name
1749 * @column: the #GtkTreeModel column to fetch attribute values from
1751 * Connects an @attribute to apply values from @column for the
1752 * #GtkTreeModel in use.
1755 gtk_cell_area_attribute_connect (GtkCellArea *area,
1756 GtkCellRenderer *renderer,
1757 const gchar *attribute,
1760 GtkCellAreaPrivate *priv;
1762 CellAttribute *cell_attribute;
1764 g_return_if_fail (GTK_IS_CELL_AREA (area));
1765 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1766 g_return_if_fail (attribute != NULL);
1767 g_return_if_fail (gtk_cell_area_has_renderer (area, renderer));
1770 info = g_hash_table_lookup (priv->cell_info, renderer);
1774 info = cell_info_new (NULL, NULL, NULL);
1776 g_hash_table_insert (priv->cell_info, renderer, info);
1782 /* Check we are not adding the same attribute twice */
1783 if ((node = g_slist_find_custom (info->attributes, attribute,
1784 (GCompareFunc)cell_attribute_find)) != NULL)
1786 cell_attribute = node->data;
1788 g_warning ("Cannot connect attribute `%s' for cell renderer class `%s' "
1789 "since `%s' is already attributed to column %d",
1791 g_type_name (G_TYPE_FROM_INSTANCE (area)),
1792 attribute, cell_attribute->column);
1797 cell_attribute = cell_attribute_new (renderer, attribute, column);
1799 if (!cell_attribute)
1801 g_warning ("Cannot connect attribute `%s' for cell renderer class `%s' "
1802 "since attribute does not exist",
1804 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1808 info->attributes = g_slist_prepend (info->attributes, cell_attribute);
1812 * gtk_cell_area_attribute_disconnect:
1813 * @area: a #GtkCellArea
1814 * @renderer: the #GtkCellRenderer to disconnect an attribute for
1815 * @attribute: the attribute name
1817 * Disconnects @attribute for the @renderer in @area so that
1818 * attribute will no longer be updated with values from the
1822 gtk_cell_area_attribute_disconnect (GtkCellArea *area,
1823 GtkCellRenderer *renderer,
1824 const gchar *attribute)
1826 GtkCellAreaPrivate *priv;
1828 CellAttribute *cell_attribute;
1831 g_return_if_fail (GTK_IS_CELL_AREA (area));
1832 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1833 g_return_if_fail (attribute != NULL);
1834 g_return_if_fail (gtk_cell_area_has_renderer (area, renderer));
1837 info = g_hash_table_lookup (priv->cell_info, renderer);
1841 node = g_slist_find_custom (info->attributes, attribute,
1842 (GCompareFunc)cell_attribute_find);
1845 cell_attribute = node->data;
1847 cell_attribute_free (cell_attribute);
1849 info->attributes = g_slist_delete_link (info->attributes, node);
1855 * gtk_cell_area_apply_attributes
1856 * @area: a #GtkCellArea
1857 * @tree_model: a #GtkTreeModel to pull values from
1858 * @iter: the #GtkTreeIter in @tree_model to apply values for
1859 * @is_expander: whether @iter has children
1860 * @is_expanded: whether @iter is expanded in the view and
1861 * children are visible
1863 * Applies any connected attributes to the renderers in
1864 * @area by pulling the values from @tree_model.
1867 gtk_cell_area_apply_attributes (GtkCellArea *area,
1868 GtkTreeModel *tree_model,
1870 gboolean is_expander,
1871 gboolean is_expanded)
1873 g_return_if_fail (GTK_IS_CELL_AREA (area));
1874 g_return_if_fail (GTK_IS_TREE_MODEL (tree_model));
1875 g_return_if_fail (iter != NULL);
1877 g_signal_emit (area, cell_area_signals[SIGNAL_APPLY_ATTRIBUTES], 0,
1878 tree_model, iter, is_expander, is_expanded);
1882 * gtk_cell_area_get_current_path_string:
1883 * @area: a #GtkCellArea
1885 * Gets the current #GtkTreePath string for the currently
1886 * applied #GtkTreeIter, this is implicitly updated when
1887 * gtk_cell_area_apply_attributes() is called and can be
1888 * used to interact with renderers from #GtkCellArea
1892 gtk_cell_area_get_current_path_string (GtkCellArea *area)
1894 GtkCellAreaPrivate *priv;
1896 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
1900 return priv->current_path;
1904 /*************************************************************
1905 * API: Cell Properties *
1906 *************************************************************/
1908 * gtk_cell_area_class_install_cell_property:
1909 * @aclass: a #GtkCellAreaClass
1910 * @property_id: the id for the property
1911 * @pspec: the #GParamSpec for the property
1913 * Installs a cell property on a cell area class.
1916 gtk_cell_area_class_install_cell_property (GtkCellAreaClass *aclass,
1920 g_return_if_fail (GTK_IS_CELL_AREA_CLASS (aclass));
1921 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1922 if (pspec->flags & G_PARAM_WRITABLE)
1923 g_return_if_fail (aclass->set_cell_property != NULL);
1924 if (pspec->flags & G_PARAM_READABLE)
1925 g_return_if_fail (aclass->get_cell_property != NULL);
1926 g_return_if_fail (property_id > 0);
1927 g_return_if_fail (PARAM_SPEC_PARAM_ID (pspec) == 0); /* paranoid */
1928 g_return_if_fail ((pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY)) == 0);
1930 if (g_param_spec_pool_lookup (cell_property_pool, pspec->name, G_OBJECT_CLASS_TYPE (aclass), TRUE))
1932 g_warning (G_STRLOC ": class `%s' already contains a cell property named `%s'",
1933 G_OBJECT_CLASS_NAME (aclass), pspec->name);
1936 g_param_spec_ref (pspec);
1937 g_param_spec_sink (pspec);
1938 PARAM_SPEC_SET_PARAM_ID (pspec, property_id);
1939 g_param_spec_pool_insert (cell_property_pool, pspec, G_OBJECT_CLASS_TYPE (aclass));
1943 * gtk_cell_area_class_find_cell_property:
1944 * @aclass: a #GtkCellAreaClass
1945 * @property_name: the name of the child property to find
1946 * @returns: (allow-none): the #GParamSpec of the child property or %NULL if @aclass has no
1947 * child property with that name.
1949 * Finds a cell property of a cell area class by name.
1952 gtk_cell_area_class_find_cell_property (GtkCellAreaClass *aclass,
1953 const gchar *property_name)
1955 g_return_val_if_fail (GTK_IS_CELL_AREA_CLASS (aclass), NULL);
1956 g_return_val_if_fail (property_name != NULL, NULL);
1958 return g_param_spec_pool_lookup (cell_property_pool,
1960 G_OBJECT_CLASS_TYPE (aclass),
1965 * gtk_cell_area_class_list_cell_properties:
1966 * @aclass: a #GtkCellAreaClass
1967 * @n_properties: location to return the number of cell properties found
1968 * @returns: a newly allocated %NULL-terminated array of #GParamSpec*.
1969 * The array must be freed with g_free().
1971 * Returns all cell properties of a cell area class.
1974 gtk_cell_area_class_list_cell_properties (GtkCellAreaClass *aclass,
1975 guint *n_properties)
1977 GParamSpec **pspecs;
1980 g_return_val_if_fail (GTK_IS_CELL_AREA_CLASS (aclass), NULL);
1982 pspecs = g_param_spec_pool_list (cell_property_pool,
1983 G_OBJECT_CLASS_TYPE (aclass),
1992 * gtk_cell_area_add_with_properties:
1993 * @area: a #GtkCellArea
1994 * @renderer: a #GtkCellRenderer to be placed inside @area
1995 * @first_prop_name: the name of the first cell property to set
1996 * @Varargs: a %NULL-terminated list of property names and values, starting
1997 * with @first_prop_name
1999 * Adds @renderer to @area, setting cell properties at the same time.
2000 * See gtk_cell_area_add() and gtk_cell_area_child_set() for more details.
2003 gtk_cell_area_add_with_properties (GtkCellArea *area,
2004 GtkCellRenderer *renderer,
2005 const gchar *first_prop_name,
2008 GtkCellAreaClass *class;
2010 g_return_if_fail (GTK_IS_CELL_AREA (area));
2011 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2013 class = GTK_CELL_AREA_GET_CLASS (area);
2019 class->add (area, renderer);
2021 va_start (var_args, first_prop_name);
2022 gtk_cell_area_cell_set_valist (area, renderer, first_prop_name, var_args);
2026 g_warning ("GtkCellAreaClass::add not implemented for `%s'",
2027 g_type_name (G_TYPE_FROM_INSTANCE (area)));
2031 * gtk_cell_area_cell_set:
2032 * @area: a #GtkCellArea
2033 * @renderer: a #GtkCellRenderer which is a cell inside @area
2034 * @first_prop_name: the name of the first cell property to set
2035 * @Varargs: a %NULL-terminated list of property names and values, starting
2036 * with @first_prop_name
2038 * Sets one or more cell properties for @cell in @area.
2041 gtk_cell_area_cell_set (GtkCellArea *area,
2042 GtkCellRenderer *renderer,
2043 const gchar *first_prop_name,
2048 g_return_if_fail (GTK_IS_CELL_AREA (area));
2049 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2051 va_start (var_args, first_prop_name);
2052 gtk_cell_area_cell_set_valist (area, renderer, first_prop_name, var_args);
2057 * gtk_cell_area_cell_get:
2058 * @area: a #GtkCellArea
2059 * @renderer: a #GtkCellRenderer which is inside @area
2060 * @first_prop_name: the name of the first cell property to get
2061 * @Varargs: return location for the first cell property, followed
2062 * optionally by more name/return location pairs, followed by %NULL
2064 * Gets the values of one or more cell properties for @renderer in @area.
2067 gtk_cell_area_cell_get (GtkCellArea *area,
2068 GtkCellRenderer *renderer,
2069 const gchar *first_prop_name,
2074 g_return_if_fail (GTK_IS_CELL_AREA (area));
2075 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2077 va_start (var_args, first_prop_name);
2078 gtk_cell_area_cell_get_valist (area, renderer, first_prop_name, var_args);
2083 area_get_cell_property (GtkCellArea *area,
2084 GtkCellRenderer *renderer,
2088 GtkCellAreaClass *class = g_type_class_peek (pspec->owner_type);
2090 class->get_cell_property (area, renderer, PARAM_SPEC_PARAM_ID (pspec), value, pspec);
2094 area_set_cell_property (GtkCellArea *area,
2095 GtkCellRenderer *renderer,
2097 const GValue *value)
2099 GValue tmp_value = { 0, };
2100 GtkCellAreaClass *class = g_type_class_peek (pspec->owner_type);
2102 /* provide a copy to work from, convert (if necessary) and validate */
2103 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2104 if (!g_value_transform (value, &tmp_value))
2105 g_warning ("unable to set cell property `%s' of type `%s' from value of type `%s'",
2107 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
2108 G_VALUE_TYPE_NAME (value));
2109 else if (g_param_value_validate (pspec, &tmp_value) && !(pspec->flags & G_PARAM_LAX_VALIDATION))
2111 gchar *contents = g_strdup_value_contents (value);
2113 g_warning ("value \"%s\" of type `%s' is invalid for property `%s' of type `%s'",
2115 G_VALUE_TYPE_NAME (value),
2117 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
2122 class->set_cell_property (area, renderer, PARAM_SPEC_PARAM_ID (pspec), &tmp_value, pspec);
2124 g_value_unset (&tmp_value);
2128 * gtk_cell_area_cell_set_valist:
2129 * @area: a #GtkCellArea
2130 * @renderer: a #GtkCellRenderer which inside @area
2131 * @first_property_name: the name of the first cell property to set
2132 * @var_args: a %NULL-terminated list of property names and values, starting
2133 * with @first_prop_name
2135 * Sets one or more cell properties for @renderer in @area.
2138 gtk_cell_area_cell_set_valist (GtkCellArea *area,
2139 GtkCellRenderer *renderer,
2140 const gchar *first_property_name,
2145 g_return_if_fail (GTK_IS_CELL_AREA (area));
2146 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2148 name = first_property_name;
2151 GValue value = { 0, };
2152 gchar *error = NULL;
2154 g_param_spec_pool_lookup (cell_property_pool, name,
2155 G_OBJECT_TYPE (area), TRUE);
2158 g_warning ("%s: cell area class `%s' has no cell property named `%s'",
2159 G_STRLOC, G_OBJECT_TYPE_NAME (area), name);
2162 if (!(pspec->flags & G_PARAM_WRITABLE))
2164 g_warning ("%s: cell property `%s' of cell area class `%s' is not writable",
2165 G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
2169 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2170 G_VALUE_COLLECT (&value, var_args, 0, &error);
2173 g_warning ("%s: %s", G_STRLOC, error);
2176 /* we purposely leak the value here, it might not be
2177 * in a sane state if an error condition occoured
2181 area_set_cell_property (area, renderer, pspec, &value);
2182 g_value_unset (&value);
2183 name = va_arg (var_args, gchar*);
2188 * gtk_cell_area_cell_get_valist:
2189 * @area: a #GtkCellArea
2190 * @renderer: a #GtkCellRenderer inside @area
2191 * @first_property_name: the name of the first property to get
2192 * @var_args: return location for the first property, followed
2193 * optionally by more name/return location pairs, followed by %NULL
2195 * Gets the values of one or more cell properties for @renderer in @area.
2198 gtk_cell_area_cell_get_valist (GtkCellArea *area,
2199 GtkCellRenderer *renderer,
2200 const gchar *first_property_name,
2205 g_return_if_fail (GTK_IS_CELL_AREA (area));
2206 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2208 name = first_property_name;
2211 GValue value = { 0, };
2215 pspec = g_param_spec_pool_lookup (cell_property_pool, name,
2216 G_OBJECT_TYPE (area), TRUE);
2219 g_warning ("%s: cell area class `%s' has no cell property named `%s'",
2220 G_STRLOC, G_OBJECT_TYPE_NAME (area), name);
2223 if (!(pspec->flags & G_PARAM_READABLE))
2225 g_warning ("%s: cell property `%s' of cell area class `%s' is not readable",
2226 G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
2230 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2231 area_get_cell_property (area, renderer, pspec, &value);
2232 G_VALUE_LCOPY (&value, var_args, 0, &error);
2235 g_warning ("%s: %s", G_STRLOC, error);
2237 g_value_unset (&value);
2240 g_value_unset (&value);
2241 name = va_arg (var_args, gchar*);
2246 * gtk_cell_area_cell_set_property:
2247 * @area: a #GtkCellArea
2248 * @renderer: a #GtkCellRenderer inside @area
2249 * @property_name: the name of the cell property to set
2250 * @value: the value to set the cell property to
2252 * Sets a cell property for @renderer in @area.
2255 gtk_cell_area_cell_set_property (GtkCellArea *area,
2256 GtkCellRenderer *renderer,
2257 const gchar *property_name,
2258 const GValue *value)
2262 g_return_if_fail (GTK_IS_CELL_AREA (area));
2263 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2264 g_return_if_fail (property_name != NULL);
2265 g_return_if_fail (G_IS_VALUE (value));
2267 pspec = g_param_spec_pool_lookup (cell_property_pool, property_name,
2268 G_OBJECT_TYPE (area), TRUE);
2270 g_warning ("%s: cell area class `%s' has no cell property named `%s'",
2271 G_STRLOC, G_OBJECT_TYPE_NAME (area), property_name);
2272 else if (!(pspec->flags & G_PARAM_WRITABLE))
2273 g_warning ("%s: cell property `%s' of cell area class `%s' is not writable",
2274 G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
2277 area_set_cell_property (area, renderer, pspec, value);
2282 * gtk_cell_area_cell_get_property:
2283 * @area: a #GtkCellArea
2284 * @renderer: a #GtkCellRenderer inside @area
2285 * @property_name: the name of the property to get
2286 * @value: a location to return the value
2288 * Gets the value of a cell property for @renderer in @area.
2291 gtk_cell_area_cell_get_property (GtkCellArea *area,
2292 GtkCellRenderer *renderer,
2293 const gchar *property_name,
2298 g_return_if_fail (GTK_IS_CELL_AREA (area));
2299 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2300 g_return_if_fail (property_name != NULL);
2301 g_return_if_fail (G_IS_VALUE (value));
2303 pspec = g_param_spec_pool_lookup (cell_property_pool, property_name,
2304 G_OBJECT_TYPE (area), TRUE);
2306 g_warning ("%s: cell area class `%s' has no cell property named `%s'",
2307 G_STRLOC, G_OBJECT_TYPE_NAME (area), property_name);
2308 else if (!(pspec->flags & G_PARAM_READABLE))
2309 g_warning ("%s: cell property `%s' of cell area class `%s' is not readable",
2310 G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
2313 GValue *prop_value, tmp_value = { 0, };
2315 /* auto-conversion of the callers value type
2317 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
2319 g_value_reset (value);
2322 else if (!g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
2324 g_warning ("can't retrieve cell property `%s' of type `%s' as value of type `%s'",
2326 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
2327 G_VALUE_TYPE_NAME (value));
2332 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2333 prop_value = &tmp_value;
2336 area_get_cell_property (area, renderer, pspec, prop_value);
2338 if (prop_value != value)
2340 g_value_transform (prop_value, value);
2341 g_value_unset (&tmp_value);
2346 /*************************************************************
2348 *************************************************************/
2351 * gtk_cell_area_is_activatable:
2352 * @area: a #GtkCellArea
2354 * Returns whether the area can do anything when activated,
2355 * after applying new attributes to @area.
2357 * Returns: whether @area can do anything when activated.
2360 gtk_cell_area_is_activatable (GtkCellArea *area)
2362 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2364 return GTK_CELL_AREA_GET_CLASS (area)->is_activatable (area);
2368 * gtk_cell_area_focus:
2369 * @area: a #GtkCellArea
2370 * @direction: the #GtkDirectionType
2372 * This should be called by the @area's owning layout widget
2373 * when focus is to be passed to @area, or moved within @area
2374 * for a given @direction and row data.
2376 * Implementing #GtkCellArea classes should implement this
2377 * method to receive and navigate focus in it's own way particular
2378 * to how it lays out cells.
2380 * Returns: %TRUE if focus remains inside @area as a result of this call.
2383 gtk_cell_area_focus (GtkCellArea *area,
2384 GtkDirectionType direction)
2386 GtkCellAreaClass *class;
2388 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2390 class = GTK_CELL_AREA_GET_CLASS (area);
2393 return class->focus (area, direction);
2395 g_warning ("GtkCellAreaClass::focus not implemented for `%s'",
2396 g_type_name (G_TYPE_FROM_INSTANCE (area)));
2402 * gtk_cell_area_activate:
2403 * @area: a #GtkCellArea
2404 * @context: the #GtkCellAreaContext in context with the current row data
2405 * @widget: the #GtkWidget that @area is rendering on
2406 * @cell_area: the size and location of @area relative to @widget's allocation
2407 * @flags: the #GtkCellRendererState flags for @area for this row of data.
2409 * Activates @area, usually by activating the currently focused
2410 * cell, however some subclasses which embed widgets in the area
2411 * can also activate a widget if it currently has the focus.
2413 * Returns: Whether @area was successfully activated.
2416 gtk_cell_area_activate (GtkCellArea *area,
2417 GtkCellAreaContext *context,
2419 const GdkRectangle *cell_area,
2420 GtkCellRendererState flags)
2422 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2424 return GTK_CELL_AREA_GET_CLASS (area)->activate (area, context, widget, cell_area, flags);
2429 * gtk_cell_area_set_focus_cell:
2430 * @area: a #GtkCellArea
2431 * @focus_cell: the #GtkCellRenderer to give focus to
2433 * This is generally called from #GtkCellArea implementations
2434 * either gtk_cell_area_grab_focus() or gtk_cell_area_update_focus()
2435 * is called. It's also up to the #GtkCellArea implementation
2436 * to update the focused cell when receiving events from
2437 * gtk_cell_area_event() appropriately.
2440 gtk_cell_area_set_focus_cell (GtkCellArea *area,
2441 GtkCellRenderer *renderer)
2443 GtkCellAreaPrivate *priv;
2445 g_return_if_fail (GTK_IS_CELL_AREA (area));
2446 g_return_if_fail (renderer == NULL || GTK_IS_CELL_RENDERER (renderer));
2450 if (priv->focus_cell != renderer)
2452 if (priv->focus_cell)
2453 g_object_unref (priv->focus_cell);
2455 priv->focus_cell = renderer;
2457 if (priv->focus_cell)
2458 g_object_ref (priv->focus_cell);
2460 g_object_notify (G_OBJECT (area), "focus-cell");
2463 /* Signal that the current focus renderer for this path changed
2464 * (it may be that the focus cell did not change, but the row
2465 * may have changed so we need to signal it) */
2466 g_signal_emit (area, cell_area_signals[SIGNAL_FOCUS_CHANGED], 0,
2467 priv->focus_cell, priv->current_path);
2472 * gtk_cell_area_get_focus_cell:
2473 * @area: a #GtkCellArea
2475 * Retrieves the currently focused cell for @area
2477 * Returns: the currently focused cell in @area.
2480 gtk_cell_area_get_focus_cell (GtkCellArea *area)
2482 GtkCellAreaPrivate *priv;
2484 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
2488 return priv->focus_cell;
2492 /*************************************************************
2493 * API: Focus Siblings *
2494 *************************************************************/
2497 * gtk_cell_area_add_focus_sibling:
2498 * @area: a #GtkCellArea
2499 * @renderer: the #GtkCellRenderer expected to have focus
2500 * @sibling: the #GtkCellRenderer to add to @renderer's focus area
2502 * Adds @sibling to @renderer's focusable area, focus will be drawn
2503 * around @renderer and all of it's siblings if @renderer can
2504 * focus for a given row.
2506 * Events handled by focus siblings can also activate the given
2507 * focusable @renderer.
2510 gtk_cell_area_add_focus_sibling (GtkCellArea *area,
2511 GtkCellRenderer *renderer,
2512 GtkCellRenderer *sibling)
2514 GtkCellAreaPrivate *priv;
2517 g_return_if_fail (GTK_IS_CELL_AREA (area));
2518 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2519 g_return_if_fail (GTK_IS_CELL_RENDERER (sibling));
2520 g_return_if_fail (renderer != sibling);
2521 g_return_if_fail (gtk_cell_area_has_renderer (area, renderer));
2522 g_return_if_fail (gtk_cell_area_has_renderer (area, sibling));
2523 g_return_if_fail (!gtk_cell_area_is_focus_sibling (area, renderer, sibling));
2525 /* XXX We should also check that sibling is not in any other renderer's sibling
2526 * list already, a renderer can be sibling of only one focusable renderer
2532 siblings = g_hash_table_lookup (priv->focus_siblings, renderer);
2535 siblings = g_list_append (siblings, sibling);
2538 siblings = g_list_append (siblings, sibling);
2539 g_hash_table_insert (priv->focus_siblings, renderer, siblings);
2544 * gtk_cell_area_remove_focus_sibling:
2545 * @area: a #GtkCellArea
2546 * @renderer: the #GtkCellRenderer expected to have focus
2547 * @sibling: the #GtkCellRenderer to remove from @renderer's focus area
2549 * Removes @sibling from @renderer's focus sibling list
2550 * (see gtk_cell_area_add_focus_sibling()).
2553 gtk_cell_area_remove_focus_sibling (GtkCellArea *area,
2554 GtkCellRenderer *renderer,
2555 GtkCellRenderer *sibling)
2557 GtkCellAreaPrivate *priv;
2560 g_return_if_fail (GTK_IS_CELL_AREA (area));
2561 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2562 g_return_if_fail (GTK_IS_CELL_RENDERER (sibling));
2563 g_return_if_fail (gtk_cell_area_is_focus_sibling (area, renderer, sibling));
2567 siblings = g_hash_table_lookup (priv->focus_siblings, renderer);
2569 siblings = g_list_copy (siblings);
2570 siblings = g_list_remove (siblings, sibling);
2573 g_hash_table_remove (priv->focus_siblings, renderer);
2575 g_hash_table_insert (priv->focus_siblings, renderer, siblings);
2579 * gtk_cell_area_is_focus_sibling:
2580 * @area: a #GtkCellArea
2581 * @renderer: the #GtkCellRenderer expected to have focus
2582 * @sibling: the #GtkCellRenderer to check against @renderer's sibling list
2584 * Returns %TRUE if @sibling is one of @renderer's focus siblings
2585 * (see gtk_cell_area_add_focus_sibling()).
2588 gtk_cell_area_is_focus_sibling (GtkCellArea *area,
2589 GtkCellRenderer *renderer,
2590 GtkCellRenderer *sibling)
2592 GtkCellAreaPrivate *priv;
2593 GList *siblings, *l;
2595 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2596 g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), FALSE);
2597 g_return_val_if_fail (GTK_IS_CELL_RENDERER (sibling), FALSE);
2601 siblings = g_hash_table_lookup (priv->focus_siblings, renderer);
2603 for (l = siblings; l; l = l->next)
2605 GtkCellRenderer *a_sibling = l->data;
2607 if (a_sibling == sibling)
2615 * gtk_cell_area_get_focus_siblings:
2616 * @area: a #GtkCellArea
2617 * @renderer: the #GtkCellRenderer expected to have focus
2619 * Gets the focus sibling cell renderers for @renderer.
2621 * Returns: A #GList of #GtkCellRenderers. The returned list is internal and should not be freed.
2624 gtk_cell_area_get_focus_siblings (GtkCellArea *area,
2625 GtkCellRenderer *renderer)
2627 GtkCellAreaPrivate *priv;
2629 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
2630 g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), NULL);
2634 return g_hash_table_lookup (priv->focus_siblings, renderer);
2638 * gtk_cell_area_get_focus_from_sibling:
2639 * @area: a #GtkCellArea
2640 * @renderer: the #GtkCellRenderer
2642 * Gets the #GtkCellRenderer which is expected to be focusable
2643 * for which @renderer is, or may be a sibling.
2645 * This is handy for #GtkCellArea subclasses when handling events,
2646 * after determining the renderer at the event location it can
2647 * then chose to activate the focus cell for which the event
2648 * cell may have been a sibling.
2650 * Returns: the #GtkCellRenderer for which @renderer is a sibling, or %NULL.
2653 gtk_cell_area_get_focus_from_sibling (GtkCellArea *area,
2654 GtkCellRenderer *renderer)
2656 GtkCellRenderer *ret_renderer = NULL;
2657 GList *renderers, *l;
2659 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
2660 g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), NULL);
2662 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (area));
2664 for (l = renderers; l; l = l->next)
2666 GtkCellRenderer *a_renderer = l->data;
2669 for (list = gtk_cell_area_get_focus_siblings (area, a_renderer);
2670 list; list = list->next)
2672 GtkCellRenderer *sibling_renderer = list->data;
2674 if (sibling_renderer == renderer)
2676 ret_renderer = a_renderer;
2681 g_list_free (renderers);
2683 return ret_renderer;
2686 /*************************************************************
2687 * API: Cell Activation/Editing *
2688 *************************************************************/
2690 gtk_cell_area_add_editable (GtkCellArea *area,
2691 GtkCellRenderer *renderer,
2692 GtkCellEditable *editable,
2693 GdkRectangle *cell_area)
2695 g_signal_emit (area, cell_area_signals[SIGNAL_ADD_EDITABLE], 0,
2696 renderer, editable, cell_area, area->priv->current_path);
2700 gtk_cell_area_remove_editable (GtkCellArea *area,
2701 GtkCellRenderer *renderer,
2702 GtkCellEditable *editable)
2704 g_signal_emit (area, cell_area_signals[SIGNAL_REMOVE_EDITABLE], 0, renderer, editable);
2708 cell_area_remove_widget_cb (GtkCellEditable *editable,
2711 GtkCellAreaPrivate *priv = area->priv;
2713 g_assert (priv->edit_widget == editable);
2714 g_assert (priv->edited_cell != NULL);
2716 gtk_cell_area_remove_editable (area, priv->edited_cell, priv->edit_widget);
2718 /* Now that we're done with editing the widget and it can be removed,
2719 * remove our references to the widget and disconnect handlers */
2720 gtk_cell_area_set_edited_cell (area, NULL);
2721 gtk_cell_area_set_edit_widget (area, NULL);
2725 gtk_cell_area_set_edited_cell (GtkCellArea *area,
2726 GtkCellRenderer *renderer)
2728 GtkCellAreaPrivate *priv;
2730 g_return_if_fail (GTK_IS_CELL_AREA (area));
2731 g_return_if_fail (renderer == NULL || GTK_IS_CELL_RENDERER (renderer));
2735 if (priv->edited_cell != renderer)
2737 if (priv->edited_cell)
2738 g_object_unref (priv->edited_cell);
2740 priv->edited_cell = renderer;
2742 if (priv->edited_cell)
2743 g_object_ref (priv->edited_cell);
2745 g_object_notify (G_OBJECT (area), "edited-cell");
2750 gtk_cell_area_set_edit_widget (GtkCellArea *area,
2751 GtkCellEditable *editable)
2753 GtkCellAreaPrivate *priv;
2755 g_return_if_fail (GTK_IS_CELL_AREA (area));
2756 g_return_if_fail (editable == NULL || GTK_IS_CELL_EDITABLE (editable));
2760 if (priv->edit_widget != editable)
2762 if (priv->edit_widget)
2764 g_signal_handler_disconnect (priv->edit_widget, priv->remove_widget_id);
2766 g_object_unref (priv->edit_widget);
2769 priv->edit_widget = editable;
2771 if (priv->edit_widget)
2773 priv->remove_widget_id =
2774 g_signal_connect (priv->edit_widget, "remove-widget",
2775 G_CALLBACK (cell_area_remove_widget_cb), area);
2777 g_object_ref (priv->edit_widget);
2780 g_object_notify (G_OBJECT (area), "edit-widget");
2785 * gtk_cell_area_get_edited_cell:
2786 * @area: a #GtkCellArea
2788 * Gets the #GtkCellRenderer in @area that is currently
2791 * Returns: The currently edited #GtkCellRenderer
2794 gtk_cell_area_get_edited_cell (GtkCellArea *area)
2796 GtkCellAreaPrivate *priv;
2798 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
2802 return priv->edited_cell;
2806 * gtk_cell_area_get_edit_widget:
2807 * @area: a #GtkCellArea
2809 * Gets the #GtkCellEditable widget currently used
2810 * to edit the currently edited cell.
2812 * Returns: The currently active #GtkCellEditable widget
2815 gtk_cell_area_get_edit_widget (GtkCellArea *area)
2817 GtkCellAreaPrivate *priv;
2819 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
2823 return priv->edit_widget;
2827 * gtk_cell_area_activate_cell:
2828 * @area: a #GtkCellArea
2829 * @widget: the #GtkWidget that @area is rendering onto
2830 * @renderer: the #GtkCellRenderer in @area to activate
2831 * @event: the #GdkEvent for which cell activation should occur
2832 * @cell_area: the #GdkRectangle in @widget relative coordinates
2833 * of @renderer for the current row.
2834 * @flags: the #GtkCellRendererState for @renderer
2836 * This is used by #GtkCellArea subclasses when handling events
2837 * to activate cells, the base #GtkCellArea class activates cells
2838 * for keyboard events for free in it's own GtkCellArea->activate()
2841 * Returns: whether cell activation was successful
2844 gtk_cell_area_activate_cell (GtkCellArea *area,
2846 GtkCellRenderer *renderer,
2848 const GdkRectangle *cell_area,
2849 GtkCellRendererState flags)
2851 GtkCellRendererMode mode;
2852 GdkRectangle inner_area;
2853 GtkCellAreaPrivate *priv;
2855 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2856 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2857 g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), FALSE);
2858 g_return_val_if_fail (cell_area != NULL, FALSE);
2862 /* Remove margins from the background area to produce the cell area.
2864 * XXX Maybe have to do some rtl mode treatment here...
2866 gtk_cell_area_inner_cell_area (area, widget, cell_area, &inner_area);
2868 g_object_get (renderer, "mode", &mode, NULL);
2870 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2872 if (gtk_cell_renderer_activate (renderer,
2880 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2882 GtkCellEditable *editable_widget;
2885 gtk_cell_renderer_start_editing (renderer,
2892 if (editable_widget != NULL)
2894 g_return_val_if_fail (GTK_IS_CELL_EDITABLE (editable_widget), FALSE);
2896 gtk_cell_area_set_edited_cell (area, renderer);
2897 gtk_cell_area_set_edit_widget (area, editable_widget);
2899 /* Signal that editing started so that callers can get
2900 * a handle on the editable_widget */
2901 gtk_cell_area_add_editable (area, priv->focus_cell, editable_widget, &inner_area);
2903 /* If the signal was successfully handled start the editing */
2904 if (gtk_widget_get_parent (GTK_WIDGET (editable_widget)))
2906 gtk_cell_editable_start_editing (editable_widget, NULL);
2907 gtk_widget_grab_focus (GTK_WIDGET (editable_widget));
2911 /* Otherwise clear the editing state and fire a warning */
2912 gtk_cell_area_set_edited_cell (area, NULL);
2913 gtk_cell_area_set_edit_widget (area, NULL);
2915 g_warning ("GtkCellArea::add-editable fired in the dark, no cell editing was started.");
2926 * gtk_cell_area_stop_editing:
2927 * @area: a #GtkCellArea
2928 * @canceled: whether editing was canceled.
2930 * Explicitly stops the editing of the currently
2931 * edited cell (see gtk_cell_area_get_edited_cell()).
2933 * If @canceled is %TRUE, the cell renderer will emit
2934 * the ::editing-canceled signal.
2937 gtk_cell_area_stop_editing (GtkCellArea *area,
2940 GtkCellAreaPrivate *priv;
2942 g_return_if_fail (GTK_IS_CELL_AREA (area));
2946 if (priv->edited_cell)
2948 GtkCellEditable *edit_widget = g_object_ref (priv->edit_widget);
2949 GtkCellRenderer *edit_cell = g_object_ref (priv->edited_cell);
2951 /* Stop editing of the cell renderer */
2952 gtk_cell_renderer_stop_editing (priv->edited_cell, canceled);
2954 /* Remove any references to the editable widget */
2955 gtk_cell_area_set_edited_cell (area, NULL);
2956 gtk_cell_area_set_edit_widget (area, NULL);
2958 /* Send the remove-widget signal explicitly (this is done after setting
2959 * the edit cell/widget NULL to avoid feedback)
2961 gtk_cell_area_remove_editable (area, edit_cell, edit_widget);
2962 g_object_unref (edit_cell);
2963 g_object_unref (edit_widget);
2967 /*************************************************************
2968 * API: Convenience for area implementations *
2969 *************************************************************/
2972 gtk_cell_area_inner_cell_area (GtkCellArea *area,
2974 const GdkRectangle *cell_area,
2975 GdkRectangle *inner_area)
2977 gint focus_line_width;
2979 g_return_if_fail (GTK_IS_CELL_AREA (area));
2980 g_return_if_fail (GTK_IS_WIDGET (widget));
2981 g_return_if_fail (cell_area != NULL);
2982 g_return_if_fail (inner_area != NULL);
2984 gtk_widget_style_get (widget, "focus-line-width", &focus_line_width, NULL);
2986 *inner_area = *cell_area;
2988 inner_area->x += focus_line_width;
2989 inner_area->width -= focus_line_width * 2;
2990 inner_area->y += focus_line_width;
2991 inner_area->height -= focus_line_width * 2;
2995 gtk_cell_area_request_renderer (GtkCellArea *area,
2996 GtkCellRenderer *renderer,
2997 GtkOrientation orientation,
3003 GtkCellAreaPrivate *priv;
3004 gint focus_line_width;
3006 g_return_if_fail (GTK_IS_CELL_AREA (area));
3007 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
3008 g_return_if_fail (GTK_IS_WIDGET (widget));
3009 g_return_if_fail (minimum_size != NULL);
3010 g_return_if_fail (natural_size != NULL);
3014 gtk_widget_style_get (widget, "focus-line-width", &focus_line_width, NULL);
3016 focus_line_width *= 2;
3018 if (orientation == GTK_ORIENTATION_HORIZONTAL)
3021 gtk_cell_renderer_get_preferred_width (renderer, widget, minimum_size, natural_size);
3024 for_size = MAX (0, for_size - focus_line_width);
3026 gtk_cell_renderer_get_preferred_width_for_height (renderer, widget, for_size,
3027 minimum_size, natural_size);
3030 else /* GTK_ORIENTATION_VERTICAL */
3033 gtk_cell_renderer_get_preferred_height (renderer, widget, minimum_size, natural_size);
3036 for_size = MAX (0, for_size - focus_line_width);
3038 gtk_cell_renderer_get_preferred_height_for_width (renderer, widget, for_size,
3039 minimum_size, natural_size);
3043 *minimum_size += focus_line_width;
3044 *natural_size += focus_line_width;