| 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 <gtkmm/treeiter.h> |
| 18 |
#include <gtkmm/entry.h> |
| 19 |
#include <gtk/gtk.h> |
| 20 |
|
| 21 |
|
| 22 |
static gboolean SignalProxy_Match_gtk_callback(GtkEntryCompletion* completion, const gchar* key, GtkTreeIter* iter, gpointer user_data) |
| 23 |
{ |
| 24 |
auto the_slot = static_cast<Gtk::EntryCompletion::SlotMatch*>(user_data); |
| 25 |
|
| 26 |
try |
| 27 |
{ |
| 28 |
auto tree_model = gtk_entry_completion_get_model(completion); |
| 29 |
return (*the_slot)(Glib::convert_const_gchar_ptr_to_ustring(key), |
| 30 |
Gtk::TreeModel::const_iterator(tree_model, iter) |
| 31 |
); |
| 32 |
} |
| 33 |
catch(...) |
| 34 |
{ |
| 35 |
Glib::exception_handlers_invoke(); |
| 36 |
} |
| 37 |
|
| 38 |
return false; //An arbitary default, just to avoid the compiler warning. |
| 39 |
} |
| 40 |
|
| 41 |
static void SignalProxy_Match_gtk_callback_destroy(void* data) |
| 42 |
{ |
| 43 |
delete static_cast<Gtk::EntryCompletion::SlotMatch*>(data); |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
namespace Gtk |
| 48 |
{ |
| 49 |
|
| 50 |
void EntryCompletion::unset_model() |
| 51 |
{ |
| 52 |
gtk_entry_completion_set_model(gobj(), nullptr); |
| 53 |
} |
| 54 |
|
| 55 |
void EntryCompletion::set_match_func(const SlotMatch& slot) |
| 56 |
{ |
| 57 |
// Create a copy of the slot. A pointer to this will be passed |
| 58 |
// through the callback's data parameter. It will be deleted |
| 59 |
// when SignalProxy_Match_gtk_callback_destroy() is called. |
| 60 |
auto slot_copy = new SlotMatch(slot); |
| 61 |
|
| 62 |
gtk_entry_completion_set_match_func(gobj(), |
| 63 |
&SignalProxy_Match_gtk_callback, slot_copy, |
| 64 |
&SignalProxy_Match_gtk_callback_destroy); |
| 65 |
} |
| 66 |
|
| 67 |
void EntryCompletion::insert_action_text(const Glib::ustring& text, int index) |
| 68 |
{ |
| 69 |
gtk_entry_completion_insert_action_text(gobj(), index, text.c_str()); |
| 70 |
} |
| 71 |
|
| 72 |
void EntryCompletion::insert_action_markup(const Glib::ustring& markup, int index) |
| 73 |
{ |
| 74 |
gtk_entry_completion_insert_action_markup(gobj(), index, markup.c_str()); |
| 75 |
} |
| 76 |
|
| 77 |
void EntryCompletion::prepend_action_text(const Glib::ustring& text) |
| 78 |
{ |
| 79 |
//We know that gtk_entry_completion_insert_action_text() uses gtk_list_store_insert(), |
| 80 |
//and we know that gtk_list_store_insert() prepends if the position is 0, though |
| 81 |
//this is not actually documented. |
| 82 |
gtk_entry_completion_insert_action_text(gobj(), 0, text.c_str()); |
| 83 |
} |
| 84 |
|
| 85 |
void EntryCompletion::prepend_action_markup(const Glib::ustring& markup) |
| 86 |
{ |
| 87 |
//We know that gtk_entry_completion_insert_action_markup() uses gtk_list_store_insert(), |
| 88 |
//and we know that gtk_list_store_insert() prepends if the position is 0, though |
| 89 |
//this is not actually documented. |
| 90 |
gtk_entry_completion_insert_action_markup(gobj(), 0 /* See C docs */, markup.c_str()); |
| 91 |
} |
| 92 |
|
| 93 |
} //namespace Gtk |
| 94 |
|
| 95 |
|
| 96 |
namespace //anonymous |
| 97 |
{ |
| 98 |
|
| 99 |
static gboolean Widget_signal_match_selected_callback(GtkEntryCompletion* self, GtkTreeModel* c_model, GtkTreeIter* c_iter, void* data) |
| 100 |
{ |
| 101 |
using namespace Gtk; |
| 102 |
typedef sigc::slot< bool, const TreeModel::iterator& > SlotType; |
| 103 |
|
| 104 |
// Do not try to call a signal on a disassociated wrapper. |
| 105 |
if(Glib::ObjectBase::_get_current_wrapper((GObject*) self)) |
| 106 |
{ |
| 107 |
try |
| 108 |
{ |
| 109 |
if(sigc::slot_base *const slot = Glib::SignalProxyNormal::data_to_slot(data)) |
| 110 |
{ |
| 111 |
//This conversion is the custom-written part: |
| 112 |
Gtk::TreeModel::iterator cppIter(c_model, c_iter); |
| 113 |
|
| 114 |
return static_cast<int>( (*static_cast<SlotType*>(slot))(cppIter) ); |
| 115 |
} |
| 116 |
} |
| 117 |
catch(...) |
| 118 |
{ |
| 119 |
Glib::exception_handlers_invoke(); |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
typedef gboolean RType; |
| 124 |
return RType(); |
| 125 |
} |
| 126 |
|
| 127 |
static gboolean Widget_signal_match_selected_notify_callback(GtkEntryCompletion* self, GtkTreeModel* c_model, GtkTreeIter* c_iter, void* data) |
| 128 |
{ |
| 129 |
using namespace Gtk; |
| 130 |
typedef sigc::slot< void, const TreeModel::iterator& > SlotType; |
| 131 |
|
| 132 |
// Do not try to call a signal on a disassociated wrapper. |
| 133 |
if(Glib::ObjectBase::_get_current_wrapper((GObject*) self)) |
| 134 |
{ |
| 135 |
try |
| 136 |
{ |
| 137 |
if(sigc::slot_base *const slot = Glib::SignalProxyNormal::data_to_slot(data)) |
| 138 |
{ |
| 139 |
//This conversion is the custom-written part: |
| 140 |
Gtk::TreeModel::iterator cppIter(c_model, c_iter); |
| 141 |
|
| 142 |
(*static_cast<SlotType*>(slot))(cppIter); |
| 143 |
} |
| 144 |
} |
| 145 |
catch(...) |
| 146 |
{ |
| 147 |
Glib::exception_handlers_invoke(); |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
typedef gboolean RType; |
| 152 |
return RType(); |
| 153 |
} |
| 154 |
|
| 155 |
const Glib::SignalProxyInfo EntryCompletion_signal_match_selected_info = |
| 156 |
{ |
| 157 |
"match_selected", |
| 158 |
(GCallback) &Widget_signal_match_selected_callback, |
| 159 |
(GCallback) &Widget_signal_match_selected_notify_callback |
| 160 |
}; |
| 161 |
|
| 162 |
|
| 163 |
static gboolean Widget_signal_cursor_on_match_callback(GtkEntryCompletion* self, GtkTreeModel* c_model, GtkTreeIter* c_iter, void* data) |
| 164 |
{ |
| 165 |
using namespace Gtk; |
| 166 |
typedef sigc::slot< bool, const TreeModel::iterator& > SlotType; |
| 167 |
|
| 168 |
// Do not try to call a signal on a disassociated wrapper. |
| 169 |
if(Glib::ObjectBase::_get_current_wrapper((GObject*) self)) |
| 170 |
{ |
| 171 |
try |
| 172 |
{ |
| 173 |
if(sigc::slot_base *const slot = Glib::SignalProxyNormal::data_to_slot(data)) |
| 174 |
{ |
| 175 |
//This conversion is the custom-written part: |
| 176 |
Gtk::TreeModel::iterator cppIter(c_model, c_iter); |
| 177 |
|
| 178 |
return static_cast<int>( (*static_cast<SlotType*>(slot))(cppIter) ); |
| 179 |
} |
| 180 |
} |
| 181 |
catch(...) |
| 182 |
{ |
| 183 |
Glib::exception_handlers_invoke(); |
| 184 |
} |
| 185 |
} |
| 186 |
|
| 187 |
typedef gboolean RType; |
| 188 |
return RType(); |
| 189 |
} |
| 190 |
|
| 191 |
static gboolean Widget_signal_cursor_on_match_notify_callback(GtkEntryCompletion* self, GtkTreeModel* c_model, GtkTreeIter* c_iter, void* data) |
| 192 |
{ |
| 193 |
using namespace Gtk; |
| 194 |
typedef sigc::slot< void, const TreeModel::iterator& > SlotType; |
| 195 |
|
| 196 |
// Do not try to call a signal on a disassociated wrapper. |
| 197 |
if(Glib::ObjectBase::_get_current_wrapper((GObject*) self)) |
| 198 |
{ |
| 199 |
try |
| 200 |
{ |
| 201 |
if(sigc::slot_base *const slot = Glib::SignalProxyNormal::data_to_slot(data)) |
| 202 |
{ |
| 203 |
//This conversion is the custom-written part: |
| 204 |
Gtk::TreeModel::iterator cppIter(c_model, c_iter); |
| 205 |
|
| 206 |
(*static_cast<SlotType*>(slot))(cppIter); |
| 207 |
} |
| 208 |
} |
| 209 |
catch(...) |
| 210 |
{ |
| 211 |
Glib::exception_handlers_invoke(); |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
typedef gboolean RType; |
| 216 |
return RType(); |
| 217 |
} |
| 218 |
|
| 219 |
|
| 220 |
const Glib::SignalProxyInfo EntryCompletion_signal_cursor_on_match_info = |
| 221 |
{ |
| 222 |
"cursor_on_match", |
| 223 |
(GCallback) &Widget_signal_cursor_on_match_callback, |
| 224 |
(GCallback) &Widget_signal_cursor_on_match_notify_callback |
| 225 |
}; |
| 226 |
|
| 227 |
} //anonymous namespace |
| 228 |
|
| 229 |
|
| 230 |
namespace Gtk |
| 231 |
{ |
| 232 |
|
| 233 |
//Hand-coded signal wrapping: |
| 234 |
|
| 235 |
bool Gtk::EntryCompletion::on_match_selected(const TreeModel::iterator& iter) |
| 236 |
{ |
| 237 |
const auto base = static_cast<BaseClassType*>( |
| 238 |
g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class). |
| 239 |
); |
| 240 |
|
| 241 |
if(base && base->match_selected) |
| 242 |
return (*base->match_selected)(gobj(), iter.get_model_gobject(), const_cast<GtkTreeIter*>(iter.gobj())); |
| 243 |
else |
| 244 |
{ |
| 245 |
typedef bool RType; |
| 246 |
return RType(); //There should always be an implementation in the C object, so this will never happen. |
| 247 |
} |
| 248 |
} |
| 249 |
|
| 250 |
gboolean EntryCompletion_Class::match_selected_callback_custom(GtkEntryCompletion* self, GtkTreeModel* c_model, GtkTreeIter* c_iter) |
| 251 |
{ |
| 252 |
const auto obj = dynamic_cast<CppObjectType*>( |
| 253 |
Glib::ObjectBase::_get_current_wrapper((GObject*)self)); |
| 254 |
|
| 255 |
// Non-gtkmmproc-generated custom classes implicitly call the default |
| 256 |
// Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc- |
| 257 |
// generated classes can use this optimisation, which avoids the unnecessary |
| 258 |
// parameter conversions if there is no possibility of the virtual function |
| 259 |
// being overridden: |
| 260 |
if(obj && obj->is_derived_()) |
| 261 |
{ |
| 262 |
try // Trap C++ exceptions which would normally be lost because this is a C callback. |
| 263 |
{ |
| 264 |
// Call the virtual member method, which derived classes might override. |
| 265 |
|
| 266 |
//This conversion is the custom-written part: |
| 267 |
Gtk::TreeModel::iterator cppIter(c_model, c_iter); |
| 268 |
return obj->on_match_selected(cppIter); |
| 269 |
} |
| 270 |
catch(...) |
| 271 |
{ |
| 272 |
Glib::exception_handlers_invoke(); |
| 273 |
} |
| 274 |
} |
| 275 |
else |
| 276 |
{ |
| 277 |
const auto base = static_cast<BaseClassType*>( |
| 278 |
g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class). |
| 279 |
); |
| 280 |
|
| 281 |
// Call the original underlying C function: |
| 282 |
if(base && base->match_selected) |
| 283 |
return (*base->match_selected)(self, c_model, c_iter); |
| 284 |
} |
| 285 |
|
| 286 |
typedef gboolean RType; |
| 287 |
return RType(); |
| 288 |
} |
| 289 |
|
| 290 |
Glib::SignalProxy1< bool, const TreeModel::iterator& > EntryCompletion::signal_match_selected() |
| 291 |
{ |
| 292 |
return Glib::SignalProxy1< bool, const TreeModel::iterator& >(this, &EntryCompletion_signal_match_selected_info); |
| 293 |
} |
| 294 |
|
| 295 |
Glib::SignalProxy1< bool, const TreeModel::iterator& > EntryCompletion::signal_cursor_on_match() |
| 296 |
{ |
| 297 |
return Glib::SignalProxy1< bool, const TreeModel::iterator& >(this, &EntryCompletion_signal_cursor_on_match_info); |
| 298 |
} |
| 299 |
|
| 300 |
} // namespace Gtk |