Blob Blame History Raw
From 44f959673e66d68d9933074157a310f2908964fe Mon Sep 17 00:00:00 2001
From: Mihai Varga <mihai.varga@collabora.com>
Date: Sun, 4 Oct 2015 19:40:13 +0300
Subject: [PATCH 175/398] LOK: added the button type and key modifier to
 postMouseEvent()

To get a better functionality we need to know the button type (left,
right, middle). We also need the key modifier (ctrl, alt, shift) for
actions such as ctrl+click (to open a link) or shift+click to select

Change-Id: Iaccb93b276f8a6870dd41cc5132dbb85d2bbf71b
(cherry picked from commit c90c08a65c480a1012182979d5e9218f17a2ba2e)
---
 desktop/source/lib/init.cxx                 |  8 ++--
 include/LibreOfficeKit/LibreOfficeKit.h     |  4 +-
 include/LibreOfficeKit/LibreOfficeKit.hxx   |  4 +-
 include/vcl/ITiledRenderable.hxx            |  2 +-
 libreofficekit/Library_libreofficekitgtk.mk |  4 ++
 libreofficekit/source/gtk/lokdocview.cxx    | 57 ++++++++++++++++++++++++++++-
 libreofficekit/source/gtk/tilebuffer.hxx    |  4 ++
 sc/inc/docuno.hxx                           |  3 +-
 sc/source/ui/unoobj/docuno.cxx              |  5 ++-
 sd/source/ui/inc/unomodel.hxx               |  3 +-
 sd/source/ui/unoidl/unomodel.cxx            |  5 ++-
 sw/inc/unotxdoc.hxx                         |  3 +-
 sw/source/uibase/uno/unotxdoc.cxx           |  4 +-
 13 files changed, 88 insertions(+), 18 deletions(-)

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index a1356aa02ca1..29e8e0d12faa 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -229,7 +229,9 @@ static void doc_postMouseEvent (LibreOfficeKitDocument* pThis,
                                 int nType,
                                 int nX,
                                 int nY,
-                                int nCount);
+                                int nCount,
+                                int nButtons,
+                                int nModifier);
 static void doc_postUnoCommand(LibreOfficeKitDocument* pThis,
                                const char* pCommand,
                                const char* pArguments);
@@ -924,7 +926,7 @@ static void doc_postUnoCommand(LibreOfficeKitDocument* /*pThis*/, const char* pC
     }
 }
 
-static void doc_postMouseEvent(LibreOfficeKitDocument* pThis, int nType, int nX, int nY, int nCount)
+static void doc_postMouseEvent(LibreOfficeKitDocument* pThis, int nType, int nX, int nY, int nCount, int nButtons, int nModifier)
 {
     ITiledRenderable* pDoc = getTiledRenderable(pThis);
     if (!pDoc)
@@ -933,7 +935,7 @@ static void doc_postMouseEvent(LibreOfficeKitDocument* pThis, int nType, int nX,
         return;
     }
 
-    pDoc->postMouseEvent(nType, nX, nY, nCount);
+    pDoc->postMouseEvent(nType, nX, nY, nCount, nButtons, nModifier);
 }
 
 static void doc_setTextSelection(LibreOfficeKitDocument* pThis, int nType, int nX, int nY)
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index d83dd49f32b5..83dcc9803d8a 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -137,7 +137,9 @@ struct _LibreOfficeKitDocumentClass
                             int nType,
                             int nX,
                             int nY,
