summaryrefslogtreecommitdiff
path: root/sc/source
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2013-03-21 15:15:15 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2013-03-22 21:49:21 -0400
commit18571d151383dd2fda423f286550b63e8c2bd256 (patch)
tree84c04aadce754b84c983426b831699881190fe24 /sc/source
parent38df6bbbbe23444732b07e438887b6863a8ad1e8 (diff)
More on PutCell() avoidance.
Change-Id: I9166a00f1aadd4bfcb9dc46ef794cd53c19f5692
Diffstat (limited to 'sc/source')
-rw-r--r--sc/source/core/data/column.cxx17
-rw-r--r--sc/source/core/data/column3.cxx10
-rw-r--r--sc/source/core/data/document.cxx27
-rw-r--r--sc/source/core/data/table2.cxx26
-rw-r--r--sc/source/filter/lotus/tool.cxx8
-rw-r--r--sc/source/filter/xml/xmlcelli.cxx27
-rw-r--r--sc/source/ui/docshell/tablink.cxx5
-rw-r--r--sc/source/ui/view/spelleng.cxx39
8 files changed, 111 insertions, 48 deletions
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index ff8aa35ce998..13287de3357e 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -1406,6 +1406,23 @@ void ScColumn::CopyStaticToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol
rDestCol.maTextWidths.set<unsigned short>(it->nRow, TEXTWIDTH_DIRTY);
}
+void ScColumn::CopyCellToDocument( SCROW nSrcRow, SCROW nDestRow, ScColumn& rDestCol )
+{
+ SCSIZE nIndex;
+ if (!Search(nSrcRow, nIndex))
+ {
+ // Source cell is empty. Remove the destination cell if one exists.
+ rDestCol.Delete(nDestRow);
+ return;
+ }
+
+ ScBaseCell* pDestCell =
+ maItems[nSrcRow].pCell->Clone(
+ *rDestCol.pDocument, ScAddress(rDestCol.nCol, nDestRow, rDestCol.nTab));
+
+ rDestCol.Insert(nDestRow, pDestCell);
+}
+
void ScColumn::CopyToColumn(
SCROW nRow1, SCROW nRow2, sal_uInt16 nFlags, bool bMarked, ScColumn& rColumn,
const ScMarkData* pMarkData, bool bAsLink) const
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index fedb52816a8a..3297b88f000d 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -1488,6 +1488,11 @@ void ScColumn::SetEditText( SCROW nRow, EditTextObject* pEditText )
Insert(nRow, new ScEditCell(pEditText, pDocument));
}
+void ScColumn::SetEditText( SCROW nRow, const EditTextObject& rEditText, const SfxItemPool* pEditPool )
+{
+ Insert(nRow, new ScEditCell(rEditText, pDocument, pEditPool));
+}
+
void ScColumn::SetFormula( SCROW nRow, const ScTokenArray& rArray, formula::FormulaGrammar::Grammar eGram )
{
ScAddress aPos(nCol, nRow, nTab);
@@ -1842,6 +1847,11 @@ const ScFormulaCell* ScColumn::GetFormulaCell( SCROW nRow ) const
return FetchFormulaCell(nRow);
}
+ScFormulaCell* ScColumn::GetFormulaCell( SCROW nRow )
+{
+ return const_cast<ScFormulaCell*>(FetchFormulaCell(nRow));
+}
+
CellType ScColumn::GetCellType( SCROW nRow ) const
{
SCSIZE nIndex;
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 5ccd2bc7425e..47075a132e5a 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -1990,6 +1990,17 @@ void ScDocument::CopyStaticToDocument(const ScRange& rSrcRange, SCTAB nDestTab,
rSrcRange.aStart.Col(), rSrcRange.aStart.Row(), rSrcRange.aEnd.Col(), rSrcRange.aEnd.Row(), pDestTab);
}
+void ScDocument::CopyCellToDocument( const ScAddress& rSrcPos, const ScAddress& rDestPos, ScDocument& rDestDoc )
+{
+ if (!TableExists(rSrcPos.Tab()) || !rDestDoc.TableExists(rDestPos.Tab()))
+ return;
+
+ ScTable& rSrcTab = *maTabs[rSrcPos.Tab()];
+ ScTable& rDestTab = *rDestDoc.maTabs[rDestPos.Tab()];
+
+ rSrcTab.CopyCellToDocument(rSrcPos.Col(), rSrcPos.Row(), rDestPos.Col(), rDestPos.Row(), rDestTab);
+}
+
void ScDocument::CopyTabToClip(SCCOL nCol1, SCROW nRow1,
SCCOL nCol2, SCROW nRow2,
SCTAB nTab, ScDocument* pClipDoc)
@@ -2981,6 +2992,14 @@ void ScDocument::SetEditText( const ScAddress& rPos, EditTextObject* pEditText )
maTabs[rPos.Tab()]->SetEditText(rPos.Col(), rPos.Row(), pEditText);
}
+void ScDocument::SetEditText( const ScAddress& rPos, const EditTextObject& rEditText, const SfxItemPool* pEditPool )
+{
+ if (!TableExists(rPos.Tab()))
+ return;
+
+ maTabs[rPos.Tab()]->SetEditText(rPos.Col(), rPos.Row(), rEditText, pEditPool);
+}
+
void ScDocument::SetEditText( const ScAddress& rPos, const OUString& rStr )
{
if (!TableExists(rPos.Tab()))
@@ -3258,6 +3277,14 @@ const ScFormulaCell* ScDocument::GetFormulaCell( const ScAddress& rPos ) const
return maTabs[rPos.Tab()]->GetFormulaCell(rPos.Col(), rPos.Row());
}
+ScFormulaCell* ScDocument::GetFormulaCell( const ScAddress& rPos )
+{
+ if (!TableExists(rPos.Tab()))
+ return NULL;
+
+ return maTabs[rPos.Tab()]->GetFormulaCell(rPos.Col(), rPos.Row());
+}
+
CellType ScDocument::GetCellType( const ScAddress& rPos ) const
{
SCTAB nTab = rPos.Tab();
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 0306f2c8f1b2..f6d34c2f04fa 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -677,6 +677,16 @@ void ScTable::CopyStaticToDocument(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW
}
}
+void ScTable::CopyCellToDocument(SCCOL nSrcCol, SCROW nSrcRow, SCCOL nDestCol, SCROW nDestRow, ScTable& rDestTab )
+{
+ if (!ValidColRow(nSrcCol, nSrcRow) || !ValidColRow(nDestCol, nDestRow))
+ return;
+
+ ScColumn& rSrcCol = aCol[nSrcCol];
+ ScColumn& rDestCol = rDestTab.aCol[nDestCol];
+ rSrcCol.CopyCellToDocument(nSrcRow, nDestRow, rDestCol);
+}
+
void ScTable::CopyConditionalFormat( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
SCsCOL nDx, SCsROW nDy, ScTable* pTable)
{
@@ -1334,6 +1344,14 @@ void ScTable::SetEditText( SCCOL nCol, SCROW nRow, EditTextObject* pEditText )
aCol[nCol].SetEditText(nRow, pEditText);
}
+void ScTable::SetEditText( SCCOL nCol, SCROW nRow, const EditTextObject& rEditText, const SfxItemPool* pEditPool )
+{
+ if (!ValidColRow(nCol, nRow))
+ return;
+
+ aCol[nCol].SetEditText(nRow, rEditText, pEditPool);
+}
+
void ScTable::SetEmptyCell( SCCOL nCol, SCROW nRow )
{
if (!ValidColRow(nCol, nRow))
@@ -1435,6 +1453,14 @@ const ScFormulaCell* ScTable::GetFormulaCell( SCCOL nCol, SCROW nRow ) const
return aCol[nCol].GetFormulaCell(nRow);
}
+ScFormulaCell* ScTable::GetFormulaCell( SCCOL nCol, SCROW nRow )
+{
+ if (!ValidColRow(nCol, nRow))
+ return NULL;
+
+ return aCol[nCol].GetFormulaCell(nRow);
+}
+
ScNotes* ScTable::GetNotes()
{
return &maNotes;
diff --git a/sc/source/filter/lotus/tool.cxx b/sc/source/filter/lotus/tool.cxx
index 4fa8eb1a1f8e..136e607e49f2 100644
--- a/sc/source/filter/lotus/tool.cxx
+++ b/sc/source/filter/lotus/tool.cxx
@@ -23,7 +23,6 @@
#include <svl/zforlist.hxx>
#include <tools/solar.h>
-#include "cell.hxx"
#include "rangenam.hxx"
#include "compiler.hxx"
@@ -33,6 +32,8 @@
#include "lotrange.hxx"
#include "namebuff.hxx"
#include "ftools.hxx"
+#include "stringutil.hxx"
+#include "tokenarray.hxx"
#include <math.h>
@@ -98,8 +99,9 @@ void PutFormString( SCCOL nCol, SCROW nRow, SCTAB nTab, sal_Char* pString )
}
pDoc->ApplyAttr( nCol, nRow, nTab, *pJustify );
- ScStringCell* pZelle = new ScStringCell( String( pString, pLotusRoot->eCharsetQ ) );
- pDoc->PutCell( nCol, nRow, nTab, pZelle, true );
+ ScSetStringParam aParam;
+ aParam.setTextInput();
+ pDoc->SetString(ScAddress(nCol,nRow,nTab), String(pString, pLotusRoot->eCharsetQ), &aParam);
}
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index 4c335e7b0eb7..d51e1b56d390 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -986,11 +986,10 @@ void ScXMLTableRowCellContext::PutTextCell( const ScAddress& rCurrentPos,
//cell was already put in document, just need to set text here.
if( rXMLImport.GetTables().IsPartOfMatrix(rCurrentPos) )
{
- ScBaseCell* pCell = rXMLImport.GetDocument()->GetCell( rCurrentPos );
- bDoIncrement = ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA );
+ bDoIncrement = rXMLImport.GetDocument()->GetCellType(rCurrentPos) == CELLTYPE_FORMULA;
if ( bDoIncrement )
{
- ScFormulaCell* pFCell = static_cast<ScFormulaCell*>(pCell);
+ ScFormulaCell* pFCell = rXMLImport.GetDocument()->GetFormulaCell(rCurrentPos);
OUString aCellString;
if (maStringValue)
aCellString = *maStringValue;
@@ -1013,8 +1012,8 @@ void ScXMLTableRowCellContext::PutTextCell( const ScAddress& rCurrentPos,
ScAddress aTopLeftMatrixCell;
if(pFCell->GetMatrixOrigin(aTopLeftMatrixCell))
{
- ScBaseCell* pMatrixCell = rXMLImport.GetDocument()->GetCell( aTopLeftMatrixCell );
- static_cast<ScFormulaCell*>(pMatrixCell)->SetDirty();
+ ScFormulaCell* pMatrixCell = rXMLImport.GetDocument()->GetFormulaCell(aTopLeftMatrixCell);
+ pMatrixCell->SetDirty();
}
else
SAL_WARN("sc", "matrix cell without matrix");
@@ -1085,10 +1084,9 @@ void ScXMLTableRowCellContext::PutValueCell( const ScAddress& rCurrentPos )
//cell was already put in document, just need to set value here.
if( rXMLImport.GetTables().IsPartOfMatrix(rCurrentPos) )
{
- ScBaseCell* pCell = rXMLImport.GetDocument()->GetCell( rCurrentPos );
- if ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA )
+ if (rXMLImport.GetDocument()->GetCellType(rCurrentPos) == CELLTYPE_FORMULA)
{
- ScFormulaCell* pFCell = static_cast<ScFormulaCell*>(pCell);
+ ScFormulaCell* pFCell = rXMLImport.GetDocument()->GetFormulaCell(rCurrentPos);
SetFormulaCell(pFCell);
}
}
@@ -1110,8 +1108,8 @@ namespace {
bool isEmptyOrNote( ScDocument* pDoc, const ScAddress& rCurrentPos )
{
- ScBaseCell* pCell = pDoc->GetCell( rCurrentPos );
- return ( !pCell || pCell->GetCellType() == CELLTYPE_NOTE );
+ CellType eType = pDoc->GetCellType(rCurrentPos);
+ return (eType == CELLTYPE_NONE) || (eType == CELLTYPE_NOTE);
}
}
@@ -1310,7 +1308,6 @@ void ScXMLTableRowCellContext::PutFormulaCell( const ScAddress& rCellPos )
if ( !aText.isEmpty() )
{
- ScBaseCell* pNewCell = NULL;
if ( aText[0] == '=' && aText.getLength() > 1 )
{
// temporary formula string as string tokens
@@ -1320,11 +1317,9 @@ void ScXMLTableRowCellContext::PutFormulaCell( const ScAddress& rCellPos )
pCode->AddStringXML( aFormulaNmsp );
pDoc->IncXMLImportedFormulaCount( aText.getLength() );
- pNewCell = new ScFormulaCell( pDoc, rCellPos, pCode.get(), eGrammar, MM_NONE );
-
- ScFormulaCell* pFCell = static_cast<ScFormulaCell*>(pNewCell);
- SetFormulaCell(pFCell);
- pDoc->PutCell( rCellPos, pNewCell );
+ ScFormulaCell* pNewCell = new ScFormulaCell(pDoc, rCellPos, pCode.get(), eGrammar, MM_NONE);
+ SetFormulaCell(pNewCell);
+ pDoc->SetFormulaCell(rCellPos, pNewCell);
}
else if ( aText[0] == '\'' && aText.getLength() > 1 )
{
diff --git a/sc/source/ui/docshell/tablink.cxx b/sc/source/ui/docshell/tablink.cxx
index e71e38763f05..a16f51ba1279 100644
--- a/sc/source/ui/docshell/tablink.cxx
+++ b/sc/source/ui/docshell/tablink.cxx
@@ -39,9 +39,9 @@
#include "undotab.hxx"
#include "global.hxx"
#include "hints.hxx"
-#include "cell.hxx"
#include "dociter.hxx"
#include "formula/opcode.hxx"
+#include "cell.hxx"
using ::rtl::OUString;
@@ -344,8 +344,7 @@ sal_Bool ScTableLink::Refresh(const String& rNewFile, const String& rNewFilter,
for (SCCOL nCol=nStartCol; nCol<=nEndCol; nCol++)
{
ScAddress aDestPos( nCol, nRow, nTab );
- ScFormulaCell* pNewCell = new ScFormulaCell( pDoc, aDestPos, &aTokenArr );
- pDoc->PutCell( aDestPos, pNewCell );
+ pDoc->SetFormula(aDestPos, aTokenArr);
}
}
diff --git a/sc/source/ui/view/spelleng.cxx b/sc/source/ui/view/spelleng.cxx
index fffda6edbb4c..65f1d9e1cb41 100644
--- a/sc/source/ui/view/spelleng.cxx
+++ b/sc/source/ui/view/spelleng.cxx
@@ -81,10 +81,10 @@ bool ScConversionEngineBase::FindNextConversionCell()
{
ScMarkData& rMark = mrViewData.GetMarkData();
ScTabViewShell* pViewShell = mrViewData.GetViewShell();
- ScBaseCell* pCell = NULL;
const ScPatternAttr* pPattern = NULL;
const ScPatternAttr* pLastPattern = NULL;
- ::std::auto_ptr< SfxItemSet > pEditDefaults( new SfxItemSet( GetEmptyItemSet() ) );
+
+ boost::scoped_ptr<SfxItemSet> pEditDefaults(new SfxItemSet(GetEmptyItemSet()));
if( IsModified() )
{
@@ -107,40 +107,27 @@ bool ScConversionEngineBase::FindNextConversionCell()
{
ScAddress aPos( mnCurrCol, mnCurrRow, nTab );
CellType eCellType = mrDoc.GetCellType( aPos );
- pCell = mrDoc.GetCell( aPos );
+ bool bEmptyCell = eCellType == CELLTYPE_NONE || eCellType == CELLTYPE_NOTE;
- if( mpUndoDoc && pCell )
- {
- ScBaseCell* pUndoCell = pCell->Clone( *mpUndoDoc );
- mpUndoDoc->PutCell( aPos, pUndoCell );
- }
+ if (mpUndoDoc && !bEmptyCell)
+ mrDoc.CopyCellToDocument(aPos, aPos, *mpUndoDoc);
- if( eCellType == CELLTYPE_EDIT )
+ if (eCellType == CELLTYPE_EDIT)
{
- if( pCell )
- {
- ScEditCell* pEditCell = static_cast< ScEditCell* >( pCell );
- boost::scoped_ptr<EditTextObject> pEditObj(CreateTextObject());
- pEditCell->SetData(*pEditObj, GetEditTextObjectPool());
- }
+ boost::scoped_ptr<EditTextObject> pEditObj(CreateTextObject());
+ mrDoc.SetEditText(aPos, *pEditObj, GetEditTextObjectPool());
}
else
- {
- mrDoc.SetString( mnCurrCol, mnCurrRow, nTab, aNewStr );
- pCell = mrDoc.GetCell( aPos );
- }
+ mrDoc.SetString(aPos, aNewStr);
- if( mpRedoDoc && pCell )
- {
- ScBaseCell* pRedoCell = pCell->Clone( *mpRedoDoc );
- mpRedoDoc->PutCell( aPos, pRedoCell );
- }
+ if (mpRedoDoc && !bEmptyCell)
+ mrDoc.CopyCellToDocument(aPos, aPos, *mpRedoDoc);
- mrDocShell.PostPaintCell( mnCurrCol, mnCurrRow, nTab );
+ mrDocShell.PostPaintCell(aPos);
}
}
}
- pCell = NULL;
+
SCCOL nNewCol = mnCurrCol;
SCROW nNewRow = mnCurrRow;