]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_hullinset.C
forward search in math insets. ugly. seems to work. don't ask why.
[lyx.git] / src / mathed / math_hullinset.C
index 8cb6fc62c3151b5d8b85c03091e3fc468904c9af..fa7bdd36ce8733793495f3e09b704cdc169a3b64 100644 (file)
@@ -1,16 +1,21 @@
+#include <config.h>
+
 #ifdef __GNUG__
 #pragma implementation
 #endif
 
-#include <vector>
-
 #include "math_hullinset.h"
+#include "math_mathmlstream.h"
+#include "math_streamstr.h"
 #include "math_support.h"
 #include "debug.h"
 #include "Painter.h"
 #include "LaTeXFeatures.h"
-#include "math_mathmlstream.h"
+#include "support/LAssert.h"
+
+#include <vector>
 
+using std::endl;
 
 namespace {
 
@@ -136,7 +141,7 @@ int MathHullInset::defaultColSpace(col_type col)
                        return (col & 1) ? 40 : 0;
                default:;
        }
-       return 10;
+       return 0;
 }
 
 
@@ -185,14 +190,10 @@ void MathHullInset::draw(Painter & pain, int x, int y) const
 }
 
 
-void MathHullInset::mathmlize(MathMLStream & os) const
-{
-       MathGridInset::mathmlize(os);
-}
-
-
 string MathHullInset::label(row_type row) const
 {
+       row_type n = nrows();
+       lyx::Assert(row < n);
        return label_[row];
 }
 
@@ -258,21 +259,23 @@ bool MathHullInset::numberedType() const
 
 void MathHullInset::validate(LaTeXFeatures & features) const
 {
-       features.amsstyle = ams();
+       if (ams())
+               features.require("amsstyle");
+
 
        // Validation is necessary only if not using AMS math.
        // To be safe, we will always run mathedvalidate.
        //if (features.amsstyle)
        //  return;
 
-       features.boldsymbol = true;
+       features.require("boldsymbol");
        //features.binom      = true;
 
        MathNestInset::validate(features);
 }
 
 
-void MathHullInset::header_write(std::ostream & os) const
+void MathHullInset::header_write(WriteStream & os) const
 {
        bool n = numberedType();
 
@@ -299,15 +302,18 @@ void MathHullInset::header_write(std::ostream & os) const
                        break;
 
                case LM_OT_ALIGNAT:
-                       os << "\\begin{alignat" << star(n) << "}" << "{" << ncols()/2 << "}\n";
+                       os << "\\begin{alignat" << star(n) << "}"
+                         << "{" << static_cast<unsigned int>(ncols()/2) << "}\n";
                        break;
 
                case LM_OT_XALIGNAT:
-                       os << "\\begin{xalignat" << star(n) << "}" << "{" << ncols()/2 << "}\n";
+                       os << "\\begin{xalignat" << star(n) << "}"
+                          << "{" << static_cast<unsigned int>(ncols()/2) << "}\n";
                        break;
 
                case LM_OT_XXALIGNAT:
-                       os << "\\begin{xxalignat}" << "{" << ncols()/2 << "}\n";
+                       os << "\\begin{xxalignat}" 
+                          << "{" << static_cast<unsigned int>(ncols()/2) << "}\n";
                        break;
 
                case LM_OT_MULTLINE:
@@ -324,7 +330,7 @@ void MathHullInset::header_write(std::ostream & os) const
 }
 
 
-void MathHullInset::footer_write(std::ostream & os) const
+void MathHullInset::footer_write(WriteStream & os) const
 {
        bool n = numberedType();
 
@@ -532,14 +538,12 @@ void MathHullInset::mutate(MathInsetTypes newtype)
 
                                        // split it "nicely" on the firest relop
                                        pos_type pos = firstRelOp(cell(0));     
-                                       cell(1) = cell(0);
+                                       cell(1) = MathArray(cell(0), pos, cell(0).size());
                                        cell(0).erase(pos, cell(0).size());
-                                       cell(1).erase(0, pos);
 
                                        if (cell(1).size()) {
-                                               cell(2) = cell(1);
+                                               cell(2) = MathArray(cell(1), 1, cell(1).size());
                                                cell(1).erase(1, cell(1).size());
-                                               cell(2).erase(0);
                                        }
 
                                        setType(LM_OT_EQNARRAY);
@@ -611,7 +615,8 @@ void MathHullInset::mutate(MathInsetTypes newtype)
 
                                default:
                                        lyxerr << "mutation from '" << getType()
-                                               << "' to '" << newtype << "' not implemented\n";
+                                               << "' to '" << newtype << "' not implemented"
+                                              << endl;
                                        break;
                        }
                        break;
@@ -623,7 +628,8 @@ void MathHullInset::mutate(MathInsetTypes newtype)
                                        break;
                                default:
                                        lyxerr << "mutation from '" << getType()
-                                               << "' to '" << newtype << "' not implemented\n";
+                                               << "' to '" << newtype << "' not implemented"
+                                              << endl;
                                        break;
                        }
 
@@ -634,44 +640,60 @@ void MathHullInset::mutate(MathInsetTypes newtype)
                                        break;
                                default:
                                        lyxerr << "mutation from '" << getType()
-                                               << "' to '" << newtype << "' not implemented\n";
+                                               << "' to '" << newtype << "' not implemented"
+                                              << endl;
                                        break;
                        }
 
                default:
                        lyxerr << "mutation from '" << getType()
-                               << "' to '" << newtype << "' not implemented\n";
+                              << "' to '" << newtype << "' not implemented"
+                              << endl;
+                       break;
        }
 }
 
 
 void MathHullInset::write(WriteStream & os) const
 {
-  header_write(os.os);
-
+       header_write(os);
+       
        bool n = numberedType();
-
+       
        for (row_type row = 0; row < nrows(); ++row) {
                for (col_type col = 0; col < ncols(); ++col) 
-                       os << cell(index(row, col)) << eocString(col).c_str();
+                       os << cell(index(row, col)) << eocString(col);
                if (n) {
                        if (!label_[row].empty())
-                               os << "\\label{" << label_[row].c_str() << "}";
+                               os << "\\label{" << label_[row] << "}";
                        if (nonum_[row])
                                os << "\\nonumber ";
                }
-               os << eolString(row).c_str();
+               os << eolString(row);
        }
-
-  footer_write(os.os);
+       
+       footer_write(os);
 }
 
 
 void MathHullInset::normalize(NormalStream & os) const
 {
-       os << "[formula " << normalName(getType()).c_str() << " ";
+       os << "[formula " << normalName(getType()) << " ";
        MathGridInset::normalize(os);
        os << "] ";
 }
 
 
+void MathHullInset::mathmlize(MathMLStream & os) const
+{
+       MathGridInset::mathmlize(os);
+}
+
+
+void MathHullInset::check() const
+{
+       lyx::Assert(nonum_.size() == nrows());
+       lyx::Assert(label_.size() == nrows());
+}
+
+