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