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