-                            int nCount);
+                            int nCount,
+                            int nButtons,
+                            int nModifier);
 
     /// @see lok::Document::postUnoCommand
     void (*postUnoCommand) (LibreOfficeKitDocument* pThis,
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index cd12ad64f245..e9167c510110 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -192,9 +192,9 @@ public:
      * @param nY vertical position in document coordinates
      * @param nCount number of clicks: 1 for single click, 2 for double click
      */
-    inline void postMouseEvent(int nType, int nX, int nY, int nCount)
+    inline void postMouseEvent(int nType, int nX, int nY, int nCount, int nButtons, int nModifier)
     {
-        mpDoc->pClass->postMouseEvent(mpDoc, nType, nX, nY, nCount);
+        mpDoc->pClass->postMouseEvent(mpDoc, nType, nX, nY, nCount, nButtons, nModifier);
     }
 
     /**
diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx
index fd336f603296..c294d20dc9cf 100644
--- a/include/vcl/ITiledRenderable.hxx
+++ b/include/vcl/ITiledRenderable.hxx
@@ -112,7 +112,7 @@ public:
      *
      * @see lok::Document::postMouseEvent().
      */
-    virtual void postMouseEvent(int nType, int nX, int nY, int nCount) = 0;
+    virtual void postMouseEvent(int nType, int nX, int nY, int nCount, int nButtons, int nModifier) = 0;
 
     /**
      * Sets the start or end of a text selection.
diff --git a/libreofficekit/Library_libreofficekitgtk.mk b/libreofficekit/Library_libreofficekitgtk.mk
index 71a77e9e36a3..7d25abf944b1 100644
--- a/libreofficekit/Library_libreofficekitgtk.mk
+++ b/libreofficekit/Library_libreofficekitgtk.mk
@@ -16,6 +16,10 @@ $(eval $(call gb_Library_add_exception_objects,libreofficekitgtk,\
     libreofficekit/source/gtk/tilebuffer \
 ))
 
+$(eval $(call gb_Library_use_externals,libreofficekitgtk,\
+    boost_headers \
+))
+
 $(eval $(call gb_Library_add_cxxflags,libreofficekitgtk,\
     $$(GTK3_CFLAGS) \
 ))
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 3aa4cabeb76c..0bd735088586 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -20,6 +20,7 @@
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
 #include <LibreOfficeKit/LibreOfficeKitGtk.h>
 #include <rsc/rsc-vcl-shared-types.hxx>
+#include <vcl/event.hxx>
 
 #include "tilebuffer.hxx"
 
@@ -66,6 +67,10 @@ struct _LOKDocViewPrivate
     guint32 m_nLastButtonPressTime;
     /// Time of the last button release.
     guint32 m_nLastButtonReleaseTime;
+    /// Last pressed button (left, right, middle)
+    guint32 m_nLastButtonPressed;
+    /// Key modifier (ctrl, atl, shift)
+    guint32 m_nKeyModifier;
     /// Rectangles of the current text selection.
     std::vector<GdkRectangle> m_aTextSelectionRectangles;
     /// Position and size of the selection start (as if there would be a cursor caret there).
@@ -267,6 +272,7 @@ signalKey (GtkWidget* pWidget, GdkEventKey* pEvent)
         return FALSE;
     }
 
+    priv->m_nKeyModifier = 0;
     switch (pEvent->keyval)
     {
     case GDK_KEY_BackSpace:
@@ -296,6 +302,21 @@ signalKey (GtkWidget* pWidget, GdkEventKey* pEvent)
     case GDK_KEY_Right:
         nKeyCode = com::sun::star::awt::Key::RIGHT;
         break;
+    case GDK_KEY_Shift_L:
+    case GDK_KEY_Shift_R:
+        if (pEvent->type == GDK_KEY_PRESS)
+            priv->m_nKeyModifier |= KEY_SHIFT;
+        break;
+    case GDK_KEY_Control_L:
+    case GDK_KEY_Control_R:
+        if (pEvent->type == GDK_KEY_PRESS)
+            priv->m_nKeyModifier |= KEY_MOD1;
+        break;
+    case GDK_KEY_Alt_L:
+    case GDK_KEY_Alt_R:
+        if (pEvent->type == GDK_KEY_PRESS)
+            priv->m_nKeyModifier |= KEY_MOD2;
+        break;
     default:
         if (pEvent->keyval >= GDK_KEY_F1 && pEvent->keyval <= GDK_KEY_F26)
             nKeyCode = com::sun::star::awt::Key::F1 + (pEvent->keyval - GDK_KEY_F1);
@@ -309,7 +330,6 @@ signalKey (GtkWidget* pWidget, GdkEventKey* pEvent)
     if (pEvent->state & GDK_SHIFT_MASK)
         nKeyCode |= KEY_SHIFT;
 
-
     if (pEvent->type == GDK_KEY_RELEASE)
     {
         GTask* task = g_task_new(pDocView, NULL, NULL, NULL);
@@ -1060,6 +1080,20 @@ lok_doc_view_signal_button(GtkWidget* pWidget, GdkEventButton* pEvent)
         pLOEvent->m_nPostMouseEventX = pixelToTwip(pEvent->x, priv->m_fZoom);
         pLOEvent->m_nPostMouseEventY = pixelToTwip(pEvent->y, priv->m_fZoom);
         pLOEvent->m_nPostMouseEventCount = nCount;
+        switch (pEvent->button)
+        {
+        case 1:
+            pLOEvent->m_nPostMouseEventButton = MOUSE_LEFT;
+            break;
+        case 2:
+            pLOEvent->m_nPostMouseEventButton = MOUSE_MIDDLE;
+            break;
+        case 3:
+            pLOEvent->m_nPostMouseEventButton = MOUSE_RIGHT;
+            break;
+        }
+        pLOEvent->m_nPostMouseEventModifier = priv->m_nKeyModifier;
+        priv->m_nLastButtonPressed = pLOEvent->m_nPostMouseEventButton;
         g_task_set_task_data(task, pLOEvent, LOEvent::destroy);
 
         g_thread_pool_push(priv->lokThreadPool, g_object_ref(task), NULL);
@@ -1078,6 +1112,20 @@ lok_doc_view_signal_button(GtkWidget* pWidget, GdkEventButton* pEvent)
         pLOEvent->m_nPostMouseEventX = pixelToTwip(pEvent->x, priv->m_fZoom);
         pLOEvent->m_nPostMouseEventY = pixelToTwip(pEvent->y, priv->m_fZoom);
         pLOEvent->m_nPostMouseEventCount = nCount;
+        switch (pEvent->button)
+        {
+        case 1:
+            pLOEvent->m_nPostMouseEventButton = MOUSE_LEFT;
+            break;
+        case 2:
+            pLOEvent->m_nPostMouseEventButton = MOUSE_MIDDLE;
+            break;
+        case 3:
+            pLOEvent->m_nPostMouseEventButton = MOUSE_RIGHT;
+            break;
+        }
+        pLOEvent->m_nPostMouseEventModifier = priv->m_nKeyModifier;
+        priv->m_nLastButtonPressed = pLOEvent->m_nPostMouseEventButton;
         g_task_set_task_data(task, pLOEvent, LOEvent::destroy);
 
         g_thread_pool_push(priv->lokThreadPool, g_object_ref(task), NULL);
@@ -1182,6 +1230,9 @@ lok_doc_view_signal_motion (GtkWidget* pWidget, GdkEventMotion* pEvent)
     pLOEvent->m_nPostMouseEventX = pixelToTwip(pEvent->x, priv->m_fZoom);
     pLOEvent->m_nPostMouseEventY = pixelToTwip(pEvent->y, priv->m_fZoom);
     pLOEvent->m_nPostMouseEventCount = 1;
+    pLOEvent->m_nPostMouseEventButton = priv->m_nLastButtonPressed;
+    pLOEvent->m_nPostMouseEventModifier = priv->m_nKeyModifier;
+
     g_task_set_task_data(task, pLOEvent, LOEvent::destroy);
 
     g_thread_pool_push(priv->lokThreadPool, g_object_ref(task), NULL);
@@ -1218,7 +1269,9 @@ postMouseEventInThread(gpointer data)
                                               pLOEvent->m_nPostMouseEventType,
                                               pLOEvent->m_nPostMouseEventX,
                                               pLOEvent->m_nPostMouseEventY,
-                                              pLOEvent->m_nPostMouseEventCount);
+                                              pLOEvent->m_nPostMouseEventCount,
+                                              pLOEvent->m_nPostMouseEventButton,
+                                              pLOEvent->m_nPostMouseEventModifier);
 }
 
 static void
diff --git a/libreofficekit/source/gtk/tilebuffer.hxx b/libreofficekit/source/gtk/tilebuffer.hxx
index fdcdd15eddd7..34b9001e8bc5 100644
--- a/libreofficekit/source/gtk/tilebuffer.hxx
+++ b/libreofficekit/source/gtk/tilebuffer.hxx
@@ -204,6 +204,8 @@ struct LOEvent
     int m_nPostMouseEventX;
     int m_nPostMouseEventY;
     int m_nPostMouseEventCount;
+    int m_nPostMouseEventButton;
+    int m_nPostMouseEventModifier;
     ///@}
 
     /// @name setGraphicSelection parameters
@@ -232,6 +234,8 @@ struct LOEvent
         , m_nPostMouseEventX(0)
         , m_nPostMouseEventY(0)
         , m_nPostMouseEventCount(0)
+        , m_nPostMouseEventButton(0)
+        , m_nPostMouseEventModifier(0)
         , m_nSetGraphicSelectionType(0)
         , m_nSetGraphicSelectionX(0)
         , m_nSetGraphicSelectionY(0)
diff --git a/sc/inc/docuno.hxx b/sc/inc/docuno.hxx
index cd6888598f69..cc132278bdf8 100644
--- a/sc/inc/docuno.hxx
+++ b/sc/inc/docuno.hxx
@@ -54,6 +54,7 @@
 #include <cppuhelper/implbase5.hxx>
 #include <cppuhelper/interfacecontainer.h>
 #include <svl/itemprop.hxx>
+#include <vcl/event.hxx>
 #include <vcl/ITiledRenderable.hxx>
 #include "drwlayer.hxx"
 
@@ -401,7 +402,7 @@ public:
     virtual void postKeyEvent(int nType, int nCharCode, int nKeyCode) SAL_OVERRIDE;
 
     /// @see vcl::ITiledRenderable::postMouseEvent().
-    virtual void postMouseEvent(int nType, int nX, int nY, int nCount) SAL_OVERRIDE;
+    virtual void postMouseEvent(int nType, int nX, int nY, int nCount, int nButtons = MOUSE_LEFT, int nModifier = 0) SAL_OVERRIDE;
 
     /// @see vcl::ITiledRenderable::setTextSelection().
     virtual void setTextSelection(int nType, int nX, int nY) SAL_OVERRIDE;
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index 1a59f887b7d7..958495f7ea7b 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -591,7 +591,7 @@ void ScModelObj::postKeyEvent(int nType, int nCharCode, int nKeyCode)
     }
 }
 
-void ScModelObj::postMouseEvent(int nType, int nX, int nY, int nCount)
+void ScModelObj::postMouseEvent(int nType, int nX, int nY, int nCount, int nButtons, int nModifier)
 {
     SolarMutexGuard aGuard;
 
@@ -607,7 +607,8 @@ void ScModelObj::postMouseEvent(int nType, int nX, int nY, int nCount)
     pViewData->SetZoom(Fraction(1, 1), Fraction(1, 1), true);
 
     // Calc operates in pixels...
-    MouseEvent aEvent(Point(nX * pViewData->GetPPTX(), nY * pViewData->GetPPTY()), nCount, MouseEventModifiers::SIMPLECLICK, MOUSE_LEFT);
+    MouseEvent aEvent(Point(nX * pViewData->GetPPTX(), nY * pViewData->GetPPTY()), nCount,
+            MouseEventModifiers::SIMPLECLICK, nButtons, nModifier);
 
     switch (nType)
     {
diff --git a/sd/source/ui/inc/unomodel.hxx b/sd/source/ui/inc/unomodel.hxx
index 009fb672cf27..4d7314875f0b 100644
--- a/sd/source/ui/inc/unomodel.hxx
+++ b/sd/source/ui/inc/unomodel.hxx
@@ -45,6 +45,7 @@
 #include <sfx2/sfxbasemodel.hxx>
 #include <svx/fmdmod.hxx>
 
+#include <vcl/event.hxx>
 #include <vcl/ITiledRenderable.hxx>
 
 #include <editeng/unoipset.hxx>
@@ -248,7 +249,7 @@ public:
     /// @see vcl::ITiledRenderable::postKeyEvent().
     virtual void postKeyEvent(int nType, int nCharCode, int nKeyCode) SAL_OVERRIDE;
     /// @see vcl::ITiledRenderable::postMouseEvent().
-    virtual void postMouseEvent(int nType, int nX, int nY, int nCount) SAL_OVERRIDE;
+    virtual void postMouseEvent(int nType, int nX, int nY, int nCount, int nButtons = MOUSE_LEFT, int nModifier = 0) SAL_OVERRIDE;
     /// @see vcl::ITiledRenderable::setTextSelection().
     virtual void setTextSelection(int nType, int nX, int nY) SAL_OVERRIDE;
     /// @see vcl::ITiledRenderable::getTextSelection().
diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx
index 0e88a099e081..6ae01a28efac 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -2428,7 +2428,7 @@ void SdXImpressDocument::postKeyEvent(int nType, int nCharCode, int nKeyCode)
     }
 }
 
-void SdXImpressDocument::postMouseEvent(int nType, int nX, int nY, int nCount)
+void SdXImpressDocument::postMouseEvent(int nType, int nX, int nY, int nCount, int nButtons, int nModifier)
 {
     SolarMutexGuard aGuard;
 
@@ -2436,7 +2436,8 @@ void SdXImpressDocument::postMouseEvent(int nType, int nX, int nY, int nCount)
     if (!pViewShell)
         return;
 
-    MouseEvent aEvent(Point(convertTwipToMm100(nX), convertTwipToMm100(nY)), nCount, MouseEventModifiers::SIMPLECLICK, MOUSE_LEFT);
+    MouseEvent aEvent(Point(convertTwipToMm100(nX), convertTwipToMm100(nY)), nCount,
+            MouseEventModifiers::SIMPLECLICK, nButtons, nModifier);
 
     switch (nType)
     {
diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx
index 311147eeaaea..346cab63ca02 100644
--- a/sw/inc/unotxdoc.hxx
+++ b/sw/inc/unotxdoc.hxx
@@ -66,6 +66,7 @@
 #include <editeng/UnoForbiddenCharsTable.hxx>
 #include <cppuhelper/weak.hxx>
 #include <cppuhelper/implbase.hxx>
+#include <vcl/event.hxx>
 #include <vcl/ITiledRenderable.hxx>
 #include <com/sun/star/tiledrendering/XTiledRenderable.hpp>
 
@@ -422,7 +423,7 @@ public:
     /// @see vcl::ITiledRenderable::postKeyEvent().
     virtual void postKeyEvent(int nType, int nCharCode, int nKeyCode) SAL_OVERRIDE;
     /// @see vcl::ITiledRenderable::postMouseEvent().
-    virtual void postMouseEvent(int nType, int nX, int nY, int nCount) SAL_OVERRIDE;
+    virtual void postMouseEvent(int nType, int nX, int nY, int nCount, int nButtons = MOUSE_LEFT, int nModifier = 0) SAL_OVERRIDE;
     /// @see vcl::ITiledRenderable::setTextSelection().
     virtual void setTextSelection(int nType, int nX, int nY) SAL_OVERRIDE;
     /// @see vcl::ITiledRenderable::getTextSelection().
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index 26ab19f170b9..fc1c6f411b74 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3282,12 +3282,12 @@ void SwXTextDocument::postKeyEvent(int nType, int nCharCode, int nKeyCode)
     }
 }
 
-void SwXTextDocument::postMouseEvent(int nType, int nX, int nY, int nCount)
+void SwXTextDocument::postMouseEvent(int nType, int nX, int nY, int nCount, int nButtons, int nModifier)
 {
     SolarMutexGuard aGuard;
 
     SwEditWin& rEditWin = pDocShell->GetView()->GetEditWin();
-    MouseEvent aEvent(Point(nX, nY), nCount, MouseEventModifiers::SIMPLECLICK, MOUSE_LEFT);
+    MouseEvent aEvent(Point(nX, nY), nCount, MouseEventModifiers::SIMPLECLICK, nButtons, nModifier);
 
     switch (nType)
     {
-- 
2.12.0