]> git.lyx.org Git - lyx.git/blob - src/texrow.C
ae847224dc14f21a9c256f11f100dfd99f02e0d0
[lyx.git] / src / texrow.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor
5  *       
6  *          Copyright (C) 1995 Matthias Ettrich
7  *          Copyright (C) 1995-1998 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 "error.h"
20
21 //      $Id: texrow.C,v 1.1 1999/09/27 18:44:38 larsbj Exp $    
22
23 #if !defined(lint) && !defined(WITH_WARNINGS)
24 static char vcid[] = "$Id: texrow.C,v 1.1 1999/09/27 18:44:38 larsbj Exp $";
25 #endif /* lint */
26
27 // Delete linked list
28 void TexRow::reset()
29 {
30         TexRow_Item *current, *iter = next;
31         while (iter) {
32                 // Iterate through the list deleting as you go.
33                 // A bit easier to debug than recursive deletion.
34                 current = iter;
35                 iter = iter->next;
36                 delete current;
37         }
38         count = 0;
39         next = 0;
40         lastpar = 0;
41         lastpos = -1;
42 }
43
44 // Defines paragraph and position for the beginning of this row
45 void TexRow::start(LyXParagraph *par, int pos) {
46         lastpar = par;
47         lastpos = pos;
48 }
49
50 // Insert node when line is completed
51 void TexRow::newline()
52 {
53         TexRow_Item *tmp = new TexRow_Item;
54         tmp->pos = lastpos;
55         
56         if (lastpar)
57                 tmp->id = lastpar->GetID();
58         else
59                 tmp->id = -1;
60
61         // Inserts at the beginning of the list
62         tmp->next = next;
63         next = tmp;
64         count++;
65         tmp->rownumber = count;
66 }
67
68
69 void TexRow::getIdFromRow(int row, int &id, int &pos)
70 {
71         TexRow_Item *tmp = next;
72         while (tmp && tmp->rownumber != row) {
73                 tmp = tmp->next;
74         }
75         if (tmp) {
76                 TexRow_Item *tmp2 = next;
77                 // Increase the pos of all rows with the
78                 // same id (and where the pos is larger)
79                 // to avoid putting errorinsets at the
80                 // same pos.
81                 while (tmp2) {
82                         if (tmp2 != tmp &&
83                             tmp2->id == tmp->id &&
84                             tmp2->pos >= tmp->pos)
85                                 tmp2->pos++;
86                         tmp2 = tmp2->next;
87                 }
88                 id = tmp->id;
89                 pos = tmp->pos;
90         } else {
91                 id = -1;
92                 pos = 0;
93         }
94 }
95
96
97 TexRow & TexRow::operator+=(const TexRow &tr)
98 {
99         // remember that the lists are stored in reverse 
100         // so you've got to turn the second one around 
101         // as you insert it in the first
102         for (int counter = tr.count; counter > 0; --counter) {
103                 int i = 1;
104                 TexRow_Item *iter = tr.next;
105                 while (i < counter) {
106                         iter = iter->next;
107                         ++i;
108                 }
109
110                 ++count;
111                 TexRow_Item *tmp;
112                 tmp = new TexRow_Item;
113                 tmp->id = iter->id;
114                 tmp->pos = iter->pos;
115                 tmp->next = next;
116                 tmp->rownumber = count;
117                 next = tmp;
118         }
119         // should I be doing this or not?
120         //lastpar = tr.lastpar;
121         //lastpos = tr.lastpos;
122         return *this;
123 }