gtk4/auto/column_view_sorter.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, ColumnViewColumn, SortType, Sorter};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 /// [`ColumnViewSorter`][crate::ColumnViewSorter] is a sorter implementation that
15 /// is geared towards the needs of [`ColumnView`][crate::ColumnView].
16 ///
17 /// The sorter returned by [`ColumnView::sorter()`][crate::ColumnView::sorter()] is
18 /// a [`ColumnViewSorter`][crate::ColumnViewSorter].
19 ///
20 /// In column views, sorting can be configured by associating
21 /// sorters with columns, and users can invert sort order by clicking
22 /// on column headers. The API of [`ColumnViewSorter`][crate::ColumnViewSorter] is designed
23 /// to allow saving and restoring this configuration.
24 ///
25 /// If you are only interested in the primary sort column (i.e. the
26 /// column where a sort indicator is shown in the header), then
27 /// you can just look at [`primary-sort-column`][struct@crate::ColumnViewSorter#primary-sort-column]
28 /// and [`primary-sort-order`][struct@crate::ColumnViewSorter#primary-sort-order].
29 ///
30 /// If you want to store the full sort configuration, including
31 /// secondary sort columns that are used for tie breaking, then
32 /// you can use [`nth_sort_column()`][Self::nth_sort_column()].
33 /// To get notified about changes, use [`changed`][struct@crate::Sorter#changed].
34 ///
35 /// To restore a saved sort configuration on a [`ColumnView`][crate::ColumnView],
36 /// use code like:
37 ///
38 /// ```text
39 /// sorter = gtk_column_view_get_sorter (view);
40 /// for (i = gtk_column_view_sorter_get_n_sort_columns (sorter) - 1; i >= 0; i--)
41 /// {
42 /// column = gtk_column_view_sorter_get_nth_sort_column (sorter, i, &order);
43 /// gtk_column_view_sort_by_column (view, column, order);
44 /// }
45 /// ```
46 ///
47 /// ## Properties
48 ///
49 ///
50 /// #### `primary-sort-column`
51 /// The primary sort column.
52 ///
53 /// The primary sort column is the one that displays the triangle
54 /// in a column view header.
55 ///
56 /// Readable
57 ///
58 ///
59 /// #### `primary-sort-order`
60 /// The primary sort order.
61 ///
62 /// The primary sort order determines whether the triangle displayed
63 /// in the column view header of the primary sort column points upwards
64 /// or downwards.
65 ///
66 /// Readable
67 ///
68 /// # Implements
69 ///
70 /// [`SorterExt`][trait@crate::prelude::SorterExt], [`trait@glib::ObjectExt`]
71 #[doc(alias = "GtkColumnViewSorter")]
72 pub struct ColumnViewSorter(Object<ffi::GtkColumnViewSorter, ffi::GtkColumnViewSorterClass>) @extends Sorter;
73
74 match fn {
75 type_ => || ffi::gtk_column_view_sorter_get_type(),
76 }
77}
78
79impl ColumnViewSorter {
80 /// Returns the number of columns by which the sorter sorts.
81 ///
82 /// If the sorter of the primary sort column does not determine
83 /// a total order, then the secondary sorters are consulted to
84 /// break the ties.
85 ///
86 /// Use the [`changed`][struct@crate::Sorter#changed] signal to get notified
87 /// when the number of sort columns changes.
88 ///
89 /// # Returns
90 ///
91 /// the number of sort columns
92 #[doc(alias = "gtk_column_view_sorter_get_n_sort_columns")]
93 #[doc(alias = "get_n_sort_columns")]
94 pub fn n_sort_columns(&self) -> u32 {
95 unsafe { ffi::gtk_column_view_sorter_get_n_sort_columns(self.to_glib_none().0) }
96 }
97
98 /// Gets the @position'th sort column and its associated sort order.
99 ///
100 /// Use the [`changed`][struct@crate::Sorter#changed] signal to get notified
101 /// when sort columns change.
102 /// ## `position`
103 /// the position of the sort column to retrieve (0 for the
104 /// primary sort column)
105 ///
106 /// # Returns
107 ///
108 /// the @positions sort column
109 ///
110 /// ## `sort_order`
111 /// return location for the sort order
112 #[doc(alias = "gtk_column_view_sorter_get_nth_sort_column")]
113 #[doc(alias = "get_nth_sort_column")]
114 pub fn nth_sort_column(&self, position: u32) -> (Option<ColumnViewColumn>, SortType) {
115 unsafe {
116 let mut sort_order = std::mem::MaybeUninit::uninit();
117 let ret = from_glib_none(ffi::gtk_column_view_sorter_get_nth_sort_column(
118 self.to_glib_none().0,
119 position,
120 sort_order.as_mut_ptr(),
121 ));
122 (ret, from_glib(sort_order.assume_init()))
123 }
124 }
125
126 /// Returns the primary sort column.
127 ///
128 /// The primary sort column is the one that displays the triangle
129 /// in a column view header.
130 ///
131 /// # Returns
132 ///
133 /// the primary sort column
134 #[doc(alias = "gtk_column_view_sorter_get_primary_sort_column")]
135 #[doc(alias = "get_primary_sort_column")]
136 #[doc(alias = "primary-sort-column")]
137 pub fn primary_sort_column(&self) -> Option<ColumnViewColumn> {
138 unsafe {
139 from_glib_none(ffi::gtk_column_view_sorter_get_primary_sort_column(
140 self.to_glib_none().0,
141 ))
142 }
143 }
144
145 /// Returns the primary sort order.
146 ///
147 /// The primary sort order determines whether the triangle displayed
148 /// in the column view header of the primary sort column points upwards
149 /// or downwards.
150 ///
151 /// If there is no primary sort column, then this function returns
152 /// `GTK_SORT_ASCENDING`.
153 ///
154 /// # Returns
155 ///
156 /// the primary sort order
157 #[doc(alias = "gtk_column_view_sorter_get_primary_sort_order")]
158 #[doc(alias = "get_primary_sort_order")]
159 #[doc(alias = "primary-sort-order")]
160 pub fn primary_sort_order(&self) -> SortType {
161 unsafe {
162 from_glib(ffi::gtk_column_view_sorter_get_primary_sort_order(
163 self.to_glib_none().0,
164 ))
165 }
166 }
167
168 #[cfg(feature = "v4_10")]
169 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
170 #[doc(alias = "primary-sort-column")]
171 pub fn connect_primary_sort_column_notify<F: Fn(&Self) + 'static>(
172 &self,
173 f: F,
174 ) -> SignalHandlerId {
175 unsafe extern "C" fn notify_primary_sort_column_trampoline<
176 F: Fn(&ColumnViewSorter) + 'static,
177 >(
178 this: *mut ffi::GtkColumnViewSorter,
179 _param_spec: glib::ffi::gpointer,
180 f: glib::ffi::gpointer,
181 ) {
182 let f: &F = &*(f as *const F);
183 f(&from_glib_borrow(this))
184 }
185 unsafe {
186 let f: Box_<F> = Box_::new(f);
187 connect_raw(
188 self.as_ptr() as *mut _,
189 b"notify::primary-sort-column\0".as_ptr() as *const _,
190 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
191 notify_primary_sort_column_trampoline::<F> as *const (),
192 )),
193 Box_::into_raw(f),
194 )
195 }
196 }
197
198 #[cfg(feature = "v4_10")]
199 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
200 #[doc(alias = "primary-sort-order")]
201 pub fn connect_primary_sort_order_notify<F: Fn(&Self) + 'static>(
202 &self,
203 f: F,
204 ) -> SignalHandlerId {
205 unsafe extern "C" fn notify_primary_sort_order_trampoline<
206 F: Fn(&ColumnViewSorter) + 'static,
207 >(
208 this: *mut ffi::GtkColumnViewSorter,
209 _param_spec: glib::ffi::gpointer,
210 f: glib::ffi::gpointer,
211 ) {
212 let f: &F = &*(f as *const F);
213 f(&from_glib_borrow(this))
214 }
215 unsafe {
216 let f: Box_<F> = Box_::new(f);
217 connect_raw(
218 self.as_ptr() as *mut _,
219 b"notify::primary-sort-order\0".as_ptr() as *const _,
220 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
221 notify_primary_sort_order_trampoline::<F> as *const (),
222 )),
223 Box_::into_raw(f),
224 )
225 }
226 }
227}