+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
* 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
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";
{
//lyxerr << "InsetFormulaBase::LocalDispatch: act: " << action
// << " arg: '" << arg << "' cursor: " << mathcursor << "\n";
- // extern char *dispatch_result;
if (!mathcursor)
return UNDISPATCHED;
}
}
- if (mathcursor)
- mathcursor->normalize();
+ mathcursor->normalize();
if (mathcursor && was_macro != mathcursor->InMacroMode()
&& action >= 0
}
-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;
}
///
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_;
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
}
-bool MathCursor::IsFont() const
-{
- return MathIsFont(nextCode());
-}
-
-
-bool MathCursor::IsScript() const
-{
- normalize();
- return MathIsScript(nextCode());
-}
-
-
int MathCursor::xpos() const
{
normalize();
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());
-
- // 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));
- }
+ 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 cell
- splitCell();
- MathArray & halfcell = array();
- idx_ += p->ncols() - 1;
- halfcell.swap(array());
+ // split cell
+ splitCell();
+ p->cell(idx_).swap(p->cell(idx_ + p->ncols() - 1));
+ }
}
char MathCursor::valign() const
///
bool prevIsInset() const;
///
- bool IsFont() const;
- ///
- bool IsScript() const;
- ///
void merge(MathArray const & arr);
///
MathInset * nextInset() const;
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,
/// An array
LM_OT_MATRIX,
- /// A big operator
- LM_OT_BIGOP,
/// A LaTeX macro
LM_OT_UNDEF,
///
}
+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
{
bool idxFirst(int &, int &) const;
///
bool idxLast(int &, int &) const;
+ ///
+ void idxDelete(int &, bool &, bool &);
///
void addRow(int);
return false;
}
-bool MathInset::idxDelete(int)
+void MathInset::idxDelete(int &, bool & popit, bool & deleteit)
{
- return false;
+ popit = false;
+ deleteit = false;
}
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;
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)
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);
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()) {
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));
halign("rl");
mutate(newtype);
break;
+ }
}
break;
}
-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());
}
/// Identifies ScriptInsets
bool isScriptInset() const { return true; }
///
- bool idxDelete(int idx);
+ void idxDelete(int & idx, bool & popit, bool & deleteit);
private:
///
bool up_;
#include "lyxfont.h"
#include "font.h"
#include "math_defs.h"
+#include "math_parser.h"
#include "Painter.h"
#include "matriz.h"
#include "symbol_def.h"
}
-#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 };
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;
}
}
-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;
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;
}
}
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;
+}
#define MATH_SUPPORT_H
#include "lyxfont.h"
+#include "math_defs.h"
#ifndef byte
#define byte unsigned char
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);