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