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-06-25 00:06:33 +00:00
|
|
|
#include "math_scriptinset.h"
|
2001-08-13 14:02:37 +00:00
|
|
|
#include "math_spaceinset.h"
|
2001-08-30 08:55:13 +00:00
|
|
|
#include "math_specialcharinset.h"
|
2001-07-17 07:38:41 +00:00
|
|
|
#include "math_parser.h"
|
2001-04-24 16:13:38 +00:00
|
|
|
|
2001-09-26 15:20:45 +00:00
|
|
|
#define FILEDEBUG 0
|
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
using std::endl;
|
2001-06-25 00:06:33 +00:00
|
|
|
using std::min;
|
|
|
|
using std::max;
|
2001-09-25 06:47:47 +00:00
|
|
|
using std::swap;
|
2001-07-06 12:09:32 +00:00
|
|
|
using std::isalnum;
|
2001-06-25 00:06:33 +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);
|
2001-10-10 13:20:51 +00:00
|
|
|
if (i1.idx_ == i2.idx_) {
|
|
|
|
MathArray ar;
|
|
|
|
if (i1.inner_) {
|
|
|
|
ar.push_back(*i1.at());
|
|
|
|
ar.back().removeNucleus();
|
|
|
|
++i1.pos_;
|
|
|
|
}
|
|
|
|
ar.push_back(MathArray(i1.cell(), i1.pos_, i2.pos_));
|
|
|
|
if (i2.inner_) {
|
|
|
|
ar.push_back(*i2.at());
|
|
|
|
ar.back().removeUp();
|
|
|
|
ar.back().removeDown();
|
|
|
|
}
|
|
|
|
data_.push_back(ar);
|
|
|
|
}
|
2001-07-16 15:53:25 +00:00
|
|
|
else {
|
2001-09-26 16:52:34 +00:00
|
|
|
std::vector<MathInset::idx_type> indices =
|
|
|
|
i1.par_->idxBetween(i1.idx_, i2.idx_);
|
|
|
|
for (MathInset::idx_type i = 0; i < indices.size(); ++i)
|
2001-07-16 15:53:25 +00:00
|
|
|
data_.push_back(i1.cell(indices[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void erase(MathCursor & cursor)
|
|
|
|
{
|
|
|
|
MathCursorPos i1;
|
|
|
|
MathCursorPos i2;
|
|
|
|
cursor.getSelection(i1, i2);
|
2001-10-10 13:20:51 +00:00
|
|
|
if (i1.idx_ == i2.idx_) {
|
|
|
|
if (i1.inner_) {
|
|
|
|
i1.inner_ = false;
|
|
|
|
i1.at()->removeUp();
|
|
|
|
i1.at()->removeDown();
|
|
|
|
++i1.pos_;
|
|
|
|
}
|
|
|
|
if (i2.inner_) {
|
|
|
|
i2.inner_ = false;
|
|
|
|
i2.at()->removeNucleus();
|
|
|
|
}
|
2001-07-16 15:53:25 +00:00
|
|
|
i1.cell().erase(i1.pos_, i2.pos_);
|
2001-10-10 13:20:51 +00:00
|
|
|
} else {
|
|
|
|
std::vector<MathInset::idx_type> indices =
|
|
|
|
i1.par_->idxBetween(i1.idx_, i2.idx_);
|
2001-07-16 15:53:25 +00:00
|
|
|
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-09-26 15:20:45 +00:00
|
|
|
#if FILEDEBUG
|
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_
|
2001-10-10 13:20:51 +00:00
|
|
|
<< " pos: " << p.pos_ << " inner: " << p.inner_ << ")";
|
2001-07-16 15:53:25 +00:00
|
|
|
return os;
|
|
|
|
}
|
2001-09-26 15:20:45 +00:00
|
|
|
#endif
|
2001-07-16 15:53:25 +00:00
|
|
|
|
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;
|
2001-10-10 13:20:51 +00:00
|
|
|
p.par_ = par;
|
|
|
|
p.inner_ = false;
|
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;
|
2001-10-10 13:20:51 +00:00
|
|
|
p.par_ = par;
|
|
|
|
p.inner_ = false;
|
2001-08-08 07:12:09 +00:00
|
|
|
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-09-24 16:25:06 +00:00
|
|
|
if (nextAtom())
|
|
|
|
nextAtom()->removeEmptyScripts();
|
2001-07-16 15:53:25 +00:00
|
|
|
Cursor_.pop_back();
|
2001-09-24 16:25:06 +00:00
|
|
|
if (nextAtom())
|
|
|
|
nextAtom()->removeEmptyScripts();
|
2001-06-27 14:10:35 +00:00
|
|
|
return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2001-09-11 10:58:17 +00:00
|
|
|
|
2001-08-08 07:12:09 +00:00
|
|
|
bool MathCursor::popRight()
|
|
|
|
{
|
|
|
|
if (Cursor_.size() <= 1)
|
|
|
|
return false;
|
2001-09-24 16:25:06 +00:00
|
|
|
if (nextAtom())
|
|
|
|
nextAtom()->removeEmptyScripts();
|
2001-08-08 07:12:09 +00:00
|
|
|
Cursor_.pop_back();
|
2001-09-24 16:25:06 +00:00
|
|
|
if (nextAtom())
|
|
|
|
nextAtom()->removeEmptyScripts();
|
2001-08-08 07:46:16 +00:00
|
|
|
posRight();
|
2001-08-08 07:12:09 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-09-26 15:20:45 +00:00
|
|
|
#if FILEDEBUG
|
2001-09-24 13:38:52 +00:00
|
|
|
void MathCursor::dump(char const *) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
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-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
|
|
|
|
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-09-26 15:20:45 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
void MathCursor::seldump(char const *) const {}
|
|
|
|
void MathCursor::dump(char const *) const {}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-08-06 17:20:26 +00:00
|
|
|
bool MathCursor::isInside(MathInset const * p) const
|
2001-02-14 17:58:40 +00:00
|
|
|
{
|
2001-07-16 15:53:25 +00:00
|
|
|
for (unsigned i = 0; i < Cursor_.size(); ++i)
|
2001-10-01 12:23:00 +00:00
|
|
|
if (Cursor_[i].par_ == p)
|
2001-06-25 00:06:33 +00:00
|
|
|
return true;
|
2001-07-16 15:53:25 +00:00
|
|
|
return false;
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-08-20 13:45:02 +00:00
|
|
|
bool MathCursor::openable(MathInset * p, bool sel) const
|
2001-07-16 15:53:25 +00:00
|
|
|
{
|
|
|
|
if (!p)
|
|
|
|
return false;
|
2001-08-07 12:02:21 +00:00
|
|
|
|
2001-08-20 13:45:02 +00:00
|
|
|
if (!p->isActive())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (sel) {
|
|
|
|
// we can't move into anything new during selection
|
|
|
|
if (Cursor_.size() == Anchor_.size())
|
|
|
|
return false;
|
|
|
|
if (p != Anchor_[Cursor_.size()].par_)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-11 12:46:58 +00:00
|
|
|
MathInset * MathCursor::positionable(MathAtom * t, int x, int y) const
|
2001-08-20 13:45:02 +00:00
|
|
|
{
|
2001-09-11 12:46:58 +00:00
|
|
|
if (!t)
|
|
|
|
return 0;
|
2001-07-16 15:53:25 +00:00
|
|
|
|
2001-09-11 12:46:58 +00:00
|
|
|
if (selection_) {
|
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())
|
2001-09-11 12:46:58 +00:00
|
|
|
return 0;
|
|
|
|
//if (t != Anchor_[Cursor_.size()].par_)
|
|
|
|
// return 0;
|
2001-07-16 15:53:25 +00:00
|
|
|
}
|
2001-09-11 12:46:58 +00:00
|
|
|
|
|
|
|
MathInset * p;
|
|
|
|
|
|
|
|
p = t->nucleus();
|
|
|
|
if (p && p->nargs() && p->covers(x, y))
|
|
|
|
return p;
|
|
|
|
|
|
|
|
p = t->up();
|
|
|
|
if (p && p->nargs() && p->covers(x, y))
|
|
|
|
return p;
|
|
|
|
|
|
|
|
p = t->down();
|
|
|
|
if (p && p->nargs() && p->covers(x, y))
|
|
|
|
return p;
|
|
|
|
|
|
|
|
return 0;
|
2001-07-16 15:53:25 +00:00
|
|
|
}
|
|
|
|
|
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-10-10 13:20:51 +00:00
|
|
|
if (inner()) {
|
|
|
|
inner() = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2001-08-08 07:46:16 +00:00
|
|
|
if (pos() == 0)
|
|
|
|
return false;
|
2001-10-10 13:20:51 +00:00
|
|
|
|
2001-08-08 07:46:16 +00:00
|
|
|
--pos();
|
2001-10-10 13:20:51 +00:00
|
|
|
|
|
|
|
if (nextAtom()->hasInner())
|
|
|
|
inner() = true;
|
|
|
|
|
2001-08-08 07:46:16 +00:00
|
|
|
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-10-10 13:20:51 +00:00
|
|
|
if (inner()) {
|
|
|
|
++pos();
|
|
|
|
inner() = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2001-08-08 07:46:16 +00:00
|
|
|
if (pos() == size())
|
|
|
|
return false;
|
2001-10-10 13:20:51 +00:00
|
|
|
|
|
|
|
if (nextAtom()->hasInner())
|
|
|
|
inner() = true;
|
|
|
|
else
|
|
|
|
++pos();
|
|
|
|
|
2001-08-08 07:46:16 +00:00
|
|
|
return true;
|
2001-08-07 12:02:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
bool MathCursor::left(bool sel)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
dump("Left 1");
|
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();
|
2001-08-20 13:45:02 +00:00
|
|
|
if (openable(p, sel)) {
|
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();
|
2001-08-20 13:45:02 +00:00
|
|
|
if (openable(p, sel)) {
|
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-09-11 12:46:58 +00:00
|
|
|
//dump("setPos 1");
|
2001-07-26 09:01:36 +00:00
|
|
|
//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-09-26 15:20:45 +00:00
|
|
|
idx() = 0;
|
|
|
|
cursor().pos_ = 0;
|
2001-09-11 12:46:58 +00:00
|
|
|
//lyxerr << "found idx: " << idx() << " cursor: " << pos() << "\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
int distmin = 1 << 30; // large enough
|
2001-09-26 15:20:45 +00:00
|
|
|
for (unsigned int i = 0; i < par()->nargs(); ++i) {
|
2001-08-07 15:04:57 +00:00
|
|
|
MathXArray const & ar = par()->xcell(i);
|
2001-06-25 00:06:33 +00:00
|
|
|
int x1 = x - ar.xo();
|
|
|
|
int y1 = y - ar.yo();
|
2001-10-01 12:10:32 +00:00
|
|
|
MathXArray::size_type c = ar.x2pos(x1);
|
2001-10-10 13:20:51 +00:00
|
|
|
int xx = abs(x1 - ar.pos2x(c, false));
|
2001-06-25 00:06:33 +00:00
|
|
|
int yy = abs(y1);
|
|
|
|
//lyxerr << "idx: " << i << " xx: " << xx << " yy: " << yy
|
|
|
|
// << " c: " << c << " xo: " << ar.xo() << "\n";
|
|
|
|
if (yy + xx <= distmin) {
|
2001-09-11 12:46:58 +00:00
|
|
|
distmin = yy + xx;
|
|
|
|
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-09-11 12:46:58 +00:00
|
|
|
if (MathInset * p = positionable(nextAtom(), x, y))
|
|
|
|
pushLeft(p);
|
|
|
|
else if (MathInset * p = positionable(prevAtom(), x, y))
|
2001-08-08 07:12:09 +00:00
|
|
|
pushRight(p);
|
|
|
|
else
|
2001-02-14 17:58:40 +00:00
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-09-11 12:46:58 +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-08-30 10:17:28 +00:00
|
|
|
void MathCursor::home(bool sel)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-07-26 09:01:36 +00:00
|
|
|
dump("home 1");
|
2001-08-30 10:17:28 +00:00
|
|
|
selHandle(sel);
|
2001-07-26 09:01:36 +00:00
|
|
|
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-08-30 10:17:28 +00:00
|
|
|
void MathCursor::end(bool sel)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-07-26 09:01:36 +00:00
|
|
|
dump("end 1");
|
2001-08-30 10:17:28 +00:00
|
|
|
selHandle(sel);
|
2001-07-26 09:01:36 +00:00
|
|
|
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-10-10 13:20:51 +00:00
|
|
|
void MathCursor::plainInsert(MathInset * p)
|
|
|
|
{
|
|
|
|
if (inner()) {
|
|
|
|
array().insert(pos(), p);
|
|
|
|
++pos();
|
2001-10-10 16:35:18 +00:00
|
|
|
if (prevAtom() && nextAtom()) // should be unnecessary
|
|
|
|
swap(prevAtom()->nucleus(), nextAtom()->nucleus());
|
2001-10-10 13:20:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MathAtom * n = nextAtom();
|
|
|
|
|
|
|
|
if (n && !n->nucleus()) {
|
|
|
|
n->nucleus() = p;
|
|
|
|
inner() = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
array().insert(pos(), p); // this invalidates the pointer!
|
|
|
|
++pos();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-10-10 13:20:51 +00:00
|
|
|
plainInsert(new MathCharInset(c, 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-07-26 09:01:36 +00:00
|
|
|
macroModeClose();
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-10-10 13:20:51 +00:00
|
|
|
if (p && 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-10-10 13:20:51 +00:00
|
|
|
plainInsert(p);
|
2001-07-16 15:53:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-13 14:02:37 +00:00
|
|
|
void MathCursor::niceInsert(MathInset * p)
|
|
|
|
{
|
|
|
|
if (!p) {
|
2001-10-10 16:35:18 +00:00
|
|
|
lyxerr << "MathCursor::niceInsert: should not happen\n";
|
2001-08-13 14:02:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
selCut();
|
2001-09-11 10:58:17 +00:00
|
|
|
//cerr << "\n2: "; p->write(cerr, true); cerr << "\n";
|
|
|
|
insert(p); // inserting invalidates the pointer!
|
|
|
|
p = prevAtom()->nucleus();
|
|
|
|
//cerr << "\n3: "; p->write(cerr, true); cerr << "\n";
|
2001-08-13 14:02:37 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-10 13:20:51 +00:00
|
|
|
void MathCursor::glueAdjacentAtoms()
|
|
|
|
{
|
|
|
|
MathAtom * p = prevAtom();
|
|
|
|
if (!p)
|
|
|
|
return;
|
|
|
|
|
|
|
|
MathAtom * n = nextAtom();
|
|
|
|
if (!n)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (p->up() && n->up())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (p->down() && n->down())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// move everything to the previous atom
|
|
|
|
if (n->up())
|
|
|
|
swap(p->up(), n->up());
|
|
|
|
|
|
|
|
if (n->down())
|
|
|
|
swap(p->down(), n->down());
|
|
|
|
|
|
|
|
plainErase();
|
|
|
|
--pos();
|
|
|
|
inner() = nextAtom()->hasInner();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-07 15:04:57 +00:00
|
|
|
void MathCursor::backspace()
|
|
|
|
{
|
2001-10-10 13:20:51 +00:00
|
|
|
if (inner()) {
|
|
|
|
nextAtom()->removeNucleus();
|
|
|
|
inner() = false;
|
|
|
|
glueAdjacentAtoms();
|
2001-08-07 15:04:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-10-10 13:20:51 +00:00
|
|
|
if (pos() == 0) {
|
2001-10-10 16:35:18 +00:00
|
|
|
pullArg(false);
|
2001-10-10 13:20:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prevAtom()->hasInner()) {
|
|
|
|
--pos();
|
|
|
|
inner() = true;
|
2001-08-07 15:04:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-10-10 13:20:51 +00:00
|
|
|
--pos();
|
|
|
|
plainErase();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
void MathCursor::erase()
|
2001-02-14 17:58:40 +00:00
|
|
|
{
|
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-10-10 13:20:51 +00:00
|
|
|
if (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-10-10 13:20:51 +00:00
|
|
|
MathAtom * n = nextAtom();
|
|
|
|
|
|
|
|
if (!n)
|
2001-09-24 16:25:06 +00:00
|
|
|
return;
|
|
|
|
|
2001-10-10 13:20:51 +00:00
|
|
|
if (inner()) {
|
2001-09-24 16:25:06 +00:00
|
|
|
if (n->up())
|
2001-10-10 13:20:51 +00:00
|
|
|
n->removeUp();
|
|
|
|
else if (n->down())
|
|
|
|
n->removeDown();
|
|
|
|
if (!n->up() && !n->down()) {
|
|
|
|
++pos();
|
|
|
|
inner() = false;
|
|
|
|
}
|
2001-09-24 16:25:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-10-10 13:20:51 +00:00
|
|
|
if (n->hasInner()) {
|
|
|
|
n->removeNucleus();
|
|
|
|
inner() = true;
|
2001-10-10 14:30:28 +00:00
|
|
|
glueAdjacentAtoms();
|
2001-10-10 13:20:51 +00:00
|
|
|
return;
|
2001-09-24 16:25:06 +00:00
|
|
|
}
|
2001-07-23 14:21:34 +00:00
|
|
|
|
2001-09-24 16:25:06 +00:00
|
|
|
plainErase();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
void MathCursor::delLine()
|
2001-02-14 17:58:40 +00:00
|
|
|
{
|
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-09-11 10:58:17 +00:00
|
|
|
// check whether we could move into a superscript on the right or on the left
|
|
|
|
if (prevAtom() && prevAtom()->up()) {
|
|
|
|
pushRight(prevAtom()->up());
|
|
|
|
return true;
|
2001-06-27 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2001-09-11 10:58:17 +00:00
|
|
|
if (nextAtom() && nextAtom()->up()) {
|
|
|
|
pushLeft(nextAtom()->up());
|
|
|
|
return true;
|
2001-06-27 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
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-09-11 10:58:17 +00:00
|
|
|
// check whether we could move into an subscript on the right or on the left
|
|
|
|
if (prevAtom() && prevAtom()->down()) {
|
|
|
|
pushRight(prevAtom()->down());
|
|
|
|
return true;
|
2001-06-27 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2001-09-11 10:58:17 +00:00
|
|
|
if (nextAtom() && nextAtom()->down()) {
|
|
|
|
pushLeft(nextAtom()->down());
|
|
|
|
return true;
|
2001-06-27 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
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-09-11 10:58:17 +00:00
|
|
|
MathAtom * t = prevAtom();
|
|
|
|
if (!t)
|
2001-08-06 17:20:26 +00:00
|
|
|
return false;
|
2001-09-11 10:58:17 +00:00
|
|
|
int old = t->limits();
|
|
|
|
t->limits(old < 0 ? 1 : -1);
|
|
|
|
return old != t->limits();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-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()) {
|
2001-10-10 16:35:18 +00:00
|
|
|
size_type old = pos();
|
|
|
|
pos() -= s.size();
|
|
|
|
array().erase(pos(), old);
|
|
|
|
interpret(s);
|
2001-08-14 11:19:19 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-10-10 16:35:18 +00:00
|
|
|
int MathCursor::macroNamePos() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-10-10 16:35:18 +00:00
|
|
|
for (int i = pos() - 1; i >= 0; --i) {
|
2001-09-11 10:58:17 +00:00
|
|
|
MathInset * p = array().at(i)->nucleus();
|
2001-10-10 16:35:18 +00:00
|
|
|
if (p && p->code() == LM_TC_TEX && p->getChar() == '\\')
|
|
|
|
return i;
|
2001-02-14 17:58:40 +00:00
|
|
|
}
|
2001-10-10 16:35:18 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string MathCursor::macroName() const
|
|
|
|
{
|
|
|
|
string s;
|
|
|
|
for (int i = macroNamePos(); i >= 0 && i < int(pos()); ++i)
|
|
|
|
s += array().at(i)->nucleus()->getChar();
|
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();
|
2001-10-10 13:20:51 +00:00
|
|
|
int x1 = c.xo() + c.pos2x(i1.pos_, i1.inner_);
|
2001-07-16 15:53:25 +00:00
|
|
|
int y1 = c.yo() - c.ascent();
|
2001-10-10 13:20:51 +00:00
|
|
|
int x2 = c.xo() + c.pos2x(i2.pos_, i2.inner_);
|
2001-07-16 15:53:25 +00:00
|
|
|
int y2 = c.yo() + c.descent();
|
|
|
|
pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
|
|
|
|
} else {
|
2001-10-01 12:10:32 +00:00
|
|
|
std::vector<MathInset::idx_type> indices = i1.par_->idxBetween(i1.idx_, i2.idx_);
|
2001-07-16 15:53:25 +00:00
|
|
|
for (unsigned i = 0; i < indices.size(); ++i) {
|
|
|
|
MathXArray & c = i1.xcell(indices[i]);
|
|
|
|
int x1 = c.xo();
|
|
|
|
int y1 = c.yo() - c.ascent();
|
|
|
|
int x2 = c.xo() + c.width();
|
|
|
|
int y2 = c.yo() + c.descent();
|
|
|
|
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-10-01 12:10:32 +00:00
|
|
|
for (MathInset::pos_type pos = i1.pos_;
|
|
|
|
pos != i2.pos_; ++pos) {
|
2001-09-11 10:58:17 +00:00
|
|
|
MathInset * p = ar.at(pos)->nucleus();
|
|
|
|
if (p)
|
|
|
|
p->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-09-12 12:51:55 +00:00
|
|
|
void MathCursor::handleDelim(string const & l, string const & r)
|
2001-07-10 13:17:43 +00:00
|
|
|
{
|
2001-08-08 07:46:16 +00:00
|
|
|
handleNest(new MathDelimInset(l, r));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathCursor::handleNest(MathInset * p)
|
|
|
|
{
|
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
|
|
|
}
|
2001-09-11 10:58:17 +00:00
|
|
|
insert(p); // this invalidates p!
|
|
|
|
p = prevAtom()->nucleus();
|
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-10-10 13:20:51 +00:00
|
|
|
x = xarray().xo() + xarray().pos2x(pos(), inner());
|
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-10-01 12:10:32 +00:00
|
|
|
MathCursor::idx_type MathCursor::idx() const
|
2001-08-07 15:04:57 +00:00
|
|
|
{
|
|
|
|
return cursor().idx_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-01 12:10:32 +00:00
|
|
|
MathCursor::idx_type & MathCursor::idx()
|
2001-08-07 15:04:57 +00:00
|
|
|
{
|
|
|
|
return cursor().idx_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-01 12:10:32 +00:00
|
|
|
MathCursor::pos_type MathCursor::pos() const
|
2001-02-13 19:10:18 +00:00
|
|
|
{
|
2001-07-16 15:53:25 +00:00
|
|
|
return cursor().pos_;
|
2001-02-13 19:10:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-01 12:10:32 +00:00
|
|
|
MathCursor::pos_type & MathCursor::pos()
|
2001-08-07 15:04:57 +00:00
|
|
|
{
|
|
|
|
return cursor().pos_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-10 13:20:51 +00:00
|
|
|
bool MathCursor::inner() const
|
|
|
|
{
|
|
|
|
return cursor().inner_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool & MathCursor::inner()
|
|
|
|
{
|
|
|
|
return cursor().inner_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
bool MathCursor::inMacroMode() const
|
2001-02-13 19:10:18 +00:00
|
|
|
{
|
2001-10-10 16:35:18 +00:00
|
|
|
return macroNamePos() != -1;
|
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-10-01 12:10:32 +00:00
|
|
|
MathArrayInset * MathCursor::enclosingArray(MathCursor::idx_type & 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
|
|
|
{
|
2001-07-23 13:52:48 +00:00
|
|
|
dump("pullarg");
|
2001-06-25 00:06:33 +00:00
|
|
|
MathArray a = array();
|
2001-10-10 16:35:18 +00:00
|
|
|
|
|
|
|
MathScriptInset const * p = par()->asScriptInset();
|
|
|
|
if (p) {
|
|
|
|
// special handling for scripts
|
|
|
|
const bool up = p->up();
|
|
|
|
popLeft();
|
|
|
|
if (nextAtom()) {
|
|
|
|
if (up)
|
|
|
|
nextAtom()->removeUp();
|
|
|
|
else
|
|
|
|
nextAtom()->removeDown();
|
|
|
|
}
|
|
|
|
++pos();
|
|
|
|
array().insert(pos(), a);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-08-08 07:12:09 +00:00
|
|
|
if (popLeft()) {
|
2001-07-26 09:01:36 +00:00
|
|
|
plainErase();
|
2001-08-07 15:04:57 +00:00
|
|
|
array().insert(pos(), a);
|
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() >= par()->nargs()) {
|
2001-09-26 15:20:45 +00:00
|
|
|
lyxerr << "this should not really happen - 1: "
|
2001-08-08 07:12:09 +00:00
|
|
|
<< idx() << " " << par()->nargs() << "\n";
|
|
|
|
dump("error 2");
|
|
|
|
}
|
2001-08-07 15:04:57 +00:00
|
|
|
it->idx() = min(idx(), par()->nargs() - 1);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-08-08 07:46:16 +00:00
|
|
|
if (pos() > size()) {
|
2001-09-26 15:20:45 +00:00
|
|
|
lyxerr << "this should not really happen - 2: "
|
2001-08-08 07:46:16 +00:00
|
|
|
<< pos() << " " << size() << "\n";
|
2001-08-08 07:12:09 +00:00
|
|
|
dump("error 4");
|
|
|
|
}
|
2001-08-08 07:46:16 +00:00
|
|
|
it->pos() = min(pos(), size());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-01 12:10:32 +00:00
|
|
|
MathCursor::size_type MathCursor::size() const
|
2001-08-08 07:46:16 +00:00
|
|
|
{
|
|
|
|
return array().size();
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-01 12:10:32 +00:00
|
|
|
MathCursor::col_type MathCursor::col() const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-08-07 15:04:57 +00:00
|
|
|
return par()->col(idx());
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-01 12:10:32 +00:00
|
|
|
MathCursor::row_type MathCursor::row() const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
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
|
|
|
|
{
|
2001-09-11 10:58:17 +00:00
|
|
|
return prevAtom() ? prevAtom()->nucleus() : 0;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathInset * MathCursor::nextInset() const
|
|
|
|
{
|
2001-09-11 10:58:17 +00:00
|
|
|
return nextAtom() ? nextAtom()->nucleus() : 0;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-11 10:58:17 +00:00
|
|
|
MathSpaceInset * MathCursor::prevSpaceInset() const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-08-06 17:20:26 +00:00
|
|
|
MathInset * p = prevInset();
|
2001-09-11 10:58:17 +00:00
|
|
|
return (p && p->isSpaceInset()) ? static_cast<MathSpaceInset *>(p) : 0;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-11 10:58:17 +00:00
|
|
|
MathAtom const * MathCursor::prevAtom() const
|
2001-07-25 14:15:05 +00:00
|
|
|
{
|
2001-09-11 10:58:17 +00:00
|
|
|
return array().at(pos() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathAtom * MathCursor::prevAtom()
|
|
|
|
{
|
|
|
|
return array().at(pos() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathAtom const * MathCursor::nextAtom() const
|
|
|
|
{
|
|
|
|
return array().at(pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathAtom * MathCursor::nextAtom()
|
|
|
|
{
|
|
|
|
return array().at(pos());
|
2001-07-25 14:15:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathArray & MathCursor::array() const
|
|
|
|
{
|
|
|
|
static MathArray dummy;
|
2001-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-09-26 15:20:45 +00:00
|
|
|
if (idx() >= par()->nargs()) {
|
2001-08-07 15:04:57 +00:00
|
|
|
lyxerr << "############ idx_ " << idx() << " not valid\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
return dummy;
|
|
|
|
}
|
|
|
|
|
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
|
2001-10-01 12:10:32 +00:00
|
|
|
const row_type r = row();
|
|
|
|
for (col_type c = col() + 1; c < p->ncols(); ++c) {
|
|
|
|
const MathMatrixInset::idx_type i1 = p->index(r, c);
|
|
|
|
const MathMatrixInset::idx_type i2 = p->index(r + 1, c);
|
2001-07-09 16:59:57 +00:00
|
|
|
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
|
|
|
|
{
|
2001-10-01 12:10:32 +00:00
|
|
|
idx_type idx;
|
2001-08-01 13:28:45 +00:00
|
|
|
MathArrayInset * p = enclosingArray(idx);
|
2001-10-01 12:10:32 +00:00
|
|
|
return p ? p->valign() : '\0';
|
2001-06-27 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2001-07-16 18:58:13 +00:00
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
char MathCursor::halign() const
|
|
|
|
{
|
2001-10-01 12:10:32 +00:00
|
|
|
idx_type idx;
|
2001-08-01 13:28:45 +00:00
|
|
|
MathArrayInset * p = enclosingArray(idx);
|
2001-10-01 12:10:32 +00:00
|
|
|
return p ? p->halign(idx % p->ncols()) : '\0';
|
2001-06-27 14:10:35 +00:00
|
|
|
}
|
2001-07-16 15:53:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
|
|
|
|
{
|
|
|
|
MathCursorPos anc = normalAnchor();
|
|
|
|
if (anc < cursor()) {
|
|
|
|
i1 = anc;
|
|
|
|
i2 = cursor();
|
|
|
|
} else {
|
|
|
|
i1 = cursor();
|
|
|
|
i2 = anc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathCursorPos & MathCursor::cursor()
|
|
|
|
{
|
|
|
|
return Cursor_.back();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathCursorPos const & MathCursor::cursor() const
|
|
|
|
{
|
|
|
|
return Cursor_.back();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-01 12:10:32 +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-10-01 12:10:32 +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-10-10 13:20:51 +00:00
|
|
|
return cellXOffset() + xarray().pos2x(pos(), inner());
|
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;
|
|
|
|
|
2001-09-24 16:25:06 +00:00
|
|
|
// leave subscript to the nearest side
|
|
|
|
if (par()->asScriptInset() && par()->asScriptInset()->down()) {
|
|
|
|
if (pos() <= size() / 2)
|
|
|
|
popLeft();
|
|
|
|
else
|
|
|
|
popRight();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2001-08-08 15:35:49 +00:00
|
|
|
// 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;
|
|
|
|
|
2001-09-24 16:25:06 +00:00
|
|
|
// leave superscript to the nearest side
|
|
|
|
if (par()->asScriptInset() && par()->asScriptInset()->up()) {
|
|
|
|
if (pos() <= size() / 2)
|
|
|
|
popLeft();
|
|
|
|
else
|
|
|
|
popRight();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2001-08-08 15:35:49 +00:00
|
|
|
// 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)
|
|
|
|
{
|
2001-10-10 16:35:18 +00:00
|
|
|
//lyxerr << "interpret 1: '" << s << "'\n";
|
2001-08-13 14:02:37 +00:00
|
|
|
//lyxerr << "in: " << in_word_set(s) << " \n";
|
|
|
|
|
|
|
|
if (s.empty())
|
|
|
|
return;
|
|
|
|
|
2001-10-10 16:35:18 +00:00
|
|
|
if (s.size() == 1) {
|
|
|
|
interpret(s[0]);
|
|
|
|
return;
|
|
|
|
}
|
2001-08-13 14:02:37 +00:00
|
|
|
|
2001-10-10 16:35:18 +00:00
|
|
|
//lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl;
|
|
|
|
//owner_->getIntl()->getTrans().TranslateAndInsert(s[0], lt);
|
|
|
|
//lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl;
|
2001-08-13 14:02:37 +00:00
|
|
|
|
2001-08-17 17:23:12 +00:00
|
|
|
if (s.size() > 7 && s.substr(0, 7) == "matrix ") {
|
2001-09-26 15:20:45 +00:00
|
|
|
unsigned int m = 1;
|
|
|
|
unsigned int n = 1;
|
2001-08-13 14:02:37 +00:00
|
|
|
string v_align;
|
|
|
|
string h_align;
|
2001-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;
|
2001-09-26 15:20:45 +00:00
|
|
|
m = std::max(1u, m);
|
|
|
|
n = std::max(1u, n);
|
2001-08-13 14:02:37 +00:00
|
|
|
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-09-12 13:23:39 +00:00
|
|
|
MathInset * p = createMathInset(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-10-10 16:35:18 +00:00
|
|
|
niceInsert(createMathInset(s.substr(1)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathCursor::interpret(char c)
|
|
|
|
{
|
|
|
|
//lyxerr << "interpret 2: '" << c << "'\n";
|
|
|
|
|
|
|
|
if (inMacroMode()) {
|
|
|
|
string name = macroName();
|
|
|
|
|
|
|
|
if (name == "\\" && c == '#') {
|
|
|
|
insert(c, LM_TC_TEX);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name == "\\" && c == '\\') {
|
|
|
|
backspac/();
|
|
|
|
interpret("\\backslash");
|
|
|
|
return;
|
|
|
|
}
|
2001-08-13 14:02:37 +00:00
|
|
|
|
2001-10-10 16:35:18 +00:00
|
|
|
if (name == "\\#" && '1' <= c && c <= '9') {
|
|
|
|
insert(c, LM_TC_TEX);
|
|
|
|
macroModeClose();
|
|
|
|
return;
|
|
|
|
}
|
2001-08-13 14:02:37 +00:00
|
|
|
|
2001-10-10 16:35:18 +00:00
|
|
|
if (isalpha(c)) {
|
|
|
|
insert(c, LM_TC_TEX);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name == "\\") {
|
|
|
|
insert(c, LM_TC_TEX);
|
|
|
|
macroModeClose();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
macroModeClose();
|
|
|
|
return;
|
|
|
|
}
|
2001-08-13 14:02:37 +00:00
|
|
|
|
2001-10-10 16:35:18 +00:00
|
|
|
// no macro mode
|
2001-08-13 14:02:37 +00:00
|
|
|
if (c == '^' || c == '_') {
|
2001-10-10 16:35:18 +00:00
|
|
|
const bool up = (c == '^');
|
|
|
|
const bool in = inner();
|
2001-10-10 13:20:51 +00:00
|
|
|
selCut();
|
2001-10-10 16:35:18 +00:00
|
|
|
if (in)
|
2001-10-10 13:20:51 +00:00
|
|
|
++pos();
|
|
|
|
if (!prevAtom())
|
|
|
|
insert(0);
|
2001-09-11 10:58:17 +00:00
|
|
|
MathInset * par = prevAtom()->ensure(up);
|
2001-10-10 16:35:18 +00:00
|
|
|
if (in)
|
|
|
|
pushLeft(par);
|
|
|
|
else
|
|
|
|
pushRight(par);
|
2001-08-13 14:02:37 +00:00
|
|
|
selPaste();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-08-14 11:19:19 +00:00
|
|
|
if (selection_)
|
|
|
|
selDel();
|
2001-08-13 14:02:37 +00:00
|
|
|
|
2001-08-28 13:34:04 +00:00
|
|
|
if (lastcode_ == LM_TC_TEXTRM) {
|
|
|
|
insert(c, LM_TC_TEXTRM);
|
2001-08-13 14:02:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == ' ') {
|
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 (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;
|
|
|
|
}
|
|
|
|
|
2001-10-10 16:35:18 +00:00
|
|
|
if (strchr("{}", c)) {
|
2001-10-10 13:20:51 +00:00
|
|
|
insert(c, LM_TC_TEX);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-10-10 16:35:18 +00:00
|
|
|
if (strchr("#$%", c)) {
|
2001-08-30 08:55:13 +00:00
|
|
|
insert(new MathSpecialCharInset(c));
|
2001-09-13 16:14:43 +00:00
|
|
|
lastcode_ = LM_TC_VAR;
|
2001-08-30 08:55:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-08-28 13:34:04 +00:00
|
|
|
if (isalpha(c) && (lastcode_ == LM_TC_GREEK || lastcode_ == LM_TC_GREEK1)) {
|
2001-08-30 14:40:43 +00:00
|
|
|
static char const greekl[][26] =
|
2001-09-05 16:32:36 +00:00
|
|
|
{"alpha", "beta", "chi", "delta", "epsilon", "phi",
|
2001-10-02 15:01:57 +00:00
|
|
|
"gamma", "eta", "iota", "iota", "kappa", "lambda", "mu",
|
2001-09-05 16:32:36 +00:00
|
|
|
"nu", "omikron", "pi", "omega", "rho", "sigma",
|
2001-10-02 15:01:57 +00:00
|
|
|
"tau", "upsilon", "theta", "omega", "xi", "upsilon", "zeta"};
|
2001-08-30 14:40:43 +00:00
|
|
|
static char const greeku[][26] =
|
2001-09-05 16:32:36 +00:00
|
|
|
{"Alpha", "Beta", "Chi", "Delta", "Epsilon", "Phi",
|
2001-10-02 15:01:57 +00:00
|
|
|
"Gamma", "Eta", "Iota", "Iota", "Kappa", "Lambda", "Mu",
|
2001-09-05 16:32:36 +00:00
|
|
|
"Nu", "Omikron", "Pi", "Omega", "Rho", "Sigma", "Tau",
|
2001-10-02 15:01:57 +00:00
|
|
|
"Upsilon", "Theta", "Omega", "xi", "Upsilon", "Zeta"};
|
2001-08-30 14:40:43 +00:00
|
|
|
|
|
|
|
latexkeys const * l = 0;
|
|
|
|
if ('a' <= c && c <= 'z')
|
|
|
|
l = in_word_set(greekl[c - 'a']);
|
|
|
|
if ('A' <= c && c <= 'Z')
|
|
|
|
l = in_word_set(greeku[c - 'A']);
|
2001-08-28 13:34:04 +00:00
|
|
|
|
2001-08-30 14:40:43 +00:00
|
|
|
if (l)
|
|
|
|
insert(createMathInset(l));
|
|
|
|
else
|
|
|
|
insert(c, LM_TC_VAR);
|
|
|
|
|
2001-08-28 13:34:04 +00:00
|
|
|
#warning greek insert problem? look here!
|
2001-08-30 14:40:43 +00:00
|
|
|
if (lastcode_ == LM_TC_GREEK1)
|
2001-08-28 13:34:04 +00:00
|
|
|
lastcode_ = LM_TC_VAR;
|
2001-08-13 14:02:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-08-28 13:34:04 +00:00
|
|
|
if (c == '\\') {
|
2001-10-02 15:01:57 +00:00
|
|
|
insert(c, LM_TC_TEX);
|
2001-08-28 13:34:04 +00:00
|
|
|
//bv->owner()->message(_("TeX mode"));
|
2001-08-13 14:02:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-08-28 13:34:04 +00:00
|
|
|
// no special circumstances, so insert the character without any fuss
|
2001-10-10 13:20:51 +00:00
|
|
|
insert(c, LM_TC_MIN);
|
2001-08-13 14:02:37 +00:00
|
|
|
}
|
|
|
|
|
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_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-01 12:10:32 +00:00
|
|
|
MathArray & MathCursorPos::cell(MathCursor::idx_type idx) const
|
2001-08-14 07:46:11 +00:00
|
|
|
{
|
|
|
|
return par_->cell(idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathArray & MathCursorPos::cell() const
|
|
|
|
{
|
|
|
|
return par_->cell(idx_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-01 12:10:32 +00:00
|
|
|
MathXArray & MathCursorPos::xcell(MathCursor::idx_type idx) const
|
2001-08-14 07:46:11 +00:00
|
|
|
{
|
|
|
|
return par_->xcell(idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathXArray & MathCursorPos::xcell() const
|
|
|
|
{
|
|
|
|
return par_->xcell(idx_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-10 13:20:51 +00:00
|
|
|
MathAtom * MathCursorPos::at() const
|
|
|
|
{
|
|
|
|
return cell().at(pos_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-14 07:46:11 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|