summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2020-01-29 12:44:30 +0100
committerTomaž Vajngerl <quikee@gmail.com>2020-01-29 14:48:38 +0100
commit82196472291c4ccbcacb5c2513d1961ba9460cdf (patch)
treee9043eb2c871867e2d21f9988371eb5bbb6d26fb
parentce1d8e20a708ed031f2336770a41fbe501fe8225 (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 53c6010f2a74..3689b0086b58 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 a79540c7a20b..a28f9a2eabae 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -672,9 +672,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 9cd67ac8afc9..67660e4919ac 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 f0f12f1cab2e..cd62c9360451 100644
--- a/sfx2/source/view/lokcharthelper.cxx
+++ b/sfx2/source/view/lokcharthelper.cxx
@@ -287,9 +287,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 c3a72154eddb..5556caa26be3 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -526,13 +526,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;
@@ -548,10 +545,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 d8f54b5817e7..f5eee610dbc2 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3500,10 +3500,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)