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
// Take a look at the license at the top of the repository in the LICENSE file.

use crate::{prelude::*, TreeIter, TreeModel};
use glib::{translate::*, value::FromValue};

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::TreeModel>> Sealed for T {}
}

// rustdoc-stripper-ignore-next
/// Trait containing manually implemented methods of [`TreeModel`](crate::TreeModel).
#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
#[allow(deprecated)]
pub trait TreeModelExtManual: sealed::Sealed + IsA<TreeModel> + 'static {
    #[doc(alias = "gtk_tree_model_get")]
    #[doc(alias = "gtk_tree_model_get_value")]
    #[doc(alias = "gtk_tree_model_get_valist")]
    fn get_value(&self, iter: &TreeIter, column: i32) -> glib::Value {
        let total_columns = self.as_ref().n_columns();
        assert!(
            column < total_columns,
            "TreeModel has {total_columns} columns but TreeModelExt::get got {column} passed as a column number",
        );
        unsafe {
            let mut value = glib::Value::uninitialized();
            ffi::gtk_tree_model_get_value(
                self.as_ref().to_glib_none().0,
                mut_override(iter.to_glib_none().0),
                column,
                value.to_glib_none_mut().0,
            );
            value
        }
    }

    #[doc(alias = "gtk_tree_model_get")]
    #[doc(alias = "gtk_tree_model_get_value")]
    #[doc(alias = "gtk_tree_model_get_valist")]
    // rustdoc-stripper-ignore-next
    /// Similar to [`Self::get_value`] but panics if the value is of a different type.
    // rustdoc-stripper-ignore-next-stop
    /// Gets the value of one or more cells in the row referenced by @iter.
    ///
    /// The variable argument list should contain integer column numbers,
    /// each column number followed by a place to store the value being
    /// retrieved.  The list is terminated by a -1. For example, to get a
    /// value from column 0 with type `G_TYPE_STRING`, you would
    /// write: `gtk_tree_model_get (model, iter, 0, &place_string_here, -1)`,
    /// where `place_string_here` is a #gchararray
    /// to be filled with the string.
    ///
    /// Returned values with type `G_TYPE_OBJECT` have to be unreferenced,
    /// values with type `G_TYPE_STRING` or `G_TYPE_BOXED` have to be freed.
    /// Other values are passed by value.
    ///
    /// # Deprecated since 4.10
    ///
    /// ## `iter`
    /// a row in @self
    fn get<V: for<'b> FromValue<'b> + 'static>(&self, iter: &TreeIter, column: i32) -> V {
        let value = self.get_value(iter, column);
        value
            .get_owned::<V>()
            .expect("Failed to get TreeModel value")
    }
}

impl<O: IsA<TreeModel>> TreeModelExtManual for O {}