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
|
|
|
|
2001-08-13 14:02:37 +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-08-13 14:02:37 +00:00
|
|
|
#include "support.h"
|
2001-07-17 07:38:41 +00:00
|
|
|
#include "formulabase.h"
|
|
|
|
#include "math_cursor.h"
|
2001-08-13 14:02:37 +00:00
|
|
|
#include "math_factory.h"
|
2001-07-17 07:38:41 +00:00
|
|
|
#include "math_arrayinset.h"
|
2001-08-09 09:19:18 +00:00
|
|
|
#include "math_charinset.h"
|
2001-07-10 13:17:43 +00:00
|
|
|
#include "math_deliminset.h"
|
2001-07-17 07:38:41 +00:00
|
|
|
#include "math_matrixinset.h"
|
2001-08-13 14:02:37 +00:00
|
|
|
#include "math_scopeinset.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "math_scriptinset.h"
|
2001-08-13 14:02:37 +00:00
|
|
|
#include "math_spaceinset.h"
|
2001-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 {
|
|
|
|
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]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void erase(MathCursor & cursor)
|
|
|
|
{
|
|
|
|
MathCursorPos i1;
|
|
|
|
MathCursorPos i2;
|
|
|
|
cursor.getSelection(i1, i2);
|
2001-08-15 05:50:39 +00:00
|
|
|
if (i1.idx_ == i2.idx_)
|
2001-07-16 15:53:25 +00:00
|
|
|
i1.cell().erase(i1.pos_, i2.pos_);
|
2001-08-15 05:50:39 +00:00
|
|
|
else {
|
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)
|
|
|
|
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
|
|
|
|
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)
|
2001-08-14 11:19:19 +00:00
|
|
|
: formula_(formula), lastcode_(LM_TC_VAR), selection_(false)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
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
|
|
|
|
2001-08-08 07:12:09 +00:00
|
|
|
void MathCursor::pushLeft(MathInset * par)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-07-16 15:53:25 +00:00
|
|
|
MathCursorPos p;
|
|
|
|
p.par_ = par;
|
2001-08-08 07:12:09 +00:00
|
|
|
par->idxFirst(p.idx_, p.pos_);
|
2001-07-16 15:53:25 +00:00
|
|
|
Cursor_.push_back(p);
|
2001-04-24 16:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-08 07:12:09 +00:00
|
|
|
void MathCursor::pushRight(MathInset * par)
|
|
|
|
{
|
2001-08-08 07:46:16 +00:00
|
|
|
posLeft();
|
2001-08-08 07:12:09 +00:00
|
|
|
MathCursorPos p;
|
|
|
|
p.par_ = par;
|
|
|
|
par->idxLast(p.idx_, p.pos_);
|
|
|
|
Cursor_.push_back(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathCursor::popLeft()
|
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
|
|
|
}
|
|
|
|
|
2001-08-08 07:12:09 +00:00
|
|
|
bool MathCursor::popRight()
|
|
|
|
{
|
|
|
|
if (Cursor_.size() <= 1)
|
|
|
|
return false;
|
|
|
|
Cursor_.pop_back();
|
2001-08-08 07:46:16 +00:00
|
|
|
posRight();
|
2001-08-08 07:12:09 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-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";
|
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
//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-08-07 13:23:16 +00:00
|
|
|
void MathCursor::seldump(char const * str) 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-08-07 13:23:16 +00:00
|
|
|
lyxerr << "\n\n\n=================vvvvvvvvvvvvv======================= "
|
|
|
|
<< str << "\ntheSelection: " << selection_
|
|
|
|
<< " '" << theSelection.glue() << "'\n";
|
|
|
|
for (unsigned int i = 0; i < Cursor_.size(); ++i)
|
|
|
|
lyxerr << Cursor_[i].par_ << "\n'" << Cursor_[i].cell() << "'\n";
|
|
|
|
lyxerr << "\n";
|
|
|
|
for (unsigned int i = 0; i < Anchor_.size(); ++i)
|
|
|
|
lyxerr << Anchor_[i].par_ << "\n'" << Anchor_[i].cell() << "'\n";
|
2001-08-07 15:04:57 +00:00
|
|
|
//lyxerr << "\ncursor.pos_: " << pos();
|
2001-07-16 15:53:25 +00:00
|
|
|
//lyxerr << "\nanchor.pos_: " << anchor().pos_;
|
2001-08-07 13:23:16 +00:00
|
|
|
lyxerr << "\n===================^^^^^^^^^^^^=====================\n\n\n";
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2001-08-06 17:20:26 +00:00
|
|
|
bool MathCursor::isInside(MathInset const * p) const
|
2001-02-14 17:58:40 +00:00
|
|
|
{
|
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;
|
2001-08-07 12:02:21 +00:00
|
|
|
|
2001-07-26 06:46:50 +00:00
|
|
|
if (!(p->isActive() || (useupdown && p->isScriptInset())))
|
2001-07-16 15:53:25 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (sel) {
|
2001-07-25 09:32:38 +00:00
|
|
|
// we can't move into anything new during selection
|
2001-07-16 15:53:25 +00:00
|
|
|
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-08-08 07:46:16 +00:00
|
|
|
bool MathCursor::posLeft()
|
2001-07-13 14:54:56 +00:00
|
|
|
{
|
2001-08-08 07:46:16 +00:00
|
|
|
if (pos() == 0)
|
|
|
|
return false;
|
|
|
|
--pos();
|
|
|
|
return true;
|
2001-07-13 14:54:56 +00:00
|
|
|
}
|
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
|
2001-08-08 07:46:16 +00:00
|
|
|
bool MathCursor::posRight()
|
2001-08-07 12:02:21 +00:00
|
|
|
{
|
2001-08-08 07:46:16 +00:00
|
|
|
if (pos() == size())
|
|
|
|
return false;
|
|
|
|
++pos();
|
|
|
|
return true;
|
2001-08-07 12:02:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
bool MathCursor::left(bool sel)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
dump("Left 1");
|
2001-08-14 11:19:19 +00:00
|
|
|
if (inMacroMode()) {
|
|
|
|
macroModeClose();
|
2001-08-15 05:50:39 +00:00
|
|
|
lastcode_ = LM_TC_VAR;
|
2001-02-14 17:58:40 +00:00
|
|
|
return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-07-26 09:01:36 +00:00
|
|
|
selHandle(sel);
|
2001-08-13 14:02:37 +00:00
|
|
|
lastcode_ = LM_TC_VAR;
|
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-08-08 07:12:09 +00:00
|
|
|
pushRight(p);
|
2001-07-16 15:53:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
2001-08-08 07:46:16 +00:00
|
|
|
|
|
|
|
return posLeft() || idxLeft() || popLeft();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
bool MathCursor::right(bool sel)
|
2001-02-14 17:58:40 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
dump("Right 1");
|
2001-08-14 11:19:19 +00:00
|
|
|
if (inMacroMode()) {
|
2001-07-26 09:01:36 +00:00
|
|
|
macroModeClose();
|
2001-08-15 05:50:39 +00:00
|
|
|
lastcode_ = LM_TC_VAR;
|
2001-02-14 17:58:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
2001-07-26 09:01:36 +00:00
|
|
|
selHandle(sel);
|
2001-08-13 14:02:37 +00:00
|
|
|
lastcode_ = LM_TC_VAR;
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
MathInset * p = nextInset();
|
|
|
|
if (openable(p, sel, false)) {
|
2001-08-08 07:12:09 +00:00
|
|
|
pushLeft(p);
|
2001-07-16 15:53:25 +00:00
|
|
|
return true;
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
2001-08-08 07:46:16 +00:00
|
|
|
|
|
|
|
return posRight() || idxRight() || popRight();
|
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();
|
2001-08-08 07:12:09 +00:00
|
|
|
pushLeft(outerPar());
|
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-08-08 07:12:09 +00:00
|
|
|
first();
|
|
|
|
end();
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
void MathCursor::setPos(int x, int y)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-07-26 09:01:36 +00:00
|
|
|
dump("setPos 1");
|
|
|
|
//lyxerr << "MathCursor::setPos x: " << x << " y: " << y << "\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
macroModeClose();
|
2001-08-13 14:02:37 +00:00
|
|
|
lastcode_ = LM_TC_VAR;
|
2001-07-16 15:53:25 +00:00
|
|
|
first();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-08-06 17:20:26 +00:00
|
|
|
cursor().par_ = outerPar();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
while (1) {
|
2001-08-07 15:04:57 +00:00
|
|
|
idx() = -1;
|
2001-07-16 15:53:25 +00:00
|
|
|
cursor().pos_ = -1;
|
2001-08-07 15:04:57 +00:00
|
|
|
//lyxerr << "found idx: " << idx_ << " cursor: " << pos() << "\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
int distmin = 1 << 30; // large enough
|
2001-08-07 15:04:57 +00:00
|
|
|
for (int i = 0; i < par()->nargs(); ++i) {
|
|
|
|
MathXArray const & ar = 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;
|
2001-08-07 15:04:57 +00:00
|
|
|
idx() = i;
|
|
|
|
pos() = c;
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
|
|
|
}
|
2001-08-07 15:04:57 +00:00
|
|
|
//lyxerr << "found idx: " << idx() << " cursor: "
|
|
|
|
// << pos() << "\n";
|
2001-07-06 12:09:32 +00:00
|
|
|
MathInset * n = nextInset();
|
|
|
|
MathInset * p = prevInset();
|
2001-07-26 09:01:36 +00:00
|
|
|
if (openable(n, selection_, true) && n->covers(x, y))
|
2001-08-08 07:12:09 +00:00
|
|
|
pushLeft(n);
|
|
|
|
else if (openable(p, selection_, true) && p->covers(x, y))
|
|
|
|
pushRight(p);
|
|
|
|
else
|
2001-02-14 17:58:40 +00:00
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-07-26 09:01:36 +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-07-26 09:01:36 +00:00
|
|
|
void MathCursor::home()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-07-26 09:01:36 +00:00
|
|
|
dump("home 1");
|
|
|
|
macroModeClose();
|
2001-08-13 14:02:37 +00:00
|
|
|
lastcode_ = LM_TC_VAR;
|
2001-08-07 15:04:57 +00:00
|
|
|
if (!par()->idxHome(idx(), pos()))
|
2001-08-08 07:12:09 +00:00
|
|
|
popLeft();
|
2001-07-26 09:01:36 +00:00
|
|
|
dump("home 2");
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
void MathCursor::end()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-07-26 09:01:36 +00:00
|
|
|
dump("end 1");
|
|
|
|
macroModeClose();
|
2001-08-13 14:02:37 +00:00
|
|
|
lastcode_ = LM_TC_VAR;
|
2001-08-08 07:12:09 +00:00
|
|
|
if (!par()->idxEnd(idx(), pos()))
|
|
|
|
popRight();
|
2001-07-26 09:01:36 +00:00
|
|
|
dump("end 2");
|
2001-02-03 21:02:22 +00:00
|
|
|
}
|
|
|
|
|
2001-02-13 19:10:18 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
void MathCursor::plainErase()
|
2001-07-26 06:46:50 +00:00
|
|
|
{
|
2001-08-07 15:04:57 +00:00
|
|
|
array().erase(pos());
|
2001-07-26 06:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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-08-09 09:19:18 +00:00
|
|
|
array().insert(pos(), new MathCharInset(c, t));
|
2001-08-08 07:46:16 +00:00
|
|
|
posRight();
|
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-07-26 09:01:36 +00:00
|
|
|
macroModeClose();
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
if (selection_) {
|
2001-06-25 00:06:33 +00:00
|
|
|
if (p->nargs())
|
2001-07-26 09:01:36 +00:00
|
|
|
selCut();
|
2001-06-25 00:06:33 +00:00
|
|
|
else
|
2001-07-26 09:01:36 +00:00
|
|
|
selDel();
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
|
|
|
|
2001-08-07 15:04:57 +00:00
|
|
|
array().insert(pos(), p);
|
2001-08-08 07:46:16 +00:00
|
|
|
posRight();
|
2001-07-16 15:53:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-13 14:02:37 +00:00
|
|
|
void MathCursor::niceInsert(MathInset * p)
|
|
|
|
{
|
|
|
|
if (!p) {
|
|
|
|
lyxerr << "should not happen\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
selCut();
|
|
|
|
insert(p);
|
|
|
|
if (p->nargs()) {
|
|
|
|
posLeft();
|
|
|
|
right(); // do not push for e.g. MathSymbolInset
|
|
|
|
selPaste();
|
|
|
|
}
|
|
|
|
p->metrics(p->size());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
void MathCursor::insert(MathArray const & ar)
|
|
|
|
{
|
2001-07-26 09:01:36 +00:00
|
|
|
macroModeClose();
|
|
|
|
if (selection_)
|
|
|
|
selCut();
|
2001-07-16 15:53:25 +00:00
|
|
|
|
2001-08-07 15:04:57 +00:00
|
|
|
array().insert(pos(), ar);
|
|
|
|
pos() += ar.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathCursor::backspace()
|
|
|
|
{
|
|
|
|
if (inMacroMode()) {
|
|
|
|
left();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-08-08 07:46:16 +00:00
|
|
|
if (posLeft()) {
|
2001-08-07 15:04:57 +00:00
|
|
|
plainErase();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-08-08 07:46:16 +00:00
|
|
|
if (size()) {
|
2001-08-07 15:04:57 +00:00
|
|
|
pullArg(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
erase();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
void MathCursor::erase()
|
2001-02-14 17:58:40 +00:00
|
|
|
{
|
2001-07-26 09:01:36 +00:00
|
|
|
dump("erase 1");
|
2001-08-14 11:19:19 +00:00
|
|
|
if (inMacroMode())
|
2001-02-14 17:58:40 +00:00
|
|
|
return;
|
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
if (selection_) {
|
|
|
|
selDel();
|
2001-02-14 17:58:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-07-09 16:59:57 +00:00
|
|
|
// delete empty cells if necessary
|
2001-08-07 15:04:57 +00:00
|
|
|
if (pos() == 0 && array().empty()) {
|
2001-07-09 16:59:57 +00:00
|
|
|
bool popit;
|
|
|
|
bool removeit;
|
2001-08-07 15:04:57 +00:00
|
|
|
par()->idxDelete(idx(), popit, removeit);
|
2001-08-08 07:12:09 +00:00
|
|
|
if (popit && popLeft() && removeit)
|
2001-07-26 09:01:36 +00:00
|
|
|
plainErase();
|
2001-07-23 14:21:34 +00:00
|
|
|
return;
|
2001-06-27 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2001-08-08 07:46:16 +00:00
|
|
|
if (pos() < size())
|
2001-07-26 09:01:36 +00:00
|
|
|
plainErase();
|
2001-07-23 14:21:34 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
dump("erase 2");
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
void MathCursor::delLine()
|
2001-02-14 17:58:40 +00:00
|
|
|
{
|
2001-07-26 09:01:36 +00:00
|
|
|
macroModeClose();
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
if (selection_) {
|
|
|
|
selDel();
|
2001-02-14 17:58:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-08-07 15:04:57 +00:00
|
|
|
if (par()->nrows() > 1)
|
|
|
|
par()->delRow(row());
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
bool MathCursor::up(bool sel)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-07-26 09:01:36 +00:00
|
|
|
dump("up 1");
|
|
|
|
macroModeClose();
|
|
|
|
selHandle(sel);
|
2001-07-16 15:53:25 +00:00
|
|
|
|
2001-08-08 07:46:16 +00:00
|
|
|
if (selection_)
|
2001-08-08 11:03:53 +00:00
|
|
|
return goUp();
|
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-08-07 15:04:57 +00:00
|
|
|
int idxx, poss;
|
|
|
|
if (p->idxFirstUp(idxx, poss)) {
|
2001-08-08 07:12:09 +00:00
|
|
|
pushLeft(p);
|
2001-08-07 15:04:57 +00:00
|
|
|
idx() = idxx;
|
|
|
|
pos() = poss;
|
2001-07-26 09:01:36 +00:00
|
|
|
dump("up 3");
|
2001-06-27 14:10:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p = prevInset();
|
|
|
|
if (p) {
|
2001-08-07 15:04:57 +00:00
|
|
|
int idxx, poss;
|
|
|
|
if (p->idxLastUp(idxx, poss)) {
|
2001-08-08 07:12:09 +00:00
|
|
|
pushRight(p);
|
2001-08-07 15:04:57 +00:00
|
|
|
idx() = idxx;
|
|
|
|
pos() = poss;
|
2001-07-26 09:01:36 +00:00
|
|
|
dump("up 4");
|
2001-06-27 14:10:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-08 11:03:53 +00:00
|
|
|
return goUp();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
bool MathCursor::down(bool sel)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-07-26 09:01:36 +00:00
|
|
|
dump("down 1");
|
|
|
|
macroModeClose();
|
|
|
|
selHandle(sel);
|
2001-07-16 15:53:25 +00:00
|
|
|
|
2001-08-08 07:46:16 +00:00
|
|
|
if (selection_)
|
2001-08-08 11:03:53 +00:00
|
|
|
return goDown();
|
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-08-07 15:04:57 +00:00
|
|
|
int idxx = 0;
|
|
|
|
int poss = 0;
|
|
|
|
if (p->idxFirstDown(idxx, poss)) {
|
2001-08-08 07:12:09 +00:00
|
|
|
pushLeft(p);
|
2001-08-07 15:04:57 +00:00
|
|
|
idx() = idxx;
|
|
|
|
pos() = poss;
|
2001-06-27 14:10:35 +00:00
|
|
|
dump("Down 3");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p = prevInset();
|
|
|
|
if (p) {
|
2001-08-07 15:04:57 +00:00
|
|
|
int idxx = 0;
|
|
|
|
int poss = 0;
|
|
|
|
if (p->idxLastDown(idxx, poss)) {
|
2001-08-08 07:12:09 +00:00
|
|
|
pushRight(p);
|
2001-08-07 15:04:57 +00:00
|
|
|
idx() = idxx;
|
|
|
|
pos() = poss;
|
2001-06-27 14:10:35 +00:00
|
|
|
dump("Down 4");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-08 11:03:53 +00:00
|
|
|
return goDown();
|
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-08-03 09:54:48 +00:00
|
|
|
MathScriptInset * p = prevScriptInset();
|
2001-08-06 17:20:26 +00:00
|
|
|
if (!p)
|
|
|
|
return false;
|
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-07-26 09:01:36 +00:00
|
|
|
void MathCursor::setSize(MathStyles size)
|
2001-02-14 17:58:40 +00:00
|
|
|
{
|
2001-08-07 15:04:57 +00:00
|
|
|
par()->userSetSize(size);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-14 11:19:19 +00:00
|
|
|
void MathCursor::macroModeClose()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-08-14 11:19:19 +00:00
|
|
|
string s = macroName();
|
|
|
|
if (s.size()) {
|
|
|
|
pos() = pos() - s.size();
|
|
|
|
for (unsigned i = 0; i < s.size(); ++i)
|
|
|
|
plainErase();
|
2001-08-15 05:50:39 +00:00
|
|
|
lastcode_ = LM_TC_VAR;
|
2001-08-14 11:19:19 +00:00
|
|
|
interpret("\\" + s);
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-08-14 11:19:19 +00:00
|
|
|
string MathCursor::macroName() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-08-14 11:19:19 +00:00
|
|
|
string s;
|
|
|
|
int p = pos() - 1;
|
|
|
|
while (p >= 0 && array().nextInset(p)->code() == LM_TC_TEX) {
|
|
|
|
s = array().nextInset(p)->getChar() + s;
|
|
|
|
--p;
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
2001-08-14 11:19:19 +00:00
|
|
|
return s;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
void MathCursor::selCopy()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-07-26 09:01:36 +00:00
|
|
|
seldump("selCopy");
|
|
|
|
if (selection_) {
|
2001-07-16 15:53:25 +00:00
|
|
|
theSelection.grab(*this);
|
2001-07-26 09:01:36 +00:00
|
|
|
selClear();
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
void MathCursor::selCut()
|
2001-02-14 17:58:40 +00:00
|
|
|
{
|
2001-07-26 09:01:36 +00:00
|
|
|
seldump("selCut");
|
|
|
|
if (selection_) {
|
2001-07-16 15:53:25 +00:00
|
|
|
theSelection.grab(*this);
|
|
|
|
theSelection.erase(*this);
|
2001-08-07 13:23:16 +00:00
|
|
|
selClear();
|
|
|
|
} else {
|
|
|
|
theSelection.clear();
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
void MathCursor::selDel()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-07-26 09:01:36 +00:00
|
|
|
seldump("selDel");
|
|
|
|
if (selection_) {
|
2001-07-16 15:53:25 +00:00
|
|
|
theSelection.erase(*this);
|
2001-07-26 09:01:36 +00:00
|
|
|
selClear();
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
void MathCursor::selPaste()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-07-26 09:01:36 +00:00
|
|
|
seldump("selPaste");
|
2001-07-16 15:53:25 +00:00
|
|
|
theSelection.paste(*this);
|
2001-07-26 09:01:36 +00:00
|
|
|
selClear();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
void MathCursor::selHandle(bool sel)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-08-07 13:23:16 +00:00
|
|
|
if (sel == selection_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
theSelection.clear();
|
|
|
|
Anchor_ = Cursor_;
|
|
|
|
selection_ = sel;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
void MathCursor::selStart()
|
2001-02-14 17:58:40 +00:00
|
|
|
{
|
2001-07-26 09:01:36 +00:00
|
|
|
seldump("selStart");
|
|
|
|
if (selection_)
|
2001-06-25 00:06:33 +00:00
|
|
|
return;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-08-07 13:23:16 +00:00
|
|
|
theSelection.clear();
|
2001-07-16 15:53:25 +00:00
|
|
|
Anchor_ = Cursor_;
|
2001-07-26 09:01:36 +00:00
|
|
|
selection_ = true;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
void MathCursor::selClear()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-08-07 13:23:16 +00:00
|
|
|
seldump("selClear");
|
2001-07-26 09:01:36 +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-26 09:01:36 +00:00
|
|
|
if (!selection_)
|
2001-02-14 17:58:40 +00:00
|
|
|
return;
|
|
|
|
|
2001-07-16 15:53:25 +00:00
|
|
|
MathCursorPos i1;
|
|
|
|
MathCursorPos i2;
|
|
|
|
getSelection(i1, i2);
|
|
|
|
|
|
|
|
//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 {
|
|
|
|
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-08-09 08:53:16 +00:00
|
|
|
MathTextCodes MathCursor::nextCode() const
|
|
|
|
{
|
2001-08-13 14:02:37 +00:00
|
|
|
//return (pos() == size()) ? LM_TC_VAR : nextInset()->code();
|
|
|
|
return LM_TC_VAR;
|
2001-08-09 08:53:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-03 07:56:55 +00:00
|
|
|
void MathCursor::handleFont(MathTextCodes t)
|
|
|
|
{
|
2001-08-13 14:02:37 +00:00
|
|
|
macroModeClose();
|
2001-07-26 09:01:36 +00:00
|
|
|
if (selection_) {
|
2001-07-16 15:53:25 +00:00
|
|
|
MathCursorPos i1;
|
|
|
|
MathCursorPos i2;
|
|
|
|
getSelection(i1, i2);
|
|
|
|
if (i1.idx_ == i2.idx_) {
|
|
|
|
MathArray & ar = i1.cell();
|
2001-08-10 13:17:39 +00:00
|
|
|
for (int pos = i1.pos_; pos != i2.pos_; ++pos)
|
|
|
|
ar.nextInset(pos)->handleFont(t);
|
2001-07-16 15:53:25 +00:00
|
|
|
}
|
2001-07-26 09:01:36 +00:00
|
|
|
} else
|
|
|
|
lastcode_ = (lastcode_ == t) ? LM_TC_VAR : t;
|
2001-01-09 13:58:48 +00:00
|
|
|
}
|
2001-02-13 19:10:18 +00:00
|
|
|
|
|
|
|
|
2001-08-09 15:19:31 +00:00
|
|
|
void MathCursor::handleDelim(latexkeys const * l, latexkeys const * r)
|
2001-07-10 13:17:43 +00:00
|
|
|
{
|
2001-08-08 07:46:16 +00:00
|
|
|
handleNest(new MathDelimInset(l, r));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathCursor::handleNest(MathInset * p)
|
|
|
|
{
|
2001-07-26 09:01:36 +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-08-08 07:12:09 +00:00
|
|
|
pushRight(p);
|
2001-07-10 13:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
void MathCursor::getPos(int & x, int & y)
|
2001-02-13 19:10:18 +00:00
|
|
|
{
|
2001-08-08 09:31:36 +00:00
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
#warning This should probably take cellXOffset and cellYOffset into account
|
|
|
|
#endif
|
2001-08-07 15:04:57 +00:00
|
|
|
x = xarray().xo() + xarray().pos2x(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
|
|
|
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-08-07 15:04:57 +00:00
|
|
|
int MathCursor::idx() const
|
|
|
|
{
|
|
|
|
return cursor().idx_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int & MathCursor::idx()
|
|
|
|
{
|
|
|
|
return cursor().idx_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-08-07 15:04:57 +00:00
|
|
|
int & MathCursor::pos()
|
|
|
|
{
|
|
|
|
return cursor().pos_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
bool MathCursor::inMacroMode() const
|
2001-02-13 19:10:18 +00:00
|
|
|
{
|
2001-08-14 11:19:19 +00:00
|
|
|
return lastcode_ == LM_TC_TEX;
|
2001-02-13 19:10:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
bool MathCursor::selection() const
|
2001-02-13 19:10:18 +00:00
|
|
|
{
|
2001-07-26 09:01:36 +00:00
|
|
|
return selection_;
|
2001-02-13 19:10:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-01 13:28:45 +00:00
|
|
|
MathArrayInset * MathCursor::enclosingArray(int & idx) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-07-16 15:53:25 +00:00
|
|
|
for (int i = Cursor_.size() - 1; i >= 0; --i) {
|
2001-08-01 13:28:45 +00:00
|
|
|
if (Cursor_[i].par_->isArray()) {
|
2001-07-16 15:53:25 +00:00
|
|
|
idx = Cursor_[i].idx_;
|
2001-08-01 13:28:45 +00:00
|
|
|
return static_cast<MathArrayInset *>(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-08-08 07:12:09 +00:00
|
|
|
if (popLeft()) {
|
2001-07-26 09:01:36 +00:00
|
|
|
plainErase();
|
2001-08-07 15:04:57 +00:00
|
|
|
array().insert(pos(), a);
|
2001-07-23 14:15:14 +00:00
|
|
|
if (goright)
|
2001-08-07 15:04:57 +00:00
|
|
|
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-08-08 07:12:09 +00:00
|
|
|
if (idx() < 0)
|
|
|
|
lyxerr << "this should not really happen - 1: " << idx() << "\n";
|
|
|
|
if (idx() >= par()->nargs()) {
|
|
|
|
lyxerr << "this should not really happen - 2: "
|
|
|
|
<< idx() << " " << par()->nargs() << "\n";
|
|
|
|
dump("error 2");
|
|
|
|
}
|
2001-08-07 15:04:57 +00:00
|
|
|
it->idx() = max(idx(), 0);
|
|
|
|
it->idx() = min(idx(), par()->nargs() - 1);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-08-08 07:12:09 +00:00
|
|
|
if (pos() < 0)
|
|
|
|
lyxerr << "this should not really happen - 3: " << pos() << "\n";
|
2001-08-08 07:46:16 +00:00
|
|
|
if (pos() > size()) {
|
2001-08-08 07:12:09 +00:00
|
|
|
lyxerr << "this should not really happen - 4: "
|
2001-08-08 07:46:16 +00:00
|
|
|
<< pos() << " " << size() << "\n";
|
2001-08-08 07:12:09 +00:00
|
|
|
dump("error 4");
|
|
|
|
}
|
2001-08-07 15:04:57 +00:00
|
|
|
it->pos() = max(pos(), 0);
|
2001-08-08 07:46:16 +00:00
|
|
|
it->pos() = min(pos(), size());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MathCursor::size() const
|
|
|
|
{
|
|
|
|
return array().size();
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MathCursor::col() const
|
|
|
|
{
|
2001-08-07 15:04:57 +00:00
|
|
|
return par()->col(idx());
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MathCursor::row() const
|
|
|
|
{
|
2001-08-07 15:04:57 +00:00
|
|
|
return par()->row(idx());
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2001-07-26 09:01:36 +00:00
|
|
|
char MathCursorPos::getChar() const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-08-07 15:04:57 +00:00
|
|
|
return array().getChar(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())
|
2001-07-26 09:01:36 +00:00
|
|
|
s += getChar();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathInset * MathCursor::prevInset() const
|
|
|
|
{
|
|
|
|
normalize();
|
2001-08-07 15:04:57 +00:00
|
|
|
if (!pos())
|
2001-06-25 00:06:33 +00:00
|
|
|
return 0;
|
2001-08-07 15:04:57 +00:00
|
|
|
return array().nextInset(pos() - 1);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathInset * MathCursor::nextInset() const
|
|
|
|
{
|
|
|
|
normalize();
|
2001-08-07 15:04:57 +00:00
|
|
|
return array().nextInset(pos());
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-26 06:46:50 +00:00
|
|
|
MathScriptInset * MathCursor::prevScriptInset() const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
normalize();
|
2001-08-06 17:20:26 +00:00
|
|
|
MathInset * p = prevInset();
|
2001-07-26 06:46:50 +00:00
|
|
|
return (p && p->isScriptInset()) ? static_cast<MathScriptInset *>(p) : 0;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-25 14:15:05 +00:00
|
|
|
MathSpaceInset * MathCursor::prevSpaceInset() const
|
|
|
|
{
|
|
|
|
normalize();
|
2001-08-06 17:20:26 +00:00
|
|
|
MathInset * p = prevInset();
|
2001-07-25 14:15:05 +00:00
|
|
|
return (p && p->isSpaceInset()) ? static_cast<MathSpaceInset *>(p) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathArray & MathCursor::array() const
|
|
|
|
{
|
|
|
|
static MathArray dummy;
|
2001-08-07 15:04:57 +00:00
|
|
|
if (!par()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
lyxerr << "############ par_ not valid\n";
|
|
|
|
return dummy;
|
|
|
|
}
|
|
|
|
|
2001-08-07 15:04:57 +00:00
|
|
|
if (idx() < 0 || idx() >= par()->nargs()) {
|
|
|
|
lyxerr << "############ idx_ " << 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
void MathCursor::idxNext()
|
2001-04-24 16:13:38 +00:00
|
|
|
{
|
2001-08-07 15:04:57 +00:00
|
|
|
par()->idxNext(idx(), pos());
|
2001-07-06 12:09:32 +00:00
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
void MathCursor::idxPrev()
|
|
|
|
{
|
2001-08-07 15:04:57 +00:00
|
|
|
par()->idxPrev(idx(), pos());
|
2001-07-06 12:09:32 +00:00
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
void MathCursor::splitCell()
|
|
|
|
{
|
2001-08-07 15:04:57 +00:00
|
|
|
if (idx() == par()->nargs() - 1)
|
2001-07-06 12:09:32 +00:00
|
|
|
return;
|
|
|
|
MathArray ar = array();
|
2001-08-07 15:04:57 +00:00
|
|
|
ar.erase(0, pos());
|
2001-08-08 07:46:16 +00:00
|
|
|
array().erase(pos(), size());
|
2001-08-07 15:04:57 +00:00
|
|
|
++idx();
|
|
|
|
pos() = 0;
|
2001-07-06 12:09:32 +00:00
|
|
|
array().insert(0, ar);
|
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
void MathCursor::breakLine()
|
|
|
|
{
|
2001-08-08 15:35:49 +00:00
|
|
|
// leave inner cells
|
|
|
|
while (popRight())
|
|
|
|
;
|
|
|
|
|
2001-08-06 17:20:26 +00:00
|
|
|
MathMatrixInset * p = outerPar();
|
2001-07-26 06:56:43 +00:00
|
|
|
if (p->getType() == LM_OT_SIMPLE || p->getType() == LM_OT_EQUATION) {
|
2001-07-06 12:09:32 +00:00
|
|
|
p->mutate(LM_OT_EQNARRAY);
|
2001-08-08 15:35:49 +00:00
|
|
|
idx() = 0;
|
|
|
|
pos() = size();
|
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-08-07 15:04:57 +00:00
|
|
|
p->cell(idx()).swap(p->cell(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;
|
2001-08-01 13:28:45 +00:00
|
|
|
MathArrayInset * p = enclosingArray(idx);
|
2001-06-27 14:10:35 +00:00
|
|
|
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;
|
2001-08-01 13:28:45 +00:00
|
|
|
MathArrayInset * p = enclosingArray(idx);
|
2001-06-27 14:10:35 +00:00
|
|
|
return p ? p->halign(idx % p->ncols()) : 0;
|
|
|
|
}
|
2001-07-16 15:53:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
|
|
|
|
{
|
|
|
|
MathCursorPos anc = normalAnchor();
|
|
|
|
if (anc < cursor()) {
|
|
|
|
i1 = anc;
|
|
|
|
i2 = cursor();
|
|
|
|
} else {
|
|
|
|
i1 = cursor();
|
|
|
|
i2 = anc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathCursorPos & MathCursor::cursor()
|
|
|
|
{
|
|
|
|
return Cursor_.back();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathCursorPos const & MathCursor::cursor() const
|
|
|
|
{
|
|
|
|
return Cursor_.back();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-08 09:47:44 +00:00
|
|
|
int MathCursor::cellXOffset() const
|
2001-07-16 15:53:25 +00:00
|
|
|
{
|
2001-08-08 09:47:44 +00:00
|
|
|
return par()->cellXOffset(idx());
|
2001-07-16 15:53:25 +00:00
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-08-08 09:47:44 +00:00
|
|
|
int MathCursor::cellYOffset() const
|
2001-07-16 15:53:25 +00:00
|
|
|
{
|
2001-08-08 09:47:44 +00:00
|
|
|
return par()->cellYOffset(idx());
|
2001-07-16 15:53:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-08 09:47:44 +00:00
|
|
|
int MathCursor::xpos() const
|
2001-07-16 15:53:25 +00:00
|
|
|
{
|
2001-08-08 09:47:44 +00:00
|
|
|
return cellXOffset() + xarray().pos2x(pos());
|
2001-07-16 15:53:25 +00:00
|
|
|
}
|
|
|
|
|
2001-08-08 09:47:44 +00:00
|
|
|
|
|
|
|
int MathCursor::ypos() const
|
2001-07-16 15:53:25 +00:00
|
|
|
{
|
2001-08-08 09:47:44 +00:00
|
|
|
return cellYOffset();
|
2001-07-16 15:53:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-08 09:47:44 +00:00
|
|
|
|
|
|
|
void MathCursor::gotoX(int x)
|
2001-07-16 15:53:25 +00:00
|
|
|
{
|
2001-08-08 09:47:44 +00:00
|
|
|
pos() = xarray().x2pos(x - cellXOffset());
|
2001-07-16 15:53:25 +00:00
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-08-08 11:03:53 +00:00
|
|
|
bool MathCursor::goUp()
|
2001-07-16 15:53:25 +00:00
|
|
|
{
|
2001-08-08 15:35:49 +00:00
|
|
|
// first ask the inset if it knows better then we
|
|
|
|
if (par()->idxUp(idx(), pos()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// if not, apply brute force.
|
2001-08-08 11:03:53 +00:00
|
|
|
int x0;
|
|
|
|
int y0;
|
|
|
|
getPos(x0, y0);
|
|
|
|
std::vector<MathCursorPos> save = Cursor_;
|
|
|
|
y0 -= xarray().ascent();
|
|
|
|
for (int y = y0 - 4; y > outerPar()->yo() - outerPar()->ascent(); y -= 4) {
|
|
|
|
setPos(x0, y);
|
|
|
|
if (save != Cursor_ && xarray().yo() < y0)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Cursor_ = save;
|
|
|
|
return false;
|
2001-07-16 15:53:25 +00:00
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-08-08 11:03:53 +00:00
|
|
|
bool MathCursor::goDown()
|
2001-07-16 15:53:25 +00:00
|
|
|
{
|
2001-08-08 15:35:49 +00:00
|
|
|
// first ask the inset if it knows better then we
|
|
|
|
if (par()->idxDown(idx(), pos()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// if not, apply brute force.
|
2001-08-08 11:03:53 +00:00
|
|
|
int x0;
|
|
|
|
int y0;
|
|
|
|
getPos(x0, y0);
|
|
|
|
std::vector<MathCursorPos> save = Cursor_;
|
|
|
|
y0 += xarray().descent();
|
|
|
|
for (int y = y0 + 4; y < outerPar()->yo() + outerPar()->descent(); y += 4) {
|
|
|
|
setPos(x0, y);
|
|
|
|
if (save != Cursor_ && xarray().yo() > y0)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Cursor_ = save;
|
|
|
|
return false;
|
2001-07-16 15:53:25 +00:00
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-08-08 09:47:44 +00:00
|
|
|
bool MathCursor::idxLeft()
|
2001-08-08 09:31:36 +00:00
|
|
|
{
|
2001-08-08 09:47:44 +00:00
|
|
|
return par()->idxLeft(idx(), pos());
|
2001-08-08 09:31:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-08 09:47:44 +00:00
|
|
|
bool MathCursor::idxRight()
|
2001-08-08 09:31:36 +00:00
|
|
|
{
|
2001-08-08 09:47:44 +00:00
|
|
|
return par()->idxRight(idx(), pos());
|
2001-08-08 09:31:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-08 09:47:44 +00:00
|
|
|
MathMatrixInset * MathCursor::outerPar() const
|
2001-08-08 09:31:36 +00:00
|
|
|
{
|
2001-08-08 09:47:44 +00:00
|
|
|
return
|
|
|
|
static_cast<MathMatrixInset *>(const_cast<MathInset *>(formula_->par()));
|
2001-08-08 09:31:36 +00:00
|
|
|
}
|
|
|
|
|
2001-08-13 14:02:37 +00:00
|
|
|
|
|
|
|
void MathCursor::interpret(string const & s)
|
|
|
|
{
|
|
|
|
//lyxerr << "interpret: '" << s << "'\n";
|
|
|
|
//lyxerr << "in: " << in_word_set(s) << " \n";
|
|
|
|
|
|
|
|
if (s.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
char c = s[0];
|
|
|
|
|
2001-08-13 14:46:06 +00:00
|
|
|
//lyxerr << "char: '" << c << "' int: " << int(c) << endl;
|
2001-08-13 14:02:37 +00:00
|
|
|
//owner_->getIntl()->getTrans().TranslateAndInsert(c, lt);
|
|
|
|
//lyxerr << "trans: '" << c << "' int: " << int(c) << endl;
|
|
|
|
|
2001-08-17 17:23:12 +00:00
|
|
|
if (s.size() > 7 && s.substr(0, 7) == "matrix ") {
|
2001-08-13 14:02:37 +00:00
|
|
|
int m = 1;
|
|
|
|
int n = 1;
|
|
|
|
string v_align;
|
|
|
|
string h_align;
|
2001-08-17 17:23:12 +00:00
|
|
|
istringstream is(s.substr(7).c_str());
|
2001-08-13 14:02:37 +00:00
|
|
|
is >> m >> n >> v_align >> h_align;
|
|
|
|
m = std::max(1, m);
|
|
|
|
n = std::max(1, n);
|
|
|
|
v_align += 'c';
|
2001-08-13 14:46:06 +00:00
|
|
|
MathArrayInset * p = new MathArrayInset(m, n);
|
|
|
|
p->valign(v_align[0]);
|
|
|
|
p->halign(h_align);
|
|
|
|
niceInsert(p);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-08-17 17:50:00 +00:00
|
|
|
if (s == "\\over" || s == "\\choose" || s == "\\atop") {
|
2001-08-13 14:46:06 +00:00
|
|
|
MathArray ar = array();
|
2001-08-13 15:26:41 +00:00
|
|
|
MathInset * p = createMathInset(in_word_set(s.substr(1)));
|
2001-08-13 14:46:06 +00:00
|
|
|
p->cell(0).swap(array());
|
|
|
|
pos() = 0;
|
|
|
|
niceInsert(p);
|
2001-08-15 05:50:39 +00:00
|
|
|
popRight();
|
|
|
|
left();
|
2001-08-13 14:02:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-08-13 15:26:41 +00:00
|
|
|
if (s.size() > 1) {
|
2001-08-15 05:50:39 +00:00
|
|
|
niceInsert(createMathInset(s.substr(1)));
|
2001-08-13 15:26:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-08-13 14:02:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
// we got just a single char now
|
|
|
|
|
|
|
|
if (c == '^' || c == '_') {
|
|
|
|
bool const up = (s[0] == '^');
|
|
|
|
selCut();
|
|
|
|
MathScriptInset * p = prevScriptInset();
|
|
|
|
if (!p) {
|
|
|
|
MathInset * b = prevInset();
|
|
|
|
if (b && b->isScriptable()) {
|
|
|
|
p = new MathScriptInset(up, !up, b->clone());
|
|
|
|
posLeft();
|
|
|
|
plainErase();
|
|
|
|
} else
|
|
|
|
p = new MathScriptInset(up, !up);
|
|
|
|
insert(p);
|
|
|
|
}
|
|
|
|
pushRight(p);
|
|
|
|
if (up)
|
|
|
|
p->up(true);
|
|
|
|
else
|
|
|
|
p->down(true);
|
|
|
|
idx() = up ? 0 : 1;
|
|
|
|
pos() = 0;
|
|
|
|
selPaste();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == '{') {
|
|
|
|
niceInsert(new MathScopeInset);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isalpha(c) && (lastcode_ == LM_TC_GREEK || lastcode_ == LM_TC_GREEK1)) {
|
|
|
|
static char const greek[26] =
|
|
|
|
{'A', 'B', 'X', 0 , 'E', 0 , 0 , 'H', 'I', 0 ,
|
|
|
|
'K', 0 , 'M', 'N', 'O', 0 , 0 , 'P', 0 , 'T',
|
|
|
|
0, 0, 0, 0, 0 , 'Z' };
|
|
|
|
|
|
|
|
MathTextCodes code = LM_TC_SYMB;
|
|
|
|
if ('A' <= c && c <= 'Z' && greek[c - 'A']) {
|
|
|
|
code = LM_TC_RM;
|
|
|
|
c = greek[c - 'A'];
|
|
|
|
}
|
|
|
|
insert(c, code);
|
|
|
|
|
|
|
|
#warning greek insert problem? look here!
|
|
|
|
//if (lastcode_ == LM_TC_GREEK1)
|
|
|
|
lastcode_ = LM_TC_VAR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-08-14 11:19:19 +00:00
|
|
|
if (selection_)
|
|
|
|
selDel();
|
2001-08-13 14:02:37 +00:00
|
|
|
|
2001-08-14 11:19:19 +00:00
|
|
|
if (lastcode_ == LM_TC_TEX) {
|
|
|
|
if (macroName().empty()) {
|
|
|
|
insert(c, LM_TC_TEX);
|
2001-08-15 05:50:39 +00:00
|
|
|
if (!isalpha(c)) {
|
2001-08-14 11:19:19 +00:00
|
|
|
macroModeClose();
|
2001-08-15 05:50:39 +00:00
|
|
|
lastcode_ = LM_TC_VAR;
|
|
|
|
}
|
2001-08-14 11:19:19 +00:00
|
|
|
} else {
|
|
|
|
if (isalpha(c))
|
|
|
|
insert(c, LM_TC_TEX);
|
2001-08-15 05:50:39 +00:00
|
|
|
else {
|
2001-08-14 11:19:19 +00:00
|
|
|
macroModeClose();
|
2001-08-15 05:50:39 +00:00
|
|
|
lastcode_ = LM_TC_VAR;
|
|
|
|
}
|
2001-08-14 11:19:19 +00:00
|
|
|
}
|
2001-08-13 14:02:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
if (strchr("0123456789;:!|[]().,?+/-*<>=", c)) {
|
2001-08-13 14:02:37 +00:00
|
|
|
if (lastcode_ != LM_TC_TEXTRM)
|
2001-08-17 16:05:19 +00:00
|
|
|
lastcode_ = LM_TC_CONST;
|
2001-08-13 14:02:37 +00:00
|
|
|
insert(c, lastcode_);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strchr("#$%{|}", c)) {
|
|
|
|
if (lastcode_ != LM_TC_TEXTRM)
|
|
|
|
lastcode_ = LM_TC_SPECIAL;
|
|
|
|
insert(c, lastcode_);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == ' ') {
|
2001-08-14 11:19:19 +00:00
|
|
|
if (inMacroMode()) {
|
2001-08-13 14:02:37 +00:00
|
|
|
macroModeClose();
|
2001-08-15 05:50:39 +00:00
|
|
|
lastcode_ = LM_TC_VAR;
|
2001-08-13 14:02:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
MathSpaceInset * p = prevSpaceInset();
|
|
|
|
if (p) {
|
|
|
|
p->incSpace();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-08-13 14:02:37 +00:00
|
|
|
if (lastcode_ == LM_TC_TEXTRM) {
|
|
|
|
insert(c, LM_TC_TEXTRM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mathcursor->popRight())
|
|
|
|
return;
|
|
|
|
|
|
|
|
#warning look here
|
|
|
|
// this would not work if the inset is in an table!
|
|
|
|
//bv->text->cursorRight(bv, true);
|
|
|
|
//result = FINISHED;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == '\'' || c == '@') {
|
|
|
|
insert(c, LM_TC_VAR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == '\\') {
|
|
|
|
lastcode_ = LM_TC_TEX;
|
2001-08-14 11:19:19 +00:00
|
|
|
//bv->owner()->message(_("TeX mode"));
|
2001-08-13 14:02:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isalpha(c)) {
|
|
|
|
insert(c, lastcode_);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-08-14 07:46:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
bool operator==(MathCursorPos const & ti, MathCursorPos const & it)
|
|
|
|
{
|
|
|
|
return ti.par_ == it.par_ && ti.idx_ == it.idx_ && ti.pos_ == it.pos_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool operator<(MathCursorPos const & ti, MathCursorPos const & it)
|
|
|
|
{
|
|
|
|
if (ti.par_ != it.par_) {
|
|
|
|
lyxerr << "can't compare cursor and anchor in different insets\n";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (ti.idx_ != it.idx_)
|
|
|
|
return ti.idx_ < it.idx_;
|
|
|
|
return ti.pos_ < it.pos_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathXArray & MathCursorPos::xcell() const
|
|
|
|
{
|
|
|
|
return par_->xcell(idx_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathCursorPos MathCursor::normalAnchor() const
|
|
|
|
{
|
|
|
|
// use Anchor on the same level as Cursor
|
|
|
|
MathCursorPos normal = Anchor_[Cursor_.size() - 1];
|
|
|
|
if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
|
|
|
|
// anchor is behind cursor -> move anchor behind the inset
|
|
|
|
++normal.pos_;
|
|
|
|
}
|
|
|
|
return normal;
|
|
|
|
}
|
|
|
|
|