summaryrefslogtreecommitdiff
path: root/sw/source/core/crsr/crsrsh.cxx
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2020-07-30 10:33:15 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-08-01 13:14:05 +0200
commitfb34aeb7842eaa852c82c3d73c722411c11885d7 (patch)
tree73547992845972e7b25fbce01c2657b967122c40 /sw/source/core/crsr/crsrsh.cxx
parenta0ec43251e8b8a0805306ca5ad86794550916fce (diff)
loplugin:flatten in sw/core/access..sc/core/crsr
Change-Id: I073545c11e2261703e5255abefaf82a2bbea5211 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99934 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw/source/core/crsr/crsrsh.cxx')
-rw-r--r--sw/source/core/crsr/crsrsh.cxx393
1 files changed, 196 insertions, 197 deletions
diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx
index ef3200a51a26..a2a169339bae 100644
--- a/sw/source/core/crsr/crsrsh.cxx
+++ b/sw/source/core/crsr/crsrsh.cxx
@@ -387,20 +387,19 @@ bool SwCursorShell::LeftRight( bool bLeft, sal_uInt16 nCnt, sal_uInt16 nMode,
void SwCursorShell::MarkListLevel( const OUString& sListId,
const int nListLevel )
{
- if ( sListId != m_sMarkedListId ||
- nListLevel != m_nMarkedListLevel)
- {
- if ( !m_sMarkedListId.isEmpty() )
- mxDoc->MarkListLevel( m_sMarkedListId, m_nMarkedListLevel, false );
+ if (sListId == m_sMarkedListId && nListLevel == m_nMarkedListLevel)
+ return;
- if ( !sListId.isEmpty() )
- {
- mxDoc->MarkListLevel( sListId, nListLevel, true );
- }
+ if ( !m_sMarkedListId.isEmpty() )
+ mxDoc->MarkListLevel( m_sMarkedListId, m_nMarkedListLevel, false );
- m_sMarkedListId = sListId;
- m_nMarkedListLevel = nListLevel;
+ if ( !sListId.isEmpty() )
+ {
+ mxDoc->MarkListLevel( sListId, nListLevel, true );
}
+
+ m_sMarkedListId = sListId;
+ m_nMarkedListLevel = nListLevel;
}
void SwCursorShell::UpdateMarkedListLevel()
@@ -408,28 +407,28 @@ void SwCursorShell::UpdateMarkedListLevel()
SwTextNode const*const pTextNd = sw::GetParaPropsNode(*GetLayout(),
GetCursor_()->GetPoint()->nNode);
- if ( pTextNd )
+ if ( !pTextNd )
+ return;
+
+ if (!pTextNd->IsNumbered(GetLayout()))
{
- if (!pTextNd->IsNumbered(GetLayout()))
- {
- m_pCurrentCursor->SetInFrontOfLabel_( false );
- MarkListLevel( OUString(), 0 );
- }
- else if ( m_pCurrentCursor->IsInFrontOfLabel() )
- {
- if ( pTextNd->IsInList() )
- {
- assert(pTextNd->GetActualListLevel() >= 0 &&
- pTextNd->GetActualListLevel() < MAXLEVEL);
- MarkListLevel( pTextNd->GetListId(),
- pTextNd->GetActualListLevel() );
- }
- }
- else
+ m_pCurrentCursor->SetInFrontOfLabel_( false );
+ MarkListLevel( OUString(), 0 );
+ }
+ else if ( m_pCurrentCursor->IsInFrontOfLabel() )
+ {
+ if ( pTextNd->IsInList() )
{
- MarkListLevel( OUString(), 0 );
+ assert(pTextNd->GetActualListLevel() >= 0 &&
+ pTextNd->GetActualListLevel() < MAXLEVEL);
+ MarkListLevel( pTextNd->GetListId(),
+ pTextNd->GetActualListLevel() );
}
}
+ else
+ {
+ MarkListLevel( OUString(), 0 );
+ }
}
void SwCursorShell::FirePageChangeEvent(sal_uInt16 nOldPage, sal_uInt16 nNewPage)
@@ -2150,76 +2149,58 @@ void SwCursorShell::RefreshBlockCursor()
aRect.Justify();
SwSelectionList aSelList( pFrame );
- if( GetLayout()->FillSelection( aSelList, aRect ) )
+ if( !GetLayout()->FillSelection( aSelList, aRect ) )
+ return;
+
+ SwCursor* pNxt = static_cast<SwCursor*>(m_pCurrentCursor->GetNext());
+ while( pNxt != m_pCurrentCursor )
{
- SwCursor* pNxt = static_cast<SwCursor*>(m_pCurrentCursor->GetNext());
- while( pNxt != m_pCurrentCursor )
- {
- delete pNxt;
- pNxt = static_cast<SwCursor*>(m_pCurrentCursor->GetNext());
- }
+ delete pNxt;
+ pNxt = static_cast<SwCursor*>(m_pCurrentCursor->GetNext());
+ }
- std::list<SwPaM*>::iterator pStart = aSelList.getStart();
- std::list<SwPaM*>::iterator pPam = aSelList.getEnd();
- OSL_ENSURE( pPam != pStart, "FillSelection should deliver at least one PaM" );
- m_pCurrentCursor->SetMark();
+ std::list<SwPaM*>::iterator pStart = aSelList.getStart();
+ std::list<SwPaM*>::iterator pPam = aSelList.getEnd();
+ OSL_ENSURE( pPam != pStart, "FillSelection should deliver at least one PaM" );
+ m_pCurrentCursor->SetMark();
+ --pPam;
+ // If there is only one text portion inside the rectangle, a simple
+ // selection is created
+ if( pPam == pStart )
+ {
+ *m_pCurrentCursor->GetPoint() = *(*pPam)->GetPoint();
+ if( (*pPam)->HasMark() )
+ *m_pCurrentCursor->GetMark() = *(*pPam)->GetMark();
+ else
+ m_pCurrentCursor->DeleteMark();
+ delete *pPam;
+ m_pCurrentCursor->SetColumnSelection( false );
+ }
+ else
+ {
+ // The order of the SwSelectionList has to be preserved but
+ // the order inside the ring created by CreateCursor() is not like
+ // expected => First create the selections before the last one
+ // downto the first selection.
+ // At least create the cursor for the last selection
--pPam;
- // If there is only one text portion inside the rectangle, a simple
- // selection is created
- if( pPam == pStart )
- {
- *m_pCurrentCursor->GetPoint() = *(*pPam)->GetPoint();
- if( (*pPam)->HasMark() )
- *m_pCurrentCursor->GetMark() = *(*pPam)->GetMark();
- else
- m_pCurrentCursor->DeleteMark();
- delete *pPam;
- m_pCurrentCursor->SetColumnSelection( false );
- }
+ *m_pCurrentCursor->GetPoint() = *(*pPam)->GetPoint(); // n-1 (if n == number of selections)
+ if( (*pPam)->HasMark() )
+ *m_pCurrentCursor->GetMark() = *(*pPam)->GetMark();
else
+ m_pCurrentCursor->DeleteMark();
+ delete *pPam;
+ m_pCurrentCursor->SetColumnSelection( true );
+ while( pPam != pStart )
{
- // The order of the SwSelectionList has to be preserved but
- // the order inside the ring created by CreateCursor() is not like
- // expected => First create the selections before the last one
- // downto the first selection.
- // At least create the cursor for the last selection
--pPam;
- *m_pCurrentCursor->GetPoint() = *(*pPam)->GetPoint(); // n-1 (if n == number of selections)
- if( (*pPam)->HasMark() )
- *m_pCurrentCursor->GetMark() = *(*pPam)->GetMark();
- else
- m_pCurrentCursor->DeleteMark();
- delete *pPam;
- m_pCurrentCursor->SetColumnSelection( true );
- while( pPam != pStart )
- {
- --pPam;
- SwShellCursor* pNew = new SwShellCursor( *m_pCurrentCursor );
- pNew->insert( pNew->begin(), m_pCurrentCursor->begin(), m_pCurrentCursor->end());
- m_pCurrentCursor->clear();
- m_pCurrentCursor->DeleteMark();
+ SwShellCursor* pNew = new SwShellCursor( *m_pCurrentCursor );
+ pNew->insert( pNew->begin(), m_pCurrentCursor->begin(), m_pCurrentCursor->end());
+ m_pCurrentCursor->clear();
+ m_pCurrentCursor->DeleteMark();
- *m_pCurrentCursor->GetPoint() = *(*pPam)->GetPoint(); // n-2, n-3, .., 2, 1
- if( (*pPam)->HasMark() )
- {
- m_pCurrentCursor->SetMark();
- *m_pCurrentCursor->GetMark() = *(*pPam)->GetMark();
- }
- else
- m_pCurrentCursor->DeleteMark();
- m_pCurrentCursor->SetColumnSelection( true );
- delete *pPam;
- }
- {
- SwShellCursor* pNew = new SwShellCursor( *m_pCurrentCursor );
- pNew->insert( pNew->begin(), m_pCurrentCursor->begin(), m_pCurrentCursor->end() );
- m_pCurrentCursor->clear();
- m_pCurrentCursor->DeleteMark();
- }
- pPam = aSelList.getEnd();
- --pPam;
- *m_pCurrentCursor->GetPoint() = *(*pPam)->GetPoint(); // n, the last selection
+ *m_pCurrentCursor->GetPoint() = *(*pPam)->GetPoint(); // n-2, n-3, .., 2, 1
if( (*pPam)->HasMark() )
{
m_pCurrentCursor->SetMark();
@@ -2230,6 +2211,24 @@ void SwCursorShell::RefreshBlockCursor()
m_pCurrentCursor->SetColumnSelection( true );
delete *pPam;
}
+ {
+ SwShellCursor* pNew = new SwShellCursor( *m_pCurrentCursor );
+ pNew->insert( pNew->begin(), m_pCurrentCursor->begin(), m_pCurrentCursor->end() );
+ m_pCurrentCursor->clear();
+ m_pCurrentCursor->DeleteMark();
+ }
+ pPam = aSelList.getEnd();
+ --pPam;
+ *m_pCurrentCursor->GetPoint() = *(*pPam)->GetPoint(); // n, the last selection
+ if( (*pPam)->HasMark() )
+ {
+ m_pCurrentCursor->SetMark();
+ *m_pCurrentCursor->GetMark() = *(*pPam)->GetMark();
+ }
+ else
+ m_pCurrentCursor->DeleteMark();
+ m_pCurrentCursor->SetColumnSelection( true );
+ delete *pPam;
}
}
@@ -2386,38 +2385,38 @@ void SwCursorShell::ShowCursors( bool bCursorVis )
void SwCursorShell::ShowCursor()
{
- if( !m_bBasicHideCursor )
- {
- m_bSVCursorVis = true;
- m_pCurrentCursor->SetShowTextInputFieldOverlay( true );
+ if( m_bBasicHideCursor )
+ return;
- if (comphelper::LibreOfficeKit::isActive())
- {
- OString aPayload = OString::boolean(m_bSVCursorVis);
- GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_CURSOR_VISIBLE, aPayload.getStr());
- SfxLokHelper::notifyOtherViews(GetSfxViewShell(), LOK_CALLBACK_VIEW_CURSOR_VISIBLE, "visible", aPayload);
- }
+ m_bSVCursorVis = true;
+ m_pCurrentCursor->SetShowTextInputFieldOverlay( true );
- UpdateCursor();
+ if (comphelper::LibreOfficeKit::isActive())
+ {
+ OString aPayload = OString::boolean(m_bSVCursorVis);
+ GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_CURSOR_VISIBLE, aPayload.getStr());
+ SfxLokHelper::notifyOtherViews(GetSfxViewShell(), LOK_CALLBACK_VIEW_CURSOR_VISIBLE, "visible", aPayload);
}
+
+ UpdateCursor();
}
void SwCursorShell::HideCursor()
{
- if( !m_bBasicHideCursor )
- {
- m_bSVCursorVis = false;
- // possibly reverse selected areas!!
- CurrShell aCurr( this );
- m_pCurrentCursor->SetShowTextInputFieldOverlay( false );
- m_pVisibleCursor->Hide();
+ if( m_bBasicHideCursor )
+ return;
- if (comphelper::LibreOfficeKit::isActive())
- {
- OString aPayload = OString::boolean(m_bSVCursorVis);
- GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_CURSOR_VISIBLE, aPayload.getStr());
- SfxLokHelper::notifyOtherViews(GetSfxViewShell(), LOK_CALLBACK_VIEW_CURSOR_VISIBLE, "visible", aPayload);
- }
+ m_bSVCursorVis = false;
+ // possibly reverse selected areas!!
+ CurrShell aCurr( this );
+ m_pCurrentCursor->SetShowTextInputFieldOverlay( false );
+ m_pVisibleCursor->Hide();
+
+ if (comphelper::LibreOfficeKit::isActive())
+ {
+ OString aPayload = OString::boolean(m_bSVCursorVis);
+ GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_CURSOR_VISIBLE, aPayload.getStr());
+ SfxLokHelper::notifyOtherViews(GetSfxViewShell(), LOK_CALLBACK_VIEW_CURSOR_VISIBLE, "visible", aPayload);
}
}
@@ -3703,30 +3702,30 @@ void SwCursorShell::GetSmartTagTerm( std::vector< OUString >& rSmartTagTypes,
SwPaM* pCursor = GetCursor();
SwPosition aPos( *pCursor->GetPoint() );
SwTextNode *pNode = aPos.nNode.GetNode().GetTextNode();
- if ( pNode && !pNode->IsInProtectSect() )
- {
- const SwWrongList *pSmartTagList = pNode->GetSmartTags();
- if ( pSmartTagList )
- {
- sal_Int32 nCurrent = aPos.nContent.GetIndex();
- sal_Int32 nBegin = nCurrent;
- sal_Int32 nLen = 1;
+ if ( !(pNode && !pNode->IsInProtectSect()) )
+ return;
- if (pSmartTagList->InWrongWord(nBegin, nLen) && !pNode->IsSymbolAt(nBegin))
- {
- const sal_uInt16 nIndex = pSmartTagList->GetWrongPos( nBegin );
- const SwWrongList* pSubList = pSmartTagList->SubList( nIndex );
- if ( pSubList )
- {
- pSmartTagList = pSubList;
- nCurrent = 0;
- }
+ const SwWrongList *pSmartTagList = pNode->GetSmartTags();
+ if ( !pSmartTagList )
+ return;
- lcl_FillRecognizerData( rSmartTagTypes, rStringKeyMaps, *pSmartTagList, nCurrent );
- lcl_FillTextRange( rRange, *pNode, nBegin, nLen );
- }
- }
+ sal_Int32 nCurrent = aPos.nContent.GetIndex();
+ sal_Int32 nBegin = nCurrent;
+ sal_Int32 nLen = 1;
+
+ if (!(pSmartTagList->InWrongWord(nBegin, nLen) && !pNode->IsSymbolAt(nBegin)))
+ return;
+
+ const sal_uInt16 nIndex = pSmartTagList->GetWrongPos( nBegin );
+ const SwWrongList* pSubList = pSmartTagList->SubList( nIndex );
+ if ( pSubList )
+ {
+ pSmartTagList = pSubList;
+ nCurrent = 0;
}
+
+ lcl_FillRecognizerData( rSmartTagTypes, rStringKeyMaps, *pSmartTagList, nCurrent );
+ lcl_FillTextRange( rRange, *pNode, nBegin, nLen );
}
// see also SwEditShell::GetCorrection( const Point* pPt, SwRect& rSelectRect )
@@ -3749,67 +3748,67 @@ void SwCursorShell::GetSmartTagRect( const Point& rPt, SwRect& rSelectRect )
pSmartTagList = pNode->GetSmartTags();
if( !pSmartTagList )
return;
- if( !pNode->IsInProtectSect() )
- {
- sal_Int32 nBegin = aPos.nContent.GetIndex();
- sal_Int32 nLen = 1;
-
- if (pSmartTagList->InWrongWord(nBegin, nLen) && !pNode->IsSymbolAt(nBegin))
- {
- // get smarttag word
- OUString aText( pNode->GetText().copy(nBegin, nLen) );
-
- //save the start and end positions of the line and the starting point
- Push();
- LeftMargin();
- const sal_Int32 nLineStart = GetCursor()->GetPoint()->nContent.GetIndex();
- RightMargin();
- const sal_Int32 nLineEnd = GetCursor()->GetPoint()->nContent.GetIndex();
- Pop(PopMode::DeleteCurrent);
-
- // make sure the selection build later from the data below does not
- // include "in word" character to the left and right in order to
- // preserve those. Therefore count those "in words" in order to
- // modify the selection accordingly.
- const sal_Unicode* pChar = aText.getStr();
- sal_Int32 nLeft = 0;
- while (*pChar++ == CH_TXTATR_INWORD)
- ++nLeft;
- pChar = aText.getLength() ? aText.getStr() + aText.getLength() - 1 : nullptr;
- sal_Int32 nRight = 0;
- while (pChar && *pChar-- == CH_TXTATR_INWORD)
- ++nRight;
-
- aPos.nContent = nBegin + nLeft;
- pCursor = GetCursor();
- *pCursor->GetPoint() = aPos;
- pCursor->SetMark();
- ExtendSelection( true, nLen - nLeft - nRight );
- // do not determine the rectangle in the current line
- const sal_Int32 nWordStart = (nBegin + nLeft) < nLineStart ? nLineStart : nBegin + nLeft;
- // take one less than the line end - otherwise the next line would
- // be calculated
- const sal_Int32 nWordEnd = std::min(nBegin + nLen - nLeft - nRight, nLineEnd);
- Push();
- pCursor->DeleteMark();
- SwIndex& rContent = GetCursor()->GetPoint()->nContent;
- rContent = nWordStart;
- SwRect aStartRect;
- SwCursorMoveState aState;
- aState.m_bRealWidth = true;
- SwContentNode* pContentNode = pCursor->GetContentNode();
- std::pair<Point, bool> const tmp(rPt, false);
- SwContentFrame *pContentFrame = pContentNode->getLayoutFrame(
- GetLayout(), pCursor->GetPoint(), &tmp);
-
- pContentFrame->GetCharRect( aStartRect, *pCursor->GetPoint(), &aState );
- rContent = nWordEnd - 1;
- SwRect aEndRect;
- pContentFrame->GetCharRect( aEndRect, *pCursor->GetPoint(),&aState );
- rSelectRect = aStartRect.Union( aEndRect );
- Pop(PopMode::DeleteCurrent);
- }
- }
+ if( pNode->IsInProtectSect() )
+ return;
+
+ sal_Int32 nBegin = aPos.nContent.GetIndex();
+ sal_Int32 nLen = 1;
+
+ if (!(pSmartTagList->InWrongWord(nBegin, nLen) && !pNode->IsSymbolAt(nBegin)))
+ return;
+
+ // get smarttag word
+ OUString aText( pNode->GetText().copy(nBegin, nLen) );
+
+ //save the start and end positions of the line and the starting point
+ Push();
+ LeftMargin();
+ const sal_Int32 nLineStart = GetCursor()->GetPoint()->nContent.GetIndex();
+ RightMargin();
+ const sal_Int32 nLineEnd = GetCursor()->GetPoint()->nContent.GetIndex();
+ Pop(PopMode::DeleteCurrent);
+
+ // make sure the selection build later from the data below does not
+ // include "in word" character to the left and right in order to
+ // preserve those. Therefore count those "in words" in order to
+ // modify the selection accordingly.
+ const sal_Unicode* pChar = aText.getStr();
+ sal_Int32 nLeft = 0;
+ while (*pChar++ == CH_TXTATR_INWORD)
+ ++nLeft;
+ pChar = aText.getLength() ? aText.getStr() + aText.getLength() - 1 : nullptr;
+ sal_Int32 nRight = 0;
+ while (pChar && *pChar-- == CH_TXTATR_INWORD)
+ ++nRight;
+
+ aPos.nContent = nBegin + nLeft;
+ pCursor = GetCursor();
+ *pCursor->GetPoint() = aPos;
+ pCursor->SetMark();
+ ExtendSelection( true, nLen - nLeft - nRight );
+ // do not determine the rectangle in the current line
+ const sal_Int32 nWordStart = (nBegin + nLeft) < nLineStart ? nLineStart : nBegin + nLeft;
+ // take one less than the line end - otherwise the next line would
+ // be calculated
+ const sal_Int32 nWordEnd = std::min(nBegin + nLen - nLeft - nRight, nLineEnd);
+ Push();
+ pCursor->DeleteMark();
+ SwIndex& rContent = GetCursor()->GetPoint()->nContent;
+ rContent = nWordStart;
+ SwRect aStartRect;
+ SwCursorMoveState aState;
+ aState.m_bRealWidth = true;
+ SwContentNode* pContentNode = pCursor->GetContentNode();
+ std::pair<Point, bool> const tmp(rPt, false);
+ SwContentFrame *pContentFrame = pContentNode->getLayoutFrame(
+ GetLayout(), pCursor->GetPoint(), &tmp);
+
+ pContentFrame->GetCharRect( aStartRect, *pCursor->GetPoint(), &aState );
+ rContent = nWordEnd - 1;
+ SwRect aEndRect;
+ pContentFrame->GetCharRect( aEndRect, *pCursor->GetPoint(),&aState );
+ rSelectRect = aStartRect.Union( aEndRect );
+ Pop(PopMode::DeleteCurrent);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */