]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView_pimpl.C
Point fix, earlier forgotten
[lyx.git] / src / BufferView_pimpl.C
index 1df70cd4b60553f49e2a7bba1922342f3778073b..296b9d61d10f7db91aee1d783cdc15b43926d1bd 100644 (file)
@@ -40,6 +40,7 @@
 #include "lyxrc.h"
 #include "lastfiles.h"
 #include "paragraph.h"
+#include "paragraph_funcs.h"
 #include "ParagraphParameters.h"
 #include "TextCache.h"
 #include "undo_funcs.h"
@@ -272,6 +273,18 @@ Painter & BufferView::Pimpl::painter() const
 }
 
 
+void BufferView::Pimpl::top_y(int y)
+{
+       top_y_ = y;
+}
+
+
+int BufferView::Pimpl::top_y() const
+{
+       return top_y_;
+}
+
+
 void BufferView::Pimpl::buffer(Buffer * b)
 {
        lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
@@ -292,6 +305,8 @@ void BufferView::Pimpl::buffer(Buffer * b)
        // set current buffer
        buffer_ = b;
 
+       top_y_ = 0;
+
        // if we're quitting lyx, don't bother updating stuff
        if (quitting)
                return;
@@ -309,7 +324,7 @@ void BufferView::Pimpl::buffer(Buffer * b)
                        resizeCurrentBuffer();
 
                // FIXME: needed when ?
-               bv_->text->top_y(screen().topCursorVisible(bv_->text));
+               top_y(screen().topCursorVisible(bv_->text));
 
                // Buffer-dependent dialogs should be updated or
                // hidden. This should go here because some dialogs (eg ToC)
@@ -460,7 +475,7 @@ void BufferView::Pimpl::resizeCurrentBuffer()
                bv_->theLockingInset(the_locking_inset);
        }
 
-       bv_->text->top_y(screen().topCursorVisible(bv_->text));
+       top_y(screen().topCursorVisible(bv_->text));
 
        switchKeyMap();
        owner_->busy(false);
@@ -483,9 +498,9 @@ void BufferView::Pimpl::updateScrollbar()
        LyXText const & t = *bv_->text;
 
        lyxerr[Debug::GUI] << "Updating scrollbar: h " << t.height << ", top_y() "
-               << t.top_y() << ", default height " << defaultRowHeight() << endl;
+               << top_y() << ", default height " << defaultRowHeight() << endl;
 
-       workarea().setScrollbarParams(t.height, t.top_y(), defaultRowHeight());
+       workarea().setScrollbarParams(t.height, top_y(), defaultRowHeight());
 }
 
 
@@ -498,22 +513,21 @@ void BufferView::Pimpl::scrollDocView(int value)
 
        screen().hideCursor();
 
-       bv_->text->top_y(value);
-       //screen().draw();
+       top_y(value);
+       screen().redraw(*bv_);
 
        if (!lyxrc.cursor_follows_scrollbar)
                return;
 
-       LyXText * vbt = bv_->text;
-
        int const height = defaultRowHeight();
-       int const first = static_cast<int>((bv_->text->top_y() + height));
-       int const last = static_cast<int>((bv_->text->top_y() + workarea().workHeight() - height));
+       int const first = top_y() + height;
+       int const last = top_y() + workarea().workHeight() - height;
 
-       if (vbt->cursor.y() < first)
-               vbt->setCursorFromCoordinates(0, first);
-       else if (vbt->cursor.y() > last)
-               vbt->setCursorFromCoordinates(0, last);
+       LyXText * text = bv_->text;
+       if (text->cursor.y() < first)
+               text->setCursorFromCoordinates(0, first);
+       else if (text->cursor.y() > last)
+               text->setCursorFromCoordinates(0, last);
 
        owner_->updateLayoutChoice();
 }
@@ -529,7 +543,7 @@ void BufferView::Pimpl::scroll(int lines)
        int const line_height = defaultRowHeight();
 
        // The new absolute coordinate
