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"
|
2005-02-25 11:55:36 +00:00
|
|
|
|
#include "buffer_funcs.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"
|
2006-04-07 22:16:09 +00:00
|
|
|
|
#include "pariterator.h"
|
2004-11-30 01:59:49 +00:00
|
|
|
|
#include "coordcache.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"
|
2004-11-30 01:59:49 +00:00
|
|
|
|
#include "frontends/Painter.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"
|
2005-01-06 16:39:35 +00:00
|
|
|
|
#include "support/convert.h"
|
2004-07-24 10:55:30 +00:00
|
|
|
|
|
2005-09-26 09:20:15 +00:00
|
|
|
|
#include <boost/current_function.hpp>
|
|
|
|
|
|
2004-07-24 10:55:30 +00:00
|
|
|
|
#include <sstream>
|
2001-11-15 00:39:11 +00:00
|
|
|
|
|
2006-04-09 02:30:40 +00:00
|
|
|
|
using lyx::char_type;
|
2004-11-24 21:53:46 +00:00
|
|
|
|
using lyx::pit_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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2006-04-26 13:36:12 +00:00
|
|
|
|
pos_type const last = row.endpos();
|
2004-02-13 13:51:12 +00:00
|
|
|
|
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
|
|
|
|
|
2004-08-16 00:16:17 +00:00
|
|
|
|
void readParToken(Buffer const & buf, Paragraph & par, LyXLex & lex,
|
2005-09-07 10:37:05 +00:00
|
|
|
|
string const & token, LyXFont & font, Change & change)
|
2004-03-25 09:16:36 +00:00
|
|
|
|
{
|
|
|
|
|
BufferParams const & bp = buf.params();
|
|
|
|
|
|
|
|
|
|
if (token[0] != '\\') {
|
|
|
|
|
string::const_iterator cit = token.begin();
|
2005-07-17 23:03:01 +00:00
|
|
|
|
for (; cit != token.end(); ++cit)
|
2004-03-25 09:16:36 +00:00
|
|
|
|
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) {
|
2004-08-16 00:16:17 +00:00
|
|
|
|
buf.error(ErrorItem(_("Unknown layout"),
|
2005-07-17 15:27:49 +00:00
|
|
|
|
bformat(_("Layout '%1$s' does not exist in textclass '%2$s'\nTrying to use the default instead.\n"),
|
2004-08-16 00:16:17 +00:00
|
|
|
|
layoutname, tclass.name()), par.id(), 0, par.size()));
|
2004-03-25 09:16:36 +00:00
|
|
|
|
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") {
|
2005-07-14 08:20:10 +00:00
|
|
|
|
lyxerr << BOOST_CURRENT_FUNCTION
|
2006-04-05 23:56:29 +00:00
|
|
|
|
<< ": Solitary \\end_layout in line "
|
|
|
|
|
<< lex.getLineNo() << "\n"
|
2004-03-25 09:16:36 +00:00
|
|
|
|
<< "Missing \\begin_layout?.\n";
|
|
|
|
|
} else if (token == "\\end_inset") {
|
2005-07-14 08:20:10 +00:00
|
|
|
|
lyxerr << BOOST_CURRENT_FUNCTION
|
2006-04-05 23:56:29 +00:00
|
|
|
|
<< ": Solitary \\end_inset in line "
|
|
|
|
|
<< lex.getLineNo() << "\n"
|
2004-03-25 09:16:36 +00:00
|
|
|
|
<< "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()));
|
|
|
|
|
}
|
|
|
|
|
} 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 ??
|
2006-03-11 13:31:41 +00:00
|
|
|
|
/*
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (!par.size())
|
|
|
|
|
par.cleanChanges();
|
2006-03-11 13:31:41 +00:00
|
|
|
|
*/
|
2004-03-25 09:16:36 +00:00
|
|
|
|
change = Change(Change::UNCHANGED);
|
|
|
|
|
} else if (token == "\\change_inserted") {
|
2004-10-05 12:56:22 +00:00
|
|
|
|
lex.eatLine();
|
2004-03-25 09:16:36 +00:00
|
|
|
|
std::istringstream is(lex.getString());
|
|
|
|
|
int aid;
|
|
|
|
|
lyx::time_type ct;
|
|
|
|
|
is >> aid >> ct;
|
2006-06-07 17:05:25 +00:00
|
|
|
|
if (aid >= bp.author_map.size()) {
|
|
|
|
|
buf.error(ErrorItem(_("Change tracking error"),
|
|
|
|
|
bformat(_("Unknown author index for insertion: %1$d\n"), aid),
|
|
|
|
|
par.id(), 0, par.size()));
|
|
|
|
|
|
|
|
|
|
change = Change(Change::UNCHANGED);
|
|
|
|
|
} else
|
|
|
|
|
change = Change(Change::INSERTED, bp.author_map[aid], ct);
|
2004-03-25 09:16:36 +00:00
|
|
|
|
} else if (token == "\\change_deleted") {
|
2004-10-05 12:56:22 +00:00
|
|
|
|
lex.eatLine();
|
2004-03-25 09:16:36 +00:00
|
|
|
|
std::istringstream is(lex.getString());
|
|
|
|
|
int aid;
|
|
|
|
|
lyx::time_type ct;
|
|
|
|
|
is >> aid >> ct;
|
2006-06-07 17:05:25 +00:00
|
|
|
|
if (aid >= bp.author_map.size()) {
|
|
|
|
|
buf.error(ErrorItem(_("Change tracking error"),
|
|
|
|
|
bformat(_("Unknown author index for deletion: %1$d\n"), aid),
|
|
|
|
|
par.id(), 0, par.size()));
|
|
|
|
|
|
|
|
|
|
change = Change(Change::UNCHANGED);
|
|
|
|
|
} else
|
|
|
|
|
change = Change(Change::DELETED, bp.author_map[aid], ct);
|
2004-03-25 09:16:36 +00:00
|
|
|
|
} else {
|
|
|
|
|
lex.eatLine();
|
|
|
|
|
buf.error(ErrorItem(_("Unknown token"),
|
|
|
|
|
bformat(_("Unknown token: %1$s %2$s\n"), token, lex.getString()),
|
|
|
|
|
par.id(), 0, par.size()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-08-16 00:16:17 +00:00
|
|
|
|
void readParagraph(Buffer const & buf, Paragraph & par, LyXLex & lex)
|
2004-03-25 09:16:36 +00:00
|
|
|
|
{
|
|
|
|
|
lex.nextToken();
|
|
|
|
|
string token = lex.getString();
|
2004-08-15 21:12:21 +00:00
|
|
|
|
LyXFont font;
|
2005-09-07 10:37:05 +00:00
|
|
|
|
Change change;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
|
|
|
|
|
while (lex.isOK()) {
|
|
|
|
|
|
2005-09-07 10:37:05 +00:00
|
|
|
|
readParToken(buf, par, lex, token, font, change);
|
2004-03-25 09:16:36 +00:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-03-11 13:31:41 +00:00
|
|
|
|
// Final change goes to paragraph break:
|
2006-05-08 20:30:52 +00:00
|
|
|
|
par.setChange(par.size(), change);
|
2006-04-05 23:56:29 +00:00
|
|
|
|
|
2005-06-16 15:15:33 +00:00
|
|
|
|
// Initialize begin_of_body_ on load; redoParagraph maintains
|
|
|
|
|
par.setBeginOfBody();
|
2004-03-25 09:16:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-23 09:06:18 +00:00
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-01 16:29:30 +00:00
|
|
|
|
int LyXText::width() const
|
2000-06-12 11:27:15 +00:00
|
|
|
|
{
|
2004-11-30 01:59:49 +00:00
|
|
|
|
return dim_.wid;
|
2004-03-01 16:29:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int LyXText::height() const
|
|
|
|
|
{
|
2004-11-30 01:59:49 +00:00
|
|
|
|
return dim_.height();
|
2000-06-12 11:27:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-10 21:40:13 +00:00
|
|
|
|
|
2004-08-15 00:01:45 +00:00
|
|
|
|
int LyXText::singleWidth(Paragraph const & par, pos_type pos) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-08-15 00:01:45 +00:00
|
|
|
|
return singleWidth(par, pos, par.getChar(pos), getFont(par, pos));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-08-15 00:01:45 +00:00
|
|
|
|
int LyXText::singleWidth(Paragraph const & par,
|
2006-04-09 02:30:40 +00:00
|
|
|
|
pos_type pos, char_type c, LyXFont const & font) const
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
|
|
|
|
// The most common case is handled first (Asger)
|
2006-04-08 09:09:57 +00:00
|
|
|
|
if (isPrintable(c)) {
|
2005-07-16 12:02:31 +00:00
|
|
|
|
Language const * language = font.language();
|
2006-04-09 00:26:19 +00:00
|
|
|
|
if (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)
|
2005-07-16 12:02:31 +00:00
|
|
|
|
&& language->lang() == "arabic") {
|
2006-04-09 00:26:19 +00:00
|
|
|
|
if (Encodings::isComposeChar_arabic(c))
|
2000-07-04 20:32:37 +00:00
|
|
|
|
return 0;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
c = par.transformChar(c, pos);
|
2005-07-16 12:02:31 +00:00
|
|
|
|
} else if (language->lang() == "hebrew" &&
|
2006-04-09 00:26:19 +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-08-14 22:38:45 +00:00
|
|
|
|
return par.getInset(pos)->width();
|
2000-02-10 17:53:36 +00:00
|
|
|
|
|
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-11-24 21:53:46 +00:00
|
|
|
|
int LyXText::leftMargin(pit_type pit) const
|
2003-11-25 11:17:27 +00:00
|
|
|
|
{
|
2004-11-30 01:59:49 +00:00
|
|
|
|
BOOST_ASSERT(pit >= 0);
|
|
|
|
|
BOOST_ASSERT(pit < int(pars_.size()));
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return leftMargin(pit, pars_[pit].size());
|
2003-11-25 11:17:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
|
int LyXText::leftMargin(pit_type const pit, pos_type const pos) const
|
2003-08-26 10:33:59 +00:00
|
|
|
|
{
|
2004-11-30 01:59:49 +00:00
|
|
|
|
BOOST_ASSERT(pit >= 0);
|
|
|
|
|
BOOST_ASSERT(pit < int(pars_.size()));
|
2004-08-14 22:38:45 +00:00
|
|
|
|
Paragraph const & par = pars_[pit];
|
2004-11-30 01:59:49 +00:00
|
|
|
|
BOOST_ASSERT(pos >= 0);
|
|
|
|
|
BOOST_ASSERT(pos <= par.size());
|
|
|
|
|
//lyxerr << "LyXText::leftMargin: pit: " << pit << " pos: " << pos << endl;
|
The Grand Font Selection Redesign:
* lib/lyx2lyx/LyX.py (format_relation): add file format 247 (from Georg BAUM).
* lib/lyx2lyx/lyx_1_5.py: add convert_font_settings, revert_font_settings (from Georg BAUM).
* lib/chkconfig.ltx: Test for newly supported font packages
* lib/doc/LaTeXConfig.lyx.in: document newly supported font packages
* lib/doc/UserGuide.lyx: document new UI.
* lib/doc/Extended.lyx: update PostScript font documentation
* development/FORMAT: document file format change 246->247.
* src/tex-strings.[Ch]: new strings tex_fonts_roman, tex_fonts_sans,
tex_fonts_monospaced (with GUI equivalents).
* src/buffer.C: Format up to 247.
* src/bufferparams.C:
new params fontsRoman, fontsSans, fontsTypewriter, fontsDefaultFamily,
fontsSC, fontsOSF, fontsSansScale and fontsTypewriterScale
(LyXFont const BufferParams::getFont): consider switch of default family.
(string const BufferParams::loadFonts): new method to get all the LaTeX
font stuff done.
* src/paragraph.C
(LyXFont const Paragraph::getFont):
(LyXFont const Paragraph::getLabelFont):
(LyXFont const Paragraph::getLayoutFont): user buffer's not textclass's
default font
* src/text.C
(int LyXText::leftMargin):
(int LyXText::rightMargin): user buffer's not textclass's default font
* src/text2.C
(LyXFont LyXText::getFont):
(LyXFont LyXText::getLayoutFont):
(LyXFont LyXText::getLabelFont): check if the family of the default document
font has been customized.
* src/frontends/gtk/GDocument.[Ch]: implement new font ui (from Georg BAUM).
* src/frontends/gtk/glade/document.glade: implement new font ui (from Georg BAUM).
* src/frontends/qt3/Makefile.dialogs: add new FontModuleBase
* src/frontends/qt3/ui/FontModuleBase.ui: new File
* src/frontends/qt3/ui/TextLayoutModuleBase.ui: remove font widgets
* src/frontends/qt3/QDocument.C
* src/frontends/qt3/QDocumentDialog.[Ch]: implement new font ui
* src/frontends/qt4/Makefile.dialogs: add new FontUi
* src/frontends/qt4/QDocumentDialog.[Ch]: implement new font ui
* src/frontends/qt4/ui/FontUi.ui: new File
* src/frontends/qt4/ui/TextLayoutUi.ui: remove font widgets
* src/frontends/qt4/ui/compile_uic.sh: add new FontUi
* src/frontends/xforms/FormDocument.[Ch]: implement new font ui
* src/frontends/xforms/forms/form_document.fd: add new font tab.
* src/frontends/controllers/ControlDocument.[Ch]
(char ControlDocument::fontfamilies):
(char ControlDocument::fontfamilies_gui):
(bool ControlDocument::isFontAvailable):
(bool ControlDocument::providesSC):
(bool ControlDocument::providesOSF):
(bool ControlDocument::providesScale): new methods, providing font info.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14143 a592a061-630c-0410-9148-cb99ea01b6c8
2006-06-19 08:10:17 +00:00
|
|
|
|
BufferParams const & params = bv()->buffer()->params();
|
|
|
|
|
LyXTextClass const & tclass = params.getLyXTextClass();
|
2004-08-14 22:38:45 +00:00
|
|
|
|
LyXLayout_ptr const & layout = par.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-11-30 01:59:49 +00:00
|
|
|
|
if (isMainText())
|
2004-08-14 15:55:22 +00:00
|
|
|
|
l_margin += changebarMargin();
|
2001-05-03 14:31:33 +00:00
|
|
|
|
|
The Grand Font Selection Redesign:
* lib/lyx2lyx/LyX.py (format_relation): add file format 247 (from Georg BAUM).
* lib/lyx2lyx/lyx_1_5.py: add convert_font_settings, revert_font_settings (from Georg BAUM).
* lib/chkconfig.ltx: Test for newly supported font packages
* lib/doc/LaTeXConfig.lyx.in: document newly supported font packages
* lib/doc/UserGuide.lyx: document new UI.
* lib/doc/Extended.lyx: update PostScript font documentation
* development/FORMAT: document file format change 246->247.
* src/tex-strings.[Ch]: new strings tex_fonts_roman, tex_fonts_sans,
tex_fonts_monospaced (with GUI equivalents).
* src/buffer.C: Format up to 247.
* src/bufferparams.C:
new params fontsRoman, fontsSans, fontsTypewriter, fontsDefaultFamily,
fontsSC, fontsOSF, fontsSansScale and fontsTypewriterScale
(LyXFont const BufferParams::getFont): consider switch of default family.
(string const BufferParams::loadFonts): new method to get all the LaTeX
font stuff done.
* src/paragraph.C
(LyXFont const Paragraph::getFont):
(LyXFont const Paragraph::getLabelFont):
(LyXFont const Paragraph::getLayoutFont): user buffer's not textclass's
default font
* src/text.C
(int LyXText::leftMargin):
(int LyXText::rightMargin): user buffer's not textclass's default font
* src/text2.C
(LyXFont LyXText::getFont):
(LyXFont LyXText::getLayoutFont):
(LyXFont LyXText::getLabelFont): check if the family of the default document
font has been customized.
* src/frontends/gtk/GDocument.[Ch]: implement new font ui (from Georg BAUM).
* src/frontends/gtk/glade/document.glade: implement new font ui (from Georg BAUM).
* src/frontends/qt3/Makefile.dialogs: add new FontModuleBase
* src/frontends/qt3/ui/FontModuleBase.ui: new File
* src/frontends/qt3/ui/TextLayoutModuleBase.ui: remove font widgets
* src/frontends/qt3/QDocument.C
* src/frontends/qt3/QDocumentDialog.[Ch]: implement new font ui
* src/frontends/qt4/Makefile.dialogs: add new FontUi
* src/frontends/qt4/QDocumentDialog.[Ch]: implement new font ui
* src/frontends/qt4/ui/FontUi.ui: new File
* src/frontends/qt4/ui/TextLayoutUi.ui: remove font widgets
* src/frontends/qt4/ui/compile_uic.sh: add new FontUi
* src/frontends/xforms/FormDocument.[Ch]: implement new font ui
* src/frontends/xforms/forms/form_document.fd: add new font tab.
* src/frontends/controllers/ControlDocument.[Ch]
(char ControlDocument::fontfamilies):
(char ControlDocument::fontfamilies_gui):
(bool ControlDocument::isFontAvailable):
(bool ControlDocument::providesSC):
(bool ControlDocument::providesOSF):
(bool ControlDocument::providesScale): new methods, providing font info.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14143 a592a061-630c-0410-9148-cb99ea01b6c8
2006-06-19 08:10:17 +00:00
|
|
|
|
l_margin += font_metrics::signedWidth(tclass.leftmargin(), params.getFont());
|
2004-08-14 15:55:22 +00:00
|
|
|
|
|
2004-08-14 22:38:45 +00:00
|
|
|
|
if (par.getDepth() != 0) {
|
2005-11-17 09:19:02 +00:00
|
|
|
|
// find the next level paragraph
|
|
|
|
|
pit_type newpar = outerHook(pit, pars_);
|
2004-11-24 21:53:46 +00:00
|
|
|
|
if (newpar != pit_type(pars_.size())) {
|
2004-08-14 15:55:22 +00:00
|
|
|
|
if (pars_[newpar].layout()->isEnvironment()) {
|
|
|
|
|
l_margin = leftMargin(newpar);
|
|
|
|
|
}
|
2004-08-14 22:38:45 +00:00
|
|
|
|
if (par.layout() == tclass.defaultLayout()) {
|
2004-08-14 15:55:22 +00:00
|
|
|
|
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
|
|
|
|
|
2005-11-17 09:19:02 +00:00
|
|
|
|
// This happens after sections in standard classes. The 1.3.x
|
|
|
|
|
// code compared depths too, but it does not seem necessary
|
|
|
|
|
// (JMarc)
|
|
|
|
|
if (par.layout() == tclass.defaultLayout()
|
|
|
|
|
&& pit > 0 && pars_[pit - 1].layout()->nextnoindent)
|
|
|
|
|
parindent.erase();
|
|
|
|
|
|
2004-08-15 00:01:45 +00:00
|
|
|
|
LyXFont const labelfont = getLabelFont(par);
|
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())
|
The Grand Font Selection Redesign:
* lib/lyx2lyx/LyX.py (format_relation): add file format 247 (from Georg BAUM).
* lib/lyx2lyx/lyx_1_5.py: add convert_font_settings, revert_font_settings (from Georg BAUM).
* lib/chkconfig.ltx: Test for newly supported font packages
* lib/doc/LaTeXConfig.lyx.in: document newly supported font packages
* lib/doc/UserGuide.lyx: document new UI.
* lib/doc/Extended.lyx: update PostScript font documentation
* development/FORMAT: document file format change 246->247.
* src/tex-strings.[Ch]: new strings tex_fonts_roman, tex_fonts_sans,
tex_fonts_monospaced (with GUI equivalents).
* src/buffer.C: Format up to 247.
* src/bufferparams.C:
new params fontsRoman, fontsSans, fontsTypewriter, fontsDefaultFamily,
fontsSC, fontsOSF, fontsSansScale and fontsTypewriterScale
(LyXFont const BufferParams::getFont): consider switch of default family.
(string const BufferParams::loadFonts): new method to get all the LaTeX
font stuff done.
* src/paragraph.C
(LyXFont const Paragraph::getFont):
(LyXFont const Paragraph::getLabelFont):
(LyXFont const Paragraph::getLayoutFont): user buffer's not textclass's
default font
* src/text.C
(int LyXText::leftMargin):
(int LyXText::rightMargin): user buffer's not textclass's default font
* src/text2.C
(LyXFont LyXText::getFont):
(LyXFont LyXText::getLayoutFont):
(LyXFont LyXText::getLabelFont): check if the family of the default document
font has been customized.
* src/frontends/gtk/GDocument.[Ch]: implement new font ui (from Georg BAUM).
* src/frontends/gtk/glade/document.glade: implement new font ui (from Georg BAUM).
* src/frontends/qt3/Makefile.dialogs: add new FontModuleBase
* src/frontends/qt3/ui/FontModuleBase.ui: new File
* src/frontends/qt3/ui/TextLayoutModuleBase.ui: remove font widgets
* src/frontends/qt3/QDocument.C
* src/frontends/qt3/QDocumentDialog.[Ch]: implement new font ui
* src/frontends/qt4/Makefile.dialogs: add new FontUi
* src/frontends/qt4/QDocumentDialog.[Ch]: implement new font ui
* src/frontends/qt4/ui/FontUi.ui: new File
* src/frontends/qt4/ui/TextLayoutUi.ui: remove font widgets
* src/frontends/qt4/ui/compile_uic.sh: add new FontUi
* src/frontends/xforms/FormDocument.[Ch]: implement new font ui
* src/frontends/xforms/forms/form_document.fd: add new font tab.
* src/frontends/controllers/ControlDocument.[Ch]
(char ControlDocument::fontfamilies):
(char ControlDocument::fontfamilies_gui):
(bool ControlDocument::isFontAvailable):
(bool ControlDocument::providesSC):
(bool ControlDocument::providesOSF):
(bool ControlDocument::providesScale): new methods, providing font info.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14143 a592a061-630c-0410-9148-cb99ea01b6c8
2006-06-19 08:10:17 +00:00
|
|
|
|
l_margin += font_metrics::signedWidth(layout->leftmargin,
|
|
|
|
|
params.getFont());
|
2004-08-14 22:38:45 +00:00
|
|
|
|
if (!par.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 22:38:45 +00:00
|
|
|
|
l_margin += font_metrics::width(par.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-08-14 22:38:45 +00:00
|
|
|
|
if (!par.empty() && pos >= par.beginOfBody()) {
|
|
|
|
|
if (!par.getLabelWidthString().empty()) {
|
|
|
|
|
l_margin += font_metrics::width(par.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:
|
The Grand Font Selection Redesign:
* lib/lyx2lyx/LyX.py (format_relation): add file format 247 (from Georg BAUM).
* lib/lyx2lyx/lyx_1_5.py: add convert_font_settings, revert_font_settings (from Georg BAUM).
* lib/chkconfig.ltx: Test for newly supported font packages
* lib/doc/LaTeXConfig.lyx.in: document newly supported font packages
* lib/doc/UserGuide.lyx: document new UI.
* lib/doc/Extended.lyx: update PostScript font documentation
* development/FORMAT: document file format change 246->247.
* src/tex-strings.[Ch]: new strings tex_fonts_roman, tex_fonts_sans,
tex_fonts_monospaced (with GUI equivalents).
* src/buffer.C: Format up to 247.
* src/bufferparams.C:
new params fontsRoman, fontsSans, fontsTypewriter, fontsDefaultFamily,
fontsSC, fontsOSF, fontsSansScale and fontsTypewriterScale
(LyXFont const BufferParams::getFont): consider switch of default family.
(string const BufferParams::loadFonts): new method to get all the LaTeX
font stuff done.
* src/paragraph.C
(LyXFont const Paragraph::getFont):
(LyXFont const Paragraph::getLabelFont):
(LyXFont const Paragraph::getLayoutFont): user buffer's not textclass's
default font
* src/text.C
(int LyXText::leftMargin):
(int LyXText::rightMargin): user buffer's not textclass's default font
* src/text2.C
(LyXFont LyXText::getFont):
(LyXFont LyXText::getLayoutFont):
(LyXFont LyXText::getLabelFont): check if the family of the default document
font has been customized.
* src/frontends/gtk/GDocument.[Ch]: implement new font ui (from Georg BAUM).
* src/frontends/gtk/glade/document.glade: implement new font ui (from Georg BAUM).
* src/frontends/qt3/Makefile.dialogs: add new FontModuleBase
* src/frontends/qt3/ui/FontModuleBase.ui: new File
* src/frontends/qt3/ui/TextLayoutModuleBase.ui: remove font widgets
* src/frontends/qt3/QDocument.C
* src/frontends/qt3/QDocumentDialog.[Ch]: implement new font ui
* src/frontends/qt4/Makefile.dialogs: add new FontUi
* src/frontends/qt4/QDocumentDialog.[Ch]: implement new font ui
* src/frontends/qt4/ui/FontUi.ui: new File
* src/frontends/qt4/ui/TextLayoutUi.ui: remove font widgets
* src/frontends/qt4/ui/compile_uic.sh: add new FontUi
* src/frontends/xforms/FormDocument.[Ch]: implement new font ui
* src/frontends/xforms/forms/form_document.fd: add new font tab.
* src/frontends/controllers/ControlDocument.[Ch]
(char ControlDocument::fontfamilies):
(char ControlDocument::fontfamilies_gui):
(bool ControlDocument::isFontAvailable):
(bool ControlDocument::providesSC):
(bool ControlDocument::providesOSF):
(bool ControlDocument::providesScale): new methods, providing font info.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14143 a592a061-630c-0410-9148-cb99ea01b6c8
2006-06-19 08:10:17 +00:00
|
|
|
|
l_margin += font_metrics::signedWidth(layout->leftmargin, params.getFont()) * 4
|
2004-08-14 22:38:45 +00:00
|
|
|
|
/ (par.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-08-14 22:38:45 +00:00
|
|
|
|
if (pos >= par.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);
|
2004-08-14 22:38:45 +00:00
|
|
|
|
l_margin += font_metrics::width(par.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-11-30 01:59:49 +00:00
|
|
|
|
RowList::iterator rit = par.rows().begin();
|
|
|
|
|
RowList::iterator end = par.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,
|
The Grand Font Selection Redesign:
* lib/lyx2lyx/LyX.py (format_relation): add file format 247 (from Georg BAUM).
* lib/lyx2lyx/lyx_1_5.py: add convert_font_settings, revert_font_settings (from Georg BAUM).
* lib/chkconfig.ltx: Test for newly supported font packages
* lib/doc/LaTeXConfig.lyx.in: document newly supported font packages
* lib/doc/UserGuide.lyx: document new UI.
* lib/doc/Extended.lyx: update PostScript font documentation
* development/FORMAT: document file format change 246->247.
* src/tex-strings.[Ch]: new strings tex_fonts_roman, tex_fonts_sans,
tex_fonts_monospaced (with GUI equivalents).
* src/buffer.C: Format up to 247.
* src/bufferparams.C:
new params fontsRoman, fontsSans, fontsTypewriter, fontsDefaultFamily,
fontsSC, fontsOSF, fontsSansScale and fontsTypewriterScale
(LyXFont const BufferParams::getFont): consider switch of default family.
(string const BufferParams::loadFonts): new method to get all the LaTeX
font stuff done.
* src/paragraph.C
(LyXFont const Paragraph::getFont):
(LyXFont const Paragraph::getLabelFont):
(LyXFont const Paragraph::getLayoutFont): user buffer's not textclass's
default font
* src/text.C
(int LyXText::leftMargin):
(int LyXText::rightMargin): user buffer's not textclass's default font
* src/text2.C
(LyXFont LyXText::getFont):
(LyXFont LyXText::getLayoutFont):
(LyXFont LyXText::getLabelFont): check if the family of the default document
font has been customized.
* src/frontends/gtk/GDocument.[Ch]: implement new font ui (from Georg BAUM).
* src/frontends/gtk/glade/document.glade: implement new font ui (from Georg BAUM).
* src/frontends/qt3/Makefile.dialogs: add new FontModuleBase
* src/frontends/qt3/ui/FontModuleBase.ui: new File
* src/frontends/qt3/ui/TextLayoutModuleBase.ui: remove font widgets
* src/frontends/qt3/QDocument.C
* src/frontends/qt3/QDocumentDialog.[Ch]: implement new font ui
* src/frontends/qt4/Makefile.dialogs: add new FontUi
* src/frontends/qt4/QDocumentDialog.[Ch]: implement new font ui
* src/frontends/qt4/ui/FontUi.ui: new File
* src/frontends/qt4/ui/TextLayoutUi.ui: remove font widgets
* src/frontends/qt4/ui/compile_uic.sh: add new FontUi
* src/frontends/xforms/FormDocument.[Ch]: implement new font ui
* src/frontends/xforms/forms/form_document.fd: add new font tab.
* src/frontends/controllers/ControlDocument.[Ch]
(char ControlDocument::fontfamilies):
(char ControlDocument::fontfamilies_gui):
(bool ControlDocument::isFontAvailable):
(bool ControlDocument::providesSC):
(bool ControlDocument::providesOSF):
(bool ControlDocument::providesScale): new methods, providing font info.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14143 a592a061-630c-0410-9148-cb99ea01b6c8
2006-06-19 08:10:17 +00:00
|
|
|
|
params.getFont());
|
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-08-14 22:38:45 +00:00
|
|
|
|
if (!par.params().leftIndent().zero())
|
|
|
|
|
l_margin += par.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-08-14 22:38:45 +00:00
|
|
|
|
if (par.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-08-14 22:38:45 +00:00
|
|
|
|
align = par.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
|
2006-04-05 23:56:29 +00:00
|
|
|
|
&& layout->latextype == LATEX_ENVIRONMENT
|
|
|
|
|
&& !isFirstInSequence(pit, pars_)))
|
2003-12-03 18:17:20 +00:00
|
|
|
|
&& align == LYX_ALIGN_BLOCK
|
2004-08-14 22:38:45 +00:00
|
|
|
|
&& !par.params().noindent()
|
2005-09-10 06:51:58 +00:00
|
|
|
|
// in some insets, paragraphs are never indented
|
2005-09-10 13:29:44 +00:00
|
|
|
|
&& !(par.inInset() && par.inInset()->neverIndent())
|
2005-07-06 06:56:38 +00:00
|
|
|
|
// display style insets are always centered, omit indentation
|
|
|
|
|
&& !(!par.empty()
|
|
|
|
|
&& par.isInset(pos)
|
|
|
|
|
&& par.getInset(pos)->display())
|
2004-08-14 22:38:45 +00:00
|
|
|
|
&& (par.layout() != tclass.defaultLayout()
|
2006-04-05 23:56:29 +00:00
|
|
|
|
|| bv()->buffer()->params().paragraph_separation ==
|
|
|
|
|
BufferParams::PARSEP_INDENT))
|
2003-12-03 18:17:20 +00:00
|
|
|
|
{
|
The Grand Font Selection Redesign:
* lib/lyx2lyx/LyX.py (format_relation): add file format 247 (from Georg BAUM).
* lib/lyx2lyx/lyx_1_5.py: add convert_font_settings, revert_font_settings (from Georg BAUM).
* lib/chkconfig.ltx: Test for newly supported font packages
* lib/doc/LaTeXConfig.lyx.in: document newly supported font packages
* lib/doc/UserGuide.lyx: document new UI.
* lib/doc/Extended.lyx: update PostScript font documentation
* development/FORMAT: document file format change 246->247.
* src/tex-strings.[Ch]: new strings tex_fonts_roman, tex_fonts_sans,
tex_fonts_monospaced (with GUI equivalents).
* src/buffer.C: Format up to 247.
* src/bufferparams.C:
new params fontsRoman, fontsSans, fontsTypewriter, fontsDefaultFamily,
fontsSC, fontsOSF, fontsSansScale and fontsTypewriterScale
(LyXFont const BufferParams::getFont): consider switch of default family.
(string const BufferParams::loadFonts): new method to get all the LaTeX
font stuff done.
* src/paragraph.C
(LyXFont const Paragraph::getFont):
(LyXFont const Paragraph::getLabelFont):
(LyXFont const Paragraph::getLayoutFont): user buffer's not textclass's
default font
* src/text.C
(int LyXText::leftMargin):
(int LyXText::rightMargin): user buffer's not textclass's default font
* src/text2.C
(LyXFont LyXText::getFont):
(LyXFont LyXText::getLayoutFont):
(LyXFont LyXText::getLabelFont): check if the family of the default document
font has been customized.
* src/frontends/gtk/GDocument.[Ch]: implement new font ui (from Georg BAUM).
* src/frontends/gtk/glade/document.glade: implement new font ui (from Georg BAUM).
* src/frontends/qt3/Makefile.dialogs: add new FontModuleBase
* src/frontends/qt3/ui/FontModuleBase.ui: new File
* src/frontends/qt3/ui/TextLayoutModuleBase.ui: remove font widgets
* src/frontends/qt3/QDocument.C
* src/frontends/qt3/QDocumentDialog.[Ch]: implement new font ui
* src/frontends/qt4/Makefile.dialogs: add new FontUi
* src/frontends/qt4/QDocumentDialog.[Ch]: implement new font ui
* src/frontends/qt4/ui/FontUi.ui: new File
* src/frontends/qt4/ui/TextLayoutUi.ui: remove font widgets
* src/frontends/qt4/ui/compile_uic.sh: add new FontUi
* src/frontends/xforms/FormDocument.[Ch]: implement new font ui
* src/frontends/xforms/forms/form_document.fd: add new font tab.
* src/frontends/controllers/ControlDocument.[Ch]
(char ControlDocument::fontfamilies):
(char ControlDocument::fontfamilies_gui):
(bool ControlDocument::isFontAvailable):
(bool ControlDocument::providesSC):
(bool ControlDocument::providesOSF):
(bool ControlDocument::providesScale): new methods, providing font info.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14143 a592a061-630c-0410-9148-cb99ea01b6c8
2006-06-19 08:10:17 +00:00
|
|
|
|
l_margin += font_metrics::signedWidth(parindent, params.getFont());
|
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
|
|
|
|
{
|
2004-08-14 15:55:22 +00:00
|
|
|
|
// We do not want rightmargins on inner texts.
|
|
|
|
|
if (bv()->text() != this)
|
|
|
|
|
return 0;
|
|
|
|
|
|
The Grand Font Selection Redesign:
* lib/lyx2lyx/LyX.py (format_relation): add file format 247 (from Georg BAUM).
* lib/lyx2lyx/lyx_1_5.py: add convert_font_settings, revert_font_settings (from Georg BAUM).
* lib/chkconfig.ltx: Test for newly supported font packages
* lib/doc/LaTeXConfig.lyx.in: document newly supported font packages
* lib/doc/UserGuide.lyx: document new UI.
* lib/doc/Extended.lyx: update PostScript font documentation
* development/FORMAT: document file format change 246->247.
* src/tex-strings.[Ch]: new strings tex_fonts_roman, tex_fonts_sans,
tex_fonts_monospaced (with GUI equivalents).
* src/buffer.C: Format up to 247.
* src/bufferparams.C:
new params fontsRoman, fontsSans, fontsTypewriter, fontsDefaultFamily,
fontsSC, fontsOSF, fontsSansScale and fontsTypewriterScale
(LyXFont const BufferParams::getFont): consider switch of default family.
(string const BufferParams::loadFonts): new method to get all the LaTeX
font stuff done.
* src/paragraph.C
(LyXFont const Paragraph::getFont):
(LyXFont const Paragraph::getLabelFont):
(LyXFont const Paragraph::getLayoutFont): user buffer's not textclass's
default font
* src/text.C
(int LyXText::leftMargin):
(int LyXText::rightMargin): user buffer's not textclass's default font
* src/text2.C
(LyXFont LyXText::getFont):
(LyXFont LyXText::getLayoutFont):
(LyXFont LyXText::getLabelFont): check if the family of the default document
font has been customized.
* src/frontends/gtk/GDocument.[Ch]: implement new font ui (from Georg BAUM).
* src/frontends/gtk/glade/document.glade: implement new font ui (from Georg BAUM).
* src/frontends/qt3/Makefile.dialogs: add new FontModuleBase
* src/frontends/qt3/ui/FontModuleBase.ui: new File
* src/frontends/qt3/ui/TextLayoutModuleBase.ui: remove font widgets
* src/frontends/qt3/QDocument.C
* src/frontends/qt3/QDocumentDialog.[Ch]: implement new font ui
* src/frontends/qt4/Makefile.dialogs: add new FontUi
* src/frontends/qt4/QDocumentDialog.[Ch]: implement new font ui
* src/frontends/qt4/ui/FontUi.ui: new File
* src/frontends/qt4/ui/TextLayoutUi.ui: remove font widgets
* src/frontends/qt4/ui/compile_uic.sh: add new FontUi
* src/frontends/xforms/FormDocument.[Ch]: implement new font ui
* src/frontends/xforms/forms/form_document.fd: add new font tab.
* src/frontends/controllers/ControlDocument.[Ch]
(char ControlDocument::fontfamilies):
(char ControlDocument::fontfamilies_gui):
(bool ControlDocument::isFontAvailable):
(bool ControlDocument::providesSC):
(bool ControlDocument::providesOSF):
(bool ControlDocument::providesScale): new methods, providing font info.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14143 a592a061-630c-0410-9148-cb99ea01b6c8
2006-06-19 08:10:17 +00:00
|
|
|
|
BufferParams const & params = bv()->buffer()->params();
|
|
|
|
|
LyXTextClass const & tclass = params.getLyXTextClass();
|
2004-08-14 15:55:22 +00:00
|
|
|
|
int const r_margin =
|
|
|
|
|
::rightMargin()
|
2002-05-24 14:34:32 +00:00
|
|
|
|
+ font_metrics::signedWidth(tclass.rightmargin(),
|
The Grand Font Selection Redesign:
* lib/lyx2lyx/LyX.py (format_relation): add file format 247 (from Georg BAUM).
* lib/lyx2lyx/lyx_1_5.py: add convert_font_settings, revert_font_settings (from Georg BAUM).
* lib/chkconfig.ltx: Test for newly supported font packages
* lib/doc/LaTeXConfig.lyx.in: document newly supported font packages
* lib/doc/UserGuide.lyx: document new UI.
* lib/doc/Extended.lyx: update PostScript font documentation
* development/FORMAT: document file format change 246->247.
* src/tex-strings.[Ch]: new strings tex_fonts_roman, tex_fonts_sans,
tex_fonts_monospaced (with GUI equivalents).
* src/buffer.C: Format up to 247.
* src/bufferparams.C:
new params fontsRoman, fontsSans, fontsTypewriter, fontsDefaultFamily,
fontsSC, fontsOSF, fontsSansScale and fontsTypewriterScale
(LyXFont const BufferParams::getFont): consider switch of default family.
(string const BufferParams::loadFonts): new method to get all the LaTeX
font stuff done.
* src/paragraph.C
(LyXFont const Paragraph::getFont):
(LyXFont const Paragraph::getLabelFont):
(LyXFont const Paragraph::getLayoutFont): user buffer's not textclass's
default font
* src/text.C
(int LyXText::leftMargin):
(int LyXText::rightMargin): user buffer's not textclass's default font
* src/text2.C
(LyXFont LyXText::getFont):
(LyXFont LyXText::getLayoutFont):
(LyXFont LyXText::getLabelFont): check if the family of the default document
font has been customized.
* src/frontends/gtk/GDocument.[Ch]: implement new font ui (from Georg BAUM).
* src/frontends/gtk/glade/document.glade: implement new font ui (from Georg BAUM).
* src/frontends/qt3/Makefile.dialogs: add new FontModuleBase
* src/frontends/qt3/ui/FontModuleBase.ui: new File
* src/frontends/qt3/ui/TextLayoutModuleBase.ui: remove font widgets
* src/frontends/qt3/QDocument.C
* src/frontends/qt3/QDocumentDialog.[Ch]: implement new font ui
* src/frontends/qt4/Makefile.dialogs: add new FontUi
* src/frontends/qt4/QDocumentDialog.[Ch]: implement new font ui
* src/frontends/qt4/ui/FontUi.ui: new File
* src/frontends/qt4/ui/TextLayoutUi.ui: remove font widgets
* src/frontends/qt4/ui/compile_uic.sh: add new FontUi
* src/frontends/xforms/FormDocument.[Ch]: implement new font ui
* src/frontends/xforms/forms/form_document.fd: add new font tab.
* src/frontends/controllers/ControlDocument.[Ch]
(char ControlDocument::fontfamilies):
(char ControlDocument::fontfamilies_gui):
(bool ControlDocument::isFontAvailable):
(bool ControlDocument::providesSC):
(bool ControlDocument::providesOSF):
(bool ControlDocument::providesScale): new methods, providing font info.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14143 a592a061-630c-0410-9148-cb99ea01b6c8
2006-06-19 08:10:17 +00:00
|
|
|
|
params.getFont())
|
2003-11-25 11:17:27 +00:00
|
|
|
|
+ font_metrics::signedWidth(par.layout()->rightmargin,
|
The Grand Font Selection Redesign:
* lib/lyx2lyx/LyX.py (format_relation): add file format 247 (from Georg BAUM).
* lib/lyx2lyx/lyx_1_5.py: add convert_font_settings, revert_font_settings (from Georg BAUM).
* lib/chkconfig.ltx: Test for newly supported font packages
* lib/doc/LaTeXConfig.lyx.in: document newly supported font packages
* lib/doc/UserGuide.lyx: document new UI.
* lib/doc/Extended.lyx: update PostScript font documentation
* development/FORMAT: document file format change 246->247.
* src/tex-strings.[Ch]: new strings tex_fonts_roman, tex_fonts_sans,
tex_fonts_monospaced (with GUI equivalents).
* src/buffer.C: Format up to 247.
* src/bufferparams.C:
new params fontsRoman, fontsSans, fontsTypewriter, fontsDefaultFamily,
fontsSC, fontsOSF, fontsSansScale and fontsTypewriterScale
(LyXFont const BufferParams::getFont): consider switch of default family.
(string const BufferParams::loadFonts): new method to get all the LaTeX
font stuff done.
* src/paragraph.C
(LyXFont const Paragraph::getFont):
(LyXFont const Paragraph::getLabelFont):
(LyXFont const Paragraph::getLayoutFont): user buffer's not textclass's
default font
* src/text.C
(int LyXText::leftMargin):
(int LyXText::rightMargin): user buffer's not textclass's default font
* src/text2.C
(LyXFont LyXText::getFont):
(LyXFont LyXText::getLayoutFont):
(LyXFont LyXText::getLabelFont): check if the family of the default document
font has been customized.
* src/frontends/gtk/GDocument.[Ch]: implement new font ui (from Georg BAUM).
* src/frontends/gtk/glade/document.glade: implement new font ui (from Georg BAUM).
* src/frontends/qt3/Makefile.dialogs: add new FontModuleBase
* src/frontends/qt3/ui/FontModuleBase.ui: new File
* src/frontends/qt3/ui/TextLayoutModuleBase.ui: remove font widgets
* src/frontends/qt3/QDocument.C
* src/frontends/qt3/QDocumentDialog.[Ch]: implement new font ui
* src/frontends/qt4/Makefile.dialogs: add new FontUi
* src/frontends/qt4/QDocumentDialog.[Ch]: implement new font ui
* src/frontends/qt4/ui/FontUi.ui: new File
* src/frontends/qt4/ui/TextLayoutUi.ui: remove font widgets
* src/frontends/qt4/ui/compile_uic.sh: add new FontUi
* src/frontends/xforms/FormDocument.[Ch]: implement new font ui
* src/frontends/xforms/forms/form_document.fd: add new font tab.
* src/frontends/controllers/ControlDocument.[Ch]
(char ControlDocument::fontfamilies):
(char ControlDocument::fontfamilies_gui):
(bool ControlDocument::isFontAvailable):
(bool ControlDocument::providesSC):
(bool ControlDocument::providesOSF):
(bool ControlDocument::providesScale): new methods, providing font info.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14143 a592a061-630c-0410-9148-cb99ea01b6c8
2006-06-19 08:10:17 +00:00
|
|
|
|
params.getFont())
|
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-11-24 21:53:46 +00:00
|
|
|
|
int LyXText::labelEnd(pit_type const 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-11-24 21:53:46 +00:00
|
|
|
|
void LyXText::rowBreakPoint(pit_type const pit, Row & row) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-08-14 22:38:45 +00:00
|
|
|
|
Paragraph const & par = pars_[pit];
|
|
|
|
|
pos_type const end = par.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-08-14 22:38:45 +00:00
|
|
|
|
int width = maxwidth_ - rightMargin(par); // - 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-08-14 22:38:45 +00:00
|
|
|
|
LyXLayout_ptr const & layout = par.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-08-14 22:38:45 +00:00
|
|
|
|
row.endpos(addressBreakPoint(pos, par));
|
2003-10-23 15:38:48 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-08-14 22:38:45 +00:00
|
|
|
|
pos_type const body_pos = par.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-11-30 01:59:49 +00:00
|
|
|
|
FontIterator fi = FontIterator(*this, par, 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) {
|
2006-04-09 02:30:40 +00:00
|
|
|
|
char_type const c = par.getChar(i);
|
2005-07-18 12:13:32 +00:00
|
|
|
|
int thiswidth = singleWidth(par, i, c, *fi);
|
2003-10-29 10:47:21 +00:00
|
|
|
|
|
2005-07-18 12:13:32 +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(par));
|
|
|
|
|
if (par.isLineSeparator(i - 1))
|
|
|
|
|
add -= singleWidth(par, i - 1);
|
2003-03-09 21:54:56 +00:00
|
|
|
|
|
2005-07-18 12:13:32 +00:00
|
|
|
|
add = std::max(add, labelEnd(pit) - x);
|
|
|
|
|
thiswidth += add;
|
2003-10-27 10:27:50 +00:00
|
|
|
|
}
|
2003-10-29 10:47:21 +00:00
|
|
|
|
|
2005-07-18 12:13:32 +00:00
|
|
|
|
x += thiswidth;
|
|
|
|
|
chunkwidth += thiswidth;
|
|
|
|
|
|
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-08-14 22:38:45 +00:00
|
|
|
|
if (par.isNewline(i)) {
|
2004-03-01 17:25:16 +00:00
|
|
|
|
point = i + 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// Break before...
|
|
|
|
|
if (i + 1 < end) {
|
2004-08-14 22:38:45 +00:00
|
|
|
|
if (par.isInset(i + 1) && par.getInset(i + 1)->display()) {
|
2004-03-01 17:25:16 +00:00
|
|
|
|
point = i + 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// ...and after.
|
2004-08-14 22:38:45 +00:00
|
|
|
|
if (par.isInset(i) && par.getInset(i)->display()) {
|
2004-03-01 17:25:16 +00:00
|
|
|
|
point = i + 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-04-03 08:37:12 +00:00
|
|
|
|
|
2004-08-14 22:38:45 +00:00
|
|
|
|
if (!par.isInset(i) || par.getInset(i)->isChar()) {
|
2003-03-09 21:54:56 +00:00
|
|
|
|
// some insets are line separators too
|
2004-08-14 22:38:45 +00:00
|
|
|
|
if (par.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-11-24 21:53:46 +00:00
|
|
|
|
void LyXText::setRowWidth(pit_type const 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-08-14 22:38:45 +00:00
|
|
|
|
Paragraph const & par = pars_[pit];
|
2005-07-14 08:20:10 +00:00
|
|
|
|
string const & labelsep = par.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-08-14 22:38:45 +00:00
|
|
|
|
pos_type const body_pos = par.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-11-30 01:59:49 +00:00
|
|
|
|
FontIterator fi = FontIterator(*this, par, i);
|
2004-03-01 10:10:10 +00:00
|
|
|
|
for ( ; i < end; ++i, ++fi) {
|
2003-07-27 00:37:17 +00:00
|
|
|
|
if (body_pos > 0 && i == body_pos) {
|
2004-08-15 00:01:45 +00:00
|
|
|
|
w += font_metrics::width(labelsep, getLabelFont(par));
|
2004-08-14 22:38:45 +00:00
|
|
|
|
if (par.isLineSeparator(i - 1))
|
2004-08-15 00:01:45 +00:00
|
|
|
|
w -= singleWidth(par, i - 1);
|
2003-11-25 11:17:27 +00:00
|
|
|
|
w = max(w, labelEnd(pit));
|
2003-07-27 00:37:17 +00:00
|
|
|
|
}
|
2006-04-09 02:30:40 +00:00
|
|
|
|
char_type const c = par.getChar(i);
|
2004-08-15 00:01:45 +00:00
|
|
|
|
w += singleWidth(par, 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) {
|
2004-08-15 00:01:45 +00:00
|
|
|
|
w += font_metrics::width(labelsep, getLabelFont(par));
|
2004-08-14 22:38:45 +00:00
|
|
|
|
if (end > 0 && par.isLineSeparator(end - 1))
|
2004-08-15 00:01:45 +00:00
|
|
|
|
w -= singleWidth(par, 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-08-14 22:38:45 +00:00
|
|
|
|
row.width(w + rightMargin(par));
|
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-08-15 00:01:45 +00:00
|
|
|
|
int LyXText::labelFill(Paragraph const & par, Row const & row) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-08-15 00:01:45 +00:00
|
|
|
|
pos_type last = par.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-08-15 00:01:45 +00:00
|
|
|
|
if (par.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)
|
2004-08-15 00:01:45 +00:00
|
|
|
|
w += singleWidth(par, i);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-08-15 00:01:45 +00:00
|
|
|
|
string const & label = par.params().labelWidthString();
|
2003-10-28 11:18:40 +00:00
|
|
|
|
if (label.empty())
|
|
|
|
|
return 0;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-08-15 00:01:45 +00:00
|
|
|
|
return max(0, font_metrics::width(label, getLabelFont(par)) - 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-11-24 21:53:46 +00:00
|
|
|
|
void LyXText::setHeightOfRow(pit_type const pit, Row & row)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-08-15 00:01:45 +00:00
|
|
|
|
Paragraph const & par = pars_[pit];
|
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-08-15 00:01:45 +00:00
|
|
|
|
LyXLayout_ptr const & layout = par.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.
|
2004-08-15 00:01:45 +00:00
|
|
|
|
LyXFont font = getFont(par, 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
|
|
|
|
|
2004-08-15 00:01:45 +00:00
|
|
|
|
LyXFont labelfont = getLabelFont(par);
|
2001-07-31 10:10:17 +00:00
|
|
|
|
|
2003-10-24 09:45:07 +00:00
|
|
|
|
// these are minimum values
|
2004-08-15 00:01:45 +00:00
|
|
|
|
double const spacing_val = layout->spacing.getValue() * spacing(par);
|
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-08-15 00:01:45 +00:00
|
|
|
|
InsetList::const_iterator ii = par.insetlist.begin();
|
|
|
|
|
InsetList::const_iterator iend = par.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-08-15 00:01:45 +00:00
|
|
|
|
par.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;
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
row.ascent(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
|
2004-08-15 00:01:45 +00:00
|
|
|
|
&& ((layout->isParagraph() && par.getDepth() == 0)
|
2004-03-25 09:16:36 +00:00
|
|
|
|
|| (pars_[pit - 1].layout()->isParagraph()
|
2006-04-05 23:56:29 +00:00
|
|
|
|
&& 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
|
|
|
|
|
2005-04-19 09:04:25 +00:00
|
|
|
|
if (par.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
|
2005-04-26 11:12:20 +00:00
|
|
|
|
if (layout->counter == "chapter"
|
2005-04-19 09:04:25 +00:00
|
|
|
|
&& !par.params().labelString().empty()) {
|
2003-10-28 11:18:40 +00:00
|
|
|
|
labeladdon = int(font_metrics::maxHeight(labelfont)
|
2006-04-05 23:56:29 +00:00
|
|
|
|
* layout->spacing.getValue()
|
|
|
|
|
* spacing(par));
|
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-08-15 00:01:45 +00:00
|
|
|
|
&& !par.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-08-15 00:01:45 +00:00
|
|
|
|
* spacing(par)
|
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-11-24 21:53:46 +00:00
|
|
|
|
pit_type prev = depthHook(pit, pars_, par.getDepth());
|
2003-10-28 11:18:40 +00:00
|
|
|
|
if (prev != pit
|
2004-03-25 09:16:36 +00:00
|
|
|
|
&& pars_[prev].layout() == layout
|
2004-08-15 00:01:45 +00:00
|
|
|
|
&& pars_[prev].getDepth() == par.getDepth()
|
|
|
|
|
&& pars_[prev].getLabelWidthString() == par.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-11-24 21:53:46 +00:00
|
|
|
|
if (prev != pit_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-08-15 00:01:45 +00:00
|
|
|
|
if (row.endpos() >= par.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-11-24 21:53:46 +00:00
|
|
|
|
pit_type nextpit = pit + 1;
|
|
|
|
|
if (nextpit != pit_type(pars_.size())) {
|
|
|
|
|
pit_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()));
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2005-01-19 08:42:32 +00:00
|
|
|
|
// Top and bottom margin of the document (only at top-level)
|
|
|
|
|
if (bv_owner->text() == this) {
|
|
|
|
|
if (pit == 0 && row.pos() == 0)
|
|
|
|
|
maxasc += 20;
|
2005-10-05 08:41:28 +00:00
|
|
|
|
if (pit + 1 == pit_type(pars_.size()) &&
|
|
|
|
|
row.endpos() == par.size())
|
2005-01-19 08:42:32 +00:00
|
|
|
|
maxdesc += 20;
|
|
|
|
|
}
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
row.ascent(maxasc + labeladdon);
|
|
|
|
|
row.descent(maxdesc);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-08-15 00:01:45 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-31 16:29:48 +00:00
|
|
|
|
void LyXText::breakParagraph(LCursor & cur, bool keep_layout)
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2006-03-11 13:31:41 +00:00
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
Paragraph & cpar = cur.paragraph();
|
2004-11-24 21:53:46 +00:00
|
|
|
|
pit_type cpit = cur.pit();
|
2004-02-12 16:36:01 +00:00
|
|
|
|
|
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-11-24 21:53:46 +00:00
|
|
|
|
recUndo(cur.pit(), undoSpan(cur.pit()) - 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
|
|
|
|
|
2005-01-31 16:29:48 +00:00
|
|
|
|
// How should the layout for the new paragraph be?
|
|
|
|
|
int preserve_layout = 0;
|
2002-05-29 12:58:23 +00:00
|
|
|
|
if (keep_layout)
|
2005-01-31 16:29:48 +00:00
|
|
|
|
preserve_layout = 2;
|
2002-05-29 12:58:23 +00:00
|
|
|
|
else
|
2005-01-31 16:29:48 +00:00
|
|
|
|
preserve_layout = layout->isEnvironment();
|
|
|
|
|
|
|
|
|
|
// We need to remember this before we break the paragraph, because
|
|
|
|
|
// that invalidates the layout variable
|
|
|
|
|
bool sensitive = layout->labeltype == LABEL_SENSITIVE;
|
2002-05-29 12:58:23 +00:00
|
|
|
|
|
2005-01-31 16:29:48 +00:00
|
|
|
|
// we need to set this before we insert the paragraph.
|
2004-02-12 16:36:01 +00:00
|
|
|
|
bool const isempty = cpar.allowEmpty() && cpar.empty();
|
2005-01-31 16:29:48 +00:00
|
|
|
|
|
2004-04-08 15:03:33 +00:00
|
|
|
|
::breakParagraph(cur.buffer().params(), paragraphs(), cpit,
|
2005-01-31 16:29:48 +00:00
|
|
|
|
cur.pos(), preserve_layout);
|
|
|
|
|
|
|
|
|
|
// After this, neither paragraph contains any rows!
|
2000-09-23 04:57:18 +00:00
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
|
cpit = cur.pit();
|
|
|
|
|
pit_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
|
2005-01-31 16:29:48 +00:00
|
|
|
|
if (sensitive) {
|
2004-08-15 00:01:45 +00:00
|
|
|
|
if (cur.pos() == 0)
|
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
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
2006-04-07 22:16:09 +00:00
|
|
|
|
ParIterator current_it(cur);
|
2006-04-16 14:19:25 +00:00
|
|
|
|
ParIterator last_it(cur);
|
|
|
|
|
++last_it;
|
|
|
|
|
++last_it;
|
2006-04-07 22:16:09 +00:00
|
|
|
|
|
2006-04-16 14:19:25 +00:00
|
|
|
|
updateLabels(cur.buffer(), current_it, last_it);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2006-03-11 13:31:41 +00:00
|
|
|
|
// Mark "carriage return" as inserted if change tracking:
|
|
|
|
|
if (cur.buffer().params().tracking_changes) {
|
2006-04-05 23:56:29 +00:00
|
|
|
|
cur.paragraph().setChange(cur.paragraph().size(),
|
2006-03-11 13:31:41 +00:00
|
|
|
|
Change::INSERTED);
|
|
|
|
|
}
|
|
|
|
|
|
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-11-24 21:53:46 +00:00
|
|
|
|
setCursor(cur, cur.pit() + 1, 0);
|
2002-05-29 12:58:23 +00:00
|
|
|
|
else
|
2004-11-24 21:53:46 +00:00
|
|
|
|
setCursor(cur, cur.pit(), 0);
|
2000-02-10 17:53:36 +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
|
2006-04-09 02:30:40 +00:00
|
|
|
|
void LyXText::insertChar(LCursor & cur, char_type 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-11-24 21:53:46 +00:00
|
|
|
|
pit_type const pit = cur.pit();
|
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) {
|
2006-04-08 09:09:57 +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() &&
|
2004-08-15 00:01:45 +00:00
|
|
|
|
getFont(par, cur.pos()).number() == LyXFont::ON &&
|
|
|
|
|
getFont(par, 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
|
2006-04-08 09:09:57 +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) {
|
2006-04-09 02:30:40 +00:00
|
|
|
|
char_type 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
|
2004-08-15 00:01:45 +00:00
|
|
|
|
&& getFont(par, cur.pos() - 2).number() == LyXFont::ON) {
|
2004-02-13 07:30:59 +00:00
|
|
|
|
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
|
|
|
|
|
2004-02-13 07:30:59 +00:00
|
|
|
|
// When the free-spacing option is set for the current layout,
|
|
|
|
|
// disable the double-space checking
|
2006-04-08 09:09:57 +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;
|
|
|
|
|
}
|
2005-01-31 16:29:48 +00:00
|
|
|
|
return;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
}
|
|
|
|
|
BOOST_ASSERT(cur.pos() > 0);
|
2005-08-01 12:37:25 +00:00
|
|
|
|
if ((par.isLineSeparator(cur.pos() - 1)
|
|
|
|
|
|| par.isNewline(cur.pos() - 1))
|
|
|
|
|
&& par.lookupChange(cur.pos() - 1) != Change::DELETED) {
|
2004-02-13 07:30:59 +00:00
|
|
|
|
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
|
|
|
|
|
2005-12-06 14:54:23 +00:00
|
|
|
|
par.insertChar(cur.pos(), c, current_font);
|
2005-10-25 11:46:12 +00:00
|
|
|
|
setCursor(cur, cur.pit(), 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-11-30 01:59:49 +00:00
|
|
|
|
RowMetrics
|
|
|
|
|
LyXText::computeRowMetrics(pit_type const pit, Row const & row) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-03-01 12:23:17 +00:00
|
|
|
|
RowMetrics result;
|
2004-08-15 00:01:45 +00:00
|
|
|
|
Paragraph const & par = pars_[pit];
|
2004-03-01 12:23:17 +00:00
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
double w = dim_.wid - row.width();
|
2000-02-03 19:51:27 +00:00
|
|
|
|
|
2004-08-15 00:01:45 +00:00
|
|
|
|
bool const is_rtl = isRTL(par);
|
2003-07-18 07:47:07 +00:00
|
|
|
|
if (is_rtl)
|
2004-08-15 00:01:45 +00:00
|
|
|
|
result.x = rightMargin(par);
|
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-08-15 00:01:45 +00:00
|
|
|
|
LyXLayout_ptr const & layout = par.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-08-15 00:01:45 +00:00
|
|
|
|
int nlh = numberOfLabelHfills(par, 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-08-15 00:01:45 +00:00
|
|
|
|
if (!par.empty())
|
2003-03-08 19:31:09 +00:00
|
|
|
|
++nlh;
|
2003-03-13 10:30:28 +00:00
|
|
|
|
|
2004-08-15 00:01:45 +00:00
|
|
|
|
if (nlh && !par.getLabelWidthString().empty())
|
|
|
|
|
result.label_hfill = labelFill(par, 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-08-15 00:01:45 +00:00
|
|
|
|
int const nh = numberOfHfills(par, 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-08-15 00:01:45 +00:00
|
|
|
|
if (par.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-08-15 00:01:45 +00:00
|
|
|
|
align = par.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-08-15 00:01:45 +00:00
|
|
|
|
// The test on par.size() is to catch zero-size pars, which
|
2003-10-21 13:04:14 +00:00
|
|
|
|
// would trigger the assert in Paragraph::getInset().
|
2004-08-15 00:01:45 +00:00
|
|
|
|
//inset = par.size() ? par.getInset(row.pos()) : 0;
|
|
|
|
|
if (!par.empty()
|
|
|
|
|
&& par.isInset(row.pos())
|
|
|
|
|
&& par.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-08-15 00:01:45 +00:00
|
|
|
|
int const ns = numberOfSeparators(par, row);
|
2004-02-27 13:06:16 +00:00
|
|
|
|
bool disp_inset = false;
|
2004-08-15 00:01:45 +00:00
|
|
|
|
if (row.endpos() < par.size()) {
|
|
|
|
|
InsetBase const * in = par.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-08-15 00:01:45 +00:00
|
|
|
|
&& row.endpos() < par.size()
|
|
|
|
|
&& !par.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-08-15 00:01:45 +00:00
|
|
|
|
bidi.computeTables(par, *bv()->buffer(), row);
|
2000-04-10 21:40:13 +00:00
|
|
|
|
if (is_rtl) {
|
2004-08-15 00:01:45 +00:00
|
|
|
|
pos_type body_pos = par.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-08-15 00:01:45 +00:00
|
|
|
|
&& (body_pos > end || !par.isLineSeparator(body_pos - 1)))
|
2003-10-28 11:18:40 +00:00
|
|
|
|
{
|
2004-08-15 00:01:45 +00:00
|
|
|
|
result.x += font_metrics::width(layout->labelsep, getLabelFont(par));
|
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
|
|
|
|
|
2005-02-08 02:06:39 +00:00
|
|
|
|
bool 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());
|
2005-02-08 02:06:39 +00:00
|
|
|
|
|
|
|
|
|
LCursor old = cur;
|
|
|
|
|
|
|
|
|
|
if (old.pos() == old.lastpos() && old.pit() != old.lastpit()) {
|
|
|
|
|
++old.pit();
|
|
|
|
|
old.pos() = 0;
|
2004-02-12 16:36:01 +00:00
|
|
|
|
} else {
|
|
|
|
|
// Advance through word.
|
2005-02-08 02:06:39 +00:00
|
|
|
|
while (old.pos() != old.lastpos() && old.paragraph().isLetter(old.pos()))
|
|
|
|
|
++old.pos();
|
2006-02-24 12:58:31 +00:00
|
|
|
|
// Skip through trailing nonword stuff.
|
|
|
|
|
while (old.pos() != old.lastpos() && !old.paragraph().isLetter(old.pos()))
|
|
|
|
|
++old.pos();
|
2004-02-12 16:36:01 +00:00
|
|
|
|
}
|
2005-02-08 02:06:39 +00:00
|
|
|
|
return setCursor(cur, old.pit(), old.pos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-02-08 02:06:39 +00:00
|
|
|
|
bool 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());
|
2005-02-08 02:06:39 +00:00
|
|
|
|
|
|
|
|
|
LCursor old = cur;
|
|
|
|
|
|
|
|
|
|
if (old.pos() == 0 && old.pit() != 0) {
|
|
|
|
|
--old.pit();
|
|
|
|
|
old.pos() = old.lastpos();
|
2004-04-03 08:37:12 +00:00
|
|
|
|
} else {
|
2004-02-12 16:36:01 +00:00
|
|
|
|
// Skip through initial nonword stuff.
|
2005-02-08 02:06:39 +00:00
|
|
|
|
while (old.pos() != 0 && !old.paragraph().isLetter(old.pos() - 1))
|
|
|
|
|
--old.pos();
|
2004-02-12 16:36:01 +00:00
|
|
|
|
// Advance through word.
|
2005-02-08 02:06:39 +00:00
|
|
|
|
while (old.pos() != 0 && old.paragraph().isLetter(old.pos() - 1))
|
|
|
|
|
--old.pos();
|
2004-02-12 16:36:01 +00:00
|
|
|
|
}
|
2005-02-08 02:06:39 +00:00
|
|
|
|
return setCursor(cur, old.pit(), old.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-11-24 21:53:46 +00:00
|
|
|
|
setCursor(cur, from.pit(), 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-11-24 21:53:46 +00:00
|
|
|
|
setCursor(cur, to.pit(), 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;
|
|
|
|
|
|
2006-03-11 13:31:41 +00:00
|
|
|
|
recordUndoSelection(cur, Undo::INSERT);
|
2006-04-05 23:56:29 +00:00
|
|
|
|
|
2006-03-11 13:31:41 +00:00
|
|
|
|
DocIterator it = cur.selectionBegin();
|
|
|
|
|
DocIterator et = cur.selectionEnd();
|
|
|
|
|
pit_type pit = it.pit();
|
2006-05-08 20:30:52 +00:00
|
|
|
|
Change::Type const type = pars_[pit].lookupChange(it.pos()).type;
|
2006-03-11 13:31:41 +00:00
|
|
|
|
for (; pit <= et.pit(); ++pit) {
|
|
|
|
|
pos_type left = ( pit == it.pit() ? it.pos() : 0 );
|
2006-04-05 23:56:29 +00:00
|
|
|
|
pos_type right =
|
2006-03-11 13:31:41 +00:00
|
|
|
|
( pit == et.pit() ? et.pos() : pars_[pit].size() + 1 );
|
|
|
|
|
pars_[pit].acceptChange(left, right);
|
2003-02-08 19:18:01 +00:00
|
|
|
|
}
|
2006-03-11 13:31:41 +00:00
|
|
|
|
if (type == Change::DELETED) {
|
|
|
|
|
ParagraphList & plist = paragraphs();
|
|
|
|
|
if (it.pit() + 1 < et.pit())
|
2006-03-23 20:11:06 +00:00
|
|
|
|
pars_.erase(boost::next(plist.begin(), it.pit() + 1),
|
|
|
|
|
boost::next(plist.begin(), et.pit()));
|
2006-04-05 23:56:29 +00:00
|
|
|
|
|
2006-03-11 13:31:41 +00:00
|
|
|
|
// Paragraph merge if appropriate:
|
2006-04-05 23:56:29 +00:00
|
|
|
|
if (pars_[it.pit()].lookupChange(pars_[it.pit()].size())
|
2006-03-11 13:31:41 +00:00
|
|
|
|
== Change::DELETED) {
|
|
|
|
|
setCursorIntern(cur, it.pit() + 1, 0);
|
|
|
|
|
backspacePos0(cur);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
finishUndo();
|
|
|
|
|
cur.clearSelection();
|
|
|
|
|
setCursorIntern(cur, it.pit(), 0);
|
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
|
|
|
|
|
2006-03-11 13:31:41 +00:00
|
|
|
|
recordUndoSelection(cur, Undo::INSERT);
|
|
|
|
|
|
|
|
|
|
DocIterator it = cur.selectionBegin();
|
|
|
|
|
DocIterator et = cur.selectionEnd();
|
|
|
|
|
pit_type pit = it.pit();
|
2006-05-08 20:30:52 +00:00
|
|
|
|
Change::Type const type = pars_[pit].lookupChange(it.pos()).type;
|
2006-03-11 13:31:41 +00:00
|
|
|
|
for (; pit <= et.pit(); ++pit) {
|
|
|
|
|
pos_type left = ( pit == it.pit() ? it.pos() : 0 );
|
2006-04-05 23:56:29 +00:00
|
|
|
|
pos_type right =
|
2006-03-11 13:31:41 +00:00
|
|
|
|
( pit == et.pit() ? et.pos() : pars_[pit].size() + 1 );
|
|
|
|
|
pars_[pit].rejectChange(left, right);
|
2003-02-08 19:18:01 +00:00
|
|
|
|
}
|
2006-03-11 13:31:41 +00:00
|
|
|
|
if (type == Change::INSERTED) {
|
|
|
|
|
ParagraphList & plist = paragraphs();
|
|
|
|
|
if (it.pit() + 1 < et.pit())
|
2006-03-23 20:11:06 +00:00
|
|
|
|
pars_.erase(boost::next(plist.begin(), it.pit() + 1),
|
|
|
|
|
boost::next(plist.begin(), et.pit()));
|
2006-03-11 13:31:41 +00:00
|
|
|
|
// Paragraph merge if appropriate:
|
2006-04-05 23:56:29 +00:00
|
|
|
|
if (pars_[it.pit()].lookupChange(pars_[it.pit()].size())
|
2006-03-11 13:31:41 +00:00
|
|
|
|
== Change::INSERTED) {
|
|
|
|
|
setCursorIntern(cur, it.pit() + 1, 0);
|
|
|
|
|
backspacePos0(cur);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
finishUndo();
|
|
|
|
|
cur.clearSelection();
|
|
|
|
|
setCursorIntern(cur, it.pit(), 0);
|
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);
|
2006-02-24 12:58:31 +00:00
|
|
|
|
cursorRightOneWord(cur);
|
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();
|
2004-11-24 21:53:46 +00:00
|
|
|
|
int par = from.pit();
|
2001-06-27 18:29:18 +00:00
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
|
while (par != int(pars_.size()) && (pos != to.pos() || par != to.pit())) {
|
|
|
|
|
pit_type pit = par;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2006-04-09 02:30:40 +00:00
|
|
|
|
char_type 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-04-09 00:26:19 +00:00
|
|
|
|
bool LyXText::erase(LCursor & cur)
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2005-12-19 12:30:34 +00:00
|
|
|
|
bool needsUpdate = false;
|
2005-07-17 16:12:48 +00:00
|
|
|
|
|
2004-04-13 06:27:29 +00:00
|
|
|
|
if (cur.pos() != cur.lastpos()) {
|
2004-11-24 21:53:46 +00:00
|
|
|
|
recordUndo(cur, Undo::DELETE, cur.pit());
|
|
|
|
|
setCursorIntern(cur, cur.pit(), cur.pos() + 1, false, cur.boundary());
|
2005-12-19 12:30:34 +00:00
|
|
|
|
needsUpdate = backspace(cur);
|
2006-03-25 16:38:28 +00:00
|
|
|
|
if (cur.paragraph().lookupChange(cur.pos()) == Change::DELETED)
|
2006-03-16 15:53:28 +00:00
|
|
|
|
cur.posRight();
|
2005-07-17 16:12:48 +00:00
|
|
|
|
} else if (cur.pit() != cur.lastpit()) {
|
|
|
|
|
LCursor scur = cur;
|
|
|
|
|
|
2006-03-25 16:38:28 +00:00
|
|
|
|
setCursorIntern(cur, cur.pit() + 1, 0, false, false);
|
2005-07-17 16:12:48 +00:00
|
|
|
|
if (pars_[cur.pit()].layout() == pars_[scur.pit()].layout()) {
|
|
|
|
|
recordUndo(scur, Undo::DELETE, scur.pit());
|
2005-12-19 12:30:34 +00:00
|
|
|
|
needsUpdate = backspace(cur);
|
2006-03-25 16:38:28 +00:00
|
|
|
|
if (cur.buffer().params().tracking_changes) {
|
|
|
|
|
// move forward after the paragraph break is DELETED
|
|
|
|
|
Paragraph & par = cur.paragraph();
|
|
|
|
|
if (par.lookupChange(par.size()) == Change::DELETED)
|
|
|
|
|
setCursorIntern(cur, cur.pit() + 1, 0);
|
|
|
|
|
}
|
2005-07-17 16:12:48 +00:00
|
|
|
|
} else {
|
|
|
|
|
setCursorIntern(scur, scur.pit(), scur.pos(), false, scur.boundary());
|
|
|
|
|
}
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
2005-12-19 12:30:34 +00:00
|
|
|
|
return needsUpdate;
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-03-11 13:31:41 +00:00
|
|
|
|
bool LyXText::backspacePos0(LCursor & cur)
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2005-12-19 12:30:34 +00:00
|
|
|
|
bool needsUpdate = false;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2006-03-11 13:31:41 +00:00
|
|
|
|
Paragraph & par = cur.paragraph();
|
|
|
|
|
// is it an empty paragraph?
|
|
|
|
|
pos_type lastpos = cur.lastpos();
|
|
|
|
|
if (lastpos == 0 || (lastpos == 1 && par.isSeparator(0))) {
|
|
|
|
|
// This is an empty paragraph and we delete it just
|
|
|
|
|
// by moving the cursor one step
|
|
|
|
|
// left and let the DeleteEmptyParagraphMechanism
|
|
|
|
|
// handle the actual deletion of the paragraph.
|
2003-03-03 23:19:01 +00:00
|
|
|
|
|
2006-03-11 13:31:41 +00:00
|
|
|
|
if (cur.pit() != 0) {
|
|
|
|
|
// For KeepEmpty layouts we need to get
|
|
|
|
|
// rid of the keepEmpty setting first.
|
|
|
|
|
// And the only way to do this is to
|
|
|
|
|
// reset the layout to something
|
|
|
|
|
// else: f.ex. the default layout.
|
|
|
|
|
if (par.allowEmpty()) {
|
|
|
|
|
Buffer & buf = cur.buffer();
|
|
|
|
|
BufferParams const & bparams = buf.params();
|
|
|
|
|
par.layout(bparams.getLyXTextClass().defaultLayout());
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
2006-04-05 23:56:29 +00:00
|
|
|
|
|
2006-03-11 13:31:41 +00:00
|
|
|
|
cursorLeft(cur);
|
|
|
|
|
return true;
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
2006-03-11 13:31:41 +00:00
|
|
|
|
}
|
2000-07-24 21:49:58 +00:00
|
|
|
|
|
2006-03-11 13:31:41 +00:00
|
|
|
|
if (cur.pit() != 0)
|
|
|
|
|
recordUndo(cur, Undo::DELETE, cur.pit() - 1);
|
|
|
|
|
|
|
|
|
|
pit_type tmppit = cur.pit();
|
|
|
|
|
// We used to do cursorLeftIntern() here, but it is
|
|
|
|
|
// not a good idea since it triggers the auto-delete
|
|
|
|
|
// mechanism. So we do a cursorLeftIntern()-lite,
|
|
|
|
|
// without the dreaded mechanism. (JMarc)
|
|
|
|
|
if (cur.pit() != 0) {
|
|
|
|
|
// steps into the above paragraph.
|
|
|
|
|
setCursorIntern(cur, cur.pit() - 1,
|
|
|
|
|
pars_[cur.pit() - 1].size(),
|
|
|
|
|
false);
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2006-03-11 13:31:41 +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.
|
|
|
|
|
// Correction: Pasting is always allowed with standard-layout
|
|
|
|
|
// Correction (Jug 20050717): Remove check about alignment!
|
|
|
|
|
Buffer & buf = cur.buffer();
|
|
|
|
|
BufferParams const & bufparams = buf.params();
|
|
|
|
|
LyXTextClass const & tclass = bufparams.getLyXTextClass();
|
|
|
|
|
pit_type const cpit = cur.pit();
|
2000-03-28 02:18:52 +00:00
|
|
|
|
|
2006-03-11 13:31:41 +00:00
|
|
|
|
if (cpit != tmppit
|
|
|
|
|
&& (pars_[cpit].layout() == pars_[tmppit].layout()
|
2006-04-05 23:56:29 +00:00
|
|
|
|
|| pars_[tmppit].layout() == tclass.defaultLayout()))
|
2006-03-11 13:31:41 +00:00
|
|
|
|
{
|
|
|
|
|
mergeParagraph(bufparams, pars_, cpit);
|
|
|
|
|
needsUpdate = true;
|
2003-08-11 09:09:01 +00:00
|
|
|
|
|
2006-03-11 13:31:41 +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
|
|
|
|
|
2006-03-11 13:31:41 +00:00
|
|
|
|
// the counters may have changed
|
2006-04-07 22:16:09 +00:00
|
|
|
|
ParIterator par_it(cur);
|
2006-04-16 14:19:25 +00:00
|
|
|
|
updateLabels(cur.buffer(), par_it);
|
2006-04-07 22:16:09 +00:00
|
|
|
|
|
2006-03-11 13:31:41 +00:00
|
|
|
|
setCursor(cur, cur.pit(), cur.pos(), false);
|
|
|
|
|
}
|
|
|
|
|
return needsUpdate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool LyXText::backspace(LCursor & cur)
|
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
|
|
|
|
bool needsUpdate = false;
|
|
|
|
|
if (cur.pos() == 0) {
|
|
|
|
|
// The cursor is at the beginning of a paragraph, so
|
|
|
|
|
// the the backspace will collapse two paragraphs into
|
|
|
|
|
// one.
|
|
|
|
|
|
2006-03-25 09:18:28 +00:00
|
|
|
|
if (cur.pit() != 0 && cur.buffer().params().tracking_changes) {
|
2006-03-11 13:31:41 +00:00
|
|
|
|
// Previous paragraph, mark "carriage return" as
|
|
|
|
|
// deleted:
|
|
|
|
|
Paragraph & par = pars_[cur.pit() - 1];
|
2006-03-16 06:54:08 +00:00
|
|
|
|
// Take care of a just inserted para break:
|
|
|
|
|
if (par.lookupChange(par.size()) != Change::INSERTED) {
|
|
|
|
|
par.setChange(par.size(), Change::DELETED);
|
|
|
|
|
setCursorIntern(cur, cur.pit() - 1, par.size());
|
2006-03-18 21:15:21 +00:00
|
|
|
|
return true;
|
2006-03-16 06:54:08 +00:00
|
|
|
|
}
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
2006-03-11 13:31:41 +00:00
|
|
|
|
|
|
|
|
|
needsUpdate = backspacePos0(cur);
|
|
|
|
|
|
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-11-24 21:53:46 +00:00
|
|
|
|
setCursorIntern(cur, cur.pit(), 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-11-24 21:53:46 +00:00
|
|
|
|
setCursor(cur, cur.pit(), cur.pos(), false, cur.boundary());
|
2005-12-19 12:30:34 +00:00
|
|
|
|
|
|
|
|
|
return needsUpdate;
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-04-21 19:51:18 +00:00
|
|
|
|
Row const & LyXText::firstRow() const
|
2003-08-14 14:10:13 +00:00
|
|
|
|
{
|
2004-11-30 01:59:49 +00:00
|
|
|
|
return *paragraphs().front().rows().begin();
|
2003-08-14 11:16:31 +00:00
|
|
|
|
}
|
2003-10-09 10:52:12 +00:00
|
|
|
|
|
|
|
|
|
|
2005-05-31 14:40:30 +00:00
|
|
|
|
bool LyXText::redoParagraph(pit_type const pit)
|
2003-10-17 10:31:47 +00:00
|
|
|
|
{
|
|
|
|
|
// remove rows of paragraph, keep track of height changes
|
2004-08-15 00:01:45 +00:00
|
|
|
|
Paragraph & par = pars_[pit];
|
2003-10-17 10:31:47 +00:00
|
|
|
|
|
2005-05-05 18:33:50 +00:00
|
|
|
|
// Add bibitem insets if necessary
|
|
|
|
|
if (par.layout()->labeltype == LABEL_BIBLIO) {
|
|
|
|
|
bool hasbibitem(false);
|
2005-06-09 09:58:08 +00:00
|
|
|
|
if (!par.insetlist.empty()
|
2005-05-05 18:33:50 +00:00
|
|
|
|
// Insist on it being in pos 0
|
|
|
|
|
&& par.getChar(0) == Paragraph::META_INSET) {
|
|
|
|
|
InsetBase * inset = par.insetlist.begin()->inset;
|
2006-04-05 23:56:29 +00:00
|
|
|
|
if (inset->lyxCode() == InsetBase::BIBITEM_CODE)
|
2005-05-05 18:33:50 +00:00
|
|
|
|
hasbibitem = true;
|
|
|
|
|
}
|
|
|
|
|
if (!hasbibitem) {
|
|
|
|
|
InsetBibitem * inset(new
|
|
|
|
|
InsetBibitem(InsetCommandParams("bibitem")));
|
|
|
|
|
par.insertInset(0, static_cast<InsetBase *>(inset));
|
2005-06-06 08:30:20 +00:00
|
|
|
|
bv()->cursor().posRight();
|
2005-05-05 18:33:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-10-17 10:31:47 +00:00
|
|
|
|
// redo insets
|
2005-12-17 15:03:41 +00:00
|
|
|
|
// FIXME: We should always use getFont(), see documentation of
|
|
|
|
|
// noFontChange() in insetbase.h.
|
2006-02-05 13:20:16 +00:00
|
|
|
|
LyXFont const bufferfont = bv()->buffer()->params().getFont();
|
2004-08-15 00:01:45 +00:00
|
|
|
|
InsetList::iterator ii = par.insetlist.begin();
|
|
|
|
|
InsetList::iterator iend = par.insetlist.end();
|
2003-10-17 10:31:47 +00:00
|
|
|
|
for (; ii != iend; ++ii) {
|
|
|
|
|
Dimension dim;
|
2005-09-27 08:48:53 +00:00
|
|
|
|
int const w = maxwidth_ - leftMargin(pit, ii->pos) - rightMargin(par);
|
2005-12-17 15:03:41 +00:00
|
|
|
|
LyXFont const & font = ii->inset->noFontChange() ?
|
2006-02-05 13:20:16 +00:00
|
|
|
|
bufferfont :
|
2005-12-17 15:03:41 +00:00
|
|
|
|
getFont(par, ii->pos);
|
|
|
|
|
MetricsInfo mi(bv(), font, w);
|
2003-10-17 10:31:47 +00:00
|
|
|
|
ii->inset->metrics(mi, dim);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// rebreak the paragraph
|
2004-11-30 01:59:49 +00:00
|
|
|
|
par.rows().clear();
|
|
|
|
|
Dimension dim;
|
|
|
|
|
|
2004-08-15 00:01:45 +00:00
|
|
|
|
par.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-11-30 01:59:49 +00:00
|
|
|
|
par.rows().push_back(row);
|
|
|
|
|
dim.wid = std::max(dim.wid, row.width());
|
|
|
|
|
dim.des += row.height();
|
2004-02-27 09:18:03 +00:00
|
|
|
|
z = row.endpos();
|
2004-08-15 00:01:45 +00:00
|
|
|
|
} while (z < par.size());
|
2003-10-24 15:04:17 +00:00
|
|
|
|
|
2005-11-16 13:12:15 +00:00
|
|
|
|
// Make sure that if a par ends in newline, there is one more row
|
|
|
|
|
// under it
|
|
|
|
|
// FIXME this is a dirty trick. Now the _same_ position in the
|
|
|
|
|
// paragraph occurs in _two_ different rows, and has two different
|
|
|
|
|
// display positions, leading to weird behaviour when moving up/down.
|
|
|
|
|
if (z > 0 && par.isNewline(z - 1)) {
|
|
|
|
|
Row row(z - 1);
|
|
|
|
|
row.endpos(z - 1);
|
|
|
|
|
setRowWidth(pit, row);
|
|
|
|
|
setHeightOfRow(pit, row);
|
|
|
|
|
par.rows().push_back(row);
|
|
|
|
|
dim.des += row.height();
|
|
|
|
|
}
|
2006-04-05 23:56:29 +00:00
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
|
dim.asc += par.rows()[0].ascent();
|
|
|
|
|
dim.des -= par.rows()[0].ascent();
|
2005-06-09 09:58:08 +00:00
|
|
|
|
|
2005-05-31 14:40:30 +00:00
|
|
|
|
bool const same = dim == par.dim();
|
|
|
|
|
|
2005-01-31 16:29:48 +00:00
|
|
|
|
par.dim() = dim;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
//lyxerr << "redoParagraph: " << par.rows().size() << " rows\n";
|
2005-05-31 14:40:30 +00:00
|
|
|
|
|
|
|
|
|
return !same;
|
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-11-30 01:59:49 +00:00
|
|
|
|
// << " maxWidth: " << maxwidth_ << "\nfont: " << mi.base.font << endl;
|
2005-04-12 18:42:27 +00:00
|
|
|
|
// save the caller's font locally:
|
|
|
|
|
font_ = mi.base.font;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
|
|
|
|
|
unsigned int h = 0;
|
|
|
|
|
unsigned int w = 0;
|
|
|
|
|
for (pit_type pit = 0, n = paragraphs().size(); pit != n; ++pit) {
|
|
|
|
|
redoParagraph(pit);
|
|
|
|
|
Paragraph & par = paragraphs()[pit];
|
|
|
|
|
h += par.height();
|
|
|
|
|
if (w < par.width())
|
|
|
|
|
w = par.width();
|
|
|
|
|
}
|
2003-10-23 08:15:57 +00:00
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
dim.wid = w;
|
|
|
|
|
dim.asc = pars_[0].ascent();
|
|
|
|
|
dim.des = h - dim.asc;
|
2003-10-17 10:31:47 +00:00
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
dim_ = dim;
|
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
|
|
|
|
{
|
2004-11-30 01:59:49 +00:00
|
|
|
|
paintTextInset(*this, pi, x, y);
|
2003-11-28 08:55:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-07-17 12:02:48 +00:00
|
|
|
|
#if 0
|
2004-02-06 11:12:49 +00:00
|
|
|
|
// only used for inset right now. should also be used for main text
|
2004-11-30 01:59:49 +00:00
|
|
|
|
void LyXText::drawSelection(PainterInfo & pi, int x , int) const
|
2004-02-06 11:12:49 +00:00
|
|
|
|
{
|
2004-11-30 01:59:49 +00:00
|
|
|
|
LCursor & cur = pi.base.bv->cursor();
|
|
|
|
|
if (!cur.selection())
|
|
|
|
|
return;
|
|
|
|
|
if (!ptr_cmp(cur.text(), this))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
lyxerr << "draw selection at " << x << endl;
|
|
|
|
|
|
2005-11-07 15:02:08 +00:00
|
|
|
|
DocIterator beg = cur.selectionBegin();
|
|
|
|
|
DocIterator end = cur.selectionEnd();
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
// the selection doesn't touch the visible screen
|
|
|
|
|
if (bv_funcs::status(pi.base.bv, beg) == bv_funcs::CUR_BELOW
|
|
|
|
|
|| bv_funcs::status(pi.base.bv, end) == bv_funcs::CUR_ABOVE)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Paragraph const & par1 = pars_[beg.pit()];
|
|
|
|
|
Paragraph const & par2 = pars_[end.pit()];
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2005-07-17 12:02:48 +00:00
|
|
|
|
Row const & row1 = par1.getRow(beg.pos(), beg.boundary());
|
|
|
|
|
Row const & row2 = par2.getRow(end.pos(), end.boundary());
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
int y1,x1,x2;
|
|
|
|
|
if (bv_funcs::status(pi.base.bv, beg) == bv_funcs::CUR_ABOVE) {
|
|
|
|
|
y1 = 0;
|
|
|
|
|
x1 = 0;
|
|
|
|
|
x2 = 0;
|
|
|
|
|
} else {
|
|
|
|
|
y1 = bv_funcs::getPos(beg).y_ - row1.ascent();
|
2005-07-15 15:49:40 +00:00
|
|
|
|
int const startx = cursorX(beg.top(), begin.boundary());
|
2004-11-30 01:59:49 +00:00
|
|
|
|
x1 = isRTL(par1) ? startx : 0;
|
|
|
|
|
x2 = isRTL(par1) ? 0 + dim_.wid : startx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int y2,X1,X2;
|
|
|
|
|
if (bv_funcs::status(pi.base.bv, end) == bv_funcs::CUR_BELOW) {
|
|
|
|
|
y2 = pi.base.bv->workHeight();
|
|
|
|
|
X1 = 0;
|
|
|
|
|
X2 = 0;
|
|
|
|
|
} else {
|
|
|
|
|
y2 = bv_funcs::getPos(end).y_ + row2.descent();
|
2005-07-15 15:49:40 +00:00
|
|
|
|
int const endx = cursorX(end.top(), end.boundary());
|
2004-11-30 01:59:49 +00:00
|
|
|
|
X1 = isRTL(par2) ? 0 : endx;
|
|
|
|
|
X2 = isRTL(par2) ? endx : 0 + dim_.wid;
|
|
|
|
|
}
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
lyxerr << " y1: " << y1 << " y2: " << y2
|
2005-01-06 15:40:49 +00:00
|
|
|
|
<< " xo: " << xo_ << " wid: " << dim_.wid
|
2004-11-30 01:59:49 +00:00
|
|
|
|
<< endl;
|
|
|
|
|
|
|
|
|
|
// paint big rectangle in one go
|
|
|
|
|
pi.pain.fillRectangle(x, y1, dim_.wid, y2 - y1, LColor::selection);
|
|
|
|
|
|
|
|
|
|
// reset background at begin of first selected line
|
|
|
|
|
pi.pain.fillRectangle(x + x1, y1, x2 - x1, row1.height(),
|
|
|
|
|
LColor::background);
|
|
|
|
|
|
|
|
|
|
// reset background at end of last selected line
|
|
|
|
|
pi.pain.fillRectangle(x + X1, y2 - row2.height(),
|
|
|
|
|
X2 - X1, row2.height(), LColor::background);
|
2004-02-06 11:12:49 +00:00
|
|
|
|
}
|
2004-11-30 01:59:49 +00:00
|
|
|
|
|
2005-07-17 12:02:48 +00:00
|
|
|
|
#else
|
2004-11-30 01:59:49 +00:00
|
|
|
|
|
|
|
|
|
void LyXText::drawSelection(PainterInfo & pi, int x, int) const
|
|
|
|
|
{
|
|
|
|
|
LCursor & cur = pi.base.bv->cursor();
|
|
|
|
|
if (!cur.selection())
|
|
|
|
|
return;
|
|
|
|
|
if (!ptr_cmp(cur.text(), this))
|
|
|
|
|
return;
|
|
|
|
|
|
2005-07-14 08:20:10 +00:00
|
|
|
|
lyxerr[Debug::DEBUG]
|
2006-04-05 23:56:29 +00:00
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< "draw selection at " << x
|
|
|
|
|
<< endl;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
|
2005-11-07 15:02:08 +00:00
|
|
|
|
DocIterator beg = cur.selectionBegin();
|
|
|
|
|
DocIterator end = cur.selectionEnd();
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
// the selection doesn't touch the visible screen
|
|
|
|
|
if (bv_funcs::status(pi.base.bv, beg) == bv_funcs::CUR_BELOW
|
|
|
|
|
|| bv_funcs::status(pi.base.bv, end) == bv_funcs::CUR_ABOVE)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Paragraph const & par1 = pars_[beg.pit()];
|
|
|
|
|
Paragraph const & par2 = pars_[end.pit()];
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
bool const above = (bv_funcs::status(pi.base.bv, beg)
|
|
|
|
|
== bv_funcs::CUR_ABOVE);
|
|
|
|
|
bool const below = (bv_funcs::status(pi.base.bv, end)
|
|
|
|
|
== bv_funcs::CUR_BELOW);
|
|
|
|
|
int y1,y2,x1,x2;
|
|
|
|
|
if (above) {
|
|
|
|
|
y1 = 0;
|
|
|
|
|
y2 = 0;
|
|
|
|
|
x1 = 0;
|
|
|
|
|
x2 = dim_.wid;
|
|
|
|
|
} else {
|
2005-07-17 12:02:48 +00:00
|
|
|
|
Row const & row1 = par1.getRow(beg.pos(), beg.boundary());
|
2005-07-15 15:49:40 +00:00
|
|
|
|
y1 = bv_funcs::getPos(beg, beg.boundary()).y_ - row1.ascent();
|
2004-11-30 01:59:49 +00:00
|
|
|
|
y2 = y1 + row1.height();
|
2005-07-18 09:18:02 +00:00
|
|
|
|
int const startx = cursorX(beg.top(), beg.boundary());
|
2004-11-30 01:59:49 +00:00
|
|
|
|
x1 = !isRTL(par1) ? startx : 0;
|
|
|
|
|
x2 = !isRTL(par1) ? 0 + dim_.wid : startx;
|
|
|
|
|
}
|
2004-02-06 11:12:49 +00:00
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
int Y1,Y2,X1,X2;
|
|
|
|
|
if (below) {
|
|
|
|
|
Y1 = pi.base.bv->workHeight();
|
|
|
|
|
Y2 = pi.base.bv->workHeight();
|
|
|
|
|
X1 = 0;
|
|
|
|
|
X2 = dim_.wid;
|
|
|
|
|
} else {
|
2005-07-17 12:02:48 +00:00
|
|
|
|
Row const & row2 = par2.getRow(end.pos(), end.boundary());
|
2005-07-15 15:49:40 +00:00
|
|
|
|
Y1 = bv_funcs::getPos(end, end.boundary()).y_ - row2.ascent();
|
2004-11-30 01:59:49 +00:00
|
|
|
|
Y2 = Y1 + row2.height();
|
2005-07-18 09:18:02 +00:00
|
|
|
|
int const endx = cursorX(end.top(), end.boundary());
|
2004-11-30 01:59:49 +00:00
|
|
|
|
X1 = !isRTL(par2) ? 0 : endx;
|
|
|
|
|
X2 = !isRTL(par2) ? endx : 0 + dim_.wid;
|
|
|
|
|
}
|
|
|
|
|
|
2005-08-15 08:26:53 +00:00
|
|
|
|
if (!above && !below && &par1.getRow(beg.pos(), beg.boundary())
|
2005-07-17 12:02:48 +00:00
|
|
|
|
== &par2.getRow(end.pos(), end.boundary()))
|
2004-11-30 01:59:49 +00:00
|
|
|
|
{
|
|
|
|
|
// paint only one rectangle
|
2005-08-15 08:26:53 +00:00
|
|
|
|
int const b( !isRTL(par1) ? x + x1 : x + X1 );
|
|
|
|
|
int const w( !isRTL(par1) ? X2 - x1 : x2 - X1 );
|
|
|
|
|
pi.pain.fillRectangle(b, y1, w, y2 - y1, LColor::selection);
|
2004-11-30 01:59:49 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-18 09:18:02 +00:00
|
|
|
|
lyxerr[Debug::DEBUG] << " y1: " << y1 << " y2: " << y2
|
|
|
|
|
<< "X1:" << X1 << " x2: " << X2 << " wid: " << dim_.wid
|
|
|
|
|
<< endl;
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
// paint upper rectangle
|
|
|
|
|
pi.pain.fillRectangle(x + x1, y1, x2 - x1, y2 - y1,
|
|
|
|
|
LColor::selection);
|
|
|
|
|
// paint bottom rectangle
|
|
|
|
|
pi.pain.fillRectangle(x + X1, Y1, X2 - X1, Y2 - Y1,
|
|
|
|
|
LColor::selection);
|
|
|
|
|
// paint center rectangle
|
|
|
|
|
pi.pain.fillRectangle(x, y2, dim_.wid,
|
|
|
|
|
Y1 - y2, LColor::selection);
|
|
|
|
|
}
|
2005-07-17 12:02:48 +00:00
|
|
|
|
#endif
|
2005-07-15 15:49:40 +00:00
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
|
bool LyXText::isLastRow(pit_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()
|
2004-11-24 21:53:46 +00:00
|
|
|
|
&& pit + 1 == pit_type(paragraphs().size());
|
2003-10-23 08:15:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
|
bool LyXText::isFirstRow(pit_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-11-24 21:53:46 +00:00
|
|
|
|
Paragraph const & from_par = pars_[from.pit()];
|
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-11-18 14:58:54 +00:00
|
|
|
|
|| !from_par.isLetter(from.pos())
|
|
|
|
|
|| !from_par.isLetter(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
|
2004-11-18 14:58:54 +00:00
|
|
|
|
if (!from.pos() || !from_par.isLetter(from.pos() - 1))
|
2004-06-29 15:43:25 +00:00
|
|
|
|
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-11-18 14:58:54 +00:00
|
|
|
|
while (from.pos() && from_par.isLetter(from.pos() - 1))
|
2004-06-29 15:43:25 +00:00
|
|
|
|
--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-11-24 21:53:46 +00:00
|
|
|
|
Paragraph & to_par = pars_[to.pit()];
|
2004-11-18 14:58:54 +00:00
|
|
|
|
while (to.pos() < to_par.size() && to_par.isLetter(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
|
|
|
|
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-08-16 00:16:17 +00:00
|
|
|
|
if (token == "\\end_body") {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (token == "\\begin_body") {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
if (token == "\\end_document") {
|
|
|
|
|
return false;
|
2003-12-03 15:27:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 {
|
2004-08-16 00:16:17 +00:00
|
|
|
|
lyxerr << "Handling unknown body token: `"
|
|
|
|
|
<< token << '\'' << endl;
|
2003-12-03 15:27:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
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-11-30 01:59:49 +00:00
|
|
|
|
return dim_.asc;
|
2003-12-10 09:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int LyXText::descent() const
|
|
|
|
|
{
|
2004-11-30 01:59:49 +00:00
|
|
|
|
return dim_.des;
|
2003-12-10 09:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-12-15 11:36:19 +00:00
|
|
|
|
|
2005-07-15 15:49:40 +00:00
|
|
|
|
int LyXText::cursorX(CursorSlice const & sl, bool boundary) const
|
2003-12-15 11:36:19 +00:00
|
|
|
|
{
|
2005-07-15 15:49:40 +00:00
|
|
|
|
pit_type const pit = sl.pit();
|
2004-08-15 00:01:45 +00:00
|
|
|
|
Paragraph const & par = pars_[pit];
|
2004-11-30 01:59:49 +00:00
|
|
|
|
if (par.rows().empty())
|
|
|
|
|
return 0;
|
2004-03-01 17:12:09 +00:00
|
|
|
|
|
2005-07-16 00:04:54 +00:00
|
|
|
|
pos_type ppos = sl.pos();
|
2005-07-16 12:02:31 +00:00
|
|
|
|
// Correct position in front of big insets
|
|
|
|
|
bool const boundary_correction = ppos != 0 && boundary;
|
|
|
|
|
if (boundary_correction)
|
2005-07-16 00:04:54 +00:00
|
|
|
|
--ppos;
|
2005-07-15 15:49:40 +00:00
|
|
|
|
|
2005-07-17 12:02:48 +00:00
|
|
|
|
Row const & row = par.getRow(sl.pos(), boundary);
|
2004-04-03 08:37:12 +00:00
|
|
|
|
|
2004-03-01 12:23:17 +00:00
|
|
|
|
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;
|
2005-07-16 00:04:54 +00:00
|
|
|
|
else if (ppos >= end)
|
2004-08-15 00:01:45 +00:00
|
|
|
|
cursor_vpos = isRTL(par) ? row_pos : end;
|
2005-07-16 00:04:54 +00:00
|
|
|
|
else if (ppos > row_pos && ppos >= end)
|
2003-12-15 11:36:19 +00:00
|
|
|
|
// Place cursor after char at (logical) position pos - 1
|
2005-07-16 00:04:54 +00:00
|
|
|
|
cursor_vpos = (bidi.level(ppos - 1) % 2 == 0)
|
|
|
|
|
? bidi.log2vis(ppos - 1) + 1 : bidi.log2vis(ppos - 1);
|
2003-12-15 11:36:19 +00:00
|
|
|
|
else
|
2005-07-16 00:04:54 +00:00
|
|
|
|
// Place cursor before char at (logical) position ppos
|
|
|
|
|
cursor_vpos = (bidi.level(ppos) % 2 == 0)
|
|
|
|
|
? bidi.log2vis(ppos) : bidi.log2vis(ppos) + 1;
|
2003-12-15 11:36:19 +00:00
|
|
|
|
|
2004-08-15 00:01:45 +00:00
|
|
|
|
pos_type body_pos = par.beginOfBody();
|
2003-12-15 11:36:19 +00:00
|
|
|
|
if (body_pos > 0 &&
|
2004-08-15 00:01:45 +00:00
|
|
|
|
(body_pos > end || !par.isLineSeparator(body_pos - 1)))
|
2003-12-15 11:36:19 +00:00
|
|
|
|
body_pos = 0;
|
|
|
|
|
|
2005-07-18 12:13:32 +00:00
|
|
|
|
// Use font span to speed things up, see below
|
2005-07-18 17:12:28 +00:00
|
|
|
|
FontSpan font_span;
|
|
|
|
|
LyXFont font;
|
2005-07-18 12:13:32 +00:00
|
|
|
|
|
2003-12-15 11:36:19 +00:00
|
|
|
|
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-08-15 00:01:45 +00:00
|
|
|
|
+ font_metrics::width(par.layout()->labelsep,
|
|
|
|
|
getLabelFont(par));
|
|
|
|
|
if (par.isLineSeparator(body_pos - 1))
|
|
|
|
|
x -= singleWidth(par, body_pos - 1);
|
2003-12-15 11:36:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-07-18 12:13:32 +00:00
|
|
|
|
// Use font span to speed things up, see above
|
|
|
|
|
if (pos < font_span.first || pos > font_span.last) {
|
|
|
|
|
font_span = par.fontSpan(pos);
|
|
|
|
|
font = getFont(par, pos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
x += singleWidth(par, pos, par.getChar(pos), font);
|
2005-07-16 12:02:31 +00:00
|
|
|
|
|
|
|
|
|
if (hfillExpansion(par, row, pos))
|
|
|
|
|
x += (pos >= body_pos) ? m.hfill : m.label_hfill;
|
|
|
|
|
else if (par.isSeparator(pos) && pos >= body_pos)
|
|
|
|
|
x += m.separator;
|
2003-12-15 11:36:19 +00:00
|
|
|
|
}
|
2006-04-05 23:56:29 +00:00
|
|
|
|
|
2005-07-15 15:49:40 +00:00
|
|
|
|
// see correction above
|
2005-07-16 12:02:31 +00:00
|
|
|
|
if (boundary_correction)
|
2005-10-03 12:13:58 +00:00
|
|
|
|
if (getFont(par, ppos).isVisibleRightToLeft())
|
2005-08-15 08:26:53 +00:00
|
|
|
|
x -= singleWidth(par, ppos);
|
|
|
|
|
else
|
|
|
|
|
x += singleWidth(par, ppos);
|
2005-07-15 15:49:40 +00:00
|
|
|
|
|
2005-10-03 12:13:58 +00:00
|
|
|
|
// Make sure inside an inset we always count from the left
|
|
|
|
|
// edge (bidi!) -- MV
|
|
|
|
|
if (sl.pos() < par.size()) {
|
|
|
|
|
font = getFont(par, sl.pos());
|
|
|
|
|
if (!boundary && font.isVisibleRightToLeft()
|
|
|
|
|
&& par.isInset(sl.pos()))
|
|
|
|
|
x -= par.getInset(sl.pos())->width();
|
2006-04-05 23:56:29 +00:00
|
|
|
|
}
|
2004-11-30 01:59:49 +00:00
|
|
|
|
return int(x);
|
2003-12-15 11:36:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-07-15 15:49:40 +00:00
|
|
|
|
int LyXText::cursorY(CursorSlice const & sl, bool boundary) const
|
2003-12-15 11:36:19 +00:00
|
|
|
|
{
|
2005-07-15 15:49:40 +00:00
|
|
|
|
//lyxerr << "LyXText::cursorY: boundary: " << boundary << std::endl;
|
|
|
|
|
Paragraph const & par = getPar(sl.pit());
|
2004-11-30 01:59:49 +00:00
|
|
|
|
int h = 0;
|
|
|
|
|
h -= pars_[0].rows()[0].ascent();
|
2005-07-15 15:49:40 +00:00
|
|
|
|
for (pit_type pit = 0; pit < sl.pit(); ++pit)
|
2004-11-30 01:59:49 +00:00
|
|
|
|
h += pars_[pit].height();
|
2005-07-16 00:04:54 +00:00
|
|
|
|
int pos = sl.pos();
|
|
|
|
|
if (pos && boundary)
|
|
|
|
|
--pos;
|
|
|
|
|
size_t const rend = par.pos2row(pos);
|
2005-07-15 15:49:40 +00:00
|
|
|
|
for (size_t rit = 0; rit != rend; ++rit)
|
2004-11-30 01:59:49 +00:00
|
|
|
|
h += par.rows()[rit].height();
|
2005-07-15 15:49:40 +00:00
|
|
|
|
h += par.rows()[rend].ascent();
|
2004-11-30 01:59:49 +00:00
|
|
|
|
return h;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
&& par.lookupChange(cur.pos()) != Change::UNCHANGED;
|
|
|
|
|
|
2006-03-11 13:31:41 +00:00
|
|
|
|
if (buf.params().tracking_changes)
|
|
|
|
|
os << "[C] ";
|
|
|
|
|
|
2004-02-13 07:30:59 +00:00
|
|
|
|
if (show_change) {
|
2006-05-05 23:11:19 +00:00
|
|
|
|
Change change = par.lookupChange(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)
|
2006-02-05 13:20:16 +00:00
|
|
|
|
// No, from the document font (MV)
|
2004-02-13 07:30:59 +00:00
|
|
|
|
LyXFont font = real_current_font;
|
2006-02-05 13:20:16 +00:00
|
|
|
|
font.reduce(buf.params().getFont());
|
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)
|
2005-01-06 15:40:49 +00:00
|
|
|
|
os << bformat(_(", Depth: %1$d"), depth);
|
2004-02-13 07:30:59 +00:00
|
|
|
|
|
|
|
|
|
// 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:
|
2005-01-06 13:48:13 +00:00
|
|
|
|
os << _("Other (") << spacing.getValueAsString() << ')';
|
2004-02-13 07:30:59 +00:00
|
|
|
|
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();
|
2004-11-24 21:53:46 +00:00
|
|
|
|
os << _(", Paragraph: ") << cur.pit();
|
2004-04-08 15:03:33 +00:00
|
|
|
|
os << _(", Id: ") << par.id();
|
2004-02-13 07:30:59 +00:00
|
|
|
|
os << _(", Position: ") << cur.pos();
|
2005-07-16 16:27:08 +00:00
|
|
|
|
os << _(", Boundary: ") << cur.boundary();
|
2004-11-30 01:59:49 +00:00
|
|
|
|
// Row & row = cur.textRow();
|
|
|
|
|
// os << bformat(_(", Row b:%1$d e:%2$d"), row.pos(), row.endpos());
|
2004-02-13 07:30:59 +00:00
|
|
|
|
#endif
|
|
|
|
|
return os.str();
|
|
|
|
|
}
|
2004-02-13 13:51:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string LyXText::getPossibleLabel(LCursor & cur) const
|
|
|
|
|
{
|
2004-11-24 21:53:46 +00:00
|
|
|
|
pit_type pit = cur.pit();
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-16 13:35:53 +00:00
|
|
|
|
string name = layout->latexname();
|
|
|
|
|
|
|
|
|
|
// for captions, we want the abbreviation of the float type
|
|
|
|
|
if (layout->labeltype == LABEL_SENSITIVE) {
|
|
|
|
|
// Search for the first float or wrap inset in the iterator
|
|
|
|
|
size_t i = cur.depth();
|
|
|
|
|
while (i > 0) {
|
|
|
|
|
--i;
|
|
|
|
|
InsetBase * const in = &cur[i].inset();
|
|
|
|
|
if (in->lyxCode() == InsetBase::FLOAT_CODE
|
|
|
|
|
|| in->lyxCode() == InsetBase::WRAP_CODE) {
|
|
|
|
|
name = in->getInsetName();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string text = name.substr(0, 3);
|
|
|
|
|
if (name == "theorem")
|
2004-02-13 13:51:12 +00:00
|
|
|
|
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-11-30 01:59:49 +00:00
|
|
|
|
//pos_type LyXText::x2pos(pit_type pit, int row, int x) const
|
|
|
|
|
//{
|
|
|
|
|
// int lastx = 0;
|
|
|
|
|
// int currx = 0;
|
|
|
|
|
// Paragraph const & par = pars_[pit];
|
|
|
|
|
// Row const & r = par.rows()[row];
|
|
|
|
|
// int pos = r.pos();
|
|
|
|
|
// for (; currx < x && pos < r.endpos(); ++pos) {
|
|
|
|
|
// lastx = currx;
|
|
|
|
|
// currx += singleWidth(par, pos);
|
|
|
|
|
// }
|
|
|
|
|
// if (abs(lastx - x) < abs(currx - x) && pos != r.pos())
|
|
|
|
|
// --pos;
|
|
|
|
|
// return pos;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pos_type LyXText::x2pos(pit_type pit, int row, int x) const
|
|
|
|
|
{
|
2005-07-15 15:49:40 +00:00
|
|
|
|
BOOST_ASSERT(row < int(pars_[pit].rows().size()));
|
2004-11-30 01:59:49 +00:00
|
|
|
|
bool bound = false;
|
|
|
|
|
Row const & r = pars_[pit].rows()[row];
|
|
|
|
|
return r.pos() + getColumnNearX(pit, r, x, bound);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//int LyXText::pos2x(pit_type pit, pos_type pos) const
|
|
|
|
|
//{
|
|
|
|
|
// Paragraph const & par = pars_[pit];
|
|
|
|
|
// Row const & r = par.rows()[row];
|
|
|
|
|
// int x = 0;
|
2005-01-06 15:40:49 +00:00
|
|
|
|
// pos -= r.pos();
|
2004-11-30 01:59:49 +00:00
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// x,y are screen coordinates
|
|
|
|
|
// sets cursor only within this LyXText
|
2005-10-13 14:48:27 +00:00
|
|
|
|
bool LyXText::setCursorFromCoordinates(LCursor & cur, int const x, int const y)
|
2004-02-16 11:58:51 +00:00
|
|
|
|
{
|
2004-11-30 01:59:49 +00:00
|
|
|
|
pit_type pit = getPitNearY(y);
|
|
|
|
|
int yy = theCoords.get(this, pit).y_ - pars_[pit].ascent();
|
2005-07-14 08:20:10 +00:00
|
|
|
|
lyxerr[Debug::DEBUG]
|
2006-04-05 23:56:29 +00:00
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< ": x: " << x
|
|
|
|
|
<< " y: " << y
|
2005-07-14 08:20:10 +00:00
|
|
|
|
<< " pit: " << pit
|
2006-04-05 23:56:29 +00:00
|
|
|
|
<< " yy: " << yy << endl;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
|
|
|
|
|
Paragraph const & par = pars_[pit];
|
|
|
|
|
int r = 0;
|
|
|
|
|
BOOST_ASSERT(par.rows().size());
|
|
|
|
|
for (; r < int(par.rows().size()) - 1; ++r) {
|
|
|
|
|
Row const & row = par.rows()[r];
|
|
|
|
|
if (int(yy + row.height()) > y)
|
|
|
|
|
break;
|
|
|
|
|
yy += row.height();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Row const & row = par.rows()[r];
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2005-07-14 08:20:10 +00:00
|
|
|
|
lyxerr[Debug::DEBUG]
|
2006-04-05 23:56:29 +00:00
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< ": row " << r
|
|
|
|
|
<< " from pos: " << row.pos()
|
|
|
|
|
<< endl;
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
bool bound = false;
|
|
|
|
|
int xx = x;
|
|
|
|
|
pos_type const pos = row.pos() + getColumnNearX(pit, row, xx, bound);
|
2005-07-15 12:56:23 +00:00
|
|
|
|
|
2006-04-05 23:56:29 +00:00
|
|
|
|
lyxerr[Debug::DEBUG]
|
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< ": setting cursor pit: " << pit
|
|
|
|
|
<< " pos: " << pos
|
|
|
|
|
<< endl;
|
|
|
|
|
|
2005-10-13 14:48:27 +00:00
|
|
|
|
return setCursor(cur, pit, pos, true, bound);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
}
|