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 Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 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 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser 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/gtk.h>
20
21// This Signal Proxy allows the C++ coder to specify a sigc::slot instead of a static function.
22
23static void
24SignalProxy_PrintSetupDone_gtk_callback(GtkPageSetup* page_setup, gpointer data)
25{
26  const Gtk::SlotPrintSetupDone* the_slot = static_cast<Gtk::SlotPrintSetupDone*>(data);
27
28  try
29  {
30    Glib::RefPtr<Gtk::PageSetup> ps = Glib::wrap(page_setup);
31    (*the_slot)(ps);
32  }
33  catch (...)
34  {
35    Glib::exception_handlers_invoke();
36  }
37
38  delete the_slot;
39}
40
41namespace Gtk
42{
43
44PrintOperationResult
45PrintOperation::run(PrintOperationAction action)
46{
47  GError* gerror = 0;
48  PrintOperationResult res =
49    (PrintOperationResult)gtk_print_operation_run(this->gobj(), (GtkPrintOperationAction)action, 0, &gerror);
50
51  if (res == PRINT_OPERATION_RESULT_ERROR)
52  {
53    gtk_print_operation_get_error(this->gobj(), &gerror);
54    ::Glib::Error::throw_exception(gerror);
55  }
56
57  return res;
58}
59
60Glib::RefPtr<PageSetup>
61run_page_setup_dialog(Window& parent,
62                      const Glib::RefPtr<const PageSetup>& page_setup,
63                      const Glib::RefPtr<const PrintSettings>& print_settings)
64{
65  // Specify the exact type with template specialization, to avoid possible
66  // ambiguities between the const and non-const versions of unwrap() reported
67  // by Sun's compiler (specifying unwrap<const Object> was reported
68  // not to work):
69  return Glib::wrap(
70    gtk_print_run_page_setup_dialog(
71      parent.gobj(),
72      const_cast<GtkPageSetup*>(Glib::unwrap<PageSetup>(page_setup)),
73      const_cast<GtkPrintSettings*>(Glib::unwrap<PrintSettings>(print_settings))));
74
75}
76
77Glib::RefPtr<PageSetup>
78run_page_setup_dialog(Window& parent,
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      0,
89      const_cast<GtkPrintSettings*>(Glib::unwrap<PrintSettings>(print_settings))));
90
91}
92
93void
94run_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
113void
114run_page_setup_dialog_async(Window& parent,
115                            const Glib::RefPtr<const PrintSettings>& print_settings,
116                            const SlotPrintSetupDone& slot)
117{
118  SlotPrintSetupDone* slot_copy = new SlotPrintSetupDone(slot);
119
120  // Specify the exact type with template specialization, to avoid possible
121  // ambiguities between the const and non-const versions of unwrap() reported
122  // by Sun's compiler (specifying unwrap<const Object> was reported
123  // not to work):
124  gtk_print_run_page_setup_dialog_async(
125    parent.gobj(),
126    0,
127    const_cast<GtkPrintSettings*>(Glib::unwrap<PrintSettings>(print_settings)),
128    &SignalProxy_PrintSetupDone_gtk_callback,
129    slot_copy);
130}
131
132} // namespace Gtk
133