]> git.lyx.org Git - lyx.git/blobdiff - src/rowpainter.C
ws changes only
[lyx.git] / src / rowpainter.C
index 6f7a77446e843542da1d72675da773dab3a09d9e..ac1fadd6a0416ad30f1689104b6f3b6c391d9151 100644 (file)
@@ -6,40 +6,40 @@
  * \author various
  * \author John Levon
  *
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
 
-#include "frontends/Painter.h"
-#include "frontends/screen.h"
-#include "frontends/font_metrics.h"
-#include "support/LAssert.h"
-#include "paragraph.h"
-#include "paragraph_funcs.h"
-#include "support/textutils.h"
+#include "rowpainter.h"
 
-#include "insets/insettext.h"
-#include "ParagraphParameters.h"
-#include "debug.h"
-#include "BufferView.h"
 #include "buffer.h"
+#include "bufferparams.h"
+#include "BufferView.h"
+#include "encoding.h"
 #include "gettext.h"
 #include "language.h"
-#include "encoding.h"
-#include "lyxtext.h"
-#include "rowpainter.h"
+#include "LColor.h"
 #include "lyxrc.h"
+#include "lyxrow.h"
 #include "lyxrow_funcs.h"
 #include "metricsinfo.h"
+#include "paragraph.h"
+#include "paragraph_funcs.h"
+#include "ParagraphParameters.h"
+#include "vspace.h"
 
-#include <algorithm>
+#include "frontends/font_metrics.h"
+#include "frontends/Painter.h"
+
+#include "insets/insettext.h"
+
+#include "support/textutils.h"
 
-using namespace lyx::support;
 
-using std::max;
-using std::endl;
 using lyx::pos_type;
+using std::max;
+using std::string;
 
 extern int PAPER_MARGIN;
 extern int CHANGEBAR_MARGIN;
@@ -152,7 +152,8 @@ int RowPainter::singleWidth(lyx::pos_type pos) const
 
 int RowPainter::singleWidth(lyx::pos_type pos, char c) const
 {
-       return text_.singleWidth(pit_, pos, c);
+       LyXFont const & font = text_.getFont(pit_, pos);
+       return text_.singleWidth(pit_, pos, c, font);
 }
 
 
