Kaydet (Commit) 5f5d2cb6 authored tarafından Kohei Yoshida's avatar Kohei Yoshida

Make the conditional formatting code free of ScBaseCell.

Change-Id: I93f83a840874c973cdc0821ddeb1913be7f09767
üst 7c2dd80c
...@@ -80,9 +80,10 @@ struct SC_DLLPUBLIC ScCellValue ...@@ -80,9 +80,10 @@ struct SC_DLLPUBLIC ScCellValue
}; };
/** /**
* This is very similar to ScCellValue, except that it points to the * This is very similar to ScCellValue, except that it references the
* original value instead of copying it. As such, don't hold an instance of * original value instead of copying it. As such, don't hold an instance of
* this class any longer than necessary. * this class any longer than necessary, and absolutely not after the
* original cell has been destroyed.
*/ */
struct SC_DLLPUBLIC ScRefCellValue struct SC_DLLPUBLIC ScRefCellValue
{ {
......
...@@ -35,10 +35,9 @@ ...@@ -35,10 +35,9 @@
#include <boost/ptr_container/ptr_vector.hpp> #include <boost/ptr_container/ptr_vector.hpp>
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
class ScBaseCell;
class ScFormulaCell; class ScFormulaCell;
class ScTokenArray; class ScTokenArray;
class ScRefCellValue;
// nOptions Flags // nOptions Flags
#define SC_COND_NOBLANKS 1 #define SC_COND_NOBLANKS 1
...@@ -196,7 +195,7 @@ public: ...@@ -196,7 +195,7 @@ public:
virtual void SetParent( ScConditionalFormat* pNew ) { pCondFormat = pNew; } virtual void SetParent( ScConditionalFormat* pNew ) { pCondFormat = pNew; }
bool IsCellValid( ScBaseCell* pCell, const ScAddress& rPos ) const; bool IsCellValid( ScRefCellValue& rCell, const ScAddress& rPos ) const;
ScConditionMode GetOperation() const { return eOp; } ScConditionMode GetOperation() const { return eOp; }
bool IsIgnoreBlank() const { return ( nOptions & SC_COND_NOBLANKS ) == 0; } bool IsIgnoreBlank() const { return ( nOptions & SC_COND_NOBLANKS ) == 0; }
...@@ -406,9 +405,9 @@ public: ...@@ -406,9 +405,9 @@ public:
const ScFormatEntry* GetEntry( sal_uInt16 nPos ) const; const ScFormatEntry* GetEntry( sal_uInt16 nPos ) const;
const rtl::OUString& GetCellStyle( ScBaseCell* pCell, const ScAddress& rPos ) const; const OUString& GetCellStyle( ScRefCellValue& rCell, const ScAddress& rPos ) const;
ScCondFormatData GetData( ScBaseCell* pCell, const ScAddress& rPos ) const; ScCondFormatData GetData( ScRefCellValue& rCell, const ScAddress& rPos ) const;
bool EqualEntries( const ScConditionalFormat& r ) const; bool EqualEntries( const ScConditionalFormat& r ) const;
......
...@@ -125,12 +125,11 @@ public: ...@@ -125,12 +125,11 @@ public:
@return true = rStrings has been filled with at least one entry. */ @return true = rStrings has been filled with at least one entry. */
bool FillSelectionList(std::vector<ScTypedStrData>& rStrings, const ScAddress& rPos) const; bool FillSelectionList(std::vector<ScTypedStrData>& rStrings, const ScAddress& rPos) const;
// with string: during input, with cell: for detective / RC_FORCED // with string: during input, with cell: for detective / RC_FORCED
sal_Bool IsDataValid( const String& rTest, const ScPatternAttr& rPattern, bool IsDataValid(
const ScAddress& rPos ) const; const OUString& rTest, const ScPatternAttr& rPattern, const ScAddress& rPos ) const;
sal_Bool IsDataValid( ScBaseCell* pCell, const ScAddress& rPos ) const;
bool IsDataValid( ScCellIterator& rIter ) const; bool IsDataValid( ScRefCellValue& rCell, const ScAddress& rPos ) const;
// TRUE -> break // TRUE -> break
sal_Bool DoError( Window* pParent, const String& rInput, const ScAddress& rPos ) const; sal_Bool DoError( Window* pParent, const String& rInput, const ScAddress& rPos ) const;
...@@ -160,14 +159,14 @@ private: ...@@ -160,14 +159,14 @@ private:
@param rMatch (out-param) the index of the first item that matched, -1 if nothing matched. @param rMatch (out-param) the index of the first item that matched, -1 if nothing matched.
@return true = Cell range found, rRange is valid, or an error entry stuffed into the list if pCell==NULL. */ @return true = Cell range found, rRange is valid, or an error entry stuffed into the list if pCell==NULL. */
bool GetSelectionFromFormula( bool GetSelectionFromFormula(
std::vector<ScTypedStrData>* pStrings, ScBaseCell* pCell, const ScAddress& rPos, std::vector<ScTypedStrData>* pStrings, ScRefCellValue& rCell, const ScAddress& rPos,
const ScTokenArray& rTokArr, int& rMatch) const; const ScTokenArray& rTokArr, int& rMatch) const;
/** Tests, if pCell is equal to what the passed token array represents. */ /** Tests, if pCell is equal to what the passed token array represents. */
bool IsEqualToTokenArray( ScBaseCell* pCell, const ScAddress& rPos, const ScTokenArray& rTokArr ) const; bool IsEqualToTokenArray( ScRefCellValue& rCell, const ScAddress& rPos, const ScTokenArray& rTokArr ) const;
/** Tests, if contents of pCell occur in cell range referenced by own formula, or in a string list. */ /** Tests, if contents of pCell occur in cell range referenced by own formula, or in a string list. */
bool IsListValid( ScBaseCell* pCell, const ScAddress& rPos ) const; bool IsListValid( ScRefCellValue& rCell, const ScAddress& rPos ) const;
}; };
// //
......
...@@ -1688,7 +1688,8 @@ void ScFormulaCell::InterpretTail( ScInterpretTailParameter eTailParam ) ...@@ -1688,7 +1688,8 @@ void ScFormulaCell::InterpretTail( ScInterpretTailParameter eTailParam )
if ( nValidation ) if ( nValidation )
{ {
const ScValidationData* pData = pDocument->GetValidationEntry( nValidation ); const ScValidationData* pData = pDocument->GetValidationEntry( nValidation );
if ( pData && !pData->IsDataValid( this, aPos ) ) ScRefCellValue aTmpCell(this);
if ( pData && !pData->IsDataValid(aTmpCell, aPos))
pData->DoCalcError( this ); pData->DoCalcError( this );
} }
} }
......
...@@ -36,6 +36,8 @@ ...@@ -36,6 +36,8 @@
#include "stlpool.hxx" #include "stlpool.hxx"
#include "rangenam.hxx" #include "rangenam.hxx"
#include "colorscale.hxx" #include "colorscale.hxx"
#include "cellvalue.hxx"
#include "editutil.hxx"
using namespace formula; using namespace formula;
//------------------------------------------------------------------------ //------------------------------------------------------------------------
...@@ -731,47 +733,40 @@ void ScConditionEntry::Interpret( const ScAddress& rPos ) ...@@ -731,47 +733,40 @@ void ScConditionEntry::Interpret( const ScAddress& rPos )
bFirstRun = false; bFirstRun = false;
} }
static bool lcl_GetCellContent( ScBaseCell* pCell, bool bIsStr1, double& rArg, rtl::OUString& rArgStr ) static bool lcl_GetCellContent( ScRefCellValue& rCell, bool bIsStr1, double& rArg, OUString& rArgStr )
{ {
if (rCell.isEmpty())
return !bIsStr1;
bool bVal = true; bool bVal = true;
if ( pCell ) switch (rCell.meType)
{ {
CellType eType = pCell->GetCellType(); case CELLTYPE_VALUE:
switch( eType ) rArg = rCell.mfValue;
break;
case CELLTYPE_FORMULA:
{ {
case CELLTYPE_VALUE: bVal = rCell.mpFormula->IsValue();
rArg = ((ScValueCell*)pCell)->GetValue(); if (bVal)
break; rArg = rCell.mpFormula->GetValue();
case CELLTYPE_FORMULA: else
{ rArgStr = rCell.mpFormula->GetString();
ScFormulaCell* pFCell = (ScFormulaCell*)pCell;
bVal = pFCell->IsValue();
if (bVal)
rArg = pFCell->GetValue();
else
rArgStr = pFCell->GetString();
}
break;
case CELLTYPE_STRING:
case CELLTYPE_EDIT:
bVal = false;
if ( eType == CELLTYPE_STRING )
rArgStr = ((ScStringCell*)pCell)->GetString();
else
rArgStr = ((ScEditCell*)pCell)->GetString();
break;
default:
pCell = NULL; // Note-Zellen wie leere
break;
} }
break;
case CELLTYPE_STRING:
case CELLTYPE_EDIT:
bVal = false;
if (rCell.meType == CELLTYPE_STRING)
rArgStr = *rCell.mpString;
else if (rCell.mpEditText)
rArgStr = ScEditUtil::GetString(*rCell.mpEditText);
break;
default:
;
} }
if( !pCell )
if( bIsStr1 )
bVal = false; // leere Zellen je nach Bedingung
return bVal; return bVal;
} }
...@@ -803,23 +798,28 @@ void ScConditionEntry::FillCache() const ...@@ -803,23 +798,28 @@ void ScConditionEntry::FillCache() const
for( SCROW r = nRowStart; r <= nRow; r++ ) for( SCROW r = nRowStart; r <= nRow; r++ )
for( SCCOL c = nColStart; c <= nCol; c++ ) for( SCCOL c = nColStart; c <= nCol; c++ )
{ {
double nVal = 0.0; ScRefCellValue aCell;
ScBaseCell *pCell = NULL; aCell.assign(*mpDoc, ScAddress(c, r, nTab));
if (aCell.isEmpty())
mpDoc->GetCell( c, r, nTab, pCell );
if( !pCell )
continue; continue;
rtl::OUString aStr; double nVal = 0.0;
if( !lcl_GetCellContent( pCell, false, nVal, aStr ) ) OUString aStr;
if (!lcl_GetCellContent(aCell, false, nVal, aStr))
{ {
std::pair<ScConditionEntryCache::StringCacheType::iterator, bool> aResult = mpCache->maStrings.insert(std::pair<rtl::OUString, sal_Int32>(aStr, static_cast<sal_Int32>(1))); std::pair<ScConditionEntryCache::StringCacheType::iterator, bool> aResult =
mpCache->maStrings.insert(
ScConditionEntryCache::StringCacheType::value_type(aStr, 1));
if(!aResult.second) if(!aResult.second)
aResult.first->second++; aResult.first->second++;
} }
else else
{ {
std::pair<ScConditionEntryCache::ValueCacheType::iterator, bool> aResult = mpCache->maValues.insert(std::pair<double, sal_Int32>(nVal, (sal_Int32)1)); std::pair<ScConditionEntryCache::ValueCacheType::iterator, bool> aResult =
mpCache->maValues.insert(
ScConditionEntryCache::ValueCacheType::value_type(nVal, 1));
if(!aResult.second) if(!aResult.second)
aResult.first->second++; aResult.first->second++;
...@@ -978,17 +978,13 @@ bool ScConditionEntry::IsAboveAverage( double nArg, bool bEqual ) const ...@@ -978,17 +978,13 @@ bool ScConditionEntry::IsAboveAverage( double nArg, bool bEqual ) const
bool ScConditionEntry::IsError( const ScAddress& rPos ) const bool ScConditionEntry::IsError( const ScAddress& rPos ) const
{ {
ScBaseCell* pCell = mpDoc->GetCell(rPos); switch (mpDoc->GetCellType(rPos))
if(!pCell)
return false;
switch(pCell->GetCellType())
{ {
case CELLTYPE_VALUE: case CELLTYPE_VALUE:
return false; return false;
case CELLTYPE_FORMULA: case CELLTYPE_FORMULA:
{ {
ScFormulaCell* pFormulaCell = static_cast<ScFormulaCell*>(pCell); ScFormulaCell* pFormulaCell = const_cast<ScFormulaCell*>(mpDoc->GetFormulaCell(rPos));
if(pFormulaCell->GetErrCode()) if(pFormulaCell->GetErrCode())
return true; return true;
} }
...@@ -1267,13 +1263,13 @@ bool ScConditionEntry::IsValidStr( const rtl::OUString& rArg, const ScAddress& r ...@@ -1267,13 +1263,13 @@ bool ScConditionEntry::IsValidStr( const rtl::OUString& rArg, const ScAddress& r
return bValid; return bValid;
} }
bool ScConditionEntry::IsCellValid( ScBaseCell* pCell, const ScAddress& rPos ) const bool ScConditionEntry::IsCellValid( ScRefCellValue& rCell, const ScAddress& rPos ) const
{ {
((ScConditionEntry*)this)->Interpret(rPos); // Formeln auswerten ((ScConditionEntry*)this)->Interpret(rPos); // Formeln auswerten
double nArg = 0.0; double nArg = 0.0;
rtl::OUString aArgStr; rtl::OUString aArgStr;
bool bVal = lcl_GetCellContent( pCell, bIsStr1, nArg, aArgStr ); bool bVal = lcl_GetCellContent( rCell, bIsStr1, nArg, aArgStr );
if (bVal) if (bVal)
return IsValid( nArg, rPos ); return IsValid( nArg, rPos );
else else
...@@ -1651,12 +1647,14 @@ ScCondDateFormatEntry::ScCondDateFormatEntry( ScDocument* pDoc, const ScCondDate ...@@ -1651,12 +1647,14 @@ ScCondDateFormatEntry::ScCondDateFormatEntry( ScDocument* pDoc, const ScCondDate
bool ScCondDateFormatEntry::IsValid( const ScAddress& rPos ) const bool ScCondDateFormatEntry::IsValid( const ScAddress& rPos ) const
{ {
ScBaseCell* pBaseCell = mpDoc->GetCell( rPos ); CellType eCellType = mpDoc->GetCellType(rPos);
if(!pBaseCell) if (eCellType == CELLTYPE_NONE || eCellType == CELLTYPE_NOTE)
// empty cell.
return false; return false;
if(pBaseCell->GetCellType() != CELLTYPE_VALUE && pBaseCell->GetCellType() != CELLTYPE_FORMULA) if (eCellType != CELLTYPE_VALUE && eCellType != CELLTYPE_FORMULA)
// non-numerical cell.
return false; return false;
if( !mpCache ) if( !mpCache )
...@@ -1903,14 +1901,14 @@ const ScFormatEntry* ScConditionalFormat::GetEntry( sal_uInt16 nPos ) const ...@@ -1903,14 +1901,14 @@ const ScFormatEntry* ScConditionalFormat::GetEntry( sal_uInt16 nPos ) const
return NULL; return NULL;
} }
const rtl::OUString& ScConditionalFormat::GetCellStyle( ScBaseCell* pCell, const ScAddress& rPos ) const const OUString& ScConditionalFormat::GetCellStyle( ScRefCellValue& rCell, const ScAddress& rPos ) const
{ {
for (CondFormatContainer::const_iterator itr = maEntries.begin(); itr != maEntries.end(); ++itr) for (CondFormatContainer::const_iterator itr = maEntries.begin(); itr != maEntries.end(); ++itr)
{ {
if(itr->GetType() == condformat::CONDITION) if(itr->GetType() == condformat::CONDITION)
{ {
const ScCondFormatEntry& rEntry = static_cast<const ScCondFormatEntry&>(*itr); const ScCondFormatEntry& rEntry = static_cast<const ScCondFormatEntry&>(*itr);
if ( rEntry.IsCellValid( pCell, rPos ) ) if (rEntry.IsCellValid(rCell, rPos))
return rEntry.GetStyle(); return rEntry.GetStyle();
} }
else if(itr->GetType() == condformat::DATE) else if(itr->GetType() == condformat::DATE)
...@@ -1924,7 +1922,7 @@ const rtl::OUString& ScConditionalFormat::GetCellStyle( ScBaseCell* pCell, const ...@@ -1924,7 +1922,7 @@ const rtl::OUString& ScConditionalFormat::GetCellStyle( ScBaseCell* pCell, const
return EMPTY_OUSTRING; return EMPTY_OUSTRING;
} }
ScCondFormatData ScConditionalFormat::GetData( ScBaseCell* pCell, const ScAddress& rPos ) const ScCondFormatData ScConditionalFormat::GetData( ScRefCellValue& rCell, const ScAddress& rPos ) const
{ {
ScCondFormatData aData; ScCondFormatData aData;
for(CondFormatContainer::const_iterator itr = maEntries.begin(); itr != maEntries.end(); ++itr) for(CondFormatContainer::const_iterator itr = maEntries.begin(); itr != maEntries.end(); ++itr)
...@@ -1932,7 +1930,7 @@ ScCondFormatData ScConditionalFormat::GetData( ScBaseCell* pCell, const ScAddres ...@@ -1932,7 +1930,7 @@ ScCondFormatData ScConditionalFormat::GetData( ScBaseCell* pCell, const ScAddres
if(itr->GetType() == condformat::CONDITION && aData.aStyleName.isEmpty()) if(itr->GetType() == condformat::CONDITION && aData.aStyleName.isEmpty())
{ {
const ScCondFormatEntry& rEntry = static_cast<const ScCondFormatEntry&>(*itr); const ScCondFormatEntry& rEntry = static_cast<const ScCondFormatEntry&>(*itr);
if ( rEntry.IsCellValid( pCell, rPos ) ) if (rEntry.IsCellValid(rCell, rPos))
aData.aStyleName = rEntry.GetStyle(); aData.aStyleName = rEntry.GetStyle();
} }
else if(itr->GetType() == condformat::COLORSCALE && !aData.pColorScale) else if(itr->GetType() == condformat::COLORSCALE && !aData.pColorScale)
......
...@@ -631,8 +631,10 @@ const SfxPoolItem* ScDocument::GetEffItem( ...@@ -631,8 +631,10 @@ const SfxPoolItem* ScDocument::GetEffItem(
const ScConditionalFormat* pForm = pCondFormList->GetFormat( *itr ); const ScConditionalFormat* pForm = pCondFormList->GetFormat( *itr );
if ( pForm ) if ( pForm )
{ {
ScBaseCell* pCell = ((ScDocument*)this)->GetCell(ScAddress(nCol,nRow,nTab)); ScAddress aPos(nCol, nRow, nTab);
rtl::OUString aStyle = pForm->GetCellStyle( pCell, ScAddress(nCol, nRow, nTab) ); ScRefCellValue aCell;
aCell.assign(const_cast<ScDocument&>(*this), aPos);
rtl::OUString aStyle = pForm->GetCellStyle(aCell, aPos);
if (!aStyle.isEmpty()) if (!aStyle.isEmpty())
{ {
SfxStyleSheetBase* pStyleSheet = xPoolHelper->GetStylePool()->Find( SfxStyleSheetBase* pStyleSheet = xPoolHelper->GetStylePool()->Find(
...@@ -663,8 +665,10 @@ const SfxItemSet* ScDocument::GetCondResult( SCCOL nCol, SCROW nRow, SCTAB nTab ...@@ -663,8 +665,10 @@ const SfxItemSet* ScDocument::GetCondResult( SCCOL nCol, SCROW nRow, SCTAB nTab
if(!pForm) if(!pForm)
continue; continue;
ScBaseCell* pCell = ((ScDocument*)this)->GetCell(ScAddress(nCol,nRow,nTab)); ScAddress aPos(nCol, nRow, nTab);
rtl::OUString aStyle = pForm->GetCellStyle( pCell, ScAddress(nCol, nRow, nTab) ); ScRefCellValue aCell;
aCell.assign(const_cast<ScDocument&>(*this), aPos);
const OUString& aStyle = pForm->GetCellStyle(aCell, aPos);
if (!aStyle.isEmpty()) if (!aStyle.isEmpty())
{ {
SfxStyleSheetBase* pStyleSheet = xPoolHelper->GetStylePool()->Find( aStyle, SFX_STYLE_FAMILY_PARA ); SfxStyleSheetBase* pStyleSheet = xPoolHelper->GetStylePool()->Find( aStyle, SFX_STYLE_FAMILY_PARA );
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include "conditio.hxx" #include "conditio.hxx"
#include "colorscale.hxx" #include "colorscale.hxx"
#include "stlpool.hxx" #include "stlpool.hxx"
#include "cellvalue.hxx"
#include <iostream> #include <iostream>
...@@ -520,8 +521,11 @@ void ScDocument::FillInfo( ScTableInfo& rTabInfo, SCCOL nX1, SCROW nY1, SCCOL nX ...@@ -520,8 +521,11 @@ void ScDocument::FillInfo( ScTableInfo& rTabInfo, SCCOL nX1, SCROW nY1, SCCOL nX
if(!pCondForm) if(!pCondForm)
continue; continue;
ScCondFormatData aData = pCondForm->GetData( pInfo->pCell, ScRefCellValue aTmpCell;
ScAddress( nX, nCurRow, nTab ) ); if (pInfo->pCell)
aTmpCell.assign(*pInfo->pCell);
ScCondFormatData aData = pCondForm->GetData(
aTmpCell, ScAddress(nX, nCurRow, nTab));
if (!aData.aStyleName.isEmpty()) if (!aData.aStyleName.isEmpty())
{ {
SfxStyleSheetBase* pStyleSheet = SfxStyleSheetBase* pStyleSheet =
......
This diff is collapsed.
...@@ -1366,7 +1366,8 @@ sal_Bool ScDetectiveFunc::MarkInvalid(sal_Bool& rOverflow) ...@@ -1366,7 +1366,8 @@ sal_Bool ScDetectiveFunc::MarkInvalid(sal_Bool& rOverflow)
DrawCircle( nCol, nRow, aData ); DrawCircle( nCol, nRow, aData );
++nInsCount; ++nInsCount;
} }
if (!pData->IsDataValid(aCellIter)) ScRefCellValue aCell = aCellIter.getRefCellValue();
if (!pData->IsDataValid(aCell, aCellIter.GetPos()))
{ {
DrawCircle( nCol, nCellRow, aData ); DrawCircle( nCol, nCellRow, aData );
++nInsCount; ++nInsCount;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment