mathed31.diff

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1566 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2001-02-20 13:16:07 +00:00
parent 434d86dd67
commit a6fc77c8e9
10 changed files with 84 additions and 109 deletions

View File

@ -3,6 +3,8 @@
* math_parinset.[Ch]: make array a real MathArray, not just a
pointer to one.
* move MathIter::Copy(int, int) to MathArray::shrink(pos, pos)
* several files: subsequent changes

View File

@ -75,6 +75,13 @@ MathedArray & MathedArray::operator=(MathedArray const & array)
return *this;
}
void MathedArray::clear()
{
last_ = 0;
bf_.resize(1);
bf_[0] = 0;
}
void MathedArray::swap(MathedArray & array)
{
if (this != &array) {
@ -155,6 +162,54 @@ void MathedArray::move(int p, int shift)
}
void MathedArray::shrink(int pos1, int pos2)
{
if (pos1 == 0 && pos2 >= last())
return;
short fc = 0;
if (pos1 > 0 && bf_[pos1] > ' ') {
for (int p = pos1; p >= 0; --p) {
if (MathIsFont(bf_[p])) {
if (p != pos1 - 1)
fc = bf_[p];
else
--pos1;
break;
}
}
}
if (pos2 > 0 && bf_[pos2] >= ' ' && MathIsFont(bf_[pos2 - 1]))
--pos2;
int dx = pos2 - pos1;
MathedArray a;
a.resize(dx + 1);
strange_copy(&a, (fc) ? 1 : 0, pos1, dx);
if (fc) {
a[0] = fc;
++dx;
}
a.last(dx);
a[dx] = '\0';
MathedIter it(&a);
it.Reset();
while (it.OK()) {
if (it.IsInset()) {
MathedInset * inset = it.GetInset();
inset = inset->Clone();
a.raw_pointer_insert(inset, it.getPos() + 1, sizeof(inset));
}
it.Next();
}
swap(a);
}
#if 0
void MathedArray::insert(MathedArray::iterator pos,
MathedArray::const_iterator beg,

View File

@ -65,6 +65,8 @@ public:
///
int empty() const;
///
void clear();
///
int last() const;
@ -73,6 +75,8 @@ public:
///
void swap(MathedArray &);
///
void shrink(int pos1, int pos2);
#if 0
///

View File

@ -227,7 +227,7 @@ InsetFormula::InsetFormula(MathParInset * p)
par = is_multiline(p->GetType()) ?
new MathMatrixInset(static_cast<MathMatrixInset*>(p)):
new MathParInset(p);
new MathParInset(*p);
// mathcursor = 0;
disp_flag = (par->GetType()>0);
@ -537,9 +537,6 @@ void InsetFormula::display(bool dspf)
par->SetStyle(LM_ST_DISPLAY);
} else {
if (is_multiline(par->GetType())) {
MathParInset * p = new MathParInset(par);
delete par;
par = p;
if (mathcursor)
mathcursor->SetPar(par);
}

View File

@ -843,12 +843,10 @@ bool MathedCursor::pullArg()
return false;
MathedArray * a = p->GetData();
p->setData(0);
p->clear();
Delete();
if (a) {
cursor->Merge(a);
cursor->Adjust();
}
cursor->Merge(a);
cursor->Adjust();
return true;
}
@ -904,7 +902,8 @@ void MathedCursor::SelCopy()
int p1 = (cursor->getPos() < selpos) ? cursor->getPos() : selpos;
int p2 = (cursor->getPos() > selpos) ?
cursor->getPos() : selpos;
selarray = cursor->Copy(p1, p2);
selarray = new MathedArray(*(cursor->GetData()));
selarray->shrink(p1, p2);
cursor->Adjust();
SelClear();
}
@ -919,7 +918,8 @@ void MathedCursor::SelCut()
int p1 = (cursor->getPos() < selpos) ? cursor->getPos() : selpos;
int p2 = (cursor->getPos() > selpos) ? cursor->getPos() : selpos;
selarray = cursor->Copy(p1, p2);
selarray = new MathedArray(*(cursor->GetData()));
selarray->shrink(p1, p2);
cursor->Clean(selpos);
cursor->Adjust();
SelClear();

