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() { x = y = size = 0; p = 0; crow = 0; }
171 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.
218 /**$ These two functions will be moved from here */
221 bool setLabel(char* label);
223 bool setNumbered(bool);
227 void setTab(int, int);
228 /// Merge the array at current position
229 void Merge(LyxArrayBase*);
230 /// Delete every object from current position to pos2
231 void Clean(int pos2);
232 MathedRowSt *adjustVerticalSt();
235 /// This function is not recursive, as MathPar::Metrics is
236 void IMetrics(int, int&, int&, int&);
237 /// Font size (display, text, script, script2)
241 // /// max ascent and descent
246 // Limits auxiliary variables
247 /// Position and max width of a script
249 /// true= center, false= left align (default)
251 /// Type of previous script
264 friend class MathedCursor;
268 //-------------------- Inline functions --------------------------//
272 bool MathedIter::IsInset()
274 return MathIsInset((*array)[pos]);
278 bool MathedIter::IsActive()
280 return MathIsActive((*array)[pos]);
284 bool MathedIter::IsFont()
286 return MathIsFont((*array)[pos]);
291 bool MathedIter::IsScript()
293 return MathIsScript((*array)[pos]);
297 bool MathedIter::IsTab()
299 return ((*array)[pos] == LM_TC_TAB);
304 bool MathedIter::IsCR()
306 return ((*array)[pos] == LM_TC_CR);
311 MathedIter::MathedIter(LyxArrayBase * d): array(d)
315 fcode = (array && IsFont()) ? (*array)[0]: 0;
320 void MathedIter::ipush()
330 void MathedIter::ipop()
340 void MathedXIter::GetPos(int&xx, int& yy)
350 int MathedXIter::GetX()
358 int MathedXIter::GetY()
367 void MathedXIter::GetIncPos(int& xx, int& yy)
374 void MathedXIter::getAD(int& a, int& d)