[Libreoffice-commits] core.git: Branch 'libreoffice-4-2' - sc/inc sc/source

Kohei Yoshida kohei.yoshida at collabora.com
Thu Feb 6 06:39:54 PST 2014


 sc/inc/column.hxx                |    2 ++
 sc/inc/document.hxx              |    2 +-
 sc/inc/mtvcellfunc.hxx           |   10 ++++++++++
 sc/inc/table.hxx                 |    3 +++
 sc/source/core/data/column.cxx   |    2 +-
 sc/source/core/data/column2.cxx  |   28 ++++++++++++++++++++++++++++
 sc/source/core/data/document.cxx |   31 ++++++++++++++++++++++---------
 sc/source/core/data/table2.cxx   |   17 +++++++++++++++++
 sc/source/ui/undo/undoblk.cxx    |    1 +
 9 files changed, 85 insertions(+), 11 deletions(-)

New commits:
commit a0fe08c6862f5debaa375cc35c6bcec64f1008dc
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Wed Feb 5 19:21:22 2014 -0500

    fdo#74556: Correctly handle note captions life cycles.
    
    When copying notes to clipboard, we don't clone captions but leave them
    pointing to the original captions objects. Also, during undo and redo,
    we need to clear all caption pointers to prevent them from being deleted
    when the ScPostIt objects get deleted. The undo and redo of caption objects
    are handled in the drawing layer afterwards.
    
    Also, Have ReleaseNote() really release note rather than destroying it.
    
    (cherry picked from commit fe5d604ecf6de4935c622e0e95efc085c4a3cbfd)
    (cherry picked from commit bc504b5adfaeeac0b910b89b0c98ae564f1ff5b8)
    
    Change-Id: Ia1da7784d04a2183f21813b6914e78161aad39d7
    Reviewed-on: https://gerrit.libreoffice.org/7887
    Reviewed-by: Fridrich Strba <fridrich at documentfoundation.org>
    Tested-by: Fridrich Strba <fridrich at documentfoundation.org>

diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 9eef085..c6db640 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -502,8 +502,10 @@ public:
     void SetCellNote( SCROW nRow, ScPostIt* pNote);
     bool IsNotesEmptyBlock(SCROW nStartRow, SCROW nEndRow) const;
 
+    ScPostIt* ReleaseNote( SCROW nRow );
     size_t GetNoteCount() const;
     void CreateAllNoteCaptions();
+    void ForgetNoteCaptions( SCROW nRow1, SCROW nRow2 );
     SCROW GetNotePosition( size_t nIndex ) const;
     void GetAllNoteEntries( std::vector<sc::NoteEntry>& rNotes ) const;
     void GetNotesInRange( SCROW nStartRow, SCROW nEndRow, std::vector<sc::NoteEntry>& rNotes ) const;
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 4a96709..505746f 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -906,7 +906,6 @@ public:
     SC_DLLPUBLIC bool            HasColNotes(SCCOL nCol, SCTAB nTab);
     SC_DLLPUBLIC bool            HasTabNotes(SCTAB nTab);
     SC_DLLPUBLIC ScPostIt*       ReleaseNote(const ScAddress& rPos);
-    SC_DLLPUBLIC ScPostIt*       ReleaseNote(SCCOL nCol, SCROW nRow, SCTAB nTab);
     SC_DLLPUBLIC ScPostIt*       GetOrCreateNote(const ScAddress& rPos);
     SC_DLLPUBLIC ScPostIt*       CreateNote(const ScAddress& rPos);
     size_t CountNotes() const;
@@ -917,6 +916,7 @@ public:
      * code uses sdr objects to export note data.
      */
     void CreateAllNoteCaptions();
+    void ForgetNoteCaptions( const ScRangeList& rRanges );
 
     ScAddress GetNotePosition( size_t nIndex ) const;
     SCROW GetNotePosition( SCTAB nTab, SCCOL nCol, size_t nIndex ) const;
