]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_hullinset.C
oh well
[lyx.git] / src / mathed / math_hullinset.C
index 8e69d2bfb0e0f964a0a2b69bd1d3bfd7fcbb3452..8e52adb9e0b86949f9e2d57e963cf49a760a706a 100644 (file)
 #include "math_support.h"
 #include "debug.h"
 #include "Painter.h"
+#include "textpainter.h"
+#include "Lsstream.h"
 #include "LaTeXFeatures.h"
 #include "support/LAssert.h"
 
 #include <vector>
 
+using std::vector;
+using std::max;
 using std::endl;
 
 namespace {
@@ -37,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())
@@ -63,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)
@@ -81,7 +85,7 @@ namespace {
                        default: break;
                }
                return "unknown";
-       }       
+       }
 
 } // end anon namespace
 
@@ -100,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)
 {
@@ -156,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;
@@ -170,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);
 }
 
 
@@ -184,12 +196,46 @@ 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();
@@ -200,13 +246,13 @@ string MathHullInset::label(row_type row) const
 
 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;
 }
 
 
@@ -220,7 +266,7 @@ bool MathHullInset::ams() const
 {
        return true;
 /*
-       return 
+       return
                objtype_ == LM_OT_ALIGN ||
                objtype_ == LM_OT_MULTLINE ||
                objtype_ == LM_OT_GATHER ||
@@ -237,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]);
@@ -261,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.
@@ -289,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:
@@ -313,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;
 
@@ -342,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:
@@ -381,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());
@@ -397,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);
@@ -515,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: {
@@ -523,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);
@@ -538,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());
 
@@ -607,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:
@@ -658,11 +704,11 @@ void MathHullInset::mutate(MathInsetTypes newtype)
 void MathHullInset::write(WriteStream & os) const
 {
        header_write(os);
-       
+
        bool n = numberedType();
-       
+
        for (row_type row = 0; row < nrows(); ++row) {
-               for (col_type col = 0; col < ncols(); ++col) 
+               for (col_type col = 0; col < ncols(); ++col)
                        os << cell(index(row, col)) << eocString(col);
                if (n) {
                        if (!label_[row].empty())
@@ -672,7 +718,7 @@ void MathHullInset::write(WriteStream & os) const
                }
                os << eolString(row);
        }
-       
+
        footer_write(os);
 }
 
@@ -696,5 +742,3 @@ void MathHullInset::check() const
        lyx::Assert(nonum_.size() == nrows());
        lyx::Assert(label_.size() == nrows());
 }
-
-