]> git.lyx.org Git - lyx.git/blobdiff - src/ParagraphParameters.cpp
Disable CheckTeX while buffer is processed
[lyx.git] / src / ParagraphParameters.cpp
index 568f183ec0a3b86d7a4d050ca344eb55e5be02dd..1152c6ab968855b4764c5d1ddff5b043d43cdabe 100644 (file)
@@ -3,11 +3,11 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author Lars Gullik Bjønnes
+ * \author Lars Gullik Bjønnes
  * \author Angus Leeming
  * \author John Levon
- * \author André Pönitz
- * \author Jürgen Vigna
+ * \author André Pönitz
+ * \author Jürgen Vigna
  *
  * Full author contact details are available in file CREDITS.
  */
 #include "ParagraphParameters.h"
 
 #include "Buffer.h"
-#include "gettext.h"
+#include "support/gettext.h"
 #include "Layout.h"
 #include "Lexer.h"
 #include "Text.h"
 #include "Paragraph.h"
-#include "tex-strings.h"
 
 #include "support/lstrings.h"
 
 #include <sstream>
 
-namespace lyx {
-
-using support::rtrim;
+using namespace std;
+using namespace lyx::support;
 
-using std::istringstream;
-using std::ostream;
-using std::ostringstream;
-using std::string;
+namespace lyx {
 
 
-static int findToken(char const * const str[], string const & search_token)
-{
-       return search_token == "default" ?
-               0 :
-               support::findToken(str, search_token);
-}
+//NOTE The order of these MUST be the same as in Layout.h.
+static char const * const string_align[] = {
+       "block", "left", "right", "center", "default", ""
+};
 
 
 ParagraphParameters::ParagraphParameters()
@@ -176,8 +169,19 @@ void ParagraphParameters::leftIndent(Length const & li)
 }
 
 
-void ParagraphParameters::read(Lexer & lex)
+void ParagraphParameters::read(string str, bool merge)
 {
+       istringstream is(str);
+       Lexer lex;
+       lex.setStream(is);
+       read(lex, merge);
+}
+
+
+void ParagraphParameters::read(Lexer & lex, bool merge)
+{
+       if (!merge)
+               clear();
        while (lex.isOK()) {
                lex.nextToken();
                string const token = lex.getString();
@@ -192,6 +196,12 @@ void ParagraphParameters::read(Lexer & lex)
 
                if (token == "\\noindent") {
                        noindent(true);
+               } else if (token == "\\indent") {
+                       //not found in LyX files but can be used with lfuns
+                       noindent(false);
+               } else if (token == "\\indent-toggle") {
+                       //not found in LyX files but can be used with lfuns
+                       noindent(!noindent());
                } else if (token == "\\leftindent") {
                        lex.next();
                        Length value(lex.getString());
@@ -201,7 +211,10 @@ void ParagraphParameters::read(Lexer & lex)
                } else if (token == "\\paragraph_spacing") {
                        lex.next();
                        string const tmp = rtrim(lex.getString());
-                       if (tmp == "single") {
+                       if (tmp == "default") {
+                               //not found in LyX files but can be used with lfuns
+                               spacing(Spacing(Spacing::Default));
+                       } else if (tmp == "single") {
                                spacing(Spacing(Spacing::Single));
                        } else if (tmp == "onehalf") {
                                spacing(Spacing(Spacing::Onehalf));
@@ -231,6 +244,18 @@ void ParagraphParameters::read(Lexer & lex)
 }
 
 
+void ParagraphParameters::apply(
+               ParagraphParameters const & p, Layout const & layout)
+{
+       spacing(p.spacing());
+       // does the layout allow the new alignment?
+       if (p.align() & layout.alignpossible)
+               align(p.align());
+       labelWidthString(p.labelWidthString());
+       noindent(p.noindent());
+}
+
+
 void ParagraphParameters::write(ostream & os) const
 {
        // Maybe the paragraph has special spacing
@@ -275,19 +300,16 @@ void params2string(Paragraph const & par, string & data)
        // This needs to be done separately
        params.labelWidthString(par.getLabelWidthString());
 
-       // Alignment
-       Layout_ptr const & layout = par.layout();
-       if (params.align() == LYX_ALIGN_LAYOUT)
-               params.align(layout->align);
-
        ostringstream os;
        params.write(os);
 
+       Layout const & layout = par.layout();
+
        // Is alignment possible
-       os << "\\alignpossible " << layout->alignpossible << '\n';
+       os << "\\alignpossible " << layout.alignpossible << '\n';
 
        /// set default alignment
-       os << "\\aligndefault " << layout->align << '\n';
+       os << "\\aligndefault " << layout.align << '\n';
 
        /// paragraph is always in inset. This is redundant.
        os << "\\ininset " << 1 << '\n';