]> Pileus Git - ~andy/gtk/blob - gtk/gtkstylecontext.h
Add helper API for getting colors/borders in GtkStyleContext/GtkThemingEngine
[~andy/gtk] / gtk / gtkstylecontext.h
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 2010 Carlos Garnacho <carlosg@gnome.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #ifndef __GTK_STYLE_CONTEXT_H__
21 #define __GTK_STYLE_CONTEXT_H__
22
23 #include <glib-object.h>
24 #include <gtk/gtkstyleprovider.h>
25 #include <gtk/gtkwidgetpath.h>
26 #include <gtk/gtkborder.h>
27
28 G_BEGIN_DECLS
29
30 #define GTK_TYPE_STYLE_CONTEXT         (gtk_style_context_get_type ())
31 #define GTK_STYLE_CONTEXT(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_STYLE_CONTEXT, GtkStyleContext))
32 #define GTK_STYLE_CONTEXT_CLASS(c)     (G_TYPE_CHECK_CLASS_CAST    ((c), GTK_TYPE_STYLE_CONTEXT, GtkStyleContextClass))
33 #define GTK_IS_STYLE_CONTEXT(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_STYLE_CONTEXT))
34 #define GTK_IS_STYLE_CONTEXT_CLASS(c)  (G_TYPE_CHECK_CLASS_TYPE    ((c), GTK_TYPE_STYLE_CONTEXT))
35 #define GTK_STYLE_CONTEXT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS  ((o), GTK_TYPE_STYLE_CONTEXT, GtkStyleContextClass))
36
37 typedef struct _GtkStyleContext GtkStyleContext;
38 typedef struct _GtkStyleContextClass GtkStyleContextClass;
39
40 struct _GtkStyleContext
41 {
42   GObject parent_object;
43   gpointer priv;
44 };
45
46 struct _GtkStyleContextClass
47 {
48   GObjectClass parent_class;
49
50   void (* changed) (GtkStyleContext *context);
51 };
52
53 /* Default set of properties that GtkStyleContext may contain */
54
55 /**
56  * GTK_STYLE_PROPERTY_BACKGROUND_COLOR:
57  *
58  * A property holding the background color of rendered elements as a #GdkRGBA.
59  */
60 #define GTK_STYLE_PROPERTY_BACKGROUND_COLOR "background-color"
61
62 /**
63  * GTK_STYLE_PROPERTY_COLOR:
64  *
65  * A property holding the foreground color of rendered elements as a #GdkRGBA.
66  */
67 #define GTK_STYLE_PROPERTY_COLOR "color"
68
69 /**
70  * GTK_STYLE_PROPERTY_FONT:
71  *
72  * A property holding the font properties used when rendering text
73  * as a #PangoFontDescription.
74  */
75 #define GTK_STYLE_PROPERTY_FONT "font"
76
77 /**
78  * GTK_STYLE_PROPERTY_MARGIN:
79  *
80  * A property holding the rendered element's margin as a #GtkBorder. The
81  * margin is defined as the spacing between the border of the element
82  * and its surrounding elements.
83  */
84 #define GTK_STYLE_PROPERTY_MARGIN "margin"
85
86 /**
87  * GTK_STYLE_PROPERTY_PADDING:
88  *
89  * A property holding the rendered element's padding as a #GtkBorder. The
90  * padding is defined as the spacing between the inner part of the element border
91  * and its child.
92  */
93 #define GTK_STYLE_PROPERTY_PADDING "padding"
94
95 /**
96  * GTK_STYLE_PROPERTY_BORDER_WIDTH:
97  *
98  * A property holding the rendered element's border width in pixels as a #gint.
99  */
100 #define GTK_STYLE_PROPERTY_BORDER_WIDTH "border-width"
101
102 /**
103  * GTK_STYLE_PROPERTY_BORDER_RADIUS:
104  *
105  * A property holding the rendered element's border radius in pixels as a #gint.
106  */
107 #define GTK_STYLE_PROPERTY_BORDER_RADIUS "border-radius"
108
109 /**
110  * GTK_STYLE_PROPERTY_BORDER_STYLE:
111  *
112  * A property holding the element's border style as a #GtkBorderStyle.
113  */
114 #define GTK_STYLE_PROPERTY_BORDER_STYLE "border-style"
115
116 /**
117  * GTK_STYLE_PROPERTY_BORDER_COLOR:
118  *
119  * A property holding the element's border color as a #GdkRGBA.
120  */
121 #define GTK_STYLE_PROPERTY_BORDER_COLOR "border-color"
122
123 /**
124  * GTK_STYLE_PROPERTY_BACKGROUND_IMAGE:
125  *
126  * A property holding the element's background as a #cairo_pattern_t.
127  */
128 #define GTK_STYLE_PROPERTY_BACKGROUND_IMAGE "background-image"
129
130
131 /* Predefined set of CSS classes */
132
133 /**
134  * GTK_STYLE_CLASS_CELL:
135  *
136  * A CSS class to match content rendered in cell views.
137  */
138 #define GTK_STYLE_CLASS_CELL "cell"
139
140 /**
141  * GTK_STYLE_CLASS_ENTRY:
142  *
143  * A CSS class to match text entries.
144  */
145 #define GTK_STYLE_CLASS_ENTRY "entry"
146
147 /**
148  * GTK_STYLE_CLASS_BUTTON:
149  *
150  * A CSS class to match buttons.
151  */
152 #define GTK_STYLE_CLASS_BUTTON "button"
153
154 /**
155  * GTK_STYLE_CLASS_CALENDAR:
156  *
157  * A CSS class to match calendars.
158  */
159 #define GTK_STYLE_CLASS_CALENDAR "calendar"
160
161 /**
162  * GTK_STYLE_CLASS_SLIDER:
163  *
164  * A CSS class to match sliders.
165  */
166 #define GTK_STYLE_CLASS_SLIDER "slider"
167
168 /**
169  * GTK_STYLE_CLASS_BACKGROUND:
170  *
171  * A CSS class to match the window background.
172  */
173 #define GTK_STYLE_CLASS_BACKGROUND "background"
174
175 /**
176  * GTK_STYLE_CLASS_RUBBERBAND:
177  *
178  * A CSS class to match the rubberband selection rectangle.
179  */
180 #define GTK_STYLE_CLASS_RUBBERBAND "rubberband"
181
182 /**
183  * GTK_STYLE_CLASS_TOOLTIP:
184  *
185  * A CSS class to match tooltip windows.
186  */
187 #define GTK_STYLE_CLASS_TOOLTIP "tooltip"
188
189 /**
190  * GTK_STYLE_CLASS_MENU:
191  *
192  * A CSS class to match popup menus.
193  */
194 #define GTK_STYLE_CLASS_MENU "menu"
195
196 /**
197  * GTK_STYLE_CLASS_MENUBAR:
198  *
199  * A CSS class to menubars.
200  */
201 #define GTK_STYLE_CLASS_MENUBAR "menubar"
202
203 /**
204  * GTK_STYLE_CLASS_MENUITEM:
205  *
206  * A CSS class to match menu items.
207  */
208 #define GTK_STYLE_CLASS_MENUITEM "menuitem"
209
210 /**
211  * GTK_STYLE_CLASS_TOOLBAR:
212  *
213  * A CSS class to match toolbars.
214  */
215 #define GTK_STYLE_CLASS_TOOLBAR "toolbar"
216
217 /**
218  * GTK_STYLE_CLASS_RADIO:
219  *
220  * A CSS class to match radio buttons.
221  */
222 #define GTK_STYLE_CLASS_RADIO "radio"
223
224 /**
225  * GTK_STYLE_CLASS_CHECK:
226  *
227  * A CSS class to match check boxes.
228  */
229 #define GTK_STYLE_CLASS_CHECK "check"
230
231 /**
232  * GTK_STYLE_CLASS_DEFAULT:
233  *
234  * A CSS class to match the default widget.
235  */
236 #define GTK_STYLE_CLASS_DEFAULT "default"
237
238 /**
239  * GTK_STYLE_CLASS_TROUGH:
240  *
241  * A CSS class to match troughs, as in scrollbars and progressbars.
242  */
243 #define GTK_STYLE_CLASS_TROUGH "trough"
244
245 /**
246  * GTK_STYLE_CLASS_SCROLLBAR:
247  *
248  * A CSS class to match scrollbars.
249  */
250 #define GTK_STYLE_CLASS_SCROLLBAR "scrollbar"
251
252 /**
253  * GTK_STYLE_CLASS_HEADER:
254  *
255  * A CSS class to match a header element.
256  */
257 #define GTK_STYLE_CLASS_HEADER "header"
258
259 /**
260  * GTK_STYLE_CLASS_ACCELERATOR:
261  *
262  * A CSS class to match an accelerator.
263  */
264 #define GTK_STYLE_CLASS_ACCELERATOR "accelerator"
265
266 /**
267  * GTK_STYLE_CLASS_GRIP:
268  *
269  * A widget class defining a resize grip
270  */
271 #define GTK_STYLE_CLASS_GRIP "grip"
272
273 /**
274  * GTK_STYLE_CLASS_DOCK:
275  *
276  * A widget class defining a dock area
277  */
278 #define GTK_STYLE_CLASS_DOCK "dock"
279
280 /**
281  * GTK_STYLE_CLASS_PROGRESSBAR:
282  *
283  * A widget class defining a resize grip
284  */
285 #define GTK_STYLE_CLASS_PROGRESSBAR "progressbar"
286
287 /**
288  * GTK_STYLE_CLASS_SPINNER:
289  *
290  * A widget class defining a spinner
291  */
292 #define GTK_STYLE_CLASS_SPINNER "spinner"
293
294 /* Predefined set of widget regions */
295
296 /**
297  * GTK_STYLE_REGION_ROW:
298  *
299  * A widget region name to define a treeview row.
300  */
301 #define GTK_STYLE_REGION_ROW "row"
302
303 /**
304  * GTK_STYLE_REGION_COLUMN:
305  *
306  * A widget region name to define a treeview column.
307  */
308 #define GTK_STYLE_REGION_COLUMN "column"
309
310 /**
311  * GTK_STYLE_REGION_COLUMN_HEADER:
312  *
313  * A widget region name to define a treeview column header.
314  */
315 #define GTK_STYLE_REGION_COLUMN_HEADER "column-header"
316
317 /**
318  * GTK_STYLE_REGION_TAB:
319  *
320  * A widget region name to define a notebook tab.
321  */
322 #define GTK_STYLE_REGION_TAB "tab"
323
324
325 GType gtk_style_context_get_type (void) G_GNUC_CONST;
326
327 GtkStyleContext * gtk_style_context_new (void);
328
329 void gtk_style_context_add_provider_for_screen    (GdkScreen        *screen,
330                                                    GtkStyleProvider *provider,
331                                                    guint             priority);
332 void gtk_style_context_remove_provider_for_screen (GdkScreen        *screen,
333                                                    GtkStyleProvider *provider);
334
335 void gtk_style_context_add_provider    (GtkStyleContext  *context,
336                                         GtkStyleProvider *provider,
337                                         guint             priority);
338
339 void gtk_style_context_remove_provider (GtkStyleContext  *context,
340                                         GtkStyleProvider *provider);
341
342 void gtk_style_context_save    (GtkStyleContext *context);
343 void gtk_style_context_restore (GtkStyleContext *context);
344
345 void gtk_style_context_get_property (GtkStyleContext *context,
346                                      const gchar     *property,
347                                      GtkStateFlags    state,
348                                      GValue          *value);
349 void gtk_style_context_get_valist   (GtkStyleContext *context,
350                                      GtkStateFlags    state,
351                                      va_list          args);
352 void gtk_style_context_get          (GtkStyleContext *context,
353                                      GtkStateFlags    state,
354                                      ...) G_GNUC_NULL_TERMINATED;
355
356 void          gtk_style_context_set_state    (GtkStyleContext *context,
357                                               GtkStateFlags    flags);
358 GtkStateFlags gtk_style_context_get_state    (GtkStyleContext *context);
359
360 gboolean      gtk_style_context_state_is_running (GtkStyleContext *context,
361                                                   GtkStateType     state,
362                                                   gdouble         *progress);
363
364 void          gtk_style_context_set_path     (GtkStyleContext *context,
365                                               GtkWidgetPath   *path);
366 G_CONST_RETURN GtkWidgetPath * gtk_style_context_get_path (GtkStyleContext *context);
367
368 GList *  gtk_style_context_list_classes (GtkStyleContext *context);
369
370 void     gtk_style_context_add_class    (GtkStyleContext *context,
371                                          const gchar     *class_name);
372 void     gtk_style_context_remove_class (GtkStyleContext *context,
373                                          const gchar     *class_name);
374 gboolean gtk_style_context_has_class    (GtkStyleContext *context,
375                                          const gchar     *class_name);
376
377 GList *  gtk_style_context_list_regions (GtkStyleContext *context);
378
379 void     gtk_style_context_add_region    (GtkStyleContext    *context,
380                                           const gchar        *region_name,
381                                           GtkRegionFlags      flags);
382 void     gtk_style_context_remove_region (GtkStyleContext    *context,
383                                           const gchar        *region_name);
384 gboolean gtk_style_context_has_region    (GtkStyleContext    *context,
385                                           const gchar        *region_name,
386                                           GtkRegionFlags     *flags_return);
387
388 void gtk_style_context_get_style_property (GtkStyleContext *context,
389                                            const gchar     *property_name,
390                                            GValue          *value);
391 void gtk_style_context_get_style_valist   (GtkStyleContext *context,
392                                            va_list          args);
393 void gtk_style_context_get_style          (GtkStyleContext *context,
394                                            ...);
395
396 GtkIconSet * gtk_style_context_lookup_icon_set (GtkStyleContext *context,
397                                                 const gchar     *stock_id);
398
399 void        gtk_style_context_set_screen (GtkStyleContext *context,
400                                           GdkScreen       *screen);
401 GdkScreen * gtk_style_context_get_screen (GtkStyleContext *context);
402
403 void             gtk_style_context_set_direction (GtkStyleContext  *context,
404                                                   GtkTextDirection  direction);
405 GtkTextDirection gtk_style_context_get_direction (GtkStyleContext  *context);
406
407 void             gtk_style_context_set_junction_sides (GtkStyleContext  *context,
408                                                        GtkJunctionSides  sides);
409 GtkJunctionSides gtk_style_context_get_junction_sides (GtkStyleContext  *context);
410
411 gboolean gtk_style_context_lookup_color (GtkStyleContext *context,
412                                          const gchar     *color_name,
413                                          GdkRGBA         *color);
414
415 void  gtk_style_context_notify_state_change (GtkStyleContext *context,
416                                              GdkWindow       *window,
417                                              gpointer         region_id,
418                                              GtkStateType     state,
419                                              gboolean         state_value);
420 void gtk_style_context_push_animatable_region (GtkStyleContext *context,
421                                                gpointer         region_id);
422 void gtk_style_context_pop_animatable_region  (GtkStyleContext *context);
423
424 /* Some helper functions to retrieve most common properties */
425 void gtk_style_context_get_color            (GtkStyleContext *context,
426                                              GtkStateFlags    state,
427                                              GdkRGBA         *color);
428 void gtk_style_context_get_background_color (GtkStyleContext *context,
429                                              GtkStateFlags    state,
430                                              GdkRGBA         *color);
431 void gtk_style_context_get_border_color     (GtkStyleContext *context,
432                                              GtkStateFlags    state,
433                                              GdkRGBA         *color);
434
435 void gtk_style_context_get_border           (GtkStyleContext *context,
436                                              GtkStateFlags    state,
437                                              GtkBorder       *border);
438 void gtk_style_context_get_padding          (GtkStyleContext *context,
439                                              GtkStateFlags    state,
440                                              GtkBorder       *padding);
441 void gtk_style_context_get_margin           (GtkStyleContext *context,
442                                              GtkStateFlags    state,
443                                              GtkBorder       *margin);
444
445 /* Semi-private API */
446 const GValue * _gtk_style_context_peek_style_property (GtkStyleContext *context,
447                                                        GType            widget_type,
448                                                        GtkStateFlags    state,
449                                                        GParamSpec      *pspec);
450 void           _gtk_style_context_invalidate_animation_areas (GtkStyleContext *context);
451 void           _gtk_style_context_coalesce_animation_areas   (GtkStyleContext *context,
452                                                               gint             rel_x,
453                                                               gint             rel_y);
454
455 void gtk_style_context_invalidate (GtkStyleContext *context);
456 void gtk_style_context_reset_widgets (GdkScreen *screen);
457
458 void gtk_style_context_set_background (GtkStyleContext *context,
459                                        GdkWindow       *window);
460
461 /* Paint methods */
462 void gtk_render_check (GtkStyleContext *context,
463                        cairo_t         *cr,
464                        gdouble          x,
465                        gdouble          y,
466                        gdouble          width,
467                        gdouble          height);
468 void gtk_render_option (GtkStyleContext *context,
469                         cairo_t         *cr,
470                         gdouble          x,
471                         gdouble          y,
472                         gdouble          width,
473                         gdouble          height);
474 void gtk_render_arrow  (GtkStyleContext *context,
475                         cairo_t         *cr,
476                         gdouble          angle,
477                         gdouble          x,
478                         gdouble          y,
479                         gdouble          size);
480 void gtk_render_background (GtkStyleContext *context,
481                             cairo_t         *cr,
482                             gdouble          x,
483                             gdouble          y,
484                             gdouble          width,
485                             gdouble          height);
486 void gtk_render_frame  (GtkStyleContext *context,
487                         cairo_t         *cr,
488                         gdouble          x,
489                         gdouble          y,
490                         gdouble          width,
491                         gdouble          height);
492 void gtk_render_expander (GtkStyleContext *context,
493                           cairo_t         *cr,
494                           gdouble          x,
495                           gdouble          y,
496                           gdouble          width,
497                           gdouble          height);
498 void gtk_render_focus    (GtkStyleContext *context,
499                           cairo_t         *cr,
500                           gdouble          x,
501                           gdouble          y,
502                           gdouble          width,
503                           gdouble          height);
504 void gtk_render_layout   (GtkStyleContext *context,
505                           cairo_t         *cr,
506                           gdouble          x,
507                           gdouble          y,
508                           PangoLayout     *layout);
509 void gtk_render_line     (GtkStyleContext *context,
510                           cairo_t         *cr,
511                           gdouble          x0,
512                           gdouble          y0,
513                           gdouble          x1,
514                           gdouble          y1);
515 void gtk_render_slider   (GtkStyleContext *context,
516                           cairo_t         *cr,
517                           gdouble          x,
518                           gdouble          y,
519                           gdouble          width,
520                           gdouble          height,
521                           GtkOrientation   orientation);
522 void gtk_render_frame_gap (GtkStyleContext *context,
523                            cairo_t         *cr,
524                            gdouble          x,
525                            gdouble          y,
526                            gdouble          width,
527                            gdouble          height,
528                            GtkPositionType  gap_side,
529                            gdouble          xy0_gap,
530                            gdouble          xy1_gap);
531 void gtk_render_extension (GtkStyleContext *context,
532                            cairo_t         *cr,
533                            gdouble          x,
534                            gdouble          y,
535                            gdouble          width,
536                            gdouble          height,
537                            GtkPositionType  gap_side);
538 void gtk_render_handle    (GtkStyleContext *context,
539                            cairo_t         *cr,
540                            gdouble          x,
541                            gdouble          y,
542                            gdouble          width,
543                            gdouble          height);
544 void gtk_render_activity  (GtkStyleContext *context,
545                            cairo_t         *cr,
546                            gdouble          x,
547                            gdouble          y,
548                            gdouble          width,
549                            gdouble          height);
550
551 GdkPixbuf * gtk_render_icon_pixbuf (GtkStyleContext     *context,
552                                     const GtkIconSource *source,
553                                     GtkIconSize          size);
554
555 G_END_DECLS
556
557 #endif /* __GTK_STYLE_CONTEXT_H__ */