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