]> git.lyx.org Git - features.git/commitdiff
postPaint() etc.
authorJohn Levon <levon@movementarian.org>
Sun, 16 Mar 2003 00:45:31 +0000 (00:45 +0000)
committerJohn Levon <levon@movementarian.org>
Sun, 16 Mar 2003 00:45:31 +0000 (00:45 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6514 a592a061-630c-0410-9148-cb99ea01b6c8

src/insets/ChangeLog
src/insets/insettext.C
src/lyxtext.h
src/text.C
src/text2.C
src/text3.C

index ff00ff23b79f609f24fd150cfe193f7ea1ff6c4c..634f58458b1da8f063383e218cccf0e6f2ccf165 100644 (file)
@@ -1,3 +1,7 @@
+2003-03-16  John Levon  <levon@movementarian.org>
+
+       * insettext.C: remove unused s.refresh
+
 2003-03-13  Angus Leeming  <leeming@lyx.org>
 
        * insettext.C (edit): replace Dialogs::updateParagraph with
index 1a7823b06bab470e7ba79c74fec8c53ca91b78de..0a5daf47f58efcdd6a186b8b2dbdef17c8a474e2 100644 (file)
@@ -100,7 +100,6 @@ void InsetText::saveLyXTextState(LyXText * t) const
                sstate.selendboundary = t->selection.end.boundary();
                sstate.selection = t->selection.set();
                sstate.mark_set = t->selection.mark();
-               sstate.refresh = t->refresh_row != 0;
        } else {
                sstate.lpar = 0;
        }
