gtk/
notebook.rs

1// Copyright 2013-2016, The Gtk-rs Project Developers.
2// See the COPYRIGHT file at the top-level directory of this distribution.
3// Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT>
4
5use glib::translate::*;
6use gtk_sys;
7use libc::c_int;
8use IsA;
9use Notebook;
10use Widget;
11
12pub trait NotebookExtManual: 'static {
13    fn append_page<T: IsA<Widget>, U: IsA<Widget>>(&self, child: &T, tab_label: Option<&U>) -> u32;
14
15    fn append_page_menu<T, U, V>(
16        &self,
17        child: &T,
18        tab_label: Option<&U>,
19        menu_label: Option<&V>,
20    ) -> u32
21    where
22        T: IsA<Widget>,
23        U: IsA<Widget>,
24        V: IsA<Widget>;
25
26    fn get_current_page(&self) -> Option<u32>;
27
28    fn get_n_pages(&self) -> u32;
29
30    fn get_nth_page(&self, page_num: Option<u32>) -> Option<Widget>;
31
32    fn insert_page<T, U>(&self, child: &T, tab_label: Option<&U>, position: Option<u32>) -> u32
33    where
34        T: IsA<Widget>,
35        U: IsA<Widget>;
36
37    fn insert_page_menu<T, U, V>(
38        &self,
39        child: &T,
40        tab_label: Option<&U>,
41        menu_label: Option<&V>,
42        position: Option<u32>,
43    ) -> u32
44    where
45        T: IsA<Widget>,
46        U: IsA<Widget>,
47        V: IsA<Widget>;
48
49    fn page_num<T: IsA<Widget>>(&self, child: &T) -> Option<u32>;
50
51    fn prepend_page<T, U>(&self, child: &T, tab_label: Option<&U>) -> u32
52    where
53        T: IsA<Widget>,
54        U: IsA<Widget>;
55
56    fn prepend_page_menu<T, U, V>(
57        &self,
58        child: &T,
59        tab_label: Option<&U>,
60        menu_label: Option<&V>,
61    ) -> u32
62    where
63        T: IsA<Widget>,
64        U: IsA<Widget>,
65        V: IsA<Widget>;
66
67    fn remove_page(&self, page_num: Option<u32>);
68
69    fn reorder_child<T: IsA<Widget>>(&self, child: &T, position: Option<u32>);
70
71    fn set_current_page(&self, page_num: Option<u32>);
72}
73
74impl<O: IsA<Notebook>> NotebookExtManual for O {
75    fn append_page<T: IsA<Widget>, U: IsA<Widget>>(&self, child: &T, tab_label: Option<&U>) -> u32 {
76        unsafe {
77            let ret = gtk_sys::gtk_notebook_append_page(
78                self.as_ref().to_glib_none().0,
79                child.as_ref().to_glib_none().0,
80                tab_label.map(|p| p.as_ref()).to_glib_none().0,
81            );
82            assert!(ret >= 0);
83            ret as u32
84        }
85    }
86
87    fn append_page_menu<T, U, V>(
88        &self,
89        child: &T,
90        tab_label: Option<&U>,
91        menu_label: Option<&V>,
92    ) -> u32
93    where
94        T: IsA<Widget>,
95        U: IsA<Widget>,
96        V: IsA<Widget>,
97    {
98        unsafe {
99            let ret = gtk_sys::gtk_notebook_append_page_menu(
100                self.as_ref().to_glib_none().0,
101                child.as_ref().to_glib_none().0,
102                tab_label.map(|p| p.as_ref()).to_glib_none().0,
103                menu_label.map(|p| p.as_ref()).to_glib_none().0,
104            );
105            assert!(ret >= 0);
106            ret as u32
107        }
108    }
109
110    fn get_current_page(&self) -> Option<u32> {
111        unsafe {
112            let ret = gtk_sys::gtk_notebook_get_current_page(self.as_ref().to_glib_none().0);
113            if ret >= 0 {
114                Some(ret as u32)
115            } else {
116                None
117            }
118        }
119    }
120
121    fn get_n_pages(&self) -> u32 {
122        unsafe {
123            let ret = gtk_sys::gtk_notebook_get_n_pages(self.as_ref().to_glib_none().0);
124            assert!(ret >= 0);
125            ret as u32
126        }
127    }
128
129    fn get_nth_page(&self, page_num: Option<u32>) -> Option<Widget> {
130        unsafe {
131            from_glib_none(gtk_sys::gtk_notebook_get_nth_page(
132                self.as_ref().to_glib_none().0,
133                page_num.map_or(-1, |n| n as c_int),
134            ))
135        }
136    }
137
138    fn insert_page<T, U>(&self, child: &T, tab_label: Option<&U>, position: Option<u32>) -> u32
139    where
140        T: IsA<Widget>,
141        U: IsA<Widget>,
142    {
143        unsafe {
144            let ret = gtk_sys::gtk_notebook_insert_page(
145                self.as_ref().to_glib_none().0,
146                child.as_ref().to_glib_none().0,
147                tab_label.map(|p| p.as_ref()).to_glib_none().0,
148                position.map_or(-1, |n| n as c_int),
149            );
150            assert!(ret >= 0);
151            ret as u32
152        }
153    }
154
155    fn insert_page_menu<T, U, V>(
156        &self,
157        child: &T,
158        tab_label: Option<&U>,
159        menu_label: Option<&V>,
160        position: Option<u32>,
161    ) -> u32
162    where
163        T: IsA<Widget>,
164        U: IsA<Widget>,
165        V: IsA<Widget>,
166    {
167        unsafe {
168            let ret = gtk_sys::gtk_notebook_insert_page_menu(
169                self.as_ref().to_glib_none().0,
170                child.as_ref().to_glib_none().0,
171                tab_label.map(|p| p.as_ref()).to_glib_none().0,
172                menu_label.map(|p| p.as_ref()).to_glib_none().0,
173                position.map_or(-1, |n| n as c_int),
174            );
175            assert!(ret >= 0);
176            ret as u32
177        }
178    }
179
180    fn page_num<T: IsA<Widget>>(&self, child: &T) -> Option<u32> {
181        unsafe {
182            let ret = gtk_sys::gtk_notebook_page_num(
183                self.as_ref().to_glib_none().0,
184                child.as_ref().to_glib_none().0,
185            );
186            if ret >= 0 {
187                Some(ret as u32)
188            } else {
189                None
190            }
191        }
192    }
193
194    fn prepend_page<T, U>(&self, child: &T, tab_label: Option<&U>) -> u32
195    where
196        T: IsA<Widget>,
197        U: IsA<Widget>,
198    {
199        unsafe {
200            let ret = gtk_sys::gtk_notebook_prepend_page(
201                self.as_ref().to_glib_none().0,
202                child.as_ref().to_glib_none().0,
203                tab_label.map(|p| p.as_ref()).to_glib_none().0,
204            );
205            assert!(ret >= 0);
206            ret as u32
207        }
208    }
209
210    fn prepend_page_menu<T, U, V>(
211        &self,
212        child: &T,
213        tab_label: Option<&U>,
214        menu_label: Option<&V>,
215    ) -> u32
216    where
217        T: IsA<Widget>,
218        U: IsA<Widget>,
219        V: IsA<Widget>,
220    {
221        unsafe {
222            let ret = gtk_sys::gtk_notebook_prepend_page_menu(
223                self.as_ref().to_glib_none().0,
224                child.as_ref().to_glib_none().0,
225                tab_label.map(|p| p.as_ref()).to_glib_none().0,
226                menu_label.map(|p| p.as_ref()).to_glib_none().0,
227            );
228            assert!(ret >= 0);
229            ret as u32
230        }
231    }
232
233    fn remove_page(&self, page_num: Option<u32>) {
234        unsafe {
235            gtk_sys::gtk_notebook_remove_page(
236                self.as_ref().to_glib_none().0,
237                page_num.map_or(-1, |n| n as c_int),
238            );
239        }
240    }
241
242    fn reorder_child<T: IsA<Widget>>(&self, child: &T, position: Option<u32>) {
243        unsafe {
244            gtk_sys::gtk_notebook_reorder_child(
245                self.as_ref().to_glib_none().0,
246                child.as_ref().to_glib_none().0,
247                position.map_or(-1, |n| n as c_int),
248            );
249        }
250    }
251
252    fn set_current_page(&self, page_num: Option<u32>) {
253        unsafe {
254            gtk_sys::gtk_notebook_set_current_page(
255                self.as_ref().to_glib_none().0,
256                page_num.map_or(-1, |n| n as c_int),
257            );
258        }
259    }
260}