Cleanup of math_accentinset.[Ch] which somehow went unnoticed so far... 280 - x lines gone, 75 - x new, x changed. Moderate simpliciations in teh parser and the dispatcher in formulabase. Andre' -- André Pönitz ............................................. [EMAIL PROTECTED]
? todo ? formula.h.1 ? math_sqrtinset.h.ok ? .math_accentinset.C.swp ? extern.diff ? test.log ? test.aux ? formula.C.1 ? math_root.h.ok ? math_fracinset.h.my ? math_fracinset.C.my ? math_root.C.ok ? math_sqrtinset.C.ok Index: formulabase.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/formulabase.C,v retrieving revision 1.14 diff -u -p -r1.14 formulabase.C --- formulabase.C 2001/07/09 16:59:56 1.14 +++ formulabase.C 2001/07/10 11:29:24 @@ -92,6 +92,13 @@ bool openNewInset(BufferView * bv, Updat return true; } +void setAccent(int code) +{ + lyxerr << "handling accent " << code << "\n"; + if (mathcursor->Selection()) + ; +} + } // namespaces @@ -621,16 +628,16 @@ InsetFormulaBase::localDispatch(BufferVi // --- accented characters ------------------------------ - case LFUN_UMLAUT: mathcursor->setAccent(LM_ddot); break; - case LFUN_CIRCUMFLEX: mathcursor->setAccent(LM_hat); break; - case LFUN_GRAVE: mathcursor->setAccent(LM_grave); break; - case LFUN_ACUTE: mathcursor->setAccent(LM_acute); break; - case LFUN_TILDE: mathcursor->setAccent(LM_tilde); break; - case LFUN_MACRON: mathcursor->setAccent(LM_bar); break; - case LFUN_DOT: mathcursor->setAccent(LM_dot); break; - case LFUN_CARON: mathcursor->setAccent(LM_check); break; - case LFUN_BREVE: mathcursor->setAccent(LM_breve); break; - case LFUN_VECTOR: mathcursor->setAccent(LM_vec); break; + case LFUN_UMLAUT: setAccent(LM_ddot); break; + case LFUN_CIRCUMFLEX: setAccent(LM_hat); break; + case LFUN_GRAVE: setAccent(LM_grave); break; + case LFUN_ACUTE: setAccent(LM_acute); break; + case LFUN_TILDE: setAccent(LM_tilde); break; + case LFUN_MACRON: setAccent(LM_bar); break; + case LFUN_DOT: setAccent(LM_dot); break; + case LFUN_CARON: setAccent(LM_check); break; + case LFUN_BREVE: setAccent(LM_breve); break; + case LFUN_VECTOR: setAccent(LM_vec); break; // Greek mode case LFUN_GREEK: @@ -848,10 +855,13 @@ InsetFormulaBase::localDispatch(BufferVi lyxerr << "trans: '" << c << "' int: " << int(c) << endl; bv->lockedInsetStoreUndo(Undo::INSERT); - if (c == ' ' && mathcursor->getAccent() == LM_hat) { - c = '^'; - mathcursor->setAccent(0); - } +#ifdef WITH_WARNINGS +#warning problems with accents? look here! +#endif + //if (c == ' ' && mathcursor->getAccent() == LM_hat) { + // c = '^'; + // hcursor->setAccent(0); + //} if (c == 0) { // Dead key, do nothing //lyxerr << "deadkey" << endl; Index: math_accentinset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_accentinset.C,v retrieving revision 1.11 diff -u -p -r1.11 math_accentinset.C --- math_accentinset.C 2001/07/09 10:19:49 1.11 +++ math_accentinset.C 2001/07/10 11:29:24 @@ -7,60 +7,24 @@ using std::ostream; -MathAccentInset::MathAccentInset(byte cx, MathTextCodes f, int cd) - : MathInset(1), c(cx), fn(f), code(cd), inset(0) +MathAccentInset::MathAccentInset(int f) + : MathInset(1), code(f) {} -MathAccentInset::MathAccentInset(MathInset * ins, int cd) - : MathInset(0), c(0), fn(LM_TC_MIN), code(cd), inset(ins) -{} - - -MathAccentInset::~MathAccentInset() -{ - delete inset; -} - - MathInset * MathAccentInset::clone() const { - MathAccentInset * p; - - if (inset) - p = new MathAccentInset(inset->clone(), code); - else - p = new MathAccentInset(c, fn, code); - - return p; + return new MathAccentInset(*this); } - -void MathAccentInset::draw(Painter & pain, int x, int y) -{ - int const dw = width() - 2; - - if (inset) - inset->draw(pain, x, y); - else - drawChar(pain, fn, size(), x, y, c); - x += (code == LM_not) ? (width() - dw) / 2 : 2; - mathed_draw_deco(pain, x, y - dy, dw, dh, code); -} - - void MathAccentInset::Metrics(MathStyles st) { - if (inset) { - inset->Metrics(st); - ascent_ = inset->ascent(); - descent_ = inset->descent(); - width_ = inset->width(); - dh = ascent_; - } else { - mathed_char_dim(fn, size(), c, ascent_, descent_, width_); - dh = width() / 2 - 1; - } + xcell(0).Metrics(st); + ascent_ = xcell(0).ascent(); + descent_ = xcell(0).descent(); + width_ = xcell(0).width(); + dh = 5; + if (code == LM_not) { ascent_ += dh; descent_ += dh; @@ -69,37 +33,29 @@ void MathAccentInset::Metrics(MathStyles ascent_ += dh + 2; dy = ascent_; -// if (MathIsBinary(fn)) -// width += 2*mathed_char_width(fn, size, ' '); } +void MathAccentInset::draw(Painter & pain, int x, int y) +{ + int const dw = width() - 2; + xcell(0).draw(pain, x, y); + x += (code == LM_not) ? (width() - dw) / 2 : 2; + mathed_draw_deco(pain, x, y - dy, dw, dh, code); +} + void MathAccentInset::Write(ostream & os, bool fragile) const { latexkeys const * l = lm_get_key_by_id(code, LM_TK_ACCENT); os << '\\' << l->name; - if (code!= LM_not) - os << '{'; - else + if (code == LM_not) os << ' '; + else + os << '{'; - if (inset) - inset->Write(os, fragile); - else { - if (fn>= LM_TC_RM && fn <= LM_TC_TEXTRM) - os << '\\' << math_font_name[fn - LM_TC_RM] << '{'; - if (MathIsSymbol(fn)) { - latexkeys const * l = lm_get_key_by_id(c, LM_TK_SYM); - if (l) - os << '\\' << l->name << ' '; - } else - os << char(c); - - if (fn>= LM_TC_RM && fn<= LM_TC_TEXTRM) - os << '}'; - } + cell(0).Write(os, fragile); - if (code!= LM_not) + if (code != LM_not) os << '}'; } @@ -109,23 +65,7 @@ void MathAccentInset::WriteNormal(ostrea latexkeys const * l = lm_get_key_by_id(code, LM_TK_ACCENT); os << "[accent " << l->name << " "; - if (inset) - inset->WriteNormal(os); - else { - if (fn >= LM_TC_RM && fn <= LM_TC_TEXTRM) - os << "[font " << math_font_name[fn - LM_TC_RM] << "]"; - if (MathIsSymbol(fn)) { - latexkeys const * l = lm_get_key_by_id(c, LM_TK_SYM); - if (l) - os << "[symbol " << l->name << "] "; - } else - os << "[char " << char(c) << "] "; - } + cell(0).WriteNormal(os); os << "] "; -} - -int MathAccentInset::getAccentCode() const -{ - return code; } Index: math_accentinset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_accentinset.h,v retrieving revision 1.7 diff -u -p -r1.7 math_accentinset.h --- math_accentinset.h 2001/07/09 10:19:49 1.7 +++ math_accentinset.h 2001/07/10 11:29:24 @@ -10,14 +10,10 @@ class MathAccentInset : public MathInset { public: /// - MathAccentInset(byte, MathTextCodes, int); + explicit MathAccentInset(int); /// - MathAccentInset(MathInset *, int); + MathInset * clone() const; /// - ~MathAccentInset(); - /// - MathInset * clone() const; - /// void draw(Painter &, int, int); /// void Write(std::ostream &, bool fragile) const; @@ -29,17 +25,13 @@ public: int getAccentCode() const; /// bool isAccentInset() const { return true; } -protected: - /// - byte c; - /// - MathTextCodes fn; +private: /// int code; /// - MathInset * inset; + int dh; /// - int dh, dy; + int dy; }; #endif Index: math_cursor.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_cursor.C,v retrieving revision 1.56 diff -u -p -r1.56 math_cursor.C --- math_cursor.C 2001/07/09 16:59:56 1.56 +++ math_cursor.C 2001/07/10 11:29:25 @@ -79,7 +79,6 @@ bool IsMacro(short tok, int id) MathCursor::MathCursor(InsetFormulaBase * formula) : formula_(formula) { - accent = 0; lastcode = LM_TC_MIN; macro_mode = false; first(); @@ -366,12 +365,8 @@ void MathCursor::insert(char c, MathText } } - if (accent) - doAccent(c, t); - else { - array().insert(cursor_, c, t); - array().next(cursor_); - } + array().insert(cursor_, c, t); + array().next(cursor_); lastcode = t; return; @@ -389,12 +384,8 @@ void MathCursor::insert(MathInset * p) SelDel(); } - if (accent && !p->nargs()) - doAccent(p); - else { - array().insert(cursor_, p); - array().next(cursor_); - } + array().insert(cursor_, p); + array().next(cursor_); //if (p->nargs()) // push(p, true); @@ -670,7 +661,7 @@ in_word_set(s) << " \n"; break; case LM_TK_ACCENT: - setAccent(l->id); + p = new MathAccentInset(l->id); break; case LM_TK_MACRO: @@ -727,9 +718,6 @@ void MathCursor::MacroModeClose() imacro->SetName(l->name); } else { Left(); - if (nextInset()->isAccentInset()) - setAccent( - static_cast<MathAccentInset*>(nextInset())->getAccentCode()); array().erase(cursor_); if (l || MathMacroTable::hasTemplate(imacro->name())) Interpret(imacro->name()); @@ -889,57 +877,6 @@ void MathCursor::SelGetArea(int * xpoint //lyxerr << "MT[" << a << " " << d << " " << a1 << " " << d1 << "]\n"; //for (i = 0; i < np; ++i) // lyxerr << "XY[" << xpoint[i] << " " << ypoint[i] << "]\n"; -} - - -void MathCursor::setAccent(int ac) -{ - if (ac > 0 && accent < 8) - nestaccent[accent++] = ac; - else - accent = 0; // consumed! -} - - -int MathCursor::getAccent() const -{ - return accent > 0 ? nestaccent[accent - 1] : 0; -} - - -void MathCursor::doAccent(char c, MathTextCodes t) -{ - MathInset * ac = 0; - - for (int i = accent - 1; i >= 0; --i) { - if (i == accent - 1) - ac = new MathAccentInset(c, t, nestaccent[i]); - else - ac = new MathAccentInset(ac, nestaccent[i]); - } - - if (ac) - insert(ac); - - accent = 0; // consumed! -} - - -void MathCursor::doAccent(MathInset * p) -{ - MathInset * ac = 0; - - for (int i = accent - 1; i >= 0; --i) { - if (i == accent - 1) - ac = new MathAccentInset(p, nestaccent[i]); - else - ac = new MathAccentInset(ac, nestaccent[i]); - } - - if (ac) - insert(ac); - - accent = 0; // consumed! } Index: math_cursor.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_cursor.h,v retrieving revision 1.24 diff -u -p -r1.24 math_cursor.h --- math_cursor.h 2001/07/09 16:59:56 1.24 +++ math_cursor.h 2001/07/10 11:29:25 @@ -80,10 +80,6 @@ public: void SetSize(MathStyles); /// bool toggleLimits(); - /// Set accent: if argument = 0 it's considered consumed - void setAccent(int ac = 0); - /// Returns last accent - int getAccent() const; /// // Macro mode methods void MacroModeOpen(); @@ -165,14 +161,6 @@ public: MathInset * par_; /// InsetFormulaBase * const formula_; - /// - void doAccent(char c, MathTextCodes t); - /// - void doAccent(MathInset * p); - /// - int accent; - /// - int nestaccent[8]; /// MathTextCodes lastcode; Index: math_macrotable.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_macrotable.C,v retrieving revision 1.18 diff -u -p -r1.18 math_macrotable.C --- math_macrotable.C 2001/07/09 10:19:50 1.18 +++ math_macrotable.C 2001/07/10 11:29:25 @@ -94,7 +94,9 @@ void MathMacroTable::builtinMacros() // This macro doesn't have arguments { MathMacroTemplate * t = new MathMacroTemplate("notin", 0); - t->push_back(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not)); + MathAccentInset * p = new MathAccentInset(LM_not); + p->cell(0).push_back(LM_in, LM_TC_BOPS); + t->push_back(p); insertTemplate(t); } @@ -111,7 +113,9 @@ void MathMacroTable::builtinMacros() { MathMacroTemplate * t = new MathMacroTemplate("emptyset", 0); - t->push_back(new MathAccentInset('0', LM_TC_RM, LM_not)); + MathAccentInset * p = new MathAccentInset(LM_not); + p->cell(0).push_back('0', LM_TC_VAR); + t->push_back(p); insertTemplate(t); } Index: math_parser.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_parser.C,v retrieving revision 1.61 diff -u -p -r1.61 math_parser.C --- math_parser.C 2001/07/09 10:19:50 1.61 +++ math_parser.C 2001/07/10 11:29:25 @@ -330,65 +330,14 @@ int yylex() } -// Accent hacks only for 0.12. Stolen from Cursor. -int accent = 0; -int nestaccent[8]; - -void setAccent(int ac) -{ - if (ac > 0 && accent < 8) - nestaccent[accent++] = ac; - else - accent = 0; // consumed! -} - - -MathInset * doAccent(unsigned char c, MathTextCodes t) -{ - MathInset * ac = 0; - - for (int i = accent - 1; i >= 0; --i) { - if (i == accent - 1) - ac = new MathAccentInset(c, t, nestaccent[i]); - else - ac = new MathAccentInset(ac, nestaccent[i]); - } - accent = 0; // consumed! - - return ac; -} - - -MathInset * doAccent(MathInset * p) -{ - MathInset * ac = 0; - - for (int i = accent - 1; i >= 0; --i) { - if (i == accent - 1) - ac = new MathAccentInset(p, nestaccent[i]); - else - ac = new MathAccentInset(ac, nestaccent[i]); - } - accent = 0; // consumed! - - return ac; -} - - void do_insert(MathArray & dat, MathInset * m) { - if (accent) - dat.push_back(doAccent(m)); - else - dat.push_back(m); + dat.push_back(m); } void do_insert(MathArray & dat, unsigned char ch, MathTextCodes fcode) { - if (accent) - dat.push_back(doAccent(ch, fcode)); - else - dat.push_back(ch, fcode); + dat.push_back(ch, fcode); } @@ -548,8 +497,6 @@ void mathed_parse(MathArray & array, uns yyvarcode = LM_TC_VAR; int brace = 0; - int acc_brace = 0; - int acc_braces[8]; ++plevel; while (t) { @@ -586,10 +533,6 @@ void mathed_parse(MathArray & array, uns case LM_TK_OPEN: ++brace; - if (accent && tprev == LM_TK_ACCENT) { - acc_braces[acc_brace++] = brace; - break; - } if (flags & FLAG_BRACE_OPT) { flags &= ~FLAG_BRACE_OPT; flags |= FLAG_BRACE; @@ -608,10 +551,6 @@ void mathed_parse(MathArray & array, uns panic = true; break; } - if (acc_brace && brace == acc_braces[acc_brace - 1] - 1) { - --acc_brace; - break; - } if (flags & FLAG_BRACE_FONT) { yyvarcode = LM_TC_VAR; flags &= ~FLAG_BRACE_FONT; @@ -801,15 +740,19 @@ void mathed_parse(MathArray & array, uns case LM_TK_WIDE: { - MathDecorationInset * sq = new MathDecorationInset(yylval.l->id); - mathed_parse(sq->cell(0), FLAG_BRACE | FLAG_BRACE_LAST); - array.push_back(sq); + MathDecorationInset * p = new +MathDecorationInset(yylval.l->id); + mathed_parse(p->cell(0), FLAG_BRACE | FLAG_BRACE_LAST); + array.push_back(p); break; } case LM_TK_ACCENT: - setAccent(yylval.l->id); + { + MathAccentInset * p = new MathAccentInset(yylval.l->id); + mathed_parse(p->cell(0), FLAG_BRACE | FLAG_BRACE_LAST); + array.push_back(p); break; + } case LM_TK_NONUM: curr_num = false; @@ -817,9 +760,9 @@ void mathed_parse(MathArray & array, uns case LM_TK_PMOD: case LM_TK_FUNC: - if (accent) - array.push_back(t, LM_TC_CONST); - else + //if (accent) + // array.push_back(t, LM_TC_CONST); + //else array.push_back(new MathFuncInset(yylval.l->name)); break;