]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetNewpage.cpp
InsetInfo: enable inset dissolve
[lyx.git] / src / insets / InsetNewpage.cpp
index e26d2f21aa6e606c0dcb5f4cbb49eed1636f62cc..145cec96c6ed2696700d4b0aa691c64e36149df0 100644 (file)
@@ -3,7 +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 André Pönitz
+ * \author Jürgen Spitzmüller
  *
  * Full author contact details are available in file CREDITS.
  */
 
 #include "InsetNewpage.h"
 
-#include "support/debug.h"
-#include "support/gettext.h"
-#include "Text.h"
+#include "Cursor.h"
+#include "FuncRequest.h"
+#include "FuncStatus.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"
 #include "frontends/Painter.h"
 
+#include "support/debug.h"
 #include "support/docstring.h"
 #include "support/docstream.h"
+#include "support/gettext.h"
 
 using namespace std;
 
+
 namespace lyx {
 
-void InsetNewpage::read(Buffer const &, Lexer &)
+       InsetNewpage::InsetNewpage() : Inset(0)
+{}
+
+
+InsetNewpage::InsetNewpage(InsetNewpageParams const & params)
+       : Inset(0), params_(params)
+{}
+
+
+void InsetNewpageParams::write(ostream & os) const
 {
-       /* Nothing to read */
+       switch (kind) {
+       case InsetNewpageParams::NEWPAGE:
+               os << "newpage";
+               break;
+       case InsetNewpageParams::PAGEBREAK:
+               os <<  "pagebreak";
+               break;
+       case InsetNewpageParams::CLEARPAGE:
+               os <<  "clearpage";
+               break;
+       case InsetNewpageParams::CLEARDOUBLEPAGE:
+               os <<  "cleardoublepage";
+               break;
+       }
 }
 
 
-void InsetNewpage::write(Buffer const &, ostream & os) const
+void InsetNewpageParams::read(Lexer & lex)
 {
-       os << "\n" << getCmdName() << '\n';
+       lex.setContext("InsetNewpageParams::read");
+       string token;
+       lex >> token;
+
+       if (token == "newpage")
+               kind = InsetNewpageParams::NEWPAGE;
+       else if (token == "pagebreak")
+               kind = InsetNewpageParams::PAGEBREAK;
+       else if (token == "clearpage")
+               kind = InsetNewpageParams::CLEARPAGE;
+       else if (token == "cleardoublepage")
+               kind = InsetNewpageParams::CLEARDOUBLEPAGE;
+       else
+               lex.printError("Unknown kind");
+}
+
+
+void InsetNewpage::write(ostream & os) const
+{
+       os << "Newpage ";
+       params_.write(os);
+}
+
+
+void InsetNewpage::read(Lexer & lex)
+{
+       params_.read(lex);
+       lex >> "\\end_inset";
 }
 
 
@@ -46,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);
 }
 
 
@@ -79,28 +134,168 @@ void InsetNewpage::draw(PainterInfo & pi, int x, int y) const
 }
 
 
