+2001-02-17 Lars Gullik Bjønnes <larsbj@lyx.org>
+ * math_xiter.h: move ipush and ipop to public, add _ on private
+ variables, move protected var to private, remove friend.
+
+ * math_cursor.C (insertInset): rename method from Insert also
+ remove default arg val. Call the public methods of xiter instead
+ of private variables.
+
+ * changes to several files beacuse of the above.
+
2001-02-14 André Pönitz <poenitz@htwm.de>
* math_iter.[Ch]: hide fcode_
}
+#if 0
+void MathedArray::insertInset(int pos, MathedInset * p, int type)
+{
+ //bf_.insert(pos, type);
+ InsetTable tmp(pos, p);
+ insetList_.push_back(tmp);
+}
+
+
+MathedInset * MathedArray::getInset(int pos)
+{
+ InsetList::const_iterator cit = insetList_.begin();
+ InsetList::const_iterator end = insetList_.end();
+ for (; cit != end; ++cit) {
+ if ((*cit).pos == pos)
+ return (*cit).inset;
+ }
+ // not found
+ return 0;
+ // We would really like to throw an exception instead... (Lgb)
+ // throw inset_not_found();
+}
+
+#else
void MathedArray::raw_pointer_insert(void * p, int pos, int len)
{
my_memcpy(&bf_[pos], &p, len);
}
+#endif
void MathedArray::strange_copy(MathedArray * dest, int dpos,
#endif
///
void raw_pointer_copy(MathedInset ** p, int pos) const;
+#if 0
+ ///
+ void insertInset(int pos, MathedInset * p, int type);
+ ///
+ MathedInset * getInset(int pos);
+#else
///
void raw_pointer_insert(void * p, int pos, int len);
+#endif
///
void strange_copy(MathedArray * dest, int dpos, int spos, int len);
///
private:
/// Buffer
buffer_type bf_;
+#if 0
+ ///
+ struct InsetTable {
+ ///
+ int pos;
+ ///
+ MathedInset * inset;
+ ///
+ InsetTable(int p, MathedInset * i)
+ : pos(p), inset(i) {}
+
+ };
+ ///
+ typedef std::vector<InsetTable> InsetList;
+ /// The list of insets in this array.
+ InsetList insetList_;
+#endif
/// Last position inserted.
int last_;
};
if (mathcursor && p) {
if (k > 2 && int(strlen(s)) > m)
p->SetAlign(s[0], &s[1]);
- mathcursor->Insert(p, LM_TC_ACTIVE_INSET);
+ mathcursor->insertInset(p, LM_TC_ACTIVE_INSET);
UpdateLocal(bv);
}
break;
}
MathDelimInset * p = new MathDelimInset(ilf, irg);
- mathcursor->Insert(p, LM_TC_ACTIVE_INSET);
+ mathcursor->insertInset(p, LM_TC_ACTIVE_INSET);
UpdateLocal(bv);
break;
}
case LFUN_PROTECTEDSPACE:
bv->lockedInsetStoreUndo(Undo::INSERT);
sp = new MathSpaceInset(1);
- mathcursor->Insert(sp);
+ mathcursor->insertInset(sp, LM_TC_INSET);
space_on = true;
UpdateLocal(bv);
break;
if (action == LFUN_MATH_MACROARG) {
int i = lyx::atoi(arg) - 1;
if (i >= 0 && i < tmacro->getNoArgs()) {
- mathcursor->Insert(tmacro->getMacroPar(i),
- LM_TC_INSET);
+ mathcursor->insertInset(tmacro->getMacroPar(i),
+ LM_TC_INSET);
InsetFormula::UpdateLocal(bv);
}
MacroModeClose();
if (t == LM_TC_CR) {
- MathParInset * p = cursor->p;
+ MathParInset * p = cursor->getPar();
if (p == par && p->GetType()<LM_OT_MPAR && p->GetType()>LM_OT_MIN) {
short int type = LM_OT_MPAR;
int cols = 1;
cursor->addRow();
}
} else if (t == LM_TC_TAB) {
- MathParInset * p = cursor->p;
+ MathParInset * p = cursor->getPar();
if (p && p->Permit(LMPF_ALLOW_TAB)) {
if (c) {
- cursor->Insert(c, t);
+ cursor->insert(c, t);
cursor->checkTabs();
} else
cursor->goNextColumn();
if (accent) {
doAccent(c, t);
} else
- cursor->Insert(c, t);
+ cursor->insert(c, t);
lastcode = t;
return;
}
-void MathedCursor::Insert(MathedInset * p, int t)
+void MathedCursor::insertInset(MathedInset * p, int t)
{
if (macro_mode)
MacroModeClose();
if (accent && !MathIsActive(t)) {
doAccent(p);
} else {
- cursor->Insert(p, t);
+ cursor->insertInset(p, t);
if (MathIsActive(t)) {
cursor->Prev();
Push();
return;
}
- MathParInset * p = cursor->p;
+ MathParInset * p = cursor->getPar();
if (p && p->GetType() <= LM_OT_MATRIX && p->GetType() >= LM_OT_MPAR) {
cursor->delRow();
}
result = cursor->Up();
- if (!result && cursor->p) {
- MathParInset * p = cursor->p;
+ if (!result && cursor->getPar()) {
+ MathParInset * p = cursor->getPar();
if (p->GetType() == LM_OT_SCRIPT) {
MathedXIter * cx = mathstk.Item(1);
}
result = cursor->Down();
- if (!result && cursor->p) {
- MathParInset * p= cursor->p;
+ if (!result && cursor->getPar()) {
+ MathParInset * p= cursor->getPar();
if (p->GetType() == LM_OT_SCRIPT) {
MathedXIter * cx = mathstk.Item(1);
bool is_up = (cx->GetChar() == LM_TC_UP);
void MathedCursor::SetSize(short size)
{
- MathParInset * p = cursor->p;
+ MathParInset * p = cursor->getPar();
p->UserSetSize(size);
cursor->SetData(p);
}
void MathedCursor::setNumbered()
-{
+{
// another ugly hack
- MathedRowSt * crow = cursor->crow;
- if (!crow)
- return;
- crow->setNumbered(!crow->isNumbered());
+ MathedRowSt * crow = cursor->currentRow();
+ if (crow)
+ crow->setNumbered(!crow->isNumbered());
}
cursor->ipop();
}
p = new MathParInset(LM_ST_SCRIPT, "", LM_OT_SCRIPT);
- Insert (p, (s[0] == '_') ? LM_TC_DOWN: LM_TC_UP);
+ insertInset(p, (s[0] == '_') ? LM_TC_DOWN: LM_TC_UP);
return;
} else
if (s[0] == '!' || s[0] == ',' || s[0] == ':' || s[0] == ';') {
int sp = ((s[0] == ',') ? 1:((s[0] == ':') ? 2:((s[0] == ';') ? 3: 0)));
p = new MathSpaceInset(sp);
- Insert(p);
+ insertInset(p, LM_TC_INSET);
return;
} else
l = in_word_set(s);
}
if (p) {
- Insert(p, tcode);
+ insertInset(p, tcode);
par->Metrics();
}
}
{
if (!macro_mode) {
imacro = new MathFuncInset("");
- Insert (imacro);
+ insertInset(imacro, LM_TC_INSET);
macro_mode = true;
} else
lyxerr << "Mathed Warning: Already in macro mode" << endl;
void MathedCursor::SelCopy()
{
if (selection) {
- int p1 = (cursor->pos < selpos) ? cursor->pos : selpos;
- int p2 = (cursor->pos > selpos) ? cursor->pos : selpos;
+ int p1 = (cursor->getPos() < selpos) ? cursor->getPos() : selpos;
+ int p2 = (cursor->getPos() > selpos) ?
+ cursor->getPos() : selpos;
selarray = cursor->Copy(p1, p2);
cursor->Adjust();
SelClear();
void MathedCursor::SelCut()
{
if (selection) {
- if (cursor->pos == selpos)
+ if (cursor->getPos() == selpos)
return;
- int p1 = (cursor->pos < selpos) ? cursor->pos : selpos;
- int p2 = (cursor->pos > selpos) ? cursor->pos : selpos;
+ int p1 = (cursor->getPos() < selpos) ? cursor->getPos() : selpos;
+ int p2 = (cursor->getPos() > selpos) ? cursor->getPos() : selpos;
selarray = cursor->Copy(p1, p2);
cursor->Clean(selpos);
cursor->Adjust();
{
// lyxerr << "Deleting sel "
if (selection) {
- if (cursor->pos == selpos)
+ if (cursor->getPos() == selpos)
return;
cursor->Clean(selpos);
cursor->Adjust();
{
lyxerr[Debug::MATHED] << "Starting sel " << endl;
if (!anchor) {
- selpos = cursor->pos;
+ selpos = cursor->getPos();
selstk = new MathStackXIter(mathstk);
anchor = selstk->Item(-1);
- anchor->SetData(cursor->p);
+ anchor->SetData(cursor->getPar());
anchor->GoBegin();
anchor->goPosAbs(selpos);
selection = true;
}
// Once balanced the levels, check that they are at the same paragraph
- selpos = anchor->pos;
+ selpos = anchor->getPos();
}
return;
}
- // single row selection
- int i = 0;
- int a;
- int d;
- int a1;
- int d1;
-
// Balance anchor and cursor
SelBalance();
int xo;
int yo;
- cursor->p->GetXY(xo, yo);
- int w = cursor->p->Width();
+ cursor->getPar()->GetXY(xo, yo);
+ int w = cursor->getPar()->Width();
int x1;
int y1;
cursor->GetPos(x1, y1);
+ int a1;
+ int d1;
cursor->getAD(a1, d1);
int x;
int y;
anchor->GetPos(x, y);
+ int a;
+ int d;
anchor->getAD(a, d);
+ // single row selection
+ int i = 0;
xpoint[i] = x;
ypoint[i++] = y + d;
xpoint[i] = x;
}
if (ac)
- cursor->Insert(ac);
+ cursor->insertInset(ac, LM_TC_INSET);
accent = 0; // consumed!
}
}
if (ac)
- cursor->Insert(ac);
+ cursor->insertInset(ac, LM_TC_INSET);
accent = 0; // consumed!
}
MathParInset * MathedCursor::getCurrentPar() const
{
- return cursor->p;
+ return cursor->getPar();
}
///
void Insert(byte, MathedTextCodes t = LM_TC_MIN);
///
- void Insert(MathedInset *, int t = LM_TC_INSET);
+ void insertInset(MathedInset *, int t);
///
void Home();
///
}
-void MathedIter::Insert(byte c, MathedTextCodes t)
+void MathedIter::insert(byte c, MathedTextCodes t)
{
if (c < ' ')
return;
}
-void MathedIter::Insert(MathedInset * p, int type)
+void MathedIter::insertInset(MathedInset * p, int type)
{
+#if 0
+ if (!MathIsInset(type))
+ type = LM_TC_INSET;
+
+ array->insertInset(pos, p, type);
+ ++pos;
+ fcode(-1);
+#else
int const shift = SizeInset;
if (!MathIsInset(type))
(*array)[pos - 1] = type;
(*array)[array->last()] = '\0';
fcode(-1);
+#endif
}
}
if (IsCR() && col < ncols - 2)
- Insert(' ', LM_TC_TAB);
+ insert(' ', LM_TC_TAB);
MathedIter::Next();
}
if (col < ncols - 2)
- Insert(' ', LM_TC_TAB);
+ insert(' ', LM_TC_TAB);
ipop();
}
///
bool IsCR() const;
///
- virtual void Reset();
+ void Reset();
///
- virtual void Insert(byte, MathedTextCodes c = LM_TC_CONST);
+ void insert(byte, MathedTextCodes c);
///
- virtual void Insert(MathedInset *, int t = LM_TC_INSET);
+ void insertInset(MathedInset *, int t);
///
- virtual bool Delete();
+ bool Delete();
///
virtual bool Next();
/// Check consistency of tabs and newlines
/// Recover previous state
virtual void ipop();
};
-
-///
-//#define MX_WAS_SUB 1
-///
-//#define MX_WAS_SUPER 2
-
#endif
addTemplate(m);
MathedArray * array = new MathedArray; // this leaks
iter.SetData(array);
- iter.Insert(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not)); // this leaks
+ iter.insertInset(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not),
+ LM_TC_INSET); // this leaks
m->setData(array);
// These two are only while we are still with LyX 2.x
addTemplate(m);
array = new MathedArray; // this leaks
iter.SetData(array);
- iter.Insert(new MathAccentInset('O', LM_TC_RM, LM_not)); // this leaks
+ iter.insertInset(new MathAccentInset('O', LM_TC_RM, LM_not),
+ LM_TC_INSET); // this leaks
m->setData(array);
m = new MathMacroTemplate("perp"); // this leaks
addTemplate(m);
array = new MathedArray; // this leaks
iter.SetData(array);
- iter.Insert(LM_bot, LM_TC_BOP);
+ iter.insert(LM_bot, LM_TC_BOP);
m->setData(array);
// binom has two arguments
m->setData(array);
iter.SetData(array);
inset = new MathDelimInset('(', ')');
- iter.Insert(inset, LM_TC_ACTIVE_INSET);
+ iter.insertInset(inset, LM_TC_ACTIVE_INSET);
array = new MathedArray;
iter.SetData(array);
MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
- iter.Insert(frac, LM_TC_ACTIVE_INSET);
+ iter.insertInset(frac, LM_TC_ACTIVE_INSET);
inset->setData(array);
array = new MathedArray;
array2 = new MathedArray;
iter.SetData(array);
- iter.Insert(m->getMacroPar(0));
+ iter.insertInset(m->getMacroPar(0), LM_TC_INSET);
iter.SetData(array2);
- iter.Insert(m->getMacroPar(1));
+ iter.insertInset(m->getMacroPar(1), LM_TC_INSET);
frac->SetData(array, array2);
/*
nr_ = n;
if (nr_ == 1 && nc_ > 1) {
for (int j = 0; j < nc_ - 1; ++j)
- it.Insert('T', LM_TC_TAB);
+ it.insert('T', LM_TC_TAB);
}
} else if (n < 0) {
row_ = new MathedRowSt(nc_ + 1);
}
if (it.IsCR()) {
while (nn > 0) {
- it.Insert(' ', LM_TC_TAB);
+ it.insert(' ', LM_TC_TAB);
--nn;
}
nn = nc_ - 1;
case LM_TK_ALPHA:
{
if (accent) {
- data.Insert(doAccent(yylval.i, varcode));
+ data.insertInset(doAccent(yylval.i, varcode), LM_TC_INSET);
} else
- data.Insert (yylval.i, varcode); //LM_TC_VAR);
+ data.insert(yylval.i, varcode); //LM_TC_VAR);
break;
}
case LM_TK_ARGUMENT:
{
if (macro) {
- data.Insert(macro->getMacroPar(yylval.i-1), LM_TC_INSET);
+ data.insertInset(macro->getMacroPar(yylval.i-1), LM_TC_INSET);
}
break;
}
}
case LM_TK_SPECIAL:
{
- data.Insert (yylval.i, LM_TC_SPECIAL);
+ data.insert(yylval.i, LM_TC_SPECIAL);
break;
}
case LM_TK_STR:
{
if (accent) {
- data.Insert(doAccent(yylval.i, LM_TC_CONST));
+ data.insertInset(doAccent(yylval.i, LM_TC_CONST), LM_TC_INSET);
} else
- data.Insert (yylval.i, LM_TC_CONST);
+ data.insert(yylval.i, LM_TC_CONST);
break;
}
case LM_TK_OPEN:
if (flags & FLAG_BRACE)
flags &= ~FLAG_BRACE;
else {
- data.Insert ('{', LM_TC_TEX);
+ data.insert('{', LM_TC_TEX);
}
break;
}
--plevel;
return array;
} else {
- data.Insert ('}', LM_TC_TEX);
+ data.insert('}', LM_TC_TEX);
}
break;
}
}
// if (arg) strcpy(arg, yytext);
} else
- data.Insert ('[');
+ data.insert('[', LM_TC_CONST);
break;
}
case ']':
--plevel;
return array;
} else
- data.Insert (']');
+ data.insert(']', LM_TC_CONST);
break;
}
MathedArray * ar = mathed_parse(FLAG_BRACE_OPT|FLAG_BRACE_LAST, 0);
p->setData(ar);
// lyxerr << "UP[" << p->GetStyle() << "]" << endl;
- data.Insert (p, LM_TC_UP);
+ data.insertInset(p, LM_TC_UP);
break;
}
case '_':
MathParInset * p = new MathParInset(size, "", LM_OT_SCRIPT);
MathedArray * ar = mathed_parse(FLAG_BRACE_OPT|FLAG_BRACE_LAST, 0);
p->setData(ar);
- data.Insert (p, LM_TC_DOWN);
+ data.insertInset(p, LM_TC_DOWN);
break;
}
{
if ((flags & FLAG_END) && mt && data.getCol()<mt->GetColumns() - 1) {
data.setNumCols(mt->GetColumns());
- data.Insert('T', LM_TC_TAB);
+ data.insert('T', LM_TC_TAB);
} else
mathPrintError("Unexpected tab");
// debug info. [made that conditional -JMarc]
crow->setNext(new MathedRowSt(mt->GetColumns() + 1)); // this leaks
crow = crow->getNext();
}
- data.Insert('K', LM_TC_CR);
+ data.insert('K', LM_TC_CR);
} else
mathPrintError("Unexpected newline");
}
case LM_TK_BIGSYM:
{
binset = new MathBigopInset(yylval.l->name, yylval.l->id);
- data.Insert(binset);
+ data.insertInset(binset, LM_TC_INSET);
break;
}
case LM_TK_SYM:
if (yylval.l->id < 256) {
MathedTextCodes tc = MathIsBOPS(yylval.l->id) ? LM_TC_BOPS: LM_TC_SYMB;
if (accent) {
- data.Insert(doAccent(yylval.l->id, tc));
+ data.insertInset(doAccent(yylval.l->id, tc), LM_TC_INSET);
} else
- data.Insert(yylval.l->id, tc);
+ data.insert(yylval.l->id, tc);
} else {
MathFuncInset * bg = new MathFuncInset(yylval.l->name);
if (accent) {
- data.Insert(doAccent(bg));
- } else
- data.Insert(bg, true);
+ data.insertInset(doAccent(bg), LM_TC_INSET);
+ } else {
+#warning This is suspisious! (Lgb)
+ // it should not take a bool as second arg (Lgb)
+ data.insertInset(bg, true);
+ }
+
}
break;
}
case LM_TK_BOP:
{
if (accent) {
- data.Insert(doAccent(yylval.i, LM_TC_BOP));
+ data.insertInset(doAccent(yylval.i, LM_TC_BOP), LM_TC_INSET);
} else
- data.Insert(yylval.i, LM_TC_BOP);
+ data.insert(yylval.i, LM_TC_BOP);
break;
}
case LM_TK_STY:
{
if (yylval.i >= 0) {
MathSpaceInset * sp = new MathSpaceInset(yylval.i);
- data.Insert(sp);
+ data.insertInset(sp, LM_TC_INSET);
}
break;
}
case LM_TK_DOTS:
{
MathDotsInset * p = new MathDotsInset(yylval.l->name, yylval.l->id);
- data.Insert(p);
+ data.insertInset(p, LM_TC_INSET);
break;
}
case LM_TK_STACK:
MathedArray * num = mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST);
MathedArray * den = mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST);
fc->SetData(num, den);
- data.Insert(fc, LM_TC_ACTIVE_INSET);
+ data.insertInset(fc, LM_TC_ACTIVE_INSET);
break;
}
case LM_TK_SQRT:
rt = new MathSqrtInset(size);
}
rt->setData(mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST, 0, &rt));
- data.Insert(rt, LM_TC_ACTIVE_INSET);
+ data.insertInset(rt, LM_TC_ACTIVE_INSET);
break;
}
rgd = (rgd == LM_TK_SYM) ? yylval.l->id: yylval.i;
MathDelimInset * dl = new MathDelimInset(lfd, rgd);
dl->setData(a);
- data.Insert(dl, LM_TC_ACTIVE_INSET);
+ data.insertInset(dl, LM_TC_ACTIVE_INSET);
// lyxerr << "RL[" << lfd << " " << rgd << "]";
break;
}
MathDecorationInset * sq = new MathDecorationInset(yylval.l->id,
size);
sq->setData(mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST));
- data.Insert(sq, LM_TC_ACTIVE_INSET);
+ data.insertInset(sq, LM_TC_ACTIVE_INSET);
break;
}
case LM_TK_PMOD:
case LM_TK_FUNC:
{
+#warning This must leak. (Lgb)
+ // if (accent) this must leak... (Lgb)
MathedInset * bg = new MathFuncInset(yylval.l->name);
if (accent) {
- data.Insert(t);
+ data.insert(t, LM_TC_CONST);
} else
- data.Insert(bg);
+ data.insertInset(bg, LM_TC_INSET);
break;
}
case LM_TK_FUNCLIM:
{
- data.Insert(new MathFuncInset(yylval.l->name, LM_OT_FUNCLIM));
+ data.insertInset(new MathFuncInset(yylval.l->name, LM_OT_FUNCLIM),
+ LM_TC_INSET);
break;
}
case LM_TK_UNDEF:
MathMacroTable::mathMTable.getMacro(yylval.s);
if (p) {
if (accent)
- data.Insert(doAccent(p), p->getTCode());
+ data.insertInset(doAccent(p), p->getTCode());
else
- data.Insert(p, p->getTCode());
+ data.insertInset(p, p->getTCode());
for (int i = 0; p->setArgumentIdx(i); ++i)
p->setData(mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST));
}
else {
MathedInset * q = new MathFuncInset(yylval.s, LM_OT_UNDEF);
if (accent) {
- data.Insert(doAccent(q));
+ data.insertInset(doAccent(q), LM_TC_INSET);
} else {
- data.Insert(q);
+ data.insertInset(q, LM_TC_INSET);
}
}
break;
int const nc = parse_align(ar, ar2);
MathParInset * mm = new MathMatrixInset(nc, 0);
mm->SetAlign(ar2[0], ar);
- data.Insert(mm, LM_TC_ACTIVE_INSET);
+ data.insertInset(mm, LM_TC_ACTIVE_INSET);
mathed_parse(FLAG_END, mm->GetData(), &mm);
} else if (is_eqn_type(yylval.i)) {
if (plevel!= 0) {
MathMacro * p =
MathMacroTable::mathMTable.getMacro(yytext.data());
if (p) {
- data.Insert(p, p->getTCode());
+ data.insertInset(p, p->getTCode());
p->setArgumentIdx(0);
mathed_parse(FLAG_END, p->GetData(), reinterpret_cast<MathParInset**>(&p));
// for (int i = 0; p->setArgumentIdx(i); ++i)
if (p) {
if (accent) {
- data.Insert(doAccent(p));
+ data.insertInset(doAccent(p), LM_TC_INSET);
} else
- data.Insert(p, static_cast<MathMacro*>(p)->getTCode());
+ data.insertInset(p, static_cast<MathMacro*>(p)->getTCode());
}
break;
}
using std::endl;
+string MathedXIter::error_label = "$mathed-error$";
+
MathedXIter::MathedXIter()
- : MathedIter(), sx(0), sw(0)
+ : MathedIter(), size_(0), x_(0), y_(0), p_(0), sx_(0), sw_(0),
+ crow_(0)
{
- x = y = size = 0;
- p = 0;
- crow = 0;
+ // should limits_ be initialized?
}
+MathedXIter::MathedXIter(MathParInset * pp)
+ : x_(0), y_(0), p_(pp), sx_(0), sw_(0), limits_(false)
+{
+ if (p_)
+ SetData(p_);
+ else {
+ crow_ = 0;
+ size_ = 0;
+ }
+}
+
+
+
MathParInset * MathedXIter::getPar() const
{
- return p;
+ return p_;
}
void MathedXIter::GetPos(int & xx, int & yy) const
{
- if (p)
- p->GetXY(xx, yy);
+ if (p_)
+ p_->GetXY(xx, yy);
else {
xx = 0;
yy = 0;
}
- xx += x;
- yy += y;
+ xx += x_;
+ yy += y_;
}
void MathedXIter::GetIncPos(int & xx, int & yy) const
{
- xx = x;
- yy = y;
+ xx = x_;
+ yy = y_;
}
void MathedXIter::getAD(int & a, int & d) const
{
- if (crow) {
- a = crow->ascent();
- d = crow->descent();
+ if (crow_) {
+ a = crow_->ascent();
+ d = crow_->descent();
} else
- if (p) {
- a = p->Ascent();
- d = p->Descent();
+ if (p_) {
+ a = p_->Ascent();
+ d = p_->Descent();
} else {
a = d = 0;
}
}
-
void MathedXIter::Clean(int pos2)
{
if (!array) {
continue;
}
if (IsCR()) {
- if (crow) {
- MathedRowSt * r = crow->getNext();
+ if (crow_) {
+ MathedRowSt * r = crow_->getNext();
if (r) {
- crow->setNext(r->getNext());
+ crow_->setNext(r->getNext());
delete r;
}
}
// Complete rows
while (pos < pos2 && OK()) {
if (IsCR()) {
- if (p && p->Permit(LMPF_ALLOW_CR)) {
- MathedRowSt * r = new MathedRowSt(ncols+1);
- if (crow) {
- r->setNext(crow->getNext());
- crow->setNext(r);
+ if (p_ && p_->Permit(LMPF_ALLOW_CR)) {
+ MathedRowSt * r = new MathedRowSt(ncols + 1);
+ if (crow_) {
+ r->setNext(crow_->getNext());
+ crow_->setNext(r);
} else {
r->setNext(0);
}
- crow = r;
+ crow_ = r;
} else {
Delete();
--pos2;
}
-
-
-MathedXIter::MathedXIter(MathParInset * pp)
- : p(pp)
-{
- x = y = 0;
- sx = sw = 0;
- limits = false;
- if (p)
- SetData(p);
- else {
- crow = 0;
- size = 0;
- }
-}
-
-
void MathedXIter::SetData(MathParInset * pp)
{
- p = pp;
- x = y = 0;
- array = p->GetData();
- ncols = p->GetColumns();
- crow = p->getRowSt();
- if (p->Permit(LMPF_ALLOW_CR))
+ p_ = pp;
+ x_ = y_ = 0;
+ array = p_->GetData();
+ ncols = p_->GetColumns();
+ crow_ = p_->getRowSt();
+ if (p_->Permit(LMPF_ALLOW_CR))
flags |= MthIF_CR;
- if (p->Permit(LMPF_ALLOW_TAB))
+ if (p_->Permit(LMPF_ALLOW_TAB))
flags |= MthIF_Tabs;
- if (crow) {
- x = crow->getTab(0);
- y = crow->getBaseline();
+ if (crow_) {
+ x_ = crow_->getTab(0);
+ y_ = crow_->getBaseline();
}
if (!array) {
array = new MathedArray; // this leaks
- p->setData(array);
+ p_->setData(array);
}
- size = p->GetStyle();
+ size_ = p_->GetStyle();
Reset();
}
string const MathedXIter::GetString() const
{
- string s = MathedIter::GetString();
- x += mathed_string_width(fcode(), size, s);
+ string const s = MathedIter::GetString();
+ x_ += mathed_string_width(fcode(), size_, s);
return s;
}
MathedInset * px = GetInset();
w = px->Width();
if (px->GetType() == LM_OT_SCRIPT) {
- if (w > sw) sw = w;
+ if (w > sw_) sw_ = w;
w = 0;
} else
- sx = (px->GetLimits()) ? w : 0;
+ sx_ = (px->GetLimits()) ? w : 0;
} else {
byte c = GetChar();
if (c >= ' ') {
// lyxerr << "WD[" << fcode << " " << size << " " << c << endl;
- w = mathed_char_width(fcode(), size, c);
+ w = mathed_char_width(fcode(), size_, c);
} else
- if (c == LM_TC_TAB && p) {
+ if (c == LM_TC_TAB && p_) {
// w = p->GetTab(col + 1);
- w = (crow) ? crow->getTab(col + 1) : 0;
+ w = (crow_) ? crow_->getTab(col + 1) : 0;
//lyxerr << "WW[" << w << "]";
} else
- if (c == LM_TC_CR && p) {
- x = 0;
- if (crow && crow->getNext()) {
- crow = crow->getNext();
- y = crow->getBaseline();
- w = crow->getTab(0);
+ if (c == LM_TC_CR && p_) {
+ x_ = 0;
+ if (crow_ && crow_->getNext()) {
+ crow_ = crow_->getNext();
+ y_ = crow_->getBaseline();
+ w = crow_->getTab(0);
}
// lyxerr << "WW[" << col " " << row << "|" << w << "]";
} else
// lyxerr <<"LNX " << pos << endl;
// if (sw>0 && GetChar()!= LM_TC_UP && GetChar()!= LM_TC_DOWN) {
// w = (sx>sw) ? 0: sw-sx;
- if ((sw > 0 || sx > 0)
+ if ((sw_ > 0 || sx_ > 0)
&& GetChar() != LM_TC_UP && GetChar() != LM_TC_DOWN) {
- if (sw > 0)
- w = (sx > sw) ? 0 : sw - sx;
- sx = sw = 0;
+ if (sw_ > 0)
+ w = (sx_ > sw_) ? 0 : sw_ - sx_;
+ sx_ = sw_ = 0;
}
- x += w;
+ x_ += w;
return true;
} else
return false;
void MathedXIter::GoBegin()
{
Reset();
- x = y = 0;
- sw = sx = 0;
- if (p) {
- crow = p->getRowSt();
- if (crow) {
- x = crow->getTab(0);
- y = crow->getBaseline();
+ x_ = y_ = 0;
+ sw_ = sx_ = 0;
+ if (p_) {
+ crow_ = p_->getRowSt();
+ if (crow_) {
+ x_ = crow_->getTab(0);
+ y_ = crow_->getBaseline();
}
}
}
bool MathedXIter::Up()
{
if (row == 0) return false;
- int xp = x;
+ int xp = x_;
int rowp = row;
int colp = col;
GoBegin();
while (row < rowp - 1) Next();
- while (x < xp && OK() && !IsCR()) {
+ while (x_ < xp && OK() && !IsCR()) {
ipush();
Next();
}
bool MathedXIter::Down()
{
- int xp = x;
+ int xp = x_;
int colp= col;
// int rowp = row
if (res) {
Next();
ipush();
- while (x < xp && OK()) {
+ while (x_ < xp && OK()) {
ipush();
Next();
}
- if (col > colp || (stck.col == colp && stck.x <= xp && x > xp))
+ if (col > colp || (stck.col == colp && stck.x <= xp && x_ > xp))
ipop();
return true;
}
}
-
void MathedXIter::addRow()
{
- if (!crow) {
+ if (!crow_) {
lyxerr[Debug::MATHED] << "MathErr: Attempt to insert new"
" line in a subparagraph. " << this << endl;
}
// Create new item for the structure
MathedRowSt * r = new MathedRowSt(ncols + 1);
- if (crow) {
- r->setNext(crow->getNext());
- crow->setNext(r);
+ if (crow_) {
+ r->setNext(crow_->getNext());
+ crow_->setNext(r);
} else {
- crow = r;
+ crow_ = r;
r->setNext(0);
}
// Fill missed tabs in current row
while (col < ncols - 1)
- Insert('T', LM_TC_TAB);
+ insert('T', LM_TC_TAB);
//newline
- Insert('K', LM_TC_CR);
+ insert('K', LM_TC_CR);
ipush();
if (!IsCR())
// Fill missed tabs in new row
while (col < ncols - 1)
- Insert('T', LM_TC_TAB);
+ insert('T', LM_TC_TAB);
ipop();
}
void MathedXIter::delRow()
{
- if (!crow) {
+ if (!crow_) {
lyxerr[Debug::MATHED] << "MathErr: Attempt to delete a line in a subparagraph." << endl;
return;
}
if (line_empty) {
- MathedRowSt * r = crow->getNext();
+ MathedRowSt * r = crow_->getNext();
if (r) {
- crow->setNext(r->getNext());
+ crow_->setNext(r->getNext());
delete r;
}
join(p1);
void MathedXIter::ipush()
{
MathedIter::ipush();
- stck.x = x;
- stck.y = y;
+ stck.x = x_;
+ stck.y = y_;
}
void MathedXIter::ipop()
{
MathedIter::ipop();
- x = stck.x;
- y = stck.y;
- if (p) {
- crow = p->getRowSt();
- if (crow)
+ x_ = stck.x;
+ y_ = stck.y;
+ if (p_) {
+ crow_ = p_->getRowSt();
+ if (crow_)
for (int i = 0; i < row; ++i)
- crow = crow->getNext();
+ crow_ = crow_->getNext();
}
}
int yo = 0;
GoBegin();
- if (p)
- p->GetXY(xo, yo);
+ if (p_)
+ p_->GetXY(xo, yo);
// first fit vertically
- while (crow && OK()) {
- if (yy >= yo + y - crow->ascent() && yy <= yo + y + crow->descent())
+ while (crow_ && OK()) {
+ if (yy >= yo + y_ - crow_->ascent()
+ && yy <= yo + y_ + crow_->descent())
break;
goNextCode(LM_TC_CR);
Next();
void MathedXIter::setTab(int tx, int tab)
{
- if (crow && tab <= ncols) {
- crow->setTab(tab, tx);
+ if (crow_ && tab <= ncols) {
+ crow_->setTab(tab, tx);
} else
lyxerr << "MathErr: No tabs allowed here" << endl;
}
void MathedXIter::subMetrics(int a, int d)
{
- if (!crow) {
+ if (!crow_) {
lyxerr[Debug::MATHED]
<< "MathErr: Attempt to submetric a subparagraph." << endl;
return;
}
- crow->ascent(a);
- crow->descent(d);
+ crow_->ascent(a);
+ crow_->descent(d);
}
if (!array) return;
if (array->empty()) return;
// if (pos2 > array->last) return;
- x1 = x;
+ x1 = x_;
while (pos < pos2) {
cx = GetChar();
if (cx >= ' ') {
- mathed_char_height(fcode(), size, cx, asc, des);
+ mathed_char_height(fcode(), size_, cx, asc, des);
if (asc > ascent) ascent = asc;
if (des > descent) descent = des;
limit = false;
if (MathIsInset(cx)) {
MathedInset * pp = GetInset();
if (cx == LM_TC_UP) {
- if (!asc && p) {
+ if (!asc && p_) {
int xx;
int yy;
- p->GetXY(xx, yy);
+ p_->GetXY(xx, yy);
static_cast<MathParInset*>(pp)->GetXY(xx, asc);
asc = yy - asc;
}
- asc += ((limits) ? pp->Height() + 4 : pp->Ascent());
+ asc += ((limits_) ? pp->Height() + 4 : pp->Ascent());
} else if (cx == LM_TC_DOWN) {
- if (!des && p) {
+ if (!des && p_) {
int xx;
int yy;
- p->GetXY(xx, yy);
+ p_->GetXY(xx, yy);
static_cast<MathParInset*>(pp)->GetXY(xx, des);
if (des - pp->Height() < yy && !asc)
asc = yy - (des - pp->Height());
}
if (pos < pos2) Next();
}
- width = x - x1;
+ width = x_ - x1;
}
bool MathedXIter::setNumbered(bool numb)
{
- if (crow) {
- crow->setNumbered(numb);
+ if (crow_) {
+ crow_->setNumbered(numb);
return true;
}
bool MathedXIter::setLabel(string const & label)
{
- if (crow) {
- crow->setLabel(label);
+ if (crow_) {
+ crow_->setLabel(label);
return true;
}
MathedRowSt * MathedXIter::adjustVerticalSt()
{
GoBegin();
- if (!crow) {
+ if (!crow_) {
// lyxerr << " CRW" << ncols << " ";
- crow = new MathedRowSt(ncols + 1); // this leaks
+ crow_ = new MathedRowSt(ncols + 1); // this leaks
}
-// lyxerr<< " CRW[" << crow << "] ";
- MathedRowSt * mrow = crow;
+// lyxerr<< " CRW[" << crow_ << "] ";
+ MathedRowSt * mrow = crow_;
while (OK()) {
if (IsCR()) {
if (col >= ncols) ncols = col + 1;
MathedRowSt * r = new MathedRowSt(ncols + 1); // this leaks
-// r->next = crow->next;
- crow->setNext(r);
- crow = r;
-// lyxerr << " CX[" << crow << "]";
+// r->next = crow_->next;
+ crow_->setNext(r);
+ crow_ = r;
+// lyxerr << " CX[" << crow_ << "]";
}
Next();
}
}
-string const & MathedXIter::getLabel() const
+string const & MathedXIter::getLabel() const
{
- return crow ? crow->getLabel() : error_label;
+ return crow_ ? crow_->getLabel() : error_label;
}
-string MathedXIter::error_label = "$mathed-error$";
///
MathParInset * getPar() const;
///
- bool Next();
+ virtual bool Next();
///
bool Prev();
///
void Clean(int pos2);
///
MathedRowSt * adjustVerticalSt();
+ ///
+ virtual void ipush();
+ ///
+ virtual void ipop();
+ ///
+ MathedRowSt * currentRow() {
+ return crow_;
+ }
+
private:
/// This function is not recursive, as MathPar::Metrics is
void IMetrics(int, int &, int &, int &);
/// Font size (display, text, script, script2)
- int size;
+ int size_;
/// current position
- mutable int x;
+ mutable int x_;
///
- int y;
+ int y_;
///
- MathParInset * p;
+ MathParInset * p_;
// Limits auxiliary variables
/// Position and max width of a script
- int sx;
+ int sx_;
///
- int sw;
+ int sw_;
/// true= center, false= left align (default)
- bool limits;
- ///
- void ipush();
- ///
- void ipop();
-protected:
+ bool limits_;
///
- MathedRowSt * crow;
+ MathedRowSt * crow_;
///
- friend class MathedCursor;
+ //friend class MathedCursor;
};
#endif