diff --git a/sc/inc/mtvcellfunc.hxx b/sc/inc/mtvcellfunc.hxx
index 793f2db..fc6d2dc 100644
--- a/sc/inc/mtvcellfunc.hxx
+++ b/sc/inc/mtvcellfunc.hxx
@@ -166,6 +166,16 @@ void ProcessNote(CellNoteStoreType& rStore, _Func& rFunc)
     ProcessElements1<CellNoteStoreType, cellnote_block, _Func, FuncElseNoOp<size_t> >(rStore, rFunc, aElse);
 }
 
+template<typename _FuncElem>
+typename CellNoteStoreType::iterator
+ProcessNote(
+    const CellNoteStoreType::iterator& it, CellNoteStoreType& rStore, SCROW nRow1, SCROW nRow2, _FuncElem& rFuncElem)
+{
+    FuncElseNoOp<size_t> aElse;
+    return ProcessElements1<
+        CellNoteStoreType, cellnote_block, _FuncElem, FuncElseNoOp<size_t> >(it, rStore, nRow1, nRow2, rFuncElem, aElse);
+}
+
 }
 
 #endif
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 3049698..f6164ce 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -381,9 +381,12 @@ public:
 
     ScPostIt*   GetNote(const SCCOL nCol, const SCROW nRow);
 
+    ScPostIt* ReleaseNote( SCCOL nCol, SCROW nRow );
+
     size_t GetNoteCount( SCCOL nCol ) const;
     SCROW GetNotePosition( SCCOL nCol, size_t nIndex ) const;
     void CreateAllNoteCaptions();
+    void ForgetNoteCaptions( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 );
 
     void GetAllNoteEntries( std::vector<sc::NoteEntry>& rNotes ) const;
     void GetNotesInRange( const ScRange& rRange, std::vector<sc::NoteEntry>& rNotes ) const;
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index e358588..5e85ace 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -1278,7 +1278,7 @@ class CopyToClipHandler
 
     void duplicateNotes(SCROW nStartRow, size_t nDataSize )
     {
-        mrSrcCol.DuplicateNotes(nStartRow, nDataSize, mrDestCol, maDestPos);
+        mrSrcCol.DuplicateNotes(nStartRow, nDataSize, mrDestCol, maDestPos, false);
     }
 
 public:
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 018052f..4f4ee06 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -1212,6 +1212,16 @@ bool ScColumn::IsNotesEmptyBlock(SCROW nStartRow, SCROW nEndRow) const
     return nEndRow < nNextRow;
 }
 
+ScPostIt* ScColumn::ReleaseNote( SCROW nRow )
+{
+    if (!ValidRow(nRow))
+        return NULL;
+
+    ScPostIt* p = NULL;
+    maCellNotes.release(nRow, p);
+    return p;
+}
+
 size_t ScColumn::GetNoteCount() const
 {
     size_t nCount = 0;
@@ -1242,6 +1252,14 @@ public:
     }
 };
 
+struct NoteCaptionCleaner
+{
+    void operator() ( size_t /*nRow*/, ScPostIt* p )
+    {
+        p->ForgetCaption();
+    }
+};
+
 }
 
 void ScColumn::CreateAllNoteCaptions()
@@ -1250,6 +1268,16 @@ void ScColumn::CreateAllNoteCaptions()
     sc::ProcessNote(maCellNotes, aFunc);
 }
 
