]> git.lyx.org Git - lyx.git/blob - src/mathed/math_iter.h
first go at mathed file cleanup
[lyx.git] / src / mathed / math_iter.h
1 // -*- C++ -*-
2 /*
3  *  File:        math_iter.h
4  *  Purpose:     Iterator for Math paragraphs
5  *  Author:      Alejandro Aguilar Sierra <asierra@servidor.unam.mx> 
6  *  Created:     January 1997
7  *  Description: Using iterators is the only way to handle math paragraphs 
8  *
9  *  Dependencies: Xlib
10  *
11  *  Copyright: 1996, 1997 Alejandro Aguilar Sierra
12  *
13  *   Version: 0.8beta, Mathed & Lyx project.
14  *
15  *   You are free to use and modify this code under the terms of
16  *   the GNU General Public Licence version 2 or later.
17  * 
18  */
19
20 #ifndef MATH_ITER
21 #define MATH_ITER
22
23 #ifdef __GNUG__
24 #pragma interface
25 #endif
26
27 #include "math_defs.h"
28
29 class MathedInset;
30
31 ///
32 enum mathIterFlags {
33     /// Allow newlines
34     MthIF_CR = 1,
35     /// Allow tabs
36     MthIF_Tabs = 2
37 };
38
39
40 /** Specialized array iterator for math paragraph.
41     Used for storing and querying data operations
42 */
43 class MathedIter {
44 public:
45         ///
46         MathedIter() {
47                 pos = 0;
48                 fcode = 0;
49                 array = 0;
50                 flags = 0;
51                 ncols = row = col = 0;
52         }
53         ///
54         explicit
55         MathedIter(MathedArray *);
56         ///
57         virtual ~MathedIter() {}
58         ///
59         bool goNextCode(MathedTextCodes);
60         ///
61         void goPosRel(int);
62         ///
63         void goPosAbs(int);
64         ///
65         int Empty() const;
66         ///
67         int OK() const;
68         ///
69         int IsFirst() const { return (pos == 0); }
70         ///
71         byte GetChar() const;
72         ///
73         string const GetString() const;
74         ///
75         MathedInset * GetInset() const;
76         ///
77         MathParInset * GetActiveInset() const;
78         ///
79         bool IsInset() const;
80         ///
81         bool IsActive() const;
82         ///
83         bool IsFont() const;
84         ///
85         bool IsScript() const;
86         ///
87         bool IsTab() const;
88         ///
89         bool IsCR() const;
90         ///
91         virtual void Reset();
92         ///
93         virtual void Insert(byte, MathedTextCodes c = LM_TC_CONST);
94         ///
95         virtual void Insert(MathedInset *, int t = LM_TC_INSET);
96         ///
97         virtual bool Delete();
98         ///
99         virtual bool Next();
100         /// Check consistency of tabs and newlines
101         void checkTabs();
102         /// Try to adjust tabs in the expected place, as in eqnarrays
103         void adjustTabs();
104         ///
105         short FCode() const { return fcode; }
106         ///
107         int getPos() const { return pos; }
108         ///
109         int getRow() const { return row; }
110         ///
111         int getCol() const { return col; }
112         ///
113         void setNumCols(int n) { ncols = n; }
114         ///
115         void SetData(MathedArray * a);
116         ///
117         MathedArray * GetData() const;
118         /// Copy every object from position p1 to p2
119         MathedArray * Copy(int p1 = 0, int p2 = 10000);
120         /// Delete every object from position p1 to p2
121         void Clear();
122 protected:
123         ///
124         void split(int);
125         ///
126         void join(int);
127         ///
128         int flags;
129         ///
130         mutable short fcode;
131         ///
132         mutable int pos;
133         ///
134         int row, col, ncols;
135         ///
136         MathedArray * array;
137         // one element stack
138         struct MIState {
139                 ///
140                 short fcode;
141                 ///
142                 int x, y;
143                 ///
144                 int pos, row, col;
145         };
146         ///
147         MIState stck;
148         /// Saves the current state of the iterator
149         virtual void ipush();
150         /// Recover previous state
151         virtual void ipop();
152 };
153
154 ///
155 #define MX_WAS_SUB   1
156 ///
157 #define MX_WAS_SUPER 2
158
159 #endif