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