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