- x -= xo_;
- y -= yo_;
- par_type pit;
- Row const & row = getRowNearY(y, pit);
- lyxerr[Debug::DEBUG] << "setCursorFromCoordinates:: hit row at: "
- << row.pos() << endl;
- bool bound = false;
- int xx = x + xo_; // getRowNearX get absolute x coords
- pos_type const pos = row.pos() + getColumnNearX(pit, row, xx, bound);
- setCursor(cur, pit, pos, true, bound);
+ BOOST_ASSERT(!paragraphs().empty());
+ BOOST_ASSERT(theCoords.getParPos().find(this) != theCoords.getParPos().end());
+ CoordCache::InnerParPosCache const & cc = theCoords.getParPos().find(this)->second;
+ lyxerr << "LyXText::getPitNearY: y: " << y << " cache size: "
+ << cc.size() << endl;
+
+ // look for highest numbered paragraph with y coordinate less than given y
+ pit_type pit = 0;
+ int yy = -1;
+ CoordCache::InnerParPosCache::const_iterator it = cc.begin();
+ CoordCache::InnerParPosCache::const_iterator et = cc.end();
+ for (; it != et; ++it) {
+ lyxerr << " examining: pit: " << it->first << " y: "
+ << it->second.y_ << endl;
+ if (it->first >= pit && int(it->second.y_) - int(pars_[it->first].ascent()) <= y) {
+ pit = it->first;
+ yy = it->second.y_;
+ }
+ }
+
+ lyxerr << " found best y: " << yy << " for pit: " << pit << endl;
+ return pit;
+}
+
+
+Row const & LyXText::getRowNearY(int y, pit_type pit) const
+{
+ Paragraph const & par = pars_[pit];
+ int yy = theCoords.get(this, pit).y_ - par.ascent();
+ BOOST_ASSERT(!par.rows().empty());
+ RowList::const_iterator rit = par.rows().begin();
+ RowList::const_iterator const rlast = boost::prior(par.rows().end());
+ for (; rit != rlast; yy += rit->height(), ++rit)
+ if (yy + rit->height() > y)
+ break;
+ return *rit;