diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:54:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:54:39 +0000 |
commit | 267c6f2ac71f92999e969232431ba04678e7437e (patch) | |
tree | 358c9467650e1d0a1d7227a21dac2e3d08b622b2 /sw/qa/uibase | |
parent | Initial commit. (diff) | |
download | libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.tar.xz libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.zip |
Adding upstream version 4:24.2.0.upstream/4%24.2.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sw/qa/uibase')
20 files changed, 3773 insertions, 0 deletions
diff --git a/sw/qa/uibase/dialog/dialog.cxx b/sw/qa/uibase/dialog/dialog.cxx new file mode 100644 index 0000000000..b7c1f766c3 --- /dev/null +++ b/sw/qa/uibase/dialog/dialog.cxx @@ -0,0 +1,59 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <swmodeltestbase.hxx> + +#include <comphelper/propertyvalue.hxx> + +#include <wrtsh.hxx> +#include <docsh.hxx> + +namespace +{ +/// Covers sw/source/uibase/dialog/ fixes. +class Test : public SwModelTestBase +{ +public: + Test() + : SwModelTestBase("/sw/qa/uibase/dialog/data/") + { + } +}; +} + +CPPUNIT_TEST_FIXTURE(Test, testInsertSection) +{ + // Given an empty document: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + + // When inserting a section with text: + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue( + "RegionName", uno::Any(OUString("ZOTERO_BIBL {} CSL_BIBLIOGRAPHY RNDRfiit6mXBc"))), + comphelper::makePropertyValue("Content", uno::Any(OUString("<p>aaa</p><p>bbb</p>"))), + }; + dispatchCommand(mxComponent, ".uno:InsertSection", aArgs); + + // Then make sure that we created a section that covers that text: + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->SttEndDoc(/*bStt=*/true); + pWrtShell->EndOfSection(/*bSelect=*/true); + SwCursor* pCursor = pWrtShell->GetCursor(); + OUString aActualResult = pCursor->GetText(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: aaa\nbbb + // - Actual : + // i.e. the value of the Content parameter was ignored. + CPPUNIT_ASSERT_EQUAL(OUString("aaa\nbbb"), aActualResult); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/uibase/dochdl/dochdl.cxx b/sw/qa/uibase/dochdl/dochdl.cxx new file mode 100644 index 0000000000..95314b48be --- /dev/null +++ b/sw/qa/uibase/dochdl/dochdl.cxx @@ -0,0 +1,81 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <swmodeltestbase.hxx> + +#include <vcl/transfer.hxx> +#include <editeng/wghtitem.hxx> +#include <editeng/postitem.hxx> +#include <editeng/udlnitem.hxx> + +#include <docsh.hxx> +#include <swdtflvr.hxx> +#include <wrtsh.hxx> +#include <view.hxx> + +/// Covers sw/source/uibase/dochdl/ fixes. +class SwUibaseDochdlTest : public SwModelTestBase +{ +}; + +CPPUNIT_TEST_FIXTURE(SwUibaseDochdlTest, testSelectPasteFormat) +{ + // Create a new document and cut a character. + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + SwDocShell* pDocShell = pDoc->GetDocShell(); + SwWrtShell* pWrtShell = pDocShell->GetWrtShell(); + pWrtShell->Insert2("x"); + pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/true, 1, /*bBasicCall=*/false); + rtl::Reference<SwTransferable> pTransfer = new SwTransferable(*pWrtShell); + pTransfer->Cut(); + + // Decide what format to use when doing a Writer->Writer paste and both RTF and ODF is an + // available format. + TransferableDataHelper aHelper(pTransfer); + sal_uInt8 nAction = EXCHG_OUT_ACTION_INSERT_STRING; + SotClipboardFormatId nFormat = SotClipboardFormatId::RICHTEXT; + SwTransferable::SelectPasteFormat(aHelper, nAction, nFormat); + + CPPUNIT_ASSERT_EQUAL(EXCHG_OUT_ACTION_INSERT_OLE, nAction); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 85 (EMBED_SOURCE) + // - Actual : 145 (RICHTEXT) + // i.e. RTF was selected for Writer->Writer out of process copying, which is worse than ODF. + CPPUNIT_ASSERT_EQUAL(SotClipboardFormatId::EMBED_SOURCE, nFormat); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseDochdlTest, testComplexSelection) +{ + // Given a document where a text node has hints, but no as-char images. + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + SwDocShell* pDocShell = pDoc->GetDocShell(); + SwWrtShell* pWrtShell = pDocShell->GetWrtShell(); + pWrtShell->Insert2("abc"); + pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false); + pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/true, 1, /*bBasicCall=*/false); + SfxItemSet aSet(pWrtShell->GetView().GetPool(), + svl::Items<RES_CHRATR_BEGIN, RES_CHRATR_END - 1>); + // Bold, italic, underline. + aSet.Put(SvxWeightItem(WEIGHT_BOLD, RES_CHRATR_WEIGHT)); + aSet.Put(SvxPostureItem(ITALIC_NORMAL, RES_CHRATR_POSTURE)); + aSet.Put(SvxUnderlineItem(LINESTYLE_SINGLE, RES_CHRATR_UNDERLINE)); + pWrtShell->SetAttrSet(aSet); + uno::Reference<datatransfer::XTransferable2> xTransfer = new SwTransferable(*pWrtShell); + + // When checking if the selection is complex, then there should be no crash. + // Without the accompanying fix in place, this test would have crashed, because we read past the + // end of the hints array. + CPPUNIT_ASSERT(!xTransfer->isComplex()); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/uibase/docvw/docvw.cxx b/sw/qa/uibase/docvw/docvw.cxx new file mode 100644 index 0000000000..280a045910 --- /dev/null +++ b/sw/qa/uibase/docvw/docvw.cxx @@ -0,0 +1,192 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <swmodeltestbase.hxx> + +#include <com/sun/star/text/XTextDocument.hpp> + +#include <vcl/event.hxx> + +#include <docsh.hxx> +#include <edtwin.hxx> +#include <flyfrm.hxx> +#include <frameformats.hxx> +#include <view.hxx> +#include <wrtsh.hxx> + +namespace +{ +/// Covers sw/source/uibase/docvw/ fixes. +class Test : public SwModelTestBase +{ +}; +} + +CPPUNIT_TEST_FIXTURE(Test, testShiftClickOnImage) +{ + // Given a document with a fly frame: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + uno::Reference<lang::XMultiServiceFactory> xMSF(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XText> xText = xTextDocument->getText(); + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + uno::Reference<beans::XPropertySet> xTextGraphic( + xMSF->createInstance("com.sun.star.text.TextGraphicObject"), uno::UNO_QUERY); + xTextGraphic->setPropertyValue("AnchorType", + uno::Any(text::TextContentAnchorType_AS_CHARACTER)); + xTextGraphic->setPropertyValue("Size", uno::Any(awt::Size(5000, 5000))); + uno::Reference<text::XTextContent> xTextContent(xTextGraphic, uno::UNO_QUERY); + xText->insertTextContent(xCursor, xTextContent, false); + pWrtShell->SttEndDoc(/*bStt=*/false); + + // When shift-clicking on that fly frame: + auto& rSpzFormats = *pDoc->GetSpzFrameFormats(); + auto pFrameFormat = dynamic_cast<SwFlyFrameFormat*>(rSpzFormats[0]); + CPPUNIT_ASSERT(pFrameFormat); + SwFlyFrame* pFlyFrame = pFrameFormat->GetFrame(); + vcl::Window& rEditWin = pDoc->GetDocShell()->GetView()->GetEditWin(); + Point aFlyCenter = rEditWin.LogicToPixel(pFlyFrame->getFrameArea().Center()); + MouseEvent aClickEvent(aFlyCenter, 1, MouseEventModifiers::SIMPLECLICK, MOUSE_LEFT, KEY_SHIFT); + rEditWin.MouseButtonDown(aClickEvent); + rEditWin.MouseButtonUp(aClickEvent); + + // Then make sure that the fly frame is selected: + SelectionType eType = pWrtShell->GetSelectionType(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 2 (SelectionType::Graphic) + // - Actual : 1 (SelectionType::Text) + // i.e. the fly frame was not selected, while a plain click or ctrl-click selected it. + CPPUNIT_ASSERT_EQUAL(SelectionType::Graphic, eType); +} + +namespace +{ +/// Interception implementation that catches the graphic dialog. +class GraphicDialogInterceptor : public cppu::WeakImplHelper<frame::XDispatchProviderInterceptor> +{ + uno::Reference<frame::XDispatchProvider> m_xMaster; + uno::Reference<frame::XDispatchProvider> m_xSlave; + int m_nGraphicDialogs = 0; + +public: + // XDispatchProviderInterceptor + uno::Reference<frame::XDispatchProvider> SAL_CALL getMasterDispatchProvider() override; + uno::Reference<frame::XDispatchProvider> SAL_CALL getSlaveDispatchProvider() override; + void SAL_CALL setMasterDispatchProvider( + const uno::Reference<frame::XDispatchProvider>& xNewSupplier) override; + void SAL_CALL + setSlaveDispatchProvider(const uno::Reference<frame::XDispatchProvider>& xNewSupplier) override; + + // XDispatchProvider + uno::Reference<frame::XDispatch> SAL_CALL queryDispatch(const util::URL& rURL, + const OUString& rTargetFrameName, + sal_Int32 SearchFlags) override; + uno::Sequence<uno::Reference<frame::XDispatch>> SAL_CALL + queryDispatches(const uno::Sequence<frame::DispatchDescriptor>& rRequests) override; + + int GetGraphicDialogs() const; +}; +} + +uno::Reference<frame::XDispatchProvider> GraphicDialogInterceptor::getMasterDispatchProvider() +{ + return m_xMaster; +} + +uno::Reference<frame::XDispatchProvider> GraphicDialogInterceptor::getSlaveDispatchProvider() +{ + return m_xSlave; +} + +void GraphicDialogInterceptor::setMasterDispatchProvider( + const uno::Reference<frame::XDispatchProvider>& xNewSupplier) +{ + m_xMaster = xNewSupplier; +} + +void GraphicDialogInterceptor::setSlaveDispatchProvider( + const uno::Reference<frame::XDispatchProvider>& xNewSupplier) +{ + m_xSlave = xNewSupplier; +} + +uno::Reference<frame::XDispatch> +GraphicDialogInterceptor::queryDispatch(const util::URL& rURL, const OUString& rTargetFrameName, + sal_Int32 nSearchFlags) +{ + if (rURL.Complete == ".uno:GraphicDialog") + { + ++m_nGraphicDialogs; + } + + return m_xSlave->queryDispatch(rURL, rTargetFrameName, nSearchFlags); +} + +uno::Sequence<uno::Reference<frame::XDispatch>> GraphicDialogInterceptor::queryDispatches( + const uno::Sequence<frame::DispatchDescriptor>& /*rRequests*/) +{ + return {}; +} + +int GraphicDialogInterceptor::GetGraphicDialogs() const { return m_nGraphicDialogs; } + +CPPUNIT_TEST_FIXTURE(Test, testShiftDoubleClickOnImage) +{ + // Given a document with a fly frame, and an interceptor to catch the graphic dialog: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + uno::Reference<lang::XMultiServiceFactory> xMSF(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XText> xText = xTextDocument->getText(); + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + uno::Reference<beans::XPropertySet> xTextGraphic( + xMSF->createInstance("com.sun.star.text.TextGraphicObject"), uno::UNO_QUERY); + xTextGraphic->setPropertyValue("AnchorType", + uno::Any(text::TextContentAnchorType_AS_CHARACTER)); + xTextGraphic->setPropertyValue("Size", uno::Any(awt::Size(5000, 5000))); + uno::Reference<text::XTextContent> xTextContent(xTextGraphic, uno::UNO_QUERY); + xText->insertTextContent(xCursor, xTextContent, false); + pWrtShell->SttEndDoc(/*bStt=*/false); + uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); + uno::Reference<frame::XDispatchProviderInterception> xRegistration( + xModel->getCurrentController()->getFrame(), uno::UNO_QUERY); + rtl::Reference pInterceptor(new GraphicDialogInterceptor); + xRegistration->registerDispatchProviderInterceptor(pInterceptor); + + // When shift-double-clicking on that fly frame: + auto& rSpzFormats = *pDoc->GetSpzFrameFormats(); + auto pFrameFormat = dynamic_cast<SwFlyFrameFormat*>(rSpzFormats[0]); + CPPUNIT_ASSERT(pFrameFormat); + SwFlyFrame* pFlyFrame = pFrameFormat->GetFrame(); + vcl::Window& rEditWin = pDoc->GetDocShell()->GetView()->GetEditWin(); + Point aFlyCenter = rEditWin.LogicToPixel(pFlyFrame->getFrameArea().Center()); + MouseEvent aClickEvent(aFlyCenter, 1, MouseEventModifiers::SIMPLECLICK, MOUSE_LEFT, KEY_SHIFT); + rEditWin.MouseButtonDown(aClickEvent); + rEditWin.MouseButtonUp(aClickEvent); + aClickEvent + = MouseEvent(aFlyCenter, 2, MouseEventModifiers::SIMPLECLICK, MOUSE_LEFT, KEY_SHIFT); + rEditWin.MouseButtonDown(aClickEvent); + rEditWin.MouseButtonUp(aClickEvent); + + // Then make sure that the fly frame's dialog is dispatched: + int nGraphicDialogs = pInterceptor->GetGraphicDialogs(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected greater than: 0 (2) + // - Actual : 0 + // i.e. the fly frame's dialog was not dispatched, while a plain click or ctrl-click dispatched + // it. + CPPUNIT_ASSERT_GREATER(0, nGraphicDialogs); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/uibase/fldui/fldui.cxx b/sw/qa/uibase/fldui/fldui.cxx new file mode 100644 index 0000000000..0bf6bfa33f --- /dev/null +++ b/sw/qa/uibase/fldui/fldui.cxx @@ -0,0 +1,171 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <swmodeltestbase.hxx> + +#include <com/sun/star/text/BibliographyDataType.hpp> +#include <com/sun/star/text/XTextDocument.hpp> + +#include <rtl/ustrbuf.hxx> +#include <comphelper/propertyvalue.hxx> + +#include <docsh.hxx> +#include <wrtsh.hxx> +#include <fldmgr.hxx> +#include <authfld.hxx> +#include <ndtxt.hxx> + +using namespace com::sun::star; + +namespace +{ +/// Covers sw/source/uibase/fldui/ fixes. +class Test : public SwModelTestBase +{ +}; + +CPPUNIT_TEST_FIXTURE(Test, testBiblioPageNumberUpdate) +{ + // Given a document with 2 biblio fields, same properties, but different page number in the URL: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xField( + xFactory->createInstance("com.sun.star.text.TextField.Bibliography"), uno::UNO_QUERY); + uno::Sequence<beans::PropertyValue> aFields = { + comphelper::makePropertyValue("BibiliographicType", text::BibliographyDataType::WWW), + comphelper::makePropertyValue("Identifier", OUString("AT")), + comphelper::makePropertyValue("Author", OUString("Author")), + comphelper::makePropertyValue("Title", OUString("Title")), + comphelper::makePropertyValue("URL", OUString("http://www.example.com/test.pdf#page=1")), + }; + xField->setPropertyValue("Fields", uno::Any(aFields)); + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XText> xText = xTextDocument->getText(); + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + uno::Reference<text::XTextContent> xContent(xField, uno::UNO_QUERY); + xText->insertTextContent(xCursor, xContent, /*bAbsorb=*/false); + xField.set(xFactory->createInstance("com.sun.star.text.TextField.Bibliography"), + uno::UNO_QUERY); + aFields = { + comphelper::makePropertyValue("BibiliographicType", text::BibliographyDataType::WWW), + comphelper::makePropertyValue("Identifier", OUString("AT")), + comphelper::makePropertyValue("Author", OUString("Author")), + comphelper::makePropertyValue("Title", OUString("Title")), + comphelper::makePropertyValue("URL", OUString("http://www.example.com/test.pdf#page=2")), + }; + xField->setPropertyValue("Fields", uno::Any(aFields)); + xContent.set(xField, uno::UNO_QUERY); + xText->insertTextContent(xCursor, xContent, /*bAbsorb=*/false); + + // When changing the page number in the second field's URL: + SwDocShell* pDocShell = pDoc->GetDocShell(); + SwWrtShell* pWrtShell = pDocShell->GetWrtShell(); + pWrtShell->SttEndDoc(/*bStt=*/false); + pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false); + OUString aCoreFields[AUTH_FIELD_END]; + aCoreFields[AUTH_FIELD_AUTHORITY_TYPE] = OUString::number(text::BibliographyDataType::WWW); + aCoreFields[AUTH_FIELD_IDENTIFIER] = "AT"; + aCoreFields[AUTH_FIELD_AUTHOR] = "Author"; + aCoreFields[AUTH_FIELD_TITLE] = "Title"; + OUString aNewUrl = "http://www.example.com/test.pdf#page=42"; + aCoreFields[AUTH_FIELD_URL] = aNewUrl; + OUStringBuffer aFieldBuffer; + for (const auto& rField : aCoreFields) + { + aFieldBuffer.append(rField + OUStringChar(TOX_STYLE_DELIMITER)); + } + SwFieldMgr aMgr(pWrtShell); + aMgr.UpdateCurField(0, aFieldBuffer.makeStringAndClear(), OUString()); + + // Then make sure that the second field's URL is updated: + auto pField = static_cast<SwAuthorityField*>(pWrtShell->GetCurField()); + const SwAuthEntry* pEntry = pField->GetAuthEntry(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: http://www.example.com/test.pdf#page=42 + // - Actual : http://www.example.com/test.pdf#page=2 + // i.e. the second biblio field's URL was not updated. + CPPUNIT_ASSERT_EQUAL(aNewUrl, pEntry->GetAuthorField(AUTH_FIELD_URL)); +} + +CPPUNIT_TEST_FIXTURE(Test, testInsertRefmark) +{ + // Given an empty document: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + + // When inserting a refmark with text: + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("TypeName", uno::Any(OUString("SetRef"))), + comphelper::makePropertyValue( + "Name", uno::Any(OUString("ZOTERO_ITEM CSL_CITATION {} RNDpyJknp173F"))), + comphelper::makePropertyValue("Content", uno::Any(OUString("aaa<b>bbb</b>ccc"))), + }; + dispatchCommand(mxComponent, ".uno:InsertField", aArgs); + + // Then make sure that we create a refmark that covers that text: + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + SwTextNode* pTextNode = pWrtShell->GetCursor()->GetPointNode().GetTextNode(); + std::vector<SwTextAttr*> aAttrs = pTextNode->GetTextAttrsAt(0, RES_TXTATR_REFMARK); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 0 + // i.e. no refmark was created, only the hard to read Type=12 created a refmark. + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aAttrs.size()); + CPPUNIT_ASSERT_EQUAL(OUString("aaabbbccc"), pTextNode->GetText()); +} + +CPPUNIT_TEST_FIXTURE(Test, testTdf68364InsertConditionalFieldWithTwoDots) +{ + // Create an empty document + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + + // Insert a conditional field containing exactly two dots for its condition + SwFieldMgr aFieldMgr(pWrtShell); + SwInsertField_Data aFieldData(SwFieldTypesEnum::ConditionalText, 0, "true", "19.12.2023", 0); + CPPUNIT_ASSERT(aFieldMgr.InsertField(aFieldData)); + pWrtShell->SttEndDoc(true); + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 19.12.2023 + // - Actual : + CPPUNIT_ASSERT_EQUAL(OUString("19.12.2023"), + pWrtShell->GetCurField()->ExpandField(true, nullptr)); +} + +CPPUNIT_TEST_FIXTURE(Test, testInsertRefmarkSelection) +{ + // Given a document with a single selected word: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->Insert2("myword"); + pWrtShell->SelAll(); + + // When inserting a refmark: + SwFieldMgr aMgr(pWrtShell); + SwInsertField_Data aData(SwFieldTypesEnum::SetRef, /*nSubType=*/0, "myname", "myword", + /*nFormatId=*/0); + aMgr.InsertField(aData); + + // Then make sure the document still just contains that word only once: + SwTextNode* pTextNode = pWrtShell->GetCursor()->GetPointNode().GetTextNode(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: myword + // - Actual : mywordmyword + // i.e. the content of the selection was duplicated. + CPPUNIT_ASSERT_EQUAL(OUString("myword"), pTextNode->GetText()); +} +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/uibase/frmdlg/data/image.png b/sw/qa/uibase/frmdlg/data/image.png Binary files differnew file mode 100644 index 0000000000..fdad35484e --- /dev/null +++ b/sw/qa/uibase/frmdlg/data/image.png diff --git a/sw/qa/uibase/frmdlg/data/wrapped-math-object.docx b/sw/qa/uibase/frmdlg/data/wrapped-math-object.docx Binary files differnew file mode 100644 index 0000000000..c6f76dd5d7 --- /dev/null +++ b/sw/qa/uibase/frmdlg/data/wrapped-math-object.docx diff --git a/sw/qa/uibase/frmdlg/frmdlg.cxx b/sw/qa/uibase/frmdlg/frmdlg.cxx new file mode 100644 index 0000000000..81a7746170 --- /dev/null +++ b/sw/qa/uibase/frmdlg/frmdlg.cxx @@ -0,0 +1,110 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <swmodeltestbase.hxx> + +#include <comphelper/propertyvalue.hxx> + +#include <com/sun/star/text/TextContentAnchorType.hpp> + +#include <docsh.hxx> +#include <wrtsh.hxx> +#include <frmmgr.hxx> +#include <itabenum.hxx> + +/// Covers sw/source/uibase/frmdlg/ fixes. +class SwUibaseFrmdlgTest : public SwModelTestBase +{ +public: + SwUibaseFrmdlgTest() + : SwModelTestBase("/sw/qa/uibase/frmdlg/data/") + { + } +}; + +CPPUNIT_TEST_FIXTURE(SwUibaseFrmdlgTest, testWrappedMathObject) +{ + // The document includes a Math object with explicit wrapping. + createSwDoc("wrapped-math-object.docx"); + uno::Reference<drawing::XShape> xMath = getShape(1); + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 4 (AT_CHARACTER) + // - Actual : 1 (AS_CHARACTER) + // i.e. the object lost its wrapping, leading to an incorrect position. + CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AT_CHARACTER, + getProperty<text::TextContentAnchorType>(getShape(1), "AnchorType")); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseFrmdlgTest, testAnchorTypeFromStyle) +{ + // Given a document with aGraphics style with anchor type set to as-character: + createSwDoc(); + uno::Reference<beans::XPropertySet> xGraphics(getStyles("FrameStyles")->getByName("Graphics"), + uno::UNO_QUERY); + xGraphics->setPropertyValue("AnchorType", uno::Any(text::TextContentAnchorType_AS_CHARACTER)); + + // When inserting an image: + uno::Sequence<beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("FileName", createFileURL(u"image.png")), + }; + dispatchCommand(mxComponent, ".uno:InsertGraphic", aArgs); + + // Then make sure the image's anchor type is as-char: + auto eActual = getProperty<text::TextContentAnchorType>(getShape(1), "AnchorType"); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 (AS_CHARACTER) + // - Actual : 4 (AT_CHARACTER) + // i.e. the anchor type from the style was ignored. + CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AS_CHARACTER, eActual); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseFrmdlgTest, testInsertFrameWidth) +{ + // Given a document with an inline table, its width is set to 6000 twips: + createSwDoc(); + // Insert a table: + SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); + SwInsertTableOptions aTableOptions(SwInsertTableFlags::DefaultBorder, 0); + pWrtShell->InsertTable(aTableOptions, /*nRows=*/1, /*nCols=*/1); + pWrtShell->MoveTable(GotoPrevTable, fnTableStart); + SwTwips nExpectedWidth = 6000; + { + SfxItemSetFixed<RES_FRMATR_BEGIN, RES_FRMATR_END - 1> aSet(pWrtShell->GetAttrPool()); + SwFormatFrameSize aSize(SwFrameSize::Variable, nExpectedWidth); + aSet.Put(aSize); + pWrtShell->SetTableAttr(aSet); + } + pWrtShell->GoPrevCell(); + pWrtShell->Insert("A1"); + SwFormatFrameSize aRowSize(SwFrameSize::Minimum); + pWrtShell->SetRowHeight(aRowSize); + pWrtShell->GoNextCell(); + pWrtShell->Insert("A2"); + pWrtShell->SetRowHeight(aRowSize); + // Select cell: + pWrtShell->SelAll(); + // Select table: + pWrtShell->SelAll(); + + // When converting that table to a floating table: + SwFlyFrameAttrMgr aMgr(/*bNew=*/true, pWrtShell, Frmmgr_Type::TEXT, nullptr); + + // Then make sure that the fly width will be based on the table width: + const SwFormatFrameSize* pFrameSize = aMgr.GetAttrSet().GetItem(RES_FRM_SIZE); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 6000 (nExpectedWidth) + // - Actual : 1134 (2cm) + // i.e. the fly width was the default, not inherited from the selected table. + CPPUNIT_ASSERT_EQUAL(nExpectedWidth, pFrameSize->GetWidth()); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/uibase/shells/data/ole-preview-update.odt b/sw/qa/uibase/shells/data/ole-preview-update.odt Binary files differnew file mode 100644 index 0000000000..3fd4d26462 --- /dev/null +++ b/sw/qa/uibase/shells/data/ole-preview-update.odt diff --git a/sw/qa/uibase/shells/data/ole-save-preview-update.odt b/sw/qa/uibase/shells/data/ole-save-preview-update.odt Binary files differnew file mode 100644 index 0000000000..353ce7fa05 --- /dev/null +++ b/sw/qa/uibase/shells/data/ole-save-preview-update.odt diff --git a/sw/qa/uibase/shells/data/protectedLinkCopy.fodt b/sw/qa/uibase/shells/data/protectedLinkCopy.fodt new file mode 100644 index 0000000000..495f752376 --- /dev/null +++ b/sw/qa/uibase/shells/data/protectedLinkCopy.fodt @@ -0,0 +1,536 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<office:document xmlns:css3t="http://www.w3.org/TR/css3-text/" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:drawooo="http://openoffice.org/2010/draw" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:rpt="http://openoffice.org/2005/report" xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:officeooo="http://openoffice.org/2009/office" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text"> + <office:meta><meta:creation-date>2023-04-19T10:13:19.940360871</meta:creation-date><dc:date>2023-04-19T10:20:31.730384611</dc:date><meta:editing-duration>PT7M24S</meta:editing-duration><meta:editing-cycles>1</meta:editing-cycles><meta:document-statistic meta:table-count="0" meta:image-count="0" meta:object-count="0" meta:page-count="1" meta:paragraph-count="5" meta:word-count="5" meta:character-count="72" meta:non-whitespace-character-count="72"/><meta:generator>LibreOfficeDev/7.6.0.0.alpha0$Linux_X86_64 LibreOffice_project/57ff98147490ea69eb2968bcaf75edfe72f88645</meta:generator></office:meta> + <office:settings> + <config:config-item-set config:name="ooo:view-settings"> + <config:config-item config:name="ViewAreaTop" config:type="long">0</config:config-item> + <config:config-item config:name="ViewAreaLeft" config:type="long">0</config:config-item> + <config:config-item config:name="ViewAreaWidth" config:type="long">26615</config:config-item> + <config:config-item config:name="ViewAreaHeight" config:type="long">15436</config:config-item> + <config:config-item config:name="ShowRedlineChanges" config:type="boolean">true</config:config-item> + <config:config-item config:name="InBrowseMode" config:type="boolean">false</config:config-item> + <config:config-item-map-indexed config:name="Views"> + <config:config-item-map-entry> + <config:config-item config:name="ViewId" config:type="string">view2</config:config-item> + <config:config-item config:name="ViewLeft" config:type="long">4807</config:config-item> + <config:config-item config:name="ViewTop" config:type="long">7195</config:config-item> + <config:config-item config:name="VisibleLeft" config:type="long">0</config:config-item> + <config:config-item config:name="VisibleTop" config:type="long">0</config:config-item> + <config:config-item config:name="VisibleRight" config:type="long">26614</config:config-item> + <config:config-item config:name="VisibleBottom" config:type="long">15434</config:config-item> + <config:config-item config:name="ZoomType" config:type="short">0</config:config-item> + <config:config-item config:name="ViewLayoutColumns" config:type="short">1</config:config-item> + <config:config-item config:name="ViewLayoutBookMode" config:type="boolean">false</config:config-item> + <config:config-item config:name="ZoomFactor" config:type="short">120</config:config-item> + <config:config-item config:name="IsSelectedFrame" config:type="boolean">false</config:config-item> + <config:config-item config:name="KeepRatio" config:type="boolean">false</config:config-item> + <config:config-item config:name="AnchoredTextOverflowLegacy" config:type="boolean">false</config:config-item> + <config:config-item config:name="LegacySingleLineFontwork" config:type="boolean">false</config:config-item> + <config:config-item config:name="ConnectorUseSnapRect" config:type="boolean">false</config:config-item> + <config:config-item config:name="IgnoreBreakAfterMultilineField" config:type="boolean">false</config:config-item> + </config:config-item-map-entry> + </config:config-item-map-indexed> + </config:config-item-set> + <config:config-item-set config:name="ooo:configuration-settings"> + <config:config-item config:name="PrintRightPages" config:type="boolean">true</config:config-item> + <config:config-item config:name="PrintProspectRTL" config:type="boolean">false</config:config-item> + <config:config-item config:name="PrintLeftPages" config:type="boolean">true</config:config-item> + <config:config-item config:name="PrintPaperFromSetup" config:type="boolean">false</config:config-item> + <config:config-item config:name="PrintControls" config:type="boolean">true</config:config-item> + <config:config-item config:name="PrintProspect" config:type="boolean">false</config:config-item> + <config:config-item config:name="PrintBlackFonts" config:type="boolean">false</config:config-item> + <config:config-item config:name="PrintEmptyPages" config:type="boolean">true</config:config-item> + <config:config-item config:name="PrintSingleJobs" config:type="boolean">false</config:config-item> + <config:config-item config:name="PrintAnnotationMode" config:type="short">0</config:config-item> + <config:config-item config:name="WordLikeWrapForAsCharFlys" config:type="boolean">false</config:config-item> + <config:config-item config:name="AutoFirstLineIndentDisregardLineSpace" config:type="boolean">true</config:config-item> + <config:config-item config:name="HeaderSpacingBelowLastPara" config:type="boolean">false</config:config-item> + <config:config-item config:name="ProtectBookmarks" config:type="boolean">false</config:config-item> + <config:config-item config:name="ContinuousEndnotes" config:type="boolean">false</config:config-item> + <config:config-item config:name="DisableOffPagePositioning" config:type="boolean">false</config:config-item> + <config:config-item config:name="PrintTables" config:type="boolean">true</config:config-item> + <config:config-item config:name="SubtractFlysAnchoredAtFlys" config:type="boolean">false</config:config-item> + <config:config-item config:name="ApplyParagraphMarkFormatToNumbering" config:type="boolean">false</config:config-item> + <config:config-item config:name="PrintFaxName" config:type="string"/> + <config:config-item config:name="SurroundTextWrapSmall" config:type="boolean">false</config:config-item> + <config:config-item config:name="TreatSingleColumnBreakAsPageBreak" config:type="boolean">false</config:config-item> + <config:config-item config:name="PropLineSpacingShrinksFirstLine" config:type="boolean">true</config:config-item> + <config:config-item config:name="TabOverSpacing" config:type="boolean">false</config:config-item> + <config:config-item config:name="TabOverMargin" config:type="boolean">false</config:config-item> + <config:config-item config:name="EmbedComplexScriptFonts" config:type="boolean">true</config:config-item> + <config:config-item config:name="EmbedLatinScriptFonts" config:type="boolean">true</config:config-item> + <config:config-item config:name="EmbedOnlyUsedFonts" config:type="boolean">false</config:config-item> + <config:config-item config:name="EmbedFonts" config:type="boolean">false</config:config-item> + <config:config-item config:name="ClippedPictures" config:type="boolean">false</config:config-item> + <config:config-item config:name="FrameAutowidthWithMorePara" config:type="boolean">false</config:config-item> + <config:config-item config:name="FloattableNomargins" config:type="boolean">false</config:config-item> + <config:config-item config:name="UnbreakableNumberings" config:type="boolean">false</config:config-item> + <config:config-item config:name="AllowPrintJobCancel" config:type="boolean">true</config:config-item> + <config:config-item config:name="UseFormerObjectPositioning" config:type="boolean">false</config:config-item> + <config:config-item config:name="UseOldNumbering" config:type="boolean">false</config:config-item> + <config:config-item config:name="RsidRoot" config:type="int">472471</config:config-item> + <config:config-item config:name="PrinterPaperFromSetup" config:type="boolean">false</config:config-item> + <config:config-item config:name="CurrentDatabaseDataSource" config:type="string"/> + <config:config-item config:name="UpdateFromTemplate" config:type="boolean">true</config:config-item> + <config:config-item config:name="AddFrameOffsets" config:type="boolean">false</config:config-item> + <config:config-item config:name="LoadReadonly" config:type="boolean">false</config:config-item> + <config:config-item config:name="Rsid" config:type="int">472471</config:config-item> + <config:config-item config:name="FootnoteInColumnToPageEnd" config:type="boolean">true</config:config-item> + <config:config-item config:name="ProtectFields" config:type="boolean">false</config:config-item> + <config:config-item config:name="SaveGlobalDocumentLinks" config:type="boolean">false</config:config-item> + <config:config-item config:name="ClipAsCharacterAnchoredWriterFlyFrames" config:type="boolean">false</config:config-item> + <config:config-item config:name="LinkUpdateMode" config:type="short">1</config:config-item> + <config:config-item config:name="AddExternalLeading" config:type="boolean">true</config:config-item> + <config:config-item config:name="PrintGraphics" config:type="boolean">true</config:config-item> + <config:config-item config:name="EmbedSystemFonts" config:type="boolean">false</config:config-item> + <config:config-item config:name="IsLabelDocument" config:type="boolean">false</config:config-item> + <config:config-item config:name="AddParaLineSpacingToTableCells" config:type="boolean">true</config:config-item> + <config:config-item config:name="UseFormerTextWrapping" config:type="boolean">false</config:config-item> + <config:config-item config:name="HyphenateURLs" config:type="boolean">false</config:config-item> + <config:config-item config:name="AddParaTableSpacingAtStart" config:type="boolean">true</config:config-item> + <config:config-item config:name="TabsRelativeToIndent" config:type="boolean">true</config:config-item> + <config:config-item config:name="FieldAutoUpdate" config:type="boolean">true</config:config-item> + <config:config-item config:name="SaveVersionOnClose" config:type="boolean">false</config:config-item> + <config:config-item config:name="ChartAutoUpdate" config:type="boolean">true</config:config-item> + <config:config-item config:name="ImagePreferredDPI" config:type="int">0</config:config-item> + <config:config-item config:name="PrinterSetup" config:type="base64Binary"/> + <config:config-item config:name="SmallCapsPercentage66" config:type="boolean">false</config:config-item> + <config:config-item config:name="AlignTabStopPosition" config:type="boolean">true</config:config-item> + <config:config-item config:name="DropCapPunctuation" config:type="boolean">true</config:config-item> + <config:config-item config:name="MathBaselineAlignment" config:type="boolean">true</config:config-item> + <config:config-item config:name="PrinterName" config:type="string"/> + <config:config-item config:name="CharacterCompressionType" config:type="short">0</config:config-item> + <config:config-item config:name="AddParaTableSpacing" config:type="boolean">true</config:config-item> + <config:config-item config:name="DoNotJustifyLinesWithManualBreak" config:type="boolean">false</config:config-item> + <config:config-item config:name="PrintHiddenText" config:type="boolean">false</config:config-item> + <config:config-item config:name="IsKernAsianPunctuation" config:type="boolean">false</config:config-item> + <config:config-item config:name="PrinterIndependentLayout" config:type="string">high-resolution</config:config-item> + <config:config-item config:name="TabOverflow" config:type="boolean">true</config:config-item> + <config:config-item config:name="AddParaSpacingToTableCells" config:type="boolean">true</config:config-item> + <config:config-item config:name="AddVerticalFrameOffsets" config:type="boolean">false</config:config-item> + <config:config-item config:name="TabAtLeftIndentForParagraphsInList" config:type="boolean">false</config:config-item> + <config:config-item config:name="ApplyUserData" config:type="boolean">true</config:config-item> + <config:config-item config:name="MsWordCompMinLineHeightByFly" config:type="boolean">false</config:config-item> + <config:config-item config:name="PrintTextPlaceholder" config:type="boolean">false</config:config-item> + <config:config-item config:name="IgnoreFirstLineIndentInNumbering" config:type="boolean">false</config:config-item> + <config:config-item config:name="UseFormerLineSpacing" config:type="boolean">false</config:config-item> + <config:config-item config:name="PrintPageBackground" config:type="boolean">true</config:config-item> + <config:config-item config:name="RedlineProtectionKey" config:type="base64Binary"/> + <config:config-item config:name="EmbedAsianScriptFonts" config:type="boolean">true</config:config-item> + <config:config-item config:name="BackgroundParaOverDrawings" config:type="boolean">false</config:config-item> + <config:config-item config:name="SaveThumbnail" config:type="boolean">true</config:config-item> + <config:config-item config:name="ConsiderTextWrapOnObjPos" config:type="boolean">false</config:config-item> + <config:config-item config:name="EmbeddedDatabaseName" config:type="string"/> + <config:config-item config:name="ProtectForm" config:type="boolean">false</config:config-item> + <config:config-item config:name="DoNotResetParaAttrsForNumFont" config:type="boolean">false</config:config-item> + <config:config-item config:name="MsWordCompTrailingBlanks" config:type="boolean">false</config:config-item> + <config:config-item config:name="EmptyDbFieldHidesPara" config:type="boolean">true</config:config-item> + <config:config-item config:name="TableRowKeep" config:type="boolean">false</config:config-item> + <config:config-item config:name="NoNumberingShowFollowBy" config:type="boolean">false</config:config-item> + <config:config-item config:name="InvertBorderSpacing" config:type="boolean">false</config:config-item> + <config:config-item config:name="IgnoreTabsAndBlanksForLineCalculation" config:type="boolean">false</config:config-item> + <config:config-item config:name="DoNotCaptureDrawObjsOnPage" config:type="boolean">false</config:config-item> + <config:config-item config:name="GutterAtTop" config:type="boolean">false</config:config-item> + <config:config-item config:name="StylesNoDefault" config:type="boolean">false</config:config-item> + <config:config-item config:name="UnxForceZeroExtLeading" config:type="boolean">false</config:config-item> + <config:config-item config:name="PrintReversed" config:type="boolean">false</config:config-item> + <config:config-item config:name="UseOldPrinterMetrics" config:type="boolean">false</config:config-item> + <config:config-item config:name="CurrentDatabaseCommandType" config:type="int">0</config:config-item> + <config:config-item config:name="PrintDrawings" config:type="boolean">true</config:config-item> + <config:config-item config:name="OutlineLevelYieldsNumbering" config:type="boolean">false</config:config-item> + <config:config-item config:name="CurrentDatabaseCommand" config:type="string"/> + <config:config-item config:name="CollapseEmptyCellPara" config:type="boolean">true</config:config-item> + </config:config-item-set> + </office:settings> + <office:scripts> + <office:script script:language="ooo:Basic"> + <ooo:libraries xmlns:ooo="http://openoffice.org/2004/office" xmlns:xlink="http://www.w3.org/1999/xlink"/> + </office:script> + </office:scripts> + <office:font-face-decls> + <style:font-face style:name="Droid Sans Devanagari" svg:font-family="'Droid Sans Devanagari'" style:font-family-generic="swiss"/> + <style:font-face style:name="Droid Sans Devanagari1" svg:font-family="'Droid Sans Devanagari'" style:font-family-generic="system" style:font-pitch="variable"/> + <style:font-face style:name="Droid Sans Fallback" svg:font-family="'Droid Sans Fallback'" style:font-family-generic="system" style:font-pitch="variable"/> + <style:font-face style:name="Liberation Sans" svg:font-family="'Liberation Sans'" style:font-family-generic="swiss" style:font-pitch="variable"/> + <style:font-face style:name="Liberation Serif" svg:font-family="'Liberation Serif'" style:font-family-generic="roman" style:font-pitch="variable"/> + <style:font-face style:name="Source Han Sans CN" svg:font-family="'Source Han Sans CN'" style:font-family-generic="system" style:font-pitch="variable"/> + </office:font-face-decls> + <office:styles> + <style:default-style style:family="graphic"> + <style:graphic-properties svg:stroke-color="#3465a4" draw:fill-color="#729fcf" fo:wrap-option="no-wrap" draw:shadow-offset-x="0.3cm" draw:shadow-offset-y="0.3cm" draw:start-line-spacing-horizontal="0.283cm" draw:start-line-spacing-vertical="0.283cm" draw:end-line-spacing-horizontal="0.283cm" draw:end-line-spacing-vertical="0.283cm" style:flow-with-text="false"/> + <style:paragraph-properties style:text-autospace="ideograph-alpha" style:line-break="strict" loext:tab-stop-distance="0cm" style:writing-mode="lr-tb" style:font-independent-line-spacing="false"> + <style:tab-stops/> + </style:paragraph-properties> + <style:text-properties style:use-window-font-color="true" loext:opacity="0%" style:font-name="Liberation Serif" fo:font-size="12pt" fo:language="cs" fo:country="CZ" style:letter-kerning="true" style:font-name-asian="Droid Sans Fallback" style:font-size-asian="10.5pt" style:language-asian="zh" style:country-asian="CN" style:font-name-complex="Droid Sans Devanagari1" style:font-size-complex="12pt" style:language-complex="hi" style:country-complex="IN"/> + </style:default-style> + <style:default-style style:family="paragraph"> + <style:paragraph-properties fo:orphans="2" fo:widows="2" fo:hyphenation-ladder-count="no-limit" style:text-autospace="ideograph-alpha" style:punctuation-wrap="hanging" style:line-break="strict" style:tab-stop-distance="1.251cm" style:writing-mode="page"/> + <style:text-properties style:use-window-font-color="true" loext:opacity="0%" style:font-name="Liberation Serif" fo:font-size="12pt" fo:language="cs" fo:country="CZ" style:letter-kerning="true" style:font-name-asian="Droid Sans Fallback" style:font-size-asian="10.5pt" style:language-asian="zh" style:country-asian="CN" style:font-name-complex="Droid Sans Devanagari1" style:font-size-complex="12pt" style:language-complex="hi" style:country-complex="IN" fo:hyphenate="false" fo:hyphenation-remain-char-count="2" fo:hyphenation-push-char-count="2" loext:hyphenation-no-caps="false" loext:hyphenation-no-last-word="false" loext:hyphenation-word-char-count="5" loext:hyphenation-zone="no-limit"/> + </style:default-style> + <style:default-style style:family="table"> + <style:table-properties table:border-model="collapsing"/> + </style:default-style> + <style:default-style style:family="table-row"> + <style:table-row-properties fo:keep-together="auto"/> + </style:default-style> + <style:style style:name="Standard" style:family="paragraph" style:class="text"/> + <style:style style:name="Heading" style:family="paragraph" style:parent-style-name="Standard" style:next-style-name="Text_20_body" style:class="text"> + <style:paragraph-properties fo:margin-top="0.423cm" fo:margin-bottom="0.212cm" style:contextual-spacing="false" fo:keep-with-next="always"/> + <style:text-properties style:font-name="Liberation Sans" fo:font-family="'Liberation Sans'" style:font-family-generic="swiss" style:font-pitch="variable" fo:font-size="14pt" style:font-name-asian="Source Han Sans CN" style:font-family-asian="'Source Han Sans CN'" style:font-family-generic-asian="system" style:font-pitch-asian="variable" style:font-size-asian="14pt" style:font-name-complex="Droid Sans Devanagari1" style:font-family-complex="'Droid Sans Devanagari'" style:font-family-generic-complex="system" style:font-pitch-complex="variable" style:font-size-complex="14pt"/> + </style:style> + <style:style style:name="Text_20_body" style:display-name="Text body" style:family="paragraph" style:parent-style-name="Standard" style:class="text"> + <style:paragraph-properties fo:margin-top="0cm" fo:margin-bottom="0.247cm" style:contextual-spacing="false" fo:line-height="115%"/> + </style:style> + <style:style style:name="List" style:family="paragraph" style:parent-style-name="Text_20_body" style:class="list"> + <style:text-properties style:font-size-asian="12pt" style:font-name-complex="Droid Sans Devanagari" style:font-family-complex="'Droid Sans Devanagari'" style:font-family-generic-complex="swiss"/> + </style:style> + <style:style style:name="Caption" style:family="paragraph" style:parent-style-name="Standard" style:class="extra"> + <style:paragraph-properties fo:margin-top="0.212cm" fo:margin-bottom="0.212cm" style:contextual-spacing="false" text:number-lines="false" text:line-number="0"/> + <style:text-properties fo:font-size="12pt" fo:font-style="italic" style:font-size-asian="12pt" style:font-style-asian="italic" style:font-name-complex="Droid Sans Devanagari" style:font-family-complex="'Droid Sans Devanagari'" style:font-family-generic-complex="swiss" style:font-size-complex="12pt" style:font-style-complex="italic"/> + </style:style> + <style:style style:name="Index" style:family="paragraph" style:parent-style-name="Standard" style:class="index"> + <style:paragraph-properties text:number-lines="false" text:line-number="0"/> + <style:text-properties style:font-size-asian="12pt" style:font-name-complex="Droid Sans Devanagari" style:font-family-complex="'Droid Sans Devanagari'" style:font-family-generic-complex="swiss"/> + </style:style> + <style:style style:name="Index_20_Heading" style:display-name="Index Heading" style:family="paragraph" style:parent-style-name="Heading" style:class="index"> + <style:paragraph-properties fo:margin-left="0cm" fo:text-indent="0cm" style:auto-text-indent="false" text:number-lines="false" text:line-number="0"/> + <style:text-properties fo:font-size="16pt" fo:font-weight="bold" style:font-size-asian="16pt" style:font-weight-asian="bold" style:font-size-complex="16pt" style:font-weight-complex="bold"/> + </style:style> + <style:style style:name="Bibliography_20_Heading" style:display-name="Bibliography Heading" style:family="paragraph" style:parent-style-name="Index_20_Heading" style:class="index"> + <style:paragraph-properties fo:margin-left="0cm" fo:text-indent="0cm" style:auto-text-indent="false" text:number-lines="false" text:line-number="0"/> + <style:text-properties fo:font-size="16pt" fo:font-weight="bold" style:font-size-asian="16pt" style:font-weight-asian="bold" style:font-size-complex="16pt" style:font-weight-complex="bold"/> + </style:style> + <style:style style:name="Bibliography_20_1" style:display-name="Bibliography 1" style:family="paragraph" style:parent-style-name="Index" style:class="index"> + <style:paragraph-properties fo:margin-left="0cm" fo:text-indent="0cm" style:auto-text-indent="false"> + <style:tab-stops> + <style:tab-stop style:position="17cm" style:type="right" style:leader-style="dotted" style:leader-text="."/> + </style:tab-stops> + </style:paragraph-properties> + </style:style> + <style:style style:name="Internet_20_link" style:display-name="Internet link" style:family="text"> + <style:text-properties fo:color="#000080" loext:opacity="100%" style:text-underline-style="solid" style:text-underline-width="auto" style:text-underline-color="font-color"/> + </style:style> + <text:outline-style style:name="Outline"> + <text:outline-level-style text:level="1" style:num-format=""> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab"/> + </style:list-level-properties> + </text:outline-level-style> + <text:outline-level-style text:level="2" style:num-format=""> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab"/> + </style:list-level-properties> + </text:outline-level-style> + <text:outline-level-style text:level="3" style:num-format=""> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab"/> + </style:list-level-properties> + </text:outline-level-style> + <text:outline-level-style text:level="4" style:num-format=""> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab"/> + </style:list-level-properties> + </text:outline-level-style> + <text:outline-level-style text:level="5" style:num-format=""> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab"/> + </style:list-level-properties> + </text:outline-level-style> + <text:outline-level-style text:level="6" style:num-format=""> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab"/> + </style:list-level-properties> + </text:outline-level-style> + <text:outline-level-style text:level="7" style:num-format=""> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab"/> + </style:list-level-properties> + </text:outline-level-style> + <text:outline-level-style text:level="8" style:num-format=""> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab"/> + </style:list-level-properties> + </text:outline-level-style> + <text:outline-level-style text:level="9" style:num-format=""> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab"/> + </style:list-level-properties> + </text:outline-level-style> + <text:outline-level-style text:level="10" style:num-format=""> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab"/> + </style:list-level-properties> + </text:outline-level-style> + </text:outline-style> + <text:notes-configuration text:note-class="footnote" style:num-format="1" text:start-value="0" text:footnotes-position="page" text:start-numbering-at="document"/> + <text:notes-configuration text:note-class="endnote" style:num-format="i" text:start-value="0"/> + <text:bibliography-configuration text:prefix="[" text:suffix="]" text:sort-algorithm="alphanumeric" fo:language="cs" fo:country="CZ"/> + <text:linenumbering-configuration text:number-lines="false" text:offset="0.499cm" style:num-format="1" text:number-position="left" text:increment="5"/> + <loext:theme loext:name="Office"> + <loext:color-table loext:name="LibreOffice"> + <loext:color loext:name="dk1" loext:color="#000000"/> + <loext:color loext:name="lt1" loext:color="#ffffff"/> + <loext:color loext:name="dk2" loext:color="#000000"/> + <loext:color loext:name="lt2" loext:color="#ffffff"/> + <loext:color loext:name="accent1" loext:color="#18a303"/> + <loext:color loext:name="accent2" loext:color="#0369a3"/> + <loext:color loext:name="accent3" loext:color="#a33e03"/> + <loext:color loext:name="accent4" loext:color="#8e03a3"/> + <loext:color loext:name="accent5" loext:color="#c99c00"/> + <loext:color loext:name="accent6" loext:color="#c9211e"/> + <loext:color loext:name="hlink" loext:color="#0000ee"/> + <loext:color loext:name="folHlink" loext:color="#551a8b"/> + </loext:color-table> + </loext:theme> + </office:styles> + <office:automatic-styles> + <style:style style:name="P1" style:family="paragraph" style:parent-style-name="Bibliography_20_1"> + <style:paragraph-properties> + <style:tab-stops/> + </style:paragraph-properties> + </style:style> + <style:style style:name="P2" style:family="paragraph" style:parent-style-name="Standard"> + <style:text-properties officeooo:paragraph-rsid="00073597"/> + </style:style> + <style:style style:name="T1" style:family="text"> + <style:text-properties officeooo:rsid="00073597"/> + </style:style> + <style:style style:name="Sect1" style:family="section"> + <style:section-properties style:editable="false"> + <style:columns fo:column-count="1" fo:column-gap="0cm"/> + </style:section-properties> + </style:style> + <style:page-layout style:name="pm1"> + <style:page-layout-properties fo:page-width="21.001cm" fo:page-height="29.7cm" style:num-format="1" style:print-orientation="portrait" fo:margin-top="2cm" fo:margin-bottom="2cm" fo:margin-left="2cm" fo:margin-right="2cm" style:writing-mode="lr-tb" style:footnote-max-height="0cm" loext:margin-gutter="0cm"> + <style:footnote-sep style:width="0.018cm" style:distance-before-sep="0.101cm" style:distance-after-sep="0.101cm" style:line-style="solid" style:adjustment="left" style:rel-width="25%" style:color="#000000"/> + </style:page-layout-properties> + <style:header-style/> + <style:footer-style/> + </style:page-layout> + </office:automatic-styles> + <office:master-styles> + <style:master-page style:name="Standard" style:page-layout-name="pm1"/> + </office:master-styles> + <office:body> + <office:text> + <text:sequence-decls> + <text:sequence-decl text:display-outline-level="0" text:name="Illustration"/> + <text:sequence-decl text:display-outline-level="0" text:name="Table"/> + <text:sequence-decl text:display-outline-level="0" text:name="Text"/> + <text:sequence-decl text:display-outline-level="0" text:name="Drawing"/> + <text:sequence-decl text:display-outline-level="0" text:name="Figure"/> + </text:sequence-decls> + <text:p text:style-name="Standard"><text:a xlink:type="simple" xlink:href="http://reset.url/1" text:style-name="Internet_20_link" text:visited-style-name="Visited_20_Internet_20_Link"><text:span text:style-name="T1">reset.url.1</text:span></text:a></text:p> + <text:p text:style-name="Standard"/> + <text:p text:style-name="Standard"><text:bibliography-mark text:identifier="Test" text:bibliography-type="www" text:url="https://test.url/1">[Test]</text:bibliography-mark></text:p> + <text:p text:style-name="Standard"/> + <text:p text:style-name="P2"><text:a xlink:type="simple" xlink:href="http://reset.url/2" text:style-name="Internet_20_link" text:visited-style-name="Visited_20_Internet_20_Link"><text:span text:style-name="T1">reset.url.2</text:span></text:a></text:p> + <text:p text:style-name="P2"/> + <text:bibliography text:style-name="Sect1" text:protected="true" text:name="Bibliography1"> + <text:bibliography-source> + <text:index-title-template text:style-name="Bibliography_20_Heading">Bibliography</text:index-title-template> + <text:bibliography-entry-template text:bibliography-type="article" text:style-name="Bibliography_20_1"> + <text:index-entry-bibliography text:bibliography-data-field="identifier"/> + <text:index-entry-span>: </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="author"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="title"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="year"/> + </text:bibliography-entry-template> + <text:bibliography-entry-template text:bibliography-type="book" text:style-name="Bibliography_20_1"> + <text:index-entry-bibliography text:bibliography-data-field="identifier"/> + <text:index-entry-span>: </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="author"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="title"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="year"/> + </text:bibliography-entry-template> + <text:bibliography-entry-template text:bibliography-type="booklet" text:style-name="Bibliography_20_1"> + <text:index-entry-bibliography text:bibliography-data-field="identifier"/> + <text:index-entry-span>: </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="author"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="title"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="year"/> + </text:bibliography-entry-template> + <text:bibliography-entry-template text:bibliography-type="conference" text:style-name="Bibliography_20_1"> + <text:index-entry-bibliography text:bibliography-data-field="identifier"/> + <text:index-entry-span>: </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="author"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="title"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="year"/> + </text:bibliography-entry-template> + <text:bibliography-entry-template text:bibliography-type="custom1" text:style-name="Bibliography_20_1"> + <text:index-entry-bibliography text:bibliography-data-field="identifier"/> + <text:index-entry-span>: </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="author"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="title"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="year"/> + </text:bibliography-entry-template> + <text:bibliography-entry-template text:bibliography-type="custom2" text:style-name="Bibliography_20_1"> + <text:index-entry-bibliography text:bibliography-data-field="identifier"/> + <text:index-entry-span>: </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="author"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="title"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="year"/> + </text:bibliography-entry-template> + <text:bibliography-entry-template text:bibliography-type="custom3" text:style-name="Bibliography_20_1"> + <text:index-entry-bibliography text:bibliography-data-field="identifier"/> + <text:index-entry-span>: </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="author"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="title"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="year"/> + </text:bibliography-entry-template> + <text:bibliography-entry-template text:bibliography-type="custom4" text:style-name="Bibliography_20_1"> + <text:index-entry-bibliography text:bibliography-data-field="identifier"/> + <text:index-entry-span>: </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="author"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="title"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="year"/> + </text:bibliography-entry-template> + <text:bibliography-entry-template text:bibliography-type="custom5" text:style-name="Bibliography_20_1"> + <text:index-entry-bibliography text:bibliography-data-field="identifier"/> + <text:index-entry-span>: </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="author"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="title"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="year"/> + </text:bibliography-entry-template> + <text:bibliography-entry-template text:bibliography-type="email" text:style-name="Bibliography_20_1"> + <text:index-entry-bibliography text:bibliography-data-field="identifier"/> + <text:index-entry-span>: </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="author"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="title"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="year"/> + </text:bibliography-entry-template> + <text:bibliography-entry-template text:bibliography-type="inbook" text:style-name="Bibliography_20_1"> + <text:index-entry-bibliography text:bibliography-data-field="identifier"/> + <text:index-entry-span>: </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="author"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="title"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="year"/> + </text:bibliography-entry-template> + <text:bibliography-entry-template text:bibliography-type="incollection" text:style-name="Bibliography_20_1"> + <text:index-entry-bibliography text:bibliography-data-field="identifier"/> + <text:index-entry-span>: </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="author"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="title"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="year"/> + </text:bibliography-entry-template> + <text:bibliography-entry-template text:bibliography-type="inproceedings" text:style-name="Bibliography_20_1"> + <text:index-entry-bibliography text:bibliography-data-field="identifier"/> + <text:index-entry-span>: </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="author"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="title"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="year"/> + </text:bibliography-entry-template> + <text:bibliography-entry-template text:bibliography-type="journal" text:style-name="Bibliography_20_1"> + <text:index-entry-bibliography text:bibliography-data-field="identifier"/> + <text:index-entry-span>: </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="author"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="title"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="year"/> + </text:bibliography-entry-template> + <text:bibliography-entry-template text:bibliography-type="manual" text:style-name="Bibliography_20_1"> + <text:index-entry-bibliography text:bibliography-data-field="identifier"/> + <text:index-entry-span>: </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="author"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="title"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="year"/> + </text:bibliography-entry-template> + <text:bibliography-entry-template text:bibliography-type="mastersthesis" text:style-name="Bibliography_20_1"> + <text:index-entry-bibliography text:bibliography-data-field="identifier"/> + <text:index-entry-span>: </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="author"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="title"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="year"/> + </text:bibliography-entry-template> + <text:bibliography-entry-template text:bibliography-type="misc" text:style-name="Bibliography_20_1"> + <text:index-entry-bibliography text:bibliography-data-field="url"/> + </text:bibliography-entry-template> + <text:bibliography-entry-template text:bibliography-type="phdthesis" text:style-name="Bibliography_20_1"> + <text:index-entry-bibliography text:bibliography-data-field="identifier"/> + <text:index-entry-span>: </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="author"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="title"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="year"/> + </text:bibliography-entry-template> + <text:bibliography-entry-template text:bibliography-type="proceedings" text:style-name="Bibliography_20_1"> + <text:index-entry-bibliography text:bibliography-data-field="identifier"/> + <text:index-entry-span>: </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="author"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="title"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="year"/> + </text:bibliography-entry-template> + <text:bibliography-entry-template text:bibliography-type="techreport" text:style-name="Bibliography_20_1"> + <text:index-entry-bibliography text:bibliography-data-field="identifier"/> + <text:index-entry-span>: </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="author"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="title"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="year"/> + </text:bibliography-entry-template> + <text:bibliography-entry-template text:bibliography-type="unpublished" text:style-name="Bibliography_20_1"> + <text:index-entry-bibliography text:bibliography-data-field="identifier"/> + <text:index-entry-span>: </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="author"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="title"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="year"/> + </text:bibliography-entry-template> + <text:bibliography-entry-template text:bibliography-type="www" text:style-name="Bibliography_20_1"> + <text:index-entry-bibliography text:bibliography-data-field="identifier"/> + <text:index-entry-span>: </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="author"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="title"/> + <text:index-entry-span>, </text:index-entry-span> + <text:index-entry-bibliography text:bibliography-data-field="year"/> + </text:bibliography-entry-template> + </text:bibliography-source> + <text:index-body> + <text:index-title text:style-name="Sect1" text:name="Bibliography1_Head"> + <text:p text:style-name="Bibliography_20_Heading">Bibliography</text:p> + </text:index-title> + <text:p text:style-name="P1"><text:a xlink:type="simple" xlink:href="https://test.url/1" text:style-name="Internet_20_link" text:visited-style-name="Internet_20_link"><text:span text:style-name="Internet_20_link">https://test.url/1</text:span></text:a></text:p> + </text:index-body> + </text:bibliography> + <text:p text:style-name="P2"/> + </office:text> + </office:body> +</office:document>
\ No newline at end of file diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx new file mode 100644 index 0000000000..2111cedf25 --- /dev/null +++ b/sw/qa/uibase/shells/shells.cxx @@ -0,0 +1,1083 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <swmodeltestbase.hxx> + +#include <com/sun/star/frame/XStorable.hpp> +#include <com/sun/star/packages/zip/ZipFileAccess.hpp> +#include <com/sun/star/text/BibliographyDataType.hpp> +#include <com/sun/star/text/XTextDocument.hpp> + +#include <sfx2/dispatch.hxx> +#include <sfx2/viewfrm.hxx> +#include <svx/svdpage.hxx> +#include <editeng/eeitem.hxx> +#include <editeng/adjustitem.hxx> +#include <editeng/outlobj.hxx> +#include <editeng/editobj.hxx> +#include <comphelper/processfactory.hxx> +#include <comphelper/propertyvalue.hxx> +#include <unotools/ucbstreamhelper.hxx> +#include <xmloff/odffields.hxx> +#include <comphelper/string.hxx> +#include <comphelper/propertysequence.hxx> +#include <comphelper/sequence.hxx> +#include <osl/thread.hxx> + +#include <IDocumentContentOperations.hxx> +#include <cmdid.h> +#include <fmtanchr.hxx> +#include <view.hxx> +#include <wrtsh.hxx> +#include <IDocumentDrawModelAccess.hxx> +#include <drawdoc.hxx> +#include <docsh.hxx> +#include <ndtxt.hxx> +#include <ftnidx.hxx> +#include <txtftn.hxx> + +/// Covers sw/source/uibase/shells/ fixes. +class SwUibaseShellsTest : public SwModelTestBase +{ +public: + SwUibaseShellsTest() + : SwModelTestBase("/sw/qa/uibase/shells/data/") + { + } +}; + +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testTdf130179) +{ + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + IDocumentContentOperations& rIDCO = pDoc->getIDocumentContentOperations(); + SwCursorShell* pShell(pDoc->GetEditShell()); + SfxItemSet aFrameSet(pDoc->GetAttrPool(), svl::Items<RES_FRMATR_BEGIN, RES_FRMATR_END - 1>); + SfxItemSet aGrfSet(pDoc->GetAttrPool(), svl::Items<RES_GRFATR_BEGIN, RES_GRFATR_END - 1>); + SwFormatAnchor aAnchor(RndStdIds::FLY_AT_PARA); + aFrameSet.Put(aAnchor); + Graphic aGrf; + CPPUNIT_ASSERT(rIDCO.InsertGraphic(*pShell->GetCursor(), OUString(), OUString(), &aGrf, + &aFrameSet, &aGrfSet, nullptr)); + CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc->GetFlyCount(FLYCNTTYPE_GRF)); + + SwView* pView = pDoc->GetDocShell()->GetView(); + selectShape(1); + + std::unique_ptr<SfxPoolItem> pItem; + pView->GetViewFrame().GetBindings().QueryState(FN_POSTIT, pItem); + // Without the accompanying fix in place, this test would have failed with: + // assertion failed + // - Expression: !pItem + // i.e. comment insertion was enabled for an at-para anchored image. + CPPUNIT_ASSERT(!pItem); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testShapeTextAlignment) +{ +// FIXME find out why this fails on macOS/Windows +#if !defined(MACOSX) && !defined(_WIN32) + // Create a document with a rectangle in it. + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + Point aStartPos(1000, 1000); + pWrtShell->BeginCreate(SdrObjKind::Rectangle, aStartPos); + Point aMovePos(2000, 2000); + pWrtShell->MoveCreate(aMovePos); + pWrtShell->EndCreate(SdrCreateCmd::ForceEnd); + + // Start shape text edit. + SwView* pView = pDoc->GetDocShell()->GetView(); + // Select the shape. + selectShape(1); + // Start the actual text edit. + SdrPage* pPage = pWrtShell->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pPage->GetObjCount()); + SdrObject* pObject = pPage->GetObj(0); + pView->EnterShapeDrawTextMode(pObject); + pView->AttrChangedNotify(nullptr); + + // Change paragraph adjustment to center. + pView->GetViewFrame().GetDispatcher()->Execute(SID_ATTR_PARA_ADJUST_CENTER, + SfxCallMode::SYNCHRON); + + // End shape text edit. + pWrtShell->EndTextEdit(); + + const OutlinerParaObject* pOutliner = pObject->GetOutlinerParaObject(); + // Without the accompanying fix in place, this test would have failed, because the shape had no + // text or text formatting. In other words the paragraph adjustment command was ignored. + CPPUNIT_ASSERT(pOutliner); + const SfxItemSet& rParaAttribs = pOutliner->GetTextObject().GetParaAttribs(0); + SvxAdjust eAdjust = rParaAttribs.GetItem(EE_PARA_JUST)->GetAdjust(); + CPPUNIT_ASSERT_EQUAL(SvxAdjust::Center, eAdjust); +#endif +} + +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testOleSavePreviewUpdate) +{ + // Load a document with 2 charts in it. The second is down enough that you have to scroll to + // trigger its rendering. Previews are missing for both. + createSwDoc("ole-save-preview-update.odt"); + + // Explicitly update OLE previews, etc. + dispatchCommand(mxComponent, ".uno:UpdateAll", {}); + + // Save the document and see if we get the previews. + uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); + xStorable->storeToURL(maTempFile.GetURL(), {}); + uno::Reference<packages::zip::XZipFileAccess2> xNameAccess + = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory), + maTempFile.GetURL()); + + // Without the accompanying fix in place, this test would have failed, because the object + // replacements were not generated, even after UpdateAll. + CPPUNIT_ASSERT(xNameAccess->hasByName("ObjectReplacements/Object 1")); + CPPUNIT_ASSERT(xNameAccess->hasByName("ObjectReplacements/Object 2")); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testOlePreviewUpdate) +{ + // Given a document with an embedded Writer object: + createSwDoc("ole-preview-update.odt"); + + // When updating "all" (including OLE previews): + dispatchCommand(mxComponent, ".uno:UpdateAll", {}); + + // Then make sure the preview is no longer a 0-sized stream: + uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); + xStorable->storeToURL(maTempFile.GetURL(), {}); + uno::Reference<packages::zip::XZipFileAccess2> xNameAccess + = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory), + maTempFile.GetURL()); + uno::Reference<io::XInputStream> xInputStream( + xNameAccess->getByName("ObjectReplacements/Object 1"), uno::UNO_QUERY); + std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true)); + // Without the accompanying fix in place, this test would have failed, the stream was still + // empty. + CPPUNIT_ASSERT_GREATER(static_cast<sal_uInt64>(0), pStream->remainingSize()); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testBibliographyUrlContextMenu) +{ + // Given a document with a bibliography field: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xField( + xFactory->createInstance("com.sun.star.text.TextField.Bibliography"), uno::UNO_QUERY); + uno::Sequence<beans::PropertyValue> aFields = { + comphelper::makePropertyValue("BibiliographicType", text::BibliographyDataType::WWW), + comphelper::makePropertyValue("Identifier", OUString("AT")), + comphelper::makePropertyValue("Author", OUString("Author")), + comphelper::makePropertyValue("Title", OUString("Title")), + comphelper::makePropertyValue("URL", OUString("http://www.example.com/test.pdf#page=1")), + }; + xField->setPropertyValue("Fields", uno::Any(aFields)); + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XText> xText = xTextDocument->getText(); + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + uno::Reference<text::XTextContent> xContent(xField, uno::UNO_QUERY); + xText->insertTextContent(xCursor, xContent, /*bAbsorb=*/false); + + // When selecting the field and opening the context menu: + SwDocShell* pDocShell = pDoc->GetDocShell(); + SwWrtShell* pWrtShell = pDocShell->GetWrtShell(); + pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/true, 1, /*bBasicCall=*/false); + SfxDispatcher* pDispatcher = pDocShell->GetViewShell()->GetViewFrame().GetDispatcher(); + css::uno::Any aState; + SfxItemState eStateOpen = pDispatcher->QueryState(SID_OPEN_HYPERLINK, aState); + SfxItemState eStateCopy = pDispatcher->QueryState(SID_COPY_HYPERLINK_LOCATION, aState); + + // Then the "open hyperlink" and "copy hyperlink location" menu items should be visible: + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 32 (SfxItemState::DEFAULT) + // - Actual : 1 (SfxItemState::DISABLED) + // i.e. the menu item was not visible for biblio entry fields with an URL. + CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT, eStateOpen); + CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT, eStateCopy); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testProtectedFieldsCopyHyperlinkLocation) +{ + // Given a test document document that contains: + // - generic url + // - empty line + // - bibliography mark + // - empty line + // - generic url + // - empty line + // - bibliography table heading + // - bibliography entry containing only url + // - empty line + createSwDoc("protectedLinkCopy.fodt"); + + // Copy generic hyperlink + dispatchCommand(mxComponent, ".uno:CopyHyperlinkLocation", {}); + dispatchCommand(mxComponent, ".uno:GoDown", {}); + dispatchCommand(mxComponent, ".uno:Paste", {}); + // Assert generic hyperlink was correctly copied and pasted + CPPUNIT_ASSERT_EQUAL(OUString("http://reset.url/1"), getParagraph(2)->getString()); + + dispatchCommand(mxComponent, ".uno:GoDown", {}); + dispatchCommand(mxComponent, ".uno:GoLeft", {}); + // Copy bibliography mark hyperlink + dispatchCommand(mxComponent, ".uno:CopyHyperlinkLocation", {}); + dispatchCommand(mxComponent, ".uno:GoDown", {}); + dispatchCommand(mxComponent, ".uno:Paste", {}); + // Assert bibliography mark hyperlink was correctly copied and pasted + CPPUNIT_ASSERT_EQUAL(OUString("https://test.url/1"), getParagraph(4)->getString()); + + dispatchCommand(mxComponent, ".uno:GoDown", {}); + dispatchCommand(mxComponent, ".uno:GoLeft", {}); + // Copy generic hyperlink + dispatchCommand(mxComponent, ".uno:CopyHyperlinkLocation", {}); + dispatchCommand(mxComponent, ".uno:GoDown", {}); + dispatchCommand(mxComponent, ".uno:Paste", {}); + // Assert generic hyperlink was correctly copied and pasted + CPPUNIT_ASSERT_EQUAL(OUString("http://reset.url/2"), getParagraph(6)->getString()); + + dispatchCommand(mxComponent, ".uno:GoDown", {}); + dispatchCommand(mxComponent, ".uno:GoDown", {}); + dispatchCommand(mxComponent, ".uno:GoLeft", {}); + // Copy bibliography table hyperlink + dispatchCommand(mxComponent, ".uno:CopyHyperlinkLocation", {}); + dispatchCommand(mxComponent, ".uno:GoDown", {}); + dispatchCommand(mxComponent, ".uno:Paste", {}); + // Assert bibliography table entry hyperlink was correctly copied and pasted + CPPUNIT_ASSERT_EQUAL(OUString("https://test.url/1"), getParagraph(9)->getString()); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testBibliographyLocalCopyContextMenu) +{ + // Given a document with a bibliography field's local copy: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xField( + xFactory->createInstance("com.sun.star.text.TextField.Bibliography"), uno::UNO_QUERY); + uno::Sequence<beans::PropertyValue> aFields = { + comphelper::makePropertyValue("BibiliographicType", text::BibliographyDataType::WWW), + comphelper::makePropertyValue("Identifier", OUString("AT")), + comphelper::makePropertyValue("Author", OUString("Author")), + comphelper::makePropertyValue("Title", OUString("Title")), + comphelper::makePropertyValue("URL", OUString("http://www.example.com/test.pdf#page=1")), + comphelper::makePropertyValue("LocalURL", OUString("file:///home/me/test.pdf")), + }; + xField->setPropertyValue("Fields", uno::Any(aFields)); + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XText> xText = xTextDocument->getText(); + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + uno::Reference<text::XTextContent> xContent(xField, uno::UNO_QUERY); + xText->insertTextContent(xCursor, xContent, /*bAbsorb=*/false); + + // When selecting the field and opening the context menu: + SwDocShell* pDocShell = pDoc->GetDocShell(); + SwWrtShell* pWrtShell = pDocShell->GetWrtShell(); + pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/true, 1, /*bBasicCall=*/false); + SfxDispatcher* pDispatcher = pDocShell->GetViewShell()->GetViewFrame().GetDispatcher(); + css::uno::Any aState; + SfxItemState eState = pDispatcher->QueryState(FN_OPEN_LOCAL_URL, aState); + + // Then the "open local copy" menu item should be visible: + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 32 (SfxItemState::DEFAULT) + // - Actual : 1 (SfxItemState::DISABLED) + // i.e. the context menu was disabled all the time, even for biblio fields. + CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT, eState); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testContentControlPageBreak) +{ + // Given a document with a content control and a cursor inside the content control: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + uno::Reference<lang::XMultiServiceFactory> xMSF(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XText> xText = xTextDocument->getText(); + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + xText->insertString(xCursor, "test", /*bAbsorb=*/false); + xCursor->gotoStart(/*bExpand=*/false); + xCursor->gotoEnd(/*bExpand=*/true); + uno::Reference<text::XTextContent> xContentControl( + xMSF->createInstance("com.sun.star.text.ContentControl"), uno::UNO_QUERY); + xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->SttEndDoc(/*bStt=*/true); + pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false); + + // When trying to insert a page break: + dispatchCommand(mxComponent, ".uno:InsertPagebreak", {}); + + // Then make sure that the document still has a single page: + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 2 + // i.e. inline content control had its start and end in different text nodes, which is not + // allowed. + CPPUNIT_ASSERT_EQUAL(1, getPages()); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testInsertTextFormField) +{ + // Given an empty document: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + + // When inserting an ODF_UNHANDLED fieldmark: + OUString aExpectedCommand("ADDIN ZOTERO_BIBL foo bar"); + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("FieldType", uno::Any(ODF_UNHANDLED)), + comphelper::makePropertyValue("FieldCommand", uno::Any(aExpectedCommand)), + comphelper::makePropertyValue("FieldResult", uno::Any(OUString("<p>aaa</p><p>bbb</p>"))), + }; + dispatchCommand(mxComponent, ".uno:TextFormField", aArgs); + + // Then make sure that it's type/name is correct: + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + SwCursor* pCursor = pWrtShell->GetCursor(); + pCursor->SttEndDoc(/*bSttDoc=*/true); + sw::mark::IFieldmark* pFieldmark + = pDoc->getIDocumentMarkAccess()->getFieldmarkAt(*pCursor->GetPoint()); + CPPUNIT_ASSERT(pFieldmark); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: vnd.oasis.opendocument.field.UNHANDLED + // - Actual : vnd.oasis.opendocument.field.FORMTEXT + // i.e. the custom type parameter was ignored. + CPPUNIT_ASSERT_EQUAL(ODF_UNHANDLED, pFieldmark->GetFieldname()); + + auto it = pFieldmark->GetParameters()->find(ODF_CODE_PARAM); + CPPUNIT_ASSERT(it != pFieldmark->GetParameters()->end()); + OUString aActualCommand; + it->second >>= aActualCommand; + CPPUNIT_ASSERT_EQUAL(aExpectedCommand, aActualCommand); + + SwPaM aPam(pFieldmark->GetMarkStart(), pFieldmark->GetMarkEnd()); + // Ignore the leading field start + sep. + aPam.GetMark()->SetContent(aPam.GetMark()->GetContentIndex() + 2); + // Ignore the trailing field end. + aPam.GetPoint()->SetContent(aPam.GetPoint()->GetContentIndex() - 1); + CPPUNIT_ASSERT(aPam.HasMark()); + OUString aActualResult = aPam.GetText(); + CPPUNIT_ASSERT_EQUAL(OUString("aaa\nbbb"), aActualResult); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testUpdateFieldmarks) +{ + // Given a document with 2 fieldmarks: + createSwDoc(); + { + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("FieldType", uno::Any(ODF_UNHANDLED)), + comphelper::makePropertyValue("FieldCommand", + uno::Any(OUString("ADDIN ZOTERO_ITEM old command 1"))), + comphelper::makePropertyValue("FieldResult", uno::Any(OUString("old result 1"))), + }; + dispatchCommand(mxComponent, ".uno:TextFormField", aArgs); + } + { + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("FieldType", uno::Any(ODF_UNHANDLED)), + comphelper::makePropertyValue("FieldCommand", + uno::Any(OUString("ADDIN ZOTERO_ITEM old command 2"))), + comphelper::makePropertyValue("FieldResult", uno::Any(OUString("old result 2"))), + }; + dispatchCommand(mxComponent, ".uno:TextFormField", aArgs); + } + + // When updating those fieldmarks: + uno::Sequence<css::beans::PropertyValue> aField1{ + comphelper::makePropertyValue("FieldType", uno::Any(ODF_UNHANDLED)), + comphelper::makePropertyValue("FieldCommand", + uno::Any(OUString("ADDIN ZOTERO_ITEM new command 1"))), + comphelper::makePropertyValue("FieldResult", uno::Any(OUString("new result 1"))), + }; + uno::Sequence<css::beans::PropertyValue> aField2{ + comphelper::makePropertyValue("FieldType", uno::Any(ODF_UNHANDLED)), + comphelper::makePropertyValue("FieldCommand", + uno::Any(OUString("ADDIN ZOTERO_ITEM new command 2"))), + comphelper::makePropertyValue("FieldResult", uno::Any(OUString("new result 2"))), + }; + uno::Sequence<uno::Sequence<css::beans::PropertyValue>> aFields = { aField1, aField2 }; + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("FieldType", uno::Any(ODF_UNHANDLED)), + comphelper::makePropertyValue("FieldCommandPrefix", + uno::Any(OUString("ADDIN ZOTERO_ITEM"))), + comphelper::makePropertyValue("Fields", uno::Any(aFields)), + }; + dispatchCommand(mxComponent, ".uno:TextFormFields", aArgs); + + // Then make sure that the document text contains the new field results: + SwDoc* pDoc = getSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->SttEndDoc(/*bStt=*/true); + SwCursor* pCursor = pWrtShell->GetCursor(); + OUString aActual = pCursor->Start()->GetNode().GetTextNode()->GetText(); + static sal_Unicode const aForbidden[] + = { CH_TXT_ATR_FIELDSTART, CH_TXT_ATR_FIELDSEP, CH_TXT_ATR_FIELDEND, 0 }; + aActual = comphelper::string::removeAny(aActual, aForbidden); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: new result 1new result 2 + // - Actual : old result 1old result 2 + // i.e. the fieldmarks were not updated. + CPPUNIT_ASSERT_EQUAL(OUString("new result 1new result 2"), aActual); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testInsertBookmark) +{ + // Given an empty document: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + + // When inserting a bookmark with text: + OUString aExpectedBookmarkName("ZOTERO_BREF_GiQ7DAWQYWLy"); + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("Bookmark", uno::Any(aExpectedBookmarkName)), + comphelper::makePropertyValue("BookmarkText", uno::Any(OUString("<p>aaa</p><p>bbb</p>"))), + }; + dispatchCommand(mxComponent, ".uno:InsertBookmark", aArgs); + + // Then make sure that we create a bookmark that covers that text: + IDocumentMarkAccess& rIDMA = *pDoc->getIDocumentMarkAccess(); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), rIDMA.getBookmarksCount()); + for (auto it = rIDMA.getBookmarksBegin(); it != rIDMA.getBookmarksEnd(); ++it) + { + sw::mark::IMark* pMark = *it; + CPPUNIT_ASSERT_EQUAL(aExpectedBookmarkName, pMark->GetName()); + SwPaM aPam(pMark->GetMarkStart(), pMark->GetMarkEnd()); + OUString aActualResult = aPam.GetText(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: aaa\nbbb + // - Actual : + // i.e. no text was inserted, the bookmark was collapsed. + CPPUNIT_ASSERT_EQUAL(OUString("aaa\nbbb"), aActualResult); + } +} + +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testGotoMark) +{ + // Given a document with 2 paragraphs, a bookmark on the second one: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->SplitNode(); + pWrtShell->SttEndDoc(/*bStt=*/false); + pWrtShell->SetBookmark(vcl::KeyCode(), "mybookmark"); + SwNodeOffset nExpected = pWrtShell->GetCursor()->GetPointNode().GetIndex(); + + // When jumping to that mark from the doc start: + pWrtShell->SttEndDoc(/*bStt=*/true); + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("GotoMark", uno::Any(OUString("mybookmark"))), + }; + dispatchCommand(mxComponent, ".uno:GotoMark", aArgs); + + // Then make sure that the final cursor position is at the bookmark: + SwNodeOffset nActual = pWrtShell->GetCursor()->GetPointNode().GetIndex(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 10 (bookmark) + // - Actual : 9 (doc start) + // i.e. the actual jump didn't happen. + CPPUNIT_ASSERT_EQUAL(nExpected, nActual); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testUpdateBookmarks) +{ + // Given a document with 2 bookmarks, first covering "B" and second covering "D": + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->Insert("ABCDE"); + pWrtShell->SttEndDoc(/*bStt=*/true); + pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false); + pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/true, 1, /*bBasicCall=*/false); + pWrtShell->SetBookmark(vcl::KeyCode(), "ZOTERO_BREF_GiQ7DAWQYWLy"); + pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false); + pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/true, 1, /*bBasicCall=*/false); + pWrtShell->SetBookmark(vcl::KeyCode(), "ZOTERO_BREF_PRxDGUb4SWXF"); + + // When updating the content of bookmarks: + pWrtShell->SttEndDoc(/*bStt=*/true); + std::vector<beans::PropertyValue> aArgsVec = comphelper::JsonToPropertyValues(R"json( +{ + "BookmarkNamePrefix": { + "type": "string", + "value": "ZOTERO_BREF_" + }, + "Bookmarks": { + "type": "[][]com.sun.star.beans.PropertyValue", + "value": [ + { + "Bookmark": { + "type": "string", + "value": "ZOTERO_BREF_new1" + }, + "BookmarkText": { + "type": "string", + "value": "new result 1" + } + }, + { + "Bookmark": { + "type": "string", + "value": "ZOTERO_BREF_new2" + }, + "BookmarkText": { + "type": "string", + "value": "new result 2" + } + } + ] + } +} +)json"_ostr); + uno::Sequence<beans::PropertyValue> aArgs = comphelper::containerToSequence(aArgsVec); + dispatchCommand(mxComponent, ".uno:UpdateBookmarks", aArgs); + + // Then make sure that the only paragraph is updated correctly: + SwCursor* pCursor = pWrtShell->GetCursor(); + OUString aActual = pCursor->GetPointNode().GetTextNode()->GetText(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: Anew result 1Cnew result 2E + // - Actual : ABCDE + // i.e. the content was not updated. + CPPUNIT_ASSERT_EQUAL(OUString("Anew result 1Cnew result 2E"), aActual); + + // Without the accompanying fix in place, this test would have failed, ZOTERO_BREF_GiQ7DAWQYWLy + // was not renamed to ZOTERO_BREF_new1. + auto it = pDoc->getIDocumentMarkAccess()->findMark("ZOTERO_BREF_new1"); + CPPUNIT_ASSERT(it != pDoc->getIDocumentMarkAccess()->getAllMarksEnd()); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testInsertFieldmarkReadonly) +{ + // Given a document with a fieldmark, the cursor inside the fieldmark: + createSwDoc(); + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("FieldType", uno::Any(ODF_UNHANDLED)), + comphelper::makePropertyValue("FieldCommand", uno::Any(OUString("my command"))), + comphelper::makePropertyValue("FieldResult", uno::Any(OUString("my result"))), + }; + dispatchCommand(mxComponent, ".uno:TextFormField", aArgs); + SwDoc* pDoc = getSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + SwCursor* pCursor = pWrtShell->GetCursor(); + pCursor->SttEndDoc(/*bSttDoc=*/true); + pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false); + + // When trying to insert an inner fieldmark: + // Without the accompanying fix in place, this test would have crashed. + dispatchCommand(mxComponent, ".uno:TextFormField", aArgs); + + // Then make sure the read-only content refuses to accept that inner fieldmark, so we still have + // just one: + size_t nActual = 0; + IDocumentMarkAccess& rIDMA = *pDoc->getIDocumentMarkAccess(); + for (auto it = rIDMA.getFieldmarksBegin(); it != rIDMA.getFieldmarksEnd(); ++it) + { + ++nActual; + } + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), nActual); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testUpdateRefmarks) +{ + // Given a document with two refmarks, one is not interesting the other is a citation: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("TypeName", uno::Any(OUString("SetRef"))), + comphelper::makePropertyValue("Name", uno::Any(OUString("some other old refmark"))), + comphelper::makePropertyValue("Content", uno::Any(OUString("some other old content"))), + }; + dispatchCommand(mxComponent, ".uno:InsertField", aArgs); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->SttEndDoc(/*bStt=*/false); + pWrtShell->SplitNode(); + pWrtShell->SttEndDoc(/*bStt=*/false); + aArgs = { + comphelper::makePropertyValue("TypeName", uno::Any(OUString("SetRef"))), + comphelper::makePropertyValue( + "Name", uno::Any(OUString("ZOTERO_ITEM CSL_CITATION {} old refmark"))), + comphelper::makePropertyValue("Content", uno::Any(OUString("old content"))), + }; + dispatchCommand(mxComponent, ".uno:InsertField", aArgs); + + // When updating that refmark: + std::vector<beans::PropertyValue> aArgsVec = comphelper::JsonToPropertyValues(R"json( +{ + "TypeName": { + "type": "string", + "value": "SetRef" + }, + "NamePrefix": { + "type": "string", + "value": "ZOTERO_ITEM CSL_CITATION" + }, + "Fields": { + "type": "[][]com.sun.star.beans.PropertyValue", + "value": [ + { + "Name": { + "type": "string", + "value": "ZOTERO_ITEM CSL_CITATION {} new refmark" + }, + "Content": { + "type": "string", + "value": "new content" + } + } + ] + } +} +)json"_ostr); + aArgs = comphelper::containerToSequence(aArgsVec); + dispatchCommand(mxComponent, ".uno:UpdateFields", aArgs); + + // Then make sure that the document text features the new content: + SwTextNode* pTextNode = pWrtShell->GetCursor()->GetPointNode().GetTextNode(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: new content + // - Actual : old content + // i.e. the doc content was not updated. + CPPUNIT_ASSERT_EQUAL(OUString("new content"), pTextNode->GetText()); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testUpdateFieldmark) +{ + // Given a document with a fieldmark: + createSwDoc(); + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("FieldType", uno::Any(ODF_UNHANDLED)), + comphelper::makePropertyValue("FieldCommand", + uno::Any(OUString("ADDIN ZOTERO_ITEM old command 1"))), + comphelper::makePropertyValue("FieldResult", uno::Any(OUString("old result 1"))), + }; + dispatchCommand(mxComponent, ".uno:TextFormField", aArgs); + + // When updating that fieldmark to have new field command & result: + SwDoc* pDoc = getSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->SttEndDoc(/*bStt=*/false); + pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false); + std::vector<beans::PropertyValue> aArgsVec = comphelper::JsonToPropertyValues(R"json( +{ + "FieldType": { + "type": "string", + "value": "vnd.oasis.opendocument.field.UNHANDLED" + }, + "FieldCommandPrefix": { + "type": "string", + "value": "ADDIN ZOTERO_ITEM" + }, + "Field": { + "type": "[]com.sun.star.beans.PropertyValue", + "value": { + "FieldType": { + "type": "string", + "value": "vnd.oasis.opendocument.field.UNHANDLED" + }, + "FieldCommand": { + "type": "string", + "value": "ADDIN ZOTERO_ITEM new command 1" + }, + "FieldResult": { + "type": "string", + "value": "new result 1" + } + } + } +} +)json"_ostr); + aArgs = comphelper::containerToSequence(aArgsVec); + dispatchCommand(mxComponent, ".uno:UpdateTextFormField", aArgs); + + // Then make sure that the document text is updated accordingly: + SwCursor* pCursor = pWrtShell->GetCursor(); + OUString aActual = pCursor->Start()->GetNode().GetTextNode()->GetText(); + static sal_Unicode const aForbidden[] + = { CH_TXT_ATR_FIELDSTART, CH_TXT_ATR_FIELDSEP, CH_TXT_ATR_FIELDEND, 0 }; + aActual = comphelper::string::removeAny(aActual, aForbidden); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: new result 1 + // - Actual : old result 1 + // i.e. the document text was not updated. + CPPUNIT_ASSERT_EQUAL(OUString("new result 1"), aActual); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testUpdateSections) +{ + // Given a document with a section: + createSwDoc(); + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("RegionName", + uno::Any(OUString("ZOTERO_BIBL {} CSL_BIBLIOGRAPHY RNDold"))), + comphelper::makePropertyValue("Content", uno::Any(OUString("old content"))), + }; + dispatchCommand(mxComponent, ".uno:InsertSection", aArgs); + + // When updating that section: + std::vector<beans::PropertyValue> aArgsVec = comphelper::JsonToPropertyValues(R"json( +{ + "SectionNamePrefix": { + "type": "string", + "value": "ZOTERO_BIBL" + }, + "Sections": { + "type": "[][]com.sun.star.beans.PropertyValue", + "value": [ + { + "RegionName": { + "type": "string", + "value": "ZOTERO_BIBL {} CSL_BIBLIOGRAPHY RNDnew" + }, + "Content": { + "type": "string", + "value": "new content" + } + } + ] + } +} +)json"_ostr); + aArgs = comphelper::containerToSequence(aArgsVec); + dispatchCommand(mxComponent, ".uno:UpdateSections", aArgs); + + // Then make sure that the section is updated: + SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); + pWrtShell->SttEndDoc(/*bStt=*/true); + pWrtShell->EndOfSection(/*bSelect=*/true); + SwCursor* pCursor = pWrtShell->GetCursor(); + OUString aActualResult = pCursor->GetText(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: new content + // - Actual : old content + // i.e. the content wasn't updated. + CPPUNIT_ASSERT_EQUAL(OUString("new content"), aActualResult); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testDeleteFieldmarks) +{ + // Given a document with 2 fieldmarks: + createSwDoc(); + { + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("FieldType", uno::Any(ODF_UNHANDLED)), + comphelper::makePropertyValue("FieldCommand", + uno::Any(OUString("ADDIN ZOTERO_ITEM old command 1"))), + comphelper::makePropertyValue("FieldResult", uno::Any(OUString("result 1"))), + }; + dispatchCommand(mxComponent, ".uno:TextFormField", aArgs); + } + { + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("FieldType", uno::Any(ODF_UNHANDLED)), + comphelper::makePropertyValue("FieldCommand", + uno::Any(OUString("ADDIN ZOTERO_ITEM old command 2"))), + comphelper::makePropertyValue("FieldResult", uno::Any(OUString("result 2"))), + }; + dispatchCommand(mxComponent, ".uno:TextFormField", aArgs); + } + + // When deleting those fieldmarks: + uno::Sequence<css::beans::PropertyValue> aArgs + = { comphelper::makePropertyValue("FieldType", uno::Any(ODF_UNHANDLED)), + comphelper::makePropertyValue("FieldCommandPrefix", + uno::Any(OUString("ADDIN ZOTERO_ITEM"))) }; + dispatchCommand(mxComponent, ".uno:DeleteTextFormFields", aArgs); + + // Then make sure that the document doesn't contain fields anymore: + SwDoc* pDoc = getSwDoc(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 0 + // - Actual : 2 + // i.e. the fieldmarks were not deleted. + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), + pDoc->getIDocumentMarkAccess()->getAllMarksCount()); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->SttEndDoc(/*bStt=*/true); + SwCursor* pCursor = pWrtShell->GetCursor(); + OUString aActual = pCursor->Start()->GetNode().GetTextNode()->GetText(); + CPPUNIT_ASSERT_EQUAL(OUString("result 1result 2"), aActual); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testUpdateBookmark) +{ + // Given a document with a bookmarks, covering "BC": + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->Insert("ABCD"); + pWrtShell->SttEndDoc(/*bStt=*/true); + pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false); + pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/true, 2, /*bBasicCall=*/false); + pWrtShell->SetBookmark(vcl::KeyCode(), "ZOTERO_BREF_old"); + + // When updating the content of the bookmark under the cursor: + pWrtShell->SttEndDoc(/*bStt=*/true); + pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/false, 2, /*bBasicCall=*/false); + std::vector<beans::PropertyValue> aArgsVec = comphelper::JsonToPropertyValues(R"json( +{ + "BookmarkNamePrefix": { + "type": "string", + "value": "ZOTERO_BREF_" + }, + "Bookmark": { + "type": "[]com.sun.star.beans.PropertyValue", + "value": { + "Bookmark": { + "type": "string", + "value": "ZOTERO_BREF_new" + }, + "BookmarkText": { + "type": "string", + "value": "new result" + } + } + } +} +)json"_ostr); + uno::Sequence<beans::PropertyValue> aArgs = comphelper::containerToSequence(aArgsVec); + dispatchCommand(mxComponent, ".uno:UpdateBookmark", aArgs); + + // Then make sure that the only paragraph is updated correctly: + SwCursor* pCursor = pWrtShell->GetCursor(); + OUString aActual = pCursor->GetPointNode().GetTextNode()->GetText(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: Anew resultD + // - Actual : ABCD + // i.e. it was not possible to update just the bookmark under cursor. + CPPUNIT_ASSERT_EQUAL(OUString("Anew resultD"), aActual); + auto it = pDoc->getIDocumentMarkAccess()->findMark("ZOTERO_BREF_new"); + CPPUNIT_ASSERT(it != pDoc->getIDocumentMarkAccess()->getAllMarksEnd()); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testUpdateRefmark) +{ + // Given a document with a refmark: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("TypeName", uno::Any(OUString("SetRef"))), + comphelper::makePropertyValue( + "Name", uno::Any(OUString("ZOTERO_ITEM CSL_CITATION {} old refmark"))), + comphelper::makePropertyValue("Content", uno::Any(OUString("old content"))), + }; + dispatchCommand(mxComponent, ".uno:InsertField", aArgs); + + // When updating that refmark: + std::vector<beans::PropertyValue> aArgsVec = comphelper::JsonToPropertyValues(R"json( +{ + "TypeName": { + "type": "string", + "value": "SetRef" + }, + "NamePrefix": { + "type": "string", + "value": "ZOTERO_ITEM CSL_CITATION" + }, + "Field": { + "type": "[]com.sun.star.beans.PropertyValue", + "value": { + "Name": { + "type": "string", + "value": "ZOTERO_ITEM CSL_CITATION {} new refmark" + }, + "Content": { + "type": "string", + "value": "new content" + } + } + } +} +)json"_ostr); + aArgs = comphelper::containerToSequence(aArgsVec); + dispatchCommand(mxComponent, ".uno:UpdateField", aArgs); + + // Then make sure that the document text features the new content: + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + SwTextNode* pTextNode = pWrtShell->GetCursor()->GetPointNode().GetTextNode(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: new content + // - Actual : old content + // i.e. the content was not updated. + CPPUNIT_ASSERT_EQUAL(OUString("new content"), pTextNode->GetText()); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testDeleteBookmarks) +{ + // Given a document with 2 bookmarks, first covering "B" and second covering "D": + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->Insert("ABCDE"); + pWrtShell->SttEndDoc(/*bStt=*/true); + pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false); + pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/true, 1, /*bBasicCall=*/false); + pWrtShell->SetBookmark(vcl::KeyCode(), "ZOTERO_BREF_GiQ7DAWQYWLy"); + pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false); + pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/true, 1, /*bBasicCall=*/false); + pWrtShell->SetBookmark(vcl::KeyCode(), "other"); + + // When deleting 1 matching bookmark: + pWrtShell->SttEndDoc(/*bStt=*/true); + std::vector<beans::PropertyValue> aArgsVec = comphelper::JsonToPropertyValues(R"json( +{ + "BookmarkNamePrefix": { + "type": "string", + "value": "ZOTERO_BREF_" + } +} +)json"_ostr); + uno::Sequence<beans::PropertyValue> aArgs = comphelper::containerToSequence(aArgsVec); + dispatchCommand(mxComponent, ".uno:DeleteBookmarks", aArgs); + + // Then make sure that only the other bookmark is kept: + auto it = pDoc->getIDocumentMarkAccess()->findMark("ZOTERO_BREF_GiQ7DAWQYWLy"); + // Without the accompanying fix in place, this test would have failed, the matching bookmark was + // not removed. + CPPUNIT_ASSERT(bool(it == pDoc->getIDocumentMarkAccess()->getAllMarksEnd())); + it = pDoc->getIDocumentMarkAccess()->findMark("other"); + CPPUNIT_ASSERT(it != pDoc->getIDocumentMarkAccess()->getAllMarksEnd()); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testDeleteFields) +{ + // Given a document with a refmark: + createSwDoc(); + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("TypeName", uno::Any(OUString("SetRef"))), + comphelper::makePropertyValue( + "Name", uno::Any(OUString("ZOTERO_ITEM CSL_CITATION {} RNDpyJknp173F"))), + comphelper::makePropertyValue("Content", uno::Any(OUString("aaa<b>bbb</b>ccc"))), + }; + dispatchCommand(mxComponent, ".uno:InsertField", aArgs); + + // When deleting the refmarks: + std::vector<beans::PropertyValue> aArgsVec = comphelper::JsonToPropertyValues(R"json( +{ + "TypeName": { + "type": "string", + "value": "SetRef" + }, + "NamePrefix": { + "type": "string", + "value": "ZOTERO_ITEM CSL_CITATION" + } +} +)json"_ostr); + aArgs = comphelper::containerToSequence(aArgsVec); + dispatchCommand(mxComponent, ".uno:DeleteFields", aArgs); + + // Then make sure that no refmark is kept: + SwDoc* pDoc = getSwDoc(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 0 + // - Actual : 1 + // i.e. the refmark was not deleted. + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(0), pDoc->GetRefMarks()); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testInsertTextFormFieldFootnote) +{ + // Given an empty document: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + + // When inserting an ODF_UNHANDLED fieldmark inside a footnote: + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("FieldType", uno::Any(ODF_UNHANDLED)), + comphelper::makePropertyValue("FieldCommand", + uno::Any(OUString("ADDIN ZOTERO_BIBL foo bar"))), + comphelper::makePropertyValue("FieldResult", uno::Any(OUString("result"))), + comphelper::makePropertyValue("Wrapper", uno::Any(OUString("Footnote"))), + }; + dispatchCommand(mxComponent, ".uno:TextFormField", aArgs); + + // Then make sure that the footnote is created: + SwFootnoteIdxs& rFootnotes = pDoc->GetFootnoteIdxs(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 0 + // i.e. no footnote was created. + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rFootnotes.size()); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testInsertTextFormFieldEndnote) +{ + // Given an empty document: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + + // When inserting an ODF_UNHANDLED fieldmark inside an endnote: + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("FieldType", uno::Any(ODF_UNHANDLED)), + comphelper::makePropertyValue("FieldCommand", + uno::Any(OUString("ADDIN ZOTERO_BIBL foo bar"))), + comphelper::makePropertyValue("FieldResult", uno::Any(OUString("result"))), + comphelper::makePropertyValue("Wrapper", uno::Any(OUString("Endnote"))), + }; + dispatchCommand(mxComponent, ".uno:TextFormField", aArgs); + + // Then make sure that the endnote is created: + SwFootnoteIdxs& rFootnotes = pDoc->GetFootnoteIdxs(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 0 + // i.e. no endnote was inserted. + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rFootnotes.size()); + SwTextFootnote* pEndnote = rFootnotes[0]; + const SwFormatFootnote& rFormatEndnote = pEndnote->GetFootnote(); + CPPUNIT_ASSERT(rFormatEndnote.IsEndNote()); + // Also check that the endnote body contains the fieldmark: + SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); + pWrtShell->SttEndDoc(/*bStt=*/true); + pWrtShell->GotoFootnoteText(); + pWrtShell->EndOfSection(/*bSelect=*/true); + SwCursor* pCursor = pWrtShell->GetCursor(); + OUString aActual = pCursor->GetText(); + static sal_Unicode const aForbidden[] + = { CH_TXT_ATR_FIELDSTART, CH_TXT_ATR_FIELDSEP, CH_TXT_ATR_FIELDEND, 0 }; + aActual = comphelper::string::removeAny(aActual, aForbidden); + // Then this was empty: the fieldmark was inserted before the note anchor, not in the note body. + CPPUNIT_ASSERT_EQUAL(OUString("result"), aActual); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testUpdateSelectedField) +{ + // Given an empty doc: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + SwPaM* pCursor = pDoc->GetEditShell()->GetCursor(); + + // Insert a time field and select it: + dispatchCommand(mxComponent, ".uno:InsertTimeFieldVar", {}); + + pCursor->SetMark(); + pCursor->Move(fnMoveBackward); + + OUString aTimeFieldBefore, aTimeFieldAfter; + pWrtShell->GetSelectedText(aTimeFieldBefore); + + // Wait for one second: + osl::Thread::wait(std::chrono::seconds(1)); + + // Update the field at cursor: + dispatchCommand(mxComponent, ".uno:UpdateSelectedField", {}); + pWrtShell->GetSelectedText(aTimeFieldAfter); + + // Check that the selected field has changed: + CPPUNIT_ASSERT(aTimeFieldAfter != aTimeFieldBefore); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/uibase/shells/textfld.cxx b/sw/qa/uibase/shells/textfld.cxx new file mode 100644 index 0000000000..6f9fa0c1c2 --- /dev/null +++ b/sw/qa/uibase/shells/textfld.cxx @@ -0,0 +1,90 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <swmodeltestbase.hxx> + +#include <comphelper/propertyvalue.hxx> + +#include <wrtsh.hxx> +#include <docsh.hxx> +#include <ftnidx.hxx> +#include <txtftn.hxx> + +namespace +{ +/// Covers sw/source/uibase/shells/textfld.cxx fixes. +class Test : public SwModelTestBase +{ +public: + Test() + : SwModelTestBase("/sw/qa/uibase/shells/data/") + { + } +}; +} + +CPPUNIT_TEST_FIXTURE(Test, testInsertRefmarkFootnote) +{ + // Given an empty document: + createSwDoc(); + + // When inserting a refmark inside a footnote: + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("TypeName", uno::Any(OUString("SetRef"))), + comphelper::makePropertyValue("Name", uno::Any(OUString("myref"))), + comphelper::makePropertyValue("Content", uno::Any(OUString("content"))), + comphelper::makePropertyValue("Wrapper", uno::Any(OUString("Footnote"))), + }; + dispatchCommand(mxComponent, ".uno:InsertField", aArgs); + + // Then make sure that the note body contains the refmark: + SwDoc* pDoc = getSwDoc(); + SwFootnoteIdxs& rNotes = pDoc->GetFootnoteIdxs(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 0 + // i.e. no note was inserted. + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rNotes.size()); + SwTextFootnote* pNote = rNotes[0]; + const SwFormatFootnote& rFormatNote = pNote->GetFootnote(); + CPPUNIT_ASSERT(!rFormatNote.IsEndNote()); + SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); + CPPUNIT_ASSERT_EQUAL(OUString("content"), rFormatNote.GetFootnoteText(*pWrtShell->GetLayout())); +} + +CPPUNIT_TEST_FIXTURE(Test, testInsertRefmarkEndnote) +{ + // Given an empty document: + createSwDoc(); + + // When inserting a refmark inside an endnote: + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("TypeName", uno::Any(OUString("SetRef"))), + comphelper::makePropertyValue("Name", uno::Any(OUString("myref"))), + comphelper::makePropertyValue("Content", uno::Any(OUString("content"))), + comphelper::makePropertyValue("Wrapper", uno::Any(OUString("Endnote"))), + }; + dispatchCommand(mxComponent, ".uno:InsertField", aArgs); + + // Then make sure that the note body contains the refmark: + SwDoc* pDoc = getSwDoc(); + SwFootnoteIdxs& rNotes = pDoc->GetFootnoteIdxs(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 0 + // i.e. no endnote was inserted. + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rNotes.size()); + SwTextFootnote* pNote = rNotes[0]; + const SwFormatFootnote& rNote = pNote->GetFootnote(); + CPPUNIT_ASSERT(rNote.IsEndNote()); + SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); + CPPUNIT_ASSERT_EQUAL(OUString("content"), rNote.GetFootnoteText(*pWrtShell->GetLayout())); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/uibase/shells/textsh.cxx b/sw/qa/uibase/shells/textsh.cxx new file mode 100644 index 0000000000..ca72a710df --- /dev/null +++ b/sw/qa/uibase/shells/textsh.cxx @@ -0,0 +1,110 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <swmodeltestbase.hxx> + +#include <comphelper/propertyvalue.hxx> +#include <comphelper/propertysequence.hxx> +#include <comphelper/sequence.hxx> +#include <sfx2/viewfrm.hxx> +#include <sfx2/bindings.hxx> + +#include <docary.hxx> +#include <docsh.hxx> +#include <frmmgr.hxx> +#include <wrtsh.hxx> +#include <formatflysplit.hxx> +#include <view.hxx> +#include <cmdid.h> + +namespace +{ +/// Covers sw/source/uibase/shells/textsh.cxx fixes. +class Test : public SwModelTestBase +{ +public: + Test() + : SwModelTestBase("/sw/qa/uibase/shells/data/") + { + } +}; + +CPPUNIT_TEST_FIXTURE(Test, testDeleteSections) +{ + // Given a document with a section: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("RegionName", + uno::Any(OUString("ZOTERO_BIBL {} CSL_BIBLIOGRAPHY RND"))), + comphelper::makePropertyValue("Content", uno::Any(OUString("old content"))), + }; + dispatchCommand(mxComponent, ".uno:InsertSection", aArgs); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pDoc->GetSections().size()); + + // When deleting sections: + std::vector<beans::PropertyValue> aArgsVec = comphelper::JsonToPropertyValues(R"json( +{ + "SectionNamePrefix": { + "type": "string", + "value": "ZOTERO_BIBL" + } +} +)json"_ostr); + aArgs = comphelper::containerToSequence(aArgsVec); + dispatchCommand(mxComponent, ".uno:DeleteSections", aArgs); + + // Then make sure that the section is deleted: + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 0 + // - Actual : 1 + // i.e. the section was not deleted. + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), pDoc->GetSections().size()); +} + +CPPUNIT_TEST_FIXTURE(Test, testSplitFlyFootnoteUI) +{ + // Given a document with a split fly (to host a table): + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); + SwFlyFrameAttrMgr aMgr(true, pWrtShell, Frmmgr_Type::TEXT, nullptr); + RndStdIds eAnchor = RndStdIds::FLY_AT_PARA; + pWrtShell->StartAllAction(); + aMgr.InsertFlyFrame(eAnchor, aMgr.GetPos(), aMgr.GetSize()); + pWrtShell->EndAllAction(); + pWrtShell->StartAllAction(); + sw::FrameFormats<sw::SpzFrameFormat*>& rFlys = *pDoc->GetSpzFrameFormats(); + sw::SpzFrameFormat* pFly = rFlys[0]; + { + SwAttrSet aSet(pFly->GetAttrSet()); + aSet.Put(SwFormatFlySplit(true)); + pDoc->SetAttr(aSet, *pFly); + } + pWrtShell->EndAllAction(); + pWrtShell->UnSelectFrame(); + pWrtShell->LeaveSelFrameMode(); + pWrtShell->GetView().AttrChangedNotify(nullptr); + pWrtShell->MoveSection(GoCurrSection, fnSectionEnd); + + // When checking if we can insert a footnote inside the split fly: + SwView& rView = pWrtShell->GetView(); + std::unique_ptr<SfxPoolItem> pItem; + SfxItemState eState = rView.GetViewFrame().GetBindings().QueryState(FN_INSERT_FOOTNOTE, pItem); + + // Then make sure that the insertion is allowed: + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 32 (DEFAULT) + // - Actual : 1 (DISABLED) + // i.e. the insertion was denied. + CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT, eState); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/uibase/uiview/data/keep-ratio.fodt b/sw/qa/uibase/uiview/data/keep-ratio.fodt new file mode 100644 index 0000000000..7cfffbec56 --- /dev/null +++ b/sw/qa/uibase/uiview/data/keep-ratio.fodt @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<office:document xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" office:mimetype="application/vnd.oasis.opendocument.text"> + <office:settings> + <config:config-item-set config:name="ooo:view-settings"> + <config:config-item-map-indexed config:name="Views"> + <config:config-item-map-entry> + <config:config-item config:name="VisibleLeft" config:type="long">0</config:config-item> + <config:config-item config:name="VisibleTop" config:type="long">0</config:config-item> + <config:config-item config:name="VisibleRight" config:type="long">40190</config:config-item> + <config:config-item config:name="VisibleBottom" config:type="long">22728</config:config-item> + <config:config-item config:name="KeepRatio" config:type="boolean">true</config:config-item> + </config:config-item-map-entry> + </config:config-item-map-indexed> + </config:config-item-set> + </office:settings> + <office:body> + <office:text> + <text:p/> + </office:text> + </office:body> +</office:document> diff --git a/sw/qa/uibase/uiview/data/update-replacement-nosetting.odt b/sw/qa/uibase/uiview/data/update-replacement-nosetting.odt Binary files differnew file mode 100644 index 0000000000..055c3d1a2c --- /dev/null +++ b/sw/qa/uibase/uiview/data/update-replacement-nosetting.odt diff --git a/sw/qa/uibase/uiview/data/updateall-objectreplacements.odt b/sw/qa/uibase/uiview/data/updateall-objectreplacements.odt Binary files differnew file mode 100644 index 0000000000..35decf73f8 --- /dev/null +++ b/sw/qa/uibase/uiview/data/updateall-objectreplacements.odt diff --git a/sw/qa/uibase/uiview/uiview.cxx b/sw/qa/uibase/uiview/uiview.cxx new file mode 100644 index 0000000000..ceae7d644c --- /dev/null +++ b/sw/qa/uibase/uiview/uiview.cxx @@ -0,0 +1,318 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <swmodeltestbase.hxx> + +#include <comphelper/processfactory.hxx> +#include <osl/file.hxx> +#include <comphelper/propertyvalue.hxx> +#include <comphelper/scopeguard.hxx> +#include <vcl/scheduler.hxx> + +#include <com/sun/star/frame/XDispatchHelper.hpp> +#include <com/sun/star/frame/XDispatchProvider.hpp> +#include <com/sun/star/frame/XComponentLoader.hpp> +#include <com/sun/star/frame/XStorable2.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/packages/zip/ZipFileAccess.hpp> +#include <com/sun/star/view/XSelectionSupplier.hpp> + +#include <unotxdoc.hxx> +#include <docsh.hxx> +#include <wrtsh.hxx> +#include <swmodule.hxx> +#include <view.hxx> + +/// Covers sw/source/uibase/uiview/ fixes. +class SwUibaseUiviewTest : public SwModelTestBase +{ +public: + SwUibaseUiviewTest() + : SwModelTestBase("/sw/qa/uibase/uiview/data/") + { + } +}; + +CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testUpdateAllObjectReplacements) +{ + // Make a temporary copy of the test document + createTempCopy(u"updateall-objectreplacements.odt"); + + /* BASIC code that exhibits the problem: + + desktop = CreateUnoService("com.sun.star.frame.Desktop") + Dim props(0) as new com.sun.star.beans.PropertyValue + props(0).Name = "Hidden" + props(0).Value = true + component = desktop.loadComponentFromURL("file://.../test.odt", "_default", 0, props) + Wait 1000 ' workaround + dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") + frame = component.CurrentController.Frame + dispatcher.executeDispatch(frame, ".uno:UpdateAll", "", 0, Array()) + component.storeSelf(Array()) + component.dispose() + */ + + uno::Reference<lang::XMultiServiceFactory> xFactory(comphelper::getProcessServiceFactory()); + + // Load the copy + uno::Reference<uno::XInterface> xInterface + = xFactory->createInstance("com.sun.star.frame.Desktop"); + uno::Reference<frame::XComponentLoader> xComponentLoader(xInterface, uno::UNO_QUERY); + uno::Sequence<beans::PropertyValue> aLoadArgs{ comphelper::makePropertyValue("Hidden", true) }; + mxComponent + = xComponentLoader->loadComponentFromURL(maTempFile.GetURL(), "_default", 0, aLoadArgs); + + // Perform the .uno:UpdateAll call and save + xInterface = xFactory->createInstance("com.sun.star.frame.DispatchHelper"); + uno::Reference<frame::XDispatchHelper> xDispatchHelper(xInterface, uno::UNO_QUERY); + uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); + uno::Reference<frame::XDispatchProvider> xDispatchProvider( + xModel->getCurrentController()->getFrame(), uno::UNO_QUERY); + uno::Sequence<beans::PropertyValue> aNoArgs; + xDispatchHelper->executeDispatch(xDispatchProvider, ".uno:UpdateAll", OUString(), 0, aNoArgs); + uno::Reference<frame::XStorable2> xStorable(mxComponent, uno::UNO_QUERY); + xStorable->storeSelf(aNoArgs); + + // Check the contents of the updated copy and verify that ObjectReplacements are there + uno::Reference<packages::zip::XZipFileAccess2> xNameAccess + = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(xFactory), + maTempFile.GetURL()); + + CPPUNIT_ASSERT(xNameAccess->hasByName("ObjectReplacements/Components")); + CPPUNIT_ASSERT(xNameAccess->hasByName("ObjectReplacements/Components_1")); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testUpdateReplacementNosetting) +{ + // Load a copy of the document in hidden mode. + OUString aSourceURL = createFileURL(u"update-replacement-nosetting.odt"); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, osl::File::copy(aSourceURL, maTempFile.GetURL())); + mxComponent = loadFromDesktop(maTempFile.GetURL(), "com.sun.star.text.TextDocument", + { comphelper::makePropertyValue("Hidden", true) }); + + // Update "everything" (including object replacements) and save it. + dispatchCommand(mxComponent, ".uno:UpdateAll", {}); + uno::Reference<frame::XStorable2> xStorable(mxComponent, uno::UNO_QUERY); + xStorable->storeSelf({}); + + // Check the contents of the updated copy. + uno::Reference<uno::XComponentContext> xContext = comphelper::getProcessComponentContext(); + uno::Reference<packages::zip::XZipFileAccess2> xNameAccess + = packages::zip::ZipFileAccess::createWithURL(xContext, maTempFile.GetURL()); + + // Without the accompanying fix in place, this test would have failed, because the embedded + // object replacement image was not generated. + CPPUNIT_ASSERT(xNameAccess->hasByName("ObjectReplacements/Components")); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testKeepRatio) +{ + // Given a document with a custom KeepRatio: + OUString aURL = createFileURL(u"keep-ratio.fodt"); + + // When loading that document: + mxComponent = loadFromDesktop(aURL); + + // Then make sure we read the custom value: + auto pXTextDocument = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell(); + const SwViewOption* pViewOption = pWrtShell->GetViewOptions(); + comphelper::ScopeGuard g([pWrtShell, pViewOption] { + SwViewOption aViewOption(*pViewOption); + aViewOption.SetKeepRatio(false); + SW_MOD()->ApplyUsrPref(aViewOption, &pWrtShell->GetView()); + }); + // Without the accompanying fix in place, this test would have failed, because KeepRatio was not + // mapped to settings.xml + CPPUNIT_ASSERT(pViewOption->IsKeepRatio()); + + // Then export as well: + save("writer8"); + xmlDocUniquePtr pXmlDoc = parseExport("settings.xml"); + assertXPathContent(pXmlDoc, "//config:config-item[@config:name='KeepRatio']"_ostr, "true"); +} + +namespace +{ +/// Interception implementation that disables .uno:Zoom on Image1, but not on Image2. +struct ImageInterceptor : public cppu::WeakImplHelper<frame::XDispatchProviderInterceptor> +{ + uno::Reference<view::XSelectionSupplier> m_xSelectionSupplier; + uno::Reference<frame::XDispatchProvider> m_xMaster; + uno::Reference<frame::XDispatchProvider> m_xSlave; + int m_nEnabled = 0; + int m_nDisabled = 0; + +public: + ImageInterceptor(const uno::Reference<lang::XComponent>& xComponent); + + // XDispatchProviderInterceptor + uno::Reference<frame::XDispatchProvider> SAL_CALL getMasterDispatchProvider() override; + uno::Reference<frame::XDispatchProvider> SAL_CALL getSlaveDispatchProvider() override; + void SAL_CALL setMasterDispatchProvider( + const uno::Reference<frame::XDispatchProvider>& xNewSupplier) override; + void SAL_CALL + setSlaveDispatchProvider(const uno::Reference<frame::XDispatchProvider>& xNewSupplier) override; + + // XDispatchProvider + uno::Reference<frame::XDispatch> SAL_CALL queryDispatch(const util::URL& rURL, + const OUString& rTargetFrameName, + sal_Int32 SearchFlags) override; + uno::Sequence<uno::Reference<frame::XDispatch>> SAL_CALL + queryDispatches(const uno::Sequence<frame::DispatchDescriptor>& rRequests) override; +}; +} + +ImageInterceptor::ImageInterceptor(const uno::Reference<lang::XComponent>& xComponent) +{ + uno::Reference<frame::XModel2> xModel(xComponent, uno::UNO_QUERY); + CPPUNIT_ASSERT(xModel.is()); + m_xSelectionSupplier.set(xModel->getCurrentController(), uno::UNO_QUERY); + CPPUNIT_ASSERT(m_xSelectionSupplier.is()); +} + +uno::Reference<frame::XDispatchProvider> ImageInterceptor::getMasterDispatchProvider() +{ + return m_xMaster; +} + +uno::Reference<frame::XDispatchProvider> ImageInterceptor::getSlaveDispatchProvider() +{ + return m_xSlave; +} + +void ImageInterceptor::setMasterDispatchProvider( + const uno::Reference<frame::XDispatchProvider>& xNewSupplier) +{ + m_xMaster = xNewSupplier; +} + +void ImageInterceptor::setSlaveDispatchProvider( + const uno::Reference<frame::XDispatchProvider>& xNewSupplier) +{ + m_xSlave = xNewSupplier; +} + +uno::Reference<frame::XDispatch> ImageInterceptor::queryDispatch(const util::URL& rURL, + const OUString& rTargetFrameName, + sal_Int32 nSearchFlags) +{ + // Disable the UNO command based on the currently selected image, i.e. this can't be cached when + // a different image is selected. Originally this was .uno:SetBorderStyle, but let's pick a + // command which is active when running cppunit tests: + if (rURL.Complete == ".uno:Zoom") + { + uno::Reference<container::XNamed> xImage; + m_xSelectionSupplier->getSelection() >>= xImage; + if (xImage.is() && xImage->getName() == "Image1") + { + ++m_nDisabled; + return {}; + } + + ++m_nEnabled; + } + + return m_xSlave->queryDispatch(rURL, rTargetFrameName, nSearchFlags); +} + +uno::Sequence<uno::Reference<frame::XDispatch>> +ImageInterceptor::queryDispatches(const uno::Sequence<frame::DispatchDescriptor>& /*rRequests*/) +{ + return {}; +} + +CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testSwitchBetweenImages) +{ + // Given a document with 2 images, and an interceptor catching an UNO command that specific to + // the current selection: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + uno::Reference<lang::XMultiServiceFactory> xMSF(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XText> xText = xTextDocument->getText(); + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + for (int i = 0; i < 2; ++i) + { + uno::Reference<beans::XPropertySet> xTextGraphic( + xMSF->createInstance("com.sun.star.text.TextGraphicObject"), uno::UNO_QUERY); + xTextGraphic->setPropertyValue("AnchorType", + uno::Any(text::TextContentAnchorType_AS_CHARACTER)); + xTextGraphic->setPropertyValue("Size", uno::Any(awt::Size(5000, 5000))); + uno::Reference<text::XTextContent> xTextContent(xTextGraphic, uno::UNO_QUERY); + xText->insertTextContent(xCursor, xTextContent, false); + } + pWrtShell->SttEndDoc(/*bStt=*/false); + uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); + uno::Reference<frame::XDispatchProviderInterception> xRegistration( + xModel->getCurrentController()->getFrame(), uno::UNO_QUERY); + rtl::Reference pInterceptor(new ImageInterceptor(mxComponent)); + + xRegistration->registerDispatchProviderInterceptor(pInterceptor); + pInterceptor->m_nEnabled = 0; + pInterceptor->m_nDisabled = 0; + + // When selecting the first image: + selectShape(1); + + // Then make sure the UNO command is disabled: + CPPUNIT_ASSERT_EQUAL(0, pInterceptor->m_nEnabled); + CPPUNIT_ASSERT_GREATEREQUAL(1, pInterceptor->m_nDisabled); + + // Given a clean state: + pInterceptor->m_nEnabled = 0; + pInterceptor->m_nDisabled = 0; + + // When selecting the second image: + selectShape(2); + + // Then make sure the UNO command is enabled: + CPPUNIT_ASSERT_GREATEREQUAL(1, pInterceptor->m_nEnabled); + CPPUNIT_ASSERT_EQUAL(0, pInterceptor->m_nDisabled); + + // Given a clean state: + pInterceptor->m_nEnabled = 0; + pInterceptor->m_nDisabled = 0; + + // When selecting the first image, again (this time not changing the selection type): + selectShape(1); + + // Then make sure the UNO command is disabled: + CPPUNIT_ASSERT_EQUAL(0, pInterceptor->m_nEnabled); + // Without the accompanying fix in place, this test would have failed with: + // - Expected greater or equal than: 1 + // - Actual : 0 + // i.e. selecting the first image didn't result in a disabled UNO command. + CPPUNIT_ASSERT_GREATEREQUAL(1, pInterceptor->m_nDisabled); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testPrintPreview) +{ + // Given a normal Writer view, in half-destroyed state, similar to what + // SfxViewFrame::SwitchToViewShell_Impl() does in practice: + createSwDoc(); + SwDocShell* pDocShell = getSwDocShell(); + SwView* pView = pDocShell->GetView(); + FmFormShell* pFormShell = pView->GetFormShell(); + pView->SetFormShell(reinterpret_cast<FmFormShell*>(-1)); + pView->SetDying(); + + // When selecting a shell, similar to what happens the doc size changes: + // Then make sure we don't crash: + pView->SelectShell(); + + // Restore the state and shut down. + pView->SetFormShell(pFormShell); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/uibase/uno/data/cond-field-cached-value.docx b/sw/qa/uibase/uno/data/cond-field-cached-value.docx Binary files differnew file mode 100644 index 0000000000..a19b1240c9 --- /dev/null +++ b/sw/qa/uibase/uno/data/cond-field-cached-value.docx diff --git a/sw/qa/uibase/uno/uno.cxx b/sw/qa/uibase/uno/uno.cxx new file mode 100644 index 0000000000..d38d0bbfc9 --- /dev/null +++ b/sw/qa/uibase/uno/uno.cxx @@ -0,0 +1,565 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <swmodeltestbase.hxx> + +#include <boost/property_tree/json_parser.hpp> + +#include <com/sun/star/frame/XModel2.hpp> +#include <com/sun/star/text/XTextViewTextRangeSupplier.hpp> +#include <com/sun/star/util/XCloseable.hpp> +#include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/beans/PropertyAttribute.hpp> + +#include <vcl/scheduler.hxx> +#include <tools/json_writer.hxx> +#include <comphelper/propertyvalue.hxx> +#include <xmloff/odffields.hxx> + +#include <docsh.hxx> +#include <edtwin.hxx> +#include <unotextrange.hxx> +#include <view.hxx> +#include <wrtsh.hxx> +#include <rootfrm.hxx> +#include <sortedobjs.hxx> +#include <anchoredobject.hxx> +#include <frameformats.hxx> +#include <fmtanchr.hxx> +#include <unotxdoc.hxx> + +/// Covers sw/source/uibase/uno/ fixes. +class SwUibaseUnoTest : public SwModelTestBase +{ +public: + SwUibaseUnoTest() + : SwModelTestBase("/sw/qa/uibase/uno/data/") + { + } +}; + +CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testLockControllers) +{ + createSwDoc(); + { + uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY_THROW); + xModel->lockControllers(); + } + { + uno::Reference<util::XCloseable> xCloseable(mxComponent, uno::UNO_QUERY_THROW); + xCloseable->close(false); + } + // Without the accompanying fix in place, this test would have crashed. + mxComponent.clear(); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testCondFieldCachedValue) +{ + createSwDoc("cond-field-cached-value.docx"); + Scheduler::ProcessEventsToIdle(); + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : + // i.e. the conditional field lost its cached content. + getParagraph(2, "1"); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testCreateTextRangeByPixelPosition) +{ + // Given a document with 2 characters, and the pixel position of the point between them: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + SwDocShell* pDocShell = pDoc->GetDocShell(); + SwWrtShell* pWrtShell = pDocShell->GetWrtShell(); + pWrtShell->Insert2("AZ"); + pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false); + Point aLogic = pWrtShell->GetCharRect().Center(); + SwView* pView = pDocShell->GetView(); + SwEditWin& rEditWin = pView->GetEditWin(); + Point aPixel = rEditWin.LogicToPixel(aLogic); + + // When converting that pixel position to a document model position (text range): + uno::Reference<frame::XModel2> xModel(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xControllers = xModel->getControllers(); + uno::Reference<text::XTextViewTextRangeSupplier> xController(xControllers->nextElement(), + uno::UNO_QUERY); + awt::Point aPoint(aPixel.getX(), aPixel.getY()); + uno::Reference<text::XTextRange> xTextRange + = xController->createTextRangeByPixelPosition(aPoint); + + // Then make sure that text range points after the first character: + auto pTextRange = dynamic_cast<SwXTextRange*>(xTextRange.get()); + SwPaM aPaM(pDoc->GetNodes()); + pTextRange->GetPositions(aPaM); + sal_Int32 nActual = aPaM.GetPoint()->GetContentIndex(); + // Without the needed PixelToLogic() call in place, this test would have failed with: + // - Expected: 1 + // - Actual : 0 + // i.e. the returned text range pointed before the first character, not between the first and + // the second character. + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), nActual); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testCreateTextRangeByPixelPositionGraphic) +{ + // Given a document with an as-char image and the center of that image in pixels: + createSwDoc(); + uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xTextGraphic( + xFactory->createInstance("com.sun.star.text.TextGraphicObject"), uno::UNO_QUERY); + xTextGraphic->setPropertyValue("AnchorType", + uno::Any(text::TextContentAnchorType_AS_CHARACTER)); + xTextGraphic->setPropertyValue("Width", uno::Any(static_cast<sal_Int32>(10000))); + xTextGraphic->setPropertyValue("Height", uno::Any(static_cast<sal_Int32>(10000))); + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XText> xBodyText = xTextDocument->getText(); + uno::Reference<text::XTextCursor> xCursor(xBodyText->createTextCursor()); + uno::Reference<text::XTextContent> xTextContent(xTextGraphic, uno::UNO_QUERY); + xBodyText->insertTextContent(xCursor, xTextContent, false); + SwDoc* pDoc = getSwDoc(); + SwDocShell* pDocShell = pDoc->GetDocShell(); + SwWrtShell* pWrtShell = pDocShell->GetWrtShell(); + SwRootFrame* pLayout = pWrtShell->GetLayout(); + SwFrame* pPage = pLayout->GetLower(); + SwFrame* pBody = pPage->GetLower(); + SwFrame* pText = pBody->GetLower(); + SwSortedObjs& rDrawObjs = *pText->GetDrawObjs(); + SwAnchoredObject* pAnchored = rDrawObjs[0]; + Point aLogic = pAnchored->GetObjRect().Center(); + SwView* pView = pDocShell->GetView(); + SwEditWin& rEditWin = pView->GetEditWin(); + Point aPixel = rEditWin.LogicToPixel(aLogic); + + // When converting that pixel position to a document model position (text range): + uno::Reference<frame::XModel2> xModel(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xControllers = xModel->getControllers(); + uno::Reference<text::XTextViewTextRangeSupplier> xController(xControllers->nextElement(), + uno::UNO_QUERY); + awt::Point aPoint(aPixel.getX(), aPixel.getY()); + // Without the accompanying fix in place, this test would have crashed, because an XTextRange + // can't point to a graphic node. + uno::Reference<text::XTextRange> xTextRange + = xController->createTextRangeByPixelPosition(aPoint); + + // Then make sure that the anchor of the image is returned: + const auto& rFormats = *pDoc->GetSpzFrameFormats(); + const auto pFormat = rFormats[0]; + SwPosition aAnchorPos(*pFormat->GetAnchor().GetContentAnchor()); + auto pTextRange = dynamic_cast<SwXTextRange*>(xTextRange.get()); + SwPaM aPaM(pDoc->GetNodes()); + pTextRange->GetPositions(aPaM); + CPPUNIT_ASSERT_EQUAL(aAnchorPos, *aPaM.GetPoint()); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testCreateTextRangeByPixelPositionAtPageGraphic) +{ + // Given a document with an at-page anchored image: + createSwDoc(); + uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xTextGraphic( + xFactory->createInstance("com.sun.star.text.TextGraphicObject"), uno::UNO_QUERY); + xTextGraphic->setPropertyValue("AnchorType", uno::Any(text::TextContentAnchorType_AT_PAGE)); + xTextGraphic->setPropertyValue("AnchorPageNo", uno::Any(static_cast<sal_Int16>(1))); + xTextGraphic->setPropertyValue("Width", uno::Any(static_cast<sal_Int32>(10000))); + xTextGraphic->setPropertyValue("Height", uno::Any(static_cast<sal_Int32>(10000))); + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XText> xBodyText = xTextDocument->getText(); + uno::Reference<text::XTextCursor> xCursor(xBodyText->createTextCursor()); + uno::Reference<text::XTextContent> xTextContent(xTextGraphic, uno::UNO_QUERY); + xBodyText->insertTextContent(xCursor, xTextContent, false); + SwDoc* pDoc = getSwDoc(); + SwDocShell* pDocShell = pDoc->GetDocShell(); + SwWrtShell* pWrtShell = pDocShell->GetWrtShell(); + SwRootFrame* pLayout = pWrtShell->GetLayout(); + SwFrame* pPage = pLayout->GetLower(); + SwSortedObjs& rDrawObjs = *pPage->GetDrawObjs(); + SwAnchoredObject* pAnchored = rDrawObjs[0]; + Point aLogic = pAnchored->GetObjRect().Center(); + SwView* pView = pDocShell->GetView(); + SwEditWin& rEditWin = pView->GetEditWin(); + Point aPixel = rEditWin.LogicToPixel(aLogic); + + // When asking for the doc model pos of the image's anchor by pixel position: + uno::Reference<frame::XModel2> xModel(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xControllers = xModel->getControllers(); + uno::Reference<text::XTextViewTextRangeSupplier> xController(xControllers->nextElement(), + uno::UNO_QUERY); + awt::Point aPoint(aPixel.getX(), aPixel.getY()); + // Without the accompanying fix in place, this test would have crashed. + uno::Reference<text::XTextRange> xTextRange + = xController->createTextRangeByPixelPosition(aPoint); + + // Then make sure that the result is empty, since the image is at-page anchored: + CPPUNIT_ASSERT(!xTextRange.is()); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testGetTextFormFields) +{ + // Given a document with 3 fieldmarks: 2 zotero items and a zotero + // bibliography: + createSwDoc(); + for (int i = 0; i < 2; ++i) + { + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("FieldType", uno::Any(ODF_UNHANDLED)), + comphelper::makePropertyValue("FieldCommand", + uno::Any(OUString("ADDIN ZOTERO_ITEM foo bar"))), + comphelper::makePropertyValue("FieldResult", uno::Any(OUString("result"))), + }; + dispatchCommand(mxComponent, ".uno:TextFormField", aArgs); + } + { + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("FieldType", uno::Any(ODF_UNHANDLED)), + comphelper::makePropertyValue("FieldCommand", + uno::Any(OUString("ADDIN ZOTERO_BIBL foo bar"))), + comphelper::makePropertyValue("FieldResult", + uno::Any(OUString("<p>aaa</p><p>bbb</p>"))), + }; + dispatchCommand(mxComponent, ".uno:TextFormField", aArgs); + } + + // When getting the zotero items: + tools::JsonWriter aJsonWriter; + std::string_view aCommand(".uno:TextFormFields?type=vnd.oasis.opendocument.field.UNHANDLED&" + "commandPrefix=ADDIN%20ZOTERO_ITEM"); + auto pXTextDocument = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + pXTextDocument->getCommandValues(aJsonWriter, aCommand); + + // Then make sure we find the 2 items and ignore the bibliography: + OString pJSON(aJsonWriter.finishAndGetAsOString()); + std::stringstream aStream((std::string(pJSON))); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + // Without the accompanying fix in place, this test would have failed with: + // - No such node (fields) + // i.e. the returned JSON was just empty. + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), aTree.get_child("fields").count("")); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testGetDocumentProperties) +{ + // Given a document with 3 custom properties: 2 Zotero ones and one other: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + SwDocShell* pDocShell = pDoc->GetDocShell(); + uno::Reference<document::XDocumentPropertiesSupplier> xDPS(pDocShell->GetModel(), + uno::UNO_QUERY); + uno::Reference<document::XDocumentProperties> xDP = xDPS->getDocumentProperties(); + uno::Reference<beans::XPropertyContainer> xUDP = xDP->getUserDefinedProperties(); + xUDP->addProperty("ZOTERO_PREF_1", beans::PropertyAttribute::REMOVABLE, + uno::Any(OUString("foo"))); + xUDP->addProperty("ZOTERO_PREF_2", beans::PropertyAttribute::REMOVABLE, + uno::Any(OUString("bar"))); + xUDP->addProperty("OTHER", beans::PropertyAttribute::REMOVABLE, uno::Any(OUString("baz"))); + + // When getting the zotero properties: + tools::JsonWriter aJsonWriter; + std::string_view aCommand(".uno:SetDocumentProperties?namePrefix=ZOTERO_PREF_"); + auto pXTextDocument = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + pXTextDocument->getCommandValues(aJsonWriter, aCommand); + + // Then make sure we find the 2 properties and ignore the other one: + OString pJSON(aJsonWriter.finishAndGetAsOString()); + std::stringstream aStream((std::string(pJSON))); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + // Without the accompanying fix in place, this test would have failed with: + // - No such node (userDefinedProperties) + // i.e. the returned JSON was just empty. + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), + aTree.get_child("userDefinedProperties").count("")); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testGetBookmarks) +{ + // Given a document with 3 bookmarks: 2 zotero references and a zotero bibliography: + createSwDoc(); + { + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("Bookmark", uno::Any(OUString("ZOTERO_BREF_1"))), + }; + dispatchCommand(mxComponent, ".uno:InsertBookmark", aArgs); + } + { + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("Bookmark", uno::Any(OUString("ZOTERO_BREF_2"))), + }; + dispatchCommand(mxComponent, ".uno:InsertBookmark", aArgs); + } + { + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("Bookmark", uno::Any(OUString("ZOTERO_BIBL"))), + }; + dispatchCommand(mxComponent, ".uno:InsertBookmark", aArgs); + } + + // When getting the reference bookmarks: + tools::JsonWriter aJsonWriter; + std::string_view aCommand(".uno:Bookmarks?namePrefix=ZOTERO_BREF_"); + auto pXTextDocument = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + pXTextDocument->getCommandValues(aJsonWriter, aCommand); + + // Then make sure we get the 2 references but not the bibliography: + OString pJSON(aJsonWriter.finishAndGetAsOString()); + std::stringstream aStream((std::string(pJSON))); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + // Without the accompanying fix in place, this test would have failed with: + // - No such node (bookmarks) + // i.e. the returned JSON was just empty. + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), aTree.get_child("bookmarks").count("")); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testGetFields) +{ + // Given a document with a refmark: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + OUString aName("ZOTERO_ITEM CSL_CITATION {} "); + for (int i = 0; i < 5; ++i) + { + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("TypeName", uno::Any(OUString("SetRef"))), + comphelper::makePropertyValue("Name", uno::Any(aName + OUString::number(i + 1))), + comphelper::makePropertyValue("Content", uno::Any(OUString("mycontent"))), + }; + dispatchCommand(mxComponent, ".uno:InsertField", aArgs); + pWrtShell->SttEndDoc(/*bStt=*/false); + pWrtShell->SplitNode(); + pWrtShell->SttEndDoc(/*bStt=*/false); + } + + // When getting the refmarks: + tools::JsonWriter aJsonWriter; + std::string_view aCommand(".uno:Fields?typeName=SetRef&namePrefix=ZOTERO_ITEM%20CSL_CITATION"); + auto pXTextDocument = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + pXTextDocument->getCommandValues(aJsonWriter, aCommand); + + // Then make sure we get the 1 refmark: + OString pJSON(aJsonWriter.finishAndGetAsOString()); + std::stringstream aStream((std::string(pJSON))); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + // Without the accompanying fix in place, this test would have failed with: + // - No such node (setRefs) + // i.e. the returned JSON was just empty. + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(5), aTree.get_child("setRefs").count("")); + auto it = aTree.get_child("setRefs").begin(); + boost::property_tree::ptree aRef = (it++)->second; + CPPUNIT_ASSERT_EQUAL(std::string("ZOTERO_ITEM CSL_CITATION {} 1"), + aRef.get<std::string>("name")); + aRef = (it++)->second; + CPPUNIT_ASSERT_EQUAL(std::string("ZOTERO_ITEM CSL_CITATION {} 2"), + aRef.get<std::string>("name")); + aRef = (it++)->second; + // Without the accompanying fix in place, this test would have failed with: + // - Expected: ZOTERO_ITEM CSL_CITATION {} 3 + // - Actual : ZOTERO_ITEM CSL_CITATION {} 4 + // i.e. the output was unsorted. + CPPUNIT_ASSERT_EQUAL(std::string("ZOTERO_ITEM CSL_CITATION {} 3"), + aRef.get<std::string>("name")); + aRef = (it++)->second; + CPPUNIT_ASSERT_EQUAL(std::string("ZOTERO_ITEM CSL_CITATION {} 4"), + aRef.get<std::string>("name")); + aRef = (it++)->second; + CPPUNIT_ASSERT_EQUAL(std::string("ZOTERO_ITEM CSL_CITATION {} 5"), + aRef.get<std::string>("name")); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testGetTextFormField) +{ + // Given a document with a fieldmark: + createSwDoc(); + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("FieldType", uno::Any(ODF_UNHANDLED)), + comphelper::makePropertyValue("FieldCommand", + uno::Any(OUString("ADDIN ZOTERO_ITEM foo bar"))), + comphelper::makePropertyValue("FieldResult", uno::Any(OUString("result"))), + }; + dispatchCommand(mxComponent, ".uno:TextFormField", aArgs); + + // When stepping into the fieldmark with the cursor and getting the command value for + // uno:TextFormField: + SwDoc* pDoc = getSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->SttEndDoc(/*bStt=*/false); + pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false); + tools::JsonWriter aJsonWriter; + std::string_view aCommand(".uno:TextFormField?type=vnd.oasis.opendocument.field.UNHANDLED&" + "commandPrefix=ADDIN%20ZOTERO_ITEM"); + auto pXTextDocument = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + pXTextDocument->getCommandValues(aJsonWriter, aCommand); + + // Then make sure we find the inserted fieldmark: + OString pJSON(aJsonWriter.finishAndGetAsOString()); + std::stringstream aStream((std::string(pJSON))); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + // Without the accompanying fix in place, this test would have failed with: + // - No such node (type) + // i.e. the returned JSON was just an empty object. + auto field = aTree.get_child("field"); + CPPUNIT_ASSERT_EQUAL(std::string("vnd.oasis.opendocument.field.UNHANDLED"), + field.get<std::string>("type")); + CPPUNIT_ASSERT_EQUAL(std::string("ADDIN ZOTERO_ITEM foo bar"), + field.get<std::string>("command")); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testGetSections) +{ + // Given a document with a section: + createSwDoc(); + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue( + "RegionName", uno::Any(OUString("ZOTERO_BIBL {} CSL_BIBLIOGRAPHY RNDRfiit6mXBc"))), + comphelper::makePropertyValue("Content", uno::Any(OUString("<p>aaa</p><p>bbb</p>"))), + }; + dispatchCommand(mxComponent, ".uno:InsertSection", aArgs); + + // When asking for a list of section names: + tools::JsonWriter aJsonWriter; + std::string_view aCommand(".uno:Sections?namePrefix=ZOTERO_BIBL"); + auto pXTextDocument = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + pXTextDocument->getCommandValues(aJsonWriter, aCommand); + + // Make sure we find our just inserted section: + OString pJSON(aJsonWriter.finishAndGetAsOString()); + std::stringstream aStream((std::string(pJSON))); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + // Without the accompanying fix in place, this test would have failed with: + // - No such node (sections) + // i.e. the returned JSON was an empty object. + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aTree.get_child("sections").count("")); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testGetBookmark) +{ + // Given a document with a bookmark: + createSwDoc(); + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("Bookmark", uno::Any(OUString("ZOTERO_BREF_1"))), + comphelper::makePropertyValue("BookmarkText", uno::Any(OUString("<p>aaa</p><p>bbb</p>"))), + }; + dispatchCommand(mxComponent, ".uno:InsertBookmark", aArgs); + + // When stepping into the bookmark with the cursor and getting the command value for + // .uno:Bookmark: + SwDoc* pDoc = getSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->SttEndDoc(/*bStt=*/false); + pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false); + tools::JsonWriter aJsonWriter; + std::string_view aCommand(".uno:Bookmark?namePrefix=ZOTERO_BREF_"); + auto pXTextDocument = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + pXTextDocument->getCommandValues(aJsonWriter, aCommand); + + // Then make sure we find the inserted bookmark: + OString pJSON(aJsonWriter.finishAndGetAsOString()); + std::stringstream aStream((std::string(pJSON))); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + boost::property_tree::ptree aBookmark = aTree.get_child("bookmark"); + // Without the accompanying fix in place, this test would have failed with: + // - No such node (bookmark) + // i.e. the returned JSON was an empty object. + CPPUNIT_ASSERT_EQUAL(std::string("ZOTERO_BREF_1"), aBookmark.get<std::string>("name")); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testGetField) +{ + // Given a document with a refmark: + createSwDoc(); + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("TypeName", uno::Any(OUString("SetRef"))), + comphelper::makePropertyValue("Name", + uno::Any(OUString("ZOTERO_ITEM CSL_CITATION {} refmark"))), + comphelper::makePropertyValue("Content", uno::Any(OUString("content"))), + }; + dispatchCommand(mxComponent, ".uno:InsertField", aArgs); + + // When in the refmark with the cursor and getting the command value for .uno:Field: + SwDoc* pDoc = getSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->SttEndDoc(/*bStt=*/false); + pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false); + tools::JsonWriter aJsonWriter; + std::string_view aCommand(".uno:Field?typeName=SetRef&namePrefix=ZOTERO_ITEM%20CSL_CITATION"); + auto pXTextDocument = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + pXTextDocument->getCommandValues(aJsonWriter, aCommand); + + // Then make sure we find the inserted refmark: + OString pJSON(aJsonWriter.finishAndGetAsOString()); + std::stringstream aStream((std::string(pJSON))); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + boost::property_tree::ptree aBookmark = aTree.get_child("setRef"); + // Without the accompanying fix in place, this test would have failed with: + // - No such node (setRef) + // i.e. the returned JSON was an empty object. + CPPUNIT_ASSERT_EQUAL(std::string("ZOTERO_ITEM CSL_CITATION {} refmark"), + aBookmark.get<std::string>("name")); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testDoNotBreakWrappedTables) +{ + // Given an empty document: + createSwDoc(); + + // When checking the state of the DoNotBreakWrappedTables compat flag: + uno::Reference<lang::XMultiServiceFactory> xDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xSettings( + xDocument->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY); + bool bDoNotBreakWrappedTables{}; + // Without the accompanying fix in place, this test would have failed with: + // An uncaught exception of type com.sun.star.beans.UnknownPropertyException + // i.e. the compat flag was not recognized. + xSettings->getPropertyValue("DoNotBreakWrappedTables") >>= bDoNotBreakWrappedTables; + // Then make sure it's false by default: + CPPUNIT_ASSERT(!bDoNotBreakWrappedTables); + + // And when setting DoNotBreakWrappedTables=true: + xSettings->setPropertyValue("DoNotBreakWrappedTables", uno::Any(true)); + // Then make sure it gets enabled: + xSettings->getPropertyValue("DoNotBreakWrappedTables") >>= bDoNotBreakWrappedTables; + CPPUNIT_ASSERT(bDoNotBreakWrappedTables); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testAllowTextAfterFloatingTableBreak) +{ + // Given an empty document: + createSwDoc(); + + // When checking the state of the AllowTextAfterFloatingTableBreak compat flag: + uno::Reference<lang::XMultiServiceFactory> xDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xSettings( + xDocument->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY); + bool bAllowTextAfterFloatingTableBreak{}; + // Without the accompanying fix in place, this test would have failed with: + // An uncaught exception of type com.sun.star.beans.UnknownPropertyException + // i.e. the compat flag was not recognized. + xSettings->getPropertyValue("AllowTextAfterFloatingTableBreak") + >>= bAllowTextAfterFloatingTableBreak; + // Then make sure it's false by default: + CPPUNIT_ASSERT(!bAllowTextAfterFloatingTableBreak); + + // And when setting AllowTextAfterFloatingTableBreak=true: + xSettings->setPropertyValue("AllowTextAfterFloatingTableBreak", uno::Any(true)); + // Then make sure it gets enabled: + xSettings->getPropertyValue("AllowTextAfterFloatingTableBreak") + >>= bAllowTextAfterFloatingTableBreak; + CPPUNIT_ASSERT(bAllowTextAfterFloatingTableBreak); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/uibase/wrtsh/wrtsh.cxx b/sw/qa/uibase/wrtsh/wrtsh.cxx new file mode 100644 index 0000000000..125a805840 --- /dev/null +++ b/sw/qa/uibase/wrtsh/wrtsh.cxx @@ -0,0 +1,437 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <wrtsh.hxx> + +#include <optional> + +#include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/text/XTextRange.hpp> +#include <com/sun/star/text/XTextDocument.hpp> + +#include <rtl/ustring.hxx> +#include <sal/types.h> +#include <comphelper/propertyvalue.hxx> + +#include <swmodeltestbase.hxx> +#include <doc.hxx> +#include <docsh.hxx> +#include <formatlinebreak.hxx> +#include <ndtxt.hxx> +#include <textcontentcontrol.hxx> +#include <fmtanchr.hxx> + +namespace +{ +/// Covers sw/source/uibase/wrtsh/ fixes. +class Test : public SwModelTestBase +{ +}; + +CPPUNIT_TEST_FIXTURE(Test, testInsertLineBreak) +{ + // Given an empty document: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + + // When inserting a clearing break: + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + std::optional<SwLineBreakClear> oClear = SwLineBreakClear::ALL; + pWrtShell->InsertLineBreak(oClear); + + // Then make sure it's not just a plain linebreak: + uno::Reference<css::text::XTextRange> xTextPortion = getRun(getParagraph(1), 1); + auto aPortionType = getProperty<OUString>(xTextPortion, "TextPortionType"); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: LineBreak + // - Actual : Text + // i.e. the line break lost its "clear" property. + CPPUNIT_ASSERT_EQUAL(OUString("LineBreak"), aPortionType); + auto xLineBreak = getProperty<uno::Reference<text::XTextContent>>(xTextPortion, "LineBreak"); + auto eClear = getProperty<sal_Int16>(xLineBreak, "Clear"); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(SwLineBreakClear::ALL), eClear); +} + +CPPUNIT_TEST_FIXTURE(Test, testGotoContentControl) +{ + // Given a document with a content control: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + uno::Reference<lang::XMultiServiceFactory> xMSF(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XText> xText = xTextDocument->getText(); + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + xText->insertString(xCursor, "test", /*bAbsorb=*/false); + xCursor->gotoStart(/*bExpand=*/false); + xCursor->gotoEnd(/*bExpand=*/true); + uno::Reference<text::XTextContent> xContentControl( + xMSF->createInstance("com.sun.star.text.ContentControl"), uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY); + xContentControlProps->setPropertyValue("ShowingPlaceHolder", uno::Any(true)); + xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true); + + // When going to that content control in placeholder mode: + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + SwNodeOffset nIndex = pWrtShell->GetCursor()->GetPointNode().GetIndex(); + SwTextNode* pTextNode = pDoc->GetNodes()[nIndex]->GetTextNode(); + SwTextAttr* pAttr = pTextNode->GetTextAttrForCharAt(0, RES_TXTATR_CONTENTCONTROL); + auto pTextContentControl = static_txtattr_cast<SwTextContentControl*>(pAttr); + auto& rFormatContentControl + = static_cast<SwFormatContentControl&>(pTextContentControl->GetAttr()); + pWrtShell->GotoContentControl(rFormatContentControl); + + // Then make sure that the content control is selected (without the dummy character): + // Without the accompanying fix in place, this test would have failed, the user had to manually + // select the placeholder text. + sal_Int32 nStart = pWrtShell->GetCursor()->Start()->GetContentIndex(); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), nStart); + sal_Int32 nEnd = pWrtShell->GetCursor()->End()->GetContentIndex(); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(5), nEnd); +} + +CPPUNIT_TEST_FIXTURE(Test, testTickCheckboxContentControl) +{ + // Given a document with a checkbox (checked) content control: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + uno::Reference<lang::XMultiServiceFactory> xMSF(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XText> xText = xTextDocument->getText(); + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + xText->insertString(xCursor, u"☒"_ustr, /*bAbsorb=*/false); + xCursor->gotoStart(/*bExpand=*/false); + xCursor->gotoEnd(/*bExpand=*/true); + uno::Reference<text::XTextContent> xContentControl( + xMSF->createInstance("com.sun.star.text.ContentControl"), uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY); + xContentControlProps->setPropertyValue("Checkbox", uno::Any(true)); + xContentControlProps->setPropertyValue("Checked", uno::Any(true)); + xContentControlProps->setPropertyValue("CheckedState", uno::Any(u"☒"_ustr)); + xContentControlProps->setPropertyValue("UncheckedState", uno::Any(u"☐"_ustr)); + xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true); + + // When clicking on that content control: + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + SwTextNode* pTextNode = pWrtShell->GetCursor()->GetPointNode().GetTextNode(); + SwTextAttr* pAttr = pTextNode->GetTextAttrForCharAt(0, RES_TXTATR_CONTENTCONTROL); + auto pTextContentControl = static_txtattr_cast<SwTextContentControl*>(pAttr); + auto& rFormatContentControl + = static_cast<SwFormatContentControl&>(pTextContentControl->GetAttr()); + pWrtShell->GotoContentControl(rFormatContentControl); + + // Then make sure that the checkbox is no longer checked: + // Without the accompanying fix in place, this test would have failed: + // - Expected: ☐ + // - Actual : ☒ + // i.e. the text node's text was "Ballot Box with X", not just "Ballot Box". + CPPUNIT_ASSERT_EQUAL(u"☐"_ustr, pTextNode->GetExpandText(pWrtShell->GetLayout())); +} + +CPPUNIT_TEST_FIXTURE(Test, testInsertContentControl) +{ + // Given an empty document: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + + // When inserting a content control: + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->InsertContentControl(SwContentControlType::RICH_TEXT); + + // Then make sure that the matching text attribute is added to the document model: + SwTextNode* pTextNode = pWrtShell->GetCursor()->GetPointNode().GetTextNode(); + // Without the accompanying fix in place, this test would have failed, nothing happened on + // InsertContentControl(). + CPPUNIT_ASSERT(pTextNode->GetTextAttrForCharAt(0, RES_TXTATR_CONTENTCONTROL)); +} + +CPPUNIT_TEST_FIXTURE(Test, testInsertCheckboxContentControl) +{ + // Given an empty document: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + + // When inserting a content control: + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->InsertContentControl(SwContentControlType::CHECKBOX); + + // Then make sure that the matching text attribute is added to the document model: + SwTextNode* pTextNode = pWrtShell->GetCursor()->GetPointNode().GetTextNode(); + SwTextAttr* pAttr = pTextNode->GetTextAttrForCharAt(0, RES_TXTATR_CONTENTCONTROL); + auto pTextContentControl = static_txtattr_cast<SwTextContentControl*>(pAttr); + auto& rFormatContentControl + = static_cast<SwFormatContentControl&>(pTextContentControl->GetAttr()); + std::shared_ptr<SwContentControl> pContentControl = rFormatContentControl.GetContentControl(); + // Without the accompanying fix in place, this test would have failed, the inserted content + // control wasn't a checkbox one. + CPPUNIT_ASSERT(pContentControl->GetCheckbox()); +} + +CPPUNIT_TEST_FIXTURE(Test, testSelectDropdownContentControl) +{ + // Given a document with a dropdown content control: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + uno::Reference<lang::XMultiServiceFactory> xMSF(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XText> xText = xTextDocument->getText(); + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + xText->insertString(xCursor, "choose an item", /*bAbsorb=*/false); + xCursor->gotoStart(/*bExpand=*/false); + xCursor->gotoEnd(/*bExpand=*/true); + uno::Reference<text::XTextContent> xContentControl( + xMSF->createInstance("com.sun.star.text.ContentControl"), uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY); + { + uno::Sequence<beans::PropertyValues> aListItems = { + { + comphelper::makePropertyValue("DisplayText", uno::Any(OUString("red"))), + comphelper::makePropertyValue("Value", uno::Any(OUString("R"))), + }, + { + comphelper::makePropertyValue("DisplayText", uno::Any(OUString("green"))), + comphelper::makePropertyValue("Value", uno::Any(OUString("G"))), + }, + { + comphelper::makePropertyValue("DisplayText", uno::Any(OUString("blue"))), + comphelper::makePropertyValue("Value", uno::Any(OUString("B"))), + }, + }; + xContentControlProps->setPropertyValue("ListItems", uno::Any(aListItems)); + } + xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true); + + // When clicking on that content control: + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + SwTextNode* pTextNode = pWrtShell->GetCursor()->GetPointNode().GetTextNode(); + SwTextAttr* pAttr = pTextNode->GetTextAttrForCharAt(0, RES_TXTATR_CONTENTCONTROL); + auto pTextContentControl = static_txtattr_cast<SwTextContentControl*>(pAttr); + auto& rFormatContentControl + = static_cast<SwFormatContentControl&>(pTextContentControl->GetAttr()); + rFormatContentControl.GetContentControl()->SetSelectedListItem(0); + pWrtShell->GotoContentControl(rFormatContentControl); + + // Then make sure that the document text is updated: + // Without the accompanying fix in place, this test would have failed: + // - Expected: red + // - Actual : choose an item + // i.e. the document text was unchanged instead of display text of the first list item. + CPPUNIT_ASSERT_EQUAL(OUString("red"), pTextNode->GetExpandText(pWrtShell->GetLayout())); +} + +CPPUNIT_TEST_FIXTURE(Test, testInsertDropdownContentControl) +{ + // Given an empty document: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + + // When inserting a content control: + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->InsertContentControl(SwContentControlType::DROP_DOWN_LIST); + + // Then make sure that the matching text attribute is added to the document model: + SwTextNode* pTextNode = pWrtShell->GetCursor()->GetPointNode().GetTextNode(); + SwTextAttr* pAttr = pTextNode->GetTextAttrForCharAt(0, RES_TXTATR_CONTENTCONTROL); + auto pTextContentControl = static_txtattr_cast<SwTextContentControl*>(pAttr); + auto& rFormatContentControl + = static_cast<SwFormatContentControl&>(pTextContentControl->GetAttr()); + std::shared_ptr<SwContentControl> pContentControl = rFormatContentControl.GetContentControl(); + // Without the accompanying fix in place, this test would have failed: + // - Expected: 1 + // - Actual : 0 + // i.e. the inserted content control was a default (rich text) one, not a dropdown. + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pContentControl->GetListItems().size()); +} + +CPPUNIT_TEST_FIXTURE(Test, testReplacePictureContentControl) +{ + // Given a document with a picture content control: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + uno::Reference<lang::XMultiServiceFactory> xMSF(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XText> xText = xTextDocument->getText(); + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + uno::Reference<beans::XPropertySet> xTextGraphic( + xMSF->createInstance("com.sun.star.text.TextGraphicObject"), uno::UNO_QUERY); + xTextGraphic->setPropertyValue("AnchorType", + uno::Any(text::TextContentAnchorType_AS_CHARACTER)); + uno::Reference<text::XTextContent> xTextContent(xTextGraphic, uno::UNO_QUERY); + xText->insertTextContent(xCursor, xTextContent, false); + xCursor->gotoStart(/*bExpand=*/false); + xCursor->gotoEnd(/*bExpand=*/true); + uno::Reference<text::XTextContent> xContentControl( + xMSF->createInstance("com.sun.star.text.ContentControl"), uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY); + xContentControlProps->setPropertyValue("ShowingPlaceHolder", uno::Any(true)); + xContentControlProps->setPropertyValue("Picture", uno::Any(true)); + xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true); + + // When clicking on that content control: + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->GotoObj(/*bNext=*/true, GotoObjFlags::Any); + pWrtShell->EnterSelFrameMode(); + const SwFrameFormat* pFlyFormat = pWrtShell->GetFlyFrameFormat(); + const SwFormatAnchor& rFormatAnchor = pFlyFormat->GetAnchor(); + SwNode* pAnchorNode = rFormatAnchor.GetAnchorNode(); + SwTextNode* pTextNode = pAnchorNode->GetTextNode(); + SwTextAttr* pAttr = pTextNode->GetTextAttrForCharAt(0, RES_TXTATR_CONTENTCONTROL); + auto pTextContentControl = static_txtattr_cast<SwTextContentControl*>(pAttr); + auto& rFormatContentControl + = static_cast<SwFormatContentControl&>(pTextContentControl->GetAttr()); + pWrtShell->GotoContentControl(rFormatContentControl); + + // Then make sure that the picture is replaced: + CPPUNIT_ASSERT(!rFormatContentControl.GetContentControl()->GetShowingPlaceHolder()); + // Without the accompanying fix in place, this test would have failed, there was no special + // handling for picture content control (how to interact with them), and the default handler + // killed the image selection. + CPPUNIT_ASSERT(pWrtShell->IsFrameSelected()); +} + +CPPUNIT_TEST_FIXTURE(Test, testInsertPictureContentControl) +{ + // Given an empty document: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + + // When inserting a content control: + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->InsertContentControl(SwContentControlType::PICTURE); + + // Then make sure that the matching text attribute is added to the document model: + SwTextNode* pTextNode = pWrtShell->GetCursor()->GetPointNode().GetTextNode(); + SwTextAttr* pAttr = pTextNode->GetTextAttrForCharAt(0, RES_TXTATR_CONTENTCONTROL); + auto pTextContentControl = static_txtattr_cast<SwTextContentControl*>(pAttr); + auto& rFormatContentControl + = static_cast<SwFormatContentControl&>(pTextContentControl->GetAttr()); + std::shared_ptr<SwContentControl> pContentControl = rFormatContentControl.GetContentControl(); + // Without the accompanying fix in place, this test would have failed, there was no special + // handling for picture content control, no placeholder fly content was inserted. + CPPUNIT_ASSERT(pContentControl->GetPicture()); + CPPUNIT_ASSERT(pTextNode->GetTextAttrForCharAt(1, RES_TXTATR_FLYCNT)); +} + +CPPUNIT_TEST_FIXTURE(Test, testSelectDateContentControl) +{ + // Given a document with a date content control: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + uno::Reference<lang::XMultiServiceFactory> xMSF(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XText> xText = xTextDocument->getText(); + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + xText->insertString(xCursor, "test", /*bAbsorb=*/false); + xCursor->gotoStart(/*bExpand=*/false); + xCursor->gotoEnd(/*bExpand=*/true); + uno::Reference<text::XTextContent> xContentControl( + xMSF->createInstance("com.sun.star.text.ContentControl"), uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY); + xContentControlProps->setPropertyValue("Date", uno::Any(true)); + xContentControlProps->setPropertyValue("DateFormat", uno::Any(OUString("YYYY-MM-DD"))); + xContentControlProps->setPropertyValue("DateLanguage", uno::Any(OUString("en-US"))); + xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true); + + // When clicking on that content control: + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + SwTextNode* pTextNode = pWrtShell->GetCursor()->GetPointNode().GetTextNode(); + SwTextAttr* pAttr = pTextNode->GetTextAttrForCharAt(0, RES_TXTATR_CONTENTCONTROL); + auto pTextContentControl = static_txtattr_cast<SwTextContentControl*>(pAttr); + auto& rFormatContentControl + = static_cast<SwFormatContentControl&>(pTextContentControl->GetAttr()); + rFormatContentControl.GetContentControl()->SetSelectedDate(44705); + pWrtShell->GotoContentControl(rFormatContentControl); + + // Then make sure that the document text is updated: + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 2022-05-24 + // - Actual : test + // i.e. the content control was not updated. + CPPUNIT_ASSERT_EQUAL(OUString("2022-05-24"), pTextNode->GetExpandText(pWrtShell->GetLayout())); + CPPUNIT_ASSERT_EQUAL(OUString("2022-05-24T00:00:00Z"), + rFormatContentControl.GetContentControl()->GetCurrentDate()); +} + +CPPUNIT_TEST_FIXTURE(Test, testInsertDateContentControl) +{ + // Given an empty document: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + + // When inserting a date content control: + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->InsertContentControl(SwContentControlType::DATE); + + // Then make sure that the matching text attribute is added to the document model: + SwTextNode* pTextNode = pWrtShell->GetCursor()->GetPointNode().GetTextNode(); + SwTextAttr* pAttr = pTextNode->GetTextAttrForCharAt(0, RES_TXTATR_CONTENTCONTROL); + auto pTextContentControl = static_txtattr_cast<SwTextContentControl*>(pAttr); + auto& rFormatContentControl + = static_cast<SwFormatContentControl&>(pTextContentControl->GetAttr()); + std::shared_ptr<SwContentControl> pContentControl = rFormatContentControl.GetContentControl(); + // Without the accompanying fix in place, this test would have failed, there was no special + // handling for date content control. + CPPUNIT_ASSERT(pContentControl->GetDate()); +} + +CPPUNIT_TEST_FIXTURE(Test, testInsertPlainTextContentControl) +{ + // Given an empty document: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + + // When inserting a plain text content control: + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->InsertContentControl(SwContentControlType::PLAIN_TEXT); + + // Then make sure that the matching text attribute is added to the document model: + SwTextNode* pTextNode = pWrtShell->GetCursor()->GetPointNode().GetTextNode(); + SwTextAttr* pAttr = pTextNode->GetTextAttrForCharAt(0, RES_TXTATR_CONTENTCONTROL); + auto pTextContentControl = static_txtattr_cast<SwTextContentControl*>(pAttr); + auto& rFormatContentControl + = static_cast<SwFormatContentControl&>(pTextContentControl->GetAttr()); + std::shared_ptr<SwContentControl> pContentControl = rFormatContentControl.GetContentControl(); + // Without the accompanying fix in place, this test would have failed, there was no special + // handling for plain text content controls. + CPPUNIT_ASSERT(pContentControl->GetPlainText()); + + CPPUNIT_ASSERT(pContentControl->GetShowingPlaceHolder()); + pWrtShell->GotoContentControl(rFormatContentControl); + CPPUNIT_ASSERT(pContentControl->GetShowingPlaceHolder()); + pWrtShell->Insert("Foo"); + // No longer showing placeholder text, as it has been changed + CPPUNIT_ASSERT(!pContentControl->GetShowingPlaceHolder()); +} + +CPPUNIT_TEST_FIXTURE(Test, testInsertComboBoxContentControl) +{ + // Given an empty document: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + + // When inserting a combo box content control: + dispatchCommand(mxComponent, ".uno:InsertComboBoxContentControl", {}); + + // Then make sure that the matching text attribute is added to the document model: + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + SwTextNode* pTextNode = pWrtShell->GetCursor()->GetPointNode().GetTextNode(); + // Without the accompanying fix in place, this test would have failed, no content control was + // inserted. + SwTextAttr* pAttr = pTextNode->GetTextAttrForCharAt(0, RES_TXTATR_CONTENTCONTROL); + CPPUNIT_ASSERT(pAttr); + auto pTextContentControl = static_txtattr_cast<SwTextContentControl*>(pAttr); + auto& rFormatContentControl + = static_cast<SwFormatContentControl&>(pTextContentControl->GetAttr()); + std::shared_ptr<SwContentControl> pContentControl = rFormatContentControl.GetContentControl(); + CPPUNIT_ASSERT(pContentControl->GetComboBox()); +} +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |