diff options
author | Tamás Zolnai <tamas.zolnai@collabora.com> | 2020-04-28 15:51:02 +0200 |
---|---|---|
committer | Tamás Zolnai <tamas.zolnai@collabora.com> | 2020-05-09 09:36:15 +0200 |
commit | 31c2fd5059d6c73ee46ecbbe94bd7578de4ca1a1 (patch) | |
tree | 8def45e2075e228c8bf7de667ebc92a7936e0846 | |
parent | 2b77fd26283bab07e55542e4354f2019ef446968 (diff) |
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.zolnai@collabora.com>
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKitEnums.h | 23 | ||||
-rw-r--r-- | libreofficekit/source/gtk/lokdocview.cxx | 1 | ||||
-rw-r--r-- | sfx2/source/view/viewsh.cxx | 5 | ||||
-rw-r--r-- | sw/qa/extras/tiledrendering/data/drop_down_form_field.odt | bin | 0 -> 8596 bytes | |||
-rw-r--r-- | sw/qa/extras/tiledrendering/tiledrendering.cxx | 82 | ||||
-rw-r--r-- | sw/source/core/crsr/bookmrk.cxx | 45 | ||||
-rw-r--r-- | sw/source/core/inc/bookmrk.hxx | 8 |
7 files changed, 161 insertions, 3 deletions
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 Binary files differnew file mode 100644 index 000000000000..7793aff4e91b --- /dev/null +++ b/sw/qa/extras/tiledrendering/data/drop_down_form_field.odt 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; }; |