3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
14 #include "rowpainter.h"
17 #include "coordcache.h"
20 #include "bufferparams.h"
21 #include "BufferView.h"
28 #include "metricsinfo.h"
29 #include "paragraph.h"
30 #include "ParagraphMetrics.h"
31 #include "paragraph_funcs.h"
32 #include "ParagraphParameters.h"
33 #include "TextMetrics.h"
36 #include "frontends/FontMetrics.h"
37 #include "frontends/Painter.h"
39 #include "insets/insettext.h"
41 #include "support/textutils.h"
43 #include <boost/crc.hpp>
48 using frontend::Painter;
49 using frontend::FontMetrics;
58 /// Flag: do a full redraw of inside text of inset
59 /// Working variable indicating a full screen refresh
63 * A class used for painting an individual row of text.
67 /// initialise and run painter
68 RowPainter(PainterInfo & pi, LyXText const & text,
69 pit_type pit, Row const & row, int x, int y);
71 // paint various parts
74 void paintChangeBar();
78 int maxWidth() { return max_width_; }
81 void paintForeignMark(double orig_x, LyXFont const & font, int desc = 0);
82 void paintHebrewComposeChar(pos_type & vpos, LyXFont const & font);
83 void paintArabicComposeChar(pos_type & vpos, LyXFont const & font);
84 void paintChars(pos_type & vpos, LyXFont const & font,
85 bool hebrew, bool arabic);
86 int paintAppendixStart(int y);
87 void paintFromPos(pos_type & vpos);
88 void paintInset(pos_type const pos, LyXFont const & font);
90 /// return left margin
91 int leftMargin() const;
93 /// return the label font for this row
94 LyXFont const getLabelFont() const;
96 /// bufferview to paint on
102 /// LyXText for the row
103 LyXText const & text_;
104 TextMetrics & text_metrics_;
105 ParagraphList const & pars_;
112 Paragraph const & par_;
113 ParagraphMetrics const & pm_;
116 /// is row erased? (change tracking)
121 int const yo_; // current baseline
130 RowPainter::RowPainter(PainterInfo & pi,
131 LyXText const & text, pit_type pit, Row const & row, int x, int y)
132 : bv_(*pi.base.bv), pain_(pi.pain), text_(text),
133 text_metrics_(pi.base.bv->textMetrics(&text)),
134 pars_(text.paragraphs()),
135 row_(row), pit_(pit), par_(text.paragraphs()[pit]),
136 pm_(text_metrics_.parMetrics(pit)),
137 max_width_(bv_.workWidth()),
139 xo_(x), yo_(y), width_(text_metrics_.width())
141 RowMetrics m = text_metrics_.computeRowMetrics(pit_, row_);
144 //lyxerr << "RowPainter: x: " << x_ << " xo: " << xo_ << " yo: " << yo_ << endl;
147 separator_ = m.separator;
149 label_hfill_ = m.label_hfill;
151 BOOST_ASSERT(pit >= 0);
152 BOOST_ASSERT(pit < int(text.paragraphs().size()));
156 LyXFont const RowPainter::getLabelFont() const
158 return text_.getLabelFont(*bv_.buffer(), par_);
162 int RowPainter::leftMargin() const
164 return text_.leftMargin(*bv_.buffer(), max_width_, pit_, row_.pos());
168 // If you want to debug inset metrics uncomment the following line:
169 // #define DEBUG_METRICS
170 // This draws green lines around each inset.
173 void RowPainter::paintInset(pos_type const pos, LyXFont const & font)
175 InsetBase const * inset = par_.getInset(pos);
177 PainterInfo pi(const_cast<BufferView *>(&bv_), pain_);
178 // FIXME: We should always use font, see documentation of
179 // noFontChange() in insetbase.h.
180 pi.base.font = inset->noFontChange() ?
181 bv_.buffer()->params().getFont() :
183 pi.ltr_pos = (text_.bidi.level(pos) % 2 == 0);
184 pi.erased_ = erased_ || par_.isDeleted(pos);
186 int const x1 = int(x_);
188 bv_.coordCache().insets().add(inset, int(x_), yo_);
189 InsetText const * const in = inset->asTextInset();
190 // non-wide insets are painted completely. Recursive
191 bool tmp = refreshInside;
192 if (!in || !in->wide()) {
193 refreshInside = true;
194 if (lyxerr.debugging(Debug::PAINTING)) {
195 lyxerr << endl << "Paint inset fully" << endl;
199 inset->drawSelection(pi, int(x_), yo_);
200 inset->draw(pi, int(x_), yo_);
202 x_ += inset->width();
205 BOOST_ASSERT(max_witdh_ > 0);
206 int right_margin = text_metrics_.rightMargin(pm_);
207 int const w = max_witdh_ - leftMargin() - right_margin;
208 MetricsInfo mi(&bv_, font, w);
209 inset->metrics(mi, dim);
210 if (inset->width() > dim.wid)
211 lyxerr << "Error: inset " << to_ascii(inset->getInsetName())
212 << " draw width " << inset->width()
213 << "> metrics width " << dim.wid << "." << std::endl;
214 if (inset->ascent() > dim.asc)
215 lyxerr << "Error: inset " << to_ascii(inset->getInsetName())
216 << " draw ascent " << inset->ascent()
217 << "> metrics ascent " << dim.asc << "." << std::endl;
218 if (inset->descent() > dim.des)
219 lyxerr << "Error: inset " << to_ascii(inset->getInsetName())
220 << " draw ascent " << inset->descent()
221 << "> metrics descent " << dim.des << "." << std::endl;
222 BOOST_ASSERT(inset->width() <= dim.wid);
223 BOOST_ASSERT(inset->ascent() <= dim.asc);
224 BOOST_ASSERT(inset->descent() <= dim.des);
225 int const x2 = x1 + dim.wid;
226 int const y1 = yo_ + dim.des;
227 int const y2 = yo_ - dim.asc;
228 pi.pain.line(x1, y1, x1, y2, LColor::green);
229 pi.pain.line(x1, y1, x2, y1, LColor::green);
230 pi.pain.line(x2, y1, x2, y2, LColor::green);
231 pi.pain.line(x1, y2, x2, y2, LColor::green);
236 void RowPainter::paintHebrewComposeChar(pos_type & vpos, LyXFont const & font)
238 pos_type pos = text_.bidi.vis2log(vpos);
243 char_type c = par_.getChar(pos);
247 int const width = theFontMetrics(font).width(c);
250 for (pos_type i = pos - 1; i >= 0; --i) {
252 if (!Encodings::isComposeChar_hebrew(c)) {
253 if (isPrintableNonspace(c)) {
254 int const width2 = text_.singleWidth(par_, i, c,
255 text_.getFont(*bv_.buffer(), par_, i));
256 dx = (c == 0x05e8 || // resh
257 c == 0x05d3) // dalet
259 : (width2 - width) / 2;
266 pain_.text(int(x_) + dx, yo_, str, font);
270 void RowPainter::paintArabicComposeChar(pos_type & vpos, LyXFont const & font)
272 pos_type pos = text_.bidi.vis2log(vpos);
276 char_type c = par_.getChar(pos);
277 c = par_.transformChar(c, pos);
281 int const width = theFontMetrics(font).width(c);
284 for (pos_type i = pos - 1; i >= 0; --i) {
286 if (!Encodings::isComposeChar_arabic(c)) {
287 if (isPrintableNonspace(c)) {
288 int const width2 = text_.singleWidth(par_, i, c,
289 text_.getFont(*bv_.buffer(), par_, i));
290 dx = (width2 - width) / 2;
296 pain_.text(int(x_) + dx, yo_, str, font);
300 void RowPainter::paintChars(pos_type & vpos, LyXFont const & font,
301 bool hebrew, bool arabic)
303 // This method takes up 70% of time when typing
304 pos_type pos = text_.bidi.vis2log(vpos);
305 pos_type const end = row_.endpos();
306 FontSpan const font_span = par_.fontSpan(pos);
307 Change::Type const prev_change = par_.lookupChange(pos).type;
310 std::vector<char_type> str;
312 str.push_back(par_.getChar(pos));
315 char_type c = str[0];
316 str[0] = par_.transformChar(c, pos);
319 // collect as much similar chars as we can
320 for (++vpos ; vpos < end ; ++vpos) {
321 pos = text_.bidi.vis2log(vpos);
322 if (pos < font_span.first || pos > font_span.last)
325 if (prev_change != par_.lookupChange(pos).type)
328 char_type c = par_.getChar(pos);
330 if (!isPrintableNonspace(c))
333 /* Because we do our own bidi, at this point the strings are
334 * already in visual order. However, Qt also applies its own
335 * bidi algorithm to strings that it paints to the screen.
336 * Therefore, if we were to paint Hebrew/Arabic words as a
337 * single string, the letters in the words would get reversed
338 * again. In order to avoid that, we don't collect Hebrew/
339 * Arabic characters, but rather paint them one at a time.
340 * See also http://thread.gmane.org/gmane.editors.lyx.devel/79740
345 /* FIXME: these checks are irrelevant, since 'arabic' and
346 * 'hebrew' alone are already going to trigger a break.
347 * However, this should not be removed completely, because
348 * if an alternative solution is found which allows grouping
349 * of arabic and hebrew characters, then these breaks may have
352 if (arabic && Encodings::isComposeChar_arabic(c))
355 if (hebrew && Encodings::isComposeChar_hebrew(c))
360 c = par_.transformChar(c, pos);
361 /* see comment in hebrew, explaining why we break */
368 docstring s(&str[0], str.size());
370 if (prev_change != Change::UNCHANGED) {
372 if (prev_change == Change::DELETED) {
373 copy.setColor(LColor::strikeout);
374 } else if (prev_change == Change::INSERTED) {
375 copy.setColor(LColor::newtext);
377 x_ += pain_.text(int(x_), yo_, s, copy);
379 x_ += pain_.text(int(x_), yo_, s, font);
384 void RowPainter::paintForeignMark(double orig_x, LyXFont const & font, int desc)
386 if (!lyxrc.mark_foreign_language)
388 if (font.language() == latex_language)
390 if (font.language() == bv_.buffer()->params().language)
393 int const y = yo_ + 1 + desc;
394 pain_.line(int(orig_x), y, int(x_), y, LColor::language);
398 void RowPainter::paintFromPos(pos_type & vpos)
400 pos_type const pos = text_.bidi.vis2log(vpos);
401 LyXFont orig_font = text_.getFont(*bv_.buffer(), par_, pos);
403 double const orig_x = x_;
405 if (par_.isInset(pos)) {
406 paintInset(pos, orig_font);
408 paintForeignMark(orig_x, orig_font,
409 par_.getInset(pos)->descent());
413 // usual characters, no insets
414 char_type const c = par_.getChar(pos);
416 // special case languages
417 std::string const & lang = orig_font.language()->lang();
418 bool const hebrew = lang == "hebrew";
419 bool const arabic = lang == "arabic" &&
420 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
421 lyxrc.font_norm_type == LyXRC::ISO_10646_1);
423 // draw as many chars as we can
424 if ((!hebrew && !arabic)
425 || (hebrew && !Encodings::isComposeChar_hebrew(c))
426 || (arabic && !Encodings::isComposeChar_arabic(c))) {
427 paintChars(vpos, orig_font, hebrew, arabic);
429 paintHebrewComposeChar(vpos, orig_font);
431 paintArabicComposeChar(vpos, orig_font);
434 paintForeignMark(orig_x, orig_font);
438 void RowPainter::paintChangeBar()
440 pos_type const start = row_.pos();
441 pos_type end = row_.endpos();
443 if (par_.size() == end) {
444 // this is the last row of the paragraph;
445 // thus, we must also consider the imaginary end-of-par character
449 if (start == end || !par_.isChanged(start, end))
452 int const height = text_.isLastRow(pit_, row_)
456 pain_.fillRectangle(5, yo_ - row_.ascent(), 3, height, LColor::changebar);
460 void RowPainter::paintAppendix()
462 if (!par_.params().appendix())
465 int y = yo_ - row_.ascent();
467 if (par_.params().startOfAppendix())
468 y += 2 * defaultRowHeight();
470 pain_.line(1, y, 1, yo_ + row_.height(), LColor::appendix);
471 pain_.line(width_ - 2, y, width_ - 2, yo_ + row_.height(), LColor::appendix);
475 void RowPainter::paintDepthBar()
477 depth_type const depth = par_.getDepth();
482 depth_type prev_depth = 0;
483 if (!text_.isFirstRow(pit_, row_)) {
484 pit_type pit2 = pit_;
487 prev_depth = pars_[pit2].getDepth();
490 depth_type next_depth = 0;
491 if (!text_.isLastRow(pit_, row_)) {
492 pit_type pit2 = pit_;
493 if (row_.endpos() >= pars_[pit2].size())
495 next_depth = pars_[pit2].getDepth();
498 for (depth_type i = 1; i <= depth; ++i) {
499 int const w = nestMargin() / 5;
500 int x = int(xo_) + w * i;
501 // only consider the changebar space if we're drawing outermost text
502 if (text_.isMainText(*bv_.buffer()))
503 x += changebarMargin();
505 int const starty = yo_ - row_.ascent();
506 int const h = row_.height() - 1 - (i - next_depth - 1) * 3;
508 pain_.line(x, starty, x, starty + h, LColor::depthbar);
511 pain_.fillRectangle(x, starty, w, 2, LColor::depthbar);
513 pain_.fillRectangle(x, starty + h, w, 2, LColor::depthbar);
518 int RowPainter::paintAppendixStart(int y)
521 pb_font.setColor(LColor::appendix);
528 docstring const label = _("Appendix");
529 theFontMetrics(pb_font).rectText(label, w, a, d);
531 int const text_start = int(xo_ + (width_ - w) / 2);
532 int const text_end = text_start + w;
534 pain_.rectText(text_start, y + d, label, pb_font, LColor::none, LColor::none);
536 pain_.line(int(xo_ + 1), y, text_start, y, LColor::appendix);
537 pain_.line(text_end, y, int(xo_ + width_ - 2), y, LColor::appendix);
539 return 3 * defaultRowHeight();
543 void RowPainter::paintFirst()
545 ParagraphParameters const & parparams = par_.params();
549 // start of appendix?
550 if (parparams.startOfAppendix())
551 y_top += paintAppendixStart(yo_ - row_.ascent() + 2 * defaultRowHeight());
553 Buffer const & buffer = *bv_.buffer();
555 LyXLayout_ptr const & layout = par_.layout();
557 if (buffer.params().paragraph_separation == BufferParams::PARSEP_SKIP) {
559 if (layout->latextype == LATEX_PARAGRAPH
560 && !par_.getDepth()) {
561 y_top += buffer.params().getDefSkip().inPixels(bv_);
563 LyXLayout_ptr const & playout = pars_[pit_ - 1].layout();
564 if (playout->latextype == LATEX_PARAGRAPH
565 && !pars_[pit_ - 1].getDepth()) {
566 // is it right to use defskip here, too? (AS)
567 y_top += buffer.params().getDefSkip().inPixels(bv_);
573 bool const is_rtl = text_.isRTL(buffer, par_);
574 bool const is_seq = isFirstInSequence(pit_, text_.paragraphs());
575 //lyxerr << "paintFirst: " << par_.id() << " is_seq: " << is_seq << std::endl;
577 // should we print a label?
578 if (layout->labeltype >= LABEL_STATIC
579 && (layout->labeltype != LABEL_STATIC
580 || layout->latextype != LATEX_ENVIRONMENT
583 LyXFont const font = getLabelFont();
584 FontMetrics const & fm = theFontMetrics(font);
586 docstring const str = par_.getLabelstring();
590 // this is special code for the chapter layout. This is
591 // printed in an extra row and has a pagebreak at
593 if (layout->counter == "chapter") {
594 double spacing_val = 1.0;
595 if (!parparams.spacing().isDefault()) {
596 spacing_val = parparams.spacing().getValue();
598 spacing_val = buffer.params().spacing().getValue();
601 int const labeladdon = int(fm.maxHeight() * layout->spacing.getValue() * spacing_val);
603 int const maxdesc = int(fm.maxDescent() * layout->spacing.getValue() * spacing_val)
604 + int(layout->parsep) * defaultRowHeight();
607 x = width_ - leftMargin() -
611 pain_.text(int(x), yo_ - maxdesc - labeladdon, str, font);
614 docstring lab = from_utf8(layout->labelsep);
616 x = width_ - leftMargin()
619 x = x_ - fm.width(lab)
623 pain_.text(int(x), yo_, str, font);
627 // the labels at the top of an environment.
628 // More or less for bibliography
630 (layout->labeltype == LABEL_TOP_ENVIRONMENT ||
631 layout->labeltype == LABEL_BIBLIO ||
632 layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) {
633 LyXFont font = getLabelFont();
634 if (!par_.getLabelstring().empty()) {
635 docstring const str = par_.getLabelstring();
636 double spacing_val = 1.0;
637 if (!parparams.spacing().isDefault())
638 spacing_val = parparams.spacing().getValue();
640 spacing_val = buffer.params().spacing().getValue();
642 FontMetrics const & fm = theFontMetrics(font);
644 int const labeladdon = int(fm.maxHeight()
645 * layout->spacing.getValue() * spacing_val);
648 int(fm.maxDescent() * layout->spacing.getValue() * spacing_val
649 + (layout->labelbottomsep * defaultRowHeight()));
652 if (layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
655 x += (width_ - text_metrics_.rightMargin(pm_) - leftMargin()) / 2;
656 x -= fm.width(str) / 2;
658 x = width_ - leftMargin() - fm.width(str);
660 pain_.text(int(x), yo_ - maxdesc - labeladdon, str, font);
666 void RowPainter::paintLast()
668 bool const is_rtl = text_.isRTL(*bv_.buffer(), par_);
669 int const endlabel = getEndLabel(pit_, text_.paragraphs());
671 // paint imaginary end-of-paragraph character
673 if (par_.isInserted(par_.size()) || par_.isDeleted(par_.size())) {
674 FontMetrics const & fm = theFontMetrics(bv_.buffer()->params().getFont());
675 int const length = fm.maxAscent() / 2;
676 LColor::color col = par_.isInserted(par_.size()) ? LColor::newtext : LColor::strikeout;
678 pain_.line(int(x_) + 1, yo_ + 2, int(x_) + 1, yo_ + 2 - length, col,
679 Painter::line_solid, Painter::line_thick);
680 pain_.line(int(x_) + 1 - length, yo_ + 2, int(x_) + 1, yo_ + 2, col,
681 Painter::line_solid, Painter::line_thick);
688 case END_LABEL_FILLED_BOX: {
689 LyXFont const font = getLabelFont();
690 FontMetrics const & fm = theFontMetrics(font);
691 int const size = int(0.75 * fm.maxAscent());
692 int const y = yo_ - size;
693 int x = is_rtl ? nestMargin() + changebarMargin() : width_ - size;
695 if (width_ - int(row_.width()) <= size)
696 x += (size - width_ + row_.width() + 1) * (is_rtl ? -1 : 1);
698 if (endlabel == END_LABEL_BOX)
699 pain_.rectangle(x, y, size, size, LColor::eolmarker);
701 pain_.fillRectangle(x, y, size, size, LColor::eolmarker);
705 case END_LABEL_STATIC: {
706 LyXFont font = getLabelFont();
707 FontMetrics const & fm = theFontMetrics(font);
708 docstring const & str = par_.layout()->endlabelstring();
709 double const x = is_rtl ?
711 : - text_metrics_.rightMargin(pm_) - row_.width();
712 pain_.text(int(x), yo_, str, font);
716 case END_LABEL_NO_LABEL:
722 void RowPainter::paintText()
724 pos_type const end = row_.endpos();
725 pos_type body_pos = par_.beginOfBody();
727 (body_pos > end || !par_.isLineSeparator(body_pos - 1))) {
731 LyXLayout_ptr const & layout = par_.layout();
733 bool running_strikeout = false;
734 bool is_struckout = false;
735 int last_strikeout_x = 0;
737 // Use font span to speed things up, see below
740 Buffer const & buffer = *bv_.buffer();
742 for (pos_type vpos = row_.pos(); vpos < end; ) {
743 if (x_ > bv_.workWidth())
746 pos_type const pos = text_.bidi.vis2log(vpos);
748 if (pos >= par_.size()) {
753 // Use font span to speed things up, see above
754 if (vpos < font_span.first || vpos > font_span.last) {
755 font_span = par_.fontSpan(vpos);
756 font = text_.getFont(buffer, par_, vpos);
759 const int width_pos =
760 text_.singleWidth(par_, pos, par_.getChar(pos), font);
762 if (x_ + width_pos < 0) {
768 is_struckout = par_.isDeleted(pos);
770 if (is_struckout && !running_strikeout) {
771 running_strikeout = true;
772 last_strikeout_x = int(x_);
775 bool const highly_editable_inset = par_.isInset(pos)
776 && isHighlyEditableInset(par_.getInset(pos));
778 // If we reach the end of a struck out range, paint it.
779 // We also don't paint across things like tables
780 if (running_strikeout && (highly_editable_inset || !is_struckout)) {
781 // Calculate 1/3 height of the buffer's default font
782 FontMetrics const & fm
783 = theFontMetrics(bv_.buffer()->params().getFont());
784 int const middle = yo_ - fm.maxAscent() / 3;
785 pain_.line(last_strikeout_x, middle, int(x_), middle,
786 LColor::strikeout, Painter::line_solid, Painter::line_thin);
787 running_strikeout = false;
790 if (body_pos > 0 && pos == body_pos - 1) {
792 int const lwidth = theFontMetrics(getLabelFont())
793 .width(from_utf8(layout->labelsep));
795 x_ += label_hfill_ + lwidth - width_pos;
798 if (par_.isHfill(pos)) {
802 int const y1 = y0 - defaultRowHeight() / 2;
804 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
806 if (par_.hfillExpansion(row_, pos)) {
807 int const y2 = (y0 + y1) / 2;
809 if (pos >= body_pos) {
810 pain_.line(int(x_), y2, int(x_ + hfill_), y2,
812 Painter::line_onoffdash);
815 pain_.line(int(x_), y2, int(x_ + label_hfill_), y2,
817 Painter::line_onoffdash);
820 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
824 } else if (par_.isSeparator(pos)) {
834 // if we reach the end of a struck out range, paint it
835 if (running_strikeout) {
836 // calculate 1/3 height of the buffer's default font
837 FontMetrics const & fm
838 = theFontMetrics(bv_.buffer()->params().getFont());
839 int const middle = yo_ - fm.maxAscent() / 3;
840 pain_.line(last_strikeout_x, middle, int(x_), middle,
841 LColor::strikeout, Painter::line_solid, Painter::line_thin);
842 running_strikeout = false;
847 bool CursorOnRow(PainterInfo & pi, pit_type const pit,
848 RowList::const_iterator rit, LyXText const & text)
850 // Is there a cursor on this row (or inside inset on row)
851 LCursor & cur = pi.base.bv->cursor();
852 for (size_type d = 0; d < cur.depth(); ++d) {
853 CursorSlice const & sl = cur[d];
854 if (sl.text() == &text
856 && sl.pos() >= rit->pos()
857 && sl.pos() <= rit->endpos())
864 bool innerCursorOnRow(PainterInfo & pi, pit_type pit,
865 RowList::const_iterator rit, LyXText const & text)
867 // Is there a cursor inside an inset on this row, and is this inset
868 // the only "character" on this row
869 LCursor & cur = pi.base.bv->cursor();
870 if (rit->pos() + 1 != rit->endpos())
872 for (size_type d = 0; d < cur.depth(); d++) {
873 CursorSlice const & sl = cur[d];
874 if (sl.text() == &text
876 && sl.pos() == rit->pos())
877 return d < cur.depth() - 1;
884 (PainterInfo & pi, LyXText const & text, pit_type pit, int x, int y,
887 // lyxerr << " paintPar: pit: " << pit << " at y: " << y << endl;
888 int const ww = pi.base.bv->workHeight();
890 pi.base.bv->coordCache().parPos()[&text][pit] = Point(x, y);
892 Paragraph const & par = text.paragraphs()[pit];
893 ParagraphMetrics const & pm = pi.base.bv->parMetrics(&text, pit);
894 if (pm.rows().empty())
897 RowList::const_iterator const rb = pm.rows().begin();
898 RowList::const_iterator const re = pm.rows().end();
902 for (RowList::const_iterator rit = rb; rit != re; ++rit, ++rowno) {
904 // Allow setting of refreshInside for nested insets in
906 bool tmp = refreshInside;
908 // Row signature; has row changed since last paint?
909 bool row_has_changed = pm.rowChangeStatus()[rowno];
911 bool cursor_on_row = CursorOnRow(pi, pit, rit, text);
912 bool in_inset_alone_on_row = innerCursorOnRow(pi, pit, rit,
915 (par.getAlign() == LYX_ALIGN_LEFT ||
916 par.getAlign() == LYX_ALIGN_BLOCK);
918 // If this is the only object on the row, we can make it wide
920 // FIXME: there is a const_cast here because paintPar() is not supposed
921 // to touch the paragraph contents. So either we move this "wide"
922 // property out of InsetText or we localize the feature to the painting
924 for (pos_type i = rit->pos() ; i != rit->endpos(); ++i) {
925 InsetBase const * const in = par.getInset(i);
927 InsetText * t = const_cast<InsetText *>(in->asTextInset());
929 t->setWide(in_inset_alone_on_row && leftEdgeFixed);
933 // If selection is on, the current row signature differs
934 // from cache, or cursor is inside an inset _on this row_,
935 // then paint the row
936 if (repaintAll || row_has_changed || cursor_on_row) {
937 bool const inside = (y + rit->descent() >= 0
938 && y - rit->ascent() < ww);
939 // it is not needed to draw on screen if we are not inside.
940 pi.pain.setDrawingEnabled(inside);
941 RowPainter rp(pi, text, pit, *rit, x, y);
942 // Clear background of this row
943 // (if paragraph background was not cleared)
945 (!(in_inset_alone_on_row && leftEdgeFixed)
946 || row_has_changed)) {
947 pi.pain.fillRectangle(x, y - rit->ascent(),
948 rp.maxWidth(), rit->height(),
949 text.backgroundColor());
950 // If outer row has changed, force nested
951 // insets to repaint completely
953 refreshInside = true;
956 // Instrumentation for testing row cache (see also
958 if (lyxerr.debugging(Debug::PAINTING)) {
959 if (text.isMainText(*pi.base.bv->buffer()))
960 lyxerr[Debug::PAINTING] << "#";
962 lyxerr[Debug::PAINTING] << "[" <<
963 repaintAll << row_has_changed <<
964 cursor_on_row << "]";
976 // Restore, see above
979 // Re-enable screen drawing for future use of the painter.
980 pi.pain.setDrawingEnabled(true);
982 if (lyxerr.debugging(Debug::PAINTING)) {
983 lyxerr[Debug::PAINTING] << "." << endl;
990 void paintText(BufferView & bv,
993 BOOST_ASSERT(bv.buffer());
994 Buffer const & buffer = *bv.buffer();
995 LyXText & text = buffer.text();
996 bool const select = bv.cursor().selection();
997 ViewMetricsInfo const & vi = bv.viewMetricsInfo();
999 PainterInfo pi(const_cast<BufferView *>(&bv), pain);
1000 // Should the whole screen, including insets, be refreshed?
1001 // FIXME: We should also distinguish DecorationUpdate to avoid text
1002 // drawing if possible. This is not possible to do easily right now
1003 // because of the single backing pixmap.
1004 bool repaintAll = select || vi.update_strategy != SingleParUpdate;
1007 // Clear background (if not delegated to rows)
1008 pain.fillRectangle(0, vi.y1, bv.workWidth(), vi.y2 - vi.y1,
1009 text.backgroundColor());
1012 text.drawSelection(pi, 0, 0);
1017 for (pit_type pit = vi.p1; pit <= vi.p2; ++pit) {
1018 refreshInside = repaintAll;
1019 ParagraphMetrics const & pm = bv.parMetrics(&text, pit);
1021 paintPar(pi, text, pit, 0, yy, repaintAll);
1025 // and grey out above (should not happen later)
1026 // lyxerr << "par ascent: " << text.getPar(vi.p1).ascent() << endl;
1027 if (vi.y1 > 0 && vi.update_strategy != SingleParUpdate)
1028 pain.fillRectangle(0, 0, bv.workWidth(), vi.y1, LColor::bottomarea);
1030 // and possibly grey out below
1031 // lyxerr << "par descent: " << text.getPar(vi.p1).ascent() << endl;
1032 if (vi.y2 < bv.workHeight() && vi.update_strategy != SingleParUpdate)
1033 pain.fillRectangle(0, vi.y2, bv.workWidth(), bv.workHeight() - vi.y2, LColor::bottomarea);
1037 void paintTextInset(LyXText const & text, PainterInfo & pi, int x, int y)
1039 // lyxerr << " paintTextInset: y: " << y << endl;
1041 y -= pi.base.bv->parMetrics(&text, 0).ascent();
1042 // This flag cannot be set from within same inset:
1043 bool repaintAll = refreshInside;
1044 for (int pit = 0; pit < int(text.paragraphs().size()); ++pit) {
1045 ParagraphMetrics const & pmi
1046 = pi.base.bv->parMetrics(&text, pit);
1048 paintPar(pi, text, pit, x, y, repaintAll);