2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file ParagraphParameters.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Angus Leeming
|
|
|
|
|
* \author John Levon
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
* \author J<EFBFBD>rgen Vigna
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
2001-03-06 14:07:14 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "ParagraphParameters.h"
|
2003-03-12 06:53:49 +00:00
|
|
|
|
|
2003-03-13 13:56:25 +00:00
|
|
|
|
#include "buffer.h"
|
|
|
|
|
#include "BufferView.h"
|
|
|
|
|
#include "gettext.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
#include "lyxlayout.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "lyxlex.h"
|
2003-03-13 13:56:25 +00:00
|
|
|
|
#include "lyxtext.h"
|
2003-09-06 17:23:08 +00:00
|
|
|
|
#include "paragraph.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "tex-strings.h"
|
2003-05-13 09:48:57 +00:00
|
|
|
|
|
2003-03-13 13:56:25 +00:00
|
|
|
|
#include "frontends/LyXView.h"
|
|
|
|
|
|
2003-03-12 07:39:17 +00:00
|
|
|
|
#include "support/lstrings.h"
|
2004-07-24 10:55:30 +00:00
|
|
|
|
|
|
|
|
|
#include <sstream>
|
2003-03-12 06:53:49 +00:00
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::rtrim;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::istringstream;
|
2003-03-12 06:53:49 +00:00
|
|
|
|
using std::ostream;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::ostringstream;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
|
2001-03-06 14:07:14 +00:00
|
|
|
|
|
|
|
|
|
ParagraphParameters::ParagraphParameters()
|
2004-03-25 09:16:36 +00:00
|
|
|
|
: noindent_(false),
|
|
|
|
|
start_of_appendix_(false), appendix_(false),
|
|
|
|
|
align_(LYX_ALIGN_LAYOUT), depth_(0)
|
|
|
|
|
{}
|
2001-03-06 14:07:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ParagraphParameters::clear()
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
operator=(ParagraphParameters());
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-09-06 20:32:37 +00:00
|
|
|
|
ParagraphParameters::depth_type ParagraphParameters::depth() const
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return depth_;
|
2003-09-06 20:32:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-03-06 14:07:14 +00:00
|
|
|
|
bool ParagraphParameters::sameLayout(ParagraphParameters const & pp) const
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return align_ == pp.align_
|
|
|
|
|
&& spacing_ == pp.spacing_
|
|
|
|
|
&& noindent_ == pp.noindent_
|
|
|
|
|
&& depth_ == pp.depth_;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Spacing const & ParagraphParameters::spacing() const
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return spacing_;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ParagraphParameters::spacing(Spacing const & s)
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
spacing_ = s;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ParagraphParameters::noindent() const
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return noindent_;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ParagraphParameters::noindent(bool ni)
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
noindent_ = ni;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LyXAlignment ParagraphParameters::align() const
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return align_;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ParagraphParameters::align(LyXAlignment la)
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
align_ = la;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void ParagraphParameters::depth(depth_type d)
|
2001-03-06 14:07:14 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
depth_ = d;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ParagraphParameters::startOfAppendix() const
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return start_of_appendix_;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ParagraphParameters::startOfAppendix(bool soa)
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
start_of_appendix_ = soa;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ParagraphParameters::appendix() const
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return appendix_;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ParagraphParameters::appendix(bool a)
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
appendix_ = a;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const & ParagraphParameters::labelString() const
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return labelstring_;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ParagraphParameters::labelString(string const & ls)
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
labelstring_ = ls;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const & ParagraphParameters::labelWidthString() const
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return labelwidthstring_;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ParagraphParameters::labelWidthString(string const & lws)
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
labelwidthstring_ = lws;
|
2001-03-06 14:07:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-05-08 12:58:16 +00:00
|
|
|
|
|
|
|
|
|
LyXLength const & ParagraphParameters::leftIndent() const
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return leftindent_;
|
2002-05-08 12:58:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ParagraphParameters::leftIndent(LyXLength const & li)
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
leftindent_ = li;
|
2002-05-08 12:58:16 +00:00
|
|
|
|
}
|
2003-03-12 06:53:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ParagraphParameters::read(LyXLex & lex)
|
|
|
|
|
{
|
2003-03-12 07:39:17 +00:00
|
|
|
|
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 == "\\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;
|
2003-03-12 11:22:53 +00:00
|
|
|
|
align(LyXAlignment(1 << tmpret));
|
2003-03-12 07:39:17 +00:00
|
|
|
|
} else if (token == "\\labelwidthstring") {
|
|
|
|
|
lex.eatLine();
|
|
|
|
|
labelWidthString(lex.getString());
|
|
|
|
|
} else {
|
|
|
|
|
lex.pushToken(token);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-03-12 06:53:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ParagraphParameters::write(ostream & os) const
|
|
|
|
|
{
|
|
|
|
|
// Maybe the paragraph has special spacing
|
|
|
|
|
spacing().writeFile(os, true);
|
|
|
|
|
|
|
|
|
|
// The labelwidth string used in lists.
|
|
|
|
|
if (!labelWidthString().empty())
|
|
|
|
|
os << "\\labelwidthstring "
|
|
|
|
|
<< labelWidthString() << '\n';
|
|
|
|
|
|
|
|
|
|
// 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] << ' ';
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-03-13 13:56:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void params2string(Paragraph const & par, string & data)
|
|
|
|
|
{
|
|
|
|
|
// A local copy
|
|
|
|
|
ParagraphParameters params = par.params();
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
|
|
// Is alignment possible
|
|
|
|
|
os << '\n' << "\\alignpossible " << layout->alignpossible << '\n';
|
|
|
|
|
|
|
|
|
|
/// set default alignment
|
|
|
|
|
os << "\\aligndefault " << layout->align << '\n';
|
|
|
|
|
|
2004-04-08 15:03:33 +00:00
|
|
|
|
/// paragraph is always in inset. This is redundant.
|
|
|
|
|
os << "\\ininset " << 1 << '\n';
|
2003-03-13 13:56:25 +00:00
|
|
|
|
|
2003-09-15 11:00:00 +00:00
|
|
|
|
data = os.str();
|
2003-03-13 13:56:25 +00:00
|
|
|
|
}
|
2004-03-25 09:16:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
bool operator==(ParagraphParameeters const & ps1,
|
|
|
|
|
ParagraphParameeters const & ps2)
|
|
|
|
|
{
|
|
|
|
|
return
|
|
|
|
|
ps1.spacing == ps2.spacing
|
|
|
|
|
&& ps1.noindent == ps2.noindent
|
|
|
|
|
&& ps1.align == ps2.align
|
|
|
|
|
&& ps1.depth == ps2.depth
|
|
|
|
|
&& ps1.start_of_appendix == ps2.start_of_appendix
|
|
|
|
|
&& ps1.appendix == ps2.appendix
|
|
|
|
|
&& ps1.labelstring == ps2.labelstring
|
|
|
|
|
&& ps1.labelwidthstring == ps2.labelwidthstring
|
|
|
|
|
&& ps1.leftindent == ps2.leftindent;
|
|
|
|
|
}
|
|
|
|
|
*/
|