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.PaperSize; 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.ListG; 32 private import glib.Str; 33 private import glib.Variant; 34 private import gobject.ObjectG; 35 private import gtk.c.functions; 36 public import gtk.c.types; 37 public import gtkc.gtktypes; 38 private import gtkd.Loader; 39 40 41 /** 42 * GtkPaperSize handles paper sizes. It uses the standard called 43 * [PWG 5101.1-2002 PWG: Standard for Media Standardized Names](http://www.pwg.org/standards.html) 44 * to name the paper sizes (and to get the data for the page sizes). 45 * In addition to standard paper sizes, GtkPaperSize allows to 46 * construct custom paper sizes with arbitrary dimensions. 47 * 48 * The #GtkPaperSize object stores not only the dimensions (width 49 * and height) of a paper size and its name, it also provides 50 * default [print margins][print-margins]. 51 * 52 * Printing support has been added in GTK+ 2.10. 53 */ 54 public class PaperSize 55 { 56 /** the main Gtk struct */ 57 protected GtkPaperSize* gtkPaperSize; 58 protected bool ownedRef; 59 60 /** Get the main Gtk struct */ 61 public GtkPaperSize* getPaperSizeStruct(bool transferOwnership = false) 62 { 63 if (transferOwnership) 64 ownedRef = false; 65 return gtkPaperSize; 66 } 67 68 /** the main Gtk struct as a void* */ 69 protected void* getStruct() 70 { 71 return cast(void*)gtkPaperSize; 72 } 73 74 /** 75 * Sets our main struct and passes it to the parent class. 76 */ 77 public this (GtkPaperSize* gtkPaperSize, bool ownedRef = false) 78 { 79 this.gtkPaperSize = gtkPaperSize; 80 this.ownedRef = ownedRef; 81 } 82 83 ~this () 84 { 85 if ( Linker.isLoaded(LIBRARY_GTK) && ownedRef ) 86 gtk_paper_size_free(gtkPaperSize); 87 } 88 89 90 /** */ 91 public static GType getType() 92 { 93 return gtk_paper_size_get_type(); 94 } 95 96 /** 97 * Creates a new #GtkPaperSize object by parsing a 98 * [PWG 5101.1-2002](ftp://ftp.pwg.org/pub/pwg/candidates/cs-pwgmsn10-20020226-5101.1.pdf) 99 * paper name. 100 * 101 * If @name is %NULL, the default paper size is returned, 102 * see gtk_paper_size_get_default(). 103 * 104 * Params: 105 * name = a paper size name, or %NULL 106 * 107 * Returns: a new #GtkPaperSize, use gtk_paper_size_free() 108 * to free it 109 * 110 * Since: 2.10 111 * 112 * Throws: ConstructionException GTK+ fails to create the object. 113 */ 114 public this(string name) 115 { 116 auto p = gtk_paper_size_new(Str.toStringz(name)); 117 118 if(p is null) 119 { 120 throw new ConstructionException("null returned by new"); 121 } 122 123 this(cast(GtkPaperSize*) p); 124 } 125 126 /** 127 * Creates a new #GtkPaperSize object with the 128 * given parameters. 129 * 130 * Params: 131 * name = the paper name 132 * displayName = the human-readable name 133 * width = the paper width, in units of @unit 134 * height = the paper height, in units of @unit 135 * unit = the unit for @width and @height. not %GTK_UNIT_NONE. 136 * 137 * Returns: a new #GtkPaperSize object, use gtk_paper_size_free() 138 * to free it 139 * 140 * Since: 2.10 141 * 142 * Throws: ConstructionException GTK+ fails to create the object. 143 */ 144 public this(string name, string displayName, double width, double height, GtkUnit unit) 145 { 146 auto p = gtk_paper_size_new_custom(Str.toStringz(name), Str.toStringz(displayName), width, height, unit); 147 148 if(p is null) 149 { 150 throw new ConstructionException("null returned by new_custom"); 151 } 152 153 this(cast(GtkPaperSize*) p); 154 } 155 156 /** 157 * Deserialize a paper size from an a{sv} variant in 158 * the format produced by gtk_paper_size_to_gvariant(). 159 * 160 * Params: 161 * variant = an a{sv} #GVariant 162 * 163 * Returns: a new #GtkPaperSize object 164 * 165 * Since: 3.22 166 * 167 * Throws: ConstructionException GTK+ fails to create the object. 168 */ 169 public this(Variant variant) 170 { 171 auto p = gtk_paper_size_new_from_gvariant((variant is null) ? null : variant.getVariantStruct()); 172 173 if(p is null) 174 { 175 throw new ConstructionException("null returned by new_from_gvariant"); 176 } 177 178 this(cast(GtkPaperSize*) p); 179 } 180 181 /** 182 * Creates a new #GtkPaperSize object by using 183 * IPP information. 184 * 185 * If @ipp_name is not a recognized paper name, 186 * @width and @height are used to 187 * construct a custom #GtkPaperSize object. 188 * 189 * Params: 190 * ippName = an IPP paper name 191 * width = the paper width, in points 192 * height = the paper height in points 193 * 194 * Returns: a new #GtkPaperSize, use gtk_paper_size_free() 195 * to free it 196 * 197 * Since: 3.16 198 * 199 * Throws: ConstructionException GTK+ fails to create the object. 200 */ 201 public this(string ippName, double width, double height) 202 { 203 auto p = gtk_paper_size_new_from_ipp(Str.toStringz(ippName), width, height); 204 205 if(p is null) 206 { 207 throw new ConstructionException("null returned by new_from_ipp"); 208 } 209 210 this(cast(GtkPaperSize*) p); 211 } 212 213 /** 214 * Reads a paper size from the group @group_name in the key file 215 * @key_file. 216 * 217 * Params: 218 * keyFile = the #GKeyFile to retrieve the papersize from 219 * groupName = the name of the group in the key file to read, 220 * or %NULL to read the first group 221 * 222 * Returns: a new #GtkPaperSize object with the restored 223 * paper size, or %NULL if an error occurred 224 * 225 * Since: 2.12 226 * 227 * Throws: GException on failure. 228 * Throws: ConstructionException GTK+ fails to create the object. 229 */ 230 public this(KeyFile keyFile, string groupName) 231 { 232 GError* err = null; 233 234 auto p = gtk_paper_size_new_from_key_file((keyFile is null) ? null : keyFile.getKeyFileStruct(), Str.toStringz(groupName), &err); 235 236 if (err !is null) 237 { 238 throw new GException( new ErrorG(err) ); 239 } 240 241 if(p is null) 242 { 243 throw new ConstructionException("null returned by new_from_key_file"); 244 } 245 246 this(cast(GtkPaperSize*) p); 247 } 248 249 /** 250 * Creates a new #GtkPaperSize object by using 251 * PPD information. 252 * 253 * If @ppd_name is not a recognized PPD paper name, 254 * @ppd_display_name, @width and @height are used to 255 * construct a custom #GtkPaperSize object. 256 * 257 * Params: 258 * ppdName = a PPD paper name 259 * ppdDisplayName = the corresponding human-readable name 260 * width = the paper width, in points 261 * height = the paper height in points 262 * 263 * Returns: a new #GtkPaperSize, use gtk_paper_size_free() 264 * to free it 265 * 266 * Since: 2.10 267 * 268 * Throws: ConstructionException GTK+ fails to create the object. 269 */ 270 public this(string ppdName, string ppdDisplayName, double width, double height) 271 { 272 auto p = gtk_paper_size_new_from_ppd(Str.toStringz(ppdName), Str.toStringz(ppdDisplayName), width, height); 273 274 if(p is null) 275 { 276 throw new ConstructionException("null returned by new_from_ppd"); 277 } 278 279 this(cast(GtkPaperSize*) p); 280 } 281 282 /** 283 * Copies an existing #GtkPaperSize. 284 * 285 * Returns: a copy of @other 286 * 287 * Since: 2.10 288 */ 289 public PaperSize copy() 290 { 291 auto p = gtk_paper_size_copy(gtkPaperSize); 292 293 if(p is null) 294 { 295 return null; 296 } 297 298 return ObjectG.getDObject!(PaperSize)(cast(GtkPaperSize*) p, true); 299 } 300 301 /** 302 * Free the given #GtkPaperSize object. 303 * 304 * Since: 2.10 305 */ 306 public void free() 307 { 308 gtk_paper_size_free(gtkPaperSize); 309 ownedRef = false; 310 } 311 312 /** 313 * Gets the default bottom margin for the #GtkPaperSize. 314 * 315 * Params: 316 * unit = the unit for the return value, not %GTK_UNIT_NONE 317 * 318 * Returns: the default bottom margin 319 * 320 * Since: 2.10 321 */ 322 public double getDefaultBottomMargin(GtkUnit unit) 323 { 324 return gtk_paper_size_get_default_bottom_margin(gtkPaperSize, unit); 325 } 326 327 /** 328 * Gets the default left margin for the #GtkPaperSize. 329 * 330 * Params: 331 * unit = the unit for the return value, not %GTK_UNIT_NONE 332 * 333 * Returns: the default left margin 334 * 335 * Since: 2.10 336 */ 337 public double getDefaultLeftMargin(GtkUnit unit) 338 { 339 return gtk_paper_size_get_default_left_margin(gtkPaperSize, unit); 340 } 341 342 /** 343 * Gets the default right margin for the #GtkPaperSize. 344 * 345 * Params: 346 * unit = the unit for the return value, not %GTK_UNIT_NONE 347 * 348 * Returns: the default right margin 349 * 350 * Since: 2.10 351 */ 352 public double getDefaultRightMargin(GtkUnit unit) 353 { 354 return gtk_paper_size_get_default_right_margin(gtkPaperSize, unit); 355 } 356 357 /** 358 * Gets the default top margin for the #GtkPaperSize. 359 * 360 * Params: 361 * unit = the unit for the return value, not %GTK_UNIT_NONE 362 * 363 * Returns: the default top margin 364 * 365 * Since: 2.10 366 */ 367 public double getDefaultTopMargin(GtkUnit unit) 368 { 369 return gtk_paper_size_get_default_top_margin(gtkPaperSize, unit); 370 } 371 372 /** 373 * Gets the human-readable name of the #GtkPaperSize. 374 * 375 * Returns: the human-readable name of @size 376 * 377 * Since: 2.10 378 */ 379 public string getDisplayName() 380 { 381 return Str.toString(gtk_paper_size_get_display_name(gtkPaperSize)); 382 } 383 384 /** 385 * Gets the paper height of the #GtkPaperSize, in 386 * units of @unit. 387 * 388 * Params: 389 * unit = the unit for the return value, not %GTK_UNIT_NONE 390 * 391 * Returns: the paper height 392 * 393 * Since: 2.10 394 */ 395 public double getHeight(GtkUnit unit) 396 { 397 return gtk_paper_size_get_height(gtkPaperSize, unit); 398 } 399 400 /** 401 * Gets the name of the #GtkPaperSize. 402 * 403 * Returns: the name of @size 404 * 405 * Since: 2.10 406 */ 407 public string getName() 408 { 409 return Str.toString(gtk_paper_size_get_name(gtkPaperSize)); 410 } 411 412 /** 413 * Gets the PPD name of the #GtkPaperSize, which 414 * may be %NULL. 415 * 416 * Returns: the PPD name of @size 417 * 418 * Since: 2.10 419 */ 420 public string getPpdName() 421 { 422 return Str.toString(gtk_paper_size_get_ppd_name(gtkPaperSize)); 423 } 424 425 /** 426 * Gets the paper width of the #GtkPaperSize, in 427 * units of @unit. 428 * 429 * Params: 430 * unit = the unit for the return value, not %GTK_UNIT_NONE 431 * 432 * Returns: the paper width 433 * 434 * Since: 2.10 435 */ 436 public double getWidth(GtkUnit unit) 437 { 438 return gtk_paper_size_get_width(gtkPaperSize, unit); 439 } 440 441 /** 442 * Returns %TRUE if @size is not a standard paper size. 443 * 444 * Returns: whether @size is a custom paper size. 445 */ 446 public bool isCustom() 447 { 448 return gtk_paper_size_is_custom(gtkPaperSize) != 0; 449 } 450 451 /** 452 * Compares two #GtkPaperSize objects. 453 * 454 * Params: 455 * size2 = another #GtkPaperSize object 456 * 457 * Returns: %TRUE, if @size1 and @size2 458 * represent the same paper size 459 * 460 * Since: 2.10 461 */ 462 public bool isEqual(PaperSize size2) 463 { 464 return gtk_paper_size_is_equal(gtkPaperSize, (size2 is null) ? null : size2.getPaperSizeStruct()) != 0; 465 } 466 467 /** 468 * Returns %TRUE if @size is an IPP standard paper size. 469 * 470 * Returns: whether @size is not an IPP custom paper size. 471 */ 472 public bool isIpp() 473 { 474 return gtk_paper_size_is_ipp(gtkPaperSize) != 0; 475 } 476 477 /** 478 * Changes the dimensions of a @size to @width x @height. 479 * 480 * Params: 481 * width = the new width in units of @unit 482 * height = the new height in units of @unit 483 * unit = the unit for @width and @height 484 * 485 * Since: 2.10 486 */ 487 public void setSize(double width, double height, GtkUnit unit) 488 { 489 gtk_paper_size_set_size(gtkPaperSize, width, height, unit); 490 } 491 492 /** 493 * Serialize a paper size to an a{sv} variant. 494 * 495 * Returns: a new, floating, #GVariant 496 * 497 * Since: 3.22 498 */ 499 public Variant toGvariant() 500 { 501 auto p = gtk_paper_size_to_gvariant(gtkPaperSize); 502 503 if(p is null) 504 { 505 return null; 506 } 507 508 return new Variant(cast(GVariant*) p); 509 } 510 511 /** 512 * This function adds the paper size from @size to @key_file. 513 * 514 * Params: 515 * keyFile = the #GKeyFile to save the paper size to 516 * groupName = the group to add the settings to in @key_file 517 * 518 * Since: 2.12 519 */ 520 public void toKeyFile(KeyFile keyFile, string groupName) 521 { 522 gtk_paper_size_to_key_file(gtkPaperSize, (keyFile is null) ? null : keyFile.getKeyFileStruct(), Str.toStringz(groupName)); 523 } 524 525 /** 526 * Returns the name of the default paper size, which 527 * depends on the current locale. 528 * 529 * Returns: the name of the default paper size. The string 530 * is owned by GTK+ and should not be modified. 531 * 532 * Since: 2.10 533 */ 534 public static string getDefault() 535 { 536 return Str.toString(gtk_paper_size_get_default()); 537 } 538 539 /** 540 * Creates a list of known paper sizes. 541 * 542 * Params: 543 * includeCustom = whether to include custom paper sizes 544 * as defined in the page setup dialog 545 * 546 * Returns: a newly allocated list of newly 547 * allocated #GtkPaperSize objects 548 * 549 * Since: 2.12 550 */ 551 public static ListG getPaperSizes(bool includeCustom) 552 { 553 auto p = gtk_paper_size_get_paper_sizes(includeCustom); 554 555 if(p is null) 556 { 557 return null; 558 } 559 560 return new ListG(cast(GList*) p, true); 561 } 562 }