]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_textinset.C
revert Buffer LyxText->InsetText commit
[lyx.git] / src / mathed / math_textinset.C
index 494fc753a7e942c6d910de08f7728ed23d2b3ea7..952692be2896f205eee0a27939b0e5a03c5c32b4 100644 (file)
@@ -1,7 +1,24 @@
+/**
+ * \file math_textinset.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_textinset.h"
-#include "math_metricsinfo.h"
+#include "math_data.h"
+
+#include "cursor_slice.h"
 #include "debug.h"
+#include "metricsinfo.h"
+
+using std::auto_ptr;
+using std::endl;
 
 
 MathTextInset::MathTextInset()
@@ -9,37 +26,40 @@ MathTextInset::MathTextInset()
 {}
 
 
-MathInset * MathTextInset::clone() const
+auto_ptr<InsetBase> MathTextInset::clone() const
 {
-       return new MathTextInset(*this);
+       return auto_ptr<InsetBase>(new MathTextInset(*this));
 }
 
 
 MathInset::idx_type MathTextInset::pos2row(pos_type pos) const
 {
-       for (pos_type r = 0, n = cache_.nargs(); r < n; ++r) 
+       for (pos_type r = 0, n = cache_.nargs(); r < n; ++r)
                if (pos >= cache_.cellinfo_[r].begin_ && pos <= cache_.cellinfo_[r].end_)
                        return r;
-       lyxerr << "illegal row for pos " << pos << "\n";
+       lyxerr << "illegal row for pos " << pos << endl;
        return 0;
 }
 
 
-void MathTextInset::getPos(idx_type, pos_type pos, int & x, int & y) const
+void MathTextInset::getCursorPos(CursorSlice const & cur, int & x, int & y) const
 {
-       idx_type const i = pos2row(pos);
-       pos_type const p = pos - cache_.cellinfo_[i].begin_; 
-       cache_.getPos(i, p, x, y);
+       CursorSlice c = cur;
+       c.idx() = pos2row(cur.pos());
+       c.pos() -= cache_.cellinfo_[c.idx()].begin_;
+       cache_.getCursorPos(c, x, y);
+       y = cache_.cell(c.idx()).yo();
 }
 
 
-bool MathTextInset::idxUpDown(idx_type &, pos_type & pos, bool up,
-       int targetx) const
+#if 0
+bool MathTextInset::idxUpDown2(LCursor & pos, bool up) const
 {
        // try to move only one screen row up or down if possible
        idx_type i = pos2row(pos);
+       //lyxerr << "\nMathTextInset::idxUpDown()  i: " << i << endl;
        MathGridInset::CellInfo const & cell1 = cache_.cellinfo_[i];
-       int const x = cells_[0].pos2x(cell1.begin_, pos, cell1.glue_);
+       int const x = cache_.cell(i).pos2x(pos - cell1.begin_, cell1.glue_);
        if (up) {
                if (i == 0)
                        return false;
@@ -50,16 +70,21 @@ bool MathTextInset::idxUpDown(idx_type &, pos_type & pos, bool up,
                        return false;
        }
        MathGridInset::CellInfo const & cell2 = cache_.cellinfo_[i];
-       pos = xcell(0).x2pos(cell2.begin_, x, cell2.glue_);
+       pos = cell2.begin_ + cache_.cell(i).x2pos(x, cell2.glue_);
        return true;
 }
+#endif
 
 
-void MathTextInset::metrics(MathMetricsInfo & mi) const
+void MathTextInset::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       xcell(0).metrics(mi);
+       cell(0).metrics(mi);
 
        // we do our own metrics fiddling
+       // save old positional information
+       int const old_xo = cache_.cell(0).xo();
+       int const old_yo = cache_.cell(0).yo();
+
        // delete old cache
        cache_ = MathGridInset(1, 0);
 
@@ -82,7 +107,7 @@ void MathTextInset::metrics(MathMetricsInfo & mi) const
                // Special handling of spaces. We reached a safe position for breaking.
                char const c = cell(0)[i]->getChar();
                if (c == ' ') {
-                       //lyxerr << "reached safe pos\n";
+                       //lyxerr << "reached safe pos" << endl;
                        // we don't count the space into the safe pos
                        safe += curr;
                        // we reset to this safepos if the next chunk does not fit
@@ -97,14 +122,14 @@ void MathTextInset::metrics(MathMetricsInfo & mi) const
                        // This is a regular char. Go on if we either don't care for
                        // the width limit or have not reached that limit.
                        curr += cell(0)[i]->width();
-                       if (!mi.base.restrictwidth || curr + safe <= mi.base.textwidth) 
+                       if (curr + safe <= mi.base.textwidth)
                                continue;
                }
 
                // We passed the limit. Create a row entry.
-               //lyxerr << "passed limit\n";
+               //lyxerr << "passed limit" << endl;
                cache_.appendRow();
-               MathXArray & ar = cache_.xcell(cache_.nargs() - 1);
+               MathArray & ar = cache_.cell(cache_.nargs() - 1);
                MathGridInset::CellInfo & row = cache_.cellinfo_.back();
                if (c == '\n') {
                        // we are here because we hit a hard newline
@@ -115,7 +140,7 @@ void MathTextInset::metrics(MathMetricsInfo & mi) const
                } else if (spaces) {
                        // but we had a space break before this position.
                        // so retreat to this position
-                       //lyxerr << "... but had safe pos.\n";
+                       //lyxerr << "... but had safe pos." << endl;
                        row.begin_ = begin;
                        row.end_   = safepos;  // this is position of the safe space
                        i          = safepos;  // i gets incremented at end of loop
@@ -124,43 +149,48 @@ void MathTextInset::metrics(MathMetricsInfo & mi) const
                } else {
                        // This item is too large and it is the only one.
                        // We have no choice but to produce an overfull box.
-                       lyxerr << "... without safe pos\n";
+                       lyxerr << "... without safe pos" << endl;
                        row.begin_ = begin;
                        row.end_   = i + 1;
                        begin      = i + 1;
                }
-               ar.data() =
-                       MathArray(cell(0).begin() + row.begin_, cell(0).begin() + row.end_);
-               //lyxerr << "line: " << ar << "\n";
+               ar = MathArray(cell(0).begin() + row.begin_, cell(0).begin() + row.end_);
+               //lyxerr << "line: " << ar << endl;
                // in any case, start the new row with empty boxes
                curr = 0;
                safe = 0;
        }
        // last row: put in everything else
        cache_.appendRow();
-       MathXArray & ar = cache_.xcell(cache_.nargs() - 1);
+       MathArray & ar = cache_.cell(cache_.nargs() - 1);
        MathGridInset::CellInfo & row = cache_.cellinfo_.back();
        row.begin_ = begin;
        row.end_   = cell(0).size();
-       ar.data()  =
-               MathArray(cell(0).begin() + row.begin_, cell(0).begin() + row.end_);
-       //lyxerr << "last line: " << ar.data() << "\n";
+       ar = MathArray(cell(0).begin() + row.begin_, cell(0).begin() + row.end_);
+       //lyxerr << "last line: " << ar.data() << endl;
 
        // what to report?
-       cache_.metrics(mi);
-       dim_ = cache_.dimensions();
+       cache_.metrics(mi, dim_);
        //lyxerr << "outer dim: " << dim_ << endl;
+
+       // reset position cache
+       for (idx_type i = 0; i < cache_.nargs(); ++i)
+               cache_.cell(i).setXY(old_xo, old_yo);
+
+       dim = dim_;
 }
 
 
-void MathTextInset::draw(MathPainterInfo & pi, int x, int y) const
+void MathTextInset::draw(PainterInfo & pi, int x, int y) const
 {
        cache_.draw(pi, x + 1, y);
 }
 
 
-void MathTextInset::drawSelection(MathPainterInfo & pi,
+/*
+void MathTextInset::drawSelection(PainterInfo & pi,
                idx_type idx1, pos_type pos1, idx_type idx2, pos_type pos2) const
 {
-       cache_.drawSelection(pi, idx1, pos1, idx2, pos2);       
+       cache_.drawSelection(pi, idx1, pos1, idx2, pos2);
 }
+*/