| 1 |
/* Copyright (C) 2003 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 <glibmm/vectorutils.h> |
| 18 |
|
| 19 |
#include <gtk/gtk.h> |
| 20 |
#include <gtkmm/icontheme.h> |
| 21 |
//TODO: Install and use this? #include <giomm/slot_async.h> |
| 22 |
|
| 23 |
namespace { |
| 24 |
|
| 25 |
//This is just to satisfy our generated code, which cannot |
| 26 |
//handle just using g_object_ref() because it needs a cast. |
| 27 |
static GtkIconInfo* gtk_icon_info_ref(GtkIconInfo* icon_info) |
| 28 |
{ |
| 29 |
g_object_ref (G_OBJECT(icon_info)); |
| 30 |
return icon_info; |
| 31 |
} |
| 32 |
|
| 33 |
//TODO: Install and use giomm's slot_async.h if we use this more often: |
| 34 |
static void |
| 35 |
SignalProxy_async_callback(GObject*, GAsyncResult* res, void* data) |
| 36 |
{ |
| 37 |
auto the_slot = static_cast<Gio::SlotAsyncReady*>(data); |
| 38 |
|
| 39 |
try |
| 40 |
{ |
| 41 |
auto result = Glib::wrap(res, true /* take copy */); |
| 42 |
(*the_slot)(result); |
| 43 |
} |
| 44 |
catch(...) |
| 45 |
{ |
| 46 |
Glib::exception_handlers_invoke(); |
| 47 |
} |
| 48 |
|
| 49 |
delete the_slot; |
| 50 |
} |
| 51 |
|
| 52 |
} |
| 53 |
|
| 54 |
namespace Gtk |
| 55 |
{ |
| 56 |
|
| 57 |
IconInfo::IconInfo(const Glib::RefPtr<IconTheme>& icon_theme, const Glib::RefPtr<Gdk::Pixbuf>& pixbuf) |
| 58 |
: gobject_( gtk_icon_info_new_for_pixbuf(Glib::unwrap(icon_theme), pixbuf->gobj()) ) |
| 59 |
{ |
| 60 |
} |
| 61 |
|
| 62 |
_DEPRECATE_IFDEF_START |
| 63 |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
| 64 |
std::vector<Gdk::Point> IconInfo::get_attach_points() const |
| 65 |
{ |
| 66 |
GdkPoint* c_attach_points = nullptr; |
| 67 |
gint n_points = 0; |
| 68 |
gtk_icon_info_get_attach_points (const_cast<GtkIconInfo*>(gobj()), &c_attach_points, &n_points); |
| 69 |
|
| 70 |
if (c_attach_points) |
| 71 |
{ |
| 72 |
return Glib::ArrayHandler<Gdk::Point, Gdk::PointTraits>::array_to_vector(c_attach_points, n_points, Glib::OWNERSHIP_DEEP); |
| 73 |
} |
| 74 |
return std::vector<Gdk::Point> (); |
| 75 |
} |
| 76 |
G_GNUC_END_IGNORE_DEPRECATIONS |
| 77 |
_DEPRECATE_IFDEF_END |
| 78 |
|
| 79 |
_DEPRECATE_IFDEF_START |
| 80 |
IconInfo::operator const void*() const |
| 81 |
{ |
| 82 |
return gobj() ? GINT_TO_POINTER(1) : nullptr; |
| 83 |
} |
| 84 |
_DEPRECATE_IFDEF_END |
| 85 |
|
| 86 |
IconInfo::operator bool() const |
| 87 |
{ |
| 88 |
return gobj(); |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
Glib::RefPtr<Gdk::Pixbuf> IconInfo::load_symbolic(const Gdk::RGBA& fg, const Gdk::RGBA& success_color, const Gdk::RGBA& warning_color, const Gdk::RGBA& error_color, bool& was_symbolic) const |
| 93 |
{ |
| 94 |
GError* gerror = nullptr; |
| 95 |
gboolean c_was_symbolic = false; |
| 96 |
auto retvalue = Glib::wrap(gtk_icon_info_load_symbolic(const_cast<GtkIconInfo*>(gobj()), const_cast<GdkRGBA*>(fg.gobj()), const_cast<GdkRGBA*>(success_color.gobj()), const_cast<GdkRGBA*>(warning_color.gobj()), const_cast<GdkRGBA*>(error_color.gobj()), &c_was_symbolic, &(gerror))); |
| 97 |
was_symbolic = c_was_symbolic; |
| 98 |
if(gerror) |
| 99 |
::Glib::Error::throw_exception(gerror); |
| 100 |
|
| 101 |
return retvalue; |
| 102 |
} |
| 103 |
|
| 104 |
Glib::RefPtr<Gdk::Pixbuf> IconInfo::load_symbolic(const Glib::RefPtr<StyleContext>& style, bool& was_symbolic) |
| 105 |
{ |
| 106 |
GError* gerror = nullptr; |
| 107 |
gboolean c_was_symbolic = false; |
| 108 |
auto retvalue = Glib::wrap(gtk_icon_info_load_symbolic_for_context(gobj(), Glib::unwrap(style), &c_was_symbolic, &(gerror))); |
| 109 |
was_symbolic = c_was_symbolic; |
| 110 |
if(gerror) |
| 111 |
::Glib::Error::throw_exception(gerror); |
| 112 |
|
| 113 |
return retvalue; |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
/* deprecated |
| 118 |
Glib::RefPtr<Gdk::Pixbuf> IconInfo::load_symbolic(const Glib::RefPtr<Style>& style, StateType state, bool& was_symbolic) const |
| 119 |
{ |
| 120 |
GError* gerror = nullptr; |
| 121 |
gboolean c_was_symbolic = false; |
| 122 |
auto retvalue = Glib::wrap(gtk_icon_info_load_symbolic_for_style(const_cast<GtkIconInfo*>(gobj()), Glib::unwrap(style), ((GtkStateType)(state)), &c_was_symbolic, &(gerror))); |
| 123 |
was_symbolic = c_was_symbolic; |
| 124 |
if(gerror) |
| 125 |
::Glib::Error::throw_exception(gerror); |
| 126 |
|
| 127 |
return retvalue; |
| 128 |
} |
| 129 |
*/ |
| 130 |
|
| 131 |
void IconInfo::load_icon_async(const Gio::SlotAsyncReady& slot, const Glib::RefPtr<Gio::Cancellable>& cancellable) |
| 132 |
{ |
| 133 |
// Create a copy of the slot. |
| 134 |
// A pointer to it will be passed through the callback's data parameter |
| 135 |
// and deleted in the callback. |
| 136 |
auto slot_copy = new Gio::SlotAsyncReady(slot); |
| 137 |
|
| 138 |
gtk_icon_info_load_icon_async(gobj(), |
| 139 |
Glib::unwrap(cancellable), |
| 140 |
&SignalProxy_async_callback, |
| 141 |
slot_copy); |
| 142 |
} |
| 143 |
|
| 144 |
void IconInfo::load_icon_async(const Gio::SlotAsyncReady& slot) |
| 145 |
{ |
| 146 |
// Create a copy of the slot. |
| 147 |
// A pointer to it will be passed through the callback's data parameter |
| 148 |
// and deleted in the callback. |
| 149 |
auto slot_copy = new Gio::SlotAsyncReady(slot); |
| 150 |
|
| 151 |
gtk_icon_info_load_icon_async(gobj(), |
| 152 |
nullptr, |
| 153 |
&SignalProxy_async_callback, |
| 154 |
slot_copy); |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
void IconInfo::load_symbolic_async(const Gdk::RGBA& fg, const Gdk::RGBA& success_color, const Gdk::RGBA& warning_color, const Gdk::RGBA& error_color, const Gio::SlotAsyncReady& slot, const Glib::RefPtr<Gio::Cancellable>& cancellable) |
| 159 |
{ |
| 160 |
// Create a copy of the slot. |
| 161 |
// A pointer to it will be passed through the callback's data parameter |
| 162 |
// and deleted in the callback. |
| 163 |
auto slot_copy = new Gio::SlotAsyncReady(slot); |
| 164 |
|
| 165 |
gtk_icon_info_load_symbolic_async(gobj(), |
| 166 |
fg.gobj(), |
| 167 |
success_color.gobj(), |
| 168 |
warning_color.gobj(), |
| 169 |
error_color.gobj(), |
| 170 |
Glib::unwrap(cancellable), |
| 171 |
&SignalProxy_async_callback, |
| 172 |
slot_copy); |
| 173 |
} |
| 174 |
|
| 175 |
void IconInfo::load_symbolic_async(const Gdk::RGBA& fg, const Gdk::RGBA& success_color, const Gdk::RGBA& warning_color, const Gdk::RGBA& error_color, const Gio::SlotAsyncReady& slot) |
| 176 |
{ |
| 177 |
// Create a copy of the slot. |
| 178 |
// A pointer to it will be passed through the callback's data parameter |
| 179 |
// and deleted in the callback. |
| 180 |
auto slot_copy = new Gio::SlotAsyncReady(slot); |
| 181 |
|
| 182 |
gtk_icon_info_load_symbolic_async(gobj(), |
| 183 |
fg.gobj(), |
| 184 |
success_color.gobj(), |
| 185 |
warning_color.gobj(), |
| 186 |
error_color.gobj(), |
| 187 |
nullptr, |
| 188 |
&SignalProxy_async_callback, |
| 189 |
slot_copy); |
| 190 |
} |
| 191 |
|
| 192 |
|
| 193 |
void IconInfo::load_symbolic_for_context_async(const Glib::RefPtr<StyleContext>& context, const Gio::SlotAsyncReady& slot, const Glib::RefPtr<Gio::Cancellable>& cancellable) |
| 194 |
{ |
| 195 |
// Create a copy of the slot. |
| 196 |
// A pointer to it will be passed through the callback's data parameter |
| 197 |
// and deleted in the callback. |
| 198 |
auto slot_copy = new Gio::SlotAsyncReady(slot); |
| 199 |
|
| 200 |
gtk_icon_info_load_symbolic_for_context_async(gobj(), |
| 201 |
Glib::unwrap(context), |
| 202 |
Glib::unwrap(cancellable), |
| 203 |
&SignalProxy_async_callback, |
| 204 |
slot_copy); |
| 205 |
} |
| 206 |
|
| 207 |
void IconInfo::load_symbolic_for_context_async(const Glib::RefPtr<StyleContext>& context, const Gio::SlotAsyncReady& slot) |
| 208 |
{ |
| 209 |
// Create a copy of the slot. |
| 210 |
// A pointer to it will be passed through the callback's data parameter |
| 211 |
// and deleted in the callback. |
| 212 |
auto slot_copy = new Gio::SlotAsyncReady(slot); |
| 213 |
|
| 214 |
gtk_icon_info_load_symbolic_for_context_async(gobj(), |
| 215 |
Glib::unwrap(context), |
| 216 |
nullptr, |
| 217 |
&SignalProxy_async_callback, |
| 218 |
slot_copy); |
| 219 |
} |
| 220 |
|
| 221 |
} // namespace Gtk |