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