]> Pileus Git - ~andy/gtk/blob - gtk/gtkpagesetup.c
ba98cffd60c4dd5bb28302ddb66640c361c86d57
[~andy/gtk] / gtk / gtkpagesetup.c
1 /* GTK - The GIMP Toolkit
2  * gtkpagesetup.c: Page Setup
3  * Copyright (C) 2006, Red Hat, Inc.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library 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 GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #include "config.h"
22
23 #include "gtkpagesetup.h"
24 #include "gtkprintutils.h"
25 #include "gtkprintoperation.h" /* for GtkPrintError */
26 #include "gtkintl.h"
27 #include "gtktypebuiltins.h"
28 #include "gtkalias.h"
29
30 #define KEYFILE_GROUP_NAME "Page Setup"
31
32 typedef struct _GtkPageSetupClass GtkPageSetupClass;
33
34 #define GTK_IS_PAGE_SETUP_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_PAGE_SETUP))
35 #define GTK_PAGE_SETUP_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_PAGE_SETUP, GtkPageSetupClass))
36 #define GTK_PAGE_SETUP_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_PAGE_SETUP, GtkPageSetupClass))
37
38 struct _GtkPageSetup
39 {
40   GObject parent_instance;
41
42   GtkPageOrientation orientation;
43   GtkPaperSize *paper_size;
44   /* These are stored in mm */
45   double top_margin, bottom_margin, left_margin, right_margin;
46 };
47
48 struct _GtkPageSetupClass
49 {
50   GObjectClass parent_class;
51 };
52
53 G_DEFINE_TYPE (GtkPageSetup, gtk_page_setup, G_TYPE_OBJECT)
54
55 static void
56 gtk_page_setup_finalize (GObject *object)
57 {
58   GtkPageSetup *setup = GTK_PAGE_SETUP (object);
59   
60   gtk_paper_size_free (setup->paper_size);
61   
62   G_OBJECT_CLASS (gtk_page_setup_parent_class)->finalize (object);
63 }
64
65 static void
66 gtk_page_setup_init (GtkPageSetup *setup)
67 {
68   setup->paper_size = gtk_paper_size_new (NULL);
69   setup->orientation = GTK_PAGE_ORIENTATION_PORTRAIT;
70   setup->top_margin = gtk_paper_size_get_default_top_margin (setup->paper_size, GTK_UNIT_MM);
71   setup->bottom_margin = gtk_paper_size_get_default_bottom_margin (setup->paper_size, GTK_UNIT_MM);
72   setup->left_margin = gtk_paper_size_get_default_left_margin (setup->paper_size, GTK_UNIT_MM);
73   setup->right_margin = gtk_paper_size_get_default_right_margin (setup->paper_size, GTK_UNIT_MM);
74 }
75
76 static void
77 gtk_page_setup_class_init (GtkPageSetupClass *class)
78 {
79   GObjectClass *gobject_class = (GObjectClass *)class;
80
81   gobject_class->finalize = gtk_page_setup_finalize;
82 }
83
84 /**
85  * gtk_page_setup_new:
86  *
87  * Creates a new #GtkPageSetup. 
88  * 
89  * Return value: a new #GtkPageSetup.
90  *
91  * Since: 2.10
92  */
93 GtkPageSetup *
94 gtk_page_setup_new (void)
95 {
96   return g_object_new (GTK_TYPE_PAGE_SETUP, NULL);
97 }
98
99 /**
100  * gtk_page_setup_copy:
101  * @other: the #GtkPageSetup to copy
102  * 
103  * Copies a #GtkPageSetup.
104  * 
105  * Return value: a copy of @other
106  *
107  * Since: 2.10
108  */
109 GtkPageSetup *
110 gtk_page_setup_copy (GtkPageSetup *other)
111 {
112   GtkPageSetup *copy;
113
114   copy = gtk_page_setup_new ();
115   copy->orientation = other->orientation;
116   gtk_paper_size_free (copy->paper_size);
117   copy->paper_size = gtk_paper_size_copy (other->paper_size);
118   copy->top_margin = other->top_margin;
119   copy->bottom_margin = other->bottom_margin;
120   copy->left_margin = other->left_margin;
121   copy->right_margin = other->right_margin;
122
123   return copy;
124 }
125
126 /**
127  * gtk_page_setup_get_orientation:
128  * @setup: a #GtkPageSetup
129  * 
130  * Gets the page orientation of the #GtkPageSetup.
131  * 
132  * Return value: the page orientation
133  *
134  * Since: 2.10
135  */
136 GtkPageOrientation
137 gtk_page_setup_get_orientation (GtkPageSetup *setup)
138 {
139   return setup->orientation;
140 }
141
142 /**
143  * gtk_page_setup_set_orientation:
144  * @setup: a #GtkPageSetup
145  * @orientation: a #GtkPageOrientation value
146  * 
147  * Sets the page orientation of the #GtkPageSetup.
148  *
149  * Since: 2.10
150  */
151 void
152 gtk_page_setup_set_orientation (GtkPageSetup       *setup,
153                                 GtkPageOrientation  orientation)
154 {
155   setup->orientation = orientation;
156 }
157
158 /**
159  * gtk_page_setup_get_paper_size:
160  * @setup: a #GtkPageSetup
161  * 
162  * Gets the paper size of the #GtkPageSetup.
163  * 
164  * Return value: the paper size
165  *
166  * Since: 2.10
167  */
168 GtkPaperSize *
169 gtk_page_setup_get_paper_size (GtkPageSetup *setup)
170 {
171   g_return_val_if_fail (GTK_IS_PAGE_SETUP (setup), NULL);
172
173   return setup->paper_size;
174 }
175
176 /**
177  * gtk_page_setup_set_paper_size:
178  * @setup: a #GtkPageSetup
179  * @size: a #GtkPaperSize 
180  * 
181  * Sets the paper size of the #GtkPageSetup without
182  * changing the margins. See 
183  * gtk_page_setup_set_paper_size_and_default_margins().
184  *
185  * Since: 2.10
186  */
187 void
188 gtk_page_setup_set_paper_size (GtkPageSetup *setup,
189                                GtkPaperSize *size)
190 {
191   GtkPaperSize *old_size;
192
193   g_return_if_fail (GTK_IS_PAGE_SETUP (setup));
194   g_return_if_fail (size != NULL);
195
196   old_size = setup->paper_size;
197
198   setup->paper_size = gtk_paper_size_copy (size);
199
200   if (old_size)
201     gtk_paper_size_free (old_size);
202 }
203
204 /**
205  * gtk_page_setup_set_paper_size_and_default_margins:
206  * @setup: a #GtkPageSetup
207  * @size: a #GtkPaperSize 
208  * 
209  * Sets the paper size of the #GtkPageSetup and modifies
210  * the margins according to the new paper size.
211  *
212  * Since: 2.10
213  */
214 void
215 gtk_page_setup_set_paper_size_and_default_margins (GtkPageSetup *setup,
216                                                    GtkPaperSize *size)
217 {
218   gtk_page_setup_set_paper_size (setup, size);
219   setup->top_margin = gtk_paper_size_get_default_top_margin (setup->paper_size, GTK_UNIT_MM);
220   setup->bottom_margin = gtk_paper_size_get_default_bottom_margin (setup->paper_size, GTK_UNIT_MM);
221   setup->left_margin = gtk_paper_size_get_default_left_margin (setup->paper_size, GTK_UNIT_MM);
222   setup->right_margin = gtk_paper_size_get_default_right_margin (setup->paper_size, GTK_UNIT_MM);
223 }
224
225 /**
226  * gtk_page_setup_get_top_margin:
227  * @setup: a #GtkPageSetup
228  * @unit: the unit for the return value
229  * 
230  * Gets the top margin in units of @unit.
231  * 
232  * Return value: the top margin
233  *
234  * Since: 2.10
235  */
236 gdouble
237 gtk_page_setup_get_top_margin (GtkPageSetup *setup,
238                                GtkUnit       unit)
239 {
240   return _gtk_print_convert_from_mm (setup->top_margin, unit);
241 }
242
243 /**
244  * gtk_page_setup_set_top_margin:
245  * @setup: a #GtkPageSetup
246  * @margin: the new top margin in units of @unit
247  * @unit: the units for @margin
248  * 
249  * Sets the top margin of the #GtkPageSetup.
250  *
251  * Since: 2.10
252  */
253 void
254 gtk_page_setup_set_top_margin (GtkPageSetup *setup,
255                                gdouble       margin,
256                                GtkUnit       unit)
257 {
258   setup->top_margin = _gtk_print_convert_to_mm (margin, unit);
259 }
260
261 /**
262  * gtk_page_setup_get_bottom_margin:
263  * @setup: a #GtkPageSetup
264  * @unit: the unit for the return value
265  * 
266  * Gets the bottom margin in units of @unit.
267  * 
268  * Return value: the bottom margin
269  *
270  * Since: 2.10
271  */
272 gdouble
273 gtk_page_setup_get_bottom_margin (GtkPageSetup *setup,
274                                   GtkUnit       unit)
275 {
276   return _gtk_print_convert_from_mm (setup->bottom_margin, unit);
277 }
278
279 /**
280  * gtk_page_setup_set_bottom_margin:
281  * @setup: a #GtkPageSetup
282  * @margin: the new bottom margin in units of @unit
283  * @unit: the units for @margin
284  * 
285  * Sets the bottom margin of the #GtkPageSetup.
286  *
287  * Since: 2.10
288  */
289 void
290 gtk_page_setup_set_bottom_margin (GtkPageSetup *setup,
291                                   gdouble       margin,
292                                   GtkUnit       unit)
293 {
294   setup->bottom_margin = _gtk_print_convert_to_mm (margin, unit);
295 }
296
297 /**
298  * gtk_page_setup_get_left_margin:
299  * @setup: a #GtkPageSetup
300  * @unit: the unit for the return value
301  * 
302  * Gets the left margin in units of @unit.
303  * 
304  * Return value: the left margin
305  *
306  * Since: 2.10
307  */
308 gdouble
309 gtk_page_setup_get_left_margin (GtkPageSetup *setup,
310                                 GtkUnit       unit)
311 {
312   return _gtk_print_convert_from_mm (setup->left_margin, unit);
313 }
314
315 /**
316  * gtk_page_setup_set_left_margin:
317  * @setup: a #GtkPageSetup
318  * @margin: the new left margin in units of @unit
319  * @unit: the units for @margin
320  * 
321  * Sets the left margin of the #GtkPageSetup.
322  *
323  * Since: 2.10
324  */
325 void
326 gtk_page_setup_set_left_margin (GtkPageSetup *setup,
327                                 gdouble       margin,
328                                 GtkUnit       unit)
329 {
330   setup->left_margin = _gtk_print_convert_to_mm (margin, unit);
331 }
332
333 /**
334  * gtk_page_setup_get_right_margin:
335  * @setup: a #GtkPageSetup
336  * @unit: the unit for the return value
337  * 
338  * Gets the right margin in units of @unit.
339  * 
340  * Return value: the right margin
341  *
342  * Since: 2.10
343  */
344 gdouble
345 gtk_page_setup_get_right_margin (GtkPageSetup *setup,
346                                  GtkUnit       unit)
347 {
348   return _gtk_print_convert_from_mm (setup->right_margin, unit);
349 }
350
351 /**
352  * gtk_page_setup_set_right_margin:
353  * @setup: a #GtkPageSetup
354  * @margin: the new right margin in units of @unit
355  * @unit: the units for @margin
356  * 
357  * Sets the right margin of the #GtkPageSetup.
358  *
359  * Since: 2.10
360  */
361 void
362 gtk_page_setup_set_right_margin (GtkPageSetup *setup,
363                                  gdouble       margin,
364                                  GtkUnit       unit)
365 {
366   setup->right_margin = _gtk_print_convert_to_mm (margin, unit);
367 }
368
369 /**
370  * gtk_page_setup_get_paper_width:
371  * @setup: a #GtkPageSetup
372  * @unit: the unit for the return value
373  * 
374  * Returns the paper width in units of @unit.
375  * 
376  * Note that this function takes orientation, but 
377  * not margins into consideration. 
378  * See gtk_page_setup_get_page_width().
379  *
380  * Return value: the paper width.
381  *
382  * Since: 2.10
383  */
384 gdouble
385 gtk_page_setup_get_paper_width (GtkPageSetup *setup,
386                                 GtkUnit       unit)
387 {
388   if (setup->orientation == GTK_PAGE_ORIENTATION_PORTRAIT ||
389       setup->orientation == GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT)
390     return gtk_paper_size_get_width (setup->paper_size, unit);
391   else
392     return gtk_paper_size_get_height (setup->paper_size, unit);
393 }
394
395 /**
396  * gtk_page_setup_get_paper_height:
397  * @setup: a #GtkPageSetup
398  * @unit: the unit for the return value
399  * 
400  * Returns the paper height in units of @unit.
401  * 
402  * Note that this function takes orientation, but 
403  * not margins into consideration.
404  * See gtk_page_setup_get_page_height().
405  *
406  * Return value: the paper height.
407  *
408  * Since: 2.10
409  */
410 gdouble
411 gtk_page_setup_get_paper_height (GtkPageSetup *setup,
412                                  GtkUnit       unit)
413 {
414   if (setup->orientation == GTK_PAGE_ORIENTATION_PORTRAIT ||
415       setup->orientation == GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT)
416     return gtk_paper_size_get_height (setup->paper_size, unit);
417   else
418     return gtk_paper_size_get_width (setup->paper_size, unit);
419 }
420
421 /**
422  * gtk_page_setup_get_page_width:
423  * @setup: a #GtkPageSetup
424  * @unit: the unit for the return value
425  * 
426  * Returns the page width in units of @unit.
427  * 
428  * Note that this function takes orientation and
429  * margins into consideration. 
430  * See gtk_page_setup_get_paper_width().
431  *
432  * Return value: the page width.
433  *
434  * Since: 2.10
435  */
436 gdouble
437 gtk_page_setup_get_page_width (GtkPageSetup *setup,
438                                GtkUnit       unit)
439 {
440   gdouble width;
441   
442   width = gtk_page_setup_get_paper_width (setup, GTK_UNIT_MM);
443   width -= setup->left_margin + setup->right_margin;
444   
445   return _gtk_print_convert_from_mm (width, unit);
446 }
447
448 /**
449  * gtk_page_setup_get_page_height:
450  * @setup: a #GtkPageSetup
451  * @unit: the unit for the return value
452  * 
453  * Returns the page height in units of @unit.
454  * 
455  * Note that this function takes orientation and
456  * margins into consideration. 
457  * See gtk_page_setup_get_paper_height().
458  *
459  * Return value: the page height.
460  *
461  * Since: 2.10
462  */
463 gdouble
464 gtk_page_setup_get_page_height (GtkPageSetup *setup,
465                                 GtkUnit       unit)
466 {
467   gdouble height;
468   
469   height = gtk_page_setup_get_paper_height (setup, GTK_UNIT_MM);
470   height -= setup->top_margin + setup->bottom_margin;
471   
472   return _gtk_print_convert_from_mm (height, unit);
473 }
474
475 /**
476  * gtk_page_setup_load_file:
477  * @setup: a #GtkPageSetup
478  * @file_name: the filename to read the page setup from
479  * @error: return location for an error, or %NULL
480  *
481  * Reads the page setup from the file @file_name.
482  * See gtk_page_setup_load_file().
483  *
484  * Return value: %TRUE on success
485  *
486  * Since: 2.14
487  */
488 gboolean
489 gtk_page_setup_load_file (GtkPageSetup *setup,
490                           const gchar  *file_name,
491                           GError      **error)
492 {
493   gboolean retval = FALSE;
494   GKeyFile *key_file;
495
496   g_return_val_if_fail (GTK_IS_PAGE_SETUP (setup), FALSE);
497   g_return_val_if_fail (file_name != NULL, FALSE);
498
499   key_file = g_key_file_new ();
500
501   if (g_key_file_load_from_file (key_file, file_name, 0, error) &&
502       gtk_page_setup_load_key_file (setup, key_file, NULL, error))
503     retval = TRUE;
504
505   g_key_file_free (key_file);
506
507   return retval;
508 }
509
510 /**
511  * gtk_page_setup_new_from_file:
512  * @file_name: the filename to read the page setup from
513  * @error: return location for an error, or %NULL
514  * 
515  * Reads the page setup from the file @file_name. Returns a 
516  * new #GtkPageSetup object with the restored page setup, 
517  * or %NULL if an error occurred. See gtk_page_setup_to_file().
518  *
519  * Return value: the restored #GtkPageSetup
520  * 
521  * Since: 2.12
522  */
523 GtkPageSetup *
524 gtk_page_setup_new_from_file (const gchar  *file_name,
525                               GError      **error)
526 {
527   GtkPageSetup *setup = gtk_page_setup_new ();
528
529   if (!gtk_page_setup_load_file (setup, file_name, error))
530     {
531       g_object_unref (setup);
532       setup = NULL;
533     }
534
535   return setup;
536 }
537
538 /* something like this should really be in gobject! */
539 static guint
540 string_to_enum (GType type,
541                 const char *enum_string)
542 {
543   GEnumClass *enum_class;
544   const GEnumValue *value;
545   guint retval = 0;
546
547   g_return_val_if_fail (enum_string != NULL, 0);
548
549   enum_class = g_type_class_ref (type);
550   value = g_enum_get_value_by_nick (enum_class, enum_string);
551   if (value)
552     retval = value->value;
553
554   g_type_class_unref (enum_class);
555
556   return retval;
557 }
558
559 /**
560  * gtk_page_setup_load_key_file:
561  * @setup: a #GtkPageSetup
562  * @key_file: the #GKeyFile to retrieve the page_setup from
563  * @group_name: the name of the group in the key_file to read, or %NULL
564  *              to use the default name "Page Setup"
565  * @error: return location for an error, or %NULL
566  * 
567  * Reads the page setup from the group @group_name in the key file
568  * @key_file.
569  * 
570  * Return value: %TRUE on success
571  *
572  * Since: 2.14
573  */
574 gboolean
575 gtk_page_setup_load_key_file (GtkPageSetup *setup,
576                               GKeyFile     *key_file,
577                               const gchar  *group_name,
578                               GError      **error)
579 {
580   GtkPaperSize *paper_size;
581   gdouble top, bottom, left, right;
582   char *orientation = NULL, *freeme = NULL;
583   gboolean retval = FALSE;
584   GError *err = NULL;
585
586   g_return_val_if_fail (GTK_IS_PAGE_SETUP (setup), FALSE);
587   g_return_val_if_fail (key_file != NULL, FALSE);
588
589   if (!group_name)
590     group_name = KEYFILE_GROUP_NAME;
591
592   if (!g_key_file_has_group (key_file, group_name))
593     {
594       g_set_error_literal (error,
595                            GTK_PRINT_ERROR,
596                            GTK_PRINT_ERROR_INVALID_FILE,
597                            _("Not a valid page setup file"));
598       goto out;
599     }
600
601 #define GET_DOUBLE(kf, group, name, v) \
602   v = g_key_file_get_double (kf, group, name, &err); \
603   if (err != NULL) \
604     { \
605       g_propagate_error (error, err);\
606       goto out;\
607     }
608
609   GET_DOUBLE (key_file, group_name, "MarginTop", top);
610   GET_DOUBLE (key_file, group_name, "MarginBottom", bottom);
611   GET_DOUBLE (key_file, group_name, "MarginLeft", left);
612   GET_DOUBLE (key_file, group_name, "MarginRight", right);
613
614 #undef GET_DOUBLE
615
616   paper_size = gtk_paper_size_new_from_key_file (key_file, group_name, &err);
617   if (!paper_size)
618     {
619       g_propagate_error (error, err);
620       goto out;
621     }
622
623   gtk_page_setup_set_paper_size (setup, paper_size);
624   gtk_paper_size_free (paper_size);
625
626   gtk_page_setup_set_top_margin (setup, top, GTK_UNIT_MM);
627   gtk_page_setup_set_bottom_margin (setup, bottom, GTK_UNIT_MM);
628   gtk_page_setup_set_left_margin (setup, left, GTK_UNIT_MM);
629   gtk_page_setup_set_right_margin (setup, right, GTK_UNIT_MM);
630
631   orientation = g_key_file_get_string (key_file, group_name,
632                                        "Orientation", NULL);
633   if (orientation)
634     {
635       gtk_page_setup_set_orientation (setup,
636                                       string_to_enum (GTK_TYPE_PAGE_ORIENTATION,
637                                                       orientation));
638       g_free (orientation);
639     }
640
641   retval = TRUE;
642
643 out:
644   g_free (freeme);
645   return retval;
646 }
647
648 /**
649  * gtk_page_setup_new_from_key_file:
650  * @key_file: the #GKeyFile to retrieve the page_setup from
651  * @group_name: the name of the group in the key_file to read, or %NULL
652  *              to use the default name "Page Setup"
653  * @error: return location for an error, or %NULL
654  *
655  * Reads the page setup from the group @group_name in the key file
656  * @key_file. Returns a new #GtkPageSetup object with the restored
657  * page setup, or %NULL if an error occurred.
658  *
659  * Return value: the restored #GtkPageSetup
660  *
661  * Since: 2.12
662  */
663 GtkPageSetup *
664 gtk_page_setup_new_from_key_file (GKeyFile     *key_file,
665                                   const gchar  *group_name,
666                                   GError      **error)
667 {
668   GtkPageSetup *setup = gtk_page_setup_new ();
669
670   if (!gtk_page_setup_load_key_file (setup, key_file, group_name, error))
671     {
672       g_object_unref (setup);
673       setup = NULL;
674     }
675
676   return setup;
677 }
678
679 /**
680  * gtk_page_setup_to_file:
681  * @setup: a #GtkPageSetup
682  * @file_name: the file to save to
683  * @error: return location for errors, or %NULL
684  * 
685  * This function saves the information from @setup to @file_name.
686  * 
687  * Return value: %TRUE on success
688  *
689  * Since: 2.12
690  */
691 gboolean
692 gtk_page_setup_to_file (GtkPageSetup  *setup,
693                         const char    *file_name,
694                         GError       **error)
695 {
696   GKeyFile *key_file;
697   gboolean retval = FALSE;
698   char *data = NULL;
699   gsize len;
700
701   g_return_val_if_fail (GTK_IS_PAGE_SETUP (setup), FALSE);
702   g_return_val_if_fail (file_name != NULL, FALSE);
703
704   key_file = g_key_file_new ();
705   gtk_page_setup_to_key_file (setup, key_file, NULL);
706
707   data = g_key_file_to_data (key_file, &len, error);
708   if (!data)
709     goto out;
710
711   retval = g_file_set_contents (file_name, data, len, error);
712
713 out:
714   g_key_file_free (key_file);
715   g_free (data);
716
717   return retval;
718 }
719
720 /* something like this should really be in gobject! */
721 static char *
722 enum_to_string (GType type,
723                 guint enum_value)
724 {
725   GEnumClass *enum_class;
726   GEnumValue *value;
727   char *retval = NULL;
728
729   enum_class = g_type_class_ref (type);
730
731   value = g_enum_get_value (enum_class, enum_value);
732   if (value)
733     retval = g_strdup (value->value_nick);
734
735   g_type_class_unref (enum_class);
736
737   return retval;
738 }
739
740 /**
741  * gtk_page_setup_to_key_file:
742  * @setup: a #GtkPageSetup
743  * @key_file: the #GKeyFile to save the page setup to
744  * @group_name: the group to add the settings to in @key_file, 
745  *      or %NULL to use the default name "Page Setup"
746  * 
747  * This function adds the page setup from @setup to @key_file.
748  * 
749  * Since: 2.12
750  */
751 void
752 gtk_page_setup_to_key_file (GtkPageSetup *setup,
753                             GKeyFile     *key_file,
754                             const gchar  *group_name)
755 {
756   GtkPaperSize *paper_size;
757   char *orientation;
758
759   g_return_if_fail (GTK_IS_PAGE_SETUP (setup));
760   g_return_if_fail (key_file != NULL);
761
762   if (!group_name)
763     group_name = KEYFILE_GROUP_NAME;
764
765   paper_size = gtk_page_setup_get_paper_size (setup);
766   g_assert (paper_size != NULL);
767
768   gtk_paper_size_to_key_file (paper_size, key_file, group_name);
769
770   g_key_file_set_double (key_file, group_name,
771                          "MarginTop", gtk_page_setup_get_top_margin (setup, GTK_UNIT_MM));
772   g_key_file_set_double (key_file, group_name,
773                          "MarginBottom", gtk_page_setup_get_bottom_margin (setup, GTK_UNIT_MM));
774   g_key_file_set_double (key_file, group_name,
775                          "MarginLeft", gtk_page_setup_get_left_margin (setup, GTK_UNIT_MM));
776   g_key_file_set_double (key_file, group_name,
777                          "MarginRight", gtk_page_setup_get_right_margin (setup, GTK_UNIT_MM));
778
779   orientation = enum_to_string (GTK_TYPE_PAGE_ORIENTATION,
780                                 gtk_page_setup_get_orientation (setup));
781   g_key_file_set_string (key_file, group_name,
782                          "Orientation", orientation);
783   g_free (orientation);
784 }
785
786 #define __GTK_PAGE_SETUP_C__
787 #include "gtkaliasdef.c"