gtk4/auto/
no_selection.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
5#[cfg(feature = "v4_12")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
7use crate::SectionModel;
8use crate::{ffi, SelectionModel};
9use glib::{
10    prelude::*,
11    signal::{connect_raw, SignalHandlerId},
12    translate::*,
13};
14use std::boxed::Box as Box_;
15
16#[cfg(feature = "v4_12")]
17#[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
18glib::wrapper! {
19    /// [`NoSelection`][crate::NoSelection] is a [`SelectionModel`][crate::SelectionModel] that does not allow selecting
20    /// anything.
21    ///
22    /// This model is meant to be used as a simple wrapper around a `GListModel`
23    /// when a [`SelectionModel`][crate::SelectionModel] is required.
24    ///
25    /// [`NoSelection`][crate::NoSelection] passes through sections from the underlying model.
26    ///
27    /// ## Properties
28    ///
29    ///
30    /// #### `item-type`
31    ///  The type of items. See [`ListModelExtManual::item_type()`][crate::gio::prelude::ListModelExtManual::item_type()].
32    ///
33    /// Readable
34    ///
35    ///
36    /// #### `model`
37    ///  The model being managed.
38    ///
39    /// Readable | Writeable
40    ///
41    ///
42    /// #### `n-items`
43    ///  The number of items. See [`ListModelExtManual::n_items()`][crate::gio::prelude::ListModelExtManual::n_items()].
44    ///
45    /// Readable
46    ///
47    /// # Implements
48    ///
49    /// [`trait@glib::ObjectExt`], [`trait@gio::prelude::ListModelExt`], [`SectionModelExt`][trait@crate::prelude::SectionModelExt], [`SelectionModelExt`][trait@crate::prelude::SelectionModelExt]
50    #[doc(alias = "GtkNoSelection")]
51    pub struct NoSelection(Object<ffi::GtkNoSelection, ffi::GtkNoSelectionClass>) @implements gio::ListModel, SectionModel, SelectionModel;
52
53    match fn {
54        type_ => || ffi::gtk_no_selection_get_type(),
55    }
56}
57
58#[cfg(not(any(feature = "v4_12")))]
59glib::wrapper! {
60    #[doc(alias = "GtkNoSelection")]
61    pub struct NoSelection(Object<ffi::GtkNoSelection, ffi::GtkNoSelectionClass>) @implements gio::ListModel, SelectionModel;
62
63    match fn {
64        type_ => || ffi::gtk_no_selection_get_type(),
65    }
66}
67
68impl NoSelection {
69    /// Creates a new selection to handle @model.
70    /// ## `model`
71    /// the `GListModel` to manage
72    ///
73    /// # Returns
74    ///
75    /// a new [`NoSelection`][crate::NoSelection]
76    #[doc(alias = "gtk_no_selection_new")]
77    pub fn new(model: Option<impl IsA<gio::ListModel>>) -> NoSelection {
78        assert_initialized_main_thread!();
79        unsafe {
80            from_glib_full(ffi::gtk_no_selection_new(
81                model.map(|p| p.upcast()).into_glib_ptr(),
82            ))
83        }
84    }
85
86    /// Gets the model that @self is wrapping.
87    ///
88    /// # Returns
89    ///
90    /// The model being wrapped
91    #[doc(alias = "gtk_no_selection_get_model")]
92    #[doc(alias = "get_model")]
93    pub fn model(&self) -> Option<gio::ListModel> {
94        unsafe { from_glib_none(ffi::gtk_no_selection_get_model(self.to_glib_none().0)) }
95    }
96
97    /// Sets the model that @self should wrap.
98    ///
99    /// If @model is [`None`], this model will be empty.
100    /// ## `model`
101    /// A `GListModel` to wrap
102    #[doc(alias = "gtk_no_selection_set_model")]
103    #[doc(alias = "model")]
104    pub fn set_model(&self, model: Option<&impl IsA<gio::ListModel>>) {
105        unsafe {
106            ffi::gtk_no_selection_set_model(
107                self.to_glib_none().0,
108                model.map(|p| p.as_ref()).to_glib_none().0,
109            );
110        }
111    }
112
113    #[doc(alias = "model")]
114    pub fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
115        unsafe extern "C" fn notify_model_trampoline<F: Fn(&NoSelection) + 'static>(
116            this: *mut ffi::GtkNoSelection,
117            _param_spec: glib::ffi::gpointer,
118            f: glib::ffi::gpointer,
119        ) {
120            let f: &F = &*(f as *const F);
121            f(&from_glib_borrow(this))
122        }
123        unsafe {
124            let f: Box_<F> = Box_::new(f);
125            connect_raw(
126                self.as_ptr() as *mut _,
127                b"notify::model\0".as_ptr() as *const _,
128                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
129                    notify_model_trampoline::<F> as *const (),
130                )),
131                Box_::into_raw(f),
132            )
133        }
134    }
135}