diff options
author | Michael Stahl <Michael.Stahl@cib.de> | 2018-10-08 15:31:02 +0200 |
---|---|---|
committer | Michael Stahl <Michael.Stahl@cib.de> | 2018-11-15 15:09:57 +0100 |
commit | 517eb22452e6b51764df400b18dcdf9c3d6007e7 (patch) | |
tree | f0e5937178d8b6b62bedb242f85ddbf4853cb4bc /sw | |
parent | f1d66b18ca7703452ce5a2735eb5763bd42ed7a1 (diff) |
sw_redlinehide_3: convert selection functions of SwAccessibleParagraph
Do i smell copypasta?
Change-Id: I5450118b58540eee5ac8ff2e941d005fda4572c3
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/core/access/accpara.cxx | 82 |
1 files changed, 50 insertions, 32 deletions
diff --git a/sw/source/core/access/accpara.cxx b/sw/source/core/access/accpara.cxx index 7b2df09d37ee..c94abfd13a61 100644 --- a/sw/source/core/access/accpara.cxx +++ b/sw/source/core/access/accpara.cxx @@ -207,8 +207,17 @@ bool SwAccessibleParagraph::GetSelection( if( pCursor != nullptr ) { // get SwPosition for my node - const SwTextNode* pNode = GetTextNode(); - sal_uLong nHere = pNode->GetIndex(); + SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(GetFrame())); + sal_uLong nFirstNode(pFrame->GetTextNodeFirst()->GetIndex()); + sal_uLong nLastNode; + if (sw::MergedPara const*const pMerged = pFrame->GetMergedPara()) + { + nLastNode = pMerged->pLastNode->GetIndex(); + } + else + { + nLastNode = nFirstNode; + } // iterate over ring for(SwPaM& rTmpCursor : pCursor->GetRingContainer()) @@ -216,19 +225,18 @@ bool SwAccessibleParagraph::GetSelection( // ignore, if no mark if( rTmpCursor.HasMark() ) { - // check whether nHere is 'inside' pCursor + // check whether frame's node(s) are 'inside' pCursor SwPosition* pStart = rTmpCursor.Start(); sal_uLong nStartIndex = pStart->nNode.GetIndex(); SwPosition* pEnd = rTmpCursor.End(); sal_uLong nEndIndex = pEnd->nNode.GetIndex(); - if( ( nHere >= nStartIndex ) && - ( nHere <= nEndIndex ) ) + if ((nStartIndex <= nLastNode) && (nFirstNode <= nEndIndex)) { // translate start and end positions // start position sal_Int32 nLocalStart = -1; - if( nHere > nStartIndex ) + if (nStartIndex < nFirstNode) { // selection starts in previous node: // then our local selection starts with the paragraph @@ -236,13 +244,13 @@ bool SwAccessibleParagraph::GetSelection( } else { - OSL_ENSURE( nHere == nStartIndex, - "miscalculated index" ); + 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 sal_Int32 nCoreStart = pStart->nContent.GetIndex(); + const TextFrameIndex nCoreStart = + pFrame->MapModelToViewPos(*pStart); if( nCoreStart < GetPortionData().GetFirstValidCorePosition() ) { @@ -264,7 +272,7 @@ bool SwAccessibleParagraph::GetSelection( // end position sal_Int32 nLocalEnd = -1; - if( nHere < nEndIndex ) + if (nLastNode < nEndIndex) { // selection ends in following node: // then our local selection extends to the end @@ -273,12 +281,12 @@ bool SwAccessibleParagraph::GetSelection( } else { - OSL_ENSURE( nHere == nEndIndex, - "miscalculated index" ); + assert(FrameContainsNode(*pFrame, nEndIndex)); // selection ends in this node: then select everything // before our part of the node - const sal_Int32 nCoreEnd = pEnd->nContent.GetIndex(); + const TextFrameIndex nCoreEnd = + pFrame->MapModelToViewPos(*pEnd); if( nCoreEnd > GetPortionData().GetLastValidCorePosition() ) { @@ -2473,13 +2481,12 @@ sal_Bool SwAccessibleParagraph::setSelection( sal_Int32 nStartIndex, sal_Int32 n if( pCursorShell != nullptr ) { // create pam for selection - SwTextNode* pNode = const_cast<SwTextNode*>( GetTextNode() ); - SwIndex aIndex(pNode, GetPortionData().GetCoreViewPosition(nStartIndex)); - SwPosition aStartPos( *pNode, aIndex ); - SwPaM aPaM( aStartPos ); + SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(GetFrame())); + TextFrameIndex const nStart(GetPortionData().GetCoreViewPosition(nStartIndex)); + TextFrameIndex const nEnd(GetPortionData().GetCoreViewPosition(nEndIndex)); + SwPaM aPaM(pFrame->MapViewToModelPos(nStart)); aPaM.SetMark(); - aPaM.GetPoint()->nContent = - GetPortionData().GetCoreViewPosition(nEndIndex); + *aPaM.GetPoint() = pFrame->MapViewToModelPos(nEnd); // set PaM at cursor shell bRet = Select( aPaM ); @@ -3340,10 +3347,11 @@ sal_Int32 SAL_CALL SwAccessibleParagraph::addSelection( sal_Int32, sal_Int32 sta { // create pam for selection pCursorShell->StartAction(); + SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(GetFrame())); SwPaM* aPaM = pCursorShell->CreateCursor(); aPaM->SetMark(); - aPaM->GetPoint()->nContent = GetPortionData().GetCoreViewPosition(startOffset); - aPaM->GetMark()->nContent = GetPortionData().GetCoreViewPosition(endOffset); + *aPaM->GetPoint() = pFrame->MapViewToModelPos(GetPortionData().GetCoreViewPosition(startOffset)); + *aPaM->GetMark() = pFrame->MapViewToModelPos(GetPortionData().GetCoreViewPosition(endOffset)); pCursorShell->EndAction(); } @@ -3545,8 +3553,17 @@ bool SwAccessibleParagraph::GetSelectionAtIndex( if( pCursor != nullptr ) { // get SwPosition for my node - const SwTextNode* pNode = GetTextNode(); - sal_uLong nHere = pNode->GetIndex(); + SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(GetFrame())); + sal_uLong nFirstNode(pFrame->GetTextNodeFirst()->GetIndex()); + sal_uLong nLastNode; + if (sw::MergedPara const*const pMerged = pFrame->GetMergedPara()) + { + nLastNode = pMerged->pLastNode->GetIndex(); + } + else + { + nLastNode = nFirstNode; + } // iterate over ring for(SwPaM& rTmpCursor : pCursor->GetRingContainer()) @@ -3554,13 +3571,12 @@ bool SwAccessibleParagraph::GetSelectionAtIndex( // ignore, if no mark if( rTmpCursor.HasMark() ) { - // check whether nHere is 'inside' pCursor + // check whether frame's node(s) are 'inside' pCursor SwPosition* pStart = rTmpCursor.Start(); sal_uLong nStartIndex = pStart->nNode.GetIndex(); SwPosition* pEnd = rTmpCursor.End(); sal_uLong nEndIndex = pEnd->nNode.GetIndex(); - if( ( nHere >= nStartIndex ) && - ( nHere <= nEndIndex ) ) + if ((nStartIndex <= nLastNode) && (nFirstNode <= nEndIndex)) { if( nSelected == 0 ) { @@ -3568,7 +3584,7 @@ bool SwAccessibleParagraph::GetSelectionAtIndex( // start position sal_Int32 nLocalStart = -1; - if( nHere > nStartIndex ) + if (nStartIndex < nFirstNode) { // selection starts in previous node: // then our local selection starts with the paragraph @@ -3576,12 +3592,13 @@ bool SwAccessibleParagraph::GetSelectionAtIndex( } else { - assert(nHere == nStartIndex); + 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 sal_Int32 nCoreStart = pStart->nContent.GetIndex(); + const TextFrameIndex nCoreStart = + pFrame->MapModelToViewPos(*pStart); if( nCoreStart < GetPortionData().GetFirstValidCorePosition() ) { @@ -3604,7 +3621,7 @@ bool SwAccessibleParagraph::GetSelectionAtIndex( // end position sal_Int32 nLocalEnd = -1; - if( nHere < nEndIndex ) + if (nLastNode < nEndIndex) { // selection ends in following node: // then our local selection extends to the end @@ -3613,11 +3630,12 @@ bool SwAccessibleParagraph::GetSelectionAtIndex( } else { - assert(nHere == nEndIndex); + assert(FrameContainsNode(*pFrame, nEndIndex)); // selection ends in this node: then select everything // before our part of the node - const sal_Int32 nCoreEnd = pEnd->nContent.GetIndex(); + const TextFrameIndex nCoreEnd = + pFrame->MapModelToViewPos(*pEnd); if( nCoreEnd > GetPortionData().GetLastValidCorePosition() ) { |