-       int new_top_y = t->top_y() + lines * line_height;
+       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);
@@ -538,7 +552,7 @@ void BufferView::Pimpl::scroll(int lines)
        scrollDocView(new_top_y);
 
        // Update the scrollbar.
-       workarea().setScrollbarParams(t->height, t->top_y(), defaultRowHeight());
+       workarea().setScrollbarParams(t->height, top_y(), defaultRowHeight());
 }
 
 
@@ -576,7 +590,7 @@ void BufferView::Pimpl::selectionRequested()
                 text->selection.end != bv_->text->xsel_cache.end))
        {
                bv_->text->xsel_cache = text->selection;
-               sel = text->selectionAsString(bv_->buffer(), false);
+               sel = text->selectionAsString(*bv_->buffer(), false);
        } else if (!text->selection.set()) {
                sel = string();
                bv_->text->xsel_cache.set(false);
@@ -642,7 +656,6 @@ void BufferView::Pimpl::update()
        if (bv_->getLyXText()) {
                // check needed to survive LyX startup
                bv_->getLyXText()->redoCursor();
-               fitCursor();
        }
        screen().redraw(*bv_);
 }
@@ -781,10 +794,7 @@ void BufferView::Pimpl::center()
 
        beforeChange(text);
        int const half_height = workarea().workHeight() / 2;
-       int new_y = 0;
-
-       if (text->cursor.y() > half_height)
-               new_y = text->cursor.y() - half_height;
+       int new_y = std::max(0, text->cursor.y() - half_height);
 
        // FIXME: look at this comment again ...
 
@@ -797,7 +807,7 @@ void BufferView::Pimpl::center()
        // and also might have moved top_y() must make sure to call
        // updateScrollbar() currently. Never mind that this is a
        // pretty obfuscated way of updating t->top_y()
-       text->top_y(new_y);
+       top_y(new_y);
        //screen().draw();
        update();
 }
@@ -974,7 +984,7 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & ev)
                screen().hideCursor();
 
                bool const res = dispatch(ev);
-               
+
                // see workAreaKeyPress
                cursor_timeout.restart();
                screen().showCursor(*bv_);
@@ -1183,7 +1193,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
        case LFUN_INSET_INSERT: {
                InsetOld * inset = createInset(ev);
                if (inset && insertInset(inset)) {
-                       updateInset();
+                       updateInset(inset);
 
                        string const name = ev.getArg(0);
                        if (name == "bibitem") {
@@ -1245,14 +1255,14 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
                string arg = ev.argument;
 
                if (arg.empty()) {
-                       arg = bv_->getLyXText()->selectionAsString(buffer_,
+                       arg = bv_->getLyXText()->selectionAsString(*buffer_,
                                                                   false);
 
                        // FIXME
                        if (arg.size() > 100 || arg.empty()) {
                                // Get word or selection
                                bv_->getLyXText()->selectWordWhenUnderCursor(lyx::WHOLE_WORD);
-                               arg = bv_->getLyXText()->selectionAsString(buffer_, false);
+                               arg = bv_->getLyXText()->selectionAsString(*buffer_, false);
                                // FIXME: where is getLyXText()->unselect(bv_) ?
                        }
                }
@@ -1372,13 +1382,16 @@ bool BufferView::Pimpl::insertInset(InsetOld * inset, string const & lout)
 }
 
 
-void BufferView::Pimpl::updateInset()
+void BufferView::Pimpl::updateInset(InsetOld const * inset)
 {
        if (!available())
                return;
 
+       bv_->text->redoParagraph(outerPar(*bv_->buffer(), inset));
+
        // this should not be needed, but it is...
-       bv_->text->redoParagraph(bv_->text->cursor.par());
+       // bv_->text->redoParagraph(bv_->text->cursor.par());
+       // bv_->text->fullRebreak();
 
        update();
        updateScrollbar();