add new sigc++2 directory
[ardour.git] / libs / gtkmm2 / gtk / src / printer.ccg
1 // -*- c++ -*-
2 /* Copyright (C) 2006 The gtkmm Development Team
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the Free
16  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18
19 #include <gtk/gtkprinter.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 Gtk::SlotPrinterEnumerator* the_slot = static_cast<Gtk::SlotPrinterEnumerator*>(data);
26
27   #ifdef GLIBMM_EXCEPTIONS_ENABLED
28   try
29   {
30   #endif //GLIBMM_EXCEPTIONS_ENABLED
31     // Create a suitable C++ instance to pass to the C++ method;
32     Glib::RefPtr<Gtk::Printer> printer = Glib::wrap(gtk_printer);
33
34     return (*the_slot)(printer);
35   #ifdef GLIBMM_EXCEPTIONS_ENABLED
36   }
37   catch(...)
38   {
39     Glib::exception_handlers_invoke();
40     return false; // arbitrary default;
41   }
42   #endif //GLIBMM_EXCEPTIONS_ENABLED
43 }
44
45 static void SignalProxy_Custom_gtk_callback_destroy(void* data)
46 {
47   delete static_cast<Gtk::SlotPrinterEnumerator*>(data);
48 }
49
50 namespace Gtk
51 {
52
53 bool Printer::equal(const Glib::RefPtr<Printer>& other) const
54 {
55   return (static_cast<bool>(gtk_printer_compare(const_cast<GtkPrinter*>(this->gobj()),
56                                                 const_cast<GtkPrinter*>(other->gobj()))));
57 }
58
59 void enumerate_printers(const SlotPrinterEnumerator& slot, bool wait)
60 {
61   // Create a copy of the slot. A pointer to this will be passed through the callback's data parameter.
62   // It will be deleted when SignalProxy_Custom_gtk_callback_destroy() is called.
63   SlotPrinterEnumerator* slot_copy = new SlotPrinterEnumerator(slot);
64       
65   gtk_enumerate_printers(&SignalProxy_Custom_gtk_callback,
66                          slot_copy,
67                          &SignalProxy_Custom_gtk_callback_destroy,
68                          static_cast<int>(wait));
69 }
70
71 } // namespace Gtk