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