include/svx/annotation/Annotation.hxx          |    2 +
 sd/source/ui/annotations/annotationmanager.cxx |   32 ++++++++--------------
 sd/source/ui/annotations/annotationwindow.cxx  |   36 +++++++++++++++++++------
 sd/source/ui/annotations/annotationwindow.hxx  |   11 ++++---
 svx/source/annotation/Annotation.cxx           |   15 ++++++++++
 5 files changed, 63 insertions(+), 33 deletions(-)

New commits:
commit 4fbb4242d924c0a7a43a10c4ecd4a33f8b339310
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Mon Jun 17 14:39:34 2024 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Mon Jun 17 10:24:21 2024 +0200

    annot: update object text when annotation text changes
    
    When the annotation text changes we need to sync this with the SDR
    object (if the object is showing the annotation text - like free
    text annotation).
    
    Also move annotation object searching to the annotation class, so
    it can be reused in AnnotationWindow.
    
    Also change uso of UNO XAnnotation in AnnotationWindow and use
    concrete type (sdr::annotation::Anootation) instead.
    
    Change-Id: I46db479ae8471c82ac58487a0125df15697245be
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168977
    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 f7917b608e9c..693666bb045e 100644
--- a/include/svx/annotation/Annotation.hxx
+++ b/include/svx/annotation/Annotation.hxx
@@ -174,6 +174,8 @@ public:
 
     CreationInfo const& getCreationInfo() { return maCreationInfo; }
     void setCreationInfo(CreationInfo const& rCreationInfo) { maCreationInfo = 
rCreationInfo; }
+
+    SdrObject* findAnnotationObject();
 };
 
 /** Vector of annotations */
diff --git a/sd/source/ui/annotations/annotationmanager.cxx 
b/sd/source/ui/annotations/annotationmanager.cxx
index a6918f9e15d8..ec6f0a14d6c6 100644
--- a/sd/source/ui/annotations/annotationmanager.cxx
+++ b/sd/source/ui/annotations/annotationmanager.cxx
@@ -167,24 +167,6 @@ OUString getAnnotationDateTimeString(const 
uno::Reference<office::XAnnotation>&
     return sRet;
 }
 
-namespace
-{
-
-SdrObject* 
findAnnotationObjectMatching(rtl::Reference<sdr::annotation::Annotation> const& 
xAnnotation)
-{
-    SdrPage const* pPage = xAnnotation->getPage();
-
-    for (size_t i = 0; i < pPage->GetObjCount(); ++i)
-    {
-        SdrObject* pObject = pPage->GetObj(i);
-        if (pObject->isAnnotationObject() && 
pObject->getAnnotationData()->mxAnnotation == xAnnotation)
-            return pObject;
-    }
-    return nullptr;
-}
-
-} // end anonymous ns
-
 AnnotationManagerImpl::AnnotationManagerImpl( ViewShellBase& rViewShellBase )
 : mrBase( rViewShellBase )
 , mpDoc( rViewShellBase.GetDocument() )
@@ -443,7 +425,7 @@ void 
AnnotationManagerImpl::ExecuteEditAnnotation(SfxRequest const & rReq)
         auto pSdAnnotation = static_cast<sd::Annotation*>(xAnnotation.get());
         pSdAnnotation->createChangeUndo();
 
