include/svx/svdpage.hxx       |   10 ++++----
 sd/inc/sdpage.hxx             |    5 +++-
 sd/source/core/sdpage2.cxx    |   51 +++++++++++++++++++++++++++---------------
 svx/source/svdraw/svdpage.cxx |   30 ++++++++++++++++++++++++
 4 files changed, 73 insertions(+), 23 deletions(-)

New commits:
commit e467cb52d68692e936eb07c2c1faa45f03dd1f82
Author:     Tomaž Vajngerl <[email protected]>
AuthorDate: Wed Jun 5 17:33:08 2024 +0900
Commit:     Tomaž Vajngerl <[email protected]>
CommitDate: Wed Jun 5 17:26:09 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 <[email protected]>
    Tested-by: Jenkins

diff --git a/include/svx/svdpage.hxx b/include/svx/svdpage.hxx
index 0747c4625773..eb1f04dc10ae 100644
--- a/include/svx/svdpage.hxx
+++ b/include/svx/svdpage.hxx
@@ -555,11 +555,13 @@ public:
 
     void dumpAsXml(xmlTextWriterPtr pWriter) const override;
 
-    virtual rtl::Reference<sdr::annotation::Annotation> createAnnotation() { 
assert(false); return nullptr; }
-    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 5c393082ad40..b0cb6f105c46 100644
--- a/sd/inc/sdpage.hxx
+++ b/sd/inc/sdpage.hxx
@@ -365,8 +365,11 @@ public:
     bool IsPrecious() const { return mbIsPrecious; }
 
     rtl::Reference<sdr::annotation::Annotation> createAnnotation() override;
-    void addAnnotation(rtl::Reference<sdr::annotation::Annotation> const& 
xAnnotation, int nIndex) 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/sdpage2.cxx b/sd/source/core/sdpage2.cxx
index 359339c7ff11..915ed33e75a6 100644
--- a/sd/source/core/sdpage2.cxx
+++ b/sd/source/core/sdpage2.cxx
@@ -556,7 +556,17 @@ rtl::Reference<sdr::annotation::Annotation> 
SdPage::createAnnotation()
     return sd::createAnnotation(this);
 }
 
-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()),
+        u"OnAnnotationInserted"_ustr,
+        
uno::Reference<uno::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())))
     {
@@ -564,44 +574,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()),
-        u"OnAnnotationInserted"_ustr,
-        
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()),
+        u"OnAnnotationRemoved"_ustr,
+        
uno::Reference<uno::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() ),
-        u"OnAnnotationRemoved"_ustr,
-        Reference<XInterface>( 
static_cast<cppu::OWeakObject*>(xAnnotation.get()), UNO_QUERY ) );
+    rModel.SetChanged();
 }
 
 void SdPage::getGraphicsForPrefetch(std::vector<Graphic*>& graphics) const
diff --git a/svx/source/svdraw/svdpage.cxx b/svx/source/svdraw/svdpage.cxx
index 7630b7e26c90..c0c6760e3ae8 100644
--- a/svx/source/svdraw/svdpage.cxx
+++ b/svx/source/svdraw/svdpage.cxx
@@ -1875,5 +1875,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: */

Reply via email to