include/svx/annotation/Annotation.hxx              |   88 +++++++-
 include/svx/annotation/AnnotationEnumeration.hxx   |   11 -
 include/svx/svdpage.hxx                            |   13 +
 sd/Library_sd.mk                                   |    1 
 sd/inc/Annotation.hxx                              |   37 ---
 sd/inc/sdpage.hxx                                  |   12 -
 sd/source/core/annotations/Annotation.cxx          |  215 ++++-----------------
 sd/source/core/sdpage2.cxx                         |   50 ++--
 sd/source/filter/pdf/sdpdffilter.cxx               |    7 
 sd/source/ui/annotations/annotationmanager.cxx     |   88 ++++----
 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               |  150 ++++++++++++++
 svx/source/annotation/AnnotationEnumeration.cxx    |   46 +---
 svx/source/svdraw/svdpage.cxx                      |    1 
 19 files changed, 436 insertions(+), 347 deletions(-)

New commits:
commit a0a581ead18f030f59d203539706de0230746cae
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Fri Apr 19 15:34:06 2024 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Fri Apr 26 10:44:05 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>

diff --git a/include/svx/annotation/Annotation.hxx 
b/include/svx/annotation/Annotation.hxx
index 566dd6ef52f4..5ec5e2ec3c34 100644
--- a/include/svx/annotation/Annotation.hxx
+++ b/include/svx/annotation/Annotation.hxx
@@ -13,12 +13,17 @@
 #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 <comphelper/compbase.hxx>
+#include <cppuhelper/propertysetmixin.hxx>
+#include <svx/annotation/Annotation.hxx>
+
 class SdrUndoAction;
 class SfxViewShell;
+class SdrPage;
 
 namespace sdr::annotation
 {
@@ -49,13 +54,15 @@ struct SVXCORE_DLLPUBLIC AnnotationData
 };
 
 class SVXCORE_DLLPUBLIC Annotation
+    : public ::comphelper::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 +76,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
+    {
+        
::comphelper::WeakComponentImplHelper<css::office::XAnnotation>::acquire();
+    }
+    virtual void SAL_CALL release() noexcept override
     {
+        
::comphelper::WeakComponentImplHelper<css::office::XAnnotation>::release();
     }
 
     css::geometry::RealPoint2D GetPosition() const { return m_Position; }
@@ -93,11 +109,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 +120,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 2afc716e8949..c8c7eecddd5c 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;
@@ -421,6 +421,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
@@ -515,8 +518,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();
@@ -551,6 +554,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 9180714846d2..dc9b38f011f3 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 9ab11b0394f9..f19584525865 100644
--- a/sd/inc/Annotation.hxx
+++ b/sd/inc/Annotation.hxx
@@ -46,9 +46,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 
rtl::Reference< sd::Annotation >& xAnnotation, bool bInsert );
+std::unique_ptr<SdrUndoAction> 
CreateUndoInsertOrRemoveAnnotation(rtl::Reference<sdr::annotation::Annotation>& 
xAnnotation, bool bInsert);
 
 struct SD_DLLPUBLIC CustomAnnotationMarker
 {
@@ -58,22 +58,14 @@ struct SD_DLLPUBLIC CustomAnnotationMarker
     std::vector<basegfx::B2DPolygon> maPolygons;
 };
 
-class SAL_DLLPUBLIC_RTTI Annotation final :
-                    public sdr::annotation::Annotation,
-                    public 
::comphelper::WeakComponentImplHelper<css::office::XAnnotation>,
-                     public ::cppu::PropertySetMixin<css::office::XAnnotation>
+class SAL_DLLPUBLIC_RTTI 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 { 
::comphelper::WeakComponentImplHelper<css::office::XAnnotation>::acquire(); }
-    virtual void SAL_CALL release() noexcept override { 
::comphelper::WeakComponentImplHelper<css::office::XAnnotation>::release(); }
+    virtual ~Annotation();
 
     // css::beans::XPropertySet:
     virtual css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL 
getPropertySetInfo() override;
@@ -129,7 +121,6 @@ private:
 
     void createChangeUndoImpl(std::unique_lock<std::mutex>& g);
 
-    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 92075d53c7f5..8c3e76d6a95f 100644
--- a/sd/source/core/annotations/Annotation.cxx
+++ b/sd/source/core/annotations/Annotation.cxx
@@ -48,33 +48,33 @@ 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::PropertySetMixin<office::XAnnotation>(context, 
IMPLEMENTS_PROPERTY_SET, uno::Sequence<OUString>())
-    , mpPage(pPage)
+    : sdr::annotation::Annotation(context, pPage)
 {
 }
 
+Annotation::~Annotation()
+{}
+
 // override WeakComponentImplHelperBase::disposing()
 // This function is called upon disposing the component,
 // if your component needs special work when it becomes
@@ -89,11 +89,6 @@ void Annotation::disposing(std::unique_lock<std::mutex>& 
/*rGuard*/)
     }
 }
 
-uno::Any Annotation::queryInterface(css::uno::Type const & type)
-{
-    return 
::comphelper::WeakComponentImplHelper<office::XAnnotation>::queryInterface(type);
-}
-
 // com.sun.star.beans.XPropertySet:
 uno::Reference<beans::XPropertySetInfo> SAL_CALL 
Annotation::getPropertySetInfo()
 {
@@ -273,11 +268,11 @@ uno::Reference<text::XText> SAL_CALL 
Annotation::getTextRange()
     return m_TextRange;
 }
 
-std::unique_ptr<SdrUndoAction> CreateUndoInsertOrRemoveAnnotation( const 
rtl::Reference<sd::Annotation>& xAnnotation, bool bInsert )
+std::unique_ptr<SdrUndoAction> 
CreateUndoInsertOrRemoveAnnotation(rtl::Reference<sdr::annotation::Annotation>& 
xAnnotation, bool bInsert)
 {
-    if( xAnnotation )
+    if (xAnnotation)
     {
-        return std::make_unique< UndoInsertOrRemoveAnnotation >( *xAnnotation, 
bInsert );
+        return std::make_unique<UndoInsertOrRemoveAnnotation>(xAnnotation, 
bInsert);
     }
     else
     {
@@ -285,54 +280,53 @@ std::unique_ptr<SdrUndoAction> 
CreateUndoInsertOrRemoveAnnotation( const rtl::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 0e4840afc48d..74d3dd94334f 100644
--- a/sd/source/core/sdpage2.cxx
+++ b/sd/source/core/sdpage2.cxx
@@ -377,19 +377,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
@@ -552,16 +552,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
     {
@@ -570,8 +570,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) );
     }
 
@@ -583,18 +584,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 41f86dda60ee..622a1e5a2c10 100644
--- a/sd/source/ui/annotations/annotationmanager.cxx
+++ b/sd/source/ui/annotations/annotationmanager.cxx
@@ -242,7 +242,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
@@ -250,17 +250,18 @@ 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](const rtl::Reference<sd::Annotation>& 
xAnnotation) {
-                    return xAnnotation->GetId() == nAnnotationId;
+            sdr::annotation::AnnotationVector 
aAnnotations(pPage->getAnnotations());
+            auto iterator = std::find_if(aAnnotations.begin(), 
aAnnotations.end(),
+                [nAnnotationId](rtl::Reference<sdr::annotation::Annotation> 
const& 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;
 }
 
@@ -349,7 +350,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 )
             {
@@ -359,7 +360,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");
                     }
                 }
@@ -370,9 +371,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;
     }
@@ -383,7 +384,7 @@ void 
AnnotationManagerImpl::ExecuteDeleteAnnotation(SfxRequest const & rReq)
 void AnnotationManagerImpl::ExecuteEditAnnotation(SfxRequest const & rReq)
 {
     const SfxItemSet* pArgs = rReq.GetArgs();
-    rtl::Reference< Annotation > xAnnotation;
+    rtl::Reference<sdr::annotation::Annotation> xAnnotation;
     OUString sText;
     sal_Int32 nPositionX = -1;
     sal_Int32 nPositionY = -1;
@@ -410,7 +411,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)
         {
@@ -447,7 +449,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();
@@ -491,8 +493,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())
@@ -531,7 +533,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 )
@@ -565,7 +567,11 @@ void AnnotationManagerImpl::ExecuteReplyToAnnotation( 
SfxRequest const & rReq )
         mpDoc->BegUndo(SdResId(STR_ANNOTATION_REPLY));
 
     if (xAnnotation)
-        xAnnotation->createChangeUndo();
+    {
+        auto pSdAnnotation = static_cast<sd::Annotation*>(xAnnotation.get());
+        pSdAnnotation->createChangeUndo();
+    }
+
     ::Outliner aOutliner( GetAnnotationPool(),OutlinerMode::TextObject );
 
     SdDrawDocument::SetCalcFieldValueHdl( &aOutliner );
@@ -630,7 +636,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();
 
@@ -660,7 +666,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 )
                 {
@@ -689,8 +695,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 );
             }
@@ -718,8 +723,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
@@ -757,13 +762,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 )
     {
@@ -800,8 +805,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;
         }
     }
@@ -860,14 +866,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;
 
@@ -881,7 +887,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;
 }
@@ -969,13 +975,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;
             }
@@ -1044,7 +1050,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 8147cedef374..91cfcbbfbcfa 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>
@@ -159,22 +160,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()))
 {
 }
 
@@ -221,10 +222,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())
@@ -269,7 +270,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 52a52177a401..f5b3b2705250 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -2562,9 +2562,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 569116c96b61..aad9521b33f3 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>
@@ -2529,7 +2529,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;
 }
@@ -2543,7 +2543,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 1b1e6f5c2cf1..a3e0b3fb64a7 100644
--- a/svx/Library_svxcore.mk
+++ b/svx/Library_svxcore.mk
@@ -107,6 +107,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/core/extendedprimitive2dxmldump \
diff --git a/svx/source/annotation/Annotation.cxx 
b/svx/source/annotation/Annotation.cxx
index afa8d0f525dd..332573563df4 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,27 @@ void AnnotationData::set(Annotation& rAnnotation)
     rAnnotation.SetText(m_Text);
 }
 
+Annotation::Annotation(const css::uno::Reference<css::uno::XComponentContext>& 
rxContext,
+                       SdrPage* pPage)
+    : 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 
comphelper::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 7f3eaa85efa5..29636efca8fd 100644
--- a/svx/source/svdraw/svdpage.cxx
+++ b/svx/source/svdraw/svdpage.cxx
@@ -48,6 +48,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>
commit d126f57fd4bbba7ac0e4218ed30524cb9bbb5859
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Thu Apr 18 22:41:04 2024 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Fri Apr 26 10:43:56 2024 +0200

    annot: move UndoAnnotation and deps. to svx, adapt svx Annotation
    
    This moves UndoAnnotation and dependent classes to svx, refactor
    the code to in sdr::annotaion::Annotation so annotations in sd
    module still work as they have before.
    
    Change-Id: I3769069a636c30c55bc1fcf2406d990f1b44baa6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166493
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>
    Tested-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/include/svx/annotation/Annotation.hxx 
b/include/svx/annotation/Annotation.hxx
index 13881a58d070..566dd6ef52f4 100644
--- a/include/svx/annotation/Annotation.hxx
+++ b/include/svx/annotation/Annotation.hxx
@@ -14,10 +14,40 @@
 #include <com/sun/star/util/DateTime.hpp>
 
 #include <svx/svdpage.hxx>
+#include <svx/svdundo.hxx>
 #include <svx/svxdllapi.h>
 
