* the GNU General Public Licence version 2 or later.
*/
+#include <config.h>
+
#ifdef __GNUG__
#pragma implementation
#endif
-#include <config.h>
-#include <algorithm>
-#include <cctype>
-
#include "support/lstrings.h"
#include "support/LAssert.h"
#include "debug.h"
#include "LColor.h"
#include "Painter.h"
+#include "math_cursor.h"
#include "formulabase.h"
#include "math_arrayinset.h"
#include "math_braceinset.h"
+#include "math_boxinset.h"
#include "math_casesinset.h"
#include "math_charinset.h"
-#include "math_cursor.h"
#include "math_deliminset.h"
#include "math_factory.h"
#include "math_hullinset.h"
#include "math_specialcharinset.h"
#include "math_support.h"
+#include <algorithm>
+#include <cctype>
+
#define FILEDEBUG 0
using std::endl;
}
void paste(MathCursor & cursor) const
- {
- idx_type idx;
- MathGridInset * p = cursor.enclosingGrid(idx);
- col_type const numcols = min(data_.ncols(), p->ncols() - p->col(idx));
- row_type const numrows = min(data_.nrows(), p->nrows() - p->row(idx));
- for (row_type row = 0; row < numrows; ++row)
- for (col_type col = 0; col < numcols; ++col) {
- idx_type i = p->index(row + p->row(idx), col + p->col(idx));
- p->cell(i).push_back(data_.cell(data_.index(row, col)));
- }
+ {
+ if (data_.nargs() == 1) {
+ // single cell/part of cell
+ cursor.insert(data_.cell(0));
+ } else {
+ // mulitple cells
+ idx_type idx;
+ MathGridInset * p = cursor.enclosingGrid(idx);
+ col_type const numcols = min(data_.ncols(), p->ncols() - p->col(idx));
+ row_type const numrows = min(data_.nrows(), p->nrows() - p->row(idx));
+ for (row_type row = 0; row < numrows; ++row)
+ for (col_type col = 0; col < numcols; ++col) {
+ idx_type i = p->index(row + p->row(idx), col + p->col(idx));
+ p->cell(i).push_back(data_.cell(data_.index(row, col)));
+ }
+ }
}
// glues selection to one cell
MathCursor::MathCursor(InsetFormulaBase * formula, bool left)
- : formula_(formula), lastcode_(LM_TC_VAR), selection_(false)
+ : formula_(formula), lastcode_(LM_TC_MIN), selection_(false)
{
left ? first() : last();
}
dump("Left 1");
if (inMacroMode()) {
macroModeClose();
- lastcode_ = LM_TC_VAR;
+ lastcode_ = LM_TC_MIN;
return true;
}
selHandle(sel);
- lastcode_ = LM_TC_VAR;
+ lastcode_ = LM_TC_MIN;
if (hasPrevAtom() && openable(prevAtom(), sel)) {
if (prevAtom()->isHyperActive()) {
dump("Right 1");
if (inMacroMode()) {
macroModeClose();
- lastcode_ = LM_TC_VAR;
+ lastcode_ = LM_TC_MIN;
return true;
}
selHandle(sel);
- lastcode_ = LM_TC_VAR;
+ lastcode_ = LM_TC_MIN;
if (hasNextAtom() && openable(nextAtom(), sel)) {
if (nextAtom()->isHyperActive()) {
void MathCursor::setPos(int x, int y)
{
- dump("setPos 2");
+ dump("setPos 1");
bool res = bruteFind(x, y,
formula()->xlow(), formula()->xhigh(),
formula()->ylow(), formula()->yhigh());
- lyx::Assert(res);
+ if (!res) {
+ // this ccan happen on creation of "math-display"
+ dump("setPos 1.5");
+ first();
+ }
dump("setPos 2");
}
dump("home 1");
selHandle(sel);
macroModeClose();
- lastcode_ = LM_TC_VAR;
+ lastcode_ = LM_TC_MIN;
if (!par()->idxHome(idx(), pos()))
popLeft();
dump("home 2");
dump("end 1");
selHandle(sel);
macroModeClose();
- lastcode_ = LM_TC_VAR;
+ lastcode_ = LM_TC_MIN;
if (!par()->idxEnd(idx(), pos()))
popRight();
dump("end 2");
}
-int MathCursor::macroNamePos() const
+MathInset::difference_type MathCursor::macroNamePos() const
{
- for (int i = pos() - 1; i >= 0; --i) {
+ for (MathInset::difference_type i = pos() - 1; i >= 0; --i) {
MathAtom & p = array().at(i);
if (p->code() == LM_TC_TEX && p->getChar() == '\\')
return i;
string MathCursor::macroName() const
{
string s;
- for (int i = macroNamePos(); i >= 0 && i < int(pos()); ++i)
+ MathInset::difference_type i = macroNamePos();
+ for ( ; i >= 0 && i < int(pos()); ++i)
s += array().at(i)->getChar();
return s;
}
MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const
{
- for (int i = Cursor_.size() - 1; i >= 0; --i) {
+ for (MathInset::difference_type i = Cursor_.size() - 1; i >= 0; --i) {
MathGridInset * p = Cursor_[i].par_->asGridInset();
if (p) {
idx = Cursor_[i].idx_;
}
-void MathCursor::normalize() const
+void MathCursor::normalize()
{
-#ifdef WITH_WARNINGS
-#warning This is evil!
-#endif
- MathCursor * it = const_cast<MathCursor *>(this);
+ // rebreak
+ {
+ MathIterator it = ibegin(formula()->par().nucleus());
+ MathIterator et = iend(formula()->par().nucleus());
+ for ( ; it != et; ++it)
+ if (it.par()->asBoxInset())
+ it.par()->asBoxInset()->rebreak();
+ }
if (idx() >= par()->nargs()) {
lyxerr << "this should not really happen - 1: "
<< idx() << " " << par()->nargs() << "\n";
dump("error 2");
}
- it->idx() = min(idx(), par()->nargs() - 1);
+ idx() = min(idx(), par()->nargs() - 1);
if (pos() > size()) {
lyxerr << "this should not really happen - 2: "
- << pos() << " " << size() << " in idx: " << it->idx()
+ << pos() << " " << size() << " in idx: " << idx()
<< " in atom: '";
WriteStream wi(lyxerr, false);
- it->par()->write(wi);
+ par()->write(wi);
lyxerr << "\n";
dump("error 4");
}
- it->pos() = min(pos(), size());
+ pos() = min(pos(), size());
}
if (s == "\\over" || s == "\\choose" || s == "\\atop") {
MathArray ar = array();
- MathAtom t = createMathInset(s.substr(1));
+ MathAtom t(createMathInset(s.substr(1)));
t->asNestInset()->cell(0).swap(array());
pos() = 0;
niceInsert(t);
return true;
}
+
bool MathCursor::script(bool up)
{
macroModeClose();
bool MathCursor::interpret(char c)
{
- //lyxerr << "interpret 2: '" << c << "'\n";
+
+ // Removed super/subscript handling from here to ::script -MV
+
// handle macroMode
if (inMacroMode()) {
string name = macroName();
// fall through in the other cases
}
- if (lastcode_ == LM_TC_TEXTRM) {
+ if (lastcode_ == LM_TC_TEXTRM || par()->asBoxInset()) {
// suppress direct insertion of two spaces in a row
// the still allows typing '<space>a<space>' and deleting the 'a', but
// it is better than nothing...
prevAtom()->asSpaceInset()->incSpace();
return true;
}
- if (mathcursor->popRight())
+ if (popRight())
return true;
// if are at the very end, leave the formula
return pos() != size();
}
// no special circumstances, so insert the character without any fuss
- insert(c, lastcode_);
+ insert(c, lastcode_ == LM_TC_MIN ? MathCharInset::nativeCode(c) : lastcode_);
lastcode_ = LM_TC_MIN;
return true;
}
}
+void MathCursor::setSelection(cursor_type const & where, size_type n)
+{
+ selection_ = true;
+ Anchor_ = where;
+ Cursor_ = where;
+ cursor().pos_ += n;
+}