/* 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/vectorutils.h>

#include <gtk/gtk.h>

namespace Gtk
{
// Initialize external constants.
const Glib::ustring PAPER_NAME_A3 = GTK_PAPER_NAME_A3;
const Glib::ustring PAPER_NAME_A4 = GTK_PAPER_NAME_A4;
const Glib::ustring PAPER_NAME_A5 = GTK_PAPER_NAME_A5;
const Glib::ustring PAPER_NAME_B5 = GTK_PAPER_NAME_B5;
const Glib::ustring PAPER_NAME_LETTER = GTK_PAPER_NAME_LETTER;
const Glib::ustring PAPER_NAME_EXECUTIVE = GTK_PAPER_NAME_EXECUTIVE;
const Glib::ustring PAPER_NAME_LEGAL = GTK_PAPER_NAME_LEGAL;

//PaperSize::PaperSize()
//:
//  gobject_(gtk_paper_size_new(gtk_paper_size_get_default()))
//{}

PaperSize::PaperSize(const Glib::ustring& name)
:
  gobject_(gtk_paper_size_new(name.c_str()))
{}

PaperSize::PaperSize(const Glib::ustring& ppd_name, const Glib::ustring& ppd_display_name, double width, double height)
:
  gobject_(gtk_paper_size_new_from_ppd(ppd_name.c_str(),
                                       ppd_display_name.c_str(),
                                       gdouble(width),
                                       gdouble(height)))
{}

PaperSize::PaperSize(const Glib::ustring& name, const Glib::ustring& display_name, double width, double height, Unit unit)
:
  gobject_(gtk_paper_size_new_custom(name.c_str(),
                                     display_name.c_str(),
                                     gdouble(width),
                                     gdouble(height),
                                     GtkUnit(unit)))
{}

//TODO: Add an operator bool() so we can detect if this succeeded:
//TODO: No, throw the error/exception instead.
PaperSize::PaperSize(const Glib::KeyFile& key_file, const Glib::ustring& group_name)
:
  gobject_(gtk_paper_size_new_from_key_file(const_cast<GKeyFile*>(key_file.gobj()), (group_name.empty() ? nullptr : group_name.c_str()) , nullptr /* GError */))
{}

bool PaperSize::equal(const PaperSize& other) const
{
  return (static_cast<bool>(gtk_paper_size_is_equal(const_cast<GtkPaperSize*>(this->gobj()),
                                                    const_cast<GtkPaperSize*>(other.gobj()))));
}

_DEPRECATE_IFDEF_START
PaperSize::operator const void*() const
{
  return gobj() ? GINT_TO_POINTER(1) : nullptr;
}
_DEPRECATE_IFDEF_END

PaperSize::operator bool() const
{
  return gobj();
}

void PaperSize::save_to_key_file(Glib::KeyFile& key_file)
{
  gtk_paper_size_to_key_file( gobj(), (key_file).gobj(), nullptr);
}


} // namespace Gtk
