gtk/auto/widget_path.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::{StateFlags, Widget, ffi};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 ///
10 /// {
11 /// GtkWidgetPath *path;
12 /// guint pos;
13 ///
14 /// path = gtk_widget_path_new ();
15 ///
16 /// pos = gtk_widget_path_append_type (path, GTK_TYPE_NOTEBOOK);
17 /// gtk_widget_path_iter_add_region (path, pos, "tab", GTK_REGION_EVEN | GTK_REGION_FIRST);
18 ///
19 /// pos = gtk_widget_path_append_type (path, GTK_TYPE_LABEL);
20 /// gtk_widget_path_iter_set_name (path, pos, "first tab label");
21 /// }
22 /// ]|
23 ///
24 /// All this information will be used to match the style information
25 /// that applies to the described widget.
26 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
27 pub struct WidgetPath(Shared<ffi::GtkWidgetPath>);
28
29 match fn {
30 ref => |ptr| ffi::gtk_widget_path_ref(ptr),
31 unref => |ptr| ffi::gtk_widget_path_unref(ptr),
32 type_ => || ffi::gtk_widget_path_get_type(),
33 }
34}
35
36impl WidgetPath {
37 /// Returns an empty widget path.
38 ///
39 /// # Returns
40 ///
41 /// A newly created, empty, [`WidgetPath`][crate::WidgetPath]
42 #[doc(alias = "gtk_widget_path_new")]
43 pub fn new() -> WidgetPath {
44 assert_initialized_main_thread!();
45 unsafe { from_glib_full(ffi::gtk_widget_path_new()) }
46 }
47
48 /// Appends the data from `widget` to the widget hierarchy represented
49 /// by `self`. This function is a shortcut for adding information from
50 /// `widget` to the given `self`. This includes setting the name or
51 /// adding the style classes from `widget`.
52 /// ## `widget`
53 /// the widget to append to the widget path
54 ///
55 /// # Returns
56 ///
57 /// the position where the data was inserted
58 #[doc(alias = "gtk_widget_path_append_for_widget")]
59 pub fn append_for_widget(&self, widget: &impl IsA<Widget>) -> i32 {
60 unsafe {
61 ffi::gtk_widget_path_append_for_widget(
62 self.to_glib_none().0,
63 widget.as_ref().to_glib_none().0,
64 )
65 }
66 }
67
68 /// Appends a widget type to the widget hierarchy represented by `self`.
69 /// ## `type_`
70 /// widget type to append
71 ///
72 /// # Returns
73 ///
74 /// the position where the element was inserted
75 #[doc(alias = "gtk_widget_path_append_type")]
76 pub fn append_type(&self, type_: glib::types::Type) -> i32 {
77 unsafe { ffi::gtk_widget_path_append_type(self.to_glib_none().0, type_.into_glib()) }
78 }
79
80 /// Appends a widget type with all its siblings to the widget hierarchy
81 /// represented by `self`. Using this function instead of
82 /// [`append_type()`][Self::append_type()] will allow the CSS theming to use
83 /// sibling matches in selectors and apply :nth-`child()` pseudo classes.
84 /// In turn, it requires a lot more care in widget implementations as
85 /// widgets need to make sure to call [`WidgetExt::reset_style()`][crate::prelude::WidgetExt::reset_style()] on all
86 /// involved widgets when the `siblings` path changes.
87 /// ## `siblings`
88 /// a widget path describing a list of siblings. This path
89 /// may not contain any siblings itself and it must not be modified
90 /// afterwards.
91 /// ## `sibling_index`
92 /// index into `siblings` for where the added element is
93 /// positioned.
94 ///
95 /// # Returns
96 ///
97 /// the position where the element was inserted.
98 #[doc(alias = "gtk_widget_path_append_with_siblings")]
99 pub fn append_with_siblings(&self, siblings: &WidgetPath, sibling_index: u32) -> i32 {
100 unsafe {
101 ffi::gtk_widget_path_append_with_siblings(
102 self.to_glib_none().0,
103 siblings.to_glib_none().0,
104 sibling_index,
105 )
106 }
107 }
108
109 #[doc(alias = "gtk_widget_path_copy")]
110 #[must_use]
111 pub fn copy(&self) -> Option<WidgetPath> {
112 unsafe { from_glib_full(ffi::gtk_widget_path_copy(self.to_glib_none().0)) }
113 }
114
115 /// Returns the topmost object type, that is, the object type this path
116 /// is representing.
117 ///
118 /// # Returns
119 ///
120 /// The object type
121 #[doc(alias = "gtk_widget_path_get_object_type")]
122 #[doc(alias = "get_object_type")]
123 pub fn object_type(&self) -> glib::types::Type {
124 unsafe { from_glib(ffi::gtk_widget_path_get_object_type(self.to_glib_none().0)) }
125 }
126
127 /// Returns [`true`] if any of the parents of the widget represented
128 /// in `self` is of type `type_`, or any subtype of it.
129 /// ## `type_`
130 /// widget type to check in parents
131 ///
132 /// # Returns
133 ///
134 /// [`true`] if any parent is of type `type_`
135 #[doc(alias = "gtk_widget_path_has_parent")]
136 pub fn has_parent(&self, type_: glib::types::Type) -> bool {
137 unsafe {
138 from_glib(ffi::gtk_widget_path_has_parent(
139 self.to_glib_none().0,
140 type_.into_glib(),
141 ))
142 }
143 }
144
145 /// Returns [`true`] if the widget type represented by this path
146 /// is `type_`, or a subtype of it.
147 /// ## `type_`
148 /// widget type to match
149 ///
150 /// # Returns
151 ///
152 /// [`true`] if the widget represented by `self` is of type `type_`
153 #[doc(alias = "gtk_widget_path_is_type")]
154 pub fn is_type(&self, type_: glib::types::Type) -> bool {
155 unsafe {
156 from_glib(ffi::gtk_widget_path_is_type(
157 self.to_glib_none().0,
158 type_.into_glib(),
159 ))
160 }
161 }
162
163 /// Adds the class `name` to the widget at position `pos` in
164 /// the hierarchy defined in `self`. See
165 /// [`StyleContextExt::add_class()`][crate::prelude::StyleContextExt::add_class()].
166 /// ## `pos`
167 /// position to modify, -1 for the path head
168 /// ## `name`
169 /// a class name
170 #[doc(alias = "gtk_widget_path_iter_add_class")]
171 pub fn iter_add_class(&self, pos: i32, name: &str) {
172 unsafe {
173 ffi::gtk_widget_path_iter_add_class(self.to_glib_none().0, pos, name.to_glib_none().0);
174 }
175 }
176
177 /// Removes all classes from the widget at position `pos` in the
178 /// hierarchy defined in `self`.
179 /// ## `pos`
180 /// position to modify, -1 for the path head
181 #[doc(alias = "gtk_widget_path_iter_clear_classes")]
182 pub fn iter_clear_classes(&self, pos: i32) {
183 unsafe {
184 ffi::gtk_widget_path_iter_clear_classes(self.to_glib_none().0, pos);
185 }
186 }
187
188 /// Returns the name corresponding to the widget found at
189 /// the position `pos` in the widget hierarchy defined by
190 /// `self`
191 /// ## `pos`
192 /// position to get the widget name for, -1 for the path head
193 ///
194 /// # Returns
195 ///
196 /// The widget name, or [`None`] if none was set.
197 #[doc(alias = "gtk_widget_path_iter_get_name")]
198 pub fn iter_get_name(&self, pos: i32) -> Option<glib::GString> {
199 unsafe {
200 from_glib_none(ffi::gtk_widget_path_iter_get_name(
201 self.to_glib_none().0,
202 pos,
203 ))
204 }
205 }
206
207 /// Returns the object name that is at position `pos` in the widget
208 /// hierarchy defined in `self`.
209 /// ## `pos`
210 /// position to get the object name for, -1 for the path head
211 ///
212 /// # Returns
213 ///
214 /// the name or [`None`]
215 #[doc(alias = "gtk_widget_path_iter_get_object_name")]
216 pub fn iter_get_object_name(&self, pos: i32) -> Option<glib::GString> {
217 unsafe {
218 from_glib_none(ffi::gtk_widget_path_iter_get_object_name(
219 self.to_glib_none().0,
220 pos,
221 ))
222 }
223 }
224
225 /// Returns the object `GType` that is at position `pos` in the widget
226 /// hierarchy defined in `self`.
227 /// ## `pos`
228 /// position to get the object type for, -1 for the path head
229 ///
230 /// # Returns
231 ///
232 /// a widget type
233 #[doc(alias = "gtk_widget_path_iter_get_object_type")]
234 pub fn iter_get_object_type(&self, pos: i32) -> glib::types::Type {
235 unsafe {
236 from_glib(ffi::gtk_widget_path_iter_get_object_type(
237 self.to_glib_none().0,
238 pos,
239 ))
240 }
241 }
242
243 /// Returns the index into the list of siblings for the element at `pos` as
244 /// returned by [`iter_get_siblings()`][Self::iter_get_siblings()]. If that function would
245 /// return [`None`] because the element at `pos` has no siblings, this function
246 /// will return 0.
247 /// ## `pos`
248 /// position to get the sibling index for, -1 for the path head
249 ///
250 /// # Returns
251 ///
252 /// 0 or the index into the list of siblings for the element at `pos`.
253 #[doc(alias = "gtk_widget_path_iter_get_sibling_index")]
254 pub fn iter_get_sibling_index(&self, pos: i32) -> u32 {
255 unsafe { ffi::gtk_widget_path_iter_get_sibling_index(self.to_glib_none().0, pos) }
256 }
257
258 /// Returns the list of siblings for the element at `pos`. If the element
259 /// was not added with siblings, [`None`] is returned.
260 /// ## `pos`
261 /// position to get the siblings for, -1 for the path head
262 ///
263 /// # Returns
264 ///
265 /// [`None`] or the list of siblings for the element at `pos`.
266 #[doc(alias = "gtk_widget_path_iter_get_siblings")]
267 #[must_use]
268 pub fn iter_get_siblings(&self, pos: i32) -> Option<WidgetPath> {
269 unsafe {
270 from_glib_none(ffi::gtk_widget_path_iter_get_siblings(
271 self.to_glib_none().0,
272 pos,
273 ))
274 }
275 }
276
277 /// Returns the state flags corresponding to the widget found at
278 /// the position `pos` in the widget hierarchy defined by
279 /// `self`
280 /// ## `pos`
281 /// position to get the state for, -1 for the path head
282 ///
283 /// # Returns
284 ///
285 /// The state flags
286 #[doc(alias = "gtk_widget_path_iter_get_state")]
287 pub fn iter_get_state(&self, pos: i32) -> StateFlags {
288 unsafe {
289 from_glib(ffi::gtk_widget_path_iter_get_state(
290 self.to_glib_none().0,
291 pos,
292 ))
293 }
294 }
295
296 /// Returns [`true`] if the widget at position `pos` has the class `name`
297 /// defined, [`false`] otherwise.
298 /// ## `pos`
299 /// position to query, -1 for the path head
300 /// ## `name`
301 /// class name
302 ///
303 /// # Returns
304 ///
305 /// [`true`] if the class `name` is defined for the widget at `pos`
306 #[doc(alias = "gtk_widget_path_iter_has_class")]
307 pub fn iter_has_class(&self, pos: i32, name: &str) -> bool {
308 unsafe {
309 from_glib(ffi::gtk_widget_path_iter_has_class(
310 self.to_glib_none().0,
311 pos,
312 name.to_glib_none().0,
313 ))
314 }
315 }
316
317 /// Returns [`true`] if the widget at position `pos` has the name `name`,
318 /// [`false`] otherwise.
319 /// ## `pos`
320 /// position to query, -1 for the path head
321 /// ## `name`
322 /// a widget name
323 ///
324 /// # Returns
325 ///
326 /// [`true`] if the widget at `pos` has this name
327 #[doc(alias = "gtk_widget_path_iter_has_name")]
328 pub fn iter_has_name(&self, pos: i32, name: &str) -> bool {
329 unsafe {
330 from_glib(ffi::gtk_widget_path_iter_has_name(
331 self.to_glib_none().0,
332 pos,
333 name.to_glib_none().0,
334 ))
335 }
336 }
337
338 /// See [`iter_has_class()`][Self::iter_has_class()]. This is a version that operates
339 /// with GQuarks.
340 /// ## `pos`
341 /// position to query, -1 for the path head
342 /// ## `qname`
343 /// class name as a `GQuark`
344 ///
345 /// # Returns
346 ///
347 /// [`true`] if the widget at `pos` has the class defined.
348 #[doc(alias = "gtk_widget_path_iter_has_qclass")]
349 pub fn iter_has_qclass(&self, pos: i32, qname: glib::Quark) -> bool {
350 unsafe {
351 from_glib(ffi::gtk_widget_path_iter_has_qclass(
352 self.to_glib_none().0,
353 pos,
354 qname.into_glib(),
355 ))
356 }
357 }
358
359 /// See [`iter_has_name()`][Self::iter_has_name()]. This is a version
360 /// that operates on `GQuarks`.
361 /// ## `pos`
362 /// position to query, -1 for the path head
363 /// ## `qname`
364 /// widget name as a `GQuark`
365 ///
366 /// # Returns
367 ///
368 /// [`true`] if the widget at `pos` has this name
369 #[doc(alias = "gtk_widget_path_iter_has_qname")]
370 pub fn iter_has_qname(&self, pos: i32, qname: glib::Quark) -> bool {
371 unsafe {
372 from_glib(ffi::gtk_widget_path_iter_has_qname(
373 self.to_glib_none().0,
374 pos,
375 qname.into_glib(),
376 ))
377 }
378 }
379
380 /// Returns a list with all the class names defined for the widget
381 /// at position `pos` in the hierarchy defined in `self`.
382 /// ## `pos`
383 /// position to query, -1 for the path head
384 ///
385 /// # Returns
386 ///
387 /// The list of
388 /// classes, This is a list of strings, the `GSList` contents
389 /// are owned by GTK+, but you should use `g_slist_free()` to
390 /// free the list itself.
391 #[doc(alias = "gtk_widget_path_iter_list_classes")]
392 pub fn iter_list_classes(&self, pos: i32) -> Vec<glib::GString> {
393 unsafe {
394 FromGlibPtrContainer::from_glib_container(ffi::gtk_widget_path_iter_list_classes(
395 self.to_glib_none().0,
396 pos,
397 ))
398 }
399 }
400
401 /// Removes the class `name` from the widget at position `pos` in
402 /// the hierarchy defined in `self`.
403 /// ## `pos`
404 /// position to modify, -1 for the path head
405 /// ## `name`
406 /// class name
407 #[doc(alias = "gtk_widget_path_iter_remove_class")]
408 pub fn iter_remove_class(&self, pos: i32, name: &str) {
409 unsafe {
410 ffi::gtk_widget_path_iter_remove_class(
411 self.to_glib_none().0,
412 pos,
413 name.to_glib_none().0,
414 );
415 }
416 }
417
418 /// Sets the widget name for the widget found at position `pos`
419 /// in the widget hierarchy defined by `self`.
420 /// ## `pos`
421 /// position to modify, -1 for the path head
422 /// ## `name`
423 /// widget name
424 #[doc(alias = "gtk_widget_path_iter_set_name")]
425 pub fn iter_set_name(&self, pos: i32, name: &str) {
426 unsafe {
427 ffi::gtk_widget_path_iter_set_name(self.to_glib_none().0, pos, name.to_glib_none().0);
428 }
429 }
430
431 /// Sets the object name for a given position in the widget hierarchy
432 /// defined by `self`.
433 ///
434 /// When set, the object name overrides the object type when matching
435 /// CSS.
436 /// ## `pos`
437 /// position to modify, -1 for the path head
438 /// ## `name`
439 /// object name to set or [`None`] to unset
440 #[doc(alias = "gtk_widget_path_iter_set_object_name")]
441 pub fn iter_set_object_name(&self, pos: i32, name: Option<&str>) {
442 unsafe {
443 ffi::gtk_widget_path_iter_set_object_name(
444 self.to_glib_none().0,
445 pos,
446 name.to_glib_none().0,
447 );
448 }
449 }
450
451 /// Sets the object type for a given position in the widget hierarchy
452 /// defined by `self`.
453 /// ## `pos`
454 /// position to modify, -1 for the path head
455 /// ## `type_`
456 /// object type to set
457 #[doc(alias = "gtk_widget_path_iter_set_object_type")]
458 pub fn iter_set_object_type(&self, pos: i32, type_: glib::types::Type) {
459 unsafe {
460 ffi::gtk_widget_path_iter_set_object_type(
461 self.to_glib_none().0,
462 pos,
463 type_.into_glib(),
464 );
465 }
466 }
467
468 /// ~flag);
469 /// ]|
470 /// ## `pos`
471 /// position to modify, -1 for the path head
472 /// ## `state`
473 /// state flags
474 #[doc(alias = "gtk_widget_path_iter_set_state")]
475 pub fn iter_set_state(&self, pos: i32, state: StateFlags) {
476 unsafe {
477 ffi::gtk_widget_path_iter_set_state(self.to_glib_none().0, pos, state.into_glib());
478 }
479 }
480
481 /// Returns the number of [`Widget`][crate::Widget] `GTypes` between the represented
482 /// widget and its topmost container.
483 ///
484 /// # Returns
485 ///
486 /// the number of elements in the path
487 #[doc(alias = "gtk_widget_path_length")]
488 pub fn length(&self) -> i32 {
489 unsafe { ffi::gtk_widget_path_length(self.to_glib_none().0) }
490 }
491
492 /// Prepends a widget type to the widget hierachy represented by `self`.
493 /// ## `type_`
494 /// widget type to prepend
495 #[doc(alias = "gtk_widget_path_prepend_type")]
496 pub fn prepend_type(&self, type_: glib::types::Type) {
497 unsafe {
498 ffi::gtk_widget_path_prepend_type(self.to_glib_none().0, type_.into_glib());
499 }
500 }
501
502 /// Dumps the widget path into a string representation. It tries to match
503 /// the CSS style as closely as possible (Note that there might be paths
504 /// that cannot be represented in CSS).
505 ///
506 /// The main use of this code is for debugging purposes, so that you can
507 /// `g_print()` the path or dump it in a gdb session.
508 ///
509 /// # Returns
510 ///
511 /// A new string describing `self`.
512 #[doc(alias = "gtk_widget_path_to_string")]
513 #[doc(alias = "to_string")]
514 pub fn to_str(&self) -> glib::GString {
515 unsafe { from_glib_full(ffi::gtk_widget_path_to_string(self.to_glib_none().0)) }
516 }
517}
518
519impl Default for WidgetPath {
520 fn default() -> Self {
521 Self::new()
522 }
523}
524
525impl std::fmt::Display for WidgetPath {
526 #[inline]
527 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
528 f.write_str(&self.to_str())
529 }
530}