/*
 * Copyright (C) 1998-2002 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 <gtkmm/misc.h>
#include <gtkmm/iconset.h>
#include <gdkmm/pixbufanimation.h>
#include <giomm/icon.h>

_DEFS(gtkmm,gtk)
_PINCLUDE(gtkmm/private/misc_p.h)


namespace Gtk
{

_CC_INCLUDE(gtk/gtk.h)
_WRAP_ENUM(ImageType, GtkImageType)


/** A widget displaying an image.
 *
 * The Gtk::Image widget displays an image. Various kinds of object can be
 * displayed as an image; most typically, you would load a Gdk::Pixbuf ("pixel
 * buffer") from a file, and then display that.
 *
 * Gtk::Image is a subclass of Gtk::Misc, which implies that you can align it
 * (center, left, right) and add padding to it, using Gtk::Misc methods.
 *
 * Gtk::Image is a "no window" widget (has no Gdk::Window of its own), so by
 * default does not receive events. If you want to receive events on the
 * image, such as button clicks, place the image inside a Gtk::EventBox, then
 * connect to the event signals on the event box.
 *
 * The Image widget looks like this:
 * @image html image1.png
 *
 * @ingroup Widgets
 */
class Image : public Misc
{
  _CLASS_GTKOBJECT(Image,GtkImage,GTK_IMAGE,Gtk::Misc,GtkMisc)
  _IGNORE(gtk_image_set, gtk_image_get, gtk_image_get_pixmap, gtk_image_get_image, gtk_image_get_stock, gtk_image_get_icon_set)
public:

  _CTOR_DEFAULT

  /** Creates an Image widget displaying the file @a filename.
   * If the file isn't found or can't be loaded, the resulting Gtk::Image will display a "broken image" icon.
   *
   * If the file contains an animation, the image will contain an animation.
   *
   * If you need to detect failures to load the file, use Gdk::Pixbuf::create_from_file() to load the file yourself,
   * then create the GtkImage from the pixbuf. (Or for animations, use Gdk::PixbufAnimation::create_from_file()).
   *
   * The storage type (get_storage_type()) of the returned image is not defined. It will be whatever is appropriate for displaying the file.
   */
  _WRAP_CTOR(Image(const std::string& file), gtk_image_new_from_file)

  //TODO: Change this documentation when we have wrapped new_from_icon_set().
  /** Creates a new Image widget displaying @a pixbuf.
   * Note that this just creates an GtkImage from the pixbuf. The Gtk::Image created will not react to state changes.
   * Should you want that, you should use new_from_icon_set().
   */
  _WRAP_CTOR(Image(const Glib::RefPtr<Gdk::Pixbuf>& pixbuf), gtk_image_new_from_pixbuf)
  //TODO: Wrap gtk_image_new_from_icon_set()

  //We don't wrap gtk_image_new_from_icon_name() to avoid a clash with the from-filename constructor.
  //But we do wrap gtk_image_set_from_icon_name()
  _IGNORE(gtk_image_new_from_icon_name)

  /** Creates am Image displaying a stock icon.
   * Sample stock icon identifiers are Gtk::Stock::OPEN, Gtk::Stock::EXIT. Sample stock sizes are Gtk::ICON_SIZE_MENU, Gtk::ICON_SIZE_SMALL_TOOLBAR.
   * If the stock icon name isn't known, a "broken image" icon will be displayed instead.
   * You can register your own stock icon names - see Gtk::IconFactory::add().
   * @param stock_id A stock icon.
   * @param size A stock icon size.
   */
  Image(const Gtk::StockID& stock_id, IconSize size);

  Image(const Glib::RefPtr<IconSet>& icon_set, IconSize size);
  explicit Image(const Glib::RefPtr<Gdk::PixbufAnimation>& animation);

