]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetPhantom.cpp
Fix bug #12795
[lyx.git] / src / insets / InsetPhantom.cpp
index 431dbd858482215e60ad500526af14acd787f5c9..d1a25f6a70bc32cfcce4f32712c6112e7e37ca97 100644 (file)
 #include "Buffer.h"
 #include "BufferParams.h"
 #include "BufferView.h"
-#include "BufferParams.h"
-#include "Counters.h"
 #include "Cursor.h"
 #include "Dimension.h"
 #include "DispatchResult.h"
 #include "Exporter.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
-#include "InsetIterator.h"
 #include "LaTeXFeatures.h"
 #include "Lexer.h"
 #include "MetricsInfo.h"
-#include "OutputParams.h"
+#include "texstream.h"
 #include "TextClass.h"
 
 #include "support/docstream.h"
@@ -71,18 +68,20 @@ PhantomTranslatorLoc const init_phantomtranslator_loc()
 
 PhantomTranslator const & phantomtranslator()
 {
-       static PhantomTranslator translator = init_phantomtranslator();
+       static PhantomTranslator const translator =
+           init_phantomtranslator();
        return translator;
 }
 
 
 PhantomTranslatorLoc const & phantomtranslator_loc()
 {
-       static PhantomTranslatorLoc translator = init_phantomtranslator_loc();
+       static PhantomTranslatorLoc const translator =
+           init_phantomtranslator_loc();
        return translator;
 }
 
-} // anon
+} // namespace
 
 
 InsetPhantomParams::InsetPhantomParams()
@@ -113,7 +112,7 @@ void InsetPhantomParams::read(Lexer & lex)
 /////////////////////////////////////////////////////////////////////
 
 InsetPhantom::InsetPhantom(Buffer * buf, string const & label)
-       : InsetCollapsable(buf)
+       : InsetCollapsible(buf)
 {
        setDrawFrame(false);
        params_.type = phantomtranslator().find(label);
@@ -126,29 +125,20 @@ InsetPhantom::~InsetPhantom()
 }
 
 
-docstring InsetPhantom::name() const 
+docstring InsetPhantom::layoutName() const
 {
        return from_ascii("Phantom:" + phantomtranslator().find(params_.type));
 }
 
 
