editeng/source/editeng/editeng.cxx | 49 +----------------------------- editeng/source/editeng/impedit.hxx | 3 + editeng/source/editeng/impedit3.cxx | 58 ++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 46 deletions(-)
New commits: commit 422b5c86e2b9bbf312d9e73a353cfb320aac3a47 Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Sun Jun 16 16:58:40 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Mon Jun 17 12:28:39 2024 +0200 move SetText code from EditEngine to ImpEditEngine so we have the implementation in one class, instead of bouncing back and forth between two. Change-Id: Ie755b1cbc175d98756f6e6ecc173f32c65c7ff7c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168955 Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> Tested-by: Jenkins diff --git a/editeng/source/editeng/editeng.cxx b/editeng/source/editeng/editeng.cxx index 550f996c2874..c1f5824f7af7 100644 --- a/editeng/source/editeng/editeng.cxx +++ b/editeng/source/editeng/editeng.cxx @@ -1039,15 +1039,7 @@ void EditEngine::InsertParagraph(sal_Int32 nPara, const OUString& rTxt) void EditEngine::SetText(sal_Int32 nPara, const OUString& rTxt) { - std::optional<EditSelection> pSel = getImpl().SelectParagraph(nPara); - if ( pSel ) - { - getImpl().UndoActionStart(EDITUNDO_INSERT); - getImpl().ImpInsertText(*pSel, rTxt); - getImpl().UndoActionEnd(); - if (getImpl().IsUpdateLayout()) - getImpl().FormatAndLayout(); - } + getImpl().SetParagraphText(nPara, rTxt); } void EditEngine::SetParaAttribs( sal_Int32 nPara, const SfxItemSet& rSet ) diff --git a/editeng/source/editeng/impedit.hxx b/editeng/source/editeng/impedit.hxx index 3b81785db1f4..d0224d11b6a2 100644 --- a/editeng/source/editeng/impedit.hxx +++ b/editeng/source/editeng/impedit.hxx @@ -1097,6 +1097,7 @@ public: void InsertParagraph(sal_Int32 nPara, const OUString& rTxt); EditPaM InsertParagraph( sal_Int32 nPara ); std::optional<EditSelection> SelectParagraph( sal_Int32 nPara ); + void SetParagraphText(sal_Int32 nPara, const OUString& rTxt); void SetStatusEventHdl( const Link<EditStatus&, void>& rLink ) { maStatusHdlLink = rLink; } const Link<EditStatus&,void>& GetStatusEventHdl() const { return maStatusHdlLink; } diff --git a/editeng/source/editeng/impedit3.cxx b/editeng/source/editeng/impedit3.cxx index 83009f385d76..5195bc3d4cb1 100644 --- a/editeng/source/editeng/impedit3.cxx +++ b/editeng/source/editeng/impedit3.cxx @@ -4664,6 +4664,19 @@ void ImpEditEngine::InsertParagraph(sal_Int32 nPara, const OUString& rTxt) FormatAndLayout(); } +void ImpEditEngine::SetParagraphText(sal_Int32 nPara, const OUString& rTxt) +{ + std::optional<EditSelection> pSel = SelectParagraph(nPara); + if ( pSel ) + { + UndoActionStart(EDITUNDO_INSERT); + ImpInsertText(*pSel, rTxt); + UndoActionEnd(); + if (IsUpdateLayout()) + FormatAndLayout(); + } +} + EditPaM ImpEditEngine::InsertParagraph( sal_Int32 nPara ) { EditPaM aPaM; commit 1b743310a2a5d84fc9048c8ceab3fa8479591203 Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Sun Jun 16 16:46:37 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Mon Jun 17 12:28:30 2024 +0200 move InsertParagragh code from EditEngine to ImpEditEngine so we have the implementation in one class, instead of bouncing back and forth between two. Change-Id: I061481f7218bc0365c6783662c24642da5f63370 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168954 Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> Tested-by: Jenkins diff --git a/editeng/source/editeng/editeng.cxx b/editeng/source/editeng/editeng.cxx index bfd1803cc59a..550f996c2874 100644 --- a/editeng/source/editeng/editeng.cxx +++ b/editeng/source/editeng/editeng.cxx @@ -1029,47 +1029,12 @@ bool EditEngine::IsInSelectionMode() const void EditEngine::InsertParagraph( sal_Int32 nPara, const EditTextObject& rTxtObj, bool bAppend ) { - if ( nPara > GetParagraphCount() ) - { - SAL_WARN_IF( nPara != EE_PARA_APPEND, "editeng", "Paragraph number too large, but not EE_PARA_APPEND!" ); - nPara = GetParagraphCount(); - } - - getImpl().UndoActionStart(EDITUNDO_INSERT); - - // No Undo compounding needed. - EditPaM aPaM(getImpl().InsertParagraph(nPara)); - // When InsertParagraph from the outside, no hard attributes - // should be taken over! - getImpl().RemoveCharAttribs(nPara); - getImpl().InsertText(rTxtObj, EditSelection(aPaM, aPaM)); - - if ( bAppend && nPara ) - getImpl().ConnectContents(nPara - 1, /*bBackwards=*/false); - - getImpl().UndoActionEnd(); - - if (getImpl().IsUpdateLayout()) - getImpl().FormatAndLayout(); + getImpl().InsertParagraph(nPara, rTxtObj, bAppend); } void EditEngine::InsertParagraph(sal_Int32 nPara, const OUString& rTxt) { - if ( nPara > GetParagraphCount() ) - { - SAL_WARN_IF( nPara != EE_PARA_APPEND, "editeng", "Paragraph number too large, but not EE_PARA_APPEND!" ); - nPara = GetParagraphCount(); - } - - getImpl().UndoActionStart(EDITUNDO_INSERT); - EditPaM aPaM(getImpl().InsertParagraph(nPara)); - // When InsertParagraph from the outside, no hard attributes - // should be taken over! - getImpl().RemoveCharAttribs(nPara); - getImpl().UndoActionEnd(); - getImpl().ImpInsertText(EditSelection(aPaM, aPaM), rTxt); - if (getImpl().IsUpdateLayout()) - getImpl().FormatAndLayout(); + getImpl().InsertParagraph(nPara, rTxt); } void EditEngine::SetText(sal_Int32 nPara, const OUString& rTxt) diff --git a/editeng/source/editeng/impedit.hxx b/editeng/source/editeng/impedit.hxx index 324ced7e7138..3b81785db1f4 100644 --- a/editeng/source/editeng/impedit.hxx +++ b/editeng/source/editeng/impedit.hxx @@ -1093,6 +1093,8 @@ public: // OV-Special void InvalidateFromParagraph( sal_Int32 nFirstInvPara ); + void InsertParagraph( sal_Int32 nPara, const EditTextObject& rTxtObj, bool bAppend ); + void InsertParagraph(sal_Int32 nPara, const OUString& rTxt); EditPaM InsertParagraph( sal_Int32 nPara ); std::optional<EditSelection> SelectParagraph( sal_Int32 nPara ); diff --git a/editeng/source/editeng/impedit3.cxx b/editeng/source/editeng/impedit3.cxx index 7df5c4583b74..83009f385d76 100644 --- a/editeng/source/editeng/impedit3.cxx +++ b/editeng/source/editeng/impedit3.cxx @@ -4619,6 +4619,51 @@ tools::Long ImpEditEngine::CalcVertLineSpacing(Point& rStartPos) const return nTotalSpace / (nTotalLineCount-1); } +void ImpEditEngine::InsertParagraph( sal_Int32 nPara, const EditTextObject& rTxtObj, bool bAppend ) +{ + if ( nPara > maEditDoc.Count() ) + { + SAL_WARN_IF( nPara != EE_PARA_APPEND, "editeng", "Paragraph number too large, but not EE_PARA_APPEND!" ); + nPara = maEditDoc.Count(); + } + + UndoActionStart(EDITUNDO_INSERT); + + // No Undo compounding needed. + EditPaM aPaM(InsertParagraph(nPara)); + // When InsertParagraph from the outside, no hard attributes + // should be taken over! + RemoveCharAttribs(nPara); + InsertText(rTxtObj, EditSelection(aPaM, aPaM)); + + if ( bAppend && nPara ) + ConnectContents(nPara - 1, /*bBackwards=*/false); + + UndoActionEnd(); + + if (IsUpdateLayout()) + FormatAndLayout(); +} + +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!" ); + nPara = maEditDoc.Count(); + } + + UndoActionStart(EDITUNDO_INSERT); + EditPaM aPaM(InsertParagraph(nPara)); + // When InsertParagraph from the outside, no hard attributes + // should be taken over! + RemoveCharAttribs(nPara); + UndoActionEnd(); + ImpInsertText(EditSelection(aPaM, aPaM), rTxt); + if (IsUpdateLayout()) + FormatAndLayout(); +} + EditPaM ImpEditEngine::InsertParagraph( sal_Int32 nPara ) { EditPaM aPaM;