diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2024-06-16 16:46:37 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-06-17 12:28:30 +0200 |
commit | 1b743310a2a5d84fc9048c8ceab3fa8479591203 (patch) | |
tree | 860dcfb72eb65baca49e691ed24ab28ba562704c | |
parent | a063a8bc391ae3017a114a9a5edd8073067168dc (diff) |
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.grandin@collabora.co.uk>
Tested-by: Jenkins
-rw-r--r-- | editeng/source/editeng/editeng.cxx | 39 | ||||
-rw-r--r-- | editeng/source/editeng/impedit.hxx | 2 | ||||
-rw-r--r-- | editeng/source/editeng/impedit3.cxx | 45 |
3 files changed, 49 insertions, 37 deletions
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; |