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() const { return array->Last()<= 1; }
65 int OK() const { return array && (pos < array->Last()); }
67 int IsFirst() const { return (pos == 0); }
71 byte * GetString(int & len) const;
73 string const GetString() const;
75 MathedInset * GetInset() const;
77 MathParInset * GetActiveInset() const;
81 bool IsActive() const;
85 bool IsScript() const;
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() const { 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
139 LyxArrayBase * array;
151 /// Saves the current state of the iterator
152 virtual void ipush();
153 /// Recover previous state
160 #define MX_WAS_SUPER 2
164 A graphic iterator (updates position.) Used for
165 metrics and updating cursor position
167 class MathedXIter: public MathedIter {
171 : MathedIter(), sx(0), sw(0) {
172 x = y = size = 0; p = 0; crow = 0;
175 MathedXIter(MathParInset *);
177 void SetData(MathParInset *);
179 MathParInset * getPar() const { return p; }
198 void GetPos(int &, int &) const;
201 void GetIncPos(int &, int &) const;
203 byte * GetString(int &) const ;
205 string const GetString() const;
211 void subMetrics(int, int);
213 void fitCoord(int, int);
215 void getAD(int & a, int & d) const;
217 /// Create a new row and insert #ncols# tabs.
223 bool setLabel(string const & label);
225 string const & getLabel() const {
226 return crow->getLabel();
229 bool setNumbered(bool);
232 void setTab(int, int);
233 /// Merge the array at current position
234 void Merge(LyxArrayBase *);
235 /// Delete every object from current position to pos2
236 void Clean(int pos2);
238 MathedRowSt * adjustVerticalSt();
241 /// This function is not recursive, as MathPar::Metrics is
242 void IMetrics(int, int &, int &, int &);
243 /// Font size (display, text, script, script2)
252 // Limits auxiliary variables
253 /// Position and max width of a script
255 /// true= center, false= left align (default)
257 /// Type of previous script
270 friend class MathedCursor;
274 //-------------------- Inline functions --------------------------//
278 bool MathedIter::IsInset() const
280 return MathIsInset((*array)[pos]);
284 bool MathedIter::IsActive() const
286 return MathIsActive((*array)[pos]);
290 bool MathedIter::IsFont() const
292 return MathIsFont((*array)[pos]);
297 bool MathedIter::IsScript() const
299 return MathIsScript((*array)[pos]);
303 bool MathedIter::IsTab() const
305 return ((*array)[pos] == LM_TC_TAB);
310 bool MathedIter::IsCR() const
312 return ((*array)[pos] == LM_TC_CR);
317 MathedIter::MathedIter(LyxArrayBase * d)
322 fcode = (array && IsFont()) ? (*array)[0]: 0;
327 void MathedIter::ipush()
337 void MathedIter::ipop()
347 void MathedXIter::GetPos(int & xx, int & yy) const
357 int MathedXIter::GetX() const
366 int MathedXIter::GetY() const
376 void MathedXIter::GetIncPos(int & xx, int & yy) const
383 void MathedXIter::getAD(int & a, int & d) const