summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2014-02-05 19:21:22 -0500
committerFridrich Strba <fridrich@documentfoundation.org>2014-02-06 14:39:29 +0000
commita0fe08c6862f5debaa375cc35c6bcec64f1008dc (patch)
tree46ed84b72f6702deece1a9e4e8618e475b66a611 /sc
parent0003e02b1c96e01607924873697a52fb813343ac (diff)
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@documentfoundation.org> Tested-by: Fridrich Strba <fridrich@documentfoundation.org>
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/column.hxx2
-rw-r--r--sc/inc/document.hxx2
-rw-r--r--sc/inc/mtvcellfunc.hxx10
-rw-r--r--sc/inc/table.hxx3
-rw-r--r--sc/source/core/data/column.cxx2
-rw-r--r--sc/source/core/data/column2.cxx28
-rw-r--r--sc/source/core/data/document.cxx31
-rw-r--r--sc/source/core/data/table2.cxx17
-rw-r--r--sc/source/ui/undo/undoblk.cxx1
9 files changed, 85 insertions, 11 deletions
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 9eef0853c05e..c6db640a8c64 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 4a967092d2c9..505746f7f33a 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 793f2dbc1872..fc6d2dcd74b0 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 3049698492c9..f6164ced3330 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 e35858842202..5e85acefc73a 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 018052f9c0a1..4f4ee062c7c5 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 99192e485181..06ae53021e67 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 ce0909d0aeb2..7d49a0026d14 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 5661fd756932..6497f0e17849 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)