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();
141 // make room for the data
143 array->mergeF(a, pos, a->last());
146 int pos2 = pos + a->last();
151 while (pos < pos2 && OK()) {
153 if (p && p->Permit(LMPF_ALLOW_CR)) {
154 MathedRowSt * r = new MathedRowSt(ncols+1);
156 r->setNext(crow->getNext());
180 MathedXIter::MathedXIter(MathParInset * pp)
196 void MathedXIter::SetData(MathParInset * pp)
200 array = p->GetData();
201 ncols = p->GetColumns();
202 crow = p->getRowSt();
203 if (p->Permit(LMPF_ALLOW_CR))
205 if (p->Permit(LMPF_ALLOW_TAB))
210 y = crow->getBaseline();
213 array = new MathedArray; // this leaks
216 size = p->GetStyle();
221 string const MathedXIter::GetString() const
223 string s = MathedIter::GetString();
224 x += mathed_string_width(fcode, size, s);
229 bool MathedXIter::Next()
231 // lyxerr << "Ne[" << pos << "]";
232 if (!OK()) return false;
236 MathedInset * px = GetInset();
238 if (px->GetType() == LM_OT_SCRIPT) {
242 sx = (px->GetLimits()) ? w : 0;
246 // lyxerr << "WD[" << fcode << " " << size << " " << c << endl;
247 w = mathed_char_width(fcode, size, c);
249 if (c == LM_TC_TAB && p) {
250 // w = p->GetTab(col + 1);
251 w = (crow) ? crow->getTab(col + 1) : 0;
252 //lyxerr << "WW[" << w << "]";
254 if (c == LM_TC_CR && p) {
256 if (crow && crow->getNext()) {
257 crow = crow->getNext();
258 y = crow->getBaseline();
261 // lyxerr << "WW[" << col " " << row << "|" << w << "]";
263 lyxerr << "No hubo w[" << c << "]!";
265 if (MathedIter::Next()) {
266 // lyxerr <<"LNX " << pos << endl;
267 // if (sw>0 && GetChar()!= LM_TC_UP && GetChar()!= LM_TC_DOWN) {
268 // w = (sx>sw) ? 0: sw-sx;
269 if ((sw > 0 || sx > 0)
270 && GetChar() != LM_TC_UP && GetChar() != LM_TC_DOWN) {
272 w = (sx > sw) ? 0 : sw - sx;
282 void MathedXIter::GoBegin()
288 crow = p->getRowSt();
291 y = crow->getBaseline();
297 void MathedXIter::GoLast()
303 void MathedXIter::Adjust()
307 while (posx > pos && OK()) Next();
311 bool MathedXIter::Prev()
313 if (pos == 0 || (pos == 1 && GetChar() >= ' '))
316 int pos2 = pos; // pos1
328 bool MathedXIter::goNextColumn()
332 while (Next() && col == colp);
334 return (col != colp + 1 || rowp != row);
338 bool MathedXIter::Up()
340 if (row == 0) return false;
345 while (row < rowp - 1) Next();
346 while (x < xp && OK() && !IsCR()) {
350 if (col > colp) // || (stck.col == colp && stck.x<= xp && x>xp))
357 bool MathedXIter::Down()
363 bool res = (IsCR()) ? true : goNextCode(LM_TC_CR);
367 while (x < xp && OK()) {
371 if (col > colp || (stck.col == colp && stck.x <= xp && x > xp))
380 void MathedXIter::addRow()
383 lyxerr[Debug::MATHED] << "MathErr: Attempt to insert new"
384 " line in a subparagraph. " << this << endl;
388 // Create new item for the structure
389 MathedRowSt * r = new MathedRowSt(ncols + 1);
391 r->setNext(crow->getNext());
397 // Fill missed tabs in current row
398 while (col < ncols - 1)
399 Insert('T', LM_TC_TAB);
401 Insert('K', LM_TC_CR);
405 goNextCode(LM_TC_CR);
407 // Fill missed tabs in new row
408 while (col < ncols - 1)
409 Insert('T', LM_TC_TAB);
414 void MathedXIter::delRow()
417 lyxerr[Debug::MATHED] << "MathErr: Attempt to delete a line in a subparagraph." << endl;
420 bool line_empty = true;
426 } else if (!IsTab()) {
430 int const p1 = getPos();
435 MathedRowSt * r = crow->getNext();
437 crow->setNext(r->getNext());
449 void MathedXIter::ipush()
457 void MathedXIter::ipop()
463 crow = p->getRowSt();
465 for (int i = 0; i < row; ++i)
466 crow = crow->getNext();
471 void MathedXIter::fitCoord(int /*xx*/, int yy)
479 // first fit vertically
480 while (crow && OK()) {
481 if (yy >= yo + y - crow->ascent() && yy <= yo + y + crow->descent())
483 goNextCode(LM_TC_CR);
487 // while (x<xx && Next());
491 void MathedXIter::setTab(int tx, int tab)
493 if (crow && tab <= ncols) {
494 crow->setTab(tab, tx);
496 lyxerr << "MathErr: No tabs allowed here" << endl;
500 void MathedXIter::subMetrics(int a, int d)
503 lyxerr[Debug::MATHED]
504 << "MathErr: Attempt to submetric a subparagraph." << endl;
512 // This function is not recursive, as MathPar::Metrics is
513 void MathedXIter::IMetrics(int pos2, int & width, int & ascent, int & descent)
521 descent = ascent = width = 0;
523 if (array->empty()) return;
524 // if (pos2 > array->last) return;
529 mathed_char_height(FCode(), size, cx, asc, des);
530 if (asc > ascent) ascent = asc;
531 if (des > descent) descent = des;
534 if (MathIsInset(cx)) {
535 MathedInset * pp = GetInset();
536 if (cx == LM_TC_UP) {
541 static_cast<MathParInset*>(pp)->GetXY(xx, asc);
544 asc += ((limits) ? pp->Height() + 4 : pp->Ascent());
545 } else if (cx == LM_TC_DOWN) {
550 static_cast<MathParInset*>(pp)->GetXY(xx, des);
551 if (des - pp->Height() < yy && !asc)
552 asc = yy - (des - pp->Height());
555 des += (limit ? pp->Height()+4: pp->Height()-pp->Ascent()/2);
560 if (asc > ascent) ascent = asc;
561 if (des > descent) descent = des;
562 if (cx != LM_TC_UP && cx != LM_TC_DOWN)
563 limit = pp->GetLimits();
564 } else if (cx == LM_TC_TAB) {
567 lyxerr[Debug::MATHED]
568 << "Mathed Sel-Error: Unrecognized code["
569 << cx << ']' << endl;
572 if (pos < pos2) Next();
578 bool MathedXIter::setNumbered(bool numb)
581 crow->setNumbered(numb);
589 bool MathedXIter::setLabel(string const & label)
592 crow->setLabel(label);
600 MathedRowSt * MathedXIter::adjustVerticalSt()
604 // lyxerr << " CRW" << ncols << " ";
605 crow = new MathedRowSt(ncols + 1); // this leaks
607 // lyxerr<< " CRW[" << crow << "] ";
608 MathedRowSt * mrow = crow;
611 if (col >= ncols) ncols = col + 1;
612 MathedRowSt * r = new MathedRowSt(ncols + 1); // this leaks
613 // r->next = crow->next;
616 // lyxerr << " CX[" << crow << "]";
624 string const & MathedXIter::getLabel() const
626 return crow ? crow->getLabel() : error_label;
630 string MathedXIter::error_label = "$mathed-error$";