]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_parboxinset.C
Compile fix gcc 2.95 + stlport
[lyx.git] / src / mathed / math_parboxinset.C
index ea7ddd55ddff7945ded45cfd4ff8dc76d8c61376..176d34988f1253a80b6768f86be010162fcff17f 100644 (file)
@@ -1,22 +1,37 @@
+/**
+ * \file math_parboxinset.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author André Pönitz
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
 
 #include "math_parboxinset.h"
+#include "math_data.h"
 #include "math_mathmlstream.h"
 #include "math_streamstr.h"
-#include "lyxlength.h"
 #include "debug.h"
 
 
+using std::string;
+using std::auto_ptr;
+using std::endl;
+
+
 MathParboxInset::MathParboxInset()
-       : MathNestInset(1), lyx_width_(0), tex_width_("0mm"),
-         position_('c')
+       : lyx_width_(0), tex_width_("0mm"), position_('c')
 {
-       lyxerr << "constructing MathParboxInset\n";
+       lyxerr << "constructing MathParboxInset" << endl;
 }
 
 
-MathInset * MathParboxInset::clone() const
+auto_ptr<InsetBase> MathParboxInset::clone() const
 {
-       return new MathParboxInset(*this);
+       return auto_ptr<InsetBase>(new MathParboxInset(*this));
 }
 
 
@@ -30,97 +45,24 @@ void MathParboxInset::setWidth(string const & w)
 {
        tex_width_ = w;
        lyx_width_ = LyXLength(w).inBP();
-       lyxerr << "setting " << w << " to " << lyx_width_ << " pixel\n";
+       lyxerr << "setting " << w << " to " << lyx_width_ << " pixel" << endl;
 }
 
 
-void MathParboxInset::metrics(MathMetricsInfo & mi) const
+void MathParboxInset::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       MathFontSetChanger dummy(mi.base, "textnormal");
-
-       // we do our own metrics fiddling
-       // delete old cache
-       rows_.clear();
-
-#if 1
-
-       xcell(0).metrics(mi);
-       width_ = xcell(0).width();
-       ascent_ = xcell(0).ascent();
-       descent_ = xcell(0).descent();
-
-#else
-
-       xcell(0).metricsExternal(mi, rows_);
-
-       int spaces = 0;
-       Dimension safe(0, 0, 0);
-       Dimension curr(0, 0, 0);
-       int safepos = 0;
-       int yo = 0;
-       for (size_type i = 0, n = cell(0).size(); i != n; ++i) {
-               // Special handling of spaces. We reached a safe position for breaking.
-               if (cell(0)[i]->getChar() == ' ') {
-                       safe += curr;
-                       safepos = i + 1;
-                       ++spaces;
-                       // restart chunk
-                       curr = Dimension(0, 0, 0);
-                       continue;
-               }
-
-               // This is a regular item. Go on if we either don't care for
-               // the width limit or have not reached that limit.
-               curr += rows_[i].dim;
-               if (curr.w + safe.w <= lyx_width_) 
-                       continue;
-
-               // We passed the limit. Create a row entry.
-               MathXArray::Row row;
-               if (spaces) {
-                       // but we had a space break before this position.
-                       row.dim  = safe;
-                       row.glue = (lyx_width_ - safe.w) / spaces;
-                       row.end  = safepos;
-                       i        = safepos;
-                       spaces   = 0;
-               } else {
-                       // This item is too large and it is the only one.
-                       // We have no choice but to produce an overfull box.
-                       row.dim  = curr;   // safe should be 0.
-                       row.glue = 0;      // does not matter
-                       row.end  = i + 1;
-               }
-               yo      += rows_[i].dim.height();
-               row.yo   = yo;
-               rows_.push_back(row);
-       }
-       // last row:
-       MathXArray::Row row;
-       row.dim  = safe;
-       row.dim += curr;
-       row.end  = cell(0).size();
-       row.glue = spaces ? (lyx_width_ - row.dim.w) / spaces : 0;
-       yo      += row.dim.height();
-       row.yo   = yo;
-       rows_.push_back(row);
-
-       // what to report?
-       ascent_  = xcell(0).ascent();
-       descent_ = xcell(0).descent() + 1;
-       width_   = xcell(0).width()   + 2;
-#endif
+       FontSetChanger dummy1(mi.base, "textnormal");
+       WidthChanger dummy2(mi.base, lyx_width_);
+       MathTextInset::metrics(mi, dim);
+       metricsMarkers(dim);
+       dim_ = dim;
 }
 
 
-void MathParboxInset::draw(MathPainterInfo & pi, int x, int y) const
+void MathParboxInset::draw(PainterInfo & pi, int x, int y) const
 {
-       MathFontSetChanger dummy(pi.base, "textnormal");
-#if 1
-       xcell(0).draw(pi, x + 1, y);
-#else
-       xcell(0).drawExternal(pi, x + 1, y, rows_);
-#endif
+       FontSetChanger dummy(pi.base, "textnormal");
+       MathTextInset::draw(pi, x + 1, y);
        drawMarkers(pi, x, y);
 }
 
@@ -138,4 +80,3 @@ void MathParboxInset::infoize(std::ostream & os) const
 {
        os << "Box: Parbox " << tex_width_;
 }
-