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