X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetVSpace.cpp;h=f621172fe2b5ba28475212002d26c7250fbdf6c7;hb=e30db1e44474ee379bedb0d1c752297541156497;hp=f93a7e2ee65f00274553169ba3255d2edd76bee1;hpb=050ec93722993a2b78bc28a39b2c7f3de00a4f2b;p=lyx.git diff --git a/src/insets/InsetVSpace.cpp b/src/insets/InsetVSpace.cpp index f93a7e2ee6..f621172fe2 100644 --- a/src/insets/InsetVSpace.cpp +++ b/src/insets/InsetVSpace.cpp @@ -4,7 +4,7 @@ * Licence details can be found in the file COPYING. * * \author various - * \author André Pönitz + * \author André Pönitz * * Full author contact details are available in file CREDITS. */ @@ -21,13 +21,15 @@ #include "FuncRequest.h" #include "FuncStatus.h" #include "Lexer.h" -#include "Text.h" #include "MetricsInfo.h" #include "OutputParams.h" +#include "output_xhtml.h" +#include "Text.h" -#include "support/lassert.h" #include "support/debug.h" +#include "support/docstream.h" #include "support/gettext.h" +#include "support/lassert.h" #include "frontends/Application.h" #include "frontends/FontMetrics.h" @@ -47,31 +49,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 +78,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.enabled(true); + 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) @@ -130,13 +125,13 @@ docstring const InsetVSpace::label() const namespace { -int const arrow_size = 4; +int const vspace_arrow_size = 4; } void InsetVSpace::metrics(MetricsInfo & mi, Dimension & dim) const { - int height = 3 * arrow_size; + int height = 3 * vspace_arrow_size; if (space_.length().len().value() >= 0.0) height = max(height, space_.inPixels(*mi.base.bv)); @@ -153,7 +148,7 @@ 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 * arrow_size + 5 + w; + dim.wid = ADD_TO_VSPACE_WIDTH + 2 * vspace_arrow_size + 5 + w; // Cache the inset dimension. setDimCache(mi, dim); } @@ -178,14 +173,14 @@ void InsetVSpace::draw(PainterInfo & pi, int x, int y) const // adding or removing space bool const added = space_.kind() != VSpace::LENGTH || space_.length().len().value() >= 0.0; - ty1 = added ? (start + arrow_size) : start; - ty2 = added ? start : (start + arrow_size); - by1 = added ? (end - arrow_size) : end; - by2 = added ? end : (end - arrow_size); + ty1 = added ? (start + vspace_arrow_size) : start; + ty2 = added ? start : (start + vspace_arrow_size); + by1 = added ? (end - vspace_arrow_size) : end; + by2 = added ? end : (end - vspace_arrow_size); } - int const midx = x + arrow_size; - int const rightx = midx + arrow_size; + int const midx = x + vspace_arrow_size; + int const rightx = midx + vspace_arrow_size; // first the string int w = 0; @@ -199,7 +194,7 @@ void InsetVSpace::draw(PainterInfo & pi, int x, int y) const docstring const lab = label(); theFontMetrics(font).rectText(lab, w, a, d); - pi.pain.rectText(x + 2 * arrow_size + 5, + pi.pain.rectText(x + 2 * vspace_arrow_size + 5, start + (end - start) / 2 + (a - d) / 2, lab, font, Color_none, Color_none); @@ -216,14 +211,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 +232,20 @@ int InsetVSpace::docbook(odocstream & os, OutputParams const &) const } -docstring InsetVSpace::contextMenu(BufferView const &, int, int) const +docstring InsetVSpace::xhtml(XHTMLStream &, OutputParams const &) const +{ + odocstringstream ods; + XHTMLStream xds(ods); + string const len = space_.asHTMLLength(); + string const attr = "style='height:" + (len.empty() ? "1em" : len) + "'"; + xds << html::StartTag("div", attr, true) << html::EndTag("div"); + return ods.str(); +} + + +string InsetVSpace::contextMenuName() const { - return from_ascii("context-vspace"); + return "context-vspace"; }