+class SdrUndoAction;
+class SfxViewShell;
+
 namespace sdr::annotation
 {
+class Annotation;
+
+enum class CommentNotificationType
+{
+    Add,
+    Modify,
+    Remove
+};
+
+SVXCORE_DLLPUBLIC void LOKCommentNotify(CommentNotificationType nType,
+                                        const SfxViewShell* pViewShell, 
Annotation& rAnnotation);
+SVXCORE_DLLPUBLIC void LOKCommentNotifyAll(CommentNotificationType nType, 
Annotation& rAnnotation);
+
+struct SVXCORE_DLLPUBLIC AnnotationData
+{
+    css::geometry::RealPoint2D m_Position;
+    css::geometry::RealSize2D m_Size;
+    OUString m_Author;
+    OUString m_Initials;
+    css::util::DateTime m_DateTime;
+    OUString m_Text;
+
+    void get(Annotation& rAnnotation);
+    void set(Annotation& rAnnotation);
+};
+
 class SVXCORE_DLLPUBLIC Annotation
 {
 private:
@@ -33,8 +63,11 @@ protected:
     OUString m_Author;
     OUString m_Initials;
     css::util::DateTime m_DateTime;
+
     bool m_bIsFreeText = false;
 
+    std::unique_ptr<SdrUndoAction> createUndoAnnotation();
+
 public:
     Annotation(SdrPage* pPage)
         : mpSdrPage(pPage)
@@ -42,12 +75,35 @@ public:
     {
     }
 
+    css::geometry::RealPoint2D GetPosition() const { return m_Position; }
+    void SetPosition(const css::geometry::RealPoint2D& rValue) { m_Position = 
rValue; }
+
+    css::geometry::RealSize2D GetSize() const { return m_Size; }
+    void SetSize(const css::geometry::RealSize2D& rValue) { m_Size = rValue; }
+
+    OUString GetAuthor() const { return m_Author; }
+    void SetAuthor(const OUString& rValue) { m_Author = rValue; }
+
+    OUString GetInitials() const { return m_Initials; }
+    void SetInitials(const OUString& rValue) { m_Initials = rValue; }
+
+    css::util::DateTime GetDateTime() const { return m_DateTime; }
+    void SetDateTime(const css::util::DateTime& rValue) { m_DateTime = rValue; 
}
+
+    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; }
 
     sal_uInt32 GetId() const { return m_nId; }
+
+    void setIsFreeText(bool value) { m_bIsFreeText = value; }
+
+    bool isFreeText() const { return m_bIsFreeText; }
 };
 
 //typedef std::vector<rtl::Reference<Annotation>> AnnotationVector;
diff --git a/sd/inc/Annotation.hxx b/sd/inc/Annotation.hxx
index 558271dbc04e..9ab11b0394f9 100644
--- a/sd/inc/Annotation.hxx
+++ b/sd/inc/Annotation.hxx
@@ -37,28 +37,19 @@
 
 class SdrUndoAction;
 
-namespace com::sun::star::office {
-    class XAnnotation;
-}
+namespace com::sun::star::office { class XAnnotation; }
 
 namespace com::sun::star::uno { template <typename > class Reference; }
 
 class SfxViewShell;
 
