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

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Wed Oct 2 12:22:41 UTC 2019


 vcl/inc/unx/gtk/gtkframe.hxx  |    1 
 vcl/unx/gtk3/gtk3gtkframe.cxx |   62 +++++++++++++++++++++++-------------------
 vcl/unx/gtk3/gtk3gtkinst.cxx  |   35 +++++++++++++++++++++++
 3 files changed, 70 insertions(+), 28 deletions(-)

New commits:
commit 1db70eadd41048da0d421bcc5eba1fc0443f253a
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Wed Oct 2 11:02:42 2019 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Wed Oct 2 14:21:12 2019 +0200

    add wheel events to drawing area
    
    Change-Id: I6071a2af3cbb01c4f21c45e289f779adc49e0dc2
    Reviewed-on: https://gerrit.libreoffice.org/80022
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/vcl/inc/unx/gtk/gtkframe.hxx b/vcl/inc/unx/gtk/gtkframe.hxx
index f9a41c6c3cf6..fc4831a23092 100644
--- a/vcl/inc/unx/gtk/gtkframe.hxx
+++ b/vcl/inc/unx/gtk/gtkframe.hxx
@@ -525,6 +525,7 @@ public:
     static guint                GetKeyValFor(GdkKeymap* pKeyMap, guint16 hardware_keycode, guint8 group);
     static sal_uInt16           GetKeyModCode(guint nState);
     static GdkEvent*            makeFakeKeyPress(GtkWidget* pWidget);
+    static SalWheelMouseEvent   GetWheelEvent(GdkEventScroll& rEvent);
 };
 
 #define OOO_TYPE_FIXED ooo_fixed_get_type()
diff --git a/vcl/unx/gtk3/gtk3gtkframe.cxx b/vcl/unx/gtk3/gtk3gtkframe.cxx
index 0b1065b13147..625e5cdf51f9 100644
--- a/vcl/unx/gtk3/gtk3gtkframe.cxx
+++ b/vcl/unx/gtk3/gtk3gtkframe.cxx
@@ -2655,35 +2655,12 @@ IMPL_LINK_NOARG(GtkSalFrame, AsyncScroll, Timer *, void)
     }
 }
 
