break;
case LFUN_MATH_MODE:
- if (mathcursor->inMathMode()) {
+ if (mathcursor->currentMode()) {
handleFont(bv, arg, "textrm");
} else {
mathcursor->niceInsert(MathAtom(new MathHullInset("simple")));
}
-void MathBoxInset::rebreak()
-{
- //lyxerr << "trying to rebreak...\n";
-}
-
-
void MathBoxInset::metrics(MathMetricsInfo & mi) const
{
MathFontSetChanger dummy(mi.base, "textnormal");
///
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;
///
#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"
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";
}
-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";
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)));
}
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;
}
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;
+}
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
///
///
MathInset * clone() const;
///
- MathFboxInset * asFboxInset() { return this; }
+ mode_type currentMode() const { return TEXT_MODE; }
///
void metrics(MathMetricsInfo & mi) 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());
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;
///
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; }
///
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;
}
///
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;
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;
/// 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; }
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; }
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; }
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;
///
///
MathParInset();
///
- MathParInset * asParInset() { return this; }
+ mode_type currentMode() const { return TEXT_MODE; }
///
void metrics(MathMetricsInfo & mi) const;
///