summaryrefslogtreecommitdiff
path: root/sc/source/core/data/clipcontext.cxx
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2013-05-16 13:52:33 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2013-05-20 20:13:08 -0400
commit4da9bf8086c90f0b0b4394cd6578da1405ca3e8d (patch)
tree85adb4c32012f1e65de7b5be258c2784a9ec7fae /sc/source/core/data/clipcontext.cxx
parentc232a8c4723e1a948fbeef2f7ea9486658191eeb (diff)
Cleaned up a bit to remove the need to initialize the block positions.
Change-Id: Iad2e69e4eb61167ad85581a83b19e3798c5edfd0
Diffstat (limited to 'sc/source/core/data/clipcontext.cxx')
-rw-r--r--sc/source/core/data/clipcontext.cxx65
1 files changed, 24 insertions, 41 deletions
diff --git a/sc/source/core/data/clipcontext.cxx b/sc/source/core/data/clipcontext.cxx
index e3e66a212910..1d19dd1258d1 100644
--- a/sc/source/core/data/clipcontext.cxx
+++ b/sc/source/core/data/clipcontext.cxx
@@ -12,9 +12,10 @@
namespace sc {
-CopyFromClipContext::CopyFromClipContext(
+CopyFromClipContext::CopyFromClipContext(ScDocument& rDoc,
ScDocument* pRefUndoDoc, ScDocument* pClipDoc, sal_uInt16 nInsertFlag,
bool bAsLink, bool bSkipAttrForEmptyCells) :
+ mrDoc(rDoc),
mpRefUndoDoc(pRefUndoDoc), mpClipDoc(pClipDoc), mnInsertFlag(nInsertFlag),
mnTabStart(-1), mnTabEnd(-1),
mbAsLink(bAsLink), mbSkipAttrForEmptyCells(bSkipAttrForEmptyCells) {}
@@ -23,44 +24,6 @@ CopyFromClipContext::~CopyFromClipContext()
{
}
-bool CopyFromClipContext::initBlockPositions(ScDocument& rDoc, SCCOL nCol1, SCCOL nCol2)
-{
- if (mnTabStart < 0 || mnTabEnd < 0 || mnTabStart > mnTabEnd)
- return false;
-
- size_t nSize = mnTabEnd - mnTabStart + 1;
- if (maTables.size() < nSize)
- maTables.resize(nSize);
-
- for (size_t i = 0; i < nSize; ++i)
- {
- SCTAB nTab = i + mnTabStart;
- ColumnsType& rCols = maTables[i];
- for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
- {
- ColumnsType::iterator it = rCols.find(nCol);
- if (it != rCols.end())
- // This column has already been initialized. Skip it.
- continue;
-
- std::pair<ColumnsType::iterator,bool> r =
- rCols.insert(
- ColumnsType::value_type(nCol, ColumnBlockPosition()));
-
- if (!r.second)
- // insertion failed.
- return false;
-
- it = r.first;
-
- if (!rDoc.InitColumnBlockPosition(it->second, nTab, nCol))
- return false;
- }
- }
-
- return true;
-}
-
void CopyFromClipContext::setTabRange(SCTAB nStart, SCTAB nEnd)
{
mnTabStart = nStart;
@@ -69,14 +32,34 @@ void CopyFromClipContext::setTabRange(SCTAB nStart, SCTAB nEnd)
ColumnBlockPosition* CopyFromClipContext::getBlockPosition(SCTAB nTab, SCCOL nCol)
{
+ if (mnTabStart < 0 || mnTabEnd < 0 || mnTabStart > mnTabEnd)
+ return NULL;
+
size_t nTabIndex = nTab - mnTabStart;
if (nTabIndex >= maTables.size())
- return NULL;
+ maTables.resize(nTabIndex+1);
ColumnsType& rCols = maTables[nTabIndex];
+
ColumnsType::iterator it = rCols.find(nCol);
+ if (it != rCols.end())
+ // Block position for this column has already been fetched.
+ return &it->second;
+
+ std::pair<ColumnsType::iterator,bool> r =
+ rCols.insert(
+ ColumnsType::value_type(nCol, ColumnBlockPosition()));
+
+ if (!r.second)
+ // insertion failed.
+ return NULL;
+
+ it = r.first;
+
+ if (!mrDoc.InitColumnBlockPosition(it->second, nTab, nCol))
+ return NULL;
- return it == rCols.end() ? NULL : &it->second;
+ return &it->second;
}
ScDocument* CopyFromClipContext::getUndoDoc()