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