[gtkmm-documentation] Adapt to latest version of Gdk::Event and its subclasses



commit 131f25f9646560704bc9b2ff720934753c5ae4d8
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Fri Oct 6 19:02:29 2017 +0200

    Adapt to latest version of Gdk::Event and its subclasses
    
    Gdk::Event and its subclasses have been modified because GdkEvent and
    its subclasses are now opaque structs, accessible only via gtk+ functions.

 examples/book/popover/examplewindow.cc             |   25 +++++++++++--------
 .../others/cellrenderercustom/cellrendererpopup.cc |    6 ++--
 examples/others/cellrenderercustom/popupentry.cc   |    8 +++++-
 3 files changed, 24 insertions(+), 15 deletions(-)
---
diff --git a/examples/book/popover/examplewindow.cc b/examples/book/popover/examplewindow.cc
index 2b2acb2..d7cbdb7 100644
--- a/examples/book/popover/examplewindow.cc
+++ b/examples/book/popover/examplewindow.cc
@@ -141,21 +141,26 @@ void ExampleWindow::configure_cal_popover()
 
 void ExampleWindow::on_day_selected()
 {
-  Gdk::Rectangle rect;
-
-  auto current_event = gtk_get_current_event();
+  auto current_event = Glib::wrap(gtk_get_current_event(), false);
 
-  if (current_event->type != GDK_BUTTON_PRESS)
+  if (current_event.get_event_type() != Gdk::Event::Type::BUTTON_PRESS)
   {
     return;
   }
 
-  gdk_window_coords_to_parent (current_event->button.window,
-                               current_event->button.x, current_event->button.y,
-                               &current_event->button.x, &current_event->button.y);
+  // The event is a GdkEventButton.
+  // This suspicious-looking cast is okay because Gdk::EventButton
+  // does not add any data members to those of Gdk::Event.
+  Gdk::EventButton& current_event_button = *static_cast<Gdk::EventButton*>(&current_event);
+
+  double x = 0.0;
+  double y = 0.0;
+  current_event_button.get_coords(x, y);
+  current_event_button.get_window()->coords_to_parent(x, y, x, y);
+  Gdk::Rectangle rect;
   auto allocation = m_calendar.get_allocation();
-  rect.set_x(current_event->button.x - allocation.get_x());
-  rect.set_y(current_event->button.y - allocation.get_y());
+  rect.set_x(x - allocation.get_x());
+  rect.set_y(y - allocation.get_y());
   rect.set_width(1);
   rect.set_height(1);
 
@@ -163,7 +168,5 @@ void ExampleWindow::on_day_selected()
   m_calendar_popover.set_visible(true);
 
   m_calendar_popover_entry.set_text("");
-
-  gdk_event_free (current_event);
 }
 
diff --git a/examples/others/cellrenderercustom/cellrendererpopup.cc 
b/examples/others/cellrenderercustom/cellrendererpopup.cc
index 1802dd3..bfb3dfa 100644
--- a/examples/others/cellrenderercustom/cellrendererpopup.cc
+++ b/examples/others/cellrenderercustom/cellrendererpopup.cc
@@ -230,9 +230,9 @@ bool CellRendererPopup::on_button_press_event(Gdk::EventButton& event)
 
   // If the event happened outside the popup, cancel editing.
 
-  //gdk_event_get_root_coords(event.Event::gobj(), &x, &y);
-  const double x = event.get_root_x();
-  const double y = event.get_root_y();
+  double x = 0.0;
+  double y = 0.0;
+  event.get_root_coords(x, y);
 
   int xoffset = 0, yoffset = 0;
   popup_window_.get_window()->get_root_origin(xoffset, yoffset);
diff --git a/examples/others/cellrenderercustom/popupentry.cc 
b/examples/others/cellrenderercustom/popupentry.cc
index f8cb767..5e86cef 100644
--- a/examples/others/cellrenderercustom/popupentry.cc
+++ b/examples/others/cellrenderercustom/popupentry.cc
@@ -109,6 +109,12 @@ bool PopupEntry::on_key_press_event(Gdk::EventKey& key_event)
 
   // Hackish :/ Synthesize a key press event for the entry.
 
+/*
+ * Can't do this now (2017-10-06).
+ * GdkEvent and its subclasses are now opaque structures. We can't directly
+ * access their data. There is a gdk_event_get_window() to get the window,
+ * but there is no gdk_event_set_window() to set a window.
+
   Gdk::EventKey synth_event(key_event);
 
   GdkEventKey* const synth_event_gobj = synth_event.gobj();
@@ -120,7 +126,7 @@ bool PopupEntry::on_key_press_event(Gdk::EventKey& key_event)
   synth_event_gobj->send_event = true;
 
   entry_->event(synth_event);
-
+*/
   return Gtk::Box::on_key_press_event(key_event);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]