| 1 |
/* Copyright (C) 2010 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 |
| 20 |
{ |
| 21 |
static void CssProvider_signal_parsing_error_callback(GtkCssProvider* self, GtkCssSection* p0,const GError* p1,void* data) |
| 22 |
{ |
| 23 |
using namespace Gtk; |
| 24 |
typedef sigc::slot< void,const Glib::RefPtr<const CssSection>&,const Glib::Error& > SlotType; |
| 25 |
|
| 26 |
auto obj = dynamic_cast<CssProvider*>(Glib::ObjectBase::_get_current_wrapper((GObject*) self)); |
| 27 |
// Do not try to call a signal on a disassociated wrapper. |
| 28 |
if(obj) |
| 29 |
{ |
| 30 |
try |
| 31 |
{ |
| 32 |
Glib::Error::throw_exception(g_error_copy(p1)); |
| 33 |
} |
| 34 |
catch (const Glib::Error& ex) |
| 35 |
{ |
| 36 |
// ex can be (and usually is) an instance of a subclass ofGlib::Error. |
| 37 |
try |
| 38 |
{ |
| 39 |
if(sigc::slot_base *const slot = Glib::SignalProxyNormal::data_to_slot(data)) |
| 40 |
(*static_cast<SlotType*>(slot))(Glib::wrap(p0, true), ex); |
| 41 |
} |
| 42 |
catch (...) |
| 43 |
{ |
| 44 |
Glib::exception_handlers_invoke(); |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
} // anonymous namespace |
| 51 |
|
| 52 |
namespace Gtk |
| 53 |
{ |
| 54 |
|
| 55 |
bool CssProvider::load_from_data(const std::string& data) |
| 56 |
{ |
| 57 |
GError* gerror = nullptr; |
| 58 |
bool retvalue = gtk_css_provider_load_from_data(gobj(), data.c_str(), -1, &(gerror)); |
| 59 |
if(gerror) |
| 60 |
Glib::Error::throw_exception(gerror); |
| 61 |
|
| 62 |
return retvalue; |
| 63 |
} |
| 64 |
|
| 65 |
//TODO: When we can break ABI, remove no_default_handler in _WRAP_SIGNAL and |
| 66 |
// uncomment CssProvider_Class::parsing_error_callback(). |
| 67 |
#if 0 |
| 68 |
void CssProvider_Class::parsing_error_callback(GtkCssProvider* self, GtkCssSection* p0, const GError* p1) |
| 69 |
{ |
| 70 |
const auto obj_base = static_cast<Glib::ObjectBase*>( |
| 71 |
Glib::ObjectBase::_get_current_wrapper((GObject*)self)); |
| 72 |
|
| 73 |
// Non-gtkmmproc-generated custom classes implicitly call the default |
| 74 |
// Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc- |
| 75 |
// generated classes can use this optimisation, which avoids the unnecessary |
| 76 |
// parameter conversions if there is no possibility of the virtual function |
| 77 |
// being overridden: |
| 78 |
if(obj_base && obj_base->is_derived_()) |
| 79 |
{ |
| 80 |
const auto obj = dynamic_cast<CppObjectType* const>(obj_base); |
| 81 |
if(obj) // This can be NULL during destruction. |
| 82 |
{ |
| 83 |
try |
| 84 |
{ |
| 85 |
Glib::Error::throw_exception(g_error_copy(p1)); |
| 86 |
} |
| 87 |
catch (const Glib::Error& ex) |
| 88 |
{ |
| 89 |
// ex can be (and usually is) an instance of a subclass ofGlib::Error. |
| 90 |
try // Trap C++ exceptions which would normally be lost because this is a C callback. |
| 91 |
{ |
| 92 |
// Call the virtual member method, which derived classes might override. |
| 93 |
obj->on_parsing_error(Glib::wrap(p0, true), ex); |
| 94 |
return; |
| 95 |
} |
| 96 |
catch(...) |
| 97 |
{ |
| 98 |
Glib::exception_handlers_invoke(); |
| 99 |
} |
| 100 |
} |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
const auto base = static_cast<BaseClassType*>( |
| 105 |
g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class). |
| 106 |
); |
| 107 |
|
| 108 |
// Call the original underlying C function: |
| 109 |
if(base && base->parsing_error) |
| 110 |
(*base->parsing_error)(self, p0, p1); |
| 111 |
} |
| 112 |
#endif |
| 113 |
} //namespace Gtk |