]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetNewline.cpp
Fix bug #10904.
[lyx.git] / src / insets / InsetNewline.cpp
index 5220568d56a377d7475dad2835b4ab7fbc0561a7..b10954d4da659210f8192c273c7b47273bd2d87d 100644 (file)
@@ -4,7 +4,7 @@
  * Licence details can be found in the file COPYING.
  *
  * \author John Levon
- * \author Jürgen Spitzmüller
+ * \author Jürgen Spitzmüller
  *
  * Full author contact details are available in file CREDITS.
  */
 
 #include "InsetNewline.h"
 
+#include "Cursor.h"
 #include "Dimension.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
 #include "Lexer.h"
 #include "MetricsInfo.h"
 #include "OutputParams.h"
+#include "output_xhtml.h"
+#include "texstream.h"
 
 #include "frontends/Application.h"
 #include "frontends/FontMetrics.h"
@@ -32,13 +35,12 @@ using namespace std;
 
 namespace lyx {
 
-InsetNewline::InsetNewline()
+InsetNewline::InsetNewline() : Inset(0)
 {}
 
 
 void InsetNewlineParams::write(ostream & os) const
 {
-       string command;
        switch (kind) {
        case InsetNewlineParams::NEWLINE:
                os << "newline";
@@ -54,14 +56,13 @@ void InsetNewlineParams::read(Lexer & lex)
 {
        string token;
        lex.setContext("InsetNewlineParams::read");
-       lex >> token;   
+       lex >> token;
        if (token == "newline")
                kind = InsetNewlineParams::NEWLINE;
        else if (token == "linebreak")
                kind = InsetNewlineParams::LINEBREAK;
        else
                lex.printError("Unknown kind: `$$Token'");
-       lex >> "\\end_inset";
 }
 
 
@@ -75,6 +76,7 @@ void InsetNewline::write(ostream & os) const
 void InsetNewline::read(Lexer & lex)
 {
        params_.read(lex);
+       lex >> "\\end_inset";
 }
 
 
@@ -89,10 +91,11 @@ void InsetNewline::metrics(MetricsInfo & mi, Dimension & dim) const
 
 void InsetNewline::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
-       switch (cmd.action) {
+       switch (cmd.action()) {
 
        case LFUN_INSET_MODIFY: {
                InsetNewlineParams params;
+               cur.recordUndo();
                string2params(to_utf8(cmd.argument()), params);
                params_.kind = params.kind;
                break;
@@ -108,7 +111,7 @@ void InsetNewline::doDispatch(Cursor & cur, FuncRequest & cmd)
 bool InsetNewline::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) == "newline") {
@@ -139,7 +142,7 @@ ColorCode InsetNewline::ColorName() const
 }
 
 
-int InsetNewline::latex(odocstream & os, OutputParams const & rp) const
+void InsetNewline::latex(otexstream & os, OutputParams const & rp) const
 {
        switch (params_.kind) {
                case InsetNewlineParams::NEWLINE:
@@ -155,11 +158,11 @@ int InsetNewline::latex(odocstream & os, OutputParams const & rp) const
                        os << "\\\\\n";
                        break;
        }
-       return 0;
 }
 
 
-int InsetNewline::plaintext(odocstream & os, OutputParams const &) const
+int InsetNewline::plaintext(odocstringstream & os,
+        OutputParams const &, size_t) const
 {
        os << '\n';
        return PLAINTEXT_NEWLINE;
@@ -173,6 +176,13 @@ int InsetNewline::docbook(odocstream & os, OutputParams const &) const
 }
 
 
+docstring InsetNewline::xhtml(XHTMLStream & xs, OutputParams const &) const
+{
+       xs << html::CR() << html::CompTag("br") << html::CR();
+       return docstring();
+}
+
+
 void InsetNewline::draw(PainterInfo & pi, int x, int y) const
 {
        FontInfo font;
@@ -235,7 +245,7 @@ void InsetNewline::draw(PainterInfo & pi, int x, int y) const
                yp[0] = int(y - 0.875 * asc * 0.75);
                yp[1] = int(y - 0.500 * asc * 0.75);
                yp[2] = int(y - 0.125 * asc * 0.75);
-       
+
                if (pi.ltr_pos) {
                        xp[0] = int(x + 2 * wid * 0.813);
                        xp[1] = int(x + 2 * wid);
@@ -250,9 +260,9 @@ void InsetNewline::draw(PainterInfo & pi, int x, int y) const
 }
 
 
-docstring InsetNewline::contextMenu(BufferView const &, int, int) const
+string InsetNewline::contextMenuName() const
 {
-       return from_ascii("context-newline");
+       return "context-newline";
 }