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/gtkunixprint.h>
20
21// This Signal Proxy allows the C++ coder to specify a sigc::slot instead of a static function.
22
23static void SignalProxy_Custom_gtk_callback(GtkPrintJob* print_job, gpointer data, GError* gerror)
24{
25  const Gtk::PrintJob::SlotPrintJobComplete* the_slot = static_cast<Gtk::PrintJob::SlotPrintJobComplete*>(data);
26
27  try
28  {
29
30    // Create a suitable C++ instance to pass to the C++ method;
31    Glib::RefPtr<Gtk::PrintJob> job = Glib::wrap(print_job);
32
33    if (gerror) Glib::Error::throw_exception(gerror);
34    (*the_slot)(job);
35
36  }
37  catch(...)
38  {
39    Glib::exception_handlers_invoke();
40  }
41}
42
43static void SignalProxy_Custom_gtk_callback_destroy(void* data)
44{
45  delete static_cast<Gtk::PrintJob::SlotPrintJobComplete*>(data);
46}
47
48namespace Gtk
49{
50
51void PrintJob::send(const SlotPrintJobComplete& slot)
52{
53  // Create a copy of the slot. A pointer to this will be passed through the callback's data parameter.
54  // It will be deleted when SignalProxy_Custom_gtk_callback_destroy() is called.
55  SlotPrintJobComplete* slot_copy = new SlotPrintJobComplete(slot);
56
57  gtk_print_job_send(gobj(), &SignalProxy_Custom_gtk_callback, slot_copy, &SignalProxy_Custom_gtk_callback_destroy);
58}
59
60} // namespace Gtk
61