+void ScColumn::ForgetNoteCaptions( SCROW nRow1, SCROW nRow2 )
+{
+    if (!ValidRow(nRow1) || !ValidRow(nRow2))
+        return;
+
+    NoteCaptionCleaner aFunc;
+    sc::CellNoteStoreType::iterator it = maCellNotes.begin();
+    sc::ProcessNote(it, maCellNotes, nRow1, nRow2, aFunc);
+}
+
 SCROW ScColumn::GetNotePosition( size_t nIndex ) const
 {
     // Return the row position of the nth note in the column.
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 99192e4..06ae530 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -6147,16 +6147,11 @@ bool ScDocument::HasTabNotes(SCTAB nTab)
 
 ScPostIt* ScDocument::ReleaseNote(const ScAddress& rPos)
 {
-        return ReleaseNote(rPos.Col(), rPos.Row(), rPos.Tab());
-}
-ScPostIt* ScDocument::ReleaseNote(SCCOL nCol, SCROW nRow, SCTAB nTab)
-{
-
-    ScPostIt* pPostIt = GetNote(nCol, nRow, nTab);
-    if (pPostIt != NULL)
-        maTabs[nTab]->aCol[nCol].DeleteCellNote(nRow);
+    ScTable* pTab = FetchTable(rPos.Tab());
+    if (!pTab)
+        return NULL;
 
-    return pPostIt;
+    return pTab->ReleaseNote(rPos.Col(), rPos.Row());
 }
 
 ScPostIt* ScDocument::GetOrCreateNote(const ScAddress& rPos)
@@ -6205,6 +6200,24 @@ void ScDocument::CreateAllNoteCaptions()
     }
 }
 
+void ScDocument::ForgetNoteCaptions( const ScRangeList& rRanges )
+{
+    for (size_t i = 0, n = rRanges.size(); i < n; ++i)
+    {
+        const ScRange* p = rRanges[i];
+        const ScAddress& s = p->aStart;
+        const ScAddress& e = p->aEnd;
+        for (SCTAB nTab = s.Tab(); nTab <= e.Tab(); ++nTab)
+        {
+            ScTable* pTab = FetchTable(nTab);
+            if (!pTab)
+                continue;
+
+            pTab->ForgetNoteCaptions(s.Col(), s.Row(), e.Col(), e.Row());
+        }
+    }
+}
+
 ScAddress ScDocument::GetNotePosition( size_t nIndex ) const
 {
     for (size_t nTab = 0; nTab < maTabs.size(); ++nTab)
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index ce0909d..7d49a00 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -1494,6 +1494,14 @@ ScPostIt* ScTable::GetNote(const SCCOL nCol, const SCROW nRow)
     return pDocument->GetNote(nCol, nRow, nTab);
 }
 
+ScPostIt* ScTable::ReleaseNote( SCCOL nCol, SCROW nRow )
+{
+    if (!ValidCol(nCol))
+        return NULL;
+
+    return aCol[nCol].ReleaseNote(nRow);
+}
+
 size_t ScTable::GetNoteCount( SCCOL nCol ) const
 {
     if (!ValidCol(nCol))
@@ -1516,6 +1524,15 @@ void ScTable::CreateAllNoteCaptions()
         aCol[i].CreateAllNoteCaptions();
 }
 
+void ScTable::ForgetNoteCaptions( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
+{
+    if (!ValidCol(nCol1) || !ValidCol(nCol2))
+        return;
+
+    for (SCCOL i = nCol1; i <= nCol2; ++i)
+        aCol[i].ForgetNoteCaptions(nRow1, nRow2);
+}
+
 void ScTable::GetAllNoteEntries( std::vector<sc::NoteEntry>& rNotes ) const
 {
     for (SCCOL nCol = 0; nCol < MAXCOLCOUNT; ++nCol)
diff --git a/sc/source/ui/undo/undoblk.cxx b/sc/source/ui/undo/undoblk.cxx
index 5661fd7..6497f0e 100644
--- a/sc/source/ui/undo/undoblk.cxx
+++ b/sc/source/ui/undo/undoblk.cxx
@@ -949,6 +949,7 @@ void ScUndoPaste::DoChange(bool bUndo)
     sal_uInt16 nExtFlags = 0;
     pDocShell->UpdatePaintExt(nExtFlags, maBlockRanges.Combine());
 
+    pDoc->ForgetNoteCaptions(maBlockRanges);
     aMarkData.MarkToMulti();
     pDoc->DeleteSelection(nUndoFlags, aMarkData, false); // no broadcasting here
     for (size_t i = 0, n = maBlockRanges.size(); i < n; ++i)


More information about the Libreoffice-commits mailing list