summaryrefslogtreecommitdiff
path: root/sc/source/core/data
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2013-08-20 17:23:12 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2013-08-20 22:57:13 -0400
commit6c4bedffb98a33b202692b225fc250b858ff9f65 (patch)
tree3d1d30ff0c7dd352d2c39737a4ce38f7e93176c5 /sc/source/core/data
parent9ca5e3da5ca5f68ced1917cf38773fd1060bede4 (diff)
Add edit text iterator that iterates through only edit text cells.
Change-Id: I898d7a2d3f0ea472daddb9dd32f772a5d7268773
Diffstat (limited to 'sc/source/core/data')
-rw-r--r--sc/source/core/data/edittextiterator.cxx86
1 files changed, 86 insertions, 0 deletions
diff --git a/sc/source/core/data/edittextiterator.cxx b/sc/source/core/data/edittextiterator.cxx
new file mode 100644
index 000000000000..e563f04ae562
--- /dev/null
+++ b/sc/source/core/data/edittextiterator.cxx
@@ -0,0 +1,86 @@
+/* -*- 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 "edittextiterator.hxx"
+#include "document.hxx"
+#include "table.hxx"
+#include "column.hxx"
+
+namespace sc {
+
+EditTextIterator::EditTextIterator( const ScDocument& rDoc, SCTAB nTab ) :
+ mrTable(*rDoc.maTabs.at(nTab)),
+ mpCol(&mrTable.aCol[0]),
+ mpColEnd(mpCol + static_cast<size_t>(MAXCOLCOUNT)),
+ mpCells(&mpCol->maCells),
+ maPos(mpCells->position(0)),
+ miEnd(mpCells->end())
+{
+}
+
+const EditTextObject* EditTextIterator::seek()
+{
+ while (maPos.first->type != sc::element_type_edittext)
+ {
+ incBlock();
+ if (maPos.first == miEnd)
+ {
+ // Move to the next column.
+ ++mpCol;
+ if (mpCol == mpColEnd)
+ // No more columns.
+ return NULL;
+
+ mpCells = &mpCol->maCells;
+ maPos = mpCells->position(0);
+ miEnd = mpCells->end();
+ }
+ }
+
+ // We are on the right block type.
+ return sc::edittext_block::at(*maPos.first->data, maPos.second);
+}
+
+void EditTextIterator::incPos()
+{
+ if (maPos.second + 1 < maPos.first->size)
+ // Increment within the block.
+ ++maPos.second;
+ else
+ incBlock();
+}
+
+void EditTextIterator::incBlock()
+{
+ ++maPos.first;
+ maPos.second = 0;
+}
+
+const EditTextObject* EditTextIterator::first()
+{
+ mpCol = &mrTable.aCol[0];
+ mpColEnd = mpCol + static_cast<size_t>(MAXCOLCOUNT);
+ mpCells = &mpCol->maCells;
+ maPos = mpCells->position(0);
+ miEnd = mpCells->end();
+ return seek();
+}
+
+const EditTextObject* EditTextIterator::next()
+{
+ if (maPos.first == miEnd)
+ return NULL;
+
+ incPos();
+ return seek();
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */