2003-09-17 16:44:51 +00:00
|
|
|
|
/**
|
2007-04-26 14:56:30 +00:00
|
|
|
|
* \file Cursor.cpp
|
2003-09-17 16:44:51 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
2004-01-26 10:13:15 +00:00
|
|
|
|
* \author Alejandro Aguilar Sierra
|
|
|
|
|
* \author Alfredo Braunstein
|
2003-11-04 12:36:59 +00:00
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
2007-05-29 20:53:32 +00:00
|
|
|
|
* \author Stefan Schimanski
|
2003-09-17 16:44:51 +00:00
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
|
#include "Bidi.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Buffer.h"
|
2008-01-12 21:38:51 +00:00
|
|
|
|
#include "BufferView.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "CoordCache.h"
|
2008-01-12 21:38:51 +00:00
|
|
|
|
#include "Cursor.h"
|
2004-03-25 09:16:36 +00:00
|
|
|
|
#include "CutAndPaste.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "DispatchResult.h"
|
|
|
|
|
#include "Encoding.h"
|
2008-01-12 21:38:51 +00:00
|
|
|
|
#include "Font.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "FuncRequest.h"
|
|
|
|
|
#include "Language.h"
|
2003-11-10 09:06:48 +00:00
|
|
|
|
#include "lfuns.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "LyXFunc.h" // only for setMessage()
|
|
|
|
|
#include "LyXRC.h"
|
2004-03-18 12:53:43 +00:00
|
|
|
|
#include "paragraph_funcs.h"
|
2008-01-12 21:38:51 +00:00
|
|
|
|
#include "Paragraph.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "ParIterator.h"
|
2008-01-12 21:38:51 +00:00
|
|
|
|
#include "Row.h"
|
|
|
|
|
#include "Text.h"
|
2007-10-11 09:59:01 +00:00
|
|
|
|
#include "TextMetrics.h"
|
2008-01-12 21:38:51 +00:00
|
|
|
|
#include "TocBackend.h"
|
2003-09-17 16:44:51 +00:00
|
|
|
|
|
2007-11-29 07:04:28 +00:00
|
|
|
|
#include "support/debug.h"
|
2007-11-05 22:54:53 +00:00
|
|
|
|
#include "support/docstream.h"
|
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
|
#include "insets/InsetTabular.h"
|
|
|
|
|
#include "insets/InsetText.h"
|
2003-11-04 12:36:59 +00:00
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "mathed/InsetMath.h"
|
|
|
|
|
#include "mathed/InsetMathScript.h"
|
2007-04-28 20:44:46 +00:00
|
|
|
|
#include "mathed/MacroTable.h"
|
2007-11-01 14:40:15 +00:00
|
|
|
|
#include "mathed/MathData.h"
|
|
|
|
|
#include "mathed/MathMacro.h"
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
2003-11-04 12:36:59 +00:00
|
|
|
|
#include <boost/assert.hpp>
|
2004-11-06 15:23:12 +00:00
|
|
|
|
#include <boost/bind.hpp>
|
2003-09-17 16:44:51 +00:00
|
|
|
|
|
2004-07-24 10:55:30 +00:00
|
|
|
|
#include <sstream>
|
2005-01-18 14:15:57 +00:00
|
|
|
|
#include <limits>
|
2006-11-27 16:40:03 +00:00
|
|
|
|
#include <map>
|
2004-07-24 10:55:30 +00:00
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
|
using namespace std;
|
2007-07-17 17:46:54 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
2004-08-13 19:19:53 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
|
bool positionable(DocIterator const & cursor, DocIterator const & anchor)
|
|
|
|
|
{
|
|
|
|
|
// avoid deeper nested insets when selecting
|
|
|
|
|
if (cursor.depth() > anchor.depth())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// anchor might be deeper, should have same path then
|
|
|
|
|
for (size_t i = 0; i < cursor.depth(); ++i)
|
|
|
|
|
if (&cursor[i].inset() != &anchor[i].inset())
|
2004-08-13 19:19:53 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
|
// position should be ok.
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2004-08-13 19:19:53 +00:00
|
|
|
|
|
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
|
// Find position closest to (x, y) in cell given by iter.
|
|
|
|
|
// Used only in mathed
|
|
|
|
|
DocIterator bruteFind2(Cursor const & c, int x, int y)
|
|
|
|
|
{
|
2007-12-12 19:28:07 +00:00
|
|
|
|
double best_dist = numeric_limits<double>::max();
|
2004-08-13 19:19:53 +00:00
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
|
DocIterator result;
|
2006-11-27 16:40:03 +00:00
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
|
DocIterator it = c;
|
|
|
|
|
it.top().pos() = 0;
|
|
|
|
|
DocIterator et = c;
|
|
|
|
|
et.top().pos() = et.top().asInsetMath()->cell(et.top().idx()).size();
|
|
|
|
|
for (size_t i = 0;; ++i) {
|
|
|
|
|
int xo;
|
|
|
|
|
int yo;
|
|
|
|
|
Inset const * inset = &it.inset();
|
2007-12-12 19:28:07 +00:00
|
|
|
|
map<Inset const *, Geometry> const & data =
|
2007-11-28 22:12:03 +00:00
|
|
|
|
c.bv().coordCache().getInsets().getData();
|
2007-12-12 19:28:07 +00:00
|
|
|
|
map<Inset const *, Geometry>::const_iterator I = data.find(inset);
|
2004-08-13 19:19:53 +00:00
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
|
// FIXME: in the case where the inset is not in the cache, this
|
|
|
|
|
// means that no part of it is visible on screen. In this case
|
|
|
|
|
// we don't do elaborate search and we just return the forwarded
|
|
|
|
|
// DocIterator at its beginning.
|
|
|
|
|
if (I == data.end()) {
|
|
|
|
|
it.top().pos() = 0;
|
|
|
|
|
return it;
|
|
|
|
|
}
|
2004-08-13 19:19:53 +00:00
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
|
Point o = I->second.pos;
|
|
|
|
|
inset->cursorPos(c.bv(), it.top(), c.boundary(), xo, yo);
|
|
|
|
|
// Convert to absolute
|
|
|
|
|
xo += o.x_;
|
|
|
|
|
yo += o.y_;
|
|
|
|
|
double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
|
|
|
|
|
// '<=' in order to take the last possible position
|
|
|
|
|
// this is important for clicking behind \sum in e.g. '\sum_i a'
|
|
|
|
|
LYXERR(Debug::DEBUG, "i: " << i << " d: " << d
|
|
|
|
|
<< " best: " << best_dist);
|
|
|
|
|
if (d <= best_dist) {
|
|
|
|
|
best_dist = d;
|
|
|
|
|
result = it;
|
|
|
|
|
}
|
|
|
|
|
if (it == et)
|
|
|
|
|
break;
|
|
|
|
|
it.forwardPos();
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
/// moves position closest to (x, y) in given box
|
|
|
|
|
bool bruteFind(Cursor & cursor,
|
|
|
|
|
int x, int y, int xlow, int xhigh, int ylow, int yhigh)
|
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(!cursor.empty());
|
|
|
|
|
Inset & inset = cursor[0].inset();
|
|
|
|
|
BufferView & bv = cursor.bv();
|
|
|
|
|
|
|
|
|
|
CoordCache::InnerParPosCache const & cache =
|
|
|
|
|
bv.coordCache().getParPos().find(cursor.bottom().text())->second;
|
|
|
|
|
// Get an iterator on the first paragraph in the cache
|
|
|
|
|
DocIterator it(inset);
|
|
|
|
|
it.push_back(CursorSlice(inset));
|
|
|
|
|
it.pit() = cache.begin()->first;
|
|
|
|
|
// Get an iterator after the last paragraph in the cache
|
|
|
|
|
DocIterator et(inset);
|
|
|
|
|
et.push_back(CursorSlice(inset));
|
|
|
|
|
et.pit() = boost::prior(cache.end())->first;
|
|
|
|
|
if (et.pit() >= et.lastpit())
|
|
|
|
|
et = doc_iterator_end(inset);
|
|
|
|
|
else
|
|
|
|
|
++et.pit();
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
|
double best_dist = numeric_limits<double>::max();;
|
2007-11-28 22:12:03 +00:00
|
|
|
|
DocIterator best_cursor = et;
|
|
|
|
|
|
|
|
|
|
for ( ; it != et; it.forwardPos(true)) {
|
|
|
|
|
// avoid invalid nesting when selecting
|
|
|
|
|
if (!cursor.selection() || positionable(it, cursor.anchor_)) {
|
|
|
|
|
Point p = bv.getPos(it, false);
|
|
|
|
|
int xo = p.x_;
|
|
|
|
|
int yo = p.y_;
|
|
|
|
|
if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
|
|
|
|
|
double const dx = xo - x;
|
|
|
|
|
double const dy = yo - y;
|
|
|
|
|
double const d = dx * dx + dy * dy;
|
|
|
|
|
// '<=' in order to take the last possible position
|
|
|
|
|
// this is important for clicking behind \sum in e.g. '\sum_i a'
|
|
|
|
|
if (d <= best_dist) {
|
|
|
|
|
// lyxerr << "*" << endl;
|
|
|
|
|
best_dist = d;
|
|
|
|
|
best_cursor = it;
|
2004-08-13 19:19:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-11-28 22:12:03 +00:00
|
|
|
|
}
|
2004-08-13 19:19:53 +00:00
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
|
if (best_cursor != et) {
|
|
|
|
|
cursor.setCursor(best_cursor);
|
|
|
|
|
return true;
|
2004-08-13 19:19:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
*/
|
2005-07-18 17:12:28 +00:00
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
|
|
|
|
|
|
/// moves position closest to (x, y) in given box
|
|
|
|
|
bool bruteFind3(Cursor & cur, int x, int y, bool up)
|
|
|
|
|
{
|
|
|
|
|
BufferView & bv = cur.bv();
|
|
|
|
|
int ylow = up ? 0 : y + 1;
|
|
|
|
|
int yhigh = up ? y - 1 : bv.workHeight();
|
|
|
|
|
int xlow = 0;
|
|
|
|
|
int xhigh = bv.workWidth();
|
2005-07-18 17:12:28 +00:00
|
|
|
|
|
|
|
|
|
// FIXME: bit more work needed to get 'from' and 'to' right.
|
2007-11-28 22:12:03 +00:00
|
|
|
|
pit_type from = cur.bottom().pit();
|
|
|
|
|
//pit_type to = cur.bottom().pit();
|
|
|
|
|
//lyxerr << "Pit start: " << from << endl;
|
|
|
|
|
|
|
|
|
|
//lyxerr << "bruteFind3: x: " << x << " y: " << y
|
|
|
|
|
// << " xlow: " << xlow << " xhigh: " << xhigh
|
|
|
|
|
// << " ylow: " << ylow << " yhigh: " << yhigh
|
|
|
|
|
// << endl;
|
|
|
|
|
Inset & inset = bv.buffer().inset();
|
|
|
|
|
DocIterator it = doc_iterator_begin(inset);
|
|
|
|
|
it.pit() = from;
|
|
|
|
|
DocIterator et = doc_iterator_end(inset);
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
|
double best_dist = numeric_limits<double>::max();
|
2007-11-28 22:12:03 +00:00
|
|
|
|
DocIterator best_cursor = et;
|
|
|
|
|
|
|
|
|
|
for ( ; it != et; it.forwardPos()) {
|
|
|
|
|
// avoid invalid nesting when selecting
|
|
|
|
|
if (bv.cursorStatus(it) == CUR_INSIDE
|
|
|
|
|
&& (!cur.selection() || positionable(it, cur.anchor_))) {
|
|
|
|
|
Point p = bv.getPos(it, false);
|
|
|
|
|
int xo = p.x_;
|
|
|
|
|
int yo = p.y_;
|
|
|
|
|
if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
|
|
|
|
|
double const dx = xo - x;
|
|
|
|
|
double const dy = yo - y;
|
|
|
|
|
double const d = dx * dx + dy * dy;
|
|
|
|
|
//lyxerr << "itx: " << xo << " ity: " << yo << " d: " << d
|
|
|
|
|
// << " dx: " << dx << " dy: " << dy
|
|
|
|
|
// << " idx: " << it.idx() << " pos: " << it.pos()
|
|
|
|
|
// << " it:\n" << it
|
|
|
|
|
// << endl;
|
|
|
|
|
// '<=' in order to take the last possible position
|
|
|
|
|
// this is important for clicking behind \sum in e.g. '\sum_i a'
|
|
|
|
|
if (d <= best_dist) {
|
|
|
|
|
//lyxerr << "*" << endl;
|
|
|
|
|
best_dist = d;
|
|
|
|
|
best_cursor = it;
|
2005-07-18 17:12:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
|
//lyxerr << "best_dist: " << best_dist << " cur:\n" << best_cursor << endl;
|
|
|
|
|
if (best_cursor == et)
|
|
|
|
|
return false;
|
|
|
|
|
cur.setCursor(best_cursor);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
docstring parbreak(Paragraph const & par)
|
|
|
|
|
{
|
|
|
|
|
odocstringstream ods;
|
|
|
|
|
ods << '\n';
|
|
|
|
|
// only add blank line if we're not in an ERT or Listings inset
|
|
|
|
|
if (par.ownerCode() != ERT_CODE
|
|
|
|
|
&& par.ownerCode() != LISTINGS_CODE)
|
2007-05-07 08:57:53 +00:00
|
|
|
|
ods << '\n';
|
2007-11-28 22:12:03 +00:00
|
|
|
|
return ods.str();
|
|
|
|
|
}
|
2007-05-07 08:57:53 +00:00
|
|
|
|
|
2004-08-13 19:19:53 +00:00
|
|
|
|
} // namespace anon
|
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
2004-12-03 16:39:59 +00:00
|
|
|
|
// be careful: this is called from the bv's constructor, too, so
|
2004-11-30 01:59:49 +00:00
|
|
|
|
// bv functions are not yet available!
|
2007-04-26 14:56:30 +00:00
|
|
|
|
Cursor::Cursor(BufferView & bv)
|
2007-05-29 20:53:32 +00:00
|
|
|
|
: DocIterator(), bv_(&bv), anchor_(), x_target_(-1), textTargetOffset_(0),
|
2007-10-28 18:51:54 +00:00
|
|
|
|
selection_(false), mark_(false), logicalpos_(false),
|
|
|
|
|
current_font(inherit_font)
|
2003-11-10 09:06:48 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
|
void Cursor::reset(Inset & inset)
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
2004-03-01 17:12:09 +00:00
|
|
|
|
clear();
|
2004-03-19 16:36:52 +00:00
|
|
|
|
push_back(CursorSlice(inset));
|
2008-02-09 15:23:05 +00:00
|
|
|
|
anchor_ = doc_iterator_begin(inset);
|
|
|
|
|
anchor_.clear();
|
2004-01-30 11:41:12 +00:00
|
|
|
|
clearTargetX();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
selection_ = false;
|
|
|
|
|
mark_ = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-08-14 19:55:00 +00:00
|
|
|
|
// this (intentionally) does neither touch anchor nor selection status
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::setCursor(DocIterator const & cur)
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
2004-03-31 19:11:56 +00:00
|
|
|
|
DocIterator::operator=(cur);
|
2004-03-01 17:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::dispatch(FuncRequest const & cmd0)
|
2003-09-17 16:44:51 +00:00
|
|
|
|
{
|
2007-11-29 21:10:35 +00:00
|
|
|
|
LYXERR(Debug::DEBUG, "cmd: " << cmd0 << '\n' << *this);
|
2004-03-18 12:53:43 +00:00
|
|
|
|
if (empty())
|
2004-08-13 14:56:06 +00:00
|
|
|
|
return;
|
2004-03-18 12:53:43 +00:00
|
|
|
|
|
2005-02-15 17:34:54 +00:00
|
|
|
|
fixIfBroken();
|
2003-11-10 09:06:48 +00:00
|
|
|
|
FuncRequest cmd = cmd0;
|
2007-04-26 14:56:30 +00:00
|
|
|
|
Cursor safe = *this;
|
2007-05-29 20:53:32 +00:00
|
|
|
|
|
|
|
|
|
// store some values to be used inside of the handlers
|
2007-06-14 20:32:28 +00:00
|
|
|
|
beforeDispatchCursor_ = *this;
|
2005-02-08 13:18:05 +00:00
|
|
|
|
for (; depth(); pop()) {
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::DEBUG, "Cursor::dispatch: cmd: "
|
|
|
|
|
<< cmd0 << endl << *this);
|
2004-03-18 12:53:43 +00:00
|
|
|
|
BOOST_ASSERT(pos() <= lastpos());
|
|
|
|
|
BOOST_ASSERT(idx() <= lastidx());
|
2004-11-24 21:53:46 +00:00
|
|
|
|
BOOST_ASSERT(pit() <= lastpit());
|
2004-03-18 12:53:43 +00:00
|
|
|
|
|
2004-04-03 08:37:12 +00:00
|
|
|
|
// The common case is 'LFUN handled, need update', so make the
|
2004-03-18 12:53:43 +00:00
|
|
|
|
// LFUN handler's life easier by assuming this as default value.
|
|
|
|
|
// The handler can reset the update and val flags if necessary.
|
2006-10-22 11:46:36 +00:00
|
|
|
|
disp_.update(Update::FitCursor | Update::Force);
|
2004-03-18 12:53:43 +00:00
|
|
|
|
disp_.dispatched(true);
|
|
|
|
|
inset().dispatch(*this, cmd);
|
|
|
|
|
if (disp_.dispatched())
|
|
|
|
|
break;
|
2003-09-17 16:44:51 +00:00
|
|
|
|
}
|
2007-06-14 20:32:28 +00:00
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
// it completely to get a 'bomb early' behaviour in case this
|
|
|
|
|
// object will be used again.
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (!disp_.dispatched()) {
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::DEBUG, "RESTORING OLD CURSOR!");
|
2004-03-18 13:57:20 +00:00
|
|
|
|
operator=(safe);
|
2006-10-22 11:46:36 +00:00
|
|
|
|
disp_.update(Update::None);
|
2004-04-07 20:20:15 +00:00
|
|
|
|
disp_.dispatched(false);
|
2007-06-14 20:32:28 +00:00
|
|
|
|
} else {
|
|
|
|
|
// restore the previous one because nested Cursor::dispatch calls
|
|
|
|
|
// are possible which would change it
|
|
|
|
|
beforeDispatchCursor_ = safe.beforeDispatchCursor_;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
}
|
2004-08-13 14:56:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
DispatchResult Cursor::result() const
|
2004-08-13 14:56:06 +00:00
|
|
|
|
{
|
2004-02-16 11:58:51 +00:00
|
|
|
|
return disp_;
|
2003-09-17 16:44:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
BufferView & Cursor::bv() const
|
2003-11-06 10:30:43 +00:00
|
|
|
|
{
|
2004-04-08 15:03:33 +00:00
|
|
|
|
BOOST_ASSERT(bv_);
|
2004-03-18 12:53:43 +00:00
|
|
|
|
return *bv_;
|
2004-03-11 17:16:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
Buffer & Cursor::buffer() const
|
2004-04-08 15:03:33 +00:00
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(bv_);
|
2007-08-21 13:03:55 +00:00
|
|
|
|
return bv_->buffer();
|
2004-04-08 15:03:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::pop()
|
2003-11-04 12:36:59 +00:00
|
|
|
|
{
|
2005-02-08 13:18:05 +00:00
|
|
|
|
BOOST_ASSERT(depth() >= 1);
|
2004-03-01 17:12:09 +00:00
|
|
|
|
pop_back();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
|
void Cursor::push(Inset & p)
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
|
|
|
|
push_back(CursorSlice(p));
|
2004-01-20 14:25:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 19:41:16 +00:00
|
|
|
|
void Cursor::pushBackward(Inset & p)
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
2004-03-01 17:12:09 +00:00
|
|
|
|
BOOST_ASSERT(!empty());
|
2007-11-05 19:41:16 +00:00
|
|
|
|
//lyxerr << "Entering inset " << t << " front" << endl;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
push(p);
|
2004-03-18 12:53:43 +00:00
|
|
|
|
p.idxFirst(*this);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 19:41:16 +00:00
|
|
|
|
bool Cursor::popBackward()
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
2004-03-01 17:12:09 +00:00
|
|
|
|
BOOST_ASSERT(!empty());
|
2007-11-05 19:41:16 +00:00
|
|
|
|
//lyxerr << "Leaving inset from in front" << endl;
|
2004-04-05 16:44:10 +00:00
|
|
|
|
inset().notifyCursorLeaves(*this);
|
2004-03-18 16:05:32 +00:00
|
|
|
|
if (depth() == 1)
|
|
|
|
|
return false;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
pop();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 19:41:16 +00:00
|
|
|
|
bool Cursor::popForward()
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
2004-03-01 17:12:09 +00:00
|
|
|
|
BOOST_ASSERT(!empty());
|
2007-11-05 19:41:16 +00:00
|
|
|
|
//lyxerr << "Leaving inset from in back" << endl;
|
2006-12-29 14:17:48 +00:00
|
|
|
|
const pos_type lp = (depth() > 1) ? (*this)[depth() - 2].lastpos() : 0;
|
2004-04-05 16:44:10 +00:00
|
|
|
|
inset().notifyCursorLeaves(*this);
|
2004-03-18 16:05:32 +00:00
|
|
|
|
if (depth() == 1)
|
|
|
|
|
return false;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
pop();
|
2006-12-29 14:17:48 +00:00
|
|
|
|
pos() += lastpos() - lp + 1;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
int Cursor::currentMode()
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
2004-03-01 17:12:09 +00:00
|
|
|
|
BOOST_ASSERT(!empty());
|
2005-02-08 13:18:05 +00:00
|
|
|
|
for (int i = depth() - 1; i >= 0; --i) {
|
2004-03-18 12:53:43 +00:00
|
|
|
|
int res = operator[](i).inset().currentMode();
|
2007-04-29 13:39:47 +00:00
|
|
|
|
if (res != Inset::UNDECIDED_MODE)
|
2004-01-26 10:13:15 +00:00
|
|
|
|
return res;
|
|
|
|
|
}
|
2007-04-29 13:39:47 +00:00
|
|
|
|
return Inset::TEXT_MODE;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::getPos(int & x, int & y) const
|
2003-11-10 09:06:48 +00:00
|
|
|
|
{
|
2007-09-29 09:22:17 +00:00
|
|
|
|
Point p = bv().getPos(*this, boundary());
|
2004-11-30 01:59:49 +00:00
|
|
|
|
x = p.x_;
|
|
|
|
|
y = p.y_;
|
2003-11-10 09:06:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
Row const & Cursor::textRow() const
|
2006-12-19 13:39:46 +00:00
|
|
|
|
{
|
2007-12-22 09:25:59 +00:00
|
|
|
|
CursorSlice const & cs = innerTextSlice();
|
|
|
|
|
ParagraphMetrics const & pm = bv().parMetrics(cs.text(), cs.pit());
|
2006-12-29 23:54:48 +00:00
|
|
|
|
BOOST_ASSERT(!pm.rows().empty());
|
|
|
|
|
return pm.getRow(pos(), boundary());
|
2006-12-19 13:39:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::resetAnchor()
|
2004-01-08 18:30:14 +00:00
|
|
|
|
{
|
2004-03-01 17:12:09 +00:00
|
|
|
|
anchor_ = *this;
|
2004-01-16 13:35:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 19:41:16 +00:00
|
|
|
|
bool Cursor::posBackward()
|
2004-01-16 13:35:10 +00:00
|
|
|
|
{
|
|
|
|
|
if (pos() == 0)
|
|
|
|
|
return false;
|
|
|
|
|
--pos();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 19:41:16 +00:00
|
|
|
|
bool Cursor::posForward()
|
2004-01-16 13:35:10 +00:00
|
|
|
|
{
|
|
|
|
|
if (pos() == lastpos())
|
|
|
|
|
return false;
|
|
|
|
|
++pos();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2004-01-20 14:25:24 +00:00
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
CursorSlice Cursor::anchor() const
|
2004-01-20 14:25:24 +00:00
|
|
|
|
{
|
2005-02-08 13:18:05 +00:00
|
|
|
|
BOOST_ASSERT(anchor_.depth() >= depth());
|
|
|
|
|
CursorSlice normal = anchor_[depth() - 1];
|
|
|
|
|
if (depth() < anchor_.depth() && top() <= normal) {
|
2004-04-07 13:15:34 +00:00
|
|
|
|
// anchor is behind cursor -> move anchor behind the inset
|
|
|
|
|
++normal.pos();
|
2004-04-07 08:07:26 +00:00
|
|
|
|
}
|
2004-04-07 13:15:34 +00:00
|
|
|
|
return normal;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
CursorSlice Cursor::selBegin() const
|
2004-01-20 14:25:24 +00:00
|
|
|
|
{
|
|
|
|
|
if (!selection())
|
2005-02-08 13:18:05 +00:00
|
|
|
|
return top();
|
|
|
|
|
return anchor() < top() ? anchor() : top();
|
2004-01-20 14:25:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
CursorSlice Cursor::selEnd() const
|
2004-01-20 14:25:24 +00:00
|
|
|
|
{
|
|
|
|
|
if (!selection())
|
2005-02-08 13:18:05 +00:00
|
|
|
|
return top();
|
|
|
|
|
return anchor() > top() ? anchor() : top();
|
2004-01-20 14:25:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
DocIterator Cursor::selectionBegin() const
|
2004-01-20 14:25:24 +00:00
|
|
|
|
{
|
|
|
|
|
if (!selection())
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return *this;
|
2005-11-07 15:02:08 +00:00
|
|
|
|
DocIterator di = (anchor() < top() ? anchor_ : *this);
|
|
|
|
|
di.resize(depth());
|
|
|
|
|
return di;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
DocIterator Cursor::selectionEnd() const
|
2004-01-20 14:25:24 +00:00
|
|
|
|
{
|
2004-02-11 14:45:44 +00:00
|
|
|
|
if (!selection())
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return *this;
|
2005-11-07 15:02:08 +00:00
|
|
|
|
DocIterator di = (anchor() > top() ? anchor_ : *this);
|
|
|
|
|
if (di.depth() > depth()) {
|
|
|
|
|
di.resize(depth());
|
|
|
|
|
++di.pos();
|
|
|
|
|
}
|
|
|
|
|
return di;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::setSelection()
|
2004-01-20 14:25:24 +00:00
|
|
|
|
{
|
|
|
|
|
selection() = true;
|
2005-07-14 17:30:24 +00:00
|
|
|
|
// A selection with no contents is not a selection
|
2007-08-10 11:47:12 +00:00
|
|
|
|
// FIXME: doesnt look ok
|
2004-11-24 21:53:46 +00:00
|
|
|
|
if (pit() == anchor().pit() && pos() == anchor().pos())
|
2004-01-20 14:25:24 +00:00
|
|
|
|
selection() = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::setSelection(DocIterator const & where, int n)
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
2004-08-14 19:55:00 +00:00
|
|
|
|
setCursor(where);
|
|
|
|
|
selection() = true;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
anchor_ = where;
|
|
|
|
|
pos() += n;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::clearSelection()
|
2004-01-20 14:25:24 +00:00
|
|
|
|
{
|
|
|
|
|
selection() = false;
|
|
|
|
|
mark() = false;
|
|
|
|
|
resetAnchor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
|
void Cursor::setTargetX(int x)
|
2004-01-20 14:25:24 +00:00
|
|
|
|
{
|
2007-05-29 20:53:32 +00:00
|
|
|
|
x_target_ = x;
|
|
|
|
|
textTargetOffset_ = 0;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
int Cursor::x_target() const
|
2004-01-20 14:25:24 +00:00
|
|
|
|
{
|
|
|
|
|
return x_target_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::clearTargetX()
|
2004-01-30 11:41:12 +00:00
|
|
|
|
{
|
|
|
|
|
x_target_ = -1;
|
2007-05-29 20:53:32 +00:00
|
|
|
|
textTargetOffset_ = 0;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
|
void Cursor::updateTextTargetOffset()
|
|
|
|
|
{
|
|
|
|
|
int x;
|
|
|
|
|
int y;
|
|
|
|
|
getPos(x, y);
|
|
|
|
|
textTargetOffset_ = x - x_target_;
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::info(odocstream & os) const
|
2004-01-20 14:25:24 +00:00
|
|
|
|
{
|
|
|
|
|
for (int i = 1, n = depth(); i < n; ++i) {
|
2004-03-18 12:53:43 +00:00
|
|
|
|
operator[](i).inset().infoize(os);
|
2004-01-20 14:25:24 +00:00
|
|
|
|
os << " ";
|
|
|
|
|
}
|
2007-02-08 08:44:45 +00:00
|
|
|
|
if (pos() != 0) {
|
2007-04-29 13:39:47 +00:00
|
|
|
|
Inset const * inset = prevInset();
|
2007-02-08 08:44:45 +00:00
|
|
|
|
// prevInset() can return 0 in certain case.
|
|
|
|
|
if (inset)
|
|
|
|
|
prevInset()->infoize2(os);
|
|
|
|
|
}
|
2004-01-20 14:25:24 +00:00
|
|
|
|
// overwite old message
|
|
|
|
|
os << " ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool Cursor::selHandle(bool sel)
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
2007-04-26 14:56:30 +00:00
|
|
|
|
//lyxerr << "Cursor::selHandle" << endl;
|
2007-12-18 07:10:55 +00:00
|
|
|
|
if (mark())
|
|
|
|
|
sel = true;
|
2004-05-18 07:18:02 +00:00
|
|
|
|
if (sel == selection())
|
2006-10-22 11:46:36 +00:00
|
|
|
|
return false;
|
2004-04-20 08:51:15 +00:00
|
|
|
|
|
2007-07-10 12:44:19 +00:00
|
|
|
|
if (!sel)
|
|
|
|
|
cap::saveSelection(*this);
|
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
resetAnchor();
|
|
|
|
|
selection() = sel;
|
2006-10-22 11:46:36 +00:00
|
|
|
|
return true;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
|
ostream & operator<<(ostream & os, Cursor const & cur)
|
2004-01-20 14:25:24 +00:00
|
|
|
|
{
|
2004-08-13 12:05:27 +00:00
|
|
|
|
os << "\n cursor: | anchor:\n";
|
2005-02-08 13:18:05 +00:00
|
|
|
|
for (size_t i = 0, n = cur.depth(); i != n; ++i) {
|
|
|
|
|
os << " " << cur[i] << " | ";
|
|
|
|
|
if (i < cur.anchor_.depth())
|
2004-03-25 09:16:36 +00:00
|
|
|
|
os << cur.anchor_[i];
|
|
|
|
|
else
|
|
|
|
|
os << "-------------------------------";
|
|
|
|
|
os << "\n";
|
|
|
|
|
}
|
2005-02-08 13:18:05 +00:00
|
|
|
|
for (size_t i = cur.depth(), n = cur.anchor_.depth(); i < n; ++i) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
os << "------------------------------- | " << cur.anchor_[i] << "\n";
|
|
|
|
|
}
|
|
|
|
|
os << " selection: " << cur.selection_
|
|
|
|
|
<< " x_target: " << cur.x_target_ << endl;
|
2004-02-06 16:50:29 +00:00
|
|
|
|
return os;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
}
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
|
|
|
|
|
|
LyXErr & operator<<(LyXErr & os, Cursor const & cur)
|
|
|
|
|
{
|
|
|
|
|
os.stream() << cur;
|
|
|
|
|
return os;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
} // namespace lyx
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
2007-11-28 22:12:03 +00:00
|
|
|
|
// FIXME: Look here
|
2004-01-26 10:13:15 +00:00
|
|
|
|
// The part below is the non-integrated rest of the original math
|
|
|
|
|
// cursor. This should be either generalized for texted or moved
|
2006-09-16 18:11:38 +00:00
|
|
|
|
// back to mathed (in most cases to InsetMathNest).
|
2004-01-26 10:13:15 +00:00
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "mathed/InsetMathChar.h"
|
|
|
|
|
#include "mathed/InsetMathGrid.h"
|
|
|
|
|
#include "mathed/InsetMathScript.h"
|
|
|
|
|
#include "mathed/InsetMathUnknown.h"
|
2006-10-22 10:15:23 +00:00
|
|
|
|
#include "mathed/MathFactory.h"
|
|
|
|
|
#include "mathed/MathStream.h"
|
|
|
|
|
#include "mathed/MathSupport.h"
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
//#define FILEDEBUG 1
|
|
|
|
|
|
|
|
|
|
|
2007-12-22 14:38:20 +00:00
|
|
|
|
bool Cursor::isInside(Inset const * p) const
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
2005-05-06 20:00:31 +00:00
|
|
|
|
for (size_t i = 0; i != depth(); ++i)
|
2004-03-18 12:53:43 +00:00
|
|
|
|
if (&operator[](i).inset() == p)
|
2004-01-26 10:13:15 +00:00
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
|
void Cursor::leaveInset(Inset const & inset)
|
2005-05-06 18:54:36 +00:00
|
|
|
|
{
|
|
|
|
|
for (size_t i = 0; i != depth(); ++i) {
|
|
|
|
|
if (&operator[](i).inset() == &inset) {
|
|
|
|
|
resize(i);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool Cursor::openable(MathAtom const & t) const
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
|
|
|
|
if (!t->isActive())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (t->lock())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (!selection())
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
// we can't move into anything new during selection
|
2005-02-08 13:18:05 +00:00
|
|
|
|
if (depth() >= anchor_.depth())
|
2004-01-26 10:13:15 +00:00
|
|
|
|
return false;
|
2007-11-01 22:17:22 +00:00
|
|
|
|
if (t.nucleus() != &anchor_[depth()].inset())
|
2004-01-26 10:13:15 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-16 10:39:44 +00:00
|
|
|
|
void Cursor::setScreenPos(int x, int /*y*/)
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
2007-05-29 20:53:32 +00:00
|
|
|
|
setTargetX(x);
|
2007-09-11 16:04:10 +00:00
|
|
|
|
//bruteFind(*this, x, y, 0, bv().workWidth(), 0, bv().workHeight());
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::plainErase()
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
|
|
|
|
cell().erase(pos());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::markInsert()
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
2006-04-09 02:30:40 +00:00
|
|
|
|
insert(char_type(0));
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::markErase()
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
|
|
|
|
cell().erase(pos());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::plainInsert(MathAtom const & t)
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
|
|
|
|
cell().insert(pos(), t);
|
|
|
|
|
++pos();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::insert(docstring const & str)
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
2004-11-06 15:23:12 +00:00
|
|
|
|
for_each(str.begin(), str.end(),
|
2007-04-26 14:56:30 +00:00
|
|
|
|
boost::bind(static_cast<void(Cursor::*)(char_type)>
|
|
|
|
|
(&Cursor::insert), this, _1));
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::insert(char_type c)
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
2007-04-26 14:56:30 +00:00
|
|
|
|
//lyxerr << "Cursor::insert char '" << c << "'" << endl;
|
2004-03-18 12:53:43 +00:00
|
|
|
|
BOOST_ASSERT(!empty());
|
|
|
|
|
if (inMathed()) {
|
2006-10-21 00:16:43 +00:00
|
|
|
|
cap::selClearOrDel(*this);
|
2006-09-16 18:11:38 +00:00
|
|
|
|
insert(new InsetMathChar(c));
|
2004-03-18 12:53:43 +00:00
|
|
|
|
} else {
|
|
|
|
|
text()->insertChar(*this, c);
|
|
|
|
|
}
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::insert(MathAtom const & t)
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
2007-04-26 14:56:30 +00:00
|
|
|
|
//lyxerr << "Cursor::insert MathAtom '" << t << "'" << endl;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
macroModeClose();
|
2006-10-21 00:16:43 +00:00
|
|
|
|
cap::selClearOrDel(*this);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
plainInsert(t);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
|
void Cursor::insert(Inset * inset)
|
2004-02-11 14:45:44 +00:00
|
|
|
|
{
|
|
|
|
|
if (inMathed())
|
|
|
|
|
insert(MathAtom(inset));
|
|
|
|
|
else
|
2004-02-13 07:30:59 +00:00
|
|
|
|
text()->insertInset(*this, inset);
|
2004-02-11 14:45:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::niceInsert(docstring const & t)
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
2007-04-26 16:06:39 +00:00
|
|
|
|
MathData ar;
|
2006-10-22 10:15:23 +00:00
|
|
|
|
asArray(t, ar);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
if (ar.size() == 1)
|
|
|
|
|
niceInsert(ar[0]);
|
|
|
|
|
else
|
|
|
|
|
insert(ar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::niceInsert(MathAtom const & t)
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
|
|
|
|
macroModeClose();
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring const safe = cap::grabAndEraseSelection(*this);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
plainInsert(t);
|
|
|
|
|
// enter the new inset and move the contents of the selection if possible
|
|
|
|
|
if (t->isActive()) {
|
2007-11-05 19:41:16 +00:00
|
|
|
|
posBackward();
|
|
|
|
|
// be careful here: don't use 'pushBackward(t)' as this we need to
|
2004-02-11 14:45:44 +00:00
|
|
|
|
// push the clone, not the original
|
2007-11-05 19:41:16 +00:00
|
|
|
|
pushBackward(*nextInset());
|
2006-02-28 19:16:38 +00:00
|
|
|
|
// We may not use niceInsert here (recursion)
|
2007-04-26 16:06:39 +00:00
|
|
|
|
MathData ar;
|
2006-10-22 10:15:23 +00:00
|
|
|
|
asArray(safe, ar);
|
2006-02-28 19:16:38 +00:00
|
|
|
|
insert(ar);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 16:06:39 +00:00
|
|
|
|
void Cursor::insert(MathData const & ar)
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
|
|
|
|
macroModeClose();
|
|
|
|
|
if (selection())
|
2006-10-21 00:16:43 +00:00
|
|
|
|
cap::eraseSelection(*this);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
cell().insert(pos(), ar);
|
|
|
|
|
pos() += ar.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool Cursor::backspace()
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
|
|
|
|
autocorrect() = false;
|
|
|
|
|
|
|
|
|
|
if (selection()) {
|
2007-01-04 15:21:58 +00:00
|
|
|
|
cap::eraseSelection(*this);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pos() == 0) {
|
2006-11-19 18:33:13 +00:00
|
|
|
|
// If empty cell, and not part of a big cell
|
|
|
|
|
if (lastpos() == 0 && inset().nargs() == 1) {
|
2007-11-05 19:41:16 +00:00
|
|
|
|
popBackward();
|
2007-05-28 22:27:45 +00:00
|
|
|
|
// Directly delete empty cell: [|[]] => [|]
|
2006-11-19 18:33:13 +00:00
|
|
|
|
if (inMathed()) {
|
|
|
|
|
plainErase();
|
|
|
|
|
resetAnchor();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
// [|], can not delete from inside
|
2004-01-26 10:13:15 +00:00
|
|
|
|
return false;
|
2006-11-19 18:33:13 +00:00
|
|
|
|
} else {
|
2007-03-29 21:58:15 +00:00
|
|
|
|
if (inMathed())
|
|
|
|
|
pullArg();
|
|
|
|
|
else
|
2007-11-05 19:41:16 +00:00
|
|
|
|
popBackward();
|
2006-11-19 18:33:13 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (inMacroMode()) {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathUnknown * p = activeMacro();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
if (p->name().size() > 1) {
|
|
|
|
|
p->setName(p->name().substr(0, p->name().size() - 1));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pos() != 0 && prevAtom()->nargs() > 0) {
|
|
|
|
|
// let's require two backspaces for 'big stuff' and
|
|
|
|
|
// highlight on the first
|
2004-04-05 16:44:10 +00:00
|
|
|
|
resetAnchor();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
selection() = true;
|
2004-02-25 14:39:14 +00:00
|
|
|
|
--pos();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
} else {
|
|
|
|
|
--pos();
|
|
|
|
|
plainErase();
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool Cursor::erase()
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
|
|
|
|
autocorrect() = false;
|
|
|
|
|
if (inMacroMode())
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (selection()) {
|
2007-01-04 15:21:58 +00:00
|
|
|
|
cap::eraseSelection(*this);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// delete empty cells if possible
|
2004-03-18 12:53:43 +00:00
|
|
|
|
if (pos() == lastpos() && inset().idxDelete(idx()))
|
2004-02-03 08:56:28 +00:00
|
|
|
|
return true;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
|
|
|
|
// special behaviour when in last position of cell
|
|
|
|
|
if (pos() == lastpos()) {
|
2004-03-18 12:53:43 +00:00
|
|
|
|
bool one_cell = inset().nargs() == 1;
|
2006-11-19 18:33:13 +00:00
|
|
|
|
if (one_cell && lastpos() == 0) {
|
2007-11-05 19:41:16 +00:00
|
|
|
|
popBackward();
|
2007-05-28 22:27:45 +00:00
|
|
|
|
// Directly delete empty cell: [|[]] => [|]
|
2006-11-19 18:33:13 +00:00
|
|
|
|
if (inMathed()) {
|
|
|
|
|
plainErase();
|
|
|
|
|
resetAnchor();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
// [|], can not delete from inside
|
2004-01-26 10:13:15 +00:00
|
|
|
|
return false;
|
2006-11-19 18:33:13 +00:00
|
|
|
|
}
|
2004-01-26 10:13:15 +00:00
|
|
|
|
// remove markup
|
2006-11-19 18:33:13 +00:00
|
|
|
|
if (!one_cell)
|
2004-03-18 12:53:43 +00:00
|
|
|
|
inset().idxGlue(idx());
|
2004-01-26 10:13:15 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-05 16:44:10 +00:00
|
|
|
|
// 'clever' UI hack: only erase large items if previously slected
|
2005-10-03 12:22:19 +00:00
|
|
|
|
if (pos() != lastpos() && nextAtom()->nargs() > 0) {
|
2004-04-05 16:44:10 +00:00
|
|
|
|
resetAnchor();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
selection() = true;
|
2004-02-25 14:39:14 +00:00
|
|
|
|
++pos();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
} else {
|
|
|
|
|
plainErase();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool Cursor::up()
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
|
|
|
|
macroModeClose();
|
2004-03-31 19:11:56 +00:00
|
|
|
|
DocIterator save = *this;
|
2007-05-29 20:53:32 +00:00
|
|
|
|
FuncRequest cmd(selection() ? LFUN_UP_SELECT : LFUN_UP, docstring());
|
|
|
|
|
this->dispatch(cmd);
|
|
|
|
|
if (disp_.dispatched())
|
2004-01-26 10:13:15 +00:00
|
|
|
|
return true;
|
2004-08-14 19:55:00 +00:00
|
|
|
|
setCursor(save);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
autocorrect() = false;
|
2007-05-29 20:53:32 +00:00
|
|
|
|
return false;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool Cursor::down()
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
|
|
|
|
macroModeClose();
|
2004-03-31 19:11:56 +00:00
|
|
|
|
DocIterator save = *this;
|
2007-05-29 20:53:32 +00:00
|
|
|
|
FuncRequest cmd(selection() ? LFUN_DOWN_SELECT : LFUN_DOWN, docstring());
|
|
|
|
|
this->dispatch(cmd);
|
|
|
|
|
if (disp_.dispatched())
|
2004-01-26 10:13:15 +00:00
|
|
|
|
return true;
|
2004-08-14 19:55:00 +00:00
|
|
|
|
setCursor(save);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
autocorrect() = false;
|
2007-05-29 20:53:32 +00:00
|
|
|
|
return false;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool Cursor::macroModeClose()
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
|
|
|
|
if (!inMacroMode())
|
2006-01-11 17:08:50 +00:00
|
|
|
|
return false;
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathUnknown * p = activeMacro();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
p->finalize();
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring const s = p->name();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
--pos();
|
|
|
|
|
cell().erase(pos());
|
|
|
|
|
|
|
|
|
|
// do nothing if the macro name is empty
|
|
|
|
|
if (s == "\\")
|
2006-01-11 17:08:50 +00:00
|
|
|
|
return false;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
2007-04-19 13:37:17 +00:00
|
|
|
|
// trigger updates of macros, at least, if no full
|
|
|
|
|
// updates take place anyway
|
|
|
|
|
updateFlags(Update::Force);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
2007-04-19 13:37:17 +00:00
|
|
|
|
docstring const name = s.substr(1);
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathNest * const in = inset().asInsetMath()->asNestInset();
|
2006-10-19 16:38:13 +00:00
|
|
|
|
if (in && in->interpretString(*this, s))
|
2006-05-01 08:05:22 +00:00
|
|
|
|
return true;
|
2007-11-01 14:40:15 +00:00
|
|
|
|
MathAtom atom = createInsetMath(name);
|
2007-11-01 14:45:14 +00:00
|
|
|
|
MathMacro * atomAsMacro = atom.nucleus()->asMacro();
|
|
|
|
|
if (atomAsMacro) {
|
2007-11-01 14:40:15 +00:00
|
|
|
|
// make non-greedy, i.e. don't eat parameters from the right
|
2007-11-14 17:33:49 +00:00
|
|
|
|
atomAsMacro->setDisplayMode(MathMacro::DISPLAY_INTERACTIVE_INIT);
|
2007-11-01 14:40:15 +00:00
|
|
|
|
}
|
|
|
|
|
plainInsert(atom);
|
2006-01-11 17:08:50 +00:00
|
|
|
|
return true;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
docstring Cursor::macroName()
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
2006-10-22 10:15:23 +00:00
|
|
|
|
return inMacroMode() ? activeMacro()->name() : docstring();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::handleNest(MathAtom const & a, int c)
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
2007-04-26 14:56:30 +00:00
|
|
|
|
//lyxerr << "Cursor::handleNest: " << c << endl;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
MathAtom t = a;
|
2006-10-22 10:15:23 +00:00
|
|
|
|
asArray(cap::grabAndEraseSelection(*this), t.nucleus()->cell(c));
|
2004-01-30 11:41:12 +00:00
|
|
|
|
insert(t);
|
2007-11-05 19:41:16 +00:00
|
|
|
|
posBackward();
|
|
|
|
|
pushBackward(*nextInset());
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
int Cursor::targetX() const
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
|
|
|
|
if (x_target() != -1)
|
|
|
|
|
return x_target();
|
|
|
|
|
int x = 0;
|
|
|
|
|
int y = 0;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
getPos(x, y);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
|
int Cursor::textTargetOffset() const
|
|
|
|
|
{
|
|
|
|
|
return textTargetOffset_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::setTargetX()
|
2004-11-30 01:59:49 +00:00
|
|
|
|
{
|
2005-02-08 13:18:05 +00:00
|
|
|
|
int x;
|
|
|
|
|
int y;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
getPos(x, y);
|
2007-05-29 20:53:32 +00:00
|
|
|
|
setTargetX(x);
|
2004-11-30 01:59:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool Cursor::inMacroMode() const
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
2007-05-29 20:53:32 +00:00
|
|
|
|
if (!inMathed())
|
|
|
|
|
return false;
|
2004-08-13 12:05:27 +00:00
|
|
|
|
if (pos() == 0)
|
2004-01-26 10:13:15 +00:00
|
|
|
|
return false;
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathUnknown const * p = prevAtom()->asUnknownInset();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
return p && !p->final();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
InsetMathUnknown * Cursor::activeMacro()
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
|
|
|
|
return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::pullArg()
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
2007-08-10 11:47:12 +00:00
|
|
|
|
// FIXME: Look here
|
2007-04-26 16:06:39 +00:00
|
|
|
|
MathData ar = cell();
|
2007-11-05 19:41:16 +00:00
|
|
|
|
if (popBackward() && inMathed()) {
|
2004-01-26 10:13:15 +00:00
|
|
|
|
plainErase();
|
|
|
|
|
cell().insert(pos(), ar);
|
|
|
|
|
resetAnchor();
|
|
|
|
|
} else {
|
2004-02-11 14:45:44 +00:00
|
|
|
|
//formula()->mutateToText();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::touch()
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
2007-08-10 11:47:12 +00:00
|
|
|
|
// FIXME: look here
|
2004-01-26 10:13:15 +00:00
|
|
|
|
#if 0
|
2004-03-31 19:11:56 +00:00
|
|
|
|
DocIterator::const_iterator it = begin();
|
|
|
|
|
DocIterator::const_iterator et = end();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
for ( ; it != et; ++it)
|
|
|
|
|
it->cell().touch();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::normalize()
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
2005-07-18 17:12:28 +00:00
|
|
|
|
if (idx() > lastidx()) {
|
2004-01-26 10:13:15 +00:00
|
|
|
|
lyxerr << "this should not really happen - 1: "
|
|
|
|
|
<< idx() << ' ' << nargs()
|
2004-03-18 12:53:43 +00:00
|
|
|
|
<< " in: " << &inset() << endl;
|
2005-07-18 17:12:28 +00:00
|
|
|
|
idx() = lastidx();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pos() > lastpos()) {
|
|
|
|
|
lyxerr << "this should not really happen - 2: "
|
|
|
|
|
<< pos() << ' ' << lastpos() << " in idx: " << idx()
|
|
|
|
|
<< " in atom: '";
|
2006-10-21 00:16:43 +00:00
|
|
|
|
odocstringstream os;
|
2006-10-19 16:51:30 +00:00
|
|
|
|
WriteStream wi(os, false, true);
|
2006-09-16 18:11:38 +00:00
|
|
|
|
inset().asInsetMath()->write(wi);
|
2006-10-21 00:16:43 +00:00
|
|
|
|
lyxerr << to_utf8(os.str()) << endl;
|
2005-07-18 17:12:28 +00:00
|
|
|
|
pos() = lastpos();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
|
bool Cursor::upDownInMath(bool up)
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
2004-02-16 11:58:51 +00:00
|
|
|
|
// Be warned: The 'logic' implemented in this function is highly
|
|
|
|
|
// fragile. A distance of one pixel or a '<' vs '<=' _really
|
|
|
|
|
// matters. So fiddle around with it only if you think you know
|
|
|
|
|
// what you are doing!
|
2004-08-13 19:19:53 +00:00
|
|
|
|
int xo = 0;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
int yo = 0;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
getPos(xo, yo);
|
2007-12-17 18:13:02 +00:00
|
|
|
|
xo = theLyXFunc().cursorBeforeDispatchX();
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
// check if we had something else in mind, if not, this is the future
|
|
|
|
|
// target
|
2007-05-29 20:53:32 +00:00
|
|
|
|
if (x_target_ == -1)
|
|
|
|
|
setTargetX(xo);
|
2007-11-03 18:07:41 +00:00
|
|
|
|
else if (inset().asInsetText() && xo - textTargetOffset() != x_target()) {
|
2007-05-29 20:53:32 +00:00
|
|
|
|
// In text mode inside the line (not left or right) possibly set a new target_x,
|
|
|
|
|
// but only if we are somewhere else than the previous target-offset.
|
|
|
|
|
|
|
|
|
|
// We want to keep the x-target on subsequent up/down movements
|
|
|
|
|
// that cross beyond the end of short lines. Thus a special
|
2007-08-11 10:32:36 +00:00
|
|
|
|
// handling when the cursor is at the end of line: Use the new
|
2007-05-29 20:53:32 +00:00
|
|
|
|
// x-target only if the old one was before the end of line
|
|
|
|
|
// or the old one was after the beginning of the line
|
|
|
|
|
bool inRTL = isWithinRtlParagraph(*this);
|
|
|
|
|
bool left;
|
|
|
|
|
bool right;
|
|
|
|
|
if (inRTL) {
|
|
|
|
|
left = pos() == textRow().endpos();
|
|
|
|
|
right = pos() == textRow().pos();
|
|
|
|
|
} else {
|
|
|
|
|
left = pos() == textRow().pos();
|
|
|
|
|
right = pos() == textRow().endpos();
|
|
|
|
|
}
|
|
|
|
|
if ((!left && !right) ||
|
2007-08-11 10:32:36 +00:00
|
|
|
|
(left && !right && xo < x_target_) ||
|
2007-05-29 20:53:32 +00:00
|
|
|
|
(!left && right && x_target_ < xo))
|
|
|
|
|
setTargetX(xo);
|
|
|
|
|
else
|
|
|
|
|
xo = targetX();
|
2007-08-11 10:32:36 +00:00
|
|
|
|
} else
|
2007-05-29 20:53:32 +00:00
|
|
|
|
xo = targetX();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
|
|
|
|
// try neigbouring script insets
|
2007-05-29 20:53:32 +00:00
|
|
|
|
Cursor old = *this;
|
|
|
|
|
if (inMathed() && !selection()) {
|
2004-01-26 10:13:15 +00:00
|
|
|
|
// try left
|
|
|
|
|
if (pos() != 0) {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathScript const * p = prevAtom()->asScriptInset();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
if (p && p->has(up)) {
|
|
|
|
|
--pos();
|
2006-09-16 18:11:38 +00:00
|
|
|
|
push(*const_cast<InsetMathScript*>(p));
|
2005-07-17 12:28:02 +00:00
|
|
|
|
idx() = p->idxOfScript(up);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
pos() = lastpos();
|
2007-05-29 20:53:32 +00:00
|
|
|
|
|
|
|
|
|
// we went in the right direction? Otherwise don't jump into the script
|
|
|
|
|
int x;
|
|
|
|
|
int y;
|
|
|
|
|
getPos(x, y);
|
2007-12-17 18:13:02 +00:00
|
|
|
|
int oy = theLyXFunc().cursorBeforeDispatchY();
|
|
|
|
|
if ((!up && y <= oy) ||
|
|
|
|
|
(up && y >= oy))
|
2007-05-29 20:53:32 +00:00
|
|
|
|
operator=(old);
|
|
|
|
|
else
|
|
|
|
|
return true;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2007-05-29 20:53:32 +00:00
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
// try right
|
|
|
|
|
if (pos() != lastpos()) {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathScript const * p = nextAtom()->asScriptInset();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
if (p && p->has(up)) {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
push(*const_cast<InsetMathScript*>(p));
|
2005-07-17 12:28:02 +00:00
|
|
|
|
idx() = p->idxOfScript(up);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
pos() = 0;
|
2007-05-29 20:53:32 +00:00
|
|
|
|
|
|
|
|
|
// we went in the right direction? Otherwise don't jump into the script
|
|
|
|
|
int x;
|
|
|
|
|
int y;
|
|
|
|
|
getPos(x, y);
|
2007-12-17 18:13:02 +00:00
|
|
|
|
int oy = theLyXFunc().cursorBeforeDispatchY();
|
|
|
|
|
if ((!up && y <= oy) ||
|
|
|
|
|
(up && y >= oy))
|
2007-05-29 20:53:32 +00:00
|
|
|
|
operator=(old);
|
|
|
|
|
else
|
|
|
|
|
return true;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-05-29 20:53:32 +00:00
|
|
|
|
|
|
|
|
|
// try to find an inset that knows better then we,
|
|
|
|
|
if (inset().idxUpDown(*this, up)) {
|
|
|
|
|
//lyxerr << "idxUpDown triggered" << endl;
|
|
|
|
|
// try to find best position within this inset
|
|
|
|
|
if (!selection())
|
|
|
|
|
setCursor(bruteFind2(*this, xo, yo));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// any improvement going just out of inset?
|
2007-11-05 19:41:16 +00:00
|
|
|
|
if (popBackward() && inMathed()) {
|
|
|
|
|
//lyxerr << "updown: popBackward succeeded" << endl;
|
2005-02-08 13:18:05 +00:00
|
|
|
|
int xnew;
|
|
|
|
|
int ynew;
|
2007-12-17 18:13:02 +00:00
|
|
|
|
int yold = theLyXFunc().cursorBeforeDispatchY();
|
2004-01-30 11:41:12 +00:00
|
|
|
|
getPos(xnew, ynew);
|
2007-12-17 18:13:02 +00:00
|
|
|
|
if (up ? ynew < yold : ynew > yold)
|
2004-01-26 10:13:15 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2007-05-29 20:53:32 +00:00
|
|
|
|
|
|
|
|
|
// no success, we are probably at the document top or bottom
|
|
|
|
|
operator=(old);
|
|
|
|
|
return false;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-11 10:32:36 +00:00
|
|
|
|
bool Cursor::upDownInText(bool up, bool & updateNeeded)
|
2007-05-29 20:53:32 +00:00
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(text());
|
|
|
|
|
|
|
|
|
|
// where are we?
|
|
|
|
|
int xo = 0;
|
|
|
|
|
int yo = 0;
|
|
|
|
|
getPos(xo, yo);
|
2007-12-17 18:13:02 +00:00
|
|
|
|
xo = theLyXFunc().cursorBeforeDispatchX();
|
|
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
|
// update the targetX - this is here before the "return false"
|
|
|
|
|
// to set a new target which can be used by InsetTexts above
|
|
|
|
|
// if we cannot move up/down inside this inset anymore
|
|
|
|
|
if (x_target_ == -1)
|
|
|
|
|
setTargetX(xo);
|
2007-08-11 10:32:36 +00:00
|
|
|
|
else if (xo - textTargetOffset() != x_target() &&
|
2007-06-14 20:32:28 +00:00
|
|
|
|
depth() == beforeDispatchCursor_.depth()) {
|
2007-05-29 20:53:32 +00:00
|
|
|
|
// In text mode inside the line (not left or right) possibly set a new target_x,
|
|
|
|
|
// but only if we are somewhere else than the previous target-offset.
|
|
|
|
|
|
|
|
|
|
// We want to keep the x-target on subsequent up/down movements
|
|
|
|
|
// that cross beyond the end of short lines. Thus a special
|
2007-08-11 10:32:36 +00:00
|
|
|
|
// handling when the cursor is at the end of line: Use the new
|
2007-05-29 20:53:32 +00:00
|
|
|
|
// x-target only if the old one was before the end of line
|
|
|
|
|
// or the old one was after the beginning of the line
|
|
|
|
|
bool inRTL = isWithinRtlParagraph(*this);
|
|
|
|
|
bool left;
|
|
|
|
|
bool right;
|
|
|
|
|
if (inRTL) {
|
|
|
|
|
left = pos() == textRow().endpos();
|
|
|
|
|
right = pos() == textRow().pos();
|
|
|
|
|
} else {
|
|
|
|
|
left = pos() == textRow().pos();
|
|
|
|
|
right = pos() == textRow().endpos();
|
|
|
|
|
}
|
|
|
|
|
if ((!left && !right) ||
|
2007-08-11 10:32:36 +00:00
|
|
|
|
(left && !right && xo < x_target_) ||
|
2007-05-29 20:53:32 +00:00
|
|
|
|
(!left && right && x_target_ < xo))
|
|
|
|
|
setTargetX(xo);
|
|
|
|
|
else
|
|
|
|
|
xo = targetX();
|
2007-08-11 10:32:36 +00:00
|
|
|
|
} else
|
2007-05-29 20:53:32 +00:00
|
|
|
|
xo = targetX();
|
|
|
|
|
|
|
|
|
|
// first get the current line
|
2007-09-02 09:44:08 +00:00
|
|
|
|
TextMetrics & tm = bv_->textMetrics(text());
|
2007-05-29 20:53:32 +00:00
|
|
|
|
ParagraphMetrics const & pm = tm.parMetrics(pit());
|
|
|
|
|
int row;
|
|
|
|
|
if (pos() && boundary())
|
|
|
|
|
row = pm.pos2row(pos() - 1);
|
|
|
|
|
else
|
|
|
|
|
row = pm.pos2row(pos());
|
|
|
|
|
|
|
|
|
|
// are we not at the start or end?
|
|
|
|
|
if (up) {
|
|
|
|
|
if (pit() == 0 && row == 0)
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
2007-08-11 10:32:36 +00:00
|
|
|
|
if (pit() + 1 >= int(text()->paragraphs().size()) &&
|
2007-05-29 20:53:32 +00:00
|
|
|
|
row + 1 >= int(pm.rows().size()))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2007-06-14 20:32:28 +00:00
|
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
|
// with and without selection are handled differently
|
|
|
|
|
if (!selection()) {
|
2007-09-29 09:22:17 +00:00
|
|
|
|
int yo = bv().getPos(*this, boundary()).y_;
|
2007-05-29 20:53:32 +00:00
|
|
|
|
Cursor old = *this;
|
|
|
|
|
// To next/previous row
|
|
|
|
|
if (up)
|
2007-09-02 09:44:08 +00:00
|
|
|
|
tm.editXY(*this, xo, yo - textRow().ascent() - 1);
|
2007-05-29 20:53:32 +00:00
|
|
|
|
else
|
2007-09-02 09:44:08 +00:00
|
|
|
|
tm.editXY(*this, xo, yo + textRow().descent() + 1);
|
2007-05-29 20:53:32 +00:00
|
|
|
|
clearSelection();
|
|
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
|
Cursor dummy = *this;
|
|
|
|
|
if (dummy == old)
|
|
|
|
|
++dummy.pos();
|
2007-05-30 19:38:22 +00:00
|
|
|
|
if (bv().checkDepm(dummy, old)) {
|
|
|
|
|
updateNeeded = true;
|
|
|
|
|
// Make sure that cur gets back whatever happened to dummy(Lgb)
|
2007-05-29 20:53:32 +00:00
|
|
|
|
operator=(dummy);
|
2007-05-30 19:38:22 +00:00
|
|
|
|
}
|
2007-05-29 20:53:32 +00:00
|
|
|
|
} else {
|
|
|
|
|
// if there is a selection, we stay out of any inset, and just jump to the right position:
|
|
|
|
|
Cursor old = *this;
|
|
|
|
|
if (up) {
|
|
|
|
|
if (row > 0) {
|
2007-12-12 19:28:07 +00:00
|
|
|
|
top().pos() = min(tm.x2pos(pit(), row - 1, xo), top().lastpos());
|
2007-05-29 20:53:32 +00:00
|
|
|
|
} else if (pit() > 0) {
|
|
|
|
|
--pit();
|
|
|
|
|
ParagraphMetrics const & pmcur = bv_->parMetrics(text(), pit());
|
2007-12-12 19:28:07 +00:00
|
|
|
|
top().pos() = min(tm.x2pos(pit(), pmcur.rows().size() - 1, xo), top().lastpos());
|
2007-05-29 20:53:32 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (row + 1 < int(pm.rows().size())) {
|
2007-12-12 19:28:07 +00:00
|
|
|
|
top().pos() = min(tm.x2pos(pit(), row + 1, xo), top().lastpos());
|
2007-05-29 20:53:32 +00:00
|
|
|
|
} else if (pit() + 1 < int(text()->paragraphs().size())) {
|
|
|
|
|
++pit();
|
2007-12-12 19:28:07 +00:00
|
|
|
|
top().pos() = min(tm.x2pos(pit(), 0, xo), top().lastpos());
|
2007-05-29 20:53:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2007-06-14 20:32:28 +00:00
|
|
|
|
|
2007-05-30 19:38:22 +00:00
|
|
|
|
updateNeeded |= bv().checkDepm(*this, old);
|
2007-05-29 20:53:32 +00:00
|
|
|
|
}
|
2007-06-14 20:32:28 +00:00
|
|
|
|
|
2007-05-29 20:53:32 +00:00
|
|
|
|
updateTextTargetOffset();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::handleFont(string const & font)
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
2007-11-29 21:10:35 +00:00
|
|
|
|
LYXERR(Debug::DEBUG, font);
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring safe;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
if (selection()) {
|
|
|
|
|
macroModeClose();
|
2006-10-21 00:16:43 +00:00
|
|
|
|
safe = cap::grabAndEraseSelection(*this);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (lastpos() != 0) {
|
|
|
|
|
// something left in the cell
|
|
|
|
|
if (pos() == 0) {
|
|
|
|
|
// cursor in first position
|
2007-11-05 19:41:16 +00:00
|
|
|
|
popBackward();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
} else if (pos() == lastpos()) {
|
|
|
|
|
// cursor in last position
|
2007-11-05 19:41:16 +00:00
|
|
|
|
popForward();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
} else {
|
|
|
|
|
// cursor in between. split cell
|
2007-04-26 16:06:39 +00:00
|
|
|
|
MathData::iterator bt = cell().begin();
|
2006-10-22 10:15:23 +00:00
|
|
|
|
MathAtom at = createInsetMath(from_utf8(font));
|
2007-04-26 16:06:39 +00:00
|
|
|
|
at.nucleus()->cell(0) = MathData(bt, bt + pos());
|
2004-01-26 10:13:15 +00:00
|
|
|
|
cell().erase(bt, bt + pos());
|
2007-11-05 19:41:16 +00:00
|
|
|
|
popBackward();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
plainInsert(at);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// nothing left in the cell
|
|
|
|
|
pullArg();
|
|
|
|
|
plainErase();
|
|
|
|
|
}
|
|
|
|
|
insert(safe);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::message(docstring const & msg) const
|
2004-02-03 11:49:05 +00:00
|
|
|
|
{
|
2006-10-11 17:24:46 +00:00
|
|
|
|
theLyXFunc().setMessage(msg);
|
2004-02-03 11:49:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::errorMessage(docstring const & msg) const
|
2004-02-03 11:49:05 +00:00
|
|
|
|
{
|
2006-10-11 17:24:46 +00:00
|
|
|
|
theLyXFunc().setErrorMessage(msg);
|
2004-02-03 11:49:05 +00:00
|
|
|
|
}
|
2004-02-11 14:45:44 +00:00
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
docstring Cursor::selectionAsString(bool label) const
|
2004-02-11 14:45:44 +00:00
|
|
|
|
{
|
|
|
|
|
if (!selection())
|
2006-09-03 07:02:38 +00:00
|
|
|
|
return docstring();
|
2004-02-11 14:45:44 +00:00
|
|
|
|
|
|
|
|
|
if (inTexted()) {
|
2007-08-21 13:03:55 +00:00
|
|
|
|
Buffer const & buffer = bv().buffer();
|
2005-07-18 11:00:15 +00:00
|
|
|
|
ParagraphList const & pars = text()->paragraphs();
|
2004-02-11 14:45:44 +00:00
|
|
|
|
|
|
|
|
|
// should be const ...
|
2004-11-24 21:53:46 +00:00
|
|
|
|
pit_type startpit = selBegin().pit();
|
|
|
|
|
pit_type endpit = selEnd().pit();
|
2004-02-11 14:45:44 +00:00
|
|
|
|
size_t const startpos = selBegin().pos();
|
|
|
|
|
size_t const endpos = selEnd().pos();
|
|
|
|
|
|
|
|
|
|
if (startpit == endpit)
|
2006-10-11 19:40:50 +00:00
|
|
|
|
return pars[startpit].asString(buffer, startpos, endpos, label);
|
2004-02-11 14:45:44 +00:00
|
|
|
|
|
|
|
|
|
// First paragraph in selection
|
2006-10-11 19:40:50 +00:00
|
|
|
|
docstring result = pars[startpit].
|
2007-05-07 08:57:53 +00:00
|
|
|
|
asString(buffer, startpos, pars[startpit].size(), label)
|
|
|
|
|
+ parbreak(pars[startpit]);
|
2004-02-11 14:45:44 +00:00
|
|
|
|
|
|
|
|
|
// The paragraphs in between (if any)
|
2004-11-24 21:53:46 +00:00
|
|
|
|
for (pit_type pit = startpit + 1; pit != endpit; ++pit) {
|
2005-07-18 11:00:15 +00:00
|
|
|
|
Paragraph const & par = pars[pit];
|
2007-05-07 08:57:53 +00:00
|
|
|
|
result += par.asString(buffer, 0, par.size(), label)
|
|
|
|
|
+ parbreak(pars[pit]);
|
2004-03-25 09:16:36 +00:00
|
|
|
|
}
|
2004-02-11 14:45:44 +00:00
|
|
|
|
|
|
|
|
|
// Last paragraph in selection
|
2004-03-25 09:16:36 +00:00
|
|
|
|
result += pars[endpit].asString(buffer, 0, endpos, label);
|
2004-02-11 14:45:44 +00:00
|
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
|
return result;
|
2004-02-11 14:45:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-10-12 18:44:53 +00:00
|
|
|
|
if (inMathed())
|
2006-10-22 10:15:23 +00:00
|
|
|
|
return cap::grabSelection(*this);
|
2005-10-12 18:44:53 +00:00
|
|
|
|
|
2006-09-03 07:02:38 +00:00
|
|
|
|
return docstring();
|
2004-02-11 14:45:44 +00:00
|
|
|
|
}
|
2004-02-13 07:30:59 +00:00
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
docstring Cursor::currentState()
|
2004-02-13 07:30:59 +00:00
|
|
|
|
{
|
|
|
|
|
if (inMathed()) {
|
2006-10-22 10:15:23 +00:00
|
|
|
|
odocstringstream os;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
info(os);
|
2006-12-21 13:58:28 +00:00
|
|
|
|
return os.str();
|
2004-02-13 07:30:59 +00:00
|
|
|
|
}
|
2004-03-18 12:53:43 +00:00
|
|
|
|
|
|
|
|
|
if (inTexted())
|
2005-02-08 13:18:05 +00:00
|
|
|
|
return text()->currentState(*this);
|
2004-03-18 12:53:43 +00:00
|
|
|
|
|
2006-12-21 13:58:28 +00:00
|
|
|
|
return docstring();
|
2004-02-13 07:30:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
docstring Cursor::getPossibleLabel()
|
2004-02-13 13:51:12 +00:00
|
|
|
|
{
|
2006-11-11 11:27:47 +00:00
|
|
|
|
return inMathed() ? from_ascii("eq:") : text()->getPossibleLabel(*this);
|
2004-02-13 13:51:12 +00:00
|
|
|
|
}
|
2004-02-16 11:58:51 +00:00
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
Encoding const * Cursor::getEncoding() const
|
2004-02-16 11:58:51 +00:00
|
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
|
if (empty())
|
|
|
|
|
return 0;
|
2008-02-07 17:07:27 +00:00
|
|
|
|
CursorSlice const & sl = innerTextSlice();
|
2007-04-29 23:33:02 +00:00
|
|
|
|
Text const & text = *sl.text();
|
2007-04-29 18:17:15 +00:00
|
|
|
|
Font font = text.getPar(sl.pit()).getFont(
|
2007-08-21 13:03:55 +00:00
|
|
|
|
bv().buffer().params(), sl.pos(), outerFont(sl.pit(), text.paragraphs()));
|
2004-03-18 12:53:43 +00:00
|
|
|
|
return font.language()->encoding();
|
2004-02-16 11:58:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::undispatched()
|
2004-02-16 11:58:51 +00:00
|
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
|
disp_.dispatched(false);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::dispatched()
|
2004-03-27 12:46:30 +00:00
|
|
|
|
{
|
|
|
|
|
disp_.dispatched(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::updateFlags(Update::flags f)
|
2004-08-13 14:56:06 +00:00
|
|
|
|
{
|
2006-10-22 11:46:36 +00:00
|
|
|
|
disp_.update(f);
|
2004-08-13 14:56:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void Cursor::noUpdate()
|
2004-02-16 11:58:51 +00:00
|
|
|
|
{
|
2006-10-22 11:46:36 +00:00
|
|
|
|
disp_.update(Update::None);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
}
|
2005-01-10 09:28:06 +00:00
|
|
|
|
|
|
|
|
|
|
2007-04-29 18:17:15 +00:00
|
|
|
|
Font Cursor::getFont() const
|
2005-01-10 09:28:06 +00:00
|
|
|
|
{
|
2007-09-02 13:35:48 +00:00
|
|
|
|
// The logic here should more or less match to the Cursor::setCurrentFont
|
2007-06-07 20:40:01 +00:00
|
|
|
|
// logic, i.e. the cursor height should give a hint what will happen
|
|
|
|
|
// if a character is entered.
|
|
|
|
|
|
2005-01-10 09:28:06 +00:00
|
|
|
|
// HACK. far from being perfect...
|
2008-02-07 17:07:27 +00:00
|
|
|
|
|
|
|
|
|
CursorSlice const & sl = innerTextSlice();
|
2007-04-29 23:33:02 +00:00
|
|
|
|
Text const & text = *sl.text();
|
2007-06-07 20:40:01 +00:00
|
|
|
|
Paragraph const & par = text.getPar(sl.pit());
|
|
|
|
|
|
|
|
|
|
// on boundary, so we are really at the character before
|
|
|
|
|
pos_type pos = sl.pos();
|
|
|
|
|
if (pos > 0 && boundary())
|
|
|
|
|
--pos;
|
|
|
|
|
|
|
|
|
|
// on space? Take the font before (only for RTL boundary stay)
|
|
|
|
|
if (pos > 0) {
|
2007-09-02 21:48:49 +00:00
|
|
|
|
TextMetrics const & tm = bv().textMetrics(&text);
|
2007-06-07 20:40:01 +00:00
|
|
|
|
if (pos == sl.lastpos()
|
2007-09-02 22:28:49 +00:00
|
|
|
|
|| (par.isSeparator(pos)
|
|
|
|
|
&& !tm.isRTLBoundary(sl.pit(), pos)))
|
2007-06-07 20:40:01 +00:00
|
|
|
|
--pos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// get font at the position
|
2007-08-21 13:03:55 +00:00
|
|
|
|
Font font = par.getFont(bv().buffer().params(), pos,
|
2005-01-10 09:28:06 +00:00
|
|
|
|
outerFont(sl.pit(), text.paragraphs()));
|
2005-02-08 13:18:05 +00:00
|
|
|
|
|
2005-01-10 09:28:06 +00:00
|
|
|
|
return font;
|
|
|
|
|
}
|
2005-02-15 17:34:54 +00:00
|
|
|
|
|
|
|
|
|
|
2007-08-19 13:40:09 +00:00
|
|
|
|
bool Cursor::fixIfBroken()
|
2005-02-15 17:34:54 +00:00
|
|
|
|
{
|
2007-05-25 23:17:24 +00:00
|
|
|
|
if (DocIterator::fixIfBroken()) {
|
|
|
|
|
clearSelection();
|
|
|
|
|
resetAnchor();
|
2007-08-19 13:40:09 +00:00
|
|
|
|
return true;
|
2005-02-15 17:34:54 +00:00
|
|
|
|
}
|
2007-08-19 13:40:09 +00:00
|
|
|
|
return false;
|
2005-02-15 17:34:54 +00:00
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
2007-06-14 20:32:28 +00:00
|
|
|
|
bool notifyCursorLeaves(DocIterator const & old, Cursor & cur)
|
|
|
|
|
{
|
|
|
|
|
// find inset in common
|
|
|
|
|
size_type i;
|
|
|
|
|
for (i = 0; i < old.depth() && i < cur.depth(); ++i) {
|
|
|
|
|
if (&old.inset() != &cur.inset())
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// notify everything on top of the common part in old cursor,
|
|
|
|
|
// but stop if the inset claims the cursor to be invalid now
|
|
|
|
|
for (; i < old.depth(); ++i) {
|
|
|
|
|
if (old[i].inset().notifyCursorLeaves(cur))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-02 13:35:48 +00:00
|
|
|
|
void Cursor::setCurrentFont()
|
|
|
|
|
{
|
2007-09-14 12:52:39 +00:00
|
|
|
|
CursorSlice const & cs = innerTextSlice();
|
|
|
|
|
Paragraph const & par = cs.paragraph();
|
|
|
|
|
pos_type cpit = cs.pit();
|
|
|
|
|
pos_type cpos = cs.pos();
|
|
|
|
|
Text const & ctext = *cs.text();
|
2007-09-02 21:48:49 +00:00
|
|
|
|
TextMetrics const & tm = bv().textMetrics(&ctext);
|
2007-09-02 13:35:48 +00:00
|
|
|
|
|
|
|
|
|
// are we behind previous char in fact? -> go to that char
|
|
|
|
|
if (cpos > 0 && boundary())
|
|
|
|
|
--cpos;
|
|
|
|
|
|
|
|
|
|
// find position to take the font from
|
|
|
|
|
if (cpos != 0) {
|
|
|
|
|
// paragraph end? -> font of last char
|
|
|
|
|
if (cpos == lastpos())
|
|
|
|
|
--cpos;
|
|
|
|
|
// on space? -> look at the words in front of space
|
|
|
|
|
else if (cpos > 0 && par.isSeparator(cpos)) {
|
|
|
|
|
// abc| def -> font of c
|
|
|
|
|
// abc |[WERBEH], i.e. boundary==true -> font of c
|
|
|
|
|
// abc [WERBEH]| def, font of the space
|
2007-09-14 12:52:39 +00:00
|
|
|
|
if (!tm.isRTLBoundary(cpit, cpos))
|
2007-09-02 13:35:48 +00:00
|
|
|
|
--cpos;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// get font
|
|
|
|
|
BufferParams const & bufparams = buffer().params();
|
|
|
|
|
current_font = par.getFontSettings(bufparams, cpos);
|
2007-09-14 12:52:39 +00:00
|
|
|
|
real_current_font = tm.getDisplayFont(cpit, cpos);
|
2007-09-02 13:35:48 +00:00
|
|
|
|
|
|
|
|
|
// special case for paragraph end
|
2007-09-14 12:52:39 +00:00
|
|
|
|
if (cs.pos() == lastpos()
|
|
|
|
|
&& tm.isRTLBoundary(cpit, cs.pos())
|
2007-09-02 13:35:48 +00:00
|
|
|
|
&& !boundary()) {
|
|
|
|
|
Language const * lang = par.getParLanguage(bufparams);
|
|
|
|
|
current_font.setLanguage(lang);
|
2007-10-28 18:51:54 +00:00
|
|
|
|
current_font.fontInfo().setNumber(FONT_OFF);
|
2007-09-02 13:35:48 +00:00
|
|
|
|
real_current_font.setLanguage(lang);
|
2007-10-28 18:51:54 +00:00
|
|
|
|
real_current_font.fontInfo().setNumber(FONT_OFF);
|
2007-09-02 13:35:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-18 11:51:17 +00:00
|
|
|
|
|
|
|
|
|
bool Cursor::textUndo()
|
|
|
|
|
{
|
|
|
|
|
DocIterator dit = *this;
|
|
|
|
|
// Undo::textUndo() will modify dit.
|
|
|
|
|
if (!bv_->buffer().undo().textUndo(dit))
|
|
|
|
|
return false;
|
|
|
|
|
// Set cursor
|
|
|
|
|
setCursor(dit);
|
|
|
|
|
selection() = false;
|
|
|
|
|
resetAnchor();
|
|
|
|
|
fixIfBroken();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Cursor::textRedo()
|
|
|
|
|
{
|
|
|
|
|
DocIterator dit = *this;
|
|
|
|
|
// Undo::textRedo() will modify dit.
|
|
|
|
|
if (!bv_->buffer().undo().textRedo(dit))
|
|
|
|
|
return false;
|
|
|
|
|
// Set cursor
|
|
|
|
|
setCursor(dit);
|
|
|
|
|
selection() = false;
|
|
|
|
|
resetAnchor();
|
|
|
|
|
fixIfBroken();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Cursor::finishUndo()
|
|
|
|
|
{
|
|
|
|
|
bv_->buffer().undo().finishUndo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Cursor::recordUndo(UndoKind kind, pit_type from, pit_type to)
|
|
|
|
|
{
|
|
|
|
|
bv_->buffer().undo().recordUndo(*this, kind, from, to);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Cursor::recordUndo(UndoKind kind, pit_type from)
|
|
|
|
|
{
|
|
|
|
|
bv_->buffer().undo().recordUndo(*this, kind, from);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Cursor::recordUndo(UndoKind kind)
|
|
|
|
|
{
|
|
|
|
|
bv_->buffer().undo().recordUndo(*this, kind);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Cursor::recordUndoInset(UndoKind kind)
|
|
|
|
|
{
|
|
|
|
|
bv_->buffer().undo().recordUndoInset(*this, kind);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Cursor::recordUndoFullDocument()
|
|
|
|
|
{
|
|
|
|
|
bv_->buffer().undo().recordUndoFullDocument(*this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Cursor::recordUndoSelection()
|
|
|
|
|
{
|
|
|
|
|
bv_->buffer().undo().recordUndo(*this, ATOMIC_UNDO,
|
|
|
|
|
selBegin().pit(), selEnd().pit());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-01-12 21:38:51 +00:00
|
|
|
|
void Cursor::checkBufferStructure()
|
|
|
|
|
{
|
|
|
|
|
if (paragraph().layout()->toclevel == Layout::NOT_IN_TOC)
|
|
|
|
|
return;
|
|
|
|
|
Buffer const * master = buffer().masterBuffer();
|
|
|
|
|
master->tocBackend().updateItem(ParConstIterator(*this));
|
|
|
|
|
master->structureChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
} // namespace lyx
|