summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2020-01-29 12:44:30 +0100
committerMichael Meeks <michael.meeks@collabora.com>2020-05-27 22:12:01 +0100
commit208491052f597bec8c16db9f467f07836c364551 (patch)
tree44591ae8724fd86b5fe7df287bb487c069013bc1
parentaa8c235386dd4075cd25ec38f7a09eb1e7877b32 (diff)
lok: preserve mouse event logic position and use in calc
When clicking in online Calc any of the charts, shapes (and other objects), sometimes the cell underneath is selected instead. The problem is that the object is not correctly recognised to be hit. From lok we get the mouse event position in logic coordinates, which we usually can just use in writer and impress. In calc however we need the coordinates in pixels, so we transform them before sending the mouse event to calc. Still calc also uses common SdrObjects (chart, shapes,...), which operate in logic coordinates. So in case of SdrObject we need to convert the coordniates back from pixel to logic again, which causes problems because conversion doesn't have access to the displaying conditions on an stateless online client. OTOH we already had the correct logic coordinates, and we can just send them along. This is what this change does. It adds an optional maLogicPosition to MouseEvent, which is filled with logic position if those is known. Change-Id: I26f6466085baf613850b5861e368f22cad7c1d26 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87681 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r--include/sfx2/lokhelper.hxx26
-rw-r--r--include/vcl/event.hxx15
-rw-r--r--sc/source/ui/drawfunc/fusel.cxx7
-rw-r--r--sc/source/ui/unoobj/docuno.cxx6
-rw-r--r--sd/source/ui/unoidl/unomodel.cxx5
-rw-r--r--sfx2/source/view/lokcharthelper.cxx5
-rw-r--r--sfx2/source/view/lokhelper.cxx18
-rw-r--r--sw/source/uibase/uno/unotxdoc.cxx4
8 files changed, 62 insertions, 24 deletions
diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
index 30cc22b340b4..ded6e36cc821 100644
--- a/include/sfx2/lokhelper.hxx
+++ b/include/sfx2/lokhelper.hxx
@@ -17,6 +17,27 @@
#include <sfx2/viewsh.hxx>
#include <cstddef>
#include <rtl/string.hxx>
+#include <o3tl/optional.hxx>
+
+struct SFX2_DLLPUBLIC LokMouseEventData
+{
+ int mnType;
+ Point maPosition;
+ int mnCount;
+ MouseEventModifiers meModifiers;
+ int mnButtons;
+ int mnModifier;
+ o3tl::optional<Point> maLogicPosition;
+
+ LokMouseEventData(int nType, Point aPosition, int nCount, MouseEventModifiers eModifiers, int nButtons, int nModifier)
+ : mnType(nType)
+ , maPosition(aPosition)
+ , mnCount(nCount)
+ , meModifiers(eModifiers)
+ , mnButtons(nButtons)
+ , mnModifier(nModifier)
+ {}
+};
class SFX2_DLLPUBLIC SfxLokHelper
{
@@ -72,10 +93,7 @@ public:
int nType, const OUString &rText);
/// Helper for posting async mouse event
- static void postMouseEventAsync(const VclPtr<vcl::Window> &xWindow,
- int nType, const Point &rPos,
- int nCount, MouseEventModifiers aModifiers,
- int nButtons, int nModifier);
+ static void postMouseEventAsync(const VclPtr<vcl::Window> &xWindow, LokMouseEventData const & rLokMouseEventData);
/// A special value to signify 'infinity'.
/// This value is chosen such that sal_Int32 will not overflow when manipulated.
diff --git a/include/vcl/event.hxx b/include/vcl/event.hxx
index bd0b5589f375..900838d11b5c 100644
--- a/include/vcl/event.hxx
+++ b/include/vcl/event.hxx
@@ -27,6 +27,7 @@
#include <vcl/vclptr.hxx>
#include <vcl/outdev.hxx>
#include <vcl/window.hxx>
+#include <o3tl/optional.hxx>
class CommandEvent;
@@ -99,7 +100,6 @@ namespace o3tl
#define MOUSE_MIDDLE (sal_uInt16(0x0002))
#define MOUSE_RIGHT (sal_uInt16(0x0004))
-
class VCL_DLLPUBLIC MouseEvent
{
private:
@@ -108,6 +108,9 @@ private:
sal_uInt16 mnClicks;
sal_uInt16 mnCode;
+ // Set, if the document relative logic position are available
+ o3tl::optional<Point> maLogicPosition;
+
public:
explicit MouseEvent();
explicit MouseEvent( const Point& rPos, sal_uInt16 nClicks = 1,
@@ -119,6 +122,16 @@ public:
sal_uInt16 GetClicks() const { return mnClicks; }
+ void setLogicPosition(Point aLogicPosition)
+ {
+ maLogicPosition = aLogicPosition;
+ }
+
+ o3tl::optional<Point> getLogicPosition() const
+ {
+ return maLogicPosition;
+ }
+
bool IsEnterWindow() const
{ return bool(mnMode & MouseEventModifiers::ENTERWINDOW); }
bool IsLeaveWindow() const
diff --git a/sc/source/ui/drawfunc/fusel.cxx b/sc/source/ui/drawfunc/fusel.cxx
index caffb9c1410b..bb82aa3459bd 100644
--- a/sc/source/ui/drawfunc/fusel.cxx
+++ b/sc/source/ui/drawfunc/fusel.cxx
@@ -78,8 +78,11 @@ bool FuSelection::MouseButtonDown(const MouseEvent& rMEvt)
bIsInDragMode = false; // somewhere it has to be reset (#50033#)
bool bReturn = FuDraw::MouseButtonDown(rMEvt);
-
- aMDPos = pWindow->PixelToLogic( rMEvt.GetPosPixel() );
+ auto aLogicPosition = rMEvt.getLogicPosition();
+ if (aLogicPosition)
+ aMDPos = *aLogicPosition;
+ else
+ aMDPos = pWindow->PixelToLogic(rMEvt.GetPosPixel());
if ( rMEvt.IsLeft() )
{
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index 5892da8689a9..e64bf7052b30 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -671,9 +671,11 @@ void ScModelObj::postMouseEvent(int nType, int nX, int nY, int nCount, int nButt
// Calc operates in pixels...
const Point aPos(nX * pViewData->GetPPTX(), nY * pViewData->GetPPTY());
- SfxLokHelper::postMouseEventAsync(pGridWindow, nType, aPos, nCount,
- MouseEventModifiers::SIMPLECLICK,
+
+ LokMouseEventData aMouseEventData(nType, aPos, nCount, MouseEventModifiers::SIMPLECLICK,
nButtons, nModifier);
+ aMouseEventData.maLogicPosition = Point(convertTwipToMm100(nX), convertTwipToMm100(nY));
+ SfxLokHelper::postMouseEventAsync(pGridWindow, aMouseEventData);
}
void ScModelObj::setTextSelection(int nType, int nX, int nY)
diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx
index 26263aa21cc3..7b8e09adf038 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -2510,10 +2510,9 @@ void SdXImpressDocument::postMouseEvent(int nType, int nX, int nY, int nCount, i
}
const Point aPos(Point(convertTwipToMm100(nX), convertTwipToMm100(nY)));
- SfxLokHelper::postMouseEventAsync(pViewShell->GetActiveWindow(), nType,
- aPos, nCount,
- MouseEventModifiers::SIMPLECLICK,
+ LokMouseEventData aMouseEventData(nType, aPos, nCount, MouseEventModifiers::SIMPLECLICK,
nButtons, nModifier);
+ SfxLokHelper::postMouseEventAsync(pViewShell->GetActiveWindow(), aMouseEventData);
}
void SdXImpressDocument::setTextSelection(int nType, int nX, int nY)
diff --git a/sfx2/source/view/lokcharthelper.cxx b/sfx2/source/view/lokcharthelper.cxx
index 2622aba832cc..add4ef80078a 100644
--- a/sfx2/source/view/lokcharthelper.cxx
+++ b/sfx2/source/view/lokcharthelper.cxx
@@ -291,9 +291,10 @@ bool LokChartHelper::postMouseEvent(int nType, int nX, int nY,
// chart window expects pixels, but the conversion factor
// can depend on the client zoom
Point aPos(nChartWinX * fScaleX, nChartWinY * fScaleY);
- SfxLokHelper::postMouseEventAsync(pChartWindow, nType, aPos, nCount,
- MouseEventModifiers::SIMPLECLICK,
+
+ LokMouseEventData aMouseEventData(nType, aPos, nCount, MouseEventModifiers::SIMPLECLICK,
nButtons, nModifier);
+ SfxLokHelper::postMouseEventAsync(pChartWindow, aMouseEventData);
return true;
}
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index 4da19e5c1c94..004b2c58bf90 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -528,13 +528,10 @@ void SfxLokHelper::postExtTextEventAsync(const VclPtr<vcl::Window> &xWindow,
postEventAsync(pLOKEv);
}
-void SfxLokHelper::postMouseEventAsync(const VclPtr<vcl::Window> &xWindow,
- int nType, const Point &rPos,
- int nCount, MouseEventModifiers aModifiers,
- int nButtons, int nModifier)
+void SfxLokHelper::postMouseEventAsync(const VclPtr<vcl::Window> &xWindow, LokMouseEventData const & rLokMouseEventData)
{
LOKAsyncEventData* pLOKEv = new LOKAsyncEventData;
- switch (nType)
+ switch (rLokMouseEventData.mnType)
{
case LOK_MOUSEEVENT_MOUSEBUTTONDOWN:
pLOKEv->mnEvent = VclEventId::WindowMouseButtonDown;
@@ -550,10 +547,15 @@ void SfxLokHelper::postMouseEventAsync(const VclPtr<vcl::Window> &xWindow,
}
// no reason - just always true so far.
- assert (aModifiers == MouseEventModifiers::SIMPLECLICK);
+ assert (rLokMouseEventData.meModifiers == MouseEventModifiers::SIMPLECLICK);
- pLOKEv->maMouseEvent = MouseEvent(rPos, nCount,
- aModifiers, nButtons, nModifier);
+ pLOKEv->maMouseEvent = MouseEvent(rLokMouseEventData.maPosition, rLokMouseEventData.mnCount,
+ rLokMouseEventData.meModifiers, rLokMouseEventData.mnButtons,
+ rLokMouseEventData.mnModifier);
+ if (rLokMouseEventData.maLogicPosition)
+ {
+ pLOKEv->maMouseEvent.setLogicPosition(*rLokMouseEventData.maLogicPosition);
+ }
pLOKEv->mpWindow = xWindow;
postEventAsync(pLOKEv);
}
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index 8829dc98abbf..9f0b2e20d72f 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3565,10 +3565,10 @@ void SwXTextDocument::postMouseEvent(int nType, int nX, int nY, int nCount, int
}
SwEditWin& rEditWin = pDocShell->GetView()->GetEditWin();
- SfxLokHelper::postMouseEventAsync(&rEditWin, nType,
- Point(nX, nY), nCount,
+ LokMouseEventData aMouseEventData(nType, Point(nX, nY), nCount,
MouseEventModifiers::SIMPLECLICK,
nButtons, nModifier);
+ SfxLokHelper::postMouseEventAsync(&rEditWin, aMouseEventData);
}
void SwXTextDocument::setTextSelection(int nType, int nX, int nY)