gtk4/auto/signal_list_item_factory.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
5use crate::{ffi, ListItemFactory};
6#[cfg(feature = "v4_8")]
7#[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
8use glib::{
9 object::ObjectType as _,
10 signal::{connect_raw, SignalHandlerId},
11};
12use glib::{prelude::*, translate::*};
13#[cfg(feature = "v4_8")]
14#[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18 /// Emits signals to manage listitems.
19 ///
20 /// Signals are emitted for every listitem in the same order:
21 ///
22 /// 1. [`setup`][struct@crate::SignalListItemFactory#setup] is emitted to set up permanent
23 /// things on the listitem. This usually means constructing the widgets used in
24 /// the row and adding them to the listitem.
25 ///
26 /// 2. [`bind`][struct@crate::SignalListItemFactory#bind] is emitted to bind the item passed
27 /// via [`item`][struct@crate::ListItem#item] to the widgets that have been created in
28 /// step 1 or to add item-specific widgets. Signals are connected to listen to
29 /// changes - both to changes in the item to update the widgets or to changes
30 /// in the widgets to update the item. After this signal has been called, the
31 /// listitem may be shown in a list widget.
32 ///
33 /// 3. [`unbind`][struct@crate::SignalListItemFactory#unbind] is emitted to undo everything
34 /// done in step 2. Usually this means disconnecting signal handlers. Once this
35 /// signal has been called, the listitem will no longer be used in a list
36 /// widget.
37 ///
38 /// 4. [`bind`][struct@crate::SignalListItemFactory#bind] and
39 /// [`unbind`][struct@crate::SignalListItemFactory#unbind] may be emitted multiple times
40 /// again to bind the listitem for use with new items. By reusing listitems,
41 /// potentially costly setup can be avoided. However, it means code needs to
42 /// make sure to properly clean up the listitem in step 3 so that no information
43 /// from the previous use leaks into the next one.
44 ///
45 /// 5. [`teardown`][struct@crate::SignalListItemFactory#teardown] is emitted to allow undoing
46 /// the effects of [`setup`][struct@crate::SignalListItemFactory#setup]. After this signal
47 /// was emitted on a listitem, the listitem will be destroyed and not be used again.
48 ///
49 /// Note that during the signal emissions, changing properties on the listitems
50 /// passed will not trigger notify signals as the listitem's notifications are
51 /// frozen. See `GObject::Object::freeze_notify()`()] for details.
52 ///
53 /// For tracking changes in other properties in the listitem, the
54 /// ::notify signal is recommended. The signal can be connected in the
55 /// [`setup`][struct@crate::SignalListItemFactory#setup] signal and removed again during
56 /// [`teardown`][struct@crate::SignalListItemFactory#teardown].
57 ///
58 /// ## Signals
59 ///
60 ///
61 /// #### `bind`
62 /// Emitted when an object has been bound to an item.
63 ///
64 /// The handler for this signal must set
65 /// to populate the listitem with widgets.
66 ///
67 /// After this signal was emitted, the object might be shown in
68 /// a [`ListView`][crate::ListView] or other widget.
69 ///
70 /// The [`unbind`][struct@crate::SignalListItemFactory#unbind] signal is the
71 /// opposite of this signal and can be used to undo everything done
72 /// in this signal.
73 ///
74 ///
75 ///
76 ///
77 /// #### `setup`
78 /// Emitted when a newly created listitem needs to be prepared for use.
79 ///
80 /// It is the first signal emitted for every listitem.
81 ///
82 /// The handler for this signal must call [`ListItemExt::set_child()`][crate::prelude::ListItemExt::set_child()]
83 /// to populate the listitem with widgets.
84 ///
85 /// The [`teardown`][struct@crate::SignalListItemFactory#teardown] signal is the opposite
86 /// of this signal and can be used to undo everything done in this signal.
87 ///
88 ///
89 ///
90 ///
91 /// #### `teardown`
92 /// Emitted when an object is about to be destroyed.
93 ///
94 /// It is the last signal ever emitted for this @object.
95 ///
96 /// This signal is the opposite of the [`setup`][struct@crate::SignalListItemFactory#setup]
97 /// signal and should be used to undo everything done in that signal.
98 ///
99 ///
100 ///
101 ///
102 /// #### `unbind`
103 /// Emitted when an object has been unbound from its item.
104 ///
105 /// This happens for example when a listitem was removed from use
106 /// in a list widget and its [`item`][struct@crate::ListItem#item] is about
107 /// to be unset.
108 ///
109 /// This signal is the opposite of the [`bind`][struct@crate::SignalListItemFactory#bind]
110 /// signal and should be used to undo everything done in that signal.
111 ///
112 ///
113 ///
114 /// # Implements
115 ///
116 /// [`ListItemFactoryExt`][trait@crate::prelude::ListItemFactoryExt], [`trait@glib::ObjectExt`]
117 #[doc(alias = "GtkSignalListItemFactory")]
118 pub struct SignalListItemFactory(Object<ffi::GtkSignalListItemFactory, ffi::GtkSignalListItemFactoryClass>) @extends ListItemFactory;
119
120 match fn {
121 type_ => || ffi::gtk_signal_list_item_factory_get_type(),
122 }
123}
124
125impl SignalListItemFactory {
126 /// Creates a new [`SignalListItemFactory`][crate::SignalListItemFactory].
127 ///
128 /// You need to connect signal handlers before you use it.
129 ///
130 /// # Returns
131 ///
132 /// a new [`SignalListItemFactory`][crate::SignalListItemFactory]
133 #[doc(alias = "gtk_signal_list_item_factory_new")]
134 pub fn new() -> SignalListItemFactory {
135 assert_initialized_main_thread!();
136 unsafe {
137 ListItemFactory::from_glib_full(ffi::gtk_signal_list_item_factory_new()).unsafe_cast()
138 }
139 }
140
141 /// Emitted when an object has been bound to an item.
142 ///
143 /// The handler for this signal must set
144 /// to populate the listitem with widgets.
145 ///
146 /// After this signal was emitted, the object might be shown in
147 /// a [`ListView`][crate::ListView] or other widget.
148 ///
149 /// The [`unbind`][struct@crate::SignalListItemFactory#unbind] signal is the
150 /// opposite of this signal and can be used to undo everything done
151 /// in this signal.
152 /// ## `object`
153 /// The `GObject` to bind
154 #[cfg(feature = "v4_8")]
155 #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
156 #[doc(alias = "bind")]
157 pub fn connect_bind<F: Fn(&Self, &glib::Object) + 'static>(&self, f: F) -> SignalHandlerId {
158 unsafe extern "C" fn bind_trampoline<
159 F: Fn(&SignalListItemFactory, &glib::Object) + 'static,
160 >(
161 this: *mut ffi::GtkSignalListItemFactory,
162 object: *mut glib::gobject_ffi::GObject,
163 f: glib::ffi::gpointer,
164 ) {
165 let f: &F = &*(f as *const F);
166 f(&from_glib_borrow(this), &from_glib_borrow(object))
167 }
168 unsafe {
169 let f: Box_<F> = Box_::new(f);
170 connect_raw(
171 self.as_ptr() as *mut _,
172 c"bind".as_ptr() as *const _,
173 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
174 bind_trampoline::<F> as *const (),
175 )),
176 Box_::into_raw(f),
177 )
178 }
179 }
180
181 /// Emitted when a newly created listitem needs to be prepared for use.
182 ///
183 /// It is the first signal emitted for every listitem.
184 ///
185 /// The handler for this signal must call [`ListItemExt::set_child()`][crate::prelude::ListItemExt::set_child()]
186 /// to populate the listitem with widgets.
187 ///
188 /// The [`teardown`][struct@crate::SignalListItemFactory#teardown] signal is the opposite
189 /// of this signal and can be used to undo everything done in this signal.
190 /// ## `object`
191 /// the `GObject` to set up
192 #[cfg(feature = "v4_8")]
193 #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
194 #[doc(alias = "setup")]
195 pub fn connect_setup<F: Fn(&Self, &glib::Object) + 'static>(&self, f: F) -> SignalHandlerId {
196 unsafe extern "C" fn setup_trampoline<
197 F: Fn(&SignalListItemFactory, &glib::Object) + 'static,
198 >(
199 this: *mut ffi::GtkSignalListItemFactory,
200 object: *mut glib::gobject_ffi::GObject,
201 f: glib::ffi::gpointer,
202 ) {
203 let f: &F = &*(f as *const F);
204 f(&from_glib_borrow(this), &from_glib_borrow(object))
205 }
206 unsafe {
207 let f: Box_<F> = Box_::new(f);
208 connect_raw(
209 self.as_ptr() as *mut _,
210 c"setup".as_ptr() as *const _,
211 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
212 setup_trampoline::<F> as *const (),
213 )),
214 Box_::into_raw(f),
215 )
216 }
217 }
218
219 /// Emitted when an object is about to be destroyed.
220 ///
221 /// It is the last signal ever emitted for this @object.
222 ///
223 /// This signal is the opposite of the [`setup`][struct@crate::SignalListItemFactory#setup]
224 /// signal and should be used to undo everything done in that signal.
225 /// ## `object`
226 /// The `GObject` to tear down
227 #[cfg(feature = "v4_8")]
228 #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
229 #[doc(alias = "teardown")]
230 pub fn connect_teardown<F: Fn(&Self, &glib::Object) + 'static>(&self, f: F) -> SignalHandlerId {
231 unsafe extern "C" fn teardown_trampoline<
232 F: Fn(&SignalListItemFactory, &glib::Object) + 'static,
233 >(
234 this: *mut ffi::GtkSignalListItemFactory,
235 object: *mut glib::gobject_ffi::GObject,
236 f: glib::ffi::gpointer,
237 ) {
238 let f: &F = &*(f as *const F);
239 f(&from_glib_borrow(this), &from_glib_borrow(object))
240 }
241 unsafe {
242 let f: Box_<F> = Box_::new(f);
243 connect_raw(
244 self.as_ptr() as *mut _,
245 c"teardown".as_ptr() as *const _,
246 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
247 teardown_trampoline::<F> as *const (),
248 )),
249 Box_::into_raw(f),
250 )
251 }
252 }
253
254 /// Emitted when an object has been unbound from its item.
255 ///
256 /// This happens for example when a listitem was removed from use
257 /// in a list widget and its [`item`][struct@crate::ListItem#item] is about
258 /// to be unset.
259 ///
260 /// This signal is the opposite of the [`bind`][struct@crate::SignalListItemFactory#bind]
261 /// signal and should be used to undo everything done in that signal.
262 /// ## `object`
263 /// The `GObject` to unbind
264 #[cfg(feature = "v4_8")]
265 #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
266 #[doc(alias = "unbind")]
267 pub fn connect_unbind<F: Fn(&Self, &glib::Object) + 'static>(&self, f: F) -> SignalHandlerId {
268 unsafe extern "C" fn unbind_trampoline<
269 F: Fn(&SignalListItemFactory, &glib::Object) + 'static,
270 >(
271 this: *mut ffi::GtkSignalListItemFactory,
272 object: *mut glib::gobject_ffi::GObject,
273 f: glib::ffi::gpointer,
274 ) {
275 let f: &F = &*(f as *const F);
276 f(&from_glib_borrow(this), &from_glib_borrow(object))
277 }
278 unsafe {
279 let f: Box_<F> = Box_::new(f);
280 connect_raw(
281 self.as_ptr() as *mut _,
282 c"unbind".as_ptr() as *const _,
283 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
284 unbind_trampoline::<F> as *const (),
285 )),
286 Box_::into_raw(f),
287 )
288 }
289 }
290}
291
292impl Default for SignalListItemFactory {
293 fn default() -> Self {
294 Self::new()
295 }
296}