X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetSpace.cpp;h=90d171e2d40570c6330fd308565d115735d243f0;hb=3934f4a36f0402612206cfc0abe0b0b62166214b;hp=680a449c432cfad93839cee8ad3544afc859a0ca;hpb=03270dd2a652bef468266d98f6b27996150cf9d2;p=lyx.git diff --git a/src/insets/InsetSpace.cpp b/src/insets/InsetSpace.cpp index 680a449c43..90d171e2d4 100644 --- a/src/insets/InsetSpace.cpp +++ b/src/insets/InsetSpace.cpp @@ -26,6 +26,7 @@ #include "Lexer.h" #include "MetricsInfo.h" #include "OutputParams.h" +#include "output_xhtml.h" #include "support/debug.h" #include "support/docstream.h" @@ -43,7 +44,7 @@ namespace lyx { InsetSpace::InsetSpace(InsetSpaceParams const & params) - : params_(params) + : Inset(0), params_(params) {} @@ -53,18 +54,12 @@ InsetSpaceParams::Kind InsetSpace::kind() const } -Length InsetSpace::length() const +GlueLength InsetSpace::length() const { return params_.length; } -InsetSpace::~InsetSpace() -{ - hideDialogs("space", this); -} - - docstring InsetSpace::toolTip(BufferView const &, int, int) const { docstring message; @@ -75,6 +70,9 @@ docstring InsetSpace::toolTip(BufferView const &, int, int) const case InsetSpaceParams::PROTECTED: message = _("Protected Space"); break; + case InsetSpaceParams::VISIBLE: + message = _("Visible Space"); + break; case InsetSpaceParams::THIN: message = _("Thin Space"); break; @@ -88,7 +86,7 @@ docstring InsetSpace::toolTip(BufferView const &, int, int) const message = _("Quad Space"); break; case InsetSpaceParams::QQUAD: - message = _("QQuad Space"); + message = _("Double Quad Space"); break; case InsetSpaceParams::ENSPACE: message = _("Enspace"); @@ -130,12 +128,14 @@ docstring InsetSpace::toolTip(BufferView const &, int, int) const message = _("Horizontal Fill (Down Brace)"); break; case InsetSpaceParams::CUSTOM: + // FIXME unicode message = support::bformat(_("Horizontal Space (%1$s)"), - params_.length.asDocstring()); + from_ascii(params_.length.asString())); break; case InsetSpaceParams::CUSTOM_PROTECTED: + // FIXME unicode message = support::bformat(_("Protected Horizontal Space (%1$s)"), - params_.length.asDocstring()); + from_ascii(params_.length.asString())); break; } return message; @@ -144,9 +144,10 @@ docstring InsetSpace::toolTip(BufferView const &, int, int) const void InsetSpace::doDispatch(Cursor & cur, FuncRequest & cmd) { - switch (cmd.action) { + switch (cmd.action()) { case LFUN_INSET_MODIFY: + cur.recordUndo(); string2params(to_utf8(cmd.argument()), params_); break; @@ -164,15 +165,18 @@ void InsetSpace::doDispatch(Cursor & cur, FuncRequest & cmd) bool InsetSpace::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) == "space") { InsetSpaceParams params; string2params(to_utf8(cmd.argument()), params); status.setOnOff(params_.kind == params.kind); - } - // fall through + status.setEnabled(true); + } else + status.setEnabled(false); + return true; + case LFUN_INSET_DIALOG_UPDATE: status.setEnabled(true); return true; @@ -182,14 +186,6 @@ bool InsetSpace::getStatus(Cursor & cur, FuncRequest const & cmd, } -bool InsetSpace::showInsetDialog(BufferView * bv) const -{ - bv->showDialog("space", params2string(params()), - const_cast(this)); - return true; -} - - namespace { int const arrow_size = 8; } @@ -222,6 +218,7 @@ void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const dim.wid = fm.width(char_type('M')) / 2; break; case InsetSpaceParams::PROTECTED: + case InsetSpaceParams::VISIBLE: case InsetSpaceParams::NORMAL: dim.wid = fm.width(char_type(' ')); break; @@ -238,7 +235,7 @@ void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const case InsetSpaceParams::CUSTOM: case InsetSpaceParams::CUSTOM_PROTECTED: { int const w = - params_.length.inPixels(mi.base.textwidth, + params_.length.len().inPixels(mi.base.textwidth, fm.width(char_type('M'))); int const minw = (w < 0) ? 3 * arrow_size : 4; dim.wid = max(minw, abs(w)); @@ -264,7 +261,7 @@ void InsetSpace::draw(PainterInfo & pi, int x, int y) const { Dimension const dim = dimension(*pi.base.bv); - if (isStretchableSpace() || params_.length.value() < 0) { + if (isStretchableSpace() || params_.length.len().value() < 0) { int const asc = theFontMetrics(pi.base.font).ascent('M'); int const desc = theFontMetrics(pi.base.font).descent('M'); // Pixel height divisible by 2 for prettier fill graphics: @@ -356,7 +353,8 @@ void InsetSpace::draw(PainterInfo & pi, int x, int y) const xp[0] = x; yp[0] = y - max(h / 4, 1); if (params_.kind == InsetSpaceParams::NORMAL || - params_.kind == InsetSpaceParams::PROTECTED) { + params_.kind == InsetSpaceParams::PROTECTED || + params_.kind == InsetSpaceParams::VISIBLE) { xp[1] = x; yp[1] = y; xp[2] = x + w; yp[2] = y; } else { @@ -366,15 +364,18 @@ void InsetSpace::draw(PainterInfo & pi, int x, int y) const xp[3] = x + w; yp[3] = y - max(h / 4, 1); + Color col = Color_special; if (params_.kind == InsetSpaceParams::PROTECTED || params_.kind == InsetSpaceParams::ENSPACE || params_.kind == InsetSpaceParams::NEGTHIN || params_.kind == InsetSpaceParams::NEGMEDIUM || params_.kind == InsetSpaceParams::NEGTHICK || params_.kind == InsetSpaceParams::CUSTOM_PROTECTED) - pi.pain.lines(xp, yp, 4, Color_latex); - else - pi.pain.lines(xp, yp, 4, Color_special); + col = Color_latex; + else if (params_.kind == InsetSpaceParams::VISIBLE) + col = Color_foreground; + + pi.pain.lines(xp, yp, 4, col); } @@ -388,6 +389,9 @@ void InsetSpaceParams::write(ostream & os) const case InsetSpaceParams::PROTECTED: os << "~"; break; + case InsetSpaceParams::VISIBLE: + os << "\\textvisiblespace{}"; + break; case InsetSpaceParams::THIN: os << "\\thinspace{}"; break; @@ -450,7 +454,7 @@ void InsetSpaceParams::write(ostream & os) const break; } - if (!length.empty()) + if (!length.len().empty()) os << "\n\\length " << length.asString(); } @@ -466,6 +470,8 @@ void InsetSpaceParams::read(Lexer & lex) kind = InsetSpaceParams::NORMAL; else if (command == "~") kind = InsetSpaceParams::PROTECTED; + else if (command == "\\textvisiblespace{}") + kind = InsetSpaceParams::VISIBLE; else if (command == "\\thinspace{}") kind = InsetSpaceParams::THIN; else if (math && command == "\\medspace{}") @@ -482,9 +488,9 @@ void InsetSpaceParams::read(Lexer & lex) kind = InsetSpaceParams::ENSKIP; else if (command == "\\negthinspace{}") kind = InsetSpaceParams::NEGTHIN; - else if (math && command == "\\negmedspace{}") + else if (command == "\\negmedspace{}") kind = InsetSpaceParams::NEGMEDIUM; - else if (math && command == "\\negthickspace{}") + else if (command == "\\negthickspace{}") kind = InsetSpaceParams::NEGTHICK; else if (command == "\\hfill{}") kind = InsetSpaceParams::HFILL; @@ -528,7 +534,7 @@ void InsetSpace::read(Lexer & lex) } -int InsetSpace::latex(odocstream & os, OutputParams const & runparams) const +void InsetSpace::latex(otexstream & os, OutputParams const & runparams) const { switch (params_.kind) { case InsetSpaceParams::NORMAL: @@ -542,6 +548,9 @@ int InsetSpace::latex(odocstream & os, OutputParams const & runparams) const else os << (runparams.free_spacing ? ' ' : '~'); break; + case InsetSpaceParams::VISIBLE: + os << (runparams.free_spacing ? " " : "\\textvisiblespace{}"); + break; case InsetSpaceParams::THIN: os << (runparams.free_spacing ? " " : "\\,"); break; @@ -609,7 +618,6 @@ int InsetSpace::latex(odocstream & os, OutputParams const & runparams) const os << "\\hspace*{" << from_ascii(params_.length.asLatexString()) << "}"; break; } - return 0; } @@ -638,6 +646,41 @@ int InsetSpace::plaintext(odocstream & os, OutputParams const &) const case InsetSpaceParams::DOWNBRACEFILL: os << "/-^-\\"; return 5; + case InsetSpaceParams::VISIBLE: + os.put(0x2423); + return 1; + case InsetSpaceParams::ENSKIP: + os.put(0x2002); + return 1; + case InsetSpaceParams::ENSPACE: + os.put(0x2060); // WORD JOINER, makes the breakable en space unbreakable + os.put(0x2002); + os.put(0x2060); // WORD JOINER, makes the breakable en space unbreakable + return 3; + case InsetSpaceParams::QUAD: + os.put(0x2003); + return 1; + case InsetSpaceParams::QQUAD: + os.put(0x2003); + os.put(0x2003); + return 2; + case InsetSpaceParams::THIN: + os.put(0x2009); + return 1; + case InsetSpaceParams::MEDIUM: + os.put(0x2005); + return 1; + case InsetSpaceParams::THICK: + os.put(0x2004); + return 1; + case InsetSpaceParams::PROTECTED: + case InsetSpaceParams::CUSTOM_PROTECTED: + os.put(0x00a0); + return 1; + case InsetSpaceParams::NEGTHIN: + case InsetSpaceParams::NEGMEDIUM: + case InsetSpaceParams::NEGTHICK: + return 0; default: os << ' '; return 1; @@ -654,8 +697,13 @@ int InsetSpace::docbook(odocstream & os, OutputParams const &) const case InsetSpaceParams::ENSKIP: os << " "; break; + // FIXME For spaces and dashes look here: + // http://oreilly.com/catalog/docbook/book2/iso-pub.html case InsetSpaceParams::PROTECTED: + // FIXME ␣ ? + case InsetSpaceParams::VISIBLE: case InsetSpaceParams::ENSPACE: + // FIXME   ? case InsetSpaceParams::THIN: case InsetSpaceParams::MEDIUM: case InsetSpaceParams::THICK: @@ -667,12 +715,15 @@ int InsetSpace::docbook(odocstream & os, OutputParams const &) const case InsetSpaceParams::HFILL: case InsetSpaceParams::HFILL_PROTECTED: os << '\n'; + break; case InsetSpaceParams::DOTFILL: // FIXME os << '\n'; + break; case InsetSpaceParams::HRULEFILL: // FIXME os << '\n'; + break; case InsetSpaceParams::LEFTARROWFILL: case InsetSpaceParams::RIGHTARROWFILL: case InsetSpaceParams::UPBRACEFILL: @@ -681,36 +732,49 @@ int InsetSpace::docbook(odocstream & os, OutputParams const &) const case InsetSpaceParams::CUSTOM_PROTECTED: // FIXME os << '\n'; + break; } return 0; } -docstring InsetSpace::xhtml(odocstream & os, OutputParams const &) const +docstring InsetSpace::xhtml(XHTMLStream & xs, OutputParams const &) const { + string output; switch (params_.kind) { case InsetSpaceParams::NORMAL: - os << " "; + output = " "; break; case InsetSpaceParams::ENSKIP: + output =" "; + break; case InsetSpaceParams::ENSPACE: - os << " "; + output ="⁠ ⁠"; break; case InsetSpaceParams::QQUAD: - os << " "; + output ="  "; + break; case InsetSpaceParams::THICK: + output =" "; + break; case InsetSpaceParams::QUAD: - os << " "; + output =" "; + break; + case InsetSpaceParams::MEDIUM: + output =" "; break; case InsetSpaceParams::THIN: - os << " "; + output =" "; break; case InsetSpaceParams::PROTECTED: - case InsetSpaceParams::MEDIUM: case InsetSpaceParams::NEGTHIN: case InsetSpaceParams::NEGMEDIUM: case InsetSpaceParams::NEGTHICK: - os << " "; + output =" "; + break; + // no XHTML entity, only unicode code for space character exists + case InsetSpaceParams::VISIBLE: + output ="␣"; break; case InsetSpaceParams::HFILL: case InsetSpaceParams::HFILL_PROTECTED: @@ -720,14 +784,21 @@ docstring InsetSpace::xhtml(odocstream & os, OutputParams const &) const case InsetSpaceParams::RIGHTARROWFILL: case InsetSpaceParams::UPBRACEFILL: case InsetSpaceParams::DOWNBRACEFILL: - // FIXME Can we do anything with those in HTML? - os << '\n'; + // FIXME XHTML + // Can we do anything with those in HTML? break; case InsetSpaceParams::CUSTOM: + // FIXME XHTML + // Probably we could do some sort of blank span? + break; case InsetSpaceParams::CUSTOM_PROTECTED: - // FIXME Probably we could do some sort of blank span? - os << '\n'; + // FIXME XHTML + // Probably we could do some sort of blank span? + output =" "; + break; } + // don't escape the entities! + xs << XHTMLStream::ESCAPE_NONE << from_ascii(output); return docstring(); } @@ -740,12 +811,19 @@ void InsetSpace::validate(LaTeXFeatures & features) const } -void InsetSpace::tocString(odocstream & os) const +void InsetSpace::toString(odocstream & os) const { plaintext(os, OutputParams(0)); } +void InsetSpace::forToc(docstring & os, size_t) const +{ + // There's no need to be cute here. + os += " "; +} + + bool InsetSpace::isStretchableSpace() const { return params_.kind == InsetSpaceParams::HFILL @@ -759,9 +837,9 @@ bool InsetSpace::isStretchableSpace() const } -docstring InsetSpace::contextMenu(BufferView const &, int, int) const +string InsetSpace::contextMenuName() const { - return from_ascii("context-space"); + return "context-space"; }