mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-27 06:19:36 +00:00
multicell selection
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2255 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
efe0b0b8eb
commit
a97c6eba47
@ -33,6 +33,14 @@ MathArray::MathArray(MathArray const & array)
|
|||||||
replace(pos, nextInset(pos)->clone());
|
replace(pos, nextInset(pos)->clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MathArray::MathArray(MathArray const & array, int from, int to)
|
||||||
|
: bf_(array.bf_.begin() + from, array.bf_.begin() + to)
|
||||||
|
{
|
||||||
|
for (int pos = 0; pos < size(); next(pos))
|
||||||
|
if (isInset(pos))
|
||||||
|
replace(pos, nextInset(pos)->clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool MathArray::next(int & pos) const
|
bool MathArray::next(int & pos) const
|
||||||
{
|
{
|
||||||
@ -209,6 +217,12 @@ int MathArray::size() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MathArray::erase()
|
||||||
|
{
|
||||||
|
erase(0, size());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void MathArray::erase(int pos)
|
void MathArray::erase(int pos)
|
||||||
{
|
{
|
||||||
if (pos < static_cast<int>(bf_.size()))
|
if (pos < static_cast<int>(bf_.size()))
|
||||||
|
@ -47,6 +47,8 @@ public:
|
|||||||
///
|
///
|
||||||
MathArray(MathArray const &);
|
MathArray(MathArray const &);
|
||||||
///
|
///
|
||||||
|
MathArray(MathArray const &, int from, int to);
|
||||||
|
///
|
||||||
MathArray & operator=(MathArray const &);
|
MathArray & operator=(MathArray const &);
|
||||||
///
|
///
|
||||||
~MathArray();
|
~MathArray();
|
||||||
@ -72,6 +74,8 @@ public:
|
|||||||
///
|
///
|
||||||
void erase(int pos);
|
void erase(int pos);
|
||||||
///
|
///
|
||||||
|
void erase();
|
||||||
|
///
|
||||||
void replace(int pos, MathInset * inset);
|
void replace(int pos, MathInset * inset);
|
||||||
///
|
///
|
||||||
bool prev(int & pos) const;
|
bool prev(int & pos) const;
|
||||||
|
@ -134,13 +134,7 @@ void InsetFormula::draw(BufferView * bv, LyXFont const &,
|
|||||||
pain.fillRectangle(x, y - a, w, h, LColor::mathbg);
|
pain.fillRectangle(x, y - a, w, h, LColor::mathbg);
|
||||||
|
|
||||||
if (mathcursor && mathcursor->formula() == this) {
|
if (mathcursor && mathcursor->formula() == this) {
|
||||||
if (mathcursor->Selection()) {
|
mathcursor->drawSelection(pain);
|
||||||
int xp[10];
|
|
||||||
int yp[10];
|
|
||||||
int n;
|
|
||||||
mathcursor->SelGetArea(xp, yp, n);
|
|
||||||
pain.fillPolygon(xp, yp, n, LColor::selection);
|
|
||||||
}
|
|
||||||
pain.rectangle(x, y - a, w, h, LColor::mathframe);
|
pain.rectangle(x, y - a, w, h, LColor::mathframe);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,7 +166,11 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
|
|||||||
|
|
||||||
case LFUN_BREAKLINE:
|
case LFUN_BREAKLINE:
|
||||||
bv->lockedInsetStoreUndo(Undo::INSERT);
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
mathcursor->GetPos(x, y);
|
||||||
mathcursor->breakLine();
|
mathcursor->breakLine();
|
||||||
|
mathcursor->normalize();
|
||||||
updateLocal(bv);
|
updateLocal(bv);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -332,17 +330,18 @@ void InsetFormula::validate(LaTeXFeatures & features) const
|
|||||||
|
|
||||||
int InsetFormula::ascent(BufferView *, LyXFont const &) const
|
int InsetFormula::ascent(BufferView *, LyXFont const &) const
|
||||||
{
|
{
|
||||||
return par()->ascent();
|
return par()->ascent() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int InsetFormula::descent(BufferView *, LyXFont const &) const
|
int InsetFormula::descent(BufferView *, LyXFont const &) const
|
||||||
{
|
{
|
||||||
return par()->descent();
|
return par()->descent() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int InsetFormula::width(BufferView *, LyXFont const &) const
|
int InsetFormula::width(BufferView *, LyXFont const &) const
|
||||||
{
|
{
|
||||||
return par()->width();
|
Metrics();
|
||||||
|
return par()->width() + 2;
|
||||||
}
|
}
|
||||||
|
@ -306,7 +306,7 @@ void InsetFormulaBase::edit(BufferView * bv, int x, int /*y*/, unsigned int)
|
|||||||
if (!bv->lockInset(this))
|
if (!bv->lockInset(this))
|
||||||
lyxerr[Debug::MATHED] << "Cannot lock inset!!!" << endl;
|
lyxerr[Debug::MATHED] << "Cannot lock inset!!!" << endl;
|
||||||
|
|
||||||
par_->Metrics(LM_ST_TEXT);
|
Metrics();
|
||||||
//bv->updateInset(this, false);
|
//bv->updateInset(this, false);
|
||||||
if (x == 0)
|
if (x == 0)
|
||||||
mathcursor->first();
|
mathcursor->first();
|
||||||
@ -408,11 +408,17 @@ vector<string> const InsetFormulaBase::getLabelList() const
|
|||||||
|
|
||||||
void InsetFormulaBase::updateLocal(BufferView * bv)
|
void InsetFormulaBase::updateLocal(BufferView * bv)
|
||||||
{
|
{
|
||||||
par_->Metrics(LM_ST_TEXT);
|
Metrics();
|
||||||
bv->updateInset(this, true);
|
bv->updateInset(this, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void InsetFormulaBase::Metrics() const
|
||||||
|
{
|
||||||
|
const_cast<MathInset *>(par_)->Metrics(LM_ST_TEXT);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void InsetFormulaBase::insetButtonRelease(BufferView * bv,
|
void InsetFormulaBase::insetButtonRelease(BufferView * bv,
|
||||||
int x, int y, int /*button*/)
|
int x, int y, int /*button*/)
|
||||||
{
|
{
|
||||||
|
@ -115,6 +115,8 @@ public:
|
|||||||
virtual std::vector<string> const getLabelList() const;
|
virtual std::vector<string> const getLabelList() const;
|
||||||
///
|
///
|
||||||
MathInset * par() const;
|
MathInset * par() const;
|
||||||
|
///
|
||||||
|
virtual void Metrics() const;
|
||||||
protected:
|
protected:
|
||||||
///
|
///
|
||||||
virtual void updateLocal(BufferView * bv);
|
virtual void updateLocal(BufferView * bv);
|
||||||
|
@ -143,13 +143,8 @@ void InsetFormulaMacro::draw(BufferView * bv, LyXFont const & f,
|
|||||||
pain.fillRectangle(int(x), y , w, h, LColor::mathmacrobg);
|
pain.fillRectangle(int(x), y , w, h, LColor::mathmacrobg);
|
||||||
pain.rectangle(int(x), y, w, h, LColor::mathframe);
|
pain.rectangle(int(x), y, w, h, LColor::mathframe);
|
||||||
|
|
||||||
if (mathcursor && mathcursor->formula() == this && mathcursor->Selection()) {
|
if (mathcursor && mathcursor->formula() == this)
|
||||||
int xp[10];
|
mathcursor->drawSelection(pain);
|
||||||
int yp[10];
|
|
||||||
int n;
|
|
||||||
mathcursor->SelGetArea(xp, yp, n);
|
|
||||||
pain.fillPolygon(xp, yp, n, LColor::selection);
|
|
||||||
}
|
|
||||||
|
|
||||||
pain.text(int(x + 2), baseline, prefix(), font);
|
pain.text(int(x + 2), baseline, prefix(), font);
|
||||||
x += width(bv, font);
|
x += width(bv, font);
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -29,6 +29,38 @@ class MathUpDownInset;
|
|||||||
class InsetFormulaBase;
|
class InsetFormulaBase;
|
||||||
class MathArray;
|
class MathArray;
|
||||||
class MathXArray;
|
class MathXArray;
|
||||||
|
class Painter;
|
||||||
|
|
||||||
|
/// Description of a position
|
||||||
|
struct MathCursorPos {
|
||||||
|
/// inset
|
||||||
|
MathInset * par_;
|
||||||
|
/// cell index
|
||||||
|
int idx_;
|
||||||
|
/// cell position
|
||||||
|
int pos_;
|
||||||
|
///
|
||||||
|
bool operator==(const MathCursorPos &) const;
|
||||||
|
///
|
||||||
|
bool operator<(const MathCursorPos &) const;
|
||||||
|
/// returns cell corresponding to this position
|
||||||
|
MathArray & cell() const;
|
||||||
|
/// returns cell corresponding to this position
|
||||||
|
MathArray & cell(int idx) const;
|
||||||
|
/// returns xcell corresponding to this position
|
||||||
|
MathXArray & xcell() const;
|
||||||
|
/// returns xcell corresponding to this position
|
||||||
|
MathXArray & xcell(int idx) const;
|
||||||
|
/// moves position on cell to the left
|
||||||
|
bool idxLeft();
|
||||||
|
/// moves position on cell to the right
|
||||||
|
bool idxRight();
|
||||||
|
/// moves position on cell up
|
||||||
|
bool idxUp();
|
||||||
|
/// moves position on cell up
|
||||||
|
bool idxDown();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/// This is the external interface of Math's subkernel
|
/// This is the external interface of Math's subkernel
|
||||||
class MathCursor {
|
class MathCursor {
|
||||||
@ -40,6 +72,8 @@ public:
|
|||||||
///
|
///
|
||||||
void insert(MathInset *);
|
void insert(MathInset *);
|
||||||
///
|
///
|
||||||
|
void insert(MathArray const &);
|
||||||
|
///
|
||||||
void Home();
|
void Home();
|
||||||
///
|
///
|
||||||
void End();
|
void End();
|
||||||
@ -108,7 +142,7 @@ public:
|
|||||||
///
|
///
|
||||||
void SelClear();
|
void SelClear();
|
||||||
///
|
///
|
||||||
void SelGetArea(int * xp, int * yp, int & n);
|
void drawSelection(Painter & pain) const;
|
||||||
///
|
///
|
||||||
void clearLastCode();
|
void clearLastCode();
|
||||||
///
|
///
|
||||||
@ -126,7 +160,7 @@ public:
|
|||||||
///
|
///
|
||||||
MathTextCodes getLastCode() const;
|
MathTextCodes getLastCode() const;
|
||||||
///
|
///
|
||||||
int idx() const { return cursor_.idx_; }
|
int idx() const { return cursor().idx_; }
|
||||||
///
|
///
|
||||||
void idxNext();
|
void idxNext();
|
||||||
///
|
///
|
||||||
@ -148,7 +182,17 @@ public:
|
|||||||
///
|
///
|
||||||
int row() const;
|
int row() const;
|
||||||
|
|
||||||
//protected:
|
///
|
||||||
|
MathStyles style() const;
|
||||||
|
/// Make sure cursor position is valid
|
||||||
|
void normalize() const;
|
||||||
|
|
||||||
|
/// Enter a new MathInset from the front or the back
|
||||||
|
void push(MathInset * par, bool first);
|
||||||
|
/// Leave current MathInset
|
||||||
|
bool pop();
|
||||||
|
|
||||||
|
//private:
|
||||||
///
|
///
|
||||||
bool macro_mode;
|
bool macro_mode;
|
||||||
|
|
||||||
@ -166,36 +210,26 @@ public:
|
|||||||
///
|
///
|
||||||
MathXArray & xarray() const;
|
MathXArray & xarray() const;
|
||||||
|
|
||||||
///
|
/// returns the first position of the (normalized) selection
|
||||||
MathStyles style() const;
|
MathCursorPos firstSelectionPos() const;
|
||||||
/// Make sure cursor position is valid
|
/// returns the last position of the (normalized) selection
|
||||||
void normalize() const;
|
MathCursorPos lastSelectionPos() const;
|
||||||
|
/// returns the selection
|
||||||
/// Enter a new MathInset from the front or the back
|
void getSelection(MathCursorPos &, MathCursorPos &) const;
|
||||||
void push(MathInset * par, bool first);
|
/// returns the normalized anchor of the selection
|
||||||
/// Leave current MathInset
|
MathCursorPos normalAnchor() const;
|
||||||
bool pop();
|
/// returns the normalized anchor of the selection
|
||||||
|
bool openable(MathInset *, bool selection, bool useupdown) const;
|
||||||
private:
|
|
||||||
/// Description of a position
|
|
||||||
struct MathIter {
|
|
||||||
/// inset
|
|
||||||
MathInset * par_;
|
|
||||||
/// cell inset
|
|
||||||
int idx_;
|
|
||||||
///
|
|
||||||
int pos_;
|
|
||||||
};
|
|
||||||
|
|
||||||
/// path of positions the cursor had to go if it were leving each inset
|
/// path of positions the cursor had to go if it were leving each inset
|
||||||
std::vector<MathIter> path_;
|
std::vector<MathCursorPos> Cursor_;
|
||||||
|
/// path of positions the anchor had to go if it were leving each inset
|
||||||
|
std::vector<MathCursorPos> Anchor_;
|
||||||
|
|
||||||
/// reference to the last item of the path
|
/// reference to the last item of the path
|
||||||
MathIter anchor_;
|
MathCursorPos & cursor();
|
||||||
///
|
///
|
||||||
MathIter cursor_;
|
MathCursorPos const & cursor() const;
|
||||||
///
|
|
||||||
int path_idx_;
|
|
||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@ -245,9 +245,6 @@ void MathGridInset::delRow(int row)
|
|||||||
if (nrows() == 1)
|
if (nrows() == 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
lyxerr << "delRow: nr: " << nrows() << " nc: " << ncols()
|
|
||||||
<< " row: " << row << "\n";
|
|
||||||
|
|
||||||
cells_type::iterator it = cells_.begin() + row * ncols();
|
cells_type::iterator it = cells_.begin() + row * ncols();
|
||||||
cells_.erase(it, it + ncols());
|
cells_.erase(it, it + ncols());
|
||||||
|
|
||||||
@ -389,6 +386,22 @@ void MathGridInset::idxDelete(int & idx, bool & popit, bool & deleteit)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MathGridInset::idxDeleteRange(int from, int to)
|
||||||
|
{
|
||||||
|
// leave this unimplemented unless someone wants to have it.
|
||||||
|
/*
|
||||||
|
int n = (to - from) / ncols();
|
||||||
|
int r = from / ncols();
|
||||||
|
|
||||||
|
if (n >= 1) {
|
||||||
|
cells_type::iterator it = cells_.begin() + from;
|
||||||
|
cells_.erase(it, it + n * ncols());
|
||||||
|
rowinfo_.erase(rowinfo_.begin() + r, rowinfo_.begin() + r + n);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
MathGridInset::RowInfo const & MathGridInset::rowinfo(int i) const
|
MathGridInset::RowInfo const & MathGridInset::rowinfo(int i) const
|
||||||
{
|
{
|
||||||
return rowinfo_[i];
|
return rowinfo_[i];
|
||||||
@ -399,3 +412,17 @@ MathGridInset::RowInfo & MathGridInset::rowinfo(int i)
|
|||||||
{
|
{
|
||||||
return rowinfo_[i];
|
return rowinfo_[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<int> MathGridInset::idxBetween(int from, int to) const
|
||||||
|
{
|
||||||
|
int r1 = std::min(row(from), row(to));
|
||||||
|
int r2 = std::max(row(from), row(to));
|
||||||
|
int c1 = std::min(col(from), col(to));
|
||||||
|
int c2 = std::max(col(from), col(to));
|
||||||
|
std::vector<int> res;
|
||||||
|
for (int i = r1; i <= r2; ++i)
|
||||||
|
for (int j = c1; j <= c2; ++j)
|
||||||
|
res.push_back(index(i, j));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
@ -101,6 +101,8 @@ public:
|
|||||||
bool idxLast(int &, int &) const;
|
bool idxLast(int &, int &) const;
|
||||||
///
|
///
|
||||||
void idxDelete(int &, bool &, bool &);
|
void idxDelete(int &, bool &, bool &);
|
||||||
|
///
|
||||||
|
void idxDeleteRange(int, int);
|
||||||
|
|
||||||
///
|
///
|
||||||
void addRow(int);
|
void addRow(int);
|
||||||
@ -114,6 +116,8 @@ public:
|
|||||||
virtual void appendRow();
|
virtual void appendRow();
|
||||||
///
|
///
|
||||||
int index(int row, int col) const;
|
int index(int row, int col) const;
|
||||||
|
///
|
||||||
|
std::vector<int> idxBetween(int from, int to) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// row info
|
/// row info
|
||||||
|
@ -284,6 +284,9 @@ void MathInset::idxDelete(int &, bool & popit, bool & deleteit)
|
|||||||
deleteit = false;
|
deleteit = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MathInset::idxDeleteRange(int, int)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
bool MathInset::idxLastUp(int &, int &) const
|
bool MathInset::idxLastUp(int &, int &) const
|
||||||
{
|
{
|
||||||
@ -363,3 +366,11 @@ void MathInset::Validate(LaTeXFeatures & features) const
|
|||||||
for (int i = 0; i < nargs(); ++i)
|
for (int i = 0; i < nargs(); ++i)
|
||||||
cell(i).Validate(features);
|
cell(i).Validate(features);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<int> MathInset::idxBetween(int from, int to) const
|
||||||
|
{
|
||||||
|
std::vector<int> res;
|
||||||
|
for (int i = from; i <= to; ++i)
|
||||||
|
res.push_back(i);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
@ -126,6 +126,11 @@ public:
|
|||||||
// the return value indicates whether the cursor should leave the inset
|
// the return value indicates whether the cursor should leave the inset
|
||||||
// and/or the whole inset should be deleted
|
// and/or the whole inset should be deleted
|
||||||
virtual void idxDelete(int & idx, bool & popit, bool & deleteit);
|
virtual void idxDelete(int & idx, bool & popit, bool & deleteit);
|
||||||
|
// deletes a cell range and moves the cursor
|
||||||
|
virtual void idxDeleteRange(int from, int to);
|
||||||
|
// returns list of cell indices that are "between" from and to for
|
||||||
|
// selction purposes
|
||||||
|
virtual std::vector<int> idxBetween(int from, int to) const;
|
||||||
|
|
||||||
///
|
///
|
||||||
int nargs() const;
|
int nargs() const;
|
||||||
|
Loading…
Reference in New Issue
Block a user