diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-04-14 15:58:10 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-04-14 20:45:59 +0200 |
commit | d72f963c0de0c2e48f1dc999cd8687e13a1f676f (patch) | |
tree | 9f5e314e1f9e504706cc18675f9408fe3c8db8ea /editeng/source/uno | |
parent | loplugin:flatten in embeddedobj,emfio (diff) | |
download | core-d72f963c0de0c2e48f1dc999cd8687e13a1f676f.tar.gz core-d72f963c0de0c2e48f1dc999cd8687e13a1f676f.zip |
loplugin:flatten in editeng
Change-Id: I5c83183d1f9d2d8f5a25b976ead1a7598a75c641
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92197
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'editeng/source/uno')
-rw-r--r-- | editeng/source/uno/unoedhlp.cxx | 104 | ||||
-rw-r--r-- | editeng/source/uno/unotext.cxx | 413 | ||||
-rw-r--r-- | editeng/source/uno/unotext2.cxx | 86 |
3 files changed, 301 insertions, 302 deletions
diff --git a/editeng/source/uno/unoedhlp.cxx b/editeng/source/uno/unoedhlp.cxx index efc60ef66bd6..19e14fcfc50a 100644 --- a/editeng/source/uno/unoedhlp.cxx +++ b/editeng/source/uno/unoedhlp.cxx @@ -161,78 +161,78 @@ void SvxEditSourceHelper::GetAttributeRun( sal_Int32& nStartIndex, sal_Int32& nE nStartIndex = nClosestStartIndex; nEndIndex = nClosestEndIndex; - if ( bInCell ) + if ( !bInCell ) + return; + + EPosition aStartPos( nPara, nStartIndex ), aEndPos( nPara, nEndIndex ); + sal_Int32 nParaCount = rEE.GetParagraphCount(); + sal_Int32 nCrrntParaLen = rEE.GetTextLen(nPara); + //need to find closest index in front of nIndex in the previous paragraphs + if ( aStartPos.nIndex == 0 ) { - EPosition aStartPos( nPara, nStartIndex ), aEndPos( nPara, nEndIndex ); - sal_Int32 nParaCount = rEE.GetParagraphCount(); - sal_Int32 nCrrntParaLen = rEE.GetTextLen(nPara); - //need to find closest index in front of nIndex in the previous paragraphs - if ( aStartPos.nIndex == 0 ) + SfxItemSet aCrrntSet = rEE.GetAttribs( nPara, 0, 1, GetAttribsFlags::CHARATTRIBS ); + for ( sal_Int32 nParaIdx = nPara-1; nParaIdx >= 0; nParaIdx-- ) { - SfxItemSet aCrrntSet = rEE.GetAttribs( nPara, 0, 1, GetAttribsFlags::CHARATTRIBS ); - for ( sal_Int32 nParaIdx = nPara-1; nParaIdx >= 0; nParaIdx-- ) + sal_uInt32 nLen = rEE.GetTextLen(nParaIdx); + if ( nLen ) { - sal_uInt32 nLen = rEE.GetTextLen(nParaIdx); - if ( nLen ) + sal_Int32 nStartIdx, nEndIdx; + GetAttributeRun( nStartIdx, nEndIdx, rEE, nParaIdx, nLen ); + SfxItemSet aSet = rEE.GetAttribs( nParaIdx, nLen-1, nLen, GetAttribsFlags::CHARATTRIBS ); + if ( aSet == aCrrntSet ) { - sal_Int32 nStartIdx, nEndIdx; - GetAttributeRun( nStartIdx, nEndIdx, rEE, nParaIdx, nLen ); - SfxItemSet aSet = rEE.GetAttribs( nParaIdx, nLen-1, nLen, GetAttribsFlags::CHARATTRIBS ); - if ( aSet == aCrrntSet ) + aStartPos.nPara = nParaIdx; + aStartPos.nIndex = nStartIdx; + if ( aStartPos.nIndex != 0 ) { - aStartPos.nPara = nParaIdx; - aStartPos.nIndex = nStartIdx; - if ( aStartPos.nIndex != 0 ) - { - break; - } + break; } } } } - //need find closest index behind nIndex in the following paragraphs - if ( aEndPos.nIndex == nCrrntParaLen ) + } + //need find closest index behind nIndex in the following paragraphs + if ( aEndPos.nIndex == nCrrntParaLen ) + { + SfxItemSet aCrrntSet = rEE.GetAttribs( nPara, nCrrntParaLen-1, nCrrntParaLen, GetAttribsFlags::CHARATTRIBS ); + for ( sal_Int32 nParaIdx = nPara+1; nParaIdx < nParaCount; nParaIdx++ ) { - SfxItemSet aCrrntSet = rEE.GetAttribs( nPara, nCrrntParaLen-1, nCrrntParaLen, GetAttribsFlags::CHARATTRIBS ); - for ( sal_Int32 nParaIdx = nPara+1; nParaIdx < nParaCount; nParaIdx++ ) + sal_Int32 nLen = rEE.GetTextLen( nParaIdx ); + if ( nLen ) { - sal_Int32 nLen = rEE.GetTextLen( nParaIdx ); - if ( nLen ) + sal_Int32 nStartIdx, nEndIdx; + GetAttributeRun( nStartIdx, nEndIdx, rEE, nParaIdx, 0 ); + SfxItemSet aSet = rEE.GetAttribs( nParaIdx, 0, 1, GetAttribsFlags::CHARATTRIBS ); + if ( aSet == aCrrntSet ) { - sal_Int32 nStartIdx, nEndIdx; - GetAttributeRun( nStartIdx, nEndIdx, rEE, nParaIdx, 0 ); - SfxItemSet aSet = rEE.GetAttribs( nParaIdx, 0, 1, GetAttribsFlags::CHARATTRIBS ); - if ( aSet == aCrrntSet ) + aEndPos.nPara = nParaIdx; + aEndPos.nIndex = nEndIdx; + if ( aEndPos.nIndex != nLen ) { - aEndPos.nPara = nParaIdx; - aEndPos.nIndex = nEndIdx; - if ( aEndPos.nIndex != nLen ) - { - break; - } + break; } } } } - nStartIndex = 0; - if ( aStartPos.nPara > 0 ) - { - for ( sal_Int32 i = 0; i < aStartPos.nPara; i++ ) - { - nStartIndex += rEE.GetTextLen(i)+1; - } - } - nStartIndex += aStartPos.nIndex; - nEndIndex = 0; - if ( aEndPos.nPara > 0 ) + } + nStartIndex = 0; + if ( aStartPos.nPara > 0 ) + { + for ( sal_Int32 i = 0; i < aStartPos.nPara; i++ ) { - for ( sal_Int32 i = 0; i < aEndPos.nPara; i++ ) - { - nEndIndex += rEE.GetTextLen(i)+1; - } + nStartIndex += rEE.GetTextLen(i)+1; } - nEndIndex += aEndPos.nIndex; } + nStartIndex += aStartPos.nIndex; + nEndIndex = 0; + if ( aEndPos.nPara > 0 ) + { + for ( sal_Int32 i = 0; i < aEndPos.nPara; i++ ) + { + nEndIndex += rEE.GetTextLen(i)+1; + } + } + nEndIndex += aEndPos.nIndex; } Point SvxEditSourceHelper::EEToUserSpace( const Point& rPoint, const Size& rEESize, bool bIsVertical ) diff --git a/editeng/source/uno/unotext.cxx b/editeng/source/uno/unotext.cxx index ad5b26429e1d..53f3088b19be 100644 --- a/editeng/source/uno/unotext.cxx +++ b/editeng/source/uno/unotext.cxx @@ -151,48 +151,48 @@ void GetSelection( struct ESelection& rSel, SvxTextForwarder const * pForwarder void CheckSelection( struct ESelection& rSel, SvxTextForwarder const * pForwarder ) throw() { DBG_ASSERT( pForwarder, "I need a valid SvxTextForwarder!" ); - if( pForwarder ) + if( !pForwarder ) + return; + + if( rSel.nStartPara == EE_PARA_MAX_COUNT ) + { + ::GetSelection( rSel, pForwarder ); + } + else { - if( rSel.nStartPara == EE_PARA_MAX_COUNT ) + ESelection aMaxSelection; + GetSelection( aMaxSelection, pForwarder ); + + // check start position + if( rSel.nStartPara < aMaxSelection.nStartPara ) { - ::GetSelection( rSel, pForwarder ); + rSel.nStartPara = aMaxSelection.nStartPara; + rSel.nStartPos = aMaxSelection.nStartPos; } - else + else if( rSel.nStartPara > aMaxSelection.nEndPara ) { - ESelection aMaxSelection; - GetSelection( aMaxSelection, pForwarder ); - - // check start position - if( rSel.nStartPara < aMaxSelection.nStartPara ) - { - rSel.nStartPara = aMaxSelection.nStartPara; - rSel.nStartPos = aMaxSelection.nStartPos; - } - else if( rSel.nStartPara > aMaxSelection.nEndPara ) - { - rSel.nStartPara = aMaxSelection.nEndPara; - rSel.nStartPos = aMaxSelection.nEndPos; - } - else if( rSel.nStartPos > pForwarder->GetTextLen( rSel.nStartPara ) ) - { - rSel.nStartPos = pForwarder->GetTextLen( rSel.nStartPara ); - } + rSel.nStartPara = aMaxSelection.nEndPara; + rSel.nStartPos = aMaxSelection.nEndPos; + } + else if( rSel.nStartPos > pForwarder->GetTextLen( rSel.nStartPara ) ) + { + rSel.nStartPos = pForwarder->GetTextLen( rSel.nStartPara ); + } - // check end position - if( rSel.nEndPara < aMaxSelection.nStartPara ) - { - rSel.nEndPara = aMaxSelection.nStartPara; - rSel.nEndPos = aMaxSelection.nStartPos; - } - else if( rSel.nEndPara > aMaxSelection.nEndPara ) - { - rSel.nEndPara = aMaxSelection.nEndPara; - rSel.nEndPos = aMaxSelection.nEndPos; - } - else if( rSel.nEndPos > pForwarder->GetTextLen( rSel.nEndPara ) ) - { - rSel.nEndPos = pForwarder->GetTextLen( rSel.nEndPara ); - } + // check end position + if( rSel.nEndPara < aMaxSelection.nStartPara ) + { + rSel.nEndPara = aMaxSelection.nStartPara; + rSel.nEndPos = aMaxSelection.nStartPos; + } + else if( rSel.nEndPara > aMaxSelection.nEndPara ) + { + rSel.nEndPara = aMaxSelection.nEndPara; + rSel.nEndPos = aMaxSelection.nEndPos; + } + else if( rSel.nEndPos > pForwarder->GetTextLen( rSel.nEndPara ) ) + { + rSel.nEndPos = pForwarder->GetTextLen( rSel.nEndPara ); } } } @@ -380,24 +380,24 @@ void SAL_CALL SvxUnoTextRangeBase::setString(const OUString& aString) SolarMutexGuard aGuard; SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : nullptr; - if( pForwarder ) - { - CheckSelection( maSelection, pForwarder ); + if( !pForwarder ) + return; - OUString aConverted(convertLineEnd(aString, LINEEND_LF)); // Simply count the number of line endings + CheckSelection( maSelection, pForwarder ); - pForwarder->QuickInsertText( aConverted, maSelection ); - mpEditSource->UpdateData(); + OUString aConverted(convertLineEnd(aString, LINEEND_LF)); // Simply count the number of line endings - // Adapt selection - //! It would be easier if the EditEngine would return the selection - //! on QuickInsertText... - CollapseToStart(); + pForwarder->QuickInsertText( aConverted, maSelection ); + mpEditSource->UpdateData(); - sal_Int32 nLen = aConverted.getLength(); - if (nLen) - GoRight( nLen, true ); - } + // Adapt selection + //! It would be easier if the EditEngine would return the selection + //! on QuickInsertText... + CollapseToStart(); + + sal_Int32 nLen = aConverted.getLength(); + if (nLen) + GoRight( nLen, true ); } // Interface beans::XPropertySet @@ -751,117 +751,117 @@ void SvxUnoTextRangeBase::_setPropertyValues( const uno::Sequence< OUString >& a SolarMutexGuard aGuard; SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : nullptr; - if( pForwarder ) - { - CheckSelection( maSelection, pForwarder ); + if( !pForwarder ) + return; - ESelection aSel( GetSelection() ); + CheckSelection( maSelection, pForwarder ); - const OUString* pPropertyNames = aPropertyNames.getConstArray(); - const uno::Any* pValues = aValues.getConstArray(); - sal_Int32 nCount = aPropertyNames.getLength(); + ESelection aSel( GetSelection() ); - sal_Int32 nEndPara = nPara; - sal_Int32 nTempPara = nPara; + const OUString* pPropertyNames = aPropertyNames.getConstArray(); + const uno::Any* pValues = aValues.getConstArray(); + sal_Int32 nCount = aPropertyNames.getLength(); - if( nTempPara == -1 ) - { - nTempPara = aSel.nStartPara; - nEndPara = aSel.nEndPara; - } + sal_Int32 nEndPara = nPara; + sal_Int32 nTempPara = nPara; + + if( nTempPara == -1 ) + { + nTempPara = aSel.nStartPara; + nEndPara = aSel.nEndPara; + } - std::unique_ptr<SfxItemSet> pOldAttrSet; - std::unique_ptr<SfxItemSet> pNewAttrSet; + std::unique_ptr<SfxItemSet> pOldAttrSet; + std::unique_ptr<SfxItemSet> pNewAttrSet; - std::unique_ptr<SfxItemSet> pOldParaSet; - std::unique_ptr<SfxItemSet> pNewParaSet; + std::unique_ptr<SfxItemSet> pOldParaSet; + std::unique_ptr<SfxItemSet> pNewParaSet; - for( ; nCount; nCount--, pPropertyNames++, pValues++ ) + for( ; nCount; nCount--, pPropertyNames++, pValues++ ) + { + const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry( *pPropertyNames ); + + if( pMap ) { - const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry( *pPropertyNames ); + bool bParaAttrib = (pMap->nWID >= EE_PARA_START) && ( pMap->nWID <= EE_PARA_END ); - if( pMap ) + if( (nPara == -1) && !bParaAttrib ) { - bool bParaAttrib = (pMap->nWID >= EE_PARA_START) && ( pMap->nWID <= EE_PARA_END ); - - if( (nPara == -1) && !bParaAttrib ) + if( nullptr == pNewAttrSet ) { - if( nullptr == pNewAttrSet ) - { - const SfxItemSet aSet( pForwarder->GetAttribs( aSel ) ); - pOldAttrSet.reset(new SfxItemSet( aSet )); - pNewAttrSet.reset(new SfxItemSet( *pOldAttrSet->GetPool(), pOldAttrSet->GetRanges() )); - } + const SfxItemSet aSet( pForwarder->GetAttribs( aSel ) ); + pOldAttrSet.reset(new SfxItemSet( aSet )); + pNewAttrSet.reset(new SfxItemSet( *pOldAttrSet->GetPool(), pOldAttrSet->GetRanges() )); + } - setPropertyValue( pMap, *pValues, GetSelection(), *pOldAttrSet, *pNewAttrSet ); + setPropertyValue( pMap, *pValues, GetSelection(), *pOldAttrSet, *pNewAttrSet ); - if( pMap->nWID >= EE_ITEMS_START && pMap->nWID <= EE_ITEMS_END ) + if( pMap->nWID >= EE_ITEMS_START && pMap->nWID <= EE_ITEMS_END ) + { + const SfxPoolItem* pItem; + if( pNewAttrSet->GetItemState( pMap->nWID, true, &pItem ) == SfxItemState::SET ) { - const SfxPoolItem* pItem; - if( pNewAttrSet->GetItemState( pMap->nWID, true, &pItem ) == SfxItemState::SET ) - { - pOldAttrSet->Put( *pItem ); - } + pOldAttrSet->Put( *pItem ); } } - else + } + else + { + if( nullptr == pNewParaSet ) { - if( nullptr == pNewParaSet ) - { - const SfxItemSet & rSet = pForwarder->GetParaAttribs( nTempPara ); - pOldParaSet.reset(new SfxItemSet( rSet )); - pNewParaSet.reset(new SfxItemSet( *pOldParaSet->GetPool(), pOldParaSet->GetRanges() )); - } + const SfxItemSet & rSet = pForwarder->GetParaAttribs( nTempPara ); + pOldParaSet.reset(new SfxItemSet( rSet )); + pNewParaSet.reset(new SfxItemSet( *pOldParaSet->GetPool(), pOldParaSet->GetRanges() )); + } - setPropertyValue( pMap, *pValues, GetSelection(), *pOldParaSet, *pNewParaSet ); + setPropertyValue( pMap, *pValues, GetSelection(), *pOldParaSet, *pNewParaSet ); - if( pMap->nWID >= EE_ITEMS_START && pMap->nWID <= EE_ITEMS_END ) + if( pMap->nWID >= EE_ITEMS_START && pMap->nWID <= EE_ITEMS_END ) + { + const SfxPoolItem* pItem; + if( pNewParaSet->GetItemState( pMap->nWID, true, &pItem ) == SfxItemState::SET ) { - const SfxPoolItem* pItem; - if( pNewParaSet->GetItemState( pMap->nWID, true, &pItem ) == SfxItemState::SET ) - { - pOldParaSet->Put( *pItem ); - } + pOldParaSet->Put( *pItem ); } - } + } } + } - bool bNeedsUpdate = false; + bool bNeedsUpdate = false; - if( pNewParaSet ) + if( pNewParaSet ) + { + if( pNewParaSet->Count() ) { - if( pNewParaSet->Count() ) + while( nTempPara <= nEndPara ) { - while( nTempPara <= nEndPara ) - { - SfxItemSet aSet( pForwarder->GetParaAttribs( nTempPara ) ); - aSet.Put( *pNewParaSet ); - pForwarder->SetParaAttribs( nTempPara, aSet ); - nTempPara++; - } - bNeedsUpdate = true; + SfxItemSet aSet( pForwarder->GetParaAttribs( nTempPara ) ); + aSet.Put( *pNewParaSet ); + pForwarder->SetParaAttribs( nTempPara, aSet ); + nTempPara++; } - - pNewParaSet.reset(); - pOldParaSet.reset(); + bNeedsUpdate = true; } - if( pNewAttrSet ) + pNewParaSet.reset(); + pOldParaSet.reset(); + } + + if( pNewAttrSet ) + { + if( pNewAttrSet->Count() ) { - if( pNewAttrSet->Count() ) - { - pForwarder->QuickSetAttribs( *pNewAttrSet, GetSelection() ); - bNeedsUpdate = true; - } - pNewAttrSet.reset(); - pOldAttrSet.reset(); + pForwarder->QuickSetAttribs( *pNewAttrSet, GetSelection() ); + bNeedsUpdate = true; } - - if( bNeedsUpdate ) - GetEditSource()->UpdateData(); + pNewAttrSet.reset(); + pOldAttrSet.reset(); } + + if( bNeedsUpdate ) + GetEditSource()->UpdateData(); } uno::Sequence< uno::Any > SAL_CALL SvxUnoTextRangeBase::getPropertyValues( const uno::Sequence< OUString >& aPropertyNames ) @@ -1413,19 +1413,18 @@ void SvxUnoTextRangeBase::GotoEnd(bool Expand) throw() CheckSelection( maSelection, mpEditSource.get() ); SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : nullptr; - if( pForwarder ) - { + if( !pForwarder ) + return; - sal_Int32 nPar = pForwarder->GetParagraphCount(); - if (nPar) - --nPar; + sal_Int32 nPar = pForwarder->GetParagraphCount(); + if (nPar) + --nPar; - maSelection.nEndPara = nPar; - maSelection.nEndPos = pForwarder->GetTextLen( nPar ); + maSelection.nEndPara = nPar; + maSelection.nEndPos = pForwarder->GetTextLen( nPar ); - if (!Expand) - CollapseToEnd(); - } + if (!Expand) + CollapseToEnd(); } // lang::XServiceInfo @@ -1742,20 +1741,20 @@ void SAL_CALL SvxUnoTextBase::insertString( const uno::Reference< text::XTextRan } SvxUnoTextRangeBase* pRange = comphelper::getUnoTunnelImplementation<SvxUnoTextRange>( xRange ); - if(pRange) - { - // setString on SvxUnoTextRangeBase instead of itself QuickInsertText - // and UpdateData, so that the selection will be adjusted to - // SvxUnoTextRangeBase. Actually all cursor objects of this Text must - // to be statement to be adapted! - - if (!bAbsorb) // do not replace -> append on tail - pRange->CollapseToEnd(); + if(!pRange) + return; - pRange->setString( aString ); + // setString on SvxUnoTextRangeBase instead of itself QuickInsertText + // and UpdateData, so that the selection will be adjusted to + // SvxUnoTextRangeBase. Actually all cursor objects of this Text must + // to be statement to be adapted! + if (!bAbsorb) // do not replace -> append on tail pRange->CollapseToEnd(); - } + + pRange->setString( aString ); + + pRange->CollapseToEnd(); } void SAL_CALL SvxUnoTextBase::insertControlCharacter( const uno::Reference< text::XTextRange >& xRange, sal_Int16 nControlCharacter, sal_Bool bAbsorb ) @@ -1764,83 +1763,83 @@ void SAL_CALL SvxUnoTextBase::insertControlCharacter( const uno::Reference< text SvxTextForwarder* pForwarder = GetEditSource() ? GetEditSource()->GetTextForwarder() : nullptr; - if( pForwarder ) + if( !pForwarder ) + return; + + ESelection aSelection; + ::GetSelection( aSelection, pForwarder ); + SetSelection( aSelection ); + + switch( nControlCharacter ) { - ESelection aSelection; - ::GetSelection( aSelection, pForwarder ); - SetSelection( aSelection ); + case text::ControlCharacter::PARAGRAPH_BREAK: + { + const OUString aText( u'\x000D' ); // '\r' does not work on Mac + insertString( xRange, aText, bAbsorb ); - switch( nControlCharacter ) - { - case text::ControlCharacter::PARAGRAPH_BREAK: + return; + } + case text::ControlCharacter::LINE_BREAK: + { + SvxUnoTextRangeBase* pRange = comphelper::getUnoTunnelImplementation<SvxUnoTextRange>( xRange ); + if(pRange) { - const OUString aText( u'\x000D' ); // '\r' does not work on Mac - insertString( xRange, aText, bAbsorb ); + ESelection aRange = pRange->GetSelection(); - return; - } - case text::ControlCharacter::LINE_BREAK: - { - SvxUnoTextRangeBase* pRange = comphelper::getUnoTunnelImplementation<SvxUnoTextRange>( xRange ); - if(pRange) + if( bAbsorb ) { - ESelection aRange = pRange->GetSelection(); + pForwarder->QuickInsertText( "", aRange ); - if( bAbsorb ) - { - pForwarder->QuickInsertText( "", aRange ); - - aRange.nEndPos = aRange.nStartPos; - aRange.nEndPara = aRange.nStartPara; - } - else - { - aRange.nStartPara = aRange.nEndPara; - aRange.nStartPos = aRange.nEndPos; - } + aRange.nEndPos = aRange.nStartPos; + aRange.nEndPara = aRange.nStartPara; + } + else + { + aRange.nStartPara = aRange.nEndPara; + aRange.nStartPos = aRange.nEndPos; + } - pForwarder->QuickInsertLineBreak( aRange ); - GetEditSource()->UpdateData(); + pForwarder->QuickInsertLineBreak( aRange ); + GetEditSource()->UpdateData(); - aRange.nEndPos += 1; - if( !bAbsorb ) - aRange.nStartPos += 1; + aRange.nEndPos += 1; + if( !bAbsorb ) + aRange.nStartPos += 1; - pRange->SetSelection( aRange ); - } - return; + pRange->SetSelection( aRange ); } - case text::ControlCharacter::APPEND_PARAGRAPH: + return; + } + case text::ControlCharacter::APPEND_PARAGRAPH: + { + SvxUnoTextRangeBase* pRange = comphelper::getUnoTunnelImplementation<SvxUnoTextRange>( xRange ); + if(pRange) { - SvxUnoTextRangeBase* pRange = comphelper::getUnoTunnelImplementation<SvxUnoTextRange>( xRange ); - if(pRange) - { - ESelection aRange = pRange->GetSelection(); + ESelection aRange = pRange->GetSelection(); // ESelection aOldSelection = aRange; - aRange.nStartPos = pForwarder->GetTextLen( aRange.nStartPara ); + aRange.nStartPos = pForwarder->GetTextLen( aRange.nStartPara ); - aRange.nEndPara = aRange.nStartPara; - aRange.nEndPos = aRange.nStartPos; + aRange.nEndPara = aRange.nStartPara; + aRange.nEndPos = aRange.nStartPos; - pRange->SetSelection( aRange ); - const OUString aText( u'\x000D' ); // '\r' does not work on Mac - pRange->setString( aText ); + pRange->SetSelection( aRange ); + const OUString aText( u'\x000D' ); // '\r' does not work on Mac + pRange->setString( aText ); - aRange.nStartPos = 0; - aRange.nStartPara += 1; - aRange.nEndPos = 0; - aRange.nEndPara += 1; + aRange.nStartPos = 0; + aRange.nStartPara += 1; + aRange.nEndPos = 0; + aRange.nEndPara += 1; - pRange->SetSelection( aRange ); + pRange->SetSelection( aRange ); - return; - } - [[fallthrough]]; - } - default: - throw lang::IllegalArgumentException(); + return; } + [[fallthrough]]; + } + default: + throw lang::IllegalArgumentException(); } } diff --git a/editeng/source/uno/unotext2.cxx b/editeng/source/uno/unotext2.cxx index 933c95002513..eb0d377140c8 100644 --- a/editeng/source/uno/unotext2.cxx +++ b/editeng/source/uno/unotext2.cxx @@ -382,42 +382,42 @@ SvxUnoTextRangeEnumeration::SvxUnoTextRangeEnumeration(const SvxUnoTextBase& rPa if (rParentText.GetEditSource()) mpEditSource = rParentText.GetEditSource()->Clone(); - if( mpEditSource && mpEditSource->GetTextForwarder() && (nParagraph == rSel.nStartPara && nParagraph == rSel.nEndPara) ) + if( !(mpEditSource && mpEditSource->GetTextForwarder() && (nParagraph == rSel.nStartPara && nParagraph == rSel.nEndPara)) ) + return; + + std::vector<sal_Int32> aPortions; + mpEditSource->GetTextForwarder()->GetPortions( nParagraph, aPortions ); + for( size_t aPortionIndex = 0; aPortionIndex < aPortions.size(); aPortionIndex++ ) { - std::vector<sal_Int32> aPortions; - mpEditSource->GetTextForwarder()->GetPortions( nParagraph, aPortions ); - for( size_t aPortionIndex = 0; aPortionIndex < aPortions.size(); aPortionIndex++ ) + sal_uInt16 nStartPos = 0; + if ( aPortionIndex > 0 ) + nStartPos = aPortions.at( aPortionIndex - 1 ); + if( nStartPos > rSel.nEndPos ) + continue; + sal_uInt16 nEndPos = aPortions.at( aPortionIndex ); + if( nEndPos < rSel.nStartPos ) + continue; + + nStartPos = std::max<int>(nStartPos, rSel.nStartPos); + nEndPos = std::min<sal_uInt16>(nEndPos, rSel.nEndPos); + ESelection aSel( nParagraph, nStartPos, nParagraph, nEndPos ); + + const SvxUnoTextRangeBaseVec& rRanges( mpEditSource->getRanges() ); + SvxUnoTextRange* pRange = nullptr; + for (auto const& elemRange : rRanges) { - sal_uInt16 nStartPos = 0; - if ( aPortionIndex > 0 ) - nStartPos = aPortions.at( aPortionIndex - 1 ); - if( nStartPos > rSel.nEndPos ) - continue; - sal_uInt16 nEndPos = aPortions.at( aPortionIndex ); - if( nEndPos < rSel.nStartPos ) - continue; - - nStartPos = std::max<int>(nStartPos, rSel.nStartPos); - nEndPos = std::min<sal_uInt16>(nEndPos, rSel.nEndPos); - ESelection aSel( nParagraph, nStartPos, nParagraph, nEndPos ); - - const SvxUnoTextRangeBaseVec& rRanges( mpEditSource->getRanges() ); - SvxUnoTextRange* pRange = nullptr; - for (auto const& elemRange : rRanges) - { - if (pRange) - break; - SvxUnoTextRange* pIterRange = dynamic_cast< SvxUnoTextRange* >( elemRange ); - if( pIterRange && pIterRange->mbPortion && (aSel == pIterRange->maSelection) ) - pRange = pIterRange; - } - if( pRange == nullptr ) - { - pRange = new SvxUnoTextRange( rParentText, true ); - pRange->SetSelection( aSel ); - } - maPortions.emplace_back(pRange ); + if (pRange) + break; + SvxUnoTextRange* pIterRange = dynamic_cast< SvxUnoTextRange* >( elemRange ); + if( pIterRange && pIterRange->mbPortion && (aSel == pIterRange->maSelection) ) + pRange = pIterRange; + } + if( pRange == nullptr ) + { + pRange = new SvxUnoTextRange( rParentText, true ); + pRange->SetSelection( aSel ); } + maPortions.emplace_back(pRange ); } } @@ -589,19 +589,19 @@ void SAL_CALL SvxUnoTextCursor::gotoRange( const uno::Reference< text::XTextRang SvxUnoTextRangeBase* pRange = comphelper::getUnoTunnelImplementation<SvxUnoTextRangeBase>( xRange ); - if( pRange ) - { - ESelection aNewSel = pRange->GetSelection(); + if( !pRange ) + return; - if( bExpand ) - { - const ESelection& rOldSel = GetSelection(); - aNewSel.nStartPara = rOldSel.nStartPara; - aNewSel.nStartPos = rOldSel.nStartPos; - } + ESelection aNewSel = pRange->GetSelection(); - SetSelection( aNewSel ); + if( bExpand ) + { + const ESelection& rOldSel = GetSelection(); + aNewSel.nStartPara = rOldSel.nStartPara; + aNewSel.nStartPos = rOldSel.nStartPos; } + + SetSelection( aNewSel ); } // text::XTextRange (rest in SvxTextRange) |