Continuing in the same vein. Trying to make this stuff somewhat understandable. Note that this probably makes CHANGED_IN_DRAW somewhat slower.
7 files changed, 95 insertions(+), 130 deletions(-) Next we see if we can remove the "refresh_y" altogether in the postRowPaint() case. It should not be needed. Comments ? regards john Index: BufferView_pimpl.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v retrieving revision 1.343 diff -u -p -r1.343 BufferView_pimpl.C --- BufferView_pimpl.C 13 Mar 2003 13:56:18 -0000 1.343 +++ BufferView_pimpl.C 16 Mar 2003 19:32:06 -0000 @@ -501,7 +501,7 @@ void BufferView::Pimpl::update() { if (!bv_->theLockingInset() || !bv_->theLockingInset()->nodraw()) { LyXText::text_status st = bv_->text->status(); - screen().update(bv_->text, bv_); + screen().update(*bv_); bool fitc = false; while (bv_->text->status() == LyXText::CHANGED_IN_DRAW) { bv_->text->fullRebreak(bv_); @@ -518,11 +518,13 @@ void BufferView::Pimpl::update() } fitc = true; bv_->text->status(bv_, st); - screen().update(bv_->text, bv_); + screen().update(*bv_); } + // do this here instead of in the screen::update because of // the above loop! - bv_->text->status(bv_, LyXText::UNCHANGED); + bv_->text->clearPaint(); + if (fitc) fitCursor(); } Index: lyxtext.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtext.h,v retrieving revision 1.142 diff -u -p -r1.142 lyxtext.h --- lyxtext.h 16 Mar 2003 00:45:30 -0000 1.142 +++ lyxtext.h 16 Mar 2003 19:32:07 -0000 @@ -187,29 +187,6 @@ public: /// mutable Row * need_break_row; - /** - * The pixel y position from which to repaint the screen. - * The position is absolute along the height of outermost - * lyxtext (I think). NEED_MORE_REFRESH and NEED_LITTLE_REFRESH - * repaints both use this as a starting point (if it's within - * the viewable portion of the lyxtext). - */ - mutable int refresh_y; - /** - * The row from which to repaint the screen, used by screen.c. - * This must be set if the pending update is NEED_LITTLE_REFRESH. - * It doesn't make any difference for NEED_MORE_REFRESH. - */ - mutable Row * refresh_row; - - /** - * Return the status. This represents what repaints are - * pending after some operation (e.g. inserting a char). - */ - text_status status() const; - - /// Set the status to make a paint pending. - void status(BufferView *, text_status) const; /// clear any pending paints void clearPaint(); @@ -230,14 +207,35 @@ public: /// Inset::RESULT dispatch(FuncRequest const & cmd); + friend class LyXScreen; + + /** + * Return the status. This represents what repaints are + * pending after some operation (e.g. inserting a char). + */ + text_status status() const; + private: + /** + * The pixel y position from which to repaint the screen. + * The position is absolute along the height of outermost + * lyxtext (I think). NEED_MORE_REFRESH and NEED_LITTLE_REFRESH + * repaints both use this as a starting point (if it's within + * the viewable portion of the lyxtext). + */ + int refresh_y; + /** + * The row from which to repaint the screen, used by screen.c. + * This must be set if the pending update is NEED_LITTLE_REFRESH. + * It doesn't make any difference for NEED_MORE_REFRESH. + */ + mutable Row * refresh_row; + + /// refresh status + text_status status_; + /// only the top-level LyXText has this non-zero BufferView * bv_owner; - - /** wether the screen needs a refresh, - starting with refresh_y - */ - mutable text_status status_; public: /** returns a pointer to the row near the specified y-coordinate diff -u -p -r1.290 text2.C --- text2.C 16 Mar 2003 00:45:31 -0000 1.290 +++ text2.C 16 Mar 2003 19:32:19 -0000 @@ -54,17 +54,19 @@ using lyx::pos_type; LyXText::LyXText(BufferView * bv) : height(0), width(0), top_row_(0), top_row_offset_(0), inset_owner(0), the_locking_inset(0), need_break_row(0), - refresh_y(0), refresh_row(0), bv_owner(bv), - status_(LyXText::UNCHANGED), firstrow(0), lastrow(0) -{} + bv_owner(bv), firstrow(0), lastrow(0) +{ + clearPaint(); +} LyXText::LyXText(InsetText * inset) : height(0), width(0), top_row_(0), top_row_offset_(0), inset_owner(inset), the_locking_inset(0), need_break_row(0), - refresh_y(0), refresh_row(0), bv_owner(0), - status_(LyXText::UNCHANGED), firstrow(0), lastrow(0) -{} + bv_owner(0), firstrow(0), lastrow(0) +{ + clearPaint(); +} void LyXText::init(BufferView * bview, bool reinit) @@ -321,10 +323,14 @@ void LyXText::removeRow(Row * row) const lyx::Assert(!row->next()); lastrow = row_prev; } + + /* FIXME: when we cache the bview, this should just + * become a postPaint(), I think */ if (refresh_row == row) { refresh_row = row_prev ? row_prev : row->next(); - // what about refresh_y, refresh_height + // what about refresh_y } + if (top_row_ == row) { if (row->next()) { top_row_ = row->next(); @@ -713,10 +719,8 @@ void LyXText::redoHeightOfParagraph(Buff setHeightOfRow(bview, tmprow); } - // we can set the refreshing parameters now - status(bview, LyXText::NEED_MORE_REFRESH); - refresh_y = y; - refresh_row = tmprow; + postPaint(*bview, y); + setCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary()); } @@ -734,12 +738,7 @@ void LyXText::redoDrawingOfParagraph(Buf y -= tmprow->height(); } - // we can set the refreshing parameters now - if (status_ == LyXText::UNCHANGED || y < refresh_y) { - refresh_y = y; - refresh_row = tmprow; - } - status(bview, LyXText::NEED_MORE_REFRESH); + postPaint(*bview, y); setCursor(bview, cur.par(), cur.pos()); } @@ -774,12 +773,8 @@ void LyXText::redoParagraphs(BufferView } } - // we can set the refreshing parameters now - status(bview, LyXText::NEED_MORE_REFRESH); - refresh_y = y; - refresh_row = tmprow->previous(); /* the real refresh row will - be deleted, so I store - the previous here */ + Row * prevrow = tmprow->previous(); + // remove it if (tmprow->next()) tmppar = tmprow->next()->par(); @@ -817,13 +812,12 @@ void LyXText::redoParagraphs(BufferView } while (tmppar && tmppar != endpar); // this is because of layout changes - if (refresh_row) { - refresh_y -= refresh_row->height(); - setHeightOfRow(bview, refresh_row); + if (prevrow) { + setHeightOfRow(bview, prevrow); + const_cast<LyXText *>(this)->postPaint(*bview, y - prevrow->height()); } else { - refresh_row = firstrow; - refresh_y = 0; - setHeightOfRow(bview, refresh_row); + setHeightOfRow(bview, firstrow); + const_cast<LyXText *>(this)->postPaint(*bview, 0); } if (tmprow && tmprow->next()) @@ -1105,9 +1099,7 @@ void LyXText::setParagraph(BufferView * while (tmppar != selection.start.par()->previous()) { setCursor(bview, tmppar, 0); - status(bview, LyXText::NEED_MORE_REFRESH); - refresh_row = cursor.row(); - refresh_y = cursor.y() - cursor.row()->baseline(); + postPaint(*bview, cursor.y() - cursor.row()->baseline()); cursor.par()->params().lineTop(line_top); cursor.par()->params().lineBottom(line_bottom); cursor.par()->params().pagebreakTop(pagebreak_top); @@ -1646,9 +1638,7 @@ void LyXText::checkParagraph(BufferView if (z >= row->pos()) { // set the dimensions of the row above y -= row->previous()->height(); - refresh_y = y; - refresh_row = row->previous(); - status(bview, LyXText::NEED_MORE_REFRESH); + postPaint(*bview, y); breakAgain(bview, row->previous()); @@ -1663,14 +1653,13 @@ void LyXText::checkParagraph(BufferView int const tmpheight = row->height(); pos_type const tmplast = row->lastPos(); - refresh_y = y; - refresh_row = row; breakAgain(bview, row); - if (row->height() == tmpheight && row->lastPos() == tmplast) - status(bview, LyXText::NEED_VERY_LITTLE_REFRESH); - else - status(bview, LyXText::NEED_MORE_REFRESH); + if (row->height() == tmpheight && row->lastPos() == tmplast) { + postRowPaint(*bview, row, y); + } else { + postPaint(*bview, y); + } // check the special right address boxes if (par->layout()->margintype == MARGIN_RIGHT_ADDRESS_BOX) { @@ -2337,13 +2326,11 @@ bool LyXText::deleteEmptyParagraphMechan // ok, we will delete anything LyXCursor tmpcursor; - // make sure that you do not delete any environments - status(bview, LyXText::NEED_MORE_REFRESH); deleted = true; if (old_cursor.row()->previous()) { - refresh_row = old_cursor.row()->previous(); - refresh_y = old_cursor.y() - old_cursor.row()->baseline() - refresh_row->height(); + const_cast<LyXText *>(this)->postPaint(*bview, old_cursor.y() - old_cursor.row()->baseline() + - old_cursor.row()->previous()->height()); tmpcursor = cursor; cursor = old_cursor; // that undo can restore the right cursor position Paragraph * endpar = old_cursor.par()->next(); @@ -2373,8 +2360,9 @@ bool LyXText::deleteEmptyParagraphMechan } setHeightOfRow(bview, refresh_row); } else { - refresh_row = old_cursor.row()->next(); - refresh_y = old_cursor.y() - old_cursor.row()->baseline(); + Row * nextrow = old_cursor.row()->next(); + const_cast<LyXText *>(this)->postPaint(*bview, + old_cursor.y() - old_cursor.row()->baseline()); tmpcursor = cursor; cursor = old_cursor; // that undo can restore the right cursor position @@ -2400,8 +2388,8 @@ bool LyXText::deleteEmptyParagraphMechan the parindent that can occur or dissappear. The next row can change its height, if there is another layout before */ - if (refresh_row) { - breakAgain(bview, refresh_row); + if (nextrow) { + breakAgain(bview, nextrow); updateCounters(bview); } } @@ -2464,35 +2452,6 @@ LyXText::text_status LyXText::status() c } -void LyXText::status(BufferView * bview, LyXText::text_status new_status) const -{ - // We should not lose information from previous status - // sets, or we'll forget to repaint the other bits - // covered by the NEED_MORE_REFRESH - if (new_status == NEED_VERY_LITTLE_REFRESH - && status_ == NEED_MORE_REFRESH) - return; - - status_ = new_status; - - if (new_status == UNCHANGED) - return; - - if (!inset_owner) - return; - - LyXText * t = bview->text; - - // We are an inset's lyxtext. Tell the top-level lyxtext - // it needs to update the row we're in. - t->status(bview, NEED_VERY_LITTLE_REFRESH); - if (!t->refresh_row) { - t->refresh_row = t->cursor.row(); - t->refresh_y = t->cursor.y() - t->cursor.row()->baseline(); - } -} - - void LyXText::clearPaint() { status_ = UNCHANGED; @@ -2509,10 +2468,18 @@ void LyXText::postChangedInDraw() void LyXText::postPaint(BufferView & bv, int start_y) { + text_status old = status_; + status_ = NEED_MORE_REFRESH; - refresh_y = start_y; refresh_row = 0; + if (old != UNCHANGED && refresh_y < start_y) { + lyxerr << "Paint already pending from above" << endl; + return; + } + + refresh_y = start_y; + if (!inset_owner) return; @@ -2533,13 +2500,21 @@ void LyXText::postPaint(BufferView & bv, // make refresh_y be 0, and use row->y etc. void LyXText::postRowPaint(BufferView & bv, Row * row, int start_y) { + if (status_ != UNCHANGED && refresh_y < start_y) { + lyxerr << "Paint already pending from above" << endl; + lyxerr << "This is row " << row << " at start " << start_y << endl; + lyxerr << "We have already row " << refresh_row << " at start " << refresh_y << endl; + return; + } else { + refresh_y = start_y; + } + // FIXME: shouldn't this check that we're not updating // above the existing refresh_y ?? if (status_ == NEED_MORE_REFRESH) return; status_ = NEED_VERY_LITTLE_REFRESH; - refresh_y = start_y; refresh_row = row; if (!inset_owner) Index: undo_funcs.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/undo_funcs.C,v retrieving revision 1.33 diff -u -p -r1.33 undo_funcs.C --- undo_funcs.C 20 Feb 2003 17:39:47 -0000 1.33 +++ undo_funcs.C 16 Mar 2003 19:32:20 -0000 @@ -66,7 +66,7 @@ void finishNoUndo(BufferView * bv) freezeUndo(); bv->unlockInset(bv->theLockingInset()); finishUndo(); - bv->text->status(bv, LyXText::NEED_MORE_REFRESH); + bv->text->postPaint(*bv, 0); unFreezeUndo(); } @@ -266,7 +266,7 @@ bool textHandleUndo(BufferView * bv, Und } finishUndo(); - bv->text->status(bv, LyXText::NEED_MORE_REFRESH); + bv->text->postPaint(*bv, 0); return true; } Index: frontends/screen.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/screen.C,v retrieving revision 1.31 diff -u -p -r1.31 screen.C --- frontends/screen.C 6 Mar 2003 20:21:18 -0000 1.31 +++ frontends/screen.C 16 Mar 2003 19:32:21 -0000 @@ -244,11 +244,11 @@ bool LyXScreen::fitCursor(LyXText * text } -void LyXScreen::update(LyXText * text, BufferView * bv, - int yo, int xo) +void LyXScreen::update(BufferView & bv, int yo, int xo) { int const vwidth = workarea().workWidth(); int const vheight = workarea().workHeight(); + LyXText * text = bv.text; workarea().getPainter().start(); @@ -256,27 +256,18 @@ void LyXScreen::update(LyXText * text, B case LyXText::NEED_MORE_REFRESH: { int const y = max(int(text->refresh_y - text->top_y()), 0); - drawFromTo(text, bv, y, vheight, yo, xo); - text->refresh_y = 0; - // otherwise this is called ONLY from BufferView_pimpl(update) - // or we should see to set this flag accordingly - if (text != bv->text) - text->status(bv, LyXText::UNCHANGED); + drawFromTo(text, &bv, y, vheight, yo, xo); expose(0, y, vwidth, vheight - y); } break; case LyXText::NEED_VERY_LITTLE_REFRESH: { // ok I will update the current cursor row - drawOneRow(text, bv, text->refresh_row, text->refresh_y, + drawOneRow(text, &bv, text->refresh_row, text->refresh_y, yo, xo); // this because if we had a major update the refresh_row could // have been set to 0! if (text->refresh_row) { - // otherwise this is called ONLY from BufferView_pimpl(update) - // or we should see to set this flag accordingly - if (text != bv->text) - text->status(bv, LyXText::UNCHANGED); expose(0, text->refresh_y - text->top_y() + yo, vwidth, text->refresh_row->height()); } Index: frontends/screen.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/screen.h,v retrieving revision 1.12 diff -u -p -r1.12 screen.h --- frontends/screen.h 26 Feb 2003 12:49:01 -0000 1.12 +++ frontends/screen.h 16 Mar 2003 19:32:21 -0000 @@ -118,18 +118,17 @@ public: /** * update - update part of the screen rendering - * @param text the containing text region * @param bv the bufferview * @param xo the x offset into the text * @param yo the x offset into the text * - * Updates part of the screen. If text->status is + * Updates part of the screen. If bv->text->status is * LyXText::NEED_MORE_REFRESH, we update from the * point of change and to the end of the screen. * If text->status is LyXText::NEED_VERY_LITTLE_REFRESH, * we only update the current row. */ - virtual void update(LyXText * text, BufferView * bv, int yo = 0, int xo = 0); + virtual void update(BufferView & bv, int yo = 0, int xo = 0); /// FIXME virtual void toggleSelection(LyXText *, BufferView *, bool = true, diff -u -p -r1.357 insettext.C --- insets/insettext.C 16 Mar 2003 00:45:30 -0000 1.357 +++ insets/insettext.C 16 Mar 2003 19:32:44 -0000 @@ -364,7 +362,7 @@ void InsetText::draw(BufferView * bv, Ly if (nw > 0 && old_max_width != nw) { need_update = INIT; old_max_width = nw; - bv->text->status(bv, LyXText::CHANGED_IN_DRAW); + bv->text->postChangedInDraw(); return; } }