diff options
Diffstat (limited to 'sw/source/core/crsr/crstrvl.cxx')
-rw-r--r-- | sw/source/core/crsr/crstrvl.cxx | 64 |
1 files changed, 51 insertions, 13 deletions
diff --git a/sw/source/core/crsr/crstrvl.cxx b/sw/source/core/crsr/crstrvl.cxx index 7df0ce6ff323..0c53e6448b46 100644 --- a/sw/source/core/crsr/crstrvl.cxx +++ b/sw/source/core/crsr/crstrvl.cxx @@ -774,7 +774,7 @@ bool SwCursorShell::MoveFieldType( SwTextNode* pTNd = rPos.nNode.GetNode().GetTextNode(); OSL_ENSURE( pTNd, "No ContentNode" ); - SwTextField * pTextField = pTNd->GetFieldTextAttrAt( rPos.nContent.GetIndex(), true ); + SwTextField * pTextField = pTNd->GetFieldTextAttrAt(rPos.nContent.GetIndex(), ::sw::GetTextAttrMode::Default); const bool bDelField = ( pTextField == nullptr ); sal_Int32 nContentOffset = -1; @@ -878,14 +878,14 @@ bool SwCursorShell::GotoFormatField( const SwFormatField& rField ) SwTextField * SwCursorShell::GetTextFieldAtPos( const SwPosition* pPos, - const bool bIncludeInputFieldAtStart ) + ::sw::GetTextAttrMode const eMode) { SwTextField* pTextField = nullptr; SwTextNode * const pNode = pPos->nNode.GetNode().GetTextNode(); if ( pNode != nullptr ) { - pTextField = pNode->GetFieldTextAttrAt( pPos->nContent.GetIndex(), bIncludeInputFieldAtStart ); + pTextField = pNode->GetFieldTextAttrAt( pPos->nContent.GetIndex(), eMode); } return pTextField; @@ -893,11 +893,11 @@ SwTextField * SwCursorShell::GetTextFieldAtPos( SwTextField* SwCursorShell::GetTextFieldAtCursor( const SwPaM* pCursor, - const bool bIncludeInputFieldAtStart ) + ::sw::GetTextAttrMode const eMode) { SwTextField* pFieldAtCursor = nullptr; - SwTextField* pTextField = GetTextFieldAtPos( pCursor->Start(), bIncludeInputFieldAtStart ); + SwTextField* pTextField = GetTextFieldAtPos(pCursor->Start(), eMode); if ( pTextField != nullptr && pCursor->Start()->nNode == pCursor->End()->nNode ) { @@ -918,7 +918,8 @@ SwField* SwCursorShell::GetFieldAtCursor( const SwPaM *const pCursor, const bool bIncludeInputFieldAtStart) { - SwTextField *const pField(GetTextFieldAtCursor(pCursor, bIncludeInputFieldAtStart)); + SwTextField *const pField(GetTextFieldAtCursor(pCursor, + bIncludeInputFieldAtStart ? ::sw::GetTextAttrMode::Default : ::sw::GetTextAttrMode::Expand)); return pField ? const_cast<SwField*>(pField->GetFormatField().GetField()) : nullptr; @@ -949,7 +950,7 @@ bool SwCursorShell::CursorInsideInputField() const { for(SwPaM& rCursor : GetCursor()->GetRingContainer()) { - if (dynamic_cast<const SwTextInputField*>(GetTextFieldAtCursor(&rCursor, true))) + if (dynamic_cast<const SwTextInputField*>(GetTextFieldAtCursor(&rCursor, ::sw::GetTextAttrMode::Parent))) return true; } return false; @@ -957,7 +958,7 @@ bool SwCursorShell::CursorInsideInputField() const bool SwCursorShell::PosInsideInputField( const SwPosition& rPos ) { - return dynamic_cast<const SwTextInputField*>(GetTextFieldAtPos( &rPos, false )) != nullptr; + return dynamic_cast<const SwTextInputField*>(GetTextFieldAtPos(&rPos, ::sw::GetTextAttrMode::Parent)) != nullptr; } bool SwCursorShell::DocPtInsideInputField( const Point& rDocPt ) const @@ -973,7 +974,7 @@ bool SwCursorShell::DocPtInsideInputField( const Point& rDocPt ) const sal_Int32 SwCursorShell::StartOfInputFieldAtPos( const SwPosition& rPos ) { - const SwTextInputField* pTextInputField = dynamic_cast<const SwTextInputField*>(GetTextFieldAtPos( &rPos, true )); + const SwTextInputField* pTextInputField = dynamic_cast<const SwTextInputField*>(GetTextFieldAtPos(&rPos, ::sw::GetTextAttrMode::Default)); assert(pTextInputField != nullptr && "<SwEditShell::StartOfInputFieldAtPos(..)> - no Input Field at given position"); return pTextInputField->GetStart(); @@ -981,7 +982,7 @@ sal_Int32 SwCursorShell::StartOfInputFieldAtPos( const SwPosition& rPos ) sal_Int32 SwCursorShell::EndOfInputFieldAtPos( const SwPosition& rPos ) { - const SwTextInputField* pTextInputField = dynamic_cast<const SwTextInputField*>(GetTextFieldAtPos( &rPos, true )); + const SwTextInputField* pTextInputField = dynamic_cast<const SwTextInputField*>(GetTextFieldAtPos(&rPos, ::sw::GetTextAttrMode::Default)); assert(pTextInputField != nullptr && "<SwEditShell::EndOfInputFieldAtPos(..)> - no Input Field at given position"); return *(pTextInputField->End()); @@ -1930,7 +1931,7 @@ bool SwContentAtPos::IsInRTLText()const return bRet; } -bool SwCursorShell::SelectText( const sal_Int32 nStart, +bool SwCursorShell::SelectTextModel( const sal_Int32 nStart, const sal_Int32 nEnd ) { SET_CURR_SHELL( this ); @@ -1954,6 +1955,43 @@ bool SwCursorShell::SelectText( const sal_Int32 nStart, return bRet; } +TextFrameIndex SwCursorShell::GetCursorPointAsViewIndex() const +{ + SwPosition const*const pPos(GetCursor()->GetPoint()); + SwTextNode const*const pTextNode(pPos->nNode.GetNode().GetTextNode()); + assert(pTextNode); + SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(pTextNode->getLayoutFrame(GetLayout()))); + assert(pFrame); + return pFrame->MapModelToViewPos(*pPos); +} + +bool SwCursorShell::SelectTextView(TextFrameIndex const nStart, + TextFrameIndex const nEnd) +{ + CurrShell aCurr( this ); + bool bRet = false; + + SwCallLink aLk( *this ); + SwCursorSaveState aSaveState( *m_pCurrentCursor ); + + SwPosition& rPos = *m_pCurrentCursor->GetPoint(); + m_pCurrentCursor->DeleteMark(); + // indexes must correspond to cursor point! + SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(m_pCurrentCursor->GetPoint()->nNode.GetNode().GetTextNode()->getLayoutFrame(GetLayout()))); + assert(pFrame); + rPos = pFrame->MapViewToModelPos(nStart); + m_pCurrentCursor->SetMark(); + rPos = pFrame->MapViewToModelPos(nEnd); + + if (!m_pCurrentCursor->IsSelOvr()) + { + UpdateCursor(); + bRet = true; + } + + return bRet; +} + bool SwCursorShell::SelectTextAttr( sal_uInt16 nWhich, bool bExpand, const SwTextAttr* pTextAttr ) @@ -1970,14 +2008,14 @@ bool SwCursorShell::SelectTextAttr( sal_uInt16 nWhich, pTextAttr = pTextNd ? pTextNd->GetTextAttrAt(rPos.nContent.GetIndex(), nWhich, - bExpand ? SwTextNode::EXPAND : SwTextNode::DEFAULT) + bExpand ? ::sw::GetTextAttrMode::Expand : ::sw::GetTextAttrMode::Default) : nullptr; } if( pTextAttr ) { const sal_Int32* pEnd = pTextAttr->End(); - bRet = SelectText( pTextAttr->GetStart(), ( pEnd ? *pEnd : pTextAttr->GetStart() + 1 ) ); + bRet = SelectTextModel(pTextAttr->GetStart(), (pEnd ? *pEnd : pTextAttr->GetStart() + 1)); } } return bRet; |