]> git.lyx.org Git - lyx.git/blob - src/texrow.h
Remove Paragraph dependency from texrow, use a id instead.
[lyx.git] / src / texrow.h
1 // -*- C++ -*-
2 /**
3  * \file texrow.h
4  * Copyright 1995-2002 the LyX Team
5  * Read the file COPYING
6  *
7  * \author Matthias Ettrich
8  */
9
10
11 #ifndef TEXROW_H
12 #define TEXROW_H
13
14 #include <list>
15
16
17 /// Represents the correspondence between paragraphs and the generated LaTeX file
18 class TexRow {
19 public:
20         ///
21         TexRow() : count(0), lastid(-1), lastpos(-1) {}
22
23         TexRow & operator+= (TexRow const &);
24
25         /// Clears structure
26         void reset();
27
28         /// Define what paragraph and position the next row will represent
29         void start(int id, int pos);
30
31         /// Insert node when line is completed
32         void newline();
33
34         /**
35          * getIdFromRow - find pid and position for a given row
36          * @param row row number to find
37          * @param id set to id if found
38          * @param pos set to paragraph position if found
39          * @return true if found, false otherwise
40          *
41          * If the row could not be found, pos is set to zero and
42          * id is set to -1
43          */
44         bool getIdFromRow(int row, int & id, int & pos) const;
45
46         /// Returns the number of rows contained
47         int rows() const { return count; }
48
49         /// an individual id/pos <=> row mapping
50         class RowItem {
51         public:
52                 RowItem(int id, int pos, int row)
53                         : id_(id), pos_(pos), rownumber_(row)
54                 {}
55
56                 /// paragraph id
57                 int id() const {
58                         return id_;
59                 }
60
61                 /// set paragraph position
62                 void pos(int p) {
63                         pos_ = p;
64                 }
65
66                 /// paragraph position
67                 int pos() const {
68                         return pos_;
69                 }
70
71                 /// row number
72                 int rownumber() const {
73                         return rownumber_;
74                 }
75         private:
76                 int id_;
77                 int pos_;
78                 int rownumber_;
79         };
80         ///
81         typedef std::list<RowItem> RowList;
82         /// increment position of all other RowItems
83         /// with same par id, to avoid placing error insets
84         /// at the same position
85         void increasePos(int id, int pos);
86 private:
87         /// number of lines
88         unsigned int count;
89         /// container of id/pos <=> row mapping
90         RowList rowlist;
91         /// Last paragraph
92         int lastid;
93         /// Last position
94         int lastpos;
95 };
96
97 #endif // TEXROW_H