From faa37a30d458ac1cd1babbae05ea3714038a7826 Mon Sep 17 00:00:00 2001 From: Alfredo Braunstein Date: Tue, 11 Nov 2003 13:17:28 +0000 Subject: [PATCH] removing update calls git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8076 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView_pimpl.C | 15 ++++++++------- src/ChangeLog | 6 ++++++ src/bufferview_funcs.C | 23 +++++++++++++++++++++-- src/cursor.C | 9 ++++++++- src/cursor.h | 2 ++ src/dispatchresult.h | 4 ++-- src/insets/ChangeLog | 5 +++++ src/insets/insetcollapsable.C | 9 --------- src/insets/insettext.C | 1 - src/paragraph_funcs.C | 2 +- 10 files changed, 53 insertions(+), 23 deletions(-) diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 6f6d80c3ed..61d686b090 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -616,8 +616,6 @@ void BufferView::Pimpl::update() // check needed to survive LyX startup if (bv_->getLyXText()) { - bv_->getLyXText()->redoCursor(); - // update all 'visible' paragraphs ParagraphList::iterator beg; ParagraphList::iterator end; @@ -625,7 +623,7 @@ void BufferView::Pimpl::update() top_y(), top_y() + workarea().workHeight(), beg, end); bv_->text->redoParagraphs(beg, end); - + bv_->getLyXText()->redoCursor(); updateScrollbar(); } screen().redraw(*bv_); @@ -962,8 +960,10 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd) cmd2.x -= inset->x(); cmd2.y -= inset->y(); res = inset->dispatch(cmd2); - if (res.update()) + if (res.update()) { bv_->update(); + bv_->cursor().updatePos(); + } res.update(false); switch (res.val()) { case FINISHED: @@ -973,6 +973,7 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd) theTempCursor.pop(); bv_->cursor() = theTempCursor; bv_->cursor().innerText()->setCursorFromCoordinates(cmd.x, top_y() + cmd.y); + bv_->cursor().updatePos(); bv_->fitCursor(); return true; default: @@ -987,12 +988,12 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd) lyxerr << "dispatching " << cmd1 << " to surrounding LyXText " << bv_->cursor().innerText() << endl; - cursor_ = theTempCursor; + bv_->cursor() = theTempCursor; theTempCursor.dispatch(cmd1); + bv_->update(); + bv_->cursor().updatePos(); //return DispatchResult(true, true); } - - bv_->update(); // see workAreaKeyPress cursor_timeout.restart(); screen().showCursor(*bv_); diff --git a/src/ChangeLog b/src/ChangeLog index 655258b2ae..faad588306 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2003-11-11 Alfredo Braunstein + + * cursor.[Ch] (updatePos): new function for updating the y + position of the tip inset + * bufferview_funcs.C (put_selection_at): + * BufferView_pimpl.C (workAreaDispatch): rationalise update calls 2003-11-11 André Pönitz diff --git a/src/bufferview_funcs.C b/src/bufferview_funcs.C index d275b1c4ba..3f67f87d0e 100644 --- a/src/bufferview_funcs.C +++ b/src/bufferview_funcs.C @@ -19,6 +19,7 @@ #include "buffer.h" #include "bufferparams.h" #include "BufferView.h" +#include "cursor.h" #include "gettext.h" #include "language.h" #include "LColor.h" @@ -263,6 +264,20 @@ void replaceSelection(LyXText * text) } +/* +if the fitCursor call refers to some point in never-explored-land, then we +don't have y information in insets there, then we cannot even do an update +to get it (because we need the y infomation for setting top_y first). So +this is solved in put_selection_at with: + +- setting top_y to the y of the outerPar (that has good info) +- calling update +- calling cursor().updatePos() +- then call fitCursor() + +Ab. +*/ + void put_selection_at(BufferView * bv, PosIterator const & cur, int length, bool backwards) { @@ -272,8 +287,12 @@ void put_selection_at(BufferView * bv, PosIterator const & cur, LyXText * text = par.text(bv); par.lockPath(bv); - + //hack for the chicken and egg problem + if (par.inset()) + bv->top_y(par.outerPar()->y); + bv->update(); text->setCursor(cur.pit(), cur.pos()); + bv->cursor().updatePos(); if (length) { text->setSelectionRange(length); @@ -281,7 +300,7 @@ void put_selection_at(BufferView * bv, PosIterator const & cur, if (backwards) text->cursor = text->selection.start; } - + bv->fitCursor(); bv->update(); } diff --git a/src/cursor.C b/src/cursor.C index c3d7c95080..383e615cb2 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -113,7 +113,7 @@ void LCursor::push(UpdatableInset * inset) { lyxerr << "LCursor::push() inset: " << inset << endl; data_.push_back(CursorItem(inset)); - cached_y_ = bv_->top_y() + inset->y(); + cached_y_ = bv_->top_y() + innerInset()->y(); } @@ -157,6 +157,13 @@ LyXText * LCursor::innerText() const } +void LCursor::updatePos() +{ + if (!data_.empty()) + cached_y_ = bv_->top_y() + innerInset()->y(); +} + + void LCursor::getPos(int & x, int & y) const { if (data_.empty()) { diff --git a/src/cursor.h b/src/cursor.h index a7f981b31e..6f43f2c0c4 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -75,6 +75,8 @@ public: LyXText * innerText() const; /// returns x,y position void getPos(int & x, int & y) const; + /// cache the absolute coordinate from the top inset + void updatePos(); /// friend std::ostream & operator<<(std::ostream &, LCursor const &); public: diff --git a/src/dispatchresult.h b/src/dispatchresult.h index 19aa2b979c..16ed98e9d6 100644 --- a/src/dispatchresult.h +++ b/src/dispatchresult.h @@ -51,9 +51,9 @@ public: DispatchResult(bool dis) : dispatched_(dis), update_(false), val_(NONE) {} DispatchResult(bool dis, bool update) - : dispatched_(dis), update_(true), val_(NONE) {} + : dispatched_(dis), update_(update), val_(NONE) {} DispatchResult(bool dis, dispatch_result_t val) - : dispatched_(dis), update_(false), val_(val) {} + : dispatched_(dis), update_(true), val_(val) {} dispatch_result_t val() const { return val_; } void val(dispatch_result_t drt) { val_ = drt; diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 4f730fa10c..d4cf4786b7 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,8 @@ +2003-11-11 Alfredo Braunstein + + * insettext.C: remove all update calls + * insetcollapsable.C: remove all update calls + 2003-11-11 Alfredo Braunstein * insettext.C (updateLocal, insertInset, setFont): remove diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 6b9367c989..9f57b483dc 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -205,8 +205,6 @@ DispatchResult InsetCollapsable::lfunMouseRelease(FuncRequest const & cmd) lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl; collapsed_ = false; edit(bv, true); - bv->buffer()->markDirty(); - bv->update(); return DispatchResult(true, true); } @@ -214,12 +212,9 @@ DispatchResult InsetCollapsable::lfunMouseRelease(FuncRequest const & cmd) if (!collapsed_) { collapsed_ = true; lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl; - bv->update(); return DispatchResult(false, FINISHED_RIGHT); } collapsed_ = false; - bv->update(); - bv->buffer()->markDirty(); lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl; } else if (!collapsed_ && cmd.y > button_dim.y2) { lyxerr << "InsetCollapsable::lfunMouseRelease 4" << endl; @@ -281,8 +276,6 @@ 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->update(); - bv->buffer()->markDirty(); inset.edit(bv, x, y); } else { if (y <= button_dim.y2) @@ -398,7 +391,6 @@ void InsetCollapsable::open(BufferView * bv) return; collapsed_ = false; - bv->update(); } @@ -408,7 +400,6 @@ void InsetCollapsable::close(BufferView * bv) const return; collapsed_ = true; - bv->update(); } diff --git a/src/insets/insettext.C b/src/insets/insettext.C index bdc65b83cd..b505230851 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -290,7 +290,6 @@ void InsetText::updateLocal(BufferView * bv, bool /*mark_dirty*/) text_.selection.cursor = text_.cursor; // bv->fitCursor(); - bv->update(); bv->owner()->view_state_changed(); bv->owner()->updateMenubar(); bv->owner()->updateToolbar(); diff --git a/src/paragraph_funcs.C b/src/paragraph_funcs.C index 884b6933dc..74d5249916 100644 --- a/src/paragraph_funcs.C +++ b/src/paragraph_funcs.C @@ -628,6 +628,6 @@ void getParsInRange(ParagraphList & pl, for (--beg; beg != begpar && beg->y > ystart; --beg) ; - for (end = beg ; end != endpar && end->y < yend; ++end) + for (end = beg ; end != endpar && end->y <= yend; ++end) ; } -- 2.39.2