Debian Codegraph @

gtk/src/papersize.hg

raw
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, see <https://www.gnu.org/licenses/>.
15 */
16
17 _CONFIGINCLUDE(gtkmmconfig.h)
18
19 _DEFS(gtkmm,gtk)
20
21 #include <glibmm/keyfile.h>
22 #include <vector>
23
24 namespace Gtk
25 {
26
27 #ifndef DOXYGEN_SHOULD_SKIP_THIS
28 struct PaperSizeTraits;
29 #endif
30
31 /** Common paper names, from PWG 5101.1-2002 PWG: Standard for Media Standardized Names
32 */
33 extern GTKMM_API const Glib::ustring PAPER_NAME_A3;
34 extern GTKMM_API const Glib::ustring PAPER_NAME_A4;
35 extern GTKMM_API const Glib::ustring PAPER_NAME_A5;
36 extern GTKMM_API const Glib::ustring PAPER_NAME_B5;
37 extern GTKMM_API const Glib::ustring PAPER_NAME_LETTER;
38 extern GTKMM_API const Glib::ustring PAPER_NAME_EXECUTIVE;
39 extern GTKMM_API const Glib::ustring PAPER_NAME_LEGAL;
40
41 _WRAP_ENUM(Unit, GtkUnit, decl_prefix GTKMM_API)
42
43 /** PaperSize handles paper sizes. It uses the standard called "PWG 5101.1-2002 PWG: Standard for Media Standardized Names"
44 * to name the paper sizes (and to get the data for the page sizes). In addition to standard paper sizes, PaperSize allows
45 * to construct custom paper sizes with arbitrary dimensions.
46 *
47 * The PaperSize object stores not only the dimensions (width and height) of a paper size and its name, it also provides
48 * default print margins.
49 *
50 * @newin{2,10}
51 *
52 * @ingroup Printing
53 */
54 class GTKMM_API PaperSize
55 {
56 // Cannot pass the _new function here, it must accept the 'name' argument.
57 _CLASS_BOXEDTYPE(PaperSize, GtkPaperSize, NONE, gtk_paper_size_copy, gtk_paper_size_free, GTKMM_API)
58 public:
59
60 // We don't use a "" default parameter value, though gtk_paper_size_new() can take NULL,
61 // because there is already a (desired) default constructor (creating an invalid instance).
62 // get_default() does what name="" would do.
63 explicit PaperSize(const Glib::ustring& name);
64 explicit PaperSize(const Glib::ustring& ppd_name, const Glib::ustring& ppd_display_name, double width, double height);
65 explicit PaperSize(const Glib::ustring& name, const Glib::ustring& display_name, double width, double height, Unit unit);
66
67 explicit PaperSize(const Glib::KeyFile& key_file, const Glib::ustring& group_name = Glib::ustring());
68
69 _IGNORE(gtk_paper_size_copy, gtk_paper_size_free, gtk_paper_size_is_equal)
70 bool equal(const PaperSize& other) const;
71
72 _DEPRECATE_IFDEF_START
73 /** This typedef is just to make it more obvious that
74 * our operator const void* should be used like operator bool().
75 *
76 * @deprecated Use the explicit operator bool() instead.
77 */
78 typedef const void* BoolExpr;
79
80 /** Returns true if the PaperSize is a valid object.
81 * For instance,
82 * @code
83 * if(papersize)
84 * do_something()
85 * @endcode
86 *
87 * @deprecated Use the explicit operator bool() instead.
88 *
89 * @newin{2,12}
90 */
91 operator BoolExpr() const;
92 _DEPRECATE_IFDEF_END
93
94 /** Returns true if the PaperSize is a valid object.
95 * For instance,
96 * @code
97 * if(papersize)
98 * do_something()
99 * @endcode
100 *
101 * @newin{3,22}
102 */
103 explicit operator bool() const;
104
105 #m4 _CONVERSION(`GList*', `std::vector<PaperSize>',`Glib::ListHandler<PaperSize, PaperSizeTraits>::list_to_vector($3, Glib::OWNERSHIP_DEEP)')
106 _WRAP_METHOD(static std::vector<PaperSize> get_paper_sizes(bool include_custom = true), gtk_paper_size_get_paper_sizes)
107
108 _WRAP_METHOD(Glib::ustring get_name() const, gtk_paper_size_get_name)
109 _WRAP_METHOD(Glib::ustring get_display_name() const, gtk_paper_size_get_display_name)
110 _WRAP_METHOD(Glib::ustring get_ppd_name() const, gtk_paper_size_get_ppd_name)
111
112 _WRAP_METHOD(double get_width(Unit unit) const, gtk_paper_size_get_width)
113 _WRAP_METHOD(double get_height(Unit unit) const, gtk_paper_size_get_height)
114 _WRAP_METHOD(bool is_custom() const, gtk_paper_size_is_custom)
115 _WRAP_METHOD(bool is_ipp() const, gtk_paper_size_is_ipp)
116
117 _WRAP_METHOD(void set_size(double width, double height, Unit unit), gtk_paper_size_set_size)
118 _WRAP_METHOD(double get_default_top_margin(Unit unit) const, gtk_paper_size_get_default_top_margin)
119 _WRAP_METHOD(double get_default_bottom_margin(Unit unit) const, gtk_paper_size_get_default_bottom_margin)
120 _WRAP_METHOD(double get_default_left_margin(Unit unit) const, gtk_paper_size_get_default_left_margin)
121 _WRAP_METHOD(double get_default_right_margin(Unit unit) const, gtk_paper_size_get_default_right_margin)
122
123 _WRAP_METHOD(static Glib::ustring get_default(), gtk_paper_size_get_default)
124
125 #m4 _CONVERSION(`Glib::KeyFile&', `GKeyFile*', __FR2P)
126 _WRAP_METHOD(void save_to_key_file(Glib::KeyFile& key_file, const Glib::ustring& group_name), gtk_paper_size_to_key_file)
127
128 /** This function adds the paper size to @a key_file in the first group.
129 *
130 * @newin{2,12}
131 *
132 * @param key_file The Glib::KeyFile to save the paper size to.
133 */
134 void save_to_key_file(Glib::KeyFile& key_file);
135 };
136
137 /** @relates Gtk::PaperSize */
138 inline bool operator==(const PaperSize& lhs, const PaperSize& rhs)
139 { return lhs.equal(rhs); }
140
141 /** @relates Gtk::PaperSize */
142 inline bool operator!=(const PaperSize& lhs, const PaperSize& rhs)
143 { return !lhs.equal(rhs); }
144
145 #ifndef DOXYGEN_SHOULD_SKIP_THIS
146 struct PaperSizeTraits
147 {
148 typedef PaperSize CppType;
149 typedef const GtkPaperSize* CType;
150 typedef GtkPaperSize* CTypeNonConst;
151
152 static CType to_c_type (const CppType& obj) { return obj.gobj(); }
153 static CType to_c_type (CType ptr) { return ptr; }
154 static CppType to_cpp_type (CType ptr) { return PaperSize(const_cast<GtkPaperSize*>(ptr), true /* make_copy */); /* Does not take ownership */ }
155 static void release_c_type (CType /* ptr */) { /* Doesn't happen */ }
156 };
157 #endif //DOXYGEN_SHOULD_SKIP_THIS
158
159 } // namespace Gtk