diff options
author | Skyler Grey <skyler.grey@collabora.com> | 2023-10-13 09:36:51 +0000 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2023-10-19 08:18:14 +0200 |
commit | 613249e2b208716aa71580ff0373bb201d9c2697 (patch) | |
tree | 1d188ee92e06b52c3403583b12910b7befa7c713 | |
parent | LOK: send state of protected cells (diff) | |
download | core-613249e2b208716aa71580ff0373bb201d9c2697.tar.gz core-613249e2b208716aa71580ff0373bb201d9c2697.zip |
Add tests for STYLEREF and fix STYLEREF bugs
- testTdf86790 tests that the "sample file with STYLEREF" document from
tdf#86790 has the correct fields
- testStyleRefSearchUp tests that the STYLEREF searches up when there
are bits of text both above and below it
- testStyleRefSearchDown tests that the STYLEREF searches down when
there are bits of text below it only
- testMarginalStyleRef tests that the STYLEREF searches from the page
top when it is placed in a footer
- testFootnotetyleRef tests that the STYLEREF searches from the
reference mark when it is placed in a footnote
- As an artifact of changing the STYLEREF namespace from TEXT to LO_EXT
partway through, some references to STYLEREF being in TEXT still
remained. This caused STYLEREFs saved to ODF to vanish on import. This
has been fixed
- Previously STYLEREF kept a pointer to the frame and text node
containing it. Unfortunately, sometimes these could be destructed and
the STYLEREF later asked to update which led to a crash due to
use-after-free. STYLEREF no longer keeps a pointer to these values,
instead preferring to not update when it is not given them
- As part of the review process for
I25dd7a6940abee5651a784b9059fe23b32547d6c we added
SearchForStyleAnchor, a function used only in reffld.cxx, to an
anonymous namespace. Unfortunately we neglected to do the same for
StyleRefElementType just above it. This has been fixed
Follow-Up-To: I25dd7a6940abee5651a784b9059fe23b32547d6c
Change-Id: I35dc36197b62fa53def4745da1d4755ece79ed22
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157911
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
-rw-r--r-- | sw/inc/reffld.hxx | 20 | ||||
-rw-r--r-- | sw/qa/core/fields/data/tdf86790.docx | bin | 0 -> 15679 bytes | |||
-rw-r--r-- | sw/qa/core/fields/fields.cxx | 228 | ||||
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter7.cxx | 15 | ||||
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter8.cxx | 6 | ||||
-rw-r--r-- | sw/source/core/fields/reffld.cxx | 73 | ||||
-rw-r--r-- | sw/source/core/text/txtfld.cxx | 7 | ||||
-rw-r--r-- | sw/source/core/txtnode/atrfld.cxx | 2 | ||||
-rw-r--r-- | sw/source/core/unocore/unofield.cxx | 2 | ||||
-rw-r--r-- | sw/source/filter/ww8/ww8par5.cxx | 8 | ||||
-rw-r--r-- | sw/source/ui/fldui/fldref.cxx | 6 | ||||
-rw-r--r-- | sw/source/uibase/docvw/edtwin2.cxx | 2 | ||||
-rw-r--r-- | sw/source/uibase/fldui/fldmgr.cxx | 13 | ||||
-rw-r--r-- | sw/source/uibase/utlui/content.cxx | 2 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 2 | ||||
-rw-r--r-- | xmloff/source/text/txtfldi.cxx | 4 |
16 files changed, 287 insertions, 103 deletions
diff --git a/sw/inc/reffld.hxx b/sw/inc/reffld.hxx index 28ced8dcc2cb..bf9d563ab2ac 100644 --- a/sw/inc/reffld.hxx +++ b/sw/inc/reffld.hxx @@ -99,22 +99,15 @@ private: /// reference to either a SwTextFootnote::m_nSeqNo or a SwSetExpField::mnSeqNo sal_uInt16 m_nSeqNo; - SwTextNode* m_pTextNode; ///< a pointer to the text node which contains the field - SwFrame* m_pFrame; ///< a pointer to the frame which contains the field - /* m_pTextNode and m_pFrame are used for STYLEREF, for other subtypes these will often be nullptr */ - virtual OUString ExpandImpl(SwRootFrame const* pLayout) const override; virtual std::unique_ptr<SwField> Copy() const override; public: SwGetRefField( SwGetRefFieldType*, OUString aSetRef, OUString aReferenceLanguage, - sal_uInt16 nSubType, sal_uInt16 nSeqNo, sal_uLong nFormat, - SwTextNode* pTextNode, SwFrame* pFrame ); + sal_uInt16 nSubType, sal_uInt16 nSeqNo, sal_uLong nFormat ); virtual ~SwGetRefField() override; - void ChangeExpansion(SwFrame* pFrame, const SwTextField* pField); - virtual OUString GetFieldName() const override; const OUString& GetSetRefName() const { return m_sSetRefName; } @@ -126,9 +119,9 @@ public: and REF_STYLE. Note: This instance may be NULL (field in Undo/Redo). This will cause no update for these reference format types. */ - void UpdateField( const SwTextField* pFieldTextAttr ); - void UpdateField( const SwTextField* pFieldTextAttr, const SwRootFrame* const pLayout, - OUString& rText ); + void UpdateField( const SwTextField* pFieldTextAttr, SwFrame* pFrame ); + void UpdateField( const SwTextField* pFieldTextAttr, SwFrame* pFrame, + const SwRootFrame* const pLayout, OUString& rText ); void SetExpand( const OUString& rStr ); @@ -139,10 +132,9 @@ public: // --> #i81002# bool IsRefToHeadingCrossRefBookmark() const; bool IsRefToNumItemCrossRefBookmark() const; - const SwTextNode* GetReferencedTextNode(SwTextNode* pTextNode) const; + const SwTextNode* GetReferencedTextNode(SwTextNode* pTextNode, SwFrame* pFrame) const; // #i85090# - OUString GetExpandedTextOfReferencedTextNode(SwRootFrame const& rLayout) const; - OUString GetExpandedTextOfReferencedTextNode(SwRootFrame const& rLayout, SwTextNode* pTextNode) const; + OUString GetExpandedTextOfReferencedTextNode(SwRootFrame const& rLayout, SwTextNode* pTextNode, SwFrame* pFrame) const; /// Get/set SequenceNo (of interest only for REF_SEQUENCEFLD). sal_uInt16 GetSeqNo() const { return m_nSeqNo; } diff --git a/sw/qa/core/fields/data/tdf86790.docx b/sw/qa/core/fields/data/tdf86790.docx Binary files differnew file mode 100644 index 000000000000..a45c03f6b898 --- /dev/null +++ b/sw/qa/core/fields/data/tdf86790.docx diff --git a/sw/qa/core/fields/fields.cxx b/sw/qa/core/fields/fields.cxx index 6f1fd79ee582..4a3dd3af1593 100644 --- a/sw/qa/core/fields/fields.cxx +++ b/sw/qa/core/fields/fields.cxx @@ -7,6 +7,36 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/frame/XStorable.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/text/ControlCharacter.hpp> +#include <com/sun/star/text/ReferenceFieldPart.hpp> +#include <com/sun/star/text/ReferenceFieldSource.hpp> +#include <com/sun/star/text/XFootnote.hpp> +#include <com/sun/star/text/XFootnotesSupplier.hpp> +#include <com/sun/star/text/XSimpleText.hpp> +#include <com/sun/star/text/XTextField.hpp> +#include <com/sun/star/text/XTextRange.hpp> +#include <com/sun/star/frame/XStorable.hpp> +#include <com/sun/star/text/XPageCursor.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/XPropertySetInfo.hpp> +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/text/XSimpleText.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/text/XPageCursor.hpp> +#include <com/sun/star/text/XTextCursor.hpp> +#include <com/sun/star/uno/Any.h> +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/uno/Sequence.h> +#include <cppunit/TestAssert.h> +#include <cppunit/extensions/HelperMacros.h> +#include <rtl/ustring.hxx> +#include <sal/types.h> #include <swmodeltestbase.hxx> #include <com/sun/star/text/XTextDocument.hpp> @@ -135,6 +165,204 @@ CPPUNIT_TEST_FIXTURE(Test, testChapterFieldsFollowedBy) CPPUNIT_ASSERT_EQUAL(sValue, xField->getPresentation(false)); } } + +CPPUNIT_TEST_FIXTURE(Test, testTdf86790) +{ + loadFromURL(u"tdf86790.docx"); + + uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xFieldsAccess( + xTextFieldsSupplier->getTextFields()); + uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); + + // Similarly to testChapterFieldsFollowedBy, the fields are enumerated with #1 first and everything else in reverse order + std::vector<std::pair<OUString, OUString>> aFieldValues = { + { " Heading 1", "1" }, // #1 + { " foobar", "22.2" }, // #5 + { " foobar", "4" }, // #4 + { " Heading 2", "1.1" }, // #3 + { " Heading 2", "1.1" }, // #2 + }; + + for (const auto& sValue : aFieldValues) + { + CPPUNIT_ASSERT(xFields->hasMoreElements()); + uno::Reference<text::XTextField> xField(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sValue.first, xField->getPresentation(true)); + CPPUNIT_ASSERT_EQUAL(sValue.second, xField->getPresentation(false)); + } +} + +/// If there is referenced text both above and below, STYLEREF searches up +CPPUNIT_TEST_FIXTURE(Test, testStyleRefSearchUp) +{ + createSwDoc(); + + 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> xCursorPropertySet(xCursor, uno::UNO_QUERY); + + xCursorPropertySet->setPropertyValue("ParaStyleName", uno::Any(OUString("Heading 1"))); + xText->insertString(xCursor, "Heading far above field", false); + xText->insertControlCharacter(xCursor, text::ControlCharacter::PARAGRAPH_BREAK, false); + + xCursorPropertySet->setPropertyValue("ParaStyleName", uno::Any(OUString("Heading 1"))); + xText->insertString(xCursor, "Heading above field", false); + xText->insertControlCharacter(xCursor, text::ControlCharacter::PARAGRAPH_BREAK, false); + + uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XTextField> xField( + xFactory->createInstance("com.sun.star.text.TextField.GetReference"), uno::UNO_QUERY); + + uno::Reference<beans::XPropertySet> xFieldPropertySet(xField, uno::UNO_QUERY); + xFieldPropertySet->setPropertyValue("ReferenceFieldSource", + uno::Any(sal_Int16(text::ReferenceFieldSource::STYLE))); + xFieldPropertySet->setPropertyValue("ReferenceFieldPart", + uno::Any(sal_Int16(text::ReferenceFieldPart::TEXT))); + xFieldPropertySet->setPropertyValue("SourceName", uno::Any(OUString("Heading 1"))); + + uno::Reference<text::XTextCursor> xFieldCursor = xText->createTextCursor(); + + xText->insertControlCharacter(xCursor, text::ControlCharacter::PARAGRAPH_BREAK, false); + xCursorPropertySet->setPropertyValue("ParaStyleName", uno::Any(OUString("Heading 1"))); + xText->insertString(xCursor, "Heading below field", false); + + xField->attach(xFieldCursor); + CPPUNIT_ASSERT_EQUAL(OUString("Heading above field"), xField->getPresentation(false)); +} + +/// If there is referenced text both above and below, STYLEREF searches down +CPPUNIT_TEST_FIXTURE(Test, testStyleRefSearchDown) +{ + createSwDoc(); + + 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> xCursorPropertySet(xCursor, uno::UNO_QUERY); + + uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XTextField> xField( + xFactory->createInstance("com.sun.star.text.TextField.GetReference"), uno::UNO_QUERY); + + uno::Reference<beans::XPropertySet> xFieldPropertySet(xField, uno::UNO_QUERY); + xFieldPropertySet->setPropertyValue("ReferenceFieldSource", + uno::Any(sal_Int16(text::ReferenceFieldSource::STYLE))); + xFieldPropertySet->setPropertyValue("ReferenceFieldPart", + uno::Any(sal_Int16(text::ReferenceFieldPart::TEXT))); + xFieldPropertySet->setPropertyValue("SourceName", uno::Any(OUString("Heading 1"))); + + uno::Reference<text::XTextCursor> xFieldCursor = xText->createTextCursor(); + + xText->insertControlCharacter(xCursor, text::ControlCharacter::PARAGRAPH_BREAK, false); + xCursorPropertySet->setPropertyValue("ParaStyleName", uno::Any(OUString("Heading 1"))); + xText->insertString(xCursor, "Heading below field", false); + + xText->insertControlCharacter(xCursor, text::ControlCharacter::PARAGRAPH_BREAK, false); + xCursorPropertySet->setPropertyValue("ParaStyleName", uno::Any(OUString("Heading 1"))); + xText->insertString(xCursor, "Heading far below field", false); + + xField->attach(xFieldCursor); + CPPUNIT_ASSERT_EQUAL(OUString("Heading below field"), xField->getPresentation(false)); +} + +/// STYLEREFs in marginals (headers or footers) should search in the page they are on first, regardless if there is anything above them +CPPUNIT_TEST_FIXTURE(Test, testMarginalStyleRef) +{ + createSwDoc(); + + 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> xCursorPropertySet(xCursor, uno::UNO_QUERY); + + xCursorPropertySet->setPropertyValue("ParaStyleName", uno::Any(OUString("Heading 1"))); + xText->insertString(xCursor, "Top heading on page", false); + xText->insertControlCharacter(xCursor, text::ControlCharacter::PARAGRAPH_BREAK, false); + + xCursorPropertySet->setPropertyValue("ParaStyleName", uno::Any(OUString("Heading 1"))); + xText->insertString(xCursor, "Bottom heading on page", false); + xText->insertControlCharacter(xCursor, text::ControlCharacter::PARAGRAPH_BREAK, false); + + uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XTextField> xField( + xFactory->createInstance("com.sun.star.text.TextField.GetReference"), uno::UNO_QUERY); + + uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(mxComponent, + uno::UNO_QUERY); + uno::Reference<container::XNameContainer> xParagraphStylesContainer( + xStyleFamiliesSupplier->getStyleFamilies()->getByName("PageStyles"), uno::UNO_QUERY); + + uno::Reference<beans::XPropertySet> xPagePropertySet( + xParagraphStylesContainer->getByName("Standard"), uno::UNO_QUERY); + + xPagePropertySet->setPropertyValue("FooterIsOn", uno::Any(true)); + uno::Reference<text::XText> xFooterText(xPagePropertySet->getPropertyValue("FooterText"), + uno::UNO_QUERY); + + uno::Reference<beans::XPropertySet> xFieldPropertySet(xField, uno::UNO_QUERY); + xFieldPropertySet->setPropertyValue("ReferenceFieldSource", + uno::Any(sal_Int16(text::ReferenceFieldSource::STYLE))); + xFieldPropertySet->setPropertyValue("ReferenceFieldPart", + uno::Any(sal_Int16(text::ReferenceFieldPart::TEXT))); + xFieldPropertySet->setPropertyValue("SourceName", uno::Any(OUString("Heading 1"))); + + uno::Reference<text::XTextRange> xFooterCursor = xFooterText->createTextCursor(); + xField->attach(xFooterCursor); + + CPPUNIT_ASSERT_EQUAL(OUString("Top heading on page"), xField->getPresentation(false)); +} + +/// STYLEREFs in footnotes should search from the point of the reference mark +CPPUNIT_TEST_FIXTURE(Test, testFootnoteStyleRef) +{ + createSwDoc(); + + 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> xCursorPropertySet(xCursor, uno::UNO_QUERY); + + xCursorPropertySet->setPropertyValue("ParaStyleName", uno::Any(OUString("Heading 1"))); + xText->insertString(xCursor, "Heading far above reference mark", false); + xText->insertControlCharacter(xCursor, text::ControlCharacter::PARAGRAPH_BREAK, false); + + xCursorPropertySet->setPropertyValue("ParaStyleName", uno::Any(OUString("Heading 1"))); + xText->insertString(xCursor, "Heading above reference mark", false); + xText->insertControlCharacter(xCursor, text::ControlCharacter::PARAGRAPH_BREAK, false); + + uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY); + + uno::Reference<text::XFootnote> xFootnote( + xFactory->createInstance("com.sun.star.text.Footnote"), uno::UNO_QUERY); + xFootnote->setLabel("Style reference mark"); + xText->insertTextContent(xCursor, xFootnote, false); + + xText->insertControlCharacter(xCursor, text::ControlCharacter::PARAGRAPH_BREAK, false); + xCursorPropertySet->setPropertyValue("ParaStyleName", uno::Any(OUString("Heading 1"))); + xText->insertString(xCursor, "Heading below reference mark", false); + + uno::Reference<text::XTextField> xField( + xFactory->createInstance("com.sun.star.text.TextField.GetReference"), uno::UNO_QUERY); + + uno::Reference<beans::XPropertySet> xFieldPropertySet(xField, uno::UNO_QUERY); + xFieldPropertySet->setPropertyValue("ReferenceFieldSource", + uno::Any(sal_Int16(text::ReferenceFieldSource::STYLE))); + xFieldPropertySet->setPropertyValue("ReferenceFieldPart", + uno::Any(sal_Int16(text::ReferenceFieldPart::TEXT))); + xFieldPropertySet->setPropertyValue("SourceName", uno::Any(OUString("Heading 1"))); + + uno::Reference<text::XSimpleText> xFootnoteText(xFootnote, uno::UNO_QUERY); + uno::Reference<text::XTextRange> xFootnoteCursor = xFootnoteText->createTextCursor(); + xField->attach(xFootnoteCursor); + + CPPUNIT_ASSERT_EQUAL(OUString("Heading above reference mark"), xField->getPresentation(false)); +} } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/qa/extras/uiwriter/uiwriter7.cxx b/sw/qa/extras/uiwriter/uiwriter7.cxx index 10cb2ace0179..697a9defa63c 100644 --- a/sw/qa/extras/uiwriter/uiwriter7.cxx +++ b/sw/qa/extras/uiwriter/uiwriter7.cxx @@ -780,16 +780,14 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf77342) //moving cursor to the starting of document pWrtShell->StartOfSection(); //inserting reference field 1 - SwGetRefField aField1(pRefType, "", "", REF_FOOTNOTE, sal_uInt16(0), REF_CONTENT, nullptr, - nullptr); + SwGetRefField aField1(pRefType, "", "", REF_FOOTNOTE, sal_uInt16(0), REF_CONTENT); pWrtShell->InsertField2(aField1); //inserting second footnote pWrtShell->InsertFootnote(""); pWrtShell->StartOfSection(); pCursor->Move(fnMoveForward); //inserting reference field 2 - SwGetRefField aField2(pRefType, "", "", REF_FOOTNOTE, sal_uInt16(1), REF_CONTENT, nullptr, - nullptr); + SwGetRefField aField2(pRefType, "", "", REF_FOOTNOTE, sal_uInt16(1), REF_CONTENT); pWrtShell->InsertField2(aField2); //inserting third footnote pWrtShell->InsertFootnote(""); @@ -797,8 +795,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf77342) pCursor->Move(fnMoveForward); pCursor->Move(fnMoveForward); //inserting reference field 3 - SwGetRefField aField3(pRefType, "", "", REF_FOOTNOTE, sal_uInt16(2), REF_CONTENT, nullptr, - nullptr); + SwGetRefField aField3(pRefType, "", "", REF_FOOTNOTE, sal_uInt16(2), REF_CONTENT); pWrtShell->InsertField2(aField3); //updating the fields IDocumentFieldsAccess& rField(pDoc->getIDocumentFieldsAccess()); @@ -1038,7 +1035,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf63553) pWrtShell->StartOfSection(); //inserting reference field 1 SwGetRefField aGetField1(pRefType, "Illustration", "", REF_SEQUENCEFLD, sal_uInt16(0), - REF_CONTENT, nullptr, nullptr); + REF_CONTENT); pWrtShell->InsertField2(aGetField1); //now we have ref1-seq1 //moving the cursor @@ -1051,7 +1048,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf63553) pCursor->Move(fnMoveForward); //inserting reference field 2 SwGetRefField aGetField2(pRefType, "Illustration", "", REF_SEQUENCEFLD, sal_uInt16(1), - REF_CONTENT, nullptr, nullptr); + REF_CONTENT); pWrtShell->InsertField2(aGetField2); //now we have ref1-ref2-seq1-seq2 //moving the cursor @@ -1065,7 +1062,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf63553) pCursor->Move(fnMoveForward); //inserting reference field 3 SwGetRefField aGetField3(pRefType, "Illustration", "", REF_SEQUENCEFLD, sal_uInt16(2), - REF_CONTENT, nullptr, nullptr); + REF_CONTENT); pWrtShell->InsertField2(aGetField3); //now after insertion we have ref1-ref2-ref3-seq1-seq2-seq3 //updating the fields diff --git a/sw/qa/extras/uiwriter/uiwriter8.cxx b/sw/qa/extras/uiwriter/uiwriter8.cxx index fd154c6c36a2..cedac55734c8 100644 --- a/sw/qa/extras/uiwriter/uiwriter8.cxx +++ b/sw/qa/extras/uiwriter/uiwriter8.cxx @@ -2390,9 +2390,9 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf128106) CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_BOOKMARK), fields[0]->GetField()->GetSubType()); CPPUNIT_ASSERT_EQUAL(OUString("bookmarkchapter1_text"), static_cast<SwGetRefField const*>(fields[0]->GetField())->GetSetRefName()); - CPPUNIT_ASSERT_EQUAL(OUString("Text"), - static_cast<SwGetRefField const*>(fields[0]->GetField()) - ->GetExpandedTextOfReferencedTextNode(*pWrtShell->GetLayout())); + CPPUNIT_ASSERT_EQUAL(OUString("Text"), static_cast<SwGetRefField const*>(fields[0]->GetField()) + ->GetExpandedTextOfReferencedTextNode( + *pWrtShell->GetLayout(), nullptr, nullptr)); CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_BOOKMARK), fields[1]->GetField()->GetSubType()); CPPUNIT_ASSERT( static_cast<SwGetRefField const*>(fields[1]->GetField())->IsRefToHeadingCrossRefBookmark()); diff --git a/sw/source/core/fields/reffld.cxx b/sw/source/core/fields/reffld.cxx index 9f43ae6b0bca..7c47846fc5ff 100644 --- a/sw/source/core/fields/reffld.cxx +++ b/sw/source/core/fields/reffld.cxx @@ -350,15 +350,12 @@ static void lcl_formatReferenceLanguage( OUString& rRefText, /// get references SwGetRefField::SwGetRefField( SwGetRefFieldType* pFieldType, OUString aSetRef, OUString aSetReferenceLanguage, sal_uInt16 nSubTyp, - sal_uInt16 nSequenceNo, sal_uLong nFormat, SwTextNode* pTextNode, - SwFrame* pFrame ) + sal_uInt16 nSequenceNo, sal_uLong nFormat ) : SwField(pFieldType, nFormat), m_sSetRefName(std::move(aSetRef)), m_sSetReferenceLanguage(std::move(aSetReferenceLanguage)), m_nSubType(nSubTyp), - m_nSeqNo(nSequenceNo), - m_pTextNode(pTextNode), - m_pFrame(pFrame) + m_nSeqNo(nSequenceNo) { } @@ -366,12 +363,6 @@ SwGetRefField::~SwGetRefField() { } -void SwGetRefField::ChangeExpansion(SwFrame* pFrame, const SwTextField* pField) -{ - m_pFrame = pFrame; - m_pTextNode = pField->GetpTextNode(); -} - void SwGetRefField::SetText(OUString sText, SwRootFrame* pLayout) { if (pLayout->IsHideRedlines()) @@ -412,14 +403,14 @@ bool SwGetRefField::IsRefToNumItemCrossRefBookmark() const ::sw::mark::CrossRefNumItemBookmark::IsLegalName(m_sSetRefName); } -const SwTextNode* SwGetRefField::GetReferencedTextNode(SwTextNode* pTextNode) const +const SwTextNode* SwGetRefField::GetReferencedTextNode(SwTextNode* pTextNode, SwFrame* pFrame) const { SwGetRefFieldType *pTyp = dynamic_cast<SwGetRefFieldType*>(GetTyp()); if (!pTyp) return nullptr; sal_Int32 nDummy = -1; return SwGetRefFieldType::FindAnchor( &pTyp->GetDoc(), m_sSetRefName, m_nSubType, m_nSeqNo, &nDummy, - nullptr, nullptr, pTextNode ? pTextNode : m_pTextNode, m_pFrame ); + nullptr, nullptr, pTextNode, pFrame ); } // strikethrough for tooltips using Unicode combining character @@ -436,15 +427,9 @@ static OUString lcl_formatStringByCombiningCharacter(std::u16string_view sText, // #i85090# OUString SwGetRefField::GetExpandedTextOfReferencedTextNode( - SwRootFrame const& rLayout) const -{ - return GetExpandedTextOfReferencedTextNode(rLayout, m_pTextNode); -} - -OUString SwGetRefField::GetExpandedTextOfReferencedTextNode( - SwRootFrame const& rLayout, SwTextNode* pTextNode) const + SwRootFrame const& rLayout, SwTextNode* pTextNode, SwFrame* pFrame) const { - const SwTextNode* pReferencedTextNode( GetReferencedTextNode(pTextNode) ); + const SwTextNode* pReferencedTextNode( GetReferencedTextNode(pTextNode, pFrame) ); if ( !pReferencedTextNode ) return OUString(); @@ -512,7 +497,7 @@ static void FilterText(OUString & rText, LanguageType const eLang, } // #i81002# - parameter <pFieldTextAttr> added -void SwGetRefField::UpdateField( const SwTextField* pFieldTextAttr ) +void SwGetRefField::UpdateField( const SwTextField* pFieldTextAttr, SwFrame* pFrame ) { SwDoc& rDoc = static_cast<SwGetRefFieldType*>(GetTyp())->GetDoc(); @@ -520,17 +505,17 @@ void SwGetRefField::UpdateField( const SwTextField* pFieldTextAttr ) { if (pLay->IsHideRedlines()) { - UpdateField(pFieldTextAttr, pLay, m_sTextRLHidden); + UpdateField(pFieldTextAttr, pFrame, pLay, m_sTextRLHidden); } else { - UpdateField(pFieldTextAttr, pLay, m_sText); + UpdateField(pFieldTextAttr, pFrame, pLay, m_sText); } } } -void SwGetRefField::UpdateField(const SwTextField* pFieldTextAttr, const SwRootFrame* const pLayout, - OUString& rText) +void SwGetRefField::UpdateField(const SwTextField* pFieldTextAttr, SwFrame* pFrameContainingField, + const SwRootFrame* const pLayout, OUString& rText) { SwDoc& rDoc = static_cast<SwGetRefFieldType*>(GetTyp())->GetDoc(); @@ -541,7 +526,7 @@ void SwGetRefField::UpdateField(const SwTextField* pFieldTextAttr, const SwRootF sal_Int32 nNumEnd = -1; SwTextNode* pTextNd = SwGetRefFieldType::FindAnchor( &rDoc, m_sSetRefName, m_nSubType, m_nSeqNo, &nNumStart, &nNumEnd, - pLayout, pFieldTextAttr ? &pFieldTextAttr->GetTextNode() : m_pTextNode, m_pFrame + pLayout, pFieldTextAttr ? pFieldTextAttr->GetpTextNode() : nullptr, pFrameContainingField ); // not found? if ( !pTextNd ) @@ -896,7 +881,7 @@ std::unique_ptr<SwField> SwGetRefField::Copy() const { std::unique_ptr<SwGetRefField> pField( new SwGetRefField( static_cast<SwGetRefFieldType*>(GetTyp()), m_sSetRefName, m_sSetReferenceLanguage, m_nSubType, - m_nSeqNo, GetFormat(), m_pTextNode, m_pFrame ) ); + m_nSeqNo, GetFormat() ) ); pField->m_sText = m_sText; pField->m_sTextRLHidden = m_sTextRLHidden; return std::unique_ptr<SwField>(pField.release()); @@ -1138,7 +1123,7 @@ void SwGetRefFieldType::UpdateGetReferences() } // #i81002# - pGRef->UpdateField(pFormatField->GetTextField()); + pGRef->UpdateField(pFormatField->GetTextField(), nullptr); } CallSwClientNotify(sw::LegacyModifyHint(nullptr, nullptr)); } @@ -1189,24 +1174,25 @@ bool IsMarkHintHidden(SwRootFrame const& rLayout, } // namespace sw -enum StyleRefElementType -{ - Default, - Reference, /* e.g. footnotes, endnotes */ - Marginal, /* headers, footers */ -}; - namespace { + enum StyleRefElementType + { + Default, + Reference, /* e.g. footnotes, endnotes */ + Marginal, /* headers, footers */ + }; + /// Picks the first text node with a matching style from a double ended queue, starting at the front /// This allows us to use the deque either as a stack or as a queue depending on whether we want to search up or down - SwTextNode* SearchForStyleAnchor(SwTextNode* pSelf, std::deque<SwNode*> pToSearch, - const OUString& rStyleName, bool bCaseSensitive = true) + SwTextNode* SearchForStyleAnchor(SwTextNode* pSelf, const std::deque<SwNode*>& pToSearch, + std::u16string_view rStyleName, bool bCaseSensitive = true) { - while (!pToSearch.empty()) + std::deque<SwNode*> pSearching(pToSearch); + while (!pSearching.empty()) { - SwNode* pCurrent = pToSearch.front(); - pToSearch.pop_front(); + SwNode* pCurrent = pSearching.front(); + pSearching.pop_front(); if (*pCurrent == *pSelf) continue; @@ -1350,8 +1336,7 @@ SwTextNode* SwGetRefFieldType::FindAnchor(SwDoc* pDoc, const OUString& rRefMark, } break; case REF_STYLE: - if (!pSelf) - break; + if (!pSelf) break; const SwNodes& nodes = pDoc->GetNodes(); @@ -1404,7 +1389,7 @@ SwTextNode* SwGetRefFieldType::FindAnchor(SwDoc* pDoc, const OUString& rRefMark, Point aPt; std::pair<Point, bool> const tmp(aPt, false); - if (!pContentFrame) SAL_WARN("<SwGetRefFieldType::FindAnchor(..)>", "Missing content frame for marginal styleref"); + if (!pContentFrame) break; const SwPageFrame* pPageFrame = nullptr; if (pContentFrame) diff --git a/sw/source/core/text/txtfld.cxx b/sw/source/core/text/txtfld.cxx index aa9cb97ffbad..0c4a9bb86449 100644 --- a/sw/source/core/text/txtfld.cxx +++ b/sw/source/core/text/txtfld.cxx @@ -248,13 +248,8 @@ SwExpandPortion *SwTextFormatter::NewFieldPortion( SwTextFormatInfo &rInf, subType = static_cast<SwGetRefField*>(pField)->GetSubType(); if (!bName && subType == REF_STYLE) { - SwTextNode* pTextNode = pHint->GetFormatField().GetTextField()->GetpTextNode(); - - if (pTextNode) - static_cast<SwGetRefField*>(pField)->ChangeExpansion( - pFrame, static_txtattr_cast<SwTextField const*>(pHint)); static_cast<SwGetRefField*>(pField)->UpdateField( - static_txtattr_cast<SwTextField const*>(pHint)); + static_txtattr_cast<SwTextField const*>(pHint), pFrame); } { diff --git a/sw/source/core/txtnode/atrfld.cxx b/sw/source/core/txtnode/atrfld.cxx index 74bf184b487f..3ffd992ae51e 100644 --- a/sw/source/core/txtnode/atrfld.cxx +++ b/sw/source/core/txtnode/atrfld.cxx @@ -338,7 +338,7 @@ void SwFormatField::UpdateTextNode(const SfxPoolItem* pOld, const SfxPoolItem* p if( SwFieldIds::GetRef == mpField->GetTyp()->Which() ) { // #i81002# - static_cast<SwGetRefField*>(mpField.get())->UpdateField( mpTextField ); + static_cast<SwGetRefField*>(mpField.get())->UpdateField( mpTextField, nullptr ); } break; case RES_DOCPOS_UPDATE: diff --git a/sw/source/core/unocore/unofield.cxx b/sw/source/core/unocore/unofield.cxx index 76d8a74939f0..f1818c3c088f 100644 --- a/sw/source/core/unocore/unofield.cxx +++ b/sw/source/core/unocore/unofield.cxx @@ -1529,8 +1529,6 @@ void SAL_CALL SwXTextField::attach( m_pImpl->m_pProps->sPar4, 0, 0, - 0, - 0, 0)); if (!m_pImpl->m_pProps->sPar3.isEmpty()) static_cast<SwGetRefField*>(xField.get())->SetExpand(m_pImpl->m_pProps->sPar3); diff --git a/sw/source/filter/ww8/ww8par5.cxx b/sw/source/filter/ww8/ww8par5.cxx index e6dcca3f2cae..fbea8790ad96 100644 --- a/sw/source/filter/ww8/ww8par5.cxx +++ b/sw/source/filter/ww8/ww8par5.cxx @@ -2157,7 +2157,7 @@ eF_ResT SwWW8ImplReader::Read_F_Ref( WW8FieldDesc*, OUString& rStr ) SwGetRefField aField( static_cast<SwGetRefFieldType*>(m_rDoc.getIDocumentFieldsAccess().GetSysFieldType( SwFieldIds::GetRef )), - sBkmName,"",REF_BOOKMARK,0,eFormat,nullptr,nullptr); + sBkmName,"",REF_BOOKMARK,0,eFormat); if (eFormat == REF_CONTENT) { @@ -2213,14 +2213,14 @@ eF_ResT SwWW8ImplReader::Read_F_NoteReference( WW8FieldDesc*, OUString& rStr ) // (will be corrected in SwGetRefField aField( static_cast<SwGetRefFieldType*>( m_rDoc.getIDocumentFieldsAccess().GetSysFieldType( SwFieldIds::GetRef )), aBkmName, "", REF_FOOTNOTE, 0, - REF_ONLYNUMBER, nullptr, nullptr ); + REF_ONLYNUMBER ); m_xReffingStck->NewAttr(*m_pPaM->GetPoint(), SwFormatField(aField)); m_xReffingStck->SetAttr(*m_pPaM->GetPoint(), RES_TXTATR_FIELD); if (bAboveBelow) { SwGetRefField aField2( static_cast<SwGetRefFieldType*>( m_rDoc.getIDocumentFieldsAccess().GetSysFieldType( SwFieldIds::GetRef )),aBkmName, "", REF_FOOTNOTE, 0, - REF_UPDOWN, nullptr, nullptr ); + REF_UPDOWN ); m_xReffingStck->NewAttr(*m_pPaM->GetPoint(), SwFormatField(aField2)); m_xReffingStck->SetAttr(*m_pPaM->GetPoint(), RES_TXTATR_FIELD); } @@ -2292,7 +2292,7 @@ eF_ResT SwWW8ImplReader::Read_F_PgRef( WW8FieldDesc*, OUString& rStr ) sPageRefBookmarkName = sName; } SwGetRefField aField( static_cast<SwGetRefFieldType*>(m_rDoc.getIDocumentFieldsAccess().GetSysFieldType( SwFieldIds::GetRef )), - sPageRefBookmarkName, "", REF_BOOKMARK, 0, REF_PAGE, nullptr, nullptr ); + sPageRefBookmarkName, "", REF_BOOKMARK, 0, REF_PAGE ); m_rDoc.getIDocumentContentOperations().InsertPoolItem( *m_pPaM, SwFormatField( aField ) ); return eF_ResT::OK; diff --git a/sw/source/ui/fldui/fldref.cxx b/sw/source/ui/fldui/fldref.cxx index 213143ef8bb6..7d8fda5145af 100644 --- a/sw/source/ui/fldui/fldref.cxx +++ b/sw/source/ui/fldui/fldref.cxx @@ -628,7 +628,7 @@ void SwFieldRefPage::UpdateSubType(const OUString& filterString) m_xSelectionToolTipLB->append(sId, pIDoc->getOutlineText(nOutlIdx, pSh->GetLayout(), true, true, false)); if ((IsFieldEdit() && pRefField - && pRefField->GetReferencedTextNode(nullptr) == maOutlineNodes[nOutlIdx]) + && pRefField->GetReferencedTextNode(nullptr, nullptr) == maOutlineNodes[nOutlIdx]) || mpSavedSelectedTextNode == maOutlineNodes[nOutlIdx]) { m_sSelectionToolTipLBId = sId; @@ -663,7 +663,7 @@ void SwFieldRefPage::UpdateSubType(const OUString& filterString) m_xSelectionToolTipLB->append(sId, pIDoc->getListItemText(*maNumItems[nNumItemIdx], *pSh->GetLayout())); if ((IsFieldEdit() && pRefField - && pRefField->GetReferencedTextNode(nullptr) == maNumItems[nNumItemIdx]->GetTextNode()) + && pRefField->GetReferencedTextNode(nullptr, nullptr) == maNumItems[nNumItemIdx]->GetTextNode()) || mpSavedSelectedTextNode == maNumItems[nNumItemIdx]->GetTextNode()) { m_sSelectionToolTipLBId = sId; @@ -1136,7 +1136,7 @@ bool SwFieldRefPage::FillItemSet(SfxItemSet* ) nTypeId = static_cast<sal_uInt16>(SwFieldTypesEnum::GetRef); nSubType = REF_STYLE; } else { - SAL_WARN("<SwFieldRefPage::FillItemSet(..)>", "no entry selected in selection listbox!"); + SAL_WARN("sw.ui", "<SwFieldRefPage::FillItemSet(..)> no entry selected in selection listbox!"); } } else // SequenceFields diff --git a/sw/source/uibase/docvw/edtwin2.cxx b/sw/source/uibase/docvw/edtwin2.cxx index 627bd054d586..73e4f8dbb237 100644 --- a/sw/source/uibase/docvw/edtwin2.cxx +++ b/sw/source/uibase/docvw/edtwin2.cxx @@ -357,7 +357,7 @@ void SwEditWin::RequestHelp(const HelpEvent &rEvt) if ( pRefField->IsRefToHeadingCrossRefBookmark() || pRefField->IsRefToNumItemCrossRefBookmark() ) { - sText = pRefField->GetExpandedTextOfReferencedTextNode(*rSh.GetLayout(), nullptr); + sText = pRefField->GetExpandedTextOfReferencedTextNode(*rSh.GetLayout(), nullptr, nullptr); if ( sText.getLength() > 80 ) { sText = OUString::Concat(sText.subView(0, 80)) + "..."; diff --git a/sw/source/uibase/fldui/fldmgr.cxx b/sw/source/uibase/fldui/fldmgr.cxx index cd9f99aa2ad7..c36e50a1454c 100644 --- a/sw/source/uibase/fldui/fldmgr.cxx +++ b/sw/source/uibase/fldui/fldmgr.cxx @@ -1132,18 +1132,7 @@ bool SwFieldMgr::InsertField( nFormatId %= SAL_N_ELEMENTS(FMT_REF_ARY); } - SwPaM* pCursor = nullptr; - SwPosition* pPos = nullptr; - SwTextNode* pTextNode = nullptr; - SwContentFrame* pFrame = nullptr; - if (nSubType == REF_STYLE) { - pCursor = pCurShell->GetCursor(); - pPos = pCursor->GetPoint(); - pTextNode = pPos->GetNode().GetTextNode(); - pFrame = pCurShell->GetCurrFrame(); - } - - pField.reset(new SwGetRefField(pTyp, rData.m_sPar1, sReferenceLanguage, nSubType, nSeqNo, nFormatId, pTextNode, pFrame)); + pField.reset(new SwGetRefField(pTyp, rData.m_sPar1, sReferenceLanguage, nSubType, nSeqNo, nFormatId)); bExp = true; break; } diff --git a/sw/source/uibase/utlui/content.cxx b/sw/source/uibase/utlui/content.cxx index 504d17e79ea4..05d3aaa22fec 100644 --- a/sw/source/uibase/utlui/content.cxx +++ b/sw/source/uibase/utlui/content.cxx @@ -704,7 +704,7 @@ void SwContentType::FillMemberList(bool* pbContentChanged) { OUString sExpandedTextOfReferencedTextNode = pRefField->GetExpandedTextOfReferencedTextNode( - *m_pWrtShell->GetLayout(), nullptr); + *m_pWrtShell->GetLayout(), nullptr, nullptr); if (sExpandedTextOfReferencedTextNode.getLength() > 80) { sExpandedTextOfReferencedTextNode = OUString::Concat( diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 46caa8f5791d..144c1fa0fc83 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -7414,7 +7414,7 @@ void DomainMapper_Impl::CloseFieldCommand() } catch (css::container::NoSuchElementException) { - aStyleDisplayName = uno::Any(sStyleSheetName); + aStyleDisplayName <<= sStyleSheetName; } xFieldProperties->setPropertyValue( diff --git a/xmloff/source/text/txtfldi.cxx b/xmloff/source/text/txtfldi.cxx index d51d1fb06316..63ac9c1511fc 100644 --- a/xmloff/source/text/txtfldi.cxx +++ b/xmloff/source/text/txtfldi.cxx @@ -407,7 +407,7 @@ XMLTextFieldImportContext::CreateTextFieldImportContext( case XML_ELEMENT(TEXT, XML_BOOKMARK_REF): case XML_ELEMENT(TEXT, XML_NOTE_REF): case XML_ELEMENT(TEXT, XML_SEQUENCE_REF): - case XML_ELEMENT(TEXT, XML_STYLE_REF): + case XML_ELEMENT(LO_EXT, XML_STYLE_REF): pContext = new XMLReferenceFieldImportContext( rImport, rHlp, nToken ); break; @@ -2510,7 +2510,7 @@ void XMLReferenceFieldImportContext::startFastElement( case XML_ELEMENT(TEXT, XML_SEQUENCE_REF): nSource = ReferenceFieldSource::SEQUENCE_FIELD; break; - case XML_ELEMENT(TEXT, XML_STYLE_REF): + case XML_ELEMENT(LO_EXT, XML_STYLE_REF): nSource = ReferenceFieldSource::STYLE; break; default: |