diff --git a/sw/inc/unoparagraph.hxx b/sw/inc/unoparagraph.hxx index 82540afdc58b..ab1bb903a7cd 100644 --- a/sw/inc/unoparagraph.hxx +++ b/sw/inc/unoparagraph.hxx @@ -45,6 +45,7 @@ class SwStartNode; class SwTextNode; class SwTableBox; class SwXText; +class SwXTextPortionEnumeration; typedef ::cppu::ImplInheritanceHelper < ::sfx2::MetadatableMixin @@ -206,6 +207,8 @@ public: virtual OUString SAL_CALL getString() override; virtual void SAL_CALL setString(const OUString& rString) override; + /// tries to return less data, but may return more than just text fields + rtl::Reference createTextFieldsEnumeration(); }; diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx index 9ea61b6e5462..4d7f80d6d3d1 100644 --- a/sw/source/core/edit/edfcol.cxx +++ b/sw/source/core/edit/edfcol.cxx @@ -96,6 +96,7 @@ #include #include #include +#include #include #include @@ -542,17 +543,16 @@ bool lcl_IsParagraphClassificationField(const uno::Reference& xMo } uno::Reference lcl_FindParagraphClassificationField(const uno::Reference& xModel, - const uno::Reference& xParagraph, + const rtl::Reference& xParagraph, std::u16string_view sKey = u"") { uno::Reference xTextField; - uno::Reference xTextPortionEnumerationAccess(xParagraph, uno::UNO_QUERY); - if (!xTextPortionEnumerationAccess.is()) + if (!xParagraph.is()) return xTextField; // Enumerate text portions to find metadata fields. This is expensive, best to enumerate fields only. - uno::Reference xTextPortions = xTextPortionEnumerationAccess->createEnumeration(); + rtl::Reference xTextPortions = xParagraph->createTextFieldsEnumeration(); while (xTextPortions->hasMoreElements()) { uno::Reference xTextPortion(xTextPortions->nextElement(), uno::UNO_QUERY); @@ -1159,7 +1159,7 @@ void SwEditShell::SetClassification(const OUString& rName, SfxClassificationPoli // on a performance-sensitive path. static void lcl_ApplyParagraphClassification(SwDoc* pDoc, const uno::Reference& xModel, - const uno::Reference& xParent, + const rtl::Reference& xParent, const css::uno::Reference& xNodeSubject, std::vector aResults) { @@ -1932,11 +1932,12 @@ void SwEditShell::RestoreMetadataFieldsAndValidateParagraphSignatures() while (xParagraphs->hasMoreElements()) { - uno::Reference xParagraph(xParagraphs->nextElement(), uno::UNO_QUERY); + uno::Reference xParaOrTable(xParagraphs->nextElement(), uno::UNO_QUERY); + rtl::Reference xParagraph(dynamic_cast(xParaOrTable.get())); try { - const css::uno::Reference xSubject(xParagraph, uno::UNO_QUERY); + const css::uno::Reference xSubject(xParagraph); const std::map aStatements = SwRDFHelper::getStatements(xModel, aGraphNames, xSubject); const auto it = aStatements.find(ParagraphClassificationFieldNamesRDFName); @@ -1991,7 +1992,7 @@ void SwEditShell::RestoreMetadataFieldsAndValidateParagraphSignatures() // Get Signatures std::map aSignatures; - for (const auto& pair : lcl_getRDFStatements(xModel, xParagraph)) + for (const auto& pair : lcl_getRDFStatements(xModel, uno::Reference(xParagraph))) { const OUString& sName = pair.first; if (sName.startsWith(ParagraphSignatureRDFNamespace)) @@ -2080,7 +2081,7 @@ bool SwEditShell::RemoveParagraphMetadataFieldAtCursor() } static OUString lcl_GetParagraphClassification(SfxClassificationHelper & rHelper, sfx::ClassificationKeyCreator const & rKeyCreator, - const uno::Reference& xModel, const uno::Reference& xParagraph) + const uno::Reference& xModel, const rtl::Reference& xParagraph) { uno::Reference xTextField; xTextField = lcl_FindParagraphClassificationField(xModel, xParagraph, rKeyCreator.makeCategoryIdentifierKey()); @@ -2121,7 +2122,8 @@ static OUString lcl_GetHighestClassificationParagraphClass(SwPaM* pCursor) rtl::Reference xParagraphs = xBodyText->createParagraphEnumeration(); while (xParagraphs->hasMoreElements()) { - uno::Reference xParagraph(xParagraphs->nextElement(), uno::UNO_QUERY); + uno::Reference xParaOrTable(xParagraphs->nextElement(), uno::UNO_QUERY); + rtl::Reference xParagraph(dynamic_cast(xParaOrTable.get())); const OUString sCurrentClass = lcl_GetParagraphClassification(aHelper, aKeyCreator, xModel, xParagraph); sHighestClass = aHelper.GetHigherClass(sHighestClass, sCurrentClass); } diff --git a/sw/source/core/inc/unoport.hxx b/sw/source/core/inc/unoport.hxx index 936bc01e0521..da718a05032b 100644 --- a/sw/source/core/inc/unoport.hxx +++ b/sw/source/core/inc/unoport.hxx @@ -257,9 +257,10 @@ class SwXTextPortionEnumeration final virtual ~SwXTextPortionEnumeration() override; public: + /// @param bOnlyTextFields tries to return less data, but may return more than just text fields SwXTextPortionEnumeration(SwPaM& rParaCursor, css::uno::Reference< css::text::XText > const & xParent, - const sal_Int32 nStart, const sal_Int32 nEnd ); + const sal_Int32 nStart, const sal_Int32 nEnd, bool bOnlyTextFields = false ); SwXTextPortionEnumeration(SwPaM& rParaCursor, TextRangeList_t && rPortions ); diff --git a/sw/source/core/unocore/unoparagraph.cxx b/sw/source/core/unocore/unoparagraph.cxx index 1bd8949d58b5..c2788895d19b 100644 --- a/sw/source/core/unocore/unoparagraph.cxx +++ b/sw/source/core/unocore/unoparagraph.cxx @@ -1265,6 +1265,20 @@ SwXParagraph::createEnumeration() return xRef; } + /// tries to return less data, but may return more than just text fields +rtl::Reference< SwXTextPortionEnumeration > +SwXParagraph::createTextFieldsEnumeration() +{ + SolarMutexGuard aGuard; + + SwTextNode & rTextNode(m_pImpl->GetTextNodeOrThrow()); + SwPosition aPos( rTextNode ); + SwPaM aPam ( aPos ); + + return new SwXTextPortionEnumeration(aPam, m_pImpl->m_xParentText, + m_pImpl->m_nSelectionStartPos, m_pImpl->m_nSelectionEndPos, /*bOnlyTextFields*/true); +} + uno::Type SAL_CALL SwXParagraph::getElementType() { return cppu::UnoType::get(); diff --git a/sw/source/core/unocore/unoportenum.cxx b/sw/source/core/unocore/unoportenum.cxx index a786340b4e4b..e6fcb06cb8de 100644 --- a/sw/source/core/unocore/unoportenum.cxx +++ b/sw/source/core/unocore/unoportenum.cxx @@ -78,7 +78,7 @@ static void lcl_CreatePortions( uno::Reference< text::XText > const& i_xParentText, SwUnoCursor* pUnoCursor, FrameClientSortList_t & i_rFrames, - const sal_Int32 i_nStartPos, const sal_Int32 i_nEndPos ); + const sal_Int32 i_nStartPos, const sal_Int32 i_nEndPos, bool bOnlyTextFields ); namespace { @@ -312,7 +312,8 @@ SwXTextPortionEnumeration::SwXTextPortionEnumeration( SwPaM& rParaCursor, uno::Reference< XText > const & xParentText, const sal_Int32 nStart, - const sal_Int32 nEnd ) + const sal_Int32 nEnd, + bool bOnlyTextFields) { m_pUnoCursor = rParaCursor.GetDoc().CreateUnoCursor(*rParaCursor.GetPoint()); @@ -323,7 +324,7 @@ SwXTextPortionEnumeration::SwXTextPortionEnumeration( // find all frames, graphics and OLEs that are bound AT character in para FrameClientSortList_t frames; ::CollectFrameAtNode(m_pUnoCursor->GetPoint()->nNode, frames, true); - lcl_CreatePortions(m_Portions, xParentText, &*m_pUnoCursor, frames, nStart, nEnd); + lcl_CreatePortions(m_Portions, xParentText, &*m_pUnoCursor, frames, nStart, nEnd, bOnlyTextFields); } SwXTextPortionEnumeration::SwXTextPortionEnumeration( @@ -1341,7 +1342,8 @@ static void lcl_CreatePortions( SwUnoCursor * const pUnoCursor, FrameClientSortList_t & i_rFrames, const sal_Int32 i_nStartPos, - const sal_Int32 i_nEndPos ) + const sal_Int32 i_nEndPos, + bool bOnlyTextFields ) { if (!pUnoCursor) return; @@ -1361,19 +1363,24 @@ static void lcl_CreatePortions( SwDoc& rDoc = pUnoCursor->GetDoc(); std::deque FieldMarks; - lcl_FillFieldMarkArray(FieldMarks, *pUnoCursor, i_nStartPos); + if (!bOnlyTextFields) + lcl_FillFieldMarkArray(FieldMarks, *pUnoCursor, i_nStartPos); SwXBookmarkPortion_ImplList Bookmarks; - lcl_FillBookmarkArray(rDoc, *pUnoCursor, Bookmarks); + if (!bOnlyTextFields) + lcl_FillBookmarkArray(rDoc, *pUnoCursor, Bookmarks); SwXRedlinePortion_ImplList Redlines; - lcl_FillRedlineArray(rDoc, *pUnoCursor, Redlines); + if (!bOnlyTextFields) + lcl_FillRedlineArray(rDoc, *pUnoCursor, Redlines); SwSoftPageBreakList SoftPageBreaks; - lcl_FillSoftPageBreakArray(*pUnoCursor, SoftPageBreaks); + if (!bOnlyTextFields) + lcl_FillSoftPageBreakArray(*pUnoCursor, SoftPageBreaks); SwAnnotationStartPortion_ImplList AnnotationStarts; - lcl_FillAnnotationStartArray( rDoc, *pUnoCursor, AnnotationStarts ); + if (!bOnlyTextFields) + lcl_FillAnnotationStartArray( rDoc, *pUnoCursor, AnnotationStarts ); PortionStack_t PortionStack; PortionStack.push( PortionList_t(&i_rPortions, nullptr) );