[Libreoffice-commits] core.git: Branch 'feature/formula-core-rework' - 3 commits - sc/inc sc/Library_sc.mk sc/source
Kohei Yoshida
kohei.yoshida at gmail.com
Tue Jun 25 23:51:07 PDT 2013
sc/Library_sc.mk | 1
sc/inc/cellclonehandler.hxx | 68 -----
sc/inc/column.hxx | 5
sc/source/core/data/cellclonehandler.cxx | 116 ---------
sc/source/core/data/column.cxx | 360 ++++++++++++++++++-------------
sc/source/core/data/column3.cxx | 106 ---------
6 files changed, 219 insertions(+), 437 deletions(-)
New commits:
commit 3ef31651e7dd52630d02b85081d35c64a2f4f395
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Wed Jun 26 02:53:40 2013 -0400
Remove these unused files.
Change-Id: Ifcff5ee2849f9f390f82197fa60a3cea12dd0b27
diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk
index 94c9a52..a2fcfc5 100644
--- a/sc/Library_sc.mk
+++ b/sc/Library_sc.mk
@@ -100,7 +100,6 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
sc/source/core/data/autonamecache \
sc/source/core/data/bcaslot \
sc/source/core/data/bigrange \
- sc/source/core/data/cellclonehandler \
sc/source/core/data/cellvalue \
sc/source/core/data/clipcontext \
sc/source/core/data/clipparam \
diff --git a/sc/inc/cellclonehandler.hxx b/sc/inc/cellclonehandler.hxx
deleted file mode 100644
index 4ae8123..0000000
--- a/sc/inc/cellclonehandler.hxx
+++ /dev/null
@@ -1,68 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-#ifndef SC_CELLCLONEHANDLER_HXX
-#define SC_CELLCLONEHANDLER_HXX
-
-#include "rtl/ustring.hxx"
-#include "address.hxx"
-#include "mtvelements.hxx"
-
-class ScDocument;
-class EditTextObject;
-class ScFormulaCell;
-
-namespace sc {
-
-class CellBlockCloneHandler
-{
- ScDocument& mrSrcDoc;
- ScDocument& mrDestDoc;
- CellStoreType& mrDestCellStore;
- CellTextAttrStoreType& mrDestAttrStore;
-
-protected:
- ScDocument& getSrcDoc();
- ScDocument& getDestDoc();
- const ScDocument& getDestDoc() const;
- CellStoreType& getDestCellStore();
- CellTextAttrStoreType& getDestAttrStore();
-
- void setDefaultAttrToDest(ColumnBlockPosition& rPos, SCROW nRow);
- void setDefaultAttrsToDest(ColumnBlockPosition& rPos, SCROW nRow, size_t nSize);
-
-public:
- CellBlockCloneHandler(
- ScDocument& rSrcDoc, ScDocument& rDestDoc,
- CellStoreType& rDestCellStore, CellTextAttrStoreType& rDestAttrStore);
-
- virtual ~CellBlockCloneHandler();
-
- virtual void cloneDoubleBlock(
- ColumnBlockPosition& rPos, const ScAddress& rSrcPos, const ScAddress& rDestPos,
- const numeric_block::const_iterator& itBegin, const numeric_block::const_iterator& itEnd);
-
- virtual void cloneStringBlock(
- ColumnBlockPosition& rPos, const ScAddress& rSrcPos, const ScAddress& rDestPos,
- const string_block::const_iterator& itBegin, const string_block::const_iterator& itEnd);
-
- virtual void cloneEditTextBlock(
- ColumnBlockPosition& rPos, const ScAddress& rSrcPos, const ScAddress& rDestPos,
- const edittext_block::const_iterator& itBegin, const edittext_block::const_iterator& itEnd);
-
- virtual void cloneFormulaBlock(
- ColumnBlockPosition& rPos, const ScAddress& rSrcPos, const ScAddress& rDestPos,
- const formula_block::const_iterator& itBegin, const formula_block::const_iterator& itEnd);
-};
-
-}
-
-#endif
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 8e4502a..93d292d 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -45,7 +45,6 @@ namespace sc {
class CopyToDocContext;
class MixDocContext;
struct ColumnBlockPosition;
- class CellBlockCloneHandler;
class SingleColumnSpanSet;
}
diff --git a/sc/source/core/data/cellclonehandler.cxx b/sc/source/core/data/cellclonehandler.cxx
deleted file mode 100644
index 8f5bd17..0000000
--- a/sc/source/core/data/cellclonehandler.cxx
+++ /dev/null
@@ -1,116 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-#include "cellclonehandler.hxx"
-#include "editutil.hxx"
-#include "document.hxx"
-
-namespace sc {
-
-CellBlockCloneHandler::CellBlockCloneHandler(
- ScDocument& rSrcDoc, ScDocument& rDestDoc,
- CellStoreType& rDestCellStore, CellTextAttrStoreType& rDestAttrStore) :
- mrSrcDoc(rSrcDoc), mrDestDoc(rDestDoc),
- mrDestCellStore(rDestCellStore), mrDestAttrStore(rDestAttrStore) {}
-
-CellBlockCloneHandler::~CellBlockCloneHandler() {}
-
-ScDocument& CellBlockCloneHandler::getSrcDoc()
-{
- return mrSrcDoc;
-}
-
-ScDocument& CellBlockCloneHandler::getDestDoc()
-{
- return mrDestDoc;
-}
-
-const ScDocument& CellBlockCloneHandler::getDestDoc() const
-{
- return mrDestDoc;
-}
-
-CellStoreType& CellBlockCloneHandler::getDestCellStore()
-{
- return mrDestCellStore;
-}
-
-CellTextAttrStoreType& CellBlockCloneHandler::getDestAttrStore()
-{
- return mrDestAttrStore;
-}
-
-void CellBlockCloneHandler::setDefaultAttrToDest(ColumnBlockPosition& rPos, SCROW nRow)
-{
- rPos.miCellTextAttrPos = mrDestAttrStore.set(rPos.miCellTextAttrPos, nRow, CellTextAttr());
-}
-
-void CellBlockCloneHandler::setDefaultAttrsToDest(ColumnBlockPosition& rPos, SCROW nRow, size_t nSize)
-{
- std::vector<sc::CellTextAttr> aAttrs(nSize); // default values
- rPos.miCellTextAttrPos = mrDestAttrStore.set(
- rPos.miCellTextAttrPos, nRow, aAttrs.begin(), aAttrs.end());
-}
-
-void CellBlockCloneHandler::cloneDoubleBlock(
- ColumnBlockPosition& rPos, const ScAddress& /*rSrcPos*/, const ScAddress& rDestPos,
- const numeric_block::const_iterator& itBegin, const numeric_block::const_iterator& itEnd)
-{
- rPos.miCellPos = mrDestCellStore.set(rPos.miCellPos, rDestPos.Row(), itBegin, itEnd);
- setDefaultAttrsToDest(rPos, rDestPos.Row(), std::distance(itBegin, itEnd));
-}
-
-void CellBlockCloneHandler::cloneStringBlock(
- ColumnBlockPosition& rPos, const ScAddress& /*rSrcPos*/, const ScAddress& rDestPos,
- const string_block::const_iterator& itBegin, const string_block::const_iterator& itEnd)
-{
- rPos.miCellPos = mrDestCellStore.set(rPos.miCellPos, rDestPos.Row(), itBegin, itEnd);
- setDefaultAttrsToDest(rPos, rDestPos.Row(), std::distance(itBegin, itEnd));
-}
-
-void CellBlockCloneHandler::cloneEditTextBlock(
- ColumnBlockPosition& rPos, const ScAddress& /*rSrcPos*/, const ScAddress& rDestPos,
- const edittext_block::const_iterator& itBegin, const edittext_block::const_iterator& itEnd)
-{
- std::vector<EditTextObject*> aCloned;
- aCloned.reserve(std::distance(itBegin, itEnd));
- for (edittext_block::const_iterator it = itBegin; it != itEnd; ++it)
- aCloned.push_back(ScEditUtil::Clone(**it, getDestDoc()));
-
- rPos.miCellPos = getDestCellStore().set(
- rPos.miCellPos, rDestPos.Row(), aCloned.begin(), aCloned.end());
-
- setDefaultAttrsToDest(rPos, rDestPos.Row(), std::distance(itBegin, itEnd));
-}
-
-void CellBlockCloneHandler::cloneFormulaBlock(
- ColumnBlockPosition& rPos, const ScAddress& /*rSrcPos*/, const ScAddress& rDestPos,
- const formula_block::const_iterator& itBegin, const formula_block::const_iterator& itEnd)
-{
- std::vector<ScFormulaCell*> aCloned;
- aCloned.reserve(std::distance(itBegin, itEnd));
- ScAddress aDestPos = rDestPos;
- for (formula_block::const_iterator it = itBegin; it != itEnd; ++it, aDestPos.IncRow())
- {
- const ScFormulaCell& rOld = **it;
- if (rOld.GetDirty() && getSrcDoc().GetAutoCalc())
- const_cast<ScFormulaCell&>(rOld).Interpret();
-
- aCloned.push_back(new ScFormulaCell(rOld, getDestDoc(), aDestPos));
- }
-
- rPos.miCellPos = getDestCellStore().set(
- rPos.miCellPos, rDestPos.Row(), aCloned.begin(), aCloned.end());
-
- setDefaultAttrsToDest(rPos, rDestPos.Row(), std::distance(itBegin, itEnd));
-}
-
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index 3f54d59..f3fb8cf 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -36,7 +36,6 @@
#include "clipcontext.hxx"
#include "types.hxx"
#include "editutil.hxx"
-#include "cellclonehandler.hxx"
#include "mtvcellfunc.hxx"
#include "columnspanset.hxx"
#include "scopetools.hxx"
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index f95d565..227a69b 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -44,7 +44,6 @@
#include "columnspanset.hxx"
#include "mtvcellfunc.hxx"
#include "scopetools.hxx"
-#include "cellclonehandler.hxx"
#include "editutil.hxx"
#include <com/sun/star/i18n/LocaleDataItem.hpp>
commit ec8e986a1f6b25660e8ac785ed3aac114b0c485e
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Wed Jun 26 02:49:00 2013 -0400
Adopt CopyAsLinkHandler as well.
With this, we no longer use CopyCellsInRangeToColumn().
Change-Id: I6506d72d084f724ccf7a6395a0daf88fe7bff40e
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index c6b3945..8e4502a 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -485,10 +485,6 @@ public:
private:
- void CopyCellsInRangeToColumn(
- sc::ColumnBlockConstPosition* rSrcColPos, sc::ColumnBlockPosition* pDestColPos,
- sc::CellBlockCloneHandler& Hdl, SCROW nRow1, SCROW nRow2, ScColumn& rColumn ) const;
-
sc::CellStoreType::iterator GetPositionToInsert( SCROW nRow );
sc::CellStoreType::iterator GetPositionToInsert( const sc::CellStoreType::iterator& it, SCROW nRow );
void ActivateNewFormulaCell( ScFormulaCell* pCell );
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index 2310212..3f54d59 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -1558,92 +1558,114 @@ bool canCopyValue(const ScDocument& rDoc, const ScAddress& rPos, sal_uInt16 nFla
return ((nFlags & IDF_VALUE) != 0);
}
-class CopyAsLinkHandler : public sc::CellBlockCloneHandler
+class CopyAsLinkHandler
{
+ const ScColumn& mrSrcCol;
+ ScColumn& mrDestCol;
+ sc::ColumnBlockPosition maDestPos;
+ sc::ColumnBlockPosition* mpDestPos;
sal_uInt16 mnCopyFlags;
std::vector<ScFormulaCell*> maCellBuffer;
- ScFormulaCell* createRefCell(const ScAddress& rSrcPos, const ScAddress& rDestPos)
+ void setDefaultAttrToDest(size_t nRow)
+ {
+ maDestPos.miCellTextAttrPos = mrDestCol.GetCellAttrStore().set(
+ maDestPos.miCellTextAttrPos, nRow, sc::CellTextAttr());
+ }
+
+ void setDefaultAttrsToDest(size_t nRow, size_t nSize)
+ {
+ std::vector<sc::CellTextAttr> aAttrs(nSize); // default values
+ maDestPos.miCellTextAttrPos = mrDestCol.GetCellAttrStore().set(
+ maDestPos.miCellTextAttrPos, nRow, aAttrs.begin(), aAttrs.end());
+ }
+
+ ScFormulaCell* createRefCell(size_t nRow)
{
ScSingleRefData aRef;
- aRef.InitAddress(rSrcPos); // Absolute reference.
+ aRef.InitAddress(ScAddress(mrSrcCol.GetCol(), nRow, mrSrcCol.GetTab())); // Absolute reference.
aRef.SetFlag3D(true);
ScTokenArray aArr;
aArr.AddSingleReference(aRef);
- return new ScFormulaCell(&getDestDoc(), rDestPos, &aArr);
+ return new ScFormulaCell(&mrDestCol.GetDoc(), ScAddress(mrDestCol.GetCol(), nRow, mrDestCol.GetTab()), &aArr);
}
- template<typename _DataBlock>
- void createRefBlock(
- sc::ColumnBlockPosition& rPos, const ScAddress& rSrcPos, const ScAddress& rDestPos,
- const typename _DataBlock::const_iterator& itBegin, const typename _DataBlock::const_iterator& itEnd)
+ void createRefBlock(const sc::CellStoreType::value_type& aNode, size_t nOffset, size_t nDataSize)
{
- size_t nSize = std::distance(itBegin, itEnd);
+ size_t nTopRow = aNode.position + nOffset;
+
maCellBuffer.clear();
- maCellBuffer.reserve(nSize);
- ScAddress aSrcPos = rSrcPos;
- ScAddress aDestPos = rDestPos;
- for (typename _DataBlock::const_iterator it = itBegin; it != itEnd; ++it, aSrcPos.IncRow(), aDestPos.IncRow())
- maCellBuffer.push_back(createRefCell(aSrcPos, aDestPos));
+ maCellBuffer.reserve(nDataSize);
+
+ for (size_t i = 0; i < nDataSize; ++i)
+ maCellBuffer.push_back(createRefCell(nTopRow + i));
- rPos.miCellPos = getDestCellStore().set(rPos.miCellPos, rDestPos.Row(), maCellBuffer.begin(), maCellBuffer.end());
- setDefaultAttrsToDest(rPos, rDestPos.Row(), nSize);
+ maDestPos.miCellPos = mrDestCol.GetCellStore().set(maDestPos.miCellPos, nTopRow, maCellBuffer.begin(), maCellBuffer.end());
+ setDefaultAttrsToDest(nTopRow, nDataSize);
}
public:
- CopyAsLinkHandler(
- ScDocument& rSrcDoc, ScDocument& rDestDoc, sc::CellStoreType& rDestCellStore, sc::CellTextAttrStoreType& rDestAttrStore, sal_uInt16 nCopyFlags) :
- sc::CellBlockCloneHandler(rSrcDoc, rDestDoc, rDestCellStore, rDestAttrStore),
- mnCopyFlags(nCopyFlags) {}
-
- virtual void cloneDoubleBlock(
- sc::ColumnBlockPosition& rPos, const ScAddress& rSrcPos, const ScAddress& rDestPos,
- const sc::numeric_block::const_iterator& itBegin, const sc::numeric_block::const_iterator& itEnd)
+ CopyAsLinkHandler(const ScColumn& rSrcCol, ScColumn& rDestCol, sc::ColumnBlockPosition* pDestPos, sal_uInt16 nCopyFlags) :
+ mrSrcCol(rSrcCol), mrDestCol(rDestCol), mpDestPos(pDestPos), mnCopyFlags(nCopyFlags)
{
- if ((mnCopyFlags & (IDF_DATETIME|IDF_VALUE)) == 0)
- return;
-
- ScAddress aSrcPos = rSrcPos;
- ScAddress aDestPos = rDestPos;
- for (sc::numeric_block::const_iterator it = itBegin; it != itEnd; ++it, aSrcPos.IncRow(), aDestPos.IncRow())
- {
- if (!canCopyValue(getSrcDoc(), aSrcPos, mnCopyFlags))
- continue;
-
- rPos.miCellPos = getDestCellStore().set(rPos.miCellPos, aDestPos.Row(), createRefCell(aSrcPos, aDestPos));
- setDefaultAttrToDest(rPos, aDestPos.Row());
- }
+ if (mpDestPos)
+ maDestPos = *mpDestPos;
}
- virtual void cloneStringBlock(
- sc::ColumnBlockPosition& rPos, const ScAddress& rSrcPos, const ScAddress& rDestPos,
- const sc::string_block::const_iterator& itBegin, const sc::string_block::const_iterator& itEnd)
+ ~CopyAsLinkHandler()
{
- if (!(mnCopyFlags & IDF_STRING))
- return;
-
- createRefBlock<sc::string_block>(rPos, rSrcPos, rDestPos, itBegin, itEnd);
+ if (mpDestPos)
+ *mpDestPos = maDestPos;
}
- virtual void cloneEditTextBlock(
- sc::ColumnBlockPosition& rPos, const ScAddress& rSrcPos, const ScAddress& rDestPos,
- const sc::edittext_block::const_iterator& itBegin, const sc::edittext_block::const_iterator& itEnd)
+ void operator() (const sc::CellStoreType::value_type& aNode, size_t nOffset, size_t nDataSize)
{
- if (!(mnCopyFlags & IDF_STRING))
- return;
+ size_t nRow = aNode.position - nOffset;
- createRefBlock<sc::edittext_block>(rPos, rSrcPos, rDestPos, itBegin, itEnd);
- }
+ switch (aNode.type)
+ {
+ case sc::element_type_numeric:
+ {
+ if ((mnCopyFlags & (IDF_DATETIME|IDF_VALUE)) == 0)
+ return;
- virtual void cloneFormulaBlock(
- sc::ColumnBlockPosition& rPos, const ScAddress& rSrcPos, const ScAddress& rDestPos,
- const sc::formula_block::const_iterator& itBegin, const sc::formula_block::const_iterator& itEnd)
- {
- if (!(mnCopyFlags & IDF_FORMULA))
- return;
+ sc::numeric_block::const_iterator it = sc::numeric_block::begin(*aNode.data);
+ std::advance(it, nOffset);
+ sc::numeric_block::const_iterator itEnd = it;
+ std::advance(itEnd, nDataSize);
- createRefBlock<sc::formula_block>(rPos, rSrcPos, rDestPos, itBegin, itEnd);
+ ScAddress aSrcPos(mrSrcCol.GetCol(), nRow, mrSrcCol.GetTab());
+ for (; it != itEnd; ++it, aSrcPos.IncRow(), ++nRow)
+ {
+ if (!canCopyValue(mrSrcCol.GetDoc(), aSrcPos, mnCopyFlags))
+ continue;
+
+ maDestPos.miCellPos = mrDestCol.GetCellStore().set(maDestPos.miCellPos, nRow, createRefCell(nRow));
+ setDefaultAttrToDest(nRow);
+ }
+ }
+ break;
+ case sc::element_type_string:
+ case sc::element_type_edittext:
+ {
+ if (!(mnCopyFlags & IDF_STRING))
+ return;
+
+ createRefBlock(aNode, nOffset, nDataSize);
+ }
+ break;
+ case sc::element_type_formula:
+ {
+ if (!(mnCopyFlags & IDF_FORMULA))
+ return;
+
+ createRefBlock(aNode, nOffset, nDataSize);
+ }
+ break;
+ default:
+ ;
+ }
}
};
@@ -1920,21 +1942,19 @@ void ScColumn::CopyToColumn(
if ((nFlags & IDF_CONTENTS) != 0)
{
- boost::scoped_ptr<sc::CellBlockCloneHandler> pHdl(NULL);
-
if (bAsLink)
{
- pHdl.reset(new CopyAsLinkHandler(*pDocument, *rColumn.pDocument, rColumn.maCells, rColumn.maCellTextAttrs, nFlags));
- CopyCellsInRangeToColumn(NULL, rCxt.getBlockPosition(rColumn.nTab, rColumn.nCol), *pHdl, nRow1, nRow2, rColumn);
+ CopyAsLinkHandler aFunc(*this, rColumn, rCxt.getBlockPosition(rColumn.nTab, rColumn.nCol), nFlags);
+ sc::ParseBlock(maCells.begin(), maCells, aFunc, nRow1, nRow2);
}
else
{
CopyByCloneHandler aFunc(*this, rColumn, rCxt.getBlockPosition(rColumn.nTab, rColumn.nCol), nFlags);
sc::ParseBlock(maCells.begin(), maCells, aFunc, nRow1, nRow2);
- rColumn.RegroupFormulaCells(nRow1, nRow2);
- rColumn.CellStorageModified();
}
+ rColumn.RegroupFormulaCells(nRow1, nRow2);
+ rColumn.CellStorageModified();
}
}
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index b8e8e10..f95d565 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -323,111 +323,6 @@ void ScColumn::DeleteRow( SCROW nStartRow, SCSIZE nSize )
std::for_each(aSpans.begin(), aSpans.end(), RangeBroadcaster(*pDocument, nTab, nCol));
}
-void ScColumn::CopyCellsInRangeToColumn(
- sc::ColumnBlockConstPosition* pSrcColPos,
- sc::ColumnBlockPosition* pDestColPos, sc::CellBlockCloneHandler& rHdl, SCROW nRow1, SCROW nRow2, ScColumn& rColumn ) const
-{
- sc::ColumnBlockConstPosition aSrcColPos;
- sc::ColumnBlockPosition aDestColPos;
-
- if (pSrcColPos)
- aSrcColPos = *pSrcColPos;
- else
- InitBlockPosition(aSrcColPos);
-
- if (pDestColPos)
- aDestColPos = *pDestColPos;
- else
- rColumn.InitBlockPosition(aDestColPos);
-
- std::pair<sc::CellStoreType::const_iterator,size_t> aPos = maCells.position(aSrcColPos.miCellPos, nRow1);
- sc::CellStoreType::const_iterator it = aPos.first;
- aSrcColPos.miCellPos = aPos.first;
- size_t nOffset = aPos.second;
- size_t nDataSize = 0;
- size_t nCurRow = nRow1;
-
- for (; it != maCells.end() && nCurRow <= static_cast<size_t>(nRow2); ++it, nOffset = 0, nCurRow += nDataSize)
- {
- bool bLastBlock = false;
- nDataSize = it->size - nOffset;
- if (nCurRow + nDataSize - 1 > static_cast<size_t>(nRow2))
- {
- // Truncate the block to copy to clipboard.
- nDataSize = nRow2 - nCurRow + 1;
- bLastBlock = true;
- }
-
- switch (it->type)
- {
- case sc::element_type_numeric:
- {
- sc::numeric_block::const_iterator itData = sc::numeric_block::begin(*it->data);
- std::advance(itData, nOffset);
- sc::numeric_block::const_iterator itDataEnd = itData;
- std::advance(itDataEnd, nDataSize);
- ScAddress aSrcPos(nCol, nCurRow, nTab);
- ScAddress aDestPos(rColumn.nCol, nCurRow, rColumn.nTab);
- rHdl.cloneDoubleBlock(aDestColPos, aSrcPos, aDestPos, itData, itDataEnd);
- }
- break;
- case sc::element_type_string:
- {
- sc::string_block::const_iterator itData = sc::string_block::begin(*it->data);
- std::advance(itData, nOffset);
- sc::string_block::const_iterator itDataEnd = itData;
- std::advance(itDataEnd, nDataSize);
- ScAddress aSrcPos(nCol, nCurRow, nTab);
- ScAddress aDestPos(rColumn.nCol, nCurRow, rColumn.nTab);
- rHdl.cloneStringBlock(aDestColPos, aSrcPos, aDestPos, itData, itDataEnd);
- }
- break;
- case sc::element_type_edittext:
- {
- sc::edittext_block::const_iterator itData = sc::edittext_block::begin(*it->data);
- std::advance(itData, nOffset);
- sc::edittext_block::const_iterator itDataEnd = itData;
- std::advance(itDataEnd, nDataSize);
- ScAddress aSrcPos(nCol, nCurRow, nTab);
- ScAddress aDestPos(rColumn.nCol, nCurRow, rColumn.nTab);
- rHdl.cloneEditTextBlock(aDestColPos, aSrcPos, aDestPos, itData, itDataEnd);
- }
- break;
- case sc::element_type_formula:
- {
- sc::formula_block::const_iterator itData = sc::formula_block::begin(*it->data);
- std::advance(itData, nOffset);
- sc::formula_block::const_iterator itDataEnd = itData;
- std::advance(itDataEnd, nDataSize);
- ScAddress aSrcPos(nCol, nCurRow, nTab);
- ScAddress aDestPos(rColumn.nCol, nCurRow, rColumn.nTab);
- rHdl.cloneFormulaBlock(aDestColPos, aSrcPos, aDestPos, itData, itDataEnd);
- }
- break;
- default:
- ;
- }
-
- if (bLastBlock)
- break;
- }
-
- if (pSrcColPos)
- {
- // Save the positions for the next iteration.
- *pSrcColPos = aSrcColPos;
- }
-
- if (pDestColPos)
- {
- // Save the positions for the next iteration.
- *pDestColPos = aDestColPos;
- }
-
- rColumn.RegroupFormulaCells(nRow1, nRow2);
- rColumn.CellStorageModified();
-}
-
sc::CellStoreType::iterator ScColumn::GetPositionToInsert( SCROW nRow )
{
return GetPositionToInsert(maCells.begin(), nRow);
commit 09857339718989260eaeff0451c4ec280717cdbb
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Wed Jun 26 02:02:14 2013 -0400
Adopt CopyByCloneHandler to ParseBlock().
Change-Id: Iac82967a9cdd1b7c3e062b1931bb306cf160bba0
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index c561035..2310212 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -1302,7 +1302,7 @@ public:
void operator() (const sc::CellStoreType::value_type& aNode, size_t nOffset, size_t nDataSize)
{
- size_t nTopRow = aNode.position;
+ size_t nTopRow = aNode.position - nOffset;
switch (aNode.type)
{
@@ -1647,14 +1647,31 @@ public:
}
};
-class CopyByCloneHandler : public sc::CellBlockCloneHandler
+class CopyByCloneHandler
{
+ const ScColumn& mrSrcCol;
+ ScColumn& mrDestCol;
+ sc::ColumnBlockPosition maDestPos;
+ sc::ColumnBlockPosition* mpDestPos;
sal_uInt16 mnCopyFlags;
- void cloneFormulaCell(
- sc::ColumnBlockPosition& rPos, const ScAddress& rSrcPos, const ScAddress& rDestPos,
- ScFormulaCell& rSrcCell)
+ void setDefaultAttrToDest(size_t nRow)
{
+ maDestPos.miCellTextAttrPos = mrDestCol.GetCellAttrStore().set(
+ maDestPos.miCellTextAttrPos, nRow, sc::CellTextAttr());
+ }
+
+ void setDefaultAttrsToDest(size_t nRow, size_t nSize)
+ {
+ std::vector<sc::CellTextAttr> aAttrs(nSize); // default values
+ maDestPos.miCellTextAttrPos = mrDestCol.GetCellAttrStore().set(
+ maDestPos.miCellTextAttrPos, nRow, aAttrs.begin(), aAttrs.end());
+ }
+
+ void cloneFormulaCell(size_t nRow, ScFormulaCell& rSrcCell)
+ {
+ ScAddress aDestPos(mrDestCol.GetCol(), nRow, mrDestCol.GetTab());
+
bool bCloneValue = (mnCopyFlags & IDF_VALUE) != 0;
bool bCloneDateTime = (mnCopyFlags & IDF_DATETIME) != 0;
bool bCloneString = (mnCopyFlags & IDF_STRING) != 0;
@@ -1679,15 +1696,14 @@ class CopyByCloneHandler : public sc::CellBlockCloneHandler
if (bForceFormula || bCloneFormula)
{
// Clone as formula cell.
- ScFormulaCell* pCell = new ScFormulaCell(rSrcCell, getDestDoc(), rDestPos);
+ ScFormulaCell* pCell = new ScFormulaCell(rSrcCell, mrDestCol.GetDoc(), aDestPos);
pCell->SetDirtyVar();
- rPos.miCellPos = getDestCellStore().set(rPos.miCellPos, rDestPos.Row(), pCell);
- setDefaultAttrToDest(rPos, rDestPos.Row());
-
+ maDestPos.miCellPos = mrDestCol.GetCellStore().set(maDestPos.miCellPos, nRow, pCell);
+ setDefaultAttrToDest(nRow);
return;
}
- if (getDestDoc().IsUndo())
+ if (mrDestCol.GetDoc().IsUndo())
return;
if (bCloneValue)
@@ -1696,11 +1712,11 @@ class CopyByCloneHandler : public sc::CellBlockCloneHandler
if (nErr)
{
// error codes are cloned with values
- ScFormulaCell* pErrCell = new ScFormulaCell(&getDestDoc(), rDestPos);
+ ScFormulaCell* pErrCell = new ScFormulaCell(&mrDestCol.GetDoc(), aDestPos);
pErrCell->SetErrCode(nErr);
- rPos.miCellPos = getDestCellStore().set(
- rPos.miCellPos, rDestPos.Row(), new ScFormulaCell(rSrcCell, getDestDoc(), rDestPos));
- setDefaultAttrToDest(rPos, rDestPos.Row());
+ maDestPos.miCellPos = mrDestCol.GetCellStore().set(
+ maDestPos.miCellPos, nRow, new ScFormulaCell(rSrcCell, mrDestCol.GetDoc(), aDestPos));
+ setDefaultAttrToDest(nRow);
return;
}
}
@@ -1709,11 +1725,11 @@ class CopyByCloneHandler : public sc::CellBlockCloneHandler
{
if (rSrcCell.IsValue())
{
- if (canCopyValue(getSrcDoc(), rSrcPos, mnCopyFlags))
+ if (canCopyValue(mrSrcCol.GetDoc(), ScAddress(mrSrcCol.GetCol(), nRow, mrSrcCol.GetTab()), mnCopyFlags))
{
- rPos.miCellPos = getDestCellStore().set(
- rPos.miCellPos, rDestPos.Row(), rSrcCell.GetValue());
- setDefaultAttrToDest(rPos, rDestPos.Row());
+ maDestPos.miCellPos = mrDestCol.GetCellStore().set(
+ maDestPos.miCellPos, nRow, rSrcCell.GetValue());
+ setDefaultAttrToDest(nRow);
}
return;
@@ -1730,91 +1746,127 @@ class CopyByCloneHandler : public sc::CellBlockCloneHandler
if (rSrcCell.IsMultilineResult())
{
// Clone as an edit text object.
- EditEngine& rEngine = getDestDoc().GetEditEngine();
+ EditEngine& rEngine = mrDestCol.GetDoc().GetEditEngine();
rEngine.SetText(aStr);
- rPos.miCellPos =
- getDestCellStore().set(rPos.miCellPos, rDestPos.Row(), rEngine.CreateTextObject());
+ maDestPos.miCellPos =
+ mrDestCol.GetCellStore().set(maDestPos.miCellPos, nRow, rEngine.CreateTextObject());
}
else
{
- rPos.miCellPos =
- getDestCellStore().set(rPos.miCellPos, rDestPos.Row(), aStr);
+ maDestPos.miCellPos =
+ mrDestCol.GetCellStore().set(maDestPos.miCellPos, nRow, aStr);
}
- setDefaultAttrToDest(rPos, rDestPos.Row());
+ setDefaultAttrToDest(nRow);
}
}
public:
- CopyByCloneHandler(ScDocument& rSrcDoc, ScDocument& rDestDoc,
- sc::CellStoreType& rDestCellStore, sc::CellTextAttrStoreType& rDestAttrStore, sal_uInt16 nCopyFlags) :
- sc::CellBlockCloneHandler(rSrcDoc, rDestDoc, rDestCellStore, rDestAttrStore),
- mnCopyFlags(nCopyFlags)
+ CopyByCloneHandler(const ScColumn& rSrcCol, ScColumn& rDestCol, sc::ColumnBlockPosition* pDestPos, sal_uInt16 nCopyFlags) :
+ mrSrcCol(rSrcCol), mrDestCol(rDestCol), mpDestPos(pDestPos), mnCopyFlags(nCopyFlags)
{
+ if (mpDestPos)
+ maDestPos = *mpDestPos;
}
- virtual void cloneDoubleBlock(
- sc::ColumnBlockPosition& rPos, const ScAddress& rSrcPos, const ScAddress& rDestPos,
- const sc::numeric_block::const_iterator& itBegin, const sc::numeric_block::const_iterator& itEnd)
+ ~CopyByCloneHandler()
{
- if ((mnCopyFlags & (IDF_DATETIME|IDF_VALUE)) == 0)
- return;
-
- ScAddress aSrcPos = rSrcPos;
- ScAddress aDestPos = rDestPos;
- for (sc::numeric_block::const_iterator it = itBegin; it != itEnd; ++it, aSrcPos.IncRow(), aDestPos.IncRow())
- {
- if (!canCopyValue(getSrcDoc(), aSrcPos, mnCopyFlags))
- continue;
-
- rPos.miCellPos = getDestCellStore().set(rPos.miCellPos, aDestPos.Row(), *it);
- setDefaultAttrToDest(rPos, aDestPos.Row());
- }
+ if (mpDestPos)
+ *mpDestPos = maDestPos;
}
- virtual void cloneStringBlock(
- sc::ColumnBlockPosition& rPos, const ScAddress& /*rSrcPos*/, const ScAddress& rDestPos,
- const sc::string_block::const_iterator& itBegin, const sc::string_block::const_iterator& itEnd)
+ void operator() (const sc::CellStoreType::value_type& aNode, size_t nOffset, size_t nDataSize)
{
- if (!(mnCopyFlags & IDF_STRING))
- return;
+ size_t nRow = aNode.position - nOffset;
- ScAddress aDestPos = rDestPos;
- for (sc::string_block::const_iterator it = itBegin; it != itEnd; ++it, aDestPos.IncRow())
+ switch (aNode.type)
{
- const OUString& rStr = *it;
- if (rStr.isEmpty())
+ case sc::element_type_numeric:
{
- // String cell with empty value is used to special-case cell value removal.
- rPos.miCellPos = getDestCellStore().set_empty(rPos.miCellPos, aDestPos.Row(), aDestPos.Row());
- rPos.miCellTextAttrPos = getDestAttrStore().set_empty(rPos.miCellTextAttrPos, aDestPos.Row(), aDestPos.Row());
+ if ((mnCopyFlags & (IDF_DATETIME|IDF_VALUE)) == 0)
+ return;
+
+ sc::numeric_block::const_iterator it = sc::numeric_block::begin(*aNode.data);
+ std::advance(it, nOffset);
+ sc::numeric_block::const_iterator itEnd = it;
+ std::advance(itEnd, nDataSize);
+
+ ScAddress aSrcPos(mrSrcCol.GetCol(), nRow, mrSrcCol.GetTab());
+ for (; it != itEnd; ++it, aSrcPos.IncRow(), ++nRow)
+ {
+ if (!canCopyValue(mrSrcCol.GetDoc(), aSrcPos, mnCopyFlags))
+ continue;
+
+ maDestPos.miCellPos = mrDestCol.GetCellStore().set(maDestPos.miCellPos, nRow, *it);
+ setDefaultAttrToDest(nRow);
+ }
}
- else
+ break;
+ case sc::element_type_string:
{
- rPos.miCellPos = getDestCellStore().set(rPos.miCellPos, aDestPos.Row(), rStr);
- setDefaultAttrToDest(rPos, aDestPos.Row());
+ if (!(mnCopyFlags & IDF_STRING))
+ return;
+
+ sc::string_block::const_iterator it = sc::string_block::begin(*aNode.data);
+ std::advance(it, nOffset);
+ sc::string_block::const_iterator itEnd = it;
+ std::advance(itEnd, nDataSize);
+
+ for (; it != itEnd; ++it, ++nRow)
+ {
+ const OUString& rStr = *it;
+ if (rStr.isEmpty())
+ {
+ // String cell with empty value is used to special-case cell value removal.
+ maDestPos.miCellPos = mrDestCol.GetCellStore().set_empty(
+ maDestPos.miCellPos, nRow, nRow);
+ maDestPos.miCellTextAttrPos = mrDestCol.GetCellAttrStore().set_empty(
+ maDestPos.miCellTextAttrPos, nRow, nRow);
+ }
+ else
+ {
+ maDestPos.miCellPos =
+ mrDestCol.GetCellStore().set(maDestPos.miCellPos, nRow, rStr);
+ setDefaultAttrToDest(nRow);
+ }
+ }
}
- }
- }
+ break;
+ case sc::element_type_edittext:
+ {
+ if (!(mnCopyFlags & IDF_STRING))
+ return;
- virtual void cloneEditTextBlock(
- sc::ColumnBlockPosition& rPos, const ScAddress& rSrcPos, const ScAddress& rDestPos,
- const sc::edittext_block::const_iterator& itBegin, const sc::edittext_block::const_iterator& itEnd)
- {
- if (!(mnCopyFlags & IDF_STRING))
- return;
+ sc::edittext_block::const_iterator it = sc::edittext_block::begin(*aNode.data);
+ std::advance(it, nOffset);
+ sc::edittext_block::const_iterator itEnd = it;
+ std::advance(itEnd, nDataSize);
- sc::CellBlockCloneHandler::cloneEditTextBlock(rPos, rSrcPos, rDestPos, itBegin, itEnd);
- }
+ std::vector<EditTextObject*> aCloned;
+ aCloned.reserve(nDataSize);
+ for (; it != itEnd; ++it)
+ aCloned.push_back(ScEditUtil::Clone(**it, mrDestCol.GetDoc()));
- virtual void cloneFormulaBlock(
- sc::ColumnBlockPosition& rPos, const ScAddress& rSrcPos, const ScAddress& rDestPos,
- const sc::formula_block::const_iterator& itBegin, const sc::formula_block::const_iterator& itEnd)
- {
- ScAddress aSrcPos = rSrcPos;
- ScAddress aDestPos = rDestPos;
- for (sc::formula_block::const_iterator it = itBegin; it != itEnd; ++it, aSrcPos.IncRow(), aDestPos.IncRow())
- cloneFormulaCell(rPos, aSrcPos, aDestPos, const_cast<ScFormulaCell&>(**it));
+ maDestPos.miCellPos = mrDestCol.GetCellStore().set(
+ maDestPos.miCellPos, nRow, aCloned.begin(), aCloned.end());
+
+ setDefaultAttrsToDest(nRow, nDataSize);
+ }
+ break;
+ case sc::element_type_formula:
+ {
+ sc::formula_block::const_iterator it = sc::formula_block::begin(*aNode.data);
+ std::advance(it, nOffset);
+ sc::formula_block::const_iterator itEnd = it;
+ std::advance(itEnd, nDataSize);
+
+ for (; it != itEnd; ++it, ++nRow)
+ cloneFormulaCell(nRow, const_cast<ScFormulaCell&>(**it));
+ }
+ break;
+ default:
+ ;
+ }
}
};
@@ -1871,11 +1923,18 @@ void ScColumn::CopyToColumn(
boost::scoped_ptr<sc::CellBlockCloneHandler> pHdl(NULL);
if (bAsLink)
+ {
pHdl.reset(new CopyAsLinkHandler(*pDocument, *rColumn.pDocument, rColumn.maCells, rColumn.maCellTextAttrs, nFlags));
+ CopyCellsInRangeToColumn(NULL, rCxt.getBlockPosition(rColumn.nTab, rColumn.nCol), *pHdl, nRow1, nRow2, rColumn);
+ }
else
- pHdl.reset(new CopyByCloneHandler(*pDocument, *rColumn.pDocument, rColumn.maCells, rColumn.maCellTextAttrs, nFlags));
+ {
+ CopyByCloneHandler aFunc(*this, rColumn, rCxt.getBlockPosition(rColumn.nTab, rColumn.nCol), nFlags);
+ sc::ParseBlock(maCells.begin(), maCells, aFunc, nRow1, nRow2);
+ rColumn.RegroupFormulaCells(nRow1, nRow2);
+ rColumn.CellStorageModified();
+ }
- CopyCellsInRangeToColumn(NULL, rCxt.getBlockPosition(rColumn.nTab, rColumn.nCol), *pHdl, nRow1, nRow2, rColumn);
}
}
More information about the Libreoffice-commits
mailing list