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
11 * Copyright: 1996, 1997 Alejandro Aguilar Sierra
13 * Version: 0.8beta, Mathed & Lyx project.
15 * You are free to use and modify this code under the terms of
16 * the GNU General Public Licence version 2 or later.
27 #include "math_defs.h"
38 /** Specialized array iterator for math paragraph.
39 Used for storing and querying data operations
49 ncols = row = col = 0;
53 MathedIter(LyxArrayBase *);
55 virtual ~MathedIter() {}
57 bool goNextCode(MathedTextCodes);
63 int Empty() { return array->Last()<= 1; }
65 int OK() { return array && (pos < array->Last()); }
67 int IsFirst() { return (pos == 0); }
71 byte * GetString(int& len);
73 MathedInset * GetInset();
75 MathParInset * GetActiveInset();
91 virtual void Insert(byte, MathedTextCodes c = LM_TC_CONST);
93 virtual void Insert(MathedInset *, int t = LM_TC_INSET);
95 virtual bool Delete();
98 /// Check consistency of tabs and newlines
100 /// Try to adjust tabs in the expected place, as in eqnarrays
103 short FCode() const { return fcode; }
105 int getPos() const { return pos; }
107 int getRow() const { return row; }
109 int getCol() const { return col; }
111 void setNumCols(int n) { ncols = n; }
113 void SetData(LyxArrayBase * a) { array = a; Reset(); }
115 LyxArrayBase * GetData() { return array; }
117 /// Copy every object from position p1 to p2
118 LyxArrayBase * Copy(int p1= 0, int p2= 10000);
120 /// Delete every object from position p1 to p2
149 /// Saves the current state of the iterator
150 virtual void ipush();
151 /// Recover previous state
158 #define MX_WAS_SUPER 2
162 A graphic iterator (updates position.) Used for
163 metrics and updating cursor position
165 class MathedXIter: public MathedIter {
169 : MathedIter(), sx(0), sw(0) {
170 x = y = size = 0; p = 0; crow = 0;
173 MathedXIter(MathParInset *);
175 void SetData(MathParInset *);
177 MathParInset * getPar() { return p; }
196 void GetPos(int &, int &);
199 void GetIncPos(int &, int &);
201 byte * GetString(int &);
207 void subMetrics(int, int);
209 void fitCoord(int, int);
211 void getAD(int & a, int & d);
213 /// Create a new row and insert #ncols# tabs.
219 bool setLabel(char* label);
221 bool setNumbered(bool);
224 void setTab(int, int);
225 /// Merge the array at current position
226 void Merge(LyxArrayBase*);
227 /// Delete every object from current position to pos2
228 void Clean(int pos2);
229 MathedRowSt *adjustVerticalSt();
232 /// This function is not recursive, as MathPar::Metrics is
233 void IMetrics(int, int&, int&, int&);
234 /// Font size (display, text, script, script2)
238 // /// max ascent and descent
243 // Limits auxiliary variables
244 /// Position and max width of a script
246 /// true= center, false= left align (default)
248 /// Type of previous script
261 friend class MathedCursor;
265 //-------------------- Inline functions --------------------------//
269 bool MathedIter::IsInset()
271 return MathIsInset((*array)[pos]);
275 bool MathedIter::IsActive()
277 return MathIsActive((*array)[pos]);
281 bool MathedIter::IsFont()
283 return MathIsFont((*array)[pos]);
288 bool MathedIter::IsScript()
290 return MathIsScript((*array)[pos]);
294 bool MathedIter::IsTab()
296 return ((*array)[pos] == LM_TC_TAB);
301 bool MathedIter::IsCR()
303 return ((*array)[pos] == LM_TC_CR);
308 MathedIter::MathedIter(LyxArrayBase * d): array(d)
312 fcode = (array && IsFont()) ? (*array)[0]: 0;
317 void MathedIter::ipush()
327 void MathedIter::ipop()
337 void MathedXIter::GetPos(int&xx, int& yy)
347 int MathedXIter::GetX()
355 int MathedXIter::GetY()
364 void MathedXIter::GetIncPos(int& xx, int& yy)
371 void MathedXIter::getAD(int& a, int& d)