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    #[doc(alias = "GtkMultiSelection")]
20    pub struct MultiSelection(Object<ffi::GtkMultiSelection, ffi::GtkMultiSelectionClass>) @implements gio::ListModel, SectionModel, SelectionModel;
21
22    match fn {
23        type_ => || ffi::gtk_multi_selection_get_type(),
24    }
25}
26
27#[cfg(not(any(feature = "v4_12")))]
28glib::wrapper! {
29    #[doc(alias = "GtkMultiSelection")]
30    pub struct MultiSelection(Object<ffi::GtkMultiSelection, ffi::GtkMultiSelectionClass>) @implements gio::ListModel, SelectionModel;
31
32    match fn {
33        type_ => || ffi::gtk_multi_selection_get_type(),
34    }
35}
36
37impl MultiSelection {
38    #[doc(alias = "gtk_multi_selection_new")]
39    pub fn new(model: Option<impl IsA<gio::ListModel>>) -> MultiSelection {
40        assert_initialized_main_thread!();
41        unsafe {
42            from_glib_full(ffi::gtk_multi_selection_new(
43                model.map(|p| p.upcast()).into_glib_ptr(),
44            ))
45        }
46    }
47
48    #[doc(alias = "gtk_multi_selection_get_model")]
49    #[doc(alias = "get_model")]
50    pub fn model(&self) -> Option<gio::ListModel> {
51        unsafe { from_glib_none(ffi::gtk_multi_selection_get_model(self.to_glib_none().0)) }
52    }
53
54    #[doc(alias = "gtk_multi_selection_set_model")]
55    #[doc(alias = "model")]
56    pub fn set_model(&self, model: Option<&impl IsA<gio::ListModel>>) {
57        unsafe {
58            ffi::gtk_multi_selection_set_model(
59                self.to_glib_none().0,
60                model.map(|p| p.as_ref()).to_glib_none().0,
61            );
62        }
63    }
64
65    #[doc(alias = "model")]
66    pub fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
67        unsafe extern "C" fn notify_model_trampoline<F: Fn(&MultiSelection) + 'static>(
68            this: *mut ffi::GtkMultiSelection,
69            _param_spec: glib::ffi::gpointer,
70            f: glib::ffi::gpointer,
71        ) {
72            let f: &F = &*(f as *const F);
73            f(&from_glib_borrow(this))
74        }
75        unsafe {
76            let f: Box_<F> = Box_::new(f);
77            connect_raw(
78                self.as_ptr() as *mut _,
79                b"notify::model\0".as_ptr() as *const _,
80                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
81                    notify_model_trampoline::<F> as *const (),
82                )),
83                Box_::into_raw(f),
84            )
85        }
86    }
87}