]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_gridinset.C
use stream-like syntax for LaTeX output
[lyx.git] / src / mathed / math_gridinset.C
index 074b76fbfe3f400d9476f0d1f2075cb337d5b01f..4b3c16d606522c2c76d048f9048c866894276d19 100644 (file)
@@ -132,7 +132,7 @@ LyXLength MathGridInset::vskip(row_type row) const
 }
 
 
-void MathGridInset::metrics(MathStyles st) const
+void MathGridInset::metrics(MathMetricsInfo const & st) const
 {
        // let the cells adjust themselves
        MathNestInset::metrics(st);
@@ -264,15 +264,29 @@ void MathGridInset::draw(Painter & pain, int x, int y) const
 }
 
 
-void MathGridInset::write(std::ostream & os, bool fragile) const
+void MathGridInset::write(MathWriteInfo & os) const
 {
        for (row_type row = 0; row < nrows(); ++row) {
+               for (col_type col = 0; col < ncols(); ++col) 
+                       os << cell(index(row, col)) << eocString(col);
+               os << eolString(row);
+       }
+}
+
+
+void MathGridInset::writeNormal(std::ostream & os) const
+{
+       os << "[grid ";
+       for (row_type row = 0; row < nrows(); ++row) {
+               os << "[row ";
                for (col_type col = 0; col < ncols(); ++col) {
-                       cell(index(row, col)).write(os, fragile);
-                       os << eocString(col);
+                       os << "[cell ";
+                       cell(index(row, col)).writeNormal(os);
+                       os << "]";
                }
-               os << eolString(row);
+               os << "]";
        }
+       os << "]";
 }
 
 
@@ -464,20 +478,26 @@ void MathGridInset::idxDelete(idx_type & idx, bool & popit, bool & deleteit)
        popit    = false;
        deleteit = false;
 
-       // delete entire row if in first cell of empty row
-       if (col(idx) == 0 && nrows() > 1) {
+       // delete entire sequence of ncols() empty cells if possible
+       if (idx <= index(nrows() - 1, 0))       {
                bool deleterow = true;
                for (idx_type i = idx; i < idx + ncols(); ++i)
                        if (cell(i).size()) {
                                deleterow = false;
                                break;
                        }
-               if (deleterow) 
+
+               if (deleterow) {
+                       // move cells if necessary
+                       for (idx_type i = index(row(idx), 0); i < idx; ++i)
+                               cell(i).swap(cell(i + ncols()));
+                       
                        delRow(row(idx));
 
-               if (idx >= nargs())
-                       idx = nargs() - 1;
-               return;
+                       if (idx >= nargs())
+                               idx = nargs() - 1;
+                       return;
+               }
        }
 
        // undo effect of Ctrl-Tab (i.e. pull next cell)