gtk4/
tree_model_filter.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::boxed::Box as Box_;
4
5use glib::translate::*;
6
7use crate::{ffi, prelude::*, TreeIter, TreeModel, TreeModelFilter, TreePath};
8
9impl TreeModelFilter {
10    #[doc(alias = "gtk_tree_model_filter_new")]
11    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
12    #[allow(deprecated)]
13    pub fn new(child_model: &impl IsA<TreeModel>, root: Option<&TreePath>) -> Self {
14        skip_assert_initialized!();
15        unsafe {
16            TreeModel::from_glib_none(ffi::gtk_tree_model_filter_new(
17                child_model.as_ref().to_glib_none().0,
18                mut_override(root.to_glib_none().0),
19            ))
20            .unsafe_cast()
21        }
22    }
23}
24
25// rustdoc-stripper-ignore-next
26/// Trait containing manually implemented methods of
27/// [`TreeModelFilter`](crate::TreeModelFilter).
28#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
29#[allow(deprecated)]
30pub trait TreeModelFilterExtManual: IsA<TreeModelFilter> + 'static {
31    /// With the @n_columns and @types parameters, you give an array of column
32    /// types for this model (which will be exposed to the parent model/view).
33    /// The @func, @data and @destroy parameters are for specifying the modify
34    /// function. The modify function will get called for each
35    /// data access, the goal of the modify function is to return the data which
36    /// should be displayed at the location specified using the parameters of the
37    /// modify function.
38    ///
39    /// Note that gtk_tree_model_filter_set_modify_func()
40    /// can only be called once for a given filter model.
41    ///
42    /// # Deprecated since 4.10
43    ///
44    /// ## `types`
45    /// The `GType`s of the columns.
46    /// ## `func`
47    /// A `GtkTreeModelFilterModifyFunc`
48    #[doc(alias = "gtk_tree_model_filter_set_modify_func")]
49    fn set_modify_func<F: Fn(&TreeModel, &TreeIter, i32) -> glib::Value + 'static>(
50        &self,
51        types: &[glib::Type],
52        func: F,
53    ) {
54        unsafe {
55            let types_ptr: Vec<glib::ffi::GType> = types.iter().map(|t| t.into_glib()).collect();
56
57            unsafe extern "C" fn func_trampoline<
58                F: Fn(&TreeModel, &TreeIter, i32) -> glib::Value + 'static,
59            >(
60                model: *mut ffi::GtkTreeModel,
61                iter: *mut ffi::GtkTreeIter,
62                value: *mut glib::gobject_ffi::GValue,
63                column: i32,
64                user_data: glib::ffi::gpointer,
65            ) {
66                let f: &F = &*(user_data as *const F);
67                let ret = f(&from_glib_borrow(model), &from_glib_borrow(iter), column);
68                *value = ret.into_raw();
69            }
70
71            unsafe extern "C" fn destroy_func<
72                F: Fn(&TreeModel, &TreeIter, i32) -> glib::Value + 'static,
73            >(
74                user_data: glib::ffi::gpointer,
75            ) {
76                let _callback: Box_<Option<Box_<F>>> = Box_::from_raw(user_data as *mut _);
77            }
78            let callback_data: Box_<F> = Box_::new(func);
79
80            ffi::gtk_tree_model_filter_set_modify_func(
81                self.as_ref().to_glib_none().0,
82                types.len() as i32,
83                mut_override(types_ptr.as_ptr()),
84                Some(func_trampoline::<F> as _),
85                Box_::into_raw(callback_data) as *mut _,
86                Some(destroy_func::<F> as _),
87            )
88        }
89    }
90}
91
92impl<O: IsA<TreeModelFilter>> TreeModelFilterExtManual for O {}