X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetPhantom.cpp;h=c6efe9a9c93416ddce6259b38d22ac5d73357819;hb=04efc84abceb49e2042e357583a84b07847c1a5a;hp=65634ef455ec9438975f034f9962a78790178468;hpb=6e506647ab4167024bb5b44818ac19580148b933;p=lyx.git diff --git a/src/insets/InsetPhantom.cpp b/src/insets/InsetPhantom.cpp index 65634ef455..c6efe9a9c9 100644 --- a/src/insets/InsetPhantom.cpp +++ b/src/insets/InsetPhantom.cpp @@ -32,6 +32,7 @@ #include "support/docstream.h" #include "support/gettext.h" +#include "support/lstrings.h" #include "support/Translator.h" #include "frontends/Application.h" @@ -70,14 +71,16 @@ 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; } @@ -111,9 +114,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 +128,15 @@ InsetPhantom::~InsetPhantom() } -docstring InsetPhantom::editMessage() const -{ - return _("Opened Phantom Inset"); -} - - -docstring InsetPhantom::name() const +docstring InsetPhantom::layoutName() 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,17 +146,17 @@ 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; ColorCode const origcol = pi.base.font.color(); pi.base.font.setColor(Color_special); pi.base.font.setColor(origcol); - Dimension const dim = dimension(*pi.base.bv); + Dimension const dim = Inset::dimension(*pi.base.bv); if (params_.type == InsetPhantomParams::Phantom || params_.type == InsetPhantomParams::VPhantom) { @@ -266,11 +258,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_); - setLayout(buffer().params()); + setButtonLabel(); + cur.forceBufferUpdate(); break; case LFUN_INSET_DIALOG_UPDATE: @@ -287,9 +281,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; @@ -303,61 +302,88 @@ 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 runparams(runparams_in); - if (params_.type == InsetPhantomParams::Phantom) + docstring const res = phantomtranslator_loc().find(params_.type); + return toolTipText(res + from_ascii(": ")); +} + + +void InsetPhantom::latex(otexstream & os, OutputParams const & runparams) const +{ + 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 = InsetText::latex(os, runparams); + break; + default: + os << "\\phantom{"; + break; + } + InsetCollapsable::latex(os, runparams); os << "}"; - runparams_in.encoding = runparams.encoding; - - return i + 2; } -int InsetPhantom::plaintext(odocstream & os, - OutputParams const & runparams_in) const +int InsetPhantom::plaintext(odocstringstream & os, + OutputParams const & runparams, size_t max_length) const { - OutputParams runparams(runparams_in); - 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") << ":"; - InsetText::plaintext(os, runparams); + break; + default: + os << '[' << buffer().B_("phantom") << ":"; + break; + } + InsetCollapsable::plaintext(os, runparams, max_length); 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"; - 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 = InsetText::docbook(os, runparams); + int const i = InsetCollapsable::docbook(os, runparams); os << ""; return i; } -docstring InsetPhantom::contextMenu(BufferView const &, int, int) const +docstring InsetPhantom::xhtml(XHTMLStream &, OutputParams const &) const +{ + return docstring(); +} + +string InsetPhantom::contextMenuName() const { - return from_ascii("context-phantom"); + return "context-phantom"; }