]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_hullinset.C
oh well
[lyx.git] / src / mathed / math_hullinset.C
index c84ad3f83d0fa68e651ecf8d3aeeeb5a583c5fa1..8e52adb9e0b86949f9e2d57e963cf49a760a706a 100644 (file)
@@ -1,16 +1,25 @@
+#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 "textpainter.h"
+#include "Lsstream.h"
 #include "LaTeXFeatures.h"
-#include "math_mathmlstream.h"
+#include "support/LAssert.h"
 
+#include <vector>
+
+using std::vector;
+using std::max;
+using std::endl;
 
 namespace {
 
@@ -32,7 +41,7 @@ namespace {
 
        // returns position of first relation operator in the array
        // used for "intelligent splitting"
-       int firstRelOp(MathArray const & ar)
+       MathArray::size_type firstRelOp(MathArray const & ar)
        {
                for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it)
                        if ((*it)->isRelOp())
@@ -58,7 +67,7 @@ namespace {
                if (s == "multline")  return LM_OT_MULTLINE;
                if (s == "gather")    return LM_OT_GATHER;
                return LM_OT_SIMPLE;
-       }       
+       }
 
 
        string normalName(MathInsetTypes t)
@@ -76,7 +85,7 @@ namespace {
                        default: break;
                }
                return "unknown";
-       }       
+       }
 
 } // end anon namespace
 
@@ -95,6 +104,13 @@ MathHullInset::MathHullInset(MathInsetTypes t)
 }
 
 
+MathHullInset::MathHullInset(MathInsetTypes t, MathGridInset const & grid)
+       : MathGridInset(grid), objtype_(t), nonum_(1), label_(1)
+{
+       setDefaults();
+}
+
+
 MathHullInset::MathHullInset(MathInsetTypes t, col_type cols)
        : MathGridInset(cols, 1), objtype_(t), nonum_(1), label_(1)
 {
@@ -136,7 +152,7 @@ int MathHullInset::defaultColSpace(col_type col)
                        return (col & 1) ? 40 : 0;
                default:;
        }
-       return 10;
+       return 0;
 }
 
 
@@ -151,12 +167,13 @@ void MathHullInset::metrics(MathMetricsInfo const & mi) const
        if (display()) {
                ascent_  += 12;
                descent_ += 12;
-       }       
+       }
 
        if (numberedType()) {
+               whichFont(mi_.font, LM_TC_BF, mi_);
                int l = 0;
                for (row_type row = 0; row < nrows(); ++row)
-                       l = std::max(l, mathed_string_width(LM_TC_BF, mi_, nicelabel(row)));
+                       l = max(l, mathed_string_width(mi_.font, nicelabel(row)));
 
                if (l)
                        width_ += 30 + l;
@@ -165,9 +182,9 @@ void MathHullInset::metrics(MathMetricsInfo const & mi) const
        // make it at least as high as the current font
        int asc = 0;
        int des = 0;
-       math_font_max_dim(LM_TC_TEXTRM, mi_, asc, des);
-       ascent_  = std::max(ascent_,  asc);
-       descent_ = std::max(descent_, des);
+       math_font_max_dim(mi_.font, asc, des);
+       ascent_  = max(ascent_,  asc);
+       descent_ = max(descent_, des);
 }
 
 
@@ -179,27 +196,63 @@ void MathHullInset::draw(Painter & pain, int x, int y) const
                int const xx = x + colinfo_.back().offset_ + colinfo_.back().width_ + 20;
                for (row_type row = 0; row < nrows(); ++row) {
                        int const yy = y + rowinfo_[row].offset_;
-                       drawStr(pain, LM_TC_BF, mi_, xx, yy, nicelabel(row));
+                       drawStr(pain, mi_.font, xx, yy, nicelabel(row));
                }
        }
 }
 
 
+void MathHullInset::metricsT(TextMetricsInfo const &) const
+{
+#if 0
+       if (display()) {
+               MathGridInset::metricsT(mi);
+       } else
+#endif
+       {
+               ostringstream os;
+               WriteStream wi(os, false, true);
+               write(wi);
+               width_   = os.str().size();
+               ascent_  = 1;
+               descent_ = 0;
+       }
+}
+
+
+void MathHullInset::drawT(TextPainter & pain, int x, int y) const
+{
+#if 0
+       if (display()) {
+               MathGridInset::drawT(pain, x, y);
+       } else
+#endif
+       {
+               ostringstream os;
+               WriteStream wi(os, false, true);
+               write(wi);
+               pain.draw(x, y, os.str().c_str());
+       }
+}
+
+
 string MathHullInset::label(row_type row) const
 {
+       row_type n = nrows();
+       lyx::Assert(row < n);
        return label_[row];
 }
 
 
 void MathHullInset::label(row_type row, string const & label)
 {
-       label_[row] = label; 
+       label_[row] = label;
 }
 
 
 void MathHullInset::numbered(row_type row, bool num)
 {
-       nonum_[row] = !num; 
+       nonum_[row] = !num;
 }
 
 
@@ -212,14 +265,15 @@ bool MathHullInset::numbered(row_type row) const
 bool MathHullInset::ams() const
 {
        return true;
-
-       return 
+/*
+       return
                objtype_ == LM_OT_ALIGN ||
                objtype_ == LM_OT_MULTLINE ||
                objtype_ == LM_OT_GATHER ||
                objtype_ == LM_OT_ALIGNAT ||
                objtype_ == LM_OT_XALIGNAT ||
                objtype_ == LM_OT_XXALIGNAT;
+*/
 }
 
 
