]> git.lyx.org Git - features.git/commitdiff
nest step...
authorAndré Pönitz <poenitz@gmx.net>
Thu, 26 Jul 2001 16:14:23 +0000 (16:14 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Thu, 26 Jul 2001 16:14:23 +0000 (16:14 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2362 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/formulabase.C
src/mathed/math_cursor.C
src/mathed/math_cursor.h
src/mathed/math_decorationinset.C
src/mathed/math_decorationinset.h
src/mathed/math_dotsinset.C
src/mathed/math_dotsinset.h
src/mathed/math_macrotable.C
src/mathed/math_macrotable.h
src/mathed/math_parser.C

index 21d1696ec2aacd2d5dfd030564fe6eff7ebdbe58..8ae66c7cb7a0f8ed3ab8de1acae77602f245cbd8 100644 (file)
@@ -76,10 +76,10 @@ void handleFont(BufferView * bv, MathTextCodes t)
        mathcursor->handleFont(t);
 }
 
-void handleAccent(BufferView * bv, string const & name, int code)
+void handleAccent(BufferView * bv, string const & name)
 {
        bv->lockedInsetStoreUndo(Undo::EDIT);
-       mathcursor->handleAccent(name, code);
+       mathcursor->handleAccent(name);
 }
 
 void handleDelim(BufferView * bv, int l, int r)
@@ -533,16 +533,16 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
 
                // --- accented characters ------------------------------
 
-       case LFUN_UMLAUT:     handleAccent(bv, "ddot", LM_ddot); break;
-       case LFUN_CIRCUMFLEX: handleAccent(bv, "hat", LM_hat); break;
-       case LFUN_GRAVE:      handleAccent(bv, "grave", LM_grave); break;
-       case LFUN_ACUTE:      handleAccent(bv, "acute", LM_acute); break;
-       case LFUN_TILDE:      handleAccent(bv, "tilde", LM_tilde); break;
-       case LFUN_MACRON:     handleAccent(bv, "bar", LM_bar); break;
-       case LFUN_DOT:        handleAccent(bv, "dot", LM_dot); break;
-       case LFUN_CARON:      handleAccent(bv, "check", LM_check); break;
-       case LFUN_BREVE:      handleAccent(bv, "breve", LM_breve); break;
-       case LFUN_VECTOR:     handleAccent(bv, "vec", LM_vec); break;
+       case LFUN_UMLAUT:     handleAccent(bv, "ddot"); break;
+       case LFUN_CIRCUMFLEX: handleAccent(bv, "hat"); break;
+       case LFUN_GRAVE:      handleAccent(bv, "grave"); break;
+       case LFUN_ACUTE:      handleAccent(bv, "acute"); break;
+       case LFUN_TILDE:      handleAccent(bv, "tilde"); break;
+       case LFUN_MACRON:     handleAccent(bv, "bar"); break;
+       case LFUN_DOT:        handleAccent(bv, "dot"); break;
+       case LFUN_CARON:      handleAccent(bv, "check"); break;
+       case LFUN_BREVE:      handleAccent(bv, "breve"); break;
+       case LFUN_VECTOR:     handleAccent(bv, "vec"); break;
 
                // Greek mode
        case LFUN_GREEK:
index 4ffe77a4f26421831fd0a2160c14fa409ffeb235..cfebdbaf5fa9efcbe9c3638e2d5e9e45d6082db4 100644 (file)
@@ -684,7 +684,7 @@ void MathCursor::interpret(string const & s)
                                break;
 
                        case LM_TK_DECORATION:
-                               p = new MathDecorationInset(l->name, l->id);
+                               p = new MathDecorationInset(l);
                                break;
 
                        case LM_TK_SPACE:
@@ -692,7 +692,7 @@ void MathCursor::interpret(string const & s)
                                break;
 
                        case LM_TK_DOTS:
-                               p = new MathDotsInset(l->name, l->id);
+                               p = new MathDotsInset(l);
                                break;
 
                        case LM_TK_MACRO:
@@ -862,9 +862,13 @@ void MathCursor::handleFont(MathTextCodes t)
 }
 
 
