1 // This file was generated by gir (https://github.com/gtk-rs/gir)
2 // from gir-files (https://github.com/gtk-rs/gir-files)
3 // DO NOT EDIT
4 
5 use gio_sys;
6 #[cfg(any(feature = "v2_44", feature = "dox"))]
7 use glib;
8 #[cfg(any(feature = "v2_44", feature = "dox"))]
9 use glib::object::Cast;
10 #[cfg(any(feature = "v2_44", feature = "dox"))]
11 use glib::object::IsA;
12 use glib::translate::*;
13 #[cfg(any(feature = "v2_44", feature = "dox"))]
14 use glib::StaticType;
15 #[cfg(any(feature = "v2_44", feature = "dox"))]
16 use glib::ToValue;
17 use std::fmt;
18 use ListModel;
19 
20 glib_wrapper! {
21     pub struct ListStore(Object<gio_sys::GListStore, gio_sys::GListStoreClass, ListStoreClass>) @implements ListModel;
22 
23     match fn {
24         get_type => || gio_sys::g_list_store_get_type(),
25     }
26 }
27 
28 impl ListStore {
29     #[cfg(any(feature = "v2_44", feature = "dox"))]
new(item_type: glib::types::Type) -> ListStore30     pub fn new(item_type: glib::types::Type) -> ListStore {
31         unsafe { from_glib_full(gio_sys::g_list_store_new(item_type.to_glib())) }
32     }
33 }
34 
35 #[derive(Clone, Default)]
36 pub struct ListStoreBuilder {
37     #[cfg(any(feature = "v2_44", feature = "dox"))]
38     item_type: Option<glib::types::Type>,
39 }
40 
41 impl ListStoreBuilder {
new() -> Self42     pub fn new() -> Self {
43         Self::default()
44     }
45 
build(self) -> ListStore46     pub fn build(self) -> ListStore {
47         let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
48         #[cfg(any(feature = "v2_44", feature = "dox"))]
49         {
50             if let Some(ref item_type) = self.item_type {
51                 properties.push(("item-type", item_type));
52             }
53         }
54         glib::Object::new(ListStore::static_type(), &properties)
55             .expect("object new")
56             .downcast()
57             .expect("downcast")
58     }
59 
60     #[cfg(any(feature = "v2_44", feature = "dox"))]
item_type(mut self, item_type: glib::types::Type) -> Self61     pub fn item_type(mut self, item_type: glib::types::Type) -> Self {
62         self.item_type = Some(item_type);
63         self
64     }
65 }
66 
67 pub const NONE_LIST_STORE: Option<&ListStore> = None;
68 
69 pub trait ListStoreExt: 'static {
70     #[cfg(any(feature = "v2_44", feature = "dox"))]
append<P: IsA<glib::Object>>(&self, item: &P)71     fn append<P: IsA<glib::Object>>(&self, item: &P);
72 
73     #[cfg(any(feature = "v2_44", feature = "dox"))]
insert<P: IsA<glib::Object>>(&self, position: u32, item: &P)74     fn insert<P: IsA<glib::Object>>(&self, position: u32, item: &P);
75 
76     #[cfg(any(feature = "v2_44", feature = "dox"))]
remove(&self, position: u32)77     fn remove(&self, position: u32);
78 
79     #[cfg(any(feature = "v2_44", feature = "dox"))]
remove_all(&self)80     fn remove_all(&self);
81 
82     #[cfg(any(feature = "v2_44", feature = "dox"))]
splice(&self, position: u32, n_removals: u32, additions: &[glib::Object])83     fn splice(&self, position: u32, n_removals: u32, additions: &[glib::Object]);
84 }
85 
86 impl<O: IsA<ListStore>> ListStoreExt for O {
87     #[cfg(any(feature = "v2_44", feature = "dox"))]
append<P: IsA<glib::Object>>(&self, item: &P)88     fn append<P: IsA<glib::Object>>(&self, item: &P) {
89         unsafe {
90             gio_sys::g_list_store_append(
91                 self.as_ref().to_glib_none().0,
92                 item.as_ref().to_glib_none().0,
93             );
94         }
95     }
96 
97     #[cfg(any(feature = "v2_44", feature = "dox"))]
insert<P: IsA<glib::Object>>(&self, position: u32, item: &P)98     fn insert<P: IsA<glib::Object>>(&self, position: u32, item: &P) {
99         unsafe {
100             gio_sys::g_list_store_insert(
101                 self.as_ref().to_glib_none().0,
102                 position,
103                 item.as_ref().to_glib_none().0,
104             );
105         }
106     }
107 
108     #[cfg(any(feature = "v2_44", feature = "dox"))]
remove(&self, position: u32)109     fn remove(&self, position: u32) {
110         unsafe {
111             gio_sys::g_list_store_remove(self.as_ref().to_glib_none().0, position);
112         }
113     }
114 
115     #[cfg(any(feature = "v2_44", feature = "dox"))]
remove_all(&self)116     fn remove_all(&self) {
117         unsafe {
118             gio_sys::g_list_store_remove_all(self.as_ref().to_glib_none().0);
119         }
120     }
121 
122     #[cfg(any(feature = "v2_44", feature = "dox"))]
splice(&self, position: u32, n_removals: u32, additions: &[glib::Object])123     fn splice(&self, position: u32, n_removals: u32, additions: &[glib::Object]) {
124         let n_additions = additions.len() as u32;
125         unsafe {
126             gio_sys::g_list_store_splice(
127                 self.as_ref().to_glib_none().0,
128                 position,
129                 n_removals,
130                 additions.to_glib_none().0,
131                 n_additions,
132             );
133         }
134     }
135 }
136 
137 impl fmt::Display for ListStore {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result138     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
139         write!(f, "ListStore")
140     }
141 }
142