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