Debian Codegraph @

gtk/src/printer.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/gtkunixprint.h>
20
21 // This Signal Proxy allows the C++ coder to specify a sigc::slot instead of a static function.
22
23 static gboolean SignalProxy_Custom_gtk_callback(GtkPrinter* gtk_printer, gpointer data)
24 {
25 const auto the_slot = static_cast<Gtk::SlotPrinterEnumerator*>(data);
26
27 try
28 {
29 // Create a suitable C++ instance to pass to the C++ method;
30 auto printer = Glib::wrap(gtk_printer, true);
31
32 return (*the_slot)(printer);
33 }
34 catch(...)
35 {
36 Glib::exception_handlers_invoke();
37 return false; // arbitrary default;
38 }
39 }
40
41 static void SignalProxy_Custom_gtk_callback_destroy(void* data)
42 {
43 delete static_cast<Gtk::SlotPrinterEnumerator*>(data);
44 }
45
46 namespace Gtk
47 {
48
49 bool Printer::equal(const Glib::RefPtr<Printer>& other) const
50 {
51 return (static_cast<bool>(gtk_printer_compare(const_cast<GtkPrinter*>(this->gobj()),
52 const_cast<GtkPrinter*>(other->gobj()))));
53 }
54
55 void enumerate_printers(const SlotPrinterEnumerator& slot, bool wait)
56 {
57 // Create a copy of the slot. A pointer to this will be passed through the callback's data parameter.
58 // It will be deleted when SignalProxy_Custom_gtk_callback_destroy() is called.
59 auto slot_copy = new SlotPrinterEnumerator(slot);
60
61 gtk_enumerate_printers(&SignalProxy_Custom_gtk_callback,
62 slot_copy,
63 &SignalProxy_Custom_gtk_callback_destroy,
64 static_cast<int>(wait));
65 }
66
67 } // namespace Gtk