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