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-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"
|
|
|
|
#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;
|
|
|
|
|
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-25 00:06:33 +00:00
|
|
|
void MathCursor::pop()
|
2001-04-24 16:13:38 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
if (path_.empty())
|
|
|
|
return;
|
|
|
|
par_ = path_.back().par_;
|
|
|
|
idx_ = path_.back().idx_;
|
|
|
|
cursor_ = path_.back().cursor_;
|
|
|
|
dump("Popped:");
|
|
|
|
path_.pop_back();
|
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
|
|
|
|
{
|
|
|
|
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_);
|
|
|
|
if (!result && !path_.empty()) {
|
|
|
|
pop();
|
|
|
|
anchor_ = cursor_;
|
|
|
|
result = array().next(anchor_);
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
} else {
|
|
|
|
MathInset * p = prevActiveInset();
|
|
|
|
if (p) {
|
|
|
|
// 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;
|
|
|
|
} else if (!path_.empty()) {
|
|
|
|
pop();
|
|
|
|
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-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_);
|
|
|
|
if (!result && !path_.empty()) {
|
|
|
|
pop();
|
|
|
|
anchor_ = cursor_;
|
|
|
|
result = array().prev(anchor_);
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
|
|
|
} else {
|
2001-06-25 00:06:33 +00:00
|
|
|
MathInset * p = nextActiveInset();
|
|
|
|
if (p) {
|
|
|
|
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;
|
|
|
|
} else if (!path_.empty()) {
|
|
|
|
pop();
|
|
|
|
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");
|
|
|
|
lyxerr << "MathCursor::SetPos x: " << x << " y: " << y << "\n";
|
|
|
|
|
|
|
|
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;
|
|
|
|
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";
|
|
|
|
if (nextIsActive() && nextInset()->covers(x, y)) {
|
|
|
|
MathInset * p = nextActiveInset();
|
|
|
|
push(p, true);
|
|
|
|
} else if (prevIsActive() && prevInset()->covers(x, y)) {
|
|
|
|
MathInset * p = prevActiveInset();
|
|
|
|
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_);
|
|
|
|
|
|
|
|
#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();
|
|
|
|
|
|
|
|
int x = xarray().pos2x(cursor_);
|
|
|
|
bool result = par_->idxUp(idx_, cursor_);
|
|
|
|
if (!result && !path_.empty()) {
|
|
|
|
pop();
|
|
|
|
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();
|
|
|
|
|
|
|
|
int x = xarray().pos2x(cursor_);
|
|
|
|
bool result = par_->idxDown(idx_, cursor_);
|
|
|
|
if (!result && !path_.empty()) {
|
|
|
|
pop();
|
|
|
|
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();
|
|
|
|
bool old = p->GetLimits();
|
|
|
|
p->SetLimits(!old);
|
|
|
|
return old != p->GetLimits();
|
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] == '^') {
|
|
|
|
MathScriptInset * p = prevScriptInset();
|
|
|
|
if (!p) {
|
|
|
|
p = new MathScriptInset;
|
|
|
|
insert(p);
|
|
|
|
}
|
|
|
|
if (!p->up())
|
|
|
|
p->up(true);
|
|
|
|
push(p, true);
|
|
|
|
return;
|
|
|
|
}
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
if (s[0] == '_') {
|
|
|
|
MathScriptInset * p = prevScriptInset();
|
|
|
|
if (!p) {
|
|
|
|
p = new MathScriptInset;
|
|
|
|
insert(p);
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
if (!p->down())
|
|
|
|
p->down(true);
|
|
|
|
push(p, true);
|
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
|
|
|
|
|
|
|
if (!l) {
|
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-25 00:06:33 +00:00
|
|
|
if (l->id < 255)
|
|
|
|
insert(static_cast<byte>(l->id), MathIsBOPS(l->id) ?
|
|
|
|
LM_TC_BOPS : LM_TC_SYMB);
|
|
|
|
else
|
2001-02-14 17:58:40 +00:00
|
|
|
p = new MathFuncInset(l->name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
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-06-25 00:06:33 +00:00
|
|
|
insert(p);
|
|
|
|
if (p->nargs()) {
|
|
|
|
array().prev(cursor_);
|
|
|
|
push(p, true);
|
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-06-25 00:06:33 +00:00
|
|
|
void MathCursor::toggleLastCode(MathTextCodes t)
|
2001-01-09 13:58:48 +00:00
|
|
|
{
|
|
|
|
if (lastcode == t)
|
|
|
|
lastcode = LM_TC_VAR;
|
|
|
|
else
|
|
|
|
lastcode = t;
|
|
|
|
}
|
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) {
|
|
|
|
lyxerr << "enclosing par is current\n";
|
|
|
|
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::prevActiveInset() const
|
|
|
|
{
|
|
|
|
if (cursor_ <= 0 || !array().isInset(cursor_ - 1))
|
|
|
|
return 0;
|
|
|
|
MathInset * inset = prevInset();
|
|
|
|
return inset->nargs() ? inset : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathInset * MathCursor::nextInset() const
|
|
|
|
{
|
|
|
|
normalize();
|
|
|
|
return array().GetInset(cursor_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathInset * MathCursor::nextActiveInset() const
|
|
|
|
{
|
|
|
|
if (!array().isInset(cursor_))
|
|
|
|
return 0;
|
|
|
|
MathInset * inset = nextInset();
|
|
|
|
return inset->nargs() ? inset : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathScriptInset * MathCursor::prevScriptInset() const
|
|
|
|
{
|
|
|
|
normalize();
|
|
|
|
return array().prevScriptInset(cursor_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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::nextIsActive() const
|
|
|
|
{
|
|
|
|
return nextIsInset() && nextInset()->nargs();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathCursor::prevIsInset() const
|
|
|
|
{
|
|
|
|
return cursor_ > 0 && MathIsInset(prevCode());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathCursor::prevIsActive() const
|
|
|
|
{
|
|
|
|
return prevIsInset() && prevInset()->nargs();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MathCursor::idxRight()
|
2001-04-24 16:13:38 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
par_->idxRight(idx_, cursor_);
|
2001-04-24 16:13:38 +00:00
|
|
|
}
|