X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2Fformulabase.C;h=18e1c97ba2a17f4b24e8e18d7bab9366309457b4;hb=30705f0927e5e2a3542ff328847014c43a11e32f;hp=c81c2ae7b0f76bbe4db73b0638cd33fe7f598d8c;hpb=2e4ad730241fb288dbc3020cdc4bb6d830fc51d4;p=lyx.git diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index c81c2ae7b0..18e1c97ba2 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -33,7 +33,7 @@ #include "gettext.h" #include "LaTeXFeatures.h" #include "debug.h" -#include "support/LOstream.h" +#include "support/lstrings.h" #include "LyXView.h" #include "Painter.h" #include "font.h" @@ -50,7 +50,6 @@ using std::vector; extern char const * latex_special_chars; -int greek_kb_flag = 0; extern char const * latex_mathenv[]; MathCursor * mathcursor = 0; @@ -104,44 +103,25 @@ bool openNewInset(BufferView * bv, UpdatableInset * new_inset) } -} // namespaces - - - -namespace { - - -// returns the nearest enclosing matrix +// returns the nearest enclosing grid MathArrayInset * matrixpar(int & idx) { idx = 0; - return - static_cast - (mathcursor ? mathcursor->enclosing(LM_OT_MATRIX, idx) : 0); + return (mathcursor ? mathcursor->enclosingArray(idx) : 0); } } // namespace anon -InsetFormulaBase::InsetFormulaBase(MathInset * par) - : par_(par) + +InsetFormulaBase::InsetFormulaBase() { #ifdef WITH_WARNINGS #warning This is needed as long the math parser is not re-entrant #endif MathMacroTable::builtinMacros(); -} - - -InsetFormulaBase::InsetFormulaBase(InsetFormulaBase const & f) - : UpdatableInset(f), par_(static_cast(f.par_->clone())) -{} - - -InsetFormulaBase::~InsetFormulaBase() -{ - delete par_; + //lyxerr << "sizeof MathInset: " << sizeof(MathInset) << "\n"; } @@ -150,6 +130,7 @@ void InsetFormulaBase::read(Buffer const *, LyXLex & lex) read(lex); } + void InsetFormulaBase::write(Buffer const *, ostream & os) const { write(os); @@ -210,7 +191,6 @@ void InsetFormulaBase::edit(BufferView * bv, int x, int /*y*/, unsigned int) void InsetFormulaBase::edit(BufferView * bv, bool front) { -#warning Please have a look if this is right (Jug) edit(bv, front ? 0 : 1, 0, 0); } @@ -232,8 +212,8 @@ void InsetFormulaBase::insetUnlock(BufferView * bv) void InsetFormulaBase::getCursorPos(BufferView *, int & x, int & y) const { mathcursor->getPos(x, y); - x -= par_->xo(); - y -= par_->yo(); + x -= par()->xo(); + y -= par()->yo(); } @@ -248,8 +228,8 @@ void InsetFormulaBase::toggleInsetCursor(BufferView * bv) int x; int y; mathcursor->getPos(x, y); - //x -= par_->xo(); - y -= par_->yo(); + //x -= par()->xo(); + y -= par()->yo(); int asc; int desc; math_font_max_dim(LM_TC_TEXTRM, LM_ST_TEXT, asc, desc); @@ -267,8 +247,8 @@ void InsetFormulaBase::showInsetCursor(BufferView * bv, bool) int x; int y; mathcursor->getPos(x, y); - x -= par_->xo(); - y -= par_->yo(); + x -= par()->xo(); + y -= par()->yo(); int asc; int desc; math_font_max_dim(LM_TC_TEXTRM, LM_ST_TEXT, asc, desc); @@ -306,19 +286,13 @@ void InsetFormulaBase::updateLocal(BufferView * bv, bool dirty) } -void InsetFormulaBase::metrics() const -{ - const_cast(par_)->metrics(LM_ST_TEXT); -} - - void InsetFormulaBase::insetButtonRelease(BufferView * bv, int x, int y, int /*button*/) { if (mathcursor) { hideInsetCursor(bv); - x += par_->xo(); - y += par_->yo(); + x += par()->xo(); + y += par()->yo(); mathcursor->setPos(x, y); showInsetCursor(bv); if (sel_flag) { @@ -350,14 +324,14 @@ void InsetFormulaBase::insetMotionNotify(BufferView * bv, if (sel_x && sel_y && abs(x-sel_x) > 4 && !sel_flag) { sel_flag = true; hideInsetCursor(bv); - mathcursor->setPos(sel_x + par_->xo(), sel_y + par_->yo()); + mathcursor->setPos(sel_x + par()->xo(), sel_y + par()->yo()); mathcursor->selStart(); showInsetCursor(bv); mathcursor->getPos(sel_x, sel_y); } else if (sel_flag) { hideInsetCursor(bv); - x += par_->xo(); - y += par_->yo(); + x += par()->xo(); + y += par()->yo(); mathcursor->setPos(x, y); showInsetCursor(bv); mathcursor->getPos(x, y); @@ -383,6 +357,8 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action, //lyxerr << "InsetFormulaBase::LocalDispatch: act: " << action // << " arg: '" << arg << "' cursor: " << mathcursor << "\n"; + static int greek_kb_flag = 0; + if (!mathcursor) return UNDISPATCHED; @@ -471,25 +447,14 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action, break; case LFUN_BACKSPACE: - // if (!mathcursor->inMacroMode() && mathcursor->pos() == 0) - if (mathcursor->pos() == 0) { - bv->lockedInsetStoreUndo(Undo::DELETE); - mathcursor->pullArg(false); - bv->updateInset(this, true); - break; - } - if (mathcursor->inMacroMode()) - mathcursor->left(); - else - mathcursor->plainLeft(); - // fall through... + bv->lockedInsetStoreUndo(Undo::DELETE); + mathcursor->backspace(); + bv->updateInset(this, true); + break; case LFUN_DELETE: bv->lockedInsetStoreUndo(Undo::DELETE); - if (mathcursor->pos() == mathcursor->array().size()) - mathcursor->pullArg(true); - else - mathcursor->erase(); + mathcursor->erase(); bv->updateInset(this, true); break; @@ -506,7 +471,7 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action, int y1; istringstream is(arg.c_str()); is >> x >> y; - par_->getXY(x1, y1); + par()->getXY(x1, y1); mathcursor->setPos(x1 + x, y1 + y); updateLocal(bv, false); } @@ -581,15 +546,6 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action, //bv->owner()->message(_("math text mode toggled")); break; -#ifndef NO_LATEX - case LFUN_TEX: - if (!mathcursor->selection()) { - mathcursor->handleFont(LM_TC_TEX); - //bv->owner()->message(_("TeX mode toggled")); - } - break; -#endif - case LFUN_MATH_LIMITS: bv->lockedInsetStoreUndo(Undo::INSERT); if (mathcursor->toggleLimits()) @@ -807,7 +763,7 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action, char greek[26] = {'A', 'B', 'X', 0 , 'E', 0 , 0 , 'H', 'I', 0 , 'K', 0 , 'M', 'N', 'O', 0 , 0 , 'P', 0 , 'T', - 'Y', 0, 0, 0, 0 , 'Z' }; + 0, 0, 0, 0, 0 , 'Z' }; if ('A' <= c && c <= 'Z' && greek[c - 'A']) { char_code = LM_TC_RM; @@ -818,7 +774,7 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action, mathcursor->insert(c, char_code); - if (greek_kb_flag && char_code == LM_TC_RM ) + if (greek_kb_flag && char_code == LM_TC_RM) mathcursor->setLastCode(LM_TC_VAR); varcode = LM_TC_MIN; @@ -917,68 +873,12 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action, } - -/* FIXME: math-greek-toggle seems to work OK, but math-greek doesn't turn - * on greek mode */ -bool math_insert_greek(BufferView * bv, char c) -{ - if (!bv->available()) - return false; - - if (!isalpha(c)) - return false; - - string tmp; - tmp = c; - if (!bv->theLockingInset() || bv->theLockingInset()->isTextInset()) { - int greek_kb_flag_save = greek_kb_flag; - InsetFormula * new_inset = new InsetFormula(); - bv->beforeChange(bv->text); - if (!bv->insertInset(new_inset)) { - delete new_inset; - return false; - } - //Update(1);//BUG - new_inset->edit(bv, 0, 0, 0); - new_inset->localDispatch(bv, LFUN_SELFINSERT, tmp); - if (greek_kb_flag_save < 2) { - bv->unlockInset(new_inset); // bv->theLockingInset()); - bv->text->cursorRight(bv, true); - } - } else - if (bv->theLockingInset()->lyxCode() == Inset::MATH_CODE || - bv->theLockingInset()->lyxCode() == Inset::MATHMACRO_CODE) - static_cast(bv->theLockingInset())->localDispatch(bv, LFUN_SELFINSERT, tmp); - else - lyxerr << "Math error: attempt to write on a wrong " - "class of inset." << endl; - return true; -} - - - Inset::Code InsetFormulaBase::lyxCode() const { return Inset::MATH_CODE; } -LyXFont const InsetFormulaBase::convertFont(LyXFont const & f) const -{ - // We have already discussed what was here - LyXFont font(f); -#ifndef NO_LATEX - font.setLatex(LyXFont::OFF); -#endif - return font; -} - -MathInset * InsetFormulaBase::par() const -{ - return par_; -} - - void mathDispatchCreation(BufferView * bv, string const & arg, bool display) { if (bv->available()) {