]> git.lyx.org Git - features.git/blobdiff - src/insets/InsetText.cpp
Move labels and insets out of moving arguments
[features.git] / src / insets / InsetText.cpp
index e65f7e9d03e24bebae9a5983a929d2bbc7ab98d2..85da8dd4ec4c35a18f608d1509b203b271631014 100644 (file)
@@ -140,7 +140,7 @@ void InsetText::clear()
 Dimension const InsetText::dimensionHelper(BufferView const & bv) const
 {
        TextMetrics const & tm = bv.textMetrics(&text_);
-       Dimension dim = tm.dimension();
+       Dimension dim = tm.dim();
        dim.wid += 2 * TEXT_TO_INSET_OFFSET;
        dim.des += TEXT_TO_INSET_OFFSET;
        dim.asc += TEXT_TO_INSET_OFFSET;
@@ -220,11 +220,19 @@ void InsetText::draw(PainterInfo & pi, int x, int y) const
        int const h = tm.height() + 2 * TEXT_TO_INSET_OFFSET;
        int const xframe = x + TEXT_TO_INSET_OFFSET / 2;
        bool change_drawn = false;
-       if (drawFrame_ || pi.full_repaint) {
-               if (pi.full_repaint)
+       if (pi.full_repaint)
                        pi.pain.fillRectangle(xframe, yframe, w, h,
                                pi.backgroundColor(this));
 
+       {
+               Changer dummy = make_change(pi.background_color,
+                                           pi.backgroundColor(this, false));
+               // The change tracking cue must not be inherited
+               Changer dummy2 = make_change(pi.change_, Change());
+               tm.draw(pi, x + TEXT_TO_INSET_OFFSET, y);
+       }
+
+       if (drawFrame_) {
                // Change color of the frame in tracked changes, like for tabulars.
                // Only do so if the color is not custom. But do so even if RowPainter
                // handles the strike-through already.
@@ -242,16 +250,9 @@ void InsetText::draw(PainterInfo & pi, int x, int y) const
                        change_drawn = true;
                } else
                        c = frameColor();
-               if (drawFrame_)
-                       pi.pain.rectangle(xframe, yframe, w, h, c);
-       }
-       {
-               Changer dummy = make_change(pi.background_color,
-                                           pi.backgroundColor(this, false));
-               // The change tracking cue must not be inherited
-               Changer dummy2 = make_change(pi.change_, Change());
-               tm.draw(pi, x + TEXT_TO_INSET_OFFSET, y);
+               pi.pain.rectangle(xframe, yframe, w, h, c);
        }
+
        if (canPaintChange(*pi.base.bv) && (!change_drawn || pi.change_.deleted()))
                // Do not draw the change tracking cue if already done by RowPainter and
                // do not draw the cue for INSERTED if the information is already in the
@@ -458,7 +459,7 @@ void InsetText::latex(otexstream & os, OutputParams const & runparams) const
                        // FIXME UNICODE
                        // FIXME \protect should only be used for fragile
                        //    commands, but we do not provide this information yet.
-                       if (hasCProtectContent())
+                       if (hasCProtectContent(runparams.moving_arg))
                                os << "\\cprotect";
                        else if (runparams.moving_arg)
                                os << "\\protect";
@@ -498,6 +499,8 @@ void InsetText::latex(otexstream & os, OutputParams const & runparams) const
                rp.pass_thru = true;
        if (il.isNeedProtect())
                rp.moving_arg = true;
+       if (il.isNeedMBoxProtect())
+               ++rp.inulemcmd;
        if (!il.passThruChars().empty())
                rp.pass_thru_chars += il.passThruChars();
        rp.par_begin = 0;
@@ -506,6 +509,8 @@ void InsetText::latex(otexstream & os, OutputParams const & runparams) const
        // Output the contents of the inset
        latexParagraphs(buffer(), text_, os, rp);
        runparams.encoding = rp.encoding;
+       // Pass the post_macros upstream
+       runparams.post_macro = rp.post_macro;
 
        if (!il.rightdelim().empty())
                os << il.rightdelim();
@@ -762,13 +767,13 @@ ParagraphList & InsetText::paragraphs()
 }
 
 
-bool InsetText::hasCProtectContent() const
+bool InsetText::hasCProtectContent(bool const fragile) const
 {
        ParagraphList const & pars = paragraphs();
        pit_type pend = paragraphs().size();
        for (pit_type pit = 0; pit != pend; ++pit) {
                Paragraph const & par = pars[pit];
-               if (par.needsCProtection())
+               if (par.needsCProtection(fragile))
                        return true;
        }
        return false;
@@ -813,13 +818,13 @@ void InsetText::updateBuffer(ParIterator const & it, UpdateType utype)
                // Note that we do not need to call:
                //      tclass.counters().clearLastLayout()
                // since we are saving and restoring the existing counters, etc.
-               Counters const savecnt = tclass.counters();
+               Counters savecnt = tclass.counters();
                tclass.counters().reset();
                // we need float information even in note insets (#9760)
                tclass.counters().current_float(savecnt.current_float());
                tclass.counters().isSubfloat(savecnt.isSubfloat());
                buffer().updateBuffer(it2, utype);
-               tclass.counters() = savecnt;
+               tclass.counters() = move(savecnt);
        }
 }
 
@@ -1070,7 +1075,11 @@ docstring InsetText::toolTipText(docstring prefix, size_t const len) const
        for (; it != end; ++it) {
                if (it != beg)
                        oss << '\n';
+               if ((*it).isRTL(buffer().params()))
+                       oss << "<div dir=\"rtl\">";
                writePlaintextParagraph(buffer(), *it, oss, rp, ref_printed, len);
+               if ((*it).isRTL(buffer().params()))
+                       oss << "</div>";
                if (oss.tellp() >= 0 && size_t(oss.tellp()) > len)
                        break;
        }
@@ -1086,16 +1095,30 @@ InsetText::XHTMLOptions operator|(InsetText::XHTMLOptions a1, InsetText::XHTMLOp
 }
 
 
-bool InsetText::needsCProtection() const
+bool InsetText::needsCProtection(bool const maintext, bool const fragile) const
 {
+       // Nested cprotect content needs \cprotect
+       // on each level
+       if (producesOutput() && hasCProtectContent(fragile))
+               return true;
+
+       // Environments generally need cprotection in fragile context
+       if (fragile && getLayout().latextype() == InsetLayout::ENVIRONMENT)
+               return true;
+
        if (!getLayout().needsCProtect())
                return false;
 
        // Environments and "no latex" types (e.g., knitr chunks)
        // need cprotection regardless the content
-       if (getLayout().latextype() != InsetLayout::COMMAND)
+       if (!maintext && getLayout().latextype() != InsetLayout::COMMAND)
                return true;
 
+       // If the inset does not produce output (e.g. Note or Branch),
+       // we can ignore the contained paragraphs
+       if (!producesOutput())
+               return false;
+
        // Commands need cprotection if they contain specific chars
        int const nchars_escape = 9;
        static char_type const chars_escape[nchars_escape] = {
@@ -1106,7 +1129,7 @@ bool InsetText::needsCProtection() const
 
        for (pit_type pit = 0; pit != pend; ++pit) {
                Paragraph const & par = pars[pit];
-               if (par.needsCProtection())
+               if (par.needsCProtection(fragile))
                        return true;
                docstring const pars = par.asString();
                for (int k = 0; k < nchars_escape; k++) {