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

namespace Gtk
{

#ifndef GTKMM_DISABLE_DEPRECATED
Image::Image(const Gtk::StockID& stock_id, IconSize size)
:
  _CONSTRUCT("stock", stock_id.get_c_str(), "icon-size", (GtkIconSize) int(size))
{}
#endif //GTKMM_DISABLE_DEPRECATED

#ifndef GTKMM_DISABLE_DEPRECATED
Image::Image(const Glib::RefPtr<IconSet>& icon_set, IconSize size)
:
  _CONSTRUCT("icon-set", (icon_set ? icon_set->gobj() : 0), "icon-size", (GtkIconSize) int(size))
{}
#endif //GTKMM_DISABLE_DEPRECATED

Image::Image(const Glib::RefPtr<Gdk::PixbufAnimation>& animation)
:
  _CONSTRUCT("pixbuf-animation", Glib::unwrap(animation))
{}

#ifndef GTKMM_DISABLE_DEPRECATED
void Image::get_stock(Gtk::StockID& stock_id, IconSize& size) const
{
  char* pStockID = 0; // GTK+ iconsistency: although not const, it should not be freed.
  GtkIconSize icon_size = GTK_ICON_SIZE_INVALID;

  gtk_image_get_stock(const_cast<GtkImage*>(gobj()), &pStockID, &icon_size);

  size = IconSize(static_cast<int>(icon_size));
  stock_id = Gtk::StockID(pStockID); // the StockID ctor checks for 0
}
#endif //GTKMM_DISABLE_DEPRECATED

#ifndef GTKMM_DISABLE_DEPRECATED
void Image::get_icon_set(Glib::RefPtr<IconSet>& icon_set, IconSize& size) const
{
  GtkIconSet* pIconSet = 0;
  GtkIconSize icon_size = GTK_ICON_SIZE_INVALID;

  gtk_image_get_icon_set(const_cast<GtkImage*>(gobj()), &pIconSet, &icon_size);

  size = IconSize(static_cast<int>(icon_size));
  icon_set = Glib::wrap(pIconSet, true); //true = take_copy.
}
#endif //GTKMM_DISABLE_DEPRECATED

Glib::ustring Image::get_icon_name() const
{
  const gchar* pchIconName = 0;
  gtk_image_get_icon_name(const_cast<GtkImage*>(gobj()), &pchIconName, 0);
  return Glib::convert_const_gchar_ptr_to_ustring(pchIconName);
}

Glib::RefPtr<Gio::Icon> Image::get_gicon(Gtk::IconSize& icon_size)
{
  GIcon* cicon = 0;
  GtkIconSize cicon_size = GTK_ICON_SIZE_INVALID;
  gtk_image_get_gicon(gobj(), &cicon, &cicon_size);

  icon_size = Gtk::IconSize(cicon_size);
  return Glib::wrap(cicon);
}

Glib::RefPtr<const Gio::Icon> Image::get_gicon(Gtk::IconSize& icon_size) const
{
  Image* nonconstthis = const_cast<Image*>(this);
  return nonconstthis->get_gicon(icon_size);
}


} // namespace Gtk
