]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetSpace.cpp
Output a parbreak after a command.
[lyx.git] / src / insets / InsetSpace.cpp
index d589b9750b484c5af7f9db9dd215d5ca72636bae..f7a1cd92ae8fc511171d61904e5266c9b13f7e91 100644 (file)
@@ -146,10 +146,16 @@ void InsetSpace::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action()) {
 
-       case LFUN_INSET_MODIFY:
+       case LFUN_INSET_MODIFY: {
                cur.recordUndo();
-               string2params(to_utf8(cmd.argument()), params_);
+               string arg = to_utf8(cmd.argument());
+               if (arg == "space \\hspace{}")
+                       arg += params_.length.len().empty()
+                               ? " \\length 1" + string(stringFromUnit(Length::defaultUnit()))
+                               : " \\length " + params_.length.asString();
+               string2params(arg, params_);
                break;
+       }
 
        case LFUN_INSET_DIALOG_UPDATE:
                cur.bv().updateDialog("space", params2string(params()));
@@ -172,7 +178,7 @@ bool InsetSpace::getStatus(Cursor & cur, FuncRequest const & cmd,
                        InsetSpaceParams params;
                        string2params(to_utf8(cmd.argument()), params);
                        status.setOnOff(params_.kind == params.kind);
-                       status.setEnabled(true);        
+                       status.setEnabled(true);
                } else
                        status.setEnabled(false);
                return true;
@@ -488,9 +494,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;
@@ -621,7 +627,8 @@ void InsetSpace::latex(otexstream & os, OutputParams const & runparams) const
 }
 
 
-int InsetSpace::plaintext(odocstream & os, OutputParams const &) const
+int InsetSpace::plaintext(odocstringstream & os,
+        OutputParams const &, size_t) const
 {
        switch (params_.kind) {
        case InsetSpaceParams::HFILL:
@@ -646,6 +653,45 @@ 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(0x202f);
+               return 1;
+       case InsetSpaceParams::MEDIUM:
+               os.put(0x200b); // ZERO WIDTH SPACE, makes the unbreakable medium space breakable
+               os.put(0x2005);
+               os.put(0x200b); // ZERO WIDTH SPACE, makes the unbreakable medium space breakable
+               return 1;
+       case InsetSpaceParams::THICK:
+               os.put(0x200b); // ZERO WIDTH SPACE, makes the unbreakable thick space breakable
+               os.put(0x2004);
+               os.put(0x200b); // ZERO WIDTH SPACE, makes the unbreakable thick space breakable
+               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;
@@ -680,12 +726,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:
@@ -694,6 +743,7 @@ int InsetSpace::docbook(odocstream & os, OutputParams const &) const
        case InsetSpaceParams::CUSTOM_PROTECTED:
                // FIXME
                os << '\n';
+               break;
        }
        return 0;
 }
@@ -707,20 +757,27 @@ docstring InsetSpace::xhtml(XHTMLStream & xs, OutputParams const &) const
                output = " ";
                break;
        case InsetSpaceParams::ENSKIP:
-       case InsetSpaceParams::ENSPACE:
                output ="&ensp;";
                break;
+       case InsetSpaceParams::ENSPACE:
+               output ="&#x2060;&ensp;&#x2060;";
+               break;
        case InsetSpaceParams::QQUAD:
-               output ="&emsp;";
+               output ="&emsp;&emsp;";
+               break;
        case InsetSpaceParams::THICK:
+               output ="&#x2004;";
+               break;
        case InsetSpaceParams::QUAD:
                output ="&emsp;";
                break;
+       case InsetSpaceParams::MEDIUM:
+               output ="&#x2005;";
+               break;
        case InsetSpaceParams::THIN:
                output ="&thinsp;";
                break;
        case InsetSpaceParams::PROTECTED:
-       case InsetSpaceParams::MEDIUM:
        case InsetSpaceParams::NEGTHIN:
        case InsetSpaceParams::NEGMEDIUM:
        case InsetSpaceParams::NEGTHICK:
@@ -742,9 +799,13 @@ docstring InsetSpace::xhtml(XHTMLStream & xs, OutputParams const &) const
                // 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 XHTML
                // Probably we could do some sort of blank span?
+               output ="&nbsp;";
                break;
        }
        // don't escape the entities!
@@ -763,11 +824,13 @@ void InsetSpace::validate(LaTeXFeatures & features) const
 
 void InsetSpace::toString(odocstream & os) const
 {
-       plaintext(os, OutputParams(0));
+       odocstringstream ods;
+       plaintext(ods, OutputParams(0));
+       os << ods.str();
 }
 
 
-void InsetSpace::forToc(docstring & os, size_t) const
+void InsetSpace::forOutliner(docstring & os, size_t) const
 {
        // There's no need to be cute here.
        os += " ";
@@ -787,9 +850,9 @@ bool InsetSpace::isStretchableSpace() const
 }
 
 
-docstring InsetSpace::contextMenuName() const
+string InsetSpace::contextMenuName() const
 {
-       return from_ascii("context-space");
+       return "context-space";
 }
 
 
@@ -809,7 +872,8 @@ void InsetSpace::string2params(string const & in, InsetSpaceParams & params)
                params.math = true;
        else {
                params.math = false;
-               LASSERT(name == "space", /**/);
+               // we can try to read this even if the name is wrong
+               LATTEST(name == "space");
        }
 
        // There are cases, such as when we are called via getStatus() from