sc/inc/cellvalue.hxx | 8 ++ sc/inc/global.hxx | 1 sc/source/core/data/autonamecache.cxx | 29 ++++--- sc/source/core/data/cellvalue.cxx | 116 +++++++++++++++++++++++++++++ sc/source/core/tool/compiler.cxx | 2 sc/source/core/tool/interpr4.cxx | 1 sc/source/ui/unoobj/cellsuno.cxx | 132 +++++++++++++++------------------- sc/source/ui/unoobj/chart2uno.cxx | 1 8 files changed, 199 insertions(+), 91 deletions(-)
New commits: commit 3f490b0dcfae65ff588b67936490f9f7a795b005 Author: Kohei Yoshida <kohei.yosh...@gmail.com> Date: Fri Mar 22 15:36:57 2013 -0400 Start switching ScCellIterator caller to alternative iteration method. Change-Id: I8b39adaaff3874e26709579530fb74b2bf0543be diff --git a/sc/inc/cellvalue.hxx b/sc/inc/cellvalue.hxx index ac96274..16af46f 100644 --- a/sc/inc/cellvalue.hxx +++ b/sc/inc/cellvalue.hxx @@ -49,6 +49,14 @@ struct ScCellValue * Set cell value at specified position in specified document. */ void commit( ScDocument& rDoc, const ScAddress& rPos ); + + bool hasString() const; + + bool hasNumeric() const; + + bool isEmpty() const; + + bool equalsWithoutFormat( const ScCellValue& r ) const; }; // TODO: temporary workaround. To be removed later. diff --git a/sc/source/core/data/autonamecache.cxx b/sc/source/core/data/autonamecache.cxx index 8a79864..2bbc4b2 100644 --- a/sc/source/core/data/autonamecache.cxx +++ b/sc/source/core/data/autonamecache.cxx @@ -21,10 +21,11 @@ #include "autonamecache.hxx" #include "dociter.hxx" -#include "cell.hxx" #include "queryparam.hxx" - -// ----------------------------------------------------------------------- +#include "cell.hxx" +#include "cellvalue.hxx" +#include "editutil.hxx" +#include "document.hxx" ScAutoNameCache::ScAutoNameCache( ScDocument* pD ) : pDoc( pD ), @@ -52,25 +53,28 @@ const ScAutoNameAddresses& ScAutoNameCache::GetNameOccurrences( const String& rN ScAutoNameAddresses& rAddresses = aNames[rName]; ScCellIterator aIter( pDoc, ScRange( 0, 0, nCurrentTab, MAXCOL, MAXROW, nCurrentTab ) ); - for ( ScBaseCell* pCell = aIter.GetFirst(); pCell; pCell = aIter.GetNext() ) + for (bool bHasCell = aIter.first(); bHasCell; bHasCell = aIter.next()) { // don't check code length here, always use the stored result // (AutoCalc is disabled during CompileXML) - - if ( pCell->HasStringData() ) + const ScCellValue& rVal = aIter.get(); + if (rVal.hasString()) { - String aStr; - CellType eType = pCell->GetCellType(); - switch ( eType ) + OUString aStr; + switch (rVal.meType) { case CELLTYPE_STRING: - aStr = ((ScStringCell*)pCell)->GetString(); + aStr = *rVal.mpString; break; case CELLTYPE_FORMULA: - aStr = ((ScFormulaCell*)pCell)->GetString(); + aStr = rVal.mpFormula->GetString(); break; case CELLTYPE_EDIT: - aStr = ((ScEditCell*)pCell)->GetString(); + { + ScFieldEditEngine& rEngine = pDoc->GetEditEngine(); + rEngine.SetText(*rVal.mpEditText); + aStr = ScEditUtil::GetMultilineString(rEngine); // string with line separators between paragraphs + } break; case CELLTYPE_NONE: case CELLTYPE_VALUE: diff --git a/sc/source/core/data/cellvalue.cxx b/sc/source/core/data/cellvalue.cxx index 6a51c68..3706278 100644 --- a/sc/source/core/data/cellvalue.cxx +++ b/sc/source/core/data/cellvalue.cxx @@ -12,6 +12,7 @@ #include "cell.hxx" #include "editeng/editobj.hxx" #include "stringutil.hxx" +#include "formula/token.hxx" ScCellValue::ScCellValue() : meType(CELLTYPE_NONE), mfValue(0.0) {} ScCellValue::ScCellValue( double fValue ) : meType(CELLTYPE_VALUE), mfValue(fValue) {} @@ -113,6 +114,121 @@ void ScCellValue::commit( ScDocument& rDoc, const ScAddress& rPos ) } } +bool ScCellValue::hasString() const +{ + switch (meType) + { + case CELLTYPE_STRING: + case CELLTYPE_EDIT: + return true; + case CELLTYPE_FORMULA: + return !mpFormula->IsValue(); + default: + return false; + } +} + +bool ScCellValue::hasNumeric() const +{ + switch (meType) + { + case CELLTYPE_VALUE: + return true; + case CELLTYPE_FORMULA: + return mpFormula->IsValue(); + default: + return false; + } +} + +bool ScCellValue::isEmpty() const +{ + return meType == CELLTYPE_NOTE || meType == CELLTYPE_NONE; +} + +namespace { + +CellType adjustCellType( CellType eOrig ) +{ + switch (eOrig) + { + case CELLTYPE_NOTE: + return CELLTYPE_NONE; + case CELLTYPE_EDIT: + return CELLTYPE_STRING; + default: + ; + } + return eOrig; +} + +OUString getString( const ScCellValue& rVal ) +{ + if (rVal.meType == CELLTYPE_STRING) + return *rVal.mpString; + + if (rVal.meType == CELLTYPE_EDIT) + { + OUStringBuffer aRet; + size_t n = rVal.mpEditText->GetParagraphCount(); + for (size_t i = 0; i < n; ++i) + { + if (i > 0) + aRet.append('\n'); + aRet.append(rVal.mpEditText->GetText(i)); + } + return aRet.makeStringAndClear(); + } + + return EMPTY_OUSTRING; +} + +} + +bool ScCellValue::equalsWithoutFormat( const ScCellValue& r ) const +{ + CellType eType1 = adjustCellType(meType); + CellType eType2 = adjustCellType(r.meType); + if (eType1 != eType2) + return false; + + switch (meType) + { + case CELLTYPE_NONE: + return true; + case CELLTYPE_VALUE: + return mfValue == r.mfValue; + case CELLTYPE_STRING: + { + OUString aStr1 = getString(*this); + OUString aStr2 = getString(r); + return aStr1 == aStr2; + } + case CELLTYPE_FORMULA: + { + ScTokenArray* pCode1 = mpFormula->GetCode(); + ScTokenArray* pCode2 = r.mpFormula->GetCode(); + + if (pCode1->GetLen() != pCode2->GetLen()) + return false; + + sal_uInt16 n = pCode1->GetLen(); + formula::FormulaToken** ppToken1 = pCode1->GetArray(); + formula::FormulaToken** ppToken2 = pCode2->GetArray(); + for (sal_uInt16 i = 0; i < n; ++i) + { + if (!ppToken1[i]->TextEqual(*(ppToken2[i]))) + return false; + } + + return true; + } + default: + ; + } + return false; +} + ScBaseCell* getHackedBaseCell( ScDocument* pDoc, const ScCellValue& rVal ) { switch (rVal.meType) diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx index a64feb1..7bff6dd 100644 --- a/sc/source/ui/unoobj/cellsuno.cxx +++ b/sc/source/ui/unoobj/cellsuno.cxx @@ -3558,14 +3558,11 @@ uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryEmptyCel ScRange aRange = *aRanges[ i ]; ScCellIterator aIter( pDoc, aRange ); - ScBaseCell* pCell = aIter.GetFirst(); - while (pCell) + for (bool bHasCell = aIter.first(); bHasCell; bHasCell = aIter.next()) { // Notizen zaehlen als nicht-leer - if ( !pCell->IsBlank() ) + if (!aIter.get().isEmpty()) aMarkData.SetMultiMarkArea(aIter.GetPos(), false); - - pCell = aIter.GetNext(); } } @@ -3597,28 +3594,28 @@ uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryContentC ScRange aRange = *aRanges[ i ]; ScCellIterator aIter( pDoc, aRange ); - ScBaseCell* pCell = aIter.GetFirst(); - while (pCell) + for (bool bHasCell = aIter.first(); bHasCell; bHasCell = aIter.next()) { - sal_Bool bAdd = false; - switch ( pCell->GetCellType() ) + bool bAdd = false; + const ScCellValue& rVal = aIter.get(); + switch (rVal.meType) { case CELLTYPE_STRING: if ( nContentFlags & sheet::CellFlags::STRING ) - bAdd = sal_True; + bAdd = true; break; case CELLTYPE_EDIT: if ( (nContentFlags & sheet::CellFlags::STRING) || (nContentFlags & sheet::CellFlags::FORMATTED) ) - bAdd = sal_True; + bAdd = true; break; case CELLTYPE_FORMULA: if ( nContentFlags & sheet::CellFlags::FORMULA ) - bAdd = sal_True; + bAdd = true; break; case CELLTYPE_VALUE: if ( (nContentFlags & (sheet::CellFlags::VALUE|sheet::CellFlags::DATETIME)) == (sheet::CellFlags::VALUE|sheet::CellFlags::DATETIME) ) - bAdd = sal_True; + bAdd = true; else { // Date/Time Erkennung @@ -3630,12 +3627,12 @@ uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryContentC (nTyp == NUMBERFORMAT_DATETIME)) { if ( nContentFlags & sheet::CellFlags::DATETIME ) - bAdd = sal_True; + bAdd = true; } else { if ( nContentFlags & sheet::CellFlags::VALUE ) - bAdd = sal_True; + bAdd = true; } } break; @@ -3647,8 +3644,6 @@ uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryContentC if (bAdd) aMarkData.SetMultiMarkArea(aIter.GetPos(), true); - - pCell = aIter.GetNext(); } } @@ -3680,34 +3675,31 @@ uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryFormulaC ScRange aRange = *aRanges[ i ]; ScCellIterator aIter( pDoc, aRange ); - ScBaseCell* pCell = aIter.GetFirst(); - while (pCell) + for (bool bHasCell = aIter.first(); bHasCell; bHasCell = aIter.next()) { - if (pCell->GetCellType() == CELLTYPE_FORMULA) + if (aIter.get().meType == CELLTYPE_FORMULA) { - ScFormulaCell* pFCell = (ScFormulaCell*)pCell; - sal_Bool bAdd = false; + ScFormulaCell* pFCell = aIter.get().mpFormula; + bool bAdd = false; if (pFCell->GetErrCode()) { if ( nResultFlags & sheet::FormulaResult::ERROR ) - bAdd = sal_True; + bAdd = true; } else if (pFCell->IsValue()) { if ( nResultFlags & sheet::FormulaResult::VALUE ) - bAdd = sal_True; + bAdd = true; } else // String { if ( nResultFlags & sheet::FormulaResult::STRING ) - bAdd = sal_True; + bAdd = true; } if (bAdd) aMarkData.SetMultiMarkArea(aIter.GetPos(), true); } - - pCell = aIter.GetNext(); } } @@ -3743,10 +3735,9 @@ uno::Reference<sheet::XSheetCellRanges> ScCellRangesBase::QueryDifferences_Impl( else aCmpRange = ScRange( static_cast<SCCOL>(nCmpPos),0,nTab, static_cast<SCCOL>(nCmpPos),MAXROW,nTab ); ScCellIterator aCmpIter( pDoc, aCmpRange ); - ScBaseCell* pCmpCell = aCmpIter.GetFirst(); - while (pCmpCell) + for (bool bHasCell = aCmpIter.first(); bHasCell; bHasCell = aCmpIter.next()) { - if (pCmpCell->GetCellType() != CELLTYPE_NOTE) + if (aCmpIter.get().meType != CELLTYPE_NOTE) { SCCOLROW nCellPos = bColumnDiff ? static_cast<SCCOLROW>(aCmpIter.GetPos().Col()) : static_cast<SCCOLROW>(aCmpIter.GetPos().Row()); if (bColumnDiff) @@ -3774,7 +3765,6 @@ uno::Reference<sheet::XSheetCellRanges> ScCellRangesBase::QueryDifferences_Impl( } } } - pCmpCell = aCmpIter.GetNext(); } // alle nichtleeren Zellen mit der Vergleichsspalte vergleichen und entsprechend @@ -3786,22 +3776,22 @@ uno::Reference<sheet::XSheetCellRanges> ScCellRangesBase::QueryDifferences_Impl( ScRange aRange( *aRanges[ i ] ); ScCellIterator aIter( pDoc, aRange ); - ScBaseCell* pCell = aIter.GetFirst(); - while (pCell) + for (bool bHasCell = aIter.first(); bHasCell; bHasCell = aIter.next()) { + const ScCellValue& rCell = aIter.get(); + if (bColumnDiff) aCmpAddr = ScAddress( aIter.GetPos().Col(), nCmpPos, aIter.GetPos().Tab() ); else aCmpAddr = ScAddress( static_cast<SCCOL>(nCmpPos), aIter.GetPos().Row(), aIter.GetPos().Tab() ); - const ScBaseCell* pOtherCell = pDoc->GetCell( aCmpAddr ); + ScCellValue aOtherCell; + aOtherCell.assign(*pDoc, aCmpAddr); ScRange aOneRange(aIter.GetPos()); - if ( !ScBaseCell::CellEqual( pCell, pOtherCell ) ) + if (!rCell.equalsWithoutFormat(aOtherCell)) aMarkData.SetMultiMarkArea( aOneRange ); else aMarkData.SetMultiMarkArea( aOneRange, false ); // deselect - - pCell = aIter.GetNext(); } } @@ -3876,23 +3866,20 @@ uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryPreceden { ScRange aRange( *aNewRanges[ nR] ); ScCellIterator aIter( pDoc, aRange ); - ScBaseCell* pCell = aIter.GetFirst(); - while (pCell) + for (bool bHasCell = aIter.first(); bHasCell; bHasCell = aIter.next()) { - if ( pCell->GetCellType() == CELLTYPE_FORMULA ) - { - ScFormulaCell* pFCell = (ScFormulaCell*) pCell; + const ScCellValue& rVal = aIter.get(); + if (rVal.meType != CELLTYPE_FORMULA) + continue; - ScDetectiveRefIter aRefIter( pFCell ); - ScRange aRefRange; - while ( aRefIter.GetNextRef( aRefRange) ) - { - if ( bRecursive && !bFound && !aMarkData.IsAllMarked( aRefRange ) ) - bFound = sal_True; - aMarkData.SetMultiMarkArea( aRefRange, sal_True ); - } + ScDetectiveRefIter aRefIter(rVal.mpFormula); + ScRange aRefRange; + while ( aRefIter.GetNextRef( aRefRange) ) + { + if ( bRecursive && !bFound && !aMarkData.IsAllMarked( aRefRange ) ) + bFound = true; + aMarkData.SetMultiMarkArea(aRefRange, true); } - pCell = aIter.GetNext(); } } @@ -3928,33 +3915,32 @@ uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryDependen SCTAB nTab = lcl_FirstTab(aNewRanges); //! alle Tabellen ScCellIterator aCellIter( pDoc, 0,0, nTab, MAXCOL,MAXROW, nTab ); - ScBaseCell* pCell = aCellIter.GetFirst(); - while (pCell) + for (bool bHasCell = aCellIter.first(); bHasCell; bHasCell = aCellIter.next()) { - if (pCell->GetCellType() == CELLTYPE_FORMULA) + const ScCellValue& rVal = aCellIter.get(); + if (rVal.meType != CELLTYPE_FORMULA) + continue; + + bool bMark = false; + ScDetectiveRefIter aIter(rVal.mpFormula); + ScRange aRefRange; + while ( aIter.GetNextRef( aRefRange) ) { - sal_Bool bMark = false; - ScDetectiveRefIter aIter( (ScFormulaCell*) pCell ); - ScRange aRefRange; - while ( aIter.GetNextRef( aRefRange) ) - { - size_t nRangesCount = aNewRanges.size(); - for (size_t nR = 0; nR < nRangesCount; ++nR) - { - ScRange aRange( *aNewRanges[ nR ] ); - if (aRange.Intersects(aRefRange)) - bMark = sal_True; // von Teil des Ranges abhaengig - } - } - if (bMark) + size_t nRangesCount = aNewRanges.size(); + for (size_t nR = 0; nR < nRangesCount; ++nR) { - ScRange aCellRange(aCellIter.GetPos()); - if ( bRecursive && !bFound && !aMarkData.IsAllMarked( aCellRange ) ) - bFound = sal_True; - aMarkData.SetMultiMarkArea( aCellRange, sal_True ); + ScRange aRange( *aNewRanges[ nR ] ); + if (aRange.Intersects(aRefRange)) + bMark = sal_True; // von Teil des Ranges abhaengig } } - pCell = aCellIter.GetNext(); + if (bMark) + { + ScRange aCellRange(aCellIter.GetPos()); + if ( bRecursive && !bFound && !aMarkData.IsAllMarked( aCellRange ) ) + bFound = true; + aMarkData.SetMultiMarkArea(aCellRange, true); + } } aMarkData.FillRangeListWithMarks( &aNewRanges, sal_True ); commit 7543917981b0e9645389ea0dce44bedfc026d534 Author: Kohei Yoshida <kohei.yosh...@gmail.com> Date: Fri Mar 22 14:27:35 2013 -0400 Nobody uses CELLTYPE_SYMBOLS anymore. Chuck it away. Change-Id: I7b9b221c3536c94fbf56c9b5230e62927efe6e1f diff --git a/sc/inc/global.hxx b/sc/inc/global.hxx index b1dd688..26d8539 100644 --- a/sc/inc/global.hxx +++ b/sc/inc/global.hxx @@ -271,7 +271,6 @@ enum CellType CELLTYPE_FORMULA, CELLTYPE_NOTE, CELLTYPE_EDIT, - CELLTYPE_SYMBOLS // for load/save #if OSL_DEBUG_LEVEL > 0 ,CELLTYPE_DESTROYED #endif diff --git a/sc/source/core/data/autonamecache.cxx b/sc/source/core/data/autonamecache.cxx index f0e98dc..8a79864 100644 --- a/sc/source/core/data/autonamecache.cxx +++ b/sc/source/core/data/autonamecache.cxx @@ -75,7 +75,6 @@ const ScAutoNameAddresses& ScAutoNameCache::GetNameOccurrences( const String& rN case CELLTYPE_NONE: case CELLTYPE_VALUE: case CELLTYPE_NOTE: - case CELLTYPE_SYMBOLS: #if OSL_DEBUG_LEVEL > 0 case CELLTYPE_DESTROYED: #endif diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx index 9979aa3..828a250 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -3055,7 +3055,6 @@ bool ScCompiler::IsColRowName( const String& rName ) case CELLTYPE_NONE: case CELLTYPE_VALUE: case CELLTYPE_NOTE: - case CELLTYPE_SYMBOLS: #if OSL_DEBUG_LEVEL > 0 case CELLTYPE_DESTROYED: #endif @@ -3184,7 +3183,6 @@ bool ScCompiler::IsColRowName( const String& rName ) case CELLTYPE_NONE: case CELLTYPE_VALUE: case CELLTYPE_NOTE: - case CELLTYPE_SYMBOLS: #if OSL_DEBUG_LEVEL > 0 case CELLTYPE_DESTROYED: #endif diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx index d78efe6..752c595 100644 --- a/sc/source/core/tool/interpr4.cxx +++ b/sc/source/core/tool/interpr4.cxx @@ -531,7 +531,6 @@ double ScInterpreter::GetCellValueOrZero( const ScAddress& rPos, const ScBaseCel case CELLTYPE_NOTE: fValue = 0.0; // empty or broadcaster cell break; - case CELLTYPE_SYMBOLS: #if OSL_DEBUG_LEVEL > 0 case CELLTYPE_DESTROYED: #endif diff --git a/sc/source/ui/unoobj/chart2uno.cxx b/sc/source/ui/unoobj/chart2uno.cxx index fcb7121..8eed3b7 100644 --- a/sc/source/ui/unoobj/chart2uno.cxx +++ b/sc/source/ui/unoobj/chart2uno.cxx @@ -2626,7 +2626,6 @@ void ScChart2DataSequence::BuildDataCache() case CELLTYPE_NONE: case CELLTYPE_NOTE: case CELLTYPE_STRING: - case CELLTYPE_SYMBOLS: default: ; // do nothing } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits