gtk4/auto/
list_item.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::{ffi, Widget};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// [`ListItem`][crate::ListItem] is used by list widgets to represent items in a
15    /// [`gio::ListModel`][crate::gio::ListModel].
16    ///
17    /// [`ListItem`][crate::ListItem] objects are managed by the list widget (with its factory)
18    /// and cannot be created by applications, but they need to be populated
19    /// by application code. This is done by calling [`ListItemExt::set_child()`][crate::prelude::ListItemExt::set_child()].
20    ///
21    /// [`ListItem`][crate::ListItem] objects exist in 2 stages:
22    ///
23    /// 1. The unbound stage where the listitem is not currently connected to
24    ///    an item in the list. In that case, the [`item`][struct@crate::ListItem#item]
25    ///    property is set to [`None`].
26    ///
27    /// 2. The bound stage where the listitem references an item from the list.
28    ///    The [`item`][struct@crate::ListItem#item] property is not [`None`].
29    ///
30    /// ## Properties
31    ///
32    ///
33    /// #### `accessible-description`
34    ///  The accessible description to set on the list item.
35    ///
36    /// Readable | Writeable
37    ///
38    ///
39    /// #### `accessible-label`
40    ///  The accessible label to set on the list item.
41    ///
42    /// Readable | Writeable
43    ///
44    ///
45    /// #### `activatable`
46    ///  If the item can be activated by the user.
47    ///
48    /// Readable | Writeable
49    ///
50    ///
51    /// #### `child`
52    ///  Widget used for display.
53    ///
54    /// Readable | Writeable
55    ///
56    ///
57    /// #### `focusable`
58    ///  If the item can be focused with the keyboard.
59    ///
60    /// Readable | Writeable
61    ///
62    ///
63    /// #### `item`
64    ///  Displayed item.
65    ///
66    /// Readable
67    ///
68    ///
69    /// #### `position`
70    ///  Position of the item.
71    ///
72    /// Readable
73    ///
74    ///
75    /// #### `selectable`
76    ///  If the item can be selected by the user.
77    ///
78    /// Readable | Writeable
79    ///
80    ///
81    /// #### `selected`
82    ///  If the item is currently selected.
83    ///
84    /// Readable
85    ///
86    /// # Implements
87    ///
88    /// [`ListItemExt`][trait@crate::prelude::ListItemExt], [`trait@glib::ObjectExt`]
89    #[doc(alias = "GtkListItem")]
90    pub struct ListItem(Object<ffi::GtkListItem, ffi::GtkListItemClass>);
91
92    match fn {
93        type_ => || ffi::gtk_list_item_get_type(),
94    }
95}
96
97impl ListItem {
98    pub const NONE: Option<&'static ListItem> = None;
99}
100
101mod sealed {
102    pub trait Sealed {}
103    impl<T: super::IsA<super::ListItem>> Sealed for T {}
104}
105
106/// Trait containing all [`struct@ListItem`] methods.
107///
108/// # Implementors
109///
110/// [`ColumnViewCell`][struct@crate::ColumnViewCell], [`ListItem`][struct@crate::ListItem]
111pub trait ListItemExt: IsA<ListItem> + sealed::Sealed + 'static {
112    /// Gets the accessible description of @self.
113    ///
114    /// # Returns
115    ///
116    /// the accessible description
117    #[cfg(feature = "v4_12")]
118    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
119    #[doc(alias = "gtk_list_item_get_accessible_description")]
120    #[doc(alias = "get_accessible_description")]
121    #[doc(alias = "accessible-description")]
122    fn accessible_description(&self) -> glib::GString {
123        unsafe {
124            from_glib_none(ffi::gtk_list_item_get_accessible_description(
125                self.as_ref().to_glib_none().0,
126            ))
127        }
128    }
129
130    /// Gets the accessible label of @self.
131    ///
132    /// # Returns
133    ///
134    /// the accessible label
135    #[cfg(feature = "v4_12")]
136    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
137    #[doc(alias = "gtk_list_item_get_accessible_label")]
138    #[doc(alias = "get_accessible_label")]
139    #[doc(alias = "accessible-label")]
140    fn accessible_label(&self) -> glib::GString {
141        unsafe {
142            from_glib_none(ffi::gtk_list_item_get_accessible_label(
143                self.as_ref().to_glib_none().0,
144            ))
145        }
146    }
147
148    /// Checks if a list item has been set to be activatable via
149    /// gtk_list_item_set_activatable().
150    ///
151    /// # Returns
152    ///
153    /// [`true`] if the item is activatable
154    #[doc(alias = "gtk_list_item_get_activatable")]
155    #[doc(alias = "get_activatable")]
156    #[doc(alias = "activatable")]
157    fn is_activatable(&self) -> bool {
158        unsafe {
159            from_glib(ffi::gtk_list_item_get_activatable(
160                self.as_ref().to_glib_none().0,
161            ))
162        }
163    }
164
165    /// Gets the child previously set via gtk_list_item_set_child() or
166    /// [`None`] if none was set.
167    ///
168    /// # Returns
169    ///
170    /// The child
171    #[doc(alias = "gtk_list_item_get_child")]
172    #[doc(alias = "get_child")]
173    fn child(&self) -> Option<Widget> {
174        unsafe { from_glib_none(ffi::gtk_list_item_get_child(self.as_ref().to_glib_none().0)) }
175    }
176
177    /// Checks if a list item has been set to be focusable via
178    /// gtk_list_item_set_focusable().
179    ///
180    /// # Returns
181    ///
182    /// [`true`] if the item is focusable
183    #[cfg(feature = "v4_12")]
184    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
185    #[doc(alias = "gtk_list_item_get_focusable")]
186    #[doc(alias = "get_focusable")]
187    #[doc(alias = "focusable")]
188    fn is_focusable(&self) -> bool {
189        unsafe {
190            from_glib(ffi::gtk_list_item_get_focusable(
191                self.as_ref().to_glib_none().0,
192            ))
193        }
194    }
195
196    /// Gets the model item that associated with @self.
197    ///
198    /// If @self is unbound, this function returns [`None`].
199    ///
200    /// # Returns
201    ///
202    /// The item displayed
203    #[doc(alias = "gtk_list_item_get_item")]
204    #[doc(alias = "get_item")]
205    fn item(&self) -> Option<glib::Object> {
206        unsafe { from_glib_none(ffi::gtk_list_item_get_item(self.as_ref().to_glib_none().0)) }
207    }
208
209    /// Gets the position in the model that @self currently displays.
210    ///
211    /// If @self is unbound, `GTK_INVALID_LIST_POSITION` is returned.
212    ///
213    /// # Returns
214    ///
215    /// The position of this item
216    #[doc(alias = "gtk_list_item_get_position")]
217    #[doc(alias = "get_position")]
218    fn position(&self) -> u32 {
219        unsafe { ffi::gtk_list_item_get_position(self.as_ref().to_glib_none().0) }
220    }
221
222    /// Checks if a list item has been set to be selectable via
223    /// gtk_list_item_set_selectable().
224    ///
225    /// Do not confuse this function with [`is_selected()`][Self::is_selected()].
226    ///
227    /// # Returns
228    ///
229    /// [`true`] if the item is selectable
230    #[doc(alias = "gtk_list_item_get_selectable")]
231    #[doc(alias = "get_selectable")]
232    #[doc(alias = "selectable")]
233    fn is_selectable(&self) -> bool {
234        unsafe {
235            from_glib(ffi::gtk_list_item_get_selectable(
236                self.as_ref().to_glib_none().0,
237            ))
238        }
239    }
240
241    /// Checks if the item is displayed as selected.
242    ///
243    /// The selected state is maintained by the list widget and its model
244    /// and cannot be set otherwise.
245    ///
246    /// # Returns
247    ///
248    /// [`true`] if the item is selected.
249    #[doc(alias = "gtk_list_item_get_selected")]
250    #[doc(alias = "get_selected")]
251    #[doc(alias = "selected")]
252    fn is_selected(&self) -> bool {
253        unsafe {
254            from_glib(ffi::gtk_list_item_get_selected(
255                self.as_ref().to_glib_none().0,
256            ))
257        }
258    }
259
260    /// Sets the accessible description for the list item,
261    /// which may be used by e.g. screen readers.
262    /// ## `description`
263    /// the description
264    #[cfg(feature = "v4_12")]
265    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
266    #[doc(alias = "gtk_list_item_set_accessible_description")]
267    #[doc(alias = "accessible-description")]
268    fn set_accessible_description(&self, description: &str) {
269        unsafe {
270            ffi::gtk_list_item_set_accessible_description(
271                self.as_ref().to_glib_none().0,
272                description.to_glib_none().0,
273            );
274        }
275    }
276
277    /// Sets the accessible label for the list item,
278    /// which may be used by e.g. screen readers.
279    /// ## `label`
280    /// the label
281    #[cfg(feature = "v4_12")]
282    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
283    #[doc(alias = "gtk_list_item_set_accessible_label")]
284    #[doc(alias = "accessible-label")]
285    fn set_accessible_label(&self, label: &str) {
286        unsafe {
287            ffi::gtk_list_item_set_accessible_label(
288                self.as_ref().to_glib_none().0,
289                label.to_glib_none().0,
290            );
291        }
292    }
293
294    /// Sets @self to be activatable.
295    ///
296    /// If an item is activatable, double-clicking on the item, using
297    /// the Return key or calling gtk_widget_activate() will activate
298    /// the item. Activating instructs the containing view to handle
299    /// activation. [`ListView`][crate::ListView] for example will be emitting the
300    /// [`activate`][struct@crate::ListView#activate] signal.
301    ///
302    /// By default, list items are activatable.
303    /// ## `activatable`
304    /// if the item should be activatable
305    #[doc(alias = "gtk_list_item_set_activatable")]
306    #[doc(alias = "activatable")]
307    fn set_activatable(&self, activatable: bool) {
308        unsafe {
309            ffi::gtk_list_item_set_activatable(
310                self.as_ref().to_glib_none().0,
311                activatable.into_glib(),
312            );
313        }
314    }
315
316    /// Sets the child to be used for this listitem.
317    ///
318    /// This function is typically called by applications when
319    /// setting up a listitem so that the widget can be reused when
320    /// binding it multiple times.
321    /// ## `child`
322    /// The list item's child or [`None`] to unset
323    #[doc(alias = "gtk_list_item_set_child")]
324    #[doc(alias = "child")]
325    fn set_child(&self, child: Option<&impl IsA<Widget>>) {
326        unsafe {
327            ffi::gtk_list_item_set_child(
328                self.as_ref().to_glib_none().0,
329                child.map(|p| p.as_ref()).to_glib_none().0,
330            );
331        }
332    }
333
334    /// Sets @self to be focusable.
335    ///
336    /// If an item is focusable, it can be focused using the keyboard.
337    /// This works similar to [`WidgetExt::set_focusable()`][crate::prelude::WidgetExt::set_focusable()].
338    ///
339    /// Note that if items are not focusable, the keyboard cannot be used to activate
340    /// them and selecting only works if one of the listitem's children is focusable.
341    ///
342    /// By default, list items are focusable.
343    /// ## `focusable`
344    /// if the item should be focusable
345    #[cfg(feature = "v4_12")]
346    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
347    #[doc(alias = "gtk_list_item_set_focusable")]
348    #[doc(alias = "focusable")]
349    fn set_focusable(&self, focusable: bool) {
350        unsafe {
351            ffi::gtk_list_item_set_focusable(self.as_ref().to_glib_none().0, focusable.into_glib());
352        }
353    }
354
355    /// Sets @self to be selectable.
356    ///
357    /// If an item is selectable, clicking on the item or using the keyboard
358    /// will try to select or unselect the item. If this succeeds is up to
359    /// the model to determine, as it is managing the selected state.
360    ///
361    /// Note that this means that making an item non-selectable has no
362    /// influence on the selected state at all. A non-selectable item
363    /// may still be selected.
364    ///
365    /// By default, list items are selectable. When rebinding them to
366    /// a new item, they will also be reset to be selectable by GTK.
367    /// ## `selectable`
368    /// if the item should be selectable
369    #[doc(alias = "gtk_list_item_set_selectable")]
370    #[doc(alias = "selectable")]
371    fn set_selectable(&self, selectable: bool) {
372        unsafe {
373            ffi::gtk_list_item_set_selectable(
374                self.as_ref().to_glib_none().0,
375                selectable.into_glib(),
376            );
377        }
378    }
379
380    #[cfg(feature = "v4_12")]
381    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
382    #[doc(alias = "accessible-description")]
383    fn connect_accessible_description_notify<F: Fn(&Self) + 'static>(
384        &self,
385        f: F,
386    ) -> SignalHandlerId {
387        unsafe extern "C" fn notify_accessible_description_trampoline<
388            P: IsA<ListItem>,
389            F: Fn(&P) + 'static,
390        >(
391            this: *mut ffi::GtkListItem,
392            _param_spec: glib::ffi::gpointer,
393            f: glib::ffi::gpointer,
394        ) {
395            let f: &F = &*(f as *const F);
396            f(ListItem::from_glib_borrow(this).unsafe_cast_ref())
397        }
398        unsafe {
399            let f: Box_<F> = Box_::new(f);
400            connect_raw(
401                self.as_ptr() as *mut _,
402                b"notify::accessible-description\0".as_ptr() as *const _,
403                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
404                    notify_accessible_description_trampoline::<Self, F> as *const (),
405                )),
406                Box_::into_raw(f),
407            )
408        }
409    }
410
411    #[cfg(feature = "v4_12")]
412    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
413    #[doc(alias = "accessible-label")]
414    fn connect_accessible_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
415        unsafe extern "C" fn notify_accessible_label_trampoline<
416            P: IsA<ListItem>,
417            F: Fn(&P) + 'static,
418        >(
419            this: *mut ffi::GtkListItem,
420            _param_spec: glib::ffi::gpointer,
421            f: glib::ffi::gpointer,
422        ) {
423            let f: &F = &*(f as *const F);
424            f(ListItem::from_glib_borrow(this).unsafe_cast_ref())
425        }
426        unsafe {
427            let f: Box_<F> = Box_::new(f);
428            connect_raw(
429                self.as_ptr() as *mut _,
430                b"notify::accessible-label\0".as_ptr() as *const _,
431                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
432                    notify_accessible_label_trampoline::<Self, F> as *const (),
433                )),
434                Box_::into_raw(f),
435            )
436        }
437    }
438
439    #[doc(alias = "activatable")]
440    fn connect_activatable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
441        unsafe extern "C" fn notify_activatable_trampoline<
442            P: IsA<ListItem>,
443            F: Fn(&P) + 'static,
444        >(
445            this: *mut ffi::GtkListItem,
446            _param_spec: glib::ffi::gpointer,
447            f: glib::ffi::gpointer,
448        ) {
449            let f: &F = &*(f as *const F);
450            f(ListItem::from_glib_borrow(this).unsafe_cast_ref())
451        }
452        unsafe {
453            let f: Box_<F> = Box_::new(f);
454            connect_raw(
455                self.as_ptr() as *mut _,
456                b"notify::activatable\0".as_ptr() as *const _,
457                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
458                    notify_activatable_trampoline::<Self, F> as *const (),
459                )),
460                Box_::into_raw(f),
461            )
462        }
463    }
464
465    #[doc(alias = "child")]
466    fn connect_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
467        unsafe extern "C" fn notify_child_trampoline<P: IsA<ListItem>, F: Fn(&P) + 'static>(
468            this: *mut ffi::GtkListItem,
469            _param_spec: glib::ffi::gpointer,
470            f: glib::ffi::gpointer,
471        ) {
472            let f: &F = &*(f as *const F);
473            f(ListItem::from_glib_borrow(this).unsafe_cast_ref())
474        }
475        unsafe {
476            let f: Box_<F> = Box_::new(f);
477            connect_raw(
478                self.as_ptr() as *mut _,
479                b"notify::child\0".as_ptr() as *const _,
480                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
481                    notify_child_trampoline::<Self, F> as *const (),
482                )),
483                Box_::into_raw(f),
484            )
485        }
486    }
487
488    #[cfg(feature = "v4_12")]
489    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
490    #[doc(alias = "focusable")]
491    fn connect_focusable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
492        unsafe extern "C" fn notify_focusable_trampoline<P: IsA<ListItem>, F: Fn(&P) + 'static>(
493            this: *mut ffi::GtkListItem,
494            _param_spec: glib::ffi::gpointer,
495            f: glib::ffi::gpointer,
496        ) {
497            let f: &F = &*(f as *const F);
498            f(ListItem::from_glib_borrow(this).unsafe_cast_ref())
499        }
500        unsafe {
501            let f: Box_<F> = Box_::new(f);
502            connect_raw(
503                self.as_ptr() as *mut _,
504                b"notify::focusable\0".as_ptr() as *const _,
505                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
506                    notify_focusable_trampoline::<Self, F> as *const (),
507                )),
508                Box_::into_raw(f),
509            )
510        }
511    }
512
513    #[doc(alias = "item")]
514    fn connect_item_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
515        unsafe extern "C" fn notify_item_trampoline<P: IsA<ListItem>, F: Fn(&P) + 'static>(
516            this: *mut ffi::GtkListItem,
517            _param_spec: glib::ffi::gpointer,
518            f: glib::ffi::gpointer,
519        ) {
520            let f: &F = &*(f as *const F);
521            f(ListItem::from_glib_borrow(this).unsafe_cast_ref())
522        }
523        unsafe {
524            let f: Box_<F> = Box_::new(f);
525            connect_raw(
526                self.as_ptr() as *mut _,
527                b"notify::item\0".as_ptr() as *const _,
528                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
529                    notify_item_trampoline::<Self, F> as *const (),
530                )),
531                Box_::into_raw(f),
532            )
533        }
534    }
535
536    #[doc(alias = "position")]
537    fn connect_position_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
538        unsafe extern "C" fn notify_position_trampoline<P: IsA<ListItem>, F: Fn(&P) + 'static>(
539            this: *mut ffi::GtkListItem,
540            _param_spec: glib::ffi::gpointer,
541            f: glib::ffi::gpointer,
542        ) {
543            let f: &F = &*(f as *const F);
544            f(ListItem::from_glib_borrow(this).unsafe_cast_ref())
545        }
546        unsafe {
547            let f: Box_<F> = Box_::new(f);
548            connect_raw(
549                self.as_ptr() as *mut _,
550                b"notify::position\0".as_ptr() as *const _,
551                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
552                    notify_position_trampoline::<Self, F> as *const (),
553                )),
554                Box_::into_raw(f),
555            )
556        }
557    }
558
559    #[doc(alias = "selectable")]
560    fn connect_selectable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
561        unsafe extern "C" fn notify_selectable_trampoline<P: IsA<ListItem>, F: Fn(&P) + 'static>(
562            this: *mut ffi::GtkListItem,
563            _param_spec: glib::ffi::gpointer,
564            f: glib::ffi::gpointer,
565        ) {
566            let f: &F = &*(f as *const F);
567            f(ListItem::from_glib_borrow(this).unsafe_cast_ref())
568        }
569        unsafe {
570            let f: Box_<F> = Box_::new(f);
571            connect_raw(
572                self.as_ptr() as *mut _,
573                b"notify::selectable\0".as_ptr() as *const _,
574                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
575                    notify_selectable_trampoline::<Self, F> as *const (),
576                )),
577                Box_::into_raw(f),
578            )
579        }
580    }
581
582    #[doc(alias = "selected")]
583    fn connect_selected_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
584        unsafe extern "C" fn notify_selected_trampoline<P: IsA<ListItem>, F: Fn(&P) + 'static>(
585            this: *mut ffi::GtkListItem,
586            _param_spec: glib::ffi::gpointer,
587            f: glib::ffi::gpointer,
588        ) {
589            let f: &F = &*(f as *const F);
590            f(ListItem::from_glib_borrow(this).unsafe_cast_ref())
591        }
592        unsafe {
593            let f: Box_<F> = Box_::new(f);
594            connect_raw(
595                self.as_ptr() as *mut _,
596                b"notify::selected\0".as_ptr() as *const _,
597                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
598                    notify_selected_trampoline::<Self, F> as *const (),
599                )),
600                Box_::into_raw(f),
601            )
602        }
603    }
604}
605
606impl<O: IsA<ListItem>> ListItemExt for O {}