  _WRAP_METHOD(void set(const std::string& filename), gtk_image_set_from_file)
  _WRAP_METHOD(void set_from_resource(const std::string& resource_path), gtk_image_set_from_resource)
  _WRAP_METHOD(void set(const Glib::RefPtr<Gdk::Pixbuf>& pixbuf), gtk_image_set_from_pixbuf)
  _WRAP_METHOD(void set(const Gtk::StockID& stock_id, IconSize size), gtk_image_set_from_stock)
  _WRAP_METHOD(void set(const Glib::RefPtr<IconSet>& icon_set, IconSize size), gtk_image_set_from_icon_set)
  _WRAP_METHOD(void set(const Glib::RefPtr<Gdk::PixbufAnimation>& animation), gtk_image_set_from_animation)
  _WRAP_METHOD(void set(const Glib::RefPtr<const Gio::Icon>& icon, IconSize size), gtk_image_set_from_gicon)

  _WRAP_METHOD(void set_from_icon_name(const Glib::ustring& icon_name, IconSize size), gtk_image_set_from_icon_name)


  _WRAP_METHOD(void clear(), gtk_image_clear)

  _WRAP_METHOD(ImageType get_storage_type() const, gtk_image_get_storage_type)

  _WRAP_METHOD(Glib::RefPtr<Gdk::Pixbuf> get_pixbuf(), gtk_image_get_pixbuf, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const Gdk::Pixbuf> get_pixbuf() const, gtk_image_get_pixbuf, refreturn, constversion)
  void get_stock(Gtk::StockID& stock_id, IconSize& size) const;
  void get_icon_set(Glib::RefPtr<IconSet>& icon_set, IconSize& size) const;
  _WRAP_METHOD(Glib::RefPtr<Gdk::PixbufAnimation> get_animation(), gtk_image_get_animation, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const Gdk::PixbufAnimation> get_animation() const, gtk_image_get_animation, refreturn, constversion)

 /** Gets the Gio::Icon and size being displayed by the Gtk::Image.
  * The storage type of the image must be IMAGE_EMPTY or
  * IMAGE_GICON (see get_storage_type()).
  *
  * @param icon_size A place to store an icon size.
  *
  * @newin{2,14}
  */
  Glib::RefPtr<Gio::Icon> get_gicon(Gtk::IconSize& icon_size);

 /** Gets the Gio::Icon and size being displayed by the Gtk::Image.
  * The storage type of the image must be IMAGE_EMPTY or
  * IMAGE_GICON (see get_storage_type()).
  *
  * @param icon_size A place to store an icon size.
  *
  * @newin{2,14}
  */
  Glib::RefPtr<const Gio::Icon> get_gicon(Gtk::IconSize& icon_size) const;
  _IGNORE(gtk_image_get_gicon)

  Glib::ustring get_icon_name() const;
  Glib::ustring get_icon_name(IconSize& size);
  _IGNORE(gtk_image_get_icon_name)

 _WRAP_METHOD(int get_pixel_size() const, gtk_image_get_pixel_size)
 _WRAP_METHOD(void set_pixel_size(int pixel_size), gtk_image_set_pixel_size)

  _WRAP_PROPERTY("pixbuf", Glib::RefPtr<Gdk::Pixbuf>)
  _WRAP_PROPERTY("file", Glib::ustring)
  _WRAP_PROPERTY("stock", Glib::ustring)
  _WRAP_PROPERTY("icon-set", Glib::RefPtr<IconSet>)
  _WRAP_PROPERTY("icon-size", int)
  _WRAP_PROPERTY("pixel-size", int)
  _WRAP_PROPERTY("pixbuf-animation", Glib::RefPtr<Gdk::PixbufAnimation>)
  _WRAP_PROPERTY("icon-name", Glib::ustring)
  _WRAP_PROPERTY("storage-type", ImageType)
  _WRAP_PROPERTY("gicon", Glib::RefPtr<Gio::Icon>)
  _WRAP_PROPERTY("use-fallback", bool)
};

} //namespace Gtk
