* 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
return *this;
}
+void MathedArray::clear()
+{
+ last_ = 0;
+ bf_.resize(1);
+ bf_[0] = 0;
+}
+
void MathedArray::swap(MathedArray & array)
{
if (this != &array) {
}
+
+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,
///
int empty() const;
+ ///
+ void clear();
///
int last() const;
///
void swap(MathedArray &);
+ ///
+ void shrink(int pos1, int pos2);
#if 0
///
par = is_multiline(p->GetType()) ?
new MathMatrixInset(static_cast<MathMatrixInset*>(p)):
- new MathParInset(p);
+ new MathParInset(*p);
// mathcursor = 0;
disp_flag = (par->GetType()>0);
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);
}
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;
}
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();
}
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();
}
-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) {
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:
///
}
-MathParInset::MathParInset(MathParInset * p)
- : MathedInset(p)
-{
- flag = p->flag;
- p->setArgumentIdx(0);
- MathedIter it(p->GetData());
- setData(it.Copy());
-}
-
-
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.
}
+void MathParInset::clear()
+{
+ array.clear();
+}
+
bool MathParInset::Inside(int x, int y)
{
return (x >= xo() && x <= xo() + width
MathParInset(short st = LM_ST_TEXT, string const & nm = string(),
short ot = LM_OT_MIN);
///
- explicit
- MathParInset(MathParInset *);
- ///
virtual ~MathParInset();
///
virtual MathedInset * Clone();
int yo() const {
return yo_;
}
+ ///
+ void clear();
protected:
/// Paragraph data is stored here
MathedArray array;
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,