]> git.lyx.org Git - lyx.git/blobdiff - src/TextMetrics.cpp
* Only enter inset which return true on isActive(). This is the behavior in the curso...
[lyx.git] / src / TextMetrics.cpp
index d80c66167fe2907116dee21845de89ad41ee56c3..8467e45a189b2618719daf65d83ff134e2de1258 100644 (file)
@@ -147,7 +147,7 @@ bool TextMetrics::metrics(MetricsInfo & mi, Dimension & dim)
 
        //lyxerr << "Text::metrics: width: " << mi.base.textwidth
        //      << " maxWidth: " << max_width_ << "\nfont: " << mi.base.font << endl;
-       
+
        bool changed = false;
 
        unsigned int h = 0;
@@ -190,10 +190,20 @@ bool TextMetrics::redoParagraph(pit_type const pit)
        main_text_ = (text_ == &buffer.text());
        bool changed = false;
 
-       // FIXME: this has nothing to do here and is the reason why text_ is not
-       // const.
-       if (par.checkBiblio(buffer.params().trackChanges))
+       // FIXME This check ought to be done somewhere else. It is the reason
+       // why text_ is not     const. But then, where else to do it?
+       // Well, how can you end up with either (a) a biblio environment that
+       // has no InsetBibitem or (b) a biblio environment with more than one
+       // InsetBibitem? I think the answer is: when paragraphs are merged;
+       // when layout is set; when material is pasted.
+       int const moveCursor = par.checkBiblio(buffer.params().trackChanges);
+       if (moveCursor > 0)
                const_cast<Cursor &>(bv_->cursor()).posRight();
+       else if (moveCursor < 0) {
+               Cursor & cursor = const_cast<Cursor &>(bv_->cursor());
+               if (cursor.pos() >= -moveCursor)
+                       cursor.posLeft();
+       }
 
        // Optimisation: this is used in the next two loops
        // so better to calculate that once here.
@@ -235,12 +245,9 @@ bool TextMetrics::redoParagraph(pit_type const pit)
 
        // Make sure that if a par ends in newline, there is one more row
        // under it
