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