]> git.lyx.org Git - lyx.git/blobdiff - src/ParagraphParameters.C
Alfredo's second patch
[lyx.git] / src / ParagraphParameters.C
index 76fb8aff4ec2e8b885b5d85b5d15022e7b0508b6..aca07b6b949e82f6cd67c0eeb0a44fe6801e52c3 100644 (file)
@@ -5,6 +5,15 @@
 #include "tex-strings.h"
 #include "lyxlex.h"
 
+#include "buffer.h"
+#include "BufferView.h"
+#include "gettext.h"
+#include "paragraph.h"
+#include "lyxtext.h"
+#include "frontends/LyXView.h"
+
+#include "support/lstrings.h"
+
 #include <iostream>
 
 using std::ostream;
@@ -268,6 +277,85 @@ void ParagraphParameters::leftIndent(LyXLength const & li)
 
 void ParagraphParameters::read(LyXLex & lex)
 {
+       while (lex.isOK()) {
+               lex.nextToken();
+               string const token = lex.getString();
+
+               if (token.empty())
+                       continue;
+
+               if (token[0] != '\\') {
+                       lex.pushToken(token);
+                       break;
+               }
+
+               if (token == "\\noindent") {
+                       noindent(true);
+               } else if (token == "\\leftindent") {
+                       lex.nextToken();
+                       LyXLength value(lex.getString());
+                       leftIndent(value);
+               } else if (token == "\\fill_top") {
+                       spaceTop(VSpace(VSpace::VFILL));
+               } else if (token == "\\fill_bottom") {
+                       spaceBottom(VSpace(VSpace::VFILL));
+               } else if (token == "\\line_top") {
+                       lineTop(true);
+               } else if (token == "\\line_bottom") {
+                       lineBottom(true);
+               } else if (token == "\\pagebreak_top") {
+                       pagebreakTop(true);
+               } else if (token == "\\pagebreak_bottom") {
+                       pagebreakBottom(true);
+               } else if (token == "\\start_of_appendix") {
+                       startOfAppendix(true);
+               } else if (token == "\\paragraph_spacing") {
+                       lex.next();
+                       string const tmp = rtrim(lex.getString());
+                       if (tmp == "single") {
+                               spacing(Spacing(Spacing::Single));
+                       } else if (tmp == "onehalf") {
+                               spacing(Spacing(Spacing::Onehalf));
+                       } else if (tmp == "double") {
+                               spacing(Spacing(Spacing::Double));
+                       } else if (tmp == "other") {
+                               lex.next();
+                               spacing(Spacing(Spacing::Other,
+                                                lex.getFloat()));
+                       } else {
+                               lex.printError("Unknown spacing token: '$$Token'");
+                       }
+               } else if (token == "\\align") {
+                       int tmpret = lex.findToken(string_align);
+                       if (tmpret == -1)
+                               ++tmpret;
+                       align(LyXAlignment(1 << tmpret));
+               } else if (token == "\\added_space_top") {
+                       lex.nextToken();
+                       VSpace value = VSpace(lex.getString());
+                       // only add the length when value > 0 or
+                       // with option keep
+                       if ((value.length().len().value() != 0) ||
+                           value.keep() ||
+                           (value.kind() != VSpace::LENGTH))
+                               spaceTop(value);
+               } else if (token == "\\added_space_bottom") {
+                       lex.nextToken();
+                       VSpace value = VSpace(lex.getString());
+                       // only add the length when value > 0 or
+                       // with option keep
+                       if ((value.length().len().value() != 0) ||
+                          value.keep() ||
+                           (value.kind() != VSpace::LENGTH))
+                               spaceBottom(value);
+               } else if (token == "\\labelwidthstring") {
+                       lex.eatLine();
+                       labelWidthString(lex.getString());
+               } else {
+                       lex.pushToken(token);
+                       break;
+               }
+       }
 }
 
 
@@ -326,3 +414,60 @@ void ParagraphParameters::write(ostream & os) const
                os << "\\align " << string_align[h] << ' ';
        }
 }
+
+
+void setParagraphParams(BufferView & bv, string const & data)
+{
+       istringstream is(data);
+       LyXLex lex(0,0);
+       lex.setStream(is);
+
+       ParagraphParameters params;
+       params.read(lex);
+
+       LyXText * text = bv.getLyXText();
+       text->setParagraph(params.lineTop(),
+                          params.lineBottom(),
+                          params.pagebreakTop(),
+                          params.pagebreakBottom(),
+                          params.spaceTop(),
+                          params.spaceBottom(),
+                          params.spacing(),
+                          params.align(),
+                          params.labelWidthString(),
+                          params.noindent());
+
+       // Actually apply these settings
+       bv.update(text, BufferView::SELECT);
+
+       bv.owner()->message(_("Paragraph layout set"));
+}
+
+
+void params2string(Paragraph const & par, string & data)
+{
+       // A local copy
+       ParagraphParameters params = par.params();
+
+       // This needs to be done separately
+       params.labelWidthString(par.getLabelWidthString());
+
+       // Alignment
+       LyXLayout_ptr const & layout = par.layout();
+       if (params.align() == LYX_ALIGN_LAYOUT)
+               params.align(layout->align);
+
+       ostringstream os;
+       params.write(os);
+
+       // Is alignment possible
+       os << '\n' << "\\alignpossible " << layout->alignpossible << '\n';
+
+       /// set default alignment
+       os << "\\aligndefault " << layout->align << '\n';
+
+       /// is paragraph in inset
+       os << "\\ininset " << par.inInset() << '\n';
+
+       data = os.str();
+}