include/svx/svdpage.hxx | 10 ++-- sd/inc/sdpage.hxx | 6 +- sd/source/core/annotations/Annotation.cxx | 2 sd/source/core/sdpage2.cxx | 58 +++++++++++++++---------- sd/source/filter/pdf/sdpdffilter.cxx | 3 - sd/source/ui/annotations/annotationmanager.cxx | 3 - sd/source/ui/unoidl/unopage.cxx | 4 - svx/source/svdraw/svdpage.cxx | 30 ++++++++++++ 8 files changed, 81 insertions(+), 35 deletions(-)
New commits: commit 36a7ff080a9efc864015dba3ea2fbc177b47cb48 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Wed Jun 5 17:33:08 2024 +0900 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Mon Jun 17 09:28:02 2024 +0200 annot: add {add,remove}Annotation that don't notify Add addAnnotationNoNotify method, that doesn't broadcast that an annotation was added, and change addAnnotation to call the method and in addition call the broadcast bits. Previously all this had happened in the addAnnotation without the choice to not broadcast. Change removeAnnotation in a similar way. Change-Id: Ie15a386a8b8d4493d5b41fcbcb55924a693b46d2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168429 Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> Tested-by: Jenkins (cherry picked from commit e467cb52d68692e936eb07c2c1faa45f03dd1f82) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168573 Tested-by: Miklos Vajna <vmik...@collabora.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/include/svx/svdpage.hxx b/include/svx/svdpage.hxx index f3ba6ee60c8e..cc6d4f47492f 100644 --- a/include/svx/svdpage.hxx +++ b/include/svx/svdpage.hxx @@ -557,11 +557,13 @@ public: void dumpAsXml(xmlTextWriterPtr pWriter) const override; - virtual void createAnnotation(rtl::Reference<sdr::annotation::Annotation>& /*xAnnotation*/) { assert(false); } - virtual void addAnnotation(rtl::Reference<sdr::annotation::Annotation> const& /*xAnnotation*/, int /*nIndex*/) { assert(false); } - virtual void removeAnnotation(rtl::Reference<sdr::annotation::Annotation> const& /*xAnnotation*/) { assert(false); } + virtual rtl::Reference<sdr::annotation::Annotation> createAnnotation(); + virtual void addAnnotation(rtl::Reference<sdr::annotation::Annotation> const& xAnnotation, int nIndex = -1); + virtual void addAnnotationNoNotify(rtl::Reference<sdr::annotation::Annotation> const& xAnnotation, int nIndex = -1); + virtual void removeAnnotation(rtl::Reference<sdr::annotation::Annotation> const& xAnnotation); + virtual void removeAnnotationNoNotify(rtl::Reference<sdr::annotation::Annotation> const& xAnnotation); - std::vector<rtl::Reference<sdr::annotation::Annotation>> const& getAnnotations() const { return maAnnotations; } + std::vector<rtl::Reference<sdr::annotation::Annotation>> const& getAnnotations() const; }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/inc/sdpage.hxx b/sd/inc/sdpage.hxx index 3903a59b23ed..ebc4a2b5abba 100644 --- a/sd/inc/sdpage.hxx +++ b/sd/inc/sdpage.hxx @@ -364,9 +364,11 @@ public: */ bool IsPrecious() const { return mbIsPrecious; } - void createAnnotation(rtl::Reference<sdr::annotation::Annotation>& xAnnotation) override; - void addAnnotation(rtl::Reference<sdr::annotation::Annotation> const& xAnnotation, int nIndex) override; + rtl::Reference<sdr::annotation::Annotation> createAnnotation() override; + void addAnnotation(rtl::Reference<sdr::annotation::Annotation> const& xAnnotation, int nIndex = -1) override; + void addAnnotationNoNotify(rtl::Reference<sdr::annotation::Annotation> const& xAnnotation, int nIndex = -1) override; void removeAnnotation(rtl::Reference<sdr::annotation::Annotation> const& xAnnotation) override; + void removeAnnotationNoNotify(rtl::Reference<sdr::annotation::Annotation> const& xAnnotation) override; bool Equals(const SdPage&) const; virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override; diff --git a/sd/source/core/annotations/Annotation.cxx b/sd/source/core/annotations/Annotation.cxx index 2bbb3342be0f..c7f89de4fb1f 100644 --- a/sd/source/core/annotations/Annotation.cxx +++ b/sd/source/core/annotations/Annotation.cxx @@ -61,7 +61,7 @@ protected: } -void createAnnotation(rtl::Reference<sdr::annotation::Annotation>& xAnnotation, SdPage* pPage ) +void createAnnotation(rtl::Reference<sdr::annotation::Annotation>& xAnnotation, SdPage* pPage) { xAnnotation.set(new Annotation(comphelper::getProcessComponentContext(), pPage)); pPage->addAnnotation(xAnnotation, -1); diff --git a/sd/source/core/sdpage2.cxx b/sd/source/core/sdpage2.cxx index 8915ee049b33..f8b6db1d5165 100644 --- a/sd/source/core/sdpage2.cxx +++ b/sd/source/core/sdpage2.cxx @@ -380,8 +380,7 @@ void SdPage::lateInit(const SdPage& rSrcPage) // annotations for (auto const& rSourceAnnotation : rSrcPage.maAnnotations) { - rtl::Reference<sdr::annotation::Annotation> aNewAnnotation; - createAnnotation(aNewAnnotation); + rtl::Reference<sdr::annotation::Annotation> aNewAnnotation = createAnnotation(); aNewAnnotation->setPosition(rSourceAnnotation->getPosition()); aNewAnnotation->setSize(rSourceAnnotation->getSize()); aNewAnnotation->setAuthor(rSourceAnnotation->getAuthor()); @@ -553,12 +552,24 @@ bool SdPage::Equals(const SdPage& rOtherPage) const return true; } -void SdPage::createAnnotation(rtl::Reference<sdr::annotation::Annotation>& xAnnotation) +rtl::Reference<sdr::annotation::Annotation> SdPage::createAnnotation() { + rtl::Reference<sdr::annotation::Annotation> xAnnotation; sd::createAnnotation(xAnnotation, this); + return xAnnotation; } -void SdPage::addAnnotation(rtl::Reference<sdr::annotation::Annotation> const& xAnnotation, int nIndex ) +void SdPage::addAnnotation(rtl::Reference<sdr::annotation::Annotation> const& xAnnotation, int nIndex) +{ + addAnnotationNoNotify(xAnnotation, nIndex); + + NotifyDocumentEvent( + static_cast< SdDrawDocument& >(getSdrModelFromSdrPage()), + "OnAnnotationInserted", + Reference<XInterface>(static_cast<cppu::OWeakObject*>(xAnnotation.get()), UNO_QUERY)); +} + +void SdPage::addAnnotationNoNotify(rtl::Reference<sdr::annotation::Annotation> const& xAnnotation, int nIndex) { if ((nIndex == -1) || (nIndex > int(maAnnotations.size()))) { @@ -566,44 +577,49 @@ void SdPage::addAnnotation(rtl::Reference<sdr::annotation::Annotation> const& xA } else { - maAnnotations.insert( maAnnotations.begin() + nIndex, xAnnotation ); + maAnnotations.insert(maAnnotations.begin() + nIndex, xAnnotation); } - if( getSdrModelFromSdrPage().IsUndoEnabled() ) + SdrModel& rModel = getSdrModelFromSdrPage(); + + if (rModel.IsUndoEnabled()) { rtl::Reference<sdr::annotation::Annotation> xUnconstAnnotation(xAnnotation); std::unique_ptr<SdrUndoAction> pAction = CreateUndoInsertOrRemoveAnnotation(xUnconstAnnotation, true); if (pAction) - getSdrModelFromSdrPage().AddUndo( std::move(pAction) ); + rModel.AddUndo(std::move(pAction)); } SetChanged(); - getSdrModelFromSdrPage().SetChanged(); - NotifyDocumentEvent( - static_cast< SdDrawDocument& >(getSdrModelFromSdrPage()), - "OnAnnotationInserted", - Reference<XInterface>(static_cast<cppu::OWeakObject*>(xAnnotation.get()), UNO_QUERY)); } void SdPage::removeAnnotation(rtl::Reference<sdr::annotation::Annotation> const& xAnnotation) { - if( getSdrModelFromSdrPage().IsUndoEnabled() ) + removeAnnotationNoNotify(xAnnotation); + + NotifyDocumentEvent( + static_cast< SdDrawDocument& >( getSdrModelFromSdrPage() ), + "OnAnnotationRemoved", + Reference<XInterface>( static_cast<cppu::OWeakObject*>(xAnnotation.get()), UNO_QUERY ) ); +} + +void SdPage::removeAnnotationNoNotify(rtl::Reference<sdr::annotation::Annotation> const& xAnnotation) +{ + SdrModel& rModel = getSdrModelFromSdrPage(); + + if (rModel.IsUndoEnabled()) { rtl::Reference<sdr::annotation::Annotation> xUnconstAnnotation(xAnnotation); std::unique_ptr<SdrUndoAction> pAction = CreateUndoInsertOrRemoveAnnotation(xUnconstAnnotation, false); - if( pAction ) - getSdrModelFromSdrPage().AddUndo( std::move(pAction) ); + if (pAction) + rModel.AddUndo(std::move(pAction)); } - sdr::annotation::AnnotationVector::iterator iterator = std::find(maAnnotations.begin(), maAnnotations.end(), xAnnotation); + auto iterator = std::find(maAnnotations.begin(), maAnnotations.end(), xAnnotation); if (iterator != maAnnotations.end()) maAnnotations.erase(iterator); - getSdrModelFromSdrPage().SetChanged(); - NotifyDocumentEvent( - static_cast< SdDrawDocument& >( getSdrModelFromSdrPage() ), - "OnAnnotationRemoved", - Reference<XInterface>( static_cast<cppu::OWeakObject*>(xAnnotation.get()), UNO_QUERY ) ); + rModel.SetChanged(); } void SdPage::getGraphicsForPrefetch(std::vector<Graphic*>& graphics) const diff --git a/sd/source/filter/pdf/sdpdffilter.cxx b/sd/source/filter/pdf/sdpdffilter.cxx index 70ebf0634b95..89ff0dd134db 100644 --- a/sd/source/filter/pdf/sdpdffilter.cxx +++ b/sd/source/filter/pdf/sdpdffilter.cxx @@ -93,8 +93,7 @@ bool SdPdfFilter::Import() for (auto const& rPDFAnnotation : rPDFGraphicResult.GetAnnotations()) { - rtl::Reference<sdr::annotation::Annotation> xAnnotation; - pPage->createAnnotation(xAnnotation); + rtl::Reference<sdr::annotation::Annotation> xAnnotation = pPage->createAnnotation(); xAnnotation->setAuthor(rPDFAnnotation.maAuthor); diff --git a/sd/source/ui/annotations/annotationmanager.cxx b/sd/source/ui/annotations/annotationmanager.cxx index 3366713f5043..2b40e6b3add2 100644 --- a/sd/source/ui/annotations/annotationmanager.cxx +++ b/sd/source/ui/annotations/annotationmanager.cxx @@ -497,8 +497,7 @@ void AnnotationManagerImpl::InsertAnnotation(const OUString& rText) } } - rtl::Reference<sdr::annotation::Annotation> xAnnotation; - pPage->createAnnotation(xAnnotation); + rtl::Reference<sdr::annotation::Annotation> xAnnotation = pPage->createAnnotation(); OUString sAuthor; if (comphelper::LibreOfficeKit::isActive()) diff --git a/sd/source/ui/unoidl/unopage.cxx b/sd/source/ui/unoidl/unopage.cxx index d5d696721f6f..16a6befc20df 100644 --- a/sd/source/ui/unoidl/unopage.cxx +++ b/sd/source/ui/unoidl/unopage.cxx @@ -2524,9 +2524,7 @@ Reference< XAnnotation > SAL_CALL SdGenericDrawPage::createAndInsertAnnotation() if( !GetPage() ) throw DisposedException(); - rtl::Reference<sdr::annotation::Annotation> xRet; - GetPage()->createAnnotation(xRet); - return xRet; + return GetPage()->createAnnotation(); } void SAL_CALL SdGenericDrawPage::removeAnnotation(const Reference< XAnnotation > & annotation) diff --git a/svx/source/svdraw/svdpage.cxx b/svx/source/svdraw/svdpage.cxx index c6e570fdaf6c..ba41dcbdba8c 100644 --- a/svx/source/svdraw/svdpage.cxx +++ b/svx/source/svdraw/svdpage.cxx @@ -1880,5 +1880,35 @@ const SdrPageProperties* SdrPage::getCorrectSdrPageProperties() const } } +rtl::Reference<sdr::annotation::Annotation> SdrPage::createAnnotation() +{ + assert(false); + return nullptr; +} + +void SdrPage::addAnnotation(rtl::Reference<sdr::annotation::Annotation> const& /*xAnnotation*/, int /*nIndex*/) +{ + assert(false); +} + +void SdrPage::addAnnotationNoNotify(rtl::Reference<sdr::annotation::Annotation> const& /*xAnnotation*/, int /*nIndex*/) +{ + assert(false); +} + +void SdrPage::removeAnnotation(rtl::Reference<sdr::annotation::Annotation> const& /*xAnnotation*/) +{ + assert(false); +} + +void SdrPage::removeAnnotationNoNotify(rtl::Reference<sdr::annotation::Annotation> const& /*xAnnotation*/) +{ + assert(false); +} + +std::vector<rtl::Reference<sdr::annotation::Annotation>> const& SdrPage::getAnnotations() const +{ + return maAnnotations; +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */