]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/formulabase.C
fix typo that put too many include paths for most people
[lyx.git] / src / mathed / formulabase.C
index 5eaa8f93ed5352ab11309cfefebce837f7b2a481..5bd77093ddeb9de73603d3a8c3756926f5348f90 100644 (file)
@@ -38,6 +38,7 @@
 #include "font.h"
 #include "Lsstream.h"
 #include "math_arrayinset.h"
+#include "math_charinset.h"
 #include "math_cursor.h"
 #include "math_factory.h"
 #include "math_hullinset.h"
@@ -47,6 +48,7 @@
 #include "math_pos.h"
 #include "math_spaceinset.h"
 #include "undo_funcs.h"
+#include "textpainter.h"
 #include "frontends/Dialogs.h"
 #include "intl.h"
 
@@ -68,7 +70,7 @@ int hack_y;
 int hack_button;
 
 
-void handleFont(BufferView * bv, string const & arg, MathTextCodes t) 
+void handleFont(BufferView * bv, string const & arg, MathTextCodes t)
 {
        if (mathcursor->selection())
                bv->lockedInsetStoreUndo(Undo::EDIT);
@@ -99,6 +101,8 @@ InsetFormulaBase::InsetFormulaBase()
        // This is needed as long the math parser is not re-entrant
        MathMacroTable::builtinMacros();
        //lyxerr << "sizeof MathInset: " << sizeof(MathInset) << "\n";
+       //lyxerr << "sizeof(MathMetricsInfo): " << sizeof(MathMetricsInfo) << "\n";
+       //lyxerr << "sizeof(MathCharInset): " << sizeof(MathCharInset) << "\n";
 }
 
 
@@ -129,14 +133,14 @@ void InsetFormulaBase::validate(LaTeXFeatures &) const
 {}
 
 
-void InsetFormulaBase::metrics(BufferView * bv, LyXFont const & f) const 
+void InsetFormulaBase::metrics(BufferView * bv, LyXFont const & f) const
 {
        font_ = f;
        metrics(bv);
 }
 
 
-void InsetFormulaBase::metrics(BufferView * bv) const 
+void InsetFormulaBase::metrics(BufferView * bv) const
 {
        if (bv)
                view_ = bv;
@@ -218,8 +222,7 @@ void InsetFormulaBase::toggleInsetCursor(BufferView * bv)
                y -= yo_;
                int asc = 0;
                int des = 0;
-               MathMetricsInfo mi(bv, font_, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
-               math_font_max_dim(LM_TC_TEXTRM, mi, asc, des);
+               math_font_max_dim(font_, asc, des);
                bv->showLockedInsetCursor(x, y, asc, des);
                //lyxerr << "toggleInsetCursor: " << x << " " << y << "\n";
        }
@@ -240,8 +243,7 @@ void InsetFormulaBase::showInsetCursor(BufferView * bv, bool)
                y -= yo_;
                int asc = 0;
                int des = 0;
-               MathMetricsInfo mi(bv, font_, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
-               math_font_max_dim(LM_TC_TEXTRM, mi, asc, des);
+               math_font_max_dim(font_, asc, des);
                bv->fitLockedInsetCursor(x, y, asc, des);
                //lyxerr << "showInsetCursor: x: " << x << " y: " << y << " yo: " << yo_ << "\n";
        }
@@ -277,7 +279,7 @@ void InsetFormulaBase::updateLocal(BufferView * bv, bool dirty)
 
 
 bool InsetFormulaBase::insetButtonRelease(BufferView * bv,
-                                          int /*x*/, int /*y*/, int /*button*/)
+                                         int /*x*/, int /*y*/, int /*button*/)
 {
        if (!mathcursor)
                return false;
@@ -326,7 +328,7 @@ void InsetFormulaBase::insetButtonPress(BufferView * bv,
                                        bv->getLyXText()->selectionAsString(bv->buffer(), false);
                                mathed_parse_cell(ar, sel);
                                mathcursor->insert(ar);
-                       }       
+                       }
                        break;
 */
                case 3:
