From 614fbe566cc69d0be881db4af31850c42e08afad Mon Sep 17 00:00:00 2001 From: Alfredo Braunstein Date: Thu, 20 Nov 2003 10:38:12 +0000 Subject: [PATCH] cursor work + absolute coords for lyxtext git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8107 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView_pimpl.C | 2 +- src/ChangeLog | 6 +++ src/insets/ChangeLog | 4 ++ src/insets/insetcollapsable.C | 1 + src/insets/insettext.C | 10 ++-- src/lyxfunc.C | 1 + src/lyxtext.h | 12 ++--- src/text2.C | 35 ++++--------- src/text3.C | 94 ++++++----------------------------- 9 files changed, 51 insertions(+), 114 deletions(-) diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 72bc9ec154..4bc6c64f44 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -486,7 +486,7 @@ void BufferView::Pimpl::scroll(int lines) // Restrict to a valid value new_top_y = std::min(t->height - 4 * line_height, new_top_y); new_top_y = std::max(0, new_top_y); - + scrollDocView(new_top_y); // Update the scrollbar. diff --git a/src/ChangeLog b/src/ChangeLog index 42db2fcd4e..62b6286984 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2003-11-20 Alfredo Braunstein + + * lyxtext.h: add x0_, y0_ + * text3.C (cursorPrevious, cursorNext): rewrite (using x0_, y0_) + * text2.C (cursorDown, cursorUp): rewrite (using x0_, y0_) + 2003-11-18 Alfredo Braunstein * text2.C (setCursorIntern): move the x_target update here * diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 55acddedec..a2dc0c8560 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,7 @@ +2003-11-20 Alfredo Braunstein + + * insettext.C (draw): sets LyXText absolute coordinates + 2003-11-20 Angus Leeming * insetcharstyle.C (latex, linuxdoc, docbook, plaintext): squash warnings diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index ba95556760..84e4e4a285 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -283,6 +283,7 @@ void InsetCollapsable::edit(BufferView * bv, int x, int y) else 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 b1d559b739..e90b8d1898 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -38,6 +38,7 @@ #include "paragraph_funcs.h" #include "ParagraphParameters.h" #include "rowpainter.h" +#include "lyxrow.h" #include "sgml.h" #include "texrow.h" #include "undo.h" @@ -257,6 +258,9 @@ void InsetText::draw(PainterInfo & pi, int x, int y) const x += TEXT_TO_INSET_OFFSET; + text_.x0_ = x; + text_.y0_ = y - text_.firstRow()->ascent_of_text() + bv->top_y(); + paintTextInset(*bv, text_, x, y); if (drawFrame_ == ALWAYS || drawFrame_ == LOCKED) @@ -340,10 +344,8 @@ void InsetText::edit(BufferView * bv, int x, int y) lyxerr << "InsetText::edit xy" << endl; old_par = -1; sanitizeEmptyText(bv); - text_.setCursorFromCoordinates(x, y + dim_.asc); - text_.cursor.x(text_.cursor.x()); - bv->x_target(text_.cursor.x()); - + text_.setCursorFromCoordinates(x - text_.x0_, y + bv->top_y() + - text_.y0_); text_.clearSelection(); finishUndo(); diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 6891eee207..3b85af5b7e 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -1409,6 +1409,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose) if (view()->available()) { view()->fitCursor(); view()->update(); + view()->cursor().updatePos(); // if we executed a mutating lfun, mark the buffer as dirty if (!getStatus(func).disabled() diff --git a/src/lyxtext.h b/src/lyxtext.h index 1ad4c89d76..62ceb7071c 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -461,19 +461,19 @@ public: /// bool checkAndActivateInset(bool front); - private: - /** Cursor related data. - Later this variable has to be removed. There should be now internal - cursor in a text */ - /// - ///TextCursor cursor_; + /// prohibit this as long as there are back pointers... LyXText(LyXText const &); // cache for cursorPar() mutable ParagraphList::iterator cache_par_; mutable int cache_pos_; + +public: + /// absolute document pixel coordinates of this LyXText + int x0_; + int y0_; }; /// return the default height of a row in pixels, considering font zoom diff --git a/src/text2.C b/src/text2.C index 40aad755fa..9c1bb6ac5d 100644 --- a/src/text2.C +++ b/src/text2.C @@ -74,7 +74,7 @@ LyXText::LyXText(BufferView * bv, InsetText * inset, bool ininset, ParagraphList & paragraphs) : height(0), width(0), inset_owner(inset), bv_owner(bv), in_inset_(ininset), paragraphs_(¶graphs), - cache_pos_(-1) + cache_pos_(-1), x0_(0), y0_(0) {} @@ -1404,7 +1404,7 @@ void LyXText::setCursorIntern(paroffset_type par, pos_type pos, bool setfont, bool boundary) { setCursor(cursor, par, pos, boundary); - bv()->x_target(cursor.x()); + bv()->x_target(cursor.x() + x0_); if (setfont) setCurrentFont(); } @@ -1562,7 +1562,7 @@ void LyXText::setCursorFromCoordinates(int x, int y) deleteEmptyParagraphMechanism(old_cursor); } - +//gets LyXText coordinates void LyXText::setCursorFromCoordinates(LyXCursor & cur, int x, int y) { // Get the row first. @@ -1710,24 +1710,16 @@ void LyXText::cursorUp(bool selecting) { ParagraphList::iterator cpit = cursorPar(); Row const & crow = *cpit->getRow(cursor.pos()); -#if 1 - int x = bv()->x_target(); + int x = bv()->x_target() - x0_; int y = cursor.y() - crow.baseline() - 1; setCursorFromCoordinates(x, y); if (!selecting) { - int topy = bv()->top_y(); - int y1 = cursor.y() - topy; - y -= topy; - InsetOld * inset_hit = checkInsetHit(x, y1); + y += y0_ - bv()->top_y(); + lyxerr << "y:" << y << " y0: " << y0_ << endl; + InsetOld * inset_hit = checkInsetHit(bv()->x_target(), y); if (inset_hit && isHighlyEditableInset(inset_hit)) inset_hit->edit(bv(), x, y); } -#else - lyxerr << "cursorUp: y " << cursor.y() << " bl: " << - crow.baseline() << endl; - setCursorFromCoordinates(bv()->x_target(), - cursor.y() - crow.baseline() - 1); -#endif } @@ -1735,22 +1727,15 @@ void LyXText::cursorDown(bool selecting) { ParagraphList::iterator cpit = cursorPar(); Row const & crow = *cpit->getRow(cursor.pos()); -#if 1 - int x = bv()->x_target(); + int x = bv()->x_target() - x0_; int y = cursor.y() - crow.baseline() + crow.height() + 1; setCursorFromCoordinates(x, y); if (!selecting) { - int topy = bv()->top_y(); - int y1 = cursor.y() - topy; - y -= topy; - InsetOld * inset_hit = checkInsetHit(x, y1); + y += y0_ - bv()->top_y(); + InsetOld * inset_hit = checkInsetHit(bv()->x_target(), y); if (inset_hit && isHighlyEditableInset(inset_hit)) inset_hit->edit(bv(), x, y); } -#else - setCursorFromCoordinates(bv()->x_target(), - cursor.y() - crow.baseline() + crow.height() + 1); -#endif } diff --git a/src/text3.C b/src/text3.C index b44e491be0..77ae09de38 100644 --- a/src/text3.C +++ b/src/text3.C @@ -362,103 +362,40 @@ void LyXText::gotoInset(InsetOld::Code code, bool same_content) void LyXText::cursorPrevious() { - int y = bv()->top_y(); - ParagraphList::iterator cpit = cursorPar(); - RowList::iterator crit = cpit->getRow(cursor.pos()); + RowList::iterator crit = cursorRow(); - if (isFirstRow(cpit, *crit)) { - if (y > 0) - bv()->updateScrollbar(); - return; - } + int x = bv()->x_target() - x0_; + int y = bv()->top_y() - y0_; + setCursorFromCoordinates(x, y); - setCursorFromCoordinates(bv()->x_target(), y); - finishUndo(); - - if (crit == bv()->text->cursorRow()) { + if (crit == cursorRow()) { // we have a row which is taller than the workarea. The // simplest solution is to move to the previous row instead. cursorUp(true); - return; } - int new_y = + crit->height() - bv()->workHeight() + 1; - - if (inset_owner) { - new_y += bv()->text->cursor.y() - + bv()->cursor().innerInset()->insetInInsetY() - + y; - } else { - new_y += cursor.y() - crit->baseline(); - } - - previousRow(cpit, crit); - LyXCursor cur; - setCursor(cur, parOffset(cpit), crit->pos(), false); - if (cur.y() > bv()->top_y()) - cursorUp(true); bv()->updateScrollbar(); + finishUndo(); } void LyXText::cursorNext() { - int topy = bv()->top_y(); + RowList::iterator crit = cursorRow(); - ParagraphList::iterator cpit = cursorPar(); - RowList::iterator crit = cpit->getRow(cursor.pos()); + int x = bv()->x_target() - x0_; + int y = bv()->top_y() + bv()->workHeight() - y0_; + setCursorFromCoordinates(x, y); - if (isLastRow(cpit, *crit)) { - int y = cursor.y() - crit->baseline() + crit->height(); - if (y > topy + bv()->workHeight()) - bv()->updateScrollbar(); - return; - } - - int y = topy + bv()->workHeight(); - if (inset_owner && !topy) { - y += - bv()->text->cursor.y() - + bv()->top_y() - - bv()->cursor().innerInset()->insetInInsetY(); - } - - ParagraphList::iterator dummypit; - Row const & row = *getRowNearY(y, dummypit); - y = dummypit->y + row.y_offset(); - - setCursorFromCoordinates(bv()->x_target(), y); - // + bv->workHeight()); - finishUndo(); - - int new_y; - if (crit == bv()->text->cursorRow()) { + if (crit == cursorRow()) { // we have a row which is taller than the workarea. The // simplest solution is to move to the next row instead. cursorDown(true); - return; - // This is what we used to do, so we wouldn't skip right past - // tall rows, but it's not working right now. -#if 0 - new_y = bv->top_y() + bv->workHeight(); -#endif } - - if (inset_owner) { - new_y = bv()->text->cursor.y() - + bv()->cursor().innerInset()->insetInInsetY() - + y - crit->baseline(); - } else { - new_y = cursor.y() - crit->baseline(); - } - - - nextRow(cpit, crit); - LyXCursor cur; - setCursor(cur, parOffset(cpit), crit->pos(), false); - if (cur.y() < bv()->top_y() + bv()->workHeight()) - cursorDown(true); + bv()->updateScrollbar(); + finishUndo(); } @@ -1355,7 +1292,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) setCursorFromCoordinates(cmd.x, cmd.y); selection.cursor = cursor; finishUndo(); - bv->x_target(cursor.x()); + bv->x_target(cursor.x() + x0_); if (bv->fitCursor()) selection_possible = false; @@ -1596,11 +1533,12 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) case LFUN_FINISHED_UP: lyxerr << "swallow LFUN_FINISHED_UP" << endl; + cursorUp(true); break; case LFUN_FINISHED_DOWN: lyxerr << "swallow LFUN_FINISHED_DOWN" << endl; - cursorRight(true); + cursorDown(true); break; default: