2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
2003-10-08 11:31:51 +00:00
|
|
|
|
* \file src/text.C
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Asger Alstrup
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
|
* \author John Levon
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
* \author Dekel Tsur
|
|
|
|
|
* \author J<EFBFBD>rgen Vigna
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2001-04-17 15:15:59 +00:00
|
|
|
|
#include "lyxtext.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "buffer.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
#include "bufferparams.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
#include "BufferView.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
|
#include "debug.h"
|
2002-05-24 14:34:32 +00:00
|
|
|
|
#include "encoding.h"
|
2003-09-04 03:54:04 +00:00
|
|
|
|
#include "funcrequest.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
#include "gettext.h"
|
2001-04-05 12:26:41 +00:00
|
|
|
|
#include "language.h"
|
2003-09-16 10:30:59 +00:00
|
|
|
|
#include "LColor.h"
|
2003-09-09 17:00:19 +00:00
|
|
|
|
#include "lyxlength.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
#include "lyxrc.h"
|
|
|
|
|
#include "lyxrow.h"
|
|
|
|
|
#include "lyxrow_funcs.h"
|
2003-10-17 10:31:47 +00:00
|
|
|
|
#include "metricsinfo.h"
|
2003-09-16 12:12:33 +00:00
|
|
|
|
#include "paragraph.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
#include "paragraph_funcs.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "ParagraphParameters.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
#include "rowpainter.h"
|
2003-07-01 11:51:20 +00:00
|
|
|
|
#include "text_funcs.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 bv_funcs::number;
|
2001-11-15 00:39:11 +00:00
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::pos_type;
|
|
|
|
|
using lyx::word_location;
|
|
|
|
|
|
|
|
|
|
using lyx::support::contains;
|
|
|
|
|
using lyx::support::lowercase;
|
|
|
|
|
using lyx::support::uppercase;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2000-01-14 18:41:30 +00:00
|
|
|
|
using std::max;
|
2000-03-28 02:18:55 +00:00
|
|
|
|
using std::endl;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-07-01 11:51:20 +00:00
|
|
|
|
|
2000-01-14 18:41:30 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
/// top, right, bottom pixel margin
|
2003-02-26 17:04:10 +00:00
|
|
|
|
extern int const PAPER_MARGIN = 20;
|
2003-02-08 19:18:01 +00:00
|
|
|
|
/// margin for changebar
|
2003-02-26 17:04:10 +00:00
|
|
|
|
extern int const CHANGEBAR_MARGIN = 10;
|
2003-02-08 19:18:01 +00:00
|
|
|
|
/// left margin
|
2003-02-26 17:04:10 +00:00
|
|
|
|
extern int const LEFT_MARGIN = PAPER_MARGIN + CHANGEBAR_MARGIN;
|
2000-09-26 13:54:57 +00:00
|
|
|
|
|
2003-08-26 10:33:59 +00:00
|
|
|
|
|
|
|
|
|
|
2003-07-28 22:34:48 +00:00
|
|
|
|
int bibitemMaxWidth(BufferView *, LyXFont const &);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-05-05 10:17:05 +00:00
|
|
|
|
|
2003-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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BufferView * LyXText::bv() const
|
|
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(bv_owner != 0);
|
2003-03-17 16:25:00 +00:00
|
|
|
|
return bv_owner;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-04-12 23:03:05 +00:00
|
|
|
|
void LyXText::updateRowPositions()
|
2003-03-06 20:21:21 +00:00
|
|
|
|
{
|
2003-08-15 08:03:54 +00:00
|
|
|
|
ParagraphList::iterator pit = ownerParagraphs().begin();
|
|
|
|
|
ParagraphList::iterator end = ownerParagraphs().end();
|
2003-08-22 16:01:13 +00:00
|
|
|
|
for (height = 0; pit != end; ++pit) {
|
2003-10-16 16:19:56 +00:00
|
|
|
|
pit->y = height;
|
|
|
|
|
height += pit->height;
|
2003-03-06 20:21:21 +00:00
|
|
|
|
}
|
2003-04-12 23:03:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
int LyXText::workWidth() const
|
2000-06-12 11:27:15 +00:00
|
|
|
|
{
|
2003-07-18 12:05:50 +00:00
|
|
|
|
return inset_owner ? inset_owner->textWidth() : bv()->workWidth();
|
2000-06-12 11:27:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-10 21:40:13 +00:00
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
int LyXText::getRealCursorX() const
|
2001-02-19 16:01:31 +00:00
|
|
|
|
{
|
|
|
|
|
int x = cursor.x();
|
2003-10-20 11:41:21 +00:00
|
|
|
|
if (the_locking_inset && the_locking_inset->getLyXText(bv()) != this)
|
2003-03-17 16:25:00 +00:00
|
|
|
|
x = the_locking_inset->getLyXText(bv())->getRealCursorX();
|
2001-02-19 16:01:31 +00:00
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-04-09 21:34:31 +00:00
|
|
|
|
#warning FIXME This function seems to belong outside of LyxText.
|
|
|
|
|
unsigned char LyXText::transformChar(unsigned char c, Paragraph const & par,
|
|
|
|
|
pos_type pos) const
|
2000-03-10 13:22:20 +00:00
|
|
|
|
{
|
2000-10-10 12:36:36 +00:00
|
|
|
|
if (!Encodings::is_arabic(c))
|
2001-12-20 15:11:51 +00:00
|
|
|
|
if (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 && IsDigit(c))
|
2000-04-10 21:40:13 +00:00
|
|
|
|
return c + (0xb0 - '0');
|
|
|
|
|
else
|
|
|
|
|
return c;
|
2000-03-10 13:22:20 +00:00
|
|
|
|
|
2003-04-09 21:34:31 +00:00
|
|
|
|
unsigned char const prev_char = pos > 0 ? par.getChar(pos - 1) : ' ';
|
2000-07-04 20:32:37 +00:00
|
|
|
|
unsigned char next_char = ' ';
|
2001-05-03 14:31:33 +00:00
|
|
|
|
|
2003-04-13 12:56:48 +00:00
|
|
|
|
pos_type const par_size = par.size();
|
|
|
|
|
|
|
|
|
|
for (pos_type i = pos + 1; i < par_size; ++i) {
|
|
|
|
|
unsigned char const par_char = par.getChar(i);
|
|
|
|
|
if (!Encodings::IsComposeChar_arabic(par_char)) {
|
|
|
|
|
next_char = par_char;
|
2000-07-04 20:32:37 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2003-04-13 12:56:48 +00:00
|
|
|
|
}
|
2000-07-04 20:32:37 +00:00
|
|
|
|
|
2000-10-10 12:36:36 +00:00
|
|
|
|
if (Encodings::is_arabic(next_char)) {
|
2002-11-25 21:29:21 +00:00
|
|
|
|
if (Encodings::is_arabic(prev_char) &&
|
|
|
|
|
!Encodings::is_arabic_special(prev_char))
|
2000-10-10 12:36:36 +00:00
|
|
|
|
return Encodings::TransformChar(c, Encodings::FORM_MEDIAL);
|
2000-03-10 13:22:20 +00:00
|
|
|
|
else
|
2000-10-10 12:36:36 +00:00
|
|
|
|
return Encodings::TransformChar(c, Encodings::FORM_INITIAL);
|
2000-09-26 13:54:57 +00:00
|
|
|
|
} else {
|
2002-11-25 21:29:21 +00:00
|
|
|
|
if (Encodings::is_arabic(prev_char) &&
|
|
|
|
|
!Encodings::is_arabic_special(prev_char))
|
2000-10-10 12:36:36 +00:00
|
|
|
|
return Encodings::TransformChar(c, Encodings::FORM_FINAL);
|
2000-03-10 13:22:20 +00:00
|
|
|
|
else
|
2000-10-10 12:36:36 +00:00
|
|
|
|
return Encodings::TransformChar(c, Encodings::FORM_ISOLATED);
|
2000-09-26 13:54:57 +00:00
|
|
|
|
}
|
2000-03-10 13:22:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-08 01:45:25 +00:00
|
|
|
|
// This is the comments that some of the warnings below refers to.
|
|
|
|
|
// There are some issues in this file and I don't think they are
|
|
|
|
|
// really related to the FIX_DOUBLE_SPACE patch. I'd rather think that
|
|
|
|
|
// this is a problem that has been here almost from day one and that a
|
2003-10-20 11:41:21 +00:00
|
|
|
|
// larger userbase with different access patters triggers the bad
|
2000-03-08 01:45:25 +00:00
|
|
|
|
// behaviour. (segfaults.) What I think happen is: In several places
|
|
|
|
|
// we store the paragraph in the current cursor and then moves the
|
|
|
|
|
// cursor. This movement of the cursor will delete paragraph at the
|
|
|
|
|
// old position if it is now empty. This will make the temporary
|
|
|
|
|
// pointer to the old cursor paragraph invalid and dangerous to use.
|
|
|
|
|
// And is some cases this will trigger a segfault. I have marked some
|
|
|
|
|
// of the cases where this happens with a warning, but I am sure there
|
|
|
|
|
// are others in this file and in text2.C. There is also a note in
|
|
|
|
|
// Delete() that you should read. In Delete I store the paragraph->id
|
|
|
|
|
// instead of a pointer to the paragraph. I am pretty sure this faulty
|
|
|
|
|
// use of temporary pointers to paragraphs that might have gotten
|
|
|
|
|
// invalidated (through a cursor movement) before they are used, are
|
|
|
|
|
// the cause of the strange crashes we get reported often.
|
|
|
|
|
//
|
|
|
|
|
// It is very tiresom to change this code, especially when it is as
|
|
|
|
|
// hard to read as it is. Help to fix all the cases where this is done
|
|
|
|
|
// would be greately appreciated.
|
|
|
|
|
//
|
|
|
|
|
// Lgb
|
|
|
|
|
|
2003-04-09 21:34:31 +00:00
|
|
|
|
int LyXText::singleWidth(ParagraphList::iterator pit, pos_type pos) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-04-09 21:34:31 +00:00
|
|
|
|
if (pos >= pit->size())
|
2003-03-13 10:30:28 +00:00
|
|
|
|
return 0;
|
|
|
|
|
|
2003-04-09 21:34:31 +00:00
|
|
|
|
char const c = pit->getChar(pos);
|
2003-08-22 07:49:57 +00:00
|
|
|
|
LyXFont const & font = getFont(pit, pos);
|
|
|
|
|
return singleWidth(pit, pos, c, font);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-04-09 21:34:31 +00:00
|
|
|
|
int LyXText::singleWidth(ParagraphList::iterator pit,
|
2003-08-22 07:49:57 +00:00
|
|
|
|
pos_type pos, char c, LyXFont const & font) const
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
2003-08-22 07:49:57 +00:00
|
|
|
|
if (pos >= pit->size()) {
|
|
|
|
|
lyxerr << "in singleWidth(), pos: " << pos << endl;
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(false);
|
2003-03-13 10:30:28 +00:00
|
|
|
|
return 0;
|
2003-08-22 07:49:57 +00:00
|
|
|
|
}
|
2003-03-13 10:30:28 +00:00
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
|
|
|
|
|
|
// The most common case is handled first (Asger)
|
|
|
|
|
if (IsPrintable(c)) {
|
2003-10-21 16:15:14 +00:00
|
|
|
|
if (!font.language()->RightToLeft()) {
|
2003-07-27 00:37:17 +00:00
|
|
|
|
if ((lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
|
|
|
|
|
lyxrc.font_norm_type == LyXRC::ISO_10646_1)
|
|
|
|
|
&& font.language()->lang() == "arabic") {
|
2000-10-10 12:36:36 +00:00
|
|
|
|
if (Encodings::IsComposeChar_arabic(c))
|
2000-07-04 20:32:37 +00:00
|
|
|
|
return 0;
|
|
|
|
|
else
|
2003-04-09 21:34:31 +00:00
|
|
|
|
c = transformChar(c, *pit, 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (c == Paragraph::META_INSET) {
|
2003-07-25 21:20:24 +00:00
|
|
|
|
InsetOld * tmpinset = pit->getInset(pos);
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(tmpinset);
|
2003-08-15 15:20:50 +00:00
|
|
|
|
if (tmpinset->lyxCode() == InsetOld::HFILL_CODE) {
|
|
|
|
|
// Because of the representation as vertical lines
|
|
|
|
|
return 3;
|
2003-03-11 15:01:29 +00:00
|
|
|
|
}
|
2003-08-15 15:20:50 +00:00
|
|
|
|
return tmpinset->width();
|
2003-03-11 15:01:29 +00:00
|
|
|
|
}
|
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-03-26 16:15:02 +00:00
|
|
|
|
lyx::pos_type LyXText::log2vis(lyx::pos_type pos) const
|
2003-03-21 23:53:26 +00:00
|
|
|
|
{
|
2003-10-21 16:15:14 +00:00
|
|
|
|
return (bidi_start == -1) ? pos : log2vis_list[pos - bidi_start];
|
2003-03-21 23:53:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-26 16:15:02 +00:00
|
|
|
|
lyx::pos_type LyXText::vis2log(lyx::pos_type pos) const
|
2003-03-21 23:53:26 +00:00
|
|
|
|
{
|
2003-10-21 16:15:14 +00:00
|
|
|
|
return (bidi_start == -1) ? pos : vis2log_list[pos - bidi_start];
|
2003-03-21 23:53:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-26 16:15:02 +00:00
|
|
|
|
lyx::pos_type LyXText::bidi_level(lyx::pos_type pos) const
|
2003-03-21 23:53:26 +00:00
|
|
|
|
{
|
2003-10-21 16:15:14 +00:00
|
|
|
|
return (bidi_start == -1) ? 0 : bidi_levels[pos - bidi_start];
|
2003-03-21 23:53:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-26 16:15:02 +00:00
|
|
|
|
bool LyXText::bidi_InRange(lyx::pos_type pos) const
|
2003-03-21 23:53:26 +00:00
|
|
|
|
{
|
2003-10-21 16:15:14 +00:00
|
|
|
|
return bidi_start == -1 || (bidi_start <= pos && pos <= bidi_end);
|
2003-03-21 23:53:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-17 10:31:47 +00:00
|
|
|
|
void LyXText::computeBidiTables(Paragraph const & par,
|
|
|
|
|
Buffer const & buf, Row & row) const
|
2000-02-04 09:38:32 +00:00
|
|
|
|
{
|
2000-04-03 11:36:35 +00:00
|
|
|
|
bidi_same_direction = true;
|
2000-03-12 10:35:05 +00:00
|
|
|
|
if (!lyxrc.rtl_support) {
|
2000-02-03 19:51:27 +00:00
|
|
|
|
bidi_start = -1;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2000-06-08 23:16:16 +00:00
|
|
|
|
|
2003-10-17 10:31:47 +00:00
|
|
|
|
InsetOld * inset = par.inInset();
|
2002-05-05 16:33:19 +00:00
|
|
|
|
if (inset && inset->owner() &&
|
2003-07-25 21:20:24 +00:00
|
|
|
|
inset->owner()->lyxCode() == InsetOld::ERT_CODE) {
|
2002-05-05 16:33:19 +00:00
|
|
|
|
bidi_start = -1;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2003-10-17 10:31:47 +00:00
|
|
|
|
bidi_start = row.pos();
|
|
|
|
|
bidi_end = lastPos(par, row);
|
2000-02-03 19:51:27 +00:00
|
|
|
|
|
2000-05-30 19:31:11 +00:00
|
|
|
|
if (bidi_start > bidi_end) {
|
2000-02-03 19:51:27 +00:00
|
|
|
|
bidi_start = -1;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2000-05-30 19:31:11 +00:00
|
|
|
|
if (bidi_end + 2 - bidi_start >
|
2001-11-26 16:42:04 +00:00
|
|
|
|
static_cast<pos_type>(log2vis_list.size())) {
|
2002-03-21 17:27:08 +00:00
|
|
|
|
pos_type new_size =
|
2000-05-30 19:31:11 +00:00
|
|
|
|
(bidi_end + 2 - bidi_start < 500) ?
|
|
|
|
|
500 : 2 * (bidi_end + 2 - bidi_start);
|
2000-02-03 19:51:27 +00:00
|
|
|
|
log2vis_list.resize(new_size);
|
|
|
|
|
vis2log_list.resize(new_size);
|
2000-04-10 21:40:13 +00:00
|
|
|
|
bidi_levels.resize(new_size);
|
2000-02-03 19:51:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-05-30 19:31:11 +00:00
|
|
|
|
vis2log_list[bidi_end + 1 - bidi_start] = -1;
|
|
|
|
|
log2vis_list[bidi_end + 1 - bidi_start] = -1;
|
2000-02-03 19:51:27 +00:00
|
|
|
|
|
2003-09-09 09:47:59 +00:00
|
|
|
|
BufferParams const & bufparams = buf.params();
|
2001-11-26 16:42:04 +00:00
|
|
|
|
pos_type stack[2];
|
2003-10-17 10:31:47 +00:00
|
|
|
|
bool const rtl_par = par.isRightToLeftPar(bufparams);
|
2000-04-10 21:40:13 +00:00
|
|
|
|
int level = 0;
|
|
|
|
|
bool rtl = false;
|
|
|
|
|
bool rtl0 = false;
|
2003-10-17 10:31:47 +00:00
|
|
|
|
pos_type const body_pos = par.beginningOfBody();
|
2000-02-03 19:51:27 +00:00
|
|
|
|
|
2002-05-29 13:28:11 +00:00
|
|
|
|
for (pos_type lpos = bidi_start; lpos <= bidi_end; ++lpos) {
|
2003-10-17 10:31:47 +00:00
|
|
|
|
bool is_space = par.isLineSeparator(lpos);
|
2001-11-26 16:42:04 +00:00
|
|
|
|
pos_type const pos =
|
2000-06-08 23:16:16 +00:00
|
|
|
|
(is_space && lpos + 1 <= bidi_end &&
|
2003-10-17 10:31:47 +00:00
|
|
|
|
!par.isLineSeparator(lpos + 1) &&
|
|
|
|
|
!par.isNewline(lpos + 1))
|
2000-04-10 21:40:13 +00:00
|
|
|
|
? lpos + 1 : lpos;
|
2003-10-17 10:31:47 +00:00
|
|
|
|
LyXFont font = par.getFontSettings(bufparams, pos);
|
2000-10-09 12:30:52 +00:00
|
|
|
|
if (pos != lpos && 0 < lpos && rtl0 && font.isRightToLeft() &&
|
|
|
|
|
font.number() == LyXFont::ON &&
|
2003-10-17 10:31:47 +00:00
|
|
|
|
par.getFontSettings(bufparams, lpos - 1).number()
|
2000-10-09 12:30:52 +00:00
|
|
|
|
== LyXFont::ON) {
|
2003-10-17 10:31:47 +00:00
|
|
|
|
font = par.getFontSettings(bufparams, lpos);
|
2000-10-09 12:30:52 +00:00
|
|
|
|
is_space = false;
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-10 21:40:13 +00:00
|
|
|
|
bool new_rtl = font.isVisibleRightToLeft();
|
|
|
|
|
bool new_rtl0 = font.isRightToLeft();
|
|
|
|
|
int new_level;
|
|
|
|
|
|
2003-03-09 12:37:22 +00:00
|
|
|
|
if (lpos == body_pos - 1
|
2003-10-17 10:31:47 +00:00
|
|
|
|
&& row.pos() < body_pos - 1
|
2000-10-09 12:30:52 +00:00
|
|
|
|
&& is_space) {
|
2003-10-17 10:31:47 +00:00
|
|
|
|
new_level = rtl_par ? 1 : 0;
|
|
|
|
|
new_rtl0 = rtl_par;
|
|
|
|
|
new_rtl = rtl_par;
|
2000-04-10 21:40:13 +00:00
|
|
|
|
} else if (new_rtl0)
|
2003-10-17 10:31:47 +00:00
|
|
|
|
new_level = new_rtl ? 1 : 2;
|
2000-04-10 21:40:13 +00:00
|
|
|
|
else
|
2003-10-17 10:31:47 +00:00
|
|
|
|
new_level = rtl_par ? 2 : 0;
|
2000-02-03 19:51:27 +00:00
|
|
|
|
|
2000-04-10 21:40:13 +00:00
|
|
|
|
if (is_space && new_level >= level) {
|
|
|
|
|
new_level = level;
|
|
|
|
|
new_rtl = rtl;
|
|
|
|
|
new_rtl0 = rtl0;
|
|
|
|
|
}
|
2000-02-03 19:51:27 +00:00
|
|
|
|
|
2000-04-10 21:40:13 +00:00
|
|
|
|
int new_level2 = new_level;
|
|
|
|
|
|
|
|
|
|
if (level == new_level && rtl0 != new_rtl0) {
|
|
|
|
|
--new_level2;
|
2003-10-17 10:31:47 +00:00
|
|
|
|
log2vis_list[lpos - bidi_start] = rtl ? 1 : -1;
|
2000-04-10 21:40:13 +00:00
|
|
|
|
} else if (level < new_level) {
|
2003-10-17 10:31:47 +00:00
|
|
|
|
log2vis_list[lpos - bidi_start] = rtl ? -1 : 1;
|
2000-04-10 21:40:13 +00:00
|
|
|
|
if (new_level > rtl_par)
|
|
|
|
|
bidi_same_direction = false;
|
|
|
|
|
} else
|
2003-10-17 10:31:47 +00:00
|
|
|
|
log2vis_list[lpos - bidi_start] = new_rtl ? -1 : 1;
|
2000-04-10 21:40:13 +00:00
|
|
|
|
rtl = new_rtl;
|
|
|
|
|
rtl0 = new_rtl0;
|
|
|
|
|
bidi_levels[lpos - bidi_start] = new_level;
|
|
|
|
|
|
|
|
|
|
while (level > new_level2) {
|
2001-11-26 16:42:04 +00:00
|
|
|
|
pos_type old_lpos = stack[--level];
|
2000-04-10 21:40:13 +00:00
|
|
|
|
int delta = lpos - old_lpos - 1;
|
|
|
|
|
if (level % 2)
|
|
|
|
|
delta = -delta;
|
|
|
|
|
log2vis_list[lpos - bidi_start] += delta;
|
|
|
|
|
log2vis_list[old_lpos - bidi_start] += delta;
|
2000-02-03 19:51:27 +00:00
|
|
|
|
}
|
2000-04-10 21:40:13 +00:00
|
|
|
|
while (level < new_level)
|
|
|
|
|
stack[level++] = lpos;
|
2000-02-03 19:51:27 +00:00
|
|
|
|
}
|
1999-11-15 12:01:38 +00:00
|
|
|
|
|
2000-02-03 19:51:27 +00:00
|
|
|
|
while (level > 0) {
|
2001-11-26 16:42:04 +00:00
|
|
|
|
pos_type const old_lpos = stack[--level];
|
2000-05-30 19:31:11 +00:00
|
|
|
|
int delta = bidi_end - old_lpos;
|
2000-04-10 21:40:13 +00:00
|
|
|
|
if (level % 2)
|
|
|
|
|
delta = -delta;
|
|
|
|
|
log2vis_list[old_lpos - bidi_start] += delta;
|
2000-02-03 19:51:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-26 16:42:04 +00:00
|
|
|
|
pos_type vpos = bidi_start - 1;
|
|
|
|
|
for (pos_type lpos = bidi_start;
|
2000-08-03 21:17:52 +00:00
|
|
|
|
lpos <= bidi_end; ++lpos) {
|
2000-02-04 09:38:32 +00:00
|
|
|
|
vpos += log2vis_list[lpos - bidi_start];
|
|
|
|
|
vis2log_list[vpos - bidi_start] = lpos;
|
|
|
|
|
log2vis_list[lpos - bidi_start] = vpos;
|
2000-02-03 19:51:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
2000-05-30 19:31:11 +00:00
|
|
|
|
// This method requires a previous call to ComputeBidiTables()
|
2003-08-28 07:41:31 +00:00
|
|
|
|
bool LyXText::isBoundary(Buffer const & buf, Paragraph const & par,
|
2001-11-26 16:42:04 +00:00
|
|
|
|
pos_type pos) const
|
2000-05-30 19:31:11 +00:00
|
|
|
|
{
|
2000-12-10 05:20:36 +00:00
|
|
|
|
if (!lyxrc.rtl_support || pos == 0)
|
|
|
|
|
return false;
|
2000-05-30 19:31:11 +00:00
|
|
|
|
|
2000-12-05 14:15:44 +00:00
|
|
|
|
if (!bidi_InRange(pos - 1)) {
|
2003-10-21 16:15:14 +00:00
|
|
|
|
// This can happen if pos is the first char of a row.
|
|
|
|
|
// Returning false in this case is incorrect!
|
2000-05-30 19:31:11 +00:00
|
|
|
|
return false;
|
2000-12-05 14:15:44 +00:00
|
|
|
|
}
|
2000-05-30 19:31:11 +00:00
|
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
|
bool const rtl = bidi_level(pos - 1) % 2;
|
2001-04-04 21:23:36 +00:00
|
|
|
|
bool const rtl2 = bidi_InRange(pos)
|
2000-12-05 14:15:44 +00:00
|
|
|
|
? bidi_level(pos) % 2
|
2003-09-09 09:47:59 +00:00
|
|
|
|
: par.isRightToLeftPar(buf.params());
|
2000-05-30 19:31:11 +00:00
|
|
|
|
return rtl != rtl2;
|
|
|
|
|
}
|
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
bool LyXText::isBoundary(Buffer const & buf, Paragraph const & par,
|
2001-11-26 16:42:04 +00:00
|
|
|
|
pos_type pos, LyXFont const & font) const
|
2000-05-30 19:31:11 +00:00
|
|
|
|
{
|
|
|
|
|
if (!lyxrc.rtl_support)
|
|
|
|
|
return false; // This is just for speedup
|
|
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
|
bool const rtl = font.isVisibleRightToLeft();
|
2001-04-04 21:23:36 +00:00
|
|
|
|
bool const rtl2 = bidi_InRange(pos)
|
2000-12-05 14:15:44 +00:00
|
|
|
|
? bidi_level(pos) % 2
|
2003-09-09 09:47:59 +00:00
|
|
|
|
: par.isRightToLeftPar(buf.params());
|
2000-05-30 19:31:11 +00:00
|
|
|
|
return rtl != rtl2;
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-29 13:28:11 +00:00
|
|
|
|
|
2003-08-14 08:34:13 +00:00
|
|
|
|
int LyXText::leftMargin(ParagraphList::iterator pit, Row const & row) const
|
2003-08-26 10:33:59 +00:00
|
|
|
|
{
|
2001-10-16 14:47:10 +00:00
|
|
|
|
LyXTextClass const & tclass =
|
2003-09-09 09:47:59 +00:00
|
|
|
|
bv()->buffer()->params().getLyXTextClass();
|
2003-08-14 08:34:13 +00:00
|
|
|
|
LyXLayout_ptr const & layout = pit->layout();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
string parindent = layout->parindent;
|
2000-06-08 23:16:16 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
int x = LEFT_MARGIN;
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2002-05-24 14:34:32 +00:00
|
|
|
|
x += font_metrics::signedWidth(tclass.leftmargin(), tclass.defaultfont());
|
2001-05-03 14:31:33 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// this is the way, LyX handles the LaTeX-Environments.
|
|
|
|
|
// I have had this idea very late, so it seems to be a
|
|
|
|
|
// later added hack and this is true
|
2003-08-14 08:34:13 +00:00
|
|
|
|
if (!pit->getDepth()) {
|
|
|
|
|
if (pit->layout() == tclass.defaultLayout()) {
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// find the previous same level paragraph
|
2003-08-14 08:34:13 +00:00
|
|
|
|
if (pit != ownerParagraphs().begin()) {
|
2003-04-16 08:12:22 +00:00
|
|
|
|
ParagraphList::iterator newpit =
|
2003-08-14 08:34:13 +00:00
|
|
|
|
depthHook(pit, ownerParagraphs(),
|
|
|
|
|
pit->getDepth());
|
|
|
|
|
if (newpit == pit &&
|
2003-04-16 08:12:22 +00:00
|
|
|
|
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
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-08-14 08:34:13 +00:00
|
|
|
|
ParagraphList::iterator newpar = outerHook(pit,
|
2003-04-16 08:12:22 +00:00
|
|
|
|
ownerParagraphs());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-07 20:32:29 +00:00
|
|
|
|
// make a corresponding row. Needed to call leftMargin()
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-03-02 16:39:54 +00:00
|
|
|
|
// check wether it is a sufficent paragraph
|
2003-04-16 08:12:22 +00:00
|
|
|
|
if (newpar != ownerParagraphs().end() &&
|
|
|
|
|
newpar->layout()->isEnvironment()) {
|
2003-08-14 08:34:13 +00:00
|
|
|
|
x = leftMargin(newpar, Row(newpar->size()));
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2002-03-02 16:39:54 +00:00
|
|
|
|
|
2003-04-16 08:12:22 +00:00
|
|
|
|
if (newpar != ownerParagraphs().end() &&
|
2003-08-14 08:34:13 +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();
|
2002-06-24 20:28:12 +00:00
|
|
|
|
else {
|
|
|
|
|
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:
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (!layout->leftmargin.empty()) {
|
|
|
|
|
x += font_metrics::signedWidth(layout->leftmargin,
|
2001-10-16 14:47:10 +00:00
|
|
|
|
tclass.defaultfont());
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
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;
|
|
|
|
|
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-08-14 08:34:13 +00:00
|
|
|
|
if (!pit->empty() && row.pos() >= pit->beginningOfBody()) {
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
case MARGIN_FIRST_DYNAMIC:
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (layout->labeltype == LABEL_MANUAL) {
|
2003-08-14 08:34:13 +00:00
|
|
|
|
if (row.pos() >= pit->beginningOfBody()) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
x += font_metrics::signedWidth(layout->leftmargin,
|
2000-06-08 23:16:16 +00:00
|
|
|
|
labelfont);
|
2000-01-13 16:28:54 +00:00
|
|
|
|
} else {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
x += font_metrics::signedWidth(layout->labelindent,
|
2000-06-08 23:16:16 +00:00
|
|
|
|
labelfont);
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2003-04-01 16:55:48 +00:00
|
|
|
|
} else if (row.pos()
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// Special case to fix problems with
|
|
|
|
|
// theorems (JMarc)
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|| (layout->labeltype == LABEL_STATIC
|
|
|
|
|
&& layout->latextype == LATEX_ENVIRONMENT
|
2003-08-14 08:34:13 +00:00
|
|
|
|
&& !isFirstInSequence(pit, ownerParagraphs()))) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
x += font_metrics::signedWidth(layout->leftmargin,
|
2000-06-08 23:16:16 +00:00
|
|
|
|
labelfont);
|
2002-06-24 20:28:12 +00:00
|
|
|
|
} else if (layout->labeltype != LABEL_TOP_ENVIRONMENT
|
|
|
|
|
&& layout->labeltype != LABEL_BIBLIO
|
|
|
|
|
&& layout->labeltype !=
|
2000-01-13 16:28:54 +00:00
|
|
|
|
LABEL_CENTERED_TOP_ENVIRONMENT) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
x += font_metrics::signedWidth(layout->labelindent,
|
2000-04-04 00:19:15 +00:00
|
|
|
|
labelfont);
|
2002-06-24 20:28:12 +00:00
|
|
|
|
x += font_metrics::width(layout->labelsep, labelfont);
|
2003-08-14 08:34:13 +00:00
|
|
|
|
x += font_metrics::width(pit->getLabelstring(),
|
2000-06-08 23:16:16 +00:00
|
|
|
|
labelfont);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
}
|
2000-01-13 16:28:54 +00:00
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
case MARGIN_RIGHT_ADDRESS_BOX:
|
|
|
|
|
{
|
|
|
|
|
// 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-08-14 09:59:05 +00:00
|
|
|
|
int minfill = rit->fill();
|
|
|
|
|
for ( ; rit != end; ++rit)
|
|
|
|
|
if (rit->fill() < minfill)
|
|
|
|
|
minfill = rit->fill();
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
|
|
|
|
x += font_metrics::signedWidth(layout->leftmargin,
|
2002-05-24 14:34:32 +00:00
|
|
|
|
tclass.defaultfont());
|
2000-01-13 16:28:54 +00:00
|
|
|
|
x += minfill;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-08-14 08:34:13 +00:00
|
|
|
|
if (workWidth() > 0 && !pit->params().leftIndent().zero()) {
|
|
|
|
|
LyXLength const len = pit->params().leftIndent();
|
2002-05-08 12:58:16 +00:00
|
|
|
|
int const tw = inset_owner ?
|
2003-03-17 16:25:00 +00:00
|
|
|
|
inset_owner->latexTextWidth(bv()) : workWidth();
|
2002-10-24 18:31:47 +00:00
|
|
|
|
x += len.inPixels(tw);
|
2002-05-08 12:58:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-04-13 01:04:04 +00:00
|
|
|
|
LyXAlignment align;
|
2001-05-03 14:31:33 +00:00
|
|
|
|
|
2003-08-14 08:34:13 +00:00
|
|
|
|
if (pit->params().align() == LYX_ALIGN_LAYOUT)
|
2002-06-24 20:28:12 +00:00
|
|
|
|
align = layout->align;
|
2000-07-19 17:16:27 +00:00
|
|
|
|
else
|
2003-08-14 08:34:13 +00:00
|
|
|
|
align = pit->params().align();
|
2001-05-03 14:31:33 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// set the correct parindent
|
2003-04-01 16:55:48 +00:00
|
|
|
|
if (row.pos() == 0) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if ((layout->labeltype == LABEL_NO_LABEL
|
|
|
|
|
|| layout->labeltype == LABEL_TOP_ENVIRONMENT
|
|
|
|
|
|| layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
|
|
|
|
|
|| (layout->labeltype == LABEL_STATIC
|
|
|
|
|
&& layout->latextype == LATEX_ENVIRONMENT
|
2003-08-14 08:34:13 +00:00
|
|
|
|
&& !isFirstInSequence(pit, ownerParagraphs())))
|
2000-01-13 16:28:54 +00:00
|
|
|
|
&& align == LYX_ALIGN_BLOCK
|
2003-08-14 08:34:13 +00:00
|
|
|
|
&& !pit->params().noindent()
|
2002-03-06 10:17:29 +00:00
|
|
|
|
// in tabulars and ert paragraphs are never indented!
|
2003-08-14 08:34:13 +00:00
|
|
|
|
&& (!pit->inInset() || !pit->inInset()->owner() ||
|
|
|
|
|
(pit->inInset()->owner()->lyxCode() != InsetOld::TABULAR_CODE &&
|
|
|
|
|
pit->inInset()->owner()->lyxCode() != InsetOld::ERT_CODE))
|
|
|
|
|
&& (pit->layout() != tclass.defaultLayout() ||
|
2003-09-09 09:47:59 +00:00
|
|
|
|
bv()->buffer()->params().paragraph_separation ==
|
2002-03-02 16:39:54 +00:00
|
|
|
|
BufferParams::PARSEP_INDENT)) {
|
2002-05-24 14:34:32 +00:00
|
|
|
|
x += font_metrics::signedWidth(parindent,
|
2001-10-16 14:47:10 +00:00
|
|
|
|
tclass.defaultfont());
|
2002-06-24 20:28:12 +00:00
|
|
|
|
} else if (layout->labeltype == LABEL_BIBLIO) {
|
2001-07-20 14:18:48 +00:00
|
|
|
|
// ale970405 Right width for bibitems
|
2003-03-17 16:25:00 +00:00
|
|
|
|
x += bibitemMaxWidth(bv(), tclass.defaultfont());
|
2000-02-17 19:59:08 +00:00
|
|
|
|
}
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
return x;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-04-26 13:57:28 +00:00
|
|
|
|
|
|
|
|
|
|
2003-10-17 10:31:47 +00:00
|
|
|
|
int LyXText::rightMargin(Paragraph const & par,
|
2003-08-28 07:41:31 +00:00
|
|
|
|
Buffer const & buf, Row const &) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-09-09 09:47:59 +00:00
|
|
|
|
LyXTextClass const & tclass = buf.params().getLyXTextClass();
|
2003-10-17 10:31:47 +00:00
|
|
|
|
LyXLayout_ptr const & layout = par.layout();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-07-29 01:46:09 +00:00
|
|
|
|
return PAPER_MARGIN
|
2002-05-24 14:34:32 +00:00
|
|
|
|
+ font_metrics::signedWidth(tclass.rightmargin(),
|
2003-10-20 13:55:51 +00:00
|
|
|
|
tclass.defaultfont())
|
2003-07-29 01:46:09 +00:00
|
|
|
|
+ font_metrics::signedWidth(layout->rightmargin,
|
2002-06-24 20:28:12 +00:00
|
|
|
|
tclass.defaultfont())
|
2003-10-17 10:31:47 +00:00
|
|
|
|
* 4 / (par.getDepth() + 4);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-14 08:34:13 +00:00
|
|
|
|
int LyXText::labelEnd(ParagraphList::iterator pit, Row const & row) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-08-14 08:34:13 +00:00
|
|
|
|
if (pit->layout()->margintype == MARGIN_MANUAL) {
|
2003-02-26 17:04:10 +00:00
|
|
|
|
Row tmprow = row;
|
2003-08-14 08:34:13 +00:00
|
|
|
|
tmprow.pos(pit->size());
|
2003-03-09 12:37:22 +00:00
|
|
|
|
// return the beginning of the body
|
2003-08-14 08:34:13 +00:00
|
|
|
|
return leftMargin(pit, tmprow);
|
2002-05-29 12:58:23 +00:00
|
|
|
|
}
|
2003-02-26 17:04:10 +00:00
|
|
|
|
|
|
|
|
|
// LabelEnd is only needed if the layout
|
|
|
|
|
// fills a flushleft label.
|
|
|
|
|
return 0;
|
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-17 10:31:47 +00:00
|
|
|
|
for (; i < par.size(); ++i)
|
2003-04-13 01:04:04 +00:00
|
|
|
|
if (par.isNewline(i))
|
2003-03-09 21:54:56 +00:00
|
|
|
|
return i;
|
|
|
|
|
|
2003-04-13 01:04:04 +00:00
|
|
|
|
return par.size();
|
2003-03-09 21:54:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2003-08-14 08:34:13 +00:00
|
|
|
|
pos_type LyXText::rowBreakPoint(ParagraphList::iterator pit,
|
|
|
|
|
Row const & row) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-03-09 21:54:56 +00:00
|
|
|
|
// maximum pixel width of a row.
|
2003-10-17 10:31:47 +00:00
|
|
|
|
int width = workWidth() - rightMargin(*pit, *bv()->buffer(), row);
|
2003-03-09 21:54:56 +00:00
|
|
|
|
|
|
|
|
|
// inset->textWidth() returns -1 via workWidth(),
|
|
|
|
|
// but why ?
|
2000-06-12 11:27:15 +00:00
|
|
|
|
if (width < 0)
|
2003-04-02 23:01:39 +00:00
|
|
|
|
return pit->size();
|
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-03-09 21:54:56 +00:00
|
|
|
|
if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX)
|
2003-04-13 01:04:04 +00:00
|
|
|
|
return addressBreakPoint(row.pos(), *pit);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-03-09 21:54:56 +00:00
|
|
|
|
pos_type const pos = row.pos();
|
2003-04-02 23:01:39 +00:00
|
|
|
|
pos_type const body_pos = pit->beginningOfBody();
|
|
|
|
|
pos_type const last = pit->size();
|
2003-03-09 21:54:56 +00:00
|
|
|
|
pos_type point = last;
|
2003-03-13 10:30:28 +00:00
|
|
|
|
|
|
|
|
|
if (pos == last)
|
|
|
|
|
return last;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-03-09 21:54:56 +00:00
|
|
|
|
// Now we iterate through until we reach the right margin
|
|
|
|
|
// or the end of the par, then choose the possible break
|
|
|
|
|
// nearest that.
|
|
|
|
|
|
2003-08-14 08:34:13 +00:00
|
|
|
|
int const left = leftMargin(pit, row);
|
2003-03-10 04:59:48 +00:00
|
|
|
|
int x = left;
|
|
|
|
|
|
|
|
|
|
// pixel width since last breakpoint
|
|
|
|
|
int chunkwidth = 0;
|
2003-03-09 21:54:56 +00:00
|
|
|
|
|
2003-03-13 10:30:28 +00:00
|
|
|
|
pos_type i = pos;
|
2003-07-27 11:16:25 +00:00
|
|
|
|
|
|
|
|
|
// We re-use the font resolution for the entire font span when possible
|
2003-07-27 21:59:06 +00:00
|
|
|
|
LyXFont font = getFont(pit, i);
|
2003-07-27 11:16:25 +00:00
|
|
|
|
lyx::pos_type endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
|
|
|
|
|
|
2003-03-13 10:30:28 +00:00
|
|
|
|
for (; i < last; ++i) {
|
2003-04-02 23:01:39 +00:00
|
|
|
|
if (pit->isNewline(i)) {
|
2003-03-09 21:54:56 +00:00
|
|
|
|
point = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2003-10-20 18:56:48 +00:00
|
|
|
|
// Break before...
|
|
|
|
|
if (i + 1 < last) {
|
2003-10-21 13:04:14 +00:00
|
|
|
|
InsetOld * in = pit->getInset(i + 1);
|
2003-10-20 18:56:48 +00:00
|
|
|
|
if (in && in->display()) {
|
|
|
|
|
point = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// ...and after.
|
|
|
|
|
in = pit->getInset(i);
|
|
|
|
|
if (in && in->display()) {
|
|
|
|
|
point = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-03-09 21:54:56 +00:00
|
|
|
|
|
2003-04-02 23:01:39 +00:00
|
|
|
|
char const c = pit->getChar(i);
|
2003-08-22 09:40:56 +00:00
|
|
|
|
if (i > endPosOfFontSpan) {
|
|
|
|
|
font = getFont(pit, i);
|
|
|
|
|
endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
|
|
|
|
|
}
|
2003-03-12 19:16:42 +00:00
|
|
|
|
|
2003-04-11 03:28:06 +00:00
|
|
|
|
int thiswidth;
|
2003-03-09 21:54:56 +00:00
|
|
|
|
|
|
|
|
|
// add the auto-hfill from label end to the body
|
2003-03-10 01:46:40 +00:00
|
|
|
|
if (body_pos && i == body_pos) {
|
2003-07-27 21:59:06 +00:00
|
|
|
|
thiswidth = font_metrics::width(layout->labelsep, getLabelFont(pit));
|
2003-04-02 23:01:39 +00:00
|
|
|
|
if (pit->isLineSeparator(i - 1))
|
2003-04-09 21:34:31 +00:00
|
|
|
|
thiswidth -= singleWidth(pit, i - 1);
|
2003-08-14 08:34:13 +00:00
|
|
|
|
int left_margin = labelEnd(pit, row);
|
2003-04-11 03:28:06 +00:00
|
|
|
|
if (thiswidth + x < left_margin)
|
|
|
|
|
thiswidth = left_margin - x;
|
2003-08-22 07:49:57 +00:00
|
|
|
|
thiswidth += singleWidth(pit, i, c, font);
|
2003-04-11 03:28:06 +00:00
|
|
|
|
} else {
|
2003-08-22 07:49:57 +00:00
|
|
|
|
thiswidth = singleWidth(pit, i, c, font);
|
2003-03-09 21:54:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-03-10 04:59:48 +00:00
|
|
|
|
x += thiswidth;
|
|
|
|
|
chunkwidth += thiswidth;
|
|
|
|
|
|
2003-10-21 13:04:14 +00:00
|
|
|
|
InsetOld * in = pit->getInset(i);
|
2003-03-10 01:46:40 +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-21 13:04:14 +00:00
|
|
|
|
if (point == last || chunkwidth >= width - left) {
|
|
|
|
|
if (pos < i) {
|
|
|
|
|
point = i - 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2003-03-09 21:54:56 +00:00
|
|
|
|
|
|
|
|
|
if (!in || in->isChar()) {
|
|
|
|
|
// some insets are line separators too
|
2003-04-02 23:01:39 +00:00
|
|
|
|
if (pit->isLineSeparator(i)) {
|
2003-03-09 21:54:56 +00:00
|
|
|
|
point = i;
|
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-03-10 01:46:40 +00:00
|
|
|
|
if (point == last && x >= width) {
|
|
|
|
|
// didn't find one, break at the point we reached the edge
|
2003-03-09 21:54:56 +00:00
|
|
|
|
point = i;
|
2003-03-10 01:46:40 +00:00
|
|
|
|
} else if (i == last && x < width) {
|
|
|
|
|
// found one, but we fell off the end of the par, so prefer
|
|
|
|
|
// that.
|
|
|
|
|
point = last;
|
|
|
|
|
}
|
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-03-09 21:54:56 +00:00
|
|
|
|
point = body_pos - 1;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-03-09 21:54:56 +00:00
|
|
|
|
return 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-17 10:31:47 +00:00
|
|
|
|
int LyXText::fill(ParagraphList::iterator pit, Row & row, int paper_width) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-06-12 11:27:15 +00:00
|
|
|
|
if (paper_width < 0)
|
2001-08-13 13:28:14 +00:00
|
|
|
|
return 0;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
|
int w;
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// get the pure distance
|
2003-09-04 15:21:34 +00:00
|
|
|
|
pos_type const last = lastPos(*pit, row);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-13 12:56:48 +00:00
|
|
|
|
LyXLayout_ptr const & layout = pit->layout();
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// special handling of the right address boxes
|
2003-04-13 12:56:48 +00:00
|
|
|
|
if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
|
2003-10-17 10:31:47 +00:00
|
|
|
|
int const tmpfill = row.fill();
|
|
|
|
|
row.fill(0); // the minfill in MarginLeft()
|
|
|
|
|
w = leftMargin(pit, row);
|
|
|
|
|
row.fill(tmpfill);
|
2000-01-13 16:28:54 +00:00
|
|
|
|
} else
|
2003-10-17 10:31:47 +00:00
|
|
|
|
w = leftMargin(pit, row);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-02 23:01:39 +00:00
|
|
|
|
pos_type const body_pos = pit->beginningOfBody();
|
2003-10-17 10:31:47 +00:00
|
|
|
|
pos_type i = row.pos();
|
2000-02-03 19:51:27 +00:00
|
|
|
|
|
2003-07-27 10:42:11 +00:00
|
|
|
|
if (! pit->empty() && i <= last) {
|
|
|
|
|
// 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-07-27 00:37:17 +00:00
|
|
|
|
while (i <= last) {
|
|
|
|
|
if (body_pos > 0 && i == body_pos) {
|
2003-07-27 21:59:06 +00:00
|
|
|
|
w += font_metrics::width(layout->labelsep, getLabelFont(pit));
|
2003-07-27 00:37:17 +00:00
|
|
|
|
if (pit->isLineSeparator(i - 1))
|
|
|
|
|
w -= singleWidth(pit, i - 1);
|
2003-10-17 10:31:47 +00:00
|
|
|
|
int left_margin = labelEnd(pit, row);
|
2003-07-27 00:37:17 +00:00
|
|
|
|
if (w < left_margin)
|
|
|
|
|
w = left_margin;
|
|
|
|
|
}
|
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);
|
2003-07-27 00:37:17 +00:00
|
|
|
|
++i;
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2000-02-03 19:51:27 +00:00
|
|
|
|
}
|
2003-03-09 12:37:22 +00:00
|
|
|
|
if (body_pos > 0 && body_pos > last) {
|
2003-07-27 21:59:06 +00:00
|
|
|
|
w += font_metrics::width(layout->labelsep, getLabelFont(pit));
|
2003-04-02 23:01:39 +00:00
|
|
|
|
if (last >= 0 && pit->isLineSeparator(last))
|
2003-04-09 21:34:31 +00:00
|
|
|
|
w -= singleWidth(pit, last);
|
2003-10-17 10:31:47 +00:00
|
|
|
|
int const left_margin = labelEnd(pit, row);
|
2000-02-03 19:51:27 +00:00
|
|
|
|
if (w < left_margin)
|
|
|
|
|
w = left_margin;
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-17 10:31:47 +00:00
|
|
|
|
int const fill = paper_width - w - rightMargin(*pit, *bv()->buffer(), row);
|
2003-04-11 03:28:06 +00:00
|
|
|
|
|
|
|
|
|
// If this case happens, it means that our calculation
|
|
|
|
|
// of the widths of the chars when we do rowBreakPoint()
|
|
|
|
|
// went wrong for some reason. Typically in list bodies.
|
|
|
|
|
// Things just about hobble on anyway, though you'll end
|
|
|
|
|
// up with a "fill_separator" less than zero, which corresponds
|
|
|
|
|
// to inter-word spacing being too small. Hopefully this problem
|
|
|
|
|
// will die when the label hacks die.
|
|
|
|
|
if (lyxerr.debugging() && fill < 0) {
|
|
|
|
|
lyxerr[Debug::GUI] << "Eek, fill() was < 0: " << fill
|
|
|
|
|
<< " w " << w << " paper_width " << paper_width
|
2003-10-17 10:31:47 +00:00
|
|
|
|
<< " right margin " << rightMargin(*pit, *bv()->buffer(), row) << endl;
|
2003-04-11 03:28:06 +00:00
|
|
|
|
}
|
2000-01-13 16:28:54 +00:00
|
|
|
|
return 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-04-13 12:56:48 +00:00
|
|
|
|
pos_type last = pit->beginningOfBody();
|
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
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
// -1 because a label ends either with a space that is in the label,
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// or with the beginning of a footnote that is outside 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-02-26 17:04:10 +00:00
|
|
|
|
pos_type i = row.pos();
|
2000-01-13 16:28:54 +00:00
|
|
|
|
while (i <= last) {
|
2003-04-13 12:56:48 +00:00
|
|
|
|
w += singleWidth(pit, i);
|
2000-01-13 16:28:54 +00:00
|
|
|
|
++i;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
int fill = 0;
|
2003-04-13 12:56:48 +00:00
|
|
|
|
string const & labwidstr = pit->params().labelWidthString();
|
2003-02-26 17:04:10 +00:00
|
|
|
|
if (!labwidstr.empty()) {
|
2003-07-27 21:59:06 +00:00
|
|
|
|
LyXFont const labfont = getLabelFont(pit);
|
2003-02-26 17:04:10 +00:00
|
|
|
|
int const labwidth = font_metrics::width(labwidstr, labfont);
|
|
|
|
|
fill = max(labwidth - w, 0);
|
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 fill;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-09-18 11:48:11 +00:00
|
|
|
|
LColor_color LyXText::backgroundColor() const
|
2001-07-24 10:13:19 +00:00
|
|
|
|
{
|
|
|
|
|
if (inset_owner)
|
|
|
|
|
return inset_owner->backgroundColor();
|
|
|
|
|
else
|
|
|
|
|
return LColor::background;
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
double tmptop = 0;
|
2001-07-31 10:10:17 +00:00
|
|
|
|
|
2003-07-17 15:04:09 +00:00
|
|
|
|
// ok, let us initialize the maxasc and maxdesc value.
|
2003-07-29 01:46:09 +00:00
|
|
|
|
// Only the fontsize count. The other properties
|
|
|
|
|
// are taken from the layoutfont. Nicer on the screen :)
|
2003-04-13 12:56:48 +00:00
|
|
|
|
LyXLayout_ptr const & layout = pit->layout();
|
2001-07-31 10:10:17 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
// as max get the first character of this row then it can increase but not
|
|
|
|
|
// decrease the height. Just some point to start with so we don't have to
|
2001-07-31 12:57:06 +00:00
|
|
|
|
// do the assignment below too often.
|
2003-10-17 10:31:47 +00:00
|
|
|
|
LyXFont font = getFont(pit, row.pos());
|
2001-07-31 12:57:06 +00:00
|
|
|
|
LyXFont::FONT_SIZE const tmpsize = font.size();
|
2003-07-27 21:59:06 +00:00
|
|
|
|
font = getLayoutFont(pit);
|
2001-07-31 12:57:06 +00:00
|
|
|
|
LyXFont::FONT_SIZE const size = font.size();
|
|
|
|
|
font.setSize(tmpsize);
|
2001-07-31 10:10:17 +00:00
|
|
|
|
|
2003-07-27 21:59:06 +00:00
|
|
|
|
LyXFont labelfont = getLabelFont(pit);
|
2001-07-31 10:10:17 +00:00
|
|
|
|
|
2003-07-29 01:46:09 +00:00
|
|
|
|
double spacing_val = 1.0;
|
|
|
|
|
if (!pit->params().spacing().isDefault())
|
2003-04-13 12:56:48 +00:00
|
|
|
|
spacing_val = pit->params().spacing().getValue();
|
2003-07-29 01:46:09 +00:00
|
|
|
|
else
|
2003-09-09 17:00:19 +00:00
|
|
|
|
spacing_val = bv()->buffer()->params().spacing().getValue();
|
2001-07-31 10:10:17 +00:00
|
|
|
|
//lyxerr << "spacing_val = " << spacing_val << endl;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-07-29 01:46:09 +00:00
|
|
|
|
int maxasc = int(font_metrics::maxAscent(font) *
|
|
|
|
|
layout->spacing.getValue() * spacing_val);
|
2002-05-24 14:34:32 +00:00
|
|
|
|
int maxdesc = int(font_metrics::maxDescent(font) *
|
2003-07-29 01:46:09 +00:00
|
|
|
|
layout->spacing.getValue() * spacing_val);
|
2002-05-24 14:34:32 +00:00
|
|
|
|
|
2003-10-17 10:31:47 +00:00
|
|
|
|
pos_type const pos_end = lastPos(*pit, row);
|
2001-07-31 10:10:17 +00:00
|
|
|
|
int labeladdon = 0;
|
|
|
|
|
int maxwidth = 0;
|
|
|
|
|
|
2003-04-13 12:56:48 +00:00
|
|
|
|
if (!pit->empty()) {
|
2003-07-27 11:16:25 +00:00
|
|
|
|
// We re-use the font resolution for the entire font span when possible
|
2003-10-17 10:31:47 +00:00
|
|
|
|
LyXFont font = getFont(pit, row.pos());
|
|
|
|
|
lyx::pos_type endPosOfFontSpan = pit->getEndPosOfFontSpan(row.pos());
|
2003-07-27 11:16:25 +00:00
|
|
|
|
|
|
|
|
|
// Optimisation
|
|
|
|
|
Paragraph const & par = *pit;
|
|
|
|
|
|
2003-03-13 17:50:39 +00:00
|
|
|
|
// Check if any insets are larger
|
2003-10-17 10:31:47 +00:00
|
|
|
|
for (pos_type pos = row.pos(); pos <= pos_end; ++pos) {
|
2003-07-29 01:46:09 +00:00
|
|
|
|
// Manual inlined optimised version of common case of
|
|
|
|
|
// "maxwidth += singleWidth(pit, pos);"
|
2003-07-27 11:16:25 +00:00
|
|
|
|
char const c = par.getChar(pos);
|
|
|
|
|
|
|
|
|
|
if (IsPrintable(c)) {
|
|
|
|
|
if (pos > endPosOfFontSpan) {
|
|
|
|
|
// We need to get the next font
|
2003-07-27 21:59:06 +00:00
|
|
|
|
font = getFont(pit, pos);
|
2003-07-27 11:16:25 +00:00
|
|
|
|
endPosOfFontSpan = par.getEndPosOfFontSpan(pos);
|
|
|
|
|
}
|
|
|
|
|
if (! font.language()->RightToLeft()) {
|
|
|
|
|
maxwidth += font_metrics::width(c, font);
|
|
|
|
|
} else {
|
|
|
|
|
// Fall-back to normal case
|
2003-08-22 07:49:57 +00:00
|
|
|
|
maxwidth += singleWidth(pit, pos, c, font);
|
2003-07-27 11:16:25 +00:00
|
|
|
|
// And flush font cache
|
|
|
|
|
endPosOfFontSpan = 0;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Special handling of insets - are any larger?
|
|
|
|
|
if (par.isInset(pos)) {
|
|
|
|
|
InsetOld const * tmpinset = par.getInset(pos);
|
|
|
|
|
if (tmpinset) {
|
|
|
|
|
maxwidth += tmpinset->width();
|
|
|
|
|
maxasc = max(maxasc, tmpinset->ascent());
|
|
|
|
|
maxdesc = max(maxdesc, tmpinset->descent());
|
2003-07-28 14:40:29 +00:00
|
|
|
|
}
|
2003-07-27 11:16:25 +00:00
|
|
|
|
} else {
|
|
|
|
|
// Fall-back to normal case
|
2003-08-22 07:49:57 +00:00
|
|
|
|
maxwidth += singleWidth(pit, pos, c, font);
|
2003-07-27 11:16:25 +00:00
|
|
|
|
// And flush font cache
|
|
|
|
|
endPosOfFontSpan = 0;
|
2003-03-13 17:50:39 +00:00
|
|
|
|
}
|
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.
|
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-04-13 12:56:48 +00:00
|
|
|
|
maxasc = max(maxasc, font_metrics::maxAscent(font));
|
|
|
|
|
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-17 10:31:47 +00:00
|
|
|
|
if (!row.pos()) {
|
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-09-09 09:47:59 +00:00
|
|
|
|
if (bv()->buffer()->params().paragraph_separation ==
|
2001-07-31 10:10:17 +00:00
|
|
|
|
BufferParams::PARSEP_SKIP)
|
|
|
|
|
{
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (layout->isParagraph()
|
2003-04-13 12:56:48 +00:00
|
|
|
|
&& pit->getDepth() == 0
|
|
|
|
|
&& pit != ownerParagraphs().begin())
|
2001-07-31 10:10:17 +00:00
|
|
|
|
{
|
2003-09-09 09:47:59 +00:00
|
|
|
|
maxasc += bufparams.getDefSkip().inPixels(*bv());
|
2003-04-13 12:56:48 +00:00
|
|
|
|
} else if (pit != ownerParagraphs().begin() &&
|
|
|
|
|
boost::prior(pit)->layout()->isParagraph() &&
|
|
|
|
|
boost::prior(pit)->getDepth() == 0)
|
2001-07-31 10:10:17 +00:00
|
|
|
|
{
|
|
|
|
|
// is it right to use defskip here too? (AS)
|
2003-09-09 09:47:59 +00:00
|
|
|
|
maxasc += bufparams.getDefSkip().inPixels(*bv());
|
2001-07-31 10:10:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-02-14 00:41:44 +00:00
|
|
|
|
// the top margin
|
2003-04-13 12:56:48 +00:00
|
|
|
|
if (pit == ownerParagraphs().begin() && !isInInset())
|
2003-02-07 14:13:51 +00:00
|
|
|
|
maxasc += PAPER_MARGIN;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-31 10:10:17 +00:00
|
|
|
|
// add the vertical spaces, that the user added
|
2003-04-13 12:56:48 +00:00
|
|
|
|
maxasc += getLengthMarkerHeight(*bv(), pit->params().spaceTop());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-31 10:10:17 +00:00
|
|
|
|
// do not forget the DTP-lines!
|
|
|
|
|
// there height depends on the font of the nearest character
|
2003-04-13 12:56:48 +00:00
|
|
|
|
if (pit->params().lineTop())
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-07-27 21:59:06 +00:00
|
|
|
|
maxasc += 2 * font_metrics::ascent('x', getFont(pit, 0));
|
2001-07-31 10:10:17 +00:00
|
|
|
|
// and now the pagebreaks
|
2003-04-13 12:56:48 +00:00
|
|
|
|
if (pit->params().pagebreakTop())
|
2003-02-14 00:41:44 +00:00
|
|
|
|
maxasc += 3 * defaultRowHeight();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-13 12:56:48 +00:00
|
|
|
|
if (pit->params().startOfAppendix())
|
2003-03-13 19:55:39 +00:00
|
|
|
|
maxasc += 3 * defaultRowHeight();
|
|
|
|
|
|
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) {
|
2001-07-31 10:10:17 +00:00
|
|
|
|
float spacing_val = 1.0;
|
2003-04-13 12:56:48 +00:00
|
|
|
|
if (!pit->params().spacing().isDefault()) {
|
|
|
|
|
spacing_val = pit->params().spacing().getValue();
|
2001-07-31 10:10:17 +00:00
|
|
|
|
} else {
|
2003-09-09 17:00:19 +00:00
|
|
|
|
spacing_val = bufparams.spacing().getValue();
|
2001-07-31 10:10:17 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-05-24 14:34:32 +00:00
|
|
|
|
labeladdon = int(font_metrics::maxDescent(labelfont) *
|
2002-06-24 20:28:12 +00:00
|
|
|
|
layout->spacing.getValue() *
|
|
|
|
|
spacing_val)
|
2002-05-24 14:34:32 +00:00
|
|
|
|
+ int(font_metrics::maxAscent(labelfont) *
|
2002-06-24 20:28:12 +00:00
|
|
|
|
layout->spacing.getValue() *
|
2001-07-31 10:10:17 +00:00
|
|
|
|
spacing_val);
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-31 10:10:17 +00:00
|
|
|
|
// special code for the top label
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if ((layout->labeltype == LABEL_TOP_ENVIRONMENT
|
|
|
|
|
|| layout->labeltype == LABEL_BIBLIO
|
|
|
|
|
|| layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
|
2003-04-16 08:12:22 +00:00
|
|
|
|
&& isFirstInSequence(pit, ownerParagraphs())
|
2003-04-13 12:56:48 +00:00
|
|
|
|
&& !pit->getLabelstring().empty())
|
2001-07-31 10:10:17 +00:00
|
|
|
|
{
|
|
|
|
|
float spacing_val = 1.0;
|
2003-04-13 12:56:48 +00:00
|
|
|
|
if (!pit->params().spacing().isDefault()) {
|
|
|
|
|
spacing_val = pit->params().spacing().getValue();
|
2001-07-31 10:10:17 +00:00
|
|
|
|
} else {
|
2003-09-09 17:00:19 +00:00
|
|
|
|
spacing_val = bufparams.spacing().getValue();
|
2001-07-31 10:10:17 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-31 10:10:17 +00:00
|
|
|
|
labeladdon = int(
|
2003-08-11 09:09:01 +00:00
|
|
|
|
(font_metrics::maxAscent(labelfont) +
|
|
|
|
|
font_metrics::maxDescent(labelfont)) *
|
2002-06-24 20:28:12 +00:00
|
|
|
|
layout->spacing.getValue() *
|
2003-08-11 09:09:01 +00:00
|
|
|
|
spacing_val
|
2003-02-14 00:41:44 +00:00
|
|
|
|
+ layout->topsep * defaultRowHeight()
|
|
|
|
|
+ layout->labelbottomsep * defaultRowHeight());
|
2001-07-31 10:10:17 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-16 08:12:22 +00:00
|
|
|
|
// And now the layout spaces, for example before and after
|
|
|
|
|
// a section, or between the items of a itemize or enumerate
|
|
|
|
|
// environment.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-13 12:56:48 +00:00
|
|
|
|
if (!pit->params().pagebreakTop()) {
|
2003-04-16 08:12:22 +00:00
|
|
|
|
ParagraphList::iterator prev =
|
|
|
|
|
depthHook(pit, ownerParagraphs(),
|
|
|
|
|
pit->getDepth());
|
|
|
|
|
if (prev != pit && prev->layout() == layout &&
|
2003-04-13 12:56:48 +00:00
|
|
|
|
prev->getDepth() == pit->getDepth() &&
|
|
|
|
|
prev->getLabelWidthString() == pit->getLabelWidthString())
|
2001-07-31 10:10:17 +00:00
|
|
|
|
{
|
2003-02-14 00:41:44 +00:00
|
|
|
|
layoutasc = (layout->itemsep * defaultRowHeight());
|
2003-10-17 10:31:47 +00:00
|
|
|
|
} else if (pit != ownerParagraphs().begin() || row.pos() != 0) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
tmptop = layout->topsep;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-31 10:10:17 +00:00
|
|
|
|
if (tmptop > 0)
|
2003-02-14 00:41:44 +00:00
|
|
|
|
layoutasc = (tmptop * defaultRowHeight());
|
2003-04-13 12:56:48 +00:00
|
|
|
|
} else if (pit->params().lineTop()) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
tmptop = layout->topsep;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-31 10:10:17 +00:00
|
|
|
|
if (tmptop > 0)
|
2003-02-14 00:41:44 +00:00
|
|
|
|
layoutasc = (tmptop * defaultRowHeight());
|
2001-07-31 10:10:17 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-16 08:12:22 +00:00
|
|
|
|
prev = outerHook(pit, ownerParagraphs());
|
|
|
|
|
if (prev != ownerParagraphs().end()) {
|
2003-02-14 00:41:44 +00:00
|
|
|
|
maxasc += int(prev->layout()->parsep * defaultRowHeight());
|
2003-04-13 12:56:48 +00:00
|
|
|
|
} else if (pit != ownerParagraphs().begin()) {
|
|
|
|
|
ParagraphList::iterator prior_pit = boost::prior(pit);
|
|
|
|
|
if (prior_pit->getDepth() != 0 ||
|
|
|
|
|
prior_pit->layout() == layout) {
|
2003-02-14 00:41:44 +00:00
|
|
|
|
maxasc += int(layout->parsep * defaultRowHeight());
|
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-17 10:31:47 +00:00
|
|
|
|
if (row.end() == pit->size()) {
|
2003-02-14 00:41:44 +00:00
|
|
|
|
// the bottom margin
|
2003-04-13 12:56:48 +00:00
|
|
|
|
ParagraphList::iterator nextpit = boost::next(pit);
|
2003-08-15 08:03:54 +00:00
|
|
|
|
if (nextpit == ownerParagraphs().end() && !isInInset())
|
2003-02-07 14:13:51 +00:00
|
|
|
|
maxdesc += PAPER_MARGIN;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-31 10:10:17 +00:00
|
|
|
|
// add the vertical spaces, that the user added
|
2003-04-13 12:56:48 +00:00
|
|
|
|
maxdesc += getLengthMarkerHeight(*bv(), pit->params().spaceBottom());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-31 10:10:17 +00:00
|
|
|
|
// do not forget the DTP-lines!
|
|
|
|
|
// there height depends on the font of the nearest character
|
2003-04-13 12:56:48 +00:00
|
|
|
|
if (pit->params().lineBottom())
|
2002-05-24 14:34:32 +00:00
|
|
|
|
maxdesc += 2 * font_metrics::ascent('x',
|
2003-07-27 21:59:06 +00:00
|
|
|
|
getFont(pit, max(pos_type(0), pit->size() - 1)));
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-31 10:10:17 +00:00
|
|
|
|
// and now the pagebreaks
|
2003-04-13 12:56:48 +00:00
|
|
|
|
if (pit->params().pagebreakBottom())
|
2003-02-14 00:41:44 +00:00
|
|
|
|
maxdesc += 3 * defaultRowHeight();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-31 10:10:17 +00:00
|
|
|
|
// and now the layout spaces, for example before and after
|
|
|
|
|
// a section, or between the items of a itemize or enumerate
|
|
|
|
|
// environment
|
2003-04-13 12:56:48 +00:00
|
|
|
|
if (!pit->params().pagebreakBottom()
|
|
|
|
|
&& nextpit != ownerParagraphs().end()) {
|
|
|
|
|
ParagraphList::iterator comparepit = pit;
|
2001-07-31 10:10:17 +00:00
|
|
|
|
float usual = 0;
|
|
|
|
|
float unusual = 0;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-02 23:01:39 +00:00
|
|
|
|
if (comparepit->getDepth() > nextpit->getDepth()) {
|
|
|
|
|
usual = (comparepit->layout()->bottomsep * defaultRowHeight());
|
2003-04-16 08:12:22 +00:00
|
|
|
|
comparepit = depthHook(comparepit, ownerParagraphs(), nextpit->getDepth());
|
2003-04-02 23:01:39 +00:00
|
|
|
|
if (comparepit->layout()!= nextpit->layout()
|
|
|
|
|
|| nextpit->getLabelWidthString() !=
|
|
|
|
|
comparepit->getLabelWidthString())
|
2001-07-31 10:10:17 +00:00
|
|
|
|
{
|
2003-04-02 23:01:39 +00:00
|
|
|
|
unusual = (comparepit->layout()->bottomsep * defaultRowHeight());
|
2001-07-31 10:10:17 +00:00
|
|
|
|
}
|
|
|
|
|
if (unusual > usual)
|
|
|
|
|
layoutdesc = unusual;
|
|
|
|
|
else
|
|
|
|
|
layoutdesc = usual;
|
2003-04-02 23:01:39 +00:00
|
|
|
|
} else if (comparepit->getDepth() == nextpit->getDepth()) {
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-02 23:01:39 +00:00
|
|
|
|
if (comparepit->layout() != nextpit->layout()
|
|
|
|
|
|| nextpit->getLabelWidthString() !=
|
|
|
|
|
comparepit->getLabelWidthString())
|
|
|
|
|
layoutdesc = int(comparepit->layout()->bottomsep * defaultRowHeight());
|
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-04-13 12:56:48 +00:00
|
|
|
|
maxasc += int(layoutasc * 2 / (2 + pit->getDepth()));
|
|
|
|
|
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));
|
2003-02-08 19:18:01 +00:00
|
|
|
|
|
2003-10-17 10:31:47 +00:00
|
|
|
|
row.width(maxwidth);
|
2001-07-31 10:10:17 +00:00
|
|
|
|
if (inset_owner) {
|
2003-03-17 16:25:00 +00:00
|
|
|
|
width = max(0, workWidth());
|
2003-08-14 14:10:13 +00:00
|
|
|
|
RowList::iterator rit = firstRow();
|
|
|
|
|
RowList::iterator end = endRow();
|
2003-08-15 08:03:54 +00:00
|
|
|
|
ParagraphList::iterator it = ownerParagraphs().begin();
|
|
|
|
|
while (rit != end) {
|
2003-08-14 14:10:13 +00:00
|
|
|
|
if (rit->width() > width)
|
|
|
|
|
width = rit->width();
|
2003-08-15 08:03:54 +00:00
|
|
|
|
nextRow(it, rit);
|
|
|
|
|
}
|
2001-07-31 10:10:17 +00:00
|
|
|
|
}
|
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-09 10:52:12 +00:00
|
|
|
|
if (cursor.pos() && cursor.pos() != cursorPar()->size()
|
|
|
|
|
&& cursorPar()->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-09 10:52:12 +00:00
|
|
|
|
LyXLayout_ptr const & layout = cursorPar()->layout();
|
2000-09-23 04:57:18 +00:00
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// this is only allowed, if the current paragraph is not empty or caption
|
2003-06-07 17:45:43 +00:00
|
|
|
|
// and if it has not the keepempty flag active
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (cursorPar()->empty() && !cursorPar()->allowEmpty()
|
2003-06-07 17:45:43 +00:00
|
|
|
|
&& layout->labeltype != LABEL_SENSITIVE)
|
2002-05-29 12:58:23 +00:00
|
|
|
|
return;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-13 10:59:31 +00:00
|
|
|
|
recUndo(cursor.par());
|
2000-02-10 17:53:36 +00:00
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// Always break behind a space
|
|
|
|
|
//
|
|
|
|
|
// It is better to erase the space (Dekel)
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (cursor.pos() < cursorPar()->size()
|
|
|
|
|
&& cursorPar()->isLineSeparator(cursor.pos()))
|
|
|
|
|
cursorPar()->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-09 10:52:12 +00:00
|
|
|
|
bool const isempty = (cursorPar()->allowEmpty() && cursorPar()->empty());
|
|
|
|
|
::breakParagraph(bv()->buffer()->params(), paragraphs, cursorPar(),
|
2003-07-10 12:26:40 +00:00
|
|
|
|
cursor.pos(), keep_layout);
|
2000-09-23 04:57:18 +00:00
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
|
#warning Trouble Point! (Lgb)
|
|
|
|
|
// When ::breakParagraph is called from within an inset we must
|
|
|
|
|
// ensure that the correct ParagraphList is used. Today that is not
|
|
|
|
|
// the case and the Buffer::paragraphs is used. Not good. (Lgb)
|
2003-10-09 10:52:12 +00:00
|
|
|
|
ParagraphList::iterator next_par = boost::next(cursorPar());
|
2003-08-15 08:03:54 +00:00
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// well this is the caption hack since one caption is really enough
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (layout->labeltype == LABEL_SENSITIVE) {
|
2002-05-29 12:58:23 +00:00
|
|
|
|
if (!cursor.pos())
|
|
|
|
|
// set to standard-layout
|
2003-10-09 10:52:12 +00:00
|
|
|
|
cursorPar()->applyLayout(tclass.defaultLayout());
|
2002-05-29 12:58:23 +00:00
|
|
|
|
else
|
|
|
|
|
// set to standard-layout
|
2003-08-15 08:03:54 +00:00
|
|
|
|
next_par->applyLayout(tclass.defaultLayout());
|
2002-05-29 12:58:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if the cursor is at the beginning of a row without prior newline,
|
|
|
|
|
// move one row up!
|
|
|
|
|
// This touches only the screen-update. Otherwise we would may have
|
2002-06-24 20:28:12 +00:00
|
|
|
|
// an empty row on the screen
|
2003-06-27 08:38:41 +00:00
|
|
|
|
if (cursor.pos() && cursorRow()->pos() == cursor.pos()
|
2003-10-09 10:52:12 +00:00
|
|
|
|
&& !cursorPar()->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-09 10:52:12 +00:00
|
|
|
|
redoParagraph(cursorPar());
|
2003-08-15 08:03:54 +00:00
|
|
|
|
redoParagraph(next_par);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// This check is necessary. Otherwise the new empty paragraph will
|
|
|
|
|
// be deleted automatically. And it is more friendly for the user!
|
|
|
|
|
if (cursor.pos() || isempty)
|
2003-04-13 02:23:30 +00:00
|
|
|
|
setCursor(next_par, 0);
|
2002-05-29 12:58:23 +00:00
|
|
|
|
else
|
2003-10-09 10:52:12 +00:00
|
|
|
|
setCursor(cursorPar(), 0);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-14 08:34:13 +00:00
|
|
|
|
// convenience function
|
2003-03-18 13:05:08 +00:00
|
|
|
|
void LyXText::redoParagraph()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-08-01 15:42:53 +00:00
|
|
|
|
clearSelection();
|
2003-10-09 10:52:12 +00:00
|
|
|
|
redoParagraph(cursorPar());
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursorIntern(cursor.par(), cursor.pos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// insert a character, moves all the following breaks in the
|
2002-06-24 20:28:12 +00:00
|
|
|
|
// same Paragraph one to the right and make a rebreak
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::insertChar(char c)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-10-14 13:01:49 +00:00
|
|
|
|
recordUndo(Undo::INSERT, this, cursor.par(), cursor.par());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
// When the free-spacing option is set for the current layout,
|
|
|
|
|
// disable the double-space checking
|
2000-03-09 03:36:48 +00:00
|
|
|
|
|
2003-10-09 10:52:12 +00:00
|
|
|
|
bool const freeSpacing = cursorPar()->layout()->free_spacing ||
|
|
|
|
|
cursorPar()->isFreeSpacing();
|
2000-02-29 02:19:17 +00:00
|
|
|
|
|
2000-10-09 12:30:52 +00:00
|
|
|
|
if (lyxrc.auto_number) {
|
2001-01-15 14:05:45 +00:00
|
|
|
|
static string const number_operators = "+-/*";
|
|
|
|
|
static string const number_unary_operators = "+-";
|
|
|
|
|
static string const number_seperators = ".,:";
|
|
|
|
|
|
2000-10-09 12:30:52 +00:00
|
|
|
|
if (current_font.number() == LyXFont::ON) {
|
2001-12-20 15:11:51 +00:00
|
|
|
|
if (!IsDigit(c) && !contains(number_operators, c) &&
|
2001-01-15 14:05:45 +00:00
|
|
|
|
!(contains(number_seperators, c) &&
|
2000-10-09 12:30:52 +00:00
|
|
|
|
cursor.pos() >= 1 &&
|
2003-10-09 10:52:12 +00:00
|
|
|
|
cursor.pos() < cursorPar()->size() &&
|
|
|
|
|
getFont(cursorPar(), cursor.pos()).number() == LyXFont::ON &&
|
|
|
|
|
getFont(cursorPar(), cursor.pos() - 1).number() == LyXFont::ON)
|
2002-02-16 15:59:55 +00:00
|
|
|
|
)
|
2003-03-17 16:25:00 +00:00
|
|
|
|
number(bv()); // 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-03-17 16:25:00 +00:00
|
|
|
|
number(bv()); // Set current_font.number to ON
|
2000-10-09 12:30:52 +00:00
|
|
|
|
|
|
|
|
|
if (cursor.pos() > 0) {
|
2003-10-09 10:52:12 +00:00
|
|
|
|
char const c = cursorPar()->getChar(cursor.pos() - 1);
|
2001-01-15 14:05:45 +00:00
|
|
|
|
if (contains(number_unary_operators, c) &&
|
2000-10-09 12:30:52 +00:00
|
|
|
|
(cursor.pos() == 1 ||
|
2003-10-09 10:52:12 +00:00
|
|
|
|
cursorPar()->isSeparator(cursor.pos() - 2) ||
|
|
|
|
|
cursorPar()->isNewline(cursor.pos() - 2))
|
2002-02-16 15:59:55 +00:00
|
|
|
|
) {
|
2003-07-27 21:59:06 +00:00
|
|
|
|
setCharFont(
|
2003-10-09 10:52:12 +00:00
|
|
|
|
cursorPar(),
|
2000-10-09 12:30:52 +00:00
|
|
|
|
cursor.pos() - 1,
|
|
|
|
|
current_font);
|
2001-01-15 14:05:45 +00:00
|
|
|
|
} else if (contains(number_seperators, c) &&
|
2000-10-09 12:30:52 +00:00
|
|
|
|
cursor.pos() >= 2 &&
|
2003-07-27 21:59:06 +00:00
|
|
|
|
getFont(
|
2003-10-09 10:52:12 +00:00
|
|
|
|
cursorPar(),
|
2001-08-03 18:28:11 +00:00
|
|
|
|
cursor.pos() - 2).number() == LyXFont::ON) {
|
2003-07-27 21:59:06 +00:00
|
|
|
|
setCharFont(
|
2003-10-09 10:52:12 +00:00
|
|
|
|
cursorPar(),
|
2000-10-09 12:30:52 +00:00
|
|
|
|
cursor.pos() - 1,
|
|
|
|
|
current_font);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// First check, if there will be two blanks together or a blank at
|
|
|
|
|
// the beginning of a paragraph.
|
|
|
|
|
// I decided to handle blanks like normal characters, the main
|
|
|
|
|
// difference are the special checks when calculating the row.fill
|
|
|
|
|
// (blank does not count at the end of a row) and the check here
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// The bug is triggered when we type in a description environment:
|
|
|
|
|
// The current_font is not changed when we go from label to main text
|
|
|
|
|
// and it should (along with realtmpfont) when we type the space.
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// CHECK There is a bug here! (Asger)
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// store the current font. This is because of the use of cursor
|
2002-06-24 20:28:12 +00:00
|
|
|
|
// movements. The moving cursor would refresh the current font
|
2003-08-11 09:09:01 +00:00
|
|
|
|
LyXFont realtmpfont = real_current_font;
|
|
|
|
|
LyXFont rawtmpfont = current_font;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-03-09 03:36:48 +00:00
|
|
|
|
if (!freeSpacing && IsLineSeparatorChar(c)) {
|
2002-03-21 17:27:08 +00:00
|
|
|
|
if ((cursor.pos() > 0
|
2003-10-09 10:52:12 +00:00
|
|
|
|
&& cursorPar()->isLineSeparator(cursor.pos() - 1))
|
2000-06-08 23:16:16 +00:00
|
|
|
|
|| (cursor.pos() > 0
|
2003-10-09 10:52:12 +00:00
|
|
|
|
&& cursorPar()->isNewline(cursor.pos() - 1))
|
2001-05-03 14:31:33 +00:00
|
|
|
|
|| (cursor.pos() == 0)) {
|
2001-05-09 15:20:58 +00:00
|
|
|
|
static bool sent_space_message = false;
|
|
|
|
|
if (!sent_space_message) {
|
2002-03-21 17:27:08 +00:00
|
|
|
|
if (cursor.pos() == 0)
|
2003-03-17 16:25:00 +00:00
|
|
|
|
bv()->owner()->message(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
|
2001-05-09 15:20:58 +00:00
|
|
|
|
else
|
2003-03-17 16:25:00 +00:00
|
|
|
|
bv()->owner()->message(_("You cannot type two spaces this way. Please read the Tutorial."));
|
2001-05-09 15:20:58 +00:00
|
|
|
|
sent_space_message = true;
|
|
|
|
|
}
|
1999-12-13 00:05:34 +00:00
|
|
|
|
charInserted();
|
|
|
|
|
return;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-03-13 10:30:28 +00:00
|
|
|
|
|
2003-08-08 15:48:57 +00:00
|
|
|
|
// Here case LyXText::InsertInset already inserted the character
|
|
|
|
|
if (c != Paragraph::META_INSET)
|
2003-10-09 10:52:12 +00:00
|
|
|
|
cursorPar()->insertChar(cursor.pos(), c);
|
2003-08-08 15:48:57 +00:00
|
|
|
|
|
2003-10-09 10:52:12 +00:00
|
|
|
|
setCharFont(cursorPar(), cursor.pos(), rawtmpfont);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-08-08 15:34:17 +00:00
|
|
|
|
current_font = rawtmpfont;
|
|
|
|
|
real_current_font = realtmpfont;
|
2003-10-09 10:52:12 +00:00
|
|
|
|
redoParagraph(cursorPar());
|
2003-08-08 15:34:17 +00:00
|
|
|
|
setCursor(cursor.par(), cursor.pos() + 1, false, cursor.boundary());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
charInserted();
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
|
|
|
|
|
void LyXText::charInserted()
|
|
|
|
|
{
|
2003-08-22 09:40:56 +00:00
|
|
|
|
// Here we could 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-08-14 08:34:13 +00:00
|
|
|
|
void LyXText::prepareToPrint(ParagraphList::iterator pit,
|
2003-08-22 09:40:56 +00:00
|
|
|
|
RowList::iterator const rit) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-07-28 12:20:42 +00:00
|
|
|
|
double w = rit->fill();
|
2003-08-22 09:40:56 +00:00
|
|
|
|
double fill_hfill = 0;
|
|
|
|
|
double fill_label_hfill = 0;
|
|
|
|
|
double fill_separator = 0;
|
|
|
|
|
double x = 0;
|
2000-02-03 19:51:27 +00:00
|
|
|
|
|
2002-01-07 16:15:11 +00:00
|
|
|
|
bool const is_rtl =
|
2003-09-09 09:47:59 +00:00
|
|
|
|
pit->isRightToLeftPar(bv()->buffer()->params());
|
2003-07-18 07:47:07 +00:00
|
|
|
|
if (is_rtl)
|
2003-10-17 10:31:47 +00:00
|
|
|
|
x = workWidth() > 0 ? rightMargin(*pit, *bv()->buffer(), *rit) : 0;
|
2003-07-18 07:47:07 +00:00
|
|
|
|
else
|
2003-08-14 08:34:13 +00:00
|
|
|
|
x = workWidth() > 0 ? leftMargin(pit, *rit) : 0;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
// is there a manual margin with a manual label
|
2003-04-13 12:56:48 +00:00
|
|
|
|
LyXLayout_ptr const & layout = pit->layout();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (layout->margintype == MARGIN_MANUAL
|
|
|
|
|
&& layout->labeltype == LABEL_MANUAL) {
|
2003-03-08 19:31:09 +00:00
|
|
|
|
/// We might have real hfills in the label part
|
2003-10-17 10:31:47 +00:00
|
|
|
|
int nlh = numberOfLabelHfills(*pit, *rit);
|
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-04-13 12:56:48 +00:00
|
|
|
|
if (nlh && !pit->getLabelWidthString().empty()) {
|
2003-08-14 08:34:13 +00:00
|
|
|
|
fill_label_hfill = labelFill(pit, *rit) / 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-17 10:31:47 +00:00
|
|
|
|
int const nh = numberOfHfills(*pit, *rit);
|
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-07-18 07:47:07 +00:00
|
|
|
|
} else if (int(rit->width()) < workWidth()) {
|
2002-03-21 17:27:08 +00:00
|
|
|
|
// is it block, flushleft or flushright?
|
2000-06-08 23:16:16 +00:00
|
|
|
|
// set x how you need it
|
2001-08-10 14:00:48 +00:00
|
|
|
|
int align;
|
2003-04-13 12:56:48 +00:00
|
|
|
|
if (pit->params().align() == LYX_ALIGN_LAYOUT) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
align = layout->align;
|
2001-08-10 14:00:48 +00:00
|
|
|
|
} else {
|
2003-04-13 12:56:48 +00:00
|
|
|
|
align = pit->params().align();
|
2001-08-10 14:00:48 +00:00
|
|
|
|
}
|
2003-07-25 21:20:24 +00:00
|
|
|
|
InsetOld * inset = 0;
|
2002-03-06 10:17:29 +00:00
|
|
|
|
// ERT insets should always be LEFT ALIGNED on screen
|
2003-04-13 12:56:48 +00:00
|
|
|
|
inset = pit->inInset();
|
2002-03-06 10:17:29 +00:00
|
|
|
|
if (inset && inset->owner() &&
|
2003-07-25 21:20:24 +00:00
|
|
|
|
inset->owner()->lyxCode() == InsetOld::ERT_CODE)
|
2002-03-06 10:17:29 +00:00
|
|
|
|
{
|
|
|
|
|
align = LYX_ALIGN_LEFT;
|
|
|
|
|
}
|
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().
|
|
|
|
|
inset = pit->size() ? pit->getInset(rit->pos()) : 0;
|
2003-10-20 18:56:48 +00:00
|
|
|
|
if (inset && inset->display()) {
|
|
|
|
|
align = LYX_ALIGN_CENTER;
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-10 14:00:48 +00:00
|
|
|
|
switch (align) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case LYX_ALIGN_BLOCK:
|
2003-08-28 07:41:31 +00:00
|
|
|
|
{
|
2003-10-17 10:31:47 +00:00
|
|
|
|
int const ns = numberOfSeparators(*pit, *rit);
|
2003-08-28 07:41:31 +00:00
|
|
|
|
RowList::iterator next_row = boost::next(rit);
|
2003-10-20 18:56:48 +00:00
|
|
|
|
bool disp_inset = false;
|
|
|
|
|
if (next_row != pit->rows.end()) {
|
|
|
|
|
InsetOld * in = pit->getInset(next_row->pos());
|
|
|
|
|
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
|
2003-08-14 11:16:31 +00:00
|
|
|
|
if (ns
|
2003-10-21 16:15:14 +00:00
|
|
|
|
&& rit->end() < pit->size()
|
2003-08-28 07:41:31 +00:00
|
|
|
|
&& !pit->isNewline(next_row->pos() - 1)
|
2003-10-20 18:56:48 +00:00
|
|
|
|
&& !disp_inset
|
2003-04-01 16:55:48 +00:00
|
|
|
|
) {
|
2003-08-28 07:41:31 +00:00
|
|
|
|
fill_separator = w / ns;
|
|
|
|
|
} else if (is_rtl) {
|
2001-08-10 14:00:48 +00:00
|
|
|
|
x += w;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2003-03-31 16:57:45 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case LYX_ALIGN_RIGHT:
|
2001-08-10 14:00:48 +00:00
|
|
|
|
x += w;
|
|
|
|
|
break;
|
1999-09-27 18:44:28 +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-17 10:31:47 +00:00
|
|
|
|
computeBidiTables(*pit, *bv()->buffer(), *rit);
|
2000-04-10 21:40:13 +00:00
|
|
|
|
if (is_rtl) {
|
2003-04-13 12:56:48 +00:00
|
|
|
|
pos_type body_pos = pit->beginningOfBody();
|
2003-10-17 10:31:47 +00:00
|
|
|
|
pos_type last = lastPos(*pit, *rit);
|
2000-02-03 19:51:27 +00:00
|
|
|
|
|
2003-03-09 12:37:22 +00:00
|
|
|
|
if (body_pos > 0 &&
|
2003-08-22 09:40:56 +00:00
|
|
|
|
(body_pos - 1 > last ||
|
|
|
|
|
!pit->isLineSeparator(body_pos - 1))) {
|
2003-07-27 21:59:06 +00:00
|
|
|
|
x += font_metrics::width(layout->labelsep, getLabelFont(pit));
|
2003-03-09 12:37:22 +00:00
|
|
|
|
if (body_pos - 1 <= last)
|
2000-02-03 19:51:27 +00:00
|
|
|
|
x += fill_label_hfill;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-08-22 09:40:56 +00:00
|
|
|
|
|
|
|
|
|
rit->fill_hfill(fill_hfill);
|
|
|
|
|
rit->fill_label_hfill(fill_label_hfill);
|
|
|
|
|
rit->fill_separator(fill_separator);
|
|
|
|
|
rit->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-06-24 20:28:12 +00:00
|
|
|
|
// important for the screen
|
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.
|
2002-06-24 20:28:12 +00:00
|
|
|
|
// They also delete the corresponding row
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-03-18 13:05:08 +00:00
|
|
|
|
void LyXText::cursorRightOneWord()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-10-09 10:52:12 +00:00
|
|
|
|
::cursorRightOneWord(*this, cursor, ownerParagraphs());
|
|
|
|
|
setCursor(cursorPar(), cursor.pos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// Skip initial whitespace at end of word and move cursor to *start*
|
2002-06-24 20:28:12 +00:00
|
|
|
|
// of prior word, not to end of next prior word.
|
2003-03-18 13:05:08 +00:00
|
|
|
|
void LyXText::cursorLeftOneWord()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
LyXCursor tmpcursor = cursor;
|
2003-10-09 10:52:12 +00:00
|
|
|
|
::cursorLeftOneWord(*this, tmpcursor, ownerParagraphs());
|
|
|
|
|
setCursor(getPar(tmpcursor), tmpcursor.pos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::selectWord(word_location loc)
|
2001-06-27 14:10:35 +00:00
|
|
|
|
{
|
2003-07-01 11:51:20 +00:00
|
|
|
|
LyXCursor from = cursor;
|
2003-10-10 11:27:05 +00:00
|
|
|
|
LyXCursor to = cursor;
|
2003-10-09 10:52:12 +00:00
|
|
|
|
::getWord(*this, from, to, loc, ownerParagraphs());
|
2001-06-27 14:10:35 +00:00
|
|
|
|
if (cursor != from)
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(from.par(), from.pos());
|
2001-07-27 16:07:33 +00:00
|
|
|
|
if (to == from)
|
|
|
|
|
return;
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.cursor = cursor;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(to.par(), to.pos());
|
|
|
|
|
setSelection();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// Select the word currently under the cursor when no
|
2002-06-24 20:28:12 +00:00
|
|
|
|
// selection is currently set
|
2003-03-17 16:25:00 +00:00
|
|
|
|
bool LyXText::selectWordWhenUnderCursor(word_location loc)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-07-27 16:07:33 +00:00
|
|
|
|
if (!selection.set()) {
|
2003-03-17 16:25:00 +00:00
|
|
|
|
selectWord(loc);
|
2001-07-27 16:07:33 +00:00
|
|
|
|
return selection.set();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-04-24 20:58:23 +00:00
|
|
|
|
return false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::acceptChange()
|
2003-02-08 19:18:01 +00:00
|
|
|
|
{
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (!selection.set() && cursorPar()->size())
|
2003-02-08 19:18:01 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (selection.start.par() == selection.end.par()) {
|
|
|
|
|
LyXCursor & startc = selection.start;
|
|
|
|
|
LyXCursor & endc = selection.end;
|
2003-10-14 13:01:49 +00:00
|
|
|
|
recordUndo(Undo::INSERT, this, startc.par());
|
2003-10-09 10:52:12 +00:00
|
|
|
|
getPar(startc)->acceptChange(startc.pos(), endc.pos());
|
2003-02-08 19:18:01 +00:00
|
|
|
|
finishUndo();
|
|
|
|
|
clearSelection();
|
2003-10-09 10:52:12 +00:00
|
|
|
|
redoParagraph(getPar(startc));
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursorIntern(startc.par(), 0);
|
2003-02-08 19:18:01 +00:00
|
|
|
|
}
|
|
|
|
|
#warning handle multi par selection
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::rejectChange()
|
2003-02-08 19:18:01 +00:00
|
|
|
|
{
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (!selection.set() && cursorPar()->size())
|
2003-02-08 19:18:01 +00:00
|
|
|
|
return;
|
2003-03-03 23:19:01 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
if (selection.start.par() == selection.end.par()) {
|
|
|
|
|
LyXCursor & startc = selection.start;
|
|
|
|
|
LyXCursor & endc = selection.end;
|
2003-10-14 13:01:49 +00:00
|
|
|
|
recordUndo(Undo::INSERT, this, startc.par());
|
2003-10-09 10:52:12 +00:00
|
|
|
|
getPar(startc)->rejectChange(startc.pos(), endc.pos());
|
2003-02-08 19:18:01 +00:00
|
|
|
|
finishUndo();
|
|
|
|
|
clearSelection();
|
2003-10-09 10:52:12 +00:00
|
|
|
|
redoParagraph(getPar(startc));
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursorIntern(startc.par(), 0);
|
2003-02-08 19:18:01 +00:00
|
|
|
|
}
|
|
|
|
|
#warning handle multi par selection
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-03 23:19:01 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// This function is only used by the spellchecker for NextWord().
|
|
|
|
|
// It doesn't handle LYX_ACCENTs and probably never will.
|
2003-10-09 10:52:12 +00:00
|
|
|
|
WordLangTuple const LyXText::selectNextWordToSpellcheck(float & value)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-07-17 15:39:12 +00:00
|
|
|
|
if (the_locking_inset) {
|
2003-10-21 16:15:14 +00:00
|
|
|
|
WordLangTuple word =
|
|
|
|
|
the_locking_inset->selectNextWordToSpellcheck(bv(), value);
|
2002-08-06 22:38:44 +00:00
|
|
|
|
if (!word.word().empty()) {
|
2002-11-07 00:37:09 +00:00
|
|
|
|
value += float(cursor.y());
|
2002-11-27 10:30:28 +00:00
|
|
|
|
value /= float(height);
|
2002-08-06 22:38:44 +00:00
|
|
|
|
return word;
|
2001-07-17 15:39:12 +00:00
|
|
|
|
}
|
2002-08-06 22:38:44 +00:00
|
|
|
|
// we have to go on checking so move cursor to the next char
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (cursor.pos() == cursorPar()->size()) {
|
|
|
|
|
if (cursor.par() + 1 == int(ownerParagraphs().size()))
|
2002-08-06 22:38:44 +00:00
|
|
|
|
return word;
|
2003-10-09 10:52:12 +00:00
|
|
|
|
cursor.par(cursor.par() + 1);
|
2001-07-17 15:39:12 +00:00
|
|
|
|
cursor.pos(0);
|
|
|
|
|
} else
|
2003-10-09 10:52:12 +00:00
|
|
|
|
cursor.pos(cursor.pos() + 1);
|
2001-07-17 15:39:12 +00:00
|
|
|
|
}
|
2003-10-09 10:52:12 +00:00
|
|
|
|
int const tmppar = cursor.par();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// If this is not the very first word, skip rest of
|
|
|
|
|
// current word because we are probably in the middle
|
|
|
|
|
// of a word if there is text here.
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (cursor.pos() || cursor.par() != 0) {
|
|
|
|
|
while (cursor.pos() < cursorPar()->size()
|
|
|
|
|
&& cursorPar()->isLetter(cursor.pos()))
|
2001-03-09 00:56:42 +00:00
|
|
|
|
cursor.pos(cursor.pos() + 1);
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Now, skip until we have real text (will jump paragraphs)
|
2003-04-09 09:15:20 +00:00
|
|
|
|
while (true) {
|
2003-10-09 10:52:12 +00:00
|
|
|
|
ParagraphList::iterator cpit = cursorPar();
|
|
|
|
|
pos_type const cpos = cursor.pos();
|
2003-03-03 23:19:01 +00:00
|
|
|
|
|
2003-04-09 09:15:20 +00:00
|
|
|
|
if (cpos == cpit->size()) {
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (cursor.par() + 1 != int(ownerParagraphs().size())) {
|
|
|
|
|
cursor.par(cursor.par() + 1);
|
2003-02-08 19:18:01 +00:00
|
|
|
|
cursor.pos(0);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2001-07-17 15:39:12 +00:00
|
|
|
|
|
2003-04-10 03:04:22 +00:00
|
|
|
|
bool const is_good_inset = cpit->isInset(cpos)
|
|
|
|
|
&& cpit->getInset(cpos)->allowSpellcheck();
|
2003-04-10 12:10:04 +00:00
|
|
|
|
|
|
|
|
|
if (!isDeletedText(*cpit, cpos)
|
2003-04-10 03:04:22 +00:00
|
|
|
|
&& (is_good_inset || cpit->isLetter(cpos)))
|
2003-04-10 12:10:04 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
cursor.pos(cpos + 1);
|
|
|
|
|
}
|
2003-03-03 23:19:01 +00:00
|
|
|
|
|
2001-07-17 15:39:12 +00:00
|
|
|
|
// now check if we hit an inset so it has to be a inset containing text!
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (cursor.pos() < cursorPar()->size() &&
|
|
|
|
|
cursorPar()->isInset(cursor.pos())) {
|
2001-07-17 15:39:12 +00:00
|
|
|
|
// lock the inset!
|
2003-05-16 07:44:00 +00:00
|
|
|
|
FuncRequest cmd(bv(), LFUN_INSET_EDIT, "left");
|
2003-10-17 18:01:15 +00:00
|
|
|
|
cursorPar()->getInset(cursor.pos())->dispatch(cmd);
|
2001-07-17 15:39:12 +00:00
|
|
|
|
// now call us again to do the above trick
|
2001-07-20 14:18:48 +00:00
|
|
|
|
// but obviously we have to start from down below ;)
|
2003-03-17 16:25:00 +00:00
|
|
|
|
return bv()->text->selectNextWordToSpellcheck(value);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Update the value if we changed paragraphs
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (cursor.par() != tmppar) {
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(cursor.par(), cursor.pos());
|
2000-06-08 23:16:16 +00:00
|
|
|
|
value = float(cursor.y())/float(height);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
// Start the selection from here
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.cursor = cursor;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-09 10:52:12 +00:00
|
|
|
|
string lang_code = getFont(cursorPar(), cursor.pos()).language()->code();
|
2001-11-13 14:47:35 +00:00
|
|
|
|
// and find the end of the word (insets like optional hyphens
|
|
|
|
|
// and ligature break are part of a word)
|
2003-10-09 10:52:12 +00:00
|
|
|
|
while (cursor.pos() < cursorPar()->size()
|
|
|
|
|
&& cursorPar()->isLetter(cursor.pos())
|
|
|
|
|
&& !isDeletedText(*cursorPar(), cursor.pos()))
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cursor.pos(cursor.pos() + 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Finally, we copy the word to a string and return it
|
2000-09-14 17:53:12 +00:00
|
|
|
|
string str;
|
2001-05-31 02:23:46 +00:00
|
|
|
|
if (selection.cursor.pos() < cursor.pos()) {
|
2003-10-21 16:15:14 +00:00
|
|
|
|
for (pos_type i = selection.cursor.pos(); i < cursor.pos(); ++i) {
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (!cursorPar()->isInset(i))
|
|
|
|
|
str += cursorPar()->getChar(i);
|
2001-05-31 02:23:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-08-06 22:38:44 +00:00
|
|
|
|
return WordLangTuple(str, lang_code);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// This one is also only for the spellchecker
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::selectSelectedWord()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-07-17 15:39:12 +00:00
|
|
|
|
if (the_locking_inset) {
|
2003-03-17 16:25:00 +00:00
|
|
|
|
the_locking_inset->selectSelectedWord(bv());
|
2001-07-17 15:39:12 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2001-05-31 02:23:46 +00:00
|
|
|
|
// move cursor to the beginning
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(selection.cursor.par(), selection.cursor.pos());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
// set the sel cursor
|
|
|
|
|
selection.cursor = cursor;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
// now find the end of the word
|
2003-10-09 10:52:12 +00:00
|
|
|
|
while (cursor.pos() < cursorPar()->size()
|
|
|
|
|
&& cursorPar()->isLetter(cursor.pos()))
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cursor.pos(cursor.pos() + 1);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-09 10:52:12 +00:00
|
|
|
|
setCursor(cursorPar(), cursor.pos());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
// finally set the selection
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setSelection();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// Delete from cursor up to the end of the current or next word.
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::deleteWordForward()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (cursorPar()->empty())
|
2003-03-17 16:25:00 +00:00
|
|
|
|
cursorRight(bv());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else {
|
2000-05-30 15:41:16 +00:00
|
|
|
|
LyXCursor tmpcursor = cursor;
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.set(true); // to avoid deletion
|
2003-03-17 16:25:00 +00:00
|
|
|
|
cursorRightOneWord();
|
|
|
|
|
setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.cursor = cursor;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
cursor = tmpcursor;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setSelection();
|
|
|
|
|
cutSelection(true, false);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// Delete from cursor to start of current or prior word.
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::deleteWordBackward()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (cursorPar()->empty())
|
2003-03-17 16:25:00 +00:00
|
|
|
|
cursorLeft(bv());
|
2002-05-29 12:58:23 +00:00
|
|
|
|
else {
|
|
|
|
|
LyXCursor tmpcursor = cursor;
|
|
|
|
|
selection.set(true); // to avoid deletion
|
2003-03-17 16:25:00 +00:00
|
|
|
|
cursorLeftOneWord();
|
|
|
|
|
setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
|
2002-05-29 12:58:23 +00:00
|
|
|
|
selection.cursor = cursor;
|
|
|
|
|
cursor = tmpcursor;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setSelection();
|
|
|
|
|
cutSelection(true, false);
|
2002-05-29 12:58:23 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
// Kill to end of line.
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::deleteLineForward()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-10-09 10:52:12 +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());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else {
|
2000-05-26 16:13:01 +00:00
|
|
|
|
LyXCursor tmpcursor = cursor;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// We can't store the row over a regular setCursor
|
2000-06-08 23:16:16 +00:00
|
|
|
|
// so we set it to 0 and reset it afterwards.
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.set(true); // to avoid deletion
|
2003-03-17 16:25:00 +00:00
|
|
|
|
cursorEnd();
|
|
|
|
|
setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.cursor = cursor;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
cursor = tmpcursor;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setSelection();
|
2000-05-30 15:41:16 +00:00
|
|
|
|
// What is this test for ??? (JMarc)
|
2001-06-27 14:10:35 +00:00
|
|
|
|
if (!selection.set()) {
|
2003-03-17 16:25:00 +00:00
|
|
|
|
deleteWordForward();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else {
|
2003-03-17 16:25:00 +00:00
|
|
|
|
cutSelection(true, false);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::changeCase(LyXText::TextCase action)
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
2001-06-27 14:10:35 +00:00
|
|
|
|
LyXCursor from;
|
|
|
|
|
LyXCursor to;
|
2001-03-09 00:56:42 +00:00
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
if (selection.set()) {
|
2001-06-27 18:29:18 +00:00
|
|
|
|
from = selection.start;
|
|
|
|
|
to = selection.end;
|
2001-06-27 14:10:35 +00:00
|
|
|
|
} else {
|
2003-07-01 11:51:20 +00:00
|
|
|
|
from = cursor;
|
2003-10-09 10:52:12 +00:00
|
|
|
|
::getWord(*this, from, to, lyx::PARTIAL_WORD, ownerParagraphs());
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(to.par(), to.pos() + 1);
|
2001-06-27 14:10:35 +00:00
|
|
|
|
}
|
2001-03-09 00:56:42 +00:00
|
|
|
|
|
2003-10-14 13:01:49 +00:00
|
|
|
|
recordUndo(Undo::ATOMIC, this, from.par(), to.par());
|
2001-06-27 15:33:55 +00:00
|
|
|
|
|
2001-11-26 16:42:04 +00:00
|
|
|
|
pos_type pos = from.pos();
|
2003-10-09 10:52:12 +00:00
|
|
|
|
int par = from.par();
|
2001-06-27 18:29:18 +00:00
|
|
|
|
|
2003-10-09 10:52:12 +00:00
|
|
|
|
while (par != int(ownerParagraphs().size()) &&
|
|
|
|
|
(pos != to.pos() || par != to.par())) {
|
|
|
|
|
ParagraphList::iterator pit = getPar(par);
|
2003-04-09 09:15:20 +00:00
|
|
|
|
if (pos == pit->size()) {
|
2003-10-09 10:52:12 +00:00
|
|
|
|
++par;
|
2002-07-01 21:50:54 +00:00
|
|
|
|
pos = 0;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2003-04-09 09:15:20 +00:00
|
|
|
|
unsigned char c = pit->getChar(pos);
|
2003-09-16 12:12:33 +00:00
|
|
|
|
if (c != Paragraph::META_INSET) {
|
2001-06-27 15:33:55 +00:00
|
|
|
|
switch (action) {
|
|
|
|
|
case text_lowercase:
|
2001-10-16 14:47:10 +00:00
|
|
|
|
c = lowercase(c);
|
2001-06-27 15:33:55 +00:00
|
|
|
|
break;
|
|
|
|
|
case text_capitalization:
|
2001-10-16 14:47:10 +00:00
|
|
|
|
c = uppercase(c);
|
2001-06-27 15:33:55 +00:00
|
|
|
|
action = text_lowercase;
|
|
|
|
|
break;
|
|
|
|
|
case text_uppercase:
|
2001-10-16 14:47:10 +00:00
|
|
|
|
c = uppercase(c);
|
2001-06-27 15:33:55 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-02-08 19:18:01 +00:00
|
|
|
|
#warning changes
|
2003-04-09 09:15:20 +00:00
|
|
|
|
pit->setChar(pos, c);
|
2001-06-27 18:29:18 +00:00
|
|
|
|
++pos;
|
2001-06-27 15:33:55 +00:00
|
|
|
|
}
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::Delete()
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
|
|
|
|
// this is a very easy implementation
|
|
|
|
|
|
|
|
|
|
LyXCursor old_cursor = cursor;
|
2003-10-09 10:52:12 +00:00
|
|
|
|
int const old_cur_par_id = cursorPar()->id();
|
2003-04-13 01:04:04 +00:00
|
|
|
|
int const old_cur_par_prev_id =
|
2003-10-09 10:52:12 +00:00
|
|
|
|
old_cursor.par() ? getPar(old_cursor.par() - 1)->id() : -1;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
|
// just move to the right
|
2003-03-17 16:25:00 +00:00
|
|
|
|
cursorRight(bv());
|
2000-02-10 17:53:36 +00:00
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// CHECK Look at the comment here.
|
2000-02-10 17:53:36 +00:00
|
|
|
|
// This check is not very good...
|
2003-10-09 10:52:12 +00:00
|
|
|
|
// The cursorRightIntern calls DeleteEmptyParagraphMechanism
|
2000-02-10 17:53:36 +00:00
|
|
|
|
// and that can very well delete the par or par->previous in
|
|
|
|
|
// old_cursor. Will a solution where we compare paragraph id's
|
|
|
|
|
//work better?
|
2003-10-09 10:52:12 +00:00
|
|
|
|
int iid = cursor.par() ? getPar(cursor.par() - 1)->id() : -1;
|
|
|
|
|
if (iid == old_cur_par_prev_id && cursorPar()->id() != old_cur_par_id) {
|
2001-11-15 00:39:11 +00:00
|
|
|
|
// delete-empty-paragraph-mechanism has done it
|
|
|
|
|
return;
|
2001-08-08 14:36:56 +00:00
|
|
|
|
}
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
|
// if you had success make a backspace
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
|
2003-10-14 13:01:49 +00:00
|
|
|
|
recordUndo(Undo::DELETE, this, old_cursor.par());
|
2003-03-17 16:25:00 +00:00
|
|
|
|
backspace();
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::backspace()
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
|
|
|
|
// Get the font that is used to calculate the baselineskip
|
2003-10-09 10:52:12 +00:00
|
|
|
|
ParagraphList::iterator pit = cursorPar();
|
|
|
|
|
pos_type lastpos = pit->size();
|
2000-02-10 17:53:36 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (cursor.pos() == 0) {
|
2000-09-23 04:57:18 +00:00
|
|
|
|
// The cursor is at the beginning of a paragraph,
|
|
|
|
|
// so the the backspace will collapse two paragraphs into one.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
// but it's not allowed unless it's new
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (pit->isChangeEdited(0, pit->size()))
|
2003-02-08 19:18:01 +00:00
|
|
|
|
return;
|
2003-03-03 23:19:01 +00:00
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
|
// we may paste some paragraphs
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
|
// is it an empty paragraph?
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (lastpos == 0 || (lastpos == 1 && pit->isSeparator(0))) {
|
2003-08-08 15:48:57 +00:00
|
|
|
|
// This is an empty paragraph and we delete it just
|
|
|
|
|
// by moving the cursor one step
|
|
|
|
|
// left and let the DeleteEmptyParagraphMechanism
|
2003-08-11 09:09:01 +00:00
|
|
|
|
// handle the actual deletion of the paragraph.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (cursor.par()) {
|
|
|
|
|
ParagraphList::iterator tmppit = getPar(cursor.par() - 1);
|
|
|
|
|
if (cursorPar()->layout() == tmppit->layout()
|
|
|
|
|
&& cursorPar()->getAlign() == tmppit->getAlign()) {
|
2001-03-06 14:07:14 +00:00
|
|
|
|
// Inherit bottom DTD from the paragraph below.
|
2000-03-16 06:08:30 +00:00
|
|
|
|
// (the one we are deleting)
|
2003-10-09 10:52:12 +00:00
|
|
|
|
tmppit->params().lineBottom(cursorPar()->params().lineBottom());
|
|
|
|
|
tmppit->params().spaceBottom(cursorPar()->params().spaceBottom());
|
|
|
|
|
tmppit->params().pagebreakBottom(cursorPar()->params().pagebreakBottom());
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
cursorLeft(bv());
|
2003-08-22 12:00:58 +00:00
|
|
|
|
|
|
|
|
|
// the layout things can change the height of a row !
|
2003-08-22 12:38:21 +00:00
|
|
|
|
redoParagraph();
|
2000-02-10 17:53:36 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-07-24 21:49:58 +00:00
|
|
|
|
|
2003-10-13 10:59:31 +00:00
|
|
|
|
if (cursor.par() != 0)
|
2003-10-14 13:01:49 +00:00
|
|
|
|
recordUndo(Undo::DELETE, this, cursor.par() - 1, cursor.par());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-09 10:52:12 +00:00
|
|
|
|
ParagraphList::iterator tmppit = cursorPar();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// We used to do cursorLeftIntern() here, but it is
|
2000-03-28 02:18:52 +00:00
|
|
|
|
// not a good idea since it triggers the auto-delete
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// mechanism. So we do a cursorLeftIntern()-lite,
|
2000-03-28 02:18:52 +00:00
|
|
|
|
// without the dreaded mechanism. (JMarc)
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (cursor.par() != 0) {
|
2000-03-28 02:18:52 +00:00
|
|
|
|
// steps into the above paragraph.
|
2003-10-09 10:52:12 +00:00
|
|
|
|
setCursorIntern(cursor.par() - 1,
|
|
|
|
|
getPar(cursor.par() - 1)->size(),
|
2002-03-21 17:27:08 +00:00
|
|
|
|
false);
|
2000-03-28 02:18:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// Pasting is not allowed, if the paragraphs have different
|
|
|
|
|
// layout. I think it is a real bug of all other
|
|
|
|
|
// word processors to allow it. It confuses the user.
|
2003-08-27 15:38:23 +00:00
|
|
|
|
// Correction: Pasting is always allowed with standard-layout
|
2003-09-09 09:47:59 +00:00
|
|
|
|
Buffer & buf = *bv()->buffer();
|
|
|
|
|
BufferParams const & bufparams = buf.params();
|
|
|
|
|
LyXTextClass const & tclass = bufparams.getLyXTextClass();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (cursorPar() != tmppit
|
|
|
|
|
&& (cursorPar()->layout() == tmppit->layout()
|
2003-04-09 09:15:20 +00:00
|
|
|
|
|| tmppit->layout() == tclass.defaultLayout())
|
2003-10-09 10:52:12 +00:00
|
|
|
|
&& cursorPar()->getAlign() == tmppit->getAlign()) {
|
2003-09-09 09:47:59 +00:00
|
|
|
|
mergeParagraph(bufparams,
|
2003-10-09 10:52:12 +00:00
|
|
|
|
buf.paragraphs(), cursorPar());
|
2003-08-11 09:09:01 +00:00
|
|
|
|
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (cursor.pos() && cursorPar()->isSeparator(cursor.pos() - 1))
|
2003-08-11 09:09:01 +00:00
|
|
|
|
cursor.pos(cursor.pos() - 1);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
|
// the row may have changed, block, hfills etc.
|
2003-08-11 09:09:01 +00:00
|
|
|
|
updateCounters();
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(cursor.par(), cursor.pos(), false);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2002-05-29 12:58:23 +00:00
|
|
|
|
// this is the code for a normal backspace, not pasting
|
2002-06-24 20:28:12 +00:00
|
|
|
|
// any paragraphs
|
2003-10-14 13:01:49 +00:00
|
|
|
|
recordUndo(Undo::DELETE, this, cursor.par());
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// We used to do cursorLeftIntern() here, but it is
|
2000-03-28 16:18:02 +00:00
|
|
|
|
// not a good idea since it triggers the auto-delete
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// mechanism. So we do a cursorLeftIntern()-lite,
|
2000-03-28 16:18:02 +00:00
|
|
|
|
// without the dreaded mechanism. (JMarc)
|
2003-08-08 15:48:57 +00:00
|
|
|
|
setCursorIntern(cursor.par(), cursor.pos() - 1,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
false, cursor.boundary());
|
2003-10-09 10:52:12 +00:00
|
|
|
|
cursorPar()->erase(cursor.pos());
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
2000-05-30 19:31:11 +00:00
|
|
|
|
|
2003-10-09 10:52:12 +00:00
|
|
|
|
lastpos = cursorPar()->size();
|
2000-12-05 14:15:44 +00:00
|
|
|
|
if (cursor.pos() == lastpos)
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCurrentFont();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-08-08 15:34:17 +00:00
|
|
|
|
redoParagraph();
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
return getPar(cursor.par());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ParagraphList::iterator LyXText::getPar(LyXCursor const & cur) const
|
|
|
|
|
{
|
|
|
|
|
return getPar(cur.par());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ParagraphList::iterator LyXText::getPar(int par) const
|
|
|
|
|
{
|
2003-10-10 09:01:23 +00:00
|
|
|
|
BOOST_ASSERT(par >= 0);
|
2003-10-13 10:59:31 +00:00
|
|
|
|
BOOST_ASSERT(par < int(ownerParagraphs().size()));
|
2003-10-09 10:52:12 +00:00
|
|
|
|
ParagraphList::iterator pit = ownerParagraphs().begin();
|
|
|
|
|
std::advance(pit, par);
|
|
|
|
|
return pit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-06-27 08:38:41 +00:00
|
|
|
|
RowList::iterator LyXText::cursorRow() const
|
|
|
|
|
{
|
2003-10-17 10:31:47 +00:00
|
|
|
|
return getRow(*cursorPar(), cursor.pos());
|
2003-06-27 08:38:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RowList::iterator LyXText::getRow(LyXCursor const & cur) const
|
|
|
|
|
{
|
2003-10-17 10:31:47 +00:00
|
|
|
|
return getRow(*getPar(cur), cur.pos());
|
2003-06-27 08:38:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-17 10:31:47 +00:00
|
|
|
|
RowList::iterator LyXText::getRow(Paragraph & par, pos_type pos) const
|
2003-06-27 08:38:41 +00:00
|
|
|
|
{
|
2003-10-17 10:31:47 +00:00
|
|
|
|
RowList::iterator rit = boost::prior(par.rows.end());
|
|
|
|
|
RowList::iterator const begin = par.rows.begin();
|
2003-08-14 11:16:31 +00:00
|
|
|
|
|
2003-08-25 10:24:26 +00:00
|
|
|
|
while (rit != begin && rit->pos() > pos)
|
|
|
|
|
--rit;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-03-30 07:27:36 +00:00
|
|
|
|
return rit;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-11-26 16:42:04 +00:00
|
|
|
|
|
2003-07-18 07:47:07 +00:00
|
|
|
|
|
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-08-25 10:24:26 +00:00
|
|
|
|
pit = boost::prior(ownerParagraphs().end());
|
|
|
|
|
|
|
|
|
|
RowList::iterator rit = lastRow();
|
|
|
|
|
RowList::iterator rbegin = firstRow();
|
|
|
|
|
|
2003-10-17 10:31:47 +00:00
|
|
|
|
while (rit != rbegin && int(pit->y + rit->y_offset()) > y)
|
2003-08-25 10:24:26 +00:00
|
|
|
|
previousRow(pit, rit);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-08-18 08:35:25 +00:00
|
|
|
|
return rit;
|
2001-11-26 16:42:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int LyXText::getDepth() const
|
|
|
|
|
{
|
2003-10-09 10:52:12 +00:00
|
|
|
|
return cursorPar()->getDepth();
|
2001-11-26 16:42:04 +00:00
|
|
|
|
}
|
2003-08-14 08:34:13 +00:00
|
|
|
|
|
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
|
RowList::iterator LyXText::firstRow() const
|
2003-08-14 08:34:13 +00:00
|
|
|
|
{
|
2003-08-15 08:03:54 +00:00
|
|
|
|
return ownerParagraphs().front().rows.begin();
|
2003-08-14 08:34:13 +00:00
|
|
|
|
}
|
2003-08-14 11:16:31 +00:00
|
|
|
|
|
|
|
|
|
|
2003-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-08-15 08:03:54 +00:00
|
|
|
|
RowList::iterator LyXText::endRow() const
|
2003-08-14 11:16:31 +00:00
|
|
|
|
{
|
2003-08-15 08:03:54 +00:00
|
|
|
|
return ownerParagraphs().back().rows.end();
|
2003-08-14 11:16:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
|
void LyXText::nextRow(ParagraphList::iterator & pit,
|
|
|
|
|
RowList::iterator & rit) const
|
2003-08-14 14:10:13 +00:00
|
|
|
|
{
|
2003-08-18 08:35:25 +00:00
|
|
|
|
++rit;
|
|
|
|
|
if (rit == pit->rows.end()) {
|
2003-08-15 08:03:54 +00:00
|
|
|
|
++pit;
|
|
|
|
|
if (pit == ownerParagraphs().end())
|
2003-08-18 08:35:25 +00:00
|
|
|
|
--pit;
|
2003-08-15 08:03:54 +00:00
|
|
|
|
else
|
|
|
|
|
rit = pit->rows.begin();
|
|
|
|
|
}
|
2003-08-14 14:10:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
|
void LyXText::previousRow(ParagraphList::iterator & pit,
|
|
|
|
|
RowList::iterator & rit) const
|
2003-08-14 11:16:31 +00:00
|
|
|
|
{
|
2003-08-15 08:03:54 +00:00
|
|
|
|
if (rit != pit->rows.begin())
|
2003-08-18 08:35:25 +00:00
|
|
|
|
--rit;
|
2003-08-15 08:03:54 +00:00
|
|
|
|
else {
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(pit != ownerParagraphs().begin());
|
2003-08-15 08:03:54 +00:00
|
|
|
|
--pit;
|
|
|
|
|
rit = boost::prior(pit->rows.end());
|
|
|
|
|
}
|
2003-08-14 11:16:31 +00:00
|
|
|
|
}
|
2003-10-09 10:52:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string LyXText::selectionAsString(Buffer const & buffer, bool label) const
|
|
|
|
|
{
|
|
|
|
|
if (!selection.set())
|
|
|
|
|
return string();
|
|
|
|
|
|
|
|
|
|
// should be const ...
|
|
|
|
|
ParagraphList::iterator startpit = getPar(selection.start);
|
|
|
|
|
ParagraphList::iterator endpit = getPar(selection.end);
|
|
|
|
|
size_t const startpos = selection.start.pos();
|
|
|
|
|
size_t const endpos = selection.end.pos();
|
|
|
|
|
|
|
|
|
|
if (startpit == endpit)
|
|
|
|
|
return startpit->asString(buffer, startpos, endpos, label);
|
|
|
|
|
|
|
|
|
|
// First paragraph in selection
|
|
|
|
|
string result =
|
|
|
|
|
startpit->asString(buffer, startpos, startpit->size(), label) + "\n\n";
|
|
|
|
|
|
|
|
|
|
// The paragraphs in between (if any)
|
|
|
|
|
ParagraphList::iterator pit = startpit;
|
|
|
|
|
for (++pit; pit != endpit; ++pit)
|
|
|
|
|
result += pit->asString(buffer, 0, pit->size(), label) + "\n\n";
|
|
|
|
|
|
|
|
|
|
// Last paragraph in selection
|
|
|
|
|
result += endpit->asString(buffer, 0, endpos, label);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int LyXText::parOffset(ParagraphList::iterator pit) const
|
|
|
|
|
{
|
|
|
|
|
return std::distance(ownerParagraphs().begin(), pit);
|
|
|
|
|
}
|
2003-10-17 10:31:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int LyXText::redoParagraphInternal(ParagraphList::iterator pit)
|
|
|
|
|
{
|
|
|
|
|
// remove rows of paragraph, keep track of height changes
|
|
|
|
|
height -= pit->height;
|
|
|
|
|
pit->rows.clear();
|
|
|
|
|
|
|
|
|
|
// redo insets
|
|
|
|
|
InsetList::iterator ii = pit->insetlist.begin();
|
|
|
|
|
InsetList::iterator iend = pit->insetlist.end();
|
|
|
|
|
for (; ii != iend; ++ii) {
|
|
|
|
|
Dimension dim;
|
|
|
|
|
MetricsInfo mi(bv(), getFont(pit, ii->pos), workWidth());
|
|
|
|
|
ii->inset->metrics(mi, dim);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// rebreak the paragraph
|
|
|
|
|
int par_width = 0;
|
|
|
|
|
int const ww = workWidth();
|
|
|
|
|
pit->height = 0;
|
|
|
|
|
|
|
|
|
|
for (pos_type z = 0; z < pit->size() + 1; ) {
|
|
|
|
|
Row row(z);
|
|
|
|
|
z = rowBreakPoint(pit, row) + 1;
|
|
|
|
|
row.end(z);
|
|
|
|
|
pit->rows.push_back(row);
|
2003-10-21 16:15:14 +00:00
|
|
|
|
RowList::iterator rit = boost::prior(pit->rows.end());
|
2003-10-17 10:31:47 +00:00
|
|
|
|
int const f = fill(pit, *rit, ww);
|
|
|
|
|
int const w = ww - f;
|
|
|
|
|
par_width = std::max(par_width, w);
|
|
|
|
|
rit->fill(f);
|
|
|
|
|
rit->width(w);
|
|
|
|
|
prepareToPrint(pit, rit);
|
|
|
|
|
setHeightOfRow(pit, *rit);
|
|
|
|
|
rit->y_offset(pit->height);
|
|
|
|
|
pit->height += rit->height();
|
|
|
|
|
}
|
|
|
|
|
height += pit->height;
|
|
|
|
|
|
|
|
|
|
//lyxerr << "redoParagraph: " << pit->rows.size() << " rows\n";
|
|
|
|
|
return par_width;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int LyXText::redoParagraphs(ParagraphList::iterator start,
|
|
|
|
|
ParagraphList::iterator end)
|
|
|
|
|
{
|
|
|
|
|
int pars_width = 0;
|
|
|
|
|
for ( ; start != end; ++start) {
|
|
|
|
|
int par_width = redoParagraphInternal(start);
|
|
|
|
|
pars_width = std::max(par_width, pars_width);
|
|
|
|
|
}
|
|
|
|
|
updateRowPositions();
|
|
|
|
|
return pars_width;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXText::redoParagraph(ParagraphList::iterator pit)
|
|
|
|
|
{
|
|
|
|
|
redoParagraphInternal(pit);
|
|
|
|
|
updateRowPositions();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXText::fullRebreak()
|
|
|
|
|
{
|
|
|
|
|
redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end());
|
|
|
|
|
redoCursor();
|
|
|
|
|
selection.cursor = cursor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
|
|
|
|
|
{
|
2003-10-21 16:15:14 +00:00
|
|
|
|
lyxerr << "LyXText::metrics: width: " << mi.base.textwidth
|
|
|
|
|
<< " workWidth: " << workWidth() << "\nfont: " << mi.base.font << endl;
|
2003-10-17 10:31:47 +00:00
|
|
|
|
//BOOST_ASSERT(mi.base.textwidth);
|
|
|
|
|
|
|
|
|
|
// rebuild row cache
|
|
|
|
|
width = 0;
|
|
|
|
|
///height = 0;
|
|
|
|
|
|
|
|
|
|
//anchor_y_ = 0;
|
|
|
|
|
width = redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end());
|
|
|
|
|
|
|
|
|
|
// final dimension
|
|
|
|
|
dim.asc = firstRow()->ascent_of_text();
|
|
|
|
|
dim.des = height - dim.asc;
|
|
|
|
|
dim.wid = std::max(mi.base.textwidth, int(width));
|
|
|
|
|
}
|