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