View File

@ -376,84 +376,6 @@ bool MathedIter::Delete()
}
MathedArray * MathedIter::Copy()
{
#if 0
return Copy(0, 10000);
#else
if (!array) {
// lyxerr << "Math error: Attempting to copy a void array." << endl;
return 0;
}
return new MathedArray(*array);
#endif
}
MathedArray * MathedIter::Copy(int pos1, int pos2)
{
if (!array) {
// lyxerr << "Math error: Attempting to copy a void array." << endl;
return 0;
}
if (pos1 > 0 || pos2 <= array->last()) {
ipush();
MathedArray * t = array;
MathedArray * a;
short fc = 0;
if (pos1 > 0 && (*array)[pos1] > ' ') {
for (int p = pos1; p >= 0; --p) {
if (MathIsFont((*array)[p])) {
if (p != pos1 - 1)
fc = (*array)[p];
else
--pos1;
break;
}
}
}
if (pos2 > 0 && (*array)[pos2] >= ' '
&& MathIsFont((*array)[pos2 - 1]))
--pos2;
int dx = pos2 - pos1;
a = new MathedArray;
a->resize(dx + 1);
// lyxerr << "VA " << pos2 << " " << pos2 << " " << dx << endl;
array->strange_copy(a, (fc) ? 1 : 0, pos1, dx);
if (fc) {
(*a)[0] = fc;
++dx;
}
a->last(dx);
(*a)[dx] = '\0';
array = a;
Reset();
while (OK()) {
if (IsInset()) {
MathedInset * inset = GetInset();
inset = inset->Clone();
array->raw_pointer_insert(inset, pos + 1, sizeof(inset));
}
Next();
}
array = t;
ipop();
return a;
}
// otherwise: full copy
return new MathedArray(*array);
}
void MathedIter::Clear()
{
if (!array) {

View File

@ -110,11 +110,7 @@ public:
void setNumCols(int n) { ncols = n; }
///
MathedArray * GetData() const;
/// Copy every object
MathedArray * Copy();
/// Copy every object from position p1 to p2
MathedArray * Copy(int p1, int p2);
/// Delete every object from position p1 to p2
void Clear();
protected:
///

View File

@ -35,16 +35,6 @@ MathParInset::MathParInset(short st, string const & nm, short ot)
}
MathParInset::MathParInset(MathParInset * p)
: MathedInset(p)
{
flag = p->flag;
p->setArgumentIdx(0);
MathedIter it(p->GetData());
setData(it.Copy());
}
MathParInset::~MathParInset()
{
}
@ -52,12 +42,18 @@ MathParInset::~MathParInset()
MathedInset * MathParInset::Clone()
{
return new MathParInset(this);
return new MathParInset(*this);
}
void MathParInset::setData(MathedArray * a)
{
if (!a) {
lyxerr << "can't set Data from NULL pointer" << endl;
array = MathedArray();
return;
}
array = *a;
// A standard paragraph shouldn't have any tabs nor CRs.
@ -387,6 +383,11 @@ void MathParInset::Write(ostream & os, bool fragile)
}
void MathParInset::clear()
{
array.clear();
}
bool MathParInset::Inside(int x, int y)
{
return (x >= xo() && x <= xo() + width

View File

@ -19,9 +19,6 @@ public:
MathParInset(short st = LM_ST_TEXT, string const & nm = string(),
short ot = LM_OT_MIN);
///
explicit
MathParInset(MathParInset *);
///
virtual ~MathParInset();
///
virtual MathedInset * Clone();
@ -79,6 +76,8 @@ public:
int yo() const {
return yo_;
}
///
void clear();
protected:
/// Paragraph data is stored here
MathedArray array;

View File

@ -148,8 +148,7 @@ void MathedXIter::Merge(MathedArray * a0)
return;
}
// All insets must be clonned
MathedIter it(a0);
MathedArray * a = it.Copy();
MathedArray * a = new MathedArray(*a0);
#if 0
array->insert(array->begin() + pos,