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