cursor movement in multiline math; remove dead code

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2212 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2001-07-09 16:59:57 +00:00
parent e321726f35
commit faa697a2a9
17 changed files with 141 additions and 133 deletions

View File

@ -1,3 +1,12 @@
2001-07-04 André Pönitz <poenitz@htwm.de>
* math_grid.C: <Delete> in the first cell of a completely empty row
deletes that row, <C-Return> places the cursor in the first of the
new empty cells.
* math_grid.C: try to split cell nicely when mutating from single-cell
to multi-cell environment
2001-07-09 Dekel Tsur <dekelts@tau.ac.il>
* math_matrixinset.C (mutate): Use only the first label when
@ -13,7 +22,7 @@
* formulabase.C (mathDispatchInsertMath): remove bogus return
statement.
2001-07-04 André Pönitz <poenitz@htwm.de>
2001-07-09 André Pönitz <poenitz@htwm.de>
* math_*inset.C: Change order of arguments in MathInset constructor

View File

@ -176,13 +176,6 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
updateLocal(bv);
break;
case LFUN_DELETE_LINE_FORWARD:
bv->lockedInsetStoreUndo(Undo::DELETE);
mathcursor->DelLine();
updateLocal(bv);
break;
case LFUN_MATH_NUMBER:
{
//lyxerr << "toggling all numbers\n";

View File

@ -469,7 +469,6 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
{
//lyxerr << "InsetFormulaBase::LocalDispatch: act: " << action
// << " arg: '" << arg << "' cursor: " << mathcursor << "\n";
// extern char *dispatch_result;
if (!mathcursor)
return UNDISPATCHED;
@ -970,8 +969,7 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
}
}
if (mathcursor)
mathcursor->normalize();
mathcursor->normalize();
if (mathcursor && was_macro != mathcursor->InMacroMode()
&& action >= 0

View File

@ -143,9 +143,12 @@ bool MathBigopInset::hasLimits() const
}
bool MathBigopInset::idxDelete(int idx)
void MathBigopInset::idxDelete(int & idx, bool & popit, bool & deleteit)
{
// ignore the return value, we do not want the inset to be deleted
MathScriptInset::idxDelete(idx);
return false;
if (idx == 0)
up(false);
else
down(false);
popit = true;
deleteit = true;
}

View File

@ -26,7 +26,7 @@ public:
///
void limits(int);
///
bool idxDelete(int idx);
void idxDelete(int & idx, bool & popit, bool & deleteit);
private:
/// 1: \limits, -1: \nolimits, 0: use default
int lims_;

View File

