Debian Codegraph @

gtk/src/stylecontext.hg

raw
1 /* Copyright (C) 2010 The gtkmm Development Team
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
15 */
16
17 _DEFS(gtkmm,gtk)
18 _PINCLUDE(glibmm/private/object_p.h)
19 _PINCLUDE(gtk/gtk.h)
20
21 #include <gtkmm/styleprovider.h>
22 #include <gtkmm/border.h>
23 #include <gtkmm/enums.h>
24 #include <gdkmm/window.h>
25 #include <gdkmm/screen.h>
26
27 #include <gtkmm/enums.h>
28 #ifndef GTKMM_DISABLE_DEPRECATED
29 #include <gtkmm/iconsource.h>
30 #include <gtkmm/iconset.h>
31 #endif
32 #include <gtkmm/widgetpath.h>
33 #include <pangomm/context.h>
34 #include <pangomm/fontdescription.h>
35 #include <pangomm/layout.h>
36 #include <gtkmmconfig.h>
37
38 namespace Gdk
39 {
40 class GTKMM_API FrameClock;
41 }
42
43 namespace Gtk
44 {
45
46 class GTKMM_API IconSet;
47
48 //TODO: Add (and translate to C++) the code examples from the C documentation.
49 /** This object stores styling information affecting a widget defined by WidgetPath.
50 *
51 * In order to construct the final style information, StyleContext
52 * queries information from all attached StyleProviders. Style providers
53 * can be either attached explicitly to the context through
54 * add_provider(), or to the screen through
55 * add_provider_for_screen(). The resulting style is a
56 * combination of all providers' information in priority order.
57 *
58 * For GTK+ widgets, any StyleContext returned by
59 * Widget::get_style_context() will already have a WidgetPath, a
60 * Gdk::Screen and RTL/LTR information set, The style context will be also
61 * updated automatically if any of these settings change on the widget.
62 *
63 * If you are using the theming layer standalone, you will need to set a
64 * widget path and a screen yourself to the created style context through
65 * set_path() and set_screen(), as well
66 * as updating the context yourself using invalidate()
67 * whenever any of the conditions change, such as a change in the
68 * Settings::property_gtk_theme_name() setting or a hierarchy change in the rendered
69 * widget.
70 *
71 * <h2>Transition animations</h2>
72 *
73 * StyleContext has built-in support for state change transitions.
74 * Note that these animations respect the Settings::property_gtk_enable_animations()
75 * setting.
76 *
77 * For simple widgets where state changes affect the whole widget area,
78 * calling notify_state_change() with a no region
79 * is sufficient to trigger the transition animation. And GTK+ already
80 * does that when Widget::set_state() or Widget::set_state_flags()
81 * are called.
82 *
83 * If a widget needs to declare several animatable regions (i.e. not
84 * affecting the whole widget area), its Widget::signal_draw() signal handler
85 * needs to wrap the render operations for the different regions with
86 * calls to push_animatable_region() and
87 * pop_animatable_region(). These methods take an
88 * identifier for the region which must be unique within the style context.
89 * For simple widgets with a fixed set of animatable regions, using an
90 * enumeration works well.
91 *
92 * For complex widgets with an arbitrary number of animatable regions, it
93 * is up to the implementation to come up with a way to uniquely identify
94 * each animatable region. Using pointers to internal objects is one way
95 * to achieve this.
96 *
97 * The widget also needs to notify the style context about a state change
98 * for a given animatable region so the animation is triggered.
99 * notify_state_change() can take no region IDs, meaning that the whole widget
100 * area will be updated by the animation.
101 *
102 * @newin{3,0}
103 */
104 class GTKMM_API StyleContext : public Glib::Object
105 {
106 _CLASS_GOBJECT(StyleContext, GtkStyleContext, GTK_STYLE_CONTEXT, Glib::Object, GObject, , , GTKMM_API)
107 protected:
108 _CTOR_DEFAULT()
109
110 public:
111 _WRAP_CREATE()
112 _IGNORE(gtk_style_context_new)
113
114 _WRAP_METHOD(static void add_provider_for_screen(const Glib::RefPtr<Gdk::Screen>& screen, const Glib::RefPtr<StyleProvider>& provider, guint priority), gtk_style_context_add_provider_for_screen)
115 _WRAP_METHOD(static void remove_provider_for_screen(const Glib::RefPtr<Gdk::Screen>& screen, const Glib::RefPtr<StyleProvider>& provider), gtk_style_context_remove_provider_for_screen)
116
117 _WRAP_METHOD(void add_provider(const Glib::RefPtr<StyleProvider>& provider, guint priority), gtk_style_context_add_provider)
118
119 _WRAP_METHOD(void remove_provider(const Glib::RefPtr<StyleProvider>& provider), gtk_style_context_remove_provider)
120
121 _WRAP_METHOD(void context_save(), gtk_style_context_save)
122 _WRAP_METHOD(void context_restore(), gtk_style_context_restore)
123
124 //TODO: GtkCssSection * gtk_style_context_get_section (GtkStyleContext *context, const gchar *property);
125 /* TODO:
126 _WRAP_METHOD(void get_property (
127 const Glib::ustring& property,
128 StateFlags state,
129 GValue *value), gtk_style_context_get_property)
130 _WRAP_METHOD(void get_valist (
131 StateFlags state,
132 va_list args), gtk_style_context_get_valist)
133 _WRAP_METHOD(void get (
134 StateFlags state,
135 ...) G_GNUC_NULL_TERMINATED;
136 */
137
138 _WRAP_METHOD(void set_state(StateFlags flags), gtk_style_context_set_state)
139 _WRAP_METHOD(StateFlags get_state() const, gtk_style_context_get_state)
140
141 _WRAP_METHOD(void set_scale(int scale), gtk_style_context_set_scale)
142 _WRAP_METHOD(int get_scale() const, gtk_style_context_get_scale)
143
144 _WRAP_METHOD(bool state_is_running(StateType state, gdouble* progress), gtk_style_context_state_is_running, deprecated "This function always returns <tt>false</tt>.")
145
146 _WRAP_METHOD(void set_path(const WidgetPath& path), gtk_style_context_set_path)
147
148 #m4 _CONVERSION(`const GtkWidgetPath*',`WidgetPath',`WidgetPath(const_cast<GtkWidgetPath*>($3), true)')
149 _WRAP_METHOD(WidgetPath get_path() const, gtk_style_context_get_path)
150
151 _WRAP_METHOD(void set_parent(const Glib::RefPtr<StyleContext>& parent), gtk_style_context_set_parent)
152 void unset_parent();
153
154 _WRAP_METHOD(Glib::RefPtr<StyleContext> get_parent(), gtk_style_context_get_parent, refreturn)
155 _WRAP_METHOD(Glib::RefPtr<const StyleContext> get_parent() const, gtk_style_context_get_parent, refreturn, constversion)
156
157 #m4 _CONVERSION(`GList*',`std::vector<Glib::ustring>',`Glib::ListHandler<Glib::ustring>::list_to_vector($3, Glib::OWNERSHIP_SHALLOW)')
158 _WRAP_METHOD(std::vector<Glib::ustring> list_classes() const, gtk_style_context_list_classes)
159
160 _WRAP_METHOD(void add_class(const Glib::ustring& class_name), gtk_style_context_add_class)
161 _WRAP_METHOD(void remove_class(const Glib::ustring& class_name), gtk_style_context_remove_class)
162 _WRAP_METHOD(bool has_class(const Glib::ustring& class_name), gtk_style_context_has_class)
163
164 _WRAP_METHOD(GList* list_regions(), gtk_style_context_list_regions, deprecated "There is no replacement.")
165 _WRAP_METHOD(void add_region(const Glib::ustring& region_name, RegionFlags flags), gtk_style_context_add_region, deprecated "There is no replacement.")
166 _WRAP_METHOD(void remove_region(const Glib::ustring& region_name), gtk_style_context_remove_region, deprecated "There is no replacement.")
167 _WRAP_METHOD(bool has_region(const Glib::ustring& region_name, RegionFlags& flags_return), gtk_style_context_has_region, deprecated "There is no replacement.")
168
169 /** Gets the value of a style property
170 * @param property_name The name of a style property.
171 * @param value Location to return the property value.
172 */
173 template <class PropertyType>
174 void get_style_property(const Glib::ustring& property_name, PropertyType& value) const;
175
176 _WRAP_METHOD(void get_style_property_value(
177 const Glib::ustring& property_name, Glib::ValueBase& value) const,
178 gtk_style_context_get_style_property)
179 _IGNORE(gtk_style_context_get_style, gtk_style_context_get_style, )
180
181 _WRAP_METHOD(Glib::RefPtr<IconSet> lookup_icon_set(const Glib::ustring& stock_id), gtk_style_context_lookup_icon_set, refreturn, deprecated "Use IconTheme::lookup_icon() instead.")
182
183 // gtk_icon_set_render_icon_pixbuf() in gtkstylecontext.h is wrapped in IconSet::render_icon_pixbuf().
184
185 _WRAP_METHOD(void set_screen(const Glib::RefPtr<Gdk::Screen>& screen), gtk_style_context_set_screen)
186
187 _WRAP_METHOD(Glib::RefPtr<Gdk::Screen> get_screen(), gtk_style_context_get_screen, refreturn)
188 _WRAP_METHOD(Glib::RefPtr<const Gdk::Screen> get_screen() const, gtk_style_context_get_screen, refreturn, constversion)
189
190 _WRAP_METHOD(void set_direction(TextDirection direction), gtk_style_context_set_direction,
191 deprecated "Use set_state() with Gtk::STATE_FLAG_DIR_LTR and Gtk::STATE_FLAG_DIR_RTL instead.")
192 _WRAP_METHOD(TextDirection get_direction() const, gtk_style_context_get_direction,
193 deprecated "Use get_state() and check for Gtk::STATE_FLAG_DIR_LTR and Gtk::STATE_FLAG_DIR_RTL instead.")
194
195 _WRAP_METHOD(void set_junction_sides(JunctionSides sides), gtk_style_context_set_junction_sides)
196 _WRAP_METHOD(JunctionSides get_junction_sides() const, gtk_style_context_get_junction_sides)
197
198 _WRAP_METHOD(void set_frame_clock(const Glib::RefPtr<Gdk::FrameClock>& frame_clock), gtk_style_context_set_frame_clock, newin "3,24")
199 _WRAP_METHOD(Glib::RefPtr<Gdk::FrameClock> get_frame_clock(), gtk_style_context_get_frame_clock, refreturn, newin "3,24")
200 _WRAP_METHOD(Glib::RefPtr<const Gdk::FrameClock> get_frame_clock() const, gtk_style_context_get_frame_clock, refreturn, constversion, newin "3,24")
201
202 _WRAP_METHOD(bool lookup_color(const Glib::ustring& color_name, Gdk::RGBA& color), gtk_style_context_lookup_color)
203
204 _WRAP_METHOD(void notify_state_change(const Glib::RefPtr<Gdk::Window>& window, gpointer region_id, StateType state, bool state_value), gtk_style_context_notify_state_change, deprecated "This function does nothing.")
205
206 _WRAP_METHOD(void cancel_animations(gpointer region_id), gtk_style_context_cancel_animations, deprecated "This function does nothing.")
207 _WRAP_METHOD(void scroll_animations(const Glib::RefPtr<Gdk::Window>& window, int dx, int dy), gtk_style_context_scroll_animations, deprecated "This function does nothing.")
208
209 _WRAP_METHOD(void push_animatable_region(gpointer region_id), gtk_style_context_push_animatable_region, deprecated "This function does nothing.")
210 _WRAP_METHOD(void pop_animatable_region(), gtk_style_context_pop_animatable_region, deprecated "This function does nothing.")
211
212 /** Gets the foreground color for a given state.
213 *
214 * @newin{3,0}
215 *
216 * @param state State to retrieve the color for.
217 * @return The foreground color for the given state.
218 */
219 Gdk::RGBA get_color(StateFlags state = (StateFlags)0) const;
220 _IGNORE(gtk_style_context_get_color)
221
222 _DEPRECATE_IFDEF_START
223 /** @deprecated Use render_background() instead.
224 */
225 Gdk::RGBA get_background_color(StateFlags state = (StateFlags)0) const;
226 _IGNORE(gtk_style_context_get_background_color)
227
228 /** @deprecated Use render_frame() instead.
229 */
230 Gdk::RGBA get_border_color(StateFlags state = (StateFlags)0) const;
231 _IGNORE(gtk_style_context_get_border_color)
232 _DEPRECATE_IFDEF_END
233
234 /** Returns the font description for a given state.
235 *
236 * @newin{3,0}
237 *
238 * @param state State to retrieve the font for.
239 * @return The Pango::FontDescription for the given state.
240 */
241 Pango::FontDescription get_font(StateFlags state = (StateFlags)0) const;
242 _IGNORE(gtk_style_context_get_font)
243
244 Border get_border(StateFlags state = (StateFlags)0) const;
245 _IGNORE(gtk_style_context_get_border)
246
247 Border get_padding(StateFlags state = (StateFlags)0) const;
248 _IGNORE(gtk_style_context_get_padding)
249
250 Border get_margin (StateFlags state = (StateFlags)0) const;
251 _IGNORE(gtk_style_context_get_margin)
252
253 _WRAP_METHOD(void invalidate(), gtk_style_context_invalidate, deprecated "Style contexts are invalidated automatically.")
254 //TODO: _WRAP_METHOD(void reset_widgets(const Glib::RefPtr<Gdk::Screen>& screen), gtk_style_context_reset_widgets)
255
256 _WRAP_METHOD(void set_background(const Glib::RefPtr<Gdk::Window>& window), gtk_style_context_set_background,
257 deprecated "Use render_background() instead. Note that clients still using this function are now responsible for calling this function again whenever the context is invalidated.")
258
259 _WRAP_METHOD(void render_check(const ::Cairo::RefPtr< ::Cairo::Context>& cr, double x, double y, double width, double height), gtk_render_check)
260 _WRAP_METHOD(void render_option(const ::Cairo::RefPtr< ::Cairo::Context>& cr, double x, double y, double width, double height), gtk_render_option)
261 _WRAP_METHOD(void render_arrow(const ::Cairo::RefPtr< ::Cairo::Context>& cr, double angle, double x, double y, double size), gtk_render_arrow)
262 _WRAP_METHOD(void render_background(const ::Cairo::RefPtr< ::Cairo::Context>& cr, double x, double y, double width, double height), gtk_render_background)
263 _WRAP_METHOD(void render_frame(const ::Cairo::RefPtr< ::Cairo::Context>& cr, double x, double y, double width, double height), gtk_render_frame)
264 _WRAP_METHOD(void render_expander(const ::Cairo::RefPtr< ::Cairo::Context>& cr, double x, double y, double width, double height), gtk_render_expander)
265 _WRAP_METHOD(void render_focus(const ::Cairo::RefPtr< ::Cairo::Context>& cr, double x, double y, double width, double height), gtk_render_focus)
266 _WRAP_METHOD(void render_layout(const ::Cairo::RefPtr< ::Cairo::Context>& cr, double x, double y, PangoLayout* layout), gtk_render_layout, deprecated "Use the render_layout() taking a const Glib::RefPtr<Pango::Layout>& layout.")
267 _WRAP_METHOD(void render_layout(const ::Cairo::RefPtr< ::Cairo::Context>& cr, double x, double y, const Glib::RefPtr<Pango::Layout>& layout), gtk_render_layout)
268 _WRAP_METHOD(void render_line(const ::Cairo::RefPtr< ::Cairo::Context>& cr, double x0, double y0, double x1, double y1), gtk_render_line)
269 _WRAP_METHOD(void render_slider(const ::Cairo::RefPtr< ::Cairo::Context>& cr, double x, double y, double width, double height, Orientation orientation), gtk_render_slider)
270 _WRAP_METHOD(void render_frame_gap(const ::Cairo::RefPtr< ::Cairo::Context>& cr, double x, double y, double width, double height, PositionType gap_side, double xy0_gap, double xy1_gap), gtk_render_frame_gap,
271 deprecated "Use render_frame() instead. Themes can create gaps by omitting borders via CSS.")
272 _WRAP_METHOD(void render_extension(const ::Cairo::RefPtr< ::Cairo::Context>& cr, double x, double y, double width, double height, PositionType gap_side), gtk_render_extension)
273 _WRAP_METHOD(void render_handle(const ::Cairo::RefPtr< ::Cairo::Context>& cr, double x, double y, double width, double height), gtk_render_handle)
274 _WRAP_METHOD(void render_activity(const ::Cairo::RefPtr< ::Cairo::Context>& cr, double x, double y, double width, double height), gtk_render_activity)
275 _WRAP_METHOD(Glib::RefPtr<Gdk::Pixbuf> render_icon_pixbuf(const IconSource& source, IconSize size), gtk_render_icon_pixbuf, deprecated "Use IconTheme::load_icon() instead.")
276 _WRAP_METHOD(void render_icon(const ::Cairo::RefPtr< ::Cairo::Context>& cr, const Glib::RefPtr<Gdk::Pixbuf>& pixbuf, double x, double y), gtk_render_icon)
277 _WRAP_METHOD(void render_insertion_cursor(const ::Cairo::RefPtr< ::Cairo::Context>& cr, double x, double y, const Glib::RefPtr<Pango::Layout>& layout, int index, Pango::Direction direction), gtk_render_insertion_cursor)
278
279
280 _WRAP_SIGNAL(void changed(), "changed")
281
282 _WRAP_PROPERTY("screen", Glib::RefPtr<Gdk::Screen>)
283 _WRAP_PROPERTY("direction", TextDirection,
284 deprecated "Use set_state()/get_state() and Gtk::STATE_FLAG_DIR_LTR/Gtk::STATE_FLAG_DIR_RTL instead.")
285 _WRAP_PROPERTY("paint-clock", Glib::RefPtr<Gdk::FrameClock>, newin "3,24")
286 _WRAP_PROPERTY("parent", Glib::RefPtr<StyleContext>)
287 };
288
289 #ifndef DOXYGEN_SHOULD_SKIP_THIS
290
291 template <class PropertyType>
292 void StyleContext::get_style_property(const Glib::ustring& property_name, PropertyType& value) const
293 {
294 Glib::Value<PropertyType> property_value;
295 property_value.init(Glib::Value<PropertyType>::value_type());
296
297 this->get_style_property_value(property_name, property_value);
298
299 value = property_value.get();
300 }
301
302 #endif
303 } // namespace Gtk