diff options
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/tiledrendering/data/drop_down_form_field_noitem.odt | bin | 0 -> 8467 bytes | |||
-rw-r--r-- | sw/qa/extras/tiledrendering/data/drop_down_form_field_noselection.odt | bin | 0 -> 8512 bytes | |||
-rw-r--r-- | sw/qa/extras/tiledrendering/tiledrendering.cxx | 77 | ||||
-rw-r--r-- | sw/source/core/crsr/bookmrk.cxx | 4 |
4 files changed, 79 insertions, 2 deletions
diff --git a/sw/qa/extras/tiledrendering/data/drop_down_form_field_noitem.odt b/sw/qa/extras/tiledrendering/data/drop_down_form_field_noitem.odt Binary files differnew file mode 100644 index 000000000000..c0b703320bec --- /dev/null +++ b/sw/qa/extras/tiledrendering/data/drop_down_form_field_noitem.odt diff --git a/sw/qa/extras/tiledrendering/data/drop_down_form_field_noselection.odt b/sw/qa/extras/tiledrendering/data/drop_down_form_field_noselection.odt Binary files differnew file mode 100644 index 000000000000..0c433c64707b --- /dev/null +++ b/sw/qa/extras/tiledrendering/data/drop_down_form_field_noselection.odt diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index 994188aaac6f..4d3e49f5643d 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -131,6 +131,8 @@ public: void testFieldmark(); void testDropDownFormFieldButton(); void testDropDownFormFieldButtonEditing(); + void testDropDownFormFieldButtonNoSelection(); + void testDropDownFormFieldButtonNoItem(); CPPUNIT_TEST_SUITE(SwTiledRenderingTest); CPPUNIT_TEST(testRegisterCallback); @@ -199,6 +201,8 @@ public: CPPUNIT_TEST(testFieldmark); CPPUNIT_TEST(testDropDownFormFieldButton); CPPUNIT_TEST(testDropDownFormFieldButtonEditing); + CPPUNIT_TEST(testDropDownFormFieldButtonNoSelection); + CPPUNIT_TEST(testDropDownFormFieldButtonNoItem); CPPUNIT_TEST_SUITE_END(); private: @@ -2675,6 +2679,79 @@ void SwTiledRenderingTest::testDropDownFormFieldButtonEditing() } } +void SwTiledRenderingTest::testDropDownFormFieldButtonNoSelection() +{ + SwXTextDocument* pXTextDocument = createDoc("drop_down_form_field_noselection.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); + + // None of the items is selected + 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); + } +} + +void SwTiledRenderingTest::testDropDownFormFieldButtonNoItem() +{ + SwXTextDocument* pXTextDocument = createDoc("drop_down_form_field_noitem.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); + + // There is not item specified for the field + CPPUNIT_ASSERT(!m_aFormFieldButton.isEmpty()); + { + std::stringstream aStream(m_aFormFieldButton.getStr()); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + + boost::property_tree::ptree aItems = aTree.get_child("params").get_child("items"); + CPPUNIT_ASSERT_EQUAL(size_t(0), aItems.size()); + + OString sSelected = aTree.get_child("params").get_child("selected").get_value<std::string>().c_str(); + CPPUNIT_ASSERT_EQUAL(OString("-1"), sSelected); + } +} + 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 e39c5ced6a05..3efdbf98167d 100644 --- a/sw/source/core/crsr/bookmrk.cxx +++ b/sw/source/core/crsr/bookmrk.cxx @@ -755,12 +755,12 @@ namespace sw::mark // Selected item OUString sResultKey = ODF_FORMDROPDOWN_RESULT; auto pSelectedItemIter = pParameters->find(sResultKey); + sal_Int32 nSelection = -1; if (pSelectedItemIter != pParameters->end()) { - sal_Int32 nSelection = -1; pSelectedItemIter->second >>= nSelection; - sPayload.append("\"selected\": \"" + OString::number(nSelection) + "\"}}"); } + sPayload.append("\"selected\": \"" + OString::number(nSelection) + "\"}}"); } else { |