From 10fd14e55b6887e3be09baa9ed1f5467c40a3889 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Thu, 18 Jul 2002 11:02:33 +0000 Subject: [PATCH] enable insertion of spaces in all \textxxx modes. some cleanup. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4702 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/formulabase.C | 2 +- src/mathed/math_boxinset.C | 6 ---- src/mathed/math_boxinset.h | 8 ++--- src/mathed/math_cursor.C | 57 ++++++++++++---------------------- src/mathed/math_cursor.h | 4 +-- src/mathed/math_fboxinset.h | 2 +- src/mathed/math_fontinset.C | 6 ++++ src/mathed/math_fontinset.h | 2 ++ src/mathed/math_fontoldinset.h | 2 ++ src/mathed/math_hullinset.C | 15 ++++----- src/mathed/math_hullinset.h | 4 +-- src/mathed/math_inset.h | 10 ++---- src/mathed/math_parboxinset.h | 2 ++ src/mathed/math_parinset.h | 2 +- 14 files changed, 52 insertions(+), 70 deletions(-) diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index 26beee4ca1..06cf5a9385 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -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"))); diff --git a/src/mathed/math_boxinset.C b/src/mathed/math_boxinset.C index 981bf356fb..218cbec0a5 100644 --- a/src/mathed/math_boxinset.C +++ b/src/mathed/math_boxinset.C @@ -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"); diff --git a/src/mathed/math_boxinset.h b/src/mathed/math_boxinset.h index dca47ceb06..c027c3954e 100644 --- a/src/mathed/math_boxinset.h +++ b/src/mathed/math_boxinset.h @@ -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; /// diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index ad8ae53d17..ef7d3beb01 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -32,12 +32,10 @@ #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 'a' 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 'a' 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; +} diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index df32032dc9..91063d8be6 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -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 /// diff --git a/src/mathed/math_fboxinset.h b/src/mathed/math_fboxinset.h index 0af5bc9ed9..9f1ea4a770 100644 --- a/src/mathed/math_fboxinset.h +++ b/src/mathed/math_fboxinset.h @@ -20,7 +20,7 @@ public: /// MathInset * clone() const; /// - MathFboxInset * asFboxInset() { return this; } + mode_type currentMode() const { return TEXT_MODE; } /// void metrics(MathMetricsInfo & mi) const; /// diff --git a/src/mathed/math_fontinset.C b/src/mathed/math_fontinset.C index 9b1536ac91..4283014d81 100644 --- a/src/mathed/math_fontinset.C +++ b/src/mathed/math_fontinset.C @@ -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()); diff --git a/src/mathed/math_fontinset.h b/src/mathed/math_fontinset.h index 5b0dfdd427..91e20458d3 100644 --- a/src/mathed/math_fontinset.h +++ b/src/mathed/math_fontinset.h @@ -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; /// diff --git a/src/mathed/math_fontoldinset.h b/src/mathed/math_fontoldinset.h index 14a42cc58f..c04f4eba42 100644 --- a/src/mathed/math_fontoldinset.h +++ b/src/mathed/math_fontoldinset.h @@ -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; } /// diff --git a/src/mathed/math_hullinset.C b/src/mathed/math_hullinset.C index 8fd885464e..a00d4afc13 100644 --- a/src/mathed/math_hullinset.C +++ b/src/mathed/math_hullinset.C @@ -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; } diff --git a/src/mathed/math_hullinset.h b/src/mathed/math_hullinset.h index 33f5fccdec..8a2a7b6cfb 100644 --- a/src/mathed/math_hullinset.h +++ b/src/mathed/math_hullinset.h @@ -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; diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 3805e7c189..6d5c089a93 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -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; } diff --git a/src/mathed/math_parboxinset.h b/src/mathed/math_parboxinset.h index 389fe158b0..842779a688 100644 --- a/src/mathed/math_parboxinset.h +++ b/src/mathed/math_parboxinset.h @@ -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; /// diff --git a/src/mathed/math_parinset.h b/src/mathed/math_parinset.h index 17b6e0bd06..17811cb879 100644 --- a/src/mathed/math_parinset.h +++ b/src/mathed/math_parinset.h @@ -8,7 +8,7 @@ public: /// MathParInset(); /// - MathParInset * asParInset() { return this; } + mode_type currentMode() const { return TEXT_MODE; } /// void metrics(MathMetricsInfo & mi) const; /// -- 2.39.2