]> git.lyx.org Git - lyx.git/blobdiff - src/rowpainter.C
fix some C++ parsing bugs
[lyx.git] / src / rowpainter.C
index 0886fc00c99ee42e4f0a8beb48bf28199b876714..faf9eb1d1657879f1da35bac4b7b21dea91b9d09 100644 (file)
@@ -69,17 +69,15 @@ LyXFont const RowPainter::getFont(pos_type pos) const
 
 int RowPainter::singleWidth(lyx::pos_type pos) const
 {
-       BufferView * bv(perv(bv_));
        Paragraph * par(const_cast<Paragraph*>(&par_));
-       return text_.singleWidth(bv, par, pos);
+       return text_.singleWidth(par, pos);
 }
 
 
 int RowPainter::singleWidth(lyx::pos_type pos, char c) const
 {
-       BufferView * bv(perv(bv_));
        Paragraph * par(const_cast<Paragraph*>(&par_));
-       return text_.singleWidth(bv, par, pos, c);
+       return text_.singleWidth(par, pos, c);
 }
 
 
@@ -99,60 +97,12 @@ char const RowPainter::transformChar(char c, lyx::pos_type pos) const
 
 int RowPainter::leftMargin() const
 {
-       BufferView * bv(perv(bv_));
        Row * row(const_cast<Row *>(&row_));
-       return text_.leftMargin(bv, row);
+       return text_.leftMargin(row);
 }
 
 
-void RowPainter::paintNewline(pos_type const pos)
-{
-       LyXFont const font = getFont(pos);
-       int const wid = font_metrics::width('n', font);
-       int const asc = font_metrics::maxAscent(font);
-       int const y = yo_ + row_.baseline();
-       // FIXME: rtl_pos, or ltr_pos ?
-       bool const rtl_pos = (text_.bidi_level(pos) % 2 == 0);
-       int xp[3];
-       int yp[3];
-
-       yp[0] = int(y - 0.875 * asc * 0.75);
-       yp[1] = int(y - 0.500 * asc * 0.75);
-       yp[2] = int(y - 0.125 * asc * 0.75);
-
-       if (rtl_pos) {
-               xp[0] = int(x_ + wid * 0.375);
-               xp[1] = int(x_);
-               xp[2] = int(x_ + wid * 0.375);
-       } else {
-               xp[0] = int(x_ + wid * 0.625);
-               xp[1] = int(x_ + wid);
-               xp[2] = int(x_ + wid * 0.625);
-       }
-
-       pain_.lines(xp, yp, 3, LColor::eolmarker);
-
-       yp[0] = int(y - 0.500 * asc * 0.75);
-       yp[1] = int(y - 0.500 * asc * 0.75);
-       yp[2] = int(y - asc * 0.75);
-
-       if (rtl_pos) {
-               xp[0] = int(x_);
-               xp[1] = int(x_ + wid);
-               xp[2] = int(x_ + wid);
-       } else {
-               xp[0] = int(x_ + wid);
-               xp[1] = int(x_);
-               xp[2] = int(x_);
-       }
-
-       pain_.lines(xp, yp, 3, LColor::eolmarker);
-
-       x_ += wid;
-}
-
-
-bool RowPainter::paintInset(pos_type const pos)
+void RowPainter::paintInset(pos_type const pos)
 {
        Inset * inset = const_cast<Inset*>(par_.getInset(pos));
 
@@ -160,13 +110,10 @@ bool RowPainter::paintInset(pos_type const pos)
 
        LyXFont const & font = getFont(pos);
 
-       inset->update(perv(bv_), font, false);
-       inset->draw(perv(bv_), font, yo_ + row_.baseline(), x_, cleared_);
+#warning inset->update FIXME
+       inset->update(perv(bv_), false);
 
-       // return true if something changed when we drew an inset
-
-       return (!text_.need_break_row && !text_.isInInset()
-           && bv_.text->status() == LyXText::CHANGED_IN_DRAW);
+       inset->draw(perv(bv_), font, yo_ + row_.baseline(), x_);
 }
 
 
@@ -308,7 +255,7 @@ void RowPainter::paintForeignMark(float const orig_x, LyXFont const & orig_font)
 }
 
 
