chart2/source/controller/main/ChartController_TextEdit.cxx | 3 cui/inc/pch/precompiled_cui.hxx | 1 cui/source/dialogs/SpellDialog.cxx | 22 - dbaccess/source/ui/app/DocumentInfoPreview.cxx | 18 - dbaccess/source/ui/control/sqledit.cxx | 14 editeng/qa/unit/ESelectionTest.cxx | 49 +- editeng/source/accessibility/AccessibleEditableTextPara.cxx | 50 +- editeng/source/accessibility/AccessibleImageBullet.cxx | 2 editeng/source/accessibility/AccessibleStaticTextBase.cxx | 52 +- editeng/source/editeng/editdbg.cxx | 2 editeng/source/editeng/editdoc.cxx | 6 editeng/source/editeng/editeng.cxx | 77 ++-- editeng/source/editeng/editobj.cxx | 4 editeng/source/editeng/editundo.cxx | 4 editeng/source/editeng/editview.cxx | 44 +- editeng/source/editeng/edtspell.cxx | 2 editeng/source/editeng/eertfpar.cxx | 4 editeng/source/editeng/impedit.cxx | 83 ++-- editeng/source/editeng/impedit.hxx | 26 - editeng/source/editeng/impedit2.cxx | 49 +- editeng/source/editeng/impedit3.cxx | 10 editeng/source/editeng/impedit4.cxx | 4 editeng/source/editeng/impedit5.cxx | 3 editeng/source/editeng/textconv.cxx | 38 +- editeng/source/misc/urlfieldhelper.cxx | 7 editeng/source/outliner/outlin2.cxx | 6 editeng/source/outliner/outliner.cxx | 10 editeng/source/outliner/outlobj.cxx | 4 editeng/source/outliner/outlvw.cxx | 102 ++--- editeng/source/outliner/overflowingtxt.cxx | 8 editeng/source/outliner/paralist.cxx | 8 editeng/source/uno/unoedhlp.cxx | 2 editeng/source/uno/unoedprx.cxx | 66 +-- editeng/source/uno/unofored.cxx | 30 - editeng/source/uno/unoforou.cxx | 24 - editeng/source/uno/unotext.cxx | 172 +++------ editeng/source/uno/unotext2.cxx | 29 - editeng/source/xml/xmltxtimp.cxx | 18 - filter/source/msfilter/msdffimp.cxx | 6 filter/source/msfilter/svdfppt.cxx | 23 - forms/source/richtext/specialdispatchers.cxx | 7 include/editeng/EPaM.hxx | 20 - include/editeng/EPosition.hxx | 49 -- include/editeng/ESelection.hxx | 92 ++--- include/editeng/editdata.hxx | 19 - include/editeng/editeng.hxx | 8 include/editeng/outliner.hxx | 8 sc/qa/extras/scpdfexport.cxx | 7 sc/qa/unit/subsequent_export_test.cxx | 21 - sc/qa/unit/ucalc.cxx | 11 sc/source/core/data/stlpool.cxx | 10 sc/source/core/tool/editutil.cxx | 3 sc/source/filter/excel/xehelper.cxx | 16 sc/source/filter/excel/xicontent.cxx | 4 sc/source/filter/excel/xihelper.cxx | 30 - sc/source/filter/html/htmlpars.cxx | 63 +-- sc/source/filter/oox/richstring.cxx | 11 sc/source/filter/orcus/interface.cxx | 5 sc/source/filter/rtf/eeimpars.cxx | 10 sc/source/filter/rtf/rtfparse.cxx | 20 - sc/source/filter/xml/xmlcelli.cxx | 13 sc/source/filter/xml/xmlexprt.cxx | 2 sc/source/ui/app/inputhdl.cxx | 212 +++++------- sc/source/ui/app/inputwin.cxx | 7 sc/source/ui/docshell/docsh4.cxx | 4 sc/source/ui/drawfunc/drtxtob.cxx | 14 sc/source/ui/drawfunc/futext.cxx | 3 sc/source/ui/formdlg/dwfunctr.cxx | 2 sc/source/ui/pagedlg/scuitphfedit.cxx | 52 +- sc/source/ui/unoobj/cellsuno.cxx | 9 sc/source/ui/unoobj/fielduno.cxx | 27 - sc/source/ui/unoobj/textuno.cxx | 27 - sc/source/ui/view/cellsh1.cxx | 4 sc/source/ui/view/editsh.cxx | 30 - sc/source/ui/view/gridwin.cxx | 6 sc/source/ui/view/tabvwshe.cxx | 4 sc/source/ui/view/viewfun4.cxx | 6 sd/qa/unit/TextFittingTest.cxx | 6 sd/qa/unit/tiledrendering/tiledrendering.cxx | 10 sd/qa/unit/uiimpress.cxx | 2 sd/source/ui/annotations/annotationmanager.cxx | 6 sd/source/ui/annotations/annotationwindow.cxx | 5 sd/source/ui/dlg/headerfooterdlg.cxx | 2 sd/source/ui/docshell/docshel3.cxx | 4 sd/source/ui/func/fubullet.cxx | 6 sd/source/ui/func/fuinsfil.cxx | 3 sd/source/ui/func/fuparagr.cxx | 8 sd/source/ui/func/futext.cxx | 9 sd/source/ui/unoidl/unosrch.cxx | 20 - sd/source/ui/view/NotesPanelViewShell.cxx | 20 - sd/source/ui/view/Outliner.cxx | 18 - sd/source/ui/view/drtxtob.cxx | 4 sd/source/ui/view/drtxtob1.cxx | 16 sd/source/ui/view/drviews2.cxx | 24 - sd/source/ui/view/drviews4.cxx | 8 sd/source/ui/view/drviews7.cxx | 4 sd/source/ui/view/drviewse.cxx | 18 - sd/source/ui/view/drviewsf.cxx | 2 sd/source/ui/view/outlnvs2.cxx | 16 sd/source/ui/view/outlnvsh.cxx | 5 sd/source/ui/view/sdview2.cxx | 3 starmath/inc/mathml/element.hxx | 4 starmath/inc/node.hxx | 4 starmath/qa/cppunit/test_starmath.cxx | 16 starmath/source/cursor.cxx | 2 starmath/source/edit.cxx | 64 +-- starmath/source/node.cxx | 4 starmath/source/smediteng.cxx | 6 starmath/source/view.cxx | 12 svx/source/accessibility/AccessibleTextHelper.cxx | 94 ++--- svx/source/annotation/TextAPI.cxx | 2 svx/source/dialog/ClassificationEditView.cxx | 2 svx/source/dialog/weldeditview.cxx | 40 +- svx/source/sdr/properties/textproperties.cxx | 10 svx/source/svdraw/svdedxv.cxx | 21 - svx/source/svdraw/svdview.cxx | 15 svx/source/svdraw/textchaincursor.cxx | 5 svx/source/svdraw/textchainflow.cxx | 4 svx/source/table/cell.cxx | 4 svx/source/table/tablecontroller.cxx | 2 svx/source/table/tablehtmlimporter.cxx | 8 svx/source/table/tablertfimporter.cxx | 8 sw/source/core/doc/DocumentDrawModelManager.cxx | 4 sw/source/filter/ww8/ww8graf.cxx | 6 sw/source/ui/dbui/mmaddressblockpage.cxx | 78 ++-- sw/source/uibase/dialog/SwSpellDialogChildWindow.cxx | 4 sw/source/uibase/docvw/AnnotationWin.cxx | 4 sw/source/uibase/docvw/AnnotationWin2.cxx | 3 sw/source/uibase/docvw/PostItMgr.cxx | 5 sw/source/uibase/docvw/edtwin.cxx | 5 sw/source/uibase/shells/annotsh.cxx | 5 sw/source/uibase/shells/drwtxtex.cxx | 7 sw/source/uibase/shells/drwtxtsh.cxx | 3 sw/source/uibase/shells/langhelper.cxx | 6 sw/source/uibase/uiview/viewdraw.cxx | 2 vcl/inc/pch/precompiled_vcl.hxx | 1 136 files changed, 1155 insertions(+), 1442 deletions(-)
New commits: commit f9cac88fc24539eb5f7fa501b2499ddf5a46d7f2 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Wed Nov 20 21:32:16 2024 +0500 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Sun Nov 24 08:12:55 2024 +0100 Let ESelection use EPaM for simplification And drop EPosition, which duplicates EPaM, except for its default ctor (used in a single place). Change-Id: I48bb6dafcba84465d61579df0ec71b815945532a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177075 Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> Tested-by: Jenkins diff --git a/chart2/source/controller/main/ChartController_TextEdit.cxx b/chart2/source/controller/main/ChartController_TextEdit.cxx index bc8e65409130..bfbacd95a90c 100644 --- a/chart2/source/controller/main/ChartController_TextEdit.cxx +++ b/chart2/source/controller/main/ChartController_TextEdit.cxx @@ -271,8 +271,7 @@ void ChartController::executeDispatch_InsertSpecialCharacter() pOutlinerView->InsertText(aString, true); ESelection aSel = pOutlinerView->GetSelection(); - aSel.nStartPara = aSel.nEndPara; - aSel.nStartPos = aSel.nEndPos; + aSel.CollapseToEnd(); pOutlinerView->SetSelection(aSel); // show changes diff --git a/cui/inc/pch/precompiled_cui.hxx b/cui/inc/pch/precompiled_cui.hxx index e007aea1cfa3..d968cc45fb23 100644 --- a/cui/inc/pch/precompiled_cui.hxx +++ b/cui/inc/pch/precompiled_cui.hxx @@ -298,7 +298,6 @@ #include <drawinglayer/primitive2d/Primitive2DContainer.hxx> #include <drawinglayer/primitive2d/Primitive2DVisitor.hxx> #include <drawinglayer/primitive2d/baseprimitive2d.hxx> -#include <editeng/EPosition.hxx> #include <editeng/ESelection.hxx> #include <editeng/editdata.hxx> #include <editeng/editengdllapi.h> diff --git a/cui/source/dialogs/SpellDialog.cxx b/cui/source/dialogs/SpellDialog.cxx index 279ed4c9f4c4..7ee6de654530 100644 --- a/cui/source/dialogs/SpellDialog.cxx +++ b/cui/source/dialogs/SpellDialog.cxx @@ -1350,7 +1350,7 @@ bool SentenceEditWindow_Impl::KeyInput(const KeyEvent& rKeyEvt) std::vector<EECharAttrib> aAttribList; m_xEditEngine->GetCharAttribs(0, aAttribList); - auto nCursor = aCurrentSelection.nStartPos; + auto nCursor = aCurrentSelection.start.nIndex; const EECharAttrib* pBackAttr = FindCharAttrib(nCursor, EE_CHAR_BKGCOLOR, aAttribList); const EECharAttrib* pErrorAttr = FindCharAttrib(nCursor, EE_CHAR_GRABBAG, aAttribList); const EECharAttrib* pBackAttrLeft = nullptr; @@ -1361,21 +1361,21 @@ bool SentenceEditWindow_Impl::KeyInput(const KeyEvent& rKeyEvt) if (bHasRange) { if (pBackAttr && - pBackAttr->nStart == aCurrentSelection.nStartPos && - pBackAttr->nEnd == aCurrentSelection.nEndPos) + pBackAttr->nStart == aCurrentSelection.start.nIndex && + pBackAttr->nEnd == aCurrentSelection.end.nIndex) { nSelectionType = FULL; } else if (pErrorAttr && - pErrorAttr->nStart <= aCurrentSelection.nStartPos && - pErrorAttr->nEnd >= aCurrentSelection.nEndPos) + pErrorAttr->nStart <= aCurrentSelection.start.nIndex && + pErrorAttr->nEnd >= aCurrentSelection.end.nIndex) { nSelectionType = INSIDE_YES; } else { nSelectionType = bHasField||bHasError ? BRACE : OUTSIDE_NO; - while (nCursor < aCurrentSelection.nEndPos) + while (nCursor < aCurrentSelection.end.nIndex) { ++nCursor; const EECharAttrib* pIntBackAttr = FindCharAttrib(nCursor, EE_CHAR_BKGCOLOR, aAttribList); @@ -1396,8 +1396,8 @@ bool SentenceEditWindow_Impl::KeyInput(const KeyEvent& rKeyEvt) const EECharAttrib* pCurAttr = pBackAttr ? pBackAttr : pErrorAttr; if (pCurAttr) { - nSelectionType = pCurAttr->nStart == aCurrentSelection.nStartPos ? - LEFT_NO : pCurAttr->nEnd == aCurrentSelection.nEndPos ? RIGHT_NO : INSIDE_NO; + nSelectionType = pCurAttr->nStart == aCurrentSelection.start.nIndex ? + LEFT_NO : pCurAttr->nEnd == aCurrentSelection.end.nIndex ? RIGHT_NO : INSIDE_NO; } else nSelectionType = OUTSIDE_NO; @@ -1747,7 +1747,7 @@ bool SentenceEditWindow_Impl::MarkNextError( bool bIgnoreCurrentError, const css void SentenceEditWindow_Impl::MoveErrorMarkTo(sal_Int32 nStart, sal_Int32 nEnd, bool bGrammarError) { - ESelection aAll(0, 0, 0, EE_TEXTPOS_ALL); + ESelection aAll(m_xEditEngine->NormalizeESelection(ESelection::All())); m_xEditEngine->RemoveAttribs(aAll, false, EE_CHAR_COLOR); m_xEditEngine->RemoveAttribs(aAll, false, EE_CHAR_WEIGHT); m_xEditEngine->RemoveAttribs(aAll, false, EE_CHAR_WEIGHT_CJK); @@ -1769,7 +1769,7 @@ void SentenceEditWindow_Impl::MoveErrorMarkTo(sal_Int32 nStart, sal_Int32 nEnd, // unless (tdf#133958) the selection already overlaps this range ESelection aCurrentSelection = m_xEditView->GetSelection(); aCurrentSelection.Adjust(); - bool bCurrentSelectionInRange = nStart <= aCurrentSelection.nEndPos && aCurrentSelection.nStartPos <= nEnd; + bool bCurrentSelectionInRange = nStart <= aCurrentSelection.end.nIndex && aCurrentSelection.start.nIndex <= nEnd; if (!bCurrentSelectionInRange) { m_xEditView->SetSelection(ESelection(0, nStart)); @@ -2160,7 +2160,7 @@ void SentenceEditWindow_Impl::SetUndoEditMode(bool bSet) pWidget->set_sensitive(false); //remove error marks - ESelection aAll(0, 0, 0, EE_TEXTPOS_ALL); + ESelection aAll(m_xEditEngine->NormalizeESelection(ESelection::All())); m_xEditEngine->RemoveAttribs(aAll, false, EE_CHAR_COLOR); m_xEditEngine->RemoveAttribs(aAll, false, EE_CHAR_WEIGHT); m_xEditEngine->RemoveAttribs(aAll, false, EE_CHAR_WEIGHT_CJK); diff --git a/dbaccess/source/ui/app/DocumentInfoPreview.cxx b/dbaccess/source/ui/app/DocumentInfoPreview.cxx index f12de3fbe515..890e19eb2dc2 100644 --- a/dbaccess/source/ui/app/DocumentInfoPreview.cxx +++ b/dbaccess/source/ui/app/DocumentInfoPreview.cxx @@ -103,28 +103,18 @@ void ODocumentInfoPreview::fill( } } - m_xEditView->SetSelection(ESelection(0, 0, 0, 0)); -} - -namespace -{ - ESelection InsertAtEnd(const EditEngine& rEditEngine) - { - const sal_uInt32 nPara = rEditEngine.GetParagraphCount() -1; - sal_Int32 nLastLen = rEditEngine.GetText(nPara).getLength(); - return ESelection(nPara, nLastLen, nPara, nLastLen); - } + m_xEditView->SetSelection(ESelection(0, 0)); } void ODocumentInfoPreview::insertEntry( std::u16string_view title, OUString const & value) { if (m_xEditEngine->HasText()) { - m_xEditEngine->QuickInsertText(u" "_ustr, InsertAtEnd(*m_xEditEngine)); + m_xEditEngine->QuickInsertText(u" "_ustr, ESelection::AtEnd()); } OUString caption(OUString::Concat(title) + ": "); - m_xEditEngine->QuickInsertText(caption, InsertAtEnd(*m_xEditEngine)); + m_xEditEngine->QuickInsertText(caption, ESelection::AtEnd()); SfxItemSet aSet(m_xEditEngine->GetEmptyItemSet()); aSet.Put(SvxWeightItem(WEIGHT_BOLD, EE_CHAR_WEIGHT)); @@ -133,7 +123,7 @@ void ODocumentInfoPreview::insertEntry( int nCaptionPara = m_xEditEngine->GetParagraphCount() - 2; m_xEditEngine->QuickSetAttribs(aSet, ESelection(nCaptionPara, 0, nCaptionPara, caption.getLength() - 1)); - m_xEditEngine->QuickInsertText(value, InsertAtEnd(*m_xEditEngine)); + m_xEditEngine->QuickInsertText(value, ESelection::AtEnd()); } void ODocumentInfoPreview::insertNonempty(tools::Long id, OUString const & value) diff --git a/dbaccess/source/ui/control/sqledit.cxx b/dbaccess/source/ui/control/sqledit.cxx index b616f1303ac8..70aa8b23aff2 100644 --- a/dbaccess/source/ui/control/sqledit.cxx +++ b/dbaccess/source/ui/control/sqledit.cxx @@ -203,7 +203,7 @@ void SQLEditView::UpdateData() { OUString aLine( rEditEngine.GetText( nLine ) ); - ESelection aAllLine(nLine, 0, nLine, EE_TEXTPOS_ALL); + ESelection aAllLine(nLine, 0, nLine, EE_TEXTPOS_MAX); rEditEngine.RemoveAttribs(aAllLine, false, EE_CHAR_COLOR); rEditEngine.RemoveAttribs(aAllLine, false, EE_CHAR_WEIGHT); rEditEngine.RemoveAttribs(aAllLine, false, EE_CHAR_WEIGHT_CJK); @@ -234,8 +234,8 @@ void SQLEditView::UpdateData() void SQLEditView::DoBracketHilight(sal_uInt16 nKey) { ESelection aCurrentPos = m_xEditView->GetSelection(); - sal_Int32 nStartPos = aCurrentPos.nStartPos; - const sal_uInt32 nStartPara = aCurrentPos.nStartPara; + sal_Int32 nStartPos = aCurrentPos.start.nIndex; + const sal_uInt32 nStartPara = aCurrentPos.start.nPara; sal_uInt16 nCount = 0; int nChar = -1; @@ -294,7 +294,7 @@ void SQLEditView::DoBracketHilight(sal_uInt16 nKey) aSet.Put(SvxWeightItem(WEIGHT_ULTRABOLD, EE_CHAR_WEIGHT_CTL)); m_xEditEngine->QuickSetAttribs(aSet, ESelection(nPara, i, nPara, i + 1)); - m_xEditEngine->QuickSetAttribs(aSet, ESelection(nStartPara, nStartPos, nStartPara, nStartPos)); + m_xEditEngine->QuickSetAttribs(aSet, ESelection(nStartPara, nStartPos)); return; } else @@ -415,11 +415,9 @@ bool SQLEditView::Command(const CommandEvent& rCEvt) pEditView->DeleteSelected(); else if (sCommand == "selectall") { - sal_Int32 nPar = m_xEditEngine->GetParagraphCount(); - if (nPar) + if (m_xEditEngine->GetParagraphCount()) { - sal_Int32 nLen = m_xEditEngine->GetTextLen(nPar - 1); - pEditView->SetSelection(ESelection(0, 0, nPar - 1, nLen)); + pEditView->SetSelection(ESelection::All()); } } else if (sCommand == "specialchar") diff --git a/editeng/qa/unit/ESelectionTest.cxx b/editeng/qa/unit/ESelectionTest.cxx index 27b9256b29d7..264a0aa2c7ac 100644 --- a/editeng/qa/unit/ESelectionTest.cxx +++ b/editeng/qa/unit/ESelectionTest.cxx @@ -20,42 +20,42 @@ CPPUNIT_TEST_FIXTURE(ESelectionTest, testConstruction) { { ESelection aNewSelection; - CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewSelection.nStartPara); - CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewSelection.nStartPos); - CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewSelection.nEndPara); - CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewSelection.nEndPos); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewSelection.start.nPara); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewSelection.start.nIndex); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewSelection.end.nPara); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewSelection.end.nIndex); } { ESelection aNewSelection(1, 2, 3, 4); - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNewSelection.nStartPara); - CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewSelection.nStartPos); - CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aNewSelection.nEndPara); - CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aNewSelection.nEndPos); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNewSelection.start.nPara); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewSelection.start.nIndex); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aNewSelection.end.nPara); + CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aNewSelection.end.nIndex); } { ESelection aNewSelection = { 1, 2, 3, 4 }; - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNewSelection.nStartPara); - CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewSelection.nStartPos); - CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aNewSelection.nEndPara); - CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aNewSelection.nEndPos); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNewSelection.start.nPara); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewSelection.start.nIndex); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aNewSelection.end.nPara); + CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aNewSelection.end.nIndex); } { ESelection aNewSelection{ 1, 2, 3, 4 }; - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNewSelection.nStartPara); - CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewSelection.nStartPos); - CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aNewSelection.nEndPara); - CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aNewSelection.nEndPos); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNewSelection.start.nPara); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewSelection.start.nIndex); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aNewSelection.end.nPara); + CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aNewSelection.end.nIndex); } { ESelection aNewSelection(1, 2); - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNewSelection.nStartPara); - CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewSelection.nStartPos); - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNewSelection.nEndPara); - CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewSelection.nEndPos); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNewSelection.start.nPara); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewSelection.start.nIndex); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNewSelection.end.nPara); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewSelection.end.nIndex); } } @@ -98,15 +98,6 @@ CPPUNIT_TEST_FIXTURE(ESelectionTest, testEquals) CPPUNIT_ASSERT_EQUAL(aSelection1, aSelection2); } -CPPUNIT_TEST_FIXTURE(ESelectionTest, testIsZero) -{ - ESelection aEmpty; - CPPUNIT_ASSERT_EQUAL(true, aEmpty.IsZero()); - - CPPUNIT_ASSERT_EQUAL(false, ESelection(1, 2, 1, 2).IsZero()); - CPPUNIT_ASSERT_EQUAL(true, ESelection(0, 0, 0, 0).IsZero()); -} - CPPUNIT_TEST_FIXTURE(ESelectionTest, testLess) { // Both equal diff --git a/editeng/source/accessibility/AccessibleEditableTextPara.cxx b/editeng/source/accessibility/AccessibleEditableTextPara.cxx index 26bee59e731d..a5c4c3b3bdb3 100644 --- a/editeng/source/accessibility/AccessibleEditableTextPara.cxx +++ b/editeng/source/accessibility/AccessibleEditableTextPara.cxx @@ -374,35 +374,35 @@ namespace accessibility if( !GetEditViewForwarder().GetSelection( aSelection ) ) return false; - if( aSelection.nStartPara < aSelection.nEndPara ) + if( aSelection.start.nPara < aSelection.end.nPara ) { - if( aSelection.nStartPara > nPara || - aSelection.nEndPara < nPara ) + if( aSelection.start.nPara > nPara || + aSelection.end.nPara < nPara ) return false; - if( nPara == aSelection.nStartPara ) - nStartPos = aSelection.nStartPos; + if( nPara == aSelection.start.nPara ) + nStartPos = aSelection.start.nIndex; else nStartPos = 0; - if( nPara == aSelection.nEndPara ) - nEndPos = aSelection.nEndPos; + if( nPara == aSelection.end.nPara ) + nEndPos = aSelection.end.nIndex; else nEndPos = GetTextLen(); } else { - if( aSelection.nStartPara < nPara || - aSelection.nEndPara > nPara ) + if( aSelection.start.nPara < nPara || + aSelection.end.nPara > nPara ) return false; - if( nPara == aSelection.nStartPara ) - nStartPos = aSelection.nStartPos; + if( nPara == aSelection.start.nPara ) + nStartPos = aSelection.start.nIndex; else nStartPos = GetTextLen(); - if( nPara == aSelection.nEndPara ) - nEndPos = aSelection.nEndPos; + if( nPara == aSelection.end.nPara ) + nEndPos = aSelection.end.nIndex; else nEndPos = 0; } @@ -983,7 +983,7 @@ namespace accessibility EBulletInfo aBulletInfo = rCacheTF.GetBulletInfo(GetParagraphIndex()); - if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND && + if( aBulletInfo.nParagraph != EE_PARA_MAX && aBulletInfo.bVisible && aBulletInfo.nType == SVX_NUM_BITMAP ) { @@ -1119,19 +1119,19 @@ namespace accessibility ESelection aSelection; if( GetEditViewForwarder().GetSelection( aSelection ) && - GetParagraphIndex() == aSelection.nEndPara ) + GetParagraphIndex() == aSelection.end.nPara ) { // caret is always nEndPara,nEndPos EBulletInfo aBulletInfo = GetTextForwarder().GetBulletInfo(GetParagraphIndex()); - if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND && + if( aBulletInfo.nParagraph != EE_PARA_MAX && aBulletInfo.bVisible && aBulletInfo.nType != SVX_NUM_BITMAP ) { sal_Int32 nBulletLen = aBulletInfo.aText.getLength(); - if( aSelection.nEndPos - nBulletLen >= 0 ) - return aSelection.nEndPos - nBulletLen; + if( aSelection.end.nIndex - nBulletLen >= 0 ) + return aSelection.end.nIndex - nBulletLen; } - return aSelection.nEndPos; + return aSelection.end.nIndex; } // not within this paragraph @@ -2048,7 +2048,7 @@ namespace accessibility //Because bullet may occupy one or more characters, the TextAdapter will include bullet to calculate the selection. Add offset to handle bullet sal_Int32 nBulletLen = 0; EBulletInfo aBulletInfo = GetTextForwarder().GetBulletInfo(GetParagraphIndex()); - if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND && aBulletInfo.bVisible ) + if( aBulletInfo.nParagraph != EE_PARA_MAX && aBulletInfo.bVisible ) nBulletLen = aBulletInfo.aText.getLength(); // save current selection ESelection aOldSelection; @@ -2091,7 +2091,7 @@ namespace accessibility // Because bullet may occupy one or more characters, the TextAdapter will include bullet to calculate the selection. Add offset to handle bullet sal_Int32 nBulletLen = 0; EBulletInfo aBulletInfo = GetTextForwarder().GetBulletInfo(GetParagraphIndex()); - if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND && aBulletInfo.bVisible ) + if( aBulletInfo.nParagraph != EE_PARA_MAX && aBulletInfo.bVisible ) nBulletLen = aBulletInfo.aText.getLength(); ESelection aSelection = MakeSelection (nStartIndex + nBulletLen, nEndIndex + nBulletLen); //if( !rCacheTF.IsEditable( MakeSelection(nStartIndex, nEndIndex) ) ) @@ -2128,7 +2128,7 @@ namespace accessibility // Because bullet may occupy one or more characters, the TextAdapter will include bullet to calculate the selection. Add offset to handle bullet sal_Int32 nBulletLen = 0; EBulletInfo aBulletInfo = GetTextForwarder().GetBulletInfo(GetParagraphIndex()); - if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND && aBulletInfo.bVisible ) + if( aBulletInfo.nParagraph != EE_PARA_MAX && aBulletInfo.bVisible ) nBulletLen = aBulletInfo.aText.getLength(); if( !rCacheTF.IsEditable( MakeSelection(nIndex + nBulletLen) ) ) return false; // non-editable area selected @@ -2165,7 +2165,7 @@ namespace accessibility // Because bullet may occupy one or more characters, the TextAdapter will include bullet to calculate the selection. Add offset to handle bullet sal_Int32 nBulletLen = 0; EBulletInfo aBulletInfo = GetTextForwarder().GetBulletInfo(GetParagraphIndex()); - if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND && aBulletInfo.bVisible ) + if( aBulletInfo.nParagraph != EE_PARA_MAX && aBulletInfo.bVisible ) nBulletLen = aBulletInfo.aText.getLength(); ESelection aSelection = MakeSelection (nStartIndex + nBulletLen, nEndIndex + nBulletLen); @@ -2206,7 +2206,7 @@ namespace accessibility // Because bullet may occupy one or more characters, the TextAdapter will include bullet to calculate the selection. Add offset to handle bullet sal_Int32 nBulletLen = 0; EBulletInfo aBulletInfo = GetTextForwarder().GetBulletInfo(GetParagraphIndex()); - if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND && aBulletInfo.bVisible ) + if( aBulletInfo.nParagraph != EE_PARA_MAX && aBulletInfo.bVisible ) nBulletLen = aBulletInfo.aText.getLength(); if( !rCacheTF.IsEditable( MakeSelection(nIndex + nBulletLen) ) ) @@ -2246,7 +2246,7 @@ namespace accessibility // Because bullet may occupy one or more characters, the TextAdapter will include bullet to calculate the selection. Add offset to handle bullet sal_Int32 nBulletLen = 0; EBulletInfo aBulletInfo = GetTextForwarder().GetBulletInfo(GetParagraphIndex()); - if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND && aBulletInfo.bVisible ) + if( aBulletInfo.nParagraph != EE_PARA_MAX && aBulletInfo.bVisible ) nBulletLen = aBulletInfo.aText.getLength(); ESelection aSelection = MakeSelection (nStartIndex + nBulletLen, nEndIndex + nBulletLen); diff --git a/editeng/source/accessibility/AccessibleImageBullet.cxx b/editeng/source/accessibility/AccessibleImageBullet.cxx index 5d07e71be0f9..5870e3300c95 100644 --- a/editeng/source/accessibility/AccessibleImageBullet.cxx +++ b/editeng/source/accessibility/AccessibleImageBullet.cxx @@ -231,7 +231,7 @@ namespace accessibility EBulletInfo aBulletInfo = rCacheTF.GetBulletInfo( GetParagraphIndex() ); tools::Rectangle aParentRect = rCacheTF.GetParaBounds( GetParagraphIndex() ); - if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND && + if( aBulletInfo.nParagraph != EE_PARA_MAX && aBulletInfo.bVisible && aBulletInfo.nType == SVX_NUM_BITMAP ) { diff --git a/editeng/source/accessibility/AccessibleStaticTextBase.cxx b/editeng/source/accessibility/AccessibleStaticTextBase.cxx index 7d22150e1503..e318dc4eecba 100644 --- a/editeng/source/accessibility/AccessibleStaticTextBase.cxx +++ b/editeng/source/accessibility/AccessibleStaticTextBase.cxx @@ -131,19 +131,19 @@ namespace accessibility AccessibleEditableTextPara& GetParagraph( sal_Int32 nPara ) const; sal_Int32 GetParagraphCount() const; - EPosition Index2Internal( sal_Int32 nFlatIndex ) const + EPaM Index2Internal( sal_Int32 nFlatIndex ) const { return ImpCalcInternal( nFlatIndex, false ); } - EPosition Range2Internal( sal_Int32 nFlatIndex ) const + EPaM Range2Internal( sal_Int32 nFlatIndex ) const { return ImpCalcInternal( nFlatIndex, true ); } - sal_Int32 Internal2Index( EPosition nEEIndex ) const; + sal_Int32 Internal2Index( EPaM nEEIndex ) const; void CorrectTextSegment( TextSegment& aTextSegment, int nPara ) const; @@ -158,7 +158,7 @@ namespace accessibility private: - EPosition ImpCalcInternal( sal_Int32 nFlatIndex, bool bExclusive ) const; + EPaM ImpCalcInternal( sal_Int32 nFlatIndex, bool bExclusive ) const; // our frontend class (the one implementing the actual // interface). That's not necessarily the one containing the impl @@ -233,7 +233,7 @@ namespace accessibility return mxTextParagraph->GetTextForwarder().GetParagraphCount(); } - sal_Int32 AccessibleStaticTextBase_Impl::Internal2Index( EPosition nEEIndex ) const + sal_Int32 AccessibleStaticTextBase_Impl::Internal2Index(EPaM nEEIndex) const { // XXX checks for overflow and returns maximum if so sal_Int32 aRes(0); @@ -268,7 +268,7 @@ namespace accessibility } } - EPosition AccessibleStaticTextBase_Impl::ImpCalcInternal( sal_Int32 nFlatIndex, bool bExclusive ) const + EPaM AccessibleStaticTextBase_Impl::ImpCalcInternal(sal_Int32 nFlatIndex, bool bExclusive) const { if( nFlatIndex < 0 ) @@ -288,7 +288,7 @@ namespace accessibility nFlatIndex - nCurrIndex + nCurrCount >= 0, "AccessibleStaticTextBase_Impl::Index2Internal: index value overflow"); - return EPosition(nCurrPara, nFlatIndex - nCurrIndex + nCurrCount); + return EPaM(nCurrPara, nFlatIndex - nCurrIndex + nCurrCount); } } @@ -300,7 +300,7 @@ namespace accessibility nFlatIndex - nCurrIndex + nCurrCount >= 0, "AccessibleStaticTextBase_Impl::Index2Internal: index value overflow"); - return EPosition(nCurrPara-1, nFlatIndex - nCurrIndex + nCurrCount); + return EPaM(nCurrPara - 1, nFlatIndex - nCurrIndex + nCurrCount); } // not found? Out of bounds @@ -507,7 +507,7 @@ namespace accessibility { SolarMutexGuard aGuard; - EPosition aPos( mpImpl->Index2Internal(nIndex) ); + EPaM aPos(mpImpl->Index2Internal(nIndex)); return mpImpl->GetParagraph( aPos.nPara ).getCharacter( aPos.nIndex ); } @@ -519,7 +519,7 @@ namespace accessibility //get the actual index without " " mpImpl->RemoveLineBreakCount( nIndex ); - EPosition aPos( mpImpl->Index2Internal(nIndex) ); + EPaM aPos(mpImpl->Index2Internal(nIndex)); return mpImpl->GetParagraph( aPos.nPara ).getCharacterAttributes( aPos.nIndex, aRequestedAttributes ); } @@ -530,7 +530,7 @@ namespace accessibility // #108900# Allow ranges for nIndex, as one-past-the-end // values are now legal, too. - EPosition aPos( mpImpl->Range2Internal(nIndex) ); + EPaM aPos(mpImpl->Range2Internal(nIndex)); // #i70916# Text in spread sheet cells return the wrong extents AccessibleEditableTextPara& rPara = mpImpl->GetParagraph( aPos.nPara ); @@ -575,7 +575,7 @@ namespace accessibility // #112814# Use correct index offset if ( ( nIndex = rPara.getIndexAtPoint( aPoint ) ) != -1 ) - return mpImpl->Internal2Index(EPosition(i, nIndex)); + return mpImpl->Internal2Index(EPaM(i, nIndex)); } return -1; @@ -627,8 +627,8 @@ namespace accessibility { SolarMutexGuard aGuard; - EPosition aStartIndex( mpImpl->Range2Internal(nStartIndex) ); - EPosition aEndIndex( mpImpl->Range2Internal(nEndIndex) ); + EPaM aStartIndex(mpImpl->Range2Internal(nStartIndex)); + EPaM aEndIndex(mpImpl->Range2Internal(nEndIndex)); return mpImpl->SetSelection( aStartIndex.nPara, aStartIndex.nIndex, aEndIndex.nPara, aEndIndex.nIndex ); @@ -682,8 +682,8 @@ namespace accessibility nEndIndex++; } OUStringBuffer aRes; - EPosition aStartIndex( mpImpl->Range2Internal(nStartIndex) ); - EPosition aEndIndex( mpImpl->Range2Internal(nEndIndex) ); + EPaM aStartIndex(mpImpl->Range2Internal(nStartIndex)); + EPaM aEndIndex(mpImpl->Range2Internal(nEndIndex)); // #102170# Special case: start and end paragraph are identical if( aStartIndex.nPara == aEndIndex.nPara ) @@ -733,7 +733,7 @@ namespace accessibility SolarMutexGuard aGuard; bool bLineBreak = mpImpl->RemoveLineBreakCount( nIndex ); - EPosition aPos( mpImpl->Range2Internal(nIndex) ); + EPaM aPos(mpImpl->Range2Internal(nIndex)); css::accessibility::TextSegment aResult; @@ -749,7 +749,7 @@ namespace accessibility aResult.SegmentText = mpImpl->GetParagraph( aPos.nPara ).getText(); // #112814# Adapt the start index with the paragraph offset - aResult.SegmentStart = mpImpl->Internal2Index( EPosition( aPos.nPara, 0 ) ); + aResult.SegmentStart = mpImpl->Internal2Index(EPaM(aPos.nPara, 0)); aResult.SegmentEnd = aResult.SegmentStart + aResult.SegmentText.getLength(); } else if ( AccessibleTextType::ATTRIBUTE_RUN == aTextType ) @@ -785,7 +785,7 @@ namespace accessibility sal_Int32 nOldIdx = nIndex; bool bLineBreak = mpImpl->RemoveLineBreakCount( nIndex ); - EPosition aPos( mpImpl->Range2Internal(nIndex) ); + EPaM aPos(mpImpl->Range2Internal(nIndex)); css::accessibility::TextSegment aResult; @@ -797,14 +797,14 @@ namespace accessibility aResult.SegmentText = mpImpl->GetParagraph( aPos.nPara ).getText(); // #112814# Adapt the start index with the paragraph offset - aResult.SegmentStart = mpImpl->Internal2Index( EPosition( aPos.nPara, 0 ) ); + aResult.SegmentStart = mpImpl->Internal2Index(EPaM(aPos.nPara, 0)); } else if( aPos.nPara > 0 ) { aResult.SegmentText = mpImpl->GetParagraph( aPos.nPara - 1 ).getText(); // #112814# Adapt the start index with the paragraph offset - aResult.SegmentStart = mpImpl->Internal2Index( EPosition( aPos.nPara - 1, 0 ) ); + aResult.SegmentStart = mpImpl->Internal2Index(EPaM(aPos.nPara - 1, 0)); } aResult.SegmentEnd = aResult.SegmentStart + aResult.SegmentText.getLength(); @@ -832,7 +832,7 @@ namespace accessibility sal_Int32 nTemp = nIndex+1; bool bLineBreak = mpImpl->RemoveLineBreakCount( nTemp ); mpImpl->RemoveLineBreakCount( nIndex ); - EPosition aPos( mpImpl->Range2Internal(nIndex) ); + EPaM aPos(mpImpl->Range2Internal(nIndex)); css::accessibility::TextSegment aResult; @@ -846,7 +846,7 @@ namespace accessibility aResult.SegmentText = mpImpl->GetParagraph( aPos.nPara + 1 ).getText(); // #112814# Adapt the start index with the paragraph offset - aResult.SegmentStart = mpImpl->Internal2Index( EPosition( aPos.nPara + 1, 0 ) ); + aResult.SegmentStart = mpImpl->Internal2Index(EPaM(aPos.nPara + 1, 0)); aResult.SegmentEnd = aResult.SegmentStart + aResult.SegmentText.getLength(); } } @@ -873,8 +873,8 @@ namespace accessibility if( nStartIndex > nEndIndex ) std::swap(nStartIndex, nEndIndex); - EPosition aStartIndex( mpImpl->Range2Internal(nStartIndex) ); - EPosition aEndIndex( mpImpl->Range2Internal(nEndIndex) ); + EPaM aStartIndex(mpImpl->Range2Internal(nStartIndex)); + EPaM aEndIndex(mpImpl->Range2Internal(nEndIndex)); return mpImpl->CopyText( aStartIndex.nPara, aStartIndex.nIndex, aEndIndex.nPara, aEndIndex.nIndex ); @@ -926,7 +926,7 @@ namespace accessibility SolarMutexGuard aGuard; - EPosition aPos( mpImpl->Index2Internal( nIndex ) ); + EPaM aPos(mpImpl->Index2Internal(nIndex)); AccessibleEditableTextPara& rPara = mpImpl->GetParagraph( aPos.nPara ); uno::Sequence< beans::PropertyValue > aDefAttrSeq = rPara.getDefaultAttributes( RequestedAttributes ); uno::Sequence< beans::PropertyValue > aRunAttrSeq = rPara.getRunAttributes( aPos.nIndex, RequestedAttributes ); diff --git a/editeng/source/editeng/editdbg.cxx b/editeng/source/editeng/editdbg.cxx index 0ff602376509..2b4d3956eefd 100644 --- a/editeng/source/editeng/editdbg.cxx +++ b/editeng/source/editeng/editdbg.cxx @@ -480,7 +480,7 @@ void ImpEditEngine::DumpData(bool bInfoBox) fprintf( fp, " VisArea: nX=%" SAL_PRIdINT64 ", nY=%" SAL_PRIdINT64 ", dX=%" SAL_PRIdINT64 ", dY=%" SAL_PRIdINT64, sal_Int64(aR.Left()), sal_Int64(aR.Top()), sal_Int64(aR.GetSize().Width()), sal_Int64(aR.GetSize().Height()) ); ESelection aSel = pV->GetSelection(); - fprintf( fp, " Selection: Start=%" SAL_PRIdINT32 ",%" SAL_PRIdINT32 ", End=%" SAL_PRIdINT32 ",%" SAL_PRIdINT32, aSel.nStartPara, aSel.nStartPos, aSel.nEndPara, aSel.nEndPos ); + fprintf( fp, " Selection: Start=%" SAL_PRIdINT32 ",%" SAL_PRIdINT32 ", End=%" SAL_PRIdINT32 ",%" SAL_PRIdINT32, aSel.start.nPara, aSel.start.nIndex, aSel.end.nPara, aSel.end.nIndex ); } if ( GetActiveView() ) { diff --git a/editeng/source/editeng/editdoc.cxx b/editeng/source/editeng/editdoc.cxx index fdc52e57a7fc..63961daefe27 100644 --- a/editeng/source/editeng/editdoc.cxx +++ b/editeng/source/editeng/editdoc.cxx @@ -451,7 +451,7 @@ sal_Int32 FastGetPos(const Array& rArray, const Val* p, sal_Int32& rLastPos) } // XXX "not found" condition for sal_Int32 indexes - return EE_PARA_NOT_FOUND; + return EE_PARA_MAX; } } @@ -537,7 +537,7 @@ sal_Int32 ParaPortionList::FindParagraph(tools::Long nYOffset) const if ( nY > nYOffset ) return i <= SAL_MAX_INT32 ? static_cast<sal_Int32>(i) : SAL_MAX_INT32; } - return EE_PARA_NOT_FOUND; + return EE_PARA_MAX; } #if OSL_DEBUG_LEVEL > 0 && !defined NDEBUG @@ -1043,7 +1043,7 @@ EditPaM EditDoc::InsertParaBreak( EditPaM aPaM, bool bKeepEndingAttribs ) assert(aPaM.GetNode()); ContentNode* pCurNode = aPaM.GetNode(); sal_Int32 nPos = GetPos( pCurNode ); - assert(nPos != EE_PARA_NOT_FOUND); + assert(nPos != EE_PARA_MAX); OUString aStr = aPaM.GetNode()->Copy( aPaM.GetIndex() ); aPaM.GetNode()->Erase( aPaM.GetIndex() ); diff --git a/editeng/source/editeng/editeng.cxx b/editeng/source/editeng/editeng.cxx index b2f0b6c0b4f1..15dcc2d7dc5a 100644 --- a/editeng/source/editeng/editeng.cxx +++ b/editeng/source/editeng/editeng.cxx @@ -321,7 +321,7 @@ EEHorizontalTextDirection EditEngine::GetDefaultHorizontalTextDirection() const SvtScriptType EditEngine::GetScriptType( const ESelection& rSelection ) const { - return getImpl().GetScriptType( rSelection ); + return getImpl().GetItemScriptType(getImpl().CreateSel(rSelection)); } editeng::LanguageSpan EditEngine::GetLanguage(const EditPaM& rPaM) const @@ -336,7 +336,7 @@ editeng::LanguageSpan EditEngine::GetLanguage( sal_Int32 nPara, sal_Int32 nPos ) void EditEngine::TransliterateText( const ESelection& rSelection, TransliterationFlags nTransliterationMode ) { - getImpl().TransliterateText(getImpl().CreateSel( rSelection ), nTransliterationMode); + TransliterateText(CreateSelection(rSelection), nTransliterationMode); } EditSelection EditEngine::TransliterateText(const EditSelection& rSelection, TransliterationFlags nTransliterationMode) @@ -457,22 +457,19 @@ sal_uInt32 EditEngine::GetTextHeight( sal_Int32 nParagraph ) const return nHeight; } -OUString EditEngine::GetWord( sal_Int32 nPara, sal_Int32 nIndex ) +OUString EditEngine::GetWord(const EPaM& rPos) { - ESelection aESel( nPara, nIndex, nPara, nIndex ); - EditSelection aSel(getImpl().CreateSel(aESel)); - aSel = getImpl().SelectWord(aSel); - return getImpl().GetSelected(aSel); + EditSelection aSel(CreateSelection(ESelection(rPos))); + aSel = SelectWord(aSel); + return GetSelected(aSel); } ESelection EditEngine::GetWord( const ESelection& rSelection, sal_uInt16 nWordType ) const { // ImpEditEngine-Iteration-Methods should be const! - EditEngine* pNonConstEditEngine = const_cast<EditEngine*>(this); - - EditSelection aSel(pNonConstEditEngine->getImpl().CreateSel( rSelection ) ); - aSel = pNonConstEditEngine->getImpl().SelectWord( aSel, nWordType ); - return pNonConstEditEngine->getImpl().CreateESel( aSel ); + EditSelection aSel(getImpl().CreateSel(rSelection)); + aSel = getImpl().SelectWord(aSel, nWordType); + return CreateESelection(aSel); } void EditEngine::CheckIdleFormatter() @@ -737,6 +734,19 @@ EditSelection EditEngine::CreateSelection(const ESelection& rSel) return getImpl().CreateSel(rSel); } +ESelection EditEngine::NormalizeESelection(const ESelection& rSel) const +{ + return CreateESelection(getImpl().CreateNormalizedSel(rSel)); +} + +EPaM EditEngine::GetEnd() const +{ + auto para = GetEditDoc().Count(); + if (para) + --para; + return { para, GetTextLen(para) }; +} + const SfxItemSet& EditEngine::GetBaseParaAttribs(sal_Int32 nPara) const { return getImpl().GetParaAttribs(nPara); @@ -851,8 +861,7 @@ std::unique_ptr<EditTextObject> EditEngine::CreateTextObject() std::unique_ptr<EditTextObject> EditEngine::CreateTextObject( const ESelection& rESelection ) { - EditSelection aSel(getImpl().CreateSel(rESelection)); - return getImpl().CreateTextObject(aSel); + return getImpl().CreateTextObject(CreateSelection(rESelection)); } std::unique_ptr<EditTextObject> EditEngine::GetEmptyTextObject() @@ -1038,8 +1047,7 @@ void EditEngine::GetCharAttribs( sal_Int32 nPara, std::vector<EECharAttrib>& rLi SfxItemSet EditEngine::GetAttribs( const ESelection& rSel, EditEngineAttribs nOnlyHardAttrib ) { - EditSelection aSel(getImpl().ConvertSelection(rSel.nStartPara, rSel.nStartPos, rSel.nEndPara, rSel.nEndPos)); - return getImpl().GetAttribs(aSel, nOnlyHardAttrib); + return getImpl().GetAttribs(getImpl().CreateNormalizedSel(rSel), nOnlyHardAttrib); } SfxItemSet EditEngine::GetAttribs( sal_Int32 nPara, sal_Int32 nStart, sal_Int32 nEnd, GetAttribsFlags nFlags ) const @@ -1207,15 +1215,14 @@ SfxItemPool* EditEngine::GetEditTextObjectPool() const void EditEngine::QuickSetAttribs( const SfxItemSet& rSet, const ESelection& rSel ) { - EditSelection aSel(getImpl().ConvertSelection(rSel.nStartPara, rSel.nStartPos, rSel.nEndPara, rSel.nEndPos)); - getImpl().SetAttribs(aSel, rSet); + getImpl().SetAttribs(getImpl().CreateNormalizedSel(rSel), rSet); } void EditEngine::QuickMarkInvalid( const ESelection& rSel ) { - DBG_ASSERT(rSel.nStartPara < getImpl().GetEditDoc().Count(), "MarkInvalid: Start out of Range!"); - DBG_ASSERT(rSel.nEndPara < getImpl().GetEditDoc().Count(), "MarkInvalid: End out of Range!"); - for (sal_Int32 nPara = rSel.nStartPara; nPara <= rSel.nEndPara; nPara++) + DBG_ASSERT(rSel.start.nPara < getImpl().GetEditDoc().Count(), "MarkInvalid: Start out of Range!"); + DBG_ASSERT(rSel.end.nPara < getImpl().GetEditDoc().Count(), "MarkInvalid: End out of Range!"); + for (sal_Int32 nPara = rSel.start.nPara; nPara <= rSel.end.nPara; nPara++) { ParaPortion* pPortion = getImpl().GetParaPortions().SafeGetObject(nPara); if ( pPortion ) @@ -1225,14 +1232,12 @@ void EditEngine::QuickMarkInvalid( const ESelection& rSel ) void EditEngine::QuickInsertText(const OUString& rText, const ESelection& rSel) { - EditSelection aSel(getImpl().ConvertSelection(rSel.nStartPara, rSel.nStartPos, rSel.nEndPara, rSel.nEndPos)); - getImpl().ImpInsertText(aSel, rText); + getImpl().ImpInsertText(getImpl().CreateNormalizedSel(rSel), rText); } void EditEngine::QuickDelete( const ESelection& rSel ) { - EditSelection aSel(getImpl().ConvertSelection(rSel.nStartPara, rSel.nStartPos, rSel.nEndPara, rSel.nEndPos)); - getImpl().ImpDeleteSelection( aSel ); + getImpl().ImpDeleteSelection(getImpl().CreateNormalizedSel(rSel)); } void EditEngine::QuickMarkToBeRepainted( sal_Int32 nPara ) @@ -1244,15 +1249,12 @@ void EditEngine::QuickMarkToBeRepainted( sal_Int32 nPara ) void EditEngine::QuickInsertLineBreak( const ESelection& rSel ) { - EditSelection aSel(getImpl().ConvertSelection(rSel.nStartPara, rSel.nStartPos, rSel.nEndPara, rSel.nEndPos)); - getImpl().InsertLineBreak( aSel ); + getImpl().InsertLineBreak(getImpl().CreateNormalizedSel(rSel)); } void EditEngine::QuickInsertField( const SvxFieldItem& rFld, const ESelection& rSel ) { - - EditSelection aSel(getImpl().ConvertSelection(rSel.nStartPara, rSel.nStartPos, rSel.nEndPara, rSel.nEndPos)); - getImpl().ImpInsertFeature(aSel, rFld); + getImpl().ImpInsertFeature(getImpl().CreateNormalizedSel(rSel), rFld); } void EditEngine::QuickFormatDoc( bool bFull ) @@ -1519,20 +1521,16 @@ sal_Int32 EditEngine::FindParagraph( tools::Long nDocPosY ) return getImpl().GetParaPortions().FindParagraph(nDocPosY); } -EPosition EditEngine::FindDocPosition( const Point& rDocPos ) const +EPaM EditEngine::FindDocPosition(const Point& rDocPos) const { - EPosition aPos; // From the point of the API, this is const... EditPaM aPaM = getImpl().GetPaM(rDocPos, false); if ( aPaM.GetNode() ) - { - aPos.nPara = getImpl().maEditDoc.GetPos(aPaM.GetNode()); - aPos.nIndex = aPaM.GetIndex(); - } - return aPos; + return getImpl().CreateEPaM(aPaM); + return EPaM::NotFound(); } -tools::Rectangle EditEngine::GetCharacterBounds( const EPosition& rPos ) const +tools::Rectangle EditEngine::GetCharacterBounds(const EPaM& rPos) const { tools::Rectangle aBounds; ContentNode* pNode = getImpl().GetEditDoc().GetObject(rPos.nPara); @@ -1574,8 +1572,7 @@ ParagraphInfos EditEngine::GetParagraphInfos( sal_Int32 nPara ) uno::Reference<datatransfer::XTransferable> EditEngine::CreateTransferable(const ESelection& rSelection) { - EditSelection aSel(getImpl().CreateSel(rSelection)); - return getImpl().CreateTransferable(aSel); + return getImpl().CreateTransferable(CreateSelection(rSelection)); } diff --git a/editeng/source/editeng/editobj.cxx b/editeng/source/editeng/editobj.cxx index 9b17e434e53d..6f7182f383af 100644 --- a/editeng/source/editeng/editobj.cxx +++ b/editeng/source/editeng/editobj.cxx @@ -382,10 +382,10 @@ ContentInfo* EditTextObjectImpl::CreateAndInsertContent() sal_Int32 EditTextObjectImpl::GetParagraphCount() const { size_t nSize = maContents.size(); - if (nSize > EE_PARA_MAX_COUNT) + if (nSize > EE_PARA_MAX) { SAL_WARN( "editeng", "EditTextObjectImpl::GetParagraphCount - overflow " << nSize); - return EE_PARA_MAX_COUNT; + return EE_PARA_MAX; } return static_cast<sal_Int32>(nSize); } diff --git a/editeng/source/editeng/editundo.cxx b/editeng/source/editeng/editundo.cxx index f785c7057df0..47f5ac5b246f 100644 --- a/editeng/source/editeng/editundo.cxx +++ b/editeng/source/editeng/editundo.cxx @@ -524,9 +524,9 @@ void EditUndoSetAttribs::Undo() DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" ); EditEngine* pEE = GetEditEngine(); bool bFields = false; - for ( sal_Int32 nPara = aESel.nStartPara; nPara <= aESel.nEndPara; nPara++ ) + for ( sal_Int32 nPara = aESel.start.nPara; nPara <= aESel.end.nPara; nPara++ ) { - const ContentAttribsInfo& rInf = *aPrevAttribs[nPara-aESel.nStartPara]; + const ContentAttribsInfo& rInf = *aPrevAttribs[nPara-aESel.start.nPara]; // first the paragraph attributes ... pEE->SetParaAttribsOnly(nPara, rInf.GetPrevParaAttribs()); diff --git a/editeng/source/editeng/editview.cxx b/editeng/source/editeng/editview.cxx index 7176e3961985..4791c5e7c0fb 100644 --- a/editeng/source/editeng/editview.cxx +++ b/editeng/source/editeng/editview.cxx @@ -274,7 +274,7 @@ void EditView::SetSelection( const ESelection& rESel ) if (nullptr != pNode) pNode->checkAndDeleteEmptyAttribs(); } - EditSelection aNewSelection(getImpEditEngine().ConvertSelection(rESel.nStartPara, rESel.nStartPos, rESel.nEndPara, rESel.nEndPos)); + EditSelection aNewSelection(getImpEditEngine().CreateNormalizedSel(rESel)); // If the selection is manipulated after a KeyInput: getEditEngine().CheckIdleFormatter(); @@ -309,15 +309,7 @@ void EditView::SetSelection( const ESelection& rESel ) ESelection EditView::GetSelection() const { - ESelection aSelection; - - aSelection.nStartPara = getEditEngine().GetEditDoc().GetPos( getImpl().GetEditSelection().Min().GetNode() ); - aSelection.nEndPara = getEditEngine().GetEditDoc().GetPos( getImpl().GetEditSelection().Max().GetNode() ); - - aSelection.nStartPos = getImpl().GetEditSelection().Min().GetIndex(); - aSelection.nEndPos = getImpl().GetEditSelection().Max().GetIndex(); - - return aSelection; + return getEditEngine().CreateESelection(getImpl().GetEditSelection()); } bool EditView::HasSelection() const @@ -734,7 +726,7 @@ void EditView::MoveParagraphs( Range aParagraphs, sal_Int32 nNewPos ) void EditView::MoveParagraphs( tools::Long nDiff ) { ESelection aSel = GetSelection(); - Range aRange( aSel.nStartPara, aSel.nEndPara ); + Range aRange( aSel.start.nPara, aSel.end.nPara ); aRange.Normalize(); tools::Long nDest = ( nDiff > 0 ? aRange.Max() : aRange.Min() ) + nDiff; if ( nDiff > 0 ) @@ -1226,8 +1218,8 @@ bool EditView::ExecuteSpellPopup(const Point& rPosPixel, const Link<SpellCallbac if (sId == "paralanguage") { ESelection aSel = GetSelection(); - aSel.nStartPos = 0; - aSel.nEndPos = EE_TEXTPOS_ALL; + aSel.start.nIndex = 0; + aSel.end.nIndex = EE_TEXTPOS_MAX; SetSelection( aSel ); } SetAttribs( aAttrs ); @@ -1427,19 +1419,19 @@ void EditView::SelectFieldAtCursor() // Make sure the whole field is selected // A field is represented by a dummy character - so it cannot be a selection larger than 1 ESelection aSel = GetSelection(); - if (aSel.nStartPos == aSel.nEndPos) // not yet selected + if (!aSel.HasRange()) // not yet selected { if (bIsBeforeCursor) { - assert (aSel.nStartPos); - --aSel.nStartPos; + assert (aSel.start.nIndex); + --aSel.start.nIndex; } else - aSel.nEndPos++; + aSel.end.nIndex++; SetSelection(aSel); } else - assert(std::abs(aSel.nStartPos - aSel.nEndPos) == 1); + assert(std::abs(aSel.start.nIndex - aSel.end.nIndex) == 1); } const SvxFieldData* EditView::GetFieldUnderMouseOrInSelectionOrAtCursor(bool bAlsoCheckBeforeCursor) const @@ -1533,7 +1525,7 @@ void EditView::ChangeFontSize( bool bGrow, const FontList* pFontList ) if( aSel.HasRange() ) { - for( sal_Int32 nPara = aSel.nStartPara; nPara <= aSel.nEndPara; nPara++ ) + for( sal_Int32 nPara = aSel.start.nPara; nPara <= aSel.end.nPara; nPara++ ) { std::vector<sal_Int32> aPortions; rEditEngine.GetPortions( nPara, aPortions ); @@ -1541,8 +1533,8 @@ void EditView::ChangeFontSize( bool bGrow, const FontList* pFontList ) if( aPortions.empty() ) aPortions.push_back( rEditEngine.GetTextLen(nPara) ); - const sal_Int32 nBeginPos = (nPara == aSel.nStartPara) ? aSel.nStartPos : 0; - const sal_Int32 nEndPos = (nPara == aSel.nEndPara) ? aSel.nEndPos : EE_TEXTPOS_ALL; + const sal_Int32 nBeginPos = (nPara == aSel.start.nPara) ? aSel.start.nIndex : 0; + const sal_Int32 nEndPos = (nPara == aSel.end.nPara) ? aSel.end.nIndex : EE_TEXTPOS_MAX; for ( size_t nPos = 0; nPos < aPortions.size(); ++nPos ) { @@ -1689,22 +1681,22 @@ Selection EditView::GetSurroundingTextSelection() const // Stop reconversion if the selected text includes a line break. if ( aStr.indexOf( 0x0A ) == -1 ) - return Selection( 0, aSelection.nEndPos - aSelection.nStartPos ); + return Selection(0, aSelection.end.nIndex - aSelection.start.nIndex); else return Selection( 0, 0 ); } else { - return Selection( aSelection.nStartPos, aSelection.nEndPos ); + return Selection(aSelection.start.nIndex, aSelection.end.nIndex); } } bool EditView::DeleteSurroundingText(const Selection& rRange) { ESelection aSel(GetSelection()); - aSel.nEndPara = aSel.nStartPara; - aSel.nStartPos = rRange.Min(); - aSel.nEndPos = rRange.Max(); + aSel.end.nPara = aSel.start.nPara; + aSel.start.nIndex = rRange.Min(); + aSel.end.nIndex = rRange.Max(); SetSelection(aSel); DeleteSelected(); return true; diff --git a/editeng/source/editeng/edtspell.cxx b/editeng/source/editeng/edtspell.cxx index 0dbcfedd55a0..8eef9af2bbe7 100644 --- a/editeng/source/editeng/edtspell.cxx +++ b/editeng/source/editeng/edtspell.cxx @@ -715,7 +715,7 @@ LanguageType EdtAutoCorrDoc::GetLanguage( sal_Int32 nPos ) const void EdtAutoCorrDoc::ImplStartUndoAction() { sal_Int32 nPara = mpEditEngine->GetEditDoc().GetPos( pCurNode ); - ESelection aSel( nPara, nCursor, nPara, nCursor ); + ESelection aSel(nPara, nCursor); mpEditEngine->UndoActionStart( EDITUNDO_INSERT, aSel ); bUndoAction = true; bAllowUndoAction = false; diff --git a/editeng/source/editeng/eertfpar.cxx b/editeng/source/editeng/eertfpar.cxx index deacdfa5905a..3170279eb7e9 100644 --- a/editeng/source/editeng/eertfpar.cxx +++ b/editeng/source/editeng/eertfpar.cxx @@ -367,8 +367,8 @@ void EditRTFParser::SetAttrInDoc( SvxRTFItemStackType &rSet ) ContentNode* pEN = aEndPaM.GetNode(); sal_Int32 nStartNode = mpEditEngine->GetEditDoc().GetPos( pSN ); sal_Int32 nEndNode = mpEditEngine->GetEditDoc().GetPos( pEN ); - assert(nStartNode != EE_PARA_NOT_FOUND); - assert(nEndNode != EE_PARA_NOT_FOUND); + assert(nStartNode != EE_PARA_MAX); + assert(nEndNode != EE_PARA_MAX); sal_Int16 nOutlLevel = 0xff; if (rSet.StyleNo() && mpEditEngine->GetStyleSheetPool() && mpEditEngine->IsImportRTFStyleSheetsSet()) diff --git a/editeng/source/editeng/impedit.cxx b/editeng/source/editeng/impedit.cxx index a7497f629868..f67073380470 100644 --- a/editeng/source/editeng/impedit.cxx +++ b/editeng/source/editeng/impedit.cxx @@ -519,7 +519,7 @@ void ImpEditView::DrawSelectionXOR( EditSelection aTmpSel, vcl::Region* pRegion, ContentNode* pEndNode = aTmpSel.Max().GetNode(); const sal_Int32 nStartPara = getEditEngine().GetEditDoc().GetPos(pStartNode); const sal_Int32 nEndPara = getEditEngine().GetEditDoc().GetPos(pEndNode); - if (nStartPara == EE_PARA_NOT_FOUND || nEndPara == EE_PARA_NOT_FOUND) + if (nStartPara == EE_PARA_MAX || nEndPara == EE_PARA_MAX) return; bool bStartHandleVisible = false; @@ -1146,7 +1146,7 @@ tools::Rectangle ImpEditView::GetEditCursor() const sal_Int32 nTextPortionStart = 0; sal_Int32 nPara = getEditEngine().GetEditDoc().GetPos( aPaM.GetNode() ); - if (nPara == EE_PARA_NOT_FOUND) // #i94322 + if (nPara == EE_PARA_MAX) // #i94322 return tools::Rectangle(); ParaPortion const& rParaPortion = getEditEngine().GetParaPortions().getRef(nPara); @@ -1192,7 +1192,7 @@ void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor ) sal_Int32 nTextPortionStart = 0; sal_Int32 nPara = getEditEngine().GetEditDoc().GetPos( aPaM.GetNode() ); - if (nPara == EE_PARA_NOT_FOUND) // #i94322 + if (nPara == EE_PARA_MAX) // #i94322 return; ParaPortion const& rParaPortion = getEditEngine().GetParaPortions().getRef(nPara); @@ -1876,7 +1876,7 @@ const SvxFieldItem* ImpEditView::GetField( const Point& rPos, sal_Int32* pPara, bool ImpEditView::IsBulletArea( const Point& rPos, sal_Int32* pPara ) { if ( pPara ) - *pPara = EE_PARA_NOT_FOUND; + *pPara = EE_PARA_MAX; if( !GetOutputArea().Contains( rPos ) ) return false; @@ -2304,7 +2304,7 @@ void ImpEditView::dragGestureRecognized(const css::datatransfer::dnd::DragGestur aSz = GetOutputDevice().PixelToLogic( aSz ); mpDragAndDropInfo->nSensibleRange = static_cast<sal_uInt16>(aSz.Width()); mpDragAndDropInfo->nCursorWidth = static_cast<sal_uInt16>(aSz.Width()) / 2; - mpDragAndDropInfo->aBeginDragSel = getImpEditEngine().CreateESel( aCopySel ); + mpDragAndDropInfo->aBeginDragSel = getEditEngine().CreateESelection( aCopySel ); uno::Reference<datatransfer::XTransferable> xData = getEditEngine().CreateTransferable(aCopySel); @@ -2330,62 +2330,61 @@ void ImpEditView::dragDropEnd( const css::datatransfer::dnd::DragSourceDropEvent if (mpDragAndDropInfo->bStarterOfDD && mpDragAndDropInfo->bDroppedInMe ) { // DropPos: Where was it dropped, irrespective of length. - ESelection aDropPos(mpDragAndDropInfo->aDropSel.nStartPara, mpDragAndDropInfo->aDropSel.nStartPos, mpDragAndDropInfo->aDropSel.nStartPara, mpDragAndDropInfo->aDropSel.nStartPos ); + ESelection aDropPos(mpDragAndDropInfo->aDropSel.start); ESelection aToBeDelSel = mpDragAndDropInfo->aBeginDragSel; - ESelection aNewSel( mpDragAndDropInfo->aDropSel.nEndPara, mpDragAndDropInfo->aDropSel.nEndPos, - mpDragAndDropInfo->aDropSel.nEndPara, mpDragAndDropInfo->aDropSel.nEndPos ); + ESelection aNewSel(mpDragAndDropInfo->aDropSel.end); bool bBeforeSelection = aDropPos < mpDragAndDropInfo->aBeginDragSel; - sal_Int32 nParaDiff = mpDragAndDropInfo->aBeginDragSel.nEndPara - mpDragAndDropInfo->aBeginDragSel.nStartPara; + sal_Int32 nParaDiff = mpDragAndDropInfo->aBeginDragSel.end.nPara - mpDragAndDropInfo->aBeginDragSel.start.nPara; if ( bBeforeSelection ) { // Adjust aToBeDelSel. - DBG_ASSERT(mpDragAndDropInfo->aBeginDragSel.nStartPara >= mpDragAndDropInfo->aDropSel.nStartPara, "But not before? "); - aToBeDelSel.nStartPara = aToBeDelSel.nStartPara + nParaDiff; - aToBeDelSel.nEndPara = aToBeDelSel.nEndPara + nParaDiff; + DBG_ASSERT(mpDragAndDropInfo->aBeginDragSel.start.nPara >= mpDragAndDropInfo->aDropSel.start.nPara, "But not before? "); + aToBeDelSel.start.nPara = aToBeDelSel.start.nPara + nParaDiff; + aToBeDelSel.end.nPara = aToBeDelSel.end.nPara + nParaDiff; // To correct the character? - if ( aToBeDelSel.nStartPara == mpDragAndDropInfo->aDropSel.nEndPara ) + if ( aToBeDelSel.start.nPara == mpDragAndDropInfo->aDropSel.end.nPara ) { sal_uInt16 nMoreChars; - if (mpDragAndDropInfo->aDropSel.nStartPara == mpDragAndDropInfo->aDropSel.nEndPara ) - nMoreChars = mpDragAndDropInfo->aDropSel.nEndPos - mpDragAndDropInfo->aDropSel.nStartPos; + if (mpDragAndDropInfo->aDropSel.start.nPara == mpDragAndDropInfo->aDropSel.end.nPara ) + nMoreChars = mpDragAndDropInfo->aDropSel.end.nIndex - mpDragAndDropInfo->aDropSel.start.nIndex; else - nMoreChars = mpDragAndDropInfo->aDropSel.nEndPos; - aToBeDelSel.nStartPos = - aToBeDelSel.nStartPos + nMoreChars; - if ( aToBeDelSel.nStartPara == aToBeDelSel.nEndPara ) - aToBeDelSel.nEndPos = - aToBeDelSel.nEndPos + nMoreChars; + nMoreChars = mpDragAndDropInfo->aDropSel.end.nIndex; + aToBeDelSel.start.nIndex = + aToBeDelSel.start.nIndex + nMoreChars; + if ( aToBeDelSel.start.nPara == aToBeDelSel.end.nPara ) + aToBeDelSel.end.nIndex = + aToBeDelSel.end.nIndex + nMoreChars; } } else { // aToBeDelSel is ok, but the selection of the View // has to be adapted, if it was deleted before! - DBG_ASSERT(mpDragAndDropInfo->aBeginDragSel.nStartPara <= mpDragAndDropInfo->aDropSel.nStartPara, "But not before? "); - aNewSel.nStartPara = aNewSel.nStartPara - nParaDiff; - aNewSel.nEndPara = aNewSel.nEndPara - nParaDiff; + DBG_ASSERT(mpDragAndDropInfo->aBeginDragSel.start.nPara <= mpDragAndDropInfo->aDropSel.start.nPara, "But not before? "); + aNewSel.start.nPara = aNewSel.start.nPara - nParaDiff; + aNewSel.end.nPara = aNewSel.end.nPara - nParaDiff; // To correct the character? - if (mpDragAndDropInfo->aBeginDragSel.nEndPara == mpDragAndDropInfo->aDropSel.nStartPara ) + if (mpDragAndDropInfo->aBeginDragSel.end.nPara == mpDragAndDropInfo->aDropSel.start.nPara ) { sal_uInt16 nLessChars; - if (mpDragAndDropInfo->aBeginDragSel.nStartPara == mpDragAndDropInfo->aBeginDragSel.nEndPara ) - nLessChars = mpDragAndDropInfo->aBeginDragSel.nEndPos - mpDragAndDropInfo->aBeginDragSel.nStartPos; + if (mpDragAndDropInfo->aBeginDragSel.start.nPara == mpDragAndDropInfo->aBeginDragSel.end.nPara ) + nLessChars = mpDragAndDropInfo->aBeginDragSel.end.nIndex - mpDragAndDropInfo->aBeginDragSel.start.nIndex; else - nLessChars = mpDragAndDropInfo->aBeginDragSel.nEndPos; - aNewSel.nStartPos = aNewSel.nStartPos - nLessChars; - if ( aNewSel.nStartPara == aNewSel.nEndPara ) - aNewSel.nEndPos = aNewSel.nEndPos - nLessChars; + nLessChars = mpDragAndDropInfo->aBeginDragSel.end.nIndex; + aNewSel.start.nIndex = aNewSel.start.nIndex - nLessChars; + if ( aNewSel.start.nPara == aNewSel.end.nPara ) + aNewSel.end.nIndex = aNewSel.end.nIndex - nLessChars; } } DrawSelectionXOR(); - EditSelection aDelSel(getImpEditEngine().CreateSel(aToBeDelSel)); + EditSelection aDelSel(getEditEngine().CreateSelection(aToBeDelSel)); DBG_ASSERT( !aDelSel.DbgIsBuggy(getEditEngine().GetEditDoc()), "ToBeDel is buggy!"); getEditEngine().DeleteSelection(aDelSel); if ( !bBeforeSelection ) { - DBG_ASSERT(!getImpEditEngine().CreateSel(aNewSel).DbgIsBuggy(getEditEngine().GetEditDoc()), "Bad"); - SetEditSelection(getImpEditEngine().CreateSel(aNewSel)); + DBG_ASSERT(!getEditEngine().CreateSelection(aNewSel).DbgIsBuggy(getEditEngine().GetEditDoc()), "Bad"); + SetEditSelection(getEditEngine().CreateSelection(aNewSel)); } getImpEditEngine().FormatAndLayout(getImpEditEngine().GetActiveView()); DrawSelectionXOR(); @@ -2430,7 +2429,7 @@ void ImpEditView::drop( const css::datatransfer::dnd::DropTargetDropEvent& rDTDE if (mpDragAndDropInfo->bOutlinerMode) { bChanges = true; - GetEditViewPtr()->MoveParagraphs(Range(mpDragAndDropInfo->aBeginDragSel.nStartPara, mpDragAndDropInfo->aBeginDragSel.nEndPara ), mpDragAndDropInfo->nOutlinerDropDest); + GetEditViewPtr()->MoveParagraphs(Range(mpDragAndDropInfo->aBeginDragSel.start.nPara, mpDragAndDropInfo->aBeginDragSel.end.nPara ), mpDragAndDropInfo->nOutlinerDropDest); } else { @@ -2457,10 +2456,8 @@ void ImpEditView::drop( const css::datatransfer::dnd::DropTargetDropEvent& rDTDE if (mpDragAndDropInfo->bStarterOfDD) { // Only set if the same engine! - mpDragAndDropInfo->aDropSel.nStartPara = getEditEngine().GetEditDoc().GetPos( aPaM.GetNode() ); - mpDragAndDropInfo->aDropSel.nStartPos = aPaM.GetIndex(); - mpDragAndDropInfo->aDropSel.nEndPara = getEditEngine().GetEditDoc().GetPos( aNewSel.Max().GetNode() ); - mpDragAndDropInfo->aDropSel.nEndPos = aNewSel.Max().GetIndex(); + mpDragAndDropInfo->aDropSel.start = getImpEditEngine().CreateEPaM(aPaM); + mpDragAndDropInfo->aDropSel.end = getImpEditEngine().CreateEPaM(aNewSel.Max()); mpDragAndDropInfo->bDroppedInMe = true; } } @@ -2578,8 +2575,8 @@ void ImpEditView::dragOver(const css::datatransfer::dnd::DropTargetDragEvent& rD mpDragAndDropInfo->nOutlinerDropDest = nPara+1; } - if ((mpDragAndDropInfo->nOutlinerDropDest >= mpDragAndDropInfo->aBeginDragSel.nStartPara) && - (mpDragAndDropInfo->nOutlinerDropDest <= (mpDragAndDropInfo->aBeginDragSel.nEndPara + 1))) + if ((mpDragAndDropInfo->nOutlinerDropDest >= mpDragAndDropInfo->aBeginDragSel.start.nPara) && + (mpDragAndDropInfo->nOutlinerDropDest <= (mpDragAndDropInfo->aBeginDragSel.end.nPara + 1))) { bAccept = false; } @@ -2589,8 +2586,8 @@ void ImpEditView::dragOver(const css::datatransfer::dnd::DropTargetDragEvent& rD { // it must not be dropped into a selection EPaM aP = getImpEditEngine().CreateEPaM( aPaM ); - ESelection aDestSel( aP.nPara, aP.nIndex, aP.nPara, aP.nIndex); - ESelection aCurSel = getImpEditEngine().CreateESel( GetEditSelection() ); + ESelection aDestSel(aP); + ESelection aCurSel = getEditEngine().CreateESelection(GetEditSelection()); aCurSel.Adjust(); if ( !(aDestSel < aCurSel) && !(aDestSel > aCurSel) ) { diff --git a/editeng/source/editeng/impedit.hxx b/editeng/source/editeng/impedit.hxx index 8f722c660c6a..029ae6a9e223 100644 --- a/editeng/source/editeng/impedit.hxx +++ b/editeng/source/editeng/impedit.hxx @@ -748,7 +748,6 @@ private: void InitScriptTypes( sal_Int32 nPara ); sal_uInt16 GetI18NScriptType( const EditPaM& rPaM, sal_Int32* pEndPos = nullptr ) const; - SvtScriptType GetScriptType( const ESelection& rSel ); SvtScriptType GetItemScriptType( const EditSelection& rSel ) const; bool IsScriptChange( const EditPaM& rPaM ) const; bool HasScriptType( sal_Int32 nPara, sal_uInt16 nType ) const; @@ -1117,8 +1116,7 @@ public: EPaM CreateEPaM( const EditPaM& rPaM ) const { - const ContentNode* pNode = rPaM.GetNode(); - return EPaM(maEditDoc.GetPos(pNode), rPaM.GetIndex()); + return EPaM(maEditDoc.GetPos(rPaM.GetNode()), rPaM.GetIndex()); } EditPaM CreateEditPaM( const EPaM& rEPaM ) @@ -1130,28 +1128,24 @@ public: ESelection CreateESel(const EditSelection& rSel) const { - const ContentNode* pStartNode = rSel.Min().GetNode(); - const ContentNode* pEndNode = rSel.Max().GetNode(); ESelection aESel; - aESel.nStartPara = maEditDoc.GetPos( pStartNode ); - aESel.nStartPos = rSel.Min().GetIndex(); - aESel.nEndPara = maEditDoc.GetPos( pEndNode ); - aESel.nEndPos = rSel.Max().GetIndex(); + aESel.start = CreateEPaM(rSel.Min()); + aESel.end = CreateEPaM(rSel.Max()); return aESel; } EditSelection CreateSel(const ESelection& rSel) { - DBG_ASSERT( rSel.nStartPara < maEditDoc.Count(), "CreateSel: invalid start paragraph" ); - DBG_ASSERT( rSel.nEndPara < maEditDoc.Count(), "CreateSel: invalid end paragraph" ); - EditSelection aSel; - aSel.Min().SetNode(maEditDoc.GetObject(rSel.nStartPara)); - aSel.Min().SetIndex( rSel.nStartPos ); - aSel.Max().SetNode(maEditDoc.GetObject(rSel.nEndPara)); - aSel.Max().SetIndex( rSel.nEndPos ); + DBG_ASSERT( rSel.start.nPara < maEditDoc.Count(), "CreateSel: invalid start paragraph" ); + DBG_ASSERT( rSel.end.nPara < maEditDoc.Count(), "CreateSel: invalid end paragraph" ); + EditSelection aSel(CreateEditPaM(rSel.start), CreateEditPaM(rSel.end)); DBG_ASSERT( !aSel.DbgIsBuggy( maEditDoc ), "CreateSel: incorrect selection!" ); return aSel; + } + EditSelection CreateNormalizedSel(const ESelection& rSel) + { + return ConvertSelection(rSel.start.nPara, rSel.start.nIndex, rSel.end.nPara, rSel.end.nIndex); } void SetStyleSheetPool( SfxStyleSheetPool* pSPool ); diff --git a/editeng/source/editeng/impedit2.cxx b/editeng/source/editeng/impedit2.cxx index 88b047f1e8e4..95ea82178989 100644 --- a/editeng/source/editeng/impedit2.cxx +++ b/editeng/source/editeng/impedit2.cxx @@ -248,7 +248,7 @@ void ImpEditEngine::InitDoc(bool bKeepParaAttribs) if ( IsCallParaInsertedOrDeleted() ) { - GetEditEnginePtr()->ParagraphDeleted( EE_PARA_ALL ); + GetEditEnginePtr()->ParagraphDeleted(EE_PARA_MAX); GetEditEnginePtr()->ParagraphInserted( 0 ); } @@ -264,8 +264,7 @@ EditPaM ImpEditEngine::DeleteSelected(const EditSelection& rSel) OUString ImpEditEngine::GetText( const ESelection& rESelection ) { - EditSelection aSel = CreateSel(rESelection); - return GetSelected(aSel); + return GetSelected(CreateSel(rESelection)); } OUString ImpEditEngine::GetSelected( const EditSelection& rSel ) const @@ -526,14 +525,14 @@ bool ImpEditEngine::Command( const CommandEvent& rCEvt, EditView* pView ) if( pView->HasSelection() ) { - aSelection.nEndPos = aSelection.nStartPos; - aSelection.nStartPos += pData->GetStart(); - aSelection.nEndPos += pData->GetEnd(); + aSelection.end.nIndex = aSelection.start.nIndex; + aSelection.start.nIndex += pData->GetStart(); + aSelection.end.nIndex += pData->GetEnd(); } else { - aSelection.nStartPos = pData->GetStart(); - aSelection.nEndPos = pData->GetEnd(); + aSelection.start.nIndex = pData->GetStart(); + aSelection.end.nIndex = pData->GetEnd(); } pView->SetSelection( aSelection ); } @@ -544,11 +543,11 @@ bool ImpEditEngine::Command( const CommandEvent& rCEvt, EditView* pView ) ESelection aSelection = pView->GetSelection(); aSelection.Adjust(); - if ( aSelection.nStartPara != aSelection.nEndPara ) + if ( aSelection.start.nPara != aSelection.end.nPara ) { - sal_Int32 aParaLen = mpEditEngine->GetTextLen( aSelection.nStartPara ); - aSelection.nEndPara = aSelection.nStartPara; - aSelection.nEndPos = aParaLen; + sal_Int32 aParaLen = mpEditEngine->GetTextLen( aSelection.start.nPara ); + aSelection.end.nPara = aSelection.start.nPara; + aSelection.end.nIndex = aParaLen; pView->SetSelection( aSelection ); } } @@ -790,7 +789,7 @@ void ImpEditEngine::ParaAttribsChanged( ContentNode const * pNode, bool bIgnoreU pPortion->MarkSelectionInvalid( 0 ); sal_Int32 nPara = maEditDoc.GetPos( pNode ); - assert( nPara != EE_PARA_NOT_FOUND ); + assert(nPara != EE_PARA_MAX); if (bIgnoreUndoCheck || mpEditEngine->IsInUndo()) mpEditEngine->ParaAttribsChanged( nPara ); @@ -1858,12 +1857,6 @@ sal_uInt16 ImpEditEngine::GetI18NScriptType( const EditPaM& rPaM, sal_Int32* pEn return nScriptType ? nScriptType : SvtLanguageOptions::GetI18NScriptTypeOfLanguage( GetDefaultLanguage() ); } -SvtScriptType ImpEditEngine::GetScriptType( const ESelection& rSel ) -{ - EditSelection aSel(CreateSel(rSel)); - return GetItemScriptType( aSel ); -} - SvtScriptType ImpEditEngine::GetItemScriptType( const EditSelection& rSel ) const { EditSelection aSel( rSel ); @@ -2257,7 +2250,7 @@ EditSelection ImpEditEngine::ImpMoveParagraphs( Range aOldPositions, sal_Int32 n // Determine the new location for paragraphs sal_Int32 nRealNewPos = pDestPortion ? GetParaPortions().GetPos( pDestPortion ) : GetParaPortions().Count(); - assert( nRealNewPos != EE_PARA_NOT_FOUND && "ImpMoveParagraphs: Invalid Position!" ); + assert(nRealNewPos != EE_PARA_MAX && "ImpMoveParagraphs: Invalid Position!"); // Add the paragraph portions and content nodes to a new position sal_Int32 i = 0; @@ -2307,8 +2300,8 @@ EditSelection ImpEditEngine::ImpMoveParagraphs( Range aOldPositions, sal_Int32 n EditPaM ImpEditEngine::ImpConnectParagraphs( ContentNode* pLeft, ContentNode* pRight, bool bBackward ) { OSL_ENSURE( pLeft != pRight, "Join together the same paragraph ?" ); - OSL_ENSURE( maEditDoc.GetPos( pLeft ) != EE_PARA_NOT_FOUND, "Inserted node not found (1)" ); - OSL_ENSURE( maEditDoc.GetPos( pRight ) != EE_PARA_NOT_FOUND, "Inserted node not found (2)" ); + OSL_ENSURE(maEditDoc.GetPos(pLeft) != EE_PARA_MAX, "Inserted node not found (1)"); + OSL_ENSURE(maEditDoc.GetPos(pRight) != EE_PARA_MAX, "Inserted node not found (2)"); // #i120020# it is possible that left and right are *not* in the desired order (left/right) // so correct it. This correction is needed, else an invalid SfxLinkUndoAction will be @@ -2506,7 +2499,7 @@ EditPaM ImpEditEngine::ImpDeleteSelection(const EditSelection& rCurSel) sal_Int32 nStartNode = maEditDoc.GetPos( aStartPaM.GetNode() ); sal_Int32 nEndNode = maEditDoc.GetPos( aEndPaM.GetNode() ); - assert( nEndNode != EE_PARA_NOT_FOUND && "Start > End ?!" ); + assert(nEndNode != EE_PARA_MAX && "Start > End ?!"); assert( nStartNode <= nEndNode && "Start > End ?!" ); // Remove all nodes in between... @@ -2630,7 +2623,7 @@ EditPaM ImpEditEngine::AutoCorrect( const EditSelection& rCurSel, sal_Unicode c, ESelection aESel( CreateESel(aSel) ); EditSelection aFirstWordSel; EditSelection aSecondWordSel; - if (aESel.nEndPara == 0) // is this the first para? + if (aESel.end.nPara == 0) // is this the first para? { // select first word... // start by checking if para starts with word. @@ -2650,7 +2643,7 @@ EditPaM ImpEditEngine::AutoCorrect( const EditSelection& rCurSel, sal_Unicode c, EditPaM aRight2Word( WordRight( aFirstWordSel.Max() ) ); aSecondWordSel = SelectWord( EditSelection( aRight2Word ) ); } - bool bIsFirstWordInFirstPara = aESel.nEndPara == 0 && + bool bIsFirstWordInFirstPara = aESel.end.nPara == 0 && aFirstWordSel.Max().GetIndex() <= aSel.Max().GetIndex() && aSel.Max().GetIndex() <= aSecondWordSel.Min().GetIndex(); @@ -2986,10 +2979,10 @@ EditPaM ImpEditEngine::ImpInsertParaBreak( const EditSelection& rCurSel ) EditPaM ImpEditEngine::ImpInsertParaBreak( EditPaM& rPaM, bool bKeepEndingAttribs ) { - if ( maEditDoc.Count() >= EE_PARA_MAX_COUNT ) + if (maEditDoc.Count() >= EE_PARA_MAX) { SAL_WARN( "editeng", "ImpEditEngine::ImpInsertParaBreak - can't process more than " - << EE_PARA_MAX_COUNT << " paragraphs!"); + << EE_PARA_MAX << " paragraphs!"); return rPaM; } @@ -3037,7 +3030,7 @@ EditPaM ImpEditEngine::ImpInsertParaBreak( EditPaM& rPaM, bool bKeepEndingAttrib // Optimization: Do not place unnecessarily many getPos to Listen! // Here, as in undo, but also in all other methods. sal_Int32 nPos = GetParaPortions().GetPos( pPortion ); - assert(nPos != EE_PARA_NOT_FOUND); + assert(nPos != EE_PARA_MAX); ParaPortion* pNewPortion = new ParaPortion( aPaM.GetNode() ); GetParaPortions().Insert(nPos+1, std::unique_ptr<ParaPortion>(pNewPortion)); ParaAttribsChanged( pNewPortion->GetNode() ); diff --git a/editeng/source/editeng/impedit3.cxx b/editeng/source/editeng/impedit3.cxx index 049cb1527008..b060d35fbc0a 100644 --- a/editeng/source/editeng/impedit3.cxx +++ b/editeng/source/editeng/impedit3.cxx @@ -4385,7 +4385,7 @@ const ParaPortion* ImpEditEngine::GetPrevVisPortion( const ParaPortion* pCurPort const ParaPortion* ImpEditEngine::GetNextVisPortion( const ParaPortion* pCurPortion ) const { sal_Int32 nPara = GetParaPortions().GetPos( pCurPortion ); - if (nPara == EE_PARA_NOT_FOUND) + if (nPara == EE_PARA_MAX) { SAL_WARN("editeng", "Portion not found: GetPrevVisNode" ); return nullptr; @@ -4449,7 +4449,7 @@ void ImpEditEngine::InsertParagraph( sal_Int32 nPara, const EditTextObject& rTxt { if ( nPara > maEditDoc.Count() ) { - SAL_WARN_IF( nPara != EE_PARA_APPEND, "editeng", "Paragraph number too large, but not EE_PARA_APPEND!" ); + SAL_WARN_IF( nPara != EE_PARA_MAX, "editeng", "Paragraph number too large, but not EE_PARA_MAX!" ); nPara = maEditDoc.Count(); } @@ -4475,7 +4475,7 @@ void ImpEditEngine::InsertParagraph(sal_Int32 nPara, const OUString& rTxt) { if ( nPara > maEditDoc.Count() ) { - SAL_WARN_IF( nPara != EE_PARA_APPEND, "editeng", "Paragraph number too large, but not EE_PARA_APPEND!" ); + SAL_WARN_IF( nPara != EE_PARA_MAX, "editeng", "Paragraph number too large, but not EE_PARA_MAX!" ); nPara = maEditDoc.Count(); } @@ -4605,8 +4605,8 @@ const SvxNumberFormat* ImpEditEngine::GetNumberFormat( const ContentNode *pNode { // get index of paragraph sal_Int32 nPara = GetEditDoc().GetPos( pNode ); - DBG_ASSERT( nPara < EE_PARA_NOT_FOUND, "node not found in array" ); - if (nPara < EE_PARA_NOT_FOUND) + DBG_ASSERT( nPara < EE_PARA_MAX, "node not found in array" ); + if (nPara < EE_PARA_MAX) { // the called function may be overridden by an OutlinerEditEng // object to provide diff --git a/editeng/source/editeng/impedit4.cxx b/editeng/source/editeng/impedit4.cxx index 6d444749092c..50d7f6fe9669 100644 --- a/editeng/source/editeng/impedit4.cxx +++ b/editeng/source/editeng/impedit4.cxx @@ -1628,7 +1628,7 @@ void ImpEditEngine::CreateSpellInfo( bool bMultipleDocs ) // (spelling in only a selection or not starting with the top requires // further changes elsewhere to work properly) mpSpellInfo->aSpellStart = EPaM(); - mpSpellInfo->aSpellTo = EPaM( EE_PARA_NOT_FOUND, EE_INDEX_NOT_FOUND ); + mpSpellInfo->aSpellTo = EPaM(EE_PARA_MAX, EE_TEXTPOS_MAX); } @@ -1852,7 +1852,7 @@ void ImpEditEngine::ImpConvert( OUString &rConvTxt, LanguageType &rConvTxtLang, mpEditEngine->GetText(mpConvInfo->aConvContinue.nPara).isEmpty()) { sal_Int32 nPara = mpConvInfo->aConvContinue.nPara; - ESelection aESel( nPara, 0, nPara, 0 ); + ESelection aESel(nPara, 0); // see comment for below same function call SetLanguageAndFont( aESel, nTargetLang, EE_CHAR_LANGUAGE_CJK, diff --git a/editeng/source/editeng/impedit5.cxx b/editeng/source/editeng/impedit5.cxx index 6dd01d1d349e..9abcc1350c06 100644 --- a/editeng/source/editeng/impedit5.cxx +++ b/editeng/source/editeng/impedit5.cxx @@ -599,8 +599,7 @@ void ImpEditEngine::RemoveAttribs( const ESelection& rSelection, bool bRemovePar EERemoveParaAttribsMode::RemoveCharItems; UndoActionStart(EDITUNDO_RESETATTRIBS); - EditSelection aSel(ConvertSelection(rSelection.nStartPara, rSelection.nStartPos, rSelection.nEndPara, rSelection.nEndPos)); - RemoveCharAttribs(aSel, eMode, nWhich); + RemoveCharAttribs(CreateNormalizedSel(rSelection), eMode, nWhich); UndoActionEnd(); if (IsUpdateLayout()) FormatAndLayout(); diff --git a/editeng/source/editeng/textconv.cxx b/editeng/source/editeng/textconv.cxx index 3d4c03e1ddeb..9582c2b2e74b 100644 --- a/editeng/source/editeng/textconv.cxx +++ b/editeng/source/editeng/textconv.cxx @@ -121,8 +121,7 @@ bool TextConvWrapper::ConvMore_impl() bool bMore = false; EditEngine& rEditEngine = m_pEditView->getEditEngine(); - ImpEditEngine& rImpEditEngine = m_pEditView->getImpEditEngine(); - ConvInfo* pConvInfo = rImpEditEngine.GetConvInfo(); + ConvInfo* pConvInfo = rEditEngine.getImpl().GetConvInfo(); if ( pConvInfo->bMultipleDoc ) { bMore = rEditEngine.ConvertNextDocument(); @@ -169,8 +168,7 @@ void TextConvWrapper::ConvStart_impl( SvxSpellArea eArea ) if (m_aConvSel.HasRange()) { // user selection: convert to end of selection - pConvInfo->aConvTo.nPara = m_aConvSel.nEndPara; - pConvInfo->aConvTo.nIndex = m_aConvSel.nEndPos; + pConvInfo->aConvTo = m_aConvSel.end; pConvInfo->bConvToEnd = false; } else @@ -248,10 +246,10 @@ void TextConvWrapper::SelectNewUnit_impl( return; ESelection aSelection = m_pEditView->GetSelection(); - DBG_ASSERT( aSelection.nStartPara == aSelection.nEndPara, + DBG_ASSERT( aSelection.start.nPara == aSelection.end.nPara, "paragraph mismatch in selection" ); - aSelection.nStartPos = (m_nLastPos + m_nUnitOffset + nUnitStart); - aSelection.nEndPos = (m_nLastPos + m_nUnitOffset + nUnitEnd); + aSelection.start.nIndex = (m_nLastPos + m_nUnitOffset + nUnitStart); + aSelection.end.nIndex = (m_nLastPos + m_nUnitOffset + nUnitEnd); m_pEditView->SetSelection( aSelection ); } @@ -269,11 +267,11 @@ void TextConvWrapper::GetNextPortion( m_nUnitOffset = 0; ESelection aSelection = m_pEditView->GetSelection(); - DBG_ASSERT( aSelection.nStartPara == aSelection.nEndPara, + DBG_ASSERT( aSelection.start.nPara == aSelection.end.nPara, "paragraph mismatch in selection" ); - DBG_ASSERT( aSelection.nStartPos <= aSelection.nEndPos, + DBG_ASSERT( aSelection.start.nIndex <= aSelection.end.nIndex, "start pos > end pos" ); - m_nLastPos = aSelection.nStartPos; + m_nLastPos = aSelection.start.nIndex; } @@ -336,15 +334,15 @@ void TextConvWrapper::ReplaceUnit( m_nUnitOffset = m_nUnitOffset + nUnitStart + aNewTxt.getLength(); // remember current original language for later use - ImpEditEngine& rImpEditEngine = m_pEditView->getImpEditEngine(); + EditEngine& rEditEngine = m_pEditView->getEditEngine(); ESelection aOldSel = m_pEditView->GetSelection(); //EditSelection aOldEditSel = pEditView->getImpl().GetEditSelection(); #ifdef DBG_UTIL - LanguageType nOldLang = rImpEditEngine.GetLanguage(rImpEditEngine.CreateSel( aOldSel ).Min() ).nLang; + LanguageType nOldLang = rEditEngine.GetLanguage(rEditEngine.CreateSelection( aOldSel ).Min() ).nLang; #endif - rImpEditEngine.UndoActionStart( EDITUNDO_INSERT ); + rEditEngine.UndoActionStart( EDITUNDO_INSERT ); // according to FT we should currently not bother about keeping // attributes in Hangul/Hanja conversion and leave that untouched. @@ -362,7 +360,7 @@ void TextConvWrapper::ReplaceUnit( "TextConvWrapper::ReplaceUnit : unexpected target language" ); ESelection aNewSel( aOldSel ); - aNewSel.nStartPos = aNewSel.nStartPos - aNewTxt.getLength(); + aNewSel.start.nIndex -= aNewTxt.getLength(); if (pNewUnitLanguage) { @@ -375,10 +373,10 @@ void TextConvWrapper::ReplaceUnit( } } - rImpEditEngine.UndoActionEnd(); + rEditEngine.UndoActionEnd(); // adjust ConvContinue / ConvTo if necessary - ConvInfo* pConvInfo = rImpEditEngine.GetConvInfo(); + ConvInfo* pConvInfo = rEditEngine.getImpl().GetConvInfo(); sal_Int32 nDelta = aNewTxt.getLength() - aOrigTxt.getLength(); if (nDelta != 0) { @@ -410,7 +408,7 @@ void TextConvWrapper::ChangeText( const OUString &rNewText, pESelection->Adjust(); // remember cursor start position for later setting of the cursor - const sal_Int32 nStartIndex = pESelection->nStartPos; + const sal_Int32 nStartIndex = pESelection->start.nIndex; const sal_Int32 nIndices = pOffsets->getLength(); const sal_Int32 *pIndices = pOffsets->getConstArray(); @@ -453,8 +451,8 @@ void TextConvWrapper::ChangeText( const OUString &rNewText, // set selection to sub string to be replaced in original text ESelection aSel( *pESelection ); sal_Int32 nChgInNodeStartIndex = nStartIndex + nCorrectionOffset + nChgPos; - aSel.nStartPos = nChgInNodeStartIndex; - aSel.nEndPos = nChgInNodeStartIndex + nChgLen; + aSel.start.nIndex = nChgInNodeStartIndex; + aSel.end.nIndex = nChgInNodeStartIndex + nChgLen; m_pEditView->SetSelection( aSel ); // replace selected sub string with the corresponding @@ -485,7 +483,7 @@ void TextConvWrapper::ChangeText( const OUString &rNewText, // set cursor to the end of the inserted text // (as it would happen after ChangeText_impl (Delete and Insert) // of the whole text in the 'else' branch below) - pESelection->nStartPos = pESelection->nEndPos = nStartIndex + nConvTextLen; + pESelection->start.nIndex = pESelection->end.nIndex = nStartIndex + nConvTextLen; } else { diff --git a/editeng/source/misc/urlfieldhelper.cxx b/editeng/source/misc/urlfieldhelper.cxx index 16303c064d50..7dafeb2c9628 100644 --- a/editeng/source/misc/urlfieldhelper.cxx +++ b/editeng/source/misc/urlfieldhelper.cxx @@ -30,12 +30,7 @@ bool URLFieldHelper::IsCursorAtURLField(const EditView& pEditView, bool bAlsoChe { // tdf#128666 Make sure only URL field (or nothing) is selected ESelection aSel = pEditView.GetSelection(); - auto nSelectedParas = aSel.nEndPara - aSel.nStartPara; - auto nSelectedChars = aSel.nEndPos - aSel.nStartPos; - bool bIsValidSelection - = nSelectedParas == 0 - && (nSelectedChars == 0 || nSelectedChars == 1 || nSelectedChars == -1); - if (!bIsValidSelection) + if (aSel.start.nPara != aSel.end.nPara || std::abs(aSel.end.nIndex - aSel.start.nIndex) > 1) return false; const SvxFieldData* pField diff --git a/editeng/source/outliner/outlin2.cxx b/editeng/source/outliner/outlin2.cxx index 6c9aeda64a4c..0e791eee9a36 100644 --- a/editeng/source/outliner/outlin2.cxx +++ b/editeng/source/outliner/outlin2.cxx @@ -158,9 +158,9 @@ OUString const & Outliner::GetWordDelimiters() const return pEditEngine->GetWordDelimiters(); } -OUString Outliner::GetWord( sal_Int32 nPara, sal_Int32 nIndex ) +OUString Outliner::GetWord(const EPaM& rPos) { - return pEditEngine->GetWord( nPara, nIndex ); + return pEditEngine->GetWord(rPos); } void Outliner::Draw( OutputDevice& rOutDev, const tools::Rectangle& rOutRect ) @@ -423,7 +423,7 @@ bool Outliner::IsTextPos( const Point& rPaperPos, sal_uInt16 nBorder, bool* pbBu { Point aDocPos = GetDocPos( rPaperPos ); sal_Int32 nPara = pEditEngine->FindParagraph( aDocPos.Y() ); - if ( ( nPara != EE_PARA_NOT_FOUND ) && ImplHasNumberFormat( nPara ) ) + if ((nPara != EE_PARA_MAX) && ImplHasNumberFormat(nPara)) { tools::Rectangle aBulArea = ImpCalcBulletArea( nPara, true, true ); if ( aBulArea.Contains( rPaperPos ) ) diff --git a/editeng/source/outliner/outliner.cxx b/editeng/source/outliner/outliner.cxx index 171c296beaa1..e23ee74ff09f 100644 --- a/editeng/source/outliner/outliner.cxx +++ b/editeng/source/outliner/outliner.cxx @@ -150,7 +150,7 @@ void Outliner::ParagraphInserted( sal_Int32 nPara ) void Outliner::ParagraphDeleted( sal_Int32 nPara ) { - if ( nBlockInsCallback || ( nPara == EE_PARA_ALL ) ) + if (nBlockInsCallback || (nPara == EE_PARA_MAX)) return; Paragraph* pPara = pParaList->GetParagraph( nPara ); @@ -606,7 +606,7 @@ void Outliner::AddText( const OutlinerParaObject& rPObj, bool bAppend ) else { nPara = pParaList->GetParagraphCount(); - pEditEngine->InsertParagraph( EE_PARA_APPEND, rPObj.GetTextObject(), bAppend ); + pEditEngine->InsertParagraph(EE_PARA_MAX, rPObj.GetTextObject(), bAppend); } bFirstParaIsEmpty = false; @@ -816,7 +816,7 @@ vcl::Font Outliner::ImpCalcBulletFont( sal_Int32 nPara ) const vcl::Font aStdFont; if ( !pEditEngine->IsFlatMode() ) { - ESelection aSel( nPara, 0, nPara, 0 ); + ESelection aSel(nPara, 0); aStdFont = EditEngine::CreateFontFromItemSet( pEditEngine->GetAttribs( aSel ), pEditEngine->GetScriptType( aSel ) ); } else @@ -1470,7 +1470,7 @@ void Outliner::StyleSheetChanged( SfxStyleSheet const * pStyle ) ImplCalcBulletText( nPara, false, false ); // EditEngine formats changed paragraphs before calling this method, // so they are not reformatted now and use wrong bullet indent - pEditEngine->QuickMarkInvalid( ESelection( nPara, 0, nPara, 0 ) ); + pEditEngine->QuickMarkInvalid(ESelection(nPara, 0)); } } } @@ -2029,7 +2029,7 @@ std::optional<NonOverflowingText> Outliner::GetNonOverflowingText() const bool bItAllOverflew = nCount == 0 && nOverflowLine == 0; if ( bItAllOverflew ) { - ESelection aEmptySel(0,0,0,0); + ESelection aEmptySel; //EditTextObject *pTObj = pEditEngine->CreateTextObject(aEmptySel); bool const bLastParaInterrupted = true; // Last Para was interrupted since everything overflew return NonOverflowingText(aEmptySel, bLastParaInterrupted); diff --git a/editeng/source/outliner/outlobj.cxx b/editeng/source/outliner/outlobj.cxx index e6dc6e691c6c..91f89a8e3e8c 100644 --- a/editeng/source/outliner/outlobj.cxx +++ b/editeng/source/outliner/outlobj.cxx @@ -166,10 +166,10 @@ TextRotation OutlinerParaObject::GetRotation() const sal_Int32 OutlinerParaObject::Count() const { size_t nSize = mpImpl->maParagraphDataVector.size(); - if (nSize > EE_PARA_MAX_COUNT) + if (nSize > o3tl::make_unsigned(EE_PARA_MAX)) { SAL_WARN( "editeng", "OutlinerParaObject::Count - overflow " << nSize); - return EE_PARA_MAX_COUNT; + return EE_PARA_MAX; } return static_cast<sal_Int32>(nSize); } diff --git a/editeng/source/outliner/outlvw.cxx b/editeng/source/outliner/outlvw.cxx index e4f06d4548a0..62fa083b0321 100644 --- a/editeng/source/outliner/outlvw.cxx +++ b/editeng/source/outliner/outlvw.cxx @@ -123,12 +123,12 @@ bool OutlinerView::PostKeyEvent( const KeyEvent& rKEvt, vcl::Window const * pFra { if( !bReadOnly && !bSelection && ( pOwner->GetOutlinerMode() != OutlinerMode::TextObject ) ) { - if( aSel.nEndPos == pOwner->pEditEngine->GetTextLen( aSel.nEndPara ) ) + if (aSel.end.nIndex == pOwner->pEditEngine->GetTextLen(aSel.end.nPara)) { - Paragraph* pNext = pOwner->pParaList->GetParagraph( aSel.nEndPara+1 ); + Paragraph* pNext = pOwner->pParaList->GetParagraph(aSel.end.nPara + 1); if( pNext && pNext->HasFlag(ParaFlag::ISPAGE) ) { - if( !pOwner->ImpCanDeleteSelectedPages( this, aSel.nEndPara, 1 ) ) + if (!pOwner->ImpCanDeleteSelectedPages(this, aSel.end.nPara, 1)) return false; } } @@ -149,13 +149,13 @@ bool OutlinerView::PostKeyEvent( const KeyEvent& rKEvt, vcl::Window const * pFra { if ( ( pOwner->GetOutlinerMode() != OutlinerMode::TextObject ) && ( pOwner->GetOutlinerMode() != OutlinerMode::TitleObject ) && - ( bSelection || !aSel.nStartPos ) ) + ( bSelection || !aSel.start.nIndex ) ) { Indent( aKeyCode.IsShift() ? -1 : +1 ); bKeyProcessed = true; } else if ( ( pOwner->GetOutlinerMode() == OutlinerMode::TextObject ) && - !bSelection && !aSel.nEndPos && pOwner->ImplHasNumberFormat( aSel.nEndPara ) ) + !bSelection && !aSel.end.nIndex && pOwner->ImplHasNumberFormat( aSel.end.nPara ) ) { Indent( aKeyCode.IsShift() ? -1 : +1 ); bKeyProcessed = true; @@ -165,15 +165,15 @@ bool OutlinerView::PostKeyEvent( const KeyEvent& rKEvt, vcl::Window const * pFra break; case KEY_BACKSPACE: { - if( !bReadOnly && !bSelection && aSel.nEndPara && !aSel.nEndPos ) + if (!bReadOnly && !bSelection && aSel.end.nPara && !aSel.end.nIndex) { - Paragraph* pPara = pOwner->pParaList->GetParagraph( aSel.nEndPara ); - Paragraph* pPrev = pOwner->pParaList->GetParagraph( aSel.nEndPara-1 ); + Paragraph* pPara = pOwner->pParaList->GetParagraph(aSel.end.nPara); + Paragraph* pPrev = pOwner->pParaList->GetParagraph(aSel.end.nPara - 1); if( !pPrev->IsVisible() ) return true; if( !pPara->GetDepth() ) { - if(!pOwner->ImpCanDeleteSelectedPages(this, aSel.nEndPara , 1 ) ) + if (!pOwner->ImpCanDeleteSelectedPages(this, aSel.end.nPara, 1)) return true; } } @@ -185,26 +185,26 @@ bool OutlinerView::PostKeyEvent( const KeyEvent& rKEvt, vcl::Window const * pFra { // Special treatment: hard return at the end of a paragraph, // which has collapsed subparagraphs. - Paragraph* pPara = pOwner->pParaList->GetParagraph( aSel.nEndPara ); + Paragraph* pPara = pOwner->pParaList->GetParagraph(aSel.end.nPara); if( !aKeyCode.IsShift() ) { // Don't let insert empty paragraph with numbering. Instead end numbering. if (pPara->GetDepth() > -1 && - pOwner->pEditEngine->GetTextLen( aSel.nEndPara ) == 0) + pOwner->pEditEngine->GetTextLen( aSel.end.nPara ) == 0) { ToggleBullets(); return true; } // ImpGetCursor again??? if( !bSelection && - aSel.nEndPos == pOwner->pEditEngine->GetTextLen( aSel.nEndPara ) ) + aSel.end.nIndex == pOwner->pEditEngine->GetTextLen( aSel.end.nPara ) ) { sal_Int32 nChildren = pOwner->pParaList->GetChildCount(pPara); if( nChildren && !pOwner->pParaList->HasVisibleChildren(pPara)) { pOwner->UndoActionStart( OLUNDO_INSERT ); - sal_Int32 nTemp = aSel.nEndPara; + sal_Int32 nTemp = aSel.end.nPara; nTemp += nChildren; nTemp++; // insert above next Non-Child SAL_WARN_IF( nTemp < 0, "editeng", "OutlinerView::PostKeyEvent - overflow"); @@ -212,7 +212,7 @@ bool OutlinerView::PostKeyEvent( const KeyEvent& rKEvt, vcl::Window const * pFra { pOwner->Insert( OUString(),nTemp,pPara->GetDepth()); // Position the cursor - ESelection aTmpSel(nTemp,0,nTemp,0); + ESelection aTmpSel(nTemp, 0); pEditView->SetSelection( aTmpSel ); } pEditView->ShowCursor(); @@ -223,15 +223,15 @@ bool OutlinerView::PostKeyEvent( const KeyEvent& rKEvt, vcl::Window const * pFra } if( !bKeyProcessed && !bSelection && !aKeyCode.IsShift() && aKeyCode.IsMod1() && - ( aSel.nEndPos == pOwner->pEditEngine->GetTextLen(aSel.nEndPara) ) ) + ( aSel.end.nIndex == pOwner->pEditEngine->GetTextLen(aSel.end.nPara) ) ) { pOwner->UndoActionStart( OLUNDO_INSERT ); - sal_Int32 nTemp = aSel.nEndPara; + sal_Int32 nTemp = aSel.end.nPara; nTemp++; pOwner->Insert( OUString(), nTemp, pPara->GetDepth()+1 ); // Position the cursor - ESelection aTmpSel(nTemp,0,nTemp,0); + ESelection aTmpSel(nTemp, 0); pEditView->SetSelection( aTmpSel ); pEditView->ShowCursor(); pOwner->UndoActionEnd(); @@ -248,7 +248,7 @@ bool OutlinerView::PostKeyEvent( const KeyEvent& rKEvt, vcl::Window const * pFra sal_Int32 OutlinerView::ImpCheckMousePos(const Point& rPosPix, MouseTarget& reTarget) { - sal_Int32 nPara = EE_PARA_NOT_FOUND; + sal_Int32 nPara = EE_PARA_MAX; Point aMousePosWin = pEditView->GetOutputDevice().PixelToLogic( rPosPix ); if( !pEditView->GetOutputArea().Contains( aMousePosWin ) ) @@ -328,7 +328,7 @@ bool OutlinerView::MouseButtonDown( const MouseEvent& rMEvt ) if ( bHasChildren && pOwner->pParaList->HasVisibleChildren(pPara) ) nEndPara += pOwner->pParaList->GetChildCount( pPara ); // The selection is inverted, so that EditEngine does not scroll - ESelection aSel(nEndPara, EE_TEXTPOS_ALL, nPara, 0 ); + ESelection aSel(nEndPara, EE_TEXTPOS_MAX, nPara, 0); pEditView->SetSelection( aSel ); } else if( rMEvt.GetClicks() == 2 && bHasChildren ) @@ -338,10 +338,10 @@ bool OutlinerView::MouseButtonDown( const MouseEvent& rMEvt ) } // special case for outliner view in impress, check if double click hits the page icon for toggle - if( (nPara == EE_PARA_NOT_FOUND) && (pOwner->GetOutlinerMode() == OutlinerMode::OutlineView) && (eTarget == MouseTarget::Text) && (rMEvt.GetClicks() == 2) ) + if( (nPara == EE_PARA_MAX) && (pOwner->GetOutlinerMode() == OutlinerMode::OutlineView) && (eTarget == MouseTarget::Text) && (rMEvt.GetClicks() == 2) ) { ESelection aSel( pEditView->GetSelection() ); - nPara = aSel.nStartPara; + nPara = aSel.start.nPara; Paragraph* pPara = pOwner->pParaList->GetParagraph( nPara ); if( (pPara && pOwner->pParaList->HasChildren(pPara)) && pPara->HasFlag(ParaFlag::ISPAGE) ) { @@ -375,7 +375,7 @@ void OutlinerView::ReleaseMouse() void OutlinerView::ImpToggleExpand( Paragraph const * pPara ) { sal_Int32 nPara = pOwner->pParaList->GetAbsPos( pPara ); - pEditView->SetSelection( ESelection( nPara, 0, nPara, 0 ) ); + pEditView->SetSelection(ESelection(nPara, 0)); ImplExpandOrCollaps( nPara, nPara, !pOwner->pParaList->HasVisibleChildren( pPara ) ); pEditView->ShowCursor(); } @@ -401,8 +401,8 @@ sal_Int16 OutlinerView::GetDepth() const { ESelection aESelection = GetSelection(); aESelection.Adjust(); - sal_Int16 nDepth = pOwner->GetDepth(aESelection.nStartPara); - for (sal_Int32 nPara = aESelection.nStartPara + 1; nPara <= aESelection.nEndPara; ++nPara) + sal_Int16 nDepth = pOwner->GetDepth(aESelection.start.nPara); + for (sal_Int32 nPara = aESelection.start.nPara + 1; nPara <= aESelection.end.nPara; ++nPara) { if (nDepth != pOwner->GetDepth(nPara)) return -2; @@ -440,7 +440,7 @@ void OutlinerView::SetAttribs( const SfxItemSet& rAttrs ) ParaRange OutlinerView::ImpGetSelectedParagraphs( bool bIncludeHiddenChildren ) { ESelection aSel = pEditView->GetSelection(); - ParaRange aParas( aSel.nStartPara, aSel.nEndPara ); + ParaRange aParas(aSel.start.nPara, aSel.end.nPara); aParas.Adjust(); // Record the invisible Children of the last Parents in the selection @@ -497,7 +497,7 @@ void OutlinerView::Indent( short nDiff ) pPara->SetFlag( ParaFlag::ISPAGE ); pOwner->DepthChangedHdl(pPara, nPrevFlags); - pOwner->pEditEngine->QuickMarkInvalid( ESelection( nPara, 0, nPara, 0 ) ); + pOwner->pEditEngine->QuickMarkInvalid(ESelection(nPara, 0)); if( bUndo ) pOwner->InsertUndo( std::make_unique<OutlinerUndoChangeParaFlags>( pOwner, nPara, nPrevFlags, pPara->nFlags ) ); @@ -566,7 +566,7 @@ void OutlinerView::Indent( short nDiff ) else { // Needs at least a repaint... - pOwner->pEditEngine->QuickMarkInvalid( ESelection( nPara, 0, nPara, 0 ) ); + pOwner->pEditEngine->QuickMarkInvalid(ESelection(nPara, 0)); } } @@ -790,8 +790,8 @@ sal_Int32 OutlinerView::ImpInitPaste( sal_Int32& rStart ) pOwner->bPasting = true; ESelection aSelection( pEditView->GetSelection() ); aSelection.Adjust(); - rStart = aSelection.nStartPara; - sal_Int32 nSize = aSelection.nEndPara - aSelection.nStartPara + 1; + rStart = aSelection.start.nPara; + sal_Int32 nSize = aSelection.end.nPara - aSelection.start.nPara + 1; return nSize; } @@ -814,11 +814,7 @@ bool OutlinerView::Command(const CommandEvent& rCEvt) void OutlinerView::SelectRange( sal_Int32 nFirst, sal_Int32 nCount ) { - sal_Int32 nLast = nFirst+nCount; - nCount = pOwner->pParaList->GetParagraphCount(); - if( nLast <= nCount ) - nLast = nCount - 1; - ESelection aSel( nFirst, 0, nLast, EE_TEXTPOS_ALL ); + ESelection aSel(nFirst, 0, nFirst + nCount, EE_TEXTPOS_MAX); pEditView->SetSelection( aSel ); } @@ -829,18 +825,18 @@ sal_Int32 OutlinerView::ImpCalcSelectedPages( bool bIncludeFirstSelected ) aSel.Adjust(); sal_Int32 nPages = 0; - sal_Int32 nFirstPage = EE_PARA_MAX_COUNT; - sal_Int32 nStartPara = aSel.nStartPara; + sal_Int32 nFirstPage = EE_PARA_MAX; + sal_Int32 nStartPara = aSel.start.nPara; if ( !bIncludeFirstSelected ) nStartPara++; // All paragraphs after StartPara will be deleted - for ( sal_Int32 nPara = nStartPara; nPara <= aSel.nEndPara; nPara++ ) + for (sal_Int32 nPara = nStartPara; nPara <= aSel.end.nPara; nPara++) { Paragraph* pPara = pOwner->pParaList->GetParagraph( nPara ); assert(pPara && "ImpCalcSelectedPages: invalid Selection?"); if( pPara->HasFlag(ParaFlag::ISPAGE) ) { nPages++; - if( nFirstPage == EE_PARA_MAX_COUNT ) + if (nFirstPage == EE_PARA_MAX) nFirstPage = nPara; } } -e ... etc. - the rest is truncated