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 void MathedXIter::GetPos(int & xx, int & yy) const
32 int MathedXIter::GetX() const
41 int MathedXIter::GetY() const
50 void MathedXIter::GetIncPos(int & xx, int & yy) const
57 void MathedXIter::getAD(int & a, int & d) const
73 void MathedXIter::Clean(int pos2)
76 lyxerr << "Math error: Attempting to clean a void array." << endl;
84 while (pos < pos2 && OK()) {
92 while (OK() && pos < pos2) {
94 MathedInset * inset = GetInset();
96 if (inset->GetType()!= LM_OT_MACRO_ARG)
102 MathedRowSt * r = crow->getNext();
104 crow->setNext(r->getNext());
113 if (pos2 <= array->last()) {
121 void MathedXIter::Merge(MathedArray * a0)
124 lyxerr[Debug::MATHED]
125 << "Math error: Attempting to merge a void array." << endl;
129 // All insets must be clonned
131 MathedArray * a = it.Copy();
133 // make room for the data
135 array->mergeF(a, pos, a->last());
138 int pos2 = pos + a->last();
143 while (pos < pos2 && OK()) {
145 if (p && p->Permit(LMPF_ALLOW_CR)) {
146 MathedRowSt * r = new MathedRowSt(ncols+1);
148 r->setNext(crow->getNext());
172 MathedXIter::MathedXIter(MathParInset * pp)
188 void MathedXIter::SetData(MathParInset * pp)
192 array = p->GetData();
193 ncols = p->GetColumns();
194 crow = p->getRowSt();
195 if (p->Permit(LMPF_ALLOW_CR))
197 if (p->Permit(LMPF_ALLOW_TAB))
202 y = crow->getBaseline();
205 array = new MathedArray; // this leaks
208 size = p->GetStyle();
213 string const MathedXIter::GetString() const
215 string s = MathedIter::GetString();
216 x += mathed_string_width(fcode, size, s);
221 bool MathedXIter::Next()
223 // lyxerr << "Ne[" << pos << "]";
224 if (!OK()) return false;
228 MathedInset * px = GetInset();
230 if (px->GetType() == LM_OT_SCRIPT) {
234 sx = (px->GetLimits()) ? w : 0;
238 // lyxerr << "WD[" << fcode << " " << size << " " << c << endl;
239 w = mathed_char_width(fcode, size, c);
241 if (c == LM_TC_TAB && p) {
242 // w = p->GetTab(col + 1);
243 w = (crow) ? crow->getTab(col + 1) : 0;
244 //lyxerr << "WW[" << w << "]";
246 if (c == LM_TC_CR && p) {
248 if (crow && crow->getNext()) {
249 crow = crow->getNext();
250 y = crow->getBaseline();
253 // lyxerr << "WW[" << col " " << row << "|" << w << "]";
255 lyxerr << "No hubo w[" << c << "]!";
257 if (MathedIter::Next()) {
258 // lyxerr <<"LNX " << pos << endl;
259 // if (sw>0 && GetChar()!= LM_TC_UP && GetChar()!= LM_TC_DOWN) {
260 // w = (sx>sw) ? 0: sw-sx;
261 if ((sw > 0 || sx > 0)
262 && GetChar() != LM_TC_UP && GetChar() != LM_TC_DOWN) {
264 w = (sx > sw) ? 0 : sw - sx;
274 void MathedXIter::GoBegin()
280 crow = p->getRowSt();
283 y = crow->getBaseline();
289 void MathedXIter::GoLast()
295 void MathedXIter::Adjust()
299 while (posx > pos && OK()) Next();
303 bool MathedXIter::Prev()
305 if (pos == 0 || (pos == 1 && GetChar() >= ' '))
308 int pos2 = pos; // pos1
320 bool MathedXIter::goNextColumn()
324 while (Next() && col == colp);
326 return (col != colp + 1 || rowp != row);
330 bool MathedXIter::Up()
332 if (row == 0) return false;
337 while (row < rowp - 1) Next();
338 while (x < xp && OK() && !IsCR()) {
342 if (col > colp) // || (stck.col == colp && stck.x<= xp && x>xp))
349 bool MathedXIter::Down()
355 bool res = (IsCR()) ? true : goNextCode(LM_TC_CR);
359 while (x < xp && OK()) {
363 if (col > colp || (stck.col == colp && stck.x <= xp && x > xp))
372 void MathedXIter::addRow()
375 lyxerr[Debug::MATHED] << "MathErr: Attempt to insert new"
376 " line in a subparagraph. " << this << endl;
380 // Create new item for the structure
381 MathedRowSt * r = new MathedRowSt(ncols + 1);
383 r->setNext(crow->getNext());
389 // Fill missed tabs in current row
390 while (col < ncols - 1)
391 Insert('T', LM_TC_TAB);
393 Insert('K', LM_TC_CR);
397 goNextCode(LM_TC_CR);
399 // Fill missed tabs in new row
400 while (col < ncols - 1)
401 Insert('T', LM_TC_TAB);
406 void MathedXIter::delRow()
409 lyxerr[Debug::MATHED] << "MathErr: Attempt to delete a line in a subparagraph." << endl;
412 bool line_empty = true;
418 } else if (!IsTab()) {
422 int const p1 = getPos();
427 MathedRowSt * r = crow->getNext();
429 crow->setNext(r->getNext());
441 void MathedXIter::ipush()
449 void MathedXIter::ipop()
455 crow = p->getRowSt();
457 for (int i = 0; i < row; ++i)
458 crow = crow->getNext();
463 void MathedXIter::fitCoord(int /*xx*/, int yy)
471 // first fit vertically
472 while (crow && OK()) {
473 if (yy >= yo + y - crow->ascent() && yy <= yo + y + crow->descent())
475 goNextCode(LM_TC_CR);
479 // while (x<xx && Next());
483 void MathedXIter::setTab(int tx, int tab)
485 if (crow && tab <= ncols) {
486 crow->setTab(tab, tx);
488 lyxerr << "MathErr: No tabs allowed here" << endl;
492 void MathedXIter::subMetrics(int a, int d)
495 lyxerr[Debug::MATHED]
496 << "MathErr: Attempt to submetric a subparagraph." << endl;
504 // This function is not recursive, as MathPar::Metrics is
505 void MathedXIter::IMetrics(int pos2, int & width, int & ascent, int & descent)
513 descent = ascent = width = 0;
515 if (array->empty()) return;
516 // if (pos2 > array->last) return;
521 mathed_char_height(FCode(), size, cx, asc, des);
522 if (asc > ascent) ascent = asc;
523 if (des > descent) descent = des;
526 if (MathIsInset(cx)) {
527 MathedInset * pp = GetInset();
528 if (cx == LM_TC_UP) {
533 static_cast<MathParInset*>(pp)->GetXY(xx, asc);
536 asc += ((limits) ? pp->Height() + 4 : pp->Ascent());
537 } else if (cx == LM_TC_DOWN) {
542 static_cast<MathParInset*>(pp)->GetXY(xx, des);
543 if (des - pp->Height() < yy && !asc)
544 asc = yy - (des - pp->Height());
547 des += (limit ? pp->Height()+4: pp->Height()-pp->Ascent()/2);
552 if (asc > ascent) ascent = asc;
553 if (des > descent) descent = des;
554 if (cx != LM_TC_UP && cx != LM_TC_DOWN)
555 limit = pp->GetLimits();
556 } else if (cx == LM_TC_TAB) {
559 lyxerr[Debug::MATHED]
560 << "Mathed Sel-Error: Unrecognized code["
561 << cx << ']' << endl;
564 if (pos < pos2) Next();
570 bool MathedXIter::setNumbered(bool numb)
573 crow->setNumbered(numb);
581 bool MathedXIter::setLabel(string const & label)
584 crow->setLabel(label);
592 MathedRowSt * MathedXIter::adjustVerticalSt()
596 // lyxerr << " CRW" << ncols << " ";
597 crow = new MathedRowSt(ncols + 1); // this leaks
599 // lyxerr<< " CRW[" << crow << "] ";
600 MathedRowSt * mrow = crow;
603 if (col >= ncols) ncols = col + 1;
604 MathedRowSt * r = new MathedRowSt(ncols + 1); // this leaks
605 // r->next = crow->next;
608 // lyxerr << " CX[" << crow << "]";
616 string const & MathedXIter::getLabel() const
618 return crow ? crow->getLabel() : error_label;
622 string MathedXIter::error_label = "$mathed-error$";