I've implemented the "decoupling" between cursor and screen in CoordBranch, similar as described in another thread.
current most obvious problems: - missing fitCursor - scrolling not so smooth "one par at a time" - some visual problems in math with super/subscripts (no idea why) - some undo crash (no so frequent) And much more fun! Alfredo
? ChangeLog-old ? PosIterator.C-save ? PosIterator.h-save ? bfri.C ? boost ? config ? config.log ? config.status ? development ? intl ? lib ? libtool ? m4 ? po ? sourcedoc ? src ? textcursor.C-save ? textcursor.h-save ? insets/insetcollapsable-save.C ? insets/safe ? mathed/safe Index: BufferView.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView.C,v retrieving revision 1.254.2.1 diff -u -p -u -r1.254.2.1 BufferView.C --- BufferView.C 3 Nov 2004 22:33:52 -0000 1.254.2.1 +++ BufferView.C 4 Nov 2004 11:05:13 -0000 @@ -349,3 +349,27 @@ LCursor const & BufferView::cursor() con { return pimpl_->cursor_; } + + +lyx::pit_type & BufferView::anchor_ref() +{ + return pimpl_->anchor_ref_; +} + + +lyx::pit_type BufferView::anchor_ref() const +{ + return pimpl_->anchor_ref_; +} + + +int & BufferView::offset_ref() +{ + return pimpl_->offset_ref_; +} + + +int BufferView::offset_ref() const +{ + return pimpl_->offset_ref_; +} Index: BufferView.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView.h,v retrieving revision 1.179.2.1 diff -u -p -u -r1.179.2.1 BufferView.h --- BufferView.h 3 Nov 2004 22:33:53 -0000 1.179.2.1 +++ BufferView.h 4 Nov 2004 11:05:13 -0000 @@ -144,6 +144,15 @@ public: /// clear the X selection void unsetXSel(); + /// access to offset + int & offset_ref(); + /// access to offset + int offset_ref() const; + /// access to anchor + lyx::pit_type & anchor_ref(); + /// access to anchor + lyx::pit_type anchor_ref() const; + /// access to full cursor LCursor & cursor(); /// access to full cursor Index: BufferView_pimpl.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v retrieving revision 1.558.2.1 diff -u -p -u -r1.558.2.1 BufferView_pimpl.C --- BufferView_pimpl.C 3 Nov 2004 22:33:53 -0000 1.558.2.1 +++ BufferView_pimpl.C 4 Nov 2004 11:05:14 -0000 @@ -133,7 +133,8 @@ T * getInsetByCode(LCursor & cur, InsetB BufferView::Pimpl::Pimpl(BufferView & bv, LyXView * owner, int width, int height) : bv_(&bv), owner_(owner), buffer_(0), cursor_timeout(400), - using_xterm_cursor(false), cursor_(bv) + using_xterm_cursor(false), cursor_(bv) , + anchor_ref_(0), offset_ref_(0) { xsel_cache_.set = false; @@ -403,8 +404,7 @@ void BufferView::Pimpl::updateScrollbar( << " curr par: " << bv_->cursor().bottom().pit() << " default height " << defaultRowHeight() << endl; - workarea().setScrollbarParams(t.paragraphs().size(), - bv_->cursor().bottom().pit(), defaultRowHeight()); + workarea().setScrollbarParams(t.paragraphs().size(), anchor_ref_, 1); } @@ -417,6 +417,12 @@ void BufferView::Pimpl::scrollDocView(in screen().hideCursor(); + anchor_ref_ = value; + offset_ref_ = 0; + lyxerr << "scrolling: " << value << std::endl; + update(); + + // top_y(value); // screen().redraw(*bv_); // @@ -435,6 +441,7 @@ void BufferView::Pimpl::scrollDocView(in // if (y > last) // y = last; // text->setCursorFromCoordinates(bv_->cursor(), 0, y); + owner_->updateLayoutChoice(); } Index: BufferView_pimpl.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.h,v retrieving revision 1.124.2.1 diff -u -p -u -r1.124.2.1 BufferView_pimpl.h --- BufferView_pimpl.h 3 Nov 2004 22:33:54 -0000 1.124.2.1 +++ BufferView_pimpl.h 4 Nov 2004 11:05:14 -0000 @@ -175,5 +175,11 @@ private: } xsel_cache_; /// LCursor cursor_; + /// + /// + lyx::pit_type anchor_ref_; + /// + int offset_ref_; + }; #endif // BUFFERVIEW_PIMPL_H Index: cursor.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.C,v retrieving revision 1.111.2.1 diff -u -p -u -r1.111.2.1 cursor.C --- cursor.C 3 Nov 2004 22:33:56 -0000 1.111.2.1 +++ cursor.C 4 Nov 2004 11:05:14 -0000 @@ -15,6 +15,7 @@ #include "BufferView.h" #include "buffer.h" #include "cursor.h" +#include "coordcache.h" #include "CutAndPaste.h" #include "debug.h" #include "dispatchresult.h" @@ -371,11 +372,15 @@ void LCursor::getDim(int & asc, int & de void LCursor::getPos(int & x, int & y) const { - coordOffset(x, y); // offset from inner inset + if (theCoords.pars_[bottom().text()].find(pit()) == theCoords.pars_[bottom().text()].end()) { + x = -1; + y = -1; + lyxerr << "cursor out of view" << std::endl; + return; + } + coordOffset(x, y); // offset from outer paragraph x += bottom().text()->cursorX(bottom()); - //y += yo_; - y = yo_; - //lyxerr << "LCursor getPos: x: " << x << " y: " << y << endl; + y += theCoords.pars_[bottom().text()][bottom().pit()].y_; } Index: rowpainter.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/rowpainter.C,v retrieving revision 1.135.2.1 diff -u -p -u -r1.135.2.1 rowpainter.C --- rowpainter.C 3 Nov 2004 22:34:02 -0000 1.135.2.1 +++ rowpainter.C 4 Nov 2004 11:05:14 -0000 @@ -45,6 +45,7 @@ using lyx::pit_type; using std::endl; using std::max; +using std::min; using std::string; @@ -738,8 +739,7 @@ void paintPar RowList::iterator const rb = par.rows().begin(); RowList::iterator const re = par.rows().end(); RowList::iterator rit = rb; - // we store the upper y paragraph position in the cache - theCoords.pars_[&text][pit] = Point(0, y - rb->ascent()); + theCoords.pars_[&text][pit] = Point(0, y); while (true) { RowPainter rp(pi, text, pit, *rit, x, y); @@ -774,9 +774,8 @@ void foo() void paintText(BufferView const & bv) { LyXText * const text = bv.text(); - LCursor const & cur = bv.cursor(); - CursorSlice const & sl = cur.bottom(); - pit_type const pit = sl.pit(); + pit_type const pit = min(bv.anchor_ref(), int(text->paragraphs().size())); + int const off = bv.offset_ref(); Painter & pain = bv.painter(); int pit1 = pit; @@ -790,17 +789,17 @@ void paintText(BufferView const & bv) // text->redoParagraph(pit); - Paragraph const & par = sl.paragraph(); - + //Paragraph const & par = text->paragraphs()[pit]; // find y begin of outer paragraph containing the cursor - int xo = 0, yo = 0; - cur.coordOffset(xo, yo); // this is the offset from inner insets - int const y = cur.yo_ - yo; - lyxerr << "outer par starts at y: " << y << endl; + //int xo = 0, yo = 0; + //cur.coordOffset(xo, yo); // this is the offset from inner insets + //int const y = cur.yo_ - yo; + //lyxerr << "outer par starts at y: " << y << endl; // redo paragraphs above cursor if necessary - int y1 = y; - while (y1 >= 0 && pit1 > 0) { + + int y1 = text->getPar(pit1).ascent(); + while (y1 > off && pit1 > 0) { y1 -= text->getPar(pit1).ascent(); --pit1; text->redoParagraph(pit1); @@ -808,16 +807,18 @@ void paintText(BufferView const & bv) } // redo paragraphs below cursor if necessary -// int y2 = y + par.height(); - int y2 = y; - while (y2 < bv.workHeight() && pit2 < int(npit) - 1) { + int y2 = -text->getPar(pit2).descent(); + while (y2 < off + bv.workHeight() && pit2 < int(npit) - 1) { y2 += text->getPar(pit2).descent(); ++pit2; text->redoParagraph(pit2); y2 += text->getPar(pit2).ascent(); } - // take care of acsent of first and descent of last line + // take care of ascent of first and descent of last line + y1 -= off; + y2 -= off; + int yy = y1; y1 -= text->getPar(pit1).ascent(); y2 += text->getPar(pit2).descent(); @@ -829,7 +830,7 @@ void paintText(BufferView const & bv) // draw selection PainterInfo pi(const_cast<BufferView *>(&bv), pain); - text->drawSelection(pi, 0, y); +// text->drawSelection(pi, 0, y); // draw contents for (pit_type pit = pit1; pit <= pit2; ) { Index: text.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v retrieving revision 1.584.2.1 diff -u -p -u -r1.584.2.1 text.C --- text.C 3 Nov 2004 22:34:02 -0000 1.584.2.1 +++ text.C 4 Nov 2004 11:05:15 -0000 @@ -2176,7 +2176,7 @@ void LyXText::setCursorFromCoordinates(L pit_type pit = getPitNearY(y); BOOST_ASSERT(theCoords.pars_.find(this) != theCoords.pars_.end()); BOOST_ASSERT(theCoords.pars_[this].find(pit) != theCoords.pars_[this].end()); - int yy = theCoords.pars_[this][pit].y_; + int yy = theCoords.pars_[this][pit].y_ - pars_[pit].ascent(); lyxerr << "setCursorFromCoordinates: x: " << x << " y: " << y << " pit: " << pit << " yy: " << yy << endl; Index: text2.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v retrieving revision 1.587.2.1 diff -u -p -u -r1.587.2.1 text2.C --- text2.C 3 Nov 2004 22:34:03 -0000 1.587.2.1 +++ text2.C 4 Nov 2004 11:05:15 -0000 @@ -1141,7 +1141,7 @@ pit_type LyXText::getPitNearY(int y) con for (; it != et; ++it) { lyxerr << " examining: pit: " << it->first << " y: " << it->second.y_ << endl; - if (it->first >= pit && it->second.y_ < y) { + if (it->first >= pit && it->second.y_ - pars_[it->first].ascent() < y) { pit = it->first; yy = it->second.y_; }