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