include/svx/annotation/Annotation.hxx              |   38 +++++++---
 include/svx/annotation/AnnotationEnumeration.hxx   |   11 +--
 include/svx/svdpage.hxx                            |   13 +++
 sd/Library_sd.mk                                   |    1 
 sd/inc/Annotation.hxx                              |   19 -----
 sd/inc/sdpage.hxx                                  |   12 +--
 sd/source/core/annotations/Annotation.cxx          |   67 +++++++-----------
 sd/source/core/sdpage2.cxx                         |   50 +++++++------
 sd/source/filter/pdf/sdpdffilter.cxx               |    7 +
 sd/source/ui/annotations/annotationmanager.cxx     |   77 +++++++++++----------
 sd/source/ui/annotations/annotationmanagerimpl.hxx |   20 ++---
 sd/source/ui/annotations/annotationtag.cxx         |   23 +++---
 sd/source/ui/annotations/annotationtag.hxx         |   11 +--
 sd/source/ui/unoidl/unomodel.cxx                   |    3 
 sd/source/ui/unoidl/unopage.cxx                    |    6 -
 svx/Library_svxcore.mk                             |    1 
 svx/source/annotation/Annotation.cxx               |   21 +++++
 svx/source/annotation/AnnotationEnumeration.cxx    |   46 +++++-------
 svx/source/svdraw/svdpage.cxx                      |    1 
 19 files changed, 225 insertions(+), 202 deletions(-)

New commits:
commit 037196e6355115ea79a10cb6020e6fcaa6958082
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Fri Apr 19 15:34:06 2024 +0900
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Jun 11 09:39:49 2024 +0200

    annot: moved more of Annotation and dependencies into svx
    
    Moved the holder of annotations from SdPage to SvxPage, so that
    the vector holding the annotations and accessors are on SvxPage
    and adapted the code.
    
    This also changes the type od most parameters on most methods
    from sd::Annotation to sdr::annotation::Annotation and adapted
    the code.
    
    Moved AnnotationEnumeration into svx, as it was needed in svx
    already.
    
    Change-Id: Iab17aa881443f58adfb9158959db00ed24076279
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166494
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>
    (cherry picked from commit a0a581ead18f030f59d203539706de0230746cae)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168555
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/include/svx/annotation/Annotation.hxx 
b/include/svx/annotation/Annotation.hxx
index 566dd6ef52f4..a2d1ef371676 100644
--- a/include/svx/annotation/Annotation.hxx
+++ b/include/svx/annotation/Annotation.hxx
@@ -13,12 +13,18 @@
 #include <com/sun/star/geometry/RealSize2D.hpp>
 #include <com/sun/star/util/DateTime.hpp>
 
-#include <svx/svdpage.hxx>
 #include <svx/svdundo.hxx>
 #include <svx/svxdllapi.h>
 
+#include <com/sun/star/office/XAnnotation.hpp>
+#include <cppuhelper/compbase.hxx>
+#include <cppuhelper/propertysetmixin.hxx>
+#include <cppuhelper/basemutex.hxx>
+#include <svx/annotation/Annotation.hxx>
+
 class SdrUndoAction;
 class SfxViewShell;
+class SdrPage;
 
 namespace sdr::annotation
 {
@@ -49,13 +55,16 @@ struct SVXCORE_DLLPUBLIC AnnotationData
 };
 
 class SVXCORE_DLLPUBLIC Annotation
+    : protected ::cppu::BaseMutex,
+      public ::cppu::WeakComponentImplHelper<css::office::XAnnotation>,
+      public ::cppu::PropertySetMixin<css::office::XAnnotation>
 {
 private:
     static sal_uInt32 m_nLastId;
     static sal_uInt32 nextID() { return m_nLastId++; }
 
 protected:
-    SdrPage* mpSdrPage;
+    SdrPage* mpPage;
     sal_uInt32 m_nId;
 
     css::geometry::RealPoint2D m_Position;
@@ -69,10 +78,19 @@ protected:
     std::unique_ptr<SdrUndoAction> createUndoAnnotation();
 
 public:
-    Annotation(SdrPage* pPage)
-        : mpSdrPage(pPage)
-        , m_nId(nextID())
+    Annotation(const css::uno::Reference<css::uno::XComponentContext>& 
context, SdrPage* pPage);
+    Annotation(const Annotation&) = delete;
+    Annotation& operator=(const Annotation&) = delete;
+
+    // XInterface:
+    virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const& type) 
override;
+    virtual void SAL_CALL acquire() noexcept override
+    {
+        ::cppu::WeakComponentImplHelper<css::office::XAnnotation>::acquire();
+    }
+    virtual void SAL_CALL release() noexcept override
     {
+        ::cppu::WeakComponentImplHelper<css::office::XAnnotation>::release();
     }
 
     css::geometry::RealPoint2D GetPosition() const { return m_Position; }
@@ -93,11 +111,9 @@ public:
     virtual OUString GetText() = 0;
     virtual void SetText(OUString const& rText) = 0;
 
-    SdrModel* GetModel()
-    {
-        return mpSdrPage != nullptr ? &mpSdrPage->getSdrModelFromSdrPage() : 
nullptr;
-    }
-    SdrPage const* getPage() const { return mpSdrPage; }
+    SdrModel* GetModel() const;
+    SdrPage const* getPage() const { return mpPage; }
+    SdrPage* getPage() { return mpPage; }
 
     sal_uInt32 GetId() const { return m_nId; }
 
@@ -106,7 +122,7 @@ public:
     bool isFreeText() const { return m_bIsFreeText; }
 };
 
-//typedef std::vector<rtl::Reference<Annotation>> AnnotationVector;
+typedef std::vector<rtl::Reference<Annotation>> AnnotationVector;
 
 } // namespace sdr::annotation
 
diff --git a/sd/inc/AnnotationEnumeration.hxx 
b/include/svx/annotation/AnnotationEnumeration.hxx
similarity index 80%
rename from sd/inc/AnnotationEnumeration.hxx
rename to include/svx/annotation/AnnotationEnumeration.hxx
index ed35b46b4068..a7befcb26946 100644
--- a/sd/inc/AnnotationEnumeration.hxx
+++ b/include/svx/annotation/AnnotationEnumeration.hxx
@@ -20,18 +20,19 @@
 #pragma once
 
 #include <sal/config.h>
-
-#include "sdpage.hxx"
+#include <svx/svxdllapi.h>
 
 namespace com::sun::star::office
 {
 class XAnnotationEnumeration;
 }
 
-namespace sd
+namespace sdr::annotation
 {
-css::uno::Reference<css::office::XAnnotationEnumeration>
-createAnnotationEnumeration(AnnotationVector&&);
+class Annotation;
+SVXCORE_DLLPUBLIC css::uno::Reference<css::office::XAnnotationEnumeration>
+createAnnotationEnumeration(
+    std::vector<rtl::Reference<sdr::annotation::Annotation>>&& 
xAnnotationVector);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/svx/svdpage.hxx b/include/svx/svdpage.hxx
index cb1e7f9f0b20..f3ba6ee60c8e 100644
--- a/include/svx/svdpage.hxx
+++ b/include/svx/svdpage.hxx
@@ -36,11 +36,11 @@
 #include <vector>
 #include <deque>
 
-
 // predefines
 namespace model { class Theme; }
 namespace reportdesign { class OSection; }
 namespace sdr::contact { class ViewContact; }
+namespace sdr::annotation { class Annotation; }
 class SdrPage;
 class SdrModel;
 class SfxItemPool;
@@ -423,6 +423,9 @@ private:
     // the SdrModel this page was created with, unchanged during SdrPage 
lifetime
     SdrModel&                   mrSdrModelFromSdrPage;
 
+protected:
+    std::vector<rtl::Reference<sdr::annotation::Annotation>> maAnnotations;
+
 private:
     tools::Long mnWidth;       // page size
     tools::Long mnHeight;      // page size
@@ -517,8 +520,8 @@ public:
 
 protected:
     void TRG_ImpMasterPageRemoved(const SdrPage& rRemovedPage);
-public:
 
+public:
     /// changing the layers does not set the modified-flag!
     const SdrLayerAdmin& GetLayerAdmin() const;
     SdrLayerAdmin& GetLayerAdmin();
@@ -553,6 +556,12 @@ public:
         bool bEdit );
 
     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); }
