summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2013-03-28 14:22:46 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2013-03-28 17:03:55 -0400
commit3d6a7391466cf259127a9c3a9cd40a86fb85b719 (patch)
tree2c6c14d0417d5cf9fda78f7899fdaf001348d81c /sc
parente5a625100497f1fae86a3b43454c9ce9a4c8dd2c (diff)
Remove GetCell() from ScDocument, and make PutCell() private.
At this point, only ScTable and ScFormulaCell call PutCell(). Make them friends of ScDocument (for now). Change-Id: I7b8795580eafe7ea0ba5a4325f531efe53a2ea5b
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/document.hxx10
-rw-r--r--sc/source/core/data/documen8.cxx30
-rw-r--r--sc/source/core/data/document.cxx173
3 files changed, 99 insertions, 114 deletions
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 840c7d12cace..d83f04468c63 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -215,6 +215,8 @@ friend class ScAttrRectIterator;
friend class ScDocShell;
friend class ScDocRowHeightUpdater;
friend class ScColumnTextWidthIterator;
+friend class ScFormulaCell;
+friend class ScTable;
typedef ::std::vector<ScTable*> TableContainer;
private:
@@ -743,9 +745,6 @@ public:
SC_DLLPUBLIC void EnsureTable( SCTAB nTab );
- SC_DLLPUBLIC void PutCell( const ScAddress&, ScBaseCell* pCell, bool bForceTab = false );
- SC_DLLPUBLIC void PutCell(SCCOL nCol, SCROW nRow, SCTAB nTab, ScBaseCell* pCell,
- sal_uLong nFormatIndex, bool bForceTab = false);
// return TRUE = number format is set
SC_DLLPUBLIC bool SetString(
SCCOL nCol, SCROW nRow, SCTAB nTab, const rtl::OUString& rString,
@@ -853,8 +852,6 @@ public:
SC_DLLPUBLIC void GetFormula( SCCOL nCol, SCROW nRow, SCTAB nTab, rtl::OUString& rFormula ) const;
SC_DLLPUBLIC void GetCellType( SCCOL nCol, SCROW nRow, SCTAB nTab, CellType& rCellType ) const;
SC_DLLPUBLIC CellType GetCellType( const ScAddress& rPos ) const;
- SC_DLLPUBLIC void GetCell( SCCOL nCol, SCROW nRow, SCTAB nTab, ScBaseCell*& rpCell ) const;
- SC_DLLPUBLIC ScBaseCell* GetCell( const ScAddress& rPos ) const;
SC_DLLPUBLIC bool HasData( SCCOL nCol, SCROW nRow, SCTAB nTab );
SC_DLLPUBLIC bool HasStringData( SCCOL nCol, SCROW nRow, SCTAB nTab ) const;
@@ -1976,6 +1973,9 @@ private: // CLOOK-Impl-methods
bool HasPartOfMerged( const ScRange& rRange );
+ void PutCell( const ScAddress&, ScBaseCell* pCell, bool bForceTab = false );
+ void PutCell(SCCOL nCol, SCROW nRow, SCTAB nTab, ScBaseCell* pCell, sal_uLong nFormatIndex, bool bForceTab = false );
+
std::map< SCTAB, ScSortParam > mSheetSortParams;
};
diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index 3dda38c104c5..5fe23dc5f75a 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -96,6 +96,7 @@
#define VSPL_START 0
#define VSPL_DONE 1
+using namespace com::sun::star;
// STATIC DATA -----------------------------------------------------------
@@ -1613,14 +1614,15 @@ void ScDocument::TransliterateText( const ScMarkData& rMultiMark, sal_Int32 nTyp
while (bFound)
{
- const ScBaseCell* pCell = GetCell( ScAddress( nCol, nRow, nTab ) );
- CellType eType = pCell ? pCell->GetCellType() : CELLTYPE_NONE;
+ ScRefCellValue aCell;
+ aCell.assign(*this, ScAddress(nCol, nRow, nTab));
+
// fdo#32786 TITLE_CASE/SENTENCE_CASE need the extra handling in EditEngine (loop over words/sentences).
// Still use TransliterationWrapper directly for text cells with other transliteration types,
// for performance reasons.
- if ( eType == CELLTYPE_EDIT ||
- ( eType == CELLTYPE_STRING && ( nType == com::sun::star::i18n::TransliterationModulesExtra::SENTENCE_CASE ||
- nType == com::sun::star::i18n::TransliterationModulesExtra::TITLE_CASE ) ) )
+ if (aCell.meType == CELLTYPE_EDIT ||
+ (aCell.meType == CELLTYPE_STRING &&
+ ( nType == i18n::TransliterationModulesExtra::SENTENCE_CASE || nType == i18n::TransliterationModulesExtra::TITLE_CASE)))
{
if (!pEngine)
pEngine = new ScFieldEditEngine(this, GetEnginePool(), GetEditPool());
@@ -1631,13 +1633,11 @@ void ScDocument::TransliterateText( const ScMarkData& rMultiMark, sal_Int32 nTyp
pPattern->FillEditItemSet( pDefaults );
pEngine->SetDefaults( pDefaults, true );
- if ( eType == CELLTYPE_STRING )
- pEngine->SetText( static_cast<const ScStringCell*>(pCell)->GetString() );
- else
- {
- const EditTextObject* pData = static_cast<const ScEditCell*>(pCell)->GetData();
- pEngine->SetText( *pData );
- }
+ if (aCell.meType == CELLTYPE_STRING)
+ pEngine->SetText(*aCell.mpString);
+ else if (aCell.mpEditText)
+ pEngine->SetText(*aCell.mpEditText);
+
pEngine->ClearModifyFlag();
sal_uInt16 nLastPar = pEngine->GetParagraphCount();
@@ -1669,9 +1669,9 @@ void ScDocument::TransliterateText( const ScMarkData& rMultiMark, sal_Int32 nTyp
}
}
- else if ( eType == CELLTYPE_STRING )
+ else if (aCell.meType == CELLTYPE_STRING)
{
- rtl::OUString aOldStr = ((const ScStringCell*)pCell)->GetString();
+ OUString aOldStr = *aCell.mpString;
sal_Int32 nOldLen = aOldStr.getLength();
if ( bConsiderLanguage )
@@ -1683,7 +1683,7 @@ void ScDocument::TransliterateText( const ScMarkData& rMultiMark, sal_Int32 nTyp
nLanguage = ((const SvxLanguageItem*)GetAttr( nCol, nRow, nTab, nWhich ))->GetValue();
}
- com::sun::star::uno::Sequence<sal_Int32> aOffsets;
+ uno::Sequence<sal_Int32> aOffsets;
rtl::OUString aNewStr = aTranslitarationWrapper.transliterate( aOldStr, nLanguage, 0, nOldLen, &aOffsets );
if ( aNewStr != aOldStr )
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 0d82eb698f3a..9aa8e6a3bfae 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -3090,49 +3090,52 @@ sal_uInt16 ScDocument::GetStringForFormula( const ScAddress& rPos, OUString& rSt
// ScInterpreter::GetCellString: always format values as numbers.
// The return value is the error code.
- sal_uInt16 nErr = 0;
- String aStr;
- ScBaseCell* pCell = GetCell( rPos );
- if (pCell)
+ ScRefCellValue aCell;
+ aCell.assign(*this, rPos);
+ if (aCell.isEmpty())
{
- SvNumberFormatter* pFormatter = GetFormatTable();
- switch (pCell->GetCellType())
+ rString = EMPTY_OUSTRING;
+ return 0;
+ }
+
+ sal_uInt16 nErr = 0;
+ OUString aStr;
+ SvNumberFormatter* pFormatter = GetFormatTable();
+ switch (aCell.meType)
+ {
+ case CELLTYPE_STRING:
+ case CELLTYPE_EDIT:
+ aStr = aCell.getString();
+ break;
+ case CELLTYPE_FORMULA:
{
- case CELLTYPE_STRING:
- aStr = static_cast<ScStringCell*>(pCell)->GetString();
- break;
- case CELLTYPE_EDIT:
- aStr = static_cast<ScEditCell*>(pCell)->GetString();
- break;
- case CELLTYPE_FORMULA:
+ ScFormulaCell* pFCell = aCell.mpFormula;
+ nErr = pFCell->GetErrCode();
+ if (pFCell->IsValue())
{
- ScFormulaCell* pFCell = static_cast<ScFormulaCell*>(pCell);
- nErr = pFCell->GetErrCode();
- if (pFCell->IsValue())
- {
- double fVal = pFCell->GetValue();
- sal_uInt32 nIndex = pFormatter->GetStandardFormat(
- NUMBERFORMAT_NUMBER,
- ScGlobal::eLnge);
- pFormatter->GetInputLineString(fVal, nIndex, aStr);
- }
- else
- aStr = pFCell->GetString();
- }
- break;
- case CELLTYPE_VALUE:
- {
- double fVal = static_cast<ScValueCell*>(pCell)->GetValue();
+ double fVal = pFCell->GetValue();
sal_uInt32 nIndex = pFormatter->GetStandardFormat(
- NUMBERFORMAT_NUMBER,
- ScGlobal::eLnge);
+ NUMBERFORMAT_NUMBER,
+ ScGlobal::eLnge);
pFormatter->GetInputLineString(fVal, nIndex, aStr);
}
- break;
- default:
- ;
+ else
+ aStr = pFCell->GetString();
+ }
+ break;
+ case CELLTYPE_VALUE:
+ {
+ double fVal = aCell.mfValue;
+ sal_uInt32 nIndex = pFormatter->GetStandardFormat(
+ NUMBERFORMAT_NUMBER,
+ ScGlobal::eLnge);
+ pFormatter->GetInputLineString(fVal, nIndex, aStr);
}
+ break;
+ default:
+ ;
}
+
rString = aStr;
return nErr;
}
@@ -3305,30 +3308,6 @@ void ScDocument::GetCellType( SCCOL nCol, SCROW nRow, SCTAB nTab,
rCellType = CELLTYPE_NONE;
}
-
-void ScDocument::GetCell( SCCOL nCol, SCROW nRow, SCTAB nTab,
- ScBaseCell*& rpCell ) const
-{
- if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
- rpCell = maTabs[nTab]->GetCell( nCol, nRow );
- else
- {
- OSL_FAIL("GetCell without a table");
- rpCell = NULL;
- }
-}
-
-
-ScBaseCell* ScDocument::GetCell( const ScAddress& rPos ) const
-{
- SCTAB nTab = rPos.Tab();
- if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
- return maTabs[nTab]->GetCell( rPos );
-
- OSL_FAIL("GetCell without a table");
- return NULL;
-}
-
bool ScDocument::HasStringData( SCCOL nCol, SCROW nRow, SCTAB nTab ) const
{
if ( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] )
@@ -5004,44 +4983,50 @@ bool ScDocument::GetMatrixFormulaRange( const ScAddress& rCellPos, ScRange& rMat
{
// if rCell is part of a matrix formula, return its complete range
- bool bRet = false;
- ScBaseCell* pCell = GetCell( rCellPos );
- if (pCell && pCell->GetCellType() == CELLTYPE_FORMULA)
+ ScFormulaCell* pFCell = GetFormulaCell(rCellPos);
+ if (!pFCell)
+ // not a formula cell. Bail out.
+ return false;
+
+ ScAddress aOrigin = rCellPos;
+ if (!pFCell->GetMatrixOrigin(aOrigin))
+ // Failed to get the address of the matrix origin.
+ return false;
+
+ if (aOrigin != rCellPos)
{
- ScAddress aOrigin = rCellPos;
- if ( ((ScFormulaCell*)pCell)->GetMatrixOrigin( aOrigin ) )
- {
- if ( aOrigin != rCellPos )
- pCell = GetCell( aOrigin );
- if (pCell && pCell->GetCellType() == CELLTYPE_FORMULA)
- {
- SCCOL nSizeX;
- SCROW nSizeY;
- ((ScFormulaCell*)pCell)->GetMatColsRows(nSizeX,nSizeY);
- if ( !(nSizeX > 0 && nSizeY > 0) )
- {
- // GetMatrixEdge computes also dimensions of the matrix
- // if not already done (may occur if document is loaded
- // from old file format).
- // Needs an "invalid" initialized address.
- aOrigin.SetInvalid();
- ((ScFormulaCell*)pCell)->GetMatrixEdge(aOrigin);
- ((ScFormulaCell*)pCell)->GetMatColsRows(nSizeX,nSizeY);
- }
- if ( nSizeX > 0 && nSizeY > 0 )
- {
- ScAddress aEnd( aOrigin.Col() + nSizeX - 1,
- aOrigin.Row() + nSizeY - 1,
- aOrigin.Tab() );
+ pFCell = GetFormulaCell(aOrigin);
+ if (!pFCell)
+ // The matrix origin cell is not a formula cell !? Something is up...
+ return false;
+ }
- rMatrix.aStart = aOrigin;
- rMatrix.aEnd = aEnd;
- bRet = true;
- }
- }
- }
+ SCCOL nSizeX;
+ SCROW nSizeY;
+ pFCell->GetMatColsRows(nSizeX, nSizeY);
+ if (nSizeX <= 0 || nSizeY <= 0)
+ {
+ // GetMatrixEdge computes also dimensions of the matrix
+ // if not already done (may occur if document is loaded
+ // from old file format).
+ // Needs an "invalid" initialized address.
+ aOrigin.SetInvalid();
+ pFCell->GetMatrixEdge(aOrigin);
+ pFCell->GetMatColsRows(nSizeX, nSizeY);
}
- return bRet;
+
+ if (nSizeX <= 0 || nSizeY <= 0)
+ // Matrix size is still invalid. Give up.
+ return false;
+
+ ScAddress aEnd( aOrigin.Col() + nSizeX - 1,
+ aOrigin.Row() + nSizeY - 1,
+ aOrigin.Tab() );
+
+ rMatrix.aStart = aOrigin;
+ rMatrix.aEnd = aEnd;
+
+ return true;
}