]> git.lyx.org Git - lyx.git/blobdiff - src/Text.cpp
Embedding: saving inzip name to .lyx file so that embedded files can always be found...
[lyx.git] / src / Text.cpp
index bf77a0c251b3459df34868bf16f54bf8d59108ae..12ed1b85d9ee12c8d6de915f50faaea6cb7af602 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * \file src/text.cpp
+ * \file src/Text.cpp
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
 #include "Cursor.h"
 #include "ParIterator.h"
 #include "CutAndPaste.h"
-#include "debug.h"
 #include "DispatchResult.h"
 #include "Encoding.h"
 #include "ErrorList.h"
 #include "FuncRequest.h"
 #include "factory.h"
 #include "FontIterator.h"
-#include "gettext.h"
 #include "Language.h"
 #include "Length.h"
 #include "Lexer.h"
 #include "insets/InsetHFill.h"
 #include "insets/InsetLine.h"
 #include "insets/InsetNewline.h"
-#include "insets/InsetPagebreak.h"
+#include "insets/InsetNewpage.h"
 #include "insets/InsetOptArg.h"
 #include "insets/InsetSpace.h"
 #include "insets/InsetSpecialChar.h"
 #include "insets/InsetTabular.h"
 
+#include "support/convert.h"
+#include "support/debug.h"
 #include "support/docstream.h"
+#include "support/gettext.h"
 #include "support/lstrings.h"
 #include "support/textutils.h"
-#include "support/convert.h"
 
-#include <boost/current_function.hpp>
 #include <boost/next_prior.hpp>
 
 #include <sstream>
 
-using std::auto_ptr;
-using std::advance;
-using std::distance;
-using std::max;
-using std::min;
-using std::endl;
-using std::string;
+using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
 
-using support::bformat;
-using support::contains;
-using support::split;
-using support::subst;
-
 using cap::cutSelection;
 using cap::pasteParagraphList;
 
@@ -137,15 +126,11 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
                par.params().read(lex);
 
        } else if (token == "\\end_layout") {
-               lyxerr << BOOST_CURRENT_FUNCTION
-                      << ": Solitary \\end_layout in line "
-                      << lex.getLineNo() << "\n"
-                      << "Missing \\begin_layout?.\n";
+               LYXERR0("Solitary \\end_layout in line " << lex.getLineNo() << "\n"
+                      << "Missing \\begin_layout ?");
        } else if (token == "\\end_inset") {
-               lyxerr << BOOST_CURRENT_FUNCTION
-                      << ": Solitary \\end_inset in line "
-                      << lex.getLineNo() << "\n"
-                      << "Missing \\begin_inset?.\n";
+               LYXERR0("Solitary \\end_inset in line " << lex.getLineNo() << "\n"
+                      << "Missing \\begin_inset ?");
        } else if (token == "\\begin_inset") {
                Inset * inset = readInset(lex, buf);
                if (inset)
@@ -232,6 +217,10 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
                }
        } else if (token == "\\backslash") {
                par.appendChar('\\', font, change);
+       } else if (token == "\\linebreak") {
+               auto_ptr<Inset> inset(new InsetLinebreak);
+               inset->read(buf, lex);
+               par.insertInset(par.size(), inset.release(), font, change);
        } else if (token == "\\newline") {
                auto_ptr<Inset> inset(new InsetNewline);
                inset->read(buf, lex);
@@ -245,6 +234,8 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
        } else if (token == "\\lyxline") {
                par.insertInset(par.size(), new InsetLine, font, change);
        } else if (token == "\\newpage") {
+               par.insertInset(par.size(), new InsetNewpage, font, change);
+       } else if (token == "\\pagebreak") {
                par.insertInset(par.size(), new InsetPagebreak, font, change);
        } else if (token == "\\clearpage") {
                par.insertInset(par.size(), new InsetClearPage, font, change);
@@ -254,9 +245,9 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
                change = Change(Change::UNCHANGED);
        } else if (token == "\\change_inserted") {
                lex.eatLine();
-               std::istringstream is(lex.getString());
+               istringstream is(lex.getString());
                unsigned int aid;
-               time_type ct;
+               time_t ct;
                is >> aid >> ct;
                if (aid >= bp.author_map.size()) {
                        errorList.push_back(ErrorItem(_("Change tracking error"),
@@ -267,9 +258,9 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
                        change = Change(Change::INSERTED, bp.author_map[aid], ct);
        } else if (token == "\\change_deleted") {
                lex.eatLine();
-               std::istringstream is(lex.getString());
+               istringstream is(lex.getString());
                unsigned int aid;
-               time_type ct;
+               time_t ct;
                is >> aid >> ct;
                if (aid >= bp.author_map.size()) {
                        errorList.push_back(ErrorItem(_("Change tracking error"),
@@ -310,8 +301,7 @@ void readParagraph(Buffer const & buf, Paragraph & par, Lexer & lex,
                        break;
                }
 
-               LYXERR(Debug::PARSER) << "Handling paragraph token: `"
-                                     << token << '\'' << endl;
+               LYXERR(Debug::PARSER, "Handling paragraph token: `" << token << '\'');
                if (token == "\\begin_layout" || token == "\\end_document"
                    || token == "\\end_inset" || token == "\\begin_deeper"
                    || token == "\\end_deeper") {
@@ -1048,6 +1038,7 @@ bool Text::dissolveInset(Cursor & cur) {
                return false;
 
        cur.recordUndoInset();
+       cur.mark() = false;
        cur.selHandle(false);
        // save position
        pos_type spos = cur.pos();
@@ -1074,8 +1065,8 @@ bool Text::dissolveInset(Cursor & cur) {
                pasteParagraphList(cur, plist, b.params().getTextClassPtr(),
                                   b.errorList("Paste"));
                // restore position
-               cur.pit() = std::min(cur.lastpit(), spit);
-               cur.pos() = std::min(cur.lastpos(), spos);
+               cur.pit() = min(cur.lastpit(), spit);
+               cur.pos() = min(cur.lastpos(), spos);
        }
        cur.clearSelection();
        cur.resetAnchor();
@@ -1109,8 +1100,7 @@ void Text::getWord(CursorSlice & from, CursorSlice & to,
                        --from.pos();
                break;
        case NEXT_WORD:
-               lyxerr << "Text::getWord: NEXT_WORD not implemented yet"
-                      << endl;
+               LYXERR0("Text::getWord: NEXT_WORD not implemented yet");
                break;
        case PARTIAL_WORD:
                // no need to move the 'from' cursor
@@ -1123,7 +1113,7 @@ void Text::getWord(CursorSlice & from, CursorSlice & to,
 }
 
 
-void Text::write(Buffer const & buf, std::ostream & os) const
+void Text::write(Buffer const & buf, ostream & os) const
 {
        ParagraphList::const_iterator pit = paragraphs().begin();
        ParagraphList::const_iterator end = paragraphs().end();
@@ -1175,14 +1165,12 @@ bool Text::read(Buffer const & buf, Lexer & lex, ErrorList & errorList)
                } else if (token == "\\begin_deeper") {
                        ++depth;
                } else if (token == "\\end_deeper") {
-                       if (!depth) {
+                       if (!depth)
                                lex.printError("\\end_deeper: " "depth is already null");
-                       } else {
+                       else
                                --depth;
-                       }
                } else {
-                       lyxerr << "Handling unknown body token: `"
-                              << token << '\'' << endl;
+                       LYXERR0("Handling unknown body token: `" << token << '\'');
                }
        }
        return true;
@@ -1258,7 +1246,7 @@ docstring Text::currentState(Cursor & cur)
        if (!par.empty() && cur.pos() < par.size()) {
                // Force output of code point, not character
                size_t const c = par.getChar(cur.pos());
-               os << _(", Char: 0x") << std::hex << c;
+               os << _(", Char: 0x") << hex << c;
        }
        os << _(", Boundary: ") << cur.boundary();
 //     Row & row = cur.textRow();
@@ -1404,4 +1392,16 @@ void Text::charsTranspose(Cursor & cur)
 }
 
 
+DocIterator Text::macrocontextPosition() const
+{
+       return macrocontext_position_;
+}
+
+
+void Text::setMacrocontextPosition(DocIterator const & pos)
+{
+       macrocontext_position_ = pos;
+}
+
+
 } // namespace lyx