- 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; i<nc; i++) {
- if (cxrow == row || ws[i]<cxrow->w[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<nc; i++) {
- bool isvoid = false;
- if (w[i]<= 0) {
- w[i] = df_width;
- isvoid = true;
- }
- switch (h_align[i]) {
- case 'l': lf = 0; break;
- case 'c': lf = (ws[i] - w[i])/2;
- break;
- case 'r': lf = ws[i] - w[i]; break;
- }
- ww = (isvoid) ? lf: lf + w[i];
- w[i] = lf + rg;
- rg = ws[i] - ww + MATH_COLSEP;
- if (cxrow == row) width += ws[i] + MATH_COLSEP;