[Libreoffice-commits] core.git: vcl/inc vcl/unx

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Tue Jul 6 15:48:36 UTC 2021


 vcl/inc/unx/gtk/gtkobject.hxx |   10 +++++++++-
 vcl/unx/gtk3/gtkobject.cxx    |   37 +++++++++++++++++++++++++++++++++----
 2 files changed, 42 insertions(+), 5 deletions(-)

New commits:
commit 406ea1528d47d1ccaf64827f8ba0d24f229147d7
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Tue Jul 6 15:10:17 2021 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Tue Jul 6 17:48:01 2021 +0200

    gtk4: update GtkSalObjectWidgetClip with new scrolling controller
    
    Change-Id: I729584b71cf8d0a507b97fce96add66fb22508a3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118513
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/vcl/inc/unx/gtk/gtkobject.hxx b/vcl/inc/unx/gtk/gtkobject.hxx
index ee063873980a..113868a4616c 100644
--- a/vcl/inc/unx/gtk/gtkobject.hxx
+++ b/vcl/inc/unx/gtk/gtkobject.hxx
@@ -84,10 +84,18 @@ class GtkSalObjectWidgetClip final : public GtkSalObjectBase
     GtkWidget* m_pScrolledWindow;
 
     // signals
-    static gboolean     signalScroll( GtkWidget*, GdkEvent*, gpointer );
+#if !GTK_CHECK_VERSION(4, 0, 0)
+    static gboolean     signalScroll(GtkWidget*, GdkEvent*, gpointer);
+#else
+    static gboolean     signalScroll(GtkEventControllerScroll* pController, double delta_x, double delta_y, gpointer object);
+#endif
     static void         signalDestroy( GtkWidget*, gpointer );
 
+#if !GTK_CHECK_VERSION(4, 0, 0)
     bool signal_scroll(GtkWidget* pScrolledWindow, GdkEvent* pEvent);
+#else
+    bool signal_scroll(GtkEventControllerScroll* pController, double delta_x, double delta_y);
+#endif
 
     void ApplyClipRegion();
 public:
diff --git a/vcl/unx/gtk3/gtkobject.cxx b/vcl/unx/gtk3/gtkobject.cxx
index fbe5a7c39a75..3b9757650e53 100644
--- a/vcl/unx/gtk3/gtkobject.cxx
+++ b/vcl/unx/gtk3/gtkobject.cxx
@@ -302,12 +302,15 @@ GtkSalObjectWidgetClip::GtkSalObjectWidgetClip(GtkSalFrame* pParent, bool bShow)
 
 #if !GTK_CHECK_VERSION(4, 0, 0)
     m_pScrolledWindow = gtk_scrolled_window_new(nullptr, nullptr);
+    g_signal_connect(m_pScrolledWindow, "scroll-event", G_CALLBACK(signalScroll), this);
 #else
     m_pScrolledWindow = gtk_scrolled_window_new();
+    GtkEventController* pScrollController = gtk_event_controller_scroll_new(GTK_EVENT_CONTROLLER_SCROLL_BOTH_AXES);
+    g_signal_connect(pScrollController, "scroll", G_CALLBACK(signalScroll), this);
+    gtk_widget_add_controller(m_pScrolledWindow, pScrollController);
 #endif
     gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(m_pScrolledWindow),
                                    GTK_POLICY_EXTERNAL, GTK_POLICY_EXTERNAL);
-    g_signal_connect(m_pScrolledWindow, "scroll-event", G_CALLBACK(signalScroll), this);
 
     // insert into container
     gtk_fixed_put( pParent->getFixedContainer(),
@@ -524,16 +527,24 @@ void GtkSalObjectWidgetClip::signalDestroy( GtkWidget* pObj, gpointer object )
     }
 }
 
+#if !GTK_CHECK_VERSION(4, 0, 0)
 gboolean GtkSalObjectWidgetClip::signalScroll(GtkWidget* pScrolledWindow, GdkEvent* pEvent, gpointer object)
 {
     GtkSalObjectWidgetClip* pThis = static_cast<GtkSalObjectWidgetClip*>(object);
     return pThis->signal_scroll(pScrolledWindow, pEvent);
 }
+#else
+gboolean GtkSalObjectWidgetClip::signalScroll(GtkEventControllerScroll* pController, double delta_x, double delta_y, gpointer object)
+{
+    GtkSalObjectWidgetClip* pThis = static_cast<GtkSalObjectWidgetClip*>(object);
+    return pThis->signal_scroll(pController, delta_x, delta_y);
+}
+#endif
 
 // forward the wheel scroll events onto the main window instead
+#if !GTK_CHECK_VERSION(4, 0, 0)
 bool GtkSalObjectWidgetClip::signal_scroll(GtkWidget*, GdkEvent* pEvent)
 {
-#if !GTK_CHECK_VERSION(4, 0, 0)
     GtkWidget* pEventWidget = gtk_get_event_widget(pEvent);
 
     GtkWidget* pMouseEventWidget = m_pParent->getMouseEventWidget();
@@ -549,10 +560,28 @@ bool GtkSalObjectWidgetClip::signal_scroll(GtkWidget*, GdkEvent* pEvent)
     pEvent->scroll.y = dest_y;
 
     GtkSalFrame::signalScroll(pMouseEventWidget, pEvent, m_pParent);
+    return true;
+}
 #else
-    (void)pEvent;
-#endif
+bool GtkSalObjectWidgetClip::signal_scroll(GtkEventControllerScroll* pController, double delta_x, double delta_y)
+{
+    GtkWidget* pEventWidget = m_pScrolledWindow;
+
+    GtkWidget* pMouseEventWidget = m_pParent->getMouseEventWidget();
+
+    gtk_coord dest_x, dest_y;
+    gtk_widget_translate_coordinates(pEventWidget,
+                                     pMouseEventWidget,
+                                     delta_x,
+                                     delta_y,
+                                     &dest_x,
+                                     &dest_y);
+    delta_x = dest_x;
+    delta_y = dest_y;
+
+    GtkSalFrame::signalScroll(pController, delta_x, delta_y, m_pParent);
     return true;
 }
+#endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list