+
+    std::vector<rtl::Reference<sdr::annotation::Annotation>> const& 
getAnnotations() const { return maAnnotations; }
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/Library_sd.mk b/sd/Library_sd.mk
index 01c546ad3dca..8c3cc747e102 100644
--- a/sd/Library_sd.mk
+++ b/sd/Library_sd.mk
@@ -158,7 +158,6 @@ $(eval $(call gb_Library_add_exception_objects,sd,\
        sd/source/core/ThemeColorChanger \
        sd/source/core/anminfo \
        sd/source/core/annotations/Annotation \
-       sd/source/core/annotations/AnnotationEnumeration \
        sd/source/core/cusshow \
        sd/source/core/drawdoc \
        sd/source/core/drawdoc2 \
diff --git a/sd/inc/Annotation.hxx b/sd/inc/Annotation.hxx
index 7d63cd54bea9..9e4374de8049 100644
--- a/sd/inc/Annotation.hxx
+++ b/sd/inc/Annotation.hxx
@@ -24,8 +24,6 @@
 #include <memory>
 
 #include <com/sun/star/office/XAnnotation.hpp>
-#include <cppuhelper/basemutex.hxx>
-#include <cppuhelper/compbase.hxx>
 #include <cppuhelper/propertysetmixin.hxx>
 #include <svx/annotation/Annotation.hxx>
 
@@ -47,9 +45,9 @@ class SfxViewShell;
 namespace sd
 {
 
-void createAnnotation( rtl::Reference< Annotation >& xAnnotation, SdPage* 
pPage );
+void createAnnotation(rtl::Reference<sdr::annotation::Annotation>& 
xAnnotation, SdPage* pPage);
 
-std::unique_ptr<SdrUndoAction> CreateUndoInsertOrRemoveAnnotation( const 
css::uno::Reference< css::office::XAnnotation >& xAnnotation, bool bInsert );
+std::unique_ptr<SdrUndoAction> 
CreateUndoInsertOrRemoveAnnotation(rtl::Reference<sdr::annotation::Annotation>& 
xAnnotation, bool bInsert);
 
 struct SD_DLLPUBLIC CustomAnnotationMarker
 {
@@ -59,23 +57,13 @@ struct SD_DLLPUBLIC CustomAnnotationMarker
     std::vector<basegfx::B2DPolygon> maPolygons;
 };
 
-class SD_DLLPUBLIC Annotation final : private ::cppu::BaseMutex,
-                    public sdr::annotation::Annotation,
-                    public 
::cppu::WeakComponentImplHelper<css::office::XAnnotation>,
-                    public ::cppu::PropertySetMixin<css::office::XAnnotation>
+class SD_DLLPUBLIC Annotation final : public sdr::annotation::Annotation
 {
 public:
     explicit Annotation( const 
css::uno::Reference<css::uno::XComponentContext>& context, SdPage* pPage );
     Annotation(const Annotation&) = delete;
     Annotation& operator=(const Annotation&) = delete;
 
-    SdPage* GetPage() const { return mpPage; }
-
-    // XInterface:
-    virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const & type) 
override;
-    virtual void SAL_CALL acquire() noexcept override { 
::cppu::WeakComponentImplHelper<css::office::XAnnotation>::acquire(); }
-    virtual void SAL_CALL release() noexcept override { 
::cppu::WeakComponentImplHelper<css::office::XAnnotation>::release(); }
-
     // css::beans::XPropertySet:
     virtual css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL 
getPropertySetInfo() override;
     virtual void SAL_CALL setPropertyValue(const OUString & aPropertyName, 
const css::uno::Any & aValue) override;
@@ -128,7 +116,6 @@ private:
     // disposed, do it here.
     virtual void SAL_CALL disposing() override;
 
-    SdPage* mpPage;
     rtl::Reference<TextApiObject> m_TextRange;
     std::unique_ptr<CustomAnnotationMarker> m_pCustomAnnotationMarker;
 };
diff --git a/sd/inc/sdpage.hxx b/sd/inc/sdpage.hxx
index ef127ea60769..3903a59b23ed 100644
--- a/sd/inc/sdpage.hxx
+++ b/sd/inc/sdpage.hxx
@@ -79,8 +79,6 @@ namespace sd {
 
         bool operator==( const HeaderFooterSettings& rSettings ) const;
     };
-
-    typedef std::vector< rtl::Reference< Annotation > > AnnotationVector;
 }
 
 namespace sd {
@@ -124,8 +122,6 @@ friend class sd::UndoAttrObject;
     sal_uInt16  mnPaperBin;               ///< PaperBin
     SdPageLink* mpPageLink;               ///< Page link (at left sides only)
 
-    sd::AnnotationVector    maAnnotations;
-
     /** holds the smil animation sequences for this page */
     css::uno::Reference< css::animations::XAnimationNode > mxAnimationNode;
 
@@ -368,10 +364,10 @@ public:
     */
     bool IsPrecious() const { return mbIsPrecious; }
 
-    void createAnnotation( rtl::Reference< sd::Annotation >& xAnnotation );
-    void addAnnotation( const rtl::Reference< sd::Annotation >& xAnnotation, 
int nIndex );
-    void removeAnnotation( const rtl::Reference< sd::Annotation >& xAnnotation 
);
-    const sd::AnnotationVector& getAnnotations() const { return maAnnotations; 
}
+    void createAnnotation(rtl::Reference<sdr::annotation::Annotation>& 
xAnnotation) override;
+    void addAnnotation(rtl::Reference<sdr::annotation::Annotation> const& 
xAnnotation, int nIndex) override;
+    void removeAnnotation(rtl::Reference<sdr::annotation::Annotation> const& 
xAnnotation) override;
+
     bool Equals(const SdPage&) const;
     virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override;
     sal_uInt16 getPageId() const { return mnPageId; }
diff --git a/sd/source/core/annotations/Annotation.cxx 
b/sd/source/core/annotations/Annotation.cxx
index f33d9b61e809..ef42f85924a2 100644
--- a/sd/source/core/annotations/Annotation.cxx
+++ b/sd/source/core/annotations/Annotation.cxx
@@ -48,31 +48,27 @@ namespace {
 class UndoInsertOrRemoveAnnotation : public SdrUndoAction
 {
 public:
-    UndoInsertOrRemoveAnnotation( Annotation& rAnnotation, bool bInsert );
+    UndoInsertOrRemoveAnnotation(rtl::Reference<sdr::annotation::Annotation>& 
xAnnotation, bool bInsert);
 
     virtual void Undo() override;
     virtual void Redo() override;
 
 protected:
-    rtl::Reference< Annotation > mxAnnotation;
+    rtl::Reference<sdr::annotation::Annotation> mxAnnotation;
     bool mbInsert;
-    int mnIndex;
+    int mnIndex = 0;
 };
 
 }
 
-void createAnnotation(rtl::Reference<Annotation>& xAnnotation, SdPage* pPage )
+void createAnnotation(rtl::Reference<sdr::annotation::Annotation>& 
xAnnotation, SdPage* pPage )
 {
-    xAnnotation.set(
-        new Annotation(comphelper::getProcessComponentContext(), pPage));
+    xAnnotation.set(new Annotation(comphelper::getProcessComponentContext(), 
pPage));
     pPage->addAnnotation(xAnnotation, -1);
 }
 
 Annotation::Annotation(const uno::Reference<uno::XComponentContext>& context, 
SdPage* pPage)
-    : sdr::annotation::Annotation(pPage)
-    , ::cppu::WeakComponentImplHelper<office::XAnnotation>(m_aMutex)
-    , ::cppu::PropertySetMixin<office::XAnnotation>(context, 
IMPLEMENTS_PROPERTY_SET, uno::Sequence<OUString>())
-    , mpPage(pPage)
+    : sdr::annotation::Annotation(context, pPage)
 {
 }
 
@@ -90,11 +86,6 @@ void SAL_CALL Annotation::disposing()
     }
 }
 
