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"
|
2004-01-13 15:25:52 +00:00
|
|
|
|
#include "cursor.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-12-03 15:27:16 +00:00
|
|
|
|
#include "lyxlex.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
#include "lyxrc.h"
|
|
|
|
|
#include "lyxrow.h"
|
|
|
|
|
#include "lyxrow_funcs.h"
|
2003-10-17 10:31:47 +00:00
|
|
|
|
#include "metricsinfo.h"
|
2003-09-16 12:12:33 +00:00
|
|
|
|
#include "paragraph.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
#include "paragraph_funcs.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "ParagraphParameters.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
#include "rowpainter.h"
|
2003-10-14 13:01:49 +00:00
|
|
|
|
#include "undo.h"
|
2003-09-09 17:00:19 +00:00
|
|
|
|
#include "vspace.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
|
#include "WordLangTuple.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
|
|
|
|
|
#include "frontends/font_metrics.h"
|
|
|
|
|
#include "frontends/LyXView.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-11-15 00:39:11 +00:00
|
|
|
|
#include "insets/insettext.h"
|
|
|
|
|
|
|
|
|
|
#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-11-25 11:17:27 +00:00
|
|
|
|
/// some space for drawing the 'nested' markers (in pixel)
|
|
|
|
|
extern int const NEST_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-11-28 09:03:13 +00:00
|
|
|
|
/// right margin
|
|
|
|
|
extern int const RIGHT_MARGIN = 10;
|
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-11-25 11:17:27 +00:00
|
|
|
|
void LyXText::updateParPositions()
|
2003-03-06 20:21:21 +00:00
|
|
|
|
{
|
2003-12-01 13:35:49 +00:00
|
|
|
|
ParagraphList::iterator pit = paragraphs().begin();
|
|
|
|
|
ParagraphList::iterator end = paragraphs().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-11-25 11:17:27 +00:00
|
|
|
|
int LyXText::textWidth() const
|
2000-06-12 11:27:15 +00:00
|
|
|
|
{
|
2003-11-25 11:17:27 +00:00
|
|
|
|
return textwidth_;
|
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-11-25 11:17:27 +00:00
|
|
|
|
return singleWidth(pit, pos, c, getFont(pit, pos));
|
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-11-25 11:17:27 +00:00
|
|
|
|
int LyXText::leftMargin(ParagraphList::iterator pit) const
|
|
|
|
|
{
|
|
|
|
|
return leftMargin(pit, pit->size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int LyXText::leftMargin(ParagraphList::iterator pit, pos_type pos) const
|
2003-08-26 10:33:59 +00:00
|
|
|
|
{
|
2001-10-16 14:47:10 +00:00
|
|
|
|
LyXTextClass const & tclass =
|
2003-09-09 09:47:59 +00:00
|
|
|
|
bv()->buffer()->params().getLyXTextClass();
|
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-11-25 11:17:27 +00:00
|
|
|
|
int x = NEST_MARGIN + CHANGEBAR_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
|
|
|
|
|
2003-11-25 11:17:27 +00:00
|
|
|
|
// This is the way LyX handles LaTeX-Environments.
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// 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-12-01 13:35:49 +00:00
|
|
|
|
if (pit != paragraphs().begin()) {
|
2003-04-16 08:12:22 +00:00
|
|
|
|
ParagraphList::iterator newpit =
|
2003-12-01 13:35:49 +00:00
|
|
|
|
depthHook(pit, paragraphs(), pit->getDepth());
|
2003-10-28 11:18:40 +00:00
|
|
|
|
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 =
|
2003-12-01 13:35:49 +00:00
|
|
|
|
outerHook(pit, paragraphs());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-25 11:17:27 +00:00
|
|
|
|
// Make a corresponding row. Need to call leftMargin()
|
|
|
|
|
// to check whether it is a sufficent paragraph.
|
2003-12-01 13:35:49 +00:00
|
|
|
|
if (newpar != paragraphs().end()
|
2003-10-28 11:18:40 +00:00
|
|
|
|
&& newpar->layout()->isEnvironment()) {
|
2003-11-25 11:17:27 +00:00
|
|
|
|
x = leftMargin(newpar);
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2002-03-02 16:39:54 +00:00
|
|
|
|
|
2003-12-01 13:35:49 +00:00
|
|
|
|
if (newpar != paragraphs().end()
|
2003-10-28 11:18:40 +00:00
|
|
|
|
&& 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-25 11:17:27 +00:00
|
|
|
|
if (!pit->empty() && 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-25 11:17:27 +00:00
|
|
|
|
if (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-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
|
2003-12-01 13:35:49 +00:00
|
|
|
|
&& !isFirstInSequence(pit, paragraphs()))) {
|
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: {
|
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.
|
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.
|
2003-11-25 11:17:27 +00:00
|
|
|
|
int minfill = textwidth_;
|
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;
|
2003-12-02 07:15:42 +00:00
|
|
|
|
#endif
|
|
|
|
|
// also wrong, but much shorter.
|
|
|
|
|
x += textwidth_ / 2;
|
2003-11-25 11:17:27 +00:00
|
|
|
|
break;
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-12-01 13:35:49 +00:00
|
|
|
|
if (!pit->params().leftIndent().zero())
|
|
|
|
|
x += pit->params().leftIndent().inPixels(textWidth());
|
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-12-03 18:17:20 +00:00
|
|
|
|
if (pos == 0
|
|
|
|
|
&& (layout->labeltype == LABEL_NO_LABEL
|
|
|
|
|
|| layout->labeltype == LABEL_TOP_ENVIRONMENT
|
|
|
|
|
|| layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
|
|
|
|
|
|| (layout->labeltype == LABEL_STATIC
|
|
|
|
|
&& layout->latextype == LATEX_ENVIRONMENT
|
|
|
|
|
&& !isFirstInSequence(pit, paragraphs())))
|
|
|
|
|
&& align == LYX_ALIGN_BLOCK
|
|
|
|
|
&& !pit->params().noindent()
|
|
|
|
|
// in tabulars and ert paragraphs are never indented!
|
|
|
|
|
&& (!pit->inInset()
|
|
|
|
|
|| !pit->inInset()->owner()
|
|
|
|
|
|| (pit->inInset()->owner()->lyxCode() != InsetOld::TABULAR_CODE
|
|
|
|
|
&& pit->inInset()->owner()->lyxCode() != InsetOld::ERT_CODE))
|
|
|
|
|
&& (pit->layout() != tclass.defaultLayout()
|
|
|
|
|
|| bv()->buffer()->params().paragraph_separation ==
|
|
|
|
|
BufferParams::PARSEP_INDENT))
|
|
|
|
|
{
|
|
|
|
|
x += font_metrics::signedWidth(parindent, tclass.defaultfont());
|
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-11-25 11:17:27 +00:00
|
|
|
|
int LyXText::rightMargin(Paragraph const & par) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-11-25 11:17:27 +00:00
|
|
|
|
LyXTextClass const & tclass = bv()->buffer()->params().getLyXTextClass();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-25 11:17:27 +00:00
|
|
|
|
return
|
2003-11-28 09:03:13 +00:00
|
|
|
|
RIGHT_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-11-25 11:17:27 +00:00
|
|
|
|
+ font_metrics::signedWidth(par.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-11-25 11:17:27 +00:00
|
|
|
|
int LyXText::labelEnd(ParagraphList::iterator 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.
|
|
|
|
|
if (pit->layout()->margintype != MARGIN_MANUAL)
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
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-11-25 11:17:27 +00:00
|
|
|
|
// maximum pixel width of a row
|
|
|
|
|
int width = textWidth() - rightMargin(*pit); // - leftMargin(pit, row);
|
2003-10-23 15:38:48 +00:00
|
|
|
|
if (width < 0) {
|
2003-10-27 10:27:50 +00:00
|
|
|
|
row.endpos(end);
|
2003-10-23 15:38:48 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2000-09-23 04:57:18 +00:00
|
|
|
|
|
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-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
|
|
|
|
|
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-11-25 11:17:27 +00:00
|
|
|
|
if (pit->isInset(i + 1) && pit->getInset(i + 1)->display()) {
|
2003-10-27 10:27:50 +00:00
|
|
|
|
point = i + 1;
|
2003-10-20 18:56:48 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// ...and after.
|
2003-11-25 11:17:27 +00:00
|
|
|
|
if (pit->isInset(i) && pit->getInset(i)->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);
|
|
|
|
|
|
2003-11-25 11:17:27 +00:00
|
|
|
|
add = std::max(add, labelEnd(pit) - x);
|
2003-10-27 10:27:50 +00:00
|
|
|
|
thiswidth += add;
|
|
|
|
|
}
|
2003-03-09 21:54:56 +00:00
|
|
|
|
|
2003-10-27 10:27:50 +00:00
|
|
|
|
x += thiswidth;
|
|
|
|
|
//lyxerr << "i: " << i << " x: "
|
|
|
|
|
//<< x << " width: " << width << endl;
|
|
|
|
|
chunkwidth += thiswidth;
|
|
|
|
|
}
|
2003-10-29 10:47:21 +00:00
|
|
|
|
|
2003-03-09 21:54:56 +00:00
|
|
|
|
// break before a character that will fall off
|
|
|
|
|
// the right of the row
|
|
|
|
|
if (x >= width) {
|
2003-08-26 10:33:59 +00:00
|
|
|
|
// if no break before, break here
|
2003-10-24 15:04:17 +00:00
|
|
|
|
if (point == end || chunkwidth >= width - left) {
|
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
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2003-03-09 21:54:56 +00:00
|
|
|
|
|
2003-11-25 11:17:27 +00:00
|
|
|
|
if (!pit->isInset(i) || pit->getInset(i)->isChar()) {
|
2003-03-09 21:54:56 +00:00
|
|
|
|
// 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 (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-11-25 11:17:27 +00:00
|
|
|
|
string labelsep = pit->layout()->labelsep;
|
|
|
|
|
int w = leftMargin(pit, row.pos());
|
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-11-25 11:17:27 +00:00
|
|
|
|
w += font_metrics::width(labelsep, getLabelFont(pit));
|
2003-07-27 00:37:17 +00:00
|
|
|
|
if (pit->isLineSeparator(i - 1))
|
|
|
|
|
w -= singleWidth(pit, i - 1);
|
2003-11-25 11:17:27 +00:00
|
|
|
|
w = max(w, labelEnd(pit));
|
2003-07-27 00:37:17 +00:00
|
|
|
|
}
|
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-11-25 11:17:27 +00:00
|
|
|
|
w += font_metrics::width(labelsep, getLabelFont(pit));
|
2003-10-27 11:44:10 +00:00
|
|
|
|
if (end > 0 && pit->isLineSeparator(end - 1))
|
|
|
|
|
w -= singleWidth(pit, end - 1);
|
2003-11-25 11:17:27 +00:00
|
|
|
|
w = max(w, labelEnd(pit));
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-25 11:17:27 +00:00
|
|
|
|
int const fill = workwidth - w - rightMargin(*pit);
|
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
|
|
|
|
{
|
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
|
|
|
|
|
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
|
|
|
|
|
2004-01-09 09:04:33 +00:00
|
|
|
|
// as max get the first character of this row then it can
|
|
|
|
|
// increase but not decrease the height. Just some point to
|
|
|
|
|
// start with so we don't have to do the assignment below too
|
|
|
|
|
// often.
|
2003-10-17 10:31:47 +00:00
|
|
|
|
LyXFont font = getFont(pit, row.pos());
|
2001-07-31 12:57:06 +00:00
|
|
|
|
LyXFont::FONT_SIZE const tmpsize = font.size();
|
2003-07-27 21:59:06 +00:00
|
|
|
|
font = getLayoutFont(pit);
|
2001-07-31 12:57:06 +00:00
|
|
|
|
LyXFont::FONT_SIZE const size = font.size();
|
|
|
|
|
font.setSize(tmpsize);
|
2001-07-31 10:10:17 +00:00
|
|
|
|
|
2003-07-27 21:59:06 +00:00
|
|
|
|
LyXFont labelfont = getLabelFont(pit);
|
2001-07-31 10:10:17 +00:00
|
|
|
|
|
2003-10-24 09:45:07 +00:00
|
|
|
|
// these are minimum values
|
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-12-01 13:35:49 +00:00
|
|
|
|
&& pit != paragraphs().begin()
|
2003-10-28 11:18:40 +00:00
|
|
|
|
&& ((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-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-12-01 13:35:49 +00:00
|
|
|
|
&& isFirstInSequence(pit, paragraphs())
|
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-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
|
|
|
|
|
2003-10-27 12:41:26 +00:00
|
|
|
|
ParagraphList::iterator prev =
|
2003-12-01 13:35:49 +00:00
|
|
|
|
depthHook(pit, paragraphs(), pit->getDepth());
|
2003-10-28 11:18:40 +00:00
|
|
|
|
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-12-01 13:35:49 +00:00
|
|
|
|
} else if (pit != paragraphs().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-12-01 13:35:49 +00:00
|
|
|
|
prev = outerHook(pit, paragraphs());
|
|
|
|
|
if (prev != paragraphs().end()) {
|
2003-10-28 11:18:40 +00:00
|
|
|
|
maxasc += int(prev->layout()->parsep * dh);
|
2003-12-01 13:35:49 +00:00
|
|
|
|
} else if (pit != paragraphs().begin()) {
|
2003-10-27 12:41:26 +00:00
|
|
|
|
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-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
|
2003-11-25 11:17:27 +00:00
|
|
|
|
ParagraphList::iterator nextpit = boost::next(pit);
|
2003-12-01 13:35:49 +00:00
|
|
|
|
if (nextpit != paragraphs().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;
|
2003-12-01 13:35:49 +00:00
|
|
|
|
cpit = depthHook(cpit, paragraphs(), nextpit->getDepth());
|
2003-10-28 11:18:40 +00:00
|
|
|
|
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();
|
2004-01-13 10:37:38 +00:00
|
|
|
|
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
|
|
|
|
|
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
|
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
|
|
|
|
|
2004-01-09 09:04:33 +00:00
|
|
|
|
// a layout change may affect also the following paragraph
|
2004-01-13 10:37:38 +00:00
|
|
|
|
recUndo(cursor().par(), parOffset(undoSpan(cpit)) - 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-01-13 10:37:38 +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,
|
2004-01-13 10:37:38 +00:00
|
|
|
|
cursor().pos(), keep_layout);
|
2000-09-23 04:57:18 +00:00
|
|
|
|
|
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) {
|
2004-01-13 10:37:38 +00:00
|
|
|
|
if (!cursor().pos())
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// 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
|
2004-01-13 10:37:38 +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!
|
2004-01-13 10:37:38 +00:00
|
|
|
|
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());
|
2004-01-13 10:37:38 +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
|
|
|
|
{
|
2004-01-13 10:37:38 +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) &&
|
2004-01-13 10:37:38 +00:00
|
|
|
|
cursor().pos() >= 1 &&
|
|
|
|
|
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
|
|
|
|
|
2004-01-13 10:37:38 +00:00
|
|
|
|
if (cursor().pos() > 0) {
|
|
|
|
|
char const c = cursorPar()->getChar(cursor().pos() - 1);
|
2001-01-15 14:05:45 +00:00
|
|
|
|
if (contains(number_unary_operators, c) &&
|
2004-01-13 10:37:38 +00:00
|
|
|
|
(cursor().pos() == 1 ||
|
|
|
|
|
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(),
|
2004-01-13 10:37:38 +00:00
|
|
|
|
cursor().pos() - 1,
|
2000-10-09 12:30:52 +00:00
|
|
|
|
current_font);
|
2001-01-15 14:05:45 +00:00
|
|
|
|
} else if (contains(number_seperators, c) &&
|
2004-01-13 10:37:38 +00:00
|
|
|
|
cursor().pos() >= 2 &&
|
2003-07-27 21:59:06 +00:00
|
|
|
|
getFont(
|
2003-10-09 10:52:12 +00:00
|
|
|
|
cursorPar(),
|
2004-01-13 10:37:38 +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(),
|
2004-01-13 10:37:38 +00:00
|
|
|
|
cursor().pos() - 1,
|
2000-10-09 12:30:52 +00:00
|
|
|
|
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)) {
|
2004-01-13 10:37:38 +00:00
|
|
|
|
if ((cursor().pos() > 0
|
|
|
|
|
&& cursorPar()->isLineSeparator(cursor().pos() - 1))
|
|
|
|
|
|| (cursor().pos() > 0
|
|
|
|
|
&& cursorPar()->isNewline(cursor().pos() - 1))
|
|
|
|
|
|| (cursor().pos() == 0)) {
|
2001-05-09 15:20:58 +00:00
|
|
|
|
static bool sent_space_message = false;
|
|
|
|
|
if (!sent_space_message) {
|
2004-01-13 10:37:38 +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)
|
2004-01-13 10:37:38 +00:00
|
|
|
|
cursorPar()->insertChar(cursor().pos(), c);
|
2003-08-08 15:48:57 +00:00
|
|
|
|
|
2004-01-13 10:37:38 +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());
|
2004-01-13 10:37:38 +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-11-25 11:17:27 +00:00
|
|
|
|
x = rightMargin(*pit);
|
2003-07-18 07:47:07 +00:00
|
|
|
|
else
|
2003-11-25 11:17:27 +00:00
|
|
|
|
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
|
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-11-25 11:17:27 +00:00
|
|
|
|
} else if (int(row.width()) < textWidth()) {
|
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
|
|
|
|
{
|
2004-01-13 10:37:38 +00:00
|
|
|
|
cursorRightOneWord(cursor());
|
|
|
|
|
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
|
|
|
|
{
|
2004-01-13 14:13:51 +00:00
|
|
|
|
CursorSlice 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
|
|
|
|
{
|
2004-01-13 14:13:51 +00:00
|
|
|
|
CursorSlice from = cursor();
|
|
|
|
|
CursorSlice to = cursor();
|
2003-11-11 10:08:35 +00:00
|
|
|
|
getWord(from, to, loc);
|
2004-01-13 10:37:38 +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;
|
2004-01-13 18:08:13 +00:00
|
|
|
|
bv()->resetAnchor();
|
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;
|
|
|
|
|
|
2003-12-12 15:19:35 +00:00
|
|
|
|
if (selStart().par() == selEnd().par()) {
|
2004-01-13 14:13:51 +00:00
|
|
|
|
CursorSlice const & startc = selStart();
|
|
|
|
|
CursorSlice const & endc = selEnd();
|
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-12-12 15:19:35 +00:00
|
|
|
|
if (selStart().par() == selEnd().par()) {
|
2004-01-13 14:13:51 +00:00
|
|
|
|
CursorSlice const & startc = selStart();
|
|
|
|
|
CursorSlice const & endc = selEnd();
|
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 {
|
2004-01-13 14:13:51 +00:00
|
|
|
|
CursorSlice 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());
|
2004-01-13 18:08:13 +00:00
|
|
|
|
bv()->resetAnchor();
|
2004-01-13 10:37:38 +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 {
|
2004-01-13 14:13:51 +00:00
|
|
|
|
CursorSlice tmpcursor = cursor();
|
2002-05-29 12:58:23 +00:00
|
|
|
|
selection.set(true); // to avoid deletion
|
2003-03-17 16:25:00 +00:00
|
|
|
|
cursorLeftOneWord();
|
|
|
|
|
setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
|
2004-01-13 18:08:13 +00:00
|
|
|
|
bv()->resetAnchor();
|
2004-01-13 10:37:38 +00:00
|
|
|
|
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 {
|
2004-01-13 14:13:51 +00:00
|
|
|
|
CursorSlice tmpcursor = cursor();
|
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());
|
2004-01-13 18:08:13 +00:00
|
|
|
|
bv()->resetAnchor();
|
2004-01-13 10:37:38 +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
|
|
|
|
{
|
2004-01-13 14:13:51 +00:00
|
|
|
|
CursorSlice from;
|
|
|
|
|
CursorSlice to;
|
2001-03-09 00:56:42 +00:00
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
if (selection.set()) {
|
2003-12-12 15:19:35 +00:00
|
|
|
|
from = selStart();
|
|
|
|
|
to = selEnd();
|
2001-06-27 14:10:35 +00:00
|
|
|
|
} else {
|
2004-01-13 10:37:38 +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-12-01 13:35:49 +00:00
|
|
|
|
while (par != int(paragraphs().size()) &&
|
2003-10-09 10:52:12 +00:00
|
|
|
|
(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
|
2004-01-13 14:13:51 +00:00
|
|
|
|
CursorSlice 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-11-27 09:22:41 +00:00
|
|
|
|
cursorRight(true);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
|
|
|
|
|
// if you had success make a backspace
|
2004-01-13 10:37:38 +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
|
|
|
|
|
2004-01-13 10:37:38 +00:00
|
|
|
|
if (cursor().pos() == 0) {
|
2004-01-09 09:04:33 +00:00
|
|
|
|
// The cursor is at the beginning of a paragraph, so
|
|
|
|
|
// the the backspace will collapse two paragraphs into
|
|
|
|
|
// one.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
// but it's not allowed unless it's new
|
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?
|
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
|
|
|
|
|
2004-01-13 10:37:38 +00:00
|
|
|
|
if (cursor().par()) {
|
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
|
|
|
|
|
2004-01-13 10:37:38 +00:00
|
|
|
|
if (cursor().par() != 0)
|
|
|
|
|
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)
|
2004-01-13 10:37:38 +00:00
|
|
|
|
if (cursor().par() != 0) {
|
2000-03-28 02:18:52 +00:00
|
|
|
|
// steps into the above paragraph.
|
2004-01-13 10:37:38 +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
|
|
|
|
|
2004-01-13 10:37:38 +00:00
|
|
|
|
if (cursor().pos() && cpit->isSeparator(cursor().pos() - 1))
|
|
|
|
|
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();
|
2004-01-13 10:37:38 +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
|
2004-01-13 10:37:38 +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)
|
2004-01-13 10:37:38 +00:00
|
|
|
|
setCursorIntern(cursor().par(), cursor().pos() - 1,
|
|
|
|
|
false, cursor().boundary());
|
|
|
|
|
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();
|
2004-01-13 10:37:38 +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();
|
2004-01-13 10:37:38 +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
|
|
|
|
|
{
|
2004-01-13 10:37:38 +00:00
|
|
|
|
return getPar(cursor().par());
|
2003-10-09 10:52:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-24 09:45:07 +00:00
|
|
|
|
RowList::iterator LyXText::cursorRow() const
|
|
|
|
|
{
|
2004-01-13 10:37:38 +00:00
|
|
|
|
return cursorPar()->getRow(cursor().pos());
|
2003-10-24 09:45:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-13 14:13:51 +00:00
|
|
|
|
ParagraphList::iterator LyXText::getPar(CursorSlice const & cur) const
|
2003-10-09 10:52:12 +00:00
|
|
|
|
{
|
|
|
|
|
return getPar(cur.par());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ParagraphList::iterator LyXText::getPar(int par) const
|
|
|
|
|
{
|
2003-10-10 09:01:23 +00:00
|
|
|
|
BOOST_ASSERT(par >= 0);
|
2003-12-01 13:35:49 +00:00
|
|
|
|
BOOST_ASSERT(par < int(paragraphs().size()));
|
|
|
|
|
ParagraphList::iterator pit = paragraphs().begin();
|
2003-10-09 10:52:12 +00:00
|
|
|
|
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
|
2003-12-01 13:35:49 +00:00
|
|
|
|
pend = boost::prior(paragraphs().end());
|
|
|
|
|
pit = paragraphs().begin();
|
2003-10-28 11:18:40 +00:00
|
|
|
|
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-12-01 13:35:49 +00:00
|
|
|
|
pit = boost::prior(paragraphs().end());
|
2003-08-25 10:24:26 +00:00
|
|
|
|
|
|
|
|
|
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-12-01 13:35:49 +00:00
|
|
|
|
return paragraphs().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
|
|
|
|
|
{
|
2003-12-01 13:35:49 +00:00
|
|
|
|
return paragraphs().begin();
|
2003-11-22 14:44:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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-12-01 13:35:49 +00:00
|
|
|
|
return paragraphs().back().rows.end();
|
2003-08-14 11:16:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-22 14:44:59 +00:00
|
|
|
|
ParagraphList::iterator LyXText::endPar() const
|
|
|
|
|
{
|
2003-12-01 13:35:49 +00:00
|
|
|
|
return paragraphs().end();
|
2003-11-22 14:44:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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;
|
2003-12-01 13:35:49 +00:00
|
|
|
|
if (pit == paragraphs().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-12-01 13:35:49 +00:00
|
|
|
|
BOOST_ASSERT(pit != paragraphs().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 ...
|
2003-12-12 15:19:35 +00:00
|
|
|
|
ParagraphList::iterator startpit = getPar(selStart());
|
|
|
|
|
ParagraphList::iterator endpit = getPar(selEnd());
|
|
|
|
|
size_t const startpos = selStart().pos();
|
|
|
|
|
size_t const endpos = selEnd().pos();
|
2003-10-09 10:52:12 +00:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
{
|
2003-12-01 13:35:49 +00:00
|
|
|
|
return std::distance(paragraphs().begin(), pit);
|
2003-10-09 10:52:12 +00:00
|
|
|
|
}
|
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;
|
2003-11-25 11:17:27 +00:00
|
|
|
|
int const w = textWidth() - leftMargin(pit) - rightMargin(*pit);
|
|
|
|
|
MetricsInfo mi(bv(), getFont(pit, ii->pos), w);
|
2003-10-17 10:31:47 +00:00
|
|
|
|
ii->inset->metrics(mi, dim);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// rebreak the paragraph
|
2003-11-13 13:43:44 +00:00
|
|
|
|
pit->setBeginOfBody();
|
2003-10-24 15:04:17 +00:00
|
|
|
|
pos_type z = 0;
|
|
|
|
|
do {
|
2003-10-17 10:31:47 +00:00
|
|
|
|
Row row(z);
|
2003-10-23 15:38:48 +00:00
|
|
|
|
rowBreakPoint(pit, row);
|
|
|
|
|
z = row.endpos();
|
2003-11-25 11:17:27 +00:00
|
|
|
|
fill(pit, row, textwidth_);
|
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-11-25 11:17:27 +00:00
|
|
|
|
updateParPositions();
|
2003-10-17 10:31:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXText::redoParagraph(ParagraphList::iterator pit)
|
|
|
|
|
{
|
|
|
|
|
redoParagraphInternal(pit);
|
2003-11-25 11:17:27 +00:00
|
|
|
|
updateParPositions();
|
2003-10-17 10:31:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXText::fullRebreak()
|
|
|
|
|
{
|
2003-12-01 13:35:49 +00:00
|
|
|
|
redoParagraphs(paragraphs().begin(), paragraphs().end());
|
2004-01-13 18:08:13 +00:00
|
|
|
|
bv()->resetAnchor();
|
2003-10-17 10:31:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
|
|
|
|
|
{
|
|
|
|
|
//BOOST_ASSERT(mi.base.textwidth);
|
2003-11-25 11:17:27 +00:00
|
|
|
|
if (mi.base.textwidth)
|
|
|
|
|
textwidth_ = mi.base.textwidth;
|
|
|
|
|
//lyxerr << "LyXText::metrics: width: " << mi.base.textwidth
|
|
|
|
|
// << " textWidth: " << textWidth() << "\nfont: " << mi.base.font << endl;
|
2003-10-23 09:06:18 +00:00
|
|
|
|
|
2003-11-25 11:17:27 +00:00
|
|
|
|
// Rebuild row cache. This recomputes height as well.
|
2003-12-01 13:35:49 +00:00
|
|
|
|
redoParagraphs(paragraphs().begin(), paragraphs().end());
|
2003-10-23 08:15:57 +00:00
|
|
|
|
|
2003-12-01 13:35:49 +00:00
|
|
|
|
width = maxParagraphWidth(paragraphs());
|
2003-10-17 10:31:47 +00:00
|
|
|
|
|
|
|
|
|
// final dimension
|
|
|
|
|
dim.asc = firstRow()->ascent_of_text();
|
|
|
|
|
dim.des = height - dim.asc;
|
2003-12-02 07:15:42 +00:00
|
|
|
|
dim.wid = width;
|
2003-10-17 10:31:47 +00:00
|
|
|
|
}
|
2003-10-23 08:15:57 +00:00
|
|
|
|
|
|
|
|
|
|
2003-11-28 08:55:12 +00:00
|
|
|
|
// only used for inset right now. should also be used for main text
|
2003-12-15 11:36:19 +00:00
|
|
|
|
void LyXText::draw(PainterInfo & pi, int x, int y) const
|
2003-11-28 08:55:12 +00:00
|
|
|
|
{
|
|
|
|
|
xo_ = x;
|
|
|
|
|
yo_ = y;
|
2003-12-15 11:36:19 +00:00
|
|
|
|
paintTextInset(*this, pi, x, y);
|
2003-11-28 08:55:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-23 08:15:57 +00:00
|
|
|
|
bool LyXText::isLastRow(ParagraphList::iterator pit, Row const & row) const
|
|
|
|
|
{
|
|
|
|
|
return row.endpos() >= pit->size()
|
2003-12-01 13:35:49 +00:00
|
|
|
|
&& boost::next(pit) == paragraphs().end();
|
2003-10-23 08:15:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool LyXText::isFirstRow(ParagraphList::iterator pit, Row const & row) const
|
|
|
|
|
{
|
2003-12-01 13:35:49 +00:00
|
|
|
|
return row.pos() == 0 && pit == paragraphs().begin();
|
2003-10-23 08:15:57 +00:00
|
|
|
|
}
|
2003-11-11 10:08:35 +00:00
|
|
|
|
|
|
|
|
|
|
2004-01-13 14:13:51 +00:00
|
|
|
|
void LyXText::cursorLeftOneWord(CursorSlice & cur)
|
2003-11-11 10:08:35 +00:00
|
|
|
|
{
|
|
|
|
|
// treat HFills, floats and Insets as words
|
|
|
|
|
|
|
|
|
|
ParagraphList::iterator pit = cursorPar();
|
2004-01-13 10:37:38 +00:00
|
|
|
|
size_t pos = cur.pos();
|
2003-11-11 10:08:35 +00:00
|
|
|
|
|
|
|
|
|
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) {
|
2003-12-01 13:35:49 +00:00
|
|
|
|
if (pit != paragraphs().begin()) {
|
2003-11-11 10:08:35 +00:00
|
|
|
|
--pit;
|
|
|
|
|
pos = pit->size();
|
|
|
|
|
}
|
|
|
|
|
} else { // Here, cur != 0
|
|
|
|
|
while (pos > 0 && pit->isWord(pos - 1))
|
|
|
|
|
--pos;
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-13 10:37:38 +00:00
|
|
|
|
cur.par(parOffset(pit));
|
|
|
|
|
cur.pos(pos);
|
2003-11-11 10:08:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-13 14:13:51 +00:00
|
|
|
|
void LyXText::cursorRightOneWord(CursorSlice & cur)
|
2003-11-11 10:08:35 +00:00
|
|
|
|
{
|
|
|
|
|
// treat floats, HFills and Insets as words
|
|
|
|
|
ParagraphList::iterator pit = cursorPar();
|
2004-01-13 10:37:38 +00:00
|
|
|
|
pos_type pos = cur.pos();
|
2003-11-11 10:08:35 +00:00
|
|
|
|
|
|
|
|
|
if (pos == pit->size() &&
|
2003-12-01 13:35:49 +00:00
|
|
|
|
boost::next(pit) != paragraphs().end()) {
|
2003-11-11 10:08:35 +00:00
|
|
|
|
++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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-13 10:37:38 +00:00
|
|
|
|
cur.par(parOffset(pit));
|
|
|
|
|
cur.pos(pos);
|
2003-11-11 10:08:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-13 14:13:51 +00:00
|
|
|
|
void LyXText::getWord(CursorSlice & from, CursorSlice & to, word_location const loc)
|
2003-11-11 10:08:35 +00:00
|
|
|
|
{
|
|
|
|
|
ParagraphList::iterator from_par = getPar(from);
|
|
|
|
|
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;
|
2004-01-14 09:33:14 +00:00
|
|
|
|
ParagraphList::iterator to_par = getPar(to);
|
2003-11-11 10:08:35 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
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)
|
|
|
|
|
{
|
|
|
|
|
static Change current_change;
|
|
|
|
|
|
|
|
|
|
bool the_end_read = false;
|
|
|
|
|
ParagraphList::iterator pit = paragraphs().begin();
|
|
|
|
|
Paragraph::depth_type depth = 0;
|
|
|
|
|
|
|
|
|
|
while (lex.isOK()) {
|
|
|
|
|
lex.nextToken();
|
|
|
|
|
string token = lex.getString();
|
|
|
|
|
|
|
|
|
|
if (token.empty())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (in_inset_) {
|
|
|
|
|
|
|
|
|
|
if (token == "\\end_inset") {
|
|
|
|
|
the_end_read = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (token == "\\end_document") {
|
|
|
|
|
lex.printError("\\end_document read in inset! Error in document!");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
if (token == "\\end_document") {
|
|
|
|
|
the_end_read = true;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FIXME: ugly.
|
|
|
|
|
int unknown = 0;
|
|
|
|
|
|
|
|
|
|
if (token == "\\begin_layout") {
|
|
|
|
|
lex.pushToken(token);
|
|
|
|
|
|
|
|
|
|
Paragraph par;
|
|
|
|
|
par.params().depth(depth);
|
|
|
|
|
if (buf.params().tracking_changes)
|
|
|
|
|
par.trackChanges();
|
|
|
|
|
LyXFont f(LyXFont::ALL_INHERIT, buf.params().language);
|
|
|
|
|
par.setFont(0, f);
|
|
|
|
|
|
|
|
|
|
// insert after
|
|
|
|
|
if (pit != paragraphs().end())
|
|
|
|
|
++pit;
|
|
|
|
|
|
|
|
|
|
pit = paragraphs().insert(pit, par);
|
|
|
|
|
|
|
|
|
|
// FIXME: goddamn InsetTabular makes us pass a Buffer
|
|
|
|
|
// not BufferParams
|
|
|
|
|
::readParagraph(buf, *pit, lex);
|
|
|
|
|
|
|
|
|
|
} else if (token == "\\begin_deeper") {
|
|
|
|
|
++depth;
|
|
|
|
|
} else if (token == "\\end_deeper") {
|
|
|
|
|
if (!depth) {
|
|
|
|
|
lex.printError("\\end_deeper: " "depth is already null");
|
|
|
|
|
} else {
|
|
|
|
|
--depth;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
++unknown;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return the_end_read;
|
|
|
|
|
}
|
2003-12-10 09:45:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int LyXText::ascent() const
|
|
|
|
|
{
|
|
|
|
|
return firstRow()->ascent_of_text();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int LyXText::descent() const
|
|
|
|
|
{
|
|
|
|
|
return height - firstRow()->ascent_of_text();
|
|
|
|
|
}
|
|
|
|
|
|
2003-12-15 11:36:19 +00:00
|
|
|
|
|
|
|
|
|
int LyXText::cursorX() const
|
|
|
|
|
{
|
2004-01-13 10:37:38 +00:00
|
|
|
|
return cursorX(cursor());
|
2003-12-15 11:36:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int LyXText::cursorY() const
|
|
|
|
|
{
|
2004-01-13 10:37:38 +00:00
|
|
|
|
return cursorY(cursor());
|
2003-12-15 11:36:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-13 14:13:51 +00:00
|
|
|
|
int LyXText::cursorX(CursorSlice const & cur) const
|
2003-12-15 11:36:19 +00:00
|
|
|
|
{
|
|
|
|
|
ParagraphList::iterator pit = getPar(cur);
|
2004-01-07 08:36:30 +00:00
|
|
|
|
if (pit->rows.empty())
|
|
|
|
|
return 0;
|
2003-12-15 11:36:19 +00:00
|
|
|
|
Row const & row = *pit->getRow(cur.pos());
|
|
|
|
|
pos_type pos = cur.pos();
|
|
|
|
|
pos_type cursor_vpos = 0;
|
|
|
|
|
double x = row.x();
|
|
|
|
|
double fill_separator = row.fill_separator();
|
|
|
|
|
double fill_hfill = row.fill_hfill();
|
|
|
|
|
double fill_label_hfill = row.fill_label_hfill();
|
|
|
|
|
pos_type const row_pos = row.pos();
|
|
|
|
|
pos_type const end = row.endpos();
|
|
|
|
|
|
|
|
|
|
if (end <= row_pos)
|
|
|
|
|
cursor_vpos = row_pos;
|
|
|
|
|
else if (pos >= end)
|
|
|
|
|
cursor_vpos = (pit->isRightToLeftPar(bv()->buffer()->params()))
|
|
|
|
|
? row_pos : end;
|
|
|
|
|
else if (pos > row_pos && pos >= end)
|
|
|
|
|
// Place cursor after char at (logical) position pos - 1
|
|
|
|
|
cursor_vpos = (bidi.level(pos - 1) % 2 == 0)
|
|
|
|
|
? bidi.log2vis(pos - 1) + 1 : bidi.log2vis(pos - 1);
|
|
|
|
|
else
|
|
|
|
|
// Place cursor before char at (logical) position pos
|
|
|
|
|
cursor_vpos = (bidi.level(pos) % 2 == 0)
|
|
|
|
|
? bidi.log2vis(pos) : bidi.log2vis(pos) + 1;
|
|
|
|
|
|
|
|
|
|
pos_type body_pos = pit->beginOfBody();
|
|
|
|
|
if (body_pos > 0 &&
|
|
|
|
|
(body_pos > end || !pit->isLineSeparator(body_pos - 1)))
|
|
|
|
|
body_pos = 0;
|
|
|
|
|
|
|
|
|
|
for (pos_type vpos = row_pos; vpos < cursor_vpos; ++vpos) {
|
|
|
|
|
pos_type pos = bidi.vis2log(vpos);
|
|
|
|
|
if (body_pos > 0 && pos == body_pos - 1) {
|
|
|
|
|
x += fill_label_hfill
|
|
|
|
|
+ font_metrics::width(pit->layout()->labelsep,
|
|
|
|
|
getLabelFont(pit));
|
|
|
|
|
if (pit->isLineSeparator(body_pos - 1))
|
|
|
|
|
x -= singleWidth(pit, body_pos - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hfillExpansion(*pit, row, pos)) {
|
|
|
|
|
x += singleWidth(pit, pos);
|
|
|
|
|
if (pos >= body_pos)
|
|
|
|
|
x += fill_hfill;
|
|
|
|
|
else
|
|
|
|
|
x += fill_label_hfill;
|
|
|
|
|
} else if (pit->isSeparator(pos)) {
|
|
|
|
|
x += singleWidth(pit, pos);
|
|
|
|
|
if (pos >= body_pos)
|
|
|
|
|
x += fill_separator;
|
|
|
|
|
} else
|
|
|
|
|
x += singleWidth(pit, pos);
|
|
|
|
|
}
|
|
|
|
|
return int(x);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-13 14:13:51 +00:00
|
|
|
|
int LyXText::cursorY(CursorSlice const & cur) const
|
2003-12-15 11:36:19 +00:00
|
|
|
|
{
|
|
|
|
|
Paragraph & par = *getPar(cur);
|
|
|
|
|
Row & row = *par.getRow(cur.pos());
|
|
|
|
|
return par.y + row.y_offset() + row.baseline();
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-13 10:37:38 +00:00
|
|
|
|
|
2004-01-13 14:13:51 +00:00
|
|
|
|
CursorSlice & LyXText::cursor()
|
2004-01-13 10:37:38 +00:00
|
|
|
|
{
|
2004-01-13 18:08:13 +00:00
|
|
|
|
return bv()->cursor();
|
2004-01-13 10:37:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-13 14:13:51 +00:00
|
|
|
|
CursorSlice const & LyXText::cursor() const
|
2004-01-13 10:37:38 +00:00
|
|
|
|
{
|
2004-01-13 18:08:13 +00:00
|
|
|
|
return bv()->cursor();
|
2004-01-13 10:37:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-13 14:13:51 +00:00
|
|
|
|
CursorSlice & LyXText::anchor()
|
2004-01-13 10:37:38 +00:00
|
|
|
|
{
|
2004-01-13 18:08:13 +00:00
|
|
|
|
return bv()->anchor();
|
2004-01-13 10:37:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-13 14:13:51 +00:00
|
|
|
|
CursorSlice const & LyXText::anchor() const
|
2004-01-13 10:37:38 +00:00
|
|
|
|
{
|
2004-01-13 18:08:13 +00:00
|
|
|
|
return bv()->anchor();
|
2004-01-13 10:37:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-13 15:25:52 +00:00
|
|
|
|
CursorSlice const & LyXText::selStart() const
|
|
|
|
|
{
|
|
|
|
|
if (!selection.set())
|
|
|
|
|
return cursor();
|
|
|
|
|
// can't use std::min as this creates a new object
|
|
|
|
|
return anchor() < cursor() ? anchor() : cursor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CursorSlice const & LyXText::selEnd() const
|
|
|
|
|
{
|
|
|
|
|
if (!selection.set())
|
|
|
|
|
return cursor();
|
|
|
|
|
return anchor() > cursor() ? anchor() : cursor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CursorSlice & LyXText::selStart()
|
|
|
|
|
{
|
|
|
|
|
if (!selection.set())
|
|
|
|
|
return cursor();
|
|
|
|
|
return anchor() < cursor() ? anchor() : cursor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CursorSlice & LyXText::selEnd()
|
|
|
|
|
{
|
|
|
|
|
if (!selection.set())
|
|
|
|
|
return cursor();
|
|
|
|
|
return anchor() > cursor() ? anchor() : cursor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXText::setSelection()
|
|
|
|
|
{
|
|
|
|
|
selection.set(true);
|
|
|
|
|
// a selection with no contents is not a selection
|
|
|
|
|
if (cursor().par() == anchor().par() && cursor().pos() == anchor().pos())
|
|
|
|
|
selection.set(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXText::clearSelection()
|
|
|
|
|
{
|
|
|
|
|
selection.set(false);
|
|
|
|
|
selection.mark(false);
|
2004-01-13 18:08:13 +00:00
|
|
|
|
bv()->resetAnchor();
|
2004-01-13 15:25:52 +00:00
|
|
|
|
// reset this in the bv()!
|
|
|
|
|
if (bv() && bv()->text())
|
|
|
|
|
bv()->unsetXSel();
|
|
|
|
|
}
|
|
|
|
|
|