| 1 |
/* Copyright (C) 1998-2002 The gtkmm Development Team |
| 2 |
* |
| 3 |
* This library is free software; you can redistribute it and/or |
| 4 |
* modify it under the terms of the GNU Lesser General Public |
| 5 |
* License as published by the Free Software Foundation; either |
| 6 |
* version 2.1 of the License, or (at your option) any later version. |
| 7 |
* |
| 8 |
* This library is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 |
* Lesser General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU Lesser General Public |
| 14 |
* License along with this library; if not, see <https://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
#include <gtkmm/misc.h> |
| 18 |
#ifndef GTKMM_DISABLE_DEPRECATED |
| 19 |
#include <gtkmm/iconset.h> |
| 20 |
#endif |
| 21 |
#include <gdkmm/pixbufanimation.h> |
| 22 |
#include <giomm/icon.h> |
| 23 |
|
| 24 |
_DEFS(gtkmm,gtk) |
| 25 |
_PINCLUDE(gtkmm/private/misc_p.h) |
| 26 |
|
| 27 |
namespace Gtk |
| 28 |
{ |
| 29 |
|
| 30 |
_CC_INCLUDE(gtk/gtk.h) |
| 31 |
_WRAP_ENUM(ImageType, GtkImageType, decl_prefix GTKMM_API) |
| 32 |
|
| 33 |
|
| 34 |
/** A widget displaying an image. |
| 35 |
* |
| 36 |
* The Gtk::Image widget displays an image. Various kinds of object can be |
| 37 |
* displayed as an image; most typically, you would load a Gdk::Pixbuf ("pixel |
| 38 |
* buffer") from a file, and then display that. |
| 39 |
* |
| 40 |
* Gtk::Image is a subclass of Gtk::Misc, which implies that you can align it |
| 41 |
* (center, left, right) and add padding to it, using Gtk::Misc methods. |
| 42 |
* |
| 43 |
* Gtk::Image is a "no window" widget (has no Gdk::Window of its own), so by |
| 44 |
* default does not receive events. If you want to receive events on the |
| 45 |
* image, such as button clicks, place the image inside a Gtk::EventBox, then |
| 46 |
* connect to the event signals on the event box. |
| 47 |
* |
| 48 |
* The Image widget looks like this: |
| 49 |
* @image html image1.png |
| 50 |
* |
| 51 |
* @ingroup Widgets |
| 52 |
*/ |
| 53 |
class GTKMM_API Image : public Misc |
| 54 |
{ |
| 55 |
_CLASS_GTKOBJECT(Image,GtkImage,GTK_IMAGE,Gtk::Misc,GtkMisc,,,GTKMM_API) |
| 56 |
_IGNORE(gtk_image_get_stock, gtk_image_get_icon_set) |
| 57 |
public: |
| 58 |
|
| 59 |
_CTOR_DEFAULT |
| 60 |
|
| 61 |
/** Creates an Image widget displaying the file @a filename. |
| 62 |
* If the file isn't found or can't be loaded, the resulting Gtk::Image will display a "broken image" icon. |
| 63 |
* |
| 64 |
* If the file contains an animation, the image will contain an animation. |
| 65 |
* |
| 66 |
* If you need to detect failures to load the file, use Gdk::Pixbuf::create_from_file() to load the file yourself, |
| 67 |
* then create the GtkImage from the pixbuf. (Or for animations, use Gdk::PixbufAnimation::create_from_file()). |
| 68 |
* |
| 69 |
* The storage type (get_storage_type()) of the returned image is not defined. It will be whatever is appropriate for displaying the file. |
| 70 |
*/ |
| 71 |
_WRAP_CTOR(Image(const std::string& file), gtk_image_new_from_file) |
| 72 |
|
| 73 |
/** Creates a new Image widget displaying @a pixbuf. |
| 74 |
* Note that this just creates an GtkImage from the pixbuf. The Gtk::Image created will not react to state changes. |
| 75 |
* Should you want that, you should use the default constructor and set_from_icon_name(). |
| 76 |
*/ |
| 77 |
_WRAP_CTOR(Image(const Glib::RefPtr<Gdk::Pixbuf>& pixbuf), gtk_image_new_from_pixbuf) |
| 78 |
_IGNORE(gtk_image_new_from_icon_set) // deprecated since 3.10 |
| 79 |
|
| 80 |
//We don't wrap gtk_image_new_from_resource() to avoid a clash with the from-filename constructor. |
| 81 |
//But we do wrap gtk_image_set_from_resource() |
| 82 |
_IGNORE(gtk_image_new_from_resource) |
| 83 |
|
| 84 |
#ifndef GTKMM_DISABLE_DEPRECATED |
| 85 |
/** Creates an Image displaying a stock icon. |
| 86 |
* Sample stock icon identifiers are Gtk::Stock::OPEN, Gtk::Stock::EXIT. Sample stock sizes are Gtk::ICON_SIZE_MENU, Gtk::ICON_SIZE_SMALL_TOOLBAR. |
| 87 |
* If the stock icon name isn't known, a "broken image" icon will be displayed instead. |
| 88 |
* You can register your own stock icon names - see Gtk::IconFactory::add(). |
| 89 |
* @param stock_id A stock icon. |
| 90 |
* @param size A stock icon size. |
| 91 |
* @deprecated Use the default constructor and set_from_icon_name() instead. |
| 92 |
*/ |
| 93 |
Image(const Gtk::StockID& stock_id, IconSize size); |
| 94 |
#endif //GTKMM_DISABLE_DEPRECATED |
| 95 |
|
| 96 |
#ifndef GTKMM_DISABLE_DEPRECATED |
| 97 |
/** @deprecated Use the default constructor and set_from_icon_name() instead. |
| 98 |
*/ |
| 99 |
Image(const Glib::RefPtr<IconSet>& icon_set, IconSize size); |
| 100 |
#endif //GTKMM_DISABLE_DEPRECATED |
| 101 |
|
| 102 |
_WRAP_METHOD_DOCS_ONLY(gtk_image_set_from_animation) |
| 103 |
explicit Image(const Glib::RefPtr<Gdk::PixbufAnimation>& animation); |
| 104 |
|
| 105 |
_WRAP_METHOD_DOCS_ONLY(gtk_image_new_from_icon_name, newin "3,24") |
| 106 |
_WRAP_CTOR(Image(const Glib::ustring& icon_name, IconSize icon_size), gtk_image_new_from_icon_name) |
| 107 |
_WRAP_METHOD_DOCS_ONLY(gtk_image_new_from_gicon, newin "3,24") |
| 108 |
_WRAP_CTOR(Image(const Glib::RefPtr<Gio::Icon>& gicon, IconSize icon_size), gtk_image_new_from_gicon) |
| 109 |
#m4 _CONVERSION(`const ::Cairo::RefPtr< ::Cairo::Surface>&',`cairo_surface_t*',`($3) ? const_cast<cairo_surface_t*>(($3)->cobj()) : nullptr') |
| 110 |
/** Creates a new Gtk::Image displaying @a surface. |
| 111 |
* |
| 112 |
* @newin{3,24} |
| 113 |
* |
| 114 |
* @param surface A Cairo::Surface or an empty Cairo::RefPtr. |
| 115 |
* @return A new Gtk::Image. |
| 116 |
*/ |
| 117 |
_WRAP_CTOR(Image(const ::Cairo::RefPtr< ::Cairo::Surface>& surface), gtk_image_new_from_surface) |
| 118 |
|
| 119 |
_WRAP_METHOD(void set(const std::string& filename), gtk_image_set_from_file) |
| 120 |
_WRAP_METHOD(void set_from_resource(const std::string& resource_path), gtk_image_set_from_resource) |
| 121 |
_WRAP_METHOD(void set(const Glib::RefPtr<Gdk::Pixbuf>& pixbuf), gtk_image_set_from_pixbuf) |
| 122 |
_WRAP_METHOD(void set(const Gtk::StockID& stock_id, IconSize size), gtk_image_set_from_stock, deprecated "Use set_from_icon_name() instead.") |
| 123 |
_WRAP_METHOD(void set(const Glib::RefPtr<IconSet>& icon_set, IconSize size), gtk_image_set_from_icon_set, deprecated "Use set_from_icon_name() instead.") |
| 124 |
_WRAP_METHOD(void set(const Glib::RefPtr<Gdk::PixbufAnimation>& animation), gtk_image_set_from_animation) |
| 125 |
_WRAP_METHOD(void set(const Glib::RefPtr<const Gio::Icon>& icon, IconSize size), gtk_image_set_from_gicon) |
| 126 |
_WRAP_METHOD(void set(const ::Cairo::RefPtr< ::Cairo::Surface>& surface), gtk_image_set_from_surface) |
| 127 |
_WRAP_METHOD(void set_from_icon_name(const Glib::ustring& icon_name, IconSize size), gtk_image_set_from_icon_name) |
| 128 |
|
| 129 |
_WRAP_METHOD(void clear(), gtk_image_clear) |
| 130 |
|
| 131 |
_WRAP_METHOD(ImageType get_storage_type() const, gtk_image_get_storage_type) |
| 132 |
|
| 133 |
_WRAP_METHOD(Glib::RefPtr<Gdk::Pixbuf> get_pixbuf(), gtk_image_get_pixbuf, refreturn) |
| 134 |
_WRAP_METHOD(Glib::RefPtr<const Gdk::Pixbuf> get_pixbuf() const, gtk_image_get_pixbuf, refreturn, constversion) |
| 135 |
|
| 136 |
#ifndef GTKMM_DISABLE_DEPRECATED |
| 137 |
/** @deprecated Use get_icon_name() instead. |
| 138 |
*/ |
| 139 |
void get_stock(Gtk::StockID& stock_id, IconSize& size) const; |
| 140 |
#endif //GTKMM_DISABLE_DEPRECATED |
| 141 |
|
| 142 |
#ifndef GTKMM_DISABLE_DEPRECATED |
| 143 |
/** @deprecated Use get_icon_name() instead. |
| 144 |
*/ |
| 145 |
void get_icon_set(Glib::RefPtr<IconSet>& icon_set, IconSize& size) const; |
| 146 |
#endif //GTKMM_DISABLE_DEPRECATED |
| 147 |
|
| 148 |
_WRAP_METHOD(Glib::RefPtr<Gdk::PixbufAnimation> get_animation(), gtk_image_get_animation, refreturn) |
| 149 |
_WRAP_METHOD(Glib::RefPtr<const Gdk::PixbufAnimation> get_animation() const, gtk_image_get_animation, refreturn, constversion) |
| 150 |
|
| 151 |
/** Gets the Gio::Icon and size being displayed by the Gtk::Image. |
| 152 |
* The storage type of the image must be IMAGE_EMPTY or |
| 153 |
* IMAGE_GICON (see get_storage_type()). |
| 154 |
* |
| 155 |
* @param icon_size A place to store an icon size. |
| 156 |
* |
| 157 |
* @newin{2,14} |
| 158 |
*/ |
| 159 |
Glib::RefPtr<Gio::Icon> get_gicon(Gtk::IconSize& icon_size); |
| 160 |
|
| 161 |
/** Gets the Gio::Icon and size being displayed by the Gtk::Image. |
| 162 |
* The storage type of the image must be IMAGE_EMPTY or |
| 163 |
* IMAGE_GICON (see get_storage_type()). |
| 164 |
* |
| 165 |
* @param icon_size A place to store an icon size. |
| 166 |
* |
| 167 |
* @newin{2,14} |
| 168 |
*/ |
| 169 |
Glib::RefPtr<const Gio::Icon> get_gicon(Gtk::IconSize& icon_size) const; |
| 170 |
_IGNORE(gtk_image_get_gicon) |
| 171 |
|
| 172 |
Glib::ustring get_icon_name() const; |
| 173 |
Glib::ustring get_icon_name(IconSize& size); |
| 174 |
_IGNORE(gtk_image_get_icon_name) |
| 175 |
|
| 176 |
_WRAP_METHOD(int get_pixel_size() const, gtk_image_get_pixel_size) |
| 177 |
_WRAP_METHOD(void set_pixel_size(int pixel_size), gtk_image_set_pixel_size) |
| 178 |
|
| 179 |
_WRAP_PROPERTY("pixbuf", Glib::RefPtr<Gdk::Pixbuf>) |
| 180 |
_WRAP_PROPERTY("file", Glib::ustring) |
| 181 |
_WRAP_PROPERTY("stock", Glib::ustring, deprecated "Use property_icon_name() instead.") |
| 182 |
_WRAP_PROPERTY("icon-set", Glib::RefPtr<IconSet>, deprecated "Use property_icon_name() instead.") |
| 183 |
_WRAP_PROPERTY("icon-size", int) |
| 184 |
_WRAP_PROPERTY("pixel-size", int) |
| 185 |
_WRAP_PROPERTY("pixbuf-animation", Glib::RefPtr<Gdk::PixbufAnimation>) |
| 186 |
_WRAP_PROPERTY("icon-name", Glib::ustring) |
| 187 |
_WRAP_PROPERTY("storage-type", ImageType) |
| 188 |
_WRAP_PROPERTY("gicon", Glib::RefPtr<Gio::Icon>) |
| 189 |
_WRAP_PROPERTY("use-fallback", bool) |
| 190 |
_WRAP_PROPERTY("resource", std::string) |
| 191 |
_WRAP_PROPERTY("surface", ::Cairo::RefPtr< ::Cairo::Surface>) |
| 192 |
}; |
| 193 |
|
| 194 |
} //namespace Gtk |