X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetPhantom.cpp;h=9e3808f0e7ca38d1d9bc4f333fc5411ac3360145;hb=bfddee97e191a853f0576f4fab3f095c4e9ce0de;hp=be77f7e7d7a3659fcae2fe5b10353b19a0193db7;hpb=b742ff6406714ea90f8c4bf073cf4cb831b4b897;p=lyx.git diff --git a/src/insets/InsetPhantom.cpp b/src/insets/InsetPhantom.cpp index be77f7e7d7..9e3808f0e7 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" @@ -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 +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,14 +144,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) { @@ -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,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(ATOMIC_UNDO, this); string2params(to_utf8(cmd.argument()), params_); - setLayout(buffer().params()); + setButtonLabel(); + cur.forceBufferUpdate(); break; case LFUN_INSET_DIALOG_UPDATE: @@ -285,9 +279,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 +300,44 @@ 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 +{ + docstring const res = phantomtranslator_loc().find(params_.type); + return toolTipText(res + from_ascii(": ")); +} + + +void InsetPhantom::latex(otexstream & 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); + InsetCollapsable::latex(os, runparams); os << "}"; - runparams_in.encoding = runparams.encoding; - - return i + 2; } 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,14 +346,19 @@ 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 << ""; return i; } -docstring InsetPhantom::contextMenu(BufferView const &, int, int) const +docstring InsetPhantom::xhtml(XHTMLStream &, OutputParams const &) const +{ + return docstring(); +} + +docstring InsetPhantom::contextMenuName() const { return from_ascii("context-phantom"); }