1999-09-27 18:44:28 +00:00
|
|
|
/* This file is part of
|
2002-03-21 17:27:08 +00:00
|
|
|
* ======================================================
|
|
|
|
*
|
1999-12-21 06:10:21 +00:00
|
|
|
* LyX, The Document Processor
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
1999-12-21 06:10:21 +00:00
|
|
|
* Copyright 1995 Matthias Ettrich
|
2001-05-30 13:53:44 +00:00
|
|
|
* Copyright 1995-2001 The LyX Team.
|
1999-12-21 06:10:21 +00:00
|
|
|
*
|
|
|
|
* ====================================================== */
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2001-04-17 15:15:59 +00:00
|
|
|
#include "lyxtext.h"
|
2001-11-26 16:42:04 +00:00
|
|
|
#include "lyxrow.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "paragraph.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "gettext.h"
|
|
|
|
#include "bufferparams.h"
|
|
|
|
#include "buffer.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
2002-08-20 13:00:25 +00:00
|
|
|
#include "intl.h"
|
2000-02-03 19:51:27 +00:00
|
|
|
#include "lyxrc.h"
|
2002-05-24 14:34:32 +00:00
|
|
|
#include "encoding.h"
|
2002-05-23 12:08:47 +00:00
|
|
|
#include "frontends/LyXView.h"
|
2002-05-23 09:21:32 +00:00
|
|
|
#include "frontends/Painter.h"
|
2002-05-24 14:34:32 +00:00
|
|
|
#include "frontends/font_metrics.h"
|
2002-05-23 15:43:25 +00:00
|
|
|
#include "frontends/screen.h"
|
2002-08-20 13:00:25 +00:00
|
|
|
#include "frontends/WorkArea.h"
|
2000-10-09 12:30:52 +00:00
|
|
|
#include "bufferview_funcs.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "BufferView.h"
|
2001-04-05 12:26:41 +00:00
|
|
|
#include "language.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "ParagraphParameters.h"
|
2001-07-06 15:57:54 +00:00
|
|
|
#include "undo_funcs.h"
|
2003-07-01 11:51:20 +00:00
|
|
|
#include "text_funcs.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
#include "WordLangTuple.h"
|
2002-08-20 19:41:13 +00:00
|
|
|
#include "paragraph_funcs.h"
|
2003-02-26 17:04:10 +00:00
|
|
|
#include "rowpainter.h"
|
2003-04-01 16:55:48 +00:00
|
|
|
#include "lyxrow_funcs.h"
|
2003-07-17 07:32:01 +00:00
|
|
|
#include "metricsinfo.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-11-15 00:39:11 +00:00
|
|
|
#include "insets/insettext.h"
|
|
|
|
|
|
|
|
#include "support/textutils.h"
|
|
|
|
#include "support/LAssert.h"
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
using namespace lyx::support;
|
|
|
|
|
2000-01-14 18:41:30 +00:00
|
|
|
using std::max;
|
|
|
|
using std::min;
|
2000-03-28 02:18:55 +00:00
|
|
|
using std::endl;
|
2000-04-04 00:19:15 +00:00
|
|
|
using std::pair;
|
2003-07-01 11:51:20 +00:00
|
|
|
|
2001-11-27 10:34:16 +00:00
|
|
|
using lyx::pos_type;
|
2003-07-01 11:51:20 +00:00
|
|
|
using lyx::word_location;
|
|
|
|
|
2003-04-03 00:36:31 +00:00
|
|
|
using namespace bv_funcs;
|
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-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-06-30 23:56:22 +00:00
|
|
|
Assert(bv_owner != 0);
|
2003-03-17 16:25:00 +00:00
|
|
|
return bv_owner;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BufferView * LyXText::bv() const
|
|
|
|
{
|
2003-06-30 23:56:22 +00:00
|
|
|
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-04-12 23:03:05 +00:00
|
|
|
RowList::iterator rit = rows().begin();
|
|
|
|
RowList::iterator rend = rows().end();
|
|
|
|
for (int y = 0; rit != rend ; ++rit) {
|
|
|
|
rit->y(y);
|
2003-03-29 23:11:20 +00:00
|
|
|
y += rit->height();
|
2003-03-06 20:21:21 +00:00
|
|
|
}
|
2003-04-12 23:03:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int LyXText::top_y() const
|
|
|
|
{
|
2003-05-28 16:36:55 +00:00
|
|
|
if (anchor_row_ == rowlist_.end())
|
2003-04-12 23:03:05 +00:00
|
|
|
return 0;
|
2003-05-21 11:39:20 +00:00
|
|
|
|
2003-04-12 23:03:05 +00:00
|
|
|
return anchor_row_->y() + anchor_row_offset_;
|
2003-03-06 20:21:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LyXText::top_y(int newy)
|
|
|
|
{
|
2003-05-21 11:39:20 +00:00
|
|
|
if (rows().empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (isInInset()) {
|
|
|
|
anchor_row_ = rows().begin();
|
|
|
|
anchor_row_offset_ = newy;
|
2003-03-06 20:21:21 +00:00
|
|
|
return;
|
2003-05-21 11:39:20 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 20:21:21 +00:00
|
|
|
lyxerr[Debug::GUI] << "setting top y = " << newy << endl;
|
2003-03-13 10:30:28 +00:00
|
|
|
|
2003-03-06 20:21:21 +00:00
|
|
|
int y = newy;
|
2003-03-30 07:27:36 +00:00
|
|
|
RowList::iterator rit = getRowNearY(y);
|
2003-03-18 17:12:49 +00:00
|
|
|
|
2003-03-30 07:27:36 +00:00
|
|
|
if (rit == anchor_row_ && anchor_row_offset_ == newy - y) {
|
2003-03-18 17:12:49 +00:00
|
|
|
lyxerr[Debug::GUI] << "top_y to same value, skipping update" << endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-03-30 18:42:37 +00:00
|
|
|
anchor_row_ = rit;
|
2003-03-18 16:47:18 +00:00
|
|
|
anchor_row_offset_ = newy - y;
|
2003-03-30 18:42:37 +00:00
|
|
|
lyxerr[Debug::GUI] << "changing reference to row: " << &*anchor_row_
|
2003-03-18 16:47:18 +00:00
|
|
|
<< " offset: " << anchor_row_offset_ << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-30 21:42:09 +00:00
|
|
|
void LyXText::anchor_row(RowList::iterator rit)
|
2003-03-18 16:47:18 +00:00
|
|
|
{
|
|
|
|
int old_y = top_y();
|
|
|
|
anchor_row_offset_ = 0;
|
2003-03-30 21:42:09 +00:00
|
|
|
anchor_row_ = rit;
|
2003-03-18 16:47:18 +00:00
|
|
|
anchor_row_offset_ = old_y - top_y();
|
2003-03-18 23:23:28 +00:00
|
|
|
lyxerr[Debug::GUI] << "anchor_row(): changing reference to row: "
|
2003-04-09 09:15:20 +00:00
|
|
|
<< &*anchor_row_ << " offset: "
|
2003-04-03 17:02:19 +00:00
|
|
|
<< anchor_row_offset_ << endl;
|
2003-03-06 20:21:21 +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-03-17 16:25:00 +00:00
|
|
|
if (the_locking_inset && (the_locking_inset->getLyXText(bv())!= this))
|
|
|
|
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
|
|
|
|
// larger userbase with differenct access patters triggers the bad
|
|
|
|
// 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);
|
|
|
|
return singleWidth(pit, pos, c);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-09 21:34:31 +00:00
|
|
|
int LyXText::singleWidth(ParagraphList::iterator pit,
|
2002-03-21 17:27:08 +00:00
|
|
|
pos_type pos, char c) const
|
2000-02-10 17:53:36 +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-07-27 21:59:06 +00:00
|
|
|
LyXFont const & font = getFont(pit, pos);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
|
|
|
// The most common case is handled first (Asger)
|
|
|
|
if (IsPrintable(c)) {
|
2000-06-08 23:16:16 +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);
|
2000-06-16 15:13:25 +00:00
|
|
|
if (tmpinset) {
|
2003-07-25 21:20:24 +00:00
|
|
|
if (tmpinset->lyxCode() == InsetOld::HFILL_CODE) {
|
2003-03-11 15:01:29 +00:00
|
|
|
// Because of the representation as vertical lines
|
|
|
|
return 3;
|
|
|
|
}
|
2003-07-22 11:54:39 +00:00
|
|
|
#if 0
|
2003-07-28 22:34:48 +00:00
|
|
|
#warning enabling this fixes the 'insets of width 0 on load' problem
|
2001-12-04 16:10:19 +00:00
|
|
|
// this IS needed otherwise on initialitation we don't get the fill
|
|
|
|
// of the row right (ONLY on initialization if we read a file!)
|
|
|
|
// should be changed! (Jug 20011204)
|
2003-07-17 07:32:01 +00:00
|
|
|
//tmpinset->update(bv());
|
|
|
|
Dimension dim;
|
2003-07-18 07:47:07 +00:00
|
|
|
MetricsInfo mi(bv(), font, workWidth());
|
2003-07-25 17:11:25 +00:00
|
|
|
tmpinset->metrics(mi, dim);
|
2003-07-17 07:32:01 +00:00
|
|
|
return dim.wid;
|
2003-07-25 17:11:25 +00:00
|
|
|
#else
|
2003-07-18 07:47:07 +00:00
|
|
|
return tmpinset->width();
|
|
|
|
#endif
|
2003-03-11 15:01:29 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
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
|
|
|
{
|
|
|
|
if (bidi_start == -1)
|
|
|
|
return pos;
|
|
|
|
else
|
2003-04-03 17:02:19 +00:00
|
|
|
return 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
|
|
|
{
|
|
|
|
if (bidi_start == -1)
|
|
|
|
return pos;
|
|
|
|
else
|
2003-04-03 17:02:19 +00:00
|
|
|
return 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
|
|
|
{
|
|
|
|
if (bidi_start == -1)
|
|
|
|
return 0;
|
|
|
|
else
|
2003-04-03 17:02:19 +00:00
|
|
|
return 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
|
|
|
{
|
|
|
|
return bidi_start == -1 ||
|
|
|
|
(bidi_start <= pos && pos <= bidi_end);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-30 21:42:09 +00:00
|
|
|
void LyXText::computeBidiTables(Buffer const * buf,
|
2003-04-01 16:55:48 +00:00
|
|
|
RowList::iterator 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-04-13 12:56:48 +00:00
|
|
|
ParagraphList::iterator row_par = row->par();
|
|
|
|
|
2003-07-25 21:20:24 +00:00
|
|
|
InsetOld * inset = row_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-04-01 16:55:48 +00:00
|
|
|
bidi_start = row->pos();
|
|
|
|
bidi_end = lastPrintablePos(*this, 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
|
|
|
|
2001-11-26 16:42:04 +00:00
|
|
|
pos_type stack[2];
|
2000-11-21 15:46:13 +00:00
|
|
|
bool const rtl_par =
|
2003-04-13 12:56:48 +00:00
|
|
|
row_par->isRightToLeftPar(buf->params);
|
2000-04-10 21:40:13 +00:00
|
|
|
int level = 0;
|
|
|
|
bool rtl = false;
|
|
|
|
bool rtl0 = false;
|
2003-04-13 12:56:48 +00:00
|
|
|
pos_type const body_pos = row_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-04-13 12:56:48 +00:00
|
|
|
bool is_space = row_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-04-13 12:56:48 +00:00
|
|
|
!row_par->isLineSeparator(lpos + 1) &&
|
|
|
|
!row_par->isNewline(lpos + 1))
|
2000-04-10 21:40:13 +00:00
|
|
|
? lpos + 1 : lpos;
|
2003-04-13 12:56:48 +00:00
|
|
|
LyXFont font = row_par->getFontSettings(buf->params, pos);
|
2000-10-09 12:30:52 +00:00
|
|
|
if (pos != lpos && 0 < lpos && rtl0 && font.isRightToLeft() &&
|
|
|
|
font.number() == LyXFont::ON &&
|
2003-04-13 12:56:48 +00:00
|
|
|
row_par->getFontSettings(buf->params, lpos - 1).number()
|
2000-10-09 12:30:52 +00:00
|
|
|
== LyXFont::ON) {
|
2003-04-13 12:56:48 +00:00
|
|
|
font = row_par->getFontSettings(buf->params, 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-04-01 16:55:48 +00:00
|
|
|
&& row->pos() < body_pos - 1
|
2000-10-09 12:30:52 +00:00
|
|
|
&& is_space) {
|
2000-04-10 21:40:13 +00:00
|
|
|
new_level = (rtl_par) ? 1 : 0;
|
|
|
|
new_rtl = new_rtl0 = rtl_par;
|
|
|
|
} else if (new_rtl0)
|
|
|
|
new_level = (new_rtl) ? 1 : 2;
|
|
|
|
else
|
|
|
|
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;
|
|
|
|
log2vis_list[lpos - bidi_start] = (rtl) ? 1 : -1;
|
|
|
|
} else if (level < new_level) {
|
|
|
|
log2vis_list[lpos - bidi_start] = (rtl) ? -1 : 1;
|
|
|
|
if (new_level > rtl_par)
|
|
|
|
bidi_same_direction = false;
|
|
|
|
} else
|
|
|
|
log2vis_list[lpos - bidi_start] = (new_rtl) ? -1 : 1;
|
|
|
|
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-04-13 01:04:04 +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)) {
|
2001-01-17 19:00:12 +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-04-13 01:04:04 +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-04-13 01:04:04 +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-04-13 01:04:04 +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-04-01 16:55:48 +00:00
|
|
|
int LyXText::leftMargin(Row const & row) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2003-07-25 21:20:24 +00:00
|
|
|
InsetOld * ins;
|
2003-03-13 10:30:28 +00:00
|
|
|
|
2003-04-01 16:55:48 +00:00
|
|
|
if (row.pos() < row.par()->size())
|
|
|
|
if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
|
|
|
|
(ins = row.par()->getInset(row.pos())) &&
|
2003-03-13 10:30:28 +00:00
|
|
|
(ins->needFullRow() || ins->display()))
|
|
|
|
return LEFT_MARGIN;
|
2002-04-12 08:22:16 +00:00
|
|
|
|
2001-10-16 14:47:10 +00:00
|
|
|
LyXTextClass const & tclass =
|
2003-03-17 16:25:00 +00:00
|
|
|
bv()->buffer()->params.getLyXTextClass();
|
2003-04-01 16:55:48 +00:00
|
|
|
LyXLayout_ptr const & layout = row.par()->layout();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
string parindent = layout->parindent;
|
2000-06-08 23:16:16 +00:00
|
|
|
|
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-04-01 16:55:48 +00:00
|
|
|
if (!row.par()->getDepth()) {
|
|
|
|
if (row.par()->layout() == tclass.defaultLayout()) {
|
2000-01-13 16:28:54 +00:00
|
|
|
// find the previous same level paragraph
|
2003-04-13 01:04:04 +00:00
|
|
|
if (row.par() != ownerParagraphs().begin()) {
|
2003-04-16 08:12:22 +00:00
|
|
|
ParagraphList::iterator newpit =
|
|
|
|
depthHook(row.par(), ownerParagraphs(),
|
|
|
|
row.par()->getDepth());
|
|
|
|
if (newpit == row.par() &&
|
|
|
|
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-04-16 08:12:22 +00:00
|
|
|
ParagraphList::iterator newpar = outerHook(row.par(),
|
|
|
|
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()) {
|
2000-01-21 17:41:57 +00:00
|
|
|
Row dummyrow;
|
2000-06-08 23:16:16 +00:00
|
|
|
dummyrow.par(newpar);
|
2001-03-11 00:21:13 +00:00
|
|
|
dummyrow.pos(newpar->size());
|
2003-04-01 16:55:48 +00:00
|
|
|
x = leftMargin(dummyrow);
|
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() &&
|
|
|
|
row.par()->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-07-27 21:59:06 +00:00
|
|
|
LyXFont const labelfont = getLabelFont(row.par());
|
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-04-01 16:55:48 +00:00
|
|
|
if (!row.par()->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-04-01 16:55:48 +00:00
|
|
|
x += font_metrics::width(row.par()->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-04-01 16:55:48 +00:00
|
|
|
if (!row.par()->empty() && row.pos() >= row.par()->beginningOfBody()) {
|
|
|
|
if (!row.par()->getLabelWidthString().empty()) {
|
|
|
|
x += font_metrics::width(row.par()->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-04-01 16:55:48 +00:00
|
|
|
/ (row.par()->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-04-01 16:55:48 +00:00
|
|
|
if (row.pos() >= row.par()->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-04-16 08:12:22 +00:00
|
|
|
&& !isFirstInSequence(row.par(), 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-04-01 16:55:48 +00:00
|
|
|
x += font_metrics::width(row.par()->getLabelstring(),
|
2000-06-08 23:16:16 +00:00
|
|
|
labelfont);
|
2002-03-21 17:27:08 +00:00
|
|
|
}
|
2000-01-13 16:28:54 +00:00
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
case MARGIN_RIGHT_ADDRESS_BOX:
|
|
|
|
{
|
|
|
|
// ok, a terrible hack. The left margin depends on the widest
|
|
|
|
// row in this paragraph. Do not care about footnotes, they
|
|
|
|
// are *NOT* allowed in the LaTeX realisation of this layout.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
// find the first row of this paragraph
|
2003-04-01 16:55:48 +00:00
|
|
|
RowList::iterator tmprit = rowlist_.begin();
|
|
|
|
while (tmprit != rowlist_.end()
|
|
|
|
&& tmprit->par() != row.par())
|
|
|
|
++tmprit;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2003-03-30 21:42:09 +00:00
|
|
|
int minfill = tmprit->fill();
|
2003-03-31 16:57:45 +00:00
|
|
|
while (boost::next(tmprit) != rowlist_.end() &&
|
2003-04-01 16:55:48 +00:00
|
|
|
boost::next(tmprit)->par() == row.par()) {
|
2003-03-30 21:42:09 +00:00
|
|
|
++tmprit;
|
|
|
|
if (tmprit->fill() < minfill)
|
|
|
|
minfill = tmprit->fill();
|
2000-01-13 16:28:54 +00:00
|
|
|
}
|
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-03-17 16:25:00 +00:00
|
|
|
if ((workWidth() > 0) &&
|
2003-04-01 16:55:48 +00:00
|
|
|
!row.par()->params().leftIndent().zero())
|
2002-05-08 12:58:16 +00:00
|
|
|
{
|
2003-04-01 16:55:48 +00:00
|
|
|
LyXLength const len = row.par()->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-04-01 16:55:48 +00:00
|
|
|
if (row.par()->params().align() == LYX_ALIGN_LAYOUT)
|
2002-06-24 20:28:12 +00:00
|
|
|
align = layout->align;
|
2000-07-19 17:16:27 +00:00
|
|
|
else
|
2003-04-01 16:55:48 +00:00
|
|
|
align = row.par()->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-04-16 08:12:22 +00:00
|
|
|
&& !isFirstInSequence(row.par(), ownerParagraphs())))
|
2000-01-13 16:28:54 +00:00
|
|
|
&& align == LYX_ALIGN_BLOCK
|
2003-04-01 16:55:48 +00:00
|
|
|
&& !row.par()->params().noindent()
|
2002-03-06 10:17:29 +00:00
|
|
|
// in tabulars and ert paragraphs are never indented!
|
2003-04-01 16:55:48 +00:00
|
|
|
&& (!row.par()->inInset() || !row.par()->inInset()->owner() ||
|
2003-07-25 21:20:24 +00:00
|
|
|
(row.par()->inInset()->owner()->lyxCode() != InsetOld::TABULAR_CODE &&
|
|
|
|
row.par()->inInset()->owner()->lyxCode() != InsetOld::ERT_CODE))
|
2003-04-01 16:55:48 +00:00
|
|
|
&& (row.par()->layout() != tclass.defaultLayout() ||
|
2003-03-17 16:25:00 +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-02-26 17:04:10 +00:00
|
|
|
int LyXText::rightMargin(Buffer const & buf, Row const & row) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2003-07-25 21:20:24 +00:00
|
|
|
InsetOld * ins;
|
2003-03-13 10:30:28 +00:00
|
|
|
|
|
|
|
if (row.pos() < row.par()->size())
|
|
|
|
if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
|
2003-03-30 21:42:09 +00:00
|
|
|
(ins = row.par()->getInset(row.pos())) &&
|
2003-03-13 10:30:28 +00:00
|
|
|
(ins->needFullRow() || ins->display()))
|
|
|
|
return PAPER_MARGIN;
|
2002-04-12 08:22:16 +00:00
|
|
|
|
2003-02-26 17:04:10 +00:00
|
|
|
LyXTextClass const & tclass = buf.params.getLyXTextClass();
|
|
|
|
LyXLayout_ptr const & layout = row.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(),
|
2001-10-16 14:47:10 +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-02-26 17:04:10 +00:00
|
|
|
* 4 / (row.par()->getDepth() + 4);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
int LyXText::labelEnd(Row const & row) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2003-02-26 17:04:10 +00:00
|
|
|
if (row.par()->layout()->margintype == MARGIN_MANUAL) {
|
|
|
|
Row tmprow = row;
|
|
|
|
tmprow.pos(row.par()->size());
|
2003-03-09 12:37:22 +00:00
|
|
|
// return the beginning of the body
|
2003-04-01 16:55:48 +00:00
|
|
|
return leftMargin(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-04-13 01:04:04 +00:00
|
|
|
for (; i < par.size(); ++i) {
|
|
|
|
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-06-12 11:09:55 +00:00
|
|
|
pos_type LyXText::rowBreakPoint(Row const & row) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2003-04-02 23:01:39 +00:00
|
|
|
ParagraphList::iterator pit = row.par();
|
2000-06-08 23:16:16 +00:00
|
|
|
|
2003-03-09 21:54:56 +00:00
|
|
|
// maximum pixel width of a row.
|
2003-03-17 16:25:00 +00:00
|
|
|
int width = workWidth() - rightMargin(*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-06-12 11:09:55 +00:00
|
|
|
int const left = leftMargin(row);
|
2003-03-10 04:59:48 +00:00
|
|
|
int x = left;
|
|
|
|
|
|
|
|
// pixel width since last breakpoint
|
|
|
|
int chunkwidth = 0;
|
2003-04-11 00:03:27 +00:00
|
|
|
bool fullrow = false;
|
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-04-02 23:01:39 +00:00
|
|
|
char const c = pit->getChar(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-04-11 03:28:06 +00:00
|
|
|
int left_margin = labelEnd(row);
|
|
|
|
if (thiswidth + x < left_margin)
|
|
|
|
thiswidth = left_margin - x;
|
|
|
|
thiswidth += singleWidth(pit, i, c);
|
|
|
|
} else {
|
2003-07-27 11:16:25 +00:00
|
|
|
// Manual inlined optimised version of common case of "thiswidth = singleWidth(pit, i, c);"
|
|
|
|
if (IsPrintable(c)) {
|
|
|
|
if (pos > endPosOfFontSpan) {
|
|
|
|
// We need to get the next font
|
2003-07-27 21:59:06 +00:00
|
|
|
font = getFont(pit, i);
|
2003-07-27 11:16:25 +00:00
|
|
|
endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
|
|
|
|
}
|
|
|
|
if (! font.language()->RightToLeft()) {
|
|
|
|
thiswidth = font_metrics::width(c, font);
|
|
|
|
} else {
|
|
|
|
// Fall-back to normal case
|
|
|
|
thiswidth = singleWidth(pit, i, c);
|
|
|
|
// And flush font cache
|
|
|
|
endPosOfFontSpan = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Fall-back to normal case
|
|
|
|
thiswidth = singleWidth(pit, i, c);
|
|
|
|
// And flush font cache
|
|
|
|
endPosOfFontSpan = 0;
|
|
|
|
}
|
2003-03-09 21:54:56 +00:00
|
|
|
}
|
|
|
|
|
2003-03-10 04:59:48 +00:00
|
|
|
x += thiswidth;
|
|
|
|
chunkwidth += thiswidth;
|
|
|
|
|
2003-07-25 21:20:24 +00:00
|
|
|
InsetOld * in = pit->isInset(i) ? pit->getInset(i) : 0;
|
2003-07-29 10:00:51 +00:00
|
|
|
fullrow = in && (in->display() || in->needFullRow());
|
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-03-10 04:59:48 +00:00
|
|
|
// if no break before or we are at an inset
|
|
|
|
// that will take up a row, break here
|
2003-03-17 16:33:49 +00:00
|
|
|
if (point == last || fullrow || chunkwidth >= (width - left)) {
|
2003-03-09 21:54:56 +00:00
|
|
|
if (pos < i)
|
|
|
|
point = i - 1;
|
|
|
|
else
|
|
|
|
point = i;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2003-03-09 21:54:56 +00:00
|
|
|
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
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-03-17 16:33:49 +00:00
|
|
|
if (!fullrow)
|
2003-03-10 01:46:40 +00:00
|
|
|
continue;
|
2003-03-13 10:30:28 +00:00
|
|
|
|
2003-03-10 01:46:40 +00:00
|
|
|
// full row insets start at a new row
|
|
|
|
if (i == pos) {
|
|
|
|
if (pos < last - 1) {
|
|
|
|
point = i;
|
2003-04-02 23:01:39 +00:00
|
|
|
if (pit->isLineSeparator(i + 1))
|
2003-03-10 01:46:40 +00:00
|
|
|
++point;
|
2003-03-09 21:54:56 +00:00
|
|
|
} else {
|
2003-03-10 01:46:40 +00:00
|
|
|
// to avoid extra rows
|
|
|
|
point = last;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2003-03-10 01:46:40 +00:00
|
|
|
} else {
|
|
|
|
point = i - 1;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2003-04-11 00:03:27 +00:00
|
|
|
|
|
|
|
return point;
|
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
|
|
|
|
if (!fullrow && 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-04-01 16:55:48 +00:00
|
|
|
int LyXText::fill(RowList::iterator 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-04-01 16:55:48 +00:00
|
|
|
pos_type const last = lastPrintablePos(*this, row);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2003-04-13 12:56:48 +00:00
|
|
|
ParagraphList::iterator pit = row->par();
|
|
|
|
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-04-01 16:55:48 +00:00
|
|
|
int const tmpfill = row->fill();
|
|
|
|
row->fill(0); // the minfill in MarginLeft()
|
|
|
|
w = leftMargin(*row);
|
|
|
|
row->fill(tmpfill);
|
2000-01-13 16:28:54 +00:00
|
|
|
} else
|
2003-04-01 16:55:48 +00:00
|
|
|
w = leftMargin(*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-04-01 16:55:48 +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);
|
|
|
|
int left_margin = labelEnd(*row);
|
|
|
|
if (w < left_margin)
|
|
|
|
w = left_margin;
|
|
|
|
}
|
2003-07-27 10:42:11 +00:00
|
|
|
{ // Manual inlined an optimised version of the common case of "w += singleWidth(pit, i);"
|
|
|
|
char const c = pit->getChar(i);
|
|
|
|
|
|
|
|
if (IsPrintable(c)) {
|
|
|
|
if (i > endPosOfFontSpan) {
|
|
|
|
// We need to get the next font
|
2003-07-27 21:59:06 +00:00
|
|
|
font = getFont(pit, i);
|
2003-07-27 10:42:11 +00:00
|
|
|
endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
|
|
|
|
}
|
2003-07-29 10:00:51 +00:00
|
|
|
if (!font.language()->RightToLeft()) {
|
2003-07-27 10:42:11 +00:00
|
|
|
w += font_metrics::width(c, font);
|
|
|
|
} else {
|
|
|
|
// Fall-back to the normal case
|
|
|
|
w += singleWidth(pit, i, c);
|
|
|
|
// And flush font cache
|
|
|
|
endPosOfFontSpan = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Fall-back to the normal case
|
|
|
|
w += singleWidth(pit, i, c);
|
|
|
|
// And flush font cache
|
|
|
|
endPosOfFontSpan = 0;
|
|
|
|
}
|
|
|
|
}
|
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-04-01 16:55:48 +00:00
|
|
|
int const left_margin = labelEnd(*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-04-01 16:55:48 +00:00
|
|
|
int const fill = paper_width - w - rightMargin(*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
|
|
|
|
<< " right margin " << rightMargin(*bv()->buffer(), *row) << endl;
|
|
|
|
}
|
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-03-17 16:25:00 +00:00
|
|
|
int LyXText::labelFill(Row const & row) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2003-04-13 12:56:48 +00:00
|
|
|
ParagraphList::iterator pit = row.par();
|
|
|
|
|
|
|
|
pos_type last = pit->beginningOfBody();
|
2003-02-26 17:04:10 +00:00
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
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-02-26 17:04:10 +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-03-30 18:42:37 +00:00
|
|
|
void LyXText::setHeightOfRow(RowList::iterator rit)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2003-06-30 23:56:22 +00:00
|
|
|
Assert(rit != rows().end());
|
2003-04-01 16:55:48 +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-02 23:01:39 +00:00
|
|
|
ParagraphList::iterator pit = rit->par();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
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-07-27 21:59:06 +00:00
|
|
|
LyXFont font = getFont(pit, rit->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-03-17 16:25:00 +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-04-01 16:55:48 +00:00
|
|
|
pos_type const pos_end = lastPos(*this, rit);
|
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-07-27 21:59:06 +00:00
|
|
|
LyXFont font = getFont(pit, rit->pos());
|
2003-07-27 11:16:25 +00:00
|
|
|
lyx::pos_type endPosOfFontSpan = pit->getEndPosOfFontSpan(rit->pos());
|
|
|
|
|
|
|
|
// Optimisation
|
|
|
|
Paragraph const & par = *pit;
|
|
|
|
|
2003-03-13 17:50:39 +00:00
|
|
|
// Check if any insets are larger
|
2003-03-30 18:42:37 +00:00
|
|
|
for (pos_type pos = rit->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
|
|
|
|
maxwidth += singleWidth(pit, pos, c);
|
|
|
|
// 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) {
|
2003-07-22 11:54:39 +00:00
|
|
|
#if 1 // this is needed for deep update on initialitation
|
2003-03-20 14:13:49 +00:00
|
|
|
#warning inset->update FIXME
|
2003-07-27 11:16:25 +00:00
|
|
|
//tmpinset->update(bv());
|
2003-08-01 14:12:04 +00:00
|
|
|
LyXFont const tmpfont = getFont(pit, pos);
|
2003-07-27 11:16:25 +00:00
|
|
|
Dimension dim;
|
|
|
|
MetricsInfo mi(bv(), tmpfont, workWidth());
|
|
|
|
tmpinset->metrics(mi, dim);
|
|
|
|
maxwidth += dim.wid;
|
|
|
|
maxasc = max(maxasc, dim.asc);
|
|
|
|
maxdesc = max(maxdesc, dim.des);
|
2003-07-18 07:47:07 +00:00
|
|
|
#else
|
2003-07-27 11:16:25 +00:00
|
|
|
maxwidth += tmpinset->width();
|
|
|
|
maxasc = max(maxasc, tmpinset->ascent());
|
|
|
|
maxdesc = max(maxdesc, tmpinset->descent());
|
2003-07-18 07:47:07 +00:00
|
|
|
#endif
|
2003-07-28 14:40:29 +00:00
|
|
|
}
|
2003-07-27 11:16:25 +00:00
|
|
|
} else {
|
|
|
|
// Fall-back to normal case
|
|
|
|
maxwidth += singleWidth(pit, pos, c);
|
|
|
|
// 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-04-13 12:56:48 +00:00
|
|
|
pit->highestFontInRange(rit->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-03-30 18:42:37 +00:00
|
|
|
rit->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-04-13 12:56:48 +00:00
|
|
|
if (!rit->pos()) {
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-07-31 10:10:17 +00:00
|
|
|
// some parksips VERY EASY IMPLEMENTATION
|
2003-03-17 16:25:00 +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-03-17 16:25:00 +00:00
|
|
|
maxasc += bv()->buffer()->params.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-03-17 16:25:00 +00:00
|
|
|
maxasc += bv()->buffer()->params.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
|
2002-06-24 20:28:12 +00:00
|
|
|
if (layout->labeltype == LABEL_COUNTER_CHAPTER
|
2003-03-17 16:25:00 +00:00
|
|
|
&& bv()->buffer()->params.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-03-17 16:25:00 +00:00
|
|
|
spacing_val = bv()->buffer()->params.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-03-17 16:25:00 +00:00
|
|
|
spacing_val = bv()->buffer()->params.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(
|
2002-05-24 14:34:32 +00:00
|
|
|
(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-05-24 14:34:32 +00:00
|
|
|
+(font_metrics::maxDescent(labelfont) *
|
2002-06-24 20:28:12 +00:00
|
|
|
layout->spacing.getValue() *
|
2001-07-31 10:10:17 +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-03-30 18:42:37 +00:00
|
|
|
} else if (rit != rows().begin()) {
|
2002-06-24 20:28:12 +00:00
|
|
|
tmptop = layout->topsep;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2003-04-13 12:56:48 +00:00
|
|
|
if (boost::prior(pit)->getDepth() >= pit->getDepth())
|
2003-03-30 18:42:37 +00:00
|
|
|
tmptop -= boost::prior(rit)->par()->layout()->bottomsep;
|
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-04-13 12:56:48 +00:00
|
|
|
RowList::iterator next_rit = boost::next(rit);
|
2003-07-16 08:42:26 +00:00
|
|
|
if (next_rit == rows().end() || next_rit->par() != pit) {
|
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);
|
|
|
|
if (nextpit == ownerParagraphs().end() &&
|
2003-04-02 23:01:39 +00:00
|
|
|
!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
|
|
|
|
2001-07-31 10:10:17 +00:00
|
|
|
// calculate the new height of the text
|
2003-03-30 18:42:37 +00:00
|
|
|
height -= rit->height();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2003-03-30 18:42:37 +00:00
|
|
|
rit->height(maxasc + maxdesc + labeladdon);
|
|
|
|
rit->baseline(maxasc + labeladdon);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2003-03-30 18:42:37 +00:00
|
|
|
height += rit->height();
|
2003-03-03 23:19:01 +00:00
|
|
|
|
2003-03-30 18:42:37 +00:00
|
|
|
rit->top_of_text(rit->baseline() - font_metrics::maxAscent(font));
|
2003-02-08 19:18:01 +00:00
|
|
|
|
2003-07-28 12:20:42 +00:00
|
|
|
double x = 0;
|
2002-06-24 20:28:12 +00:00
|
|
|
if (layout->margintype != MARGIN_RIGHT_ADDRESS_BOX) {
|
2002-01-07 16:15:11 +00:00
|
|
|
// this IS needed
|
2003-03-30 18:42:37 +00:00
|
|
|
rit->width(maxwidth);
|
2003-07-29 01:46:09 +00:00
|
|
|
double dummy;
|
2003-03-30 21:42:09 +00:00
|
|
|
prepareToPrint(rit, x, dummy, dummy, dummy, false);
|
2001-10-19 15:40:01 +00:00
|
|
|
}
|
2003-03-30 18:42:37 +00:00
|
|
|
rit->width(int(maxwidth + x));
|
2001-07-31 10:10:17 +00:00
|
|
|
if (inset_owner) {
|
2003-03-17 16:25:00 +00:00
|
|
|
width = max(0, workWidth());
|
2003-03-30 18:42:37 +00:00
|
|
|
RowList::iterator it = rows().begin();
|
2003-03-29 23:11:20 +00:00
|
|
|
RowList::iterator end = rows().end();
|
2003-07-29 01:46:09 +00:00
|
|
|
for (; it != end; ++it)
|
2003-03-30 18:42:37 +00:00
|
|
|
if (it->width() > width)
|
|
|
|
width = it->width();
|
2001-07-31 10:10:17 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-09 21:54:56 +00:00
|
|
|
// Appends the implicit specified paragraph before the specified row,
|
2002-06-24 20:28:12 +00:00
|
|
|
// start at the implicit given position
|
2003-03-29 19:29:30 +00:00
|
|
|
void LyXText::appendParagraph(RowList::iterator rowit)
|
2000-02-17 19:59:08 +00:00
|
|
|
{
|
2003-06-30 23:56:22 +00:00
|
|
|
Assert(rowit != rowlist_.end());
|
2003-03-29 19:29:30 +00:00
|
|
|
|
|
|
|
pos_type const last = rowit->par()->size();
|
2003-03-09 21:54:56 +00:00
|
|
|
bool done = false;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-12-04 16:10:19 +00:00
|
|
|
do {
|
2003-03-29 19:29:30 +00:00
|
|
|
pos_type z = rowBreakPoint(*rowit);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2003-03-29 19:29:30 +00:00
|
|
|
RowList::iterator tmprow = rowit;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2003-03-09 21:54:56 +00:00
|
|
|
if (z < last) {
|
2001-12-04 16:10:19 +00:00
|
|
|
++z;
|
2003-04-01 16:55:48 +00:00
|
|
|
Row newrow(rowit->par(), z);
|
|
|
|
rowit = rowlist_.insert(boost::next(rowit), newrow);
|
2003-03-09 21:54:56 +00:00
|
|
|
} else {
|
|
|
|
done = true;
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-12-04 16:10:19 +00:00
|
|
|
// Set the dimensions of the row
|
|
|
|
// fixed fill setting now by calling inset->update() in
|
|
|
|
// SingleWidth when needed!
|
2003-04-01 16:55:48 +00:00
|
|
|
tmprow->fill(fill(tmprow, workWidth()));
|
|
|
|
setHeightOfRow(tmprow);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
2003-03-09 21:54:56 +00:00
|
|
|
} while (!done);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-30 18:42:37 +00:00
|
|
|
void LyXText::breakAgain(RowList::iterator rit)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2003-06-30 23:56:22 +00:00
|
|
|
Assert(rit != rows().end());
|
2003-03-29 19:29:30 +00:00
|
|
|
|
2001-06-07 14:51:20 +00:00
|
|
|
bool not_ready = true;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-06-07 14:51:20 +00:00
|
|
|
do {
|
2003-03-30 18:42:37 +00:00
|
|
|
pos_type z = rowBreakPoint(*rit);
|
|
|
|
RowList::iterator tmprit = rit;
|
|
|
|
RowList::iterator end = rows().end();
|
2001-06-07 14:51:20 +00:00
|
|
|
|
2003-03-30 18:42:37 +00:00
|
|
|
if (z < rit->par()->size()) {
|
2003-04-13 12:56:48 +00:00
|
|
|
RowList::iterator next_rit = boost::next(rit);
|
|
|
|
|
|
|
|
if (next_rit == end ||
|
|
|
|
(next_rit != end &&
|
|
|
|
next_rit->par() != rit->par())) {
|
2001-06-07 14:51:20 +00:00
|
|
|
// insert a new row
|
|
|
|
++z;
|
2003-04-01 16:55:48 +00:00
|
|
|
Row newrow(rit->par(), z);
|
2003-04-13 12:56:48 +00:00
|
|
|
rit = rowlist_.insert(next_rit, newrow);
|
2001-06-07 14:51:20 +00:00
|
|
|
} else {
|
2003-03-30 18:42:37 +00:00
|
|
|
++rit;
|
2001-06-07 14:51:20 +00:00
|
|
|
++z;
|
2003-03-30 18:42:37 +00:00
|
|
|
if (rit->pos() == z)
|
2003-03-17 16:25:00 +00:00
|
|
|
not_ready = false; // the rest will not change
|
2001-06-07 14:51:20 +00:00
|
|
|
else {
|
2003-03-30 18:42:37 +00:00
|
|
|
rit->pos(z);
|
2001-06-07 14:51:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2002-05-29 12:58:23 +00:00
|
|
|
// if there are some rows too much, delete them
|
|
|
|
// only if you broke the whole paragraph!
|
2003-03-30 18:42:37 +00:00
|
|
|
RowList::iterator tmprit2 = rit;
|
2003-04-01 16:55:48 +00:00
|
|
|
while (boost::next(tmprit2) != end
|
|
|
|
&& boost::next(tmprit2)->par() == rit->par()) {
|
2003-03-30 18:42:37 +00:00
|
|
|
++tmprit2;
|
2001-06-07 14:51:20 +00:00
|
|
|
}
|
2003-03-30 18:42:37 +00:00
|
|
|
while (tmprit2 != rit) {
|
|
|
|
--tmprit2;
|
|
|
|
removeRow(boost::next(tmprit2));
|
2001-06-07 14:51:20 +00:00
|
|
|
}
|
|
|
|
not_ready = false;
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
// set the dimensions of the row
|
2003-04-01 16:55:48 +00:00
|
|
|
tmprit->fill(fill(tmprit, workWidth()));
|
2003-03-30 18:42:37 +00:00
|
|
|
setHeightOfRow(tmprit);
|
2001-06-07 14:51:20 +00:00
|
|
|
} while (not_ready);
|
2000-02-10 17:53:36 +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
|
|
|
|
if (cursor.pos() && cursor.pos() != cursor.par()->size()
|
|
|
|
&& cursor.par()->isChangeEdited(0, cursor.pos()))
|
|
|
|
return;
|
|
|
|
|
2002-03-05 16:13:59 +00:00
|
|
|
LyXTextClass const & tclass =
|
2003-03-17 16:25:00 +00:00
|
|
|
bv()->buffer()->params.getLyXTextClass();
|
2002-06-24 20:28:12 +00:00
|
|
|
LyXLayout_ptr const & layout = cursor.par()->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
|
|
|
|
if (cursor.par()->empty() && !cursor.par()->allowEmpty()
|
|
|
|
&& layout->labeltype != LABEL_SENSITIVE)
|
2002-05-29 12:58:23 +00:00
|
|
|
return;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2003-07-25 19:18:43 +00:00
|
|
|
recordUndo(bv(), Undo::ATOMIC, 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)
|
|
|
|
if (cursor.pos() < cursor.par()->size()
|
|
|
|
&& cursor.par()->isLineSeparator(cursor.pos()))
|
2001-06-25 00:06:33 +00:00
|
|
|
cursor.par()->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-06-07 17:45:43 +00:00
|
|
|
bool const isempty = (cursor.par()->allowEmpty() && cursor.par()->empty());
|
2003-07-25 17:11:25 +00:00
|
|
|
::breakParagraph(bv()->buffer()->params, paragraphs, cursor.par(),
|
2003-07-10 12:26:40 +00:00
|
|
|
cursor.pos(), keep_layout);
|
2000-09-23 04:57:18 +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
|
2002-06-24 20:28:12 +00:00
|
|
|
cursor.par()->applyLayout(tclass.defaultLayout());
|
2002-05-29 12:58:23 +00:00
|
|
|
else
|
|
|
|
// set to standard-layout
|
2003-04-13 02:23:30 +00:00
|
|
|
boost::next(cursor.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()
|
|
|
|
&& !cursorRow()->par()->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-06-27 08:38:41 +00:00
|
|
|
removeParagraph(cursorRow());
|
2002-05-29 12:58:23 +00:00
|
|
|
|
|
|
|
// set the dimensions of the cursor row
|
2003-06-27 08:38:41 +00:00
|
|
|
cursorRow()->fill(fill(cursorRow(), workWidth()));
|
2002-05-29 12:58:23 +00:00
|
|
|
|
2003-06-27 08:38:41 +00:00
|
|
|
setHeightOfRow(cursorRow());
|
2002-05-29 12:58:23 +00:00
|
|
|
|
2003-03-05 09:41:49 +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-04-13 02:23:30 +00:00
|
|
|
ParagraphList::iterator next_par = boost::next(cursor.par());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2003-04-13 02:23:30 +00:00
|
|
|
while (!next_par->empty() && next_par->isNewline(0))
|
|
|
|
next_par->erase(0);
|
|
|
|
|
2003-06-27 08:38:41 +00:00
|
|
|
insertParagraph(next_par, boost::next(cursorRow()));
|
2003-03-17 16:25:00 +00:00
|
|
|
updateCounters();
|
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-03-17 16:25:00 +00:00
|
|
|
setCursor(cursor.par(), 0);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2003-06-27 08:38:41 +00:00
|
|
|
if (boost::next(cursorRow()) != rows().end())
|
|
|
|
breakAgain(boost::next(cursorRow()));
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
// Just a macro to make some thing easier.
|
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-08-01 11:22:13 +00:00
|
|
|
redoParagraph(cursor.par());
|
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-07-25 19:18:43 +00:00
|
|
|
recordUndo(bv(), Undo::INSERT, 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-06-27 08:38:41 +00:00
|
|
|
bool const freeSpacing = cursorRow()->par()->layout()->free_spacing ||
|
|
|
|
cursorRow()->par()->isFreeSpacing();
|
2000-02-29 02:19:17 +00:00
|
|
|
|
2000-10-09 12:30:52 +00:00
|
|
|
if (lyxrc.auto_number) {
|
2001-01-15 14:05:45 +00:00
|
|
|
static string const number_operators = "+-/*";
|
|
|
|
static string const number_unary_operators = "+-";
|
|
|
|
static string const number_seperators = ".,:";
|
|
|
|
|
2000-10-09 12:30:52 +00:00
|
|
|
if (current_font.number() == LyXFont::ON) {
|
2001-12-20 15:11:51 +00:00
|
|
|
if (!IsDigit(c) && !contains(number_operators, c) &&
|
2001-01-15 14:05:45 +00:00
|
|
|
!(contains(number_seperators, c) &&
|
2000-10-09 12:30:52 +00:00
|
|
|
cursor.pos() >= 1 &&
|
|
|
|
cursor.pos() < cursor.par()->size() &&
|
2003-07-27 21:59:06 +00:00
|
|
|
getFont(cursor.par(), cursor.pos()).number() == LyXFont::ON &&
|
|
|
|
getFont(cursor.par(), 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) {
|
2001-06-25 00:06:33 +00:00
|
|
|
char const c = cursor.par()->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 ||
|
2001-06-25 00:06:33 +00:00
|
|
|
cursor.par()->isSeparator(cursor.pos() - 2) ||
|
2002-02-16 15:59:55 +00:00
|
|
|
cursor.par()->isNewline(cursor.pos() - 2))
|
|
|
|
) {
|
2003-07-27 21:59:06 +00:00
|
|
|
setCharFont(
|
2003-04-13 12:56:48 +00:00
|
|
|
cursor.par(),
|
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-04-10 12:10:04 +00:00
|
|
|
cursor.par(),
|
2001-08-03 18:28:11 +00:00
|
|
|
cursor.pos() - 2).number() == LyXFont::ON) {
|
2003-07-27 21:59:06 +00:00
|
|
|
setCharFont(
|
2003-04-10 12:10:04 +00:00
|
|
|
cursor.par(),
|
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
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
LyXFont realtmpfont = real_current_font;
|
2002-06-24 20:28:12 +00:00
|
|
|
LyXFont rawtmpfont = current_font;
|
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
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// Get the font that is used to calculate the baselineskip
|
2001-11-26 16:42:04 +00:00
|
|
|
pos_type const lastpos = cursor.par()->size();
|
2001-05-03 14:31:33 +00:00
|
|
|
LyXFont rawparfont =
|
2003-03-17 16:25:00 +00:00
|
|
|
cursor.par()->getFontSettings(bv()->buffer()->params,
|
2001-05-03 14:31:33 +00:00
|
|
|
lastpos - 1);
|
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
|
2001-06-25 00:06:33 +00:00
|
|
|
&& cursor.par()->isLineSeparator(cursor.pos() - 1))
|
2000-06-08 23:16:16 +00:00
|
|
|
|| (cursor.pos() > 0
|
2001-06-25 00:06:33 +00:00
|
|
|
&& cursor.par()->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)
|
2001-06-25 00:06:33 +00:00
|
|
|
cursor.par()->insertChar(cursor.pos(), c);
|
2003-08-08 15:48:57 +00:00
|
|
|
|
2003-07-27 21:59:06 +00:00
|
|
|
setCharFont(cursor.par(), 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;
|
|
|
|
redoParagraph(cursor.par());
|
|
|
|
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()
|
|
|
|
{
|
1999-09-27 18:44:28 +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-07-28 12:20:42 +00:00
|
|
|
void LyXText::prepareToPrint(RowList::iterator rit, double & x,
|
|
|
|
double & fill_separator,
|
|
|
|
double & fill_hfill,
|
|
|
|
double & fill_label_hfill,
|
2002-03-21 17:27:08 +00:00
|
|
|
bool bidi) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2003-07-28 12:20:42 +00:00
|
|
|
double w = rit->fill();
|
1999-09-27 18:44:28 +00:00
|
|
|
fill_hfill = 0;
|
|
|
|
fill_label_hfill = 0;
|
|
|
|
fill_separator = 0;
|
|
|
|
fill_label_hfill = 0;
|
2000-02-03 19:51:27 +00:00
|
|
|
|
2003-04-13 12:56:48 +00:00
|
|
|
ParagraphList::iterator pit = rit->par();
|
|
|
|
|
2002-01-07 16:15:11 +00:00
|
|
|
bool const is_rtl =
|
2003-04-13 12:56:48 +00:00
|
|
|
pit->isRightToLeftPar(bv()->buffer()->params);
|
2003-07-18 07:47:07 +00:00
|
|
|
if (is_rtl)
|
|
|
|
x = workWidth() > 0 ? rightMargin(*bv()->buffer(), *rit) : 0;
|
|
|
|
else
|
|
|
|
x = workWidth() > 0 ? leftMargin(*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-07-18 07:47:07 +00:00
|
|
|
int nlh = numberOfLabelHfills(*this, 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-07-28 12:20:42 +00:00
|
|
|
fill_label_hfill = labelFill(*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-07-18 07:47:07 +00:00
|
|
|
int const nh = numberOfHfills(*this, 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
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
|
|
// center displayed insets
|
2003-07-25 21:20:24 +00:00
|
|
|
InsetOld * inset = 0;
|
2003-04-13 12:56:48 +00:00
|
|
|
if (rit->pos() < pit->size()
|
|
|
|
&& pit->isInset(rit->pos())
|
|
|
|
&& (inset = pit->getInset(rit->pos()))
|
2001-08-10 14:00:48 +00:00
|
|
|
&& (inset->display())) // || (inset->scroll() < 0)))
|
2003-07-25 21:20:24 +00:00
|
|
|
align = (inset->lyxCode() == InsetOld::MATHMACRO_CODE)
|
2002-03-21 17:27:08 +00:00
|
|
|
? LYX_ALIGN_BLOCK : LYX_ALIGN_CENTER;
|
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
|
|
|
|
2001-08-10 14:00:48 +00:00
|
|
|
switch (align) {
|
1999-09-27 18:44:28 +00:00
|
|
|
case LYX_ALIGN_BLOCK:
|
2003-03-31 16:57:45 +00:00
|
|
|
{
|
2003-07-18 07:47:07 +00:00
|
|
|
int const ns = numberOfSeparators(*this, rit);
|
2003-03-31 16:57:45 +00:00
|
|
|
RowList::iterator next_row = boost::next(rit);
|
2003-04-13 12:56:48 +00:00
|
|
|
ParagraphList::iterator next_pit = next_row->par();
|
2003-04-01 16:55:48 +00:00
|
|
|
|
2003-03-31 16:57:45 +00:00
|
|
|
if (ns && next_row != rowlist_.end() &&
|
2003-04-13 12:56:48 +00:00
|
|
|
next_pit == pit &&
|
|
|
|
!(next_pit->isNewline(next_row->pos() - 1))
|
|
|
|
&& !(next_pit->isInset(next_row->pos()) &&
|
|
|
|
next_pit->getInset(next_row->pos()) &&
|
|
|
|
next_pit->getInset(next_row->pos())->display())
|
2003-04-01 16:55:48 +00:00
|
|
|
) {
|
2001-08-10 14:00:48 +00:00
|
|
|
fill_separator = w / ns;
|
|
|
|
} else if (is_rtl) {
|
|
|
|
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
|
|
|
}
|
2000-02-03 19:51:27 +00:00
|
|
|
if (!bidi)
|
|
|
|
return;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2003-04-01 16:55:48 +00:00
|
|
|
computeBidiTables(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-04-01 16:55:48 +00:00
|
|
|
pos_type last = lastPos(*this, rit);
|
2000-02-03 19:51:27 +00:00
|
|
|
|
2003-03-09 12:37:22 +00:00
|
|
|
if (body_pos > 0 &&
|
|
|
|
(body_pos - 1 > last ||
|
2003-04-13 12:56:48 +00:00
|
|
|
!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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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-07-01 11:51:20 +00:00
|
|
|
::cursorRightOneWord(cursor, ownerParagraphs());
|
|
|
|
setCursor(cursor.par(), 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-07-01 11:51:20 +00:00
|
|
|
::cursorLeftOneWord(tmpcursor, ownerParagraphs());
|
2003-03-17 16:25:00 +00:00
|
|
|
setCursor(tmpcursor.par(), 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;
|
2001-06-27 14:10:35 +00:00
|
|
|
LyXCursor to;
|
2003-07-01 11:51:20 +00:00
|
|
|
::getWord(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
|
|
|
{
|
|
|
|
if (!selection.set() && cursor.par()->size())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (selection.start.par() == selection.end.par()) {
|
|
|
|
LyXCursor & startc = selection.start;
|
|
|
|
LyXCursor & endc = selection.end;
|
2003-07-25 19:18:43 +00:00
|
|
|
recordUndo(bv(), Undo::INSERT, startc.par());
|
2003-02-08 19:18:01 +00:00
|
|
|
startc.par()->acceptChange(startc.pos(), endc.pos());
|
|
|
|
finishUndo();
|
|
|
|
clearSelection();
|
2003-08-01 11:22:13 +00:00
|
|
|
redoParagraph(startc.par());
|
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
|
|
|
{
|
|
|
|
if (!selection.set() && cursor.par()->size())
|
|
|
|
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-07-25 19:18:43 +00:00
|
|
|
recordUndo(bv(), Undo::INSERT, startc.par());
|
2003-02-08 19:18:01 +00:00
|
|
|
startc.par()->rejectChange(startc.pos(), endc.pos());
|
|
|
|
finishUndo();
|
|
|
|
clearSelection();
|
2003-08-01 11:22:13 +00:00
|
|
|
redoParagraph(startc.par());
|
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.
|
2002-08-13 14:40:38 +00:00
|
|
|
WordLangTuple const
|
2003-03-18 13:05:08 +00:00
|
|
|
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-03-17 16:25:00 +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
|
2001-07-17 15:39:12 +00:00
|
|
|
if (cursor.pos() == cursor.par()->size()) {
|
2003-04-13 02:23:30 +00:00
|
|
|
if (boost::next(cursor.par()) == ownerParagraphs().end())
|
2002-08-06 22:38:44 +00:00
|
|
|
return word;
|
2003-04-13 02:23:30 +00:00
|
|
|
cursor.par(boost::next(cursor.par()));
|
2001-07-17 15:39:12 +00:00
|
|
|
cursor.pos(0);
|
|
|
|
} else
|
|
|
|
cursor.pos(cursor.pos() + 1);
|
|
|
|
}
|
2003-04-09 09:15:20 +00:00
|
|
|
ParagraphList::iterator tmppit = 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-04-13 01:04:04 +00:00
|
|
|
if (cursor.pos() || cursor.par() != ownerParagraphs().begin()) {
|
2001-03-11 00:21:13 +00:00
|
|
|
while (cursor.pos() < cursor.par()->size()
|
2001-06-25 00:06:33 +00:00
|
|
|
&& cursor.par()->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) {
|
|
|
|
ParagraphList::iterator cpit = cursor.par();
|
2003-02-08 19:18:01 +00:00
|
|
|
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()) {
|
|
|
|
if (boost::next(cpit) != ownerParagraphs().end()) {
|
|
|
|
cursor.par(boost::next(cpit));
|
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!
|
|
|
|
if (cursor.pos() < cursor.par()->size() &&
|
2003-02-08 19:18:01 +00:00
|
|
|
cursor.par()->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");
|
|
|
|
cursor.par()->getInset(cursor.pos())->localDispatch(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-04-09 09:15:20 +00:00
|
|
|
if (cursor.par() != tmppit) {
|
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-07-27 21:59:06 +00:00
|
|
|
string lang_code = getFont(cursor.par(), 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)
|
2001-03-11 00:21:13 +00:00
|
|
|
while (cursor.pos() < cursor.par()->size()
|
2003-02-08 19:18:01 +00:00
|
|
|
&& cursor.par()->isLetter(cursor.pos())
|
2003-02-26 17:04:10 +00:00
|
|
|
&& !isDeletedText(*cursor.par(), 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()) {
|
2001-11-26 16:42:04 +00:00
|
|
|
pos_type i;
|
2001-05-31 02:23:46 +00:00
|
|
|
for (i = selection.cursor.pos(); i < cursor.pos(); ++i) {
|
2001-11-13 14:47:35 +00:00
|
|
|
if (!cursor.par()->isInset(i))
|
2001-06-25 00:06:33 +00:00
|
|
|
str += cursor.par()->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
|
2001-03-11 00:21:13 +00:00
|
|
|
while (cursor.pos() < cursor.par()->size()
|
2001-11-13 14:47:35 +00:00
|
|
|
&& (cursor.par()->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-03-17 16:25:00 +00:00
|
|
|
setCursor(cursor.par(), 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
|
|
|
{
|
2002-08-10 15:21:07 +00:00
|
|
|
if (cursor.par()->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();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-05-29 12:58:23 +00:00
|
|
|
// Great, CutSelection() gets rid of multiple spaces.
|
2003-03-17 16:25:00 +00:00
|
|
|
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
|
|
|
{
|
2002-08-10 15:21:07 +00:00
|
|
|
if (cursor.par()->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
|
|
|
{
|
2002-08-10 15:21:07 +00:00
|
|
|
if (cursor.par()->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;
|
|
|
|
::getWord(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-07-25 19:18:43 +00:00
|
|
|
recordUndo(bv(), Undo::ATOMIC, 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-04-09 09:15:20 +00:00
|
|
|
ParagraphList::iterator pit = from.par();
|
2001-06-27 18:29:18 +00:00
|
|
|
|
2003-04-09 09:15:20 +00:00
|
|
|
while (pit != ownerParagraphs().end() &&
|
|
|
|
(pos != to.pos() || pit != to.par())) {
|
|
|
|
if (pos == pit->size()) {
|
|
|
|
++pit;
|
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-03-11 15:01:29 +00:00
|
|
|
if (!IsInsetChar(c)) {
|
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);
|
2003-04-13 12:56:48 +00:00
|
|
|
checkParagraph(pit, pos);
|
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;
|
2000-11-21 15:46:13 +00:00
|
|
|
int const old_cur_par_id = old_cursor.par()->id();
|
2003-04-13 01:04:04 +00:00
|
|
|
int const old_cur_par_prev_id =
|
|
|
|
(old_cursor.par() != ownerParagraphs().begin() ?
|
|
|
|
boost::prior(old_cursor.par())->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...
|
2001-06-25 00:06:33 +00:00
|
|
|
// The cursorRightIntern calls DeleteEmptyParagrapgMechanism
|
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-04-13 01:04:04 +00:00
|
|
|
if ((cursor.par() != ownerParagraphs().begin() ? boost::prior(cursor.par())->id() : -1)
|
2000-02-10 17:53:36 +00:00
|
|
|
== old_cur_par_prev_id
|
2001-11-15 00:39:11 +00:00
|
|
|
&& cursor.par()->id() != old_cur_par_id) {
|
|
|
|
// 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()) {
|
2000-02-10 17:53:36 +00:00
|
|
|
LyXCursor tmpcursor = cursor;
|
2001-11-15 00:39:11 +00:00
|
|
|
// to make sure undo gets the right cursor position
|
|
|
|
cursor = old_cursor;
|
2003-07-25 19:18:43 +00:00
|
|
|
recordUndo(bv(), Undo::DELETE, cursor.par());
|
2000-02-10 17:53:36 +00:00
|
|
|
cursor = tmpcursor;
|
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
|
2001-11-26 16:42:04 +00:00
|
|
|
pos_type lastpos = cursor.par()->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
|
|
|
|
if (cursor.par()->isChangeEdited(0, cursor.par()->size()))
|
|
|
|
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-08-08 15:48:57 +00:00
|
|
|
if (lastpos == 0
|
|
|
|
|| (lastpos == 1 && cursor.par()->isSeparator(0))) {
|
|
|
|
// This is an empty paragraph and we delete it just
|
|
|
|
// by moving the cursor one step
|
|
|
|
// left and let the DeleteEmptyParagraphMechanism
|
|
|
|
// handle the actual deletion
|
2000-03-16 06:08:30 +00:00
|
|
|
// of the paragraph.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2003-04-13 01:04:04 +00:00
|
|
|
if (cursor.par() != ownerParagraphs().begin()) {
|
|
|
|
ParagraphList::iterator tmppit = boost::prior(cursor.par());
|
|
|
|
if (cursor.par()->layout() == tmppit->layout()
|
|
|
|
&& cursor.par()->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-04-13 01:04:04 +00:00
|
|
|
tmppit->params().lineBottom(cursor.par()->params().lineBottom());
|
|
|
|
tmppit->params().spaceBottom(cursor.par()->params().spaceBottom());
|
|
|
|
tmppit->params().pagebreakBottom(cursor.par()->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());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
// the layout things can change the height of a row !
|
2003-06-27 08:38:41 +00:00
|
|
|
setHeightOfRow(cursorRow());
|
2000-02-10 17:53:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2000-07-24 21:49:58 +00:00
|
|
|
|
2003-04-13 01:04:04 +00:00
|
|
|
if (cursor.par() != ownerParagraphs().begin()) {
|
2003-07-25 19:18:43 +00:00
|
|
|
recordUndo(bv(), Undo::DELETE,
|
2003-04-29 23:59:39 +00:00
|
|
|
boost::prior(cursor.par()),
|
2003-05-23 10:33:40 +00:00
|
|
|
cursor.par());
|
2000-07-24 21:49:58 +00:00
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2003-04-09 09:15:20 +00:00
|
|
|
ParagraphList::iterator tmppit = cursor.par();
|
2003-06-27 08:38:41 +00:00
|
|
|
RowList::iterator tmprow = cursorRow();
|
2000-03-28 02:18:52 +00:00
|
|
|
|
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-04-09 09:15:20 +00:00
|
|
|
if (cursor.par() != ownerParagraphs().begin()) {
|
2000-03-28 02:18:52 +00:00
|
|
|
// steps into the above paragraph.
|
2003-04-09 09:15:20 +00:00
|
|
|
setCursorIntern(boost::prior(cursor.par()),
|
|
|
|
boost::prior(cursor.par())->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.
|
|
|
|
// Even so with a footnote paragraph and a non-footnote
|
|
|
|
// paragraph. I will not allow pasting in this case,
|
|
|
|
// because the user would be confused if the footnote behaves
|
|
|
|
// different wether it is open or closed.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
// Correction: Pasting is always allowed with standard-layout
|
2002-07-21 21:21:06 +00:00
|
|
|
LyXTextClass const & tclass =
|
2003-03-17 16:25:00 +00:00
|
|
|
bv()->buffer()->params.getLyXTextClass();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2003-04-09 09:15:20 +00:00
|
|
|
if (cursor.par() != tmppit
|
|
|
|
&& (cursor.par()->layout() == tmppit->layout()
|
|
|
|
|| tmppit->layout() == tclass.defaultLayout())
|
|
|
|
&& cursor.par()->getAlign() == tmppit->getAlign()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
removeParagraph(tmprow);
|
|
|
|
removeRow(tmprow);
|
2003-03-17 16:25:00 +00:00
|
|
|
mergeParagraph(bv()->buffer()->params, bv()->buffer()->paragraphs, cursor.par());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
if (!cursor.pos() || !cursor.par()->isSeparator(cursor.pos() - 1))
|
|
|
|
; //cursor.par()->insertChar(cursor.pos(), ' ');
|
2000-03-16 06:08:30 +00:00
|
|
|
// strangely enough it seems that commenting out the line above removes
|
|
|
|
// most or all of the segfaults. I will however also try to move the
|
|
|
|
// two Remove... lines in front of the PasteParagraph too.
|
2000-02-10 17:53:36 +00:00
|
|
|
else
|
2000-06-08 23:16:16 +00:00
|
|
|
if (cursor.pos())
|
|
|
|
cursor.pos(cursor.pos() - 1);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
// remove the lost paragraph
|
2000-03-16 06:08:30 +00:00
|
|
|
// This one is not safe, since the paragraph that the tmprow and the
|
|
|
|
// following rows belong to has been deleted by the PasteParagraph
|
|
|
|
// above. The question is... could this be moved in front of the
|
|
|
|
// PasteParagraph?
|
|
|
|
//RemoveParagraph(tmprow);
|
2002-03-21 17:27:08 +00:00
|
|
|
//RemoveRow(tmprow);
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
// This rebuilds the rows.
|
2003-06-27 08:38:41 +00:00
|
|
|
appendParagraph(cursorRow());
|
2003-03-17 16:25:00 +00:00
|
|
|
updateCounters();
|
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-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-07-25 19:18:43 +00:00
|
|
|
recordUndo(bv(), Undo::DELETE, 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-08-08 15:48:57 +00:00
|
|
|
cursor.par()->erase(cursor.pos());
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
2000-05-30 19:31:11 +00:00
|
|
|
|
2001-03-11 00:21:13 +00:00
|
|
|
lastpos = cursor.par()->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-06-27 08:38:41 +00:00
|
|
|
RowList::iterator LyXText::cursorRow() const
|
|
|
|
{
|
|
|
|
return getRow(cursor.par(), cursor.pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RowList::iterator LyXText::getRow(LyXCursor const & cur) const
|
|
|
|
{
|
|
|
|
return getRow(cur.par(), cur.pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RowList::iterator
|
|
|
|
LyXText::getRow(ParagraphList::iterator pit, pos_type pos) const
|
|
|
|
{
|
|
|
|
if (rows().empty())
|
|
|
|
return rowlist_.end();
|
|
|
|
|
|
|
|
// find the first row of the specified paragraph
|
|
|
|
RowList::iterator rit = rowlist_.begin();
|
|
|
|
RowList::iterator end = rowlist_.end();
|
|
|
|
while (boost::next(rit) != end && rit->par() != pit) {
|
|
|
|
++rit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// now find the wanted row
|
|
|
|
while (rit->pos() < pos
|
|
|
|
&& boost::next(rit) != end
|
|
|
|
&& boost::next(rit)->par() == pit
|
|
|
|
&& boost::next(rit)->pos() <= pos) {
|
|
|
|
++rit;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rit;
|
|
|
|
}
|
|
|
|
|
2003-07-18 07:47:07 +00:00
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
// returns pointer to a specified row
|
2003-03-30 07:27:36 +00:00
|
|
|
RowList::iterator
|
2003-04-10 21:07:55 +00:00
|
|
|
LyXText::getRow(ParagraphList::iterator pit, pos_type pos, int & y) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-01-13 16:28:54 +00:00
|
|
|
y = 0;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2003-03-30 21:42:09 +00:00
|
|
|
if (rows().empty())
|
2003-03-31 16:57:45 +00:00
|
|
|
return rowlist_.end();
|
2003-03-30 18:42:37 +00:00
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
// find the first row of the specified paragraph
|
2003-03-31 16:57:45 +00:00
|
|
|
RowList::iterator rit = rowlist_.begin();
|
|
|
|
RowList::iterator end = rowlist_.end();
|
2003-04-10 21:07:55 +00:00
|
|
|
while (boost::next(rit) != end && rit->par() != pit) {
|
2003-03-29 23:11:20 +00:00
|
|
|
y += rit->height();
|
|
|
|
++rit;
|
2000-01-13 16:28:54 +00:00
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
// now find the wanted row
|
2003-03-29 23:11:20 +00:00
|
|
|
while (rit->pos() < pos
|
|
|
|
&& boost::next(rit) != end
|
2003-04-10 21:07:55 +00:00
|
|
|
&& boost::next(rit)->par() == pit
|
2003-03-29 23:11:20 +00:00
|
|
|
&& boost::next(rit)->pos() <= pos) {
|
|
|
|
y += rit->height();
|
|
|
|
++rit;
|
2000-01-13 16:28:54 +00:00
|
|
|
}
|
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-07-16 08:42:26 +00:00
|
|
|
// returns pointer to some fancy row 'below' specified row
|
|
|
|
RowList::iterator LyXText::cursorIRow() const
|
|
|
|
{
|
|
|
|
int y = 0;
|
|
|
|
return getRow(cursor.par(), cursor.pos(), y);
|
|
|
|
}
|
|
|
|
|
2001-11-26 16:42:04 +00:00
|
|
|
|
2003-03-30 07:27:36 +00:00
|
|
|
RowList::iterator LyXText::getRowNearY(int & y) const
|
2001-11-26 16:42:04 +00:00
|
|
|
{
|
2003-04-12 23:03:05 +00:00
|
|
|
RowList::iterator rit = anchor_row_;
|
|
|
|
RowList::iterator const beg = rows().begin();
|
|
|
|
RowList::iterator const end = rows().end();
|
2003-03-29 23:11:20 +00:00
|
|
|
|
2003-04-12 23:03:05 +00:00
|
|
|
if (rows().empty()) {
|
|
|
|
y = 0;
|
|
|
|
return end;
|
|
|
|
}
|
|
|
|
if (rit == end)
|
|
|
|
rit = beg;
|
|
|
|
|
|
|
|
int tmpy = rit->y();
|
|
|
|
|
|
|
|
if (tmpy <= y) {
|
|
|
|
while (rit != end && tmpy <= y) {
|
|
|
|
tmpy += rit->height();
|
|
|
|
++rit;
|
|
|
|
}
|
|
|
|
if (rit != beg) {
|
|
|
|
--rit;
|
|
|
|
tmpy -= rit->height();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
while (rit != beg && tmpy > y) {
|
|
|
|
--rit;
|
|
|
|
tmpy -= rit->height();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (tmpy < 0 || rit == end) {
|
|
|
|
tmpy = 0;
|
|
|
|
rit = beg;
|
2001-11-26 16:42:04 +00:00
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2003-04-12 23:03:05 +00:00
|
|
|
// return the rel y
|
2003-03-31 16:57:45 +00:00
|
|
|
y = tmpy;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2003-03-30 07:27:36 +00:00
|
|
|
return rit;
|
2001-11-26 16:42:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int LyXText::getDepth() const
|
|
|
|
{
|
|
|
|
return cursor.par()->getDepth();
|
|
|
|
}
|