-bool CursorOnRow(PainterInfo & pi, pit_type const pit,
- RowList::const_iterator rit, Text const & text)
-{
- // Is there a cursor on this row (or inside inset on row)
- Cursor & cur = pi.base.bv->cursor();
- for (size_type d = 0; d < cur.depth(); ++d) {
- CursorSlice const & sl = cur[d];
- if (sl.text() == &text
- && sl.pit() == pit
- && sl.pos() >= rit->pos()
- && sl.pos() <= rit->endpos())
- return true;
- }
- return false;
-}
-
-
-bool innerCursorOnRow(PainterInfo & pi, pit_type pit,
- RowList::const_iterator rit, Text const & text)
-{
- // Is there a cursor inside an inset on this row, and is this inset
- // the only "character" on this row
- Cursor & cur = pi.base.bv->cursor();
- if (rit->pos() + 1 != rit->endpos())
- return false;
- for (size_type d = 0; d < cur.depth(); d++) {
- CursorSlice const & sl = cur[d];
- if (sl.text() == &text
- && sl.pit() == pit
- && sl.pos() == rit->pos())
- return d < cur.depth() - 1;
- }
- return false;
-}
-
-
-// FIXME: once wide() is obsolete, remove this as well!
-bool inNarrowInset(PainterInfo & pi)
-{
- // check whether the current inset is nested in a non-wide inset
- Cursor & cur = pi.base.bv->cursor();
- for (int i = cur.depth() - 1; --i >= 0; ) {
- Inset * const in = &cur[i].inset();
- if (in) {
- InsetText * t =
- const_cast<InsetText *>(in->asTextInset());
- if (t)
- return !t->wide();
- }
- }
- return false;
-}
-
-
-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)