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