desktop/qa/desktop_lib/test_desktop_lib.cxx | 3 desktop/source/lib/init.cxx | 32 ++ include/LibreOfficeKit/LibreOfficeKit.h | 4 include/LibreOfficeKit/LibreOfficeKit.hxx | 10 include/LibreOfficeKit/LibreOfficeKitEnums.h | 23 ++ include/vcl/ITiledRenderable.hxx | 11 + libreofficekit/source/gtk/lokdocview.cxx | 1 sfx2/source/view/viewsh.cxx | 5 sw/inc/unotxdoc.hxx | 3 sw/qa/extras/tiledrendering/data/drop_down_form_field.odt |binary sw/qa/extras/tiledrendering/data/drop_down_form_field2.odt |binary sw/qa/extras/tiledrendering/tiledrendering.cxx | 140 +++++++++++++ sw/source/core/crsr/bookmrk.cxx | 86 +++++++ sw/source/core/doc/docbm.cxx | 3 sw/source/core/inc/bookmrk.hxx | 9 sw/source/uibase/uno/unotxdoc.cxx | 37 +++ 16 files changed, 362 insertions(+), 5 deletions(-)
New commits: commit eae46152b4a59dc995d165dbcd79169f72e47494 Author: Tamás Zolnai <tamas.zol...@collabora.com> AuthorDate: Thu May 7 12:25:51 2020 +0200 Commit: Tamás Zolnai <tamas.zol...@collabora.com> CommitDate: Sat May 9 09:36:16 2020 +0200 lok: MSForms: add a test case about editing drop down form field. Change-Id: I926b322d3af3047fc72c6ee9b923bc4435111328 diff --git a/sw/qa/extras/tiledrendering/data/drop_down_form_field2.odt b/sw/qa/extras/tiledrendering/data/drop_down_form_field2.odt new file mode 100644 index 000000000000..7793aff4e91b Binary files /dev/null and b/sw/qa/extras/tiledrendering/data/drop_down_form_field2.odt differ diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index 8ef00b63908f..884f52674213 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -46,6 +46,7 @@ #include <svx/svxids.hrc> #include <flddat.hxx> #include <basesh.hxx> +#include <vcl/ITiledRenderable.hxx> static char const DATA_DIRECTORY[] = "/sw/qa/extras/tiledrendering/data/"; @@ -124,6 +125,7 @@ public: void testRedlineNotificationDuringSave(); void testFieldmark(); void testDropDownFormFieldButton(); + void testDropDownFormFieldButtonEditing(); CPPUNIT_TEST_SUITE(SwTiledRenderingTest); CPPUNIT_TEST(testRegisterCallback); @@ -189,6 +191,7 @@ public: CPPUNIT_TEST(testRedlineNotificationDuringSave); CPPUNIT_TEST(testFieldmark); CPPUNIT_TEST(testDropDownFormFieldButton); + CPPUNIT_TEST(testDropDownFormFieldButtonEditing); CPPUNIT_TEST_SUITE_END(); private: @@ -2536,7 +2539,7 @@ void SwTiledRenderingTest::testDropDownFormFieldButton() pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, /*bBasicCall=*/false); CPPUNIT_ASSERT(m_aFormFieldButton.isEmpty()); - // Do a tile rendering to trigger the button message with a valide text area + // Do a tile rendering to trigger the button message with a valid text area size_t nCanvasWidth = 1024; size_t nCanvasHeight = 512; std::vector<unsigned char> aPixmap(nCanvasWidth * nCanvasHeight * 4, 0); @@ -2594,6 +2597,64 @@ void SwTiledRenderingTest::testDropDownFormFieldButton() } } +void SwTiledRenderingTest::testDropDownFormFieldButtonEditing() +{ + comphelper::LibreOfficeKit::setActive(); + SwXTextDocument* pXTextDocument = createDoc("drop_down_form_field2.odt"); + pXTextDocument->setClientVisibleArea(tools::Rectangle(0, 0, 10000, 4000)); + + SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell(); + pWrtShell->GetSfxViewShell()->registerLibreOfficeKitViewCallback(&SwTiledRenderingTest::callback, this); + + // Move the cursor to trigger displaying of the field button. + pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, /*bBasicCall=*/false); + CPPUNIT_ASSERT(m_aFormFieldButton.isEmpty()); + + // Do a tile rendering to trigger the button message with a valid text area + size_t nCanvasWidth = 1024; + size_t nCanvasHeight = 512; + std::vector<unsigned char> aPixmap(nCanvasWidth * nCanvasHeight * 4, 0); + ScopedVclPtrInstance<VirtualDevice> pDevice(DeviceFormat::DEFAULT); + pDevice->SetBackground(Wallpaper(COL_TRANSPARENT)); + pDevice->SetOutputSizePixelScaleOffsetAndBuffer(Size(nCanvasWidth, nCanvasHeight), + Fraction(1.0), Point(), aPixmap.data()); + pXTextDocument->paintTile(*pDevice, nCanvasWidth, nCanvasHeight, /*nTilePosX=*/0, + /*nTilePosY=*/0, /*nTileWidth=*/10000, /*nTileHeight=*/4000); + + // The item with the index '1' is selected by default + CPPUNIT_ASSERT(!m_aFormFieldButton.isEmpty()); + { + std::stringstream aStream(m_aFormFieldButton.getStr()); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + + OString sSelected = aTree.get_child("params").get_child("selected").get_value<std::string>().c_str(); + CPPUNIT_ASSERT_EQUAL(OString("1"), sSelected); + } + m_aFormFieldButton = ""; + + // Trigger a form field event to select a different item. + vcl::ITiledRenderable::StringMap aArguments; + aArguments["type"] = "drop-down"; + aArguments["cmd"] = "selected"; + aArguments["data"] = "3"; + pXTextDocument->executeFromFieldEvent(aArguments); + + // Do a tile rendering to trigger the button message. + pXTextDocument->paintTile(*pDevice, nCanvasWidth, nCanvasHeight, /*nTilePosX=*/0, + /*nTilePosY=*/0, /*nTileWidth=*/10000, /*nTileHeight=*/4000); + + CPPUNIT_ASSERT(!m_aFormFieldButton.isEmpty()); + { + std::stringstream aStream(m_aFormFieldButton.getStr()); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + + OString sSelected = aTree.get_child("params").get_child("selected").get_value<std::string>().c_str(); + CPPUNIT_ASSERT_EQUAL(OString("3"), sSelected); + } +} + CPPUNIT_TEST_SUITE_REGISTRATION(SwTiledRenderingTest); CPPUNIT_PLUGIN_IMPLEMENT(); commit 5beba4976f09c3b5f6e9adf6ba03c6db41639518 Author: Tamás Zolnai <tamas.zol...@collabora.com> AuthorDate: Fri May 8 15:26:57 2020 +0200 Commit: Tamás Zolnai <tamas.zol...@collabora.com> CommitDate: Sat May 9 09:36:15 2020 +0200 lok: MSForms: send button message also when paint area is not changing. We can filter out duplicated messages with storing the last message. Ignoring messages with the same paint area is a problem, if we change the drop down field content to a new item with the same size. Change-Id: Ie2e0bab445eb0e6e5b9b25846adbd79af55e7816 diff --git a/sw/source/core/crsr/bookmrk.cxx b/sw/source/core/crsr/bookmrk.cxx index 53300c97863a..d32d66404efe 100644 --- a/sw/source/core/crsr/bookmrk.cxx +++ b/sw/source/core/crsr/bookmrk.cxx @@ -557,7 +557,10 @@ namespace sw { namespace mark { if(m_aPortionPaintArea == rPortionPaintArea && m_pButton && m_pButton->IsVisible()) + { + SendLOKMessage("show"); return; + } m_aPortionPaintArea = rPortionPaintArea; if(m_pButton) @@ -625,7 +628,10 @@ namespace sw { namespace mark { sPayload = "{\"action\": \"hide\", \"type\": \"drop-down\"}"; } - pEditWin->GetView().GetWrtShell().GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_FORM_FIELD_BUTTON, sPayload.toString().getStr()); + if (sPayload.toString() != m_sLastSentLOKMsg) { + m_sLastSentLOKMsg = sPayload.toString(); + pEditWin->GetView().GetWrtShell().GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_FORM_FIELD_BUTTON, m_sLastSentLOKMsg.getStr()); + } } } diff --git a/sw/source/core/inc/bookmrk.hxx b/sw/source/core/inc/bookmrk.hxx index c156a86c9772..ebbc0c944b87 100644 --- a/sw/source/core/inc/bookmrk.hxx +++ b/sw/source/core/inc/bookmrk.hxx @@ -305,6 +305,7 @@ namespace sw { private: SwRect m_aPortionPaintArea; + OString m_sLastSentLOKMsg; }; /// Fieldmark representing a date form field. commit 5c325eb0e6867eec42d234ade6eb65da99e4fde1 Author: Tamás Zolnai <tamas.zol...@collabora.com> AuthorDate: Thu May 7 17:28:02 2020 +0200 Commit: Tamás Zolnai <tamas.zol...@collabora.com> CommitDate: Sat May 9 09:36:15 2020 +0200 lok: MSForms: fix field activation for multiple fields. First hide hide the button of the previously active field and show the new button afterwards. Change-Id: I6de668f25a18f8c1d3dbf66beb357f089b51ae0b diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx index 8d61b4272d5e..fc4309d45519 100644 --- a/sw/source/core/doc/docbm.cxx +++ b/sw/source/core/doc/docbm.cxx @@ -1203,7 +1203,6 @@ namespace sw { namespace mark if (m_pLastActiveFieldmark != pFieldBM) { auto pFormField = dynamic_cast<FieldmarkWithDropDownButton*>(pFieldBM); - pFormField->ShowButton(&rEditWin); pNewActiveFieldmark = pFormField; } else @@ -1216,6 +1215,8 @@ namespace sw { namespace mark { ClearFieldActivation(); m_pLastActiveFieldmark = pNewActiveFieldmark; + if(pNewActiveFieldmark) + pNewActiveFieldmark->ShowButton(&rEditWin); } } commit cdf234f0f8b72eb1fd1ed9082180df46607bcfc2 Author: Tamás Zolnai <tamas.zol...@collabora.com> AuthorDate: Thu May 7 16:57:45 2020 +0200 Commit: Tamás Zolnai <tamas.zol...@collabora.com> CommitDate: Sat May 9 09:36:15 2020 +0200 lok: MSForms: fix editing of drop-down field. When cursor is on the left side of the form field. Change-Id: I8587c477b6177e9309349afbbfc70979b4338275 diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index 5c2ce7236c7e..3ab7e4a8c8d8 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -3439,16 +3439,16 @@ void SwXTextDocument::executeFromFieldEvent(const StringMap& aArguments) { --aPos.nContent; pFieldBM = pDocShell->GetWrtShell()->getIDocumentMarkAccess()->getFieldmarkFor(aPos); - if (pFieldBM && pFieldBM->GetFieldname() == ODF_FORMDROPDOWN) + } + if (pFieldBM && pFieldBM->GetFieldname() == ODF_FORMDROPDOWN) + { + if (nSelection >= 0) { - if (nSelection >= 0) - { - OUString sKey = ODF_FORMDROPDOWN_RESULT; - (*pFieldBM->GetParameters())[sKey] <<= nSelection; - pFieldBM->Invalidate(); - pDocShell->GetWrtShell()->SetModified(); - pDocShell->GetView()->GetEditWin().LogicInvalidate(nullptr); - } + OUString sKey = ODF_FORMDROPDOWN_RESULT; + (*pFieldBM->GetParameters())[sKey] <<= nSelection; + pFieldBM->Invalidate(); + pDocShell->GetWrtShell()->SetModified(); + pDocShell->GetView()->GetEditWin().LogicInvalidate(nullptr); } } } commit b59bb50b56b5e22b9d71e14064239da3a295b89c Author: Tamás Zolnai <tamas.zol...@collabora.com> AuthorDate: Thu May 7 12:45:48 2020 +0200 Commit: Tamás Zolnai <tamas.zol...@collabora.com> CommitDate: Sat May 9 09:36:15 2020 +0200 lok: MSForms: disable form field messages on mobile. Change-Id: I466c457fb0a2cbca3e7480fe8fde9833d9c35b63 diff --git a/sw/source/core/crsr/bookmrk.cxx b/sw/source/core/crsr/bookmrk.cxx index 945312968e1e..53300c97863a 100644 --- a/sw/source/core/crsr/bookmrk.cxx +++ b/sw/source/core/crsr/bookmrk.cxx @@ -571,6 +571,12 @@ namespace sw { namespace mark void DropDownFieldmark::SendLOKMessage(const OString& sAction) { + const SfxViewShell* pViewShell = SfxViewShell::Current(); + if (pViewShell && pViewShell->isLOKMobilePhone()) + { + return; + } + if (comphelper::LibreOfficeKit::isActive()) { if (!m_pButton) commit 0bd0903369d3a55052a6727c0489369a537d540c Author: Tamás Zolnai <tamas.zol...@collabora.com> AuthorDate: Thu May 7 12:08:39 2020 +0200 Commit: Tamás Zolnai <tamas.zol...@collabora.com> CommitDate: Sat May 9 09:36:15 2020 +0200 lok: MSForms: dont send form field button data with empty text area. Change-Id: I88d793765b58a3c483aad51d1a0e2e9f0159d5f1 diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index 7446d5397b20..8ef00b63908f 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -2534,24 +2534,7 @@ void SwTiledRenderingTest::testDropDownFormFieldButton() // Move the cursor to trigger displaying of the field button. pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, /*bBasicCall=*/false); - - CPPUNIT_ASSERT(!m_aFormFieldButton.isEmpty()); - - // First we have a button with an empty text area. - { - std::stringstream aStream(m_aFormFieldButton.getStr()); - boost::property_tree::ptree aTree; - boost::property_tree::read_json(aStream, aTree); - - OString sAction = aTree.get_child("action").get_value<std::string>().c_str(); - CPPUNIT_ASSERT_EQUAL(OString("show"), sAction); - - OString sType = aTree.get_child("type").get_value<std::string>().c_str(); - CPPUNIT_ASSERT_EQUAL(OString("drop-down"), sType); - - OString sTextArea = aTree.get_child("textArea").get_value<std::string>().c_str(); - CPPUNIT_ASSERT_EQUAL(OString("0, 0, -1, -1"), sTextArea); - } + CPPUNIT_ASSERT(m_aFormFieldButton.isEmpty()); // Do a tile rendering to trigger the button message with a valide text area size_t nCanvasWidth = 1024; diff --git a/sw/source/core/crsr/bookmrk.cxx b/sw/source/core/crsr/bookmrk.cxx index 2f8a9e96b183..945312968e1e 100644 --- a/sw/source/core/crsr/bookmrk.cxx +++ b/sw/source/core/crsr/bookmrk.cxx @@ -583,6 +583,9 @@ namespace sw { namespace mark OStringBuffer sPayload; if (sAction == "show") { + if(m_aPortionPaintArea.IsEmpty()) + return; + sPayload = OStringLiteral("{\"action\": \"show\"," " \"type\": \"drop-down\", \"textArea\": \"") + m_aPortionPaintArea.SVRect().toString() + "\","; commit 8692addd7ba2e60132500b695eb606d3b9c7703a Author: Tamás Zolnai <tamas.zol...@collabora.com> AuthorDate: Wed May 6 14:33:10 2020 +0200 Commit: Tamás Zolnai <tamas.zol...@collabora.com> CommitDate: Sat May 9 09:36:15 2020 +0200 lok: MSForms: Handle event about item selection of a drop-down field. Change-Id: I095013097348c98361b6614e4ddf1e9029923c7f diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 3ca8c555544a..8a3f2d3efc9a 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -2884,10 +2884,11 @@ void DesktopLOKTest::testABI() 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)); + CPPUNIT_ASSERT_EQUAL(documentClassOffset(61), offsetof(struct _LibreOfficeKitDocumentClass, sendFormFieldEvent)); // Extending is fine, update this, and add new assert for the offsetof the // new method - CPPUNIT_ASSERT_EQUAL(documentClassOffset(61), sizeof(struct _LibreOfficeKitDocumentClass)); + CPPUNIT_ASSERT_EQUAL(documentClassOffset(62), sizeof(struct _LibreOfficeKitDocumentClass)); } CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest); diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index a6f87754b411..40c19ca439fd 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -1091,6 +1091,9 @@ static void doc_resizeWindow(LibreOfficeKitDocument* pThis, unsigned nLOKWindowI const int nWidth, const int nHeight); static void doc_completeFunction(LibreOfficeKitDocument* pThis, const char*); + +static void doc_sendFormFieldEvent(LibreOfficeKitDocument* pThis, + const char* pArguments); } // extern "C" namespace { @@ -1261,6 +1264,8 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone m_pDocumentClass->createViewWithOptions = doc_createViewWithOptions; m_pDocumentClass->completeFunction = doc_completeFunction; + m_pDocumentClass->sendFormFieldEvent = doc_sendFormFieldEvent; + gDocumentClass = m_pDocumentClass; } pClass = m_pDocumentClass.get(); @@ -5451,6 +5456,33 @@ static void doc_completeFunction(LibreOfficeKitDocument* pThis, const char* pFun pDoc->completeFunction(OUString::fromUtf8(pFunctionName)); } + +static void doc_sendFormFieldEvent(LibreOfficeKitDocument* pThis, const char* pArguments) +{ + SolarMutexGuard aGuard; + + // Supported in Writer only + if (doc_getDocumentType(pThis) != LOK_DOCTYPE_TEXT) + return; + + StringMap aMap(jsonToStringMap(pArguments)); + ITiledRenderable* pDoc = getTiledRenderable(pThis); + if (!pDoc) + { + SetLastExceptionMsg("Document doesn't support tiled rendering!"); + return; + } + + // Sanity check + if (aMap.find("type") == aMap.end() || aMap.find("cmd") == aMap.end()) + { + SetLastExceptionMsg("Wrong arguments for sendFormFieldEvent!"); + return; + } + + pDoc->executeFromFieldEvent(aMap); +} + static char* lo_getError (LibreOfficeKit *pThis) { comphelper::ProfileZone aZone("lo_getError"); diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h index f95c8cb7858b..8b68452697b3 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.h +++ b/include/LibreOfficeKit/LibreOfficeKit.h @@ -446,6 +446,10 @@ struct _LibreOfficeKitDocumentClass int nX, int nY); + /// @see lok::Document::sendFormFieldEvent + void (*sendFormFieldEvent) (LibreOfficeKitDocument* pThis, + const char* pArguments); + #endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY }; diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx index ae72a3258357..e48ed862f649 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.hxx +++ b/include/LibreOfficeKit/LibreOfficeKit.hxx @@ -780,6 +780,16 @@ public: mpDoc->pClass->setWindowTextSelection(mpDoc, nWindowId, bSwap, nX, nY); } + /** + * Posts an event for the form field at the cursor position. + * + * @param pArguments arguments of the event. + */ + void sendFormFieldEvent(const char* pArguments) + { + mpDoc->pClass->sendFormFieldEvent(mpDoc, pArguments); + } + #endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY }; diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx index b68157d32468..f041862de162 100644 --- a/include/vcl/ITiledRenderable.hxx +++ b/include/vcl/ITiledRenderable.hxx @@ -97,6 +97,9 @@ namespace vcl class VCL_DLLPUBLIC ITiledRenderable { public: + + typedef std::map<const OUString, OUString> StringMap; + virtual ~ITiledRenderable(); /** @@ -349,6 +352,14 @@ public: { return false; } + + /** + * Execute a form field event in the document. + * E.g. select an item from a drop down field's list. + */ + virtual void executeFromFieldEvent(const StringMap&) + { + } }; } // namespace vcl diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx index 2df74ab078e8..775788e9f99e 100644 --- a/sw/inc/unotxdoc.hxx +++ b/sw/inc/unotxdoc.hxx @@ -434,6 +434,9 @@ public: /// @see vcl::ITiledRenderable::getPostIts(). OUString getPostIts() override; + /// @see vcl::ITiledRenderable::executeFromFieldEvent(). + virtual void executeFromFieldEvent(const StringMap& aArguments) override; + // css::tiledrendering::XTiledRenderable virtual void SAL_CALL paintTile( const ::css::uno::Any& Parent, ::sal_Int32 nOutputWidth, ::sal_Int32 nOutputHeight, ::sal_Int32 nTilePosX, ::sal_Int32 nTilePosY, ::sal_Int32 nTileWidth, ::sal_Int32 nTileHeight ) override; diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index 4cc7d317bd47..5c2ce7236c7e 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -180,6 +180,8 @@ #include <memory> #include <fchrfmt.hxx> #include <redline.hxx> +#include <DocumentRedlineManager.hxx> +#include <xmloff/odffields.hxx> #define TWIPS_PER_PIXEL 15 @@ -3419,6 +3421,41 @@ OUString SwXTextDocument::getPostIts() return OUString::fromUtf8(aStream.str().c_str()); } +void SwXTextDocument::executeFromFieldEvent(const StringMap& aArguments) +{ + auto aIter = aArguments.find("type"); + if (aIter != aArguments.end() && aIter->second == "drop-down") + { + aIter = aArguments.find("cmd"); + if (aIter != aArguments.end() && aIter->second == "selected") + { + aIter = aArguments.find("data"); + if (aIter != aArguments.end()) + { + sal_Int32 nSelection = aIter->second.toInt32(); + SwPosition aPos(*pDocShell->GetWrtShell()->GetCursor()->GetPoint()); + sw::mark::IFieldmark* pFieldBM = pDocShell->GetWrtShell()->getIDocumentMarkAccess()->getFieldmarkFor(aPos); + if ( !pFieldBM ) + { + --aPos.nContent; + pFieldBM = pDocShell->GetWrtShell()->getIDocumentMarkAccess()->getFieldmarkFor(aPos); + if (pFieldBM && pFieldBM->GetFieldname() == ODF_FORMDROPDOWN) + { + if (nSelection >= 0) + { + OUString sKey = ODF_FORMDROPDOWN_RESULT; + (*pFieldBM->GetParameters())[sKey] <<= nSelection; + pFieldBM->Invalidate(); + pDocShell->GetWrtShell()->SetModified(); + pDocShell->GetView()->GetEditWin().LogicInvalidate(nullptr); + } + } + } + } + } + } +} + int SwXTextDocument::getPart() { SolarMutexGuard aGuard; commit b4bfb45031b3df61e02cafefc7c1e6e7c68bd28a Author: Tamás Zolnai <tamas.zol...@collabora.com> AuthorDate: Tue May 5 14:36:16 2020 +0200 Commit: Tamás Zolnai <tamas.zol...@collabora.com> CommitDate: Sat May 9 09:36:15 2020 +0200 lok: MSForms: Send also the drop down field params to the client code. Change-Id: Id42f428b7944d97d1b61a5b60d6e0807cb51cc95 diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index 3c7584e0311b..7446d5397b20 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -2578,6 +2578,20 @@ void SwTiledRenderingTest::testDropDownFormFieldButton() OString sTextArea = aTree.get_child("textArea").get_value<std::string>().c_str(); CPPUNIT_ASSERT_EQUAL(OString("1538, 1418, 1026, 275"), sTextArea); + + boost::property_tree::ptree aItems = aTree.get_child("params").get_child("items"); + CPPUNIT_ASSERT_EQUAL(size_t(6), aItems.size()); + + OStringBuffer aItemList; + for (auto &item : aItems) + { + aItemList.append(item.second.get_value<std::string>().c_str()); + aItemList.append(";"); + } + CPPUNIT_ASSERT_EQUAL(OString("2019/2020;2020/2021;2021/2022;2022/2023;2023/2024;2024/2025;"), aItemList.toString()); + + OString sSelected = aTree.get_child("params").get_child("selected").get_value<std::string>().c_str(); + CPPUNIT_ASSERT_EQUAL(OString("1"), sSelected); } // Move the cursor back so the button becomes hidden. diff --git a/sw/source/core/crsr/bookmrk.cxx b/sw/source/core/crsr/bookmrk.cxx index 0aaa78493e7b..2f8a9e96b183 100644 --- a/sw/source/core/crsr/bookmrk.cxx +++ b/sw/source/core/crsr/bookmrk.cxx @@ -47,6 +47,7 @@ #include <view.hxx> #include <LibreOfficeKit/LibreOfficeKitEnums.h> #include <wrtsh.hxx> +#include <rtl/strbuf.hxx> using namespace ::sw::mark; using namespace ::com::sun::star; @@ -579,18 +580,43 @@ namespace sw { namespace mark if (!pEditWin) return; - OString sPayload; + OStringBuffer sPayload; if (sAction == "show") { sPayload = OStringLiteral("{\"action\": \"show\"," " \"type\": \"drop-down\", \"textArea\": \"") + - m_aPortionPaintArea.SVRect().toString() + "\"}"; + m_aPortionPaintArea.SVRect().toString() + "\","; + // Add field params to the message + sPayload.append(" \"params\": { \"items\": ["); + + // List items + auto pParameters = this->GetParameters(); + auto pListEntriesIter = pParameters->find(ODF_FORMDROPDOWN_LISTENTRY); + css::uno::Sequence<OUString> vListEntries; + if (pListEntriesIter != pParameters->end()) + { + pListEntriesIter->second >>= vListEntries; + for (const OUString& sItem : vListEntries) + sPayload.append("\"" + OUStringToOString(sItem, RTL_TEXTENCODING_UTF8) + "\", "); + sPayload.setLength(sPayload.getLength() - 2); + } + sPayload.append("], "); + + // Selected item + OUString sResultKey = ODF_FORMDROPDOWN_RESULT; + auto pSelectedItemIter = pParameters->find(sResultKey); + if (pSelectedItemIter != pParameters->end()) + { + sal_Int32 nSelection = -1; + pSelectedItemIter->second >>= nSelection; + sPayload.append("\"selected\": \"" + OString::number(nSelection) + "\"}}"); + } } else { sPayload = "{\"action\": \"hide\", \"type\": \"drop-down\"}"; } - pEditWin->GetView().GetWrtShell().GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_FORM_FIELD_BUTTON, sPayload.getStr()); + pEditWin->GetView().GetWrtShell().GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_FORM_FIELD_BUTTON, sPayload.toString().getStr()); } } commit 31c2fd5059d6c73ee46ecbbe94bd7578de4ca1a1 Author: Tamás Zolnai <tamas.zol...@collabora.com> AuthorDate: Tue Apr 28 15:51:02 2020 +0200 Commit: Tamás Zolnai <tamas.zol...@collabora.com> CommitDate: Sat May 9 09:36:15 2020 +0200 lok: MSForms: Add callback for form field button. Show and hide the button and send the button area, where it should be displayed. Change-Id: I5922eb9f5e544483dd4efd12e4218d2e51270632 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93657 Tested-by: Jenkins Reviewed-by: Tamás Zolnai <tamas.zol...@collabora.com> diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h index 401b5f24dc0b..96eda9b50978 100644 --- a/include/LibreOfficeKit/LibreOfficeKitEnums.h +++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h @@ -726,6 +726,27 @@ typedef enum * Sends the tab stop list for the current of the current cursor position. */ LOK_CALLBACK_TAB_STOP_LIST = 48, + + /** + * Sends all informations for displaying form field button for a text based field. + * + * It contains the position where the frame with the button should be displayed and + * also contains all information that the popup window needs. + * + * The payload example: + * { + * "action": "show", + * "type": "drop-down", + * "textArea": "1418, 3906, 3111, 919" + * } + * + * or + * { + * "action": "hide", + * "type": "drop-down" + * } + */ + LOK_CALLBACK_FORM_FIELD_BUTTON = 49, } LibreOfficeKitCallbackType; @@ -852,6 +873,8 @@ static inline const char* lokCallbackTypeToString(int nType) return "LOK_CALLBACK_CALC_FUNCTION_LIST"; case LOK_CALLBACK_TAB_STOP_LIST: return "LOK_CALLBACK_TAB_STOP_LIST"; + case LOK_CALLBACK_FORM_FIELD_BUTTON: + return "LOK_CALLBACK_FORM_FIELD_BUTTON"; } assert(!"Unknown LibreOfficeKitCallbackType type."); diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index 6284d85ee9b1..d094c85c1ba3 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -1378,6 +1378,7 @@ callback (gpointer pData) case LOK_CALLBACK_JSDIALOG: case LOK_CALLBACK_CALC_FUNCTION_LIST: case LOK_CALLBACK_TAB_STOP_LIST: + case LOK_CALLBACK_FORM_FIELD_BUTTON: { // TODO: Implement me break; diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx index 6728f866d0cf..dcbdc9ceef3a 100644 --- a/sfx2/source/view/viewsh.cxx +++ b/sfx2/source/view/viewsh.cxx @@ -1485,7 +1485,10 @@ void SfxViewShell::registerLibreOfficeKitViewCallback(LibreOfficeKitCallback pCa void SfxViewShell::libreOfficeKitViewCallback(int nType, const char* pPayload) const { - if (!comphelper::LibreOfficeKit::isActive() || comphelper::LibreOfficeKit::isTiledPainting()) + if (!comphelper::LibreOfficeKit::isActive()) + return; + + if (comphelper::LibreOfficeKit::isTiledPainting() && nType != LOK_CALLBACK_FORM_FIELD_BUTTON) return; if (pImpl->m_bTiledSearching) diff --git a/sw/qa/extras/tiledrendering/data/drop_down_form_field.odt b/sw/qa/extras/tiledrendering/data/drop_down_form_field.odt new file mode 100644 index 000000000000..7793aff4e91b Binary files /dev/null and b/sw/qa/extras/tiledrendering/data/drop_down_form_field.odt differ diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index 2771b76fda79..3c7584e0311b 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -123,6 +123,7 @@ public: void testHyperlink(); void testRedlineNotificationDuringSave(); void testFieldmark(); + void testDropDownFormFieldButton(); CPPUNIT_TEST_SUITE(SwTiledRenderingTest); CPPUNIT_TEST(testRegisterCallback); @@ -187,6 +188,7 @@ public: CPPUNIT_TEST(testHyperlink); CPPUNIT_TEST(testRedlineNotificationDuringSave); CPPUNIT_TEST(testFieldmark); + CPPUNIT_TEST(testDropDownFormFieldButton); CPPUNIT_TEST_SUITE_END(); private: @@ -207,6 +209,7 @@ private: int m_nTrackedChangeIndex; OString m_sHyperlinkText; OString m_sHyperlinkLink; + OString m_aFormFieldButton; }; SwTiledRenderingTest::SwTiledRenderingTest() @@ -352,6 +355,11 @@ void SwTiledRenderingTest::callbackImpl(int nType, const char* pPayload) } } break; + case LOK_CALLBACK_FORM_FIELD_BUTTON: + { + m_aFormFieldButton = OString(pPayload); + } + break; } } @@ -2515,6 +2523,80 @@ void SwTiledRenderingTest::testFieldmark() createDoc("fieldmark.docx"); } +void SwTiledRenderingTest::testDropDownFormFieldButton() +{ + comphelper::LibreOfficeKit::setActive(); + SwXTextDocument* pXTextDocument = createDoc("drop_down_form_field.odt"); + pXTextDocument->setClientVisibleArea(tools::Rectangle(0, 0, 10000, 4000)); + + SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell(); + pWrtShell->GetSfxViewShell()->registerLibreOfficeKitViewCallback(&SwTiledRenderingTest::callback, this); + + // Move the cursor to trigger displaying of the field button. + pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, /*bBasicCall=*/false); + + CPPUNIT_ASSERT(!m_aFormFieldButton.isEmpty()); + + // First we have a button with an empty text area. + { + std::stringstream aStream(m_aFormFieldButton.getStr()); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + + OString sAction = aTree.get_child("action").get_value<std::string>().c_str(); + CPPUNIT_ASSERT_EQUAL(OString("show"), sAction); + + OString sType = aTree.get_child("type").get_value<std::string>().c_str(); + CPPUNIT_ASSERT_EQUAL(OString("drop-down"), sType); + + OString sTextArea = aTree.get_child("textArea").get_value<std::string>().c_str(); + CPPUNIT_ASSERT_EQUAL(OString("0, 0, -1, -1"), sTextArea); + } + + // Do a tile rendering to trigger the button message with a valide text area + size_t nCanvasWidth = 1024; + size_t nCanvasHeight = 512; + std::vector<unsigned char> aPixmap(nCanvasWidth * nCanvasHeight * 4, 0); + ScopedVclPtrInstance<VirtualDevice> pDevice(DeviceFormat::DEFAULT); + pDevice->SetBackground(Wallpaper(COL_TRANSPARENT)); + pDevice->SetOutputSizePixelScaleOffsetAndBuffer(Size(nCanvasWidth, nCanvasHeight), + Fraction(1.0), Point(), aPixmap.data()); + pXTextDocument->paintTile(*pDevice, nCanvasWidth, nCanvasHeight, /*nTilePosX=*/0, + /*nTilePosY=*/0, /*nTileWidth=*/10000, /*nTileHeight=*/4000); + + CPPUNIT_ASSERT(!m_aFormFieldButton.isEmpty()); + { + std::stringstream aStream(m_aFormFieldButton.getStr()); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + + OString sAction = aTree.get_child("action").get_value<std::string>().c_str(); + CPPUNIT_ASSERT_EQUAL(OString("show"), sAction); + + OString sType = aTree.get_child("type").get_value<std::string>().c_str(); + CPPUNIT_ASSERT_EQUAL(OString("drop-down"), sType); + + OString sTextArea = aTree.get_child("textArea").get_value<std::string>().c_str(); + CPPUNIT_ASSERT_EQUAL(OString("1538, 1418, 1026, 275"), sTextArea); + } + + // Move the cursor back so the button becomes hidden. + pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, /*bBasicCall=*/false); + + CPPUNIT_ASSERT(!m_aFormFieldButton.isEmpty()); + { + std::stringstream aStream(m_aFormFieldButton.getStr()); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + + OString sAction = aTree.get_child("action").get_value<std::string>().c_str(); + CPPUNIT_ASSERT_EQUAL(OString("hide"), sAction); + + OString sType = aTree.get_child("type").get_value<std::string>().c_str(); + CPPUNIT_ASSERT_EQUAL(OString("drop-down"), sType); + } +} + CPPUNIT_TEST_SUITE_REGISTRATION(SwTiledRenderingTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/core/crsr/bookmrk.cxx b/sw/source/core/crsr/bookmrk.cxx index 14fab9d32da5..0aaa78493e7b 100644 --- a/sw/source/core/crsr/bookmrk.cxx +++ b/sw/source/core/crsr/bookmrk.cxx @@ -43,6 +43,10 @@ #include <svx/numfmtsh.hxx> #include <ndtxt.hxx> #include <DocumentContentOperationsManager.hxx> +#include <comphelper/lok.hxx> +#include <view.hxx> +#include <LibreOfficeKit/LibreOfficeKitEnums.h> +#include <wrtsh.hxx> using namespace ::sw::mark; using namespace ::com::sun::star; @@ -521,6 +525,7 @@ namespace sw { namespace mark DropDownFieldmark::~DropDownFieldmark() { + SendLOKMessage("hide"); } void DropDownFieldmark::ShowButton(SwEditWin* pEditWin) @@ -531,9 +536,22 @@ namespace sw { namespace mark m_pButton = VclPtr<DropDownFormFieldButton>::Create(pEditWin, *this); m_pButton->CalcPosAndSize(m_aPortionPaintArea); m_pButton->Show(); + SendLOKMessage("show"); } } + void DropDownFieldmark::HideButton() + { + SendLOKMessage("hide"); + FieldmarkWithDropDownButton::HideButton(); + } + + void DropDownFieldmark::RemoveButton() + { + SendLOKMessage("hide"); + FieldmarkWithDropDownButton::RemoveButton(); + } + void DropDownFieldmark::SetPortionPaintArea(const SwRect& rPortionPaintArea) { if(m_aPortionPaintArea == rPortionPaintArea && @@ -546,6 +564,33 @@ namespace sw { namespace mark m_pButton->Show(); m_pButton->CalcPosAndSize(m_aPortionPaintArea); m_pButton->Invalidate(); + SendLOKMessage("show"); + } + } + + void DropDownFieldmark::SendLOKMessage(const OString& sAction) + { + if (comphelper::LibreOfficeKit::isActive()) + { + if (!m_pButton) + return; + + SwEditWin* pEditWin = dynamic_cast<SwEditWin*>(m_pButton->GetParent()); + if (!pEditWin) + return; + + OString sPayload; + if (sAction == "show") + { + sPayload = OStringLiteral("{\"action\": \"show\"," + " \"type\": \"drop-down\", \"textArea\": \"") + + m_aPortionPaintArea.SVRect().toString() + "\"}"; + } + else + { + sPayload = "{\"action\": \"hide\", \"type\": \"drop-down\"}"; + } + pEditWin->GetView().GetWrtShell().GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_FORM_FIELD_BUTTON, sPayload.getStr()); } } diff --git a/sw/source/core/inc/bookmrk.hxx b/sw/source/core/inc/bookmrk.hxx index 2107b3640616..c156a86c9772 100644 --- a/sw/source/core/inc/bookmrk.hxx +++ b/sw/source/core/inc/bookmrk.hxx @@ -279,8 +279,8 @@ namespace sw { virtual ~FieldmarkWithDropDownButton() override; virtual void ShowButton(SwEditWin* pEditWin) = 0; - void HideButton(); - void RemoveButton(); + virtual void HideButton(); + virtual void RemoveButton(); protected: VclPtr<FormFieldButton> m_pButton; @@ -295,10 +295,14 @@ namespace sw { virtual ~DropDownFieldmark() override; virtual void ShowButton(SwEditWin* pEditWin) override; + virtual void HideButton() override; + virtual void RemoveButton() override; // This method should be called only by the portion so we can now the portion's painting area void SetPortionPaintArea(const SwRect& rPortionPaintArea); + void SendLOKMessage(const OString& sAction); + private: SwRect m_aPortionPaintArea; }; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits