include/sfx2/lokhelper.hxx        |   11 ++++++++++
 sc/source/ui/unoobj/docuno.cxx    |   39 +++++--------------------------------
 sd/source/ui/unoidl/unomodel.cxx  |   23 ++-------------------
 sfx2/source/view/lokhelper.cxx    |   40 ++++++++++++++++++++++++++++++++++++++
 sw/source/uibase/uno/unotxdoc.cxx |   22 ++------------------
 5 files changed, 63 insertions(+), 72 deletions(-)

New commits:
commit a81e957f5026373f3935390c786c21416fc74fcc
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Wed Nov 16 23:01:10 2022 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Wed Nov 16 22:15:19 2022 +0100

    lok: handle mouse/keyboard events in Math embedded in Calc
    
    And extract the identical code used in all components into
    static SfxLokHelper methods.
    
    Change-Id: I6556b1b996936835ecfc0d59e2c1dd1ef6380db2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142793
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
index b2bf16aa99ab..fb2d767b7b66 100644
--- a/include/sfx2/lokhelper.hxx
+++ b/include/sfx2/lokhelper.hxx
@@ -13,6 +13,8 @@
 #include <vcl/IDialogRenderable.hxx>
 #include <vcl/ITiledRenderable.hxx>
 #include <vcl/event.hxx>
+#include <vcl/vclptr.hxx>
+#include <vcl/window.hxx>
 #include <sfx2/dllapi.h>
 #include <sfx2/viewsh.hxx>
 #include <tools/gen.hxx>
@@ -163,6 +165,15 @@ public:
     /// This could be a new insertion or property modifications to an existing 
one.
     static void notifyMediaUpdate(boost::property_tree::ptree& json);
 
+    /// Process the mouse event in the currently active in-place component (if 
any).
+    /// Returns true if the event has been processed, and no further 
processing is necessary.
+    static bool testInPlaceComponentMouseEventHit(SfxViewShell* pViewShell, 
int nType, int nX,
+                                                  int nY, int nCount, int 
nButtons, int nModifier,
+                                                  double fScaleX, double 
fScaleY,
+                                                  bool bNegativeX = false);
+
+    static VclPtr<vcl::Window> getInPlaceDocWindow(SfxViewShell* pViewShell);
+
 private:
     static int createView(SfxViewFrame* pViewFrame, ViewShellDocId docId);
 };
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index 614eed94d891..bb8a1ce81e7b 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -635,20 +635,10 @@ VclPtr<vcl::Window> ScModelObj::getDocWindow()
     if (!pViewShell)
         return VclPtr<vcl::Window>();
 
-    ScViewData* pViewData = &pViewShell->GetViewData();
-
-    VclPtr<vcl::Window> pWindow;
-    if (pViewData)
-    {
-        pWindow = pViewData->GetActiveWin();
+    if (VclPtr<vcl::Window> pWindow = 
SfxLokHelper::getInPlaceDocWindow(pViewShell))
+        return pWindow;
 
-        LokChartHelper aChartHelper(pViewData->GetViewShell());
-        vcl::Window* pChartWindow = aChartHelper.GetWindow();
-        if (pChartWindow)
-            pWindow = pChartWindow;
-    }
-
-    return pWindow;
+    return pViewShell->GetViewData().GetActiveWin();
 }
 
 Size ScModelObj::getDocumentSize()
