editeng: add convenience creators to ESelection All, NotFound
ESelection::All() select all text
ESelection::NotFound() sets seletion to not found state
ESelection::NoSelection() sets selection to no / invalid selection
Introduce max paragraph and position constants in ESelection,
use for EE_PARA_APPEND, EE_PARA_ALL, EE_PARA_MAX_COUNT,
EE_TEXTPOS_ALL, EE_TEXTPOS_MAX_COUNT.
Also simplify some ESelection constructs.
Change-Id: Ib110c5a730a1deabe4f988baa5a600249b3a31e9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169356
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Tested-by: Jenkins
diff --git a/include/editeng/ESelection.hxx b/include/editeng/ESelection.hxx
index 7f5aa8e..1b6c985 100644
--- a/include/editeng/ESelection.hxx
+++ b/include/editeng/ESelection.hxx
@@ -21,6 +21,20 @@
struct ESelection
{
static constexpr sal_Int32 MAX_PARAGRAPH_POSITION = SAL_MAX_INT32;
static constexpr sal_Int32 MAX_TEXT_POSITION = SAL_MAX_INT32;
// Select all text
static ESelection All() { return ESelection(0, 0, MAX_PARAGRAPH_POSITION, MAX_TEXT_POSITION); }
// Set to "not found" state
static ESelection NotFound() { return ESelection(MAX_PARAGRAPH_POSITION, MAX_TEXT_POSITION); }
// Set to no selection
static ESelection NoSelection()
{
return ESelection(MAX_PARAGRAPH_POSITION, MAX_TEXT_POSITION);
}
sal_Int32 nStartPara = 0;
sal_Int32 nStartPos = 0;
sal_Int32 nEndPara = 0;
diff --git a/include/editeng/editdata.hxx b/include/editeng/editdata.hxx
index 799b29b..25745f7 100644
--- a/include/editeng/editdata.hxx
+++ b/include/editeng/editdata.hxx
@@ -47,12 +47,12 @@ enum class EEAnchorMode {
enum class EERemoveParaAttribsMode { RemoveAll, RemoveCharItems, RemoveNone };
#define EE_PARA_APPEND SAL_MAX_INT32
#define EE_PARA_ALL SAL_MAX_INT32
#define EE_PARA_MAX_COUNT SAL_MAX_INT32
#define EE_PARA_APPEND ESelection::MAX_PARAGRAPH_POSITION
#define EE_PARA_ALL ESelection::MAX_PARAGRAPH_POSITION
#define EE_PARA_MAX_COUNT ESelection::MAX_PARAGRAPH_POSITION
#define EE_TEXTPOS_ALL SAL_MAX_INT32
#define EE_TEXTPOS_MAX_COUNT SAL_MAX_INT32
#define EE_TEXTPOS_ALL ESelection::MAX_TEXT_POSITION
#define EE_TEXTPOS_MAX_COUNT ESelection::MAX_TEXT_POSITION
EDITENG_DLLPUBLIC extern const size_t EE_APPEND;
diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx
index 93f2c3d..d921025 100644
--- a/sc/source/ui/app/inputhdl.cxx
+++ b/sc/source/ui/app/inputhdl.cxx
@@ -3964,7 +3964,7 @@ bool ScInputHandler::KeyInput( const KeyEvent& rKEvt, bool bStartEdit /* = false
{
pTableView->getEditEngine().SetText( aStrLoP );
if ( !aStrLoP.isEmpty() )
pTableView->SetSelection( ESelection(0,0, 0,0) ); // before the '%'
pTableView->SetSelection(ESelection()); // before the '%'
// Don't call SetSelection if the string is empty anyway,
// to avoid breaking the bInitial handling in ScViewData::EditGrowY
@@ -3973,7 +3973,7 @@ bool ScInputHandler::KeyInput( const KeyEvent& rKEvt, bool bStartEdit /* = false
{
pTopView->getEditEngine().SetText( aStrLoP );
if ( !aStrLoP.isEmpty() )
pTopView->SetSelection( ESelection(0,0, 0,0) ); // before the '%'
pTopView->SetSelection(ESelection()); // before the '%'
}
}
SyncViews();
@@ -4187,12 +4187,12 @@ void ScInputHandler::InputCommand( const CommandEvent& rCEvt )
if (pTableView)
{
pTableView->getEditEngine().SetText( u""_ustr );
pTableView->SetSelection( ESelection(0,0, 0,0) );
pTableView->SetSelection(ESelection());
}
if (pTopView)
{
pTopView->getEditEngine().SetText( u""_ustr );
pTopView->SetSelection( ESelection(0,0, 0,0) );
pTopView->SetSelection(ESelection());
}
}
SyncViews();
diff --git a/sc/source/ui/pagedlg/scuitphfedit.cxx b/sc/source/ui/pagedlg/scuitphfedit.cxx
index ecc7b1c..97f179a 100644
--- a/sc/source/ui/pagedlg/scuitphfedit.cxx
+++ b/sc/source/ui/pagedlg/scuitphfedit.cxx
@@ -444,7 +444,7 @@ bool ScHFEditPage::IsPageEntry(EditEngine*pEngine, const EditTextObject* pTextOb
if(aPosList.size() == 2)
{
OUString aPageEntry(m_xFtPage->get_label() + " ");
ESelection aSel(0,0,0,0);
ESelection aSel;
aSel.nEndPos = aPageEntry.getLength();
if(aPageEntry == pEngine->GetText(aSel))
{
@@ -531,7 +531,7 @@ void ScHFEditPage::ProcessDefinedListSel(ScHFEntryId eSel, bool bTravelling)
case ePagesEntry:
{
ClearTextAreas();
ESelection aSel(0,0,0,0);
ESelection aSel;
OUString aPageEntry( m_xFtPage->get_label() + " ");
m_xWndCenter->GetEditEngine()->SetTextCurrentDefaults(aPageEntry);
aSel.nEndPos = aPageEntry.getLength();
@@ -574,7 +574,7 @@ void ScHFEditPage::ProcessDefinedListSel(ScHFEntryId eSel, bool bTravelling)
case eFileNamePageEntry:
{
ClearTextAreas();
ESelection aSel(0,0,0,0);
ESelection aSel;
m_xWndCenter->GetEditEngine()->QuickInsertField(SvxFieldItem( SvxFileField(), EE_FEATURE_FIELD ), aSel );
++aSel.nEndPos;
OUString aPageEntry(", " + m_xFtPage->get_label() + " ");
@@ -600,7 +600,7 @@ void ScHFEditPage::ProcessDefinedListSel(ScHFEntryId eSel, bool bTravelling)
case ePageSheetEntry:
{
ClearTextAreas();
ESelection aSel(0,0,0,0);
ESelection aSel;
OUString aPageEntry( m_xFtPage->get_label() + " " );
m_xWndCenter->GetEditEngine()->SetTextCurrentDefaults(aPageEntry);
aSel.nEndPos = aPageEntry.getLength();
@@ -621,7 +621,7 @@ void ScHFEditPage::ProcessDefinedListSel(ScHFEntryId eSel, bool bTravelling)
case ePageFileNameEntry:
{
ClearTextAreas();
ESelection aSel(0,0,0,0);
ESelection aSel;
OUString aPageEntry( m_xFtPage->get_label() + " " );
m_xWndCenter->GetEditEngine()->SetTextCurrentDefaults(aPageEntry);
aSel.nEndPos = aPageEntry.getLength();
diff --git a/sc/source/ui/view/viewfun4.cxx b/sc/source/ui/view/viewfun4.cxx
index 17677ee..835c526 100644
--- a/sc/source/ui/view/viewfun4.cxx
+++ b/sc/source/ui/view/viewfun4.cxx
@@ -379,7 +379,7 @@ void ScViewFunc::DoThesaurus()
if (pEditSel)
pEditView->SetSelection(*pEditSel);
else
pEditView->SetSelection(ESelection(0,0,0,0));
pEditView->SetSelection(ESelection());
pThesaurusEngine->ClearModifyFlag();
diff --git a/sd/qa/unit/TextFittingTest.cxx b/sd/qa/unit/TextFittingTest.cxx
index 501c0c1..750614c 100644
--- a/sd/qa/unit/TextFittingTest.cxx
+++ b/sd/qa/unit/TextFittingTest.cxx
@@ -68,7 +68,7 @@ CPPUNIT_TEST_FIXTURE(TextFittingTest, testTest)
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), rEditEngine.GetParagraphCount());
// Add paragraph 4
rEditView.SetSelection(ESelection(3, 0, 3, 0));
rEditView.SetSelection(ESelection(3, 0));
rEditView.InsertText(u"\nD4"_ustr);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(sal_Int32(4), rEditEngine.GetParagraphCount());
@@ -77,7 +77,7 @@ CPPUNIT_TEST_FIXTURE(TextFittingTest, testTest)
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.8, rEditEngine.getScalingParameters().fSpacingY, 1E-4);
// Add paragraph 5
rEditView.SetSelection(ESelection(4, 0, 4, 0));
rEditView.SetSelection(ESelection(4, 0));
rEditView.InsertText(u"\nD5"_ustr);
CPPUNIT_ASSERT_EQUAL(sal_Int32(5), rEditEngine.GetParagraphCount());
@@ -85,7 +85,7 @@ CPPUNIT_TEST_FIXTURE(TextFittingTest, testTest)
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.8, rEditEngine.getScalingParameters().fSpacingY, 1E-4);
// Add paragraph 6
rEditView.SetSelection(ESelection(5, 0, 5, 0));
rEditView.SetSelection(ESelection(5, 0));
rEditView.InsertText(u"\nD6"_ustr);
CPPUNIT_ASSERT_EQUAL(sal_Int32(6), rEditEngine.GetParagraphCount());
diff --git a/sd/source/ui/func/futext.cxx b/sd/source/ui/func/futext.cxx
index d90aefc..446c583 100644
--- a/sd/source/ui/func/futext.cxx
+++ b/sd/source/ui/func/futext.cxx
@@ -1095,7 +1095,7 @@ void FuText::SetInEditMode(const MouseEvent& rMEvt, bool bQuickDrag)
else
{
// Move cursor to end of text
ESelection aNewSelection(EE_PARA_NOT_FOUND, EE_INDEX_NOT_FOUND, EE_PARA_NOT_FOUND, EE_INDEX_NOT_FOUND);
ESelection aNewSelection = ESelection::NotFound();
if (pOLV != nullptr)
pOLV->SetSelection(aNewSelection);
}
diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx
index 12f5490..5b6b797 100644
--- a/sd/source/ui/view/drviews2.cxx
+++ b/sd/source/ui/view/drviews2.cxx
@@ -409,7 +409,7 @@ private:
for (svx::ClassificationResult const & rResult : rResults)
{
ESelection aPosition(nParagraph, EE_TEXTPOS_MAX_COUNT, nParagraph, EE_TEXTPOS_MAX_COUNT);
ESelection aPosition(nParagraph, EE_TEXTPOS_MAX_COUNT);
switch (rResult.meType)
{
diff --git a/svx/inc/textchain.hxx b/svx/inc/textchain.hxx
index 0607052..4619285 100644
--- a/svx/inc/textchain.hxx
+++ b/svx/inc/textchain.hxx
@@ -50,8 +50,8 @@ protected:
{
aNilChainingEvent = false;
aCursorEvent = CursorChainingEvent::NULL_EVENT;
aPreChainingSel = ESelection(0, 0, 0, 0);
aPostChainingSel = ESelection(0, 0, 0, 0);
aPreChainingSel = ESelection();
aPostChainingSel = ESelection();
aIsPartOfLastParaInNextLink = false; // XXX: Should come from file
aSwitchingToNextBox = false;
}
diff --git a/svx/source/accessibility/AccessibleTextHelper.cxx b/svx/source/accessibility/AccessibleTextHelper.cxx
index c486ab8..d83f3fc 100644
--- a/svx/source/accessibility/AccessibleTextHelper.cxx
+++ b/svx/source/accessibility/AccessibleTextHelper.cxx
@@ -1157,8 +1157,7 @@ namespace accessibility
// change children state
maParaManager.SetActive( false );
maLastSelection = ESelection( EE_PARA_NOT_FOUND, EE_INDEX_NOT_FOUND,
EE_PARA_NOT_FOUND, EE_INDEX_NOT_FOUND);
maLastSelection = ESelection::NotFound();
break;
}
default:
diff --git a/svx/source/sdr/properties/textproperties.cxx b/svx/source/sdr/properties/textproperties.cxx
index 90c68df..38aa230 100644
--- a/svx/source/sdr/properties/textproperties.cxx
+++ b/svx/source/sdr/properties/textproperties.cxx
@@ -196,7 +196,7 @@ namespace sdr::properties
if(nParaCount)
{
ESelection aSelection( 0, 0, EE_PARA_ALL, EE_TEXTPOS_ALL);
auto aSelection = ESelection::All();
rOutliner.RemoveAttribs(aSelection, true, 0);
std::optional<OutlinerParaObject> pTemp = rOutliner.CreateParaObject(0, nParaCount);
diff --git a/svx/source/svdraw/svdotxat.cxx b/svx/source/svdraw/svdotxat.cxx
index 7e696f6..b6029f9 100644
--- a/svx/source/svdraw/svdotxat.cxx
+++ b/svx/source/svdraw/svdotxat.cxx
@@ -403,7 +403,7 @@ void SdrTextObj::RemoveOutlinerCharacterAttribs( const std::vector<sal_uInt16>&
pOutliner->SetText(*pOutlinerParaObject);
}
ESelection aSelAll( 0, 0, EE_PARA_ALL, EE_TEXTPOS_ALL );
auto aSelAll = ESelection::All();
for( const auto& rWhichId : rCharWhichIds )
{
pOutliner->RemoveAttribs( aSelAll, false, rWhichId );
diff --git a/svx/source/svdraw/svdview.cxx b/svx/source/svdraw/svdview.cxx
index 36e7fce..a1e134f 100644
--- a/svx/source/svdraw/svdview.cxx
+++ b/svx/source/svdraw/svdview.cxx
@@ -1361,7 +1361,7 @@ SdrViewContext SdrView::GetContext() const
void SdrView::MarkAll()
{
if (IsTextEdit()) {
GetTextEditOutlinerView()->SetSelection(ESelection(0,0,EE_PARA_ALL,EE_TEXTPOS_ALL));
GetTextEditOutlinerView()->SetSelection(ESelection::All());
} else if (IsGluePointEditMode()) MarkAllGluePoints();
else if (HasMarkablePoints()) MarkAllPoints();
else {
diff --git a/svx/source/table/cell.cxx b/svx/source/table/cell.cxx
index c10c431..9073266 100644
--- a/svx/source/table/cell.cxx
+++ b/svx/source/table/cell.cxx
@@ -1613,7 +1613,7 @@ void SAL_CALL Cell::setAllPropertiesToDefault()
if(nParaCount)
{
ESelection aSelection( 0, 0, EE_PARA_ALL, EE_TEXTPOS_ALL);
auto aSelection = ESelection::All();
rOutliner.RemoveAttribs(aSelection, true, 0);
std::optional<OutlinerParaObject> pTemp = rOutliner.CreateParaObject(0, nParaCount);
diff --git a/svx/source/table/tablecontroller.cxx b/svx/source/table/tablecontroller.cxx
index 85f5cb6..a888f66 100644
--- a/svx/source/table/tablecontroller.cxx
+++ b/svx/source/table/tablecontroller.cxx
@@ -2099,7 +2099,7 @@ void SvxTableController::EditCell(const CellPos& rPos, vcl::Window* pWindow, Tbl
((nAction == TblAction::GotoRightCell) && (eMode == WritingMode_RL_TB));
if( bLast )
aNewSelection = ESelection(EE_PARA_NOT_FOUND, EE_INDEX_NOT_FOUND, EE_PARA_NOT_FOUND, EE_INDEX_NOT_FOUND);
aNewSelection = ESelection::NotFound();
}
pOLV->SetSelection(aNewSelection);
}