2003-09-17 16:44:51 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file cursor.C
|
|
|
|
|
* 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
|
2003-09-17 16:44:51 +00:00
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2004-03-11 17:16:38 +00:00
|
|
|
|
#include "BufferView.h"
|
2004-03-18 12:53:43 +00:00
|
|
|
|
#include "buffer.h"
|
2003-09-17 16:44:51 +00:00
|
|
|
|
#include "cursor.h"
|
2004-11-30 01:59:49 +00:00
|
|
|
|
#include "coordcache.h"
|
2004-03-25 09:16:36 +00:00
|
|
|
|
#include "CutAndPaste.h"
|
2003-09-17 16:44:51 +00:00
|
|
|
|
#include "debug.h"
|
2003-10-29 10:47:21 +00:00
|
|
|
|
#include "dispatchresult.h"
|
2004-03-18 12:53:43 +00:00
|
|
|
|
#include "encoding.h"
|
2003-11-10 09:06:48 +00:00
|
|
|
|
#include "funcrequest.h"
|
2004-03-18 12:53:43 +00:00
|
|
|
|
#include "language.h"
|
2003-11-10 09:06:48 +00:00
|
|
|
|
#include "lfuns.h"
|
2004-03-18 12:53:43 +00:00
|
|
|
|
#include "lyxfont.h"
|
2004-02-03 11:49:05 +00:00
|
|
|
|
#include "lyxfunc.h" // only for setMessage()
|
2004-01-26 10:13:15 +00:00
|
|
|
|
#include "lyxrc.h"
|
2003-11-13 08:50:26 +00:00
|
|
|
|
#include "lyxrow.h"
|
2004-02-03 11:49:05 +00:00
|
|
|
|
#include "lyxtext.h"
|
2004-01-26 10:13:15 +00:00
|
|
|
|
#include "paragraph.h"
|
2004-03-18 12:53:43 +00:00
|
|
|
|
#include "paragraph_funcs.h"
|
2004-03-28 22:00:22 +00:00
|
|
|
|
#include "pariterator.h"
|
2003-09-17 16:44:51 +00:00
|
|
|
|
|
2003-11-10 09:06:48 +00:00
|
|
|
|
#include "insets/insettabular.h"
|
2003-11-04 12:36:59 +00:00
|
|
|
|
#include "insets/insettext.h"
|
|
|
|
|
|
2004-01-16 13:35:10 +00:00
|
|
|
|
#include "mathed/math_data.h"
|
2004-03-18 16:05:32 +00:00
|
|
|
|
#include "mathed/math_inset.h"
|
2005-07-17 12:28:02 +00:00
|
|
|
|
#include "mathed/math_scriptinset.h"
|
2004-04-13 06:27:29 +00:00
|
|
|
|
#include "mathed/math_macrotable.h"
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
|
|
|
|
#include "support/limited_stack.h"
|
2004-02-13 07:30:59 +00:00
|
|
|
|
|
2004-02-03 11:49:05 +00:00
|
|
|
|
#include "frontends/LyXView.h"
|
2004-11-30 01:59:49 +00:00
|
|
|
|
#include "frontends/font_metrics.h"
|
2004-01-16 13:35:10 +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>
|
2004-08-14 15:55:22 +00:00
|
|
|
|
#include <boost/current_function.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>
|
2004-07-24 10:55:30 +00:00
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
|
using lyx::pit_type;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
using std::string;
|
2003-09-17 16:44:51 +00:00
|
|
|
|
using std::vector;
|
2003-10-29 12:18:08 +00:00
|
|
|
|
using std::endl;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
#ifndef CXX_GLOBAL_CSTD
|
|
|
|
|
using std::isalpha;
|
|
|
|
|
#endif
|
|
|
|
|
using std::min;
|
|
|
|
|
using std::swap;
|
|
|
|
|
|
2004-08-13 19:19:53 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
2004-11-06 15:23:12 +00:00
|
|
|
|
bool
|
|
|
|
|
positionable(DocIterator const & cursor, DocIterator const & anchor)
|
2004-08-13 19:19:53 +00:00
|
|
|
|
{
|
|
|
|
|
// avoid deeper nested insets when selecting
|
2005-02-08 13:18:05 +00:00
|
|
|
|
if (cursor.depth() > anchor.depth())
|
2004-08-13 19:19:53 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// anchor might be deeper, should have same path then
|
2005-02-08 13:18:05 +00:00
|
|
|
|
for (size_t i = 0; i < cursor.depth(); ++i)
|
2004-08-13 19:19:53 +00:00
|
|
|
|
if (&cursor[i].inset() != &anchor[i].inset())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// position should be ok.
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Find position closest to (x, y) in cell given by iter.
|
2004-11-30 01:59:49 +00:00
|
|
|
|
// Used only in mathed
|
2004-08-13 19:19:53 +00:00
|
|
|
|
DocIterator bruteFind2(LCursor const & c, int x, int y)
|
|
|
|
|
{
|
2004-11-30 01:59:49 +00:00
|
|
|
|
double best_dist = std::numeric_limits<double>::max();
|
2004-08-13 19:19:53 +00:00
|
|
|
|
|
|
|
|
|
DocIterator result;
|
|
|
|
|
|
|
|
|
|
DocIterator it = c;
|
2005-02-08 13:18:05 +00:00
|
|
|
|
it.top().pos() = 0;
|
2004-08-13 19:19:53 +00:00
|
|
|
|
DocIterator et = c;
|
2005-02-08 13:18:05 +00:00
|
|
|
|
et.top().pos() = et.top().asMathInset()->cell(et.top().idx()).size();
|
2005-09-20 08:31:37 +00:00
|
|
|
|
for (size_t i = 0; ; ++i) {
|
2005-02-08 13:18:05 +00:00
|
|
|
|
int xo;
|
|
|
|
|
int yo;
|
2005-07-16 00:04:54 +00:00
|
|
|
|
it.inset().cursorPos(it.top(), c.boundary() && ((i+1) == it.depth()), xo, yo);
|
2004-08-13 19:19:53 +00:00
|
|
|
|
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'
|
2004-11-30 01:59:49 +00:00
|
|
|
|
lyxerr[Debug::DEBUG] << "i: " << i << " d: " << d
|
|
|
|
|
<< " best: " << best_dist << endl;
|
2004-08-13 19:19:53 +00:00
|
|
|
|
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(LCursor & cursor,
|
|
|
|
|
int x, int y, int xlow, int xhigh, int ylow, int yhigh)
|
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(!cursor.empty());
|
2005-07-18 17:12:28 +00:00
|
|
|
|
InsetBase & inset = cursor[0].inset();
|
2004-12-03 16:39:59 +00:00
|
|
|
|
|
2005-07-18 17:12:28 +00:00
|
|
|
|
DocIterator it = doc_iterator_begin(inset);
|
|
|
|
|
DocIterator const et = doc_iterator_end(inset);
|
2004-08-13 19:19:53 +00:00
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
double best_dist = std::numeric_limits<double>::max();;
|
|
|
|
|
DocIterator best_cursor = et;
|
2004-08-13 19:19:53 +00:00
|
|
|
|
|
|
|
|
|
for ( ; it != et; it.forwardPos()) {
|
|
|
|
|
// avoid invalid nesting when selecting
|
2004-11-30 01:59:49 +00:00
|
|
|
|
if (bv_funcs::status(&cursor.bv(), it) == bv_funcs::CUR_INSIDE
|
|
|
|
|
&& (!cursor.selection() || positionable(it, cursor.anchor_))) {
|
2005-07-15 15:49:40 +00:00
|
|
|
|
Point p = bv_funcs::getPos(it, false);
|
2004-11-30 01:59:49 +00:00
|
|
|
|
int xo = p.x_;
|
|
|
|
|
int yo = p.y_;
|
2004-08-13 19:19:53 +00:00
|
|
|
|
if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
|
2005-07-18 17:12:28 +00:00
|
|
|
|
double const dx = xo - x;
|
|
|
|
|
double const dy = yo - y;
|
|
|
|
|
double const d = dx * dx + dy * dy;
|
2004-08-13 19:19:53 +00:00
|
|
|
|
// '<=' 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) {
|
2005-07-18 17:12:28 +00:00
|
|
|
|
lyxerr << "*" << endl;
|
2004-08-13 19:19:53 +00:00
|
|
|
|
best_dist = d;
|
|
|
|
|
best_cursor = it;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
if (best_cursor != et) {
|
2004-08-14 19:55:00 +00:00
|
|
|
|
cursor.setCursor(best_cursor);
|
2004-11-30 01:59:49 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2004-08-13 19:19:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-07-18 17:12:28 +00:00
|
|
|
|
|
|
|
|
|
/// moves position closest to (x, y) in given box
|
|
|
|
|
bool bruteFind3(LCursor & 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();
|
|
|
|
|
|
|
|
|
|
// FIXME: bit more work needed to get 'from' and 'to' right.
|
|
|
|
|
pit_type from = cur.bottom().pit();
|
2005-09-20 08:31:37 +00:00
|
|
|
|
//pit_type to = cur.bottom().pit();
|
2005-07-18 17:12:28 +00:00
|
|
|
|
//lyxerr << "Pit start: " << from << endl;
|
|
|
|
|
|
|
|
|
|
//lyxerr << "bruteFind3: x: " << x << " y: " << y
|
|
|
|
|
// << " xlow: " << xlow << " xhigh: " << xhigh
|
|
|
|
|
// << " ylow: " << ylow << " yhigh: " << yhigh
|
|
|
|
|
// << endl;
|
|
|
|
|
InsetBase & inset = bv.buffer()->inset();
|
|
|
|
|
DocIterator it = doc_iterator_begin(inset);
|
|
|
|
|
it.pit() = from;
|
|
|
|
|
DocIterator et = doc_iterator_end(inset);
|
|
|
|
|
|
|
|
|
|
double best_dist = std::numeric_limits<double>::max();
|
|
|
|
|
DocIterator best_cursor = et;
|
|
|
|
|
|
|
|
|
|
for ( ; it != et; it.forwardPos()) {
|
|
|
|
|
// avoid invalid nesting when selecting
|
|
|
|
|
if (bv_funcs::status(&bv, it) == bv_funcs::CUR_INSIDE
|
|
|
|
|
&& (!cur.selection() || positionable(it, cur.anchor_))) {
|
|
|
|
|
Point p = bv_funcs::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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//lyxerr << "best_dist: " << best_dist << " cur:\n" << best_cursor << endl;
|
|
|
|
|
if (best_cursor == et)
|
|
|
|
|
return false;
|
|
|
|
|
cur.setCursor(best_cursor);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
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!
|
2004-01-16 10:55:19 +00:00
|
|
|
|
LCursor::LCursor(BufferView & bv)
|
2004-04-07 20:20:15 +00:00
|
|
|
|
: DocIterator(), bv_(&bv), anchor_(), x_target_(-1),
|
2005-07-15 15:49:40 +00:00
|
|
|
|
selection_(false), mark_(false), logicalpos_(false)
|
2003-11-10 09:06:48 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2004-03-19 16:36:52 +00:00
|
|
|
|
void LCursor::reset(InsetBase & 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));
|
2004-03-31 19:11:56 +00:00
|
|
|
|
anchor_ = DocIterator(inset);
|
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
|
|
|
|
|
void LCursor::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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-08-13 14:56:06 +00:00
|
|
|
|
void LCursor::dispatch(FuncRequest const & cmd0)
|
2003-09-17 16:44:51 +00:00
|
|
|
|
{
|
2005-02-08 13:18:05 +00:00
|
|
|
|
lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< " cmd: " << cmd0 << '\n'
|
|
|
|
|
<< *this << endl;
|
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;
|
2004-03-18 13:57:20 +00:00
|
|
|
|
LCursor safe = *this;
|
2004-03-18 12:53:43 +00:00
|
|
|
|
|
2005-02-08 13:18:05 +00:00
|
|
|
|
for (; depth(); pop()) {
|
2005-01-10 09:28:06 +00:00
|
|
|
|
lyxerr[Debug::DEBUG] << "LCursor::dispatch: cmd: "
|
|
|
|
|
<< cmd0 << endl << *this << endl;
|
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.
|
|
|
|
|
disp_.update(true);
|
|
|
|
|
disp_.dispatched(true);
|
|
|
|
|
inset().dispatch(*this, cmd);
|
|
|
|
|
if (disp_.dispatched())
|
|
|
|
|
break;
|
2003-09-17 16:44:51 +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()) {
|
2004-06-18 13:31:55 +00:00
|
|
|
|
lyxerr[Debug::DEBUG] << "RESTORING OLD CURSOR!" << endl;
|
2004-03-18 13:57:20 +00:00
|
|
|
|
operator=(safe);
|
2004-04-07 20:20:15 +00:00
|
|
|
|
disp_.dispatched(false);
|
2004-03-25 09:16:36 +00:00
|
|
|
|
}
|
2004-08-13 14:56:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DispatchResult LCursor::result() const
|
|
|
|
|
{
|
2004-02-16 11:58:51 +00:00
|
|
|
|
return disp_;
|
2003-09-17 16:44:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-01 17:12:09 +00:00
|
|
|
|
BufferView & LCursor::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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-04-08 15:03:33 +00:00
|
|
|
|
Buffer & LCursor::buffer() const
|
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(bv_);
|
|
|
|
|
BOOST_ASSERT(bv_->buffer());
|
|
|
|
|
return *bv_->buffer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-04 12:36:59 +00:00
|
|
|
|
void LCursor::pop()
|
|
|
|
|
{
|
2005-02-08 13:18:05 +00:00
|
|
|
|
BOOST_ASSERT(depth() >= 1);
|
2004-03-01 17:12:09 +00:00
|
|
|
|
pop_back();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
void LCursor::push(InsetBase & p)
|
2004-03-01 17:12:09 +00:00
|
|
|
|
{
|
|
|
|
|
push_back(CursorSlice(p));
|
2004-01-20 14:25:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
void LCursor::pushLeft(InsetBase & p)
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
2004-03-01 17:12:09 +00:00
|
|
|
|
BOOST_ASSERT(!empty());
|
2004-01-26 10:13:15 +00:00
|
|
|
|
//lyxerr << "Entering inset " << t << " left" << endl;
|
|
|
|
|
push(p);
|
2004-03-18 12:53:43 +00:00
|
|
|
|
p.idxFirst(*this);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool LCursor::popLeft()
|
|
|
|
|
{
|
2004-03-01 17:12:09 +00:00
|
|
|
|
BOOST_ASSERT(!empty());
|
2004-01-26 10:13:15 +00:00
|
|
|
|
//lyxerr << "Leaving inset to the left" << 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool LCursor::popRight()
|
|
|
|
|
{
|
2004-03-01 17:12:09 +00:00
|
|
|
|
BOOST_ASSERT(!empty());
|
2004-01-26 10:13:15 +00:00
|
|
|
|
//lyxerr << "Leaving inset to the right" << 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();
|
2004-02-11 14:45:44 +00:00
|
|
|
|
++pos();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int LCursor::currentMode()
|
|
|
|
|
{
|
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();
|
2004-03-18 16:05:32 +00:00
|
|
|
|
if (res != InsetBase::UNDECIDED_MODE)
|
2004-01-26 10:13:15 +00:00
|
|
|
|
return res;
|
|
|
|
|
}
|
2004-03-18 16:05:32 +00:00
|
|
|
|
return InsetBase::TEXT_MODE;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-10 09:06:48 +00:00
|
|
|
|
void LCursor::getPos(int & x, int & y) const
|
|
|
|
|
{
|
2005-07-15 15:49:40 +00:00
|
|
|
|
Point p = bv_funcs::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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
void LCursor::paste(string const & data)
|
|
|
|
|
{
|
2005-09-21 09:56:54 +00:00
|
|
|
|
if (!data.empty())
|
|
|
|
|
dispatch(FuncRequest(LFUN_PASTE, data));
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-16 12:36:23 +00:00
|
|
|
|
void LCursor::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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool LCursor::posLeft()
|
|
|
|
|
{
|
|
|
|
|
if (pos() == 0)
|
|
|
|
|
return false;
|
|
|
|
|
--pos();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool LCursor::posRight()
|
|
|
|
|
{
|
|
|
|
|
if (pos() == lastpos())
|
|
|
|
|
return false;
|
|
|
|
|
++pos();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2004-01-20 14:25:24 +00:00
|
|
|
|
|
|
|
|
|
|
2004-04-07 13:15:34 +00:00
|
|
|
|
CursorSlice LCursor::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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-04-07 13:15:34 +00:00
|
|
|
|
CursorSlice LCursor::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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-04-07 13:15:34 +00:00
|
|
|
|
CursorSlice LCursor::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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
DocIterator LCursor::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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
DocIterator LCursor::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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LCursor::setSelection()
|
|
|
|
|
{
|
|
|
|
|
selection() = true;
|
2005-07-14 17:30:24 +00:00
|
|
|
|
// A selection with no contents is not a selection
|
2004-04-29 14:49:02 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2004-04-07 08:07:26 +00:00
|
|
|
|
#warning doesnt look ok
|
2004-04-29 14:49:02 +00:00
|
|
|
|
#endif
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
void LCursor::setSelection(DocIterator const & where, size_t 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
void LCursor::clearSelection()
|
|
|
|
|
{
|
|
|
|
|
selection() = false;
|
|
|
|
|
mark() = false;
|
|
|
|
|
resetAnchor();
|
|
|
|
|
bv().unsetXSel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
int & LCursor::x_target()
|
2004-01-20 14:25:24 +00:00
|
|
|
|
{
|
2004-01-30 11:41:12 +00:00
|
|
|
|
return x_target_;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int LCursor::x_target() const
|
|
|
|
|
{
|
|
|
|
|
return x_target_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
void LCursor::clearTargetX()
|
|
|
|
|
{
|
|
|
|
|
x_target_ = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
|
2004-02-13 07:30:59 +00:00
|
|
|
|
void LCursor::info(std::ostream & 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 << " ";
|
|
|
|
|
}
|
2004-02-03 11:49:05 +00:00
|
|
|
|
if (pos() != 0)
|
|
|
|
|
prevInset()->infoize2(os);
|
2004-01-20 14:25:24 +00:00
|
|
|
|
// overwite old message
|
|
|
|
|
os << " ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
void LCursor::selHandle(bool sel)
|
|
|
|
|
{
|
2004-02-11 14:45:44 +00:00
|
|
|
|
//lyxerr << "LCursor::selHandle" << endl;
|
2004-05-18 07:18:02 +00:00
|
|
|
|
if (sel == selection())
|
2004-01-26 10:13:15 +00:00
|
|
|
|
return;
|
2004-04-20 08:51:15 +00:00
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
resetAnchor();
|
|
|
|
|
selection() = sel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
std::ostream & operator<<(std::ostream & os, LCursor const & cur)
|
|
|
|
|
{
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// The part below is the non-integrated rest of the original math
|
|
|
|
|
// cursor. This should be either generalized for texted or moved
|
2004-03-01 17:12:09 +00:00
|
|
|
|
// back to mathed (in most cases to MathNestInset).
|
2004-01-26 10:13:15 +00:00
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#include "mathed/math_charinset.h"
|
|
|
|
|
#include "mathed/math_factory.h"
|
|
|
|
|
#include "mathed/math_gridinset.h"
|
|
|
|
|
#include "mathed/math_macroarg.h"
|
|
|
|
|
#include "mathed/math_mathmlstream.h"
|
|
|
|
|
#include "mathed/math_scriptinset.h"
|
|
|
|
|
#include "mathed/math_support.h"
|
|
|
|
|
#include "mathed/math_unknowninset.h"
|
|
|
|
|
|
|
|
|
|
//#define FILEDEBUG 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool LCursor::isInside(InsetBase const * p)
|
|
|
|
|
{
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-05-06 18:54:36 +00:00
|
|
|
|
void LCursor::leaveInset(InsetBase const & inset)
|
|
|
|
|
{
|
|
|
|
|
for (size_t i = 0; i != depth(); ++i) {
|
|
|
|
|
if (&operator[](i).inset() == &inset) {
|
|
|
|
|
resize(i);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-25 12:00:53 +00:00
|
|
|
|
bool LCursor::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;
|
2004-03-18 12:53:43 +00:00
|
|
|
|
if (!ptr_cmp(t.nucleus(), &anchor_[depth()].inset()))
|
2004-01-26 10:13:15 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LCursor::setScreenPos(int x, int y)
|
|
|
|
|
{
|
2004-03-18 16:05:32 +00:00
|
|
|
|
x_target() = x;
|
2004-08-13 19:19:53 +00:00
|
|
|
|
bruteFind(*this, x, y, 0, bv().workWidth(), 0, bv().workHeight());
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LCursor::plainErase()
|
|
|
|
|
{
|
|
|
|
|
cell().erase(pos());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LCursor::markInsert()
|
|
|
|
|
{
|
2004-04-05 16:44:10 +00:00
|
|
|
|
insert(char(0));
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LCursor::markErase()
|
|
|
|
|
{
|
|
|
|
|
cell().erase(pos());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LCursor::plainInsert(MathAtom const & t)
|
|
|
|
|
{
|
|
|
|
|
cell().insert(pos(), t);
|
|
|
|
|
++pos();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LCursor::insert(string const & str)
|
|
|
|
|
{
|
2004-11-06 15:23:12 +00:00
|
|
|
|
for_each(str.begin(), str.end(),
|
|
|
|
|
boost::bind(static_cast<void(LCursor::*)(char)>
|
|
|
|
|
(&LCursor::insert), this, _1));
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LCursor::insert(char c)
|
|
|
|
|
{
|
2004-02-11 14:45:44 +00:00
|
|
|
|
//lyxerr << "LCursor::insert char '" << c << "'" << endl;
|
2004-03-18 12:53:43 +00:00
|
|
|
|
BOOST_ASSERT(!empty());
|
|
|
|
|
if (inMathed()) {
|
2004-04-18 07:32:34 +00:00
|
|
|
|
lyx::cap::selClearOrDel(*this);
|
2004-04-05 16:44:10 +00:00
|
|
|
|
insert(new MathCharInset(c));
|
2004-03-18 12:53:43 +00:00
|
|
|
|
} else {
|
|
|
|
|
text()->insertChar(*this, c);
|
|
|
|
|
}
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LCursor::insert(MathAtom const & t)
|
|
|
|
|
{
|
2004-08-13 12:05:27 +00:00
|
|
|
|
//lyxerr << "LCursor::insert MathAtom '" << t << "'" << endl;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
macroModeClose();
|
2004-04-18 07:32:34 +00:00
|
|
|
|
lyx::cap::selClearOrDel(*this);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
plainInsert(t);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-11 14:45:44 +00:00
|
|
|
|
void LCursor::insert(InsetBase * inset)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
void LCursor::niceInsert(string const & t)
|
|
|
|
|
{
|
|
|
|
|
MathArray ar;
|
|
|
|
|
asArray(t, ar);
|
|
|
|
|
if (ar.size() == 1)
|
|
|
|
|
niceInsert(ar[0]);
|
|
|
|
|
else
|
|
|
|
|
insert(ar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LCursor::niceInsert(MathAtom const & t)
|
|
|
|
|
{
|
|
|
|
|
macroModeClose();
|
2005-02-08 13:18:05 +00:00
|
|
|
|
string const safe = lyx::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()) {
|
|
|
|
|
posLeft();
|
2004-02-11 14:45:44 +00:00
|
|
|
|
// be careful here: don't use 'pushLeft(t)' as this we need to
|
|
|
|
|
// push the clone, not the original
|
2004-03-18 12:53:43 +00:00
|
|
|
|
pushLeft(*nextInset());
|
2004-01-26 10:13:15 +00:00
|
|
|
|
paste(safe);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LCursor::insert(MathArray const & ar)
|
|
|
|
|
{
|
|
|
|
|
macroModeClose();
|
|
|
|
|
if (selection())
|
2004-04-18 07:32:34 +00:00
|
|
|
|
lyx::cap::eraseSelection(*this);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
cell().insert(pos(), ar);
|
|
|
|
|
pos() += ar.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool LCursor::backspace()
|
|
|
|
|
{
|
|
|
|
|
autocorrect() = false;
|
|
|
|
|
|
|
|
|
|
if (selection()) {
|
2004-04-18 07:32:34 +00:00
|
|
|
|
lyx::cap::selDel(*this);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pos() == 0) {
|
2004-03-18 12:53:43 +00:00
|
|
|
|
if (inset().nargs() == 1 && depth() == 1 && lastpos() == 0)
|
2004-01-26 10:13:15 +00:00
|
|
|
|
return false;
|
|
|
|
|
pullArg();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (inMacroMode()) {
|
|
|
|
|
MathUnknownInset * p = activeMacro();
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool LCursor::erase()
|
|
|
|
|
{
|
|
|
|
|
autocorrect() = false;
|
|
|
|
|
if (inMacroMode())
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (selection()) {
|
2004-04-18 07:32:34 +00:00
|
|
|
|
lyx::cap::selDel(*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;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
if (one_cell && depth() == 1 && lastpos() == 0)
|
|
|
|
|
return false;
|
|
|
|
|
// remove markup
|
|
|
|
|
if (one_cell)
|
|
|
|
|
pullArg();
|
|
|
|
|
else
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool LCursor::up()
|
|
|
|
|
{
|
|
|
|
|
macroModeClose();
|
2004-03-31 19:11:56 +00:00
|
|
|
|
DocIterator save = *this;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
if (goUpDown(true))
|
|
|
|
|
return true;
|
2004-08-14 19:55:00 +00:00
|
|
|
|
setCursor(save);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
autocorrect() = false;
|
|
|
|
|
return selection();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool LCursor::down()
|
|
|
|
|
{
|
|
|
|
|
macroModeClose();
|
2004-03-31 19:11:56 +00:00
|
|
|
|
DocIterator save = *this;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
if (goUpDown(false))
|
|
|
|
|
return true;
|
2004-08-14 19:55:00 +00:00
|
|
|
|
setCursor(save);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
autocorrect() = false;
|
|
|
|
|
return selection();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LCursor::macroModeClose()
|
|
|
|
|
{
|
|
|
|
|
if (!inMacroMode())
|
|
|
|
|
return;
|
|
|
|
|
MathUnknownInset * p = activeMacro();
|
|
|
|
|
p->finalize();
|
2005-02-08 13:18:05 +00:00
|
|
|
|
string 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 == "\\")
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// prevent entering of recursive macros
|
2004-08-13 09:31:48 +00:00
|
|
|
|
// FIXME: this is only a weak attempt... only prevents immediate
|
|
|
|
|
// recursion
|
2005-12-20 16:24:17 +00:00
|
|
|
|
string const name = s.substr(1);
|
2004-02-25 14:39:14 +00:00
|
|
|
|
InsetBase const * macro = innerInsetOfType(InsetBase::MATHMACRO_CODE);
|
|
|
|
|
if (macro && macro->getInsetName() == name)
|
2004-01-26 10:13:15 +00:00
|
|
|
|
lyxerr << "can't enter recursive macro" << endl;
|
|
|
|
|
|
2005-12-20 16:24:17 +00:00
|
|
|
|
// Going back and forth between LCursor and mathed is a bit
|
|
|
|
|
// ridiculous, but the alternative was to duplicate the code
|
|
|
|
|
// in MathNestInset::doDispatch/LFUN_INSERT_MATH (which puts
|
|
|
|
|
// the cursor in the newly created inset). (JMarc 2005/12/20)
|
|
|
|
|
dispatch(FuncRequest(LFUN_INSERT_MATH, s));
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string LCursor::macroName()
|
|
|
|
|
{
|
|
|
|
|
return inMacroMode() ? activeMacro()->name() : string();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LCursor::handleNest(MathAtom const & a, int c)
|
|
|
|
|
{
|
2004-02-11 14:45:44 +00:00
|
|
|
|
//lyxerr << "LCursor::handleNest: " << c << endl;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
MathAtom t = a;
|
2004-04-18 07:32:34 +00:00
|
|
|
|
asArray(lyx::cap::grabAndEraseSelection(*this), t.nucleus()->cell(c));
|
2004-01-30 11:41:12 +00:00
|
|
|
|
insert(t);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
posLeft();
|
2004-03-18 12:53:43 +00:00
|
|
|
|
pushLeft(*nextInset());
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int LCursor::targetX() const
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
void LCursor::setTargetX()
|
|
|
|
|
{
|
2005-02-08 13:18:05 +00:00
|
|
|
|
// For now this is good enough. A better solution would be to
|
|
|
|
|
// avoid this rebreak by setting cursorX only after drawing
|
2004-11-30 01:59:49 +00:00
|
|
|
|
bottom().text()->redoParagraph(bottom().pit());
|
2005-02-08 13:18:05 +00:00
|
|
|
|
int x;
|
|
|
|
|
int y;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
getPos(x, y);
|
|
|
|
|
x_target_ = x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
bool LCursor::inMacroMode() const
|
|
|
|
|
{
|
2004-08-13 12:05:27 +00:00
|
|
|
|
if (pos() == 0)
|
2004-01-26 10:13:15 +00:00
|
|
|
|
return false;
|
|
|
|
|
MathUnknownInset const * p = prevAtom()->asUnknownInset();
|
|
|
|
|
return p && !p->final();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MathUnknownInset * LCursor::activeMacro()
|
|
|
|
|
{
|
|
|
|
|
return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LCursor::pullArg()
|
|
|
|
|
{
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2004-02-11 14:45:44 +00:00
|
|
|
|
#warning Look here
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#endif
|
2004-01-26 10:13:15 +00:00
|
|
|
|
MathArray ar = cell();
|
2004-02-11 14:45:44 +00:00
|
|
|
|
if (popLeft() && 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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LCursor::touch()
|
|
|
|
|
{
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2004-01-26 10:13:15 +00:00
|
|
|
|
#warning look here
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#endif
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LCursor::normalize()
|
|
|
|
|
{
|
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: '";
|
|
|
|
|
WriteStream wi(lyxerr, false, true);
|
2004-03-18 12:53:43 +00:00
|
|
|
|
inset().asMathInset()->write(wi);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
lyxerr << endl;
|
2005-07-18 17:12:28 +00:00
|
|
|
|
pos() = lastpos();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool LCursor::goUpDown(bool up)
|
|
|
|
|
{
|
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-03-18 16:05:32 +00:00
|
|
|
|
|
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);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
|
|
|
|
// check if we had something else in mind, if not, this is the future goal
|
|
|
|
|
if (x_target() == -1)
|
2004-01-30 11:41:12 +00:00
|
|
|
|
x_target() = xo;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
else
|
|
|
|
|
xo = x_target();
|
|
|
|
|
|
|
|
|
|
// try neigbouring script insets
|
|
|
|
|
if (!selection()) {
|
|
|
|
|
// try left
|
|
|
|
|
if (pos() != 0) {
|
|
|
|
|
MathScriptInset const * p = prevAtom()->asScriptInset();
|
|
|
|
|
if (p && p->has(up)) {
|
|
|
|
|
--pos();
|
2005-07-17 12:28:02 +00:00
|
|
|
|
push(*const_cast<MathScriptInset*>(p));
|
|
|
|
|
idx() = p->idxOfScript(up);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
pos() = lastpos();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// try right
|
|
|
|
|
if (pos() != lastpos()) {
|
|
|
|
|
MathScriptInset const * p = nextAtom()->asScriptInset();
|
|
|
|
|
if (p && p->has(up)) {
|
2005-07-17 12:28:02 +00:00
|
|
|
|
push(*const_cast<MathScriptInset*>(p));
|
|
|
|
|
idx() = p->idxOfScript(up);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
pos() = 0;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-18 17:12:28 +00:00
|
|
|
|
// FIXME: Switch this on for more robust movement
|
|
|
|
|
#if 0
|
|
|
|
|
|
|
|
|
|
return bruteFind3(*this, xo, yo, up);
|
|
|
|
|
|
|
|
|
|
#else
|
2004-01-26 10:13:15 +00:00
|
|
|
|
//xarray().boundingBox(xlow, xhigh, ylow, yhigh);
|
|
|
|
|
//if (up)
|
|
|
|
|
// yhigh = yo - 4;
|
|
|
|
|
//else
|
|
|
|
|
// ylow = yo + 4;
|
2004-08-13 19:19:53 +00:00
|
|
|
|
//if (bruteFind(*this, xo, yo, xlow, xhigh, ylow, yhigh)) {
|
2004-01-26 10:13:15 +00:00
|
|
|
|
// lyxerr << "updown: handled by brute find in the same cell" << endl;
|
|
|
|
|
// return true;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
// try to find an inset that knows better then we
|
2005-02-08 13:18:05 +00:00
|
|
|
|
while (true) {
|
2005-07-18 17:12:28 +00:00
|
|
|
|
lyxerr << "updown: We are in " << &inset() << " idx: " << idx() << endl;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
// ask inset first
|
2004-03-18 12:53:43 +00:00
|
|
|
|
if (inset().idxUpDown(*this, up)) {
|
2005-07-18 17:12:28 +00:00
|
|
|
|
lyxerr << "idxUpDown triggered" << endl;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
// try to find best position within this inset
|
|
|
|
|
if (!selection())
|
2004-08-14 19:55:00 +00:00
|
|
|
|
setCursor(bruteFind2(*this, xo, yo));
|
2004-01-26 10:13:15 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// no such inset found, just take something "above"
|
|
|
|
|
if (!popLeft()) {
|
2005-07-18 17:12:28 +00:00
|
|
|
|
lyxerr << "updown: popleft failed (strange case)" << endl;
|
2004-03-18 16:05:32 +00:00
|
|
|
|
int ylow = up ? 0 : yo + 1;
|
|
|
|
|
int yhigh = up ? yo - 1 : bv().workHeight();
|
2004-08-13 19:19:53 +00:00
|
|
|
|
return bruteFind(*this, xo, yo, 0, bv().workWidth(), ylow, yhigh);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// any improvement so far?
|
2005-07-18 17:12:28 +00:00
|
|
|
|
lyxerr << "updown: popLeft succeeded" << endl;
|
2005-02-08 13:18:05 +00:00
|
|
|
|
int xnew;
|
|
|
|
|
int ynew;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
getPos(xnew, ynew);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
if (up ? ynew < yo : ynew > yo)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-13 19:19:53 +00:00
|
|
|
|
// we should not come here.
|
|
|
|
|
BOOST_ASSERT(false);
|
2005-07-18 17:12:28 +00:00
|
|
|
|
#endif
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LCursor::handleFont(string const & font)
|
|
|
|
|
{
|
2004-08-14 15:55:22 +00:00
|
|
|
|
lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION << ": " << font << endl;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
string safe;
|
|
|
|
|
if (selection()) {
|
|
|
|
|
macroModeClose();
|
2004-04-18 07:32:34 +00:00
|
|
|
|
safe = lyx::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
|
|
|
|
|
popLeft();
|
|
|
|
|
} else if (pos() == lastpos()) {
|
|
|
|
|
// cursor in last position
|
|
|
|
|
popRight();
|
|
|
|
|
} else {
|
|
|
|
|
// cursor in between. split cell
|
|
|
|
|
MathArray::iterator bt = cell().begin();
|
|
|
|
|
MathAtom at = createMathInset(font);
|
|
|
|
|
at.nucleus()->cell(0) = MathArray(bt, bt + pos());
|
|
|
|
|
cell().erase(bt, bt + pos());
|
|
|
|
|
popLeft();
|
|
|
|
|
plainInsert(at);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// nothing left in the cell
|
|
|
|
|
pullArg();
|
|
|
|
|
plainErase();
|
|
|
|
|
}
|
|
|
|
|
insert(safe);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-03 11:49:05 +00:00
|
|
|
|
void LCursor::message(string const & msg) const
|
|
|
|
|
{
|
|
|
|
|
bv().owner()->getLyXFunc().setMessage(msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LCursor::errorMessage(string const & msg) const
|
|
|
|
|
{
|
|
|
|
|
bv().owner()->getLyXFunc().setErrorMessage(msg);
|
|
|
|
|
}
|
2004-02-11 14:45:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string LCursor::selectionAsString(bool label) const
|
|
|
|
|
{
|
|
|
|
|
if (!selection())
|
|
|
|
|
return string();
|
|
|
|
|
|
|
|
|
|
if (inTexted()) {
|
|
|
|
|
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)
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return pars[startpit].asString(buffer, startpos, endpos, label);
|
2004-02-11 14:45:44 +00:00
|
|
|
|
|
|
|
|
|
// First paragraph in selection
|
2004-03-25 09:16:36 +00:00
|
|
|
|
string result = pars[startpit].
|
|
|
|
|
asString(buffer, startpos, pars[startpit].size(), label) + "\n\n";
|
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];
|
2004-03-25 09:16:36 +00:00
|
|
|
|
result += par.asString(buffer, 0, par.size(), label) + "\n\n";
|
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2005-10-12 18:44:53 +00:00
|
|
|
|
if (inMathed())
|
|
|
|
|
return lyx::cap::grabSelection(*this);
|
|
|
|
|
|
2004-02-11 14:45:44 +00:00
|
|
|
|
return string();
|
|
|
|
|
}
|
2004-02-13 07:30:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string LCursor::currentState()
|
|
|
|
|
{
|
|
|
|
|
if (inMathed()) {
|
|
|
|
|
std::ostringstream os;
|
|
|
|
|
info(os);
|
|
|
|
|
return os.str();
|
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
|
return string();
|
2004-02-13 07:30:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-13 13:51:12 +00:00
|
|
|
|
string LCursor::getPossibleLabel()
|
|
|
|
|
{
|
|
|
|
|
return inMathed() ? "eq:" : text()->getPossibleLabel(*this);
|
|
|
|
|
}
|
2004-02-16 11:58:51 +00:00
|
|
|
|
|
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
Encoding const * LCursor::getEncoding() const
|
2004-02-16 11:58:51 +00:00
|
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
|
if (empty())
|
|
|
|
|
return 0;
|
|
|
|
|
if (!bv().buffer())
|
|
|
|
|
return 0;
|
|
|
|
|
int s = 0;
|
|
|
|
|
// go up until first non-0 text is hit
|
|
|
|
|
// (innermost text is 0 in mathed)
|
2005-02-08 13:18:05 +00:00
|
|
|
|
for (s = depth() - 1; s >= 0; --s)
|
2004-03-18 12:53:43 +00:00
|
|
|
|
if (operator[](s).text())
|
|
|
|
|
break;
|
|
|
|
|
CursorSlice const & sl = operator[](s);
|
2005-01-31 16:29:48 +00:00
|
|
|
|
LyXText const & text = *sl.text();
|
2004-11-24 21:53:46 +00:00
|
|
|
|
LyXFont font = text.getPar(sl.pit()).getFont(
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
void LCursor::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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-27 12:46:30 +00:00
|
|
|
|
void LCursor::dispatched()
|
|
|
|
|
{
|
|
|
|
|
disp_.dispatched(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-08-13 14:56:06 +00:00
|
|
|
|
void LCursor::needsUpdate()
|
|
|
|
|
{
|
|
|
|
|
disp_.update(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-01 17:12:09 +00:00
|
|
|
|
void LCursor::noUpdate()
|
2004-02-16 11:58:51 +00:00
|
|
|
|
{
|
|
|
|
|
disp_.update(false);
|
|
|
|
|
}
|
2005-01-10 09:28:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LyXFont LCursor::getFont() const
|
|
|
|
|
{
|
|
|
|
|
// HACK. far from being perfect...
|
|
|
|
|
int s = 0;
|
|
|
|
|
// go up until first non-0 text is hit
|
|
|
|
|
// (innermost text is 0 in mathed)
|
2005-02-08 13:18:05 +00:00
|
|
|
|
for (s = depth() - 1; s >= 0; --s)
|
2005-01-10 09:28:06 +00:00
|
|
|
|
if (operator[](s).text())
|
|
|
|
|
break;
|
|
|
|
|
CursorSlice const & sl = operator[](s);
|
2005-01-31 16:29:48 +00:00
|
|
|
|
LyXText const & text = *sl.text();
|
2005-01-10 09:28:06 +00:00
|
|
|
|
LyXFont font = text.getPar(sl.pit()).getFont(
|
|
|
|
|
bv().buffer()->params(),
|
|
|
|
|
sl.pos(),
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LCursor::fixIfBroken()
|
|
|
|
|
{
|
|
|
|
|
// find out last good level
|
|
|
|
|
LCursor copy = *this;
|
|
|
|
|
size_t newdepth = depth();
|
|
|
|
|
while (!copy.empty()) {
|
|
|
|
|
if (copy.idx() > copy.lastidx()) {
|
|
|
|
|
lyxerr << "wrong idx " << copy.idx()
|
|
|
|
|
<< ", max is " << copy.lastidx()
|
|
|
|
|
<< " at level " << copy.depth()
|
|
|
|
|
<< ". Trying to correct this." << endl;
|
|
|
|
|
newdepth = copy.depth() - 1;
|
|
|
|
|
}
|
|
|
|
|
else if (copy.pit() > copy.lastpit()) {
|
|
|
|
|
lyxerr << "wrong pit " << copy.pit()
|
|
|
|
|
<< ", max is " << copy.lastpit()
|
|
|
|
|
<< " at level " << copy.depth()
|
|
|
|
|
<< ". Trying to correct this." << endl;
|
|
|
|
|
newdepth = copy.depth() - 1;
|
|
|
|
|
}
|
|
|
|
|
else if (copy.pos() > copy.lastpos()) {
|
|
|
|
|
lyxerr << "wrong pos " << copy.pos()
|
|
|
|
|
<< ", max is " << copy.lastpos()
|
|
|
|
|
<< " at level " << copy.depth()
|
|
|
|
|
<< ". Trying to correct this." << endl;
|
|
|
|
|
newdepth = copy.depth() - 1;
|
|
|
|
|
}
|
2005-04-26 11:12:20 +00:00
|
|
|
|
copy.pop();
|
2005-02-15 17:34:54 +00:00
|
|
|
|
}
|
|
|
|
|
// shrink cursor to a size where everything is valid, possibly
|
|
|
|
|
// leaving insets
|
|
|
|
|
while (depth() > newdepth) {
|
|
|
|
|
pop();
|
|
|
|
|
lyxerr << "correcting cursor to level " << depth() << endl;
|
|
|
|
|
}
|
|
|
|
|
}
|