sw/source/core/edit/edfcol.cxx | 19 - sw/source/ui/vba/vbaautotextentry.cxx | 5 sw/source/ui/vba/vbaselection.cxx | 11 - sw/source/writerfilter/dmapper/DomainMapperTableHandler.cxx | 8 sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx | 131 ++++++------ sw/source/writerfilter/dmapper/DomainMapper_Impl.hxx | 7 sw/source/writerfilter/dmapper/PropertyMap.cxx | 95 ++++---- sw/source/writerfilter/dmapper/PropertyMap.hxx | 5 8 files changed, 150 insertions(+), 131 deletions(-)
New commits: commit 29b10216ce0b369496df480f5fbd64b9c2cc42d1 Author: Noel Grandin <[email protected]> AuthorDate: Fri Feb 6 12:58:56 2026 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Sat Feb 7 12:37:01 2026 +0100 use more concrete SwXTextCursor class the only thing that implements XParagraphCursor is SwXTextCursor, so wherever we see that, we can instead use the concrete class Change-Id: Idfe0fed936efa7a7c61c5165b3dd4a5d08e5f937 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198827 Reviewed-by: Noel Grandin <[email protected]> Tested-by: Jenkins diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx index 656fe088565b..de36a621dd8f 100644 --- a/sw/source/core/edit/edfcol.cxx +++ b/sw/source/core/edit/edfcol.cxx @@ -99,6 +99,7 @@ #include <unotextbodyhf.hxx> #include <unoport.hxx> #include <unofield.hxx> +#include <unotextcursor.hxx> #include <comphelper/diagnose_ex.hxx> #include <IDocumentRedlineAccess.hxx> @@ -708,14 +709,14 @@ SwTextFormatColl& SwEditShell::GetTextFormatColl(sal_uInt16 nFormatColl) const return *((*(GetDoc()->GetTextFormatColls()))[nFormatColl]); } -static void insertFieldToDocument(uno::Reference<text::XText> const & rxText, uno::Reference<text::XParagraphCursor> const & rxParagraphCursor, +static void insertFieldToDocument(uno::Reference<text::XText> const & rxText, rtl::Reference<SwXTextCursor> const & rxParagraphCursor, OUString const & rsKey) { rtl::Reference<SwXTextField> xField = SwXTextField::CreateXTextField(nullptr, nullptr, SwServiceType::FieldTypeDocInfoCustom); xField->setPropertyValue(UNO_NAME_NAME, uno::Any(rsKey)); uno::Reference<text::XTextContent> xTextContent(xField); - rxText->insertTextContent(rxParagraphCursor, xTextContent, false); + rxText->insertTextContent(static_cast<text::XSentenceCursor*>(rxParagraphCursor.get()), xTextContent, false); } static void removeAllClassificationFields(std::u16string_view rPolicy, uno::Reference<text::XText> const & rxText) @@ -871,8 +872,8 @@ void SwEditShell::ApplyAdvancedClassification(std::vector<svx::ClassificationRes aWatermarkItem.SetText(aHelper.GetDocumentWatermark()); SetWatermark(aWatermarkItem); - uno::Reference<text::XParagraphCursor> xHeaderParagraphCursor(xHeaderText->createTextCursor(), uno::UNO_QUERY); - uno::Reference<text::XParagraphCursor> xFooterParagraphCursor(xFooterText->createTextCursor(), uno::UNO_QUERY); + rtl::Reference<SwXTextCursor> xHeaderParagraphCursor = dynamic_cast<SwXTextCursor*>(xHeaderText->createTextCursor().get()); + rtl::Reference<SwXTextCursor> xFooterParagraphCursor = dynamic_cast<SwXTextCursor*>(xFooterText->createTextCursor().get()); sal_Int32 nParagraph = -1; @@ -929,17 +930,15 @@ void SwEditShell::ApplyAdvancedClassification(std::vector<svx::ClassificationRes xHeaderParagraphCursor->gotoStartOfParagraph(false); xFooterParagraphCursor->gotoStartOfParagraph(false); - uno::Reference<beans::XPropertySet> xHeaderPropertySet(xHeaderParagraphCursor, uno::UNO_QUERY_THROW); - uno::Reference<beans::XPropertySet> xFooterPropertySet(xFooterParagraphCursor, uno::UNO_QUERY_THROW); if (rResult.msName == "BOLD") { - xHeaderPropertySet->setPropertyValue(u"CharWeight"_ustr, uno::Any(awt::FontWeight::BOLD)); - xFooterPropertySet->setPropertyValue(u"CharWeight"_ustr, uno::Any(awt::FontWeight::BOLD)); + xHeaderParagraphCursor->setPropertyValue(u"CharWeight"_ustr, uno::Any(awt::FontWeight::BOLD)); + xFooterParagraphCursor->setPropertyValue(u"CharWeight"_ustr, uno::Any(awt::FontWeight::BOLD)); } else { - xHeaderPropertySet->setPropertyValue(u"CharWeight"_ustr, uno::Any(awt::FontWeight::NORMAL)); - xFooterPropertySet->setPropertyValue(u"CharWeight"_ustr, uno::Any(awt::FontWeight::NORMAL)); + xHeaderParagraphCursor->setPropertyValue(u"CharWeight"_ustr, uno::Any(awt::FontWeight::NORMAL)); + xFooterParagraphCursor->setPropertyValue(u"CharWeight"_ustr, uno::Any(awt::FontWeight::NORMAL)); } } break; diff --git a/sw/source/ui/vba/vbaautotextentry.cxx b/sw/source/ui/vba/vbaautotextentry.cxx index fcfff74a36b0..27d34080ba2f 100644 --- a/sw/source/ui/vba/vbaautotextentry.cxx +++ b/sw/source/ui/vba/vbaautotextentry.cxx @@ -23,6 +23,7 @@ #include "wordvbahelper.hxx" #include "vbarange.hxx" #include <unotxdoc.hxx> +#include <unotextcursor.hxx> using namespace ::ooo::vba; using namespace ::ooo::vba::word; @@ -57,7 +58,9 @@ uno::Reference< word::XRange > SAL_CALL SwVbaAutoTextEntry::Insert( const uno::R if( bRich ) { // check if it is a blank paragraph - uno::Reference< text::XParagraphCursor > xParaCursor( xTC, uno::UNO_QUERY_THROW ); + rtl::Reference< SwXTextCursor > xParaCursor = dynamic_cast<SwXTextCursor*>( xTC.get() ); + if (!xParaCursor) + throw uno::RuntimeException(); if( xParaCursor->isStartOfParagraph() && xParaCursor->isEndOfParagraph() ) { //remove the blank paragraph diff --git a/sw/source/ui/vba/vbaselection.cxx b/sw/source/ui/vba/vbaselection.cxx index bf3f82b120b2..88d2d6a47b76 100644 --- a/sw/source/ui/vba/vbaselection.cxx +++ b/sw/source/ui/vba/vbaselection.cxx @@ -66,6 +66,7 @@ #include <unotxdoc.hxx> #include <unodraw.hxx> #include <unobasestyle.hxx> +#include <unotextcursor.hxx> using namespace ::ooo::vba; using namespace ::com::sun::star; @@ -316,7 +317,9 @@ SwVbaSelection::Move( const uno::Any& _unit, const uno::Any& _count, const uno:: { throw uno::RuntimeException(u"Not implemented"_ustr ); } - uno::Reference< text::XParagraphCursor > xParagraphCursor( xTextCursor, uno::UNO_QUERY_THROW ); + rtl::Reference< SwXTextCursor > xParagraphCursor = dynamic_cast<SwXTextCursor*>( xTextCursor.get() ); + if (!xParagraphCursor) + throw uno::RuntimeException(); for( sal_Int32 i=0; i<nCount; i++ ) { if( ( eDirection == word::MOVE_UP ) && !xParagraphCursor->gotoPreviousParagraph( bExpand ) ) @@ -1141,11 +1144,13 @@ SwVbaSelection::Paragraphs( const uno::Any& aIndex ) uno::Reference< text::XTextRange > xTextRange = mxTextViewCursor->getStart(); uno::Reference< text::XText > xText = xTextRange->getText(); - uno::Reference< text::XParagraphCursor > xParaCursor( xText->createTextCursor(), uno::UNO_QUERY_THROW ); + rtl::Reference< SwXTextCursor > xParaCursor = dynamic_cast<SwXTextCursor*>( xText->createTextCursor().get() ); + if (!xParaCursor) + throw uno::RuntimeException(); xParaCursor->gotoStartOfParagraph( false ); xParaCursor->gotoStartOfParagraph( true ); - uno::Reference< text::XTextRange > xParaRange( xParaCursor, uno::UNO_QUERY_THROW ); + uno::Reference< text::XTextRange > xParaRange( static_cast<text::XSentenceCursor*>(xParaCursor.get()) ); uno::Reference< word::XParagraph > xParagraph = new SwVbaParagraph( mxParent, mxContext, mxModel, xParaRange ); aRet <<= xParagraph; diff --git a/sw/source/writerfilter/dmapper/DomainMapperTableHandler.cxx b/sw/source/writerfilter/dmapper/DomainMapperTableHandler.cxx index 81a698785006..6438c16ed185 100644 --- a/sw/source/writerfilter/dmapper/DomainMapperTableHandler.cxx +++ b/sw/source/writerfilter/dmapper/DomainMapperTableHandler.cxx @@ -1235,8 +1235,10 @@ void DomainMapperTableHandler::ApplyParagraphPropertiesFromTableStyle(TableParag { if (!oParagraphText) // do it only once { - uno::Reference<text::XParagraphCursor> xParagraph( - rParaProp.m_rEndParagraph->getText()->createTextCursorByRange(rParaProp.m_rEndParagraph), uno::UNO_QUERY_THROW ); + rtl::Reference<SwXTextCursor> xParagraph = dynamic_cast<SwXTextCursor*>( + rParaProp.m_rEndParagraph->getText()->createTextCursorByRange(rParaProp.m_rEndParagraph).get() ); + if (!xParagraph) + throw uno::RuntimeException(); // select paragraph xParagraph->gotoStartOfParagraph( true ); oParagraphText = xParagraph->getString(); @@ -1552,7 +1554,7 @@ void DomainMapperTableHandler::endTable(unsigned int nestedTableLevel) std::vector<TableParagraph>::iterator aIt = pTableParagraphs->begin(); while ( aIt != pTableParagraphs->end() ) try { - if (!bApply && xTextRangeCompare->compareRegionStarts(rStartPara, aIt->m_rStartParagraph) == 0) + if (!bApply && xTextRangeCompare->compareRegionStarts(rStartPara, static_cast<text::XSentenceCursor*>(aIt->m_rStartParagraph.get())) == 0) bApply = true; if (bApply) { diff --git a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx index 3dd66fb798d8..bd46598898c1 100644 --- a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx +++ b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx @@ -607,7 +607,7 @@ void CopyPageDescNameToNextParagraph(const uno::Reference<lang::XComponent>& xPa } // If so, search for the next paragraph. - uno::Reference<text::XParagraphCursor> xParaCursor(xCursor, uno::UNO_QUERY); + rtl::Reference<SwXTextCursor> xParaCursor = dynamic_cast<SwXTextCursor*>(xCursor.get()); if (!xParaCursor.is()) { return; @@ -619,13 +619,7 @@ void CopyPageDescNameToNextParagraph(const uno::Reference<lang::XComponent>& xPa return; } - uno::Reference<container::XEnumerationAccess> xEnumerationAccess(xParaCursor, uno::UNO_QUERY); - if (!xEnumerationAccess.is()) - { - return; - } - - uno::Reference<container::XEnumeration> xEnumeration = xEnumerationAccess->createEnumeration(); + uno::Reference<container::XEnumeration> xEnumeration = xParaCursor->createEnumeration(); if (!xEnumeration.is()) { return; @@ -848,7 +842,7 @@ void DomainMapper_Impl::RemoveLastParagraph( ) xCursor->gotoEnd(false); } else - xCursor.set(m_aTextAppendStack.top().xCursor, uno::UNO_SET_THROW); + xCursor.set(static_cast<text::XSentenceCursor*>(m_aTextAppendStack.top().xCursor.get()), uno::UNO_SET_THROW); // Keep the character properties of the last but one paragraph, even if // it's empty. This works for headers/footers, and maybe in other cases @@ -1103,7 +1097,7 @@ void DomainMapper_Impl::PopSdt() // Go to the start of the end's paragraph. This helps in case // DomainMapper_Impl::AddDummyParaForTableInSection() would make our range multi-paragraph, // while the intention is to keep start/end inside the same paragraph for run SDTs. - uno::Reference<text::XParagraphCursor> xParagraphCursor(xCursor, uno::UNO_QUERY); + rtl::Reference<SwXTextCursor> xParagraphCursor = dynamic_cast<SwXTextCursor*>(xCursor.get()); if (xParagraphCursor.is() && m_pSdtHelper->GetSdtType() == NS_ooxml::LN_CT_SdtRun_sdtContent) { @@ -1852,8 +1846,10 @@ static void lcl_AddRange( uno::Reference< text::XTextAppend > const& xTextAppend, TextAppendContext const & rAppendContext) { - uno::Reference<text::XParagraphCursor> xParaCursor( - xTextAppend->createTextCursorByRange( rAppendContext.xInsertPosition.is() ? rAppendContext.xInsertPosition : xTextAppend->getEnd()), uno::UNO_QUERY_THROW ); + rtl::Reference<SwXTextCursor> xParaCursor = dynamic_cast<SwXTextCursor*>( + xTextAppend->createTextCursorByRange( rAppendContext.xCursor.is() ? static_cast<text::XSentenceCursor*>(rAppendContext.xCursor.get()) : xTextAppend->getEnd()).get() ); + if (!xParaCursor) + throw uno::RuntimeException(); pToBeSavedProperties->SetEndingRange(xParaCursor->getStart()); xParaCursor->gotoStartOfParagraph( false ); @@ -2501,13 +2497,14 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con bool bKeepLastParagraphProperties = false; if( bIsDropCap ) { - uno::Reference<text::XParagraphCursor> xParaCursor( - xTextAppend->createTextCursorByRange(xTextAppend->getEnd()), uno::UNO_QUERY_THROW); + rtl::Reference<SwXTextCursor> xParaCursor = dynamic_cast<SwXTextCursor*> + (xTextAppend->createTextCursorByRange(xTextAppend->getEnd()).get()); + if (!xParaCursor) + throw uno::RuntimeException(); //select paragraph xParaCursor->gotoStartOfParagraph( true ); - uno::Reference< beans::XPropertyState > xParaProperties( xParaCursor, uno::UNO_QUERY_THROW ); - xParaProperties->setPropertyToDefault(getPropertyName(PROP_CHAR_ESCAPEMENT)); - xParaProperties->setPropertyToDefault(getPropertyName(PROP_CHAR_HEIGHT)); + xParaCursor->setPropertyToDefault(getPropertyName(PROP_CHAR_ESCAPEMENT)); + xParaCursor->setPropertyToDefault(getPropertyName(PROP_CHAR_HEIGHT)); //handles (2) and part of (6) pToBeSavedProperties = new ParagraphProperties(pParaContext->props()); sal_Int32 nCount = xParaCursor->getString().getLength(); @@ -2544,8 +2541,8 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con { //handles (7) rAppendContext.pLastParagraphProperties->SetEndingRange( - rAppendContext.xInsertPosition.is() ? rAppendContext.xInsertPosition - : xTextAppend->getEnd()); + rAppendContext.xCursor.is() ? static_cast<text::XSentenceCursor*>(rAppendContext.xCursor.get()) + : xTextAppend->getEnd()); bKeepLastParagraphProperties = true; } else @@ -2706,9 +2703,9 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con aProperties.push_back(aValue); } uno::Reference< text::XTextRange > xTextRange; - if (rAppendContext.xInsertPosition.is()) + if (rAppendContext.xCursor.is()) { - xTextRange = xTextAppend->finishParagraphInsert( comphelper::containerToSequence(aProperties), rAppendContext.xInsertPosition ); + xTextRange = xTextAppend->finishParagraphInsert( comphelper::containerToSequence(aProperties), static_cast<text::XSentenceCursor*>(rAppendContext.xCursor.get()) ); rAppendContext.xCursor->gotoNextParagraph(false); if (rAppendContext.pLastParagraphProperties) rAppendContext.pLastParagraphProperties->SetEndingRange(xTextRange->getEnd()); @@ -2847,8 +2844,10 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con // tdf#164878 skip empty paragraphs, i.e. math formula and other objects m_StreamStateStack.top().bParaChanged ) { - uno::Reference<text::XParagraphCursor> xParaCursor( - xTextAppend->createTextCursorByRange(xTextAppend->getEnd()), uno::UNO_QUERY_THROW); + rtl::Reference<SwXTextCursor> xParaCursor = dynamic_cast<SwXTextCursor*>( + xTextAppend->createTextCursorByRange(xTextAppend->getEnd()).get()); + if (!xParaCursor) + throw uno::RuntimeException(); //select paragraph xParaCursor->gotoStartOfParagraph( true ); @@ -2987,8 +2986,8 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con { // Get the end of paragraph character inserted uno::Reference< text::XTextCursor > xCur = xTextRange->getText( )->createTextCursor( ); - if (rAppendContext.xInsertPosition.is()) - xCur->gotoRange( rAppendContext.xInsertPosition, false ); + if (rAppendContext.xCursor.is()) + xCur->gotoRange( static_cast<text::XSentenceCursor*>(rAppendContext.xCursor.get()), false ); else xCur->gotoEnd( false ); @@ -3007,8 +3006,8 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con break; } - if (rAppendContext.xInsertPosition.is()) - xCur->gotoRange(rAppendContext.xInsertPosition, false); + if (rAppendContext.xCursor.is()) + xCur->gotoRange(static_cast<text::XSentenceCursor*>(rAppendContext.xCursor.get()), false); else xCur->gotoEnd(false); } @@ -3032,8 +3031,10 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con uno::Reference<text::XTextCursor> xCur = xTextRange->getText( )->createTextCursor( ); xCur->gotoEnd(false); xCur->goLeft(1, false); - uno::Reference<text::XTextCursor> xCur2 = xTextRange->getText()->createTextCursorByRange(xCur); - uno::Reference<text::XParagraphCursor> xParaCursor(xCur2, uno::UNO_QUERY_THROW); + rtl::Reference<SwXTextCursor> xParaCursor = dynamic_cast<SwXTextCursor*> + (xTextRange->getText()->createTextCursorByRange(xCur).get()); + if (!xParaCursor) + throw uno::RuntimeException(); xParaCursor->gotoStartOfParagraph(false); if (0 < m_StreamStateStack.top().nTableDepth) { @@ -3055,7 +3056,7 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con pHidden->second >>= bIsHidden; if (!bIsHidden) { - uno::Reference<text::XTextCursor> xCur3 = xTextRange->getText()->createTextCursorByRange(xParaCursor); + uno::Reference<text::XTextCursor> xCur3 = xTextRange->getText()->createTextCursorByRange(static_cast<text::XSentenceCursor*>(xParaCursor.get())); xCur3->goRight(1, true); if (xCur3->getString() == SAL_NEWLINE_STRING) { @@ -3533,9 +3534,9 @@ void DomainMapper_Impl::appendTextPortion( const OUString& rString, const Proper MergeAtContentImageRedlineWithNext(xTextAppend); uno::Reference< text::XTextRange > xTextRange; - if (m_aTextAppendStack.top().xInsertPosition.is()) + if (m_aTextAppendStack.top().xCursor.is()) { - xTextRange = xTextAppend->insertTextPortion(rString, aValues, m_aTextAppendStack.top().xInsertPosition); + xTextRange = xTextAppend->insertTextPortion(rString, aValues, static_cast<text::XSentenceCursor*>(m_aTextAppendStack.top().xCursor.get())); m_aTextAppendStack.top().xCursor->gotoRange(xTextRange->getEnd(), true); } else @@ -3642,8 +3643,8 @@ void DomainMapper_Impl::appendTextContent( try { - if (m_aTextAppendStack.top().xInsertPosition.is()) - xTextAppendAndConvert->insertTextContentWithProperties( xContent, xPropertyValues, m_aTextAppendStack.top().xInsertPosition ); + if (m_aTextAppendStack.top().xCursor.is()) + xTextAppendAndConvert->insertTextContentWithProperties( xContent, xPropertyValues, static_cast<text::XSentenceCursor*>(m_aTextAppendStack.top().xCursor.get()) ); else xTextAppendAndConvert->appendTextContent( xContent, xPropertyValues ); } @@ -3933,12 +3934,15 @@ rtl::Reference< SwXTextSection > DomainMapper_Impl::appendTextSectionAfter( try { - uno::Reference< text::XParagraphCursor > xCursor( - xTextAppend->createTextCursorByRange( xBefore ), uno::UNO_QUERY_THROW); + rtl::Reference< SwXTextCursor > xCursor = + dynamic_cast<SwXTextCursor*>( + xTextAppend->createTextCursorByRange( xBefore ).get()); + if (!xCursor) + return {}; //the cursor has been moved to the end of the paragraph because of the appendTextPortion() calls xCursor->gotoStartOfParagraph( false ); - if (m_aTextAppendStack.top().xInsertPosition.is()) - xCursor->gotoRange( m_aTextAppendStack.top().xInsertPosition, true ); + if (m_aTextAppendStack.top().xCursor.is()) + xCursor->gotoRange( static_cast<text::XSentenceCursor*>(m_aTextAppendStack.top().xCursor.get()), true ); else xCursor->gotoEnd( true ); // The paragraph after this new section is already inserted. The previous node may be a @@ -3955,7 +3959,7 @@ rtl::Reference< SwXTextSection > DomainMapper_Impl::appendTextSectionAfter( copyAllProps(xEndPara, xNewPara); xSection = m_xTextDocument->createTextSection(); - xSection->attach(xCursor); + xSection->attach(static_cast<text::XSentenceCursor*>(xCursor.get())); // Remove the extra paragraph (last inside the section) xEndPara->dispose(); @@ -5472,7 +5476,7 @@ void DomainMapper_Impl::HandlePTab(sal_Int32 nAlignment) } uno::Reference<css::text::XTextRange> xInsertPosition - = m_aTextAppendStack.top().xInsertPosition; + = static_cast<text::XSentenceCursor*>(m_aTextAppendStack.top().xCursor.get()); if (!xInsertPosition.is()) { xInsertPosition = xTextAppend->getEnd(); @@ -5488,7 +5492,7 @@ void DomainMapper_Impl::HandlePTab(sal_Int32 nAlignment) } // Assume that there is some content before the tab character. - uno::Reference<text::XParagraphCursor> xParagraphCursor(xCursor, uno::UNO_QUERY); + rtl::Reference<SwXTextCursor> xParagraphCursor(dynamic_cast<SwXTextCursor*>(xCursor.get())); if (!xParagraphCursor.is()) { return; @@ -6371,8 +6375,8 @@ void DomainMapper_Impl::PushFieldContext() uno::Reference<text::XTextAppend> xTextAppend = m_aTextAppendStack.top().xTextAppend; if (xTextAppend.is()) xCrsr = xTextAppend->createTextCursorByRange( - m_aTextAppendStack.top().xInsertPosition.is() - ? m_aTextAppendStack.top().xInsertPosition + m_aTextAppendStack.top().xCursor.is() + ? static_cast<text::XSentenceCursor*>(m_aTextAppendStack.top().xCursor.get()) : xTextAppend->getEnd()); } @@ -7241,15 +7245,16 @@ OUString DomainMapper_Impl::extractTocTitle() // try-catch was added in the same way as inside appendTextSectionAfter() try { - uno::Reference<text::XParagraphCursor> const xCursor( - xTextAppend->createTextCursorByRange(m_StreamStateStack.top().xSdtEntryStart), uno::UNO_QUERY_THROW); + rtl::Reference<SwXTextCursor> const xCursor = + dynamic_cast<SwXTextCursor*>( + xTextAppend->createTextCursorByRange(m_StreamStateStack.top().xSdtEntryStart).get()); if (!xCursor.is()) return OUString(); //the cursor has been moved to the end of the paragraph because of the appendTextPortion() calls xCursor->gotoStartOfParagraph( false ); - if (m_aTextAppendStack.top().xInsertPosition.is()) - xCursor->gotoRange( m_aTextAppendStack.top().xInsertPosition, true ); + if (m_aTextAppendStack.top().xCursor.is()) + xCursor->gotoRange( static_cast<text::XSentenceCursor*>(m_aTextAppendStack.top().xCursor.get()), true ); else xCursor->gotoEnd( true ); @@ -7283,7 +7288,7 @@ DomainMapper_Impl::StartIndexSectionChecked(std::u16string_view sServiceName) const auto& xTextAppend = GetTopTextAppend(); const auto xTextRange = xTextAppend->getEnd(); const auto xRet = createSectionForRange(xTextRange, xTextRange, sServiceName, false); - if (!m_aTextAppendStack.top().xInsertPosition) + if (!m_aTextAppendStack.top().xCursor) { try { @@ -7732,8 +7737,8 @@ rtl::Reference<SwXSection> DomainMapper_Impl::createSectionForRange( rtl::Reference< SwXSection > xSection; try { - uno::Reference< text::XParagraphCursor > xCursor( - xTextAppend->createTextCursorByRange( xStart ), uno::UNO_QUERY ); + rtl::Reference< SwXTextCursor > xCursor = + dynamic_cast<SwXTextCursor*>(xTextAppend->createTextCursorByRange( xStart ).get()); if(!xCursor) return {}; //the cursor has been moved to the end of the paragraph because of the appendTextPortion() calls @@ -7745,7 +7750,7 @@ rtl::Reference<SwXSection> DomainMapper_Impl::createSectionForRange( xSection = m_xTextDocument->createSection(sObjectType); if (!xSection) return {}; - xSection->attach( xCursor ); + xSection->attach( static_cast<text::XSentenceCursor*>(xCursor.get()) ); } catch(const uno::Exception&) { @@ -7843,17 +7848,17 @@ static auto InsertFieldmark(std::stack<TextAppendContext> & rTextAppendStack, uno::Reference<text::XTextAppend> const& xTextAppend(rTextAppendStack.top().xTextAppend); uno::Reference<text::XTextCursor> const xCursor = xTextAppend->createTextCursorByRange(xStartRange); - if (rTextAppendStack.top().xInsertPosition.is()) + if (rTextAppendStack.top().xCursor.is()) { uno::Reference<text::XTextRangeCompare> const xCompare( rTextAppendStack.top().xTextAppend, uno::UNO_QUERY); - if (xCompare->compareRegionStarts(xStartRange, rTextAppendStack.top().xInsertPosition) < 0) + if (xCompare->compareRegionStarts(xStartRange, static_cast<text::XSentenceCursor*>(rTextAppendStack.top().xCursor.get())) < 0) { SAL_WARN("writerfilter.dmapper", "invalid field mark positions"); assert(false); } - xCursor->gotoRange(rTextAppendStack.top().xInsertPosition, true); + xCursor->gotoRange(static_cast<text::XSentenceCursor*>(rTextAppendStack.top().xCursor.get()), true); } else { @@ -7886,7 +7891,7 @@ static auto PopFieldmark(std::stack<TextAppendContext> & rTextAppendStack, { return; // only a single CH_TXT_ATR_FORMELEMENT! } - xCursor->gotoRange(rTextAppendStack.top().xInsertPosition, false); + xCursor->gotoRange(static_cast<text::XSentenceCursor*>(rTextAppendStack.top().xCursor.get()), false); xCursor->goRight(1, true); xCursor->setString(OUString()); // undo SplitNode from CloseFieldCommand() // note: paragraph properties will be overwritten @@ -9138,8 +9143,8 @@ void DomainMapper_Impl::PopFieldContext() // should not be part of index auto xCursor = xTextAppend->createTextCursorByRange( - m_aTextAppendStack.top().xInsertPosition.is() - ? m_aTextAppendStack.top().xInsertPosition + m_aTextAppendStack.top().xCursor.is() + ? static_cast<text::XSentenceCursor*>(m_aTextAppendStack.top().xCursor.get()) : xTextAppend->getEnd()); xCursor->goLeft(1, true); // delete @@ -9152,7 +9157,7 @@ void DomainMapper_Impl::PopFieldContext() else { xTextAppend->finishParagraphInsert(css::beans::PropertyValues(), - m_aTextAppendStack.top().xInsertPosition); + static_cast<text::XSentenceCursor*>(m_aTextAppendStack.top().xCursor.get())); } } m_bStartedTOC = false; @@ -9223,9 +9228,9 @@ void DomainMapper_Impl::PopFieldContext() } else if (!pContext->GetHyperlinkURL().isEmpty() && xCrsr.is()) { - if (m_aTextAppendStack.top().xInsertPosition.is()) + if (m_aTextAppendStack.top().xCursor.is()) { - xCrsr->gotoRange(m_aTextAppendStack.top().xInsertPosition, true); + xCrsr->gotoRange(static_cast<text::XSentenceCursor*>(m_aTextAppendStack.top().xCursor.get()), true); } else { @@ -9415,8 +9420,8 @@ void DomainMapper_Impl::StartOrEndBookmark( const OUString& rId ) { uno::Reference<text::XTextCursor> const xCursor = xTextAppend->createTextCursorByRange( - m_aTextAppendStack.top().xInsertPosition.is() - ? m_aTextAppendStack.top().xInsertPosition + m_aTextAppendStack.top().xCursor.is() + ? static_cast<text::XSentenceCursor*>(m_aTextAppendStack.top().xCursor.get()) : xTextAppend->getEnd() ); if (!xCursor) @@ -9581,7 +9586,7 @@ void DomainMapper_Impl::AddAnnotationPosition( if (m_bIsNewDoc) xCursor = xTextAppend->createTextCursorByRange(xTextAppend->getEnd()); else - xCursor = m_aTextAppendStack.top().xCursor; + xCursor = static_cast<text::XSentenceCursor*>(m_aTextAppendStack.top().xCursor.get()); if (xCursor.is()) xCurrent = xCursor->getStart(); } diff --git a/sw/source/writerfilter/dmapper/DomainMapper_Impl.hxx b/sw/source/writerfilter/dmapper/DomainMapper_Impl.hxx index 97ed342c2293..26aca1fbbe02 100644 --- a/sw/source/writerfilter/dmapper/DomainMapper_Impl.hxx +++ b/sw/source/writerfilter/dmapper/DomainMapper_Impl.hxx @@ -57,6 +57,7 @@ #include <unobookmark.hxx> #include <unofield.hxx> #include <unoframe.hxx> +#include <unotextcursor.hxx> #include <map> class SwXTextDocument; @@ -518,8 +519,7 @@ struct AnchoredObjectsInfo struct TextAppendContext { css::uno::Reference<css::text::XTextAppend> xTextAppend; - css::uno::Reference<css::text::XParagraphCursor> xCursor; - css::uno::Reference<css::text::XTextRange> xInsertPosition; + rtl::Reference<SwXTextCursor> xCursor; ParagraphPropertiesPtr pLastParagraphProperties; /** @@ -531,8 +531,7 @@ struct TextAppendContext TextAppendContext(css::uno::Reference<css::text::XTextAppend> const& i_xAppend, css::uno::Reference<css::text::XTextCursor> const& i_xCursor) : xTextAppend(i_xAppend) - , xCursor(i_xCursor, css::uno::UNO_QUERY) - , xInsertPosition(xCursor) + , xCursor(dynamic_cast<SwXTextCursor*>(i_xCursor.get())) {} }; diff --git a/sw/source/writerfilter/dmapper/PropertyMap.cxx b/sw/source/writerfilter/dmapper/PropertyMap.cxx index 7c33e28d39e5..fe85029db329 100644 --- a/sw/source/writerfilter/dmapper/PropertyMap.cxx +++ b/sw/source/writerfilter/dmapper/PropertyMap.cxx @@ -1596,9 +1596,10 @@ void SectionPropertyMap::EmulateSectPrBelowSpacing(DomainMapper_Impl& rDM_Impl) { const uno::Any aBelowSpacingOfPrevSection(*pPrevSection->GetBelowSpacing()); const OUString sProp(getPropertyName(PROP_PARA_BOTTOM_MARGIN)); - uno::Reference<beans::XPropertySet> xLastParaInPrevSection(m_xPreStartingRange, - uno::UNO_QUERY_THROW); - xLastParaInPrevSection->setPropertyValue(sProp, aBelowSpacingOfPrevSection); + if (m_xPreStartingRange) + m_xPreStartingRange->setPropertyValue(sProp, aBelowSpacingOfPrevSection); + else + SAL_WARN("writerfilter", "Failed to transfer below spacing to last para."); } catch (uno::Exception&) { @@ -1730,16 +1731,15 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl ) if (!xSection.is() && m_xPreStartingRange.is()) { //similar hack as below - uno::Reference<beans::XPropertySet> const xPSRange(m_xPreStartingRange, uno::UNO_QUERY_THROW); style::BreakType eBreakType; - if ((xPSRange->getPropertyValue(u"BreakType"_ustr) >>= eBreakType) && eBreakType == style::BreakType_PAGE_BEFORE) + if ((m_xPreStartingRange->getPropertyValue(u"BreakType"_ustr) >>= eBreakType) && eBreakType == style::BreakType_PAGE_BEFORE) { - xPSRange->setPropertyValue(getPropertyName(PROP_PAGE_DESC_NAME), uno::Any(m_sPageStyleName)); + m_xPreStartingRange->setPropertyValue(getPropertyName(PROP_PAGE_DESC_NAME), uno::Any(m_sPageStyleName)); m_aPageStyle->setPropertyValue(getPropertyName(PROP_FIRST_IS_SHARED), uno::Any(true)); if (0 <= m_nPageNumber) { sal_Int16 nPageNumber = static_cast< sal_Int16 >(m_nPageNumber); - xPSRange->setPropertyValue(getPropertyName(PROP_PAGE_NUMBER_OFFSET), + m_xPreStartingRange->setPropertyValue(getPropertyName(PROP_PAGE_NUMBER_OFFSET), uno::Any(nPageNumber)); } } @@ -1776,42 +1776,44 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl ) } } } - uno::Reference<text::XParagraphCursor> const xPCursor(xCursor, uno::UNO_QUERY_THROW); - float fCharHeight = 0; - if (!isFound) - { // HACK: try the last paragraph of the previous section - xPCursor->gotoPreviousParagraph(false); - uno::Reference<beans::XPropertySet> const xPSCursor(xCursor, uno::UNO_QUERY_THROW); - style::BreakType eBreakType; - if ((xPSCursor->getPropertyValue(u"BreakType"_ustr) >>= eBreakType) && eBreakType == style::BreakType_PAGE_BEFORE) - { - xPSCursor->setPropertyValue(getPropertyName(PROP_PAGE_DESC_NAME), uno::Any(m_sPageStyleName)); - m_aPageStyle->setPropertyValue(getPropertyName(PROP_FIRST_IS_SHARED), uno::Any(true)); - isFound = true; - if (0 <= m_nPageNumber) + rtl::Reference<SwXTextCursor> const xPCursor = dynamic_cast<SwXTextCursor*>(xCursor.get()); + if (xPCursor) + { + float fCharHeight = 0; + if (!isFound) + { // HACK: try the last paragraph of the previous section + xPCursor->gotoPreviousParagraph(false); + style::BreakType eBreakType; + if ((xPCursor->getPropertyValue(u"BreakType"_ustr) >>= eBreakType) && eBreakType == style::BreakType_PAGE_BEFORE) + { + xPCursor->setPropertyValue(getPropertyName(PROP_PAGE_DESC_NAME), uno::Any(m_sPageStyleName)); + m_aPageStyle->setPropertyValue(getPropertyName(PROP_FIRST_IS_SHARED), uno::Any(true)); + isFound = true; + if (0 <= m_nPageNumber) + { + sal_Int16 nPageNumber = static_cast< sal_Int16 >(m_nPageNumber); + xPCursor->setPropertyValue(getPropertyName(PROP_PAGE_NUMBER_OFFSET), + uno::Any(nPageNumber)); + } + } + else { - sal_Int16 nPageNumber = static_cast< sal_Int16 >(m_nPageNumber); - xPSCursor->setPropertyValue(getPropertyName(PROP_PAGE_NUMBER_OFFSET), - uno::Any(nPageNumber)); + xPCursor->getPropertyValue(u"CharHeight"_ustr) >>= fCharHeight; } } - else - { - xPSCursor->getPropertyValue(u"CharHeight"_ustr) >>= fCharHeight; - } - } - if (!isFound && fCharHeight <= 1.0) - { - // If still not found, see if the last paragraph is ~invisible, and work with - // the last-in-practice paragraph. - xPCursor->gotoPreviousParagraph(false); - uno::Reference<beans::XPropertySet> xPropertySet(xCursor, uno::UNO_QUERY_THROW); - OUString aPageDescName; - if ((xPropertySet->getPropertyValue(u"PageDescName"_ustr) >>= aPageDescName) && !aPageDescName.isEmpty()) + if (!isFound && fCharHeight <= 1.0) { - rtl::Reference<SwXBaseStyle> xPageStyle(rDM_Impl.GetPageStyles()->getStyleByName(aPageDescName)); - xPageStyle->setPropertyValue(u"FollowStyle"_ustr, uno::Any(m_sPageStyleName)); - m_aPageStyle->setPropertyValue(getPropertyName(PROP_FIRST_IS_SHARED), uno::Any(true)); + // If still not found, see if the last paragraph is ~invisible, and work with + // the last-in-practice paragraph. + xPCursor->gotoPreviousParagraph(false); + uno::Reference<beans::XPropertySet> xPropertySet(xCursor, uno::UNO_QUERY_THROW); + OUString aPageDescName; + if ((xPropertySet->getPropertyValue(u"PageDescName"_ustr) >>= aPageDescName) && !aPageDescName.isEmpty()) + { + rtl::Reference<SwXBaseStyle> xPageStyle(rDM_Impl.GetPageStyles()->getStyleByName(aPageDescName)); + xPageStyle->setPropertyValue(u"FollowStyle"_ustr, uno::Any(m_sPageStyleName)); + m_aPageStyle->setPropertyValue(getPropertyName(PROP_FIRST_IS_SHARED), uno::Any(true)); + } } } } @@ -2222,12 +2224,15 @@ void SectionPropertyMap::SetStart( const uno::Reference< text::XTextRange >& xRa m_xStartingRange = xRange; try { - uno::Reference<text::XParagraphCursor> const xPCursor( - m_xStartingRange->getText()->createTextCursorByRange(m_xStartingRange), uno::UNO_QUERY_THROW); - // CAUTION: gotoPreviousParagraph skips over tables, - // so this range does not necessarily indicate the end of the previous section - if (xPCursor->gotoPreviousParagraph(false)) - m_xPreStartingRange = xPCursor; + rtl::Reference<SwXTextCursor> const xPCursor = + dynamic_cast<SwXTextCursor*>(m_xStartingRange->getText()->createTextCursorByRange(m_xStartingRange).get()); + if (xPCursor) + { + // CAUTION: gotoPreviousParagraph skips over tables, + // so this range does not necessarily indicate the end of the previous section + if (xPCursor->gotoPreviousParagraph(false)) + m_xPreStartingRange = xPCursor; + } } catch (const uno::Exception&) { diff --git a/sw/source/writerfilter/dmapper/PropertyMap.hxx b/sw/source/writerfilter/dmapper/PropertyMap.hxx index 31ee213ccc4b..a688c21fa0e5 100644 --- a/sw/source/writerfilter/dmapper/PropertyMap.hxx +++ b/sw/source/writerfilter/dmapper/PropertyMap.hxx @@ -32,6 +32,7 @@ #include "PropertyIds.hxx" #include <unofootnote.hxx> #include <unoxstyle.hxx> +#include <unotextcursor.hxx> #include <memory> #include <optional> @@ -258,7 +259,7 @@ private: bool m_bIsFirstSection; css::uno::Reference< css::text::XTextRange > m_xStartingRange; - css::uno::Reference< css::text::XTextRange > m_xPreStartingRange; + rtl::Reference< SwXTextCursor > m_xPreStartingRange; OUString m_sPageStyleName; rtl::Reference<SwXPageStyle> m_aPageStyle; @@ -650,7 +651,7 @@ typedef tools::SvRef< TablePropertyMap > TablePropertyMapPtr; /// Information about a paragraph to be finished after a table end. struct TableParagraph { - css::uno::Reference<css::text::XTextRange> m_rStartParagraph; + rtl::Reference<SwXTextCursor> m_rStartParagraph; css::uno::Reference<css::text::XTextRange> m_rEndParagraph; PropertyMapPtr m_pPropertyMap; css::uno::Reference<css::beans::XPropertySet> m_rPropertySet;
