/* Copyright (C) 1998-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., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <goocanvasmm/item.h>
#include <goocanvasmm/itemmodel.h>
#include <goocanvasmm/itemsimple.h>
#include <goocanvasmm/style.h>
#include <goocanvasmm/widget.h>

#include <gtkmm/adjustment.h>
#include <gtkmm/container.h>
#include <gdkmm/cursor.h>
#include <cairomm/context.h>
#include <gtkmm/papersize.h> //For Gtk::Unit



_DEFS(goocanvasmm,libgoocanvas)
_PINCLUDE(gtkmm/private/container_p.h)

namespace Goocanvas
{

/** The main canvas widget, containing a number of canvas items.
 * Add child items (see Item) to the root item (see get_root_item()), for instance with Item::add_child().
 */
class Canvas :
  public Gtk::Container
{
  _CLASS_GTKOBJECT(Canvas, GooCanvas, GOO_CANVAS, Gtk::Container, GtkContainer)

public:
  _CTOR_DEFAULT

  _WRAP_METHOD(Glib::RefPtr<Item> get_root_item(), goo_canvas_get_root_item, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const Item> get_root_item() const, goo_canvas_get_root_item, constversion)
  _WRAP_METHOD(void set_root_item(const Glib::RefPtr<Item>& item), goo_canvas_set_root_item)

  _WRAP_METHOD(Glib::RefPtr<ItemModel> get_root_item_model(), goo_canvas_get_root_item_model, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const ItemModel> get_root_item_model() const, goo_canvas_get_root_item_model, constversion)
  _WRAP_METHOD(void set_root_item_model(const Glib::RefPtr<ItemModel>& model), goo_canvas_set_root_item_model)

  _WRAP_METHOD(Glib::RefPtr<Item> get_static_root_item(), goo_canvas_get_static_root_item)
  _WRAP_METHOD(Glib::RefPtr<const Item> get_static_root_item() const, goo_canvas_get_static_root_item, constversion)
  _WRAP_METHOD(void set_static_root_item(const Glib::RefPtr<Item>& item), goo_canvas_set_static_root_item)

  _WRAP_METHOD(Glib::RefPtr<ItemModel> get_static_root_item_model(), goo_canvas_get_static_root_item_model, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const ItemModel> get_static_root_item_model() const, goo_canvas_get_static_root_item_model, constversion)
  _WRAP_METHOD(void set_static_root_item_model(const Glib::RefPtr<ItemModel>& model), goo_canvas_set_static_root_item_model)

  _WRAP_METHOD(Glib::RefPtr<Item> get_item(const Glib::RefPtr<ItemModel>& model), goo_canvas_get_item, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const Item> get_item(const Glib::RefPtr<ItemModel>& model) const, goo_canvas_get_item, constversion)

  _WRAP_METHOD(Glib::RefPtr<Item> get_item_at(double x, double y, bool is_pointer_event), goo_canvas_get_item_at, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const Item> get_item_at(double x, double y, bool is_pointer_event) const, goo_canvas_get_item_at, constversion)

#m4 _CONVERSION(`GList*',`std::vector< Glib::RefPtr<Item> >',`Glib::ListHandler<Glib::RefPtr<Item> >::list_to_vector($3, Glib::OWNERSHIP_SHALLOW)')
#m4 _CONVERSION(`GList*',`std::vector< Glib::RefPtr<const Item> >',`Glib::ListHandler<Glib::RefPtr<const Item> >::list_to_vector($3, Glib::OWNERSHIP_SHALLOW)')

  _WRAP_METHOD(std::vector< Glib::RefPtr<Item> > get_items_at(double x, double y, bool is_pointer_event), goo_canvas_get_items_at)
  _WRAP_METHOD(std::vector< Glib::RefPtr<const Item> > get_items_at(double x, double y, bool is_pointer_event) const, goo_canvas_get_items_at)
  _WRAP_METHOD(std::vector< Glib::RefPtr<Item> > get_items_in_area(const Bounds& area, bool inside_area, bool allow_overlaps, bool include_containers), goo_canvas_get_items_in_area)
  _WRAP_METHOD(std::vector< Glib::RefPtr<const Item> > get_items_in_area(const Bounds& area, bool inside_area, bool allow_overlaps, bool include_containers) const, goo_canvas_get_items_in_area)

  _WRAP_METHOD(double get_scale() const, goo_canvas_get_scale)
  _WRAP_METHOD(void set_scale(double scale), goo_canvas_set_scale)


  _WRAP_METHOD(void get_bounds(double& left, double& top, double& right, double& bottom) const, goo_canvas_get_bounds)
  void get_bounds(Bounds& bounds) const;

  _WRAP_METHOD(void set_bounds(double left, double top, double right, double bottom), goo_canvas_set_bounds)
  void set_bounds(const Bounds& bounds);

  _WRAP_METHOD(void scroll_to(double left, double top), goo_canvas_scroll_to)

  _WRAP_METHOD(void grab_focus(const Glib::RefPtr<Item>& item), goo_canvas_grab_focus)

  _WRAP_METHOD(void render(const Cairo::RefPtr<Cairo::Context>& context, const Bounds& bounds, double scale = 0.0), goo_canvas_render)
  void render(const Cairo::RefPtr<Cairo::Context>& context, double scale = 0.0);

  _WRAP_METHOD(void convert_to_pixels(double& x, double& y) const, goo_canvas_convert_to_pixels)
  _WRAP_METHOD(void convert_from_pixels(double& x, double& y) const, goo_canvas_convert_from_pixels)
  _WRAP_METHOD(void convert_to_item_space(const Glib::RefPtr<Item>& item, double& x, double& y) const, goo_canvas_convert_to_item_space)
  _WRAP_METHOD(void convert_from_item_space(const Glib::RefPtr<Item>& item, double& x, double& y) const, goo_canvas_convert_from_item_space)
  _WRAP_METHOD(void convert_bounds_to_item_space(const Glib::RefPtr<Item>& item, Bounds& bounds) const, goo_canvas_convert_bounds_to_item_space)

  _WRAP_METHOD(Gdk::GrabStatus pointer_grab(const Glib::RefPtr<Item>& item, Gdk::EventMask mask, const Glib::RefPtr<Gdk::Cursor>& cursor, guint32 time), goo_canvas_pointer_grab)
  Gdk::GrabStatus pointer_grab(const Glib::RefPtr<Item>& item, Gdk::EventMask mask, guint32 time);

  _WRAP_METHOD(void pointer_ungrab(const Glib::RefPtr<Item>& item, guint32 time), goo_canvas_pointer_ungrab)
  _WRAP_METHOD(GdkGrabStatus keyboard_grab(const Glib::RefPtr<Item>& item, bool owner_events, guint32 time), goo_canvas_keyboard_grab)
  _WRAP_METHOD(void keyboard_ungrab(const Glib::RefPtr<Item>& item, guint32 time), goo_canvas_keyboard_ungrab)

  _WRAP_METHOD(Cairo::RefPtr<Cairo::Context> create_cairo_context(), goo_canvas_create_cairo_context)

  _WRAP_METHOD(Glib::RefPtr<Item> create_item(const Glib::RefPtr<ItemModel>& model), goo_canvas_create_item)
  _WRAP_METHOD(void unregister_item(const Glib::RefPtr<ItemModel>& model), goo_canvas_unregister_item)

  _WRAP_METHOD(void update(), goo_canvas_update)
  _WRAP_METHOD(void request_update(), goo_canvas_request_update)
  _WRAP_METHOD(void request_redraw(const Bounds& bounds), goo_canvas_request_redraw)
  _WRAP_METHOD(void request_item_redraw(const Bounds& bounds, bool is_static = false), goo_canvas_request_item_redraw)
  _WRAP_METHOD(double get_default_line_width() const, goo_canvas_get_default_line_width)

  _WRAP_METHOD(void register_widget_item(const Glib::RefPtr<Goocanvas::Widget>& widget), goo_canvas_register_widget_item)
  _WRAP_METHOD(void unregister_widget_item(const Glib::RefPtr<Goocanvas::Widget>& widget), goo_canvas_unregister_widget_item)

#m4 _CONVERSION(`GooCanvasItem*',`const Glib::RefPtr<Item>&',`Glib::wrap($3, true)')
#m4 _CONVERSION(`GooCanvasItemModel*',`const Glib::RefPtr<ItemModel>&',`Glib::wrap($3, true)')
  _WRAP_SIGNAL(void item_created(const Glib::RefPtr<Item>& item, const Glib::RefPtr<ItemModel>& model), "item_created")

  _WRAP_PROPERTY("scale", double)
  _WRAP_PROPERTY("scale-x", double)
  _WRAP_PROPERTY("scale-y", double)
  _WRAP_PROPERTY("anchor", AnchorType)
  _WRAP_PROPERTY("x1", double)
  _WRAP_PROPERTY("y1", double)
  _WRAP_PROPERTY("x2", double)
  _WRAP_PROPERTY("y2", double)
  _WRAP_PROPERTY("automatic-bounds", bool)
  _WRAP_PROPERTY("bounds-from-origin", bool)
  _WRAP_PROPERTY("bounds-padding", double)
  _WRAP_PROPERTY("units", Gtk::Unit)
  _WRAP_PROPERTY("resolution-x", double)
  _WRAP_PROPERTY("resolution-y", double)
  _WRAP_PROPERTY("background-color", Glib::ustring)
  _WRAP_PROPERTY("background-color-rgb", guint)
  _WRAP_PROPERTY("background-color-gdk-rgba", Gdk::RGBA)
  _WRAP_PROPERTY("integer-layout", bool)
  _WRAP_PROPERTY("clear-background", bool)

protected:
  _WRAP_VFUNC(Glib::RefPtr<Item> create_item(const Glib::RefPtr<ItemModel>& model), "create_item")
};

} //namespace Goocanvas