-uno::Any Annotation::queryInterface(css::uno::Type const & type)
-{
-    return 
::cppu::WeakComponentImplHelper<office::XAnnotation>::queryInterface(type);
-}
-
 // com.sun.star.beans.XPropertySet:
 uno::Reference<beans::XPropertySetInfo> SAL_CALL 
Annotation::getPropertySetInfo()
 {
@@ -264,12 +255,11 @@ uno::Reference<text::XText> SAL_CALL 
Annotation::getTextRange()
     return m_TextRange;
 }
 
-std::unique_ptr<SdrUndoAction> CreateUndoInsertOrRemoveAnnotation( const 
uno::Reference<office::XAnnotation>& xAnnotation, bool bInsert )
+std::unique_ptr<SdrUndoAction> 
CreateUndoInsertOrRemoveAnnotation(rtl::Reference<sdr::annotation::Annotation>& 
xAnnotation, bool bInsert)
 {
-    Annotation* pAnnotation = dynamic_cast< Annotation* >( xAnnotation.get() );
-    if( pAnnotation )
+    if (xAnnotation)
     {
-        return std::make_unique< UndoInsertOrRemoveAnnotation >( *pAnnotation, 
bInsert );
+        return std::make_unique<UndoInsertOrRemoveAnnotation>(xAnnotation, 
bInsert);
     }
     else
     {
@@ -277,54 +267,53 @@ std::unique_ptr<SdrUndoAction> 
CreateUndoInsertOrRemoveAnnotation( const uno::Re
     }
 }
 
-UndoInsertOrRemoveAnnotation::UndoInsertOrRemoveAnnotation( Annotation& 
rAnnotation, bool bInsert )
-: SdrUndoAction( *rAnnotation.GetModel() )
-, mxAnnotation( &rAnnotation )
-, mbInsert( bInsert )
-, mnIndex( 0 )
+UndoInsertOrRemoveAnnotation::UndoInsertOrRemoveAnnotation(rtl::Reference<sdr::annotation::Annotation>&
 xAnnotation, bool bInsert)
+    : SdrUndoAction(*xAnnotation->GetModel())
+    , mxAnnotation(xAnnotation)
+    , mbInsert(bInsert)
 {
-    SdPage* pPage = rAnnotation.GetPage();
-    if( pPage )
+    SdrPage const* pPage = mxAnnotation->getPage();
+    if (pPage)
     {
-        const AnnotationVector& rVec = pPage->getAnnotations();
-        auto iter = std::find(rVec.begin(), rVec.end(), &rAnnotation);
-        mnIndex += std::distance(rVec.begin(), iter);
+        sdr::annotation::AnnotationVector const& rVector = 
pPage->getAnnotations();
+        auto iterator = std::find(rVector.begin(), rVector.end(), 
mxAnnotation);
+        mnIndex += std::distance(rVector.begin(), iterator);
     }
 }
 
 void UndoInsertOrRemoveAnnotation::Undo()
 {
-    SdPage* pPage = mxAnnotation->GetPage();
+    SdrPage* pPage = mxAnnotation->getPage();
     SdrModel* pModel = mxAnnotation->GetModel();
-    if( !(pPage && pModel) )
+    if (!pPage || !pModel)
         return;
 
-    if( mbInsert )
+    if (mbInsert)
     {
-        pPage->removeAnnotation( mxAnnotation );
+        pPage->removeAnnotation(mxAnnotation);
     }
     else
     {
-        pPage->addAnnotation( mxAnnotation, mnIndex );
+        pPage->addAnnotation(mxAnnotation, mnIndex);
         LOKCommentNotifyAll(sdr::annotation::CommentNotificationType::Add, 
*mxAnnotation);
     }
 }
 
 void UndoInsertOrRemoveAnnotation::Redo()
 {
-    SdPage* pPage = mxAnnotation->GetPage();
+    SdrPage* pPage = mxAnnotation->getPage();
     SdrModel* pModel = mxAnnotation->GetModel();
-    if( !(pPage && pModel) )
+    if (!pPage || !pModel)
         return;
 
-    if( mbInsert )
+    if (mbInsert)
     {
-        pPage->addAnnotation( mxAnnotation, mnIndex );
+        pPage->addAnnotation(mxAnnotation, mnIndex);
         LOKCommentNotifyAll(sdr::annotation::CommentNotificationType::Add, 
*mxAnnotation);
     }
     else
     {
-        pPage->removeAnnotation( mxAnnotation );
+        pPage->removeAnnotation(mxAnnotation);
     }
 }
 
diff --git a/sd/source/core/sdpage2.cxx b/sd/source/core/sdpage2.cxx
index 0195a5578acb..8915ee049b33 100644
--- a/sd/source/core/sdpage2.cxx
+++ b/sd/source/core/sdpage2.cxx
@@ -378,19 +378,19 @@ void SdPage::lateInit(const SdPage& rSrcPage)
     rSrcPage.cloneAnimations(*this);
 
     // annotations
-    for(const rtl::Reference< Annotation >& srcAnnotation : 
rSrcPage.maAnnotations)
+    for (auto const& rSourceAnnotation : rSrcPage.maAnnotations)
     {
-        rtl::Reference< Annotation > ref;
-        createAnnotation(ref);
-        ref->setPosition(srcAnnotation->getPosition());
-        ref->setSize(srcAnnotation->getSize());
-        ref->setAuthor(srcAnnotation->getAuthor());
-        ref->setInitials(srcAnnotation->getInitials());
-        ref->setDateTime(srcAnnotation->getDateTime());
-        Reference< ::css::text::XTextCopy > srcRange ( 
srcAnnotation->getTextRange(), uno::UNO_QUERY);
-        Reference< ::css::text::XTextCopy > range ( ref->getTextRange(), 
uno::UNO_QUERY);
-        if(srcRange.is() && range.is())
-            range->copyText( srcRange );
+        rtl::Reference<sdr::annotation::Annotation> aNewAnnotation;
+        createAnnotation(aNewAnnotation);
+        aNewAnnotation->setPosition(rSourceAnnotation->getPosition());
+        aNewAnnotation->setSize(rSourceAnnotation->getSize());
+        aNewAnnotation->setAuthor(rSourceAnnotation->getAuthor());
+        aNewAnnotation->setInitials(rSourceAnnotation->getInitials());
+        aNewAnnotation->setDateTime(rSourceAnnotation->getDateTime());
+        uno::Reference<css::text::XTextCopy> xSourceRange 
(rSourceAnnotation->getTextRange(), uno::UNO_QUERY);
+        uno::Reference<css::text::XTextCopy> xRange 
(aNewAnnotation->getTextRange(), uno::UNO_QUERY);
+        if(xSourceRange.is() && xRange.is())
+            xRange->copyText(xSourceRange);
     }
 
     // fix user calls for duplicated slide
@@ -553,16 +553,16 @@ bool SdPage::Equals(const SdPage& rOtherPage) const
     return true;
  }
 
