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