2 /* $Id: image.ccg,v 1.3 2005/07/10 19:24:22 murrayc Exp $ */
6 * Copyright 1998-2002 The gtkmm Development Team
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the Free
20 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <gtk/gtkimage.h>
24 #include <gdkmm/image.h>
25 #include <gdkmm/bitmap.h>
26 #include <gdkmm/pixmap.h>
31 Image::Image(const Gtk::StockID& stock_id, IconSize size)
33 _CONSTRUCT("stock", stock_id.get_c_str(), "icon-size", (GtkIconSize) int(size))
36 Image::Image(IconSet& icon_set, IconSize size)
38 _CONSTRUCT("icon-set", icon_set.gobj(), "icon-size", (GtkIconSize) int(size))
41 Image::Image(const Glib::RefPtr<Gdk::PixbufAnimation>& animation)
43 _CONSTRUCT("pixbuf-animation", Glib::unwrap(animation))
46 void Image::get_pixmap(Glib::RefPtr<Gdk::Pixmap>& pixmap, Glib::RefPtr<Gdk::Bitmap>& mask) const
48 GdkPixmap* pPixmap = 0;
49 GdkBitmap* pBitmap = 0;
51 gtk_image_get_pixmap(const_cast<GtkImage*>(gobj()), &pPixmap, &pBitmap);
53 pixmap = Glib::wrap((GdkPixmapObject*) pPixmap, true);
54 mask = Glib::RefPtr<Gdk::Bitmap>::cast_dynamic(Glib::wrap((GdkPixmapObject*) pBitmap, true));
57 void Image::get_image(Glib::RefPtr<Gdk::Image>& gdk_image, Glib::RefPtr<Gdk::Bitmap>& mask) const
60 GdkBitmap* pBitmap = 0;
62 gtk_image_get_image(const_cast<GtkImage*>(gobj()), &pImage, &pBitmap);
64 gdk_image = Glib::wrap(pImage, true);
65 mask = Glib::RefPtr<Gdk::Bitmap>::cast_dynamic(Glib::wrap((GdkPixmapObject*) pBitmap, true));
68 void Image::get_stock(Gtk::StockID& stock_id, IconSize& size) const
70 char* pStockID = 0; // GTK+ iconsistency: although not const, it should not be freed.
71 GtkIconSize icon_size = GTK_ICON_SIZE_INVALID;
73 gtk_image_get_stock(const_cast<GtkImage*>(gobj()), &pStockID, &icon_size);
75 size = IconSize(static_cast<int>(icon_size));
76 stock_id = Gtk::StockID(pStockID); // the StockID ctor checks for 0
79 void Image::get_icon_set(IconSet& icon_set, IconSize& size) const
81 GtkIconSet* pIconSet = 0;
82 GtkIconSize icon_size = GTK_ICON_SIZE_INVALID;
84 gtk_image_get_icon_set(const_cast<GtkImage*>(gobj()), &pIconSet, &icon_size);
86 size = IconSize(static_cast<int>(icon_size));
87 icon_set = Glib::wrap(pIconSet, true); //true = take_copy.
90 Glib::ustring Image::get_icon_name() const
92 const gchar* pchIconName = 0;
93 gtk_image_get_icon_name(const_cast<GtkImage*>(gobj()), &pchIconName, 0);
94 return Glib::convert_const_gchar_ptr_to_ustring(pchIconName);
97 Glib::ustring Image::get_icon_name(IconSize& size)
99 const gchar* pchIconName = 0;
100 GtkIconSize cIconSize = GTK_ICON_SIZE_INVALID;
101 gtk_image_get_icon_name(const_cast<GtkImage*>(gobj()), &pchIconName, &cIconSize);
102 size = (IconSize)cIconSize;
103 return Glib::convert_const_gchar_ptr_to_ustring(pchIconName);