3 #include "math_xiter.h"
4 #include "math_parinset.h"
5 #include "math_rowst.h"
7 #include "mathed/support.h"
12 MathedXIter::MathedXIter()
13 : MathedIter(), sx(0), sw(0)
21 MathParInset * MathedXIter::getPar() const
27 void MathedXIter::GetPos(int & xx, int & yy) const
40 int MathedXIter::GetX() const
49 int MathedXIter::GetY() const
58 void MathedXIter::GetIncPos(int & xx, int & yy) const
65 void MathedXIter::getAD(int & a, int & d) const
81 void MathedXIter::Clean(int pos2)
84 lyxerr << "Math error: Attempting to clean a void array." << endl;
92 while (pos < pos2 && OK()) {
100 while (OK() && pos < pos2) {
102 MathedInset * inset = GetInset();
104 if (inset->GetType()!= LM_OT_MACRO_ARG)
110 MathedRowSt * r = crow->getNext();
112 crow->setNext(r->getNext());
121 if (pos2 <= array->last()) {
129 void MathedXIter::Merge(MathedArray * a0)
132 lyxerr[Debug::MATHED]
133 << "Math error: Attempting to merge a void array." << endl;
137 // All insets must be clonned
139 MathedArray * a = it.Copy();
142 array->insert(array->begin() + pos,
143 a->begin(), a->end());
145 // make room for the data
147 array->mergeF(a, pos, a->last());
150 int pos2 = pos + a->last();
155 while (pos < pos2 && OK()) {
157 if (p && p->Permit(LMPF_ALLOW_CR)) {
158 MathedRowSt * r = new MathedRowSt(ncols+1);
160 r->setNext(crow->getNext());
184 MathedXIter::MathedXIter(MathParInset * pp)
199 void MathedXIter::SetData(MathParInset * pp)
203 array = p->GetData();
204 ncols = p->GetColumns();
205 crow = p->getRowSt();
206 if (p->Permit(LMPF_ALLOW_CR))
208 if (p->Permit(LMPF_ALLOW_TAB))
213 y = crow->getBaseline();
216 array = new MathedArray; // this leaks
219 size = p->GetStyle();
224 string const MathedXIter::GetString() const
226 string s = MathedIter::GetString();
227 x += mathed_string_width(fcode, size, s);
232 bool MathedXIter::Next()
234 // lyxerr << "Ne[" << pos << "]";
235 if (!OK()) return false;
239 MathedInset * px = GetInset();
241 if (px->GetType() == LM_OT_SCRIPT) {
245 sx = (px->GetLimits()) ? w : 0;
249 // lyxerr << "WD[" << fcode << " " << size << " " << c << endl;
250 w = mathed_char_width(fcode, size, c);
252 if (c == LM_TC_TAB && p) {
253 // w = p->GetTab(col + 1);
254 w = (crow) ? crow->getTab(col + 1) : 0;
255 //lyxerr << "WW[" << w << "]";
257 if (c == LM_TC_CR && p) {
259 if (crow && crow->getNext()) {
260 crow = crow->getNext();
261 y = crow->getBaseline();
264 // lyxerr << "WW[" << col " " << row << "|" << w << "]";
266 lyxerr << "No hubo w[" << c << "]!";
268 if (MathedIter::Next()) {
269 // lyxerr <<"LNX " << pos << endl;
270 // if (sw>0 && GetChar()!= LM_TC_UP && GetChar()!= LM_TC_DOWN) {
271 // w = (sx>sw) ? 0: sw-sx;
272 if ((sw > 0 || sx > 0)
273 && GetChar() != LM_TC_UP && GetChar() != LM_TC_DOWN) {
275 w = (sx > sw) ? 0 : sw - sx;
285 void MathedXIter::GoBegin()
291 crow = p->getRowSt();
294 y = crow->getBaseline();
300 void MathedXIter::GoLast()
306 void MathedXIter::Adjust()
310 while (posx > pos && OK()) Next();
314 bool MathedXIter::Prev()
316 if (pos == 0 || (pos == 1 && GetChar() >= ' '))
319 int pos2 = pos; // pos1
331 void MathedXIter::goNextColumn()
335 while (Next() && col == colp)
338 //return (col != colp + 1 || rowp != row);
342 bool MathedXIter::Up()
344 if (row == 0) return false;
349 while (row < rowp - 1) Next();
350 while (x < xp && OK() && !IsCR()) {
354 if (col > colp) // || (stck.col == colp && stck.x<= xp && x>xp))
361 bool MathedXIter::Down()
367 bool res = (IsCR()) ? true : goNextCode(LM_TC_CR);
371 while (x < xp && OK()) {
375 if (col > colp || (stck.col == colp && stck.x <= xp && x > xp))
384 void MathedXIter::addRow()
387 lyxerr[Debug::MATHED] << "MathErr: Attempt to insert new"
388 " line in a subparagraph. " << this << endl;
392 // Create new item for the structure
393 MathedRowSt * r = new MathedRowSt(ncols + 1);
395 r->setNext(crow->getNext());
401 // Fill missed tabs in current row
402 while (col < ncols - 1)
403 Insert('T', LM_TC_TAB);
405 Insert('K', LM_TC_CR);
409 goNextCode(LM_TC_CR);
411 // Fill missed tabs in new row
412 while (col < ncols - 1)
413 Insert('T', LM_TC_TAB);
418 void MathedXIter::delRow()
421 lyxerr[Debug::MATHED] << "MathErr: Attempt to delete a line in a subparagraph." << endl;
424 bool line_empty = true;
430 } else if (!IsTab()) {
434 int const p1 = getPos();
439 MathedRowSt * r = crow->getNext();
441 crow->setNext(r->getNext());
453 void MathedXIter::ipush()
461 void MathedXIter::ipop()
467 crow = p->getRowSt();
469 for (int i = 0; i < row; ++i)
470 crow = crow->getNext();
475 void MathedXIter::fitCoord(int /*xx*/, int yy)
483 // first fit vertically
484 while (crow && OK()) {
485 if (yy >= yo + y - crow->ascent() && yy <= yo + y + crow->descent())
487 goNextCode(LM_TC_CR);
491 // while (x<xx && Next());
495 void MathedXIter::setTab(int tx, int tab)
497 if (crow && tab <= ncols) {
498 crow->setTab(tab, tx);
500 lyxerr << "MathErr: No tabs allowed here" << endl;
504 void MathedXIter::subMetrics(int a, int d)
507 lyxerr[Debug::MATHED]
508 << "MathErr: Attempt to submetric a subparagraph." << endl;
516 // This function is not recursive, as MathPar::Metrics is
517 void MathedXIter::IMetrics(int pos2, int & width, int & ascent, int & descent)
525 descent = ascent = width = 0;
527 if (array->empty()) return;
528 // if (pos2 > array->last) return;
533 mathed_char_height(FCode(), size, cx, asc, des);
534 if (asc > ascent) ascent = asc;
535 if (des > descent) descent = des;
538 if (MathIsInset(cx)) {
539 MathedInset * pp = GetInset();
540 if (cx == LM_TC_UP) {
545 static_cast<MathParInset*>(pp)->GetXY(xx, asc);
548 asc += ((limits) ? pp->Height() + 4 : pp->Ascent());
549 } else if (cx == LM_TC_DOWN) {
554 static_cast<MathParInset*>(pp)->GetXY(xx, des);
555 if (des - pp->Height() < yy && !asc)
556 asc = yy - (des - pp->Height());
559 des += (limit ? pp->Height()+4: pp->Height()-pp->Ascent()/2);
564 if (asc > ascent) ascent = asc;
565 if (des > descent) descent = des;
566 if (cx != LM_TC_UP && cx != LM_TC_DOWN)
567 limit = pp->GetLimits();
568 } else if (cx == LM_TC_TAB) {
571 lyxerr[Debug::MATHED]
572 << "Mathed Sel-Error: Unrecognized code["
573 << cx << ']' << endl;
576 if (pos < pos2) Next();
582 bool MathedXIter::setNumbered(bool numb)
585 crow->setNumbered(numb);
593 bool MathedXIter::setLabel(string const & label)
596 crow->setLabel(label);
604 MathedRowSt * MathedXIter::adjustVerticalSt()
608 // lyxerr << " CRW" << ncols << " ";
609 crow = new MathedRowSt(ncols + 1); // this leaks
611 // lyxerr<< " CRW[" << crow << "] ";
612 MathedRowSt * mrow = crow;
615 if (col >= ncols) ncols = col + 1;
616 MathedRowSt * r = new MathedRowSt(ncols + 1); // this leaks
617 // r->next = crow->next;
620 // lyxerr << " CX[" << crow << "]";
628 string const & MathedXIter::getLabel() const
630 return crow ? crow->getLabel() : error_label;
634 string MathedXIter::error_label = "$mathed-error$";