gtk4/auto/
no_selection.rs
1#[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 = "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 #[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 #[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 #[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}