]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView_pimpl.C
More 'standard conformant blurb' nonsense.
[lyx.git] / src / BufferView_pimpl.C
index 980128bb1fa387508b8e2532952be76b26261a41..222c5a0b71dc31c02f3e7c7ee6f00be90ac6db10 100644 (file)
@@ -29,7 +29,6 @@
 #include "lyxfunc.h"
 #include "lyxtext.h"
 #include "lyxrc.h"
-#include "lyxrow.h"
 #include "lastfiles.h"
 #include "paragraph.h"
 #include "ParagraphParameters.h"
@@ -188,10 +187,10 @@ bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles)
        // get absolute path of file and add ".lyx" to the filename if
        // necessary
        string s = FileSearch(string(), filename, "lyx");
-       
+
        bool const found = !s.empty();
 
-       if (!found) 
+       if (!found)
                s = filename;
 
        // file already open?
@@ -319,7 +318,7 @@ void BufferView::Pimpl::buffer(Buffer * b)
                textcache.clear();
        }
 
-       repaint();
+       update();
        updateScrollbar();
        owner_->updateMenubar();
        owner_->updateToolbar();
@@ -349,7 +348,7 @@ bool BufferView::Pimpl::fitCursor()
                ret = screen().fitCursor(bv_->text, bv_);
        }
 
-       dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
+       //dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
 
        // We need to always update, in case we did a
        // paste and we stayed anchored to a row, but
@@ -366,12 +365,12 @@ void BufferView::Pimpl::redoCurrentBuffer()
                resizeCurrentBuffer();
                updateScrollbar();
                owner_->updateLayoutChoice();
-               repaint();
+               update();
        }
 }
 
 
-int BufferView::Pimpl::resizeCurrentBuffer()
+void BufferView::Pimpl::resizeCurrentBuffer()
 {
        lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
 
@@ -400,30 +399,26 @@ int BufferView::Pimpl::resizeCurrentBuffer()
                selection = bv_->text->selection.set();
                mark_set = bv_->text->selection.mark();
                the_locking_inset = bv_->theLockingInset();
-               resizeInsets(bv_);
                bv_->text->fullRebreak();
                update();
        } else {
-               lyxerr << "text not available!\n";
+               lyxerr << "text not available!" << endl;
                // See if we have a text in TextCache that fits
                // the new buffer_ with the correct width.
                bv_->text = textcache.findFit(buffer_, workarea().workWidth());
                if (bv_->text) {
-                       lyxerr << "text in cache!\n";
+                       lyxerr << "text in cache!" << endl;
                        if (lyxerr.debugging()) {
-                               lyxerr << "Found a LyXText that fits:\n";
+                               lyxerr << "Found a LyXText that fits:" << endl;
                                textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea().workWidth(), bv_->text)));
                        }
                        // Set the owner of the newly found text
                        //      bv_->text->owner(bv_);
                        if (lyxerr.debugging())
                                textcache.show(lyxerr, "resizeCurrentBuffer");
-
-                       resizeInsets(bv_);
                } else {
-                       lyxerr << "no text in cache!\n";
-                       bv_->text = new LyXText(bv_);
-                       resizeInsets(bv_);
+                       lyxerr << "no text in cache!" << endl;
+                       bv_->text = new LyXText(bv_, 0, false, bv_->buffer()->paragraphs);
                        bv_->text->init(bv_);
                }
 
@@ -432,6 +427,10 @@ int BufferView::Pimpl::resizeCurrentBuffer()
                selendpar = bv_->text->ownerParagraphs().end();
        }
 
+#warning does not help much
+       bv_->text->redoParagraphs(bv_->text->ownerParagraphs().begin(),
+               bv_->text->ownerParagraphs().end());
+
        if (par != bv_->text->ownerParagraphs().end()) {
                bv_->text->selection.set(true);
                // At this point just to avoid the Delete-Empty-Paragraph-
@@ -461,15 +460,6 @@ int BufferView::Pimpl::resizeCurrentBuffer()
        owner_->clearMessage();
 
        updateScrollbar();
-
-       return 0;
-}
-
-
-void BufferView::Pimpl::repaint()
-{
-       // Regenerate the screen.
-       screen().redraw(bv_, bv_->text);
 }
 
 
@@ -499,7 +489,8 @@ void BufferView::Pimpl::scrollDocView(int value)
 
        screen().hideCursor();
 
