Debian Codegraph @

gtk/src/printjob.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 <gtk/gtkunixprint.h>
18
19 // This Signal Proxy allows the C++ coder to specify a sigc::slot instead of a static function.
20
21 static void SignalProxy_Custom_gtk_callback(GtkPrintJob* print_job, gpointer data, const GError* gerror)
22 {
23 const auto the_slot = static_cast<Gtk::PrintJob::SlotPrintJobComplete*>(data);
24
25 try
26 {
27 if (gerror)
28 Glib::Error::throw_exception(g_error_copy(gerror));
29
30 // Create a suitable C++ instance to pass to the C++ method;
31 auto job = Glib::wrap(print_job);
32 (*the_slot)(job);
33 }
34 catch(...)
35 {
36 Glib::exception_handlers_invoke();
37 }
38 }
39
40 static void SignalProxy_Custom_gtk_callback_destroy(void* data)
41 {
42 delete static_cast<Gtk::PrintJob::SlotPrintJobComplete*>(data);
43 }
44
45 namespace Gtk
46 {
47
48 void PrintJob::send(const SlotPrintJobComplete& slot)
49 {
50 // Create a copy of the slot. A pointer to this will be passed through the callback's data parameter.
51 // It will be deleted when SignalProxy_Custom_gtk_callback_destroy() is called.
52 auto slot_copy = new SlotPrintJobComplete(slot);
53
54 gtk_print_job_send(gobj(), &SignalProxy_Custom_gtk_callback, slot_copy, &SignalProxy_Custom_gtk_callback_destroy);
55 }
56
57 std::vector<PrintSettings::PageRange> PrintJob::get_page_ranges() const
58 {
59 int num_ranges (0);
60 GtkPageRange* page_ranges =
61 gtk_print_job_get_page_ranges(const_cast<GtkPrintJob*>(gobj()), &num_ranges);
62
63 // no need for deep ownership.
64 return Glib::ArrayHandler<PrintSettings::PageRange, PrintSettings::PageRangeTraits>::array_to_vector(page_ranges, num_ranges, Glib::OWNERSHIP_SHALLOW);
65 }
66
67 void PrintJob::set_page_ranges(const std::vector<PrintSettings::PageRange>& page_ranges)
68 {
69 gtk_print_job_set_page_ranges(gobj(),
70 Glib::ArrayHandler<PrintSettings::PageRange, PrintSettings::PageRangeTraits>::vector_to_array(page_ranges).data (),
71 page_ranges.size ());
72 }
73
74 } // namespace Gtk