-namespace sd {
-
-enum class CommentNotificationType { Add, Modify, Remove };
+namespace sd
+{
 
 void createAnnotation( rtl::Reference< Annotation >& xAnnotation, SdPage* 
pPage );
 
 std::unique_ptr<SdrUndoAction> CreateUndoInsertOrRemoveAnnotation( const 
rtl::Reference< sd::Annotation >& xAnnotation, bool bInsert );
 
-void LOKCommentNotify(CommentNotificationType nType, const SfxViewShell* 
pViewShell,
-        rtl::Reference<sd::Annotation> const & rxAnnotation);
-
-void LOKCommentNotifyAll(CommentNotificationType nType,
-        rtl::Reference<sd::Annotation> const & rxAnnotation);
-
 struct SD_DLLPUBLIC CustomAnnotationMarker
 {
     Color maLineColor;
@@ -124,9 +115,8 @@ public:
         return bool(m_pCustomAnnotationMarker);
     }
 
-    void setIsFreeText(bool value) { m_bIsFreeText = value; }
-
-    bool isFreeText() const { return m_bIsFreeText; }
+    OUString GetText() override;
+    void SetText(OUString const& rText) override;
 
 private:
     // destructor is private and will be called indirectly by the release call 
   virtual ~Annotation() {}
diff --git a/sd/source/core/annotations/Annotation.cxx 
b/sd/source/core/annotations/Annotation.cxx
index b3938002b87c..92075d53c7f5 100644
--- a/sd/source/core/annotations/Annotation.cxx
+++ b/sd/source/core/annotations/Annotation.cxx
@@ -36,7 +36,6 @@
 
 #include <notifydocumentevent.hxx>
 
-#include <tools/json_writer.hxx>
 
 using namespace css;
 
@@ -60,52 +59,6 @@ protected:
     int mnIndex;
 };
 
-struct AnnotationData
-{
-    geometry::RealPoint2D m_Position;
-    geometry::RealSize2D m_Size;
-    OUString m_Author;
-    OUString m_Initials;
-    util::DateTime m_DateTime;
-    OUString m_Text;
-
-    void get( const rtl::Reference< Annotation >& xAnnotation )
-    {
-        m_Position = xAnnotation->getPosition();
-        m_Size = xAnnotation->getSize();
-        m_Author = xAnnotation->getAuthor();
-        m_Initials = xAnnotation->getInitials();
-        m_DateTime = xAnnotation->getDateTime();
-        uno::Reference<text::XText> xText(xAnnotation->getTextRange());
-        m_Text = xText->getString();
-    }
-
-    void set( const rtl::Reference< Annotation >& xAnnotation )
-    {
-        xAnnotation->setPosition(m_Position);
-        xAnnotation->setSize(m_Size);
-        xAnnotation->setAuthor(m_Author);
-        xAnnotation->setInitials(m_Initials);
-        xAnnotation->setDateTime(m_DateTime);
-        uno::Reference<text::XText> xText(xAnnotation->getTextRange());
-        xText->setString(m_Text);
-    }
-};
-
-class UndoAnnotation : public SdrUndoAction
-{
-public:
-    explicit UndoAnnotation( Annotation& rAnnotation );
-
-    virtual void Undo() override;
-    virtual void Redo() override;
-
-protected:
-    rtl::Reference< Annotation > mxAnnotation;
-    AnnotationData maUndoData;
-    AnnotationData maRedoData;
-};
-
 }
 
 void createAnnotation(rtl::Reference<Annotation>& xAnnotation, SdPage* pPage )
@@ -271,6 +224,18 @@ void SAL_CALL Annotation::setDateTime(const util::DateTime 
& the_value)
     }
 }
 
+OUString Annotation::GetText()
+{
+    uno::Reference<text::XText> xText(getTextRange());
+    return xText->getString();
+}
+
+void Annotation::SetText(OUString const& rText)
+{
+    uno::Reference<text::XText> xText(getTextRange());
+    return xText->setString(rText);
+}
+
 void Annotation::createChangeUndo()
 {
     std::unique_lock g(m_aMutex);
@@ -283,7 +248,7 @@ void 
Annotation::createChangeUndoImpl(std::unique_lock<std::mutex>& g)
     if( pModel && pModel->IsUndoEnabled() )
     {
         g.unlock(); // AddUndo calls back into Annotation
-        pModel->AddUndo( std::make_unique<UndoAnnotation>( *this ) );
+        pModel->AddUndo(createUndoAnnotation());
         g.lock();
     }
 
@@ -320,67 +285,6 @@ std::unique_ptr<SdrUndoAction> 
CreateUndoInsertOrRemoveAnnotation( const rtl::Re
     }
 }
 