-        SdrObject* pObject = findAnnotationObjectMatching(xAnnotation);
+        SdrObject* pObject = xAnnotation->findAnnotationObject();
         if (pObject && nPositionX >= 0 && nPositionY >= 0)
         {
             double fX = convertTwipToMm100(nPositionX);
@@ -1007,7 +989,7 @@ void AnnotationManagerImpl::SyncAnnotationObjects()
     bool bAnnotatonInserted = false;
     for (auto const& xAnnotation : mxCurrentPage->getAnnotations())
     {
-        SdrObject* pObject = findAnnotationObjectMatching(xAnnotation);
+        SdrObject* pObject = xAnnotation->findAnnotationObject();
 
         if (pObject)
             continue;
diff --git a/sd/source/ui/annotations/annotationwindow.cxx 
b/sd/source/ui/annotations/annotationwindow.cxx
index b3d8778fe780..1430e2875e28 100644
--- a/sd/source/ui/annotations/annotationwindow.cxx
+++ b/sd/source/ui/annotations/annotationwindow.cxx
@@ -57,6 +57,9 @@
 #include <ViewShell.hxx>
 #include <drawdoc.hxx>
 #include <svx/annotation/TextAPI.hxx>
+#include <svx/annotation/Annotation.hxx>
+#include <svx/annotation/ObjectAnnotationData.hxx>
+#include <svx/svdorect.hxx>
 #include <sdresid.hxx>
 
 #include <memory>
@@ -207,7 +210,7 @@ void 
AnnotationTextWindow::SetDrawingArea(weld::DrawingArea* pDrawingArea)
 // see SwAnnotationWin in sw for something similar
 AnnotationWindow::AnnotationWindow(weld::Window* pParent, const 
::tools::Rectangle& rRect,
                                    DrawDocShell* pDocShell,
-                                   const uno::Reference<office::XAnnotation>& 
xAnnotation)
+                                   rtl::Reference<sdr::annotation::Annotation> 
const& xAnnotation)
     : mxBuilder(Application::CreateBuilder(pParent, 
u"modules/simpress/ui/annotation.ui"_ustr))
     , mxPopover(mxBuilder->weld_popover(u"Annotation"_ustr))
     , mxContainer(mxBuilder->weld_widget(u"container"_ustr))
@@ -300,15 +303,18 @@ IMPL_LINK(AnnotationWindow, MenuItemSelectedHdl, const 
OUString&, rIdent, void)
     if (!pDispatcher)
         return;
 
+    uno::Reference<office::XAnnotation> xUnoAnnotation(mxAnnotation);
+
     if (rIdent == ".uno:ReplyToAnnotation")
     {
-        const SfxUnoAnyItem aItem(SID_REPLYTO_POSTIT, uno::Any(mxAnnotation));
+
+        const SfxUnoAnyItem aItem(SID_REPLYTO_POSTIT, 
uno::Any(xUnoAnnotation));
         pDispatcher->ExecuteList(SID_REPLYTO_POSTIT,
                 SfxCallMode::ASYNCHRON, { &aItem });
     }
     else if (rIdent == ".uno:DeleteAnnotation")
     {
-        const SfxUnoAnyItem aItem(SID_DELETE_POSTIT, uno::Any(mxAnnotation));
+        const SfxUnoAnyItem aItem(SID_DELETE_POSTIT, uno::Any(xUnoAnnotation));
         pDispatcher->ExecuteList(SID_DELETE_POSTIT, SfxCallMode::ASYNCHRON,
                 { &aItem });
     }
@@ -489,9 +495,9 @@ sdr::annotation::TextApiObject* getTextApiObject(const 
uno::Reference<office::XA
     return nullptr;
 }
 
-void AnnotationWindow::setAnnotation(const 
uno::Reference<office::XAnnotation>& xAnnotation)
+void 
AnnotationWindow::setAnnotation(rtl::Reference<sdr::annotation::Annotation> 
const& xAnnotation)
 {
-    if( (xAnnotation == mxAnnotation) || !xAnnotation.is() )
+    if (xAnnotation == mxAnnotation || !xAnnotation.is())
         return;
 
     mxAnnotation = xAnnotation;
@@ -502,7 +508,7 @@ void AnnotationWindow::setAnnotation(const 
uno::Reference<office::XAnnotation>&
     mbProtected = aUserOptions.GetFullName() != xAnnotation->getAuthor();
 
     mpOutliner->Clear();
-    auto* pTextApi = getTextApiObject( mxAnnotation );
+    auto* pTextApi = getTextApiObject(mxAnnotation);
 
     if( pTextApi )
     {
@@ -609,6 +615,18 @@ void AnnotationWindow::SaveToDocument()
                 // set current time to changed annotation
                 xAnnotation->setDateTime( getCurrentDateTime() );
 
+                rtl::Reference<sdr::annotation::Annotation> xSdrAnnotation = 
dynamic_cast<sdr::annotation::Annotation*>(xAnnotation.get());
+                if (xSdrAnnotation && xSdrAnnotation->getCreationInfo().meType 
== sdr::annotation::AnnotationType::FreeText)
+                {
+                    SdrObject* pObject = 
xSdrAnnotation->findAnnotationObject();
+                    SdrRectObj* pRectangleObject = pObject ? 
dynamic_cast<SdrRectObj*>(pObject) : nullptr;
+                    if (pRectangleObject)
+                    {
+                        OUString aString = 
xSdrAnnotation->getTextRange()->getString();
+                        pRectangleObject->SetText(aString);
+                    }
+                }
+
                 if( mpDoc->IsUndoEnabled() )
                     mpDoc->EndUndo();
 
@@ -754,15 +772,17 @@ bool AnnotationTextWindow::Command(const CommandEvent& 
rCEvt)
 
         auto sId = xMenu->popup_at_rect(pPopupParent, aRect);
 
+        uno::Reference<office::XAnnotation> 
xUnoAnnotation(mrContents.getAnnotation());
+
         if (sId == ".uno:ReplyToAnnotation")
         {
-            const SfxUnoAnyItem aItem(SID_REPLYTO_POSTIT, 
uno::Any(xAnnotation));
+            const SfxUnoAnyItem aItem(SID_REPLYTO_POSTIT, 
uno::Any(xUnoAnnotation));
             pDispatcher->ExecuteList(SID_REPLYTO_POSTIT,
                     SfxCallMode::ASYNCHRON, { &aItem });
         }
         else if (sId == ".uno:DeleteAnnotation")
         {
-            const SfxUnoAnyItem aItem(SID_DELETE_POSTIT, 
uno::Any(xAnnotation));
+            const SfxUnoAnyItem aItem(SID_DELETE_POSTIT, 
uno::Any(xUnoAnnotation));
             pDispatcher->ExecuteList(SID_DELETE_POSTIT, SfxCallMode::ASYNCHRON,
                     { &aItem });
         }
diff --git a/sd/source/ui/annotations/annotationwindow.hxx 
b/sd/source/ui/annotations/annotationwindow.hxx
index fd5919b40d06..31f82348b371 100644
--- a/sd/source/ui/annotations/annotationwindow.hxx
+++ b/sd/source/ui/annotations/annotationwindow.hxx
@@ -22,13 +22,14 @@
 #include <vcl/weld.hxx>
 #include <tools/long.hxx>
 #include <svx/weldeditview.hxx>
+#include <svx/annotation/Annotation.hxx>
 
-namespace com::sun::star::office { class XAnnotation; }
 
 class OutlinerView;
 class Outliner;
 class SvxLanguageItem;
 class SdDrawDocument;
+
 namespace sdr::annotation { class TextApiObject; }
 
 namespace sd
@@ -72,7 +73,7 @@ private:
     bool mbReadonly;
     bool mbProtected;
 
-    css::uno::Reference< css::office::XAnnotation > mxAnnotation;
+    rtl::Reference<sdr::annotation::Annotation> mxAnnotation;
 
 public:
     Color maColor;
@@ -98,12 +99,12 @@ private:
     void InitControls();
 
     void SetMapMode(const MapMode& rNewMapMode);
-    void setAnnotation(const css::uno::Reference<css::office::XAnnotation>& 
xAnnotation);
+    void setAnnotation(rtl::Reference<sdr::annotation::Annotation> const& 
xAnnotation);
 
     static sal_Int32 GetPrefScrollbarWidth() { return 16; }
 public:
     AnnotationWindow(weld::Window* pParent, const ::tools::Rectangle& rRect, 
DrawDocShell* pDocShell,
-                     const css::uno::Reference<css::office::XAnnotation>& 
xAnnotation);
+                     const rtl::Reference<sdr::annotation::Annotation>& 
xAnnotation);
 
     void connect_closed(const Link<weld::Popover&, void>& rLink) { 
mxPopover->connect_closed(rLink); }
 
@@ -112,7 +113,7 @@ public:
     void SetScrollbar();
     void StartEdit();
 
-    const css::uno::Reference<css::office::XAnnotation>& getAnnotation() const 
{ return mxAnnotation; }
+    const rtl::Reference<sdr::annotation::Annotation>& getAnnotation() const { 
return mxAnnotation; }
 
     void SaveToDocument();
 
diff --git a/svx/source/annotation/Annotation.cxx 
b/svx/source/annotation/Annotation.cxx
index 293e4328a9e7..e27449db2b9e 100644
--- a/svx/source/annotation/Annotation.cxx
+++ b/svx/source/annotation/Annotation.cxx
@@ -8,6 +8,7 @@
  */
 
 #include <svx/annotation/Annotation.hxx>
+#include <svx/annotation/ObjectAnnotationData.hxx>
 #include <svx/svdpage.hxx>
 #include <tools/json_writer.hxx>
 #include <sfx2/viewsh.hxx>
@@ -196,6 +197,20 @@ void Annotation::disposing(std::unique_lock<std::mutex>& 
/*rGuard*/)
     }
 }
 
+SdrObject* Annotation::findAnnotationObject()
+{
+    SdrPage const* pPage = getPage();
+
+    for (size_t i = 0; i < pPage->GetObjCount(); ++i)
+    {
+        SdrObject* pObject = pPage->GetObj(i);
+        if (pObject->isAnnotationObject()
+            && pObject->getAnnotationData()->mxAnnotation.get() == this)
+            return pObject;
+    }
+    return nullptr;
+}
+
 } // namespace sdr::annotation
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 23052214e026745fc5d8e780b91630e1f8dea205
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Mon Jun 17 14:31:20 2024 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Mon Jun 17 10:24:11 2024 +0200

    annot: add undo to annotations inserter when synching
    
    Change-Id: If4b8ddcbee9468655944effb931347c8077abc3c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168976
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/sd/source/ui/annotations/annotationmanager.cxx 
b/sd/source/ui/annotations/annotationmanager.cxx
index 296a6f5a3ac2..a6918f9e15d8 100644
--- a/sd/source/ui/annotations/annotationmanager.cxx
+++ b/sd/source/ui/annotations/annotationmanager.cxx
@@ -73,6 +73,7 @@
 #include <drawdoc.hxx>
 #include <svx/annotation/TextAPI.hxx>
 #include <svx/annotation/AnnotationObject.hxx>
