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