-       screen().draw(bv_->text, bv_, value);
+       bv_->text->top_y(value);
+       //screen().draw();
 
        if (!lyxrc.cursor_follows_scrollbar)
                return;
@@ -591,7 +582,6 @@ void BufferView::Pimpl::selectionLost()
 {
        if (available()) {
                screen().hideCursor();
-               toggleSelection();
                bv_->getLyXText()->clearSelection();
                bv_->text->xsel_cache.set(false);
        }
@@ -624,69 +614,28 @@ void BufferView::Pimpl::workAreaResize()
                        if (lyxerr.debugging())
                                textcache.show(lyxerr, "Expose delete all");
                        textcache.clear();
-                       // FIXME: this is already done in resizeCurrentBuffer() ??
-                       resizeInsets(bv_);
-               } else if (heightChange) {
-                       // fitCursor() ensures we don't jump back
-                       // to the start of the document on vertical
-                       // resize
-                       fitCursor();
                }
        }
 
-       if (widthChange || heightChange) {
-               repaint();
-       }
+       if (widthChange || heightChange)
+               update();
 
        // always make sure that the scrollbar is sane.
        updateScrollbar();
        owner_->updateLayoutChoice();
-       return;
 }
 
 
 void BufferView::Pimpl::update()
 {
-       if (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()) {
-               screen().update(*bv_);
-               bv_->text->clearPaint();
-       }
-}
-
-
-void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
-{
-       if (!text->selection.set() && (f & SELECT)) {
-               text->selection.cursor = text->cursor;
-       }
-
-       text->partialRebreak();
-
-       if (text->inset_owner) {
-               text->inset_owner->setUpdateStatus(InsetText::NONE);
-               updateInset(text->inset_owner);
-       } else {
-               update();
-       }
-}
-
-
-void BufferView::Pimpl::update(BufferView::UpdateCodes f)
-{
-       LyXText * text = bv_->text;
-
-       if (!text->selection.set() && (f & SELECT)) {
-               text->selection.cursor = text->cursor;
-       }
-
-       text->partialRebreak();
-
-       if (text->inset_owner) {
-               text->inset_owner->setUpdateStatus(InsetText::NONE);
-               updateInset(text->inset_owner);
-       } else {
-               update();
+       lyxerr << "BufferView::update()" << endl;
+       // fix cursor coordinate cache in case something went wrong
+       if (bv_->getLyXText()) {
+               // check needed to survive LyX startup
+               bv_->getLyXText()->redoCursor();
+               fitCursor();
        }
+       screen().redraw(*bv_);
 }
 
 
@@ -717,19 +666,18 @@ Change const BufferView::Pimpl::getCurrentChange()
        if (!bv_->buffer()->params.tracking_changes)
                return Change(Change::UNCHANGED);
 
-       LyXText * t(bv_->getLyXText());
+       LyXText * text = bv_->getLyXText();
 
-       if (!t->selection.set())
+       if (!text->selection.set())
                return Change(Change::UNCHANGED);
 
-       LyXCursor const & cur(t->selection.start);
+       LyXCursor const & cur = text->selection.start;
        return cur.par()->lookupChangeFull(cur.pos());
 }
 
 
 void BufferView::Pimpl::beforeChange(LyXText * text)
 {
-       toggleSelection();
        text->clearSelection();
 }
 
@@ -774,7 +722,7 @@ void BufferView::Pimpl::restorePosition(unsigned int i)
        bv_->text->setCursor(par.pit(),
                             min(par->size(), saved_positions[i].par_pos));
 
-       update(BufferView::SELECT);
+       update();
        if (i > 0)
                owner_->message(bformat(_("Moved to bookmark %1$s"), tostr(i)));
 }
@@ -818,23 +766,16 @@ void BufferView::Pimpl::insetUnlock()
 }
 
 
-void BufferView::Pimpl::toggleSelection(bool b)
-{
-       screen().toggleSelection(bv_->text, bv_, b);
-}
-
-
 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;
-       }
+       if (text->cursor.y() > half_height)
+               new_y = text->cursor.y() - half_height;
 
        // FIXME: look at this comment again ...
 
@@ -847,9 +788,9 @@ 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);
-
-       update(BufferView::SELECT);
+       text->top_y(new_y);
+       //screen().draw();
+       update();
 }
 
 
