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")]
51 pub struct NoSelection(Object<ffi::GtkNoSelection, ffi::GtkNoSelectionClass>) @implements gio::ListModel, SectionModel, SelectionModel;
52
53 match fn {
54 type_ => || ffi::gtk_no_selection_get_type(),
55 }
56}
57
58#[cfg(not(any(feature = "v4_12")))]
59glib::wrapper! {
60 #[doc(alias = "GtkNoSelection")]
61 pub struct NoSelection(Object<ffi::GtkNoSelection, ffi::GtkNoSelectionClass>) @implements gio::ListModel, SelectionModel;
62
63 match fn {
64 type_ => || ffi::gtk_no_selection_get_type(),
65 }
66}
67
68impl NoSelection {
69 #[doc(alias = "gtk_no_selection_new")]
77 pub fn new(model: Option<impl IsA<gio::ListModel>>) -> NoSelection {
78 assert_initialized_main_thread!();
79 unsafe {
80 from_glib_full(ffi::gtk_no_selection_new(
81 model.map(|p| p.upcast()).into_glib_ptr(),
82 ))
83 }
84 }
85
86 #[doc(alias = "gtk_no_selection_get_model")]
92 #[doc(alias = "get_model")]
93 pub fn model(&self) -> Option<gio::ListModel> {
94 unsafe { from_glib_none(ffi::gtk_no_selection_get_model(self.to_glib_none().0)) }
95 }
96
97 #[doc(alias = "gtk_no_selection_set_model")]
103 #[doc(alias = "model")]
104 pub fn set_model(&self, model: Option<&impl IsA<gio::ListModel>>) {
105 unsafe {
106 ffi::gtk_no_selection_set_model(
107 self.to_glib_none().0,
108 model.map(|p| p.as_ref()).to_glib_none().0,
109 );
110 }
111 }
112
113 #[doc(alias = "model")]
114 pub fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
115 unsafe extern "C" fn notify_model_trampoline<F: Fn(&NoSelection) + 'static>(
116 this: *mut ffi::GtkNoSelection,
117 _param_spec: glib::ffi::gpointer,
118 f: glib::ffi::gpointer,
119 ) {
120 let f: &F = &*(f as *const F);
121 f(&from_glib_borrow(this))
122 }
123 unsafe {
124 let f: Box_<F> = Box_::new(f);
125 connect_raw(
126 self.as_ptr() as *mut _,
127 b"notify::model\0".as_ptr() as *const _,
128 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
129 notify_model_trampoline::<F> as *const (),
130 )),
131 Box_::into_raw(f),
132 )
133 }
134 }
135}