-
#include <config.h>
#include "ParagraphParameters.h"
#include "ParameterStruct.h"
+#include "tex-strings.h"
+#include "lyxlex.h"
+
+#include "buffer.h"
+#include "BufferView.h"
+#include "Lsstream.h"
+#include "gettext.h"
+#include "paragraph.h"
+#include "lyxtext.h"
+#include "Lsstream.h"
+
+#include "frontends/LyXView.h"
+
+#include "support/lstrings.h"
+
+#include <iostream>
+
+using std::ostream;
// Initialize static member var.
ShareContainer<ParameterStruct> ParagraphParameters::container;
ParagraphParameters::ParagraphParameters()
{
ParameterStruct tmp;
- tmp.appendix = false;
- tmp.align = LYX_ALIGN_BLOCK;
-
set_from_struct(tmp);
}
tmp.labelstring.erase();
tmp.labelwidthstring.erase();
tmp.start_of_appendix = false;
-#ifndef NO_PEXTRA_REALLY
- //tmp.pextra_type = PEXTRA_NONE;
- tmp.pextra_type = 0;
- tmp.pextra_width.erase();
- tmp.pextra_widthp.erase();
- //tmp.pextra_alignment = MINIPAGE_ALIGN_TOP;
- tmp.pextra_alignment = 0;
- tmp.pextra_hfill = false;
- tmp.pextra_start_minipage = false;
-#endif
set_from_struct(tmp);
}
param->line_top == pp.param->line_top &&
param->pagebreak_top == pp.param->pagebreak_top &&
param->added_space_top == pp.param->added_space_top &&
-#ifndef NO_PEXTRA_REALLY
param->spacing == pp.param->spacing &&
- param->pextra_type == pp.param->pextra_type &&
- param->pextra_width == pp.param->pextra_width &&
- param->pextra_widthp == pp.param->pextra_widthp &&
- param->pextra_alignment == pp.param->pextra_alignment &&
- param->pextra_hfill == pp.param->pextra_hfill &&
- param->pextra_start_minipage == pp.param->pextra_start_minipage &&
-#endif
param->noindent == pp.param->noindent &&
param->depth == pp.param->depth;
}
-void ParagraphParameters::makeSame(ParagraphParameters const & pp)
-{
- ParameterStruct tmp(*param);
- tmp.align = pp.param->align;
- // tmp.labelwidthstring = pp.params.labelwidthstring;
- tmp.line_bottom = pp.param->line_bottom;
- tmp.pagebreak_bottom = pp.param->pagebreak_bottom;
- tmp.added_space_bottom = pp.param->added_space_bottom;
- tmp.line_top = pp.param->line_top;
- tmp.pagebreak_top = pp.param->pagebreak_top;
- tmp.added_space_top = pp.param->added_space_top;
- tmp.spacing = pp.param->spacing;
-#ifndef NO_PEXTRA_REALLY
- tmp.pextra_type = pp.param->pextra_type;
- tmp.pextra_width = pp.param->pextra_width;
- tmp.pextra_widthp = pp.param->pextra_widthp;
- tmp.pextra_alignment = pp.param->pextra_alignment;
- tmp.pextra_hfill = pp.param->pextra_hfill;
- tmp.pextra_start_minipage = pp.param->pextra_start_minipage;
-#endif
- tmp.noindent = pp.param->noindent;
- tmp.depth = pp.param->depth;
-
- set_from_struct(tmp);
-}
-
-
-void ParagraphParameters::set_from_struct(ParameterStruct const & ps)
+void ParagraphParameters::set_from_struct(ParameterStruct const & ps)
{
// get new param from container with tmp as template
param = container.get(ps);
}
-void ParagraphParameters::depth(char d)
+void ParagraphParameters::depth(depth_type d)
{
ParameterStruct tmp(*param);
tmp.depth = d;
set_from_struct(tmp);
}
-#ifndef NO_PEXTRA_REALLY
-int ParagraphParameters::pextraType() const
-{
- return param->pextra_type;
-}
-
-
-void ParagraphParameters::pextraType(int t)
-{
- ParameterStruct tmp(*param);
- tmp.pextra_type = t;
- set_from_struct(tmp);
-}
-
-string const & ParagraphParameters::pextraWidth() const
+LyXLength const & ParagraphParameters::leftIndent() const
{
- return param->pextra_width;
+ return param->leftindent;
}
-void ParagraphParameters::pextraWidth(string const & w)
+void ParagraphParameters::leftIndent(LyXLength const & li)
{
ParameterStruct tmp(*param);
- tmp.pextra_width = w;
+ tmp.leftindent = li;
set_from_struct(tmp);
}
-string const & ParagraphParameters::pextraWidthp() const
-{
- return param->pextra_widthp;
+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;
+ }
+ }
+}
+
+
+void ParagraphParameters::write(ostream & os) const
+{
+ // Maybe some vertical spaces.
+ if (spaceTop().kind() != VSpace::NONE)
+ os << "\\added_space_top "
+ << spaceTop().asLyXCommand() << ' ';
+ if (spaceBottom().kind() != VSpace::NONE)
+ os << "\\added_space_bottom "
+ << spaceBottom().asLyXCommand() << ' ';
+
+ // Maybe the paragraph has special spacing
+ spacing().writeFile(os, true);
+
+ // The labelwidth string used in lists.
+ if (!labelWidthString().empty())
+ os << "\\labelwidthstring "
+ << labelWidthString() << '\n';
+
+ // Lines above or below?
+ if (lineTop())
+ os << "\\line_top ";
+ if (lineBottom())
+ os << "\\line_bottom ";
+
+ // Pagebreaks above or below?
+ if (pagebreakTop())
+ os << "\\pagebreak_top ";
+ if (pagebreakBottom())
+ os << "\\pagebreak_bottom ";
+
+ // Start of appendix?
+ if (startOfAppendix())
+ os << "\\start_of_appendix ";
+
+ // Noindent?
+ if (noindent())
+ os << "\\noindent ";
+
+ // Do we have a manual left indent?
+ if (!leftIndent().zero())
+ os << "\\leftindent " << leftIndent().asString()
+ << ' ';
+
+ // Alignment?
+ if (align() != LYX_ALIGN_LAYOUT) {
+ int h = 0;
+ switch (align()) {
+ case LYX_ALIGN_LEFT: h = 1; break;
+ case LYX_ALIGN_RIGHT: h = 2; break;
+ case LYX_ALIGN_CENTER: h = 3; break;
+ default: h = 0; break;
+ }
+ os << "\\align " << string_align[h] << ' ';
+ }
+}
+
+
+void setParagraphParams(BufferView & bv, string const & data)
+{
+ istringstream is(STRCONV(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 ParagraphParameters::pextraWidthp(string const & wp)
+void params2string(Paragraph const & par, string & data)
{
- ParameterStruct tmp(*param);
- tmp.pextra_widthp = wp;
- set_from_struct(tmp);
-}
-
-
-int ParagraphParameters::pextraAlignment() const
-{
- return param->pextra_alignment;
-}
-
-
-void ParagraphParameters::pextraAlignment(int a)
-{
- ParameterStruct tmp(*param);
- tmp.pextra_alignment = a;
- set_from_struct(tmp);
-}
+ // A local copy
+ ParagraphParameters params = par.params();
+ // This needs to be done separately
+ params.labelWidthString(par.getLabelWidthString());
-bool ParagraphParameters::pextraHfill() const
-{
- return param->pextra_hfill;
-}
-
+ // Alignment
+ LyXLayout_ptr const & layout = par.layout();
+ if (params.align() == LYX_ALIGN_LAYOUT)
+ params.align(layout->align);
-void ParagraphParameters::pextraHfill(bool hf)
-{
- ParameterStruct tmp(*param);
- tmp.pextra_hfill = hf;
- set_from_struct(tmp);
-}
+ ostringstream os;
+ params.write(os);
+ // Is alignment possible
+ os << '\n' << "\\alignpossible " << layout->alignpossible << '\n';
-bool ParagraphParameters::pextraStartMinipage() const
-{
- return param->pextra_start_minipage;
-}
+ /// set default alignment
+ os << "\\aligndefault " << layout->align << '\n';
+ /// is paragraph in inset
+ os << "\\ininset " << (par.inInset()?1:0) << '\n';
-void ParagraphParameters::pextraStartMinipage(bool smp)
-{
- ParameterStruct tmp(*param);
- tmp.pextra_start_minipage = smp;
- set_from_struct(tmp);
+ data = STRCONV(os.str());
}
-#endif