@@ -877,7 +818,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;
@@ -981,7 +922,7 @@ void BufferView::Pimpl::trackChanges()
                // we cannot allow undos beyond the freeze point
                buf->undostack.clear();
        } else {
-               update(BufferView::SELECT);
+               update();
                bv_->text->setCursor(buf->paragraphs.begin(), 0);
 #warning changes FIXME
                //moveCursorUpdate(false);
@@ -1002,37 +943,49 @@ void BufferView::Pimpl::trackChanges()
 }
 
 
-// Doesn't go through lyxfunc, so we need to update the
-// layout choice etc. ourselves
-bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & ev_in)
+bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & ev)
 {
-       // e.g. Qt mouse press when no buffer
-       if (!available())
-               return false;
+       switch (ev.action) {
+       case LFUN_MOUSE_PRESS:
+       case LFUN_MOUSE_MOTION:
+       case LFUN_MOUSE_RELEASE:
+       case LFUN_MOUSE_DOUBLE:
+       case LFUN_MOUSE_TRIPLE:
+       {
+               // We pass those directly to the Bufferview, since
+               // otherwise selection handling breaks down
 
-       screen().hideCursor();
+               // Doesn't go through lyxfunc, so we need to update
+               // the layout choice etc. ourselves
 
-       // Make sure that the cached BufferView is correct.
-       FuncRequest ev = ev_in;
-       ev.setView(bv_);
+               // e.g. Qt mouse press when no buffer
+               if (!available())
+                       return false;
 
-       bool const res = dispatch(ev);
+               screen().hideCursor();
 
-       // see workAreaKeyPress
-       cursor_timeout.restart();
-       screen().showCursor(*bv_);
+               bool const res = dispatch(ev);
+               
+               // see workAreaKeyPress
+               cursor_timeout.restart();
+               screen().showCursor(*bv_);
 
-       // FIXME: we should skip these when selecting
-       bv_->owner()->updateLayoutChoice();
-       bv_->owner()->updateToolbar();
-       bv_->fitCursor();
+               // FIXME: we should skip these when selecting
+               owner_->updateLayoutChoice();
+               owner_->updateToolbar();
+               fitCursor();
 
-       // slight hack: this is only called currently when
-       // we clicked somewhere, so we force through the display
-       // of the new status here.
-       bv_->owner()->clearMessage();
+               // slight hack: this is only called currently when we
+               // clicked somewhere, so we force through the display
+               // of the new status here.
+               owner_->clearMessage();
 
-       return res;
+               return res;
+       }
+       default:
+               owner_->dispatch(ev);
+               return true;
+       }
 }
 
 
@@ -1187,7 +1140,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
                        owner_->getLyXFunc().handleKeyFunc(ev.action);
                        owner_->getIntl().getTransManager()
                                .TranslateAndInsert(ev.argument[0], bv_->getLyXText());
-                       update(bv_->getLyXText(), BufferView::SELECT);
+                       update();
                }
                break;
 
