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