From cf6549229d733a184a6a5e3a908259e51bbd29a9 Mon Sep 17 00:00:00 2001 From: Alfredo Braunstein Date: Wed, 27 Aug 2003 14:55:20 +0000 Subject: [PATCH] moves top_y from lyxtext to BufferView git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7616 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 12 ++++++++++++ src/BufferView.h | 6 ++++++ src/BufferView_pimpl.C | 34 ++++++++++++++++++++++++---------- src/BufferView_pimpl.h | 6 ++++++ src/ChangeLog | 14 ++++++++++++++ src/frontends/screen.C | 26 ++++++++++++++------------ src/insets/insettabular.C | 6 +++--- src/insets/insettext.C | 8 ++++---- src/lyxtext.h | 6 ------ src/rowpainter.C | 17 +++++++---------- src/rowpainter.h | 2 +- src/text.C | 13 ------------- src/text2.C | 15 ++------------- src/text3.C | 30 +++++++++++++++--------------- 14 files changed, 108 insertions(+), 87 deletions(-) diff --git a/src/BufferView.C b/src/BufferView.C index 41b8c53efb..a5541ed7f2 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -225,6 +225,18 @@ void BufferView::center() } +int BufferView::top_y() const +{ + return pimpl_->top_y(); +} + + +void BufferView::top_y(int y) +{ + pimpl_->top_y(y); +} + + string const BufferView::getClipboard() const { return pimpl_->workarea().getClipboard(); diff --git a/src/BufferView.h b/src/BufferView.h index 076361c14e..5848a4639e 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -64,6 +64,12 @@ public: /// return the owning main view LyXView * owner() const; + /// return the visible top y + int top_y() const; + + /// set the visible top y + void top_y(int); + /// resize event has happened void resize(); diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index a62e5004f9..59716a1171 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -273,6 +273,18 @@ Painter & BufferView::Pimpl::painter() const } +void BufferView::Pimpl::top_y(int y) +{ + top_y_ = y; +} + + +int BufferView::Pimpl::top_y() const +{ + return top_y_; +} + + void BufferView::Pimpl::buffer(Buffer * b) { lyxerr[Debug::INFO] << "Setting buffer in BufferView (" @@ -293,6 +305,8 @@ void BufferView::Pimpl::buffer(Buffer * b) // set current buffer buffer_ = b; + top_y_ = 0; + // if we're quitting lyx, don't bother updating stuff if (quitting) return; @@ -310,7 +324,7 @@ void BufferView::Pimpl::buffer(Buffer * b) resizeCurrentBuffer(); // FIXME: needed when ? - bv_->text->top_y(screen().topCursorVisible(bv_->text)); + top_y(screen().topCursorVisible(bv_->text)); // Buffer-dependent dialogs should be updated or // hidden. This should go here because some dialogs (eg ToC) @@ -461,7 +475,7 @@ void BufferView::Pimpl::resizeCurrentBuffer() bv_->theLockingInset(the_locking_inset); } - bv_->text->top_y(screen().topCursorVisible(bv_->text)); + top_y(screen().topCursorVisible(bv_->text)); switchKeyMap(); owner_->busy(false); @@ -484,9 +498,9 @@ void BufferView::Pimpl::updateScrollbar() LyXText const & t = *bv_->text; lyxerr[Debug::GUI] << "Updating scrollbar: h " << t.height << ", top_y() " - << t.top_y() << ", default height " << defaultRowHeight() << endl; + << top_y() << ", default height " << defaultRowHeight() << endl; - workarea().setScrollbarParams(t.height, t.top_y(), defaultRowHeight()); + workarea().setScrollbarParams(t.height, top_y(), defaultRowHeight()); } @@ -499,15 +513,15 @@ void BufferView::Pimpl::scrollDocView(int value) screen().hideCursor(); - bv_->text->top_y(value); + top_y(value); screen().redraw(*bv_); if (!lyxrc.cursor_follows_scrollbar) return; int const height = defaultRowHeight(); - int const first = int((bv_->text->top_y() + height)); - int const last = int((bv_->text->top_y() + workarea().workHeight() - height)); + int const first = top_y() + height; + int const last = top_y() + workarea().workHeight() - height; LyXText * text = bv_->text; if (text->cursor.y() < first) @@ -529,7 +543,7 @@ void BufferView::Pimpl::scroll(int lines) int const line_height = defaultRowHeight(); // The new absolute coordinate - int new_top_y = t->top_y() + lines * line_height; + int new_top_y = top_y() + lines * line_height; // Restrict to a valid value new_top_y = std::min(t->height - 4 * line_height, new_top_y); @@ -538,7 +552,7 @@ void BufferView::Pimpl::scroll(int lines) scrollDocView(new_top_y); // Update the scrollbar. - workarea().setScrollbarParams(t->height, t->top_y(), defaultRowHeight()); + workarea().setScrollbarParams(t->height, top_y(), defaultRowHeight()); } @@ -797,7 +811,7 @@ void BufferView::Pimpl::center() // and also might have moved top_y() must make sure to call // updateScrollbar() currently. Never mind that this is a // pretty obfuscated way of updating t->top_y() - text->top_y(new_y); + top_y(new_y); //screen().draw(); update(); } diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index df03767e9c..2032a09ec3 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -106,7 +106,13 @@ struct BufferView::Pimpl : public boost::signals::trackable { bool workAreaDispatch(FuncRequest const & ev); /// a function should be executed bool dispatch(FuncRequest const & ev); + /// + int top_y() const; + /// + void top_y(int y); private: + /// the y coordinate of the top of the screen + int top_y_; /// An error list (replaces the error insets) ErrorList errorlist_; /// add an error to the list diff --git a/src/ChangeLog b/src/ChangeLog index 1b3f994fa8..828203c8f1 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,17 @@ + +2003-08-27 Alfredo Braunstein + + * lyxtext.h (top_y): move top_y from here + * text.C: + * text2.C: + * text3.C: + * BufferView.[Ch]: + * BufferView_pimpl.[Ch]: to here + * frontends/screen.C: + * insets/insettabular.C: + * insets/insettext.C: adjust + * rowpainter.[Ch] (paintRows): remove LyXText & argument + 2003-08-27 Alfredo Braunstein * BufferView.[Ch]: diff --git a/src/frontends/screen.C b/src/frontends/screen.C index 9da9ef0545..5f647b5a51 100644 --- a/src/frontends/screen.C +++ b/src/frontends/screen.C @@ -163,7 +163,7 @@ void LyXScreen::showCursor(BufferView & bv) int h = ascent + descent; int x = 0; int y = 0; - int const top_y = bv.text->top_y(); + int const top_y = bv.top_y(); if (bv.theLockingInset()) { // Would be nice to clean this up to make some understandable sense... @@ -220,23 +220,25 @@ void LyXScreen::toggleCursor(BufferView & bv) } -bool LyXScreen::fitManualCursor(BufferView * /*bv*/, LyXText * text, +bool LyXScreen::fitManualCursor(BufferView * bv, LyXText * text, int /*x*/, int y, int asc, int desc) { int const vheight = workarea().workHeight(); - int newtop = text->top_y(); - - if (y + desc - text->top_y() >= vheight) + 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 < text->top_y() && text->top_y() > 0) + else if (y - asc < topy && topy > 0) newtop = y - vheight / 4; newtop = max(newtop, 0); // can newtop ever be < 0? (Lgb) - if (newtop == text->top_y()) + if (newtop == topy) return false; - text->top_y(newtop); + bv->top_y(newtop); return true; } @@ -244,7 +246,7 @@ bool LyXScreen::fitManualCursor(BufferView * /*bv*/, LyXText * text, unsigned int LyXScreen::topCursorVisible(LyXText * text) { LyXCursor const & cursor = text->cursor; - int top_y = text->top_y(); + int top_y = text->bv()->top_y(); int newtop = top_y; int const vheight = workarea().workHeight(); @@ -279,8 +281,8 @@ bool LyXScreen::fitCursor(LyXText * text, BufferView * bv) { // Is a change necessary? int const newtop = topCursorVisible(text); - bool const result = (newtop != text->top_y()); - text->top_y(newtop); + bool const result = (newtop != bv->top_y()); + bv->top_y(newtop); return result; } @@ -298,7 +300,7 @@ void LyXScreen::redraw(BufferView & bv) hideCursor(); - int const y = paintText(bv, *bv.text); + int const y = paintText(bv); // maybe we have to clear the screen at the bottom int const y2 = workarea().workHeight(); diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 72068ed550..fd20f0a99d 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -860,10 +860,10 @@ InsetOld::RESULT InsetTabular::localDispatch(FuncRequest const & cmd) clearSelection(); int column = actcol; unlockInsetInInset(bv, the_locking_inset); - if (bv->text->top_y() + bv->painter().paperHeight() < + if (bv->top_y() + bv->painter().paperHeight() < top_baseline + tabular.getHeightOfTabular()) { - bv->scrollDocView(bv->text->top_y() + bv->painter().paperHeight()); + bv->scrollDocView(bv->top_y() + bv->painter().paperHeight()); actcell = tabular.getCellBelow(first_visible_cell) + column; } else { actcell = tabular.getFirstCellInRow(tabular.rows() - 1) + column; @@ -878,7 +878,7 @@ InsetOld::RESULT InsetTabular::localDispatch(FuncRequest const & cmd) int column = actcol; unlockInsetInInset(bv, the_locking_inset); if (top_baseline < 0) { - bv->scrollDocView(bv->text->top_y() - bv->painter().paperHeight()); + bv->scrollDocView(bv->top_y() - bv->painter().paperHeight()); if (top_baseline > 0) actcell = column; else diff --git a/src/insets/insettext.C b/src/insets/insettext.C index e2d4f46981..53e160cc79 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -489,7 +489,7 @@ void InsetText::lfunMousePress(FuncRequest const & cmd) lockInset(bv); int tmp_x = cmd.x - drawTextXOffset; - int tmp_y = cmd.y + dim_.asc - getLyXText(bv)->top_y(); + int tmp_y = cmd.y + dim_.asc - bv->top_y(); InsetOld * inset = getLyXText(bv)->checkInsetHit(tmp_x, tmp_y); if (the_locking_inset) { @@ -524,7 +524,7 @@ void InsetText::lfunMousePress(FuncRequest const & cmd) localDispatch(FuncRequest(bv, LFUN_COPY)); paste_internally = true; } - int old_top_y = text_.top_y(); + int old_top_y = bv->top_y(); text_.setCursorFromCoordinates(cmd.x - drawTextXOffset, cmd.y + dim_.asc); @@ -538,7 +538,7 @@ void InsetText::lfunMousePress(FuncRequest const & cmd) bv->owner()->setLayout(cpar()->layout()->name()); // we moved the view we cannot do mouse selection in this case! - if (getLyXText(bv)->top_y() != old_top_y) + if (bv->top_y() != old_top_y) no_selection = true; old_par = cpar(); // Insert primary selection with middle mouse @@ -568,7 +568,7 @@ bool InsetText::lfunMouseRelease(FuncRequest const & cmd) return the_locking_inset->localDispatch(cmd1); int tmp_x = cmd.x - drawTextXOffset; - int tmp_y = cmd.y + dim_.asc - getLyXText(bv)->top_y(); + int tmp_y = cmd.y + dim_.asc - bv->top_y(); InsetOld * inset = getLyXText(bv)->checkInsetHit(tmp_x, tmp_y); bool ret = false; if (inset) { diff --git a/src/lyxtext.h b/src/lyxtext.h index 827f768aea..abf6aae77f 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -70,12 +70,6 @@ private: public: /// update all cached row positions void updateRowPositions(); - /// get the y coord. of the top of the screen (relative to doc start) - int top_y() const; - /// set the y coord. of the top of the screen (relative to doc start) - void top_y(int newy); - /// set the anchoring row. top_y will be computed relative to this - void anchor_row(RowList::iterator rit); /// InsetText * inset_owner; /// diff --git a/src/rowpainter.C b/src/rowpainter.C index f90f0f2cbf..be7f7e3130 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -1062,7 +1062,7 @@ int paintRows(BufferView const & bv, LyXText const & text, if (row == rit) active = true; if (active) { - RowPainter painter(bv, text, pit, row, y + yo, xo, y + text.top_y()); + RowPainter painter(bv, text, pit, row, y + yo, xo, y + bv.top_y()); painter.paint(); y += row->height(); if (yy + y >= y2) @@ -1080,13 +1080,13 @@ int paintRows(BufferView const & bv, LyXText const & text, } // namespace anon -int paintText(BufferView & bv, LyXText & text) +int paintText(BufferView & bv) { - int const topy = text.top_y(); + int const topy = bv.top_y(); ParagraphList::iterator pit; - RowList::iterator rit = text.getRowNearY(topy, pit); + RowList::iterator rit = bv.text->getRowNearY(topy, pit); int y = rit->y() - topy; - return paintRows(bv, text, pit, rit, 0, y, y, 0); + return paintRows(bv, *bv.text, pit, rit, 0, y, y, 0); } @@ -1102,13 +1102,10 @@ void paintTextInset(BufferView & bv, LyXText & text, int x, int baseline) y += rit->height(); text.nextRow(pit, rit); } - if (y_offset < 0) { - text.top_y(-y_offset); + if (y_offset < 0) paintRows(bv, text, pit, rit, x, 0, y, y); - } else { - text.top_y(y - y_offset); + else paintRows(bv, text, pit, rit, x, 0, y_offset, y_offset); - } } diff --git a/src/rowpainter.h b/src/rowpainter.h index 4c5b5175aa..b663ae8471 100644 --- a/src/rowpainter.h +++ b/src/rowpainter.h @@ -21,7 +21,7 @@ class VSpace; int getLengthMarkerHeight(BufferView const & bv, VSpace const & vsp); /// paint the rows of the main text, return last drawn y value -int paintText(BufferView & bv, LyXText & text); +int paintText(BufferView & bv); /// paint the rows of a text inset void paintTextInset(BufferView & bv, LyXText & text, int x, int y); diff --git a/src/text.C b/src/text.C index 2eeb91d546..1c3f07b9c1 100644 --- a/src/text.C +++ b/src/text.C @@ -103,19 +103,6 @@ void LyXText::updateRowPositions() } -int LyXText::top_y() const -{ - return anchor_y_; -} - - -void LyXText::top_y(int newy) -{ - anchor_y_ = newy; - lyxerr[Debug::GUI] << "changing reference to offset: " << anchor_y_ << endl; -} - - int LyXText::workWidth() const { return inset_owner ? inset_owner->textWidth() : bv()->workWidth(); diff --git a/src/text2.C b/src/text2.C index 45d3be00ce..da8ebec8b1 100644 --- a/src/text2.C +++ b/src/text2.C @@ -1399,17 +1399,6 @@ void LyXText::setCursor(LyXCursor & cur, ParagraphList::iterator pit, cur.ix(int(x)); } else cur.ix(cur.x()); -/* We take out this for the time being because 1) the redraw code is not - prepared to this yet and 2) because some good policy has yet to be decided - while editting: for instance how to act on rows being created/deleted - because of DEPM. -*/ -#if 0 - //if the cursor is in a visible row, anchor to it - int topy = top_y(); - if (topy < y && y < topy + bv()->workHeight()) - anchor_row(row); -#endif } @@ -1694,7 +1683,7 @@ void LyXText::cursorUp(bool selecting) int y = cursor.y() - cursorRow()->baseline() - 1; setCursorFromCoordinates(x, y); if (!selecting) { - int topy = top_y(); + int topy = bv_owner->top_y(); int y1 = cursor.iy() - topy; int y2 = y1; y -= topy; @@ -1720,7 +1709,7 @@ void LyXText::cursorDown(bool selecting) int y = cursor.y() - cursorRow()->baseline() + cursorRow()->height() + 1; setCursorFromCoordinates(x, y); if (!selecting && cursorRow() == cursorIRow()) { - int topy = top_y(); + int topy = bv_owner->top_y(); int y1 = cursor.iy() - topy; int y2 = y1; y -= topy; diff --git a/src/text3.C b/src/text3.C index e2795e8239..35cacddf2f 100644 --- a/src/text3.C +++ b/src/text3.C @@ -146,7 +146,7 @@ namespace { InsetOld * LyXText::checkInsetHit(int & x, int & y) { - int y_tmp = y + top_y(); + int y_tmp = y + bv_owner->top_y(); LyXCursor cur; setCursorFromCoordinates(cur, x, y_tmp); @@ -243,7 +243,7 @@ void LyXText::gotoInset(InsetOld::Code code, bool same_content) void LyXText::cursorPrevious() { - int y = top_y(); + int y = bv_owner->top_y(); RowList::iterator rit = cursorRow(); @@ -282,7 +282,7 @@ void LyXText::cursorPrevious() ParagraphList::iterator pit = cursor.par(); previousRow(pit, rit); setCursor(cur, pit, rit->pos(), false); - if (cur.y() > top_y()) + if (cur.y() > bv_owner->top_y()) cursorUp(true); bv()->updateScrollbar(); } @@ -290,21 +290,21 @@ void LyXText::cursorPrevious() void LyXText::cursorNext() { - int topy = top_y(); + int topy = bv_owner->top_y(); RowList::iterator rit = cursorRow(); if (rit == lastRow()) { int y = cursor.y() - rit->baseline() + cursorRow()->height(); if (y > topy + bv()->workHeight()) - bv()->updateScrollbar(); + bv_owner->updateScrollbar(); return; } - int y = topy + bv()->workHeight(); + int y = topy + bv_owner->workHeight(); if (inset_owner && !topy) { - y -= (bv()->text->cursor.iy() - - bv()->text->top_y() - + bv()->theLockingInset()->insetInInsetY()); + y -= (bv_owner->text->cursor.iy() + - bv_owner->top_y() + + bv_owner->theLockingInset()->insetInInsetY()); } ParagraphList::iterator dummypit; @@ -315,7 +315,7 @@ void LyXText::cursorNext() finishUndo(); int new_y; - if (rit == bv()->text->cursorRow()) { + if (rit == bv_owner->text->cursorRow()) { // we have a row which is taller than the workarea. The // simplest solution is to move to the next row instead. cursorDown(true); @@ -323,7 +323,7 @@ void LyXText::cursorNext() // 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->text->top_y() + bv->workHeight(); + new_y = bv->top_y() + bv->workHeight(); #endif } else { if (inset_owner) { @@ -339,7 +339,7 @@ void LyXText::cursorNext() nextRow(pit, rit); LyXCursor cur; setCursor(cur, pit, rit->pos(), false); - if (cur.y() < top_y() + bv()->workHeight()) + if (cur.y() < bv_owner->top_y() + bv()->workHeight()) cursorDown(true); bv()->updateScrollbar(); } @@ -1218,7 +1218,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd) int start_x = inset_x + tli->scroll(); FuncRequest cmd1 = cmd; cmd1.x = cmd.x - start_x; - cmd1.y = cmd.y - cursor.iy() + bv->text->top_y(); + cmd1.y = cmd.y - cursor.iy() + bv->top_y(); tli->localDispatch(cmd1); break; } @@ -1233,7 +1233,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd) } RowList::iterator cursorrow = bv->text->cursorRow(); - bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->text->top_y()); + bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->top_y()); #if 0 // sorry for this but I have a strange error that the y value jumps at // a certain point. This seems like an error in my xforms library or @@ -1289,7 +1289,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd) paste_internally = true; } - int const screen_first = bv->text->top_y(); + int const screen_first = bv->top_y(); if (bv->theLockingInset()) { // We are in inset locking mode -- 2.39.2