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