From: Alfredo Braunstein Date: Thu, 13 Nov 2003 08:50:26 +0000 (+0000) Subject: fitCursor work X-Git-Tag: 1.6.10~15800 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=79ae54d4c018e4d9600d6d09d3ff22fd4505baab;p=features.git fitCursor work git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8079 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/BufferView.C b/src/BufferView.C index af246c8a0b..55b1bfec87 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -369,25 +369,6 @@ void BufferView::replaceWord(string const & replacestring) } -bool BufferView::fitLockedInsetCursor(int x, int y, int asc, int desc) -{ - lyxerr << "BufferView::fitLockedInsetCursor x: " << x - << " y: " << y << std::endl; - UpdatableInset * tli = - static_cast(cursor().innerInset()); - if (tli && available()) { - lyxerr << " text->cursor.y: " << text->cursor.y() << std::endl; - lyxerr << " insetInInsetY: " << tli->insetInInsetY() << std::endl; - y += text->cursor.y() + tli->insetInInsetY(); - if (screen().fitManualCursor(this, text, x, y, asc, desc)) { - updateScrollbar(); - return true; - } - } - return false; -} - - void BufferView::hideCursor() { screen().hideCursor(); diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 61d686b090..7620633646 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -313,7 +313,7 @@ void BufferView::Pimpl::buffer(Buffer * b) resizeCurrentBuffer(); // FIXME: needed when ? - top_y(screen().topCursorVisible(bv_->text)); + fitCursor(); // Buffer-dependent dialogs should be updated or // hidden. This should go here because some dialogs (eg ToC) @@ -343,42 +343,11 @@ void BufferView::Pimpl::buffer(Buffer * b) bool BufferView::Pimpl::fitCursor() { lyxerr << "BufferView::Pimpl::fitCursor." << endl; - - 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); + if (screen().fitCursor(bv_)) { updateScrollbar(); return true; } return false; - -// dead code below - bool ret; -#if 0 - UpdatableInset * tli = - static_cast(cursor_.innerInset()); - if (tli) { - tli->fitInsetCursor(bv_); - ret = true; - } else { - ret = screen().fitCursor(bv_->text, bv_); - } -#endif -#if 0 - ret = screen().fitCursor(bv_->text, bv_); -#endif - - //dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE)); - - // We need to always update, in case we did a - // paste and we stayed anchored to a row, but - // the actual height of the doc changed ... - updateScrollbar(); - return ret; } @@ -446,7 +415,7 @@ void BufferView::Pimpl::resizeCurrentBuffer() } } - top_y(screen().topCursorVisible(bv_->text)); + fitCursor(); switchKeyMap(); owner_->busy(false); @@ -973,8 +942,8 @@ 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(); + if (bv_->fitCursor()) + bv_->update(); return true; default: lyxerr << "not dispatched by inner inset val: " << res.val() << endl; @@ -984,24 +953,26 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd) // otherwise set cursor to surrounding LyXText if (!res.dispatched()) { - lyxerr << "cursor is: " << bv_->cursor() << endl; + lyxerr << "temp cursor is: " << theTempCursor << endl; lyxerr << "dispatching " << cmd1 << " to surrounding LyXText " - << bv_->cursor().innerText() << endl; + << theTempCursor.innerText() << endl; bv_->cursor() = theTempCursor; - theTempCursor.dispatch(cmd1); - bv_->update(); - bv_->cursor().updatePos(); + res = bv_->cursor().innerText()->dispatch(cmd1); + if (bv_->fitCursor() || res.update()) + bv_->update(); + //return DispatchResult(true, true); } // see workAreaKeyPress cursor_timeout.restart(); screen().showCursor(*bv_); - // FIXME: we should skip these when selecting - owner_->updateLayoutChoice(); - owner_->updateToolbar(); -// fitCursor(); + // skip these when selecting + if (cmd.action != LFUN_MOUSE_MOTION) { + owner_->updateLayoutChoice(); + owner_->updateToolbar(); + } // slight hack: this is only called currently when we // clicked somewhere, so we force through the display @@ -1295,7 +1266,6 @@ bool BufferView::Pimpl::insertInset(InsetOld * inset, string const & lout) string(), 0); } - bv_->cursor().innerText()->insertInset(inset); update(); diff --git a/src/ChangeLog b/src/ChangeLog index 790fba51b3..ccb6e2bbef 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2003-11-13 Alfredo Braunstein + + * BufferView_pimpl.C (fitCursor): call screen().fitCursor() + * BufferView.C (fitLockedInsetCursor): remove + * cursor.[Ch] (getDim): add + * text.C (getRowNearY): add faster version + * text3.C: remove some update calls 2003-11-12 Martin Vermeer diff --git a/src/cursor.C b/src/cursor.C index 383e615cb2..3aa3273cf9 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -20,6 +20,7 @@ #include "lfuns.h" #include "lyxtext.h" #include "paragraph.h" +#include "lyxrow.h" #include "insets/updatableinset.h" #include "insets/insettabular.h" @@ -164,6 +165,19 @@ void LCursor::updatePos() } +void LCursor::getDim(int & asc, int & desc) const +{ + LyXText * txt = innerText(); + + if (txt) { + Row const & row = *txt->cursorRow(); + asc = row.baseline(); + desc = row.height() - asc; + } else + innerInset()->getCursorDim(bv_, asc, desc); +} + + void LCursor::getPos(int & x, int & y) const { if (data_.empty()) { diff --git a/src/cursor.h b/src/cursor.h index 6f43f2c0c4..07efdf737a 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; + /// returns cursor dimension + void getDim(int & asc, int & desc) const; /// cache the absolute coordinate from the top inset void updatePos(); /// diff --git a/src/frontends/ChangeLog b/src/frontends/ChangeLog index fad235d0d5..8324571171 100644 --- a/src/frontends/ChangeLog +++ b/src/frontends/ChangeLog @@ -1,3 +1,10 @@ +2003-11-13 Alfredo Braunstein + + * screen.[Ch] (fitCursor): use LCursor::getDim, simplify + (fitManualCursor): remove + (topCursorVisible): remove + + 2003-11-11 Alfredo Braunstein * screen.C (showCursor): use absolute coords form LCursor diff --git a/src/frontends/screen.C b/src/frontends/screen.C index fc8540e09a..7d4299eb7b 100644 --- a/src/frontends/screen.C +++ b/src/frontends/screen.C @@ -204,70 +204,39 @@ void LyXScreen::toggleCursor(BufferView & bv) } -bool LyXScreen::fitManualCursor(BufferView * bv, LyXText *, - int x, int y, int asc, int desc) +bool LyXScreen::fitCursor(BufferView * bv) { - lyxerr << "LyXScreen::fitManualCursor x: " << x << " y: " << y << std::endl; - int const vheight = workarea().workHeight(); - int const topy = bv->top_y(); - int newtop = topy; - - if (y + desc - topy >= vheight) - newtop = y - 3 * vheight / 4; // the scroll region must be so big!! - else if (y - asc < topy && topy > 0) - newtop = y - vheight / 4; - - newtop = max(newtop, 0); // can newtop ever be < 0? (Lgb) - - if (newtop == topy) - return false; - - bv->top_y(newtop); - return true; -} - - -unsigned int LyXScreen::topCursorVisible(LyXText * text) -{ - LyXCursor const & cursor = text->cursor; - int top_y = text->bv()->top_y(); + int const top_y = bv->top_y(); + int const h = workarea().workHeight(); int newtop = top_y; - unsigned int const vheight = workarea().workHeight(); - - Row & row = *text->cursorPar()->getRow(cursor.pos()); - - if (int(cursor.y() - row.baseline() + row.height() - top_y) >= vheight) { - if (row.height() < vheight - && row.height() > vheight / 4) { - newtop = cursor.y() - + row.height() - - row.baseline() - vheight; - } else { - // scroll down, the scroll region must be so big!! - newtop = cursor.y() - vheight / 2; - } - - } else if (int(cursor.y() - row.baseline()) < top_y && top_y > 0) { - if (row.height() < vheight && row.height() > vheight / 4) { - newtop = cursor.y() - row.baseline(); - } else { - // scroll up - newtop = cursor.y() - vheight / 2; + int x, y, asc, desc; + + bv->cursor().getPos(x, y); + bv->cursor().getDim(asc, desc); + + bool const big_row = h / 4 < asc + desc && asc + desc < h; + + if (y + desc - top_y >= h) { + if (big_row) + newtop = y + desc - h; + else + newtop = y - h / 2; + + } else if (top_y > max(y - asc, 0)) { + if (big_row) + newtop = y - asc; + else { + newtop = y - h / 2; newtop = min(newtop, top_y); } } - return max(newtop, 0); -} - + newtop = max(newtop, 0); + if (newtop == top_y) + return false; -bool LyXScreen::fitCursor(LyXText * text, BufferView * bv) -{ - // Is a change necessary? - int const newtop = topCursorVisible(text); - bool const result = (newtop != bv->top_y()); bv->top_y(newtop); - return result; + return true; } diff --git a/src/frontends/screen.h b/src/frontends/screen.h index 8b8959c5f8..2845592450 100644 --- a/src/frontends/screen.h +++ b/src/frontends/screen.h @@ -36,42 +36,17 @@ public: virtual ~LyXScreen(); - /** - * fit the cursor onto the visible work area, scrolling if necessary - * @param bv the buffer view - * @param vheight the height of the visible region - * @param base_y the top of the lyxtext to look at - * @param x the new x position - * @param y the new y position - * @param a ascent of the cursor's row - * @param d descent of the cursor's row - * @return true if the work area needs scrolling as a result - */ - bool fitManualCursor(BufferView * bv, LyXText * text, - int x, int y, int a, int d); - /// redraw the screen, without using existing pixmap virtual void redraw(BufferView & bv); - /** - * topCursorVisible - get a new "top" to make the cursor visible - * in a LyXText - * - * This helper function calculates a new y co-ordinate for - * the top of the containing region such that the cursor contained - * within the LyXText is "nicely" visible. - */ - virtual unsigned int topCursorVisible(LyXText *); - /** * fitCursor - fit the cursor onto the work area - * @param text the text containing the cursor * @param bv the bufferview * @return true if a change was necessary * * Scrolls the screen so that the cursor is visible */ - virtual bool fitCursor(LyXText *, BufferView *); + virtual bool fitCursor(BufferView *); /// hide the visible cursor, if it is visible void hideCursor(); diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index d3c92e409b..6b46edea90 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,11 @@ +2003-11-13 Alfredo Braunstein + + * insetcollapsable.[Ch] (fitInsetCursor): remove + * insettabular.[Ch] (fitInsetCursor): remove + * insettext.[Ch] (fitInsetCursor): remove + * updatableinset.[Ch] (fitInsetCursor): remove + (getCursorDIm): add virtual + 2003-11-12 Martin Vermeer * src/insets/Makefile.am: diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 9f57b483dc..72df386bca 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -433,12 +433,6 @@ bool InsetCollapsable::insetAllowed(InsetOld::Code code) const } -void InsetCollapsable::fitInsetCursor(BufferView * bv) const -{ - inset.fitInsetCursor(bv); -} - - void InsetCollapsable::setLabelFont(LyXFont & f) { labelfont_ = f; diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index f8f095b719..c201859768 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -79,8 +79,6 @@ public: /// get the screen x,y of the cursor void getCursorPos(BufferView *, int & x, int & y) const; /// - void fitInsetCursor(BufferView * bv) const; - /// void setFont(BufferView *, LyXFont const &, bool toggleall = false, bool selectall = false); /// diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index a38ab49e58..e8351e5cae 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -973,22 +973,6 @@ void InsetTabular::getCursorPos(BufferView *, int & x, int & y) const } -void InsetTabular::fitInsetCursor(BufferView * bv) const -{ - if (the_locking_inset) { - the_locking_inset->fitInsetCursor(bv); - return; - } - - LyXFont font; - int const asc = font_metrics::maxAscent(font); - int const desc = font_metrics::maxDescent(font); - resetPos(bv); - - bv->fitLockedInsetCursor(cursorx_, cursory_, asc, desc); -} - - void InsetTabular::setPos(BufferView * bv, int x, int y) const { cursory_ = 0; diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index 28862fb362..4dde1e33c8 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -196,8 +196,6 @@ private: void drawCellSelection(Painter &, int x, int baseline, int row, int column, int cell) const; /// - void fitInsetCursor(BufferView *) const; - /// void setPos(BufferView *, int x, int y) const; /// DispatchResult moveRight(BufferView *, bool lock); diff --git a/src/insets/insettext.C b/src/insets/insettext.C index b505230851..47f29bb362 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -699,15 +699,6 @@ int InsetText::insetInInsetY() const } -void InsetText::fitInsetCursor(BufferView * bv) const -{ - LyXFont const font = text_.getFont(cpar(), cpos()); - int const asc = font_metrics::maxAscent(font); - int const desc = font_metrics::maxDescent(font); - bv->fitLockedInsetCursor(cx(), cy(), asc, desc); -} - - DispatchResult InsetText::moveRight(BufferView * bv) { if (text_.cursorPar()->isRightToLeftPar(bv->buffer()->params())) diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 752ecf3669..2d67e152d7 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -93,8 +93,6 @@ public: /// int insetInInsetY() const; /// - void fitInsetCursor(BufferView *) const; - /// bool insertInset(BufferView *, InsetOld *); /// bool insetAllowed(InsetOld::Code) const; diff --git a/src/insets/updatableinset.C b/src/insets/updatableinset.C index 8463104b8d..7ab4647b43 100644 --- a/src/insets/updatableinset.C +++ b/src/insets/updatableinset.C @@ -23,6 +23,8 @@ #include "support/lstrings.h" +#include + using lyx::support::strToDbl; using lyx::support::strToInt; @@ -35,10 +37,6 @@ InsetOld::EDITABLE UpdatableInset::editable() const } -void UpdatableInset::fitInsetCursor(BufferView *) const -{} - - void UpdatableInset::scroll(BufferView * bv, float s) const { if (!s) { @@ -107,3 +105,9 @@ UpdatableInset::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) return DispatchResult(false); } } + + +void UpdatableInset::getCursorDim(BufferView *, int &, int &) const +{ + BOOST_ASSERT(false); +} diff --git a/src/insets/updatableinset.h b/src/insets/updatableinset.h index 361c554716..f8d124c26c 100644 --- a/src/insets/updatableinset.h +++ b/src/insets/updatableinset.h @@ -29,10 +29,10 @@ public: /// virtual EDITABLE editable() const; - /// - virtual void fitInsetCursor(BufferView *) const; - /// FIXME + /// return the cursor pos, relative to the inset pos virtual void getCursorPos(BufferView *, int &, int &) const {} + /// return the cursor dim + virtual void getCursorDim(BufferView *, int &, int &) const; /// virtual bool insertInset(BufferView *, InsetOld *) { return false; } /// diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index dae1f38efd..a5103425e8 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,6 @@ +2003-11-13 Alfredo Braunstein + + * formulabase.[Ch] (getCursorDim): add 2003-11-10 André Pönitz diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index 7ba15987d9..f815d86ba5 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -186,18 +186,14 @@ void InsetFormulaBase::getCursorPos(BufferView *, int & x, int & y) const } -void InsetFormulaBase::fitInsetCursor(BufferView * bv) const +void InsetFormulaBase::getCursorDim(BufferView * bv, + int & asc, int & desc) const { if (!mathcursor) return; - int x, y, asc, des; asc = 10; - des = 2; + desc = 2; //math_font_max_dim(font_, asc, des); - getCursorPos(bv, x, y); - //y += yo_; - //lyxerr << "fitInsetCursor: x: " << x << " y: " << y << " yo: " << yo_ << endl; - bv->fitLockedInsetCursor(x, y, asc, des); } @@ -745,7 +741,6 @@ InsetFormulaBase::priv_dispatch(FuncRequest const & cmd, toggleInsetSelection(bv); if (result.dispatched()) { - fitInsetCursor(bv); revealCodes(bv); cmd.view()->stuffClipboard(mathcursor->grabSelection()); } else { diff --git a/src/mathed/formulabase.h b/src/mathed/formulabase.h index f79f69662d..14455e6947 100644 --- a/src/mathed/formulabase.h +++ b/src/mathed/formulabase.h @@ -45,9 +45,9 @@ public: /// what appears in the minibuffer when opening virtual std::string const editMessage() const; /// - virtual void fitInsetCursor(BufferView *) const; - /// FIXME virtual void getCursorPos(BufferView *, int &, int &) const; + /// + virtual void getCursorDim(BufferView *, int &, int &) const; /// get the absolute document x,y of the cursor virtual void getCursor(BufferView & bv, int & x, int & y) const; /// diff --git a/src/text.C b/src/text.C index 995c935e1c..a2617f2db4 100644 --- a/src/text.C +++ b/src/text.C @@ -1467,18 +1467,20 @@ RowList::iterator LyXText::getRowNearY(int y, ParagraphList::iterator & pit) const { //lyxerr << "getRowNearY: y " << y << endl; -#if 0 - ParagraphList::iterator const pend = ownerParagraphs().end(); +#if 1 + ParagraphList::iterator const + pend = boost::prior(ownerParagraphs().end()); pit = ownerParagraphs().begin(); while (int(pit->y + pit->height) < y && pit != pend) ++pit; - RowList::iterator rit = pit->rows.begin(); - RowList::iterator const rend = pit->rows.end(); - while (int(pit->y + rit->y_offset()) < y && rit != rend) - ++rit; + RowList::iterator rit = pit->rows.end(); + RowList::iterator const rbegin = pit->rows.begin(); + do { + --rit; + } while (rit != rbegin && int(pit->y + rit->y_offset()) > y); + return rit; - #else pit = boost::prior(ownerParagraphs().end()); diff --git a/src/text3.C b/src/text3.C index 4b1cbdf7ff..36a10e54f5 100644 --- a/src/text3.C +++ b/src/text3.C @@ -227,7 +227,7 @@ namespace { if (!lt->selection.set()) bv->haveSelection(false); - bv->update(); +// bv->update(); bv->switchKeyMap(); } @@ -495,8 +495,7 @@ void doInsertInset(LyXText * lt, FuncRequest const & cmd, inset->edit(bv, true); if (gotsel && pastesel) bv->owner()->dispatch(FuncRequest(LFUN_PASTE)); - } - else + } else delete inset; } } @@ -1290,7 +1289,6 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) selection.cursor = cursor; cursorEnd(); setSelection(); - bv->update(); bv->haveSelection(selection.set()); } break; @@ -1300,7 +1298,6 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) break; if (cmd.button() == mouse_button::button1) { selectWord(lyx::WHOLE_WORD_STRICT); - bv->update(); bv->haveSelection(selection.set()); } break; @@ -1352,15 +1349,15 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) << bv->text->cursor.y() << endl; #endif // This is to allow jumping over large insets - if (cursorrow == bv->text->cursorRow()) { + if (cursorrow == cursorRow()) { if (cmd.y >= bv->workHeight()) - bv->text->cursorDown(false); + cursorDown(false); else if (cmd.y < 0) - bv->text->cursorUp(false); + cursorUp(false); } bv->text->setSelection(); - bv->update(); +// bv->update(); break; } @@ -1428,13 +1425,13 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) } case LFUN_MOUSE_RELEASE: { - // do nothing if we used the mouse wheel if (!bv->buffer()) break; + // do nothing if we used the mouse wheel if (cmd.button() == mouse_button::button4 || cmd.button() == mouse_button::button5) - break; + return DispatchResult(true, false); selection_possible = false;