diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-08-19 10:27:00 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-08-19 13:09:33 +0200 |
commit | b55db12f79a01ccbd3276f4a291fe20750efbaf3 (patch) | |
tree | 0f102142980bc0ca86ee2e959f193f7964a1f501 | |
parent | 1b06e7e9e8c467de3450077fe8b90be6b7f73e4b (diff) |
use std::optional<OutlinerParaObject> in SwPostItMgr
it is a COW object, no need to allocate separately on heap
Change-Id: I9388d2a850a39a8645071dfb2907a4fe7785ac21
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120703
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | sw/inc/AnnotationWin.hxx | 3 | ||||
-rw-r--r-- | sw/inc/PostItMgr.hxx | 7 | ||||
-rw-r--r-- | sw/source/uibase/docvw/AnnotationWin.cxx | 6 | ||||
-rw-r--r-- | sw/source/uibase/docvw/AnnotationWin2.cxx | 4 | ||||
-rw-r--r-- | sw/source/uibase/docvw/PostItMgr.cxx | 6 |
5 files changed, 13 insertions, 13 deletions
diff --git a/sw/inc/AnnotationWin.hxx b/sw/inc/AnnotationWin.hxx index 69335760f4fe..53ae31f83b10 100644 --- a/sw/inc/AnnotationWin.hxx +++ b/sw/inc/AnnotationWin.hxx @@ -21,6 +21,7 @@ #define INCLUDED_SW_INC_ANNOTATIONWIN_HXX #include <basegfx/range/b2drange.hxx> +#include <editeng/outlobj.hxx> #include <tools/date.hxx> #include <tools/time.hxx> #include <vcl/InterimItemWindow.hxx> @@ -80,7 +81,7 @@ class SAL_DLLPUBLIC_RTTI SwAnnotationWin final : public InterimItemWindow /// Calculate parent postit id of current annotation window sal_uInt32 CalcParent(); - void InitAnswer(OutlinerParaObject const * pText); + void InitAnswer(OutlinerParaObject const & rText); bool IsProtected() const; diff --git a/sw/inc/PostItMgr.hxx b/sw/inc/PostItMgr.hxx index 760fc7f8abe7..a2f0af3b9dea 100644 --- a/sw/inc/PostItMgr.hxx +++ b/sw/inc/PostItMgr.hxx @@ -33,6 +33,7 @@ #include <unotools/configitem.hxx> #include <com/sun/star/uno/Any.hxx> #include "SidebarWindowsTypes.hxx" +#include <editeng/outlobj.hxx> #include <svl/lstner.hxx> #include <vcl/vclptr.hxx> @@ -137,7 +138,7 @@ class SAL_DLLPUBLIC_RTTI SwPostItMgr final : public SfxListener bool mbReadOnly; bool mbDeleteNote; FieldShadowState mShadowState; - OutlinerParaObject* mpAnswer; + std::optional<OutlinerParaObject> mpAnswer; OUString maAnswerText; bool mbIsShowAnchor; @@ -251,8 +252,8 @@ class SAL_DLLPUBLIC_RTTI SwPostItMgr final : public SfxListener static Color GetColorLight(std::size_t aAuthorIndex); static Color GetColorAnchor(std::size_t aAuthorIndex); - void RegisterAnswer(OutlinerParaObject* pAnswer) { mpAnswer = pAnswer;} - OutlinerParaObject* IsAnswer() {return mpAnswer;} + void RegisterAnswer(OutlinerParaObject* pAnswer) { if (pAnswer) mpAnswer =* pAnswer; else mpAnswer.reset(); } + OutlinerParaObject* IsAnswer() { return mpAnswer ? &*mpAnswer : nullptr; } void RegisterAnswerText(const OUString& aAnswerText) { maAnswerText = aAnswerText; } const OUString& GetAnswerText() const { return maAnswerText; } void CheckMetaText(); diff --git a/sw/source/uibase/docvw/AnnotationWin.cxx b/sw/source/uibase/docvw/AnnotationWin.cxx index 01d12affedad..7ecc4889b5fc 100644 --- a/sw/source/uibase/docvw/AnnotationWin.cxx +++ b/sw/source/uibase/docvw/AnnotationWin.cxx @@ -397,7 +397,7 @@ sal_uInt32 SwAnnotationWin::CountFollowing() return aCount - 1; } -void SwAnnotationWin::InitAnswer(OutlinerParaObject const * pText) +void SwAnnotationWin::InitAnswer(OutlinerParaObject const & rText) { // If tiled annotations is off in lok case, skip adding additional reply text. if (comphelper::LibreOfficeKit::isActive() && !comphelper::LibreOfficeKit::isTiledAnnotations()) @@ -420,8 +420,8 @@ void SwAnnotationWin::InitAnswer(OutlinerParaObject const * pText) // insert old, selected text or "..." // TODO: iterate over all paragraphs, not only first one to find out if it is empty - if (!pText->GetTextObject().GetText(0).isEmpty()) - GetOutlinerView()->GetEditView().InsertText(pText->GetTextObject()); + if (!rText.GetTextObject().GetText(0).isEmpty()) + GetOutlinerView()->GetEditView().InsertText(rText.GetTextObject()); else GetOutlinerView()->InsertText("..."); GetOutlinerView()->InsertText("\"\n"); diff --git a/sw/source/uibase/docvw/AnnotationWin2.cxx b/sw/source/uibase/docvw/AnnotationWin2.cxx index 71a78d6fae0e..12988e4d3343 100644 --- a/sw/source/uibase/docvw/AnnotationWin2.cxx +++ b/sw/source/uibase/docvw/AnnotationWin2.cxx @@ -1072,8 +1072,8 @@ void SwAnnotationWin::ExecuteCommand(sal_uInt16 nSlot) // will be created if (!mpOutliner->GetEditEngine().GetText().isEmpty()) { - OutlinerParaObject* pPara = new OutlinerParaObject(GetOutlinerView()->GetEditView().CreateTextObject()); - mrMgr.RegisterAnswer(pPara); + OutlinerParaObject aPara(GetOutlinerView()->GetEditView().CreateTextObject()); + mrMgr.RegisterAnswer(&aPara); } if (mrMgr.HasActiveSidebarWin()) mrMgr.SetActiveSidebarWin(nullptr); diff --git a/sw/source/uibase/docvw/PostItMgr.cxx b/sw/source/uibase/docvw/PostItMgr.cxx index fe85da695657..a60b70b6cbef 100644 --- a/sw/source/uibase/docvw/PostItMgr.cxx +++ b/sw/source/uibase/docvw/PostItMgr.cxx @@ -200,7 +200,6 @@ SwPostItMgr::SwPostItMgr(SwView* pView) , mbLayouting(false) , mbReadOnly(mpView->GetDocShell()->IsReadOnly()) , mbDeleteNote(true) - , mpAnswer(nullptr) , mbIsShowAnchor( false ) { if(!mpView->GetDrawView() ) @@ -742,9 +741,8 @@ void SwPostItMgr::LayoutPostIts() if (mpAnswer) { if (static_cast<bool>(pPostIt->CalcParent())) //do we really have another note in front of this one - pPostIt->InitAnswer(mpAnswer); - delete mpAnswer; - mpAnswer = nullptr; + pPostIt->InitAnswer(*mpAnswer); + mpAnswer.reset(); } } |