Skip to main content

gtk/auto/
style_context.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{
6    Border, CssSection, JunctionSides, StateFlags, StyleContextPrintFlags, StyleProvider,
7    TextDirection, WidgetPath,
8};
9use glib::{
10    prelude::*,
11    signal::{connect_raw, SignalHandlerId},
12    translate::*,
13};
14use std::{boxed::Box as Box_, fmt, mem::transmute};
15
16glib::wrapper! {
17    /// [`StyleContext`][crate::StyleContext] is an object that stores styling information affecting
18    /// a widget defined by [`WidgetPath`][crate::WidgetPath].
19    ///
20    /// In order to construct the final style information, [`StyleContext`][crate::StyleContext]
21    /// queries information from all attached `GtkStyleProviders`. Style providers
22    /// can be either attached explicitly to the context through
23    /// [`StyleContextExt::add_provider()`][crate::prelude::StyleContextExt::add_provider()], or to the screen through
24    /// [`add_provider_for_screen()`][Self::add_provider_for_screen()]. The resulting style is a
25    /// combination of all providers’ information in priority order.
26    ///
27    /// For GTK+ widgets, any [`StyleContext`][crate::StyleContext] returned by
28    /// [`WidgetExt::style_context()`][crate::prelude::WidgetExt::style_context()] will already have a [`WidgetPath`][crate::WidgetPath], a
29    /// [`gdk::Screen`][crate::gdk::Screen] and RTL/LTR information set. The style context will also be
30    /// updated automatically if any of these settings change on the widget.
31    ///
32    /// If you are using the theming layer standalone, you will need to set a
33    /// widget path and a screen yourself to the created style context through
34    /// [`StyleContextExt::set_path()`][crate::prelude::StyleContextExt::set_path()] and possibly [`StyleContextExt::set_screen()`][crate::prelude::StyleContextExt::set_screen()]. See
35    /// the “Foreign drawing“ example in gtk3-demo.
36    ///
37    /// # Style Classes # {`gtkstylecontext`-classes}
38    ///
39    /// Widgets can add style classes to their context, which can be used to associate
40    /// different styles by class. The documentation for individual widgets lists
41    /// which style classes it uses itself, and which style classes may be added by
42    /// applications to affect their appearance.
43    ///
44    /// GTK+ defines macros for a number of style classes.
45    ///
46    /// # Style Regions
47    ///
48    /// Widgets can also add regions with flags to their context. This feature is
49    /// deprecated and will be removed in a future GTK+ update. Please use style
50    /// classes instead.
51    ///
52    /// GTK+ defines macros for a number of style regions.
53    ///
54    /// # Custom styling in UI libraries and applications
55    ///
56    /// If you are developing a library with custom `GtkWidgets` that
57    /// render differently than standard components, you may need to add a
58    /// [`StyleProvider`][crate::StyleProvider] yourself with the `GTK_STYLE_PROVIDER_PRIORITY_FALLBACK`
59    /// priority, either a [`CssProvider`][crate::CssProvider] or a custom object implementing the
60    /// [`StyleProvider`][crate::StyleProvider] interface. This way themes may still attempt
61    /// to style your UI elements in a different way if needed so.
62    ///
63    /// If you are using custom styling on an applications, you probably want then
64    /// to make your style information prevail to the theme’s, so you must use
65    /// a [`StyleProvider`][crate::StyleProvider] with the `GTK_STYLE_PROVIDER_PRIORITY_APPLICATION`
66    /// priority, keep in mind that the user settings in
67    /// `XDG_CONFIG_HOME/gtk-3.0/gtk.css` will
68    /// still take precedence over your changes, as it uses the
69    /// `GTK_STYLE_PROVIDER_PRIORITY_USER` priority.
70    ///
71    /// ## Properties
72    ///
73    ///
74    /// #### `direction`
75    ///  Readable | Writeable
76    ///
77    ///
78    /// #### `paint-clock`
79    ///  Readable | Writeable
80    ///
81    ///
82    /// #### `parent`
83    ///  Sets or gets the style context’s parent. See [`StyleContextExt::set_parent()`][crate::prelude::StyleContextExt::set_parent()]
84    /// for details.
85    ///
86    /// Readable | Writeable
87    ///
88    ///
89    /// #### `screen`
90    ///  Readable | Writeable
91    ///
92    /// ## Signals
93    ///
94    ///
95    /// #### `changed`
96    ///  The ::changed signal is emitted when there is a change in the
97    /// [`StyleContext`][crate::StyleContext].
98    ///
99    /// For a [`StyleContext`][crate::StyleContext] returned by [`WidgetExt::style_context()`][crate::prelude::WidgetExt::style_context()], the
100    /// [`style-updated`][struct@crate::Widget#style-updated] signal/vfunc might be more convenient to use.
101    ///
102    /// This signal is useful when using the theming layer standalone.
103    ///
104    ///
105    ///
106    /// # Implements
107    ///
108    /// [`StyleContextExt`][trait@crate::prelude::StyleContextExt], [`trait@glib::ObjectExt`], [`StyleContextExtManual`][trait@crate::prelude::StyleContextExtManual]
109    #[doc(alias = "GtkStyleContext")]
110    pub struct StyleContext(Object<ffi::GtkStyleContext, ffi::GtkStyleContextClass>);
111
112    match fn {
113        type_ => || ffi::gtk_style_context_get_type(),
114    }
115}
116
117impl StyleContext {
118    pub const NONE: Option<&'static StyleContext> = None;
119
120    /// Creates a standalone [`StyleContext`][crate::StyleContext], this style context
121    /// won’t be attached to any widget, so you may want
122    /// to call [`StyleContextExt::set_path()`][crate::prelude::StyleContextExt::set_path()] yourself.
123    ///
124    /// This function is only useful when using the theming layer
125    /// separated from GTK+, if you are using [`StyleContext`][crate::StyleContext] to
126    /// theme `GtkWidgets`, use [`WidgetExt::style_context()`][crate::prelude::WidgetExt::style_context()]
127    /// in order to get a style context ready to theme the widget.
128    ///
129    /// # Returns
130    ///
131    /// A newly created [`StyleContext`][crate::StyleContext].
132    #[doc(alias = "gtk_style_context_new")]
133    pub fn new() -> StyleContext {
134        assert_initialized_main_thread!();
135        unsafe { from_glib_full(ffi::gtk_style_context_new()) }
136    }
137
138    // rustdoc-stripper-ignore-next
139    /// Creates a new builder-pattern struct instance to construct [`StyleContext`] objects.
140    ///
141    /// This method returns an instance of [`StyleContextBuilder`](crate::builders::StyleContextBuilder) which can be used to create [`StyleContext`] objects.
142    pub fn builder() -> StyleContextBuilder {
143        StyleContextBuilder::new()
144    }
145
146    /// Adds a global style provider to `screen`, which will be used
147    /// in style construction for all `GtkStyleContexts` under `screen`.
148    ///
149    /// GTK+ uses this to make styling information from [`Settings`][crate::Settings]
150    /// available.
151    ///
152    /// Note: If both priorities are the same, A [`StyleProvider`][crate::StyleProvider]
153    /// added through [`StyleContextExt::add_provider()`][crate::prelude::StyleContextExt::add_provider()] takes precedence
154    /// over another added through this function.
155    /// ## `screen`
156    /// a [`gdk::Screen`][crate::gdk::Screen]
157    /// ## `provider`
158    /// a [`StyleProvider`][crate::StyleProvider]
159    /// ## `priority`
160    /// the priority of the style provider. The lower
161    ///  it is, the earlier it will be used in the style
162    ///  construction. Typically this will be in the range
163    ///  between `GTK_STYLE_PROVIDER_PRIORITY_FALLBACK` and
164    ///  `GTK_STYLE_PROVIDER_PRIORITY_USER`
165    #[doc(alias = "gtk_style_context_add_provider_for_screen")]
166    pub fn add_provider_for_screen(
167        screen: &gdk::Screen,
168        provider: &impl IsA<StyleProvider>,
169        priority: u32,
170    ) {
171        skip_assert_initialized!();
172        unsafe {
173            ffi::gtk_style_context_add_provider_for_screen(
174                screen.to_glib_none().0,
175                provider.as_ref().to_glib_none().0,
176                priority,
177            );
178        }
179    }
180
181    /// Removes `provider` from the global style providers list in `screen`.
182    /// ## `screen`
183    /// a [`gdk::Screen`][crate::gdk::Screen]
184    /// ## `provider`
185    /// a [`StyleProvider`][crate::StyleProvider]
186    #[doc(alias = "gtk_style_context_remove_provider_for_screen")]
187    pub fn remove_provider_for_screen(screen: &gdk::Screen, provider: &impl IsA<StyleProvider>) {
188        skip_assert_initialized!();
189        unsafe {
190            ffi::gtk_style_context_remove_provider_for_screen(
191                screen.to_glib_none().0,
192                provider.as_ref().to_glib_none().0,
193            );
194        }
195    }
196
197    /// This function recomputes the styles for all widgets under a particular
198    /// [`gdk::Screen`][crate::gdk::Screen]. This is useful when some global parameter has changed that
199    /// affects the appearance of all widgets, because when a widget gets a new
200    /// style, it will both redraw and recompute any cached information about
201    /// its appearance. As an example, it is used when the color scheme changes
202    /// in the related [`Settings`][crate::Settings] object.
203    /// ## `screen`
204    /// a [`gdk::Screen`][crate::gdk::Screen]
205    #[doc(alias = "gtk_style_context_reset_widgets")]
206    pub fn reset_widgets(screen: &gdk::Screen) {
207        assert_initialized_main_thread!();
208        unsafe {
209            ffi::gtk_style_context_reset_widgets(screen.to_glib_none().0);
210        }
211    }
212}
213
214impl Default for StyleContext {
215    fn default() -> Self {
216        Self::new()
217    }
218}
219
220// rustdoc-stripper-ignore-next
221/// A [builder-pattern] type to construct [`StyleContext`] objects.
222///
223/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
224#[must_use = "The builder must be built to be used"]
225pub struct StyleContextBuilder {
226    builder: glib::object::ObjectBuilder<'static, StyleContext>,
227}
228
229impl StyleContextBuilder {
230    fn new() -> Self {
231        Self {
232            builder: glib::object::Object::builder(),
233        }
234    }
235
236    pub fn direction(self, direction: TextDirection) -> Self {
237        Self {
238            builder: self.builder.property("direction", direction),
239        }
240    }
241
242    pub fn paint_clock(self, paint_clock: &gdk::FrameClock) -> Self {
243        Self {
244            builder: self.builder.property("paint-clock", paint_clock.clone()),
245        }
246    }
247
248    /// Sets or gets the style context’s parent. See [`StyleContextExt::set_parent()`][crate::prelude::StyleContextExt::set_parent()]
249    /// for details.
250    pub fn parent(self, parent: &impl IsA<StyleContext>) -> Self {
251        Self {
252            builder: self.builder.property("parent", parent.clone().upcast()),
253        }
254    }
255
256    pub fn screen(self, screen: &gdk::Screen) -> Self {
257        Self {
258            builder: self.builder.property("screen", screen.clone()),
259        }
260    }
261
262    // rustdoc-stripper-ignore-next
263    /// Build the [`StyleContext`].
264    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
265    pub fn build(self) -> StyleContext {
266        self.builder.build()
267    }
268}
269
270mod sealed {
271    pub trait Sealed {}
272    impl<T: super::IsA<super::StyleContext>> Sealed for T {}
273}
274
275/// Trait containing all [`struct@StyleContext`] methods.
276///
277/// # Implementors
278///
279/// [`StyleContext`][struct@crate::StyleContext]
280pub trait StyleContextExt: IsA<StyleContext> + sealed::Sealed + 'static {
281    /// Adds a style class to `self`, so posterior calls to
282    /// `gtk_style_context_get()` or any of the gtk_render_*()
283    /// functions will make use of this new class for styling.
284    ///
285    /// In the CSS file format, a [`Entry`][crate::Entry] defining a “search”
286    /// class, would be matched by:
287    ///
288    ///
289    ///
290    /// **⚠️ The following code is in CSS ⚠️**
291    ///
292    /// ```CSS
293    /// entry.search { ... }
294    /// ```
295    ///
296    /// While any widget defining a “search” class would be
297    /// matched by:
298    ///
299    ///
300    /// **⚠️ The following code is in CSS ⚠️**
301    ///
302    /// ```CSS
303    /// .search { ... }
304    /// ```
305    /// ## `class_name`
306    /// class name to use in styling
307    #[doc(alias = "gtk_style_context_add_class")]
308    fn add_class(&self, class_name: &str) {
309        unsafe {
310            ffi::gtk_style_context_add_class(
311                self.as_ref().to_glib_none().0,
312                class_name.to_glib_none().0,
313            );
314        }
315    }
316
317    /// Adds a style provider to `self`, to be used in style construction.
318    /// Note that a style provider added by this function only affects
319    /// the style of the widget to which `self` belongs. If you want
320    /// to affect the style of all widgets, use
321    /// [`StyleContext::add_provider_for_screen()`][crate::StyleContext::add_provider_for_screen()].
322    ///
323    /// Note: If both priorities are the same, a [`StyleProvider`][crate::StyleProvider]
324    /// added through this function takes precedence over another added
325    /// through [`StyleContext::add_provider_for_screen()`][crate::StyleContext::add_provider_for_screen()].
326    /// ## `provider`
327    /// a [`StyleProvider`][crate::StyleProvider]
328    /// ## `priority`
329    /// the priority of the style provider. The lower
330    ///  it is, the earlier it will be used in the style
331    ///  construction. Typically this will be in the range
332    ///  between `GTK_STYLE_PROVIDER_PRIORITY_FALLBACK` and
333    ///  `GTK_STYLE_PROVIDER_PRIORITY_USER`
334    #[doc(alias = "gtk_style_context_add_provider")]
335    fn add_provider(&self, provider: &impl IsA<StyleProvider>, priority: u32) {
336        unsafe {
337            ffi::gtk_style_context_add_provider(
338                self.as_ref().to_glib_none().0,
339                provider.as_ref().to_glib_none().0,
340                priority,
341            );
342        }
343    }
344
345    /// Gets the border for a given state as a [`Border`][crate::Border].
346    ///
347    /// See [`style_property_for_state()`][Self::style_property_for_state()] and
348    /// [`STYLE_PROPERTY_BORDER_WIDTH`][crate::STYLE_PROPERTY_BORDER_WIDTH] for details.
349    /// ## `state`
350    /// state to retrieve the border for
351    ///
352    /// # Returns
353    ///
354    ///
355    /// ## `border`
356    /// return value for the border settings
357    #[doc(alias = "gtk_style_context_get_border")]
358    #[doc(alias = "get_border")]
359    fn border(&self, state: StateFlags) -> Border {
360        unsafe {
361            let mut border = Border::uninitialized();
362            ffi::gtk_style_context_get_border(
363                self.as_ref().to_glib_none().0,
364                state.into_glib(),
365                border.to_glib_none_mut().0,
366            );
367            border
368        }
369    }
370
371    /// Gets the foreground color for a given state.
372    ///
373    /// See [`style_property_for_state()`][Self::style_property_for_state()] and
374    /// [`STYLE_PROPERTY_COLOR`][crate::STYLE_PROPERTY_COLOR] for details.
375    /// ## `state`
376    /// state to retrieve the color for
377    ///
378    /// # Returns
379    ///
380    ///
381    /// ## `color`
382    /// return value for the foreground color
383    #[doc(alias = "gtk_style_context_get_color")]
384    #[doc(alias = "get_color")]
385    fn color(&self, state: StateFlags) -> gdk::RGBA {
386        unsafe {
387            let mut color = gdk::RGBA::uninitialized();
388            ffi::gtk_style_context_get_color(
389                self.as_ref().to_glib_none().0,
390                state.into_glib(),
391                color.to_glib_none_mut().0,
392            );
393            color
394        }
395    }
396
397    /// Returns the [`gdk::FrameClock`][crate::gdk::FrameClock] to which `self` is attached.
398    ///
399    /// # Returns
400    ///
401    /// a [`gdk::FrameClock`][crate::gdk::FrameClock], or [`None`]
402    ///  if `self` does not have an attached frame clock.
403    #[doc(alias = "gtk_style_context_get_frame_clock")]
404    #[doc(alias = "get_frame_clock")]
405    fn frame_clock(&self) -> Option<gdk::FrameClock> {
406        unsafe {
407            from_glib_none(ffi::gtk_style_context_get_frame_clock(
408                self.as_ref().to_glib_none().0,
409            ))
410        }
411    }
412
413    /// Returns the sides where rendered elements connect visually with others.
414    ///
415    /// # Returns
416    ///
417    /// the junction sides
418    #[doc(alias = "gtk_style_context_get_junction_sides")]
419    #[doc(alias = "get_junction_sides")]
420    fn junction_sides(&self) -> JunctionSides {
421        unsafe {
422            from_glib(ffi::gtk_style_context_get_junction_sides(
423                self.as_ref().to_glib_none().0,
424            ))
425        }
426    }
427
428    /// Gets the margin for a given state as a [`Border`][crate::Border].
429    /// See `gtk_style_property_get()` and [`STYLE_PROPERTY_MARGIN`][crate::STYLE_PROPERTY_MARGIN]
430    /// for details.
431    /// ## `state`
432    /// state to retrieve the border for
433    ///
434    /// # Returns
435    ///
436    ///
437    /// ## `margin`
438    /// return value for the margin settings
439    #[doc(alias = "gtk_style_context_get_margin")]
440    #[doc(alias = "get_margin")]
441    fn margin(&self, state: StateFlags) -> Border {
442        unsafe {
443            let mut margin = Border::uninitialized();
444            ffi::gtk_style_context_get_margin(
445                self.as_ref().to_glib_none().0,
446                state.into_glib(),
447                margin.to_glib_none_mut().0,
448            );
449            margin
450        }
451    }
452
453    /// Gets the padding for a given state as a [`Border`][crate::Border].
454    /// See `gtk_style_context_get()` and [`STYLE_PROPERTY_PADDING`][crate::STYLE_PROPERTY_PADDING]
455    /// for details.
456    /// ## `state`
457    /// state to retrieve the padding for
458    ///
459    /// # Returns
460    ///
461    ///
462    /// ## `padding`
463    /// return value for the padding settings
464    #[doc(alias = "gtk_style_context_get_padding")]
465    #[doc(alias = "get_padding")]
466    fn padding(&self, state: StateFlags) -> Border {
467        unsafe {
468            let mut padding = Border::uninitialized();
469            ffi::gtk_style_context_get_padding(
470                self.as_ref().to_glib_none().0,
471                state.into_glib(),
472                padding.to_glib_none_mut().0,
473            );
474            padding
475        }
476    }
477
478    /// Gets the parent context set via [`set_parent()`][Self::set_parent()].
479    /// See that function for details.
480    ///
481    /// # Returns
482    ///
483    /// the parent context or [`None`]
484    #[doc(alias = "gtk_style_context_get_parent")]
485    #[doc(alias = "get_parent")]
486    #[must_use]
487    fn parent(&self) -> Option<StyleContext> {
488        unsafe {
489            from_glib_none(ffi::gtk_style_context_get_parent(
490                self.as_ref().to_glib_none().0,
491            ))
492        }
493    }
494
495    /// Returns the widget path used for style matching.
496    ///
497    /// # Returns
498    ///
499    /// A [`WidgetPath`][crate::WidgetPath]
500    #[doc(alias = "gtk_style_context_get_path")]
501    #[doc(alias = "get_path")]
502    fn path(&self) -> Option<WidgetPath> {
503        unsafe {
504            from_glib_none(ffi::gtk_style_context_get_path(
505                self.as_ref().to_glib_none().0,
506            ))
507        }
508    }
509
510    /// Gets a style property from `self` for the given state.
511    ///
512    /// Note that not all CSS properties that are supported by GTK+ can be
513    /// retrieved in this way, since they may not be representable as [`glib::Value`][crate::glib::Value].
514    /// GTK+ defines macros for a number of properties that can be used
515    /// with this function.
516    ///
517    /// Note that passing a state other than the current state of `self`
518    /// is not recommended unless the style context has been saved with
519    /// [`save()`][Self::save()].
520    ///
521    /// When `value` is no longer needed, [`glib::Value::unset()`][crate::glib::Value::unset()] must be called
522    /// to free any allocated memory.
523    /// ## `property`
524    /// style property name
525    /// ## `state`
526    /// state to retrieve the property value for
527    ///
528    /// # Returns
529    ///
530    ///
531    /// ## `value`
532    /// return location for the style property value
533    #[doc(alias = "gtk_style_context_get_property")]
534    #[doc(alias = "get_property")]
535    fn style_property_for_state(&self, property: &str, state: StateFlags) -> glib::Value {
536        unsafe {
537            let mut value = glib::Value::uninitialized();
538            ffi::gtk_style_context_get_property(
539                self.as_ref().to_glib_none().0,
540                property.to_glib_none().0,
541                state.into_glib(),
542                value.to_glib_none_mut().0,
543            );
544            value
545        }
546    }
547
548    /// Returns the scale used for assets.
549    ///
550    /// # Returns
551    ///
552    /// the scale
553    #[doc(alias = "gtk_style_context_get_scale")]
554    #[doc(alias = "get_scale")]
555    fn scale(&self) -> i32 {
556        unsafe { ffi::gtk_style_context_get_scale(self.as_ref().to_glib_none().0) }
557    }
558
559    /// Returns the [`gdk::Screen`][crate::gdk::Screen] to which `self` is attached.
560    ///
561    /// # Returns
562    ///
563    /// a [`gdk::Screen`][crate::gdk::Screen].
564    #[doc(alias = "gtk_style_context_get_screen")]
565    #[doc(alias = "get_screen")]
566    fn screen(&self) -> Option<gdk::Screen> {
567        unsafe {
568            from_glib_none(ffi::gtk_style_context_get_screen(
569                self.as_ref().to_glib_none().0,
570            ))
571        }
572    }
573
574    /// Queries the location in the CSS where `property` was defined for the
575    /// current `self`. Note that the state to be queried is taken from
576    /// [`state()`][Self::state()].
577    ///
578    /// If the location is not available, [`None`] will be returned. The
579    /// location might not be available for various reasons, such as the
580    /// property being overridden, `property` not naming a supported CSS
581    /// property or tracking of definitions being disabled for performance
582    /// reasons.
583    ///
584    /// Shorthand CSS properties cannot be queried for a location and will
585    /// always return [`None`].
586    /// ## `property`
587    /// style property name
588    ///
589    /// # Returns
590    ///
591    /// [`None`] or the section where a value
592    /// for `property` was defined
593    #[doc(alias = "gtk_style_context_get_section")]
594    #[doc(alias = "get_section")]
595    fn section(&self, property: &str) -> Option<CssSection> {
596        unsafe {
597            from_glib_none(ffi::gtk_style_context_get_section(
598                self.as_ref().to_glib_none().0,
599                property.to_glib_none().0,
600            ))
601        }
602    }
603
604    /// Returns the state used for style matching.
605    ///
606    /// This method should only be used to retrieve the [`StateFlags`][crate::StateFlags]
607    /// to pass to [`StyleContext`][crate::StyleContext] methods, like [`padding()`][Self::padding()].
608    /// If you need to retrieve the current state of a [`Widget`][crate::Widget], use
609    /// [`WidgetExt::state_flags()`][crate::prelude::WidgetExt::state_flags()].
610    ///
611    /// # Returns
612    ///
613    /// the state flags
614    #[doc(alias = "gtk_style_context_get_state")]
615    #[doc(alias = "get_state")]
616    fn state(&self) -> StateFlags {
617        unsafe {
618            from_glib(ffi::gtk_style_context_get_state(
619                self.as_ref().to_glib_none().0,
620            ))
621        }
622    }
623
624    //#[doc(alias = "gtk_style_context_get_style")]
625    //#[doc(alias = "get_style")]
626    //fn style(&self, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) {
627    //    unsafe { TODO: call ffi:gtk_style_context_get_style() }
628    //}
629
630    /// Gets the value for a widget style property.
631    ///
632    /// When `value` is no longer needed, [`glib::Value::unset()`][crate::glib::Value::unset()] must be called
633    /// to free any allocated memory.
634    /// ## `property_name`
635    /// the name of the widget style property
636    ///
637    /// # Returns
638    ///
639    ///
640    /// ## `value`
641    /// Return location for the property value
642    #[doc(alias = "gtk_style_context_get_style_property")]
643    #[doc(alias = "get_style_property")]
644    fn style_property(&self, property_name: &str) -> glib::Value {
645        unsafe {
646            let mut value = glib::Value::uninitialized();
647            ffi::gtk_style_context_get_style_property(
648                self.as_ref().to_glib_none().0,
649                property_name.to_glib_none().0,
650                value.to_glib_none_mut().0,
651            );
652            value
653        }
654    }
655
656    //#[doc(alias = "gtk_style_context_get_style_valist")]
657    //#[doc(alias = "get_style_valist")]
658    //fn style_valist(&self, args: /*Unknown conversion*//*Unimplemented*/Unsupported) {
659    //    unsafe { TODO: call ffi:gtk_style_context_get_style_valist() }
660    //}
661
662    //#[doc(alias = "gtk_style_context_get_valist")]
663    //#[doc(alias = "get_valist")]
664    //fn valist(&self, state: StateFlags, args: /*Unknown conversion*//*Unimplemented*/Unsupported) {
665    //    unsafe { TODO: call ffi:gtk_style_context_get_valist() }
666    //}
667
668    /// Returns [`true`] if `self` currently has defined the
669    /// given class name.
670    /// ## `class_name`
671    /// a class name
672    ///
673    /// # Returns
674    ///
675    /// [`true`] if `self` has `class_name` defined
676    #[doc(alias = "gtk_style_context_has_class")]
677    fn has_class(&self, class_name: &str) -> bool {
678        unsafe {
679            from_glib(ffi::gtk_style_context_has_class(
680                self.as_ref().to_glib_none().0,
681                class_name.to_glib_none().0,
682            ))
683        }
684    }
685
686    /// Returns the list of classes currently defined in `self`.
687    ///
688    /// # Returns
689    ///
690    /// a `GList` of
691    ///  strings with the currently defined classes. The contents
692    ///  of the list are owned by GTK+, but you must free the list
693    ///  itself with `g_list_free()` when you are done with it.
694    #[doc(alias = "gtk_style_context_list_classes")]
695    fn list_classes(&self) -> Vec<glib::GString> {
696        unsafe {
697            FromGlibPtrContainer::from_glib_container(ffi::gtk_style_context_list_classes(
698                self.as_ref().to_glib_none().0,
699            ))
700        }
701    }
702
703    /// Looks up and resolves a color name in the `self` color map.
704    /// ## `color_name`
705    /// color name to lookup
706    ///
707    /// # Returns
708    ///
709    /// [`true`] if `color_name` was found and resolved, [`false`] otherwise
710    ///
711    /// ## `color`
712    /// Return location for the looked up color
713    #[doc(alias = "gtk_style_context_lookup_color")]
714    fn lookup_color(&self, color_name: &str) -> Option<gdk::RGBA> {
715        unsafe {
716            let mut color = gdk::RGBA::uninitialized();
717            let ret = from_glib(ffi::gtk_style_context_lookup_color(
718                self.as_ref().to_glib_none().0,
719                color_name.to_glib_none().0,
720                color.to_glib_none_mut().0,
721            ));
722            if ret {
723                Some(color)
724            } else {
725                None
726            }
727        }
728    }
729
730    /// Removes `class_name` from `self`.
731    /// ## `class_name`
732    /// class name to remove
733    #[doc(alias = "gtk_style_context_remove_class")]
734    fn remove_class(&self, class_name: &str) {
735        unsafe {
736            ffi::gtk_style_context_remove_class(
737                self.as_ref().to_glib_none().0,
738                class_name.to_glib_none().0,
739            );
740        }
741    }
742
743    /// Removes `provider` from the style providers list in `self`.
744    /// ## `provider`
745    /// a [`StyleProvider`][crate::StyleProvider]
746    #[doc(alias = "gtk_style_context_remove_provider")]
747    fn remove_provider(&self, provider: &impl IsA<StyleProvider>) {
748        unsafe {
749            ffi::gtk_style_context_remove_provider(
750                self.as_ref().to_glib_none().0,
751                provider.as_ref().to_glib_none().0,
752            );
753        }
754    }
755
756    /// Restores `self` state to a previous stage.
757    /// See [`save()`][Self::save()].
758    #[doc(alias = "gtk_style_context_restore")]
759    fn restore(&self) {
760        unsafe {
761            ffi::gtk_style_context_restore(self.as_ref().to_glib_none().0);
762        }
763    }
764
765    /// Saves the `self` state, so temporary modifications done through
766    /// [`add_class()`][Self::add_class()], [`remove_class()`][Self::remove_class()],
767    /// [`set_state()`][Self::set_state()], etc. can quickly be reverted
768    /// in one go through [`restore()`][Self::restore()].
769    ///
770    /// The matching call to [`restore()`][Self::restore()] must be done
771    /// before GTK returns to the main loop.
772    #[doc(alias = "gtk_style_context_save")]
773    fn save(&self) {
774        unsafe {
775            ffi::gtk_style_context_save(self.as_ref().to_glib_none().0);
776        }
777    }
778
779    /// Attaches `self` to the given frame clock.
780    ///
781    /// The frame clock is used for the timing of animations.
782    ///
783    /// If you are using a [`StyleContext`][crate::StyleContext] returned from
784    /// [`WidgetExt::style_context()`][crate::prelude::WidgetExt::style_context()], you do not need to
785    /// call this yourself.
786    /// ## `frame_clock`
787    /// a [`gdk::FrameClock`][crate::gdk::FrameClock]
788    #[doc(alias = "gtk_style_context_set_frame_clock")]
789    fn set_frame_clock(&self, frame_clock: &gdk::FrameClock) {
790        unsafe {
791            ffi::gtk_style_context_set_frame_clock(
792                self.as_ref().to_glib_none().0,
793                frame_clock.to_glib_none().0,
794            );
795        }
796    }
797
798    /// Sets the sides where rendered elements (mostly through
799    /// [`render_frame()`][crate::render_frame()]) will visually connect with other visual elements.
800    ///
801    /// This is merely a hint that may or may not be honored
802    /// by themes.
803    ///
804    /// Container widgets are expected to set junction hints as appropriate
805    /// for their children, so it should not normally be necessary to call
806    /// this function manually.
807    /// ## `sides`
808    /// sides where rendered elements are visually connected to
809    ///  other elements
810    #[doc(alias = "gtk_style_context_set_junction_sides")]
811    fn set_junction_sides(&self, sides: JunctionSides) {
812        unsafe {
813            ffi::gtk_style_context_set_junction_sides(
814                self.as_ref().to_glib_none().0,
815                sides.into_glib(),
816            );
817        }
818    }
819
820    /// Sets the parent style context for `self`. The parent style
821    /// context is used to implement
822    /// [inheritance](http://www.w3.org/TR/css3-cascade/`inheritance`)
823    /// of properties.
824    ///
825    /// If you are using a [`StyleContext`][crate::StyleContext] returned from
826    /// [`WidgetExt::style_context()`][crate::prelude::WidgetExt::style_context()], the parent will be set for you.
827    /// ## `parent`
828    /// the new parent or [`None`]
829    #[doc(alias = "gtk_style_context_set_parent")]
830    fn set_parent(&self, parent: Option<&impl IsA<StyleContext>>) {
831        unsafe {
832            ffi::gtk_style_context_set_parent(
833                self.as_ref().to_glib_none().0,
834                parent.map(|p| p.as_ref()).to_glib_none().0,
835            );
836        }
837    }
838
839    /// Sets the [`WidgetPath`][crate::WidgetPath] used for style matching. As a
840    /// consequence, the style will be regenerated to match
841    /// the new given path.
842    ///
843    /// If you are using a [`StyleContext`][crate::StyleContext] returned from
844    /// [`WidgetExt::style_context()`][crate::prelude::WidgetExt::style_context()], you do not need to call
845    /// this yourself.
846    /// ## `path`
847    /// a [`WidgetPath`][crate::WidgetPath]
848    #[doc(alias = "gtk_style_context_set_path")]
849    fn set_path(&self, path: &WidgetPath) {
850        unsafe {
851            ffi::gtk_style_context_set_path(self.as_ref().to_glib_none().0, path.to_glib_none().0);
852        }
853    }
854
855    /// Sets the scale to use when getting image assets for the style.
856    /// ## `scale`
857    /// scale
858    #[doc(alias = "gtk_style_context_set_scale")]
859    fn set_scale(&self, scale: i32) {
860        unsafe {
861            ffi::gtk_style_context_set_scale(self.as_ref().to_glib_none().0, scale);
862        }
863    }
864
865    /// Attaches `self` to the given screen.
866    ///
867    /// The screen is used to add style information from “global” style
868    /// providers, such as the screen’s [`Settings`][crate::Settings] instance.
869    ///
870    /// If you are using a [`StyleContext`][crate::StyleContext] returned from
871    /// [`WidgetExt::style_context()`][crate::prelude::WidgetExt::style_context()], you do not need to
872    /// call this yourself.
873    /// ## `screen`
874    /// a [`gdk::Screen`][crate::gdk::Screen]
875    #[doc(alias = "gtk_style_context_set_screen")]
876    fn set_screen(&self, screen: &gdk::Screen) {
877        unsafe {
878            ffi::gtk_style_context_set_screen(
879                self.as_ref().to_glib_none().0,
880                screen.to_glib_none().0,
881            );
882        }
883    }
884
885    /// Sets the state to be used for style matching.
886    /// ## `flags`
887    /// state to represent
888    #[doc(alias = "gtk_style_context_set_state")]
889    fn set_state(&self, flags: StateFlags) {
890        unsafe {
891            ffi::gtk_style_context_set_state(self.as_ref().to_glib_none().0, flags.into_glib());
892        }
893    }
894
895    /// Converts the style context into a string representation.
896    ///
897    /// The string representation always includes information about
898    /// the name, state, id, visibility and style classes of the CSS
899    /// node that is backing `self`. Depending on the flags, more
900    /// information may be included.
901    ///
902    /// This function is intended for testing and debugging of the
903    /// CSS implementation in GTK+. There are no guarantees about
904    /// the format of the returned string, it may change.
905    /// ## `flags`
906    /// Flags that determine what to print
907    ///
908    /// # Returns
909    ///
910    /// a newly allocated string representing `self`
911    #[doc(alias = "gtk_style_context_to_string")]
912    fn to_string(&self, flags: StyleContextPrintFlags) -> Option<glib::GString> {
913        unsafe {
914            from_glib_full(ffi::gtk_style_context_to_string(
915                self.as_ref().to_glib_none().0,
916                flags.into_glib(),
917            ))
918        }
919    }
920
921    fn direction(&self) -> TextDirection {
922        ObjectExt::property(self.as_ref(), "direction")
923    }
924
925    fn set_direction(&self, direction: TextDirection) {
926        ObjectExt::set_property(self.as_ref(), "direction", direction)
927    }
928
929    #[doc(alias = "paint-clock")]
930    fn paint_clock(&self) -> Option<gdk::FrameClock> {
931        ObjectExt::property(self.as_ref(), "paint-clock")
932    }
933
934    #[doc(alias = "paint-clock")]
935    fn set_paint_clock(&self, paint_clock: Option<&gdk::FrameClock>) {
936        ObjectExt::set_property(self.as_ref(), "paint-clock", paint_clock)
937    }
938
939    /// The ::changed signal is emitted when there is a change in the
940    /// [`StyleContext`][crate::StyleContext].
941    ///
942    /// For a [`StyleContext`][crate::StyleContext] returned by [`WidgetExt::style_context()`][crate::prelude::WidgetExt::style_context()], the
943    /// [`style-updated`][struct@crate::Widget#style-updated] signal/vfunc might be more convenient to use.
944    ///
945    /// This signal is useful when using the theming layer standalone.
946    #[doc(alias = "changed")]
947    fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
948        unsafe extern "C" fn changed_trampoline<P: IsA<StyleContext>, F: Fn(&P) + 'static>(
949            this: *mut ffi::GtkStyleContext,
950            f: glib::ffi::gpointer,
951        ) {
952            let f: &F = &*(f as *const F);
953            f(StyleContext::from_glib_borrow(this).unsafe_cast_ref())
954        }
955        unsafe {
956            let f: Box_<F> = Box_::new(f);
957            connect_raw(
958                self.as_ptr() as *mut _,
959                b"changed\0".as_ptr() as *const _,
960                Some(transmute::<_, unsafe extern "C" fn()>(
961                    changed_trampoline::<Self, F> as *const (),
962                )),
963                Box_::into_raw(f),
964            )
965        }
966    }
967
968    #[doc(alias = "direction")]
969    fn connect_direction_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
970        unsafe extern "C" fn notify_direction_trampoline<
971            P: IsA<StyleContext>,
972            F: Fn(&P) + 'static,
973        >(
974            this: *mut ffi::GtkStyleContext,
975            _param_spec: glib::ffi::gpointer,
976            f: glib::ffi::gpointer,
977        ) {
978            let f: &F = &*(f as *const F);
979            f(StyleContext::from_glib_borrow(this).unsafe_cast_ref())
980        }
981        unsafe {
982            let f: Box_<F> = Box_::new(f);
983            connect_raw(
984                self.as_ptr() as *mut _,
985                b"notify::direction\0".as_ptr() as *const _,
986                Some(transmute::<_, unsafe extern "C" fn()>(
987                    notify_direction_trampoline::<Self, F> as *const (),
988                )),
989                Box_::into_raw(f),
990            )
991        }
992    }
993
994    #[doc(alias = "paint-clock")]
995    fn connect_paint_clock_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
996        unsafe extern "C" fn notify_paint_clock_trampoline<
997            P: IsA<StyleContext>,
998            F: Fn(&P) + 'static,
999        >(
1000            this: *mut ffi::GtkStyleContext,
1001            _param_spec: glib::ffi::gpointer,
1002            f: glib::ffi::gpointer,
1003        ) {
1004            let f: &F = &*(f as *const F);
1005            f(StyleContext::from_glib_borrow(this).unsafe_cast_ref())
1006        }
1007        unsafe {
1008            let f: Box_<F> = Box_::new(f);
1009            connect_raw(
1010                self.as_ptr() as *mut _,
1011                b"notify::paint-clock\0".as_ptr() as *const _,
1012                Some(transmute::<_, unsafe extern "C" fn()>(
1013                    notify_paint_clock_trampoline::<Self, F> as *const (),
1014                )),
1015                Box_::into_raw(f),
1016            )
1017        }
1018    }
1019
1020    #[doc(alias = "parent")]
1021    fn connect_parent_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1022        unsafe extern "C" fn notify_parent_trampoline<P: IsA<StyleContext>, F: Fn(&P) + 'static>(
1023            this: *mut ffi::GtkStyleContext,
1024            _param_spec: glib::ffi::gpointer,
1025            f: glib::ffi::gpointer,
1026        ) {
1027            let f: &F = &*(f as *const F);
1028            f(StyleContext::from_glib_borrow(this).unsafe_cast_ref())
1029        }
1030        unsafe {
1031            let f: Box_<F> = Box_::new(f);
1032            connect_raw(
1033                self.as_ptr() as *mut _,
1034                b"notify::parent\0".as_ptr() as *const _,
1035                Some(transmute::<_, unsafe extern "C" fn()>(
1036                    notify_parent_trampoline::<Self, F> as *const (),
1037                )),
1038                Box_::into_raw(f),
1039            )
1040        }
1041    }
1042
1043    #[doc(alias = "screen")]
1044    fn connect_screen_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1045        unsafe extern "C" fn notify_screen_trampoline<P: IsA<StyleContext>, F: Fn(&P) + 'static>(
1046            this: *mut ffi::GtkStyleContext,
1047            _param_spec: glib::ffi::gpointer,
1048            f: glib::ffi::gpointer,
1049        ) {
1050            let f: &F = &*(f as *const F);
1051            f(StyleContext::from_glib_borrow(this).unsafe_cast_ref())
1052        }
1053        unsafe {
1054            let f: Box_<F> = Box_::new(f);
1055            connect_raw(
1056                self.as_ptr() as *mut _,
1057                b"notify::screen\0".as_ptr() as *const _,
1058                Some(transmute::<_, unsafe extern "C" fn()>(
1059                    notify_screen_trampoline::<Self, F> as *const (),
1060                )),
1061                Box_::into_raw(f),
1062            )
1063        }
1064    }
1065}
1066
1067impl<O: IsA<StyleContext>> StyleContextExt for O {}
1068
1069impl fmt::Display for StyleContext {
1070    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1071        f.write_str("StyleContext")
1072    }
1073}