diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-11-10 21:22:34 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-11-18 08:31:53 -0500 |
commit | e392f758b141d731e1743a49086549ed27bf0617 (patch) | |
tree | 697a53881bdaa2aac7dfbce72447904012dc0ee9 /sc | |
parent | ff5aad0a26aac46a3a540ac6ed2b7eca4a8cd23d (diff) |
Move this code to the context class.
Change-Id: I387dba24993d418a2b3923eac992ad2506229704
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/clipcontext.hxx | 2 | ||||
-rw-r--r-- | sc/source/core/data/clipcontext.cxx | 127 | ||||
-rw-r--r-- | sc/source/core/data/document10.cxx | 118 |
3 files changed, 130 insertions, 117 deletions
diff --git a/sc/inc/clipcontext.hxx b/sc/inc/clipcontext.hxx index ccaca6770202..3891274d7283 100644 --- a/sc/inc/clipcontext.hxx +++ b/sc/inc/clipcontext.hxx @@ -50,6 +50,7 @@ class CopyFromClipContext : public ClipContextBase SCROW mnDestRow2; SCTAB mnTabStart; SCTAB mnTabEnd; + ScDocument& mrDestDoc; ScDocument* mpRefUndoDoc; ScDocument* mpClipDoc; InsertDeleteFlags mnInsertFlag; @@ -106,6 +107,7 @@ public: void setSingleCellColumnSize( size_t nSize ); ScCellValue& getSingleCell( size_t nColOffset ); + void setSingleCell( const ScAddress& rSrcPos, const ScColumn& rSrcCol ); const ScPatternAttr* getSingleCellPattern( size_t nColOffset ) const; void setSingleCellPattern( size_t nColOffset, const ScPatternAttr* pAttr ); diff --git a/sc/source/core/data/clipcontext.cxx b/sc/source/core/data/clipcontext.cxx index a414cfd4fb6f..85c079c8c85a 100644 --- a/sc/source/core/data/clipcontext.cxx +++ b/sc/source/core/data/clipcontext.cxx @@ -12,6 +12,9 @@ #include "mtvelements.hxx" #include <column.hxx> #include <scitems.hxx> +#include <tokenarray.hxx> +#include <editutil.hxx> +#include <clipparam.hxx> #include <svl/intitem.hxx> @@ -34,6 +37,7 @@ CopyFromClipContext::CopyFromClipContext(ScDocument& rDoc, mnDestCol1(-1), mnDestCol2(-1), mnDestRow1(-1), mnDestRow2(-1), mnTabStart(-1), mnTabEnd(-1), + mrDestDoc(rDoc), mpRefUndoDoc(pRefUndoDoc), mpClipDoc(pClipDoc), mnInsertFlag(nInsertFlag), mnDeleteFlag(IDF_NONE), mpCondFormatList(NULL), @@ -119,6 +123,129 @@ ScCellValue& CopyFromClipContext::getSingleCell( size_t nColOffset ) return maSingleCells[nColOffset]; } +void CopyFromClipContext::setSingleCell( const ScAddress& rSrcPos, const ScColumn& rSrcCol ) +{ + SCCOL nColOffset = rSrcPos.Col() - mpClipDoc->GetClipParam().getWholeRange().aStart.Col(); + + ScCellValue& rSrcCell = getSingleCell(nColOffset); + if (isAsLink()) + { + ScSingleRefData aRef; + aRef.InitAddress(rSrcPos); + aRef.SetFlag3D(true); + + ScTokenArray aArr; + aArr.AddSingleReference(aRef); + rSrcCell.set(new ScFormulaCell(mpClipDoc, rSrcPos, aArr)); + } + else + { + rSrcCell.assign(*mpClipDoc, rSrcPos); + + // Check the paste flag to see whether we want to paste this cell. If the + // flag says we don't want to paste this cell, we'll return with true. + InsertDeleteFlags nFlags = getInsertFlag(); + bool bNumeric = (nFlags & IDF_VALUE) != IDF_NONE; + bool bDateTime = (nFlags & IDF_DATETIME) != IDF_NONE; + bool bString = (nFlags & IDF_STRING) != IDF_NONE; + bool bBoolean = (nFlags & IDF_SPECIAL_BOOLEAN) != IDF_NONE; + bool bFormula = (nFlags & IDF_FORMULA) != IDF_NONE; + + switch (rSrcCell.meType) + { + case CELLTYPE_VALUE: + { + bool bPaste = isDateCell(rSrcCol, rSrcPos.Row()) ? bDateTime : bNumeric; + if (!bPaste) + // Don't paste this. + rSrcCell.clear(); + } + break; + case CELLTYPE_STRING: + case CELLTYPE_EDIT: + { + if (!bString) + // Skip pasting. + rSrcCell.clear(); + } + break; + case CELLTYPE_FORMULA: + { + if (bBoolean) + { + // Check if this formula cell is a boolean cell, and if so, go ahead and paste it. + ScTokenArray* pCode = rSrcCell.mpFormula->GetCode(); + if (pCode && pCode->GetLen() == 1) + { + const formula::FormulaToken* p = pCode->First(); + if (p->GetOpCode() == ocTrue || p->GetOpCode() == ocFalse) + // This is a boolean formula. Good. + break; + } + } + + if (bFormula) + // Good. + break; + + sal_uInt16 nErr = rSrcCell.mpFormula->GetErrCode(); + if (nErr) + { + // error codes are cloned with values + if (!bNumeric) + // Error code is treated as numeric value. Don't paste it. + rSrcCell.clear(); + } + else if (rSrcCell.mpFormula->IsValue()) + { + bool bPaste = isDateCell(rSrcCol, rSrcPos.Row()) ? bDateTime : bNumeric; + if (!bPaste) + { + // Don't paste this. + rSrcCell.clear(); + break; + } + + // Turn this into a numeric cell. + rSrcCell.set(rSrcCell.mpFormula->GetValue()); + } + else if (bString) + { + svl::SharedString aStr = rSrcCell.mpFormula->GetString(); + if (aStr.isEmpty()) + { + // do not clone empty string + rSrcCell.clear(); + break; + } + + // Turn this into a string or edit cell. + if (rSrcCell.mpFormula->IsMultilineResult()) + { + // TODO : Add shared string support to the edit engine to + // make this process simpler. + ScFieldEditEngine& rEngine = mrDestDoc.GetEditEngine(); + rEngine.SetText(rSrcCell.mpFormula->GetString().getString()); + boost::scoped_ptr<EditTextObject> pObj(rEngine.CreateTextObject()); + pObj->NormalizeString(mrDestDoc.GetSharedStringPool()); + rSrcCell.set(*pObj); + } + else + rSrcCell.set(rSrcCell.mpFormula->GetString()); + } + else + // We don't want to paste this. + rSrcCell.clear(); + } + break; + case CELLTYPE_NONE: + default: + // There is nothing to paste. + rSrcCell.clear(); + } + } +} + const ScPatternAttr* CopyFromClipContext::getSingleCellPattern( size_t nColOffset ) const { assert(nColOffset < maSinglePatterns.size()); diff --git a/sc/source/core/data/document10.cxx b/sc/source/core/data/document10.cxx index 714bc238f88b..49c0a9f77436 100644 --- a/sc/source/core/data/document10.cxx +++ b/sc/source/core/data/document10.cxx @@ -104,123 +104,7 @@ bool ScDocument::CopyOneCellFromClip( if ((rCxt.getInsertFlag() & (IDF_NOTE | IDF_ADDNOTES)) != IDF_NONE) rCxt.setSingleCellNote(nColOffset, pClipDoc->GetNote(aSrcPos)); - ScCellValue& rSrcCell = rCxt.getSingleCell(nColOffset); - if (rCxt.isAsLink()) - { - ScSingleRefData aRef; - aRef.InitAddress(aSrcPos); - aRef.SetFlag3D(true); - - ScTokenArray aArr; - aArr.AddSingleReference(aRef); - rSrcCell.set(new ScFormulaCell(pClipDoc, aSrcPos, aArr)); - } - else - { - rSrcCell.assign(*pClipDoc, aSrcPos); - - // Check the paste flag to see whether we want to paste this cell. If the - // flag says we don't want to paste this cell, we'll return with true. - InsertDeleteFlags nFlags = rCxt.getInsertFlag(); - bool bNumeric = (nFlags & IDF_VALUE) != IDF_NONE; - bool bDateTime = (nFlags & IDF_DATETIME) != IDF_NONE; - bool bString = (nFlags & IDF_STRING) != IDF_NONE; - bool bBoolean = (nFlags & IDF_SPECIAL_BOOLEAN) != IDF_NONE; - bool bFormula = (nFlags & IDF_FORMULA) != IDF_NONE; - - switch (rSrcCell.meType) - { - case CELLTYPE_VALUE: - { - bool bPaste = rCxt.isDateCell(pSrcTab->aCol[aSrcPos.Col()], aSrcPos.Row()) ? bDateTime : bNumeric; - if (!bPaste) - // Don't paste this. - rSrcCell.clear(); - } - break; - case CELLTYPE_STRING: - case CELLTYPE_EDIT: - { - if (!bString) - // Skip pasting. - rSrcCell.clear(); - } - break; - case CELLTYPE_FORMULA: - { - if (bBoolean) - { - // Check if this formula cell is a boolean cell, and if so, go ahead and paste it. - ScTokenArray* pCode = rSrcCell.mpFormula->GetCode(); - if (pCode && pCode->GetLen() == 1) - { - const formula::FormulaToken* p = pCode->First(); - if (p->GetOpCode() == ocTrue || p->GetOpCode() == ocFalse) - // This is a boolean formula. Good. - break; - } - } - - if (bFormula) - // Good. - break; - - sal_uInt16 nErr = rSrcCell.mpFormula->GetErrCode(); - if (nErr) - { - // error codes are cloned with values - if (!bNumeric) - // Error code is treated as numeric value. Don't paste it. - rSrcCell.clear(); - } - else if (rSrcCell.mpFormula->IsValue()) - { - bool bPaste = rCxt.isDateCell(pSrcTab->aCol[aSrcPos.Col()], aSrcPos.Row()) ? bDateTime : bNumeric; - if (!bPaste) - { - // Don't paste this. - rSrcCell.clear(); - break; - } - - // Turn this into a numeric cell. - rSrcCell.set(rSrcCell.mpFormula->GetValue()); - } - else if (bString) - { - svl::SharedString aStr = rSrcCell.mpFormula->GetString(); - if (aStr.isEmpty()) - { - // do not clone empty string - rSrcCell.clear(); - break; - } - - // Turn this into a string or edit cell. - if (rSrcCell.mpFormula->IsMultilineResult()) - { - // TODO : Add shared string support to the edit engine to - // make this process simpler. - ScFieldEditEngine& rEngine = GetEditEngine(); - rEngine.SetText(rSrcCell.mpFormula->GetString().getString()); - boost::scoped_ptr<EditTextObject> pObj(rEngine.CreateTextObject()); - pObj->NormalizeString(GetSharedStringPool()); - rSrcCell.set(*pObj); - } - else - rSrcCell.set(rSrcCell.mpFormula->GetString()); - } - else - // We don't want to paste this. - rSrcCell.clear(); - } - break; - case CELLTYPE_NONE: - default: - // There is nothing to paste. - rSrcCell.clear(); - } - } + rCxt.setSingleCell(aSrcPos, pSrcTab->aCol[aSrcPos.Col()]); } // All good. Proceed with the pasting. |