gtk/auto/tree_sortable.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::TreeModel;
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::{boxed::Box as Box_, fmt, mem::transmute};
12
13glib::wrapper! {
14 /// [`TreeSortable`][crate::TreeSortable] is an interface to be implemented by tree models which
15 /// support sorting. The [`TreeView`][crate::TreeView] uses the methods provided by this interface
16 /// to sort the model.
17 ///
18 /// ## Signals
19 ///
20 ///
21 /// #### `sort-column-changed`
22 /// The ::sort-column-changed signal is emitted when the sort column
23 /// or sort order of `sortable` is changed. The signal is emitted before
24 /// the contents of `sortable` are resorted.
25 ///
26 ///
27 /// <details><summary><h4>TreeModel</h4></summary>
28 ///
29 ///
30 /// #### `row-changed`
31 /// This signal is emitted when a row in the model has changed.
32 ///
33 ///
34 ///
35 ///
36 /// #### `row-deleted`
37 /// This signal is emitted when a row has been deleted.
38 ///
39 /// Note that no iterator is passed to the signal handler,
40 /// since the row is already deleted.
41 ///
42 /// This should be called by models after a row has been removed.
43 /// The location pointed to by `path` should be the location that
44 /// the row previously was at. It may not be a valid location anymore.
45 ///
46 ///
47 ///
48 ///
49 /// #### `row-has-child-toggled`
50 /// This signal is emitted when a row has gotten the first child
51 /// row or lost its last child row.
52 ///
53 ///
54 ///
55 ///
56 /// #### `row-inserted`
57 /// This signal is emitted when a new row has been inserted in
58 /// the model.
59 ///
60 /// Note that the row may still be empty at this point, since
61 /// it is a common pattern to first insert an empty row, and
62 /// then fill it with the desired values.
63 ///
64 ///
65 ///
66 ///
67 /// #### `rows-reordered`
68 /// This signal is emitted when the children of a node in the
69 /// [`TreeModel`][crate::TreeModel] have been reordered.
70 ///
71 /// Note that this signal is not emitted
72 /// when rows are reordered by DND, since this is implemented
73 /// by removing and then reinserting the row.
74 ///
75 ///
76 /// </details>
77 ///
78 /// # Implements
79 ///
80 /// [`TreeSortableExt`][trait@crate::prelude::TreeSortableExt], [`TreeModelExt`][trait@crate::prelude::TreeModelExt], [`TreeSortableExtManual`][trait@crate::prelude::TreeSortableExtManual]
81 #[doc(alias = "GtkTreeSortable")]
82 pub struct TreeSortable(Interface<ffi::GtkTreeSortable, ffi::GtkTreeSortableIface>) @requires TreeModel;
83
84 match fn {
85 type_ => || ffi::gtk_tree_sortable_get_type(),
86 }
87}
88
89impl TreeSortable {
90 pub const NONE: Option<&'static TreeSortable> = None;
91}
92
93mod sealed {
94 pub trait Sealed {}
95 impl<T: super::IsA<super::TreeSortable>> Sealed for T {}
96}
97
98/// Trait containing all [`struct@TreeSortable`] methods.
99///
100/// # Implementors
101///
102/// [`ListStore`][struct@crate::ListStore], [`TreeModelSort`][struct@crate::TreeModelSort], [`TreeSortable`][struct@crate::TreeSortable], [`TreeStore`][struct@crate::TreeStore]
103pub trait TreeSortableExt: IsA<TreeSortable> + sealed::Sealed + 'static {
104 /// Returns [`true`] if the model has a default sort function. This is used
105 /// primarily by GtkTreeViewColumns in order to determine if a model can
106 /// go back to the default state, or not.
107 ///
108 /// # Returns
109 ///
110 /// [`true`], if the model has a default sort function
111 #[doc(alias = "gtk_tree_sortable_has_default_sort_func")]
112 fn has_default_sort_func(&self) -> bool {
113 unsafe {
114 from_glib(ffi::gtk_tree_sortable_has_default_sort_func(
115 self.as_ref().to_glib_none().0,
116 ))
117 }
118 }
119
120 /// Emits a [`sort-column-changed`][struct@crate::TreeSortable#sort-column-changed] signal on `self`.
121 #[doc(alias = "gtk_tree_sortable_sort_column_changed")]
122 fn sort_column_changed(&self) {
123 unsafe {
124 ffi::gtk_tree_sortable_sort_column_changed(self.as_ref().to_glib_none().0);
125 }
126 }
127
128 /// The ::sort-column-changed signal is emitted when the sort column
129 /// or sort order of `sortable` is changed. The signal is emitted before
130 /// the contents of `sortable` are resorted.
131 #[doc(alias = "sort-column-changed")]
132 fn connect_sort_column_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
133 unsafe extern "C" fn sort_column_changed_trampoline<
134 P: IsA<TreeSortable>,
135 F: Fn(&P) + 'static,
136 >(
137 this: *mut ffi::GtkTreeSortable,
138 f: glib::ffi::gpointer,
139 ) {
140 let f: &F = &*(f as *const F);
141 f(TreeSortable::from_glib_borrow(this).unsafe_cast_ref())
142 }
143 unsafe {
144 let f: Box_<F> = Box_::new(f);
145 connect_raw(
146 self.as_ptr() as *mut _,
147 b"sort-column-changed\0".as_ptr() as *const _,
148 Some(transmute::<_, unsafe extern "C" fn()>(
149 sort_column_changed_trampoline::<Self, F> as *const (),
150 )),
151 Box_::into_raw(f),
152 )
153 }
154 }
155}
156
157impl<O: IsA<TreeSortable>> TreeSortableExt for O {}
158
159impl fmt::Display for TreeSortable {
160 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
161 f.write_str("TreeSortable")
162 }
163}