From d109cee80bb0156683629bd15f1b246a9bb463b9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Tue, 18 Dec 2001 12:21:33 +0000 Subject: [PATCH] preliminary support for \mbox git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3237 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/formulabase.C | 11 +++++--- src/mathed/math_boxinset.C | 57 ++++++-------------------------------- src/mathed/math_boxinset.h | 35 ++++++----------------- src/mathed/math_cursor.C | 39 ++++++++++++++------------ src/mathed/math_cursor.h | 2 +- src/mathed/math_defs.h | 25 ++++++----------- src/mathed/math_hash.C | 1 + src/mathed/math_inset.h | 1 + src/mathed/math_parser.C | 26 +++++++++++------ src/mathed/math_support.C | 3 +- 10 files changed, 75 insertions(+), 125 deletions(-) diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index fc2b83b1ff..1af5cd2f1d 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -36,12 +36,13 @@ #include "LyXView.h" #include "Painter.h" #include "font.h" -#include "math_cursor.h" #include "math_arrayinset.h" -#include "math_spaceinset.h" -#include "math_macrotable.h" +#include "math_cursor.h" #include "math_factory.h" +#include "math_hullinset.h" +#include "math_macrotable.h" #include "math_parser.h" +#include "math_spaceinset.h" #include "undo_funcs.h" using std::endl; @@ -523,7 +524,9 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action, break; case LFUN_MATH_MODE: - handleFont(bv, LM_TC_TEXTRM); + //handleFont(bv, LM_TC_TEXTRM); + mathcursor->niceInsert(MathAtom(new MathHullInset(LM_OT_SIMPLE))); + updateLocal(bv, true); //bv->owner()->message(_("math text mode toggled")); break; diff --git a/src/mathed/math_boxinset.C b/src/mathed/math_boxinset.C index 1a546c7826..b2ed64015f 100644 --- a/src/mathed/math_boxinset.C +++ b/src/mathed/math_boxinset.C @@ -6,47 +6,23 @@ #include "math_boxinset.h" #include "support/LOstream.h" -#include "LColor.h" #include "debug.h" #include "Painter.h" #include "math_cursor.h" -#include "insets/insettext.h" #include "math_mathmlstream.h" #include "math_streamstr.h" MathBoxInset::MathBoxInset(string const & name) - : MathDimInset(), name_(name), text_(new InsetText), buffer_(0) + : MathGridInset(1, 1), name_(name) {} -MathBoxInset::MathBoxInset(MathBoxInset const & m) - : MathDimInset(*this), name_(m.name_), text_(0), buffer_(m.buffer_) -{ - if (!m.buffer_) - lyxerr << "no buffer\n"; - else - text_ = static_cast(m.text_->clone(*m.buffer_, false)); -} - - -MathBoxInset::~MathBoxInset() -{ - delete text_; -} - - MathInset * MathBoxInset::clone() const { return new MathBoxInset(*this); } -UpdatableInset * MathBoxInset::asHyperActiveInset() const -{ - return text_; -} - - void MathBoxInset::write(WriteStream & os) const { os << "\\" << name_ << "{" << cell(0) << "}"; @@ -55,40 +31,23 @@ void MathBoxInset::write(WriteStream & os) const void MathBoxInset::normalize(NormalStream & os) const { - os << "[mbox "; + os << '[' << name_ << ' '; //text_->write(buffer(), os); os << "] "; } -void MathBoxInset::metrics(MathMetricsInfo const & st) const +void MathBoxInset::rebreak() { - mi_ = st; - if (text_ && mi_.view) { - ascent_ = text_->ascent(mi_.view, mi_.font) + 2; - descent_ = text_->descent(mi_.view, mi_.font) + 2; - width_ = text_->width(mi_.view, mi_.font) + 4; - } else { - ascent_ = 10; - descent_ = 0; - width_ = 10; - } + //lyxerr << "trying to rebreak...\n"; } void MathBoxInset::draw(Painter & pain, int x, int y) const { - float fx = x + 2; - if (text_ && mi_.view) - text_->draw(mi_.view, mi_.font, y, fx, false); - if (mathcursor && mathcursor->isInside(this)) - pain.rectangle(x, y - ascent(), xcell(0).width(), height(), + MathGridInset::draw(pain, x, y); + if (mathcursor && mathcursor->isInside(this)) { + pain.rectangle(x - 1, y - ascent() - 1, width(), height(), LColor::mathframe); -} - - -void MathBoxInset::edit(BufferView * bv, int x, int y, unsigned int button) -{ - if (text_) - text_->edit(bv, x, y, button); + } } diff --git a/src/mathed/math_boxinset.h b/src/mathed/math_boxinset.h index f67fa168f6..c2f4364daa 100644 --- a/src/mathed/math_boxinset.h +++ b/src/mathed/math_boxinset.h @@ -2,59 +2,40 @@ #ifndef MATH_BOXINSET_H #define MATH_BOXINSET_H -#include "math_diminset.h" +#include "math_gridinset.h" #include "LString.h" #ifdef __GNUG__ #pragma interface #endif -class InsetText; -class UpdatableInset; -class BufferView; -class Buffer; class LyXFont; /// Support for \\mbox -class MathBoxInset : public MathDimInset { +class MathBoxInset : public MathGridInset { public: /// explicit MathBoxInset(string const &); /// - MathBoxInset(MathBoxInset const &); - /// - ~MathBoxInset(); - /// MathInset * clone() const; + /// identifies BoxInsets + MathBoxInset * asBoxInset() { return this; } + /// identifies BoxInsets + MathBoxInset const * asBoxInset() const { return this; } /// - void draw(Painter &, int x, int y) const; + void rebreak(); /// void write(WriteStream & os) const; /// void normalize(NormalStream &) const; /// - void metrics(MathMetricsInfo const &) const; - /// identifies BoxInsets - MathBoxInset * asBoxInset() { return this; } - /// - bool isHyperActive() const { return 1; } - /// - void edit(BufferView * bv, int x, int y, unsigned int button); - /// identifies hyperactive insets - UpdatableInset * asHyperActiveInset() const; + void draw(Painter &, int x, int y) const; private: - /// unimplemented - void operator=(MathBoxInset const &); - /// mutable MathMetricsInfo mi_; /// string name_; - /// - InsetText * text_; - /// - mutable Buffer * buffer_; }; #endif diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 12126ff245..2c9cf7fa59 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -21,10 +21,16 @@ #pragma implementation #endif +#include "support/lstrings.h" +#include "support/LAssert.h" +#include "debug.h" +#include "LColor.h" +#include "Painter.h" #include "math_cursor.h" #include "formulabase.h" #include "math_arrayinset.h" #include "math_braceinset.h" +#include "math_boxinset.h" #include "math_casesinset.h" #include "math_charinset.h" #include "math_deliminset.h" @@ -39,13 +45,6 @@ #include "math_specialcharinset.h" #include "math_support.h" -#include "debug.h" -#include "LColor.h" -#include "Painter.h" - -#include "support/lstrings.h" -#include "support/LAssert.h" - #include #include @@ -891,30 +890,34 @@ void MathCursor::pullArg(bool goright) } -void MathCursor::normalize() const +void MathCursor::normalize() { -#ifdef WITH_WARNINGS -#warning This is evil! -#endif - MathCursor * it = const_cast(this); + // 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(); + } if (idx() >= par()->nargs()) { lyxerr << "this should not really happen - 1: " << idx() << " " << par()->nargs() << "\n"; dump("error 2"); } - it->idx() = min(idx(), par()->nargs() - 1); + idx() = min(idx(), par()->nargs() - 1); if (pos() > size()) { lyxerr << "this should not really happen - 2: " - << pos() << " " << size() << " in idx: " << it->idx() + << pos() << " " << size() << " in idx: " << idx() << " in atom: '"; WriteStream wi(lyxerr, false); - it->par()->write(wi); + par()->write(wi); lyxerr << "\n"; dump("error 4"); } - it->pos() = min(pos(), size()); + pos() = min(pos(), size()); } @@ -1339,7 +1342,7 @@ bool MathCursor::interpret(char c) // fall through in the other cases } - if (lastcode_ == LM_TC_TEXTRM) { + if (lastcode_ == LM_TC_TEXTRM || par()->asBoxInset()) { // suppress direct insertion of two spaces in a row // the still allows typing 'a' and deleting the 'a', but // it is better than nothing... @@ -1354,7 +1357,7 @@ bool MathCursor::interpret(char c) prevAtom()->asSpaceInset()->incSpace(); return true; } - if (mathcursor->popRight()) + if (popRight()) return true; // if are at the very end, leave the formula return pos() != size(); diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index b15fef5dc7..91a52bb009 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -182,7 +182,7 @@ public: row_type gridRow() const; /// make sure cursor position is valid - void normalize() const; + void normalize(); /// UpdatableInset * asHyperActiveInset() const; diff --git a/src/mathed/math_defs.h b/src/mathed/math_defs.h index adba3adb4e..d84036f31a 100644 --- a/src/mathed/math_defs.h +++ b/src/mathed/math_defs.h @@ -25,18 +25,14 @@ #endif -/** The restrictions of a standard LaTeX math paragraph - allows to get a small number of text codes (<30) */ +/// enum MathTextCodes { - /// This must be >= 0 + /// LM_TC_MIN = 0, - /// Math Inset - LM_TC_INSET, - - /// - LM_FONT_BEGIN, - /// Internal code for variables + /// internal code for variables LM_TC_VAR, + /// internal code for stuff in wrapped in mbox etc + LM_TC_BOX, /// LM_TC_CONST, /// @@ -57,13 +53,13 @@ enum MathTextCodes { LM_TC_IT, /// LM_TC_TEXTRM, - /// Math mode TeX characters ",;:{}" + /// math mode TeX characters ",;:{}" LM_TC_TEX, - /// Internal code when typing greek + /// internal code when typing greek LM_TC_GREEK, - /// Internal code when typing a single greek character + /// internal code when typing a single greek character LM_TC_GREEK1, - /// Internal code for symbols + /// internal code for symbols LM_TC_SYMB, /// internal code for symbols that get bigger in displayed math LM_TC_BOLDSYMB, @@ -81,9 +77,6 @@ enum MathTextCodes { LM_TC_MSB, /// LM_FONT_END, - - /// This must be < 32 - LM_TC_MAX }; diff --git a/src/mathed/math_hash.C b/src/mathed/math_hash.C index 6d0fb8ccec..1f22147ab4 100644 --- a/src/mathed/math_hash.C +++ b/src/mathed/math_hash.C @@ -90,6 +90,7 @@ key_type wordlist_array[] = {"limsup", LM_TK_FUNCLIM, 0}, {"ln", LM_TK_FUNC, 0}, {"log", LM_TK_FUNC, 0}, + {"lyxbox", LM_TK_BOX, 0}, {"mathbb", LM_TK_FONT, LM_TC_BB}, {"mathbf", LM_TK_FONT, LM_TC_BF}, {"mathcal", LM_TK_FONT, LM_TC_CAL}, diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index bf2f2ec314..5b8d6de1da 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -177,6 +177,7 @@ public: /// identifies certain types of insets 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; } diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index eff6c33f57..7538fce72c 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -137,6 +137,7 @@ enum { FLAG_RIGHT = 1 << 2, // next \\right ends the parsing process FLAG_END = 1 << 3, // next \\end ends the parsing process FLAG_BRACK_END = 1 << 4, // next closing bracket ends the parsing process + FLAG_BOX = 1 << 5, // we are in a box FLAG_ITEM = 1 << 7, // read a (possibly braced token) FLAG_BLOCK = 1 << 8, // next block ends the parsing process FLAG_LEAVE = 1 << 9 // leave the loop at the end @@ -148,13 +149,6 @@ void catInit() fill(theCatcode, theCatcode + 256, catOther); fill(theCatcode + 'a', theCatcode + 'z' + 1, catLetter); fill(theCatcode + 'A', theCatcode + 'Z' + 1, catLetter); - -// for (int i = 0; i <= 255; ++i) -// theCatcode[i] = catOther; -// for (int i = 'a'; i <= 'z'; ++i) -// theCatcode[i] = catLetter; -// for (int i = 'A'; i <= 'Z'; ++i) -// theCatcode[i] = catLetter; theCatcode['\\'] = catEscape; theCatcode['{'] = catBegin; @@ -767,8 +761,16 @@ void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code) // // cat codes // - if (t.cat() == catMath) - break; + if (t.cat() == catMath) { + if (flags & FLAG_BOX) { + // we are inside an mbox, so opening new math is allowed + array.push_back(MathAtom(new MathHullInset(LM_OT_SIMPLE))); + parse_into(array.back()->cell(0), 0); + } else { + // otherwise this is the end of the formula + break; + } + } else if (t.cat() == catLetter) add(array, t.character(), code); @@ -992,6 +994,12 @@ void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code) code = static_cast(l->id); } + else if (l->token == LM_TK_BOX) { + MathAtom p = createMathInset(t.cs()); + parse_into(p->cell(0), FLAG_ITEM | FLAG_BOX, LM_TC_BOX); + array.push_back(p); + } + else { MathAtom p = createMathInset(t.cs()); for (MathInset::idx_type i = 0; i < p->nargs(); ++i) diff --git a/src/mathed/math_support.C b/src/mathed/math_support.C index 29c1d6b4ff..f3d5a0b3d5 100644 --- a/src/mathed/math_support.C +++ b/src/mathed/math_support.C @@ -153,6 +153,7 @@ LyXFont const & whichFontBaseIntern(MathTextCodes type) case LM_TC_TT: return MathFonts[FONT_TT]; + case LM_TC_BOX: case LM_TC_TEXTRM: case LM_TC_CONST: case LM_TC_TEX: @@ -253,7 +254,7 @@ LyXFont whichFont(MathTextCodes type, MathMetricsInfo const & size) break; } - if (type != LM_TC_TEXTRM) + if (type != LM_TC_TEXTRM && type != LM_TC_BOX) f.setColor(LColor::math); if (type == LM_TC_TEX) -- 2.39.2