1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
/* -*- 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)),
mnCol(0),
mpCells(nullptr),
maPos(sc::CellStoreType::const_position_type()),
miEnd(maPos.first)
{
init();
}
void EditTextIterator::init()
{
mnCol = 0;
if (mnCol >= mrTable.aCol.size())
mnCol = -1;
if (mnCol != -1)
{
mpCells = &mrTable.aCol[mnCol].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.
++mnCol;
if (mnCol >= mrTable.aCol.size())
// No more columns.
return nullptr;
mpCells = &mrTable.aCol[mnCol].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::incBlock()
{
++maPos.first;
maPos.second = 0;
}
const EditTextObject* EditTextIterator::first()
{
init();
if (mnCol == -1)
return nullptr;
return seek();
}
const EditTextObject* EditTextIterator::next()
{
if (mnCol == -1)
return nullptr;
if (maPos.first == miEnd)
return nullptr;
// increment position by one
if (maPos.second + 1 < maPos.first->size)
// Increment within the block.
++maPos.second;
else
incBlock();
return seek();
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|