From 3347f41a9b13c317c1d001e7ff501a4b0ee8f896 Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Wed, 23 Oct 2013 13:17:00 -0400 Subject: Avoid exposing the internal cell note storage outside ScDocument. Let's try to avoid including mtvelements.hxx in document.hxx... mtvelements.hxx is very parser-heavy, and document.hxx is included everywhere... Change-Id: I2768ba6e25f8ff10f61f9cfd4a7cbc4844230630 --- sc/source/core/data/column2.cxx | 76 +++++++++++++++++++++++++ sc/source/core/data/document.cxx | 72 +++++++++++++++++++---- sc/source/core/data/postit.cxx | 8 +++ sc/source/core/data/table2.cxx | 22 ++++++++ sc/source/filter/excel/excdoc.cxx | 34 ++--------- sc/source/ui/navipi/content.cxx | 116 ++++++-------------------------------- sc/source/ui/unoobj/docuno.cxx | 41 ++------------ 7 files changed, 195 insertions(+), 174 deletions(-) (limited to 'sc/source') 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& mrNotes; + SCTAB mnTab; + SCCOL mnCol; +public: + NoteEntryCollector( std::vector& 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& 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; nTabGetNoteCount(nCol); +} + +ScAddress ScDocument::GetNotePosition( size_t nIndex ) const +{ + for (size_t nTab = 0; nTab < maTabs.size(); ++nTab) { for (SCCOL nCol=0; nCol= 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& 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& 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 )) diff --git a/sc/source/filter/excel/excdoc.cxx b/sc/source/filter/excel/excdoc.cxx index 32db2e80c81f..574dcbb09bb7 100644 --- a/sc/source/filter/excel/excdoc.cxx +++ b/sc/source/filter/excel/excdoc.cxx @@ -417,35 +417,11 @@ void ExcTable::FillAsTable( SCTAB nCodeNameIdx ) mxCellTable.reset( new XclExpCellTable( GetRoot() ) ); //export cell notes - for (SCCOL nCol=0; nColdata) - { - SCROW nRow = itBlk->position; - itData = sc::cellnote_block::begin(*itBlk->data); - itDataEnd = sc::cellnote_block::end(*itBlk->data); - for (; itData != itDataEnd; ++itData, ++nRow) - { - ScPostIt* pScNote = *itData; - if (pScNote) - { - ScAddress aScPos( nCol, nRow, mnScTab ); - mxNoteList->AppendNewRecord( new XclExpNote( GetRoot(), aScPos, pScNote, OUString() ) ); - } - } - } - } - } - } + std::vector aNotes; + rDoc.GetAllNoteEntries(aNotes); + std::vector::const_iterator it = aNotes.begin(), itEnd = aNotes.end(); + for (; it != itEnd; ++it) + mxNoteList->AppendNewRecord(new XclExpNote(GetRoot(), it->maPos, it->mpNote, OUString())); if( GetOutput() != EXC_OUTPUT_BINARY ) { diff --git a/sc/source/ui/navipi/content.cxx b/sc/source/ui/navipi/content.cxx index 844ed81dfde6..fc70ef67f76f 100644 --- a/sc/source/ui/navipi/content.cxx +++ b/sc/source/ui/navipi/content.cxx @@ -848,7 +848,6 @@ static OUString lcl_NoteString( const ScPostIt& rNote ) return aText; } - void ScContentTree::GetNoteStrings() { if ( nRootType && nRootType != SC_CONTENT_NOTE ) // ausgeblendet ? @@ -859,36 +858,11 @@ void ScContentTree::GetNoteStrings() return; // loop over cell notes - SCTAB nTabCount = pDoc->GetTableCount(); - for (SCTAB nTab=0; nTabHasColNotes(nCol, nTab) ) - { - sc::CellNoteStoreType& maCellNotes = pDoc->GetColNotes(nCol, nTab); - - sc::CellNoteStoreType::const_iterator itBlk = maCellNotes.begin(), itBlkEnd = maCellNotes.end(); - sc::cellnote_block::const_iterator itData, itDataEnd; - - for(;itBlk != itBlkEnd; ++itBlk) - { - if (itBlk->data) - { - itData = sc::cellnote_block::begin(*itBlk->data); - itDataEnd = sc::cellnote_block::end(*itBlk->data); - for (; itData != itDataEnd; ++itData) - { - ScPostIt* pNote = *itData; - if (pNote) - InsertContent(SC_CONTENT_NOTE, lcl_NoteString( *pNote )); - } - } - - } - } - } - } + std::vector aEntries; + pDoc->GetAllNoteEntries(aEntries); + std::vector::const_iterator it = aEntries.begin(), itEnd = aEntries.end(); + for (; it != itEnd; ++it) + InsertContent(SC_CONTENT_NOTE, lcl_NoteString(*it->mpNote)); } ScAddress ScContentTree::GetNotePos( sal_uLong nIndex ) @@ -897,48 +871,9 @@ ScAddress ScContentTree::GetNotePos( sal_uLong nIndex ) if (!pDoc) return ScAddress(); - sal_uLong nFound = 0; - SCTAB nTabCount = pDoc->GetTableCount(); - - for (SCTAB nTab=0; nTabHasColNotes(nCol, nTab) ) - { - sc::CellNoteStoreType& maCellNotes = pDoc->GetColNotes(nCol, nTab); - - sc::CellNoteStoreType::const_iterator itBlk = maCellNotes.begin(), itBlkEnd = maCellNotes.end(); - sc::cellnote_block::const_iterator itData, itDataEnd; - - for(;itBlk != itBlkEnd; ++itBlk) - { - if (itBlk->data) - { - SCROW nRow = itBlk->position; - itData = sc::cellnote_block::begin(*itBlk->data); - itDataEnd = sc::cellnote_block::end(*itBlk->data); - for (; itData != itDataEnd; ++itData, ++nRow) - { - ScPostIt* pNote = *itData; - if (pNote) - { - if (nFound == nIndex) - return ScAddress(nCol, nRow, nTab); - ++nFound; - } - } - } - } - } - } - } - - OSL_FAIL("note not found"); - return ScAddress(); + return pDoc->GetNotePosition(nIndex); } - sal_Bool ScContentTree::NoteStringsChanged() { ScDocument* pDoc = GetSourceDocument(); @@ -952,35 +887,20 @@ sal_Bool ScContentTree::NoteStringsChanged() SvTreeListEntry* pEntry = FirstChild( pParent ); bool bEqual = true; - SCTAB nTabCount = pDoc->GetTableCount(); - for (SCTAB nTab=0; nTab aEntries; + pDoc->GetAllNoteEntries(aEntries); + std::vector::const_iterator it = aEntries.begin(), itEnd = aEntries.end(); + for (; it != itEnd; ++it) { - for (SCCOL nCol=0; nColmpNote; + if (!pEntry) + bEqual = false; + else { - if ( pDoc->HasColNotes(nCol, nTab) ) - { - sc::CellNoteStoreType& maCellNotes = pDoc->GetColNotes(nCol, nTab); - sc::CellNoteStoreType::const_iterator it = maCellNotes.begin(), itEnd = maCellNotes.end(); - for (; it != itEnd; ++it) - { - if (it->type == sc::element_type_cellnote) - { - SCROW nRow = it->position; - ScPostIt* pNote = maCellNotes.get(nRow); - if (pNote) - { - if ( !pEntry ) - bEqual = false; - else - { - if ( lcl_NoteString( *pNote ) != GetEntryText(pEntry) ) - bEqual = false; - pEntry = NextSibling( pEntry ); - } - } - } - } - } + if (lcl_NoteString(*pNote) != GetEntryText(pEntry)) + bEqual = false; + + pEntry = NextSibling(pEntry); } } diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx index 4f1430f99791..8123f4593b0b 100644 --- a/sc/source/ui/unoobj/docuno.cxx +++ b/sc/source/ui/unoobj/docuno.cxx @@ -3429,41 +3429,12 @@ void ScAnnotationsObj::Notify( SfxBroadcaster&, const SfxHint& rHint ) bool ScAnnotationsObj::GetAddressByIndex_Impl( sal_Int32 nIndex, ScAddress& rPos ) const { - if (pDocShell) - { - sal_Int32 nFound = 0; - ScDocument* pDoc = pDocShell->GetDocument(); - SCTAB nTabCount = pDoc->GetTableCount(); - for (SCTAB aTab=0; aTabGetColNotes(nCol, aTab); - std::pair aPos = maNotes.position(0); - sc::CellNoteStoreType::const_iterator it = aPos.first; - size_t nOffset = aPos.second; - size_t nDataSize = 0; - size_t nRow = 0; - sal_Int32 nNotesSize = maNotes.size(); - if (nFound + nNotesSize >= nIndex) - { - for (; it != maNotes.end(); ++it, nOffset = 0, nRow += nDataSize) - { - nDataSize = it->size - nOffset; - if (nFound == nIndex) - { - rPos = ScAddress(nCol, nRow, nTab); - return true; - } - ++nFound; - } - } - else - nFound += nNotesSize; - } - } - } - return false; + if (!pDocShell) + return false; + + ScDocument* pDoc = pDocShell->GetDocument(); + rPos = pDoc->GetNotePosition(nIndex); + return rPos.IsValid(); } ScAnnotationObj* ScAnnotationsObj::GetObjectByIndex_Impl( sal_Int32 nIndex ) const -- cgit v1.2.3