X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetPhantom.cpp;h=19e05700230583c00abc817865004914091da473;hb=705302f6dee4e4be9ea46213aa1b0cc18be0cfb0;hp=9e3808f0e7ca38d1d9bc4f333fc5411ac3360145;hpb=3f27f951cbc2521edfbf78792839d61306bdb978;p=lyx.git diff --git a/src/insets/InsetPhantom.cpp b/src/insets/InsetPhantom.cpp index 9e3808f0e7..19e0570023 100644 --- a/src/insets/InsetPhantom.cpp +++ b/src/insets/InsetPhantom.cpp @@ -28,6 +28,7 @@ #include "Lexer.h" #include "MetricsInfo.h" #include "OutputParams.h" +#include "texstream.h" #include "TextClass.h" #include "support/docstream.h" @@ -71,18 +72,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 +116,7 @@ void InsetPhantomParams::read(Lexer & lex) ///////////////////////////////////////////////////////////////////// InsetPhantom::InsetPhantom(Buffer * buf, string const & label) - : InsetCollapsable(buf) + : InsetCollapsible(buf) { setDrawFrame(false); params_.type = phantomtranslator().find(label); @@ -132,29 +135,20 @@ docstring InsetPhantom::layoutName() const } -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(); pi.base.font.setColor(Color_special); pi.base.font.setColor(origcol); - Dimension const dim = Inset::dimension(*pi.base.bv); + Dimension const dim = dimension(*pi.base.bv); if (params_.type == InsetPhantomParams::Phantom || params_.type == InsetPhantomParams::VPhantom) { @@ -228,14 +222,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); } @@ -259,7 +253,7 @@ void InsetPhantom::doDispatch(Cursor & cur, FuncRequest & cmd) switch (cmd.action()) { case LFUN_INSET_MODIFY: - cur.recordUndoInset(ATOMIC_UNDO, this); + cur.recordUndoInset(this); string2params(to_utf8(cmd.argument()), params_); setButtonLabel(); cur.forceBufferUpdate(); @@ -270,7 +264,7 @@ void InsetPhantom::doDispatch(Cursor & cur, FuncRequest & cmd) break; default: - InsetCollapsable::doDispatch(cur, cmd); + InsetCollapsible::doDispatch(cur, cmd); break; } } @@ -295,7 +289,7 @@ bool InsetPhantom::getStatus(Cursor & cur, FuncRequest const & cmd, return true; default: - return InsetCollapsable::getStatus(cur, cmd, flag); + return InsetCollapsible::getStatus(cur, cmd, flag); } } @@ -309,27 +303,46 @@ docstring InsetPhantom::toolTip(BufferView const &, int, int) 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{"; - InsetCollapsable::latex(os, runparams); + break; + default: + os << "\\phantom{"; + break; + } + InsetCollapsible::latex(os, runparams); os << "}"; } -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; @@ -338,15 +351,17 @@ int InsetPhantom::plaintext(odocstream & os, int InsetPhantom::docbook(odocstream & os, OutputParams const & runparams) 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"; + docstring cmdname; + switch (params_.type) { + case InsetPhantomParams::Phantom: + case InsetPhantomParams::HPhantom: + case InsetPhantomParams::VPhantom: + default: + cmdname = from_ascii("phantom"); + break; + } os << "<" + cmdname + ">"; - int const i = InsetCollapsable::docbook(os, runparams); + int const i = InsetCollapsible::docbook(os, runparams); os << ""; return i; @@ -358,9 +373,9 @@ docstring InsetPhantom::xhtml(XHTMLStream &, OutputParams const &) const return docstring(); } -docstring InsetPhantom::contextMenuName() const +string InsetPhantom::contextMenuName() const { - return from_ascii("context-phantom"); + return "context-phantom"; }