-void SdPage::createAnnotation( rtl::Reference< Annotation >& xAnnotation )
+void SdPage::createAnnotation(rtl::Reference<sdr::annotation::Annotation>& 
xAnnotation)
 {
-    sd::createAnnotation( xAnnotation, this );
+    sd::createAnnotation(xAnnotation, this);
 }
 
-void SdPage::addAnnotation( const rtl::Reference< Annotation >& xAnnotation, 
int nIndex )
+void SdPage::addAnnotation(rtl::Reference<sdr::annotation::Annotation> const& 
xAnnotation, int nIndex )
 {
-    if( (nIndex == -1) || (nIndex > static_cast<int>(maAnnotations.size())) )
+    if ((nIndex == -1) || (nIndex > int(maAnnotations.size())))
     {
-        maAnnotations.push_back( xAnnotation );
+        maAnnotations.push_back(xAnnotation);
     }
     else
     {
@@ -571,8 +571,9 @@ void SdPage::addAnnotation( const rtl::Reference< 
Annotation >& xAnnotation, int
 
     if( getSdrModelFromSdrPage().IsUndoEnabled() )
     {
-        std::unique_ptr<SdrUndoAction> pAction = 
CreateUndoInsertOrRemoveAnnotation( xAnnotation, true );
-        if( pAction )
+        rtl::Reference<sdr::annotation::Annotation> 
xUnconstAnnotation(xAnnotation);
+        std::unique_ptr<SdrUndoAction> pAction = 
CreateUndoInsertOrRemoveAnnotation(xUnconstAnnotation, true);
+        if (pAction)
             getSdrModelFromSdrPage().AddUndo( std::move(pAction) );
     }
 
@@ -584,18 +585,19 @@ void SdPage::addAnnotation( const rtl::Reference< 
Annotation >& xAnnotation, int
         
Reference<XInterface>(static_cast<cppu::OWeakObject*>(xAnnotation.get()), 
UNO_QUERY));
 }
 
-void SdPage::removeAnnotation( const rtl::Reference< Annotation >& xAnnotation 
)
+void SdPage::removeAnnotation(rtl::Reference<sdr::annotation::Annotation> 
const& xAnnotation)
 {
     if( getSdrModelFromSdrPage().IsUndoEnabled() )
     {
-        std::unique_ptr<SdrUndoAction> pAction = 
CreateUndoInsertOrRemoveAnnotation( xAnnotation, false );
+        rtl::Reference<sdr::annotation::Annotation> 
xUnconstAnnotation(xAnnotation);
+        std::unique_ptr<SdrUndoAction> pAction = 
CreateUndoInsertOrRemoveAnnotation(xUnconstAnnotation, false);
         if( pAction )
             getSdrModelFromSdrPage().AddUndo( std::move(pAction) );
     }
 
-    AnnotationVector::iterator iter = std::find( maAnnotations.begin(), 
maAnnotations.end(), xAnnotation );
-    if( iter != maAnnotations.end() )
-        maAnnotations.erase( iter );
+    sdr::annotation::AnnotationVector::iterator iterator = 
std::find(maAnnotations.begin(), maAnnotations.end(), xAnnotation);
+    if (iterator != maAnnotations.end())
+        maAnnotations.erase(iterator);
 
     getSdrModelFromSdrPage().SetChanged();
     NotifyDocumentEvent(
diff --git a/sd/source/filter/pdf/sdpdffilter.cxx 
b/sd/source/filter/pdf/sdpdffilter.cxx
index c0800010e16a..70ebf0634b95 100644
--- a/sd/source/filter/pdf/sdpdffilter.cxx
+++ b/sd/source/filter/pdf/sdpdffilter.cxx
@@ -93,7 +93,7 @@ bool SdPdfFilter::Import()
 
         for (auto const& rPDFAnnotation : rPDFGraphicResult.GetAnnotations())
         {
-            rtl::Reference<sd::Annotation> xAnnotation;
+            rtl::Reference<sdr::annotation::Annotation> xAnnotation;
             pPage->createAnnotation(xAnnotation);
 
             xAnnotation->setAuthor(rPDFAnnotation.maAuthor);
@@ -111,9 +111,10 @@ bool SdPdfFilter::Import()
 
             if (rPDFAnnotation.mpMarker)
             {
-                xAnnotation->createCustomAnnotationMarker();
+                auto* pAnnotation = 
static_cast<sd::Annotation*>(xAnnotation.get());
+                pAnnotation->createCustomAnnotationMarker();
                 sd::CustomAnnotationMarker& rCustomAnnotationMarker
-                    = xAnnotation->getCustomAnnotationMarker();
+                    = pAnnotation->getCustomAnnotationMarker();
 
                 rCustomAnnotationMarker.maLineColor = rPDFAnnotation.maColor;
 
diff --git a/sd/source/ui/annotations/annotationmanager.cxx 
b/sd/source/ui/annotations/annotationmanager.cxx
index 02b46a324908..984773b7b9a9 100644
--- a/sd/source/ui/annotations/annotationmanager.cxx
+++ b/sd/source/ui/annotations/annotationmanager.cxx
@@ -248,7 +248,7 @@ void SAL_CALL AnnotationManagerImpl::disposing( const 
css::lang::EventObject& /*
 {
 }
 
-rtl::Reference<Annotation> AnnotationManagerImpl::GetAnnotationById(sal_uInt32 
nAnnotationId)
+rtl::Reference<sdr::annotation::Annotation> 
AnnotationManagerImpl::GetAnnotationById(sal_uInt32 nAnnotationId)
 {
     SdPage* pPage = nullptr;
     do
@@ -256,17 +256,17 @@ rtl::Reference<Annotation> 
AnnotationManagerImpl::GetAnnotationById(sal_uInt32 n
         pPage = GetNextPage(pPage, true);
         if( pPage && !pPage->getAnnotations().empty() )
         {
-            AnnotationVector aAnnotations(pPage->getAnnotations());
-            auto iter = std::find_if(aAnnotations.begin(), aAnnotations.end(),
-                [nAnnotationId](rtl::Reference<sd::Annotation>& xAnnotation) {
+            sdr::annotation::AnnotationVector 
aAnnotations(pPage->getAnnotations());
+            auto iterator = std::find_if(aAnnotations.begin(), 
aAnnotations.end(),
+                [nAnnotationId](rtl::Reference<sdr::annotation::Annotation>& 
xAnnotation) {
                     return xAnnotation->GetId() == nAnnotationId;
                 });
-            if (iter != aAnnotations.end())
-                return *iter;
+            if (iterator != aAnnotations.end())
+                return *iterator;
         }
-    } while( pPage );
+    } while(pPage);
 
-    rtl::Reference<Annotation> xAnnotationEmpty;
+    rtl::Reference<sdr::annotation::Annotation> xAnnotationEmpty;
     return xAnnotationEmpty;
 }
 
@@ -355,7 +355,7 @@ void 
AnnotationManagerImpl::ExecuteDeleteAnnotation(SfxRequest const & rReq)
         break;
     case SID_DELETE_POSTIT:
         {
-            rtl::Reference< Annotation > xAnnotation;
+            rtl::Reference<sdr::annotation::Annotation> xAnnotation;
             sal_uInt32 nId = 0;
             if( pArgs )
             {
@@ -365,7 +365,7 @@ void 
AnnotationManagerImpl::ExecuteDeleteAnnotation(SfxRequest const & rReq)
                     uno::Reference<XAnnotation> xTmpAnnotation;
                     if (static_cast<const 
SfxUnoAnyItem*>(pPoolItem)->GetValue() >>= xTmpAnnotation)
                     {
-                        xAnnotation = 
dynamic_cast<Annotation*>(xTmpAnnotation.get());
+                        xAnnotation = 
dynamic_cast<sdr::annotation::Annotation*>(xTmpAnnotation.get());
                         assert(bool(xAnnotation) == bool(xTmpAnnotation) && 
"must be of concrete type sd::Annotation");
                     }
                 }
@@ -376,9 +376,9 @@ void 
AnnotationManagerImpl::ExecuteDeleteAnnotation(SfxRequest const & rReq)
             if (nId != 0)
                 xAnnotation = GetAnnotationById(nId);
             else if( !xAnnotation.is() )
-                GetSelectedAnnotation( xAnnotation );
+                GetSelectedAnnotation(xAnnotation);
 
-            DeleteAnnotation( xAnnotation );
+            DeleteAnnotation(xAnnotation);
         }
         break;
     }
@@ -389,7 +389,7 @@ void 
AnnotationManagerImpl::ExecuteDeleteAnnotation(SfxRequest const & rReq)
 void AnnotationManagerImpl::ExecuteEditAnnotation(SfxRequest const & rReq)
 {
     const SfxItemSet* pArgs = rReq.GetArgs();
-    rtl::Reference<sd::Annotation> xAnnotation;
+    rtl::Reference<sdr::annotation::Annotation> xAnnotation;
     OUString sText;
     sal_Int32 nPositionX = -1;
     sal_Int32 nPositionY = -1;
@@ -416,7 +416,8 @@ void 
AnnotationManagerImpl::ExecuteEditAnnotation(SfxRequest const & rReq)
 
     if (xAnnotation.is())
     {
-        xAnnotation->createChangeUndo();
+        auto pSdAnnotation = static_cast<sd::Annotation*>(xAnnotation.get());
+        pSdAnnotation->createChangeUndo();
 
         if (nPositionX >= 0 && nPositionY >= 0)
         {
@@ -452,7 +453,7 @@ void AnnotationManagerImpl::InsertAnnotation(const 
OUString& rText)
     // find free space for new annotation
     int y = 0, x = 0;
 
-    AnnotationVector aAnnotations( pPage->getAnnotations() );
+    sdr::annotation::AnnotationVector aAnnotations(pPage->getAnnotations());
     if( !aAnnotations.empty() )
     {
         const int page_width = pPage->GetSize().Width();
@@ -496,8 +497,8 @@ void AnnotationManagerImpl::InsertAnnotation(const 
OUString& rText)
         }
     }
 
-    rtl::Reference< Annotation > xAnnotation;
-    pPage->createAnnotation( xAnnotation );
+    rtl::Reference<sdr::annotation::Annotation> xAnnotation;
+    pPage->createAnnotation(xAnnotation);
 
     OUString sAuthor;
     if (comphelper::LibreOfficeKit::isActive())
@@ -536,7 +537,7 @@ void AnnotationManagerImpl::InsertAnnotation(const 
OUString& rText)
 
 void AnnotationManagerImpl::ExecuteReplyToAnnotation( SfxRequest const & rReq )
 {
-    rtl::Reference< Annotation > xAnnotation;
+    rtl::Reference< sdr::annotation::Annotation> xAnnotation;
     const SfxItemSet* pArgs = rReq.GetArgs();
     OUString sReplyText;
     if( pArgs )
@@ -569,7 +570,11 @@ void AnnotationManagerImpl::ExecuteReplyToAnnotation( 
SfxRequest const & rReq )
     if (mpDoc->IsUndoEnabled())
         mpDoc->BegUndo(SdResId(STR_ANNOTATION_REPLY));
 
-    xAnnotation->createChangeUndo();
+    if (xAnnotation)
+    {
+        auto pSdAnnotation = static_cast<sd::Annotation*>(xAnnotation.get());
+        pSdAnnotation->createChangeUndo();
+    }
     ::Outliner aOutliner( GetAnnotationPool(),OutlinerMode::TextObject );
 
     SdDrawDocument::SetCalcFieldValueHdl( &aOutliner );
@@ -634,7 +639,7 @@ void AnnotationManagerImpl::ExecuteReplyToAnnotation( 
SfxRequest const & rReq )
     SelectAnnotation( xAnnotation, true );
 }
 
-void AnnotationManagerImpl::DeleteAnnotation( const rtl::Reference< Annotation 
>& xAnnotation )
+void 
AnnotationManagerImpl::DeleteAnnotation(rtl::Reference<sdr::annotation::Annotation>
 const& xAnnotation )
 {
     SdPage* pPage = GetCurrentPage();
 
@@ -664,7 +669,7 @@ void AnnotationManagerImpl::DeleteAnnotationsByAuthor( 
std::u16string_view sAuth
 
         if( pPage )
         {
-            for( const rtl::Reference< Annotation >& xAnnotation : 
pPage->getAnnotations() )
+            for (auto const& xAnnotation : pPage->getAnnotations())
             {
                 if( xAnnotation->getAuthor() == sAuthor )
                 {
@@ -693,8 +698,7 @@ void AnnotationManagerImpl::DeleteAllAnnotations()
         if( pPage && !pPage->getAnnotations().empty() )
         {
 
-            AnnotationVector aAnnotations( pPage->getAnnotations() );
-            for( const auto& rxAnnotation : aAnnotations )
+            for( const auto& rxAnnotation : pPage->getAnnotations())
             {
                 pPage->removeAnnotation( rxAnnotation );
             }
@@ -722,8 +726,8 @@ void AnnotationManagerImpl::GetAnnotationState(SfxItemSet& 
rSet)
 
     rSet.Put(SfxBoolItem(SID_TOGGLE_NOTES, mbShowAnnotations));
 
-    rtl::Reference< Annotation > xAnnotation;
-    GetSelectedAnnotation( xAnnotation );
+    rtl::Reference<sdr::annotation::Annotation> xAnnotation;
+    GetSelectedAnnotation(xAnnotation);
 
     // Don't disable these slot in case of LOK, as postit doesn't need to
     // selected before doing an operation on it in LOK
@@ -761,13 +765,13 @@ void AnnotationManagerImpl::SelectNextAnnotation(bool 
bForward)
 {
     ShowAnnotations( true );
 
-    rtl::Reference< Annotation > xCurrent;
-    GetSelectedAnnotation( xCurrent );
+    rtl::Reference<sdr::annotation::Annotation> xCurrent;
+    GetSelectedAnnotation(xCurrent);
     SdPage* pPage = GetCurrentPage();
     if( !pPage )
         return;
 
-    AnnotationVector aAnnotations( pPage->getAnnotations() );
+    sdr::annotation::AnnotationVector const& aAnnotations = 
pPage->getAnnotations();
 
     if( bForward )
     {
@@ -804,8 +808,9 @@ void AnnotationManagerImpl::SelectNextAnnotation(bool 
bForward)
         }
         else if( !aAnnotations.empty() )
         {
-            AnnotationVector::iterator iter( aAnnotations.end() );
-            SelectAnnotation( *(--iter) );
+            auto iterator = aAnnotations.end();
+            iterator--;
+            SelectAnnotation(*iterator);
             return;
         }
     }
@@ -864,14 +869,14 @@ void AnnotationManagerImpl::onTagSelected( AnnotationTag 
const & rTag )
 
 void AnnotationManagerImpl::onTagDeselected( AnnotationTag const & rTag )
 {
-    if( rTag.GetAnnotation() == mxSelectedAnnotation )
+    if (rTag.GetAnnotation() == mxSelectedAnnotation)
     {
         mxSelectedAnnotation.clear();
         invalidateSlots();
     }
 }
 
-void AnnotationManagerImpl::SelectAnnotation( const rtl::Reference< Annotation 
>& xAnnotation, bool bEdit /* = sal_False */ )
+void 
AnnotationManagerImpl::SelectAnnotation(rtl::Reference<sdr::annotation::Annotation>
 const& xAnnotation, bool bEdit)
 {
     mxSelectedAnnotation = xAnnotation;
 
@@ -885,7 +890,7 @@ void AnnotationManagerImpl::SelectAnnotation( const 
rtl::Reference< Annotation >
     }
 }
 
-void AnnotationManagerImpl::GetSelectedAnnotation( rtl::Reference< Annotation 
>& xAnnotation )
+void AnnotationManagerImpl::GetSelectedAnnotation( 
rtl::Reference<sdr::annotation::Annotation>& xAnnotation )
 {
     xAnnotation = mxSelectedAnnotation;
 }
@@ -973,13 +978,13 @@ void AnnotationManagerImpl::CreateTags()
 
         rtl::Reference< AnnotationTag > xSelectedTag;
 
-        for (const rtl::Reference< Annotation > & xAnnotation : 
mxCurrentPage->getAnnotations() )
+        for (rtl::Reference<sdr::annotation::Annotation> const& xAnnotation : 
mxCurrentPage->getAnnotations())
         {
             Color aColor( GetColorLight( mpDoc->GetAnnotationAuthorIndex( 
xAnnotation->getAuthor() ) ) );
             rtl::Reference< AnnotationTag > xTag( new AnnotationTag( *this, 
*xViewShell->GetView(), xAnnotation, aColor, nIndex++, maFont ) );
             maTagVector.push_back(xTag);
 
-            if( xAnnotation == mxSelectedAnnotation )
+            if (xAnnotation == mxSelectedAnnotation)
             {
                 xSelectedTag = xTag;
             }
@@ -1048,7 +1053,7 @@ IMPL_LINK(AnnotationManagerImpl,EventMultiplexerListener,
     }
 }
 
-void AnnotationManagerImpl::ExecuteAnnotationTagContextMenu(const 
rtl::Reference<Annotation>& xAnnotation, weld::Widget* pParent, const 
::tools::Rectangle& rContextRect)
+void AnnotationManagerImpl::ExecuteAnnotationTagContextMenu(const 
rtl::Reference<sdr::annotation::Annotation>& xAnnotation, weld::Widget* 
pParent, const ::tools::Rectangle& rContextRect)
 {
     SfxDispatcher* pDispatcher( getDispatcher( mrBase ) );
     if( !pDispatcher )
diff --git a/sd/source/ui/annotations/annotationmanagerimpl.hxx 
b/sd/source/ui/annotations/annotationmanagerimpl.hxx
index bbcd5a852199..1a7b60263089 100644
--- a/sd/source/ui/annotations/annotationmanagerimpl.hxx
+++ b/sd/source/ui/annotations/annotationmanagerimpl.hxx
@@ -36,14 +36,14 @@ class SdPage;
 class SdDrawDocument;
 struct ImplSVEvent;
 
+namespace sdr::annotation { class Annotation; }
+
 namespace sd
 {
 class Annotation;
 class ViewShellBase;
 
-namespace tools {
-class EventMultiplexerEvent;
-}
+namespace tools { class EventMultiplexerEvent; }
 
 typedef comphelper::WeakComponentImplHelper <
     css::document::XEventListener
@@ -73,15 +73,15 @@ public:
 
     void SelectNextAnnotation(bool bForward);
 
-    void SelectAnnotation( const rtl::Reference< Annotation >& xAnnotation, 
bool bEdit = false );
-    void GetSelectedAnnotation( rtl::Reference< Annotation >& xAnnotation );
+    void SelectAnnotation(rtl::Reference<sdr::annotation::Annotation> const& 
xAnnotation, bool bEdit = false);
+    void GetSelectedAnnotation(rtl::Reference<sdr::annotation::Annotation>& 
xAnnotation);
 
     void InsertAnnotation(const OUString& rText);
-    void DeleteAnnotation( const rtl::Reference< Annotation >& xAnnotation );
+    void DeleteAnnotation(rtl::Reference<sdr::annotation::Annotation> const& 
xAnnotation);
     void DeleteAnnotationsByAuthor( std::u16string_view sAuthor );
     void DeleteAllAnnotations();
 
-    void ExecuteAnnotationTagContextMenu(const rtl::Reference<Annotation>& 
xAnnotation, weld::Widget* pParent, const ::tools::Rectangle& rContextRect);
+    void 
ExecuteAnnotationTagContextMenu(rtl::Reference<sdr::annotation::Annotation> 
const& xAnnotation, weld::Widget* pParent, const ::tools::Rectangle& 
rContextRect);
 
     static Color GetColorDark(sal_uInt16 aAuthorIndex);
     static Color GetColorLight(sal_uInt16 aAuthorIndex);
@@ -120,14 +120,14 @@ private:
     std::vector< rtl::Reference< AnnotationTag > > maTagVector;
 
     css::uno::Reference< css::drawing::XDrawView > mxView;
-    rtl::Reference< SdPage > mxCurrentPage;
-    rtl::Reference< Annotation > mxSelectedAnnotation;
+    rtl::Reference<SdPage> mxCurrentPage;
+    rtl::Reference<sdr::annotation::Annotation> mxSelectedAnnotation;
 
     bool mbShowAnnotations;
     ImplSVEvent * mnUpdateTagsEvent;
     vcl::Font maFont;
 
-    rtl::Reference<Annotation> GetAnnotationById(sal_uInt32 nAnnotationId);
+    rtl::Reference<sdr::annotation::Annotation> GetAnnotationById(sal_uInt32 
nAnnotationId);
 };
 
 OUString getAnnotationDateTimeString( const css::uno::Reference< 
css::office::XAnnotation >& xAnnotation );
diff --git a/sd/source/ui/annotations/annotationtag.cxx 
b/sd/source/ui/annotations/annotationtag.cxx
index 6bea2492725e..01810721c16a 100644
--- a/sd/source/ui/annotations/annotationtag.cxx
+++ b/sd/source/ui/annotations/annotationtag.cxx
@@ -43,6 +43,7 @@
 #include "annotationmanagerimpl.hxx"
 #include "annotationwindow.hxx"
 #include "annotationtag.hxx"
+#include <svx/annotation/Annotation.hxx>
 #include <Annotation.hxx>
 #include <ViewShell.hxx>
 #include <Window.hxx>
@@ -162,22 +163,22 @@ namespace {
 class AnnotationHdl : public SmartHdl
 {
 public:
-    AnnotationHdl( const SmartTagReference& xTag, const rtl::Reference< 
Annotation >& xAnnotation, const Point& rPnt );
+    AnnotationHdl( const SmartTagReference& xTag, 
rtl::Reference<sdr::annotation::Annotation> const& xAnnotation, const Point& 
rPnt );
 
     virtual void CreateB2dIAObject() override;
     virtual bool IsFocusHdl() const override;
 
 private:
-    rtl::Reference< sd::Annotation > mxAnnotation;
-    rtl::Reference< AnnotationTag > mxTag;
+    rtl::Reference<sdr::annotation::Annotation> mxAnnotation;
+    rtl::Reference<AnnotationTag> mxTag;
 };
 
 }
 
-AnnotationHdl::AnnotationHdl( const SmartTagReference& xTag, const 
rtl::Reference< Annotation >& xAnnotation, const Point& rPnt )
-: SmartHdl( xTag, rPnt, SdrHdlKind::SmartTag )
-, mxAnnotation( xAnnotation )
-, mxTag( dynamic_cast< AnnotationTag* >( xTag.get() ) )
+AnnotationHdl::AnnotationHdl( const SmartTagReference& xTag, 
rtl::Reference<sdr::annotation::Annotation> const& xAnnotation, const Point& 
rPnt )
+    : SmartHdl(xTag, rPnt, SdrHdlKind::SmartTag)
+    , mxAnnotation(xAnnotation)
+    , mxTag(dynamic_cast<AnnotationTag*>(xTag.get()))
 {
 }
 
@@ -224,10 +225,10 @@ void AnnotationHdl::CreateB2dIAObject()
         if(rPaintWindow.OutputToWindow() && xManager.is() )
         {
             std::unique_ptr<sdr::overlay::OverlayObject> pOverlayObject;
-
-            if (mxAnnotation && mxAnnotation->hasCustomAnnotationMarker())
+            auto pSdAnnotation = 
dynamic_cast<sd::Annotation*>(mxAnnotation.get());
+            if (pSdAnnotation && pSdAnnotation->hasCustomAnnotationMarker())
             {
-                CustomAnnotationMarker& rCustomAnnotationMarker = 
mxAnnotation->getCustomAnnotationMarker();
+                CustomAnnotationMarker& rCustomAnnotationMarker = 
pSdAnnotation->getCustomAnnotationMarker();
 
                 auto& rPolygons = rCustomAnnotationMarker.maPolygons;
                 if (!rPolygons.empty())
@@ -272,7 +273,7 @@ bool AnnotationHdl::IsFocusHdl() const
     return true;
 }
 
-AnnotationTag::AnnotationTag( AnnotationManagerImpl& rManager, ::sd::View& 
rView, const rtl::Reference< Annotation >& xAnnotation, Color const & rColor, 
int nIndex, const vcl::Font& rFont )
+AnnotationTag::AnnotationTag(AnnotationManagerImpl& rManager, ::sd::View& 
rView, rtl::Reference<sdr::annotation::Annotation> const& xAnnotation, Color 
const & rColor, int nIndex, const vcl::Font& rFont)
 : SmartTag( rView )
 , mrManager( rManager )
 , mxAnnotation( xAnnotation )
diff --git a/sd/source/ui/annotations/annotationtag.hxx 
b/sd/source/ui/annotations/annotationtag.hxx
index b5807a4b08d7..afe6d134a829 100644
--- a/sd/source/ui/annotations/annotationtag.hxx
+++ b/sd/source/ui/annotations/annotationtag.hxx
@@ -26,15 +26,16 @@
 
 namespace com::sun::star::office { class XAnnotation; }
 
-namespace sd {
-class Annotation;
+namespace sdr::annotation { class Annotation; }
+namespace sd
+{
 class View;
 class AnnotationManagerImpl;
 
 class AnnotationTag final : public SmartTag
 {
 public:
-    AnnotationTag( AnnotationManagerImpl& rManager, ::sd::View& rView, const 
rtl::Reference< Annotation >& xAnnotation, Color const & rColor, int nIndex, 
const vcl::Font& rFont );
+    AnnotationTag( AnnotationManagerImpl& rManager, ::sd::View& rView, 
rtl::Reference<sdr::annotation::Annotation> const& xAnnotation, Color const & 
rColor, int nIndex, const vcl::Font& rFont );
     virtual ~AnnotationTag() override;
 
     /// @return true if the SmartTag handled the event.
@@ -58,7 +59,7 @@ public:
 
     BitmapEx CreateAnnotationBitmap(bool);
 
-    const rtl::Reference< Annotation >& GetAnnotation() const { return 
mxAnnotation; }
+    rtl::Reference<sdr::annotation::Annotation> const& GetAnnotation() const { 
return mxAnnotation; }
 
     void OpenPopup( bool bEdit );
     void ClosePopup();
@@ -74,7 +75,7 @@ private:
     DECL_LINK(PopupModeEndHdl, weld::Popover&, void);
 
     AnnotationManagerImpl& mrManager;
-    rtl::Reference< Annotation >                    mxAnnotation;
+    rtl::Reference<sdr::annotation::Annotation> mxAnnotation;
     std::unique_ptr<AnnotationWindow>               mpAnnotationWindow;
     Color                                           maColor;
     int                                             mnIndex;
diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx
index bd97913ade5c..6ef7b4124abd 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -2552,9 +2552,8 @@ void SdXImpressDocument::getPostIts(::tools::JsonWriter& 
rJsonWriter)
     for (sal_uInt16 nPage = 0; nPage < nMaxPages; ++nPage)
     {
         pPage = static_cast<SdPage*>(mpDoc->GetPage(nPage));
-        const sd::AnnotationVector& aPageAnnotations = pPage->getAnnotations();
 
-        for (const rtl::Reference<Annotation>& xAnnotation : aPageAnnotations)
+        for (auto const& xAnnotation : pPage->getAnnotations())
         {
             sal_uInt32 nID = xAnnotation->GetId();
             OString nodeName = "comment" + OString::number(nID);
diff --git a/sd/source/ui/unoidl/unopage.cxx b/sd/source/ui/unoidl/unopage.cxx
index 1462e08e369e..d5d696721f6f 100644
--- a/sd/source/ui/unoidl/unopage.cxx
+++ b/sd/source/ui/unoidl/unopage.cxx
@@ -42,7 +42,7 @@
 #include <comphelper/diagnose_ex.hxx>
 #include <vcl/svapp.hxx>
 #include <Annotation.hxx>
-#include <AnnotationEnumeration.hxx>
+#include <svx/annotation/AnnotationEnumeration.hxx>
 #include <createunopageimpl.hxx>
 #include <unomodel.hxx>
 #include <unopage.hxx>
@@ -2524,7 +2524,7 @@ Reference< XAnnotation > SAL_CALL 
SdGenericDrawPage::createAndInsertAnnotation()
     if( !GetPage() )
         throw DisposedException();
 
-    rtl::Reference< sd::Annotation > xRet;
+    rtl::Reference<sdr::annotation::Annotation> xRet;
     GetPage()->createAnnotation(xRet);
     return xRet;
 }
@@ -2538,7 +2538,7 @@ void SAL_CALL SdGenericDrawPage::removeAnnotation(const 
Reference< XAnnotation >
 
 Reference< XAnnotationEnumeration > SAL_CALL 
SdGenericDrawPage::createAnnotationEnumeration()
 {
-    return ::sd::createAnnotationEnumeration( 
std::vector(GetPage()->getAnnotations()) );
+    return 
sdr::annotation::createAnnotationEnumeration(std::vector(GetPage()->getAnnotations()));
 }
 
 void SdDrawPage::getBackground(Any& rValue)
diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk
index e4630a1e0d56..33bca46f698d 100644
--- a/svx/Library_svxcore.mk
+++ b/svx/Library_svxcore.mk
@@ -106,6 +106,7 @@ endif
 
 $(eval $(call gb_Library_add_exception_objects,svxcore,\
     svx/source/annotation/Annotation \
+    svx/source/annotation/AnnotationEnumeration \
     svx/source/core/extedit \
     svx/source/core/graphichelper \
     svx/source/customshapes/EnhancedCustomShape2d \
diff --git a/svx/source/annotation/Annotation.cxx 
b/svx/source/annotation/Annotation.cxx
index afa8d0f525dd..7654d047f4a1 100644
--- a/svx/source/annotation/Annotation.cxx
+++ b/svx/source/annotation/Annotation.cxx
@@ -8,6 +8,7 @@
  */
 
 #include <svx/annotation/Annotation.hxx>
+#include <svx/svdpage.hxx>
 #include <tools/json_writer.hxx>
 #include <sfx2/viewsh.hxx>
 #include <unotools/datetime.hxx>
@@ -136,8 +137,28 @@ void AnnotationData::set(Annotation& rAnnotation)
     rAnnotation.SetText(m_Text);
 }
 
+Annotation::Annotation(const css::uno::Reference<css::uno::XComponentContext>& 
rxContext,
+                       SdrPage* pPage)
+    : cppu::WeakComponentImplHelper<office::XAnnotation>(m_aMutex)
+    , cppu::PropertySetMixin<office::XAnnotation>(rxContext, 
IMPLEMENTS_PROPERTY_SET,
+                                                  uno::Sequence<OUString>())
+    , mpPage(pPage)
+    , m_nId(nextID())
+{
+}
+
 sal_uInt32 Annotation::m_nLastId = 1;
 
+SdrModel* Annotation::GetModel() const
+{
+    return mpPage != nullptr ? &mpPage->getSdrModelFromSdrPage() : nullptr;
+}
+
+uno::Any Annotation::queryInterface(uno::Type const& type)
+{
+    return 
::cppu::WeakComponentImplHelper<office::XAnnotation>::queryInterface(type);
+}
+
 std::unique_ptr<SdrUndoAction> Annotation::createUndoAnnotation()
 {
     return std::make_unique<UndoAnnotation>(*this);
diff --git a/sd/source/core/annotations/AnnotationEnumeration.cxx 
b/svx/source/annotation/AnnotationEnumeration.cxx
similarity index 61%
rename from sd/source/core/annotations/AnnotationEnumeration.cxx
rename to svx/source/annotation/AnnotationEnumeration.cxx
index c622b10383bb..443a04f8c217 100644
--- a/sd/source/core/annotations/AnnotationEnumeration.cxx
+++ b/svx/source/annotation/AnnotationEnumeration.cxx
@@ -23,29 +23,25 @@
 #include <com/sun/star/container/NoSuchElementException.hpp>
 #include <com/sun/star/office/XAnnotationEnumeration.hpp>
 
-#include <Annotation.hxx>
-#include <AnnotationEnumeration.hxx>
-#include <sdpage.hxx>
+#include <svx/annotation/Annotation.hxx>
+#include <svx/annotation/AnnotationEnumeration.hxx>
 
-using namespace ::com::sun::star::uno;
-using namespace ::com::sun::star::office;
-using namespace ::com::sun::star::container;
-using namespace ::com::sun::star::lang;
+using namespace css;
 
-namespace sd {
-
-namespace {
-
-class AnnotationEnumeration: public ::cppu::WeakImplHelper< 
css::office::XAnnotationEnumeration >
+namespace sdr::annotation
+{
+namespace
+{
+class AnnotationEnumeration : public 
::cppu::WeakImplHelper<css::office::XAnnotationEnumeration>
 {
 public:
-    explicit AnnotationEnumeration( AnnotationVector&& rAnnotations );
+    explicit AnnotationEnumeration(AnnotationVector&& rAnnotations);
     AnnotationEnumeration(const AnnotationEnumeration&) = delete;
     AnnotationEnumeration& operator=(const AnnotationEnumeration&) = delete;
 
     // css::office::XAnnotationEnumeration:
     virtual sal_Bool SAL_CALL hasMoreElements() override;
-    virtual css::uno::Reference< css::office::XAnnotation > SAL_CALL 
nextElement() override;
+    virtual css::uno::Reference<css::office::XAnnotation> SAL_CALL 
nextElement() override;
 
 private:
     // destructor is private and will be called indirectly by the release call 
   virtual ~AnnotationEnumeration() {}
@@ -54,33 +50,31 @@ private:
     AnnotationVector::iterator maIter;
 };
 
-}
+} // end anonymous ns
 
-Reference< XAnnotationEnumeration > createAnnotationEnumeration( 
sd::AnnotationVector&& rAnnotations )
+uno::Reference<office::XAnnotationEnumeration>
+createAnnotationEnumeration(AnnotationVector&& rAnnotations)
 {
-    return new AnnotationEnumeration( std::move(rAnnotations) );
+    return new AnnotationEnumeration(std::move(rAnnotations));
 }
 
-AnnotationEnumeration::AnnotationEnumeration( AnnotationVector&& rAnnotations )
-: maAnnotations(std::move(rAnnotations))
+AnnotationEnumeration::AnnotationEnumeration(AnnotationVector&& rAnnotations)
+    : maAnnotations(std::move(rAnnotations))
 {
     maIter = maAnnotations.begin();
 }
 
 // css::office::XAnnotationEnumeration:
-sal_Bool SAL_CALL AnnotationEnumeration::hasMoreElements()
-{
-    return maIter != maAnnotations.end();
-}
+sal_Bool SAL_CALL AnnotationEnumeration::hasMoreElements() { return maIter != 
maAnnotations.end(); }
 
-css::uno::Reference< css::office::XAnnotation > SAL_CALL 
AnnotationEnumeration::nextElement()
+css::uno::Reference<css::office::XAnnotation> SAL_CALL 
AnnotationEnumeration::nextElement()
 {
-    if( maIter == maAnnotations.end() )
+    if (maIter == maAnnotations.end())
         throw css::container::NoSuchElementException();
 
     return (*maIter++);
 }
 
-} // namespace sd
+} // end sdr::annotation
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/svdraw/svdpage.cxx b/svx/source/svdraw/svdpage.cxx
index 49a3025759b5..c6e570fdaf6c 100644
--- a/svx/source/svdraw/svdpage.cxx
+++ b/svx/source/svdraw/svdpage.cxx
@@ -51,6 +51,7 @@
 #include <sdr/contact/viewcontactofsdrpage.hxx>
 #include <svx/sdr/contact/viewobjectcontact.hxx>
 #include <svx/sdr/contact/displayinfo.hxx>
+#include <svx/annotation/Annotation.hxx>
 #include <algorithm>
 #include <clonelist.hxx>
 #include <svl/hint.hxx>

Reply via email to