]> git.lyx.org Git - features.git/blobdiff - src/insets/InsetNewpage.cpp
context-sensitive command termination at some more places.
[features.git] / src / insets / InsetNewpage.cpp
index 9cb680c6849007c1ccfe3b036880b0fda889a5cf..e062e8bbecf583f1a8610b487c35c81bf64978fb 100644 (file)
@@ -3,8 +3,8 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author André Pönitz
- * \author Jürgen Spitzmüller
+ * \author André Pönitz
+ * \author Jürgen Spitzmüller
  *
  * Full author contact details are available in file CREDITS.
  */
 
 #include "InsetNewpage.h"
 
+#include "Cursor.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
-#include "Text.h"
 #include "Lexer.h"
 #include "MetricsInfo.h"
 #include "OutputParams.h"
+#include "output_xhtml.h"
+#include "texstream.h"
+#include "Text.h"
 #include "TextMetrics.h"
 
 #include "frontends/FontMetrics.h"
@@ -34,18 +37,17 @@ using namespace std;
 
 namespace lyx {
 
-InsetNewpage::InsetNewpage()
+       InsetNewpage::InsetNewpage() : Inset(0)
 {}
 
 
 InsetNewpage::InsetNewpage(InsetNewpageParams const & params)
-       : params_(params)
+       : Inset(0), params_(params)
 {}
 
 
 void InsetNewpageParams::write(ostream & os) const
 {
-       string command;
        switch (kind) {
        case InsetNewpageParams::NEWPAGE:
                os << "newpage";
@@ -79,8 +81,6 @@ void InsetNewpageParams::read(Lexer & lex)
                kind = InsetNewpageParams::CLEARDOUBLEPAGE;
        else
                lex.printError("Unknown kind");
-
-       lex >> "\\end_inset";
 }
 
 
@@ -94,6 +94,7 @@ void InsetNewpage::write(ostream & os) const
 void InsetNewpage::read(Lexer & lex)
 {
        params_.read(lex);
+       lex >> "\\end_inset";
 }
 
 
@@ -102,8 +103,6 @@ void InsetNewpage::metrics(MetricsInfo & mi, Dimension & dim) const
        dim.asc = defaultRowHeight();
        dim.des = defaultRowHeight();
        dim.wid = mi.base.textwidth;
-       // Cache the inset dimension. 
-       setDimCache(mi, dim);
 }
 
 
@@ -137,10 +136,11 @@ void InsetNewpage::draw(PainterInfo & pi, int x, int y) const
 
 void InsetNewpage::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
-       switch (cmd.action) {
+       switch (cmd.action()) {
 
        case LFUN_INSET_MODIFY: {
                InsetNewpageParams params;
+               cur.recordUndo();
                string2params(to_utf8(cmd.argument()), params);
                params_.kind = params.kind;
                break;
@@ -156,7 +156,7 @@ void InsetNewpage::doDispatch(Cursor & cur, FuncRequest & cmd)
 bool InsetNewpage::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) == "newpage") {
@@ -197,49 +197,46 @@ docstring InsetNewpage::insetLabel() const
 ColorCode InsetNewpage::ColorName() const
 {
        switch (params_.kind) {
-               case InsetNewpageParams::NEWPAGE:
-                       return Color_newpage;
-                       break;
                case InsetNewpageParams::PAGEBREAK:
                        return Color_pagebreak;
                        break;
+               case InsetNewpageParams::NEWPAGE:
                case InsetNewpageParams::CLEARPAGE:
-                       return Color_newpage;
-                       break;
                case InsetNewpageParams::CLEARDOUBLEPAGE:
                        return Color_newpage;
                        break;
-               default:
-                       return Color_newpage;
-                       break;
        }
+       // not really useful, but to avoids gcc complaints
+       return Color_newpage;
 }
 
 
-int InsetNewpage::latex(odocstream & os, OutputParams const &) const
+void InsetNewpage::latex(otexstream & os, OutputParams const & runparams) const
 {
        switch (params_.kind) {
                case InsetNewpageParams::NEWPAGE:
-                       os << "\\newpage{}";
+                       os << "\\newpage" << termcmd;
                        break;
                case InsetNewpageParams::PAGEBREAK:
-                       os << "\\pagebreak{}";
+                       if (runparams.moving_arg)
+                               os << "\\protect";
+                       os << "\\pagebreak" << termcmd;
                        break;
                case InsetNewpageParams::CLEARPAGE:
-                       os << "\\clearpage{}";
+                       os << "\\clearpage" << termcmd;
                        break;
                case InsetNewpageParams::CLEARDOUBLEPAGE:
-                       os << "\\cleardoublepage{}";
+                       os << "\\cleardoublepage" << termcmd;
                        break;
                default:
-                       os << "\\newpage{}";
+                       os << "\\newpage" << termcmd;
                        break;
        }
-       return 0;
 }
 
 
-int InsetNewpage::plaintext(odocstream & os, OutputParams const &) const
+int InsetNewpage::plaintext(odocstringstream & os,
+        OutputParams const &, size_t) const
 {
        os << '\n';
        return PLAINTEXT_NEWLINE;
@@ -253,9 +250,16 @@ int InsetNewpage::docbook(odocstream & os, OutputParams const &) const
 }
 
 
-docstring InsetNewpage::contextMenu(BufferView const &, int, int) const
+docstring InsetNewpage::xhtml(XHTMLStream & xs, OutputParams const &) const
+{
+       xs << html::CompTag("br");
+       return docstring();
+}
+
+
+string InsetNewpage::contextMenuName() const
 {
-       return from_ascii("context-newpage");
+       return "context-newpage";
 }