2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
2003-10-08 11:31:51 +00:00
|
|
|
|
* \file src/text.C
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Asger Alstrup
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
|
* \author John Levon
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
* \author Dekel Tsur
|
|
|
|
|
* \author J<EFBFBD>rgen Vigna
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2001-04-17 15:15:59 +00:00
|
|
|
|
#include "lyxtext.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
|
2004-02-13 07:30:59 +00:00
|
|
|
|
#include "author.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "buffer.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
#include "bufferparams.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
#include "BufferView.h"
|
2004-01-13 15:25:52 +00:00
|
|
|
|
#include "cursor.h"
|
2004-03-25 09:16:36 +00:00
|
|
|
|
#include "CutAndPaste.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
|
#include "debug.h"
|
2003-10-29 10:47:21 +00:00
|
|
|
|
#include "dispatchresult.h"
|
2002-05-24 14:34:32 +00:00
|
|
|
|
#include "encoding.h"
|
2004-03-25 09:16:36 +00:00
|
|
|
|
#include "errorlist.h"
|
2003-09-04 03:54:04 +00:00
|
|
|
|
#include "funcrequest.h"
|
2004-03-25 09:16:36 +00:00
|
|
|
|
#include "factory.h"
|
2004-03-01 10:46:58 +00:00
|
|
|
|
#include "FontIterator.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
#include "gettext.h"
|
2001-04-05 12:26:41 +00:00
|
|
|
|
#include "language.h"
|
2003-09-16 10:30:59 +00:00
|
|
|
|
#include "LColor.h"
|
2003-09-09 17:00:19 +00:00
|
|
|
|
#include "lyxlength.h"
|
2003-12-03 15:27:16 +00:00
|
|
|
|
#include "lyxlex.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
#include "lyxrc.h"
|
|
|
|
|
#include "lyxrow.h"
|
|
|
|
|
#include "lyxrow_funcs.h"
|
2003-10-17 10:31:47 +00:00
|
|
|
|
#include "metricsinfo.h"
|
2003-09-16 12:12:33 +00:00
|
|
|
|
#include "paragraph.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
#include "paragraph_funcs.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "ParagraphParameters.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
#include "rowpainter.h"
|
2003-10-14 13:01:49 +00:00
|
|
|
|
#include "undo.h"
|
2003-09-09 17:00:19 +00:00
|
|
|
|
#include "vspace.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
|
#include "WordLangTuple.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
|
|
|
|
|
#include "frontends/font_metrics.h"
|
|
|
|
|
#include "frontends/LyXView.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-11-15 00:39:11 +00:00
|
|
|
|
#include "insets/insettext.h"
|
2004-03-25 09:16:36 +00:00
|
|
|
|
#include "insets/insetbibitem.h"
|
|
|
|
|
#include "insets/insethfill.h"
|
|
|
|
|
#include "insets/insetlatexaccent.h"
|
|
|
|
|
#include "insets/insetline.h"
|
|
|
|
|
#include "insets/insetnewline.h"
|
|
|
|
|
#include "insets/insetpagebreak.h"
|
|
|
|
|
#include "insets/insetoptarg.h"
|
|
|
|
|
#include "insets/insetspace.h"
|
|
|
|
|
#include "insets/insetspecialchar.h"
|
|
|
|
|
#include "insets/insettabular.h"
|
2001-11-15 00:39:11 +00:00
|
|
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
#include "support/textutils.h"
|
2004-02-13 07:30:59 +00:00
|
|
|
|
#include "support/tostr.h"
|
2004-07-24 10:55:30 +00:00
|
|
|
|
|
|
|
|
|
#include <sstream>
|
2001-11-15 00:39:11 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
using lyx::par_type;
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::pos_type;
|
|
|
|
|
using lyx::word_location;
|
|
|
|
|
|
2004-02-13 07:30:59 +00:00
|
|
|
|
using lyx::support::bformat;
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::contains;
|
|
|
|
|
using lyx::support::lowercase;
|
2004-02-13 13:51:12 +00:00
|
|
|
|
using lyx::support::split;
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::uppercase;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
using lyx::cap::cutSelection;
|
|
|
|
|
|
|
|
|
|
using std::auto_ptr;
|
2004-01-28 16:21:29 +00:00
|
|
|
|
using std::advance;
|
|
|
|
|
using std::distance;
|
2000-01-14 18:41:30 +00:00
|
|
|
|
using std::max;
|
2004-02-13 13:51:12 +00:00
|
|
|
|
using std::min;
|
2000-03-28 02:18:55 +00:00
|
|
|
|
using std::endl;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-07-01 11:51:20 +00:00
|
|
|
|
|
2000-01-14 18:41:30 +00:00
|
|
|
|
|
2003-10-23 09:06:18 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
2004-02-13 13:51:12 +00:00
|
|
|
|
int numberOfSeparators(Paragraph const & par, Row const & row)
|
|
|
|
|
{
|
|
|
|
|
pos_type const first = max(row.pos(), par.beginOfBody());
|
|
|
|
|
pos_type const last = row.endpos() - 1;
|
|
|
|
|
int n = 0;
|
|
|
|
|
for (pos_type p = first; p < last; ++p) {
|
|
|
|
|
if (par.isSeparator(p))
|
|
|
|
|
++n;
|
|
|
|
|
}
|
|
|
|
|
return n;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-23 09:06:18 +00:00
|
|
|
|
unsigned int maxParagraphWidth(ParagraphList const & plist)
|
|
|
|
|
{
|
|
|
|
|
unsigned int width = 0;
|
|
|
|
|
ParagraphList::const_iterator pit = plist.begin();
|
|
|
|
|
ParagraphList::const_iterator end = plist.end();
|
|
|
|
|
for (; pit != end; ++pit)
|
|
|
|
|
width = std::max(width, pit->width);
|
|
|
|
|
return width;
|
|
|
|
|
}
|
|
|
|
|
|
2004-02-13 13:51:12 +00:00
|
|
|
|
|
|
|
|
|
int numberOfLabelHfills(Paragraph const & par, Row const & row)
|
|
|
|
|
{
|
|
|
|
|
pos_type last = row.endpos() - 1;
|
|
|
|
|
pos_type first = row.pos();
|
|
|
|
|
|
|
|
|
|
// hfill *DO* count at the beginning of paragraphs!
|
|
|
|
|
if (first) {
|
|
|
|
|
while (first < last && par.isHfill(first))
|
|
|
|
|
++first;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
last = min(last, par.beginOfBody());
|
|
|
|
|
int n = 0;
|
|
|
|
|
for (pos_type p = first; p < last; ++p) {
|
|
|
|
|
if (par.isHfill(p))
|
|
|
|
|
++n;
|
|
|
|
|
}
|
|
|
|
|
return n;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int numberOfHfills(Paragraph const & par, Row const & row)
|
|
|
|
|
{
|
|
|
|
|
pos_type const last = row.endpos() - 1;
|
|
|
|
|
pos_type first = row.pos();
|
|
|
|
|
|
|
|
|
|
// hfill *DO* count at the beginning of paragraphs!
|
|
|
|
|
if (first) {
|
|
|
|
|
while (first < last && par.isHfill(first))
|
|
|
|
|
++first;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
first = max(first, par.beginOfBody());
|
|
|
|
|
|
|
|
|
|
int n = 0;
|
|
|
|
|
for (pos_type p = first; p < last; ++p) {
|
|
|
|
|
if (par.isHfill(p))
|
|
|
|
|
++n;
|
|
|
|
|
}
|
|
|
|
|
return n;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
|
|
|
|
|
int readParToken(Buffer const & buf, Paragraph & par, LyXLex & lex,
|
|
|
|
|
string const & token)
|
|
|
|
|
{
|
|
|
|
|
static LyXFont font;
|
|
|
|
|
static Change change;
|
|
|
|
|
|
|
|
|
|
BufferParams const & bp = buf.params();
|
|
|
|
|
|
|
|
|
|
if (token[0] != '\\') {
|
|
|
|
|
string::const_iterator cit = token.begin();
|
|
|
|
|
for (; cit != token.end(); ++cit) {
|
|
|
|
|
par.insertChar(par.size(), (*cit), font, change);
|
|
|
|
|
}
|
|
|
|
|
} else if (token == "\\begin_layout") {
|
|
|
|
|
lex.eatLine();
|
|
|
|
|
string layoutname = lex.getString();
|
|
|
|
|
|
|
|
|
|
font = LyXFont(LyXFont::ALL_INHERIT, bp.language);
|
|
|
|
|
change = Change();
|
|
|
|
|
|
|
|
|
|
LyXTextClass const & tclass = bp.getLyXTextClass();
|
|
|
|
|
|
|
|
|
|
if (layoutname.empty()) {
|
|
|
|
|
layoutname = tclass.defaultLayoutName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool hasLayout = tclass.hasLayout(layoutname);
|
|
|
|
|
|
|
|
|
|
if (!hasLayout) {
|
|
|
|
|
lyxerr << "Layout '" << layoutname << "' does not"
|
|
|
|
|
<< " exist in textclass '" << tclass.name()
|
|
|
|
|
<< "'." << endl;
|
|
|
|
|
lyxerr << "Trying to use default layout instead."
|
|
|
|
|
<< endl;
|
|
|
|
|
layoutname = tclass.defaultLayoutName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
par.layout(bp.getLyXTextClass()[layoutname]);
|
|
|
|
|
|
|
|
|
|
// Test whether the layout is obsolete.
|
|
|
|
|
LyXLayout_ptr const & layout = par.layout();
|
|
|
|
|
if (!layout->obsoleted_by().empty())
|
|
|
|
|
par.layout(bp.getLyXTextClass()[layout->obsoleted_by()]);
|
|
|
|
|
|
|
|
|
|
par.params().read(lex);
|
|
|
|
|
|
|
|
|
|
} else if (token == "\\end_layout") {
|
|
|
|
|
lyxerr << "Solitary \\end_layout in line " << lex.getLineNo() << "\n"
|
|
|
|
|
<< "Missing \\begin_layout?.\n";
|
|
|
|
|
} else if (token == "\\end_inset") {
|
|
|
|
|
lyxerr << "Solitary \\end_inset in line " << lex.getLineNo() << "\n"
|
|
|
|
|
<< "Missing \\begin_inset?.\n";
|
|
|
|
|
} else if (token == "\\begin_inset") {
|
|
|
|
|
InsetBase * inset = readInset(lex, buf);
|
|
|
|
|
if (inset)
|
|
|
|
|
par.insertInset(par.size(), inset, font, change);
|
|
|
|
|
else {
|
|
|
|
|
lex.eatLine();
|
|
|
|
|
string line = lex.getString();
|
|
|
|
|
buf.error(ErrorItem(_("Unknown Inset"), line,
|
|
|
|
|
par.id(), 0, par.size()));
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
} else if (token == "\\family") {
|
|
|
|
|
lex.next();
|
|
|
|
|
font.setLyXFamily(lex.getString());
|
|
|
|
|
} else if (token == "\\series") {
|
|
|
|
|
lex.next();
|
|
|
|
|
font.setLyXSeries(lex.getString());
|
|
|
|
|
} else if (token == "\\shape") {
|
|
|
|
|
lex.next();
|
|
|
|
|
font.setLyXShape(lex.getString());
|
|
|
|
|
} else if (token == "\\size") {
|
|
|
|
|
lex.next();
|
|
|
|
|
font.setLyXSize(lex.getString());
|
|
|
|
|
} else if (token == "\\lang") {
|
|
|
|
|
lex.next();
|
|
|
|
|
string const tok = lex.getString();
|
|
|
|
|
Language const * lang = languages.getLanguage(tok);
|
|
|
|
|
if (lang) {
|
|
|
|
|
font.setLanguage(lang);
|
|
|
|
|
} else {
|
|
|
|
|
font.setLanguage(bp.language);
|
|
|
|
|
lex.printError("Unknown language `$$Token'");
|
|
|
|
|
}
|
|
|
|
|
} else if (token == "\\numeric") {
|
|
|
|
|
lex.next();
|
|
|
|
|
font.setNumber(font.setLyXMisc(lex.getString()));
|
|
|
|
|
} else if (token == "\\emph") {
|
|
|
|
|
lex.next();
|
|
|
|
|
font.setEmph(font.setLyXMisc(lex.getString()));
|
|
|
|
|
} else if (token == "\\bar") {
|
|
|
|
|
lex.next();
|
|
|
|
|
string const tok = lex.getString();
|
|
|
|
|
|
|
|
|
|
if (tok == "under")
|
|
|
|
|
font.setUnderbar(LyXFont::ON);
|
|
|
|
|
else if (tok == "no")
|
|
|
|
|
font.setUnderbar(LyXFont::OFF);
|
|
|
|
|
else if (tok == "default")
|
|
|
|
|
font.setUnderbar(LyXFont::INHERIT);
|
|
|
|
|
else
|
|
|
|
|
lex.printError("Unknown bar font flag "
|
|
|
|
|
"`$$Token'");
|
|
|
|
|
} else if (token == "\\noun") {
|
|
|
|
|
lex.next();
|
|
|
|
|
font.setNoun(font.setLyXMisc(lex.getString()));
|
|
|
|
|
} else if (token == "\\color") {
|
|
|
|
|
lex.next();
|
|
|
|
|
font.setLyXColor(lex.getString());
|
|
|
|
|
} else if (token == "\\InsetSpace" || token == "\\SpecialChar") {
|
|
|
|
|
|
|
|
|
|
// Insets don't make sense in a free-spacing context! ---Kayvan
|
|
|
|
|
if (par.isFreeSpacing()) {
|
|
|
|
|
if (token == "\\InsetSpace")
|
|
|
|
|
par.insertChar(par.size(), ' ', font, change);
|
|
|
|
|
else if (lex.isOK()) {
|
|
|
|
|
lex.next();
|
|
|
|
|
string const next_token = lex.getString();
|
|
|
|
|
if (next_token == "\\-")
|
|
|
|
|
par.insertChar(par.size(), '-', font, change);
|
|
|
|
|
else {
|
|
|
|
|
lex.printError("Token `$$Token' "
|
|
|
|
|
"is in free space "
|
|
|
|
|
"paragraph layout!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
auto_ptr<InsetBase> inset;
|
|
|
|
|
if (token == "\\SpecialChar" )
|
|
|
|
|
inset.reset(new InsetSpecialChar);
|
|
|
|
|
else
|
|
|
|
|
inset.reset(new InsetSpace);
|
|
|
|
|
inset->read(buf, lex);
|
|
|
|
|
par.insertInset(par.size(), inset.release(),
|
|
|
|
|
font, change);
|
|
|
|
|
}
|
|
|
|
|
} else if (token == "\\i") {
|
|
|
|
|
auto_ptr<InsetBase> inset(new InsetLatexAccent);
|
|
|
|
|
inset->read(buf, lex);
|
|
|
|
|
par.insertInset(par.size(), inset.release(), font, change);
|
|
|
|
|
} else if (token == "\\backslash") {
|
|
|
|
|
par.insertChar(par.size(), '\\', font, change);
|
|
|
|
|
} else if (token == "\\newline") {
|
|
|
|
|
auto_ptr<InsetBase> inset(new InsetNewline);
|
|
|
|
|
inset->read(buf, lex);
|
|
|
|
|
par.insertInset(par.size(), inset.release(), font, change);
|
|
|
|
|
} else if (token == "\\LyXTable") {
|
|
|
|
|
auto_ptr<InsetBase> inset(new InsetTabular(buf));
|
|
|
|
|
inset->read(buf, lex);
|
|
|
|
|
par.insertInset(par.size(), inset.release(), font, change);
|
|
|
|
|
} else if (token == "\\bibitem") {
|
|
|
|
|
InsetCommandParams p("bibitem", "dummy");
|
|
|
|
|
auto_ptr<InsetBibitem> inset(new InsetBibitem(p));
|
|
|
|
|
inset->read(buf, lex);
|
|
|
|
|
par.insertInset(par.size(), inset.release(), font, change);
|
|
|
|
|
} else if (token == "\\hfill") {
|
|
|
|
|
par.insertInset(par.size(), new InsetHFill, font, change);
|
|
|
|
|
} else if (token == "\\lyxline") {
|
|
|
|
|
par.insertInset(par.size(), new InsetLine, font, change);
|
|
|
|
|
} else if (token == "\\newpage") {
|
|
|
|
|
par.insertInset(par.size(), new InsetPagebreak, font, change);
|
|
|
|
|
} else if (token == "\\change_unchanged") {
|
|
|
|
|
// Hack ! Needed for empty paragraphs :/
|
|
|
|
|
// FIXME: is it still ??
|
|
|
|
|
if (!par.size())
|
|
|
|
|
par.cleanChanges();
|
|
|
|
|
change = Change(Change::UNCHANGED);
|
|
|
|
|
} else if (token == "\\change_inserted") {
|
|
|
|
|
lex.nextToken();
|
|
|
|
|
std::istringstream is(lex.getString());
|
|
|
|
|
int aid;
|
|
|
|
|
lyx::time_type ct;
|
|
|
|
|
is >> aid >> ct;
|
|
|
|
|
change = Change(Change::INSERTED, bp.author_map[aid], ct);
|
|
|
|
|
} else if (token == "\\change_deleted") {
|
|
|
|
|
lex.nextToken();
|
|
|
|
|
std::istringstream is(lex.getString());
|
|
|
|
|
int aid;
|
|
|
|
|
lyx::time_type ct;
|
|
|
|
|
is >> aid >> ct;
|
|
|
|
|
change = Change(Change::DELETED, bp.author_map[aid], ct);
|
|
|
|
|
} else {
|
|
|
|
|
lex.eatLine();
|
|
|
|
|
buf.error(ErrorItem(_("Unknown token"),
|
|
|
|
|
bformat(_("Unknown token: %1$s %2$s\n"), token, lex.getString()),
|
|
|
|
|
par.id(), 0, par.size()));
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int readParagraph(Buffer const & buf, Paragraph & par, LyXLex & lex)
|
|
|
|
|
{
|
|
|
|
|
int unknown = 0;
|
|
|
|
|
|
|
|
|
|
lex.nextToken();
|
|
|
|
|
string token = lex.getString();
|
|
|
|
|
|
|
|
|
|
while (lex.isOK()) {
|
|
|
|
|
|
|
|
|
|
unknown += readParToken(buf, par, lex, token);
|
|
|
|
|
|
|
|
|
|
lex.nextToken();
|
|
|
|
|
token = lex.getString();
|
|
|
|
|
|
|
|
|
|
if (token.empty())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (token == "\\end_layout") {
|
|
|
|
|
//Ok, paragraph finished
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lyxerr[Debug::PARSER] << "Handling paragraph token: `"
|
|
|
|
|
<< token << '\'' << endl;
|
|
|
|
|
if (token == "\\begin_layout" || token == "\\end_document"
|
|
|
|
|
|| token == "\\end_inset" || token == "\\begin_deeper"
|
|
|
|
|
|| token == "\\end_deeper") {
|
|
|
|
|
lex.pushToken(token);
|
|
|
|
|
lyxerr << "Paragraph ended in line "
|
|
|
|
|
<< lex.getLineNo() << "\n"
|
|
|
|
|
<< "Missing \\end_layout.\n";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return unknown;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-23 09:06:18 +00:00
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
BufferView * LyXText::bv()
|
|
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(bv_owner != 0);
|
2003-03-17 16:25:00 +00:00
|
|
|
|
return bv_owner;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-04-08 15:03:33 +00:00
|
|
|
|
BufferView * LyXText::bv() const
|
2003-10-28 11:18:40 +00:00
|
|
|
|
{
|
2004-04-08 15:03:33 +00:00
|
|
|
|
BOOST_ASSERT(bv_owner != 0);
|
|
|
|
|
return bv_owner;
|
2003-10-28 11:18:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-04-08 15:03:33 +00:00
|
|
|
|
double LyXText::spacing(Paragraph const & par) const
|
2003-03-17 16:25:00 +00:00
|
|
|
|
{
|
2004-04-08 15:03:33 +00:00
|
|
|
|
if (par.params().spacing().isDefault())
|
|
|
|
|
return bv()->buffer()->params().spacing().getValue();
|
|
|
|
|
return par.params().spacing().getValue();
|
2003-03-17 16:25:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-25 11:17:27 +00:00
|
|
|
|
void LyXText::updateParPositions()
|
2003-03-06 20:21:21 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
par_type pit = 0;
|
|
|
|
|
par_type end = pars_.size();
|
2004-03-01 16:29:30 +00:00
|
|
|
|
for (height_ = 0; pit != end; ++pit) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pars_[pit].y = height_;
|
|
|
|
|
height_ += pars_[pit].height;
|
2003-03-06 20:21:21 +00:00
|
|
|
|
}
|
2003-04-12 23:03:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-01 16:29:30 +00:00
|
|
|
|
int LyXText::width() const
|
2000-06-12 11:27:15 +00:00
|
|
|
|
{
|
2004-03-01 16:29:30 +00:00
|
|
|
|
return width_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int LyXText::height() const
|
|
|
|
|
{
|
|
|
|
|
return height_;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-10 21:40:13 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
int LyXText::singleWidth(par_type par, pos_type pos) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (pos >= pars_[par].size())
|
2003-03-13 10:30:28 +00:00
|
|
|
|
return 0;
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
char const c = pars_[par].getChar(pos);
|
|
|
|
|
return singleWidth(par, pos, c, getFont(par, pos));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
int LyXText::singleWidth(par_type pit,
|
2003-08-22 07:49:57 +00:00
|
|
|
|
pos_type pos, char c, LyXFont const & font) const
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (pos >= pars_[pit].size()) {
|
2003-08-22 07:49:57 +00:00
|
|
|
|
lyxerr << "in singleWidth(), pos: " << pos << endl;
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(false);
|
2003-03-13 10:30:28 +00:00
|
|
|
|
return 0;
|
2003-08-22 07:49:57 +00:00
|
|
|
|
}
|
2003-03-13 10:30:28 +00:00
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
|
// The most common case is handled first (Asger)
|
|
|
|
|
if (IsPrintable(c)) {
|
2003-10-21 16:15:14 +00:00
|
|
|
|
if (!font.language()->RightToLeft()) {
|
2003-07-27 00:37:17 +00:00
|
|
|
|
if ((lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
|
|
|
|
|
lyxrc.font_norm_type == LyXRC::ISO_10646_1)
|
|
|
|
|
&& font.language()->lang() == "arabic") {
|
2000-10-10 12:36:36 +00:00
|
|
|
|
if (Encodings::IsComposeChar_arabic(c))
|
2000-07-04 20:32:37 +00:00
|
|
|
|
return 0;
|
|
|
|
|
else
|
2004-03-25 09:16:36 +00:00
|
|
|
|
c = pars_[pit].transformChar(c, pos);
|
2003-03-11 15:01:29 +00:00
|
|
|
|
} else if (font.language()->lang() == "hebrew" &&
|
2000-10-10 12:36:36 +00:00
|
|
|
|
Encodings::IsComposeChar_hebrew(c))
|
2000-05-05 10:17:05 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2002-05-24 14:34:32 +00:00
|
|
|
|
return font_metrics::width(c, font);
|
2003-03-11 15:01:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-10-29 10:47:21 +00:00
|
|
|
|
if (c == Paragraph::META_INSET)
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return pars_[pit].getInset(pos)->width();
|
2000-02-10 17:53:36 +00:00
|
|
|
|
|
2003-03-11 15:01:29 +00:00
|
|
|
|
if (IsSeparatorChar(c))
|
2000-02-10 17:53:36 +00:00
|
|
|
|
c = ' ';
|
2002-05-24 14:34:32 +00:00
|
|
|
|
return font_metrics::width(c, font);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
int LyXText::leftMargin(par_type pit) const
|
2003-11-25 11:17:27 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return leftMargin(pit, pars_[pit].size());
|
2003-11-25 11:17:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
int LyXText::leftMargin(par_type pit, pos_type pos) const
|
2003-08-26 10:33:59 +00:00
|
|
|
|
{
|
2001-10-16 14:47:10 +00:00
|
|
|
|
LyXTextClass const & tclass =
|
2003-09-09 09:47:59 +00:00
|
|
|
|
bv()->buffer()->params().getLyXTextClass();
|
2004-03-25 09:16:36 +00:00
|
|
|
|
LyXLayout_ptr const & layout = pars_[pit].layout();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
string parindent = layout->parindent;
|
2000-06-08 23:16:16 +00:00
|
|
|
|
|
2004-08-14 15:55:22 +00:00
|
|
|
|
int l_margin = 0;
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2004-08-14 15:55:22 +00:00
|
|
|
|
if (xo_ == 0)
|
|
|
|
|
l_margin += changebarMargin();
|
2001-05-03 14:31:33 +00:00
|
|
|
|
|
2004-08-14 15:55:22 +00:00
|
|
|
|
l_margin += font_metrics::signedWidth(tclass.leftmargin(), tclass.defaultfont());
|
|
|
|
|
|
|
|
|
|
if (pars_[pit].getDepth() != 0) {
|
|
|
|
|
// find the next level paragraph
|
|
|
|
|
par_type newpar = outerHook(pit, pars_);
|
|
|
|
|
if (newpar != par_type(pars_.size())) {
|
|
|
|
|
if (pars_[newpar].layout()->isEnvironment()) {
|
|
|
|
|
l_margin = leftMargin(newpar);
|
|
|
|
|
}
|
|
|
|
|
if (pars_[pit].layout() == tclass.defaultLayout()) {
|
|
|
|
|
if (pars_[newpar].params().noindent())
|
2000-05-04 10:57:00 +00:00
|
|
|
|
parindent.erase();
|
2004-08-14 15:55:22 +00:00
|
|
|
|
else
|
|
|
|
|
parindent = pars_[newpar].layout()->parindent;
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-08-14 08:34:13 +00:00
|
|
|
|
LyXFont const labelfont = getLabelFont(pit);
|
2002-06-24 20:28:12 +00:00
|
|
|
|
switch (layout->margintype) {
|
2000-01-13 16:28:54 +00:00
|
|
|
|
case MARGIN_DYNAMIC:
|
2003-10-28 11:18:40 +00:00
|
|
|
|
if (!layout->leftmargin.empty())
|
2004-08-14 15:55:22 +00:00
|
|
|
|
l_margin += font_metrics::signedWidth(layout->leftmargin,
|
2001-10-16 14:47:10 +00:00
|
|
|
|
tclass.defaultfont());
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (!pars_[pit].getLabelstring().empty()) {
|
2004-08-14 15:55:22 +00:00
|
|
|
|
l_margin += font_metrics::signedWidth(layout->labelindent,
|
2000-04-04 00:19:15 +00:00
|
|
|
|
labelfont);
|
2004-08-14 15:55:22 +00:00
|
|
|
|
l_margin += font_metrics::width(pars_[pit].getLabelstring(),
|
2000-06-08 23:16:16 +00:00
|
|
|
|
labelfont);
|
2004-08-14 15:55:22 +00:00
|
|
|
|
l_margin += font_metrics::width(layout->labelsep, labelfont);
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
case MARGIN_MANUAL:
|
2004-08-14 15:55:22 +00:00
|
|
|
|
l_margin += font_metrics::signedWidth(layout->labelindent, labelfont);
|
2003-03-08 19:31:09 +00:00
|
|
|
|
// The width of an empty par, even with manual label, should be 0
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (!pars_[pit].empty() && pos >= pars_[pit].beginOfBody()) {
|
|
|
|
|
if (!pars_[pit].getLabelWidthString().empty()) {
|
2004-08-14 15:55:22 +00:00
|
|
|
|
l_margin += font_metrics::width(pars_[pit].getLabelWidthString(),
|
2000-04-04 00:19:15 +00:00
|
|
|
|
labelfont);
|
2004-08-14 15:55:22 +00:00
|
|
|
|
l_margin += font_metrics::width(layout->labelsep, labelfont);
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
case MARGIN_STATIC:
|
2004-08-14 15:55:22 +00:00
|
|
|
|
l_margin += font_metrics::signedWidth(layout->leftmargin, tclass.defaultfont()) * 4
|
2004-03-25 09:16:36 +00:00
|
|
|
|
/ (pars_[pit].getDepth() + 4);
|
2000-01-13 16:28:54 +00:00
|
|
|
|
break;
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
case MARGIN_FIRST_DYNAMIC:
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (layout->labeltype == LABEL_MANUAL) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (pos >= pars_[pit].beginOfBody()) {
|
2004-08-14 15:55:22 +00:00
|
|
|
|
l_margin += font_metrics::signedWidth(layout->leftmargin,
|
2000-06-08 23:16:16 +00:00
|
|
|
|
labelfont);
|
2000-01-13 16:28:54 +00:00
|
|
|
|
} else {
|
2004-08-14 15:55:22 +00:00
|
|
|
|
l_margin += font_metrics::signedWidth(layout->labelindent,
|
2000-06-08 23:16:16 +00:00
|
|
|
|
labelfont);
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2003-11-25 11:17:27 +00:00
|
|
|
|
} else if (pos != 0
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// Special case to fix problems with
|
|
|
|
|
// theorems (JMarc)
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|| (layout->labeltype == LABEL_STATIC
|
|
|
|
|
&& layout->latextype == LATEX_ENVIRONMENT
|
2004-08-14 15:55:22 +00:00
|
|
|
|
&& !isFirstInSequence(pit, pars_))) {
|
|
|
|
|
l_margin += font_metrics::signedWidth(layout->leftmargin,
|
2000-06-08 23:16:16 +00:00
|
|
|
|
labelfont);
|
2002-06-24 20:28:12 +00:00
|
|
|
|
} else if (layout->labeltype != LABEL_TOP_ENVIRONMENT
|
|
|
|
|
&& layout->labeltype != LABEL_BIBLIO
|
|
|
|
|
&& layout->labeltype !=
|
2000-01-13 16:28:54 +00:00
|
|
|
|
LABEL_CENTERED_TOP_ENVIRONMENT) {
|
2004-08-14 15:55:22 +00:00
|
|
|
|
l_margin += font_metrics::signedWidth(layout->labelindent,
|
2000-04-04 00:19:15 +00:00
|
|
|
|
labelfont);
|
2004-08-14 15:55:22 +00:00
|
|
|
|
l_margin += font_metrics::width(layout->labelsep, labelfont);
|
|
|
|
|
l_margin += font_metrics::width(pars_[pit].getLabelstring(),
|
2000-06-08 23:16:16 +00:00
|
|
|
|
labelfont);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
}
|
2000-01-13 16:28:54 +00:00
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-28 11:18:40 +00:00
|
|
|
|
case MARGIN_RIGHT_ADDRESS_BOX: {
|
2003-12-02 07:15:42 +00:00
|
|
|
|
#if 0
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// ok, a terrible hack. The left margin depends on the widest
|
2003-10-17 10:31:47 +00:00
|
|
|
|
// row in this paragraph.
|
2004-03-25 09:16:36 +00:00
|
|
|
|
RowList::iterator rit = pars_[pit].rows.begin();
|
|
|
|
|
RowList::iterator end = pars_[pit].rows.end();
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2003-10-24 08:33:52 +00:00
|
|
|
|
#warning This is wrong.
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#endif
|
2004-03-01 16:29:30 +00:00
|
|
|
|
int minfill = maxwidth_;
|
2003-08-14 09:59:05 +00:00
|
|
|
|
for ( ; rit != end; ++rit)
|
|
|
|
|
if (rit->fill() < minfill)
|
|
|
|
|
minfill = rit->fill();
|
2004-08-14 15:55:22 +00:00
|
|
|
|
l_margin += font_metrics::signedWidth(layout->leftmargin,
|
2002-05-24 14:34:32 +00:00
|
|
|
|
tclass.defaultfont());
|
2004-08-14 15:55:22 +00:00
|
|
|
|
l_margin += minfill;
|
2003-12-02 07:15:42 +00:00
|
|
|
|
#endif
|
|
|
|
|
// also wrong, but much shorter.
|
2004-08-14 15:55:22 +00:00
|
|
|
|
l_margin += maxwidth_ / 2;
|
2003-11-25 11:17:27 +00:00
|
|
|
|
break;
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2004-04-03 08:37:12 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (!pars_[pit].params().leftIndent().zero())
|
2004-08-14 15:55:22 +00:00
|
|
|
|
l_margin += pars_[pit].params().leftIndent().inPixels(maxwidth_);
|
2002-05-08 12:58:16 +00:00
|
|
|
|
|
2003-04-13 01:04:04 +00:00
|
|
|
|
LyXAlignment align;
|
2001-05-03 14:31:33 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (pars_[pit].params().align() == LYX_ALIGN_LAYOUT)
|
2002-06-24 20:28:12 +00:00
|
|
|
|
align = layout->align;
|
2000-07-19 17:16:27 +00:00
|
|
|
|
else
|
2004-03-25 09:16:36 +00:00
|
|
|
|
align = pars_[pit].params().align();
|
2001-05-03 14:31:33 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// set the correct parindent
|
2003-12-03 18:17:20 +00:00
|
|
|
|
if (pos == 0
|
|
|
|
|
&& (layout->labeltype == LABEL_NO_LABEL
|
|
|
|
|
|| layout->labeltype == LABEL_TOP_ENVIRONMENT
|
|
|
|
|
|| layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
|
|
|
|
|
|| (layout->labeltype == LABEL_STATIC
|
|
|
|
|
&& layout->latextype == LATEX_ENVIRONMENT
|
2004-08-14 15:55:22 +00:00
|
|
|
|
&& !isFirstInSequence(pit, pars_)))
|
2003-12-03 18:17:20 +00:00
|
|
|
|
&& align == LYX_ALIGN_BLOCK
|
2004-03-25 09:16:36 +00:00
|
|
|
|
&& !pars_[pit].params().noindent()
|
2003-12-03 18:17:20 +00:00
|
|
|
|
// in tabulars and ert paragraphs are never indented!
|
2004-08-14 15:55:22 +00:00
|
|
|
|
&& (pars_[pit].ownerCode() != InsetBase::TEXT_CODE
|
|
|
|
|
&& pars_[pit].ownerCode() != InsetBase::ERT_CODE)
|
2004-03-25 09:16:36 +00:00
|
|
|
|
&& (pars_[pit].layout() != tclass.defaultLayout()
|
2003-12-03 18:17:20 +00:00
|
|
|
|
|| bv()->buffer()->params().paragraph_separation ==
|
|
|
|
|
BufferParams::PARSEP_INDENT))
|
|
|
|
|
{
|
2004-08-14 15:55:22 +00:00
|
|
|
|
l_margin += font_metrics::signedWidth(parindent, tclass.defaultfont());
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-08-14 15:55:22 +00:00
|
|
|
|
return l_margin;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-04-26 13:57:28 +00:00
|
|
|
|
|
|
|
|
|
|
2003-11-25 11:17:27 +00:00
|
|
|
|
int LyXText::rightMargin(Paragraph const & par) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-11-25 11:17:27 +00:00
|
|
|
|
LyXTextClass const & tclass = bv()->buffer()->params().getLyXTextClass();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-08-14 15:55:22 +00:00
|
|
|
|
// We do not want rightmargins on inner texts.
|
|
|
|
|
if (bv()->text() != this)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
int const r_margin =
|
|
|
|
|
::rightMargin()
|
2002-05-24 14:34:32 +00:00
|
|
|
|
+ font_metrics::signedWidth(tclass.rightmargin(),
|
2004-08-14 15:55:22 +00:00
|
|
|
|
tclass.defaultfont())
|
2003-11-25 11:17:27 +00:00
|
|
|
|
+ font_metrics::signedWidth(par.layout()->rightmargin,
|
2004-08-14 15:55:22 +00:00
|
|
|
|
tclass.defaultfont())
|
2003-10-17 10:31:47 +00:00
|
|
|
|
* 4 / (par.getDepth() + 4);
|
2004-08-14 15:55:22 +00:00
|
|
|
|
|
|
|
|
|
return r_margin;
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
int LyXText::labelEnd(par_type pit) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-10-28 11:18:40 +00:00
|
|
|
|
// labelEnd is only needed if the layout fills a flushleft label.
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (pars_[pit].layout()->margintype != MARGIN_MANUAL)
|
2003-10-28 11:18:40 +00:00
|
|
|
|
return 0;
|
|
|
|
|
// return the beginning of the body
|
2003-11-25 11:17:27 +00:00
|
|
|
|
return leftMargin(pit);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-09 21:54:56 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
// this needs special handling - only newlines count as a break point
|
2003-04-13 01:04:04 +00:00
|
|
|
|
pos_type addressBreakPoint(pos_type i, Paragraph const & par)
|
2003-03-09 21:54:56 +00:00
|
|
|
|
{
|
2003-10-27 10:27:50 +00:00
|
|
|
|
pos_type const end = par.size();
|
2003-10-29 10:47:21 +00:00
|
|
|
|
|
2003-10-27 10:27:50 +00:00
|
|
|
|
for (; i < end; ++i)
|
2003-04-13 01:04:04 +00:00
|
|
|
|
if (par.isNewline(i))
|
2003-10-24 15:04:17 +00:00
|
|
|
|
return i + 1;
|
2003-03-09 21:54:56 +00:00
|
|
|
|
|
2003-10-27 10:27:50 +00:00
|
|
|
|
return end;
|
2003-03-09 21:54:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
void LyXText::rowBreakPoint(par_type pit, Row & row) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pos_type const end = pars_[pit].size();
|
2003-10-27 10:27:50 +00:00
|
|
|
|
pos_type const pos = row.pos();
|
|
|
|
|
if (pos == end) {
|
|
|
|
|
row.endpos(end);
|
2003-10-24 15:04:17 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2003-10-29 10:47:21 +00:00
|
|
|
|
|
2003-11-25 11:17:27 +00:00
|
|
|
|
// maximum pixel width of a row
|
2004-03-25 09:16:36 +00:00
|
|
|
|
int width = maxwidth_ - rightMargin(pars_[pit]); // - leftMargin(pit, row);
|
2003-10-23 15:38:48 +00:00
|
|
|
|
if (width < 0) {
|
2003-10-27 10:27:50 +00:00
|
|
|
|
row.endpos(end);
|
2003-10-23 15:38:48 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2000-09-23 04:57:18 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
LyXLayout_ptr const & layout = pars_[pit].layout();
|
2000-11-21 15:46:13 +00:00
|
|
|
|
|
2003-10-23 15:38:48 +00:00
|
|
|
|
if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
row.endpos(addressBreakPoint(pos, pars_[pit]));
|
2003-10-23 15:38:48 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pos_type const body_pos = pars_[pit].beginOfBody();
|
2003-03-13 10:30:28 +00:00
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-03-09 21:54:56 +00:00
|
|
|
|
// Now we iterate through until we reach the right margin
|
|
|
|
|
// or the end of the par, then choose the possible break
|
|
|
|
|
// nearest that.
|
|
|
|
|
|
2003-11-25 11:17:27 +00:00
|
|
|
|
int const left = leftMargin(pit, pos);
|
2003-03-10 04:59:48 +00:00
|
|
|
|
int x = left;
|
|
|
|
|
|
|
|
|
|
// pixel width since last breakpoint
|
|
|
|
|
int chunkwidth = 0;
|
2003-03-09 21:54:56 +00:00
|
|
|
|
|
2004-03-01 10:10:10 +00:00
|
|
|
|
FontIterator fi = FontIterator(*this, pit, pos);
|
2003-10-27 10:27:50 +00:00
|
|
|
|
pos_type point = end;
|
|
|
|
|
pos_type i = pos;
|
2004-03-01 10:10:10 +00:00
|
|
|
|
for ( ; i < end; ++i, ++fi) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
char const c = pars_[pit].getChar(i);
|
2003-10-29 10:47:21 +00:00
|
|
|
|
|
2003-10-27 10:27:50 +00:00
|
|
|
|
{
|
2004-03-01 10:10:10 +00:00
|
|
|
|
int thiswidth = singleWidth(pit, i, c, *fi);
|
2003-03-12 19:16:42 +00:00
|
|
|
|
|
2003-10-27 10:27:50 +00:00
|
|
|
|
// add the auto-hfill from label end to the body
|
|
|
|
|
if (body_pos && i == body_pos) {
|
|
|
|
|
int add = font_metrics::width(layout->labelsep, getLabelFont(pit));
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (pars_[pit].isLineSeparator(i - 1))
|
2003-10-27 10:27:50 +00:00
|
|
|
|
add -= singleWidth(pit, i - 1);
|
|
|
|
|
|
2003-11-25 11:17:27 +00:00
|
|
|
|
add = std::max(add, labelEnd(pit) - x);
|
2003-10-27 10:27:50 +00:00
|
|
|
|
thiswidth += add;
|
|
|
|
|
}
|
2003-03-09 21:54:56 +00:00
|
|
|
|
|
2003-10-27 10:27:50 +00:00
|
|
|
|
x += thiswidth;
|
|
|
|
|
chunkwidth += thiswidth;
|
|
|
|
|
}
|
2003-10-29 10:47:21 +00:00
|
|
|
|
|
2003-03-09 21:54:56 +00:00
|
|
|
|
// break before a character that will fall off
|
|
|
|
|
// the right of the row
|
|
|
|
|
if (x >= width) {
|
2003-08-26 10:33:59 +00:00
|
|
|
|
// if no break before, break here
|
2003-10-24 15:04:17 +00:00
|
|
|
|
if (point == end || chunkwidth >= width - left) {
|
2004-02-27 12:53:58 +00:00
|
|
|
|
if (i > pos)
|
2003-10-27 10:27:50 +00:00
|
|
|
|
point = i;
|
2004-02-27 12:53:58 +00:00
|
|
|
|
else
|
|
|
|
|
point = i + 1;
|
|
|
|
|
|
2003-10-21 13:04:14 +00:00
|
|
|
|
}
|
2003-10-27 10:27:50 +00:00
|
|
|
|
// exit on last registered breakpoint:
|
2003-10-28 14:04:56 +00:00
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2003-03-09 21:54:56 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (pars_[pit].isNewline(i)) {
|
2004-03-01 17:25:16 +00:00
|
|
|
|
point = i + 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// Break before...
|
|
|
|
|
if (i + 1 < end) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (pars_[pit].isInset(i + 1) && pars_[pit].getInset(i + 1)->display()) {
|
2004-03-01 17:25:16 +00:00
|
|
|
|
point = i + 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// ...and after.
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (pars_[pit].isInset(i) && pars_[pit].getInset(i)->display()) {
|
2004-03-01 17:25:16 +00:00
|
|
|
|
point = i + 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-04-03 08:37:12 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (!pars_[pit].isInset(i) || pars_[pit].getInset(i)->isChar()) {
|
2003-03-09 21:54:56 +00:00
|
|
|
|
// some insets are line separators too
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (pars_[pit].isLineSeparator(i)) {
|
2003-10-22 06:02:55 +00:00
|
|
|
|
// register breakpoint:
|
2003-10-29 10:47:21 +00:00
|
|
|
|
point = i + 1;
|
2003-03-10 04:59:48 +00:00
|
|
|
|
chunkwidth = 0;
|
|
|
|
|
}
|
2003-03-09 21:54:56 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-03-01 17:25:16 +00:00
|
|
|
|
// maybe found one, but the par is short enough.
|
|
|
|
|
if (i == end && x < width)
|
2003-10-27 10:27:50 +00:00
|
|
|
|
point = end;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-11 00:03:27 +00:00
|
|
|
|
// manual labels cannot be broken in LaTeX. But we
|
|
|
|
|
// want to make our on-screen rendering of footnotes
|
|
|
|
|
// etc. still break
|
2003-08-26 10:33:59 +00:00
|
|
|
|
if (body_pos && point < body_pos)
|
2003-10-27 10:27:50 +00:00
|
|
|
|
point = body_pos;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-27 10:27:50 +00:00
|
|
|
|
row.endpos(point);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
void LyXText::setRowWidth(par_type pit, Row & row) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// get the pure distance
|
2003-10-27 11:44:10 +00:00
|
|
|
|
pos_type const end = row.endpos();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
string labelsep = pars_[pit].layout()->labelsep;
|
2003-11-25 11:17:27 +00:00
|
|
|
|
int w = leftMargin(pit, row.pos());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pos_type const body_pos = pars_[pit].beginOfBody();
|
2003-10-17 10:31:47 +00:00
|
|
|
|
pos_type i = row.pos();
|
2000-02-03 19:51:27 +00:00
|
|
|
|
|
2003-10-27 11:44:10 +00:00
|
|
|
|
if (i < end) {
|
2004-03-01 10:10:10 +00:00
|
|
|
|
FontIterator fi = FontIterator(*this, pit, i);
|
|
|
|
|
for ( ; i < end; ++i, ++fi) {
|
2003-07-27 00:37:17 +00:00
|
|
|
|
if (body_pos > 0 && i == body_pos) {
|
2003-11-25 11:17:27 +00:00
|
|
|
|
w += font_metrics::width(labelsep, getLabelFont(pit));
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (pars_[pit].isLineSeparator(i - 1))
|
2003-07-27 00:37:17 +00:00
|
|
|
|
w -= singleWidth(pit, i - 1);
|
2003-11-25 11:17:27 +00:00
|
|
|
|
w = max(w, labelEnd(pit));
|
2003-07-27 00:37:17 +00:00
|
|
|
|
}
|
2004-03-25 09:16:36 +00:00
|
|
|
|
char const c = pars_[pit].getChar(i);
|
2004-03-01 10:10:10 +00:00
|
|
|
|
w += singleWidth(pit, i, c, *fi);
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2000-02-03 19:51:27 +00:00
|
|
|
|
}
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
2003-10-27 11:44:10 +00:00
|
|
|
|
if (body_pos > 0 && body_pos >= end) {
|
2003-11-25 11:17:27 +00:00
|
|
|
|
w += font_metrics::width(labelsep, getLabelFont(pit));
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (end > 0 && pars_[pit].isLineSeparator(end - 1))
|
2003-10-27 11:44:10 +00:00
|
|
|
|
w -= singleWidth(pit, end - 1);
|
2003-11-25 11:17:27 +00:00
|
|
|
|
w = max(w, labelEnd(pit));
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
row.width(w + rightMargin(pars_[pit]));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// returns the minimum space a manual label needs on the screen in pixel
|
2004-03-25 09:16:36 +00:00
|
|
|
|
int LyXText::labelFill(par_type pit, Row const & row) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pos_type last = pars_[pit].beginOfBody();
|
2003-02-26 17:04:10 +00:00
|
|
|
|
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(last > 0);
|
2003-02-26 17:04:10 +00:00
|
|
|
|
|
2003-10-24 09:45:07 +00:00
|
|
|
|
// -1 because a label ends with a space that is in the label
|
2003-02-26 17:04:10 +00:00
|
|
|
|
--last;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// a separator at this end does not count
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (pars_[pit].isLineSeparator(last))
|
2000-01-13 16:28:54 +00:00
|
|
|
|
--last;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
int w = 0;
|
2003-10-24 09:45:07 +00:00
|
|
|
|
for (pos_type i = row.pos(); i <= last; ++i)
|
2003-04-13 12:56:48 +00:00
|
|
|
|
w += singleWidth(pit, i);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
string const & label = pars_[pit].params().labelWidthString();
|
2003-10-28 11:18:40 +00:00
|
|
|
|
if (label.empty())
|
|
|
|
|
return 0;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-28 11:18:40 +00:00
|
|
|
|
return max(0, font_metrics::width(label, getLabelFont(pit)) - w);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-09-18 11:48:11 +00:00
|
|
|
|
LColor_color LyXText::backgroundColor() const
|
2001-07-24 10:13:19 +00:00
|
|
|
|
{
|
2003-12-01 13:35:49 +00:00
|
|
|
|
return LColor_color(LColor::color(background_color_));
|
2001-07-24 10:13:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-03-29 23:11:20 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
void LyXText::setHeightOfRow(par_type pit, Row & row)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// get the maximum ascent and the maximum descent
|
2003-07-29 01:46:09 +00:00
|
|
|
|
double layoutasc = 0;
|
|
|
|
|
double layoutdesc = 0;
|
2003-10-28 11:18:40 +00:00
|
|
|
|
double const dh = defaultRowHeight();
|
2001-07-31 10:10:17 +00:00
|
|
|
|
|
2003-07-17 15:04:09 +00:00
|
|
|
|
// ok, let us initialize the maxasc and maxdesc value.
|
2003-07-29 01:46:09 +00:00
|
|
|
|
// Only the fontsize count. The other properties
|
|
|
|
|
// are taken from the layoutfont. Nicer on the screen :)
|
2004-03-25 09:16:36 +00:00
|
|
|
|
LyXLayout_ptr const & layout = pars_[pit].layout();
|
2001-07-31 10:10:17 +00:00
|
|
|
|
|
2004-01-09 09:04:33 +00:00
|
|
|
|
// as max get the first character of this row then it can
|
|
|
|
|
// increase but not decrease the height. Just some point to
|
|
|
|
|
// start with so we don't have to do the assignment below too
|
|
|
|
|
// often.
|
2003-10-17 10:31:47 +00:00
|
|
|
|
LyXFont font = getFont(pit, row.pos());
|
2001-07-31 12:57:06 +00:00
|
|
|
|
LyXFont::FONT_SIZE const tmpsize = font.size();
|
2003-07-27 21:59:06 +00:00
|
|
|
|
font = getLayoutFont(pit);
|
2001-07-31 12:57:06 +00:00
|
|
|
|
LyXFont::FONT_SIZE const size = font.size();
|
|
|
|
|
font.setSize(tmpsize);
|
2001-07-31 10:10:17 +00:00
|
|
|
|
|
2003-07-27 21:59:06 +00:00
|
|
|
|
LyXFont labelfont = getLabelFont(pit);
|
2001-07-31 10:10:17 +00:00
|
|
|
|
|
2003-10-24 09:45:07 +00:00
|
|
|
|
// these are minimum values
|
2004-03-25 09:16:36 +00:00
|
|
|
|
double const spacing_val =
|
|
|
|
|
layout->spacing.getValue() * spacing(pars_[pit]);
|
2003-10-28 11:18:40 +00:00
|
|
|
|
//lyxerr << "spacing_val = " << spacing_val << endl;
|
|
|
|
|
int maxasc = int(font_metrics::maxAscent(font) * spacing_val);
|
|
|
|
|
int maxdesc = int(font_metrics::maxDescent(font) * spacing_val);
|
2002-05-24 14:34:32 +00:00
|
|
|
|
|
2003-10-24 09:45:07 +00:00
|
|
|
|
// insets may be taller
|
2004-05-17 11:28:31 +00:00
|
|
|
|
InsetList::const_iterator ii = pars_[pit].insetlist.begin();
|
|
|
|
|
InsetList::const_iterator iend = pars_[pit].insetlist.end();
|
2003-10-24 09:45:07 +00:00
|
|
|
|
for ( ; ii != iend; ++ii) {
|
|
|
|
|
if (ii->pos >= row.pos() && ii->pos < row.endpos()) {
|
2003-10-28 11:18:40 +00:00
|
|
|
|
maxasc = max(maxasc, ii->inset->ascent());
|
2003-10-24 09:45:07 +00:00
|
|
|
|
maxdesc = max(maxdesc, ii->inset->descent());
|
2001-07-31 10:10:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if any custom fonts are larger (Asger)
|
|
|
|
|
// This is not completely correct, but we can live with the small,
|
|
|
|
|
// cosmetic error for now.
|
2003-10-24 09:45:07 +00:00
|
|
|
|
int labeladdon = 0;
|
2003-10-27 11:44:10 +00:00
|
|
|
|
pos_type const pos_end = row.endpos();
|
2003-10-24 09:45:07 +00:00
|
|
|
|
|
2001-07-31 12:57:06 +00:00
|
|
|
|
LyXFont::FONT_SIZE maxsize =
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pars_[pit].highestFontInRange(row.pos(), pos_end, size);
|
2001-07-31 10:10:17 +00:00
|
|
|
|
if (maxsize > font.size()) {
|
|
|
|
|
font.setSize(maxsize);
|
2003-10-28 11:18:40 +00:00
|
|
|
|
maxasc = max(maxasc, font_metrics::maxAscent(font));
|
2003-04-13 12:56:48 +00:00
|
|
|
|
maxdesc = max(maxdesc, font_metrics::maxDescent(font));
|
2001-07-31 10:10:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This is nicer with box insets:
|
|
|
|
|
++maxasc;
|
|
|
|
|
++maxdesc;
|
|
|
|
|
|
2003-10-17 10:31:47 +00:00
|
|
|
|
row.ascent_of_text(maxasc);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-31 10:10:17 +00:00
|
|
|
|
// is it a top line?
|
2003-10-28 11:18:40 +00:00
|
|
|
|
if (row.pos() == 0) {
|
2003-09-09 09:47:59 +00:00
|
|
|
|
BufferParams const & bufparams = bv()->buffer()->params();
|
2001-07-31 10:10:17 +00:00
|
|
|
|
// some parksips VERY EASY IMPLEMENTATION
|
2003-10-28 11:18:40 +00:00
|
|
|
|
if (bv()->buffer()->params().paragraph_separation
|
2003-10-29 10:47:21 +00:00
|
|
|
|
== BufferParams::PARSEP_SKIP
|
2004-03-25 09:16:36 +00:00
|
|
|
|
&& pit != 0
|
|
|
|
|
&& ((layout->isParagraph() && pars_[pit].getDepth() == 0)
|
|
|
|
|
|| (pars_[pit - 1].layout()->isParagraph()
|
|
|
|
|
&& pars_[pit - 1].getDepth() == 0)))
|
2001-07-31 10:10:17 +00:00
|
|
|
|
{
|
2003-09-09 09:47:59 +00:00
|
|
|
|
maxasc += bufparams.getDefSkip().inPixels(*bv());
|
2001-07-31 10:10:17 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (pars_[pit].params().startOfAppendix())
|
2003-10-28 11:18:40 +00:00
|
|
|
|
maxasc += int(3 * dh);
|
2003-03-13 19:55:39 +00:00
|
|
|
|
|
2001-07-31 10:10:17 +00:00
|
|
|
|
// This is special code for the chapter, since the label of this
|
|
|
|
|
// layout is printed in an extra row
|
2003-09-12 17:13:22 +00:00
|
|
|
|
if (layout->counter == "chapter" && bufparams.secnumdepth >= 0) {
|
2003-10-28 11:18:40 +00:00
|
|
|
|
labeladdon = int(font_metrics::maxHeight(labelfont)
|
2004-03-25 09:16:36 +00:00
|
|
|
|
* layout->spacing.getValue()
|
|
|
|
|
* spacing(pars_[pit]));
|
2001-07-31 10:10:17 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-31 10:10:17 +00:00
|
|
|
|
// special code for the top label
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if ((layout->labeltype == LABEL_TOP_ENVIRONMENT
|
|
|
|
|
|| layout->labeltype == LABEL_BIBLIO
|
|
|
|
|
|| layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
|
2003-12-01 13:35:49 +00:00
|
|
|
|
&& isFirstInSequence(pit, paragraphs())
|
2004-03-25 09:16:36 +00:00
|
|
|
|
&& !pars_[pit].getLabelstring().empty())
|
2001-07-31 10:10:17 +00:00
|
|
|
|
{
|
|
|
|
|
labeladdon = int(
|
2003-10-28 11:18:40 +00:00
|
|
|
|
font_metrics::maxHeight(labelfont)
|
|
|
|
|
* layout->spacing.getValue()
|
2004-03-25 09:16:36 +00:00
|
|
|
|
* spacing(pars_[pit])
|
2003-10-28 11:18:40 +00:00
|
|
|
|
+ (layout->topsep + layout->labelbottomsep) * dh);
|
2001-07-31 10:10:17 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-28 15:53:34 +00:00
|
|
|
|
// Add the layout spaces, for example before and after
|
2003-04-16 08:12:22 +00:00
|
|
|
|
// a section, or between the items of a itemize or enumerate
|
|
|
|
|
// environment.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
par_type prev = depthHook(pit, pars_, pars_[pit].getDepth());
|
2003-10-28 11:18:40 +00:00
|
|
|
|
if (prev != pit
|
2004-03-25 09:16:36 +00:00
|
|
|
|
&& pars_[prev].layout() == layout
|
|
|
|
|
&& pars_[prev].getDepth() == pars_[pit].getDepth()
|
|
|
|
|
&& pars_[prev].getLabelWidthString() == pars_[pit].getLabelWidthString())
|
2003-10-27 12:41:26 +00:00
|
|
|
|
{
|
2003-10-28 11:18:40 +00:00
|
|
|
|
layoutasc = layout->itemsep * dh;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
} else if (pit != 0 || row.pos() != 0) {
|
2003-10-28 11:18:40 +00:00
|
|
|
|
if (layout->topsep > 0)
|
|
|
|
|
layoutasc = layout->topsep * dh;
|
2003-10-27 12:41:26 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
prev = outerHook(pit, pars_);
|
2004-03-27 01:18:51 +00:00
|
|
|
|
if (prev != par_type(pars_.size())) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
maxasc += int(pars_[prev].layout()->parsep * dh);
|
|
|
|
|
} else if (pit != 0) {
|
|
|
|
|
if (pars_[pit - 1].getDepth() != 0 ||
|
|
|
|
|
pars_[pit - 1].layout() == layout) {
|
2003-10-28 11:18:40 +00:00
|
|
|
|
maxasc += int(layout->parsep * dh);
|
2001-07-31 10:10:17 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-07-31 10:10:17 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-31 10:10:17 +00:00
|
|
|
|
// is it a bottom line?
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (row.endpos() >= pars_[pit].size()) {
|
2003-11-28 15:53:34 +00:00
|
|
|
|
// add the layout spaces, for example before and after
|
2001-07-31 10:10:17 +00:00
|
|
|
|
// a section, or between the items of a itemize or enumerate
|
|
|
|
|
// environment
|
2004-03-25 09:16:36 +00:00
|
|
|
|
par_type nextpit = pit + 1;
|
2004-03-27 01:18:51 +00:00
|
|
|
|
if (nextpit != par_type(pars_.size())) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
par_type cpit = pit;
|
2003-10-28 11:18:40 +00:00
|
|
|
|
double usual = 0;
|
|
|
|
|
double unusual = 0;
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (pars_[cpit].getDepth() > pars_[nextpit].getDepth()) {
|
|
|
|
|
usual = pars_[cpit].layout()->bottomsep * dh;
|
|
|
|
|
cpit = depthHook(cpit, paragraphs(), pars_[nextpit].getDepth());
|
|
|
|
|
if (pars_[cpit].layout() != pars_[nextpit].layout()
|
|
|
|
|
|| pars_[nextpit].getLabelWidthString() != pars_[cpit].getLabelWidthString())
|
2001-07-31 10:10:17 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
unusual = pars_[cpit].layout()->bottomsep * dh;
|
2001-07-31 10:10:17 +00:00
|
|
|
|
}
|
2003-10-28 11:18:40 +00:00
|
|
|
|
layoutdesc = max(unusual, usual);
|
2004-03-25 09:16:36 +00:00
|
|
|
|
} else if (pars_[cpit].getDepth() == pars_[nextpit].getDepth()) {
|
|
|
|
|
if (pars_[cpit].layout() != pars_[nextpit].layout()
|
|
|
|
|
|| pars_[nextpit].getLabelWidthString() != pars_[cpit].getLabelWidthString())
|
|
|
|
|
layoutdesc = int(pars_[cpit].layout()->bottomsep * dh);
|
2001-07-31 10:10:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-31 10:10:17 +00:00
|
|
|
|
// incalculate the layout spaces
|
2004-03-25 09:16:36 +00:00
|
|
|
|
maxasc += int(layoutasc * 2 / (2 + pars_[pit].getDepth()));
|
|
|
|
|
maxdesc += int(layoutdesc * 2 / (2 + pars_[pit].getDepth()));
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-17 10:31:47 +00:00
|
|
|
|
row.height(maxasc + maxdesc + labeladdon);
|
|
|
|
|
row.baseline(maxasc + labeladdon);
|
|
|
|
|
row.top_of_text(row.baseline() - font_metrics::maxAscent(font));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
void LyXText::breakParagraph(LCursor & cur, char keep_layout)
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2003-02-08 19:18:01 +00:00
|
|
|
|
// allow only if at start or end, or all previous is new text
|
2004-02-12 16:36:01 +00:00
|
|
|
|
Paragraph & cpar = cur.paragraph();
|
2004-03-25 09:16:36 +00:00
|
|
|
|
par_type cpit = cur.par();
|
2004-02-12 16:36:01 +00:00
|
|
|
|
|
|
|
|
|
if (cur.pos() != 0 && cur.pos() != cur.lastpos()
|
|
|
|
|
&& cpar.isChangeEdited(0, cur.pos()))
|
2003-02-08 19:18:01 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2004-04-08 15:03:33 +00:00
|
|
|
|
LyXTextClass const & tclass = cur.buffer().params().getLyXTextClass();
|
2004-02-12 16:36:01 +00:00
|
|
|
|
LyXLayout_ptr const & layout = cpar.layout();
|
2000-09-23 04:57:18 +00:00
|
|
|
|
|
2004-01-09 09:04:33 +00:00
|
|
|
|
// this is only allowed, if the current paragraph is not empty
|
|
|
|
|
// or caption and if it has not the keepempty flag active
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.lastpos() == 0 && !cpar.allowEmpty()
|
2003-06-07 17:45:43 +00:00
|
|
|
|
&& layout->labeltype != LABEL_SENSITIVE)
|
2002-05-29 12:58:23 +00:00
|
|
|
|
return;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-01-09 09:04:33 +00:00
|
|
|
|
// a layout change may affect also the following paragraph
|
2004-03-25 09:16:36 +00:00
|
|
|
|
recUndo(cur.par(), undoSpan(cur.par()) - 1);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// Always break behind a space
|
|
|
|
|
// It is better to erase the space (Dekel)
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.pos() != cur.lastpos() && cpar.isLineSeparator(cur.pos()))
|
|
|
|
|
cpar.erase(cur.pos());
|
2002-05-29 12:58:23 +00:00
|
|
|
|
|
|
|
|
|
// break the paragraph
|
|
|
|
|
if (keep_layout)
|
|
|
|
|
keep_layout = 2;
|
|
|
|
|
else
|
2002-06-24 20:28:12 +00:00
|
|
|
|
keep_layout = layout->isEnvironment();
|
2002-05-29 12:58:23 +00:00
|
|
|
|
|
|
|
|
|
// we need to set this before we insert the paragraph. IMO the
|
|
|
|
|
// breakParagraph call should return a bool if it inserts the
|
|
|
|
|
// paragraph before or behind and we should react on that one
|
|
|
|
|
// but we can fix this in 1.3.0 (Jug 20020509)
|
2004-02-12 16:36:01 +00:00
|
|
|
|
bool const isempty = cpar.allowEmpty() && cpar.empty();
|
2004-04-08 15:03:33 +00:00
|
|
|
|
::breakParagraph(cur.buffer().params(), paragraphs(), cpit,
|
2004-02-12 16:36:01 +00:00
|
|
|
|
cur.pos(), keep_layout);
|
2000-09-23 04:57:18 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
cpit = cur.par();
|
|
|
|
|
par_type next_par = cpit + 1;
|
2003-08-15 08:03:54 +00:00
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// well this is the caption hack since one caption is really enough
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (layout->labeltype == LABEL_SENSITIVE) {
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (!cur.pos())
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// set to standard-layout
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pars_[cpit].applyLayout(tclass.defaultLayout());
|
2002-05-29 12:58:23 +00:00
|
|
|
|
else
|
|
|
|
|
// set to standard-layout
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pars_[next_par].applyLayout(tclass.defaultLayout());
|
2002-05-29 12:58:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if the cursor is at the beginning of a row without prior newline,
|
|
|
|
|
// move one row up!
|
|
|
|
|
// This touches only the screen-update. Otherwise we would may have
|
2002-06-24 20:28:12 +00:00
|
|
|
|
// an empty row on the screen
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.pos() != 0 && cur.textRow().pos() == cur.pos()
|
2004-03-25 09:16:36 +00:00
|
|
|
|
&& !pars_[cpit].isNewline(cur.pos() - 1))
|
2002-05-29 12:58:23 +00:00
|
|
|
|
{
|
2004-02-20 17:19:53 +00:00
|
|
|
|
cursorLeft(cur);
|
2002-05-29 12:58:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
while (!pars_[next_par].empty() && pars_[next_par].isNewline(0))
|
|
|
|
|
pars_[next_par].erase(0);
|
2003-04-13 02:23:30 +00:00
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
updateCounters();
|
2003-10-24 09:45:07 +00:00
|
|
|
|
redoParagraph(cpit);
|
2003-08-15 08:03:54 +00:00
|
|
|
|
redoParagraph(next_par);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// This check is necessary. Otherwise the new empty paragraph will
|
|
|
|
|
// be deleted automatically. And it is more friendly for the user!
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.pos() != 0 || isempty)
|
2004-02-13 11:05:29 +00:00
|
|
|
|
setCursor(cur, cur.par() + 1, 0);
|
2002-05-29 12:58:23 +00:00
|
|
|
|
else
|
2004-02-13 11:05:29 +00:00
|
|
|
|
setCursor(cur, cur.par(), 0);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-14 08:34:13 +00:00
|
|
|
|
// convenience function
|
2004-02-13 07:30:59 +00:00
|
|
|
|
void LyXText::redoParagraph(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2004-02-13 07:30:59 +00:00
|
|
|
|
cur.clearSelection();
|
2004-03-25 09:16:36 +00:00
|
|
|
|
redoParagraph(cur.par());
|
2004-02-13 11:05:29 +00:00
|
|
|
|
setCursorIntern(cur, cur.par(), cur.pos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// insert a character, moves all the following breaks in the
|
2002-06-24 20:28:12 +00:00
|
|
|
|
// same Paragraph one to the right and make a rebreak
|
2004-02-13 07:30:59 +00:00
|
|
|
|
void LyXText::insertChar(LCursor & cur, char c)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2004-03-08 21:14:45 +00:00
|
|
|
|
BOOST_ASSERT(c != Paragraph::META_INSET);
|
|
|
|
|
|
2004-02-13 07:30:59 +00:00
|
|
|
|
recordUndo(cur, Undo::INSERT);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2004-02-13 07:30:59 +00:00
|
|
|
|
Paragraph & par = cur.paragraph();
|
|
|
|
|
// try to remove this
|
2004-03-25 09:16:36 +00:00
|
|
|
|
par_type pit = cur.par();
|
2000-03-09 03:36:48 +00:00
|
|
|
|
|
2004-02-13 07:30:59 +00:00
|
|
|
|
bool const freeSpacing = par.layout()->free_spacing ||
|
|
|
|
|
par.isFreeSpacing();
|
2000-02-29 02:19:17 +00:00
|
|
|
|
|
2000-10-09 12:30:52 +00:00
|
|
|
|
if (lyxrc.auto_number) {
|
2001-01-15 14:05:45 +00:00
|
|
|
|
static string const number_operators = "+-/*";
|
|
|
|
|
static string const number_unary_operators = "+-";
|
|
|
|
|
static string const number_seperators = ".,:";
|
|
|
|
|
|
2000-10-09 12:30:52 +00:00
|
|
|
|
if (current_font.number() == LyXFont::ON) {
|
2001-12-20 15:11:51 +00:00
|
|
|
|
if (!IsDigit(c) && !contains(number_operators, c) &&
|
2001-01-15 14:05:45 +00:00
|
|
|
|
!(contains(number_seperators, c) &&
|
2004-02-13 07:30:59 +00:00
|
|
|
|
cur.pos() != 0 &&
|
|
|
|
|
cur.pos() != cur.lastpos() &&
|
|
|
|
|
getFont(pit, cur.pos()).number() == LyXFont::ON &&
|
|
|
|
|
getFont(pit, cur.pos() - 1).number() == LyXFont::ON)
|
2002-02-16 15:59:55 +00:00
|
|
|
|
)
|
2004-02-13 11:05:29 +00:00
|
|
|
|
number(cur); // Set current_font.number to OFF
|
2001-12-20 15:11:51 +00:00
|
|
|
|
} else if (IsDigit(c) &&
|
2000-10-09 12:30:52 +00:00
|
|
|
|
real_current_font.isVisibleRightToLeft()) {
|
2004-02-13 11:05:29 +00:00
|
|
|
|
number(cur); // Set current_font.number to ON
|
2000-10-09 12:30:52 +00:00
|
|
|
|
|
2004-02-13 07:30:59 +00:00
|
|
|
|
if (cur.pos() != 0) {
|
|
|
|
|
char const c = par.getChar(cur.pos() - 1);
|
2001-01-15 14:05:45 +00:00
|
|
|
|
if (contains(number_unary_operators, c) &&
|
2004-02-13 07:30:59 +00:00
|
|
|
|
(cur.pos() == 1
|
|
|
|
|
|| par.isSeparator(cur.pos() - 2)
|
|
|
|
|
|| par.isNewline(cur.pos() - 2))
|
2002-02-16 15:59:55 +00:00
|
|
|
|
) {
|
2004-02-13 07:30:59 +00:00
|
|
|
|
setCharFont(pit, cur.pos() - 1, current_font);
|
|
|
|
|
} else if (contains(number_seperators, c)
|
|
|
|
|
&& cur.pos() >= 2
|
|
|
|
|
&& getFont(pit, cur.pos() - 2).number() == LyXFont::ON) {
|
|
|
|
|
setCharFont(pit, cur.pos() - 1, current_font);
|
2000-10-09 12:30:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// First check, if there will be two blanks together or a blank at
|
|
|
|
|
// the beginning of a paragraph.
|
|
|
|
|
// I decided to handle blanks like normal characters, the main
|
|
|
|
|
// difference are the special checks when calculating the row.fill
|
|
|
|
|
// (blank does not count at the end of a row) and the check here
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// The bug is triggered when we type in a description environment:
|
|
|
|
|
// The current_font is not changed when we go from label to main text
|
|
|
|
|
// and it should (along with realtmpfont) when we type the space.
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// CHECK There is a bug here! (Asger)
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// store the current font. This is because of the use of cursor
|
2002-06-24 20:28:12 +00:00
|
|
|
|
// movements. The moving cursor would refresh the current font
|
2003-08-11 09:09:01 +00:00
|
|
|
|
LyXFont realtmpfont = real_current_font;
|
|
|
|
|
LyXFont rawtmpfont = current_font;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2004-02-13 07:30:59 +00:00
|
|
|
|
// When the free-spacing option is set for the current layout,
|
|
|
|
|
// disable the double-space checking
|
2000-03-09 03:36:48 +00:00
|
|
|
|
if (!freeSpacing && IsLineSeparatorChar(c)) {
|
2004-02-13 07:30:59 +00:00
|
|
|
|
if (cur.pos() == 0) {
|
2001-05-09 15:20:58 +00:00
|
|
|
|
static bool sent_space_message = false;
|
|
|
|
|
if (!sent_space_message) {
|
2004-02-13 07:30:59 +00:00
|
|
|
|
cur.message(_("You cannot insert a space at the "
|
|
|
|
|
"beginning of a paragraph. Please read the Tutorial."));
|
|
|
|
|
sent_space_message = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
BOOST_ASSERT(cur.pos() > 0);
|
|
|
|
|
if (par.isLineSeparator(cur.pos() - 1)
|
|
|
|
|
|| par.isNewline(cur.pos() - 1)) {
|
|
|
|
|
static bool sent_space_message = false;
|
|
|
|
|
if (!sent_space_message) {
|
|
|
|
|
cur.message(_("You cannot type two spaces this way. "
|
|
|
|
|
"Please read the Tutorial."));
|
2001-05-09 15:20:58 +00:00
|
|
|
|
sent_space_message = true;
|
|
|
|
|
}
|
1999-12-13 00:05:34 +00:00
|
|
|
|
return;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-03-13 10:30:28 +00:00
|
|
|
|
|
2004-08-05 15:14:29 +00:00
|
|
|
|
par.insertChar(cur.pos(), c, rawtmpfont);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-08-08 15:34:17 +00:00
|
|
|
|
current_font = rawtmpfont;
|
|
|
|
|
real_current_font = realtmpfont;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
redoParagraph(cur);
|
2004-02-13 11:05:29 +00:00
|
|
|
|
setCursor(cur, cur.par(), cur.pos() + 1, false, cur.boundary());
|
1999-12-13 00:05:34 +00:00
|
|
|
|
charInserted();
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
|
|
|
|
|
void LyXText::charInserted()
|
|
|
|
|
{
|
2003-10-27 11:44:10 +00:00
|
|
|
|
// Here we call finishUndo for every 20 characters inserted.
|
2003-04-13 12:56:48 +00:00
|
|
|
|
// This is from my experience how emacs does it. (Lgb)
|
2001-06-04 23:57:32 +00:00
|
|
|
|
static unsigned int counter;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (counter < 20) {
|
|
|
|
|
++counter;
|
|
|
|
|
} else {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
finishUndo();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
counter = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-12-13 00:05:34 +00:00
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
RowMetrics LyXText::computeRowMetrics(par_type pit, Row const & row) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-03-01 12:23:17 +00:00
|
|
|
|
RowMetrics result;
|
|
|
|
|
|
2004-03-01 16:29:30 +00:00
|
|
|
|
double w = width_ - row.width();
|
2000-02-03 19:51:27 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
bool const is_rtl = isRTL(pars_[pit]);
|
2003-07-18 07:47:07 +00:00
|
|
|
|
if (is_rtl)
|
2004-03-25 09:16:36 +00:00
|
|
|
|
result.x = rightMargin(pars_[pit]);
|
2003-07-18 07:47:07 +00:00
|
|
|
|
else
|
2004-03-01 12:23:17 +00:00
|
|
|
|
result.x = leftMargin(pit, row.pos());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
// is there a manual margin with a manual label
|
2004-03-25 09:16:36 +00:00
|
|
|
|
LyXLayout_ptr const & layout = pars_[pit].layout();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (layout->margintype == MARGIN_MANUAL
|
|
|
|
|
&& layout->labeltype == LABEL_MANUAL) {
|
2003-03-08 19:31:09 +00:00
|
|
|
|
/// We might have real hfills in the label part
|
2004-03-25 09:16:36 +00:00
|
|
|
|
int nlh = numberOfLabelHfills(pars_[pit], row);
|
2003-03-08 19:31:09 +00:00
|
|
|
|
|
|
|
|
|
// A manual label par (e.g. List) has an auto-hfill
|
2003-03-09 12:37:22 +00:00
|
|
|
|
// between the label text and the body of the
|
2003-03-08 19:31:09 +00:00
|
|
|
|
// paragraph too.
|
|
|
|
|
// But we don't want to do this auto hfill if the par
|
|
|
|
|
// is empty.
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (!pars_[pit].empty())
|
2003-03-08 19:31:09 +00:00
|
|
|
|
++nlh;
|
2003-03-13 10:30:28 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (nlh && !pars_[pit].getLabelWidthString().empty())
|
2004-03-01 12:23:17 +00:00
|
|
|
|
result.label_hfill = labelFill(pit, row) / double(nlh);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
// are there any hfills in the row?
|
2004-03-25 09:16:36 +00:00
|
|
|
|
int const nh = numberOfHfills(pars_[pit], row);
|
2000-09-23 04:57:18 +00:00
|
|
|
|
|
2001-08-10 14:00:48 +00:00
|
|
|
|
if (nh) {
|
|
|
|
|
if (w > 0)
|
2004-03-01 12:23:17 +00:00
|
|
|
|
result.hfill = w / nh;
|
2002-01-07 16:15:11 +00:00
|
|
|
|
// we don't have to look at the alignment if it is ALIGN_LEFT and
|
|
|
|
|
// if the row is already larger then the permitted width as then
|
|
|
|
|
// we force the LEFT_ALIGN'edness!
|
2004-03-01 16:29:30 +00:00
|
|
|
|
} else if (int(row.width()) < maxwidth_) {
|
2002-03-21 17:27:08 +00:00
|
|
|
|
// is it block, flushleft or flushright?
|
2000-06-08 23:16:16 +00:00
|
|
|
|
// set x how you need it
|
2001-08-10 14:00:48 +00:00
|
|
|
|
int align;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (pars_[pit].params().align() == LYX_ALIGN_LAYOUT)
|
2002-06-24 20:28:12 +00:00
|
|
|
|
align = layout->align;
|
2003-10-29 12:18:08 +00:00
|
|
|
|
else
|
2004-03-25 09:16:36 +00:00
|
|
|
|
align = pars_[pit].params().align();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-20 18:56:48 +00:00
|
|
|
|
// Display-style insets should always be on a centred row
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// The test on pars_[pit].size() is to catch zero-size pars, which
|
2003-10-21 13:04:14 +00:00
|
|
|
|
// would trigger the assert in Paragraph::getInset().
|
2004-03-25 09:16:36 +00:00
|
|
|
|
//inset = pars_[pit].size() ? pars_[pit].getInset(row.pos()) : 0;
|
|
|
|
|
if (!pars_[pit].empty()
|
|
|
|
|
&& pars_[pit].isInset(row.pos())
|
|
|
|
|
&& pars_[pit].getInset(row.pos())->display())
|
2003-10-24 15:04:17 +00:00
|
|
|
|
{
|
2003-10-20 18:56:48 +00:00
|
|
|
|
align = LYX_ALIGN_CENTER;
|
|
|
|
|
}
|
2003-10-29 10:47:21 +00:00
|
|
|
|
|
2001-08-10 14:00:48 +00:00
|
|
|
|
switch (align) {
|
2004-02-27 13:06:16 +00:00
|
|
|
|
case LYX_ALIGN_BLOCK: {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
int const ns = numberOfSeparators(pars_[pit], row);
|
2004-02-27 13:06:16 +00:00
|
|
|
|
bool disp_inset = false;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (row.endpos() < pars_[pit].size()) {
|
|
|
|
|
InsetBase const * in = pars_[pit].getInset(row.endpos());
|
2004-02-27 13:06:16 +00:00
|
|
|
|
if (in)
|
|
|
|
|
disp_inset = in->display();
|
2001-08-10 14:00:48 +00:00
|
|
|
|
}
|
2004-02-27 13:06:16 +00:00
|
|
|
|
// If we have separators, this is not the last row of a
|
|
|
|
|
// par, does not end in newline, and is not row above a
|
|
|
|
|
// display inset... then stretch it
|
|
|
|
|
if (ns
|
2004-03-25 09:16:36 +00:00
|
|
|
|
&& row.endpos() < pars_[pit].size()
|
|
|
|
|
&& !pars_[pit].isNewline(row.endpos() - 1)
|
2004-02-27 13:06:16 +00:00
|
|
|
|
&& !disp_inset
|
|
|
|
|
) {
|
2004-03-01 12:23:17 +00:00
|
|
|
|
result.separator = w / ns;
|
2004-02-27 13:06:16 +00:00
|
|
|
|
} else if (is_rtl) {
|
2004-03-01 12:23:17 +00:00
|
|
|
|
result.x += w;
|
2004-02-27 13:06:16 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case LYX_ALIGN_RIGHT:
|
2004-03-01 12:23:17 +00:00
|
|
|
|
result.x += w;
|
2001-08-10 14:00:48 +00:00
|
|
|
|
break;
|
2004-02-27 13:06:16 +00:00
|
|
|
|
case LYX_ALIGN_CENTER:
|
2004-03-01 12:23:17 +00:00
|
|
|
|
result.x += w / 2;
|
2001-08-10 14:00:48 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
bidi.computeTables(pars_[pit], *bv()->buffer(), row);
|
2000-04-10 21:40:13 +00:00
|
|
|
|
if (is_rtl) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pos_type body_pos = pars_[pit].beginOfBody();
|
2003-10-27 11:44:10 +00:00
|
|
|
|
pos_type end = row.endpos();
|
2000-02-03 19:51:27 +00:00
|
|
|
|
|
2003-10-28 11:18:40 +00:00
|
|
|
|
if (body_pos > 0
|
2004-03-25 09:16:36 +00:00
|
|
|
|
&& (body_pos > end || !pars_[pit].isLineSeparator(body_pos - 1)))
|
2003-10-28 11:18:40 +00:00
|
|
|
|
{
|
2004-03-01 12:23:17 +00:00
|
|
|
|
result.x += font_metrics::width(layout->labelsep, getLabelFont(pit));
|
2003-10-27 11:44:10 +00:00
|
|
|
|
if (body_pos <= end)
|
2004-03-01 12:23:17 +00:00
|
|
|
|
result.x += result.label_hfill;
|
2000-02-03 19:51:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-08-22 09:40:56 +00:00
|
|
|
|
|
2004-03-01 12:23:17 +00:00
|
|
|
|
return result;
|
2000-02-03 19:51:27 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// the cursor set functions have a special mechanism. When they
|
|
|
|
|
// realize, that you left an empty paragraph, they will delete it.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
void LyXText::cursorRightOneWord(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.pos() == cur.lastpos() && cur.par() != cur.lastpar()) {
|
|
|
|
|
++cur.par();
|
|
|
|
|
cur.pos() = 0;
|
|
|
|
|
} else {
|
|
|
|
|
// Skip through initial nonword stuff.
|
|
|
|
|
// Treat floats and insets as words.
|
|
|
|
|
while (cur.pos() != cur.lastpos() && !cur.paragraph().isWord(cur.pos()))
|
|
|
|
|
++cur.pos();
|
|
|
|
|
// Advance through word.
|
|
|
|
|
while (cur.pos() != cur.lastpos() && cur.paragraph().isWord(cur.pos()))
|
|
|
|
|
++cur.pos();
|
|
|
|
|
}
|
2004-02-13 11:05:29 +00:00
|
|
|
|
setCursor(cur, cur.par(), cur.pos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
void LyXText::cursorLeftOneWord(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.pos() == 0 && cur.par() != 0) {
|
|
|
|
|
--cur.par();
|
|
|
|
|
cur.pos() = cur.lastpos();
|
2004-04-03 08:37:12 +00:00
|
|
|
|
} else {
|
2004-02-12 16:36:01 +00:00
|
|
|
|
// Skip through initial nonword stuff.
|
|
|
|
|
// Treat floats and insets as words.
|
|
|
|
|
while (cur.pos() != 0 && !cur.paragraph().isWord(cur.pos() - 1))
|
|
|
|
|
--cur.pos();
|
|
|
|
|
// Advance through word.
|
|
|
|
|
while (cur.pos() != 0 && cur.paragraph().isWord(cur.pos() - 1))
|
|
|
|
|
--cur.pos();
|
|
|
|
|
}
|
2004-02-13 11:05:29 +00:00
|
|
|
|
setCursor(cur, cur.par(), cur.pos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
|
2004-02-13 07:30:59 +00:00
|
|
|
|
void LyXText::selectWord(LCursor & cur, word_location loc)
|
2001-06-27 14:10:35 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2004-03-01 17:12:09 +00:00
|
|
|
|
CursorSlice from = cur.top();
|
|
|
|
|
CursorSlice to = cur.top();
|
2003-11-11 10:08:35 +00:00
|
|
|
|
getWord(from, to, loc);
|
2004-03-01 17:12:09 +00:00
|
|
|
|
if (cur.top() != from)
|
2004-02-13 11:05:29 +00:00
|
|
|
|
setCursor(cur, from.par(), from.pos());
|
2001-07-27 16:07:33 +00:00
|
|
|
|
if (to == from)
|
|
|
|
|
return;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
cur.resetAnchor();
|
2004-02-13 11:05:29 +00:00
|
|
|
|
setCursor(cur, to.par(), to.pos());
|
2004-02-13 07:30:59 +00:00
|
|
|
|
cur.setSelection();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// Select the word currently under the cursor when no
|
2002-06-24 20:28:12 +00:00
|
|
|
|
// selection is currently set
|
2004-02-13 07:30:59 +00:00
|
|
|
|
bool LyXText::selectWordWhenUnderCursor(LCursor & cur, word_location loc)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2004-02-13 07:30:59 +00:00
|
|
|
|
if (cur.selection())
|
2004-01-20 14:25:24 +00:00
|
|
|
|
return false;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
selectWord(cur, loc);
|
|
|
|
|
return cur.selection();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-13 07:30:59 +00:00
|
|
|
|
void LyXText::acceptChange(LCursor & cur)
|
2003-02-08 19:18:01 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2004-02-13 07:30:59 +00:00
|
|
|
|
if (!cur.selection() && cur.lastpos() != 0)
|
2003-02-08 19:18:01 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2004-02-13 07:30:59 +00:00
|
|
|
|
CursorSlice const & startc = cur.selBegin();
|
|
|
|
|
CursorSlice const & endc = cur.selEnd();
|
|
|
|
|
if (startc.par() == endc.par()) {
|
|
|
|
|
recordUndoSelection(cur, Undo::INSERT);
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pars_[startc.par()].acceptChange(startc.pos(), endc.pos());
|
2003-02-08 19:18:01 +00:00
|
|
|
|
finishUndo();
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.clearSelection();
|
2004-03-25 09:16:36 +00:00
|
|
|
|
redoParagraph(startc.par());
|
2004-02-13 11:05:29 +00:00
|
|
|
|
setCursorIntern(cur, startc.par(), 0);
|
2003-02-08 19:18:01 +00:00
|
|
|
|
}
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2003-02-08 19:18:01 +00:00
|
|
|
|
#warning handle multi par selection
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#endif
|
2003-02-08 19:18:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-13 07:30:59 +00:00
|
|
|
|
void LyXText::rejectChange(LCursor & cur)
|
2003-02-08 19:18:01 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2004-02-13 07:30:59 +00:00
|
|
|
|
if (!cur.selection() && cur.lastpos() != 0)
|
2003-02-08 19:18:01 +00:00
|
|
|
|
return;
|
2003-03-03 23:19:01 +00:00
|
|
|
|
|
2004-02-13 07:30:59 +00:00
|
|
|
|
CursorSlice const & startc = cur.selBegin();
|
|
|
|
|
CursorSlice const & endc = cur.selEnd();
|
|
|
|
|
if (startc.par() == endc.par()) {
|
|
|
|
|
recordUndoSelection(cur, Undo::INSERT);
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pars_[startc.par()].rejectChange(startc.pos(), endc.pos());
|
2003-02-08 19:18:01 +00:00
|
|
|
|
finishUndo();
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.clearSelection();
|
2004-03-25 09:16:36 +00:00
|
|
|
|
redoParagraph(startc.par());
|
2004-02-13 11:05:29 +00:00
|
|
|
|
setCursorIntern(cur, startc.par(), 0);
|
2003-02-08 19:18:01 +00:00
|
|
|
|
}
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2003-02-08 19:18:01 +00:00
|
|
|
|
#warning handle multi par selection
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#endif
|
2003-02-08 19:18:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-03-03 23:19:01 +00:00
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// Delete from cursor up to the end of the current or next word.
|
2004-02-12 16:36:01 +00:00
|
|
|
|
void LyXText::deleteWordForward(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.lastpos() == 0)
|
2004-02-20 17:19:53 +00:00
|
|
|
|
cursorRight(cur);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else {
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.resetAnchor();
|
2004-02-12 16:36:01 +00:00
|
|
|
|
cur.selection() = true;
|
|
|
|
|
cursorRightOneWord(cur);
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.setSelection();
|
2004-02-13 11:05:29 +00:00
|
|
|
|
cutSelection(cur, true, false);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// Delete from cursor to start of current or prior word.
|
2004-02-12 16:36:01 +00:00
|
|
|
|
void LyXText::deleteWordBackward(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.lastpos() == 0)
|
2004-02-20 17:19:53 +00:00
|
|
|
|
cursorLeft(cur);
|
2002-05-29 12:58:23 +00:00
|
|
|
|
else {
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.resetAnchor();
|
2004-02-12 16:36:01 +00:00
|
|
|
|
cur.selection() = true;
|
|
|
|
|
cursorLeftOneWord(cur);
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.setSelection();
|
2004-02-13 11:05:29 +00:00
|
|
|
|
cutSelection(cur, true, false);
|
2002-05-29 12:58:23 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
// Kill to end of line.
|
2004-02-12 16:36:01 +00:00
|
|
|
|
void LyXText::deleteLineForward(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.lastpos() == 0) {
|
2000-05-26 16:13:01 +00:00
|
|
|
|
// Paragraph is empty, so we just go to the right
|
2004-02-20 17:19:53 +00:00
|
|
|
|
cursorRight(cur);
|
2003-10-27 11:44:10 +00:00
|
|
|
|
} else {
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.resetAnchor();
|
2004-02-12 16:36:01 +00:00
|
|
|
|
cur.selection() = true; // to avoid deletion
|
|
|
|
|
cursorEnd(cur);
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.setSelection();
|
2000-05-30 15:41:16 +00:00
|
|
|
|
// What is this test for ??? (JMarc)
|
2004-01-20 14:25:24 +00:00
|
|
|
|
if (!cur.selection())
|
2004-02-12 16:36:01 +00:00
|
|
|
|
deleteWordForward(cur);
|
2003-10-27 11:44:10 +00:00
|
|
|
|
else
|
2004-02-13 11:05:29 +00:00
|
|
|
|
cutSelection(cur, true, false);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
|
2004-02-13 07:30:59 +00:00
|
|
|
|
void LyXText::changeCase(LCursor & cur, LyXText::TextCase action)
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2004-01-13 14:13:51 +00:00
|
|
|
|
CursorSlice from;
|
|
|
|
|
CursorSlice to;
|
2001-03-09 00:56:42 +00:00
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
if (cur.selection()) {
|
2004-01-26 10:13:15 +00:00
|
|
|
|
from = cur.selBegin();
|
2004-01-20 14:25:24 +00:00
|
|
|
|
to = cur.selEnd();
|
2001-06-27 14:10:35 +00:00
|
|
|
|
} else {
|
2004-03-18 13:28:49 +00:00
|
|
|
|
from = cur.top();
|
2003-11-11 10:08:35 +00:00
|
|
|
|
getWord(from, to, lyx::PARTIAL_WORD);
|
2004-02-13 11:05:29 +00:00
|
|
|
|
setCursor(cur, to.par(), to.pos() + 1);
|
2001-06-27 14:10:35 +00:00
|
|
|
|
}
|
2001-03-09 00:56:42 +00:00
|
|
|
|
|
2004-02-13 07:30:59 +00:00
|
|
|
|
recordUndoSelection(cur);
|
2001-06-27 15:33:55 +00:00
|
|
|
|
|
2001-11-26 16:42:04 +00:00
|
|
|
|
pos_type pos = from.pos();
|
2003-10-09 10:52:12 +00:00
|
|
|
|
int par = from.par();
|
2001-06-27 18:29:18 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
while (par != int(pars_.size()) && (pos != to.pos() || par != to.par())) {
|
|
|
|
|
par_type pit = par;
|
|
|
|
|
if (pos == pars_[pit].size()) {
|
2003-10-09 10:52:12 +00:00
|
|
|
|
++par;
|
2002-07-01 21:50:54 +00:00
|
|
|
|
pos = 0;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2004-03-25 09:16:36 +00:00
|
|
|
|
unsigned char c = pars_[pit].getChar(pos);
|
2003-09-16 12:12:33 +00:00
|
|
|
|
if (c != Paragraph::META_INSET) {
|
2001-06-27 15:33:55 +00:00
|
|
|
|
switch (action) {
|
|
|
|
|
case text_lowercase:
|
2001-10-16 14:47:10 +00:00
|
|
|
|
c = lowercase(c);
|
2001-06-27 15:33:55 +00:00
|
|
|
|
break;
|
|
|
|
|
case text_capitalization:
|
2001-10-16 14:47:10 +00:00
|
|
|
|
c = uppercase(c);
|
2001-06-27 15:33:55 +00:00
|
|
|
|
action = text_lowercase;
|
|
|
|
|
break;
|
|
|
|
|
case text_uppercase:
|
2001-10-16 14:47:10 +00:00
|
|
|
|
c = uppercase(c);
|
2001-06-27 15:33:55 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2003-02-08 19:18:01 +00:00
|
|
|
|
#warning changes
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#endif
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pars_[pit].setChar(pos, c);
|
2001-06-27 18:29:18 +00:00
|
|
|
|
++pos;
|
2001-06-27 15:33:55 +00:00
|
|
|
|
}
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
void LyXText::Delete(LCursor & cur)
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2004-04-13 06:27:29 +00:00
|
|
|
|
if (cur.pos() != cur.lastpos()) {
|
|
|
|
|
recordUndo(cur, Undo::DELETE, cur.par());
|
|
|
|
|
setCursorIntern(cur, cur.par(), cur.pos() + 1, false, cur.boundary());
|
2004-02-12 16:36:01 +00:00
|
|
|
|
backspace(cur);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
2004-04-13 06:27:29 +00:00
|
|
|
|
// should we do anything in an else branch?
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
void LyXText::backspace(LCursor & cur)
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.pos() == 0) {
|
2004-01-09 09:04:33 +00:00
|
|
|
|
// The cursor is at the beginning of a paragraph, so
|
|
|
|
|
// the the backspace will collapse two paragraphs into
|
|
|
|
|
// one.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
// but it's not allowed unless it's new
|
2004-02-13 07:30:59 +00:00
|
|
|
|
Paragraph & par = cur.paragraph();
|
|
|
|
|
if (par.isChangeEdited(0, par.size()))
|
2003-02-08 19:18:01 +00:00
|
|
|
|
return;
|
2003-03-03 23:19:01 +00:00
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
|
// we may paste some paragraphs
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
|
// is it an empty paragraph?
|
2004-02-13 07:30:59 +00:00
|
|
|
|
pos_type lastpos = cur.lastpos();
|
|
|
|
|
if (lastpos == 0 || (lastpos == 1 && par.isSeparator(0))) {
|
2003-08-08 15:48:57 +00:00
|
|
|
|
// This is an empty paragraph and we delete it just
|
|
|
|
|
// by moving the cursor one step
|
|
|
|
|
// left and let the DeleteEmptyParagraphMechanism
|
2003-08-11 09:09:01 +00:00
|
|
|
|
// handle the actual deletion of the paragraph.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.par() != 0) {
|
2004-02-20 17:19:53 +00:00
|
|
|
|
cursorLeft(cur);
|
2003-08-22 12:00:58 +00:00
|
|
|
|
// the layout things can change the height of a row !
|
2004-02-13 07:30:59 +00:00
|
|
|
|
redoParagraph(cur);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-07-24 21:49:58 +00:00
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.par() != 0)
|
|
|
|
|
recordUndo(cur, Undo::DELETE, cur.par() - 1);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
par_type tmppit = cur.par();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// We used to do cursorLeftIntern() here, but it is
|
2000-03-28 02:18:52 +00:00
|
|
|
|
// not a good idea since it triggers the auto-delete
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// mechanism. So we do a cursorLeftIntern()-lite,
|
2000-03-28 02:18:52 +00:00
|
|
|
|
// without the dreaded mechanism. (JMarc)
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.par() != 0) {
|
2000-03-28 02:18:52 +00:00
|
|
|
|
// steps into the above paragraph.
|
2004-02-13 11:05:29 +00:00
|
|
|
|
setCursorIntern(cur, cur.par() - 1,
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pars_[cur.par() - 1].size(),
|
2002-03-21 17:27:08 +00:00
|
|
|
|
false);
|
2000-03-28 02:18:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// Pasting is not allowed, if the paragraphs have different
|
|
|
|
|
// layout. I think it is a real bug of all other
|
|
|
|
|
// word processors to allow it. It confuses the user.
|
2003-08-27 15:38:23 +00:00
|
|
|
|
// Correction: Pasting is always allowed with standard-layout
|
2004-04-08 15:03:33 +00:00
|
|
|
|
Buffer & buf = cur.buffer();
|
2003-09-09 09:47:59 +00:00
|
|
|
|
BufferParams const & bufparams = buf.params();
|
|
|
|
|
LyXTextClass const & tclass = bufparams.getLyXTextClass();
|
2004-03-25 09:16:36 +00:00
|
|
|
|
par_type const cpit = cur.par();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-28 11:18:40 +00:00
|
|
|
|
if (cpit != tmppit
|
2004-03-25 09:16:36 +00:00
|
|
|
|
&& (pars_[cpit].layout() == pars_[tmppit].layout()
|
|
|
|
|
|| pars_[tmppit].layout() == tclass.defaultLayout())
|
|
|
|
|
&& pars_[cpit].getAlign() == pars_[tmppit].getAlign()) {
|
2003-10-28 11:18:40 +00:00
|
|
|
|
mergeParagraph(bufparams, buf.paragraphs(), cpit);
|
2003-08-11 09:09:01 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (cur.pos() != 0 && pars_[cpit].isSeparator(cur.pos() - 1))
|
2004-02-12 16:36:01 +00:00
|
|
|
|
--cur.pos();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-28 11:18:40 +00:00
|
|
|
|
// the counters may have changed
|
2003-08-11 09:09:01 +00:00
|
|
|
|
updateCounters();
|
2004-02-13 11:05:29 +00:00
|
|
|
|
setCursor(cur, cur.par(), cur.pos(), false);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// this is the code for a normal backspace, not pasting
|
2002-06-24 20:28:12 +00:00
|
|
|
|
// any paragraphs
|
2004-02-12 16:36:01 +00:00
|
|
|
|
recordUndo(cur, Undo::DELETE);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// We used to do cursorLeftIntern() here, but it is
|
2000-03-28 16:18:02 +00:00
|
|
|
|
// not a good idea since it triggers the auto-delete
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// mechanism. So we do a cursorLeftIntern()-lite,
|
2000-03-28 16:18:02 +00:00
|
|
|
|
// without the dreaded mechanism. (JMarc)
|
2004-02-13 11:05:29 +00:00
|
|
|
|
setCursorIntern(cur, cur.par(), cur.pos() - 1,
|
2004-02-12 16:36:01 +00:00
|
|
|
|
false, cur.boundary());
|
|
|
|
|
cur.paragraph().erase(cur.pos());
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
2000-05-30 19:31:11 +00:00
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.pos() == cur.lastpos())
|
2004-02-13 11:05:29 +00:00
|
|
|
|
setCurrentFont(cur);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-02-13 07:30:59 +00:00
|
|
|
|
redoParagraph(cur);
|
2004-02-13 11:05:29 +00:00
|
|
|
|
setCursor(cur, cur.par(), cur.pos(), false, cur.boundary());
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
Paragraph & LyXText::getPar(par_type par) const
|
2003-10-09 10:52:12 +00:00
|
|
|
|
{
|
2004-01-30 11:41:12 +00:00
|
|
|
|
//lyxerr << "getPar: " << par << " from " << paragraphs().size() << endl;
|
2003-10-10 09:01:23 +00:00
|
|
|
|
BOOST_ASSERT(par >= 0);
|
2003-12-01 13:35:49 +00:00
|
|
|
|
BOOST_ASSERT(par < int(paragraphs().size()));
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return paragraphs()[par];
|
2003-10-09 10:52:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-06 13:18:49 +00:00
|
|
|
|
// y is relative to this LyXText's top
|
2004-04-21 19:51:18 +00:00
|
|
|
|
Row const & LyXText::getRowNearY(int y, par_type & pit) const
|
2001-11-26 16:42:04 +00:00
|
|
|
|
{
|
2004-02-06 13:18:49 +00:00
|
|
|
|
BOOST_ASSERT(!paragraphs().empty());
|
|
|
|
|
BOOST_ASSERT(!paragraphs().begin()->rows.empty());
|
2004-03-25 09:16:36 +00:00
|
|
|
|
par_type const pend = paragraphs().size() - 1;
|
|
|
|
|
pit = 0;
|
|
|
|
|
while (int(pars_[pit].y + pars_[pit].height) < y && pit != pend)
|
2003-10-28 11:18:40 +00:00
|
|
|
|
++pit;
|
2003-08-15 08:03:54 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
RowList::iterator rit = pars_[pit].rows.end();
|
|
|
|
|
RowList::iterator const rbegin = pars_[pit].rows.begin();
|
2003-11-13 08:50:26 +00:00
|
|
|
|
do {
|
|
|
|
|
--rit;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
} while (rit != rbegin && int(pars_[pit].y + rit->y_offset()) > y);
|
2003-11-22 14:44:59 +00:00
|
|
|
|
|
2004-04-21 19:51:18 +00:00
|
|
|
|
return *rit;
|
2003-08-14 11:16:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-04-21 19:51:18 +00:00
|
|
|
|
Row const & LyXText::firstRow() const
|
2003-08-14 14:10:13 +00:00
|
|
|
|
{
|
2004-04-21 19:51:18 +00:00
|
|
|
|
return *paragraphs().front().rows.begin();
|
2003-08-14 11:16:31 +00:00
|
|
|
|
}
|
2003-10-09 10:52:12 +00:00
|
|
|
|
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
void LyXText::redoParagraphInternal(par_type pit)
|
2003-10-17 10:31:47 +00:00
|
|
|
|
{
|
|
|
|
|
// remove rows of paragraph, keep track of height changes
|
2004-03-25 09:16:36 +00:00
|
|
|
|
height_ -= pars_[pit].height;
|
2003-10-23 08:15:57 +00:00
|
|
|
|
|
|
|
|
|
// clear old data
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pars_[pit].rows.clear();
|
|
|
|
|
pars_[pit].height = 0;
|
|
|
|
|
pars_[pit].width = 0;
|
2003-10-17 10:31:47 +00:00
|
|
|
|
|
|
|
|
|
// redo insets
|
2004-03-25 09:16:36 +00:00
|
|
|
|
InsetList::iterator ii = pars_[pit].insetlist.begin();
|
|
|
|
|
InsetList::iterator iend = pars_[pit].insetlist.end();
|
2003-10-17 10:31:47 +00:00
|
|
|
|
for (; ii != iend; ++ii) {
|
|
|
|
|
Dimension dim;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
int const w = maxwidth_ - leftMargin(pit) - rightMargin(pars_[pit]);
|
2003-11-25 11:17:27 +00:00
|
|
|
|
MetricsInfo mi(bv(), getFont(pit, ii->pos), w);
|
2003-10-17 10:31:47 +00:00
|
|
|
|
ii->inset->metrics(mi, dim);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// rebreak the paragraph
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pars_[pit].setBeginOfBody();
|
2003-10-24 15:04:17 +00:00
|
|
|
|
pos_type z = 0;
|
|
|
|
|
do {
|
2003-10-17 10:31:47 +00:00
|
|
|
|
Row row(z);
|
2003-10-23 15:38:48 +00:00
|
|
|
|
rowBreakPoint(pit, row);
|
2004-02-27 09:18:03 +00:00
|
|
|
|
setRowWidth(pit, row);
|
2003-10-22 16:30:57 +00:00
|
|
|
|
setHeightOfRow(pit, row);
|
2004-03-25 09:16:36 +00:00
|
|
|
|
row.y_offset(pars_[pit].height);
|
|
|
|
|
pars_[pit].rows.push_back(row);
|
|
|
|
|
pars_[pit].width = std::max(pars_[pit].width, row.width());
|
|
|
|
|
pars_[pit].height += row.height();
|
2004-02-27 09:18:03 +00:00
|
|
|
|
z = row.endpos();
|
2004-03-25 09:16:36 +00:00
|
|
|
|
} while (z < pars_[pit].size());
|
2003-10-24 15:04:17 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
height_ += pars_[pit].height;
|
|
|
|
|
//lyxerr << "redoParagraph: " << pars_[pit].rows.size() << " rows\n";
|
2003-10-17 10:31:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
void LyXText::redoParagraphs(par_type pit, par_type end)
|
2003-10-17 10:31:47 +00:00
|
|
|
|
{
|
2004-07-25 00:04:42 +00:00
|
|
|
|
for (; pit != end; ++pit)
|
2003-10-23 08:15:57 +00:00
|
|
|
|
redoParagraphInternal(pit);
|
2003-11-25 11:17:27 +00:00
|
|
|
|
updateParPositions();
|
2004-04-13 17:46:36 +00:00
|
|
|
|
updateCounters();
|
2003-10-17 10:31:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
void LyXText::redoParagraph(par_type pit)
|
2003-10-17 10:31:47 +00:00
|
|
|
|
{
|
|
|
|
|
redoParagraphInternal(pit);
|
2003-11-25 11:17:27 +00:00
|
|
|
|
updateParPositions();
|
2003-10-17 10:31:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXText::fullRebreak()
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
redoParagraphs(0, paragraphs().size());
|
2004-01-20 14:25:24 +00:00
|
|
|
|
bv()->cursor().resetAnchor();
|
2003-10-17 10:31:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
|
|
|
|
|
{
|
|
|
|
|
//BOOST_ASSERT(mi.base.textwidth);
|
2003-11-25 11:17:27 +00:00
|
|
|
|
if (mi.base.textwidth)
|
2004-03-01 16:29:30 +00:00
|
|
|
|
maxwidth_ = mi.base.textwidth;
|
2003-11-25 11:17:27 +00:00
|
|
|
|
//lyxerr << "LyXText::metrics: width: " << mi.base.textwidth
|
2004-03-01 16:29:30 +00:00
|
|
|
|
//<< " maxWidth: " << maxwidth << "\nfont: " << mi.base.font
|
|
|
|
|
//<< endl;
|
2003-10-23 09:06:18 +00:00
|
|
|
|
|
2003-11-25 11:17:27 +00:00
|
|
|
|
// Rebuild row cache. This recomputes height as well.
|
2004-03-25 09:16:36 +00:00
|
|
|
|
redoParagraphs(0, paragraphs().size());
|
2003-10-23 08:15:57 +00:00
|
|
|
|
|
2004-03-01 16:29:30 +00:00
|
|
|
|
width_ = maxParagraphWidth(paragraphs());
|
2003-10-17 10:31:47 +00:00
|
|
|
|
|
|
|
|
|
// final dimension
|
2004-04-21 19:51:18 +00:00
|
|
|
|
dim.asc = firstRow().ascent_of_text();
|
2004-03-01 16:29:30 +00:00
|
|
|
|
dim.des = height_ - dim.asc;
|
|
|
|
|
dim.wid = width_;
|
2003-10-17 10:31:47 +00:00
|
|
|
|
}
|
2003-10-23 08:15:57 +00:00
|
|
|
|
|
|
|
|
|
|
2003-11-28 08:55:12 +00:00
|
|
|
|
// only used for inset right now. should also be used for main text
|
2003-12-15 11:36:19 +00:00
|
|
|
|
void LyXText::draw(PainterInfo & pi, int x, int y) const
|
2003-11-28 08:55:12 +00:00
|
|
|
|
{
|
|
|
|
|
xo_ = x;
|
|
|
|
|
yo_ = y;
|
2004-04-07 20:20:15 +00:00
|
|
|
|
paintTextInset(*this, pi);
|
2003-11-28 08:55:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-06 11:12:49 +00:00
|
|
|
|
// only used for inset right now. should also be used for main text
|
2004-02-13 11:05:29 +00:00
|
|
|
|
void LyXText::drawSelection(PainterInfo &, int, int) const
|
2004-02-06 11:12:49 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
//lyxerr << "LyXText::drawSelection at " << x << " " << y << endl;
|
2004-02-06 11:12:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
bool LyXText::isLastRow(par_type pit, Row const & row) const
|
2003-10-23 08:15:57 +00:00
|
|
|
|
{
|
2004-03-27 01:18:51 +00:00
|
|
|
|
return row.endpos() >= pars_[pit].size()
|
|
|
|
|
&& pit + 1 == par_type(paragraphs().size());
|
2003-10-23 08:15:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
bool LyXText::isFirstRow(par_type pit, Row const & row) const
|
2003-10-23 08:15:57 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return row.pos() == 0 && pit == 0;
|
2003-10-23 08:15:57 +00:00
|
|
|
|
}
|
2003-11-11 10:08:35 +00:00
|
|
|
|
|
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
void LyXText::getWord(CursorSlice & from, CursorSlice & to,
|
|
|
|
|
word_location const loc)
|
2003-11-11 10:08:35 +00:00
|
|
|
|
{
|
2004-07-25 00:04:42 +00:00
|
|
|
|
Paragraph const & from_par = pars_[from.par()];
|
2003-11-11 10:08:35 +00:00
|
|
|
|
switch (loc) {
|
|
|
|
|
case lyx::WHOLE_WORD_STRICT:
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (from.pos() == 0 || from.pos() == from_par.size()
|
2004-06-29 15:43:25 +00:00
|
|
|
|
|| !from_par.isWord(from.pos())
|
|
|
|
|
|| !from_par.isWord(from.pos() - 1)) {
|
2003-11-11 10:08:35 +00:00
|
|
|
|
to = from;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// no break here, we go to the next
|
|
|
|
|
|
|
|
|
|
case lyx::WHOLE_WORD:
|
2004-06-29 15:43:25 +00:00
|
|
|
|
// If we are already at the beginning of a word, do nothing
|
|
|
|
|
if (!from.pos() || !from_par.isWord(from.pos() - 1))
|
|
|
|
|
break;
|
|
|
|
|
// no break here, we go to the next
|
|
|
|
|
|
2003-11-11 10:08:35 +00:00
|
|
|
|
case lyx::PREVIOUS_WORD:
|
|
|
|
|
// always move the cursor to the beginning of previous word
|
2004-06-29 15:43:25 +00:00
|
|
|
|
while (from.pos() && from_par.isWord(from.pos() - 1))
|
|
|
|
|
--from.pos();
|
2003-11-11 10:08:35 +00:00
|
|
|
|
break;
|
|
|
|
|
case lyx::NEXT_WORD:
|
|
|
|
|
lyxerr << "LyXText::getWord: NEXT_WORD not implemented yet"
|
|
|
|
|
<< endl;
|
|
|
|
|
break;
|
|
|
|
|
case lyx::PARTIAL_WORD:
|
2004-06-29 15:43:25 +00:00
|
|
|
|
// no need to move the 'from' cursor
|
2003-11-11 10:08:35 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
to = from;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
Paragraph & to_par = pars_[to.par()];
|
2004-06-29 15:43:25 +00:00
|
|
|
|
while (to.pos() < to_par.size() && to_par.isWord(to.pos()))
|
2004-02-12 16:36:01 +00:00
|
|
|
|
++to.pos();
|
2003-11-11 10:08:35 +00:00
|
|
|
|
}
|
2003-12-02 12:39:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXText::write(Buffer const & buf, std::ostream & os) const
|
|
|
|
|
{
|
|
|
|
|
ParagraphList::const_iterator pit = paragraphs().begin();
|
|
|
|
|
ParagraphList::const_iterator end = paragraphs().end();
|
|
|
|
|
Paragraph::depth_type dth = 0;
|
|
|
|
|
for (; pit != end; ++pit)
|
|
|
|
|
pit->write(buf, os, buf.params(), dth);
|
|
|
|
|
}
|
2003-12-03 15:27:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool LyXText::read(Buffer const & buf, LyXLex & lex)
|
2004-01-28 16:21:29 +00:00
|
|
|
|
{
|
2003-12-03 15:27:16 +00:00
|
|
|
|
static Change current_change;
|
|
|
|
|
|
|
|
|
|
Paragraph::depth_type depth = 0;
|
|
|
|
|
|
|
|
|
|
while (lex.isOK()) {
|
|
|
|
|
lex.nextToken();
|
2004-07-25 00:04:42 +00:00
|
|
|
|
string const token = lex.getString();
|
2003-12-03 15:27:16 +00:00
|
|
|
|
|
|
|
|
|
if (token.empty())
|
|
|
|
|
continue;
|
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
if (token == "\\end_inset") {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2003-12-03 15:27:16 +00:00
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
if (token == "\\end_document") {
|
|
|
|
|
return false;
|
2003-12-03 15:27:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FIXME: ugly.
|
|
|
|
|
int unknown = 0;
|
|
|
|
|
|
|
|
|
|
if (token == "\\begin_layout") {
|
|
|
|
|
lex.pushToken(token);
|
|
|
|
|
|
|
|
|
|
Paragraph par;
|
|
|
|
|
par.params().depth(depth);
|
|
|
|
|
if (buf.params().tracking_changes)
|
|
|
|
|
par.trackChanges();
|
2004-03-18 12:53:43 +00:00
|
|
|
|
par.setFont(0, LyXFont(LyXFont::ALL_INHERIT, buf.params().language));
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pars_.push_back(par);
|
2003-12-03 15:27:16 +00:00
|
|
|
|
|
|
|
|
|
// FIXME: goddamn InsetTabular makes us pass a Buffer
|
|
|
|
|
// not BufferParams
|
2004-03-25 09:16:36 +00:00
|
|
|
|
::readParagraph(buf, pars_.back(), lex);
|
2003-12-03 15:27:16 +00:00
|
|
|
|
|
|
|
|
|
} else if (token == "\\begin_deeper") {
|
|
|
|
|
++depth;
|
|
|
|
|
} else if (token == "\\end_deeper") {
|
|
|
|
|
if (!depth) {
|
|
|
|
|
lex.printError("\\end_deeper: " "depth is already null");
|
|
|
|
|
} else {
|
|
|
|
|
--depth;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
++unknown;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2004-08-14 18:41:27 +00:00
|
|
|
|
return true;
|
2003-12-03 15:27:16 +00:00
|
|
|
|
}
|
2003-12-10 09:45:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int LyXText::ascent() const
|
|
|
|
|
{
|
2004-04-21 19:51:18 +00:00
|
|
|
|
return firstRow().ascent_of_text();
|
2003-12-10 09:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int LyXText::descent() const
|
|
|
|
|
{
|
2004-04-21 19:51:18 +00:00
|
|
|
|
return height_ - firstRow().ascent_of_text();
|
2003-12-10 09:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-12-15 11:36:19 +00:00
|
|
|
|
|
2004-01-13 14:13:51 +00:00
|
|
|
|
int LyXText::cursorX(CursorSlice const & cur) const
|
2003-12-15 11:36:19 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
par_type pit = cur.par();
|
|
|
|
|
if (pars_[pit].rows.empty())
|
2004-01-31 15:30:24 +00:00
|
|
|
|
return xo_;
|
2004-03-01 17:12:09 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
Row const & row = *pars_[pit].getRow(cur.pos());
|
2004-04-03 08:37:12 +00:00
|
|
|
|
|
2004-03-01 12:23:17 +00:00
|
|
|
|
pos_type pos = cur.pos();
|
|
|
|
|
pos_type cursor_vpos = 0;
|
|
|
|
|
|
2004-03-01 16:29:30 +00:00
|
|
|
|
RowMetrics const m = computeRowMetrics(pit, row);
|
2004-03-01 12:23:17 +00:00
|
|
|
|
double x = m.x;
|
|
|
|
|
|
2003-12-15 11:36:19 +00:00
|
|
|
|
pos_type const row_pos = row.pos();
|
|
|
|
|
pos_type const end = row.endpos();
|
|
|
|
|
|
|
|
|
|
if (end <= row_pos)
|
|
|
|
|
cursor_vpos = row_pos;
|
|
|
|
|
else if (pos >= end)
|
2004-03-25 09:16:36 +00:00
|
|
|
|
cursor_vpos = isRTL(pars_[pit]) ? row_pos : end;
|
2003-12-15 11:36:19 +00:00
|
|
|
|
else if (pos > row_pos && pos >= end)
|
|
|
|
|
// Place cursor after char at (logical) position pos - 1
|
|
|
|
|
cursor_vpos = (bidi.level(pos - 1) % 2 == 0)
|
|
|
|
|
? bidi.log2vis(pos - 1) + 1 : bidi.log2vis(pos - 1);
|
|
|
|
|
else
|
|
|
|
|
// Place cursor before char at (logical) position pos
|
|
|
|
|
cursor_vpos = (bidi.level(pos) % 2 == 0)
|
|
|
|
|
? bidi.log2vis(pos) : bidi.log2vis(pos) + 1;
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pos_type body_pos = pars_[pit].beginOfBody();
|
2003-12-15 11:36:19 +00:00
|
|
|
|
if (body_pos > 0 &&
|
2004-03-25 09:16:36 +00:00
|
|
|
|
(body_pos > end || !pars_[pit].isLineSeparator(body_pos - 1)))
|
2003-12-15 11:36:19 +00:00
|
|
|
|
body_pos = 0;
|
|
|
|
|
|
|
|
|
|
for (pos_type vpos = row_pos; vpos < cursor_vpos; ++vpos) {
|
|
|
|
|
pos_type pos = bidi.vis2log(vpos);
|
|
|
|
|
if (body_pos > 0 && pos == body_pos - 1) {
|
2004-03-01 12:23:17 +00:00
|
|
|
|
x += m.label_hfill
|
2004-03-25 09:16:36 +00:00
|
|
|
|
+ font_metrics::width(pars_[pit].layout()->labelsep,
|
2003-12-15 11:36:19 +00:00
|
|
|
|
getLabelFont(pit));
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (pars_[pit].isLineSeparator(body_pos - 1))
|
2003-12-15 11:36:19 +00:00
|
|
|
|
x -= singleWidth(pit, body_pos - 1);
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (hfillExpansion(pars_[pit], row, pos)) {
|
2003-12-15 11:36:19 +00:00
|
|
|
|
x += singleWidth(pit, pos);
|
|
|
|
|
if (pos >= body_pos)
|
2004-03-01 12:23:17 +00:00
|
|
|
|
x += m.hfill;
|
2003-12-15 11:36:19 +00:00
|
|
|
|
else
|
2004-03-01 12:23:17 +00:00
|
|
|
|
x += m.label_hfill;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
} else if (pars_[pit].isSeparator(pos)) {
|
2003-12-15 11:36:19 +00:00
|
|
|
|
x += singleWidth(pit, pos);
|
|
|
|
|
if (pos >= body_pos)
|
2004-03-01 12:23:17 +00:00
|
|
|
|
x += m.separator;
|
2003-12-15 11:36:19 +00:00
|
|
|
|
} else
|
|
|
|
|
x += singleWidth(pit, pos);
|
|
|
|
|
}
|
2004-01-30 11:41:12 +00:00
|
|
|
|
return xo_ + int(x);
|
2003-12-15 11:36:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-13 14:13:51 +00:00
|
|
|
|
int LyXText::cursorY(CursorSlice const & cur) const
|
2003-12-15 11:36:19 +00:00
|
|
|
|
{
|
2004-07-25 00:04:42 +00:00
|
|
|
|
Paragraph const & par = getPar(cur.par());
|
|
|
|
|
Row const & row = *par.getRow(cur.pos());
|
2004-01-30 11:41:12 +00:00
|
|
|
|
return yo_ + par.y + row.y_offset() + row.baseline();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-13 07:30:59 +00:00
|
|
|
|
// Returns the current font and depth as a message.
|
|
|
|
|
string LyXText::currentState(LCursor & cur)
|
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2004-04-08 15:03:33 +00:00
|
|
|
|
Buffer & buf = cur.buffer();
|
2004-02-13 07:30:59 +00:00
|
|
|
|
Paragraph const & par = cur.paragraph();
|
|
|
|
|
std::ostringstream os;
|
|
|
|
|
|
2004-04-08 15:03:33 +00:00
|
|
|
|
bool const show_change = buf.params().tracking_changes
|
2004-02-13 07:30:59 +00:00
|
|
|
|
&& cur.pos() != cur.lastpos()
|
|
|
|
|
&& par.lookupChange(cur.pos()) != Change::UNCHANGED;
|
|
|
|
|
|
|
|
|
|
if (show_change) {
|
|
|
|
|
Change change = par.lookupChangeFull(cur.pos());
|
2004-04-08 15:03:33 +00:00
|
|
|
|
Author const & a = buf.params().authors().get(change.author);
|
2004-02-13 07:30:59 +00:00
|
|
|
|
os << _("Change: ") << a.name();
|
|
|
|
|
if (!a.email().empty())
|
|
|
|
|
os << " (" << a.email() << ")";
|
|
|
|
|
if (change.changetime)
|
|
|
|
|
os << _(" at ") << ctime(&change.changetime);
|
|
|
|
|
os << " : ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// I think we should only show changes from the default
|
|
|
|
|
// font. (Asger)
|
|
|
|
|
LyXFont font = real_current_font;
|
2004-04-08 15:03:33 +00:00
|
|
|
|
font.reduce(buf.params().getLyXTextClass().defaultfont());
|
2004-02-13 07:30:59 +00:00
|
|
|
|
|
|
|
|
|
// avoid _(...) re-entrance problem
|
2004-04-08 15:03:33 +00:00
|
|
|
|
string const s = font.stateText(&buf.params());
|
2004-02-13 07:30:59 +00:00
|
|
|
|
os << bformat(_("Font: %1$s"), s);
|
|
|
|
|
|
2004-04-08 15:03:33 +00:00
|
|
|
|
// os << bformat(_("Font: %1$s"), font.stateText(&buf.params));
|
2004-02-13 07:30:59 +00:00
|
|
|
|
|
|
|
|
|
// The paragraph depth
|
2004-03-18 13:28:49 +00:00
|
|
|
|
int depth = cur.paragraph().getDepth();
|
2004-02-13 07:30:59 +00:00
|
|
|
|
if (depth > 0)
|
|
|
|
|
os << bformat(_(", Depth: %1$s"), tostr(depth));
|
|
|
|
|
|
|
|
|
|
// The paragraph spacing, but only if different from
|
|
|
|
|
// buffer spacing.
|
|
|
|
|
Spacing const & spacing = par.params().spacing();
|
|
|
|
|
if (!spacing.isDefault()) {
|
|
|
|
|
os << _(", Spacing: ");
|
|
|
|
|
switch (spacing.getSpace()) {
|
|
|
|
|
case Spacing::Single:
|
|
|
|
|
os << _("Single");
|
|
|
|
|
break;
|
|
|
|
|
case Spacing::Onehalf:
|
|
|
|
|
os << _("OneHalf");
|
|
|
|
|
break;
|
|
|
|
|
case Spacing::Double:
|
|
|
|
|
os << _("Double");
|
|
|
|
|
break;
|
|
|
|
|
case Spacing::Other:
|
|
|
|
|
os << _("Other (") << spacing.getValue() << ')';
|
|
|
|
|
break;
|
|
|
|
|
case Spacing::Default:
|
|
|
|
|
// should never happen, do nothing
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-08-13 20:26:26 +00:00
|
|
|
|
|
2004-02-13 07:30:59 +00:00
|
|
|
|
#ifdef DEVEL_VERSION
|
2004-04-08 15:03:33 +00:00
|
|
|
|
os << _(", Inset: ") << &cur.inset();
|
|
|
|
|
os << _(", Paragraph: ") << cur.par();
|
|
|
|
|
os << _(", Id: ") << par.id();
|
2004-02-13 07:30:59 +00:00
|
|
|
|
os << _(", Position: ") << cur.pos();
|
|
|
|
|
Row & row = cur.textRow();
|
|
|
|
|
os << bformat(_(", Row b:%1$d e:%2$d"), row.pos(), row.endpos());
|
|
|
|
|
#endif
|
|
|
|
|
return os.str();
|
|
|
|
|
}
|
2004-02-13 13:51:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string LyXText::getPossibleLabel(LCursor & cur) const
|
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
par_type pit = cur.par();
|
2004-02-13 13:51:12 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
LyXLayout_ptr layout = pars_[pit].layout();
|
2004-02-13 13:51:12 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (layout->latextype == LATEX_PARAGRAPH && pit != 0) {
|
|
|
|
|
LyXLayout_ptr const & layout2 = pars_[pit - 1].layout();
|
2004-02-13 13:51:12 +00:00
|
|
|
|
if (layout2->latextype != LATEX_PARAGRAPH) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
--pit;
|
2004-02-13 13:51:12 +00:00
|
|
|
|
layout = layout2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string text = layout->latexname().substr(0, 3);
|
|
|
|
|
if (layout->latexname() == "theorem")
|
|
|
|
|
text = "thm"; // Create a correct prefix for prettyref
|
|
|
|
|
|
|
|
|
|
text += ':';
|
2004-02-16 11:58:51 +00:00
|
|
|
|
if (layout->latextype == LATEX_PARAGRAPH || lyxrc.label_init_length < 0)
|
2004-02-13 13:51:12 +00:00
|
|
|
|
text.erase();
|
|
|
|
|
|
2004-04-08 15:03:33 +00:00
|
|
|
|
string par_text = pars_[pit].asString(cur.buffer(), false);
|
2004-02-13 13:51:12 +00:00
|
|
|
|
for (int i = 0; i < lyxrc.label_init_length; ++i) {
|
|
|
|
|
if (par_text.empty())
|
|
|
|
|
break;
|
|
|
|
|
string head;
|
|
|
|
|
par_text = split(par_text, head, ' ');
|
|
|
|
|
// Is it legal to use spaces in labels ?
|
|
|
|
|
if (i > 0)
|
|
|
|
|
text += '-';
|
|
|
|
|
text += head;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return text;
|
|
|
|
|
}
|
2004-02-16 11:58:51 +00:00
|
|
|
|
|
|
|
|
|
|
2004-08-14 14:03:42 +00:00
|
|
|
|
// Manhattan distance to nearest corner
|
2004-02-16 11:58:51 +00:00
|
|
|
|
int LyXText::dist(int x, int y) const
|
|
|
|
|
{
|
|
|
|
|
int xx = 0;
|
|
|
|
|
int yy = 0;
|
|
|
|
|
|
|
|
|
|
if (x < xo_)
|
|
|
|
|
xx = xo_ - x;
|
2004-03-27 01:18:51 +00:00
|
|
|
|
else if (x > xo_ + int(width_))
|
2004-03-01 16:29:30 +00:00
|
|
|
|
xx = x - xo_ - width_;
|
2004-02-16 11:58:51 +00:00
|
|
|
|
|
|
|
|
|
if (y < yo_ - ascent())
|
|
|
|
|
yy = yo_ - ascent() - y;
|
|
|
|
|
else if (y > yo_ + descent())
|
|
|
|
|
yy = y - yo_ - descent();
|
|
|
|
|
|
|
|
|
|
return xx + yy;
|
|
|
|
|
}
|