]> git.lyx.org Git - lyx.git/commitdiff
Fix scrolling to top and bottom of the document.
authorAbdelrazak Younes <younes@lyx.org>
Tue, 29 Jan 2008 09:51:12 +0000 (09:51 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Tue, 29 Jan 2008 09:51:12 +0000 (09:51 +0000)
* BufferView
- showCursor(DocIterator): new DocIterator argument.
- showCursor(): use above method.
- scrollDocView(): take care of top and bottom special cases early in the method.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22707 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView.cpp
src/BufferView.h

index e563a4f81d2f4702a5af15c891e05158db0a4706..d7e7e1655e929deb8a5642f295cebfec57c7f543 100644 (file)
@@ -501,6 +501,24 @@ docstring BufferView::contextMenu(int x, int y) const
 
 void BufferView::scrollDocView(int value)
 {
+       // cut off at the top
+       if (value <= d->scrollbarParameters_.min) {
+               DocIterator dit = doc_iterator_begin(buffer_.inset());
+               showCursor(dit);
+               LYXERR(Debug::SCROLLING, "scroll to top");
+               return;
+       }
+
+       // cut off at the top
+       if (value >= d->scrollbarParameters_.max) {
+               DocIterator dit = doc_iterator_end(buffer_.inset());
+               dit.backwardPos();
+               showCursor(dit);
+               LYXERR(Debug::SCROLLING, "scroll to bottom");
+               return;
+       }
+
+
        int const offset = value - d->scrollbarParameters_.position;
        // If the offset is less than 2 screen height, prefer to scroll instead.
        if (abs(offset) <= 2 * height_) {
@@ -508,10 +526,6 @@ void BufferView::scrollDocView(int value)
                return;
        }
 
-       // cut off at the top
-       if (value < d->scrollbarParameters_.min)
-               value = d->scrollbarParameters_.min;
-
        // find paragraph at target positin
        int par_pos = d->scrollbarParameters_.min;
        for (size_t i = 0; i != d->par_height_.size(); ++i) {
@@ -703,6 +717,12 @@ int BufferView::workWidth() const
 
 
 void BufferView::showCursor()
+{
+       showCursor(d->cursor_);
+}
+
+
+void BufferView::showCursor(DocIterator const & dit)
 {
        // We are not properly started yet, delay until resizing is
        // done.
@@ -711,11 +731,11 @@ void BufferView::showCursor()
 
        LYXERR(Debug::SCROLLING, "recentering!");
 
-       CursorSlice & bot = d->cursor_.bottom();
+       CursorSlice const & bot = dit.bottom();
        TextMetrics & tm = d->text_metrics_[bot.text()];
 
        pos_type const max_pit = pos_type(bot.text()->paragraphs().size() - 1);
-       int bot_pit = d->cursor_.bottom().pit();
+       int bot_pit = bot.pit();
        if (bot_pit > max_pit) {
                // FIXME: Why does this happen?
                LYXERR0("bottom pit is greater that max pit: "
@@ -730,9 +750,13 @@ void BufferView::showCursor()
 
        if (tm.has(bot_pit)) {
                ParagraphMetrics const & pm = tm.parMetrics(bot_pit);
-               int offset = coordOffset(d->cursor_, d->cursor_.boundary()).y_;
+               BOOST_ASSERT(!pm.rows().empty());
+               // FIXME: smooth scrolling doesn't work in mathed.
+               CursorSlice const & cs = dit.innerTextSlice();
+               int offset = coordOffset(dit, dit.boundary()).y_;
                int ypos = pm.position() + offset;
-               Dimension const & row_dim = d->cursor_.textRow().dimension();
+               Dimension const & row_dim =
+                       pm.getRow(cs.pos(), dit.boundary()).dimension();
                if (ypos - row_dim.ascent() < 0)
                        scrollUp(- ypos + row_dim.ascent());
                else if (ypos + row_dim.descent() > height_)
@@ -743,10 +767,12 @@ void BufferView::showCursor()
 
        tm.redoParagraph(bot_pit);
        ParagraphMetrics const & pm = tm.parMetrics(bot_pit);
-       int offset = coordOffset(d->cursor_, d->cursor_.boundary()).y_;
+       int offset = coordOffset(dit, dit.boundary()).y_;
 
        d->anchor_pit_ = bot_pit;
-       Dimension const & row_dim = d->cursor_.textRow().dimension();
+       CursorSlice const & cs = dit.innerTextSlice();
+       Dimension const & row_dim =
+               pm.getRow(cs.pos(), dit.boundary()).dimension();
 
        if (d->anchor_pit_ == 0)
                d->anchor_ypos_ = offset + pm.ascent();
index faac2f6c62b423cb1804709f71578266a8a5fea0..2fe006418818b839c25e3271dc218e8b66f8fb66 100644 (file)
@@ -127,10 +127,14 @@ public:
        /// set the cursor based on the given TeX source row.
        void setCursorFromRow(int row);
 
-       /// Ensure the cursor is visible.
-       /// This method will automatically scroll and update the BufferView and updated 
+       /// Ensure that the BufferView cursor is visible.
+       /// This method will automatically scroll and update the BufferView
        /// if needed.
        void showCursor();
+       /// Ensure the passed cursor \p dit is visible.
+       /// This method will automatically scroll and update the BufferView
+       /// if needed.
+       void showCursor(DocIterator const & dit);
        /// LFUN_SCROLL Helper.
        void lfunScroll(FuncRequest const & cmd);
        /// scroll down document by the given number of pixels.