gtk4/
tree_model_filter.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Take a look at the license at the top of the repository in the LICENSE file.

use std::boxed::Box as Box_;

use glib::translate::*;

use crate::{ffi, prelude::*, TreeIter, TreeModel, TreeModelFilter, TreePath};

impl TreeModelFilter {
    #[doc(alias = "gtk_tree_model_filter_new")]
    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
    #[allow(deprecated)]
    pub fn new(child_model: &impl IsA<TreeModel>, root: Option<&TreePath>) -> Self {
        skip_assert_initialized!();
        unsafe {
            TreeModel::from_glib_none(ffi::gtk_tree_model_filter_new(
                child_model.as_ref().to_glib_none().0,
                mut_override(root.to_glib_none().0),
            ))
            .unsafe_cast()
        }
    }
}

// rustdoc-stripper-ignore-next
/// Trait containing manually implemented methods of
/// [`TreeModelFilter`](crate::TreeModelFilter).
#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
#[allow(deprecated)]
pub trait TreeModelFilterExtManual: IsA<TreeModelFilter> + 'static {
    /// With the @n_columns and @types parameters, you give an array of column
    /// types for this model (which will be exposed to the parent model/view).
    /// The @func, @data and @destroy parameters are for specifying the modify
    /// function. The modify function will get called for each
    /// data access, the goal of the modify function is to return the data which
    /// should be displayed at the location specified using the parameters of the
    /// modify function.
    ///
    /// Note that gtk_tree_model_filter_set_modify_func()
    /// can only be called once for a given filter model.
    ///
    /// # Deprecated since 4.10
    ///
    /// ## `types`
    /// The `GType`s of the columns.
    /// ## `func`
    /// A `GtkTreeModelFilterModifyFunc`
    #[doc(alias = "gtk_tree_model_filter_set_modify_func")]
    fn set_modify_func<F: Fn(&TreeModel, &TreeIter, i32) -> glib::Value + 'static>(
        &self,
        types: &[glib::Type],
        func: F,
    ) {
        unsafe {
            let types_ptr: Vec<glib::ffi::GType> = types.iter().map(|t| t.into_glib()).collect();

            unsafe extern "C" fn func_trampoline<
                F: Fn(&TreeModel, &TreeIter, i32) -> glib::Value + 'static,
            >(
                model: *mut ffi::GtkTreeModel,
                iter: *mut ffi::GtkTreeIter,
                value: *mut glib::gobject_ffi::GValue,
                column: i32,
                user_data: glib::ffi::gpointer,
            ) {
                let f: &F = &*(user_data as *const F);
                let ret = f(&from_glib_borrow(model), &from_glib_borrow(iter), column);
                *value = ret.into_raw();
            }

            unsafe extern "C" fn destroy_func<
                F: Fn(&TreeModel, &TreeIter, i32) -> glib::Value + 'static,
            >(
                user_data: glib::ffi::gpointer,
            ) {
                let _callback: Box_<Option<Box_<F>>> = Box_::from_raw(user_data as *mut _);
            }
            let callback_data: Box_<F> = Box_::new(func);

            ffi::gtk_tree_model_filter_set_modify_func(
                self.as_ref().to_glib_none().0,
                types.len() as i32,
                mut_override(types_ptr.as_ptr()),
                Some(func_trampoline::<F> as _),
                Box_::into_raw(callback_data) as *mut _,
                Some(destroy_func::<F> as _),
            )
        }
    }
}

impl<O: IsA<TreeModelFilter>> TreeModelFilterExtManual for O {}