Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / sc / source / core / data / edittextiterator.cxx
blobbdf7c99341612c4298caf90166d92f37a316742e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include <edittextiterator.hxx>
11 #include <document.hxx>
12 #include <table.hxx>
13 #include <column.hxx>
15 namespace sc {
17 EditTextIterator::EditTextIterator( const ScDocument& rDoc, SCTAB nTab ) :
18 mrTable(*rDoc.maTabs.at(nTab)),
19 mnCol(0),
20 mpCells(nullptr),
21 miEnd(maPos.first)
23 init();
26 void EditTextIterator::init()
28 mnCol = 0;
29 if (mnCol >= mrTable.aCol.size())
30 mnCol = -1;
32 if (mnCol != -1)
34 mpCells = &mrTable.aCol[mnCol].maCells;
35 maPos = mpCells->position(0);
36 miEnd = mpCells->end();
40 const EditTextObject* EditTextIterator::seek()
42 while (maPos.first->type != sc::element_type_edittext)
44 incBlock();
45 if (maPos.first == miEnd)
47 // Move to the next column.
48 ++mnCol;
49 if (mnCol >= mrTable.aCol.size())
50 // No more columns.
51 return nullptr;
53 mpCells = &mrTable.aCol[mnCol].maCells;
54 maPos = mpCells->position(0);
55 miEnd = mpCells->end();
59 // We are on the right block type.
60 return sc::edittext_block::at(*maPos.first->data, maPos.second);
63 void EditTextIterator::incBlock()
65 ++maPos.first;
66 maPos.second = 0;
69 const EditTextObject* EditTextIterator::first()
71 init();
72 if (mnCol == -1)
73 return nullptr;
74 return seek();
77 const EditTextObject* EditTextIterator::next()
79 if (mnCol == -1)
80 return nullptr;
82 if (maPos.first == miEnd)
83 return nullptr;
85 // increment position by one
86 if (maPos.second + 1 < maPos.first->size)
87 // Increment within the block.
88 ++maPos.second;
89 else
90 incBlock();
92 return seek();
97 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */