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
25mod sealed {
26    pub trait Sealed {}
27    impl<T: super::IsA<super::TreeModelFilter>> Sealed for T {}
28}
29
30// rustdoc-stripper-ignore-next
31/// Trait containing manually implemented methods of
32/// [`TreeModelFilter`](crate::TreeModelFilter).
33#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
34#[allow(deprecated)]
35pub trait TreeModelFilterExtManual: sealed::Sealed + IsA<TreeModelFilter> + 'static {
36    /// With the @n_columns and @types parameters, you give an array of column
37    /// types for this model (which will be exposed to the parent model/view).
38    /// The @func, @data and @destroy parameters are for specifying the modify
39    /// function. The modify function will get called for each
40    /// data access, the goal of the modify function is to return the data which
41    /// should be displayed at the location specified using the parameters of the
42    /// modify function.
43    ///
44    /// Note that gtk_tree_model_filter_set_modify_func()
45    /// can only be called once for a given filter model.
46    ///
47    /// # Deprecated since 4.10
48    ///
49    /// ## `types`
50    /// The `GType`s of the columns.
51    /// ## `func`
52    /// A `GtkTreeModelFilterModifyFunc`
53    #[doc(alias = "gtk_tree_model_filter_set_modify_func")]
54    fn set_modify_func<F: Fn(&TreeModel, &TreeIter, i32) -> glib::Value + 'static>(
55        &self,
56        types: &[glib::Type],
57        func: F,
58    ) {
59        unsafe {
60            let types_ptr: Vec<glib::ffi::GType> = types.iter().map(|t| t.into_glib()).collect();
61
62            unsafe extern "C" fn func_trampoline<
63                F: Fn(&TreeModel, &TreeIter, i32) -> glib::Value + 'static,
64            >(
65                model: *mut ffi::GtkTreeModel,
66                iter: *mut ffi::GtkTreeIter,
67                value: *mut glib::gobject_ffi::GValue,
68                column: i32,
69                user_data: glib::ffi::gpointer,
70            ) {
71                let f: &F = &*(user_data as *const F);
72                let ret = f(&from_glib_borrow(model), &from_glib_borrow(iter), column);
73                *value = ret.into_raw();
74            }
75
76            unsafe extern "C" fn destroy_func<
77                F: Fn(&TreeModel, &TreeIter, i32) -> glib::Value + 'static,
78            >(
79                user_data: glib::ffi::gpointer,
80            ) {
81                let _callback: Box_<Option<Box_<F>>> = Box_::from_raw(user_data as *mut _);
82            }
83            let callback_data: Box_<F> = Box_::new(func);
84
85            ffi::gtk_tree_model_filter_set_modify_func(
86                self.as_ref().to_glib_none().0,
87                types.len() as i32,
88                mut_override(types_ptr.as_ptr()),
89                Some(func_trampoline::<F> as _),
90                Box_::into_raw(callback_data) as *mut _,
91                Some(destroy_func::<F> as _),
92            )
93        }
94    }
95}
96
97impl<O: IsA<TreeModelFilter>> TreeModelFilterExtManual for O {}