1/* Copyright (C) 2006 The gtkmm Development Team
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free
15 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 */
17
18#include <glibmm/object.h>
19#include <gtkmm/enums.h>
20#include <gtkmm/papersize.h>
21
22_DEFS(gtkmm,gtk)
23_PINCLUDE(glibmm/private/object_p.h)
24
25namespace Gtk
26{
27
28/** A PageSetup object stores the page size, orientation and margins. You can get one of these from the page setup dialog
29 * and then pass it to the PrintOperation when printing. The benefit of splitting this out of the PrintSettings is that
30 * these affect the actual layout of the page, and thus need to be set long before the user prints.
31 *
32 * The margins specified in this object are the "print margins", i.e. the parts of the page that the printer cannot print
33 * on. These are different from the layout margins that a word processor uses; they are typically used to determine the
34 * minimal size for the layout margins.
35 *
36 * To obtain a PageSetup use PageSetup::create() to get the defaults, or use run_page_setup_dialog() to show the page
37 * setup dialog and receive the resulting page setup.
38 *
39 * @newin{2,10}
40 *
41 * @ingroup Printing
42 */
43class PageSetup : public Glib::Object
44{
45  _CLASS_GOBJECT(PageSetup, GtkPageSetup, GTK_PAGE_SETUP, Glib::Object, GObject)
46protected:
47  _CTOR_DEFAULT
48
49public:
50  _WRAP_CREATE()
51
52 /** Reads the page setup from the "Page Setup" group in the key file @a key_file.
53  * Returns a new PageSetup object with the restored
54  * page setup, or an empty RefPtr if an error occurred.
55  *
56  * @param key_file The KeyFile to retrieve the page setup from.
57  * @result The restored PageSetup
58  *
59  * @throws KeyFileError
60  *
61  * @newin{2,14}
62  */
63  static Glib::RefPtr<PageSetup> create_from_key_file(const Glib::KeyFile& key_file);
64
65 /** Reads the page setup from the group @a group_name in the key file @a key_file.
66  * Returns a new PageSetup object with the restored
67  * page setup, or an empty RefPtr if an error occurred.
68  *
69  * @param key_file The KeyFile to retrieve the page setup from.
70  * @param group_name The name of the group in the key_file to read.
71  * @result The restored PageSetup
72  *
73  * @throws KeyFileError
74  *
75  * @newin{2,14}
76  */
77  static Glib::RefPtr<PageSetup> create_from_key_file(const Glib::KeyFile& key_file, const Glib::ustring& group_name);
78  _IGNORE(gtk_page_setup_new_from_key_file)
79
80 /** Reads the page setup from the file @file_name. Returns a
81  * new PageSetup object with the restored page setup,
82  * or an empty RefPtr if an error occurred. See save_to_file().
83  *
84  * @param file_name The filename to read the page setup from.
85  * @result The restored PageSetup
86  *
87  * @newin{2,14}
88  */
89  static Glib::RefPtr<PageSetup> create_from_file(const std::string& file_name);
90  _IGNORE(gtk_page_setup_new_from_file)
91
92  _WRAP_METHOD(Glib::RefPtr<PageSetup> copy() const, gtk_page_setup_copy)
93
94  //The from_ infix was added to these functions to make them clearer. GTK+ didn't want to change them.
95  _WRAP_METHOD(bool load_from_file(const std::string& file_name), gtk_page_setup_load_file, errthrow)
96
97  #m4 _CONVERSION(`const Glib::KeyFile&', `GKeyFile*', __FCR2P)
98  _WRAP_METHOD(bool load_from_key_file(const Glib::KeyFile& key_file, const Glib::ustring& group_name), gtk_page_setup_load_key_file, errthrow)
99
100 /** Reads the page setup from the "Page Setup" group in the key file @a key_file.
101  *
102  * @param key_file The KeyFile to retrieve the page setup from.
103  * @result true on success
104  *
105  * @throws KeyFileError
106  *
107  * @newin{2,14}
108  */
109  bool load_from_key_file(const Glib::KeyFile& key_file);
110
111  _WRAP_METHOD(PageOrientation get_orientation() const, gtk_page_setup_get_orientation)
112  _WRAP_METHOD(void set_orientation(PageOrientation orientation), gtk_page_setup_set_orientation)
113
114  _WRAP_METHOD(PaperSize get_paper_size(), gtk_page_setup_get_paper_size)
115  _WRAP_METHOD(const PaperSize get_paper_size() const, gtk_page_setup_get_paper_size, constversion)
116  _WRAP_METHOD(void set_paper_size(const PaperSize& paper_size), gtk_page_setup_set_paper_size)
117
118  _WRAP_METHOD(double get_top_margin(Unit unit) const, gtk_page_setup_get_top_margin)
119  _WRAP_METHOD(void set_top_margin(double margin, Unit unit), gtk_page_setup_set_top_margin)
120
121  _WRAP_METHOD(double get_bottom_margin(Unit unit) const, gtk_page_setup_get_bottom_margin)
122  _WRAP_METHOD(void set_bottom_margin(double margin, Unit unit), gtk_page_setup_set_bottom_margin)
123
124  _WRAP_METHOD(double get_left_margin(Unit unit) const, gtk_page_setup_get_left_margin)
125  _WRAP_METHOD(void set_left_margin(double margin, Unit unit), gtk_page_setup_set_left_margin)
126
127  _WRAP_METHOD(double get_right_margin(Unit unit) const, gtk_page_setup_get_right_margin)
128  _WRAP_METHOD(void set_right_margin(double margin, Unit unit), gtk_page_setup_set_right_margin)
129
130  _WRAP_METHOD(void set_paper_size_and_default_margins(const PaperSize& paper_size),
131               gtk_page_setup_set_paper_size_and_default_margins)
132
133  _WRAP_METHOD(double get_paper_width(Unit unit) const, gtk_page_setup_get_paper_width)
134  _WRAP_METHOD(double get_paper_height(Unit unit) const, gtk_page_setup_get_paper_height)
135
136  _WRAP_METHOD(double get_page_width(Unit unit) const, gtk_page_setup_get_page_width)
137  _WRAP_METHOD(double get_page_height(Unit unit) const, gtk_page_setup_get_page_height)
138
139  //The save_ prefix was added to these functions to make them clearer. GTK+ didn't want to change them.
140  _WRAP_METHOD(bool save_to_file(const std::string& file_name) const, gtk_page_setup_to_file, errthrow)
141
142  #m4 _CONVERSION(`Glib::KeyFile&', `GKeyFile*', __FR2P)
143  _WRAP_METHOD(void save_to_key_file(Glib::KeyFile& key_file, const Glib::ustring& group_name), gtk_page_setup_to_key_file, deprecated "Use the const version.")
144  _WRAP_METHOD(void save_to_key_file(Glib::KeyFile& key_file, const Glib::ustring& group_name) const, gtk_page_setup_to_key_file)
145
146  #ifndef GTKMM_DISABLE_DEPRECATED
147  /** This function adds the page setup from @a setup to @a key_file,
148   * in the group "Page Setup"
149   *
150   * @newin{2,12}
151   * @param key_file The G::KeyFile to save the page setup to.
152   *
153   * @deprecated Use the const version.
154   */
155  void save_to_key_file(Glib::KeyFile& key_file);
156  #endif //GTKMM_DISABLE_DEPRECATED
157
158  /** This function adds the page setup from @a setup to @a key_file,
159   * in the group "Page Setup"
160   *
161   * @newin{2,12}
162   * @param key_file The G::KeyFile to save the page setup to.
163   */
164  void save_to_key_file(Glib::KeyFile& key_file) const;
165};
166
167} // namespace Gtk
168