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; }
195 void GetPos(int&, int&);
198 void GetIncPos(int&, int&);
200 byte* GetString(int&);
206 void subMetrics(int, int);
208 void fitCoord(int, int);
210 void getAD(int& a, int& d);
212 /// Create a new row and insert #ncols# tabs.
217 /**$ These two functions will be moved from here */
220 bool setLabel(char* label);
222 bool setNumbered(bool);
226 void setTab(int, int);
227 /// Merge the array at current position
228 void Merge(LyxArrayBase*);
229 /// Delete every object from current position to pos2
230 void Clean(int pos2);
231 MathedRowSt *adjustVerticalSt();
234 /// This function is not recursive, as MathPar::Metrics is
235 void IMetrics(int, int&, int&, int&);
236 /// Font size (display, text, script, script2)
240 // /// max ascent and descent
245 // Limits auxiliary variables
246 /// Position and max width of a script
248 /// true= center, false= left align (default)
250 /// Type of previous script
263 friend class MathedCursor;
267 //-------------------- Inline functions --------------------------//
271 bool MathedIter::IsInset()
273 return MathIsInset((*array)[pos]);
277 bool MathedIter::IsActive()
279 return MathIsActive((*array)[pos]);
283 bool MathedIter::IsFont()
285 return MathIsFont((*array)[pos]);
290 bool MathedIter::IsScript()
292 return MathIsScript((*array)[pos]);
296 bool MathedIter::IsTab()
298 return ((*array)[pos] == LM_TC_TAB);
303 bool MathedIter::IsCR()
305 return ((*array)[pos] == LM_TC_CR);
310 MathedIter::MathedIter(LyxArrayBase * d): array(d)
314 fcode = (array && IsFont()) ? (*array)[0]: 0;
319 void MathedIter::ipush()
329 void MathedIter::ipop()
339 void MathedXIter::GetPos(int&xx, int& yy)
349 int MathedXIter::GetX()
357 int MathedXIter::GetY()
366 void MathedXIter::GetIncPos(int& xx, int& yy)
373 void MathedXIter::getAD(int& a, int& d)