1999-09-27 18:44:28 +00:00
|
|
|
|
/* This file is part of
|
1999-10-07 18:44:17 +00:00
|
|
|
|
* ======================================================
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
1999-10-07 18:44:17 +00:00
|
|
|
|
* LyX, The Document Processor
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
1999-10-07 18:44:17 +00:00
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
2001-05-30 13:53:44 +00:00
|
|
|
|
* Copyright 1995-2001 The LyX Team.
|
1999-10-07 18:44:17 +00:00
|
|
|
|
*
|
1999-11-15 12:01:38 +00:00
|
|
|
|
* ====================================================== */
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2001-04-17 15:15:59 +00:00
|
|
|
|
#include "lyxtext.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "LString.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "paragraph.h"
|
2002-05-23 12:08:47 +00:00
|
|
|
|
#include "frontends/LyXView.h"
|
2001-07-06 15:57:54 +00:00
|
|
|
|
#include "undo_funcs.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "buffer.h"
|
|
|
|
|
#include "bufferparams.h"
|
|
|
|
|
#include "gettext.h"
|
1999-12-19 22:35:36 +00:00
|
|
|
|
#include "BufferView.h"
|
2000-04-10 14:29:05 +00:00
|
|
|
|
#include "CutAndPaste.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"
|
2000-04-08 17:02:02 +00:00
|
|
|
|
#include "debug.h"
|
2000-07-10 10:31:34 +00:00
|
|
|
|
#include "lyxrc.h"
|
2001-11-26 16:42:04 +00:00
|
|
|
|
#include "lyxrow.h"
|
2000-07-18 17:45:27 +00:00
|
|
|
|
#include "FloatList.h"
|
2001-04-05 12:26:41 +00:00
|
|
|
|
#include "language.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "ParagraphParameters.h"
|
2002-08-06 22:40:59 +00:00
|
|
|
|
#include "counters.h"
|
2003-04-01 16:55:48 +00:00
|
|
|
|
#include "lyxrow_funcs.h"
|
2003-04-14 18:35:29 +00:00
|
|
|
|
#include "paragraph_funcs.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
2003-02-21 09:20:18 +00:00
|
|
|
|
#include "insets/insetbibitem.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
#include "insets/insetfloat.h"
|
|
|
|
|
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#include "support/LAssert.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
#include "support/textutils.h"
|
|
|
|
|
#include "support/lstrings.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-03-30 20:25:44 +00:00
|
|
|
|
#include "support/BoostFormat.h"
|
2002-12-01 21:10:37 +00:00
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
using std::vector;
|
1999-12-19 22:35:36 +00:00
|
|
|
|
using std::copy;
|
2000-03-28 02:18:55 +00:00
|
|
|
|
using std::endl;
|
2001-01-19 15:31:40 +00:00
|
|
|
|
using std::find;
|
2000-04-04 00:19:15 +00:00
|
|
|
|
using std::pair;
|
2001-11-27 10:34:16 +00:00
|
|
|
|
using lyx::pos_type;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-07-21 18:47:54 +00:00
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
LyXText::LyXText(BufferView * bv)
|
2003-03-30 18:42:37 +00:00
|
|
|
|
: height(0), width(0), anchor_row_offset_(0),
|
|
|
|
|
inset_owner(0), the_locking_inset(0), bv_owner(bv)
|
2003-03-17 01:34:36 +00:00
|
|
|
|
{
|
2003-03-30 18:42:37 +00:00
|
|
|
|
anchor_row_ = rows().end();
|
|
|
|
|
need_break_row = rows().end();
|
|
|
|
|
refresh_row = rows().end();
|
2003-04-01 16:55:48 +00:00
|
|
|
|
|
2003-03-17 01:34:36 +00:00
|
|
|
|
clearPaint();
|
|
|
|
|
}
|
2000-06-12 11:27:15 +00:00
|
|
|
|
|
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
LyXText::LyXText(BufferView * bv, InsetText * inset)
|
2003-03-30 18:42:37 +00:00
|
|
|
|
: height(0), width(0), anchor_row_offset_(0),
|
|
|
|
|
inset_owner(inset), the_locking_inset(0), bv_owner(bv)
|
2003-03-17 01:34:36 +00:00
|
|
|
|
{
|
2003-03-30 18:42:37 +00:00
|
|
|
|
anchor_row_ = rows().end();
|
|
|
|
|
need_break_row = rows().end();
|
|
|
|
|
refresh_row = rows().end();
|
2003-04-01 16:55:48 +00:00
|
|
|
|
|
2003-03-17 01:34:36 +00:00
|
|
|
|
clearPaint();
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-03-02 16:39:54 +00:00
|
|
|
|
|
2001-07-20 14:18:48 +00:00
|
|
|
|
void LyXText::init(BufferView * bview, bool reinit)
|
2000-06-12 11:27:15 +00:00
|
|
|
|
{
|
2001-07-20 14:18:48 +00:00
|
|
|
|
if (reinit) {
|
2003-03-27 12:41:47 +00:00
|
|
|
|
rowlist_.clear();
|
2003-03-30 18:42:37 +00:00
|
|
|
|
need_break_row = rows().end();
|
2002-03-02 16:39:54 +00:00
|
|
|
|
width = height = 0;
|
|
|
|
|
copylayouttype.erase();
|
2003-03-16 00:45:31 +00:00
|
|
|
|
top_y(0);
|
|
|
|
|
clearPaint();
|
2003-03-29 23:11:20 +00:00
|
|
|
|
} else if (!rowlist_.empty())
|
2000-06-12 11:27:15 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2003-04-10 12:10:04 +00:00
|
|
|
|
ParagraphList::iterator pit = ownerParagraphs().begin();
|
2003-04-02 17:11:38 +00:00
|
|
|
|
ParagraphList::iterator end = ownerParagraphs().end();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-10 12:10:04 +00:00
|
|
|
|
current_font = getFont(bview->buffer(), pit, 0);
|
2003-04-02 17:11:38 +00:00
|
|
|
|
|
2003-04-10 12:10:04 +00:00
|
|
|
|
for (; pit != end; ++pit) {
|
2003-04-13 12:56:48 +00:00
|
|
|
|
insertParagraph(pit, rowlist_.end());
|
2000-06-12 11:27:15 +00:00
|
|
|
|
}
|
2003-04-10 12:10:04 +00:00
|
|
|
|
setCursorIntern(rowlist_.begin()->par(), 0);
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.cursor = cursor;
|
2002-09-06 14:48:01 +00:00
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
updateCounters();
|
2000-06-12 11:27:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-07-06 15:41:17 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Gets the fully instantiated font at a given position in a paragraph
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// Basically the same routine as Paragraph::getFont() in paragraph.C.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// The difference is that this one is used for displaying, and thus we
|
|
|
|
|
// are allowed to make cosmetic improvements. For instance make footnotes
|
|
|
|
|
// smaller. (Asger)
|
|
|
|
|
// If position is -1, we get the layout font of the paragraph.
|
|
|
|
|
// If position is -2, we get the font of the manual label of the paragraph.
|
2003-04-09 21:34:31 +00:00
|
|
|
|
LyXFont const LyXText::getFont(Buffer const * buf, ParagraphList::iterator pit,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
pos_type pos) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-08-03 18:28:11 +00:00
|
|
|
|
lyx::Assert(pos >= 0);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-09 21:34:31 +00:00
|
|
|
|
LyXLayout_ptr const & layout = pit->layout();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// We specialize the 95% common case:
|
2003-04-09 21:34:31 +00:00
|
|
|
|
if (!pit->getDepth()) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (layout->labeltype == LABEL_MANUAL
|
2003-04-09 21:34:31 +00:00
|
|
|
|
&& pos < pit->beginningOfBody()) {
|
2002-02-20 14:55:17 +00:00
|
|
|
|
// 1% goes here
|
2003-04-09 21:34:31 +00:00
|
|
|
|
LyXFont f = pit->getFontSettings(buf->params, pos);
|
|
|
|
|
if (pit->inInset())
|
|
|
|
|
pit->inInset()->getDrawFont(f);
|
2002-06-24 20:28:12 +00:00
|
|
|
|
return f.realize(layout->reslabelfont);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else {
|
2003-04-09 21:34:31 +00:00
|
|
|
|
LyXFont f = pit->getFontSettings(buf->params, pos);
|
|
|
|
|
if (pit->inInset())
|
|
|
|
|
pit->inInset()->getDrawFont(f);
|
2002-06-24 20:28:12 +00:00
|
|
|
|
return f.realize(layout->resfont);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// The uncommon case need not be optimized as much
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-08-03 18:28:11 +00:00
|
|
|
|
LyXFont layoutfont;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-09 21:34:31 +00:00
|
|
|
|
if (pos < pit->beginningOfBody()) {
|
2001-08-03 18:28:11 +00:00
|
|
|
|
// 1% goes here
|
2002-06-24 20:28:12 +00:00
|
|
|
|
layoutfont = layout->labelfont;
|
1999-11-04 01:40:20 +00:00
|
|
|
|
} else {
|
2001-08-03 18:28:11 +00:00
|
|
|
|
// 99% goes here
|
2002-06-24 20:28:12 +00:00
|
|
|
|
layoutfont = layout->font;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-04-09 21:34:31 +00:00
|
|
|
|
LyXFont tmpfont = pit->getFontSettings(buf->params, pos);
|
2001-08-11 18:31:14 +00:00
|
|
|
|
tmpfont.realize(layoutfont);
|
2002-09-06 15:18:11 +00:00
|
|
|
|
|
2003-04-09 21:34:31 +00:00
|
|
|
|
if (pit->inInset())
|
|
|
|
|
pit->inInset()->getDrawFont(tmpfont);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-15 00:11:03 +00:00
|
|
|
|
// Realize with the fonts of lesser depth.
|
|
|
|
|
tmpfont.realize(outerFont(pit));
|
|
|
|
|
|
2003-04-15 18:34:43 +00:00
|
|
|
|
return realizeFont(tmpfont, buf->params);
|
2001-08-03 18:28:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-04-10 12:10:04 +00:00
|
|
|
|
LyXFont const LyXText::getLayoutFont(Buffer const * buf,
|
|
|
|
|
ParagraphList::iterator pit) const
|
2001-08-03 18:28:11 +00:00
|
|
|
|
{
|
2003-04-10 12:10:04 +00:00
|
|
|
|
LyXLayout_ptr const & layout = pit->layout();
|
2001-08-03 18:28:11 +00:00
|
|
|
|
|
2003-04-10 12:10:04 +00:00
|
|
|
|
if (!pit->getDepth()) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
return layout->resfont;
|
1999-11-04 01:40:20 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-04-15 00:11:03 +00:00
|
|
|
|
LyXFont font(layout->font);
|
|
|
|
|
// Realize with the fonts of lesser depth.
|
|
|
|
|
font.realize(outerFont(pit));
|
|
|
|
|
|
2003-04-15 18:34:43 +00:00
|
|
|
|
return realizeFont(font, buf->params);
|
2001-08-03 18:28:11 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-08-03 18:28:11 +00:00
|
|
|
|
|
2003-04-10 12:10:04 +00:00
|
|
|
|
LyXFont const LyXText::getLabelFont(Buffer const * buf,
|
|
|
|
|
ParagraphList::iterator pit) const
|
2001-08-03 18:28:11 +00:00
|
|
|
|
{
|
2003-04-10 12:10:04 +00:00
|
|
|
|
LyXLayout_ptr const & layout = pit->layout();
|
2001-08-03 18:28:11 +00:00
|
|
|
|
|
2003-04-10 12:10:04 +00:00
|
|
|
|
if (!pit->getDepth()) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
return layout->reslabelfont;
|
2001-08-03 18:28:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-04-15 00:11:03 +00:00
|
|
|
|
LyXFont font(layout->labelfont);
|
|
|
|
|
// Realize with the fonts of lesser depth.
|
|
|
|
|
font.realize(outerFont(pit));
|
|
|
|
|
|
2003-04-15 18:34:43 +00:00
|
|
|
|
return realizeFont(layout->labelfont, buf->params);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-04-10 12:10:04 +00:00
|
|
|
|
void LyXText::setCharFont(ParagraphList::iterator pit,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
pos_type pos, LyXFont const & fnt,
|
|
|
|
|
bool toggleall)
|
2001-05-28 15:11:24 +00:00
|
|
|
|
{
|
2003-03-17 16:25:00 +00:00
|
|
|
|
Buffer const * buf = bv()->buffer();
|
2003-04-10 12:10:04 +00:00
|
|
|
|
LyXFont font = getFont(buf, pit, pos);
|
2001-08-11 18:31:14 +00:00
|
|
|
|
font.update(fnt, buf->params.language, toggleall);
|
2001-05-28 15:11:24 +00:00
|
|
|
|
// Let the insets convert their font
|
2003-04-10 12:10:04 +00:00
|
|
|
|
if (pit->isInset(pos)) {
|
|
|
|
|
Inset * inset = pit->getInset(pos);
|
2001-11-09 13:44:48 +00:00
|
|
|
|
if (isEditableInset(inset)) {
|
|
|
|
|
UpdatableInset * uinset =
|
|
|
|
|
static_cast<UpdatableInset *>(inset);
|
2003-03-17 16:25:00 +00:00
|
|
|
|
uinset->setFont(bv(), fnt, toggleall, true);
|
2001-05-28 15:11:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-01 12:39:22 +00:00
|
|
|
|
// Plug thru to version below:
|
2003-04-10 12:10:04 +00:00
|
|
|
|
setCharFont(buf, pit, pos, font);
|
2001-05-28 15:11:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-07-06 15:41:17 +00:00
|
|
|
|
|
2003-04-10 12:10:04 +00:00
|
|
|
|
void LyXText::setCharFont(Buffer const * buf, ParagraphList::iterator pit,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
pos_type pos, LyXFont const & fnt)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-01-13 16:28:54 +00:00
|
|
|
|
LyXFont font(fnt);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-07-21 21:21:06 +00:00
|
|
|
|
LyXTextClass const & tclass = buf->params.getLyXTextClass();
|
2003-04-10 12:10:04 +00:00
|
|
|
|
LyXLayout_ptr const & layout = pit->layout();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Get concrete layout font to reduce against
|
|
|
|
|
LyXFont layoutfont;
|
|
|
|
|
|
2003-04-10 12:10:04 +00:00
|
|
|
|
if (pos < pit->beginningOfBody())
|
2002-06-24 20:28:12 +00:00
|
|
|
|
layoutfont = layout->labelfont;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
2002-06-24 20:28:12 +00:00
|
|
|
|
layoutfont = layout->font;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Realize against environment font information
|
2003-04-10 12:10:04 +00:00
|
|
|
|
if (pit->getDepth()) {
|
|
|
|
|
#warning FIXME I think I hate this outerHood stuff.
|
|
|
|
|
Paragraph * tp = &*pit;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
while (!layoutfont.resolved() && tp && tp->getDepth()) {
|
2003-04-14 18:35:29 +00:00
|
|
|
|
tp = outerHook(tp);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (tp)
|
2002-06-24 20:28:12 +00:00
|
|
|
|
layoutfont.realize(tp->layout()->font);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-02 16:39:54 +00:00
|
|
|
|
layoutfont.realize(tclass.defaultfont());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Now, reduce font against full layout font
|
|
|
|
|
font.reduce(layoutfont);
|
|
|
|
|
|
2003-04-10 12:10:04 +00:00
|
|
|
|
pit->setFont(pos, font);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// removes the row and reset the touched counters
|
2003-03-30 18:42:37 +00:00
|
|
|
|
void LyXText::removeRow(RowList::iterator rit)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-03-17 01:34:36 +00:00
|
|
|
|
/* FIXME: when we cache the bview, this should just
|
|
|
|
|
* become a postPaint(), I think */
|
2003-03-30 18:42:37 +00:00
|
|
|
|
if (refresh_row == rit) {
|
|
|
|
|
if (rit == rows().begin())
|
|
|
|
|
refresh_row = boost::next(rit);
|
|
|
|
|
else
|
|
|
|
|
refresh_row = boost::prior(rit);
|
|
|
|
|
|
2003-03-17 01:34:36 +00:00
|
|
|
|
// what about refresh_y
|
2002-01-16 12:57:26 +00:00
|
|
|
|
}
|
2003-03-17 01:34:36 +00:00
|
|
|
|
|
2003-03-30 18:42:37 +00:00
|
|
|
|
if (anchor_row_ == rit) {
|
|
|
|
|
if (rit != rows().begin()) {
|
|
|
|
|
anchor_row_ = boost::prior(rit);
|
2003-04-12 23:03:05 +00:00
|
|
|
|
anchor_row_offset_ += anchor_row_->height();
|
2003-03-06 20:21:21 +00:00
|
|
|
|
} else {
|
2003-03-30 18:42:37 +00:00
|
|
|
|
anchor_row_ = boost::next(rit);
|
|
|
|
|
anchor_row_offset_ -= rit->height();
|
2003-03-06 20:21:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-01-16 12:57:26 +00:00
|
|
|
|
|
2003-03-27 12:41:47 +00:00
|
|
|
|
// the text becomes smaller
|
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
|
|
|
|
rowlist_.erase(rit);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// remove all following rows of the paragraph of the specified row.
|
2003-03-30 21:42:09 +00:00
|
|
|
|
void LyXText::removeParagraph(RowList::iterator rit)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-04-02 23:01:39 +00:00
|
|
|
|
ParagraphList::iterator tmppit = rit->par();
|
2003-03-30 21:42:09 +00:00
|
|
|
|
++rit;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-02 23:01:39 +00:00
|
|
|
|
while (rit != rows().end() && rit->par() == tmppit) {
|
2003-03-30 21:42:09 +00:00
|
|
|
|
RowList::iterator tmprit = boost::next(rit);
|
|
|
|
|
removeRow(rit);
|
|
|
|
|
rit = tmprit;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-02-23 16:39:03 +00:00
|
|
|
|
|
2003-04-10 21:07:55 +00:00
|
|
|
|
void LyXText::insertParagraph(ParagraphList::iterator pit,
|
|
|
|
|
RowList::iterator rowit)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-08-21 17:35:24 +00:00
|
|
|
|
// insert a new row, starting at position 0
|
2003-04-10 21:07:55 +00:00
|
|
|
|
Row newrow(pit, 0);
|
2003-04-01 16:55:48 +00:00
|
|
|
|
RowList::iterator rit = rowlist_.insert(rowit, newrow);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-03-09 21:54:56 +00:00
|
|
|
|
// and now append the whole paragraph before the new row
|
2003-03-29 19:29:30 +00:00
|
|
|
|
appendParagraph(rit);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-07-24 22:08:49 +00:00
|
|
|
|
|
2001-07-19 08:52:59 +00:00
|
|
|
|
Inset * LyXText::getInset() const
|
2001-07-11 12:10:46 +00:00
|
|
|
|
{
|
2003-04-13 22:24:28 +00:00
|
|
|
|
ParagraphList::iterator pit = cursor.par();
|
|
|
|
|
pos_type const pos = cursor.pos();
|
|
|
|
|
|
|
|
|
|
if (pos < pit->size() && pit->isInset(pos)) {
|
|
|
|
|
return pit->getInset(pos);
|
2001-07-11 12:10:46 +00:00
|
|
|
|
}
|
2003-02-17 15:16:14 +00:00
|
|
|
|
return 0;
|
2001-07-19 08:52:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-07-24 22:08:49 +00:00
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::toggleInset()
|
2001-07-19 08:52:59 +00:00
|
|
|
|
{
|
|
|
|
|
Inset * inset = getInset();
|
2002-02-12 12:56:46 +00:00
|
|
|
|
// is there an editable inset at cursor position?
|
|
|
|
|
if (!isEditableInset(inset)) {
|
|
|
|
|
// No, try to see if we are inside a collapsable inset
|
|
|
|
|
if (inset_owner && inset_owner->owner()
|
|
|
|
|
&& inset_owner->owner()->isOpen()) {
|
2003-03-17 16:25:00 +00:00
|
|
|
|
bv()->unlockInset(static_cast<UpdatableInset *>(inset_owner->owner()));
|
|
|
|
|
inset_owner->owner()->close(bv());
|
|
|
|
|
bv()->getLyXText()->cursorRight(bv());
|
2002-02-12 12:56:46 +00:00
|
|
|
|
}
|
2001-07-19 08:52:59 +00:00
|
|
|
|
return;
|
2002-02-12 12:56:46 +00:00
|
|
|
|
}
|
2003-03-17 16:25:00 +00:00
|
|
|
|
//bv()->owner()->message(inset->editMessage());
|
2001-07-19 08:52:59 +00:00
|
|
|
|
|
|
|
|
|
// do we want to keep this?? (JMarc)
|
2001-11-09 13:44:48 +00:00
|
|
|
|
if (!isHighlyEditableInset(inset))
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursorParUndo(bv());
|
2001-07-24 22:08:49 +00:00
|
|
|
|
|
|
|
|
|
if (inset->isOpen()) {
|
2003-03-17 16:25:00 +00:00
|
|
|
|
inset->close(bv());
|
2001-07-24 22:08:49 +00:00
|
|
|
|
} else {
|
2003-03-17 16:25:00 +00:00
|
|
|
|
inset->open(bv());
|
2001-07-24 22:08:49 +00:00
|
|
|
|
}
|
2003-03-20 14:13:49 +00:00
|
|
|
|
|
|
|
|
|
bv()->updateInset(inset);
|
2001-07-11 12:10:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
/* used in setlayout */
|
|
|
|
|
// Asger is not sure we want to do this...
|
2003-02-26 17:04:10 +00:00
|
|
|
|
void LyXText::makeFontEntriesLayoutSpecific(Buffer const & buf,
|
|
|
|
|
Paragraph & par)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-02-26 17:04:10 +00:00
|
|
|
|
LyXLayout_ptr const & layout = par.layout();
|
2003-04-13 22:24:28 +00:00
|
|
|
|
pos_type const psize = par.size();
|
1999-11-04 01:40:20 +00:00
|
|
|
|
|
2001-07-30 11:56:00 +00:00
|
|
|
|
LyXFont layoutfont;
|
2003-04-13 22:24:28 +00:00
|
|
|
|
for (pos_type pos = 0; pos < psize; ++pos) {
|
2003-03-09 12:37:22 +00:00
|
|
|
|
if (pos < par.beginningOfBody())
|
2002-06-24 20:28:12 +00:00
|
|
|
|
layoutfont = layout->labelfont;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
2002-06-24 20:28:12 +00:00
|
|
|
|
layoutfont = layout->font;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-02-26 17:04:10 +00:00
|
|
|
|
LyXFont tmpfont = par.getFontSettings(buf.params, pos);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
tmpfont.reduce(layoutfont);
|
2003-02-26 17:04:10 +00:00
|
|
|
|
par.setFont(pos, tmpfont);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
2003-04-10 21:07:55 +00:00
|
|
|
|
ParagraphList::iterator
|
|
|
|
|
LyXText::setLayout(LyXCursor & cur, LyXCursor & sstart_cur,
|
|
|
|
|
LyXCursor & send_cur,
|
|
|
|
|
string const & layout)
|
2001-04-04 21:47:26 +00:00
|
|
|
|
{
|
2003-04-13 02:23:30 +00:00
|
|
|
|
ParagraphList::iterator endpit = boost::next(send_cur.par());
|
|
|
|
|
ParagraphList::iterator undoendpit = endpit;
|
2003-04-13 22:24:28 +00:00
|
|
|
|
ParagraphList::iterator pars_end = ownerParagraphs().end();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-13 22:24:28 +00:00
|
|
|
|
if (endpit != pars_end && endpit->getDepth()) {
|
|
|
|
|
while (endpit != pars_end && endpit->getDepth()) {
|
2003-04-13 02:23:30 +00:00
|
|
|
|
++endpit;
|
|
|
|
|
undoendpit = endpit;
|
2001-04-04 21:47:26 +00:00
|
|
|
|
}
|
2003-04-13 22:24:28 +00:00
|
|
|
|
} else if (endpit != pars_end) {
|
2003-04-13 02:23:30 +00:00
|
|
|
|
// because of parindents etc.
|
|
|
|
|
++endpit;
|
2001-04-04 21:47:26 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-13 02:23:30 +00:00
|
|
|
|
setUndo(bv(), Undo::EDIT, &*sstart_cur.par(), &*undoendpit);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// ok we have a selection. This is always between sstart_cur
|
|
|
|
|
// and sel_end cursor
|
2001-04-04 21:47:26 +00:00
|
|
|
|
cur = sstart_cur;
|
2003-04-09 09:15:20 +00:00
|
|
|
|
ParagraphList::iterator pit = sstart_cur.par();
|
|
|
|
|
ParagraphList::iterator epit = boost::next(send_cur.par());
|
2002-03-02 16:39:54 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
LyXLayout_ptr const & lyxlayout =
|
2003-03-17 16:25:00 +00:00
|
|
|
|
bv()->buffer()->params.getLyXTextClass()[layout];
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-02-27 14:02:10 +00:00
|
|
|
|
do {
|
2003-04-09 09:15:20 +00:00
|
|
|
|
pit->applyLayout(lyxlayout);
|
|
|
|
|
makeFontEntriesLayoutSpecific(*bv()->buffer(), *pit);
|
|
|
|
|
ParagraphList::iterator fppit = pit;
|
|
|
|
|
fppit->params().spaceTop(lyxlayout->fill_top ?
|
2001-07-07 18:19:18 +00:00
|
|
|
|
VSpace(VSpace::VFILL)
|
|
|
|
|
: VSpace(VSpace::NONE));
|
2003-04-09 09:15:20 +00:00
|
|
|
|
fppit->params().spaceBottom(lyxlayout->fill_bottom ?
|
2001-07-07 18:19:18 +00:00
|
|
|
|
VSpace(VSpace::VFILL)
|
|
|
|
|
: VSpace(VSpace::NONE));
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (lyxlayout->margintype == MARGIN_MANUAL)
|
2003-04-09 09:15:20 +00:00
|
|
|
|
pit->setLabelWidthString(lyxlayout->labelstring());
|
|
|
|
|
cur.par(pit);
|
|
|
|
|
++pit;
|
|
|
|
|
} while (pit != epit);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-13 02:23:30 +00:00
|
|
|
|
return endpit;
|
2000-05-04 08:14:34 +00:00
|
|
|
|
}
|
2001-04-04 21:47:26 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// set layout over selection and make a total rebreak of those paragraphs
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::setLayout(string const & layout)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-05-31 02:23:46 +00:00
|
|
|
|
LyXCursor tmpcursor = cursor; /* store the current cursor */
|
|
|
|
|
|
|
|
|
|
// if there is no selection just set the layout
|
|
|
|
|
// of the current paragraph */
|
|
|
|
|
if (!selection.set()) {
|
|
|
|
|
selection.start = cursor; // dummy selection
|
|
|
|
|
selection.end = cursor;
|
|
|
|
|
}
|
2003-04-10 21:07:55 +00:00
|
|
|
|
ParagraphList::iterator endpit = setLayout(cursor, selection.start,
|
|
|
|
|
selection.end, layout);
|
|
|
|
|
redoParagraphs(selection.start, endpit);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
// we have to reset the selection, because the
|
|
|
|
|
// geometry could have changed
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(selection.start.par(),
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.start.pos(), false);
|
|
|
|
|
selection.cursor = cursor;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(selection.end.par(), selection.end.pos(), false);
|
|
|
|
|
updateCounters();
|
2001-08-01 15:42:53 +00:00
|
|
|
|
clearSelection();
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setSelection();
|
|
|
|
|
setCursor(tmpcursor.par(), tmpcursor.pos(), true);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-04-03 01:26:02 +00:00
|
|
|
|
bool LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only)
|
2001-05-31 02:23:46 +00:00
|
|
|
|
{
|
2003-04-02 17:59:01 +00:00
|
|
|
|
ParagraphList::iterator pit(cursor.par());
|
|
|
|
|
ParagraphList::iterator end(cursor.par());
|
|
|
|
|
ParagraphList::iterator start = pit;
|
|
|
|
|
|
|
|
|
|
if (selection.set()) {
|
|
|
|
|
pit = selection.start.par();
|
|
|
|
|
end = selection.end.par();
|
|
|
|
|
start = pit;
|
2001-05-31 02:23:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-04-09 09:15:20 +00:00
|
|
|
|
ParagraphList::iterator pastend = boost::next(end);
|
|
|
|
|
|
2003-04-08 00:12:36 +00:00
|
|
|
|
if (!test_only)
|
|
|
|
|
setUndo(bv(), Undo::EDIT, &(*start), &(*pastend));
|
2001-05-31 02:23:46 +00:00
|
|
|
|
|
2003-04-03 01:26:02 +00:00
|
|
|
|
bool changed = false;
|
|
|
|
|
|
2003-04-02 17:59:01 +00:00
|
|
|
|
int prev_after_depth = 0;
|
|
|
|
|
#warning parlist ... could be nicer ?
|
2003-04-09 09:15:20 +00:00
|
|
|
|
if (start != ownerParagraphs().begin()) {
|
2003-04-02 17:59:01 +00:00
|
|
|
|
prev_after_depth = boost::prior(start)->getMaxDepthAfter();
|
2003-04-09 09:15:20 +00:00
|
|
|
|
}
|
2001-05-31 02:23:46 +00:00
|
|
|
|
|
2003-04-02 17:59:01 +00:00
|
|
|
|
while (true) {
|
|
|
|
|
int const depth = pit->params().depth();
|
2003-04-03 00:36:31 +00:00
|
|
|
|
if (type == bv_funcs::INC_DEPTH) {
|
|
|
|
|
if (depth < prev_after_depth
|
|
|
|
|
&& pit->layout()->labeltype != LABEL_BIBLIO) {
|
2003-04-03 01:26:02 +00:00
|
|
|
|
changed = true;
|
2003-04-09 09:15:20 +00:00
|
|
|
|
if (!test_only) {
|
2003-04-03 01:26:02 +00:00
|
|
|
|
pit->params().depth(depth + 1);
|
2003-04-09 09:15:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-04-03 00:36:31 +00:00
|
|
|
|
}
|
2003-04-03 01:26:02 +00:00
|
|
|
|
} else if (depth) {
|
|
|
|
|
changed = true;
|
|
|
|
|
if (!test_only)
|
2003-04-03 00:36:31 +00:00
|
|
|
|
pit->params().depth(depth - 1);
|
2003-04-02 17:59:01 +00:00
|
|
|
|
}
|
2001-05-31 02:23:46 +00:00
|
|
|
|
|
2003-04-02 17:59:01 +00:00
|
|
|
|
prev_after_depth = pit->getMaxDepthAfter();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-09 09:15:20 +00:00
|
|
|
|
if (pit == end) {
|
2001-07-07 18:19:18 +00:00
|
|
|
|
break;
|
2003-04-09 09:15:20 +00:00
|
|
|
|
}
|
2003-04-02 21:19:35 +00:00
|
|
|
|
|
2003-04-02 17:59:01 +00:00
|
|
|
|
++pit;
|
2001-05-31 02:23:46 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-03 01:26:02 +00:00
|
|
|
|
if (test_only)
|
|
|
|
|
return changed;
|
|
|
|
|
|
2003-04-02 17:59:01 +00:00
|
|
|
|
// Wow, redoParagraphs is stupid.
|
|
|
|
|
LyXCursor tmpcursor;
|
|
|
|
|
setCursor(tmpcursor, &(*start), 0);
|
2003-04-09 09:15:20 +00:00
|
|
|
|
|
|
|
|
|
//redoParagraphs(tmpcursor, &(*pastend));
|
2003-04-02 17:59:01 +00:00
|
|
|
|
redoParagraphs(tmpcursor, &(*pastend));
|
|
|
|
|
|
|
|
|
|
// We need to actually move the text->cursor. I don't
|
|
|
|
|
// understand why ...
|
|
|
|
|
tmpcursor = cursor;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-02 17:59:01 +00:00
|
|
|
|
// we have to reset the visual selection because the
|
2001-05-31 02:23:46 +00:00
|
|
|
|
// geometry could have changed
|
2003-04-02 17:59:01 +00:00
|
|
|
|
if (selection.set()) {
|
|
|
|
|
setCursor(selection.start.par(), selection.start.pos());
|
|
|
|
|
selection.cursor = cursor;
|
|
|
|
|
setCursor(selection.end.par(), selection.end.pos());
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-07 20:32:29 +00:00
|
|
|
|
// this handles the counter labels, and also fixes up
|
|
|
|
|
// depth values for follow-on (child) paragraphs
|
2003-03-17 16:25:00 +00:00
|
|
|
|
updateCounters();
|
2003-04-07 20:32:29 +00:00
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setSelection();
|
|
|
|
|
setCursor(tmpcursor.par(), tmpcursor.pos());
|
2003-04-03 01:26:02 +00:00
|
|
|
|
|
|
|
|
|
return changed;
|
2001-05-31 02:23:46 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// set font over selection and make a total rebreak of those paragraphs
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::setFont(LyXFont const & font, bool toggleall)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// if there is no selection just set the current_font
|
2001-05-31 02:23:46 +00:00
|
|
|
|
if (!selection.set()) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Determine basis font
|
|
|
|
|
LyXFont layoutfont;
|
2003-03-09 12:37:22 +00:00
|
|
|
|
if (cursor.pos() < cursor.par()->beginningOfBody()) {
|
2003-03-17 16:25:00 +00:00
|
|
|
|
layoutfont = getLabelFont(bv()->buffer(),
|
2003-04-10 12:10:04 +00:00
|
|
|
|
cursor.par());
|
2001-08-03 13:09:59 +00:00
|
|
|
|
} else {
|
2003-03-17 16:25:00 +00:00
|
|
|
|
layoutfont = getLayoutFont(bv()->buffer(),
|
2003-04-10 12:10:04 +00:00
|
|
|
|
cursor.par());
|
2001-08-03 13:09:59 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Update current font
|
2002-03-21 17:27:08 +00:00
|
|
|
|
real_current_font.update(font,
|
2003-03-17 16:25:00 +00:00
|
|
|
|
bv()->buffer()->params.language,
|
2001-08-11 18:31:14 +00:00
|
|
|
|
toggleall);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Reduce to implicit settings
|
|
|
|
|
current_font = real_current_font;
|
|
|
|
|
current_font.reduce(layoutfont);
|
|
|
|
|
// And resolve it completely
|
2001-08-11 18:31:14 +00:00
|
|
|
|
real_current_font.realize(layoutfont);
|
2002-09-06 15:18:11 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
LyXCursor tmpcursor = cursor; // store the current cursor
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// ok we have a selection. This is always between sel_start_cursor
|
|
|
|
|
// and sel_end cursor
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setUndo(bv(), Undo::EDIT,
|
2003-04-09 09:15:20 +00:00
|
|
|
|
&*selection.start.par(), &*boost::next(selection.end.par()));
|
2001-06-25 00:06:33 +00:00
|
|
|
|
freezeUndo();
|
2001-05-31 02:23:46 +00:00
|
|
|
|
cursor = selection.start;
|
|
|
|
|
while (cursor.par() != selection.end.par() ||
|
2002-05-29 16:21:03 +00:00
|
|
|
|
cursor.pos() < selection.end.pos())
|
2001-08-03 13:09:59 +00:00
|
|
|
|
{
|
2001-05-03 14:31:33 +00:00
|
|
|
|
if (cursor.pos() < cursor.par()->size()) {
|
2002-05-23 09:21:32 +00:00
|
|
|
|
// an open footnote should behave like a closed one
|
2003-04-13 12:56:48 +00:00
|
|
|
|
setCharFont(cursor.par(), cursor.pos(),
|
2001-07-07 18:19:18 +00:00
|
|
|
|
font, toggleall);
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cursor.pos(cursor.pos() + 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else {
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cursor.pos(0);
|
2003-04-13 02:23:30 +00:00
|
|
|
|
cursor.par(boost::next(cursor.par()));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
unFreezeUndo();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-13 02:23:30 +00:00
|
|
|
|
redoParagraphs(selection.start, boost::next(selection.end.par()));
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// we have to reset the selection, because the
|
2001-12-11 14:33:52 +00:00
|
|
|
|
// geometry could have changed, but we keep
|
|
|
|
|
// it for user convenience
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(selection.start.par(), selection.start.pos());
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.cursor = cursor;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(selection.end.par(), selection.end.pos());
|
|
|
|
|
setSelection();
|
|
|
|
|
setCursor(tmpcursor.par(), tmpcursor.pos(), true,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
tmpcursor.boundary());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::redoHeightOfParagraph()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-04-01 10:10:28 +00:00
|
|
|
|
RowList::iterator tmprow = cursor.row();
|
2003-03-13 21:19:01 +00:00
|
|
|
|
int y = cursor.y() - tmprow->baseline();
|
1999-11-04 01:40:20 +00:00
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setHeightOfRow(tmprow);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-01 10:10:28 +00:00
|
|
|
|
while (tmprow != rows().begin()
|
|
|
|
|
&& boost::prior(tmprow)->par() == tmprow->par()) {
|
|
|
|
|
--tmprow;
|
2000-06-08 23:16:16 +00:00
|
|
|
|
y -= tmprow->height();
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setHeightOfRow(tmprow);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
postPaint(y);
|
2003-03-17 01:34:36 +00:00
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(cursor.par(), cursor.pos(), false, cursor.boundary());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::redoDrawingOfParagraph(LyXCursor const & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-04-01 10:10:28 +00:00
|
|
|
|
RowList::iterator tmprow = cur.row();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-09-29 18:44:07 +00:00
|
|
|
|
int y = cur.y() - tmprow->baseline();
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setHeightOfRow(tmprow);
|
2001-07-03 15:19:04 +00:00
|
|
|
|
|
2003-04-01 10:10:28 +00:00
|
|
|
|
while (tmprow != rows().begin()
|
|
|
|
|
&& boost::prior(tmprow)->par() == tmprow->par()) {
|
|
|
|
|
--tmprow;
|
2001-07-03 15:19:04 +00:00
|
|
|
|
y -= tmprow->height();
|
|
|
|
|
}
|
2001-07-07 18:02:19 +00:00
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
postPaint(y);
|
|
|
|
|
setCursor(cur.par(), cur.pos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// deletes and inserts again all paragaphs between the cursor
|
2002-03-21 17:27:08 +00:00
|
|
|
|
// and the specified par
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// This function is needed after SetLayout and SetFont etc.
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::redoParagraphs(LyXCursor const & cur,
|
2003-04-10 21:07:55 +00:00
|
|
|
|
ParagraphList::iterator endpit)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-04-01 00:01:42 +00:00
|
|
|
|
RowList::iterator tmprit = cur.row();
|
|
|
|
|
int y = cur.y() - tmprit->baseline();
|
2001-07-03 15:19:04 +00:00
|
|
|
|
|
2003-04-02 23:01:39 +00:00
|
|
|
|
ParagraphList::iterator first_phys_pit;
|
2003-04-01 00:01:42 +00:00
|
|
|
|
if (tmprit == rows().begin()) {
|
2003-04-01 08:59:25 +00:00
|
|
|
|
// A trick/hack for UNDO.
|
|
|
|
|
// This is needed because in an UNDO/REDO we could have
|
|
|
|
|
// changed the ownerParagrah() so the paragraph inside
|
|
|
|
|
// the row is NOT my really first par anymore.
|
|
|
|
|
// Got it Lars ;) (Jug 20011206)
|
2003-04-02 23:01:39 +00:00
|
|
|
|
first_phys_pit = ownerParagraphs().begin();
|
2003-04-01 08:59:25 +00:00
|
|
|
|
#warning FIXME
|
|
|
|
|
// In here prevrit could be set to rows().end(). (Lgb)
|
2001-07-03 15:19:04 +00:00
|
|
|
|
} else {
|
2003-04-02 23:01:39 +00:00
|
|
|
|
first_phys_pit = tmprit->par();
|
2003-04-01 00:01:42 +00:00
|
|
|
|
while (tmprit != rows().begin()
|
2003-04-02 23:01:39 +00:00
|
|
|
|
&& boost::prior(tmprit)->par() == first_phys_pit)
|
2001-08-02 14:55:06 +00:00
|
|
|
|
{
|
2003-04-01 00:01:42 +00:00
|
|
|
|
--tmprit;
|
|
|
|
|
y -= tmprit->height();
|
2001-07-03 15:19:04 +00:00
|
|
|
|
}
|
2003-04-01 08:59:25 +00:00
|
|
|
|
#warning FIXME
|
|
|
|
|
// Is it possible to put the prevrit setting in here? (Lgb)
|
2001-07-03 15:19:04 +00:00
|
|
|
|
}
|
2001-12-11 14:33:52 +00:00
|
|
|
|
|
2003-04-01 00:01:42 +00:00
|
|
|
|
RowList::iterator prevrit;
|
2003-04-01 08:59:25 +00:00
|
|
|
|
bool good_prevrit = false;
|
|
|
|
|
#warning FIXME
|
|
|
|
|
// It seems to mee that good_prevrit is not needed if we let
|
|
|
|
|
// a bad prevrit have the value rows().end() (Lgb)
|
2003-04-01 00:01:42 +00:00
|
|
|
|
if (tmprit != rows().begin()) {
|
|
|
|
|
prevrit = boost::prior(tmprit);
|
2003-04-01 08:59:25 +00:00
|
|
|
|
good_prevrit = true;
|
2003-04-01 00:01:42 +00:00
|
|
|
|
}
|
2003-03-17 01:34:36 +00:00
|
|
|
|
|
2003-04-01 00:01:42 +00:00
|
|
|
|
// remove it
|
2003-04-02 23:01:39 +00:00
|
|
|
|
while (tmprit != rows().end() && tmprit->par() != endpit) {
|
2003-04-01 08:59:25 +00:00
|
|
|
|
RowList::iterator tmprit2 = tmprit++;
|
|
|
|
|
removeRow(tmprit2);
|
2001-12-11 14:33:52 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-03-27 12:41:47 +00:00
|
|
|
|
// Reinsert the paragraphs.
|
2003-04-02 23:01:39 +00:00
|
|
|
|
ParagraphList::iterator tmppit = first_phys_pit;
|
2003-04-01 08:59:25 +00:00
|
|
|
|
#warning FIXME
|
|
|
|
|
// See if this loop can be rewritten as a while loop instead.
|
|
|
|
|
// That should also make the code a bit easier to read. (Lgb)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
do {
|
2003-04-02 23:01:39 +00:00
|
|
|
|
if (tmppit != ownerParagraphs().end()) {
|
2003-04-13 12:56:48 +00:00
|
|
|
|
insertParagraph(tmppit, tmprit);
|
2003-04-01 00:01:42 +00:00
|
|
|
|
while (tmprit != rows().end()
|
2003-04-02 23:01:39 +00:00
|
|
|
|
&& tmprit->par() == tmppit) {
|
2003-04-01 00:01:42 +00:00
|
|
|
|
++tmprit;
|
2001-07-07 18:19:18 +00:00
|
|
|
|
}
|
2003-04-02 23:01:39 +00:00
|
|
|
|
++tmppit;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2003-04-02 23:01:39 +00:00
|
|
|
|
} while (tmppit != ownerParagraphs().end() && tmppit != endpit);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-01 08:59:25 +00:00
|
|
|
|
#warning FIXME
|
|
|
|
|
// If the above changes are done, then we can compare prevrit
|
|
|
|
|
// with rows().end() here. (Lgb)
|
|
|
|
|
if (good_prevrit) {
|
|
|
|
|
setHeightOfRow(prevrit);
|
|
|
|
|
const_cast<LyXText *>(this)->postPaint(y - prevrit->height());
|
|
|
|
|
} else {
|
|
|
|
|
setHeightOfRow(rows().begin());
|
|
|
|
|
const_cast<LyXText *>(this)->postPaint(0);
|
|
|
|
|
}
|
|
|
|
|
if (tmprit != rows().end())
|
|
|
|
|
setHeightOfRow(tmprit);
|
2003-04-09 09:15:20 +00:00
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
updateCounters();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::fullRebreak()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-03-29 23:11:20 +00:00
|
|
|
|
if (rows().empty()) {
|
2003-03-17 16:25:00 +00:00
|
|
|
|
init(bv());
|
2002-05-01 22:17:09 +00:00
|
|
|
|
return;
|
2000-06-21 15:07:57 +00:00
|
|
|
|
}
|
2003-04-13 22:24:28 +00:00
|
|
|
|
|
|
|
|
|
RowList::iterator rows_end = rows().end();
|
|
|
|
|
|
|
|
|
|
if (need_break_row != rows_end) {
|
2003-03-17 16:25:00 +00:00
|
|
|
|
breakAgain(need_break_row);
|
2003-04-13 22:24:28 +00:00
|
|
|
|
need_break_row = rows_end;
|
2002-05-01 22:17:09 +00:00
|
|
|
|
return;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// important for the screen
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2002-05-29 13:28:11 +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
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// need the selection cursor:
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::setSelection()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-05-31 02:23:46 +00:00
|
|
|
|
bool const lsel = selection.set();
|
2001-02-14 08:38:21 +00:00
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
if (!selection.set()) {
|
|
|
|
|
last_sel_cursor = selection.cursor;
|
|
|
|
|
selection.start = selection.cursor;
|
|
|
|
|
selection.end = selection.cursor;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.set(true);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// first the toggling area
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (cursor.y() < last_sel_cursor.y()
|
|
|
|
|
|| (cursor.y() == last_sel_cursor.y()
|
2001-07-07 18:19:18 +00:00
|
|
|
|
&& cursor.x() < last_sel_cursor.x())) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
toggle_end_cursor = last_sel_cursor;
|
|
|
|
|
toggle_cursor = cursor;
|
2000-05-20 21:37:05 +00:00
|
|
|
|
} else {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
toggle_end_cursor = cursor;
|
|
|
|
|
toggle_cursor = last_sel_cursor;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
last_sel_cursor = cursor;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// and now the whole selection
|
2000-02-03 19:51:27 +00:00
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
if (selection.cursor.par() == cursor.par())
|
2001-07-07 18:19:18 +00:00
|
|
|
|
if (selection.cursor.pos() < cursor.pos()) {
|
|
|
|
|
selection.end = cursor;
|
|
|
|
|
selection.start = selection.cursor;
|
|
|
|
|
} else {
|
2002-03-21 17:27:08 +00:00
|
|
|
|
selection.end = selection.cursor;
|
2001-07-07 18:19:18 +00:00
|
|
|
|
selection.start = cursor;
|
|
|
|
|
}
|
2001-05-31 02:23:46 +00:00
|
|
|
|
else if (selection.cursor.y() < cursor.y() ||
|
2001-07-07 18:19:18 +00:00
|
|
|
|
(selection.cursor.y() == cursor.y()
|
|
|
|
|
&& selection.cursor.x() < cursor.x())) {
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.end = cursor;
|
|
|
|
|
selection.start = selection.cursor;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
2002-03-21 17:27:08 +00:00
|
|
|
|
selection.end = selection.cursor;
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.start = cursor;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// a selection with no contents is not a selection
|
2002-03-21 17:27:08 +00:00
|
|
|
|
if (selection.start.par() == selection.end.par() &&
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.start.pos() == selection.end.pos())
|
|
|
|
|
selection.set(false);
|
2001-02-14 08:38:21 +00:00
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
if (inset_owner && (selection.set() || lsel))
|
2003-03-17 16:25:00 +00:00
|
|
|
|
inset_owner->setUpdateStatus(bv(), InsetText::SELECTION);
|
2000-05-20 21:37:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-09-12 10:41:25 +00:00
|
|
|
|
string const LyXText::selectionAsString(Buffer const * buffer,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
bool label) const
|
2000-05-20 21:37:05 +00:00
|
|
|
|
{
|
2001-05-31 02:23:46 +00:00
|
|
|
|
if (!selection.set()) return string();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-08-04 23:11:50 +00:00
|
|
|
|
// should be const ...
|
2003-04-09 09:15:20 +00:00
|
|
|
|
ParagraphList::iterator startpit = selection.start.par();
|
|
|
|
|
ParagraphList::iterator endpit = selection.end.par();
|
2002-08-04 23:11:50 +00:00
|
|
|
|
pos_type const startpos(selection.start.pos());
|
|
|
|
|
pos_type const endpos(selection.end.pos());
|
2002-08-10 15:21:07 +00:00
|
|
|
|
|
2003-04-09 09:15:20 +00:00
|
|
|
|
if (startpit == endpit) {
|
|
|
|
|
return startpit->asString(buffer, startpos, endpos, label);
|
2000-05-20 21:37:05 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-08-04 23:11:50 +00:00
|
|
|
|
string result;
|
2000-05-20 21:37:05 +00:00
|
|
|
|
|
|
|
|
|
// First paragraph in selection
|
2003-04-09 09:15:20 +00:00
|
|
|
|
result += startpit->asString(buffer, startpos, startpit->size(), label) + "\n\n";
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-05-20 21:37:05 +00:00
|
|
|
|
// The paragraphs in between (if any)
|
2003-04-13 22:24:28 +00:00
|
|
|
|
ParagraphList::iterator pit = boost::next(startpit);
|
|
|
|
|
for (; pit != endpit; ++pit) {
|
|
|
|
|
result += pit->asString(buffer, 0, pit->size(), label) + "\n\n";
|
2000-05-20 21:37:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Last paragraph in selection
|
2003-04-09 09:15:20 +00:00
|
|
|
|
result += endpit->asString(buffer, 0, endpos, label);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-05-20 21:37:05 +00:00
|
|
|
|
return result;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-18 13:05:08 +00:00
|
|
|
|
void LyXText::clearSelection()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.set(false);
|
|
|
|
|
selection.mark(false);
|
2001-12-04 16:10:19 +00:00
|
|
|
|
last_sel_cursor = selection.end = selection.start = selection.cursor = cursor;
|
2002-03-20 10:36:03 +00:00
|
|
|
|
// reset this in the bv_owner!
|
|
|
|
|
if (bv_owner && bv_owner->text)
|
|
|
|
|
bv_owner->text->xsel_cache.set(false);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-18 13:05:08 +00:00
|
|
|
|
void LyXText::cursorHome()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(cursor.par(), cursor.row()->pos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-18 13:05:08 +00:00
|
|
|
|
void LyXText::cursorEnd()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-03-28 04:04:36 +00:00
|
|
|
|
if (cursor.par()->empty())
|
|
|
|
|
return;
|
|
|
|
|
|
2003-04-13 22:24:28 +00:00
|
|
|
|
RowList::iterator rit = cursor.row();
|
|
|
|
|
RowList::iterator next_rit = boost::next(rit);
|
|
|
|
|
ParagraphList::iterator pit = rit->par();
|
|
|
|
|
pos_type last_pos = lastPos(*this, rit);
|
|
|
|
|
|
|
|
|
|
if (next_rit == rows().end() || next_rit->par() != pit) {
|
|
|
|
|
++last_pos;
|
2001-07-07 18:19:18 +00:00
|
|
|
|
} else {
|
2003-04-13 22:24:28 +00:00
|
|
|
|
if (pit->empty() ||
|
|
|
|
|
(pit->getChar(last_pos) != ' ' && !pit->isNewline(last_pos))) {
|
|
|
|
|
++last_pos;
|
2001-07-07 18:19:18 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2003-04-13 22:24:28 +00:00
|
|
|
|
|
|
|
|
|
setCursor(pit, last_pos);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-18 13:05:08 +00:00
|
|
|
|
void LyXText::cursorTop()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-04-13 01:04:04 +00:00
|
|
|
|
setCursor(ownerParagraphs().begin(), 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-18 13:05:08 +00:00
|
|
|
|
void LyXText::cursorBottom()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-04-13 01:04:04 +00:00
|
|
|
|
#warning FIXME
|
|
|
|
|
// This is how it should be:
|
|
|
|
|
// ParagraphList::iterator lastpit = boost::prior(ownerParagraphs().end());
|
|
|
|
|
ParagraphList::iterator lastpit = &ownerParagraphs().back();
|
|
|
|
|
int pos = lastpit->size();
|
|
|
|
|
setCursor(lastpit, pos);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::toggleFree(LyXFont const & font, bool toggleall)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
// If the mask is completely neutral, tell user
|
2000-02-17 19:59:08 +00:00
|
|
|
|
if (font == LyXFont(LyXFont::ALL_IGNORE)) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Could only happen with user style
|
2003-03-17 16:25:00 +00:00
|
|
|
|
bv()->owner()->message(_("No font change defined. Use Character under the Layout menu to define font change."));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Try implicit word selection
|
2002-03-21 17:27:08 +00:00
|
|
|
|
// If there is a change in the language the implicit word selection
|
2000-04-24 20:58:23 +00:00
|
|
|
|
// is disabled.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
LyXCursor resetCursor = cursor;
|
2000-10-09 12:30:52 +00:00
|
|
|
|
bool implicitSelection = (font.language() == ignore_language
|
2002-03-21 17:27:08 +00:00
|
|
|
|
&& font.number() == LyXFont::IGNORE)
|
2003-03-17 16:25:00 +00:00
|
|
|
|
? selectWordWhenUnderCursor(WHOLE_WORD_STRICT) : false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Set font
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setFont(font, toggleall);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// Implicit selections are cleared afterwards
|
|
|
|
|
//and cursor is set to the original position.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (implicitSelection) {
|
2001-08-01 15:42:53 +00:00
|
|
|
|
clearSelection();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
cursor = resetCursor;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(cursor.par(), cursor.pos());
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.cursor = cursor;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-02-14 08:38:21 +00:00
|
|
|
|
if (inset_owner)
|
2003-03-17 16:25:00 +00:00
|
|
|
|
inset_owner->setUpdateStatus(bv(), InsetText::CURSOR_PAR);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
string LyXText::getStringToIndex()
|
2001-07-30 10:50:37 +00:00
|
|
|
|
{
|
|
|
|
|
// Try implicit word selection
|
2002-03-21 17:27:08 +00:00
|
|
|
|
// If there is a change in the language the implicit word selection
|
2001-07-30 10:50:37 +00:00
|
|
|
|
// is disabled.
|
2002-08-06 22:38:44 +00:00
|
|
|
|
LyXCursor const reset_cursor = cursor;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
bool const implicitSelection = selectWordWhenUnderCursor(PREVIOUS_WORD);
|
2001-07-30 10:50:37 +00:00
|
|
|
|
|
2003-01-31 13:50:21 +00:00
|
|
|
|
string idxstring;
|
|
|
|
|
if (!selection.set())
|
2003-03-17 16:25:00 +00:00
|
|
|
|
bv()->owner()->message(_("Nothing to index!"));
|
2003-01-31 13:50:21 +00:00
|
|
|
|
else if (selection.start.par() != selection.end.par())
|
2003-03-17 16:25:00 +00:00
|
|
|
|
bv()->owner()->message(_("Cannot index more than one paragraph!"));
|
2003-01-31 13:50:21 +00:00
|
|
|
|
else
|
2003-03-17 16:25:00 +00:00
|
|
|
|
idxstring = selectionAsString(bv()->buffer(), false);
|
2001-07-30 10:50:37 +00:00
|
|
|
|
|
2003-01-31 13:50:21 +00:00
|
|
|
|
// Reset cursors to their original position.
|
|
|
|
|
cursor = reset_cursor;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(cursor.par(), cursor.pos());
|
2003-01-31 13:50:21 +00:00
|
|
|
|
selection.cursor = cursor;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-01-31 13:50:21 +00:00
|
|
|
|
// Clear the implicit selection.
|
|
|
|
|
if (implicitSelection)
|
2001-08-01 15:42:53 +00:00
|
|
|
|
clearSelection();
|
2003-01-31 13:50:21 +00:00
|
|
|
|
|
2001-07-30 10:50:37 +00:00
|
|
|
|
return idxstring;
|
|
|
|
|
}
|
|
|
|
|
|
2001-10-18 16:17:46 +00:00
|
|
|
|
|
2002-05-29 13:28:11 +00:00
|
|
|
|
// the DTP switches for paragraphs. LyX will store them in the first
|
|
|
|
|
// physicla paragraph. When a paragraph is broken, the top settings rest,
|
|
|
|
|
// the bottom settings are given to the new one. So I can make shure,
|
|
|
|
|
// they do not duplicate themself and you cannnot make dirty things with
|
|
|
|
|
// them!
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::setParagraph(bool line_top, bool line_bottom,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
bool pagebreak_top, bool pagebreak_bottom,
|
2000-01-13 16:28:54 +00:00
|
|
|
|
VSpace const & space_top,
|
|
|
|
|
VSpace const & space_bottom,
|
2001-10-18 16:17:46 +00:00
|
|
|
|
Spacing const & spacing,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
LyXAlignment align,
|
2003-03-17 16:25:00 +00:00
|
|
|
|
string const & labelwidthstring,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
bool noindent)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
|
LyXCursor tmpcursor = cursor;
|
2001-05-31 02:23:46 +00:00
|
|
|
|
if (!selection.set()) {
|
|
|
|
|
selection.start = cursor;
|
|
|
|
|
selection.end = cursor;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// make sure that the depth behind the selection are restored, too
|
2003-04-13 01:04:04 +00:00
|
|
|
|
ParagraphList::iterator endpit = boost::next(selection.end.par());
|
|
|
|
|
ParagraphList::iterator undoendpit = endpit;
|
2003-04-13 22:24:28 +00:00
|
|
|
|
ParagraphList::iterator pars_end = ownerParagraphs().end();
|
2003-04-13 01:04:04 +00:00
|
|
|
|
|
2003-04-13 22:24:28 +00:00
|
|
|
|
if (endpit != pars_end && endpit->getDepth()) {
|
|
|
|
|
while (endpit != pars_end && endpit->getDepth()) {
|
2003-04-13 01:04:04 +00:00
|
|
|
|
++endpit;
|
|
|
|
|
undoendpit = endpit;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2003-04-13 22:24:28 +00:00
|
|
|
|
} else if (endpit!= pars_end) {
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// because of parindents etc.
|
2003-04-13 01:04:04 +00:00
|
|
|
|
++endpit;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-13 01:04:04 +00:00
|
|
|
|
setUndo(bv(), Undo::EDIT, &*selection.start.par(), &*undoendpit);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-09 09:15:20 +00:00
|
|
|
|
ParagraphList::iterator tmppit = selection.end.par();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-09 09:15:20 +00:00
|
|
|
|
while (tmppit != boost::prior(selection.start.par())) {
|
|
|
|
|
setCursor(tmppit, 0);
|
2003-03-17 16:25:00 +00:00
|
|
|
|
postPaint(cursor.y() - cursor.row()->baseline());
|
2003-04-13 22:24:28 +00:00
|
|
|
|
|
|
|
|
|
ParagraphList::iterator pit = cursor.par();
|
|
|
|
|
ParagraphParameters & params = pit->params();
|
|
|
|
|
|
|
|
|
|
params.lineTop(line_top);
|
|
|
|
|
params.lineBottom(line_bottom);
|
|
|
|
|
params.pagebreakTop(pagebreak_top);
|
|
|
|
|
params.pagebreakBottom(pagebreak_bottom);
|
|
|
|
|
params.spaceTop(space_top);
|
|
|
|
|
params.spaceBottom(space_bottom);
|
|
|
|
|
params.spacing(spacing);
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// does the layout allow the new alignment?
|
2003-04-13 22:24:28 +00:00
|
|
|
|
LyXLayout_ptr const & layout = pit->layout();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
if (align == LYX_ALIGN_LAYOUT)
|
2002-06-24 20:28:12 +00:00
|
|
|
|
align = layout->align;
|
|
|
|
|
if (align & layout->alignpossible) {
|
|
|
|
|
if (align == layout->align)
|
2003-04-13 22:24:28 +00:00
|
|
|
|
params.align(LYX_ALIGN_LAYOUT);
|
2001-07-07 18:19:18 +00:00
|
|
|
|
else
|
2003-04-13 22:24:28 +00:00
|
|
|
|
params.align(align);
|
2001-07-07 18:19:18 +00:00
|
|
|
|
}
|
2003-04-13 22:24:28 +00:00
|
|
|
|
pit->setLabelWidthString(labelwidthstring);
|
|
|
|
|
params.noindent(noindent);
|
|
|
|
|
tmppit = boost::prior(pit);
|
1999-11-04 01:40:20 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-13 01:04:04 +00:00
|
|
|
|
redoParagraphs(selection.start, endpit);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-08-01 15:42:53 +00:00
|
|
|
|
clearSelection();
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(selection.start.par(), selection.start.pos());
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.cursor = cursor;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(selection.end.par(), selection.end.pos());
|
|
|
|
|
setSelection();
|
|
|
|
|
setCursor(tmpcursor.par(), tmpcursor.pos());
|
2000-08-01 09:35:42 +00:00
|
|
|
|
if (inset_owner)
|
2003-03-19 14:45:22 +00:00
|
|
|
|
bv()->updateInset(inset_owner);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// set the counter of a paragraph. This includes the labels
|
2003-04-10 21:07:55 +00:00
|
|
|
|
void LyXText::setCounter(Buffer const * buf, ParagraphList::iterator pit)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-07-21 21:21:06 +00:00
|
|
|
|
LyXTextClass const & textclass = buf->params.getLyXTextClass();
|
2003-04-10 21:07:55 +00:00
|
|
|
|
LyXLayout_ptr const & layout = pit->layout();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-04-10 21:07:55 +00:00
|
|
|
|
if (pit != ownerParagraphs().begin()) {
|
2002-08-06 22:40:59 +00:00
|
|
|
|
|
2003-04-10 21:07:55 +00:00
|
|
|
|
pit->params().appendix(boost::prior(pit)->params().appendix());
|
|
|
|
|
if (!pit->params().appendix() &&
|
|
|
|
|
pit->params().startOfAppendix()) {
|
|
|
|
|
pit->params().appendix(true);
|
2002-09-06 14:48:01 +00:00
|
|
|
|
textclass.counters().reset();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2003-04-10 21:07:55 +00:00
|
|
|
|
pit->enumdepth = boost::prior(pit)->enumdepth;
|
|
|
|
|
pit->itemdepth = boost::prior(pit)->itemdepth;
|
2000-07-18 17:45:27 +00:00
|
|
|
|
} else {
|
2003-04-10 21:07:55 +00:00
|
|
|
|
pit->params().appendix(pit->params().startOfAppendix());
|
|
|
|
|
pit->enumdepth = 0;
|
|
|
|
|
pit->itemdepth = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Maybe we have to increment the enumeration depth.
|
|
|
|
|
* BUT, enumeration in a footnote is considered in isolation from its
|
|
|
|
|
* surrounding paragraph so don't increment if this is the
|
|
|
|
|
* first line of the footnote
|
|
|
|
|
* AND, bibliographies can't have their depth changed ie. they
|
|
|
|
|
* are always of depth 0
|
|
|
|
|
*/
|
2003-04-10 21:07:55 +00:00
|
|
|
|
if (pit != ownerParagraphs().begin()
|
|
|
|
|
&& boost::prior(pit)->getDepth() < pit->getDepth()
|
|
|
|
|
&& boost::prior(pit)->layout()->labeltype == LABEL_COUNTER_ENUMI
|
|
|
|
|
&& pit->enumdepth < 3
|
2002-06-24 20:28:12 +00:00
|
|
|
|
&& layout->labeltype != LABEL_BIBLIO) {
|
2003-04-10 21:07:55 +00:00
|
|
|
|
pit->enumdepth++;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// Maybe we have to decrement the enumeration depth, see note above
|
2003-04-10 21:07:55 +00:00
|
|
|
|
if (pit != ownerParagraphs().begin()
|
|
|
|
|
&& boost::prior(pit)->getDepth() > pit->getDepth()
|
2002-06-24 20:28:12 +00:00
|
|
|
|
&& layout->labeltype != LABEL_BIBLIO) {
|
2003-04-14 18:35:29 +00:00
|
|
|
|
pit->enumdepth = depthHook(&*pit, pit->getDepth())->enumdepth;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-10 21:07:55 +00:00
|
|
|
|
if (!pit->params().labelString().empty()) {
|
|
|
|
|
pit->params().labelString(string());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (layout->margintype == MARGIN_MANUAL) {
|
2003-04-10 21:07:55 +00:00
|
|
|
|
if (pit->params().labelWidthString().empty()) {
|
|
|
|
|
pit->setLabelWidthString(layout->labelstring());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-02-29 02:19:17 +00:00
|
|
|
|
} else {
|
2003-04-10 21:07:55 +00:00
|
|
|
|
pit->setLabelWidthString(string());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-08-10 15:21:07 +00:00
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// is it a layout that has an automatic label?
|
2002-08-21 14:23:28 +00:00
|
|
|
|
if (layout->labeltype >= LABEL_COUNTER_CHAPTER) {
|
2002-12-01 21:10:37 +00:00
|
|
|
|
int const i = layout->labeltype - LABEL_COUNTER_CHAPTER;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-08-06 22:40:59 +00:00
|
|
|
|
ostringstream s;
|
|
|
|
|
|
2002-08-21 14:23:28 +00:00
|
|
|
|
if (i >= 0 && i <= buf->params.secnumdepth) {
|
2002-12-01 21:10:37 +00:00
|
|
|
|
string numbertype;
|
|
|
|
|
string langtype;
|
2002-08-06 22:40:59 +00:00
|
|
|
|
|
2002-09-06 14:48:01 +00:00
|
|
|
|
textclass.counters().step(layout->latexname());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Is there a label? Useful for Chapter layout
|
2003-04-10 21:07:55 +00:00
|
|
|
|
if (!pit->params().appendix()) {
|
2002-12-01 21:10:37 +00:00
|
|
|
|
s << layout->labelstring();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
} else {
|
2002-12-01 21:10:37 +00:00
|
|
|
|
s << layout->labelstring_appendix();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-03-08 01:45:25 +00:00
|
|
|
|
|
2002-12-01 21:10:37 +00:00
|
|
|
|
// Use of an integer is here less than elegant. For now.
|
2002-08-06 22:40:59 +00:00
|
|
|
|
int head = textclass.maxcounter() - LABEL_COUNTER_CHAPTER;
|
2003-04-10 21:07:55 +00:00
|
|
|
|
if (!pit->params().appendix()) {
|
2002-08-06 22:40:59 +00:00
|
|
|
|
numbertype = "sectioning";
|
|
|
|
|
} else {
|
|
|
|
|
numbertype = "appendix";
|
2003-04-10 21:07:55 +00:00
|
|
|
|
if (pit->isRightToLeftPar(buf->params))
|
2002-08-06 22:40:59 +00:00
|
|
|
|
langtype = "hebrew";
|
|
|
|
|
else
|
|
|
|
|
langtype = "latin";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-08-10 15:21:07 +00:00
|
|
|
|
|
2002-09-06 14:48:01 +00:00
|
|
|
|
s << textclass.counters()
|
2002-09-05 12:58:10 +00:00
|
|
|
|
.numberLabel(layout->latexname(),
|
|
|
|
|
numbertype, langtype, head);
|
2000-09-18 17:39:21 +00:00
|
|
|
|
|
2003-04-10 21:07:55 +00:00
|
|
|
|
pit->params().labelString(STRCONV(s.str()));
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-08-06 22:40:59 +00:00
|
|
|
|
// reset enum counters
|
2002-09-06 14:48:01 +00:00
|
|
|
|
textclass.counters().reset("enum");
|
2002-06-24 20:28:12 +00:00
|
|
|
|
} else if (layout->labeltype < LABEL_COUNTER_ENUMI) {
|
2002-09-06 14:48:01 +00:00
|
|
|
|
textclass.counters().reset("enum");
|
2002-06-24 20:28:12 +00:00
|
|
|
|
} else if (layout->labeltype == LABEL_COUNTER_ENUMI) {
|
2002-09-05 12:58:10 +00:00
|
|
|
|
// FIXME
|
|
|
|
|
// Yes I know this is a really, really! bad solution
|
|
|
|
|
// (Lgb)
|
|
|
|
|
string enumcounter("enum");
|
|
|
|
|
|
2003-04-10 21:07:55 +00:00
|
|
|
|
switch (pit->enumdepth) {
|
2002-09-05 12:58:10 +00:00
|
|
|
|
case 2:
|
|
|
|
|
enumcounter += 'i';
|
|
|
|
|
case 1:
|
|
|
|
|
enumcounter += 'i';
|
|
|
|
|
case 0:
|
|
|
|
|
enumcounter += 'i';
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
enumcounter += "iv";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
// not a valid enumdepth...
|
|
|
|
|
break;
|
|
|
|
|
}
|
2000-09-18 17:39:21 +00:00
|
|
|
|
|
2002-09-06 14:48:01 +00:00
|
|
|
|
textclass.counters().step(enumcounter);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-09-06 14:48:01 +00:00
|
|
|
|
s << textclass.counters()
|
2002-12-01 21:10:37 +00:00
|
|
|
|
.numberLabel(enumcounter, "enumeration");
|
2003-04-10 21:07:55 +00:00
|
|
|
|
pit->params().labelString(STRCONV(s.str()));
|
2002-03-21 17:27:08 +00:00
|
|
|
|
}
|
2002-06-24 20:28:12 +00:00
|
|
|
|
} else if (layout->labeltype == LABEL_BIBLIO) {// ale970302
|
2002-09-06 14:48:01 +00:00
|
|
|
|
textclass.counters().step("bibitem");
|
|
|
|
|
int number = textclass.counters().value("bibitem");
|
2003-04-10 21:07:55 +00:00
|
|
|
|
if (pit->bibitem()) {
|
|
|
|
|
pit->bibitem()->setCounter(number);
|
|
|
|
|
pit->params().labelString(layout->labelstring());
|
2000-08-04 13:12:30 +00:00
|
|
|
|
}
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// In biblio should't be following counters but...
|
|
|
|
|
} else {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
string s = layout->labelstring();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// the caption hack:
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (layout->labeltype == LABEL_SENSITIVE) {
|
2003-04-10 21:07:55 +00:00
|
|
|
|
ParagraphList::iterator tmppit = pit;
|
2002-08-20 11:14:46 +00:00
|
|
|
|
Inset * in = 0;
|
|
|
|
|
bool isOK = false;
|
2003-04-10 21:07:55 +00:00
|
|
|
|
while (tmppit != ownerParagraphs().end() &&
|
|
|
|
|
tmppit->inInset()
|
2002-08-20 11:14:46 +00:00
|
|
|
|
// the single '=' is intended below
|
2003-04-10 21:07:55 +00:00
|
|
|
|
&& (in = tmppit->inInset()->owner())) {
|
2002-09-10 10:18:58 +00:00
|
|
|
|
if (in->lyxCode() == Inset::FLOAT_CODE ||
|
|
|
|
|
in->lyxCode() == Inset::WRAP_CODE) {
|
2002-08-20 11:14:46 +00:00
|
|
|
|
isOK = true;
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
2003-04-10 21:07:55 +00:00
|
|
|
|
tmppit = in->parOwner();
|
2002-08-20 11:14:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-07-19 17:16:27 +00:00
|
|
|
|
if (isOK) {
|
2000-07-18 17:45:27 +00:00
|
|
|
|
Floating const & fl
|
2002-08-27 15:51:19 +00:00
|
|
|
|
= textclass.floats().getType(static_cast<InsetFloat*>(in)->type());
|
2002-08-06 22:40:59 +00:00
|
|
|
|
|
2002-09-06 14:48:01 +00:00
|
|
|
|
textclass.counters().step(fl.type());
|
2002-08-20 21:50:08 +00:00
|
|
|
|
|
2002-08-12 20:24:10 +00:00
|
|
|
|
// Doesn't work... yet.
|
2002-12-01 21:10:37 +00:00
|
|
|
|
#if USE_BOOST_FORMAT
|
|
|
|
|
s = boost::io::str(boost::format(_("%1$s #:")) % fl.name());
|
|
|
|
|
// s << boost::format(_("%1$s %1$d:")
|
|
|
|
|
// % fl.name()
|
|
|
|
|
// % buf->counters().value(fl.name());
|
|
|
|
|
#else
|
2002-08-06 22:40:59 +00:00
|
|
|
|
ostringstream o;
|
2002-11-27 10:30:28 +00:00
|
|
|
|
//o << fl.name() << ' ' << buf->counters().value(fl.name()) << ":";
|
2002-08-12 20:24:10 +00:00
|
|
|
|
o << fl.name() << " #:";
|
2002-11-04 02:12:42 +00:00
|
|
|
|
s = STRCONV(o.str());
|
2002-12-01 21:10:37 +00:00
|
|
|
|
#endif
|
2000-07-18 17:45:27 +00:00
|
|
|
|
} else {
|
2002-08-21 14:23:28 +00:00
|
|
|
|
// par->SetLayout(0);
|
2002-08-21 17:35:24 +00:00
|
|
|
|
// s = layout->labelstring;
|
2002-12-01 21:10:37 +00:00
|
|
|
|
s = _("Senseless: ");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-04-10 21:07:55 +00:00
|
|
|
|
pit->params().labelString(s);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-09-06 14:48:01 +00:00
|
|
|
|
// reset the enumeration counter. They are always reset
|
2002-08-21 17:35:24 +00:00
|
|
|
|
// when there is any other layout between
|
2002-09-06 14:48:01 +00:00
|
|
|
|
// Just fall-through between the cases so that all
|
|
|
|
|
// enum counters deeper than enumdepth is also reset.
|
2003-04-10 21:07:55 +00:00
|
|
|
|
switch (pit->enumdepth) {
|
2002-09-05 12:58:10 +00:00
|
|
|
|
case 0:
|
2002-09-06 14:48:01 +00:00
|
|
|
|
textclass.counters().reset("enumi");
|
2002-09-05 12:58:10 +00:00
|
|
|
|
case 1:
|
2002-09-06 14:48:01 +00:00
|
|
|
|
textclass.counters().reset("enumii");
|
2002-09-05 12:58:10 +00:00
|
|
|
|
case 2:
|
2002-09-06 14:48:01 +00:00
|
|
|
|
textclass.counters().reset("enumiii");
|
2002-09-05 12:58:10 +00:00
|
|
|
|
case 3:
|
2002-09-06 14:48:01 +00:00
|
|
|
|
textclass.counters().reset("enumiv");
|
2002-08-06 22:40:59 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-11-05 18:25:53 +00:00
|
|
|
|
// Updates all counters. Paragraphs with changed label string will be rebroken
|
2003-03-18 13:05:08 +00:00
|
|
|
|
void LyXText::updateCounters()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-03-29 23:11:20 +00:00
|
|
|
|
RowList::iterator rowit = rows().begin();
|
2003-04-02 23:01:39 +00:00
|
|
|
|
ParagraphList::iterator pit = rowit->par();
|
2001-05-03 14:31:33 +00:00
|
|
|
|
|
2002-09-06 14:48:01 +00:00
|
|
|
|
// CHECK if this is really needed. (Lgb)
|
2003-03-17 16:25:00 +00:00
|
|
|
|
bv()->buffer()->params.getLyXTextClass().counters().reset();
|
2002-09-06 14:48:01 +00:00
|
|
|
|
|
2003-04-13 22:24:28 +00:00
|
|
|
|
for (; pit != ownerParagraphs().end(); ++pit) {
|
2003-04-02 23:01:39 +00:00
|
|
|
|
while (rowit->par() != pit)
|
2003-03-29 23:11:20 +00:00
|
|
|
|
++rowit;
|
2002-08-20 21:50:08 +00:00
|
|
|
|
|
2003-04-02 23:01:39 +00:00
|
|
|
|
string const oldLabel = pit->params().labelString();
|
2002-11-05 18:25:53 +00:00
|
|
|
|
|
2003-04-07 20:32:29 +00:00
|
|
|
|
int maxdepth = 0;
|
|
|
|
|
if (pit != ownerParagraphs().begin())
|
|
|
|
|
maxdepth = boost::prior(pit)->getMaxDepthAfter();
|
|
|
|
|
|
|
|
|
|
if (pit->params().depth() > maxdepth)
|
|
|
|
|
pit->params().depth(maxdepth);
|
|
|
|
|
|
2002-12-01 21:10:37 +00:00
|
|
|
|
// setCounter can potentially change the labelString.
|
2003-04-13 12:56:48 +00:00
|
|
|
|
setCounter(bv()->buffer(), pit);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-02 23:01:39 +00:00
|
|
|
|
string const & newLabel = pit->params().labelString();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-11-05 18:25:53 +00:00
|
|
|
|
if (oldLabel.empty() && !newLabel.empty()) {
|
2003-03-31 16:57:45 +00:00
|
|
|
|
removeParagraph(rowit);
|
2003-03-29 23:11:20 +00:00
|
|
|
|
appendParagraph(rowit);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::insertInset(Inset * inset)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-07-19 08:52:59 +00:00
|
|
|
|
if (!cursor.par()->insetAllowed(inset->lyxCode()))
|
2000-04-10 14:29:05 +00:00
|
|
|
|
return;
|
2003-04-09 09:15:20 +00:00
|
|
|
|
setUndo(bv(), Undo::FINISH, &*cursor.par(),
|
|
|
|
|
&*boost::next(cursor.par()));
|
2002-04-12 08:31:06 +00:00
|
|
|
|
freezeUndo();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
cursor.par()->insertInset(cursor.pos(), inset);
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// Just to rebreak and refresh correctly.
|
|
|
|
|
// The character will not be inserted a second time
|
2003-03-17 16:25:00 +00:00
|
|
|
|
insertChar(Paragraph::META_INSET);
|
2001-01-08 16:14:09 +00:00
|
|
|
|
// If we enter a highly editable inset the cursor should be to before
|
|
|
|
|
// the inset. This couldn't happen before as Undo was not handled inside
|
2000-09-28 14:05:24 +00:00
|
|
|
|
// inset now after the Undo LyX tries to call inset->Edit(...) again
|
|
|
|
|
// and cannot do this as the cursor is behind the inset and GetInset
|
|
|
|
|
// does not return the inset!
|
2001-11-09 13:44:48 +00:00
|
|
|
|
if (isHighlyEditableInset(inset)) {
|
2003-03-17 16:25:00 +00:00
|
|
|
|
cursorLeft(true);
|
2000-09-28 14:05:24 +00:00
|
|
|
|
}
|
2002-04-12 08:31:06 +00:00
|
|
|
|
unFreezeUndo();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXText::copyEnvironmentType()
|
|
|
|
|
{
|
2002-06-24 20:28:12 +00:00
|
|
|
|
copylayouttype = cursor.par()->layout()->name();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::pasteEnvironmentType()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-12-18 14:36:28 +00:00
|
|
|
|
// do nothing if there has been no previous copyEnvironmentType()
|
|
|
|
|
if (!copylayouttype.empty())
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setLayout(copylayouttype);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-15 15:44:39 +00:00
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::cutSelection(bool doclear, bool realcut)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-06-15 15:44:39 +00:00
|
|
|
|
// Stuff what we got on the clipboard. Even if there is no selection.
|
|
|
|
|
|
|
|
|
|
// There is a problem with having the stuffing here in that the
|
|
|
|
|
// larger the selection the slower LyX will get. This can be
|
|
|
|
|
// solved by running the line below only when the selection has
|
|
|
|
|
// finished. The solution used currently just works, to make it
|
|
|
|
|
// faster we need to be more clever and probably also have more
|
|
|
|
|
// calls to stuffClipboard. (Lgb)
|
2003-03-17 16:25:00 +00:00
|
|
|
|
bv()->stuffClipboard(selectionAsString(bv()->buffer(), true));
|
2000-06-15 15:44:39 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// This doesn't make sense, if there is no selection
|
2001-05-31 02:23:46 +00:00
|
|
|
|
if (!selection.set())
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
// OK, we have a selection. This is always between selection.start
|
|
|
|
|
// and selection.end
|
2000-09-23 04:57:18 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// make sure that the depth behind the selection are restored, too
|
2003-04-13 02:23:30 +00:00
|
|
|
|
ParagraphList::iterator endpit = boost::next(selection.end.par());
|
|
|
|
|
ParagraphList::iterator undoendpit = endpit;
|
2003-04-13 22:24:28 +00:00
|
|
|
|
ParagraphList::iterator pars_end = ownerParagraphs().end();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-13 22:24:28 +00:00
|
|
|
|
if (endpit != pars_end && endpit->getDepth()) {
|
|
|
|
|
while (endpit != pars_end && endpit->getDepth()) {
|
2003-04-13 02:23:30 +00:00
|
|
|
|
++endpit;
|
|
|
|
|
undoendpit = endpit;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2003-04-13 22:24:28 +00:00
|
|
|
|
} else if (endpit != pars_end) {
|
2003-04-13 02:23:30 +00:00
|
|
|
|
// because of parindents etc.
|
|
|
|
|
++endpit;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-13 02:23:30 +00:00
|
|
|
|
setUndo(bv(), Undo::DELETE, &*selection.start.par(), &*undoendpit);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// there are two cases: cut only within one paragraph or
|
|
|
|
|
// more than one paragraph
|
2001-05-31 02:23:46 +00:00
|
|
|
|
if (selection.start.par() == selection.end.par()) {
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// only within one paragraph
|
2003-04-13 02:23:30 +00:00
|
|
|
|
endpit = selection.end.par();
|
2001-05-31 02:23:46 +00:00
|
|
|
|
int pos = selection.end.pos();
|
2003-04-13 02:23:30 +00:00
|
|
|
|
CutAndPaste::cutSelection(&*selection.start.par(), &*endpit,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
selection.start.pos(), pos,
|
2003-03-17 16:25:00 +00:00
|
|
|
|
bv()->buffer()->params.textclass,
|
2001-10-16 14:47:10 +00:00
|
|
|
|
doclear, realcut);
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.end.pos(pos);
|
2000-01-17 21:01:30 +00:00
|
|
|
|
} else {
|
2003-04-13 02:23:30 +00:00
|
|
|
|
endpit = selection.end.par();
|
2001-05-31 02:23:46 +00:00
|
|
|
|
int pos = selection.end.pos();
|
2003-04-13 02:23:30 +00:00
|
|
|
|
CutAndPaste::cutSelection(&*selection.start.par(), &*endpit,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
selection.start.pos(), pos,
|
2003-03-17 16:25:00 +00:00
|
|
|
|
bv()->buffer()->params.textclass,
|
2001-10-16 14:47:10 +00:00
|
|
|
|
doclear, realcut);
|
2003-04-13 02:23:30 +00:00
|
|
|
|
cursor.par(endpit);
|
|
|
|
|
selection.end.par(endpit);
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.end.pos(pos);
|
|
|
|
|
cursor.pos(selection.end.pos());
|
2000-01-17 21:01:30 +00:00
|
|
|
|
}
|
2003-04-13 02:23:30 +00:00
|
|
|
|
++endpit;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// sometimes necessary
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (doclear)
|
2002-06-24 20:28:12 +00:00
|
|
|
|
selection.start.par()->stripLeadingSpaces();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-04-13 02:23:30 +00:00
|
|
|
|
redoParagraphs(selection.start, endpit);
|
2001-05-30 13:17:50 +00:00
|
|
|
|
|
|
|
|
|
// cutSelection can invalidate the cursor so we need to set
|
|
|
|
|
// it anew. (Lgb)
|
2003-02-08 19:18:01 +00:00
|
|
|
|
// we prefer the end for when tracking changes
|
|
|
|
|
cursor = selection.end;
|
2001-05-30 13:17:50 +00:00
|
|
|
|
|
|
|
|
|
// need a valid cursor. (Lgb)
|
2001-08-01 15:42:53 +00:00
|
|
|
|
clearSelection();
|
2001-05-30 13:17:50 +00:00
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(cursor.par(), cursor.pos());
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.cursor = cursor;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
updateCounters();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-06-16 15:13:25 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::copySelection()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-01-13 17:28:42 +00:00
|
|
|
|
// stuff the selection onto the X clipboard, from an explicit copy request
|
2003-03-17 16:25:00 +00:00
|
|
|
|
bv()->stuffClipboard(selectionAsString(bv()->buffer(), true));
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
|
|
|
|
// this doesnt make sense, if there is no selection
|
2001-05-31 02:23:46 +00:00
|
|
|
|
if (!selection.set())
|
2000-04-10 14:29:05 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
// ok we have a selection. This is always between selection.start
|
2000-04-10 14:29:05 +00:00
|
|
|
|
// and sel_end cursor
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
2000-04-10 14:29:05 +00:00
|
|
|
|
// copy behind a space if there is one
|
2001-05-31 02:23:46 +00:00
|
|
|
|
while (selection.start.par()->size() > selection.start.pos()
|
2001-06-25 00:06:33 +00:00
|
|
|
|
&& selection.start.par()->isLineSeparator(selection.start.pos())
|
2001-05-31 02:23:46 +00:00
|
|
|
|
&& (selection.start.par() != selection.end.par()
|
|
|
|
|
|| selection.start.pos() < selection.end.pos()))
|
2002-03-21 17:27:08 +00:00
|
|
|
|
selection.start.pos(selection.start.pos() + 1);
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
2003-04-09 09:15:20 +00:00
|
|
|
|
CutAndPaste::copySelection(&*selection.start.par(),
|
|
|
|
|
&*selection.end.par(),
|
2002-03-21 17:27:08 +00:00
|
|
|
|
selection.start.pos(), selection.end.pos(),
|
2003-03-17 16:25:00 +00:00
|
|
|
|
bv()->buffer()->params.textclass);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::pasteSelection()
|
2000-04-10 14:29:05 +00:00
|
|
|
|
{
|
2000-06-12 11:27:15 +00:00
|
|
|
|
// this does not make sense, if there is nothing to paste
|
2003-03-06 21:01:04 +00:00
|
|
|
|
if (!CutAndPaste::checkPastePossible())
|
2000-06-12 11:27:15 +00:00
|
|
|
|
return;
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setUndo(bv(), Undo::INSERT,
|
2003-04-09 09:15:20 +00:00
|
|
|
|
&*cursor.par(), &*boost::next(cursor.par()));
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * endpar;
|
2003-04-09 09:15:20 +00:00
|
|
|
|
ParagraphList::iterator actpit = cursor.par();
|
2000-06-12 11:27:15 +00:00
|
|
|
|
int pos = cursor.pos();
|
2001-09-20 10:16:24 +00:00
|
|
|
|
|
2003-04-09 09:15:20 +00:00
|
|
|
|
Paragraph * actpar = &*actpit;
|
2001-07-03 15:39:17 +00:00
|
|
|
|
CutAndPaste::pasteSelection(&actpar, &endpar, pos,
|
2003-03-17 16:25:00 +00:00
|
|
|
|
bv()->buffer()->params.textclass);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
redoParagraphs(cursor, endpar);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(cursor.par(), cursor.pos());
|
2001-08-01 15:42:53 +00:00
|
|
|
|
clearSelection();
|
2002-03-18 13:47:37 +00:00
|
|
|
|
|
|
|
|
|
selection.cursor = cursor;
|
2003-04-09 09:15:20 +00:00
|
|
|
|
setCursor(actpit, pos);
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setSelection();
|
|
|
|
|
updateCounters();
|
2000-04-10 14:29:05 +00:00
|
|
|
|
}
|
2000-06-15 15:44:39 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::setSelectionRange(lyx::pos_type length)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-02-08 19:18:01 +00:00
|
|
|
|
if (!length)
|
2001-06-13 16:32:36 +00:00
|
|
|
|
return;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.cursor = cursor;
|
2003-02-08 19:18:01 +00:00
|
|
|
|
while (length--)
|
2003-03-17 16:25:00 +00:00
|
|
|
|
cursorRight(bv());
|
|
|
|
|
setSelection();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// simple replacing. The font of the first selected character is used
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::replaceSelectionWithString(string const & str)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursorParUndo(bv());
|
2001-06-25 00:06:33 +00:00
|
|
|
|
freezeUndo();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
if (!selection.set()) { // create a dummy selection
|
|
|
|
|
selection.end = cursor;
|
|
|
|
|
selection.start = cursor;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get font setting before we cut
|
2001-11-26 16:42:04 +00:00
|
|
|
|
pos_type pos = selection.end.pos();
|
2001-05-31 02:23:46 +00:00
|
|
|
|
LyXFont const font = selection.start.par()
|
2003-03-17 16:25:00 +00:00
|
|
|
|
->getFontSettings(bv()->buffer()->params,
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.start.pos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Insert the new string
|
2000-09-14 17:53:12 +00:00
|
|
|
|
for (string::const_iterator cit = str.begin(); cit != str.end(); ++cit) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
selection.end.par()->insertChar(pos, (*cit), font);
|
1999-11-04 01:40:20 +00:00
|
|
|
|
++pos;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Cut the selection
|
2003-03-17 16:25:00 +00:00
|
|
|
|
cutSelection(true, false);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
unFreezeUndo();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// needed to insert the selection
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::insertStringAsLines(string const & str)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-04-09 09:15:20 +00:00
|
|
|
|
ParagraphList::iterator pit = cursor.par();
|
2001-11-26 16:42:04 +00:00
|
|
|
|
pos_type pos = cursor.pos();
|
2003-04-09 09:15:20 +00:00
|
|
|
|
ParagraphList::iterator endpit = boost::next(cursor.par());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursorParUndo(bv());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// only to be sure, should not be neccessary
|
2001-08-01 15:42:53 +00:00
|
|
|
|
clearSelection();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-09 09:15:20 +00:00
|
|
|
|
Paragraph * par = &*pit;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
bv()->buffer()->insertStringAsLines(par, pos, current_font, str);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2003-04-13 12:56:48 +00:00
|
|
|
|
redoParagraphs(cursor, endpit);
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(cursor.par(), cursor.pos());
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.cursor = cursor;
|
2003-04-09 09:15:20 +00:00
|
|
|
|
setCursor(pit, pos);
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setSelection();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// turns double-CR to single CR, others where converted into one
|
|
|
|
|
// blank. Then InsertStringAsLines is called
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::insertStringAsParagraphs(string const & str)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
|
|
|
|
string linestr(str);
|
|
|
|
|
bool newline_inserted = false;
|
|
|
|
|
for (string::size_type i = 0; i < linestr.length(); ++i) {
|
|
|
|
|
if (linestr[i] == '\n') {
|
|
|
|
|
if (newline_inserted) {
|
|
|
|
|
// we know that \r will be ignored by
|
|
|
|
|
// InsertStringA. Of course, it is a dirty
|
|
|
|
|
// trick, but it works...
|
|
|
|
|
linestr[i - 1] = '\r';
|
|
|
|
|
linestr[i] = '\n';
|
|
|
|
|
} else {
|
|
|
|
|
linestr[i] = ' ';
|
|
|
|
|
newline_inserted = true;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
} else if (IsPrintable(linestr[i])) {
|
|
|
|
|
newline_inserted = false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-03-17 16:25:00 +00:00
|
|
|
|
insertStringAsLines(linestr);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-04-10 21:07:55 +00:00
|
|
|
|
void LyXText::checkParagraph(ParagraphList::iterator pit, pos_type pos)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-03-21 17:27:08 +00:00
|
|
|
|
LyXCursor tmpcursor;
|
2000-04-26 13:57:28 +00:00
|
|
|
|
|
2000-09-29 18:44:07 +00:00
|
|
|
|
int y = 0;
|
2001-11-26 16:42:04 +00:00
|
|
|
|
pos_type z;
|
2003-04-10 21:07:55 +00:00
|
|
|
|
RowList::iterator row = getRow(pit, pos, y);
|
2003-03-30 07:27:36 +00:00
|
|
|
|
RowList::iterator beg = rows().begin();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-09-23 04:57:18 +00:00
|
|
|
|
// is there a break one row above
|
2003-03-30 07:27:36 +00:00
|
|
|
|
if (row != beg
|
|
|
|
|
&& boost::prior(row)->par() == row->par()) {
|
|
|
|
|
z = rowBreakPoint(*boost::prior(row));
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (z >= row->pos()) {
|
2000-09-23 04:57:18 +00:00
|
|
|
|
// set the dimensions of the row above
|
2003-03-30 07:27:36 +00:00
|
|
|
|
y -= boost::prior(row)->height();
|
2003-03-17 16:25:00 +00:00
|
|
|
|
postPaint(y);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-03-31 16:57:45 +00:00
|
|
|
|
breakAgain(boost::prior(row));
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-09-23 04:57:18 +00:00
|
|
|
|
// set the cursor again. Otherwise
|
|
|
|
|
// dangling pointers are possible
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(cursor.par(), cursor.pos(),
|
2000-12-17 06:09:35 +00:00
|
|
|
|
false, cursor.boundary());
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.cursor = cursor;
|
2000-09-23 04:57:18 +00:00
|
|
|
|
return;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-09-23 04:57:18 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-09-23 04:57:18 +00:00
|
|
|
|
int const tmpheight = row->height();
|
2003-04-01 16:55:48 +00:00
|
|
|
|
pos_type const tmplast = lastPos(*this, row);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-01 16:55:48 +00:00
|
|
|
|
breakAgain(row);
|
|
|
|
|
if (row->height() == tmpheight && lastPos(*this, row) == tmplast) {
|
|
|
|
|
postRowPaint(row, y);
|
2003-03-17 01:34:36 +00:00
|
|
|
|
} else {
|
2003-03-17 16:25:00 +00:00
|
|
|
|
postPaint(y);
|
2003-03-17 01:34:36 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-09-23 04:57:18 +00:00
|
|
|
|
// check the special right address boxes
|
2003-04-10 21:07:55 +00:00
|
|
|
|
if (pit->layout()->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
|
|
|
|
|
tmpcursor.par(pit);
|
2003-04-01 16:55:48 +00:00
|
|
|
|
tmpcursor.row(row);
|
2000-09-23 04:57:18 +00:00
|
|
|
|
tmpcursor.y(y);
|
|
|
|
|
tmpcursor.x(0);
|
|
|
|
|
tmpcursor.x_fix(0);
|
|
|
|
|
tmpcursor.pos(pos);
|
2003-03-17 16:25:00 +00:00
|
|
|
|
redoDrawingOfParagraph(tmpcursor);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// set the cursor again. Otherwise dangling pointers are possible
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// also set the selection
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
if (selection.set()) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
tmpcursor = cursor;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursorIntern(selection.cursor.par(), selection.cursor.pos(),
|
2001-05-31 02:23:46 +00:00
|
|
|
|
false, selection.cursor.boundary());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
selection.cursor = cursor;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursorIntern(selection.start.par(),
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.start.pos(),
|
|
|
|
|
false, selection.start.boundary());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
selection.start = cursor;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursorIntern(selection.end.par(),
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.end.pos(),
|
|
|
|
|
false, selection.end.boundary());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
selection.end = cursor;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursorIntern(last_sel_cursor.par(),
|
2000-12-17 06:09:35 +00:00
|
|
|
|
last_sel_cursor.pos(),
|
|
|
|
|
false, last_sel_cursor.boundary());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
last_sel_cursor = cursor;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
cursor = tmpcursor;
|
|
|
|
|
}
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursorIntern(cursor.par(), cursor.pos(),
|
2000-12-17 06:09:35 +00:00
|
|
|
|
false, cursor.boundary());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-21 15:07:57 +00:00
|
|
|
|
// returns false if inset wasn't found
|
2003-03-17 16:25:00 +00:00
|
|
|
|
bool LyXText::updateInset(Inset * inset)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// first check the current paragraph
|
2001-06-25 00:06:33 +00:00
|
|
|
|
int pos = cursor.par()->getPositionOfInset(inset);
|
2001-10-18 16:17:46 +00:00
|
|
|
|
if (pos != -1) {
|
2003-04-13 12:56:48 +00:00
|
|
|
|
checkParagraph(cursor.par(), pos);
|
2000-06-21 15:07:57 +00:00
|
|
|
|
return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// check every paragraph
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-02 17:11:38 +00:00
|
|
|
|
ParagraphList::iterator par = ownerParagraphs().begin();
|
|
|
|
|
ParagraphList::iterator end = ownerParagraphs().end();
|
2003-04-13 22:24:28 +00:00
|
|
|
|
for (; par != end; ++par) {
|
2001-07-07 18:19:18 +00:00
|
|
|
|
pos = par->getPositionOfInset(inset);
|
2001-10-18 16:17:46 +00:00
|
|
|
|
if (pos != -1) {
|
2003-04-13 12:56:48 +00:00
|
|
|
|
checkParagraph(par, pos);
|
2001-07-07 18:19:18 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2003-04-13 22:24:28 +00:00
|
|
|
|
};
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-06-21 15:07:57 +00:00
|
|
|
|
return false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-04-09 09:15:20 +00:00
|
|
|
|
bool LyXText::setCursor(ParagraphList::iterator pit,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
pos_type pos,
|
2003-03-18 13:05:08 +00:00
|
|
|
|
bool setfont, bool boundary)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
LyXCursor old_cursor = cursor;
|
2003-04-09 09:15:20 +00:00
|
|
|
|
setCursorIntern(pit, pos, setfont, boundary);
|
2003-03-17 16:25:00 +00:00
|
|
|
|
return deleteEmptyParagraphMechanism(old_cursor);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
2003-04-09 09:15:20 +00:00
|
|
|
|
void LyXText::setCursor(LyXCursor & cur, ParagraphList::iterator pit,
|
2003-03-18 13:05:08 +00:00
|
|
|
|
pos_type pos, bool boundary)
|
2000-04-19 14:42:19 +00:00
|
|
|
|
{
|
2003-04-09 09:15:20 +00:00
|
|
|
|
lyx::Assert(pit != ownerParagraphs().end());
|
2002-03-14 13:40:19 +00:00
|
|
|
|
|
2003-04-09 09:15:20 +00:00
|
|
|
|
cur.par(pit);
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cur.pos(pos);
|
|
|
|
|
cur.boundary(boundary);
|
2000-04-19 14:42:19 +00:00
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// get the cursor y position in text
|
2000-09-29 18:44:07 +00:00
|
|
|
|
int y = 0;
|
2003-04-10 21:07:55 +00:00
|
|
|
|
RowList::iterator row = getRow(pit, pos, y);
|
2003-03-30 07:27:36 +00:00
|
|
|
|
RowList::iterator beg = rows().begin();
|
|
|
|
|
|
|
|
|
|
RowList::iterator old_row = row;
|
2003-04-01 10:10:28 +00:00
|
|
|
|
cur.irow(row);
|
2002-04-11 09:53:23 +00:00
|
|
|
|
// if we are before the first char of this row and are still in the
|
|
|
|
|
// same paragraph and there is a previous row then put the cursor on
|
|
|
|
|
// the end of the previous row
|
|
|
|
|
cur.iy(y + row->baseline());
|
|
|
|
|
Inset * ins;
|
2003-03-30 07:27:36 +00:00
|
|
|
|
if (row != beg && pos &&
|
|
|
|
|
boost::prior(row)->par() == row->par() &&
|
2003-04-09 09:15:20 +00:00
|
|
|
|
pos < pit->size() &&
|
|
|
|
|
pit->getChar(pos) == Paragraph::META_INSET &&
|
|
|
|
|
(ins = pit->getInset(pos)) && (ins->needFullRow() || ins->display()))
|
2002-04-11 09:53:23 +00:00
|
|
|
|
{
|
2003-03-30 07:27:36 +00:00
|
|
|
|
--row;
|
2002-04-11 09:53:23 +00:00
|
|
|
|
y -= row->height();
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-01 16:55:48 +00:00
|
|
|
|
cur.row(row);
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// y is now the beginning of the cursor row
|
2000-06-08 23:16:16 +00:00
|
|
|
|
y += row->baseline();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
// y is now the cursor baseline
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cur.y(y);
|
2001-11-09 13:44:48 +00:00
|
|
|
|
|
2003-04-01 16:55:48 +00:00
|
|
|
|
pos_type last = lastPrintablePos(*this, old_row);
|
2000-04-19 14:42:19 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
// None of these should happen, but we're scaredy-cats
|
2003-04-09 09:15:20 +00:00
|
|
|
|
if (pos > pit->size()) {
|
2003-03-13 10:30:28 +00:00
|
|
|
|
lyxerr << "dont like 1 please report" << endl;
|
2003-02-08 19:18:01 +00:00
|
|
|
|
pos = 0;
|
|
|
|
|
cur.pos(0);
|
|
|
|
|
} else if (pos > last + 1) {
|
2003-03-13 10:30:28 +00:00
|
|
|
|
lyxerr << "dont like 2 please report" << endl;
|
2001-12-28 21:17:18 +00:00
|
|
|
|
// This shouldn't happen.
|
2000-06-08 23:16:16 +00:00
|
|
|
|
pos = last + 1;
|
2001-12-28 21:17:18 +00:00
|
|
|
|
cur.pos(pos);
|
|
|
|
|
} else if (pos < row->pos()) {
|
2003-03-13 10:30:28 +00:00
|
|
|
|
lyxerr << "dont like 3 please report" << endl;
|
2000-06-08 23:16:16 +00:00
|
|
|
|
pos = row->pos();
|
2001-12-28 21:17:18 +00:00
|
|
|
|
cur.pos(pos);
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-04-12 15:59:03 +00:00
|
|
|
|
// now get the cursors x position
|
2003-04-01 16:55:48 +00:00
|
|
|
|
float x = getCursorX(row, pos, last, boundary);
|
2002-04-12 15:59:03 +00:00
|
|
|
|
cur.x(int(x));
|
|
|
|
|
cur.x_fix(cur.x());
|
|
|
|
|
if (old_row != row) {
|
2003-04-01 16:55:48 +00:00
|
|
|
|
x = getCursorX(old_row, pos, last, boundary);
|
2002-04-12 15:59:03 +00:00
|
|
|
|
cur.ix(int(x));
|
|
|
|
|
} else
|
|
|
|
|
cur.ix(cur.x());
|
2003-04-09 09:15:20 +00:00
|
|
|
|
/* We take out this for the time being because 1) the redraw code is not
|
2003-04-02 22:45:56 +00:00
|
|
|
|
prepared to this yet and 2) because some good policy has yet to be decided
|
|
|
|
|
while editting: for instance how to act on rows being created/deleted
|
|
|
|
|
because of DEPM.
|
2003-04-09 09:15:20 +00:00
|
|
|
|
*/
|
2003-04-02 22:45:56 +00:00
|
|
|
|
#if 0
|
2003-03-18 16:47:18 +00:00
|
|
|
|
//if the cursor is in a visible row, anchor to it
|
|
|
|
|
int topy = top_y();
|
2003-03-26 16:15:02 +00:00
|
|
|
|
if (topy < y && y < topy + bv()->workHeight())
|
2003-04-01 16:55:48 +00:00
|
|
|
|
anchor_row(row);
|
2003-04-02 22:45:56 +00:00
|
|
|
|
#endif
|
2002-04-12 15:59:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-31 11:16:39 +00:00
|
|
|
|
float LyXText::getCursorX(RowList::iterator rit,
|
2003-03-17 16:25:00 +00:00
|
|
|
|
pos_type pos, pos_type last, bool boundary) const
|
2002-04-12 15:59:03 +00:00
|
|
|
|
{
|
|
|
|
|
pos_type cursor_vpos = 0;
|
|
|
|
|
float x;
|
|
|
|
|
float fill_separator;
|
|
|
|
|
float fill_hfill;
|
|
|
|
|
float fill_label_hfill;
|
|
|
|
|
// This call HAS to be here because of the BidiTables!!!
|
2003-03-31 11:16:39 +00:00
|
|
|
|
prepareToPrint(rit, x, fill_separator, fill_hfill,
|
2002-04-22 16:31:14 +00:00
|
|
|
|
fill_label_hfill);
|
2002-04-12 15:59:03 +00:00
|
|
|
|
|
2003-04-13 22:24:28 +00:00
|
|
|
|
ParagraphList::iterator rit_par = rit->par();
|
|
|
|
|
pos_type const rit_pos = rit->pos();
|
|
|
|
|
|
|
|
|
|
if (last < rit_pos)
|
|
|
|
|
cursor_vpos = rit_pos;
|
2000-05-30 19:31:11 +00:00
|
|
|
|
else if (pos > last && !boundary)
|
2003-04-13 22:24:28 +00:00
|
|
|
|
cursor_vpos = (rit_par->isRightToLeftPar(bv()->buffer()->params))
|
|
|
|
|
? rit_pos : last + 1;
|
|
|
|
|
else if (pos > rit_pos && (pos > last || boundary))
|
2000-06-08 23:16:16 +00:00
|
|
|
|
/// Place cursor after char at (logical) position pos - 1
|
|
|
|
|
cursor_vpos = (bidi_level(pos - 1) % 2 == 0)
|
|
|
|
|
? log2vis(pos - 1) + 1 : log2vis(pos - 1);
|
2000-04-19 14:42:19 +00:00
|
|
|
|
else
|
|
|
|
|
/// Place cursor before char at (logical) position pos
|
2000-05-30 19:31:11 +00:00
|
|
|
|
cursor_vpos = (bidi_level(pos) % 2 == 0)
|
2000-04-19 14:42:19 +00:00
|
|
|
|
? log2vis(pos) : log2vis(pos) + 1;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-13 22:24:28 +00:00
|
|
|
|
pos_type body_pos = rit_par->beginningOfBody();
|
2003-03-09 12:37:22 +00:00
|
|
|
|
if ((body_pos > 0) &&
|
2003-04-13 22:24:28 +00:00
|
|
|
|
((body_pos - 1 > last) || !rit_par->isLineSeparator(body_pos - 1)))
|
2003-03-09 12:37:22 +00:00
|
|
|
|
body_pos = 0;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-13 22:24:28 +00:00
|
|
|
|
for (pos_type vpos = rit_pos; vpos < cursor_vpos; ++vpos) {
|
2002-04-12 15:59:03 +00:00
|
|
|
|
pos_type pos = vis2log(vpos);
|
2003-03-09 12:37:22 +00:00
|
|
|
|
if (body_pos > 0 && pos == body_pos - 1) {
|
2000-09-23 04:57:18 +00:00
|
|
|
|
x += fill_label_hfill +
|
2002-06-24 20:28:12 +00:00
|
|
|
|
font_metrics::width(
|
2003-04-13 22:24:28 +00:00
|
|
|
|
rit_par->layout()->labelsep,
|
|
|
|
|
getLabelFont(bv()->buffer(), rit_par));
|
|
|
|
|
if (rit_par->isLineSeparator(body_pos - 1))
|
|
|
|
|
x -= singleWidth(rit_par, body_pos - 1);
|
2000-09-23 04:57:18 +00:00
|
|
|
|
}
|
2003-04-01 16:55:48 +00:00
|
|
|
|
|
|
|
|
|
if (hfillExpansion(*this, rit, pos)) {
|
2003-04-13 22:24:28 +00:00
|
|
|
|
x += singleWidth(rit_par, pos);
|
2003-03-09 12:37:22 +00:00
|
|
|
|
if (pos >= body_pos)
|
2000-09-23 04:57:18 +00:00
|
|
|
|
x += fill_hfill;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
else
|
2000-09-23 04:57:18 +00:00
|
|
|
|
x += fill_label_hfill;
|
2003-04-13 22:24:28 +00:00
|
|
|
|
} else if (rit_par->isSeparator(pos)) {
|
|
|
|
|
x += singleWidth(rit_par, pos);
|
2003-03-09 12:37:22 +00:00
|
|
|
|
if (pos >= body_pos)
|
2000-09-23 04:57:18 +00:00
|
|
|
|
x += fill_separator;
|
|
|
|
|
} else
|
2003-04-13 22:24:28 +00:00
|
|
|
|
x += singleWidth(rit_par, pos);
|
2000-04-19 14:42:19 +00:00
|
|
|
|
}
|
2002-04-12 15:59:03 +00:00
|
|
|
|
return x;
|
2000-04-19 14:42:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-04-09 09:15:20 +00:00
|
|
|
|
void LyXText::setCursorIntern(ParagraphList::iterator pit,
|
2003-03-18 13:05:08 +00:00
|
|
|
|
pos_type pos, bool setfont, bool boundary)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-04-09 09:15:20 +00:00
|
|
|
|
InsetText * it = static_cast<InsetText *>(pit->inInset());
|
2001-08-05 22:12:27 +00:00
|
|
|
|
if (it) {
|
|
|
|
|
if (it != inset_owner) {
|
2002-03-19 21:42:50 +00:00
|
|
|
|
lyxerr[Debug::INSETS] << "InsetText is " << it
|
|
|
|
|
<< endl
|
|
|
|
|
<< "inset_owner is "
|
|
|
|
|
<< inset_owner << endl;
|
2002-02-26 10:50:48 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2001-09-27 09:52:06 +00:00
|
|
|
|
#warning I believe this code is wrong. (Lgb)
|
2001-08-05 22:12:27 +00:00
|
|
|
|
#warning J<>rgen, have a look at this. (Lgb)
|
2001-08-08 14:36:56 +00:00
|
|
|
|
#warning Hmmm, I guess you are right but we
|
|
|
|
|
#warning should verify when this is needed
|
2002-02-26 10:50:48 +00:00
|
|
|
|
#endif
|
2001-08-05 22:12:27 +00:00
|
|
|
|
// J<>rgen, would you like to have a look?
|
|
|
|
|
// I guess we need to move the outer cursor
|
|
|
|
|
// and open and lock the inset (bla bla bla)
|
|
|
|
|
// stuff I don't know... so can you have a look?
|
|
|
|
|
// (Lgb)
|
2001-09-09 22:02:19 +00:00
|
|
|
|
// I moved the lyxerr stuff in here so we can see if
|
|
|
|
|
// this is actually really needed and where!
|
2001-08-08 14:36:56 +00:00
|
|
|
|
// (Jug)
|
2003-03-17 16:25:00 +00:00
|
|
|
|
// it->getLyXText(bv())->setCursorIntern(bv(), par, pos, setfont, boundary);
|
2001-08-05 22:12:27 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2001-07-06 15:57:54 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-09 09:15:20 +00:00
|
|
|
|
setCursor(cursor, pit, pos, boundary);
|
2001-08-05 22:12:27 +00:00
|
|
|
|
if (setfont)
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCurrentFont();
|
2000-05-30 19:31:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-09-23 04:57:18 +00:00
|
|
|
|
|
2003-03-18 13:05:08 +00:00
|
|
|
|
void LyXText::setCurrentFont()
|
2000-05-30 19:31:11 +00:00
|
|
|
|
{
|
2001-11-26 16:42:04 +00:00
|
|
|
|
pos_type pos = cursor.pos();
|
2003-04-13 22:24:28 +00:00
|
|
|
|
ParagraphList::iterator pit = cursor.par();
|
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (cursor.boundary() && pos > 0)
|
2000-05-30 19:31:11 +00:00
|
|
|
|
--pos;
|
|
|
|
|
|
|
|
|
|
if (pos > 0) {
|
2003-04-13 22:24:28 +00:00
|
|
|
|
if (pos == pit->size())
|
2000-05-30 19:31:11 +00:00
|
|
|
|
--pos;
|
2001-05-30 13:17:50 +00:00
|
|
|
|
else // potentional bug... BUG (Lgb)
|
2003-04-13 22:24:28 +00:00
|
|
|
|
if (pit->isSeparator(pos)) {
|
2001-07-07 18:19:18 +00:00
|
|
|
|
if (pos > cursor.row()->pos() &&
|
2002-03-21 17:27:08 +00:00
|
|
|
|
bidi_level(pos) % 2 ==
|
2001-07-07 18:19:18 +00:00
|
|
|
|
bidi_level(pos - 1) % 2)
|
|
|
|
|
--pos;
|
2003-04-13 22:24:28 +00:00
|
|
|
|
else if (pos + 1 < pit->size())
|
2001-07-07 18:19:18 +00:00
|
|
|
|
++pos;
|
|
|
|
|
}
|
2000-04-19 14:42:19 +00:00
|
|
|
|
}
|
2000-05-30 19:31:11 +00:00
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
current_font =
|
2003-04-13 22:24:28 +00:00
|
|
|
|
pit->getFontSettings(bv()->buffer()->params, pos);
|
|
|
|
|
real_current_font = getFont(bv()->buffer(), pit, pos);
|
2000-07-10 10:31:34 +00:00
|
|
|
|
|
2003-04-13 22:24:28 +00:00
|
|
|
|
if (cursor.pos() == pit->size() &&
|
|
|
|
|
isBoundary(bv()->buffer(), *pit, cursor.pos()) &&
|
2000-07-10 10:31:34 +00:00
|
|
|
|
!cursor.boundary()) {
|
|
|
|
|
Language const * lang =
|
2003-04-13 22:24:28 +00:00
|
|
|
|
pit->getParLanguage(bv()->buffer()->params);
|
2000-07-10 10:31:34 +00:00
|
|
|
|
current_font.setLanguage(lang);
|
2001-02-26 10:50:03 +00:00
|
|
|
|
current_font.setNumber(LyXFont::OFF);
|
2000-07-10 10:31:34 +00:00
|
|
|
|
real_current_font.setLanguage(lang);
|
2001-02-26 10:50:03 +00:00
|
|
|
|
real_current_font.setNumber(LyXFont::OFF);
|
2000-07-10 10:31:34 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-10 05:03:33 +00:00
|
|
|
|
// returns the column near the specified x-coordinate of the row
|
|
|
|
|
// x is set to the real beginning of this column
|
|
|
|
|
pos_type
|
2003-04-01 00:01:42 +00:00
|
|
|
|
LyXText::getColumnNearX(RowList::iterator rit, int & x, bool & boundary) const
|
2003-03-10 05:03:33 +00:00
|
|
|
|
{
|
|
|
|
|
float tmpx = 0.0;
|
|
|
|
|
float fill_separator;
|
|
|
|
|
float fill_hfill;
|
|
|
|
|
float fill_label_hfill;
|
|
|
|
|
|
2003-03-30 21:42:09 +00:00
|
|
|
|
prepareToPrint(rit, tmpx, fill_separator,
|
2003-03-10 05:03:33 +00:00
|
|
|
|
fill_hfill, fill_label_hfill);
|
|
|
|
|
|
2003-03-30 21:42:09 +00:00
|
|
|
|
pos_type vc = rit->pos();
|
2003-04-01 16:55:48 +00:00
|
|
|
|
pos_type last = lastPrintablePos(*this, rit);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
pos_type c = 0;
|
|
|
|
|
|
2003-04-13 22:24:28 +00:00
|
|
|
|
ParagraphList::iterator rit_par = rit->par();
|
2003-03-30 21:42:09 +00:00
|
|
|
|
LyXLayout_ptr const & layout = rit->par()->layout();
|
2003-03-10 05:03:33 +00:00
|
|
|
|
|
|
|
|
|
bool left_side = false;
|
|
|
|
|
|
2003-04-13 22:24:28 +00:00
|
|
|
|
pos_type body_pos = rit_par->beginningOfBody();
|
2003-03-10 05:03:33 +00:00
|
|
|
|
float last_tmpx = tmpx;
|
|
|
|
|
|
|
|
|
|
if (body_pos > 0 &&
|
|
|
|
|
(body_pos - 1 > last ||
|
2003-04-13 22:24:28 +00:00
|
|
|
|
!rit_par->isLineSeparator(body_pos - 1)))
|
2003-03-10 05:03:33 +00:00
|
|
|
|
body_pos = 0;
|
|
|
|
|
|
|
|
|
|
// check for empty row
|
2003-04-13 22:24:28 +00:00
|
|
|
|
if (!rit_par->size()) {
|
2003-03-10 05:03:33 +00:00
|
|
|
|
x = int(tmpx);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (vc <= last && tmpx <= x) {
|
|
|
|
|
c = vis2log(vc);
|
|
|
|
|
last_tmpx = tmpx;
|
2003-03-30 21:42:09 +00:00
|
|
|
|
if (body_pos > 0 && c == body_pos - 1) {
|
2003-03-10 05:03:33 +00:00
|
|
|
|
tmpx += fill_label_hfill +
|
|
|
|
|
font_metrics::width(layout->labelsep,
|
2003-04-13 22:24:28 +00:00
|
|
|
|
getLabelFont(bv()->buffer(), &*rit_par));
|
|
|
|
|
if (rit_par->isLineSeparator(body_pos - 1))
|
|
|
|
|
tmpx -= singleWidth(rit_par, body_pos - 1);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-04-01 16:55:48 +00:00
|
|
|
|
if (hfillExpansion(*this, rit, c)) {
|
2003-04-13 22:24:28 +00:00
|
|
|
|
tmpx += singleWidth(rit_par, c);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
if (c >= body_pos)
|
|
|
|
|
tmpx += fill_hfill;
|
|
|
|
|
else
|
|
|
|
|
tmpx += fill_label_hfill;
|
2003-04-13 22:24:28 +00:00
|
|
|
|
} else if (rit_par->isSeparator(c)) {
|
|
|
|
|
tmpx += singleWidth(rit_par, c);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
if (c >= body_pos)
|
|
|
|
|
tmpx+= fill_separator;
|
|
|
|
|
} else {
|
2003-04-13 22:24:28 +00:00
|
|
|
|
tmpx += singleWidth(rit_par, c);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
}
|
|
|
|
|
++vc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((tmpx + last_tmpx) / 2 > x) {
|
|
|
|
|
tmpx = last_tmpx;
|
|
|
|
|
left_side = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (vc > last + 1) // This shouldn't happen.
|
|
|
|
|
vc = last + 1;
|
|
|
|
|
|
|
|
|
|
boundary = false;
|
2003-03-31 16:57:45 +00:00
|
|
|
|
// This (rtl_support test) is not needed, but gives
|
|
|
|
|
// some speedup if rtl_support=false
|
|
|
|
|
bool const lastrow = lyxrc.rtl_support &&
|
|
|
|
|
(boost::next(rit) == rowlist_.end() ||
|
2003-04-13 22:24:28 +00:00
|
|
|
|
boost::next(rit)->par() != rit_par);
|
2003-03-31 16:57:45 +00:00
|
|
|
|
// If lastrow is false, we don't need to compute
|
|
|
|
|
// the value of rtl.
|
2003-03-10 05:03:33 +00:00
|
|
|
|
bool const rtl = (lastrow)
|
2003-04-13 22:24:28 +00:00
|
|
|
|
? rit_par->isRightToLeftPar(bv()->buffer()->params)
|
2003-03-31 16:57:45 +00:00
|
|
|
|
: false;
|
2003-03-10 05:03:33 +00:00
|
|
|
|
if (lastrow &&
|
2003-03-30 21:42:09 +00:00
|
|
|
|
((rtl && left_side && vc == rit->pos() && x < tmpx - 5) ||
|
2003-03-10 05:03:33 +00:00
|
|
|
|
(!rtl && !left_side && vc == last + 1 && x > tmpx + 5)))
|
|
|
|
|
c = last + 1;
|
2003-03-30 21:42:09 +00:00
|
|
|
|
else if (vc == rit->pos()) {
|
2003-03-10 05:03:33 +00:00
|
|
|
|
c = vis2log(vc);
|
|
|
|
|
if (bidi_level(c) % 2 == 1)
|
|
|
|
|
++c;
|
|
|
|
|
} else {
|
|
|
|
|
c = vis2log(vc - 1);
|
|
|
|
|
bool const rtl = (bidi_level(c) % 2 == 1);
|
|
|
|
|
if (left_side == rtl) {
|
|
|
|
|
++c;
|
2003-04-13 22:24:28 +00:00
|
|
|
|
boundary = isBoundary(bv()->buffer(), *rit_par, c);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-30 21:42:09 +00:00
|
|
|
|
if (rit->pos() <= last && c > last
|
2003-04-13 22:24:28 +00:00
|
|
|
|
&& rit_par->isNewline(last)) {
|
2003-03-10 05:03:33 +00:00
|
|
|
|
if (bidi_level(last) % 2 == 0)
|
2003-04-13 22:24:28 +00:00
|
|
|
|
tmpx -= singleWidth(rit_par, last);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
else
|
2003-04-13 22:24:28 +00:00
|
|
|
|
tmpx += singleWidth(rit_par, last);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
c = last;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-30 21:42:09 +00:00
|
|
|
|
c -= rit->pos();
|
2003-03-10 05:03:33 +00:00
|
|
|
|
x = int(tmpx);
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-18 13:05:08 +00:00
|
|
|
|
void LyXText::setCursorFromCoordinates(int x, int y)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
|
LyXCursor old_cursor = cursor;
|
2001-07-30 11:56:00 +00:00
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursorFromCoordinates(cursor, x, y);
|
|
|
|
|
setCurrentFont();
|
|
|
|
|
deleteEmptyParagraphMechanism(old_cursor);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
|
2002-08-04 23:11:50 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* return true if the cursor given is at the end of a row,
|
|
|
|
|
* and the next row is filled by an inset that spans an entire
|
|
|
|
|
* row.
|
|
|
|
|
*/
|
2003-04-15 00:30:26 +00:00
|
|
|
|
bool beforeFullRowInset(LyXText & lt, LyXCursor const & cur) {
|
|
|
|
|
RowList::iterator row = cur.row();
|
2003-04-01 16:55:48 +00:00
|
|
|
|
if (boost::next(row) == lt.rows().end())
|
2002-08-04 23:11:50 +00:00
|
|
|
|
return false;
|
2003-04-01 16:55:48 +00:00
|
|
|
|
Row const & next = *boost::next(row);
|
2002-08-04 23:11:50 +00:00
|
|
|
|
|
|
|
|
|
if (next.pos() != cur.pos() || next.par() != cur.par())
|
|
|
|
|
return false;
|
2003-04-15 00:30:26 +00:00
|
|
|
|
|
|
|
|
|
if (cur.pos() == cur.par()->size()
|
|
|
|
|
|| !cur.par()->isInset(cur.pos()))
|
2002-08-04 23:11:50 +00:00
|
|
|
|
return false;
|
|
|
|
|
Inset const * inset = cur.par()->getInset(cur.pos());
|
|
|
|
|
if (inset->needFullRow() || inset->display())
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-08-10 15:21:07 +00:00
|
|
|
|
|
2002-08-04 23:11:50 +00:00
|
|
|
|
|
2003-03-30 07:27:36 +00:00
|
|
|
|
void LyXText::setCursorFromCoordinates(LyXCursor & cur, int x, int y)
|
2000-03-27 15:13:47 +00:00
|
|
|
|
{
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// Get the row first.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-03-30 07:27:36 +00:00
|
|
|
|
RowList::iterator row = getRowNearY(y);
|
2000-06-08 23:16:16 +00:00
|
|
|
|
bool bound = false;
|
2003-04-01 16:55:48 +00:00
|
|
|
|
pos_type const column = getColumnNearX(row, x, bound);
|
2003-04-13 12:56:48 +00:00
|
|
|
|
cur.par(row->par());
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cur.pos(row->pos() + column);
|
|
|
|
|
cur.x(x);
|
|
|
|
|
cur.y(y + row->baseline());
|
2003-04-01 16:55:48 +00:00
|
|
|
|
cur.row(row);
|
2002-08-10 15:21:07 +00:00
|
|
|
|
|
2003-04-15 00:30:26 +00:00
|
|
|
|
if (beforeFullRowInset(*this, cur)) {
|
2003-04-01 16:55:48 +00:00
|
|
|
|
pos_type last = lastPrintablePos(*this, row);
|
|
|
|
|
float x = getCursorX(boost::next(row), cur.pos(), last, bound);
|
2002-04-16 14:10:39 +00:00
|
|
|
|
cur.ix(int(x));
|
2003-04-01 16:55:48 +00:00
|
|
|
|
cur.iy(y + row->height() + boost::next(row)->baseline());
|
|
|
|
|
cur.irow(boost::next(row));
|
2002-04-11 14:22:39 +00:00
|
|
|
|
} else {
|
|
|
|
|
cur.iy(cur.y());
|
2002-04-16 14:10:39 +00:00
|
|
|
|
cur.ix(cur.x());
|
2003-04-01 16:55:48 +00:00
|
|
|
|
cur.irow(row);
|
2002-04-11 14:22:39 +00:00
|
|
|
|
}
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cur.boundary(bound);
|
2000-03-27 15:13:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-03-18 13:05:08 +00:00
|
|
|
|
void LyXText::cursorLeft(bool internal)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (cursor.pos() > 0) {
|
|
|
|
|
bool boundary = cursor.boundary();
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(cursor.par(), cursor.pos() - 1, true, false);
|
2000-05-30 19:31:11 +00:00
|
|
|
|
if (!internal && !boundary &&
|
2003-04-13 01:04:04 +00:00
|
|
|
|
isBoundary(bv()->buffer(), *cursor.par(), cursor.pos() + 1))
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(cursor.par(), cursor.pos() + 1, true, true);
|
2003-04-13 01:04:04 +00:00
|
|
|
|
} else if (cursor.par() != ownerParagraphs().begin()) { // steps into the above paragraph.
|
|
|
|
|
ParagraphList::iterator pit = boost::prior(cursor.par());
|
|
|
|
|
setCursor(pit, pit->size());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-18 13:05:08 +00:00
|
|
|
|
void LyXText::cursorRight(bool internal)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-04-09 22:28:51 +00:00
|
|
|
|
bool const at_end = (cursor.pos() == cursor.par()->size());
|
|
|
|
|
bool const at_newline = !at_end &&
|
|
|
|
|
cursor.par()->isNewline(cursor.pos());
|
|
|
|
|
|
|
|
|
|
if (!internal && cursor.boundary() && !at_newline)
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(cursor.par(), cursor.pos(), true, false);
|
2003-04-09 22:28:51 +00:00
|
|
|
|
else if (!at_end) {
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(cursor.par(), cursor.pos() + 1, true, false);
|
2000-07-10 10:31:34 +00:00
|
|
|
|
if (!internal &&
|
2003-04-13 01:04:04 +00:00
|
|
|
|
isBoundary(bv()->buffer(), *cursor.par(), cursor.pos()))
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(cursor.par(), cursor.pos(), true, true);
|
2003-04-13 02:23:30 +00:00
|
|
|
|
} else if (boost::next(cursor.par()) != ownerParagraphs().end())
|
|
|
|
|
setCursor(boost::next(cursor.par()), 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-18 13:05:08 +00:00
|
|
|
|
void LyXText::cursorUp(bool selecting)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-04-16 14:10:39 +00:00
|
|
|
|
#if 1
|
|
|
|
|
int x = cursor.x_fix();
|
|
|
|
|
int y = cursor.y() - cursor.row()->baseline() - 1;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursorFromCoordinates(x, y);
|
2002-04-17 08:34:59 +00:00
|
|
|
|
if (!selecting) {
|
2003-03-06 20:21:21 +00:00
|
|
|
|
int topy = top_y();
|
|
|
|
|
int y1 = cursor.iy() - topy;
|
2002-04-17 08:34:59 +00:00
|
|
|
|
int y2 = y1;
|
2003-03-06 20:21:21 +00:00
|
|
|
|
y -= topy;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
Inset * inset_hit = checkInsetHit(x, y1);
|
2002-04-17 08:34:59 +00:00
|
|
|
|
if (inset_hit && isHighlyEditableInset(inset_hit)) {
|
2003-03-17 16:25:00 +00:00
|
|
|
|
inset_hit->edit(bv(), x, y - (y2 - y1), mouse_button::none);
|
2002-04-17 08:34:59 +00:00
|
|
|
|
}
|
2002-04-16 14:10:39 +00:00
|
|
|
|
}
|
|
|
|
|
#else
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursorFromCoordinates(bv(), cursor.x_fix(),
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cursor.y() - cursor.row()->baseline() - 1);
|
2002-04-16 14:10:39 +00:00
|
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-18 13:05:08 +00:00
|
|
|
|
void LyXText::cursorDown(bool selecting)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-04-16 14:10:39 +00:00
|
|
|
|
#if 1
|
|
|
|
|
int x = cursor.x_fix();
|
|
|
|
|
int y = cursor.y() - cursor.row()->baseline() +
|
|
|
|
|
cursor.row()->height() + 1;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursorFromCoordinates(x, y);
|
2002-04-19 11:06:09 +00:00
|
|
|
|
if (!selecting && cursor.row() == cursor.irow()) {
|
2003-03-06 20:21:21 +00:00
|
|
|
|
int topy = top_y();
|
|
|
|
|
int y1 = cursor.iy() - topy;
|
2002-04-17 08:34:59 +00:00
|
|
|
|
int y2 = y1;
|
2003-03-06 20:21:21 +00:00
|
|
|
|
y -= topy;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
Inset * inset_hit = checkInsetHit(x, y1);
|
2002-04-17 08:34:59 +00:00
|
|
|
|
if (inset_hit && isHighlyEditableInset(inset_hit)) {
|
2003-03-17 16:25:00 +00:00
|
|
|
|
inset_hit->edit(bv(), x, y - (y2 - y1), mouse_button::none);
|
2002-04-17 08:34:59 +00:00
|
|
|
|
}
|
2002-04-16 14:10:39 +00:00
|
|
|
|
}
|
|
|
|
|
#else
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursorFromCoordinates(bv(), cursor.x_fix(),
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cursor.y() - cursor.row()->baseline()
|
|
|
|
|
+ cursor.row()->height() + 1);
|
2002-04-16 14:10:39 +00:00
|
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-18 13:05:08 +00:00
|
|
|
|
void LyXText::cursorUpParagraph()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (cursor.pos() > 0) {
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(cursor.par(), 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2003-04-13 01:04:04 +00:00
|
|
|
|
else if (cursor.par() != ownerParagraphs().begin()) {
|
|
|
|
|
setCursor(boost::prior(cursor.par()), 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-18 13:05:08 +00:00
|
|
|
|
void LyXText::cursorDownParagraph()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-04-13 02:23:30 +00:00
|
|
|
|
if (boost::next(cursor.par()) != ownerParagraphs().end()) {
|
|
|
|
|
setCursor(boost::next(cursor.par()), 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else {
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(cursor.par(), cursor.par()->size());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-09-27 09:52:06 +00:00
|
|
|
|
// fix the cursor `cur' after a characters has been deleted at `where'
|
|
|
|
|
// position. Called by deleteEmptyParagraphMechanism
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::fixCursorAfterDelete(LyXCursor & cur,
|
2003-03-18 13:05:08 +00:00
|
|
|
|
LyXCursor const & where)
|
2001-09-27 09:52:06 +00:00
|
|
|
|
{
|
|
|
|
|
// if cursor is not in the paragraph where the delete occured,
|
|
|
|
|
// do nothing
|
|
|
|
|
if (cur.par() != where.par())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// if cursor position is after the place where the delete occured,
|
|
|
|
|
// update it
|
|
|
|
|
if (cur.pos() > where.pos())
|
|
|
|
|
cur.pos(cur.pos()-1);
|
|
|
|
|
|
2002-05-02 12:45:27 +00:00
|
|
|
|
// check also if we don't want to set the cursor on a spot behind the
|
|
|
|
|
// pagragraph because we erased the last character.
|
|
|
|
|
if (cur.pos() > cur.par()->size())
|
|
|
|
|
cur.pos(cur.par()->size());
|
2002-05-29 16:21:03 +00:00
|
|
|
|
|
2001-09-27 09:52:06 +00:00
|
|
|
|
// recompute row et al. for this cursor
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(cur, cur.par(), cur.pos(), cur.boundary());
|
2001-09-27 09:52:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-03-18 13:05:08 +00:00
|
|
|
|
bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-03-14 23:33:15 +00:00
|
|
|
|
// Would be wrong to delete anything if we have a selection.
|
2002-03-07 11:58:19 +00:00
|
|
|
|
if (selection.set())
|
|
|
|
|
return false;
|
2000-01-13 16:28:54 +00:00
|
|
|
|
|
2000-03-14 23:33:15 +00:00
|
|
|
|
// We allow all kinds of "mumbo-jumbo" when freespacing.
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (old_cursor.par()->layout()->free_spacing
|
|
|
|
|
|| old_cursor.par()->isFreeSpacing()) {
|
2002-01-12 21:03:30 +00:00
|
|
|
|
return false;
|
2001-11-29 16:29:30 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
/* Ok I'll put some comments here about what is missing.
|
|
|
|
|
I have fixed BackSpace (and thus Delete) to not delete
|
|
|
|
|
double-spaces automagically. I have also changed Cut,
|
|
|
|
|
Copy and Paste to hopefully do some sensible things.
|
|
|
|
|
There are still some small problems that can lead to
|
|
|
|
|
double spaces stored in the document file or space at
|
|
|
|
|
the beginning of paragraphs. This happens if you have
|
|
|
|
|
the cursor betwenn to spaces and then save. Or if you
|
|
|
|
|
cut and paste and the selection have a space at the
|
|
|
|
|
beginning and then save right after the paste. I am
|
|
|
|
|
sure none of these are very hard to fix, but I will
|
|
|
|
|
put out 1.1.4pre2 with FIX_DOUBLE_SPACE defined so
|
|
|
|
|
that I can get some feedback. (Lgb)
|
|
|
|
|
*/
|
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
// If old_cursor.pos() == 0 and old_cursor.pos()(1) == LineSeparator
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// delete the LineSeparator.
|
|
|
|
|
// MISSING
|
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
// If old_cursor.pos() == 1 and old_cursor.pos()(0) == LineSeparator
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// delete the LineSeparator.
|
|
|
|
|
// MISSING
|
|
|
|
|
|
|
|
|
|
// If the pos around the old_cursor were spaces, delete one of them.
|
2001-12-11 14:33:52 +00:00
|
|
|
|
if (old_cursor.par() != cursor.par()
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|| old_cursor.pos() != cursor.pos()) {
|
2000-05-26 16:13:01 +00:00
|
|
|
|
// Only if the cursor has really moved
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (old_cursor.pos() > 0
|
2001-03-11 00:21:13 +00:00
|
|
|
|
&& old_cursor.pos() < old_cursor.par()->size()
|
2001-06-25 00:06:33 +00:00
|
|
|
|
&& old_cursor.par()->isLineSeparator(old_cursor.pos())
|
|
|
|
|
&& old_cursor.par()->isLineSeparator(old_cursor.pos() - 1)) {
|
|
|
|
|
old_cursor.par()->erase(old_cursor.pos() - 1);
|
2003-04-13 02:23:30 +00:00
|
|
|
|
redoParagraphs(old_cursor, boost::next(old_cursor.par()));
|
2001-09-27 09:52:06 +00:00
|
|
|
|
|
|
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
|
#warning This will not work anymore when we have multiple views of the same buffer
|
|
|
|
|
// In this case, we will have to correct also the cursors held by
|
|
|
|
|
// other bufferviews. It will probably be easier to do that in a more
|
|
|
|
|
// automated way in LyXCursor code. (JMarc 26/09/2001)
|
|
|
|
|
#endif
|
|
|
|
|
// correct all cursors held by the LyXText
|
2003-03-17 16:25:00 +00:00
|
|
|
|
fixCursorAfterDelete(cursor, old_cursor);
|
|
|
|
|
fixCursorAfterDelete(selection.cursor,
|
2001-09-27 09:52:06 +00:00
|
|
|
|
old_cursor);
|
2003-03-17 16:25:00 +00:00
|
|
|
|
fixCursorAfterDelete(selection.start,
|
2001-09-27 09:52:06 +00:00
|
|
|
|
old_cursor);
|
2003-03-17 16:25:00 +00:00
|
|
|
|
fixCursorAfterDelete(selection.end, old_cursor);
|
|
|
|
|
fixCursorAfterDelete(last_sel_cursor,
|
2001-09-27 09:52:06 +00:00
|
|
|
|
old_cursor);
|
2003-03-17 16:25:00 +00:00
|
|
|
|
fixCursorAfterDelete(toggle_cursor, old_cursor);
|
|
|
|
|
fixCursorAfterDelete(toggle_end_cursor,
|
2001-09-27 09:52:06 +00:00
|
|
|
|
old_cursor);
|
2002-01-12 21:03:30 +00:00
|
|
|
|
return false;
|
2000-03-14 23:33:15 +00:00
|
|
|
|
}
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
2001-12-11 14:33:52 +00:00
|
|
|
|
// don't delete anything if this is the ONLY paragraph!
|
2003-04-13 01:04:04 +00:00
|
|
|
|
if (ownerParagraphs().size() == 1)
|
2002-01-12 21:03:30 +00:00
|
|
|
|
return false;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-03-14 23:33:15 +00:00
|
|
|
|
// Do not delete empty paragraphs with keepempty set.
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (old_cursor.par()->layout()->keepempty)
|
2002-01-12 21:03:30 +00:00
|
|
|
|
return false;
|
2000-01-13 16:28:54 +00:00
|
|
|
|
|
2001-09-27 10:52:53 +00:00
|
|
|
|
// only do our magic if we changed paragraph
|
2002-03-21 17:27:08 +00:00
|
|
|
|
if (old_cursor.par() == cursor.par())
|
2002-01-12 21:03:30 +00:00
|
|
|
|
return false;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-01-12 21:03:30 +00:00
|
|
|
|
// record if we have deleted a paragraph
|
|
|
|
|
// we can't possibly have deleted a paragraph before this point
|
|
|
|
|
bool deleted = false;
|
|
|
|
|
|
2003-04-13 01:04:04 +00:00
|
|
|
|
if (old_cursor.par()->empty() ||
|
|
|
|
|
(old_cursor.par()->size() == 1 &&
|
|
|
|
|
old_cursor.par()->isLineSeparator(0))) {
|
2001-09-27 10:52:53 +00:00
|
|
|
|
// ok, we will delete anything
|
|
|
|
|
LyXCursor tmpcursor;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-09-27 10:52:53 +00:00
|
|
|
|
deleted = true;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-16 00:02:38 +00:00
|
|
|
|
bool selection_position_was_oldcursor_position = (
|
|
|
|
|
selection.cursor.par() == old_cursor.par()
|
|
|
|
|
&& selection.cursor.pos() == old_cursor.pos());
|
|
|
|
|
|
2003-04-01 16:55:48 +00:00
|
|
|
|
if (old_cursor.row() != rows().begin()) {
|
2003-04-09 09:15:20 +00:00
|
|
|
|
RowList::iterator
|
2003-04-03 17:04:20 +00:00
|
|
|
|
prevrow = boost::prior(old_cursor.row());
|
|
|
|
|
const_cast<LyXText *>(this)->postPaint(old_cursor.y() - old_cursor.row()->baseline() - prevrow->height());
|
2001-09-27 10:52:53 +00:00
|
|
|
|
tmpcursor = cursor;
|
|
|
|
|
cursor = old_cursor; // that undo can restore the right cursor position
|
2003-04-13 02:23:30 +00:00
|
|
|
|
#warning FIXME. --end() iterator is usable here
|
|
|
|
|
ParagraphList::iterator endpit = boost::next(old_cursor.par());
|
|
|
|
|
while (endpit != ownerParagraphs().end() &&
|
|
|
|
|
endpit->getDepth()) {
|
|
|
|
|
++endpit;
|
2001-09-27 10:52:53 +00:00
|
|
|
|
}
|
2003-04-13 01:04:04 +00:00
|
|
|
|
|
2003-04-13 02:23:30 +00:00
|
|
|
|
setUndo(bv(), Undo::DELETE, &*old_cursor.par(), &*endpit);
|
2001-09-27 10:52:53 +00:00
|
|
|
|
cursor = tmpcursor;
|
2001-07-07 18:19:18 +00:00
|
|
|
|
|
2001-12-05 16:11:47 +00:00
|
|
|
|
// delete old row
|
2001-09-27 10:52:53 +00:00
|
|
|
|
removeRow(old_cursor.row());
|
2002-01-12 21:03:30 +00:00
|
|
|
|
// delete old par
|
2003-04-16 00:02:38 +00:00
|
|
|
|
ownerParagraphs().erase(old_cursor.par());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-09-27 10:52:53 +00:00
|
|
|
|
/* Breakagain the next par. Needed because of
|
|
|
|
|
* the parindent that can occur or dissappear.
|
|
|
|
|
* The next row can change its height, if
|
|
|
|
|
* there is another layout before */
|
2003-04-03 17:04:20 +00:00
|
|
|
|
if (boost::next(prevrow) != rows().end()) {
|
|
|
|
|
breakAgain(boost::next(prevrow));
|
|
|
|
|
updateCounters();
|
2001-09-27 10:52:53 +00:00
|
|
|
|
}
|
2003-04-03 17:04:20 +00:00
|
|
|
|
setHeightOfRow(prevrow);
|
2001-09-27 10:52:53 +00:00
|
|
|
|
} else {
|
2003-04-01 16:55:48 +00:00
|
|
|
|
RowList::iterator nextrow = boost::next(old_cursor.row());
|
2003-03-17 16:25:00 +00:00
|
|
|
|
const_cast<LyXText *>(this)->postPaint(
|
2003-03-17 01:34:36 +00:00
|
|
|
|
old_cursor.y() - old_cursor.row()->baseline());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-09-27 10:52:53 +00:00
|
|
|
|
tmpcursor = cursor;
|
|
|
|
|
cursor = old_cursor; // that undo can restore the right cursor position
|
2003-04-13 02:23:30 +00:00
|
|
|
|
#warning FIXME. --end() iterator is usable here
|
|
|
|
|
ParagraphList::iterator endpit = boost::next(old_cursor.par());
|
|
|
|
|
while (endpit != ownerParagraphs().end() &&
|
|
|
|
|
endpit->getDepth()) {
|
|
|
|
|
++endpit;
|
2001-09-27 10:52:53 +00:00
|
|
|
|
}
|
2003-04-13 01:04:04 +00:00
|
|
|
|
|
2003-04-13 02:23:30 +00:00
|
|
|
|
setUndo(bv(), Undo::DELETE, &*old_cursor.par(), &*endpit);
|
2001-09-27 10:52:53 +00:00
|
|
|
|
cursor = tmpcursor;
|
|
|
|
|
|
|
|
|
|
// delete old row
|
|
|
|
|
removeRow(old_cursor.row());
|
|
|
|
|
// delete old par
|
2003-04-16 00:02:38 +00:00
|
|
|
|
ownerParagraphs().erase(old_cursor.par());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-09-27 10:52:53 +00:00
|
|
|
|
/* Breakagain the next par. Needed because of
|
|
|
|
|
the parindent that can occur or dissappear.
|
|
|
|
|
The next row can change its height, if
|
|
|
|
|
there is another layout before */
|
2003-04-01 16:55:48 +00:00
|
|
|
|
if (nextrow != rows().end()) {
|
2003-03-17 16:25:00 +00:00
|
|
|
|
breakAgain(nextrow);
|
|
|
|
|
updateCounters();
|
2001-07-07 18:19:18 +00:00
|
|
|
|
}
|
2001-09-27 10:52:53 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-09-27 10:52:53 +00:00
|
|
|
|
// correct cursor y
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursorIntern(cursor.par(), cursor.pos());
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
2003-04-16 00:02:38 +00:00
|
|
|
|
if (selection_position_was_oldcursor_position) {
|
2001-09-27 10:52:53 +00:00
|
|
|
|
// correct selection
|
|
|
|
|
selection.cursor = cursor;
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2001-09-27 10:52:53 +00:00
|
|
|
|
}
|
|
|
|
|
if (!deleted) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (old_cursor.par()->stripLeadingSpaces()) {
|
2003-04-13 02:23:30 +00:00
|
|
|
|
redoParagraphs(old_cursor, boost::next(old_cursor.par()));
|
2001-09-27 10:52:53 +00:00
|
|
|
|
// correct cursor y
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursorIntern(cursor.par(), cursor.pos());
|
2001-09-27 10:52:53 +00:00
|
|
|
|
selection.cursor = cursor;
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-01-12 21:03:30 +00:00
|
|
|
|
return deleted;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-04-02 17:11:38 +00:00
|
|
|
|
ParagraphList & LyXText::ownerParagraphs() const
|
2000-06-12 11:27:15 +00:00
|
|
|
|
{
|
2001-07-07 18:19:18 +00:00
|
|
|
|
if (inset_owner) {
|
2003-04-02 17:11:38 +00:00
|
|
|
|
return inset_owner->paragraphs;
|
2001-07-07 18:19:18 +00:00
|
|
|
|
}
|
2003-04-02 17:11:38 +00:00
|
|
|
|
return bv_owner->buffer()->paragraphs;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-25 01:28:29 +00:00
|
|
|
|
LyXText::refresh_status LyXText::refreshStatus() const
|
2001-07-06 15:57:54 +00:00
|
|
|
|
{
|
2003-03-25 01:28:29 +00:00
|
|
|
|
return refresh_status_;
|
2001-07-06 15:57:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-16 00:45:31 +00:00
|
|
|
|
void LyXText::clearPaint()
|
|
|
|
|
{
|
2003-03-25 01:28:29 +00:00
|
|
|
|
refresh_status_ = REFRESH_NONE;
|
2003-03-30 18:42:37 +00:00
|
|
|
|
refresh_row = rows().end();
|
2003-03-16 00:45:31 +00:00
|
|
|
|
refresh_y = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::postPaint(int start_y)
|
2003-03-16 00:45:31 +00:00
|
|
|
|
{
|
2003-03-25 01:28:29 +00:00
|
|
|
|
refresh_status old = refresh_status_;
|
2003-03-17 01:34:36 +00:00
|
|
|
|
|
2003-03-25 01:28:29 +00:00
|
|
|
|
refresh_status_ = REFRESH_AREA;
|
2003-03-30 18:42:37 +00:00
|
|
|
|
refresh_row = rows().end();
|
2003-03-16 00:45:31 +00:00
|
|
|
|
|
2003-03-25 01:28:29 +00:00
|
|
|
|
if (old != REFRESH_NONE && refresh_y < start_y)
|
2003-03-17 01:34:36 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
refresh_y = start_y;
|
|
|
|
|
|
2003-03-16 00:45:31 +00:00
|
|
|
|
if (!inset_owner)
|
|
|
|
|
return;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
|
2003-03-16 00:45:31 +00:00
|
|
|
|
// We are an inset's lyxtext. Tell the top-level lyxtext
|
|
|
|
|
// it needs to update the row we're in.
|
2003-03-17 16:25:00 +00:00
|
|
|
|
LyXText * t = bv()->text;
|
2003-03-20 14:13:49 +00:00
|
|
|
|
t->postRowPaint(t->cursor.row(), t->cursor.y() - t->cursor.row()->baseline());
|
2003-03-16 00:45:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// FIXME: we should probably remove this y parameter,
|
|
|
|
|
// make refresh_y be 0, and use row->y etc.
|
2003-03-30 21:42:09 +00:00
|
|
|
|
void LyXText::postRowPaint(RowList::iterator rit, int start_y)
|
2003-03-16 00:45:31 +00:00
|
|
|
|
{
|
2003-03-25 01:28:29 +00:00
|
|
|
|
if (refresh_status_ != REFRESH_NONE && refresh_y < start_y) {
|
|
|
|
|
refresh_status_ = REFRESH_AREA;
|
2003-03-17 01:34:36 +00:00
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
refresh_y = start_y;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-25 01:28:29 +00:00
|
|
|
|
if (refresh_status_ == REFRESH_AREA)
|
2003-03-16 00:45:31 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2003-03-25 01:28:29 +00:00
|
|
|
|
refresh_status_ = REFRESH_ROW;
|
2003-03-30 21:42:09 +00:00
|
|
|
|
refresh_row = rit;
|
2003-03-16 00:45:31 +00:00
|
|
|
|
|
|
|
|
|
if (!inset_owner)
|
|
|
|
|
return;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
|
2003-03-16 00:45:31 +00:00
|
|
|
|
// We are an inset's lyxtext. Tell the top-level lyxtext
|
|
|
|
|
// it needs to update the row we're in.
|
2003-03-17 16:25:00 +00:00
|
|
|
|
LyXText * t = bv()->text;
|
2003-03-20 14:13:49 +00:00
|
|
|
|
t->postRowPaint(t->cursor.row(), t->cursor.y() - t->cursor.row()->baseline());
|
2003-03-16 00:45:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-26 17:04:10 +00:00
|
|
|
|
bool LyXText::isInInset() const
|
|
|
|
|
{
|
2003-03-17 16:25:00 +00:00
|
|
|
|
// Sub-level has non-null bv owner and
|
|
|
|
|
// non-null inset owner.
|
|
|
|
|
return inset_owner != 0 && bv_owner != 0;
|
2003-02-26 17:04:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-14 00:41:44 +00:00
|
|
|
|
int defaultRowHeight()
|
|
|
|
|
{
|
|
|
|
|
LyXFont const font(LyXFont::ALL_SANE);
|
|
|
|
|
return int(font_metrics::maxAscent(font)
|
|
|
|
|
+ font_metrics::maxDescent(font) * 1.5);
|
|
|
|
|
}
|