X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetVSpace.cpp;h=d4e1aaf4a8f8d9773e3f0953593c6bfdd2c30e8d;hb=f365a650686cc27487f686a7803968df1f24e0b8;hp=8812024683117640af259200011be8c1b1944a12;hpb=f1cba8ff64b369792fd49f5ddf90e8126ab476ac;p=lyx.git diff --git a/src/insets/InsetVSpace.cpp b/src/insets/InsetVSpace.cpp index 8812024683..d4e1aaf4a8 100644 --- a/src/insets/InsetVSpace.cpp +++ b/src/insets/InsetVSpace.cpp @@ -23,9 +23,12 @@ #include "Lexer.h" #include "MetricsInfo.h" #include "OutputParams.h" +#include "output_xhtml.h" +#include "texstream.h" #include "Text.h" #include "support/debug.h" +#include "support/docstream.h" #include "support/gettext.h" #include "support/lassert.h" @@ -47,31 +50,25 @@ int const ADD_TO_VSPACE_WIDTH = 5; InsetVSpace::InsetVSpace(VSpace const & space) - : space_(space) + : Inset(0), space_(space) {} -InsetVSpace::~InsetVSpace() -{ - hideDialogs("vspace", this); -} - - void InsetVSpace::doDispatch(Cursor & cur, FuncRequest & cmd) { - switch (cmd.action) { + switch (cmd.action()) { case LFUN_INSET_MODIFY: { - InsetVSpace::string2params(to_utf8(cmd.argument()), space_); + cur.recordUndo(); + string arg = to_utf8(cmd.argument()); + if (arg == "vspace custom") + arg = (space_.kind() == VSpace::LENGTH) + ? "vspace " + space_.length().asString() + : "vspace 1" + string(stringFromUnit(Length::defaultUnit())); + InsetVSpace::string2params(arg, space_); break; } - case LFUN_MOUSE_RELEASE: - if (!cur.selection() && cmd.button() == mouse_button::button1) - cur.bv().showDialog("vspace", params2string(space()), - const_cast(this)); - break; - default: Inset::doDispatch(cur, cmd); break; @@ -82,32 +79,31 @@ void InsetVSpace::doDispatch(Cursor & cur, FuncRequest & cmd) bool InsetVSpace::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & status) const { - switch (cmd.action) { + switch (cmd.action()) { // we handle these case LFUN_INSET_MODIFY: if (cmd.getArg(0) == "vspace") { VSpace vspace; - InsetVSpace::string2params(to_utf8(cmd.argument()), vspace); + string arg = to_utf8(cmd.argument()); + if (arg == "vspace custom") + arg = (space_.kind() == VSpace::LENGTH) + ? "vspace " + space_.length().asString() + : "vspace 1" + string(stringFromUnit(Length::defaultUnit())); + InsetVSpace::string2params(arg, vspace); status.setOnOff(vspace == space_); } status.setEnabled(true); return true; + default: return Inset::getStatus(cur, cmd, status); } } -void InsetVSpace::edit(Cursor & cur, bool, EntryDirection) -{ - cur.bv().showDialog("vspace", params2string(space()), - const_cast(this)); -} - - void InsetVSpace::read(Lexer & lex) { - LASSERT(lex.isOK(), /**/); + LASSERT(lex.isOK(), return); string vsp; lex >> vsp; if (lex) @@ -154,8 +150,6 @@ void InsetVSpace::metrics(MetricsInfo & mi, Dimension & dim) const dim.asc = height / 2 + (a - d) / 2; // align cursor with the dim.des = height - dim.asc; // label text dim.wid = ADD_TO_VSPACE_WIDTH + 2 * vspace_arrow_size + 5 + w; - // Cache the inset dimension. - setDimCache(mi, dim); } @@ -216,14 +210,14 @@ void InsetVSpace::draw(PainterInfo & pi, int x, int y) const } -int InsetVSpace::latex(odocstream & os, OutputParams const &) const +void InsetVSpace::latex(otexstream & os, OutputParams const &) const { os << from_ascii(space_.asLatexCommand(buffer().params())) << '\n'; - return 1; } -int InsetVSpace::plaintext(odocstream & os, OutputParams const &) const +int InsetVSpace::plaintext(odocstringstream & os, + OutputParams const &, size_t) const { os << "\n\n"; return PLAINTEXT_NEWLINE; @@ -237,9 +231,18 @@ int InsetVSpace::docbook(odocstream & os, OutputParams const &) const } -docstring InsetVSpace::contextMenu(BufferView const &, int, int) const +docstring InsetVSpace::xhtml(XHTMLStream & os, OutputParams const &) const +{ + string const len = space_.asHTMLLength(); + string const attr = "style='height:" + (len.empty() ? "1em" : len) + "'"; + os << html::StartTag("div", attr, true) << html::EndTag("div"); + return docstring(); +} + + +string InsetVSpace::contextMenuName() const { - return from_ascii("context-vspace"); + return "context-vspace"; }