Skip to main content

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