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-16 15:53:25 +00:00
|
|
|
#include <algorithm>
|
2001-07-06 12:09:32 +00:00
|
|
|
#include <cctype>
|
2001-06-25 00:06:33 +00:00
|
|
|
|
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-07-17 07:38:41 +00:00
|
|
|
#include "mathed/support.h"
|
|
|
|
#include "formulabase.h"
|
|
|
|
#include "math_cursor.h"
|
|
|
|
#include "math_arrayinset.h"
|
2001-02-13 13:28:32 +00:00
|
|
|
#include "math_bigopinset.h"
|
|
|
|
#include "math_decorationinset.h"
|
2001-07-10 13:17:43 +00:00
|
|
|
#include "math_deliminset.h"
|
2001-07-17 07:38:41 +00:00
|
|
|
#include "math_dotsinset.h"
|
|
|
|
#include "math_fracinset.h"
|
|
|
|
#include "math_funcinset.h"
|
|
|
|
#include "math_gridinset.h"
|
|
|
|
#include "math_macro.h"
|
|
|
|
#include "math_macroarg.h"
|
|
|
|
#include "math_macrotable.h"
|
2001-03-01 14:07:43 +00:00
|
|
|
#include "math_macrotemplate.h"
|
2001-07-17 07:38:41 +00:00
|
|
|
#include "math_matrixinset.h"
|
|
|
|
#include "math_rootinset.h"
|
|
|
|
#include "math_spaceinset.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "math_sqrtinset.h"
|
2001-07-17 07:38:41 +00:00
|
|
|
#include "support/lstrings.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "math_scriptinset.h"
|
2001-07-17 07:38:41 +00:00
|
|
|
#include "math_parser.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-07-16 15:53:25 +00:00
|
|
|
struct Selection
|
|
|
|
{
|
|
|
|
void grab(MathCursor const & cursor)
|
|
|
|
{
|
|
|
|
data_.clear();
|
|
|
|
MathCursorPos i1;
|
|
|
|
MathCursorPos i2;
|
|
|
|
cursor.getSelection(i1, i2);
|
|
|
|
if (i1.idx_ == i2.idx_)
|
|
|
|
data_.push_back(MathArray(i1.cell(), i1.pos_, i2.pos_));
|
|
|
|
else {
|
|
|
|
#ifdef RECTANGULAR_SELECT
|
|
|
|
std::vector<int> indices = i1.par_->idxBetween(i1.idx_, i2.idx_);
|
|
|
|
for (unsigned i = 0; i < indices.size(); ++i)
|
|
|
|
data_.push_back(i1.cell(indices[i]));
|
|
|
|
#else
|
|
|
|
data_.push_back(MathArray(i1.cell(), i1.pos_, i1.cell().size()));
|
|
|
|
for (int i = i1.idx_ + 1; i < i2.idx_; ++i)
|
|
|
|
data_.push_back(i1.cell(i));
|
|
|
|
data_.push_back(MathArray(i2.cell(), 0, i2.pos_));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void erase(MathCursor & cursor)
|
|
|
|
{
|
|
|
|
MathCursorPos i1;
|
|
|
|
MathCursorPos i2;
|
|
|
|
cursor.getSelection(i1, i2);
|
|
|
|
if (i1.idx_ == i2.idx_) {
|
|
|
|
i1.cell().erase(i1.pos_, i2.pos_);
|
|
|
|
} else {
|
|
|
|
std::vector<int> indices = i1.par_->idxBetween(i1.idx_, i2.idx_);
|
|
|
|
for (unsigned i = 0; i < indices.size(); ++i)
|
|
|
|
i1.cell(indices[i]).erase();
|
|
|
|
}
|
|
|
|
cursor.cursor() = i1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void paste(MathCursor & cursor) const
|
|
|
|
{
|
2001-07-24 17:26:44 +00:00
|
|
|
cursor.insert(glue());
|
2001-07-16 15:53:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// glues selection to one cell
|
|
|
|
MathArray glue() const
|
|
|
|
{
|
|
|
|
MathArray ar;
|
|
|
|
for (unsigned i = 0; i < data_.size(); ++i)
|
|
|
|
ar.push_back(data_[i]);
|
|
|
|
return ar;
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear()
|
|
|
|
{
|
|
|
|
data_.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<MathArray> data_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
Selection theSelection;
|
2001-07-16 15:53:25 +00:00
|
|
|
|
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 &&
|
2001-07-13 07:55:55 +00:00
|
|
|
tok != LM_TK_DECORATION &&
|
2001-02-14 17:58:40 +00:00
|
|
|
tok != LM_TK_SPACE &&
|
|
|
|
tok != LM_TK_DOTS &&
|
|
|
|
tok != LM_TK_FUNCLIM &&
|
|
|
|
tok != LM_TK_BIGSYM &&
|
|
|
|
!(tok == LM_TK_SYM && id < 255);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
|
|
|
std::ostream & operator<<(std::ostream & os, MathCursorPos const & p)
|
2001-07-16 15:53:25 +00:00
|
|
|
{
|
2001-07-16 18:58:13 +00:00
|
|
|
os << "(par: " << p.par_ << " idx: " << p.idx_
|
|
|
|
<< " pos: " << p.pos_ << ")";
|
2001-07-16 15:53:25 +00:00
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2001-04-24 16:13:38 +00:00
|
|
|
}
|
|
|
|
|
2001-07-16 15:53:25 +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
|
|
|
lastcode = LM_TC_MIN;
|
2001-06-25 00:06:33 +00:00
|
|
|
macro_mode = false;
|
2001-07-16 15:53:25 +00:00
|
|
|
selection = false;
|
2001-06-25 00:06:33 +00:00
|
|
|
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-07-16 15:53:25 +00:00
|
|
|
MathCursorPos p;
|
|
|
|
p.par_ = par;
|
2001-07-13 16:06:10 +00:00
|
|
|
if (first)
|
2001-07-16 15:53:25 +00:00
|
|
|
par->idxFirst(p.idx_, p.pos_);
|
2001-07-13 16:06:10 +00:00
|
|
|
else
|
2001-07-16 15:53:25 +00:00
|
|
|
par->idxLast(p.idx_, p.pos_);
|
|
|
|
Cursor_.push_back(p);
|
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-07-16 15:53:25 +00:00
|
|
|
if (Cursor_.size() <= 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
|
|
|
}
|
|
|
|
|
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-07-16 15:53:25 +00:00
|
|
|
return Cursor_[i].par_;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-07-16 18:58:13 +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-07-23 13:52:48 +00:00
|
|
|
lyxerr << "MC: " << what << "\n";
|
|
|
|
for (unsigned i = 0; i < Cursor_.size(); ++i)
|
|
|
|
lyxerr << " i: " << i
|
|
|
|
<< " pos: " << Cursor_[i].pos_
|
|
|
|
<< " idx: " << Cursor_[i].idx_
|
|
|
|
<< " par: " << Cursor_[i].par_ << "\n";
|
|
|
|
|
|
|
|
//lyxerr << " sel: " << selection << " data: " << array() << "\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
void MathCursor::seldump(char const *) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-07-16 15:53:25 +00:00
|
|
|
//lyxerr << "SEL: " << str << ": '" << theSelection << "'\n";
|
|
|
|
//dump(" Pos");
|
2001-06-25 00:06:33 +00:00
|
|
|
return;
|
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
//lyxerr << "\n\n\\n=================vvvvvvvvvvvvv======================= "
|
|
|
|
// << str << "\ntheSelection: " << theSelection;
|
|
|
|
//for (unsigned int i = 0; i < Cursor_.size(); ++i)
|
|
|
|
// lyxerr << Cursor_[i].par_ << "\n'" << Cursor_[i].cell() << "'\n";
|
|
|
|
//lyxerr << "\ncursor.pos_: " << cursor().pos_;
|
|
|
|
//lyxerr << "\nanchor.pos_: " << anchor().pos_;
|
|
|
|
//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-07-16 15:53:25 +00:00
|
|
|
for (unsigned i = 0; i < Cursor_.size(); ++i)
|
2001-06-25 00:06:33 +00:00
|
|
|
if (parInset(i) == p)
|
|
|
|
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-07-16 15:53:25 +00:00
|
|
|
bool MathCursor::openable(MathInset * p, bool sel, bool useupdown) const
|
|
|
|
{
|
|
|
|
if (!p)
|
|
|
|
return false;
|
|
|
|
if (!(p->isActive() || (useupdown && p->isUpDownInset())))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (sel) {
|
|
|
|
// we can't move into everything during selection
|
|
|
|
if (Cursor_.size() == Anchor_.size())
|
|
|
|
return false;
|
|
|
|
if (p != Anchor_[Cursor_.size()].par_)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-07-13 14:54:56 +00:00
|
|
|
bool MathCursor::plainLeft()
|
|
|
|
{
|
2001-07-16 15:53:25 +00:00
|
|
|
return array().prev(cursor().pos_);
|
2001-07-13 14:54:56 +00:00
|
|
|
}
|
|
|
|
|
2001-07-16 15:53:25 +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-06-25 00:06:33 +00:00
|
|
|
SelHandle(sel);
|
2001-07-13 14:54:56 +00:00
|
|
|
clearLastCode();
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
MathInset * p = prevInset();
|
|
|
|
if (openable(p, sel, false)) {
|
2001-07-23 13:52:48 +00:00
|
|
|
plainLeft();
|
2001-07-16 15:53:25 +00:00
|
|
|
push(p, false);
|
|
|
|
return true;
|
|
|
|
}
|
2001-07-23 13:52:48 +00:00
|
|
|
if (plainLeft())
|
2001-07-16 15:53:25 +00:00
|
|
|
return true;
|
|
|
|
if (cursor().par_->idxLeft(cursor().idx_, cursor().pos_))
|
|
|
|
return true;
|
|
|
|
if (pop())
|
|
|
|
return true;
|
|
|
|
return false;
|
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()
|
|
|
|
{
|
2001-07-16 15:53:25 +00:00
|
|
|
return array().next(cursor().pos_);
|
2001-06-27 14:10:35 +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;
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
SelHandle(sel);
|
2001-07-13 14:54:56 +00:00
|
|
|
clearLastCode();
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
MathInset * p = nextInset();
|
|
|
|
if (openable(p, sel, false)) {
|
|
|
|
push(p, true);
|
|
|
|
return true;
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
2001-07-16 15:53:25 +00:00
|
|
|
if (array().next(cursor().pos_))
|
|
|
|
return true;
|
|
|
|
if (cursor().par_->idxRight(cursor().idx_, cursor().pos_))
|
|
|
|
return true;
|
|
|
|
if (!pop())
|
|
|
|
return false;
|
|
|
|
array().next(cursor().pos_);
|
|
|
|
return true;
|
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();
|
|
|
|
push(formula_->par(), true);
|
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()
|
|
|
|
{
|
2001-07-16 15:53:25 +00:00
|
|
|
Cursor_.clear();
|
|
|
|
push(formula_->par(), false);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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-07-16 15:53:25 +00:00
|
|
|
first();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
cursor().par_ = formula()->par();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
while (1) {
|
2001-07-16 15:53:25 +00:00
|
|
|
cursor().idx_ = -1;
|
|
|
|
cursor().pos_ = -1;
|
|
|
|
//lyxerr << "found idx: " << idx_ << " cursor: " << cursor().pos_ << "\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
int distmin = 1 << 30; // large enough
|
2001-07-16 15:53:25 +00:00
|
|
|
for (int i = 0; i < cursor().par_->nargs(); ++i) {
|
|
|
|
MathXArray const & ar = cursor().par_->xcell(i);
|
2001-06-25 00:06:33 +00:00
|
|
|
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) {
|
2001-07-16 15:53:25 +00:00
|
|
|
distmin = yy + xx;
|
|
|
|
cursor().idx_ = i;
|
|
|
|
cursor().pos_ = c;
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
|
|
|
}
|
2001-07-16 15:53:25 +00:00
|
|
|
//lyxerr << "found idx: " << cursor().idx_ << " cursor: "
|
|
|
|
// << cursor().pos_ << "\n";
|
2001-07-06 12:09:32 +00:00
|
|
|
MathInset * n = nextInset();
|
|
|
|
MathInset * p = prevInset();
|
2001-07-16 15:53:25 +00:00
|
|
|
if (openable(n, selection, true) && n->covers(x, y))
|
2001-07-06 12:09:32 +00:00
|
|
|
push(n, true);
|
2001-07-16 15:53:25 +00:00
|
|
|
else if (openable(p, selection, true) && p->covers(x, y)) {
|
2001-07-23 13:52:48 +00:00
|
|
|
plainLeft();
|
2001-06-25 00:06:33 +00:00
|
|
|
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-07-16 15:53:25 +00:00
|
|
|
if (!cursor().par_->idxHome(cursor().idx_, cursor().pos_))
|
2001-06-25 00:06:33 +00:00
|
|
|
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-07-16 15:53:25 +00:00
|
|
|
if (!cursor().par_->idxEnd(cursor().idx_, cursor().pos_)) {
|
2001-06-25 00:06:33 +00:00
|
|
|
pop();
|
2001-07-16 15:53:25 +00:00
|
|
|
array().next(cursor().pos_);
|
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-07-10 13:17:43 +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-07-16 15:53:25 +00:00
|
|
|
array().insert(cursor().pos_, c, t);
|
|
|
|
array().next(cursor().pos_);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
lastcode = t;
|
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-07-16 15:53:25 +00:00
|
|
|
array().insert(cursor().pos_, p);
|
|
|
|
array().next(cursor().pos_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathCursor::insert(MathArray const & ar)
|
|
|
|
{
|
|
|
|
MacroModeClose();
|
|
|
|
if (selection)
|
|
|
|
SelCut();
|
|
|
|
|
|
|
|
array().insert(cursor().pos_, ar);
|
|
|
|
cursor().pos_ += ar.size();
|
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-07-09 16:59:57 +00:00
|
|
|
// delete empty cells if necessary
|
2001-07-16 15:53:25 +00:00
|
|
|
if (cursor().pos_ == 0 && array().size() == 0) {
|
2001-07-09 16:59:57 +00:00
|
|
|
bool popit;
|
|
|
|
bool removeit;
|
2001-07-16 15:53:25 +00:00
|
|
|
cursor().par_->idxDelete(cursor().idx_, popit, removeit);
|
2001-07-09 16:59:57 +00:00
|
|
|
if (popit && pop() && removeit)
|
|
|
|
Delete();
|
2001-07-23 14:21:34 +00:00
|
|
|
return;
|
2001-06-27 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2001-07-23 14:21:34 +00:00
|
|
|
if (cursor().pos_ < array().size())
|
|
|
|
array().erase(cursor().pos_);
|
|
|
|
|
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-07-16 15:53:25 +00:00
|
|
|
if (cursor().par_->nrows() > 1)
|
|
|
|
cursor().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);
|
2001-07-16 15:53:25 +00:00
|
|
|
|
|
|
|
if (selection) {
|
|
|
|
int x = xarray().pos2x(cursor().pos_);
|
|
|
|
if (cursor().par_->idxUp(cursor().idx_, cursor().pos_)) {
|
|
|
|
cursor().pos_ = xarray().x2pos(x);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (pop())
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
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) {
|
2001-07-16 15:53:25 +00:00
|
|
|
int idx, pos;
|
|
|
|
if (p->idxFirstUp(idx, pos)) {
|
2001-06-27 14:10:35 +00:00
|
|
|
push(p, true);
|
2001-07-16 15:53:25 +00:00
|
|
|
cursor().par_ = p;
|
|
|
|
cursor().idx_ = idx;
|
|
|
|
cursor().pos_ = pos;
|
2001-06-27 14:10:35 +00:00
|
|
|
dump("Up 3");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p = prevInset();
|
|
|
|
if (p) {
|
2001-07-16 15:53:25 +00:00
|
|
|
int idx, pos;
|
|
|
|
if (p->idxLastUp(idx, pos)) {
|
2001-07-23 13:52:48 +00:00
|
|
|
plainLeft();
|
2001-06-27 14:10:35 +00:00
|
|
|
push(p, false);
|
2001-07-16 15:53:25 +00:00
|
|
|
cursor().par_ = p;
|
|
|
|
cursor().idx_ = idx;
|
|
|
|
cursor().pos_ = pos;
|
2001-06-27 14:10:35 +00:00
|
|
|
dump("Up 4");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
int x = xarray().pos2x(cursor().pos_);
|
|
|
|
if (cursor().idxUp()) {
|
|
|
|
cursor().pos_ = xarray().x2pos(x);
|
|
|
|
return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-07-16 15:53:25 +00:00
|
|
|
if (pop())
|
|
|
|
return true;
|
|
|
|
return false;
|
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);
|
2001-07-16 15:53:25 +00:00
|
|
|
|
|
|
|
if (selection) {
|
|
|
|
int x = xarray().pos2x(cursor().pos_);
|
|
|
|
if (cursor().idxDown()) {
|
|
|
|
cursor().pos_ = xarray().x2pos(x);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (pop())
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
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) {
|
2001-07-13 16:06:10 +00:00
|
|
|
int idx, pos;
|
|
|
|
if (p->idxFirstDown(idx, pos)) {
|
2001-06-27 14:10:35 +00:00
|
|
|
push(p, true);
|
2001-07-16 15:53:25 +00:00
|
|
|
cursor().idx_ = idx;
|
|
|
|
cursor().pos_ = pos;
|
2001-06-27 14:10:35 +00:00
|
|
|
dump("Down 3");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p = prevInset();
|
|
|
|
if (p) {
|
2001-07-13 16:06:10 +00:00
|
|
|
int idx, pos;
|
|
|
|
if (p->idxLastDown(idx, pos)) {
|
2001-07-23 13:52:48 +00:00
|
|
|
plainLeft();
|
2001-06-27 14:10:35 +00:00
|
|
|
push(p, false);
|
2001-07-16 15:53:25 +00:00
|
|
|
cursor().idx_ = idx;
|
|
|
|
cursor().pos_ = pos;
|
2001-06-27 14:10:35 +00:00
|
|
|
dump("Down 4");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
int x = xarray().pos2x(cursor().pos_);
|
|
|
|
if (cursor().par_->idxDown(cursor().idx_, cursor().pos_)) {
|
|
|
|
cursor().pos_ = xarray().x2pos(x);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (pop())
|
|
|
|
return true;
|
|
|
|
return false;
|
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();
|
2001-07-12 07:18:29 +00:00
|
|
|
p->limits(old < 0 ? 1 : -1);
|
2001-06-27 14:10:35 +00:00
|
|
|
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-07-16 15:53:25 +00:00
|
|
|
cursor().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-07-09 10:19:50 +00:00
|
|
|
lyxerr << "Interpret: '" << s << "' ('" << s.substr(0, 7) << "' " <<
|
|
|
|
in_word_set(s) << " \n";
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-07-24 16:10:17 +00:00
|
|
|
if (s[0] == '^' || s[0] == '_') {
|
|
|
|
bool const up = (s[0] == '^');
|
|
|
|
SelCut();
|
|
|
|
MathUpDownInset * p = prevUpDownInset();
|
2001-06-25 00:06:33 +00:00
|
|
|
if (!p) {
|
2001-07-24 16:10:17 +00:00
|
|
|
p = new MathScriptInset(up, !up);
|
2001-06-25 00:06:33 +00:00
|
|
|
insert(p);
|
2001-07-23 13:52:48 +00:00
|
|
|
plainLeft();
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
2001-06-27 14:10:35 +00:00
|
|
|
push(p, true);
|
2001-07-24 16:10:17 +00:00
|
|
|
if (up)
|
|
|
|
p->up(true);
|
|
|
|
else
|
|
|
|
p->down(true);
|
|
|
|
cursor().idx_ = up ? 0 : 1;
|
|
|
|
cursor().pos_ = 0;
|
|
|
|
SelPaste();
|
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));
|
2001-07-09 10:19:50 +00:00
|
|
|
else if (s.size() > 7 && s.substr(0, 7) == "matrix ") {
|
|
|
|
int m = 1;
|
|
|
|
int n = 1;
|
|
|
|
string v_align;
|
|
|
|
string h_align;
|
2001-07-13 14:03:48 +00:00
|
|
|
istringstream is(s.substr(7).c_str());
|
2001-07-09 10:19:50 +00:00
|
|
|
is >> m >> n >> v_align >> h_align;
|
|
|
|
m = std::max(1, m);
|
|
|
|
n = std::max(1, n);
|
2001-07-16 15:53:25 +00:00
|
|
|
v_align += 'c';
|
2001-07-09 10:19:50 +00:00
|
|
|
MathArrayInset * pp = new MathArrayInset(m, n);
|
|
|
|
pp->valign(v_align[0]);
|
|
|
|
pp->halign(h_align);
|
|
|
|
p = pp;
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
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;
|
|
|
|
|
2001-07-20 14:54:13 +00:00
|
|
|
case LM_TK_SYM: {
|
|
|
|
MathTextCodes code = static_cast<MathTextCodes>(l->id);
|
|
|
|
if (code < 255)
|
|
|
|
insert(l->id, MathIsBOPS(code) ? LM_TC_BOPS : LM_TC_SYMB);
|
2001-07-13 11:32:22 +00:00
|
|
|
else
|
2001-06-27 14:10:35 +00:00
|
|
|
p = new MathFuncInset(l->name);
|
|
|
|
break;
|
2001-07-20 14:54:13 +00:00
|
|
|
}
|
2001-06-27 14:10:35 +00:00
|
|
|
|
2001-02-14 17:58:40 +00:00
|
|
|
case LM_TK_STACK:
|
2001-07-09 10:19:50 +00:00
|
|
|
p = new MathFracInset("stackrel");
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
2001-02-14 17:58:40 +00:00
|
|
|
|
|
|
|
case LM_TK_FRAC:
|
2001-07-09 10:19:50 +00:00
|
|
|
p = new MathFracInset("frac");
|
2001-02-14 17:58:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_TK_SQRT:
|
|
|
|
p = new MathSqrtInset;
|
|
|
|
break;
|
|
|
|
|
2001-07-13 07:55:55 +00:00
|
|
|
case LM_TK_DECORATION:
|
|
|
|
p = new MathDecorationInset(l->name, l->id);
|
2001-02-14 17:58:40 +00:00
|
|
|
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_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()) {
|
2001-07-23 13:52:48 +00:00
|
|
|
plainLeft();
|
2001-07-23 14:30:22 +00:00
|
|
|
//push(p, true);
|
|
|
|
Right(); // do not push for e.g. MathBigopInset
|
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-07-16 15:53:25 +00:00
|
|
|
array().erase(cursor().pos_);
|
2001-06-25 00:06:33 +00:00
|
|
|
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-07-16 15:53:25 +00:00
|
|
|
theSelection.grab(*this);
|
2001-02-14 17:58:40 +00:00
|
|
|
SelClear();
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +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-07-16 15:53:25 +00:00
|
|
|
theSelection.grab(*this);
|
|
|
|
theSelection.erase(*this);
|
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-07-16 15:53:25 +00:00
|
|
|
theSelection.erase(*this);
|
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");
|
2001-07-16 15:53:25 +00:00
|
|
|
theSelection.paste(*this);
|
2001-06-25 00:06:33 +00:00
|
|
|
SelClear();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +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-07-16 15:53:25 +00:00
|
|
|
Anchor_ = Cursor_;
|
2001-06-25 00:06:33 +00:00
|
|
|
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-07-16 15:53:25 +00:00
|
|
|
void MathCursor::drawSelection(Painter & pain) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-07-16 15:53:25 +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);
|
|
|
|
|
|
|
|
//lyxerr << "selection from: " << i1 << " to " << i2 << "\n";
|
|
|
|
|
|
|
|
if (i1.idx_ == i2.idx_) {
|
|
|
|
MathXArray & c = i1.xcell();
|
|
|
|
int x1 = c.xo() + c.pos2x(i1.pos_);
|
|
|
|
int y1 = c.yo() - c.ascent();
|
|
|
|
int x2 = c.xo() + c.pos2x(i2.pos_);
|
|
|
|
int y2 = c.yo() + c.descent();
|
|
|
|
pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
|
|
|
|
} else {
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
std::vector<int> indices = i1.par_->idxBetween(i1.idx_, i2.idx_);
|
|
|
|
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();
|
|
|
|
pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
|
|
|
|
}
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2001-07-03 07:56:55 +00:00
|
|
|
void MathCursor::handleFont(MathTextCodes t)
|
|
|
|
{
|
2001-07-16 15:53:25 +00:00
|
|
|
if (selection) {
|
|
|
|
MathCursorPos i1;
|
|
|
|
MathCursorPos i2;
|
|
|
|
getSelection(i1, i2);
|
|
|
|
if (i1.idx_ == i2.idx_) {
|
|
|
|
MathArray & ar = i1.cell();
|
|
|
|
for (int pos = i1.pos_; pos != i2.pos_; 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 {
|
2001-07-16 15:53:25 +00:00
|
|
|
lastcode = (lastcode == t) ? LM_TC_VAR : t;
|
2001-07-03 07:56:55 +00:00
|
|
|
}
|
2001-01-09 13:58:48 +00:00
|
|
|
}
|
2001-02-13 19:10:18 +00:00
|
|
|
|
|
|
|
|
2001-07-13 07:55:55 +00:00
|
|
|
void MathCursor::handleAccent(string const & name, int code)
|
2001-07-10 13:17:43 +00:00
|
|
|
{
|
2001-07-13 07:55:55 +00:00
|
|
|
MathDecorationInset * p = new MathDecorationInset(name, code);
|
2001-07-10 13:17:43 +00:00
|
|
|
if (selection) {
|
|
|
|
SelCut();
|
2001-07-16 15:53:25 +00:00
|
|
|
p->cell(0) = theSelection.glue();
|
2001-07-10 13:17:43 +00:00
|
|
|
}
|
|
|
|
insert(p);
|
2001-07-13 07:55:55 +00:00
|
|
|
push(p, true);
|
2001-07-10 13:17:43 +00:00
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-07-10 13:17:43 +00:00
|
|
|
void MathCursor::handleDelim(int l, int r)
|
|
|
|
{
|
|
|
|
MathDelimInset * p = new MathDelimInset(l, r);
|
|
|
|
if (selection) {
|
|
|
|
SelCut();
|
2001-07-16 15:53:25 +00:00
|
|
|
p->cell(0) = theSelection.glue();
|
2001-07-10 13:17:43 +00:00
|
|
|
}
|
|
|
|
insert(p);
|
2001-07-23 13:52:48 +00:00
|
|
|
plainLeft();
|
2001-07-13 07:55:55 +00:00
|
|
|
push(p, true);
|
2001-07-10 13:17:43 +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-07-16 15:53:25 +00:00
|
|
|
x = xarray().xo() + xarray().pos2x(cursor().pos_);
|
2001-06-25 00:06:33 +00:00
|
|
|
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-07-16 15:53:25 +00:00
|
|
|
return array().GetCode(cursor().pos_);
|
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-07-16 15:53:25 +00:00
|
|
|
return array().GetCode(cursor().pos_ - 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-07-16 15:53:25 +00:00
|
|
|
return cursor().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-07-16 15:53:25 +00:00
|
|
|
return cursor().pos_;
|
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
|
|
|
|
{
|
2001-07-16 15:53:25 +00:00
|
|
|
for (int i = Cursor_.size() - 1; i >= 0; --i) {
|
|
|
|
//lyxerr << "checking level " << i << "\n";
|
|
|
|
if (Cursor_[i].par_->GetType() == t) {
|
|
|
|
idx = Cursor_[i].idx_;
|
|
|
|
return Cursor_[i].par_;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-07-23 14:15:14 +00:00
|
|
|
void MathCursor::pullArg(bool goright)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
// pullArg
|
2001-07-23 13:52:48 +00:00
|
|
|
dump("pullarg");
|
2001-06-25 00:06:33 +00:00
|
|
|
MathArray a = array();
|
2001-07-23 13:52:48 +00:00
|
|
|
if (pop()) {
|
|
|
|
array().erase(cursor().pos_);
|
|
|
|
array().insert(cursor().pos_, a);
|
2001-07-23 14:15:14 +00:00
|
|
|
if (goright)
|
|
|
|
cursor().pos_ += a.size();
|
2001-07-23 13:52:48 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
if (cursor().idx_ < 0 || cursor().idx_ > cursor().par_->nargs())
|
2001-06-25 00:06:33 +00:00
|
|
|
lyxerr << "this should not really happen - 1\n";
|
2001-07-16 15:53:25 +00:00
|
|
|
it->cursor().idx_ = max(cursor().idx_, 0);
|
|
|
|
it->cursor().idx_ = min(cursor().idx_, cursor().par_->nargs());
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
if (cursor().pos_ < 0 || cursor().pos_ > array().size())
|
2001-06-25 00:06:33 +00:00
|
|
|
lyxerr << "this should not really happen - 2\n";
|
2001-07-16 15:53:25 +00:00
|
|
|
it->cursor().pos_ = max(cursor().pos_, 0);
|
|
|
|
it->cursor().pos_ = min(cursor().pos_, array().size());
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MathCursor::col() const
|
|
|
|
{
|
2001-07-16 15:53:25 +00:00
|
|
|
return par()->col(cursor().idx_);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MathCursor::row() const
|
|
|
|
{
|
2001-07-16 15:53:25 +00:00
|
|
|
return par()->row(cursor().idx_);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2001-07-16 15:53:25 +00:00
|
|
|
char MathCursorPos::GetChar() const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-07-16 15:53:25 +00:00
|
|
|
return array().GetChar(cursor().pos_);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
string MathCursorPos::readString()
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
string s;
|
|
|
|
int code = nextCode();
|
|
|
|
for ( ; OK() && nextCode() == code; Next())
|
|
|
|
s += GetChar();
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathInset * MathCursor::prevInset() const
|
|
|
|
{
|
|
|
|
normalize();
|
2001-07-16 15:53:25 +00:00
|
|
|
int c = cursor().pos_;
|
2001-06-25 00:06:33 +00:00
|
|
|
if (!array().prev(c))
|
|
|
|
return 0;
|
2001-07-12 07:18:29 +00:00
|
|
|
return array().nextInset(c);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathInset * MathCursor::nextInset() const
|
|
|
|
{
|
|
|
|
normalize();
|
2001-07-16 15:53:25 +00:00
|
|
|
return array().nextInset(cursor().pos_);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-24 16:10:17 +00:00
|
|
|
MathUpDownInset * MathCursor::prevUpDownInset() const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
normalize();
|
2001-07-16 15:53:25 +00:00
|
|
|
MathInset * p = array().prevInset(cursor().pos_);
|
2001-07-24 16:10:17 +00:00
|
|
|
return (p && p->isUpDownInset()) ? static_cast<MathUpDownInset *>(p) : 0;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathArray & MathCursor::array() const
|
|
|
|
{
|
|
|
|
static MathArray dummy;
|
2001-07-16 15:53:25 +00:00
|
|
|
if (!cursor().par_) {
|
2001-06-25 00:06:33 +00:00
|
|
|
lyxerr << "############ par_ not valid\n";
|
|
|
|
return dummy;
|
|
|
|
}
|
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
if (cursor().idx_ < 0 || cursor().idx_ >= cursor().par_->nargs()) {
|
|
|
|
lyxerr << "############ idx_ " << cursor().idx_ << " not valid\n";
|
2001-06-25 00:06:33 +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-07-16 15:53:25 +00:00
|
|
|
return cursor().xcell();
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathCursor::nextIsInset() const
|
|
|
|
{
|
2001-07-16 15:53:25 +00:00
|
|
|
return cursor().pos_ < array().size() && MathIsInset(nextCode());
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathCursor::prevIsInset() const
|
|
|
|
{
|
2001-07-16 15:53:25 +00:00
|
|
|
return cursor().pos_ > 0 && MathIsInset(prevCode());
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MathCursor::xpos() const
|
|
|
|
{
|
|
|
|
normalize();
|
2001-07-16 15:53:25 +00:00
|
|
|
return xarray().pos2x(cursor().pos_);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathCursor::gotoX(int x)
|
|
|
|
{
|
2001-07-16 15:53:25 +00:00
|
|
|
cursor().pos_ = xarray().x2pos(x);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
void MathCursor::idxNext()
|
2001-04-24 16:13:38 +00:00
|
|
|
{
|
2001-07-16 15:53:25 +00:00
|
|
|
cursor().par_->idxNext(cursor().idx_, cursor().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-07-16 15:53:25 +00:00
|
|
|
cursor().par_->idxPrev(cursor().idx_, cursor().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()
|
|
|
|
{
|
2001-07-16 15:53:25 +00:00
|
|
|
if (cursor().idx_ == cursor().par_->nargs() - 1)
|
2001-07-06 12:09:32 +00:00
|
|
|
return;
|
|
|
|
MathArray ar = array();
|
2001-07-16 15:53:25 +00:00
|
|
|
ar.erase(0, cursor().pos_);
|
|
|
|
array().erase(cursor().pos_, array().size());
|
|
|
|
++cursor().idx_;
|
|
|
|
cursor().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()
|
|
|
|
{
|
|
|
|
MathMatrixInset * p = static_cast<MathMatrixInset *>(formula()->par());
|
2001-07-09 16:59:57 +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);
|
2001-07-16 15:53:25 +00:00
|
|
|
p->addRow(0);
|
|
|
|
cursor().idx_ = p->nrows();
|
|
|
|
cursor().pos_ = 0;
|
2001-07-09 16:59:57 +00:00
|
|
|
} else {
|
|
|
|
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));
|
|
|
|
}
|
2001-07-06 12:09:32 +00:00
|
|
|
|
2001-07-09 16:59:57 +00:00
|
|
|
// split cell
|
|
|
|
splitCell();
|
2001-07-16 15:53:25 +00:00
|
|
|
p->cell(cursor().idx_).swap(p->cell(cursor().idx_ + p->ncols() - 1));
|
2001-07-09 16:59:57 +00:00
|
|
|
}
|
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-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;
|
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
char MathCursor::halign() const
|
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
MathGridInset * p =
|
|
|
|
static_cast<MathGridInset *>(enclosing(LM_OT_MATRIX, idx));
|
|
|
|
return p ? p->halign(idx % p->ncols()) : 0;
|
|
|
|
}
|
2001-07-16 15:53:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
MathCursorPos MathCursor::firstSelectionPos() const
|
|
|
|
{
|
|
|
|
MathCursorPos anc = normalAnchor();
|
|
|
|
return anc < cursor() ? anc : cursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathCursorPos MathCursor::lastSelectionPos() const
|
|
|
|
{
|
|
|
|
MathCursorPos anc = normalAnchor();
|
|
|
|
return anc < cursor() ? cursor() : anc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
return Cursor_.back();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathCursorPos const & MathCursor::cursor() const
|
|
|
|
{
|
|
|
|
return Cursor_.back();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
bool operator==(MathCursorPos const & ti, MathCursorPos const & it)
|
2001-07-16 15:53:25 +00:00
|
|
|
{
|
2001-07-16 18:58:13 +00:00
|
|
|
return ti.par_ == it.par_ && ti.idx_ == it.idx_ && ti.pos_ == it.pos_;
|
2001-07-16 15:53:25 +00:00
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
|
|
|
bool operator<(MathCursorPos const & ti, MathCursorPos const & it)
|
2001-07-16 15:53:25 +00:00
|
|
|
{
|
2001-07-16 18:58:13 +00:00
|
|
|
if (ti.par_ != it.par_) {
|
2001-07-16 15:53:25 +00:00
|
|
|
lyxerr << "can't compare cursor and anchor in different insets\n";
|
|
|
|
return true;
|
|
|
|
}
|
2001-07-16 18:58:13 +00:00
|
|
|
if (ti.idx_ != it.idx_)
|
|
|
|
return ti.idx_ < it.idx_;
|
|
|
|
return ti.pos_ < it.pos_;
|
2001-07-16 15:53:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathArray & MathCursorPos::cell(int idx) const
|
|
|
|
{
|
|
|
|
return par_->cell(idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
MathArray & MathCursorPos::cell() const
|
|
|
|
{
|
|
|
|
return par_->cell(idx_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathXArray & MathCursorPos::xcell(int idx) const
|
|
|
|
{
|
|
|
|
return par_->xcell(idx);
|
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
MathXArray & MathCursorPos::xcell() const
|
|
|
|
{
|
|
|
|
return par_->xcell(idx_);
|
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
MathCursorPos MathCursor::normalAnchor() const
|
|
|
|
{
|
|
|
|
// use Anchor on the same level as Cursor
|
|
|
|
MathCursorPos normal = Anchor_[Cursor_.size() - 1];
|
2001-07-16 18:58:13 +00:00
|
|
|
if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
|
2001-07-16 15:53:25 +00:00
|
|
|
// anchor is behind cursor -> move anchor behind the inset
|
|
|
|
normal.cell().next(normal.pos_);
|
|
|
|
}
|
|
|
|
//lyxerr << "normalizing: from " << Anchor_[Anchor_.size() - 1] << " to "
|
|
|
|
// << normal << "\n";
|
|
|
|
return normal;
|
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
bool MathCursorPos::idxUp()
|
|
|
|
{
|
|
|
|
return par_->idxUp(idx_, pos_);
|
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
bool MathCursorPos::idxDown()
|
|
|
|
{
|
|
|
|
return par_->idxDown(idx_, pos_);
|
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
bool MathCursorPos::idxLeft()
|
|
|
|
{
|
|
|
|
return par_->idxLeft(idx_, pos_);
|
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
bool MathCursorPos::idxRight()
|
|
|
|
{
|
|
|
|
return par_->idxRight(idx_, pos_);
|
|
|
|
}
|