sd/inc/Annotation.hxx                          |   27 ++----
 sd/source/core/annotations/Annotation.cxx      |  100 ++++++++++---------------
 sd/source/ui/annotations/annotationmanager.cxx |   15 ++-
 sd/source/ui/unoidl/unomodel.cxx               |    2 
 4 files changed, 61 insertions(+), 83 deletions(-)

New commits:
commit db8b19a77ba0c115c1e0b0ad067ef433a3aa3a79
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Tue Apr 2 11:04:38 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Apr 2 13:04:21 2024 +0200

    use more concrete UNO types in sd
    
    Change-Id: Iea48c8750c940441c5687068317107a5932799e1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165670
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sd/inc/Annotation.hxx b/sd/inc/Annotation.hxx
index 12354e493ae4..965cbded3719 100644
--- a/sd/inc/Annotation.hxx
+++ b/sd/inc/Annotation.hxx
@@ -50,17 +50,13 @@ enum class CommentNotificationType { Add, Modify, Remove };
 
 void createAnnotation( rtl::Reference< Annotation >& xAnnotation, SdPage* 
pPage );
 
-std::unique_ptr<SdrUndoAction> CreateUndoInsertOrRemoveAnnotation( const 
css::uno::Reference< css::office::XAnnotation >& xAnnotation, bool bInsert );
-
-sal_uInt32 getAnnotationId(const css::uno::Reference 
<css::office::XAnnotation>& xAnnotation);
-
-const SdPage* getAnnotationPage(const 
css::uno::Reference<css::office::XAnnotation>& xAnnotation);
+std::unique_ptr<SdrUndoAction> CreateUndoInsertOrRemoveAnnotation( const 
rtl::Reference< sd::Annotation >& xAnnotation, bool bInsert );
 
 void LOKCommentNotify(CommentNotificationType nType, const SfxViewShell* 
pViewShell,
-        css::uno::Reference<css::office::XAnnotation> const & rxAnnotation);
+        rtl::Reference<sd::Annotation> const & rxAnnotation);
 
 void LOKCommentNotifyAll(CommentNotificationType nType,
-        css::uno::Reference<css::office::XAnnotation> const & rxAnnotation);
+        rtl::Reference<sd::Annotation> const & rxAnnotation);
 
 struct SD_DLLPUBLIC CustomAnnotationMarker
 {
diff --git a/sd/source/core/annotations/Annotation.cxx 
b/sd/source/core/annotations/Annotation.cxx
index 92bcbc28903d..fee7312bcca2 100644
--- a/sd/source/core/annotations/Annotation.cxx
+++ b/sd/source/core/annotations/Annotation.cxx
@@ -312,12 +312,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( const 
rtl::Reference<sd::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
     {
@@ -325,26 +324,9 @@ std::unique_ptr<SdrUndoAction> 
CreateUndoInsertOrRemoveAnnotation( const uno::Re
     }
 }
 
-sal_uInt32 getAnnotationId(const uno::Reference<office::XAnnotation>& 
xAnnotation)
-{
-    Annotation* pAnnotation = dynamic_cast<Annotation*>(xAnnotation.get());
-    sal_uInt32 nId = 0;
-    if (pAnnotation)
-        nId = pAnnotation->GetId();
-    return nId;
-}
-
-const SdPage* getAnnotationPage(const uno::Reference<office::XAnnotation>& 
xAnnotation)
-{
-    Annotation* pAnnotation = dynamic_cast<Annotation*>(xAnnotation.get());
-    if (pAnnotation)
-        return pAnnotation->GetPage();
-    return nullptr;
-}
-
 namespace
 {
-OString lcl_LOKGetCommentPayload(CommentNotificationType nType, 
uno::Reference<office::XAnnotation> const & rxAnnotation)
+OString lcl_LOKGetCommentPayload(CommentNotificationType nType, 
rtl::Reference<sd::Annotation> const & rxAnnotation)
 {
     ::tools::JsonWriter aJsonWriter;
     {
@@ -353,16 +335,16 @@ OString lcl_LOKGetCommentPayload(CommentNotificationType 
nType, uno::Reference<o
         aJsonWriter.put("action", (nType == CommentNotificationType::Add ? 
"Add" :
                                 (nType == CommentNotificationType::Remove ? 
"Remove" :
                                     (nType == CommentNotificationType::Modify 
? "Modify" : "???"))));
-        aJsonWriter.put("id", sd::getAnnotationId(rxAnnotation));
+        aJsonWriter.put("id", rxAnnotation->GetId());
 
         if (nType != CommentNotificationType::Remove && rxAnnotation.is())
         {
-            aJsonWriter.put("id", sd::getAnnotationId(rxAnnotation));
+            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 = sd::getAnnotationPage(rxAnnotation);
+            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();
@@ -377,7 +359,7 @@ OString lcl_LOKGetCommentPayload(CommentNotificationType 
nType, uno::Reference<o
 }
 } // anonymous ns
 
-void LOKCommentNotify(CommentNotificationType nType, const SfxViewShell* 
pViewShell, uno::Reference<office::XAnnotation> const & rxAnnotation)
+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())
@@ -387,7 +369,7 @@ void LOKCommentNotify(CommentNotificationType nType, const 
SfxViewShell* pViewSh
     pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_COMMENT, aPayload);
 }
 
-void LOKCommentNotifyAll(CommentNotificationType nType, 
uno::Reference<office::XAnnotation> const & rxAnnotation)
+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())
@@ -432,8 +414,7 @@ void UndoInsertOrRemoveAnnotation::Undo()
     else
     {
         pPage->addAnnotation( mxAnnotation, mnIndex );
-        uno::Reference<office::XAnnotation> xAnnotation( mxAnnotation );
-        LOKCommentNotifyAll( CommentNotificationType::Add, xAnnotation );
+        LOKCommentNotifyAll( CommentNotificationType::Add, mxAnnotation );
     }
 }
 
@@ -447,8 +428,7 @@ void UndoInsertOrRemoveAnnotation::Redo()
     if( mbInsert )
     {
         pPage->addAnnotation( mxAnnotation, mnIndex );
-        uno::Reference<office::XAnnotation> xAnnotation( mxAnnotation );
-        LOKCommentNotifyAll( CommentNotificationType::Add, xAnnotation );
+        LOKCommentNotifyAll( CommentNotificationType::Add, mxAnnotation );
     }
     else
     {
diff --git a/sd/source/ui/annotations/annotationmanager.cxx 
b/sd/source/ui/annotations/annotationmanager.cxx
index 04be49385849..ed16758d4baf 100644
--- a/sd/source/ui/annotations/annotationmanager.cxx
+++ b/sd/source/ui/annotations/annotationmanager.cxx
@@ -235,9 +235,9 @@ void SAL_CALL AnnotationManagerImpl::notifyEvent( const 
css::document::EventObje
     if ( aEvent.EventName == "OnAnnotationRemoved" )
     {
         Reference< XAnnotation > xAnnotation( aEvent.Source, uno::UNO_QUERY );
-        if ( xAnnotation.is() )
+        if ( auto pAnnotation = 
dynamic_cast<sd::Annotation*>(xAnnotation.get()) )
         {
-            LOKCommentNotify(CommentNotificationType::Remove, &mrBase, 
xAnnotation);
+            LOKCommentNotify(CommentNotificationType::Remove, &mrBase, 
pAnnotation);
         }
     }
 
@@ -258,8 +258,8 @@ rtl::Reference<Annotation> 
AnnotationManagerImpl::GetAnnotationById(sal_uInt32 n
         {
             AnnotationVector aAnnotations(pPage->getAnnotations());
             auto iter = std::find_if(aAnnotations.begin(), aAnnotations.end(),
-                [nAnnotationId](const Reference<XAnnotation>& xAnnotation) {
-                    return sd::getAnnotationId(xAnnotation) == nAnnotationId;
+                [nAnnotationId](const rtl::Reference<sd::Annotation>& 
xAnnotation) {
+                    return xAnnotation->GetId() == nAnnotationId;
                 });
             if (iter != aAnnotations.end())
                 return *iter;
diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx
index 8139ea4686e3..6dbc5bd57a25 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -2564,7 +2564,7 @@ void SdXImpressDocument::getPostIts(::tools::JsonWriter& 
rJsonWriter)
 
         for (const rtl::Reference<Annotation>& xAnnotation : aPageAnnotations)
         {
-            sal_uInt32 nID = sd::getAnnotationId(xAnnotation);
+            sal_uInt32 nID = xAnnotation->GetId();
             OString nodeName = "comment" + OString::number(nID);
             auto commentNode = rJsonWriter.startNode(nodeName);
             rJsonWriter.put("id", nID);
commit 354c9e03790f837cc2fa0d6b8474425612e182e6
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Tue Apr 2 10:50:20 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Apr 2 13:04:13 2024 +0200

    convert sd::Annotation to comphelper::WeakComponentImplHelper
    
    Change-Id: Icafd8d0e3cf1923fd287792cb03a5431907599e7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165669
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sd/inc/Annotation.hxx b/sd/inc/Annotation.hxx
index d272c5c4a9c4..12354e493ae4 100644
--- a/sd/inc/Annotation.hxx
+++ b/sd/inc/Annotation.hxx
@@ -24,8 +24,7 @@
 #include <memory>
 
 #include <com/sun/star/office/XAnnotation.hpp>
-#include <cppuhelper/basemutex.hxx>
-#include <cppuhelper/compbase.hxx>
+#include <comphelper/compbase.hxx>
 #include <cppuhelper/propertysetmixin.hxx>
 
 #include "sdpage.hxx"
@@ -53,8 +52,6 @@ void createAnnotation( rtl::Reference< Annotation >& 
xAnnotation, SdPage* pPage
 
 std::unique_ptr<SdrUndoAction> CreateUndoInsertOrRemoveAnnotation( const 
css::uno::Reference< css::office::XAnnotation >& xAnnotation, bool bInsert );
 
-void CreateChangeUndo(const css::uno::Reference< css::office::XAnnotation >& 
xAnnotation);
-
 sal_uInt32 getAnnotationId(const css::uno::Reference 
<css::office::XAnnotation>& xAnnotation);
 
 const SdPage* getAnnotationPage(const 
css::uno::Reference<css::office::XAnnotation>& xAnnotation);
@@ -73,8 +70,8 @@ struct SD_DLLPUBLIC CustomAnnotationMarker
     std::vector<basegfx::B2DPolygon> maPolygons;
 };
 
-class SAL_DLLPUBLIC_RTTI Annotation final : private ::cppu::BaseMutex,
-                   public 
::cppu::WeakComponentImplHelper<css::office::XAnnotation>,
+class SAL_DLLPUBLIC_RTTI Annotation final :
+                   public 
::comphelper::WeakComponentImplHelper<css::office::XAnnotation>,
                    public ::cppu::PropertySetMixin<css::office::XAnnotation>
 {
 public:
@@ -90,8 +87,8 @@ public:
 
     // 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(); }
+    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::beans::XPropertySet:
     virtual css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL 
getPropertySetInfo() override;
@@ -144,7 +141,9 @@ private:
     // This function is called upon disposing the component,
     // if your component needs special work when it becomes
     // disposed, do it here.
-    virtual void SAL_CALL disposing() override;
+    virtual void disposing(std::unique_lock<std::mutex>& rGuard) override;
+
+    void createChangeUndoImpl(std::unique_lock<std::mutex>& g);
 
     sal_uInt32 m_nId;
     SdPage* mpPage;
diff --git a/sd/source/core/annotations/Annotation.cxx 
b/sd/source/core/annotations/Annotation.cxx
index 597c357dd3ba..92bcbc28903d 100644
--- a/sd/source/core/annotations/Annotation.cxx
+++ b/sd/source/core/annotations/Annotation.cxx
@@ -118,8 +118,7 @@ void createAnnotation(rtl::Reference<Annotation>& 
xAnnotation, SdPage* pPage )
 sal_uInt32 Annotation::m_nLastId = 1;
 
 Annotation::Annotation(const uno::Reference<uno::XComponentContext>& context, 
SdPage* pPage)
-    : ::cppu::WeakComponentImplHelper<office::XAnnotation>(m_aMutex)
-    , ::cppu::PropertySetMixin<office::XAnnotation>(context, 
IMPLEMENTS_PROPERTY_SET,
+    : ::cppu::PropertySetMixin<office::XAnnotation>(context, 
IMPLEMENTS_PROPERTY_SET,
                                                     uno::Sequence<OUString>())
     , m_nId(m_nLastId++)
     , mpPage(pPage)
@@ -131,7 +130,7 @@ Annotation::Annotation(const 
uno::Reference<uno::XComponentContext>& context, Sd
 // This function is called upon disposing the component,
 // if your component needs special work when it becomes
 // disposed, do it here.
-void SAL_CALL Annotation::disposing()
+void Annotation::disposing(std::unique_lock<std::mutex>& /*rGuard*/)
 {
     mpPage = nullptr;
     if( m_TextRange.is() )
@@ -143,7 +142,7 @@ void SAL_CALL Annotation::disposing()
 
 uno::Any Annotation::queryInterface(css::uno::Type const & type)
 {
-    return 
::cppu::WeakComponentImplHelper<office::XAnnotation>::queryInterface(type);
+    return 
::comphelper::WeakComponentImplHelper<office::XAnnotation>::queryInterface(type);
 }
 
 // com.sun.star.beans.XPropertySet:
@@ -184,7 +183,7 @@ void SAL_CALL 
Annotation::removeVetoableChangeListener(const OUString & aPropert
 
 uno::Any SAL_CALL Annotation::getAnchor()
 {
-    osl::MutexGuard g(m_aMutex);
+    std::unique_lock g(m_aMutex);
     uno::Any aRet;
     if( mpPage )
     {
@@ -197,7 +196,7 @@ uno::Any SAL_CALL Annotation::getAnchor()
 // css::office::XAnnotation:
 geometry::RealPoint2D SAL_CALL Annotation::getPosition()
 {
-    osl::MutexGuard g(m_aMutex);
+    std::unique_lock g(m_aMutex);
     return m_Position;
 }
 
@@ -205,8 +204,8 @@ void SAL_CALL Annotation::setPosition(const 
geometry::RealPoint2D & the_value)
 {
     prepareSet("Position", uno::Any(), uno::Any(), nullptr);
     {
-        osl::MutexGuard g(m_aMutex);
-        createChangeUndo();
+        std::unique_lock g(m_aMutex);
+        createChangeUndoImpl(g);
         m_Position = the_value;
     }
 }
@@ -214,7 +213,7 @@ void SAL_CALL Annotation::setPosition(const 
geometry::RealPoint2D & the_value)
 // css::office::XAnnotation:
 geometry::RealSize2D SAL_CALL Annotation::getSize()
 {
-    osl::MutexGuard g(m_aMutex);
+    std::unique_lock g(m_aMutex);
     return m_Size;
 }
 
@@ -222,15 +221,15 @@ void SAL_CALL Annotation::setSize(const 
geometry::RealSize2D & the_value)
 {
     prepareSet("Size", uno::Any(), uno::Any(), nullptr);
     {
-        osl::MutexGuard g(m_aMutex);
-        createChangeUndo();
+        std::unique_lock g(m_aMutex);
+        createChangeUndoImpl(g);
         m_Size = the_value;
     }
 }
 
 OUString SAL_CALL Annotation::getAuthor()
 {
-    osl::MutexGuard g(m_aMutex);
+    std::unique_lock g(m_aMutex);
     return m_Author;
 }
 
@@ -238,15 +237,15 @@ void SAL_CALL Annotation::setAuthor(const OUString & 
the_value)
 {
     prepareSet("Author", uno::Any(), uno::Any(), nullptr);
     {
-        osl::MutexGuard g(m_aMutex);
-        createChangeUndo();
+        std::unique_lock g(m_aMutex);
+        createChangeUndoImpl(g);
         m_Author = the_value;
     }
 }
 
 OUString SAL_CALL Annotation::getInitials()
 {
-    osl::MutexGuard g(m_aMutex);
+    std::unique_lock g(m_aMutex);
     return m_Initials;
 }
 
@@ -254,15 +253,15 @@ void SAL_CALL Annotation::setInitials(const OUString & 
the_value)
 {
     prepareSet("Initials", uno::Any(), uno::Any(), nullptr);
     {
-        osl::MutexGuard g(m_aMutex);
-        createChangeUndo();
+        std::unique_lock g(m_aMutex);
+        createChangeUndoImpl(g);
         m_Initials = the_value;
     }
 }
 
 util::DateTime SAL_CALL Annotation::getDateTime()
 {
-    osl::MutexGuard g(m_aMutex);
+    std::unique_lock g(m_aMutex);
     return m_DateTime;
 }
 
@@ -270,17 +269,27 @@ void SAL_CALL Annotation::setDateTime(const 
util::DateTime & the_value)
 {
     prepareSet("DateTime", uno::Any(), uno::Any(), nullptr);
     {
-        osl::MutexGuard g(m_aMutex);
-        createChangeUndo();
+        std::unique_lock g(m_aMutex);
+        createChangeUndoImpl(g);
         m_DateTime = the_value;
     }
 }
 
 void Annotation::createChangeUndo()
+{
+    std::unique_lock g(m_aMutex);
+    createChangeUndoImpl(g);
+}
+
+void Annotation::createChangeUndoImpl(std::unique_lock<std::mutex>& g)
 {
     SdrModel* pModel = GetModel(); // TTTT should use reference
     if( pModel && pModel->IsUndoEnabled() )
+    {
+        g.unlock(); // AddUndo calls back into Annotation
         pModel->AddUndo( std::make_unique<UndoAnnotation>( *this ) );
+        g.lock();
+    }
 
     if( pModel )
     {
@@ -295,7 +304,7 @@ void Annotation::createChangeUndo()
 
 uno::Reference<text::XText> SAL_CALL Annotation::getTextRange()
 {
-    osl::MutexGuard g(m_aMutex);
+    std::unique_lock g(m_aMutex);
     if( !m_TextRange.is() && (mpPage != nullptr) )
     {
         m_TextRange = TextApiObject::create( static_cast< SdDrawDocument* >( 
&mpPage->getSdrModelFromSdrPage() ) );
@@ -316,13 +325,6 @@ std::unique_ptr<SdrUndoAction> 
CreateUndoInsertOrRemoveAnnotation( const uno::Re
     }
 }
 
-void CreateChangeUndo(const uno::Reference<office::XAnnotation>& xAnnotation)
-{
-    Annotation* pAnnotation = dynamic_cast<Annotation*>(xAnnotation.get());
-    if (pAnnotation)
-        pAnnotation->createChangeUndo();
-}
-
 sal_uInt32 getAnnotationId(const uno::Reference<office::XAnnotation>& 
xAnnotation)
 {
     Annotation* pAnnotation = dynamic_cast<Annotation*>(xAnnotation.get());
diff --git a/sd/source/ui/annotations/annotationmanager.cxx 
b/sd/source/ui/annotations/annotationmanager.cxx
index 0ab47a7b1a07..04be49385849 100644
--- a/sd/source/ui/annotations/annotationmanager.cxx
+++ b/sd/source/ui/annotations/annotationmanager.cxx
@@ -389,7 +389,7 @@ void 
AnnotationManagerImpl::ExecuteDeleteAnnotation(SfxRequest const & rReq)
 void AnnotationManagerImpl::ExecuteEditAnnotation(SfxRequest const & rReq)
 {
     const SfxItemSet* pArgs = rReq.GetArgs();
-    Reference< XAnnotation > xAnnotation;
+    rtl::Reference< Annotation > xAnnotation;
     OUString sText;
     sal_Int32 nPositionX = -1;
     sal_Int32 nPositionY = -1;
@@ -416,7 +416,7 @@ void 
AnnotationManagerImpl::ExecuteEditAnnotation(SfxRequest const & rReq)
 
     if (xAnnotation.is())
     {
-        CreateChangeUndo(xAnnotation);
+        xAnnotation->createChangeUndo();
 
         if (nPositionX >= 0 && nPositionY >= 0)
         {
@@ -570,7 +570,8 @@ void AnnotationManagerImpl::ExecuteReplyToAnnotation( 
SfxRequest const & rReq )
     if (mpDoc->IsUndoEnabled())
         mpDoc->BegUndo(SdResId(STR_ANNOTATION_REPLY));
 
-    CreateChangeUndo(xAnnotation);
+    if (xAnnotation)
+        xAnnotation->createChangeUndo();
     ::Outliner aOutliner( GetAnnotationPool(),OutlinerMode::TextObject );
 
     SdDrawDocument::SetCalcFieldValueHdl( &aOutliner );

Reply via email to