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 	 * Reads a paper size from the group @group_name in the key file
146 	 * @key_file.
147 	 *
148 	 * Params:
149 	 *     keyFile = the #GKeyFile to retrieve the papersize from
150 	 *     groupName = the name ofthe group in the key file to read,
151 	 *         or %NULL to read the first group
152 	 *
153 	 * Return: a new #GtkPaperSize object with the restored
154 	 *     paper size, or %NULL if an error occurred
155 	 *
156 	 * Since: 2.12
157 	 *
158 	 * Throws: GException on failure.
159 	 * Throws: ConstructionException GTK+ fails to create the object.
160 	 */
161 	public this(KeyFile keyFile, string groupName)
162 	{
163 		GError* err = null;
164 		
165 		auto p = gtk_paper_size_new_from_key_file((keyFile is null) ? null : keyFile.getKeyFileStruct(), Str.toStringz(groupName), &err);
166 		
167 		if(p is null)
168 		{
169 			throw new ConstructionException("null returned by new_from_key_file");
170 		}
171 		
172 		if (err !is null)
173 		{
174 			throw new GException( new ErrorG(err) );
175 		}
176 		
177 		this(cast(GtkPaperSize*) p);
178 	}
179 
180 	/**
181 	 * Creates a new #GtkPaperSize object by using
182 	 * PPD information.
183 	 *
184 	 * If @ppd_name is not a recognized PPD paper name,
185 	 * @ppd_display_name, @width and @height are used to
186 	 * construct a custom #GtkPaperSize object.
187 	 *
188 	 * Params:
189 	 *     ppdName = a PPD paper name
190 	 *     ppdDisplayName = the corresponding human-readable name
191 	 *     width = the paper width, in points
192 	 *     height = the paper height in points
193 	 *
194 	 * Return: a new #GtkPaperSize, use gtk_paper_size_free()
195 	 *     to free it
196 	 *
197 	 * Since: 2.10
198 	 *
199 	 * Throws: ConstructionException GTK+ fails to create the object.
200 	 */
201 	public this(string ppdName, string ppdDisplayName, double width, double height)
202 	{
203 		auto p = gtk_paper_size_new_from_ppd(Str.toStringz(ppdName), Str.toStringz(ppdDisplayName), width, height);
204 		
205 		if(p is null)
206 		{
207 			throw new ConstructionException("null returned by new_from_ppd");
208 		}
209 		
210 		this(cast(GtkPaperSize*) p);
211 	}
212 
213 	/**
214 	 * Copies an existing #GtkPaperSize.
215 	 *
216 	 * Return: a copy of @other
217 	 *
218 	 * Since: 2.10
219 	 */
220 	public PaperSize copy()
221 	{
222 		auto p = gtk_paper_size_copy(gtkPaperSize);
223 		
224 		if(p is null)
225 		{
226 			return null;
227 		}
228 		
229 		return ObjectG.getDObject!(PaperSize)(cast(GtkPaperSize*) p);
230 	}
231 
232 	/**
233 	 * Free the given #GtkPaperSize object.
234 	 *
235 	 * Since: 2.10
236 	 */
237 	public void free()
238 	{
239 		gtk_paper_size_free(gtkPaperSize);
240 	}
241 
242 	/**
243 	 * Gets the default bottom margin for the #GtkPaperSize.
244 	 *
245 	 * Params:
246 	 *     unit = the unit for the return value, not %GTK_UNIT_NONE
247 	 *
248 	 * Return: the default bottom margin
249 	 *
250 	 * Since: 2.10
251 	 */
252 	public double getDefaultBottomMargin(GtkUnit unit)
253 	{
254 		return gtk_paper_size_get_default_bottom_margin(gtkPaperSize, unit);
255 	}
256 
257 	/**
258 	 * Gets the default left margin for the #GtkPaperSize.
259 	 *
260 	 * Params:
261 	 *     unit = the unit for the return value, not %GTK_UNIT_NONE
262 	 *
263 	 * Return: the default left margin
264 	 *
265 	 * Since: 2.10
266 	 */
267 	public double getDefaultLeftMargin(GtkUnit unit)
268 	{
269 		return gtk_paper_size_get_default_left_margin(gtkPaperSize, unit);
270 	}
271 
272 	/**
273 	 * Gets the default right margin for the #GtkPaperSize.
274 	 *
275 	 * Params:
276 	 *     unit = the unit for the return value, not %GTK_UNIT_NONE
277 	 *
278 	 * Return: the default right margin
279 	 *
280 	 * Since: 2.10
281 	 */
282 	public double getDefaultRightMargin(GtkUnit unit)
283 	{
284 		return gtk_paper_size_get_default_right_margin(gtkPaperSize, unit);
285 	}
286 
287 	/**
288 	 * Gets the default top margin for the #GtkPaperSize.
289 	 *
290 	 * Params:
291 	 *     unit = the unit for the return value, not %GTK_UNIT_NONE
292 	 *
293 	 * Return: the default top margin
294 	 *
295 	 * Since: 2.10
296 	 */
297 	public double getDefaultTopMargin(GtkUnit unit)
298 	{
299 		return gtk_paper_size_get_default_top_margin(gtkPaperSize, unit);
300 	}
301 
302 	/**
303 	 * Gets the human-readable name of the #GtkPaperSize.
304 	 *
305 	 * Return: the human-readable name of @size
306 	 *
307 	 * Since: 2.10
308 	 */
309 	public string getDisplayName()
310 	{
311 		return Str.toString(gtk_paper_size_get_display_name(gtkPaperSize));
312 	}
313 
314 	/**
315 	 * Gets the paper height of the #GtkPaperSize, in
316 	 * units of @unit.
317 	 *
318 	 * Params:
319 	 *     unit = the unit for the return value, not %GTK_UNIT_NONE
320 	 *
321 	 * Return: the paper height
322 	 *
323 	 * Since: 2.10
324 	 */
325 	public double getHeight(GtkUnit unit)
326 	{
327 		return gtk_paper_size_get_height(gtkPaperSize, unit);
328 	}
329 
330 	/**
331 	 * Gets the name of the #GtkPaperSize.
332 	 *
333 	 * Return: the name of @size
334 	 *
335 	 * Since: 2.10
336 	 */
337 	public string getName()
338 	{
339 		return Str.toString(gtk_paper_size_get_name(gtkPaperSize));
340 	}
341 
342 	/**
343 	 * Gets the PPD name of the #GtkPaperSize, which
344 	 * may be %NULL.
345 	 *
346 	 * Return: the PPD name of @size
347 	 *
348 	 * Since: 2.10
349 	 */
350 	public string getPpdName()
351 	{
352 		return Str.toString(gtk_paper_size_get_ppd_name(gtkPaperSize));
353 	}
354 
355 	/**
356 	 * Gets the paper width of the #GtkPaperSize, in
357 	 * units of @unit.
358 	 *
359 	 * Params:
360 	 *     unit = the unit for the return value, not %GTK_UNIT_NONE
361 	 *
362 	 * Return: the paper width
363 	 *
364 	 * Since: 2.10
365 	 */
366 	public double getWidth(GtkUnit unit)
367 	{
368 		return gtk_paper_size_get_width(gtkPaperSize, unit);
369 	}
370 
371 	/**
372 	 * Returns %TRUE if @size is not a standard paper size.
373 	 *
374 	 * Return: whether @size is a custom paper size.
375 	 */
376 	public bool isCustom()
377 	{
378 		return gtk_paper_size_is_custom(gtkPaperSize) != 0;
379 	}
380 
381 	/**
382 	 * Compares two #GtkPaperSize objects.
383 	 *
384 	 * Params:
385 	 *     size2 = another #GtkPaperSize object
386 	 *
387 	 * Return: %TRUE, if @size1 and @size2
388 	 *     represent the same paper size
389 	 *
390 	 * Since: 2.10
391 	 */
392 	public bool isEqual(PaperSize size2)
393 	{
394 		return gtk_paper_size_is_equal(gtkPaperSize, (size2 is null) ? null : size2.getPaperSizeStruct()) != 0;
395 	}
396 
397 	/**
398 	 * Changes the dimensions of a @size to @width x @height.
399 	 *
400 	 * Params:
401 	 *     width = the new width in units of @unit
402 	 *     height = the new height in units of @unit
403 	 *     unit = the unit for @width and @height
404 	 *
405 	 * Since: 2.10
406 	 */
407 	public void setSize(double width, double height, GtkUnit unit)
408 	{
409 		gtk_paper_size_set_size(gtkPaperSize, width, height, unit);
410 	}
411 
412 	/**
413 	 * This function adds the paper size from @size to @key_file.
414 	 *
415 	 * Params:
416 	 *     keyFile = the #GKeyFile to save the paper size to
417 	 *     groupName = the group to add the settings to in @key_file
418 	 *
419 	 * Since: 2.12
420 	 */
421 	public void toKeyFile(KeyFile keyFile, string groupName)
422 	{
423 		gtk_paper_size_to_key_file(gtkPaperSize, (keyFile is null) ? null : keyFile.getKeyFileStruct(), Str.toStringz(groupName));
424 	}
425 
426 	/**
427 	 * Returns the name of the default paper size, which
428 	 * depends on the current locale.
429 	 *
430 	 * Return: the name of the default paper size. The string
431 	 *     is owned by GTK+ and should not be modified.
432 	 *
433 	 * Since: 2.10
434 	 */
435 	public static string getDefault()
436 	{
437 		return Str.toString(gtk_paper_size_get_default());
438 	}
439 
440 	/**
441 	 * Creates a list of known paper sizes.
442 	 *
443 	 * Params:
444 	 *     includeCustom = whether to include custom paper sizes
445 	 *         as defined in the page setup dialog
446 	 *
447 	 * Return: a newly allocated list of newly
448 	 *     allocated #GtkPaperSize objects
449 	 *
450 	 * Since: 2.12
451 	 */
452 	public static ListG getPaperSizes(bool includeCustom)
453 	{
454 		auto p = gtk_paper_size_get_paper_sizes(includeCustom);
455 		
456 		if(p is null)
457 		{
458 			return null;
459 		}
460 		
461 		return new ListG(cast(GList*) p);
462 	}
463 }