-namespace
-{
-OString lcl_LOKGetCommentPayload(CommentNotificationType nType, 
rtl::Reference<sd::Annotation> const & rxAnnotation)
-{
-    ::tools::JsonWriter aJsonWriter;
-    {
-        auto aCommentNode = aJsonWriter.startNode("comment");
-
-        aJsonWriter.put("action", (nType == CommentNotificationType::Add ? 
"Add" :
-                                (nType == CommentNotificationType::Remove ? 
"Remove" :
-                                    (nType == CommentNotificationType::Modify 
? "Modify" : "???"))));
-        aJsonWriter.put("id", rxAnnotation->GetId());
-
-        if (nType != CommentNotificationType::Remove && rxAnnotation.is())
-        {
-            aJsonWriter.put("id", rxAnnotation->GetId());
-            aJsonWriter.put("author", rxAnnotation->getAuthor());
-            aJsonWriter.put("dateTime", 
utl::toISO8601(rxAnnotation->getDateTime()));
-            uno::Reference<text::XText> xText(rxAnnotation->getTextRange());
-            aJsonWriter.put("text", xText->getString());
-            const SdPage* pPage = rxAnnotation->GetPage();
-            aJsonWriter.put("parthash", pPage ? 
OString::number(pPage->GetHashCode()) : OString());
-            geometry::RealPoint2D const & rPoint = rxAnnotation->getPosition();
-            geometry::RealSize2D const & rSize = rxAnnotation->getSize();
-            ::tools::Rectangle 
aRectangle(Point(std::round(o3tl::toTwips(rPoint.X, o3tl::Length::mm)),
-                                                
std::round(o3tl::toTwips(rPoint.Y, o3tl::Length::mm))),
-                                          
Size(std::round(o3tl::toTwips(rSize.Width, o3tl::Length::mm)),
-                                               
std::round(o3tl::toTwips(rSize.Height, o3tl::Length::mm))));
-            aJsonWriter.put("rectangle", aRectangle.toString());
-        }
-    }
-    return aJsonWriter.finishAndGetAsOString();
-}
-} // anonymous ns
-
-void LOKCommentNotify(CommentNotificationType nType, const SfxViewShell* 
pViewShell, rtl::Reference<sd::Annotation> const & rxAnnotation)
-{
-    // callbacks only if tiled annotations are explicitly turned off by LOK 
client
-    if (!comphelper::LibreOfficeKit::isActive() || 
comphelper::LibreOfficeKit::isTiledAnnotations())
-        return ;
-
-    OString aPayload = lcl_LOKGetCommentPayload(nType, rxAnnotation);
-    pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_COMMENT, aPayload);
-}
-
-void LOKCommentNotifyAll(CommentNotificationType nType, 
rtl::Reference<sd::Annotation> const & rxAnnotation)
-{
-    // callbacks only if tiled annotations are explicitly turned off by LOK 
client
-    if (!comphelper::LibreOfficeKit::isActive() || 
comphelper::LibreOfficeKit::isTiledAnnotations())
-        return ;
-
-    OString aPayload = lcl_LOKGetCommentPayload(nType, rxAnnotation);
-
-    const SfxViewShell* pViewShell = SfxViewShell::GetFirst();
-    while (pViewShell)
-    {
-        pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_COMMENT, aPayload);
-        pViewShell = SfxViewShell::GetNext(*pViewShell);
-    }
-}
-
 UndoInsertOrRemoveAnnotation::UndoInsertOrRemoveAnnotation( Annotation& 
rAnnotation, bool bInsert )
 : SdrUndoAction( *rAnnotation.GetModel() )
 , mxAnnotation( &rAnnotation )
@@ -410,7 +314,7 @@ void UndoInsertOrRemoveAnnotation::Undo()
     else
     {
         pPage->addAnnotation( mxAnnotation, mnIndex );
-        LOKCommentNotifyAll( CommentNotificationType::Add, mxAnnotation );
+        LOKCommentNotifyAll(sdr::annotation::CommentNotificationType::Add, 
*mxAnnotation);
     }
 }
 
@@ -424,7 +328,7 @@ void UndoInsertOrRemoveAnnotation::Redo()
     if( mbInsert )
     {
         pPage->addAnnotation( mxAnnotation, mnIndex );
-        LOKCommentNotifyAll( CommentNotificationType::Add, mxAnnotation );
+        LOKCommentNotifyAll(sdr::annotation::CommentNotificationType::Add, 
*mxAnnotation);
     }
     else
     {
@@ -432,27 +336,6 @@ void UndoInsertOrRemoveAnnotation::Redo()
     }
 }
 
