From 29d6854e98d9cf3008bea6c967c7c8b70298bf9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Sat, 17 Feb 2001 18:52:53 +0000 Subject: [PATCH] remove a friend + other stuff git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1530 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/ChangeLog | 10 ++ src/mathed/array.C | 25 ++++ src/mathed/array.h | 24 +++ src/mathed/formula.C | 6 +- src/mathed/formulamacro.C | 4 +- src/mathed/math_cursor.C | 83 +++++------ src/mathed/math_cursor.h | 2 +- src/mathed/math_iter.C | 17 ++- src/mathed/math_iter.h | 14 +- src/mathed/math_macrotable.C | 16 +- src/mathed/math_matrixinset.C | 4 +- src/mathed/math_parser.C | 85 ++++++----- src/mathed/math_xiter.C | 271 +++++++++++++++++----------------- src/mathed/math_xiter.h | 34 +++-- 14 files changed, 332 insertions(+), 263 deletions(-) diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index d975a4c99f..e9e3b5eafd 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,4 +1,14 @@ +2001-02-17 Lars Gullik Bjønnes + * 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 * math_iter.[Ch]: hide fcode_ diff --git a/src/mathed/array.C b/src/mathed/array.C index 245b801a2f..f93104b464 100644 --- a/src/mathed/array.C +++ b/src/mathed/array.C @@ -120,10 +120,35 @@ void MathedArray::raw_pointer_copy(MathedInset ** p, int pos) const } +#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, diff --git a/src/mathed/array.h b/src/mathed/array.h index c9d042587a..35a2f25c27 100644 --- a/src/mathed/array.h +++ b/src/mathed/array.h @@ -84,8 +84,15 @@ public: #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); /// @@ -102,6 +109,23 @@ public: 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 InsetList; + /// The list of insets in this array. + InsetList insetList_; +#endif /// Last position inserted. int last_; }; diff --git a/src/mathed/formula.C b/src/mathed/formula.C index 6456dfad99..acd8c3c2ef 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -945,7 +945,7 @@ InsetFormula::LocalDispatch(BufferView * bv, int action, string const & arg) 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; @@ -993,7 +993,7 @@ InsetFormula::LocalDispatch(BufferView * bv, int action, string const & arg) } MathDelimInset * p = new MathDelimInset(ilf, irg); - mathcursor->Insert(p, LM_TC_ACTIVE_INSET); + mathcursor->insertInset(p, LM_TC_ACTIVE_INSET); UpdateLocal(bv); break; } @@ -1001,7 +1001,7 @@ InsetFormula::LocalDispatch(BufferView * bv, int action, string const & arg) 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; diff --git a/src/mathed/formulamacro.C b/src/mathed/formulamacro.C index be5a9c60f6..e93d5ea816 100644 --- a/src/mathed/formulamacro.C +++ b/src/mathed/formulamacro.C @@ -211,8 +211,8 @@ InsetFormulaMacro::LocalDispatch(BufferView * bv, 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); } diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 4cb9e3dea0..a8290700b7 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -432,7 +432,7 @@ void MathedCursor::Insert(byte c, MathedTextCodes t) MacroModeClose(); if (t == LM_TC_CR) { - MathParInset * p = cursor->p; + MathParInset * p = cursor->getPar(); if (p == par && p->GetType()GetType()>LM_OT_MIN) { short int type = LM_OT_MPAR; int cols = 1; @@ -466,10 +466,10 @@ void MathedCursor::Insert(byte c, MathedTextCodes t) 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(); @@ -493,7 +493,7 @@ void MathedCursor::Insert(byte c, MathedTextCodes t) if (accent) { doAccent(c, t); } else - cursor->Insert(c, t); + cursor->insert(c, t); lastcode = t; return; @@ -502,7 +502,7 @@ void MathedCursor::Insert(byte c, MathedTextCodes t) } -void MathedCursor::Insert(MathedInset * p, int t) +void MathedCursor::insertInset(MathedInset * p, int t) { if (macro_mode) MacroModeClose(); @@ -519,7 +519,7 @@ void MathedCursor::Insert(MathedInset * p, int t) if (accent && !MathIsActive(t)) { doAccent(p); } else { - cursor->Insert(p, t); + cursor->insertInset(p, t); if (MathIsActive(t)) { cursor->Prev(); Push(); @@ -559,7 +559,7 @@ void MathedCursor::DelLine() return; } - MathParInset * p = cursor->p; + MathParInset * p = cursor->getPar(); if (p && p->GetType() <= LM_OT_MATRIX && p->GetType() >= LM_OT_MPAR) { cursor->delRow(); @@ -598,8 +598,8 @@ bool MathedCursor::Up(bool sel) } 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); @@ -655,8 +655,8 @@ bool MathedCursor::Down(bool sel) } 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); @@ -693,7 +693,7 @@ bool MathedCursor::Limits() void MathedCursor::SetSize(short size) { - MathParInset * p = cursor->p; + MathParInset * p = cursor->getPar(); p->UserSetSize(size); cursor->SetData(p); } @@ -708,12 +708,11 @@ void MathedCursor::setLabel(string const & label) 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()); } @@ -742,13 +741,13 @@ void MathedCursor::Interpret(string const & s) 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); @@ -830,7 +829,7 @@ void MathedCursor::Interpret(string const & s) } if (p) { - Insert(p, tcode); + insertInset(p, tcode); par->Metrics(); } } @@ -861,7 +860,7 @@ void MathedCursor::MacroModeOpen() { 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; @@ -902,8 +901,9 @@ void MathedCursor::MacroModeClose() 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(); @@ -914,11 +914,11 @@ void MathedCursor::SelCopy() 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(); @@ -931,7 +931,7 @@ void MathedCursor::SelDel() { // lyxerr << "Deleting sel " if (selection) { - if (cursor->pos == selpos) + if (cursor->getPos() == selpos) return; cursor->Clean(selpos); cursor->Adjust(); @@ -957,10 +957,10 @@ void MathedCursor::SelStart() { 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; @@ -1000,7 +1000,7 @@ void MathedCursor::SelBalance() } // Once balanced the levels, check that they are at the same paragraph - selpos = anchor->pos; + selpos = anchor->getPos(); } @@ -1018,29 +1018,28 @@ void MathedCursor::SelGetArea(int ** xp, int ** yp, int & np) 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; @@ -1109,7 +1108,7 @@ void MathedCursor::doAccent(byte c, MathedTextCodes t) } if (ac) - cursor->Insert(ac); + cursor->insertInset(ac, LM_TC_INSET); accent = 0; // consumed! } @@ -1127,7 +1126,7 @@ void MathedCursor::doAccent(MathedInset * p) } if (ac) - cursor->Insert(ac); + cursor->insertInset(ac, LM_TC_INSET); accent = 0; // consumed! } @@ -1162,7 +1161,7 @@ MathParInset * MathedCursor::GetPar() MathParInset * MathedCursor::getCurrentPar() const { - return cursor->p; + return cursor->getPar(); } diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index c8d1da8c19..51a9942ef5 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -39,7 +39,7 @@ public: /// void Insert(byte, MathedTextCodes t = LM_TC_MIN); /// - void Insert(MathedInset *, int t = LM_TC_INSET); + void insertInset(MathedInset *, int t); /// void Home(); /// diff --git a/src/mathed/math_iter.C b/src/mathed/math_iter.C index 9ba085e84e..38c2c59f5c 100644 --- a/src/mathed/math_iter.C +++ b/src/mathed/math_iter.C @@ -188,7 +188,7 @@ void MathedIter::goPosAbs(int p) } -void MathedIter::Insert(byte c, MathedTextCodes t) +void MathedIter::insert(byte c, MathedTextCodes t) { if (c < ' ') return; @@ -311,8 +311,16 @@ void MathedIter::join(int pos2) } -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)) @@ -326,6 +334,7 @@ void MathedIter::Insert(MathedInset * p, int type) (*array)[pos - 1] = type; (*array)[array->last()] = '\0'; fcode(-1); +#endif } @@ -462,13 +471,13 @@ void MathedIter::checkTabs() } 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(); } diff --git a/src/mathed/math_iter.h b/src/mathed/math_iter.h index 17ddc56d8c..a16de18776 100644 --- a/src/mathed/math_iter.h +++ b/src/mathed/math_iter.h @@ -83,13 +83,13 @@ public: /// 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 @@ -157,10 +157,4 @@ protected: /// Recover previous state virtual void ipop(); }; - -/// -//#define MX_WAS_SUB 1 -/// -//#define MX_WAS_SUPER 2 - #endif diff --git a/src/mathed/math_macrotable.C b/src/mathed/math_macrotable.C index d8216b9e73..d8f381dbf9 100644 --- a/src/mathed/math_macrotable.C +++ b/src/mathed/math_macrotable.C @@ -62,7 +62,8 @@ void MathMacroTable::builtinMacros() 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 @@ -70,14 +71,15 @@ void MathMacroTable::builtinMacros() 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 @@ -87,18 +89,18 @@ void MathMacroTable::builtinMacros() 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); /* diff --git a/src/mathed/math_matrixinset.C b/src/mathed/math_matrixinset.C index b641bdfe68..8a58205f24 100644 --- a/src/mathed/math_matrixinset.C +++ b/src/mathed/math_matrixinset.C @@ -21,7 +21,7 @@ MathMatrixInset::MathMatrixInset(int m, int n, short st) 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); @@ -105,7 +105,7 @@ void MathMatrixInset::setData(MathedArray * a) } if (it.IsCR()) { while (nn > 0) { - it.Insert(' ', LM_TC_TAB); + it.insert(' ', LM_TC_TAB); --nn; } nn = nc_ - 1; diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index d5de9bef84..3a2e90d733 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -441,15 +441,15 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0, 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; } @@ -474,15 +474,15 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0, } 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: @@ -500,7 +500,7 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0, if (flags & FLAG_BRACE) flags &= ~FLAG_BRACE; else { - data.Insert ('{', LM_TC_TEX); + data.insert('{', LM_TC_TEX); } break; } @@ -526,7 +526,7 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0, --plevel; return array; } else { - data.Insert ('}', LM_TC_TEX); + data.insert('}', LM_TC_TEX); } break; } @@ -543,7 +543,7 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0, } // if (arg) strcpy(arg, yytext); } else - data.Insert ('['); + data.insert('[', LM_TC_CONST); break; } case ']': @@ -552,7 +552,7 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0, --plevel; return array; } else - data.Insert (']'); + data.insert(']', LM_TC_CONST); break; } @@ -562,7 +562,7 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0, 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 '_': @@ -570,7 +570,7 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0, 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; } @@ -587,7 +587,7 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0, { if ((flags & FLAG_END) && mt && data.getCol()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] @@ -603,7 +603,7 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0, 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"); } @@ -612,7 +612,7 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0, 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: @@ -620,24 +620,28 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0, 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: @@ -651,14 +655,14 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0, { 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: @@ -669,7 +673,7 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0, 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: @@ -688,7 +692,7 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0, 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; } @@ -705,7 +709,7 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0, 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; } @@ -733,7 +737,7 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0, 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; } @@ -751,16 +755,19 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0, 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: @@ -770,18 +777,18 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0, 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; @@ -814,7 +821,7 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0, 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) { @@ -864,7 +871,7 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 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(&p)); // for (int i = 0; p->setArgumentIdx(i); ++i) @@ -882,9 +889,9 @@ MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0, if (p) { if (accent) { - data.Insert(doAccent(p)); + data.insertInset(doAccent(p), LM_TC_INSET); } else - data.Insert(p, static_cast(p)->getTCode()); + data.insertInset(p, static_cast(p)->getTCode()); } break; } diff --git a/src/mathed/math_xiter.C b/src/mathed/math_xiter.C index 046a472f43..bcd012efc0 100644 --- a/src/mathed/math_xiter.C +++ b/src/mathed/math_xiter.C @@ -9,31 +9,45 @@ 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_; } @@ -57,27 +71,26 @@ int MathedXIter::GetY() const 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) { @@ -106,10 +119,10 @@ void MathedXIter::Clean(int pos2) 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; } } @@ -154,15 +167,15 @@ void MathedXIter::Merge(MathedArray * a0) // 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; @@ -179,52 +192,35 @@ void MathedXIter::Merge(MathedArray * a0) } - - -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; } @@ -239,27 +235,27 @@ bool MathedXIter::Next() 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 @@ -269,13 +265,13 @@ bool MathedXIter::Next() // 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; @@ -285,13 +281,13 @@ bool MathedXIter::Next() 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(); } } } @@ -342,12 +338,12 @@ void MathedXIter::goNextColumn() 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(); } @@ -360,7 +356,7 @@ bool MathedXIter::Up() bool MathedXIter::Down() { - int xp = x; + int xp = x_; int colp= col; // int rowp = row @@ -368,11 +364,11 @@ bool MathedXIter::Down() 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; } @@ -380,10 +376,9 @@ bool MathedXIter::Down() } - void MathedXIter::addRow() { - if (!crow) { + if (!crow_) { lyxerr[Debug::MATHED] << "MathErr: Attempt to insert new" " line in a subparagraph. " << this << endl; @@ -391,18 +386,18 @@ void MathedXIter::addRow() } // 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()) @@ -410,14 +405,14 @@ void MathedXIter::addRow() // 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; } @@ -436,9 +431,9 @@ void MathedXIter::delRow() 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); @@ -453,21 +448,21 @@ void MathedXIter::delRow() 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(); } } @@ -478,11 +473,12 @@ void MathedXIter::fitCoord(int /*xx*/, int yy) 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(); @@ -494,8 +490,8 @@ void MathedXIter::fitCoord(int /*xx*/, int yy) 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; } @@ -503,13 +499,13 @@ void MathedXIter::setTab(int tx, int tab) 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); } @@ -526,11 +522,11 @@ void MathedXIter::IMetrics(int pos2, int & width, int & ascent, int & descent) 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; @@ -538,19 +534,19 @@ void MathedXIter::IMetrics(int pos2, int & width, int & ascent, int & descent) 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(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(pp)->GetXY(xx, des); if (des - pp->Height() < yy && !asc) asc = yy - (des - pp->Height()); @@ -575,14 +571,14 @@ void MathedXIter::IMetrics(int pos2, int & width, int & ascent, int & descent) } 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; } @@ -592,8 +588,8 @@ bool MathedXIter::setNumbered(bool numb) bool MathedXIter::setLabel(string const & label) { - if (crow) { - crow->setLabel(label); + if (crow_) { + crow_->setLabel(label); return true; } @@ -604,20 +600,20 @@ bool MathedXIter::setLabel(string const & label) 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(); } @@ -625,10 +621,9 @@ MathedRowSt * MathedXIter::adjustVerticalSt() } -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$"; diff --git a/src/mathed/math_xiter.h b/src/mathed/math_xiter.h index 309c1596cd..6a15654e3d 100644 --- a/src/mathed/math_xiter.h +++ b/src/mathed/math_xiter.h @@ -22,7 +22,7 @@ public: /// MathParInset * getPar() const; /// - bool Next(); + virtual bool Next(); /// bool Prev(); /// @@ -76,34 +76,38 @@ public: 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