| 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 <gtk/gtk.h> |
| 18 |
|
| 19 |
namespace Gtk |
| 20 |
{ |
| 21 |
|
| 22 |
#ifndef GTKMM_DISABLE_DEPRECATED |
| 23 |
Image::Image(const Gtk::StockID& stock_id, IconSize size) |
| 24 |
: |
| 25 |
_CONSTRUCT("stock", stock_id.get_c_str(), "icon-size", (GtkIconSize) int(size)) |
| 26 |
{} |
| 27 |
#endif //GTKMM_DISABLE_DEPRECATED |
| 28 |
|
| 29 |
#ifndef GTKMM_DISABLE_DEPRECATED |
| 30 |
Image::Image(const Glib::RefPtr<IconSet>& icon_set, IconSize size) |
| 31 |
: |
| 32 |
_CONSTRUCT("icon-set", (icon_set ? icon_set->gobj() : nullptr), "icon-size", (GtkIconSize) int(size)) |
| 33 |
{} |
| 34 |
#endif //GTKMM_DISABLE_DEPRECATED |
| 35 |
|
| 36 |
Image::Image(const Glib::RefPtr<Gdk::PixbufAnimation>& animation) |
| 37 |
: |
| 38 |
_CONSTRUCT("pixbuf-animation", Glib::unwrap(animation)) |
| 39 |
{} |
| 40 |
|
| 41 |
#ifndef GTKMM_DISABLE_DEPRECATED |
| 42 |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
| 43 |
void Image::get_stock(Gtk::StockID& stock_id, IconSize& size) const |
| 44 |
{ |
| 45 |
char* pStockID = nullptr; // GTK+ iconsistency: although not const, it should not be freed. |
| 46 |
GtkIconSize icon_size = GTK_ICON_SIZE_INVALID; |
| 47 |
|
| 48 |
gtk_image_get_stock(const_cast<GtkImage*>(gobj()), &pStockID, &icon_size); |
| 49 |
|
| 50 |
size = IconSize(static_cast<int>(icon_size)); |
| 51 |
stock_id = Gtk::StockID(pStockID); // the StockID ctor checks for 0 |
| 52 |
} |
| 53 |
G_GNUC_END_IGNORE_DEPRECATIONS |
| 54 |
#endif //GTKMM_DISABLE_DEPRECATED |
| 55 |
|
| 56 |
#ifndef GTKMM_DISABLE_DEPRECATED |
| 57 |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
| 58 |
void Image::get_icon_set(Glib::RefPtr<IconSet>& icon_set, IconSize& size) const |
| 59 |
{ |
| 60 |
GtkIconSet* pIconSet = nullptr; |
| 61 |
GtkIconSize icon_size = GTK_ICON_SIZE_INVALID; |
| 62 |
|
| 63 |
gtk_image_get_icon_set(const_cast<GtkImage*>(gobj()), &pIconSet, &icon_size); |
| 64 |
|
| 65 |
size = IconSize(static_cast<int>(icon_size)); |
| 66 |
icon_set = Glib::wrap(pIconSet, true); //true = take_copy. |
| 67 |
} |
| 68 |
G_GNUC_END_IGNORE_DEPRECATIONS |
| 69 |
#endif //GTKMM_DISABLE_DEPRECATED |
| 70 |
|
| 71 |
Glib::ustring Image::get_icon_name() const |
| 72 |
{ |
| 73 |
const gchar* pchIconName = nullptr; |
| 74 |
gtk_image_get_icon_name(const_cast<GtkImage*>(gobj()), &pchIconName, nullptr); |
| 75 |
return Glib::convert_const_gchar_ptr_to_ustring(pchIconName); |
| 76 |
} |
| 77 |
|
| 78 |
Glib::RefPtr<Gio::Icon> Image::get_gicon(Gtk::IconSize& icon_size) |
| 79 |
{ |
| 80 |
GIcon* cicon = nullptr; |
| 81 |
GtkIconSize cicon_size = GTK_ICON_SIZE_INVALID; |
| 82 |
gtk_image_get_gicon(gobj(), &cicon, &cicon_size); |
| 83 |
|
| 84 |
icon_size = Gtk::IconSize(cicon_size); |
| 85 |
return Glib::wrap(cicon); |
| 86 |
} |
| 87 |
|
| 88 |
Glib::RefPtr<const Gio::Icon> Image::get_gicon(Gtk::IconSize& icon_size) const |
| 89 |
{ |
| 90 |
auto nonconstthis = const_cast<Image*>(this); |
| 91 |
return nonconstthis->get_gicon(icon_size); |
| 92 |
} |
| 93 |
|
| 94 |
} // namespace Gtk |