-gboolean GtkSalFrame::signalScroll(GtkWidget*, GdkEvent* pInEvent, gpointer frame)
+SalWheelMouseEvent GtkSalFrame::GetWheelEvent(GdkEventScroll& rEvent)
 {
-    GdkEventScroll& rEvent = pInEvent->scroll;
-
-    UpdateLastInputEventTime(rEvent.time);
-
-    GtkSalFrame* pThis = static_cast<GtkSalFrame*>(frame);
-
-    if (rEvent.direction == GDK_SCROLL_SMOOTH)
-    {
-        pThis->LaunchAsyncScroll(pInEvent);
-        return true;
-    }
-
-    //if we have smooth scrolling previous pending states, flush that queue now
-    if (!pThis->m_aPendingScrollEvents.empty())
-    {
-        pThis->m_aSmoothScrollIdle.Stop();
-        pThis->m_aSmoothScrollIdle.Invoke();
-        assert(pThis->m_aPendingScrollEvents.empty());
-    }
-
     SalWheelMouseEvent aEvent;
 
     aEvent.mnTime = rEvent.time;
     aEvent.mnX = static_cast<sal_uLong>(rEvent.x);
-    // --- RTL --- (mirror mouse pos)
-    if (AllSettings::GetLayoutRTL())
-        aEvent.mnX = pThis->maGeometry.nWidth - 1 - aEvent.mnX;
     aEvent.mnY = static_cast<sal_uLong>(rEvent.y);
     aEvent.mnCode = GetMouseModCode(rEvent.state);
 
@@ -2694,7 +2671,6 @@ gboolean GtkSalFrame::signalScroll(GtkWidget*, GdkEvent* pInEvent, gpointer fram
             aEvent.mnNotchDelta = 1;
             aEvent.mnScrollLines = 3;
             aEvent.mbHorz = false;
-            pThis->CallCallbackExc(SalEvent::WheelMouse, &aEvent);
             break;
 
         case GDK_SCROLL_DOWN:
@@ -2702,7 +2678,6 @@ gboolean GtkSalFrame::signalScroll(GtkWidget*, GdkEvent* pInEvent, gpointer fram
             aEvent.mnNotchDelta = -1;
             aEvent.mnScrollLines = 3;
             aEvent.mbHorz = false;
-            pThis->CallCallbackExc(SalEvent::WheelMouse, &aEvent);
             break;
 
         case GDK_SCROLL_LEFT:
@@ -2710,7 +2685,6 @@ gboolean GtkSalFrame::signalScroll(GtkWidget*, GdkEvent* pInEvent, gpointer fram
             aEvent.mnNotchDelta = 1;
             aEvent.mnScrollLines = 3;
             aEvent.mbHorz = true;
-            pThis->CallCallbackExc(SalEvent::WheelMouse, &aEvent);
             break;
 
         case GDK_SCROLL_RIGHT:
@@ -2718,12 +2692,44 @@ gboolean GtkSalFrame::signalScroll(GtkWidget*, GdkEvent* pInEvent, gpointer fram
             aEvent.mnNotchDelta = -1;
             aEvent.mnScrollLines = 3;
             aEvent.mbHorz = true;
-            pThis->CallCallbackExc(SalEvent::WheelMouse, &aEvent);
             break;
         default:
             break;
     }
 
+    return aEvent;
+}
+
+gboolean GtkSalFrame::signalScroll(GtkWidget*, GdkEvent* pInEvent, gpointer frame)
+{
+    GdkEventScroll& rEvent = pInEvent->scroll;
+
+    UpdateLastInputEventTime(rEvent.time);
+
+    GtkSalFrame* pThis = static_cast<GtkSalFrame*>(frame);
+
+    if (rEvent.direction == GDK_SCROLL_SMOOTH)
+    {
+        pThis->LaunchAsyncScroll(pInEvent);
+        return true;
+    }
+
+    //if we have smooth scrolling previous pending states, flush that queue now
+    if (!pThis->m_aPendingScrollEvents.empty())
+    {
+        pThis->m_aSmoothScrollIdle.Stop();
+        pThis->m_aSmoothScrollIdle.Invoke();
+        assert(pThis->m_aPendingScrollEvents.empty());
+    }
+
+    SalWheelMouseEvent aEvent(GetWheelEvent(rEvent));
+
+    // --- RTL --- (mirror mouse pos)
+    if (AllSettings::GetLayoutRTL())
+        aEvent.mnX = pThis->maGeometry.nWidth - 1 - aEvent.mnX;
+
+    pThis->CallCallbackExc(SalEvent::WheelMouse, &aEvent);
+
     return true;
 }
 
diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx
index 70d743541ede..e31fb2371bb3 100644
--- a/vcl/unx/gtk3/gtk3gtkinst.cxx
+++ b/vcl/unx/gtk3/gtk3gtkinst.cxx
@@ -9753,6 +9753,7 @@ private:
     gulong m_nStyleUpdatedSignalId;
     gulong m_nQueryTooltip;
     gulong m_nPopupMenu;
+    gulong m_nScrollEvent;
 
     static gboolean signalDraw(GtkWidget*, cairo_t* cr, gpointer widget)
     {
@@ -9822,6 +9823,38 @@ private:
     {
         return m_aCommandHdl.Call(rCEvt);
     }
+    bool signal_scroll(GdkEventScroll* pEvent)
+    {
+        SalWheelMouseEvent aEvt(GtkSalFrame::GetWheelEvent(*pEvent));
+
+        if (AllSettings::GetLayoutRTL())
+            aEvt.mnX = gtk_widget_get_allocated_width(m_pWidget) - 1 - aEvt.mnX;
+
+        CommandWheelMode nMode;
+        sal_uInt16 nCode = aEvt.mnCode;
+        bool bHorz = aEvt.mbHorz;
+        if (nCode & KEY_MOD1)
+            nMode = CommandWheelMode::ZOOM;
+        else if (nCode & KEY_MOD2)
+            nMode = CommandWheelMode::DATAZOOM;
+        else
+        {
+            nMode = CommandWheelMode::SCROLL;
+            // #i85450# interpret shift-wheel as horizontal wheel action
+            if( (nCode & (KEY_SHIFT | KEY_MOD1 | KEY_MOD2 | KEY_MOD3)) == KEY_SHIFT )
+                bHorz = true;
+        }
+
+        CommandWheelData aWheelData(aEvt.mnDelta, aEvt.mnNotchDelta, aEvt.mnScrollLines,
+                                    nMode, nCode, bHorz, aEvt.mbDeltaIsPixel);
+        CommandEvent aCEvt(Point(aEvt.mnX, aEvt.mnY), CommandEventId::Wheel, true, &aWheelData);
+        return m_aCommandHdl.Call(aCEvt);
+    }
+    static gboolean signalScroll(GtkWidget*, GdkEventScroll* pEvent, gpointer widget)
+    {
+        GtkInstanceDrawingArea* pThis = static_cast<GtkInstanceDrawingArea*>(widget);
+        return pThis->signal_scroll(pEvent);
+    }
 public:
     GtkInstanceDrawingArea(GtkDrawingArea* pDrawingArea, GtkInstanceBuilder* pBuilder, const a11yref& rA11y, bool bTakeOwnership)
         : GtkInstanceWidget(GTK_WIDGET(pDrawingArea), pBuilder, bTakeOwnership)
@@ -9834,6 +9867,7 @@ public:
         , m_nStyleUpdatedSignalId(g_signal_connect(m_pDrawingArea,"style-updated", G_CALLBACK(signalStyleUpdated), this))
         , m_nQueryTooltip(g_signal_connect(m_pDrawingArea, "query-tooltip", G_CALLBACK(signalQueryTooltip), this))
         , m_nPopupMenu(g_signal_connect(m_pDrawingArea, "popup-menu", G_CALLBACK(signalPopupMenu), this))
+        , m_nScrollEvent(g_signal_connect(m_pDrawingArea, "scroll-event", G_CALLBACK(signalScroll), this))
     {
         gtk_widget_set_has_tooltip(m_pWidget, true);
         g_object_set_data(G_OBJECT(m_pDrawingArea), "g-lo-GtkInstanceDrawingArea", this);
@@ -9939,6 +9973,7 @@ public:
         css::uno::Reference<css::lang::XComponent> xComp(m_xAccessible, css::uno::UNO_QUERY);
         if (xComp.is())
             xComp->dispose();
+        g_signal_handler_disconnect(m_pDrawingArea, m_nScrollEvent);
         g_signal_handler_disconnect(m_pDrawingArea, m_nPopupMenu);
         g_signal_handler_disconnect(m_pDrawingArea, m_nQueryTooltip);
         g_signal_handler_disconnect(m_pDrawingArea, m_nStyleUpdatedSignalId);


More information about the Libreoffice-commits mailing list