summaryrefslogtreecommitdiff
path: root/sc/source/core
diff options
context:
space:
mode:
Diffstat (limited to 'sc/source/core')
-rw-r--r--sc/source/core/data/column2.cxx76
-rw-r--r--sc/source/core/data/document.cxx72
-rw-r--r--sc/source/core/data/postit.cxx8
-rw-r--r--sc/source/core/data/table2.cxx22
4 files changed, 166 insertions, 12 deletions
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 0027ed8d2a91..a3bdef50f9d0 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -1214,6 +1214,82 @@ bool ScColumn::IsNotesEmptyBlock(SCROW nStartRow, SCROW nEndRow) const
return nEndRow < nNextRow;
}
+size_t ScColumn::GetNoteCount() const
+{
+ size_t nCount = 0;
+ sc::CellNoteStoreType::const_iterator it = maCellNotes.begin(), itEnd = maCellNotes.end();
+ for (; it != itEnd; ++it)
+ {
+ if (it->type != sc::element_type_cellnote)
+ continue;
+
+ nCount += it->size;
+ }
+
+ return nCount;
+}
+
+SCROW ScColumn::GetNotePosition( size_t nIndex ) const
+{
+ // Return the row position of the nth note in the column.
+
+ sc::CellNoteStoreType::const_iterator it = maCellNotes.begin(), itEnd = maCellNotes.end();
+
+ size_t nCount = 0; // Number of notes encountered so far.
+ for (; it != itEnd; ++it)
+ {
+ if (!it->type != sc::element_type_cellnote)
+ // Skip the empty blocks.
+ continue;
+
+ if (nIndex < nCount + it->size)
+ {
+ // Index falls within this block.
+ size_t nOffset = nIndex - nCount;
+ return it->position + nOffset;
+ }
+
+ nCount += it->size;
+ }
+
+ return -1;
+}
+
+namespace {
+
+class NoteEntryCollector
+{
+ std::vector<sc::NoteEntry>& mrNotes;
+ SCTAB mnTab;
+ SCCOL mnCol;
+public:
+ NoteEntryCollector( std::vector<sc::NoteEntry>& rNotes, SCTAB nTab, SCCOL nCol ) :
+ mrNotes(rNotes), mnTab(nTab), mnCol(nCol) {}
+
+ void operator() (const sc::CellNoteStoreType::value_type& node) const
+ {
+ if (node.type != sc::element_type_cellnote)
+ return;
+
+ size_t nTopRow = node.position;
+ sc::cellnote_block::const_iterator it = sc::cellnote_block::begin(*node.data);
+ sc::cellnote_block::const_iterator itEnd = sc::cellnote_block::end(*node.data);
+ size_t nOffset = 0;
+ for (; it != itEnd; ++it, ++nOffset)
+ {
+ ScAddress aPos(mnCol, nTopRow + nOffset, mnTab);
+ mrNotes.push_back(sc::NoteEntry(aPos, *it));
+ }
+ }
+};
+
+}
+
+void ScColumn::GetAllNoteEntries( std::vector<sc::NoteEntry>& rNotes ) const
+{
+ std::for_each(maCellNotes.begin(), maCellNotes.end(), NoteEntryCollector(rNotes, nTab, nCol));
+}
+
SCSIZE ScColumn::GetEmptyLinesInBlock( SCROW nStartRow, SCROW nEndRow, ScDirection eDir ) const
{
// Given a range of rows, find a top or bottom empty segment.
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index a6180bc946b4..30c92563b7fa 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -6073,10 +6073,7 @@ ScPostIt* ScDocument::GetNote(SCCOL nCol, SCROW nRow, SCTAB nTab)
return NULL;
}
-sc::CellNoteStoreType& ScDocument::GetColNotes(SCCOL nCol, SCTAB nTab)
-{
- return maTabs[nTab]->aCol[nCol].maCellNotes;
-}
+
void ScDocument::SetNote(const ScAddress& rPos, ScPostIt* pNote)
{
return SetNote(rPos.Col(), rPos.Row(), rPos.Tab(), pNote);
@@ -6138,24 +6135,75 @@ ScPostIt* ScDocument::CreateNote(const ScAddress& rPos)
return pPostIt;
}
-sal_uLong ScDocument::CountNotes()
+size_t ScDocument::CountNotes() const
{
- sal_uLong nCount = 0;
+ size_t nCount = 0;
SCTAB nTabCount = GetTableCount();
for (SCTAB nTab=0; nTab<nTabCount; nTab++)
{
for (SCCOL nCol=0; nCol<MAXCOLCOUNT; nCol++)
+ nCount += GetNoteCount(nTab, nCol);
+ }
+ return nCount;
+}
+
+size_t ScDocument::GetNoteCount( SCTAB nTab, SCCOL nCol ) const
+{
+ const ScTable* pTab = FetchTable(nTab);
+ if (!pTab)
+ return 0;
+
+ return pTab->GetNoteCount(nCol);
+}
+
+ScAddress ScDocument::GetNotePosition( size_t nIndex ) const
+{
+ for (size_t nTab = 0; nTab < maTabs.size(); ++nTab)
+ {
+ for (SCCOL nCol=0; nCol<MAXCOLCOUNT; nCol++)
{
- sc::CellNoteStoreType& maCellNotes = GetColNotes(nCol, nTab);
- sc::CellNoteStoreType::const_iterator it = maCellNotes.begin(), itEnd = maCellNotes.end();
- for (; it != itEnd; ++it)
+ size_t nColNoteCount = GetNoteCount(nTab, nCol);
+ if (!nColNoteCount)
+ continue;
+
+ if (nIndex >= nColNoteCount)
{
- if (it->type == sc::element_type_cellnote)
- nCount +=it->size;
+ nIndex -= nColNoteCount;
+ continue;
}
+
+ SCROW nRow = GetNotePosition(nTab, nCol, nIndex);
+ if (nRow >= 0)
+ return ScAddress(nCol, nRow, nTab);
+
+ OSL_FAIL("note not found");
+ return ScAddress();
}
}
- return nCount;
+
+ OSL_FAIL("note not found");
+ return ScAddress();
+}
+
+SCROW ScDocument::GetNotePosition( SCTAB nTab, SCCOL nCol, size_t nIndex ) const
+{
+ const ScTable* pTab = FetchTable(nTab);
+ if (!pTab)
+ return -1;
+
+ return pTab->GetNotePosition(nCol, nIndex);
+}
+
+void ScDocument::GetAllNoteEntries( std::vector<sc::NoteEntry>& rNotes ) const
+{
+ for (size_t nTab = 0; nTab < maTabs.size(); ++nTab)
+ {
+ const ScTable* pTab = maTabs[nTab];
+ if (!pTab)
+ continue;
+
+ pTab->GetAllNoteEntries(rNotes);
+ }
}
void ScDocument::SetAutoNameCache( ScAutoNameCache* pCache )
diff --git a/sc/source/core/data/postit.cxx b/sc/source/core/data/postit.cxx
index 67f730344ca5..dfd143dfd803 100644
--- a/sc/source/core/data/postit.cxx
+++ b/sc/source/core/data/postit.cxx
@@ -936,4 +936,12 @@ ScPostIt* ScNoteUtil::CreateNoteFromString(
}
return pNote;
}
+
+namespace sc {
+
+NoteEntry::NoteEntry( const ScAddress& rPos, const ScPostIt* pNote ) :
+ maPos(rPos), mpNote(pNote) {}
+
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 312aa22b77a4..5295af6c5e5c 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -1502,6 +1502,28 @@ ScPostIt* ScTable::GetNote(const SCCOL nCol, const SCROW nRow)
return pDocument->GetNote(nCol, nRow, nTab);
}
+size_t ScTable::GetNoteCount( SCCOL nCol ) const
+{
+ if (!ValidCol(nCol))
+ return 0;
+
+ return aCol[nCol].GetNoteCount();
+}
+
+SCROW ScTable::GetNotePosition( SCCOL nCol, size_t nIndex ) const
+{
+ if (!ValidCol(nCol))
+ return -1;
+
+ return aCol[nCol].GetNotePosition(nIndex);
+}
+
+void ScTable::GetAllNoteEntries( std::vector<sc::NoteEntry>& rNotes ) const
+{
+ for (SCCOL nCol = 0; nCol < MAXCOLCOUNT; ++nCol)
+ aCol[nCol].GetAllNoteEntries(rNotes);
+}
+
CellType ScTable::GetCellType( SCCOL nCol, SCROW nRow ) const
{
if (ValidColRow( nCol, nRow ))