]> git.lyx.org Git - lyx.git/commitdiff
Re-introduction of a BraceInset to handle "extra braces"
authorAndré Pönitz <poenitz@gmx.net>
Mon, 29 Oct 2001 15:45:24 +0000 (15:45 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Mon, 29 Oct 2001 15:45:24 +0000 (15:45 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2943 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/BUGS
src/mathed/Makefile.am
src/mathed/formula.C
src/mathed/math_braceinset.C [new file with mode: 0644]
src/mathed/math_braceinset.h [new file with mode: 0644]
src/mathed/math_cursor.C
src/mathed/math_deliminset.C
src/mathed/math_parser.C
src/mathed/math_symbolinset.C

index b373073a64c8f3ffa1f25f70dd648c3bdd4bffeb..679e64204cfad1fe954dcc5a4aad405baf610f07 100644 (file)
@@ -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 <right> <right> <right>       (zoom=100, screenDPI=100)
 
-- When selecting multiple cells in a array using the keyboard, <left>
-  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, <left>
+//   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.
index d9028062c75aeb2e21f0b226c1b641973c3dd582..5ca7a92d22077f30a04ee387b379e3ec799153ff 100644 (file)
@@ -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 \
index 02ab30e6f678c4ce7555129b2a492cfc9596602b..ff031371395a1ea6569e599deca48dcff61dfa3d 100644 (file)
@@ -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 (file)
index 0000000..93b3733
--- /dev/null
@@ -0,0 +1,56 @@
+#include <config.h>
+
+#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 (file)
index 0000000..b7ed951
--- /dev/null
@@ -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
index 25a86f1b7e6726df6b3c693d49093e4ec0368404..ac755a854357b3f21b0a53b87ec6657a3d97a00e 100644 (file)
@@ -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)));  
index d9755b7cb0463aec46f00381e04b4a111d40aca9..3c6ad1691588d52c433fb7113d7dcc0ecd7b8bb1 100644 (file)
@@ -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 << "]";
 }
 
 
index c2e4c31392366346eec8b207ef1d197ac766fabb..1421b5b7f3c067b56e36c8ae9dcb2b5805ea2eac 100644 (file)
  *   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 <config.h>
 
 #include <cctype>
@@ -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<MathTextCodes> 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<MathTextCodes>(l->id));
+                                       code = static_cast<MathTextCodes>(l->id);
                                }
 
                                else {
index 09a3cbadad8a42ab85cc68ea8cc6a6700593c867..e27fbe1bc9bb1aabd34e5e83f1131e18a133fa1b 100644 (file)
@@ -24,7 +24,7 @@ void MathSymbolInset::write(MathWriteInfo & os) const
 
 void MathSymbolInset::writeNormal(ostream & os) const
 {
-       os << "[" << sym_->name << "] ";
+       os << "[symbol " << sym_->name << "]";
 }