-void InsetPhantom::metrics(MetricsInfo & mi, Dimension & dim) const
-{
-       InsetCollapsable::metrics(mi, dim);
-
-       // cache the inset dimension
-       setDimCache(mi, dim);
-}
-
-
 void InsetPhantom::draw(PainterInfo & pi, int x, int y) const
 {
        // draw the text
-       InsetCollapsable::draw(pi, x, y);
+       InsetCollapsible::draw(pi, x, y);
 
        // draw the inset marker
        drawMarkers(pi, x, y);
-       
+
        // draw the arrow(s)
        static int const arrow_size = 4;
        ColorCode const origcol = pi.base.font.color();
@@ -201,10 +191,10 @@ void InsetPhantom::draw(PainterInfo & pi, int x, int y) const
                //       |   |        |   |
                //      x1  x2       x3  x4
 
-               x = x + TEXT_TO_INSET_OFFSET;
+               x += leftOffset(pi.base.bv);
                int const x1 = x;
                int const x2 = x + arrow_size;
-               int const x4 = x + dim.wid - 2 * TEXT_TO_INSET_OFFSET;
+               int const x4 = x + dim.wid - leftOffset(pi.base.bv) - rightOffset(pi.base.bv);
                int const x3 = x4 - arrow_size;
 
                int const y2 = y + (dim.des - dim.asc) / 2;
@@ -228,14 +218,14 @@ void InsetPhantom::draw(PainterInfo & pi, int x, int y) const
 void InsetPhantom::write(ostream & os) const
 {
        params_.write(os);
-       InsetCollapsable::write(os);
+       InsetCollapsible::write(os);
 }
 
 
 void InsetPhantom::read(Lexer & lex)
 {
        params_.read(lex);
-       InsetCollapsable::read(lex);
+       InsetCollapsible::read(lex);
 }
 
 
@@ -256,10 +246,13 @@ bool InsetPhantom::showInsetDialog(BufferView * bv) const
 
 void InsetPhantom::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
-       switch (cmd.action) {
+       switch (cmd.action()) {
 
        case LFUN_INSET_MODIFY:
+               cur.recordUndoInset(this);
                string2params(to_utf8(cmd.argument()), params_);
+               setButtonLabel();
+               cur.forceBufferUpdate();
                break;
 
        case LFUN_INSET_DIALOG_UPDATE:
@@ -267,7 +260,7 @@ void InsetPhantom::doDispatch(Cursor & cur, FuncRequest & cmd)
                break;
 
        default:
-               InsetCollapsable::doDispatch(cur, cmd);
+               InsetCollapsible::doDispatch(cur, cmd);
                break;
        }
 }
@@ -276,7 +269,7 @@ void InsetPhantom::doDispatch(Cursor & cur, FuncRequest & cmd)
 bool InsetPhantom::getStatus(Cursor & cur, FuncRequest const & cmd,
                FuncStatus & flag) const
 {
-       switch (cmd.action) {
+       switch (cmd.action()) {
 
        case LFUN_INSET_MODIFY:
                if (cmd.getArg(0) == "phantom") {
@@ -292,80 +285,80 @@ bool InsetPhantom::getStatus(Cursor & cur, FuncRequest const & cmd,
                return true;
 
        default:
-               return InsetCollapsable::getStatus(cur, cmd, flag);
+               return InsetCollapsible::getStatus(cur, cmd, flag);
        }
 }
 
 
 docstring InsetPhantom::toolTip(BufferView const &, int, int) const
 {
-       OutputParams rp(&buffer().params().encoding());
-       odocstringstream ods;
-       InsetCollapsable::plaintext(ods, rp);
-       docstring content_tip = support::wrapParas(ods.str());
-       docstring res = phantomtranslator_loc().find(params_.type);
-       if (!content_tip.empty())
-               res += from_ascii(": ") + "\n" + content_tip;
-       return res;
+       docstring const res = phantomtranslator_loc().find(params_.type);
+       return toolTipText(res + from_ascii(": "));
 }
 
 
-int InsetPhantom::latex(odocstream & os, OutputParams const & runparams) const
+void InsetPhantom::latex(otexstream & os, OutputParams const & runparams) const
 {
-       if (params_.type == InsetPhantomParams::Phantom)
+       if (runparams.moving_arg)
+               os << "\\protect";
+
+       switch (params_.type) {
+       case InsetPhantomParams::Phantom:
                os << "\\phantom{";
-       else if (params_.type == InsetPhantomParams::HPhantom)
+               break;
+       case InsetPhantomParams::HPhantom:
                os << "\\hphantom{";
-       else if (params_.type == InsetPhantomParams::VPhantom)
+               break;
+       case InsetPhantomParams::VPhantom:
                os << "\\vphantom{";
-       int const i = InsetCollapsable::latex(os, runparams);
+               break;
+       default:
+               os << "\\phantom{";
+               break;
+       }
+       InsetCollapsible::latex(os, runparams);
        os << "}";
-
-       return i;
 }
 
 
-int InsetPhantom::plaintext(odocstream & os,
-                           OutputParams const & runparams) const
+int InsetPhantom::plaintext(odocstringstream & os,
+                           OutputParams const & runparams, size_t max_length) const
 {
-       if (params_.type == InsetPhantomParams::Phantom)
+       switch (params_.type) {
+       case InsetPhantomParams::Phantom:
                os << '[' << buffer().B_("phantom") << ":";
-       else if (params_.type == InsetPhantomParams::HPhantom)
+               break;
+       case InsetPhantomParams::HPhantom:
                os << '[' << buffer().B_("hphantom") << ":";
-       else if (params_.type == InsetPhantomParams::VPhantom)
+               break;
+       case InsetPhantomParams::VPhantom:
                os << '[' << buffer().B_("vphantom") << ":";
-       InsetCollapsable::plaintext(os, runparams);
+               break;
+       default:
+               os << '[' << buffer().B_("phantom") << ":";
+               break;
+       }
+       InsetCollapsible::plaintext(os, runparams, max_length);
        os << "]";
 
        return PLAINTEXT_NEWLINE;
 }
 
 
-int InsetPhantom::docbook(odocstream & os, OutputParams const & runparams) const
+void InsetPhantom::docbook(XMLStream &, OutputParams const &) const
 {
-       string cmdname;
-       if (params_.type == InsetPhantomParams::Phantom)
-               cmdname = "phantom";
-       else if (params_.type == InsetPhantomParams::HPhantom)
-               cmdname = "phantom";
-       else if (params_.type == InsetPhantomParams::VPhantom)
-               cmdname = "phantom";
-       os << "<" + cmdname + ">";
-       int const i = InsetCollapsable::docbook(os, runparams);
-       os << "</" + cmdname + ">";
-
-       return i;
+       return;
 }
 
 
-docstring InsetPhantom::xhtml(odocstream &, OutputParams const &) const
+docstring InsetPhantom::xhtml(XMLStream &, OutputParams const &) const
 {
        return docstring();
 }
 
-docstring InsetPhantom::contextMenu(BufferView const &, int, int) const
+string InsetPhantom::contextMenuName() const
 {
-       return from_ascii("context-phantom");
+       return "context-phantom";
 }