2 * \file ParagraphParameters.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
7 * \author Angus Leeming
10 * \author Jürgen Vigna
12 * Full author contact details are available in file CREDITS.
17 #include "ParagraphParameters.h"
20 #include "BufferView.h"
22 #include "lyxlayout.h"
25 #include "paragraph.h"
26 #include "tex-strings.h"
28 #include "frontends/LyXView.h"
30 #include "support/lstrings.h"
34 using lyx::support::rtrim;
36 using std::istringstream;
38 using std::ostringstream;
43 int findToken(char const * const str[], string const search_token)
47 if (search_token != "default") {
48 while (str[i][0] && str[i] != search_token) {
62 ParagraphParameters::ParagraphParameters()
64 start_of_appendix_(false), appendix_(false),
65 align_(LYX_ALIGN_LAYOUT), depth_(0)
69 void ParagraphParameters::clear()
71 operator=(ParagraphParameters());
75 ParagraphParameters::depth_type ParagraphParameters::depth() const
81 bool ParagraphParameters::sameLayout(ParagraphParameters const & pp) const
83 return align_ == pp.align_
84 && spacing_ == pp.spacing_
85 && noindent_ == pp.noindent_
86 && depth_ == pp.depth_;
90 Spacing const & ParagraphParameters::spacing() const
96 void ParagraphParameters::spacing(Spacing const & s)
102 bool ParagraphParameters::noindent() const
108 void ParagraphParameters::noindent(bool ni)
114 LyXAlignment ParagraphParameters::align() const
120 void ParagraphParameters::align(LyXAlignment la)
126 void ParagraphParameters::depth(depth_type d)
132 bool ParagraphParameters::startOfAppendix() const
134 return start_of_appendix_;
138 void ParagraphParameters::startOfAppendix(bool soa)
140 start_of_appendix_ = soa;
144 bool ParagraphParameters::appendix() const
150 void ParagraphParameters::appendix(bool a)
156 string const & ParagraphParameters::labelString() const
162 void ParagraphParameters::labelString(string const & ls)
168 string const & ParagraphParameters::labelWidthString() const
170 return labelwidthstring_;
174 void ParagraphParameters::labelWidthString(string const & lws)
176 labelwidthstring_ = lws;
180 LyXLength const & ParagraphParameters::leftIndent() const
186 void ParagraphParameters::leftIndent(LyXLength const & li)
192 void ParagraphParameters::read(LyXLex & lex)
196 string const token = lex.getString();
201 if (token[0] != '\\') {
202 lex.pushToken(token);
206 if (token == "\\noindent") {
208 } else if (token == "\\leftindent") {
210 LyXLength value(lex.getString());
212 } else if (token == "\\start_of_appendix") {
213 startOfAppendix(true);
214 } else if (token == "\\paragraph_spacing") {
216 string const tmp = rtrim(lex.getString());
217 if (tmp == "single") {
218 spacing(Spacing(Spacing::Single));
219 } else if (tmp == "onehalf") {
220 spacing(Spacing(Spacing::Onehalf));
221 } else if (tmp == "double") {
222 spacing(Spacing(Spacing::Double));
223 } else if (tmp == "other") {
225 spacing(Spacing(Spacing::Other,
228 lex.printError("Unknown spacing token: '$$Token'");
230 } else if (token == "\\align") {
232 int tmpret = findToken(string_align, lex.getString());
235 align(LyXAlignment(1 << tmpret));
236 } else if (token == "\\labelwidthstring") {
238 labelWidthString(lex.getString());
240 lex.pushToken(token);
247 void ParagraphParameters::write(ostream & os) const
251 // Maybe the paragraph has special spacing
252 spacing().writeFile(oss, true);
254 // The labelwidth string used in lists.
255 if (!labelWidthString().empty())
256 oss << "\\labelwidthstring "
257 << labelWidthString() << '\n';
259 // Start of appendix?
260 if (startOfAppendix())
261 oss << "\\start_of_appendix ";
265 oss << "\\noindent ";
267 // Do we have a manual left indent?
268 if (!leftIndent().zero())
269 oss << "\\leftindent " << leftIndent().asString()
273 if (align() != LYX_ALIGN_LAYOUT) {
276 case LYX_ALIGN_LEFT: h = 1; break;
277 case LYX_ALIGN_RIGHT: h = 2; break;
278 case LYX_ALIGN_CENTER: h = 3; break;
279 default: h = 0; break;
281 oss << "\\align " << string_align[h] << ' ';
283 os << rtrim(oss.str());
287 void params2string(Paragraph const & par, string & data)
290 ParagraphParameters params = par.params();
292 // This needs to be done separately
293 params.labelWidthString(par.getLabelWidthString());
296 LyXLayout_ptr const & layout = par.layout();
297 if (params.align() == LYX_ALIGN_LAYOUT)
298 params.align(layout->align);
303 // Is alignment possible
304 os << '\n' << "\\alignpossible " << layout->alignpossible << '\n';
306 /// set default alignment
307 os << "\\aligndefault " << layout->align << '\n';
309 /// paragraph is always in inset. This is redundant.
310 os << "\\ininset " << 1 << '\n';
317 bool operator==(ParagraphParameeters const & ps1,
318 ParagraphParameeters const & ps2)
321 ps1.spacing == ps2.spacing
322 && ps1.noindent == ps2.noindent
323 && ps1.align == ps2.align
324 && ps1.depth == ps2.depth
325 && ps1.start_of_appendix == ps2.start_of_appendix
326 && ps1.appendix == ps2.appendix
327 && ps1.labelstring == ps2.labelstring
328 && ps1.labelwidthstring == ps2.labelwidthstring
329 && ps1.leftindent == ps2.leftindent;