]> git.lyx.org Git - lyx.git/blobdiff - src/tabular.C
more changes, read the Changelog
[lyx.git] / src / tabular.C
index 0d05fddbb25268ae4cfc05ce48f0a51ef1802c17..feb9c652b79df35aaec89e061df5b9772df3fa66 100644 (file)
@@ -40,6 +40,8 @@ using std::vector;
 
 static int const WIDTH_OF_LINE = 5;
 
+extern BufferView * current_view;
+
 /// Define a few methods for the inner structs
 
 LyXTabular::cellstruct::cellstruct() 
@@ -52,46 +54,6 @@ LyXTabular::cellstruct::cellstruct()
     bottom_line = false;
     rotate = false;
     linebreaks = false;
-    inset = 0;
-}
-
-
-LyXTabular::cellstruct::~cellstruct() 
-{
-    delete inset;
-}
-
-
-LyXTabular::cellstruct::cellstruct(cellstruct const & cs)
-{
-    cellno = cs.cellno;
-    width_of_cell = cs.width_of_cell;
-    multicolumn = cs.multicolumn;
-    alignment = cs.alignment;
-    top_line = cs.top_line;
-    bottom_line = cs.bottom_line;
-    rotate = cs.rotate;
-    linebreaks = cs.linebreaks;
-    inset = 0;
-//    if (cs.inset)
-//     inset = static_cast<InsetText *>(cs.inset->Clone());
-}
-
-
-LyXTabular::cellstruct & 
-LyXTabular::cellstruct::operator=(cellstruct const & cs)
-{
-    cellno = cs.cellno;
-    width_of_cell = cs.width_of_cell;
-    multicolumn = cs.multicolumn;
-    alignment = cs.alignment;
-    top_line = cs.top_line;
-    bottom_line = cs.bottom_line;
-    rotate = cs.rotate;
-    linebreaks = cs.linebreaks;
-    if (cs.inset)
-       inset = static_cast<InsetText *>(cs.inset->Clone());
-    return *this;
 }
 
 
@@ -131,10 +93,10 @@ LyXTabular::LyXTabular(InsetTabular * inset, LyXTabular const & lt)
 }
 
 
-LyXTabular::LyXTabular(InsetTabular * inset, LyXLex & lex)
+LyXTabular::LyXTabular(Buffer const * buf, InsetTabular * inset, LyXLex & lex)
 {
     owner_ = inset;
-    Read(lex);
+    Read(buf, lex);
 }
 
 
@@ -181,10 +143,8 @@ LyXTabular * LyXTabular::Clone(InsetTabular * inset)
     int i,j;
     for(i=0; i < rows_; ++i) {
        for(j=0; j < columns_; ++j) {
-           delete result->cell_info[i][j].inset;
-           result->cell_info[i][j].inset=new InsetText(*cell_info[i][j].inset,
-                                                       inset->BufferOwner());
-           result->cell_info[i][j].inset->setOwner(inset);
+           result->cell_info[i][j].inset = cell_info[i][j].inset;
+           result->cell_info[i][j].inset.setOwner(inset);
        }
     }
     return result;
@@ -207,10 +167,8 @@ void LyXTabular::Init(int rows_arg, int columns_arg)
     // Jürgen, use iterators.
     for (i = 0; i < rows_; ++i) {
         for (j = 0; j < columns_; ++j) {
-           if (!cell_info[i][j].inset)
-               cell_info[i][j].inset = new InsetText(owner_->BufferOwner());
-           cell_info[i][j].inset->setOwner(owner_);
-           cell_info[i][j].inset->SetDrawLockedFrame(true);
+           cell_info[i][j].inset.setOwner(owner_);
+           cell_info[i][j].inset.SetDrawFrame(0, InsetText::LOCKED);
             cell_info[i][j].cellno = cellno++;
         }
     }
@@ -238,45 +196,36 @@ void LyXTabular::Init(int rows_arg, int columns_arg)
 
 void LyXTabular::AppendRow(int cell )
 {
-//    cell_vector::iterator cit = cell_info.begin() + row;
-//    cell_info.insert(cit, vector<cellstruct>(columns_, cellstruct()));
-//    cell_info.insert(cell_info.begin(), vector<cellstruct>(columns_, cellstruct()));
-
     ++rows_;
    
-//    row_vector r_info = row_vector(rows_, rowstruct());
-
-    cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_,
-                                                         cellstruct()));
     int row = row_of_cell(cell);
-    int i;
 
     row_vector::iterator rit = row_info.begin() + row;
     row_info.insert(rit, rowstruct());
 
-    for(i = 0; i <= row; ++i) {
-//     r_info[i] = row_info[i];
+#if 0
+    cell_vvector::iterator cit = cell_info.begin() + row;
+    cell_info.insert(cit, vector<cellstruct>(columns_, cellstruct()));
+#else
+    cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_,
+                                                         cellstruct()));
+
+    for(int i = 0; i <= row; ++i) {
        for(int j = 0; j < columns_; ++j) {
            c_info[i][j] = cell_info[i][j];
        }
     }
-    for(i = row+1; i < rows_; ++i) {
-//     r_info[i] = row_info[i-1];
+    for(int i = row+1; i < rows_; ++i) {
        for(int j = 0; j < columns_; ++j) {
            c_info[i][j] = cell_info[i-1][j];
        }
     }
-//    row_info = r_info;
     cell_info = c_info;
-    for(i = 0; i < rows_; ++i) {
-       for(int j = 0; j < columns_; ++j) {
-           cell_info[i][j].inset = static_cast<InsetText *>(c_info[i][j].inset->Clone());
-       }
-    }
     ++row;
     for (int j = 0; j < columns_; ++j) {
-       cell_info[row][j].inset->clear();
+       cell_info[row][j].inset.clear();
     }
+#endif
     Reinit();
 }
 
