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_can_focus (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->can_focus = gtk_cell_area_real_can_focus;
558 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_can_focus (GtkCellRenderer *renderer,
997 if (gtk_cell_renderer_can_focus (renderer))
1002 gtk_cell_area_real_can_focus (GtkCellArea *area)
1004 gboolean can_focus = 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_can_focus, &can_focus);
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;
1027 if (priv->focus_cell)
1029 /* Get the allocation of the focused cell.
1031 gtk_cell_area_get_cell_allocation (area, context, widget, priv->focus_cell,
1032 cell_area, &background_area);
1034 /* Activate or Edit the currently focused cell
1036 * Currently just not sending an event, renderers afaics dont use
1037 * the event argument anyway, worst case is we can synthesize one.
1039 if (gtk_cell_area_activate_cell (area, widget, priv->focus_cell, NULL,
1040 &background_area, flags))
1047 /*************************************************************
1048 * GtkCellLayoutIface *
1049 *************************************************************/
1051 gtk_cell_area_cell_layout_init (GtkCellLayoutIface *iface)
1053 iface->pack_start = gtk_cell_area_pack_default;
1054 iface->pack_end = gtk_cell_area_pack_default;
1055 iface->clear = gtk_cell_area_clear;
1056 iface->add_attribute = gtk_cell_area_add_attribute;
1057 iface->set_cell_data_func = gtk_cell_area_set_cell_data_func;
1058 iface->clear_attributes = gtk_cell_area_clear_attributes;
1059 iface->reorder = gtk_cell_area_reorder;
1060 iface->get_cells = gtk_cell_area_get_cells;
1064 gtk_cell_area_pack_default (GtkCellLayout *cell_layout,
1065 GtkCellRenderer *renderer,
1068 gtk_cell_area_add (GTK_CELL_AREA (cell_layout), renderer);
1072 gtk_cell_area_clear (GtkCellLayout *cell_layout)
1074 GtkCellArea *area = GTK_CELL_AREA (cell_layout);
1076 gtk_cell_layout_get_cells (cell_layout);
1078 for (l = cells; l; l = l->next)
1080 GtkCellRenderer *renderer = l->data;
1081 gtk_cell_area_remove (area, renderer);
1084 g_list_free (cells);
1088 gtk_cell_area_add_attribute (GtkCellLayout *cell_layout,
1089 GtkCellRenderer *renderer,
1090 const gchar *attribute,
1093 gtk_cell_area_attribute_connect (GTK_CELL_AREA (cell_layout),
1094 renderer, attribute, column);
1098 gtk_cell_area_set_cell_data_func (GtkCellLayout *cell_layout,
1099 GtkCellRenderer *renderer,
1100 GtkCellLayoutDataFunc func,
1102 GDestroyNotify destroy)
1104 GtkCellArea *area = GTK_CELL_AREA (cell_layout);
1105 GtkCellAreaPrivate *priv = area->priv;
1108 info = g_hash_table_lookup (priv->cell_info, renderer);
1112 if (info->destroy && info->data)
1113 info->destroy (info->data);
1118 info->data = func_data;
1119 info->destroy = destroy;
1125 info->destroy = NULL;
1130 info = cell_info_new (func, func_data, destroy);
1132 g_hash_table_insert (priv->cell_info, renderer, info);
1137 gtk_cell_area_clear_attributes (GtkCellLayout *cell_layout,
1138 GtkCellRenderer *renderer)
1140 GtkCellArea *area = GTK_CELL_AREA (cell_layout);
1141 GtkCellAreaPrivate *priv = area->priv;
1144 info = g_hash_table_lookup (priv->cell_info, renderer);
1148 g_slist_foreach (info->attributes, (GFunc)cell_attribute_free, NULL);
1149 g_slist_free (info->attributes);
1151 info->attributes = NULL;
1156 gtk_cell_area_reorder (GtkCellLayout *cell_layout,
1157 GtkCellRenderer *cell,
1160 g_warning ("GtkCellLayout::reorder not implemented for `%s'",
1161 g_type_name (G_TYPE_FROM_INSTANCE (cell_layout)));
1165 accum_cells (GtkCellRenderer *renderer,
1168 *accum = g_list_prepend (*accum, renderer);
1172 gtk_cell_area_get_cells (GtkCellLayout *cell_layout)
1174 GList *cells = NULL;
1176 gtk_cell_area_forall (GTK_CELL_AREA (cell_layout),
1177 (GtkCellCallback)accum_cells,
1180 return g_list_reverse (cells);
1184 /*************************************************************
1186 *************************************************************/
1189 * gtk_cell_area_add:
1190 * @area: a #GtkCellArea
1191 * @renderer: the #GtkCellRenderer to add to @area
1193 * Adds @renderer to @area with the default child cell properties.
1196 gtk_cell_area_add (GtkCellArea *area,
1197 GtkCellRenderer *renderer)
1199 GtkCellAreaClass *class;
1201 g_return_if_fail (GTK_IS_CELL_AREA (area));
1202 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1204 class = GTK_CELL_AREA_GET_CLASS (area);
1207 class->add (area, renderer);
1209 g_warning ("GtkCellAreaClass::add not implemented for `%s'",
1210 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1214 * gtk_cell_area_remove:
1215 * @area: a #GtkCellArea
1216 * @renderer: the #GtkCellRenderer to add to @area
1218 * Removes @renderer from @area.
1221 gtk_cell_area_remove (GtkCellArea *area,
1222 GtkCellRenderer *renderer)
1224 GtkCellAreaClass *class;
1225 GtkCellAreaPrivate *priv;
1226 GList *renderers, *l;
1228 g_return_if_fail (GTK_IS_CELL_AREA (area));
1229 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1231 class = GTK_CELL_AREA_GET_CLASS (area);
1234 /* Remove any custom attributes and custom cell data func here first */
1235 g_hash_table_remove (priv->cell_info, renderer);
1237 /* Remove focus siblings of this renderer */
1238 g_hash_table_remove (priv->focus_siblings, renderer);
1240 /* Remove this renderer from any focus renderer's sibling list */
1241 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (area));
1243 for (l = renderers; l; l = l->next)
1245 GtkCellRenderer *focus_renderer = l->data;
1247 if (gtk_cell_area_is_focus_sibling (area, focus_renderer, renderer))
1249 gtk_cell_area_remove_focus_sibling (area, focus_renderer, renderer);
1254 g_list_free (renderers);
1257 class->remove (area, renderer);
1259 g_warning ("GtkCellAreaClass::remove not implemented for `%s'",
1260 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1264 get_has_renderer (GtkCellRenderer *renderer,
1265 HasRendererCheck *check)
1267 if (renderer == check->renderer)
1268 check->has_renderer = TRUE;
1272 * gtk_cell_area_has_renderer:
1273 * @area: a #GtkCellArea
1274 * @renderer: the #GtkCellRenderer to check
1276 * Checks if @area contains @renderer.
1278 * Returns: %TRUE if @renderer is in the @area.
1281 gtk_cell_area_has_renderer (GtkCellArea *area,
1282 GtkCellRenderer *renderer)
1284 HasRendererCheck check = { renderer, FALSE };
1286 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
1287 g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), FALSE);
1289 gtk_cell_area_forall (area, (GtkCellCallback)get_has_renderer, &check);
1291 return check.has_renderer;
1295 * gtk_cell_area_forall:
1296 * @area: a #GtkCellArea
1297 * @callback: the #GtkCellCallback to call
1298 * @callback_data: user provided data pointer
1300 * Calls @callback for every #GtkCellRenderer in @area.
1303 gtk_cell_area_forall (GtkCellArea *area,
1304 GtkCellCallback callback,
1305 gpointer callback_data)
1307 GtkCellAreaClass *class;
1309 g_return_if_fail (GTK_IS_CELL_AREA (area));
1310 g_return_if_fail (callback != NULL);
1312 class = GTK_CELL_AREA_GET_CLASS (area);
1315 class->forall (area, callback, callback_data);
1317 g_warning ("GtkCellAreaClass::forall not implemented for `%s'",
1318 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1322 * gtk_cell_area_get_cell_allocation:
1323 * @area: a #GtkCellArea
1324 * @context: the #GtkCellAreaContext used to hold sizes for @area.
1325 * @widget: the #GtkWidget that @area is rendering on
1326 * @renderer: the #GtkCellRenderer to get the allocation for
1327 * @cell_area: the whole allocated area for @area in @widget
1329 * @allocation: where to store the allocation for @renderer
1331 * Derives the allocation of @renderer inside @area if @area
1332 * were to be renderered in @cell_area.
1335 gtk_cell_area_get_cell_allocation (GtkCellArea *area,
1336 GtkCellAreaContext *context,
1338 GtkCellRenderer *renderer,
1339 const GdkRectangle *cell_area,
1340 GdkRectangle *allocation)
1342 GtkCellAreaClass *class;
1344 g_return_if_fail (GTK_IS_CELL_AREA (area));
1345 g_return_if_fail (GTK_IS_CELL_AREA_CONTEXT (context));
1346 g_return_if_fail (GTK_IS_WIDGET (widget));
1347 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1348 g_return_if_fail (cell_area != NULL);
1349 g_return_if_fail (allocation != NULL);
1351 class = GTK_CELL_AREA_GET_CLASS (area);
1353 if (class->get_cell_allocation)
1354 class->get_cell_allocation (area, context, widget, renderer, cell_area, allocation);
1356 g_warning ("GtkCellAreaClass::get_cell_allocation not implemented for `%s'",
1357 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1361 * gtk_cell_area_event:
1362 * @area: a #GtkCellArea
1363 * @context: the #GtkCellAreaContext for this row of data.
1364 * @widget: the #GtkWidget that @area is rendering to
1365 * @event: the #GdkEvent to handle
1366 * @cell_area: the @widget relative coordinates for @area
1367 * @flags: the #GtkCellRendererState for @area in this row.
1369 * Delegates event handling to a #GtkCellArea.
1371 * Returns: %TRUE if the event was handled by @area.
1374 gtk_cell_area_event (GtkCellArea *area,
1375 GtkCellAreaContext *context,
1378 const GdkRectangle *cell_area,
1379 GtkCellRendererState flags)
1381 GtkCellAreaClass *class;
1383 g_return_val_if_fail (GTK_IS_CELL_AREA (area), 0);
1384 g_return_val_if_fail (GTK_IS_CELL_AREA_CONTEXT (context), 0);
1385 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
1386 g_return_val_if_fail (event != NULL, 0);
1387 g_return_val_if_fail (cell_area != NULL, 0);
1389 class = GTK_CELL_AREA_GET_CLASS (area);
1392 return class->event (area, context, widget, event, cell_area, flags);
1394 g_warning ("GtkCellAreaClass::event not implemented for `%s'",
1395 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1400 * gtk_cell_area_render:
1401 * @area: a #GtkCellArea
1402 * @context: the #GtkCellAreaContext for this row of data.
1403 * @widget: the #GtkWidget that @area is rendering to
1404 * @cr: the #cairo_t to render with
1405 * @background_area: the @widget relative coordinates for @area's background
1406 * @cell_area: the @widget relative coordinates for @area
1407 * @flags: the #GtkCellRendererState for @area in this row.
1408 * @paint_focus: whether @area should paint focus on focused cells for focused rows or not.
1410 * Renders @area's cells according to @area's layout onto @widget at
1411 * the given coordinates.
1414 gtk_cell_area_render (GtkCellArea *area,
1415 GtkCellAreaContext *context,
1418 const GdkRectangle *background_area,
1419 const GdkRectangle *cell_area,
1420 GtkCellRendererState flags,
1421 gboolean paint_focus)
1423 GtkCellAreaClass *class;
1425 g_return_if_fail (GTK_IS_CELL_AREA (area));
1426 g_return_if_fail (GTK_IS_CELL_AREA_CONTEXT (context));
1427 g_return_if_fail (GTK_IS_WIDGET (widget));
1428 g_return_if_fail (cr != NULL);
1429 g_return_if_fail (background_area != NULL);
1430 g_return_if_fail (cell_area != NULL);
1432 class = GTK_CELL_AREA_GET_CLASS (area);
1435 class->render (area, context, widget, cr, background_area, cell_area, flags, paint_focus);
1437 g_warning ("GtkCellAreaClass::render not implemented for `%s'",
1438 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1442 * gtk_cell_area_set_style_detail:
1443 * @area: a #GtkCellArea
1444 * @detail: the #GtkStyle detail string to set
1446 * Sets the detail string used in any gtk_paint_*() functions
1450 gtk_cell_area_set_style_detail (GtkCellArea *area,
1451 const gchar *detail)
1453 GtkCellAreaPrivate *priv;
1455 g_return_if_fail (GTK_IS_CELL_AREA (area));
1459 if (g_strcmp0 (priv->style_detail, detail) != 0)
1461 g_free (priv->style_detail);
1462 priv->style_detail = g_strdup (detail);
1467 * gtk_cell_area_get_style_detail:
1468 * @area: a #GtkCellArea
1470 * Gets the detail string used in any gtk_paint_*() functions
1473 * Returns: the detail string.
1475 G_CONST_RETURN gchar *
1476 gtk_cell_area_get_style_detail (GtkCellArea *area)
1478 GtkCellAreaPrivate *priv;
1480 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
1484 return priv->style_detail;
1487 /*************************************************************
1489 *************************************************************/
1491 * gtk_cell_area_create_context:
1492 * @area: a #GtkCellArea
1494 * Creates a #GtkCellAreaContext to be used with @area for
1495 * all purposes. #GtkCellAreaContext stores geometry information
1496 * for rows for which it was operated on, it is important to use
1497 * the same context for the same row of data at all times (i.e.
1498 * one should render and handle events with the same #GtkCellAreaContext
1499 * which was used to request the size of those rows of data).
1501 * Returns: a newly created #GtkCellAreaContext which can be used with @area.
1503 GtkCellAreaContext *
1504 gtk_cell_area_create_context (GtkCellArea *area)
1506 GtkCellAreaClass *class;
1508 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
1510 class = GTK_CELL_AREA_GET_CLASS (area);
1512 if (class->create_context)
1513 return class->create_context (area);
1515 g_warning ("GtkCellAreaClass::create_context not implemented for `%s'",
1516 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1523 * gtk_cell_area_get_request_mode:
1524 * @area: a #GtkCellArea
1526 * Gets whether the area prefers a height-for-width layout
1527 * or a width-for-height layout.
1529 * Returns: The #GtkSizeRequestMode preferred by @area.
1534 gtk_cell_area_get_request_mode (GtkCellArea *area)
1536 GtkCellAreaClass *class;
1538 g_return_val_if_fail (GTK_IS_CELL_AREA (area),
1539 GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH);
1541 class = GTK_CELL_AREA_GET_CLASS (area);
1543 if (class->get_request_mode)
1544 return class->get_request_mode (area);
1546 g_warning ("GtkCellAreaClass::get_request_mode not implemented for `%s'",
1547 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1549 return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
1553 * gtk_cell_area_get_preferred_width:
1554 * @area: a #GtkCellArea
1555 * @context: the #GtkCellAreaContext to perform this request with
1556 * @widget: the #GtkWidget where @area will be rendering
1557 * @minimum_width: (out) (allow-none): location to store the minimum width, or %NULL
1558 * @natural_width: (out) (allow-none): location to store the natural width, or %NULL
1560 * Retrieves a cell area's initial minimum and natural width.
1562 * @area will store some geometrical information in @context along the way,
1563 * when requesting sizes over an arbitrary number of rows, its not important
1564 * to check the @minimum_width and @natural_width of this call but rather to
1565 * consult gtk_cell_area_context_get_preferred_width() after a series of
1572 gtk_cell_area_get_preferred_width (GtkCellArea *area,
1573 GtkCellAreaContext *context,
1575 gint *minimum_width,
1576 gint *natural_width)
1578 GtkCellAreaClass *class;
1580 g_return_if_fail (GTK_IS_CELL_AREA (area));
1581 g_return_if_fail (GTK_IS_WIDGET (widget));
1583 class = GTK_CELL_AREA_GET_CLASS (area);
1585 if (class->get_preferred_width)
1586 class->get_preferred_width (area, context, widget, minimum_width, natural_width);
1588 g_warning ("GtkCellAreaClass::get_preferred_width not implemented for `%s'",
1589 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1593 * gtk_cell_area_get_preferred_height_for_width:
1594 * @area: a #GtkCellArea
1595 * @context: the #GtkCellAreaContext which has already been requested for widths.
1596 * @widget: the #GtkWidget where @area will be rendering
1597 * @width: the width for which to check the height of this area
1598 * @minimum_height: (out) (allow-none): location to store the minimum height, or %NULL
1599 * @natural_height: (out) (allow-none): location to store the natural height, or %NULL
1601 * Retrieves a cell area's minimum and natural height if it would be given
1602 * the specified @width.
1604 * @area stores some geometrical information in @context along the way
1605 * while calling gtk_cell_area_get_preferred_width(), it's important to
1606 * perform a series of gtk_cell_area_get_preferred_width() requests with
1607 * @context first and then call gtk_cell_area_get_preferred_height_for_width()
1608 * on each cell area individually to get the height for width of each
1609 * fully requested row.
1611 * If at some point, the width of a single row changes, it should be
1612 * requested with gtk_cell_area_get_preferred_width() again and then
1613 * the full width of the requested rows checked again with
1614 * gtk_cell_area_context_get_preferred_width().
1619 gtk_cell_area_get_preferred_height_for_width (GtkCellArea *area,
1620 GtkCellAreaContext *context,
1623 gint *minimum_height,
1624 gint *natural_height)
1626 GtkCellAreaClass *class;
1628 g_return_if_fail (GTK_IS_CELL_AREA (area));
1629 g_return_if_fail (GTK_IS_WIDGET (widget));
1631 class = GTK_CELL_AREA_GET_CLASS (area);
1632 class->get_preferred_height_for_width (area, context, widget, width, minimum_height, natural_height);
1637 * gtk_cell_area_get_preferred_height:
1638 * @area: a #GtkCellArea
1639 * @context: the #GtkCellAreaContext to perform this request with
1640 * @widget: the #GtkWidget where @area will be rendering
1641 * @minimum_height: (out) (allow-none): location to store the minimum height, or %NULL
1642 * @natural_height: (out) (allow-none): location to store the natural height, or %NULL
1644 * Retrieves a cell area's initial minimum and natural height.
1646 * @area will store some geometrical information in @context along the way,
1647 * when requesting sizes over an arbitrary number of rows, its not important
1648 * to check the @minimum_height and @natural_height of this call but rather to
1649 * consult gtk_cell_area_context_get_preferred_height() after a series of
1655 gtk_cell_area_get_preferred_height (GtkCellArea *area,
1656 GtkCellAreaContext *context,
1658 gint *minimum_height,
1659 gint *natural_height)
1661 GtkCellAreaClass *class;
1663 g_return_if_fail (GTK_IS_CELL_AREA (area));
1664 g_return_if_fail (GTK_IS_WIDGET (widget));
1666 class = GTK_CELL_AREA_GET_CLASS (area);
1668 if (class->get_preferred_height)
1669 class->get_preferred_height (area, context, widget, minimum_height, natural_height);
1671 g_warning ("GtkCellAreaClass::get_preferred_height not implemented for `%s'",
1672 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1676 * gtk_cell_area_get_preferred_width_for_height:
1677 * @area: a #GtkCellArea
1678 * @context: the #GtkCellAreaContext which has already been requested for widths.
1679 * @widget: the #GtkWidget where @area will be rendering
1680 * @height: the height for which to check the width of this area
1681 * @minimum_width: (out) (allow-none): location to store the minimum width, or %NULL
1682 * @natural_width: (out) (allow-none): location to store the natural width, or %NULL
1684 * Retrieves a cell area's minimum and natural width if it would be given
1685 * the specified @height.
1687 * @area stores some geometrical information in @context along the way
1688 * while calling gtk_cell_area_get_preferred_height(), it's important to
1689 * perform a series of gtk_cell_area_get_preferred_height() requests with
1690 * @context first and then call gtk_cell_area_get_preferred_width_for_height()
1691 * on each cell area individually to get the height for width of each
1692 * fully requested row.
1694 * If at some point, the height of a single row changes, it should be
1695 * requested with gtk_cell_area_get_preferred_height() again and then
1696 * the full height of the requested rows checked again with
1697 * gtk_cell_area_context_get_preferred_height().
1702 gtk_cell_area_get_preferred_width_for_height (GtkCellArea *area,
1703 GtkCellAreaContext *context,
1706 gint *minimum_width,
1707 gint *natural_width)
1709 GtkCellAreaClass *class;
1711 g_return_if_fail (GTK_IS_CELL_AREA (area));
1712 g_return_if_fail (GTK_IS_WIDGET (widget));
1714 class = GTK_CELL_AREA_GET_CLASS (area);
1715 class->get_preferred_width_for_height (area, context, widget, height, minimum_width, natural_width);
1718 /*************************************************************
1720 *************************************************************/
1723 * gtk_cell_area_attribute_connect:
1724 * @area: a #GtkCellArea
1725 * @renderer: the #GtkCellRenderer to connect an attribute for
1726 * @attribute: the attribute name
1727 * @column: the #GtkTreeModel column to fetch attribute values from
1729 * Connects an @attribute to apply values from @column for the
1730 * #GtkTreeModel in use.
1733 gtk_cell_area_attribute_connect (GtkCellArea *area,
1734 GtkCellRenderer *renderer,
1735 const gchar *attribute,
1738 GtkCellAreaPrivate *priv;
1740 CellAttribute *cell_attribute;
1742 g_return_if_fail (GTK_IS_CELL_AREA (area));
1743 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1744 g_return_if_fail (attribute != NULL);
1745 g_return_if_fail (gtk_cell_area_has_renderer (area, renderer));
1748 info = g_hash_table_lookup (priv->cell_info, renderer);
1752 info = cell_info_new (NULL, NULL, NULL);
1754 g_hash_table_insert (priv->cell_info, renderer, info);
1760 /* Check we are not adding the same attribute twice */
1761 if ((node = g_slist_find_custom (info->attributes, attribute,
1762 (GCompareFunc)cell_attribute_find)) != NULL)
1764 cell_attribute = node->data;
1766 g_warning ("Cannot connect attribute `%s' for cell renderer class `%s' "
1767 "since `%s' is already attributed to column %d",
1769 g_type_name (G_TYPE_FROM_INSTANCE (area)),
1770 attribute, cell_attribute->column);
1775 cell_attribute = cell_attribute_new (renderer, attribute, column);
1777 if (!cell_attribute)
1779 g_warning ("Cannot connect attribute `%s' for cell renderer class `%s' "
1780 "since attribute does not exist",
1782 g_type_name (G_TYPE_FROM_INSTANCE (area)));
1786 info->attributes = g_slist_prepend (info->attributes, cell_attribute);
1790 * gtk_cell_area_attribute_disconnect:
1791 * @area: a #GtkCellArea
1792 * @renderer: the #GtkCellRenderer to disconnect an attribute for
1793 * @attribute: the attribute name
1795 * Disconnects @attribute for the @renderer in @area so that
1796 * attribute will no longer be updated with values from the
1800 gtk_cell_area_attribute_disconnect (GtkCellArea *area,
1801 GtkCellRenderer *renderer,
1802 const gchar *attribute)
1804 GtkCellAreaPrivate *priv;
1806 CellAttribute *cell_attribute;
1809 g_return_if_fail (GTK_IS_CELL_AREA (area));
1810 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1811 g_return_if_fail (attribute != NULL);
1812 g_return_if_fail (gtk_cell_area_has_renderer (area, renderer));
1815 info = g_hash_table_lookup (priv->cell_info, renderer);
1819 node = g_slist_find_custom (info->attributes, attribute,
1820 (GCompareFunc)cell_attribute_find);
1823 cell_attribute = node->data;
1825 cell_attribute_free (cell_attribute);
1827 info->attributes = g_slist_delete_link (info->attributes, node);
1833 * gtk_cell_area_apply_attributes
1834 * @area: a #GtkCellArea
1835 * @tree_model: a #GtkTreeModel to pull values from
1836 * @iter: the #GtkTreeIter in @tree_model to apply values for
1837 * @is_expander: whether @iter has children
1838 * @is_expanded: whether @iter is expanded in the view and
1839 * children are visible
1841 * Applies any connected attributes to the renderers in
1842 * @area by pulling the values from @tree_model.
1845 gtk_cell_area_apply_attributes (GtkCellArea *area,
1846 GtkTreeModel *tree_model,
1848 gboolean is_expander,
1849 gboolean is_expanded)
1851 g_return_if_fail (GTK_IS_CELL_AREA (area));
1852 g_return_if_fail (GTK_IS_TREE_MODEL (tree_model));
1853 g_return_if_fail (iter != NULL);
1855 g_signal_emit (area, cell_area_signals[SIGNAL_APPLY_ATTRIBUTES], 0,
1856 tree_model, iter, is_expander, is_expanded);
1860 * gtk_cell_area_get_current_path_string:
1861 * @area: a #GtkCellArea
1863 * Gets the current #GtkTreePath string for the currently
1864 * applied #GtkTreeIter, this is implicitly updated when
1865 * gtk_cell_area_apply_attributes() is called and can be
1866 * used to interact with renderers from #GtkCellArea
1870 gtk_cell_area_get_current_path_string (GtkCellArea *area)
1872 GtkCellAreaPrivate *priv;
1874 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
1878 return priv->current_path;
1882 /*************************************************************
1883 * API: Cell Properties *
1884 *************************************************************/
1886 * gtk_cell_area_class_install_cell_property:
1887 * @aclass: a #GtkCellAreaClass
1888 * @property_id: the id for the property
1889 * @pspec: the #GParamSpec for the property
1891 * Installs a cell property on a cell area class.
1894 gtk_cell_area_class_install_cell_property (GtkCellAreaClass *aclass,
1898 g_return_if_fail (GTK_IS_CELL_AREA_CLASS (aclass));
1899 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1900 if (pspec->flags & G_PARAM_WRITABLE)
1901 g_return_if_fail (aclass->set_cell_property != NULL);
1902 if (pspec->flags & G_PARAM_READABLE)
1903 g_return_if_fail (aclass->get_cell_property != NULL);
1904 g_return_if_fail (property_id > 0);
1905 g_return_if_fail (PARAM_SPEC_PARAM_ID (pspec) == 0); /* paranoid */
1906 g_return_if_fail ((pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY)) == 0);
1908 if (g_param_spec_pool_lookup (cell_property_pool, pspec->name, G_OBJECT_CLASS_TYPE (aclass), TRUE))
1910 g_warning (G_STRLOC ": class `%s' already contains a cell property named `%s'",
1911 G_OBJECT_CLASS_NAME (aclass), pspec->name);
1914 g_param_spec_ref (pspec);
1915 g_param_spec_sink (pspec);
1916 PARAM_SPEC_SET_PARAM_ID (pspec, property_id);
1917 g_param_spec_pool_insert (cell_property_pool, pspec, G_OBJECT_CLASS_TYPE (aclass));
1921 * gtk_cell_area_class_find_cell_property:
1922 * @aclass: a #GtkCellAreaClass
1923 * @property_name: the name of the child property to find
1924 * @returns: (allow-none): the #GParamSpec of the child property or %NULL if @aclass has no
1925 * child property with that name.
1927 * Finds a cell property of a cell area class by name.
1930 gtk_cell_area_class_find_cell_property (GtkCellAreaClass *aclass,
1931 const gchar *property_name)
1933 g_return_val_if_fail (GTK_IS_CELL_AREA_CLASS (aclass), NULL);
1934 g_return_val_if_fail (property_name != NULL, NULL);
1936 return g_param_spec_pool_lookup (cell_property_pool,
1938 G_OBJECT_CLASS_TYPE (aclass),
1943 * gtk_cell_area_class_list_cell_properties:
1944 * @aclass: a #GtkCellAreaClass
1945 * @n_properties: location to return the number of cell properties found
1946 * @returns: a newly allocated %NULL-terminated array of #GParamSpec*.
1947 * The array must be freed with g_free().
1949 * Returns all cell properties of a cell area class.
1952 gtk_cell_area_class_list_cell_properties (GtkCellAreaClass *aclass,
1953 guint *n_properties)
1955 GParamSpec **pspecs;
1958 g_return_val_if_fail (GTK_IS_CELL_AREA_CLASS (aclass), NULL);
1960 pspecs = g_param_spec_pool_list (cell_property_pool,
1961 G_OBJECT_CLASS_TYPE (aclass),
1970 * gtk_cell_area_add_with_properties:
1971 * @area: a #GtkCellArea
1972 * @renderer: a #GtkCellRenderer to be placed inside @area
1973 * @first_prop_name: the name of the first cell property to set
1974 * @Varargs: a %NULL-terminated list of property names and values, starting
1975 * with @first_prop_name
1977 * Adds @renderer to @area, setting cell properties at the same time.
1978 * See gtk_cell_area_add() and gtk_cell_area_child_set() for more details.
1981 gtk_cell_area_add_with_properties (GtkCellArea *area,
1982 GtkCellRenderer *renderer,
1983 const gchar *first_prop_name,
1986 GtkCellAreaClass *class;
1988 g_return_if_fail (GTK_IS_CELL_AREA (area));
1989 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
1991 class = GTK_CELL_AREA_GET_CLASS (area);
1997 class->add (area, renderer);
1999 va_start (var_args, first_prop_name);
2000 gtk_cell_area_cell_set_valist (area, renderer, first_prop_name, var_args);
2004 g_warning ("GtkCellAreaClass::add not implemented for `%s'",
2005 g_type_name (G_TYPE_FROM_INSTANCE (area)));
2009 * gtk_cell_area_cell_set:
2010 * @area: a #GtkCellArea
2011 * @renderer: a #GtkCellRenderer which is a cell inside @area
2012 * @first_prop_name: the name of the first cell property to set
2013 * @Varargs: a %NULL-terminated list of property names and values, starting
2014 * with @first_prop_name
2016 * Sets one or more cell properties for @cell in @area.
2019 gtk_cell_area_cell_set (GtkCellArea *area,
2020 GtkCellRenderer *renderer,
2021 const gchar *first_prop_name,
2026 g_return_if_fail (GTK_IS_CELL_AREA (area));
2027 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2029 va_start (var_args, first_prop_name);
2030 gtk_cell_area_cell_set_valist (area, renderer, first_prop_name, var_args);
2035 * gtk_cell_area_cell_get:
2036 * @area: a #GtkCellArea
2037 * @renderer: a #GtkCellRenderer which is inside @area
2038 * @first_prop_name: the name of the first cell property to get
2039 * @Varargs: return location for the first cell property, followed
2040 * optionally by more name/return location pairs, followed by %NULL
2042 * Gets the values of one or more cell properties for @renderer in @area.
2045 gtk_cell_area_cell_get (GtkCellArea *area,
2046 GtkCellRenderer *renderer,
2047 const gchar *first_prop_name,
2052 g_return_if_fail (GTK_IS_CELL_AREA (area));
2053 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2055 va_start (var_args, first_prop_name);
2056 gtk_cell_area_cell_get_valist (area, renderer, first_prop_name, var_args);
2061 area_get_cell_property (GtkCellArea *area,
2062 GtkCellRenderer *renderer,
2066 GtkCellAreaClass *class = g_type_class_peek (pspec->owner_type);
2068 class->get_cell_property (area, renderer, PARAM_SPEC_PARAM_ID (pspec), value, pspec);
2072 area_set_cell_property (GtkCellArea *area,
2073 GtkCellRenderer *renderer,
2075 const GValue *value)
2077 GValue tmp_value = { 0, };
2078 GtkCellAreaClass *class = g_type_class_peek (pspec->owner_type);
2080 /* provide a copy to work from, convert (if necessary) and validate */
2081 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2082 if (!g_value_transform (value, &tmp_value))
2083 g_warning ("unable to set cell property `%s' of type `%s' from value of type `%s'",
2085 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
2086 G_VALUE_TYPE_NAME (value));
2087 else if (g_param_value_validate (pspec, &tmp_value) && !(pspec->flags & G_PARAM_LAX_VALIDATION))
2089 gchar *contents = g_strdup_value_contents (value);
2091 g_warning ("value \"%s\" of type `%s' is invalid for property `%s' of type `%s'",
2093 G_VALUE_TYPE_NAME (value),
2095 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
2100 class->set_cell_property (area, renderer, PARAM_SPEC_PARAM_ID (pspec), &tmp_value, pspec);
2102 g_value_unset (&tmp_value);
2106 * gtk_cell_area_cell_set_valist:
2107 * @area: a #GtkCellArea
2108 * @renderer: a #GtkCellRenderer which inside @area
2109 * @first_property_name: the name of the first cell property to set
2110 * @var_args: a %NULL-terminated list of property names and values, starting
2111 * with @first_prop_name
2113 * Sets one or more cell properties for @renderer in @area.
2116 gtk_cell_area_cell_set_valist (GtkCellArea *area,
2117 GtkCellRenderer *renderer,
2118 const gchar *first_property_name,
2123 g_return_if_fail (GTK_IS_CELL_AREA (area));
2124 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2126 name = first_property_name;
2129 GValue value = { 0, };
2130 gchar *error = NULL;
2132 g_param_spec_pool_lookup (cell_property_pool, name,
2133 G_OBJECT_TYPE (area), TRUE);
2136 g_warning ("%s: cell area class `%s' has no cell property named `%s'",
2137 G_STRLOC, G_OBJECT_TYPE_NAME (area), name);
2140 if (!(pspec->flags & G_PARAM_WRITABLE))
2142 g_warning ("%s: cell property `%s' of cell area class `%s' is not writable",
2143 G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
2147 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2148 G_VALUE_COLLECT (&value, var_args, 0, &error);
2151 g_warning ("%s: %s", G_STRLOC, error);
2154 /* we purposely leak the value here, it might not be
2155 * in a sane state if an error condition occoured
2159 area_set_cell_property (area, renderer, pspec, &value);
2160 g_value_unset (&value);
2161 name = va_arg (var_args, gchar*);
2166 * gtk_cell_area_cell_get_valist:
2167 * @area: a #GtkCellArea
2168 * @renderer: a #GtkCellRenderer inside @area
2169 * @first_property_name: the name of the first property to get
2170 * @var_args: return location for the first property, followed
2171 * optionally by more name/return location pairs, followed by %NULL
2173 * Gets the values of one or more cell properties for @renderer in @area.
2176 gtk_cell_area_cell_get_valist (GtkCellArea *area,
2177 GtkCellRenderer *renderer,
2178 const gchar *first_property_name,
2183 g_return_if_fail (GTK_IS_CELL_AREA (area));
2184 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2186 name = first_property_name;
2189 GValue value = { 0, };
2193 pspec = g_param_spec_pool_lookup (cell_property_pool, name,
2194 G_OBJECT_TYPE (area), TRUE);
2197 g_warning ("%s: cell area class `%s' has no cell property named `%s'",
2198 G_STRLOC, G_OBJECT_TYPE_NAME (area), name);
2201 if (!(pspec->flags & G_PARAM_READABLE))
2203 g_warning ("%s: cell property `%s' of cell area class `%s' is not readable",
2204 G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
2208 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2209 area_get_cell_property (area, renderer, pspec, &value);
2210 G_VALUE_LCOPY (&value, var_args, 0, &error);
2213 g_warning ("%s: %s", G_STRLOC, error);
2215 g_value_unset (&value);
2218 g_value_unset (&value);
2219 name = va_arg (var_args, gchar*);
2224 * gtk_cell_area_cell_set_property:
2225 * @area: a #GtkCellArea
2226 * @renderer: a #GtkCellRenderer inside @area
2227 * @property_name: the name of the cell property to set
2228 * @value: the value to set the cell property to
2230 * Sets a cell property for @renderer in @area.
2233 gtk_cell_area_cell_set_property (GtkCellArea *area,
2234 GtkCellRenderer *renderer,
2235 const gchar *property_name,
2236 const GValue *value)
2240 g_return_if_fail (GTK_IS_CELL_AREA (area));
2241 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2242 g_return_if_fail (property_name != NULL);
2243 g_return_if_fail (G_IS_VALUE (value));
2245 pspec = g_param_spec_pool_lookup (cell_property_pool, property_name,
2246 G_OBJECT_TYPE (area), TRUE);
2248 g_warning ("%s: cell area class `%s' has no cell property named `%s'",
2249 G_STRLOC, G_OBJECT_TYPE_NAME (area), property_name);
2250 else if (!(pspec->flags & G_PARAM_WRITABLE))
2251 g_warning ("%s: cell property `%s' of cell area class `%s' is not writable",
2252 G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
2255 area_set_cell_property (area, renderer, pspec, value);
2260 * gtk_cell_area_cell_get_property:
2261 * @area: a #GtkCellArea
2262 * @renderer: a #GtkCellRenderer inside @area
2263 * @property_name: the name of the property to get
2264 * @value: a location to return the value
2266 * Gets the value of a cell property for @renderer in @area.
2269 gtk_cell_area_cell_get_property (GtkCellArea *area,
2270 GtkCellRenderer *renderer,
2271 const gchar *property_name,
2276 g_return_if_fail (GTK_IS_CELL_AREA (area));
2277 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2278 g_return_if_fail (property_name != NULL);
2279 g_return_if_fail (G_IS_VALUE (value));
2281 pspec = g_param_spec_pool_lookup (cell_property_pool, property_name,
2282 G_OBJECT_TYPE (area), TRUE);
2284 g_warning ("%s: cell area class `%s' has no cell property named `%s'",
2285 G_STRLOC, G_OBJECT_TYPE_NAME (area), property_name);
2286 else if (!(pspec->flags & G_PARAM_READABLE))
2287 g_warning ("%s: cell property `%s' of cell area class `%s' is not readable",
2288 G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (area));
2291 GValue *prop_value, tmp_value = { 0, };
2293 /* auto-conversion of the callers value type
2295 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
2297 g_value_reset (value);
2300 else if (!g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
2302 g_warning ("can't retrieve cell property `%s' of type `%s' as value of type `%s'",
2304 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
2305 G_VALUE_TYPE_NAME (value));
2310 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2311 prop_value = &tmp_value;
2314 area_get_cell_property (area, renderer, pspec, prop_value);
2316 if (prop_value != value)
2318 g_value_transform (prop_value, value);
2319 g_value_unset (&tmp_value);
2324 /*************************************************************
2326 *************************************************************/
2329 * gtk_cell_area_can_focus:
2330 * @area: a #GtkCellArea
2332 * Returns whether the area can receive keyboard focus,
2333 * after applying new attributes to @area.
2335 * Returns: whether @area can receive focus.
2338 gtk_cell_area_can_focus (GtkCellArea *area)
2340 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2342 return GTK_CELL_AREA_GET_CLASS (area)->can_focus (area);
2346 * gtk_cell_area_focus:
2347 * @area: a #GtkCellArea
2348 * @direction: the #GtkDirectionType
2350 * This should be called by the @area's owning layout widget
2351 * when focus is to be passed to @area, or moved within @area
2352 * for a given @direction and row data.
2354 * Implementing #GtkCellArea classes should implement this
2355 * method to receive and navigate focus in it's own way particular
2356 * to how it lays out cells.
2358 * Returns: %TRUE if focus remains inside @area as a result of this call.
2361 gtk_cell_area_focus (GtkCellArea *area,
2362 GtkDirectionType direction)
2364 GtkCellAreaClass *class;
2366 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2368 class = GTK_CELL_AREA_GET_CLASS (area);
2371 return class->focus (area, direction);
2373 g_warning ("GtkCellAreaClass::focus not implemented for `%s'",
2374 g_type_name (G_TYPE_FROM_INSTANCE (area)));
2380 * gtk_cell_area_activate:
2381 * @area: a #GtkCellArea
2382 * @context: the #GtkCellAreaContext in context with the current row data
2383 * @widget: the #GtkWidget that @area is rendering on
2384 * @cell_area: the size and location of @area relative to @widget's allocation
2385 * @flags: the #GtkCellRendererState flags for @area for this row of data.
2387 * Activates @area, usually by activating the currently focused
2388 * cell, however some subclasses which embed widgets in the area
2389 * can also activate a widget if it currently has the focus.
2391 * Returns: Whether @area was successfully activated.
2394 gtk_cell_area_activate (GtkCellArea *area,
2395 GtkCellAreaContext *context,
2397 const GdkRectangle *cell_area,
2398 GtkCellRendererState flags)
2400 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2402 return GTK_CELL_AREA_GET_CLASS (area)->activate (area, context, widget, cell_area, flags);
2407 * gtk_cell_area_set_focus_cell:
2408 * @area: a #GtkCellArea
2409 * @focus_cell: the #GtkCellRenderer to give focus to
2411 * This is generally called from #GtkCellArea implementations
2412 * either gtk_cell_area_grab_focus() or gtk_cell_area_update_focus()
2413 * is called. It's also up to the #GtkCellArea implementation
2414 * to update the focused cell when receiving events from
2415 * gtk_cell_area_event() appropriately.
2418 gtk_cell_area_set_focus_cell (GtkCellArea *area,
2419 GtkCellRenderer *renderer)
2421 GtkCellAreaPrivate *priv;
2423 g_return_if_fail (GTK_IS_CELL_AREA (area));
2424 g_return_if_fail (renderer == NULL || GTK_IS_CELL_RENDERER (renderer));
2428 if (priv->focus_cell != renderer)
2430 if (priv->focus_cell)
2431 g_object_unref (priv->focus_cell);
2433 priv->focus_cell = renderer;
2435 if (priv->focus_cell)
2436 g_object_ref (priv->focus_cell);
2438 g_object_notify (G_OBJECT (area), "focus-cell");
2441 /* Signal that the current focus renderer for this path changed
2442 * (it may be that the focus cell did not change, but the row
2443 * may have changed so we need to signal it) */
2444 g_signal_emit (area, cell_area_signals[SIGNAL_FOCUS_CHANGED], 0,
2445 priv->focus_cell, priv->current_path);
2450 * gtk_cell_area_get_focus_cell:
2451 * @area: a #GtkCellArea
2453 * Retrieves the currently focused cell for @area
2455 * Returns: the currently focused cell in @area.
2458 gtk_cell_area_get_focus_cell (GtkCellArea *area)
2460 GtkCellAreaPrivate *priv;
2462 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
2466 return priv->focus_cell;
2470 /*************************************************************
2471 * API: Focus Siblings *
2472 *************************************************************/
2475 * gtk_cell_area_add_focus_sibling:
2476 * @area: a #GtkCellArea
2477 * @renderer: the #GtkCellRenderer expected to have focus
2478 * @sibling: the #GtkCellRenderer to add to @renderer's focus area
2480 * Adds @sibling to @renderer's focusable area, focus will be drawn
2481 * around @renderer and all of it's siblings if @renderer can
2482 * focus for a given row.
2484 * Events handled by focus siblings can also activate the given
2485 * focusable @renderer.
2488 gtk_cell_area_add_focus_sibling (GtkCellArea *area,
2489 GtkCellRenderer *renderer,
2490 GtkCellRenderer *sibling)
2492 GtkCellAreaPrivate *priv;
2495 g_return_if_fail (GTK_IS_CELL_AREA (area));
2496 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2497 g_return_if_fail (GTK_IS_CELL_RENDERER (sibling));
2498 g_return_if_fail (renderer != sibling);
2499 g_return_if_fail (gtk_cell_area_has_renderer (area, renderer));
2500 g_return_if_fail (gtk_cell_area_has_renderer (area, sibling));
2501 g_return_if_fail (!gtk_cell_area_is_focus_sibling (area, renderer, sibling));
2503 /* XXX We should also check that sibling is not in any other renderer's sibling
2504 * list already, a renderer can be sibling of only one focusable renderer
2510 siblings = g_hash_table_lookup (priv->focus_siblings, renderer);
2513 siblings = g_list_append (siblings, sibling);
2516 siblings = g_list_append (siblings, sibling);
2517 g_hash_table_insert (priv->focus_siblings, renderer, siblings);
2522 * gtk_cell_area_remove_focus_sibling:
2523 * @area: a #GtkCellArea
2524 * @renderer: the #GtkCellRenderer expected to have focus
2525 * @sibling: the #GtkCellRenderer to remove from @renderer's focus area
2527 * Removes @sibling from @renderer's focus sibling list
2528 * (see gtk_cell_area_add_focus_sibling()).
2531 gtk_cell_area_remove_focus_sibling (GtkCellArea *area,
2532 GtkCellRenderer *renderer,
2533 GtkCellRenderer *sibling)
2535 GtkCellAreaPrivate *priv;
2538 g_return_if_fail (GTK_IS_CELL_AREA (area));
2539 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2540 g_return_if_fail (GTK_IS_CELL_RENDERER (sibling));
2541 g_return_if_fail (gtk_cell_area_is_focus_sibling (area, renderer, sibling));
2545 siblings = g_hash_table_lookup (priv->focus_siblings, renderer);
2547 siblings = g_list_copy (siblings);
2548 siblings = g_list_remove (siblings, sibling);
2551 g_hash_table_remove (priv->focus_siblings, renderer);
2553 g_hash_table_insert (priv->focus_siblings, renderer, siblings);
2557 * gtk_cell_area_is_focus_sibling:
2558 * @area: a #GtkCellArea
2559 * @renderer: the #GtkCellRenderer expected to have focus
2560 * @sibling: the #GtkCellRenderer to check against @renderer's sibling list
2562 * Returns %TRUE if @sibling is one of @renderer's focus siblings
2563 * (see gtk_cell_area_add_focus_sibling()).
2566 gtk_cell_area_is_focus_sibling (GtkCellArea *area,
2567 GtkCellRenderer *renderer,
2568 GtkCellRenderer *sibling)
2570 GtkCellAreaPrivate *priv;
2571 GList *siblings, *l;
2573 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2574 g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), FALSE);
2575 g_return_val_if_fail (GTK_IS_CELL_RENDERER (sibling), FALSE);
2579 siblings = g_hash_table_lookup (priv->focus_siblings, renderer);
2581 for (l = siblings; l; l = l->next)
2583 GtkCellRenderer *a_sibling = l->data;
2585 if (a_sibling == sibling)
2593 * gtk_cell_area_get_focus_siblings:
2594 * @area: a #GtkCellArea
2595 * @renderer: the #GtkCellRenderer expected to have focus
2597 * Gets the focus sibling cell renderers for @renderer.
2599 * Returns: A #GList of #GtkCellRenderers. The returned list is internal and should not be freed.
2602 gtk_cell_area_get_focus_siblings (GtkCellArea *area,
2603 GtkCellRenderer *renderer)
2605 GtkCellAreaPrivate *priv;
2607 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
2608 g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), NULL);
2612 return g_hash_table_lookup (priv->focus_siblings, renderer);
2616 * gtk_cell_area_get_focus_from_sibling:
2617 * @area: a #GtkCellArea
2618 * @renderer: the #GtkCellRenderer
2620 * Gets the #GtkCellRenderer which is expected to be focusable
2621 * for which @renderer is, or may be a sibling.
2623 * This is handy for #GtkCellArea subclasses when handling events,
2624 * after determining the renderer at the event location it can
2625 * then chose to activate the focus cell for which the event
2626 * cell may have been a sibling.
2628 * Returns: the #GtkCellRenderer for which @renderer is a sibling, or %NULL.
2631 gtk_cell_area_get_focus_from_sibling (GtkCellArea *area,
2632 GtkCellRenderer *renderer)
2634 GtkCellRenderer *ret_renderer = NULL;
2635 GList *renderers, *l;
2637 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
2638 g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), NULL);
2640 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (area));
2642 for (l = renderers; l; l = l->next)
2644 GtkCellRenderer *a_renderer = l->data;
2647 for (list = gtk_cell_area_get_focus_siblings (area, a_renderer);
2648 list; list = list->next)
2650 GtkCellRenderer *sibling_renderer = list->data;
2652 if (sibling_renderer == renderer)
2654 ret_renderer = a_renderer;
2659 g_list_free (renderers);
2661 return ret_renderer;
2664 /*************************************************************
2665 * API: Cell Activation/Editing *
2666 *************************************************************/
2668 gtk_cell_area_add_editable (GtkCellArea *area,
2669 GtkCellRenderer *renderer,
2670 GtkCellEditable *editable,
2671 GdkRectangle *cell_area)
2673 g_signal_emit (area, cell_area_signals[SIGNAL_ADD_EDITABLE], 0,
2674 renderer, editable, cell_area, area->priv->current_path);
2678 gtk_cell_area_remove_editable (GtkCellArea *area,
2679 GtkCellRenderer *renderer,
2680 GtkCellEditable *editable)
2682 g_signal_emit (area, cell_area_signals[SIGNAL_REMOVE_EDITABLE], 0, renderer, editable);
2686 cell_area_remove_widget_cb (GtkCellEditable *editable,
2689 GtkCellAreaPrivate *priv = area->priv;
2691 g_assert (priv->edit_widget == editable);
2692 g_assert (priv->edited_cell != NULL);
2694 gtk_cell_area_remove_editable (area, priv->edited_cell, priv->edit_widget);
2696 /* Now that we're done with editing the widget and it can be removed,
2697 * remove our references to the widget and disconnect handlers */
2698 gtk_cell_area_set_edited_cell (area, NULL);
2699 gtk_cell_area_set_edit_widget (area, NULL);
2703 gtk_cell_area_set_edited_cell (GtkCellArea *area,
2704 GtkCellRenderer *renderer)
2706 GtkCellAreaPrivate *priv;
2708 g_return_if_fail (GTK_IS_CELL_AREA (area));
2709 g_return_if_fail (renderer == NULL || GTK_IS_CELL_RENDERER (renderer));
2713 if (priv->edited_cell != renderer)
2715 if (priv->edited_cell)
2716 g_object_unref (priv->edited_cell);
2718 priv->edited_cell = renderer;
2720 if (priv->edited_cell)
2721 g_object_ref (priv->edited_cell);
2723 g_object_notify (G_OBJECT (area), "edited-cell");
2728 gtk_cell_area_set_edit_widget (GtkCellArea *area,
2729 GtkCellEditable *editable)
2731 GtkCellAreaPrivate *priv;
2733 g_return_if_fail (GTK_IS_CELL_AREA (area));
2734 g_return_if_fail (editable == NULL || GTK_IS_CELL_EDITABLE (editable));
2738 if (priv->edit_widget != editable)
2740 if (priv->edit_widget)
2742 g_signal_handler_disconnect (priv->edit_widget, priv->remove_widget_id);
2744 g_object_unref (priv->edit_widget);
2747 priv->edit_widget = editable;
2749 if (priv->edit_widget)
2751 priv->remove_widget_id =
2752 g_signal_connect (priv->edit_widget, "remove-widget",
2753 G_CALLBACK (cell_area_remove_widget_cb), area);
2755 g_object_ref (priv->edit_widget);
2758 g_object_notify (G_OBJECT (area), "edit-widget");
2763 * gtk_cell_area_get_edited_cell:
2764 * @area: a #GtkCellArea
2766 * Gets the #GtkCellRenderer in @area that is currently
2769 * Returns: The currently edited #GtkCellRenderer
2772 gtk_cell_area_get_edited_cell (GtkCellArea *area)
2774 GtkCellAreaPrivate *priv;
2776 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
2780 return priv->edited_cell;
2784 * gtk_cell_area_get_edit_widget:
2785 * @area: a #GtkCellArea
2787 * Gets the #GtkCellEditable widget currently used
2788 * to edit the currently edited cell.
2790 * Returns: The currently active #GtkCellEditable widget
2793 gtk_cell_area_get_edit_widget (GtkCellArea *area)
2795 GtkCellAreaPrivate *priv;
2797 g_return_val_if_fail (GTK_IS_CELL_AREA (area), NULL);
2801 return priv->edit_widget;
2805 * gtk_cell_area_activate_cell:
2806 * @area: a #GtkCellArea
2807 * @widget: the #GtkWidget that @area is rendering onto
2808 * @renderer: the #GtkCellRenderer in @area to activate
2809 * @event: the #GdkEvent for which cell activation should occur
2810 * @cell_area: the #GdkRectangle in @widget relative coordinates
2811 * of @renderer for the current row.
2812 * @flags: the #GtkCellRendererState for @renderer
2814 * This is used by #GtkCellArea subclasses when handling events
2815 * to activate cells, the base #GtkCellArea class activates cells
2816 * for keyboard events for free in it's own GtkCellArea->activate()
2819 * Returns: whether cell activation was successful
2822 gtk_cell_area_activate_cell (GtkCellArea *area,
2824 GtkCellRenderer *renderer,
2826 const GdkRectangle *cell_area,
2827 GtkCellRendererState flags)
2829 GtkCellRendererMode mode;
2830 GdkRectangle inner_area;
2831 GtkCellAreaPrivate *priv;
2833 g_return_val_if_fail (GTK_IS_CELL_AREA (area), FALSE);
2834 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2835 g_return_val_if_fail (GTK_IS_CELL_RENDERER (renderer), FALSE);
2836 g_return_val_if_fail (cell_area != NULL, FALSE);
2840 /* Remove margins from the background area to produce the cell area.
2842 * XXX Maybe have to do some rtl mode treatment here...
2844 gtk_cell_area_inner_cell_area (area, widget, cell_area, &inner_area);
2846 g_object_get (renderer, "mode", &mode, NULL);
2848 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2850 if (gtk_cell_renderer_activate (renderer,
2858 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2860 GtkCellEditable *editable_widget;
2863 gtk_cell_renderer_start_editing (renderer,
2870 if (editable_widget != NULL)
2872 g_return_val_if_fail (GTK_IS_CELL_EDITABLE (editable_widget), FALSE);
2874 gtk_cell_area_set_edited_cell (area, renderer);
2875 gtk_cell_area_set_edit_widget (area, editable_widget);
2877 /* Signal that editing started so that callers can get
2878 * a handle on the editable_widget */
2879 gtk_cell_area_add_editable (area, priv->focus_cell, editable_widget, &inner_area);
2881 /* If the signal was successfully handled start the editing */
2882 if (gtk_widget_get_parent (GTK_WIDGET (editable_widget)))
2884 gtk_cell_editable_start_editing (editable_widget, NULL);
2885 gtk_widget_grab_focus (GTK_WIDGET (editable_widget));
2889 /* Otherwise clear the editing state and fire a warning */
2890 gtk_cell_area_set_edited_cell (area, NULL);
2891 gtk_cell_area_set_edit_widget (area, NULL);
2893 g_warning ("GtkCellArea::add-editable fired in the dark, no cell editing was started.");
2904 * gtk_cell_area_stop_editing:
2905 * @area: a #GtkCellArea
2906 * @canceled: whether editing was canceled.
2908 * Explicitly stops the editing of the currently
2909 * edited cell (see gtk_cell_area_get_edited_cell()).
2911 * If @canceled is %TRUE, the cell renderer will emit
2912 * the ::editing-canceled signal.
2915 gtk_cell_area_stop_editing (GtkCellArea *area,
2918 GtkCellAreaPrivate *priv;
2920 g_return_if_fail (GTK_IS_CELL_AREA (area));
2924 if (priv->edited_cell)
2926 GtkCellEditable *edit_widget = g_object_ref (priv->edit_widget);
2927 GtkCellRenderer *edit_cell = g_object_ref (priv->edited_cell);
2929 /* Stop editing of the cell renderer */
2930 gtk_cell_renderer_stop_editing (priv->edited_cell, canceled);
2932 /* Remove any references to the editable widget */
2933 gtk_cell_area_set_edited_cell (area, NULL);
2934 gtk_cell_area_set_edit_widget (area, NULL);
2936 /* Send the remove-widget signal explicitly (this is done after setting
2937 * the edit cell/widget NULL to avoid feedback)
2939 gtk_cell_area_remove_editable (area, edit_cell, edit_widget);
2940 g_object_unref (edit_cell);
2941 g_object_unref (edit_widget);
2945 /*************************************************************
2946 * API: Convenience for area implementations *
2947 *************************************************************/
2950 gtk_cell_area_inner_cell_area (GtkCellArea *area,
2952 const GdkRectangle *cell_area,
2953 GdkRectangle *inner_area)
2955 gint focus_line_width;
2957 g_return_if_fail (GTK_IS_CELL_AREA (area));
2958 g_return_if_fail (GTK_IS_WIDGET (widget));
2959 g_return_if_fail (cell_area != NULL);
2960 g_return_if_fail (inner_area != NULL);
2962 gtk_widget_style_get (widget, "focus-line-width", &focus_line_width, NULL);
2964 *inner_area = *cell_area;
2966 inner_area->x += focus_line_width;
2967 inner_area->width -= focus_line_width * 2;
2968 inner_area->y += focus_line_width;
2969 inner_area->height -= focus_line_width * 2;
2973 gtk_cell_area_request_renderer (GtkCellArea *area,
2974 GtkCellRenderer *renderer,
2975 GtkOrientation orientation,
2981 GtkCellAreaPrivate *priv;
2982 gint focus_line_width;
2984 g_return_if_fail (GTK_IS_CELL_AREA (area));
2985 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
2986 g_return_if_fail (GTK_IS_WIDGET (widget));
2987 g_return_if_fail (minimum_size != NULL);
2988 g_return_if_fail (natural_size != NULL);
2992 gtk_widget_style_get (widget, "focus-line-width", &focus_line_width, NULL);
2994 focus_line_width *= 2;
2996 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2999 gtk_cell_renderer_get_preferred_width (renderer, widget, minimum_size, natural_size);
3002 for_size = MAX (0, for_size - focus_line_width);
3004 gtk_cell_renderer_get_preferred_width_for_height (renderer, widget, for_size,
3005 minimum_size, natural_size);
3008 else /* GTK_ORIENTATION_VERTICAL */
3011 gtk_cell_renderer_get_preferred_height (renderer, widget, minimum_size, natural_size);
3014 for_size = MAX (0, for_size - focus_line_width);
3016 gtk_cell_renderer_get_preferred_height_for_width (renderer, widget, for_size,
3017 minimum_size, natural_size);
3021 *minimum_size += focus_line_width;
3022 *natural_size += focus_line_width;