3 #include "math_xiter.h"
4 #include "math_parinset.h"
5 #include "math_rowst.h"
7 #include "mathed/support.h"
11 MathedXIter::MathedXIter()
12 : MathedIter(), sx(0), sw(0)
20 MathParInset * MathedXIter::getPar() const
26 void MathedXIter::GetPos(int & xx, int & yy) const
39 int MathedXIter::GetX() const
48 int MathedXIter::GetY() const
57 void MathedXIter::GetIncPos(int & xx, int & yy) const
64 void MathedXIter::getAD(int & a, int & d) const
80 void MathedXIter::Clean(int pos2)
83 lyxerr << "Math error: Attempting to clean a void array." << endl;
91 while (pos < pos2 && OK()) {
99 while (OK() && pos < pos2) {
101 MathedInset * inset = GetInset();
103 if (inset->GetType()!= LM_OT_MACRO_ARG)
109 MathedRowSt * r = crow->getNext();
111 crow->setNext(r->getNext());
120 if (pos2 <= array->last()) {
128 void MathedXIter::Merge(MathedArray * a0)
131 lyxerr[Debug::MATHED]
132 << "Math error: Attempting to merge a void array." << endl;
136 // All insets must be clonned
138 MathedArray * a = it.Copy();
140 // make room for the data
142 array->mergeF(a, pos, a->last());
145 int pos2 = pos + a->last();
150 while (pos < pos2 && OK()) {
152 if (p && p->Permit(LMPF_ALLOW_CR)) {
153 MathedRowSt * r = new MathedRowSt(ncols+1);
155 r->setNext(crow->getNext());
179 MathedXIter::MathedXIter(MathParInset * pp)
195 void MathedXIter::SetData(MathParInset * pp)
199 array = p->GetData();
200 ncols = p->GetColumns();
201 crow = p->getRowSt();
202 if (p->Permit(LMPF_ALLOW_CR))
204 if (p->Permit(LMPF_ALLOW_TAB))
209 y = crow->getBaseline();
212 array = new MathedArray; // this leaks
215 size = p->GetStyle();
220 string const MathedXIter::GetString() const
222 string s = MathedIter::GetString();
223 x += mathed_string_width(fcode, size, s);
228 bool MathedXIter::Next()
230 // lyxerr << "Ne[" << pos << "]";
231 if (!OK()) return false;
235 MathedInset * px = GetInset();
237 if (px->GetType() == LM_OT_SCRIPT) {
241 sx = (px->GetLimits()) ? w : 0;
245 // lyxerr << "WD[" << fcode << " " << size << " " << c << endl;
246 w = mathed_char_width(fcode, size, c);
248 if (c == LM_TC_TAB && p) {
249 // w = p->GetTab(col + 1);
250 w = (crow) ? crow->getTab(col + 1) : 0;
251 //lyxerr << "WW[" << w << "]";
253 if (c == LM_TC_CR && p) {
255 if (crow && crow->getNext()) {
256 crow = crow->getNext();
257 y = crow->getBaseline();
260 // lyxerr << "WW[" << col " " << row << "|" << w << "]";
262 lyxerr << "No hubo w[" << c << "]!";
264 if (MathedIter::Next()) {
265 // lyxerr <<"LNX " << pos << endl;
266 // if (sw>0 && GetChar()!= LM_TC_UP && GetChar()!= LM_TC_DOWN) {
267 // w = (sx>sw) ? 0: sw-sx;
268 if ((sw > 0 || sx > 0)
269 && GetChar() != LM_TC_UP && GetChar() != LM_TC_DOWN) {
271 w = (sx > sw) ? 0 : sw - sx;
281 void MathedXIter::GoBegin()
287 crow = p->getRowSt();
290 y = crow->getBaseline();
296 void MathedXIter::GoLast()
302 void MathedXIter::Adjust()
306 while (posx > pos && OK()) Next();
310 bool MathedXIter::Prev()
312 if (pos == 0 || (pos == 1 && GetChar() >= ' '))
315 int pos2 = pos; // pos1
327 bool MathedXIter::goNextColumn()
331 while (Next() && col == colp);
333 return (col != colp + 1 || rowp != row);
337 bool MathedXIter::Up()
339 if (row == 0) return false;
344 while (row < rowp - 1) Next();
345 while (x < xp && OK() && !IsCR()) {
349 if (col > colp) // || (stck.col == colp && stck.x<= xp && x>xp))
356 bool MathedXIter::Down()
362 bool res = (IsCR()) ? true : goNextCode(LM_TC_CR);
366 while (x < xp && OK()) {
370 if (col > colp || (stck.col == colp && stck.x <= xp && x > xp))
379 void MathedXIter::addRow()
382 lyxerr[Debug::MATHED] << "MathErr: Attempt to insert new"
383 " line in a subparagraph. " << this << endl;
387 // Create new item for the structure
388 MathedRowSt * r = new MathedRowSt(ncols + 1);
390 r->setNext(crow->getNext());
396 // Fill missed tabs in current row
397 while (col < ncols - 1)
398 Insert('T', LM_TC_TAB);
400 Insert('K', LM_TC_CR);
404 goNextCode(LM_TC_CR);
406 // Fill missed tabs in new row
407 while (col < ncols - 1)
408 Insert('T', LM_TC_TAB);
413 void MathedXIter::delRow()
416 lyxerr[Debug::MATHED] << "MathErr: Attempt to delete a line in a subparagraph." << endl;
419 bool line_empty = true;
425 } else if (!IsTab()) {
429 int const p1 = getPos();
434 MathedRowSt * r = crow->getNext();
436 crow->setNext(r->getNext());
448 void MathedXIter::ipush()
456 void MathedXIter::ipop()
462 crow = p->getRowSt();
464 for (int i = 0; i < row; ++i)
465 crow = crow->getNext();
470 void MathedXIter::fitCoord(int /*xx*/, int yy)
478 // first fit vertically
479 while (crow && OK()) {
480 if (yy >= yo + y - crow->ascent() && yy <= yo + y + crow->descent())
482 goNextCode(LM_TC_CR);
486 // while (x<xx && Next());
490 void MathedXIter::setTab(int tx, int tab)
492 if (crow && tab <= ncols) {
493 crow->setTab(tab, tx);
495 lyxerr << "MathErr: No tabs allowed here" << endl;
499 void MathedXIter::subMetrics(int a, int d)
502 lyxerr[Debug::MATHED]
503 << "MathErr: Attempt to submetric a subparagraph." << endl;
511 // This function is not recursive, as MathPar::Metrics is
512 void MathedXIter::IMetrics(int pos2, int & width, int & ascent, int & descent)
520 descent = ascent = width = 0;
522 if (array->empty()) return;
523 // if (pos2 > array->last) return;
528 mathed_char_height(FCode(), size, cx, asc, des);
529 if (asc > ascent) ascent = asc;
530 if (des > descent) descent = des;
533 if (MathIsInset(cx)) {
534 MathedInset * pp = GetInset();
535 if (cx == LM_TC_UP) {
540 static_cast<MathParInset*>(pp)->GetXY(xx, asc);
543 asc += ((limits) ? pp->Height() + 4 : pp->Ascent());
544 } else if (cx == LM_TC_DOWN) {
549 static_cast<MathParInset*>(pp)->GetXY(xx, des);
550 if (des - pp->Height() < yy && !asc)
551 asc = yy - (des - pp->Height());
554 des += (limit ? pp->Height()+4: pp->Height()-pp->Ascent()/2);
559 if (asc > ascent) ascent = asc;
560 if (des > descent) descent = des;
561 if (cx != LM_TC_UP && cx != LM_TC_DOWN)
562 limit = pp->GetLimits();
563 } else if (cx == LM_TC_TAB) {
566 lyxerr[Debug::MATHED]
567 << "Mathed Sel-Error: Unrecognized code["
568 << cx << ']' << endl;
571 if (pos < pos2) Next();
577 bool MathedXIter::setNumbered(bool numb)
580 crow->setNumbered(numb);
588 bool MathedXIter::setLabel(string const & label)
591 crow->setLabel(label);
599 MathedRowSt * MathedXIter::adjustVerticalSt()
603 // lyxerr << " CRW" << ncols << " ";
604 crow = new MathedRowSt(ncols + 1); // this leaks
606 // lyxerr<< " CRW[" << crow << "] ";
607 MathedRowSt * mrow = crow;
610 if (col >= ncols) ncols = col + 1;
611 MathedRowSt * r = new MathedRowSt(ncols + 1); // this leaks
612 // r->next = crow->next;
615 // lyxerr << " CX[" << crow << "]";
623 string const & MathedXIter::getLabel() const
625 return crow ? crow->getLabel() : error_label;
629 string MathedXIter::error_label = "$mathed-error$";