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"
39 Specialized array iterator for amth paragraph. Used for
40 storing and querying data operations
51 ncols = row = col = 0;
55 MathedIter(LyxArrayBase *);
57 virtual ~MathedIter() { }
59 bool goNextCode(MathedTextCodes);
65 int Empty() { return array->Last()<= 1; }
67 int OK() { return array && (pos < array->Last()); }
69 int IsFirst() { return (pos == 0); }
73 byte * GetString(int& len);
75 MathedInset * GetInset();
77 MathParInset * GetActiveInset();
93 virtual void Insert(byte, MathedTextCodes c = LM_TC_CONST);
95 virtual void Insert(MathedInset *, int t = LM_TC_INSET);
97 virtual bool Delete();
100 /// Check consistency of tabs and newlines
102 /// Try to adjust tabs in the expected place, as in eqnarrays
105 short FCode() const { return fcode; }
107 int getPos() const { return pos; }
109 int getRow() const { return row; }
111 int getCol() const { return col; }
113 void setNumCols(int n) { ncols = n; }
115 void SetData(LyxArrayBase * a) { array = a; Reset(); }
117 LyxArrayBase * GetData() { return array; }
119 /// Copy every object from position p1 to p2
120 LyxArrayBase * Copy(int p1= 0, int p2= 10000);
122 /// Delete every object from position p1 to p2
150 /// Saves the current state of the iterator
151 virtual void ipush();
152 /// Recover previous state
159 #define MX_WAS_SUPER 2
163 A graphic iterator (updates position.) Used for
164 metrics and updating cursor position
166 class MathedXIter: public MathedIter {
169 MathedXIter() : MathedIter(), sx(0), sw(0) { x = y = size = 0; p = 0; crow = 0; }
171 MathedXIter(MathParInset*);
173 void SetData(MathParInset *);
175 MathParInset *getPar() { return p; }
194 void GetPos(int&, int&);
197 void GetIncPos(int&, int&);
199 byte* GetString(int&);
205 void subMetrics(int, int);
207 void fitCoord(int, int);
209 void getAD(int& a, int& d);
211 /// Create a new row and insert #ncols# tabs.
216 /**$ These two functions will be moved from here */
219 bool setLabel(char* label);
221 bool setNumbered(bool);
225 void setTab(int, int);
226 /// Merge the array at current position
227 void Merge(LyxArrayBase*);
228 /// Delete every object from current position to pos2
229 void Clean(int pos2);
230 MathedRowSt *adjustVerticalSt();
233 /// This function is not recursive, as MathPar::Metrics is
234 void IMetrics(int, int&, int&, int&);
235 /// Font size (display, text, script, script2)
239 // /// max ascent and descent
244 // Limits auxiliary variables
245 /// Position and max width of a script
247 /// true= center, false= left align (default)
249 /// Type of previous script
262 friend class MathedCursor;
266 //-------------------- Inline functions --------------------------//
270 bool MathedIter::IsInset()
272 return MathIsInset((*array)[pos]);
276 bool MathedIter::IsActive()
278 return MathIsActive((*array)[pos]);
282 bool MathedIter::IsFont()
284 return MathIsFont((*array)[pos]);
289 bool MathedIter::IsScript()
291 return MathIsScript((*array)[pos]);
295 bool MathedIter::IsTab()
297 return ((*array)[pos] == LM_TC_TAB);
302 bool MathedIter::IsCR()
304 return ((*array)[pos] == LM_TC_CR);
309 MathedIter::MathedIter(LyxArrayBase * d): array(d)
313 fcode = (array && IsFont()) ? (*array)[0]: 0;
318 void MathedIter::ipush()
328 void MathedIter::ipop()
338 void MathedXIter::GetPos(int&xx, int& yy)
348 int MathedXIter::GetX()
356 int MathedXIter::GetY()
365 void MathedXIter::GetIncPos(int& xx, int& yy)
372 void MathedXIter::getAD(int& a, int& d)