| 1 |
/* Copyright (C) 2009 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 |
#include <gtkmm/builder.h> |
| 19 |
#include <cstring> |
| 20 |
|
| 21 |
namespace Gtk |
| 22 |
{ |
| 23 |
|
| 24 |
//static |
| 25 |
gboolean Buildable_Class::custom_tag_start_vfunc_callback( |
| 26 |
GtkBuildable* buildable, |
| 27 |
GtkBuilder* builder, |
| 28 |
GObject* child, |
| 29 |
const gchar* tagname, |
| 30 |
GMarkupParser* parser, |
| 31 |
gpointer* data) |
| 32 |
{ |
| 33 |
// If it's a TreeModel (such as ListStore or TreeStore) and it's the start |
| 34 |
// of a <columns> element, inform the Builder that the get_type_from_name() |
| 35 |
// vfunc shall not search for gtkmm-derived types. |
| 36 |
// See https://bugzilla.gnome.org/show_bug.cgi?id=742637 |
| 37 |
if (GTK_IS_TREE_MODEL(buildable) && std::strcmp(tagname, "columns") == 0) |
| 38 |
{ |
| 39 |
const auto cpp_builder = dynamic_cast<Builder*>( |
| 40 |
Glib::ObjectBase::_get_current_wrapper((GObject*)builder)); |
| 41 |
if (cpp_builder) |
| 42 |
cpp_builder->set_no_gtkmm_derived_types(true); |
| 43 |
} |
| 44 |
|
| 45 |
const auto base = static_cast<BaseClassType*>( |
| 46 |
g_type_interface_peek_parent( // Get the parent interface of the interface (The original underlying C interface). |
| 47 |
g_type_interface_peek(G_OBJECT_GET_CLASS(buildable), CppObjectType::get_type()) // Get the interface. |
| 48 |
) |
| 49 |
); |
| 50 |
|
| 51 |
// Call the original underlying C function: |
| 52 |
if (base && base->custom_tag_start) |
| 53 |
return (*base->custom_tag_start)(buildable, builder, child, tagname, parser, data); |
| 54 |
return false; |
| 55 |
} |
| 56 |
|
| 57 |
//static |
| 58 |
void Buildable_Class::custom_tag_end_vfunc_callback( |
| 59 |
GtkBuildable* buildable, |
| 60 |
GtkBuilder* builder, |
| 61 |
GObject* child, |
| 62 |
const gchar* tagname, |
| 63 |
gpointer* data) |
| 64 |
{ |
| 65 |
const auto base = static_cast<BaseClassType*>( |
| 66 |
g_type_interface_peek_parent( // Get the parent interface of the interface (The original underlying C interface). |
| 67 |
g_type_interface_peek(G_OBJECT_GET_CLASS(buildable), CppObjectType::get_type()) // Get the interface. |
| 68 |
) |
| 69 |
); |
| 70 |
|
| 71 |
// Call the original underlying C function: |
| 72 |
if (base && base->custom_tag_end) |
| 73 |
(*base->custom_tag_end)(buildable, builder, child, tagname, data); |
| 74 |
|
| 75 |
// If it's a TreeModel (such as ListStore or TreeStore) and it's the end |
| 76 |
// of a </columns> element, inform the Builder that the get_type_from_name() |
| 77 |
// vfunc shall resume search for gtkmm-derived types. |
| 78 |
// See https://bugzilla.gnome.org/show_bug.cgi?id=742637 |
| 79 |
if (GTK_IS_TREE_MODEL(buildable) && std::strcmp(tagname, "columns") == 0) |
| 80 |
{ |
| 81 |
const auto cpp_builder = dynamic_cast<Builder*>( |
| 82 |
Glib::ObjectBase::_get_current_wrapper((GObject*)builder)); |
| 83 |
if (cpp_builder) |
| 84 |
cpp_builder->set_no_gtkmm_derived_types(false); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
} // namespace Gtk |