/* 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <glibmm/object.h>
#include <gtkmm/enums.h>
#include <gtkmm/papersize.h>

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

namespace Gtk
{

/** A PageSetup object stores the page size, orientation and margins. You can get one of these from the page setup dialog
 * and then pass it to the PrintOperation when printing. The benefit of splitting this out of the PrintSettings is that
 * these affect the actual layout of the page, and thus need to be set long before the user prints.
 *
 * The margins specified in this object are the "print margins", i.e. the parts of the page that the printer cannot print
 * on. These are different from the layout margins that a word processor uses; they are typically used to determine the
 * minimal size for the layout margins.
 *
 * To obtain a PageSetup use PageSetup::create() to get the defaults, or use run_page_setup_dialog() to show the page
 * setup dialog and receive the resulting page setup.
 *
 * @newin{2,10}
 *
 * @ingroup Printing
 */
class PageSetup : public Glib::Object
{
  _CLASS_GOBJECT(PageSetup, GtkPageSetup, GTK_PAGE_SETUP, Glib::Object, GObject)
protected:
  _CTOR_DEFAULT

public:
  _WRAP_CREATE()

 /** Reads the page setup from the "Page Setup" group in the key file @a key_file.
  * Returns a new PageSetup object with the restored
  * page setup, or an empty RefPtr if an error occurred.
  *
  * @param key_file The KeyFile to retrieve the page setup from.
  * @result The restored PageSetup
  *
  * @throws KeyFileError
  *
  * @newin{2,14}
  */
  static Glib::RefPtr<PageSetup> create_from_key_file(const Glib::RefPtr<const Glib::KeyFile>& key_file);

 /** Reads the page setup from the group @a group_name in the key file @a key_file.
  * Returns a new PageSetup object with the restored
  * page setup, or an empty RefPtr if an error occurred.
  *
  * @param key_file The KeyFile to retrieve the page setup from.
  * @param group_name The name of the group in the key_file to read.
  * @result The restored PageSetup
  *
  * @throws KeyFileError
  *
  * @newin{2,14}
  */
  static Glib::RefPtr<PageSetup> create_from_key_file(const Glib::RefPtr<const Glib::KeyFile>& key_file, const Glib::ustring& group_name);
  _IGNORE(gtk_page_setup_new_from_key_file)

 /** Reads the page setup from the file @a file_name. Returns a
  * new PageSetup object with the restored page setup,
  * or an empty RefPtr if an error occurred. See save_to_file().
  *
  * @param file_name The filename to read the page setup from.
  * @result The restored PageSetup
  *
  * @newin{2,14}
  */
  static Glib::RefPtr<PageSetup> create_from_file(const std::string& file_name);
  _IGNORE(gtk_page_setup_new_from_file)

  _WRAP_METHOD(Glib::RefPtr<PageSetup> copy() const, gtk_page_setup_copy)

  //The from_ infix was added to these functions to make them clearer. GTK+ didn't want to change them.
  _WRAP_METHOD(bool load_from_file(const std::string& file_name), gtk_page_setup_load_file, errthrow)

  _WRAP_METHOD(bool load_from_key_file(const Glib::RefPtr<const Glib::KeyFile>& key_file, const Glib::ustring& group_name), gtk_page_setup_load_key_file, errthrow)

 /** Reads the page setup from the "Page Setup" group in the key file @a key_file.
  *
  * @param key_file The KeyFile to retrieve the page setup from.
  * @result true on success
  *
  * @throws KeyFileError
  *
  * @newin{2,14}
  */
  bool load_from_key_file(const Glib::RefPtr<const Glib::KeyFile>& key_file);

  _WRAP_METHOD(PageOrientation get_orientation() const, gtk_page_setup_get_orientation)
  _WRAP_METHOD(void set_orientation(PageOrientation orientation), gtk_page_setup_set_orientation)

  _WRAP_METHOD(PaperSize get_paper_size(), gtk_page_setup_get_paper_size)
  _WRAP_METHOD(const PaperSize get_paper_size() const, gtk_page_setup_get_paper_size, constversion)
  _WRAP_METHOD(void set_paper_size(const PaperSize& size), gtk_page_setup_set_paper_size)

  _WRAP_METHOD(double get_top_margin(Unit unit) const, gtk_page_setup_get_top_margin)
  _WRAP_METHOD(void set_top_margin(double margin, Unit unit), gtk_page_setup_set_top_margin)

  _WRAP_METHOD(double get_bottom_margin(Unit unit) const, gtk_page_setup_get_bottom_margin)
  _WRAP_METHOD(void set_bottom_margin(double margin, Unit unit), gtk_page_setup_set_bottom_margin)

  _WRAP_METHOD(double get_left_margin(Unit unit) const, gtk_page_setup_get_left_margin)
  _WRAP_METHOD(void set_left_margin(double margin, Unit unit), gtk_page_setup_set_left_margin)

  _WRAP_METHOD(double get_right_margin(Unit unit) const, gtk_page_setup_get_right_margin)
  _WRAP_METHOD(void set_right_margin(double margin, Unit unit), gtk_page_setup_set_right_margin)

  _WRAP_METHOD(void set_paper_size_and_default_margins(const PaperSize& size),
               gtk_page_setup_set_paper_size_and_default_margins)

  _WRAP_METHOD(double get_paper_width(Unit unit) const, gtk_page_setup_get_paper_width)
  _WRAP_METHOD(double get_paper_height(Unit unit) const, gtk_page_setup_get_paper_height)

  _WRAP_METHOD(double get_page_width(Unit unit) const, gtk_page_setup_get_page_width)
  _WRAP_METHOD(double get_page_height(Unit unit) const, gtk_page_setup_get_page_height)

  //The save_ prefix was added to these functions to make them clearer. GTK+ didn't want to change them.
  _WRAP_METHOD(bool save_to_file(const std::string& file_name) const, gtk_page_setup_to_file, errthrow)

  _WRAP_METHOD(void save_to_key_file(const Glib::RefPtr<Glib::KeyFile>& key_file, const Glib::ustring& group_name) const, gtk_page_setup_to_key_file)

  /** This function adds the page setup from @a setup to @a key_file,
   * in the group "Page Setup"
   *
   * @newin{2,12}
   *
   * @param key_file The G::KeyFile to save the page setup to.
   */
  void save_to_key_file(const Glib::RefPtr<Glib::KeyFile>& key_file) const;
};

} // namespace Gtk