-bool RowPainter::paintFromPos(pos_type & vpos)
+void RowPainter::paintFromPos(pos_type & vpos)
 {
        pos_type const pos = text_.vis2log(vpos);
 
@@ -318,16 +265,11 @@ bool RowPainter::paintFromPos(pos_type & vpos)
 
        char const c = par_.getChar(pos);
 
-       if (IsNewlineChar(c)) {
-               ++vpos;
-               paintNewline(pos);
-               return true;
-       } else if (IsInsetChar(c)) {
-               if (paintInset(pos))
-                       return true;
+       if (IsInsetChar(c)) {
+               paintInset(pos);
                ++vpos;
                paintForeignMark(orig_x, orig_font);
-               return false;
+               return;
        }
 
        // usual characters, no insets
@@ -352,66 +294,16 @@ bool RowPainter::paintFromPos(pos_type & vpos)
 
        paintForeignMark(orig_x, orig_font);
 
-       return false;
+       return;
 }
 
 
-bool RowPainter::paintBackground()
+void RowPainter::paintBackground()
 {
-       pos_type const last = row_.lastPrintablePos();
-       bool clear_area = true;
-       Inset const * inset = 0;
-
-       if (!bv_.screen().forceClear() && last == row_.pos()
-               && par_.isInset(row_.pos())) {
-               inset = par_.getInset(row_.pos());
-               clear_area = inset->doClearArea();
-       }
-
-       if (cleared_) {
-               return true;
-       }
-
-       if (clear_area) {
-               int const x = xo_;
-               int const y = yo_ < 0 ? 0 : yo_;
-               int const h = yo_ < 0 ? row_.height() + yo_ : row_.height();
-               pain_.fillRectangle(x, y, width_, h, text_.backgroundColor());
-               return true;
-       }
-
-       if (!inset)
-               return false;
-
-       LyXFont font(LyXFont::ALL_SANE);
-
-       // FIXME
-       BufferView * bv = perv(bv_);
-
-       int h = row_.baseline() - inset->ascent(bv, font);
-
-       // first clear the whole row above the inset!
-       if (h > 0) {
-               pain_.fillRectangle(xo_, yo_, width_, h, text_.backgroundColor());
-       }
-
-       // clear the space below the inset!
-       h += inset->ascent(bv, font) + inset->descent(bv, font);
-       if ((row_.height() - h) > 0) {
-               pain_.fillRectangle(xo_, yo_ + h,
-                       width_, row_.height() - h, text_.backgroundColor());
-       }
-
-       // clear the space behind the inset, if needed
-       if (!inset->display() && !inset->needFullRow()) {
-               int const xp = int(x_) + inset->width(bv, font);
-               if (width_ - xp > 0) {
-                       pain_.fillRectangle(xp, yo_, width_ - xp,
-                               row_.height(), text_.backgroundColor());
-               }
-       }
-
-       return false;
+       int const x = xo_;
+       int const y = yo_ < 0 ? 0 : yo_;
+       int const h = yo_ < 0 ? row_.height() + yo_ : row_.height();
+       pain_.fillRectangle(x, y, width_, h, text_.backgroundColor());
 }
 
 
@@ -538,13 +430,19 @@ void RowPainter::paintChangeBar()
 
 void RowPainter::paintAppendix()
 {
+       if (!par_.params().appendix())
+               return;
+
        // FIXME: can be just width_ ?
        int const ww = bv_.workWidth();
 
-       if (par_.params().appendix()) {
-               pain_.line(1, yo_, 1, yo_ + row_.height(), LColor::appendixline);
-               pain_.line(ww - 2, yo_, ww - 2, yo_ + row_.height(), LColor::appendixline);
-       }
+       int y = yo_;
+
+       if (par_.params().startOfAppendix())
+               y += 2 * defaultRowHeight();
+
+       pain_.line(1, y, 1, yo_ + row_.height(), LColor::appendix);
+       pain_.line(ww - 2, y, ww - 2, yo_ + row_.height(), LColor::appendix);
 }
 
 
@@ -691,19 +589,42 @@ int RowPainter::paintPageBreak(string const & label, int y)
 }
 
 
