X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2FInsetMathSpace.cpp;h=6d873b3460d3d7148b34adefe37e35185a25068c;hb=efaae780dbbe3685e26e040ed4255e5abf268106;hp=b2a321234df7366418156ade3ebf5af2004b3f90;hpb=8a0134cc8ce7de41d6d6911a1c4219ca958f2b71;p=lyx.git diff --git a/src/mathed/InsetMathSpace.cpp b/src/mathed/InsetMathSpace.cpp index b2a321234d..6d873b3460 100644 --- a/src/mathed/InsetMathSpace.cpp +++ b/src/mathed/InsetMathSpace.cpp @@ -42,26 +42,33 @@ struct SpaceInfo { bool negative; bool visible; bool custom; + bool escape; ///< whether a backslash needs to be added for writing }; SpaceInfo space_info[] = { - // name width kind negative visible custom - {"!", 6, InsetSpaceParams::NEGTHIN, true, true, false}, - {"negthinspace", 6, InsetSpaceParams::NEGTHIN, true, true, false}, - {"negmedspace", 8, InsetSpaceParams::NEGMEDIUM, true, true, false}, - {"negthickspace", 10, InsetSpaceParams::NEGTHICK, true, true, false}, - {",", 6, InsetSpaceParams::THIN, false, true, false}, - {"thinspace", 6, InsetSpaceParams::THIN, false, true, false}, - {":", 8, InsetSpaceParams::MEDIUM, false, true, false}, - {"medspace", 8, InsetSpaceParams::MEDIUM, false, true, false}, - {";", 10, InsetSpaceParams::THICK, false, true, false}, - {"thickspace", 10, InsetSpaceParams::THICK, false, true, false}, - {"enskip", 10, InsetSpaceParams::ENSKIP, false, true, false}, - {"quad", 20, InsetSpaceParams::QUAD, false, true, false}, - {"qquad", 40, InsetSpaceParams::QQUAD, false, true, false}, - {"lyxnegspace", -2, InsetSpaceParams::NEGTHIN, true, false, false}, - {"lyxposspace", 2, InsetSpaceParams::THIN, false, false, false}, - {"hspace", 0, InsetSpaceParams::CUSTOM, false, true, true}, + // name width kind negative visible custom escape + {"!", 6, InsetSpaceParams::NEGTHIN, true, true, false, true}, + {"negthinspace", 6, InsetSpaceParams::NEGTHIN, true, true, false, true}, + {"negmedspace", 8, InsetSpaceParams::NEGMEDIUM, true, true, false, true}, + {"negthickspace", 10, InsetSpaceParams::NEGTHICK, true, true, false, true}, + {",", 6, InsetSpaceParams::THIN, false, true, false, true}, + {"thinspace", 6, InsetSpaceParams::THIN, false, true, false, true}, + {":", 8, InsetSpaceParams::MEDIUM, false, true, false, true}, + {"medspace", 8, InsetSpaceParams::MEDIUM, false, true, false, true}, + {";", 10, InsetSpaceParams::THICK, false, true, false, true}, + {"thickspace", 10, InsetSpaceParams::THICK, false, true, false, true}, + {"enskip", 10, InsetSpaceParams::ENSKIP, false, true, false, true}, + {"enspace", 10, InsetSpaceParams::ENSPACE, false, true, false, true}, + {"quad", 20, InsetSpaceParams::QUAD, false, true, false, true}, + {"qquad", 40, InsetSpaceParams::QQUAD, false, true, false, true}, + {"lyxnegspace", -2, InsetSpaceParams::NEGTHIN, true, false, false, true}, + {"lyxposspace", 2, InsetSpaceParams::THIN, false, false, false, true}, + {"hfill", 80, InsetSpaceParams::HFILL, false, true, false, true}, + {"hspace*{\\fill}", 80, InsetSpaceParams::HFILL_PROTECTED, false, true, false, true}, + {"hspace*", 0, InsetSpaceParams::CUSTOM_PROTECTED,false, true, true, true}, + {"hspace", 0, InsetSpaceParams::CUSTOM, false, true, true, true}, + {" ", 10, InsetSpaceParams::NORMAL, false, true, false, true}, + {"~", 10, InsetSpaceParams::PROTECTED, false, true, false, false}, }; int const nSpace = sizeof(space_info)/sizeof(SpaceInfo); @@ -93,23 +100,18 @@ InsetMathSpace::InsetMathSpace(string const & name, string const & length) } -InsetMathSpace::InsetMathSpace(Length const & length) +InsetMathSpace::InsetMathSpace(Length const & length, bool const prot) : space_(defaultSpace), length_(length) { for (int i = 0; i < nSpace; ++i) - if (space_info[i].name == "hspace") { + if ((prot && space_info[i].name == "hspace*") + || (!prot && space_info[i].name == "hspace")) { space_ = i; break; } } -InsetMathSpace::~InsetMathSpace() -{ - hideDialogs("mathspace", this); -} - - Inset * InsetMathSpace::clone() const { return new InsetMathSpace(*this); @@ -192,11 +194,11 @@ void InsetMathSpace::octave(OctaveStream & os) const } -docstring InsetMathSpace::mathmlize(MathStream & ms) const +void InsetMathSpace::mathmlize(MathStream & ms) const { SpaceInfo const & si = space_info[space_]; if (si.negative || !si.visible) - return docstring(); + return; string l; if (si.custom) l = length_.asHTMLString(); @@ -210,7 +212,50 @@ docstring InsetMathSpace::mathmlize(MathStream & ms) const if (!l.empty()) ms << " width=\"" << from_ascii(l) << "\""; ms << " />"; - return docstring(); +} + + +void InsetMathSpace::htmlize(HtmlStream & ms) const +{ + SpaceInfo const & si = space_info[space_]; + switch (si.kind) { + case InsetSpaceParams::THIN: + ms << from_ascii(" "); + break; + case InsetSpaceParams::MEDIUM: + ms << from_ascii(" "); + break; + case InsetSpaceParams::THICK: + ms << from_ascii(" "); + break; + case InsetSpaceParams::ENSKIP: + case InsetSpaceParams::ENSPACE: + ms << from_ascii(" "); + break; + case InsetSpaceParams::QUAD: + ms << from_ascii(" "); + break; + case InsetSpaceParams::QQUAD: + ms << from_ascii("  "); + break; + case InsetSpaceParams::HFILL: + case InsetSpaceParams::HFILL_PROTECTED: + // FIXME: is there a useful HTML entity? + break; + case InsetSpaceParams::CUSTOM: + case InsetSpaceParams::CUSTOM_PROTECTED: { + string l = length_.asHTMLString(); + ms << MTag("span", "width='" + l + "'") + << from_ascii(" ") << ETag("span"); + break; + } + case InsetSpaceParams::NORMAL: + case InsetSpaceParams::PROTECTED: + ms << from_ascii(" "); + break; + default: + break; + } } @@ -223,34 +268,36 @@ void InsetMathSpace::normalize(NormalStream & os) const void InsetMathSpace::write(WriteStream & os) const { // no MathEnsurer - all kinds work in text and math mode - os << '\\' << space_info[space_].name.c_str(); + if (space_info[space_].escape) + os << '\\'; + os << space_info[space_].name.c_str(); if (space_info[space_].custom) os << '{' << length_.asLatexString().c_str() << '}'; - else + else if (space_info[space_].escape && space_info[space_].name != " ") os.pendingSpace(true); } -string const InsetMathSpace::createDialogStr() const +InsetSpaceParams InsetMathSpace::params() const { LASSERT(space_info[space_].visible, /**/); InsetSpaceParams isp(true); isp.kind = space_info[space_].kind; isp.length = GlueLength(length_); - return InsetSpace::params2string(isp); + return isp; } -docstring InsetMathSpace::contextMenu(BufferView const &, int, int) const +string InsetMathSpace::contextMenuName() const { - return from_ascii("context-mathspace"); + return "context-mathspace"; } bool InsetMathSpace::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & status) const { - switch (cmd.action) { + switch (cmd.action()) { // we handle these case LFUN_INSET_MODIFY: case LFUN_INSET_DIALOG_UPDATE: @@ -268,11 +315,12 @@ bool InsetMathSpace::getStatus(Cursor & cur, FuncRequest const & cmd, void InsetMathSpace::doDispatch(Cursor & cur, FuncRequest & cmd) { - switch (cmd.action) { + switch (cmd.action()) { case LFUN_INSET_MODIFY: if (cmd.getArg(0) == "mathspace") { MathData ar; if (createInsetMath_fromDialogStr(cmd.argument(), ar)) { + cur.recordUndo(); *this = *ar[0].nucleus()->asSpaceInset(); break; } @@ -280,14 +328,9 @@ void InsetMathSpace::doDispatch(Cursor & cur, FuncRequest & cmd) cur.undispatched(); break; - case LFUN_INSET_DIALOG_UPDATE: - cur.bv().updateDialog("mathspace", createDialogStr()); - break; - case LFUN_MOUSE_RELEASE: if (cmd.button() == mouse_button::button1) { - string const data = createDialogStr(); - cur.bv().showDialog("mathspace", data, this); + showInsetDialog(&cur.bv()); break; } cur.undispatched();