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::{ListItemFactory, ffi};
6#[cfg(feature = "v4_8")]
7#[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
8use glib::{
9 object::ObjectType as _,
10 signal::{SignalHandlerId, connect_raw},
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 unsafe {
166 let f: &F = &*(f as *const F);
167 f(&from_glib_borrow(this), &from_glib_borrow(object))
168 }
169 }
170 unsafe {
171 let f: Box_<F> = Box_::new(f);
172 connect_raw(
173 self.as_ptr() as *mut _,
174 c"bind".as_ptr() as *const _,
175 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
176 bind_trampoline::<F> as *const (),
177 )),
178 Box_::into_raw(f),
179 )
180 }
181 }
182
183 /// Emitted when a newly created listitem needs to be prepared for use.
184 ///
185 /// It is the first signal emitted for every listitem.
186 ///
187 /// The handler for this signal must call [`ListItemExt::set_child()`][crate::prelude::ListItemExt::set_child()]
188 /// to populate the listitem with widgets.
189 ///
190 /// The [`teardown`][struct@crate::SignalListItemFactory#teardown] signal is the opposite
191 /// of this signal and can be used to undo everything done in this signal.
192 /// ## `object`
193 /// the `GObject` to set up
194 #[cfg(feature = "v4_8")]
195 #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
196 #[doc(alias = "setup")]
197 pub fn connect_setup<F: Fn(&Self, &glib::Object) + 'static>(&self, f: F) -> SignalHandlerId {
198 unsafe extern "C" fn setup_trampoline<
199 F: Fn(&SignalListItemFactory, &glib::Object) + 'static,
200 >(
201 this: *mut ffi::GtkSignalListItemFactory,
202 object: *mut glib::gobject_ffi::GObject,
203 f: glib::ffi::gpointer,
204 ) {
205 unsafe {
206 let f: &F = &*(f as *const F);
207 f(&from_glib_borrow(this), &from_glib_borrow(object))
208 }
209 }
210 unsafe {
211 let f: Box_<F> = Box_::new(f);
212 connect_raw(
213 self.as_ptr() as *mut _,
214 c"setup".as_ptr() as *const _,
215 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
216 setup_trampoline::<F> as *const (),
217 )),
218 Box_::into_raw(f),
219 )
220 }
221 }
222
223 /// Emitted when an object is about to be destroyed.
224 ///
225 /// It is the last signal ever emitted for this @object.
226 ///
227 /// This signal is the opposite of the [`setup`][struct@crate::SignalListItemFactory#setup]
228 /// signal and should be used to undo everything done in that signal.
229 /// ## `object`
230 /// The `GObject` to tear down
231 #[cfg(feature = "v4_8")]
232 #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
233 #[doc(alias = "teardown")]
234 pub fn connect_teardown<F: Fn(&Self, &glib::Object) + 'static>(&self, f: F) -> SignalHandlerId {
235 unsafe extern "C" fn teardown_trampoline<
236 F: Fn(&SignalListItemFactory, &glib::Object) + 'static,
237 >(
238 this: *mut ffi::GtkSignalListItemFactory,
239 object: *mut glib::gobject_ffi::GObject,
240 f: glib::ffi::gpointer,
241 ) {
242 unsafe {
243 let f: &F = &*(f as *const F);
244 f(&from_glib_borrow(this), &from_glib_borrow(object))
245 }
246 }
247 unsafe {
248 let f: Box_<F> = Box_::new(f);
249 connect_raw(
250 self.as_ptr() as *mut _,
251 c"teardown".as_ptr() as *const _,
252 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
253 teardown_trampoline::<F> as *const (),
254 )),
255 Box_::into_raw(f),
256 )
257 }
258 }
259
260 /// Emitted when an object has been unbound from its item.
261 ///
262 /// This happens for example when a listitem was removed from use
263 /// in a list widget and its [`item`][struct@crate::ListItem#item] is about
264 /// to be unset.
265 ///
266 /// This signal is the opposite of the [`bind`][struct@crate::SignalListItemFactory#bind]
267 /// signal and should be used to undo everything done in that signal.
268 /// ## `object`
269 /// The `GObject` to unbind
270 #[cfg(feature = "v4_8")]
271 #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
272 #[doc(alias = "unbind")]
273 pub fn connect_unbind<F: Fn(&Self, &glib::Object) + 'static>(&self, f: F) -> SignalHandlerId {
274 unsafe extern "C" fn unbind_trampoline<
275 F: Fn(&SignalListItemFactory, &glib::Object) + 'static,
276 >(
277 this: *mut ffi::GtkSignalListItemFactory,
278 object: *mut glib::gobject_ffi::GObject,
279 f: glib::ffi::gpointer,
280 ) {
281 unsafe {
282 let f: &F = &*(f as *const F);
283 f(&from_glib_borrow(this), &from_glib_borrow(object))
284 }
285 }
286 unsafe {
287 let f: Box_<F> = Box_::new(f);
288 connect_raw(
289 self.as_ptr() as *mut _,
290 c"unbind".as_ptr() as *const _,
291 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
292 unbind_trampoline::<F> as *const (),
293 )),
294 Box_::into_raw(f),
295 )
296 }
297 }
298}
299
300impl Default for SignalListItemFactory {
301 fn default() -> Self {
302 Self::new()
303 }
304}