Remove ancient/unused flowcanvas and libglademm from repository.
[ardour.git] / libs / gtkmm2 / gtk / src / printoperation.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/gtkprintoperation.h>
20
21 // This Signal Proxy allows the C++ coder to specify a sigc::slot instead of a static function.
22
23 static void
24 SignalProxy_PrintSetupDone_gtk_callback(GtkPageSetup* page_setup, gpointer data)
25 {
26   const Gtk::SlotPrintSetupDone* the_slot = static_cast<Gtk::SlotPrintSetupDone*>(data);
27
28   #ifdef GLIBMM_EXCEPTIONS_ENABLED
29   try
30   {
31   #endif //GLIBMM_EXCEPTIONS_ENABLED
32     Glib::RefPtr<Gtk::PageSetup> ps = Glib::wrap(page_setup);
33     (*the_slot)(ps);
34   #ifdef GLIBMM_EXCEPTIONS_ENABLED
35   }
36   catch (...)
37   {
38     Glib::exception_handlers_invoke();
39   }
40   #endif //GLIBMM_EXCEPTIONS_ENABLED
41
42   delete the_slot;
43 }
44
45 namespace Gtk
46 {
47
48 PrintOperationResult
49 #ifdef GLIBMM_EXCEPTIONS_ENABLED
50 PrintOperation::run(PrintOperationAction action)
51 #else
52 PrintOperation::run(PrintOperationAction action, std::auto_ptr<Glib::Error>& error)
53 #endif //GLIBMM_EXCEPTIONS_ENABLED
54 {
55   GError* gerror = 0;
56   PrintOperationResult res =
57     (PrintOperationResult)gtk_print_operation_run(this->gobj(), (GtkPrintOperationAction)action, 0, &gerror);
58
59   #ifdef GLIBMM_EXCEPTIONS_ENABLED
60   if (res == PRINT_OPERATION_RESULT_ERROR)
61   {
62     gtk_print_operation_get_error(this->gobj(), &gerror);
63     ::Glib::Error::throw_exception(gerror);
64   }
65   #else
66   if (res == PRINT_OPERATION_RESULT_ERROR)
67   {
68     gtk_print_operation_get_error(this->gobj(), &gerror);
69     error = ::Glib::Error::throw_exception(gerror);
70   }
71   #endif //GLIBMM_EXCEPTIONS_ENABLED
72
73   return res;
74 }
75
76 Glib::RefPtr<PageSetup>
77 run_page_setup_dialog(Window& parent,
78                       const Glib::RefPtr<const PageSetup>& page_setup,
79                       const Glib::RefPtr<const PrintSettings>& print_settings)
80 {
81   // Specify the exact type with template specialization, to avoid possible
82   // ambiguities between the const and non-const versions of unwrap() reported
83   // by Sun's compiler (specifying unwrap<const Object> was reported
84   // not to work):
85   return Glib::wrap(
86     gtk_print_run_page_setup_dialog(
87       parent.gobj(),
88       const_cast<GtkPageSetup*>(Glib::unwrap<PageSetup>(page_setup)),
89       const_cast<GtkPrintSettings*>(Glib::unwrap<PrintSettings>(print_settings))));
90
91 }
92
93 void
94 run_page_setup_dialog_async(Window& parent,
95                             const Glib::RefPtr<const PageSetup>& page_setup,
96                             const Glib::RefPtr<const PrintSettings>& print_settings,
97                             const SlotPrintSetupDone& slot)
98 {
99   SlotPrintSetupDone* slot_copy = new SlotPrintSetupDone(slot);
100
101   // Specify the exact type with template specialization, to avoid possible
102   // ambiguities between the const and non-const versions of unwrap() reported
103   // by Sun's compiler (specifying unwrap<const Object> was reported
104   // not to work):
105   gtk_print_run_page_setup_dialog_async(
106     parent.gobj(),
107     const_cast<GtkPageSetup*>(Glib::unwrap<PageSetup>(page_setup)),
108     const_cast<GtkPrintSettings*>(Glib::unwrap<PrintSettings>(print_settings)),
109     &SignalProxy_PrintSetupDone_gtk_callback,
110     slot_copy);
111 }
112
113 } // namespace Gtk