+int RowPainter::paintAppendixStart(int y)
+{
+       LyXFont pb_font;
+       pb_font.setColor(LColor::appendix).decSize();
+
+       string const label = _("Appendix");
+       int w = 0;
+       int a = 0;
+       int d = 0;
+       font_metrics::rectText(label, pb_font, w, a, d);
+
+       int const text_start = xo_ + ((width_ - w) / 2);
+       int const text_end = text_start + w;
+
+       pain_.rectText(text_start, y + d, label, pb_font);
+
+       pain_.line(xo_ + 1, y, text_start, y, LColor::appendix);
+       pain_.line(text_end, y, xo_ + width_ - 2, y, LColor::appendix);
+
+       return 3 * defaultRowHeight();
+}
+
+
 void RowPainter::paintFirst()
 {
        ParagraphParameters const & parparams = par_.params();
 
+       int y_top = 0;
+
        // start of appendix?
        if (parparams.startOfAppendix()) {
-               pain_.line(1, yo_, width_ - 2, yo_, LColor::appendixline);
+               y_top += paintAppendixStart(yo_ + y_top + 2 * defaultRowHeight());
        }
 
-       int y_top = 0;
-
        // the top margin
-       if (!row_.previous() && text_.isTopLevel())
+       if (!row_.previous() && !text_.isInInset())
                y_top += PAPER_MARGIN;
 
        // draw a top pagebreak
@@ -850,7 +771,7 @@ void RowPainter::paintLast()
        int y_bottom = row_.height() - 1;
 
        // the bottom margin
-       if (!row_.next() && text_.isTopLevel())
+       if (!row_.next() && !text_.isInInset())
                y_bottom -= PAPER_MARGIN;
 
        int const ww = bv_.workWidth();
@@ -927,7 +848,7 @@ void RowPainter::paintLast()
 }
 
 
-bool RowPainter::paintText()
+void RowPainter::paintText()
 {
        pos_type const last = row_.lastPrintablePos();
        pos_type body_pos = par_.beginningOfBody();
@@ -949,6 +870,11 @@ bool RowPainter::paintText()
                        break;
                pos_type pos = text_.vis2log(vpos);
 
+               if (pos >= par_.size()) {
+                       ++vpos;
+                       continue;
+               }
+
                if (x_ + singleWidth(pos) < 0) {
                        x_ += singleWidth(pos);
                        ++vpos;
@@ -1020,8 +946,7 @@ bool RowPainter::paintText()
                                x_ += separator_;
                        ++vpos;
                } else {
-                       if (paintFromPos(vpos))
-                               return true;
+                       paintFromPos(vpos);
                }
        }
 
@@ -1033,32 +958,32 @@ bool RowPainter::paintText()
                        LColor::strikeout, Painter::line_solid, Painter::line_thin);
                running_strikeout = false;
        }
-       return false;
+       return;
 }
 
 
-bool RowPainter::paint(int y_offset, int x_offset, int y, bool cleared)
+void RowPainter::paint(int y_offset, int x_offset, int y)
 {
        xo_ = x_offset;
        yo_ = y_offset;
        y_ = y;
-       cleared_ = cleared;
        width_ = text_.isInInset()
                ? text_.inset_owner->textWidth(perv(bv_), true) : bv_.workWidth();
 
        // FIXME: must be a cleaner way here. Aren't these calculations
        // belonging to row metrics ?
-       BufferView * bv(const_cast<BufferView *>(&bv_));
        Row * row(const_cast<Row *>(&row_));
-       text_.prepareToPrint(bv, row, x_, separator_, hfill_, label_hfill_);
+       text_.prepareToPrint(row, x_, separator_, hfill_, label_hfill_);
 
        // FIXME: what is this fixing ?
        if (text_.isInInset() && (x_ < 0))
                x_ = 0;
        x_ += xo_;
 
-       // clear to background if necessary
-       cleared_ = paintBackground();
+       // If we're *not* at the top-level of rows, then the
+       // background has already been cleared.
+       if (&text_ == bv_.text)
+               paintBackground();
 
        // paint the selection background
        if (text_.selection.set()) {
@@ -1083,5 +1008,5 @@ bool RowPainter::paint(int y_offset, int x_offset, int y, bool cleared)
        }
 
        // paint text
-       return paintText();
+       paintText();
 }