diff options
Diffstat (limited to 'sw/source/core/unocore/unoflatpara.cxx')
-rw-r--r-- | sw/source/core/unocore/unoflatpara.cxx | 108 |
1 files changed, 48 insertions, 60 deletions
diff --git a/sw/source/core/unocore/unoflatpara.cxx b/sw/source/core/unocore/unoflatpara.cxx index 5e405e9ec75c..0f158e49fc82 100644 --- a/sw/source/core/unocore/unoflatpara.cxx +++ b/sw/source/core/unocore/unoflatpara.cxx @@ -22,6 +22,7 @@ #include <unoflatpara.hxx> #include <o3tl/safeint.hxx> +#include <utility> #include <vcl/svapp.hxx> #include <com/sun/star/text/TextMarkupType.hpp> #include <com/sun/star/beans/PropertyAttribute.hpp> @@ -41,7 +42,7 @@ #include <rootfrm.hxx> #include <poolfmt.hxx> #include <pagedesc.hxx> -#include <IGrammarContact.hxx> +#include <GrammarContact.hxx> #include <viewopt.hxx> #include <comphelper/servicehelper.hxx> #include <comphelper/propertysetinfo.hxx> @@ -64,9 +65,10 @@ CreateFlatParagraphIterator(SwDoc & rDoc, sal_Int32 const nTextMarkupType, } -SwXFlatParagraph::SwXFlatParagraph( SwTextNode& rTextNode, const OUString& aExpandText, const ModelToViewHelper& rMap ) +SwXFlatParagraph::SwXFlatParagraph( SwTextNode& rTextNode, OUString aExpandText, const ModelToViewHelper& rMap ) : SwXFlatParagraph_Base(& rTextNode, rMap) - , maExpandText(aExpandText) + , maExpandText(std::move(aExpandText)) + , maOrigText(rTextNode.GetText()) { } @@ -79,10 +81,11 @@ SwXFlatParagraph::~SwXFlatParagraph() uno::Reference< beans::XPropertySetInfo > SAL_CALL SwXFlatParagraph::getPropertySetInfo() { - static comphelper::PropertyMapEntry s_Entries[] = { + static const comphelper::PropertyMapEntry s_Entries[] = { { OUString("FieldPositions"), -1, ::cppu::UnoType<uno::Sequence<sal_Int32>>::get(), beans::PropertyAttribute::READONLY, 0 }, { OUString("FootnotePositions"), -1, ::cppu::UnoType<uno::Sequence<sal_Int32>>::get(), beans::PropertyAttribute::READONLY, 0 }, - { OUString(), -1, css::uno::Type(), 0, 0 } + { OUString("SortedTextId"), -1, ::cppu::UnoType<sal_Int32>::get(), beans::PropertyAttribute::READONLY, 0 }, + { OUString("DocumentElementsCount"), -1, ::cppu::UnoType<sal_Int32>::get(), beans::PropertyAttribute::READONLY, 0 }, }; return new comphelper::PropertySetInfo(s_Entries); } @@ -91,7 +94,7 @@ void SAL_CALL SwXFlatParagraph::setPropertyValue(const OUString&, const uno::Any&) { throw lang::IllegalArgumentException("no values can be set", - static_cast< ::cppu::OWeakObject*>(this), 0); + getXWeak(), 0); } uno::Any SAL_CALL @@ -101,11 +104,27 @@ SwXFlatParagraph::getPropertyValue(const OUString& rPropertyName) if (rPropertyName == "FieldPositions") { - return uno::makeAny( comphelper::containerToSequence( GetConversionMap().getFieldPositions() ) ); + return uno::Any( comphelper::containerToSequence( GetConversionMap().getFieldPositions() ) ); } else if (rPropertyName == "FootnotePositions") { - return uno::makeAny( comphelper::containerToSequence( GetConversionMap().getFootnotePositions() ) ); + return uno::Any( comphelper::containerToSequence( GetConversionMap().getFootnotePositions() ) ); + } + else if (rPropertyName == "SortedTextId") + { + SwTextNode const*const pCurrentNode = GetTextNode(); + sal_Int32 nIndex = -1; + if ( pCurrentNode ) + nIndex = pCurrentNode->GetIndex().get(); + return uno::Any( nIndex ); + } + else if (rPropertyName == "DocumentElementsCount") + { + SwTextNode const*const pCurrentNode = GetTextNode(); + sal_Int32 nCount = -1; + if ( pCurrentNode ) + nCount = pCurrentNode->GetDoc().GetNodes().Count().get(); + return uno::Any( nCount ); } return uno::Any(); } @@ -182,7 +201,7 @@ void SAL_CALL SwXFlatParagraph::setChecked( ::sal_Int32 nType, sal_Bool bVal ) if ( text::TextMarkupType::SPELLCHECK == nType ) { GetTextNode()->SetWrongDirty( - bVal ? SwTextNode::WrongState::DONE : SwTextNode::WrongState::TODO); + bVal ? sw::WrongState::DONE : sw::WrongState::TODO); } else if ( text::TextMarkupType::SMARTTAG == nType ) GetTextNode()->SetSmartTagDirty( !bVal ); @@ -190,7 +209,7 @@ void SAL_CALL SwXFlatParagraph::setChecked( ::sal_Int32 nType, sal_Bool bVal ) { GetTextNode()->SetGrammarCheckDirty( !bVal ); if( bVal ) - ::finishGrammarCheck( *GetTextNode() ); + sw::finishGrammarCheckFor(*GetTextNode()); } } @@ -215,7 +234,7 @@ sal_Bool SAL_CALL SwXFlatParagraph::isChecked( ::sal_Int32 nType ) sal_Bool SAL_CALL SwXFlatParagraph::isModified() { SolarMutexGuard aGuard; - return nullptr == GetTextNode(); + return !GetTextNode() || GetTextNode()->GetText() != maOrigText; } // text::XFlatParagraph: @@ -260,14 +279,13 @@ void SAL_CALL SwXFlatParagraph::changeText(::sal_Int32 nPos, ::sal_Int32 nLen, c UnoActionContext aAction( &GetTextNode()->GetDoc() ); - const uno::Reference< text::XTextRange > xRange = + const rtl::Reference<SwXTextRange> xRange = SwXTextRange::CreateXTextRange( GetTextNode()->GetDoc(), *aPaM.GetPoint(), aPaM.GetMark() ); - uno::Reference< beans::XPropertySet > xPropSet( xRange, uno::UNO_QUERY ); - if ( xPropSet.is() ) + if ( xRange.is() ) { for ( const auto& rAttribute : aAttributes ) - xPropSet->setPropertyValue( rAttribute.Name, rAttribute.Value ); + xRange->setPropertyValue( rAttribute.Name, rAttribute.Value ); } IDocumentContentOperations& rIDCO = pOldTextNode->getIDocumentContentOperations(); @@ -293,14 +311,13 @@ void SAL_CALL SwXFlatParagraph::changeAttributes(::sal_Int32 nPos, ::sal_Int32 n UnoActionContext aAction( &GetTextNode()->GetDoc() ); - const uno::Reference< text::XTextRange > xRange = + const rtl::Reference<SwXTextRange> xRange = SwXTextRange::CreateXTextRange( GetTextNode()->GetDoc(), *aPaM.GetPoint(), aPaM.GetMark() ); - uno::Reference< beans::XPropertySet > xPropSet( xRange, uno::UNO_QUERY ); - if ( xPropSet.is() ) + if ( xRange.is() ) { for ( const auto& rAttribute : aAttributes ) - xPropSet->setPropertyValue( rAttribute.Name, rAttribute.Value ); + xRange->setPropertyValue( rAttribute.Name, rAttribute.Value ); } ClearTextNode(); // TODO: is this really needed? @@ -312,24 +329,6 @@ css::uno::Sequence< ::sal_Int32 > SAL_CALL SwXFlatParagraph::getLanguagePortions return css::uno::Sequence< ::sal_Int32>(); } -namespace -{ - class theSwXFlatParagraphUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSwXFlatParagraphUnoTunnelId > {}; -} - -const uno::Sequence< sal_Int8 >& -SwXFlatParagraph::getUnoTunnelId() -{ - return theSwXFlatParagraphUnoTunnelId::get().getSeq(); -} - -sal_Int64 SAL_CALL -SwXFlatParagraph::getSomething( - const uno::Sequence< sal_Int8 >& rId) -{ - return sw::UnoTunnelImpl(rId, this); -} - SwXFlatParagraphIterator::SwXFlatParagraphIterator( SwDoc& rDoc, sal_Int32 nType, bool bAutomatic ) : mpDoc( &rDoc ), mnType( nType ), @@ -460,7 +459,7 @@ uno::Reference< text::XFlatParagraph > SwXFlatParagraphIterator::getNextPara() else // non-automatic checking { const SwNodes& rNodes = mpDoc->GetNodes(); - const sal_uLong nMaxNodes = rNodes.Count(); + const SwNodeOffset nMaxNodes = rNodes.Count(); while ( mnCurrentNode < mnEndNode && mnCurrentNode < nMaxNodes ) { @@ -468,14 +467,14 @@ uno::Reference< text::XFlatParagraph > SwXFlatParagraphIterator::getNextPara() ++mnCurrentNode; - pRet = dynamic_cast<SwTextNode*>(pNd); + pRet = pNd->GetTextNode(); if ( pRet ) break; if ( mnCurrentNode == mnEndNode ) { - mnCurrentNode = 0; - mnEndNode = 0; + mnCurrentNode = SwNodeOffset(0); + mnEndNode = SwNodeOffset(0); } } } @@ -487,8 +486,6 @@ uno::Reference< text::XFlatParagraph > SwXFlatParagraphIterator::getNextPara() const OUString& aExpandText = aConversionMap.getViewText(); xRet = new SwXFlatParagraph( *pRet, aExpandText, aConversionMap ); - // keep hard references... - m_aFlatParaList.insert( xRet ); } return xRet; @@ -507,10 +504,8 @@ uno::Reference< text::XFlatParagraph > SwXFlatParagraphIterator::getParaAfter(co if (!mpDoc) return xRet; - const uno::Reference<lang::XUnoTunnel> xFPTunnel(xPara, uno::UNO_QUERY); - SAL_WARN_IF(!xFPTunnel.is(), "sw.core", "invalid argument"); - SwXFlatParagraph* const pFlatParagraph(sw::UnoTunnelGetImplementation<SwXFlatParagraph>(xFPTunnel)); - + SwXFlatParagraph* const pFlatParagraph(dynamic_cast<SwXFlatParagraph*>(xPara.get())); + SAL_WARN_IF(!pFlatParagraph, "sw.core", "invalid argument"); if ( !pFlatParagraph ) return xRet; @@ -522,10 +517,10 @@ uno::Reference< text::XFlatParagraph > SwXFlatParagraphIterator::getParaAfter(co SwTextNode* pNextTextNode = nullptr; const SwNodes& rNodes = pCurrentNode->GetDoc().GetNodes(); - for( sal_uLong nCurrentNode = pCurrentNode->GetIndex() + 1; nCurrentNode < rNodes.Count(); ++nCurrentNode ) + for( SwNodeOffset nCurrentNode = pCurrentNode->GetIndex() + 1; nCurrentNode < rNodes.Count(); ++nCurrentNode ) { SwNode* pNd = rNodes[ nCurrentNode ]; - pNextTextNode = dynamic_cast<SwTextNode*>(pNd); + pNextTextNode = pNd->GetTextNode(); if ( pNextTextNode ) break; } @@ -537,8 +532,6 @@ uno::Reference< text::XFlatParagraph > SwXFlatParagraphIterator::getParaAfter(co const OUString& aExpandText = aConversionMap.getViewText(); xRet = new SwXFlatParagraph( *pNextTextNode, aExpandText, aConversionMap ); - // keep hard references... - m_aFlatParaList.insert( xRet ); } return xRet; @@ -552,11 +545,8 @@ uno::Reference< text::XFlatParagraph > SwXFlatParagraphIterator::getParaBefore(c if (!mpDoc) return xRet; - const uno::Reference<lang::XUnoTunnel> xFPTunnel(xPara, uno::UNO_QUERY); - - SAL_WARN_IF(!xFPTunnel.is(), "sw.core", "invalid argument"); - SwXFlatParagraph* const pFlatParagraph(sw::UnoTunnelGetImplementation<SwXFlatParagraph>(xFPTunnel)); - + SwXFlatParagraph* const pFlatParagraph(dynamic_cast<SwXFlatParagraph*>(xPara.get())); + SAL_WARN_IF(!pFlatParagraph, "sw.core", "invalid argument"); if ( !pFlatParagraph ) return xRet; @@ -568,10 +558,10 @@ uno::Reference< text::XFlatParagraph > SwXFlatParagraphIterator::getParaBefore(c SwTextNode* pPrevTextNode = nullptr; const SwNodes& rNodes = pCurrentNode->GetDoc().GetNodes(); - for( sal_uLong nCurrentNode = pCurrentNode->GetIndex() - 1; nCurrentNode > 0; --nCurrentNode ) + for( SwNodeOffset nCurrentNode = pCurrentNode->GetIndex() - 1; nCurrentNode > SwNodeOffset(0); --nCurrentNode ) { SwNode* pNd = rNodes[ nCurrentNode ]; - pPrevTextNode = dynamic_cast<SwTextNode*>(pNd); + pPrevTextNode = pNd->GetTextNode(); if ( pPrevTextNode ) break; } @@ -583,8 +573,6 @@ uno::Reference< text::XFlatParagraph > SwXFlatParagraphIterator::getParaBefore(c const OUString& aExpandText = aConversionMap.getViewText(); xRet = new SwXFlatParagraph( *pPrevTextNode, aExpandText, aConversionMap ); - // keep hard references... - m_aFlatParaList.insert( xRet ); } return xRet; |