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 /// Adds a style class to `self`, so posterior calls to
279 /// `gtk_style_context_get()` or any of the gtk_render_*()
280 /// functions will make use of this new class for styling.
281 ///
282 /// In the CSS file format, a [`Entry`][crate::Entry] defining a “search”
283 /// class, would be matched by:
284 ///
285 ///
286 ///
287 /// **⚠️ The following code is in CSS ⚠️**
288 ///
289 /// ```CSS
290 /// entry.search { ... }
291 /// ```
292 ///
293 /// While any widget defining a “search” class would be
294 /// matched by:
295 ///
296 ///
297 /// **⚠️ The following code is in CSS ⚠️**
298 ///
299 /// ```CSS
300 /// .search { ... }
301 /// ```
302 /// ## `class_name`
303 /// class name to use in styling
304 #[doc(alias = "gtk_style_context_add_class")]
305 fn add_class(&self, class_name: &str) {
306 unsafe {
307 ffi::gtk_style_context_add_class(
308 self.as_ref().to_glib_none().0,
309 class_name.to_glib_none().0,
310 );
311 }
312 }
313
314 /// Adds a style provider to `self`, to be used in style construction.
315 /// Note that a style provider added by this function only affects
316 /// the style of the widget to which `self` belongs. If you want
317 /// to affect the style of all widgets, use
318 /// [`StyleContext::add_provider_for_screen()`][crate::StyleContext::add_provider_for_screen()].
319 ///
320 /// Note: If both priorities are the same, a [`StyleProvider`][crate::StyleProvider]
321 /// added through this function takes precedence over another added
322 /// through [`StyleContext::add_provider_for_screen()`][crate::StyleContext::add_provider_for_screen()].
323 /// ## `provider`
324 /// a [`StyleProvider`][crate::StyleProvider]
325 /// ## `priority`
326 /// the priority of the style provider. The lower
327 /// it is, the earlier it will be used in the style
328 /// construction. Typically this will be in the range
329 /// between `GTK_STYLE_PROVIDER_PRIORITY_FALLBACK` and
330 /// `GTK_STYLE_PROVIDER_PRIORITY_USER`
331 #[doc(alias = "gtk_style_context_add_provider")]
332 fn add_provider(&self, provider: &impl IsA<StyleProvider>, priority: u32) {
333 unsafe {
334 ffi::gtk_style_context_add_provider(
335 self.as_ref().to_glib_none().0,
336 provider.as_ref().to_glib_none().0,
337 priority,
338 );
339 }
340 }
341
342 /// Gets the border for a given state as a [`Border`][crate::Border].
343 ///
344 /// See [`style_property_for_state()`][Self::style_property_for_state()] and
345 /// [`STYLE_PROPERTY_BORDER_WIDTH`][crate::STYLE_PROPERTY_BORDER_WIDTH] for details.
346 /// ## `state`
347 /// state to retrieve the border for
348 ///
349 /// # Returns
350 ///
351 ///
352 /// ## `border`
353 /// return value for the border settings
354 #[doc(alias = "gtk_style_context_get_border")]
355 #[doc(alias = "get_border")]
356 fn border(&self, state: StateFlags) -> Border {
357 unsafe {
358 let mut border = Border::uninitialized();
359 ffi::gtk_style_context_get_border(
360 self.as_ref().to_glib_none().0,
361 state.into_glib(),
362 border.to_glib_none_mut().0,
363 );
364 border
365 }
366 }
367
368 /// Gets the foreground color for a given state.
369 ///
370 /// See [`style_property_for_state()`][Self::style_property_for_state()] and
371 /// [`STYLE_PROPERTY_COLOR`][crate::STYLE_PROPERTY_COLOR] for details.
372 /// ## `state`
373 /// state to retrieve the color for
374 ///
375 /// # Returns
376 ///
377 ///
378 /// ## `color`
379 /// return value for the foreground color
380 #[doc(alias = "gtk_style_context_get_color")]
381 #[doc(alias = "get_color")]
382 fn color(&self, state: StateFlags) -> gdk::RGBA {
383 unsafe {
384 let mut color = gdk::RGBA::uninitialized();
385 ffi::gtk_style_context_get_color(
386 self.as_ref().to_glib_none().0,
387 state.into_glib(),
388 color.to_glib_none_mut().0,
389 );
390 color
391 }
392 }
393
394 /// Returns the [`gdk::FrameClock`][crate::gdk::FrameClock] to which `self` is attached.
395 ///
396 /// # Returns
397 ///
398 /// a [`gdk::FrameClock`][crate::gdk::FrameClock], or [`None`]
399 /// if `self` does not have an attached frame clock.
400 #[doc(alias = "gtk_style_context_get_frame_clock")]
401 #[doc(alias = "get_frame_clock")]
402 fn frame_clock(&self) -> Option<gdk::FrameClock> {
403 unsafe {
404 from_glib_none(ffi::gtk_style_context_get_frame_clock(
405 self.as_ref().to_glib_none().0,
406 ))
407 }
408 }
409
410 /// Returns the sides where rendered elements connect visually with others.
411 ///
412 /// # Returns
413 ///
414 /// the junction sides
415 #[doc(alias = "gtk_style_context_get_junction_sides")]
416 #[doc(alias = "get_junction_sides")]
417 fn junction_sides(&self) -> JunctionSides {
418 unsafe {
419 from_glib(ffi::gtk_style_context_get_junction_sides(
420 self.as_ref().to_glib_none().0,
421 ))
422 }
423 }
424
425 /// Gets the margin for a given state as a [`Border`][crate::Border].
426 /// See `gtk_style_property_get()` and [`STYLE_PROPERTY_MARGIN`][crate::STYLE_PROPERTY_MARGIN]
427 /// for details.
428 /// ## `state`
429 /// state to retrieve the border for
430 ///
431 /// # Returns
432 ///
433 ///
434 /// ## `margin`
435 /// return value for the margin settings
436 #[doc(alias = "gtk_style_context_get_margin")]
437 #[doc(alias = "get_margin")]
438 fn margin(&self, state: StateFlags) -> Border {
439 unsafe {
440 let mut margin = Border::uninitialized();
441 ffi::gtk_style_context_get_margin(
442 self.as_ref().to_glib_none().0,
443 state.into_glib(),
444 margin.to_glib_none_mut().0,
445 );
446 margin
447 }
448 }
449
450 /// Gets the padding for a given state as a [`Border`][crate::Border].
451 /// See `gtk_style_context_get()` and [`STYLE_PROPERTY_PADDING`][crate::STYLE_PROPERTY_PADDING]
452 /// for details.
453 /// ## `state`
454 /// state to retrieve the padding for
455 ///
456 /// # Returns
457 ///
458 ///
459 /// ## `padding`
460 /// return value for the padding settings
461 #[doc(alias = "gtk_style_context_get_padding")]
462 #[doc(alias = "get_padding")]
463 fn padding(&self, state: StateFlags) -> Border {
464 unsafe {
465 let mut padding = Border::uninitialized();
466 ffi::gtk_style_context_get_padding(
467 self.as_ref().to_glib_none().0,
468 state.into_glib(),
469 padding.to_glib_none_mut().0,
470 );
471 padding
472 }
473 }
474
475 /// Gets the parent context set via [`set_parent()`][Self::set_parent()].
476 /// See that function for details.
477 ///
478 /// # Returns
479 ///
480 /// the parent context or [`None`]
481 #[doc(alias = "gtk_style_context_get_parent")]
482 #[doc(alias = "get_parent")]
483 #[must_use]
484 fn parent(&self) -> Option<StyleContext> {
485 unsafe {
486 from_glib_none(ffi::gtk_style_context_get_parent(
487 self.as_ref().to_glib_none().0,
488 ))
489 }
490 }
491
492 /// Returns the widget path used for style matching.
493 ///
494 /// # Returns
495 ///
496 /// A [`WidgetPath`][crate::WidgetPath]
497 #[doc(alias = "gtk_style_context_get_path")]
498 #[doc(alias = "get_path")]
499 fn path(&self) -> Option<WidgetPath> {
500 unsafe {
501 from_glib_none(ffi::gtk_style_context_get_path(
502 self.as_ref().to_glib_none().0,
503 ))
504 }
505 }
506
507 /// Gets a style property from `self` for the given state.
508 ///
509 /// Note that not all CSS properties that are supported by GTK+ can be
510 /// retrieved in this way, since they may not be representable as [`glib::Value`][crate::glib::Value].
511 /// GTK+ defines macros for a number of properties that can be used
512 /// with this function.
513 ///
514 /// Note that passing a state other than the current state of `self`
515 /// is not recommended unless the style context has been saved with
516 /// [`save()`][Self::save()].
517 ///
518 /// When `value` is no longer needed, [`glib::Value::unset()`][crate::glib::Value::unset()] must be called
519 /// to free any allocated memory.
520 /// ## `property`
521 /// style property name
522 /// ## `state`
523 /// state to retrieve the property value for
524 ///
525 /// # Returns
526 ///
527 ///
528 /// ## `value`
529 /// return location for the style property value
530 #[doc(alias = "gtk_style_context_get_property")]
531 #[doc(alias = "get_property")]
532 fn style_property_for_state(&self, property: &str, state: StateFlags) -> glib::Value {
533 unsafe {
534 let mut value = glib::Value::uninitialized();
535 ffi::gtk_style_context_get_property(
536 self.as_ref().to_glib_none().0,
537 property.to_glib_none().0,
538 state.into_glib(),
539 value.to_glib_none_mut().0,
540 );
541 value
542 }
543 }
544
545 /// Returns the scale used for assets.
546 ///
547 /// # Returns
548 ///
549 /// the scale
550 #[doc(alias = "gtk_style_context_get_scale")]
551 #[doc(alias = "get_scale")]
552 fn scale(&self) -> i32 {
553 unsafe { ffi::gtk_style_context_get_scale(self.as_ref().to_glib_none().0) }
554 }
555
556 /// Returns the [`gdk::Screen`][crate::gdk::Screen] to which `self` is attached.
557 ///
558 /// # Returns
559 ///
560 /// a [`gdk::Screen`][crate::gdk::Screen].
561 #[doc(alias = "gtk_style_context_get_screen")]
562 #[doc(alias = "get_screen")]
563 fn screen(&self) -> Option<gdk::Screen> {
564 unsafe {
565 from_glib_none(ffi::gtk_style_context_get_screen(
566 self.as_ref().to_glib_none().0,
567 ))
568 }
569 }
570
571 /// Queries the location in the CSS where `property` was defined for the
572 /// current `self`. Note that the state to be queried is taken from
573 /// [`state()`][Self::state()].
574 ///
575 /// If the location is not available, [`None`] will be returned. The
576 /// location might not be available for various reasons, such as the
577 /// property being overridden, `property` not naming a supported CSS
578 /// property or tracking of definitions being disabled for performance
579 /// reasons.
580 ///
581 /// Shorthand CSS properties cannot be queried for a location and will
582 /// always return [`None`].
583 /// ## `property`
584 /// style property name
585 ///
586 /// # Returns
587 ///
588 /// [`None`] or the section where a value
589 /// for `property` was defined
590 #[doc(alias = "gtk_style_context_get_section")]
591 #[doc(alias = "get_section")]
592 fn section(&self, property: &str) -> Option<CssSection> {
593 unsafe {
594 from_glib_none(ffi::gtk_style_context_get_section(
595 self.as_ref().to_glib_none().0,
596 property.to_glib_none().0,
597 ))
598 }
599 }
600
601 /// Returns the state used for style matching.
602 ///
603 /// This method should only be used to retrieve the [`StateFlags`][crate::StateFlags]
604 /// to pass to [`StyleContext`][crate::StyleContext] methods, like [`padding()`][Self::padding()].
605 /// If you need to retrieve the current state of a [`Widget`][crate::Widget], use
606 /// [`WidgetExt::state_flags()`][crate::prelude::WidgetExt::state_flags()].
607 ///
608 /// # Returns
609 ///
610 /// the state flags
611 #[doc(alias = "gtk_style_context_get_state")]
612 #[doc(alias = "get_state")]
613 fn state(&self) -> StateFlags {
614 unsafe {
615 from_glib(ffi::gtk_style_context_get_state(
616 self.as_ref().to_glib_none().0,
617 ))
618 }
619 }
620
621 //#[doc(alias = "gtk_style_context_get_style")]
622 //#[doc(alias = "get_style")]
623 //fn style(&self, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) {
624 // unsafe { TODO: call ffi:gtk_style_context_get_style() }
625 //}
626
627 /// Gets the value for a widget style property.
628 ///
629 /// When `value` is no longer needed, [`glib::Value::unset()`][crate::glib::Value::unset()] must be called
630 /// to free any allocated memory.
631 /// ## `property_name`
632 /// the name of the widget style property
633 ///
634 /// # Returns
635 ///
636 ///
637 /// ## `value`
638 /// Return location for the property value
639 #[doc(alias = "gtk_style_context_get_style_property")]
640 #[doc(alias = "get_style_property")]
641 fn style_property(&self, property_name: &str) -> glib::Value {
642 unsafe {
643 let mut value = glib::Value::uninitialized();
644 ffi::gtk_style_context_get_style_property(
645 self.as_ref().to_glib_none().0,
646 property_name.to_glib_none().0,
647 value.to_glib_none_mut().0,
648 );
649 value
650 }
651 }
652
653 //#[doc(alias = "gtk_style_context_get_style_valist")]
654 //#[doc(alias = "get_style_valist")]
655 //fn style_valist(&self, args: /*Unknown conversion*//*Unimplemented*/Unsupported) {
656 // unsafe { TODO: call ffi:gtk_style_context_get_style_valist() }
657 //}
658
659 //#[doc(alias = "gtk_style_context_get_valist")]
660 //#[doc(alias = "get_valist")]
661 //fn valist(&self, state: StateFlags, args: /*Unknown conversion*//*Unimplemented*/Unsupported) {
662 // unsafe { TODO: call ffi:gtk_style_context_get_valist() }
663 //}
664
665 /// Returns [`true`] if `self` currently has defined the
666 /// given class name.
667 /// ## `class_name`
668 /// a class name
669 ///
670 /// # Returns
671 ///
672 /// [`true`] if `self` has `class_name` defined
673 #[doc(alias = "gtk_style_context_has_class")]
674 fn has_class(&self, class_name: &str) -> bool {
675 unsafe {
676 from_glib(ffi::gtk_style_context_has_class(
677 self.as_ref().to_glib_none().0,
678 class_name.to_glib_none().0,
679 ))
680 }
681 }
682
683 /// Returns the list of classes currently defined in `self`.
684 ///
685 /// # Returns
686 ///
687 /// a `GList` of
688 /// strings with the currently defined classes. The contents
689 /// of the list are owned by GTK+, but you must free the list
690 /// itself with `g_list_free()` when you are done with it.
691 #[doc(alias = "gtk_style_context_list_classes")]
692 fn list_classes(&self) -> Vec<glib::GString> {
693 unsafe {
694 FromGlibPtrContainer::from_glib_container(ffi::gtk_style_context_list_classes(
695 self.as_ref().to_glib_none().0,
696 ))
697 }
698 }
699
700 /// Looks up and resolves a color name in the `self` color map.
701 /// ## `color_name`
702 /// color name to lookup
703 ///
704 /// # Returns
705 ///
706 /// [`true`] if `color_name` was found and resolved, [`false`] otherwise
707 ///
708 /// ## `color`
709 /// Return location for the looked up color
710 #[doc(alias = "gtk_style_context_lookup_color")]
711 fn lookup_color(&self, color_name: &str) -> Option<gdk::RGBA> {
712 unsafe {
713 let mut color = gdk::RGBA::uninitialized();
714 let ret = from_glib(ffi::gtk_style_context_lookup_color(
715 self.as_ref().to_glib_none().0,
716 color_name.to_glib_none().0,
717 color.to_glib_none_mut().0,
718 ));
719 if ret { Some(color) } else { None }
720 }
721 }
722
723 /// Removes `class_name` from `self`.
724 /// ## `class_name`
725 /// class name to remove
726 #[doc(alias = "gtk_style_context_remove_class")]
727 fn remove_class(&self, class_name: &str) {
728 unsafe {
729 ffi::gtk_style_context_remove_class(
730 self.as_ref().to_glib_none().0,
731 class_name.to_glib_none().0,
732 );
733 }
734 }
735
736 /// Removes `provider` from the style providers list in `self`.
737 /// ## `provider`
738 /// a [`StyleProvider`][crate::StyleProvider]
739 #[doc(alias = "gtk_style_context_remove_provider")]
740 fn remove_provider(&self, provider: &impl IsA<StyleProvider>) {
741 unsafe {
742 ffi::gtk_style_context_remove_provider(
743 self.as_ref().to_glib_none().0,
744 provider.as_ref().to_glib_none().0,
745 );
746 }
747 }
748
749 /// Restores `self` state to a previous stage.
750 /// See [`save()`][Self::save()].
751 #[doc(alias = "gtk_style_context_restore")]
752 fn restore(&self) {
753 unsafe {
754 ffi::gtk_style_context_restore(self.as_ref().to_glib_none().0);
755 }
756 }
757
758 /// Saves the `self` state, so temporary modifications done through
759 /// [`add_class()`][Self::add_class()], [`remove_class()`][Self::remove_class()],
760 /// [`set_state()`][Self::set_state()], etc. can quickly be reverted
761 /// in one go through [`restore()`][Self::restore()].
762 ///
763 /// The matching call to [`restore()`][Self::restore()] must be done
764 /// before GTK returns to the main loop.
765 #[doc(alias = "gtk_style_context_save")]
766 fn save(&self) {
767 unsafe {
768 ffi::gtk_style_context_save(self.as_ref().to_glib_none().0);
769 }
770 }
771
772 /// Attaches `self` to the given frame clock.
773 ///
774 /// The frame clock is used for the timing of animations.
775 ///
776 /// If you are using a [`StyleContext`][crate::StyleContext] returned from
777 /// [`WidgetExt::style_context()`][crate::prelude::WidgetExt::style_context()], you do not need to
778 /// call this yourself.
779 /// ## `frame_clock`
780 /// a [`gdk::FrameClock`][crate::gdk::FrameClock]
781 #[doc(alias = "gtk_style_context_set_frame_clock")]
782 fn set_frame_clock(&self, frame_clock: &gdk::FrameClock) {
783 unsafe {
784 ffi::gtk_style_context_set_frame_clock(
785 self.as_ref().to_glib_none().0,
786 frame_clock.to_glib_none().0,
787 );
788 }
789 }
790
791 /// Sets the sides where rendered elements (mostly through
792 /// [`render_frame()`][crate::render_frame()]) will visually connect with other visual elements.
793 ///
794 /// This is merely a hint that may or may not be honored
795 /// by themes.
796 ///
797 /// Container widgets are expected to set junction hints as appropriate
798 /// for their children, so it should not normally be necessary to call
799 /// this function manually.
800 /// ## `sides`
801 /// sides where rendered elements are visually connected to
802 /// other elements
803 #[doc(alias = "gtk_style_context_set_junction_sides")]
804 fn set_junction_sides(&self, sides: JunctionSides) {
805 unsafe {
806 ffi::gtk_style_context_set_junction_sides(
807 self.as_ref().to_glib_none().0,
808 sides.into_glib(),
809 );
810 }
811 }
812
813 /// Sets the parent style context for `self`. The parent style
814 /// context is used to implement
815 /// [inheritance](http://www.w3.org/TR/css3-cascade/`inheritance`)
816 /// of properties.
817 ///
818 /// If you are using a [`StyleContext`][crate::StyleContext] returned from
819 /// [`WidgetExt::style_context()`][crate::prelude::WidgetExt::style_context()], the parent will be set for you.
820 /// ## `parent`
821 /// the new parent or [`None`]
822 #[doc(alias = "gtk_style_context_set_parent")]
823 #[doc(alias = "parent")]
824 fn set_parent(&self, parent: Option<&impl IsA<StyleContext>>) {
825 unsafe {
826 ffi::gtk_style_context_set_parent(
827 self.as_ref().to_glib_none().0,
828 parent.map(|p| p.as_ref()).to_glib_none().0,
829 );
830 }
831 }
832
833 /// Sets the [`WidgetPath`][crate::WidgetPath] used for style matching. As a
834 /// consequence, the style will be regenerated to match
835 /// the new given path.
836 ///
837 /// If you are using a [`StyleContext`][crate::StyleContext] returned from
838 /// [`WidgetExt::style_context()`][crate::prelude::WidgetExt::style_context()], you do not need to call
839 /// this yourself.
840 /// ## `path`
841 /// a [`WidgetPath`][crate::WidgetPath]
842 #[doc(alias = "gtk_style_context_set_path")]
843 fn set_path(&self, path: &WidgetPath) {
844 unsafe {
845 ffi::gtk_style_context_set_path(self.as_ref().to_glib_none().0, path.to_glib_none().0);
846 }
847 }
848
849 /// Sets the scale to use when getting image assets for the style.
850 /// ## `scale`
851 /// scale
852 #[doc(alias = "gtk_style_context_set_scale")]
853 fn set_scale(&self, scale: i32) {
854 unsafe {
855 ffi::gtk_style_context_set_scale(self.as_ref().to_glib_none().0, scale);
856 }
857 }
858
859 /// Attaches `self` to the given screen.
860 ///
861 /// The screen is used to add style information from “global” style
862 /// providers, such as the screen’s [`Settings`][crate::Settings] instance.
863 ///
864 /// If you are using a [`StyleContext`][crate::StyleContext] returned from
865 /// [`WidgetExt::style_context()`][crate::prelude::WidgetExt::style_context()], you do not need to
866 /// call this yourself.
867 /// ## `screen`
868 /// a [`gdk::Screen`][crate::gdk::Screen]
869 #[doc(alias = "gtk_style_context_set_screen")]
870 #[doc(alias = "screen")]
871 fn set_screen(&self, screen: &gdk::Screen) {
872 unsafe {
873 ffi::gtk_style_context_set_screen(
874 self.as_ref().to_glib_none().0,
875 screen.to_glib_none().0,
876 );
877 }
878 }
879
880 /// Sets the state to be used for style matching.
881 /// ## `flags`
882 /// state to represent
883 #[doc(alias = "gtk_style_context_set_state")]
884 fn set_state(&self, flags: StateFlags) {
885 unsafe {
886 ffi::gtk_style_context_set_state(self.as_ref().to_glib_none().0, flags.into_glib());
887 }
888 }
889
890 /// Converts the style context into a string representation.
891 ///
892 /// The string representation always includes information about
893 /// the name, state, id, visibility and style classes of the CSS
894 /// node that is backing `self`. Depending on the flags, more
895 /// information may be included.
896 ///
897 /// This function is intended for testing and debugging of the
898 /// CSS implementation in GTK+. There are no guarantees about
899 /// the format of the returned string, it may change.
900 /// ## `flags`
901 /// Flags that determine what to print
902 ///
903 /// # Returns
904 ///
905 /// a newly allocated string representing `self`
906 #[doc(alias = "gtk_style_context_to_string")]
907 fn to_string(&self, flags: StyleContextPrintFlags) -> Option<glib::GString> {
908 unsafe {
909 from_glib_full(ffi::gtk_style_context_to_string(
910 self.as_ref().to_glib_none().0,
911 flags.into_glib(),
912 ))
913 }
914 }
915
916 fn direction(&self) -> TextDirection {
917 ObjectExt::property(self.as_ref(), "direction")
918 }
919
920 fn set_direction(&self, direction: TextDirection) {
921 ObjectExt::set_property(self.as_ref(), "direction", direction)
922 }
923
924 #[doc(alias = "paint-clock")]
925 fn paint_clock(&self) -> Option<gdk::FrameClock> {
926 ObjectExt::property(self.as_ref(), "paint-clock")
927 }
928
929 #[doc(alias = "paint-clock")]
930 fn set_paint_clock(&self, paint_clock: Option<&gdk::FrameClock>) {
931 ObjectExt::set_property(self.as_ref(), "paint-clock", paint_clock)
932 }
933
934 /// The ::changed signal is emitted when there is a change in the
935 /// [`StyleContext`][crate::StyleContext].
936 ///
937 /// For a [`StyleContext`][crate::StyleContext] returned by [`WidgetExt::style_context()`][crate::prelude::WidgetExt::style_context()], the
938 /// [`style-updated`][struct@crate::Widget#style-updated] signal/vfunc might be more convenient to use.
939 ///
940 /// This signal is useful when using the theming layer standalone.
941 #[doc(alias = "changed")]
942 fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
943 unsafe extern "C" fn changed_trampoline<P: IsA<StyleContext>, F: Fn(&P) + 'static>(
944 this: *mut ffi::GtkStyleContext,
945 f: glib::ffi::gpointer,
946 ) {
947 unsafe {
948 let f: &F = &*(f as *const F);
949 f(StyleContext::from_glib_borrow(this).unsafe_cast_ref())
950 }
951 }
952 unsafe {
953 let f: Box_<F> = Box_::new(f);
954 connect_raw(
955 self.as_ptr() as *mut _,
956 c"changed".as_ptr(),
957 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
958 changed_trampoline::<Self, F> as *const (),
959 )),
960 Box_::into_raw(f),
961 )
962 }
963 }
964
965 #[doc(alias = "direction")]
966 fn connect_direction_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
967 unsafe extern "C" fn notify_direction_trampoline<
968 P: IsA<StyleContext>,
969 F: Fn(&P) + 'static,
970 >(
971 this: *mut ffi::GtkStyleContext,
972 _param_spec: glib::ffi::gpointer,
973 f: glib::ffi::gpointer,
974 ) {
975 unsafe {
976 let f: &F = &*(f as *const F);
977 f(StyleContext::from_glib_borrow(this).unsafe_cast_ref())
978 }
979 }
980 unsafe {
981 let f: Box_<F> = Box_::new(f);
982 connect_raw(
983 self.as_ptr() as *mut _,
984 c"notify::direction".as_ptr(),
985 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
986 notify_direction_trampoline::<Self, F> as *const (),
987 )),
988 Box_::into_raw(f),
989 )
990 }
991 }
992
993 #[doc(alias = "paint-clock")]
994 fn connect_paint_clock_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
995 unsafe extern "C" fn notify_paint_clock_trampoline<
996 P: IsA<StyleContext>,
997 F: Fn(&P) + 'static,
998 >(
999 this: *mut ffi::GtkStyleContext,
1000 _param_spec: glib::ffi::gpointer,
1001 f: glib::ffi::gpointer,
1002 ) {
1003 unsafe {
1004 let f: &F = &*(f as *const F);
1005 f(StyleContext::from_glib_borrow(this).unsafe_cast_ref())
1006 }
1007 }
1008 unsafe {
1009 let f: Box_<F> = Box_::new(f);
1010 connect_raw(
1011 self.as_ptr() as *mut _,
1012 c"notify::paint-clock".as_ptr(),
1013 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1014 notify_paint_clock_trampoline::<Self, F> as *const (),
1015 )),
1016 Box_::into_raw(f),
1017 )
1018 }
1019 }
1020
1021 #[doc(alias = "parent")]
1022 fn connect_parent_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1023 unsafe extern "C" fn notify_parent_trampoline<P: IsA<StyleContext>, F: Fn(&P) + 'static>(
1024 this: *mut ffi::GtkStyleContext,
1025 _param_spec: glib::ffi::gpointer,
1026 f: glib::ffi::gpointer,
1027 ) {
1028 unsafe {
1029 let f: &F = &*(f as *const F);
1030 f(StyleContext::from_glib_borrow(this).unsafe_cast_ref())
1031 }
1032 }
1033 unsafe {
1034 let f: Box_<F> = Box_::new(f);
1035 connect_raw(
1036 self.as_ptr() as *mut _,
1037 c"notify::parent".as_ptr(),
1038 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1039 notify_parent_trampoline::<Self, F> as *const (),
1040 )),
1041 Box_::into_raw(f),
1042 )
1043 }
1044 }
1045
1046 #[doc(alias = "screen")]
1047 fn connect_screen_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1048 unsafe extern "C" fn notify_screen_trampoline<P: IsA<StyleContext>, F: Fn(&P) + 'static>(
1049 this: *mut ffi::GtkStyleContext,
1050 _param_spec: glib::ffi::gpointer,
1051 f: glib::ffi::gpointer,
1052 ) {
1053 unsafe {
1054 let f: &F = &*(f as *const F);
1055 f(StyleContext::from_glib_borrow(this).unsafe_cast_ref())
1056 }
1057 }
1058 unsafe {
1059 let f: Box_<F> = Box_::new(f);
1060 connect_raw(
1061 self.as_ptr() as *mut _,
1062 c"notify::screen".as_ptr(),
1063 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1064 notify_screen_trampoline::<Self, F> as *const (),
1065 )),
1066 Box_::into_raw(f),
1067 )
1068 }
1069 }
1070}
1071
1072impl<O: IsA<StyleContext>> StyleContextExt for O {}