+#include <svx/annotation/Annotation.hxx>
 #include <svx/annotation/ObjectAnnotationData.hxx>
 #include <optsitem.hxx>
 #include <sdmod.hxx>
@@ -1003,6 +1004,7 @@ void AnnotationManagerImpl::SyncAnnotationObjects()
         return;
 
     sal_Int32 nIndex = 1;
+    bool bAnnotatonInserted = false;
     for (auto const& xAnnotation : mxCurrentPage->getAnnotations())
     {
         SdrObject* pObject = findAnnotationObjectMatching(xAnnotation);
@@ -1010,6 +1012,11 @@ void AnnotationManagerImpl::SyncAnnotationObjects()
         if (pObject)
             continue;
 
+        if (!bAnnotatonInserted && mpDoc->IsUndoEnabled())
+            mpDoc->BegUndo(SdResId(STR_ANNOTATION_UNDO_INSERT));
+
+        bAnnotatonInserted = true;
+
         auto const& rInfo = xAnnotation->getCreationInfo();
 
         auto* pView = xViewShell->GetView();
@@ -1112,6 +1119,9 @@ void AnnotationManagerImpl::SyncAnnotationObjects()
 
         nIndex++;
     }
+
+    if (bAnnotatonInserted && mpDoc->IsUndoEnabled())
+        mpDoc->EndUndo();
 }
 
 void AnnotationManagerImpl::addListener()

Reply via email to