-UndoAnnotation::UndoAnnotation( Annotation& rAnnotation )
-: SdrUndoAction( *rAnnotation.GetModel() )
-, mxAnnotation( &rAnnotation )
-{
-    maUndoData.get( mxAnnotation );
-}
-
-void UndoAnnotation::Undo()
-{
-    maRedoData.get( mxAnnotation );
-    maUndoData.set( mxAnnotation );
-    LOKCommentNotifyAll( CommentNotificationType::Modify, mxAnnotation );
-}
-
-void UndoAnnotation::Redo()
-{
-    maUndoData.get( mxAnnotation );
-    maRedoData.set( mxAnnotation );
-    LOKCommentNotifyAll( CommentNotificationType::Modify, mxAnnotation );
-}
-
 } // namespace sd
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/source/ui/annotations/annotationmanager.cxx 
b/sd/source/ui/annotations/annotationmanager.cxx
index 8a844e8dc118..41f86dda60ee 100644
--- a/sd/source/ui/annotations/annotationmanager.cxx
+++ b/sd/source/ui/annotations/annotationmanager.cxx
@@ -231,7 +231,7 @@ void SAL_CALL AnnotationManagerImpl::notifyEvent( const 
css::document::EventObje
         Reference< XAnnotation > xAnnotation( aEvent.Source, uno::UNO_QUERY );
         if ( auto pAnnotation = 
dynamic_cast<sd::Annotation*>(xAnnotation.get()) )
         {
-            LOKCommentNotify(CommentNotificationType::Remove, &mrBase, 
pAnnotation);
+            LOKCommentNotify(sdr::annotation::CommentNotificationType::Remove, 
&mrBase, *pAnnotation);
         }
     }
 
@@ -426,7 +426,7 @@ void 
AnnotationManagerImpl::ExecuteEditAnnotation(SfxRequest const & rReq)
             xText->setString(sText);
         }
 
-        LOKCommentNotifyAll(CommentNotificationType::Modify, xAnnotation);
+        LOKCommentNotifyAll(sdr::annotation::CommentNotificationType::Modify, 
*xAnnotation);
     }
 
     if (mpDoc->IsUndoEnabled())
@@ -523,7 +523,7 @@ void AnnotationManagerImpl::InsertAnnotation(const 
OUString& rText)
         mpDoc->EndUndo();
 
     // Tell our LOK clients about new comment added
-    LOKCommentNotifyAll(CommentNotificationType::Add, xAnnotation);
+    LOKCommentNotifyAll(sdr::annotation::CommentNotificationType::Add, 
*xAnnotation);
 
     UpdateTags(true);
     SelectAnnotation( xAnnotation, true );
@@ -621,7 +621,7 @@ void AnnotationManagerImpl::ExecuteReplyToAnnotation( 
SfxRequest const & rReq )
     xAnnotation->setDateTime( getCurrentDateTime() );
 
     // Tell our LOK clients about this (comment modification)
-    LOKCommentNotifyAll(CommentNotificationType::Modify, xAnnotation);
+    LOKCommentNotifyAll(sdr::annotation::CommentNotificationType::Modify, 
*xAnnotation);
 
     if( mpDoc->IsUndoEnabled() )
         mpDoc->EndUndo();
diff --git a/svx/source/annotation/Annotation.cxx 
b/svx/source/annotation/Annotation.cxx
index df6e2175cef6..afa8d0f525dd 100644
--- a/svx/source/annotation/Annotation.cxx
+++ b/svx/source/annotation/Annotation.cxx
@@ -8,11 +8,141 @@
  */
 
 #include <svx/annotation/Annotation.hxx>