@@ -229,9 +283,9 @@ bool MathHullInset::display() const
 }
 
 
-std::vector<string> const MathHullInset::getLabelList() const
+vector<string> const MathHullInset::getLabelList() const
 {
-       std::vector<string> res;
+       vector<string> res;
        for (row_type row = 0; row < nrows(); ++row)
                if (!label_[row].empty() && nonum_[row] != 1)
                        res.push_back(label_[row]);
@@ -253,7 +307,7 @@ bool MathHullInset::numberedType() const
 void MathHullInset::validate(LaTeXFeatures & features) const
 {
        if (ams())
-               features.require("amsstyle");
+               features.require("amsmath");
 
 
        // Validation is necessary only if not using AMS math.
@@ -281,9 +335,9 @@ void MathHullInset::header_write(WriteStream & os) const
 
                case LM_OT_EQUATION:
                        if (n)
-                               os << "\\begin{equation" << star(n) << "}\n"; 
+                               os << "\\begin{equation" << star(n) << "}\n";
                        else
-                               os << "\\[\n"; 
+                               os << "\\[\n";
                        break;
 
                case LM_OT_EQNARRAY:
@@ -305,7 +359,7 @@ void MathHullInset::header_write(WriteStream & os) const
                        break;
 
                case LM_OT_XXALIGNAT:
-                       os << "\\begin{xxalignat}" 
+                       os << "\\begin{xxalignat}"
                           << "{" << static_cast<unsigned int>(ncols()/2) << "}\n";
                        break;
 
@@ -334,9 +388,9 @@ void MathHullInset::footer_write(WriteStream & os) const
 
                case LM_OT_EQUATION:
                        if (n)
-                               os << "\\end{equation" << star(n) << "}\n"; 
+                               os << "\\end{equation" << star(n) << "}\n";
                        else
-                               os << "\\]\n"; 
+                               os << "\\]\n";
                        break;
 
                case LM_OT_EQNARRAY:
@@ -373,7 +427,7 @@ void MathHullInset::footer_write(WriteStream & os) const
 }
 
 
-void MathHullInset::addRow(row_type row) 
+void MathHullInset::addRow(row_type row)
 {
        nonum_.insert(nonum_.begin() + row + 1, !numberedType());
        label_.insert(label_.begin() + row + 1, string());
@@ -389,7 +443,7 @@ void MathHullInset::appendRow()
 }
 
 
-void MathHullInset::delRow(row_type row) 
+void MathHullInset::delRow(row_type row)
 {
        MathGridInset::delRow(row);
        nonum_.erase(nonum_.begin() + row);
@@ -507,7 +561,7 @@ void MathHullInset::mutate(MathInsetTypes newtype)
                                        setType(LM_OT_SIMPLE);
                                        break;
 
-                               case LM_OT_ALIGN: 
+                               case LM_OT_ALIGN:
                                case LM_OT_ALIGNAT:
                                case LM_OT_XALIGNAT:
                                case LM_OT_XXALIGNAT: {
@@ -515,7 +569,7 @@ void MathHullInset::mutate(MathInsetTypes newtype)
                                        MathGridInset::addCol(1);
 
                                        // split it "nicely"
-                                       pos_type pos = firstRelOp(cell(0));     
+                                       pos_type pos = firstRelOp(cell(0));
                                        cell(1) = cell(0);
                                        cell(0).erase(pos, cell(0).size());
                                        cell(1).erase(0, pos);
@@ -530,7 +584,7 @@ void MathHullInset::mutate(MathInsetTypes newtype)
                                        MathGridInset::addCol(1);
 
                                        // split it "nicely" on the firest relop
-                                       pos_type pos = firstRelOp(cell(0));     
+                                       pos_type pos = firstRelOp(cell(0));
                                        cell(1) = MathArray(cell(0), pos, cell(0).size());
                                        cell(0).erase(pos, cell(0).size());
 
@@ -599,7 +653,7 @@ void MathHullInset::mutate(MathInsetTypes newtype)
                                        setType(LM_OT_EQNARRAY);
                                        mutate(newtype);
                                        break;
-                               
+
                                case LM_OT_ALIGNAT:
                                case LM_OT_XALIGNAT:
                                case LM_OT_XXALIGNAT:
@@ -608,7 +662,8 @@ void MathHullInset::mutate(MathInsetTypes newtype)
 
                                default:
                                        lyxerr << "mutation from '" << getType()
-                                               << "' to '" << newtype << "' not implemented\n";
+                                               << "' to '" << newtype << "' not implemented"
+                                              << endl;
                                        break;
                        }
                        break;
@@ -620,7 +675,8 @@ void MathHullInset::mutate(MathInsetTypes newtype)
                                        break;
                                default:
                                        lyxerr << "mutation from '" << getType()
-                                               << "' to '" << newtype << "' not implemented\n";
+                                               << "' to '" << newtype << "' not implemented"
+                                              << endl;
                                        break;
                        }
 
@@ -631,42 +687,45 @@ 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);
+       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();
+               for (col_type col = 0; col < ncols(); ++col)
+                       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);
+       footer_write(os);
 }
 
 
 void MathHullInset::normalize(NormalStream & os) const
 {
-       os << "[formula " << normalName(getType()).c_str() << " ";
+       os << "[formula " << normalName(getType()) << " ";
        MathGridInset::normalize(os);
        os << "] ";
 }
@@ -678,3 +737,8 @@ void MathHullInset::mathmlize(MathMLStream & os) const
 }
 
 
+void MathHullInset::check() const
+{
+       lyx::Assert(nonum_.size() == nrows());
+       lyx::Assert(label_.size() == nrows());
+}