]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetSpace.cpp
revert r37459 and add a note to the sources:
[lyx.git] / src / insets / InsetSpace.cpp
index 9a6b98495965dd8f991b3b99ef43caa1684d381a..023da440289f3b62150a7e214f37e9ad5ba981f6 100644 (file)
 #include "Dimension.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
+#include "Language.h"
 #include "LaTeXFeatures.h"
 #include "Length.h"
 #include "Lexer.h"
 #include "MetricsInfo.h"
 #include "OutputParams.h"
+#include "output_xhtml.h"
 
 #include "support/debug.h"
 #include "support/docstream.h"
@@ -42,7 +44,7 @@ namespace lyx {
 
 
 InsetSpace::InsetSpace(InsetSpaceParams const & params)
-       : params_(params)
+       : Inset(0), params_(params)
 {}
 
 
@@ -52,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;
@@ -87,7 +83,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");
@@ -129,12 +125,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;
@@ -143,9 +141,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;
 
@@ -163,15 +162,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;
@@ -181,14 +183,6 @@ bool InsetSpace::getStatus(Cursor & cur, FuncRequest const & cmd,
 }
 
 
-bool InsetSpace::showInsetDialog(BufferView * bv) const
-{
-       bv->showDialog("space", params2string(params()),
-               const_cast<InsetSpace *>(this));
-       return true;
-}
-
-
 namespace {
 int const arrow_size = 8;
 }
@@ -237,7 +231,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));
@@ -263,7 +257,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:
@@ -449,7 +443,7 @@ void InsetSpaceParams::write(ostream & os) const
                break;
        }
        
-       if (!length.empty())
+       if (!length.len().empty())
                os << "\n\\length " << length.asString();
 }
 
@@ -527,14 +521,19 @@ void InsetSpace::read(Lexer & lex)
 }
 
 
-int InsetSpace::latex(odocstream & os, OutputParams const & runparams) const
+int InsetSpace::latex(otexstream & os, OutputParams const & runparams) const
 {
        switch (params_.kind) {
        case InsetSpaceParams::NORMAL:
                os << (runparams.free_spacing ? " " : "\\ ");
                break;
        case InsetSpaceParams::PROTECTED:
-               os << (runparams.free_spacing ? ' ' : '~');
+               if (runparams.local_font &&
+                   runparams.local_font->language()->lang() == "polutonikogreek")
+                       // in babel's polutonikogreek, ~ is active
+                       os << (runparams.free_spacing ? " " : "\\nobreakspace{}");
+               else
+                       os << (runparams.free_spacing ? ' ' : '~');
                break;
        case InsetSpaceParams::THIN:
                os << (runparams.free_spacing ? " " : "\\,");
@@ -680,31 +679,32 @@ int InsetSpace::docbook(odocstream & os, OutputParams const &) const
 }
 
 
-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:
        case InsetSpaceParams::ENSPACE:
-               os << "&ensp;";
+               output ="&ensp;";
                break;
        case InsetSpaceParams::QQUAD:
-               os << "&emsp;";
+               output ="&emsp;";
        case InsetSpaceParams::THICK:
        case InsetSpaceParams::QUAD:
-               os << "&emsp;";
+               output ="&emsp;";
                break;
        case InsetSpaceParams::THIN:
-               os << "&thinsp;";
+               output ="&thinsp;";
                break;
        case InsetSpaceParams::PROTECTED:
        case InsetSpaceParams::MEDIUM:
        case InsetSpaceParams::NEGTHIN:
        case InsetSpaceParams::NEGMEDIUM:
        case InsetSpaceParams::NEGTHICK:
-               os << "&nbsp;";
+               output ="&nbsp;";
                break;
        case InsetSpaceParams::HFILL:
        case InsetSpaceParams::HFILL_PROTECTED:
@@ -714,14 +714,17 @@ 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:
        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?
+               break;
        }
+       // don't escape the entities!
+       xs << XHTMLStream::ESCAPE_NONE << from_ascii(output);
        return docstring();
 }
 
@@ -734,12 +737,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
@@ -753,7 +763,7 @@ bool InsetSpace::isStretchableSpace() const
 }
 
 
-docstring InsetSpace::contextMenu(BufferView const &, int, int) const
+docstring InsetSpace::contextMenuName() const
 {
        return from_ascii("context-space");
 }