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

source code of include/gtk-3.0/gtk/gtkcellarea.h