1/* gtkcellarea.h
2 *
3 * Copyright (C) 2010 Openismus GmbH
4 *
5 * Authors:
6 * Tristan Van Berkom <tristanvb@openismus.com>
7 *
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.
12 *
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.
17 *
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#ifndef __GTK_CELL_AREA_H__
23#define __GTK_CELL_AREA_H__
24
25#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
26#error "Only <gtk/gtk.h> can be included directly."
27#endif
28
29#include <gtk/gtkcellrenderer.h>
30#include <gtk/gtkwidget.h>
31#include <gtk/gtktreemodel.h>
32
33G_BEGIN_DECLS
34
35#define GTK_TYPE_CELL_AREA (gtk_cell_area_get_type ())
36#define GTK_CELL_AREA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_CELL_AREA, GtkCellArea))
37#define GTK_CELL_AREA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_CELL_AREA, GtkCellAreaClass))
38#define GTK_IS_CELL_AREA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_CELL_AREA))
39#define GTK_IS_CELL_AREA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_CELL_AREA))
40#define GTK_CELL_AREA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CELL_AREA, GtkCellAreaClass))
41
42typedef struct _GtkCellArea GtkCellArea;
43typedef struct _GtkCellAreaClass GtkCellAreaClass;
44typedef struct _GtkCellAreaContext GtkCellAreaContext;
45
46/**
47 * GTK_CELL_AREA_WARN_INVALID_CELL_PROPERTY_ID:
48 * @object: the `GObject` on which set_cell_property() or get_cell_property()
49 * was called
50 * @property_id: the numeric id of the property
51 * @pspec: the `GParamSpec` of the property
52 *
53 * This macro should be used to emit a standard warning about unexpected
54 * properties in set_cell_property() and get_cell_property() implementations.
55 */
56#define GTK_CELL_AREA_WARN_INVALID_CELL_PROPERTY_ID(object, property_id, pspec) \
57 G_OBJECT_WARN_INVALID_PSPEC ((object), "cell property id", (property_id), (pspec))
58
59/**
60 * GtkCellCallback:
61 * @renderer: the cell renderer to operate on
62 * @data: (closure): user-supplied data
63 *
64 * The type of the callback functions used for iterating over
65 * the cell renderers of a `GtkCellArea`, see gtk_cell_area_foreach().
66 *
67 * Returns: %TRUE to stop iterating over cells.
68 */
69typedef gboolean (*GtkCellCallback) (GtkCellRenderer *renderer,
70 gpointer data);
71
72/**
73 * GtkCellAllocCallback:
74 * @renderer: the cell renderer to operate on
75 * @cell_area: the area allocated to @renderer inside the rectangle
76 * provided to gtk_cell_area_foreach_alloc().
77 * @cell_background: the background area for @renderer inside the
78 * background area provided to gtk_cell_area_foreach_alloc().
79 * @data: (closure): user-supplied data
80 *
81 * The type of the callback functions used for iterating over the
82 * cell renderers and their allocated areas inside a `GtkCellArea`,
83 * see gtk_cell_area_foreach_alloc().
84 *
85 * Returns: %TRUE to stop iterating over cells.
86 */
87typedef gboolean (*GtkCellAllocCallback) (GtkCellRenderer *renderer,
88 const GdkRectangle *cell_area,
89 const GdkRectangle *cell_background,
90 gpointer data);
91
92
93struct _GtkCellArea
94{
95 /*< private >*/
96 GInitiallyUnowned parent_instance;
97};
98
99
100/**
101 * GtkCellAreaClass:
102 * @add: adds a `GtkCellRenderer` to the area.
103 * @remove: removes a `GtkCellRenderer` from the area.
104 * @foreach: calls the `GtkCellCallback` function on every `GtkCellRenderer` in
105 * the area with the provided user data until the callback returns %TRUE.
106 * @foreach_alloc: Calls the `GtkCellAllocCallback` function on every
107 * `GtkCellRenderer` in the area with the allocated area for the cell
108 * and the provided user data until the callback returns %TRUE.
109 * @event: Handle an event in the area, this is generally used to activate
110 * a cell at the event location for button events but can also be used
111 * to generically pass events to `GtkWidget`s drawn onto the area.
112 * @snapshot: Actually snapshot the area’s cells to the specified rectangle,
113 * @background_area should be correctly distributed to the cells
114 * corresponding background areas.
115 * @apply_attributes: Apply the cell attributes to the cells. This is
116 * implemented as a signal and generally `GtkCellArea` subclasses don't
117 * need to implement it since it is handled by the base class.
118 * @create_context: Creates and returns a class specific `GtkCellAreaContext`
119 * to store cell alignment and allocation details for a said `GtkCellArea`
120 * class.
121 * @copy_context: Creates a new `GtkCellAreaContext` in the same state as
122 * the passed @context with any cell alignment data and allocations intact.
123 * @get_request_mode: This allows an area to tell its layouting widget whether
124 * it prefers to be allocated in %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH or
125 * %GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT mode.
126 * @get_preferred_width: Calculates the minimum and natural width of the
127 * areas cells with the current attributes applied while considering
128 * the particular layouting details of the said `GtkCellArea`. While
129 * requests are performed over a series of rows, alignments and overall
130 * minimum and natural sizes should be stored in the corresponding
131 * `GtkCellAreaContext`.
132 * @get_preferred_height_for_width: Calculates the minimum and natural height
133 * for the area if the passed @context would be allocated the given width.
134 * When implementing this virtual method it is safe to assume that @context
135 * has already stored the aligned cell widths for every `GtkTreeModel` row
136 * that @context will be allocated for since this information was stored
137 * at `GtkCellAreaClass.get_preferred_width()` time. This virtual method
138 * should also store any necessary alignments of cell heights for the
139 * case that the context is allocated a height.
140 * @get_preferred_height: Calculates the minimum and natural height of the
141 * areas cells with the current attributes applied. Essentially this is
142 * the same as `GtkCellAreaClass.get_preferred_width()` only for areas
143 * that are being requested as %GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT.
144 * @get_preferred_width_for_height: Calculates the minimum and natural width
145 * for the area if the passed @context would be allocated the given
146 * height. The same as `GtkCellAreaClass.get_preferred_height_for_width()`
147 * only for handling requests in the %GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT
148 * mode.
149 * @set_cell_property: This should be implemented to handle changes in child
150 * cell properties for a given `GtkCellRenderer` that were previously
151 * installed on the `GtkCellAreaClass` with gtk_cell_area_class_install_cell_property().
152 * @get_cell_property: This should be implemented to report the values of
153 * child cell properties for a given child `GtkCellRenderer`.
154 * @focus: This virtual method should be implemented to navigate focus from
155 * cell to cell inside the `GtkCellArea`. The `GtkCellArea` should move
156 * focus from cell to cell inside the area and return %FALSE if focus
157 * logically leaves the area with the following exceptions: When the
158 * area contains no activatable cells, the entire area receives focus.
159 * Focus should not be given to cells that are actually “focus siblings”
160 * of other sibling cells (see gtk_cell_area_get_focus_from_sibling()).
161 * Focus is set by calling gtk_cell_area_set_focus_cell().
162 * @is_activatable: Returns whether the `GtkCellArea` can respond to
163 * `GtkCellAreaClass.activate()`, usually this does not need to be
164 * implemented since the base class takes care of this however it can
165 * be enhanced if the `GtkCellArea` subclass can handle activation in
166 * other ways than activating its `GtkCellRenderers`.
167 * @activate: This is called when the layouting widget rendering the
168 * `GtkCellArea` activates the focus cell (see gtk_cell_area_get_focus_cell()).
169 */
170struct _GtkCellAreaClass
171{
172 /*< private >*/
173 GInitiallyUnownedClass parent_class;
174
175 /*< public >*/
176
177 /* Basic methods */
178 void (* add) (GtkCellArea *area,
179 GtkCellRenderer *renderer);
180 void (* remove) (GtkCellArea *area,
181 GtkCellRenderer *renderer);
182 void (* foreach) (GtkCellArea *area,
183 GtkCellCallback callback,
184 gpointer callback_data);
185 void (* foreach_alloc) (GtkCellArea *area,
186 GtkCellAreaContext *context,
187 GtkWidget *widget,
188 const GdkRectangle *cell_area,
189 const GdkRectangle *background_area,
190 GtkCellAllocCallback callback,
191 gpointer callback_data);
192 int (* event) (GtkCellArea *area,
193 GtkCellAreaContext *context,
194 GtkWidget *widget,
195 GdkEvent *event,
196 const GdkRectangle *cell_area,
197 GtkCellRendererState flags);
198 void (* snapshot) (GtkCellArea *area,
199 GtkCellAreaContext *context,
200 GtkWidget *widget,
201 GtkSnapshot *snapshot,
202 const GdkRectangle *background_area,
203 const GdkRectangle *cell_area,
204 GtkCellRendererState flags,
205 gboolean paint_focus);
206 void (* apply_attributes) (GtkCellArea *area,
207 GtkTreeModel *tree_model,
208 GtkTreeIter *iter,
209 gboolean is_expander,
210 gboolean is_expanded);
211
212 /* Geometry */
213 GtkCellAreaContext *(* create_context) (GtkCellArea *area);
214 GtkCellAreaContext *(* copy_context) (GtkCellArea *area,
215 GtkCellAreaContext *context);
216 GtkSizeRequestMode (* get_request_mode) (GtkCellArea *area);
217 void (* get_preferred_width) (GtkCellArea *area,
218 GtkCellAreaContext *context,
219 GtkWidget *widget,
220 int *minimum_width,
221 int *natural_width);
222 void (* get_preferred_height_for_width) (GtkCellArea *area,
223 GtkCellAreaContext *context,
224 GtkWidget *widget,
225 int width,
226 int *minimum_height,
227 int *natural_height);
228 void (* get_preferred_height) (GtkCellArea *area,
229 GtkCellAreaContext *context,
230 GtkWidget *widget,
231 int *minimum_height,
232 int *natural_height);
233 void (* get_preferred_width_for_height) (GtkCellArea *area,
234 GtkCellAreaContext *context,
235 GtkWidget *widget,
236 int height,
237 int *minimum_width,
238 int *natural_width);
239
240 /* Cell Properties */
241 void (* set_cell_property) (GtkCellArea *area,
242 GtkCellRenderer *renderer,
243 guint property_id,
244 const GValue *value,
245 GParamSpec *pspec);
246 void (* get_cell_property) (GtkCellArea *area,
247 GtkCellRenderer *renderer,
248 guint property_id,
249 GValue *value,
250 GParamSpec *pspec);
251
252 /* Focus */
253 gboolean (* focus) (GtkCellArea *area,
254 GtkDirectionType direction);
255 gboolean (* is_activatable) (GtkCellArea *area);
256 gboolean (* activate) (GtkCellArea *area,
257 GtkCellAreaContext *context,
258 GtkWidget *widget,
259 const GdkRectangle *cell_area,
260 GtkCellRendererState flags,
261 gboolean edit_only);
262
263 /*< private >*/
264
265 gpointer padding[8];
266};
267
268GDK_AVAILABLE_IN_ALL
269GType gtk_cell_area_get_type (void) G_GNUC_CONST;
270
271/* Basic methods */
272GDK_AVAILABLE_IN_ALL
273void gtk_cell_area_add (GtkCellArea *area,
274 GtkCellRenderer *renderer);
275GDK_AVAILABLE_IN_ALL
276void gtk_cell_area_remove (GtkCellArea *area,
277 GtkCellRenderer *renderer);
278GDK_AVAILABLE_IN_ALL
279gboolean gtk_cell_area_has_renderer (GtkCellArea *area,
280 GtkCellRenderer *renderer);
281GDK_AVAILABLE_IN_ALL
282void gtk_cell_area_foreach (GtkCellArea *area,
283 GtkCellCallback callback,
284 gpointer callback_data);
285GDK_AVAILABLE_IN_ALL
286void gtk_cell_area_foreach_alloc (GtkCellArea *area,
287 GtkCellAreaContext *context,
288 GtkWidget *widget,
289 const GdkRectangle *cell_area,
290 const GdkRectangle *background_area,
291 GtkCellAllocCallback callback,
292 gpointer callback_data);
293GDK_AVAILABLE_IN_ALL
294int gtk_cell_area_event (GtkCellArea *area,
295 GtkCellAreaContext *context,
296 GtkWidget *widget,
297 GdkEvent *event,
298 const GdkRectangle *cell_area,
299 GtkCellRendererState flags);
300GDK_AVAILABLE_IN_ALL
301void gtk_cell_area_snapshot (GtkCellArea *area,
302 GtkCellAreaContext *context,
303 GtkWidget *widget,
304 GtkSnapshot *snapshot,
305 const GdkRectangle *background_area,
306 const GdkRectangle *cell_area,
307 GtkCellRendererState flags,
308 gboolean paint_focus);
309
310GDK_AVAILABLE_IN_ALL
311void gtk_cell_area_get_cell_allocation (GtkCellArea *area,
312 GtkCellAreaContext *context,
313 GtkWidget *widget,
314 GtkCellRenderer *renderer,
315 const GdkRectangle *cell_area,
316 GdkRectangle *allocation);
317GDK_AVAILABLE_IN_ALL
318GtkCellRenderer *gtk_cell_area_get_cell_at_position (GtkCellArea *area,
319 GtkCellAreaContext *context,
320 GtkWidget *widget,
321 const GdkRectangle *cell_area,
322 int x,
323 int y,
324 GdkRectangle *alloc_area);
325
326/* Geometry */
327GDK_AVAILABLE_IN_ALL
328GtkCellAreaContext *gtk_cell_area_create_context (GtkCellArea *area);
329GDK_AVAILABLE_IN_ALL
330GtkCellAreaContext *gtk_cell_area_copy_context (GtkCellArea *area,
331 GtkCellAreaContext *context);
332GDK_AVAILABLE_IN_ALL
333GtkSizeRequestMode gtk_cell_area_get_request_mode (GtkCellArea *area);
334GDK_AVAILABLE_IN_ALL
335void gtk_cell_area_get_preferred_width (GtkCellArea *area,
336 GtkCellAreaContext *context,
337 GtkWidget *widget,
338 int *minimum_width,
339 int *natural_width);
340GDK_AVAILABLE_IN_ALL
341void gtk_cell_area_get_preferred_height_for_width (GtkCellArea *area,
342 GtkCellAreaContext *context,
343 GtkWidget *widget,
344 int width,
345 int *minimum_height,
346 int *natural_height);
347GDK_AVAILABLE_IN_ALL
348void gtk_cell_area_get_preferred_height (GtkCellArea *area,
349 GtkCellAreaContext *context,
350 GtkWidget *widget,
351 int *minimum_height,
352 int *natural_height);
353GDK_AVAILABLE_IN_ALL
354void gtk_cell_area_get_preferred_width_for_height (GtkCellArea *area,
355 GtkCellAreaContext *context,
356 GtkWidget *widget,
357 int height,
358 int *minimum_width,
359 int *natural_width);
360GDK_AVAILABLE_IN_ALL
361const char * gtk_cell_area_get_current_path_string (GtkCellArea *area);
362
363
364/* Attributes */
365GDK_AVAILABLE_IN_ALL
366void gtk_cell_area_apply_attributes (GtkCellArea *area,
367 GtkTreeModel *tree_model,
368 GtkTreeIter *iter,
369 gboolean is_expander,
370 gboolean is_expanded);
371GDK_AVAILABLE_IN_ALL
372void gtk_cell_area_attribute_connect (GtkCellArea *area,
373 GtkCellRenderer *renderer,
374 const char *attribute,
375 int column);
376GDK_AVAILABLE_IN_ALL
377void gtk_cell_area_attribute_disconnect (GtkCellArea *area,
378 GtkCellRenderer *renderer,
379 const char *attribute);
380GDK_AVAILABLE_IN_ALL
381int gtk_cell_area_attribute_get_column (GtkCellArea *area,
382 GtkCellRenderer *renderer,
383 const char *attribute);
384
385
386/* Cell Properties */
387GDK_AVAILABLE_IN_ALL
388void gtk_cell_area_class_install_cell_property (GtkCellAreaClass *aclass,
389 guint property_id,
390 GParamSpec *pspec);
391GDK_AVAILABLE_IN_ALL
392GParamSpec* gtk_cell_area_class_find_cell_property (GtkCellAreaClass *aclass,
393 const char *property_name);
394GDK_AVAILABLE_IN_ALL
395GParamSpec** gtk_cell_area_class_list_cell_properties (GtkCellAreaClass *aclass,
396 guint *n_properties);
397GDK_AVAILABLE_IN_ALL
398void gtk_cell_area_add_with_properties (GtkCellArea *area,
399 GtkCellRenderer *renderer,
400 const char *first_prop_name,
401 ...) G_GNUC_NULL_TERMINATED;
402GDK_AVAILABLE_IN_ALL
403void gtk_cell_area_cell_set (GtkCellArea *area,
404 GtkCellRenderer *renderer,
405 const char *first_prop_name,
406 ...) G_GNUC_NULL_TERMINATED;
407GDK_AVAILABLE_IN_ALL
408void gtk_cell_area_cell_get (GtkCellArea *area,
409 GtkCellRenderer *renderer,
410 const char *first_prop_name,
411 ...) G_GNUC_NULL_TERMINATED;
412GDK_AVAILABLE_IN_ALL
413void gtk_cell_area_cell_set_valist (GtkCellArea *area,
414 GtkCellRenderer *renderer,
415 const char *first_property_name,
416 va_list var_args);
417GDK_AVAILABLE_IN_ALL
418void gtk_cell_area_cell_get_valist (GtkCellArea *area,
419 GtkCellRenderer *renderer,
420 const char *first_property_name,
421 va_list var_args);
422GDK_AVAILABLE_IN_ALL
423void gtk_cell_area_cell_set_property (GtkCellArea *area,
424 GtkCellRenderer *renderer,
425 const char *property_name,
426 const GValue *value);
427GDK_AVAILABLE_IN_ALL
428void gtk_cell_area_cell_get_property (GtkCellArea *area,
429 GtkCellRenderer *renderer,
430 const char *property_name,
431 GValue *value);
432
433/* Focus */
434GDK_AVAILABLE_IN_ALL
435gboolean gtk_cell_area_is_activatable (GtkCellArea *area);
436GDK_AVAILABLE_IN_ALL
437gboolean gtk_cell_area_activate (GtkCellArea *area,
438 GtkCellAreaContext *context,
439 GtkWidget *widget,
440 const GdkRectangle *cell_area,
441 GtkCellRendererState flags,
442 gboolean edit_only);
443GDK_AVAILABLE_IN_ALL
444gboolean gtk_cell_area_focus (GtkCellArea *area,
445 GtkDirectionType direction);
446GDK_AVAILABLE_IN_ALL
447void gtk_cell_area_set_focus_cell (GtkCellArea *area,
448 GtkCellRenderer *renderer);
449GDK_AVAILABLE_IN_ALL
450GtkCellRenderer *gtk_cell_area_get_focus_cell (GtkCellArea *area);
451
452
453/* Focus siblings */
454GDK_AVAILABLE_IN_ALL
455void gtk_cell_area_add_focus_sibling (GtkCellArea *area,
456 GtkCellRenderer *renderer,
457 GtkCellRenderer *sibling);
458GDK_AVAILABLE_IN_ALL
459void gtk_cell_area_remove_focus_sibling (GtkCellArea *area,
460 GtkCellRenderer *renderer,
461 GtkCellRenderer *sibling);
462GDK_AVAILABLE_IN_ALL
463gboolean gtk_cell_area_is_focus_sibling (GtkCellArea *area,
464 GtkCellRenderer *renderer,
465 GtkCellRenderer *sibling);
466GDK_AVAILABLE_IN_ALL
467const GList * gtk_cell_area_get_focus_siblings (GtkCellArea *area,
468 GtkCellRenderer *renderer);
469GDK_AVAILABLE_IN_ALL
470GtkCellRenderer *gtk_cell_area_get_focus_from_sibling (GtkCellArea *area,
471 GtkCellRenderer *renderer);
472
473/* Cell Activation/Editing */
474GDK_AVAILABLE_IN_ALL
475GtkCellRenderer *gtk_cell_area_get_edited_cell (GtkCellArea *area);
476GDK_AVAILABLE_IN_ALL
477GtkCellEditable *gtk_cell_area_get_edit_widget (GtkCellArea *area);
478GDK_AVAILABLE_IN_ALL
479gboolean gtk_cell_area_activate_cell (GtkCellArea *area,
480 GtkWidget *widget,
481 GtkCellRenderer *renderer,
482 GdkEvent *event,
483 const GdkRectangle *cell_area,
484 GtkCellRendererState flags);
485GDK_AVAILABLE_IN_ALL
486void gtk_cell_area_stop_editing (GtkCellArea *area,
487 gboolean canceled);
488
489/* Functions for area implementations */
490
491/* Distinguish the inner cell area from the whole requested area including margins */
492GDK_AVAILABLE_IN_ALL
493void gtk_cell_area_inner_cell_area (GtkCellArea *area,
494 GtkWidget *widget,
495 const GdkRectangle *cell_area,
496 GdkRectangle *inner_area);
497
498/* Request the size of a cell while respecting the cell margins (requests are margin inclusive) */
499GDK_AVAILABLE_IN_ALL
500void gtk_cell_area_request_renderer (GtkCellArea *area,
501 GtkCellRenderer *renderer,
502 GtkOrientation orientation,
503 GtkWidget *widget,
504 int for_size,
505 int *minimum_size,
506 int *natural_size);
507
508/* For api stability, this is called from gtkcelllayout.c in order to ensure the correct
509 * object is passed to the user function in gtk_cell_layout_set_cell_data_func.
510 *
511 * This private api takes gpointer & GFunc arguments to circumvent circular header file
512 * dependencies.
513 */
514void _gtk_cell_area_set_cell_data_func_with_proxy (GtkCellArea *area,
515 GtkCellRenderer *cell,
516 GFunc func,
517 gpointer func_data,
518 GDestroyNotify destroy,
519 gpointer proxy);
520
521G_END_DECLS
522
523#endif /* __GTK_CELL_AREA_H__ */
524

source code of gtk/gtk/gtkcellarea.h