From 29eaa7609488e8a0614699112f563c836271447b Mon Sep 17 00:00:00 2001 From: Alfredo Braunstein Date: Tue, 11 Nov 2003 09:06:41 +0000 Subject: [PATCH] some fitcursor work git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8074 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView_pimpl.C | 31 ++++++++++++++++++++++++------- src/ChangeLog | 6 ++++++ src/cursor.C | 5 +++-- src/cursor.h | 3 +++ src/frontends/ChangeLog | 3 +++ src/frontends/screen.C | 2 +- src/insets/ChangeLog | 4 ++++ src/insets/insetcollapsable.C | 5 ++--- src/insets/insettext.C | 6 +++--- 9 files changed, 49 insertions(+), 16 deletions(-) diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index c99eb53632..6f6d80c3ed 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -343,9 +343,22 @@ void BufferView::Pimpl::buffer(Buffer * b) bool BufferView::Pimpl::fitCursor() { lyxerr << "BufferView::Pimpl::fitCursor." << endl; - bool ret; -#ifndef LOCK + int x,y; + bv_->cursor().getPos(x, y); + + if (y < top_y() || y > top_y() + workarea().workHeight()) { + int newtop = y - workarea().workHeight() / 2; + newtop = std::max(0, newtop); + top_y(newtop); + updateScrollbar(); + return true; + } + return false; + +// dead code below + bool ret; +#if 0 UpdatableInset * tli = static_cast(cursor_.innerInset()); if (tli) { @@ -354,7 +367,8 @@ bool BufferView::Pimpl::fitCursor() } else { ret = screen().fitCursor(bv_->text, bv_); } -#else +#endif +#if 0 ret = screen().fitCursor(bv_->text, bv_); #endif @@ -958,7 +972,8 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd) case FINISHED_DOWN: theTempCursor.pop(); bv_->cursor() = theTempCursor; - bv_->cursor().innerText()->setCursorFromCoordinates(cmd.x, cmd.y); + bv_->cursor().innerText()->setCursorFromCoordinates(cmd.x, top_y() + cmd.y); + bv_->fitCursor(); return true; default: lyxerr << "not dispatched by inner inset val: " << res.val() << endl; @@ -969,13 +984,15 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd) // otherwise set cursor to surrounding LyXText if (!res.dispatched()) { lyxerr << "cursor is: " << bv_->cursor() << endl; - lyxerr << "dispatching " << cmd1 << " to surrounding LyXText " - << bv_->cursor().innerText() << endl; - theTempCursor.innerText()->dispatch(cmd1); + lyxerr << "dispatching " << cmd1 + << " to surrounding LyXText " + << bv_->cursor().innerText() << endl; cursor_ = theTempCursor; + theTempCursor.dispatch(cmd1); //return DispatchResult(true, true); } + bv_->update(); // see workAreaKeyPress cursor_timeout.restart(); screen().showCursor(*bv_); diff --git a/src/ChangeLog b/src/ChangeLog index 64ec3a1f7d..45864a67b3 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2003-11-11 Alfredo Braunstein + + * cursor.C (getPos): return absolute cached y coord + + * BufferView_pimpl.C (fitCursor): new simplistic code + (workAreaDispatch): add a fitCursor call 2003-11-10 André Pönitz diff --git a/src/cursor.C b/src/cursor.C index 3ca9d9b9cb..c3d7c95080 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -113,6 +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(); } @@ -161,7 +162,7 @@ void LCursor::getPos(int & x, int & y) const if (data_.empty()) { x = bv_->text->cursor.x(); y = bv_->text->cursor.y(); - y -= bv_->top_y(); +// y -= bv_->top_y(); } else { // Would be nice to clean this up to make some understandable sense... UpdatableInset * inset = innerInset(); @@ -176,7 +177,7 @@ void LCursor::getPos(int & x, int & y) const //y = inset->insetInInsetY() + bv_->text->cursor.y(); inset->getCursorPos(bv_, x, y); x += inset->x(); - y += inset->y(); + y += cached_y_; } } diff --git a/src/cursor.h b/src/cursor.h index ce5fb19d77..a7f981b31e 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -82,6 +82,9 @@ public: std::vector data_; /// BufferView * bv_; +private: + /// + int cached_y_; }; #endif // LYXCURSOR_H diff --git a/src/frontends/ChangeLog b/src/frontends/ChangeLog index 4a52910086..fad235d0d5 100644 --- a/src/frontends/ChangeLog +++ b/src/frontends/ChangeLog @@ -1,3 +1,6 @@ +2003-11-11 Alfredo Braunstein + + * screen.C (showCursor): use absolute coords form LCursor 2003-11-10 André Pönitz diff --git a/src/frontends/screen.C b/src/frontends/screen.C index 6e8e43fd1e..fc8540e09a 100644 --- a/src/frontends/screen.C +++ b/src/frontends/screen.C @@ -173,7 +173,7 @@ void LyXScreen::showCursor(BufferView & bv) int x = 0; int y = 0; bv.cursor().getPos(x, y); - y -= ascent; + y -= ascent + bv.top_y(); //lyxerr << "LyXScreen::showCursor x: " << x << " y: " << y << endl; // if it doesn't fit entirely on the screen, don't try to show it diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 7c6dab1af8..4f730fa10c 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,7 @@ +2003-11-11 Alfredo Braunstein + + * insettext.C (updateLocal, insertInset, setFont): remove + fitCursor calls 2003-11-10 André Pönitz diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 88cfedffbc..6b9367c989 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -268,9 +268,9 @@ bool InsetCollapsable::hitButton(FuncRequest const & cmd) const void InsetCollapsable::edit(BufferView * bv, bool left) { lyxerr << "InsetCollapsable: edit left/right" << endl; - bv->cursor().push(this); inset.edit(bv, left); open(bv); + bv->cursor().push(this); } @@ -288,8 +288,7 @@ void InsetCollapsable::edit(BufferView * bv, int x, int y) if (y <= button_dim.y2) inset.edit(bv, x, 0); else - inset.edit(bv, x, - ascent() + y - height_collapsed() + inset.ascent()); + inset.edit(bv, x, ascent() + y - height_collapsed() + inset.ascent()); } bv->cursor().push(this); } diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 85dc75e69a..bdc65b83cd 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -289,7 +289,7 @@ void InsetText::updateLocal(BufferView * bv, bool /*mark_dirty*/) if (!text_.selection.set()) text_.selection.cursor = text_.cursor; - bv->fitCursor(); +// bv->fitCursor(); bv->update(); bv->owner()->view_state_changed(); bv->owner()->updateMenubar(); @@ -780,7 +780,7 @@ bool InsetText::insertInset(BufferView * bv, InsetOld * inset) { inset->setOwner(this); text_.insertInset(inset); - bv->fitCursor(); +// bv->fitCursor(); updateLocal(bv, true); return true; } @@ -847,7 +847,7 @@ void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall, if (selectall) text_.clearSelection(); - bv->fitCursor(); +// bv->fitCursor(); updateLocal(bv, true); } -- 2.39.2