X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Frowpainter.C;h=3b703b58d49080700bb0b2ae5608b4e11e93481a;hb=c688967bc365872241697371e7bd12e2b5217028;hp=1ac042d13c1c28be2c754f5df3e90a6f582277c3;hpb=b11b6f78b1153198dd8dba2bc7da4c56bfa20dab;p=lyx.git diff --git a/src/rowpainter.C b/src/rowpainter.C index 1ac042d13c..3b703b58d4 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -32,6 +32,7 @@ #include "vspace.h" #include "frontends/font_metrics.h" +#include "frontends/nullpainter.h" #include "frontends/Painter.h" #include "insets/insettext.h" @@ -57,8 +58,8 @@ namespace { class RowPainter { public: /// initialise and run painter - RowPainter(BufferView const & bv, LyXText const & text, - par_type pit, RowList::iterator rit, int xo, int yo); + RowPainter(BufferView const & bv, Painter & pain, LyXText const & text, + par_type pit, RowList::iterator rit, int y); private: // paint various parts void paintBackground(); @@ -118,10 +119,11 @@ private: }; -RowPainter::RowPainter(BufferView const & bv, LyXText const & text, - par_type pit, RowList::iterator rit, int xo, int yo) - : bv_(bv), pain_(bv_.painter()), text_(text), pars_(text.paragraphs()), - rit_(rit), row_(*rit), pit_(pit), xo_(xo), yo_(yo), width_(text_.width()) +RowPainter::RowPainter(BufferView const & bv, Painter & pain, + LyXText const & text, par_type pit, RowList::iterator rit, int y) + : bv_(bv), pain_(pain), text_(text), pars_(text.paragraphs()), + rit_(rit), row_(*rit), pit_(pit), + xo_(text_.xo_), yo_(y), width_(text_.width()) { //lyxerr << "RowPainter: x: " << x_ << " xo: " << xo << " yo: " << yo // << " pit->y: " << pit_->y @@ -196,7 +198,7 @@ void RowPainter::paintInset(pos_type const pos) { InsetBase const * inset = pars_[pit_].getInset(pos); BOOST_ASSERT(inset); - PainterInfo pi(const_cast(&bv_)); + PainterInfo pi(const_cast(&bv_), pain_); pi.base.font = getFont(pos); inset->drawSelection(pi, int(x_), yo_ + row_.baseline()); inset->draw(pi, int(x_), yo_ + row_.baseline()); @@ -396,8 +398,6 @@ void RowPainter::paintSelection() // the current selection LCursor const & cur = bv_.cursor(); - int const startx = text_.cursorX(cur.selBegin()); - int const endx = text_.cursorX(cur.selEnd()); int const starty = text_.cursorY(cur.selBegin()); int const endy = text_.cursorY(cur.selEnd()); par_type startpit = cur.selBegin().par(); @@ -414,14 +414,18 @@ void RowPainter::paintSelection() if (text_.bidi.same_direction()) { if (sel_on_one_row) { + int const startx = text_.cursorX(cur.selBegin()); + int const endx = text_.cursorX(cur.selEnd()); int const x1 = is_rtl ? endx : startx; int const x2 = is_rtl ? startx : endx; pain_.fillRectangle(x1, yo_, x2 - x1, h, LColor::selection); } else if (sel_starts_here) { + int const startx = text_.cursorX(cur.selBegin()); int const x1 = is_rtl ? int(xo_) : startx; int const x2 = is_rtl ? startx : int(xo_) + width_; pain_.fillRectangle(x1, yo_, x2 - x1, h, LColor::selection); } else if (sel_ends_here) { + int const endx = text_.cursorX(cur.selEnd()); int const x1 = is_rtl ? endx : int(xo_); int const x2 = is_rtl ? int(xo_) + width_ : endx; pain_.fillRectangle(x1, yo_, x2 - x1, h, LColor::selection); @@ -844,43 +848,53 @@ void RowPainter::paintText() } -int paintPars(BufferView const & bv, LyXText const & text, - par_type pit, int xo, int yo, int y) +int paintPars(BufferView const & bv, Painter & pain, + LyXText const & text, par_type pit, par_type end) { //lyxerr << " paintRows: pit: " << &*pit << endl; - int const y2 = bv.painter().paperHeight(); - y -= bv.top_y(); - ParagraphList & pars = text.paragraphs(); - for ( ; pit != par_type(pars.size()); ++pit) { + + int y = pars[pit].y + text.yo_ - bv.top_y(); + int const y2 = pain.paperHeight(); + + for (; pit != end; ++pit) { RowList::iterator row = pars[pit].rows.begin(); RowList::iterator rend = pars[pit].rows.end(); for ( ; row != rend; ++row) { - RowPainter(bv, text, pit, row, xo, y + yo); + RowPainter(bv, pain, text, pit, row, y); y += row->height(); + if (y >= y2) + break; } - if (yo + y >= y2) - break; - } + } return y; } + } // namespace anon +void refreshPar(BufferView const & bv, LyXText const & text, par_type pit) +{ + + static NullPainter nop; + paintPars(bv, nop, text, pit, pit + 1); +} + + int paintText(BufferView const & bv) { - par_type pit; - bv.text()->updateParPositions(); - bv.text()->getRowNearY(bv.top_y(), pit); + par_type pit, end; + getParsInRange(bv.text()->paragraphs(), bv.top_y(), + bv.top_y() + bv.workHeight(), pit, end); //lyxerr << "top_y: " << bv.top_y() << " y: " << pit->y << endl; - return paintPars(bv, *bv.text(), pit, 0, 0, bv.text()->paragraphs()[pit].y); + return paintPars(bv, bv.painter(), *bv.text(), pit, end); } -void paintTextInset(LyXText const & text, PainterInfo & pi, int xo, int yo) +void paintTextInset(LyXText const & text, PainterInfo & pi) { - paintPars(*pi.base.bv, text, 0, xo, yo, 0); + paintPars(*pi.base.bv, pi.pain, text, 0, text.paragraphs().size()); }