sw/source/core/access/accpara.cxx | 241 ++++++++++++++++++-------------------- sw/source/core/access/accpara.hxx | 2 sw/source/core/crsr/crsrsh.cxx | 4 3 files changed, 118 insertions(+), 129 deletions(-)
New commits: commit de6fdfdf976215d2965aecb69ab2dae22c07f6fb Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Thu Aug 14 12:30:26 2025 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Thu Aug 14 17:07:20 2025 +0200 sw: Drop unnecessary casting in SwCursorShell::DestroyCursor Presumably unnecessary since commit 8e156f009e29a90883c2536943f338be163dad45 Date: Thu Apr 5 13:18:07 2018 +0200 provide overrides of GetNext/GetPrev in SwPaM subclasses so we don't need to cast at the call sites. Change-Id: I7244a75aca7ed29454ba8c26416f65d5eb3d2a52 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189584 Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> Tested-by: Jenkins diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx index 8908daefa1a1..e609d341421a 100644 --- a/sw/source/core/crsr/crsrsh.cxx +++ b/sw/source/core/crsr/crsrsh.cxx @@ -161,9 +161,9 @@ void SwCursorShell::DestroyCursor() return; SwCallLink aLk( *this ); // watch Cursor-Moves - SwCursor* pNextCursor = static_cast<SwCursor*>(m_pCurrentCursor->GetNext()); + SwShellCursor* pNextCursor = m_pCurrentCursor->GetNext(); delete m_pCurrentCursor; - m_pCurrentCursor = dynamic_cast<SwShellCursor*>(pNextCursor); + m_pCurrentCursor = pNextCursor; UpdateCursor(); } commit 21dc8b065eedbf591215d99916059803d5df7c06 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Thu Aug 14 12:22:10 2025 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Thu Aug 14 17:07:15 2025 +0200 sw a11y: Flatten SwAccessibleParagraph::GetSelectionAtIndex Return early if pCursor is null. (`git show --ignore-space-change` helps see the "actual change" more easily.) Change-Id: Ia3b602eb4ebee50b759b0bb30a3c4dce06a3a57e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189583 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/sw/source/core/access/accpara.cxx b/sw/source/core/access/accpara.cxx index e22b7530a6d6..7908cb54a7c7 100644 --- a/sw/source/core/access/accpara.cxx +++ b/sw/source/core/access/accpara.cxx @@ -3123,134 +3123,133 @@ bool SwAccessibleParagraph::GetSelectionAtIndex( // get the selection, and test whether it affects our text node SwPaM* pCursor = GetCursor( true ); - if( pCursor != nullptr ) + if (!pCursor) + return false; + + // get SwPosition for my node + const SwTextFrame* const pFrame = GetTextFrame(); + SwNodeOffset nFirstNode(pFrame->GetTextNodeFirst()->GetIndex()); + SwNodeOffset nLastNode; + if (sw::MergedPara const*const pMerged = pFrame->GetMergedPara()) { - // get SwPosition for my node - const SwTextFrame* const pFrame = GetTextFrame(); - SwNodeOffset nFirstNode(pFrame->GetTextNodeFirst()->GetIndex()); - SwNodeOffset nLastNode; - if (sw::MergedPara const*const pMerged = pFrame->GetMergedPara()) - { - nLastNode = pMerged->pLastNode->GetIndex(); - } - else - { - nLastNode = nFirstNode; - } + nLastNode = pMerged->pLastNode->GetIndex(); + } + else + { + nLastNode = nFirstNode; + } - // iterate over ring - for(SwPaM& rTmpCursor : pCursor->GetRingContainer()) + // iterate over ring + for(SwPaM& rTmpCursor : pCursor->GetRingContainer()) + { + // ignore, if no mark + if( rTmpCursor.HasMark() ) { - // ignore, if no mark - if( rTmpCursor.HasMark() ) + // check whether frame's node(s) are 'inside' pCursor + SwPosition* pStart = rTmpCursor.Start(); + SwNodeOffset nStartIndex = pStart->GetNodeIndex(); + SwPosition* pEnd = rTmpCursor.End(); + SwNodeOffset nEndIndex = pEnd->GetNodeIndex(); + if ((nStartIndex <= nLastNode) && (nFirstNode <= nEndIndex)) { - // check whether frame's node(s) are 'inside' pCursor - SwPosition* pStart = rTmpCursor.Start(); - SwNodeOffset nStartIndex = pStart->GetNodeIndex(); - SwPosition* pEnd = rTmpCursor.End(); - SwNodeOffset nEndIndex = pEnd->GetNodeIndex(); - if ((nStartIndex <= nLastNode) && (nFirstNode <= nEndIndex)) + if (!pSelection || *pSelection == 0) { - if (!pSelection || *pSelection == 0) - { - // translate start and end positions + // translate start and end positions - // start position - sal_Int32 nLocalStart = -1; - if (nStartIndex < nFirstNode) + // start position + sal_Int32 nLocalStart = -1; + if (nStartIndex < nFirstNode) + { + // selection starts in previous node: + // then our local selection starts with the paragraph + nLocalStart = 0; + } + else + { + assert(FrameContainsNode(*pFrame, nStartIndex)); + + // selection starts in this node: + // then check whether it's before or inside our part of + // the paragraph, and if so, get the proper position + const TextFrameIndex nCoreStart = + pFrame->MapModelToViewPos(*pStart); + if( nCoreStart < + GetPortionData().GetFirstValidCorePosition() ) { - // selection starts in previous node: - // then our local selection starts with the paragraph nLocalStart = 0; } - else + else if( nCoreStart <= + GetPortionData().GetLastValidCorePosition() ) { - assert(FrameContainsNode(*pFrame, nStartIndex)); - - // selection starts in this node: - // then check whether it's before or inside our part of - // the paragraph, and if so, get the proper position - const TextFrameIndex nCoreStart = - pFrame->MapModelToViewPos(*pStart); - if( nCoreStart < - GetPortionData().GetFirstValidCorePosition() ) - { - nLocalStart = 0; - } - else if( nCoreStart <= - GetPortionData().GetLastValidCorePosition() ) - { - SAL_WARN_IF( - !GetPortionData().IsValidCorePosition( - nCoreStart), - "sw.a11y", - "problem determining valid core position"); - - nLocalStart = - GetPortionData().GetAccessiblePosition( - nCoreStart ); - } + SAL_WARN_IF( + !GetPortionData().IsValidCorePosition( + nCoreStart), + "sw.a11y", + "problem determining valid core position"); + + nLocalStart = + GetPortionData().GetAccessiblePosition( + nCoreStart ); } + } - // end position - sal_Int32 nLocalEnd = -1; - if (nLastNode < nEndIndex) + // end position + sal_Int32 nLocalEnd = -1; + if (nLastNode < nEndIndex) + { + // selection ends in following node: + // then our local selection extends to the end + nLocalEnd = GetPortionData().GetAccessibleString(). + getLength(); + } + else + { + assert(FrameContainsNode(*pFrame, nEndIndex)); + + // selection ends in this node: then select everything + // before our part of the node + const TextFrameIndex nCoreEnd = + pFrame->MapModelToViewPos(*pEnd); + if( nCoreEnd > + GetPortionData().GetLastValidCorePosition() ) { - // selection ends in following node: - // then our local selection extends to the end + // selection extends beyond out part of this para nLocalEnd = GetPortionData().GetAccessibleString(). - getLength(); + getLength(); } - else + else if( nCoreEnd >= + GetPortionData().GetFirstValidCorePosition() ) { - assert(FrameContainsNode(*pFrame, nEndIndex)); - - // selection ends in this node: then select everything - // before our part of the node - const TextFrameIndex nCoreEnd = - pFrame->MapModelToViewPos(*pEnd); - if( nCoreEnd > - GetPortionData().GetLastValidCorePosition() ) - { - // selection extends beyond out part of this para - nLocalEnd = GetPortionData().GetAccessibleString(). - getLength(); - } - else if( nCoreEnd >= - GetPortionData().GetFirstValidCorePosition() ) - { - // selection is inside our part of this para - SAL_WARN_IF( - !GetPortionData().IsValidCorePosition( - nCoreEnd), - "sw.a11y", - "problem determining valid core position"); - - nLocalEnd = GetPortionData().GetAccessiblePosition( - nCoreEnd ); - } + // selection is inside our part of this para + SAL_WARN_IF( + !GetPortionData().IsValidCorePosition( + nCoreEnd), + "sw.a11y", + "problem determining valid core position"); + + nLocalEnd = GetPortionData().GetAccessiblePosition( + nCoreEnd ); } + } - if( ( nLocalStart != -1 ) && ( nLocalEnd != -1 ) ) - { - nStart = nLocalStart; - nEnd = nLocalEnd; - bRet = true; - } - } // if hit the index - else + if( ( nLocalStart != -1 ) && ( nLocalEnd != -1 ) ) { - --*pSelection; + nStart = nLocalStart; + nEnd = nLocalEnd; + bRet = true; } + } // if hit the index + else + { + --*pSelection; } - // else: this PaM doesn't point to this paragraph } - // else: this PaM is collapsed and doesn't select anything - if(bRet) - break; + // else: this PaM doesn't point to this paragraph } + // else: this PaM is collapsed and doesn't select anything + if(bRet) + break; } - // else: nocursor -> no selection if (pSelection && bRet) { commit 0dd4e9697dd5668df7c38b3085ae70b760ceccbe Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Thu Aug 14 12:12:46 2025 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Thu Aug 14 17:07:08 2025 +0200 sw a11y: Simplify SwAccessibleParagraph::IsValidRange use Instead of calling `GetString().getLenght()` in all callers to pass it as an argument, call it inside of the method and drop the param. Change-Id: Ieaf7250ae545349c1f3ca1816e3a8dec01cbc819 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189582 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/sw/source/core/access/accpara.cxx b/sw/source/core/access/accpara.cxx index c54350dd3126..e22b7530a6d6 100644 --- a/sw/source/core/access/accpara.cxx +++ b/sw/source/core/access/accpara.cxx @@ -421,10 +421,9 @@ rtl::Reference<SwXTextPortion> SwAccessibleParagraph::CreateUnoPortion( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) { - OSL_ENSURE( (IsValidChar(nStartIndex, GetString().getLength()) && - (nEndIndex == -1)) || - IsValidRange(nStartIndex, nEndIndex, GetString().getLength()), - "please check parameters before calling this method" ); + OSL_ENSURE((IsValidChar(nStartIndex, GetString().getLength()) && (nEndIndex == -1)) + || IsValidRange(nStartIndex, nEndIndex), + "please check parameters before calling this method"); const TextFrameIndex nStart = GetPortionData().GetCoreViewPosition(nStartIndex); const TextFrameIndex nEnd = (nEndIndex == -1) @@ -457,9 +456,9 @@ bool SwAccessibleParagraph::IsValidPosition( return (nPos >= 0) && (nPos <= nLength); } -bool SwAccessibleParagraph::IsValidRange( - sal_Int32 nBegin, sal_Int32 nEnd, sal_Int32 nLength) +bool SwAccessibleParagraph::IsValidRange(sal_Int32 nBegin, sal_Int32 nEnd) { + const sal_Int32 nLength = GetString().getLength(); return IsValidPosition(nBegin, nLength) && IsValidPosition(nEnd, nLength); } @@ -2014,8 +2013,7 @@ sal_Bool SwAccessibleParagraph::setSelection( sal_Int32 nStartIndex, sal_Int32 n ThrowIfDisposed(); // parameter checking - sal_Int32 nLength = GetString().getLength(); - if ( ! IsValidRange( nStartIndex, nEndIndex, nLength ) ) + if (!IsValidRange(nStartIndex, nEndIndex)) { throw lang::IndexOutOfBoundsException(); } @@ -2057,13 +2055,11 @@ OUString SwAccessibleParagraph::getTextRange( ThrowIfDisposed(); - OUString sText( GetString() ); - - if ( !IsValidRange( nStartIndex, nEndIndex, sText.getLength() ) ) + if (!IsValidRange(nStartIndex, nEndIndex)) throw lang::IndexOutOfBoundsException(); OrderRange( nStartIndex, nEndIndex ); - return sText.copy(nStartIndex, nEndIndex-nStartIndex ); + return GetString().copy(nStartIndex, nEndIndex - nStartIndex); } TextSegment SwAccessibleParagraph::getTextAtIndex(sal_Int32 nIndex, sal_Int16 nTextType) @@ -2292,8 +2288,7 @@ sal_Bool SwAccessibleParagraph::scrollSubstringTo( sal_Int32 nStartIndex, ThrowIfDisposed(); // parameter checking - sal_Int32 nLength = GetString().getLength(); - if ( ! IsValidRange( nStartIndex, nEndIndex, nLength ) ) + if (!IsValidRange(nStartIndex, nEndIndex)) throw lang::IndexOutOfBoundsException(); vcl::Window *pWin = GetWindow(); @@ -2398,9 +2393,7 @@ sal_Bool SwAccessibleParagraph::replaceText( ThrowIfDisposed(); - const OUString& rText = GetString(); - - if( !IsValidRange( nStartIndex, nEndIndex, rText.getLength() ) ) + if (!IsValidRange(nStartIndex, nEndIndex)) throw lang::IndexOutOfBoundsException(); if( !IsEditableState() ) @@ -2445,9 +2438,7 @@ sal_Bool SwAccessibleParagraph::setAttributes( ThrowIfDisposed(); - const OUString& rText = GetString(); - - if( ! IsValidRange( nStartIndex, nEndIndex, rText.getLength() ) ) + if (!IsValidRange(nStartIndex, nEndIndex)) throw lang::IndexOutOfBoundsException(); if( !IsEditableState() ) @@ -2887,8 +2878,7 @@ sal_Int32 SAL_CALL SwAccessibleParagraph::addSelection(sal_Int32 startOffset, sa ThrowIfDisposed(); // parameter checking - sal_Int32 nLength = GetString().getLength(); - if ( ! IsValidRange( startOffset, endOffset, nLength ) ) + if (!IsValidRange(startOffset, endOffset)) { throw lang::IndexOutOfBoundsException(); } diff --git a/sw/source/core/access/accpara.hxx b/sw/source/core/access/accpara.hxx index 268f2d2f01cd..81607e3f9cc7 100644 --- a/sw/source/core/access/accpara.hxx +++ b/sw/source/core/access/accpara.hxx @@ -126,7 +126,7 @@ class SwAccessibleParagraph : static bool IsValidPosition(sal_Int32 nPos, sal_Int32 nLength); // is nBegin...nEnd a valid range? (nEnd points past the last character) - static bool IsValidRange(sal_Int32 nBegin, sal_Int32 nEnd, sal_Int32 nLength); + bool IsValidRange(sal_Int32 nBegin, sal_Int32 nEnd); // Ensure ordered range (i.e. nBegin is smaller then nEnd) static void OrderRange(sal_Int32& nBegin, sal_Int32& nEnd)