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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
use crate::{PageOrientation, PaperSize, Unit};
use glib::translate::*;
glib::wrapper! {
/// A [`PageSetup`][crate::PageSetup] object stores the page size, orientation and margins.
///
/// The idea is that you can get one of these from the page setup dialog
/// and then pass it to the [`PrintOperation`][crate::PrintOperation] when printing.
/// The benefit of splitting this out of the [`PrintSettings`][crate::PrintSettings] is that
/// these affect the actual layout of the page, and thus need to be set
/// long before user prints.
///
/// ## Margins
///
/// The margins specified in this object are the “print margins”, i.e. the
/// parts of the page that the printer cannot print on. These are different
/// from the layout margins that a word processor uses; they are typically
/// used to determine the minimal size for the layout margins.
///
/// To obtain a [`PageSetup`][crate::PageSetup] use [`new()`][Self::new()] to get the defaults,
/// or use [`print_run_page_setup_dialog()`][crate::print_run_page_setup_dialog()] to show the page setup dialog
/// and receive the resulting page setup.
///
/// ## A page setup dialog
///
/// **⚠️ The following code is in c ⚠️**
///
/// ```c
/// static GtkPrintSettings *settings = NULL;
/// static GtkPageSetup *page_setup = NULL;
///
/// static void
/// do_page_setup (void)
/// {
/// GtkPageSetup *new_page_setup;
///
/// if (settings == NULL)
/// settings = gtk_print_settings_new ();
///
/// new_page_setup = gtk_print_run_page_setup_dialog (GTK_WINDOW (main_window),
/// page_setup, settings);
///
/// if (page_setup)
/// g_object_unref (page_setup);
///
/// page_setup = new_page_setup;
/// }
/// ```
///
/// # Implements
///
/// [`trait@glib::ObjectExt`]
#[doc(alias = "GtkPageSetup")]
pub struct PageSetup(Object<ffi::GtkPageSetup>);
match fn {
type_ => || ffi::gtk_page_setup_get_type(),
}
}
impl PageSetup {
/// Creates a new [`PageSetup`][crate::PageSetup].
///
/// # Returns
///
/// a new [`PageSetup`][crate::PageSetup].
#[doc(alias = "gtk_page_setup_new")]
pub fn new() -> PageSetup {
assert_initialized_main_thread!();
unsafe { from_glib_full(ffi::gtk_page_setup_new()) }
}
/// Reads the page setup from the file @file_name.
///
/// Returns a new [`PageSetup`][crate::PageSetup] object with the restored
/// page setup, or [`None`] if an error occurred.
/// See [`to_file()`][Self::to_file()].
/// ## `file_name`
/// the filename to read the page setup from
///
/// # Returns
///
/// the restored [`PageSetup`][crate::PageSetup]
#[doc(alias = "gtk_page_setup_new_from_file")]
#[doc(alias = "new_from_file")]
pub fn from_file(file_name: impl AsRef<std::path::Path>) -> Result<PageSetup, glib::Error> {
assert_initialized_main_thread!();
unsafe {
let mut error = std::ptr::null_mut();
let ret =
ffi::gtk_page_setup_new_from_file(file_name.as_ref().to_glib_none().0, &mut error);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
/// Desrialize a page setup from an a{sv} variant.
///
/// The variant must be in the format produced by
/// [`to_gvariant()`][Self::to_gvariant()].
/// ## `variant`
/// an a{sv} `GVariant`
///
/// # Returns
///
/// a new [`PageSetup`][crate::PageSetup] object
#[doc(alias = "gtk_page_setup_new_from_gvariant")]
#[doc(alias = "new_from_gvariant")]
pub fn from_gvariant(variant: &glib::Variant) -> PageSetup {
assert_initialized_main_thread!();
unsafe {
from_glib_full(ffi::gtk_page_setup_new_from_gvariant(
variant.to_glib_none().0,
))
}
}
/// Reads the page setup from the group @group_name in the key file
/// @key_file.
///
/// Returns a new [`PageSetup`][crate::PageSetup] object with the restored
/// page setup, or [`None`] if an error occurred.
/// ## `key_file`
/// the `GKeyFile` to retrieve the page_setup from
/// ## `group_name`
/// the name of the group in the key_file to read
/// to use the default name “Page Setup”
///
/// # Returns
///
/// the restored [`PageSetup`][crate::PageSetup]
#[doc(alias = "gtk_page_setup_new_from_key_file")]
#[doc(alias = "new_from_key_file")]
pub fn from_key_file(
key_file: &glib::KeyFile,
group_name: Option<&str>,
) -> Result<PageSetup, glib::Error> {
assert_initialized_main_thread!();
unsafe {
let mut error = std::ptr::null_mut();
let ret = ffi::gtk_page_setup_new_from_key_file(
key_file.to_glib_none().0,
group_name.to_glib_none().0,
&mut error,
);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
#[doc(alias = "gtk_page_setup_copy")]
#[must_use]
pub fn copy(&self) -> PageSetup {
unsafe { from_glib_full(ffi::gtk_page_setup_copy(self.to_glib_none().0)) }
}
/// Gets the bottom margin in units of @unit.
/// ## `unit`
/// the unit for the return value
///
/// # Returns
///
/// the bottom margin
#[doc(alias = "gtk_page_setup_get_bottom_margin")]
#[doc(alias = "get_bottom_margin")]
pub fn bottom_margin(&self, unit: Unit) -> f64 {
unsafe { ffi::gtk_page_setup_get_bottom_margin(self.to_glib_none().0, unit.into_glib()) }
}
/// Gets the left margin in units of @unit.
/// ## `unit`
/// the unit for the return value
///
/// # Returns
///
/// the left margin
#[doc(alias = "gtk_page_setup_get_left_margin")]
#[doc(alias = "get_left_margin")]
pub fn left_margin(&self, unit: Unit) -> f64 {
unsafe { ffi::gtk_page_setup_get_left_margin(self.to_glib_none().0, unit.into_glib()) }
}
/// Gets the page orientation of the [`PageSetup`][crate::PageSetup].
///
/// # Returns
///
/// the page orientation
#[doc(alias = "gtk_page_setup_get_orientation")]
#[doc(alias = "get_orientation")]
pub fn orientation(&self) -> PageOrientation {
unsafe { from_glib(ffi::gtk_page_setup_get_orientation(self.to_glib_none().0)) }
}
/// Returns the page height in units of @unit.
///
/// Note that this function takes orientation
/// and margins into consideration.
/// See [`paper_height()`][Self::paper_height()].
/// ## `unit`
/// the unit for the return value
///
/// # Returns
///
/// the page height.
#[doc(alias = "gtk_page_setup_get_page_height")]
#[doc(alias = "get_page_height")]
pub fn page_height(&self, unit: Unit) -> f64 {
unsafe { ffi::gtk_page_setup_get_page_height(self.to_glib_none().0, unit.into_glib()) }
}
/// Returns the page width in units of @unit.
///
/// Note that this function takes orientation
/// and margins into consideration.
/// See [`paper_width()`][Self::paper_width()].
/// ## `unit`
/// the unit for the return value
///
/// # Returns
///
/// the page width.
#[doc(alias = "gtk_page_setup_get_page_width")]
#[doc(alias = "get_page_width")]
pub fn page_width(&self, unit: Unit) -> f64 {
unsafe { ffi::gtk_page_setup_get_page_width(self.to_glib_none().0, unit.into_glib()) }
}
/// Returns the paper height in units of @unit.
///
/// Note that this function takes orientation,
/// but not margins into consideration.
/// See [`page_height()`][Self::page_height()].
/// ## `unit`
/// the unit for the return value
///
/// # Returns
///
/// the paper height.
#[doc(alias = "gtk_page_setup_get_paper_height")]
#[doc(alias = "get_paper_height")]
pub fn paper_height(&self, unit: Unit) -> f64 {
unsafe { ffi::gtk_page_setup_get_paper_height(self.to_glib_none().0, unit.into_glib()) }
}
/// Gets the paper size of the [`PageSetup`][crate::PageSetup].
///
/// # Returns
///
/// the paper size
#[doc(alias = "gtk_page_setup_get_paper_size")]
#[doc(alias = "get_paper_size")]
pub fn paper_size(&self) -> PaperSize {
unsafe { from_glib_none(ffi::gtk_page_setup_get_paper_size(self.to_glib_none().0)) }
}
/// Returns the paper width in units of @unit.
///
/// Note that this function takes orientation,
/// but not margins into consideration.
/// See [`page_width()`][Self::page_width()].
/// ## `unit`
/// the unit for the return value
///
/// # Returns
///
/// the paper width.
#[doc(alias = "gtk_page_setup_get_paper_width")]
#[doc(alias = "get_paper_width")]
pub fn paper_width(&self, unit: Unit) -> f64 {
unsafe { ffi::gtk_page_setup_get_paper_width(self.to_glib_none().0, unit.into_glib()) }
}
/// Gets the right margin in units of @unit.
/// ## `unit`
/// the unit for the return value
///
/// # Returns
///
/// the right margin
#[doc(alias = "gtk_page_setup_get_right_margin")]
#[doc(alias = "get_right_margin")]
pub fn right_margin(&self, unit: Unit) -> f64 {
unsafe { ffi::gtk_page_setup_get_right_margin(self.to_glib_none().0, unit.into_glib()) }
}
/// Gets the top margin in units of @unit.
/// ## `unit`
/// the unit for the return value
///
/// # Returns
///
/// the top margin
#[doc(alias = "gtk_page_setup_get_top_margin")]
#[doc(alias = "get_top_margin")]
pub fn top_margin(&self, unit: Unit) -> f64 {
unsafe { ffi::gtk_page_setup_get_top_margin(self.to_glib_none().0, unit.into_glib()) }
}
/// Reads the page setup from the file @file_name.
///
/// See [`to_file()`][Self::to_file()].
/// ## `file_name`
/// the filename to read the page setup from
///
/// # Returns
///
/// [`true`] on success
#[doc(alias = "gtk_page_setup_load_file")]
pub fn load_file(&self, file_name: impl AsRef<std::path::Path>) -> Result<(), glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::gtk_page_setup_load_file(
self.to_glib_none().0,
file_name.as_ref().to_glib_none().0,
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
/// Reads the page setup from the group @group_name in the key file
/// @key_file.
/// ## `key_file`
/// the `GKeyFile` to retrieve the page_setup from
/// ## `group_name`
/// the name of the group in the key_file to read
/// to use the default name “Page Setup”
///
/// # Returns
///
/// [`true`] on success
#[doc(alias = "gtk_page_setup_load_key_file")]
pub fn load_key_file(
&self,
key_file: &glib::KeyFile,
group_name: Option<&str>,
) -> Result<(), glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::gtk_page_setup_load_key_file(
self.to_glib_none().0,
key_file.to_glib_none().0,
group_name.to_glib_none().0,
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
/// Sets the bottom margin of the [`PageSetup`][crate::PageSetup].
/// ## `margin`
/// the new bottom margin in units of @unit
/// ## `unit`
/// the units for @margin
#[doc(alias = "gtk_page_setup_set_bottom_margin")]
pub fn set_bottom_margin(&self, margin: f64, unit: Unit) {
unsafe {
ffi::gtk_page_setup_set_bottom_margin(self.to_glib_none().0, margin, unit.into_glib());
}
}
/// Sets the left margin of the [`PageSetup`][crate::PageSetup].
/// ## `margin`
/// the new left margin in units of @unit
/// ## `unit`
/// the units for @margin
#[doc(alias = "gtk_page_setup_set_left_margin")]
pub fn set_left_margin(&self, margin: f64, unit: Unit) {
unsafe {
ffi::gtk_page_setup_set_left_margin(self.to_glib_none().0, margin, unit.into_glib());
}
}
/// Sets the page orientation of the [`PageSetup`][crate::PageSetup].
/// ## `orientation`
/// a [`PageOrientation`][crate::PageOrientation] value
#[doc(alias = "gtk_page_setup_set_orientation")]
pub fn set_orientation(&self, orientation: PageOrientation) {
unsafe {
ffi::gtk_page_setup_set_orientation(self.to_glib_none().0, orientation.into_glib());
}
}
/// Sets the paper size of the [`PageSetup`][crate::PageSetup] without
/// changing the margins.
///
/// See [`set_paper_size_and_default_margins()`][Self::set_paper_size_and_default_margins()].
/// ## `size`
/// a [`PaperSize`][crate::PaperSize]
#[doc(alias = "gtk_page_setup_set_paper_size")]
pub fn set_paper_size(&self, size: &PaperSize) {
unsafe {
ffi::gtk_page_setup_set_paper_size(
self.to_glib_none().0,
mut_override(size.to_glib_none().0),
);
}
}
/// Sets the paper size of the [`PageSetup`][crate::PageSetup] and modifies
/// the margins according to the new paper size.
/// ## `size`
/// a [`PaperSize`][crate::PaperSize]
#[doc(alias = "gtk_page_setup_set_paper_size_and_default_margins")]
pub fn set_paper_size_and_default_margins(&self, size: &PaperSize) {
unsafe {
ffi::gtk_page_setup_set_paper_size_and_default_margins(
self.to_glib_none().0,
mut_override(size.to_glib_none().0),
);
}
}
/// Sets the right margin of the [`PageSetup`][crate::PageSetup].
/// ## `margin`
/// the new right margin in units of @unit
/// ## `unit`
/// the units for @margin
#[doc(alias = "gtk_page_setup_set_right_margin")]
pub fn set_right_margin(&self, margin: f64, unit: Unit) {
unsafe {
ffi::gtk_page_setup_set_right_margin(self.to_glib_none().0, margin, unit.into_glib());
}
}
/// Sets the top margin of the [`PageSetup`][crate::PageSetup].
/// ## `margin`
/// the new top margin in units of @unit
/// ## `unit`
/// the units for @margin
#[doc(alias = "gtk_page_setup_set_top_margin")]
pub fn set_top_margin(&self, margin: f64, unit: Unit) {
unsafe {
ffi::gtk_page_setup_set_top_margin(self.to_glib_none().0, margin, unit.into_glib());
}
}
/// This function saves the information from @self to @file_name.
/// ## `file_name`
/// the file to save to
///
/// # Returns
///
/// [`true`] on success
#[doc(alias = "gtk_page_setup_to_file")]
pub fn to_file(&self, file_name: impl AsRef<std::path::Path>) -> Result<(), glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::gtk_page_setup_to_file(
self.to_glib_none().0,
file_name.as_ref().to_glib_none().0,
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
/// Serialize page setup to an a{sv} variant.
///
/// # Returns
///
/// a new, floating, `GVariant`
#[doc(alias = "gtk_page_setup_to_gvariant")]
pub fn to_gvariant(&self) -> glib::Variant {
unsafe { from_glib_none(ffi::gtk_page_setup_to_gvariant(self.to_glib_none().0)) }
}
/// This function adds the page setup from @self to @key_file.
/// ## `key_file`
/// the `GKeyFile` to save the page setup to
/// ## `group_name`
/// the group to add the settings to in @key_file,
/// or [`None`] to use the default name “Page Setup”
#[doc(alias = "gtk_page_setup_to_key_file")]
pub fn to_key_file(&self, key_file: &glib::KeyFile, group_name: Option<&str>) {
unsafe {
ffi::gtk_page_setup_to_key_file(
self.to_glib_none().0,
key_file.to_glib_none().0,
group_name.to_glib_none().0,
);
}
}
}
impl Default for PageSetup {
fn default() -> Self {
Self::new()
}
}