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 /// [`SectionModel`][crate::SectionModel] is 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
76mod sealed {
77 pub trait Sealed {}
78 impl<T: super::IsA<super::SectionModel>> Sealed for T {}
79}
80
81/// Trait containing all [`struct@SectionModel`] methods.
82///
83/// # Implementors
84///
85/// [`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]
86pub trait SectionModelExt: IsA<SectionModel> + sealed::Sealed + 'static {
87 /// Query the section that covers the given position. The number of
88 /// items in the section can be computed by `out_end - out_start`.
89 ///
90 /// If the position is larger than the number of items, a single
91 /// range from n_items to G_MAXUINT will be returned.
92 /// ## `position`
93 /// the position of the item to query
94 ///
95 /// # Returns
96 ///
97 ///
98 /// ## `out_start`
99 /// the position of the first item in the section
100 ///
101 /// ## `out_end`
102 /// the position of the first item not part of the section
103 /// anymore.
104 #[doc(alias = "gtk_section_model_get_section")]
105 #[doc(alias = "get_section")]
106 fn section(&self, position: u32) -> (u32, u32) {
107 unsafe {
108 let mut out_start = std::mem::MaybeUninit::uninit();
109 let mut out_end = std::mem::MaybeUninit::uninit();
110 ffi::gtk_section_model_get_section(
111 self.as_ref().to_glib_none().0,
112 position,
113 out_start.as_mut_ptr(),
114 out_end.as_mut_ptr(),
115 );
116 (out_start.assume_init(), out_end.assume_init())
117 }
118 }
119
120 /// This function emits the [`sections-changed`][struct@crate::SectionModel#sections-changed]
121 /// signal to notify about changes to sections.
122 ///
123 /// It must cover all positions that used to be a section start or that
124 /// are now a section start. It does not have to cover all positions for
125 /// which the section has changed.
126 ///
127 /// The [`items-changed`][struct@crate::gio::ListModel#items-changed] implies the effect of the
128 /// [`sections-changed`][struct@crate::SectionModel#sections-changed] signal for all the items
129 /// it covers.
130 ///
131 /// It is recommended that when changes to the items cause section changes
132 /// in a larger range, that the larger range is included in the emission
133 /// of the [`items-changed`][struct@crate::gio::ListModel#items-changed] instead of emitting
134 /// two signals.
135 /// ## `position`
136 /// the first changed item
137 /// ## `n_items`
138 /// the number of changed items
139 #[doc(alias = "gtk_section_model_sections_changed")]
140 fn sections_changed(&self, position: u32, n_items: u32) {
141 unsafe {
142 ffi::gtk_section_model_sections_changed(
143 self.as_ref().to_glib_none().0,
144 position,
145 n_items,
146 );
147 }
148 }
149
150 /// Emitted when the start-of-section state of some of the items in @model changes.
151 ///
152 /// Note that this signal does not specify the new section state of the
153 /// items, they need to be queried manually. It is also not necessary for
154 /// a model to change the section state of any of the items in the section
155 /// model, though it would be rather useless to emit such a signal.
156 ///
157 /// The [`items-changed`][struct@crate::gio::ListModel#items-changed] implies the effect of the
158 /// [`sections-changed`][struct@crate::SectionModel#sections-changed] signal for all the items
159 /// it covers.
160 /// ## `position`
161 /// The first item that may have changed
162 /// ## `n_items`
163 /// number of items with changes
164 #[cfg(feature = "v4_12")]
165 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
166 #[doc(alias = "sections-changed")]
167 fn connect_sections_changed<F: Fn(&Self, u32, u32) + 'static>(&self, f: F) -> SignalHandlerId {
168 unsafe extern "C" fn sections_changed_trampoline<
169 P: IsA<SectionModel>,
170 F: Fn(&P, u32, u32) + 'static,
171 >(
172 this: *mut ffi::GtkSectionModel,
173 position: std::ffi::c_uint,
174 n_items: std::ffi::c_uint,
175 f: glib::ffi::gpointer,
176 ) {
177 let f: &F = &*(f as *const F);
178 f(
179 SectionModel::from_glib_borrow(this).unsafe_cast_ref(),
180 position,
181 n_items,
182 )
183 }
184 unsafe {
185 let f: Box_<F> = Box_::new(f);
186 connect_raw(
187 self.as_ptr() as *mut _,
188 b"sections-changed\0".as_ptr() as *const _,
189 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
190 sections_changed_trampoline::<Self, F> as *const (),
191 )),
192 Box_::into_raw(f),
193 )
194 }
195 }
196}
197
198impl<O: IsA<SectionModel>> SectionModelExt for O {}