commit f686375eecc92a2658425a6bb93ee184c5049ec1
Author: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date:   Fri Dec 20 14:02:31 2013 +0100

    Change getColumnNearX to getPosNearX
    
    The semantics was bad: the old implementation would return pos - row.pos(), 
and then all user of the function had to re-add row.pos().

diff --git a/00README_STR_METRICS_BRANCH b/00README_STR_METRICS_BRANCH
index e38d4b6..1983dfe 100644
--- a/00README_STR_METRICS_BRANCH
+++ b/00README_STR_METRICS_BRANCH
@@ -17,7 +17,11 @@ What is done:
   metrics are computed. The list of elements is stored in the row
   object in visual ordering, not logical.
 
-* Re-implement cursorX and getColumnNearX using row elements.
+* rename getColumnNearX to getPosNearX (and change code accordingly).
+  It does not make sense to return a position relative to the start of
+  row, since nobody needs this.
+
+* Re-implement cursorX and getPosNearX using row elements.
 
 * Implement proper string metrics computation (with cache), when
   lyxrc.force_paint_single_char is false. In this case, remove also
@@ -34,10 +38,6 @@ Next steps:
   kept for comparison purpose, guarded with KEEP_OLD_METRICS_CODE in
   order to check computations.
 
-* rename getColumnNearX to getPosNearX or x2pos (and change code
-  accordingly). It does not make sense to return a position relative
-  to the start of row, since nobody needs this.
-
 * Re-implement row painting using row elements. This is not difficult
   in principle, but the code is intricate and needs some careful
   analysis. First thing that needs to be done is to break row elements
diff --git a/src/Cursor.cpp b/src/Cursor.cpp
index 7dff932..61e4b60 100644
--- a/src/Cursor.cpp
+++ b/src/Cursor.cpp
@@ -2090,9 +2090,7 @@ bool Cursor::upDownInText(bool up, bool & updateNeeded)
 
                Row const & real_next_row = 
tm.parMetrics(pit()).rows()[next_row];
                bool bound = false;
-               pos_type const col = tm.getColumnNearX(pit(), real_next_row, 
-                                                      xo, bound);
-               top().pos() = real_next_row.pos() + col;
+               top().pos() = tm.getPosNearX(pit(), real_next_row, xo, bound);
                boundary(bound);
 
                updateNeeded |= bv().checkDepm(*this, old);
diff --git a/src/Row.cpp b/src/Row.cpp
index 86b7d06..15af2c2 100644
--- a/src/Row.cpp
+++ b/src/Row.cpp
@@ -104,7 +104,7 @@ pos_type Row::Element::x2pos(double &x, bool const low) 
const
                x = x2;
        }
 
-       //lyxerr << "=> p=" << i << " x=" << x << endl;
+       //lyxerr << "=> p=" << pos + i << " x=" << x << endl;
        return pos + i;
 }
 
diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp
index b894133..9e775e0 100644
--- a/src/TextMetrics.cpp
+++ b/src/TextMetrics.cpp
@@ -1114,7 +1114,7 @@ void TextMetrics::setRowHeight(Row & row, pit_type const 
pit,
 // x is an absolute screen coord
 // returns the column near the specified x-coordinate of the row
 // x is set to the real beginning of this column
-pos_type TextMetrics::getColumnNearX(pit_type const pit,
+pos_type TextMetrics::getPosNearX(pit_type const pit,
                Row const & row, int & x, bool & boundary) const
 {
 
@@ -1291,7 +1291,7 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit,
 
        if (abs(x2 - x) > 0.1 || boundary != boundary
            || c != pos) {
-               lyxerr << "getColumnNearX(" << x_orig << "): new=(x=" << x - xo 
<< ", b=" << boundary << ", p=" << pos << "), "
+               lyxerr << "getPosNearX(" << x_orig << "): new=(x=" << x - xo << 
", b=" << boundary << ", p=" << pos << "), "
                       << "old=(x=" << x2 - xo << ", b=" << boundary2 << ", p=" 
<< c << "), " << row;
        }
 
@@ -1307,7 +1307,7 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit,
        return min(col, end - 1 - row.pos());
 #endif // 0
 #endif // KEEP_OLD_METRICS_CODE
-       return pos - row.pos();
+       return pos;
 }
 
 
@@ -1322,7 +1322,7 @@ pos_type TextMetrics::x2pos(pit_type pit, int row, int x) 
const
        LBUFERR(row < int(pm.rows().size()));
        bool bound = false;
        Row const & r = pm.rows()[row];
-       return r.pos() + getColumnNearX(pit, r, x, bound);
+       return getPosNearX(pit, r, x, bound);
 }
 
 
@@ -1482,10 +1482,9 @@ Inset * TextMetrics::editXY(Cursor & cur, int x, int y,
 
        if (!it) {
                // No inset, set position in the text
-               bool bound = false; // is modified by getColumnNearX
-               int xx = x; // is modified by getColumnNearX
-               cur.pos() = row.pos()
-                       + getColumnNearX(pit, row, xx, bound);
+               bool bound = false; // is modified by getPosNearX
+               int xx = x; // is modified by getPosNearX
+               cur.pos() = getPosNearX(pit, row, xx, bound);
                cur.boundary(bound);
                cur.setCurrentFont();
                cur.setTargetX(xx);
@@ -1536,7 +1535,7 @@ void TextMetrics::setCursorFromCoordinates(Cursor & cur, 
int const x, int const
 
        bool bound = false;
        int xx = x;
-       pos_type const pos = row.pos() + getColumnNearX(pit, row, xx, bound);
+       pos_type const pos = getPosNearX(pit, row, xx, bound);
 
        LYXERR(Debug::DEBUG, "setting cursor pit: " << pit << " pos: " << pos);
 
diff --git a/src/TextMetrics.h b/src/TextMetrics.h
index 46e208a..c7feaa7 100644
--- a/src/TextMetrics.h
+++ b/src/TextMetrics.h
@@ -149,10 +149,10 @@ private:
 
 // Temporary public:
 public:
-       /// returns the column near the specified x-coordinate of the row.
+       /// returns the position near the specified x-coordinate of the row.
        /// x is an absolute screen coord, it is set to the real beginning
        /// of this column.
-       pos_type getColumnNearX(pit_type pit, Row const & row, int & x,
+       pos_type getPosNearX(pit_type pit, Row const & row, int & x,
                bool & boundary) const;
 
        /// returns pos in given par at given x coord.
diff --git a/src/frontends/qt4/GuiWorkArea.cpp 
b/src/frontends/qt4/GuiWorkArea.cpp
index 514866a..8c21c6a 100644
--- a/src/frontends/qt4/GuiWorkArea.cpp
+++ b/src/frontends/qt4/GuiWorkArea.cpp
@@ -1002,7 +1002,7 @@ void GuiWorkArea::generateSyntheticMouseEvent()
        // Find the position of the cursor
        bool bound;
        int x = d->synthetic_mouse_event_.cmd.x();
-       pos_type const pos = rit->pos() + tm.getColumnNearX(pit, *rit, x, 
bound);
+       pos_type const pos = tm.getPosNearX(pit, *rit, x, bound);
 
        // Set the cursor
        cur.pit() = pit;

Reply via email to