]> git.lyx.org Git - lyx.git/blobdiff - src/text.C
fix some C++ parsing bugs
[lyx.git] / src / text.C
index e23daf91d289e4812c60f03e378e30ccf9cf2277..396ca0e08c624e60a88964c65e89f749cc2de263 100644 (file)
@@ -58,44 +58,79 @@ extern int const LEFT_MARGIN = PAPER_MARGIN + CHANGEBAR_MARGIN;
 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
 
 
+BufferView * LyXText::bv()
+{
+       lyx::Assert(bv_owner != 0);
+       return bv_owner;
+}
+
+
+BufferView * LyXText::bv() const
+{
+       lyx::Assert(bv_owner != 0);
+       return bv_owner;
+}
+
+
 int LyXText::top_y() const
 {
-       if (!top_row_)
+       if (!anchor_row_)
                return 0;
-       
+
        int y = 0;
-       for (Row * row = firstrow; row && row != top_row_; row = row->next()) {
+       for (Row * row = firstRow();
+            row && row != anchor_row_; row = row->next()) {
                y += row->height();
        }
-       return y + top_row_offset_;
+       return y + anchor_row_offset_;
 }
 
 
 void LyXText::top_y(int newy)
 {
-       if (!firstrow)
+       if (!firstRow())
                return;
        lyxerr[Debug::GUI] << "setting top y = " << newy << endl;
-       
+
        int y = newy;
-       top_row_ = getRowNearY(y);
-       top_row_offset_ = newy - y;
-       lyxerr[Debug::GUI] << "changing reference to row: " << top_row_
-              << " offset: " << top_row_offset_ << endl;
+       Row * row = getRowNearY(y);
+
+       if (row == anchor_row_ && anchor_row_offset_ == newy - y) {
+               lyxerr[Debug::GUI] << "top_y to same value, skipping update" << endl;
+               return;
+       }
+
+       anchor_row_ = row;
+       anchor_row_offset_ = newy - y;
+       lyxerr[Debug::GUI] << "changing reference to row: " << anchor_row_
+              << " offset: " << anchor_row_offset_ << endl;
+       postPaint(0);
+}
+
+
+void LyXText::anchor_row(Row * row)
+{
+       int old_y = top_y();
+       anchor_row_offset_ = 0;
+       anchor_row_ = row;
+       anchor_row_offset_ = old_y - top_y();
+       lyxerr[Debug::GUI] << "anchor_row(): changing reference to row: "
+                          << anchor_row_ << " offset: " << anchor_row_offset_
+                          << endl;
 }
 
 
-int LyXText::workWidth(BufferView & bview) const
+int LyXText::workWidth() const
 {
        if (inset_owner) {
                // FIXME: pass (const ?) ref
-               return inset_owner->textWidth(&bview);
+               return inset_owner->textWidth(bv());
        }
-       return bview.workWidth();
+       return bv()->workWidth();
 }
 
 
-int LyXText::workWidth(BufferView & bview, Inset * inset) const
+int LyXText::workWidth(Inset * inset) const
 {
        Paragraph * par = inset->parOwner();
        lyx::Assert(par);
@@ -112,7 +147,7 @@ int LyXText::workWidth(BufferView & bview, Inset * inset) const
                Row dummyrow;
                dummyrow.par(par);
                dummyrow.pos(pos);
-               return workWidth(bview) - leftMargin(&bview, &dummyrow);
+               return workWidth() - leftMargin(&dummyrow);
        } else {
                int dummy_y;
                Row * row = getRow(par, pos, dummy_y);
@@ -132,15 +167,15 @@ int LyXText::workWidth(BufferView & bview, Inset * inset) const
                        return maxw;
 
        }
-       return workWidth(bview);
+       return workWidth();
 }
 
 
-int LyXText::getRealCursorX(BufferView * bview) const
+int LyXText::getRealCursorX() const
 {
        int x = cursor.x();
-       if (the_locking_inset && (the_locking_inset->getLyXText(bview)!=this))
-               x = the_locking_inset->getLyXText(bview)->getRealCursorX(bview);
+       if (the_locking_inset && (the_locking_inset->getLyXText(bv())!= this))
+               x = the_locking_inset->getLyXText(bv())->getRealCursorX();
        return x;
 }
 
@@ -203,59 +238,102 @@ unsigned char LyXText::transformChar(unsigned char c, Paragraph * par,
 //
 // Lgb
 
-int LyXText::singleWidth(BufferView * bview, Paragraph * par,
+int LyXText::singleWidth(Paragraph * par,
                         pos_type pos) const
 {
+       if (pos >= par->size())
+               return 0;
+
        char const c = par->getChar(pos);
-       return singleWidth(bview, par, pos, c);
+       return singleWidth(par, pos, c);
 }
 
 
-int LyXText::singleWidth(BufferView * bview, Paragraph * par,
+int LyXText::singleWidth(Paragraph * par,
                         pos_type pos, char c) const
 {
-       LyXFont const font = getFont(bview->buffer(), par, pos);
+       if (pos >= par->size())
+               return 0;
+
+       LyXFont const font = getFont(bv()->buffer(), par, pos);
 
        // The most common case is handled first (Asger)
        if (IsPrintable(c)) {
                if (font.language()->RightToLeft()) {
                        if (font.language()->lang() == "arabic" &&
                            (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
-                            lyxrc.font_norm_type == LyXRC::ISO_10646_1))
+                            lyxrc.font_norm_type == LyXRC::ISO_10646_1)) {
                                if (Encodings::IsComposeChar_arabic(c))
                                        return 0;
                                else
                                        c = transformChar(c, par, pos);
-                       else if (font.language()->lang() == "hebrew" &&
+                       else if (font.language()->lang() == "hebrew" &&
                                 Encodings::IsComposeChar_hebrew(c))
                                return 0;
                }
                return font_metrics::width(c, font);
 
-       } else if (IsHfillChar(c)) {
-               // Because of the representation as vertical lines
-               return 3;
-       } else if (c == Paragraph::META_INSET) {
+       }
+
+       if (c == Paragraph::META_INSET) {
                Inset * tmpinset = par->getInset(pos);
                if (tmpinset) {
+                       if (tmpinset->lyxCode() == Inset::HFILL_CODE) {
+                               // Because of the representation as vertical lines
+                               return 3;
+                       }
 #if 1
+#warning inset->update FIXME
                        // this IS needed otherwise on initialitation we don't get the fill
                        // of the row right (ONLY on initialization if we read a file!)
                        // should be changed! (Jug 20011204)
-                       tmpinset->update(bview, font);
+                       tmpinset->update(bv());
 #endif
-                       return tmpinset->width(bview, font);
-               } else
-                       return 0;
+                       return tmpinset->width(bv(), font);
+               }
+               return 0;
+       }
 
-       } else if (IsSeparatorChar(c))
+       if (IsSeparatorChar(c))
                c = ' ';
-       else if (IsNewlineChar(c))
-               c = 'n';
        return font_metrics::width(c, font);
 }
 
 
+lyx::pos_type LyXText::log2vis(lyx::pos_type pos) const
+{
+       if (bidi_start == -1)
+               return pos;
+       else
+               return log2vis_list[pos-bidi_start];
+}
+
+
+lyx::pos_type LyXText::vis2log(lyx::pos_type pos) const
+{
+       if (bidi_start == -1)
+               return pos;
+       else
+               return vis2log_list[pos-bidi_start];
+}
+
+
+lyx::pos_type LyXText::bidi_level(lyx::pos_type pos) const
+{
+       if (bidi_start == -1)
+               return 0;
+       else
+               return bidi_levels[pos-bidi_start];
+}
+
+
+bool LyXText::bidi_InRange(lyx::pos_type pos) const
+{
+       return bidi_start == -1 ||
+               (bidi_start <= pos && pos <= bidi_end);
+}
+
+
 void LyXText::computeBidiTables(Buffer const * buf, Row * row) const
 {
        bidi_same_direction = true;
@@ -417,16 +495,18 @@ bool LyXText::isBoundary(Buffer const * buf, Paragraph * par,
 }
 
 
-int LyXText::leftMargin(BufferView * bview, Row const * row) const
+int LyXText::leftMargin(Row const * row) const
 {
        Inset * ins;
-       if ((row->par()->getChar(row->pos()) == Paragraph::META_INSET) &&
-               (ins=row->par()->getInset(row->pos())) &&
-               (ins->needFullRow() || ins->display()))
-               return LEFT_MARGIN;
+
+       if (row->pos() < row->par()->size())
+               if ((row->par()->getChar(row->pos()) == Paragraph::META_INSET) &&
+                   (ins = row->par()->getInset(row->pos())) &&
+                   (ins->needFullRow() || ins->display()))
+                       return LEFT_MARGIN;
 
        LyXTextClass const & tclass =
-               bview->buffer()->params.getLyXTextClass();
+               bv()->buffer()->params.getLyXTextClass();
        LyXLayout_ptr const & layout = row->par()->layout();
 
        string parindent = layout->parindent;
@@ -461,7 +541,7 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const
                        Row dummyrow;
                        dummyrow.par(newpar);
                        dummyrow.pos(newpar->size());
-                       x = leftMargin(bview, &dummyrow);
+                       x = leftMargin(&dummyrow);
                } else {
                        // this is no longer an error, because this function
                        // is used to clear impossible depths after changing
@@ -480,7 +560,7 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const
                }
        }
 
-       LyXFont const labelfont = getLabelFont(bview->buffer(), row->par());
+       LyXFont const labelfont = getLabelFont(bv()->buffer(), row->par());
        switch (layout->margintype) {
        case MARGIN_DYNAMIC:
                if (!layout->leftmargin.empty()) {
@@ -565,12 +645,12 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const
        break;
        }
 
-       if ((workWidth(*bview) > 0) &&
+       if ((workWidth() > 0) &&
                !row->par()->params().leftIndent().zero())
        {
                LyXLength const len = row->par()->params().leftIndent();
                int const tw = inset_owner ?
-                       inset_owner->latexTextWidth(bview) : workWidth(*bview);
+                       inset_owner->latexTextWidth(bv()) : workWidth();
                x += len.inPixels(tw);
        }
 
@@ -596,13 +676,13 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const
                                (row->par()->inInset()->owner()->lyxCode() != Inset::TABULAR_CODE &&
                                 row->par()->inInset()->owner()->lyxCode() != Inset::ERT_CODE))
                    && (row->par()->layout() != tclass.defaultLayout() ||
-                       bview->buffer()->params.paragraph_separation ==
+                       bv()->buffer()->params.paragraph_separation ==
                        BufferParams::PARSEP_INDENT)) {
                        x += font_metrics::signedWidth(parindent,
                                                  tclass.defaultfont());
                } else if (layout->labeltype == LABEL_BIBLIO) {
                        // ale970405 Right width for bibitems
-                       x += bibitemMaxWidth(bview, tclass.defaultfont());
+                       x += bibitemMaxWidth(bv(), tclass.defaultfont());
                }
        }
 
