]> git.lyx.org Git - lyx.git/blob - src/texrow.C
NEW_INSETS changes, + some small things in insettabular.C
[lyx.git] / src / texrow.C
1 /* This file is part of
2  * ====================================================== 
3  * 
4  *           LyX, The Document Processor
5  *       
6  *          Copyright 1995 Matthias Ettrich
7  *          Copyright 1995-2000 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "texrow.h"
18 #include "lyxparagraph.h"
19 #include "debug.h"
20
21
22 // Delete linked list
23 void TexRow::reset()
24 {
25         rowlist.clear();
26         count = 0;
27         lastpar = 0;
28         lastpos = -1;
29 }
30
31
32 // Defines paragraph and position for the beginning of this row
33 void TexRow::start(LyXParagraph * par, int pos)
34 {
35         lastpar = par;
36         lastpos = pos;
37 }
38
39
40 // Insert node when line is completed
41 void TexRow::newline()
42 {
43         RowItem tmp;
44         tmp.pos(lastpos);
45         if (lastpar)
46                 tmp.id(lastpar->id());
47         else
48                 tmp.id(-1);
49         tmp.rownumber(++count);
50         rowlist.push_back(tmp);
51 }
52
53
54 void TexRow::getIdFromRow(int row, int & id, int & pos)
55 {
56         RowList::const_iterator cit = rowlist.begin();
57         for (; cit != rowlist.end(); ++cit) {
58                 if ((*cit).rownumber() == row) break;
59         }
60         if (cit != rowlist.end()) {
61                 RowList::iterator kit = rowlist.begin();
62                 // Increase the pos of all rows with the
63                 // same id (and where the pos is larger)
64                 // to avoid putting errorinsets at the
65                 // same pos.
66                 for(; kit != rowlist.end(); ++kit) {
67                         if (&(*kit) != &(*cit)
68                             && (*kit).id() == (*cit).id()
69                             && (*kit).pos() >= (*cit).pos())
70                                 (*kit).pos((*kit).pos() + 1);
71                 }
72                 id = (*cit).id();
73                 pos = (*cit).pos();
74         } else {
75                 id = -1;
76                 pos = 0;
77         }
78 }
79
80
81 TexRow & TexRow::operator+= (TexRow const & tr)
82 {
83         rowlist.insert(rowlist.end(), tr.rowlist.begin(), tr.rowlist.end());
84         return *this;
85 }