add new sigc++2 directory
[ardour.git] / libs / gtkmm2 / gtk / src / printsettings.ccg
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 Library General Public
5  * License as published by the Free Software Foundation; either
6  * version 2 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  * Library General Public License for more details.
12  *
13  * You should have received a copy of the GNU Library 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 <gtk/gtkprintsettings.h>
19 #include <gtk/gtktypebuiltins.h>
20
21 #include <vector>
22
23 #include <glib/gmem.h>
24
25 namespace // anonymous
26 {
27
28 static void proxy_foreach_callback(const gchar* key, const gchar* value, void* data)
29 {
30   typedef Gtk::PrintSettings::SlotForeach SlotType;
31   SlotType& slot = *static_cast<SlotType*>(data);
32
33   #ifdef GLIBMM_EXCEPTIONS_ENABLED
34   try
35   {
36   #endif //GLIBMM_EXCEPTIONS_ENABLED
37     slot(Glib::convert_const_gchar_ptr_to_ustring(key), Glib::convert_const_gchar_ptr_to_ustring(value));
38   #ifdef GLIBMM_EXCEPTIONS_ENABLED
39   }
40   catch(...)
41   {
42     Glib::exception_handlers_invoke();
43   }
44   #endif //GLIBMM_EXCEPTIONS_ENABLED
45 }
46
47 } // anonymous namespace
48
49 namespace Gtk
50 {
51
52 //Initialize static members:
53 const Glib::ustring PrintSettings::Keys::PRINTER = GTK_PRINT_SETTINGS_PRINTER;
54 const Glib::ustring PrintSettings::Keys::ORIENTATION = GTK_PRINT_SETTINGS_ORIENTATION;
55 const Glib::ustring PrintSettings::Keys::PAPER_FORMAT = GTK_PRINT_SETTINGS_PAPER_FORMAT;
56 const Glib::ustring PrintSettings::Keys::PAPER_WIDTH = GTK_PRINT_SETTINGS_PAPER_WIDTH;
57 const Glib::ustring PrintSettings::Keys::PAPER_HEIGHT = GTK_PRINT_SETTINGS_PAPER_HEIGHT;
58 const Glib::ustring PrintSettings::Keys::NUM_COPIES = GTK_PRINT_SETTINGS_N_COPIES;
59 const Glib::ustring PrintSettings::Keys::DEFAULT_SOURCE = GTK_PRINT_SETTINGS_DEFAULT_SOURCE;
60 const Glib::ustring PrintSettings::Keys::QUALITY = GTK_PRINT_SETTINGS_QUALITY;
61 const Glib::ustring PrintSettings::Keys::RESOLUTION = GTK_PRINT_SETTINGS_RESOLUTION;
62 const Glib::ustring PrintSettings::Keys::USE_COLOR = GTK_PRINT_SETTINGS_USE_COLOR;
63 const Glib::ustring PrintSettings::Keys::DUPLEX = GTK_PRINT_SETTINGS_DUPLEX;
64 const Glib::ustring PrintSettings::Keys::COLLATE = GTK_PRINT_SETTINGS_COLLATE;
65 const Glib::ustring PrintSettings::Keys::REVERSE = GTK_PRINT_SETTINGS_REVERSE;
66 const Glib::ustring PrintSettings::Keys::MEDIA_TYPE = GTK_PRINT_SETTINGS_MEDIA_TYPE;
67 const Glib::ustring PrintSettings::Keys::DITHER = GTK_PRINT_SETTINGS_DITHER;
68 const Glib::ustring PrintSettings::Keys::SCALE = GTK_PRINT_SETTINGS_SCALE;
69 const Glib::ustring PrintSettings::Keys::PRINT_PAGES = GTK_PRINT_SETTINGS_PRINT_PAGES;
70 const Glib::ustring PrintSettings::Keys::PAGE_RANGES = GTK_PRINT_SETTINGS_PAGE_RANGES;
71 const Glib::ustring PrintSettings::Keys::PAGE_SET = GTK_PRINT_SETTINGS_PAGE_SET;
72 const Glib::ustring PrintSettings::Keys::FINISHINGS = GTK_PRINT_SETTINGS_FINISHINGS;
73 const Glib::ustring PrintSettings::Keys::NUMBER_UP = GTK_PRINT_SETTINGS_NUMBER_UP;
74 const Glib::ustring PrintSettings::Keys::OUTPUT_BIN = GTK_PRINT_SETTINGS_OUTPUT_BIN;
75
76 const Glib::ustring PrintSettings::Keys::OUTPUT_FILE_FORMAT = GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT;
77 const Glib::ustring PrintSettings::Keys::OUTPUT_URI = GTK_PRINT_SETTINGS_OUTPUT_URI;
78
79 const Glib::ustring PrintSettings::Keys::WIN32_DRIVER_VERSION = GTK_PRINT_SETTINGS_WIN32_DRIVER_VERSION;
80 const Glib::ustring PrintSettings::Keys::WIN32_DRIVER_EXTRA = GTK_PRINT_SETTINGS_WIN32_DRIVER_EXTRA;
81
82
83 void PrintSettings::setting_foreach(const SlotForeach& slot)
84 {
85   SlotForeach slot_copy(slot);
86   gtk_print_settings_foreach(const_cast<GtkPrintSettings*>(gobj()), &proxy_foreach_callback, &slot_copy);
87 }
88
89 PrintSettings::PageRange::PageRange()
90 :
91   start(0),
92   end(0)
93 {}
94
95 PrintSettings::PageRange::PageRange(int start_, int end_)
96 :
97   start(start_),
98   end(end_)
99 {}
100
101 Glib::ArrayHandle<PrintSettings::PageRange> PrintSettings::get_page_ranges() const
102 {
103   int num_ranges;
104   GtkPageRange* page_ranges =
105     gtk_print_settings_get_page_ranges(const_cast<GtkPrintSettings*>(gobj()), &num_ranges);
106   std::vector<PrintSettings::PageRange> v(num_ranges);
107
108   for (int i = 0; i < num_ranges; ++i)
109   {
110     v.push_back(PrintSettings::PageRange(page_ranges[i].start, page_ranges[i].end));
111   }
112
113   g_free(page_ranges);
114
115   Glib::ArrayHandle<PrintSettings::PageRange> ah(v);
116
117   return ah;
118 }
119
120 void PrintSettings::set_page_ranges(const Glib::ArrayHandle<PrintSettings::PageRange>& page_ranges)
121 {
122   int n = page_ranges.size();
123   GtkPageRange* ranges = g_new0(GtkPageRange, n);
124   std::vector<PrintSettings::PageRange> v_ranges(page_ranges);
125
126   for (int i = 0; i < n; ++i)
127   {
128     ranges[i].start = v_ranges[i].start;
129     ranges[i].end = v_ranges[i].end;
130   }
131
132   gtk_print_settings_set_page_ranges(const_cast<GtkPrintSettings*>(gobj()), ranges, n);
133   g_free(ranges);
134 }
135
136 void PrintSettings::save_to_key_file(Glib::KeyFile& key_file)
137 {
138   gtk_print_settings_to_key_file(gobj(), (key_file).gobj(), 0); 
139 }
140
141 } // namespace Gtk