3 #include "math_xiter.h"
4 #include "math_parinset.h"
5 #include "math_rowst.h"
7 #include "mathed/support.h"
10 MathedXIter::MathedXIter()
11 : MathedIter(), sx(0), sw(0)
19 MathParInset * MathedXIter::getPar() const
25 void MathedXIter::GetPos(int & xx, int & yy) const
38 int MathedXIter::GetX() const
47 int MathedXIter::GetY() const
56 void MathedXIter::GetIncPos(int & xx, int & yy) const
63 void MathedXIter::getAD(int & a, int & d) const
79 void MathedXIter::Clean(int pos2)
82 lyxerr << "Math error: Attempting to clean a void array." << endl;
90 while (pos < pos2 && OK()) {
98 while (OK() && pos < pos2) {
100 MathedInset * inset = GetInset();
102 if (inset->GetType()!= LM_OT_MACRO_ARG)
108 MathedRowSt * r = crow->getNext();
110 crow->setNext(r->getNext());
119 if (pos2 <= array->last()) {
127 void MathedXIter::Merge(MathedArray * a0)
130 lyxerr[Debug::MATHED]
131 << "Math error: Attempting to merge a void array." << endl;
135 // All insets must be clonned
137 MathedArray * a = it.Copy();
139 // make room for the data
141 array->mergeF(a, pos, a->last());
144 int pos2 = pos + a->last();
149 while (pos < pos2 && OK()) {
151 if (p && p->Permit(LMPF_ALLOW_CR)) {
152 MathedRowSt * r = new MathedRowSt(ncols+1);
154 r->setNext(crow->getNext());
178 MathedXIter::MathedXIter(MathParInset * pp)
194 void MathedXIter::SetData(MathParInset * pp)
198 array = p->GetData();
199 ncols = p->GetColumns();
200 crow = p->getRowSt();
201 if (p->Permit(LMPF_ALLOW_CR))
203 if (p->Permit(LMPF_ALLOW_TAB))
208 y = crow->getBaseline();
211 array = new MathedArray; // this leaks
214 size = p->GetStyle();
219 string const MathedXIter::GetString() const
221 string s = MathedIter::GetString();
222 x += mathed_string_width(fcode, size, s);
227 bool MathedXIter::Next()
229 // lyxerr << "Ne[" << pos << "]";
230 if (!OK()) return false;
234 MathedInset * px = GetInset();
236 if (px->GetType() == LM_OT_SCRIPT) {
240 sx = (px->GetLimits()) ? w : 0;
244 // lyxerr << "WD[" << fcode << " " << size << " " << c << endl;
245 w = mathed_char_width(fcode, size, c);
247 if (c == LM_TC_TAB && p) {
248 // w = p->GetTab(col + 1);
249 w = (crow) ? crow->getTab(col + 1) : 0;
250 //lyxerr << "WW[" << w << "]";
252 if (c == LM_TC_CR && p) {
254 if (crow && crow->getNext()) {
255 crow = crow->getNext();
256 y = crow->getBaseline();
259 // lyxerr << "WW[" << col " " << row << "|" << w << "]";
261 lyxerr << "No hubo w[" << c << "]!";
263 if (MathedIter::Next()) {
264 // lyxerr <<"LNX " << pos << endl;
265 // if (sw>0 && GetChar()!= LM_TC_UP && GetChar()!= LM_TC_DOWN) {
266 // w = (sx>sw) ? 0: sw-sx;
267 if ((sw > 0 || sx > 0)
268 && GetChar() != LM_TC_UP && GetChar() != LM_TC_DOWN) {
270 w = (sx > sw) ? 0 : sw - sx;
280 void MathedXIter::GoBegin()
286 crow = p->getRowSt();
289 y = crow->getBaseline();
295 void MathedXIter::GoLast()
301 void MathedXIter::Adjust()
305 while (posx > pos && OK()) Next();
309 bool MathedXIter::Prev()
311 if (pos == 0 || (pos == 1 && GetChar() >= ' '))
314 int pos2 = pos; // pos1
326 bool MathedXIter::goNextColumn()
330 while (Next() && col == colp);
332 return (col != colp + 1 || rowp != row);
336 bool MathedXIter::Up()
338 if (row == 0) return false;
343 while (row < rowp - 1) Next();
344 while (x < xp && OK() && !IsCR()) {
348 if (col > colp) // || (stck.col == colp && stck.x<= xp && x>xp))
355 bool MathedXIter::Down()
361 bool res = (IsCR()) ? true : goNextCode(LM_TC_CR);
365 while (x < xp && OK()) {
369 if (col > colp || (stck.col == colp && stck.x <= xp && x > xp))
378 void MathedXIter::addRow()
381 lyxerr[Debug::MATHED] << "MathErr: Attempt to insert new"
382 " line in a subparagraph. " << this << endl;
386 // Create new item for the structure
387 MathedRowSt * r = new MathedRowSt(ncols + 1);
389 r->setNext(crow->getNext());
395 // Fill missed tabs in current row
396 while (col < ncols - 1)
397 Insert('T', LM_TC_TAB);
399 Insert('K', LM_TC_CR);
403 goNextCode(LM_TC_CR);
405 // Fill missed tabs in new row
406 while (col < ncols - 1)
407 Insert('T', LM_TC_TAB);
412 void MathedXIter::delRow()
415 lyxerr[Debug::MATHED] << "MathErr: Attempt to delete a line in a subparagraph." << endl;
418 bool line_empty = true;
424 } else if (!IsTab()) {
428 int const p1 = getPos();
433 MathedRowSt * r = crow->getNext();
435 crow->setNext(r->getNext());
447 void MathedXIter::ipush()
455 void MathedXIter::ipop()
461 crow = p->getRowSt();
463 for (int i = 0; i < row; ++i)
464 crow = crow->getNext();
469 void MathedXIter::fitCoord(int /*xx*/, int yy)
477 // first fit vertically
478 while (crow && OK()) {
479 if (yy >= yo + y - crow->ascent() && yy <= yo + y + crow->descent())
481 goNextCode(LM_TC_CR);
485 // while (x<xx && Next());
489 void MathedXIter::setTab(int tx, int tab)
491 if (crow && tab <= ncols) {
492 crow->setTab(tab, tx);
494 lyxerr << "MathErr: No tabs allowed here" << endl;
498 void MathedXIter::subMetrics(int a, int d)
501 lyxerr[Debug::MATHED]
502 << "MathErr: Attempt to submetric a subparagraph." << endl;
510 // This function is not recursive, as MathPar::Metrics is
511 void MathedXIter::IMetrics(int pos2, int & width, int & ascent, int & descent)
519 descent = ascent = width = 0;
521 if (array->empty()) return;
522 // if (pos2 > array->last) return;
527 mathed_char_height(FCode(), size, cx, asc, des);
528 if (asc > ascent) ascent = asc;
529 if (des > descent) descent = des;
532 if (MathIsInset(cx)) {
533 MathedInset * pp = GetInset();
534 if (cx == LM_TC_UP) {
539 static_cast<MathParInset*>(pp)->GetXY(xx, asc);
542 asc += ((limits) ? pp->Height() + 4 : pp->Ascent());
543 } else if (cx == LM_TC_DOWN) {
548 static_cast<MathParInset*>(pp)->GetXY(xx, des);
549 if (des - pp->Height() < yy && !asc)
550 asc = yy - (des - pp->Height());
553 des += (limit ? pp->Height()+4: pp->Height()-pp->Ascent()/2);
558 if (asc > ascent) ascent = asc;
559 if (des > descent) descent = des;
560 if (cx != LM_TC_UP && cx != LM_TC_DOWN)
561 limit = pp->GetLimits();
562 } else if (cx == LM_TC_TAB) {
565 lyxerr[Debug::MATHED]
566 << "Mathed Sel-Error: Unrecognized code["
567 << cx << ']' << endl;
570 if (pos < pos2) Next();
576 bool MathedXIter::setNumbered(bool numb)
579 crow->setNumbered(numb);
587 bool MathedXIter::setLabel(string const & label)
590 crow->setLabel(label);
598 MathedRowSt * MathedXIter::adjustVerticalSt()
602 // lyxerr << " CRW" << ncols << " ";
603 crow = new MathedRowSt(ncols + 1); // this leaks
605 // lyxerr<< " CRW[" << crow << "] ";
606 MathedRowSt * mrow = crow;
609 if (col >= ncols) ncols = col + 1;
610 MathedRowSt * r = new MathedRowSt(ncols + 1); // this leaks
611 // r->next = crow->next;
614 // lyxerr << " CX[" << crow << "]";
622 string const & MathedXIter::getLabel() const
624 return crow ? crow->getLabel() : error_label;
628 string MathedXIter::error_label = "$mathed-error$";