1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gtk.PageSetup; 26 27 private import glib.ConstructionException; 28 private import glib.ErrorG; 29 private import glib.GException; 30 private import glib.KeyFile; 31 private import glib.Str; 32 private import glib.Variant; 33 private import gobject.ObjectG; 34 private import gtk.PaperSize; 35 private import gtk.c.functions; 36 public import gtk.c.types; 37 public import gtkc.gtktypes; 38 39 40 /** 41 * A GtkPageSetup object stores the page size, orientation and margins. 42 * The idea is that you can get one of these from the page setup dialog 43 * and then pass it to the #GtkPrintOperation when printing. 44 * The benefit of splitting this out of the #GtkPrintSettings is that 45 * these affect the actual layout of the page, and thus need to be set 46 * long before user prints. 47 * 48 * ## Margins ## {#print-margins} 49 * The margins specified in this object are the “print margins”, i.e. the 50 * parts of the page that the printer cannot print on. These are different 51 * from the layout margins that a word processor uses; they are typically 52 * used to determine the minimal size for the layout 53 * margins. 54 * 55 * To obtain a #GtkPageSetup use gtk_page_setup_new() to get the defaults, 56 * or use gtk_print_run_page_setup_dialog() to show the page setup dialog 57 * and receive the resulting page setup. 58 * 59 * ## A page setup dialog 60 * 61 * |[<!-- language="C" --> 62 * static GtkPrintSettings *settings = NULL; 63 * static GtkPageSetup *page_setup = NULL; 64 * 65 * static void 66 * do_page_setup (void) 67 * { 68 * GtkPageSetup *new_page_setup; 69 * 70 * if (settings == NULL) 71 * settings = gtk_print_settings_new (); 72 * 73 * new_page_setup = gtk_print_run_page_setup_dialog (GTK_WINDOW (main_window), 74 * page_setup, settings); 75 * 76 * if (page_setup) 77 * g_object_unref (page_setup); 78 * 79 * page_setup = new_page_setup; 80 * } 81 * ]| 82 * 83 * Printing support was added in GTK+ 2.10. 84 */ 85 public class PageSetup : ObjectG 86 { 87 /** the main Gtk struct */ 88 protected GtkPageSetup* gtkPageSetup; 89 90 /** Get the main Gtk struct */ 91 public GtkPageSetup* getPageSetupStruct(bool transferOwnership = false) 92 { 93 if (transferOwnership) 94 ownedRef = false; 95 return gtkPageSetup; 96 } 97 98 /** the main Gtk struct as a void* */ 99 protected override void* getStruct() 100 { 101 return cast(void*)gtkPageSetup; 102 } 103 104 /** 105 * Sets our main struct and passes it to the parent class. 106 */ 107 public this (GtkPageSetup* gtkPageSetup, bool ownedRef = false) 108 { 109 this.gtkPageSetup = gtkPageSetup; 110 super(cast(GObject*)gtkPageSetup, ownedRef); 111 } 112 113 114 /** */ 115 public static GType getType() 116 { 117 return gtk_page_setup_get_type(); 118 } 119 120 /** 121 * Creates a new #GtkPageSetup. 122 * 123 * Returns: a new #GtkPageSetup. 124 * 125 * Since: 2.10 126 * 127 * Throws: ConstructionException GTK+ fails to create the object. 128 */ 129 public this() 130 { 131 auto p = gtk_page_setup_new(); 132 133 if(p is null) 134 { 135 throw new ConstructionException("null returned by new"); 136 } 137 138 this(cast(GtkPageSetup*) p, true); 139 } 140 141 /** 142 * Reads the page setup from the file @file_name. Returns a 143 * new #GtkPageSetup object with the restored page setup, 144 * or %NULL if an error occurred. See gtk_page_setup_to_file(). 145 * 146 * Params: 147 * fileName = the filename to read the page setup from 148 * 149 * Returns: the restored #GtkPageSetup 150 * 151 * Since: 2.12 152 * 153 * Throws: GException on failure. 154 * Throws: ConstructionException GTK+ fails to create the object. 155 */ 156 public this(string fileName) 157 { 158 GError* err = null; 159 160 auto p = gtk_page_setup_new_from_file(Str.toStringz(fileName), &err); 161 162 if (err !is null) 163 { 164 throw new GException( new ErrorG(err) ); 165 } 166 167 if(p is null) 168 { 169 throw new ConstructionException("null returned by new_from_file"); 170 } 171 172 this(cast(GtkPageSetup*) p, true); 173 } 174 175 /** 176 * Desrialize a page setup from an a{sv} variant in 177 * the format produced by gtk_page_setup_to_gvariant(). 178 * 179 * Params: 180 * variant = an a{sv} #GVariant 181 * 182 * Returns: a new #GtkPageSetup object 183 * 184 * Since: 3.22 185 * 186 * Throws: ConstructionException GTK+ fails to create the object. 187 */ 188 public this(Variant variant) 189 { 190 auto p = gtk_page_setup_new_from_gvariant((variant is null) ? null : variant.getVariantStruct()); 191 192 if(p is null) 193 { 194 throw new ConstructionException("null returned by new_from_gvariant"); 195 } 196 197 this(cast(GtkPageSetup*) p, true); 198 } 199 200 /** 201 * Reads the page setup from the group @group_name in the key file 202 * @key_file. Returns a new #GtkPageSetup object with the restored 203 * page setup, or %NULL if an error occurred. 204 * 205 * Params: 206 * keyFile = the #GKeyFile to retrieve the page_setup from 207 * groupName = the name of the group in the key_file to read, or %NULL 208 * to use the default name “Page Setup” 209 * 210 * Returns: the restored #GtkPageSetup 211 * 212 * Since: 2.12 213 * 214 * Throws: GException on failure. 215 * Throws: ConstructionException GTK+ fails to create the object. 216 */ 217 public this(KeyFile keyFile, string groupName) 218 { 219 GError* err = null; 220 221 auto p = gtk_page_setup_new_from_key_file((keyFile is null) ? null : keyFile.getKeyFileStruct(), Str.toStringz(groupName), &err); 222 223 if (err !is null) 224 { 225 throw new GException( new ErrorG(err) ); 226 } 227 228 if(p is null) 229 { 230 throw new ConstructionException("null returned by new_from_key_file"); 231 } 232 233 this(cast(GtkPageSetup*) p, true); 234 } 235 236 /** 237 * Copies a #GtkPageSetup. 238 * 239 * Returns: a copy of @other 240 * 241 * Since: 2.10 242 */ 243 public PageSetup copy() 244 { 245 auto p = gtk_page_setup_copy(gtkPageSetup); 246 247 if(p is null) 248 { 249 return null; 250 } 251 252 return ObjectG.getDObject!(PageSetup)(cast(GtkPageSetup*) p, true); 253 } 254 255 /** 256 * Gets the bottom margin in units of @unit. 257 * 258 * Params: 259 * unit = the unit for the return value 260 * 261 * Returns: the bottom margin 262 * 263 * Since: 2.10 264 */ 265 public double getBottomMargin(GtkUnit unit) 266 { 267 return gtk_page_setup_get_bottom_margin(gtkPageSetup, unit); 268 } 269 270 /** 271 * Gets the left margin in units of @unit. 272 * 273 * Params: 274 * unit = the unit for the return value 275 * 276 * Returns: the left margin 277 * 278 * Since: 2.10 279 */ 280 public double getLeftMargin(GtkUnit unit) 281 { 282 return gtk_page_setup_get_left_margin(gtkPageSetup, unit); 283 } 284 285 /** 286 * Gets the page orientation of the #GtkPageSetup. 287 * 288 * Returns: the page orientation 289 * 290 * Since: 2.10 291 */ 292 public GtkPageOrientation getOrientation() 293 { 294 return gtk_page_setup_get_orientation(gtkPageSetup); 295 } 296 297 /** 298 * Returns the page height in units of @unit. 299 * 300 * Note that this function takes orientation and 301 * margins into consideration. 302 * See gtk_page_setup_get_paper_height(). 303 * 304 * Params: 305 * unit = the unit for the return value 306 * 307 * Returns: the page height. 308 * 309 * Since: 2.10 310 */ 311 public double getPageHeight(GtkUnit unit) 312 { 313 return gtk_page_setup_get_page_height(gtkPageSetup, unit); 314 } 315 316 /** 317 * Returns the page width in units of @unit. 318 * 319 * Note that this function takes orientation and 320 * margins into consideration. 321 * See gtk_page_setup_get_paper_width(). 322 * 323 * Params: 324 * unit = the unit for the return value 325 * 326 * Returns: the page width. 327 * 328 * Since: 2.10 329 */ 330 public double getPageWidth(GtkUnit unit) 331 { 332 return gtk_page_setup_get_page_width(gtkPageSetup, unit); 333 } 334 335 /** 336 * Returns the paper height in units of @unit. 337 * 338 * Note that this function takes orientation, but 339 * not margins into consideration. 340 * See gtk_page_setup_get_page_height(). 341 * 342 * Params: 343 * unit = the unit for the return value 344 * 345 * Returns: the paper height. 346 * 347 * Since: 2.10 348 */ 349 public double getPaperHeight(GtkUnit unit) 350 { 351 return gtk_page_setup_get_paper_height(gtkPageSetup, unit); 352 } 353 354 /** 355 * Gets the paper size of the #GtkPageSetup. 356 * 357 * Returns: the paper size 358 * 359 * Since: 2.10 360 */ 361 public PaperSize getPaperSize() 362 { 363 auto p = gtk_page_setup_get_paper_size(gtkPageSetup); 364 365 if(p is null) 366 { 367 return null; 368 } 369 370 return ObjectG.getDObject!(PaperSize)(cast(GtkPaperSize*) p); 371 } 372 373 /** 374 * Returns the paper width in units of @unit. 375 * 376 * Note that this function takes orientation, but 377 * not margins into consideration. 378 * See gtk_page_setup_get_page_width(). 379 * 380 * Params: 381 * unit = the unit for the return value 382 * 383 * Returns: the paper width. 384 * 385 * Since: 2.10 386 */ 387 public double getPaperWidth(GtkUnit unit) 388 { 389 return gtk_page_setup_get_paper_width(gtkPageSetup, unit); 390 } 391 392 /** 393 * Gets the right margin in units of @unit. 394 * 395 * Params: 396 * unit = the unit for the return value 397 * 398 * Returns: the right margin 399 * 400 * Since: 2.10 401 */ 402 public double getRightMargin(GtkUnit unit) 403 { 404 return gtk_page_setup_get_right_margin(gtkPageSetup, unit); 405 } 406 407 /** 408 * Gets the top margin in units of @unit. 409 * 410 * Params: 411 * unit = the unit for the return value 412 * 413 * Returns: the top margin 414 * 415 * Since: 2.10 416 */ 417 public double getTopMargin(GtkUnit unit) 418 { 419 return gtk_page_setup_get_top_margin(gtkPageSetup, unit); 420 } 421 422 /** 423 * Reads the page setup from the file @file_name. 424 * See gtk_page_setup_to_file(). 425 * 426 * Params: 427 * fileName = the filename to read the page setup from 428 * 429 * Returns: %TRUE on success 430 * 431 * Since: 2.14 432 * 433 * Throws: GException on failure. 434 */ 435 public bool loadFile(string fileName) 436 { 437 GError* err = null; 438 439 auto p = gtk_page_setup_load_file(gtkPageSetup, Str.toStringz(fileName), &err) != 0; 440 441 if (err !is null) 442 { 443 throw new GException( new ErrorG(err) ); 444 } 445 446 return p; 447 } 448 449 /** 450 * Reads the page setup from the group @group_name in the key file 451 * @key_file. 452 * 453 * Params: 454 * keyFile = the #GKeyFile to retrieve the page_setup from 455 * groupName = the name of the group in the key_file to read, or %NULL 456 * to use the default name “Page Setup” 457 * 458 * Returns: %TRUE on success 459 * 460 * Since: 2.14 461 * 462 * Throws: GException on failure. 463 */ 464 public bool loadKeyFile(KeyFile keyFile, string groupName) 465 { 466 GError* err = null; 467 468 auto p = gtk_page_setup_load_key_file(gtkPageSetup, (keyFile is null) ? null : keyFile.getKeyFileStruct(), Str.toStringz(groupName), &err) != 0; 469 470 if (err !is null) 471 { 472 throw new GException( new ErrorG(err) ); 473 } 474 475 return p; 476 } 477 478 /** 479 * Sets the bottom margin of the #GtkPageSetup. 480 * 481 * Params: 482 * margin = the new bottom margin in units of @unit 483 * unit = the units for @margin 484 * 485 * Since: 2.10 486 */ 487 public void setBottomMargin(double margin, GtkUnit unit) 488 { 489 gtk_page_setup_set_bottom_margin(gtkPageSetup, margin, unit); 490 } 491 492 /** 493 * Sets the left margin of the #GtkPageSetup. 494 * 495 * Params: 496 * margin = the new left margin in units of @unit 497 * unit = the units for @margin 498 * 499 * Since: 2.10 500 */ 501 public void setLeftMargin(double margin, GtkUnit unit) 502 { 503 gtk_page_setup_set_left_margin(gtkPageSetup, margin, unit); 504 } 505 506 /** 507 * Sets the page orientation of the #GtkPageSetup. 508 * 509 * Params: 510 * orientation = a #GtkPageOrientation value 511 * 512 * Since: 2.10 513 */ 514 public void setOrientation(GtkPageOrientation orientation) 515 { 516 gtk_page_setup_set_orientation(gtkPageSetup, orientation); 517 } 518 519 /** 520 * Sets the paper size of the #GtkPageSetup without 521 * changing the margins. See 522 * gtk_page_setup_set_paper_size_and_default_margins(). 523 * 524 * Params: 525 * size = a #GtkPaperSize 526 * 527 * Since: 2.10 528 */ 529 public void setPaperSize(PaperSize size) 530 { 531 gtk_page_setup_set_paper_size(gtkPageSetup, (size is null) ? null : size.getPaperSizeStruct()); 532 } 533 534 /** 535 * Sets the paper size of the #GtkPageSetup and modifies 536 * the margins according to the new paper size. 537 * 538 * Params: 539 * size = a #GtkPaperSize 540 * 541 * Since: 2.10 542 */ 543 public void setPaperSizeAndDefaultMargins(PaperSize size) 544 { 545 gtk_page_setup_set_paper_size_and_default_margins(gtkPageSetup, (size is null) ? null : size.getPaperSizeStruct()); 546 } 547 548 /** 549 * Sets the right margin of the #GtkPageSetup. 550 * 551 * Params: 552 * margin = the new right margin in units of @unit 553 * unit = the units for @margin 554 * 555 * Since: 2.10 556 */ 557 public void setRightMargin(double margin, GtkUnit unit) 558 { 559 gtk_page_setup_set_right_margin(gtkPageSetup, margin, unit); 560 } 561 562 /** 563 * Sets the top margin of the #GtkPageSetup. 564 * 565 * Params: 566 * margin = the new top margin in units of @unit 567 * unit = the units for @margin 568 * 569 * Since: 2.10 570 */ 571 public void setTopMargin(double margin, GtkUnit unit) 572 { 573 gtk_page_setup_set_top_margin(gtkPageSetup, margin, unit); 574 } 575 576 /** 577 * This function saves the information from @setup to @file_name. 578 * 579 * Params: 580 * fileName = the file to save to 581 * 582 * Returns: %TRUE on success 583 * 584 * Since: 2.12 585 * 586 * Throws: GException on failure. 587 */ 588 public bool toFile(string fileName) 589 { 590 GError* err = null; 591 592 auto p = gtk_page_setup_to_file(gtkPageSetup, Str.toStringz(fileName), &err) != 0; 593 594 if (err !is null) 595 { 596 throw new GException( new ErrorG(err) ); 597 } 598 599 return p; 600 } 601 602 /** 603 * Serialize page setup to an a{sv} variant. 604 * 605 * Returns: a new, floating, #GVariant 606 * 607 * Since: 3.22 608 */ 609 public Variant toGvariant() 610 { 611 auto p = gtk_page_setup_to_gvariant(gtkPageSetup); 612 613 if(p is null) 614 { 615 return null; 616 } 617 618 return new Variant(cast(GVariant*) p); 619 } 620 621 /** 622 * This function adds the page setup from @setup to @key_file. 623 * 624 * Params: 625 * keyFile = the #GKeyFile to save the page setup to 626 * groupName = the group to add the settings to in @key_file, 627 * or %NULL to use the default name “Page Setup” 628 * 629 * Since: 2.12 630 */ 631 public void toKeyFile(KeyFile keyFile, string groupName) 632 { 633 gtk_page_setup_to_key_file(gtkPageSetup, (keyFile is null) ? null : keyFile.getKeyFileStruct(), Str.toStringz(groupName)); 634 } 635 }