]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_textinset.C
fix #1073
[lyx.git] / src / mathed / math_textinset.C
index 97105704f3c46d3b77e67c5dea6afcd0de0fa1ab..d67dbb19d778829c008db8b5212e13c2d7b15169 100644 (file)
@@ -1,10 +1,6 @@
 
-#ifdef __GNUG__
-#pragma implementation 
-#endif
-
 #include "math_textinset.h"
-#include "math_metricsinfo.h"
+#include "metricsinfo.h"
 #include "debug.h"
 
 
@@ -21,7 +17,7 @@ MathInset * MathTextInset::clone() const
 
 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";
@@ -29,21 +25,23 @@ MathInset::idx_type MathTextInset::pos2row(pos_type pos) const
 }
 
 
-void MathTextInset::getPos(idx_type, pos_type pos, int & x, int & y) const
+void MathTextInset::getPos(idx_type /*idx*/, pos_type pos, int & x, int & y) const
 {
        idx_type const i = pos2row(pos);
-       pos_type const p = pos - cache_.cellinfo_[i].begin_; 
+       pos_type const p = pos - cache_.cellinfo_[i].begin_;
        cache_.getPos(i, p, x, y);
+       y = cache_.cell(i).yo();
 }
 
 
-bool MathTextInset::idxUpDown(idx_type &, pos_type & pos, bool up,
+bool MathTextInset::idxUpDown2(idx_type &, pos_type & pos, bool up,
        int /*targetx*/) 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;
@@ -54,16 +52,20 @@ bool MathTextInset::idxUpDown(idx_type &, pos_type & pos, bool up,
                        return false;
        }
        MathGridInset::CellInfo const & cell2 = cache_.cellinfo_[i];
-       pos = cell(0).x2pos(cell2.begin_, x, cell2.glue_);
+       pos = cell2.begin_ + cache_.cell(i).x2pos(x, cell2.glue_);
        return true;
 }
 
 
-void MathTextInset::metrics(MathMetricsInfo & mi) const
+void MathTextInset::metrics(MetricsInfo & mi) const
 {
        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);
 
@@ -101,7 +103,7 @@ 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 (!mi.base.restrictwidth || curr + safe <= mi.base.textwidth)
                                continue;
                }
 
@@ -152,17 +154,22 @@ void MathTextInset::metrics(MathMetricsInfo & mi) const
        cache_.metrics(mi);
        dim_ = cache_.dimensions();
        //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);
+
 }
 
 
-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);
 }