@@ -109,26 +108,24 @@ void InsetText::saveLyXTextState(LyXText * t) const
 
 void InsetText::restoreLyXTextState(BufferView * bv, LyXText * t) const
 {
-       if (sstate.lpar) {
-               t->selection.set(true);
-               /* at this point just to avoid the Delete-Empty-Paragraph
-                * Mechanism when setting the cursor */
-               t->selection.mark(sstate.mark_set);
-               if (sstate.selection) {
-                       t->setCursor(bv, sstate.selstartpar, sstate.selstartpos,
-                                    true, sstate.selstartboundary);
-                       t->selection.cursor = t->cursor;
-                       t->setCursor(bv, sstate.selendpar, sstate.selendpos,
-                                    true, sstate.selendboundary);
-                       t->setSelection(bv);
-                       t->setCursor(bv, sstate.lpar, sstate.pos);
-               } else {
-                       t->setCursor(bv, sstate.lpar, sstate.pos, true, sstate.boundary);
-                       t->selection.cursor = t->cursor;
-                       t->selection.set(false);
-               }
-               if (sstate.refresh) {
-               }
+       if (!sstate.lpar)
+               return;
+
+       t->selection.set(true);
+       /* at this point just to avoid the DEPM when setting the cursor */
+       t->selection.mark(sstate.mark_set);
+       if (sstate.selection) {
+               t->setCursor(bv, sstate.selstartpar, sstate.selstartpos,
+                            true, sstate.selstartboundary);
+               t->selection.cursor = t->cursor;
+               t->setCursor(bv, sstate.selendpar, sstate.selendpos,
+                            true, sstate.selendboundary);
+               t->setSelection(bv);
+               t->setCursor(bv, sstate.lpar, sstate.pos);
+       } else {
+               t->setCursor(bv, sstate.lpar, sstate.pos, true, sstate.boundary);
+               t->selection.cursor = t->cursor;
+               t->selection.set(false);
        }
 }
 
index 058b2d5ba98adac8aa7ebc40926a9683f32276f4..540b47455fd9373be9dcaf80aca60f7c7db66a6a 100644 (file)
@@ -211,6 +211,22 @@ public:
        /// Set the status to make a paint pending.
        void status(BufferView *, text_status) const;
 
+       /// clear any pending paints
+       void clearPaint();
+
+       /// post notice that we changed during a draw
+       void postChangedInDraw();
+
+       /**
+        * Mark position y as the starting point for a repaint
+        */
+       void postPaint(BufferView & bv, int start_y);
+
+       /**
+        * Mark the given row at position y as needing a repaint.
+        */
+       void postRowPaint(BufferView & bv, Row * row, int start_y);
+
        ///
        Inset::RESULT dispatch(FuncRequest const & cmd);
 
index beb5587cea962ae36e43adacc0981ed6a9eeead9..c179a22ac53729e08e63ef4982ddc9aebfa79878 100644 (file)
@@ -1453,19 +1453,19 @@ void LyXText::breakParagraph(BufferView * bview,
                cursorLeft(bview);
        }
 
-       status(bview, LyXText::NEED_MORE_REFRESH);
-       refresh_row = cursor.row();
-       refresh_y = cursor.y() - cursor.row()->baseline();
+       int y = cursor.y() - cursor.row()->baseline();
 
        // Do not forget the special right address boxes
        if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
-               while (refresh_row->previous() &&
-                      refresh_row->previous()->par() == refresh_row->par())
-               {
-                       refresh_row = refresh_row->previous();
-                       refresh_y -= refresh_row->height();
+               Row * r = cursor.row();
+               while (r->previous() && r->previous()->par() == r->par()) {
+                       r = r->previous();
+                       y -= r->height();
                }
        }
+
+       postPaint(*bview, y);
+
        removeParagraph(cursor.row());
 
        // set the dimensions of the cursor row
@@ -1660,9 +1660,8 @@ void LyXText::insertChar(BufferView * bview, char c)
                        setHeightOfRow(bview, row->previous());
 
                        y -= row->previous()->height();
-                       refresh_y = y;
-                       refresh_row = row->previous();
-                       status(bview, LyXText::NEED_MORE_REFRESH);
+
+                       postPaint(*bview, y);
 
                        breakAgainOneRow(bview, row);
 
@@ -1695,9 +1694,7 @@ void LyXText::insertChar(BufferView * bview, char c)
        }
 
        if (c == Paragraph::META_INSET || row->fill() < 0) {
-               refresh_y = y;
-               refresh_row = row;
-               status(bview, LyXText::NEED_MORE_REFRESH);
+               postPaint(*bview, y);
                breakAgainOneRow(bview, row);
                // will the cursor be in another row now?
                if (row->lastPos() <= cursor.pos() + 1 && row->next()) {
@@ -1720,15 +1717,16 @@ void LyXText::insertChar(BufferView * bview, char c)
                else
                        need_break_row = 0;
        } else {
-               refresh_y = y;
-               refresh_row = row;
-
+               // FIXME: similar code is duplicated all over - make resetHeightOfRow
                int const tmpheight = row->height();
+
                setHeightOfRow(bview, row);
-               if (tmpheight == row->height())
-                       status(bview, LyXText::NEED_VERY_LITTLE_REFRESH);
-               else
-                       status(bview, LyXText::NEED_MORE_REFRESH);
+
+               if (tmpheight == row->height()) {
+                       postRowPaint(*bview, row, y);
+               } else {
+                       postPaint(*bview, y);
+               }
 
                current_font = rawtmpfont;
                real_current_font = realtmpfont;
@@ -2344,11 +2342,9 @@ void LyXText::changeCase(BufferView & bview, LyXText::TextCase action)
 
                ++pos;
        }
-       if (to.row() != from.row()) {
-               refresh_y = from.y() - from.row()->baseline();
-               refresh_row = from.row();
-               status(&bview, LyXText::NEED_MORE_REFRESH);
-       }
+
+       if (to.row() != from.row())
+               postPaint(bview, from.y() - from.row()->baseline());
 }
 
 
@@ -2468,9 +2464,7 @@ void LyXText::backspace(BufferView * bview)
                                int const tmpheight = cursor.row()->height();
                                setHeightOfRow(bview, cursor.row());
                                if (cursor.row()->height() != tmpheight) {
-                                       refresh_y = cursor.y() - cursor.row()->baseline();
-                                       refresh_row = cursor.row();
-                                       status(bview, LyXText::NEED_MORE_REFRESH);
+                                       postPaint(*bview, cursor.y() - cursor.row()->baseline());
                                }
                                return;
                        }
@@ -2524,9 +2518,7 @@ void LyXText::backspace(BufferView * bview)
                                if (cursor.pos())
                                        cursor.pos(cursor.pos() - 1);
 
-                       status(bview, LyXText::NEED_MORE_REFRESH);
-                       refresh_row = cursor.row();
-                       refresh_y = cursor.y() - cursor.row()->baseline();
+                       postPaint(*bview, cursor.y() - cursor.row()->baseline());
 
                        // remove the lost paragraph
                        // This one is not safe, since the paragraph that the tmprow and the
@@ -2655,9 +2647,8 @@ void LyXText::backspace(BufferView * bview)
                                tmprow->fill(fill(*bview, *tmprow, workWidth(*bview)));
                                setHeightOfRow(bview, tmprow);
 
