]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.cpp
BufferParams.cpp: change the package loading to:
[lyx.git] / src / BufferView.cpp
index 341ab318f4c5c6c50606ee30794fc96f6ee06a57..eed6d0403d59b7654c77d5cc875e2105b84e9fe3 100644 (file)
@@ -1045,49 +1045,30 @@ void BufferView::resize(int width, int height)
 
 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;
 }
 
 
@@ -1110,9 +1091,6 @@ bool BufferView::workAreaDispatch(FuncRequest const & cmd0)
        cmd.y = min(max(cmd.y, -1), height_);
 
        if (cmd.action == LFUN_MOUSE_MOTION && cmd.button() == mouse_button::none) {
-               //FIXME: disabling mouse hover for now as it is causing funny things
-               // on screen.
-               return false;
 
                // Get inset under mouse, if there is one.
                Inset const * covering_inset =
@@ -1131,38 +1109,30 @@ bool BufferView::workAreaDispatch(FuncRequest const & cmd0)
                        // Highlighted the newly hovered inset (if any).
                        need_redraw |= inset->setMouseHover(true);
                last_inset_ = inset;
+               if (!need_redraw)
+                       return false;
 
                // 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.
-               // FIXME: It is possible to redraw only the area around the button!
-               if (need_redraw
-                       && metrics_info_.update_strategy == SingleParUpdate) {
-                       // FIXME: It should be possible to redraw only the area around
-                       // the button by doing this:
-                       //
-                       //metrics_info_.singlepar = false;
-                       //metrics_info_.y1 = ymin of button;
-                       //metrics_info_.y2 = ymax of button;
-                       //
-                       // Unfortunately, BufferView::draw() does not distinguish
-                       // between background updates and text updates. So we use the hammer
-                       // solution for now. We could also avoid the updateMetrics() below
-                       // by using the first and last pit of the CoordCache. Have a look
-                       // at Text::getPitNearY() to see what I mean.
-                       //
-                       //metrics_info_.pit1 = first pit of CoordCache;
-                       //metrics_info_.pit2 = last pit of CoordCache;
-                       //metrics_info_.singlepar = false;
-                       //metrics_info_.y1 = 0;
-                       //metrics_info_.y2 = height_;
-                       //
-                       updateMetrics(false);
-               }
+               // 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.
-               return need_redraw;
+               return true;
        }
 
        // Build temporary cursor.
@@ -1210,8 +1180,8 @@ void BufferView::scrollDown(int offset)
        TextMetrics & tm = text_metrics_[text];
        int ymax = height_ + offset;
        while (true) {
-               std::pair<pit_type, ParagraphMetrics> const & last = tm.last();
-               int bottom_pos = last.second.position() + last.second.descent();
+               std::pair<pit_type, ParagraphMetrics const *> last = tm.last();
+               int bottom_pos = last.second->position() + last.second->descent();
                if (last.first == text->paragraphs().size() - 1) {
                        if (bottom_pos <= height_)
                                return;
@@ -1234,8 +1204,8 @@ void BufferView::scrollUp(int offset)
        TextMetrics & tm = text_metrics_[text];
        int ymin = - offset;
        while (true) {
-               std::pair<pit_type, ParagraphMetrics> const & first = tm.first();
-               int top_pos = first.second.position() - first.second.ascent();
+               std::pair<pit_type, ParagraphMetrics const *> first = tm.first();
+               int top_pos = first.second->position() - first.second->ascent();
                if (first.first == 0) {
                        if (top_pos >= 0)
                                return;
@@ -1607,7 +1577,7 @@ void BufferView::menuInsertLyXFile(string const & filenm)
                el = buf.errorList("Parse");
                recordUndo(cursor_);
                cap::pasteParagraphList(cursor_, buf.paragraphs(),
-                                            buf.params().getTextClass_ptr(), el);
+                                            buf.params().getTextClassPtr(), el);
                res = _("Document %1$s inserted.");
        } else
                res = _("Could not insert document %1$s");