diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-05-24 11:52:18 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-06-24 16:51:25 -0400 |
commit | c008dc483f8c6840803983e7e351cec6fdd32070 (patch) | |
tree | 7c88eeabde57ea4a3c1a760d1c02ea2fd37bd721 /sc/source/core/data/cellvalue.cxx | |
parent | 75dec25730c88bdb8eb5e2a3f92689460fa89d29 (diff) |
Switch to using multi_type_vector for cell storage.
The old style cell storage is no more. Currently the code is buildable,
but crashes during unit test.
Change-Id: Ie688e22e95c7fb02b9e97b23df0fc1883a97945f
Diffstat (limited to 'sc/source/core/data/cellvalue.cxx')
-rw-r--r-- | sc/source/core/data/cellvalue.cxx | 151 |
1 files changed, 109 insertions, 42 deletions
diff --git a/sc/source/core/data/cellvalue.cxx b/sc/source/core/data/cellvalue.cxx index 75362ba7bfc2..169d2f7ef6d7 100644 --- a/sc/source/core/data/cellvalue.cxx +++ b/sc/source/core/data/cellvalue.cxx @@ -9,6 +9,7 @@ #include "cellvalue.hxx" #include "document.hxx" +#include "column.hxx" #include "cell.hxx" #include "formulacell.hxx" #include "editeng/editobj.hxx" @@ -182,6 +183,41 @@ void ScCellValue::clear() mfValue = 0.0; } +void ScCellValue::set( double fValue ) +{ + clear(); + meType = CELLTYPE_VALUE; + mfValue = fValue; +} + +void ScCellValue::set( const OUString& rStr ) +{ + clear(); + meType = CELLTYPE_STRING; + mpString = new OUString(rStr); +} + +void ScCellValue::set( const EditTextObject& rEditText ) +{ + clear(); + meType = CELLTYPE_EDIT; + mpEditText = rEditText.Clone(); +} + +void ScCellValue::set( const ScFormulaCell& rFormula ) +{ + clear(); + meType = CELLTYPE_FORMULA; + mpFormula = rFormula.Clone(); +} + +void ScCellValue::set( ScFormulaCell* pFormula ) +{ + clear(); + meType = CELLTYPE_FORMULA; + mpFormula = pFormula; +} + void ScCellValue::assign( const ScDocument& rDoc, const ScAddress& rPos ) { clear(); @@ -255,85 +291,87 @@ void ScCellValue::assign( const ScCellValue& rOther, ScDocument& rDestDoc, int n } } -void ScCellValue::assign( const ScBaseCell& rCell ) +void ScCellValue::commit( ScDocument& rDoc, const ScAddress& rPos ) const { - clear(); - - meType = rCell.GetCellType(); switch (meType) { case CELLTYPE_STRING: - mpString = new OUString(static_cast<const ScStringCell&>(rCell).GetString()); - break; - case CELLTYPE_EDIT: { - const EditTextObject* p = static_cast<const ScEditCell&>(rCell).GetData(); - if (p) - mpEditText = p->Clone(); + ScSetStringParam aParam; + aParam.setTextInput(); + rDoc.SetString(rPos, *mpString, &aParam); } break; + case CELLTYPE_EDIT: + rDoc.SetEditText(rPos, mpEditText->Clone()); + break; case CELLTYPE_VALUE: - mfValue = static_cast<const ScValueCell&>(rCell).GetValue(); + rDoc.SetValue(rPos, mfValue); break; case CELLTYPE_FORMULA: - mpFormula = static_cast<const ScFormulaCell&>(rCell).Clone(); + rDoc.SetFormulaCell(rPos, mpFormula->Clone()); break; default: - meType = CELLTYPE_NONE; // reset to empty. + rDoc.SetEmptyCell(rPos); } } -void ScCellValue::commit( ScDocument& rDoc, const ScAddress& rPos ) const +void ScCellValue::release( ScDocument& rDoc, const ScAddress& rPos ) { switch (meType) { case CELLTYPE_STRING: { + // Currently, string cannot be placed without copying. ScSetStringParam aParam; aParam.setTextInput(); rDoc.SetString(rPos, *mpString, &aParam); + delete mpString; } break; case CELLTYPE_EDIT: - rDoc.SetEditText(rPos, mpEditText->Clone()); + // Cell takes the ownership of the text object. + rDoc.SetEditText(rPos, mpEditText); break; case CELLTYPE_VALUE: rDoc.SetValue(rPos, mfValue); break; case CELLTYPE_FORMULA: - rDoc.SetFormulaCell(rPos, mpFormula->Clone()); + // This formula cell instance is directly placed in the document without copying. + rDoc.SetFormulaCell(rPos, mpFormula); break; default: rDoc.SetEmptyCell(rPos); } + + meType = CELLTYPE_NONE; + mfValue = 0.0; } -void ScCellValue::release( ScDocument& rDoc, const ScAddress& rPos ) +void ScCellValue::release( ScColumn& rColumn, SCROW nRow ) { switch (meType) { case CELLTYPE_STRING: { // Currently, string cannot be placed without copying. - ScSetStringParam aParam; - aParam.setTextInput(); - rDoc.SetString(rPos, *mpString, &aParam); + rColumn.SetRawString(nRow, *mpString); delete mpString; } break; case CELLTYPE_EDIT: // Cell takes the ownership of the text object. - rDoc.SetEditText(rPos, mpEditText); + rColumn.SetEditText(nRow, mpEditText); break; case CELLTYPE_VALUE: - rDoc.SetValue(rPos, mfValue); + rColumn.SetValue(nRow, mfValue); break; case CELLTYPE_FORMULA: // This formula cell instance is directly placed in the document without copying. - rDoc.SetFormulaCell(rPos, mpFormula); + rColumn.SetFormulaCell(nRow, mpFormula); break; default: - rDoc.SetEmptyCell(rPos); + rColumn.Delete(nRow); } meType = CELLTYPE_NONE; @@ -403,52 +441,81 @@ void ScRefCellValue::assign( ScDocument& rDoc, const ScAddress& rPos ) *this = rDoc.GetRefCellValue(rPos); } -void ScRefCellValue::assign( ScBaseCell& rCell ) +void ScRefCellValue::assign( const sc::CellStoreType::const_iterator& itPos, size_t nOffset ) { - clear(); + switch (itPos->type) + { + case sc::element_type_numeric: + // Numeric cell + mfValue = sc::numeric_block::at(*itPos->data, nOffset); + meType = CELLTYPE_VALUE; + break; + case sc::element_type_string: + // String cell + mpString = &sc::string_block::at(*itPos->data, nOffset); + meType = CELLTYPE_STRING; + break; + case sc::element_type_edittext: + // Edit cell + mpEditText = sc::edittext_block::at(*itPos->data, nOffset); + meType = CELLTYPE_EDIT; + break; + case sc::element_type_formula: + // Formula cell + mpFormula = sc::formula_block::at(*itPos->data, nOffset); + meType = CELLTYPE_FORMULA; + break; + default: + clear(); + } +} - meType = rCell.GetCellType(); +void ScRefCellValue::commit( ScDocument& rDoc, const ScAddress& rPos ) const +{ switch (meType) { case CELLTYPE_STRING: - mpString = static_cast<const ScStringCell&>(rCell).GetStringPtr(); + { + ScSetStringParam aParam; + aParam.setTextInput(); + rDoc.SetString(rPos, *mpString, &aParam); + } break; case CELLTYPE_EDIT: - mpEditText = static_cast<const ScEditCell&>(rCell).GetData(); + rDoc.SetEditText(rPos, ScEditUtil::Clone(*mpEditText, rDoc)); break; case CELLTYPE_VALUE: - mfValue = static_cast<const ScValueCell&>(rCell).GetValue(); + rDoc.SetValue(rPos, mfValue); break; case CELLTYPE_FORMULA: - mpFormula = static_cast<ScFormulaCell*>(&rCell); + rDoc.SetFormulaCell(rPos, new ScFormulaCell(*mpFormula, rDoc, rPos)); break; default: - meType = CELLTYPE_NONE; // reset to empty. + rDoc.SetEmptyCell(rPos); } } -void ScRefCellValue::commit( ScDocument& rDoc, const ScAddress& rPos ) const +void ScRefCellValue::commit( ScColumn& rColumn, SCROW nRow ) const { switch (meType) { case CELLTYPE_STRING: - { - ScSetStringParam aParam; - aParam.setTextInput(); - rDoc.SetString(rPos, *mpString, &aParam); - } + rColumn.SetRawString(nRow, *mpString); break; case CELLTYPE_EDIT: - rDoc.SetEditText(rPos, mpEditText->Clone()); + rColumn.SetEditText(nRow, ScEditUtil::Clone(*mpEditText, rColumn.GetDoc())); break; case CELLTYPE_VALUE: - rDoc.SetValue(rPos, mfValue); + rColumn.SetValue(nRow, mfValue); break; case CELLTYPE_FORMULA: - rDoc.SetFormulaCell(rPos, mpFormula->Clone()); + { + ScAddress aDestPos(rColumn.GetCol(), nRow, rColumn.GetTab()); + rColumn.SetFormulaCell(nRow, new ScFormulaCell(*mpFormula, rColumn.GetDoc(), aDestPos)); + } break; default: - rDoc.SetEmptyCell(rPos); + rColumn.Delete(nRow); } } |