gtk4/auto/section_model.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;
6use glib::{
7 object::ObjectType as _,
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 /// An interface that adds support for sections to list models.
16 ///
17 /// A [`SectionModel`][crate::SectionModel] groups successive items into so-called sections. List widgets
18 /// like [`ListView`][crate::ListView] and [`GridView`][crate::GridView] then allow displaying section headers for
19 /// these sections by installing a header factory.
20 ///
21 /// Many GTK list models support sections inherently, or they pass through the sections
22 /// of a model they are wrapping.
23 ///
24 /// When the section groupings of a model change, the model will emit the
25 /// [`sections-changed`][struct@crate::SectionModel#sections-changed] signal by calling the
26 /// [`SectionModelExt::sections_changed()`][crate::prelude::SectionModelExt::sections_changed()] function. All sections in the given range
27 /// then need to be queried again.
28 /// The [`items-changed`][struct@crate::gio::ListModel#items-changed] signal has the same effect, all sections in
29 /// that range are invalidated, too.
30 ///
31 /// ## Signals
32 ///
33 ///
34 /// #### `sections-changed`
35 /// Emitted when the start-of-section state of some of the items in @model changes.
36 ///
37 /// Note that this signal does not specify the new section state of the
38 /// items, they need to be queried manually. It is also not necessary for
39 /// a model to change the section state of any of the items in the section
40 /// model, though it would be rather useless to emit such a signal.
41 ///
42 /// The [`items-changed`][struct@crate::gio::ListModel#items-changed] implies the effect of the
43 /// [`sections-changed`][struct@crate::SectionModel#sections-changed] signal for all the items
44 /// it covers.
45 ///
46 ///
47 /// <details><summary><h4>ListModel</h4></summary>
48 ///
49 ///
50 /// #### `items-changed`
51 /// This signal is emitted whenever items were added to or removed
52 /// from @list. At @position, @removed items were removed and @added
53 /// items were added in their place.
54 ///
55 /// Note: If `removed != added`, the positions of all later items
56 /// in the model change.
57 ///
58 ///
59 /// </details>
60 ///
61 /// # Implements
62 ///
63 /// [`SectionModelExt`][trait@crate::prelude::SectionModelExt], [`trait@gio::prelude::ListModelExt`]
64 #[doc(alias = "GtkSectionModel")]
65 pub struct SectionModel(Interface<ffi::GtkSectionModel, ffi::GtkSectionModelInterface>) @requires gio::ListModel;
66
67 match fn {
68 type_ => || ffi::gtk_section_model_get_type(),
69 }
70}
71
72impl SectionModel {
73 pub const NONE: Option<&'static SectionModel> = None;
74}
75
76/// Trait containing all [`struct@SectionModel`] methods.
77///
78/// # Implementors
79///
80/// [`FilterListModel`][struct@crate::FilterListModel], [`FlattenListModel`][struct@crate::FlattenListModel], [`MapListModel`][struct@crate::MapListModel], [`MultiSelection`][struct@crate::MultiSelection], [`NoSelection`][struct@crate::NoSelection], [`SectionModel`][struct@crate::SectionModel], [`SingleSelection`][struct@crate::SingleSelection], [`SliceListModel`][struct@crate::SliceListModel], [`SortListModel`][struct@crate::SortListModel]
81pub trait SectionModelExt: IsA<SectionModel> + 'static {
82 /// Query the section that covers the given position. The number of
83 /// items in the section can be computed by `out_end - out_start`.
84 ///
85 /// If the position is larger than the number of items, a single
86 /// range from n_items to G_MAXUINT will be returned.
87 /// ## `position`
88 /// the position of the item to query
89 ///
90 /// # Returns
91 ///
92 ///
93 /// ## `out_start`
94 /// the position of the first item in the section
95 ///
96 /// ## `out_end`
97 /// the position of the first item not part of the section
98 /// anymore.
99 #[doc(alias = "gtk_section_model_get_section")]
100 #[doc(alias = "get_section")]
101 fn section(&self, position: u32) -> (u32, u32) {
102 unsafe {
103 let mut out_start = std::mem::MaybeUninit::uninit();
104 let mut out_end = std::mem::MaybeUninit::uninit();
105 ffi::gtk_section_model_get_section(
106 self.as_ref().to_glib_none().0,
107 position,
108 out_start.as_mut_ptr(),
109 out_end.as_mut_ptr(),
110 );
111 (out_start.assume_init(), out_end.assume_init())
112 }
113 }
114
115 /// This function emits the [`sections-changed`][struct@crate::SectionModel#sections-changed]
116 /// signal to notify about changes to sections.
117 ///
118 /// It must cover all positions that used to be a section start or that
119 /// are now a section start. It does not have to cover all positions for
120 /// which the section has changed.
121 ///
122 /// The [`items-changed`][struct@crate::gio::ListModel#items-changed] implies the effect of the
123 /// [`sections-changed`][struct@crate::SectionModel#sections-changed] signal for all the items
124 /// it covers.
125 ///
126 /// It is recommended that when changes to the items cause section changes
127 /// in a larger range, that the larger range is included in the emission
128 /// of the [`items-changed`][struct@crate::gio::ListModel#items-changed] instead of emitting
129 /// two signals.
130 /// ## `position`
131 /// the first changed item
132 /// ## `n_items`
133 /// the number of changed items
134 #[doc(alias = "gtk_section_model_sections_changed")]
135 fn sections_changed(&self, position: u32, n_items: u32) {
136 unsafe {
137 ffi::gtk_section_model_sections_changed(
138 self.as_ref().to_glib_none().0,
139 position,
140 n_items,
141 );
142 }
143 }
144
145 /// Emitted when the start-of-section state of some of the items in @model changes.
146 ///
147 /// Note that this signal does not specify the new section state of the
148 /// items, they need to be queried manually. It is also not necessary for
149 /// a model to change the section state of any of the items in the section
150 /// model, though it would be rather useless to emit such a signal.
151 ///
152 /// The [`items-changed`][struct@crate::gio::ListModel#items-changed] implies the effect of the
153 /// [`sections-changed`][struct@crate::SectionModel#sections-changed] signal for all the items
154 /// it covers.
155 /// ## `position`
156 /// The first item that may have changed
157 /// ## `n_items`
158 /// number of items with changes
159 #[cfg(feature = "v4_12")]
160 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
161 #[doc(alias = "sections-changed")]
162 fn connect_sections_changed<F: Fn(&Self, u32, u32) + 'static>(&self, f: F) -> SignalHandlerId {
163 unsafe extern "C" fn sections_changed_trampoline<
164 P: IsA<SectionModel>,
165 F: Fn(&P, u32, u32) + 'static,
166 >(
167 this: *mut ffi::GtkSectionModel,
168 position: std::ffi::c_uint,
169 n_items: std::ffi::c_uint,
170 f: glib::ffi::gpointer,
171 ) {
172 let f: &F = &*(f as *const F);
173 f(
174 SectionModel::from_glib_borrow(this).unsafe_cast_ref(),
175 position,
176 n_items,
177 )
178 }
179 unsafe {
180 let f: Box_<F> = Box_::new(f);
181 connect_raw(
182 self.as_ptr() as *mut _,
183 c"sections-changed".as_ptr() as *const _,
184 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
185 sections_changed_trampoline::<Self, F> as *const (),
186 )),
187 Box_::into_raw(f),
188 )
189 }
190 }
191}
192
193impl<O: IsA<SectionModel>> SectionModelExt for O {}