@@ -1221,16 +1174,14 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
        case LFUN_INSET_INSERT: {
                InsetOld * inset = createInset(ev);
                if (inset && insertInset(inset)) {
-                       updateInset(inset);
+                       updateInset();
 
                        string const name = ev.getArg(0);
                        if (name == "bibitem") {
                                // We need to do a redraw because the maximum
                                // InsetBibitem width could have changed
-#warning please check you mean repaint() not update(),
-#warning and whether the repaint() is needed at all
-                               bv_->repaint();
-                               bv_->fitCursor();
+#warning check whether the update() is needed at all
+                               bv_->update();
                        }
                } else {
                        delete inset;
@@ -1250,12 +1201,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);
@@ -1265,15 +1212,13 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
        case LFUN_PARAGRAPH_UPDATE: {
                if (!bv_->owner()->getDialogs().visible("paragraph"))
                        break;
-               Paragraph const * par = &*bv_->getLyXText()->cursor.par();
-               if (!par)
-                       break;
+               Paragraph const & par = *bv_->getLyXText()->cursor.par();
 
                string data;
-               params2string(*par, data);
+               params2string(par, data);
 
                // Will the paragraph accept changes from the dialog?
-               InsetOld * const inset = par->inInset();
+               InsetOld * const inset = par.inInset();
                bool const accept =
                        !(inset && inset->forceDefaultParagraphs(inset));
 
@@ -1316,40 +1261,38 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
                break;
 
        case LFUN_ACCEPT_ALL_CHANGES: {
-               update(BufferView::SELECT);
                bv_->text->setCursor(bv_->buffer()->paragraphs.begin(), 0);
 #warning FIXME changes
                //moveCursorUpdate(false);
 
-               while (lyx::find::findNextChange(bv_)) {
+               while (lyx::find::findNextChange(bv_))
                        bv_->getLyXText()->acceptChange();
-               }
-               update(BufferView::SELECT);
+
+               update();
                break;
        }
 
        case LFUN_REJECT_ALL_CHANGES: {
-               update(BufferView::SELECT);
                bv_->text->setCursor(bv_->buffer()->paragraphs.begin(), 0);
 #warning FIXME changes
                //moveCursorUpdate(false);
 
-               while (lyx::find::findNextChange(bv_)) {
+               while (lyx::find::findNextChange(bv_))
                        bv_->getLyXText()->rejectChange();
-               }
-               update(BufferView::SELECT);
+
+               update();
                break;
        }
 
        case LFUN_ACCEPT_CHANGE: {
                bv_->getLyXText()->acceptChange();
-               update(BufferView::SELECT);
+               update();
                break;
        }
 
        case LFUN_REJECT_CHANGE: {
                bv_->getLyXText()->rejectChange();
-               update(BufferView::SELECT);
+               update();
                break;
        }
 
@@ -1381,20 +1324,15 @@ bool BufferView::Pimpl::insertInset(InsetOld * inset, string const & lout)
 
        beforeChange(bv_->text);
        if (!lout.empty()) {
-               update(BufferView::SELECT);
                bv_->text->breakParagraph(bv_->buffer()->paragraphs);
-               update(BufferView::SELECT);
 
                if (!bv_->text->cursor.par()->empty()) {
                        bv_->text->cursorLeft(bv_);
-
                        bv_->text->breakParagraph(bv_->buffer()->paragraphs);
-                       update(BufferView::SELECT);
                }
 
                string lres = lout;
-               LyXTextClass const & tclass =
-                       buffer_->params.getLyXTextClass();
+               LyXTextClass const & tclass = buffer_->params.getLyXTextClass();
                bool hasLayout = tclass.hasLayout(lres);
                string lay = tclass.defaultLayoutName();
 
@@ -1415,57 +1353,24 @@ bool BufferView::Pimpl::insertInset(InsetOld * inset, string const & lout)
                                   LYX_ALIGN_LAYOUT,
                                   string(),
                                   0);
-               update(BufferView::SELECT);
        }
 
        bv_->text->insertInset(inset);
-       update(BufferView::SELECT);
+       update();
 
        unFreezeUndo();
        return true;
 }
 
 
-void BufferView::Pimpl::updateInset(InsetOld * inset)
+void BufferView::Pimpl::updateInset()
 {
-       if (!inset || !available())
+       if (!available())
                return;
 
-       // first check for locking insets
-       if (bv_->theLockingInset()) {
-               if (bv_->theLockingInset() == inset) {
-                       if (bv_->text->updateInset(inset)) {
-                               update();
-                               updateScrollbar();
-                               return;
-                       }
-               } else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
-                       if (bv_->text->updateInset(bv_->theLockingInset())) {
-                               update();
-                               updateScrollbar();
-                               return;
-                       }
-               }
-       }
+       // this should not be needed, but it is...
+       bv_->text->redoParagraph(bv_->text->cursor.par());
 
-       // then check if the inset is a top_level inset (has no owner)
-       // if yes do the update as always otherwise we have to update the
-       // toplevel inset where this inset is inside
-       InsetOld * tl_inset = inset;
-       while (tl_inset->owner())
-               tl_inset = tl_inset->owner();
-       if (tl_inset == inset) {
-               update(BufferView::UPDATE);
-               if (bv_->text->updateInset(inset)) {
-                       update(BufferView::SELECT);
-                       return;
-               }
-       } else if (static_cast<UpdatableInset *>(tl_inset)
-                          ->updateInsetInInset(bv_, inset))
-       {
-               if (bv_->text->updateInset(tl_inset)) {
-                       update();
-                       updateScrollbar();
-               }
-       }
+       update();
+       updateScrollbar();
 }