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.PageSetup;
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.Str;
32 private import glib.Variant;
33 private import gobject.ObjectG;
34 private import gtk.PaperSize;
35 private import gtk.c.functions;
36 public  import gtk.c.types;
37 
38 
39 /**
40  * A `GtkPageSetup` object stores the page size, orientation and margins.
41  * 
42  * The idea is that you can get one of these from the page setup dialog
43  * and then pass it to the `GtkPrintOperation` when printing.
44  * The benefit of splitting this out of the `GtkPrintSettings` is that
45  * these affect the actual layout of the page, and thus need to be set
46  * long before user prints.
47  * 
48  * ## Margins
49  * 
50  * The margins specified in this object are the “print margins”, i.e. the
51  * parts of the page that the printer cannot print on. These are different
52  * from the layout margins that a word processor uses; they are typically
53  * used to determine the minimal size for the layout margins.
54  * 
55  * To obtain a `GtkPageSetup` use [ctor@Gtk.PageSetup.new] to get the defaults,
56  * or use [func@Gtk.print_run_page_setup_dialog] to show the page setup dialog
57  * and receive the resulting page setup.
58  * 
59  * ## A page setup dialog
60  * 
61  * ```c
62  * static GtkPrintSettings *settings = NULL;
63  * static GtkPageSetup *page_setup = NULL;
64  * 
65  * static void
66  * do_page_setup (void)
67  * {
68  * GtkPageSetup *new_page_setup;
69  * 
70  * if (settings == NULL)
71  * settings = gtk_print_settings_new ();
72  * 
73  * new_page_setup = gtk_print_run_page_setup_dialog (GTK_WINDOW (main_window),
74  * page_setup, settings);
75  * 
76  * if (page_setup)
77  * g_object_unref (page_setup);
78  * 
79  * page_setup = new_page_setup;
80  * }
81  * ```
82  */
83 public class PageSetup : ObjectG
84 {
85 	/** the main Gtk struct */
86 	protected GtkPageSetup* gtkPageSetup;
87 
88 	/** Get the main Gtk struct */
89 	public GtkPageSetup* getPageSetupStruct(bool transferOwnership = false)
90 	{
91 		if (transferOwnership)
92 			ownedRef = false;
93 		return gtkPageSetup;
94 	}
95 
96 	/** the main Gtk struct as a void* */
97 	protected override void* getStruct()
98 	{
99 		return cast(void*)gtkPageSetup;
100 	}
101 
102 	/**
103 	 * Sets our main struct and passes it to the parent class.
104 	 */
105 	public this (GtkPageSetup* gtkPageSetup, bool ownedRef = false)
106 	{
107 		this.gtkPageSetup = gtkPageSetup;
108 		super(cast(GObject*)gtkPageSetup, ownedRef);
109 	}
110 
111 
112 	/** */
113 	public static GType getType()
114 	{
115 		return gtk_page_setup_get_type();
116 	}
117 
118 	/**
119 	 * Creates a new `GtkPageSetup`.
120 	 *
121 	 * Returns: a new `GtkPageSetup`.
122 	 *
123 	 * Throws: ConstructionException GTK+ fails to create the object.
124 	 */
125 	public this()
126 	{
127 		auto __p = gtk_page_setup_new();
128 
129 		if(__p is null)
130 		{
131 			throw new ConstructionException("null returned by new");
132 		}
133 
134 		this(cast(GtkPageSetup*) __p, true);
135 	}
136 
137 	/**
138 	 * Reads the page setup from the file @file_name.
139 	 *
140 	 * Returns a new `GtkPageSetup` object with the restored
141 	 * page setup, or %NULL if an error occurred.
142 	 * See [method@Gtk.PageSetup.to_file].
143 	 *
144 	 * Params:
145 	 *     fileName = the filename to read the page setup from
146 	 *
147 	 * Returns: the restored `GtkPageSetup`
148 	 *
149 	 * Throws: GException on failure.
150 	 * Throws: ConstructionException GTK+ fails to create the object.
151 	 */
152 	public this(string fileName)
153 	{
154 		GError* err = null;
155 
156 		auto __p = gtk_page_setup_new_from_file(Str.toStringz(fileName), &err);
157 
158 		if (err !is null)
159 		{
160 			throw new GException( new ErrorG(err) );
161 		}
162 
163 		if(__p is null)
164 		{
165 			throw new ConstructionException("null returned by new_from_file");
166 		}
167 
168 		this(cast(GtkPageSetup*) __p, true);
169 	}
170 
171 	/**
172 	 * Desrialize a page setup from an a{sv} variant.
173 	 *
174 	 * The variant must be in the format produced by
175 	 * [method@Gtk.PageSetup.to_gvariant].
176 	 *
177 	 * Params:
178 	 *     variant = an a{sv} `GVariant`
179 	 *
180 	 * Returns: a new `GtkPageSetup` object
181 	 *
182 	 * Throws: ConstructionException GTK+ fails to create the object.
183 	 */
184 	public this(Variant variant)
185 	{
186 		auto __p = gtk_page_setup_new_from_gvariant((variant is null) ? null : variant.getVariantStruct());
187 
188 		if(__p is null)
189 		{
190 			throw new ConstructionException("null returned by new_from_gvariant");
191 		}
192 
193 		this(cast(GtkPageSetup*) __p, true);
194 	}
195 
196 	/**
197 	 * Reads the page setup from the group @group_name in the key file
198 	 * @key_file.
199 	 *
200 	 * Returns a new `GtkPageSetup` object with the restored
201 	 * page setup, or %NULL if an error occurred.
202 	 *
203 	 * Params:
204 	 *     keyFile = the `GKeyFile` to retrieve the page_setup from
205 	 *     groupName = the name of the group in the key_file to read, or %NULL
206 	 *         to use the default name “Page Setup”
207 	 *
208 	 * Returns: the restored `GtkPageSetup`
209 	 *
210 	 * Throws: GException on failure.
211 	 * Throws: ConstructionException GTK+ fails to create the object.
212 	 */
213 	public this(KeyFile keyFile, string groupName)
214 	{
215 		GError* err = null;
216 
217 		auto __p = gtk_page_setup_new_from_key_file((keyFile is null) ? null : keyFile.getKeyFileStruct(), Str.toStringz(groupName), &err);
218 
219 		if (err !is null)
220 		{
221 			throw new GException( new ErrorG(err) );
222 		}
223 
224 		if(__p is null)
225 		{
226 			throw new ConstructionException("null returned by new_from_key_file");
227 		}
228 
229 		this(cast(GtkPageSetup*) __p, true);
230 	}
231 
232 	/**
233 	 * Copies a `GtkPageSetup`.
234 	 *
235 	 * Returns: a copy of @other
236 	 */
237 	public PageSetup copy()
238 	{
239 		auto __p = gtk_page_setup_copy(gtkPageSetup);
240 
241 		if(__p is null)
242 		{
243 			return null;
244 		}
245 
246 		return ObjectG.getDObject!(PageSetup)(cast(GtkPageSetup*) __p, true);
247 	}
248 
249 	/**
250 	 * Gets the bottom margin in units of @unit.
251 	 *
252 	 * Params:
253 	 *     unit = the unit for the return value
254 	 *
255 	 * Returns: the bottom margin
256 	 */
257 	public double getBottomMargin(GtkUnit unit)
258 	{
259 		return gtk_page_setup_get_bottom_margin(gtkPageSetup, unit);
260 	}
261 
262 	/**
263 	 * Gets the left margin in units of @unit.
264 	 *
265 	 * Params:
266 	 *     unit = the unit for the return value
267 	 *
268 	 * Returns: the left margin
269 	 */
270 	public double getLeftMargin(GtkUnit unit)
271 	{
272 		return gtk_page_setup_get_left_margin(gtkPageSetup, unit);
273 	}
274 
275 	/**
276 	 * Gets the page orientation of the `GtkPageSetup`.
277 	 *
278 	 * Returns: the page orientation
279 	 */
280 	public GtkPageOrientation getOrientation()
281 	{
282 		return gtk_page_setup_get_orientation(gtkPageSetup);
283 	}
284 
285 	/**
286 	 * Returns the page height in units of @unit.
287 	 *
288 	 * Note that this function takes orientation
289 	 * and margins into consideration.
290 	 * See [method@Gtk.PageSetup.get_paper_height].
291 	 *
292 	 * Params:
293 	 *     unit = the unit for the return value
294 	 *
295 	 * Returns: the page height.
296 	 */
297 	public double getPageHeight(GtkUnit unit)
298 	{
299 		return gtk_page_setup_get_page_height(gtkPageSetup, unit);
300 	}
301 
302 	/**
303 	 * Returns the page width in units of @unit.
304 	 *
305 	 * Note that this function takes orientation
306 	 * and margins into consideration.
307 	 * See [method@Gtk.PageSetup.get_paper_width].
308 	 *
309 	 * Params:
310 	 *     unit = the unit for the return value
311 	 *
312 	 * Returns: the page width.
313 	 */
314 	public double getPageWidth(GtkUnit unit)
315 	{
316 		return gtk_page_setup_get_page_width(gtkPageSetup, unit);
317 	}
318 
319 	/**
320 	 * Returns the paper height in units of @unit.
321 	 *
322 	 * Note that this function takes orientation,
323 	 * but not margins into consideration.
324 	 * See [method@Gtk.PageSetup.get_page_height].
325 	 *
326 	 * Params:
327 	 *     unit = the unit for the return value
328 	 *
329 	 * Returns: the paper height.
330 	 */
331 	public double getPaperHeight(GtkUnit unit)
332 	{
333 		return gtk_page_setup_get_paper_height(gtkPageSetup, unit);
334 	}
335 
336 	/**
337 	 * Gets the paper size of the `GtkPageSetup`.
338 	 *
339 	 * Returns: the paper size
340 	 */
341 	public PaperSize getPaperSize()
342 	{
343 		auto __p = gtk_page_setup_get_paper_size(gtkPageSetup);
344 
345 		if(__p is null)
346 		{
347 			return null;
348 		}
349 
350 		return ObjectG.getDObject!(PaperSize)(cast(GtkPaperSize*) __p);
351 	}
352 
353 	/**
354 	 * Returns the paper width in units of @unit.
355 	 *
356 	 * Note that this function takes orientation,
357 	 * but not margins into consideration.
358 	 * See [method@Gtk.PageSetup.get_page_width].
359 	 *
360 	 * Params:
361 	 *     unit = the unit for the return value
362 	 *
363 	 * Returns: the paper width.
364 	 */
365 	public double getPaperWidth(GtkUnit unit)
366 	{
367 		return gtk_page_setup_get_paper_width(gtkPageSetup, unit);
368 	}
369 
370 	/**
371 	 * Gets the right margin in units of @unit.
372 	 *
373 	 * Params:
374 	 *     unit = the unit for the return value
375 	 *
376 	 * Returns: the right margin
377 	 */
378 	public double getRightMargin(GtkUnit unit)
379 	{
380 		return gtk_page_setup_get_right_margin(gtkPageSetup, unit);
381 	}
382 
383 	/**
384 	 * Gets the top margin in units of @unit.
385 	 *
386 	 * Params:
387 	 *     unit = the unit for the return value
388 	 *
389 	 * Returns: the top margin
390 	 */
391 	public double getTopMargin(GtkUnit unit)
392 	{
393 		return gtk_page_setup_get_top_margin(gtkPageSetup, unit);
394 	}
395 
396 	/**
397 	 * Reads the page setup from the file @file_name.
398 	 *
399 	 * See [method@Gtk.PageSetup.to_file].
400 	 *
401 	 * Params:
402 	 *     fileName = the filename to read the page setup from
403 	 *
404 	 * Returns: %TRUE on success
405 	 *
406 	 * Throws: GException on failure.
407 	 */
408 	public bool loadFile(string fileName)
409 	{
410 		GError* err = null;
411 
412 		auto __p = gtk_page_setup_load_file(gtkPageSetup, Str.toStringz(fileName), &err) != 0;
413 
414 		if (err !is null)
415 		{
416 			throw new GException( new ErrorG(err) );
417 		}
418 
419 		return __p;
420 	}
421 
422 	/**
423 	 * Reads the page setup from the group @group_name in the key file
424 	 * @key_file.
425 	 *
426 	 * Params:
427 	 *     keyFile = the `GKeyFile` to retrieve the page_setup from
428 	 *     groupName = the name of the group in the key_file to read, or %NULL
429 	 *         to use the default name “Page Setup”
430 	 *
431 	 * Returns: %TRUE on success
432 	 *
433 	 * Throws: GException on failure.
434 	 */
435 	public bool loadKeyFile(KeyFile keyFile, string groupName)
436 	{
437 		GError* err = null;
438 
439 		auto __p = gtk_page_setup_load_key_file(gtkPageSetup, (keyFile is null) ? null : keyFile.getKeyFileStruct(), Str.toStringz(groupName), &err) != 0;
440 
441 		if (err !is null)
442 		{
443 			throw new GException( new ErrorG(err) );
444 		}
445 
446 		return __p;
447 	}
448 
449 	/**
450 	 * Sets the bottom margin of the `GtkPageSetup`.
451 	 *
452 	 * Params:
453 	 *     margin = the new bottom margin in units of @unit
454 	 *     unit = the units for @margin
455 	 */
456 	public void setBottomMargin(double margin, GtkUnit unit)
457 	{
458 		gtk_page_setup_set_bottom_margin(gtkPageSetup, margin, unit);
459 	}
460 
461 	/**
462 	 * Sets the left margin of the `GtkPageSetup`.
463 	 *
464 	 * Params:
465 	 *     margin = the new left margin in units of @unit
466 	 *     unit = the units for @margin
467 	 */
468 	public void setLeftMargin(double margin, GtkUnit unit)
469 	{
470 		gtk_page_setup_set_left_margin(gtkPageSetup, margin, unit);
471 	}
472 
473 	/**
474 	 * Sets the page orientation of the `GtkPageSetup`.
475 	 *
476 	 * Params:
477 	 *     orientation = a #GtkPageOrientation value
478 	 */
479 	public void setOrientation(GtkPageOrientation orientation)
480 	{
481 		gtk_page_setup_set_orientation(gtkPageSetup, orientation);
482 	}
483 
484 	/**
485 	 * Sets the paper size of the `GtkPageSetup` without
486 	 * changing the margins.
487 	 *
488 	 * See [method@Gtk.PageSetup.set_paper_size_and_default_margins].
489 	 *
490 	 * Params:
491 	 *     size = a #GtkPaperSize
492 	 */
493 	public void setPaperSize(PaperSize size)
494 	{
495 		gtk_page_setup_set_paper_size(gtkPageSetup, (size is null) ? null : size.getPaperSizeStruct());
496 	}
497 
498 	/**
499 	 * Sets the paper size of the `GtkPageSetup` and modifies
500 	 * the margins according to the new paper size.
501 	 *
502 	 * Params:
503 	 *     size = a #GtkPaperSize
504 	 */
505 	public void setPaperSizeAndDefaultMargins(PaperSize size)
506 	{
507 		gtk_page_setup_set_paper_size_and_default_margins(gtkPageSetup, (size is null) ? null : size.getPaperSizeStruct());
508 	}
509 
510 	/**
511 	 * Sets the right margin of the `GtkPageSetup`.
512 	 *
513 	 * Params:
514 	 *     margin = the new right margin in units of @unit
515 	 *     unit = the units for @margin
516 	 */
517 	public void setRightMargin(double margin, GtkUnit unit)
518 	{
519 		gtk_page_setup_set_right_margin(gtkPageSetup, margin, unit);
520 	}
521 
522 	/**
523 	 * Sets the top margin of the `GtkPageSetup`.
524 	 *
525 	 * Params:
526 	 *     margin = the new top margin in units of @unit
527 	 *     unit = the units for @margin
528 	 */
529 	public void setTopMargin(double margin, GtkUnit unit)
530 	{
531 		gtk_page_setup_set_top_margin(gtkPageSetup, margin, unit);
532 	}
533 
534 	/**
535 	 * This function saves the information from @setup to @file_name.
536 	 *
537 	 * Params:
538 	 *     fileName = the file to save to
539 	 *
540 	 * Returns: %TRUE on success
541 	 *
542 	 * Throws: GException on failure.
543 	 */
544 	public bool toFile(string fileName)
545 	{
546 		GError* err = null;
547 
548 		auto __p = gtk_page_setup_to_file(gtkPageSetup, Str.toStringz(fileName), &err) != 0;
549 
550 		if (err !is null)
551 		{
552 			throw new GException( new ErrorG(err) );
553 		}
554 
555 		return __p;
556 	}
557 
558 	/**
559 	 * Serialize page setup to an a{sv} variant.
560 	 *
561 	 * Returns: a new, floating, #GVariant
562 	 */
563 	public Variant toGvariant()
564 	{
565 		auto __p = gtk_page_setup_to_gvariant(gtkPageSetup);
566 
567 		if(__p is null)
568 		{
569 			return null;
570 		}
571 
572 		return new Variant(cast(GVariant*) __p);
573 	}
574 
575 	/**
576 	 * This function adds the page setup from @setup to @key_file.
577 	 *
578 	 * Params:
579 	 *     keyFile = the `GKeyFile` to save the page setup to
580 	 *     groupName = the group to add the settings to in @key_file,
581 	 *         or %NULL to use the default name “Page Setup”
582 	 */
583 	public void toKeyFile(KeyFile keyFile, string groupName)
584 	{
585 		gtk_page_setup_to_key_file(gtkPageSetup, (keyFile is null) ? null : keyFile.getKeyFileStruct(), Str.toStringz(groupName));
586 	}
587 }