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

use crate::{prelude::*, ComboBox};
use glib::translate::*;

// rustdoc-stripper-ignore-next
/// Trait containing manually implemented methods of [`ComboBox`](crate::ComboBox).
#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
#[allow(deprecated)]
pub trait ComboBoxExtManual: 'static {
    #[doc(alias = "gtk_combo_box_set_row_separator_func")]
    #[doc(alias = "set_row_separator_func")]
    fn unset_row_separator_func(&self);

    /// Sets the active item of @self to be the item at @index.
    ///
    /// # Deprecated since 4.10
    ///
    /// Use [`DropDown`][crate::DropDown]
    /// ## `index_`
    /// An index in the model passed during construction,
    ///   or -1 to have no active item
    #[doc(alias = "gtk_combo_box_set_active")]
    fn set_active(&self, index_: Option<u32>);

    /// Returns the index of the currently active item.
    ///
    /// If the model is a non-flat treemodel, and the active item is not
    /// an immediate child of the root of the tree, this function returns
    /// `gtk_tree_path_get_indices (path)[0]`, where `path` is the
    /// [`TreePath`][crate::TreePath] of the active item.
    ///
    /// # Deprecated since 4.10
    ///
    /// Use [`DropDown`][crate::DropDown]
    ///
    /// # Returns
    ///
    /// An integer which is the index of the currently active item,
    ///   or -1 if there’s no active item
    #[doc(alias = "gtk_combo_box_get_active")]
    #[doc(alias = "get_active")]
    fn active(&self) -> Option<u32>;
}

impl<O: IsA<ComboBox>> ComboBoxExtManual for O {
    fn unset_row_separator_func(&self) {
        unsafe {
            ffi::gtk_combo_box_set_row_separator_func(
                self.as_ref().to_glib_none().0,
                None,
                std::ptr::null_mut(),
                None,
            );
        }
    }

    fn set_active(&self, index_: Option<u32>) {
        let index_ = match index_ {
            Some(i) => i as _,
            None => -1,
        };
        unsafe {
            ffi::gtk_combo_box_set_active(self.as_ref().to_glib_none().0, index_);
        }
    }

    fn active(&self) -> Option<u32> {
        match unsafe { ffi::gtk_combo_box_get_active(self.as_ref().to_glib_none().0) } {
            -1 => None,
            x => Some(x as _),
        }
    }
}