X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetNewline.cpp;h=411da120eb60120df773d8f9771209d2d57d0c1e;hb=e4c46abeb7385960c9dd42494e3c7c1f3e699b56;hp=72f7e1370999042f364f799b79349801025edcd8;hpb=2012beb58e62d04b9c2fc2bc0bc3d60fa095e03e;p=lyx.git diff --git a/src/insets/InsetNewline.cpp b/src/insets/InsetNewline.cpp index 72f7e13709..411da120eb 100644 --- a/src/insets/InsetNewline.cpp +++ b/src/insets/InsetNewline.cpp @@ -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. */ @@ -13,12 +13,15 @@ #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"; @@ -52,23 +54,15 @@ void InsetNewlineParams::write(ostream & os) const void InsetNewlineParams::read(Lexer & lex) { - lex.next(); - string const command = lex.getString(); - - if (command == "newline") + string token; + lex.setContext("InsetNewlineParams::read"); + lex >> token; + if (token == "newline") kind = InsetNewlineParams::NEWLINE; - else if (command == "linebreak") + else if (token == "linebreak") kind = InsetNewlineParams::LINEBREAK; else - lex.printError("InsetNewline: Unknown kind: `$$Token'"); - - string token; - lex >> token; - if (!lex) - return; - if (token != "\\end_inset") - lex.printError("Missing \\end_inset at this point. " - "Read: `$$Token'"); + lex.printError("Unknown kind: `$$Token'"); } @@ -82,6 +76,7 @@ void InsetNewline::write(ostream & os) const void InsetNewline::read(Lexer & lex) { params_.read(lex); + lex >> "\\end_inset"; } @@ -96,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; @@ -115,16 +111,15 @@ 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") { InsetNewlineParams params; string2params(to_utf8(cmd.argument()), params); status.setOnOff(params_.kind == params.kind); - } else { - status.enabled(true); } + status.setEnabled(true); return true; default: return Inset::getStatus(cur, cmd, status); @@ -141,18 +136,20 @@ ColorCode InsetNewline::ColorName() const case InsetNewlineParams::LINEBREAK: return Color_pagebreak; break; - default: - return Color_eolmarker; - break; } + // not really useful, but to avoids gcc complaints + return Color_eolmarker; } -int InsetNewline::latex(odocstream & os, OutputParams const &) const +void InsetNewline::latex(otexstream & os, OutputParams const & rp) const { switch (params_.kind) { case InsetNewlineParams::NEWLINE: - os << "\\\\\n"; + if (rp.inTableCell == OutputParams::PLAIN) + os << "\\newline\n"; + else + os << "\\\\\n"; break; case InsetNewlineParams::LINEBREAK: os << "\\linebreak{}\n"; @@ -161,11 +158,11 @@ int InsetNewline::latex(odocstream & os, OutputParams const &) 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; @@ -179,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; @@ -256,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"; } @@ -267,18 +271,11 @@ void InsetNewline::string2params(string const & in, InsetNewlineParams & params) params = InsetNewlineParams(); if (in.empty()) return; - istringstream data(in); - Lexer lex(0,0); + Lexer lex; lex.setStream(data); - - string name; - lex >> name; - if (!lex || name != "newline") { - LYXERR0("Expected arg 1 to be \"newlien\" in " << in); - return; - } - + lex.setContext("InsetNewline::string2params"); + lex >> "newline"; params.read(lex); }