* 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 "LyXText.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()
}
-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();
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());
} 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));
}
+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
// 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';