3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Matthias Ettrich
7 * \author Lars Gullik Bjønnes
10 * Full author contact details are available in file CREDITS.
15 #include "DocIterator.h"
16 #include "Paragraph.h"
19 #include "support/debug.h"
27 void TexRow::reset(bool enable)
36 void TexRow::start(int id, int pos)
38 if (!enabled_ || started)
46 void TexRow::newline()
50 RowList::value_type tmp(lastid, lastpos);
51 rowlist.push_back(tmp);
55 void TexRow::newlines(int num_lines)
59 for (int i = 0; i < num_lines; ++i) {
64 void TexRow::finalize()
71 bool TexRow::getIdFromRow(int row, int & id, int & pos) const
73 if (row <= 0 || row > int(rowlist.size())) {
79 id = rowlist[row - 1].id();
80 pos = rowlist[row - 1].pos();
85 std::pair<int,int> TexRow::rowFromDocIterator(DocIterator const & dit) const
88 size_t best_slice = 0;
89 size_t const n = dit.depth();
90 // this loop finds the last row of the topmost possible CursorSlice
91 RowList::const_iterator best_beg_row = rowlist.begin();
92 RowList::const_iterator best_end_row = rowlist.begin();
93 RowList::const_iterator it = rowlist.begin();
94 RowList::const_iterator const end = rowlist.end();
95 for (; it != end; ++it) {
97 // Compute the best end row. It is the one that matches pos+1.
98 CursorSlice const & best = dit[best_slice];
100 && it->id() == best.paragraph().id()
101 && it->pos() == best.pos() + 1
102 && (best_end_row->id() != it->id()
103 || best_end_row->pos() < it->pos()))
106 for (size_t i = best_slice; i < n && dit[i].text(); ++i) {
107 int const id = dit[i].paragraph().id();
108 if (it->id() == id) {
109 if (it->pos() <= dit[i].pos()
110 && (best_beg_row->id() != id
111 || it->pos() > best_beg_row->pos())) {
114 best_beg_row = best_end_row = it;
122 return std::make_pair(-1,-1);
123 int const beg_i = distance(rowlist.begin(), best_beg_row) + 1;
124 // remove one to the end
125 int const end_i = std::max(beg_i,
126 (int)distance(rowlist.begin(), best_end_row));
127 return std::make_pair(beg_i,end_i);
131 LyXErr & operator<<(LyXErr & l, TexRow & texrow)
134 for (int i = 0; i < texrow.rows(); i++) {
136 if (texrow.getIdFromRow(i+1,id,pos) && id>0)
137 l << i+1 << ":" << id << ":" << pos << "\n";