-int InsetNewpage::latex(Buffer const &, odocstream & os,
-                         OutputParams const &) const
+void InsetNewpage::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
-       os << from_ascii(getCmdName()) << "{}";
-       return 0;
+       switch (cmd.action()) {
+
+       case LFUN_INSET_MODIFY: {
+               InsetNewpageParams params;
+               cur.recordUndo();
+               string2params(to_utf8(cmd.argument()), params);
+               params_.kind = params.kind;
+               break;
+       }
+
+       default:
+               Inset::doDispatch(cur, cmd);
+               break;
+       }
+}
+
+
+bool InsetNewpage::getStatus(Cursor & cur, FuncRequest const & cmd,
+       FuncStatus & status) const
+{
+       switch (cmd.action()) {
+       // we handle these
+       case LFUN_INSET_MODIFY:
+               if (cmd.getArg(0) == "newpage") {
+                       InsetNewpageParams params;
+                       string2params(to_utf8(cmd.argument()), params);
+                       status.setOnOff(params_.kind == params.kind);
+               }
+               status.setEnabled(true);
+               return true;
+       default:
+               return Inset::getStatus(cur, cmd, status);
+       }
+}
+
+
+docstring InsetNewpage::insetLabel() const
+{
+       switch (params_.kind) {
+               case InsetNewpageParams::NEWPAGE:
+                       return _("New Page");
+                       break;
+               case InsetNewpageParams::PAGEBREAK:
+                       return _("Page Break");
+                       break;
+               case InsetNewpageParams::CLEARPAGE:
+                       return _("Clear Page");
+                       break;
+               case InsetNewpageParams::CLEARDOUBLEPAGE:
+                       return _("Clear Double Page");
+                       break;
+               default:
+                       return _("New Page");
+                       break;
+       }
+}
+
+
+ColorCode InsetNewpage::ColorName() const
+{
+       switch (params_.kind) {
+               case InsetNewpageParams::PAGEBREAK:
+                       return Color_pagebreak;
+                       break;
+               case InsetNewpageParams::NEWPAGE:
+               case InsetNewpageParams::CLEARPAGE:
+               case InsetNewpageParams::CLEARDOUBLEPAGE:
+                       return Color_newpage;
+                       break;
+       }
+       // not really useful, but to avoids gcc complaints
+       return Color_newpage;
 }
 
 
-int InsetNewpage::plaintext(Buffer const &, odocstream & os,
-                             OutputParams const &) const
+void InsetNewpage::latex(otexstream & os, OutputParams const & runparams) const
+{
+       if (runparams.inDeletedInset) {
+               os << "\\mbox{}\\\\\\makebox[\\columnwidth]{\\dotfill\\ "
+                  << insetLabel() << "\\ \\dotfill}";
+       } else {
+               switch (params_.kind) {
+               case InsetNewpageParams::NEWPAGE:
+                       os << "\\newpage" << termcmd;
+                       break;
+               case InsetNewpageParams::PAGEBREAK:
+                       if (runparams.moving_arg)
+                               os << "\\protect";
+                       os << "\\pagebreak" << termcmd;
+                       break;
+               case InsetNewpageParams::CLEARPAGE:
+                       os << "\\clearpage" << termcmd;
+                       break;
+               case InsetNewpageParams::CLEARDOUBLEPAGE:
+                       os << "\\cleardoublepage" << termcmd;
+                       break;
+               default:
+                       os << "\\newpage" << termcmd;
+                       break;
+               }
+       }
+}
+
+
+int InsetNewpage::plaintext(odocstringstream & os,
+        OutputParams const &, size_t) const
 {
        os << '\n';
        return PLAINTEXT_NEWLINE;
 }
 
 
-int InsetNewpage::docbook(Buffer const &, odocstream & os,
-                           OutputParams const &) const
+int InsetNewpage::docbook(odocstream & os, OutputParams const &) const
 {
        os << '\n';
        return 0;
 }
 
 
+docstring InsetNewpage::xhtml(XHTMLStream & xs, OutputParams const &) const
+{
+       xs << html::CompTag("br");
+       return docstring();
+}
+
+
+string InsetNewpage::contextMenuName() const
+{
+       return "context-newpage";
+}
+
+
+void InsetNewpage::string2params(string const & in, InsetNewpageParams & params)
+{
+       params = InsetNewpageParams();
+       if (in.empty())
+               return;
+
+       istringstream data(in);
+       Lexer lex;
+       lex.setStream(data);
+
+       string name;
+       lex >> name;
+       if (!lex || name != "newpage") {
+               LYXERR0("Expected arg 2 to be \"wrap\" in " << in);
+               return;
+       }
+
+       params.read(lex);
+}
+
+
+string InsetNewpage::params2string(InsetNewpageParams const & params)
+{
+       ostringstream data;
+       data << "newpage" << ' ';
+       params.write(data);
+       return data.str();
+}
+
+
 } // namespace lyx