#include "Buffer.h"
#include "gettext.h"
-#include "LyXLayout.h"
-#include "LyXLex.h"
-#include "LyXText.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 lyx::support::rtrim;
using std::istringstream;
using std::ostream;
using std::string;
-static int findToken(char const * const str[], string const & search_token)
-{
- return search_token == "default" ?
- 0 :
- support::findToken(str, search_token);
-}
+namespace lyx {
+
+//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()
}
-LyXLength const & ParagraphParameters::leftIndent() const
+Length const & ParagraphParameters::leftIndent() const
{
return leftindent_;
}
-void ParagraphParameters::leftIndent(LyXLength const & li)
+void ParagraphParameters::leftIndent(Length const & li)
{
leftindent_ = li;
}
-void ParagraphParameters::read(LyXLex & lex)
+void ParagraphParameters::read(std::string str, bool merge)
+{
+ std::istringstream is(str);
+ Lexer lex(0, 0);
+ 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();
- LyXLength value(lex.getString());
+ Length value(lex.getString());
leftIndent(value);
} else if (token == "\\start_of_appendix") {
startOfAppendix(true);
} 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));
}
} else if (token == "\\align") {
lex.next();
- int tmpret = findToken(string_align, lex.getString());
+ int tmpret = support::findToken(string_align, lex.getString());
if (tmpret == -1)
++tmpret;
align(LyXAlignment(1 << tmpret));
}
+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());
+}
+
+
+//FIXME This needs to be made a real method, so that getStatus()
+//can return sensible information.
+bool ParagraphParameters::canApply(
+ ParagraphParameters const & /*params*/, Layout const & /*layout*/)
+{
+ return true;
+}
+
+
void ParagraphParameters::write(ostream & os) const
{
// Maybe the paragraph has special spacing
// 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_ptr const & layout = par.layout();
+
// Is alignment possible
os << "\\alignpossible " << layout->alignpossible << '\n';