]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.cpp
Fulfill promise to Andre: TextClass_ptr --> TextClassPtr.
[lyx.git] / src / BufferView.cpp
index 9a66db40140db5e8363898f3d2f6d585608553c7..f1cf7c1f817537b7ec37bd203b6ad709db3d4f5f 100644 (file)
@@ -339,6 +339,7 @@ void BufferView::scrollDocView(int value)
        int const h = tm.parMetrics(anchor_ref_).height();
        offset_ref_ = int((bar * t.paragraphs().size() - anchor_ref_) * h);
        updateMetrics(false);
+       buffer_.changed();
 }
 
 
@@ -477,7 +478,7 @@ void BufferView::translateAndInsert(char_type c, Text * t, Cursor & cur)
                                intl_->keyMapPrim();
                }
        }
-       
+
        intl_->getTransManager().translateAndInsert(c, t, cur);
 }
 
@@ -592,6 +593,18 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd)
                break;
        }
 
+       case LFUN_SCREEN_UP:
+       case LFUN_SCREEN_DOWN:
+               flag.enabled(true);
+               break;
+
+       // FIXME: LFUN_SCREEN_DOWN_SELECT should be removed from
+       // everywhere else before this can enabled:
+       case LFUN_SCREEN_UP_SELECT:
+       case LFUN_SCREEN_DOWN_SELECT:
+               flag.enabled(false);
+               break;
+
        default:
                flag.enabled(false);
        }
@@ -935,6 +948,47 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd)
                break;
        }
 
+       case LFUN_SCREEN_UP:
+       case LFUN_SCREEN_DOWN: {
+               Point p = bv_funcs::getPos(*this, cur, cur.boundary());
+               if (p.y_ < 0 || p.y_ > height_) {
+                       // The cursor is off-screen so recenter before proceeding.
+                       center();
+                       updateMetrics(false);
+                       //FIXME: updateMetrics() does not update paragraph position
+                       // This is done at draw() time. So we need a redraw!
+                       buffer_.changed();
+                       p = bv_funcs::getPos(*this, cur, cur.boundary());
+               }
+               scroll(cmd.action == LFUN_SCREEN_UP? - height_ : height_);
+               cur.reset(buffer_.inset());
+               text_metrics_[&buffer_.text()].editXY(cur, p.x_, p.y_);
+               //FIXME: what to do with cur.x_target()?
+               finishUndo();
+               // The metrics are already up to date. see scroll()
+               updateFlags = Update::None;
+               break;
+       }
+
+       case LFUN_SCREEN_UP_SELECT:
+       case LFUN_SCREEN_DOWN_SELECT: {
+               cur.selHandle(true);
+               size_t initial_depth = cur.depth();
+               Point const p = bv_funcs::getPos(*this, cur, cur.boundary());
+               scroll(cmd.action == LFUN_SCREEN_UP_SELECT? - height_ : height_);
+               // FIXME: We need to verify if the cursor stayed within an inset...
+               //cur.reset(buffer_.inset());
+               text_metrics_[&buffer_.text()].editXY(cur, p.x_, p.y_);
+               finishUndo();
+               while (cur.depth() > initial_depth) {
+                       cur.forwardInset();
+               }
+               // FIXME: we need to do a redraw again because of the selection
+               buffer_.changed();
+               updateFlags = Update::Force | Update::FitCursor;
+               break;
+       }
+
        default:
                updateFlags = Update::None;
        }
@@ -1056,6 +1110,9 @@ 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 =
@@ -1138,20 +1195,60 @@ bool BufferView::workAreaDispatch(FuncRequest const & cmd0)
 }
 
 
-void BufferView::scroll(int /*lines*/)
+void BufferView::scroll(int y)
 {
-//     Text const * t = buffer_.text();
-//     int const line_height = defaultRowHeight();
-//
-//     // The new absolute coordinate
-//     int new_top_y = top_y() + lines * line_height;
-//
-//     // Restrict to a valid value
-//     new_top_y = std::min(t->height() - 4 * line_height, new_top_y);
-//     new_top_y = std::max(0, new_top_y);
-//
-//     scrollDocView(new_top_y);
-//
+       if (y > 0)
+               scrollDown(y);
+       else if (y < 0)
+               scrollUp(-y);
+}
+
+
+void BufferView::scrollDown(int offset)
+{
+       Text * text = &buffer_.text();
+       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();
+               if (last.first == text->paragraphs().size() - 1) {
+                       if (bottom_pos <= height_)
+                               return;
+                       offset = min(offset, bottom_pos - height_);
+                       break;
+               }
+               if (bottom_pos > ymax)
+                       break;
+               tm.newParMetricsDown();
+       }
+       offset_ref_ += offset;
+       updateMetrics(false);
+       buffer_.changed();
+}
+
+
+void BufferView::scrollUp(int offset)
+{
+       Text * text = &buffer_.text();
+       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();
+               if (first.first == 0) {
+                       if (top_pos >= 0)
+                               return;
+                       offset = min(offset, - top_pos);
+                       break;
+               }
+               if (top_pos < ymin)
+                       break;
+               tm.newParMetricsUp();
+       }
+       offset_ref_ -= offset;
+       updateMetrics(false);
+       buffer_.changed();
 }
 
 
@@ -1253,7 +1350,7 @@ bool BufferView::mouseSetCursor(Cursor & cur)
 {
        BOOST_ASSERT(&cur.bv() == this);
 
-        // this event will clear selection so we save selection for
+       // this event will clear selection so we save selection for
        // persistent selection
        cap::saveSelection(cursor());
 
@@ -1351,7 +1448,7 @@ void BufferView::updateMetrics(bool singlepar)
        if (!singlepar) {
                // Clear out the position cache in case of full screen redraw,
                coord_cache_.clear();
-       
+
                // Clear out paragraph metrics to avoid having invalid metrics
                // in the cache from paragraphs not relayouted below
                // The complete text metrics will be redone.
@@ -1510,7 +1607,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");
@@ -1549,13 +1646,13 @@ void BufferView::draw(frontend::Painter & pain)
 
        // and grey out above (should not happen later)
 //     lyxerr << "par ascent: " << text.getPar(metrics_info_.p1).ascent() << endl;
-       if (metrics_info_.y1 > 0 
+       if (metrics_info_.y1 > 0
                && metrics_info_.update_strategy == FullScreenUpdate)
                pain.fillRectangle(0, 0, width_, metrics_info_.y1, Color::bottomarea);
 
        // and possibly grey out below
 //     lyxerr << "par descent: " << text.getPar(metrics_info_.p1).ascent() << endl;
-       if (metrics_info_.y2 < height_ 
+       if (metrics_info_.y2 < height_
                && metrics_info_.update_strategy == FullScreenUpdate)
                pain.fillRectangle(0, metrics_info_.y2, width_,
                        height_ - metrics_info_.y2, Color::bottomarea);