From de49e029348c639be64ec77cc9d292c0da6ddc3b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Mon, 10 Nov 2003 13:23:14 +0000 Subject: [PATCH] the update/updateInset merge git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8069 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 6 ---- src/BufferView.h | 17 ++------- src/BufferView_pimpl.C | 66 +++++++++++++++++------------------ src/BufferView_pimpl.h | 5 +-- src/ChangeLog | 5 +++ src/bufferview_funcs.C | 3 +- src/cursor.C | 2 +- src/frontends/LyXView.C | 2 +- src/insets/insetbibitem.C | 2 +- src/insets/insetbox.C | 1 - src/insets/insetbranch.C | 1 - src/insets/insetcollapsable.C | 9 +++-- src/insets/insetcommand.C | 2 +- src/insets/insetert.C | 4 +-- src/insets/insetexternal.C | 2 +- src/insets/insetfloat.C | 2 +- src/insets/insetgraphics.C | 2 +- src/insets/insetinclude.C | 2 +- src/insets/insetlabel.C | 2 +- src/insets/insetminipage.C | 2 +- src/insets/insetnote.C | 2 +- src/insets/insettabular.C | 4 +-- src/insets/insettext.C | 2 +- src/insets/insetwrap.C | 2 +- src/insets/updatableinset.C | 2 +- src/mathed/formulabase.C | 24 ++++++------- src/text2.C | 5 ++- src/text3.C | 14 ++++---- 28 files changed, 85 insertions(+), 107 deletions(-) diff --git a/src/BufferView.C b/src/BufferView.C index 747768eb14..af246c8a0b 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -394,12 +394,6 @@ void BufferView::hideCursor() } -void BufferView::updateInset(InsetOld const * inset) -{ - pimpl_->updateInset(inset); -} - - bool BufferView::ChangeRefsIfUnique(string const & from, string const & to) { // Check if the label 'from' appears more than once diff --git a/src/BufferView.h b/src/BufferView.h index d3ec1cb833..2865989f9b 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -86,19 +86,6 @@ public: bool fitCursor(); /// perform pending painting updates void update(); - /** update for a particular inset. Gets a pointer and not a - * reference because we really need the pointer information - * to find it in the buffer. - * - * Extracted from Matthias notes: - * - * If a inset wishes any redraw and/or update it just has to call - * updateInset(this). It's is completly irrelevant, where the inset is. - * UpdateInset will find it in any paragraph in any buffer. - * Of course the insets in the current paragraph/buffer - * are checked first, so no performance problem should occur. - */ - void updateInset(InsetOld const *); /// reset the scrollbar to reflect current view position void updateScrollbar(); /// FIXME @@ -196,9 +183,9 @@ public: bool dispatch(FuncRequest const & argument); /// set target x position of cursor - void BufferView::x_target(int x); + void x_target(int x); /// return target x position of cursor - int BufferView::x_target() const; + int x_target() const; /// access to cursor LCursor & cursor(); diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 53b8cbce76..d0213c2cbf 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -599,9 +599,17 @@ 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 bv_->getLyXText()->redoCursor(); + + // update all 'visible' paragraphs + ParagraphList::iterator beg, end; + getVisiblePars(beg, end); + bv_->text->redoParagraphs(beg, end); + + updateScrollbar(); } screen().redraw(*bv_); } @@ -938,7 +946,7 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd) cmd2.y -= inset->y(); res = inset->dispatch(cmd2); if (res.update()) - bv_->updateInset(inset); + bv_->update(); res.update(false); } @@ -1094,8 +1102,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 { @@ -1107,21 +1114,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)) { @@ -1273,23 +1269,6 @@ bool BufferView::Pimpl::insertInset(InsetOld * inset, string const & lout) } -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) { @@ -1347,3 +1326,22 @@ void BufferView::Pimpl::updateParagraphDialog() data = "update " + tostr(accept) + '\n' + data; bv_->owner()->getDialogs().update("paragraph", data); } + + +void BufferView::Pimpl::getVisiblePars + (ParagraphList::iterator & beg, ParagraphList::iterator & end) +{ + beg = bv_->text->cursorPar(); + end = beg; + + for ( ; beg != bv_->text->ownerParagraphs().begin(); --beg) + if (beg->y - top_y() < 0) + break; + + if (beg != bv_->text->ownerParagraphs().begin()) + --beg; + + for ( ; end != bv_->text->ownerParagraphs().end(); ++end) + if (end->y - top_y() > workarea().workHeight()) + break; +} diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index 19e702bea2..a7f06bce88 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -104,8 +104,6 @@ struct BufferView::Pimpl : public boost::signals::trackable { void center(); /// bool insertInset(InsetOld * inset, std::string const & lout = std::string()); - /// - void updateInset(InsetOld const * inset); /// a function should be executed from the workarea bool workAreaDispatch(FuncRequest const & ev); /// a function should be executed @@ -195,6 +193,9 @@ private: void MenuInsertLyXFile(std::string const & filen); /// our workarea WorkArea & workarea() const; + /// range of visible main text paragraphs + void getVisiblePars(ParagraphList::iterator &, ParagraphList::iterator &); + /// LCursor cursor_; }; diff --git a/src/ChangeLog b/src/ChangeLog index 0717046e55..64ec3a1f7d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,4 +1,9 @@ +2003-11-10 André Pönitz + + * BufferView.[Ch]: + * BufferView_pimpl.[Ch]: merge update() and updateInset() + 2003-11-10 André Pönitz * lfuns.h: new LFUN_FINISHED_LEFT, LFUN_FINISHED_RIGHT, diff --git a/src/bufferview_funcs.C b/src/bufferview_funcs.C index 2c28e2b81a..d275b1c4ba 100644 --- a/src/bufferview_funcs.C +++ b/src/bufferview_funcs.C @@ -157,8 +157,7 @@ bool changeDepth(BufferView * bv, LyXText * text, DEPTH_CHANGE type, bool test_o return text->changeDepth(type, true); bool const changed = text->changeDepth(type, false); - if (text->inset_owner) - bv->updateInset(text->inset_owner); + bv->update(); return changed; } diff --git a/src/cursor.C b/src/cursor.C index 347780ae81..3ca9d9b9cb 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -74,7 +74,7 @@ DispatchResult LCursor::dispatch(FuncRequest const & cmd0) lyxerr << "trying to dispatch to inset " << citem.inset_ << endl; DispatchResult res = citem.inset_->dispatch(cmd); if (res.update()) - bv_->updateInset(citem.inset_); + bv_->update(); if (res.dispatched()) { lyxerr << " successfully dispatched to inset " << citem.inset_ << endl; return DispatchResult(true, true); diff --git a/src/frontends/LyXView.C b/src/frontends/LyXView.C index 658a4a25f7..a018e067ce 100644 --- a/src/frontends/LyXView.C +++ b/src/frontends/LyXView.C @@ -199,7 +199,7 @@ Buffer const * const LyXView::updateInset(InsetOld const * inset) const Buffer const * buffer_ptr = 0; if (inset) { buffer_ptr = bufferview_->buffer(); - bufferview_->updateInset(inset); + bufferview_->update(); } return buffer_ptr; } diff --git a/src/insets/insetbibitem.C b/src/insets/insetbibitem.C index f7bb99dd6b..3b18f09854 100644 --- a/src/insets/insetbibitem.C +++ b/src/insets/insetbibitem.C @@ -75,7 +75,7 @@ InsetBibitem::priv_dispatch(FuncRequest const & cmd, if (p.getCmdName().empty()) return DispatchResult(true, true); setParams(p); - cmd.view()->updateInset(this); + cmd.view()->update(); cmd.view()->fitCursor(); return DispatchResult(true, true); } diff --git a/src/insets/insetbox.C b/src/insets/insetbox.C index e626f12b3d..c1902b32bf 100644 --- a/src/insets/insetbox.C +++ b/src/insets/insetbox.C @@ -180,7 +180,6 @@ InsetBox::priv_dispatch(FuncRequest const & cmd, lyxerr << "InsetBox::dispatch MODIFY" << endl; InsetBoxMailer::string2params(cmd.argument, params_); setButtonLabel(); - bv->updateInset(this); result.dispatched(true); result.update(true); return result; diff --git a/src/insets/insetbranch.C b/src/insets/insetbranch.C index b8cc58517a..d54b7b6497 100644 --- a/src/insets/insetbranch.C +++ b/src/insets/insetbranch.C @@ -128,7 +128,6 @@ InsetBranch::priv_dispatch(FuncRequest const & cmd, InsetBranchMailer::string2params(cmd.argument, params); params_.branch = params.branch; setButtonLabel(); - bv->updateInset(this); return DispatchResult(true, true); } diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index cf91680156..1c86249bc0 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -205,7 +205,6 @@ DispatchResult InsetCollapsable::lfunMouseRelease(FuncRequest const & cmd) collapsed_ = false; edit(bv, true); bv->buffer()->markDirty(); - bv->updateInset(this); bv->update(); return result; } @@ -221,7 +220,7 @@ DispatchResult InsetCollapsable::lfunMouseRelease(FuncRequest const & cmd) return result; } result.update(true); - bv->updateInset(this); + bv->update(); bv->buffer()->markDirty(); } else if (!collapsed_ && cmd.y > button_dim.y2) { lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl; @@ -283,7 +282,7 @@ void InsetCollapsable::edit(BufferView * bv, int x, int y) collapsed_ = false; // set this only here as it should be recollapsed only if // it was already collapsed! - bv->updateInset(this); + bv->update(); bv->buffer()->markDirty(); inset.edit(bv, x, y); } else { @@ -401,7 +400,7 @@ void InsetCollapsable::open(BufferView * bv) return; collapsed_ = false; - bv->updateInset(this); + bv->update(); } @@ -411,7 +410,7 @@ void InsetCollapsable::close(BufferView * bv) const return; collapsed_ = true; - bv->updateInset(this); + bv->update(); } diff --git a/src/insets/insetcommand.C b/src/insets/insetcommand.C index 544d25a7da..207a56d2e7 100644 --- a/src/insets/insetcommand.C +++ b/src/insets/insetcommand.C @@ -99,7 +99,7 @@ InsetCommand::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) return DispatchResult(false); setParams(p); - cmd.view()->updateInset(this); + cmd.view()->update(); return DispatchResult(true, true); } diff --git a/src/insets/insetert.C b/src/insets/insetert.C index 03cd6fee24..9cfab1397e 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -427,7 +427,7 @@ InsetERT::priv_dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos) InsetERT::ERTStatus status_; InsetERTMailer::string2params(cmd.argument, status_); status(bv, status_); - bv->updateInset(this); + bv->update(); return DispatchResult(true, true); } @@ -561,7 +561,7 @@ void InsetERT::status(BufferView * bv, ERTStatus const st) const break; } if (bv) { - bv->updateInset(this); + bv->update(); bv->buffer()->markDirty(); } } diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index 714f3327fd..b6239cc34b 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -449,7 +449,7 @@ InsetExternal::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) InsetExternalParams p; InsetExternalMailer::string2params(cmd.argument, buffer, p); setParams(p, buffer); - cmd.view()->updateInset(this); + cmd.view()->update(); return DispatchResult(true, true); } diff --git a/src/insets/insetfloat.C b/src/insets/insetfloat.C index e5510c4bdc..801a180e4c 100644 --- a/src/insets/insetfloat.C +++ b/src/insets/insetfloat.C @@ -175,7 +175,7 @@ InsetFloat::priv_dispatch(FuncRequest const & cmd, params_.wide = params.wide; wide(params_.wide, cmd.view()->buffer()->params()); - cmd.view()->updateInset(this); + cmd.view()->update(); return DispatchResult(true, true); } diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index ec3387a4c8..949120d37b 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -201,7 +201,7 @@ InsetGraphics::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) InsetGraphicsMailer::string2params(cmd.argument, buffer, p); if (!p.filename.empty()) { setParams(p); - cmd.view()->updateInset(this); + cmd.view()->update(); } return DispatchResult(true, true); } diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index db89cc757c..88821066df 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -118,7 +118,7 @@ InsetInclude::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) InsetIncludeMailer::string2params(cmd.argument, p); if (!p.getCmdName().empty()) { set(p, *cmd.view()->buffer()); - cmd.view()->updateInset(this); + cmd.view()->update(); } return DispatchResult(true, true); } diff --git a/src/insets/insetlabel.C b/src/insets/insetlabel.C index 16978b7398..5f225ae608 100644 --- a/src/insets/insetlabel.C +++ b/src/insets/insetlabel.C @@ -83,7 +83,7 @@ InsetLabel::priv_dispatch(FuncRequest const & cmd, } setParams(p); - bv->updateInset(this); + bv->update(); return DispatchResult(true, true); } diff --git a/src/insets/insetminipage.C b/src/insets/insetminipage.C index bb9ca07133..cf2d3f9ea8 100644 --- a/src/insets/insetminipage.C +++ b/src/insets/insetminipage.C @@ -106,7 +106,7 @@ InsetMinipage::priv_dispatch(FuncRequest const & cmd, InsetMinipageMailer::string2params(cmd.argument, params); params_.pos = params.pos; params_.width = params.width; - cmd.view()->updateInset(this); + cmd.view()->update(); return DispatchResult(true, true); } diff --git a/src/insets/insetnote.C b/src/insets/insetnote.C index 1717ce70c3..655ac16702 100644 --- a/src/insets/insetnote.C +++ b/src/insets/insetnote.C @@ -141,7 +141,7 @@ InsetNote::priv_dispatch(FuncRequest const & cmd, case LFUN_INSET_MODIFY: { InsetNoteMailer::string2params(cmd.argument, params_); setButtonLabel(); - bv->updateInset(this); + bv->update(); return DispatchResult(true, true); } diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index e140e3abcc..d293e1d611 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -378,7 +378,7 @@ string const InsetTabular::editMessage() const void InsetTabular::updateLocal(BufferView * bv) const { - bv->updateInset(this); + bv->update(); resetPos(bv); } @@ -522,7 +522,7 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) scroll(cmd.view(), static_cast(strToDbl(cmd.argument))); else scroll(cmd.view(), strToInt(cmd.argument)); - cmd.view()->updateInset(this); + cmd.view()->update(); return DispatchResult(true, true); } diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 68c7a4ce19..a871874b53 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -290,7 +290,7 @@ void InsetText::updateLocal(BufferView * bv, bool /*mark_dirty*/) text_.selection.cursor = text_.cursor; bv->fitCursor(); - bv->updateInset(this); + bv->update(); bv->owner()->view_state_changed(); bv->owner()->updateMenubar(); bv->owner()->updateToolbar(); diff --git a/src/insets/insetwrap.C b/src/insets/insetwrap.C index 8a30af6f54..b1c32be963 100644 --- a/src/insets/insetwrap.C +++ b/src/insets/insetwrap.C @@ -91,7 +91,7 @@ InsetWrap::priv_dispatch(FuncRequest const & cmd, params_.placement = params.placement; params_.width = params.width; - cmd.view()->updateInset(this); + cmd.view()->update(); return DispatchResult(true, true); } diff --git a/src/insets/updatableinset.C b/src/insets/updatableinset.C index 60c4bab900..0bc7e235d3 100644 --- a/src/insets/updatableinset.C +++ b/src/insets/updatableinset.C @@ -99,7 +99,7 @@ UpdatableInset::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) scroll(cmd.view(), static_cast(strToDbl(cmd.argument))); else scroll(cmd.view(), strToInt(cmd.argument)); - cmd.view()->updateInset(this); + cmd.view()->update(); return DispatchResult(true, true); } diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index d9dd11a923..1ce996a4e5 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -155,15 +155,13 @@ string const InsetFormulaBase::editMessage() const void InsetFormulaBase::insetUnlock(BufferView * bv) { if (mathcursor) { - if (mathcursor->inMacroMode()) { + if (mathcursor->inMacroMode()) mathcursor->macroModeClose(); - bv->updateInset(this); - } releaseMathCursor(bv); } if (bv->buffer()) generatePreview(*bv->buffer()); - bv->updateInset(this); + bv->update(); } @@ -209,7 +207,7 @@ void InsetFormulaBase::fitInsetCursor(BufferView * bv) const void InsetFormulaBase::toggleInsetSelection(BufferView * bv) { if (mathcursor) - bv->updateInset(this); + bv->update(); } @@ -219,7 +217,7 @@ DispatchResult InsetFormulaBase::lfunMouseRelease(FuncRequest const & cmd) return DispatchResult(false); BufferView * bv = cmd.view(); - bv->updateInset(this); + bv->update(); //lyxerr << "lfunMouseRelease: buttons: " << cmd.button() << endl; if (cmd.button() == mouse_button::button3) { @@ -238,7 +236,7 @@ DispatchResult InsetFormulaBase::lfunMouseRelease(FuncRequest const & cmd) mathcursor->selClear(); mathcursor->setPos(cmd.x + xo_, cmd.y + yo_); mathcursor->insert(ar); - bv->updateInset(this); + bv->update(); return DispatchResult(true, true); } @@ -285,7 +283,7 @@ DispatchResult InsetFormulaBase::lfunMousePress(FuncRequest const & cmd) return DispatchResult(true, true); } - bv->updateInset(this); + bv->update(); return DispatchResult(true, true); } @@ -313,7 +311,7 @@ DispatchResult InsetFormulaBase::lfunMouseMotion(FuncRequest const & cmd) BufferView * bv = cmd.view(); mathcursor->setPos(cmd.x + xo_, cmd.y + yo_); - bv->updateInset(this); + bv->update(); return DispatchResult(true, true); } @@ -326,7 +324,7 @@ void InsetFormulaBase::edit(BufferView * bv, bool left) bv->cursor().push(this); // if that is removed, we won't get the magenta box when entering an // inset for the first time - bv->updateInset(this); + bv->update(); } @@ -340,7 +338,7 @@ void InsetFormulaBase::edit(BufferView * bv, int x, int y) bv->cursor().push(this); // if that is removed, we won't get the magenta box when entering an // inset for the first time - bv->updateInset(this); + bv->update(); } @@ -739,7 +737,7 @@ InsetFormulaBase::priv_dispatch(FuncRequest const & cmd, } if (result == DispatchResult(true, true)) - bv->updateInset(this); + bv->update(); mathcursor->normalize(); mathcursor->touch(); @@ -862,7 +860,7 @@ bool InsetFormulaBase::searchForward(BufferView * bv, string const & str, mathcursor->setSelection(it, ar.size()); current = it; it.jump(ar.size()); - bv->updateInset(this); + bv->update(); return true; } } diff --git a/src/text2.C b/src/text2.C index 124cdaf48f..fe8c5ddd9d 100644 --- a/src/text2.C +++ b/src/text2.C @@ -273,7 +273,7 @@ void LyXText::toggleInset() else inset->open(bv()); - bv()->updateInset(inset); + bv()->update(); } @@ -724,8 +724,7 @@ void LyXText::setParagraph( setCursor(selection.end.par(), selection.end.pos()); setSelection(); setCursor(tmpcursor.par(), tmpcursor.pos()); - if (inset_owner) - bv()->updateInset(inset_owner); + bv()->update(); } diff --git a/src/text3.C b/src/text3.C index 870c3ff5c6..09eecd3e14 100644 --- a/src/text3.C +++ b/src/text3.C @@ -267,12 +267,12 @@ InsetOld * LyXText::checkInsetHit(int & x, int & y) InsetList::iterator iend = pit->insetlist.end(); for ( ; iit != iend; ++iit) { InsetOld * inset = iit->inset; - lyxerr << "examining inset " << inset - << " xy: " << inset->x() << "/" << inset->y() - << " x: " << inset->x() << "..." << inset->x() + inset->width() - << " y: " << inset->y() - inset->ascent() << "..." - << inset->y() + inset->descent() - << endl; + //lyxerr << "examining inset " << inset + // << " xy: " << inset->x() << "/" << inset->y() + // << " x: " << inset->x() << "..." << inset->x() + inset->width() + // << " y: " << inset->y() - inset->ascent() << "..." + // << inset->y() + inset->descent() + // << endl; if (x >= inset->x() && x <= inset->x() + inset->width() && y >= inset->y() - inset->ascent() @@ -471,7 +471,7 @@ void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind) if (!bv->insertInset(new_inset)) delete new_inset; else - bv->updateInset(new_inset); + bv->update(); } -- 2.39.2