@@ -740,32 +730,15 @@ void ScModelObj::postMouseEvent(int nType, int nX, int 
nY, int nCount, int nButt
     if (!pGridWindow)
         return;
 
-    // check if user hit a chart which is being edited by him
-    ScTabViewShell * pTabViewShell = pViewData->GetViewShell();
     SCTAB nTab = pViewData->GetTabNo();
     const ScDocument& rDoc = pDocShell->GetDocument();
-    // In LOK RTL mode draw/svx operates in negative X coordinates
-    // But the coordinates from client is always positive, so negate nX for 
draw.
     bool bDrawNegativeX = rDoc.IsNegativePage(nTab);
-    LokChartHelper aChartHelper(pTabViewShell, bDrawNegativeX);
-    int nDrawX = bDrawNegativeX ? -nX : nX;
-    if (aChartHelper.postMouseEvent(nType, nDrawX, nY,
-                                    nCount, nButtons, nModifier,
-                                    pViewData->GetPPTX(), 
pViewData->GetPPTY()))
-    {
+    if (SfxLokHelper::testInPlaceComponentMouseEventHit(pViewShell, nType, nX, 
nY, nCount,
+                                                        nButtons, nModifier, 
pViewData->GetPPTX(),
+                                                        pViewData->GetPPTY(), 
bDrawNegativeX))
         return;
-    }
 
     Point aPointTwip(nX, nY);
-    Point aPointTwipDraw(nDrawX, nY);
-
-    // check if the user hit a chart which is being edited by someone else
-    // and, if so, skip current mouse event
-    if (nType != LOK_MOUSEEVENT_MOUSEMOVE)
-    {
-        if (LokChartHelper::HitAny(aPointTwipDraw, bDrawNegativeX))
-            return;
-    }
 
     // Check if a control is hit
     Point aPointHMM = o3tl::convert(aPointTwip, o3tl::Length::twip, 
o3tl::Length::mm100);
diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx
index db972faeb633..36688e31640b 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -2432,10 +2432,7 @@ VclPtr<vcl::Window> SdXImpressDocument::getDocWindow()
     if (!pViewShell)
         return {};
 
-    SfxViewShell* pSfxViewShell = pViewShell->GetViewShell();
-    if (VclPtr<vcl::Window> pWindow = 
LokChartHelper(pSfxViewShell).GetWindow())
-        return pWindow;
-    if (VclPtr<vcl::Window> pWindow = 
LokStarMathHelper(pSfxViewShell).GetWidgetWindow())
+    if (VclPtr<vcl::Window> pWindow = 
SfxLokHelper::getInPlaceDocWindow(pViewShell->GetViewShell()))
         return pWindow;
 
     return pViewShell->GetActiveWindow();
@@ -2605,23 +2602,9 @@ void SdXImpressDocument::postMouseEvent(int nType, int 
nX, int nY, int nCount, i
 
     constexpr double fScale = o3tl::convert(1.0, o3tl::Length::twip, 
o3tl::Length::px);
 
-    // check if user hit a chart which is being edited by him
-    LokChartHelper aChartHelper(pViewShell->GetViewShell());
-    if (aChartHelper.postMouseEvent(nType, nX, nY,
-                                    nCount, nButtons, nModifier,
-                                    fScale, fScale))
+    if (SfxLokHelper::testInPlaceComponentMouseEventHit(
+            pViewShell->GetViewShell(), nType, nX, nY, nCount, nButtons, 
nModifier, fScale, fScale))
         return;
-    if (LokStarMathHelper(pViewShell->GetViewShell())
-            .postMouseEvent(nType, nX, nY, nCount, nButtons, nModifier, 
fScale, fScale))
-        return;
-
-    // check if the user hit a chart which is being edited by someone else
-    // and, if so, skip current mouse event
-    if (nType != LOK_MOUSEEVENT_MOUSEMOVE)
-    {
-        if (LokChartHelper::HitAny(Point(nX, nY)))
-            return;
-    }
 
     const Point aPos(Point(convertTwipToMm100(nX), convertTwipToMm100(nY)));
     LokMouseEventData aMouseEventData(nType, aPos, nCount, 
MouseEventModifiers::SIMPLECLICK,
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index b6b5a7895744..7b10b7e6b7ad 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -11,6 +11,7 @@
 
 #include <string_view>
 
+#include <sfx2/lokcomponenthelpers.hxx>
 #include <sfx2/lokhelper.hxx>
 
 #include <com/sun/star/frame/Desktop.hpp>
@@ -910,4 +911,43 @@ void 
SfxLokHelper::notifyMediaUpdate(boost::property_tree::ptree& json)
     SfxLokHelper::notifyAllViews(LOK_CALLBACK_MEDIA_SHAPE, str.c_str());
 }
 
+bool SfxLokHelper::testInPlaceComponentMouseEventHit(SfxViewShell* pViewShell, 
int nType, int nX,
+                                                     int nY, int nCount, int 
nButtons,
+                                                     int nModifier, double 
fScaleX, double fScaleY,
+                                                     bool bNegativeX)
+{
+    // In LOK RTL mode draw/svx operates in negative X coordinates
+    // But the coordinates from client is always positive, so negate nX.
+    if (bNegativeX)
+        nX = -nX;
+
+    // check if the user hit a chart/math object which is being edited by this 
view
+    if (LokChartHelper aChartHelper(pViewShell, bNegativeX);
+        aChartHelper.postMouseEvent(nType, nX, nY, nCount, nButtons, 
nModifier, fScaleX, fScaleY))
+        return true;
+
+    if (LokStarMathHelper aMathHelper(pViewShell);
+        aMathHelper.postMouseEvent(nType, nX, nY, nCount, nButtons, nModifier, 
fScaleX, fScaleY))
+        return true;
+
+    // check if the user hit a chart which is being edited by someone else
+    // and, if so, skip current mouse event
+    if (nType != LOK_MOUSEEVENT_MOUSEMOVE)
+    {
+        if (LokChartHelper::HitAny({nX, nY}, bNegativeX))
+            return true;
+    }
+
+    return false;
+}
+
+VclPtr<vcl::Window> SfxLokHelper::getInPlaceDocWindow(SfxViewShell* pViewShell)
+{
+    if (VclPtr<vcl::Window> pWindow = LokChartHelper(pViewShell).GetWindow())
+        return pWindow;
+    if (VclPtr<vcl::Window> pWindow = 
LokStarMathHelper(pViewShell).GetWidgetWindow())
+        return pWindow;
+    return {};
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/uno/unotxdoc.cxx 
b/sw/source/uibase/uno/unotxdoc.cxx
index 146384c452f2..0f0fb093cb3e 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3537,9 +3537,7 @@ VclPtr<vcl::Window> SwXTextDocument::getDocWindow()
     if (!pView)
         return {};
 
-    if (VclPtr<vcl::Window> pWindow = LokChartHelper(pView).GetWindow())
-        return pWindow;
-    if (VclPtr<vcl::Window> pWindow = 
LokStarMathHelper(pView).GetWidgetWindow())
+    if (VclPtr<vcl::Window> pWindow = SfxLokHelper::getInPlaceDocWindow(pView))
         return pWindow;
 
     return &(pView->GetEditWin());
@@ -3637,24 +3635,10 @@ void SwXTextDocument::postMouseEvent(int nType, int nX, 
int nY, int nCount, int
     SwViewOption aOption(*(pWrtViewShell->GetViewOptions()));
     double fScale = aOption.GetZoom() / o3tl::convert(100.0, o3tl::Length::px, 
o3tl::Length::twip);
 
-    // check if the user hit a chart/math object which is being edited by this 
view
-    if (LokChartHelper(m_pDocShell->GetView()).postMouseEvent(nType, nX, nY,
-                                                              nCount, 
nButtons, nModifier,
-                                                              fScale, fScale))
-        return;
-    if (LokStarMathHelper(m_pDocShell->GetView()).postMouseEvent(nType, nX, nY,
-                                                                 nCount, 
nButtons, nModifier,
-                                                                 fScale, 
fScale))
+    if (SfxLokHelper::testInPlaceComponentMouseEventHit(
+            m_pDocShell->GetView(), nType, nX, nY, nCount, nButtons, 
nModifier, fScale, fScale))
         return;
 
-    // check if the user hit a chart which is being edited by someone else
-    // and, if so, skip current mouse event
-    if (nType != LOK_MOUSEEVENT_MOUSEMOVE)
-    {
-        if (LokChartHelper::HitAny(Point(nX, nY)))
-            return;
-    }
-
     SwEditWin& rEditWin = m_pDocShell->GetView()->GetEditWin();
     LokMouseEventData aMouseEventData(nType, Point(nX, nY), nCount,
                                       MouseEventModifiers::SIMPLECLICK,

Reply via email to