]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetPhantom.cpp
InsetBox.cpp: only shaded boxes can have multiple paragraphs when there is no inner box
[lyx.git] / src / insets / InsetPhantom.cpp
index be77f7e7d7a3659fcae2fe5b10353b19a0193db7..8a6d2e68dbe59cb426499ea75384801dfb949906 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "support/docstream.h"
 #include "support/gettext.h"
+#include "support/lstrings.h"
 #include "support/Translator.h"
 
 #include "frontends/Application.h"
@@ -111,9 +112,10 @@ void InsetPhantomParams::read(Lexer & lex)
 //
 /////////////////////////////////////////////////////////////////////
 
-InsetPhantom::InsetPhantom(Buffer const & buf, string const & label)
+InsetPhantom::InsetPhantom(Buffer * buf, string const & label)
        : InsetCollapsable(buf)
 {
+       setDrawFrame(false);
        params_.type = phantomtranslator().find(label);
 }
 
@@ -124,27 +126,15 @@ InsetPhantom::~InsetPhantom()
 }
 
 
-docstring InsetPhantom::editMessage() const
-{
-       return _("Opened Phantom Inset");
-}
-
-
 docstring InsetPhantom::name() const 
 {
        return from_ascii("Phantom:" + phantomtranslator().find(params_.type));
 }
 
 
-Inset::DisplayType InsetPhantom::display() const
-{
-       return Inline;
-}
-
-
 void InsetPhantom::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       InsetText::metrics(mi, dim);
+       InsetCollapsable::metrics(mi, dim);
 
        // cache the inset dimension
        setDimCache(mi, dim);
@@ -154,7 +144,10 @@ void InsetPhantom::metrics(MetricsInfo & mi, Dimension & dim) const
 void InsetPhantom::draw(PainterInfo & pi, int x, int y) const
 {
        // draw the text
-       InsetText::draw(pi, x, y);
+       InsetCollapsable::draw(pi, x, y);
+
+       // draw the inset marker
+       drawMarkers(pi, x, y);
        
        // draw the arrow(s)
        static int const arrow_size = 4;
@@ -208,9 +201,10 @@ void InsetPhantom::draw(PainterInfo & pi, int x, int y) const
                //       |   |        |   |
                //      x1  x2       x3  x4
 
+               x = x + TEXT_TO_INSET_OFFSET;
                int const x1 = x;
                int const x2 = x + arrow_size;
-               int const x4 = x + dim.wid;
+               int const x4 = x + dim.wid - 2 * TEXT_TO_INSET_OFFSET;
                int const x3 = x4 - arrow_size;
 
                int const y2 = y + (dim.des - dim.asc) / 2;
@@ -228,8 +222,6 @@ void InsetPhantom::draw(PainterInfo & pi, int x, int y) const
                // joining line
                pi.pain.line(x1, y2, x4, y2, Color_added_space);
        }
-
-       drawMarkers(pi, x, y);
 }
 
 
@@ -264,11 +256,10 @@ bool InsetPhantom::showInsetDialog(BufferView * bv) const
 
 void InsetPhantom::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
-       switch (cmd.action) {
+       switch (cmd.action()) {
 
        case LFUN_INSET_MODIFY:
                string2params(to_utf8(cmd.argument()), params_);
-               setLayout(buffer().params());
                break;
 
        case LFUN_INSET_DIALOG_UPDATE:
@@ -285,9 +276,14 @@ 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") {
+                       InsetPhantomParams params;
+                       string2params(to_utf8(cmd.argument()), params);
+                       flag.setOnOff(params_.type == params.type);
+               }
                flag.setEnabled(true);
                return true;
 
@@ -301,43 +297,52 @@ bool InsetPhantom::getStatus(Cursor & cur, FuncRequest const & cmd,
 }
 
 
-int InsetPhantom::latex(odocstream & os, OutputParams const & runparams_in) const
+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;
+}
+
+
+int InsetPhantom::latex(odocstream & os, OutputParams const & runparams) const
 {
-       OutputParams runparams(runparams_in);
        if (params_.type == InsetPhantomParams::Phantom)
                os << "\\phantom{";
        else if (params_.type == InsetPhantomParams::HPhantom)
                os << "\\hphantom{";
        else if (params_.type == InsetPhantomParams::VPhantom)
                os << "\\vphantom{";
-       int const i = InsetText::latex(os, runparams);
+       int const i = InsetCollapsable::latex(os, runparams);
        os << "}";
-       runparams_in.encoding = runparams.encoding;
 
-       return i + 2;
+       return i;
 }
 
 
 int InsetPhantom::plaintext(odocstream & os,
-                        OutputParams const & runparams_in) const
+                           OutputParams const & runparams) const
 {
-       OutputParams runparams(runparams_in);
        if (params_.type == InsetPhantomParams::Phantom)
                os << '[' << buffer().B_("phantom") << ":";
        else if (params_.type == InsetPhantomParams::HPhantom)
                os << '[' << buffer().B_("hphantom") << ":";
        else if (params_.type == InsetPhantomParams::VPhantom)
                os << '[' << buffer().B_("vphantom") << ":";
-       InsetText::plaintext(os, runparams);
+       InsetCollapsable::plaintext(os, runparams);
        os << "]";
 
        return PLAINTEXT_NEWLINE;
 }
 
 
-int InsetPhantom::docbook(odocstream & os, OutputParams const & runparams_in) const
+int InsetPhantom::docbook(odocstream & os, OutputParams const & runparams) const
 {
-       OutputParams runparams(runparams_in);
        string cmdname;
        if (params_.type == InsetPhantomParams::Phantom)
                cmdname = "phantom";
@@ -346,13 +351,18 @@ int InsetPhantom::docbook(odocstream & os, OutputParams const & runparams_in) co
        else if (params_.type == InsetPhantomParams::VPhantom)
                cmdname = "phantom";
        os << "<" + cmdname + ">";
-       int const i = InsetText::docbook(os, runparams);
+       int const i = InsetCollapsable::docbook(os, runparams);
        os << "</" + cmdname + ">";
 
        return i;
 }
 
 
+docstring InsetPhantom::xhtml(XHTMLStream &, OutputParams const &) const
+{
+       return docstring();
+}
+
 docstring InsetPhantom::contextMenu(BufferView const &, int, int) const
 {
        return from_ascii("context-phantom");