]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView_pimpl.C
no need for three calls to update() in a row...
[lyx.git] / src / BufferView_pimpl.C
index 34df16b03e5ded1af9f02aaeffc6524261b57ae5..799e8f203b9b2746854836c2daaa9ce413e1cf34 100644 (file)
@@ -313,7 +313,7 @@ void BufferView::Pimpl::buffer(Buffer * b)
                        resizeCurrentBuffer();
 
                // FIXME: needed when ?
-               top_y(screen().topCursorVisible(bv_->text));
+               fitCursor();
 
                // Buffer-dependent dialogs should be updated or
                // hidden. This should go here because some dialogs (eg ToC)
@@ -343,28 +343,11 @@ void BufferView::Pimpl::buffer(Buffer * b)
 bool BufferView::Pimpl::fitCursor()
 {
        lyxerr << "BufferView::Pimpl::fitCursor." << endl;
-       bool ret;
-
-#ifndef LOCK
-       UpdatableInset * tli =
-               static_cast<UpdatableInset *>(cursor_.innerInset());
-       if (tli) {
-               tli->fitInsetCursor(bv_);
-               ret = true;
-       } else {
-               ret = screen().fitCursor(bv_->text, bv_);
+       if (screen().fitCursor(bv_)) {
+               updateScrollbar();
+               return true;
        }
-#else
-       ret = screen().fitCursor(bv_->text, bv_);
-#endif
-
-       //dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
-
-       // We need to always update, in case we did a
-       // paste and we stayed anchored to a row, but
-       // the actual height of the doc changed ...
-       updateScrollbar();
-       return ret;
+       return false;
 }
 
 
@@ -375,7 +358,6 @@ void BufferView::Pimpl::redoCurrentBuffer()
                resizeCurrentBuffer();
                updateScrollbar();
                owner_->updateLayoutChoice();
-               update();
        }
 }
 
@@ -432,7 +414,7 @@ void BufferView::Pimpl::resizeCurrentBuffer()
                }
        }
 
-       top_y(screen().topCursorVisible(bv_->text));
+       fitCursor();
 
        switchKeyMap();
        owner_->busy(false);
@@ -599,9 +581,18 @@ void BufferView::Pimpl::update()
 {
        //lyxerr << "BufferView::update()" << endl;
        // fix cursor coordinate cache in case something went wrong
+
+       // check needed to survive LyX startup
        if (bv_->getLyXText()) {
-               // check needed to survive LyX startup
+               // update all 'visible' paragraphs
+               ParagraphList::iterator beg;
+               ParagraphList::iterator end;
+               getParsInRange(buffer_->paragraphs(),
+                              top_y(), top_y() + workarea().workHeight(),
+                              beg, end);
+               bv_->text->redoParagraphs(beg, end);
                bv_->getLyXText()->redoCursor();
+               updateScrollbar();
        }
        screen().redraw(*bv_);
 }
@@ -681,7 +672,6 @@ void BufferView::Pimpl::restorePosition(unsigned int i)
        bv_->text->setCursor(par.pit(),
                             min(par->size(), saved_positions[i].par_pos));
 
-       update();
        if (i > 0)
                owner_->message(bformat(_("Moved to bookmark %1$s"), tostr(i)));
 }
@@ -727,7 +717,6 @@ void BufferView::Pimpl::center()
        // updateScrollbar() currently. Never mind that this is a
        // pretty obfuscated way of updating t->top_y()
        top_y(new_y);
-       update();
 }
 
 
@@ -856,8 +845,6 @@ void BufferView::Pimpl::trackChanges()
                update();
                bv_->text->setCursor(0, 0);
 #warning changes FIXME