-                               refresh_y = y;
-                               refresh_row = tmprow;
-                               status(bview, LyXText::NEED_MORE_REFRESH);
+                               postPaint(*bview, y);
+
                                setCursor(bview, cursor.par(), cursor.pos(),
                                          false, cursor.boundary());
                                //current_font = rawtmpfont;
@@ -2683,9 +2674,7 @@ void LyXText::backspace(BufferView * bview)
                        if (row->lastPos() == row->par()->size() - 1)
                                removeRow(row->next());
 
-                       refresh_y = y;
-                       refresh_row = row;
-                       status(bview, LyXText::NEED_MORE_REFRESH);
+                       postPaint(*bview, y);
 
                        breakAgainOneRow(bview, row);
                        // will the cursor be in another row now?
@@ -2706,12 +2695,11 @@ void LyXText::backspace(BufferView * bview)
                        row->fill(fill(*bview, *row, workWidth(*bview)));
                        int const tmpheight = row->height();
                        setHeightOfRow(bview, row);
-                       if (tmpheight == row->height())
-                               status(bview, LyXText::NEED_VERY_LITTLE_REFRESH);
-                       else
-                               status(bview, LyXText::NEED_MORE_REFRESH);
-                       refresh_y = y;
-                       refresh_row = row;
+                       if (tmpheight == row->height()) {
+                               postRowPaint(*bview, row, y);
+                       } else {
+                               postPaint(*bview, y);
+                       }
                        setCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
                }
        }
index 3575e7acc8a69276d891d1d8277ec483533b6d98..1040c8a11395507d013df094c596e24cf300fc32 100644 (file)
@@ -79,12 +79,11 @@ void LyXText::init(BufferView * bview, bool reinit)
                }
 
                lastrow = 0;
-               refresh_row = 0;
                need_break_row = 0;
                width = height = 0;
                copylayouttype.erase();
-               top_y(refresh_y = 0);
-               status_ = LyXText::UNCHANGED;
+               top_y(0);
+               clearPaint();
        } else if (firstrow)
                return;
 
@@ -2494,6 +2493,72 @@ void LyXText::status(BufferView * bview, LyXText::text_status new_status) const
 }
 
 
+void LyXText::clearPaint()
+{
+       status_ = UNCHANGED;
+       refresh_row = 0;
+       refresh_y = 0;
+}
+
+
+void LyXText::postChangedInDraw()
+{
+       status_ = CHANGED_IN_DRAW;
+}
+
+
+void LyXText::postPaint(BufferView & bv, int start_y)
+{
+       status_ = NEED_MORE_REFRESH;
+       refresh_y = start_y;
+       refresh_row = 0;
+
+       if (!inset_owner)
+               return;
+               
+       // We are an inset's lyxtext. Tell the top-level lyxtext
+       // it needs to update the row we're in.
+
+       LyXText * t = bv.text;
+
+       // FIXME: but what if this row is below ?
+       if (!t->refresh_row) {
+               t->refresh_row = t->cursor.row();
+               t->refresh_y = t->cursor.y() - t->cursor.row()->baseline();
+       }
+}
+
+
+// FIXME: we should probably remove this y parameter,
+// make refresh_y be 0, and use row->y etc.
+void LyXText::postRowPaint(BufferView & bv, Row * row, int 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)
+               return;
+               
+       // We are an inset's lyxtext. Tell the top-level lyxtext
+       // it needs to update the row we're in.
+
+       LyXText * t = bv.text;
+
+       // FIXME: but what if this new row is above ?
+       // Why the !t->refresh_row at all ?
+       if (!t->refresh_row) {
+               t->refresh_row = t->cursor.row();
+               t->refresh_y = t->cursor.y() - t->cursor.row()->baseline();
+       }
+}
+
+
 bool LyXText::isTopLevel() const
 {
        /// only the top-level lyxtext has a non-null bv owner
index 7dcedf4a169802888392c9c06fec18cf602fd3a0..1c904840a625d1655540bd63259bc530a800384e 100644 (file)
@@ -429,11 +429,9 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                par->params().startOfAppendix(start);
 
                // we can set the refreshing parameters now
-               status(cmd.view(), LyXText::NEED_MORE_REFRESH);
                updateCounters(cmd.view());
                redoHeightOfParagraph(bv);
-               refresh_y = 0;
-               refresh_row = 0;
+               postPaint(*cmd.view(), 0);
                setCursor(cmd.view(), cursor.par(), cursor.pos());
                update(bv);
                break;