+#include <tools/json_writer.hxx>
+#include <sfx2/viewsh.hxx>
+#include <unotools/datetime.hxx>
+#include <comphelper/lok.hxx>
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
+
+using namespace css;
 
 namespace sdr::annotation
 {
+namespace
+{
+OString lcl_LOKGetCommentPayload(CommentNotificationType nType, Annotation& 
rAnnotation)
+{
+    tools::JsonWriter aJsonWriter;
+    {
+        auto aCommentNode = aJsonWriter.startNode("comment");
+
+        aJsonWriter.put(
+            "action",
+            (nType == CommentNotificationType::Add
+                 ? "Add"
+                 : (nType == CommentNotificationType::Remove
+                        ? "Remove"
+                        : (nType == CommentNotificationType::Modify ? "Modify" 
: "???"))));
+        aJsonWriter.put("id", rAnnotation.GetId());
+
+        if (nType != CommentNotificationType::Remove)
+        {
+            aJsonWriter.put("id", rAnnotation.GetId());
+            aJsonWriter.put("author", rAnnotation.GetAuthor());
+            aJsonWriter.put("dateTime", 
utl::toISO8601(rAnnotation.GetDateTime()));
+            aJsonWriter.put("text", rAnnotation.GetText());
+            SdrPage const* pPage = rAnnotation.getPage();
+            sal_Int64 nHash = 
sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(pPage));
+            aJsonWriter.put("parthash", pPage ? OString::number(nHash) : 
OString());
+            geometry::RealPoint2D const& rPoint = rAnnotation.GetPosition();
+            geometry::RealSize2D const& rSize = rAnnotation.GetSize();
+            tools::Rectangle aRectangle(
+                Point(std::round(o3tl::toTwips(rPoint.X, o3tl::Length::mm)),
+                      std::round(o3tl::toTwips(rPoint.Y, o3tl::Length::mm))),
+                Size(std::round(o3tl::toTwips(rSize.Width, o3tl::Length::mm)),
+                     std::round(o3tl::toTwips(rSize.Height, 
o3tl::Length::mm))));
+            aJsonWriter.put("rectangle", aRectangle.toString());
+        }
+    }
+    return aJsonWriter.finishAndGetAsOString();
+}
+
+class UndoAnnotation : public SdrUndoAction
+{
+public:
+    explicit UndoAnnotation(Annotation& rAnnotation)
+        : SdrUndoAction(*rAnnotation.GetModel())
+        , mrAnnotation(rAnnotation)
+    {
+        maUndoData.get(mrAnnotation);
+    }
+
+    void Undo() override
+    {
+        maRedoData.get(mrAnnotation);
+        maUndoData.set(mrAnnotation);
+        LOKCommentNotifyAll(CommentNotificationType::Modify, mrAnnotation);
+    }
+
+    void Redo() override
+    {
+        maUndoData.get(mrAnnotation);
+        maRedoData.set(mrAnnotation);
+        LOKCommentNotifyAll(CommentNotificationType::Modify, mrAnnotation);
+    }
+
+protected:
+    Annotation& mrAnnotation;
+    AnnotationData maUndoData;
+    AnnotationData maRedoData;
+};
+
+} // anonymous ns
+
+void LOKCommentNotify(CommentNotificationType nType, const SfxViewShell* 
pViewShell,
+                      Annotation& rAnnotation)
+{
+    // callbacks only if tiled annotations are explicitly turned off by LOK 
client
+    if (!comphelper::LibreOfficeKit::isActive() || 
comphelper::LibreOfficeKit::isTiledAnnotations())
+        return;
+
+    OString aPayload = lcl_LOKGetCommentPayload(nType, rAnnotation);
+    pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_COMMENT, aPayload);
+}
+
+void LOKCommentNotifyAll(CommentNotificationType nType, Annotation& 
rAnnotation)
+{
+    // callbacks only if tiled annotations are explicitly turned off by LOK 
client
+    if (!comphelper::LibreOfficeKit::isActive() || 
comphelper::LibreOfficeKit::isTiledAnnotations())
+        return;
+
+    OString aPayload = lcl_LOKGetCommentPayload(nType, rAnnotation);
+
+    const SfxViewShell* pViewShell = SfxViewShell::GetFirst();
+    while (pViewShell)
+    {
+        pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_COMMENT, aPayload);
+        pViewShell = SfxViewShell::GetNext(*pViewShell);
+    }
+}
+
+void AnnotationData::get(Annotation& rAnnotation)
+{
+    m_Position = rAnnotation.GetPosition();
+    m_Size = rAnnotation.GetSize();
+    m_Author = rAnnotation.GetAuthor();
+    m_Initials = rAnnotation.GetInitials();
+    m_DateTime = rAnnotation.GetDateTime();
+    m_Text = rAnnotation.GetText();
+}
+
+void AnnotationData::set(Annotation& rAnnotation)
+{
+    rAnnotation.SetPosition(m_Position);
+    rAnnotation.SetSize(m_Size);
+    rAnnotation.SetAuthor(m_Author);
+    rAnnotation.SetInitials(m_Initials);
+    rAnnotation.SetDateTime(m_DateTime);
+    rAnnotation.SetText(m_Text);
+}
+
 sal_uInt32 Annotation::m_nLastId = 1;
 
+std::unique_ptr<SdrUndoAction> Annotation::createUndoAnnotation()
+{
+    return std::make_unique<UndoAnnotation>(*this);
+}
+
 } // namespace sdr::annotation
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to