2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file text2.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Asger Alstrup
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Alfredo Braunstein
|
|
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
|
* \author Angus Leeming
|
|
|
|
|
* \author John Levon
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
* \author Allan Rae
|
|
|
|
|
* \author Dekel Tsur
|
|
|
|
|
* \author J<EFBFBD>rgen Vigna
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2001-04-17 15:15:59 +00:00
|
|
|
|
#include "lyxtext.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "LString.h"
|
2003-05-13 09:48:57 +00:00
|
|
|
|
#include "Lsstream.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "paragraph.h"
|
2003-05-13 09:48:57 +00:00
|
|
|
|
#include "funcrequest.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"
|
2003-06-24 20:42:15 +00:00
|
|
|
|
#include "buffer_funcs.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "bufferparams.h"
|
2003-05-20 16:51:31 +00:00
|
|
|
|
#include "errorlist.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#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"
|
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-07-22 10:12:24 +00:00
|
|
|
|
#include "metricsinfo.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"
|
2003-05-19 07:12:09 +00:00
|
|
|
|
#include "insets/insetenv.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
#include "insets/insetfloat.h"
|
2003-05-06 06:16:59 +00:00
|
|
|
|
#include "insets/insetwrap.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
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-04-29 09:40:49 +00:00
|
|
|
|
#include <boost/tuple/tuple.hpp>
|
2002-12-01 21:10:37 +00:00
|
|
|
|
|
2003-07-22 10:12:24 +00:00
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
|
using namespace lyx::support;
|
|
|
|
|
|
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
|
|
|
|
|
2003-08-15 14:54:19 +00:00
|
|
|
|
LyXText::LyXText(BufferView * bv, InsetText * inset, bool ininset,
|
|
|
|
|
ParagraphList & paragraphs)
|
2003-08-15 13:12:24 +00:00
|
|
|
|
: height(0), width(0), anchor_y_(0),
|
2003-08-15 14:54:19 +00:00
|
|
|
|
inset_owner(inset), the_locking_inset(0), bv_owner(bv),
|
|
|
|
|
in_inset_(ininset), paragraphs_(paragraphs)
|
|
|
|
|
{
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-03-02 16:39:54 +00:00
|
|
|
|
|
2003-07-15 08:26:17 +00:00
|
|
|
|
void LyXText::init(BufferView * bview)
|
2000-06-12 11:27:15 +00:00
|
|
|
|
{
|
2003-07-10 08:00:41 +00:00
|
|
|
|
bv_owner = bview;
|
2003-07-15 08:26:17 +00:00
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
|
ParagraphList::iterator const beg = ownerParagraphs().begin();
|
|
|
|
|
ParagraphList::iterator const end = ownerParagraphs().end();
|
|
|
|
|
for (ParagraphList::iterator pit = beg; pit != end; ++pit)
|
|
|
|
|
pit->rows.clear();
|
|
|
|
|
|
2003-08-07 10:00:33 +00:00
|
|
|
|
width = 0;
|
|
|
|
|
height = 0;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
|
2003-08-15 13:12:24 +00:00
|
|
|
|
anchor_y_ = 0;
|
2003-07-14 09:15:58 +00:00
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
|
current_font = getFont(beg, 0);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
|
redoParagraphs(beg, end);
|
|
|
|
|
setCursorIntern(beg, 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)
|
2003-07-27 21:59:06 +00:00
|
|
|
|
LyXFont LyXText::getFont(ParagraphList::iterator pit, pos_type pos) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-06-30 23:56:22 +00:00
|
|
|
|
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();
|
2003-07-27 21:59:06 +00:00
|
|
|
|
#warning broken?
|
|
|
|
|
BufferParams const & params = bv()->buffer()->params;
|
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-07-27 21:59:06 +00:00
|
|
|
|
LyXFont f = pit->getFontSettings(params, pos);
|
2003-04-09 21:34:31 +00:00
|
|
|
|
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-07-27 21:59:06 +00:00
|
|
|
|
LyXFont f = pit->getFontSettings(params, pos);
|
2003-04-09 21:34:31 +00:00
|
|
|
|
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-07-27 21:59:06 +00:00
|
|
|
|
LyXFont tmpfont = pit->getFontSettings(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.
|
2003-04-16 04:35:43 +00:00
|
|
|
|
tmpfont.realize(outerFont(pit, ownerParagraphs()));
|
2003-07-28 10:41:47 +00:00
|
|
|
|
tmpfont.realize(defaultfont_);
|
2003-04-15 00:11:03 +00:00
|
|
|
|
|
2003-07-27 21:59:06 +00:00
|
|
|
|
return tmpfont;
|
2001-08-03 18:28:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-27 21:59:06 +00:00
|
|
|
|
LyXFont LyXText::getLayoutFont(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-07-31 12:25:36 +00:00
|
|
|
|
if (!pit->getDepth())
|
2002-06-24 20:28:12 +00:00
|
|
|
|
return layout->resfont;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-07-27 21:59:06 +00:00
|
|
|
|
LyXFont font = layout->font;
|
2003-04-15 00:11:03 +00:00
|
|
|
|
// Realize with the fonts of lesser depth.
|
2003-04-16 04:35:43 +00:00
|
|
|
|
font.realize(outerFont(pit, ownerParagraphs()));
|
2003-07-28 10:41:47 +00:00
|
|
|
|
font.realize(defaultfont_);
|
2003-04-15 00:11:03 +00:00
|
|
|
|
|
2003-07-27 21:59:06 +00:00
|
|
|
|
return font;
|
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-07-27 21:59:06 +00:00
|
|
|
|
LyXFont LyXText::getLabelFont(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-07-31 12:25:36 +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-07-27 21:59:06 +00:00
|
|
|
|
LyXFont font = layout->labelfont;
|
2003-04-15 00:11:03 +00:00
|
|
|
|
// Realize with the fonts of lesser depth.
|
2003-04-16 04:35:43 +00:00
|
|
|
|
font.realize(outerFont(pit, ownerParagraphs()));
|
2003-07-28 10:41:47 +00:00
|
|
|
|
font.realize(defaultfont_);
|
2003-04-15 00:11:03 +00:00
|
|
|
|
|
2003-07-27 21:59:06 +00:00
|
|
|
|
return font;
|
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-07-27 21:59:06 +00:00
|
|
|
|
BufferParams const & params = bv()->buffer()->params;
|
|
|
|
|
LyXFont font = getFont(pit, pos);
|
|
|
|
|
font.update(fnt, 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)) {
|
2003-07-25 21:20:24 +00:00
|
|
|
|
InsetOld * inset = pit->getInset(pos);
|
2001-11-09 13:44:48 +00:00
|
|
|
|
if (isEditableInset(inset)) {
|
2003-07-27 21:59:06 +00:00
|
|
|
|
static_cast<UpdatableInset *>(inset)
|
|
|
|
|
->setFont(bv(), fnt, toggleall, true);
|
2001-05-28 15:11:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-27 21:59:06 +00:00
|
|
|
|
// Plug through to version below:
|
|
|
|
|
setCharFont(pit, pos, font);
|
2001-05-28 15:11:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-07-06 15:41:17 +00:00
|
|
|
|
|
2003-07-27 21:59:06 +00:00
|
|
|
|
void LyXText::setCharFont(
|
|
|
|
|
ParagraphList::iterator pit, pos_type pos, LyXFont const & fnt)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-07-27 21:59:06 +00:00
|
|
|
|
LyXFont font = fnt;
|
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()) {
|
2003-04-16 08:12:22 +00:00
|
|
|
|
ParagraphList::iterator tp = pit;
|
|
|
|
|
while (!layoutfont.resolved() &&
|
|
|
|
|
tp != ownerParagraphs().end() &&
|
|
|
|
|
tp->getDepth()) {
|
|
|
|
|
tp = outerHook(tp, ownerParagraphs());
|
|
|
|
|
if (tp != ownerParagraphs().end())
|
2002-06-24 20:28:12 +00:00
|
|
|
|
layoutfont.realize(tp->layout()->font);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-28 10:41:47 +00:00
|
|
|
|
layoutfont.realize(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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-25 21:20:24 +00:00
|
|
|
|
InsetOld * 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
|
|
|
|
{
|
2003-07-25 21:20:24 +00:00
|
|
|
|
InsetOld * 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-06-04 07:14:05 +00:00
|
|
|
|
bv()->unlockInset(inset_owner->owner());
|
2003-03-17 16:25:00 +00:00
|
|
|
|
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-07-25 19:18:43 +00:00
|
|
|
|
recordUndo(bv(), Undo::ATOMIC);
|
2001-07-24 22:08:49 +00:00
|
|
|
|
|
2003-08-05 08:07:07 +00:00
|
|
|
|
if (inset->isOpen())
|
2003-03-17 16:25:00 +00:00
|
|
|
|
inset->close(bv());
|
2003-08-05 08:07:07 +00:00
|
|
|
|
else
|
2003-03-17 16:25:00 +00:00
|
|
|
|
inset->open(bv());
|
2003-03-20 14:13:49 +00:00
|
|
|
|
|
2003-08-27 13:51:18 +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-07-27 21:59:06 +00:00
|
|
|
|
void LyXText::makeFontEntriesLayoutSpecific(BufferParams const & params,
|
2003-02-26 17:04:10 +00:00
|
|
|
|
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-07-27 21:59:06 +00:00
|
|
|
|
LyXFont tmpfont = par.getFontSettings(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-07-25 19:18:43 +00:00
|
|
|
|
recordUndo(bv(), Undo::ATOMIC, sstart_cur.par(), boost::prior(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);
|
2003-07-27 21:59:06 +00:00
|
|
|
|
makeFontEntriesLayoutSpecific(bv()->buffer()->params, *pit);
|
2003-08-11 09:09:01 +00:00
|
|
|
|
pit->params().spaceTop(lyxlayout->fill_top ?
|
2001-07-07 18:19:18 +00:00
|
|
|
|
VSpace(VSpace::VFILL)
|
|
|
|
|
: VSpace(VSpace::NONE));
|
2003-08-11 09:09:01 +00:00
|
|
|
|
pit->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
|
|
|
|
{
|
2003-05-23 07:44:09 +00:00
|
|
|
|
LyXCursor tmpcursor = cursor; // store the current cursor
|
2001-05-31 02:23:46 +00:00
|
|
|
|
|
|
|
|
|
// if there is no selection just set the layout
|
2003-05-23 07:44:09 +00:00
|
|
|
|
// of the current paragraph
|
2001-05-31 02:23:46 +00:00
|
|
|
|
if (!selection.set()) {
|
|
|
|
|
selection.start = cursor; // dummy selection
|
|
|
|
|
selection.end = cursor;
|
|
|
|
|
}
|
2003-05-19 07:12:09 +00:00
|
|
|
|
|
|
|
|
|
// special handling of new environment insets
|
|
|
|
|
BufferParams const & params = bv()->buffer()->params;
|
|
|
|
|
LyXLayout_ptr const & lyxlayout = params.getLyXTextClass()[layout];
|
|
|
|
|
if (lyxlayout->is_environment) {
|
|
|
|
|
// move everything in a new environment inset
|
|
|
|
|
lyxerr << "setting layout " << layout << endl;
|
|
|
|
|
bv()->owner()->dispatch(FuncRequest(LFUN_HOME));
|
|
|
|
|
bv()->owner()->dispatch(FuncRequest(LFUN_ENDSEL));
|
|
|
|
|
bv()->owner()->dispatch(FuncRequest(LFUN_CUT));
|
2003-07-25 21:20:24 +00:00
|
|
|
|
InsetOld * inset = new InsetEnvironment(params, layout);
|
2003-05-19 07:12:09 +00:00
|
|
|
|
if (bv()->insertInset(inset)) {
|
|
|
|
|
//inset->edit(bv());
|
|
|
|
|
//bv()->owner()->dispatch(FuncRequest(LFUN_PASTE));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
delete inset;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-10 21:07:55 +00:00
|
|
|
|
ParagraphList::iterator endpit = setLayout(cursor, selection.start,
|
|
|
|
|
selection.end, layout);
|
2003-08-01 11:22:13 +00:00
|
|
|
|
redoParagraphs(selection.start.par(), 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-05-19 07:12:09 +00:00
|
|
|
|
setCursor(selection.start.par(), selection.start.pos(), false);
|
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(), 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-08-11 09:09:01 +00:00
|
|
|
|
ParagraphList::iterator pit = cursor.par();
|
|
|
|
|
ParagraphList::iterator end = cursor.par();
|
2003-04-02 17:59:01 +00:00
|
|
|
|
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)
|
2003-07-25 19:18:43 +00:00
|
|
|
|
recordUndo(bv(), Undo::ATOMIC, start, end);
|
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-08-11 09:09:01 +00:00
|
|
|
|
if (!test_only)
|
2003-04-03 01:26:02 +00:00
|
|
|
|
pit->params().depth(depth + 1);
|
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-08-01 11:22:13 +00:00
|
|
|
|
redoParagraphs(start, pastend);
|
2003-04-02 17:59:01 +00:00
|
|
|
|
|
|
|
|
|
// We need to actually move the text->cursor. I don't
|
|
|
|
|
// understand why ...
|
2003-08-01 11:22:13 +00:00
|
|
|
|
LyXCursor 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-07-27 21:59:06 +00:00
|
|
|
|
layoutfont = getLabelFont(cursor.par());
|
2001-08-03 13:09:59 +00:00
|
|
|
|
} else {
|
2003-07-27 21:59:06 +00:00
|
|
|
|
layoutfont = getLayoutFont(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-07-25 19:18:43 +00:00
|
|
|
|
recordUndo(bv(), Undo::ATOMIC, selection.start.par(), 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-08-01 11:22:13 +00:00
|
|
|
|
redoParagraph(selection.start.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-08-26 10:33:59 +00:00
|
|
|
|
int LyXText::redoParagraphInternal(ParagraphList::iterator pit)
|
2003-08-01 12:20:27 +00:00
|
|
|
|
{
|
2003-08-15 08:03:54 +00:00
|
|
|
|
RowList::iterator rit = pit->rows.begin();
|
|
|
|
|
RowList::iterator end = pit->rows.end();
|
|
|
|
|
|
2003-08-22 07:49:57 +00:00
|
|
|
|
// remove rows of paragraph, keep track of height changes
|
2003-08-15 13:12:24 +00:00
|
|
|
|
for (int i = 0; rit != end; ++rit, ++i)
|
2003-08-15 08:03:54 +00:00
|
|
|
|
height -= rit->height();
|
|
|
|
|
pit->rows.clear();
|
|
|
|
|
|
2003-08-22 11:54:02 +00:00
|
|
|
|
// redo insets
|
|
|
|
|
InsetList::iterator ii = pit->insetlist.begin();
|
|
|
|
|
InsetList::iterator iend = pit->insetlist.end();
|
|
|
|
|
for (; ii != iend; ++ii) {
|
|
|
|
|
Dimension dim;
|
2003-08-22 12:38:21 +00:00
|
|
|
|
MetricsInfo mi(bv(), getFont(pit, ii->pos), workWidth());
|
2003-08-22 11:54:02 +00:00
|
|
|
|
ii->inset->metrics(mi, dim);
|
|
|
|
|
}
|
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
|
// rebreak the paragraph
|
2003-08-22 07:49:57 +00:00
|
|
|
|
for (pos_type z = 0; z < pit->size() + 1; ) {
|
|
|
|
|
Row row(z);
|
|
|
|
|
z = rowBreakPoint(pit, row) + 1;
|
|
|
|
|
row.end(z);
|
|
|
|
|
pit->rows.push_back(row);
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-08-26 10:33:59 +00:00
|
|
|
|
int par_width = 0;
|
|
|
|
|
// set height and fill and width of rows
|
|
|
|
|
int const ww = workWidth();
|
2003-08-22 07:49:57 +00:00
|
|
|
|
for (rit = pit->rows.begin(); rit != end; ++rit) {
|
2003-08-26 10:33:59 +00:00
|
|
|
|
int const f = fill(pit, rit, ww);
|
|
|
|
|
int const w = ww - f;
|
|
|
|
|
par_width = std::max(par_width, w);
|
|
|
|
|
rit->fill(f);
|
|
|
|
|
rit->width(w);
|
2003-08-22 09:40:56 +00:00
|
|
|
|
prepareToPrint(pit, rit);
|
2003-08-22 07:49:57 +00:00
|
|
|
|
setHeightOfRow(pit, rit);
|
2003-08-22 12:38:21 +00:00
|
|
|
|
height += rit->height();
|
2003-08-15 08:03:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//lyxerr << "redoParagraph: " << pit->rows.size() << " rows\n";
|
2003-08-26 10:33:59 +00:00
|
|
|
|
return par_width;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-26 10:33:59 +00:00
|
|
|
|
int LyXText::redoParagraphs(ParagraphList::iterator start,
|
2003-08-25 10:24:26 +00:00
|
|
|
|
ParagraphList::iterator end)
|
|
|
|
|
{
|
2003-08-26 10:33:59 +00:00
|
|
|
|
int pars_width = 0;
|
|
|
|
|
for ( ; start != end; ++start) {
|
|
|
|
|
int par_width = redoParagraphInternal(start);
|
2003-08-28 07:41:31 +00:00
|
|
|
|
pars_width = std::max(par_width, pars_width);
|
2003-08-26 10:33:59 +00:00
|
|
|
|
}
|
2003-08-25 10:24:26 +00:00
|
|
|
|
updateRowPositions();
|
2003-08-26 10:33:59 +00:00
|
|
|
|
return pars_width;
|
2003-08-25 10:24:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXText::redoParagraph(ParagraphList::iterator pit)
|
|
|
|
|
{
|
|
|
|
|
redoParagraphInternal(pit);
|
|
|
|
|
updateRowPositions();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
void LyXText::fullRebreak()
|
2003-06-27 09:44:26 +00:00
|
|
|
|
{
|
2003-08-01 12:20:27 +00:00
|
|
|
|
redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end());
|
2003-08-11 09:09:01 +00:00
|
|
|
|
redoCursor();
|
2003-08-01 12:20:27 +00:00
|
|
|
|
selection.cursor = cursor;
|
2003-06-27 09:44:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-22 10:12:24 +00:00
|
|
|
|
void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
|
2003-07-17 06:45:39 +00:00
|
|
|
|
{
|
2003-08-15 14:54:19 +00:00
|
|
|
|
//lyxerr << "LyXText::metrics: width: " << mi.base.textwidth
|
|
|
|
|
// << " workWidth: " << workWidth() << endl;
|
2003-08-01 12:20:27 +00:00
|
|
|
|
//Assert(mi.base.textwidth);
|
2003-07-22 10:12:24 +00:00
|
|
|
|
|
|
|
|
|
// rebuild row cache
|
2003-08-22 12:38:21 +00:00
|
|
|
|
width = 0;
|
|
|
|
|
///height = 0;
|
2003-07-17 06:45:39 +00:00
|
|
|
|
|
2003-08-15 13:12:24 +00:00
|
|
|
|
//anchor_y_ = 0;
|
2003-08-26 10:33:59 +00:00
|
|
|
|
width = redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end());
|
2003-07-17 06:45:39 +00:00
|
|
|
|
|
2003-07-22 10:12:24 +00:00
|
|
|
|
// final dimension
|
2003-08-14 14:10:13 +00:00
|
|
|
|
dim.asc = firstRow()->ascent_of_text();
|
2003-07-22 10:12:24 +00:00
|
|
|
|
dim.des = height - dim.asc;
|
|
|
|
|
dim.wid = std::max(mi.base.textwidth, int(width));
|
2003-07-17 06:45:39 +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
|
|
|
|
{
|
2003-08-05 06:30:42 +00:00
|
|
|
|
TextCursor::setSelection();
|
2000-05-20 21:37:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2003-06-27 13:13:04 +00:00
|
|
|
|
TextCursor::clearSelection();
|
|
|
|
|
|
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-06-27 08:38:41 +00:00
|
|
|
|
setCursor(cursor.par(), cursorRow()->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-06-27 08:38:41 +00:00
|
|
|
|
RowList::iterator rit = cursorRow();
|
2003-08-14 08:34:13 +00:00
|
|
|
|
ParagraphList::iterator pit = cursor.par();
|
2003-09-02 15:44:36 +00:00
|
|
|
|
pos_type pos = lastPos(*pit, rit);
|
|
|
|
|
/* cursor should be before a hard newline only */
|
|
|
|
|
if (!pit->isNewline(pos))
|
|
|
|
|
++pos;
|
|
|
|
|
setCursor(pit, 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-05-29 11:19:52 +00:00
|
|
|
|
ParagraphList::iterator lastpit =
|
|
|
|
|
boost::prior(ownerParagraphs().end());
|
|
|
|
|
setCursor(lastpit, lastpit->size());
|
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-07-01 11:51:20 +00:00
|
|
|
|
? selectWordWhenUnderCursor(lyx::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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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-07-01 11:51:20 +00:00
|
|
|
|
bool const implicitSelection =
|
|
|
|
|
selectWordWhenUnderCursor(lyx::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-08-28 07:41:31 +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
|
2003-08-11 09:09:01 +00:00
|
|
|
|
// physical paragraph. When a paragraph is broken, the top settings rest,
|
|
|
|
|
// the bottom settings are given to the new one. So I can make sure,
|
2002-05-29 13:28:11 +00:00
|
|
|
|
// 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-05-02 15:21:45 +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-07-25 19:18:43 +00:00
|
|
|
|
recordUndo(bv(), Undo::ATOMIC, selection.start.par(),
|
2003-05-23 10:33:40 +00:00
|
|
|
|
boost::prior(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-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-08-01 11:22:13 +00:00
|
|
|
|
redoParagraphs(selection.start.par(), 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-08-27 13:51:18 +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-08-28 07:41:31 +00:00
|
|
|
|
void LyXText::setCounter(Buffer const & buf, ParagraphList::iterator pit)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-08-28 07:41:31 +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
|
|
|
|
}
|
|
|
|
|
|
2003-08-11 09:09:01 +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-16 08:12:22 +00:00
|
|
|
|
pit->enumdepth = depthHook(pit, ownerParagraphs(),
|
|
|
|
|
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-08-11 09:09:01 +00:00
|
|
|
|
if (pit->params().labelWidthString().empty())
|
2003-04-10 21:07:55 +00:00
|
|
|
|
pit->setLabelWidthString(layout->labelstring());
|
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;
|
|
|
|
|
|
2003-08-28 07:41:31 +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()) {
|
2003-08-28 07:41:31 +00:00
|
|
|
|
s << buf.B_(layout->labelstring());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
} else {
|
2003-08-28 07:41:31 +00:00
|
|
|
|
s << buf.B_(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-08-28 07:41:31 +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
|
|
|
|
|
2003-04-25 00:15:48 +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 {
|
2003-08-28 07:41:31 +00:00
|
|
|
|
string s = buf.B_(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-07-31 13:38:06 +00:00
|
|
|
|
ParagraphList::iterator end = ownerParagraphs().end();
|
2003-04-10 21:07:55 +00:00
|
|
|
|
ParagraphList::iterator tmppit = pit;
|
2003-07-25 21:20:24 +00:00
|
|
|
|
InsetOld * in = 0;
|
2002-08-20 11:14:46 +00:00
|
|
|
|
bool isOK = false;
|
2003-07-31 13:38:06 +00:00
|
|
|
|
while (tmppit != end && tmppit->inInset()
|
2002-08-20 11:14:46 +00:00
|
|
|
|
// the single '=' is intended below
|
2003-07-31 13:38:06 +00:00
|
|
|
|
&& (in = tmppit->inInset()->owner()))
|
|
|
|
|
{
|
2003-07-25 21:20:24 +00:00
|
|
|
|
if (in->lyxCode() == InsetOld::FLOAT_CODE ||
|
|
|
|
|
in->lyxCode() == InsetOld::WRAP_CODE) {
|
2002-08-20 11:14:46 +00:00
|
|
|
|
isOK = true;
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
2003-08-28 07:41:31 +00:00
|
|
|
|
Paragraph const * owner = &ownerPar(buf, in);
|
2003-07-31 13:38:06 +00:00
|
|
|
|
tmppit = ownerParagraphs().begin();
|
|
|
|
|
for ( ; tmppit != end; ++tmppit)
|
2003-08-26 16:36:53 +00:00
|
|
|
|
if (&*tmppit == owner)
|
2003-07-31 13:38:06 +00:00
|
|
|
|
break;
|
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) {
|
2003-05-06 06:16:59 +00:00
|
|
|
|
string type;
|
|
|
|
|
|
2003-07-25 21:20:24 +00:00
|
|
|
|
if (in->lyxCode() == InsetOld::FLOAT_CODE)
|
2003-05-06 06:16:59 +00:00
|
|
|
|
type = static_cast<InsetFloat*>(in)->params().type;
|
2003-07-25 21:20:24 +00:00
|
|
|
|
else if (in->lyxCode() == InsetOld::WRAP_CODE)
|
2003-05-06 06:16:59 +00:00
|
|
|
|
type = static_cast<InsetWrap*>(in)->params().type;
|
|
|
|
|
else
|
2003-06-30 23:56:22 +00:00
|
|
|
|
Assert(0);
|
2003-05-06 06:16:59 +00:00
|
|
|
|
|
|
|
|
|
Floating const & fl = textclass.floats().getType(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.
|
2003-08-28 07:41:31 +00:00
|
|
|
|
s = bformat(_("%1$s #:"), buf.B_(fl.name()));
|
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-08-11 09:09:01 +00:00
|
|
|
|
// start over
|
2003-03-17 16:25:00 +00:00
|
|
|
|
bv()->buffer()->params.getLyXTextClass().counters().reset();
|
2002-09-06 14:48:01 +00:00
|
|
|
|
|
2003-06-18 17:43:49 +00:00
|
|
|
|
ParagraphList::iterator beg = ownerParagraphs().begin();
|
|
|
|
|
ParagraphList::iterator end = ownerParagraphs().end();
|
2003-08-11 09:09:01 +00:00
|
|
|
|
for (ParagraphList::iterator pit = beg; pit != end; ++pit) {
|
2003-04-02 23:01:39 +00:00
|
|
|
|
string const oldLabel = pit->params().labelString();
|
2002-11-05 18:25:53 +00:00
|
|
|
|
|
2003-05-16 07:44:00 +00:00
|
|
|
|
size_t maxdepth = 0;
|
2003-06-18 17:43:49 +00:00
|
|
|
|
if (pit != beg)
|
2003-04-07 20:32:29 +00:00
|
|
|
|
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-08-28 07:41:31 +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
|
|
|
|
|
2003-08-11 09:09:01 +00:00
|
|
|
|
if (oldLabel != newLabel)
|
|
|
|
|
redoParagraph(pit);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-25 21:20:24 +00:00
|
|
|
|
void LyXText::insertInset(InsetOld * 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-07-25 19:18:43 +00:00
|
|
|
|
recordUndo(bv(), Undo::ATOMIC, 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);
|
2003-08-11 09:09:01 +00:00
|
|
|
|
// If we enter a highly editable inset the cursor should be before
|
2003-08-28 07:41:31 +00:00
|
|
|
|
// the inset. After an Undo LyX tries to call inset->edit(...)
|
2003-08-11 09:09:01 +00:00
|
|
|
|
// and fails if the cursor is behind the inset and getInset
|
2000-09-28 14:05:24 +00:00
|
|
|
|
// does not return the inset!
|
2003-08-11 09:09:01 +00:00
|
|
|
|
if (isHighlyEditableInset(inset))
|
2003-03-17 16:25:00 +00:00
|
|
|
|
cursorLeft(true);
|
2002-04-12 08:31:06 +00:00
|
|
|
|
unFreezeUndo();
|
1999-09-27 18:44:28 +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-08-28 07:41:31 +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-07-25 19:18:43 +00:00
|
|
|
|
recordUndo(bv(), Undo::DELETE, selection.start.par(),
|
2003-08-05 22:00:04 +00:00
|
|
|
|
boost::prior(undoendpit));
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-29 09:40:49 +00:00
|
|
|
|
endpit = selection.end.par();
|
|
|
|
|
int endpos = selection.end.pos();
|
|
|
|
|
|
2003-04-29 23:59:39 +00:00
|
|
|
|
boost::tie(endpit, endpos) = realcut ?
|
2003-06-10 14:39:45 +00:00
|
|
|
|
CutAndPaste::cutSelection(bv()->buffer()->params,
|
|
|
|
|
ownerParagraphs(),
|
2003-04-29 09:40:49 +00:00
|
|
|
|
selection.start.par(), endpit,
|
|
|
|
|
selection.start.pos(), endpos,
|
|
|
|
|
bv()->buffer()->params.textclass,
|
|
|
|
|
doclear)
|
2003-06-10 14:39:45 +00:00
|
|
|
|
: CutAndPaste::eraseSelection(bv()->buffer()->params,
|
|
|
|
|
ownerParagraphs(),
|
2003-04-29 09:40:49 +00:00
|
|
|
|
selection.start.par(), endpit,
|
|
|
|
|
selection.start.pos(), endpos,
|
|
|
|
|
doclear);
|
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-08-01 11:22:13 +00:00
|
|
|
|
redoParagraphs(selection.start.par(), boost::next(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
|
2003-04-29 09:40:49 +00:00
|
|
|
|
cursor.pos(endpos);
|
|
|
|
|
cursor.par(endpit);
|
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-08-28 07:41:31 +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-30 10:32:01 +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-06-17 15:33:49 +00:00
|
|
|
|
void LyXText::pasteSelection(size_t sel_index)
|
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-07-25 19:18:43 +00:00
|
|
|
|
recordUndo(bv(), Undo::INSERT, cursor.par());
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
2003-04-30 10:32:01 +00:00
|
|
|
|
ParagraphList::iterator endpit;
|
|
|
|
|
PitPosPair ppp;
|
2001-09-20 10:16:24 +00:00
|
|
|
|
|
2003-05-20 16:51:31 +00:00
|
|
|
|
ErrorList el;
|
|
|
|
|
|
2003-05-07 09:26:33 +00:00
|
|
|
|
boost::tie(ppp, endpit) =
|
2003-06-10 14:39:45 +00:00
|
|
|
|
CutAndPaste::pasteSelection(*bv()->buffer(),
|
|
|
|
|
ownerParagraphs(),
|
2003-05-07 09:26:33 +00:00
|
|
|
|
cursor.par(), cursor.pos(),
|
2003-05-20 16:51:31 +00:00
|
|
|
|
bv()->buffer()->params.textclass,
|
2003-06-17 15:33:49 +00:00
|
|
|
|
sel_index, el);
|
2003-07-07 08:37:02 +00:00
|
|
|
|
bufferErrors(*bv()->buffer(), el);
|
2003-05-20 16:51:31 +00:00
|
|
|
|
bv()->showErrorList(_("Paste"));
|
2003-05-07 09:26:33 +00:00
|
|
|
|
|
2003-08-01 11:22:13 +00:00
|
|
|
|
redoParagraphs(cursor.par(), endpit);
|
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-30 10:32:01 +00:00
|
|
|
|
setCursor(ppp.first, ppp.second);
|
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-07-25 19:18:43 +00:00
|
|
|
|
recordUndo(bv(), Undo::ATOMIC);
|
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
|
2003-06-18 17:43:49 +00:00
|
|
|
|
string::const_iterator cit = str.begin();
|
|
|
|
|
string::const_iterator end = str.end();
|
|
|
|
|
for (; cit != 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-07-25 19:18:43 +00:00
|
|
|
|
recordUndo(bv(), Undo::ATOMIC);
|
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-16 08:12:22 +00:00
|
|
|
|
bv()->buffer()->insertStringAsLines(pit, pos, current_font, str);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2003-08-01 11:22:13 +00:00
|
|
|
|
redoParagraphs(cursor.par(), 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;
|
2003-06-18 17:43:49 +00:00
|
|
|
|
string::size_type const siz = linestr.length();
|
|
|
|
|
|
|
|
|
|
for (string::size_type i = 0; i < siz; ++i) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
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-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-08-11 09:09:01 +00:00
|
|
|
|
void LyXText::redoCursor()
|
|
|
|
|
{
|
|
|
|
|
#warning maybe the same for selections?
|
|
|
|
|
setCursor(cursor, cursor.par(), cursor.pos(), cursor.boundary());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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-06-30 23:56:22 +00:00
|
|
|
|
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);
|
2003-08-15 08:03:54 +00:00
|
|
|
|
if (noRows())
|
2003-07-17 06:45:39 +00:00
|
|
|
|
return;
|
2000-04-19 14:42:19 +00:00
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// get the cursor y position in text
|
2003-08-25 10:24:26 +00:00
|
|
|
|
|
|
|
|
|
RowList::iterator row = getRow(pit, pos);
|
|
|
|
|
int y = row->y();
|
2003-08-28 07:41:31 +00:00
|
|
|
|
|
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-09-02 17:08:54 +00:00
|
|
|
|
pos_type last = lastPrintablePos(*pit, 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-08-15 12:09:25 +00:00
|
|
|
|
lyxerr << "dont like 1, pos: " << pos << " size: " << pit->size() << 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-08-14 08:34:13 +00:00
|
|
|
|
float x = getCursorX(pit, row, pos, last, boundary);
|
2002-04-12 15:59:03 +00:00
|
|
|
|
cur.x(int(x));
|
|
|
|
|
cur.x_fix(cur.x());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-14 08:34:13 +00:00
|
|
|
|
float LyXText::getCursorX(ParagraphList::iterator pit, 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
|
|
|
|
{
|
2003-08-22 09:40:56 +00:00
|
|
|
|
pos_type cursor_vpos = 0;
|
|
|
|
|
double x = rit->x();
|
|
|
|
|
double fill_separator = rit->fill_separator();
|
|
|
|
|
double fill_hfill = rit->fill_hfill();
|
|
|
|
|
double fill_label_hfill = rit->fill_label_hfill();
|
|
|
|
|
pos_type const rit_pos = rit->pos();
|
2003-04-13 22:24:28 +00:00
|
|
|
|
|
|
|
|
|
if (last < rit_pos)
|
|
|
|
|
cursor_vpos = rit_pos;
|
2000-05-30 19:31:11 +00:00
|
|
|
|
else if (pos > last && !boundary)
|
2003-08-14 08:34:13 +00:00
|
|
|
|
cursor_vpos = (pit->isRightToLeftPar(bv()->buffer()->params))
|
2003-04-13 22:24:28 +00:00
|
|
|
|
? rit_pos : last + 1;
|
|
|
|
|
else if (pos > rit_pos && (pos > last || boundary))
|
2003-08-11 09:09:01 +00:00
|
|
|
|
// Place cursor after char at (logical) position pos - 1
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cursor_vpos = (bidi_level(pos - 1) % 2 == 0)
|
|
|
|
|
? log2vis(pos - 1) + 1 : log2vis(pos - 1);
|
2000-04-19 14:42:19 +00:00
|
|
|
|
else
|
2003-08-11 09:09:01 +00:00
|
|
|
|
// 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-08-14 08:34:13 +00:00
|
|
|
|
pos_type body_pos = pit->beginningOfBody();
|
2003-07-28 12:20:42 +00:00
|
|
|
|
if (body_pos > 0 &&
|
2003-08-14 08:34:13 +00:00
|
|
|
|
(body_pos - 1 > last || !pit->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-08-14 08:34:13 +00:00
|
|
|
|
pit->layout()->labelsep, getLabelFont(pit));
|
|
|
|
|
if (pit->isLineSeparator(body_pos - 1))
|
|
|
|
|
x -= singleWidth(pit, body_pos - 1);
|
2000-09-23 04:57:18 +00:00
|
|
|
|
}
|
2003-04-01 16:55:48 +00:00
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
|
if (hfillExpansion(*pit, rit, pos)) {
|
2003-08-14 08:34:13 +00:00
|
|
|
|
x += singleWidth(pit, 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-08-14 08:34:13 +00:00
|
|
|
|
} else if (pit->isSeparator(pos)) {
|
|
|
|
|
x += singleWidth(pit, 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-08-14 08:34:13 +00:00
|
|
|
|
x += singleWidth(pit, 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
|
|
|
|
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)) {
|
2003-06-27 08:38:41 +00:00
|
|
|
|
if (pos > cursorRow()->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
|
|
|
|
|
2003-07-27 21:59:06 +00:00
|
|
|
|
current_font = pit->getFontSettings(bv()->buffer()->params, pos);
|
|
|
|
|
real_current_font = getFont(pit, pos);
|
2000-07-10 10:31:34 +00:00
|
|
|
|
|
2003-04-13 22:24:28 +00:00
|
|
|
|
if (cursor.pos() == pit->size() &&
|
2003-08-28 07:41:31 +00:00
|
|
|
|
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
|
2003-08-14 08:34:13 +00:00
|
|
|
|
pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
|
|
|
|
|
RowList::iterator rit, int & x, bool & boundary) const
|
2003-03-10 05:03:33 +00:00
|
|
|
|
{
|
2003-08-22 09:40:56 +00:00
|
|
|
|
double tmpx = rit->x();
|
|
|
|
|
double fill_separator = rit->fill_separator();
|
|
|
|
|
double fill_hfill = rit->fill_hfill();
|
|
|
|
|
double fill_label_hfill = rit->fill_label_hfill();
|
2003-03-10 05:03:33 +00:00
|
|
|
|
|
2003-03-30 21:42:09 +00:00
|
|
|
|
pos_type vc = rit->pos();
|
2003-08-15 08:03:54 +00:00
|
|
|
|
pos_type last = lastPrintablePos(*pit, rit);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
pos_type c = 0;
|
2003-08-14 08:34:13 +00:00
|
|
|
|
LyXLayout_ptr const & layout = pit->layout();
|
2003-03-10 05:03:33 +00:00
|
|
|
|
|
|
|
|
|
bool left_side = false;
|
|
|
|
|
|
2003-08-14 08:34:13 +00:00
|
|
|
|
pos_type body_pos = pit->beginningOfBody();
|
2003-07-28 12:20:42 +00:00
|
|
|
|
double last_tmpx = tmpx;
|
2003-03-10 05:03:33 +00:00
|
|
|
|
|
|
|
|
|
if (body_pos > 0 &&
|
|
|
|
|
(body_pos - 1 > last ||
|
2003-08-14 08:34:13 +00:00
|
|
|
|
!pit->isLineSeparator(body_pos - 1)))
|
2003-03-10 05:03:33 +00:00
|
|
|
|
body_pos = 0;
|
|
|
|
|
|
|
|
|
|
// check for empty row
|
2003-08-14 08:34:13 +00:00
|
|
|
|
if (!pit->size()) {
|
2003-07-28 18:40:05 +00:00
|
|
|
|
x = int(tmpx);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
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 +
|
2003-08-14 08:34:13 +00:00
|
|
|
|
font_metrics::width(layout->labelsep, getLabelFont(pit));
|
|
|
|
|
if (pit->isLineSeparator(body_pos - 1))
|
|
|
|
|
tmpx -= singleWidth(pit, body_pos - 1);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
|
if (hfillExpansion(*pit, rit, c)) {
|
2003-08-14 08:34:13 +00:00
|
|
|
|
tmpx += singleWidth(pit, c);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
if (c >= body_pos)
|
|
|
|
|
tmpx += fill_hfill;
|
|
|
|
|
else
|
|
|
|
|
tmpx += fill_label_hfill;
|
2003-08-14 08:34:13 +00:00
|
|
|
|
} else if (pit->isSeparator(c)) {
|
|
|
|
|
tmpx += singleWidth(pit, c);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
if (c >= body_pos)
|
2003-07-21 11:01:29 +00:00
|
|
|
|
tmpx += fill_separator;
|
2003-03-10 05:03:33 +00:00
|
|
|
|
} else {
|
2003-08-14 08:34:13 +00:00
|
|
|
|
tmpx += singleWidth(pit, 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
|
2003-08-14 11:16:31 +00:00
|
|
|
|
// some speedup if rtl_support == false
|
|
|
|
|
bool const lastrow = lyxrc.rtl_support
|
2003-08-15 08:03:54 +00:00
|
|
|
|
&& boost::next(rit) == pit->rows.end();
|
2003-06-18 17:43:49 +00:00
|
|
|
|
|
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-08-14 08:34:13 +00:00
|
|
|
|
? pit->isRightToLeftPar(bv()->buffer()->params)
|
2003-03-31 16:57:45 +00:00
|
|
|
|
: false;
|
2003-03-10 05:03:33 +00:00
|
|
|
|
if (lastrow &&
|
2003-08-14 11:16:31 +00:00
|
|
|
|
((rtl && left_side && vc == rit->pos() && x < tmpx - 5) ||
|
|
|
|
|
(!rtl && !left_side && vc == last + 1 && x > tmpx + 5)))
|
2003-03-10 05:03:33 +00:00
|
|
|
|
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-08-28 07:41:31 +00:00
|
|
|
|
boundary = isBoundary(*bv()->buffer(), *pit, c);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-08-14 08:34:13 +00:00
|
|
|
|
if (rit->pos() <= last && c > last && pit->isNewline(last)) {
|
2003-03-10 05:03:33 +00:00
|
|
|
|
if (bidi_level(last) % 2 == 0)
|
2003-08-14 08:34:13 +00:00
|
|
|
|
tmpx -= singleWidth(pit, last);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
else
|
2003-08-14 08:34:13 +00:00
|
|
|
|
tmpx += singleWidth(pit, 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
|
|
|
|
{
|
2003-08-15 13:20:45 +00:00
|
|
|
|
LyXCursor old_cursor = cursor;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursorFromCoordinates(cursor, x, y);
|
|
|
|
|
setCurrentFont();
|
2003-08-15 13:20:45 +00:00
|
|
|
|
deleteEmptyParagraphMechanism(old_cursor);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-08 23:16:16 +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.
|
2003-08-15 08:03:54 +00:00
|
|
|
|
ParagraphList::iterator pit;
|
2003-08-22 07:49:57 +00:00
|
|
|
|
RowList::iterator rit = getRowNearY(y, pit);
|
2003-08-25 10:24:26 +00:00
|
|
|
|
y = rit->y();
|
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
bool bound = false;
|
2003-08-22 07:49:57 +00:00
|
|
|
|
pos_type const column = getColumnNearX(pit, rit, x, bound);
|
2003-08-14 08:34:13 +00:00
|
|
|
|
cur.par(pit);
|
2003-08-22 07:49:57 +00:00
|
|
|
|
cur.pos(rit->pos() + column);
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cur.x(x);
|
2003-08-22 07:49:57 +00:00
|
|
|
|
cur.y(y + rit->baseline());
|
|
|
|
|
|
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-08-28 07:41:31 +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-08-01 14:12:04 +00:00
|
|
|
|
} else if (cursor.par() != ownerParagraphs().begin()) {
|
|
|
|
|
// steps into the paragraph above
|
2003-04-13 01:04:04 +00:00
|
|
|
|
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-08-28 07:41:31 +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();
|
2003-06-27 08:38:41 +00:00
|
|
|
|
int y = cursor.y() - cursorRow()->baseline() - 1;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursorFromCoordinates(x, y);
|
2002-04-17 08:34:59 +00:00
|
|
|
|
if (!selecting) {
|
2003-08-27 14:55:20 +00:00
|
|
|
|
int topy = bv_owner->top_y();
|
2003-09-02 17:08:54 +00:00
|
|
|
|
int y1 = cursor.y() - topy;
|
2002-04-17 08:34:59 +00:00
|
|
|
|
int y2 = y1;
|
2003-03-06 20:21:21 +00:00
|
|
|
|
y -= topy;
|
2003-07-25 21:20:24 +00:00
|
|
|
|
InsetOld * inset_hit = checkInsetHit(x, y1);
|
2002-04-17 08:34:59 +00:00
|
|
|
|
if (inset_hit && isHighlyEditableInset(inset_hit)) {
|
2003-05-16 07:44:00 +00:00
|
|
|
|
inset_hit->localDispatch(
|
|
|
|
|
FuncRequest(bv(), LFUN_INSET_EDIT, 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-08-15 08:03:54 +00:00
|
|
|
|
lyxerr << "cursorUp: y " << cursor.y() << " bl: " <<
|
|
|
|
|
cursorRow()->baseline() << endl;
|
2003-08-14 14:10:13 +00:00
|
|
|
|
setCursorFromCoordinates(cursor.x_fix(),
|
2003-08-15 08:03:54 +00:00
|
|
|
|
cursor.y() - cursorRow()->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();
|
2003-07-15 16:25:02 +00:00
|
|
|
|
int y = cursor.y() - cursorRow()->baseline() + cursorRow()->height() + 1;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursorFromCoordinates(x, y);
|
2003-07-16 08:42:26 +00:00
|
|
|
|
if (!selecting && cursorRow() == cursorIRow()) {
|
2003-08-27 14:55:20 +00:00
|
|
|
|
int topy = bv_owner->top_y();
|
2003-09-02 17:08:54 +00:00
|
|
|
|
int y1 = cursor.y() - topy;
|
2002-04-17 08:34:59 +00:00
|
|
|
|
int y2 = y1;
|
2003-03-06 20:21:21 +00:00
|
|
|
|
y -= topy;
|
2003-07-25 21:20:24 +00:00
|
|
|
|
InsetOld * inset_hit = checkInsetHit(x, y1);
|
2002-04-17 08:34:59 +00:00
|
|
|
|
if (inset_hit && isHighlyEditableInset(inset_hit)) {
|
2003-05-16 07:44:00 +00:00
|
|
|
|
FuncRequest cmd(bv(), LFUN_INSET_EDIT, x, y - (y2 - y1), mouse_button::none);
|
|
|
|
|
inset_hit->localDispatch(cmd);
|
2002-04-17 08:34:59 +00:00
|
|
|
|
}
|
2002-04-16 14:10:39 +00:00
|
|
|
|
}
|
|
|
|
|
#else
|
2003-08-14 14:10:13 +00:00
|
|
|
|
setCursorFromCoordinates(cursor.x_fix(),
|
|
|
|
|
cursor.y() - cursorRow()->baseline() + cursorRow()->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
|
|
|
|
{
|
2003-08-01 14:12:04 +00:00
|
|
|
|
if (cursor.pos() > 0)
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursor(cursor.par(), 0);
|
2003-08-01 14:12:04 +00:00
|
|
|
|
else if (cursor.par() != ownerParagraphs().begin())
|
2003-04-13 01:04:04 +00:00
|
|
|
|
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-06-18 17:43:49 +00:00
|
|
|
|
ParagraphList::iterator par = cursor.par();
|
|
|
|
|
ParagraphList::iterator next_par = boost::next(par);
|
|
|
|
|
|
2003-08-01 14:12:04 +00:00
|
|
|
|
if (next_par != ownerParagraphs().end())
|
2003-06-18 17:43:49 +00:00
|
|
|
|
setCursor(next_par, 0);
|
2003-08-01 14:12:04 +00:00
|
|
|
|
else
|
2003-06-18 17:43:49 +00:00
|
|
|
|
setCursor(par, par->size());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-08-01 14:12:04 +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-08-11 09:09:01 +00:00
|
|
|
|
void LyXText::fixCursorAfterDelete(LyXCursor & cur, 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.
|
2003-08-11 09:09:01 +00:00
|
|
|
|
if (old_cursor.par()->isFreeSpacing())
|
2002-01-12 21:03:30 +00:00
|
|
|
|
return false;
|
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
|
2003-08-22 07:49:57 +00:00
|
|
|
|
the cursor between to spaces and then save. Or if you
|
2000-01-13 16:28:54 +00:00
|
|
|
|
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()) {
|
|
|
|
|
|
2003-08-11 09:09:01 +00:00
|
|
|
|
// Only if the cursor has really moved
|
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)) {
|
2003-08-05 22:00:04 +00:00
|
|
|
|
bool erased = old_cursor.par()->erase(old_cursor.pos() - 1);
|
2003-08-01 11:22:13 +00:00
|
|
|
|
redoParagraph(old_cursor.par());
|
2001-09-27 09:52:06 +00:00
|
|
|
|
|
2003-08-05 22:00:04 +00:00
|
|
|
|
if (!erased)
|
|
|
|
|
return false;
|
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);
|
2003-07-28 21:22:42 +00:00
|
|
|
|
fixCursorAfterDelete(selection.cursor, old_cursor);
|
|
|
|
|
fixCursorAfterDelete(selection.start, old_cursor);
|
2003-03-17 16:25:00 +00:00
|
|
|
|
fixCursorAfterDelete(selection.end, 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.
|
2003-06-07 17:45:43 +00:00
|
|
|
|
if (old_cursor.par()->allowEmpty())
|
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))) {
|
2003-08-22 07:49:57 +00:00
|
|
|
|
// ok, we will delete something
|
2001-09-27 10:52:53 +00:00
|
|
|
|
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-08-15 08:03:54 +00:00
|
|
|
|
tmpcursor = cursor;
|
|
|
|
|
cursor = old_cursor; // that undo can restore the right cursor position
|
2001-07-07 18:19:18 +00:00
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
|
ParagraphList::iterator endpit = boost::next(old_cursor.par());
|
|
|
|
|
while (endpit != ownerParagraphs().end() && endpit->getDepth())
|
|
|
|
|
++endpit;
|
2003-08-28 07:41:31 +00:00
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
|
recordUndo(bv(), Undo::DELETE, old_cursor.par(), boost::prior(endpit));
|
|
|
|
|
cursor = tmpcursor;
|
2001-09-27 10:52:53 +00:00
|
|
|
|
|
2003-08-15 08:03:54 +00:00
|
|
|
|
// delete old par
|
|
|
|
|
ownerParagraphs().erase(old_cursor.par());
|
|
|
|
|
redoParagraph();
|
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-08-01 11:22:13 +00:00
|
|
|
|
redoParagraph(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
|
|
|
|
{
|
2003-08-15 14:54:19 +00:00
|
|
|
|
return paragraphs_;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-26 17:04:10 +00:00
|
|
|
|
bool LyXText::isInInset() const
|
|
|
|
|
{
|
2003-08-11 09:09:01 +00:00
|
|
|
|
// Sub-level has non-null bv owner and non-null inset owner.
|
2003-08-15 14:54:19 +00:00
|
|
|
|
return inset_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);
|
|
|
|
|
}
|