@@ -178,7 +179,7 @@ void RowPainter::paintInset(pos_type const pos)
 {
        InsetOld * inset = const_cast<InsetOld*>(pit_->getInset(pos));
 
-       Assert(inset);
+       BOOST_ASSERT(inset);
 
        PainterInfo pi(perv(bv_));
        pi.base.font = getFont(pos);
@@ -256,7 +257,7 @@ void RowPainter::paintArabicComposeChar(pos_type & vpos)
 void RowPainter::paintChars(pos_type & vpos, bool hebrew, bool arabic)
 {
        pos_type pos = text_.vis2log(vpos);
-       pos_type const last = lastPrintablePos(*pit_, row_);
+       pos_type const last = lastPos(*pit_, row_);
        LyXFont orig_font = getFont(pos);
 
        // first character
@@ -319,7 +320,7 @@ void RowPainter::paintForeignMark(double orig_x, LyXFont const & orig_font)
                return;
        if (orig_font.language() == latex_language)
                return;
-       if (orig_font.language() == bv_.buffer()->params.language)
+       if (orig_font.language() == bv_.buffer()->params().language)
                return;
 
        int const y = yo_ + row_->baseline() + 1;
@@ -337,7 +338,7 @@ void RowPainter::paintFromPos(pos_type & vpos)
 
        char const c = pit_->getChar(pos);
 
-       if (IsInsetChar(c)) {
+       if (c == Paragraph::META_INSET) {
                paintInset(pos);
                ++vpos;
                paintForeignMark(orig_x, orig_font);
@@ -381,7 +382,7 @@ void RowPainter::paintBackground()
 
 void RowPainter::paintSelection()
 {
-       bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params);
+       bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params());
 
        // the current selection
        int const startx = text_.selection.start.x();
@@ -433,7 +434,7 @@ void RowPainter::paintSelection()
                        int(x_), row_->height(), LColor::selection);
 
        pos_type const body_pos = pit_->beginningOfBody();
-       pos_type const last = lastPrintablePos(*pit_, row_);
+       pos_type const last = lastPos(*pit_, row_);
        double tmpx = x_;
 
        for (pos_type vpos = row_->pos(); vpos <= last; ++vpos)  {
@@ -485,7 +486,7 @@ void RowPainter::paintSelection()
 void RowPainter::paintChangeBar()
 {
        pos_type const start = row_->pos();
-       pos_type const end = lastPrintablePos(*pit_, row_);
+       pos_type const end = lastPos(*pit_, row_);
 
        if (!pit_->isChanged(start, end))
                return;
@@ -598,12 +599,15 @@ int RowPainter::paintLengthMarker(string const & prefix, VSpace const & vsp, int
        int d = 0;
 
        LyXFont font;
-       font.setColor(LColor::added_space).decSize().decSize();
+       font.setColor(LColor::added_space);
+       font.decSize();
+       font.decSize();
        font_metrics::rectText(str, font, w, a, d);
 
        pain_.rectText(leftx + 2 * arrow_size + 5,
-                        start + ((end - start) / 2) + d,
-                        str, font);
+                      start + ((end - start) / 2) + d,
+                      str, font,
+                      LColor::none, LColor::none);
 
        // top arrow
        pain_.line(leftx, ty1, midx, ty2, LColor::added_space);
@@ -623,7 +627,8 @@ int RowPainter::paintLengthMarker(string const & prefix, VSpace const & vsp, int
 int RowPainter::paintPageBreak(string const & label, int y)
 {
        LyXFont pb_font;
-       pb_font.setColor(LColor::pagebreak).decSize();
+       pb_font.setColor(LColor::pagebreak);
+       pb_font.decSize();
 
        int w = 0;
        int a = 0;
@@ -633,12 +638,12 @@ int RowPainter::paintPageBreak(string const & label, int y)
        int const text_start = int(xo_ + (width_ - w) / 2);
        int const text_end = text_start + w;
 
-       pain_.rectText(text_start, y + d, label, pb_font);
+       pain_.rectText(text_start, y + d, label, pb_font, LColor::none, LColor::none);
 
        pain_.line(int(xo_), y, text_start, y,
-               LColor::pagebreak, Painter::line_onoffdash);
+                  LColor::pagebreak, Painter::line_onoffdash);
        pain_.line(text_end, y, int(xo_ + width_), y,
-               LColor::pagebreak, Painter::line_onoffdash);
+                  LColor::pagebreak, Painter::line_onoffdash);
 
        return 3 * defaultRowHeight();
 }
@@ -647,7 +652,8 @@ int RowPainter::paintPageBreak(string const & label, int y)
 int RowPainter::paintAppendixStart(int y)
 {
        LyXFont pb_font;
-       pb_font.setColor(LColor::appendix).decSize();
+       pb_font.setColor(LColor::appendix);
+       pb_font.decSize();
 
        string const label = _("Appendix");
        int w = 0;
@@ -658,7 +664,7 @@ int RowPainter::paintAppendixStart(int y)
        int const text_start = int(xo_ + (width_ - w) / 2);
        int const text_end = text_start + w;
 
-       pain_.rectText(text_start, y + d, label, pb_font);
+       pain_.rectText(text_start, y + d, label, pb_font, LColor::none, LColor::none);
 
        pain_.line(int(xo_ + 1), y, text_start, y, LColor::appendix);
        pain_.line(text_end, y, int(xo_ + width_ - 2), y, LColor::appendix);
@@ -690,22 +696,22 @@ void RowPainter::paintFirst()
        y_top += paintLengthMarker(_("Space above"), parparams.spaceTop(),
                        yo_ + y_top);
 
-       Buffer const * buffer = bv_.buffer();
+       Buffer const & buffer = *bv_.buffer();
 
        LyXLayout_ptr const & layout = pit_->layout();
 
-       if (buffer->params.paragraph_separation == BufferParams::PARSEP_SKIP) {
+       if (buffer.params().paragraph_separation == BufferParams::PARSEP_SKIP) {
                if (pit_ != text_.ownerParagraphs().begin()) {
                        if (layout->latextype == LATEX_PARAGRAPH
                                && !pit_->getDepth()) {
-                               y_top += buffer->params.getDefSkip().inPixels(bv_);
+                               y_top += buffer.params().getDefSkip().inPixels(bv_);
                        } else {
                                LyXLayout_ptr const & playout =
                                        boost::prior(pit_)->layout();
                                if (playout->latextype == LATEX_PARAGRAPH
                                        && !boost::prior(pit_)->getDepth()) {
                                        // is it right to use defskip here, too? (AS)
-                                       y_top += buffer->params.getDefSkip().inPixels(bv_);
+                                       y_top += buffer.params().getDefSkip().inPixels(bv_);
                                }
                        }
                }
@@ -728,7 +734,7 @@ void RowPainter::paintFirst()
                y_top += asc;
        }
 
-       bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params);
+       bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params());
 
        // should we print a label?
        if (layout->labeltype >= LABEL_STATIC
@@ -744,13 +750,13 @@ void RowPainter::paintFirst()
                        // this is special code for the chapter layout. This is
                        // printed in an extra row and has a pagebreak at
                        // the top.
-                       if (layout->labeltype == LABEL_COUNTER_CHAPTER) {
-                               if (buffer->params.secnumdepth >= 0) {
+                       if (layout->counter == "chapter") {
+                               if (buffer.params().secnumdepth >= 0) {
                                        float spacing_val = 1.0;
                                        if (!parparams.spacing().isDefault()) {
                                                spacing_val = parparams.spacing().getValue();
                                        } else {
-                                               spacing_val = buffer->params.spacing.getValue();
+                                               spacing_val = buffer.params().spacing().getValue();
                                        }
 
                                        int const maxdesc =
@@ -793,7 +799,7 @@ void RowPainter::paintFirst()
                        if (!parparams.spacing().isDefault()) {
                                spacing_val = parparams.spacing().getValue();
                        } else {
-                               spacing_val = buffer->params.spacing.getValue();
+                               spacing_val = buffer.params().spacing().getValue();
                        }
 
                        int maxdesc =
@@ -855,7 +861,7 @@ void RowPainter::paintLast()
                y_bottom -= asc;
        }
 
-       bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params);
+       bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params());
        int const endlabel = getEndLabel(pit_, text_.ownerParagraphs());
 
        // draw an endlabel
@@ -895,7 +901,7 @@ void RowPainter::paintLast()
 
 void RowPainter::paintText()
 {
-       pos_type const last = lastPrintablePos(*pit_, row_);
+       pos_type const last = lastPos(*pit_, row_);
        pos_type body_pos = pit_->beginningOfBody();
        if (body_pos > 0 &&
                (body_pos - 1 > last || !pit_->isLineSeparator(body_pos - 1))) {
@@ -1001,11 +1007,11 @@ void RowPainter::paintText()
 
 void RowPainter::paint()
 {
-       width_ = text_.workWidth();
-
-       // FIXME: must be a cleaner way here. Aren't these calculations
-       // belonging to row metrics ?
-       text_.prepareToPrint(pit_, row_, x_, separator_, hfill_, label_hfill_);
+       width_       = text_.workWidth();
+       x_           = row_->x();
+       separator_   = row_->fill_separator();
+       hfill_       = row_->fill_hfill();
+       label_hfill_ = row_->fill_label_hfill();
 
        // FIXME: what is this fixing ?
        if (text_.isInInset() && x_ < 0)
@@ -1041,39 +1047,15 @@ void RowPainter::paint()
 }
 
 
-} // namespace anon
-
-
-int getLengthMarkerHeight(BufferView const & bv, VSpace const & vsp)
-{
-       if (vsp.kind() == VSpace::NONE)
-               return 0;
-
-       int const arrow_size = 4;
-       int const space_size = vsp.inPixels(bv);
-
-       LyXFont font;
-       font.decSize();
-       int const min_size = max(3 * arrow_size,
-               font_metrics::maxAscent(font)
-               + font_metrics::maxDescent(font));
-
-       if (vsp.length().len().value() < 0.0)
-               return min_size;
-       else
-               return max(min_size, space_size);
-}
-
-
 int paintRows(BufferView const & bv, LyXText const & text,
        ParagraphList::iterator pit, RowList::iterator rit,
        int xo, int y, int yf, int yo)
 {
-       lyxerr << "  paintRows: rit: " << &*rit << endl;
-       const_cast<LyXText&>(text).updateRowPositions();
+       //lyxerr << "  paintRows: rit: " << &*rit << endl;
+       //const_cast<LyXText&>(text).updateRowPositions();
        int const yy = yf - y;
        int const y2 = bv.painter().paperHeight();
-       
+
        ParagraphList::iterator end = text.ownerParagraphs().end();
        bool active = false;
 
@@ -1085,7 +1067,7 @@ int paintRows(BufferView const & bv, LyXText const & text,
                        if (row == rit)
                                active = true;
                        if (active) {
-                               RowPainter painter(bv, text, pit, row, y + yo, xo, y + text.top_y());
+                               RowPainter painter(bv, text, pit, row, y + yo, xo, y + bv.top_y());
                                painter.paint();
                                y += row->height();
                                if (yy + y >= y2)
@@ -1099,3 +1081,54 @@ int paintRows(BufferView const & bv, LyXText const & text,
        return y;
 }
 
+} // namespace anon
+
+
+int paintText(BufferView & bv)
+{
+       int const topy = bv.top_y();
+       ParagraphList::iterator pit;
+       RowList::iterator rit = bv.text->getRowNearY(topy, pit);
+       int y = rit->y() - topy;
+       return paintRows(bv, *bv.text, pit, rit, 0, y, y, 0);
+}
+
+
+void paintTextInset(BufferView & bv, LyXText & text, int x, int baseline)
+{
+       RowList::iterator rit = text.firstRow();
+       RowList::iterator end = text.endRow();
+       ParagraphList::iterator pit = text.ownerParagraphs().begin();
+
+       int y_offset = baseline - rit->ascent_of_text();
+       int y = y_offset;
+       while (rit != end && y + rit->height() <= 0) {
+               y += rit->height();
+               text.nextRow(pit, rit);
+       }
+       if (y_offset < 0)
+               paintRows(bv, text, pit, rit, x, 0, y, y);
+       else
+               paintRows(bv, text, pit, rit, x, 0, y_offset, y_offset);
+}
+
+
+int getLengthMarkerHeight(BufferView const & bv, VSpace const & vsp)
+{
+       if (vsp.kind() == VSpace::NONE)
+               return 0;
+
+       int const arrow_size = 4;
+       int const space_size = vsp.inPixels(bv);
+
+       LyXFont font;
+       font.decSize();
+       int const min_size = max(3 * arrow_size,
+               font_metrics::maxAscent(font)
+               + font_metrics::maxDescent(font));
+
+       if (vsp.length().len().value() < 0.0)
+               return min_size;
+       else
+               return max(min_size, space_size);
+}