]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView_pimpl.C
Point fix, earlier forgotten
[lyx.git] / src / BufferView_pimpl.C
index c5281728fd81239b1d44b8762347b9ccd524b9ed..296b9d61d10f7db91aee1d783cdc15b43926d1bd 100644 (file)
@@ -1,10 +1,19 @@
 /**
  * \file BufferView_pimpl.C
- * Copyright 2002 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
+ * \author Asger Alstrup
+ * \author Alfredo Braustein
  * \author Lars Gullik Bjønnes
- * \author various
+ * \author Jean-Marc Lasgouttes
+ * \author Angus Leeming
+ * \author John Levon
+ * \author André Pönitz
+ * \author Dekel Tsur
+ * \author Jürgen Vigna
+ *
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
@@ -31,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"
@@ -263,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 ("
@@ -283,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;
@@ -300,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)
@@ -427,7 +451,7 @@ void BufferView::Pimpl::resizeCurrentBuffer()
                selendpar = bv_->text->ownerParagraphs().end();
        }
 
-#warning doesn't help much
+#warning does not help much
        bv_->text->redoParagraphs(bv_->text->ownerParagraphs().begin(),
                bv_->text->ownerParagraphs().end());
 
@@ -451,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);
@@ -474,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());
 }
 
 
@@ -489,21 +513,21 @@ void BufferView::Pimpl::scrollDocView(int value)
 
        screen().hideCursor();
 
-       screen().draw(bv_->text, bv_, value);
+       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();
 }
@@ -519,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);
@@ -528,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());
 }
 
 
@@ -566,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);
@@ -632,7 +656,6 @@ void BufferView::Pimpl::update()
        if (bv_->getLyXText()) {
                // check needed to survive LyX startup
                bv_->getLyXText()->redoCursor();
-               fitCursor();
        }
        screen().redraw(*bv_);
 }
@@ -767,14 +790,11 @@ void BufferView::Pimpl::insetUnlock()
 
 void BufferView::Pimpl::center()
 {
-       LyXText * t = bv_->text;
+       LyXText * text = bv_->text;
 
-       beforeChange(t);
+       beforeChange(text);
        int const half_height = workarea().workHeight() / 2;
-       int new_y = 0;
-
-       if (t->cursor.y() > half_height)
-               new_y = t->cursor.y() - half_height;
+       int new_y = std::max(0, text->cursor.y() - half_height);
 
        // FIXME: look at this comment again ...
 
@@ -787,8 +807,8 @@ 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()
-       screen().draw(t, bv_, new_y);
-
+       top_y(new_y);
+       //screen().draw();
        update();
 }
 
@@ -817,7 +837,7 @@ InsetOld * BufferView::Pimpl::getInsetByCode(InsetOld::Code code)
        return it != buffer_->inset_iterator_end() ? (*it) : 0;
 #else
        // Ok, this is a little bit too brute force but it
-       // should work for now. Better infrastructure is comming. (Lgb)
+       // should work for now. Better infrastructure is coming. (Lgb)
 
        Buffer * b = bv_->buffer();
        LyXCursor cursor = bv_->getLyXText()->cursor;
@@ -964,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_);
@@ -1173,13 +1193,12 @@ 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") {
                                // We need to do a redraw because the maximum
                                // InsetBibitem width could have changed
-                               bv_->fitCursor();
 #warning check whether the update() is needed at all
                                bv_->update();
                        }
@@ -1201,12 +1220,8 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
                break;
 
        case LFUN_LAYOUT_PARAGRAPH: {
-               Paragraph const * par = &*bv_->getLyXText()->cursor.par();
-               if (!par)
-                       break;
-
                string data;
-               params2string(*par, data);
+               params2string(*bv_->getLyXText()->cursor.par(), data);
 
                data = "show\n" + data;
                bv_->owner()->getDialogs().show("paragraph", data);
@@ -1240,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_) ?
                        }
                }
@@ -1367,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();