| 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 <glibmm/vectorutils.h> |
| 18 |
|
| 19 |
#include <gdkmm/frameclock.h> |
| 20 |
#include <gtkmm/adjustment.h> |
| 21 |
#include <gtkmm/window.h> |
| 22 |
#include <gtkmm/accelgroup.h> |
| 23 |
#include <gtkmm/settings.h> |
| 24 |
#include <gtkmm/container.h> |
| 25 |
#include <gtkmm/selectiondata_private.h> |
| 26 |
#include <gtkmm/action.h> |
| 27 |
#include <gtkmm/tooltip.h> |
| 28 |
#include <gtk/gtk.h> //For gtk_widget_get_action(). |
| 29 |
|
| 30 |
|
| 31 |
namespace //anonymous |
| 32 |
{ |
| 33 |
|
| 34 |
// This signal callback is custom implemented, so that we can refrain from calling |
| 35 |
// the signal handler if the C++ wrapper is being deleted. |
| 36 |
// https://bugzilla.gnome.org/show_bug.cgi?id=605728#c5 |
| 37 |
void Widget_signal_hide_callback(GObject* self, void* data) |
| 38 |
{ |
| 39 |
const auto obj = Glib::ObjectBase::_get_current_wrapper(self); |
| 40 |
|
| 41 |
// Do not try to call a signal on a disassociated wrapper. |
| 42 |
// This function might be invoked recursively if the signal_hide() handler |
| 43 |
// deletes the object. |
| 44 |
// Therefore we have to test for cpp_destruction_in_progress_ at this point. |
| 45 |
if(obj && !obj->_cpp_destruction_is_in_progress()) |
| 46 |
{ |
| 47 |
try |
| 48 |
{ |
| 49 |
if(sigc::slot_base *const slot = Glib::SignalProxyNormal::data_to_slot(data)) |
| 50 |
(*static_cast<sigc::slot<void>*>(slot))(); |
| 51 |
} |
| 52 |
catch(...) |
| 53 |
{ |
| 54 |
Glib::exception_handlers_invoke(); |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
//These signal callbacks are custom implemented, so that we can create a temporary SelectionData instance. |
| 60 |
//To do this, we used the optional custom_c_callback paramater to _WRAP_SIGNAL() in the .hg file. |
| 61 |
static void Widget_signal_drag_data_get_callback(GtkWidget* self, GdkDragContext* p0,GtkSelectionData* p1,guint p2,guint p3,void* data) |
| 62 |
{ |
| 63 |
using namespace Gtk; |
| 64 |
typedef sigc::slot< void,const Glib::RefPtr<Gdk::DragContext>&,SelectionData&,guint,guint > SlotType; |
| 65 |
|
| 66 |
// Do not try to call a signal on a disassociated wrapper. |
| 67 |
if(Glib::ObjectBase::_get_current_wrapper((GObject*) self)) |
| 68 |
{ |
| 69 |
try |
| 70 |
{ |
| 71 |
if(sigc::slot_base *const slot = Glib::SignalProxyNormal::data_to_slot(data)) |
| 72 |
{ |
| 73 |
SelectionData_WithoutOwnership temp_instance(p1); |
| 74 |
(*static_cast<SlotType*>(slot))( Glib::wrap(p0, true), temp_instance, p2, p3 ); |
| 75 |
} |
| 76 |
} |
| 77 |
catch(...) |
| 78 |
{ |
| 79 |
Glib::exception_handlers_invoke(); |
| 80 |
} |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
static void Widget_signal_selection_get_callback(GtkWidget* self, GtkSelectionData* p0,guint p1,guint p2,void* data) |
| 85 |
{ |
| 86 |
using namespace Gtk; |
| 87 |
typedef sigc::slot< void, SelectionData&, guint, guint > SlotType; |
| 88 |
|
| 89 |
// Do not try to call a signal on a disassociated wrapper. |
| 90 |
if(Glib::ObjectBase::_get_current_wrapper((GObject*) self)) |
| 91 |
{ |
| 92 |
try |
| 93 |
{ |
| 94 |
if(sigc::slot_base *const slot = Glib::SignalProxyNormal::data_to_slot(data)) |
| 95 |
{ |
| 96 |
SelectionData_WithoutOwnership temp_instance(p0); |
| 97 |
(*static_cast<SlotType*>(slot))( temp_instance, p1, p2 ); |
| 98 |
} |
| 99 |
} |
| 100 |
catch(...) |
| 101 |
{ |
| 102 |
Glib::exception_handlers_invoke(); |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
gboolean SlotTick_gtk_callback(GtkWidget* self, GdkFrameClock* frame_clock, void* data) |
| 108 |
{ |
| 109 |
// Do not try to call a signal on a disassociated wrapper. |
| 110 |
if (Glib::ObjectBase::_get_current_wrapper((GObject*)self)) |
| 111 |
{ |
| 112 |
auto the_slot = static_cast<Gtk::Widget::SlotTick*>(data); |
| 113 |
try |
| 114 |
{ |
| 115 |
return (*the_slot)(Glib::wrap(frame_clock, true)); |
| 116 |
} |
| 117 |
catch (...) |
| 118 |
{ |
| 119 |
Glib::exception_handlers_invoke(); |
| 120 |
} |
| 121 |
} |
| 122 |
return false; |
| 123 |
} |
| 124 |
|
| 125 |
} //anonymous |
| 126 |
|
| 127 |
namespace Gtk |
| 128 |
{ |
| 129 |
|
| 130 |
// This default handler callback is custom implemented, so that we can refrain |
| 131 |
// from calling an on_hide() override, if the C++ wrapper is being deleted. |
| 132 |
void Widget_Class::hide_callback(GtkWidget* self) |
| 133 |
{ |
| 134 |
const auto obj_base = static_cast<Glib::ObjectBase*>( |
| 135 |
Glib::ObjectBase::_get_current_wrapper((GObject*)self)); |
| 136 |
|
| 137 |
// Non-gtkmmproc-generated custom classes implicitly call the default |
| 138 |
// Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc- |
| 139 |
// generated classes can use this optimisation, which avoids the unnecessary |
| 140 |
// parameter conversions if there is no possibility of the virtual function |
| 141 |
// being overridden: |
| 142 |
// This function might be invoked recursively if an on_hide() override |
| 143 |
// deletes the object. |
| 144 |
// Therefore we test for cpp_destruction_in_progress_ at this point. |
| 145 |
// (Not sure if it's necessary, but it feels safer. Perhaps the following |
| 146 |
// dynamic_cast catches all dangerous cases. /Kjell Ahlstedt) |
| 147 |
if(obj_base && obj_base->is_derived_() && !obj_base->_cpp_destruction_is_in_progress()) |
| 148 |
{ |
| 149 |
const auto obj = dynamic_cast<CppObjectType* const>(obj_base); |
| 150 |
if(obj) // This can be NULL during destruction. |
| 151 |
{ |
| 152 |
try // Trap C++ exceptions which would normally be lost because this is a C callback. |
| 153 |
{ |
| 154 |
// Call the virtual member method, which derived classes might override. |
| 155 |
obj->on_hide(); |
| 156 |
return; |
| 157 |
} |
| 158 |
catch(...) |
| 159 |
{ |
| 160 |
Glib::exception_handlers_invoke(); |
| 161 |
} |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
const auto base = static_cast<BaseClassType*>( |
| 166 |
g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class). |
| 167 |
); |
| 168 |
|
| 169 |
// Call the original underlying C function: |
| 170 |
if(base && base->hide) |
| 171 |
(*base->hide)(self); |
| 172 |
} |
| 173 |
|
| 174 |
//These default handler callbacks are custom implemented, so that we can create a temporary SelectionData instance. |
| 175 |
//To do this, we used the optional custom_c_callback paramater to _WRAP_SIGNAL() in the .hg file. |
| 176 |
void Widget_Class::selection_get_callback(GtkWidget* self, GtkSelectionData* p0, guint p1, guint p2) |
| 177 |
{ |
| 178 |
const auto obj = dynamic_cast<CppObjectType*>( |
| 179 |
Glib::ObjectBase::_get_current_wrapper((GObject*)self)); |
| 180 |
|
| 181 |
// Non-gtkmmproc-generated custom classes implicitly call the default |
| 182 |
// Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc- |
| 183 |
// generated classes can use this optimisation, which avoids the unnecessary |
| 184 |
// parameter conversions if there is no possibility of the virtual function |
| 185 |
// being overridden: |
| 186 |
if(obj && obj->is_derived_()) |
| 187 |
{ |
| 188 |
try // Trap C++ exceptions which would normally be lost because this is a C callback. |
| 189 |
{ |
| 190 |
// Call the virtual member method, which derived classes might override. |
| 191 |
SelectionData_WithoutOwnership temp_instance(p0); |
| 192 |
obj->on_selection_get(temp_instance, p1, p2); |
| 193 |
} |
| 194 |
catch(...) |
| 195 |
{ |
| 196 |
Glib::exception_handlers_invoke(); |
| 197 |
} |
| 198 |
} |
| 199 |
else |
| 200 |
{ |
| 201 |
const auto base = static_cast<BaseClassType*>( |
| 202 |
g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class). |
| 203 |
); |
| 204 |
|
| 205 |
// Call the original underlying C function: |
| 206 |
if(base && base->selection_get) |
| 207 |
(*base->selection_get)(self, p0, p1, p2); |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
void Widget_Class::drag_data_get_callback(GtkWidget* self, GdkDragContext* p0, GtkSelectionData* p1, guint p2, guint p3) |
| 212 |
{ |
| 213 |
const auto obj = dynamic_cast<CppObjectType*>( |
| 214 |
Glib::ObjectBase::_get_current_wrapper((GObject*)self)); |
| 215 |
|
| 216 |
// Non-gtkmmproc-generated custom classes implicitly call the default |
| 217 |
// Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc- |
| 218 |
// generated classes can use this optimisation, which avoids the unnecessary |
| 219 |
// parameter conversions if there is no possibility of the virtual function |
| 220 |
// being overridden: |
| 221 |
if(obj && obj->is_derived_()) |
| 222 |
{ |
| 223 |
try // Trap C++ exceptions which would normally be lost because this is a C callback. |
| 224 |
{ |
| 225 |
// Call the virtual member method, which derived classes might override. |
| 226 |
SelectionData_WithoutOwnership temp_instance(p1); |
| 227 |
obj->on_drag_data_get(Glib::wrap(p0, true), temp_instance, p2, p3); |
| 228 |
} |
| 229 |
catch(...) |
| 230 |
{ |
| 231 |
Glib::exception_handlers_invoke(); |
| 232 |
} |
| 233 |
} |
| 234 |
else |
| 235 |
{ |
| 236 |
const auto base = static_cast<BaseClassType*>( |
| 237 |
g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class). |
| 238 |
); |
| 239 |
|
| 240 |
// Call the original underlying C function: |
| 241 |
if(base && base->drag_data_get) |
| 242 |
(*base->drag_data_get)(self, p0, p1, p2, p3); |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
//These vfunc callbacks are custom implemented because we want the output |
| 247 |
//arguments of the C++ vfuncs to be int& (not int*), and the vfunc_callback |
| 248 |
//functions may be called from gtk+ with a NULL pointer. |
| 249 |
void Widget_Class::get_preferred_width_vfunc_callback(GtkWidget* self, gint* minimum_width, gint* natural_width) |
| 250 |
{ |
| 251 |
const auto obj_base = static_cast<Glib::ObjectBase*>( |
| 252 |
Glib::ObjectBase::_get_current_wrapper((GObject*)self)); |
| 253 |
|
| 254 |
// Non-gtkmmproc-generated custom classes implicitly call the default |
| 255 |
// Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc- |
| 256 |
// generated classes can use this optimisation, which avoids the unnecessary |
| 257 |
// parameter conversions if there is no possibility of the virtual function |
| 258 |
// being overridden: |
| 259 |
if(obj_base && obj_base->is_derived_()) |
| 260 |
{ |
| 261 |
const auto obj = dynamic_cast<CppObjectType* const>(obj_base); |
| 262 |
if(obj) // This can be NULL during destruction. |
| 263 |
{ |
| 264 |
try // Trap C++ exceptions which would normally be lost because this is a C callback. |
| 265 |
{ |
| 266 |
// Call the virtual member method, which derived classes might override. |
| 267 |
int min_width = 0; |
| 268 |
int nat_width = 0; |
| 269 |
obj->get_preferred_width_vfunc( |
| 270 |
(minimum_width ? *minimum_width : min_width), |
| 271 |
(natural_width ? *natural_width : nat_width)); |
| 272 |
return; |
| 273 |
} |
| 274 |
catch(...) |
| 275 |
{ |
| 276 |
Glib::exception_handlers_invoke(); |
| 277 |
} |
| 278 |
} |
| 279 |
} |
| 280 |
|
| 281 |
const auto base = static_cast<BaseClassType*>( |
| 282 |
g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class). |
| 283 |
); |
| 284 |
|
| 285 |
// Call the original underlying C function: |
| 286 |
if(base && base->get_preferred_width) |
| 287 |
(*base->get_preferred_width)(self, minimum_width, natural_width); |
| 288 |
} |
| 289 |
|
| 290 |
void Widget_Class::get_preferred_height_for_width_vfunc_callback(GtkWidget* self, gint width, gint* minimum_height, gint* natural_height) |
| 291 |
{ |
| 292 |
const auto obj_base = static_cast<Glib::ObjectBase*>( |
| 293 |
Glib::ObjectBase::_get_current_wrapper((GObject*)self)); |
| 294 |
|
| 295 |
// Non-gtkmmproc-generated custom classes implicitly call the default |
| 296 |
// Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc- |
| 297 |
// generated classes can use this optimisation, which avoids the unnecessary |
| 298 |
// parameter conversions if there is no possibility of the virtual function |
| 299 |
// being overridden: |
| 300 |
if(obj_base && obj_base->is_derived_()) |
| 301 |
{ |
| 302 |
const auto obj = dynamic_cast<CppObjectType* const>(obj_base); |
| 303 |
if(obj) // This can be NULL during destruction. |
| 304 |
{ |
| 305 |
try // Trap C++ exceptions which would normally be lost because this is a C callback. |
| 306 |
{ |
| 307 |
// Call the virtual member method, which derived classes might override. |
| 308 |
int min_height = 0; |
| 309 |
int nat_height = 0; |
| 310 |
obj->get_preferred_height_for_width_vfunc(width, |
| 311 |
(minimum_height ? *minimum_height : min_height), |
| 312 |
(natural_height ? *natural_height : nat_height)); |
| 313 |
return; |
| 314 |
} |
| 315 |
catch(...) |
| 316 |
{ |
| 317 |
Glib::exception_handlers_invoke(); |
| 318 |
} |
| 319 |
} |
| 320 |
} |
| 321 |
|
| 322 |
const auto base = static_cast<BaseClassType*>( |
| 323 |
g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class). |
| 324 |
); |
| 325 |
|
| 326 |
// Call the original underlying C function: |
| 327 |
if(base && base->get_preferred_height_for_width) |
| 328 |
(*base->get_preferred_height_for_width)(self, width, minimum_height, natural_height); |
| 329 |
} |
| 330 |
|
| 331 |
void Widget_Class::get_preferred_height_vfunc_callback(GtkWidget* self, gint* minimum_height, gint* natural_height) |
| 332 |
{ |
| 333 |
const auto obj_base = static_cast<Glib::ObjectBase*>( |
| 334 |
Glib::ObjectBase::_get_current_wrapper((GObject*)self)); |
| 335 |
|
| 336 |
// Non-gtkmmproc-generated custom classes implicitly call the default |
| 337 |
// Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc- |
| 338 |
// generated classes can use this optimisation, which avoids the unnecessary |
| 339 |
// parameter conversions if there is no possibility of the virtual function |
| 340 |
// being overridden: |
| 341 |
if(obj_base && obj_base->is_derived_()) |
| 342 |
{ |
| 343 |
const auto obj = dynamic_cast<CppObjectType* const>(obj_base); |
| 344 |
if(obj) // This can be NULL during destruction. |
| 345 |
{ |
| 346 |
try // Trap C++ exceptions which would normally be lost because this is a C callback. |
| 347 |
{ |
| 348 |
// Call the virtual member method, which derived classes might override. |
| 349 |
int min_height = 0; |
| 350 |
int nat_height = 0; |
| 351 |
obj->get_preferred_height_vfunc( |
| 352 |
(minimum_height ? *minimum_height : min_height), |
| 353 |
(natural_height ? *natural_height : nat_height)); |
| 354 |
return; |
| 355 |
} |
| 356 |
catch(...) |
| 357 |
{ |
| 358 |
Glib::exception_handlers_invoke(); |
| 359 |
} |
| 360 |
} |
| 361 |
} |
| 362 |
|
| 363 |
const auto base = static_cast<BaseClassType*>( |
| 364 |
g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class). |
| 365 |
); |
| 366 |
|
| 367 |
// Call the original underlying C function: |
| 368 |
if(base && base->get_preferred_height) |
| 369 |
(*base->get_preferred_height)(self, minimum_height, natural_height); |
| 370 |
} |
| 371 |
|
| 372 |
void Widget_Class::get_preferred_width_for_height_vfunc_callback(GtkWidget* self, gint height, gint* minimum_width, gint* natural_width) |
| 373 |
{ |
| 374 |
const auto obj_base = static_cast<Glib::ObjectBase*>( |
| 375 |
Glib::ObjectBase::_get_current_wrapper((GObject*)self)); |
| 376 |
|
| 377 |
// Non-gtkmmproc-generated custom classes implicitly call the default |
| 378 |
// Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc- |
| 379 |
// generated classes can use this optimisation, which avoids the unnecessary |
| 380 |
// parameter conversions if there is no possibility of the virtual function |
| 381 |
// being overridden: |
| 382 |
if(obj_base && obj_base->is_derived_()) |
| 383 |
{ |
| 384 |
const auto obj = dynamic_cast<CppObjectType* const>(obj_base); |
| 385 |
if(obj) // This can be NULL during destruction. |
| 386 |
{ |
| 387 |
try // Trap C++ exceptions which would normally be lost because this is a C callback. |
| 388 |
{ |
| 389 |
// Call the virtual member method, which derived classes might override. |
| 390 |
int min_width = 0; |
| 391 |
int nat_width = 0; |
| 392 |
obj->get_preferred_width_for_height_vfunc(height, |
| 393 |
(minimum_width ? *minimum_width : min_width), |
| 394 |
(natural_width ? *natural_width : nat_width)); |
| 395 |
return; |
| 396 |
} |
| 397 |
catch(...) |
| 398 |
{ |
| 399 |
Glib::exception_handlers_invoke(); |
| 400 |
} |
| 401 |
} |
| 402 |
} |
| 403 |
|
| 404 |
const auto base = static_cast<BaseClassType*>( |
| 405 |
g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class). |
| 406 |
); |
| 407 |
|
| 408 |
// Call the original underlying C function: |
| 409 |
if(base && base->get_preferred_width_for_height) |
| 410 |
(*base->get_preferred_width_for_height)(self, height, minimum_width, natural_width); |
| 411 |
} |
| 412 |
|
| 413 |
Widget::~Widget() noexcept |
| 414 |
{} |
| 415 |
|
| 416 |
void Widget::reparent(Widget& new_parent) |
| 417 |
{ |
| 418 |
//TODO: When 'Widget& new_parent' is changed to 'Container& new_parent', |
| 419 |
// remove the next two statements. |
| 420 |
auto new_container = dynamic_cast<Container*>(&new_parent); |
| 421 |
g_return_if_fail(new_container != nullptr); // if new_parent is not a Container |
| 422 |
auto old_container = get_parent(); |
| 423 |
g_return_if_fail(old_container != nullptr); // if the widget is not in a Container |
| 424 |
|
| 425 |
if (old_container != new_container) |
| 426 |
{ |
| 427 |
reference(); |
| 428 |
old_container->remove(*this); |
| 429 |
new_container->add(*this); |
| 430 |
unreference(); |
| 431 |
} |
| 432 |
} |
| 433 |
|
| 434 |
bool Widget::intersect(const Gdk::Rectangle& area) const |
| 435 |
{ |
| 436 |
return gtk_widget_intersect( |
| 437 |
const_cast<GtkWidget*>(gobj()), const_cast<GdkRectangle*>(area.gobj()), nullptr); |
| 438 |
} |
| 439 |
|
| 440 |
void Widget::unset_name() |
| 441 |
{ |
| 442 |
gtk_widget_set_name(gobj(), nullptr); |
| 443 |
} |
| 444 |
|
| 445 |
#ifndef GTKMM_DISABLE_DEPRECATED |
| 446 |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
| 447 |
void Widget::unset_composite_name() |
| 448 |
{ |
| 449 |
gtk_widget_set_composite_name(gobj(), nullptr); |
| 450 |
} |
| 451 |
G_GNUC_END_IGNORE_DEPRECATIONS |
| 452 |
#endif // GTKMM_DISABLE_DEPRECATED |
| 453 |
|
| 454 |
void Widget::realize_if_needed() |
| 455 |
{ |
| 456 |
if(!get_realized()) |
| 457 |
realize(); |
| 458 |
} |
| 459 |
|
| 460 |
void Widget::add_modal_grab() |
| 461 |
{ |
| 462 |
gtk_grab_add(gobj()); |
| 463 |
} |
| 464 |
|
| 465 |
void Widget::remove_modal_grab() |
| 466 |
{ |
| 467 |
gtk_grab_remove(gobj()); |
| 468 |
} |
| 469 |
|
| 470 |
Widget* Widget::get_current_modal_grab() |
| 471 |
{ |
| 472 |
return Glib::wrap(gtk_grab_get_current()); |
| 473 |
} |
| 474 |
|
| 475 |
void Widget::set_window(const Glib::RefPtr<Gdk::Window>& window) |
| 476 |
{ |
| 477 |
gtk_widget_set_window(gobj(), Glib::unwrap(window)); |
| 478 |
if (window) |
| 479 |
window->reference(); // gtk_widget_set_window does not add a ref. |
| 480 |
} |
| 481 |
|
| 482 |
Allocation Widget::get_clip() const |
| 483 |
{ |
| 484 |
Allocation allocation; |
| 485 |
gtk_widget_get_clip(const_cast<GtkWidget*>(gobj()), allocation.gobj()); |
| 486 |
return allocation; |
| 487 |
} |
| 488 |
|
| 489 |
|
| 490 |
Allocation Widget::get_allocation() const |
| 491 |
{ |
| 492 |
Allocation allocation; |
| 493 |
gtk_widget_get_allocation(const_cast<GtkWidget*>(gobj()), allocation.gobj()); |
| 494 |
return allocation; |
| 495 |
} |
| 496 |
|
| 497 |
int Widget::get_width() const |
| 498 |
{ return get_allocation().get_width(); } |
| 499 |
|
| 500 |
int Widget::get_height() const |
| 501 |
{ return get_allocation().get_height(); } |
| 502 |
|
| 503 |
|
| 504 |
void Widget::drag_dest_set(DestDefaults flags, Gdk::DragAction actions) |
| 505 |
{ |
| 506 |
gtk_drag_dest_set(gobj(), (GtkDestDefaults)flags, nullptr, 0, (GdkDragAction)actions); |
| 507 |
} |
| 508 |
|
| 509 |
void Widget::drag_dest_set(const std::vector<TargetEntry>& targets, |
| 510 |
DestDefaults flags, Gdk::DragAction actions) |
| 511 |
{ |
| 512 |
// I've used Gdk::ACTION_COPY as the default, because Gdk::ACTION_DEFAULT means that |
| 513 |
// it's never a drag destination, so it would seem like this method didn't work. murrayc. |
| 514 |
gtk_drag_dest_set( |
| 515 |
gobj(), (GtkDestDefaults)flags, |
| 516 |
Glib::ArrayHandler<TargetEntry, TargetEntryTraits>::vector_to_array(targets).data(), |
| 517 |
targets.size(), (GdkDragAction)actions); |
| 518 |
} |
| 519 |
|
| 520 |
void Widget::drag_source_set(const std::vector<TargetEntry>& targets, |
| 521 |
Gdk::ModifierType start_button_mask, Gdk::DragAction actions) |
| 522 |
{ |
| 523 |
// I've used Gdk::MODIFIER_MASK as the default, because it seems |
| 524 |
// to mean 'whatever is possible in the context'. murrayc. |
| 525 |
gtk_drag_source_set( |
| 526 |
gobj(), (GdkModifierType)start_button_mask, |
| 527 |
Glib::ArrayHandler<TargetEntry, TargetEntryTraits>::vector_to_array(targets).data(), |
| 528 |
targets.size(), (GdkDragAction)actions); |
| 529 |
} |
| 530 |
|
| 531 |
Widget* Widget::drag_get_source_widget(const Glib::RefPtr<Gdk::DragContext>& context) //static |
| 532 |
{ |
| 533 |
return Glib::wrap( gtk_drag_get_source_widget(Glib::unwrap(context)) ); |
| 534 |
} |
| 535 |
|
| 536 |
void Widget::drag_set_as_icon(const Glib::RefPtr<Gdk::DragContext>& context, int hot_x, int hot_y) |
| 537 |
{ |
| 538 |
gtk_drag_set_icon_widget(Glib::unwrap(context), gobj(), hot_x, hot_y); |
| 539 |
} |
| 540 |
|
| 541 |
void Widget_Class::hierarchy_changed_callback_custom(GtkWidget* self, GtkWidget* p0) |
| 542 |
{ |
| 543 |
//GTKMM_LIFECYCLE |
| 544 |
//Don't call wrap() on a GTK+ instance whose gtkmm instance has been deleted - just call the original C callback. |
| 545 |
bool gtkmm_child_already_deleted = Glib::_gobject_cppinstance_already_deleted((GObject*)p0); |
| 546 |
|
| 547 |
if(!gtkmm_child_already_deleted) |
| 548 |
{ |
| 549 |
//Call the regular, generated callback: |
| 550 |
Widget_Class::hierarchy_changed_callback(self, p0); |
| 551 |
} |
| 552 |
else |
| 553 |
{ |
| 554 |
const auto base = static_cast<BaseClassType*>( |
| 555 |
g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class). |
| 556 |
); |
| 557 |
|
| 558 |
//Call the original underlying C function: |
| 559 |
if(base && base->hierarchy_changed) |
| 560 |
(*base->hierarchy_changed)(self, p0); |
| 561 |
} |
| 562 |
} |
| 563 |
|
| 564 |
void Widget_Class::parent_set_callback_custom(GtkWidget* self, GtkWidget* p0) |
| 565 |
{ |
| 566 |
//GTKMM_LIFECYCLE |
| 567 |
//Don't call wrap() on a GTK+ instance whose gtkmm instance has been deleted - just call the original C callback. |
| 568 |
bool gtkmm_p0_already_deleted = Glib::_gobject_cppinstance_already_deleted((GObject*)p0); |
| 569 |
|
| 570 |
if(!gtkmm_p0_already_deleted) |
| 571 |
{ |
| 572 |
//Call the regular, generated callback: |
| 573 |
Widget_Class::parent_set_callback(self, p0); |
| 574 |
} |
| 575 |
else |
| 576 |
{ |
| 577 |
const auto base = static_cast<BaseClassType*>( |
| 578 |
g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class). |
| 579 |
); |
| 580 |
|
| 581 |
//Call the original underlying C function: |
| 582 |
if(base && base->parent_set) |
| 583 |
(*base->parent_set)(self, p0); |
| 584 |
} |
| 585 |
} |
| 586 |
|
| 587 |
void Widget_Class::dispose_vfunc_callback(GObject* self) |
| 588 |
{ |
| 589 |
//Avoid disposal. See also Window_Class::dispose_vfunc_callback(). |
| 590 |
|
| 591 |
#ifdef GLIBMM_DEBUG_REFCOUNTING |
| 592 |
g_warning("Widget_Class::dispose_vfunc_callback(): gobject_: %p\n", (void*)self); |
| 593 |
//if(self) |
| 594 |
//g_warning(" gtypename: %s\n", G_OBJECT_TYPE_NAME(self)); |
| 595 |
#endif |
| 596 |
|
| 597 |
const auto obj = dynamic_cast<Widget*>( |
| 598 |
Glib::ObjectBase::_get_current_wrapper(self)); |
| 599 |
|
| 600 |
// This function might be invoked recursively because we're triggering |
| 601 |
// several signal emissions, particularly signal_hide(). Therefore we |
| 602 |
// have to test for cpp_destruction_in_progress_ at this point. |
| 603 |
|
| 604 |
if(obj && !obj->_cpp_destruction_is_in_progress()) //When it should really be destroyed, we zero gobj_. |
| 605 |
{ |
| 606 |
const auto pWidget = obj->gobj(); |
| 607 |
g_return_if_fail(pWidget == GTK_WIDGET(self)); |
| 608 |
|
| 609 |
// Abort dispose if the widget isn't managed, in order to prevent |
| 610 |
// the nasty self-destroying behaviour of GTK+. This applies to |
| 611 |
// any widget inside a GtkContainer on gtk_container_destroy() |
| 612 |
// See also Window_Class::dispose_vfunc_callback(). |
| 613 |
|
| 614 |
if(obj->referenced_) //Not managed |
| 615 |
{ |
| 616 |
// GTKMM_LIFECYCLE |
| 617 |
// Remove the widget from its parent container so that it |
| 618 |
// won't be destroyed later by gtk_container_destroy(). |
| 619 |
GtkWidget* parent = gtk_widget_get_parent(pWidget); |
| 620 |
if(parent) |
| 621 |
{ |
| 622 |
// Normally, we would have to ref the child widget because |
| 623 |
// gtk_container_remove() unrefs it. But since we only remove |
| 624 |
// non-managed objects here, the container just releases the |
| 625 |
// reference it has acquired before in gtk_container_add(). |
| 626 |
|
| 627 |
#ifdef GLIBMM_DEBUG_REFCOUNTING |
| 628 |
g_warning("Widget_Class::dispose_vfunc_callback(): removing gobject_: %p from parent: %p", (void*)self, (void*)parent); |
| 629 |
#endif |
| 630 |
|
| 631 |
gtk_container_remove(GTK_CONTAINER(parent), pWidget); |
| 632 |
|
| 633 |
#ifdef GLIBMM_DEBUG_REFCOUNTING |
| 634 |
g_warning("Widget_Class::dispose_vfunc_callback(): after removing from parent."); |
| 635 |
#endif |
| 636 |
} |
| 637 |
// Special case for GtkMenu because gtk_menu_attach_to_widget does |
| 638 |
// not set widget->parent but gtk_menu_item_destroy() destroys the menu |
| 639 |
// like gtk_container_destroy() |
| 640 |
// Gtk::Menu does not use a parent widget because it must |
| 641 |
// be contained in its Gtk::Window so that it can be displayed as a popup. |
| 642 |
else if (GTK_IS_MENU(pWidget) && GTK_IS_MENU_ITEM(gtk_menu_get_attach_widget(GTK_MENU(pWidget)))) |
| 643 |
{ |
| 644 |
gtk_menu_detach(GTK_MENU(pWidget)); |
| 645 |
} |
| 646 |
|
| 647 |
#ifdef GLIBMM_DEBUG_REFCOUNTING |
| 648 |
g_warning("Widget_Class::dispose_vfunc_callback(): before gtk_widget_hide()."); |
| 649 |
#endif |
| 650 |
|
| 651 |
// Now hide the widget. The C++ object must _not_ be accessed anymore |
| 652 |
// after this call, because a signal_hide() handler might delete it. |
| 653 |
gtk_widget_hide(pWidget); |
| 654 |
|
| 655 |
#ifdef GLIBMM_DEBUG_REFCOUNTING |
| 656 |
g_warning("Widget_Class::dispose_vfunc_callback(): after gtk_widget_hide()."); |
| 657 |
#endif |
| 658 |
|
| 659 |
// GTKMM_LIFECYCLE |
| 660 |
return; // Prevent calling of normal C dispose vfunc (see below) |
| 661 |
} |
| 662 |
|
| 663 |
#ifdef GLIBMM_DEBUG_REFCOUNTING |
| 664 |
g_warning("Widget_Class::dispose_vfunc_callback(): unreferenced: before gtk_widget_hide()."); |
| 665 |
#endif |
| 666 |
|
| 667 |
// Always hide widgets on object destruction, regardless of whether |
| 668 |
// the widget is managed or not. This is done for consistency so that |
| 669 |
// connecting to signal_hide() is guaranteed to work. |
| 670 |
gtk_widget_hide(pWidget); |
| 671 |
|
| 672 |
#ifdef GLIBMM_DEBUG_REFCOUNTING |
| 673 |
g_warning("Widget_Class::dispose_vfunc_callback(): unreferenced: after gtk_widget_hide()."); |
| 674 |
#endif |
| 675 |
} |
| 676 |
|
| 677 |
const auto base = static_cast<GObjectClass*>( |
| 678 |
g_type_class_peek_parent(G_OBJECT_GET_CLASS(self))); |
| 679 |
|
| 680 |
#ifdef GLIBMM_DEBUG_REFCOUNTING |
| 681 |
g_warning("Widget_Class::dispose_vfunc_callback(): before calling base->dispose."); |
| 682 |
#endif |
| 683 |
|
| 684 |
if(base->dispose) |
| 685 |
(*base->dispose)(self); |
| 686 |
|
| 687 |
#ifdef GLIBMM_DEBUG_REFCOUNTING |
| 688 |
g_warning("Widget_Class::dispose_vfunc_callback(): after calling base->dispose."); |
| 689 |
#endif |
| 690 |
} |
| 691 |
|
| 692 |
Glib::ustring Widget::drag_dest_find_target(const Glib::RefPtr<Gdk::DragContext>& context) const |
| 693 |
{ |
| 694 |
return Gdk::AtomUstring::to_cpp_type(gtk_drag_dest_find_target(const_cast<GtkWidget*>(gobj()), Glib::unwrap(context), nullptr /* See GTK+ docs */)); |
| 695 |
} |
| 696 |
|
| 697 |
#ifndef GTKMM_DISABLE_DEPRECATED |
| 698 |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
| 699 |
void Widget::draw_insertion_cursor(const Cairo::RefPtr<Cairo::Context>& cr, const Gdk::Rectangle& location, bool is_primary, TextDirection direction, bool draw_arrow) |
| 700 |
{ |
| 701 |
gtk_draw_insertion_cursor(gobj(), cr->cobj(), const_cast<GdkRectangle*>(location.gobj()), is_primary, (GtkTextDirection)direction, draw_arrow); |
| 702 |
} |
| 703 |
G_GNUC_END_IGNORE_DEPRECATIONS |
| 704 |
#endif // GTKMM_DISABLE_DEPRECATED |
| 705 |
|
| 706 |
#ifndef GTKMM_DISABLE_DEPRECATED |
| 707 |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
| 708 |
Requisition Widget::get_requisition() const |
| 709 |
{ |
| 710 |
Requisition result = {0, 0}; |
| 711 |
gtk_widget_get_requisition(const_cast<GtkWidget*>(gobj()), &result); |
| 712 |
return result; |
| 713 |
} |
| 714 |
G_GNUC_END_IGNORE_DEPRECATIONS |
| 715 |
#endif // GTKMM_DISABLE_DEPRECATED |
| 716 |
|
| 717 |
_DEPRECATE_IFDEF_START |
| 718 |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
| 719 |
void Widget::unset_color(StateFlags state) |
| 720 |
{ |
| 721 |
gtk_widget_override_color(gobj(), ((GtkStateFlags)(state)), nullptr); |
| 722 |
} |
| 723 |
|
| 724 |
void Widget::unset_background_color(StateFlags state) |
| 725 |
{ |
| 726 |
gtk_widget_override_background_color(gobj(), ((GtkStateFlags)(state)), nullptr); |
| 727 |
} |
| 728 |
|
| 729 |
void Widget::unset_font() |
| 730 |
{ |
| 731 |
gtk_widget_override_font(gobj(), nullptr); |
| 732 |
} |
| 733 |
|
| 734 |
void Widget::unset_symbolic_color(const Glib::ustring& name) |
| 735 |
{ |
| 736 |
gtk_widget_override_symbolic_color(gobj(), name.c_str(), nullptr); |
| 737 |
} |
| 738 |
|
| 739 |
void Widget::unset_cursor() |
| 740 |
{ |
| 741 |
gtk_widget_override_cursor(gobj(), nullptr, nullptr); |
| 742 |
} |
| 743 |
G_GNUC_END_IGNORE_DEPRECATIONS |
| 744 |
_DEPRECATE_IFDEF_END |
| 745 |
|
| 746 |
void Widget::unset_font_options() |
| 747 |
{ |
| 748 |
gtk_widget_set_font_options(gobj(), nullptr); |
| 749 |
} |
| 750 |
|
| 751 |
void Widget::transform_cairo_context_to_window(const Cairo::RefPtr<Cairo::Context>& cr, const Glib::RefPtr<const Gdk::Window>& window) |
| 752 |
{ |
| 753 |
gtk_cairo_transform_to_window((cr)->cobj(), gobj(), const_cast<GdkWindow*>(Glib::unwrap<Gdk::Window>(window))); |
| 754 |
} |
| 755 |
|
| 756 |
void Widget::remove_action_group(const Glib::ustring& name) |
| 757 |
{ |
| 758 |
gtk_widget_insert_action_group(gobj(), name.c_str(), nullptr /* see C docs */); |
| 759 |
} |
| 760 |
|
| 761 |
guint Widget::add_tick_callback(const SlotTick& slot) |
| 762 |
{ |
| 763 |
// Create a copy of the slot object. A pointer to this will be passed |
| 764 |
// through the callback's data parameter. It will be deleted |
| 765 |
// when Glib::destroy_notify_delete<SlotTick>() is called. |
| 766 |
auto slot_copy = new SlotTick(slot); |
| 767 |
|
| 768 |
return gtk_widget_add_tick_callback(gobj(), &SlotTick_gtk_callback, slot_copy, |
| 769 |
&Glib::destroy_notify_delete<SlotTick>); |
| 770 |
} |
| 771 |
|
| 772 |
} // namespace Gtk |