@ -415,11 +415,13 @@ void MathCursor::Delete()
if (cursor_ < array().size())
array().erase(cursor_);
// delete empty cells parts if necessary
// delete empty cells if necessary
if (cursor_ == 0 && array().size() == 0) {
bool removeit = par_->idxDelete(idx_);
if (pop() && removeit)
Delete();
bool popit;
bool removeit;
par_->idxDelete(idx_, popit, removeit);
if (popit && pop() && removeit)
Delete();
}
#ifdef WITH_WARNINGS
@ -1176,19 +1178,6 @@ bool MathCursor::prevIsInset() const
}
bool MathCursor::IsFont() const
{
return MathIsFont(nextCode());
}
bool MathCursor::IsScript() const
{
normalize();
return MathIsScript(nextCode());
}
int MathCursor::xpos() const
{
normalize();
@ -1225,24 +1214,27 @@ void MathCursor::splitCell()
void MathCursor::breakLine()
{
MathMatrixInset * p = static_cast<MathMatrixInset *>(formula()->par());
if (p->GetType() == LM_OT_SIMPLE || p->GetType() == LM_OT_EQUATION)
if (p->GetType() == LM_OT_SIMPLE || p->GetType() == LM_OT_EQUATION) {
p->mutate(LM_OT_EQNARRAY);
p->addRow(row());
p->addRow(row());
idx_ = p->nrows();
cursor_ = 0;
} else {
p->addRow(row());
// split line
const int r = row();
for (int c = col() + 1; c < p->ncols(); ++c) {
const int i1 = p->index(r, c);
const int i2 = p->index(r + 1, c);
lyxerr << "swapping cells " << i1 << " and " << i2 << "\n";
p->cell(i1).swap(p->cell(i2));
// split line
const int r = row();
for (int c = col() + 1; c < p->ncols(); ++c) {
const int i1 = p->index(r, c);
const int i2 = p->index(r + 1, c);
lyxerr << "swapping cells " << i1 << " and " << i2 << "\n";
p->cell(i1).swap(p->cell(i2));
}
// split cell
splitCell();
p->cell(idx_).swap(p->cell(idx_ + p->ncols() - 1));
}
// split cell
splitCell();
MathArray & halfcell = array();
idx_ += p->ncols() - 1;
halfcell.swap(array());
}
char MathCursor::valign() const

View File

@ -221,10 +221,6 @@ private:
///
bool prevIsInset() const;
///
bool IsFont() const;
///
bool IsScript() const;
///
void merge(MathArray const & arr);
///
MathInset * nextInset() const;

View File

@ -50,23 +50,12 @@ MathStyles smallerStyleFrac(MathStyles st);
enum MathTextCodes {
/// This must be >= 0
LM_TC_MIN = 0,
/// Open and Close group
LM_TC_OPEN,
///
LM_TC_CLOSE,
/// Math Inset
LM_TC_INSET,
/// Super and sub scripts
LM_TC_UP,
///
LM_TC_DOWN,
/// Editable Math Inset
LM_TC_ACTIVE_INSET,
/// Editable Text Inset
LM_TC_TEXT_INSET,
///
LM_FONT_BEGIN,
/// Internal code for constants 11
/// Internal code for constants 4
LM_TC_CONST,
/// Internal code for variables
LM_TC_VAR,
@ -125,8 +114,6 @@ enum MathInsetTypes {
/// An array
LM_OT_MATRIX,
/// A big operator
LM_OT_BIGOP,
/// A LaTeX macro
LM_OT_UNDEF,
///

View File

@ -365,6 +365,32 @@ bool MathGridInset::idxLast(int & idx, int & pos) const
}
void MathGridInset::idxDelete(int & idx, bool & popit, bool & deleteit)
{
popit = false;
deleteit = false;
// delete entire row if in first cell of empty row
if (col(idx) == 0 && nrows() > 1) {
bool deleterow = true;
for (int i = idx; i < idx + ncols(); ++i)
if (cell(i).size()) {
deleterow = false;
break;
}
if (deleterow)
delRow(row(idx));
if (idx >= nargs())
idx = nargs() - 1;
return;
}
// undo effect of Ctrl-Tab (i.e. pull next cell)
//if (idx != nargs() - 1)
// cell(idx).swap(cell(idx + 1));
}
MathGridInset::RowInfo const & MathGridInset::rowinfo(int i) const
{

View File

@ -99,6 +99,8 @@ public:
bool idxFirst(int &, int &) const;
///
bool idxLast(int &, int &) const;
///
void idxDelete(int &, bool &, bool &);
///
void addRow(int);

View File

@ -294,9 +294,10 @@ bool MathInset::idxFirstDown(int &, int &) const
return false;
}
bool MathInset::idxDelete(int)
void MathInset::idxDelete(int &, bool & popit, bool & deleteit)
{
return false;
popit = false;
deleteit = false;
}

View File

@ -121,8 +121,9 @@ public:
virtual bool idxEnd(int & idx, int & pos) const;
/// Delete a cell and move cursor
// a return value true indicates that the whole inset should be deleted
virtual bool idxDelete(int idx);
// the return value indicates whether the cursor should leave the inset
// and/or the whole inset should be deleted
virtual void idxDelete(int & idx, bool & popit, bool & deleteit);
///
int nargs() const;

View File

@ -69,6 +69,17 @@ int getCols(short int type)
return col;
}
// returns position of first relation operator in the array
// used for "intelligent splitting"
int firstRelOp(MathArray const & array)
{
for (int pos = 0; pos < array.size(); array.next(pos))
if (!array.isInset(pos) &&
MathIsRelOp(array.GetChar(pos), array.GetCode(pos)))
return pos;
return array.size();
}
}
MathMatrixInset::MathMatrixInset(MathInsetTypes t)
@ -456,15 +467,36 @@ void MathMatrixInset::mutate(short newtype)
SetType(LM_OT_SIMPLE);
break;
case LM_OT_ALIGN:
case LM_OT_ALIGN: {
MathGridInset::addCol(1);
// split it "nicely"
int pos = firstRelOp(cell(0));
cell(1) = cell(0);
cell(0).erase(pos, cell(0).size());
cell(1).erase(0, pos);
halign("rl");
SetType(LM_OT_ALIGN);
break;
}
case LM_OT_EQNARRAY:
default:
MathGridInset::addCol(1);
MathGridInset::addCol(1);
// split it "nicely" on the firest relop
int pos1 = firstRelOp(cell(0));
cell(1) = cell(0);
cell(0).erase(pos1, cell(0).size());
cell(1).erase(0, pos1);
int pos2 = 0;
cell(1).next(pos2);
cell(2) = cell(1);
cell(1).erase(pos2, cell(1).size());
cell(2).erase(0, pos2);
halign("rcl");
SetType(LM_OT_EQNARRAY);
mutate(newtype);
@ -476,12 +508,15 @@ void MathMatrixInset::mutate(short newtype)
switch (newtype) {
case LM_OT_SIMPLE:
case LM_OT_EQUATION: {
// set correct (no)numbering
bool allnonum = true;
for (int r = 0; r < nrows(); ++r) {
if (!nonum_[r])
allnonum = false;
}
nonum_[0] = allnonum;
// set first non-empty label
string label;
for (int r = 0; r < nrows(); ++r) {
if (!label_[r].empty()) {
@ -489,16 +524,15 @@ void MathMatrixInset::mutate(short newtype)
break;
}
}
label_[0] = label;
glueall();
mutate(newtype);
label_[0] = label;
nonum_[0] = allnonum;
break;
}
case LM_OT_ALIGN:
default:
default: {
for (int row = 0; row < nrows(); ++row) {
int c = 3 * row + 1;
cell(c).push_back(cell(c + 1));
@ -508,6 +542,7 @@ void MathMatrixInset::mutate(short newtype)
halign("rl");
mutate(newtype);
break;
}
}
break;

View File

@ -185,13 +185,12 @@ bool MathScriptInset::idxLastDown(int & idx, int & pos) const
}
bool MathScriptInset::idxDelete(int idx)
void MathScriptInset::idxDelete(int & idx, bool & popit, bool & deleteit)
{
if (idx == 0) {
if (idx == 0)
up(false);
return !down();
} else {
else
down(false);
return !up();
}
popit = true;
deleteit = !(up() || down());
}

View File

@ -61,7 +61,7 @@ public:
/// Identifies ScriptInsets
bool isScriptInset() const { return true; }
///
bool idxDelete(int idx);
void idxDelete(int & idx, bool & popit, bool & deleteit);
private:
///
bool up_;

View File

@ -6,6 +6,7 @@
#include "lyxfont.h"
#include "font.h"
#include "math_defs.h"
#include "math_parser.h"
#include "Painter.h"
#include "matriz.h"
#include "symbol_def.h"
@ -468,26 +469,6 @@ void mathed_draw_deco(Painter & pain, int x, int y, int w, int h, int code)
}
#define USE_EXCEPTIONS 0
#if USE_EXCEPTIONS
struct deco_not_found {};
math_deco_struct const & search_deco(int code)
{
math_deco_struct const * res =
lower_bound(math_deco_table,
math_deco_table + math_deco_table_size,
code, math_deco_compare());
if (res != math_deco_table + math_deco_table_size &&
res->code == code)
return *res;
throw deco_not_found();
}
#else
math_deco_struct const * search_deco(int code)
{
math_deco_struct search_elem = { code, 0, 0 };
@ -501,18 +482,11 @@ math_deco_struct const * search_deco(int code)
return res;
return 0;
}
#endif
bool MathIsInset(short x)
{
return LM_TC_INSET <= x && x <= LM_TC_ACTIVE_INSET;
}
bool MathIsFont(short x)
{
return LM_TC_CONST <= x && x <= LM_TC_BSYM;
return LM_TC_INSET == x;
}
@ -522,24 +496,6 @@ bool MathIsAlphaFont(short x)
}
bool MathIsUp(short x)
{
return x == LM_TC_UP;
}
bool MathIsDown(short x)
{
return x == LM_TC_DOWN;
}
bool MathIsScript(short x)
{
return x == LM_TC_DOWN || x == LM_TC_UP;
}
bool MathIsBOPS(short x)
{
return MathLookupBOP(x) > LMB_NONE;
@ -554,7 +510,7 @@ bool MathIsBinary(short x)
bool MathIsSymbol(short x)
{
return LM_TC_SYMB <= x && x <= LM_TC_BSYM;
return x == LM_TC_SYMB || x == LM_TC_BOPS || x == LM_TC_BSYM;
}
@ -610,3 +566,15 @@ MathStyles smallerStyleFrac(MathStyles st)
}
return st;
}
bool MathIsRelOp(byte c, MathTextCodes f)
{
if (f == LM_TC_BOP && (c == '=' || c == '<' || c == '>'))
return true;
#ifndef WITH_WARNINGS
#warning implement me properly
#endif
if (f == LM_TC_SYMB && (c == LM_leq || c == LM_geq))
return true;
return false;
}

View File

@ -4,6 +4,7 @@
#define MATH_SUPPORT_H
#include "lyxfont.h"
#include "math_defs.h"
#ifndef byte
#define byte unsigned char
@ -39,14 +40,11 @@ int mathed_string_width(short type, int size, string const & s);
math_deco_struct const * search_deco(int code);
bool MathIsInset(short x);
bool MathIsFont(short x);
bool MathIsAlphaFont(short x);
bool MathIsUp(short x);
bool MathIsDown(short x);
bool MathIsScript(short x);
bool MathIsBOPS(short x);
bool MathIsBinary(short x);
bool MathIsSymbol(short x);
bool MathIsRelOp(byte c, MathTextCodes f);
void drawStr(Painter & pain, short type, int siz,
int x, int y, string const & s);