]> git.lyx.org Git - lyx.git/blob - src/texrow.C
Fixed various "missing features" in the tabular/textinset code.
[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 #include <algorithm>
14
15 #ifdef __GNUG__
16 #pragma implementation
17 #endif
18
19 #include "texrow.h"
20 #include "lyxparagraph.h"
21 #include "debug.h"
22
23 using std::find_if;
24 using std::endl;
25
26 // Delete linked list
27 void TexRow::reset()
28 {
29         rowlist.clear();
30         count = 0;
31         lastpar = 0;
32         lastpos = -1;
33 }
34
35
36 // Defines paragraph and position for the beginning of this row
37 void TexRow::start(LyXParagraph * par, int pos)
38 {
39         lastpar = par;
40         lastpos = pos;
41 }
42
43
44 // Insert node when line is completed
45 void TexRow::newline()
46 {
47         RowItem tmp;
48         tmp.pos(lastpos);
49         if (lastpar)
50                 tmp.id(lastpar->id());
51         else
52                 tmp.id(-1);
53         tmp.rownumber(++count);
54         rowlist.push_back(tmp);
55 }
56
57
58 class same_rownumber {
59 public:
60         same_rownumber(TexRow::RowList::value_type const & v):vt(v){}
61         bool operator()(TexRow::RowList::value_type const & vt1) const {
62                 return vt.rownumber() == vt1.rownumber();
63         }
64 private:
65         TexRow::RowList::value_type const & vt;
66 };
67
68
69
70 bool TexRow::getIdFromRow(int row, int & id, int & pos) const
71 {
72         RowList::value_type vt;
73         vt.rownumber(row);
74         RowList::const_iterator cit =
75                 find_if(rowlist.begin(), rowlist.end(), same_rownumber(vt));
76         
77         if (cit != rowlist.end()) {
78 #if 0
79                 RowList::iterator kit = rowlist.begin();
80                 RowList::iterator end = rowlist.end();
81                 // Increase the pos of all rows with the
82                 // same id (and where the pos is larger)
83                 // to avoid putting errorinsets at the
84                 // same pos.
85                 for (; kit != end; ++kit) {
86                         if (&(*kit) != &(*cit)
87                             && (*kit).id() == (*cit).id()
88                             && (*kit).pos() >= (*cit).pos())
89                                 (*kit).pos((*kit).pos() + 1);
90                 }
91 #endif
92                 id = (*cit).id();
93                 pos = (*cit).pos();
94                 return true;
95         }
96         id = -1;
97         pos = 0;
98         return false;
99 }
100
101
102 // should perhaps have a better name...
103 // Increase the pos of all rows with the
104 // same id (and where the pos is larger)
105 // to avoid putting errorinsets at the
106 // same pos.
107 void TexRow::increasePos(int id, int pos) const
108 {
109         RowList::iterator kit = rowlist.begin();
110         RowList::iterator end = rowlist.end();
111         for (; kit != end; ++kit) {
112                 if (id == (*kit).id()
113                     && pos < (*kit).pos()) {
114                         (*kit).pos((*kit).pos() + 1);
115                         lyxerr << "TeXRow::increasePos: ideally this "
116                                 "should never happen..." << endl;
117                 }
118                 // When verified to work this clause should be deleted.
119                 if (id == (*kit).id()
120                     && pos == (*kit).pos()) {
121                         lyxerr << "TexRow::increasePos: this should happen "
122                                 "maximum one time for each run of "
123                                 "increasePos!" << endl;
124                 }
125         }
126 }
127
128
129 TexRow & TexRow::operator+= (TexRow const & tr)
130 {
131         rowlist.insert(rowlist.end(), tr.rowlist.begin(), tr.rowlist.end());
132         return *this;
133 }