From fcc87d756bc89183e2647f0d96a73dda2f414c78 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Mon, 29 Oct 2001 15:45:24 +0000 Subject: [PATCH] Re-introduction of a BraceInset to handle "extra braces" git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2943 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/BUGS | 10 ++++--- src/mathed/Makefile.am | 2 ++ src/mathed/formula.C | 18 ++++++----- src/mathed/math_braceinset.C | 56 +++++++++++++++++++++++++++++++++++ src/mathed/math_braceinset.h | 38 ++++++++++++++++++++++++ src/mathed/math_cursor.C | 25 +++++++++++++++- src/mathed/math_deliminset.C | 5 +++- src/mathed/math_parser.C | 50 +++++++++++++++++++++++-------- src/mathed/math_symbolinset.C | 2 +- 9 files changed, 178 insertions(+), 28 deletions(-) create mode 100644 src/mathed/math_braceinset.C create mode 100644 src/mathed/math_braceinset.h diff --git a/src/mathed/BUGS b/src/mathed/BUGS index b373073a64..679e64204c 100644 --- a/src/mathed/BUGS +++ b/src/mathed/BUGS @@ -12,6 +12,8 @@ Items marked with !! - mark "not a bug, a feature" replies, usually with a request for further discussion + pp - partially fixed + Unmarked items are known unfixed but probably unverified bugs. ---------------------------------------------------------------------- @@ -60,7 +62,7 @@ Misc: // - When you press the mouse just to the left of the middle point of // some char, the cursor will be positioned to the right of the char. -- It is possible to put two or more consecutive spaces in math text mode +pp - It is possible to put two or more consecutive spaces in math text mode // - Text in superscript is not smaller than normal text. @@ -113,9 +115,9 @@ Eran Tromer: // enter the cell its cell and press // M-m ( M-f 1 (zoom=100, screenDPI=100) -- When selecting multiple cells in a array using the keyboard, - etc. should can move whole cell at a time -- no need to navigate - within cells. +// - When selecting multiple cells in a array using the keyboard, +// etc. should can move whole cell at a time -- no need to navigate +// within cells. - When selecting, maybe give a visual indication of the "original" anchor, when it differs from the "actual" one. diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index d9028062c7..5ca7a92d22 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -24,6 +24,8 @@ libmathed_la_SOURCES = \ math_atom.h \ math_binominset.C \ math_binominset.h \ + math_braceinset.C \ + math_braceinset.h \ math_boxinset.C \ math_boxinset.h \ math_charinset.C \ diff --git a/src/mathed/formula.C b/src/mathed/formula.C index 02ab30e6f6..ff03137139 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -291,14 +291,6 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action, break; } - case LFUN_MATH_EXTERN: - bv->lockedInsetStoreUndo(Undo::EDIT); - handleExtern(arg); - // re-compute inset dimension - metrics(bv); - updateLocal(bv, true); - break; - case LFUN_MATH_MUTATE: { bv->lockedInsetStoreUndo(Undo::EDIT); @@ -312,6 +304,16 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action, break; } + case LFUN_MATH_EXTERN: + { + bv->lockedInsetStoreUndo(Undo::EDIT); + handleExtern(arg); + // re-compute inset dimension + metrics(bv); + updateLocal(bv, true); + break; + } + case LFUN_MATH_DISPLAY: { int x; diff --git a/src/mathed/math_braceinset.C b/src/mathed/math_braceinset.C new file mode 100644 index 0000000000..93b37336d6 --- /dev/null +++ b/src/mathed/math_braceinset.C @@ -0,0 +1,56 @@ +#include + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "math_braceinset.h" +#include "math_parser.h" +#include "mathed/support.h" +#include "support/LOstream.h" + +using std::max; + + +MathBraceInset::MathBraceInset() + : MathNestInset(1) +{} + + +MathInset * MathBraceInset::clone() const +{ + return new MathBraceInset(*this); +} + + +void MathBraceInset::write(MathWriteInfo & os) const +{ + os << '{' << cell(0) << '}'; +} + + +void MathBraceInset::writeNormal(std::ostream & os) const +{ + os << "[block "; + cell(0).writeNormal(os); + os << "]"; +} + + +void MathBraceInset::metrics(MathMetricsInfo const & mi) const +{ + xcell(0).metrics(mi); + int a, d; + mathed_char_dim(LM_TC_TEX, mi, '{', a, d, wid_); + ascent_ = std::max(xcell(0).ascent(), a); + descent_ = std::max(xcell(0).descent(), a); + width_ = xcell(0).width() + 2 * wid_; +} + + +void MathBraceInset::draw(Painter & pain, int x, int y) const +{ + drawChar(pain, LM_TC_TEX, mi_, x, y, '{'); + xcell(0).draw(pain, x + wid_, y); + drawChar(pain, LM_TC_TEX, mi_, x + width_ - wid_, y, '}'); +} diff --git a/src/mathed/math_braceinset.h b/src/mathed/math_braceinset.h new file mode 100644 index 0000000000..b7ed9514ff --- /dev/null +++ b/src/mathed/math_braceinset.h @@ -0,0 +1,38 @@ +// -*- C++ -*- +#ifndef MATH_BRACEINSET_H +#define MATH_BRACEINSET_H + +#include "math_nestinset.h" +#include "math_metricsinfo.h" + +#ifdef __GNUG__ +#pragma interface +#endif + +/** Extra nesting + \author André Pönitz +*/ + +class MathBraceInset : public MathNestInset { +public: + /// + MathBraceInset(); + /// + MathInset * clone() const; + /// + void draw(Painter &, int x, int y) const; + /// + void write(MathWriteInfo & os) const; + /// write normalized content + void writeNormal(std::ostream &) const; + /// + void metrics(MathMetricsInfo const & st) const; + +private: + /// width of brace character + mutable int wid_; + /// + MathMetricsInfo mi_; +}; + +#endif diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 25a86f1b7e..ac755a8543 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -33,6 +33,7 @@ #include "math_cursor.h" #include "math_factory.h" #include "math_arrayinset.h" +#include "math_braceinset.h" #include "math_charinset.h" #include "math_deliminset.h" #include "math_matrixinset.h" @@ -786,7 +787,6 @@ void MathCursor::drawSelection(Painter & pain) const MathCursorPos i1; MathCursorPos i2; getSelection(i1, i2); - //lyxerr << "selection from: " << i1 << " to " << i2 << "\n"; if (i1.idx_ == i2.idx_) { @@ -808,6 +808,18 @@ void MathCursor::drawSelection(Painter & pain) const pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection); } } + +#if 0 + // draw anchor if different from selection boundary + MathCursorPos anc = Anchor_.back(); + if (anc != i1 && anc != i2) { + MathXArray & c = anc.xcell(); + int x = c.xo() + c.pos2x(anc.pos_); + int y1 = c.yo() - c.ascent(); + int y2 = c.yo() + c.descent(); + pain.line(x, y1, x, y2, LColor::mathline); + } +#endif } @@ -1385,10 +1397,21 @@ void MathCursor::interpret(char c) return; } +/* if (strchr("{}", c)) { insert(c, LM_TC_TEX); return; } +*/ + + if (c == '{') { + niceInsert(MathAtom(new MathBraceInset)); + return; + } + + if (c == '}') { + return; + } if (strchr("#$%", c)) { insert(MathAtom(new MathSpecialCharInset(c))); diff --git a/src/mathed/math_deliminset.C b/src/mathed/math_deliminset.C index d9755b7cb0..3c6ad16915 100644 --- a/src/mathed/math_deliminset.C +++ b/src/mathed/math_deliminset.C @@ -11,6 +11,7 @@ using std::max; + MathDelimInset::MathDelimInset(string const & l, string const & r) : MathNestInset(1), left_(l), right_(r) {} @@ -51,7 +52,9 @@ void MathDelimInset::write(MathWriteInfo & os) const void MathDelimInset::writeNormal(std::ostream & os) const { - os << "[delim " << latexName(left_) << " " << latexName(right_) << "]"; + os << "[delim " << latexName(left_) << ' ' << latexName(right_) << ' '; + cell(0).writeNormal(os); + os << "]"; } diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index c2e4c31392..1421b5b7f3 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -15,6 +15,34 @@ * the GNU General Public Licence version 2 or later. */ +/* + +If someone desperately needs partial "structures" (such as a few cells of +an array inset or similar) (s)he could uses the following hack as starting +point to write some macros: + + \newif\ifcomment + \commentfalse + \ifcomment + \def\makeamptab{\catcode`\&=4\relax} + \def\makeampletter{\catcode`\&=11\relax} + \def\b{\makeampletter\expandafter\makeamptab\bi} + \long\def\bi#1\e{} + \else + \def\b{}\def\e{} + \fi + + ... + + \[\begin{array}{ccc} + 1 & 2\b & 3^2\\ + 4 & 5\e & 6\\ + 7 & 8 & 9 + \end{array}\] + +*/ + + #include #include @@ -28,6 +56,7 @@ #include "array.h" #include "math_inset.h" #include "math_arrayinset.h" +#include "math_braceinset.h" #include "math_charinset.h" #include "math_deliminset.h" #include "math_factory.h" @@ -642,9 +671,6 @@ bool Parser::parse_normal(MathAtom & matrix) void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code) { - stack fontcodes; - fontcodes.push(LM_TC_MIN); - bool panic = false; int limits = 0; @@ -695,11 +721,10 @@ void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code) break; else if (t.cat() == catLetter) - add(array, t.character(), fontcodes.top()); + add(array, t.character(), code); - else if (t.cat() == catSpace && - (fontcodes.top() == LM_TC_TEXTRM || code == LM_TC_TEXTRM)) - add(array, ' ', fontcodes.top()); + else if (t.cat() == catSpace && code == LM_TC_TEXTRM) + add(array, t.character(), code); else if (t.cat() == catParameter) { Token const & n = getToken(); @@ -707,15 +732,15 @@ void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code) } else if (t.cat() == catBegin) { - add(array, '{', LM_TC_TEX); - fontcodes.push(LM_TC_MIN); + array.push_back(MathAtom(new MathBraceInset)); + parse_into(array.back()->cell(0), FLAG_BRACE_LAST, LM_TC_MIN); } else if (t.cat() == catEnd) { if (flags & FLAG_BRACE_LAST) return; + lyxerr << "found '}' unexpectedly, array: '" << array << "'\n"; add(array, '}', LM_TC_TEX); - fontcodes.pop(); } else if (t.cat() == catAlign) { @@ -742,7 +767,7 @@ void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code) return; else if (t.cat() == catOther) - add(array, t.character(), fontcodes.top()); + add(array, t.character(), code); // // codesequences @@ -930,8 +955,7 @@ void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code) } else if (l->token == LM_TK_OLDFONT) { - fontcodes.pop(); - fontcodes.push(static_cast(l->id)); + code = static_cast(l->id); } else { diff --git a/src/mathed/math_symbolinset.C b/src/mathed/math_symbolinset.C index 09a3cbadad..e27fbe1bc9 100644 --- a/src/mathed/math_symbolinset.C +++ b/src/mathed/math_symbolinset.C @@ -24,7 +24,7 @@ void MathSymbolInset::write(MathWriteInfo & os) const void MathSymbolInset::writeNormal(ostream & os) const { - os << "[" << sym_->name << "] "; + os << "[symbol " << sym_->name << "]"; } -- 2.39.5