1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 5 * This Source Code Form is subject to the terms of the Mozilla Public 6 * License, v. 2.0. If a copy of the MPL was not distributed with this 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 */ 9 10 #include <edittextiterator.hxx> 11 #include <document.hxx> 12 #include <table.hxx> 13 #include <column.hxx> 14 15 namespace sc { 16 EditTextIterator(const ScDocument & rDoc,SCTAB nTab)17EditTextIterator::EditTextIterator( const ScDocument& rDoc, SCTAB nTab ) : 18 mrTable(*rDoc.maTabs.at(nTab)), 19 mnCol(0), 20 mpCells(nullptr), 21 maPos(sc::CellStoreType::const_position_type()), 22 miEnd(maPos.first) 23 { 24 init(); 25 } 26 init()27void EditTextIterator::init() 28 { 29 mnCol = 0; 30 if (mnCol >= mrTable.aCol.size()) 31 mnCol = -1; 32 33 if (mnCol != -1) 34 { 35 mpCells = &mrTable.aCol[mnCol].maCells; 36 maPos = mpCells->position(0); 37 miEnd = mpCells->end(); 38 } 39 } 40 seek()41const EditTextObject* EditTextIterator::seek() 42 { 43 while (maPos.first->type != sc::element_type_edittext) 44 { 45 incBlock(); 46 if (maPos.first == miEnd) 47 { 48 // Move to the next column. 49 ++mnCol; 50 if (mnCol >= mrTable.aCol.size()) 51 // No more columns. 52 return nullptr; 53 54 mpCells = &mrTable.aCol[mnCol].maCells; 55 maPos = mpCells->position(0); 56 miEnd = mpCells->end(); 57 } 58 } 59 60 // We are on the right block type. 61 return sc::edittext_block::at(*maPos.first->data, maPos.second); 62 } 63 incBlock()64void EditTextIterator::incBlock() 65 { 66 ++maPos.first; 67 maPos.second = 0; 68 } 69 first()70const EditTextObject* EditTextIterator::first() 71 { 72 init(); 73 if (mnCol == -1) 74 return nullptr; 75 return seek(); 76 } 77 next()78const EditTextObject* EditTextIterator::next() 79 { 80 if (mnCol == -1) 81 return nullptr; 82 83 if (maPos.first == miEnd) 84 return nullptr; 85 86 // increment position by one 87 if (maPos.second + 1 < maPos.first->size) 88 // Increment within the block. 89 ++maPos.second; 90 else 91 incBlock(); 92 93 return seek(); 94 } 95 96 } 97 98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 99