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