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
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
2001-02-14 17:58:40 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#include <config.h>
|
2001-07-06 12:09:32 +00:00
|
|
|
#include <cctype>
|
2001-06-25 00:06:33 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "math_inset.h"
|
|
|
|
#include "math_parser.h"
|
|
|
|
#include "math_cursor.h"
|
|
|
|
#include "math_macro.h"
|
2001-04-24 16:13:38 +00:00
|
|
|
#include "math_macroarg.h"
|
2001-02-13 17:08:51 +00:00
|
|
|
#include "math_macrotable.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "math_root.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/lstrings.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
2000-02-10 17:53:36 +00:00
|
|
|
#include "LColor.h"
|
|
|
|
#include "Painter.h"
|
2001-02-13 13:28:32 +00:00
|
|
|
#include "math_matrixinset.h"
|
2001-06-27 14:10:35 +00:00
|
|
|
#include "math_grid.h"
|
2001-02-13 13:28:32 +00:00
|
|
|
#include "math_spaceinset.h"
|
|
|
|
#include "math_funcinset.h"
|
|
|
|
#include "math_bigopinset.h"
|
|
|
|
#include "math_fracinset.h"
|
|
|
|
#include "math_decorationinset.h"
|
|
|
|
#include "math_dotsinset.h"
|
|
|
|
#include "math_accentinset.h"
|
2001-03-01 14:07:43 +00:00
|
|
|
#include "math_macrotemplate.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "math_sqrtinset.h"
|
|
|
|
#include "math_scriptinset.h"
|
2001-02-13 19:10:18 +00:00
|
|
|
#include "mathed/support.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "formulabase.h"
|
2001-04-24 16:13:38 +00:00
|
|
|
|
|
|
|
|
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-07-06 12:09:32 +00:00
|
|
|
using std::isalnum;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
namespace {
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathArray selarray;
|
2001-03-20 01:22:46 +00:00
|
|
|
|
2000-03-07 01:14:37 +00:00
|
|
|
bool IsMacro(short tok, int id)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-02-14 17:58:40 +00:00
|
|
|
return tok != LM_TK_STACK &&
|
|
|
|
tok != LM_TK_FRAC &&
|
|
|
|
tok != LM_TK_SQRT &&
|
|
|
|
tok != LM_TK_WIDE &&
|
|
|
|
tok != LM_TK_SPACE &&
|
|
|
|
tok != LM_TK_DOTS &&
|
|
|
|
tok != LM_TK_FUNCLIM &&
|
|
|
|
tok != LM_TK_BIGSYM &&
|
|
|
|
tok != LM_TK_ACCENT &&
|
|
|
|
!(tok == LM_TK_SYM && id < 255);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2001-04-24 16:13:38 +00:00
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathCursor::MathCursor(InsetFormulaBase * formula)
|
|
|
|
: formula_(formula)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-04-24 16:13:38 +00:00
|
|
|
accent = 0;
|
|
|
|
lastcode = LM_TC_MIN;
|
2001-06-25 00:06:33 +00:00
|
|
|
macro_mode = false;
|
|
|
|
first();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
void MathCursor::push(MathInset * par, bool first)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
path_.push_back(MathIter());
|
|
|
|
path_.back().par_ = par_;
|
|
|
|
path_.back().idx_ = idx_;
|
|
|
|
path_.back().cursor_ = cursor_;
|
|
|
|
dump("Pushed:");
|
|
|
|
par_ = par;
|
|
|
|
first ? par_->idxFirst(idx_, cursor_) : par_->idxLast(idx_, cursor_);
|
2001-04-24 16:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
bool MathCursor::pop()
|
2001-04-24 16:13:38 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
if (path_.empty())
|
2001-06-27 14:10:35 +00:00
|
|
|
return false;
|
2001-06-25 00:06:33 +00:00
|
|
|
par_ = path_.back().par_;
|
|
|
|
idx_ = path_.back().idx_;
|
|
|
|
cursor_ = path_.back().cursor_;
|
|
|
|
dump("Popped:");
|
|
|
|
path_.pop_back();
|
2001-06-27 14:10:35 +00:00
|
|
|
return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathInset * MathCursor::parInset(int i) const
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return path_[i].par_;
|
|
|
|
}
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathCursor::dump(char const * what) const
|
|
|
|
{
|
2001-07-06 12:09:32 +00:00
|
|
|
return;
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
lyxerr << "MC: " << what
|
|
|
|
<< " cursor: " << cursor_
|
|
|
|
<< " anchor: " << anchor_
|
|
|
|
<< " idx: " << idx_
|
|
|
|
<< " par: " << par_
|
|
|
|
<< " sel: " << selection
|
|
|
|
<< " data: " << array()
|
|
|
|
<< "\n";
|
|
|
|
}
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathCursor::seldump(char const * str) const
|
|
|
|
{
|
|
|
|
lyxerr << "SEL: " << str << ": '" << selarray << "'\n";
|
|
|
|
dump(" Pos");
|
|
|
|
return;
|
|
|
|
|
|
|
|
lyxerr << "\n\n\\n=================vvvvvvvvvvvvv======================= "
|
|
|
|
<< str << "\nselarray: " << selarray;
|
|
|
|
for (unsigned int i = 0; i < path_.size(); ++i)
|
|
|
|
lyxerr << path_[i].par_ << "\n'" << path_[i].par_->cell(0) << "'\n";
|
|
|
|
lyxerr << "\ncursor: " << cursor_;
|
|
|
|
lyxerr << "\nanchor: " << anchor_;
|
|
|
|
lyxerr << "\n===================^^^^^^^^^^^^=====================\n\n\n";
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
bool MathCursor::isInside(MathInset * p) const
|
2001-02-14 17:58:40 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
for (unsigned i = 0; i < path_.size(); ++i)
|
|
|
|
if (parInset(i) == p)
|
|
|
|
return true;
|
|
|
|
return par_ == p;
|
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-06-25 00:06:33 +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");
|
2001-02-14 17:58:40 +00:00
|
|
|
if (macro_mode) {
|
2001-02-14 19:35:25 +00:00
|
|
|
// was MacroModeBack()
|
2001-06-25 00:06:33 +00:00
|
|
|
if (!imacro->name().empty()) {
|
|
|
|
imacro->SetName(imacro->name().substr(0, imacro->name().length()-1));
|
|
|
|
imacro->Metrics(imacro->size());
|
2001-02-14 19:35:25 +00:00
|
|
|
} else
|
|
|
|
MacroModeClose();
|
2001-02-14 17:58:40 +00:00
|
|
|
return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-02-14 17:58:40 +00:00
|
|
|
clearLastCode();
|
2001-06-25 00:06:33 +00:00
|
|
|
SelHandle(sel);
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
bool result = false;
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
if (selection) {
|
|
|
|
result = array().prev(cursor_);
|
2001-06-27 14:10:35 +00:00
|
|
|
if (!result && pop()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
anchor_ = cursor_;
|
|
|
|
result = array().next(anchor_);
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
} else {
|
2001-07-06 12:09:32 +00:00
|
|
|
MathInset * p = prevInset();
|
|
|
|
if (p && p->isActive()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
// We have to move deeper into the previous inset
|
|
|
|
array().prev(cursor_);
|
|
|
|
push(p, false);
|
|
|
|
result = true;
|
|
|
|
} else {
|
|
|
|
// The common case, where we are not
|
|
|
|
// entering a deeper inset
|
|
|
|
result = array().prev(cursor_);
|
|
|
|
if (!result) {
|
|
|
|
if (par_->idxLeft(idx_, cursor_)) {
|
|
|
|
result = true;
|
2001-06-27 14:10:35 +00:00
|
|
|
} else if (pop()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
}
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
dump("Left 2");
|
2001-02-14 17:58:40 +00:00
|
|
|
return result;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
bool MathCursor::plainRight()
|
|
|
|
{
|
|
|
|
return array().next(cursor_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +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");
|
2001-02-14 17:58:40 +00:00
|
|
|
if (macro_mode) {
|
|
|
|
MacroModeClose();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
clearLastCode();
|
2001-06-25 00:06:33 +00:00
|
|
|
SelHandle(sel);
|
2001-02-14 17:58:40 +00:00
|
|
|
|
|
|
|
bool result = false;
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
if (selection) {
|
|
|
|
result = array().next(cursor_);
|
2001-06-27 14:10:35 +00:00
|
|
|
if (!result && pop()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
anchor_ = cursor_;
|
2001-06-27 14:10:35 +00:00
|
|
|
result = array().next(cursor_);
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
|
|
|
} else {
|
2001-07-06 12:09:32 +00:00
|
|
|
MathInset * p = nextInset();
|
|
|
|
if (p && p->isActive()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
push(p, true);
|
2001-02-14 17:58:40 +00:00
|
|
|
result = true;
|
2001-06-25 00:06:33 +00:00
|
|
|
} else {
|
|
|
|
result = array().next(cursor_);
|
|
|
|
if (!result) {
|
|
|
|
if (par_->idxRight(idx_, cursor_)) {
|
|
|
|
result = true;
|
2001-06-27 14:10:35 +00:00
|
|
|
} else if (pop()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
result = true;
|
|
|
|
array().next(cursor_);
|
|
|
|
}
|
|
|
|
}
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
dump("Right 2");
|
2001-02-14 17:58:40 +00:00
|
|
|
return result;
|
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-06-25 00:06:33 +00:00
|
|
|
selection = false;
|
|
|
|
par_ = formula_->par();
|
|
|
|
idx_ = 0;
|
|
|
|
cursor_ = 0;
|
|
|
|
anchor_ = 0;
|
|
|
|
par_->idxFirst(idx_, cursor_);
|
|
|
|
}
|
2001-02-14 17:58:40 +00:00
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathCursor::last()
|
|
|
|
{
|
|
|
|
selection = false;
|
|
|
|
par_ = formula_->par();
|
|
|
|
idx_ = 0;
|
|
|
|
cursor_ = 0;
|
|
|
|
anchor_ = 0;
|
|
|
|
par_->idxLast(idx_, cursor_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathCursor::SetPos(int x, int y)
|
|
|
|
{
|
|
|
|
dump("SetPos 1");
|
2001-07-06 12:09:32 +00:00
|
|
|
//lyxerr << "MathCursor::SetPos x: " << x << " y: " << y << "\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
MacroModeClose();
|
2001-02-14 17:58:40 +00:00
|
|
|
lastcode = LM_TC_MIN;
|
2001-06-25 00:06:33 +00:00
|
|
|
path_.clear();
|
|
|
|
|
|
|
|
par_ = formula()->par();
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
idx_ = -1;
|
|
|
|
cursor_ = -1;
|
2001-07-06 12:09:32 +00:00
|
|
|
//lyxerr << "found idx: " << idx_ << " cursor: " << cursor_ << "\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
int distmin = 1 << 30; // large enough
|
|
|
|
for (int i = 0; i < par_->nargs(); ++i) {
|
|
|
|
MathXArray const & ar = par_->xcell(i);
|
|
|
|
int x1 = x - ar.xo();
|
|
|
|
int y1 = y - ar.yo();
|
|
|
|
int c = ar.x2pos(x1);
|
|
|
|
int xx = abs(x1 - ar.pos2x(c));
|
|
|
|
int yy = abs(y1);
|
|
|
|
//lyxerr << "idx: " << i << " xx: " << xx << " yy: " << yy
|
|
|
|
// << " c: " << c << " xo: " << ar.xo() << "\n";
|
|
|
|
if (yy + xx <= distmin) {
|
|
|
|
distmin = yy + xx;
|
|
|
|
idx_ = i;
|
|
|
|
cursor_ = c;
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
lyxerr << "found idx: " << idx_ << " cursor: " << cursor_ << "\n";
|
2001-07-06 12:09:32 +00:00
|
|
|
MathInset * n = nextInset();
|
|
|
|
MathInset * p = prevInset();
|
|
|
|
if (n && (n->isActive() || n->isScriptInset()) && n->covers(x, y))
|
|
|
|
push(n, true);
|
|
|
|
else if (p && (p->isActive() || p->isScriptInset()) && p->covers(x, y)) {
|
2001-06-25 00:06:33 +00:00
|
|
|
array().prev(cursor_);
|
|
|
|
push(p, false);
|
|
|
|
} else
|
2001-02-14 17:58:40 +00:00
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
dump("SetPos 2");
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-02-14 17:58:40 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathCursor::Home()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
dump("Home 1");
|
2001-02-14 17:58:40 +00:00
|
|
|
if (macro_mode)
|
|
|
|
MacroModeClose();
|
|
|
|
clearLastCode();
|
2001-06-25 00:06:33 +00:00
|
|
|
if (!par_->idxHome(idx_, cursor_)) {
|
|
|
|
pop();
|
|
|
|
}
|
|
|
|
dump("Home 2");
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathCursor::End()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
dump("End 1");
|
2001-02-14 17:58:40 +00:00
|
|
|
if (macro_mode)
|
|
|
|
MacroModeClose();
|
|
|
|
clearLastCode();
|
2001-06-25 00:06:33 +00:00
|
|
|
if (!par_->idxEnd(idx_, cursor_)) {
|
|
|
|
pop();
|
|
|
|
array().next(cursor_);
|
2001-02-03 21:02:22 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
dump("End 2");
|
2001-02-03 21:02:22 +00:00
|
|
|
}
|
|
|
|
|
2001-02-13 19:10:18 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
void MathCursor::insert(char c, MathTextCodes t)
|
2001-02-14 17:58:40 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
lyxerr << "inserting '" << c << "'\n";
|
2001-02-14 17:58:40 +00:00
|
|
|
if (selection)
|
|
|
|
SelDel();
|
|
|
|
|
|
|
|
if (t == LM_TC_MIN)
|
|
|
|
t = lastcode;
|
|
|
|
|
|
|
|
if (macro_mode && !(MathIsAlphaFont(t) || t == LM_TC_MIN))
|
|
|
|
MacroModeClose();
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
if (macro_mode) {
|
|
|
|
if (MathIsAlphaFont(t) || t == LM_TC_MIN) {
|
|
|
|
// was MacroModeinsert(c);
|
|
|
|
imacro->SetName(imacro->name() + static_cast<char>(c));
|
|
|
|
return;
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
if (accent)
|
|
|
|
doAccent(c, t);
|
|
|
|
else {
|
|
|
|
array().insert(cursor_, c, t);
|
|
|
|
array().next(cursor_);
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
lastcode = t;
|
|
|
|
return;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathCursor::insert(MathInset * p)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
MacroModeClose();
|
2001-02-14 17:58:40 +00:00
|
|
|
|
|
|
|
if (selection) {
|
2001-06-25 00:06:33 +00:00
|
|
|
if (p->nargs())
|
2001-02-14 17:58:40 +00:00
|
|
|
SelCut();
|
2001-06-25 00:06:33 +00:00
|
|
|
else
|
2001-02-14 17:58:40 +00:00
|
|
|
SelDel();
|
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
if (accent && !p->nargs())
|
|
|
|
doAccent(p);
|
|
|
|
else {
|
|
|
|
array().insert(cursor_, p);
|
|
|
|
array().next(cursor_);
|
|
|
|
}
|
|
|
|
|
|
|
|
//if (p->nargs())
|
|
|
|
// push(p, true);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathCursor::Delete()
|
2001-02-14 17:58:40 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
dump("Delete 1");
|
2001-02-14 17:58:40 +00:00
|
|
|
if (macro_mode)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (selection) {
|
|
|
|
SelDel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
if (cursor_ < array().size())
|
|
|
|
array().erase(cursor_);
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
// delete empty cells parts if necessary
|
|
|
|
if (cursor_ == 0 && array().size() == 0) {
|
|
|
|
bool removeit = par_->idxDelete(idx_);
|
|
|
|
if (pop() && removeit)
|
|
|
|
Delete();
|
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
#warning pullArg disabled
|
|
|
|
#endif
|
|
|
|
//if (cursor_ == 0 && !path_.empty()) {
|
|
|
|
// lyxerr << "Delete: popping...\n";
|
|
|
|
// pop();
|
|
|
|
//}
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
dump("Delete 2");
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathCursor::DelLine()
|
2001-02-14 17:58:40 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
MacroModeClose();
|
2001-02-14 17:58:40 +00:00
|
|
|
|
|
|
|
if (selection) {
|
|
|
|
SelDel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
if (par_->nrows() > 1)
|
|
|
|
par_->delRow(row());
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
bool MathCursor::Up(bool sel)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
dump("Up 1");
|
|
|
|
MacroModeClose();
|
|
|
|
SelHandle(sel);
|
|
|
|
SelClear();
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
// check whether we could move into an inset on the right or on the left
|
|
|
|
MathInset * p = nextInset();
|
|
|
|
if (p) {
|
|
|
|
int idx, cursor;
|
|
|
|
if (p->idxFirstUp(idx, cursor)) {
|
|
|
|
push(p, true);
|
|
|
|
par_ = p;
|
|
|
|
idx_ = idx;
|
|
|
|
cursor_ = cursor;
|
|
|
|
dump("Up 3");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p = prevInset();
|
|
|
|
if (p) {
|
|
|
|
int idx, cursor;
|
|
|
|
if (p->idxLastUp(idx, cursor)) {
|
|
|
|
array().prev(cursor_);
|
|
|
|
push(p, false);
|
|
|
|
par_ = p;
|
|
|
|
idx_ = idx;
|
|
|
|
cursor_ = cursor;
|
|
|
|
dump("Up 4");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
int x = xarray().pos2x(cursor_);
|
|
|
|
bool result = par_->idxUp(idx_, cursor_);
|
2001-06-27 14:10:35 +00:00
|
|
|
if (!result && pop()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
result = par_->idxUp(idx_, cursor_);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
cursor_ = xarray().x2pos(x);
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
dump("Up 2");
|
2001-02-14 17:58:40 +00:00
|
|
|
return result;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
bool MathCursor::Down(bool sel)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
dump("Down 1");
|
|
|
|
MacroModeClose();
|
|
|
|
SelHandle(sel);
|
|
|
|
SelClear();
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
// check whether we could move into an inset on the right or on the left
|
|
|
|
MathInset * p = nextInset();
|
|
|
|
if (p) {
|
|
|
|
int idx, cursor;
|
|
|
|
if (p->idxFirstDown(idx, cursor)) {
|
|
|
|
push(p, true);
|
|
|
|
idx_ = idx;
|
|
|
|
cursor_ = cursor;
|
|
|
|
dump("Down 3");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p = prevInset();
|
|
|
|
if (p) {
|
|
|
|
int idx, cursor;
|
|
|
|
if (p->idxLastDown(idx, cursor)) {
|
|
|
|
array().prev(cursor_);
|
|
|
|
push(p, false);
|
|
|
|
idx_ = idx;
|
|
|
|
cursor_ = cursor;
|
|
|
|
dump("Down 4");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
int x = xarray().pos2x(cursor_);
|
|
|
|
bool result = par_->idxDown(idx_, cursor_);
|
2001-06-27 14:10:35 +00:00
|
|
|
if (!result && pop()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
result = par_->idxDown(idx_, cursor_);
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
cursor_ = xarray().x2pos(x);
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
dump("Down 2");
|
2001-02-14 17:58:40 +00:00
|
|
|
return result;
|
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-06-25 00:06:33 +00:00
|
|
|
if (!prevIsInset())
|
|
|
|
return false;
|
|
|
|
MathInset * p = prevInset();
|
2001-06-27 14:10:35 +00:00
|
|
|
int old = p->limits();
|
|
|
|
p->limits(old == -1 ? 1 : -1);
|
|
|
|
return old != p->limits();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathCursor::SetSize(MathStyles size)
|
2001-02-14 17:58:40 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
par_->UserSetSize(size);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathCursor::Interpret(string const & s)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
lyxerr << "Interpret: '" << s << "'\n";
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
if (s[0] == '^') {
|
2001-06-27 14:10:35 +00:00
|
|
|
MathScriptInset * p = nearbyScriptInset();
|
2001-06-25 00:06:33 +00:00
|
|
|
if (!p) {
|
|
|
|
p = new MathScriptInset;
|
|
|
|
insert(p);
|
2001-06-27 14:10:35 +00:00
|
|
|
array().prev(cursor_);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
2001-06-27 14:10:35 +00:00
|
|
|
push(p, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
if (!p->up())
|
|
|
|
p->up(true);
|
2001-06-27 14:10:35 +00:00
|
|
|
idx_ = 0;
|
2001-06-25 00:06:33 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
if (s[0] == '_') {
|
2001-06-27 14:10:35 +00:00
|
|
|
MathScriptInset * p = nearbyScriptInset();
|
2001-06-25 00:06:33 +00:00
|
|
|
if (!p) {
|
|
|
|
p = new MathScriptInset;
|
|
|
|
insert(p);
|
2001-06-27 14:10:35 +00:00
|
|
|
array().prev(cursor_);
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
2001-06-27 14:10:35 +00:00
|
|
|
push(p, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
if (!p->down())
|
|
|
|
p->down(true);
|
2001-06-27 14:10:35 +00:00
|
|
|
idx_ = 1;
|
1999-09-27 18:44:28 +00:00
|
|
|
return;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2001-02-14 17:58:40 +00:00
|
|
|
if (s[0] == '!' || s[0] == ',' || s[0] == ':' || s[0] == ';') {
|
2001-06-25 00:06:33 +00:00
|
|
|
int sp = (s[0] == ',') ? 1:((s[0] == ':') ? 2:((s[0] == ';') ? 3: 0));
|
|
|
|
insert(new MathSpaceInset(sp));
|
2001-02-14 17:58:40 +00:00
|
|
|
return;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MathInset * p = 0;
|
|
|
|
latexkeys const * l = in_word_set(s);
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
if (l == 0) {
|
2001-06-25 00:06:33 +00:00
|
|
|
if (s == "root")
|
|
|
|
p = new MathRootInset;
|
|
|
|
else if (MathMacroTable::hasTemplate(s))
|
|
|
|
p = new MathMacro(MathMacroTable::provideTemplate(s));
|
|
|
|
else
|
|
|
|
p = new MathFuncInset(s, LM_OT_UNDEF);
|
1999-09-27 18:44:28 +00:00
|
|
|
} else {
|
2001-02-14 17:58:40 +00:00
|
|
|
switch (l->token) {
|
|
|
|
case LM_TK_BIGSYM:
|
|
|
|
p = new MathBigopInset(l->name, l->id);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_SYM:
|
2001-06-27 14:10:35 +00:00
|
|
|
if (l->id < 255) {
|
|
|
|
insert(static_cast<byte>(l->id),
|
|
|
|
MathIsBOPS(l->id) ?
|
|
|
|
LM_TC_BOPS : LM_TC_SYMB);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
p = new MathFuncInset(l->name);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2001-02-14 17:58:40 +00:00
|
|
|
case LM_TK_STACK:
|
2001-06-25 00:06:33 +00:00
|
|
|
p = new MathFracInset(LM_OT_STACKREL);
|
|
|
|
break;
|
2001-02-14 17:58:40 +00:00
|
|
|
|
|
|
|
case LM_TK_FRAC:
|
2001-06-25 00:06:33 +00:00
|
|
|
p = new MathFracInset(LM_OT_FRAC);
|
2001-02-14 17:58:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_SQRT:
|
|
|
|
p = new MathSqrtInset;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_WIDE:
|
|
|
|
p = new MathDecorationInset(l->id);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_FUNCLIM:
|
|
|
|
p = new MathFuncInset(l->name, LM_OT_FUNCLIM);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_SPACE:
|
|
|
|
p = new MathSpaceInset(l->id);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_DOTS:
|
|
|
|
p = new MathDotsInset(l->name, l->id);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_ACCENT:
|
|
|
|
setAccent(l->id);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_MACRO:
|
2001-04-24 16:13:38 +00:00
|
|
|
p = new MathMacro(MathMacroTable::provideTemplate(s));
|
2001-02-14 17:58:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
p = new MathFuncInset(l->name);
|
|
|
|
break;
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-02-14 17:58:40 +00:00
|
|
|
|
|
|
|
if (p) {
|
2001-07-06 12:09:32 +00:00
|
|
|
bool oldsel = selection;
|
|
|
|
if (oldsel)
|
|
|
|
SelCut();
|
2001-06-25 00:06:33 +00:00
|
|
|
insert(p);
|
|
|
|
if (p->nargs()) {
|
|
|
|
array().prev(cursor_);
|
|
|
|
push(p, true);
|
2001-07-06 12:09:32 +00:00
|
|
|
if (oldsel)
|
|
|
|
SelPaste();
|
2001-02-20 14:00:34 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
p->Metrics(p->size());
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathCursor::MacroModeOpen()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-02-14 17:58:40 +00:00
|
|
|
if (!macro_mode) {
|
|
|
|
imacro = new MathFuncInset("");
|
2001-06-25 00:06:33 +00:00
|
|
|
insert(imacro);
|
2001-02-14 17:58:40 +00:00
|
|
|
macro_mode = true;
|
|
|
|
} else
|
2001-06-25 00:06:33 +00:00
|
|
|
lyxerr << "Math Warning: Already in macro mode" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathCursor::MacroModeClose()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-02-14 17:58:40 +00:00
|
|
|
if (macro_mode) {
|
|
|
|
macro_mode = false;
|
2001-06-25 00:06:33 +00:00
|
|
|
latexkeys const * l = in_word_set(imacro->name());
|
|
|
|
if (!imacro->name().empty()
|
|
|
|
&& (!l || (l && IsMacro(l->token, l->id)))
|
|
|
|
&& !MathMacroTable::hasTemplate(imacro->name()))
|
2001-04-24 16:13:38 +00:00
|
|
|
{
|
2001-02-14 17:58:40 +00:00
|
|
|
if (!l) {
|
|
|
|
//imacro->SetName(macrobf);
|
|
|
|
// This guarantees that the string will be removed by destructor
|
|
|
|
imacro->SetType(LM_OT_UNDEF);
|
|
|
|
} else
|
|
|
|
imacro->SetName(l->name);
|
|
|
|
} else {
|
|
|
|
Left();
|
2001-06-25 00:06:33 +00:00
|
|
|
if (nextInset()->GetType() == LM_OT_ACCENT)
|
2001-02-14 17:58:40 +00:00
|
|
|
setAccent(
|
2001-06-25 00:06:33 +00:00
|
|
|
static_cast<MathAccentInset*>(nextInset())->getAccentCode());
|
|
|
|
array().erase(cursor_);
|
|
|
|
if (l || MathMacroTable::hasTemplate(imacro->name()))
|
|
|
|
Interpret(imacro->name());
|
|
|
|
imacro->SetName(string());
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
|
|
|
imacro = 0;
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathCursor::SelCopy()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
seldump("SelCopy");
|
2001-02-14 17:58:40 +00:00
|
|
|
if (selection) {
|
2001-06-25 00:06:33 +00:00
|
|
|
int const p1 = min(cursor_, anchor_);
|
|
|
|
int const p2 = max(cursor_, anchor_);
|
|
|
|
selarray = array();
|
|
|
|
selarray.erase(p2, selarray.size());
|
|
|
|
selarray.erase(0, p1);
|
2001-02-14 17:58:40 +00:00
|
|
|
SelClear();
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathCursor::selArray(MathArray & ar) const
|
|
|
|
{
|
|
|
|
int const p1 = min(cursor_, anchor_);
|
|
|
|
int const p2 = max(cursor_, anchor_);
|
|
|
|
ar = array();
|
|
|
|
ar.erase(p2, ar.size());
|
|
|
|
ar.erase(0, p1);
|
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathCursor::SelCut()
|
2001-02-14 17:58:40 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
seldump("SelCut");
|
2001-02-14 17:58:40 +00:00
|
|
|
if (selection) {
|
2001-06-25 00:06:33 +00:00
|
|
|
int const p1 = min(cursor_, anchor_);
|
|
|
|
int const p2 = max(cursor_, anchor_);
|
|
|
|
cursor_ = p1; // move cursor to a same position
|
|
|
|
selarray = array();
|
|
|
|
selarray.erase(p2, selarray.size());
|
|
|
|
selarray.erase(0, p1);
|
|
|
|
array().erase(p1, p2);
|
2001-02-14 17:58:40 +00:00
|
|
|
SelClear();
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathCursor::SelDel()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
seldump("SelDel");
|
2001-02-14 17:58:40 +00:00
|
|
|
if (selection) {
|
2001-06-25 00:06:33 +00:00
|
|
|
int const p1 = min(cursor_, anchor_);
|
|
|
|
int const p2 = max(cursor_, anchor_);
|
|
|
|
array().erase(p1, p2);
|
2001-02-14 17:58:40 +00:00
|
|
|
SelClear();
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathCursor::SelPaste()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
seldump("SelPaste");
|
|
|
|
array().insert(cursor_, selarray);
|
|
|
|
cursor_ += selarray.size();
|
|
|
|
SelClear();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathCursor::SelHandle(bool sel)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
if (sel && !selection)
|
|
|
|
SelStart();
|
|
|
|
if (!sel && selection)
|
|
|
|
SelClear();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathCursor::SelStart()
|
2001-02-14 17:58:40 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
seldump("SelStart");
|
|
|
|
if (selection)
|
|
|
|
return;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
anchor_ = cursor_;
|
|
|
|
selection = true;
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathCursor::SelClear()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
selection = false;
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathCursor::SelGetArea(int * xpoint, int * ypoint, int & n)
|
|
|
|
{
|
2001-02-14 17:58:40 +00:00
|
|
|
if (!selection) {
|
2001-06-25 00:06:33 +00:00
|
|
|
n = 0;
|
2001-02-14 17:58:40 +00:00
|
|
|
xpoint[0] = 0;
|
|
|
|
ypoint[0] = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Balance anchor and cursor
|
|
|
|
int xo;
|
|
|
|
int yo;
|
2001-06-25 00:06:33 +00:00
|
|
|
par()->GetXY(xo, yo);
|
|
|
|
int w = par()->width();
|
|
|
|
// cursor
|
|
|
|
int x1 = xarray().xo() + xarray().pos2x(cursor_);
|
|
|
|
int y1 = xarray().yo();
|
|
|
|
//int a1 = xarray().ascent();
|
|
|
|
//int d1 = xarray().descent();
|
|
|
|
|
|
|
|
// anchor
|
|
|
|
int x = xarray().xo() + xarray().pos2x(anchor_);
|
|
|
|
int y = xarray().yo();
|
|
|
|
int a = xarray().ascent();
|
|
|
|
int d = xarray().descent();
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-02-17 18:52:53 +00:00
|
|
|
// single row selection
|
2001-06-25 00:06:33 +00:00
|
|
|
n = 0;
|
|
|
|
xpoint[n] = x;
|
|
|
|
ypoint[n++] = y + d;
|
|
|
|
xpoint[n] = x;
|
|
|
|
ypoint[n++] = y - a;
|
2001-02-14 17:58:40 +00:00
|
|
|
|
|
|
|
if (y != y1) {
|
2001-06-25 00:06:33 +00:00
|
|
|
xpoint[n] = xo + w;
|
|
|
|
ypoint[n++] = y - a;
|
2001-02-14 17:58:40 +00:00
|
|
|
|
|
|
|
if (x1 < xo + w) {
|
2001-06-25 00:06:33 +00:00
|
|
|
xpoint[n] = xo + w;
|
|
|
|
ypoint[n++] = y1 - a;
|
|
|
|
}
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
xpoint[n] = x1;
|
|
|
|
ypoint[n++] = y1 - a;
|
|
|
|
xpoint[n] = x1;
|
|
|
|
ypoint[n++] = y1 + d;
|
2001-02-14 17:58:40 +00:00
|
|
|
|
|
|
|
if (y != y1) {
|
2001-06-25 00:06:33 +00:00
|
|
|
xpoint[n] = xo;
|
|
|
|
ypoint[n++] = y1 + d;
|
2001-02-14 17:58:40 +00:00
|
|
|
if (x > xo) {
|
2001-06-25 00:06:33 +00:00
|
|
|
xpoint[n] = xo;
|
|
|
|
ypoint[n++] = y + d;
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
xpoint[n] = xpoint[0];
|
|
|
|
ypoint[n++] = ypoint[0];
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
//lyxerr << "AN[" << x << " " << y << " " << x1 << " " << y1 << "]\n";
|
|
|
|
//lyxerr << "MT[" << a << " " << d << " " << a1 << " " << d1 << "]\n";
|
|
|
|
//for (i = 0; i < np; ++i)
|
|
|
|
// lyxerr << "XY[" << xpoint[i] << " " << ypoint[i] << "]\n";
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathCursor::setAccent(int ac)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-04-24 16:13:38 +00:00
|
|
|
if (ac > 0 && accent < 8)
|
1999-09-27 18:44:28 +00:00
|
|
|
nestaccent[accent++] = ac;
|
2001-04-24 16:13:38 +00:00
|
|
|
else
|
2001-02-14 17:58:40 +00:00
|
|
|
accent = 0; // consumed!
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
int MathCursor::getAccent() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return accent > 0 ? nestaccent[accent - 1] : 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathCursor::doAccent(char c, MathTextCodes t)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
MathInset * ac = 0;
|
2001-02-14 17:58:40 +00:00
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
for (int i = accent - 1; i >= 0; --i) {
|
|
|
|
if (i == accent - 1)
|
2001-02-14 17:58:40 +00:00
|
|
|
ac = new MathAccentInset(c, t, nestaccent[i]);
|
|
|
|
else
|
|
|
|
ac = new MathAccentInset(ac, nestaccent[i]);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2001-02-14 17:58:40 +00:00
|
|
|
if (ac)
|
2001-06-25 00:06:33 +00:00
|
|
|
insert(ac);
|
2001-02-14 17:58:40 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
accent = 0; // consumed!
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathCursor::doAccent(MathInset * p)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
MathInset * ac = 0;
|
2001-02-14 17:58:40 +00:00
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
for (int i = accent - 1; i >= 0; --i) {
|
|
|
|
if (i == accent - 1)
|
2001-02-14 17:58:40 +00:00
|
|
|
ac = new MathAccentInset(p, nestaccent[i]);
|
|
|
|
else
|
|
|
|
ac = new MathAccentInset(ac, nestaccent[i]);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-02-14 17:58:40 +00:00
|
|
|
|
|
|
|
if (ac)
|
2001-06-25 00:06:33 +00:00
|
|
|
insert(ac);
|
2001-02-14 17:58:40 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
accent = 0; // consumed!
|
|
|
|
}
|
|
|
|
|
2001-01-09 13:58:48 +00:00
|
|
|
|
2001-07-03 07:56:55 +00:00
|
|
|
void MathCursor::handleFont(MathTextCodes t)
|
|
|
|
{
|
|
|
|
if (selection) {
|
|
|
|
int const p1 = std::min(cursor_, anchor_);
|
|
|
|
int const p2 = std::max(cursor_, anchor_);
|
2001-07-06 12:09:32 +00:00
|
|
|
MathArray & ar = array();
|
|
|
|
for (int pos = p1; pos != p2; ar.next(pos))
|
|
|
|
if (!ar.isInset(pos) && isalnum(ar.GetChar(pos))) {
|
|
|
|
MathTextCodes c = ar.GetCode(pos) == t ? LM_TC_VAR : t;
|
|
|
|
ar.setCode(pos, c);
|
2001-07-03 07:56:55 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (lastcode == t)
|
|
|
|
lastcode = LM_TC_VAR;
|
|
|
|
else
|
|
|
|
lastcode = t;
|
|
|
|
}
|
2001-01-09 13:58:48 +00:00
|
|
|
}
|
2001-02-13 19:10:18 +00:00
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathCursor::GetPos(int & x, int & y)
|
2001-02-13 19:10:18 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
x = xarray().xo() + xarray().pos2x(cursor_);
|
|
|
|
y = xarray().yo();
|
2001-02-13 19:10:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathTextCodes MathCursor::nextCode() const
|
2001-02-13 19:10:18 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return array().GetCode(cursor_);
|
2001-02-13 19:10:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathTextCodes MathCursor::prevCode() const
|
2001-02-13 19:10:18 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return array().GetCode(cursor_ - 1);
|
2001-02-13 19:10:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathInset * MathCursor::par() const
|
2001-02-13 19:10:18 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return par_;
|
2001-02-13 19:10:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
InsetFormulaBase const * 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-06-25 00:06:33 +00:00
|
|
|
int MathCursor::pos() const
|
2001-02-13 19:10:18 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return cursor_;
|
2001-02-13 19:10:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
bool MathCursor::InMacroMode() const
|
2001-02-13 19:10:18 +00:00
|
|
|
{
|
|
|
|
return macro_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
bool MathCursor::Selection() const
|
2001-02-13 19:10:18 +00:00
|
|
|
{
|
|
|
|
return selection;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathCursor::clearLastCode()
|
2001-02-13 19:10:18 +00:00
|
|
|
{
|
|
|
|
lastcode = LM_TC_MIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathCursor::setLastCode(MathTextCodes t)
|
2001-02-13 19:10:18 +00:00
|
|
|
{
|
|
|
|
lastcode = t;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathTextCodes MathCursor::getLastCode() const
|
2001-02-13 19:10:18 +00:00
|
|
|
{
|
|
|
|
return lastcode;
|
|
|
|
}
|
2001-04-24 16:13:38 +00:00
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathInset * MathCursor::enclosing(MathInsetTypes t, int & idx) const
|
|
|
|
{
|
|
|
|
if (par_->GetType() == t) {
|
2001-07-06 12:09:32 +00:00
|
|
|
//lyxerr << "enclosing par is current\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
idx = idx_;
|
|
|
|
return par_;
|
|
|
|
}
|
|
|
|
for (int i = path_.size() - 1; i >= 0; --i) {
|
|
|
|
lyxerr << "checking level " << i << "\n";
|
|
|
|
if (path_[i].par_->GetType() == t) {
|
|
|
|
idx = path_[i].idx_;
|
|
|
|
return path_[i].par_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MathCursor::pullArg()
|
|
|
|
{
|
|
|
|
// pullArg
|
|
|
|
MathArray a = array();
|
|
|
|
if (!Left())
|
|
|
|
return;
|
|
|
|
normalize();
|
|
|
|
array().erase(cursor_);
|
|
|
|
array().insert(cursor_, a);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathStyles MathCursor::style() const
|
|
|
|
{
|
|
|
|
return xarray().style();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathCursor::normalize() const
|
|
|
|
{
|
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
#warning This is evil!
|
|
|
|
#endif
|
|
|
|
MathCursor * it = const_cast<MathCursor *>(this);
|
|
|
|
|
|
|
|
if (idx_ < 0 || idx_ > par_->nargs())
|
|
|
|
lyxerr << "this should not really happen - 1\n";
|
|
|
|
it->idx_ = max(idx_, 0);
|
|
|
|
it->idx_ = min(idx_, par_->nargs());
|
|
|
|
|
|
|
|
if (cursor_ < 0 || cursor_ > array().size())
|
|
|
|
lyxerr << "this should not really happen - 2\n";
|
|
|
|
it->cursor_ = max(cursor_, 0);
|
|
|
|
it->cursor_ = min(cursor_, array().size());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MathCursor::col() const
|
|
|
|
{
|
|
|
|
return par_->col(idx_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MathCursor::row() const
|
|
|
|
{
|
|
|
|
return par_->row(idx_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
char MathIter::GetChar() const
|
|
|
|
{
|
|
|
|
return array().GetChar(cursor_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string MathIter::readString()
|
|
|
|
{
|
|
|
|
string s;
|
|
|
|
int code = nextCode();
|
|
|
|
for ( ; OK() && nextCode() == code; Next())
|
|
|
|
s += GetChar();
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
MathInset * MathCursor::prevInset() const
|
|
|
|
{
|
|
|
|
normalize();
|
|
|
|
int c = cursor_;
|
|
|
|
if (!array().prev(c))
|
|
|
|
return 0;
|
|
|
|
return array().GetInset(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathInset * MathCursor::nextInset() const
|
|
|
|
{
|
|
|
|
normalize();
|
|
|
|
return array().GetInset(cursor_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
MathScriptInset * MathCursor::nearbyScriptInset() const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
normalize();
|
2001-06-27 14:10:35 +00:00
|
|
|
MathScriptInset * p = array().prevScriptInset(cursor_);
|
|
|
|
if (p)
|
|
|
|
return p;
|
|
|
|
return array().nextScriptInset(cursor_);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MathArray & MathCursor::array() const
|
|
|
|
{
|
|
|
|
static MathArray dummy;
|
|
|
|
if (!par_) {
|
|
|
|
lyxerr << "############ par_ not valid\n";
|
|
|
|
return dummy;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (idx_ < 0 || idx_ >= par_->nargs()) {
|
|
|
|
lyxerr << "############ idx_ " << idx_ << " not valid\n";
|
|
|
|
return dummy;
|
|
|
|
}
|
|
|
|
|
|
|
|
return par_->cell(idx_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathXArray & MathCursor::xarray() const
|
|
|
|
{
|
|
|
|
return par_->xcell(idx_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MathCursor::nextIsInset() const
|
|
|
|
{
|
|
|
|
return cursor_ < array().size() && MathIsInset(nextCode());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathCursor::prevIsInset() const
|
|
|
|
{
|
|
|
|
return cursor_ > 0 && MathIsInset(prevCode());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathCursor::IsFont() const
|
|
|
|
{
|
|
|
|
return MathIsFont(nextCode());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathCursor::IsScript() const
|
|
|
|
{
|
|
|
|
normalize();
|
|
|
|
return MathIsScript(nextCode());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MathCursor::xpos() const
|
|
|
|
{
|
|
|
|
normalize();
|
|
|
|
return xarray().pos2x(cursor_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MathCursor::gotoX(int x)
|
|
|
|
{
|
|
|
|
cursor_ = xarray().x2pos(x);
|
|
|
|
}
|
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
void MathCursor::idxNext()
|
2001-04-24 16:13:38 +00:00
|
|
|
{
|
2001-07-06 12:09:32 +00:00
|
|
|
par_->idxNext(idx_, cursor_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MathCursor::idxPrev()
|
|
|
|
{
|
|
|
|
par_->idxPrev(idx_, cursor_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MathCursor::splitCell()
|
|
|
|
{
|
|
|
|
if (idx_ == par_->nargs() - 1)
|
|
|
|
return;
|
|
|
|
MathArray ar = array();
|
|
|
|
ar.erase(0, cursor_);
|
|
|
|
array().erase(cursor_, array().size());
|
|
|
|
++idx_;
|
|
|
|
cursor_ = 0;
|
|
|
|
array().insert(0, ar);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MathCursor::breakLine()
|
|
|
|
{
|
|
|
|
MathMatrixInset * p = static_cast<MathMatrixInset *>(formula()->par());
|
|
|
|
if (p->GetType() == LM_OT_SIMPLE || p->GetType() == LM_OT_EQUATION)
|
|
|
|
p->mutate(LM_OT_EQNARRAY);
|
|
|
|
p->addRow(row());
|
|
|
|
|
|
|
|
// split line
|
|
|
|
const int r = row();
|
|
|
|
for (int c = col() + 1; c < p->ncols(); ++c) {
|
|
|
|
const int i1 = p->index(r, c);
|
|
|
|
const int i2 = p->index(r + 1, c);
|
|
|
|
lyxerr << "swapping cells " << i1 << " and " << i2 << "\n";
|
|
|
|
p->cell(i1).swap(p->cell(i2));
|
|
|
|
}
|
|
|
|
|
|
|
|
// split cell
|
|
|
|
splitCell();
|
|
|
|
MathArray & halfcell = array();
|
|
|
|
idx_ += p->ncols() - 1;
|
|
|
|
halfcell.swap(array());
|
2001-04-24 16:13:38 +00:00
|
|
|
}
|
2001-06-27 14:10:35 +00:00
|
|
|
|
|
|
|
char MathCursor::valign() const
|
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
MathGridInset * p =
|
|
|
|
static_cast<MathGridInset *>(enclosing(LM_OT_MATRIX, idx));
|
|
|
|
return p ? p->valign() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
char MathCursor::halign() const
|
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
MathGridInset * p =
|
|
|
|
static_cast<MathGridInset *>(enclosing(LM_OT_MATRIX, idx));
|
|
|
|
return p ? p->halign(idx % p->ncols()) : 0;
|
|
|
|
}
|