-       // FIXME this is a dirty trick. Now the _same_ position in the
-       // paragraph occurs in _two_ different rows, and has two different
-       // display positions, leading to weird behaviour when moving up/down.
        if (z > 0 && par.isNewline(z - 1)) {
-               Row row(z - 1);
-               row.endpos(z - 1);
+               Row row(z);
+               row.endpos(z);
                setRowWidth(right_margin, pit, row);
                setHeightOfRow(pit, row);
                pm.rows().push_back(row);
@@ -322,11 +329,18 @@ RowMetrics TextMetrics::computeRowMetrics(pit_type const pit,
                // The test on par.size() is to catch zero-size pars, which
                // would trigger the assert in Paragraph::getInset().
                //inset = par.size() ? par.getInset(row.pos()) : 0;
-               if (!par.empty()
-                   && par.isInset(row.pos())
-                   && par.getInset(row.pos())->display())
+               if (row.pos() < par.size()
+                   && par.isInset(row.pos()))
                {
-                       align = LYX_ALIGN_CENTER;
+                   switch(par.getInset(row.pos())->display()) {
+                       case Inset::AlignLeft:
+                               align = LYX_ALIGN_BLOCK;
+                               break;
+                       case Inset::AlignCenter:
+                               align = LYX_ALIGN_CENTER;
+                               break;
+                       // other types unchanged (use align)
+                       }
                }
 
                switch (align) {
@@ -361,7 +375,6 @@ RowMetrics TextMetrics::computeRowMetrics(pit_type const pit,
                }
        }
 
-       text_->bidi.computeTables(par, buffer, row);
        if (is_rtl) {
                pos_type body_pos = par.beginOfBody();
                pos_type end = row.endpos();
@@ -402,7 +415,7 @@ int TextMetrics::labelFill(Paragraph const & par, Row const & row) const
        if (label.empty())
                return 0;
 
-       FontMetrics const & fm 
+       FontMetrics const & fm
                = theFontMetrics(text_->getLabelFont(buffer, par));
 
        return max(0, fm.width(label) - w);
@@ -650,9 +663,12 @@ void TextMetrics::setHeightOfRow(pit_type const pit,
        Font::FONT_SIZE maxsize =
                par.highestFontInRange(row.pos(), pos_end, size);
        if (maxsize > font.size()) {
-               font.setSize(maxsize);
-               maxasc  = max(maxasc,  fontmetrics.maxAscent());
-               maxdesc = max(maxdesc, fontmetrics.maxDescent());
+               // use standard paragraph font with the maximal size
+               Font maxfont = font;
+               maxfont.setSize(maxsize);
+               FontMetrics const & maxfontmetrics = theFontMetrics(maxfont);
+               maxasc  = max(maxasc,  maxfontmetrics.maxAscent());
+               maxdesc = max(maxdesc, maxfontmetrics.maxDescent());
        }
 
        // This is nicer with box insets:
@@ -669,6 +685,7 @@ void TextMetrics::setHeightOfRow(pit_type const pit,
                if (bufparams.paragraph_separation
                    == BufferParams::PARSEP_SKIP
                        && par.ownerCode() != Inset::ERT_CODE
+                       && par.ownerCode() != Inset::LISTINGS_CODE
                        && pit > 0
                        && ((layout->isParagraph() && par.getDepth() == 0)
                            || (pars[pit - 1].layout()->isParagraph()
@@ -764,15 +781,16 @@ void TextMetrics::setHeightOfRow(pit_type const pit,
        maxasc  += int(layoutasc  * 2 / (2 + pars[pit].getDepth()));
        maxdesc += int(layoutdesc * 2 / (2 + pars[pit].getDepth()));
 
-       // FIXME: the correct way is to do the following is to move the 
-       // following code in another method specially tailored for the 
+       // FIXME: the correct way is to do the following is to move the
+       // following code in another method specially tailored for the
        // main Text. The following test is thus bogus.
        // Top and bottom margin of the document (only at top-level)
        if (main_text_) {
                if (pit == 0 && row.pos() == 0)
                        maxasc += 20;
                if (pit + 1 == pit_type(pars.size()) &&
-                   row.endpos() == par.size())
+                   row.endpos() == par.size() &&
+                               !(row.endpos() > 0 && par.isNewline(row.endpos() - 1)))
                        maxdesc += 20;
        }
 
@@ -796,6 +814,8 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit,
        x -= xo;
        RowMetrics const r = computeRowMetrics(pit, row);
        Paragraph const & par = text_->getPar(pit);
+       Bidi bidi;
+       bidi.computeTables(par, buffer, row);
 
        pos_type vc = row.pos();
        pos_type end = row.endpos();
@@ -819,11 +839,11 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit,
                return 0;
        }
 
-       frontend::FontMetrics const & fm 
+       frontend::FontMetrics const & fm
                = theFontMetrics(text_->getLabelFont(buffer, par));
 
        while (vc < end && tmpx <= x) {
-               c = text_->bidi.vis2log(vc);
+               c = bidi.vis2log(vc);
                last_tmpx = tmpx;
                if (body_pos > 0 && c == body_pos - 1) {
                        // FIXME UNICODE
@@ -869,15 +889,15 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit,
             (!rtl && !left_side && vc == end  && x > tmpx + 5)))
                c = end;
        else if (vc == row.pos()) {
-               c = text_->bidi.vis2log(vc);
-               if (text_->bidi.level(c) % 2 == 1)
+               c = bidi.vis2log(vc);
+               if (bidi.level(c) % 2 == 1)
                        ++c;
        } else {
-               c = text_->bidi.vis2log(vc - 1);
-               bool const rtl = (text_->bidi.level(c) % 2 == 1);
+               c = bidi.vis2log(vc - 1);
+               bool const rtl = (bidi.level(c) % 2 == 1);
                if (left_side == rtl) {
                        ++c;
-                       boundary = text_->bidi.isBoundary(buffer, par, c);
+                       boundary = text_->isRTLBoundary(buffer, par, c);
                }
        }
 
@@ -890,7 +910,7 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit,
        // specially, so cursor up/down doesn't get stuck in an air gap -- MV
        // Newline inset, air gap below:
        if (row.pos() < end && c >= end && par.isNewline(end - 1)) {
-               if (text_->bidi.level(end -1) % 2 == 0)
+               if (bidi.level(end -1) % 2 == 0)
                        tmpx -= text_->singleWidth(buffer, par, end - 1);
                else
                        tmpx += text_->singleWidth(buffer, par, end - 1);