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: (c) 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"
39 Specialized array iterator for amth paragraph. Used for
40 storing and querying data operations
51 ncols = row = col = 0;
54 MathedIter(LyxArrayBase *);
56 virtual ~MathedIter() { }
58 bool goNextCode(MathedTextCodes);
64 int Empty() { return array->last<=1; }
66 int OK() { return array && (pos < array->last); }
68 int IsFirst() { return (pos==0); }
72 byte* GetString(int& len);
74 MathedInset* GetInset();
76 MathParInset* GetActiveInset();
92 virtual void Insert(byte, MathedTextCodes c=LM_TC_CONST);
94 virtual void Insert(MathedInset*, int t=LM_TC_INSET);
96 virtual bool Delete();
99 /// Check consistency of tabs and newlines
101 /// Try to adjust tabs in the expected place, as in eqnarrays
104 short FCode() const { return fcode; }
106 int getPos() const { return pos; }
108 int getRow() const { return row; }
110 int getCol() const { return col; }
112 void setNumCols(int n) { ncols = n; }
114 void SetData(LyxArrayBase *a) { array = a; Reset(); }
116 LyxArrayBase *GetData() { return array; }
118 /// Copy every object from position p1 to p2
119 LyxArrayBase *Copy(int p1=0, int p2=10000);
121 /// 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 {
168 MathedXIter(): MathedIter() { x = y = size = 0; p = 0; crow = 0; }
170 MathedXIter(MathParInset*);
174 void SetData(MathParInset *);
176 MathParInset *getPar() { return p; }
194 inline void GetPos(int&, int&);
196 inline void GetIncPos(int&, int&);
198 byte* GetString(int&);
204 void subMetrics(int, int);
206 void fitCoord(int, int);
208 void getAD(int& a, int& d);
210 /// Create a new row and insert #ncols# tabs.
215 /**$ These two functions will be moved from here */
218 bool setLabel(char* label);
220 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->bf[pos]);
275 bool MathedIter::IsActive()
277 return MathIsActive(array->bf[pos]);
281 bool MathedIter::IsFont()
283 return MathIsFont(array->bf[pos]);
288 bool MathedIter::IsScript()
290 return MathIsScript(array->bf[pos]);
294 bool MathedIter::IsTab()
296 return (array->bf[pos]==LM_TC_TAB);
301 bool MathedIter::IsCR()
303 return (array->bf[pos]==LM_TC_CR);
308 MathedIter::MathedIter(LyxArrayBase *d): array(d)
312 fcode = (array && IsFont()) ? array->bf[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)