-void MathCursor::handleAccent(string const & name, int code)
+void MathCursor::handleAccent(string const & name)
 {
-       MathDecorationInset * p = new MathDecorationInset(name, code);
+       latexkeys const * l = in_word_set(name);
+       if (!l)
+               return;
+
+       MathDecorationInset * p = new MathDecorationInset(l);
        if (selection_) {
                selCut();
                p->cell(0) = theSelection.glue();
index 1d0366886322dbb10a22cf32e4178b6608fba908..3372505d6abbeef3adcfa9d9c258a7181aaa4d93 100644 (file)
@@ -156,7 +156,7 @@ public:
        ///
        void handleFont(MathTextCodes t);
        ///
-       void handleAccent(string const & name, int code);
+       void handleAccent(string const & name);
        ///
        void handleDelim(int l, int r);
        /// Splits cells and shifts right part to the next cell
index e547aa52dbf641586710db8fc48c21e23f7d86b4..dd87a10ec530a141d780a12cff92d1e0a267d7d4 100644 (file)
 using std::ostream;
 
 
-MathDecorationInset::MathDecorationInset(string const & name, int d)
-       : MathInset(1, name), deco_(d)
+MathDecorationInset::MathDecorationInset(latexkeys const * key)
+       : MathInset(1), key_(key)
 {
-       upper_ = deco_ != LM_underline && deco_ != LM_underbrace;
+       upper_ = key_->id != LM_underline && key_->id != LM_underbrace;
 }
 
 
@@ -43,7 +43,7 @@ void MathDecorationInset::metrics(MathStyles st)
                descent_ += dh_ + 2;
        }
 
-       if (deco_ == LM_not) {
+       if (key_->id == LM_not) {
                ascent_  += dh_;
                descent_ += dh_;
                dh_ = height();
@@ -56,34 +56,35 @@ void MathDecorationInset::draw(Painter & pain, int x, int y)
        xo(x);
        yo(x);
        xcell(0).draw(pain, x, y);
-       mathed_draw_deco(pain, x, y + dy_, width_, dh_, deco_);
+       mathed_draw_deco(pain, x, y + dy_, width_, dh_, key_->id);
 }
 
 
 void MathDecorationInset::write(ostream & os, bool fragile) const
 {
+       string name = key_->name;
        if (fragile &&
-                       (name_ == "overbrace" ||
-                        name_ == "underbrace" ||
-                        name_ == "overleftarrow" ||
-                        name_ == "overrightarrow"))
+                       (name == "overbrace" ||
+                        name == "underbrace" ||
+                        name == "overleftarrow" ||
+                        name == "overrightarrow"))
                os << "\\protect";
-       os << '\\' << name_;
+       os << '\\' << name;
 
-       if (deco_ == LM_not)
+       if (key_->id == LM_not)
                os << ' ';
        else
                os << '{';
 
        cell(0).write(os, fragile);  
 
-       if (deco_ != LM_not)
+       if (key_->id != LM_not)
                os << '}';
 }
 
 void MathDecorationInset::writeNormal(ostream & os) const
 {
-       os << "[" << name_ << " ";
+       os << "[" << key_->name << " ";
        cell(0).writeNormal(os);
        os << "] ";
 }
index d9bc68393076582ad591acebd5d14820784a64c3..cf90fb1df9a14dc3dd5c233c487aaa4c97ab164f 100644 (file)
 /** Decorations and accents over (below) a math object
     \author Alejandro Aguilar Sierra
  */
+
+struct latexkeys;
+
 class MathDecorationInset : public MathInset {
 public:
        ///
-       MathDecorationInset(string const & name, int);
+       explicit MathDecorationInset(latexkeys const *);
        ///
        MathInset * clone() const;
        ///
@@ -27,7 +30,7 @@ public:
        void writeNormal(std::ostream & os) const;
 private:
        ///
-       int deco_;
+       latexkeys const * key_;
        ///
        bool upper_;
        /// height of deco
index 4466879a5523a4c05b54a6e94f26c2fbe4224380..35cb29396438af4dd3e5d17bef123d121d20e192 100644 (file)
@@ -4,13 +4,14 @@
 
 #include "math_dotsinset.h"
 #include "mathed/support.h"
+#include "mathed/math_parser.h"
 #include "support/LOstream.h"
 
 using std::ostream;
 
 
-MathDotsInset::MathDotsInset(string const & name, int id)
-       : MathInset(0, name), code_(id)
+MathDotsInset::MathDotsInset(latexkeys const * key)
+       : key_(key)
 {}
 
 
@@ -22,12 +23,12 @@ MathInset * MathDotsInset::clone() const
 
 void MathDotsInset::draw(Painter & pain, int x, int y)
 {
-       mathed_draw_deco(pain, x + 2, y - dh_, width_ - 2, ascent_, code_);
-       if (code_ == LM_vdots || code_ == LM_ddots)
+       mathed_draw_deco(pain, x + 2, y - dh_, width_ - 2, ascent_, key_->id);
+       if (key_->id == LM_vdots || key_->id == LM_ddots)
                ++x;
-       if (code_ != LM_vdots)
+       if (key_->id != LM_vdots)
                --y;
-       mathed_draw_deco(pain, x + 2, y - dh_, width_ - 2, ascent_, code_);
+       mathed_draw_deco(pain, x + 2, y - dh_, width_ - 2, ascent_, key_->id);
 }
 
 
@@ -35,9 +36,9 @@ void MathDotsInset::metrics(MathStyles st)
 {
        size(st);
        mathed_char_dim(LM_TC_VAR, size(), 'M', ascent_, descent_, width_);
-       switch (code_) {
+       switch (key_->id) {
                case LM_ldots: dh_ = 0; break;
-               case LM_cdots: dh_ = ascent_/2; break;
+               case LM_cdots: dh_ = ascent_ / 2; break;
                case LM_vdots: width_ /= 2;
                case LM_ddots: dh_ = ascent_; break;
        }
@@ -46,11 +47,11 @@ void MathDotsInset::metrics(MathStyles st)
 
 void MathDotsInset::write(ostream & os, bool /* fragile */) const
 {
-       os << '\\' << name() << ' ';
+       os << '\\' << key_->name << ' ';
 }
 
 
 void MathDotsInset::writeNormal(ostream & os) const
 {
-       os << "[" << name() << "] ";
+       os << "[" << key_->name << "] ";
 }
index 9f0937a127a80535eba19c45026bcc6e3ddca5a9..cf8fb21fce830bb634c50a6ad153a605d882b08d 100644 (file)
@@ -9,13 +9,15 @@
 #pragma interface
 #endif
 
+struct latexkeys;
+
 /// The different kinds of ellipsis
 class MathDotsInset : public MathInset {
 public:
        ///
-       MathDotsInset(string const &, int);
+       explicit MathDotsInset(latexkeys const *);
        ///
-       MathInset *  clone() const;
+       MathInset * clone() const;
        ///
        void draw(Painter &, int, int);
        ///
@@ -28,6 +30,6 @@ protected:
        ///
        int dh_;
        ///
-       int code_;
+       latexkeys const * key_;
 };   
 #endif
index ab116755c4ce378488ecf24143b420f6e303926f..c18456063f73c69f00536d36f27f7526d30c9f9f 100644 (file)
@@ -20,6 +20,9 @@
 
 using std::endl;
 
+MathArray mathed_parse_cell(string const &);
+
+
 MathMacroTable::table_type MathMacroTable::macro_table;
 
 
@@ -67,6 +70,15 @@ MathMacroTemplate & MathMacroTable::provideTemplate(string const & name)
 }
 
 
+void MathMacroTable::createTemplate
+       (string const & name, int na, string const & text)
+{
+       MathMacroTemplate * t = new MathMacroTemplate(name, na);
+       t->cell(0) = mathed_parse_cell(text);
+       insertTemplate(t);
+}
+
+
 bool MathMacroTable::hasTemplate(string const & name)
 {
        builtinMacros();
@@ -90,27 +102,25 @@ void MathMacroTable::builtinMacros()
        built = true;
     
        lyxerr[Debug::MATHED] << "Building macros" << endl;
-    
+   
+/* 
        // This macro doesn't have arguments
        {
                MathMacroTemplate * t = new MathMacroTemplate("notin", 0);
-               MathDecorationInset * p = new MathDecorationInset("not", LM_not);
+               MathDecorationInset * p = new MathDecorationInset("not");
                p->cell(0).push_back(LM_in, LM_TC_SYMB);
                t->push_back(p);
                insertTemplate(t);
        }
-
-/*
-       // This macro doesn't have arguments
-       {
-               MathMacroTemplate & m = createTemplate("silentmult", 0);
-               istringstream is("\\cdot\0");
-               mathed_parser_file(is, 0);
-               MathMatrixInset * p = &m;
-       mathed_parse(m.array, p, 0);
-       }
 */
 
+       createTemplate("silentmult", 0, "\\cdot");
+       createTemplate("emptyset",   0, "\\not0");
+       createTemplate("notin",      0, "\\not\\in");
+
+
+
+/*
        {
                MathMacroTemplate * t = new MathMacroTemplate("emptyset", 0);
                MathDecorationInset * p = new MathDecorationInset("not", LM_not);
@@ -118,8 +128,10 @@ void MathMacroTable::builtinMacros()
                t->push_back(p);
                insertTemplate(t);
        }
+*/
 
        {
+
                MathMacroTemplate * t = new MathMacroTemplate("land", 0);
                t->push_back(LM_wedge, LM_TC_SYMB);
                insertTemplate(t);
index 3d3241640f12d751a0b0f4be1d084d4cba4d4dbf..68ea0494768daf60560abc0fd50102ab26251de6 100644 (file)
@@ -26,6 +26,8 @@ public:
        static bool hasTemplate(string const &);
        ///
        static MathMacro * cloneTemplate(string const &);
+       ///
+       static void createTemplate(string const &, int, string const &);
 private:
        ///
        static void builtinMacros();
index b855c0732b3aaa8c57ddcae5ef39f68d8cb4c128..8bc608ac66e3132fc1677f7b2004c297acba310e 100644 (file)
@@ -310,7 +310,7 @@ int yylex()
                        }
                        if (lexcode[c] == LexAlpha) {
                                yytext.erase();
-                               while (lexcode[c] == LexAlpha) {
+                               while (lexcode[c] == LexAlpha && yyis->good()) {
                                        yytext += c;
                                        c = getuchar(yyis);
                                }
@@ -512,9 +512,7 @@ void mathed_parse(MathArray & array, unsigned flags)
 
        ++plevel;
        while (t) {
-               //lyxerr << "t: " << t << " flags: " << flags << " i: " << yylval.i
-               //      << " TK_LIMIT " << LM_TK_LIMIT << "\n";
-                               
+               //lyxerr << "t: " << t << " flags: " << flags << " i: " << yylval.i << "\n";
                //      << " plevel: " << plevel << " ";
                //array.dump(lyxerr);
                //lyxerr << "\n";
@@ -647,7 +645,7 @@ void mathed_parse(MathArray & array, unsigned flags)
                        break;
 
                case LM_TK_DOTS:
-                       array.push_back(new MathDotsInset(yylval.l->name, yylval.l->id));
+                       array.push_back(new MathDotsInset(yylval.l));
                        break;
                
                case LM_TK_CHOOSE:
@@ -727,8 +725,7 @@ void mathed_parse(MathArray & array, unsigned flags)
 
                case LM_TK_DECORATION:
                {  
-                       MathDecorationInset * p
-                               = new MathDecorationInset(yylval.l->name, yylval.l->id);
+                       MathDecorationInset * p = new MathDecorationInset(yylval.l);
                        mathed_parse(p->cell(0), FLAG_ITEM);
                        array.push_back(p);
                        break;
@@ -805,7 +802,7 @@ void mathed_parse(MathArray & array, unsigned flags)
                        //   Search for the end command. 
                        do {
                                t = yylex();
-                       } while (t != LM_TK_END && t);
+                       } while (yyis->good() && t != LM_TK_END && t);
                } else
                        t = yylex();
 
@@ -815,6 +812,18 @@ void mathed_parse(MathArray & array, unsigned flags)
 
 }
 
+
+MathArray mathed_parse_cell(string const & str)
+{
+       istringstream is(str.c_str());
+       yyis     = &is;
+       yylineno = 0;
+       MathArray ar;
+       mathed_parse(ar, 0);
+       return ar;
+}
+
+
 MathInset * mathed_parse(string const & str)
 {
        istringstream is(str.c_str());