]> git.lyx.org Git - lyx.git/blobdiff - src/TextMetrics.cpp
Initialize class member to please coverity
[lyx.git] / src / TextMetrics.cpp
index 94594ede2c2b2bb2dc46f7cd11090efa7437fb68..87a381eed0d09a66e436728cf0cba2c75d8464c1 100644 (file)
@@ -1094,7 +1094,7 @@ void TextMetrics::setRowHeight(Row & row) const
 // returns the column near the specified x-coordinate of the row
 // x is set to the real beginning of this column
 pos_type TextMetrics::getPosNearX(Row const & row, int & x,
-                                 bool & boundary) const
+                                  bool & boundary, bool const select) const
 {
        //LYXERR0("getPosNearX(" << x << ") row=" << row);
        /// For the main Text, it is possible that this pit is not
@@ -1124,7 +1124,7 @@ pos_type TextMetrics::getPosNearX(Row const & row, int & x,
                for ( ; cit != cend; ++cit) {
                        if (w <= x &&  w + cit->full_width() > x) {
                                int x_offset = int(x - w);
-                               pos = cit->x2pos(x_offset);
+                               pos = cit->x2pos(x_offset, select);
                                x = int(x_offset + w);
                                break;
                        }
@@ -1382,7 +1382,8 @@ Inset * TextMetrics::editXY(Cursor & cur, int x, int y,
 }
 
 
-void TextMetrics::setCursorFromCoordinates(Cursor & cur, int const x, int const y)
+void TextMetrics::setCursorFromCoordinates(Cursor & cur, int const x,
+                                           int const y, bool const select)
 {
        LASSERT(text_ == cur.text(), return);
        pit_type const pit = getPitNearY(y);
@@ -1409,7 +1410,7 @@ void TextMetrics::setCursorFromCoordinates(Cursor & cur, int const x, int const
 
        bool bound = false;
        int xx = x;
-       pos_type const pos = getPosNearX(row, xx, bound);
+       pos_type const pos = getPosNearX(row, xx, bound, select);
 
        LYXERR(Debug::DEBUG, "setting cursor pit: " << pit << " pos: " << pos);
 
@@ -1427,28 +1428,12 @@ InsetList::InsetTable * TextMetrics::checkInsetHit(pit_type pit, int x, int y)
 
        LYXERR(Debug::DEBUG, "x: " << x << " y: " << y << "  pit: " << pit);
 
-       InsetList::const_iterator iit = par.insetList().begin();
-       InsetList::const_iterator iend = par.insetList().end();
-       for (; iit != iend; ++iit) {
-               Inset * inset = iit->inset;
-
-               LYXERR(Debug::DEBUG, "examining inset " << inset);
-
-               if (!insetCache.has(inset)) {
-                       LYXERR(Debug::DEBUG, "inset has no cached position");
-                       return 0;
-               }
-
-               Dimension const & dim = insetCache.dim(inset);
-               Point p = insetCache.xy(inset);
-
-               LYXERR(Debug::DEBUG, "xo: " << p.x_ << "..." << p.x_ + dim.wid
-                       << " yo: " << p.y_ - dim.asc << "..." << p.y_ + dim.des);
+       for (auto const & it : par.insetList()) {
+               LYXERR(Debug::DEBUG, "examining inset " << it.inset);
 
-               if (x >= p.x_ && x <= p.x_ + dim.wid
-                   && y >= p.y_ - dim.asc && y <= p.y_ + dim.des) {
-                       LYXERR(Debug::DEBUG, "Hit inset: " << inset);
-                       return const_cast<InsetList::InsetTable *>(&(*iit));
+               if (insetCache.covers(it.inset, x, y)) {
+                       LYXERR(Debug::DEBUG, "Hit inset: " << it.inset);
+                       return const_cast<InsetList::InsetTable *>(&it);
                }
        }