X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FParagraphParameters.cpp;h=1152c6ab968855b4764c5d1ddff5b043d43cdabe;hb=c16440ac9bdb7505aafff0dc9d94c5e63403948c;hp=14386641148c14a0c2e1b79c848c18bb68322887;hpb=8c622e4ff04765c786cbe9ccc9824f4429aee4e7;p=lyx.git diff --git a/src/ParagraphParameters.cpp b/src/ParagraphParameters.cpp index 1438664114..1152c6ab96 100644 --- a/src/ParagraphParameters.cpp +++ b/src/ParagraphParameters.cpp @@ -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. */ @@ -17,33 +17,26 @@ #include "ParagraphParameters.h" #include "Buffer.h" -#include "gettext.h" -#include "LyXLayout.h" +#include "support/gettext.h" +#include "Layout.h" #include "Lexer.h" -#include "LyXText.h" +#include "Text.h" #include "Paragraph.h" -#include "tex-strings.h" #include "support/lstrings.h" #include -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 - LyXLayout_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';