Inset const * BufferView::getCoveringInset(Text const & text, int x, int y)
{
- pit_type pit = text_metrics_[&text].getPitNearY(y);
- BOOST_ASSERT(pit != -1);
- Paragraph const & par = text.getPar(pit);
-
- LYXERR(Debug::DEBUG)
- << BOOST_CURRENT_FUNCTION
- << ": x: " << x
- << " y: " << y
- << " pit: " << pit
- << endl;
- InsetList::const_iterator iit = par.insetlist.begin();
- InsetList::const_iterator iend = par.insetlist.end();
- for (; iit != iend; ++iit) {
- Inset * const inset = iit->inset;
- if (inset->covers(*this, x, y)) {
- if (!inset->descendable())
- // No need to go further down if the inset is not
- // descendable.
- return inset;
-
- size_t cell_number = inset->nargs();
- // Check all the inner cell.
- for (size_t i = 0; i != cell_number; ++i) {
- Text const * inner_text = inset->getText(i);
- if (inner_text) {
- // Try deeper.
- Inset const * inset_deeper =
- getCoveringInset(*inner_text, x, y);
- if (inset_deeper)
- return inset_deeper;
- }
- }
-
- LYXERR(Debug::DEBUG)
- << BOOST_CURRENT_FUNCTION
- << ": Hit inset: " << inset << endl;
- return inset;
+ TextMetrics & tm = text_metrics_[&text];
+ Inset * inset = tm.checkInsetHit(x, y);
+ if (!inset)
+ return 0;
+
+ if (!inset->descendable())
+ // No need to go further down if the inset is not
+ // descendable.
+ return inset;
+
+ size_t cell_number = inset->nargs();
+ // Check all the inner cell.
+ for (size_t i = 0; i != cell_number; ++i) {
+ Text const * inner_text = inset->getText(i);
+ if (inner_text) {
+ // Try deeper.
+ Inset const * inset_deeper =
+ getCoveringInset(*inner_text, x, y);
+ if (inset_deeper)
+ return inset_deeper;
}
}
- LYXERR(Debug::DEBUG)
- << BOOST_CURRENT_FUNCTION
- << ": No inset hit. " << endl;
- return 0;
+
+ return inset;
}
// if last metrics update was in singlepar mode, WorkArea::redraw() will
// not expose the button for redraw. We adjust here the metrics dimension
- // to enable a full redraw.
- if (metrics_info_.update_strategy == SingleParUpdate) {
- // Build temporary cursor.
- TextMetrics & tm = text_metrics_[&buffer_.text()];
- tm.editXY(cur, cmd.x, cmd.y);
- // collect cursor paragraph iter bounds
- std::pair<pit_type, ParagraphMetrics const *> firstpm = tm.first();
- std::pair<pit_type, ParagraphMetrics const *> lastpm = tm.last();
- int y1 = firstpm.second->position() - firstpm.second->ascent();
- int y2 = lastpm.second->position() + lastpm.second->descent();
- metrics_info_ = ViewMetricsInfo(firstpm.first, lastpm.first, y1, y2,
- FullScreenUpdate, buffer_.text().paragraphs().size());
- }
+ // to enable a full redraw in any case as this is not costly.
+ TextMetrics & tm = text_metrics_[&buffer_.text()];
+ std::pair<pit_type, ParagraphMetrics const *> firstpm = tm.first();
+ std::pair<pit_type, ParagraphMetrics const *> lastpm = tm.last();
+ int y1 = firstpm.second->position() - firstpm.second->ascent();
+ int y2 = lastpm.second->position() + lastpm.second->descent();
+ metrics_info_ = ViewMetricsInfo(firstpm.first, lastpm.first, y1, y2,
+ FullScreenUpdate, buffer_.text().paragraphs().size());
+ // Reinitialize anchor to first pit.
+ anchor_ref_ = firstpm.first;
+ offset_ref_ = -y1;
+ LYXERR(Debug::PAINTING)
+ << "Mouse hover detected at: (" << cmd.x << ", " << cmd.y << ")"
+ << "\nTriggering redraw: y1: " << y1 << " y2: " << y2
+ << " pit1: " << firstpm.first << " pit2: " << lastpm.first << endl;
// This event (moving without mouse click) is not passed further.
// This should be changed if it is further utilized.