1999-09-27 18:44:28 +00:00
|
|
|
/*
|
2001-04-24 16:13:38 +00:00
|
|
|
* File: math_cursor.C
|
|
|
|
* Purpose: Interaction for mathed
|
|
|
|
* Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
|
|
|
|
* Created: January 1996
|
|
|
|
* Description: Math interaction for a WYSIWYG math editor.
|
|
|
|
*
|
|
|
|
* Dependencies: Xlib, XForms
|
|
|
|
*
|
|
|
|
* Copyright: 1996, Alejandro Aguilar Sierra
|
|
|
|
*
|
2001-06-25 00:06:33 +00:00
|
|
|
* Version: 0.8beta, Math & Lyx project.
|
2001-04-24 16:13:38 +00:00
|
|
|
*
|
|
|
|
* You are free to use and modify this code under the terms of
|
|
|
|
* the GNU General Public Licence version 2 or later.
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-12-18 03:16:46 +00:00
|
|
|
#include <config.h>
|
2002-05-14 09:15:40 +00:00
|
|
|
#include <lyxrc.h>
|
2001-12-18 03:16:46 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-12-18 12:21:33 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
#include "support/LAssert.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "LColor.h"
|
2002-05-23 09:21:32 +00:00
|
|
|
#include "frontends/Painter.h"
|
2001-12-18 03:16:46 +00:00
|
|
|
#include "math_cursor.h"
|
2001-07-17 07:38:41 +00:00
|
|
|
#include "formulabase.h"
|
2002-05-24 08:29:16 +00:00
|
|
|
#include "math_autocorrect.h"
|
2001-07-17 07:38:41 +00:00
|
|
|
#include "math_arrayinset.h"
|
2001-10-29 15:45:24 +00:00
|
|
|
#include "math_braceinset.h"
|
2001-12-18 12:21:33 +00:00
|
|
|
#include "math_boxinset.h"
|
2001-12-05 17:50:18 +00:00
|
|
|
#include "math_casesinset.h"
|
2001-08-09 09:19:18 +00:00
|
|
|
#include "math_charinset.h"
|
2001-07-10 13:17:43 +00:00
|
|
|
#include "math_deliminset.h"
|
2002-06-18 15:44:30 +00:00
|
|
|
#include "math_extern.h"
|
2001-12-05 17:50:18 +00:00
|
|
|
#include "math_factory.h"
|
2001-11-08 12:28:33 +00:00
|
|
|
#include "math_hullinset.h"
|
2001-12-05 17:50:18 +00:00
|
|
|
#include "math_iterator.h"
|
2002-01-11 10:26:13 +00:00
|
|
|
#include "math_macroarg.h"
|
2002-03-13 11:20:35 +00:00
|
|
|
#include "math_macrotemplate.h"
|
2001-12-05 17:50:18 +00:00
|
|
|
#include "math_mathmlstream.h"
|
|
|
|
#include "math_parser.h"
|
|
|
|
#include "math_replace.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "math_scriptinset.h"
|
2001-08-13 14:02:37 +00:00
|
|
|
#include "math_spaceinset.h"
|
2001-12-05 17:50:18 +00:00
|
|
|
#include "math_support.h"
|
2002-05-30 07:09:54 +00:00
|
|
|
#include "math_unknowninset.h"
|
2001-04-24 16:13:38 +00:00
|
|
|
|
2001-12-18 03:16:46 +00:00
|
|
|
#include <algorithm>
|
2002-03-20 10:22:23 +00:00
|
|
|
#include <cctype>
|
2001-12-18 03:16:46 +00:00
|
|
|
|
2001-09-26 15:20:45 +00:00
|
|
|
#define FILEDEBUG 0
|
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
using std::endl;
|
2001-06-25 00:06:33 +00:00
|
|
|
using std::min;
|
|
|
|
using std::max;
|
2001-09-25 06:47:47 +00:00
|
|
|
using std::swap;
|
2002-02-16 15:59:55 +00:00
|
|
|
using std::vector;
|
|
|
|
using std::ostringstream;
|
2002-05-28 11:13:01 +00:00
|
|
|
using std::isalpha;
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
// matheds own cut buffer
|
|
|
|
MathGridInset theCutBuffer = MathGridInset(1, 1);
|
2001-04-24 16:13:38 +00:00
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
|
2002-06-14 10:48:27 +00:00
|
|
|
MathCursor::MathCursor(InsetFormulaBase * formula, bool front)
|
2002-05-30 07:09:54 +00:00
|
|
|
: formula_(formula), autocorrect_(false), selection_(false)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2002-06-14 10:48:27 +00:00
|
|
|
front ? first() : last();
|
2002-06-18 15:44:30 +00:00
|
|
|
Anchor_ = Cursor_;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
void MathCursor::push(MathAtom & t)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-12-11 15:35:18 +00:00
|
|
|
Cursor_.push_back(MathCursorPos(t.nucleus()));
|
2001-04-24 16:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
void MathCursor::pushLeft(MathAtom & t)
|
|
|
|
{
|
|
|
|
//cerr << "Entering atom "; t->write(cerr, false); cerr << " left\n";
|
|
|
|
push(t);
|
|
|
|
t->idxFirst(idx(), pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathCursor::pushRight(MathAtom & t)
|
2001-08-08 07:12:09 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
//cerr << "Entering atom "; t->write(cerr, false); cerr << " right\n";
|
2001-08-08 07:46:16 +00:00
|
|
|
posLeft();
|
2001-10-12 12:02:49 +00:00
|
|
|
push(t);
|
|
|
|
t->idxLast(idx(), pos());
|
2001-08-08 07:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathCursor::popLeft()
|
2001-04-24 16:13:38 +00:00
|
|
|
{
|
2002-03-18 11:45:53 +00:00
|
|
|
//cerr << "Leaving atom to the left\n";
|
2002-06-18 15:44:30 +00:00
|
|
|
if (depth() <= 1)
|
2001-06-27 14:10:35 +00:00
|
|
|
return false;
|
2001-07-16 15:53:25 +00:00
|
|
|
Cursor_.pop_back();
|
2001-06-27 14:10:35 +00:00
|
|
|
return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2001-09-11 10:58:17 +00:00
|
|
|
|
2001-08-08 07:12:09 +00:00
|
|
|
bool MathCursor::popRight()
|
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
//cerr << "Leaving atom "; par()->write(cerr, false); cerr << " right\n";
|
2002-06-18 15:44:30 +00:00
|
|
|
if (depth() <= 1)
|
2001-08-08 07:12:09 +00:00
|
|
|
return false;
|
|
|
|
Cursor_.pop_back();
|
2001-08-08 07:46:16 +00:00
|
|
|
posRight();
|
2001-08-08 07:12:09 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-09-26 15:20:45 +00:00
|
|
|
#if FILEDEBUG
|
2001-12-05 17:50:18 +00:00
|
|
|
void MathCursor::dump(char const * what) const
|
|
|
|
{
|
|
|
|
lyxerr << "MC: " << what << "\n";
|
2002-06-18 15:44:30 +00:00
|
|
|
lyxerr << " Cursor: " << depth() << "\n";
|
|
|
|
for (unsigned i = 0; i < depth(); ++i)
|
2001-12-05 17:50:18 +00:00
|
|
|
lyxerr << " i: " << i << " " << Cursor_[i] << "\n";
|
|
|
|
lyxerr << " Anchor: " << Anchor_.size() << "\n";
|
|
|
|
for (unsigned i = 0; i < Anchor_.size(); ++i)
|
|
|
|
lyxerr << " i: " << i << " " << Anchor_[i] << "\n";
|
|
|
|
lyxerr << " sel: " << selection_ << "\n";
|
|
|
|
}
|
2001-09-26 15:20:45 +00:00
|
|
|
#else
|
2001-12-05 17:50:18 +00:00
|
|
|
void MathCursor::dump(char const *) const {}
|
2001-09-26 15:20:45 +00:00
|
|
|
#endif
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-08-06 17:20:26 +00:00
|
|
|
bool MathCursor::isInside(MathInset const * p) const
|
2001-02-14 17:58:40 +00:00
|
|
|
{
|
2002-06-18 15:44:30 +00:00
|
|
|
for (unsigned i = 0; i < depth(); ++i)
|
2002-01-11 10:26:13 +00:00
|
|
|
if (Cursor_[i].par_ == p)
|
2001-06-25 00:06:33 +00:00
|
|
|
return true;
|
2001-07-16 15:53:25 +00:00
|
|
|
return false;
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
bool MathCursor::openable(MathAtom const & t, bool sel) const
|
2001-07-16 15:53:25 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
if (!t->isActive())
|
2001-07-16 15:53:25 +00:00
|
|
|
return false;
|
2001-08-07 12:02:21 +00:00
|
|
|
|
2002-06-14 10:48:27 +00:00
|
|
|
if (t->lock())
|
|
|
|
return false;
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
if (t->asScriptInset())
|
2001-08-20 13:45:02 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (sel) {
|
|
|
|
// we can't move into anything new during selection
|
2002-06-18 15:44:30 +00:00
|
|
|
if (depth() == Anchor_.size())
|
2001-08-20 13:45:02 +00:00
|
|
|
return false;
|
2002-06-18 15:44:30 +00:00
|
|
|
if (t.nucleus() != Anchor_[depth()].par_)
|
2001-08-20 13:45:02 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-08 07:46:16 +00:00
|
|
|
bool MathCursor::posLeft()
|
2001-07-13 14:54:56 +00:00
|
|
|
{
|
2001-08-08 07:46:16 +00:00
|
|
|
if (pos() == 0)
|
|
|
|
return false;
|
|
|
|
--pos();
|
|
|
|
return true;
|
2001-07-13 14:54:56 +00:00
|
|
|
}
|
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
|
2001-08-08 07:46:16 +00:00
|
|
|
bool MathCursor::posRight()
|
2001-08-07 12:02:21 +00:00
|
|
|
{
|
2001-08-08 07:46:16 +00:00
|
|
|
if (pos() == size())
|
|
|
|
return false;
|
2001-10-12 12:02:49 +00:00
|
|
|
++pos();
|
2001-08-08 07:46:16 +00:00
|
|
|
return true;
|
2001-08-07 12:02:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
bool MathCursor::left(bool sel)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
dump("Left 1");
|
2002-05-24 08:29:16 +00:00
|
|
|
autocorrect_ = false;
|
2002-06-14 10:48:27 +00:00
|
|
|
targetx_ = -1; // "no target"
|
2001-08-14 11:19:19 +00:00
|
|
|
if (inMacroMode()) {
|
|
|
|
macroModeClose();
|
2001-02-14 17:58:40 +00:00
|
|
|
return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-07-26 09:01:36 +00:00
|
|
|
selHandle(sel);
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
if (hasPrevAtom() && openable(prevAtom(), sel)) {
|
|
|
|
pushRight(prevAtom());
|
2001-07-16 15:53:25 +00:00
|
|
|
return true;
|
2002-01-11 10:26:13 +00:00
|
|
|
}
|
2001-10-15 14:19:16 +00:00
|
|
|
|
2001-10-12 16:12:32 +00:00
|
|
|
return posLeft() || idxLeft() || popLeft() || selection_;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
bool MathCursor::right(bool sel)
|
2001-02-14 17:58:40 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
dump("Right 1");
|
2002-05-24 08:29:16 +00:00
|
|
|
autocorrect_ = false;
|
2002-06-14 10:48:27 +00:00
|
|
|
targetx_ = -1; // "no target"
|
2001-08-14 11:19:19 +00:00
|
|
|
if (inMacroMode()) {
|
2001-07-26 09:01:36 +00:00
|
|
|
macroModeClose();
|
2001-02-14 17:58:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
2001-07-26 09:01:36 +00:00
|
|
|
selHandle(sel);
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
if (hasNextAtom() && openable(nextAtom(), sel)) {
|
|
|
|
pushLeft(nextAtom());
|
2001-07-16 15:53:25 +00:00
|
|
|
return true;
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
2001-08-08 07:46:16 +00:00
|
|
|
|
2001-10-12 16:12:32 +00:00
|
|
|
return posRight() || idxRight() || popRight() || selection_;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathCursor::first()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-07-16 15:53:25 +00:00
|
|
|
Cursor_.clear();
|
2002-06-14 10:48:27 +00:00
|
|
|
push(formula_->par());
|
|
|
|
par()->idxFirst(idx(), pos());
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
2001-02-14 17:58:40 +00:00
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathCursor::last()
|
|
|
|
{
|
2002-06-14 10:48:27 +00:00
|
|
|
Cursor_.clear();
|
|
|
|
push(formula_->par());
|
|
|
|
par()->idxLast(idx(), pos());
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-11 18:51:47 +00:00
|
|
|
bool positionable(MathCursor::cursor_type const & cursor,
|
2002-05-29 16:21:03 +00:00
|
|
|
MathCursor::cursor_type const & anchor)
|
2001-12-11 18:51:47 +00:00
|
|
|
{
|
|
|
|
// avoid deeper nested insets when selecting
|
|
|
|
if (cursor.size() > anchor.size())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// anchor might be deeper, should have same path then
|
|
|
|
for (MathCursor::cursor_type::size_type i = 0; i < cursor.size(); ++i)
|
|
|
|
if (cursor[i].par_ != anchor[i].par_)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// position should be ok.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2001-12-05 17:50:18 +00:00
|
|
|
|
|
|
|
void MathCursor::setPos(int x, int y)
|
|
|
|
{
|
2001-12-17 10:25:17 +00:00
|
|
|
dump("setPos 1");
|
2001-12-12 14:05:38 +00:00
|
|
|
bool res = bruteFind(x, y,
|
|
|
|
formula()->xlow(), formula()->xhigh(),
|
|
|
|
formula()->ylow(), formula()->yhigh());
|
2001-12-17 10:25:17 +00:00
|
|
|
if (!res) {
|
|
|
|
// this ccan happen on creation of "math-display"
|
|
|
|
dump("setPos 1.5");
|
|
|
|
first();
|
|
|
|
}
|
2001-12-05 17:50:18 +00:00
|
|
|
dump("setPos 2");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-08-30 10:17:28 +00:00
|
|
|
void MathCursor::home(bool sel)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-07-26 09:01:36 +00:00
|
|
|
dump("home 1");
|
2002-05-24 08:29:16 +00:00
|
|
|
autocorrect_ = false;
|
2001-08-30 10:17:28 +00:00
|
|
|
selHandle(sel);
|
2001-07-26 09:01:36 +00:00
|
|
|
macroModeClose();
|
2002-01-11 10:26:13 +00:00
|
|
|
if (!par()->idxHome(idx(), pos()))
|
2001-08-08 07:12:09 +00:00
|
|
|
popLeft();
|
2001-07-26 09:01:36 +00:00
|
|
|
dump("home 2");
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-08-30 10:17:28 +00:00
|
|
|
void MathCursor::end(bool sel)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-07-26 09:01:36 +00:00
|
|
|
dump("end 1");
|
2002-05-24 08:29:16 +00:00
|
|
|
autocorrect_ = false;
|
2001-08-30 10:17:28 +00:00
|
|
|
selHandle(sel);
|
2001-07-26 09:01:36 +00:00
|
|
|
macroModeClose();
|
2001-08-08 07:12:09 +00:00
|
|
|
if (!par()->idxEnd(idx(), pos()))
|
|
|
|
popRight();
|
2001-07-26 09:01:36 +00:00
|
|
|
dump("end 2");
|
2001-02-03 21:02:22 +00:00
|
|
|
}
|
|
|
|
|
2001-02-13 19:10:18 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
void MathCursor::plainErase()
|
2001-07-26 06:46:50 +00:00
|
|
|
{
|
2001-08-07 15:04:57 +00:00
|
|
|
array().erase(pos());
|
2001-07-26 06:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-15 14:07:09 +00:00
|
|
|
void MathCursor::markInsert()
|
|
|
|
{
|
|
|
|
//lyxerr << "inserting mark\n";
|
2002-05-30 07:09:54 +00:00
|
|
|
array().insert(pos(), MathAtom(new MathCharInset(0)));
|
2002-02-15 14:07:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathCursor::markErase()
|
|
|
|
{
|
|
|
|
//lyxerr << "deleting mark\n";
|
|
|
|
array().erase(pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
void MathCursor::plainInsert(MathAtom const & t)
|
2001-10-10 13:20:51 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
array().insert(pos(), t);
|
2001-10-10 13:20:51 +00:00
|
|
|
++pos();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-01 14:56:49 +00:00
|
|
|
void MathCursor::insert(char c)
|
|
|
|
{
|
2002-05-30 07:09:54 +00:00
|
|
|
//lyxerr << "inserting '" << c << "'\n";
|
|
|
|
selClearOrDel();
|
|
|
|
plainInsert(MathAtom(new MathCharInset(c)));
|
2002-02-01 14:56:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
void MathCursor::insert(MathAtom const & t)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-07-26 09:01:36 +00:00
|
|
|
macroModeClose();
|
2002-06-18 15:44:30 +00:00
|
|
|
selClearOrDel();
|
2001-10-12 12:02:49 +00:00
|
|
|
plainInsert(t);
|
2001-07-16 15:53:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-11 10:26:13 +00:00
|
|
|
void MathCursor::niceInsert(MathAtom const & t)
|
2001-08-13 14:02:37 +00:00
|
|
|
{
|
2002-06-18 15:44:30 +00:00
|
|
|
macroModeClose();
|
|
|
|
MathGridInset safe = grabAndEraseSelection();
|
|
|
|
plainInsert(t);
|
2002-06-14 10:48:27 +00:00
|
|
|
// enter the new inset and move the contents of the selection if possible
|
2002-06-18 15:44:30 +00:00
|
|
|
if (t->isActive()) {
|
|
|
|
posLeft();
|
|
|
|
pushLeft(nextAtom());
|
|
|
|
paste(safe);
|
2001-08-13 14:02:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
void MathCursor::insert(MathArray const & ar)
|
|
|
|
{
|
2001-07-26 09:01:36 +00:00
|
|
|
macroModeClose();
|
|
|
|
if (selection_)
|
2002-06-18 15:44:30 +00:00
|
|
|
eraseSelection();
|
2001-07-16 15:53:25 +00:00
|
|
|
|
2001-08-07 15:04:57 +00:00
|
|
|
array().insert(pos(), ar);
|
|
|
|
pos() += ar.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
void MathCursor::paste(MathArray const & ar)
|
2001-10-10 13:20:51 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
Anchor_ = Cursor_;
|
|
|
|
selection_ = true;
|
|
|
|
array().insert(pos(), ar);
|
|
|
|
pos() += ar.size();
|
2001-10-10 13:20:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
void MathCursor::paste(MathGridInset const & data)
|
|
|
|
{
|
|
|
|
if (data.nargs() == 1) {
|
|
|
|
// single cell/part of cell
|
|
|
|
paste(data.cell(0));
|
|
|
|
} else {
|
|
|
|
// mulitple cells
|
|
|
|
idx_type idx; // index of upper left cell
|
|
|
|
MathGridInset * p = enclosingGrid(idx);
|
|
|
|
col_type const numcols = min(data.ncols(), p->ncols() - p->col(idx));
|
|
|
|
row_type const numrows = min(data.nrows(), p->nrows() - p->row(idx));
|
|
|
|
for (row_type row = 0; row < numrows; ++row) {
|
|
|
|
for (col_type col = 0; col < numcols; ++col) {
|
|
|
|
idx_type i = p->index(row + p->row(idx), col + p->col(idx));
|
|
|
|
p->cell(i).push_back(data.cell(data.index(row, col)));
|
|
|
|
}
|
|
|
|
// append the left over horizontal cells to the last column
|
|
|
|
idx_type i = p->index(row + p->row(idx), p->ncols() - 1);
|
|
|
|
for (MathInset::col_type col = numcols; col < data.ncols(); ++col)
|
|
|
|
p->cell(i).push_back(data.cell(data.index(row, col)));
|
|
|
|
}
|
|
|
|
// append the left over vertical cells to the last _cell_
|
|
|
|
idx_type i = p->nargs() - 1;
|
|
|
|
for (row_type row = numrows; row < data.nrows(); ++row)
|
|
|
|
for (col_type col = 0; col < data.ncols(); ++col)
|
|
|
|
p->cell(i).push_back(data.cell(data.index(row, col)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-07 15:04:57 +00:00
|
|
|
void MathCursor::backspace()
|
|
|
|
{
|
2002-05-24 08:29:16 +00:00
|
|
|
autocorrect_ = false;
|
2001-10-10 13:20:51 +00:00
|
|
|
if (pos() == 0) {
|
2001-10-10 16:35:18 +00:00
|
|
|
pullArg(false);
|
2001-10-10 13:20:51 +00:00
|
|
|
return;
|
2002-01-11 10:26:13 +00:00
|
|
|
}
|
2001-10-10 13:20:51 +00:00
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
if (selection_) {
|
|
|
|
selDel();
|
2001-08-07 15:04:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
MathScriptInset * p = prevAtom()->asScriptInset();
|
|
|
|
if (p) {
|
|
|
|
p->removeScript(p->hasUp());
|
2002-01-11 10:26:13 +00:00
|
|
|
// Don't delete if there is anything left
|
2001-10-12 12:02:49 +00:00
|
|
|
if (p->hasUp() || p->hasDown())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-10-10 13:20:51 +00:00
|
|
|
--pos();
|
|
|
|
plainErase();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
void MathCursor::erase()
|
2001-02-14 17:58:40 +00:00
|
|
|
{
|
2002-05-24 08:29:16 +00:00
|
|
|
autocorrect_ = false;
|
2001-08-14 11:19:19 +00:00
|
|
|
if (inMacroMode())
|
2001-02-14 17:58:40 +00:00
|
|
|
return;
|
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
if (selection_) {
|
|
|
|
selDel();
|
2001-02-14 17:58:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-03-25 12:11:25 +00:00
|
|
|
// delete empty cells if possible
|
|
|
|
if (array().empty())
|
|
|
|
if (par()->idxDelete(idx()))
|
|
|
|
return;
|
2001-06-27 14:10:35 +00:00
|
|
|
|
2002-03-25 12:11:25 +00:00
|
|
|
// old behaviour when in last position of cell
|
|
|
|
if (pos() == size()) {
|
|
|
|
par()->idxGlue(idx());
|
2001-09-24 16:25:06 +00:00
|
|
|
return;
|
2002-03-25 12:11:25 +00:00
|
|
|
}
|
2001-09-24 16:25:06 +00:00
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
MathScriptInset * p = nextAtom()->asScriptInset();
|
|
|
|
if (p) {
|
|
|
|
p->removeScript(p->hasUp());
|
2002-01-11 10:26:13 +00:00
|
|
|
// Don't delete if there is anything left
|
2001-10-12 12:02:49 +00:00
|
|
|
if (p->hasUp() || p->hasDown())
|
|
|
|
return;
|
2001-09-24 16:25:06 +00:00
|
|
|
}
|
2001-07-23 14:21:34 +00:00
|
|
|
|
2001-09-24 16:25:06 +00:00
|
|
|
plainErase();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
void MathCursor::delLine()
|
2001-02-14 17:58:40 +00:00
|
|
|
{
|
2002-05-24 08:29:16 +00:00
|
|
|
autocorrect_ = false;
|
2001-07-26 09:01:36 +00:00
|
|
|
macroModeClose();
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
if (selection_) {
|
|
|
|
selDel();
|
2001-02-14 17:58:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-12-11 15:04:02 +00:00
|
|
|
if (par()->nrows() > 1) {
|
|
|
|
// grid are the only things with more than one row...
|
|
|
|
lyx::Assert(par()->asGridInset());
|
|
|
|
par()->asGridInset()->delRow(hullRow());
|
|
|
|
}
|
2001-10-23 13:48:52 +00:00
|
|
|
|
2002-02-08 18:19:16 +00:00
|
|
|
if (idx() >= par()->nargs())
|
|
|
|
idx() = par()->nargs() - 1;
|
2001-11-28 13:09:40 +00:00
|
|
|
|
2001-10-23 13:48:52 +00:00
|
|
|
if (pos() > size())
|
|
|
|
pos() = size();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
bool MathCursor::up(bool sel)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-07-26 09:01:36 +00:00
|
|
|
dump("up 1");
|
|
|
|
macroModeClose();
|
|
|
|
selHandle(sel);
|
2001-12-11 18:51:47 +00:00
|
|
|
cursor_type save = Cursor_;
|
|
|
|
if (goUpDown(true))
|
|
|
|
return true;
|
|
|
|
Cursor_ = save;
|
2002-05-24 08:29:16 +00:00
|
|
|
autocorrect_ = false;
|
2001-12-11 18:51:47 +00:00
|
|
|
return selection_;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
bool MathCursor::down(bool sel)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-07-26 09:01:36 +00:00
|
|
|
dump("down 1");
|
|
|
|
macroModeClose();
|
|
|
|
selHandle(sel);
|
2001-12-11 18:51:47 +00:00
|
|
|
cursor_type save = Cursor_;
|
|
|
|
if (goUpDown(false))
|
|
|
|
return true;
|
|
|
|
Cursor_ = save;
|
2002-05-24 08:29:16 +00:00
|
|
|
autocorrect_ = false;
|
2001-12-11 18:51:47 +00:00
|
|
|
return selection_;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
bool MathCursor::toggleLimits()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-11-27 13:36:23 +00:00
|
|
|
if (!hasNextAtom())
|
2001-10-12 12:02:49 +00:00
|
|
|
return false;
|
2001-11-27 13:36:23 +00:00
|
|
|
MathScriptInset * t = nextAtom()->asScriptInset();
|
2001-09-11 10:58:17 +00:00
|
|
|
if (!t)
|
2001-08-06 17:20:26 +00:00
|
|
|
return false;
|
2001-09-11 10:58:17 +00:00
|
|
|
int old = t->limits();
|
|
|
|
t->limits(old < 0 ? 1 : -1);
|
|
|
|
return old != t->limits();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-14 11:19:19 +00:00
|
|
|
void MathCursor::macroModeClose()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2002-05-30 07:09:54 +00:00
|
|
|
MathUnknownInset * p = inMacroMode();
|
|
|
|
if (!p)
|
2002-03-27 18:42:02 +00:00
|
|
|
return;
|
2002-05-30 07:09:54 +00:00
|
|
|
p->finalize();
|
|
|
|
string s = p->name();
|
|
|
|
--pos();
|
|
|
|
array().erase(pos());
|
2002-03-27 18:42:02 +00:00
|
|
|
if (s != "\\")
|
2001-10-10 16:35:18 +00:00
|
|
|
interpret(s);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-10-10 16:35:18 +00:00
|
|
|
string MathCursor::macroName() const
|
|
|
|
{
|
2002-06-18 15:44:30 +00:00
|
|
|
return inMacroMode() ? inMacroMode()->name() : string();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathCursor::selClear()
|
|
|
|
{
|
|
|
|
selection_ = false;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
void MathCursor::selCopy()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-12-05 17:50:18 +00:00
|
|
|
dump("selCopy");
|
2001-07-26 09:01:36 +00:00
|
|
|
if (selection_) {
|
2002-06-18 15:44:30 +00:00
|
|
|
theCutBuffer = grabSelection();
|
|
|
|
selection_ = false;
|
|
|
|
} else {
|
|
|
|
theCutBuffer = MathGridInset(1, 1);
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
void MathCursor::selCut()
|
2001-02-14 17:58:40 +00:00
|
|
|
{
|
2001-12-05 17:50:18 +00:00
|
|
|
dump("selCut");
|
2002-06-18 15:44:30 +00:00
|
|
|
theCutBuffer = grabAndEraseSelection();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
void MathCursor::selDel()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-12-05 17:50:18 +00:00
|
|
|
dump("selDel");
|
2001-07-26 09:01:36 +00:00
|
|
|
if (selection_) {
|
2002-06-18 15:44:30 +00:00
|
|
|
eraseSelection();
|
|
|
|
selection_ = false;
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
void MathCursor::selPaste()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-12-05 17:50:18 +00:00
|
|
|
dump("selPaste");
|
2002-05-14 09:15:40 +00:00
|
|
|
selClearOrDel();
|
2002-06-18 15:44:30 +00:00
|
|
|
paste(theCutBuffer);
|
|
|
|
//grabSelection();
|
|
|
|
selection_ = false;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
void MathCursor::selHandle(bool sel)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-08-07 13:23:16 +00:00
|
|
|
if (sel == selection_)
|
|
|
|
return;
|
2002-06-18 15:44:30 +00:00
|
|
|
//clear();
|
|
|
|
Anchor_ = Cursor_;
|
2001-08-07 13:23:16 +00:00
|
|
|
selection_ = sel;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
void MathCursor::selStart()
|
2001-02-14 17:58:40 +00:00
|
|
|
{
|
2001-12-05 17:50:18 +00:00
|
|
|
dump("selStart 1");
|
2002-06-18 15:44:30 +00:00
|
|
|
//clear();
|
2001-07-16 15:53:25 +00:00
|
|
|
Anchor_ = Cursor_;
|
2001-07-26 09:01:36 +00:00
|
|
|
selection_ = true;
|
2001-12-05 17:50:18 +00:00
|
|
|
dump("selStart 2");
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2002-05-14 09:15:40 +00:00
|
|
|
void MathCursor::selClearOrDel()
|
|
|
|
{
|
|
|
|
if (lyxrc.auto_region_delete)
|
|
|
|
selDel();
|
|
|
|
else
|
2002-06-18 15:44:30 +00:00
|
|
|
selection_ = false;
|
2002-05-14 09:15:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-23 13:48:52 +00:00
|
|
|
void MathCursor::selGet(MathArray & ar)
|
|
|
|
{
|
2001-12-05 17:50:18 +00:00
|
|
|
dump("selGet");
|
2002-06-18 15:44:30 +00:00
|
|
|
if (selection_)
|
|
|
|
ar = grabSelection().glue();
|
2001-10-23 13:48:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
void MathCursor::drawSelection(MathPainterInfo & pain) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-07-26 09:01:36 +00:00
|
|
|
if (!selection_)
|
2001-02-14 17:58:40 +00:00
|
|
|
return;
|
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
MathCursorPos i1;
|
|
|
|
MathCursorPos i2;
|
|
|
|
getSelection(i1, i2);
|
|
|
|
|
|
|
|
if (i1.idx_ == i2.idx_) {
|
|
|
|
MathXArray & c = i1.xcell();
|
2001-10-12 12:02:49 +00:00
|
|
|
int x1 = c.xo() + c.pos2x(i1.pos_);
|
2001-07-16 15:53:25 +00:00
|
|
|
int y1 = c.yo() - c.ascent();
|
2001-10-12 12:02:49 +00:00
|
|
|
int x2 = c.xo() + c.pos2x(i2.pos_);
|
2001-07-16 15:53:25 +00:00
|
|
|
int y2 = c.yo() + c.descent();
|
2002-05-30 07:09:54 +00:00
|
|
|
pain.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
|
2001-07-16 15:53:25 +00:00
|
|
|
} else {
|
2002-02-16 15:59:55 +00:00
|
|
|
vector<MathInset::idx_type> indices
|
2001-12-11 15:35:18 +00:00
|
|
|
= i1.par_->idxBetween(i1.idx_, i2.idx_);
|
2001-07-16 15:53:25 +00:00
|
|
|
for (unsigned i = 0; i < indices.size(); ++i) {
|
|
|
|
MathXArray & c = i1.xcell(indices[i]);
|
|
|
|
int x1 = c.xo();
|
|
|
|
int y1 = c.yo() - c.ascent();
|
|
|
|
int x2 = c.xo() + c.width();
|
|
|
|
int y2 = c.yo() + c.descent();
|
2002-05-30 07:09:54 +00:00
|
|
|
pain.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
|
2001-07-16 15:53:25 +00:00
|
|
|
}
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
2001-10-29 15:45:24 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
// draw anchor if different from selection boundary
|
|
|
|
MathCursorPos anc = Anchor_.back();
|
|
|
|
if (anc != i1 && anc != i2) {
|
|
|
|
MathXArray & c = anc.xcell();
|
|
|
|
int x = c.xo() + c.pos2x(anc.pos_);
|
|
|
|
int y1 = c.yo() - c.ascent();
|
|
|
|
int y2 = c.yo() + c.descent();
|
2001-12-03 16:24:50 +00:00
|
|
|
pain.line(x, y1, x, y2, LColor::math);
|
2001-10-29 15:45:24 +00:00
|
|
|
}
|
|
|
|
#endif
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2001-09-12 12:51:55 +00:00
|
|
|
void MathCursor::handleDelim(string const & l, string const & r)
|
2001-07-10 13:17:43 +00:00
|
|
|
{
|
2001-08-08 07:46:16 +00:00
|
|
|
handleNest(new MathDelimInset(l, r));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathCursor::handleNest(MathInset * p)
|
|
|
|
{
|
2002-06-18 15:44:30 +00:00
|
|
|
p->cell(0) = grabAndEraseSelection().glue();
|
2001-10-12 12:02:49 +00:00
|
|
|
insert(MathAtom(p)); // this invalidates p!
|
|
|
|
pushRight(prevAtom());
|
2001-07-10 13:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
void MathCursor::getPos(int & x, int & y)
|
2001-02-13 19:10:18 +00:00
|
|
|
{
|
2001-08-08 09:31:36 +00:00
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
#warning This should probably take cellXOffset and cellYOffset into account
|
|
|
|
#endif
|
2001-10-12 12:02:49 +00:00
|
|
|
x = xarray().xo() + xarray().pos2x(pos());
|
2002-05-08 16:17:57 +00:00
|
|
|
// move cursor visually into empty cells ("blue rectangles");
|
|
|
|
if (array().empty())
|
|
|
|
x += 2;
|
2001-06-25 00:06:33 +00:00
|
|
|
y = xarray().yo();
|
2001-02-13 19:10:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-11 15:35:18 +00:00
|
|
|
MathInset * MathCursor::par() const
|
2001-02-13 19:10:18 +00:00
|
|
|
{
|
2001-12-11 15:35:18 +00:00
|
|
|
return cursor().par_;
|
2001-02-13 19:10:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-10 10:09:00 +00:00
|
|
|
InsetFormulaBase * MathCursor::formula()
|
2001-02-13 19:10:18 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return formula_;
|
2001-02-13 19:10:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-01 12:10:32 +00:00
|
|
|
MathCursor::idx_type MathCursor::idx() const
|
2001-08-07 15:04:57 +00:00
|
|
|
{
|
|
|
|
return cursor().idx_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-01 12:10:32 +00:00
|
|
|
MathCursor::idx_type & MathCursor::idx()
|
2001-08-07 15:04:57 +00:00
|
|
|
{
|
|
|
|
return cursor().idx_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-01 12:10:32 +00:00
|
|
|
MathCursor::pos_type MathCursor::pos() const
|
2001-02-13 19:10:18 +00:00
|
|
|
{
|
2001-07-16 15:53:25 +00:00
|
|
|
return cursor().pos_;
|
2001-02-13 19:10:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-01 12:10:32 +00:00
|
|
|
MathCursor::pos_type & MathCursor::pos()
|
2001-08-07 15:04:57 +00:00
|
|
|
{
|
|
|
|
return cursor().pos_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
MathUnknownInset * MathCursor::inMacroMode() const
|
2001-02-13 19:10:18 +00:00
|
|
|
{
|
2002-05-30 07:09:54 +00:00
|
|
|
if (pos() == 0)
|
|
|
|
return 0;
|
|
|
|
MathUnknownInset * p = prevAtom()->asUnknownInset();
|
|
|
|
return (p && !p->final()) ? p : 0;
|
2001-02-13 19:10:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-11 10:26:13 +00:00
|
|
|
bool MathCursor::inMacroArgMode() const
|
|
|
|
{
|
|
|
|
return pos() > 0 && prevAtom()->getChar() == '#';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
bool MathCursor::selection() const
|
2001-02-13 19:10:18 +00:00
|
|
|
{
|
2001-07-26 09:01:36 +00:00
|
|
|
return selection_;
|
2001-02-13 19:10:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-13 08:21:03 +00:00
|
|
|
MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2002-06-18 15:44:30 +00:00
|
|
|
for (MathInset::difference_type i = depth() - 1; i >= 0; --i) {
|
2001-12-11 15:35:18 +00:00
|
|
|
MathGridInset * p = Cursor_[i].par_->asGridInset();
|
2001-10-12 12:02:49 +00:00
|
|
|
if (p) {
|
2001-07-16 15:53:25 +00:00
|
|
|
idx = Cursor_[i].idx_;
|
2001-10-12 12:02:49 +00:00
|
|
|
return p;
|
2002-06-18 15:44:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathHullInset * MathCursor::enclosingHull(MathCursor::idx_type & idx) const
|
|
|
|
{
|
|
|
|
for (MathInset::difference_type i = depth() - 1; i >= 0; --i) {
|
|
|
|
MathHullInset * p = Cursor_[i].par_->asHullInset();
|
|
|
|
if (p) {
|
|
|
|
idx = Cursor_[i].idx_;
|
|
|
|
return p;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2002-03-26 12:38:59 +00:00
|
|
|
void MathCursor::popToEnclosingGrid()
|
|
|
|
{
|
2002-06-18 15:44:30 +00:00
|
|
|
while (depth() && !Cursor_.back().par_->asGridInset())
|
|
|
|
Cursor_.pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathCursor::popToEnclosingHull()
|
|
|
|
{
|
|
|
|
while (depth() && !Cursor_.back().par_->asHullInset())
|
2002-03-26 12:38:59 +00:00
|
|
|
Cursor_.pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-23 14:15:14 +00:00
|
|
|
void MathCursor::pullArg(bool goright)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-07-23 13:52:48 +00:00
|
|
|
dump("pullarg");
|
2001-06-25 00:06:33 +00:00
|
|
|
MathArray a = array();
|
2001-10-10 16:35:18 +00:00
|
|
|
|
|
|
|
MathScriptInset const * p = par()->asScriptInset();
|
|
|
|
if (p) {
|
|
|
|
// special handling for scripts
|
2001-10-12 12:02:49 +00:00
|
|
|
const bool up = p->hasUp();
|
2001-10-10 16:35:18 +00:00
|
|
|
popLeft();
|
2001-10-12 12:02:49 +00:00
|
|
|
MathScriptInset * q = nextAtom()->asScriptInset();
|
|
|
|
if (q)
|
|
|
|
q->removeScript(up);
|
2001-10-10 16:35:18 +00:00
|
|
|
++pos();
|
|
|
|
array().insert(pos(), a);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-08-08 07:12:09 +00:00
|
|
|
if (popLeft()) {
|
2001-07-26 09:01:36 +00:00
|
|
|
plainErase();
|
2001-08-07 15:04:57 +00:00
|
|
|
array().insert(pos(), a);
|
2002-01-11 10:26:13 +00:00
|
|
|
if (goright)
|
2001-08-07 15:04:57 +00:00
|
|
|
pos() += a.size();
|
2002-02-07 08:19:47 +00:00
|
|
|
} else {
|
|
|
|
formula()->mutateToText();
|
2001-07-23 13:52:48 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-12 14:59:08 +00:00
|
|
|
void MathCursor::touch()
|
|
|
|
{
|
|
|
|
cursor_type::const_iterator it = Cursor_.begin();
|
|
|
|
cursor_type::const_iterator et = Cursor_.end();
|
|
|
|
for ( ; it != et; ++it)
|
|
|
|
it->xcell().touch();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-18 12:21:33 +00:00
|
|
|
void MathCursor::normalize()
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2002-03-12 16:39:27 +00:00
|
|
|
#if 0
|
2001-12-18 12:21:33 +00:00
|
|
|
// rebreak
|
|
|
|
{
|
|
|
|
MathIterator it = ibegin(formula()->par().nucleus());
|
|
|
|
MathIterator et = iend(formula()->par().nucleus());
|
2002-02-16 15:59:55 +00:00
|
|
|
for (; it != et; ++it)
|
2001-12-18 12:21:33 +00:00
|
|
|
if (it.par()->asBoxInset())
|
|
|
|
it.par()->asBoxInset()->rebreak();
|
|
|
|
}
|
2002-03-12 16:39:27 +00:00
|
|
|
#endif
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
if (idx() >= par()->nargs()) {
|
2001-09-26 15:20:45 +00:00
|
|
|
lyxerr << "this should not really happen - 1: "
|
2001-08-08 07:12:09 +00:00
|
|
|
<< idx() << " " << par()->nargs() << "\n";
|
|
|
|
dump("error 2");
|
|
|
|
}
|
2002-03-21 17:42:56 +00:00
|
|
|
idx() = min(idx(), par()->nargs() - 1);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-08-08 07:46:16 +00:00
|
|
|
if (pos() > size()) {
|
2001-09-26 15:20:45 +00:00
|
|
|
lyxerr << "this should not really happen - 2: "
|
2001-12-18 12:21:33 +00:00
|
|
|
<< pos() << " " << size() << " in idx: " << idx()
|
2001-10-12 15:38:58 +00:00
|
|
|
<< " in atom: '";
|
2002-03-25 12:11:25 +00:00
|
|
|
WriteStream wi(lyxerr, false, true);
|
2001-12-18 12:21:33 +00:00
|
|
|
par()->write(wi);
|
2001-10-12 15:38:58 +00:00
|
|
|
lyxerr << "\n";
|
2001-08-08 07:12:09 +00:00
|
|
|
dump("error 4");
|
|
|
|
}
|
2001-12-18 12:21:33 +00:00
|
|
|
pos() = min(pos(), size());
|
2002-03-18 11:45:53 +00:00
|
|
|
|
|
|
|
// remove empty scripts if possible
|
2002-04-12 13:30:14 +00:00
|
|
|
if (1) {
|
|
|
|
for (pos_type i = 0; i < size(); ++i) {
|
2002-06-18 15:44:30 +00:00
|
|
|
MathScriptInset * p = array()[i]->asScriptInset();
|
2002-04-12 13:30:14 +00:00
|
|
|
if (p) {
|
|
|
|
p->removeEmptyScripts();
|
|
|
|
//if (p->empty())
|
|
|
|
// array().erase(i);
|
|
|
|
}
|
2002-03-18 11:45:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// fix again position
|
|
|
|
pos() = min(pos(), size());
|
2001-08-08 07:46:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-01 12:10:32 +00:00
|
|
|
MathCursor::size_type MathCursor::size() const
|
2001-08-08 07:46:16 +00:00
|
|
|
{
|
|
|
|
return array().size();
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-11 15:04:02 +00:00
|
|
|
MathCursor::col_type MathCursor::hullCol() const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2002-06-18 15:44:30 +00:00
|
|
|
idx_type idx = 0;
|
|
|
|
MathHullInset * p = enclosingHull(idx);
|
|
|
|
return p->col(idx);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-11 15:04:02 +00:00
|
|
|
MathCursor::row_type MathCursor::hullRow() const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2002-06-18 15:44:30 +00:00
|
|
|
idx_type idx = 0;
|
|
|
|
MathHullInset * p = enclosingHull(idx);
|
|
|
|
return p->row(idx);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
bool MathCursor::hasPrevAtom() const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
return pos() > 0;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
bool MathCursor::hasNextAtom() const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
return pos() < size();
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
MathAtom const & MathCursor::prevAtom() const
|
2001-07-25 14:15:05 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
lyx::Assert(pos() > 0);
|
2002-06-18 15:44:30 +00:00
|
|
|
return array()[pos() - 1];
|
2001-09-11 10:58:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
MathAtom & MathCursor::prevAtom()
|
2001-09-11 10:58:17 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
lyx::Assert(pos() > 0);
|
2002-06-18 15:44:30 +00:00
|
|
|
return array()[pos() - 1];
|
2001-09-11 10:58:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
MathAtom const & MathCursor::nextAtom() const
|
2001-09-11 10:58:17 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
lyx::Assert(pos() < size());
|
2002-06-18 15:44:30 +00:00
|
|
|
return array()[pos()];
|
2001-09-11 10:58:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
MathAtom & MathCursor::nextAtom()
|
2001-09-11 10:58:17 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
lyx::Assert(pos() < size());
|
2002-06-18 15:44:30 +00:00
|
|
|
return array()[pos()];
|
2001-07-25 14:15:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathArray & MathCursor::array() const
|
|
|
|
{
|
|
|
|
static MathArray dummy;
|
|
|
|
|
2001-09-26 15:20:45 +00:00
|
|
|
if (idx() >= par()->nargs()) {
|
2001-08-07 15:04:57 +00:00
|
|
|
lyxerr << "############ idx_ " << idx() << " not valid\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
return dummy;
|
|
|
|
}
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
if (depth() == 0) {
|
|
|
|
lyxerr << "############ depth() == 0 not valid\n";
|
2001-12-10 10:09:00 +00:00
|
|
|
return dummy;
|
|
|
|
}
|
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
return cursor().cell();
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathXArray & MathCursor::xarray() const
|
|
|
|
{
|
2001-12-10 10:09:00 +00:00
|
|
|
static MathXArray dummy;
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
if (depth() == 0) {
|
|
|
|
lyxerr << "############ depth() == 0 not valid\n";
|
2001-12-10 10:09:00 +00:00
|
|
|
return dummy;
|
|
|
|
}
|
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
return cursor().xcell();
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
void MathCursor::idxNext()
|
2001-04-24 16:13:38 +00:00
|
|
|
{
|
2001-08-07 15:04:57 +00:00
|
|
|
par()->idxNext(idx(), pos());
|
2001-07-06 12:09:32 +00:00
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
void MathCursor::idxPrev()
|
|
|
|
{
|
2001-08-07 15:04:57 +00:00
|
|
|
par()->idxPrev(idx(), pos());
|
2001-07-06 12:09:32 +00:00
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
void MathCursor::splitCell()
|
|
|
|
{
|
2002-01-11 10:26:13 +00:00
|
|
|
if (idx() + 1 == par()->nargs())
|
2001-07-06 12:09:32 +00:00
|
|
|
return;
|
|
|
|
MathArray ar = array();
|
2001-08-07 15:04:57 +00:00
|
|
|
ar.erase(0, pos());
|
2001-08-08 07:46:16 +00:00
|
|
|
array().erase(pos(), size());
|
2001-08-07 15:04:57 +00:00
|
|
|
++idx();
|
|
|
|
pos() = 0;
|
2001-07-06 12:09:32 +00:00
|
|
|
array().insert(0, ar);
|
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
void MathCursor::breakLine()
|
|
|
|
{
|
2001-08-08 15:35:49 +00:00
|
|
|
// leave inner cells
|
|
|
|
while (popRight())
|
|
|
|
;
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
idx_type dummy;
|
|
|
|
MathHullInset * p = enclosingHull(dummy);
|
2001-10-12 12:02:49 +00:00
|
|
|
if (!p)
|
|
|
|
return;
|
|
|
|
|
2001-07-26 06:56:43 +00:00
|
|
|
if (p->getType() == LM_OT_SIMPLE || p->getType() == LM_OT_EQUATION) {
|
2001-07-06 12:09:32 +00:00
|
|
|
p->mutate(LM_OT_EQNARRAY);
|
2002-06-18 15:44:30 +00:00
|
|
|
idx() = 1;
|
|
|
|
pos() = 0;
|
2001-12-10 10:09:00 +00:00
|
|
|
} else {
|
2001-12-11 15:04:02 +00:00
|
|
|
p->addRow(hullRow());
|
2001-07-09 16:59:57 +00:00
|
|
|
|
2001-12-10 10:09:00 +00:00
|
|
|
// split line
|
2001-12-11 15:04:02 +00:00
|
|
|
const row_type r = hullRow();
|
|
|
|
for (col_type c = hullCol() + 1; c < p->ncols(); ++c)
|
2001-12-10 10:09:00 +00:00
|
|
|
p->cell(p->index(r, c)).swap(p->cell(p->index(r + 1, c)));
|
2001-07-06 12:09:32 +00:00
|
|
|
|
2001-12-10 10:09:00 +00:00
|
|
|
// split cell
|
|
|
|
splitCell();
|
|
|
|
p->cell(idx()).swap(p->cell(idx() + p->ncols() - 1));
|
|
|
|
}
|
2001-04-24 16:13:38 +00:00
|
|
|
}
|
2001-06-27 14:10:35 +00:00
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-12-11 15:04:02 +00:00
|
|
|
//void MathCursor::readLine(MathArray & ar) const
|
|
|
|
//{
|
|
|
|
// idx_type base = row() * par()->ncols();
|
|
|
|
// for (idx_type off = 0; off < par()->ncols(); ++off)
|
|
|
|
// ar.push_back(par()->cell(base + off));
|
|
|
|
//}
|
2001-11-12 16:45:09 +00:00
|
|
|
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
char MathCursor::valign() const
|
|
|
|
{
|
2001-10-01 12:10:32 +00:00
|
|
|
idx_type idx;
|
2001-11-13 08:21:03 +00:00
|
|
|
MathGridInset * p = enclosingGrid(idx);
|
2001-10-01 12:10:32 +00:00
|
|
|
return p ? p->valign() : '\0';
|
2001-06-27 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
char MathCursor::halign() const
|
|
|
|
{
|
2001-10-01 12:10:32 +00:00
|
|
|
idx_type idx;
|
2001-11-13 08:21:03 +00:00
|
|
|
MathGridInset * p = enclosingGrid(idx);
|
2001-10-01 12:10:32 +00:00
|
|
|
return p ? p->halign(idx % p->ncols()) : '\0';
|
2001-06-27 14:10:35 +00:00
|
|
|
}
|
2001-07-16 15:53:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
|
|
|
|
{
|
|
|
|
MathCursorPos anc = normalAnchor();
|
|
|
|
if (anc < cursor()) {
|
|
|
|
i1 = anc;
|
|
|
|
i2 = cursor();
|
|
|
|
} else {
|
|
|
|
i1 = cursor();
|
|
|
|
i2 = anc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathCursorPos & MathCursor::cursor()
|
|
|
|
{
|
2002-06-18 15:44:30 +00:00
|
|
|
lyx::Assert(depth());
|
2001-07-16 15:53:25 +00:00
|
|
|
return Cursor_.back();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathCursorPos const & MathCursor::cursor() const
|
|
|
|
{
|
2002-06-18 15:44:30 +00:00
|
|
|
lyx::Assert(depth());
|
2001-07-16 15:53:25 +00:00
|
|
|
return Cursor_.back();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-11 18:51:47 +00:00
|
|
|
bool MathCursor::goUpDown(bool up)
|
2001-07-16 15:53:25 +00:00
|
|
|
{
|
2002-03-22 09:31:26 +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 know what you are doing!
|
2001-12-12 14:05:38 +00:00
|
|
|
int xlow, xhigh, ylow, yhigh;
|
|
|
|
|
|
|
|
int xo, yo;
|
2001-12-11 18:51:47 +00:00
|
|
|
getPos(xo, yo);
|
2001-07-16 15:53:25 +00:00
|
|
|
|
2002-06-13 18:07:40 +00:00
|
|
|
// check if we had something else in mind, if not, this is the future goal
|
2002-06-14 10:48:27 +00:00
|
|
|
if (targetx_ == -1)
|
2002-06-13 18:07:40 +00:00
|
|
|
targetx_ = xo;
|
2002-06-14 10:48:27 +00:00
|
|
|
else
|
|
|
|
xo = targetx_;
|
2002-06-13 18:07:40 +00:00
|
|
|
|
2002-03-21 09:48:46 +00:00
|
|
|
// try neigbouring script insets
|
|
|
|
// try left
|
|
|
|
if (hasPrevAtom()) {
|
|
|
|
MathScriptInset * p = prevAtom()->asScriptInset();
|
|
|
|
if (p && p->has(up)) {
|
|
|
|
--pos();
|
|
|
|
push(nextAtom());
|
|
|
|
idx() = up; // the superscript has index 1
|
|
|
|
pos() = size();
|
|
|
|
///lyxerr << "updown: handled by scriptinset to the left\n";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// try right
|
|
|
|
if (hasNextAtom()) {
|
|
|
|
MathScriptInset * p = nextAtom()->asScriptInset();
|
|
|
|
if (p && p->has(up)) {
|
|
|
|
push(nextAtom());
|
|
|
|
idx() = up;
|
|
|
|
pos() = 0;
|
|
|
|
///lyxerr << "updown: handled by scriptinset to the right\n";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// try current cell
|
|
|
|
//xarray().boundingBox(xlow, xhigh, ylow, yhigh);
|
|
|
|
//if (up)
|
|
|
|
// yhigh = yo - 4;
|
|
|
|
//else
|
|
|
|
// ylow = yo + 4;
|
|
|
|
//if (bruteFind(xo, yo, xlow, xhigh, ylow, yhigh)) {
|
|
|
|
// lyxerr << "updown: handled by brute find in the same cell\n";
|
|
|
|
// return true;
|
|
|
|
//}
|
2001-12-12 14:05:38 +00:00
|
|
|
|
2001-12-11 18:51:47 +00:00
|
|
|
// try to find an inset that knows better then we
|
|
|
|
while (1) {
|
2002-03-22 09:31:26 +00:00
|
|
|
///lyxerr << "updown: We are in " << *par() << " idx: " << idx() << '\n';
|
|
|
|
// ask inset first
|
2002-03-21 09:48:46 +00:00
|
|
|
if (par()->idxUpDown(idx(), up)) {
|
2002-03-22 09:31:26 +00:00
|
|
|
// we found a cell that thinks it has something "below" us.
|
2002-03-21 09:48:46 +00:00
|
|
|
///lyxerr << "updown: found inset that handles UpDown\n";
|
|
|
|
xarray().boundingBox(xlow, xhigh, ylow, yhigh);
|
|
|
|
// project (xo,yo) onto proper box
|
|
|
|
///lyxerr << "\n xo: " << xo << " yo: " << yo
|
|
|
|
/// << "\n xlow: " << xlow << " ylow: " << ylow
|
|
|
|
/// << "\n xhigh: " << xhigh << " yhigh: " << yhigh;
|
|
|
|
xo = min(max(xo, xlow), xhigh);
|
|
|
|
yo = min(max(yo, ylow), yhigh);
|
|
|
|
///lyxerr << "\n xo2: " << xo << " yo2: " << yo << "\n";
|
|
|
|
bruteFind(xo, yo, xlow, xhigh, ylow, yhigh);
|
|
|
|
///lyxerr << "updown: handled by final brute find\n";
|
|
|
|
return true;
|
2001-12-11 18:51:47 +00:00
|
|
|
}
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2002-03-22 09:31:26 +00:00
|
|
|
// leave inset
|
2001-12-11 18:51:47 +00:00
|
|
|
if (!popLeft()) {
|
2001-12-12 14:05:38 +00:00
|
|
|
// no such inset found, just take something "above"
|
2002-03-21 09:48:46 +00:00
|
|
|
///lyxerr << "updown: handled by strange case\n";
|
2002-03-21 17:42:56 +00:00
|
|
|
return
|
2001-12-11 18:51:47 +00:00
|
|
|
bruteFind(xo, yo,
|
|
|
|
formula()->xlow(),
|
|
|
|
formula()->xhigh(),
|
|
|
|
up ? formula()->ylow() : yo + 4,
|
|
|
|
up ? yo - 4 : formula()->yhigh()
|
|
|
|
);
|
|
|
|
}
|
2002-04-22 16:31:14 +00:00
|
|
|
|
2002-03-22 09:31:26 +00:00
|
|
|
// any improvement so far?
|
|
|
|
int xnew, ynew;
|
|
|
|
getPos(xnew, ynew);
|
|
|
|
if (up ? ynew < yo : ynew > yo)
|
|
|
|
return true;
|
2001-12-05 17:50:18 +00:00
|
|
|
}
|
2001-07-16 15:53:25 +00:00
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2002-03-21 09:48:46 +00:00
|
|
|
bool MathCursor::bruteFind
|
|
|
|
(int x, int y, int xlow, int xhigh, int ylow, int yhigh)
|
2001-12-05 17:50:18 +00:00
|
|
|
{
|
|
|
|
cursor_type best_cursor;
|
|
|
|
double best_dist = 1e10;
|
|
|
|
|
2001-12-11 15:35:18 +00:00
|
|
|
MathIterator it = ibegin(formula()->par().nucleus());
|
|
|
|
MathIterator et = iend(formula()->par().nucleus());
|
2002-02-01 12:57:16 +00:00
|
|
|
while (1) {
|
2002-02-05 16:30:56 +00:00
|
|
|
// avoid invalid nesting when selecting
|
|
|
|
if (!selection_ || positionable(it.cursor(), Anchor_)) {
|
2002-03-13 11:17:21 +00:00
|
|
|
MathCursorPos const & top = it.position();
|
|
|
|
int xo = top.xpos();
|
|
|
|
int yo = top.ypos();
|
2002-03-21 09:48:46 +00:00
|
|
|
if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
|
2002-02-05 16:30:56 +00:00
|
|
|
double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
|
2002-03-22 09:31:26 +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) {
|
2002-02-05 16:30:56 +00:00
|
|
|
best_dist = d;
|
|
|
|
best_cursor = it.cursor();
|
|
|
|
}
|
2001-12-05 17:50:18 +00:00
|
|
|
}
|
|
|
|
}
|
2002-02-01 12:57:16 +00:00
|
|
|
|
|
|
|
if (it == et)
|
|
|
|
break;
|
|
|
|
++it;
|
2001-12-05 17:50:18 +00:00
|
|
|
}
|
2002-02-01 12:57:16 +00:00
|
|
|
|
2001-12-05 17:50:18 +00:00
|
|
|
if (best_dist < 1e10)
|
|
|
|
Cursor_ = best_cursor;
|
2001-12-05 18:55:45 +00:00
|
|
|
return best_dist < 1e10;
|
2001-12-05 17:50:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
bool MathCursor::idxLineFirst()
|
|
|
|
{
|
|
|
|
idx() -= idx() % par()->ncols();
|
|
|
|
pos() = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathCursor::idxLineLast()
|
|
|
|
{
|
|
|
|
idx() -= idx() % par()->ncols();
|
|
|
|
idx() += par()->ncols() - 1;
|
|
|
|
pos() = size();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2001-08-08 09:47:44 +00:00
|
|
|
bool MathCursor::idxLeft()
|
2001-08-08 09:31:36 +00:00
|
|
|
{
|
2001-08-08 09:47:44 +00:00
|
|
|
return par()->idxLeft(idx(), pos());
|
2001-08-08 09:31:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-08 09:47:44 +00:00
|
|
|
bool MathCursor::idxRight()
|
2001-08-08 09:31:36 +00:00
|
|
|
{
|
2001-08-08 09:47:44 +00:00
|
|
|
return par()->idxRight(idx(), pos());
|
2001-08-08 09:31:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-13 08:03:52 +00:00
|
|
|
bool MathCursor::interpret(string const & s)
|
2001-08-13 14:02:37 +00:00
|
|
|
{
|
2001-10-10 16:35:18 +00:00
|
|
|
//lyxerr << "interpret 1: '" << s << "'\n";
|
2001-08-13 14:02:37 +00:00
|
|
|
if (s.empty())
|
2001-11-13 08:03:52 +00:00
|
|
|
return true;
|
2001-08-13 14:02:37 +00:00
|
|
|
|
2001-10-10 16:35:18 +00:00
|
|
|
//lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl;
|
2002-06-18 15:44:30 +00:00
|
|
|
//owner_->getIntl()->getTransManager().TranslateAndInsert(s[0], lt);
|
2001-10-10 16:35:18 +00:00
|
|
|
//lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl;
|
2001-08-13 14:02:37 +00:00
|
|
|
|
2001-11-12 16:45:09 +00:00
|
|
|
if (s.size() >= 5 && s.substr(0, 5) == "cases") {
|
|
|
|
unsigned int n = 1;
|
2001-11-13 12:51:43 +00:00
|
|
|
istringstream is(s.substr(5).c_str());
|
2001-11-12 16:45:09 +00:00
|
|
|
is >> n;
|
2002-02-16 15:59:55 +00:00
|
|
|
n = max(1u, n);
|
2001-11-12 16:45:09 +00:00
|
|
|
niceInsert(MathAtom(new MathCasesInset(n)));
|
2001-11-13 08:03:52 +00:00
|
|
|
return true;
|
2001-11-12 16:45:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (s.size() >= 6 && s.substr(0, 6) == "matrix") {
|
2001-09-26 15:20:45 +00:00
|
|
|
unsigned int m = 1;
|
|
|
|
unsigned int n = 1;
|
2001-08-13 14:02:37 +00:00
|
|
|
string v_align;
|
|
|
|
string h_align;
|
2001-11-13 12:51:43 +00:00
|
|
|
istringstream is(s.substr(6).c_str());
|
2001-08-13 14:02:37 +00:00
|
|
|
is >> m >> n >> v_align >> h_align;
|
2002-02-16 15:59:55 +00:00
|
|
|
m = max(1u, m);
|
|
|
|
n = max(1u, n);
|
2001-08-13 14:02:37 +00:00
|
|
|
v_align += 'c';
|
2002-02-14 14:52:23 +00:00
|
|
|
niceInsert(MathAtom(new MathArrayInset("array", m, n, v_align[0], h_align)));
|
2001-11-13 08:03:52 +00:00
|
|
|
return true;
|
2001-08-13 14:46:06 +00:00
|
|
|
}
|
|
|
|
|
2001-11-16 09:55:37 +00:00
|
|
|
if (s.size() >= 7 && s.substr(0, 7) == "replace") {
|
|
|
|
ReplaceData rep;
|
|
|
|
istringstream is(s.substr(7).c_str());
|
|
|
|
string from, to;
|
|
|
|
is >> from >> to;
|
|
|
|
mathed_parse_cell(rep.from, from);
|
|
|
|
mathed_parse_cell(rep.to, to);
|
|
|
|
lyxerr << "replacing '" << from << "' with '" << to << "'\n";
|
|
|
|
par()->replace(rep);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-04-04 10:11:13 +00:00
|
|
|
string name = s.substr(1);
|
|
|
|
|
|
|
|
if (name == "over" || name == "choose" || name == "atop") {
|
2001-08-13 14:46:06 +00:00
|
|
|
MathArray ar = array();
|
2002-04-04 10:11:13 +00:00
|
|
|
MathAtom t(createMathInset(name));
|
2001-10-12 12:02:49 +00:00
|
|
|
t->asNestInset()->cell(0).swap(array());
|
2001-08-13 14:46:06 +00:00
|
|
|
pos() = 0;
|
2001-10-12 12:02:49 +00:00
|
|
|
niceInsert(t);
|
2001-08-15 05:50:39 +00:00
|
|
|
popRight();
|
|
|
|
left();
|
2001-11-13 08:03:52 +00:00
|
|
|
return true;
|
2001-08-13 14:02:37 +00:00
|
|
|
}
|
|
|
|
|
2002-02-01 17:09:55 +00:00
|
|
|
// prevent entering of recursive macros
|
2002-03-21 17:42:56 +00:00
|
|
|
if (formula()->lyxCode() == Inset::MATHMACRO_CODE
|
2002-04-04 10:11:13 +00:00
|
|
|
&& formula()->getInsetName() == name)
|
2002-02-01 17:09:55 +00:00
|
|
|
{
|
|
|
|
lyxerr << "can't enter recursive macro\n";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-04-04 10:11:13 +00:00
|
|
|
niceInsert(createMathInset(name));
|
2001-11-13 08:03:52 +00:00
|
|
|
return true;
|
2001-10-10 16:35:18 +00:00
|
|
|
}
|
|
|
|
|
2002-01-03 12:02:54 +00:00
|
|
|
|
2001-12-12 14:37:59 +00:00
|
|
|
bool MathCursor::script(bool up)
|
|
|
|
{
|
2002-04-18 15:29:27 +00:00
|
|
|
// Hack to get \\^ and \\_ working
|
|
|
|
if (inMacroMode() && macroName() == "\\") {
|
|
|
|
if (up)
|
|
|
|
interpret("\\mathcircumflex");
|
|
|
|
else
|
|
|
|
interpret('_');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2001-12-12 14:37:59 +00:00
|
|
|
macroModeClose();
|
2002-06-18 15:44:30 +00:00
|
|
|
MathGridInset safe = grabAndEraseSelection();
|
2001-12-12 14:37:59 +00:00
|
|
|
if (hasPrevAtom() && prevAtom()->asScriptInset()) {
|
|
|
|
prevAtom()->asScriptInset()->ensure(up);
|
|
|
|
pushRight(prevAtom());
|
|
|
|
idx() = up;
|
|
|
|
pos() = size();
|
|
|
|
} else if (hasNextAtom() && nextAtom()->asScriptInset()) {
|
|
|
|
nextAtom()->asScriptInset()->ensure(up);
|
|
|
|
pushLeft(nextAtom());
|
|
|
|
idx() = up;
|
|
|
|
pos() = 0;
|
|
|
|
} else {
|
|
|
|
plainInsert(MathAtom(new MathScriptInset(up)));
|
|
|
|
prevAtom()->asScriptInset()->ensure(up);
|
|
|
|
pushRight(prevAtom());
|
|
|
|
idx() = up;
|
|
|
|
pos() = 0;
|
|
|
|
}
|
2002-06-18 15:44:30 +00:00
|
|
|
paste(safe);
|
2001-12-12 14:37:59 +00:00
|
|
|
dump("1");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2001-10-10 16:35:18 +00:00
|
|
|
|
2002-06-04 09:45:41 +00:00
|
|
|
bool MathCursor::inMathMode() const
|
|
|
|
{
|
|
|
|
return !par()->asBoxInset();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-13 08:03:52 +00:00
|
|
|
bool MathCursor::interpret(char c)
|
2001-10-10 16:35:18 +00:00
|
|
|
{
|
2002-04-04 10:11:13 +00:00
|
|
|
//lyxerr << "interpret 2: '" << c << "'\n";
|
2002-06-14 10:48:27 +00:00
|
|
|
targetx_ = -1; // "no target"
|
2002-01-11 10:26:13 +00:00
|
|
|
if (inMacroArgMode()) {
|
|
|
|
--pos();
|
|
|
|
plainErase();
|
2002-03-13 11:20:35 +00:00
|
|
|
int n = c - '0';
|
|
|
|
MathMacroTemplate * p = formula()->par()->asMacroTemplate();
|
|
|
|
if (p && 1 <= n && n <= p->numargs())
|
2002-05-30 07:09:54 +00:00
|
|
|
insert(MathAtom(new MathMacroArgument(c - '0')));
|
2002-01-11 10:26:13 +00:00
|
|
|
else {
|
2002-06-18 15:44:30 +00:00
|
|
|
insert(createMathInset("#"));
|
2002-01-11 10:26:13 +00:00
|
|
|
interpret(c); // try again
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2002-01-03 13:44:21 +00:00
|
|
|
|
2001-11-09 13:51:24 +00:00
|
|
|
// handle macroMode
|
2001-10-10 16:35:18 +00:00
|
|
|
if (inMacroMode()) {
|
|
|
|
string name = macroName();
|
2002-04-04 10:11:13 +00:00
|
|
|
//lyxerr << "interpret name: '" << name << "'\n";
|
2001-10-10 16:35:18 +00:00
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
if (name.empty() && c == '\\') {
|
|
|
|
backspace();
|
|
|
|
interpret("\\backslash");
|
2001-11-13 08:03:52 +00:00
|
|
|
return true;
|
2001-10-10 16:35:18 +00:00
|
|
|
}
|
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
if (isalpha(c)) {
|
|
|
|
inMacroMode()->name() += c;
|
2002-04-02 07:33:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-04-04 10:11:13 +00:00
|
|
|
// handle 'special char' macros
|
|
|
|
if (name == "\\") {
|
|
|
|
// remove the '\\'
|
|
|
|
backspace();
|
2002-04-22 16:31:14 +00:00
|
|
|
if (c == '\\')
|
2002-04-04 10:11:13 +00:00
|
|
|
interpret("\\backslash");
|
|
|
|
else
|
|
|
|
interpret(string("\\") + c);
|
|
|
|
return true;
|
|
|
|
}
|
2002-01-30 11:29:54 +00:00
|
|
|
|
2002-04-04 10:11:13 +00:00
|
|
|
// leave macro mode and try again
|
|
|
|
macroModeClose();
|
|
|
|
interpret(c);
|
2001-11-13 08:03:52 +00:00
|
|
|
return true;
|
2001-10-10 16:35:18 +00:00
|
|
|
}
|
2001-08-13 14:02:37 +00:00
|
|
|
|
2002-05-24 08:29:16 +00:00
|
|
|
// leave autocorrect mode if necessary
|
|
|
|
if (autocorrect_ && c == ' ') {
|
|
|
|
autocorrect_ = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-05-14 09:15:40 +00:00
|
|
|
// just clear selection on pressing the space par
|
|
|
|
if (selection_ && c == ' ') {
|
2002-06-18 15:44:30 +00:00
|
|
|
selection_ = false;
|
2002-05-14 09:15:40 +00:00
|
|
|
return true;
|
2001-12-15 16:13:11 +00:00
|
|
|
}
|
2001-08-13 14:02:37 +00:00
|
|
|
|
2002-05-14 09:15:40 +00:00
|
|
|
selClearOrDel();
|
|
|
|
|
2002-06-04 09:45:41 +00:00
|
|
|
if (!inMathMode()) {
|
2001-12-15 16:13:11 +00:00
|
|
|
// suppress direct insertion of two spaces in a row
|
2001-10-25 14:46:57 +00:00
|
|
|
// the still allows typing '<space>a<space>' and deleting the 'a', but
|
2001-12-15 16:13:11 +00:00
|
|
|
// it is better than nothing...
|
2001-11-13 08:24:41 +00:00
|
|
|
if (c == ' ' && hasPrevAtom() && prevAtom()->getChar() == ' ')
|
2001-11-13 08:03:52 +00:00
|
|
|
return true;
|
2002-06-04 09:45:41 +00:00
|
|
|
insert(c);
|
2002-05-30 07:09:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == '\\') {
|
|
|
|
lyxerr << "starting with macro\n";
|
|
|
|
insert(MathAtom(new MathUnknownInset("\\", false)));
|
2001-11-13 08:03:52 +00:00
|
|
|
return true;
|
2001-08-13 14:02:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (c == ' ') {
|
2001-10-12 13:29:46 +00:00
|
|
|
if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
|
|
|
|
prevAtom()->asSpaceInset()->incSpace();
|
2001-11-13 08:03:52 +00:00
|
|
|
return true;
|
2001-08-17 09:48:24 +00:00
|
|
|
}
|
2001-12-18 12:21:33 +00:00
|
|
|
if (popRight())
|
2001-11-13 08:03:52 +00:00
|
|
|
return true;
|
|
|
|
// if are at the very end, leave the formula
|
|
|
|
return pos() != size();
|
2001-08-13 14:02:37 +00:00
|
|
|
}
|
|
|
|
|
2002-01-11 10:26:13 +00:00
|
|
|
if (c == '#') {
|
2002-05-30 07:09:54 +00:00
|
|
|
insert(c); // LM_TC_TEX;
|
2002-01-11 10:26:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2001-10-29 15:45:24 +00:00
|
|
|
/*
|
2002-03-20 07:54:14 +00:00
|
|
|
if (c == '{' || c == '}', c)) {
|
2002-05-30 07:09:54 +00:00
|
|
|
insert(c); // LM_TC_TEX;
|
2001-11-13 08:03:52 +00:00
|
|
|
return true;
|
2001-10-10 13:20:51 +00:00
|
|
|
}
|
2001-10-29 15:45:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (c == '{') {
|
|
|
|
niceInsert(MathAtom(new MathBraceInset));
|
2001-11-13 08:03:52 +00:00
|
|
|
return true;
|
2001-10-29 15:45:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (c == '}') {
|
2001-11-13 08:03:52 +00:00
|
|
|
return true;
|
2001-10-29 15:45:24 +00:00
|
|
|
}
|
2001-10-10 13:20:51 +00:00
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
if (c == '$') {
|
|
|
|
insert(createMathInset("$"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == '%') {
|
|
|
|
insert(createMathInset("%"));
|
2001-11-13 08:03:52 +00:00
|
|
|
return true;
|
2001-08-30 08:55:13 +00:00
|
|
|
}
|
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
/*
|
2001-10-23 08:14:52 +00:00
|
|
|
if (isalpha(c) && lastcode_ == LM_TC_GREEK) {
|
|
|
|
insert(c, LM_TC_VAR);
|
2001-11-13 08:03:52 +00:00
|
|
|
return true;
|
2001-10-23 08:14:52 +00:00
|
|
|
}
|
2001-08-30 14:40:43 +00:00
|
|
|
|
2001-10-23 08:14:52 +00:00
|
|
|
if (isalpha(c) && lastcode_ == LM_TC_GREEK1) {
|
|
|
|
insert(c, LM_TC_VAR);
|
|
|
|
lastcode_ = LM_TC_VAR;
|
2001-11-13 08:03:52 +00:00
|
|
|
return true;
|
2001-08-13 14:02:37 +00:00
|
|
|
}
|
|
|
|
|
2001-08-28 13:34:04 +00:00
|
|
|
if (c == '\\') {
|
2001-10-02 15:01:57 +00:00
|
|
|
insert(c, LM_TC_TEX);
|
2001-08-28 13:34:04 +00:00
|
|
|
//bv->owner()->message(_("TeX mode"));
|
2002-01-11 10:26:13 +00:00
|
|
|
return true;
|
2001-08-13 14:02:37 +00:00
|
|
|
}
|
2002-05-30 07:09:54 +00:00
|
|
|
*/
|
2001-08-13 14:02:37 +00:00
|
|
|
|
2002-05-24 08:29:16 +00:00
|
|
|
// try auto-correction
|
|
|
|
if (autocorrect_ && hasPrevAtom() && math_autocorrect(prevAtom(), c))
|
|
|
|
return true;
|
|
|
|
|
2001-08-28 13:34:04 +00:00
|
|
|
// no special circumstances, so insert the character without any fuss
|
2002-05-30 07:09:54 +00:00
|
|
|
insert(c);
|
|
|
|
autocorrect_ = true;
|
2001-11-13 08:03:52 +00:00
|
|
|
return true;
|
2001-08-13 14:02:37 +00:00
|
|
|
}
|
|
|
|
|
2001-08-14 07:46:11 +00:00
|
|
|
|
2002-01-03 09:41:26 +00:00
|
|
|
void MathCursor::setSelection(cursor_type const & where, size_type n)
|
|
|
|
{
|
|
|
|
selection_ = true;
|
|
|
|
Anchor_ = where;
|
|
|
|
Cursor_ = where;
|
|
|
|
cursor().pos_ += n;
|
|
|
|
}
|
2002-01-16 14:24:38 +00:00
|
|
|
|
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
void MathCursor::insetToggle()
|
|
|
|
{
|
|
|
|
if (hasNextAtom())
|
|
|
|
nextAtom()->lock(!nextAtom()->lock());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-16 14:24:38 +00:00
|
|
|
string MathCursor::info() const
|
|
|
|
{
|
2002-02-16 15:59:55 +00:00
|
|
|
ostringstream os;
|
2002-05-30 07:09:54 +00:00
|
|
|
os << "Math editor mode ";
|
2002-06-18 15:44:30 +00:00
|
|
|
for (int i = 0, n = depth(); i < n; ++i) {
|
2002-05-30 07:09:54 +00:00
|
|
|
Cursor_[i].par_->infoize(os);
|
|
|
|
os << " ";
|
|
|
|
}
|
|
|
|
//if (pos() > 0)
|
|
|
|
// prevAtom()->infoize(os);
|
|
|
|
os << " ";
|
2002-04-02 02:45:23 +00:00
|
|
|
return os.str().c_str(); // .c_str() needed for lyxstring
|
2002-01-16 14:24:38 +00:00
|
|
|
}
|
2002-06-18 15:44:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
unsigned MathCursor::depth() const
|
|
|
|
{
|
|
|
|
return Cursor_.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
void region(MathCursorPos const & i1, MathCursorPos const & i2,
|
|
|
|
MathInset::row_type & r1, MathInset::row_type & r2,
|
|
|
|
MathInset::col_type & c1, MathInset::col_type & c2)
|
|
|
|
{
|
|
|
|
MathInset * p = i1.par_;
|
|
|
|
c1 = p->col(i1.idx_);
|
|
|
|
c2 = p->col(i2.idx_);
|
|
|
|
if (c1 > c2)
|
|
|
|
swap(c1, c2);
|
|
|
|
r1 = p->row(i1.idx_);
|
|
|
|
r2 = p->row(i2.idx_);
|
|
|
|
if (r1 > r2)
|
|
|
|
swap(r1, r2);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathGridInset MathCursor::grabSelection() const
|
|
|
|
{
|
|
|
|
if (!selection_)
|
|
|
|
return MathGridInset();
|
|
|
|
MathCursorPos i1;
|
|
|
|
MathCursorPos i2;
|
|
|
|
getSelection(i1, i2);
|
|
|
|
// shouldn't we assert on i1.par_ == i2.par_?
|
|
|
|
if (i1.idx_ == i2.idx_) {
|
|
|
|
MathGridInset data(1, 1);
|
|
|
|
data.cell(0) = MathArray(i1.cell(), i1.pos_, i2.pos_);
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
row_type r1, r2;
|
|
|
|
col_type c1, c2;
|
|
|
|
region(i1, i2, r1, r2, c1, c2);
|
|
|
|
MathGridInset data(c2 - c1 + 1, r2 - r1 + 1);
|
|
|
|
for (row_type row = 0; row < data.nrows(); ++row)
|
|
|
|
for (col_type col = 0; col < data.ncols(); ++col) {
|
|
|
|
idx_type i = i1.par_->index(row + r1, col + c1);
|
|
|
|
data.cell(data.index(row, col)) = i1.par_->cell(i);
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathCursor::eraseSelection()
|
|
|
|
{
|
|
|
|
MathCursorPos i1;
|
|
|
|
MathCursorPos i2;
|
|
|
|
getSelection(i1, i2);
|
|
|
|
if (i1.idx_ == i2.idx_)
|
|
|
|
i1.cell().erase(i1.pos_, i2.pos_);
|
|
|
|
else {
|
|
|
|
MathInset * p = i1.par_;
|
|
|
|
row_type r1, r2;
|
|
|
|
col_type c1, c2;
|
|
|
|
region(i1, i2, r1, r2, c1, c2);
|
|
|
|
for (row_type row = r1; row <= r2; ++row)
|
|
|
|
for (col_type col = c1; col <= c2; ++col)
|
|
|
|
p->cell(p->index(row, col)).erase();
|
|
|
|
}
|
|
|
|
cursor() = i1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathGridInset MathCursor::grabAndEraseSelection()
|
|
|
|
{
|
|
|
|
if (!selection_)
|
|
|
|
return MathGridInset();
|
|
|
|
MathGridInset res = grabSelection();
|
|
|
|
eraseSelection();
|
|
|
|
selection_ = false;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathCursorPos MathCursor::normalAnchor() const
|
|
|
|
{
|
|
|
|
if (Anchor_.size() < depth()) {
|
|
|
|
Anchor_ = Cursor_;
|
|
|
|
lyxerr << "unusual Anchor size\n";
|
|
|
|
}
|
|
|
|
//lyx::Assert(Anchor_.size() >= cursor.depth());
|
|
|
|
// use Anchor on the same level as Cursor
|
|
|
|
MathCursorPos normal = Anchor_[depth() - 1];
|
|
|
|
if (depth() < Anchor_.size() && !(normal < cursor())) {
|
|
|
|
// anchor is behind cursor -> move anchor behind the inset
|
|
|
|
++normal.pos_;
|
|
|
|
}
|
|
|
|
return normal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathCursor::handleExtern(const string & arg)
|
|
|
|
{
|
|
|
|
string lang;
|
|
|
|
string extra;
|
|
|
|
istringstream iss(arg.c_str());
|
|
|
|
iss >> lang >> extra;
|
|
|
|
if (extra.empty())
|
|
|
|
extra = "noextra";
|
|
|
|
|
|
|
|
|
|
|
|
if (selection()) {
|
|
|
|
MathArray ar;
|
|
|
|
selGet(ar);
|
|
|
|
lyxerr << "use selection: " << ar << "\n";
|
|
|
|
insert(pipeThroughExtern(lang, extra, ar));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MathArray eq;
|
|
|
|
eq.push_back(MathAtom(new MathCharInset('=')));
|
|
|
|
|
|
|
|
popToEnclosingHull();
|
|
|
|
|
|
|
|
idx_type idx = 0;
|
|
|
|
MathHullInset * hull = enclosingHull(idx);
|
|
|
|
lyx::Assert(hull);
|
|
|
|
idxLineFirst();
|
|
|
|
|
|
|
|
if (hull->getType() == LM_OT_SIMPLE) {
|
|
|
|
MathArray::size_type pos = cursor().cell().find_last(eq);
|
|
|
|
MathArray ar;
|
|
|
|
if (pos == size()) {
|
|
|
|
ar = array();
|
|
|
|
lyxerr << "use whole cell: " << ar << "\n";
|
|
|
|
} else {
|
|
|
|
ar = MathArray(array(), pos + 1, size());
|
|
|
|
lyxerr << "use partial cell form pos: " << pos << "\n";
|
|
|
|
}
|
|
|
|
end();
|
|
|
|
insert(eq);
|
|
|
|
insert(pipeThroughExtern(lang, extra, ar));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hull->getType() == LM_OT_EQUATION) {
|
|
|
|
lyxerr << "use equation inset\n";
|
|
|
|
hull->mutate(LM_OT_EQNARRAY);
|
|
|
|
MathArray & ar = cursor().cell();
|
|
|
|
lyxerr << "use cell: " << ar << "\n";
|
|
|
|
idxRight();
|
|
|
|
cursor().cell() = eq;
|
|
|
|
idxRight();
|
|
|
|
cursor().cell() = pipeThroughExtern(lang, extra, ar);
|
|
|
|
idxLineLast();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
lyxerr << "use eqnarray\n";
|
|
|
|
idxLineLast();
|
|
|
|
MathArray ar = cursor().cell();
|
|
|
|
lyxerr << "use cell: " << ar << "\n";
|
|
|
|
breakLine();
|
|
|
|
idxRight();
|
|
|
|
cursor().cell() = eq;
|
|
|
|
idxRight();
|
|
|
|
cursor().cell() = pipeThroughExtern(lang, extra, ar);
|
|
|
|
idxLineLast();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|