diff options
-rw-r--r-- | sc/inc/column.hxx | 2 | ||||
-rw-r--r-- | sc/inc/document.hxx | 14 | ||||
-rw-r--r-- | sc/inc/table.hxx | 4 | ||||
-rw-r--r-- | sc/source/core/data/column3.cxx | 12 | ||||
-rw-r--r-- | sc/source/core/data/documen2.cxx | 33 | ||||
-rw-r--r-- | sc/source/core/data/document.cxx | 22 | ||||
-rw-r--r-- | sc/source/core/data/table2.cxx | 18 | ||||
-rw-r--r-- | sc/source/filter/dif/difimp.cxx | 6 | ||||
-rw-r--r-- | sc/source/filter/oox/worksheethelper.cxx | 15 | ||||
-rw-r--r-- | sc/source/filter/orcus/interface.cxx | 16 | ||||
-rw-r--r-- | sc/source/filter/qpro/qpro.cxx | 3 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlcelli.cxx | 34 | ||||
-rw-r--r-- | sc/source/ui/docshell/impex.cxx | 12 |
13 files changed, 133 insertions, 58 deletions
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index 37a28bbf61e1..558b83f3bdef 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -262,6 +262,8 @@ public: ScSetStringParam* pParam = NULL ); void SetEditText( SCROW nRow, EditTextObject* pEditText ); + void SetFormula( SCROW nRow, const ScTokenArray& rArray, formula::FormulaGrammar::Grammar eGram ); + void SetFormula( SCROW nRow, const OUString& rFormula, formula::FormulaGrammar::Grammar eGram ); void SetValue( SCROW nRow, const double& rVal); void SetError( SCROW nRow, const sal_uInt16 nError); diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 54c18ea86ead..efecd06a2b3a 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -767,12 +767,26 @@ public: SC_DLLPUBLIC void SetEditText( const ScAddress& rPos, const OUString& rStr ); + /** + * Call this if you are not sure whether to put this as an edit text or a + * simple text. + */ + SC_DLLPUBLIC void SetTextCell( const ScAddress& rPos, const OUString& rStr ); + void SetEmptyCell( const ScAddress& rPos ); SC_DLLPUBLIC void SetValue( SCCOL nCol, SCROW nRow, SCTAB nTab, const double& rVal ); SC_DLLPUBLIC void SetValue( const ScAddress& rPos, double fVal ); void SetError( SCCOL nCol, SCROW nRow, SCTAB nTab, const sal_uInt16 nError); + SC_DLLPUBLIC void SetFormula( + const ScAddress& rPos, const ScTokenArray& rArray, + formula::FormulaGrammar::Grammar eGram = formula::FormulaGrammar::GRAM_DEFAULT ); + + SC_DLLPUBLIC void SetFormula( + const ScAddress& rPos, const OUString& rFormula, + formula::FormulaGrammar::Grammar eGram = formula::FormulaGrammar::GRAM_DEFAULT ); + SC_DLLPUBLIC void InsertMatrixFormula(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, const ScMarkData& rMark, diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 98ca220b94cf..b87ecfe39e7a 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -306,6 +306,10 @@ public: void SetEditText( SCCOL nCol, SCROW nRow, EditTextObject* pEditText ); void SetEmptyCell( SCCOL nCol, SCROW nRow ); + void SetFormula( + SCCOL nCol, SCROW nRow, const ScTokenArray& rArray, formula::FormulaGrammar::Grammar eGram ); + void SetFormula( + SCCOL nCol, SCROW nRow, const OUString& rFormula, formula::FormulaGrammar::Grammar eGram ); void SetValue( SCCOL nCol, SCROW nRow, const double& rVal ); void SetError( SCCOL nCol, SCROW nRow, sal_uInt16 nError); diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx index 36689bfdb952..469c818bd490 100644 --- a/sc/source/core/data/column3.cxx +++ b/sc/source/core/data/column3.cxx @@ -1488,6 +1488,18 @@ void ScColumn::SetEditText( SCROW nRow, EditTextObject* pEditText ) Insert(nRow, new ScEditCell(pEditText, pDocument)); } +void ScColumn::SetFormula( SCROW nRow, const ScTokenArray& rArray, formula::FormulaGrammar::Grammar eGram ) +{ + ScAddress aPos(nCol, nRow, nTab); + Insert(nRow, new ScFormulaCell(pDocument, aPos, &rArray, eGram)); +} + +void ScColumn::SetFormula( SCROW nRow, const OUString& rFormula, formula::FormulaGrammar::Grammar eGram ) +{ + ScAddress aPos(nCol, nRow, nTab); + Insert(nRow, new ScFormulaCell(pDocument, aPos, rFormula, eGram)); +} + void ScColumn::GetFilterEntries(SCROW nStartRow, SCROW nEndRow, std::vector<ScTypedStrData>& rStrings, bool& rHasDates) { bool bHasDates = false; diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx index bc681ba89789..315105387b3c 100644 --- a/sc/source/core/data/documen2.cxx +++ b/sc/source/core/data/documen2.cxx @@ -589,17 +589,8 @@ void ScDocument::PutCell( SCCOL nCol, SCROW nRow, SCTAB nTab, { if (ValidTab(nTab)) { - if ( bForceTab && ( nTab >= static_cast<SCTAB>(maTabs.size()) || !maTabs[nTab] ) ) - { - bool bExtras = !bIsUndo; // Spaltenbreiten, Zeilenhoehen, Flags - if ( nTab >= static_cast<SCTAB>(maTabs.size()) ) - { - maTabs.resize( nTab + 1, NULL ); - } - maTabs.at(nTab) = new ScTable(this, nTab, - OUString("temp"), - bExtras, bExtras); - } + if (bForceTab) + EnsureTable(nTab); if ( nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] ) maTabs[nTab]->PutCell( nCol, nRow, nFormatIndex, pCell ); @@ -1040,8 +1031,6 @@ sal_uLong ScDocument::TransferTab( ScDocument* pSrcDoc, SCTAB nSrcPos, return nRetVal; } -// ---------------------------------------------------------------------------- - void ScDocument::SetError( SCCOL nCol, SCROW nRow, SCTAB nTab, const sal_uInt16 nError) { if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size())) @@ -1049,7 +1038,23 @@ void ScDocument::SetError( SCCOL nCol, SCROW nRow, SCTAB nTab, const sal_uInt16 maTabs[nTab]->SetError( nCol, nRow, nError ); } -// ---------------------------------------------------------------------------- +void ScDocument::SetFormula( + const ScAddress& rPos, const ScTokenArray& rArray, formula::FormulaGrammar::Grammar eGram ) +{ + if (!TableExists(rPos.Tab())) + return; + + maTabs[rPos.Tab()]->SetFormula(rPos.Col(), rPos.Row(), rArray, eGram); +} + +void ScDocument::SetFormula( + const ScAddress& rPos, const OUString& rFormula, formula::FormulaGrammar::Grammar eGram ) +{ + if (!TableExists(rPos.Tab())) + return; + + maTabs[rPos.Tab()]->SetFormula(rPos.Col(), rPos.Row(), rFormula, eGram); +} void ScDocument::SetConsolidateDlgData( const ScConsolidateParam* pData ) { diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index 455178a0d83c..4515b2c55109 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -87,6 +87,7 @@ #include "stlalgorithm.hxx" #include "defaultsoptions.hxx" #include "editutil.hxx" +#include "stringutil.hxx" #include <map> #include <limits> @@ -2990,6 +2991,27 @@ void ScDocument::SetEditText( const ScAddress& rPos, const OUString& rStr ) maTabs[rPos.Tab()]->SetEditText(rPos.Col(), rPos.Row(), rEngine.CreateTextObject()); } +void ScDocument::SetTextCell( const ScAddress& rPos, const OUString& rStr ) +{ + if (!TableExists(rPos.Tab())) + return; + + if (ScStringUtil::isMultiline(rStr)) + { + ScFieldEditEngine& rEngine = GetEditEngine(); + rEngine.SetText(rStr); + maTabs[rPos.Tab()]->SetEditText(rPos.Col(), rPos.Row(), rEngine.CreateTextObject()); + } + else + { + ScSetStringParam aParam; + aParam.mbDetectNumberFormat = false; + aParam.mbHandleApostrophe = false; + aParam.meSetTextNumFormat = ScSetStringParam::Always; + maTabs[rPos.Tab()]->SetString(rPos.Col(), rPos.Row(), rPos.Tab(), rStr, &aParam); + } +} + void ScDocument::SetEmptyCell( const ScAddress& rPos ) { if (!TableExists(rPos.Tab())) diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index 80cc8cb4650c..e73a8e94b80a 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -1342,6 +1342,24 @@ void ScTable::SetEmptyCell( SCCOL nCol, SCROW nRow ) aCol[nCol].Delete(nRow); } +void ScTable::SetFormula( + SCCOL nCol, SCROW nRow, const ScTokenArray& rArray, formula::FormulaGrammar::Grammar eGram ) +{ + if (!ValidColRow(nCol, nRow)) + return; + + aCol[nCol].SetFormula(nRow, rArray, eGram); +} + +void ScTable::SetFormula( + SCCOL nCol, SCROW nRow, const OUString& rFormula, formula::FormulaGrammar::Grammar eGram ) +{ + if (!ValidColRow(nCol, nRow)) + return; + + aCol[nCol].SetFormula(nRow, rFormula, eGram); +} + void ScTable::SetValue( SCCOL nCol, SCROW nRow, const double& rVal ) { if (ValidColRow(nCol, nRow)) diff --git a/sc/source/filter/dif/difimp.cxx b/sc/source/filter/dif/difimp.cxx index 63987e736e1e..4b20016d82f3 100644 --- a/sc/source/filter/dif/difimp.cxx +++ b/sc/source/filter/dif/difimp.cxx @@ -204,11 +204,7 @@ FltError ScFormatFilterPluginImpl::ScImportDif( SvStream& rIn, ScDocument* pDoc, if (!aData.isEmpty()) { pDoc->EnsureTable(nBaseTab); - - if (ScStringUtil::isMultiline(aData)) - pDoc->SetEditText(aPos, aData); - else - pDoc->SetString(aPos, aData, &aStrParam); + pDoc->SetTextCell(aPos, aData); } } else diff --git a/sc/source/filter/oox/worksheethelper.cxx b/sc/source/filter/oox/worksheethelper.cxx index c83e3c0666a2..dfb1653ab684 100644 --- a/sc/source/filter/oox/worksheethelper.cxx +++ b/sc/source/filter/oox/worksheethelper.cxx @@ -46,7 +46,6 @@ #include "oox/helper/propertyset.hxx" #include "addressconverter.hxx" #include "autofilterbuffer.hxx" -#include "cell.hxx" #include "commentsbuffer.hxx" #include "condformatbuffer.hxx" #include "convuno.hxx" @@ -67,8 +66,10 @@ #include "worksheetsettings.hxx" #include "formulabuffer.hxx" #include "scitems.hxx" -#include <svl/stritem.hxx> #include "editutil.hxx" +#include "tokenarray.hxx" + +#include <svl/stritem.hxx> #include <editeng/editobj.hxx> namespace oox { @@ -1556,14 +1557,9 @@ void WorksheetHelper::putString( const CellAddress& rAddress, const OUString& rT { ScAddress aAddress; ScUnoConversion::FillScAddress( aAddress, rAddress ); - ScBaseCell* pNewCell = NULL; ScDocument& rDoc = getScDocument(); if ( !rText.isEmpty() ) - pNewCell = ScBaseCell::CreateTextCell( rText, &rDoc ); - if ( pNewCell ) - rDoc.PutCell( aAddress, pNewCell ); - else - rDoc.SetString( aAddress.Col(), aAddress.Row(), aAddress.Tab(), rText ); + rDoc.SetTextCell(aAddress, rText); } void WorksheetHelper::putRichString( const CellAddress& rAddress, const RichString& rString, const Font* pFirstPortionFont ) const @@ -1584,8 +1580,7 @@ void WorksheetHelper::putFormulaTokens( const CellAddress& rAddress, const ApiTo ScAddress aCellPos; ScUnoConversion::FillScAddress( aCellPos, rAddress ); ScTokenConversion::ConvertToTokenArray( rDoc, aTokenArray, rTokens ); - ScBaseCell* pNewCell = new ScFormulaCell( &rDoc, aCellPos, &aTokenArray ); - rDoc.PutCell( aCellPos, pNewCell, sal_True ); + rDoc.SetFormula(aCellPos, aTokenArray); } void WorksheetHelper::initializeWorksheetImport() diff --git a/sc/source/filter/orcus/interface.cxx b/sc/source/filter/orcus/interface.cxx index b21e7e56e6c3..6e5464f6bb1e 100644 --- a/sc/source/filter/orcus/interface.cxx +++ b/sc/source/filter/orcus/interface.cxx @@ -118,9 +118,7 @@ void ScOrcusSheet::set_formula( { OUString aFormula(p, n, RTL_TEXTENCODING_UTF8); formula::FormulaGrammar::Grammar eGrammar = getCalcGrammarFromOrcus( grammar ); - - ScFormulaCell* pCell = new ScFormulaCell(&mrDoc, ScAddress(col, row, mnTab), aFormula, eGrammar); - mrDoc.PutCell(col, row, mnTab, pCell); + mrDoc.SetFormula(ScAddress(col,row,mnTab), aFormula, eGrammar); } void ScOrcusSheet::set_formula_result(row_t row, col_t col, const char* p, size_t n) @@ -153,8 +151,7 @@ void ScOrcusSheet::set_shared_formula( maSharedFormulas.insert( std::pair<size_t, ScRangeData*>(sindex, pSharedFormula) ); ScTokenArray aArr; aArr.AddToken( formula::FormulaIndexToken( ocName, pSharedFormula->GetIndex() ) ); - ScFormulaCell* pCell = new ScFormulaCell( &mrDoc, ScAddress( row, col, mnTab ), &aArr ); - mrDoc.PutCell( col, row, mnTab, pCell ); + mrDoc.SetFormula(ScAddress(col,row,mnTab), aArr); } } @@ -174,8 +171,7 @@ void ScOrcusSheet::set_shared_formula( maSharedFormulas.insert( std::pair<size_t, ScRangeData*>(sindex, pSharedFormula) ); ScTokenArray aArr; aArr.AddToken( formula::FormulaIndexToken( ocName, pSharedFormula->GetIndex() ) ); - ScFormulaCell* pCell = new ScFormulaCell( &mrDoc, ScAddress( row, col, mnTab ), &aArr ); - mrDoc.PutCell( col, row, mnTab, pCell ); + mrDoc.SetFormula(ScAddress(col,row,mnTab), aArr); } } @@ -187,8 +183,7 @@ void ScOrcusSheet::set_shared_formula(row_t row, col_t col, size_t sindex) ScRangeData* pSharedFormula = maSharedFormulas.find(sindex)->second; ScTokenArray aArr; aArr.AddToken( formula::FormulaIndexToken( ocName, pSharedFormula->GetIndex() ) ); - ScFormulaCell* pCell = new ScFormulaCell( &mrDoc, ScAddress( row, col, mnTab ), &aArr ); - mrDoc.PutCell( col, row, mnTab, pCell ); + mrDoc.SetFormula(ScAddress(col,row,mnTab), aArr); } void ScOrcusSheet::set_string(row_t row, col_t col, size_t sindex) @@ -199,8 +194,7 @@ void ScOrcusSheet::set_string(row_t row, col_t col, size_t sindex) // normal string const OUString& rSharedString = mrSharedStrings.getByIndex(sindex); - ScBaseCell* pCell = ScBaseCell::CreateTextCell( rSharedString, &mrDoc ); - mrDoc.PutCell(col, row, mnTab, pCell); + mrDoc.SetTextCell(ScAddress(col,row,mnTab), rSharedString); } void ScOrcusSheet::set_value(row_t row, col_t col, double value) diff --git a/sc/source/filter/qpro/qpro.cxx b/sc/source/filter/qpro/qpro.cxx index 2ae1f61d9b78..e292871833db 100644 --- a/sc/source/filter/qpro/qpro.cxx +++ b/sc/source/filter/qpro/qpro.cxx @@ -61,7 +61,8 @@ FltError ScQProReader::readSheet( SCTAB nTab, ScDocument* pDoc, ScQProStyle *pSt readString( aLabel, nLen - 7 ); nStyle = nStyle >> 3; pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle ); - pDoc->PutCell( nCol, nRow, nTab, ScBaseCell::CreateTextCell( aLabel, pDoc ), true ); + pDoc->EnsureTable(nTab); + pDoc->SetTextCell(ScAddress(nCol,nRow,nTab), aLabel); } else eRet = eERR_FORMAT; diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx index 19b9041530eb..6d376a78043f 100644 --- a/sc/source/filter/xml/xmlcelli.cxx +++ b/sc/source/filter/xml/xmlcelli.cxx @@ -48,6 +48,7 @@ #include "editutil.hxx" #include "cell.hxx" #include "editattributemap.hxx" +#include "stringutil.hxx" #include <xmloff/xmltkmap.hxx> #include <xmloff/xmltoken.hxx> @@ -1024,16 +1025,22 @@ void ScXMLTableRowCellContext::PutTextCell( const ScAddress& rCurrentPos, } else //regular text cells { - ScBaseCell* pNewCell = NULL; ScDocument* pDoc = rXMLImport.GetDocument(); if (maStringValue) - pNewCell = ScBaseCell::CreateTextCell( *maStringValue, pDoc ); + { + pDoc->SetTextCell(rCurrentPos, *maStringValue); + bDoIncrement = true; + } else if (mbEditEngineHasText) { if (maFields.empty() && maFormats.empty() && mpEditEngine->GetParagraphCount() == 1) { // This is a normal text without format runs. - pNewCell = new ScStringCell(mpEditEngine->GetText()); + ScSetStringParam aParam; + aParam.mbDetectNumberFormat = false; + aParam.mbHandleApostrophe = false; + aParam.meSetTextNumFormat = ScSetStringParam::Always; + pDoc->SetString(rCurrentPos, mpEditEngine->GetText(), &aParam); } else { @@ -1055,14 +1062,17 @@ void ScXMLTableRowCellContext::PutTextCell( const ScAddress& rCurrentPos, // is a prerequisite for using this constructor of ScEditCell. pDoc->SetEditText(rCurrentPos, mpEditEngine->CreateTextObject()); } + bDoIncrement = true; } else if ( nCurrentCol > 0 && pOUText && !pOUText->isEmpty() ) - pNewCell = ScBaseCell::CreateTextCell( *pOUText, pDoc ); - - bDoIncrement = pNewCell != NULL; - if (bDoIncrement && pNewCell) - pDoc->PutCell( rCurrentPos, pNewCell ); + { + pDoc->SetTextCell(rCurrentPos, *pOUText); + bDoIncrement = true; + } + else + bDoIncrement = false; } + // #i56027# This is about setting simple text, not edit cells, // so ProgressBarIncrement must be called with bEditCell = FALSE. // Formatted text that is put into the cell by the child context @@ -1316,12 +1326,13 @@ void ScXMLTableRowCellContext::PutFormulaCell( const ScAddress& rCellPos ) ScFormulaCell* pFCell = static_cast<ScFormulaCell*>(pNewCell); SetFormulaCell(pFCell); + pDoc->PutCell( rCellPos, pNewCell ); } else if ( aText[0] == '\'' && aText.getLength() > 1 ) { // for bEnglish, "'" at the beginning is always interpreted as text // marker and stripped - pNewCell = ScBaseCell::CreateTextCell( aText.copy( 1 ), pDoc ); + pDoc->SetTextCell(rCellPos, aText.copy(1)); } else { @@ -1329,13 +1340,12 @@ void ScXMLTableRowCellContext::PutFormulaCell( const ScAddress& rCellPos ) sal_uInt32 nEnglish = pFormatter->GetStandardIndex(LANGUAGE_ENGLISH_US); double fVal; if ( pFormatter->IsNumberFormat( aText, nEnglish, fVal ) ) - pNewCell = new ScValueCell( fVal ); + pDoc->SetValue(rCellPos, fVal); //the (english) number format will not be set //search matching local format and apply it else - pNewCell = ScBaseCell::CreateTextCell( aText, pDoc ); + pDoc->SetTextCell(rCellPos, aText); } - pDoc->PutCell( rCellPos, pNewCell ); } } diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx index b94146c860f1..edc4b8fbd718 100644 --- a/sc/source/ui/docshell/impex.cxx +++ b/sc/source/ui/docshell/impex.cxx @@ -981,7 +981,7 @@ static bool lcl_PutString( pDoc->ApplyPattern(nCol, nRow, nTab, aNewAttrs); } - pDoc->PutCell( nCol, nRow, nTab, ScBaseCell::CreateTextCell( rStr, pDoc ) ); + pDoc->SetTextCell(ScAddress(nCol,nRow,nTab), rStr); return bMultiLine; } @@ -1183,7 +1183,9 @@ static bool lcl_PutString( if (nFound > 5) nFormat = pDocFormatter->GetStandardFormat( fDays, nFormat, nType, eDocLang); - pDoc->PutCell( nCol, nRow, nTab, new ScValueCell(fDays), nFormat, false ); + ScAddress aPos(nCol,nRow,nTab); + pDoc->SetValue(aPos, fDays); + pDoc->SetNumberFormat(aPos, nFormat); return bMultiLine; // success } @@ -1780,9 +1782,9 @@ bool ScImportExport::Sylk2Doc( SvStream& rStrm ) { // don't ignore value if( bText ) { - pDoc->PutCell( nCol, nRow, aRange.aStart.Tab(), - ScBaseCell::CreateTextCell( aText, pDoc), - true); + pDoc->EnsureTable(aRange.aStart.Tab()); + pDoc->SetTextCell( + ScAddress(nCol, nRow, aRange.aStart.Tab()), aText); } else { |