From 814c69878b03cd053b53bcc81bbaeee02d416ce7 Mon Sep 17 00:00:00 2001 From: Marco Cecchetti Date: Thu, 6 Feb 2020 11:19:32 +0100 Subject: lok: calc: formula input bar: set text selection as requested by client Change-Id: If04ed3c1637249329530a73d20df9b9296d1004e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88089 Reviewed-by: Marco Cecchetti Tested-by: Marco Cecchetti (cherry picked from commit 01f0d42f5ca9fb0e6e45b7bfcf51cb33c1a27bec) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88117 Tested-by: Jenkins Reviewed-by: Miklos Vajna --- desktop/qa/desktop_lib/test_desktop_lib.cxx | 3 ++- desktop/source/lib/init.cxx | 31 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) (limited to 'desktop') diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 14ecd2bcb196..a582ba764a01 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -2902,10 +2902,11 @@ void DesktopLOKTest::testABI() CPPUNIT_ASSERT_EQUAL(documentClassOffset(57), offsetof(struct _LibreOfficeKitDocumentClass, renderFontOrientation)); CPPUNIT_ASSERT_EQUAL(documentClassOffset(58), offsetof(struct _LibreOfficeKitDocumentClass, paintWindowForView)); CPPUNIT_ASSERT_EQUAL(documentClassOffset(59), offsetof(struct _LibreOfficeKitDocumentClass, completeFunction)); + CPPUNIT_ASSERT_EQUAL(documentClassOffset(60), offsetof(struct _LibreOfficeKitDocumentClass, setWindowTextSelection)); // Extending is fine, update this, and add new assert for the offsetof the // new method - CPPUNIT_ASSERT_EQUAL(documentClassOffset(60), sizeof(struct _LibreOfficeKitDocumentClass)); + CPPUNIT_ASSERT_EQUAL(documentClassOffset(61), sizeof(struct _LibreOfficeKitDocumentClass)); } CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest); diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 253ab51d2b29..65698eebbc37 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -1037,6 +1037,11 @@ static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pCommand, const char* pArguments, bool bNotifyWhenFinished); +static void doc_setWindowTextSelection(LibreOfficeKitDocument* pThis, + unsigned nLOKWindowId, + bool swap, + int nX, + int nY); static void doc_setTextSelection (LibreOfficeKitDocument* pThis, int nType, int nX, @@ -1201,6 +1206,7 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference sendDialogEvent = doc_sendDialogEvent; m_pDocumentClass->postUnoCommand = doc_postUnoCommand; m_pDocumentClass->setTextSelection = doc_setTextSelection; + m_pDocumentClass->setWindowTextSelection = doc_setWindowTextSelection; m_pDocumentClass->getTextSelection = doc_getTextSelection; m_pDocumentClass->getSelectionType = doc_getSelectionType; m_pDocumentClass->getClipboard = doc_getClipboard; @@ -3881,6 +3887,31 @@ static void doc_setTextSelection(LibreOfficeKitDocument* pThis, int nType, int n pDoc->setTextSelection(nType, nX, nY); } +static void doc_setWindowTextSelection(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKWindowId, bool swap, int nX, int nY) +{ + comphelper::ProfileZone aZone("doc_setWindowTextSelection"); + + SolarMutexGuard aGuard; + SetLastExceptionMsg(); + + VclPtr pWindow = vcl::Window::FindLOKWindow(nLOKWindowId); + if (!pWindow) + { + SetLastExceptionMsg("Document doesn't support dialog rendering, or window not found."); + return; + } + + + Size aOffset(pWindow->GetOutOffXPixel(), pWindow->GetOutOffYPixel()); + Point aCursorPos(nX, nY); + aCursorPos.Move(aOffset); + sal_uInt16 nModifier = swap ? KEY_MOD1 + KEY_MOD2 : KEY_SHIFT; + + MouseEvent aCursorEvent(aCursorPos, 1, MouseEventModifiers::SIMPLECLICK, 0, nModifier); + Application::PostMouseEvent(VclEventId::WindowMouseButtonDown, pWindow, &aCursorEvent); + Application::PostMouseEvent(VclEventId::WindowMouseButtonUp, pWindow, &aCursorEvent); +} + static bool getFromTransferrable( const css::uno::Reference &xTransferable, const OString &aInMimeType, OString &aRet); -- cgit