]> git.lyx.org Git - lyx.git/commitdiff
fix random crashes
authorAndré Pönitz <poenitz@gmx.net>
Mon, 28 Apr 2003 08:44:56 +0000 (08:44 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Mon, 28 Apr 2003 08:44:56 +0000 (08:44 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6867 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/ChangeLog
src/mathed/formula.C
src/mathed/formula.h
src/mathed/math_gridinset.C
src/mathed/math_hullinset.C
src/mathed/math_hullinset.h
src/mathed/math_inset.C
src/mathed/math_inset.h
src/mathed/math_parser.C

index 899cf2c1c819e136ab0646777846328d69ef2fb5..b465c713f2ef881900a0a3971173b706c5192902 100644 (file)
@@ -1,3 +1,4 @@
+
 2003-04-14  Angus Leeming  <leeming@lyx.org>
 
        * math_fboxinset.C:
index 1d7119fc13b8caed3cd923ea86ba1fca1a01ce84..4154cb80cae71eb78a158cb545e04e7d6842c2e5 100644 (file)
 #include "graphics/PreviewedInset.h"
 #include "graphics/PreviewImage.h"
 
-#include <fstream>
-
 
 using std::ostream;
-using std::ifstream;
-using std::istream;
-using std::pair;
-using std::endl;
 using std::vector;
-using std::getline;
 
 
 class InsetFormula::PreviewImpl : public grfx::PreviewedInset {
@@ -78,10 +71,13 @@ private:
 
 
 
-InsetFormula::InsetFormula()
+InsetFormula::InsetFormula(bool chemistry)
        : par_(MathAtom(new MathHullInset)),
          preview_(new PreviewImpl(*this))
-{}
+{
+       if (chemistry)
+               mutate("chemistry");
+}
 
 
 InsetFormula::InsetFormula(InsetFormula const & other)
@@ -182,6 +178,19 @@ int InsetFormula::docbook(Buffer const * buf, ostream & os, bool) const
 void InsetFormula::read(Buffer const *, LyXLex & lex)
 {
        mathed_parse_normal(par_, lex);
+       // remove extra 'mathrm' for chemistry stuff.
+       // will be re-added on write
+       if (par_->asHullInset()->getType() =="chemistry")  {
+               lyxerr << "this is chemistry\n";
+               if (par_->cell(0).size() == 1) {
+                       lyxerr << "this is size 1\n";
+           if (par_->cell(0)[0]->asFontInset()) {
+                               lyxerr << "this is a font inset \n";
+                               lyxerr << "replacing " << par_.nucleus()->cell(0) << 
+                                       " with " << par_->cell(0)[0]->cell(0) << "\n";
+                       }
+               }
+       }
        metrics();
 }
 
@@ -293,12 +302,10 @@ int InsetFormula::width(BufferView * bv, LyXFont const & font) const
 }
 
 
-/*
 void InsetFormula::mutate(string const & type)
 {
        par_.nucleus()->mutate(type);
 }
-*/
 
 
 //
index 3c7381ee24a172e7fac38c634fcfe75a5b368da5..cf45606dadbf05caf3ce9a9f02b78b5c8b6aabcb 100644 (file)
@@ -25,7 +25,7 @@
 class InsetFormula : public InsetFormulaBase {
 public:
        ///
-       InsetFormula();
+       InsetFormula(bool chemistry = false);
        ///
        explicit InsetFormula(BufferView *);
        ///
@@ -75,7 +75,7 @@ public:
        ///
        void addPreview(grfx::PreviewLoader &) const;
        ///
-       //void mutate(string const & type);
+       void mutate(string const & type);
 
 private:
        /// available in AMS only?
index ccf1c7b4863b5ce757b8d76ad7a67c7fd76bc2b7..8f1a72a1e1df6e10cf43612ca712345ce1f37114 100644 (file)
@@ -211,13 +211,13 @@ char MathGridInset::valign() const
 
 MathGridInset::col_type MathGridInset::ncols() const
 {
-       return colinfo_.size() - 1;
+       return colinfo_.size();
 }
 
 
 MathGridInset::row_type MathGridInset::nrows() const
 {
-       return rowinfo_.size() - 1;
+       return rowinfo_.size();
 }
 
 
@@ -263,12 +263,10 @@ void MathGridInset::metrics(MetricsInfo & mi) const
                rowinfo_[row].descent_ = desc;
        }
        rowinfo_[0].ascent_       += hlinesep() * rowinfo_[0].lines_;
-       rowinfo_[nrows()].ascent_  = 0;
-       rowinfo_[nrows()].descent_ = 0;
 
        // compute vertical offsets
        rowinfo_[0].offset_ = 0;
-       for (row_type row = 1; row <= nrows(); ++row) {
+       for (row_type row = 1; row < nrows(); ++row) {
                rowinfo_[row].offset_  =
                        rowinfo_[row - 1].offset_  +
                        rowinfo_[row - 1].descent_ +
@@ -290,7 +288,7 @@ void MathGridInset::metrics(MetricsInfo & mi) const
                default:
                        h = rowinfo_[nrows() - 1].offset_ / 2;
        }
-       for (row_type row = 0; row <= nrows(); ++row)
+       for (row_type row = 0; row < nrows(); ++row)
                rowinfo_[row].offset_ -= h;
 
 
@@ -301,11 +299,10 @@ void MathGridInset::metrics(MetricsInfo & mi) const
                        wid = max(wid, cell(index(row, col)).width());
                colinfo_[col].width_ = wid;
        }
-       colinfo_[ncols()].width_  = 0;
 
        // compute horizontal offsets
        colinfo_[0].offset_ = border();
-       for (col_type col = 1; col <= ncols(); ++col) {
+       for (col_type col = 1; col < ncols(); ++col) {
                colinfo_[col].offset_ =
                        colinfo_[col - 1].offset_ +
                        colinfo_[col - 1].width_ +
@@ -315,19 +312,19 @@ void MathGridInset::metrics(MetricsInfo & mi) const
        }
 
 
-       dim_.w   =   colinfo_[ncols() - 1].offset_
+       dim_.w =   colinfo_[ncols() - 1].offset_
                       + colinfo_[ncols() - 1].width_
-                + vlinesep() * colinfo_[ncols()].lines_
+                //+ vlinesep() * colinfo_[ncols()].lines_
                       + border();
 
-       dim_.a  = - rowinfo_[0].offset_
+       dim_.a = - rowinfo_[0].offset_
                       + rowinfo_[0].ascent_
-                + hlinesep() * rowinfo_[0].lines_
+                + hlinesep() * rowinfo_[0].lines_
                       + border();
 
        dim_.d =   rowinfo_[nrows() - 1].offset_
                       + rowinfo_[nrows() - 1].descent_
-                + hlinesep() * rowinfo_[nrows()].lines_
+                //+ hlinesep() * rowinfo_[nrows()].lines_
                       + border();
 
 
@@ -389,14 +386,14 @@ void MathGridInset::draw(PainterInfo & pi, int x, int y) const
        for (idx_type idx = 0; idx < nargs(); ++idx)
                cell(idx).draw(pi, x + cellXOffset(idx), y + cellYOffset(idx));
 
-       for (row_type row = 0; row <= nrows(); ++row)
+       for (row_type row = 0; row < nrows(); ++row)
                for (int i = 0; i < rowinfo_[row].lines_; ++i) {
                        int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
                                - i * hlinesep() - hlinesep()/2 - rowsep()/2;
                        pi.pain.line(x + 1, yy, x + width() - 1, yy);
                }
 
-       for (col_type col = 0; col <= ncols(); ++col)
+       for (col_type col = 0; col < ncols(); ++col)
                for (int i = 0; i < colinfo_[col].lines_; ++i) {
                        int xx = x + colinfo_[col].offset_
                                - i * vlinesep() - vlinesep()/2 - colsep()/2;
@@ -430,7 +427,7 @@ void MathGridInset::metricsT(TextMetricsInfo const & mi) const
 
        // compute vertical offsets
        rowinfo_[0].offset_ = 0;
-       for (row_type row = 1; row <= nrows(); ++row) {
+       for (row_type row = 1; row < nrows(); ++row) {
                rowinfo_[row].offset_  =
                        rowinfo_[row - 1].offset_  +
                        rowinfo_[row - 1].descent_ +
@@ -452,7 +449,7 @@ void MathGridInset::metricsT(TextMetricsInfo const & mi) const
                default:
                        h = rowinfo_[nrows() - 1].offset_ / 2;
        }
-       for (row_type row = 0; row <= nrows(); ++row)
+       for (row_type row = 0; row < nrows(); ++row)
                rowinfo_[row].offset_ -= h;
 
 
@@ -467,7 +464,7 @@ void MathGridInset::metricsT(TextMetricsInfo const & mi) const
 
        // compute horizontal offsets
        colinfo_[0].offset_ = border();
-       for (col_type col = 1; col <= ncols(); ++col) {
+       for (col_type col = 1; col < ncols(); ++col) {
                colinfo_[col].offset_ =
                        colinfo_[col - 1].offset_ +
                        colinfo_[col - 1].width_ +
@@ -908,12 +905,12 @@ void MathGridInset::write(WriteStream & os) const
                if (!emptyline && row + 1 < nrows())
                        os << "\n";
        }
-       string const s = verboseHLine(rowinfo_[nrows()].lines_);
-       if (!s.empty() && s != " ") {
-               if (os.fragile())
-                       os << "\\protect";
-               os << "\\\\" << s;
-       }
+       //string const s = verboseHLine(rowinfo_[nrows()].lines_);
+       //if (!s.empty() && s != " ") {
+       //      if (os.fragile())
+       //              os << "\\protect";
+       //      os << "\\\\" << s;
+       //}
 }
 
 
index c1271901393dd49cc4e6ac1c9086f225e35e73d4..ad5080ffc02b112ff700bdfeee05080561168ef4 100644 (file)
@@ -69,15 +69,16 @@ namespace {
        {
                if (s == "none")      return 0;
                if (s == "simple")    return 1;
-               if (s == "equation")  return 2;
-               if (s == "eqnarray")  return 3;
-               if (s == "align")     return 4;
-               if (s == "alignat")   return 5;
-               if (s == "xalignat")  return 6;
-               if (s == "xxalignat") return 7;
-               if (s == "multline")  return 8;
-               if (s == "gather")    return 9;
-               if (s == "flalign")   return 10;
+               if (s == "chemistry") return 2;
+               if (s == "equation")  return 3;
+               if (s == "eqnarray")  return 4;
+               if (s == "align")     return 5;
+               if (s == "alignat")   return 6;
+               if (s == "xalignat")  return 7;
+               if (s == "xxalignat") return 8;
+               if (s == "multline")  return 9;
+               if (s == "gather")    return 10;
+               if (s == "flalign")   return 11;
                lyxerr << "unknown hull type '" << s << "'\n";
                return 0;
        }
@@ -162,6 +163,8 @@ char const * MathHullInset::standardFont() const
 {
        if (type_ == "none")
                return "lyxnochange";
+       if (type_ == "chemistry")
+               return "mathrm";
        return "mathnormal";
 }
 
@@ -290,7 +293,7 @@ bool MathHullInset::ams() const
 
 bool MathHullInset::display() const
 {
-       return type_ != "simple" && type_ != "none";
+       return type_ != "simple" && type_ != "none" && type_ != "chemistry";
 }
 
 
@@ -306,6 +309,8 @@ bool MathHullInset::numberedType() const
 {
        if (type_ == "none")
                return false;
+       if (type_ == "chemistry")
+               return false;
        if (type_ == "simple")
                return false;
        if (type_ == "xxalignat")
@@ -348,6 +353,9 @@ void MathHullInset::header_write(WriteStream & os) const
                        os << ' ';
        }
 
+       else if (type_ == "chemistry")
+               os << "$\\mathrm{";
+
        else if (type_ == "equation") {
                if (n)
                        os << "\\begin{equation" << star(n) << "}\n";
@@ -382,6 +390,9 @@ void MathHullInset::footer_write(WriteStream & os) const
        else if (type_ == "simple")
                os << '$';
 
+       else if (type_ == "chemistry")
+               os << "}$";
+
        else if (type_ == "equation")
                if (n)
                        os << "\\end{equation" << star(n) << "}\n";
@@ -495,22 +506,22 @@ void MathHullInset::mutate(string const & newtype)
                // done
        }
 
-       else if (type_ == "none") {
-               setType("simple");
+       else if (newtype == "none" || newtype == "chemistry") {
+               mutate("simple");
                numbered(0, false);
-               mutate(newtype);
        }
 
-       else if (type_ == "simple") {
-               if (newtype == "none") {
-                       setType("none");
-               } else {
-                       setType("equation");
+       else if (newtype == "simple") {
+               if (type_ != "none" && type_ != "chemistry") {
+                       mutate("equation");
                        numbered(0, false);
-                       mutate(newtype);
                }
        }
 
+       else if (newtype == "equation" && smaller(type_, newtype)) {
+               numbered(0, false);
+       }
+
        else if (type_ == "equation") {
                if (smaller(newtype, type_)) {
                        setType("simple");
@@ -614,6 +625,8 @@ void MathHullInset::mutate(string const & newtype)
                lyxerr << "mutation from '" << type_
                                         << "' to '" << newtype << "' not implemented" << endl;
        }
+
+       setType(newtype);
 }
 
 
@@ -842,3 +855,11 @@ dispatch_result MathHullInset::dispatch
        }
        return UNDISPATCHED;
 }
+
+
+string MathHullInset::fileInsetLabel() const
+{
+       if (type_ == "chemistry")
+               return "Chemistry";
+       return "Formula";
+}
index 3beaa30e4f0f887b5368a27eb22aff3413cf5a9c..7b3e407e42567e81c3060f6b8e2898f186db6158 100644 (file)
@@ -79,6 +79,8 @@ public:
        ///
        bool idxLast(idx_type &, pos_type &) const;
 
+       ///
+       string fileInsetLabel() const;
        ///
        void write(WriteStream & os) const;
        ///
index 7b4fd1fdb80ec61bb65d08048e06a3178b900042..aa4493987bba941a6eda7120f8f01088f15b602e 100644 (file)
@@ -276,7 +276,7 @@ int MathInset::docbook(std::ostream &, bool) const
 
 string const & MathInset::getType() const
 {
-       static string t("none");
+       static string const t("none");
        return t;
 }
 
@@ -311,3 +311,8 @@ ostream & operator<<(ostream & os, MathAtom const & at)
        return os;
 }
 
+
+string MathInset::fileInsetLabel() const
+{
+       return "Formula";
+}
index 2bd1a232330fc5fb0d8be22a503b3805e9b37116..19ebb970c82b156e75be5d27d0e54c3e07a069de 100644 (file)
@@ -299,7 +299,7 @@ public:
        /// change type
        virtual void mutate(string const &) {}
        /// how is the inset called in the .lyx file?
-       virtual string fileInsetLabel() const { return "Formula"; }
+       virtual string fileInsetLabel() const;
        /// usually the latex name
        virtual string name() const;
 
index 57d04f882ec19621f9023277c359b605ae4dc595..b7601e448ed22446251c3e45ea6e9d48901385f8 100644 (file)
@@ -1213,10 +1213,10 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
                                MathAtom at = createMathInset(t.cs());
                                MathInset::mode_type m = mode;
                                //if (m == MathInset::UNDECIDED_MODE)
-                               lyxerr << "default creation: m1: " << m << "\n";
+                               //lyxerr << "default creation: m1: " << m << "\n";
                                if (at->currentMode() != MathInset::UNDECIDED_MODE)
                                        m = at->currentMode();
-                               lyxerr << "default creation: m2: " << m << "\n";
+                               //lyxerr << "default creation: m2: " << m << "\n";
                                MathInset::idx_type start = 0;
                                // this fails on \bigg[...\bigg]
                                //MathArray opt;