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"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "buffer.h"
|
2003-06-24 20:42:15 +00:00
|
|
|
|
#include "buffer_funcs.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
#include "bufferparams.h"
|
1999-12-19 22:35:36 +00:00
|
|
|
|
#include "BufferView.h"
|
2003-09-12 17:13:22 +00:00
|
|
|
|
#include "Bullet.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "counters.h"
|
2003-11-04 12:36:59 +00:00
|
|
|
|
#include "cursor.h"
|
2000-04-10 14:29:05 +00:00
|
|
|
|
#include "CutAndPaste.h"
|
2000-04-08 17:02:02 +00:00
|
|
|
|
#include "debug.h"
|
2003-10-29 10:47:21 +00:00
|
|
|
|
#include "dispatchresult.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "errorlist.h"
|
2003-09-04 03:54:04 +00:00
|
|
|
|
#include "Floating.h"
|
2000-07-18 17:45:27 +00:00
|
|
|
|
#include "FloatList.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "funcrequest.h"
|
|
|
|
|
#include "gettext.h"
|
2001-04-05 12:26:41 +00:00
|
|
|
|
#include "language.h"
|
2003-12-01 13:35:49 +00:00
|
|
|
|
#include "LColor.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "lyxrc.h"
|
2003-09-06 12:36:58 +00:00
|
|
|
|
#include "lyxrow.h"
|
2003-04-01 16:55:48 +00:00
|
|
|
|
#include "lyxrow_funcs.h"
|
2003-09-16 12:12:33 +00:00
|
|
|
|
#include "paragraph.h"
|
2003-04-14 18:35:29 +00:00
|
|
|
|
#include "paragraph_funcs.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "ParagraphParameters.h"
|
2003-11-27 09:22:41 +00:00
|
|
|
|
#include "PosIterator.h"
|
2003-10-14 13:01:49 +00:00
|
|
|
|
#include "undo.h"
|
2003-09-09 17:00:19 +00:00
|
|
|
|
#include "vspace.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
|
|
|
|
|
#include "frontends/font_metrics.h"
|
|
|
|
|
#include "frontends/LyXView.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
|
|
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "support/textutils.h"
|
2003-09-12 17:13:22 +00:00
|
|
|
|
#include "support/tostr.h"
|
|
|
|
|
#include "support/std_sstream.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-09-09 22:13:45 +00:00
|
|
|
|
using lyx::pos_type;
|
2003-10-09 10:52:12 +00:00
|
|
|
|
using lyx::paroffset_type;
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::bformat;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
|
using std::endl;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
using std::ostringstream;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
|
2000-07-21 18:47:54 +00:00
|
|
|
|
|
2003-12-01 13:35:49 +00:00
|
|
|
|
LyXText::LyXText(BufferView * bv, bool in_inset)
|
2003-11-25 11:17:27 +00:00
|
|
|
|
: height(0), width(0), textwidth_(bv ? bv->workWidth() : 100),
|
2003-12-01 13:35:49 +00:00
|
|
|
|
background_color_(LColor::background),
|
|
|
|
|
bv_owner(bv), in_inset_(in_inset), xo_(0), yo_(0)
|
2003-11-10 09:06:48 +00:00
|
|
|
|
{}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-03-02 16:39:54 +00:00
|
|
|
|
|
2004-02-02 16:38:13 +00:00
|
|
|
|
void LyXText::init(BufferView * bv)
|
2000-06-12 11:27:15 +00:00
|
|
|
|
{
|
2004-02-02 16:38:13 +00:00
|
|
|
|
bv_owner = bv;
|
2003-07-15 08:26:17 +00:00
|
|
|
|
|
2003-12-01 13:35:49 +00:00
|
|
|
|
ParagraphList::iterator const beg = paragraphs().begin();
|
|
|
|
|
ParagraphList::iterator const end = paragraphs().end();
|
2003-08-15 08:03:54 +00:00
|
|
|
|
for (ParagraphList::iterator pit = beg; pit != end; ++pit)
|
|
|
|
|
pit->rows.clear();
|
|
|
|
|
|
2003-08-07 10:00:33 +00:00
|
|
|
|
width = 0;
|
|
|
|
|
height = 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);
|
2004-02-02 16:38:13 +00:00
|
|
|
|
bv->cursor().resetAnchor();
|
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-09-09 17:25:35 +00:00
|
|
|
|
BOOST_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?
|
2003-09-09 09:47:59 +00:00
|
|
|
|
BufferParams const & params = bv()->buffer()->params();
|
2003-11-13 13:43:44 +00:00
|
|
|
|
pos_type const body_pos = pit->beginOfBody();
|
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()) {
|
2003-10-21 16:15:14 +00:00
|
|
|
|
LyXFont f = pit->getFontSettings(params, pos);
|
2003-12-03 18:17:20 +00:00
|
|
|
|
if (in_inset_)
|
|
|
|
|
f.realize(font_);
|
2003-10-21 16:15:14 +00:00
|
|
|
|
if (layout->labeltype == LABEL_MANUAL && pos < body_pos)
|
2002-06-24 20:28:12 +00:00
|
|
|
|
return f.realize(layout->reslabelfont);
|
2003-10-21 16:15:14 +00:00
|
|
|
|
else
|
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
|
2001-08-03 18:28:11 +00:00
|
|
|
|
LyXFont layoutfont;
|
2003-10-21 16:15:14 +00:00
|
|
|
|
if (pos < body_pos)
|
2002-06-24 20:28:12 +00:00
|
|
|
|
layoutfont = layout->labelfont;
|
2003-10-21 16:15:14 +00:00
|
|
|
|
else
|
2002-06-24 20:28:12 +00:00
|
|
|
|
layoutfont = layout->font;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-10-21 16:15:14 +00:00
|
|
|
|
LyXFont font = pit->getFontSettings(params, pos);
|
|
|
|
|
font.realize(layoutfont);
|
2002-09-06 15:18:11 +00:00
|
|
|
|
|
2003-12-03 18:17:20 +00:00
|
|
|
|
if (in_inset_)
|
|
|
|
|
font.realize(font_);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-15 00:11:03 +00:00
|
|
|
|
// Realize with the fonts of lesser depth.
|
2003-12-01 13:35:49 +00:00
|
|
|
|
//font.realize(outerFont(pit, paragraphs()));
|
2003-10-21 16:15:14 +00:00
|
|
|
|
font.realize(defaultfont_);
|
2003-04-15 00:11:03 +00:00
|
|
|
|
|
2003-10-21 16:15:14 +00:00
|
|
|
|
return font;
|
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-12-01 13:35:49 +00:00
|
|
|
|
//font.realize(outerFont(pit, paragraphs()));
|
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-12-01 13:35:49 +00:00
|
|
|
|
font.realize(outerFont(pit, paragraphs()));
|
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-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-11-13 13:43:44 +00:00
|
|
|
|
if (pos < pit->beginOfBody())
|
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() &&
|
2003-12-01 13:35:49 +00:00
|
|
|
|
tp != paragraphs().end() &&
|
2003-04-16 08:12:22 +00:00
|
|
|
|
tp->getDepth()) {
|
2003-12-01 13:35:49 +00:00
|
|
|
|
tp = outerHook(tp, paragraphs());
|
|
|
|
|
if (tp != paragraphs().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-11-22 14:44:59 +00:00
|
|
|
|
// used in setLayout
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// 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-11-13 13:43:44 +00:00
|
|
|
|
if (pos < par.beginOfBody())
|
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
|
|
|
|
|
2004-01-09 09:04:33 +00:00
|
|
|
|
// return past-the-last paragraph influenced by a layout change on pit
|
2004-01-30 11:41:12 +00:00
|
|
|
|
ParagraphList::iterator LyXText::undoSpan(ParagraphList::iterator pit)
|
2004-01-09 09:04:33 +00:00
|
|
|
|
{
|
|
|
|
|
ParagraphList::iterator end = paragraphs().end();
|
|
|
|
|
ParagraphList::iterator nextpit = boost::next(pit);
|
|
|
|
|
if (nextpit == end)
|
|
|
|
|
return nextpit;
|
|
|
|
|
//because of parindents
|
|
|
|
|
if (!pit->getDepth())
|
|
|
|
|
return boost::next(nextpit);
|
|
|
|
|
//because of depth constrains
|
|
|
|
|
for (; nextpit != end; ++pit, ++nextpit) {
|
|
|
|
|
if (!pit->getDepth())
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return nextpit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-04-10 21:07:55 +00:00
|
|
|
|
ParagraphList::iterator
|
2003-12-08 12:47:18 +00:00
|
|
|
|
LyXText::setLayout(ParagraphList::iterator start,
|
|
|
|
|
ParagraphList::iterator end,
|
2003-04-10 21:07:55 +00:00
|
|
|
|
string const & layout)
|
2001-04-04 21:47:26 +00:00
|
|
|
|
{
|
2004-01-09 09:04:33 +00:00
|
|
|
|
BOOST_ASSERT(start != end);
|
|
|
|
|
ParagraphList::iterator undopit = undoSpan(boost::prior(end));
|
2003-12-08 12:47:18 +00:00
|
|
|
|
recUndo(parOffset(start), parOffset(undopit) - 1);
|
2002-03-02 16:39:54 +00:00
|
|
|
|
|
2003-09-09 09:47:59 +00:00
|
|
|
|
BufferParams const & bufparams = bv()->buffer()->params();
|
2002-06-24 20:28:12 +00:00
|
|
|
|
LyXLayout_ptr const & lyxlayout =
|
2003-09-09 09:47:59 +00:00
|
|
|
|
bufparams.getLyXTextClass()[layout];
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-12-08 12:47:18 +00:00
|
|
|
|
for (ParagraphList::iterator pit = start; pit != end; ++pit) {
|
2003-04-09 09:15:20 +00:00
|
|
|
|
pit->applyLayout(lyxlayout);
|
2003-09-09 09:47:59 +00:00
|
|
|
|
makeFontEntriesLayoutSpecific(bufparams, *pit);
|
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());
|
2003-12-08 12:47:18 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-12-08 12:47:18 +00:00
|
|
|
|
return undopit;
|
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-19 07:12:09 +00:00
|
|
|
|
// special handling of new environment insets
|
2003-09-09 09:47:59 +00:00
|
|
|
|
BufferParams const & params = bv()->buffer()->params();
|
2003-05-19 07:12:09 +00:00
|
|
|
|
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));
|
2004-01-26 10:13:15 +00:00
|
|
|
|
InsetBase * inset = new InsetEnvironment(params, layout);
|
2004-02-04 11:23:25 +00:00
|
|
|
|
insertInset(inset);
|
2004-02-04 09:44:12 +00:00
|
|
|
|
//inset->edit(bv());
|
|
|
|
|
//bv()->owner()->dispatch(FuncRequest(LFUN_PASTE));
|
2003-05-19 07:12:09 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
ParagraphList::iterator start =
|
2004-01-26 10:13:15 +00:00
|
|
|
|
getPar(bv()->cursor().selBegin().par());
|
2004-01-20 14:25:24 +00:00
|
|
|
|
ParagraphList::iterator end =
|
|
|
|
|
boost::next(getPar(bv()->cursor().selEnd().par()));
|
2003-12-08 12:47:18 +00:00
|
|
|
|
ParagraphList::iterator endpit = setLayout(start, end, layout);
|
|
|
|
|
|
|
|
|
|
redoParagraphs(start, endpit);
|
2003-03-17 16:25:00 +00:00
|
|
|
|
updateCounters();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-26 09:48:21 +00:00
|
|
|
|
namespace {
|
2003-04-02 17:59:01 +00:00
|
|
|
|
|
2003-11-26 09:48:21 +00:00
|
|
|
|
|
|
|
|
|
void getSelectionSpan(LyXText & text,
|
|
|
|
|
ParagraphList::iterator & beg,
|
|
|
|
|
ParagraphList::iterator & end)
|
|
|
|
|
{
|
2004-01-20 14:25:24 +00:00
|
|
|
|
if (!text.bv()->cursor().selection()) {
|
2003-11-26 09:48:21 +00:00
|
|
|
|
beg = text.cursorPar();
|
|
|
|
|
end = boost::next(beg);
|
|
|
|
|
} else {
|
2004-01-26 10:13:15 +00:00
|
|
|
|
beg = text.getPar(text.bv()->cursor().selBegin());
|
2004-01-20 14:25:24 +00:00
|
|
|
|
end = boost::next(text.getPar(text.bv()->cursor().selEnd()));
|
2001-05-31 02:23:46 +00:00
|
|
|
|
}
|
2003-11-26 09:48:21 +00:00
|
|
|
|
}
|
2001-05-31 02:23:46 +00:00
|
|
|
|
|
|
|
|
|
|
2003-11-26 09:48:21 +00:00
|
|
|
|
bool changeDepthAllowed(bv_funcs::DEPTH_CHANGE type,
|
|
|
|
|
Paragraph const & par,
|
|
|
|
|
int max_depth)
|
|
|
|
|
{
|
|
|
|
|
if (par.layout()->labeltype == LABEL_BIBLIO)
|
|
|
|
|
return false;
|
|
|
|
|
int const depth = par.params().depth();
|
|
|
|
|
if (type == bv_funcs::INC_DEPTH && depth < max_depth)
|
|
|
|
|
return true;
|
|
|
|
|
if (type == bv_funcs::DEC_DEPTH && depth > 0)
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2003-04-03 01:26:02 +00:00
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
|
2003-11-26 09:48:21 +00:00
|
|
|
|
}
|
2001-05-31 02:23:46 +00:00
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-26 09:48:21 +00:00
|
|
|
|
bool LyXText::changeDepthAllowed(bv_funcs::DEPTH_CHANGE type)
|
|
|
|
|
{
|
|
|
|
|
ParagraphList::iterator beg, end;
|
|
|
|
|
getSelectionSpan(*this, beg, end);
|
|
|
|
|
int max_depth = 0;
|
2003-12-01 13:35:49 +00:00
|
|
|
|
if (beg != paragraphs().begin())
|
2003-11-26 09:48:21 +00:00
|
|
|
|
max_depth = boost::prior(beg)->getMaxDepthAfter();
|
2003-04-02 21:19:35 +00:00
|
|
|
|
|
2003-11-26 09:48:21 +00:00
|
|
|
|
for (ParagraphList::iterator pit = beg; pit != end; ++pit) {
|
|
|
|
|
if (::changeDepthAllowed(type, *pit, max_depth))
|
|
|
|
|
return true;
|
|
|
|
|
max_depth = pit->getMaxDepthAfter();
|
2001-05-31 02:23:46 +00:00
|
|
|
|
}
|
2003-11-26 09:48:21 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-03 01:26:02 +00:00
|
|
|
|
|
2003-11-26 09:48:21 +00:00
|
|
|
|
void LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type)
|
|
|
|
|
{
|
|
|
|
|
ParagraphList::iterator beg, end;
|
|
|
|
|
getSelectionSpan(*this, beg, end);
|
|
|
|
|
|
|
|
|
|
recUndo(parOffset(beg), parOffset(end) - 1);
|
2003-04-02 17:59:01 +00:00
|
|
|
|
|
2003-11-26 09:48:21 +00:00
|
|
|
|
int max_depth = 0;
|
2003-12-01 13:35:49 +00:00
|
|
|
|
if (beg != paragraphs().begin())
|
2003-11-26 09:48:21 +00:00
|
|
|
|
max_depth = boost::prior(beg)->getMaxDepthAfter();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-26 09:48:21 +00:00
|
|
|
|
for (ParagraphList::iterator pit = beg; pit != end; ++pit) {
|
|
|
|
|
if (::changeDepthAllowed(type, *pit, max_depth)) {
|
|
|
|
|
int const depth = pit->params().depth();
|
|
|
|
|
if (type == bv_funcs::INC_DEPTH)
|
|
|
|
|
pit->params().depth(depth + 1);
|
|
|
|
|
else
|
|
|
|
|
pit->params().depth(depth - 1);
|
|
|
|
|
}
|
|
|
|
|
max_depth = pit->getMaxDepthAfter();
|
2003-04-02 17:59:01 +00:00
|
|
|
|
}
|
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();
|
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
|
|
|
|
{
|
2004-01-20 14:25:24 +00:00
|
|
|
|
LCursor & cur = bv()->cursor();
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// if there is no selection just set the current_font
|
2004-01-20 14:25:24 +00:00
|
|
|
|
if (!cur.selection()) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Determine basis font
|
|
|
|
|
LyXFont layoutfont;
|
2004-01-13 10:37:38 +00:00
|
|
|
|
if (cursor().pos() < cursorPar()->beginOfBody())
|
2003-10-09 10:52:12 +00:00
|
|
|
|
layoutfont = getLabelFont(cursorPar());
|
2003-12-08 12:47:18 +00:00
|
|
|
|
else
|
2003-10-09 10:52:12 +00:00
|
|
|
|
layoutfont = getLayoutFont(cursorPar());
|
2003-12-08 12:47:18 +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-09-09 09:47:59 +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;
|
|
|
|
|
}
|
|
|
|
|
|
2003-11-27 09:22:41 +00:00
|
|
|
|
// ok we have a selection.
|
2004-01-26 10:13:15 +00:00
|
|
|
|
recUndo(cur.selBegin().par(), cur.selEnd().par());
|
2001-06-25 00:06:33 +00:00
|
|
|
|
freezeUndo();
|
2003-11-27 09:22:41 +00:00
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
ParagraphList::iterator beg = getPar(cur.selBegin().par());
|
2004-01-20 14:25:24 +00:00
|
|
|
|
ParagraphList::iterator end = getPar(cur.selEnd().par());
|
2003-11-27 09:22:41 +00:00
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
PosIterator pos(¶graphs(), beg, cur.selBegin().pos());
|
2004-01-20 14:25:24 +00:00
|
|
|
|
PosIterator posend(¶graphs(), end, cur.selEnd().pos());
|
2003-11-27 09:22:41 +00:00
|
|
|
|
|
|
|
|
|
BufferParams const & params = bv()->buffer()->params();
|
|
|
|
|
|
|
|
|
|
for (; pos != posend; ++pos) {
|
|
|
|
|
LyXFont f = getFont(pos.pit(), pos.pos());
|
|
|
|
|
f.update(font, params.language, toggleall);
|
|
|
|
|
setCharFont(pos.pit(), pos.pos(), f);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2003-11-27 09:22:41 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
unFreezeUndo();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-27 09:22:41 +00:00
|
|
|
|
redoParagraphs(beg, ++end);
|
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
|
2004-01-13 15:25:52 +00:00
|
|
|
|
// realize you left an empty paragraph, they will delete it.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
void LyXText::cursorHome(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-12 16:36:01 +00:00
|
|
|
|
setCursor(cur.par(), cur.textRow().pos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
void LyXText::cursorEnd(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-11-10 09:06:48 +00:00
|
|
|
|
// if not on the last row of the par, put the cursor before
|
|
|
|
|
// the final space
|
2004-02-12 16:36:01 +00:00
|
|
|
|
pos_type const end = cur.textRow().endpos();
|
|
|
|
|
setCursor(cur.par(), end == cur.lastpos() ? end : end - 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
void LyXText::cursorTop(LCursor &)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-12 16:36:01 +00:00
|
|
|
|
setCursor(0, 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
void LyXText::cursorBottom(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-12 16:36:01 +00:00
|
|
|
|
setCursor(cur.lastpar(), boost::prior(paragraphs().end())->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-11-25 11:17:27 +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.
|
2004-01-13 14:13:51 +00:00
|
|
|
|
CursorSlice resetCursor = cursor();
|
2003-10-29 10:47:21 +00:00
|
|
|
|
bool implicitSelection =
|
2003-10-28 11:18:40 +00:00
|
|
|
|
font.language() == ignore_language
|
|
|
|
|
&& font.number() == LyXFont::IGNORE
|
|
|
|
|
&& selectWordWhenUnderCursor(lyx::WHOLE_WORD_STRICT);
|
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) {
|
2004-01-20 14:25:24 +00:00
|
|
|
|
bv()->cursor().clearSelection();
|
2004-01-13 10:37:38 +00:00
|
|
|
|
cursor() = resetCursor;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
bv()->cursor().resetAnchor();
|
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
|
|
|
|
{
|
2004-01-20 14:25:24 +00:00
|
|
|
|
LCursor & cur = bv()->cursor();
|
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.
|
2004-01-13 14:13:51 +00:00
|
|
|
|
CursorSlice 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;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
if (!cur.selection())
|
2003-03-17 16:25:00 +00:00
|
|
|
|
bv()->owner()->message(_("Nothing to index!"));
|
2004-01-26 10:13:15 +00:00
|
|
|
|
else if (cur.selBegin().par() != cur.selEnd().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
|
2004-02-11 14:45:44 +00:00
|
|
|
|
idxstring = cur.selectionAsString(false);
|
2001-07-30 10:50:37 +00:00
|
|
|
|
|
2003-01-31 13:50:21 +00:00
|
|
|
|
// Reset cursors to their original position.
|
2004-01-13 10:37:38 +00:00
|
|
|
|
cursor() = reset_cursor;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.resetAnchor();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-01-31 13:50:21 +00:00
|
|
|
|
// Clear the implicit selection.
|
|
|
|
|
if (implicitSelection)
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.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
|
|
|
|
|
2003-12-01 13:35:49 +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,
|
2003-11-10 09:06:48 +00:00
|
|
|
|
// they do not duplicate themself and you cannot play dirty tricks with
|
2002-05-29 13:28:11 +00:00
|
|
|
|
// them!
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-12-08 12:47:18 +00:00
|
|
|
|
void LyXText::setParagraph(Spacing const & spacing, LyXAlignment align,
|
|
|
|
|
string const & labelwidthstring, bool noindent)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-01-20 14:25:24 +00:00
|
|
|
|
LCursor & cur = bv()->cursor();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// make sure that the depth behind the selection are restored, too
|
2004-01-20 14:25:24 +00:00
|
|
|
|
ParagraphList::iterator undopit = undoSpan(getPar(cur.selEnd()));
|
2004-01-26 10:13:15 +00:00
|
|
|
|
recUndo(cur.selBegin().par(), parOffset(undopit) - 1);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
ParagraphList::reverse_iterator pit(getPar(cur.selEnd().par()));
|
2004-01-26 10:13:15 +00:00
|
|
|
|
ParagraphList::reverse_iterator beg(getPar(cur.selBegin().par()));
|
2003-04-13 22:24:28 +00:00
|
|
|
|
|
2003-12-20 00:24:31 +00:00
|
|
|
|
for (--pit; pit != beg; ++pit) {
|
2003-04-13 22:24:28 +00:00
|
|
|
|
ParagraphParameters & params = pit->params();
|
|
|
|
|
params.spacing(spacing);
|
2003-10-27 12:41:26 +00:00
|
|
|
|
|
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);
|
1999-11-04 01:40:20 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
redoParagraphs(getPar(cur.selBegin()), undopit);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-09-12 17:13:22 +00:00
|
|
|
|
string expandLabel(LyXTextClass const & textclass,
|
|
|
|
|
LyXLayout_ptr const & layout, bool appendix)
|
|
|
|
|
{
|
|
|
|
|
string fmt = appendix ?
|
|
|
|
|
layout->labelstring_appendix() : layout->labelstring();
|
|
|
|
|
|
|
|
|
|
// handle 'inherited level parts' in 'fmt',
|
|
|
|
|
// i.e. the stuff between '@' in '@Section@.\arabic{subsection}'
|
|
|
|
|
size_t const i = fmt.find('@', 0);
|
|
|
|
|
if (i != string::npos) {
|
|
|
|
|
size_t const j = fmt.find('@', i + 1);
|
|
|
|
|
if (j != string::npos) {
|
|
|
|
|
string parent(fmt, i + 1, j - i - 1);
|
|
|
|
|
string label = expandLabel(textclass, textclass[parent], appendix);
|
|
|
|
|
fmt = string(fmt, 0, i) + label + string(fmt, j + 1, string::npos);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return textclass.counters().counterLabel(fmt);
|
|
|
|
|
}
|
|
|
|
|
|
2003-10-08 17:44:32 +00:00
|
|
|
|
|
2003-11-25 17:23:36 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
2003-10-08 17:44:32 +00:00
|
|
|
|
void incrementItemDepth(ParagraphList::iterator pit,
|
|
|
|
|
ParagraphList::iterator first_pit)
|
|
|
|
|
{
|
|
|
|
|
int const cur_labeltype = pit->layout()->labeltype;
|
|
|
|
|
|
2003-11-25 11:17:27 +00:00
|
|
|
|
if (cur_labeltype != LABEL_ENUMERATE && cur_labeltype != LABEL_ITEMIZE)
|
2003-10-08 17:44:32 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int const cur_depth = pit->getDepth();
|
|
|
|
|
|
|
|
|
|
ParagraphList::iterator prev_pit = boost::prior(pit);
|
|
|
|
|
while (true) {
|
|
|
|
|
int const prev_depth = prev_pit->getDepth();
|
|
|
|
|
int const prev_labeltype = prev_pit->layout()->labeltype;
|
|
|
|
|
if (prev_depth == 0 && cur_depth > 0) {
|
|
|
|
|
if (prev_labeltype == cur_labeltype) {
|
|
|
|
|
pit->itemdepth = prev_pit->itemdepth + 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
} else if (prev_depth < cur_depth) {
|
|
|
|
|
if (prev_labeltype == cur_labeltype) {
|
|
|
|
|
pit->itemdepth = prev_pit->itemdepth + 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else if (prev_depth == cur_depth) {
|
|
|
|
|
if (prev_labeltype == cur_labeltype) {
|
|
|
|
|
pit->itemdepth = prev_pit->itemdepth;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (prev_pit == first_pit)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
--prev_pit;
|
|
|
|
|
}
|
2003-09-12 17:13:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-08 17:44:32 +00:00
|
|
|
|
void resetEnumCounterIfNeeded(ParagraphList::iterator pit,
|
|
|
|
|
ParagraphList::iterator firstpit,
|
|
|
|
|
Counters & counters)
|
|
|
|
|
{
|
|
|
|
|
if (pit == firstpit)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int const cur_depth = pit->getDepth();
|
|
|
|
|
ParagraphList::iterator prev_pit = boost::prior(pit);
|
|
|
|
|
while (true) {
|
|
|
|
|
int const prev_depth = prev_pit->getDepth();
|
|
|
|
|
int const prev_labeltype = prev_pit->layout()->labeltype;
|
|
|
|
|
if (prev_depth <= cur_depth) {
|
|
|
|
|
if (prev_labeltype != LABEL_ENUMERATE) {
|
|
|
|
|
switch (pit->itemdepth) {
|
|
|
|
|
case 0:
|
|
|
|
|
counters.reset("enumi");
|
|
|
|
|
case 1:
|
|
|
|
|
counters.reset("enumii");
|
|
|
|
|
case 2:
|
|
|
|
|
counters.reset("enumiii");
|
|
|
|
|
case 3:
|
|
|
|
|
counters.reset("enumiv");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (prev_pit == firstpit)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
--prev_pit;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // anon namespace
|
|
|
|
|
|
|
|
|
|
|
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-09-09 09:47:59 +00:00
|
|
|
|
BufferParams const & bufparams = buf.params();
|
|
|
|
|
LyXTextClass const & textclass = bufparams.getLyXTextClass();
|
2003-04-10 21:07:55 +00:00
|
|
|
|
LyXLayout_ptr const & layout = pit->layout();
|
2003-12-01 13:35:49 +00:00
|
|
|
|
ParagraphList::iterator first_pit = paragraphs().begin();
|
2003-10-08 17:44:32 +00:00
|
|
|
|
Counters & counters = textclass.counters();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-10-08 17:44:32 +00:00
|
|
|
|
// Always reset
|
|
|
|
|
pit->itemdepth = 0;
|
|
|
|
|
|
|
|
|
|
if (pit == first_pit) {
|
|
|
|
|
pit->params().appendix(pit->params().startOfAppendix());
|
|
|
|
|
} else {
|
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-10-08 17:44:32 +00:00
|
|
|
|
// Maybe we have to increment the item depth.
|
|
|
|
|
incrementItemDepth(pit, first_pit);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-09-12 17:13:22 +00:00
|
|
|
|
// erase what was there before
|
|
|
|
|
pit->params().labelString(string());
|
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?
|
2003-09-12 17:13:22 +00:00
|
|
|
|
if (layout->labeltype == LABEL_COUNTER) {
|
|
|
|
|
BufferParams const & bufparams = buf.params();
|
|
|
|
|
LyXTextClass const & textclass = bufparams.getLyXTextClass();
|
2003-10-08 17:44:32 +00:00
|
|
|
|
counters.step(layout->counter);
|
2003-09-12 17:13:22 +00:00
|
|
|
|
string label = expandLabel(textclass, layout, pit->params().appendix());
|
|
|
|
|
pit->params().labelString(label);
|
|
|
|
|
} else if (layout->labeltype == LABEL_ITEMIZE) {
|
2003-10-08 17:44:32 +00:00
|
|
|
|
// At some point of time we should do something more
|
|
|
|
|
// clever here, like:
|
2003-09-12 17:13:22 +00:00
|
|
|
|
// pit->params().labelString(
|
2003-10-08 17:44:32 +00:00
|
|
|
|
// bufparams.user_defined_bullet(pit->itemdepth).getText());
|
|
|
|
|
// for now, use a simple hardcoded label
|
|
|
|
|
string itemlabel;
|
|
|
|
|
switch (pit->itemdepth) {
|
|
|
|
|
case 0:
|
|
|
|
|
itemlabel = "*";
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
itemlabel = "-";
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
itemlabel = "@";
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
itemlabel = "<EFBFBD>";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pit->params().labelString(itemlabel);
|
2003-09-12 17:13:22 +00:00
|
|
|
|
} else if (layout->labeltype == LABEL_ENUMERATE) {
|
2003-10-08 17:44:32 +00:00
|
|
|
|
// Maybe we have to reset the enumeration counter.
|
|
|
|
|
resetEnumCounterIfNeeded(pit, first_pit, counters);
|
|
|
|
|
|
2003-09-12 17:13:22 +00:00
|
|
|
|
// FIXME
|
|
|
|
|
// Yes I know this is a really, really! bad solution
|
|
|
|
|
// (Lgb)
|
|
|
|
|
string enumcounter = "enum";
|
|
|
|
|
|
2003-10-08 17:44:32 +00:00
|
|
|
|
switch (pit->itemdepth) {
|
2003-09-12 17:13:22 +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
|
|
|
|
|
2003-10-08 17:44:32 +00:00
|
|
|
|
counters.step(enumcounter);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-10-08 17:44:32 +00:00
|
|
|
|
pit->params().labelString(counters.enumLabel(enumcounter));
|
2002-06-24 20:28:12 +00:00
|
|
|
|
} else if (layout->labeltype == LABEL_BIBLIO) {// ale970302
|
2003-10-08 17:44:32 +00:00
|
|
|
|
counters.step("bibitem");
|
|
|
|
|
int number = 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-12-01 13:35:49 +00:00
|
|
|
|
ParagraphList::iterator end = paragraphs().end();
|
2003-04-10 21:07:55 +00:00
|
|
|
|
ParagraphList::iterator tmppit = pit;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
InsetBase * 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()))
|
|
|
|
|
{
|
2004-01-26 10:13:15 +00:00
|
|
|
|
if (in->lyxCode() == InsetBase::FLOAT_CODE ||
|
|
|
|
|
in->lyxCode() == InsetBase::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-10-08 17:44:32 +00:00
|
|
|
|
tmppit = first_pit;
|
2003-07-31 13:38:06 +00:00
|
|
|
|
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;
|
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
if (in->lyxCode() == InsetBase::FLOAT_CODE)
|
2003-05-06 06:16:59 +00:00
|
|
|
|
type = static_cast<InsetFloat*>(in)->params().type;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
else if (in->lyxCode() == InsetBase::WRAP_CODE)
|
2003-05-06 06:16:59 +00:00
|
|
|
|
type = static_cast<InsetWrap*>(in)->params().type;
|
|
|
|
|
else
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(false);
|
2003-05-06 06:16:59 +00:00
|
|
|
|
|
|
|
|
|
Floating const & fl = textclass.floats().getType(type);
|
2002-08-06 22:40:59 +00:00
|
|
|
|
|
2003-10-08 17:44:32 +00:00
|
|
|
|
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
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-26 09:48:21 +00:00
|
|
|
|
// Updates all counters.
|
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-09-09 09:47:59 +00:00
|
|
|
|
bv()->buffer()->params().getLyXTextClass().counters().reset();
|
2002-09-06 14:48:01 +00:00
|
|
|
|
|
2003-11-26 09:48:21 +00:00
|
|
|
|
bool update_pos = false;
|
|
|
|
|
|
2003-12-01 13:35:49 +00:00
|
|
|
|
ParagraphList::iterator beg = paragraphs().begin();
|
|
|
|
|
ParagraphList::iterator end = paragraphs().end();
|
2003-08-11 09:09:01 +00:00
|
|
|
|
for (ParagraphList::iterator pit = beg; pit != end; ++pit) {
|
2003-11-26 09:48:21 +00:00
|
|
|
|
string const oldLabel = pit->params().labelString();
|
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);
|
2003-11-26 09:48:21 +00:00
|
|
|
|
string const & newLabel = pit->params().labelString();
|
|
|
|
|
if (oldLabel != newLabel) {
|
|
|
|
|
redoParagraphInternal(pit);
|
|
|
|
|
update_pos = true;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2003-11-26 09:48:21 +00:00
|
|
|
|
if (update_pos)
|
|
|
|
|
updateParPositions();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
void LyXText::insertInset(InsetBase * inset)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (!cursorPar()->insetAllowed(inset->lyxCode()))
|
2000-04-10 14:29:05 +00:00
|
|
|
|
return;
|
2003-11-10 09:06:48 +00:00
|
|
|
|
|
2004-01-13 10:37:38 +00:00
|
|
|
|
recUndo(cursor().par());
|
2002-04-12 08:31:06 +00:00
|
|
|
|
freezeUndo();
|
2004-01-13 10:37:38 +00:00
|
|
|
|
cursorPar()->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-11-25 11:17:27 +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))
|
2004-02-12 16:36:01 +00:00
|
|
|
|
cursorLeft(bv()->cursor(), true);
|
2003-11-22 14:44:59 +00:00
|
|
|
|
|
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
|
|
|
|
{
|
2004-01-20 14:25:24 +00:00
|
|
|
|
LCursor & cur = bv()->cursor();
|
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)
|
2004-02-11 14:45:44 +00:00
|
|
|
|
bv()->stuffClipboard(cur.selectionAsString(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
|
2004-01-20 14:25:24 +00:00
|
|
|
|
if (!cur.selection())
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
// OK, we have a selection. This is always between cur.selBegin()
|
2004-01-20 14:25:24 +00:00
|
|
|
|
// and cur.selEnd()
|
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
|
2004-01-26 10:13:15 +00:00
|
|
|
|
ParagraphList::iterator begpit = getPar(cur.selBegin().par());
|
2004-01-20 14:25:24 +00:00
|
|
|
|
ParagraphList::iterator endpit = getPar(cur.selEnd().par());
|
2004-01-09 09:04:33 +00:00
|
|
|
|
ParagraphList::iterator undopit = undoSpan(endpit);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
recUndo(cur.selBegin().par(), parOffset(undopit) - 1);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
int endpos = cur.selEnd().pos();
|
2003-04-29 09:40:49 +00:00
|
|
|
|
|
2003-09-09 09:47:59 +00:00
|
|
|
|
BufferParams const & bufparams = bv()->buffer()->params();
|
2003-04-29 23:59:39 +00:00
|
|
|
|
boost::tie(endpit, endpos) = realcut ?
|
2003-09-09 09:47:59 +00:00
|
|
|
|
CutAndPaste::cutSelection(bufparams,
|
2003-12-01 13:35:49 +00:00
|
|
|
|
paragraphs(),
|
2003-12-08 12:47:18 +00:00
|
|
|
|
begpit , endpit,
|
2004-01-26 10:13:15 +00:00
|
|
|
|
cur.selBegin().pos(), endpos,
|
2003-09-09 09:47:59 +00:00
|
|
|
|
bufparams.textclass,
|
2003-04-29 09:40:49 +00:00
|
|
|
|
doclear)
|
2003-09-09 09:47:59 +00:00
|
|
|
|
: CutAndPaste::eraseSelection(bufparams,
|
2003-12-01 13:35:49 +00:00
|
|
|
|
paragraphs(),
|
2003-12-08 12:47:18 +00:00
|
|
|
|
begpit, endpit,
|
2004-01-26 10:13:15 +00:00
|
|
|
|
cur.selBegin().pos(), endpos,
|
2003-04-29 09:40:49 +00:00
|
|
|
|
doclear);
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// sometimes necessary
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (doclear)
|
2003-12-08 12:47:18 +00:00
|
|
|
|
begpit->stripLeadingSpaces();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-12-08 12:47:18 +00:00
|
|
|
|
redoParagraphs(begpit, undopit);
|
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
|
2004-01-13 10:37:38 +00:00
|
|
|
|
cursor().pos(endpos);
|
|
|
|
|
cursor().par(parOffset(endpit));
|
2001-05-30 13:17:50 +00:00
|
|
|
|
|
|
|
|
|
// need a valid cursor. (Lgb)
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.clearSelection();
|
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
|
|
|
|
{
|
2004-01-20 14:25:24 +00:00
|
|
|
|
LCursor & cur = bv()->cursor();
|
2002-01-13 17:28:42 +00:00
|
|
|
|
// stuff the selection onto the X clipboard, from an explicit copy request
|
2004-02-11 14:45:44 +00:00
|
|
|
|
bv()->stuffClipboard(cur.selectionAsString(true));
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
|
|
|
|
// this doesnt make sense, if there is no selection
|
2004-01-20 14:25:24 +00:00
|
|
|
|
if (!cur.selection())
|
2000-04-10 14:29:05 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
// ok we have a selection. This is always between cur.selBegin()
|
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
|
2004-01-26 10:13:15 +00:00
|
|
|
|
while (getPar(cur.selBegin())->size() > cur.selBegin().pos()
|
|
|
|
|
&& getPar(cur.selBegin())->isLineSeparator(cur.selBegin().pos())
|
|
|
|
|
&& (cur.selBegin().par() != cur.selEnd().par()
|
|
|
|
|
|| cur.selBegin().pos() < cur.selEnd().pos()))
|
|
|
|
|
cur.selBegin().pos(cur.selBegin().pos() + 1);
|
2004-01-20 14:25:24 +00:00
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
CutAndPaste::copySelection(getPar(cur.selBegin().par()),
|
2004-01-20 14:25:24 +00:00
|
|
|
|
getPar(cur.selEnd().par()),
|
2004-01-26 10:13:15 +00:00
|
|
|
|
cur.selBegin().pos(),
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.selEnd().pos(),
|
2003-09-09 09:47:59 +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
|
|
|
|
{
|
2004-01-20 14:25:24 +00:00
|
|
|
|
LCursor & cur = bv()->cursor();
|
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
|
|
|
|
|
2004-01-13 10:37:38 +00:00
|
|
|
|
recUndo(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(),
|
2003-12-01 13:35:49 +00:00
|
|
|
|
paragraphs(),
|
2004-01-13 10:37:38 +00:00
|
|
|
|
cursorPar(), cursor().pos(),
|
2003-09-09 09:47:59 +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-10-09 10:52:12 +00:00
|
|
|
|
redoParagraphs(cursorPar(), endpit);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.clearSelection();
|
|
|
|
|
cur.resetAnchor();
|
2004-02-12 16:36:01 +00:00
|
|
|
|
setCursor(parOffset(ppp.first), ppp.second);
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.setSelection();
|
2003-03-17 16:25:00 +00:00
|
|
|
|
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
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
LCursor & cur = bv()->cursor();
|
|
|
|
|
cur.resetAnchor();
|
2003-02-08 19:18:01 +00:00
|
|
|
|
while (length--)
|
2004-02-12 16:36:01 +00:00
|
|
|
|
cursorRight(cur, true);
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.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
|
|
|
|
{
|
2004-01-20 14:25:24 +00:00
|
|
|
|
LCursor & cur = bv()->cursor();
|
|
|
|
|
recUndo(cur.par());
|
2001-06-25 00:06:33 +00:00
|
|
|
|
freezeUndo();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Get font setting before we cut
|
2004-01-20 14:25:24 +00:00
|
|
|
|
pos_type pos = cur.selEnd().pos();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
LyXFont const font = getPar(cur.selBegin())
|
2003-09-09 09:47:59 +00:00
|
|
|
|
->getFontSettings(bv()->buffer()->params(),
|
2004-01-26 10:13:15 +00:00
|
|
|
|
cur.selBegin().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) {
|
2004-01-20 14:25:24 +00:00
|
|
|
|
getPar(cur.selEnd())->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
|
|
|
|
{
|
2004-01-20 14:25:24 +00:00
|
|
|
|
LCursor & cur = bv()->cursor();
|
2003-10-09 10:52:12 +00:00
|
|
|
|
ParagraphList::iterator pit = cursorPar();
|
2004-01-13 10:37:38 +00:00
|
|
|
|
pos_type pos = cursor().pos();
|
2003-10-09 10:52:12 +00:00
|
|
|
|
ParagraphList::iterator endpit = boost::next(cursorPar());
|
2004-02-03 08:56:28 +00:00
|
|
|
|
recordUndo(cur, 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
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.clearSelection();
|
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-10-09 10:52:12 +00:00
|
|
|
|
redoParagraphs(cursorPar(), endpit);
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.resetAnchor();
|
2004-02-12 16:36:01 +00:00
|
|
|
|
setCursor(parOffset(pit), pos);
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.setSelection();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
|
2003-12-01 13:35:49 +00:00
|
|
|
|
// turn double CR to single CR, others are 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
|
2003-12-01 13:35:49 +00:00
|
|
|
|
// insertStringAsLines. Of course, it is a dirty
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// 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-12-01 13:35:49 +00:00
|
|
|
|
bool LyXText::setCursor(paroffset_type par, pos_type pos, bool setfont,
|
|
|
|
|
bool boundary)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-01-13 14:13:51 +00:00
|
|
|
|
CursorSlice old_cursor = cursor();
|
2003-10-09 10:52:12 +00:00
|
|
|
|
setCursorIntern(par, 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
|
|
|
|
|
2004-01-13 14:13:51 +00:00
|
|
|
|
void LyXText::setCursor(CursorSlice & cur, paroffset_type par,
|
2003-10-09 10:52:12 +00:00
|
|
|
|
pos_type pos, bool boundary)
|
2000-04-19 14:42:19 +00:00
|
|
|
|
{
|
2003-12-01 13:35:49 +00:00
|
|
|
|
BOOST_ASSERT(par != int(paragraphs().size()));
|
2002-03-14 13:40:19 +00:00
|
|
|
|
|
2003-10-09 10:52:12 +00:00
|
|
|
|
cur.par(par);
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cur.pos(pos);
|
|
|
|
|
cur.boundary(boundary);
|
2003-10-08 14:29:16 +00:00
|
|
|
|
|
|
|
|
|
// no rows, no fun...
|
2003-12-01 13:35:49 +00:00
|
|
|
|
if (paragraphs().begin()->rows.empty())
|
2003-07-17 06:45:39 +00:00
|
|
|
|
return;
|
2000-04-19 14:42:19 +00:00
|
|
|
|
|
2004-01-14 09:33:14 +00:00
|
|
|
|
// now some strict checking
|
2004-01-20 14:25:24 +00:00
|
|
|
|
Paragraph & para = *getPar(par);
|
|
|
|
|
Row const & row = *para.getRow(pos);
|
2003-10-27 11:44:10 +00:00
|
|
|
|
pos_type const end = row.endpos();
|
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-10-27 11:44:10 +00:00
|
|
|
|
if (pos < 0) {
|
|
|
|
|
lyxerr << "dont like -1" << endl;
|
|
|
|
|
pos = 0;
|
|
|
|
|
cur.pos(0);
|
|
|
|
|
BOOST_ASSERT(false);
|
2004-01-20 14:25:24 +00:00
|
|
|
|
} else if (pos > para.size()) {
|
2003-10-24 15:04:17 +00:00
|
|
|
|
lyxerr << "dont like 1, pos: " << pos
|
2004-01-20 14:25:24 +00:00
|
|
|
|
<< " size: " << para.size()
|
2003-10-24 15:04:17 +00:00
|
|
|
|
<< " row.pos():" << row.pos()
|
|
|
|
|
<< " paroffset: " << par << endl;
|
2003-02-08 19:18:01 +00:00
|
|
|
|
pos = 0;
|
|
|
|
|
cur.pos(0);
|
2003-10-24 15:04:17 +00:00
|
|
|
|
BOOST_ASSERT(false);
|
2003-10-27 11:44:10 +00:00
|
|
|
|
} else if (pos > end) {
|
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.
|
2003-10-27 11:44:10 +00:00
|
|
|
|
pos = end;
|
2001-12-28 21:17:18 +00:00
|
|
|
|
cur.pos(pos);
|
2003-10-24 15:04:17 +00:00
|
|
|
|
BOOST_ASSERT(false);
|
2003-10-17 10:31:47 +00:00
|
|
|
|
} else if (pos < row.pos()) {
|
2003-10-24 15:04:17 +00:00
|
|
|
|
lyxerr << "dont like 3 please report pos:" << pos
|
2004-01-20 14:25:24 +00:00
|
|
|
|
<< " size: " << para.size()
|
2003-10-24 15:04:17 +00:00
|
|
|
|
<< " row.pos():" << row.pos()
|
|
|
|
|
<< " paroffset: " << par << endl;
|
2003-10-17 10:31:47 +00:00
|
|
|
|
pos = row.pos();
|
2001-12-28 21:17:18 +00:00
|
|
|
|
cur.pos(pos);
|
2003-10-24 15:04:17 +00:00
|
|
|
|
BOOST_ASSERT(false);
|
2001-12-28 21:17:18 +00:00
|
|
|
|
}
|
2000-04-19 14:42:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-10-09 10:52:12 +00:00
|
|
|
|
void LyXText::setCursorIntern(paroffset_type par,
|
2003-03-18 13:05:08 +00:00
|
|
|
|
pos_type pos, bool setfont, bool boundary)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-01-13 10:37:38 +00:00
|
|
|
|
setCursor(cursor(), par, pos, boundary);
|
2004-01-30 11:41:12 +00:00
|
|
|
|
bv()->cursor().x_target() = cursorX(cursor());
|
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
|
|
|
|
{
|
2004-01-20 14:25:24 +00:00
|
|
|
|
LCursor & cur = bv()->cursor();
|
|
|
|
|
pos_type pos = cur.pos();
|
2003-10-09 10:52:12 +00:00
|
|
|
|
ParagraphList::iterator pit = cursorPar();
|
2003-04-13 22:24:28 +00:00
|
|
|
|
|
2004-01-13 10:37:38 +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-10-24 09:45:07 +00:00
|
|
|
|
if (pos > pit->getRow(pos)->pos() &&
|
2003-10-23 13:28:49 +00:00
|
|
|
|
bidi.level(pos) % 2 ==
|
|
|
|
|
bidi.level(pos - 1) % 2)
|
2001-07-07 18:19:18 +00:00
|
|
|
|
--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-09-09 09:47:59 +00:00
|
|
|
|
BufferParams const & bufparams = bv()->buffer()->params();
|
|
|
|
|
current_font = pit->getFontSettings(bufparams, pos);
|
2003-07-27 21:59:06 +00:00
|
|
|
|
real_current_font = getFont(pit, pos);
|
2000-07-10 10:31:34 +00:00
|
|
|
|
|
2004-01-13 10:37:38 +00:00
|
|
|
|
if (cursor().pos() == pit->size() &&
|
|
|
|
|
bidi.isBoundary(*bv()->buffer(), *pit, cursor().pos()) &&
|
|
|
|
|
!cursor().boundary()) {
|
2000-07-10 10:31:34 +00:00
|
|
|
|
Language const * lang =
|
2003-09-09 09:47:59 +00:00
|
|
|
|
pit->getParLanguage(bufparams);
|
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
|
|
|
|
}
|
|
|
|
|
|
2004-02-06 13:18:49 +00:00
|
|
|
|
// x is an absolute screen coord
|
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,
|
2003-10-17 10:31:47 +00:00
|
|
|
|
Row const & row, int & x, bool & boundary) const
|
2003-03-10 05:03:33 +00:00
|
|
|
|
{
|
2004-01-30 11:41:12 +00:00
|
|
|
|
x -= xo_;
|
2003-10-17 10:31:47 +00:00
|
|
|
|
double tmpx = row.x();
|
|
|
|
|
double fill_separator = row.fill_separator();
|
|
|
|
|
double fill_hfill = row.fill_hfill();
|
|
|
|
|
double fill_label_hfill = row.fill_label_hfill();
|
2003-03-10 05:03:33 +00:00
|
|
|
|
|
2003-10-17 10:31:47 +00:00
|
|
|
|
pos_type vc = row.pos();
|
2003-10-27 11:44:10 +00:00
|
|
|
|
pos_type end = row.endpos();
|
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-11-13 13:43:44 +00:00
|
|
|
|
pos_type body_pos = pit->beginOfBody();
|
2003-07-28 12:20:42 +00:00
|
|
|
|
double last_tmpx = tmpx;
|
2003-03-10 05:03:33 +00:00
|
|
|
|
|
|
|
|
|
if (body_pos > 0 &&
|
2003-12-01 13:35:49 +00:00
|
|
|
|
(body_pos > end || !pit->isLineSeparator(body_pos - 1)))
|
2003-03-10 05:03:33 +00:00
|
|
|
|
body_pos = 0;
|
|
|
|
|
|
|
|
|
|
// check for empty row
|
2003-10-27 11:44:10 +00:00
|
|
|
|
if (vc == end) {
|
2004-01-30 11:41:12 +00:00
|
|
|
|
x = int(tmpx) + xo_;
|
2003-03-10 05:03:33 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2003-10-27 11:44:10 +00:00
|
|
|
|
while (vc < end && tmpx <= x) {
|
2003-10-23 13:28:49 +00:00
|
|
|
|
c = bidi.vis2log(vc);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
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-10-17 10:31:47 +00:00
|
|
|
|
if (hfillExpansion(*pit, row, 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;
|
|
|
|
|
}
|
|
|
|
|
|
2003-10-27 11:44:10 +00:00
|
|
|
|
BOOST_ASSERT(vc <= end); // This shouldn't happen.
|
2003-03-10 05:03:33 +00:00
|
|
|
|
|
|
|
|
|
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
|
2003-10-22 16:30:57 +00:00
|
|
|
|
bool const lastrow = lyxrc.rtl_support && row.endpos() == pit->size();
|
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.
|
2004-01-20 14:25:24 +00:00
|
|
|
|
bool const rtl = lastrow
|
2003-09-09 09:47:59 +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-10-17 10:31:47 +00:00
|
|
|
|
((rtl && left_side && vc == row.pos() && x < tmpx - 5) ||
|
2003-10-27 11:44:10 +00:00
|
|
|
|
(!rtl && !left_side && vc == end && x > tmpx + 5)))
|
|
|
|
|
c = end;
|
2003-10-17 10:31:47 +00:00
|
|
|
|
else if (vc == row.pos()) {
|
2003-10-23 13:28:49 +00:00
|
|
|
|
c = bidi.vis2log(vc);
|
|
|
|
|
if (bidi.level(c) % 2 == 1)
|
2003-03-10 05:03:33 +00:00
|
|
|
|
++c;
|
|
|
|
|
} else {
|
2003-10-23 13:28:49 +00:00
|
|
|
|
c = bidi.vis2log(vc - 1);
|
|
|
|
|
bool const rtl = (bidi.level(c) % 2 == 1);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
if (left_side == rtl) {
|
|
|
|
|
++c;
|
2003-10-23 13:28:49 +00:00
|
|
|
|
boundary = bidi.isBoundary(*bv()->buffer(), *pit, c);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-10-27 11:44:10 +00:00
|
|
|
|
if (row.pos() < end && c >= end && pit->isNewline(end - 1)) {
|
|
|
|
|
if (bidi.level(end -1) % 2 == 0)
|
|
|
|
|
tmpx -= singleWidth(pit, end - 1);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
else
|
2003-10-27 11:44:10 +00:00
|
|
|
|
tmpx += singleWidth(pit, end - 1);
|
|
|
|
|
c = end - 1;
|
2003-03-10 05:03:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
x = int(tmpx) + xo_;
|
|
|
|
|
return c - row.pos();
|
2003-03-10 05:03:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-18 13:05:08 +00:00
|
|
|
|
void LyXText::setCursorFromCoordinates(int x, int y)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-01-13 14:13:51 +00:00
|
|
|
|
CursorSlice old_cursor = cursor();
|
2004-01-13 10:37:38 +00:00
|
|
|
|
setCursorFromCoordinates(cursor(), x, y);
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCurrentFont();
|
2003-08-15 13:20:45 +00:00
|
|
|
|
deleteEmptyParagraphMechanism(old_cursor);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-12-15 11:36:19 +00:00
|
|
|
|
|
2003-11-25 11:17:27 +00:00
|
|
|
|
// x,y are coordinates relative to this LyXText
|
2004-01-13 14:13:51 +00:00
|
|
|
|
void LyXText::setCursorFromCoordinates(CursorSlice & cur, int x, int y)
|
2000-03-27 15:13:47 +00:00
|
|
|
|
{
|
2003-08-15 08:03:54 +00:00
|
|
|
|
ParagraphList::iterator pit;
|
2003-10-17 10:31:47 +00:00
|
|
|
|
Row const & row = *getRowNearY(y, pit);
|
2000-06-08 23:16:16 +00:00
|
|
|
|
bool bound = false;
|
2004-02-06 13:18:49 +00:00
|
|
|
|
int xx = x + xo_; // getRowNearX get absolute x coords
|
|
|
|
|
pos_type const pos = row.pos() + getColumnNearX(pit, row, xx, bound);
|
2004-01-30 11:41:12 +00:00
|
|
|
|
cur.par() = parOffset(pit);
|
|
|
|
|
cur.pos() = pos;
|
|
|
|
|
cur.boundary() = bound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// x,y are absolute screen coordinates
|
|
|
|
|
void LyXText::edit(LCursor & cur, int x, int y)
|
|
|
|
|
{
|
|
|
|
|
ParagraphList::iterator pit;
|
2004-02-06 13:18:49 +00:00
|
|
|
|
Row const & row = *getRowNearY(y - yo_, pit);
|
2004-01-30 11:41:12 +00:00
|
|
|
|
bool bound = false;
|
2004-02-06 13:18:49 +00:00
|
|
|
|
|
|
|
|
|
int xx = x; // is modified by getColumnNearX
|
2004-01-30 11:41:12 +00:00
|
|
|
|
pos_type const pos = row.pos() + getColumnNearX(pit, row, xx, bound);
|
|
|
|
|
cur.par() = parOffset(pit);
|
|
|
|
|
cur.pos() = pos;
|
|
|
|
|
cur.boundary() = bound;
|
|
|
|
|
|
|
|
|
|
// try to descend into nested insets
|
|
|
|
|
InsetBase * inset = checkInsetHit(x, y);
|
|
|
|
|
if (inset) {
|
2004-02-06 13:18:49 +00:00
|
|
|
|
// This should be just before or just behind the
|
|
|
|
|
// cursor position set above.
|
2004-01-30 11:41:12 +00:00
|
|
|
|
BOOST_ASSERT((pos != 0 && inset == pit->getInset(pos - 1))
|
|
|
|
|
|| inset == pit->getInset(pos));
|
2004-02-06 13:18:49 +00:00
|
|
|
|
// Make sure the cursor points to the position before
|
|
|
|
|
// this inset.
|
2004-01-30 11:41:12 +00:00
|
|
|
|
if (inset == pit->getInset(pos - 1))
|
|
|
|
|
--cur.pos();
|
|
|
|
|
inset->edit(cur, x, y);
|
|
|
|
|
}
|
2000-03-27 15:13:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
bool LyXText::checkAndActivateInset(LCursor & cur, bool front)
|
2003-11-17 14:28:18 +00:00
|
|
|
|
{
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.pos() == cur.lastpos())
|
2003-11-17 14:28:18 +00:00
|
|
|
|
return false;
|
2004-02-12 16:36:01 +00:00
|
|
|
|
InsetBase * inset = cur.nextInset();
|
2003-11-17 14:28:18 +00:00
|
|
|
|
if (!isHighlyEditableInset(inset))
|
|
|
|
|
return false;
|
2004-02-12 16:36:01 +00:00
|
|
|
|
inset->edit(cur, front);
|
2003-11-17 14:28:18 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
DispatchResult LyXText::moveRight(LCursor & cur)
|
2003-11-17 14:28:18 +00:00
|
|
|
|
{
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.paragraph().isRightToLeftPar(bv()->buffer()->params()))
|
|
|
|
|
return moveLeftIntern(cur, false, true, false);
|
2003-11-17 14:28:18 +00:00
|
|
|
|
else
|
2004-02-12 16:36:01 +00:00
|
|
|
|
return moveRightIntern(cur, true, true, false);
|
2003-11-17 14:28:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
DispatchResult LyXText::moveLeft(LCursor & cur)
|
2003-11-17 14:28:18 +00:00
|
|
|
|
{
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.paragraph().isRightToLeftPar(bv()->buffer()->params()))
|
|
|
|
|
return moveRightIntern(cur, true, true, false);
|
2003-11-17 14:28:18 +00:00
|
|
|
|
else
|
2004-02-12 16:36:01 +00:00
|
|
|
|
return moveLeftIntern(cur, false, true, false);
|
2003-11-17 14:28:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
DispatchResult LyXText::moveRightIntern(LCursor & cur,
|
|
|
|
|
bool front, bool activate_inset, bool selecting)
|
2003-11-17 14:28:18 +00:00
|
|
|
|
{
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.par() == cur.lastpar() && cur.pos() == cur.lastpos())
|
2003-11-17 14:28:18 +00:00
|
|
|
|
return DispatchResult(false, FINISHED_RIGHT);
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (activate_inset && checkAndActivateInset(cur, front))
|
2003-11-17 14:28:18 +00:00
|
|
|
|
return DispatchResult(true, true);
|
2004-02-12 16:36:01 +00:00
|
|
|
|
cursorRight(cur, true);
|
2003-11-17 14:28:18 +00:00
|
|
|
|
if (!selecting)
|
2004-02-12 16:36:01 +00:00
|
|
|
|
cur.clearSelection();
|
2003-11-17 14:28:18 +00:00
|
|
|
|
return DispatchResult(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
DispatchResult LyXText::moveLeftIntern(LCursor & cur,
|
|
|
|
|
bool front, bool activate_inset, bool selecting)
|
2003-11-17 14:28:18 +00:00
|
|
|
|
{
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.par() == 0 && cur.pos() == 0)
|
2003-11-17 14:28:18 +00:00
|
|
|
|
return DispatchResult(false, FINISHED);
|
2004-02-12 16:36:01 +00:00
|
|
|
|
cursorLeft(cur, true);
|
2003-11-17 14:28:18 +00:00
|
|
|
|
if (!selecting)
|
2004-02-12 16:36:01 +00:00
|
|
|
|
cur.clearSelection();
|
|
|
|
|
if (activate_inset && checkAndActivateInset(cur, front))
|
2003-11-17 14:28:18 +00:00
|
|
|
|
return DispatchResult(true, true);
|
|
|
|
|
return DispatchResult(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
DispatchResult LyXText::moveUp(LCursor & cur)
|
2003-11-17 14:28:18 +00:00
|
|
|
|
{
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.par() == 0 && cur.row() == 0)
|
2003-11-17 14:28:18 +00:00
|
|
|
|
return DispatchResult(false, FINISHED_UP);
|
2004-02-12 16:36:01 +00:00
|
|
|
|
cursorUp(cur, false);
|
2004-02-03 08:56:28 +00:00
|
|
|
|
cur.clearSelection();
|
2003-11-17 14:28:18 +00:00
|
|
|
|
return DispatchResult(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
DispatchResult LyXText::moveDown(LCursor & cur)
|
2003-11-17 14:28:18 +00:00
|
|
|
|
{
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.par() == cur.lastpar() && cur.textRow().endpos() == cur.lastpos())
|
2003-11-17 14:28:18 +00:00
|
|
|
|
return DispatchResult(false, FINISHED_DOWN);
|
2004-02-12 16:36:01 +00:00
|
|
|
|
cursorDown(cur, false);
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.clearSelection();
|
2003-11-17 14:28:18 +00:00
|
|
|
|
return DispatchResult(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
bool LyXText::cursorLeft(LCursor & cur, bool internal)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.pos() != 0) {
|
2004-01-20 14:25:24 +00:00
|
|
|
|
bool boundary = cur.boundary();
|
|
|
|
|
setCursor(cur.par(), cur.pos() - 1, true, false);
|
2000-05-30 19:31:11 +00:00
|
|
|
|
if (!internal && !boundary &&
|
2004-01-20 14:25:24 +00:00
|
|
|
|
bidi.isBoundary(*bv()->buffer(), cur.paragraph(), cur.pos() + 1))
|
|
|
|
|
setCursor(cur.par(), cur.pos() + 1, true, true);
|
2003-11-17 14:28:18 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
if (cur.par() != 0) {
|
2003-08-01 14:12:04 +00:00
|
|
|
|
// steps into the paragraph above
|
2004-01-20 14:25:24 +00:00
|
|
|
|
setCursor(cur.par() - 1, boost::prior(cursorPar())->size());
|
2003-11-17 14:28:18 +00:00
|
|
|
|
return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2003-11-17 14:28:18 +00:00
|
|
|
|
|
|
|
|
|
return false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
bool LyXText::cursorRight(LCursor & cur, bool internal)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-01-20 14:25:24 +00:00
|
|
|
|
if (!internal && cur.boundary()) {
|
|
|
|
|
setCursor(cur.par(), cur.pos(), true, false);
|
2003-11-17 14:28:18 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
if (cur.pos() != cur.lastpos()) {
|
|
|
|
|
setCursor(cur.par(), cur.pos() + 1, true, false);
|
|
|
|
|
if (!internal && bidi.isBoundary(*bv()->buffer(), cur.paragraph(),
|
|
|
|
|
cur.pos()))
|
|
|
|
|
setCursor(cur.par(), cur.pos(), true, true);
|
2003-11-17 14:28:18 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.par() != cur.lastpar()) {
|
2004-01-20 14:25:24 +00:00
|
|
|
|
setCursor(cur.par() + 1, 0);
|
2003-11-17 14:28:18 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
void LyXText::cursorUp(LCursor & cur, bool selecting)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-11-21 08:35:15 +00:00
|
|
|
|
Row const & row = *cursorRow();
|
2004-01-30 11:41:12 +00:00
|
|
|
|
int x = cur.x_target();
|
|
|
|
|
int y = cursorY(cur.current()) - row.baseline() - 1;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
setCursorFromCoordinates(x, y);
|
2003-11-22 14:44:59 +00:00
|
|
|
|
|
2002-04-17 08:34:59 +00:00
|
|
|
|
if (!selecting) {
|
2004-01-30 11:41:12 +00:00
|
|
|
|
InsetBase * inset_hit = checkInsetHit(cur.x_target(), y);
|
2003-11-06 16:43:12 +00:00
|
|
|
|
if (inset_hit && isHighlyEditableInset(inset_hit))
|
2004-01-30 11:41:12 +00:00
|
|
|
|
inset_hit->edit(cur, cur.x_target(), y);
|
2002-04-16 14:10:39 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
void LyXText::cursorDown(LCursor & cur, bool selecting)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-12 16:36:01 +00:00
|
|
|
|
Row const & row = cur.textRow();
|
2004-01-30 11:41:12 +00:00
|
|
|
|
int x = cur.x_target();
|
|
|
|
|
int y = cursorY(cur.current()) - row.baseline() + row.height() + 1;
|
2004-02-12 16:36:01 +00:00
|
|
|
|
setCursorFromCoordinates(cur.current(), x, y);
|
2003-11-21 08:35:15 +00:00
|
|
|
|
|
2003-10-17 10:31:47 +00:00
|
|
|
|
if (!selecting) {
|
2004-01-30 11:41:12 +00:00
|
|
|
|
InsetBase * inset_hit = checkInsetHit(cur.x_target(), y);
|
2003-11-06 16:43:12 +00:00
|
|
|
|
if (inset_hit && isHighlyEditableInset(inset_hit))
|
2004-01-30 11:41:12 +00:00
|
|
|
|
inset_hit->edit(cur, cur.x_target(), y);
|
2002-04-16 14:10:39 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
void LyXText::cursorUpParagraph(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.pos() > 0)
|
|
|
|
|
setCursor(cur.par(), 0);
|
|
|
|
|
else if (cur.par() != 0)
|
|
|
|
|
setCursor(cur.par() - 1, 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
void LyXText::cursorDownParagraph(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.par() != cur.lastpar())
|
|
|
|
|
setCursor(cur.par() + 1, 0);
|
2003-08-01 14:12:04 +00:00
|
|
|
|
else
|
2004-02-12 16:36:01 +00:00
|
|
|
|
setCursor(cur.par(), cur.lastpos());
|
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
|
2004-01-13 14:13:51 +00:00
|
|
|
|
void LyXText::fixCursorAfterDelete(CursorSlice & cur, CursorSlice 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())
|
2004-02-12 16:36:01 +00:00
|
|
|
|
--cur.pos();
|
2001-09-27 09:52:06 +00:00
|
|
|
|
|
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.
|
2004-01-20 14:25:24 +00:00
|
|
|
|
if (cur.pos() > cur.lastpos())
|
|
|
|
|
cur.pos() = cur.lastpos();
|
2001-09-27 09:52:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2004-01-13 14:13:51 +00:00
|
|
|
|
bool LyXText::deleteEmptyParagraphMechanism(CursorSlice const & old_cursor)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-01-14 17:21:39 +00:00
|
|
|
|
#warning Disabled as it crashes after the cursor data shift... (Andre)
|
|
|
|
|
return false;
|
|
|
|
|
|
2000-03-14 23:33:15 +00:00
|
|
|
|
// Would be wrong to delete anything if we have a selection.
|
2004-01-20 14:25:24 +00:00
|
|
|
|
if (bv()->cursor().selection())
|
2002-03-07 11:58:19 +00:00
|
|
|
|
return false;
|
2000-01-13 16:28:54 +00:00
|
|
|
|
|
2003-10-10 09:01:23 +00:00
|
|
|
|
// Don't do anything if the cursor is invalid
|
|
|
|
|
if (old_cursor.par() == -1)
|
|
|
|
|
return false;
|
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
#if 0
|
2000-03-14 23:33:15 +00:00
|
|
|
|
// We allow all kinds of "mumbo-jumbo" when freespacing.
|
2003-10-10 09:01:23 +00:00
|
|
|
|
ParagraphList::iterator const old_pit = getPar(old_cursor);
|
|
|
|
|
if (old_pit->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
|
2003-12-01 13:35:49 +00:00
|
|
|
|
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.
|
2004-01-13 10:37:38 +00:00
|
|
|
|
if (old_cursor.par() != cursor().par()
|
|
|
|
|
|| old_cursor.pos() != cursor().pos()) {
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
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
|
2003-10-09 10:52:12 +00:00
|
|
|
|
&& old_cursor.pos() < old_pit->size()
|
|
|
|
|
&& old_pit->isLineSeparator(old_cursor.pos())
|
|
|
|
|
&& old_pit->isLineSeparator(old_cursor.pos() - 1)) {
|
|
|
|
|
bool erased = old_pit->erase(old_cursor.pos() - 1);
|
|
|
|
|
redoParagraph(old_pit);
|
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
|
2004-01-13 14:13:51 +00:00
|
|
|
|
// automated way in CursorSlice code. (JMarc 26/09/2001)
|
2001-09-27 09:52:06 +00:00
|
|
|
|
#endif
|
|
|
|
|
// correct all cursors held by the LyXText
|
2004-01-13 10:37:38 +00:00
|
|
|
|
fixCursorAfterDelete(cursor(), old_cursor);
|
|
|
|
|
fixCursorAfterDelete(anchor(), 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-12-01 13:35:49 +00:00
|
|
|
|
if (paragraphs().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-10-09 10:52:12 +00:00
|
|
|
|
if (old_pit->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
|
2004-01-13 10:37:38 +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-10-28 11:18:40 +00:00
|
|
|
|
if (old_pit->empty()
|
|
|
|
|
|| (old_pit->size() == 1 && old_pit->isLineSeparator(0))) {
|
2003-08-22 07:49:57 +00:00
|
|
|
|
// ok, we will delete something
|
2004-01-13 14:13:51 +00:00
|
|
|
|
CursorSlice 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-10-13 00:38:09 +00:00
|
|
|
|
bool selection_position_was_oldcursor_position =
|
2004-01-13 10:37:38 +00:00
|
|
|
|
anchor().par() == old_cursor.par()
|
|
|
|
|
&& anchor().pos() == old_cursor.pos();
|
2003-04-16 00:02:38 +00:00
|
|
|
|
|
2004-01-13 10:37:38 +00:00
|
|
|
|
tmpcursor = cursor();
|
|
|
|
|
cursor() = old_cursor; // that undo can restore the right cursor position
|
2001-07-07 18:19:18 +00:00
|
|
|
|
|
2003-10-09 10:52:12 +00:00
|
|
|
|
ParagraphList::iterator endpit = boost::next(old_pit);
|
2003-12-01 13:35:49 +00:00
|
|
|
|
while (endpit != paragraphs().end() && endpit->getDepth())
|
2003-08-15 08:03:54 +00:00
|
|
|
|
++endpit;
|
2003-08-28 07:41:31 +00:00
|
|
|
|
|
2003-10-13 10:59:31 +00:00
|
|
|
|
recUndo(parOffset(old_pit), parOffset(endpit) - 1);
|
2004-01-13 10:37:38 +00:00
|
|
|
|
cursor() = tmpcursor;
|
2001-09-27 10:52:53 +00:00
|
|
|
|
|
2003-11-05 21:47:25 +00:00
|
|
|
|
// cache cursor pit
|
|
|
|
|
ParagraphList::iterator tmppit = cursorPar();
|
2003-08-15 08:03:54 +00:00
|
|
|
|
// delete old par
|
2003-12-01 13:35:49 +00:00
|
|
|
|
paragraphs().erase(old_pit);
|
2003-11-05 21:47:25 +00:00
|
|
|
|
// update cursor par offset
|
2004-01-13 10:37:38 +00:00
|
|
|
|
cursor().par(parOffset(tmppit));
|
2003-08-15 08:03:54 +00:00
|
|
|
|
redoParagraph();
|
2002-03-21 17:27:08 +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
|
2004-01-13 18:08:13 +00:00
|
|
|
|
bv()->resetAnchor();
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2001-09-27 10:52:53 +00:00
|
|
|
|
}
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
|
|
|
|
if (deleted)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (old_pit->stripLeadingSpaces()) {
|
|
|
|
|
redoParagraph(old_pit);
|
2004-01-13 18:08:13 +00:00
|
|
|
|
bv()->resetAnchor();
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2003-10-28 11:18:40 +00:00
|
|
|
|
return false;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-12-01 13:35:49 +00:00
|
|
|
|
ParagraphList & LyXText::paragraphs() const
|
2000-06-12 11:27:15 +00:00
|
|
|
|
{
|
2003-12-01 13:35:49 +00:00
|
|
|
|
return const_cast<ParagraphList &>(paragraphs_);
|
2000-06-12 11:27:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-13 10:59:31 +00:00
|
|
|
|
void LyXText::recUndo(paroffset_type first, paroffset_type last) const
|
|
|
|
|
{
|
2004-02-03 08:56:28 +00:00
|
|
|
|
recordUndo(bv()->cursor(), Undo::ATOMIC, first, last);
|
2003-10-13 10:59:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXText::recUndo(lyx::paroffset_type par) const
|
|
|
|
|
{
|
2004-02-03 08:56:28 +00:00
|
|
|
|
recordUndo(bv()->cursor(), Undo::ATOMIC, par, par);
|
2003-10-13 10:59:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-26 17:04:10 +00:00
|
|
|
|
bool LyXText::isInInset() const
|
|
|
|
|
{
|
2003-12-01 13:35:49 +00:00
|
|
|
|
return in_inset_;
|
2003-02-26 17:04:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-03 08:56:28 +00:00
|
|
|
|
bool LyXText::toggleInset()
|
|
|
|
|
{
|
|
|
|
|
InsetBase * inset = bv()->cursor().nextInset();
|
|
|
|
|
// is there an editable inset at cursor position?
|
|
|
|
|
if (!isEditableInset(inset))
|
|
|
|
|
return false;
|
|
|
|
|
//bv()->owner()->message(inset->editMessage());
|
|
|
|
|
|
|
|
|
|
// do we want to keep this?? (JMarc)
|
|
|
|
|
if (!isHighlyEditableInset(inset))
|
|
|
|
|
recUndo(cursor().par());
|
|
|
|
|
|
|
|
|
|
if (inset->isOpen())
|
|
|
|
|
inset->close();
|
|
|
|
|
else
|
|
|
|
|
inset->open();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-14 00:41:44 +00:00
|
|
|
|
int defaultRowHeight()
|
|
|
|
|
{
|
2003-12-01 13:35:49 +00:00
|
|
|
|
return int(font_metrics::maxHeight(LyXFont(LyXFont::ALL_SANE)) * 1.2);
|
2003-02-14 00:41:44 +00:00
|
|
|
|
}
|