sc/inc/column.hxx | 3 ++ sc/inc/document.hxx | 12 +++++++++++ sc/inc/table.hxx | 3 ++ sc/source/core/data/column.cxx | 17 ++++++++++++++++ sc/source/core/data/column3.cxx | 10 +++++++++ sc/source/core/data/document.cxx | 27 ++++++++++++++++++++++++++ sc/source/core/data/table2.cxx | 26 +++++++++++++++++++++++++ sc/source/filter/lotus/tool.cxx | 8 ++++--- sc/source/filter/xml/xmlcelli.cxx | 27 ++++++++++---------------- sc/source/ui/docshell/tablink.cxx | 5 +--- sc/source/ui/view/spelleng.cxx | 39 ++++++++++++-------------------------- 11 files changed, 129 insertions(+), 48 deletions(-)
New commits: commit df7cbec4410e250dc45f9fd506dde42f709a591d Author: Kohei Yoshida <kohei.yosh...@gmail.com> Date: Thu Mar 21 15:15:15 2013 -0400 More on PutCell() avoidance. Change-Id: I9166a00f1aadd4bfcb9dc46ef794cd53c19f5692 diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index 83a5530..f25dc78 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -207,6 +207,7 @@ public: void DeleteArea(SCROW nStartRow, SCROW nEndRow, sal_uInt16 nDelFlag ); void CopyToClip(SCROW nRow1, SCROW nRow2, ScColumn& rColumn, bool bKeepScenarioFlags) const; void CopyStaticToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol); + void CopyCellToDocument( SCROW nSrcRow, SCROW nDestRow, ScColumn& rDestCol ); void CopyFromClip(SCROW nRow1, SCROW nRow2, long nDy, sal_uInt16 nInsFlag, bool bAsLink, bool bSkipAttrForEmpty, ScColumn& rColumn); void StartListeningInArea( SCROW nRow1, SCROW nRow2 ); @@ -262,6 +263,7 @@ public: ScSetStringParam* pParam = NULL ); void SetEditText( SCROW nRow, EditTextObject* pEditText ); + void SetEditText( SCROW nRow, const EditTextObject& rEditText, const SfxItemPool* pEditPool ); void SetFormula( SCROW nRow, const ScTokenArray& rArray, formula::FormulaGrammar::Grammar eGram ); void SetFormula( SCROW nRow, const OUString& rFormula, formula::FormulaGrammar::Grammar eGram ); void SetFormulaCell( SCROW nRow, ScFormulaCell* pCell ); @@ -276,6 +278,7 @@ public: void GetFormula( SCROW nRow, rtl::OUString& rFormula ) const; const ScTokenArray* GetFormulaTokens( SCROW nRow ) const; const ScFormulaCell* GetFormulaCell( SCROW nRow ) const; + ScFormulaCell* GetFormulaCell( SCROW nRow ); CellType GetCellType( SCROW nRow ) const; SCSIZE GetCellCount() const; sal_uInt32 GetWeightedCount() const; diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index c31c952..5f0a681 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -765,6 +765,8 @@ public: */ SC_DLLPUBLIC void SetEditText( const ScAddress& rPos, EditTextObject* pEditText ); + void SetEditText( const ScAddress& rPos, const EditTextObject& rEditText, const SfxItemPool* pEditPool ); + SC_DLLPUBLIC void SetEditText( const ScAddress& rPos, const OUString& rStr ); /** @@ -824,6 +826,7 @@ public: void GetFormula( SCCOL nCol, SCROW nRow, SCTAB nTab, String& rFormula ) const; const ScTokenArray* GetFormulaTokens( const ScAddress& rPos ) const; const ScFormulaCell* GetFormulaCell( const ScAddress& rPos ) const; + ScFormulaCell* GetFormulaCell( const ScAddress& rPos ); 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; @@ -1088,6 +1091,15 @@ public: */ void CopyStaticToDocument(const ScRange& rSrcRange, SCTAB nDestTab, ScDocument* pDestDoc); + /** + * Copy only cell, nothing but cell to another document. + * + * @param rSrcPos source cell position + * @param rDestPos destination cell position + * @param rDestDoc destination document + */ + void CopyCellToDocument( const ScAddress& rSrcPos, const ScAddress& rDestPos, ScDocument& rDestDoc ); + void CopyTabToClip(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, SCTAB nTab, ScDocument* pClipDoc = NULL); void CopyBlockFromClip( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index aebe9c0..461da522 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -304,6 +304,7 @@ public: ScSetStringParam* pParam = NULL ); void SetEditText( SCCOL nCol, SCROW nRow, EditTextObject* pEditText ); + void SetEditText( SCCOL nCol, SCROW nRow, const EditTextObject& rEditText, const SfxItemPool* pEditPool ); void SetEmptyCell( SCCOL nCol, SCROW nRow ); void SetFormula( @@ -329,6 +330,7 @@ public: void GetFormula( SCCOL nCol, SCROW nRow, rtl::OUString& rFormula ) const; const ScTokenArray* GetFormulaTokens( SCCOL nCol, SCROW nRow ) const; const ScFormulaCell* GetFormulaCell( SCCOL nCol, SCROW nRow ) const; + ScFormulaCell* GetFormulaCell( SCCOL nCol, SCROW nRow ); CellType GetCellType( const ScAddress& rPos ) const { @@ -369,6 +371,7 @@ public: void CopyToClip(const ScRangeList& rRanges, ScTable* pTable, bool bKeepScenarioFlags, bool bCloneNoteCaptions); void CopyStaticToDocument(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScTable* pDestTab); + void CopyCellToDocument( SCCOL nSrcCol, SCROW nSrcRow, SCCOL nDestCol, SCROW nDestRow, ScTable& rDestTab ); void CopyFromClip(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, SCsCOL nDx, SCsROW nDy, sal_uInt16 nInsFlag, bool bAsLink, bool bSkipAttrForEmpty, ScTable* pTable); void StartListeningInArea( SCCOL nCol1, SCROW nRow1, diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx index ff8aa35..13287de 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 fedb528..3297b88 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 5ccd2bc..47075a1 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 0306f2c..f6d34c2 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 4fa8eb1..136e607 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 4c335e7..d51e1b5 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 e71e387..a16f51b 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 fffda6e..65f1d9e 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; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits