1use crate::{ffi, PageOrientation, PaperSize, Unit};
6use glib::translate::*;
7
8glib::wrapper! {
9 #[doc(alias = "GtkPageSetup")]
10 pub struct PageSetup(Object<ffi::GtkPageSetup>);
11
12 match fn {
13 type_ => || ffi::gtk_page_setup_get_type(),
14 }
15}
16
17impl PageSetup {
18 #[doc(alias = "gtk_page_setup_new")]
19 pub fn new() -> PageSetup {
20 assert_initialized_main_thread!();
21 unsafe { from_glib_full(ffi::gtk_page_setup_new()) }
22 }
23
24 #[doc(alias = "gtk_page_setup_new_from_file")]
25 #[doc(alias = "new_from_file")]
26 pub fn from_file(file_name: impl AsRef<std::path::Path>) -> Result<PageSetup, glib::Error> {
27 assert_initialized_main_thread!();
28 unsafe {
29 let mut error = std::ptr::null_mut();
30 let ret =
31 ffi::gtk_page_setup_new_from_file(file_name.as_ref().to_glib_none().0, &mut error);
32 if error.is_null() {
33 Ok(from_glib_full(ret))
34 } else {
35 Err(from_glib_full(error))
36 }
37 }
38 }
39
40 #[doc(alias = "gtk_page_setup_new_from_gvariant")]
41 #[doc(alias = "new_from_gvariant")]
42 pub fn from_gvariant(variant: &glib::Variant) -> PageSetup {
43 assert_initialized_main_thread!();
44 unsafe {
45 from_glib_full(ffi::gtk_page_setup_new_from_gvariant(
46 variant.to_glib_none().0,
47 ))
48 }
49 }
50
51 #[doc(alias = "gtk_page_setup_new_from_key_file")]
52 #[doc(alias = "new_from_key_file")]
53 pub fn from_key_file(
54 key_file: &glib::KeyFile,
55 group_name: Option<&str>,
56 ) -> Result<PageSetup, glib::Error> {
57 assert_initialized_main_thread!();
58 unsafe {
59 let mut error = std::ptr::null_mut();
60 let ret = ffi::gtk_page_setup_new_from_key_file(
61 key_file.to_glib_none().0,
62 group_name.to_glib_none().0,
63 &mut error,
64 );
65 if error.is_null() {
66 Ok(from_glib_full(ret))
67 } else {
68 Err(from_glib_full(error))
69 }
70 }
71 }
72
73 #[doc(alias = "gtk_page_setup_copy")]
74 #[must_use]
75 pub fn copy(&self) -> PageSetup {
76 unsafe { from_glib_full(ffi::gtk_page_setup_copy(self.to_glib_none().0)) }
77 }
78
79 #[doc(alias = "gtk_page_setup_get_bottom_margin")]
80 #[doc(alias = "get_bottom_margin")]
81 pub fn bottom_margin(&self, unit: Unit) -> f64 {
82 unsafe { ffi::gtk_page_setup_get_bottom_margin(self.to_glib_none().0, unit.into_glib()) }
83 }
84
85 #[doc(alias = "gtk_page_setup_get_left_margin")]
86 #[doc(alias = "get_left_margin")]
87 pub fn left_margin(&self, unit: Unit) -> f64 {
88 unsafe { ffi::gtk_page_setup_get_left_margin(self.to_glib_none().0, unit.into_glib()) }
89 }
90
91 #[doc(alias = "gtk_page_setup_get_orientation")]
92 #[doc(alias = "get_orientation")]
93 pub fn orientation(&self) -> PageOrientation {
94 unsafe { from_glib(ffi::gtk_page_setup_get_orientation(self.to_glib_none().0)) }
95 }
96
97 #[doc(alias = "gtk_page_setup_get_page_height")]
98 #[doc(alias = "get_page_height")]
99 pub fn page_height(&self, unit: Unit) -> f64 {
100 unsafe { ffi::gtk_page_setup_get_page_height(self.to_glib_none().0, unit.into_glib()) }
101 }
102
103 #[doc(alias = "gtk_page_setup_get_page_width")]
104 #[doc(alias = "get_page_width")]
105 pub fn page_width(&self, unit: Unit) -> f64 {
106 unsafe { ffi::gtk_page_setup_get_page_width(self.to_glib_none().0, unit.into_glib()) }
107 }
108
109 #[doc(alias = "gtk_page_setup_get_paper_height")]
110 #[doc(alias = "get_paper_height")]
111 pub fn paper_height(&self, unit: Unit) -> f64 {
112 unsafe { ffi::gtk_page_setup_get_paper_height(self.to_glib_none().0, unit.into_glib()) }
113 }
114
115 #[doc(alias = "gtk_page_setup_get_paper_size")]
116 #[doc(alias = "get_paper_size")]
117 pub fn paper_size(&self) -> PaperSize {
118 unsafe { from_glib_none(ffi::gtk_page_setup_get_paper_size(self.to_glib_none().0)) }
119 }
120
121 #[doc(alias = "gtk_page_setup_get_paper_width")]
122 #[doc(alias = "get_paper_width")]
123 pub fn paper_width(&self, unit: Unit) -> f64 {
124 unsafe { ffi::gtk_page_setup_get_paper_width(self.to_glib_none().0, unit.into_glib()) }
125 }
126
127 #[doc(alias = "gtk_page_setup_get_right_margin")]
128 #[doc(alias = "get_right_margin")]
129 pub fn right_margin(&self, unit: Unit) -> f64 {
130 unsafe { ffi::gtk_page_setup_get_right_margin(self.to_glib_none().0, unit.into_glib()) }
131 }
132
133 #[doc(alias = "gtk_page_setup_get_top_margin")]
134 #[doc(alias = "get_top_margin")]
135 pub fn top_margin(&self, unit: Unit) -> f64 {
136 unsafe { ffi::gtk_page_setup_get_top_margin(self.to_glib_none().0, unit.into_glib()) }
137 }
138
139 #[doc(alias = "gtk_page_setup_load_file")]
140 pub fn load_file(&self, file_name: impl AsRef<std::path::Path>) -> Result<(), glib::Error> {
141 unsafe {
142 let mut error = std::ptr::null_mut();
143 let is_ok = ffi::gtk_page_setup_load_file(
144 self.to_glib_none().0,
145 file_name.as_ref().to_glib_none().0,
146 &mut error,
147 );
148 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
149 if error.is_null() {
150 Ok(())
151 } else {
152 Err(from_glib_full(error))
153 }
154 }
155 }
156
157 #[doc(alias = "gtk_page_setup_load_key_file")]
158 pub fn load_key_file(
159 &self,
160 key_file: &glib::KeyFile,
161 group_name: Option<&str>,
162 ) -> Result<(), glib::Error> {
163 unsafe {
164 let mut error = std::ptr::null_mut();
165 let is_ok = ffi::gtk_page_setup_load_key_file(
166 self.to_glib_none().0,
167 key_file.to_glib_none().0,
168 group_name.to_glib_none().0,
169 &mut error,
170 );
171 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
172 if error.is_null() {
173 Ok(())
174 } else {
175 Err(from_glib_full(error))
176 }
177 }
178 }
179
180 #[doc(alias = "gtk_page_setup_set_bottom_margin")]
181 pub fn set_bottom_margin(&self, margin: f64, unit: Unit) {
182 unsafe {
183 ffi::gtk_page_setup_set_bottom_margin(self.to_glib_none().0, margin, unit.into_glib());
184 }
185 }
186
187 #[doc(alias = "gtk_page_setup_set_left_margin")]
188 pub fn set_left_margin(&self, margin: f64, unit: Unit) {
189 unsafe {
190 ffi::gtk_page_setup_set_left_margin(self.to_glib_none().0, margin, unit.into_glib());
191 }
192 }
193
194 #[doc(alias = "gtk_page_setup_set_orientation")]
195 pub fn set_orientation(&self, orientation: PageOrientation) {
196 unsafe {
197 ffi::gtk_page_setup_set_orientation(self.to_glib_none().0, orientation.into_glib());
198 }
199 }
200
201 #[doc(alias = "gtk_page_setup_set_paper_size")]
202 pub fn set_paper_size(&self, size: &PaperSize) {
203 unsafe {
204 ffi::gtk_page_setup_set_paper_size(
205 self.to_glib_none().0,
206 mut_override(size.to_glib_none().0),
207 );
208 }
209 }
210
211 #[doc(alias = "gtk_page_setup_set_paper_size_and_default_margins")]
212 pub fn set_paper_size_and_default_margins(&self, size: &PaperSize) {
213 unsafe {
214 ffi::gtk_page_setup_set_paper_size_and_default_margins(
215 self.to_glib_none().0,
216 mut_override(size.to_glib_none().0),
217 );
218 }
219 }
220
221 #[doc(alias = "gtk_page_setup_set_right_margin")]
222 pub fn set_right_margin(&self, margin: f64, unit: Unit) {
223 unsafe {
224 ffi::gtk_page_setup_set_right_margin(self.to_glib_none().0, margin, unit.into_glib());
225 }
226 }
227
228 #[doc(alias = "gtk_page_setup_set_top_margin")]
229 pub fn set_top_margin(&self, margin: f64, unit: Unit) {
230 unsafe {
231 ffi::gtk_page_setup_set_top_margin(self.to_glib_none().0, margin, unit.into_glib());
232 }
233 }
234
235 #[doc(alias = "gtk_page_setup_to_file")]
236 pub fn to_file(&self, file_name: impl AsRef<std::path::Path>) -> Result<(), glib::Error> {
237 unsafe {
238 let mut error = std::ptr::null_mut();
239 let is_ok = ffi::gtk_page_setup_to_file(
240 self.to_glib_none().0,
241 file_name.as_ref().to_glib_none().0,
242 &mut error,
243 );
244 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
245 if error.is_null() {
246 Ok(())
247 } else {
248 Err(from_glib_full(error))
249 }
250 }
251 }
252
253 #[doc(alias = "gtk_page_setup_to_gvariant")]
254 pub fn to_gvariant(&self) -> glib::Variant {
255 unsafe { from_glib_none(ffi::gtk_page_setup_to_gvariant(self.to_glib_none().0)) }
256 }
257
258 #[doc(alias = "gtk_page_setup_to_key_file")]
259 pub fn to_key_file(&self, key_file: &glib::KeyFile, group_name: Option<&str>) {
260 unsafe {
261 ffi::gtk_page_setup_to_key_file(
262 self.to_glib_none().0,
263 key_file.to_glib_none().0,
264 group_name.to_glib_none().0,
265 );
266 }
267 }
268}
269
270impl Default for PageSetup {
271 fn default() -> Self {
272 Self::new()
273 }
274}