X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2Fmath_inset.C;h=9bc23390677907a362a73df3f06b728794f56084;hb=2da8fcabdc695b8bb139d7252b923ef6b9aa29dd;hp=3656a70a8702f89c91d20ac0fc89105f956fe366;hpb=d8a6abd63afb7e88a014e2f7acf84069396d52ff;p=lyx.git diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index 3656a70a87..9bc2339067 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -7,7 +7,7 @@ * * Dependencies: Xlib, XForms * - * Copyright: (c) 1996, 1997 Alejandro Aguilar Sierra + * Copyright: 1996, 1997 Alejandro Aguilar Sierra * * Version: 0.8beta. * @@ -15,526 +15,288 @@ * the GNU General Public Licence version 2 or later. */ -#include - #ifdef __GNUG__ -#pragma implementation "math_inset.h" +#pragma implementation #endif -#include "math_iter.h" #include "math_inset.h" -#include "symbol_def.h" +#include "debug.h" + + +int MathInset::workwidth; + +MathInset::MathInset() + : size_(LM_ST_DISPLAY), xo_(0), yo_(0) +{} -inline -char *strnew(char const* s) + +int MathInset::height() const { - char *s1 = new char[strlen(s)+1]; - return strcpy(s1, s); + return ascent() + descent(); } -MathedInset::MathedInset(MathedInset* inset) +MathStyles MathInset::size() const { - if (inset) { - name = inset->GetName(); - objtype = inset->GetType(); - size = inset->GetStyle(); - width = inset->Width(); - ascent = inset->Ascent(); - descent = inset->Descent(); - } else { - objtype = LM_OT_UNDEF; - size = LM_ST_TEXT; - width = ascent = descent = 0; - name = 0; - } + return size_; } -MathFuncInset::MathFuncInset(char const *nm, short ot, short st): - MathedInset("", ot, st) +void MathInset::size(MathStyles s) const { - ln = 0; - lims = (GetType() == LM_OT_FUNCLIM); - if (GetType() == LM_OT_UNDEF) { - fname = strnew(nm); - SetName(fname); - } else { - fname = 0; - SetName(nm); - } + size_ = s; } -MathedInset *MathFuncInset::Clone() -{ - MathedInset *l = new MathFuncInset(name, GetType(), GetStyle()); - return l; + +std::ostream & operator<<(std::ostream & os, MathInset const & inset) +{ + inset.write(os, false); + return os; } -MathSpaceInset::MathSpaceInset(int sp, short ot, short st): - MathedInset("", ot, st), space(sp) + +int MathInset::xo() const { + return xo_; } -MathedInset *MathSpaceInset::Clone() -{ - MathedInset *l = new MathSpaceInset(space, GetType(), GetStyle()); - return l; + +int MathInset::yo() const +{ + return yo_; } -MathParInset::MathParInset(short st, char const *nm, short ot): - MathedInset(nm, ot, st) + +void MathInset::xo(int x) const { - array = 0; - ascent = 8; - width = 4; - descent = 0; - flag = 1; - if (objtype == LM_OT_SCRIPT) - flag |= LMPF_SCRIPT; + xo_ = x; } -MathParInset::MathParInset(MathParInset* p): MathedInset(p) + +void MathInset::yo(int y) const { - flag = p->flag; - p->setArgumentIdx(0); - MathedIter it(p->GetData()); - SetData(it.Copy()); + yo_ = y; } -MathParInset::~MathParInset() +int MathInset::nargs() const { - if (array) { - MathedIter it(array); - it.Clear(); - delete array; - } + return 0; } -MathedInset *MathParInset::Clone() -{ - MathParInset* p = new MathParInset(this); - return p; +MathXArray dummyCell; + +MathXArray & MathInset::xcell(int) +{ + lyxerr << "I don't have a cell\n"; + return dummyCell; } -void MathParInset::SetData(LyxArrayBase *a) +MathXArray const & MathInset::xcell(int) const { - array = a; - - // A standard paragraph shouldn't have any tabs nor CRs. - if (array) { - MathedIter it(array); - while (it.OK()) { - char c = it.GetChar(); - if (c == LM_TC_TAB || c == LM_TC_CR) - it.Delete(); - else - it.Next(); - } - } + lyxerr << "I don't have a cell\n"; + return dummyCell; } -MathSqrtInset::MathSqrtInset(short st): MathParInset(st, "sqrt", LM_OT_SQRT) -{ +MathArray & MathInset::cell(int) +{ + lyxerr << "I don't have a cell\n"; + return dummyCell.data_; } -MathedInset *MathSqrtInset::Clone() -{ - MathSqrtInset* p = new MathSqrtInset(GetStyle()); - MathedIter it(array); - p->SetData(it.Copy()); - return p; +MathArray const & MathInset::cell(int) const +{ + lyxerr << "I don't have a cell\n"; + return dummyCell.data_; } -bool MathSqrtInset::Inside(int x, int y) +void MathInset::substitute(MathArray & array, MathMacro const &) const { - return (x>= xo-hmax && x<= xo+width-hmax && y<= yo+descent && y>= yo-ascent); + array.push_back(clone()); } -MathDelimInset::MathDelimInset(int l, int r, short st): - MathParInset(st, "", LM_OT_DELIM), left(l), right(r) +bool MathInset::idxNext(int &, int &) const { + return false; } -MathedInset *MathDelimInset::Clone() -{ - MathDelimInset* p = new MathDelimInset(left, right, GetStyle()); - MathedIter it(array); - p->SetData(it.Copy()); - return p; + +bool MathInset::idxRight(int &, int &) const +{ + return false; } -MathDecorationInset::MathDecorationInset(int d, short st): - MathParInset(st, "", LM_OT_DECO), deco(d) +bool MathInset::idxPrev(int &, int &) const { - upper = (deco!= LM_underline && deco!= LM_underbrace); + return false; } -MathedInset *MathDecorationInset::Clone() -{ - MathDecorationInset* p = new MathDecorationInset(deco, GetStyle()); - MathedIter it(array); - p->SetData(it.Copy()); - return p; + +bool MathInset::idxLeft(int &, int &) const +{ + return false; } -MathFracInset::MathFracInset(short ot): MathParInset(LM_ST_TEXT, "frac", ot) + +bool MathInset::idxUp(int &, int &) const { - - den = new MathParInset(LM_ST_TEXT); // this leaks - dh = 0; - idx = 0; - if (objtype == LM_OT_STACKREL) { - flag |= LMPF_SCRIPT; - SetName("stackrel"); - } + return false; } -MathFracInset::~MathFracInset() + +bool MathInset::idxDown(int &, int &) const { - delete den; + return false; } -MathedInset *MathFracInset::Clone() -{ - MathFracInset* p = new MathFracInset(GetType()); - MathedIter itn(array); - MathedIter itd(den->GetData()); - p->SetData(itn.Copy(), itd.Copy()); - p->idx = idx; - p->dh = dh; - return p; + +bool MathInset::idxFirst(int &, int &) const +{ + return false; } -bool MathFracInset::setArgumentIdx(int i) + +bool MathInset::idxLast(int &, int &) const { - if (i == 0 || i == 1) { - idx = i; - return true; - } else - return false; + return false; } -void MathFracInset::SetStyle(short st) +bool MathInset::idxHome(int &, int &) const { - MathParInset::SetStyle(st); - dh = 0; - den->SetStyle((size == LM_ST_DISPLAY) ? (short)LM_ST_TEXT: size); + return false; } -void MathFracInset::SetData(LyxArrayBase *n, LyxArrayBase *d) + +bool MathInset::idxEnd(int &, int &) const { - den->SetData(d); - MathParInset::SetData(n); + return false; } -void MathFracInset::SetData(LyxArrayBase *d) + +bool MathInset::idxFirstUp(int &, int &) const { - if (idx == 0) - MathParInset::SetData(d); - else { - den->SetData(d); - } + return false; } -void MathFracInset::GetXY(int& x, int& y) const -{ - if (idx == 0) - MathParInset::GetXY(x, y); - else - den->GetXY(x, y); + +bool MathInset::idxFirstDown(int &, int &) const +{ + return false; } - -LyxArrayBase *MathFracInset::GetData() + + +void MathInset::idxDelete(int &, bool & popit, bool & deleteit) { - if (idx == 0) - return array; - else - return den->GetData(); + popit = false; + deleteit = false; } -bool MathFracInset::Inside(int x, int y) +void MathInset::idxDeleteRange(int, int) +{} + + +bool MathInset::idxLastUp(int &, int &) const { - int xx = xo - (width-w0)/2; - - return (x>= xx && x<= xx+width && y<= yo+descent && y>= yo-ascent); + return false; } -void MathFracInset::SetFocus(int /*x*/, int y) -{ -// lyxerr << "y " << y << " " << yo << " " << den->yo << " "; - idx = (y > yo) ? 1: 0; + +bool MathInset::idxLastDown(int &, int &) const +{ + return false; } -MathMatrixInset::MathMatrixInset(int m, int n, short st): - MathParInset(st, "array", LM_OT_MATRIX), nc(m) +void MathInset::getXY(int & x, int & y) const { - ws = new int[nc]; - v_align = 0; - h_align = new char[nc+1]; - for (int i = 0; i < nc; i++) h_align[i] = 'c'; - h_align[nc] = '\0'; - nr = 0; - row = 0; - flag = 15; - if (n>0) { - row = new MathedRowSt(nc+1); - MathedXIter it(this); - for (int j = 1; j < n; j++) it.addRow(); - nr = n; - if (nr == 1 && nc>1) { - for (int j = 0; j < nc - 1; j++) - it.Insert('T', LM_TC_TAB); - } - } else if (n<0) { - row = new MathedRowSt(nc+1); - nr = 1; - } -} - - -MathMatrixInset::MathMatrixInset(MathMatrixInset *mt): - MathParInset(mt->GetStyle(), mt->GetName(), mt->GetType()) -{ - nr = 0; - nc = mt->nc; - ws = new int[nc]; - h_align = new char[nc+1]; - strcpy(h_align, mt->GetAlign(&v_align)); - MathedIter it; - it.SetData(mt->GetData()); - array = it.Copy(); - if (mt->row != 0) { - MathedRowSt *r, *ro= 0, *mrow = mt->row; - mrow = mt->row; - while (mrow) { - r = new MathedRowSt(nc+1); - r->numbered = mrow->numbered; - if (mrow->label) - r->label = strnew(mrow->label); - if (!ro) - row = r; - else - ro->next = r; - mrow = mrow->next; - ro = r; - nr++; - } - } else - row = 0; - flag = mt->flag; -} - - -MathMatrixInset::~MathMatrixInset() -{ - delete[] ws; - - MathedRowSt *r = row; - while (r) { - MathedRowSt *q = r->next; - delete r; - r = q; - } -} - -MathedInset *MathMatrixInset::Clone() -{ - MathMatrixInset* mt = new MathMatrixInset(this); - return mt; -} - -void MathMatrixInset::SetAlign(char vv, char const* hh) -{ - v_align = vv; - strncpy(h_align, hh, nc); -} - - -// Check the number of tabs and crs -void MathMatrixInset::SetData(LyxArrayBase *a) -{ - if (!a) return; - MathedIter it(a); - int nn = nc-1; - nr = 1; - // count tabs per row - while (it.OK()) { - if (it.IsTab()) { - if (nn<0) { - it.Delete(); - continue; - } else { -// it.Next(); - nn--; - } - } - if (it.IsCR()) { - while (nn>0) { - it.Insert(' ', LM_TC_TAB); - nn--; - } - nn = nc-1; - nr++; - } - it.Next(); - } - it.Reset(); - - // Automatically inserts tabs around bops - // DISABLED because it's very easy to insert tabs - array = a; -} - - -void MathMatrixInset::Draw(int x, int baseline) -{ - MathParInset::Draw(x, baseline); -} - -void MathMatrixInset::Metrics() -{ - int i, /*cy,*/ hl, h= 0; - MathedRowSt *cprow= 0, *cxrow; - - if (!row) { -// lyxerr << " MIDA "; - MathedXIter it(this); - row = it.adjustVerticalSt(); - } - - // Clean the arrays - cxrow = row; - while (cxrow) { - for (i= 0; i<= nc; i++) cxrow->w[i] = 0; - cxrow = cxrow->next; - } - - // Basic metrics - MathParInset::Metrics(); - - if (nc<= 1 && !row->next) { - row->asc = ascent; - row->desc = descent; - } - - // Vertical positions of each row - cxrow = row; - while (cxrow) { - for (i= 0; iw[i]) ws[i]= cxrow->w[i]; - if (cxrow->next == 0 && ws[i] == 0) ws[i] = df_width; - } - - cxrow->y = (cxrow == row) ? cxrow->asc: - cxrow->asc + cprow->desc + MATH_ROWSEP + cprow->y; - h += cxrow->asc + cxrow->desc + MATH_ROWSEP; - cprow = cxrow; - cxrow = cxrow->next; - } - - hl = Descent(); - h -= MATH_ROWSEP; - - // Compute vertical align - switch (v_align) { - case 't': ascent = row->y; break; - case 'b': ascent = h - hl; break; - default: ascent = (row->next) ? h/2: h - hl; break; - } - descent = h - ascent + 2; - - - // Adjust local tabs - cxrow = row; - width = MATH_COLSEP; - while (cxrow) { - int rg= MATH_COLSEP, ww, lf= 0, *w = cxrow->w; - for (i= 0; i= 0) { + size_ = sz; + flag = flag & ~LMPF_FIXED_SIZE; } - cxrow->y -= ascent; - cxrow = cxrow->next; - } } +*/ -MathAccentInset::MathAccentInset(byte cx, MathedTextCodes f, int cd, short st): - MathedInset("", LM_OT_ACCENT, st), c(cx), fn(f), code(cd) +void MathInset::writeNormal(std::ostream & os) const { - inset = 0; + os << "[unknown] "; } -MathAccentInset::MathAccentInset(MathedInset *ins, int cd, short st): - MathedInset("", LM_OT_ACCENT, st), c(0), fn(LM_TC_MIN), code(cd), inset(ins) + +void MathInset::dump() const { + lyxerr << "---------------------------------------------\n"; + write(lyxerr, false); + lyxerr << "\n---------------------------------------------\n"; } -MathAccentInset::~MathAccentInset() +void MathInset::push_back(unsigned char, MathTextCodes) { - if (inset) - delete inset; + lyxerr << "can't push without a cell\n"; } -MathedInset *MathAccentInset::Clone() -{ - MathAccentInset* p; - - if (inset) - p = new MathAccentInset(inset->Clone(), code, GetStyle()); - else - p = new MathAccentInset(c, fn, code, GetStyle()); - - return p; + +void MathInset::push_back(MathInset *) +{ + lyxerr << "can't push without a cell\n"; } -MathBigopInset::MathBigopInset(char const* nam, int id, short st): - MathedInset(nam, LM_OT_BIGOP, st), sym(id) +bool MathInset::covers(int x, int y) const { - lims = -1; + return + x >= xo_ && + x <= xo_ + width() && + y >= yo_ - ascent() && + y <= yo_ + descent(); } -MathedInset *MathBigopInset::Clone() -{ - MathBigopInset* p = new MathBigopInset(name, sym, GetStyle()); - return p; + +void MathInset::validate(LaTeXFeatures &) const +{} + + +std::vector MathInset::idxBetween(int from, int to) const +{ + std::vector res; + for (int i = from; i <= to; ++i) + res.push_back(i); + return res; } - -MathDotsInset::MathDotsInset(char const* nam, int id, short st): - MathedInset(nam, LM_OT_DOTS, st), code(id) + + +void MathInset::metrics(MathStyles st) const { + lyxerr << "MathInset::metrics() called directly!\n"; + size_ = st; } -MathedInset *MathDotsInset::Clone() + +void MathInset::draw(Painter &, int, int) const { - MathDotsInset* p = new MathDotsInset(name, code, GetStyle()); - return p; -} + lyxerr << "MathInset::draw() called directly!\n"; +} + +void MathInset::write(std::ostream &, bool) const +{ + lyxerr << "MathInset::write() called directly!\n"; +}