@@ -613,10 +693,12 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const
 int LyXText::rightMargin(Buffer const & buf, Row const & row) const
 {
        Inset * ins;
-       if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
-               (ins=row.par()->getInset(row.pos())) &&
-               (ins->needFullRow() || ins->display()))
-               return PAPER_MARGIN;
+
+       if (row.pos() < row.par()->size())
+               if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
+                   (ins=row.par()->getInset(row.pos())) &&
+                   (ins->needFullRow() || ins->display()))
+                       return PAPER_MARGIN;
 
        LyXTextClass const & tclass = buf.params.getLyXTextClass();
        LyXLayout_ptr const & layout = row.par()->layout();
@@ -663,13 +745,13 @@ int LyXText::rightMargin(Buffer const & buf, Row const & row) const
 }
 
 
-int LyXText::labelEnd(BufferView & bview, Row const & row) const
+int LyXText::labelEnd(Row const & row) const
 {
        if (row.par()->layout()->margintype == MARGIN_MANUAL) {
                Row tmprow = row;
                tmprow.pos(row.par()->size());
                // return the beginning of the body
-               return leftMargin(&bview, &tmprow);
+               return leftMargin(&tmprow);
        }
 
        // LabelEnd is only needed if the layout
@@ -684,13 +766,8 @@ namespace {
 pos_type addressBreakPoint(pos_type i, Paragraph * par)
 {
        for (; i < par->size(); ++i) {
-               if (par->isNewline(i)) {
+               if (par->isNewline(i))
                        return i;
-               } else if (par->isInset(i) && par->getInset(i)->display()) {
-                       // FIXME: what are we doing modifying stuff here !
-                       par->getInset(i)->display(false);
-               }
-               ++i;
        }
 
        return par->size();
@@ -700,12 +777,12 @@ pos_type addressBreakPoint(pos_type i, Paragraph * par)
 
 
 pos_type
-LyXText::rowBreakPoint(BufferView & bv, Row const & row) const
+LyXText::rowBreakPoint(Row const & row) const
 {
        Paragraph * par = row.par();
 
        // maximum pixel width of a row.
-       int width = workWidth(bv) - rightMargin(*bv.buffer(), row);
+       int width = workWidth() - rightMargin(*bv()->buffer(), row);
 
        // inset->textWidth() returns -1 via workWidth(),
        // but why ?
@@ -721,36 +798,39 @@ LyXText::rowBreakPoint(BufferView & bv, Row const & row) const
        pos_type const body_pos = par->beginningOfBody();
        pos_type const last = par->size();
        pos_type point = last;
-       pos_type i = pos;
+
+       if (pos == last)
+               return last;
 
        // Now we iterate through until we reach the right margin
        // or the end of the par, then choose the possible break
        // nearest that.
 
-       int const left = leftMargin(&bv, &row);
+       int const left = leftMargin(&row);
        int x = left;
 
        // pixel width since last breakpoint
        int chunkwidth = 0;
 
-       for (i = pos; i < last; ++i) {
-
-               char const c = par->getChar(i);
+       pos_type i = pos;
+       for (; i < last; ++i) {
 
-               if (IsNewlineChar(c)) {
+               if (par->isNewline(i)) {
                        point = i;
                        break;
                }
 
-               int thiswidth = singleWidth(&bv, par, i, c);
+               char const c = par->getChar(i);
+
+               int thiswidth = singleWidth(par, i, c);
 
                // add the auto-hfill from label end to the body
                if (body_pos && i == body_pos) {
                        thiswidth += font_metrics::width(layout->labelsep,
-                                   getLabelFont(bv.buffer(), par));
+                                   getLabelFont(bv()->buffer(), par));
                        if (par->isLineSeparator(i - 1))
-                               thiswidth -= singleWidth(&bv, par, i - 1);
-                       int left_margin = labelEnd(bv, row);
+                               thiswidth -= singleWidth(par, i - 1);
+                       int left_margin = labelEnd(row);
                        if (thiswidth < left_margin)
                                thiswidth = left_margin;
                }
@@ -759,22 +839,14 @@ LyXText::rowBreakPoint(BufferView & bv, Row const & row) const
                chunkwidth += thiswidth;
 
                Inset * in = par->isInset(i) ? par->getInset(i) : 0;
-               bool display = (in && (in->display() || in->needFullRow()));
-
-               // check whether a Display() inset is valid here.
-               // If not, change it to non-display. FIXME:
-               // we should not be modifying things at this
-               // point !
-               if (in && in->display() && (layout->isCommand() ||
-                   (layout->labeltype == LABEL_MANUAL && i < body_pos)))
-                       in->display(false);
+               bool fullrow = (in && (in->display() || in->needFullRow()));
 
                // break before a character that will fall off
                // the right of the row
                if (x >= width) {
                        // if no break before or we are at an inset
                        // that will take up a row, break here
-                       if (point == last || display || chunkwidth >= (width - left)) {
+                       if (point == last || fullrow || chunkwidth >= (width - left)) {
                                if (pos < i)
                                        point = i - 1;
                                else
@@ -792,9 +864,9 @@ LyXText::rowBreakPoint(BufferView & bv, Row const & row) const
                        continue;
                }
 
-               if (!display)
+               if (!fullrow)
                        continue;
-                       
+
                // full row insets start at a new row
                if (i == pos) {
                        if (pos < last - 1) {
@@ -829,7 +901,7 @@ LyXText::rowBreakPoint(BufferView & bv, Row const & row) const
 
 
 // returns the minimum space a row needs on the screen in pixel
-int LyXText::fill(BufferView & bview, Row & row, int paper_width) const
+int LyXText::fill(Row & row, int paper_width) const
 {
        if (paper_width < 0)
                return 0;
@@ -842,10 +914,10 @@ int LyXText::fill(BufferView & bview, Row & row, int paper_width) const
        if (row.par()->layout()->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
                int const tmpfill = row.fill();
                row.fill(0); // the minfill in MarginLeft()
-               w = leftMargin(&bview, &row);
+               w = leftMargin(&row);
                row.fill(tmpfill);
        } else
-               w = leftMargin(&bview, &row);
+               w = leftMargin(&row);
 
        Paragraph * par = row.par();
        LyXLayout_ptr const & layout = par->layout();
@@ -855,32 +927,32 @@ int LyXText::fill(BufferView & bview, Row & row, int paper_width) const
 
        while (i <= last) {
                if (body_pos > 0 && i == body_pos) {
-                       w += font_metrics::width(layout->labelsep, getLabelFont(bview.buffer(), par));
+                       w += font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), par));
                        if (par->isLineSeparator(i - 1))
-                               w -= singleWidth(&bview, par, i - 1);
-                       int left_margin = labelEnd(bview, row);
+                               w -= singleWidth(par, i - 1);
+                       int left_margin = labelEnd(row);
                        if (w < left_margin)
                                w = left_margin;
                }
-               w += singleWidth(&bview, par, i);
+               w += singleWidth(par, i);
                ++i;
        }
        if (body_pos > 0 && body_pos > last) {
-               w += font_metrics::width(layout->labelsep, getLabelFont(bview.buffer(), par));
+               w += font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), par));
                if (last >= 0 && par->isLineSeparator(last))
-                       w -= singleWidth(&bview, par, last);
-               int const left_margin = labelEnd(bview, row);
+                       w -= singleWidth(par, last);
+               int const left_margin = labelEnd(row);
                if (w < left_margin)
                        w = left_margin;
        }
 
-       int const fill = paper_width - w - rightMargin(*bview.buffer(), row);
+       int const fill = paper_width - w - rightMargin(*bv()->buffer(), row);
        return fill;
 }
 
 
 // returns the minimum space a manual label needs on the screen in pixel
-int LyXText::labelFill(BufferView & bview, Row const & row) const
+int LyXText::labelFill(Row const & row) const
 {
        pos_type last = row.par()->beginningOfBody();
 
@@ -897,14 +969,14 @@ int LyXText::labelFill(BufferView & bview, Row const & row) const
        int w = 0;
        pos_type i = row.pos();
        while (i <= last) {
-               w += singleWidth(&bview, row.par(), i);
+               w += singleWidth(row.par(), i);
                ++i;
        }
 
        int fill = 0;
        string const & labwidstr = row.par()->params().labelWidthString();
        if (!labwidstr.empty()) {
-               LyXFont const labfont = getLabelFont(bview.buffer(), row.par());
+               LyXFont const labfont = getLabelFont(bv()->buffer(), row.par());
                int const labwidth = font_metrics::width(labwidstr, labfont);
                fill = max(labwidth - w, 0);
        }
@@ -921,7 +993,7 @@ LColor::color LyXText::backgroundColor() const
                return LColor::background;
 }
 
-void LyXText::setHeightOfRow(BufferView * bview, Row * row) const
+void LyXText::setHeightOfRow(Row * row)
 {
        // get the maximum ascent and the maximum descent
        int asc = 0;
@@ -947,19 +1019,19 @@ void LyXText::setHeightOfRow(BufferView * bview, Row * row) const
        // as max get the first character of this row then it can increase but not
        // decrease the height. Just some point to start with so we don't have to
        // do the assignment below too often.
-       LyXFont font = getFont(bview->buffer(), par, row->pos());
+       LyXFont font = getFont(bv()->buffer(), par, row->pos());
        LyXFont::FONT_SIZE const tmpsize = font.size();
-       font = getLayoutFont(bview->buffer(), par);
+       font = getLayoutFont(bv()->buffer(), par);
        LyXFont::FONT_SIZE const size = font.size();
        font.setSize(tmpsize);
 
-       LyXFont labelfont = getLabelFont(bview->buffer(), par);
+       LyXFont labelfont = getLabelFont(bv()->buffer(), par);
 
        float spacing_val = 1.0;
        if (!row->par()->params().spacing().isDefault()) {
                spacing_val = row->par()->params().spacing().getValue();
        } else {
-               spacing_val = bview->buffer()->params.spacing.getValue();
+               spacing_val = bv()->buffer()->params.spacing.getValue();
        }
        //lyxerr << "spacing_val = " << spacing_val << endl;
 
@@ -974,23 +1046,26 @@ void LyXText::setHeightOfRow(BufferView * bview, Row * row) const
        int labeladdon = 0;
        int maxwidth = 0;
 
-       // Check if any insets are larger
-       for (pos_type pos = row->pos(); pos <= pos_end; ++pos) {
-               if (row->par()->isInset(pos)) {
-                       tmpfont = getFont(bview->buffer(), row->par(), pos);
-                       tmpinset = row->par()->getInset(pos);
-                       if (tmpinset) {
+       if (!row->par()->empty()) {
+               // Check if any insets are larger
+               for (pos_type pos = row->pos(); pos <= pos_end; ++pos) {
+                       if (row->par()->isInset(pos)) {
+                               tmpfont = getFont(bv()->buffer(), row->par(), pos);
+                               tmpinset = row->par()->getInset(pos);
+                               if (tmpinset) {
 #if 1 // this is needed for deep update on initialitation
-                               tmpinset->update(bview, tmpfont);
+#warning inset->update FIXME
+                                       tmpinset->update(bv());
 #endif
-                               asc = tmpinset->ascent(bview, tmpfont);
-                               desc = tmpinset->descent(bview, tmpfont);
-                               maxwidth += tmpinset->width(bview, tmpfont);
-                               maxasc = max(maxasc, asc);
-                               maxdesc = max(maxdesc, desc);
+                                       asc = tmpinset->ascent(bv(), tmpfont);
+                                       desc = tmpinset->descent(bv(), tmpfont);
+                                       maxwidth += tmpinset->width(bv(), tmpfont);
+                                       maxasc = max(maxasc, asc);
+                                       maxdesc = max(maxdesc, desc);
+                               }
+                       } else {
+                               maxwidth += singleWidth(row->par(), pos);
                        }
-               } else {
-                       maxwidth += singleWidth(bview, row->par(), pos);
                }
        }
 
@@ -1020,50 +1095,53 @@ void LyXText::setHeightOfRow(BufferView * bview, Row * row) const
        if (!row->pos() && (row->par() == firstpar)) {
 
                // some parksips VERY EASY IMPLEMENTATION
-               if (bview->buffer()->params.paragraph_separation ==
+               if (bv()->buffer()->params.paragraph_separation ==
                        BufferParams::PARSEP_SKIP)
                {
                        if (layout->isParagraph()
                                && firstpar->getDepth() == 0
                                && firstpar->previous())
                        {
-                               maxasc += bview->buffer()->params.getDefSkip().inPixels(*bview);
+                               maxasc += bv()->buffer()->params.getDefSkip().inPixels(*bv());
                        } else if (firstpar->previous() &&
                                   firstpar->previous()->layout()->isParagraph() &&
                                   firstpar->previous()->getDepth() == 0)
                        {
                                // is it right to use defskip here too? (AS)
-                               maxasc += bview->buffer()->params.getDefSkip().inPixels(*bview);
+                               maxasc += bv()->buffer()->params.getDefSkip().inPixels(*bv());
                        }
                }
 
                // the top margin
-               if (!row->par()->previous() && isTopLevel())
+               if (!row->par()->previous() && !isInInset())
                        maxasc += PAPER_MARGIN;
 
                // add the vertical spaces, that the user added
-               maxasc += getLengthMarkerHeight(*bview, firstpar->params().spaceTop());
+               maxasc += getLengthMarkerHeight(*bv(), firstpar->params().spaceTop());
 
                // do not forget the DTP-lines!
                // there height depends on the font of the nearest character
                if (firstpar->params().lineTop())
 
-                       maxasc += 2 * font_metrics::ascent('x', getFont(bview->buffer(),
+                       maxasc += 2 * font_metrics::ascent('x', getFont(bv()->buffer(),
                                        firstpar, 0));
                // and now the pagebreaks
                if (firstpar->params().pagebreakTop())
                        maxasc += 3 * defaultRowHeight();
 
+               if (firstpar->params().startOfAppendix())
+                       maxasc += 3 * defaultRowHeight();
+
                // This is special code for the chapter, since the label of this
                // layout is printed in an extra row
                if (layout->labeltype == LABEL_COUNTER_CHAPTER
-                       && bview->buffer()->params.secnumdepth >= 0)
+                       && bv()->buffer()->params.secnumdepth >= 0)
                {
                        float spacing_val = 1.0;
                        if (!row->par()->params().spacing().isDefault()) {
                                spacing_val = row->par()->params().spacing().getValue();
                        } else {
-                               spacing_val = bview->buffer()->params.spacing.getValue();
+                               spacing_val = bv()->buffer()->params.spacing.getValue();
                        }
 
                        labeladdon = int(font_metrics::maxDescent(labelfont) *
@@ -1085,7 +1163,7 @@ void LyXText::setHeightOfRow(BufferView * bview, Row * row) const
                        if (!row->par()->params().spacing().isDefault()) {
                                spacing_val = row->par()->params().spacing().getValue();
                        } else {
-                               spacing_val = bview->buffer()->params.spacing.getValue();
+                               spacing_val = bv()->buffer()->params.spacing.getValue();
                        }
 
                        labeladdon = int(
@@ -1147,17 +1225,17 @@ void LyXText::setHeightOfRow(BufferView * bview, Row * row) const
        if (row->par() == par
                && (!row->next() || row->next()->par() != row->par())) {
                // the bottom margin
-               if (!par->next() && isTopLevel())
+               if (!par->next() && !isInInset())
                        maxdesc += PAPER_MARGIN;
 
                // add the vertical spaces, that the user added
-               maxdesc += getLengthMarkerHeight(*bview, firstpar->params().spaceBottom());
+               maxdesc += getLengthMarkerHeight(*bv(), firstpar->params().spaceBottom());
 
                // do not forget the DTP-lines!
                // there height depends on the font of the nearest character
                if (firstpar->params().lineBottom())
                        maxdesc += 2 * font_metrics::ascent('x',
-                                                      getFont(bview->buffer(),
+                                                      getFont(bv()->buffer(),
                                                               par,
                                                               max(pos_type(0), par->size() - 1)));
 
@@ -1217,12 +1295,12 @@ void LyXText::setHeightOfRow(BufferView * bview, Row * row) const
                float dummy;
                // this IS needed
                row->width(maxwidth);
-               prepareToPrint(bview, row, x, dummy, dummy, dummy, false);
+               prepareToPrint(row, x, dummy, dummy, dummy, false);
        }
        row->width(int(maxwidth + x));
        if (inset_owner) {
-               Row * r = firstrow;
-               width = max(0, workWidth(*bview));
+               Row * r = firstRow();
+               width = max(0, workWidth());
                while (r) {
                        if (r->width() > width)
                                width = r->width();
@@ -1234,13 +1312,13 @@ void LyXText::setHeightOfRow(BufferView * bview, Row * row) const
 
 // Appends the implicit specified paragraph before the specified row,
 // start at the implicit given position
-void LyXText::appendParagraph(BufferView * bview, Row * row) const
+void LyXText::appendParagraph(Row * row)
 {
        pos_type const last = row->par()->size();
        bool done = false;
 
        do {
-               pos_type z = rowBreakPoint(*bview, *row);
+               pos_type z = rowBreakPoint(*row);
 
                Row * tmprow = row;
 
@@ -1248,7 +1326,6 @@ void LyXText::appendParagraph(BufferView * bview, Row * row) const
                        ++z;
                        insertRow(row, row->par(), z);
                        row = row->next();
-                       row->height(0);
                } else {
                        done = true;
                }
@@ -1256,42 +1333,19 @@ void LyXText::appendParagraph(BufferView * bview, Row * row) const
                // Set the dimensions of the row
                // fixed fill setting now by calling inset->update() in
                // SingleWidth when needed!
-               tmprow->fill(fill(*bview, *tmprow, workWidth(*bview)));
-               setHeightOfRow(bview, tmprow);
+               tmprow->fill(fill(*tmprow, workWidth()));
+               setHeightOfRow(tmprow);
 
        } while (!done);
 }
 
 
-// Do we even need this at all ? Code that uses  RowPainter *already*
-// sets need_break_row when it sees a CHANGED_IN_DRAW, though not
-// quite like this
-void LyXText::markChangeInDraw(BufferView * bv, Row * row, Row * prev)
-{
-       if (prev && prev->par() == row->par()) {
-               breakAgainOneRow(bv, prev);
-               if (prev->next() != row) {
-                       // breakAgainOneRow() has removed row_
-                       need_break_row = prev;
-               } else {
-                       need_break_row = row;
-               }
-       } else if (!prev) {
-               need_break_row = firstrow;
-       } else {
-               need_break_row = prev->next();
-       }
-       setCursor(bv, cursor.par(), cursor.pos());
-       /* FIXME */
-}
-
-
-void LyXText::breakAgain(BufferView * bview, Row * row) const
+void LyXText::breakAgain(Row * row)
 {
        bool not_ready = true;
 
        do  {
-               pos_type z = rowBreakPoint(*bview, *row);
+               pos_type z = rowBreakPoint(*row);
                Row * tmprow = row;
 
                if (z < row->par()->size()) {
@@ -1300,12 +1354,11 @@ void LyXText::breakAgain(BufferView * bview, Row * row) const
                                ++z;
                                insertRow(row, row->par(), z);
                                row = row->next();
-                               row->height(0);
                        } else  {
                                row = row->next();
                                ++z;
                                if (row->pos() == z)
-                                       not_ready = false;     // the rest will not change
+                                       not_ready = false; // the rest will not change
                                else {
                                        row->pos(z);
                                }
@@ -1325,16 +1378,16 @@ void LyXText::breakAgain(BufferView * bview, Row * row) const
                }
 
                // set the dimensions of the row
-               tmprow->fill(fill(*bview, *tmprow, workWidth(*bview)));
-               setHeightOfRow(bview, tmprow);
+               tmprow->fill(fill(*tmprow, workWidth()));
+               setHeightOfRow(tmprow);
        } while (not_ready);
 }
 
 
 // this is just a little changed version of break again
-void LyXText::breakAgainOneRow(BufferView * bview, Row * row)
+void LyXText::breakAgainOneRow(Row * row)
 {
-       pos_type z = rowBreakPoint(*bview, *row);
+       pos_type z = rowBreakPoint(*row);
        Row * tmprow = row;
 
        if (z < row->par()->size()) {
@@ -1344,7 +1397,6 @@ void LyXText::breakAgainOneRow(BufferView * bview, Row * row)
                        ++z;
                        insertRow(row, row->par(), z);
                        row = row->next();
-                       row->height(0);
                } else  {
                        row = row->next();
                        ++z;
@@ -1366,13 +1418,12 @@ void LyXText::breakAgainOneRow(BufferView * bview, Row * row)
        }
 
        // set the dimensions of the row
-       tmprow->fill(fill(*bview, *tmprow, workWidth(*bview)));
-       setHeightOfRow(bview, tmprow);
+       tmprow->fill(fill(*tmprow, workWidth()));
+       setHeightOfRow(tmprow);
 }
 
 
-void LyXText::breakParagraph(BufferView * bview,
-                            ParagraphList & paragraphs, char keep_layout)
+void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
 {
        // allow only if at start or end, or all previous is new text
        if (cursor.pos() && cursor.pos() != cursor.par()->size()
@@ -1380,7 +1431,7 @@ void LyXText::breakParagraph(BufferView * bview,
                return;
 
        LyXTextClass const & tclass =
-               bview->buffer()->params.getLyXTextClass();
+               bv()->buffer()->params.getLyXTextClass();
        LyXLayout_ptr const & layout = cursor.par()->layout();
 
        // this is only allowed, if the current paragraph is not empty or caption
@@ -1390,7 +1441,7 @@ void LyXText::breakParagraph(BufferView * bview,
           && !layout->keepempty)
                return;
 
-       setUndo(bview, Undo::FINISH, cursor.par(), cursor.par()->next());
+       setUndo(bv(), Undo::FINISH, cursor.par(), cursor.par()->next());
 
        // Always break behind a space
        //
@@ -1411,7 +1462,7 @@ void LyXText::breakParagraph(BufferView * bview,
        // paragraph before or behind and we should react on that one
        // but we can fix this in 1.3.0 (Jug 20020509)
        bool const isempty = (layout->keepempty && cursor.par()->empty());
-       ::breakParagraph(bview->buffer()->params, paragraphs, cursor.par(), cursor.pos(),
+       ::breakParagraph(bv()->buffer()->params, paragraphs, cursor.par(), cursor.pos(),
                       keep_layout);
 
        // well this is the caption hack since one caption is really enough
@@ -1431,28 +1482,28 @@ void LyXText::breakParagraph(BufferView * bview,
        if (cursor.pos() && !cursor.row()->par()->isNewline(cursor.row()->pos() - 1)
                         && cursor.row()->pos() == cursor.pos())
        {
-               cursorLeft(bview);
+               cursorLeft(bv());
        }
 
-       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(y);
+
        removeParagraph(cursor.row());
 
        // set the dimensions of the cursor row
-       cursor.row()->fill(fill(*bview, *cursor.row(), workWidth(*bview)));
+       cursor.row()->fill(fill(*cursor.row(), workWidth()));
 
-       setHeightOfRow(bview, cursor.row());
+       setHeightOfRow(cursor.row());
 
 #warning Trouble Point! (Lgb)
        // When ::breakParagraph is called from within an inset we must
@@ -1462,38 +1513,37 @@ void LyXText::breakParagraph(BufferView * bview,
          && cursor.par()->next()->isNewline(0))
           cursor.par()->next()->erase(0);
 
-       insertParagraph(bview, cursor.par()->next(), cursor.row());
-
-       updateCounters(bview);
+       insertParagraph(cursor.par()->next(), cursor.row());
+       updateCounters();
 
        // This check is necessary. Otherwise the new empty paragraph will
        // be deleted automatically. And it is more friendly for the user!
        if (cursor.pos() || isempty)
-               setCursor(bview, cursor.par()->next(), 0);
+               setCursor(cursor.par()->next(), 0);
        else
-               setCursor(bview, cursor.par(), 0);
+               setCursor(cursor.par(), 0);
 
        if (cursor.row()->next())
-               breakAgain(bview, cursor.row()->next());
+               breakAgain(cursor.row()->next());
 
        need_break_row = 0;
 }
 
 
 // Just a macro to make some thing easier.
-void LyXText::redoParagraph(BufferView * bview) const
+void LyXText::redoParagraph()
 {
        clearSelection();
-       redoParagraphs(bview, cursor, cursor.par()->next());
-       setCursorIntern(bview, cursor.par(), cursor.pos());
+       redoParagraphs(cursor, cursor.par()->next());
+       setCursorIntern(cursor.par(), cursor.pos());
 }
 
 
 // insert a character, moves all the following breaks in the
 // same Paragraph one to the right and make a rebreak
-void LyXText::insertChar(BufferView * bview, char c)
+void LyXText::insertChar(char c)
 {
-       setUndo(bview, Undo::INSERT, cursor.par(), cursor.par()->next());
+       setUndo(bv(), Undo::INSERT, cursor.par(), cursor.par()->next());
 
        // When the free-spacing option is set for the current layout,
        // disable the double-space checking
@@ -1511,17 +1561,17 @@ void LyXText::insertChar(BufferView * bview, char c)
                            !(contains(number_seperators, c) &&
                              cursor.pos() >= 1 &&
                              cursor.pos() < cursor.par()->size() &&
-                             getFont(bview->buffer(),
+                             getFont(bv()->buffer(),
                                      cursor.par(),
                                      cursor.pos()).number() == LyXFont::ON &&
-                             getFont(bview->buffer(),
+                             getFont(bv()->buffer(),
                                      cursor.par(),
                                      cursor.pos() - 1).number() == LyXFont::ON)
                           )
-                               number(bview); // Set current_font.number to OFF
+                               number(bv()); // Set current_font.number to OFF
                } else if (IsDigit(c) &&
                           real_current_font.isVisibleRightToLeft()) {
-                       number(bview); // Set current_font.number to ON
+                       number(bv()); // Set current_font.number to ON
 
                        if (cursor.pos() > 0) {
                                char const c = cursor.par()->getChar(cursor.pos() - 1);
@@ -1530,16 +1580,16 @@ void LyXText::insertChar(BufferView * bview, char c)
                                     cursor.par()->isSeparator(cursor.pos() - 2) ||
                                     cursor.par()->isNewline(cursor.pos() - 2))
                                  ) {
-                                       setCharFont(bview->buffer(),
+                                       setCharFont(bv()->buffer(),
                                                    cursor.par(),
                                                    cursor.pos() - 1,
                                                    current_font);
                                } else if (contains(number_seperators, c) &&
                                           cursor.pos() >= 2 &&
-                                          getFont(bview->buffer(),
+                                          getFont(bv()->buffer(),
                                                   cursor.par(),
                                                   cursor.pos() - 2).number() == LyXFont::ON) {
-                                       setCharFont(bview->buffer(),
+                                       setCharFont(bv()->buffer(),
                                                    cursor.par(),
                                                    cursor.pos() - 1,
                                                    current_font);
@@ -1568,7 +1618,7 @@ void LyXText::insertChar(BufferView * bview, char c)
        // Get the font that is used to calculate the baselineskip
        pos_type const lastpos = cursor.par()->size();
        LyXFont rawparfont =
-               cursor.par()->getFontSettings(bview->buffer()->params,
+               cursor.par()->getFontSettings(bv()->buffer()->params,
                                              lastpos - 1);
 
        bool jumped_over_space = false;
@@ -1582,31 +1632,19 @@ void LyXText::insertChar(BufferView * bview, char c)
                        static bool sent_space_message = false;
                        if (!sent_space_message) {
                                if (cursor.pos() == 0)
-                                       bview->owner()->message(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
+                                       bv()->owner()->message(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
                                else
-                                       bview->owner()->message(_("You cannot type two spaces this way. Please read the Tutorial."));
+                                       bv()->owner()->message(_("You cannot type two spaces this way. Please read the Tutorial."));
                                sent_space_message = true;
                        }
                        charInserted();
                        return;
                }
-       } else if (IsNewlineChar(c)) {
-               if (cursor.pos() <= cursor.par()->beginningOfBody()) {
-                       charInserted();
-                       return;
-               }
-               // No newline at first position of a paragraph or behind labels.
-               // TeX does not allow that
-
-               if (cursor.pos() < cursor.par()->size() &&
-                   cursor.par()->isLineSeparator(cursor.pos()))
-                       // newline always after a blank!
-                       cursorRight(bview);
-               cursor.row()->fill(-1);        // to force a new break
        }
 
        // the display inset stuff
-       if (cursor.row()->par()->isInset(cursor.row()->pos())) {
+       if (cursor.row()->pos() < cursor.row()->par()->size()
+           && cursor.row()->par()->isInset(cursor.row()->pos())) {
                Inset * inset = cursor.row()->par()->getInset(cursor.row()->pos());
                if (inset && (inset->display() || inset->needFullRow())) {
                        // force a new break
@@ -1621,7 +1659,7 @@ void LyXText::insertChar(BufferView * bview, char c)
                // Here case LyXText::InsertInset  already insertet the character
                cursor.par()->insertChar(cursor.pos(), c);
        }
-       setCharFont(bview->buffer(), cursor.par(), cursor.pos(), rawtmpfont);
+       setCharFont(bv()->buffer(), cursor.par(), cursor.pos(), rawtmpfont);
 
        if (!jumped_over_space) {
                // refresh the positions
@@ -1636,32 +1674,31 @@ void LyXText::insertChar(BufferView * bview, char c)
        if (row->previous() && row->previous()->par() == row->par()
            && (cursor.par()->isLineSeparator(cursor.pos())
                || cursor.par()->isNewline(cursor.pos())
-               || ((cursor.pos() < cursor.par()->size()) &&
-                   cursor.par()->isInset(cursor.pos()+1))
+               || ((cursor.pos() + 1 < cursor.par()->size()) &&
+                   cursor.par()->isInset(cursor.pos() + 1))
                || cursor.row()->fill() == -1))
        {
-               pos_type z = rowBreakPoint(*bview, *row->previous());
+               pos_type z = rowBreakPoint(*row->previous());
 
                if (z >= row->pos()) {
                        row->pos(z + 1);
 
                        // set the dimensions of the row above
-                       row->previous()->fill(fill(*bview,
+                       row->previous()->fill(fill(
                                                   *row->previous(),
-                                                  workWidth(*bview)));
+                                                  workWidth()));
 
-                       setHeightOfRow(bview, row->previous());
+                       setHeightOfRow(row->previous());
 
                        y -= row->previous()->height();
-                       refresh_y = y;
-                       refresh_row = row->previous();
-                       status(bview, LyXText::NEED_MORE_REFRESH);
 
-                       breakAgainOneRow(bview, row);
+                       postPaint(y);
+
+                       breakAgainOneRow(row);
 
                        current_font = rawtmpfont;
                        real_current_font = realtmpfont;
-                       setCursor(bview, cursor.par(), cursor.pos() + 1,
+                       setCursor(cursor.par(), cursor.pos() + 1,
                                  false, cursor.boundary());
                        // cursor MUST be in row now.
 
@@ -1673,7 +1710,7 @@ void LyXText::insertChar(BufferView * bview, char c)
                        // check, wether the last characters font has changed.
                        if (cursor.pos() && cursor.pos() == cursor.par()->size()
                            && rawparfont != rawtmpfont)
-                               redoHeightOfParagraph(bview, cursor);
+                               redoHeightOfParagraph();
 
                        charInserted();
                        return;
@@ -1684,60 +1721,59 @@ void LyXText::insertChar(BufferView * bview, char c)
        if (row->fill() >= 0) {
                // needed because a newline will set fill to -1. Otherwise
                // we would not get a rebreak!
-               row->fill(fill(*bview, *row, workWidth(*bview)));
+               row->fill(fill(*row, workWidth()));
        }
 
        if (c == Paragraph::META_INSET || row->fill() < 0) {
-               refresh_y = y;
-               refresh_row = row;
-               status(bview, LyXText::NEED_MORE_REFRESH);
-               breakAgainOneRow(bview, row);
+               postPaint(y);
+               breakAgainOneRow(row);
                // will the cursor be in another row now?
                if (row->lastPos() <= cursor.pos() + 1 && row->next()) {
                        if (row->next() && row->next()->par() == row->par())
                                // this should always be true
                                row = row->next();
-                       breakAgainOneRow(bview, row);
+                       breakAgainOneRow(row);
                }
                current_font = rawtmpfont;
                real_current_font = realtmpfont;
 
-               setCursor(bview, cursor.par(), cursor.pos() + 1, false,
+               setCursor(cursor.par(), cursor.pos() + 1, false,
                          cursor.boundary());
-               if (isBoundary(bview->buffer(), cursor.par(), cursor.pos())
+               if (isBoundary(bv()->buffer(), cursor.par(), cursor.pos())
                    != cursor.boundary())
-                       setCursor(bview, cursor.par(), cursor.pos(), false,
+                       setCursor(cursor.par(), cursor.pos(), false,
                          !cursor.boundary());
                if (row->next() && row->next()->par() == row->par())
                        need_break_row = row->next();
                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);
+
+               setHeightOfRow(row);
+
+               if (tmpheight == row->height()) {
+                       postRowPaint(row, y);
+               } else {
+                       postPaint(y);
+               }
 
                current_font = rawtmpfont;
                real_current_font = realtmpfont;
-               setCursor(bview, cursor.par(), cursor.pos() + 1, false,
+               setCursor(cursor.par(), cursor.pos() + 1, false,
                          cursor.boundary());
        }
 
        // check, wether the last characters font has changed.
        if (cursor.pos() && cursor.pos() == cursor.par()->size()
            && rawparfont != rawtmpfont) {
-               redoHeightOfParagraph(bview, cursor);
+               redoHeightOfParagraph();
        } else {
                // now the special right address boxes
                if (cursor.par()->layout()->margintype
                    == MARGIN_RIGHT_ADDRESS_BOX) {
-                       redoDrawingOfParagraph(bview, cursor);
+                       redoDrawingOfParagraph(cursor);
                }
        }
 
@@ -1759,8 +1795,7 @@ void LyXText::charInserted()
 }
 
 
-void LyXText::prepareToPrint(BufferView * bview,
-                            Row * row, float & x,
+void LyXText::prepareToPrint(Row * row, float & x,
                             float & fill_separator,
                             float & fill_hfill,
                             float & fill_label_hfill,
@@ -1776,13 +1811,13 @@ void LyXText::prepareToPrint(BufferView * bview,
        fill_label_hfill = 0;
 
        bool const is_rtl =
-               row->par()->isRightToLeftPar(bview->buffer()->params);
+               row->par()->isRightToLeftPar(bv()->buffer()->params);
        if (is_rtl) {
-               x = (workWidth(*bview) > 0)
-                       ? rightMargin(*bview->buffer(), *row) : 0;
+               x = (workWidth() > 0)
+                       ? rightMargin(*bv()->buffer(), *row) : 0;
        } else
-               x = (workWidth(*bview) > 0)
-                       ? leftMargin(bview, row) : 0;
+               x = (workWidth() > 0)
+                       ? leftMargin(row) : 0;
 
        // is there a manual margin with a manual label
        LyXLayout_ptr const & layout = row->par()->layout();
@@ -1799,9 +1834,9 @@ void LyXText::prepareToPrint(BufferView * bview,
                // is empty.
                if (!row->par()->empty())
                        ++nlh;
-                       
+
                if (nlh && !row->par()->getLabelWidthString().empty()) {
-                       fill_label_hfill = labelFill(*bview, *row) / nlh;
+                       fill_label_hfill = labelFill(*row) / nlh;
                }
        }
 
@@ -1814,7 +1849,7 @@ void LyXText::prepareToPrint(BufferView * bview,
        // we don't have to look at the alignment if it is ALIGN_LEFT and
        // if the row is already larger then the permitted width as then
        // we force the LEFT_ALIGN'edness!
-       } else if (static_cast<int>(row->width()) < workWidth(*bview)) {
+       } else if (static_cast<int>(row->width()) < workWidth()) {
                // is it block, flushleft or flushright?
                // set x how you need it
                int align;
@@ -1826,8 +1861,9 @@ void LyXText::prepareToPrint(BufferView * bview,
 
                // center displayed insets
                Inset * inset;
-               if (row->par()->isInset(row->pos())
-                   && (inset=row->par()->getInset(row->pos()))
+               if (row->pos() < row->par()->size()
+                   && row->par()->isInset(row->pos())
+                   && (inset = row->par()->getInset(row->pos()))
                    && (inset->display())) // || (inset->scroll() < 0)))
                    align = (inset->lyxCode() == Inset::MATHMACRO_CODE)
                        ? LYX_ALIGN_BLOCK : LYX_ALIGN_CENTER;
@@ -1865,7 +1901,7 @@ void LyXText::prepareToPrint(BufferView * bview,
        if (!bidi)
                return;
 
-       computeBidiTables(bview->buffer(), row);
+       computeBidiTables(bv()->buffer(), row);
        if (is_rtl) {
                pos_type body_pos = row->par()->beginningOfBody();
                pos_type last = row->lastPos();
@@ -1874,7 +1910,7 @@ void LyXText::prepareToPrint(BufferView * bview,
                    (body_pos - 1 > last ||
                     !row->par()->isLineSeparator(body_pos - 1))) {
                        x += font_metrics::width(layout->labelsep,
-                                           getLabelFont(bview->buffer(), row->par()));
+                                           getLabelFont(bv()->buffer(), row->par()));
                        if (body_pos - 1 <= last)
                                x += fill_label_hfill;
                }
@@ -1889,7 +1925,7 @@ void LyXText::prepareToPrint(BufferView * bview,
 // realize, that you left an empty paragraph, they will delete it.
 // They also delete the corresponding row
 
-void LyXText::cursorRightOneWord(BufferView * bview) const
+void LyXText::cursorRightOneWord()
 {
        // treat floats, HFills and Insets as words
        LyXCursor tmpcursor = cursor;
@@ -1917,11 +1953,11 @@ void LyXText::cursorRightOneWord(BufferView * bview) const
                        ++steps;
                }
        }
-       setCursor(bview, tmpcursor.par(), tmpcursor.pos());
+       setCursor(tmpcursor.par(), tmpcursor.pos());
 }
 
 
-void LyXText::cursorTab(BufferView * bview) const
+void LyXText::cursorTab()
 {
        LyXCursor tmpcursor = cursor;
        while (tmpcursor.pos() < tmpcursor.par()->size()
@@ -1935,27 +1971,28 @@ void LyXText::cursorTab(BufferView * bview) const
                }
        } else
                tmpcursor.pos(tmpcursor.pos() + 1);
-       setCursor(bview, tmpcursor.par(), tmpcursor.pos());
+       setCursor(tmpcursor.par(), tmpcursor.pos());
 }
 
 
 // Skip initial whitespace at end of word and move cursor to *start*
 // of prior word, not to end of next prior word.
-void LyXText::cursorLeftOneWord(BufferView * bview)  const
+void LyXText::cursorLeftOneWord()
 {
        LyXCursor tmpcursor = cursor;
        cursorLeftOneWord(tmpcursor);
-       setCursor(bview, tmpcursor.par(), tmpcursor.pos());
+       setCursor(tmpcursor.par(), tmpcursor.pos());
 }
 
 
-void LyXText::cursorLeftOneWord(LyXCursor & cur) const
+void LyXText::cursorLeftOneWord(LyXCursor & cur)
 {
        // treat HFills, floats and Insets as words
        cur = cursor;
        while (cur.pos()
               && (cur.par()->isSeparator(cur.pos() - 1)
-                  || cur.par()->isKomma(cur.pos() - 1))
+                  || cur.par()->isKomma(cur.pos() - 1)
+                  || cur.par()->isNewline(cur.pos() - 1))
               && !(cur.par()->isHfill(cur.pos() - 1)
                    || cur.par()->isInset(cur.pos() - 1)))
                cur.pos(cur.pos() - 1);
@@ -1980,7 +2017,7 @@ void LyXText::cursorLeftOneWord(LyXCursor & cur) const
 // Select current word. This depends on behaviour of
 // CursorLeftOneWord(), so it is patched as well.
 void LyXText::getWord(LyXCursor & from, LyXCursor & to,
-                     word_location const loc) const
+                     word_location const loc)
 {
        // first put the cursor where we wana start to select the word
        from = cursor;
@@ -1989,8 +2026,10 @@ void LyXText::getWord(LyXCursor & from, LyXCursor & to,
                if (cursor.pos() == 0 || cursor.pos() == cursor.par()->size()
                    || cursor.par()->isSeparator(cursor.pos())
                    || cursor.par()->isKomma(cursor.pos())
+                   || cursor.par()->isNewline(cursor.pos())
                    || cursor.par()->isSeparator(cursor.pos() - 1)
-                   || cursor.par()->isKomma(cursor.pos() - 1)) {
+                   || cursor.par()->isKomma(cursor.pos() - 1)
+                   || cursor.par()->isNewline(cursor.pos() - 1)) {
                        to = from;
                        return;
                }
@@ -1999,7 +2038,8 @@ void LyXText::getWord(LyXCursor & from, LyXCursor & to,
        case WHOLE_WORD:
                // Move cursor to the beginning, when not already there.
                if (from.pos() && !from.par()->isSeparator(from.pos() - 1)
-                   && !from.par()->isKomma(from.pos() - 1))
+                   && !(from.par()->isKomma(from.pos() - 1)
+                        || from.par()->isNewline(from.pos() - 1)))
                        cursorLeftOneWord(from);
                break;
        case PREVIOUS_WORD:
@@ -2016,6 +2056,7 @@ void LyXText::getWord(LyXCursor & from, LyXCursor & to,
        while (to.pos() < to.par()->size()
               && !to.par()->isSeparator(to.pos())
               && !to.par()->isKomma(to.pos())
+              && !to.par()->isNewline(to.pos())
               && !to.par()->isHfill(to.pos())
               && !to.par()->isInset(to.pos()))
        {
@@ -2024,71 +2065,70 @@ void LyXText::getWord(LyXCursor & from, LyXCursor & to,
 }
 
 
-void LyXText::selectWord(BufferView * bview, word_location const loc)
+void LyXText::selectWord(word_location loc)
 {
        LyXCursor from;
        LyXCursor to;
        getWord(from, to, loc);
        if (cursor != from)
-               setCursor(bview, from.par(), from.pos());
+               setCursor(from.par(), from.pos());
        if (to == from)
                return;
        selection.cursor = cursor;
-       setCursor(bview, to.par(), to.pos());
-       setSelection(bview);
+       setCursor(to.par(), to.pos());
+       setSelection();
 }
 
 
 // Select the word currently under the cursor when no
 // selection is currently set
-bool LyXText::selectWordWhenUnderCursor(BufferView * bview,
-                                       word_location const loc)
+bool LyXText::selectWordWhenUnderCursor(word_location loc)
 {
        if (!selection.set()) {
-               selectWord(bview, loc);
+               selectWord(loc);
                return selection.set();
        }
        return false;
 }
 
 
-void LyXText::acceptChange(BufferView * bv)
+void LyXText::acceptChange()
 {
        if (!selection.set() && cursor.par()->size())
                return;
 
-       bv->hideCursor();
+       bv()->hideCursor();
 
        if (selection.start.par() == selection.end.par()) {
                LyXCursor & startc = selection.start;
                LyXCursor & endc = selection.end;
-               setUndo(bv, Undo::INSERT, startc.par(), startc.par()->next());
+               setUndo(bv(), Undo::INSERT, startc.par(), startc.par()->next());
                startc.par()->acceptChange(startc.pos(), endc.pos());
                finishUndo();
                clearSelection();
-               redoParagraphs(bv, startc, startc.par()->next());
-               setCursorIntern(bv, startc.par(), 0);
+               redoParagraphs(startc, startc.par()->next());
+               setCursorIntern(startc.par(), 0);
        }
 #warning handle multi par selection
 }
 
 
-void LyXText::rejectChange(BufferView * bv)
+void LyXText::rejectChange()
 {
        if (!selection.set() && cursor.par()->size())
                return;
 
-       bv->hideCursor();
+       bv()->hideCursor();
 
        if (selection.start.par() == selection.end.par()) {
                LyXCursor & startc = selection.start;
                LyXCursor & endc = selection.end;
-               setUndo(bv, Undo::INSERT, startc.par(), startc.par()->next());
+               setUndo(bv(), Undo::INSERT, startc.par(), startc.par()->next());
                startc.par()->rejectChange(startc.pos(), endc.pos());
                finishUndo();
                clearSelection();
-               redoParagraphs(bv, startc, startc.par()->next());
-               setCursorIntern(bv, startc.par(), 0);
+               redoParagraphs(startc, startc.par()->next());
+               setCursorIntern(startc.par(), 0);
        }
 #warning handle multi par selection
 }
@@ -2097,10 +2137,10 @@ void LyXText::rejectChange(BufferView * bv)
 // This function is only used by the spellchecker for NextWord().
 // It doesn't handle LYX_ACCENTs and probably never will.
 WordLangTuple const
-LyXText::selectNextWordToSpellcheck(BufferView * bview, float & value) const
+LyXText::selectNextWordToSpellcheck(float & value)
 {
        if (the_locking_inset) {
-               WordLangTuple word = the_locking_inset->selectNextWordToSpellcheck(bview, value);
+               WordLangTuple word = the_locking_inset->selectNextWordToSpellcheck(bv(), value);
                if (!word.word().empty()) {
                        value += float(cursor.y());
                        value /= float(height);
@@ -2154,15 +2194,15 @@ LyXText::selectNextWordToSpellcheck(BufferView * bview, float & value) const
        if (cursor.pos() < cursor.par()->size() &&
            cursor.par()->isInset(cursor.pos())) {
                // lock the inset!
-               cursor.par()->getInset(cursor.pos())->edit(bview);
+               cursor.par()->getInset(cursor.pos())->edit(bv());
                // now call us again to do the above trick
                // but obviously we have to start from down below ;)
-               return bview->text->selectNextWordToSpellcheck(bview, value);
+               return bv()->text->selectNextWordToSpellcheck(value);
        }
 
        // Update the value if we changed paragraphs
        if (cursor.par() != tmppar) {
-               setCursor(bview, cursor.par(), cursor.pos());
+               setCursor(cursor.par(), cursor.pos());
                value = float(cursor.y())/float(height);
        }
 
@@ -2170,7 +2210,7 @@ LyXText::selectNextWordToSpellcheck(BufferView * bview, float & value) const
        selection.cursor = cursor;
 
        string lang_code(
-               getFont(bview->buffer(), cursor.par(), cursor.pos())
+               getFont(bv()->buffer(), cursor.par(), cursor.pos())
                        .language()->code());
        // and find the end of the word (insets like optional hyphens
        // and ligature break are part of a word)
@@ -2193,14 +2233,14 @@ LyXText::selectNextWordToSpellcheck(BufferView * bview, float & value) const
 
 
 // This one is also only for the spellchecker
-void LyXText::selectSelectedWord(BufferView * bview)
+void LyXText::selectSelectedWord()
 {
        if (the_locking_inset) {
-               the_locking_inset->selectSelectedWord(bview);
+               the_locking_inset->selectSelectedWord(bv());
                return;
        }
        // move cursor to the beginning
-       setCursor(bview, selection.cursor.par(), selection.cursor.pos());
+       setCursor(selection.cursor.par(), selection.cursor.pos());
 
        // set the sel cursor
        selection.cursor = cursor;
@@ -2210,81 +2250,81 @@ void LyXText::selectSelectedWord(BufferView * bview)
               && (cursor.par()->isLetter(cursor.pos())))
                cursor.pos(cursor.pos() + 1);
 
-       setCursor(bview, cursor.par(), cursor.pos());
+       setCursor(cursor.par(), cursor.pos());
 
        // finally set the selection
-       setSelection(bview);
+       setSelection();
 }
 
 
 // Delete from cursor up to the end of the current or next word.
-void LyXText::deleteWordForward(BufferView * bview)
+void LyXText::deleteWordForward()
 {
        if (cursor.par()->empty())
-               cursorRight(bview);
+               cursorRight(bv());
        else {
                LyXCursor tmpcursor = cursor;
                tmpcursor.row(0); // ??
                selection.set(true); // to avoid deletion
-               cursorRightOneWord(bview);
-               setCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
+               cursorRightOneWord();
+               setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
                selection.cursor = cursor;
                cursor = tmpcursor;
-               setSelection(bview);
+               setSelection();
 
                // Great, CutSelection() gets rid of multiple spaces.
-               cutSelection(bview, true, false);
+               cutSelection(true, false);
        }
 }
 
 
 // Delete from cursor to start of current or prior word.
-void LyXText::deleteWordBackward(BufferView * bview)
+void LyXText::deleteWordBackward()
 {
        if (cursor.par()->empty())
-               cursorLeft(bview);
+               cursorLeft(bv());
        else {
                LyXCursor tmpcursor = cursor;
                tmpcursor.row(0); // ??
                selection.set(true); // to avoid deletion
-               cursorLeftOneWord(bview);
-               setCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
+               cursorLeftOneWord();
+               setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
                selection.cursor = cursor;
                cursor = tmpcursor;
-               setSelection(bview);
-               cutSelection(bview, true, false);
+               setSelection();
+               cutSelection(true, false);
        }
 }
 
 
 // Kill to end of line.
-void LyXText::deleteLineForward(BufferView * bview)
+void LyXText::deleteLineForward()
 {
        if (cursor.par()->empty())
                // Paragraph is empty, so we just go to the right
-               cursorRight(bview);
+               cursorRight(bv());
        else {
                LyXCursor tmpcursor = cursor;
                // We can't store the row over a regular setCursor
                // so we set it to 0 and reset it afterwards.
                tmpcursor.row(0); // ??
                selection.set(true); // to avoid deletion
-               cursorEnd(bview);
-               setCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
+               cursorEnd();
+               setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
                selection.cursor = cursor;
                cursor = tmpcursor;
-               setSelection(bview);
+               setSelection();
                // What is this test for ??? (JMarc)
                if (!selection.set()) {
-                       deleteWordForward(bview);
+                       deleteWordForward();
                } else {
-                       cutSelection(bview, true, false);
+                       cutSelection(true, false);
                }
        }
 }
 
 
-void LyXText::changeCase(BufferView & bview, LyXText::TextCase action)
+void LyXText::changeCase(LyXText::TextCase action)
 {
        LyXCursor from;
        LyXCursor to;
@@ -2294,12 +2334,12 @@ void LyXText::changeCase(BufferView & bview, LyXText::TextCase action)
                to = selection.end;
        } else {
                getWord(from, to, PARTIAL_WORD);
-               setCursor(&bview, to.par(), to.pos() + 1);
+               setCursor(to.par(), to.pos() + 1);
        }
 
        lyx::Assert(from <= to);
 
-       setUndo(&bview, Undo::FINISH, from.par(), to.par()->next());
+       setUndo(bv(), Undo::FINISH, from.par(), to.par()->next());
 
        pos_type pos = from.pos();
        Paragraph * par = from.par();
@@ -2311,7 +2351,7 @@ void LyXText::changeCase(BufferView & bview, LyXText::TextCase action)
                        continue;
                }
                unsigned char c = par->getChar(pos);
-               if (!IsInsetChar(c) && !IsHfillChar(c)) {
+               if (!IsInsetChar(c)) {
                        switch (action) {
                        case text_lowercase:
                                c = lowercase(c);
@@ -2327,23 +2367,21 @@ void LyXText::changeCase(BufferView & bview, LyXText::TextCase action)
                }
 #warning changes
                par->setChar(pos, c);
-               checkParagraph(&bview, par, pos);
+               checkParagraph(par, pos);
 
                ++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(from.y() - from.row()->baseline());
 }
 
 
-void LyXText::transposeChars(BufferView & bview)
+void LyXText::transposeChars()
 {
        Paragraph * tmppar = cursor.par();
 
-       setUndo(&bview, Undo::FINISH, tmppar, tmppar->next());
+       setUndo(bv(), Undo::FINISH, tmppar, tmppar->next());
 
        pos_type tmppos = cursor.pos();
 
@@ -2370,11 +2408,11 @@ void LyXText::transposeChars(BufferView & bview)
        tmppar->insertChar(ipos, c1);
        tmppar->insertChar(ipos + 1, c2);
 
-       checkParagraph(&bview, tmppar, tmppos);
+       checkParagraph(tmppar, tmppos);
 }
 
 
-void LyXText::Delete(BufferView * bview)
+void LyXText::Delete()
 {
        // this is a very easy implementation
 
@@ -2384,7 +2422,7 @@ void LyXText::Delete(BufferView * bview)
                old_cursor.par()->previous()->id() : -1;
 
        // just move to the right
-       cursorRight(bview);
+       cursorRight(bv());
 
        // CHECK Look at the comment here.
        // This check is not very good...
@@ -2404,20 +2442,20 @@ void LyXText::Delete(BufferView * bview)
                LyXCursor tmpcursor = cursor;
                // to make sure undo gets the right cursor position
                cursor = old_cursor;
-               setUndo(bview, Undo::DELETE,
+               setUndo(bv(), Undo::DELETE,
                        cursor.par(), cursor.par()->next());
                cursor = tmpcursor;
-               backspace(bview);
+               backspace();
        }
 }
 
 
-void LyXText::backspace(BufferView * bview)
+void LyXText::backspace()
 {
        // Get the font that is used to calculate the baselineskip
        pos_type lastpos = cursor.par()->size();
        LyXFont rawparfont =
-               cursor.par()->getFontSettings(bview->buffer()->params,
+               cursor.par()->getFontSettings(bv()->buffer()->params,
                                              lastpos - 1);
 
        if (cursor.pos() == 0) {
@@ -2449,22 +2487,20 @@ void LyXText::backspace(BufferView * bview)
                                        tmppar->params().pagebreakBottom(cursor.par()->params().pagebreakBottom());
                                }
 
-                               cursorLeft(bview);
+                               cursorLeft(bv());
 
                                // the layout things can change the height of a row !
                                int const tmpheight = cursor.row()->height();
-                               setHeightOfRow(bview, cursor.row());
+                               setHeightOfRow(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(cursor.y() - cursor.row()->baseline());
                                }
                                return;
                        }
                }
 
                if (cursor.par()->previous()) {
-                       setUndo(bview, Undo::DELETE,
+                       setUndo(bv(), Undo::DELETE,
                                cursor.par()->previous(), cursor.par()->next());
                }
 
@@ -2477,7 +2513,7 @@ void LyXText::backspace(BufferView * bview)
                // without the dreaded mechanism. (JMarc)
                if (cursor.par()->previous()) {
                        // steps into the above paragraph.
-                       setCursorIntern(bview, cursor.par()->previous(),
+                       setCursorIntern(cursor.par()->previous(),
                                        cursor.par()->previous()->size(),
                                        false);
                }
@@ -2492,7 +2528,7 @@ void LyXText::backspace(BufferView * bview)
 
                //      Correction: Pasting is always allowed with standard-layout
                LyXTextClass const & tclass =
-                       bview->buffer()->params.getLyXTextClass();
+                       bv()->buffer()->params.getLyXTextClass();
 
                if (cursor.par() != tmppar
                    && (cursor.par()->layout() == tmppar->layout()
@@ -2500,7 +2536,7 @@ void LyXText::backspace(BufferView * bview)
                    && cursor.par()->getAlign() == tmppar->getAlign()) {
                        removeParagraph(tmprow);
                        removeRow(tmprow);
-                       mergeParagraph(bview->buffer()->params, bview->buffer()->paragraphs, cursor.par());
+                       mergeParagraph(bv()->buffer()->params, bv()->buffer()->paragraphs, cursor.par());
 
                        if (!cursor.pos() || !cursor.par()->isSeparator(cursor.pos() - 1))
                                ; //cursor.par()->insertChar(cursor.pos(), ' ');
@@ -2511,9 +2547,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(cursor.y() - cursor.row()->baseline());
 
                        // remove the lost paragraph
                        // This one is not safe, since the paragraph that the tmprow and the
@@ -2524,22 +2558,22 @@ void LyXText::backspace(BufferView * bview)
                        //RemoveRow(tmprow);
 
                        // This rebuilds the rows.
-                       appendParagraph(bview, cursor.row());
-                       updateCounters(bview);
+                       appendParagraph(cursor.row());
+                       updateCounters();
 
                        // the row may have changed, block, hfills etc.
-                       setCursor(bview, cursor.par(), cursor.pos(), false);
+                       setCursor(cursor.par(), cursor.pos(), false);
                }
        } else {
                // this is the code for a normal backspace, not pasting
                // any paragraphs
-               setUndo(bview, Undo::DELETE,
+               setUndo(bv(), Undo::DELETE,
                        cursor.par(), cursor.par()->next());
                // We used to do cursorLeftIntern() here, but it is
                // not a good idea since it triggers the auto-delete
                // mechanism. So we do a cursorLeftIntern()-lite,
                // without the dreaded mechanism. (JMarc)
-               setCursorIntern(bview, cursor.par(), cursor.pos()- 1,
+               setCursorIntern(cursor.par(), cursor.pos()- 1,
                                false, cursor.boundary());
 
                if (cursor.par()->isInset(cursor.pos())) {
@@ -2548,7 +2582,7 @@ void LyXText::backspace(BufferView * bview)
                        if (cursor.par()->getInset(cursor.pos())->display() ||
                            cursor.par()->getInset(cursor.pos())->needFullRow()) {
                                cursor.par()->erase(cursor.pos());
-                               redoParagraph(bview);
+                               redoParagraph();
                                return;
                        }
                }
@@ -2560,7 +2594,7 @@ void LyXText::backspace(BufferView * bview)
                // when calculating the fill
                if (cursor.pos() < row->lastPos() ||
                    !cursor.par()->isLineSeparator(cursor.pos())) {
-                       row->fill(row->fill() + singleWidth(bview,
+                       row->fill(row->fill() + singleWidth(
                                                            cursor.par(),
                                                            cursor.pos()));
                }
@@ -2581,7 +2615,7 @@ void LyXText::backspace(BufferView * bview)
                        if (cursor.pos() < cursor.par()->size()
                            && !cursor.par()->isSeparator(cursor.pos())) {
                                cursor.par()->insertChar(cursor.pos(), ' ');
-                               setCharFont(bview->buffer(), cursor.par(),
+                               setCharFont(bv()->buffer(), cursor.par(),
                                            cursor.pos(), current_font);
                                // refresh the positions
                                tmprow = row;
@@ -2603,6 +2637,7 @@ void LyXText::backspace(BufferView * bview)
 
                        // delete newlines at the beginning of paragraphs
                        while (!cursor.par()->empty() &&
+                              cursor.pos() < cursor.par()->size() &&
                               cursor.par()->isNewline(cursor.pos()) &&
                               cursor.pos() == cursor.par()->beginningOfBody()) {
                                cursor.par()->erase(cursor.pos());
@@ -2618,7 +2653,7 @@ void LyXText::backspace(BufferView * bview)
 
                // is there a break one row above
                if (row->previous() && row->previous()->par() == row->par()) {
-                       z = rowBreakPoint(*bview, *row->previous());
+                       z = rowBreakPoint(*row->previous());
                        if (z >= row->pos()) {
                                row->pos(z + 1);
 
@@ -2630,7 +2665,7 @@ void LyXText::backspace(BufferView * bview)
                                        removeRow(row);
                                        need_break_row = 0;
                                } else {
-                                       breakAgainOneRow(bview, row);
+                                       breakAgainOneRow(row);
                                        if (row->next() && row->next()->par() == row->par())
                                                need_break_row = row->next();
                                        else
@@ -2639,21 +2674,20 @@ void LyXText::backspace(BufferView * bview)
 
                                // set the dimensions of the row above
                                y -= tmprow->height();
-                               tmprow->fill(fill(*bview, *tmprow, workWidth(*bview)));
-                               setHeightOfRow(bview, tmprow);
+                               tmprow->fill(fill(*tmprow, workWidth()));
+                               setHeightOfRow(tmprow);
+
+                               postPaint(y);
 
-                               refresh_y = y;
-                               refresh_row = tmprow;
-                               status(bview, LyXText::NEED_MORE_REFRESH);
-                               setCursor(bview, cursor.par(), cursor.pos(),
+                               setCursor(cursor.par(), cursor.pos(),
                                          false, cursor.boundary());
                                //current_font = rawtmpfont;
                                //real_current_font = realtmpfont;
                                // check, whether the last character's font has changed.
                                if (rawparfont !=
-                                   cursor.par()->getFontSettings(bview->buffer()->params,
+                                   cursor.par()->getFontSettings(bv()->buffer()->params,
                                                                  cursor.par()->size() - 1))
-                                       redoHeightOfParagraph(bview, cursor);
+                                       redoHeightOfParagraph();
                                return;
                        }
                }
@@ -2661,7 +2695,7 @@ void LyXText::backspace(BufferView * bview)
                // break the cursor row again
                if (row->next() && row->next()->par() == row->par() &&
                    (row->lastPos() == row->par()->size() - 1 ||
-                    rowBreakPoint(*bview, *row) != row->lastPos())) {
+                    rowBreakPoint(*row) != row->lastPos())) {
 
                        // it can happen that a paragraph loses one row
                        // without a real breakup. This is when a word
@@ -2670,19 +2704,17 @@ 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(y);
 
-                       breakAgainOneRow(bview, row);
+                       breakAgainOneRow(row);
                        // will the cursor be in another row now?
                        if (row->next() && row->next()->par() == row->par() &&
                            row->lastPos() <= cursor.pos()) {
                                row = row->next();
-                               breakAgainOneRow(bview, row);
+                               breakAgainOneRow(row);
                        }
 
-                       setCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
+                       setCursor(cursor.par(), cursor.pos(), false, cursor.boundary());
 
                        if (row->next() && row->next()->par() == row->par())
                                need_break_row = row->next();
@@ -2690,164 +2722,51 @@ void LyXText::backspace(BufferView * bview)
                                need_break_row = 0;
                } else  {
                        // set the dimensions of the row
-                       row->fill(fill(*bview, *row, workWidth(*bview)));
+                       row->fill(fill(*row, workWidth()));
                        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;
-                       setCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
+                       setHeightOfRow(row);
+                       if (tmpheight == row->height()) {
+                               postRowPaint(row, y);
+                       } else {
+                               postPaint(y);
+                       }
+                       setCursor(cursor.par(), cursor.pos(), false, cursor.boundary());
                }
        }
 
        // current_font = rawtmpfont;
        // real_current_font = realtmpfont;
 
-       if (isBoundary(bview->buffer(), cursor.par(), cursor.pos())
+       if (isBoundary(bv()->buffer(), cursor.par(), cursor.pos())
            != cursor.boundary())
-               setCursor(bview, cursor.par(), cursor.pos(), false,
+               setCursor(cursor.par(), cursor.pos(), false,
                          !cursor.boundary());
 
        lastpos = cursor.par()->size();
        if (cursor.pos() == lastpos)
-               setCurrentFont(bview);
+               setCurrentFont();
 
        // check, whether the last characters font has changed.
        if (rawparfont !=
-           cursor.par()->getFontSettings(bview->buffer()->params, lastpos - 1)) {
-               redoHeightOfParagraph(bview, cursor);
+           cursor.par()->getFontSettings(bv()->buffer()->params, lastpos - 1)) {
+               redoHeightOfParagraph();
        } else {
                // now the special right address boxes
                if (cursor.par()->layout()->margintype
                    == MARGIN_RIGHT_ADDRESS_BOX) {
-                       redoDrawingOfParagraph(bview, cursor);
-               }
-       }
-}
-
-
-// returns the column near the specified x-coordinate of the row
-// x is set to the real beginning of this column
-pos_type
-LyXText::getColumnNearX(BufferView * bview, Row * row, int & x,
-                       bool & boundary) const
-{
-       float tmpx = 0.0;
-       float fill_separator;
-       float fill_hfill;
-       float fill_label_hfill;
-
-       prepareToPrint(bview, row, tmpx, fill_separator,
-                      fill_hfill, fill_label_hfill);
-
-       pos_type vc = row->pos();
-       pos_type last = row->lastPrintablePos();
-       pos_type c = 0;
-
-       LyXLayout_ptr const & layout = row->par()->layout();
-
-       bool left_side = false;
-
-       pos_type body_pos = row->par()->beginningOfBody();
-       float last_tmpx = tmpx;
-
-       if (body_pos > 0 &&
-           (body_pos - 1 > last ||
-            !row->par()->isLineSeparator(body_pos - 1)))
-               body_pos = 0;
-
-       // check for empty row
-       if (!row->par()->size()) {
-               x = int(tmpx);
-               return 0;
-       }
-
-       while (vc <= last && tmpx <= x) {
-               c = vis2log(vc);
-               last_tmpx = tmpx;
-               if (body_pos > 0 && c == body_pos-1) {
-                       tmpx += fill_label_hfill +
-                               font_metrics::width(layout->labelsep,
-                                              getLabelFont(bview->buffer(), row->par()));
-                       if (row->par()->isLineSeparator(body_pos - 1))
-                               tmpx -= singleWidth(bview, row->par(), body_pos-1);
-               }
-
-               if (row->hfillExpansion(c)) {
-                       tmpx += singleWidth(bview, row->par(), c);
-                       if (c >= body_pos)
-                               tmpx += fill_hfill;
-                       else
-                               tmpx += fill_label_hfill;
-               } else if (row->par()->isSeparator(c)) {
-                       tmpx += singleWidth(bview, row->par(), c);
-                       if (c >= body_pos)
-                               tmpx+= fill_separator;
-               } else {
-                       tmpx += singleWidth(bview, row->par(), c);
-               }
-               ++vc;
-       }
-
-       if ((tmpx + last_tmpx) / 2 > x) {
-               tmpx = last_tmpx;
-               left_side = true;
-       }
-
-       if (vc > last + 1)  // This shouldn't happen.
-               vc = last + 1;
-
-       boundary = false;
-       bool const lastrow = lyxrc.rtl_support // This is not needed, but gives
-                                        // some speedup if rtl_support=false
-               && (!row->next() || row->next()->par() != row->par());
-       bool const rtl = (lastrow)
-               ? row->par()->isRightToLeftPar(bview->buffer()->params)
-               : false; // If lastrow is false, we don't need to compute
-                        // the value of rtl.
-
-       if (lastrow &&
-                ((rtl &&  left_side && vc == row->pos() && x < tmpx - 5) ||
-                  (!rtl && !left_side && vc == last + 1   && x > tmpx + 5)))
-               c = last + 1;
-       else if (vc == row->pos()) {
-               c = vis2log(vc);
-               if (bidi_level(c) % 2 == 1)
-                       ++c;
-       } else {
-               c = vis2log(vc - 1);
-               bool const rtl = (bidi_level(c) % 2 == 1);
-               if (left_side == rtl) {
-                       ++c;
-                       boundary = isBoundary(bview->buffer(), row->par(), c);
+                       redoDrawingOfParagraph(cursor);
                }
        }
-
-       if (row->pos() <= last && c > last
-           && row->par()->isNewline(last)) {
-               if (bidi_level(last) % 2 == 0)
-                       tmpx -= singleWidth(bview, row->par(), last);
-               else
-                       tmpx += singleWidth(bview, row->par(), last);
-               c = last;
-       }
-
-       c -= row->pos();
-       x = int(tmpx);
-       return c;
 }
 
 
 // returns pointer to a specified row
 Row * LyXText::getRow(Paragraph * par, pos_type pos, int & y) const
 {
-       if (!firstrow)
+       if (!firstRow())
                return 0;
 
-       Row * tmprow = firstrow;
+       Row * tmprow = firstRow();
        y = 0;
 
        // find the first row of the specified paragraph
@@ -2873,7 +2792,7 @@ Row * LyXText::getRowNearY(int & y) const
 {
 #if 1
        // If possible we should optimize this method. (Lgb)
-       Row * tmprow = firstrow;
+       Row * tmprow = firstRow();
        int tmpy = 0;
 
        while (tmprow->next() && tmpy + tmprow->height() <= y) {