@@ -351,9 +353,9 @@ void InsetFormulaBase::insetMotionNotify(BufferView * bv,
        first_x = x;
        first_y = y;
 
-       if (!mathcursor->selection()) 
+       if (!mathcursor->selection())
                mathcursor->selStart();
-       
+
        //lyxerr << "insetMotionNotify: " << x + xo_ << ' ' << y + yo_
        //      << ' ' << button << "\n";
        hideInsetCursor(bv);
@@ -376,7 +378,7 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
        //lyxerr << "InsetFormulaBase::localDispatch: act: " << action
        //      << " arg: '" << arg << "' cursor: " << mathcursor << "\n";
 
-       if (!mathcursor) 
+       if (!mathcursor)
                return UNDISPATCHED;
 
        if (mathcursor->asHyperActiveInset()) {
@@ -392,6 +394,8 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
        hideInsetCursor(bv);
 
        mathcursor->normalize();
+       mathcursor->touch();
+
        switch (action) {
 
                // --- Cursor Movements ---------------------------------------------
@@ -564,7 +568,7 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
        case LFUN_DEFAULT:      handleFont(bv, arg, LM_TC_VAR); break;
        case LFUN_FREE:         handleFont(bv, arg, LM_TC_TEXTRM); break;
 
-       case LFUN_GREEK: 
+       case LFUN_GREEK:
                handleFont(bv, arg, LM_TC_GREEK1);
                if (arg.size())
                        mathcursor->interpret(arg);
@@ -614,7 +618,7 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
                updateLocal(bv, true);
                break;
        }
-       
+
        case LFUN_SUPERSCRIPT:
        case LFUN_SUBSCRIPT:
        {
@@ -623,7 +627,7 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
                updateLocal(bv, true);
                break;
        }
-       
+
        case LFUN_MATH_DELIM:
        {
                lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'\n";
@@ -663,11 +667,12 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
                MathInset::idx_type idx = 0;
                MathGridInset * p = mathcursor ? mathcursor->enclosingGrid(idx) : 0;
                if (p) {
+                       mathcursor->popToEnclosingGrid();
                        bv->lockedInsetStoreUndo(Undo::EDIT);
-                       char al = arg.size() ? arg[0] : 'c';
+                       char align = arg.size() ? arg[0] : 'c';
                        switch (action) {
-                               case LFUN_MATH_HALIGN: p->halign(al, p->col(idx)); break;
-                               case LFUN_MATH_VALIGN: p->valign(al); break;
+                               case LFUN_MATH_HALIGN: p->halign(align, p->col(idx)); break;
+                               case LFUN_MATH_VALIGN: p->valign(align); break;
                                case LFUN_MATH_ROW_INSERT: p->addRow(p->row(idx)); break;
                                case LFUN_MATH_ROW_DELETE: p->delRow(p->row(idx)); break;
                                case LFUN_MATH_COLUMN_INSERT: p->addCol(p->col(idx)); break;
@@ -721,6 +726,7 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
        }
 
        mathcursor->normalize();
+       mathcursor->touch();
 
        lyx::Assert(mathcursor);
 
@@ -820,7 +826,7 @@ bool InsetFormulaBase::searchForward(BufferView * bv, string const & str,
                //lyxerr << "reset lastformula to " << this << "\n";
                lastformula = this;
                laststr = str;
-               current = ibegin(par().nucleus());
+               current = ibegin(par().nucleus());
                ar.clear();
                mathed_parse_cell(ar, str);
        } else {
@@ -888,7 +894,8 @@ void mathDispatchCreation(BufferView * bv, string const & arg, bool display)
                } else {
                        // create a macro if we see "\\newcommand" somewhere, and an ordinary
                        // formula otherwise
-                       if (sel.find("\\newcommand") == string::npos) 
+                       if (sel.find("\\newcommand") == string::npos &&
+                                 sel.find("\\def") == string::npos)
                                f = new InsetFormula(sel);
                        else {
                                string name;
@@ -909,7 +916,7 @@ void mathDispatchMathDisplay(BufferView * bv, string const & arg)
        mathDispatchCreation(bv, arg, true);
 }
 
-       
+
 void mathDispatchMathMode(BufferView * bv, string const & arg)
 {
        mathDispatchCreation(bv, arg, false);
@@ -928,7 +935,7 @@ void mathDispatchMathMacro(BufferView * bv, string const & arg)
                if (arg.empty())
                        bv->owner()->getLyXFunc()->setErrorMessage(N_("Missing argument"));
                else {
-                       string s(arg);
+                       string s = arg;
                        string const s1 = token(s, ' ', 1);
                        int const na = s1.empty() ? 0 : lyx::atoi(s1);
                        openNewInset(bv, new InsetFormulaMacro(token(s, ' ', 0), na));
@@ -939,20 +946,20 @@ void mathDispatchMathMacro(BufferView * bv, string const & arg)
 
 void mathDispatchMathDelim(BufferView * bv, string const & arg)
 {
-       if (bv->available()) { 
+       if (bv->available()) {
                if (openNewInset(bv, new InsetFormula))
                        bv->theLockingInset()->localDispatch(bv, LFUN_MATH_DELIM, arg);
        }
-}         
+}
 
 
 void mathDispatchInsertMatrix(BufferView * bv, string const & arg)
-{         
-       if (bv->available()) { 
+{
+       if (bv->available()) {
                if (openNewInset(bv, new InsetFormula))
                        bv->theLockingInset()->localDispatch(bv, LFUN_INSERT_MATRIX, arg);
        }
-}         
+}
 
 
 void mathDispatchInsertMath(BufferView * bv, string const & arg)
@@ -969,16 +976,16 @@ void mathDispatchInsertMath(BufferView * bv, string const & arg)
 
 
 void mathDispatchGreek(BufferView * bv, string const & arg)
-{         
-       if (bv->available()) { 
+{
+       if (bv->available()) {
                InsetFormula * f = new InsetFormula;
                if (openNewInset(bv, f)) {
                        bv->theLockingInset()->localDispatch(bv, LFUN_GREEK, arg);
                        bv->unlockInset(f);
                }
        }
-}         
+}
 
 
 void mathDispatch(BufferView *, kb_action, string const &)
-{}        
+{}