gtk4/auto/
style_context.rs1#![allow(deprecated)]
5
6use crate::{ffi, Border, StateFlags, StyleContextPrintFlags, StyleProvider};
7use glib::{
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "GtkStyleContext")]
16 pub struct StyleContext(Object<ffi::GtkStyleContext, ffi::GtkStyleContextClass>);
17
18 match fn {
19 type_ => || ffi::gtk_style_context_get_type(),
20 }
21}
22
23impl StyleContext {
24 pub const NONE: Option<&'static StyleContext> = None;
25}
26
27pub trait StyleContextExt: IsA<StyleContext> + 'static {
28 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
29 #[allow(deprecated)]
30 #[doc(alias = "gtk_style_context_add_class")]
31 fn add_class(&self, class_name: &str) {
32 unsafe {
33 ffi::gtk_style_context_add_class(
34 self.as_ref().to_glib_none().0,
35 class_name.to_glib_none().0,
36 );
37 }
38 }
39
40 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
41 #[allow(deprecated)]
42 #[doc(alias = "gtk_style_context_add_provider")]
43 fn add_provider(&self, provider: &impl IsA<StyleProvider>, priority: u32) {
44 unsafe {
45 ffi::gtk_style_context_add_provider(
46 self.as_ref().to_glib_none().0,
47 provider.as_ref().to_glib_none().0,
48 priority,
49 );
50 }
51 }
52
53 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
54 #[allow(deprecated)]
55 #[doc(alias = "gtk_style_context_get_border")]
56 #[doc(alias = "get_border")]
57 fn border(&self) -> Border {
58 unsafe {
59 let mut border = Border::uninitialized();
60 ffi::gtk_style_context_get_border(
61 self.as_ref().to_glib_none().0,
62 border.to_glib_none_mut().0,
63 );
64 border
65 }
66 }
67
68 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
69 #[allow(deprecated)]
70 #[doc(alias = "gtk_style_context_get_color")]
71 #[doc(alias = "get_color")]
72 fn color(&self) -> gdk::RGBA {
73 unsafe {
74 let mut color = gdk::RGBA::uninitialized();
75 ffi::gtk_style_context_get_color(
76 self.as_ref().to_glib_none().0,
77 color.to_glib_none_mut().0,
78 );
79 color
80 }
81 }
82
83 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
84 #[allow(deprecated)]
85 #[doc(alias = "gtk_style_context_get_display")]
86 #[doc(alias = "get_display")]
87 fn display(&self) -> gdk::Display {
88 unsafe {
89 from_glib_none(ffi::gtk_style_context_get_display(
90 self.as_ref().to_glib_none().0,
91 ))
92 }
93 }
94
95 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
96 #[allow(deprecated)]
97 #[doc(alias = "gtk_style_context_get_margin")]
98 #[doc(alias = "get_margin")]
99 fn margin(&self) -> Border {
100 unsafe {
101 let mut margin = Border::uninitialized();
102 ffi::gtk_style_context_get_margin(
103 self.as_ref().to_glib_none().0,
104 margin.to_glib_none_mut().0,
105 );
106 margin
107 }
108 }
109
110 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
111 #[allow(deprecated)]
112 #[doc(alias = "gtk_style_context_get_padding")]
113 #[doc(alias = "get_padding")]
114 fn padding(&self) -> Border {
115 unsafe {
116 let mut padding = Border::uninitialized();
117 ffi::gtk_style_context_get_padding(
118 self.as_ref().to_glib_none().0,
119 padding.to_glib_none_mut().0,
120 );
121 padding
122 }
123 }
124
125 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
126 #[allow(deprecated)]
127 #[doc(alias = "gtk_style_context_get_scale")]
128 #[doc(alias = "get_scale")]
129 fn scale(&self) -> i32 {
130 unsafe { ffi::gtk_style_context_get_scale(self.as_ref().to_glib_none().0) }
131 }
132
133 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
134 #[allow(deprecated)]
135 #[doc(alias = "gtk_style_context_get_state")]
136 #[doc(alias = "get_state")]
137 fn state(&self) -> StateFlags {
138 unsafe {
139 from_glib(ffi::gtk_style_context_get_state(
140 self.as_ref().to_glib_none().0,
141 ))
142 }
143 }
144
145 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
146 #[allow(deprecated)]
147 #[doc(alias = "gtk_style_context_has_class")]
148 fn has_class(&self, class_name: &str) -> bool {
149 unsafe {
150 from_glib(ffi::gtk_style_context_has_class(
151 self.as_ref().to_glib_none().0,
152 class_name.to_glib_none().0,
153 ))
154 }
155 }
156
157 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
158 #[allow(deprecated)]
159 #[doc(alias = "gtk_style_context_lookup_color")]
160 fn lookup_color(&self, color_name: &str) -> Option<gdk::RGBA> {
161 unsafe {
162 let mut color = gdk::RGBA::uninitialized();
163 let ret = from_glib(ffi::gtk_style_context_lookup_color(
164 self.as_ref().to_glib_none().0,
165 color_name.to_glib_none().0,
166 color.to_glib_none_mut().0,
167 ));
168 if ret {
169 Some(color)
170 } else {
171 None
172 }
173 }
174 }
175
176 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
177 #[allow(deprecated)]
178 #[doc(alias = "gtk_style_context_remove_class")]
179 fn remove_class(&self, class_name: &str) {
180 unsafe {
181 ffi::gtk_style_context_remove_class(
182 self.as_ref().to_glib_none().0,
183 class_name.to_glib_none().0,
184 );
185 }
186 }
187
188 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
189 #[allow(deprecated)]
190 #[doc(alias = "gtk_style_context_remove_provider")]
191 fn remove_provider(&self, provider: &impl IsA<StyleProvider>) {
192 unsafe {
193 ffi::gtk_style_context_remove_provider(
194 self.as_ref().to_glib_none().0,
195 provider.as_ref().to_glib_none().0,
196 );
197 }
198 }
199
200 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
201 #[allow(deprecated)]
202 #[doc(alias = "gtk_style_context_restore")]
203 fn restore(&self) {
204 unsafe {
205 ffi::gtk_style_context_restore(self.as_ref().to_glib_none().0);
206 }
207 }
208
209 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
210 #[allow(deprecated)]
211 #[doc(alias = "gtk_style_context_save")]
212 fn save(&self) {
213 unsafe {
214 ffi::gtk_style_context_save(self.as_ref().to_glib_none().0);
215 }
216 }
217
218 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
219 #[allow(deprecated)]
220 #[doc(alias = "gtk_style_context_set_display")]
221 #[doc(alias = "display")]
222 fn set_display(&self, display: &impl IsA<gdk::Display>) {
223 unsafe {
224 ffi::gtk_style_context_set_display(
225 self.as_ref().to_glib_none().0,
226 display.as_ref().to_glib_none().0,
227 );
228 }
229 }
230
231 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
232 #[allow(deprecated)]
233 #[doc(alias = "gtk_style_context_set_scale")]
234 fn set_scale(&self, scale: i32) {
235 unsafe {
236 ffi::gtk_style_context_set_scale(self.as_ref().to_glib_none().0, scale);
237 }
238 }
239
240 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
241 #[allow(deprecated)]
242 #[doc(alias = "gtk_style_context_set_state")]
243 fn set_state(&self, flags: StateFlags) {
244 unsafe {
245 ffi::gtk_style_context_set_state(self.as_ref().to_glib_none().0, flags.into_glib());
246 }
247 }
248
249 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
250 #[allow(deprecated)]
251 #[doc(alias = "gtk_style_context_to_string")]
252 fn to_string(&self, flags: StyleContextPrintFlags) -> glib::GString {
253 unsafe {
254 from_glib_full(ffi::gtk_style_context_to_string(
255 self.as_ref().to_glib_none().0,
256 flags.into_glib(),
257 ))
258 }
259 }
260
261 #[doc(alias = "display")]
262 fn connect_display_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
263 unsafe extern "C" fn notify_display_trampoline<
264 P: IsA<StyleContext>,
265 F: Fn(&P) + 'static,
266 >(
267 this: *mut ffi::GtkStyleContext,
268 _param_spec: glib::ffi::gpointer,
269 f: glib::ffi::gpointer,
270 ) {
271 let f: &F = &*(f as *const F);
272 f(StyleContext::from_glib_borrow(this).unsafe_cast_ref())
273 }
274 unsafe {
275 let f: Box_<F> = Box_::new(f);
276 connect_raw(
277 self.as_ptr() as *mut _,
278 c"notify::display".as_ptr() as *const _,
279 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
280 notify_display_trampoline::<Self, F> as *const (),
281 )),
282 Box_::into_raw(f),
283 )
284 }
285 }
286}
287
288impl<O: IsA<StyleContext>> StyleContextExt for O {}