[gtkmm] Gdk::Event: Inherit from Glib::Object



commit 64753083a4172cf780ee489ad29aba7b399964a8
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Fri Jan 12 16:08:10 2018 +0100

    Gdk::Event: Inherit from Glib::Object
    
    GdkEvent is now a reference counted subclass of GObject.
    Make Gdk::Event and its subclasses inherit from Glib::Object and store
    pointers to them in Glib::RefPtr.
    GdkEventKey, GdkEventButton, etc. are not real subclasses of GdkEvent.
    They all share a single type in the GType system.

 demos/gtk-demo/example_change_display.cc |    4 +-
 demos/gtk-demo/example_iconbrowser.cc    |    4 +-
 gdk/src/display.hg                       |    7 +-
 gdk/src/event.ccg                        |    9 +-
 gdk/src/event.hg                         |   40 ++++---
 gdk/src/seat.hg                          |    2 +-
 gdk/src/window.hg                        |    2 +-
 gtk/src/cellarea.hg                      |    8 +-
 gtk/src/celleditable.hg                  |    6 +-
 gtk/src/cellrenderer.hg                  |   10 +-
 gtk/src/entry.hg                         |    8 +-
 gtk/src/eventcontroller.hg               |    2 +-
 gtk/src/gesture.hg                       |    3 +-
 gtk/src/menu.hg                          |    6 +-
 gtk/src/scrollbar.hg                     |    4 +-
 gtk/src/searchbar.hg                     |    4 +-
 gtk/src/searchentry.hg                   |    4 +-
 gtk/src/textview.hg                      |    2 +-
 gtk/src/widget.ccg                       |    7 -
 gtk/src/widget.hg                        |   90 +++++++-------
 tools/m4/class_gdkevent.m4               |  208 +++---------------------------
 tools/m4/convert_gdk.m4                  |   21 ++--
 22 files changed, 140 insertions(+), 311 deletions(-)
---
diff --git a/demos/gtk-demo/example_change_display.cc b/demos/gtk-demo/example_change_display.cc
index 3733c7f..af10972 100644
--- a/demos/gtk-demo/example_change_display.cc
+++ b/demos/gtk-demo/example_change_display.cc
@@ -64,7 +64,7 @@ protected:
 
   virtual void on_display_closed(bool is_error, Glib::RefPtr<Gdk::Display> display);
 
-  virtual bool on_popup_button_release_event(Gdk::EventButton& event);
+  virtual bool on_popup_button_release_event(const Glib::RefPtr<Gdk::EventButton>& event);
 
   void on_response(int response_id) override;
 
@@ -358,7 +358,7 @@ Gtk::Widget* Example_ChangeDisplay::find_toplevel_at_pointer(const Glib::RefPtr<
 }
 
 
-bool Example_ChangeDisplay::on_popup_button_release_event(Gdk::EventButton& /* event */)
+bool Example_ChangeDisplay::on_popup_button_release_event(const Glib::RefPtr<Gdk::EventButton>& /* event */)
 {
   m_popup_clicked = true;
   return true;
diff --git a/demos/gtk-demo/example_iconbrowser.cc b/demos/gtk-demo/example_iconbrowser.cc
index db2ed03..a68f6ea 100644
--- a/demos/gtk-demo/example_iconbrowser.cc
+++ b/demos/gtk-demo/example_iconbrowser.cc
@@ -119,7 +119,7 @@ public:
 
 protected:
   // Signal handlers:
-  bool on_window_key_press_event(Gdk::EventKey& event);
+  bool on_window_key_press_event(const Glib::RefPtr<Gdk::EventKey>& event);
   void on_symbolic_radio_toggled();
   void on_context_list_selected_rows_changed();
   void on_icon_view_item_activated(const Gtk::TreeModel::Path& path);
@@ -267,7 +267,7 @@ Example_IconBrowser::~Example_IconBrowser()
 {
 }
 
-bool Example_IconBrowser::on_window_key_press_event(Gdk::EventKey& key_press_event)
+bool Example_IconBrowser::on_window_key_press_event(const Glib::RefPtr<Gdk::EventKey>& key_press_event)
 {
   return m_search_bar.handle_event(key_press_event);
 }
diff --git a/gdk/src/display.hg b/gdk/src/display.hg
index b91ec83..20587b1 100644
--- a/gdk/src/display.hg
+++ b/gdk/src/display.hg
@@ -65,10 +65,11 @@ public:
   _WRAP_METHOD(bool is_rgba() const, gdk_display_is_rgba)
 
   // get_event() removes the next event, if there is one - therefore there is no const version:
-  _WRAP_METHOD(Event get_event(), gdk_display_get_event)
+  _WRAP_METHOD(Glib::RefPtr<Event> get_event(), gdk_display_get_event)
 
-  _WRAP_METHOD(Event peek_event() const, gdk_display_peek_event)
-  _WRAP_METHOD(void put_event(const Event& event), gdk_display_put_event)
+  _WRAP_METHOD(Glib::RefPtr<Event> peek_event(), gdk_display_peek_event)
+  _WRAP_METHOD(Glib::RefPtr<const Event> peek_event() const, gdk_display_peek_event, constversion)
+  _WRAP_METHOD(void put_event(const Glib::RefPtr<const Event>& event), gdk_display_put_event)
   _WRAP_METHOD(bool has_pending() const, gdk_display_has_pending)
 
   _WRAP_METHOD(static Glib::RefPtr<Display> get_default(), gdk_display_get_default, refreturn)
diff --git a/gdk/src/event.ccg b/gdk/src/event.ccg
index 0ebaee1..d908fe5 100644
--- a/gdk/src/event.ccg
+++ b/gdk/src/event.ccg
@@ -19,12 +19,5 @@
 #include <gdkmm/seat.h>
 #include <gdkmm/window.h>
 
-namespace Gdk
-{
+using Type = Gdk::Event::Type;
 
-Event::operator bool() const noexcept
-{
-  return gobj() != nullptr;
-}
-
-} //namespace Gdk
diff --git a/gdk/src/event.hg b/gdk/src/event.hg
index 37408d0..70d36b6 100644
--- a/gdk/src/event.hg
+++ b/gdk/src/event.hg
@@ -17,7 +17,9 @@
 
 _DEFS(gdkmm,gdk)
 _CC_INCLUDE(gdk/gdk.h)
+_PINCLUDE(glibmm/private/object_p.h)
 
+#include <glibmm/object.h>
 #include <glibmm/refptr.h>
 #include <glibmm/value.h>
 
@@ -33,7 +35,8 @@ enum { DELETE = GTKMM_MACRO_DEFINITION_DELETE };
 #endif
 
 #ifndef DOXYGEN_SHOULD_SKIP_THIS
-extern "C" { typedef union _GdkEvent GdkEvent; }
+using GdkEvent = union _GdkEvent;
+using GdkEventClass = struct _GdkEventClass;
 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
 
 namespace Gdk
@@ -42,28 +45,31 @@ class Display;
 class Seat;
 class Window;
 
-/** Represents an event.
+/** Functions for handling events from the window system.
+ *
+ * In GTK+ applications the events are handled automatically in
+ * gtk_main_do_event() and passed on to the appropriate widgets,
+ * so %Gdk::Event and its subclasses are rarely needed.
  */
-class Event
+class Event : public Glib::Object
 {
-  _CLASS_GDKEVENT(Event, GdkEvent)
-  _IGNORE(gdk_event_new, gdk_event_copy, gdk_event_free)
-public:
+  _CLASS_GOBJECT(Event, GdkEvent, GDK_EVENT, Glib::Object, GObject)
+  _STRUCT_NOT_HIDDEN dnl// _GdkEvent is not a struct, it's a union
+  _IGNORE(gdk_event_new, gdk_event_free)
 
+public:
   _WRAP_ENUM(Type, GdkEventType)
 
-  /** Discover whether the event is valid.
-   * For instance,
-   * @code
-   * if (event)
-   *   do_something();
-   * @endcode
-   *
-   * @newin{3,92}
+protected:
+  _WRAP_CTOR(Event(Type event_type), gdk_event_new)
+
+public:
+  /** Creates a new event of the given type. All fields are set to 0.
    */
-  explicit operator bool() const noexcept;
+  _WRAP_CREATE(Type event_type)
+  _WRAP_METHOD(Glib::RefPtr<Event> copy() const, gdk_event_copy)
 
-  _WRAP_METHOD(Event::Type get_event_type() const, gdk_event_get_event_type)
+  _WRAP_METHOD(Type get_event_type() const, gdk_event_get_event_type)
 
   _WRAP_METHOD(Glib::RefPtr<Gdk::Window> get_window(), gdk_event_get_window, refreturn)
   _WRAP_METHOD(Glib::RefPtr<const Gdk::Window> get_window() const, gdk_event_get_window, refreturn, 
constversion)
@@ -85,6 +91,8 @@ public:
   _WRAP_METHOD(Glib::RefPtr<Seat> get_seat(), gdk_event_get_seat, refreturn, newin "3,90")
   _WRAP_METHOD(Glib::RefPtr<const Seat> get_seat() const, gdk_event_get_seat, refreturn, constversion, newin 
"3,90")
 
+  _WRAP_PROPERTY("event-type", Type)
+
   //TODO: If GdkDeviceTool is wrapped in gtkmm, wrap gdk_event_get_device_tool().
   _IGNORE(gdk_event_set_device_tool) dnl// "Should be rarely used"
 
diff --git a/gdk/src/seat.hg b/gdk/src/seat.hg
index f8df074..540245e 100644
--- a/gdk/src/seat.hg
+++ b/gdk/src/seat.hg
@@ -60,7 +60,7 @@ public:
                Capabilities capabilities,
                bool owner_events,
                const Glib::RefPtr<Cursor>& cursor = Glib::RefPtr<Cursor>(),
-               const Event& event = Event(),
+               const Glib::RefPtr<const Event>& event = {},
                const SlotGrabPrepare& slot = SlotGrabPrepare()),
                gdk_seat_grab, slot_name slot, slot_callback Seat_grab_callback, no_slot_copy)
 
