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
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "buffer.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
#include "bufferparams.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
#include "BufferView.h"
|
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"
|
2003-09-04 03:54:04 +00:00
|
|
|
|
#include "funcrequest.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-09-06 23:36:02 +00:00
|
|
|
|
#include "lyxrc.h"
|
|
|
|
|
#include "lyxrow.h"
|
|
|
|
|
#include "lyxrow_funcs.h"
|
2003-10-17 10:31:47 +00:00
|
|
|
|
#include "metricsinfo.h"
|
2003-09-16 12:12:33 +00:00
|
|
|
|
#include "paragraph.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
#include "paragraph_funcs.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "ParagraphParameters.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
#include "rowpainter.h"
|
2003-10-14 13:01:49 +00:00
|
|
|
|
#include "undo.h"
|
2003-09-09 17:00:19 +00:00
|
|
|
|
#include "vspace.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
|
#include "WordLangTuple.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
|
|
|
|
|
#include "frontends/font_metrics.h"
|
|
|
|
|
#include "frontends/LyXView.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-11-15 00:39:11 +00:00
|
|
|
|
#include "insets/insettext.h"
|
|
|
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
#include "support/textutils.h"
|
2001-11-15 00:39:11 +00:00
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::pos_type;
|
|
|
|
|
using lyx::word_location;
|
|
|
|
|
|
|
|
|
|
using lyx::support::contains;
|
|
|
|
|
using lyx::support::lowercase;
|
|
|
|
|
using lyx::support::uppercase;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2000-01-14 18:41:30 +00:00
|
|
|
|
using std::max;
|
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-02-08 19:18:01 +00:00
|
|
|
|
/// top, right, bottom pixel margin
|
2003-02-26 17:04:10 +00:00
|
|
|
|
extern int const PAPER_MARGIN = 20;
|
2003-02-08 19:18:01 +00:00
|
|
|
|
/// margin for changebar
|
2003-02-26 17:04:10 +00:00
|
|
|
|
extern int const CHANGEBAR_MARGIN = 10;
|
2003-02-08 19:18:01 +00:00
|
|
|
|
/// left margin
|
2003-02-26 17:04:10 +00:00
|
|
|
|
extern int const LEFT_MARGIN = PAPER_MARGIN + CHANGEBAR_MARGIN;
|
2000-09-26 13:54:57 +00:00
|
|
|
|
|
2003-08-26 10:33:59 +00:00
|
|
|
|
|
|
|
|
|
|
2003-07-28 22:34:48 +00:00
|
|
|
|
int bibitemMaxWidth(BufferView *, LyXFont const &);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-05-05 10:17:05 +00:00
|
|
|
|
|
2003-10-23 09:06:18 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
unsigned int maxParagraphWidth(ParagraphList const & plist)
|
|
|
|
|
{
|
|
|
|
|
unsigned int width = 0;
|
|
|
|
|
ParagraphList::const_iterator pit = plist.begin();
|
|
|
|
|
ParagraphList::const_iterator end = plist.end();
|
|
|
|
|
for (; pit != end; ++pit)
|
|
|
|
|
width = std::max(width, pit->width);
|
|
|
|
|
return width;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
BufferView * LyXText::bv()
|
|
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(bv_owner != 0);
|
2003-03-17 16:25:00 +00:00
|
|
|
|
return bv_owner;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-28 11:18:40 +00:00
|
|
|
|
double LyXText::spacing(Paragraph const & par) const
|
|
|
|
|
{
|
|
|
|
|
if (par.params().spacing().isDefault())
|
|
|
|
|
return bv()->buffer()->params().spacing().getValue();
|
|
|
|
|
return par.params().spacing().getValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
BufferView * LyXText::bv() const
|
|
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(bv_owner != 0);
|
2003-03-17 16:25:00 +00:00
|
|
|
|
return bv_owner;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-04-12 23:03:05 +00:00
|
|
|
|
void LyXText::updateRowPositions()
|
2003-03-06 20:21:21 +00:00
|
|
|
|
{
|
2003-08-15 08:03:54 +00:00
|
|
|
|
ParagraphList::iterator pit = ownerParagraphs().begin();
|
|
|
|
|
ParagraphList::iterator end = ownerParagraphs().end();
|
2003-08-22 16:01:13 +00:00
|
|
|
|
for (height = 0; pit != end; ++pit) {
|
2003-10-16 16:19:56 +00:00
|
|
|
|
pit->y = height;
|
|
|
|
|
height += pit->height;
|
2003-03-06 20:21:21 +00:00
|
|
|
|
}
|
2003-04-12 23:03:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
int LyXText::workWidth() const
|
2000-06-12 11:27:15 +00:00
|
|
|
|
{
|
2003-07-18 12:05:50 +00:00
|
|
|
|
return inset_owner ? inset_owner->textWidth() : bv()->workWidth();
|
2000-06-12 11:27:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-10 21:40:13 +00:00
|
|
|
|
|
2003-04-09 21:34:31 +00:00
|
|
|
|
int LyXText::singleWidth(ParagraphList::iterator pit, pos_type pos) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-04-09 21:34:31 +00:00
|
|
|
|
if (pos >= pit->size())
|
2003-03-13 10:30:28 +00:00
|
|
|
|
return 0;
|
|
|
|
|
|
2003-04-09 21:34:31 +00:00
|
|
|
|
char const c = pit->getChar(pos);
|
2003-08-22 07:49:57 +00:00
|
|
|
|
LyXFont const & font = getFont(pit, pos);
|
|
|
|
|
return singleWidth(pit, pos, c, font);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-04-09 21:34:31 +00:00
|
|
|
|
int LyXText::singleWidth(ParagraphList::iterator pit,
|
2003-08-22 07:49:57 +00:00
|
|
|
|
pos_type pos, char c, LyXFont const & font) const
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
2003-08-22 07:49:57 +00:00
|
|
|
|
if (pos >= pit->size()) {
|
|
|
|
|
lyxerr << "in singleWidth(), pos: " << pos << endl;
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(false);
|
2003-03-13 10:30:28 +00:00
|
|
|
|
return 0;
|
2003-08-22 07:49:57 +00:00
|
|
|
|
}
|
2003-03-13 10:30:28 +00:00
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
|
// The most common case is handled first (Asger)
|
|
|
|
|
if (IsPrintable(c)) {
|
2003-10-21 16:15:14 +00:00
|
|
|
|
if (!font.language()->RightToLeft()) {
|
2003-07-27 00:37:17 +00:00
|
|
|
|
if ((lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
|
|
|
|
|
lyxrc.font_norm_type == LyXRC::ISO_10646_1)
|
|
|
|
|
&& font.language()->lang() == "arabic") {
|
2000-10-10 12:36:36 +00:00
|
|
|
|
if (Encodings::IsComposeChar_arabic(c))
|
2000-07-04 20:32:37 +00:00
|
|
|
|
return 0;
|
|
|
|
|
else
|
2003-10-27 12:41:26 +00:00
|
|
|
|
c = pit->transformChar(c, pos);
|
2003-03-11 15:01:29 +00:00
|
|
|
|
} else if (font.language()->lang() == "hebrew" &&
|
2000-10-10 12:36:36 +00:00
|
|
|
|
Encodings::IsComposeChar_hebrew(c))
|
2000-05-05 10:17:05 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2002-05-24 14:34:32 +00:00
|
|
|
|
return font_metrics::width(c, font);
|
2003-03-11 15:01:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-10-29 10:47:21 +00:00
|
|
|
|
if (c == Paragraph::META_INSET)
|
2003-10-28 11:18:40 +00:00
|
|
|
|
return pit->getInset(pos)->width();
|
2000-02-10 17:53:36 +00:00
|
|
|
|
|
2003-03-11 15:01:29 +00:00
|
|
|
|
if (IsSeparatorChar(c))
|
2000-02-10 17:53:36 +00:00
|
|
|
|
c = ' ';
|
2002-05-24 14:34:32 +00:00
|
|
|
|
return font_metrics::width(c, font);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2003-08-14 08:34:13 +00:00
|
|
|
|
int LyXText::leftMargin(ParagraphList::iterator pit, Row const & row) const
|
2003-08-26 10:33:59 +00:00
|
|
|
|
{
|
2001-10-16 14:47:10 +00:00
|
|
|
|
LyXTextClass const & tclass =
|
2003-09-09 09:47:59 +00:00
|
|
|
|
bv()->buffer()->params().getLyXTextClass();
|
2003-08-14 08:34:13 +00:00
|
|
|
|
LyXLayout_ptr const & layout = pit->layout();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
string parindent = layout->parindent;
|
2000-06-08 23:16:16 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
int x = LEFT_MARGIN;
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2002-05-24 14:34:32 +00:00
|
|
|
|
x += font_metrics::signedWidth(tclass.leftmargin(), tclass.defaultfont());
|
2001-05-03 14:31:33 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// this is the way, LyX handles the LaTeX-Environments.
|
|
|
|
|
// I have had this idea very late, so it seems to be a
|
|
|
|
|
// later added hack and this is true
|
2003-10-28 11:18:40 +00:00
|
|
|
|
if (pit->getDepth() == 0) {
|
2003-08-14 08:34:13 +00:00
|
|
|
|
if (pit->layout() == tclass.defaultLayout()) {
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// find the previous same level paragraph
|
2003-08-14 08:34:13 +00:00
|
|
|
|
if (pit != ownerParagraphs().begin()) {
|
2003-04-16 08:12:22 +00:00
|
|
|
|
ParagraphList::iterator newpit =
|
2003-10-28 11:18:40 +00:00
|
|
|
|
depthHook(pit, ownerParagraphs(), pit->getDepth());
|
|
|
|
|
if (newpit == pit && newpit->layout()->nextnoindent)
|
2000-05-04 10:57:00 +00:00
|
|
|
|
parindent.erase();
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// find the next level paragraph
|
2003-10-28 11:18:40 +00:00
|
|
|
|
ParagraphList::iterator newpar =
|
|
|
|
|
outerHook(pit, ownerParagraphs());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-07 20:32:29 +00:00
|
|
|
|
// make a corresponding row. Needed to call leftMargin()
|
2002-03-02 16:39:54 +00:00
|
|
|
|
// check wether it is a sufficent paragraph
|
2003-10-28 11:18:40 +00:00
|
|
|
|
if (newpar != ownerParagraphs().end()
|
|
|
|
|
&& newpar->layout()->isEnvironment()) {
|
2003-08-14 08:34:13 +00:00
|
|
|
|
x = leftMargin(newpar, Row(newpar->size()));
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2002-03-02 16:39:54 +00:00
|
|
|
|
|
2003-10-28 11:18:40 +00:00
|
|
|
|
if (newpar != ownerParagraphs().end()
|
|
|
|
|
&& pit->layout() == tclass.defaultLayout()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (newpar->params().noindent())
|
2000-05-04 10:57:00 +00:00
|
|
|
|
parindent.erase();
|
2003-10-28 11:18:40 +00:00
|
|
|
|
else
|
2002-06-24 20:28:12 +00:00
|
|
|
|
parindent = newpar->layout()->parindent;
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-08-14 08:34:13 +00:00
|
|
|
|
LyXFont const labelfont = getLabelFont(pit);
|
2002-06-24 20:28:12 +00:00
|
|
|
|
switch (layout->margintype) {
|
2000-01-13 16:28:54 +00:00
|
|
|
|
case MARGIN_DYNAMIC:
|
2003-10-28 11:18:40 +00:00
|
|
|
|
if (!layout->leftmargin.empty())
|
2002-06-24 20:28:12 +00:00
|
|
|
|
x += font_metrics::signedWidth(layout->leftmargin,
|
2001-10-16 14:47:10 +00:00
|
|
|
|
tclass.defaultfont());
|
2003-08-14 08:34:13 +00:00
|
|
|
|
if (!pit->getLabelstring().empty()) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
x += font_metrics::signedWidth(layout->labelindent,
|
2000-04-04 00:19:15 +00:00
|
|
|
|
labelfont);
|
2003-08-14 08:34:13 +00:00
|
|
|
|
x += font_metrics::width(pit->getLabelstring(),
|
2000-06-08 23:16:16 +00:00
|
|
|
|
labelfont);
|
2002-06-24 20:28:12 +00:00
|
|
|
|
x += 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:
|
2002-06-24 20:28:12 +00:00
|
|
|
|
x += 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
|
2003-11-13 13:43:44 +00:00
|
|
|
|
if (!pit->empty() && row.pos() >= pit->beginOfBody()) {
|
2003-08-14 08:34:13 +00:00
|
|
|
|
if (!pit->getLabelWidthString().empty()) {
|
|
|
|
|
x += font_metrics::width(pit->getLabelWidthString(),
|
2000-04-04 00:19:15 +00:00
|
|
|
|
labelfont);
|
2002-06-24 20:28:12 +00:00
|
|
|
|
x += 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:
|
2002-06-24 20:28:12 +00:00
|
|
|
|
x += font_metrics::signedWidth(layout->leftmargin, tclass.defaultfont()) * 4
|
2003-08-14 08:34:13 +00:00
|
|
|
|
/ (pit->getDepth() + 4);
|
2000-01-13 16:28:54 +00:00
|
|
|
|
break;
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
case MARGIN_FIRST_DYNAMIC:
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (layout->labeltype == LABEL_MANUAL) {
|
2003-11-13 13:43:44 +00:00
|
|
|
|
if (row.pos() >= pit->beginOfBody()) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
x += font_metrics::signedWidth(layout->leftmargin,
|
2000-06-08 23:16:16 +00:00
|
|
|
|
labelfont);
|
2000-01-13 16:28:54 +00:00
|
|
|
|
} else {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
x += font_metrics::signedWidth(layout->labelindent,
|
2000-06-08 23:16:16 +00:00
|
|
|
|
labelfont);
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2003-04-01 16:55:48 +00:00
|
|
|
|
} else if (row.pos()
|
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
|
2003-08-14 08:34:13 +00:00
|
|
|
|
&& !isFirstInSequence(pit, ownerParagraphs()))) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
x += 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) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
x += font_metrics::signedWidth(layout->labelindent,
|
2000-04-04 00:19:15 +00:00
|
|
|
|
labelfont);
|
2002-06-24 20:28:12 +00:00
|
|
|
|
x += font_metrics::width(layout->labelsep, labelfont);
|
2003-08-14 08:34:13 +00:00
|
|
|
|
x += font_metrics::width(pit->getLabelstring(),
|
2000-06-08 23:16:16 +00:00
|
|
|
|
labelfont);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
}
|
2000-01-13 16:28:54 +00:00
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-28 11:18:40 +00:00
|
|
|
|
case MARGIN_RIGHT_ADDRESS_BOX: {
|
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.
|
2003-08-15 08:03:54 +00:00
|
|
|
|
RowList::iterator rit = pit->rows.begin();
|
|
|
|
|
RowList::iterator end = pit->rows.end();
|
2003-10-24 08:33:52 +00:00
|
|
|
|
#warning This is wrong.
|
|
|
|
|
int minfill = workWidth() / 2;
|
2003-08-14 09:59:05 +00:00
|
|
|
|
for ( ; rit != end; ++rit)
|
|
|
|
|
if (rit->fill() < minfill)
|
|
|
|
|
minfill = rit->fill();
|
2002-06-24 20:28:12 +00:00
|
|
|
|
x += font_metrics::signedWidth(layout->leftmargin,
|
2002-05-24 14:34:32 +00:00
|
|
|
|
tclass.defaultfont());
|
2000-01-13 16:28:54 +00:00
|
|
|
|
x += minfill;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-08-14 08:34:13 +00:00
|
|
|
|
if (workWidth() > 0 && !pit->params().leftIndent().zero()) {
|
|
|
|
|
LyXLength const len = pit->params().leftIndent();
|
2002-05-08 12:58:16 +00:00
|
|
|
|
int const tw = inset_owner ?
|
2003-03-17 16:25:00 +00:00
|
|
|
|
inset_owner->latexTextWidth(bv()) : workWidth();
|
2002-10-24 18:31:47 +00:00
|
|
|
|
x += len.inPixels(tw);
|
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
|
|
|
|
|
2003-08-14 08:34:13 +00:00
|
|
|
|
if (pit->params().align() == LYX_ALIGN_LAYOUT)
|
2002-06-24 20:28:12 +00:00
|
|
|
|
align = layout->align;
|
2000-07-19 17:16:27 +00:00
|
|
|
|
else
|
2003-08-14 08:34:13 +00:00
|
|
|
|
align = pit->params().align();
|
2001-05-03 14:31:33 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// set the correct parindent
|
2003-04-01 16:55:48 +00:00
|
|
|
|
if (row.pos() == 0) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if ((layout->labeltype == LABEL_NO_LABEL
|
|
|
|
|
|| layout->labeltype == LABEL_TOP_ENVIRONMENT
|
|
|
|
|
|| layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
|
|
|
|
|
|| (layout->labeltype == LABEL_STATIC
|
|
|
|
|
&& layout->latextype == LATEX_ENVIRONMENT
|
2003-08-14 08:34:13 +00:00
|
|
|
|
&& !isFirstInSequence(pit, ownerParagraphs())))
|
2000-01-13 16:28:54 +00:00
|
|
|
|
&& align == LYX_ALIGN_BLOCK
|
2003-08-14 08:34:13 +00:00
|
|
|
|
&& !pit->params().noindent()
|
2002-03-06 10:17:29 +00:00
|
|
|
|
// in tabulars and ert paragraphs are never indented!
|
2003-08-14 08:34:13 +00:00
|
|
|
|
&& (!pit->inInset() || !pit->inInset()->owner() ||
|
|
|
|
|
(pit->inInset()->owner()->lyxCode() != InsetOld::TABULAR_CODE &&
|
|
|
|
|
pit->inInset()->owner()->lyxCode() != InsetOld::ERT_CODE))
|
|
|
|
|
&& (pit->layout() != tclass.defaultLayout() ||
|
2003-09-09 09:47:59 +00:00
|
|
|
|
bv()->buffer()->params().paragraph_separation ==
|
2002-03-02 16:39:54 +00:00
|
|
|
|
BufferParams::PARSEP_INDENT)) {
|
2002-05-24 14:34:32 +00:00
|
|
|
|
x += font_metrics::signedWidth(parindent,
|
2001-10-16 14:47:10 +00:00
|
|
|
|
tclass.defaultfont());
|
2002-06-24 20:28:12 +00:00
|
|
|
|
} else if (layout->labeltype == LABEL_BIBLIO) {
|
2001-07-20 14:18:48 +00:00
|
|
|
|
// ale970405 Right width for bibitems
|
2003-03-17 16:25:00 +00:00
|
|
|
|
x += bibitemMaxWidth(bv(), tclass.defaultfont());
|
2000-02-17 19:59:08 +00:00
|
|
|
|
}
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
return x;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-04-26 13:57:28 +00:00
|
|
|
|
|
|
|
|
|
|
2003-10-28 11:18:40 +00:00
|
|
|
|
int LyXText::rightMargin(Paragraph const & par, Buffer const & buf) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-09-09 09:47:59 +00:00
|
|
|
|
LyXTextClass const & tclass = buf.params().getLyXTextClass();
|
2003-10-17 10:31:47 +00:00
|
|
|
|
LyXLayout_ptr const & layout = par.layout();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-07-29 01:46:09 +00:00
|
|
|
|
return PAPER_MARGIN
|
2002-05-24 14:34:32 +00:00
|
|
|
|
+ font_metrics::signedWidth(tclass.rightmargin(),
|
2003-10-20 13:55:51 +00:00
|
|
|
|
tclass.defaultfont())
|
2003-07-29 01:46:09 +00:00
|
|
|
|
+ font_metrics::signedWidth(layout->rightmargin,
|
2002-06-24 20:28:12 +00:00
|
|
|
|
tclass.defaultfont())
|
2003-10-17 10:31:47 +00:00
|
|
|
|
* 4 / (par.getDepth() + 4);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-14 08:34:13 +00:00
|
|
|
|
int LyXText::labelEnd(ParagraphList::iterator pit, Row const & row) 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.
|
|
|
|
|
if (pit->layout()->margintype != MARGIN_MANUAL)
|
|
|
|
|
return 0;
|
2003-02-26 17:04:10 +00:00
|
|
|
|
|
2003-10-28 11:18:40 +00:00
|
|
|
|
Row tmprow = row;
|
|
|
|
|
tmprow.pos(pit->size());
|
|
|
|
|
// return the beginning of the body
|
|
|
|
|
return leftMargin(pit, tmprow);
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2003-10-23 15:38:48 +00:00
|
|
|
|
void LyXText::rowBreakPoint(ParagraphList::iterator pit, Row & row) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-10-27 10:27:50 +00:00
|
|
|
|
pos_type const end = pit->size();
|
|
|
|
|
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-03-09 21:54:56 +00:00
|
|
|
|
// maximum pixel width of a row.
|
2003-10-28 11:18:40 +00:00
|
|
|
|
int width = workWidth() - rightMargin(*pit, *bv()->buffer());
|
2003-10-27 10:27:50 +00:00
|
|
|
|
// - leftMargin(pit, row);
|
2003-03-09 21:54:56 +00:00
|
|
|
|
|
|
|
|
|
// inset->textWidth() returns -1 via workWidth(),
|
|
|
|
|
// but why ?
|
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
|
|
|
|
|
2003-04-02 23:01:39 +00:00
|
|
|
|
LyXLayout_ptr const & layout = pit->layout();
|
2000-11-21 15:46:13 +00:00
|
|
|
|
|
2003-10-23 15:38:48 +00:00
|
|
|
|
if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
|
2003-10-27 10:27:50 +00:00
|
|
|
|
row.endpos(addressBreakPoint(pos, *pit));
|
2003-10-23 15:38:48 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
pos_type const body_pos = pit->beginOfBody();
|
2003-03-13 10:30:28 +00:00
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-03-09 21:54:56 +00:00
|
|
|
|
// Now we iterate through until we reach the right margin
|
|
|
|
|
// or the end of the par, then choose the possible break
|
|
|
|
|
// nearest that.
|
|
|
|
|
|
2003-08-14 08:34:13 +00:00
|
|
|
|
int const left = leftMargin(pit, row);
|
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
|
|
|
|
|
2003-10-27 11:44:10 +00:00
|
|
|
|
|
2003-07-27 11:16:25 +00:00
|
|
|
|
// We re-use the font resolution for the entire font span when possible
|
2003-10-27 10:27:50 +00:00
|
|
|
|
LyXFont font = getFont(pit, pos);
|
|
|
|
|
lyx::pos_type endPosOfFontSpan = pit->getEndPosOfFontSpan(pos);
|
2003-07-27 11:16:25 +00:00
|
|
|
|
|
2003-10-27 10:27:50 +00:00
|
|
|
|
pos_type point = end;
|
|
|
|
|
pos_type i = pos;
|
2003-10-24 15:04:17 +00:00
|
|
|
|
for ( ; i < end; ++i) {
|
2003-04-02 23:01:39 +00:00
|
|
|
|
if (pit->isNewline(i)) {
|
2003-10-27 10:27:50 +00:00
|
|
|
|
point = i + 1;
|
2003-03-09 21:54:56 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2003-10-29 10:47:21 +00:00
|
|
|
|
// Break before...
|
2003-10-24 15:04:17 +00:00
|
|
|
|
if (i + 1 < end) {
|
2003-10-21 13:04:14 +00:00
|
|
|
|
InsetOld * in = pit->getInset(i + 1);
|
2003-10-20 18:56:48 +00:00
|
|
|
|
if (in && in->display()) {
|
2003-10-27 10:27:50 +00:00
|
|
|
|
point = i + 1;
|
2003-10-20 18:56:48 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// ...and after.
|
|
|
|
|
in = pit->getInset(i);
|
|
|
|
|
if (in && in->display()) {
|
2003-10-27 10:27:50 +00:00
|
|
|
|
point = i + 1;
|
2003-10-20 18:56:48 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-03-09 21:54:56 +00:00
|
|
|
|
|
2003-04-02 23:01:39 +00:00
|
|
|
|
char const c = pit->getChar(i);
|
2003-10-29 10:47:21 +00:00
|
|
|
|
|
2003-08-22 09:40:56 +00:00
|
|
|
|
if (i > endPosOfFontSpan) {
|
|
|
|
|
font = getFont(pit, i);
|
|
|
|
|
endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
|
|
|
|
|
}
|
2003-10-29 10:47:21 +00:00
|
|
|
|
|
2003-10-27 10:27:50 +00:00
|
|
|
|
{
|
|
|
|
|
int thiswidth = singleWidth(pit, i, c, font);
|
2003-03-12 19:16:42 +00:00
|
|
|
|
|
2003-10-27 10:27:50 +00:00
|
|
|
|
// add the auto-hfill from label end to the body
|
|
|
|
|
if (body_pos && i == body_pos) {
|
|
|
|
|
int add = font_metrics::width(layout->labelsep, getLabelFont(pit));
|
|
|
|
|
if (pit->isLineSeparator(i - 1))
|
|
|
|
|
add -= singleWidth(pit, i - 1);
|
|
|
|
|
|
|
|
|
|
add = std::max(add, labelEnd(pit, row) - x);
|
|
|
|
|
thiswidth += add;
|
|
|
|
|
}
|
2003-03-09 21:54:56 +00:00
|
|
|
|
|
2003-10-27 10:27:50 +00:00
|
|
|
|
x += thiswidth;
|
|
|
|
|
//lyxerr << "i: " << i << " x: "
|
|
|
|
|
//<< x << " width: " << width << endl;
|
|
|
|
|
chunkwidth += thiswidth;
|
|
|
|
|
}
|
2003-10-29 10:47:21 +00:00
|
|
|
|
|
2003-03-10 04:59:48 +00:00
|
|
|
|
|
2003-03-09 21:54:56 +00:00
|
|
|
|
// break before a character that will fall off
|
|
|
|
|
// the right of the row
|
|
|
|
|
if (x >= width) {
|
2003-08-26 10:33:59 +00:00
|
|
|
|
// if no break before, break here
|
2003-10-24 15:04:17 +00:00
|
|
|
|
if (point == end || chunkwidth >= width - left) {
|
2003-10-27 10:27:50 +00:00
|
|
|
|
if (i > pos) {
|
|
|
|
|
point = i;
|
2003-10-29 10:47:21 +00:00
|
|
|
|
break;
|
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
|
|
|
|
#if 0
|
|
|
|
|
// hack removed:
|
2003-10-24 15:04:17 +00:00
|
|
|
|
if (i + 1 < end)
|
2003-10-28 14:04:56 +00:00
|
|
|
|
#endif
|
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2003-03-09 21:54:56 +00:00
|
|
|
|
|
2003-10-21 17:16:01 +00:00
|
|
|
|
InsetOld * in = pit->getInset(i);
|
2003-03-09 21:54:56 +00:00
|
|
|
|
if (!in || in->isChar()) {
|
|
|
|
|
// some insets are line separators too
|
2003-04-02 23:01:39 +00:00
|
|
|
|
if (pit->isLineSeparator(i)) {
|
2003-10-22 06:02:55 +00:00
|
|
|
|
// register breakpoint:
|
2003-10-29 10:47:21 +00:00
|
|
|
|
point = i + 1;
|
2003-03-10 04:59:48 +00:00
|
|
|
|
chunkwidth = 0;
|
|
|
|
|
}
|
2003-03-09 21:54:56 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-28 14:04:56 +00:00
|
|
|
|
#if 0
|
|
|
|
|
// hack removed (connected with the #if 0 above):
|
2003-10-27 10:27:50 +00:00
|
|
|
|
if (point == end && i != end && x >= width) {
|
2003-03-10 01:46:40 +00:00
|
|
|
|
// didn't find one, break at the point we reached the edge
|
2003-10-27 10:27:50 +00:00
|
|
|
|
point = i + 1;
|
2003-10-28 14:04:56 +00:00
|
|
|
|
} else
|
|
|
|
|
#endif
|
|
|
|
|
if (i == end && x < width) {
|
2003-10-27 10:27:50 +00:00
|
|
|
|
// maybe found one, but the par is short enough.
|
|
|
|
|
point = end;
|
2003-03-10 01:46:40 +00:00
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// returns the minimum space a row needs on the screen in pixel
|
2003-10-28 11:18:40 +00:00
|
|
|
|
void LyXText::fill(ParagraphList::iterator pit, Row & row, int workwidth) 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
|
|
|
|
|
2003-04-13 12:56:48 +00:00
|
|
|
|
LyXLayout_ptr const & layout = pit->layout();
|
2003-10-28 11:18:40 +00:00
|
|
|
|
int w = leftMargin(pit, row);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
pos_type const body_pos = pit->beginOfBody();
|
2003-10-17 10:31:47 +00:00
|
|
|
|
pos_type i = row.pos();
|
2000-02-03 19:51:27 +00:00
|
|
|
|
|
2003-10-27 11:44:10 +00:00
|
|
|
|
if (i < end) {
|
2003-07-27 10:42:11 +00:00
|
|
|
|
// We re-use the font resolution for the entire span when possible
|
2003-07-27 21:59:06 +00:00
|
|
|
|
LyXFont font = getFont(pit, i);
|
2003-07-27 10:42:11 +00:00
|
|
|
|
lyx::pos_type endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
|
2003-10-28 11:18:40 +00:00
|
|
|
|
for ( ; i < end; ++i) {
|
2003-07-27 00:37:17 +00:00
|
|
|
|
if (body_pos > 0 && i == body_pos) {
|
2003-07-27 21:59:06 +00:00
|
|
|
|
w += font_metrics::width(layout->labelsep, getLabelFont(pit));
|
2003-07-27 00:37:17 +00:00
|
|
|
|
if (pit->isLineSeparator(i - 1))
|
|
|
|
|
w -= singleWidth(pit, i - 1);
|
2003-10-28 11:18:40 +00:00
|
|
|
|
w = max(w, labelEnd(pit, row));
|
2003-07-27 00:37:17 +00:00
|
|
|
|
}
|
2003-08-22 07:49:57 +00:00
|
|
|
|
char const c = pit->getChar(i);
|
|
|
|
|
if (IsPrintable(c) && i > endPosOfFontSpan) {
|
|
|
|
|
// We need to get the next font
|
|
|
|
|
font = getFont(pit, i);
|
|
|
|
|
endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
|
2003-07-27 10:42:11 +00:00
|
|
|
|
}
|
2003-08-28 07:41:31 +00:00
|
|
|
|
w += singleWidth(pit, i, c, font);
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2000-02-03 19:51:27 +00:00
|
|
|
|
}
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
2003-10-27 11:44:10 +00:00
|
|
|
|
if (body_pos > 0 && body_pos >= end) {
|
2003-07-27 21:59:06 +00:00
|
|
|
|
w += font_metrics::width(layout->labelsep, getLabelFont(pit));
|
2003-10-27 11:44:10 +00:00
|
|
|
|
if (end > 0 && pit->isLineSeparator(end - 1))
|
|
|
|
|
w -= singleWidth(pit, end - 1);
|
2003-10-28 11:18:40 +00:00
|
|
|
|
w = max(w, labelEnd(pit, row));
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-28 11:18:40 +00:00
|
|
|
|
int const fill = workwidth - w - rightMargin(*pit, *bv()->buffer());
|
2003-10-24 07:59:04 +00:00
|
|
|
|
row.fill(fill);
|
2003-10-28 11:18:40 +00:00
|
|
|
|
row.width(workwidth - fill);
|
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
|
2003-08-14 08:34:13 +00:00
|
|
|
|
int LyXText::labelFill(ParagraphList::iterator pit, Row const & row) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-11-13 13:43:44 +00:00
|
|
|
|
pos_type last = pit->beginOfBody();
|
2003-02-26 17:04:10 +00:00
|
|
|
|
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(last > 0);
|
2003-02-26 17:04:10 +00:00
|
|
|
|
|
2003-10-24 09:45:07 +00:00
|
|
|
|
// -1 because a label ends with a space that is in the label
|
2003-02-26 17:04:10 +00:00
|
|
|
|
--last;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// a separator at this end does not count
|
2003-04-13 12:56:48 +00:00
|
|
|
|
if (pit->isLineSeparator(last))
|
2000-01-13 16:28:54 +00:00
|
|
|
|
--last;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
int w = 0;
|
2003-10-24 09:45:07 +00:00
|
|
|
|
for (pos_type i = row.pos(); i <= last; ++i)
|
2003-04-13 12:56:48 +00:00
|
|
|
|
w += singleWidth(pit, i);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-28 11:18:40 +00:00
|
|
|
|
string const & label = pit->params().labelWidthString();
|
|
|
|
|
if (label.empty())
|
|
|
|
|
return 0;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-28 11:18:40 +00:00
|
|
|
|
return max(0, font_metrics::width(label, getLabelFont(pit)) - w);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-09-18 11:48:11 +00:00
|
|
|
|
LColor_color LyXText::backgroundColor() const
|
2001-07-24 10:13:19 +00:00
|
|
|
|
{
|
|
|
|
|
if (inset_owner)
|
|
|
|
|
return inset_owner->backgroundColor();
|
2003-10-28 11:18:40 +00:00
|
|
|
|
return LColor::background;
|
2001-07-24 10:13:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-03-29 23:11:20 +00:00
|
|
|
|
|
2003-10-17 10:31:47 +00:00
|
|
|
|
void LyXText::setHeightOfRow(ParagraphList::iterator pit, Row & row)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// get the maximum ascent and the maximum descent
|
2003-07-29 01:46:09 +00:00
|
|
|
|
double layoutasc = 0;
|
|
|
|
|
double layoutdesc = 0;
|
2003-10-28 11:18:40 +00:00
|
|
|
|
double const dh = defaultRowHeight();
|
2001-07-31 10:10:17 +00:00
|
|
|
|
|
2003-07-17 15:04:09 +00:00
|
|
|
|
// ok, let us initialize the maxasc and maxdesc value.
|
2003-07-29 01:46:09 +00:00
|
|
|
|
// Only the fontsize count. The other properties
|
|
|
|
|
// are taken from the layoutfont. Nicer on the screen :)
|
2003-04-13 12:56:48 +00:00
|
|
|
|
LyXLayout_ptr const & layout = pit->layout();
|
2001-07-31 10:10:17 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +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
|
2001-07-31 12:57:06 +00:00
|
|
|
|
// do the assignment below too often.
|
2003-10-17 10:31:47 +00:00
|
|
|
|
LyXFont font = getFont(pit, row.pos());
|
2001-07-31 12:57:06 +00:00
|
|
|
|
LyXFont::FONT_SIZE const tmpsize = font.size();
|
2003-07-27 21:59:06 +00:00
|
|
|
|
font = getLayoutFont(pit);
|
2001-07-31 12:57:06 +00:00
|
|
|
|
LyXFont::FONT_SIZE const size = font.size();
|
|
|
|
|
font.setSize(tmpsize);
|
2001-07-31 10:10:17 +00:00
|
|
|
|
|
2003-07-27 21:59:06 +00:00
|
|
|
|
LyXFont labelfont = getLabelFont(pit);
|
2001-07-31 10:10:17 +00:00
|
|
|
|
|
2003-10-24 09:45:07 +00:00
|
|
|
|
// these are minimum values
|
2003-10-28 11:18:40 +00:00
|
|
|
|
double const spacing_val = layout->spacing.getValue() * spacing(*pit);
|
|
|
|
|
//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
|
|
|
|
|
InsetList::iterator ii = pit->insetlist.begin();
|
|
|
|
|
InsetList::iterator iend = pit->insetlist.end();
|
|
|
|
|
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 =
|
2003-10-17 10:31:47 +00:00
|
|
|
|
pit->highestFontInRange(row.pos(), pos_end, size);
|
2001-07-31 10:10:17 +00:00
|
|
|
|
if (maxsize > font.size()) {
|
|
|
|
|
font.setSize(maxsize);
|
2003-10-28 11:18:40 +00:00
|
|
|
|
maxasc = max(maxasc, font_metrics::maxAscent(font));
|
2003-04-13 12:56:48 +00:00
|
|
|
|
maxdesc = max(maxdesc, font_metrics::maxDescent(font));
|
2001-07-31 10:10:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This is nicer with box insets:
|
|
|
|
|
++maxasc;
|
|
|
|
|
++maxdesc;
|
|
|
|
|
|
2003-10-17 10:31:47 +00:00
|
|
|
|
row.ascent_of_text(maxasc);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-31 10:10:17 +00:00
|
|
|
|
// is it a top line?
|
2003-10-28 11:18:40 +00:00
|
|
|
|
if (row.pos() == 0) {
|
2003-09-09 09:47:59 +00:00
|
|
|
|
BufferParams const & bufparams = bv()->buffer()->params();
|
2001-07-31 10:10:17 +00:00
|
|
|
|
// some parksips VERY EASY IMPLEMENTATION
|
2003-10-28 11:18:40 +00:00
|
|
|
|
if (bv()->buffer()->params().paragraph_separation
|
2003-10-29 10:47:21 +00:00
|
|
|
|
== BufferParams::PARSEP_SKIP
|
2003-10-28 11:18:40 +00:00
|
|
|
|
&& pit != ownerParagraphs().begin()
|
|
|
|
|
&& ((layout->isParagraph() && pit->getDepth() == 0)
|
|
|
|
|
|| (boost::prior(pit)->layout()->isParagraph()
|
|
|
|
|
&& boost::prior(pit)->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
|
|
|
|
|
2003-02-14 00:41:44 +00:00
|
|
|
|
// the top margin
|
2003-04-13 12:56:48 +00:00
|
|
|
|
if (pit == ownerParagraphs().begin() && !isInInset())
|
2003-02-07 14:13:51 +00:00
|
|
|
|
maxasc += PAPER_MARGIN;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-28 11:18:40 +00:00
|
|
|
|
// add user added vertical space
|
2003-04-13 12:56:48 +00:00
|
|
|
|
maxasc += getLengthMarkerHeight(*bv(), pit->params().spaceTop());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-13 12:56:48 +00:00
|
|
|
|
if (pit->params().startOfAppendix())
|
2003-10-28 11:18:40 +00:00
|
|
|
|
maxasc += int(3 * dh);
|
2003-03-13 19:55:39 +00:00
|
|
|
|
|
2001-07-31 10:10:17 +00:00
|
|
|
|
// This is special code for the chapter, since the label of this
|
|
|
|
|
// layout is printed in an extra row
|
2003-09-12 17:13:22 +00:00
|
|
|
|
if (layout->counter == "chapter" && bufparams.secnumdepth >= 0) {
|
2003-10-28 11:18:40 +00:00
|
|
|
|
labeladdon = int(font_metrics::maxHeight(labelfont)
|
|
|
|
|
* layout->spacing.getValue() * spacing(*pit));
|
2001-07-31 10:10:17 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-31 10:10:17 +00:00
|
|
|
|
// special code for the top label
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if ((layout->labeltype == LABEL_TOP_ENVIRONMENT
|
|
|
|
|
|| layout->labeltype == LABEL_BIBLIO
|
|
|
|
|
|| layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
|
2003-04-16 08:12:22 +00:00
|
|
|
|
&& isFirstInSequence(pit, ownerParagraphs())
|
2003-04-13 12:56:48 +00:00
|
|
|
|
&& !pit->getLabelstring().empty())
|
2001-07-31 10:10:17 +00:00
|
|
|
|
{
|
|
|
|
|
labeladdon = int(
|
2003-10-28 11:18:40 +00:00
|
|
|
|
font_metrics::maxHeight(labelfont)
|
|
|
|
|
* layout->spacing.getValue()
|
|
|
|
|
* spacing(*pit)
|
|
|
|
|
+ (layout->topsep + layout->labelbottomsep) * dh);
|
2001-07-31 10:10:17 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-16 08:12:22 +00:00
|
|
|
|
// And now the layout spaces, for example before and after
|
|
|
|
|
// a section, or between the items of a itemize or enumerate
|
|
|
|
|
// environment.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-27 12:41:26 +00:00
|
|
|
|
ParagraphList::iterator prev =
|
2003-10-28 11:18:40 +00:00
|
|
|
|
depthHook(pit, ownerParagraphs(), pit->getDepth());
|
|
|
|
|
if (prev != pit
|
|
|
|
|
&& prev->layout() == layout
|
|
|
|
|
&& prev->getDepth() == pit->getDepth()
|
|
|
|
|
&& prev->getLabelWidthString() == pit->getLabelWidthString())
|
2003-10-27 12:41:26 +00:00
|
|
|
|
{
|
2003-10-28 11:18:40 +00:00
|
|
|
|
layoutasc = layout->itemsep * dh;
|
2003-10-27 12:41:26 +00:00
|
|
|
|
} else if (pit != ownerParagraphs().begin() || 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
|
|
|
|
|
2003-10-27 12:41:26 +00:00
|
|
|
|
prev = outerHook(pit, ownerParagraphs());
|
2003-10-28 11:18:40 +00:00
|
|
|
|
if (prev != ownerParagraphs().end()) {
|
|
|
|
|
maxasc += int(prev->layout()->parsep * dh);
|
2003-10-27 12:41:26 +00:00
|
|
|
|
} else if (pit != ownerParagraphs().begin()) {
|
|
|
|
|
ParagraphList::iterator prior_pit = boost::prior(pit);
|
|
|
|
|
if (prior_pit->getDepth() != 0 ||
|
|
|
|
|
prior_pit->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?
|
2003-10-22 16:30:57 +00:00
|
|
|
|
if (row.endpos() >= pit->size()) {
|
2003-02-14 00:41:44 +00:00
|
|
|
|
// the bottom margin
|
2003-04-13 12:56:48 +00:00
|
|
|
|
ParagraphList::iterator nextpit = boost::next(pit);
|
2003-08-15 08:03:54 +00:00
|
|
|
|
if (nextpit == ownerParagraphs().end() && !isInInset())
|
2003-02-07 14:13:51 +00:00
|
|
|
|
maxdesc += PAPER_MARGIN;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-31 10:10:17 +00:00
|
|
|
|
// add the vertical spaces, that the user added
|
2003-04-13 12:56:48 +00:00
|
|
|
|
maxdesc += getLengthMarkerHeight(*bv(), pit->params().spaceBottom());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-31 10:10:17 +00:00
|
|
|
|
// and now the layout spaces, for example before and after
|
|
|
|
|
// a section, or between the items of a itemize or enumerate
|
|
|
|
|
// environment
|
2003-10-27 12:41:26 +00:00
|
|
|
|
if (nextpit != ownerParagraphs().end()) {
|
2003-10-28 11:18:40 +00:00
|
|
|
|
ParagraphList::iterator cpit = pit;
|
|
|
|
|
double usual = 0;
|
|
|
|
|
double unusual = 0;
|
|
|
|
|
|
|
|
|
|
if (cpit->getDepth() > nextpit->getDepth()) {
|
|
|
|
|
usual = cpit->layout()->bottomsep * dh;
|
|
|
|
|
cpit = depthHook(cpit, ownerParagraphs(), nextpit->getDepth());
|
|
|
|
|
if (cpit->layout() != nextpit->layout()
|
|
|
|
|
|| nextpit->getLabelWidthString() != cpit->getLabelWidthString())
|
2001-07-31 10:10:17 +00:00
|
|
|
|
{
|
2003-10-28 11:18:40 +00:00
|
|
|
|
unusual = cpit->layout()->bottomsep * dh;
|
2001-07-31 10:10:17 +00:00
|
|
|
|
}
|
2003-10-28 11:18:40 +00:00
|
|
|
|
layoutdesc = max(unusual, usual);
|
|
|
|
|
} else if (cpit->getDepth() == nextpit->getDepth()) {
|
|
|
|
|
if (cpit->layout() != nextpit->layout()
|
|
|
|
|
|| nextpit->getLabelWidthString() != cpit->getLabelWidthString())
|
|
|
|
|
layoutdesc = int(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
|
2003-10-28 11:18:40 +00:00
|
|
|
|
maxasc += int(layoutasc * 2 / (2 + pit->getDepth()));
|
2003-04-13 12:56:48 +00:00
|
|
|
|
maxdesc += int(layoutdesc * 2 / (2 + pit->getDepth()));
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-17 10:31:47 +00:00
|
|
|
|
row.height(maxasc + maxdesc + labeladdon);
|
|
|
|
|
row.baseline(maxasc + labeladdon);
|
|
|
|
|
row.top_of_text(row.baseline() - font_metrics::maxAscent(font));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
2003-02-08 19:18:01 +00:00
|
|
|
|
// allow only if at start or end, or all previous is new text
|
2003-10-24 09:45:07 +00:00
|
|
|
|
ParagraphList::iterator cpit = cursorPar();
|
|
|
|
|
if (cursor.pos() && cursor.pos() != cpit->size()
|
|
|
|
|
&& cpit->isChangeEdited(0, cursor.pos()))
|
2003-02-08 19:18:01 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2002-03-05 16:13:59 +00:00
|
|
|
|
LyXTextClass const & tclass =
|
2003-09-09 09:47:59 +00:00
|
|
|
|
bv()->buffer()->params().getLyXTextClass();
|
2003-10-24 09:45:07 +00:00
|
|
|
|
LyXLayout_ptr const & layout = cpit->layout();
|
2000-09-23 04:57:18 +00:00
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// this is only allowed, if the current paragraph is not empty or caption
|
2003-06-07 17:45:43 +00:00
|
|
|
|
// and if it has not the keepempty flag active
|
2003-10-24 09:45:07 +00:00
|
|
|
|
if (cpit->empty() && !cpit->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
|
|
|
|
|
2003-10-13 10:59:31 +00:00
|
|
|
|
recUndo(cursor.par());
|
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)
|
2003-10-24 09:45:07 +00:00
|
|
|
|
if (cursor.pos() < cpit->size() && cpit->isLineSeparator(cursor.pos()))
|
|
|
|
|
cpit->erase(cursor.pos());
|
2002-05-29 12:58:23 +00:00
|
|
|
|
|
|
|
|
|
// break the paragraph
|
|
|
|
|
if (keep_layout)
|
|
|
|
|
keep_layout = 2;
|
|
|
|
|
else
|
2002-06-24 20:28:12 +00:00
|
|
|
|
keep_layout = layout->isEnvironment();
|
2002-05-29 12:58:23 +00:00
|
|
|
|
|
|
|
|
|
// we need to set this before we insert the paragraph. IMO the
|
|
|
|
|
// breakParagraph call should return a bool if it inserts the
|
|
|
|
|
// paragraph before or behind and we should react on that one
|
|
|
|
|
// but we can fix this in 1.3.0 (Jug 20020509)
|
2003-10-24 09:45:07 +00:00
|
|
|
|
bool const isempty = cpit->allowEmpty() && cpit->empty();
|
|
|
|
|
::breakParagraph(bv()->buffer()->params(), paragraphs, cpit,
|
2003-07-10 12:26:40 +00:00
|
|
|
|
cursor.pos(), keep_layout);
|
2000-09-23 04:57:18 +00:00
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
|
#warning Trouble Point! (Lgb)
|
|
|
|
|
// When ::breakParagraph is called from within an inset we must
|
|
|
|
|
// ensure that the correct ParagraphList is used. Today that is not
|
|
|
|
|
// the case and the Buffer::paragraphs is used. Not good. (Lgb)
|
2003-10-24 09:45:07 +00:00
|
|
|
|
cpit = cursorPar();
|
|
|
|
|
ParagraphList::iterator next_par = boost::next(cpit);
|
2003-08-15 08:03:54 +00:00
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// well this is the caption hack since one caption is really enough
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (layout->labeltype == LABEL_SENSITIVE) {
|
2002-05-29 12:58:23 +00:00
|
|
|
|
if (!cursor.pos())
|
|
|
|
|
// set to standard-layout
|
2003-10-24 09:45:07 +00:00
|
|
|
|
cpit->applyLayout(tclass.defaultLayout());
|
2002-05-29 12:58:23 +00:00
|
|
|
|
else
|
|
|
|
|
// set to standard-layout
|
2003-08-15 08:03:54 +00:00
|
|
|
|
next_par->applyLayout(tclass.defaultLayout());
|
2002-05-29 12:58:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if the cursor is at the beginning of a row without prior newline,
|
|
|
|
|
// move one row up!
|
|
|
|
|
// This touches only the screen-update. Otherwise we would may have
|
2002-06-24 20:28:12 +00:00
|
|
|
|
// an empty row on the screen
|
2003-10-24 09:45:07 +00:00
|
|
|
|
RowList::iterator crit = cpit->getRow(cursor.pos());
|
|
|
|
|
if (cursor.pos() && crit->pos() == cursor.pos()
|
|
|
|
|
&& !cpit->isNewline(cursor.pos() - 1))
|
2002-05-29 12:58:23 +00:00
|
|
|
|
{
|
2003-03-17 16:25:00 +00:00
|
|
|
|
cursorLeft(bv());
|
2002-05-29 12:58:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-04-13 02:23:30 +00:00
|
|
|
|
while (!next_par->empty() && next_par->isNewline(0))
|
|
|
|
|
next_par->erase(0);
|
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
updateCounters();
|
2003-10-24 09:45:07 +00:00
|
|
|
|
redoParagraph(cpit);
|
2003-08-15 08:03:54 +00:00
|
|
|
|
redoParagraph(next_par);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// This check is necessary. Otherwise the new empty paragraph will
|
|
|
|
|
// be deleted automatically. And it is more friendly for the user!
|
|
|
|
|
if (cursor.pos() || isempty)
|
2003-04-13 02:23:30 +00:00
|
|
|
|
setCursor(next_par, 0);
|
2002-05-29 12:58:23 +00:00
|
|
|
|
else
|
2003-10-24 09:45:07 +00:00
|
|
|
|
setCursor(cpit, 0);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-14 08:34:13 +00:00
|
|
|
|
// convenience function
|
2003-03-18 13:05:08 +00:00
|
|
|
|
void LyXText::redoParagraph()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-08-01 15:42:53 +00:00
|
|
|
|
clearSelection();
|
2003-10-09 10:52:12 +00:00
|
|
|
|
redoParagraph(cursorPar());
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursorIntern(cursor.par(), cursor.pos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// insert a character, moves all the following breaks in the
|
2002-06-24 20:28:12 +00:00
|
|
|
|
// same Paragraph one to the right and make a rebreak
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::insertChar(char c)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-10-14 13:01:49 +00:00
|
|
|
|
recordUndo(Undo::INSERT, this, cursor.par(), cursor.par());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
// When the free-spacing option is set for the current layout,
|
|
|
|
|
// disable the double-space checking
|
2000-03-09 03:36:48 +00:00
|
|
|
|
|
2003-10-09 10:52:12 +00:00
|
|
|
|
bool const freeSpacing = cursorPar()->layout()->free_spacing ||
|
|
|
|
|
cursorPar()->isFreeSpacing();
|
2000-02-29 02:19:17 +00:00
|
|
|
|
|
2000-10-09 12:30:52 +00:00
|
|
|
|
if (lyxrc.auto_number) {
|
2001-01-15 14:05:45 +00:00
|
|
|
|
static string const number_operators = "+-/*";
|
|
|
|
|
static string const number_unary_operators = "+-";
|
|
|
|
|
static string const number_seperators = ".,:";
|
|
|
|
|
|
2000-10-09 12:30:52 +00:00
|
|
|
|
if (current_font.number() == LyXFont::ON) {
|
2001-12-20 15:11:51 +00:00
|
|
|
|
if (!IsDigit(c) && !contains(number_operators, c) &&
|
2001-01-15 14:05:45 +00:00
|
|
|
|
!(contains(number_seperators, c) &&
|
2000-10-09 12:30:52 +00:00
|
|
|
|
cursor.pos() >= 1 &&
|
2003-10-09 10:52:12 +00:00
|
|
|
|
cursor.pos() < cursorPar()->size() &&
|
|
|
|
|
getFont(cursorPar(), cursor.pos()).number() == LyXFont::ON &&
|
|
|
|
|
getFont(cursorPar(), cursor.pos() - 1).number() == LyXFont::ON)
|
2002-02-16 15:59:55 +00:00
|
|
|
|
)
|
2003-11-10 09:06:48 +00:00
|
|
|
|
number(); // Set current_font.number to OFF
|
2001-12-20 15:11:51 +00:00
|
|
|
|
} else if (IsDigit(c) &&
|
2000-10-09 12:30:52 +00:00
|
|
|
|
real_current_font.isVisibleRightToLeft()) {
|
2003-11-10 09:06:48 +00:00
|
|
|
|
number(); // Set current_font.number to ON
|
2000-10-09 12:30:52 +00:00
|
|
|
|
|
|
|
|
|
if (cursor.pos() > 0) {
|
2003-10-09 10:52:12 +00:00
|
|
|
|
char const c = cursorPar()->getChar(cursor.pos() - 1);
|
2001-01-15 14:05:45 +00:00
|
|
|
|
if (contains(number_unary_operators, c) &&
|
2000-10-09 12:30:52 +00:00
|
|
|
|
(cursor.pos() == 1 ||
|
2003-10-09 10:52:12 +00:00
|
|
|
|
cursorPar()->isSeparator(cursor.pos() - 2) ||
|
|
|
|
|
cursorPar()->isNewline(cursor.pos() - 2))
|
2002-02-16 15:59:55 +00:00
|
|
|
|
) {
|
2003-07-27 21:59:06 +00:00
|
|
|
|
setCharFont(
|
2003-10-09 10:52:12 +00:00
|
|
|
|
cursorPar(),
|
2000-10-09 12:30:52 +00:00
|
|
|
|
cursor.pos() - 1,
|
|
|
|
|
current_font);
|
2001-01-15 14:05:45 +00:00
|
|
|
|
} else if (contains(number_seperators, c) &&
|
2000-10-09 12:30:52 +00:00
|
|
|
|
cursor.pos() >= 2 &&
|
2003-07-27 21:59:06 +00:00
|
|
|
|
getFont(
|
2003-10-09 10:52:12 +00:00
|
|
|
|
cursorPar(),
|
2001-08-03 18:28:11 +00:00
|
|
|
|
cursor.pos() - 2).number() == LyXFont::ON) {
|
2003-07-27 21:59:06 +00:00
|
|
|
|
setCharFont(
|
2003-10-09 10:52:12 +00:00
|
|
|
|
cursorPar(),
|
2000-10-09 12:30:52 +00:00
|
|
|
|
cursor.pos() - 1,
|
|
|
|
|
current_font);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// First check, if there will be two blanks together or a blank at
|
|
|
|
|
// the beginning of a paragraph.
|
|
|
|
|
// I decided to handle blanks like normal characters, the main
|
|
|
|
|
// difference are the special checks when calculating the row.fill
|
|
|
|
|
// (blank does not count at the end of a row) and the check here
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// The bug is triggered when we type in a description environment:
|
|
|
|
|
// The current_font is not changed when we go from label to main text
|
|
|
|
|
// and it should (along with realtmpfont) when we type the space.
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// CHECK There is a bug here! (Asger)
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// store the current font. This is because of the use of cursor
|
2002-06-24 20:28:12 +00:00
|
|
|
|
// movements. The moving cursor would refresh the current font
|
2003-08-11 09:09:01 +00:00
|
|
|
|
LyXFont realtmpfont = real_current_font;
|
|
|
|
|
LyXFont rawtmpfont = current_font;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-03-09 03:36:48 +00:00
|
|
|
|
if (!freeSpacing && IsLineSeparatorChar(c)) {
|
2002-03-21 17:27:08 +00:00
|
|
|
|
if ((cursor.pos() > 0
|
2003-10-09 10:52:12 +00:00
|
|
|
|
&& cursorPar()->isLineSeparator(cursor.pos() - 1))
|
2000-06-08 23:16:16 +00:00
|
|
|
|
|| (cursor.pos() > 0
|
2003-10-09 10:52:12 +00:00
|
|
|
|
&& cursorPar()->isNewline(cursor.pos() - 1))
|
2001-05-03 14:31:33 +00:00
|
|
|
|
|| (cursor.pos() == 0)) {
|
2001-05-09 15:20:58 +00:00
|
|
|
|
static bool sent_space_message = false;
|
|
|
|
|
if (!sent_space_message) {
|
2002-03-21 17:27:08 +00:00
|
|
|
|
if (cursor.pos() == 0)
|
2003-03-17 16:25:00 +00:00
|
|
|
|
bv()->owner()->message(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
|
2001-05-09 15:20:58 +00:00
|
|
|
|
else
|
2003-03-17 16:25:00 +00:00
|
|
|
|
bv()->owner()->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
|
|
|
|
charInserted();
|
|
|
|
|
return;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-03-13 10:30:28 +00:00
|
|
|
|
|
2003-08-08 15:48:57 +00:00
|
|
|
|
// Here case LyXText::InsertInset already inserted the character
|
|
|
|
|
if (c != Paragraph::META_INSET)
|
2003-10-09 10:52:12 +00:00
|
|
|
|
cursorPar()->insertChar(cursor.pos(), c);
|
2003-08-08 15:48:57 +00:00
|
|
|
|
|
2003-10-09 10:52:12 +00:00
|
|
|
|
setCharFont(cursorPar(), cursor.pos(), rawtmpfont);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-08-08 15:34:17 +00:00
|
|
|
|
current_font = rawtmpfont;
|
|
|
|
|
real_current_font = realtmpfont;
|
2003-10-09 10:52:12 +00:00
|
|
|
|
redoParagraph(cursorPar());
|
2003-08-08 15:34:17 +00:00
|
|
|
|
setCursor(cursor.par(), cursor.pos() + 1, false, cursor.boundary());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
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
|
|
|
|
|
2003-10-22 09:56:22 +00:00
|
|
|
|
void LyXText::prepareToPrint(ParagraphList::iterator pit, Row & row) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-10-22 09:56:22 +00:00
|
|
|
|
double w = row.fill();
|
2003-08-22 09:40:56 +00:00
|
|
|
|
double fill_hfill = 0;
|
|
|
|
|
double fill_label_hfill = 0;
|
|
|
|
|
double fill_separator = 0;
|
|
|
|
|
double x = 0;
|
2000-02-03 19:51:27 +00:00
|
|
|
|
|
2002-01-07 16:15:11 +00:00
|
|
|
|
bool const is_rtl =
|
2003-09-09 09:47:59 +00:00
|
|
|
|
pit->isRightToLeftPar(bv()->buffer()->params());
|
2003-07-18 07:47:07 +00:00
|
|
|
|
if (is_rtl)
|
2003-10-28 11:18:40 +00:00
|
|
|
|
x = workWidth() > 0 ? rightMargin(*pit, *bv()->buffer()) : 0;
|
2003-07-18 07:47:07 +00:00
|
|
|
|
else
|
2003-10-22 09:56:22 +00:00
|
|
|
|
x = workWidth() > 0 ? leftMargin(pit, row) : 0;
|
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
|
2003-04-13 12:56:48 +00:00
|
|
|
|
LyXLayout_ptr const & layout = pit->layout();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (layout->margintype == MARGIN_MANUAL
|
|
|
|
|
&& layout->labeltype == LABEL_MANUAL) {
|
2003-03-08 19:31:09 +00:00
|
|
|
|
/// We might have real hfills in the label part
|
2003-10-22 09:56:22 +00:00
|
|
|
|
int nlh = numberOfLabelHfills(*pit, row);
|
2003-03-08 19:31:09 +00:00
|
|
|
|
|
|
|
|
|
// A manual label par (e.g. List) has an auto-hfill
|
2003-03-09 12:37:22 +00:00
|
|
|
|
// between the label text and the body of the
|
2003-03-08 19:31:09 +00:00
|
|
|
|
// paragraph too.
|
|
|
|
|
// But we don't want to do this auto hfill if the par
|
|
|
|
|
// is empty.
|
2003-04-13 12:56:48 +00:00
|
|
|
|
if (!pit->empty())
|
2003-03-08 19:31:09 +00:00
|
|
|
|
++nlh;
|
2003-03-13 10:30:28 +00:00
|
|
|
|
|
2003-10-27 11:44:10 +00:00
|
|
|
|
if (nlh && !pit->getLabelWidthString().empty())
|
2003-10-22 09:56:22 +00:00
|
|
|
|
fill_label_hfill = labelFill(pit, row) / double(nlh);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
// are there any hfills in the row?
|
2003-10-22 09:56:22 +00:00
|
|
|
|
int const nh = numberOfHfills(*pit, row);
|
2000-09-23 04:57:18 +00:00
|
|
|
|
|
2001-08-10 14:00:48 +00:00
|
|
|
|
if (nh) {
|
|
|
|
|
if (w > 0)
|
|
|
|
|
fill_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!
|
2003-10-22 09:56:22 +00:00
|
|
|
|
} else if (int(row.width()) < workWidth()) {
|
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;
|
2003-10-29 12:18:08 +00:00
|
|
|
|
if (pit->params().align() == LYX_ALIGN_LAYOUT)
|
2002-06-24 20:28:12 +00:00
|
|
|
|
align = layout->align;
|
2003-10-29 12:18:08 +00:00
|
|
|
|
else
|
2003-04-13 12:56:48 +00:00
|
|
|
|
align = pit->params().align();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-20 18:56:48 +00:00
|
|
|
|
// Display-style insets should always be on a centred row
|
2003-10-21 13:04:14 +00:00
|
|
|
|
// The test on pit->size() is to catch zero-size pars, which
|
|
|
|
|
// would trigger the assert in Paragraph::getInset().
|
2003-10-22 09:56:22 +00:00
|
|
|
|
//inset = pit->size() ? pit->getInset(row.pos()) : 0;
|
2003-10-24 15:04:17 +00:00
|
|
|
|
if (!pit->empty()
|
|
|
|
|
&& pit->isInset(row.pos())
|
|
|
|
|
&& pit->getInset(row.pos())->display())
|
|
|
|
|
{
|
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) {
|
2003-10-28 11:18:40 +00:00
|
|
|
|
case LYX_ALIGN_BLOCK: {
|
|
|
|
|
int const ns = numberOfSeparators(*pit, row);
|
|
|
|
|
bool disp_inset = false;
|
|
|
|
|
if (row.endpos() < pit->size()) {
|
|
|
|
|
InsetOld * in = pit->getInset(row.endpos());
|
|
|
|
|
if (in)
|
|
|
|
|
disp_inset = in->display();
|
|
|
|
|
}
|
|
|
|
|
// 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
|
|
|
|
|
&& row.endpos() < pit->size()
|
|
|
|
|
&& !pit->isNewline(row.endpos() - 1)
|
|
|
|
|
&& !disp_inset
|
|
|
|
|
) {
|
|
|
|
|
fill_separator = w / ns;
|
|
|
|
|
} else if (is_rtl) {
|
|
|
|
|
x += w;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2001-08-10 14:00:48 +00:00
|
|
|
|
}
|
2003-10-28 11:18:40 +00:00
|
|
|
|
case LYX_ALIGN_RIGHT:
|
2001-08-10 14:00:48 +00:00
|
|
|
|
x += w;
|
|
|
|
|
break;
|
2003-10-28 11:18:40 +00:00
|
|
|
|
case LYX_ALIGN_CENTER:
|
2001-08-10 14:00:48 +00:00
|
|
|
|
x += w / 2;
|
|
|
|
|
break;
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-10-23 13:28:49 +00:00
|
|
|
|
bidi.computeTables(*pit, *bv()->buffer(), row);
|
2000-04-10 21:40:13 +00:00
|
|
|
|
if (is_rtl) {
|
2003-11-13 13:43:44 +00:00
|
|
|
|
pos_type body_pos = pit->beginOfBody();
|
2003-10-27 11:44:10 +00:00
|
|
|
|
pos_type end = row.endpos();
|
2000-02-03 19:51:27 +00:00
|
|
|
|
|
2003-10-28 11:18:40 +00:00
|
|
|
|
if (body_pos > 0
|
|
|
|
|
&& (body_pos > end || !pit->isLineSeparator(body_pos - 1)))
|
|
|
|
|
{
|
2003-07-27 21:59:06 +00:00
|
|
|
|
x += font_metrics::width(layout->labelsep, getLabelFont(pit));
|
2003-10-27 11:44:10 +00:00
|
|
|
|
if (body_pos <= end)
|
2000-02-03 19:51:27 +00:00
|
|
|
|
x += fill_label_hfill;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-08-22 09:40:56 +00:00
|
|
|
|
|
2003-10-22 09:56:22 +00:00
|
|
|
|
row.fill_hfill(fill_hfill);
|
|
|
|
|
row.fill_label_hfill(fill_label_hfill);
|
|
|
|
|
row.fill_separator(fill_separator);
|
|
|
|
|
row.x(x);
|
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
|
|
|
|
|
2003-03-18 13:05:08 +00:00
|
|
|
|
void LyXText::cursorRightOneWord()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-11-11 10:08:35 +00:00
|
|
|
|
cursorRightOneWord(cursor);
|
2003-10-09 10:52:12 +00:00
|
|
|
|
setCursor(cursorPar(), cursor.pos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// Skip initial whitespace at end of word and move cursor to *start*
|
2002-06-24 20:28:12 +00:00
|
|
|
|
// of prior word, not to end of next prior word.
|
2003-03-18 13:05:08 +00:00
|
|
|
|
void LyXText::cursorLeftOneWord()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
LyXCursor tmpcursor = cursor;
|
2003-11-11 10:08:35 +00:00
|
|
|
|
cursorLeftOneWord(tmpcursor);
|
2003-10-09 10:52:12 +00:00
|
|
|
|
setCursor(getPar(tmpcursor), tmpcursor.pos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::selectWord(word_location loc)
|
2001-06-27 14:10:35 +00:00
|
|
|
|
{
|
2003-07-01 11:51:20 +00:00
|
|
|
|
LyXCursor from = cursor;
|
2003-10-10 11:27:05 +00:00
|
|
|
|
LyXCursor to = cursor;
|
2003-11-11 10:08:35 +00:00
|
|
|
|
getWord(from, to, loc);
|
2001-06-27 14:10:35 +00:00
|
|
|
|
if (cursor != from)
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(from.par(), from.pos());
|
2001-07-27 16:07:33 +00:00
|
|
|
|
if (to == from)
|
|
|
|
|
return;
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.cursor = cursor;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(to.par(), to.pos());
|
|
|
|
|
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
|
2003-03-17 16:25:00 +00:00
|
|
|
|
bool LyXText::selectWordWhenUnderCursor(word_location loc)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-07-27 16:07:33 +00:00
|
|
|
|
if (!selection.set()) {
|
2003-03-17 16:25:00 +00:00
|
|
|
|
selectWord(loc);
|
2001-07-27 16:07:33 +00:00
|
|
|
|
return selection.set();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-04-24 20:58:23 +00:00
|
|
|
|
return false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::acceptChange()
|
2003-02-08 19:18:01 +00:00
|
|
|
|
{
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (!selection.set() && cursorPar()->size())
|
2003-02-08 19:18:01 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (selection.start.par() == selection.end.par()) {
|
|
|
|
|
LyXCursor & startc = selection.start;
|
|
|
|
|
LyXCursor & endc = selection.end;
|
2003-10-14 13:01:49 +00:00
|
|
|
|
recordUndo(Undo::INSERT, this, startc.par());
|
2003-10-09 10:52:12 +00:00
|
|
|
|
getPar(startc)->acceptChange(startc.pos(), endc.pos());
|
2003-02-08 19:18:01 +00:00
|
|
|
|
finishUndo();
|
|
|
|
|
clearSelection();
|
2003-10-09 10:52:12 +00:00
|
|
|
|
redoParagraph(getPar(startc));
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursorIntern(startc.par(), 0);
|
2003-02-08 19:18:01 +00:00
|
|
|
|
}
|
|
|
|
|
#warning handle multi par selection
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::rejectChange()
|
2003-02-08 19:18:01 +00:00
|
|
|
|
{
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (!selection.set() && cursorPar()->size())
|
2003-02-08 19:18:01 +00:00
|
|
|
|
return;
|
2003-03-03 23:19:01 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
if (selection.start.par() == selection.end.par()) {
|
|
|
|
|
LyXCursor & startc = selection.start;
|
|
|
|
|
LyXCursor & endc = selection.end;
|
2003-10-14 13:01:49 +00:00
|
|
|
|
recordUndo(Undo::INSERT, this, startc.par());
|
2003-10-09 10:52:12 +00:00
|
|
|
|
getPar(startc)->rejectChange(startc.pos(), endc.pos());
|
2003-02-08 19:18:01 +00:00
|
|
|
|
finishUndo();
|
|
|
|
|
clearSelection();
|
2003-10-09 10:52:12 +00:00
|
|
|
|
redoParagraph(getPar(startc));
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursorIntern(startc.par(), 0);
|
2003-02-08 19:18:01 +00:00
|
|
|
|
}
|
|
|
|
|
#warning handle multi par selection
|
|
|
|
|
}
|
|
|
|
|
|
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.
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::deleteWordForward()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (cursorPar()->empty())
|
2003-03-17 16:25:00 +00:00
|
|
|
|
cursorRight(bv());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else {
|
2000-05-30 15:41:16 +00:00
|
|
|
|
LyXCursor tmpcursor = cursor;
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.set(true); // to avoid deletion
|
2003-03-17 16:25:00 +00:00
|
|
|
|
cursorRightOneWord();
|
|
|
|
|
setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.cursor = cursor;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
cursor = tmpcursor;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setSelection();
|
|
|
|
|
cutSelection(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.
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::deleteWordBackward()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (cursorPar()->empty())
|
2003-03-17 16:25:00 +00:00
|
|
|
|
cursorLeft(bv());
|
2002-05-29 12:58:23 +00:00
|
|
|
|
else {
|
|
|
|
|
LyXCursor tmpcursor = cursor;
|
|
|
|
|
selection.set(true); // to avoid deletion
|
2003-03-17 16:25:00 +00:00
|
|
|
|
cursorLeftOneWord();
|
|
|
|
|
setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
|
2002-05-29 12:58:23 +00:00
|
|
|
|
selection.cursor = cursor;
|
|
|
|
|
cursor = tmpcursor;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setSelection();
|
|
|
|
|
cutSelection(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.
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::deleteLineForward()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-10-27 11:44:10 +00:00
|
|
|
|
if (cursorPar()->empty()) {
|
2000-05-26 16:13:01 +00:00
|
|
|
|
// Paragraph is empty, so we just go to the right
|
2003-03-17 16:25:00 +00:00
|
|
|
|
cursorRight(bv());
|
2003-10-27 11:44:10 +00:00
|
|
|
|
} else {
|
2000-05-26 16:13:01 +00:00
|
|
|
|
LyXCursor tmpcursor = cursor;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// We can't store the row over a regular setCursor
|
2000-06-08 23:16:16 +00:00
|
|
|
|
// so we set it to 0 and reset it afterwards.
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.set(true); // to avoid deletion
|
2003-03-17 16:25:00 +00:00
|
|
|
|
cursorEnd();
|
|
|
|
|
setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.cursor = cursor;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
cursor = tmpcursor;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setSelection();
|
2000-05-30 15:41:16 +00:00
|
|
|
|
// What is this test for ??? (JMarc)
|
2003-10-27 11:44:10 +00:00
|
|
|
|
if (!selection.set())
|
2003-03-17 16:25:00 +00:00
|
|
|
|
deleteWordForward();
|
2003-10-27 11:44:10 +00:00
|
|
|
|
else
|
2003-03-17 16:25:00 +00:00
|
|
|
|
cutSelection(true, false);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::changeCase(LyXText::TextCase action)
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
2001-06-27 14:10:35 +00:00
|
|
|
|
LyXCursor from;
|
|
|
|
|
LyXCursor to;
|
2001-03-09 00:56:42 +00:00
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
if (selection.set()) {
|
2001-06-27 18:29:18 +00:00
|
|
|
|
from = selection.start;
|
|
|
|
|
to = selection.end;
|
2001-06-27 14:10:35 +00:00
|
|
|
|
} else {
|
2003-07-01 11:51:20 +00:00
|
|
|
|
from = cursor;
|
2003-11-11 10:08:35 +00:00
|
|
|
|
getWord(from, to, lyx::PARTIAL_WORD);
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(to.par(), to.pos() + 1);
|
2001-06-27 14:10:35 +00:00
|
|
|
|
}
|
2001-03-09 00:56:42 +00:00
|
|
|
|
|
2003-10-14 13:01:49 +00:00
|
|
|
|
recordUndo(Undo::ATOMIC, this, from.par(), to.par());
|
2001-06-27 15:33:55 +00:00
|
|
|
|
|
2001-11-26 16:42:04 +00:00
|
|
|
|
pos_type pos = from.pos();
|
2003-10-09 10:52:12 +00:00
|
|
|
|
int par = from.par();
|
2001-06-27 18:29:18 +00:00
|
|
|
|
|
2003-10-09 10:52:12 +00:00
|
|
|
|
while (par != int(ownerParagraphs().size()) &&
|
|
|
|
|
(pos != to.pos() || par != to.par())) {
|
|
|
|
|
ParagraphList::iterator pit = getPar(par);
|
2003-04-09 09:15:20 +00:00
|
|
|
|
if (pos == pit->size()) {
|
2003-10-09 10:52:12 +00:00
|
|
|
|
++par;
|
2002-07-01 21:50:54 +00:00
|
|
|
|
pos = 0;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2003-04-09 09:15:20 +00:00
|
|
|
|
unsigned char c = 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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-02-08 19:18:01 +00:00
|
|
|
|
#warning changes
|
2003-04-09 09:15:20 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::Delete()
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
|
|
|
|
// this is a very easy implementation
|
|
|
|
|
LyXCursor old_cursor = cursor;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
|
// just move to the right
|
2003-03-17 16:25:00 +00:00
|
|
|
|
cursorRight(bv());
|
2000-02-10 17:53:36 +00:00
|
|
|
|
|
|
|
|
|
// if you had success make a backspace
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
|
2003-10-14 13:01:49 +00:00
|
|
|
|
recordUndo(Undo::DELETE, this, old_cursor.par());
|
2003-03-17 16:25:00 +00:00
|
|
|
|
backspace();
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::backspace()
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
|
|
|
|
// Get the font that is used to calculate the baselineskip
|
2003-10-09 10:52:12 +00:00
|
|
|
|
ParagraphList::iterator pit = cursorPar();
|
|
|
|
|
pos_type lastpos = pit->size();
|
2000-02-10 17:53:36 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (cursor.pos() == 0) {
|
2000-09-23 04:57:18 +00:00
|
|
|
|
// The cursor is at the beginning of a paragraph,
|
|
|
|
|
// so the the backspace will collapse two paragraphs into one.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
// but it's not allowed unless it's new
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (pit->isChangeEdited(0, pit->size()))
|
2003-02-08 19:18:01 +00:00
|
|
|
|
return;
|
2003-03-03 23:19:01 +00:00
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
|
// we may paste some paragraphs
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
|
// is it an empty paragraph?
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (lastpos == 0 || (lastpos == 1 && pit->isSeparator(0))) {
|
2003-08-08 15:48:57 +00:00
|
|
|
|
// This is an empty paragraph and we delete it just
|
|
|
|
|
// by moving the cursor one step
|
|
|
|
|
// left and let the DeleteEmptyParagraphMechanism
|
2003-08-11 09:09:01 +00:00
|
|
|
|
// handle the actual deletion of the paragraph.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (cursor.par()) {
|
|
|
|
|
ParagraphList::iterator tmppit = getPar(cursor.par() - 1);
|
|
|
|
|
if (cursorPar()->layout() == tmppit->layout()
|
|
|
|
|
&& cursorPar()->getAlign() == tmppit->getAlign()) {
|
2001-03-06 14:07:14 +00:00
|
|
|
|
// Inherit bottom DTD from the paragraph below.
|
2000-03-16 06:08:30 +00:00
|
|
|
|
// (the one we are deleting)
|
2003-10-09 10:52:12 +00:00
|
|
|
|
tmppit->params().spaceBottom(cursorPar()->params().spaceBottom());
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
cursorLeft(bv());
|
2003-08-22 12:00:58 +00:00
|
|
|
|
|
|
|
|
|
// the layout things can change the height of a row !
|
2003-08-22 12:38:21 +00:00
|
|
|
|
redoParagraph();
|
2000-02-10 17:53:36 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-07-24 21:49:58 +00:00
|
|
|
|
|
2003-10-13 10:59:31 +00:00
|
|
|
|
if (cursor.par() != 0)
|
2003-10-14 13:01:49 +00:00
|
|
|
|
recordUndo(Undo::DELETE, this, cursor.par() - 1, cursor.par());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-09 10:52:12 +00:00
|
|
|
|
ParagraphList::iterator tmppit = cursorPar();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// We used to do cursorLeftIntern() here, but it is
|
2000-03-28 02:18:52 +00:00
|
|
|
|
// not a good idea since it triggers the auto-delete
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// mechanism. So we do a cursorLeftIntern()-lite,
|
2000-03-28 02:18:52 +00:00
|
|
|
|
// without the dreaded mechanism. (JMarc)
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (cursor.par() != 0) {
|
2000-03-28 02:18:52 +00:00
|
|
|
|
// steps into the above paragraph.
|
2003-10-09 10:52:12 +00:00
|
|
|
|
setCursorIntern(cursor.par() - 1,
|
|
|
|
|
getPar(cursor.par() - 1)->size(),
|
2002-03-21 17:27:08 +00:00
|
|
|
|
false);
|
2000-03-28 02:18:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// Pasting is not allowed, if the paragraphs have different
|
|
|
|
|
// layout. I think it is a real bug of all other
|
|
|
|
|
// word processors to allow it. It confuses the user.
|
2003-08-27 15:38:23 +00:00
|
|
|
|
// Correction: Pasting is always allowed with standard-layout
|
2003-09-09 09:47:59 +00:00
|
|
|
|
Buffer & buf = *bv()->buffer();
|
|
|
|
|
BufferParams const & bufparams = buf.params();
|
|
|
|
|
LyXTextClass const & tclass = bufparams.getLyXTextClass();
|
2003-10-28 11:18:40 +00:00
|
|
|
|
ParagraphList::iterator const cpit = cursorPar();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-28 11:18:40 +00:00
|
|
|
|
if (cpit != tmppit
|
|
|
|
|
&& (cpit->layout() == tmppit->layout()
|
|
|
|
|
|| tmppit->layout() == tclass.defaultLayout())
|
|
|
|
|
&& cpit->getAlign() == tmppit->getAlign()) {
|
|
|
|
|
mergeParagraph(bufparams, buf.paragraphs(), cpit);
|
2003-08-11 09:09:01 +00:00
|
|
|
|
|
2003-10-28 11:18:40 +00:00
|
|
|
|
if (cursor.pos() && cpit->isSeparator(cursor.pos() - 1))
|
2003-08-11 09:09:01 +00:00
|
|
|
|
cursor.pos(cursor.pos() - 1);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-28 11:18:40 +00:00
|
|
|
|
// the counters may have changed
|
2003-08-11 09:09:01 +00:00
|
|
|
|
updateCounters();
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(cursor.par(), cursor.pos(), false);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// this is the code for a normal backspace, not pasting
|
2002-06-24 20:28:12 +00:00
|
|
|
|
// any paragraphs
|
2003-10-14 13:01:49 +00:00
|
|
|
|
recordUndo(Undo::DELETE, this, cursor.par());
|
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)
|
2003-08-08 15:48:57 +00:00
|
|
|
|
setCursorIntern(cursor.par(), cursor.pos() - 1,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
false, cursor.boundary());
|
2003-10-09 10:52:12 +00:00
|
|
|
|
cursorPar()->erase(cursor.pos());
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
2000-05-30 19:31:11 +00:00
|
|
|
|
|
2003-10-09 10:52:12 +00:00
|
|
|
|
lastpos = cursorPar()->size();
|
2000-12-05 14:15:44 +00:00
|
|
|
|
if (cursor.pos() == lastpos)
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCurrentFont();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-08-08 15:34:17 +00:00
|
|
|
|
redoParagraph();
|
2003-10-27 20:23:26 +00:00
|
|
|
|
setCursor(cursor.par(), cursor.pos(), false, cursor.boundary());
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-09 10:52:12 +00:00
|
|
|
|
ParagraphList::iterator LyXText::cursorPar() const
|
|
|
|
|
{
|
2003-11-04 07:33:50 +00:00
|
|
|
|
return getPar(cursor.par());
|
|
|
|
|
#warning have a look at this again later.
|
|
|
|
|
// We need some method to mark the cache as invalidated when
|
|
|
|
|
// the paragraph it points get removed, for this to work.
|
2003-10-27 12:41:26 +00:00
|
|
|
|
if (cursor.par() != cache_pos_) {
|
|
|
|
|
cache_pos_ = cursor.par();
|
|
|
|
|
cache_par_ = getPar(cache_pos_);
|
|
|
|
|
}
|
|
|
|
|
return cache_par_;
|
2003-10-09 10:52:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-24 09:45:07 +00:00
|
|
|
|
RowList::iterator LyXText::cursorRow() const
|
|
|
|
|
{
|
|
|
|
|
return cursorPar()->getRow(cursor.pos());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-09 10:52:12 +00:00
|
|
|
|
ParagraphList::iterator LyXText::getPar(LyXCursor const & cur) const
|
|
|
|
|
{
|
|
|
|
|
return getPar(cur.par());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ParagraphList::iterator LyXText::getPar(int par) const
|
|
|
|
|
{
|
2003-10-10 09:01:23 +00:00
|
|
|
|
BOOST_ASSERT(par >= 0);
|
2003-10-13 10:59:31 +00:00
|
|
|
|
BOOST_ASSERT(par < int(ownerParagraphs().size()));
|
2003-10-09 10:52:12 +00:00
|
|
|
|
ParagraphList::iterator pit = ownerParagraphs().begin();
|
|
|
|
|
std::advance(pit, par);
|
|
|
|
|
return pit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-17 10:31:47 +00:00
|
|
|
|
RowList::iterator
|
|
|
|
|
LyXText::getRowNearY(int y, ParagraphList::iterator & pit) const
|
2001-11-26 16:42:04 +00:00
|
|
|
|
{
|
2003-08-15 08:03:54 +00:00
|
|
|
|
//lyxerr << "getRowNearY: y " << y << endl;
|
2003-11-13 08:50:26 +00:00
|
|
|
|
#if 1
|
|
|
|
|
ParagraphList::iterator const
|
|
|
|
|
pend = boost::prior(ownerParagraphs().end());
|
2003-10-28 11:18:40 +00:00
|
|
|
|
pit = ownerParagraphs().begin();
|
|
|
|
|
while (int(pit->y + pit->height) < y && pit != pend)
|
|
|
|
|
++pit;
|
2003-08-15 08:03:54 +00:00
|
|
|
|
|
2003-11-13 08:50:26 +00:00
|
|
|
|
RowList::iterator rit = pit->rows.end();
|
|
|
|
|
RowList::iterator const rbegin = pit->rows.begin();
|
|
|
|
|
do {
|
|
|
|
|
--rit;
|
|
|
|
|
} while (rit != rbegin && int(pit->y + rit->y_offset()) > y);
|
2003-11-22 14:44:59 +00:00
|
|
|
|
|
2003-10-28 11:18:40 +00:00
|
|
|
|
return rit;
|
|
|
|
|
#else
|
2003-08-25 10:24:26 +00:00
|
|
|
|
pit = boost::prior(ownerParagraphs().end());
|
|
|
|
|
|
|
|
|
|
RowList::iterator rit = lastRow();
|
|
|
|
|
RowList::iterator rbegin = firstRow();
|
|
|
|
|
|
2003-10-17 10:31:47 +00:00
|
|
|
|
while (rit != rbegin && int(pit->y + rit->y_offset()) > y)
|
2003-08-25 10:24:26 +00:00
|
|
|
|
previousRow(pit, rit);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-08-18 08:35:25 +00:00
|
|
|
|
return rit;
|
2003-10-28 11:18:40 +00:00
|
|
|
|
#endif
|
2001-11-26 16:42:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int LyXText::getDepth() const
|
|
|
|
|
{
|
2003-10-09 10:52:12 +00:00
|
|
|
|
return cursorPar()->getDepth();
|
2001-11-26 16:42:04 +00:00
|
|
|
|
}
|
2003-08-14 08:34:13 +00:00
|
|
|
|
|
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
|
RowList::iterator LyXText::firstRow() const
|
2003-08-14 08:34:13 +00:00
|
|
|
|
{
|
2003-08-15 08:03:54 +00:00
|
|
|
|
return ownerParagraphs().front().rows.begin();
|
2003-08-14 08:34:13 +00:00
|
|
|
|
}
|
2003-08-14 11:16:31 +00:00
|
|
|
|
|
|
|
|
|
|
2003-11-22 14:44:59 +00:00
|
|
|
|
ParagraphList::iterator LyXText::firstPar() const
|
|
|
|
|
{
|
|
|
|
|
return ownerParagraphs().begin();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
|
RowList::iterator LyXText::lastRow() const
|
2003-08-14 11:16:31 +00:00
|
|
|
|
{
|
2003-08-15 08:03:54 +00:00
|
|
|
|
return boost::prior(endRow());
|
2003-08-14 11:16:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-22 14:44:59 +00:00
|
|
|
|
ParagraphList::iterator LyXText::lastPar() const
|
|
|
|
|
{
|
|
|
|
|
return boost::prior(endPar());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
|
RowList::iterator LyXText::endRow() const
|
2003-08-14 11:16:31 +00:00
|
|
|
|
{
|
2003-08-15 08:03:54 +00:00
|
|
|
|
return ownerParagraphs().back().rows.end();
|
2003-08-14 11:16:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-22 14:44:59 +00:00
|
|
|
|
ParagraphList::iterator LyXText::endPar() const
|
|
|
|
|
{
|
|
|
|
|
return ownerParagraphs().end();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
|
void LyXText::nextRow(ParagraphList::iterator & pit,
|
|
|
|
|
RowList::iterator & rit) const
|
2003-08-14 14:10:13 +00:00
|
|
|
|
{
|
2003-08-18 08:35:25 +00:00
|
|
|
|
++rit;
|
|
|
|
|
if (rit == pit->rows.end()) {
|
2003-08-15 08:03:54 +00:00
|
|
|
|
++pit;
|
|
|
|
|
if (pit == ownerParagraphs().end())
|
2003-08-18 08:35:25 +00:00
|
|
|
|
--pit;
|
2003-08-15 08:03:54 +00:00
|
|
|
|
else
|
|
|
|
|
rit = pit->rows.begin();
|
|
|
|
|
}
|
2003-08-14 14:10:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
|
void LyXText::previousRow(ParagraphList::iterator & pit,
|
|
|
|
|
RowList::iterator & rit) const
|
2003-08-14 11:16:31 +00:00
|
|
|
|
{
|
2003-08-15 08:03:54 +00:00
|
|
|
|
if (rit != pit->rows.begin())
|
2003-08-18 08:35:25 +00:00
|
|
|
|
--rit;
|
2003-08-15 08:03:54 +00:00
|
|
|
|
else {
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(pit != ownerParagraphs().begin());
|
2003-08-15 08:03:54 +00:00
|
|
|
|
--pit;
|
|
|
|
|
rit = boost::prior(pit->rows.end());
|
|
|
|
|
}
|
2003-08-14 11:16:31 +00:00
|
|
|
|
}
|
2003-10-09 10:52:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string LyXText::selectionAsString(Buffer const & buffer, bool label) const
|
|
|
|
|
{
|
|
|
|
|
if (!selection.set())
|
|
|
|
|
return string();
|
|
|
|
|
|
|
|
|
|
// should be const ...
|
|
|
|
|
ParagraphList::iterator startpit = getPar(selection.start);
|
|
|
|
|
ParagraphList::iterator endpit = getPar(selection.end);
|
|
|
|
|
size_t const startpos = selection.start.pos();
|
|
|
|
|
size_t const endpos = selection.end.pos();
|
|
|
|
|
|
|
|
|
|
if (startpit == endpit)
|
|
|
|
|
return startpit->asString(buffer, startpos, endpos, label);
|
|
|
|
|
|
|
|
|
|
// First paragraph in selection
|
|
|
|
|
string result =
|
|
|
|
|
startpit->asString(buffer, startpos, startpit->size(), label) + "\n\n";
|
|
|
|
|
|
|
|
|
|
// The paragraphs in between (if any)
|
|
|
|
|
ParagraphList::iterator pit = startpit;
|
|
|
|
|
for (++pit; pit != endpit; ++pit)
|
|
|
|
|
result += pit->asString(buffer, 0, pit->size(), label) + "\n\n";
|
|
|
|
|
|
|
|
|
|
// Last paragraph in selection
|
|
|
|
|
result += endpit->asString(buffer, 0, endpos, label);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int LyXText::parOffset(ParagraphList::iterator pit) const
|
|
|
|
|
{
|
|
|
|
|
return std::distance(ownerParagraphs().begin(), pit);
|
|
|
|
|
}
|
2003-10-17 10:31:47 +00:00
|
|
|
|
|
|
|
|
|
|
2003-10-23 08:15:57 +00:00
|
|
|
|
void LyXText::redoParagraphInternal(ParagraphList::iterator pit)
|
2003-10-17 10:31:47 +00:00
|
|
|
|
{
|
|
|
|
|
// remove rows of paragraph, keep track of height changes
|
|
|
|
|
height -= pit->height;
|
2003-10-23 08:15:57 +00:00
|
|
|
|
|
|
|
|
|
// clear old data
|
2003-10-17 10:31:47 +00:00
|
|
|
|
pit->rows.clear();
|
2003-10-23 08:15:57 +00:00
|
|
|
|
pit->height = 0;
|
|
|
|
|
pit->width = 0;
|
2003-10-17 10:31:47 +00:00
|
|
|
|
|
|
|
|
|
// redo insets
|
|
|
|
|
InsetList::iterator ii = pit->insetlist.begin();
|
|
|
|
|
InsetList::iterator iend = pit->insetlist.end();
|
|
|
|
|
for (; ii != iend; ++ii) {
|
|
|
|
|
Dimension dim;
|
|
|
|
|
MetricsInfo mi(bv(), getFont(pit, ii->pos), workWidth());
|
|
|
|
|
ii->inset->metrics(mi, dim);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// rebreak the paragraph
|
2003-11-13 13:43:44 +00:00
|
|
|
|
pit->setBeginOfBody();
|
2003-10-17 10:31:47 +00:00
|
|
|
|
int const ww = workWidth();
|
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);
|
|
|
|
|
z = row.endpos();
|
2003-10-24 07:59:04 +00:00
|
|
|
|
fill(pit, row, ww);
|
2003-10-22 16:30:57 +00:00
|
|
|
|
prepareToPrint(pit, row);
|
|
|
|
|
setHeightOfRow(pit, row);
|
|
|
|
|
row.y_offset(pit->height);
|
2003-10-21 17:21:23 +00:00
|
|
|
|
pit->rows.push_back(row);
|
2003-10-24 07:59:04 +00:00
|
|
|
|
pit->width = std::max(pit->width, row.width());
|
|
|
|
|
pit->height += row.height();
|
2003-10-24 15:04:17 +00:00
|
|
|
|
} while (z < pit->size());
|
|
|
|
|
|
2003-10-17 10:31:47 +00:00
|
|
|
|
height += pit->height;
|
|
|
|
|
//lyxerr << "redoParagraph: " << pit->rows.size() << " rows\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-23 08:15:57 +00:00
|
|
|
|
void LyXText::redoParagraphs(ParagraphList::iterator pit,
|
2003-10-17 10:31:47 +00:00
|
|
|
|
ParagraphList::iterator end)
|
|
|
|
|
{
|
2003-10-23 08:15:57 +00:00
|
|
|
|
for ( ; pit != end; ++pit)
|
|
|
|
|
redoParagraphInternal(pit);
|
2003-10-17 10:31:47 +00:00
|
|
|
|
updateRowPositions();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXText::redoParagraph(ParagraphList::iterator pit)
|
|
|
|
|
{
|
|
|
|
|
redoParagraphInternal(pit);
|
|
|
|
|
updateRowPositions();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXText::fullRebreak()
|
|
|
|
|
{
|
|
|
|
|
redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end());
|
|
|
|
|
redoCursor();
|
|
|
|
|
selection.cursor = cursor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
|
|
|
|
|
{
|
2003-10-23 15:06:52 +00:00
|
|
|
|
//lyxerr << "LyXText::metrics: width: " << mi.base.textwidth
|
|
|
|
|
// << " workWidth: " << workWidth() << "\nfont: " << mi.base.font << endl;
|
2003-10-17 10:31:47 +00:00
|
|
|
|
//BOOST_ASSERT(mi.base.textwidth);
|
2003-10-23 09:06:18 +00:00
|
|
|
|
|
|
|
|
|
// rebuild row cache. This recomputes height as well.
|
2003-10-23 08:15:57 +00:00
|
|
|
|
redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end());
|
|
|
|
|
|
2003-10-23 09:06:18 +00:00
|
|
|
|
width = maxParagraphWidth(ownerParagraphs());
|
2003-10-17 10:31:47 +00:00
|
|
|
|
|
|
|
|
|
// final dimension
|
|
|
|
|
dim.asc = firstRow()->ascent_of_text();
|
|
|
|
|
dim.des = height - dim.asc;
|
|
|
|
|
dim.wid = std::max(mi.base.textwidth, int(width));
|
|
|
|
|
}
|
2003-10-23 08:15:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool LyXText::isLastRow(ParagraphList::iterator pit, Row const & row) const
|
|
|
|
|
{
|
|
|
|
|
return row.endpos() >= pit->size()
|
|
|
|
|
&& boost::next(pit) == ownerParagraphs().end();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool LyXText::isFirstRow(ParagraphList::iterator pit, Row const & row) const
|
|
|
|
|
{
|
|
|
|
|
return row.pos() == 0 && pit == ownerParagraphs().begin();
|
|
|
|
|
}
|
2003-11-11 10:08:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXText::cursorLeftOneWord(LyXCursor & cursor)
|
|
|
|
|
{
|
|
|
|
|
// treat HFills, floats and Insets as words
|
|
|
|
|
|
|
|
|
|
ParagraphList::iterator pit = cursorPar();
|
|
|
|
|
size_t pos = cursor.pos();
|
|
|
|
|
|
|
|
|
|
while (pos &&
|
|
|
|
|
(pit->isSeparator(pos - 1) ||
|
|
|
|
|
pit->isKomma(pos - 1) ||
|
|
|
|
|
pit->isNewline(pos - 1)) &&
|
|
|
|
|
!(pit->isHfill(pos - 1) ||
|
|
|
|
|
pit->isInset(pos - 1)))
|
|
|
|
|
--pos;
|
|
|
|
|
|
|
|
|
|
if (pos &&
|
|
|
|
|
(pit->isInset(pos - 1) ||
|
|
|
|
|
pit->isHfill(pos - 1))) {
|
|
|
|
|
--pos;
|
|
|
|
|
} else if (!pos) {
|
|
|
|
|
if (pit != ownerParagraphs().begin()) {
|
|
|
|
|
--pit;
|
|
|
|
|
pos = pit->size();
|
|
|
|
|
}
|
|
|
|
|
} else { // Here, cur != 0
|
|
|
|
|
while (pos > 0 && pit->isWord(pos - 1))
|
|
|
|
|
--pos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cursor.par(parOffset(pit));
|
|
|
|
|
cursor.pos(pos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXText::cursorRightOneWord(LyXCursor & cursor)
|
|
|
|
|
{
|
|
|
|
|
// treat floats, HFills and Insets as words
|
|
|
|
|
ParagraphList::iterator pit = cursorPar();
|
|
|
|
|
pos_type pos = cursor.pos();
|
|
|
|
|
|
|
|
|
|
if (pos == pit->size() &&
|
|
|
|
|
boost::next(pit) != ownerParagraphs().end()) {
|
|
|
|
|
++pit;
|
|
|
|
|
pos = 0;
|
|
|
|
|
} else {
|
|
|
|
|
// Skip through initial nonword stuff.
|
|
|
|
|
while (pos < pit->size() && !pit->isWord(pos)) {
|
|
|
|
|
++pos;
|
|
|
|
|
}
|
|
|
|
|
// Advance through word.
|
|
|
|
|
while (pos < pit->size() && pit->isWord(pos)) {
|
|
|
|
|
++pos;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cursor.par(parOffset(pit));
|
|
|
|
|
cursor.pos(pos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXText::getWord(LyXCursor & from, LyXCursor & to, word_location const loc)
|
|
|
|
|
{
|
|
|
|
|
ParagraphList::iterator from_par = getPar(from);
|
|
|
|
|
ParagraphList::iterator to_par = getPar(to);
|
|
|
|
|
switch (loc) {
|
|
|
|
|
case lyx::WHOLE_WORD_STRICT:
|
|
|
|
|
if (from.pos() == 0 || from.pos() == from_par->size()
|
|
|
|
|
|| from_par->isSeparator(from.pos())
|
|
|
|
|
|| from_par->isKomma(from.pos())
|
|
|
|
|
|| from_par->isNewline(from.pos())
|
|
|
|
|
|| from_par->isSeparator(from.pos() - 1)
|
|
|
|
|
|| from_par->isKomma(from.pos() - 1)
|
|
|
|
|
|| from_par->isNewline(from.pos() - 1)) {
|
|
|
|
|
to = from;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// no break here, we go to the next
|
|
|
|
|
|
|
|
|
|
case lyx::WHOLE_WORD:
|
|
|
|
|
// Move cursor to the beginning, when not already there.
|
|
|
|
|
if (from.pos() && !from_par->isSeparator(from.pos() - 1)
|
|
|
|
|
&& !(from_par->isKomma(from.pos() - 1)
|
|
|
|
|
|| from_par->isNewline(from.pos() - 1)))
|
|
|
|
|
cursorLeftOneWord(from);
|
|
|
|
|
break;
|
|
|
|
|
case lyx::PREVIOUS_WORD:
|
|
|
|
|
// always move the cursor to the beginning of previous word
|
|
|
|
|
cursorLeftOneWord(from);
|
|
|
|
|
break;
|
|
|
|
|
case lyx::NEXT_WORD:
|
|
|
|
|
lyxerr << "LyXText::getWord: NEXT_WORD not implemented yet"
|
|
|
|
|
<< endl;
|
|
|
|
|
break;
|
|
|
|
|
case lyx::PARTIAL_WORD:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
to = from;
|
|
|
|
|
while (to.pos() < to_par->size()
|
|
|
|
|
&& !to_par->isSeparator(to.pos())
|
|
|
|
|
&& !to_par->isKomma(to.pos())
|
|
|
|
|
&& !to_par->isNewline(to.pos())
|
|
|
|
|
&& !to_par->isHfill(to.pos())
|
|
|
|
|
&& !to_par->isInset(to.pos()))
|
|
|
|
|
{
|
|
|
|
|
to.pos(to.pos() + 1);
|
|
|
|
|
}
|
|
|
|
|
}
|