@@ -320,14 +269,9 @@ void LyXTabular::AppendColumn(int cell)
         }
     }
     cell_info = c_info;
-    for(i = 0; i < rows_; ++i) {
-       for(j = 0; j < columns_; ++j) {
-           cell_info[i][j].inset = static_cast<InsetText *>(c_info[i][j].inset->Clone());
-       }
-    }
     ++column;
     for (i = 0; i < rows_; ++i) {
-       cell_info[i][column].inset->clear();
+       cell_info[i][column].inset.clear();
     }
     Reinit();
 }
@@ -356,6 +300,7 @@ void LyXTabular::Reinit()
     for (; i < rows_; ++i) {
        for (j = 0; j < columns_; ++j) {
            cell_info[i][j].width_of_cell = 0;
+           cell_info[i][j].inset.setOwner(owner_);
        }
     }
   
@@ -409,7 +354,7 @@ void LyXTabular::set_row_column_number_info()
        for (column = 0; column<columns_; ++column) {
            if (IsPartOfMultiColumn(row,column))
                continue;
-           cell_info[row][column].inset->SetAutoBreakRows(
+           cell_info[row][column].inset.SetAutoBreakRows(
                !GetPWidth(GetCellNumber(row, column)).empty());
        }
     }
@@ -905,7 +850,7 @@ int LyXTabular::right_column_of_cell(int cell) const
 }
 
 
-void LyXTabular::Write(ostream & os) const
+void LyXTabular::Write(Buffer const * buf, ostream & os) const
 {
     int i, j;
 
@@ -944,7 +889,7 @@ void LyXTabular::Write(ostream & os) const
                "\" special=\"" << cell_info[i][j].align_special <<
                "\">" << endl;
            os << "\\begin_inset ";
-           cell_info[i][j].inset->Write(os);
+           cell_info[i][j].inset.Write(buf, os);
            os << "\n\\end_inset " << endl;
            os << "</Cell>" << endl;
            os << "</Column>" << endl;
@@ -1037,7 +982,7 @@ void l_getline(istream & is, string & str)
 }
 
 
-void LyXTabular::Read(LyXLex & lex)
+void LyXTabular::Read(Buffer const * buf, LyXLex & lex)
 {
     string line;
     istream & is = lex.getStream();
@@ -1110,7 +1055,7 @@ void LyXTabular::Read(LyXLex & lex)
            (void)getTokenValue(line, "special", cell_info[i][j].align_special);
            l_getline(is, line);
            if (prefixIs(line, "\\begin_inset")) {
-               cell_info[i][j].inset->Read(lex);
+               cell_info[i][j].inset.Read(buf, lex);
                l_getline(is, line);
            }
            if (line != "</Cell>") {
@@ -1292,10 +1237,10 @@ void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl)
     }
     // now we have the par we should fill the insets with this!
     int cell = 0;
-    InsetText *inset = GetCellInset(cell);
+    InsetText * inset = GetCellInset(cell);
     int row;
 
-    for(int i=0; i < par->Last(); ++i) {
+    for(int i = 0; i < par->Last(); ++i) {
        if (par->IsNewline(i)) {
            ++cell;
            if (cell > GetNumberOfCells()) {
@@ -1322,7 +1267,7 @@ void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl)
                par->InsertChar(i, ' ');
            }
        }
-       par->CopyIntoMinibuffer(i);
+       par->CopyIntoMinibuffer(current_view->buffer()->params, i);
        inset->par->InsertFromMinibuffer(inset->par->Last());
     }
     Reinit();
@@ -1767,19 +1712,21 @@ bool LyXTabular::GetLTNewPage(int cell) const
 }
 
 
-void LyXTabular::SetAscentOfRow(int row, int height)
+bool LyXTabular::SetAscentOfRow(int row, int height)
 {
-    if (row >= rows_)
-        return;
+    if ((row >= rows_) || (row_info[row].ascent_of_row == height))
+        return false;
     row_info[row].ascent_of_row = height;
+    return true;
 }
 
 
-void LyXTabular::SetDescentOfRow(int row, int height)
+bool LyXTabular::SetDescentOfRow(int row, int height)
 {
-    if (row >= rows_)
-        return;
+    if ((row >= rows_) || (row_info[row].descent_of_row == height))
+        return false;
     row_info[row].descent_of_row = height;
+    return true;
 }
 
 
@@ -1945,7 +1892,7 @@ int LyXTabular::TeXCellPostamble(ostream & os, int cell) const
 }
 
 
-int LyXTabular::Latex(ostream & os, bool fragile, bool fp) const
+int LyXTabular::Latex(Buffer const * buf, ostream & os, bool fragile, bool fp) const
 {
     int ret = 0;
     int i,j;
@@ -2001,7 +1948,7 @@ int LyXTabular::Latex(ostream & os, bool fragile, bool fp) const
            if (IsPartOfMultiColumn(i,j))
                continue;
            ret += TeXCellPreamble(os, cell);
-           ret += GetCellInset(cell)->Latex(os, fragile, fp);
+           ret += GetCellInset(cell)->Latex(buf, os, fragile, fp);
            ret += TeXCellPostamble(os, cell);
            if (!IsLastCellInRow(cell)) { // not last cell in row
                os << "&" << endl;
@@ -2054,7 +2001,7 @@ int LyXTabular::Latex(ostream & os, bool fragile, bool fp) const
 
 InsetText * LyXTabular::GetCellInset(int cell) const
 {
-    return cell_info[row_of_cell(cell)][column_of_cell(cell)].inset;
+    return cell_info[row_of_cell(cell)][column_of_cell(cell)].inset;
 }
 
 void LyXTabular::Validate(LaTeXFeatures & features) const