/* Copyright (C) 2006 The gtkmm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
 */

#include <glibmm/object.h>
#include <gtkmm/pagesetup.h>
#include <gtkmm/printer.h>
#include <gtkmm/printoperation.h>
#include <gtkmm/printsettings.h>
#include <cairomm/surface.h>

_DEFS(gtkmm,gtk)
_PINCLUDE(glibmm/private/object_p.h)

namespace Gtk
{

/** A PrintJob object represents a job that is sent to a printer. You only need to deal
 * directly with print jobs if you  use the non-portable PrintUnixDialog API.
 *
 * Use get_surface() to obtain the cairo surface onto which the pages must be drawn.
 * Use send() to send the finished job to the printer.If you don't use cairo then
 * PrintJob also supports printing of manually generated postscript, via set_source_file().
 *
 * @ingroup Printing
 */
class GTKMM_API PrintJob : public Glib::Object
{
  _CLASS_GOBJECT(PrintJob, GtkPrintJob, GTK_PRINT_JOB, Glib::Object, GObject, , , GTKMM_API)
  _GTKMMPROC_WIN32_NO_WRAP

protected:
  _WRAP_CTOR(PrintJob(const Glib::ustring& title, const Glib::RefPtr<Printer>& printer, const Glib::RefPtr<PrintSettings>& settings, const Glib::RefPtr<PageSetup>& page_setup), gtk_print_job_new)

public:
  _WRAP_CREATE(const Glib::ustring& title, const Glib::RefPtr<Printer>& printer, const Glib::RefPtr<PrintSettings>& settings, const Glib::RefPtr<PageSetup>& page_setup)

  _WRAP_METHOD(Glib::RefPtr<PrintSettings> get_settings(), gtk_print_job_get_settings, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const PrintSettings> get_settings() const, gtk_print_job_get_settings, refreturn, constversion)

  _WRAP_METHOD(Glib::RefPtr<Printer> get_printer(), gtk_print_job_get_printer, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const Printer> get_printer() const, gtk_print_job_get_printer, refreturn, constversion)

  _WRAP_METHOD(Glib::ustring get_title() const, gtk_print_job_get_title)
  _WRAP_METHOD(PrintStatus get_status() const, gtk_print_job_get_status)
  _WRAP_METHOD(void set_source_file(const std::string& filename), gtk_print_job_set_source_file, errthrow)

  _WRAP_METHOD(Cairo::RefPtr<Cairo::Surface> get_surface(), gtk_print_job_get_surface, refreturn, errthrow)
  _WRAP_METHOD(Cairo::RefPtr<const Cairo::Surface> get_surface() const, gtk_print_job_get_surface, refreturn, constversion, errthrow)

  _WRAP_METHOD(void set_track_print_status(bool track_status = true), gtk_print_job_set_track_print_status)
  _WRAP_METHOD(bool get_track_print_status() const, gtk_print_job_get_track_print_status)

  /** For example,
   * void on_print_job_complete(const Glib::RefPtr<PrintJob>& job);
   *
   * @throws exception
   */
  typedef sigc::slot<void(const Glib::RefPtr<PrintJob>&)> SlotPrintJobComplete;

  /** Sends the print job off to the printer.
   * @param slot A function to call when the job completes or an error occurs.
   */
  void send(const SlotPrintJobComplete& slot);
  _IGNORE(gtk_print_job_send)


  _WRAP_METHOD(PrintPages get_pages() const, gtk_print_job_get_pages)
  _WRAP_METHOD(void set_pages(PrintPages pages), gtk_print_job_set_pages)

  std::vector<PageRange> get_page_ranges() const;
  _IGNORE(gtk_print_job_get_page_ranges)

  void set_page_ranges(const std::vector<PageRange>& ranges);
  _IGNORE(gtk_print_job_set_page_ranges)


  _WRAP_METHOD(PageSet get_page_set() const, gtk_print_job_get_page_set)
  _WRAP_METHOD(void set_page_set(PageSet page_set), gtk_print_job_set_page_set)
  _WRAP_METHOD(int get_num_copies() const, gtk_print_job_get_num_copies)
  _WRAP_METHOD(void set_num_copies(int num_copies), gtk_print_job_set_num_copies)
  _WRAP_METHOD(double get_scale() const, gtk_print_job_get_scale)
  _WRAP_METHOD(void set_scale(double scale), gtk_print_job_set_scale)
  _WRAP_METHOD(guint get_n_up() const, gtk_print_job_get_n_up)
  _WRAP_METHOD(void set_n_up(guint n_up), gtk_print_job_set_n_up)
  _WRAP_METHOD(NumberUpLayout get_n_up_layout() const, gtk_print_job_get_n_up_layout)
  _WRAP_METHOD(void set_n_up_layout(NumberUpLayout  layout), gtk_print_job_set_n_up_layout)
  _WRAP_METHOD(bool get_rotate() const, gtk_print_job_get_rotate)
  _WRAP_METHOD(void set_rotate(bool rotate = true), gtk_print_job_set_rotate)
  _WRAP_METHOD(bool get_collate() const, gtk_print_job_get_collate)
  _WRAP_METHOD(void set_collate(bool collate = true), gtk_print_job_set_collate)
  _WRAP_METHOD(bool get_reverse() const, gtk_print_job_get_reverse)
  _WRAP_METHOD(void set_reverse(bool reverse = true), gtk_print_job_set_reverse)

  // no_default_handler because GtkPrintJobClass is private.
  _WRAP_SIGNAL(void status_changed(), "status_changed", no_default_handler)

  _WRAP_PROPERTY("title", Glib::ustring)
  _WRAP_PROPERTY("printer", Glib::RefPtr<Printer>)
  _WRAP_PROPERTY("settings", Glib::RefPtr<PrintSettings>)
  _WRAP_PROPERTY("page_setup", Glib::RefPtr<PageSetup>)
  _WRAP_PROPERTY("track-print-status", bool)
};

} // namespace Gtk
