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