]> git.lyx.org Git - features.git/commitdiff
enable insertion of spaces in all \textxxx modes.
authorAndré Pönitz <poenitz@gmx.net>
Thu, 18 Jul 2002 11:02:33 +0000 (11:02 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Thu, 18 Jul 2002 11:02:33 +0000 (11:02 +0000)
some cleanup.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4702 a592a061-630c-0410-9148-cb99ea01b6c8

14 files changed:
src/mathed/formulabase.C
src/mathed/math_boxinset.C
src/mathed/math_boxinset.h
src/mathed/math_cursor.C
src/mathed/math_cursor.h
src/mathed/math_fboxinset.h
src/mathed/math_fontinset.C
src/mathed/math_fontinset.h
src/mathed/math_fontoldinset.h
src/mathed/math_hullinset.C
src/mathed/math_hullinset.h
src/mathed/math_inset.h
src/mathed/math_parboxinset.h
src/mathed/math_parinset.h

index 26beee4ca1089ad198263f8adc3b321bdeb7210d..06cf5a9385e1321684ba001fe76174a0c05efa5e 100644 (file)
@@ -613,7 +613,7 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
                break;
 
        case LFUN_MATH_MODE:
-               if (mathcursor->inMathMode()) {
+               if (mathcursor->currentMode()) {
                        handleFont(bv, arg, "textrm");
                } else {
                        mathcursor->niceInsert(MathAtom(new MathHullInset("simple")));
index 981bf356fb89730212c88a0c0dcf3e40c475931c..218cbec0a521fbd486da26e1f78b0af80661f253 100644 (file)
@@ -36,12 +36,6 @@ void MathBoxInset::normalize(NormalStream & os) const
 }
 
 
-void MathBoxInset::rebreak()
-{
-       //lyxerr << "trying to rebreak...\n";
-}
-
-
 void MathBoxInset::metrics(MathMetricsInfo & mi) const
 {
        MathFontSetChanger dummy(mi.base, "textnormal");
index dca47ceb0646e2c0ee4f47bec60cdd342220ea3c..c027c3954e489114c84ae2b8f754180eb08eda6c 100644 (file)
@@ -20,15 +20,11 @@ public:
        ///
        MathInset * clone() const;
        ///
+       mode_type currentMode() const { return TEXT_MODE; }
+       ///
        void metrics(MathMetricsInfo & mi) const;
        ///
        void draw(MathPainterInfo & pi, int x, int y) const;
-       /// identifies BoxInsets
-       MathBoxInset * asBoxInset() { return this; }
-       /// identifies BoxInsets
-       MathBoxInset const * asBoxInset() const { return this; }
-       ///
-       void rebreak();
        ///
        void write(WriteStream & os) const;
        ///
index ad8ae53d173786d258c5362b72f2d3fbcad0c0fa..ef7d3beb01585ebdc9fa6eaf700a8fd47346a708 100644 (file)
 #include "math_autocorrect.h"
 #include "math_arrayinset.h"
 #include "math_braceinset.h"
-#include "math_boxinset.h"
 #include "math_casesinset.h"
 #include "math_charinset.h"
 #include "math_extern.h"
 #include "math_factory.h"
-#include "math_fboxinset.h"
 #include "math_hullinset.h"
 #include "math_iterator.h"
 #include "math_macroarg.h"
@@ -855,17 +853,6 @@ void MathCursor::touch()
 
 void MathCursor::normalize()
 {
-#if 0
-       // rebreak
-       {
-               MathIterator it = ibegin(formula()->par().nucleus());
-               MathIterator et = iend(formula()->par().nucleus());
-               for (; it != et; ++it)
-                       if (it.par()->asBoxInset())
-                               it.par()->asBoxInset()->rebreak();
-       }
-#endif
-
        if (idx() >= par()->nargs()) {
                lyxerr << "this should not really happen - 1: "
                       << idx() << " " << par()->nargs() << "\n";
@@ -1366,20 +1353,6 @@ bool MathCursor::script(bool up)
 }
 
 
-bool MathCursor::inMathMode() const
-{
-       if (par()->asBoxInset())
-               return false;
-       if (par()->asFboxInset())
-               return false;
-       if (par()->asParboxInset())
-               return false;
-       if (par()->asParInset())
-               return false;
-       return true;
-}
-
-
 bool MathCursor::interpret(char c)
 {
        //lyxerr << "interpret 2: '" << c << "'\n";
@@ -1451,16 +1424,6 @@ bool MathCursor::interpret(char c)
 
        selClearOrDel();
 
-       if (!inMathMode()) {
-               // suppress direct insertion of two spaces in a row
-               // the still allows typing  '<space>a<space>' and deleting the 'a', but
-               // it is better than nothing...
-               if (c == ' ' && hasPrevAtom() && prevAtom()->getChar() == ' ')
-                       return true;
-               insert(c);
-               return true;
-       }
-
        if (c == '\\') {
                //lyxerr << "starting with macro\n";
                insert(MathAtom(new MathUnknownInset("\\", false)));
@@ -1468,6 +1431,15 @@ bool MathCursor::interpret(char c)
        }
 
        if (c == ' ') {
+               if (currentMode() == MathInset::TEXT_MODE) {
+                       // insert spaces in text mode,
+                       // but suppress direct insertion of two spaces in a row
+                       // the still allows typing  '<space>a<space>' and deleting the 'a', but
+                       // it is better than nothing...
+                       if (!hasPrevAtom() || prevAtom()->getChar() != ' ')
+                               insert(c);
+                       return true;
+               }
                if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
                        prevAtom()->asSpaceInset()->incSpace();
                        return true;
@@ -1771,3 +1743,14 @@ int MathCursor::dispatch(string const & cmd)
        }
        return 0;
 }
+
+
+MathInset::mode_type MathCursor::currentMode() const
+{
+       for (int i = Cursor_.size() - 1; i >= 0; --i) {
+               MathInset::mode_type res = Cursor_[i].par_->currentMode();
+               if (res != MathInset::UNDECIDED_MODE)
+                       return res;
+       }
+       return MathInset::UNDECIDED_MODE;
+}
index df32032dc9da365d00ad0c311541cee10a959117..91063d8be64bbd33c093f756e50aa4cbde434f57 100644 (file)
@@ -138,8 +138,8 @@ public:
        MathUnknownInset * inMacroMode() const;
        /// are we currently typing '#1' or '#2' or...?
        bool inMacroArgMode() const;
-       /// are we in an mbox?
-       bool inMathMode() const;
+       /// are we in math mode (1), text mode (-1) or unsure?
+       MathInset::mode_type currentMode() const;
 
        // Local selection methods
        ///
index 0af5bc9ed9414365b6002365952744f471691453..9f1ea4a770d8f85586f52fb63158ac512edb610d 100644 (file)
@@ -20,7 +20,7 @@ public:
        ///
        MathInset * clone() const;
        ///
-       MathFboxInset * asFboxInset() { return this; }
+       mode_type currentMode() const { return TEXT_MODE; }
        ///
        void metrics(MathMetricsInfo & mi) const;
        ///
index 9b1536ac91d7848d7da0de2efd63eb3c3a57f870..4283014d81110ed960ccd90993b61ac6b3fa1289 100644 (file)
@@ -29,6 +29,12 @@ MathInset * MathFontInset::clone() const
 }
 
 
+MathInset::mode_type MathFontInset::currentMode() const
+{
+       return key_->extra == "mathmode" ? MATH_MODE : TEXT_MODE;
+}
+
+
 void MathFontInset::metrics(MathMetricsInfo & mi) const
 {
        MathFontSetChanger dummy(mi.base, key_->name.c_str());
index 5b0dfdd427309a5863af0280e24e45ddf77d6ca9..91e20458d341ba7129f10667cd2d4c16f173d87c 100644 (file)
@@ -20,6 +20,8 @@ public:
        explicit MathFontInset(latexkeys const * key);
        ///
        MathInset * clone() const;
+       /// are we in math mode, text mode, or unsure?
+       mode_type currentMode() const;
        ///
        void metrics(MathMetricsInfo & mi) const;
        ///
index 14a42cc58f50ba3ca1216dd0ae6295d284a98916..c04f4eba424300afb88623791ea9c746224d8a7d 100644 (file)
@@ -20,6 +20,8 @@ public:
        explicit MathFontOldInset(latexkeys const * key);
        ///
        MathInset * clone() const;
+       /// we are in text mode.
+       mode_type currentMode() const { return TEXT_MODE; }
        /// we write extra braces in any case...
        bool extraBraces() const { return true; }
        ///
index 8fd885464ebda87604c41f475c5c6f85a1a4431d..a00d4afc13a162a3aa816f3325edf2a7f94eccc5 100644 (file)
@@ -94,18 +94,19 @@ MathHullInset::MathHullInset(string const & type)
        setDefaults();
 }
 
-/*
-MathHullInset::MathHullInset(string const & type, MathGridInset const & grid)
-       : MathGridInset(grid), type_(type), nonum_(1), label_(1)
+
+MathInset * MathHullInset::clone() const
 {
-       setDefaults();
+       return new MathHullInset(*this);
 }
-*/
 
 
-MathInset * MathHullInset::clone() const
+MathInset::mode_type MathHullInset::currentMode() const
 {
-       return new MathHullInset(*this);
+       if (type_ == "none")
+               return UNDECIDED_MODE;
+       // definitely math mode ...
+       return MATH_MODE;
 }
 
 
index 33f5fccdec47c586f6ddb60bb729dbbc636578e1..8a2a7b6cfb171aaa7e3b6817f08fb1caa5dc50cf 100644 (file)
@@ -21,10 +21,10 @@ public:
        ///
        explicit MathHullInset(string const & type);
        ///
-       MathHullInset(string const & type, MathGridInset const & grid);
-       ///
        MathInset * clone() const;
        ///
+       mode_type currentMode() const;
+       ///
        void metrics(MathMetricsInfo & mi) const;
        ///
        void draw(MathPainterInfo &, int x, int y) const;
index 3805e7c189d9036991974ddf49db8f9a14ffaf19..6d5c089a93821fc2deee756f3b48152b271e67af 100644 (file)
@@ -49,16 +49,13 @@ inclusion in the "real LyX insets" FormulaInset and FormulaMacroInset.
 
 class MathArrayInset;
 class MathAMSArrayInset;
-class MathBoxInset;
 class MathCharInset;
 class MathDelimInset;
-class MathFboxInset;
 class MathGridInset;
 class MathFracInset;
 class MathHullInset;
 class MathMatrixInset;
 class MathNestInset;
-class MathParInset;
 class MathParboxInset;
 class MathScriptInset;
 class MathStringInset;
@@ -196,12 +193,9 @@ public:
        /// identifies certain types of insets
        virtual MathAMSArrayInset      * asAMSArrayInset()      { return 0; }
        virtual MathArrayInset         * asArrayInset()         { return 0; }
-       virtual MathBoxInset           * asBoxInset()           { return 0; }
-       virtual MathBoxInset const     * asBoxInset() const     { return 0; }
        virtual MathCharInset const    * asCharInset() const    { return 0; }
        virtual MathDelimInset         * asDelimInset()         { return 0; }
        virtual MathDelimInset const   * asDelimInset() const   { return 0; }
-       virtual MathFboxInset          * asFboxInset()          { return 0; }
        virtual MathFracInset          * asFracInset()          { return 0; }
        virtual MathGridInset          * asGridInset()          { return 0; }
        virtual MathHullInset          * asHullInset()          { return 0; }
@@ -209,7 +203,6 @@ public:
        virtual MathMacroTemplate      * asMacroTemplate()      { return 0; }
        virtual MathMatrixInset const  * asMatrixInset() const  { return 0; }
        virtual MathNestInset          * asNestInset()          { return 0; }
-       virtual MathParInset           * asParInset()           { return 0; }
        virtual MathParboxInset        * asParboxInset()        { return 0; }
        virtual MathScriptInset        * asScriptInset()        { return 0; }
        virtual MathScriptInset const  * asScriptInset() const  { return 0; }
@@ -227,6 +220,9 @@ public:
        virtual bool isActive() const { return nargs() > 0; }
        /// is the a relational operator (used for splitting equations)
        virtual bool isRelOp() const { return false; }
+       /// -1: text mode, 1: math mode, 0 undecided
+       enum mode_type {UNDECIDED_MODE, TEXT_MODE, MATH_MODE};
+       virtual mode_type currentMode() const { return UNDECIDED_MODE; }
        /// will this get written as a single block in {..}
        virtual bool extraBraces() const { return false; }
 
index 389fe158b0bdca4359354273b961603d87d09a53..842779a6883ba5269fee247a15ac9495d1b3f6a4 100644 (file)
@@ -11,6 +11,8 @@ public:
        MathParboxInset * asParboxInset() { return this; }
        ///
        MathInset * clone() const;
+       ///
+       mode_type currentMode() const { return TEXT_MODE; }
        /// get cursor position
        void getPos(idx_type idx, pos_type pos, int & x, int & y) const;
        ///
index 17b6e0bd069c79ed8134cc87970d539757631ecb..17811cb87912c12ed64ccf3b2e96afa69ba548ba 100644 (file)
@@ -8,7 +8,7 @@ public:
        ///
        MathParInset();
        ///
-       MathParInset * asParInset() { return this; }
+       mode_type currentMode() const { return TEXT_MODE; }
        ///
        void metrics(MathMetricsInfo & mi) const;
        ///