diff --git a/gdk/src/window.hg b/gdk/src/window.hg
index 59ed319..90b2eca 100644
--- a/gdk/src/window.hg
+++ b/gdk/src/window.hg
@@ -306,7 +306,7 @@ public:
 
   _WRAP_METHOD(void set_shadow_width(int left, int right, int top, int bottom), gdk_window_set_shadow_width)
 
-  _WRAP_METHOD(bool show_window_menu(const Event& event), gdk_window_show_window_menu)
+  _WRAP_METHOD(bool show_window_menu(const Glib::RefPtr<const Event>& event), gdk_window_show_window_menu)
 
   /** Creates a new GLContext matching the framebuffer format to the visual of the
    * Window. The context is disconnected from any particular window or surface.
diff --git a/gtk/src/cellarea.hg b/gtk/src/cellarea.hg
index 119a1ca..2ab6816 100644
--- a/gtk/src/cellarea.hg
+++ b/gtk/src/cellarea.hg
@@ -157,7 +157,9 @@ public:
   void foreach(const Glib::RefPtr<CellAreaContext>& context, Widget* widget, const Gdk::Rectangle& 
cell_area, const Gdk::Rectangle& background_area, const SlotForeachAlloc& slot);
   _IGNORE(gtk_cell_area_foreach_alloc)
 
-  _WRAP_METHOD(int event(const Glib::RefPtr<CellAreaContext>& context, Widget& widget, const Gdk::Event& 
gdk_event, const Gdk::Rectangle& cell_area, GtkCellRendererState flags), gtk_cell_area_event)
+  _WRAP_METHOD(int event(const Glib::RefPtr<CellAreaContext>& context, Widget& widget,
+    const Glib::RefPtr<const Gdk::Event>& gdk_event, const Gdk::Rectangle& cell_area,
+    GtkCellRendererState flags), gtk_cell_area_event)
 
   _WRAP_METHOD(void snapshot(const Glib::RefPtr<CellAreaContext>& context, Widget& widget,
      Snapshot& snapshot, const Gdk::Rectangle& background_area, const Gdk::Rectangle& cell_area,
@@ -220,7 +222,9 @@ public:
   _WRAP_METHOD(CellEditable* get_edit_widget(), gtk_cell_area_get_edit_widget)
   _WRAP_METHOD(const CellEditable* get_edit_widget() const, gtk_cell_area_get_edit_widget, constversion)
 
-  _WRAP_METHOD(bool activate_cell(Widget& widget, CellRenderer& renderer, const Gdk::Event& gdk_event, const 
Gdk::Rectangle& cell_area, CellRendererState flags), gtk_cell_area_activate_cell)
+  _WRAP_METHOD(bool activate_cell(Widget& widget, CellRenderer& renderer,
+    const Glib::RefPtr<const Gdk::Event>& gdk_event, const Gdk::Rectangle& cell_area,
+    CellRendererState flags), gtk_cell_area_activate_cell)
   _WRAP_METHOD(void stop_editing(bool canceled), gtk_cell_area_stop_editing)
 
   _WRAP_METHOD(void inner_cell_area(Widget& widget, const Gdk::Rectangle& cell_area, Gdk::Rectangle& 
inner_area), gtk_cell_area_inner_cell_area)
diff --git a/gtk/src/celleditable.hg b/gtk/src/celleditable.hg
index 70eec89..f0163c8 100644
--- a/gtk/src/celleditable.hg
+++ b/gtk/src/celleditable.hg
@@ -40,7 +40,7 @@ class CellEditable : public Glib::Interface
   _CLASS_INTERFACE(CellEditable,GtkCellEditable,GTK_CELL_EDITABLE,GtkCellEditableIface)
 
 public:
-  _WRAP_METHOD(void start_editing(const Gdk::Event& event), gtk_cell_editable_start_editing)
+  _WRAP_METHOD(void start_editing(const Glib::RefPtr<const Gdk::Event>& event), 
gtk_cell_editable_start_editing)
   _WRAP_METHOD(void editing_done(), gtk_cell_editable_editing_done)
   _WRAP_METHOD(void remove_widget(), gtk_cell_editable_remove_widget)
 
@@ -50,8 +50,8 @@ public:
   _WRAP_PROPERTY("editing-canceled", bool)
 
 protected:
-#m4 _CONVERSION(`GdkEvent*',`const Gdk::Event&',`Gdk::wrap_event($3)')
-  _WRAP_VFUNC(void start_editing(const Gdk::Event& event), start_editing)
+#m4 _CONVERSION(`GdkEvent*',`const Glib::RefPtr<const Gdk::Event>&',`Glib::wrap($3, true)')
+  _WRAP_VFUNC(void start_editing(const Glib::RefPtr<const Gdk::Event>& event), start_editing)
 };
 
 } // namespace Gtk
diff --git a/gtk/src/cellrenderer.hg b/gtk/src/cellrenderer.hg
index 8e6af01..7e4f7fc 100644
--- a/gtk/src/cellrenderer.hg
+++ b/gtk/src/cellrenderer.hg
@@ -72,7 +72,7 @@ public:
                   CellRendererState flags), gtk_cell_renderer_snapshot)
 
   _WRAP_METHOD(bool activate(
-                  const Gdk::Event& event,
+                  const Glib::RefPtr<const Gdk::Event>& event,
                   Widget& widget,
                   const Glib::ustring& path,
                   const Gdk::Rectangle& background_area,
@@ -80,7 +80,7 @@ public:
                   CellRendererState flags), gtk_cell_renderer_activate)
 
   _WRAP_METHOD(CellEditable* start_editing(
-                  const Gdk::Event& event, Widget& widget,
+                  const Glib::RefPtr<const Gdk::Event>& event, Widget& widget,
                   const Glib::ustring& path,
                   const Gdk::Rectangle& background_area,
                   const Gdk::Rectangle& cell_area,
@@ -151,9 +151,9 @@ protected:
                   const Gdk::Rectangle& cell_area,
                   CellRendererState flags), snapshot)
 
-#m4 _CONVERSION(`GdkEvent*',`const Gdk::Event&',`Gdk::wrap_event($3)')
+#m4 _CONVERSION(`GdkEvent*',`const Glib::RefPtr<const Gdk::Event>&',`Glib::wrap($3, true)')
   _WRAP_VFUNC(bool activate(
-                  const Gdk::Event& event,
+                  const Glib::RefPtr<const Gdk::Event>& event,
                   Widget& widget,
                   const Glib::ustring& path,
                   const Gdk::Rectangle& background_area,
@@ -161,7 +161,7 @@ protected:
                   CellRendererState flags), activate)
 
   _WRAP_VFUNC(CellEditable* start_editing(
-                  const Gdk::Event& event,
+                  const Glib::RefPtr<const Gdk::Event>& event,
                   Widget& widget,
                   const Glib::ustring& path,
                   const Gdk::Rectangle& background_area,
diff --git a/gtk/src/entry.hg b/gtk/src/entry.hg
index e832665..d57f8bf 100644
--- a/gtk/src/entry.hg
+++ b/gtk/src/entry.hg
@@ -177,7 +177,7 @@ public:
   _IGNORE(gtk_entry_get_icon_area)
 
   _WRAP_METHOD(int get_current_icon_drag_source(), gtk_entry_get_current_icon_drag_source)
-  _WRAP_METHOD(bool im_context_filter_keypress(Gdk::EventKey& gdk_event), 
gtk_entry_im_context_filter_keypress)
+  _WRAP_METHOD(bool im_context_filter_keypress(const Glib::RefPtr<Gdk::EventKey>& gdk_event), 
gtk_entry_im_context_filter_keypress)
   _WRAP_METHOD(void reset_im_context(), gtk_entry_reset_im_context)
 
   _WRAP_METHOD(void set_input_purpose(InputPurpose purpose), gtk_entry_set_input_purpose)
@@ -204,10 +204,10 @@ public:
   //Note that the GTK+ C documentation for the activate signal says (as of 2012-06) that it should be used 
by applications even though it is a keybinding signal.
   _WRAP_SIGNAL(void activate(), "activate")
 
-#m4 _CONVERSION(`const GdkEventButton*',`const Gdk::EventButton&',`Gdk::wrap_event($3)')
+#m4 _CONVERSION(`const GdkEventButton*',`const Glib::RefPtr<const 
Gdk::EventButton>&',`Glib::wrap(const_cast<GdkEventButton*>($3), true)')
   // no_default_handler because the wrapped C signals have no default handlers.
-  _WRAP_SIGNAL(void icon_release(IconPosition icon_position, const Gdk::EventButton& event), "icon-release", 
no_default_handler)
-  _WRAP_SIGNAL(void icon_press(IconPosition icon_position, const Gdk::EventButton& event), "icon-press", 
no_default_handler)
+  _WRAP_SIGNAL(void icon_release(IconPosition icon_position, const Glib::RefPtr<const Gdk::EventButton>& 
event), "icon-release", no_default_handler)
+  _WRAP_SIGNAL(void icon_press(IconPosition icon_position, const Glib::RefPtr<const Gdk::EventButton>& 
event), "icon-press", no_default_handler)
 
   _IGNORE_SIGNAL("move_cursor")
   _IGNORE_SIGNAL("delete_from_cursor")
diff --git a/gtk/src/eventcontroller.hg b/gtk/src/eventcontroller.hg
index 1d5673e..7cc55b2 100644
--- a/gtk/src/eventcontroller.hg
+++ b/gtk/src/eventcontroller.hg
@@ -69,7 +69,7 @@ public:
 
   _WRAP_METHOD(Widget* get_widget(), gtk_event_controller_get_widget)
   _WRAP_METHOD(const Widget* get_widget() const, gtk_event_controller_get_widget, constversion)
-  _WRAP_METHOD(bool handle_event(const Gdk::Event& event), gtk_event_controller_handle_event)
+  _WRAP_METHOD(bool handle_event(const Glib::RefPtr<const Gdk::Event>& event), 
gtk_event_controller_handle_event)
   _WRAP_METHOD(void reset(), gtk_event_controller_reset)
   _WRAP_METHOD(PropagationPhase get_propagation_phase() const, gtk_event_controller_get_propagation_phase)
   _WRAP_METHOD(void set_propagation_phase(PropagationPhase phase), 
gtk_event_controller_set_propagation_phase)
diff --git a/gtk/src/gesture.hg b/gtk/src/gesture.hg
index 24f6fdb..627ff83 100644
--- a/gtk/src/gesture.hg
+++ b/gtk/src/gesture.hg
@@ -144,7 +144,8 @@ public:
   _WRAP_METHOD(Gdk::EventSequence* get_last_updated_sequence(), gtk_gesture_get_last_updated_sequence)
   _WRAP_METHOD(const Gdk::EventSequence* get_last_updated_sequence() const, 
gtk_gesture_get_last_updated_sequence, constversion)
   _WRAP_METHOD(bool handles_sequence(Gdk::EventSequence* sequence) const, gtk_gesture_handles_sequence)
-  _WRAP_METHOD(Gdk::Event get_last_event(Gdk::EventSequence* sequence) const, gtk_gesture_get_last_event)
+  _WRAP_METHOD(Glib::RefPtr<const Gdk::Event> get_last_event(Gdk::EventSequence* sequence) const,
+    gtk_gesture_get_last_event, refreturn)
   _WRAP_METHOD(bool get_point(Gdk::EventSequence* sequence, double& x, double& y) const, 
gtk_gesture_get_point)
   _WRAP_METHOD(bool get_bounding_box(Gdk::Rectangle& rect) const, gtk_gesture_get_bounding_box)
   _WRAP_METHOD(bool get_bounding_box_center(double& x, double& y) const, gtk_gesture_get_bounding_box_center)
diff --git a/gtk/src/menu.hg b/gtk/src/menu.hg
index 0b43198..5c13f15 100644
--- a/gtk/src/menu.hg
+++ b/gtk/src/menu.hg
@@ -100,10 +100,10 @@ public:
 
   _WRAP_METHOD(void popup_at_rect(const Glib::RefPtr<Gdk::Window>& rect_window,
     const Gdk::Rectangle& rect, Gdk::Gravity rect_anchor, Gdk::Gravity menu_anchor,
-    const Gdk::Event& trigger_event = Gdk::Event()), gtk_menu_popup_at_rect)
+    const Glib::RefPtr<const Gdk::Event>& trigger_event = {}), gtk_menu_popup_at_rect)
   _WRAP_METHOD(void popup_at_widget(Widget* widget, Gdk::Gravity widget_anchor,
-   Gdk::Gravity menu_anchor, const Gdk::Event& trigger_event = Gdk::Event()), gtk_menu_popup_at_widget)
-  _WRAP_METHOD(void popup_at_pointer(const Gdk::Event& trigger_event = Gdk::Event()), 
gtk_menu_popup_at_pointer)
+   Gdk::Gravity menu_anchor, const Glib::RefPtr<const Gdk::Event>& trigger_event = {}), 
gtk_menu_popup_at_widget)
+  _WRAP_METHOD(void popup_at_pointer(const Glib::RefPtr<const Gdk::Event>& trigger_event = {}), 
gtk_menu_popup_at_pointer)
 
   _WRAP_METHOD(void reposition(), gtk_menu_reposition)
 
diff --git a/gtk/src/scrollbar.hg b/gtk/src/scrollbar.hg
index b7557d5..ff8dba6 100644
--- a/gtk/src/scrollbar.hg
+++ b/gtk/src/scrollbar.hg
@@ -65,8 +65,8 @@ public:
   _WRAP_METHOD(Glib::RefPtr<Adjustment> get_adjustment(), gtk_scrollbar_get_adjustment, refreturn)
   _WRAP_METHOD(Glib::RefPtr<const Adjustment> get_adjustment() const, gtk_scrollbar_get_adjustment, 
refreturn, constversion)
 
-#m4 _CONVERSION(`const Gdk::EventScroll&',`const GdkEventScroll*',`($3).gobj()')
-  _WRAP_METHOD(double get_wheel_delta(const Gdk::EventScroll& event) const, gtk_scrollbar_get_wheel_delta)
+#m4 _CONVERSION(`const Glib::RefPtr<const Gdk::EventScroll>&',`const GdkEventScroll*',__CONVERT_REFPTR_TO_P)
+  _WRAP_METHOD(double get_wheel_delta(const Glib::RefPtr<const Gdk::EventScroll>& event) const, 
gtk_scrollbar_get_wheel_delta)
 
   _WRAP_PROPERTY("adjustment", Glib::RefPtr<Adjustment>)
 };
diff --git a/gtk/src/searchbar.hg b/gtk/src/searchbar.hg
index d7844d4..ee53045 100644
--- a/gtk/src/searchbar.hg
+++ b/gtk/src/searchbar.hg
@@ -66,8 +66,8 @@ public:
   _WRAP_METHOD(void set_show_close_button(bool visible=true), gtk_search_bar_set_show_close_button)
 
   // We use Gdk::EventKey& rather than Gdk::Event&. See GTK+ bug 
https://bugzilla.gnome.org/show_bug.cgi?id=709544
-#m4 _CONVERSION(`Gdk::EventKey&',`GdkEvent*',`($3).Event::gobj()')
-  _WRAP_METHOD(bool handle_event(Gdk::EventKey& gdk_event), gtk_search_bar_handle_event)
+#m4 _CONVERSION(`const Glib::RefPtr<Gdk::EventKey>&',`GdkEvent*',`reinterpret_cast<$2>(Glib::unwrap($3))')
+  _WRAP_METHOD(bool handle_event(const Glib::RefPtr<Gdk::EventKey>& gdk_event), gtk_search_bar_handle_event)
 
 
   _WRAP_PROPERTY("search-mode-enabled", bool)
diff --git a/gtk/src/searchentry.hg b/gtk/src/searchentry.hg
index 6d36bc0..e1b7ef5 100644
--- a/gtk/src/searchentry.hg
+++ b/gtk/src/searchentry.hg
@@ -61,8 +61,8 @@ public:
   _CTOR_DEFAULT
 
   // We use Gdk::EventKey& rather than Gdk::Event&. See GTK+ bug 
https://bugzilla.gnome.org/show_bug.cgi?id=709544
-#m4 _CONVERSION(`Gdk::EventKey&',`GdkEvent*',`($3).Event::gobj()')
-  _WRAP_METHOD(bool handle_event(Gdk::EventKey& gdk_event), gtk_search_entry_handle_event)
+#m4 _CONVERSION(`const Glib::RefPtr<Gdk::EventKey>&',`GdkEvent*',`reinterpret_cast<$2>(Glib::unwrap($3))')
+  _WRAP_METHOD(bool handle_event(const Glib::RefPtr<Gdk::EventKey>& gdk_event), 
gtk_search_entry_handle_event)
 
   _WRAP_SIGNAL(void search_changed(), "search-changed")
   // Although next-match, previous-match and stop-search are keybinding signals,
diff --git a/gtk/src/textview.hg b/gtk/src/textview.hg
index de42edc..cf78d2c 100644
--- a/gtk/src/textview.hg
+++ b/gtk/src/textview.hg
@@ -151,7 +151,7 @@ public:
   _WRAP_METHOD(bool starts_display_line(const TextBuffer::iterator&  iter), 
gtk_text_view_starts_display_line)
   _WRAP_METHOD(bool move_visually(TextBuffer::iterator& iter, int count), gtk_text_view_move_visually)
 
-  _WRAP_METHOD(bool im_context_filter_keypress(Gdk::EventKey& gdk_event), 
gtk_text_view_im_context_filter_keypress)
+  _WRAP_METHOD(bool im_context_filter_keypress(const Glib::RefPtr<Gdk::EventKey>& gdk_event), 
gtk_text_view_im_context_filter_keypress)
   _WRAP_METHOD(void reset_im_context(), gtk_text_view_reset_im_context)
 
   _WRAP_METHOD(void add_child_at_anchor(Widget& child, const Glib::RefPtr<TextBuffer::ChildAnchor>& anchor), 
gtk_text_view_add_child_at_anchor)
diff --git a/gtk/src/widget.ccg b/gtk/src/widget.ccg
index 0048e61..ada65b6 100644
--- a/gtk/src/widget.ccg
+++ b/gtk/src/widget.ccg
@@ -82,13 +82,6 @@ static void Widget_signal_drag_data_get_callback(GtkWidget* self, GdkDragContext
   }
 }
 
-// The reinterpret_cast works because Event is a standard-layout class
-// whose only data member is a GdkEvent pointer.
-Gdk::Event& wrap_event_any(GdkEventAny*& event)
-{
-  return reinterpret_cast<Gdk::Event&>(event);
-}
-
 } //anonymous
 
 namespace Gtk
diff --git a/gtk/src/widget.hg b/gtk/src/widget.hg
index 2f21ef3..c80294f 100644
--- a/gtk/src/widget.hg
+++ b/gtk/src/widget.hg
@@ -141,10 +141,10 @@ public:
   _IGNORE(gtk_widget_can_activate_accel)
   //Probably not useful. Too C-specific: _WRAP_METHOD(bool can_activate_accel(guint signal_id) const, 
gtk_widget_can_activate_accel)
 
-  _WRAP_METHOD(bool event(const Gdk::Event& gdk_event), gtk_widget_event)
+  _WRAP_METHOD(bool event(const Glib::RefPtr<const Gdk::Event>& gdk_event), gtk_widget_event)
   // We use const Gdk::EventFocus& rather than Gdk::Event&. See GTK+ bug 
https://bugzilla.gnome.org/show_bug.cgi?id=709544
-#m4 _CONVERSION(`const Gdk::EventFocus&',`GdkEvent*',`const_cast<$2>(($3).Event::gobj())')
-  _WRAP_METHOD(bool send_focus_change(const Gdk::EventFocus& gdk_event), gtk_widget_send_focus_change)
+#m4 _CONVERSION(`const Glib::RefPtr<const 
Gdk::EventFocus>&',`GdkEvent*',`const_cast<$2>(reinterpret_cast<const $2>(Glib::unwrap($3)))')
+  _WRAP_METHOD(bool send_focus_change(const Glib::RefPtr<const Gdk::EventFocus>& gdk_event), 
gtk_widget_send_focus_change)
   _WRAP_METHOD(bool activate(), gtk_widget_activate)
 
   // gtk_widget_reparent() has been removed, but we want to keep Gtk::Widget::reparent().
@@ -580,31 +580,31 @@ public:
   _WRAP_SIGNAL(bool mnemonic_activate(bool group_cycling), "mnemonic_activate")
   _WRAP_SIGNAL(void grab_focus(), "grab_focus")
   _WRAP_SIGNAL(bool focus(DirectionType direction), "focus")
-#m4 _CONVERSION(`GdkEvent*',`Gdk::Event&',`Gdk::wrap_event($3)')
-  _WRAP_SIGNAL(bool event(Gdk::Event& gdk_event), "event", deprecated)
+#m4 _CONVERSION(`GdkEvent*',`const Glib::RefPtr<Gdk::Event>&',`Glib::wrap($3, true)')
+  _WRAP_SIGNAL(bool event(const Glib::RefPtr<Gdk::Event>& gdk_event), "event", deprecated)
   // The event_after signal can't have a default handler because the wrapped C signal has no default handler.
-#m4 _CONVERSION(`GdkEvent*',`const Gdk::Event&',`Gdk::wrap_event($3)')
-  _WRAP_SIGNAL(void event_after(const Gdk::Event& gdk_event), "event_after", no_default_handler, deprecated)
+#m4 _CONVERSION(`GdkEvent*',`const Glib::RefPtr<const Gdk::Event>&',`Glib::wrap($3, true)')
+  _WRAP_SIGNAL(void event_after(const Glib::RefPtr<const Gdk::Event>& gdk_event), "event_after", 
no_default_handler, deprecated)
 
-#m4 _CONVERSION(`GdkEventButton*',`Gdk::EventButton&',`Gdk::wrap_event($3)')
+#m4 _CONVERSION(`GdkEventButton*',`const Glib::RefPtr<Gdk::EventButton>&',`Glib::wrap($3, true)')
   /// Event triggered by user pressing button.
-  _WRAP_SIGNAL(bool button_press_event(Gdk::EventButton& button_event),"button_press_event", deprecated)
+  _WRAP_SIGNAL(bool button_press_event(const Glib::RefPtr<Gdk::EventButton>& 
button_event),"button_press_event", deprecated)
 
   /// Event triggered by user releasing button.
-  _WRAP_SIGNAL(bool button_release_event(Gdk::EventButton& release_event), "button_release_event", 
deprecated)
+  _WRAP_SIGNAL(bool button_release_event(const Glib::RefPtr<Gdk::EventButton>& release_event), 
"button_release_event", deprecated)
 
-#m4 _CONVERSION(`GdkEventScroll*',`Gdk::EventScroll&',`Gdk::wrap_event($3)')
-#m4 _CONVERSION(`Gdk::EventScroll&',`GdkEventScroll*',`($3).gobj()')
-  _WRAP_SIGNAL(bool scroll_event(Gdk::EventScroll& scroll_event), "scroll_event", deprecated)
+#m4 _CONVERSION(`GdkEventScroll*',`const Glib::RefPtr<Gdk::EventScroll>&',`Glib::wrap($3, true)')
+#m4 _CONVERSION(`const Glib::RefPtr<Gdk::EventScroll>&',`GdkEventScroll*',__CONVERT_REFPTR_TO_P)
+  _WRAP_SIGNAL(bool scroll_event(const Glib::RefPtr<Gdk::EventScroll>& scroll_event), "scroll_event", 
deprecated)
 
-#m4 _CONVERSION(`GdkEventMotion*',`Gdk::EventMotion&',`Gdk::wrap_event($3)')
-#m4 _CONVERSION(`Gdk::EventMotion&',`GdkEventMotion*',`($3).gobj()')
+#m4 _CONVERSION(`GdkEventMotion*',`const Glib::RefPtr<Gdk::EventMotion>&',`Glib::wrap($3, true)')
+#m4 _CONVERSION(`const Glib::RefPtr<Gdk::EventMotion>&',`GdkEventMotion*',__CONVERT_REFPTR_TO_P)
   /// Event triggered by user moving pointer.
-  _WRAP_SIGNAL(bool motion_notify_event(Gdk::EventMotion& motion_event), "motion_notify_event", deprecated)
+  _WRAP_SIGNAL(bool motion_notify_event(const Glib::RefPtr<Gdk::EventMotion>& motion_event), 
"motion_notify_event", deprecated)
 
-#m4 _CONVERSION(`GdkEventAny*',`Gdk::Event&',`wrap_event_any($3)')
-#m4 _CONVERSION(`Gdk::Event&',`GdkEventAny*',`reinterpret_cast<GdkEventAny*>(($3).gobj())')
-  _WRAP_SIGNAL(bool delete_event(Gdk::Event& any_event), "delete_event")
+#m4 _CONVERSION(`GdkEventAny*',`const Glib::RefPtr<Gdk::Event>&',`Glib::wrap((GdkEvent*)$3, true)')
+#m4 _CONVERSION(`const 
Glib::RefPtr<Gdk::Event>&',`GdkEventAny*',`reinterpret_cast<GdkEventAny*>(Glib::unwrap($3))')
+  _WRAP_SIGNAL(bool delete_event(const Glib::RefPtr<Gdk::Event>& any_event), "delete_event")
 
 #m4begin
 dnl// Hook in special code to catch explicit uses of gtk_object_destroy() by
@@ -626,35 +626,35 @@ dnl
   //_WRAP_SIGNAL(bool draw(const Cairo::RefPtr<Cairo::Context>& cr), "draw")
   _IGNORE_SIGNAL(draw)
 
-#m4 _CONVERSION(`GdkEventKey*',`Gdk::EventKey&',`Gdk::wrap_event($3)')
+#m4 _CONVERSION(`GdkEventKey*',`const Glib::RefPtr<Gdk::EventKey>&',`Glib::wrap($3, true)')
   /// Event triggered by a key press will widget has focus.
-  _WRAP_SIGNAL(bool key_press_event(Gdk::EventKey& key_event), "key_press_event")
+  _WRAP_SIGNAL(bool key_press_event(const Glib::RefPtr<Gdk::EventKey>& key_event), "key_press_event")
 
   /// Event triggered by a key release will widget has focus.
-  _WRAP_SIGNAL(bool key_release_event(Gdk::EventKey& key_event), "key_release_event")
+  _WRAP_SIGNAL(bool key_release_event(const Glib::RefPtr<Gdk::EventKey>& key_event), "key_release_event")
 
-#m4 _CONVERSION(`GdkEventCrossing*',`Gdk::EventCrossing&',`Gdk::wrap_event($3)')
-#m4 _CONVERSION(`Gdk::EventCrossing&',`GdkEventCrossing*',`($3).gobj()')
+#m4 _CONVERSION(`GdkEventCrossing*',`const Glib::RefPtr<Gdk::EventCrossing>&',`Glib::wrap($3, true)')
+#m4 _CONVERSION(`const Glib::RefPtr<Gdk::EventCrossing>&',`GdkEventCrossing*',__CONVERT_REFPTR_TO_P)
   /// Event triggered by pointer entering widget area.
-  _WRAP_SIGNAL(bool enter_notify_event(Gdk::EventCrossing& crossing_event), "enter_notify_event", deprecated)
+  _WRAP_SIGNAL(bool enter_notify_event(const Glib::RefPtr<Gdk::EventCrossing>& crossing_event), 
"enter_notify_event", deprecated)
 
   /// Event triggered by pointer leaving widget area.
-  _WRAP_SIGNAL(bool leave_notify_event(Gdk::EventCrossing& crossing_event), "leave_notify_event", deprecated)
+  _WRAP_SIGNAL(bool leave_notify_event(const Glib::RefPtr<Gdk::EventCrossing>& crossing_event), 
"leave_notify_event", deprecated)
 
-#m4 _CONVERSION(`GdkEventConfigure*',`Gdk::EventConfigure&',`Gdk::wrap_event($3)')
-#m4 _CONVERSION(`Gdk::EventConfigure&',`GdkEventConfigure*',`($3).gobj()')
+#m4 _CONVERSION(`GdkEventConfigure*',`const Glib::RefPtr<Gdk::EventConfigure>&',`Glib::wrap($3, true)')
+#m4 _CONVERSION(`const Glib::RefPtr<Gdk::EventConfigure>&',`GdkEventConfigure*',__CONVERT_REFPTR_TO_P)
   /// Event triggered by a window resizing.
-  _WRAP_SIGNAL(bool configure_event(Gdk::EventConfigure& configure_event), "configure_event")
-#m4 _CONVERSION(`GdkEventFocus*',`Gdk::EventFocus&',`Gdk::wrap_event($3)')
-#m4 _CONVERSION(`Gdk::EventFocus&',`GdkEventFocus*',`($3).gobj()')
-  _WRAP_SIGNAL(bool focus_in_event(Gdk::EventFocus& focus_event), "focus_in_event")
-  _WRAP_SIGNAL(bool focus_out_event(Gdk::EventFocus& gdk_event), "focus_out_event")
-  _WRAP_SIGNAL(bool map_event(Gdk::Event& any_event), "map_event")
-  _WRAP_SIGNAL(bool unmap_event(Gdk::Event& any_event), "unmap_event")
-#m4 _CONVERSION(`GdkEventProximity*',`Gdk::EventProximity&',`Gdk::wrap_event($3)')
-#m4 _CONVERSION(`Gdk::EventProximity&',`GdkEventProximity*',`($3).gobj()')
-  _WRAP_SIGNAL(bool proximity_in_event(Gdk::EventProximity& proximity_event), "proximity_in_event", 
deprecated)
-  _WRAP_SIGNAL(bool proximity_out_event(Gdk::EventProximity& proximity_event), "proximity_out_event", 
deprecated)
+  _WRAP_SIGNAL(bool configure_event(const Glib::RefPtr<Gdk::EventConfigure>& configure_event), 
"configure_event")
+#m4 _CONVERSION(`GdkEventFocus*',`const Glib::RefPtr<Gdk::EventFocus>&',`Glib::wrap($3, true)')
+#m4 _CONVERSION(`const Glib::RefPtr<Gdk::EventFocus>&',`GdkEventFocus*',__CONVERT_REFPTR_TO_P)
+  _WRAP_SIGNAL(bool focus_in_event(const Glib::RefPtr<Gdk::EventFocus>& focus_event), "focus_in_event")
+  _WRAP_SIGNAL(bool focus_out_event(const Glib::RefPtr<Gdk::EventFocus>& gdk_event), "focus_out_event")
+  _WRAP_SIGNAL(bool map_event(const Glib::RefPtr<Gdk::Event>& any_event), "map_event")
+  _WRAP_SIGNAL(bool unmap_event(const Glib::RefPtr<Gdk::Event>& any_event), "unmap_event")
+#m4 _CONVERSION(`GdkEventProximity*',`const Glib::RefPtr<Gdk::EventProximity>&',`Glib::wrap($3, true)')
+#m4 _CONVERSION(`const Glib::RefPtr<Gdk::EventProximity>&',`GdkEventProximity*',__CONVERT_REFPTR_TO_P)
+  _WRAP_SIGNAL(bool proximity_in_event(const Glib::RefPtr<Gdk::EventProximity>& proximity_event), 
"proximity_in_event", deprecated)
+  _WRAP_SIGNAL(bool proximity_out_event(const Glib::RefPtr<Gdk::EventProximity>& proximity_event), 
"proximity_out_event", deprecated)
 
 #m4 _CONVERSION(`GdkDragContext*',`const Glib::RefPtr<Gdk::DragContext>&',Glib::wrap($3, true))
 
@@ -690,13 +690,13 @@ _CONVERSION(`GdkDisplay*',`const Glib::RefPtr<Gdk::Display>&',`Glib::wrap($3, tr
 #m4 _CONVERSION(`GtkTooltip*',`const Glib::RefPtr<Tooltip>&',`Glib::wrap($3, true)')
   _WRAP_SIGNAL(bool query_tooltip(int x, int y, bool keyboard_tooltip, const Glib::RefPtr<Tooltip>& 
tooltip), "query_tooltip")
 
-#m4 _CONVERSION(`GdkEventGrabBroken*',`Gdk::EventGrabBroken&',`Gdk::wrap_event($3)')
-#m4 _CONVERSION(`Gdk::EventGrabBroken&',`GdkEventGrabBroken*',`($3).gobj()')
-  _WRAP_SIGNAL(bool grab_broken_event(Gdk::EventGrabBroken& grab_broken_event), "grab_broken_event")
+#m4 _CONVERSION(`GdkEventGrabBroken*',`const Glib::RefPtr<Gdk::EventGrabBroken>&',`Glib::wrap($3, true)')
+#m4 _CONVERSION(`const Glib::RefPtr<Gdk::EventGrabBroken>&',`GdkEventGrabBroken*',__CONVERT_REFPTR_TO_P)
+  _WRAP_SIGNAL(bool grab_broken_event(const Glib::RefPtr<Gdk::EventGrabBroken>& grab_broken_event), 
"grab_broken_event")
 
-#m4 _CONVERSION(`GdkEventTouch*',`Gdk::EventTouch&',`Gdk::wrap_event($3)')
-#m4 _CONVERSION(`Gdk::EventTouch&',`GdkEventTouch*',`($3).gobj()')
-  _WRAP_SIGNAL(bool touch_event(Gdk::EventTouch& touch_event), "touch_event", deprecated)
+#m4 _CONVERSION(`GdkEventTouch*',`const Glib::RefPtr<Gdk::EventTouch>&',`Glib::wrap($3, true)')
+#m4 _CONVERSION(`const Glib::RefPtr<Gdk::EventTouch>&',`GdkEventTouch*',__CONVERT_REFPTR_TO_P)
+  _WRAP_SIGNAL(bool touch_event(const Glib::RefPtr<Gdk::EventTouch>& touch_event), "touch_event", deprecated)
 
   _WRAP_PROPERTY("name", Glib::ustring)
   _WRAP_PROPERTY("parent", Container*)
diff --git a/tools/m4/class_gdkevent.m4 b/tools/m4/class_gdkevent.m4
index cb0027e..c621c11 100644
--- a/tools/m4/class_gdkevent.m4
+++ b/tools/m4/class_gdkevent.m4
@@ -1,17 +1,15 @@
 dnl Gdk::Event and subclasses is a specific case where a class hierarchy
-dnl refers to a single pointer to a boxed type in the base class.
+dnl refers to a single pointer to a GObject type in the base class.
 dnl
-dnl Add this to Gdk::Event (Replace Event and GdkEvent with the actual name
-dnl of the class.)
+dnl Add this to Gdk::Event (Replace Event, GdkEvent and GDK_EVENT with
+dnl the actual name of the class.)
 dnl
-dnl _CLASS_GDKEVENT(Event, GdkEvent)
+dnl _CLASS_GOBJECT(Event, GdkEvent, GDK_EVENT, Glib::Object, GObject)
 dnl
-dnl Add this to any subclass Gdk::Event. This instructs to use the functionality
+dnl Add this to any subclass of Gdk::Event. This instructs to use the functionality
 dnl of the parent class for copying and destruction (note, that creation of new
-dnl events is unsupported). With only two parameters, gdk_event_copy and
-dnl gdk_event_free are used for these purposes. Replace EventKey and GdkEventKey
-dnl with the actual name of the class, and Event and GdkEvent with the name of
-dnl the base class.
+dnl events is unsupported). Replace EventKey and GdkEventKey with the actual
+dnl name of the class, and Event and GdkEvent with the name of the base class.
 dnl
 dnl _CLASS_GDKEVENT(EventKey, GdkEventKey, Event, GdkEvent)
 dnl _CLASS_GDKEVENT(C++ class, C class, C++ base class, C base class)
@@ -36,59 +34,23 @@ dnl
 define(`_END_CLASS_GDKEVENT',`
 _SECTION(SECTION_HEADER3)
 
-__NAMESPACE_BEGIN__
-
-/**
- * @param lhs The left-hand side
- * @param rhs The right-hand side
- *
- * @relates __NAMESPACE__::__CPPNAME__
- */
-inline void swap(__CPPNAME__& lhs, __CPPNAME__& rhs) noexcept
-  { lhs.swap(rhs); }
-
-/** Wraps a C event instance without making unnecessary copy when the ownership
- * can not be acquired.
- *
- * The @a event pointer must not be deleted until last usage of the returned
- * instance. Note, that this requirement applies to the pointer itself, in
- * addition to the object it is pointing to.
- *
- * @relates __NAMESPACE__::__CPPNAME__
- */
-const __CPPNAME__& wrap_event(const __CNAME__*& event);
-
-/** See wrap_event(const __CNAME__*& event).
- *
- * @relates __NAMESPACE__::__CPPNAME__
- */
-__CPPNAME__& wrap_event(__CNAME__*& event);
-
-__NAMESPACE_END__
-
+ifdef(`__BOOL_NO_WRAP_FUNCTION__',`',`dnl else
 namespace Glib
 {
-ifdef(`__BOOL_NO_WRAP_FUNCTION__',`',`dnl else
 
 /** A Glib::wrap() method for this object.
  *
  * @param object The C instance.
- * @param take_copy @c false if the result should take ownership of the C instance,
- *        @c true if it should take a new copy.
+ * @param take_copy @c false if the result should take ownership of the C instance.
+ *        @c true if it should take a new copy or ref.
  * @result A C++ instance that wraps this C instance.
  *
  * @relates __NAMESPACE__::__CPPNAME__
  */
-__NAMESPACE__::__CPPNAME__ wrap(__CNAME__* object, bool take_copy = false);
-')dnl endif __BOOL_NO_WRAP_FUNCTION__
-
-#ifndef DOXYGEN_SHOULD_SKIP_THIS
-template <>
-class Value<__NAMESPACE__::__CPPNAME__> : public Glib::Value_Boxed<__NAMESPACE__::__CPPNAME__>
-{};
-#endif /* DOXYGEN_SHOULD_SKIP_THIS */
+Glib::RefPtr<__NAMESPACE__::__CPPNAME__> wrap(__CNAME__* object, bool take_copy = false);
 
 } // namespace Glib
+')dnl endif __BOOL_NO_WRAP_FUNCTION__
 
 _SECTION(SECTION_SRC_GENERATED)
 
@@ -96,9 +58,9 @@ ifdef(`__BOOL_NO_WRAP_FUNCTION__',`',`dnl else
 namespace Glib
 {
 
-__NAMESPACE__::__CPPNAME__ wrap(__CNAME__* object, bool take_copy)
+Glib::RefPtr<__NAMESPACE__::__CPPNAME__> wrap(__CNAME__* object, bool take_copy)
 {
-  return __NAMESPACE__::__CPPNAME__`'(object, take_copy);
+  return std::static_pointer_cast<__NAMESPACE__::__CPPNAME__>(wrap((__CPARENT__*)object, take_copy));
 }
 
 } // namespace Glib
@@ -111,98 +73,11 @@ dnl The implementation:
 dnl
 
 dnl All events have the same GType. Only the base class need a get_type() method.
-ifelse(__CPPPARENT__,,`dnl
-// static
-GType __CPPNAME__::get_type()
-{
-  return _GET_TYPE_FUNC(__CNAME__);
-}
-')dnl endif not __CPPPARENT__
-
-__CPPNAME__::__CPPNAME__`'()
-:
-ifelse(__CPPPARENT__,,`dnl base class
-  gobject_(nullptr)
-',`dnl else, i.e. subclass
-  __CPPPARENT__`'()
-')dnl endif
-{
-}
-
-__CPPNAME__::__CPPNAME__`'(__CNAME__* gobject, bool make_a_copy)
-:
-ifelse(__CPPPARENT__,,`dnl base class
-  gobject_((make_a_copy && gobject) ? gdk_event_copy(gobject) : gobject)
-',`dnl else i.e. subclass
-  __CPPPARENT__`'(reinterpret_cast<__CPARENT__*>(gobject), make_a_copy)
-')dnl endif
-{}
 
-ifelse(__CPPPARENT__,`',`dnl We need those functions only for Gdk::Event
-
-__CPPNAME__::__CPPNAME__`'(const __CPPNAME__& other)
-:
-  gobject_((other.gobject_) ? gdk_event_copy(other.gobject_) : nullptr)
-{}
-
-__CPPNAME__::__CPPNAME__`'(__CPPNAME__&& other) noexcept
-:
-  gobject_(other.gobject_)
+__CNAME__* __CPPNAME__::gobj_copy()
 {
-  other.gobject_ = nullptr;
-}
-
-__CPPNAME__& __CPPNAME__::operator=(const __CPPNAME__`'& other)
-{
-  __CPPNAME__ temp(other);
-  swap(temp);
-  return *this;
-}
-
-__CPPNAME__& __CPPNAME__::operator=(__CPPNAME__`'&& other) noexcept
-{
-  __CPPNAME__ temp(std::move(other));
-  swap(temp);
-  return *this;
-}
-
-__CPPNAME__::~__CPPNAME__`'() noexcept
-{
-  if (gobject_)
-    gdk_event_free(gobject_);
-}
-')dnl endif not __CPPPARENT__
-
-void __CPPNAME__::swap(__CPPNAME__& other) noexcept
-{
-ifelse(__CPPPARENT__,,`dnl base class
-  __CNAME__ *const temp = gobject_;
-  gobject_ = other.gobject_;
-  other.gobject_ = temp;
-',`dnl else i.e. subclass
-  __CPPPARENT__::swap(other);
-')dnl endif
-}
-
-__CNAME__* __CPPNAME__::gobj_copy() const
-{
-ifelse(__CPPPARENT__,,`dnl base class
-  return gdk_event_copy(gobject_);
-',`dnl else i.e. subclass
-  return reinterpret_cast<__CNAME__*>(__CPPPARENT__::gobj_copy());
-')dnl endif
-}
-
-// The reinterpret_cast works because __CPPNAME__ is a standard-layout class
-// whose only data member is a ifelse(__CPARENT__,,`__CNAME__',`__CPARENT__') pointer.
-const __CPPNAME__& wrap_event(const __CNAME__*& event)
-{
-  return reinterpret_cast<const __CPPNAME__&>(event);
-}
-
-__CPPNAME__& wrap_event(__CNAME__*& event)
-{
-  return reinterpret_cast<__CPPNAME__&>(event);
+  reference();
+  return gobj();
 }
 
 _IMPORT(SECTION_CC)
@@ -222,63 +97,18 @@ public:
   using BaseObjectType = __CNAME__;
 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
 
-ifelse(__CPPPARENT__,,`dnl base class
-  /// Get the GType for this class, for use with the underlying GObject type system.
-  static GType get_type() G_GNUC_CONST;
-')dnl
-
-  /** Creates an invalid event object.
-   * Calling any member functions other than operator bool() is undefined behavior.
-   * An invalid event object can be used in a function call, if the underlying
-   * C function expects a NULL __CNAME__ pointer.
-   */
-  __CPPNAME__`'();
-
-  /** Wraps a C event instance.
-   * This constructor either acquires ownership of @a gobject, or copies it.
-   *
-   * @param gobject %Event to wrap.
-   * @param make_a_copy If @c false, the ownership of @a gobject is acquired,
-   *        otherwise a copy is made.
-   */
-  explicit __CPPNAME__`'(__CNAME__* gobject, bool make_a_copy = false);
-ifelse(__CPPPARENT__,`',`dnl Only add for Gdk::Event
-
-  __CPPNAME__`'(const __CPPNAME__& other);
-  __CPPNAME__& operator=(const __CPPNAME__& other);
-
-  __CPPNAME__`'(__CPPNAME__&& other) noexcept;
-  __CPPNAME__& operator=(__CPPNAME__&& other) noexcept;
-
-_IMPORT(SECTION_DTOR_DOCUMENTATION)
-  ~__CPPNAME__`'() noexcept;
-')dnl endif
-
-  void swap(__CPPNAME__& other) noexcept;
-
-ifelse(__CPPPARENT__,,`dnl
-  /// Provides access to the underlying C instance.
-  __CNAME__* gobj() noexcept { return gobject_; }
-
-  /// Provides access to the underlying C instance.
-  const __CNAME__* gobj() const noexcept { return gobject_; }
-',`dnl else
   /// Provides access to the underlying C instance.
   __CNAME__* gobj() noexcept { return reinterpret_cast<__CNAME__*>(__CPPPARENT__::gobj()); }
 
   /// Provides access to the underlying C instance.
   const __CNAME__* gobj() const noexcept { return reinterpret_cast<const __CNAME__*>(__CPPPARENT__::gobj()); 
}
-')dnl endif
 
   /** Provides access to the underlying C instance.
-   * The caller is responsible for freeing it with gdk_event_free().
+   * The caller is responsible for unrefing it with g_object_unref().
    * Use when directly setting fields in structs.
    */
-  __CNAME__* gobj_copy() const;
+  __CNAME__* gobj_copy();
 
 private:
-ifelse(__CPPPARENT__,`',`dnl Only add for Gdk::Event
-  __CNAME__* gobject_;
-')dnl
 _IMPORT(SECTION_CLASS2)
 ')
diff --git a/tools/m4/convert_gdk.m4 b/tools/m4/convert_gdk.m4
index 57c858f..c76bf90 100644
--- a/tools/m4/convert_gdk.m4
+++ b/tools/m4/convert_gdk.m4
@@ -260,17 +260,16 @@ _CONVERSION(`const Glib::ustring&', `GdkAtom', `Gdk::AtomString::to_c_type($3)')
 _CONVERSION(`Glib::ustring&',`GdkAtom',`Gdk::AtomString::to_c_type($3)')
 
 dnl GdkEvent and GdkEventSequence
-_CONVERSION(`GdkEvent*',`Event',`Glib::wrap($3)')
-_CONVERSION(`GdkEvent*',`Gdk::Event',`Glib::wrap($3)')
-_CONVERSION(`const GdkEvent*',`Gdk::Event',`Glib::wrap(const_cast<GdkEvent*>($3), true)')
-_CONVERSION(`Event&',`GdkEvent*',`($3).gobj()')
-_CONVERSION(`Gdk::Event&',`GdkEvent*',`($3).gobj()')
-_CONVERSION(`const Event&',`GdkEvent*',`const_cast<$2>(($3).gobj())')
-_CONVERSION(`const Gdk::Event&',`GdkEvent*',`const_cast<$2>(($3).gobj())')
-_CONVERSION(`const Event&',`const GdkEvent*',`($3).gobj()')
-_CONVERSION(`const Gdk::Event&',`const GdkEvent*',`($3).gobj()')
-_CONVERSION(`Gdk::EventButton&',`GdkEventButton*',`($3).gobj()')
-_CONVERSION(`Gdk::EventKey&',`GdkEventKey*',`($3).gobj()')
+_CONVERSION(`GdkEvent*',`Glib::RefPtr<Event>',`Glib::wrap($3)')
+_CONVERSION(`GdkEvent*',`Glib::RefPtr<Gdk::Event>',`Glib::wrap($3)')
+_CONVERSION(`const GdkEvent*',`Glib::RefPtr<const Gdk::Event>',`Glib::wrap(const_cast<GdkEvent*>($3))')
+_CONVERSION(`const Glib::RefPtr<Gdk::Event>&',`GdkEvent*',__CONVERT_REFPTR_TO_P)
+_CONVERSION(`const Glib::RefPtr<const Event>&',`GdkEvent*',__CONVERT_CONST_REFPTR_TO_P)
+_CONVERSION(`const Glib::RefPtr<const Gdk::Event>&',`GdkEvent*',__CONVERT_CONST_REFPTR_TO_P)
+_CONVERSION(`const Glib::RefPtr<const Event>&',`const GdkEvent*',__CONVERT_REFPTR_TO_P)
+_CONVERSION(`const Glib::RefPtr<const Gdk::Event>&',`const GdkEvent*',__CONVERT_REFPTR_TO_P)
+_CONVERSION(`const Glib::RefPtr<Gdk::EventButton>&',`GdkEventButton*',__CONVERT_REFPTR_TO_P)
+_CONVERSION(`const Glib::RefPtr<Gdk::EventKey>&',`GdkEventKey*',__CONVERT_REFPTR_TO_P)
 _CONVERSION(`Gdk::EventSequence*',`GdkEventSequence*',`reinterpret_cast<$2>($3)')
 _CONVERSION(`GdkEventSequence*',`Gdk::EventSequence*',`reinterpret_cast<$2>($3)')
 



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