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