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"
|
2004-08-14 19:55:00 +00:00
|
|
|
|
#include "coordcache.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"
|
|
|
|
|
#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"
|
2005-02-25 11:55:36 +00:00
|
|
|
|
#include "pariterator.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-05-19 07:12:09 +00:00
|
|
|
|
#include "insets/insetenv.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "support/textutils.h"
|
2004-07-24 10:55:30 +00:00
|
|
|
|
|
2005-09-26 09:20:15 +00:00
|
|
|
|
#include <boost/current_function.hpp>
|
|
|
|
|
|
2004-07-24 10:55:30 +00:00
|
|
|
|
#include <sstream>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
|
using lyx::pit_type;
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::pos_type;
|
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;
|
2005-07-15 12:56:23 +00:00
|
|
|
|
using std::min;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
|
2000-07-21 18:47:54 +00:00
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
LyXText::LyXText(BufferView * bv)
|
2004-11-30 01:59:49 +00:00
|
|
|
|
: maxwidth_(bv ? bv->workWidth() : 100),
|
2005-12-06 14:54:23 +00:00
|
|
|
|
current_font(LyXFont::ALL_INHERIT),
|
2004-03-01 16:29:30 +00:00
|
|
|
|
background_color_(LColor::background),
|
2004-12-17 16:27:12 +00:00
|
|
|
|
bv_owner(bv),
|
|
|
|
|
autoBreakRows_(false)
|
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-03-25 09:16:36 +00:00
|
|
|
|
BOOST_ASSERT(bv);
|
2004-02-02 16:38:13 +00:00
|
|
|
|
bv_owner = bv;
|
2004-03-01 16:29:30 +00:00
|
|
|
|
maxwidth_ = bv->workWidth();
|
2004-11-30 01:59:49 +00:00
|
|
|
|
dim_.wid = maxwidth_;
|
|
|
|
|
dim_.asc = 10;
|
|
|
|
|
dim_.des = 10;
|
2003-07-14 09:15:58 +00:00
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
|
pit_type const end = paragraphs().size();
|
|
|
|
|
for (pit_type pit = 0; pit != end; ++pit)
|
2004-11-30 01:59:49 +00:00
|
|
|
|
pars_[pit].rows().clear();
|
2002-09-06 14:48:01 +00:00
|
|
|
|
|
2004-08-15 00:01:45 +00:00
|
|
|
|
current_font = getFont(pars_[0], 0);
|
2005-02-25 11:55:36 +00:00
|
|
|
|
updateCounters(*bv->buffer());
|
2000-06-12 11:27:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-07-06 15:41:17 +00:00
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
bool LyXText::isMainText() const
|
|
|
|
|
{
|
|
|
|
|
return &bv()->buffer()->text() == this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
//takes screen x,y coordinates
|
2004-10-05 10:11:42 +00:00
|
|
|
|
InsetBase * LyXText::checkInsetHit(int x, int y) const
|
2004-08-14 19:55:00 +00:00
|
|
|
|
{
|
2004-11-30 01:59:49 +00:00
|
|
|
|
pit_type pit = getPitNearY(y);
|
|
|
|
|
BOOST_ASSERT(pit != -1);
|
2004-08-14 19:55:00 +00:00
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
Paragraph const & par = pars_[pit];
|
2004-08-14 19:55:00 +00:00
|
|
|
|
|
2005-07-14 08:20:10 +00:00
|
|
|
|
lyxerr[Debug::DEBUG]
|
2005-09-26 22:54:12 +00:00
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< ": x: " << x
|
|
|
|
|
<< " y: " << y
|
|
|
|
|
<< " pit: " << pit
|
|
|
|
|
<< endl;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
InsetList::const_iterator iit = par.insetlist.begin();
|
|
|
|
|
InsetList::const_iterator iend = par.insetlist.end();
|
|
|
|
|
for (; iit != iend; ++iit) {
|
|
|
|
|
InsetBase * inset = iit->inset;
|
2004-08-14 19:55:00 +00:00
|
|
|
|
#if 1
|
2005-07-14 08:20:10 +00:00
|
|
|
|
lyxerr[Debug::DEBUG]
|
2005-09-26 22:54:12 +00:00
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< ": examining inset " << inset << endl;
|
|
|
|
|
|
2005-01-31 16:29:48 +00:00
|
|
|
|
if (theCoords.getInsets().has(inset))
|
2005-07-14 08:20:10 +00:00
|
|
|
|
lyxerr[Debug::DEBUG]
|
2005-09-26 22:54:12 +00:00
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
2005-07-14 08:20:10 +00:00
|
|
|
|
<< ": xo: " << inset->xo() << "..."
|
2004-11-30 01:59:49 +00:00
|
|
|
|
<< inset->xo() + inset->width()
|
|
|
|
|
<< " yo: " << inset->yo() - inset->ascent()
|
|
|
|
|
<< "..."
|
2005-07-14 08:20:10 +00:00
|
|
|
|
<< inset->yo() + inset->descent()
|
2005-09-26 22:54:12 +00:00
|
|
|
|
<< endl;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
else
|
2005-07-14 08:20:10 +00:00
|
|
|
|
lyxerr[Debug::DEBUG]
|
2005-09-26 22:54:12 +00:00
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< ": inset has no cached position" << endl;
|
2004-08-14 19:55:00 +00:00
|
|
|
|
#endif
|
2004-11-30 01:59:49 +00:00
|
|
|
|
if (inset->covers(x, y)) {
|
2005-07-14 08:20:10 +00:00
|
|
|
|
lyxerr[Debug::DEBUG]
|
2005-09-26 22:54:12 +00:00
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< ": Hit inset: " << inset << endl;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
return inset;
|
2004-08-14 19:55:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2005-07-14 08:20:10 +00:00
|
|
|
|
lyxerr[Debug::DEBUG]
|
2005-09-26 22:54:12 +00:00
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< ": No inset hit. " << endl;
|
2004-08-14 19:55:00 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
2004-08-15 00:01:45 +00:00
|
|
|
|
LyXFont LyXText::getFont(Paragraph const & par, pos_type const 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
|
|
|
|
|
2004-08-14 22:38:45 +00:00
|
|
|
|
LyXLayout_ptr const & layout = par.layout();
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2003-07-27 21:59:06 +00:00
|
|
|
|
#warning broken?
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#endif
|
2003-09-09 09:47:59 +00:00
|
|
|
|
BufferParams const & params = bv()->buffer()->params();
|
2004-08-14 22:38:45 +00:00
|
|
|
|
pos_type const body_pos = par.beginOfBody();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// We specialize the 95% common case:
|
2004-08-14 22:38:45 +00:00
|
|
|
|
if (!par.getDepth()) {
|
|
|
|
|
LyXFont f = par.getFontSettings(params, pos);
|
2004-03-18 12:53:43 +00:00
|
|
|
|
if (!isMainText())
|
2005-04-12 18:42:27 +00:00
|
|
|
|
applyOuterFont(f);
|
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
|
|
|
|
|
2004-08-14 22:38:45 +00:00
|
|
|
|
LyXFont font = par.getFontSettings(params, pos);
|
2003-10-21 16:15:14 +00:00
|
|
|
|
font.realize(layoutfont);
|
2002-09-06 15:18:11 +00:00
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
if (!isMainText())
|
2005-04-12 18:42:27 +00:00
|
|
|
|
applyOuterFont(font);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2006-01-23 10:25:41 +00:00
|
|
|
|
// Find the pit value belonging to paragraph. This will not break
|
|
|
|
|
// even if pars_ would not be a vector anymore.
|
|
|
|
|
// Performance appears acceptable.
|
|
|
|
|
|
|
|
|
|
pit_type pit = pars_.size();
|
|
|
|
|
for (pit_type it = 0; it < pit; ++it)
|
|
|
|
|
if (&pars_[it] == &par) {
|
|
|
|
|
pit = it;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// Realize against environment font information
|
|
|
|
|
if (pit < pars_.size())
|
|
|
|
|
font.realize(outerFont(pit, pars_));
|
|
|
|
|
|
2003-04-15 00:11:03 +00:00
|
|
|
|
// Realize with the fonts of lesser depth.
|
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
|
|
|
|
}
|
|
|
|
|
|
2005-04-12 18:42:27 +00:00
|
|
|
|
// There are currently two font mechanisms in LyX:
|
|
|
|
|
// 1. The font attributes in a lyxtext, and
|
|
|
|
|
// 2. The inset-specific font properties, defined in an inset's
|
|
|
|
|
// metrics() and draw() methods and handed down the inset chain through
|
|
|
|
|
// the pi/mi parameters, and stored locally in a lyxtext in font_.
|
|
|
|
|
// This is where the two are integrated in the final fully realized
|
|
|
|
|
// font.
|
|
|
|
|
void LyXText::applyOuterFont(LyXFont & font) const {
|
|
|
|
|
LyXFont lf(font_);
|
|
|
|
|
lf.reduce(defaultfont_);
|
|
|
|
|
lf.realize(font);
|
|
|
|
|
lf.setLanguage(font.language());
|
|
|
|
|
font = lf;
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-03 18:28:11 +00:00
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
|
LyXFont LyXText::getLayoutFont(pit_type const pit) const
|
2001-08-03 18:28:11 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
LyXLayout_ptr const & layout = pars_[pit].layout();
|
2001-08-03 18:28:11 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (!pars_[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
|
|
|
|
|
2004-08-15 00:01:45 +00:00
|
|
|
|
LyXFont LyXText::getLabelFont(Paragraph const & par) const
|
2001-08-03 18:28:11 +00:00
|
|
|
|
{
|
2004-08-15 00:01:45 +00:00
|
|
|
|
LyXLayout_ptr const & layout = par.layout();
|
2001-08-03 18:28:11 +00:00
|
|
|
|
|
2004-08-15 00:01:45 +00:00
|
|
|
|
if (!par.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-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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
|
void LyXText::setCharFont(pit_type 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;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
LyXLayout_ptr const & layout = pars_[pit].layout();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Get concrete layout font to reduce against
|
|
|
|
|
LyXFont layoutfont;
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (pos < pars_[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
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (pars_[pit].getDepth()) {
|
2004-11-24 21:53:46 +00:00
|
|
|
|
pit_type tp = pit;
|
2003-04-16 08:12:22 +00:00
|
|
|
|
while (!layoutfont.resolved() &&
|
2004-11-24 21:53:46 +00:00
|
|
|
|
tp != pit_type(paragraphs().size()) &&
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pars_[tp].getDepth()) {
|
2003-12-01 13:35:49 +00:00
|
|
|
|
tp = outerHook(tp, paragraphs());
|
2004-11-24 21:53:46 +00:00
|
|
|
|
if (tp != pit_type(paragraphs().size()))
|
2004-03-25 09:16:36 +00:00
|
|
|
|
layoutfont.realize(pars_[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);
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pars_[pit].setFont(pos, font);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-09 09:04:33 +00:00
|
|
|
|
// return past-the-last paragraph influenced by a layout change on pit
|
2004-11-24 21:53:46 +00:00
|
|
|
|
pit_type LyXText::undoSpan(pit_type pit)
|
2004-01-09 09:04:33 +00:00
|
|
|
|
{
|
2004-11-24 21:53:46 +00:00
|
|
|
|
pit_type end = paragraphs().size();
|
|
|
|
|
pit_type nextpit = pit + 1;
|
2004-01-09 09:04:33 +00:00
|
|
|
|
if (nextpit == end)
|
|
|
|
|
return nextpit;
|
|
|
|
|
//because of parindents
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (!pars_[pit].getDepth())
|
2004-01-09 09:04:33 +00:00
|
|
|
|
return boost::next(nextpit);
|
|
|
|
|
//because of depth constrains
|
|
|
|
|
for (; nextpit != end; ++pit, ++nextpit) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (!pars_[pit].getDepth())
|
2004-01-09 09:04:33 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return nextpit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-11-28 11:52:03 +00:00
|
|
|
|
void LyXText::setLayout(pit_type start, pit_type end, string const & layout)
|
2001-04-04 21:47:26 +00:00
|
|
|
|
{
|
2004-01-09 09:04:33 +00:00
|
|
|
|
BOOST_ASSERT(start != end);
|
2002-03-02 16:39:54 +00:00
|
|
|
|
|
2003-09-09 09:47:59 +00:00
|
|
|
|
BufferParams const & bufparams = bv()->buffer()->params();
|
2004-03-25 09:16:36 +00:00
|
|
|
|
LyXLayout_ptr const & lyxlayout = bufparams.getLyXTextClass()[layout];
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
|
for (pit_type pit = start; pit != end; ++pit) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pars_[pit].applyLayout(lyxlayout);
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (lyxlayout->margintype == MARGIN_MANUAL)
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pars_[pit].setLabelWidthString(lyxlayout->labelstring());
|
2003-12-08 12:47:18 +00:00
|
|
|
|
}
|
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
|
2004-02-13 07:30:59 +00:00
|
|
|
|
void LyXText::setLayout(LCursor & cur, string const & layout)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2003-05-19 07:12:09 +00:00
|
|
|
|
// special handling of new environment insets
|
2004-04-08 15:03:33 +00:00
|
|
|
|
BufferView & bv = cur.bv();
|
|
|
|
|
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
|
2004-06-18 13:31:55 +00:00
|
|
|
|
lyxerr[Debug::DEBUG] << "setting layout " << layout << endl;
|
2004-04-08 15:03:33 +00:00
|
|
|
|
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-13 07:30:59 +00:00
|
|
|
|
insertInset(cur, inset);
|
2004-02-13 13:51:12 +00:00
|
|
|
|
//inset->edit(cur, true);
|
2004-04-08 15:03:33 +00:00
|
|
|
|
//bv.owner()->dispatch(FuncRequest(LFUN_PASTE));
|
2003-05-19 07:12:09 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
|
pit_type start = cur.selBegin().pit();
|
|
|
|
|
pit_type end = cur.selEnd().pit() + 1;
|
2005-11-28 11:52:03 +00:00
|
|
|
|
pit_type undopit = undoSpan(end - 1);
|
|
|
|
|
recUndo(start, undopit - 1);
|
2004-12-29 11:39:17 +00:00
|
|
|
|
setLayout(start, end, layout);
|
2005-02-25 11:55:36 +00:00
|
|
|
|
updateCounters(cur.buffer());
|
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
|
|
|
|
|
2004-03-18 13:57:20 +00:00
|
|
|
|
bool changeDepthAllowed(LyXText::DEPTH_CHANGE type,
|
2005-09-26 22:54:12 +00:00
|
|
|
|
Paragraph const & par, int max_depth)
|
2003-11-26 09:48:21 +00:00
|
|
|
|
{
|
|
|
|
|
if (par.layout()->labeltype == LABEL_BIBLIO)
|
|
|
|
|
return false;
|
|
|
|
|
int const depth = par.params().depth();
|
2004-03-18 13:57:20 +00:00
|
|
|
|
if (type == LyXText::INC_DEPTH && depth < max_depth)
|
2003-11-26 09:48:21 +00:00
|
|
|
|
return true;
|
2004-03-18 13:57:20 +00:00
|
|
|
|
if (type == LyXText::DEC_DEPTH && depth > 0)
|
2003-11-26 09:48:21 +00:00
|
|
|
|
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
|
|
|
|
|
2004-03-18 13:57:20 +00:00
|
|
|
|
bool LyXText::changeDepthAllowed(LCursor & cur, DEPTH_CHANGE type) const
|
2003-11-26 09:48:21 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2004-12-06 12:55:03 +00:00
|
|
|
|
pit_type const beg = cur.selBegin().pit();
|
|
|
|
|
pit_type const end = cur.selEnd().pit() + 1;
|
|
|
|
|
int max_depth = (beg != 0 ? pars_[beg - 1].getMaxDepthAfter() : 0);
|
2003-04-02 21:19:35 +00:00
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
|
for (pit_type pit = beg; pit != end; ++pit) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (::changeDepthAllowed(type, pars_[pit], max_depth))
|
2003-11-26 09:48:21 +00:00
|
|
|
|
return true;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
max_depth = pars_[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
|
|
|
|
|
2004-03-18 13:57:20 +00:00
|
|
|
|
void LyXText::changeDepth(LCursor & cur, DEPTH_CHANGE type)
|
2003-11-26 09:48:21 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2004-12-06 12:55:03 +00:00
|
|
|
|
pit_type const beg = cur.selBegin().pit();
|
|
|
|
|
pit_type const end = cur.selEnd().pit() + 1;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
recordUndoSelection(cur);
|
2004-12-06 12:55:03 +00:00
|
|
|
|
int max_depth = (beg != 0 ? pars_[beg - 1].getMaxDepthAfter() : 0);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
|
for (pit_type pit = beg; pit != end; ++pit) {
|
2004-11-30 01:59:49 +00:00
|
|
|
|
Paragraph & par = pars_[pit];
|
|
|
|
|
if (::changeDepthAllowed(type, par, max_depth)) {
|
|
|
|
|
int const depth = par.params().depth();
|
2004-03-18 13:57:20 +00:00
|
|
|
|
if (type == INC_DEPTH)
|
2004-11-30 01:59:49 +00:00
|
|
|
|
par.params().depth(depth + 1);
|
2003-11-26 09:48:21 +00:00
|
|
|
|
else
|
2004-11-30 01:59:49 +00:00
|
|
|
|
par.params().depth(depth - 1);
|
2003-11-26 09:48:21 +00:00
|
|
|
|
}
|
2004-11-30 01:59:49 +00:00
|
|
|
|
max_depth = par.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
|
2005-02-25 11:55:36 +00:00
|
|
|
|
updateCounters(cur.buffer());
|
2001-05-31 02:23:46 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// set font over selection
|
2004-02-13 07:30:59 +00:00
|
|
|
|
void LyXText::setFont(LCursor & cur, LyXFont const & font, bool toggleall)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
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-11-24 21:53:46 +00:00
|
|
|
|
pit_type pit = cur.pit();
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (cur.pos() < pars_[pit].beginOfBody())
|
2004-08-15 00:01:45 +00:00
|
|
|
|
layoutfont = getLabelFont(pars_[pit]);
|
2003-12-08 12:47:18 +00:00
|
|
|
|
else
|
2004-02-13 07:30:59 +00:00
|
|
|
|
layoutfont = getLayoutFont(pit);
|
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,
|
2004-04-08 15:03:33 +00:00
|
|
|
|
cur.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;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-01 17:12:09 +00:00
|
|
|
|
// Ok, we have a selection.
|
2004-02-13 07:30:59 +00:00
|
|
|
|
recordUndoSelection(cur);
|
2003-11-27 09:22:41 +00:00
|
|
|
|
|
2004-08-15 00:01:45 +00:00
|
|
|
|
DocIterator dit = cur.selectionBegin();
|
|
|
|
|
DocIterator ditend = cur.selectionEnd();
|
2004-04-07 08:07:26 +00:00
|
|
|
|
|
2004-04-08 15:03:33 +00:00
|
|
|
|
BufferParams const & params = cur.buffer().params();
|
2003-11-27 09:22:41 +00:00
|
|
|
|
|
2004-08-15 00:01:45 +00:00
|
|
|
|
// Don't use forwardChar here as ditend might have
|
2004-04-07 08:07:26 +00:00
|
|
|
|
// pos() == lastpos() and forwardChar would miss it.
|
2005-02-14 08:17:23 +00:00
|
|
|
|
// Can't use forwardPos either as this descends into
|
2005-04-26 11:12:20 +00:00
|
|
|
|
// nested insets.
|
2005-02-14 08:17:23 +00:00
|
|
|
|
for (; dit != ditend; dit.forwardPosNoDescend()) {
|
2004-08-15 00:01:45 +00:00
|
|
|
|
if (dit.pos() != dit.lastpos()) {
|
|
|
|
|
LyXFont f = getFont(dit.paragraph(), dit.pos());
|
2004-04-07 08:07:26 +00:00
|
|
|
|
f.update(font, params.language, toggleall);
|
2004-11-24 21:53:46 +00:00
|
|
|
|
setCharFont(dit.pit(), dit.pos(), f);
|
2004-04-07 08:07:26 +00:00
|
|
|
|
}
|
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-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2005-07-17 12:02:48 +00:00
|
|
|
|
Row const & row = cur.paragraph().getRow(cur.pos(),cur.boundary());
|
|
|
|
|
|
|
|
|
|
setCursor(cur, cur.pit(), row.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
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2003-11-10 09:06:48 +00:00
|
|
|
|
// if not on the last row of the par, put the cursor before
|
2005-07-16 23:54:32 +00:00
|
|
|
|
// the final space exept if I have a spanning inset or one string
|
|
|
|
|
// is so long that we force a break.
|
|
|
|
|
pos_type end = cur.textRow().endpos();
|
2005-09-05 06:50:42 +00:00
|
|
|
|
if (end == 0)
|
|
|
|
|
// empty text, end-1 is no valid position
|
|
|
|
|
return;
|
2005-07-16 23:54:32 +00:00
|
|
|
|
bool boundary = false;
|
2005-09-15 13:53:38 +00:00
|
|
|
|
if (end != cur.lastpos()) {
|
2005-09-26 22:54:12 +00:00
|
|
|
|
if (!cur.paragraph().isLineSeparator(end-1)
|
|
|
|
|
&& !cur.paragraph().isNewline(end-1))
|
2005-09-15 13:53:38 +00:00
|
|
|
|
boundary = true;
|
|
|
|
|
else
|
|
|
|
|
--end;
|
|
|
|
|
}
|
2005-07-16 23:54:32 +00:00
|
|
|
|
setCursor(cur, cur.pit(), end, true, boundary);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-13 11:05:29 +00:00
|
|
|
|
void LyXText::cursorTop(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
|
|
|
|
setCursor(cur, 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-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2004-11-24 21:53:46 +00:00
|
|
|
|
setCursor(cur, cur.lastpit(), boost::prior(paragraphs().end())->size());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
|
|
|
|
|
2004-02-13 07:30:59 +00:00
|
|
|
|
void LyXText::toggleFree(LCursor & cur, LyXFont const & font, bool toggleall)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
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
|
2004-02-13 07:30:59 +00:00
|
|
|
|
cur.message(_("No font change defined. "
|
2005-09-26 22:54:12 +00:00
|
|
|
|
"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-03-01 17:12:09 +00:00
|
|
|
|
CursorSlice resetCursor = cur.top();
|
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
|
2004-02-13 07:30:59 +00:00
|
|
|
|
&& selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD_STRICT);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Set font
|
2004-02-13 07:30:59 +00:00
|
|
|
|
setFont(cur, font, toggleall);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// Implicit selections are cleared afterwards
|
2004-02-13 07:30:59 +00:00
|
|
|
|
// and cursor is set to the original position.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (implicitSelection) {
|
2004-02-13 07:30:59 +00:00
|
|
|
|
cur.clearSelection();
|
2004-03-01 17:12:09 +00:00
|
|
|
|
cur.top() = resetCursor;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
cur.resetAnchor();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-05-30 15:35:11 +00:00
|
|
|
|
string LyXText::getStringToIndex(LCursor const & cur)
|
2001-07-30 10:50:37 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2001-07-30 10:50:37 +00:00
|
|
|
|
|
2003-01-31 13:50:21 +00:00
|
|
|
|
string idxstring;
|
2005-05-30 15:35:11 +00:00
|
|
|
|
if (cur.selection()) {
|
2004-02-11 14:45:44 +00:00
|
|
|
|
idxstring = cur.selectionAsString(false);
|
2005-05-30 15:35:11 +00:00
|
|
|
|
} else {
|
|
|
|
|
// Try implicit word selection. If there is a change
|
|
|
|
|
// in the language the implicit word selection is
|
|
|
|
|
// disabled.
|
|
|
|
|
LCursor tmpcur = cur;
|
|
|
|
|
selectWord(tmpcur, lyx::PREVIOUS_WORD);
|
|
|
|
|
|
|
|
|
|
if (!tmpcur.selection())
|
|
|
|
|
cur.message(_("Nothing to index!"));
|
|
|
|
|
else if (tmpcur.selBegin().pit() != tmpcur.selEnd().pit())
|
|
|
|
|
cur.message(_("Cannot index more than one paragraph!"));
|
|
|
|
|
else
|
|
|
|
|
idxstring = tmpcur.selectionAsString(false);
|
|
|
|
|
}
|
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
|
|
|
|
|
2004-02-13 11:05:29 +00:00
|
|
|
|
void LyXText::setParagraph(LCursor & cur,
|
2005-09-26 22:54:12 +00:00
|
|
|
|
Spacing const & spacing, LyXAlignment align,
|
|
|
|
|
string const & labelwidthstring, bool noindent)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(cur.text());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// make sure that the depth behind the selection are restored, too
|
2004-11-24 21:53:46 +00:00
|
|
|
|
pit_type undopit = undoSpan(cur.selEnd().pit());
|
|
|
|
|
recUndo(cur.selBegin().pit(), undopit - 1);
|
2003-04-13 22:24:28 +00:00
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
|
for (pit_type pit = cur.selBegin().pit(), end = cur.selEnd().pit();
|
2005-09-26 22:54:12 +00:00
|
|
|
|
pit <= end; ++pit) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
Paragraph & par = pars_[pit];
|
|
|
|
|
ParagraphParameters & params = par.params();
|
2003-04-13 22:24:28 +00:00
|
|
|
|
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?
|
2004-03-25 09:16:36 +00:00
|
|
|
|
LyXLayout_ptr const & layout = par.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
|
|
|
|
}
|
2004-03-25 09:16:36 +00:00
|
|
|
|
par.setLabelWidthString(labelwidthstring);
|
2003-04-13 22:24:28 +00:00
|
|
|
|
params.noindent(noindent);
|
1999-11-04 01:40:20 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-08-16 00:32:04 +00:00
|
|
|
|
// this really should just insert the inset and not move the cursor.
|
2004-02-13 07:30:59 +00:00
|
|
|
|
void LyXText::insertInset(LCursor & cur, InsetBase * inset)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2004-03-08 21:14:45 +00:00
|
|
|
|
BOOST_ASSERT(inset);
|
2004-02-13 07:30:59 +00:00
|
|
|
|
cur.paragraph().insertInset(cur.pos(), inset);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// needed to insert the selection
|
2004-02-13 07:30:59 +00:00
|
|
|
|
void LyXText::insertStringAsLines(LCursor & cur, string const & str)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2005-09-26 22:54:12 +00:00
|
|
|
|
cur.buffer().insertStringAsLines(pars_, cur.pit(), cur.pos(),
|
|
|
|
|
current_font, str, autoBreakRows_);
|
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
|
2004-02-13 07:30:59 +00:00
|
|
|
|
void LyXText::insertStringAsParagraphs(LCursor & cur, string const & str)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2004-02-13 07:30:59 +00:00
|
|
|
|
string linestr = str;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
bool newline_inserted = false;
|
2003-06-18 17:43:49 +00:00
|
|
|
|
|
2004-02-13 07:30:59 +00:00
|
|
|
|
for (string::size_type i = 0, siz = linestr.size(); 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
|
|
|
|
}
|
|
|
|
|
}
|
2004-02-13 07:30:59 +00:00
|
|
|
|
insertStringAsLines(cur, linestr);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
|
bool LyXText::setCursor(LCursor & cur, pit_type par, pos_type pos,
|
2005-09-26 22:54:12 +00:00
|
|
|
|
bool setfont, bool boundary)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
LCursor old = cur;
|
2004-02-13 11:05:29 +00:00
|
|
|
|
setCursorIntern(cur, par, pos, setfont, boundary);
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return deleteEmptyParagraphMechanism(cur, old);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
2005-09-20 08:31:37 +00:00
|
|
|
|
void LyXText::setCursor(CursorSlice & cur, pit_type par, pos_type pos)
|
2000-04-19 14:42:19 +00:00
|
|
|
|
{
|
2003-12-01 13:35:49 +00:00
|
|
|
|
BOOST_ASSERT(par != int(paragraphs().size()));
|
2004-11-24 21:53:46 +00:00
|
|
|
|
cur.pit() = par;
|
2004-02-16 11:58:51 +00:00
|
|
|
|
cur.pos() = pos;
|
2003-10-08 14:29:16 +00:00
|
|
|
|
|
2004-01-14 09:33:14 +00:00
|
|
|
|
// now some strict checking
|
2004-03-25 09:16:36 +00:00
|
|
|
|
Paragraph & para = getPar(par);
|
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;
|
|
|
|
|
BOOST_ASSERT(false);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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()
|
2004-02-13 11:05:29 +00:00
|
|
|
|
<< " par: " << par << endl;
|
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
|
|
|
|
|
2004-02-13 11:05:29 +00:00
|
|
|
|
void LyXText::setCursorIntern(LCursor & cur,
|
2005-09-26 22:54:12 +00:00
|
|
|
|
pit_type par, pos_type pos, bool setfont, bool boundary)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2005-07-16 16:34:54 +00:00
|
|
|
|
cur.boundary(boundary);
|
2005-09-20 08:31:37 +00:00
|
|
|
|
setCursor(cur.top(), par, pos);
|
2004-11-30 01:59:49 +00:00
|
|
|
|
cur.setTargetX();
|
2001-08-05 22:12:27 +00:00
|
|
|
|
if (setfont)
|
2004-02-13 11:05:29 +00:00
|
|
|
|
setCurrentFont(cur);
|
2000-05-30 19:31:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-09-23 04:57:18 +00:00
|
|
|
|
|
2004-02-13 11:05:29 +00:00
|
|
|
|
void LyXText::setCurrentFont(LCursor & cur)
|
2000-05-30 19:31:11 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2004-01-20 14:25:24 +00:00
|
|
|
|
pos_type pos = cur.pos();
|
2004-08-15 00:01:45 +00:00
|
|
|
|
Paragraph & par = cur.paragraph();
|
2003-04-13 22:24:28 +00:00
|
|
|
|
|
2004-02-13 11:05:29 +00:00
|
|
|
|
if (cur.boundary() && pos > 0)
|
2000-05-30 19:31:11 +00:00
|
|
|
|
--pos;
|
|
|
|
|
|
|
|
|
|
if (pos > 0) {
|
2004-02-13 11:05:29 +00:00
|
|
|
|
if (pos == cur.lastpos())
|
2000-05-30 19:31:11 +00:00
|
|
|
|
--pos;
|
2001-05-30 13:17:50 +00:00
|
|
|
|
else // potentional bug... BUG (Lgb)
|
2004-08-15 00:01:45 +00:00
|
|
|
|
if (par.isSeparator(pos)) {
|
2004-02-13 11:05:29 +00:00
|
|
|
|
if (pos > cur.textRow().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;
|
2004-02-13 11:05:29 +00:00
|
|
|
|
else if (pos + 1 < cur.lastpos())
|
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
|
|
|
|
|
2004-04-08 15:03:33 +00:00
|
|
|
|
BufferParams const & bufparams = cur.buffer().params();
|
2004-08-15 00:01:45 +00:00
|
|
|
|
current_font = par.getFontSettings(bufparams, pos);
|
|
|
|
|
real_current_font = getFont(par, pos);
|
2000-07-10 10:31:34 +00:00
|
|
|
|
|
2004-02-13 11:05:29 +00:00
|
|
|
|
if (cur.pos() == cur.lastpos()
|
2004-08-15 00:01:45 +00:00
|
|
|
|
&& bidi.isBoundary(cur.buffer(), par, cur.pos())
|
2004-02-13 11:05:29 +00:00
|
|
|
|
&& !cur.boundary()) {
|
2004-08-15 00:01:45 +00:00
|
|
|
|
Language const * lang = par.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-13 07:30:59 +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
|
2004-11-24 21:53:46 +00:00
|
|
|
|
pos_type LyXText::getColumnNearX(pit_type const pit,
|
2005-09-26 22:54:12 +00:00
|
|
|
|
Row const & row, int & x, bool & boundary) const
|
2003-03-10 05:03:33 +00:00
|
|
|
|
{
|
2004-11-30 01:59:49 +00:00
|
|
|
|
int const xo = theCoords.get(this, pit).x_;
|
|
|
|
|
x -= xo;
|
2004-03-01 16:29:30 +00:00
|
|
|
|
RowMetrics const r = computeRowMetrics(pit, row);
|
2004-08-15 00:01:45 +00:00
|
|
|
|
Paragraph const & par = pars_[pit];
|
2004-04-03 08:37:12 +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;
|
2004-08-15 00:01:45 +00:00
|
|
|
|
LyXLayout_ptr const & layout = par.layout();
|
2003-03-10 05:03:33 +00:00
|
|
|
|
|
|
|
|
|
bool left_side = false;
|
|
|
|
|
|
2004-08-15 00:01:45 +00:00
|
|
|
|
pos_type body_pos = par.beginOfBody();
|
2004-03-01 12:23:17 +00:00
|
|
|
|
|
|
|
|
|
double tmpx = r.x;
|
2003-07-28 12:20:42 +00:00
|
|
|
|
double last_tmpx = tmpx;
|
2003-03-10 05:03:33 +00:00
|
|
|
|
|
|
|
|
|
if (body_pos > 0 &&
|
2004-08-15 00:01:45 +00:00
|
|
|
|
(body_pos > end || !par.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-11-30 01:59:49 +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) {
|
2004-03-01 12:23:17 +00:00
|
|
|
|
tmpx += r.label_hfill +
|
2004-08-15 00:01:45 +00:00
|
|
|
|
font_metrics::width(layout->labelsep, getLabelFont(par));
|
|
|
|
|
if (par.isLineSeparator(body_pos - 1))
|
|
|
|
|
tmpx -= singleWidth(par, body_pos - 1);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-08-15 00:01:45 +00:00
|
|
|
|
if (hfillExpansion(par, row, c)) {
|
|
|
|
|
tmpx += singleWidth(par, c);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
if (c >= body_pos)
|
2004-03-01 12:23:17 +00:00
|
|
|
|
tmpx += r.hfill;
|
2003-03-10 05:03:33 +00:00
|
|
|
|
else
|
2004-03-01 12:23:17 +00:00
|
|
|
|
tmpx += r.label_hfill;
|
2004-08-15 00:01:45 +00:00
|
|
|
|
} else if (par.isSeparator(c)) {
|
|
|
|
|
tmpx += singleWidth(par, c);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
if (c >= body_pos)
|
2004-03-01 12:23:17 +00:00
|
|
|
|
tmpx += r.separator;
|
2003-03-10 05:03:33 +00:00
|
|
|
|
} else {
|
2004-08-15 00:01:45 +00:00
|
|
|
|
tmpx += singleWidth(par, 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
|
2004-08-15 00:01:45 +00:00
|
|
|
|
bool const lastrow = lyxrc.rtl_support && row.endpos() == par.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-08-15 00:01:45 +00:00
|
|
|
|
bool const rtl = lastrow ? isRTL(par) : false;
|
2003-03-10 05:03:33 +00:00
|
|
|
|
if (lastrow &&
|
2005-09-26 22:54:12 +00:00
|
|
|
|
((rtl && left_side && vc == row.pos() && x < tmpx - 5) ||
|
|
|
|
|
(!rtl && !left_side && vc == end && x > tmpx + 5)))
|
2003-10-27 11:44:10 +00:00
|
|
|
|
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;
|
2004-08-15 00:01:45 +00:00
|
|
|
|
boundary = bidi.isBoundary(*bv()->buffer(), par, c);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-16 23:54:32 +00:00
|
|
|
|
// I believe this code is not needed anymore (Jug 20050717)
|
|
|
|
|
#if 0
|
2005-03-11 14:20:58 +00:00
|
|
|
|
// The following code is necessary because the cursor position past
|
|
|
|
|
// the last char in a row is logically equivalent to that before
|
|
|
|
|
// the first char in the next row. That's why insets causing row
|
|
|
|
|
// divisions -- Newline and display-style insets -- must be treated
|
|
|
|
|
// specially, so cursor up/down doesn't get stuck in an air gap -- MV
|
|
|
|
|
// Newline inset, air gap below:
|
2004-08-15 00:01:45 +00:00
|
|
|
|
if (row.pos() < end && c >= end && par.isNewline(end - 1)) {
|
2003-10-27 11:44:10 +00:00
|
|
|
|
if (bidi.level(end -1) % 2 == 0)
|
2004-08-15 00:01:45 +00:00
|
|
|
|
tmpx -= singleWidth(par, end - 1);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
else
|
2004-08-15 00:01:45 +00:00
|
|
|
|
tmpx += singleWidth(par, end - 1);
|
2003-10-27 11:44:10 +00:00
|
|
|
|
c = end - 1;
|
2003-03-10 05:03:33 +00:00
|
|
|
|
}
|
2005-07-16 15:18:14 +00:00
|
|
|
|
|
2005-03-11 14:20:58 +00:00
|
|
|
|
// Air gap above display inset:
|
|
|
|
|
if (row.pos() < end && c >= end && end < par.size()
|
2005-03-08 10:02:03 +00:00
|
|
|
|
&& par.isInset(end) && par.getInset(end)->display()) {
|
|
|
|
|
c = end - 1;
|
|
|
|
|
}
|
2005-03-11 14:20:58 +00:00
|
|
|
|
// Air gap below display inset:
|
2005-04-26 11:12:20 +00:00
|
|
|
|
if (row.pos() < end && c >= end && par.isInset(end - 1)
|
2005-03-11 14:20:58 +00:00
|
|
|
|
&& par.getInset(end - 1)->display()) {
|
|
|
|
|
c = end - 1;
|
|
|
|
|
}
|
2005-07-16 23:54:32 +00:00
|
|
|
|
#endif
|
2005-03-08 10:02:03 +00:00
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
x = int(tmpx) + xo;
|
2005-07-18 20:34:55 +00:00
|
|
|
|
pos_type const col = c - row.pos();
|
2005-07-15 12:56:23 +00:00
|
|
|
|
|
2005-09-26 22:54:12 +00:00
|
|
|
|
if (!c || end == par.size())
|
|
|
|
|
return col;
|
2005-07-15 12:56:23 +00:00
|
|
|
|
|
2005-07-16 23:54:32 +00:00
|
|
|
|
if (c==end && !par.isLineSeparator(c-1) && !par.isNewline(c-1)) {
|
2005-07-16 11:03:01 +00:00
|
|
|
|
boundary = true;
|
2005-07-16 21:19:36 +00:00
|
|
|
|
return col;
|
2005-07-16 11:03:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-09-26 22:54:12 +00:00
|
|
|
|
return min(col, end - 1 - row.pos());
|
2003-03-10 05:03:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
// y is screen coordinate
|
|
|
|
|
pit_type LyXText::getPitNearY(int y) const
|
2004-08-14 21:56:40 +00:00
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(!paragraphs().empty());
|
2005-01-31 16:29:48 +00:00
|
|
|
|
BOOST_ASSERT(theCoords.getParPos().find(this) != theCoords.getParPos().end());
|
|
|
|
|
CoordCache::InnerParPosCache const & cc = theCoords.getParPos().find(this)->second;
|
2005-07-14 08:20:10 +00:00
|
|
|
|
lyxerr[Debug::DEBUG]
|
2005-09-26 22:54:12 +00:00
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< ": y: " << y << " cache size: " << cc.size()
|
|
|
|
|
<< endl;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
|
|
|
|
|
// look for highest numbered paragraph with y coordinate less than given y
|
|
|
|
|
pit_type pit = 0;
|
|
|
|
|
int yy = -1;
|
|
|
|
|
CoordCache::InnerParPosCache::const_iterator it = cc.begin();
|
|
|
|
|
CoordCache::InnerParPosCache::const_iterator et = cc.end();
|
|
|
|
|
for (; it != et; ++it) {
|
2005-07-14 08:20:10 +00:00
|
|
|
|
lyxerr[Debug::DEBUG]
|
2005-09-26 22:54:12 +00:00
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< " examining: pit: " << it->first
|
|
|
|
|
<< " y: " << it->second.y_
|
|
|
|
|
<< endl;
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
if (it->first >= pit && int(it->second.y_) - int(pars_[it->first].ascent()) <= y) {
|
|
|
|
|
pit = it->first;
|
|
|
|
|
yy = it->second.y_;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-08-14 21:56:40 +00:00
|
|
|
|
|
2005-07-14 08:20:10 +00:00
|
|
|
|
lyxerr[Debug::DEBUG]
|
2005-09-26 22:54:12 +00:00
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< ": found best y: " << yy << " for pit: " << pit
|
|
|
|
|
<< endl;
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
return pit;
|
2004-08-14 21:56:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
Row const & LyXText::getRowNearY(int y, pit_type pit) const
|
2000-03-27 15:13:47 +00:00
|
|
|
|
{
|
2004-11-30 01:59:49 +00:00
|
|
|
|
Paragraph const & par = pars_[pit];
|
|
|
|
|
int yy = theCoords.get(this, pit).y_ - par.ascent();
|
|
|
|
|
BOOST_ASSERT(!par.rows().empty());
|
|
|
|
|
RowList::const_iterator rit = par.rows().begin();
|
|
|
|
|
RowList::const_iterator const rlast = boost::prior(par.rows().end());
|
|
|
|
|
for (; rit != rlast; yy += rit->height(), ++rit)
|
|
|
|
|
if (yy + rit->height() > y)
|
|
|
|
|
break;
|
|
|
|
|
return *rit;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-02-08 02:06:39 +00:00
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
// x,y are absolute screen coordinates
|
2004-08-14 19:55:00 +00:00
|
|
|
|
// sets cursor recursively descending into nested editable insets
|
2005-07-15 00:39:44 +00:00
|
|
|
|
InsetBase * LyXText::editXY(LCursor & cur, int x, int y)
|
2004-01-30 11:41:12 +00:00
|
|
|
|
{
|
2004-11-30 01:59:49 +00:00
|
|
|
|
pit_type pit = getPitNearY(y);
|
|
|
|
|
BOOST_ASSERT(pit != -1);
|
|
|
|
|
Row const & row = getRowNearY(y, 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);
|
2004-11-24 21:53:46 +00:00
|
|
|
|
cur.pit() = pit;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
cur.pos() = pos;
|
2005-07-15 15:49:40 +00:00
|
|
|
|
cur.boundary(bound);
|
2004-11-30 01:59:49 +00:00
|
|
|
|
cur.x_target() = x;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
|
|
|
|
|
// try to descend into nested insets
|
|
|
|
|
InsetBase * inset = checkInsetHit(x, y);
|
2005-07-15 08:51:34 +00:00
|
|
|
|
//lyxerr << "inset " << inset << " hit at x: " << x << " y: " << y << endl;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
if (!inset) {
|
2005-02-08 02:06:39 +00:00
|
|
|
|
// Either we deconst editXY or better we move current_font
|
|
|
|
|
// and real_current_font to LCursor
|
2005-07-15 00:39:44 +00:00
|
|
|
|
setCurrentFont(cur);
|
2004-02-13 13:51:12 +00:00
|
|
|
|
return 0;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
}
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2004-02-13 13:51:12 +00:00
|
|
|
|
// This should be just before or just behind the
|
|
|
|
|
// cursor position set above.
|
2004-03-25 09:16:36 +00:00
|
|
|
|
BOOST_ASSERT((pos != 0 && inset == pars_[pit].getInset(pos - 1))
|
|
|
|
|
|| inset == pars_[pit].getInset(pos));
|
2004-02-13 13:51:12 +00:00
|
|
|
|
// Make sure the cursor points to the position before
|
|
|
|
|
// this inset.
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (inset == pars_[pit].getInset(pos - 1))
|
2004-02-13 13:51:12 +00:00
|
|
|
|
--cur.pos();
|
2004-11-30 01:59:49 +00:00
|
|
|
|
inset = inset->editXY(cur, x, y);
|
|
|
|
|
if (cur.top().text() == this)
|
2005-07-15 00:39:44 +00:00
|
|
|
|
setCurrentFont(cur);
|
2004-11-30 01:59:49 +00:00
|
|
|
|
return inset;
|
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-20 17:19:53 +00:00
|
|
|
|
if (cur.selection())
|
|
|
|
|
return false;
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-02-08 02:06:39 +00:00
|
|
|
|
bool LyXText::cursorLeft(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2005-07-17 09:52:52 +00:00
|
|
|
|
if (!cur.boundary() && cur.pos() > 0 &&
|
2005-07-16 23:54:32 +00:00
|
|
|
|
cur.textRow().pos() == cur.pos() &&
|
|
|
|
|
!cur.paragraph().isLineSeparator(cur.pos()-1) &&
|
2005-09-26 22:54:12 +00:00
|
|
|
|
!cur.paragraph().isNewline(cur.pos()-1)) {
|
2005-07-16 23:54:32 +00:00
|
|
|
|
return setCursor(cur, cur.pit(), cur.pos(), true, true);
|
|
|
|
|
}
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.pos() != 0) {
|
2004-01-20 14:25:24 +00:00
|
|
|
|
bool boundary = cur.boundary();
|
2005-02-08 02:06:39 +00:00
|
|
|
|
bool updateNeeded = setCursor(cur, cur.pit(), cur.pos() - 1, true, false);
|
2004-02-20 17:19:53 +00:00
|
|
|
|
if (!checkAndActivateInset(cur, false)) {
|
|
|
|
|
if (false && !boundary &&
|
2005-09-26 22:54:12 +00:00
|
|
|
|
bidi.isBoundary(cur.buffer(), cur.paragraph(), cur.pos() + 1))
|
2005-02-08 02:06:39 +00:00
|
|
|
|
updateNeeded |=
|
|
|
|
|
setCursor(cur, cur.pit(), cur.pos() + 1, true, true);
|
2004-02-20 17:19:53 +00:00
|
|
|
|
}
|
2005-02-08 02:06:39 +00:00
|
|
|
|
return updateNeeded;
|
2003-11-17 14:28:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
|
if (cur.pit() != 0) {
|
2005-02-08 02:06:39 +00:00
|
|
|
|
// Steps into the paragraph above
|
|
|
|
|
return setCursor(cur, cur.pit() - 1, getPar(cur.pit() - 1).size());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2005-02-08 02:06:39 +00:00
|
|
|
|
return false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-02-08 02:06:39 +00:00
|
|
|
|
bool LyXText::cursorRight(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-01-20 14:25:24 +00:00
|
|
|
|
if (cur.pos() != cur.lastpos()) {
|
2005-09-26 22:54:12 +00:00
|
|
|
|
if (cur.boundary())
|
|
|
|
|
return setCursor(cur, cur.pit(), cur.pos(),
|
2005-09-21 10:38:24 +00:00
|
|
|
|
true, false);
|
|
|
|
|
|
2005-02-08 02:06:39 +00:00
|
|
|
|
bool updateNeeded = false;
|
2004-04-03 08:37:12 +00:00
|
|
|
|
if (!checkAndActivateInset(cur, true)) {
|
2005-09-15 13:53:38 +00:00
|
|
|
|
if (cur.textRow().endpos() == cur.pos() + 1 &&
|
|
|
|
|
cur.textRow().endpos() != cur.lastpos() &&
|
2005-07-16 23:54:32 +00:00
|
|
|
|
!cur.paragraph().isLineSeparator(cur.pos()) &&
|
2005-09-26 22:54:12 +00:00
|
|
|
|
!cur.paragraph().isNewline(cur.pos())) {
|
2005-07-16 23:54:32 +00:00
|
|
|
|
cur.boundary(true);
|
|
|
|
|
}
|
|
|
|
|
updateNeeded |= setCursor(cur, cur.pit(), cur.pos() + 1, true, cur.boundary());
|
2004-04-08 15:03:33 +00:00
|
|
|
|
if (false && bidi.isBoundary(cur.buffer(), cur.paragraph(),
|
2005-09-26 22:54:12 +00:00
|
|
|
|
cur.pos()))
|
2005-02-08 02:06:39 +00:00
|
|
|
|
updateNeeded |= setCursor(cur, cur.pit(), cur.pos(), true, true);
|
2004-02-20 17:19:53 +00:00
|
|
|
|
}
|
2005-02-08 02:06:39 +00:00
|
|
|
|
return updateNeeded;
|
2003-11-17 14:28:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
|
if (cur.pit() != cur.lastpit())
|
2005-02-08 02:06:39 +00:00
|
|
|
|
return setCursor(cur, cur.pit() + 1, 0);
|
|
|
|
|
return false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-02-08 02:06:39 +00:00
|
|
|
|
bool LyXText::cursorUp(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-11-30 01:59:49 +00:00
|
|
|
|
Paragraph const & par = cur.paragraph();
|
2005-07-16 16:34:54 +00:00
|
|
|
|
int row;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
int const x = cur.targetX();
|
2003-11-22 14:44:59 +00:00
|
|
|
|
|
2005-07-16 16:34:54 +00:00
|
|
|
|
if (cur.pos() && cur.boundary())
|
|
|
|
|
row = par.pos2row(cur.pos()-1);
|
|
|
|
|
else
|
|
|
|
|
row = par.pos2row(cur.pos());
|
|
|
|
|
|
2004-02-20 17:19:53 +00:00
|
|
|
|
if (!cur.selection()) {
|
2005-07-15 15:49:40 +00:00
|
|
|
|
int const y = bv_funcs::getPos(cur, cur.boundary()).y_;
|
2005-02-08 02:06:39 +00:00
|
|
|
|
LCursor old = cur;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
editXY(cur, x, y - par.rows()[row].ascent() - 1);
|
2005-10-13 14:48:27 +00:00
|
|
|
|
cur.clearSelection();
|
2005-02-08 02:06:39 +00:00
|
|
|
|
|
|
|
|
|
// This happens when you move out of an inset.
|
|
|
|
|
// And to give the DEPM the possibility of doing
|
|
|
|
|
// something we must provide it with two different
|
|
|
|
|
// cursors. (Lgb)
|
|
|
|
|
LCursor dummy = cur;
|
|
|
|
|
if (dummy == old)
|
|
|
|
|
++dummy.pos();
|
|
|
|
|
|
|
|
|
|
return deleteEmptyParagraphMechanism(dummy, old);
|
2004-11-30 01:59:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-02-08 02:06:39 +00:00
|
|
|
|
bool updateNeeded = false;
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
if (row > 0) {
|
2005-02-08 02:06:39 +00:00
|
|
|
|
updateNeeded |= setCursor(cur, cur.pit(),
|
|
|
|
|
x2pos(cur.pit(), row - 1, x));
|
2004-11-30 01:59:49 +00:00
|
|
|
|
} else if (cur.pit() > 0) {
|
|
|
|
|
--cur.pit();
|
2005-03-07 15:27:51 +00:00
|
|
|
|
//cannot use 'par' now
|
2005-07-18 11:00:15 +00:00
|
|
|
|
updateNeeded |= setCursor(cur, cur.pit(),
|
2005-09-26 22:54:12 +00:00
|
|
|
|
x2pos(cur.pit(), cur.paragraph().rows().size() - 1, x));
|
2002-04-16 14:10:39 +00:00
|
|
|
|
}
|
2004-11-30 01:59:49 +00:00
|
|
|
|
|
|
|
|
|
cur.x_target() = x;
|
2005-02-08 02:06:39 +00:00
|
|
|
|
|
|
|
|
|
return updateNeeded;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-02-08 02:06:39 +00:00
|
|
|
|
bool LyXText::cursorDown(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-11-30 01:59:49 +00:00
|
|
|
|
Paragraph const & par = cur.paragraph();
|
2005-07-16 16:34:54 +00:00
|
|
|
|
int row;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
int const x = cur.targetX();
|
2003-11-21 08:35:15 +00:00
|
|
|
|
|
2005-07-16 16:34:54 +00:00
|
|
|
|
if (cur.pos() && cur.boundary())
|
|
|
|
|
row = par.pos2row(cur.pos()-1);
|
|
|
|
|
else
|
|
|
|
|
row = par.pos2row(cur.pos());
|
|
|
|
|
|
2004-02-20 17:19:53 +00:00
|
|
|
|
if (!cur.selection()) {
|
2005-07-15 15:49:40 +00:00
|
|
|
|
int const y = bv_funcs::getPos(cur, cur.boundary()).y_;
|
2005-02-08 02:06:39 +00:00
|
|
|
|
LCursor old = cur;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
editXY(cur, x, y + par.rows()[row].descent() + 1);
|
2005-10-13 14:48:27 +00:00
|
|
|
|
cur.clearSelection();
|
2005-02-08 02:06:39 +00:00
|
|
|
|
|
|
|
|
|
// This happens when you move out of an inset.
|
|
|
|
|
// And to give the DEPM the possibility of doing
|
|
|
|
|
// something we must provide it with two different
|
|
|
|
|
// cursors. (Lgb)
|
|
|
|
|
LCursor dummy = cur;
|
|
|
|
|
if (dummy == old)
|
|
|
|
|
++dummy.pos();
|
|
|
|
|
|
|
|
|
|
bool const changed = deleteEmptyParagraphMechanism(dummy, old);
|
|
|
|
|
|
|
|
|
|
// Make sure that cur gets back whatever happened to dummy(Lgb)
|
|
|
|
|
if (changed)
|
|
|
|
|
cur = dummy;
|
|
|
|
|
|
|
|
|
|
return changed;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
}
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2005-02-08 02:06:39 +00:00
|
|
|
|
bool updateNeeded = false;
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
if (row + 1 < int(par.rows().size())) {
|
2005-02-08 02:06:39 +00:00
|
|
|
|
updateNeeded |= setCursor(cur, cur.pit(),
|
|
|
|
|
x2pos(cur.pit(), row + 1, x));
|
2004-11-30 01:59:49 +00:00
|
|
|
|
} else if (cur.pit() + 1 < int(paragraphs().size())) {
|
|
|
|
|
++cur.pit();
|
2005-02-08 02:06:39 +00:00
|
|
|
|
updateNeeded |= setCursor(cur, cur.pit(),
|
|
|
|
|
x2pos(cur.pit(), 0, x));
|
2002-04-16 14:10:39 +00:00
|
|
|
|
}
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
cur.x_target() = x;
|
2005-02-08 02:06:39 +00:00
|
|
|
|
|
|
|
|
|
return updateNeeded;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-02-08 02:06:39 +00:00
|
|
|
|
bool LyXText::cursorUpParagraph(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2005-02-08 02:06:39 +00:00
|
|
|
|
bool updated = false;
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.pos() > 0)
|
2005-02-08 02:06:39 +00:00
|
|
|
|
updated = setCursor(cur, cur.pit(), 0);
|
2004-11-24 21:53:46 +00:00
|
|
|
|
else if (cur.pit() != 0)
|
2005-02-08 02:06:39 +00:00
|
|
|
|
updated = setCursor(cur, cur.pit() - 1, 0);
|
|
|
|
|
return updated;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-02-08 02:06:39 +00:00
|
|
|
|
bool LyXText::cursorDownParagraph(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2005-02-08 02:06:39 +00:00
|
|
|
|
bool updated = false;
|
2004-11-24 21:53:46 +00:00
|
|
|
|
if (cur.pit() != cur.lastpit())
|
2005-02-08 02:06:39 +00:00
|
|
|
|
updated = setCursor(cur, cur.pit() + 1, 0);
|
2003-08-01 14:12:04 +00:00
|
|
|
|
else
|
2005-02-08 02:06:39 +00:00
|
|
|
|
updated = setCursor(cur, cur.pit(), cur.lastpos());
|
|
|
|
|
return updated;
|
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
|
|
|
|
{
|
2005-02-08 02:06:39 +00:00
|
|
|
|
// Do nothing if cursor is not in the paragraph where the
|
2004-02-13 13:51:12 +00:00
|
|
|
|
// deletion occured,
|
2004-11-24 21:53:46 +00:00
|
|
|
|
if (cur.pit() != where.pit())
|
2001-09-27 09:52:06 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2005-02-08 02:06:39 +00:00
|
|
|
|
// If cursor position is after the deletion place update it
|
2001-09-27 09:52:06 +00:00
|
|
|
|
if (cur.pos() > where.pos())
|
2004-02-12 16:36:01 +00:00
|
|
|
|
--cur.pos();
|
2001-09-27 09:52:06 +00:00
|
|
|
|
|
2005-02-08 02:06:39 +00:00
|
|
|
|
// Check also if we don't want to set the cursor on a spot behind the
|
2002-05-02 12:45:27 +00:00
|
|
|
|
// 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
|
|
|
|
|
2005-10-25 09:14:11 +00:00
|
|
|
|
bool LyXText::deleteEmptyParagraphMechanism(LCursor & cur, LCursor & old)
|
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.
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (cur.selection())
|
|
|
|
|
return false;
|
|
|
|
|
|
2004-06-18 13:31:55 +00:00
|
|
|
|
//lyxerr[Debug::DEBUG] << "DEPM: cur:\n" << cur << "old:\n" << old << endl;
|
2005-10-25 09:14:11 +00:00
|
|
|
|
// old should point to us
|
|
|
|
|
BOOST_ASSERT(old.text() == this);
|
|
|
|
|
|
|
|
|
|
Paragraph & oldpar = old.paragraph();
|
2003-10-10 09:01:23 +00:00
|
|
|
|
|
2000-03-14 23:33:15 +00:00
|
|
|
|
// We allow all kinds of "mumbo-jumbo" when freespacing.
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (oldpar.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.
|
|
|
|
|
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
|
2005-10-25 09:14:11 +00:00
|
|
|
|
beginning and then save right after the paste. (Lgb)
|
2000-01-13 16:28:54 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// If old.pos() == 0 and old.pos()(1) == LineSeparator
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// delete the LineSeparator.
|
|
|
|
|
// MISSING
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// If old.pos() == 1 and old.pos()(0) == LineSeparator
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// delete the LineSeparator.
|
|
|
|
|
// MISSING
|
|
|
|
|
|
2005-10-25 09:14:11 +00:00
|
|
|
|
bool const same_inset = &old.inset() == &cur.inset();
|
|
|
|
|
bool const same_par = same_inset && old.pit() == cur.pit();
|
|
|
|
|
bool const same_par_pos = same_par && old.pos() == cur.pos();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2005-10-25 09:14:11 +00:00
|
|
|
|
// If the chars around the old cursor were spaces, delete one of them.
|
|
|
|
|
if (!same_par_pos) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// Only if the cursor has really moved.
|
|
|
|
|
if (old.pos() > 0
|
|
|
|
|
&& old.pos() < oldpar.size()
|
|
|
|
|
&& oldpar.isLineSeparator(old.pos())
|
2005-08-01 12:37:25 +00:00
|
|
|
|
&& oldpar.isLineSeparator(old.pos() - 1)
|
|
|
|
|
&& oldpar.lookupChange(old.pos() - 1) != Change::DELETED) {
|
2005-03-05 10:59:29 +00:00
|
|
|
|
// We need to set the text to Change::INSERTED to
|
|
|
|
|
// get it erased properly
|
2005-10-25 09:14:11 +00:00
|
|
|
|
oldpar.setChange(old.pos() -1, Change::INSERTED);
|
|
|
|
|
oldpar.erase(old.pos() - 1);
|
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
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// correct all cursor parts
|
2005-10-25 09:14:11 +00:00
|
|
|
|
if (same_par) {
|
|
|
|
|
fixCursorAfterDelete(cur.top(), old.top());
|
|
|
|
|
cur.resetAnchor();
|
|
|
|
|
}
|
2005-02-08 02:06:39 +00:00
|
|
|
|
return true;
|
2000-03-14 23:33:15 +00:00
|
|
|
|
}
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// only do our magic if we changed paragraph
|
2005-10-25 09:14:11 +00:00
|
|
|
|
if (same_par)
|
2002-01-12 21:03:30 +00:00
|
|
|
|
return false;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// don't delete anything if this is the ONLY paragraph!
|
2005-10-25 09:14:11 +00:00
|
|
|
|
if (old.lastpit() == 0)
|
2002-01-12 21:03:30 +00:00
|
|
|
|
return false;
|
2000-01-13 16:28:54 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// Do not delete empty paragraphs with keepempty set.
|
|
|
|
|
if (oldpar.allowEmpty())
|
2002-01-12 21:03:30 +00:00
|
|
|
|
return false;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (oldpar.empty() || (oldpar.size() == 1 && oldpar.isLineSeparator(0))) {
|
|
|
|
|
// Delete old par.
|
2006-01-04 14:24:40 +00:00
|
|
|
|
recordUndo(old, Undo::ATOMIC,
|
|
|
|
|
old.pit(), min(old.pit() + 1, old.lastpit()));
|
2005-10-25 09:14:11 +00:00
|
|
|
|
ParagraphList & plist = old.text()->paragraphs();
|
|
|
|
|
plist.erase(plist.begin() + old.pit());
|
|
|
|
|
|
|
|
|
|
// see #warning above
|
|
|
|
|
if (cur.depth() >= old.depth()) {
|
|
|
|
|
CursorSlice & curslice = cur[old.depth() - 1];
|
|
|
|
|
if (&curslice.inset() == &old.inset()
|
|
|
|
|
&& curslice.pit() > old.pit()) {
|
|
|
|
|
--curslice.pit();
|
|
|
|
|
// since a paragraph has been deleted, all the
|
|
|
|
|
// insets after `old' have been copied and
|
|
|
|
|
// their address has changed. Therefore we
|
|
|
|
|
// need to `regenerate' cur. (JMarc)
|
|
|
|
|
cur.updateInsets(&(cur.bottom().inset()));
|
|
|
|
|
cur.resetAnchor();
|
|
|
|
|
}
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2005-10-25 09:14:11 +00:00
|
|
|
|
updateCounters(old.buffer());
|
2003-10-28 11:18:40 +00:00
|
|
|
|
return true;
|
2005-07-17 15:22:15 +00:00
|
|
|
|
}
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
2005-10-25 09:14:11 +00:00
|
|
|
|
if (oldpar.stripLeadingSpaces())
|
2004-03-25 09:16:36 +00:00
|
|
|
|
cur.resetAnchor();
|
|
|
|
|
|
2003-10-28 11:18:40 +00:00
|
|
|
|
return false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
|
void LyXText::recUndo(pit_type first, pit_type last) const
|
2003-10-13 10:59:31 +00:00
|
|
|
|
{
|
2004-02-03 08:56:28 +00:00
|
|
|
|
recordUndo(bv()->cursor(), Undo::ATOMIC, first, last);
|
2003-10-13 10:59:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
|
void LyXText::recUndo(pit_type par) const
|
2003-10-13 10:59:31 +00:00
|
|
|
|
{
|
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-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
|
|
|
|
}
|