sw/inc/AnnotationWin.hxx                  |    5 +++++
 sw/inc/PostItMgr.hxx                      |    2 ++
 sw/inc/postithelper.hxx                   |    5 +++++
 sw/source/uibase/docvw/AnnotationWin.cxx  |   21 +++++++++++++++++++++
 sw/source/uibase/docvw/AnnotationWin2.cxx |    8 ++++++++
 sw/source/uibase/docvw/PostItMgr.cxx      |    5 +++++
 6 files changed, 46 insertions(+)

New commits:
commit 8fe61323cc338370c4fd67f8c88aedd8ef8d6b3b
Author:     Paris Oplopoios <paris.oplopo...@collabora.com>
AuthorDate: Wed Jan 18 20:26:58 2023 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Thu Feb 16 09:11:43 2023 +0000

    tdf#119229 docx: Set paraIdParent upon FN_REPLY
    
    Set the paraIdParent SwPostItField attribute when replying on an
    existing comment in Writer
    
    Change-Id: I33d89688d5a36a91b26a64cf4b0f605d7bf33b1f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145750
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    (cherry picked from commit 70ff425141e3569bf09a6768ded3b8a7b0002bab)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147069
    Tested-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/inc/AnnotationWin.hxx b/sw/inc/AnnotationWin.hxx
index f5d3c167c24e..2aa641361ebf 100644
--- a/sw/inc/AnnotationWin.hxx
+++ b/sw/inc/AnnotationWin.hxx
@@ -191,6 +191,11 @@ class SAL_DLLPUBLIC_RTTI SwAnnotationWin final : public 
InterimItemWindow
         bool IsResolved() const;
         bool IsThreadResolved();
 
+        // Get annotation paraId or generate one if it doesn't exist
+        sal_uInt32 GetParaId();
+        // Used to generate a unique paraId
+        static sal_uInt32 CreateUniqueParaId();
+
         // Set this SwAnnotationWin as the currently active one
         // return false if it was already active
         bool SetActiveSidebarWin();
diff --git a/sw/inc/PostItMgr.hxx b/sw/inc/PostItMgr.hxx
index 68292b452ab3..98d9f4f2ef30 100644
--- a/sw/inc/PostItMgr.hxx
+++ b/sw/inc/PostItMgr.hxx
@@ -230,6 +230,8 @@ class SAL_DLLPUBLIC_RTTI SwPostItMgr final : public 
SfxListener
 
         sw::annotation::SwAnnotationWin* GetNextPostIt( sal_uInt16 aDirection,
                                                         
sw::annotation::SwAnnotationWin* aPostIt);
+        SwPostItField* GetLatestPostItField();
+
         tools::Long GetNextBorder();
 
         sw::annotation::SwAnnotationWin* GetActiveSidebarWin() { return 
mpActivePostIt; }
diff --git a/sw/inc/postithelper.hxx b/sw/inc/postithelper.hxx
index 3377fc752450..f55d64d39a99 100644
--- a/sw/inc/postithelper.hxx
+++ b/sw/inc/postithelper.hxx
@@ -114,6 +114,7 @@ public:
     virtual SwPosition GetAnchorPosition() const = 0;
     virtual bool UseElement(SwRootFrame const&, IDocumentRedlineAccess const&) 
= 0;
     virtual const SwFormatField& GetFormatField() const = 0;
+    virtual SwFormatField& GetFormatField() = 0;
     virtual const SfxBroadcaster* GetBroadcaster() const = 0;
     virtual VclPtr<sw::annotation::SwAnnotationWin> GetSidebarWindow( 
SwEditWin& rEditWin,
                                                                 SwPostItMgr& 
aMgr) = 0;
@@ -136,6 +137,10 @@ public:
     {
         return mrFormatField;
     }
