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"
|
2001-10-12 12:02:49 +00:00
|
|
|
#include "support/LAssert.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-12 12:02:49 +00:00
|
|
|
if (i1.idx_ == i2.idx_)
|
|
|
|
data_.push_back(MathArray(i1.cell(), i1.pos_, i2.pos_));
|
2001-07-16 15:53:25 +00:00
|
|
|
else {
|
2001-09-26 16:52:34 +00:00
|
|
|
std::vector<MathInset::idx_type> indices =
|
2001-10-12 12:02:49 +00:00
|
|
|
(*i1.par_)->idxBetween(i1.idx_, i2.idx_);
|
2001-09-26 16:52:34 +00:00
|
|
|
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_) {
|
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 =
|
2001-10-12 12:02:49 +00:00
|
|
|
(*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-10-12 12:02:49 +00:00
|
|
|
MathArray ar = glue();
|
|
|
|
cursor.paste(ar);
|
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-10-12 12:02:49 +00:00
|
|
|
os << "(par: " << p.par_ << " idx: " << p.idx_ << " pos: " << p.pos_ << ")";
|
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-10-12 12:02:49 +00:00
|
|
|
MathCursor::MathCursor(InsetFormulaBase * formula, bool left)
|
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-10-12 12:02:49 +00:00
|
|
|
left ? first() : last();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
void MathCursor::push(MathAtom & t)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-07-16 15:53:25 +00:00
|
|
|
MathCursorPos p;
|
2001-10-12 12:02:49 +00:00
|
|
|
p.par_ = &t;
|
2001-10-12 15:38:58 +00:00
|
|
|
p.idx_ = 0;
|
|
|
|
p.pos_ = 0;
|
2001-07-16 15:53:25 +00:00
|
|
|
Cursor_.push_back(p);
|
2001-04-24 16:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
void MathCursor::pushLeft(MathAtom & t)
|
|
|
|
{
|
|
|
|
//cerr << "Entering atom "; t->write(cerr, false); cerr << " left\n";
|
|
|
|
push(t);
|
|
|
|
t->idxFirst(idx(), pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathCursor::pushRight(MathAtom & t)
|
2001-08-08 07:12:09 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
//cerr << "Entering atom "; t->write(cerr, false); cerr << " right\n";
|
2001-08-08 07:46:16 +00:00
|
|
|
posLeft();
|
2001-10-12 12:02:49 +00:00
|
|
|
push(t);
|
|
|
|
t->idxLast(idx(), pos());
|
2001-08-08 07:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathCursor::popLeft()
|
2001-04-24 16:13:38 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
//cerr << "Leaving atom "; par()->write(cerr, false); cerr << " left\n";
|
2001-07-16 15:53:25 +00:00
|
|
|
if (Cursor_.size() <= 1)
|
2001-06-27 14:10:35 +00:00
|
|
|
return false;
|
2001-10-12 12:02:49 +00:00
|
|
|
//if (nextInset())
|
|
|
|
// nextInset()->removeEmptyScripts();
|
2001-07-16 15:53:25 +00:00
|
|
|
Cursor_.pop_back();
|
2001-10-12 12:02:49 +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()
|
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
//cerr << "Leaving atom "; par()->write(cerr, false); cerr << " right\n";
|
2001-08-08 07:12:09 +00:00
|
|
|
if (Cursor_.size() <= 1)
|
|
|
|
return false;
|
2001-10-12 12:02:49 +00:00
|
|
|
//if (nextInset())
|
|
|
|
// nextInset()->removeEmptyScripts();
|
2001-08-08 07:12:09 +00:00
|
|
|
Cursor_.pop_back();
|
2001-10-12 12:02:49 +00:00
|
|
|
//if (nextInset())
|
|
|
|
// nextInset()->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-10-12 12:02:49 +00:00
|
|
|
void MathCursor::dump(char const * what) 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
|
2001-10-12 12:02:49 +00:00
|
|
|
<< " Cursor: pos: " << Cursor_[i].pos_
|
2001-07-23 13:52:48 +00:00
|
|
|
<< " idx: " << Cursor_[i].idx_
|
|
|
|
<< " par: " << Cursor_[i].par_ << "\n";
|
2001-10-12 12:02:49 +00:00
|
|
|
|
|
|
|
for (unsigned i = 0; i < Anchor_.size(); ++i)
|
|
|
|
lyxerr << " i: " << i
|
|
|
|
<< " Anchor: pos: " << Anchor_[i].pos_
|
|
|
|
<< " idx: " << Anchor_[i].idx_
|
|
|
|
<< " par: " << Anchor_[i].par_ << "\n";
|
|
|
|
|
|
|
|
lyxerr << " sel: " << selection_ << "\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
2001-02-14 17:58:40 +00:00
|
|
|
|
2001-10-12 12:02:49 +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-12 12:02:49 +00:00
|
|
|
if (Cursor_[i].par_->nucleus() == 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-10-12 12:02:49 +00:00
|
|
|
bool MathCursor::openable(MathAtom const & t, bool sel) const
|
2001-07-16 15:53:25 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
if (!t->isActive())
|
2001-07-16 15:53:25 +00:00
|
|
|
return false;
|
2001-08-07 12:02:21 +00:00
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
if (t->asScriptInset())
|
2001-08-20 13:45:02 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (sel) {
|
|
|
|
// we can't move into anything new during selection
|
|
|
|
if (Cursor_.size() == Anchor_.size())
|
|
|
|
return false;
|
2001-10-12 12:02:49 +00:00
|
|
|
if (&t != Anchor_[Cursor_.size()].par_)
|
2001-08-20 13:45:02 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
bool MathCursor::positionable(MathAtom const & t, int x, int y) const
|
2001-08-20 13:45:02 +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
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
return t->nargs() && t->covers(x, y);
|
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-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;
|
2001-10-12 12:02:49 +00:00
|
|
|
++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-10-12 12:02:49 +00:00
|
|
|
if (hasPrevAtom() && openable(prevAtom(), sel)) {
|
|
|
|
pushRight(prevAtom());
|
2001-07-16 15:53:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
2001-08-08 07:46:16 +00:00
|
|
|
|
2001-10-12 16:12:32 +00:00
|
|
|
return posLeft() || idxLeft() || popLeft() || selection_;
|
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-10-12 12:02:49 +00:00
|
|
|
if (hasNextAtom() && openable(nextAtom(), sel)) {
|
|
|
|
pushLeft(nextAtom());
|
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
|
|
|
|
2001-10-12 16:12:32 +00:00
|
|
|
return posRight() || idxRight() || popRight() || selection_;
|
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-10-12 12:02:49 +00:00
|
|
|
pushLeft(formula_->par());
|
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-10-12 12:02:49 +00:00
|
|
|
cursor().par_ = &formula_->par();
|
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-12 12:02:49 +00:00
|
|
|
int xx = abs(x1 - ar.pos2x(c));
|
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-10-12 12:02:49 +00:00
|
|
|
if (hasNextAtom() && positionable(nextAtom(), x, y))
|
|
|
|
pushLeft(nextAtom());
|
|
|
|
else if (hasPrevAtom() && positionable(prevAtom(), x, y))
|
|
|
|
pushRight(prevAtom());
|
2001-08-08 07:12:09 +00:00
|
|
|
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-12 12:02:49 +00:00
|
|
|
void MathCursor::plainInsert(MathAtom const & t)
|
2001-10-10 13:20:51 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
array().insert(pos(), t);
|
2001-10-10 13:20:51 +00:00
|
|
|
++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-12 12:02:49 +00:00
|
|
|
plainInsert(MathAtom(new MathCharInset(c, t)));
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
void MathCursor::insert(MathAtom const & t)
|
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-12 12:02:49 +00:00
|
|
|
if (selection_) {
|
|
|
|
if (t->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-12 12:02:49 +00:00
|
|
|
plainInsert(t);
|
2001-07-16 15:53:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
void MathCursor::niceInsert(MathAtom const & t)
|
2001-08-13 14:02:37 +00:00
|
|
|
{
|
|
|
|
selCut();
|
2001-10-12 12:02:49 +00:00
|
|
|
insert(t); // inserting invalidates the pointer!
|
|
|
|
MathAtom const & p = prevAtom();
|
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-12 12:02:49 +00:00
|
|
|
void MathCursor::paste(MathArray const & ar)
|
2001-10-10 13:20:51 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
Anchor_ = Cursor_;
|
|
|
|
selection_ = true;
|
|
|
|
array().insert(pos(), ar);
|
|
|
|
pos() += ar.size();
|
2001-10-10 13:20:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-07 15:04:57 +00:00
|
|
|
void MathCursor::backspace()
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
if (selection_) {
|
|
|
|
selDel();
|
2001-08-07 15:04:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
MathScriptInset * p = prevAtom()->asScriptInset();
|
|
|
|
if (p) {
|
|
|
|
p->removeScript(p->hasUp());
|
|
|
|
// Don't delete if there is anything left
|
|
|
|
if (p->hasUp() || p->hasDown())
|
|
|
|
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-12 12:02:49 +00:00
|
|
|
if (pos() == size())
|
2001-09-24 16:25:06 +00:00
|
|
|
return;
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
MathScriptInset * p = nextAtom()->asScriptInset();
|
|
|
|
if (p) {
|
|
|
|
p->removeScript(p->hasUp());
|
|
|
|
// Don't delete if there is anything left
|
|
|
|
if (p->hasUp() || p->hasDown())
|
|
|
|
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-10-12 12:02:49 +00:00
|
|
|
if (!selection_) {
|
|
|
|
// check whether we could move into a superscript
|
|
|
|
if (hasPrevAtom()) {
|
|
|
|
MathAtom & p = prevAtom();
|
|
|
|
if (p->asScriptInset() && p->asScriptInset()->hasUp()) {
|
|
|
|
pushRight(p);
|
2001-10-12 14:09:00 +00:00
|
|
|
idx() = 1;
|
2001-10-12 12:02:49 +00:00
|
|
|
pos() = size();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2001-06-27 14:10:35 +00:00
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
if (hasNextAtom()) {
|
|
|
|
MathAtom & n = nextAtom();
|
|
|
|
if (n->asScriptInset() && n->asScriptInset()->hasUp()) {
|
|
|
|
pushLeft(n);
|
2001-10-12 14:09:00 +00:00
|
|
|
idx() = 1;
|
2001-10-12 12:02:49 +00:00
|
|
|
pos() = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2001-06-27 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2001-10-12 16:12:32 +00:00
|
|
|
return goUp() || selection_;
|
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-10-12 12:02:49 +00:00
|
|
|
if (!selection_) {
|
|
|
|
// check whether we could move into a subscript
|
|
|
|
if (hasPrevAtom()) {
|
|
|
|
MathAtom & p = prevAtom();
|
|
|
|
if (p->asScriptInset() && p->asScriptInset()->hasDown()) {
|
|
|
|
pushRight(p);
|
2001-10-12 14:09:00 +00:00
|
|
|
idx() = 0;
|
2001-10-12 12:02:49 +00:00
|
|
|
pos() = size();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2001-06-27 14:10:35 +00:00
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
if (hasNextAtom()) {
|
|
|
|
MathAtom & n = nextAtom();
|
|
|
|
if (n->asScriptInset() && n->asScriptInset()->hasDown()) {
|
|
|
|
pushLeft(n);
|
2001-10-12 14:09:00 +00:00
|
|
|
idx() = 0;
|
2001-10-12 12:02:49 +00:00
|
|
|
pos() = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2001-06-27 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2001-10-12 16:12:32 +00:00
|
|
|
return goDown() || selection_;
|
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-10-12 12:02:49 +00:00
|
|
|
if (!hasPrevAtom())
|
|
|
|
return false;
|
|
|
|
MathScriptInset * t = prevAtom()->asScriptInset();
|
2001-09-11 10:58:17 +00:00
|
|
|
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-10-12 12:02:49 +00:00
|
|
|
MathAtom & p = array().at(i);
|
|
|
|
if (p->code() == LM_TC_TEX && p->getChar() == '\\')
|
2001-10-10 16:35:18 +00:00
|
|
|
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)
|
2001-10-12 12:02:49 +00:00
|
|
|
s += array().at(i)->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-10-12 12:02:49 +00:00
|
|
|
theSelection.grab(*this);
|
|
|
|
//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-12 12:02:49 +00:00
|
|
|
int x1 = c.xo() + c.pos2x(i1.pos_);
|
2001-07-16 15:53:25 +00:00
|
|
|
int y1 = c.yo() - c.ascent();
|
2001-10-12 12:02:49 +00:00
|
|
|
int x2 = c.xo() + c.pos2x(i2.pos_);
|
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-12 12:02:49 +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-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-12 12:02:49 +00:00
|
|
|
for (MathInset::pos_type pos = i1.pos_; pos != i2.pos_; ++pos)
|
|
|
|
ar.at(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-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-10-12 12:02:49 +00:00
|
|
|
insert(MathAtom(p)); // this invalidates p!
|
|
|
|
pushRight(prevAtom());
|
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-12 12:02:49 +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-10-12 12:02:49 +00:00
|
|
|
MathAtom & MathCursor::par() const
|
2001-02-13 19:10:18 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +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-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-10-12 12:02:49 +00:00
|
|
|
MathArrayInset * p = (*Cursor_[i].par_)->asArrayInset();
|
|
|
|
if (p) {
|
2001-07-16 15:53:25 +00:00
|
|
|
idx = Cursor_[i].idx_;
|
2001-10-12 12:02:49 +00:00
|
|
|
return p;
|
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
|
2001-10-12 12:02:49 +00:00
|
|
|
const bool up = p->hasUp();
|
2001-10-10 16:35:18 +00:00
|
|
|
popLeft();
|
2001-10-12 12:02:49 +00:00
|
|
|
MathScriptInset * q = nextAtom()->asScriptInset();
|
|
|
|
if (q)
|
|
|
|
q->removeScript(up);
|
2001-10-10 16:35:18 +00:00
|
|
|
++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-10-12 15:38:58 +00:00
|
|
|
<< pos() << " " << size() << " in idx: " << it->idx()
|
|
|
|
<< " in atom: '";
|
|
|
|
it->par()->write(lyxerr, false);
|
|
|
|
lyxerr << "\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-10-12 12:02:49 +00:00
|
|
|
bool MathCursor::hasPrevAtom() const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
return pos() > 0;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
bool MathCursor::hasNextAtom() const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
return pos() < size();
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
MathAtom const & MathCursor::prevAtom() const
|
2001-07-25 14:15:05 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
lyx::Assert(pos() > 0);
|
2001-09-11 10:58:17 +00:00
|
|
|
return array().at(pos() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
MathAtom & MathCursor::prevAtom()
|
2001-09-11 10:58:17 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
lyx::Assert(pos() > 0);
|
2001-09-11 10:58:17 +00:00
|
|
|
return array().at(pos() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
MathAtom const & MathCursor::nextAtom() const
|
2001-09-11 10:58:17 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
lyx::Assert(pos() < size());
|
2001-09-11 10:58:17 +00:00
|
|
|
return array().at(pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
MathAtom & MathCursor::nextAtom()
|
2001-09-11 10:58:17 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
lyx::Assert(pos() < size());
|
2001-09-11 10:58:17 +00:00
|
|
|
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-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-10-12 12:02:49 +00:00
|
|
|
MathMatrixInset * p = formula()->par()->asMatrixInset();
|
|
|
|
if (!p)
|
|
|
|
return;
|
|
|
|
|
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-12 12:02:49 +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;
|
|
|
|
|
2001-09-24 16:25:06 +00:00
|
|
|
// leave subscript to the nearest side
|
2001-10-12 12:02:49 +00:00
|
|
|
MathScriptInset * p = par()->asScriptInset();
|
|
|
|
if (p && p->hasDown()) {
|
2001-09-24 16:25:06 +00:00
|
|
|
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_;
|
2001-10-12 12:02:49 +00:00
|
|
|
MathAtom const & out = formula()->par();
|
2001-08-08 11:03:53 +00:00
|
|
|
y0 -= xarray().ascent();
|
2001-10-12 12:02:49 +00:00
|
|
|
for (int y = y0 - 4; y > out->yo() - out->ascent(); y -= 4) {
|
2001-08-08 11:03:53 +00:00
|
|
|
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
|
2001-10-12 12:02:49 +00:00
|
|
|
MathScriptInset * p = par()->asScriptInset();
|
|
|
|
if (p && p->hasUp()) {
|
2001-09-24 16:25:06 +00:00
|
|
|
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_;
|
2001-10-12 12:02:49 +00:00
|
|
|
MathAtom const & out = formula()->par();
|
2001-08-08 11:03:53 +00:00
|
|
|
y0 += xarray().descent();
|
2001-10-12 12:02:49 +00:00
|
|
|
for (int y = y0 + 4; y < out->yo() + out->descent(); y += 4) {
|
2001-08-08 11:03:53 +00:00
|
|
|
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-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-10-12 12:02:49 +00:00
|
|
|
niceInsert(MathAtom(new MathArrayInset(m, n, v_align[0], h_align)));
|
2001-08-13 14:46:06 +00:00
|
|
|
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-10-12 12:02:49 +00:00
|
|
|
MathAtom t = createMathInset(s.substr(1));
|
|
|
|
t->asNestInset()->cell(0).swap(array());
|
2001-08-13 14:46:06 +00:00
|
|
|
pos() = 0;
|
2001-10-12 12:02:49 +00:00
|
|
|
niceInsert(t);
|
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 == '\\') {
|
2001-10-10 16:39:42 +00:00
|
|
|
backspace();
|
2001-10-10 16:35:18 +00:00
|
|
|
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 == '^');
|
2001-10-10 13:20:51 +00:00
|
|
|
selCut();
|
2001-10-12 12:02:49 +00:00
|
|
|
if (hasPrevAtom() && prevAtom()->asScriptInset()) {
|
|
|
|
prevAtom()->asScriptInset()->ensure(up);
|
|
|
|
pushRight(prevAtom());
|
2001-10-12 15:38:58 +00:00
|
|
|
idx() = up;
|
2001-10-12 12:02:49 +00:00
|
|
|
pos() = size();
|
2001-10-12 13:05:21 +00:00
|
|
|
} else if (hasNextAtom() && nextAtom()->asScriptInset()) {
|
2001-10-12 12:02:49 +00:00
|
|
|
nextAtom()->asScriptInset()->ensure(up);
|
|
|
|
pushLeft(nextAtom());
|
2001-10-12 15:38:58 +00:00
|
|
|
idx() = up;
|
2001-10-12 12:02:49 +00:00
|
|
|
pos() = 0;
|
2001-10-12 13:05:21 +00:00
|
|
|
} else {
|
|
|
|
plainInsert(MathAtom(new MathScriptInset(up)));
|
2001-10-12 15:38:58 +00:00
|
|
|
prevAtom()->asScriptInset()->ensure(up);
|
2001-10-12 13:05:21 +00:00
|
|
|
pushRight(prevAtom());
|
2001-10-12 15:38:58 +00:00
|
|
|
idx() = up;
|
|
|
|
pos() = 0;
|
2001-10-12 12:02:49 +00:00
|
|
|
}
|
2001-08-13 14:02:37 +00:00
|
|
|
selPaste();
|
2001-10-12 15:38:58 +00:00
|
|
|
dump("1");
|
2001-08-13 14:02:37 +00:00
|
|
|
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-10-12 13:29:46 +00:00
|
|
|
if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
|
|
|
|
prevAtom()->asSpaceInset()->incSpace();
|
2001-08-17 09:48:24 +00:00
|
|
|
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-10-12 12:02:49 +00:00
|
|
|
insert(MathAtom(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-12 14:09:00 +00:00
|
|
|
"gamma", "eta", "iota", "epsilon", "kappa", "lambda", "mu",
|
2001-10-12 14:33:38 +00:00
|
|
|
"nu", "omega", "pi", "vartheta", "rho", "sigma",
|
2001-10-12 14:09:00 +00:00
|
|
|
"tau", "upsilon", "theta", "omega", "xi", "varphi", "zeta"};
|
2001-08-30 14:40:43 +00:00
|
|
|
static char const greeku[][26] =
|
2001-10-12 14:33:38 +00:00
|
|
|
{"alpha", "beta", "chi", "Delta", "varepsilon", "Phi",
|
|
|
|
"Gamma", "varepsilon", "varepsilon", "epsilon", "kappa", "Lambda", "mu",
|
|
|
|
"Nu", "Omega", "Pi", "vartheta", "varrho", "Sigma", "varsigma",
|
|
|
|
"Upsilon", "Theta", "Omega", "Xi", "Varphi", "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);
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
return (*par_)->cell(idx);
|
2001-08-14 07:46:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathArray & MathCursorPos::cell() const
|
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
return (*par_)->cell(idx_);
|
2001-08-14 07:46:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-01 12:10:32 +00:00
|
|
|
MathXArray & MathCursorPos::xcell(MathCursor::idx_type idx) const
|
2001-08-14 07:46:11 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
return (*par_)->xcell(idx);
|
2001-08-14 07:46:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathXArray & MathCursorPos::xcell() const
|
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
return (*par_)->xcell(idx_);
|
2001-10-10 13:20:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
|