Debian Codegraph @

gtk/src/papersize.ccg

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 #include <glibmm/vectorutils.h>
18
19 #include <gtk/gtk.h>
20
21 namespace Gtk
22 {
23 // Initialize external constants.
24 const Glib::ustring PAPER_NAME_A3 = GTK_PAPER_NAME_A3;
25 const Glib::ustring PAPER_NAME_A4 = GTK_PAPER_NAME_A4;
26 const Glib::ustring PAPER_NAME_A5 = GTK_PAPER_NAME_A5;
27 const Glib::ustring PAPER_NAME_B5 = GTK_PAPER_NAME_B5;
28 const Glib::ustring PAPER_NAME_LETTER = GTK_PAPER_NAME_LETTER;
29 const Glib::ustring PAPER_NAME_EXECUTIVE = GTK_PAPER_NAME_EXECUTIVE;
30 const Glib::ustring PAPER_NAME_LEGAL = GTK_PAPER_NAME_LEGAL;
31
32 //PaperSize::PaperSize()
33 //:
34 // gobject_(gtk_paper_size_new(gtk_paper_size_get_default()))
35 //{}
36
37 PaperSize::PaperSize(const Glib::ustring& name)
38 :
39 gobject_(gtk_paper_size_new(name.c_str()))
40 {}
41
42 PaperSize::PaperSize(const Glib::ustring& ppd_name, const Glib::ustring& ppd_display_name, double width, double height)
43 :
44 gobject_(gtk_paper_size_new_from_ppd(ppd_name.c_str(),
45 ppd_display_name.c_str(),
46 gdouble(width),
47 gdouble(height)))
48 {}
49
50 PaperSize::PaperSize(const Glib::ustring& name, const Glib::ustring& display_name, double width, double height, Unit unit)
51 :
52 gobject_(gtk_paper_size_new_custom(name.c_str(),
53 display_name.c_str(),
54 gdouble(width),
55 gdouble(height),
56 GtkUnit(unit)))
57 {}
58
59 //TODO: Add an operator bool() so we can detect if this succeeded:
60 //TODO: No, throw the error/exception instead.
61 PaperSize::PaperSize(const Glib::KeyFile& key_file, const Glib::ustring& group_name)
62 :
63 gobject_(gtk_paper_size_new_from_key_file(const_cast<GKeyFile*>(key_file.gobj()), (group_name.empty() ? nullptr : group_name.c_str()) , nullptr /* GError */))
64 {}
65
66 bool PaperSize::equal(const PaperSize& other) const
67 {
68 return (static_cast<bool>(gtk_paper_size_is_equal(const_cast<GtkPaperSize*>(this->gobj()),
69 const_cast<GtkPaperSize*>(other.gobj()))));
70 }
71
72 _DEPRECATE_IFDEF_START
73 PaperSize::operator const void*() const
74 {
75 return gobj() ? GINT_TO_POINTER(1) : nullptr;
76 }
77 _DEPRECATE_IFDEF_END
78
79 PaperSize::operator bool() const
80 {
81 return gobj();
82 }
83
84 void PaperSize::save_to_key_file(Glib::KeyFile& key_file)
85 {
86 gtk_paper_size_to_key_file( gobj(), (key_file).gobj(), nullptr);
87 }
88
89 } // namespace Gtk