+    SwFormatField& GetFormatField() override
+    {
+        return mrFormatField;
+    }
     virtual const SfxBroadcaster* GetBroadcaster() const override
     {
         return &mrFormatField;
diff --git a/sw/source/uibase/docvw/AnnotationWin.cxx 
b/sw/source/uibase/docvw/AnnotationWin.cxx
index 685dcbb5ce94..8ba768d7d253 100644
--- a/sw/source/uibase/docvw/AnnotationWin.cxx
+++ b/sw/source/uibase/docvw/AnnotationWin.cxx
@@ -49,6 +49,7 @@
 #include <editeng/outlobj.hxx>
 
 #include <comphelper/lok.hxx>
+#include <comphelper/random.hxx>
 #include <docufld.hxx>
 #include <txtfld.hxx>
 #include <ndtxt.hxx>
@@ -236,6 +237,26 @@ void SwAnnotationWin::ToggleResolvedForThread()
     mrMgr.LayoutPostIts();
 }
 
+sal_uInt32 SwAnnotationWin::GetParaId()
+{
+    auto pField = static_cast<SwPostItField*>(mpFormatField->GetField());
+    auto nParaId = pField->GetParaId();
+    if (nParaId == 0)
+    {
+        // The parent annotation does not have a paraId. This happens when the 
annotation was just
+        // created, and not imported. paraIds are regenerated upon export, 
thus this new paraId
+        // is only generated so that children annotations can refer to it
+        nParaId = CreateUniqueParaId();
+        pField->SetParaId(nParaId);
+    }
+    return nParaId;
+}
+
+sal_uInt32 SwAnnotationWin::CreateUniqueParaId()
+{
+    return comphelper::rng::uniform_uint_distribution(0, 
std::numeric_limits<sal_uInt32>::max());
+}
+
 void SwAnnotationWin::DeleteThread()
 {
     // Go to the top and delete each comment one by one
diff --git a/sw/source/uibase/docvw/AnnotationWin2.cxx 
b/sw/source/uibase/docvw/AnnotationWin2.cxx
index 087759047a81..3f8dd2333b9d 100644
--- a/sw/source/uibase/docvw/AnnotationWin2.cxx
+++ b/sw/source/uibase/docvw/AnnotationWin2.cxx
@@ -67,6 +67,7 @@
 #include <docsh.hxx>
 #include <wrtsh.hxx>
 #include <doc.hxx>
+#include <docufld.hxx>
 #include <swmodule.hxx>
 
 #include <SwRewriter.hxx>
@@ -1092,6 +1093,13 @@ void SwAnnotationWin::ExecuteCommand(sal_uInt16 nSlot)
                 mrMgr.SetActiveSidebarWin(nullptr);
             SwitchToFieldPos();
             mrView.GetViewFrame()->GetDispatcher()->Execute(FN_POSTIT);
+
+            if (nSlot == FN_REPLY)
+            {
+                // Get newly created SwPostItField and set its paraIdParent
+                auto pPostItField = mrMgr.GetLatestPostItField();
+                pPostItField->SetParentId(GetTopReplyNote()->GetParaId());
+            }
             break;
         }
         case FN_DELETE_COMMENT:
diff --git a/sw/source/uibase/docvw/PostItMgr.cxx 
b/sw/source/uibase/docvw/PostItMgr.cxx
index 0e478d9bea6b..e0ceb396fc81 100644
--- a/sw/source/uibase/docvw/PostItMgr.cxx
+++ b/sw/source/uibase/docvw/PostItMgr.cxx
@@ -1812,6 +1812,11 @@ sw::annotation::SwAnnotationWin* 
SwPostItMgr::GetAnnotationWin(const sal_uInt32
     return nullptr;
 }
 
+SwPostItField* SwPostItMgr::GetLatestPostItField()
+{
+    return 
static_cast<SwPostItField*>(mvPostItFields.back()->GetFormatField().GetField());
+}
+
 SwAnnotationWin* SwPostItMgr::GetNextPostIt( sal_uInt16 aDirection,
                                           SwAnnotationWin* aPostIt )
 {

Reply via email to