sc/inc/column.hxx              |    2 +-
 sc/source/core/data/column.cxx |   28 ++++++++++++++++++++++------
 sc/source/core/data/table2.cxx |    2 +-
 3 files changed, 24 insertions(+), 8 deletions(-)

New commits:
commit c15c1d87fceb782d76b5984f576d03a63c609ae5
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Tue Oct 31 11:33:56 2023 +0000
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Tue Oct 31 17:15:30 2023 +0100

    tell client when the cell for the comment changed
    
    when a row/column is inserted/deleted, etc the cell the comments are
    associated with changes, so broadcast that change to the clients.
    
    https://github.com/CollaboraOnline/online/issues/7334
    
    Change-Id: I8a3e5fc151b6ba99e68b32c3fe8804de9ba2baf4
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158720
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 0f30f64cb672..26ef79da2e6d 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -714,7 +714,7 @@ public:
     void DuplicateNotes(SCROW nStartRow, size_t nDataSize, ScColumn& rDestCol,
                             sc::ColumnBlockPosition& rDestBlockPos, bool 
bCloneCaption, SCROW nRowOffsetDest = 0) const;
 
-    void UpdateNoteCaptions( SCROW nRow1, SCROW nRow2 );
+    void UpdateNoteCaptions( SCROW nRow1, SCROW nRow2, bool bAddressChanged = 
true );
 
     void UpdateDrawObjects( std::vector<std::vector<SdrObject*>>& pObjects, 
SCROW nRowStart, SCROW nRowEnd );
     void UpdateDrawObjectsForRow( std::vector<SdrObject*>& pObjects, SCCOL 
nTargetCol, SCROW nTargetRow );
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index fea2f84e5be0..7ffd5ae9c735 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -20,6 +20,7 @@
 #include <column.hxx>
 #include <scitems.hxx>
 #include <formulacell.hxx>
+#include <docsh.hxx>
 #include <document.hxx>
 #include <table.hxx>
 #include <docpool.hxx>
@@ -1808,22 +1809,37 @@ void resetColumnPosition(sc::CellStoreType& rCells, 
SCCOL nCol)
 
 class NoteCaptionUpdater
 {
-    SCCOL mnCol;
-    SCTAB mnTab;
+    const ScDocument& m_rDocument;
+    const ScAddress m_aAddress; // 'incomplete' address consisting of tab, 
column
+    bool m_bAddressChanged;  // false if the cell anchor address is unchanged
 public:
-    NoteCaptionUpdater( SCCOL nCol, SCTAB nTab ) : mnCol(nCol), mnTab(nTab) {}
+    NoteCaptionUpdater(const ScDocument& rDocument, const ScAddress& rPos, 
bool bAddressChanged)
+        : m_rDocument(rDocument)
+        , m_aAddress(rPos)
+        , m_bAddressChanged(bAddressChanged)
+    {
+    }
 
     void operator() ( size_t nRow, ScPostIt* p )
     {
-        p->UpdateCaptionPos(ScAddress(mnCol,nRow,mnTab));
+        // Create a 'complete' address object
+        ScAddress aAddr(m_aAddress);
+        aAddr.SetRow(nRow);
+
+        p->UpdateCaptionPos(aAddr);
+
+        // Notify our LOK clients
+        if (m_bAddressChanged)
+            ScDocShell::LOKCommentNotify(LOKCommentNotificationType::Modify, 
m_rDocument, aAddr, p);
     }
 };
 
 }
 
-void ScColumn::UpdateNoteCaptions( SCROW nRow1, SCROW nRow2 )
+void ScColumn::UpdateNoteCaptions( SCROW nRow1, SCROW nRow2, bool 
bAddressChanged )
 {
-    NoteCaptionUpdater aFunc(nCol, nTab);
+    ScAddress aAddr(nCol, 0, nTab);
+    NoteCaptionUpdater aFunc(GetDoc(), aAddr, bAddressChanged);
     sc::ProcessNote(maCellNotes.begin(), maCellNotes, nRow1, nRow2, aFunc);
 }
 
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 31a0d6f1dd1e..978bd00ecbac 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -1491,7 +1491,7 @@ void ScTable::CopyCaptionsToTable( SCCOL nCol1, SCROW 
nRow1, SCCOL nCol2, SCROW
     for (SCCOL i = nCol1; i <= nCol2; i++)
     {
         aCol[i].CopyCellNotesToDocument(nRow1, nRow2, 
pDestTab->CreateColumnIfNotExists(i), bCloneCaption);
-        pDestTab->aCol[i].UpdateNoteCaptions(nRow1, nRow2);
+        pDestTab->aCol[i].UpdateNoteCaptions(nRow1, nRow2, false /* address 
unchanged from initial create */);
     }
 }
 

Reply via email to