-               //moveCursorUpdate(false);
-
                bool found = lyx::find::findNextChange(bv_);
                if (found) {
                        owner_->getDialogs().show("changes");
@@ -882,13 +869,17 @@ namespace {
        {
                LyXText * text = bv->text;
                InsetOld * inset = 0;
-               InsetOld * inset_hit = 0;
                theTempCursor = LCursor(bv);
-               while ((inset_hit = text->checkInsetHit(x, y))) {
+               while (true) {
+                       InsetOld * inset_hit = text->checkInsetHit(x, y);
+                       if (!inset_hit)
+                               break;
                        inset = inset_hit;
+                       if (!inset_hit->descendable())
+                               break;
                        text = inset_hit->getText(0);
                        lyxerr << "Hit inset: " << inset << " at x: " << x
-                               << " y: " << y << endl;
+                               << " text: " << text << " y: " << y << endl;
                        theTempCursor.push(static_cast<UpdatableInset*>(inset));
                }
                return inset;
@@ -933,28 +924,50 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd)
                        cmd2.x -= inset->x();
                        cmd2.y -= inset->y();
                        res = inset->dispatch(cmd2);
-                       if (res.update())
-                               bv_->updateInset(inset);
+                       if (res.update()) {
+                               bv_->update();
+                               bv_->cursor().updatePos();
+                       }
                        res.update(false);
+                       switch (res.val()) {
+                               case FINISHED:
+                               case FINISHED_RIGHT:
+                               case FINISHED_UP: 
+                               case FINISHED_DOWN:
+                                       theTempCursor.pop();
+                                       bv_->cursor() = theTempCursor;
+                                       bv_->cursor().innerText()->setCursorFromCoordinates(cmd.x, top_y() + cmd.y);
+                                       if (bv_->fitCursor())
+                                               bv_->update();
+                                       return true;
+                               default:
+                                       lyxerr << "not dispatched by inner inset val: " << res.val() << endl;
+                                       break;
+                       }
                }
 
                // otherwise set cursor to surrounding LyXText
                if (!res.dispatched()) {
-                       lyxerr << "cursor is: " << bv_->cursor() << endl;
-                       lyxerr << "dispatching to surrounding LyXText "
-                               << bv_->cursor().innerText() << endl;
-                       bv_->cursor().innerText()->dispatch(cmd1);
+                       lyxerr << "temp cursor is: " << theTempCursor << endl;
+                       lyxerr << "dispatching " << cmd1
+                              << " to surrounding LyXText "
+                              << theTempCursor.innerText() << endl;
+                       bv_->cursor() = theTempCursor;
+                       res = bv_->cursor().innerText()->dispatch(cmd1);
+                       if (bv_->fitCursor() || res.update())
+                               bv_->update();
+                       
                        //return DispatchResult(true, true);
                }
-
                // see workAreaKeyPress
                cursor_timeout.restart();
                screen().showCursor(*bv_);
 
-               // FIXME: we should skip these when selecting
-               owner_->updateLayoutChoice();
-               owner_->updateToolbar();
-               fitCursor();
+               // skip these when selecting
+               if (cmd.action != LFUN_MOUSE_MOTION) {
+                       owner_->updateLayoutChoice();
+                       owner_->updateToolbar();
+               }
 
                // slight hack: this is only called currently when we
                // clicked somewhere, so we force through the display
@@ -1090,8 +1103,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
                InsetBase * inset = owner_->getDialogs().getOpenInset(name);
                if (inset) {
                        // This works both for 'original' and 'mathed' insets.
-                       // Note that the localDispatch performs updateInset
-                       // also.
+                       // Note that the localDispatch performs update also.
                        FuncRequest fr(bv_, LFUN_INSET_MODIFY, ev.argument);
                        inset->dispatch(fr);
                } else {
@@ -1103,21 +1115,10 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
 
        case LFUN_INSET_INSERT: {
                InsetOld * inset = createInset(ev);
-               if (inset && insertInset(inset)) {
-                       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
-#warning check whether the update() is needed at all
-                               bv_->update();
-                       }
-               } else {
+               if (!inset || !insertInset(inset))
                        delete inset;
-               }
+               break;
        }
-       break;
 
        case LFUN_FLOAT_LIST:
                if (tclass.floats().typeExist(ev.argument)) {
@@ -1177,11 +1178,8 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
        case LFUN_ACCEPT_ALL_CHANGES: {
                bv_->text->setCursor(0, 0);
 #warning FIXME changes
-               //moveCursorUpdate(false);
-
                while (lyx::find::findNextChange(bv_))
                        bv_->getLyXText()->acceptChange();
-
                update();
                break;
        }
@@ -1189,11 +1187,8 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
        case LFUN_REJECT_ALL_CHANGES: {
                bv_->text->setCursor(0, 0);
 #warning FIXME changes
-               //moveCursorUpdate(false);
-
                while (lyx::find::findNextChange(bv_))
                        bv_->getLyXText()->rejectChange();
-
                update();
                break;
        }
@@ -1260,32 +1255,12 @@ bool BufferView::Pimpl::insertInset(InsetOld * inset, string const & lout)
                                   string(),
                                   0);
        }
-
        bv_->cursor().innerText()->insertInset(inset);
-       update();
-
        unFreezeUndo();
        return true;
 }
 
 
-void BufferView::Pimpl::updateInset(InsetOld const * /*inset*/)
-{
-       if (!available())
-               return;
-
-#warning used for asynchronous updates?
-       //bv_->text->redoParagraph(outerPar(*bv_->buffer(), inset));
-
-       // this should not be needed, but it is...
-       bv_->text->redoParagraph(bv_->text->cursorPar());
-       // bv_->text->fullRebreak();
-
-       update();
-       updateScrollbar();
-}
-
-
 bool BufferView::Pimpl::ChangeInsets(InsetOld::Code code,
                                     string const & from, string const & to)
 {
@@ -1343,3 +1318,5 @@ void BufferView::Pimpl::updateParagraphDialog()
        data = "update " + tostr(accept) + '\n' + data;
        bv_->owner()->getDialogs().update("paragraph", data);
 }
+
+