summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Stahl <michael.stahl@allotropia.de>2022-03-04 21:53:38 +0100
committerThorsten Behrens <thorsten.behrens@allotropia.de>2022-03-12 11:18:16 +0100
commit26830d91d2f2a2d50f989fa3f36d18d55ea0eafd (patch)
treeb46b4bbf7ca7c39bcce41e3bed563412a98094c3
parentsw_redlinehide: fix crashes in SwEditWin Surrounding functions (diff)
downloadcore-26830d91d2f2a2d50f989fa3f36d18d55ea0eafd.tar.gz
core-26830d91d2f2a2d50f989fa3f36d18d55ea0eafd.zip
sw_redlinehide: more issues with SwEditWin Surrounding functions
.. and SwEditWinUIObject. These need to work with TextFrameIndex. Add some functions to SwCursorShell to make it possible. Change-Id: I884c4822a0e7ecf254ea09a893762e1e6d539534 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131042 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@allotropia.de> (cherry picked from commit 112592ac580108998a2cd99ae9bbf376c80c10d8) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131109 Reviewed-by: Thorsten Behrens <thorsten.behrens@allotropia.de>
-rw-r--r--sw/inc/crsrsh.hxx11
-rw-r--r--sw/qa/extras/uiwriter/uiwriter.cxx6
-rw-r--r--sw/source/core/crsr/crstrvl.cxx41
-rw-r--r--sw/source/uibase/docvw/edtwin.cxx17
-rw-r--r--sw/source/uibase/shells/textfld.cxx2
-rw-r--r--sw/source/uibase/uitest/uiobject.cxx29
6 files changed, 78 insertions, 28 deletions
diff --git a/sw/inc/crsrsh.hxx b/sw/inc/crsrsh.hxx
index dc633a7bc9f2..6d843e7e424d 100644
--- a/sw/inc/crsrsh.hxx
+++ b/sw/inc/crsrsh.hxx
@@ -26,6 +26,9 @@
#include <vcl/keycod.hxx>
#include <o3tl/typed_flags_set.hxx>
+#ifdef SW_DLLIMPLEMENTATION
+#include <TextFrameIndex.hxx>
+#endif
#include "IShellCursorSupplier.hxx"
#include "swdllapi.h"
#include "docary.hxx"
@@ -789,8 +792,12 @@ public:
bool GotoINetAttr( const SwTextINetFormat& rAttr );
const SwFormatINetFormat* FindINetAttr( std::u16string_view rName ) const;
- bool SelectText( const sal_Int32 nStart,
- const sal_Int32 nEnd );
+ bool SelectTextModel(sal_Int32 nStart, sal_Int32 nEnd);
+#ifdef SW_DLLIMPLEMENTATION
+ bool SelectTextView(TextFrameIndex nStart, TextFrameIndex nEnd);
+ // result is only valid while cursor isn't moved!
+ TextFrameIndex GetCursorPointAsViewIndex() const;
+#endif
bool CheckTableBoxContent( const SwPosition* pPos = nullptr );
void SaveTableBoxContent( const SwPosition* pPos = nullptr );
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index bd7a464a23bf..d626d5a9d6ec 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -3703,7 +3703,7 @@ void SwUiWriterTest::testUndoDelAsCharTdf107512()
CPPUNIT_ASSERT(rIDCO.InsertGraphicObject(*pShell->GetCursor(), grf, &frameSet, &grfSet));
CPPUNIT_ASSERT_EQUAL(size_t(2), pDoc->GetFlyCount(FLYCNTTYPE_GRF));
SvxCharHiddenItem hidden(true, RES_CHRATR_HIDDEN);
- pShell->SelectText(1, 4);
+ pShell->SelectTextModel(1, 4);
rIDCO.InsertPoolItem(*pShell->GetCursor(), hidden);
// now we have "\1foo\1" with the "foo" hidden
CPPUNIT_ASSERT(pShell->GetCursor()->GetNode().GetTextNode()->GetTextAttrForCharAt(0, RES_TXTATR_FLYCNT));
@@ -3717,7 +3717,7 @@ void SwUiWriterTest::testUndoDelAsCharTdf107512()
query.ClearItem(RES_CHRATR_HIDDEN);
// delete from the start
- pShell->SelectText(0, 4);
+ pShell->SelectTextModel(0, 4);
rIDCO.DeleteAndJoin(*pShell->GetCursor());
CPPUNIT_ASSERT(pShell->GetCursor()->GetNode().GetTextNode()->GetTextAttrForCharAt(0, RES_TXTATR_FLYCNT));
CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc->GetFlyCount(FLYCNTTYPE_GRF));
@@ -3760,7 +3760,7 @@ void SwUiWriterTest::testUndoDelAsCharTdf107512()
query.ClearItem(RES_CHRATR_HIDDEN);
// delete from the end
- pShell->SelectText(1, 5);
+ pShell->SelectTextModel(1, 5);
rIDCO.DeleteAndJoin(*pShell->GetCursor());
CPPUNIT_ASSERT(pShell->GetCursor()->GetNode().GetTextNode()->GetTextAttrForCharAt(0, RES_TXTATR_FLYCNT));
CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc->GetFlyCount(FLYCNTTYPE_GRF));
diff --git a/sw/source/core/crsr/crstrvl.cxx b/sw/source/core/crsr/crstrvl.cxx
index da22013cc31f..e7e27c1980a3 100644
--- a/sw/source/core/crsr/crstrvl.cxx
+++ b/sw/source/core/crsr/crstrvl.cxx
@@ -1996,7 +1996,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 )
{
CurrShell aCurr( this );
@@ -2020,6 +2020,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 )
@@ -2043,7 +2080,7 @@ bool SwCursorShell::SelectTextAttr( sal_uInt16 nWhich,
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;
diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx
index 31f4c69e162e..adf0d7847397 100644
--- a/sw/source/uibase/docvw/edtwin.cxx
+++ b/sw/source/uibase/docvw/edtwin.cxx
@@ -3731,7 +3731,7 @@ void SwEditWin::MouseButtonDown(const MouseEvent& _rMEvt)
// select content of Input Field, but exclude CH_TXT_ATR_INPUTFIELDSTART
// and CH_TXT_ATR_INPUTFIELDEND
rSh.SttSelect();
- rSh.SelectText( aFieldAtPos.pFndTextAttr->GetStart() + 1,
+ rSh.SelectTextModel( aFieldAtPos.pFndTextAttr->GetStart() + 1,
*(aFieldAtPos.pFndTextAttr->End()) - 1 );
}
// don't reset here any longer so that, in case through MouseMove
@@ -3777,7 +3777,7 @@ void SwEditWin::MouseButtonDown(const MouseEvent& _rMEvt)
// select content of Input Field, but exclude CH_TXT_ATR_INPUTFIELDSTART
// and CH_TXT_ATR_INPUTFIELDEND
rSh.SttSelect();
- rSh.SelectText( aFieldAtPos.pFndTextAttr->GetStart() + 1,
+ rSh.SelectTextModel( aFieldAtPos.pFndTextAttr->GetStart() + 1,
*(aFieldAtPos.pFndTextAttr->End()) - 1 );
}
}
@@ -6474,13 +6474,13 @@ Selection SwEditWin::GetSurroundingTextSelection() const
// Return the position of the visible cursor in the sentence
// around the visible cursor.
- SwPosition *pPos = rSh.GetCursor()->GetPoint();
- const sal_Int32 nPos = pPos->nContent.GetIndex();
+ TextFrameIndex const nPos(rSh.GetCursorPointAsViewIndex());
+
rSh.Push();
rSh.HideCursor();
rSh.GoStartSentence();
- const sal_Int32 nStartPos = rSh.GetCursor()->GetPoint()->nContent.GetIndex();
+ TextFrameIndex const nStartPos(rSh.GetCursorPointAsViewIndex());
rSh.Pop(SwCursorShell::PopMode::DeleteCurrent);
rSh.ShowCursor();
@@ -6488,7 +6488,7 @@ Selection SwEditWin::GetSurroundingTextSelection() const
if (bUnLockView)
rSh.LockView(false);
- return Selection( nPos - nStartPos, nPos - nStartPos );
+ return Selection(sal_Int32(nPos - nStartPos), sal_Int32(nPos - nStartPos));
}
}
@@ -6507,11 +6507,12 @@ bool SwEditWin::DeleteSurroundingText(const Selection& rSelection)
rSh.Push();
rSh.HideCursor();
rSh.GoStartSentence();
- const sal_Int32 nStartPos = rSh.GetCursor()->GetPoint()->nContent.GetIndex();
+ TextFrameIndex const nStartPos(rSh.GetCursorPointAsViewIndex());
+
rSh.Pop(SwCursorShell::PopMode::DeleteCurrent);
rSh.ShowCursor();
- if (rSh.SelectText(nStartPos + rSelection.Min(), nStartPos + rSelection.Max()))
+ if (rSh.SelectTextView(nStartPos + TextFrameIndex(rSelection.Min()), nStartPos + TextFrameIndex(rSelection.Max())))
{
rSh.Delete();
return true;
diff --git a/sw/source/uibase/shells/textfld.cxx b/sw/source/uibase/shells/textfld.cxx
index ee20d9c74f65..9a1cbe76e040 100644
--- a/sw/source/uibase/shells/textfld.cxx
+++ b/sw/source/uibase/shells/textfld.cxx
@@ -180,7 +180,7 @@ void SwTextShell::ExecField(SfxRequest &rReq)
SwCursorShell::GetTextFieldAtCursor(rSh.GetCursor(), true))))
{
rSh.SttSelect();
- rSh.SelectText(
+ rSh.SelectTextModel(
SwCursorShell::StartOfInputFieldAtPos( *(rSh.GetCursor()->Start()) ) + 1,
SwCursorShell::EndOfInputFieldAtPos( *(rSh.GetCursor()->Start()) ) - 1 );
}
diff --git a/sw/source/uibase/uitest/uiobject.cxx b/sw/source/uibase/uitest/uiobject.cxx
index 7a19b4c8d88e..5f8a408c4b85 100644
--- a/sw/source/uibase/uitest/uiobject.cxx
+++ b/sw/source/uibase/uitest/uiobject.cxx
@@ -96,25 +96,30 @@ void SwEditWinUIObject::execute(const OUString& rAction,
{
auto itr = rParameters.find("START_POS");
OUString aStartPos = itr->second;
- sal_Int32 nStartPos = aStartPos.toInt32();
+ TextFrameIndex const nStartPos(aStartPos.toInt32());
itr = rParameters.find("END_POS");
assert(itr != rParameters.end());
OUString aEndPos = itr->second;
- sal_Int32 nEndPos = aEndPos.toInt32();
+ TextFrameIndex const nEndPos(aEndPos.toInt32());
auto & shell = getWrtShell(mxEditWin);
- sal_Int32 len;
- if (auto const text = shell.GetCursor_()->GetPoint()->nNode.GetNode().GetTextNode()) {
- len = text->GetText().getLength();
- } else {
- len = 0;
+ if (shell.GetCursor_()->GetPoint()->nNode.GetNode().GetTextNode())
+ {
+ shell.Push();
+ shell.MovePara(GoCurrPara, fnParaEnd);
+ TextFrameIndex const len(shell.GetCursorPointAsViewIndex());
+ shell.Pop(SwCursorShell::PopMode::DeleteCurrent);
+ SAL_WARN_IF(
+ sal_Int32(nStartPos) < 0 || nStartPos > len || sal_Int32(nEndPos) < 0 || nEndPos > len, "sw.ui",
+ "SELECT START/END_POS " << sal_Int32(nStartPos) << ".." << sal_Int32(nEndPos) << " outside 0.." << sal_Int32(len));
+ shell.SelectTextView(
+ std::clamp(nStartPos, TextFrameIndex(0), len), std::clamp(nEndPos, TextFrameIndex(0), len));
+ }
+ else
+ {
+ SAL_WARN("sw.ui", "SELECT without SwTextNode");
}
- SAL_WARN_IF(
- nStartPos < 0 || nStartPos > len || nEndPos < 0 || nEndPos > len, "sw.ui",
- "SELECT START/END_POS " << nStartPos << ".." << nEndPos << " outside 0.." << len);
- shell.SelectText(
- std::clamp(nStartPos, sal_Int32(0), len), std::clamp(nEndPos, sal_Int32(0), len));
}
}
else if (rAction == "SIDEBAR")