]> git.lyx.org Git - features.git/commitdiff
remove the imacro_ hack from MathCursor
authorAndré Pönitz <poenitz@gmx.net>
Tue, 14 Aug 2001 11:19:19 +0000 (11:19 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Tue, 14 Aug 2001 11:19:19 +0000 (11:19 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2512 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/math_charinset.h
src/mathed/math_cursor.C
src/mathed/math_cursor.h
src/mathed/math_funcinset.C
src/mathed/math_inset.h

index c43eac27636519b5c1a4307113136c9c864ddd45..0760c2166fe43d7525a722f3b4f41fc5461c2215 100644 (file)
@@ -37,6 +37,8 @@ public:
        ///
        char getChar() const { return char_; }
        ///
+       MathTextCodes code() const { return code_; }
+       ///
        bool isRelOp() const;
        ///
        void handleFont(MathTextCodes t);
index aa4e86f18e0a12499cfa28857e1219491c9d16e6..ac332723b83ca8f431a5b4709b814fd0cc4eda04 100644 (file)
 #include "formulabase.h"
 #include "math_cursor.h"
 #include "math_factory.h"
+#include "math_funcinset.h"
 #include "math_arrayinset.h"
 #include "math_charinset.h"
 #include "math_decorationinset.h"
 #include "math_deliminset.h"
-#include "math_funcinset.h"
 #include "math_macro.h"
 #include "math_macrotable.h"
 #include "math_matrixinset.h"
@@ -121,16 +121,14 @@ std::ostream & operator<<(std::ostream & os, MathCursorPos const & p)
 
 
 MathCursor::MathCursor(InsetFormulaBase * formula)
-       : formula_(formula), lastcode_(LM_TC_VAR), imacro_(0), selection_(false)
+       : formula_(formula), lastcode_(LM_TC_VAR), selection_(false)
 {
        first();
 }
 
 
 MathCursor::~MathCursor()
-{
-       delete imacro_;
-}
+{}
 
 
 void MathCursor::pushLeft(MathInset * par)
@@ -260,13 +258,8 @@ bool MathCursor::posRight()
 bool MathCursor::left(bool sel)
 {
        dump("Left 1");
-       if (imacro_) {
-               // was MacroModeBack()
-               if (!imacro_->name().empty()) {
-                       imacro_->setName(imacro_->name().substr(0, imacro_->name().length()-1));
-                       imacro_->metrics(imacro_->size());
-               } else
-                       macroModeClose();
+       if (inMacroMode()) {
+               macroModeClose();
                return true;
        }
        selHandle(sel);
@@ -285,7 +278,7 @@ bool MathCursor::left(bool sel)
 bool MathCursor::right(bool sel)
 {
        dump("Right 1");
-       if (imacro_) {
+       if (inMacroMode()) {
                macroModeClose();
                return true;
        }
@@ -393,20 +386,6 @@ void MathCursor::plainErase()
 void MathCursor::insert(char c, MathTextCodes t)
 {
        //lyxerr << "inserting '" << c << "'\n";
-       if (selection_)
-               selDel();
-
-       if (t != LM_TC_VAR)
-               lastcode_ = t;
-
-       if (imacro_ && t != LM_TC_TEX)
-               macroModeClose();
-
-       if (imacro_) {
-               imacro_->setName(imacro_->name() + c);
-               return;
-       }
-
        array().insert(pos(), new MathCharInset(c, t));
        posRight();
 }
@@ -480,7 +459,7 @@ void MathCursor::backspace()
 void MathCursor::erase()
 {
        dump("erase 1");
-       if (imacro_)
+       if (inMacroMode())
                return;
 
        if (selection_) {
@@ -614,28 +593,28 @@ void MathCursor::setSize(MathStyles size)
 }
 
 
-
-void MathCursor::macroModeOpen()
+void MathCursor::macroModeClose()
 {
-       if (!imacro_) {
-               imacro_ = new MathFuncInset("");
-               array().insert(pos(), imacro_);
-               ++pos();
-               //insert(imacro_);
-       } else
-               lyxerr << "Math Warning: Already in macro mode" << endl;
+       string s = macroName();
+       if (s.size()) {
+               pos() = pos() - s.size();
+               for (unsigned i = 0; i < s.size(); ++i)
+                       plainErase();
+               interpret("\\" + s);
+       }
+       lastcode_ = LM_TC_VAR;
 }
 
 
-void MathCursor::macroModeClose()
+string MathCursor::macroName() const
 {
-       if (imacro_) {
-               string name = imacro_->name();
-               posLeft();
-               plainErase();
-               imacro_ = 0;
-               interpret("\\" + name);
+       string s;
+       int p = pos() - 1;
+       while (p >= 0 && array().nextInset(p)->code() == LM_TC_TEX) {
+               s = array().nextInset(p)->getChar() + s;
+               --p;
        }
+       return s;
 }
 
 
@@ -839,7 +818,7 @@ int & MathCursor::pos()
 
 bool MathCursor::inMacroMode() const
 {
-       return imacro_;
+       return lastcode_ == LM_TC_TEX;
 }
 
 
@@ -1302,16 +1281,20 @@ void MathCursor::interpret(string const & s)
                return; 
        }
 
-       if (c == '_' && lastcode_ == LM_TC_TEX) {
-               lastcode_ = LM_TC_VAR;
-               insert(c, LM_TC_SPECIAL);
-               return;
-       }
+       if (selection_)
+               selDel();
 
-       if ('0' <= c && c <= '9' && (lastcode_ == LM_TC_TEX || imacro_)) {
-               macroModeOpen();
-               lastcode_ = LM_TC_VAR;
-               insert(c, lastcode_);
+       if (lastcode_ == LM_TC_TEX) {
+               if (macroName().empty()) {
+                       insert(c, LM_TC_TEX);
+                       if (!isalpha(c))
+                               macroModeClose();
+               } else {
+                       if (isalpha(c))
+                               insert(c, LM_TC_TEX);
+                       else
+                               macroModeClose();
+               }
                return;
        }
 
@@ -1337,7 +1320,7 @@ void MathCursor::interpret(string const & s)
        }
 
        if (c == ' ') {
-               if (imacro_) {
+               if (inMacroMode()) {
                        lastcode_ = LM_TC_VAR;
                        macroModeClose();
                        return;
@@ -1364,18 +1347,12 @@ void MathCursor::interpret(string const & s)
        }
 
        if (c == '\\') {
-               if (imacro_)
-                       macroModeClose();
-               //bv->owner()->message(_("TeX mode"));
                lastcode_ = LM_TC_TEX;
+               //bv->owner()->message(_("TeX mode"));
                return; 
        }
 
        if (isalpha(c)) {
-               if (lastcode_ == LM_TC_TEX) {
-                       macroModeOpen();
-                       lastcode_ = LM_TC_VAR;
-               }
                insert(c, lastcode_);
                return; 
        }
index 389ce3dc201f33e6b348c10e8d6f71689434c6fd..8fa6d16fd4e43234e10a70fa331cdbc85228af0f 100644 (file)
@@ -67,8 +67,6 @@ public:
        ///
        ~MathCursor();
        ///
-       void insert(char, MathTextCodes t = LM_TC_MIN);
-       ///
        void insert(MathInset *);
        ///
        void insert(MathArray const &);
@@ -140,8 +138,6 @@ public:
        bool toggleLimits();
        ///
        // Macro mode methods
-       void macroModeOpen();
-       ///
        void macroModeClose();
        ///
        bool inMacroMode() const;
@@ -253,6 +249,10 @@ public:
        ///
        MathSpaceInset * prevSpaceInset() const;
 private:
+       ///
+       string macroName() const;
+       ///
+       void insert(char, MathTextCodes t = LM_TC_MIN);
        ///
        int & pos();
        ///
@@ -272,8 +272,6 @@ private:
        InsetFormulaBase * const formula_;
        ///
        MathTextCodes lastcode_;
-       ///
-       MathFuncInset * imacro_;
        // Selection stuff
        /// do we currently select
        bool selection_;
index d34245db74a9195d093a09ee2de9579637690cca..9932510580690f8b7c20a19e9c358265c50c3986 100644 (file)
@@ -52,10 +52,7 @@ void MathFuncInset::writeNormal(std::ostream & os) const
 void MathFuncInset::metrics(MathStyles st) const 
 {
        size_ = st;
-       if (name_.empty()) 
-               mathed_char_dim(LM_TC_TEX, size_, 'I', ascent_, descent_, width_);
-       else 
-               mathed_string_dim(LM_TC_TEX, size_, name_, ascent_, descent_, width_);
+       mathed_string_dim(LM_TC_TEX, size_, name_, ascent_, descent_, width_);
 }
 
 
@@ -63,8 +60,5 @@ void MathFuncInset::draw(Painter & pain, int x, int y) const
 { 
        xo(x);
        yo(y);
-       if (name_.empty()) 
-               drawChar(pain, LM_TC_TEX, size_, x, y, ' ');
-       else
-               drawStr(pain, LM_TC_TEX, size_, x, y, name_);
+       drawStr(pain, LM_TC_TEX, size_, x, y, name_);
 }
index 86afc24191f2360e872481596acbcee37330d288..c188fe4a532787166c1cdf1b30501c570d14633a 100644 (file)
@@ -182,11 +182,13 @@ public:
        virtual bool isRelOp() const { return false; }
        ///
        virtual char getChar() const { return 0; }
+       ///
+       virtual MathTextCodes code() const { return LM_TC_MIN; }
 
        ///
        virtual void push_back(MathInset *);
        ///
-       virtual void push_back(unsigned char ch, MathTextCodes fcode);
+       virtual void push_back(unsigned char c, MathTextCodes code);
        ///
        virtual void dump() const;