-
-void paintPar
- (PainterInfo & pi, Text const & text, pit_type pit, int x, int y,
- bool repaintAll)
-{
-// lyxerr << " paintPar: pit: " << pit << " at y: " << y << endl;
- int const ww = pi.base.bv->workHeight();
-
- pi.base.bv->coordCache().parPos()[&text][pit] = Point(x, y);
-
- Paragraph const & par = text.paragraphs()[pit];
- ParagraphMetrics const & pm = pi.base.bv->parMetrics(&text, pit);
- if (pm.rows().empty())
- return;
-
- RowList::const_iterator const rb = pm.rows().begin();
- RowList::const_iterator const re = pm.rows().end();
-
- Bidi bidi;
-
- y -= rb->ascent();
- size_type rowno = 0;
- for (RowList::const_iterator rit = rb; rit != re; ++rit, ++rowno) {
- y += rit->ascent();
- // Allow setting of refreshInside for nested insets in
- // this row only
- bool tmp = refreshInside;
-
- // Row signature; has row changed since last paint?
- bool row_has_changed = pm.rowChangeStatus()[rowno];
-
- bool cursor_on_row = CursorOnRow(pi, pit, rit, text);
- bool in_inset_alone_on_row =
- innerCursorOnRow(pi, pit, rit, text);
- bool leftEdgeFixed =
- (par.getAlign() == LYX_ALIGN_LEFT ||
- par.getAlign() == LYX_ALIGN_BLOCK);
- bool inNarrowIns = inNarrowInset(pi);
-
- // If this is the only object on the row, we can make it wide
- //
- // FIXME: there is a const_cast here because paintPar() is not supposed
- // to touch the paragraph contents. So either we move this "wide"
- // property out of InsetText or we localize the feature to the painting
- // done here.
- // JSpitzm: We should aim at removing wide() altogether while retaining
- // typing speed within insets.
- for (pos_type i = rit->pos() ; i != rit->endpos(); ++i) {
- Inset const * const in = par.getInset(i);
- if (in) {
- InsetText * t = const_cast<InsetText *>(in->asTextInset());
- if (t)
- t->setWide(in_inset_alone_on_row
- && leftEdgeFixed
- && !inNarrowIns);
- }
- }
-
- // If selection is on, the current row signature differs
- // from cache, or cursor is inside an inset _on this row_,
- // then paint the row
- if (repaintAll || row_has_changed || cursor_on_row) {
- bool const inside = (y + rit->descent() >= 0
- && y - rit->ascent() < ww);
- // it is not needed to draw on screen if we are not inside.
- pi.pain.setDrawingEnabled(inside);
- RowPainter rp(pi, text, pit, *rit, bidi, x, y);
- // Clear background of this row
- // (if paragraph background was not cleared)
- if (!repaintAll &&
- (!(in_inset_alone_on_row && leftEdgeFixed)
- || row_has_changed)) {
- pi.pain.fillRectangle(x, y - rit->ascent(),
- rp.maxWidth(), rit->height(),
- text.backgroundColor());
- // If outer row has changed, force nested
- // insets to repaint completely
- if (row_has_changed)
- refreshInside = true;
- }
-
- // Instrumentation for testing row cache (see also
- // 12 lines lower):
- if (lyxerr.debugging(Debug::PAINTING)) {
- if (text.isMainText(*pi.base.bv->buffer()))
- LYXERR(Debug::PAINTING) << "#";
- else
- LYXERR(Debug::PAINTING) << "[" <<
- repaintAll << row_has_changed <<
- cursor_on_row << "]";
- }
- rp.paintAppendix();
- rp.paintDepthBar();
- rp.paintChangeBar();
- if (rit == rb)
- rp.paintFirst();
- rp.paintText();
- if (rit + 1 == re)
- rp.paintLast();
- }
- y += rit->descent();
- // Restore, see above
- refreshInside = tmp;
- }
- // Re-enable screen drawing for future use of the painter.
- pi.pain.setDrawingEnabled(true);
-
- LYXERR(Debug::PAINTING) << "." << endl;
-}
-
-} // namespace anon
-
-
-void paintText(BufferView & bv,
- Painter & pain)
-{
- BOOST_ASSERT(bv.buffer());
- Buffer const & buffer = *bv.buffer();
- Text & text = buffer.text();
- bool const select = bv.cursor().selection();
- ViewMetricsInfo const & vi = bv.viewMetricsInfo();
-
- PainterInfo pi(const_cast<BufferView *>(&bv), pain);
- // Should the whole screen, including insets, be refreshed?
- // FIXME: We should also distinguish DecorationUpdate to avoid text
- // drawing if possible. This is not possible to do easily right now
- // because of the single backing pixmap.
- bool repaintAll = select || vi.update_strategy != SingleParUpdate;
-
- if (repaintAll) {
- // Clear background (if not delegated to rows)
- pain.fillRectangle(0, vi.y1, bv.workWidth(), vi.y2 - vi.y1,
- text.backgroundColor());
- }
- if (select) {
- text.drawSelection(pi, 0, 0);
- }
-
- int yy = vi.y1;
- // draw contents
- for (pit_type pit = vi.p1; pit <= vi.p2; ++pit) {
- refreshInside = repaintAll;
- ParagraphMetrics const & pm = bv.parMetrics(&text, pit);
- yy += pm.ascent();
- paintPar(pi, text, pit, 0, yy, repaintAll);
- yy += pm.descent();
- }
-
- // and grey out above (should not happen later)
-// lyxerr << "par ascent: " << text.getPar(vi.p1).ascent() << endl;
- if (vi.y1 > 0 && vi.update_strategy == FullScreenUpdate)
- pain.fillRectangle(0, 0, bv.workWidth(), vi.y1, Color::bottomarea);
-
- // and possibly grey out below
-// lyxerr << "par descent: " << text.getPar(vi.p1).ascent() << endl;
- if (vi.y2 < bv.workHeight() && vi.update_strategy == FullScreenUpdate)
- pain.fillRectangle(0, vi.y2, bv.workWidth(), bv.workHeight() - vi.y2, Color::bottomarea);
-}
-
-
-void paintTextInset(Text const & text, PainterInfo & pi, int x, int y)
-{
-// lyxerr << " paintTextInset: y: " << y << endl;
-
- y -= pi.base.bv->parMetrics(&text, 0).ascent();
- // This flag cannot be set from within same inset:
- bool repaintAll = refreshInside;
- for (int pit = 0; pit < int(text.paragraphs().size()); ++pit) {
- ParagraphMetrics const & pmi
- = pi.base.bv->parMetrics(&text, pit);
- y += pmi.ascent();
- paintPar(pi, text, pit, x, y, repaintAll);
- y += pmi.descent();
- }
-}
-
-