]> git.lyx.org Git - features.git/commitdiff
Commiting my changes till now. Mainly (only?) changes to make text-insets and
authorJürgen Vigna <jug@sad.it>
Thu, 4 May 2000 08:14:34 +0000 (08:14 +0000)
committerJürgen Vigna <jug@sad.it>
Thu, 4 May 2000 08:14:34 +0000 (08:14 +0000)
tabular insets work. After all the complaints about the tabular-save format
I redid it completely, have a look ;)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@711 a592a061-630c-0410-9148-cb99ea01b6c8

17 files changed:
ChangeLog
src/buffer.C
src/buffer.h
src/insets/insetfoot.C
src/insets/insettabular.C
src/insets/insettabular.h
src/insets/insettext.C
src/insets/insettext.h
src/insets/lyxinset.h
src/lyxcursor.h
src/lyxtext.h
src/paragraph.C
src/table.C
src/tabular.C
src/tabular.h
src/texrow.h
src/text2.C

index 9eaa9fa1d67c98276205c02d0bdc807d5a1845c6..179ff7afd7ece2bdc539411890c7602c53479cc7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,37 @@
+2000-05-04  Juergen Vigna  <jug@sad.it>
+
+       * src/insets/insettext.C: Prepared all for inserting of multiple
+       paragraphs. Still display stuff to do (alignment and other things),
+       but I would like to use LyXText to do this when we cleaned out the
+       table-support stuff.
+
+       * src/insets/insettabular.C: Changed lot of stuff and added lots
+       of functionality still a lot to do.
+
+       * src/tabular.C: Various functions changed name and moved to be
+       const functions. Added new Read and Write functions and changed
+       lots of things so it works good with tabular-insets (also removed
+       some stuff which is not needed anymore * hacks *).
+
+       * src/lyxcursor.h: added operators == and != which just look if
+       par and pos are (not) equal.
+
+       * src/buffer.C (latexParagraphs): inserted this function to latex
+       all paragraphs form par to endpar as then I can use this too for
+       text-insets.
+
+       * src/text2.C (SetLayout): Changed this to use a cursor this is needed
+       so that I can call this to from text insets with their own cursor.
+
+       * src/buffer.C (makeLaTeXFile): added the output of one \n after the
+       output off all paragraphs (because of the fix below)!
+
+       * src/paragraph.C (TeXOnePar): removed output of \n when we are in
+       the very last paragraph (this could be also the last paragraph of an
+       inset!)
+
+       * src/texrow.h: added rows() call which returns the count-variable.
+
 2000-05-03  Jose Abilio Oliveira Matos <jamatos@novalis.fc.up.pt>
 
        * lib/lyxrc.example: fix examples for exporting SGML to HTML.
 2000-05-03  Jose Abilio Oliveira Matos <jamatos@novalis.fc.up.pt>
 
        * lib/lyxrc.example: fix examples for exporting SGML to HTML.
index 1509fb19fb6996a6e9f86fa8bf603ea760dbd3bf..ff33b4b0b3a9a5386d6066f16ab2c8116ea59492 100644 (file)
@@ -71,6 +71,7 @@
 #include "insets/insetert.h"
 #include "insets/insetgraphics.h"
 #include "insets/insetfoot.h"
 #include "insets/insetert.h"
 #include "insets/insetgraphics.h"
 #include "insets/insetfoot.h"
+#include "insets/insettabular.h"
 #include "support/filetools.h"
 #include "support/path.h"
 #include "LaTeX.h"
 #include "support/filetools.h"
 #include "support/path.h"
 #include "LaTeX.h"
@@ -822,6 +823,13 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
                        par->InsertInset(pos, inset);
                        par->SetFont(pos, font);
                        ++pos;
                        par->InsertInset(pos, inset);
                        par->SetFont(pos, font);
                        ++pos;
+               } else if (tmptok == "Tabular") {
+                       Inset * inset = new InsetTabular(this);
+                       inset->Read(lex);
+                       par->InsertChar(pos, LyXParagraph::META_INSET);
+                       par->InsertInset(pos, inset);
+                       par->SetFont(pos, font);
+                       ++pos;
                } else if (tmptok == "Text") {
                        Inset * inset = new InsetText(this);
                        inset->Read(lex);
                } else if (tmptok == "Text") {
                        Inset * inset = new InsetText(this);
                        inset->Read(lex);
@@ -2025,6 +2033,52 @@ void Buffer::makeLaTeXFile(string const & fname,
                texrow.newline();
        }
        
                texrow.newline();
        }
        
+       latexParagraphs(ofs, paragraph, 0, texrow);
+
+       // add this just in case after all the paragraphs
+       ofs << endl;
+       texrow.newline();
+
+       if (!lyxrc.language_auto_end && params.language != "default") {
+               ofs << subst(lyxrc.language_command_end, "$$lang",
+                            params.language)
+                   << endl;
+               texrow.newline();
+       }
+
+       if (!only_body) {
+               ofs << "\\end{document}\n";
+               texrow.newline();
+       
+               lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
+       } else {
+               lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
+                                    << endl;
+       }
+
+       // Just to be sure. (Asger)
+       texrow.newline();
+
+       // tex_code_break_column's value is used to decide
+       // if we are in batchmode or not (within mathed_write()
+       // in math_write.C) so we must set it to a non-zero
+       // value when we leave otherwise we save incorrect .lyx files.
+       tex_code_break_column = lyxrc.ascii_linelen;
+
+       ofs.close();
+       if (ofs.fail()) {
+               lyxerr << "File was not closed properly." << endl;
+       }
+       
+       lyxerr.debug() << "Finished making latex file." << endl;
+}
+
+//
+// LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
+//
+void Buffer::latexParagraphs(ostream & ofs, LyXParagraph *par,
+                            LyXParagraph *endpar, TexRow & texrow)
+{
        bool was_title = false;
        bool already_title = false;
 #ifdef HAVE_SSTREAM
        bool was_title = false;
        bool already_title = false;
 #ifdef HAVE_SSTREAM
@@ -2035,10 +2089,8 @@ void Buffer::makeLaTeXFile(string const & fname,
        TexRow ft_texrow;
        int ftcount = 0;
 
        TexRow ft_texrow;
        int ftcount = 0;
 
-       LyXParagraph * par = paragraph;
-
        // if only_body
        // if only_body
-       while (par) {
+       while (par != endpar) {
 #ifndef HAVE_SSTREAM
                ostrstream ftnote;
                if (tmpholder) {
 #ifndef HAVE_SSTREAM
                ostrstream ftnote;
                if (tmpholder) {
@@ -2048,7 +2100,7 @@ void Buffer::makeLaTeXFile(string const & fname,
                }
 #endif
                if (par->IsDummy())
                }
 #endif
                if (par->IsDummy())
-                       lyxerr[Debug::LATEX] << "Error in MakeLateXFile."
+                       lyxerr[Debug::LATEX] << "Error in latexParagraphs."
                                             << endl;
                LyXLayout const & layout =
                        textclasslist.Style(params.textclass,
                                             << endl;
                LyXLayout const & layout =
                        textclasslist.Style(params.textclass,
@@ -2056,7 +2108,7 @@ void Buffer::makeLaTeXFile(string const & fname,
            
                if (layout.intitle) {
                        if (already_title) {
            
                if (layout.intitle) {
                        if (already_title) {
-                               lyxerr <<"Error in MakeLatexFile: You"
+                               lyxerr <<"Error in latexParagraphs: You"
                                        " should not mix title layouts"
                                        " with normal ones." << endl;
                        } else
                                        " should not mix title layouts"
                                        " with normal ones." << endl;
                        } else
@@ -2114,42 +2166,8 @@ void Buffer::makeLaTeXFile(string const & fname,
                ofs << "\\maketitle\n";
                texrow.newline();
        }
                ofs << "\\maketitle\n";
                texrow.newline();
        }
-
-       if (!lyxrc.language_auto_end && params.language != "default") {
-               ofs << subst(lyxrc.language_command_end, "$$lang",
-                            params.language)
-                   << endl;
-               texrow.newline();
-       }
-
-       if (!only_body) {
-               ofs << "\\end{document}\n";
-               texrow.newline();
-       
-               lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
-       } else {
-               lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
-                                    << endl;
-       }
-
-       // Just to be sure. (Asger)
-       texrow.newline();
-
-       // tex_code_break_column's value is used to decide
-       // if we are in batchmode or not (within mathed_write()
-       // in math_write.C) so we must set it to a non-zero
-       // value when we leave otherwise we save incorrect .lyx files.
-       tex_code_break_column = lyxrc.ascii_linelen;
-
-       ofs.close();
-       if (ofs.fail()) {
-               lyxerr << "File was not closed properly." << endl;
-       }
-       
-       lyxerr.debug() << "Finished making latex file." << endl;
 }
 
 }
 
-
 bool Buffer::isLatex() const
 {
        return textclasslist.TextClass(params.textclass).outputType() == LATEX;
 bool Buffer::isLatex() const
 {
        return textclasslist.TextClass(params.textclass).outputType() == LATEX;
index 32f669e59acb8021c94f9a5c34719d2d8eb3bcfc..991d166c78246b07f0d3f12f62bbc09a4462463e 100644 (file)
@@ -153,6 +153,12 @@ public:
        void makeLaTeXFile(string const & filename,
                           string const & original_path,
                           bool nice, bool only_body = false);
        void makeLaTeXFile(string const & filename,
                           string const & original_path,
                           bool nice, bool only_body = false);
+       //
+       // LaTeX all paragraphs from par to endpar,
+       // if endpar == 0 then to the end
+       //
+       void latexParagraphs(ostream & os, LyXParagraph *par,
+                            LyXParagraph *endpar, TexRow & texrow);
 
        ///
        int runLaTeX();
 
        ///
        int runLaTeX();
index 4b09114c098ee7930528626d548f36da176c1711..07c8335353ed9a3ccf279eb9d32eb0bb2f5aa869 100644 (file)
@@ -54,15 +54,12 @@ char const * InsetFoot::EditMessage() const
 
 int InsetFoot::Latex(ostream & os, bool fragile, bool fp) const
 {
 
 int InsetFoot::Latex(ostream & os, bool fragile, bool fp) const
 {
-    if (fragile) 
-       os << "\\footnote{"; // was footnotemark but that won't work
-    else 
-       os << "\\footnote{";
+    os << "\\footnote{%" << endl;
     
     int i = InsetText::Latex(os, fragile, fp);
     
     int i = InsetText::Latex(os, fragile, fp);
-    os << "}";
+    os << "}%" << endl;
     
     
-    return i;
+    return i + 2;
 }
 
 
 }
 
 
index c958ec13ef9502e63238375d44e8a2a3e0307502..8e6e8e98dc70d19733fbb658c02ee6e3a3d106fd 100644 (file)
@@ -26,6 +26,7 @@
 #include "LaTeXFeatures.h"
 #include "Painter.h"
 #include "font.h"
 #include "LaTeXFeatures.h"
 #include "Painter.h"
 #include "font.h"
+#include "lyxtext.h"
 #include "insets/insettext.h"
 
 const int ADD_TO_HEIGHT = 2;
 #include "insets/insettext.h"
 
 const int ADD_TO_HEIGHT = 2;
@@ -51,7 +52,7 @@ InsetTabular::InsetTabular(Buffer * buf, int rows, int columns)
     buffer = buf;
     cursor_visible = false;
     cursor.x_fix = -1;
     buffer = buf;
     cursor_visible = false;
     cursor.x_fix = -1;
-    sel_pos_start = sel_pos_end = 0;
+    actcell = cursor.pos = sel_pos_start = sel_pos_end = 0;
     no_selection = false;
     init = true;
 }
     no_selection = false;
     init = true;
 }
@@ -64,7 +65,7 @@ InsetTabular::InsetTabular(InsetTabular const & tab, Buffer * buf)
     buffer = buf;
     cursor_visible = false;
     cursor.x_fix = -1;
     buffer = buf;
     cursor_visible = false;
     cursor.x_fix = -1;
-    sel_pos_start = sel_pos_end = 0;
+    actcell = cursor.pos = sel_pos_start = sel_pos_end = 0;
     no_selection = false;
     init = true;
 }
     no_selection = false;
     init = true;
 }
@@ -72,7 +73,7 @@ InsetTabular::InsetTabular(InsetTabular const & tab, Buffer * buf)
 
 InsetTabular::~InsetTabular()
 {
 
 InsetTabular::~InsetTabular()
 {
-        delete tabular;
+    delete tabular;
 }
 
 
 }
 
 
@@ -85,18 +86,31 @@ Inset * InsetTabular::Clone() const
 
 void InsetTabular::Write(ostream & os) const
 {
 
 void InsetTabular::Write(ostream & os) const
 {
-    os << "\\begin_inset Tabular\n";
-    tabular->Write(os,false);
-    os << "\\end_inset\n";
+    os << " Tabular" << endl;
+    tabular->Write(os);
 }
 
 
 void InsetTabular::Read(LyXLex & lex)
 {
 }
 
 
 void InsetTabular::Read(LyXLex & lex)
 {
-       delete tabular;
+//    bool old_format = (lex.GetString() == "\\LyXTable");
+    string token;
 
 
-//    bool old_format = (lex.GetString() == "\\LyXTabular");
+    if (tabular)
+       delete tabular;
     tabular = new LyXTabular(lex, buffer);
     tabular = new LyXTabular(lex, buffer);
+
+    lex.nextToken();
+    token = lex.GetString();
+    while (lex.IsOK() && (token != "\\end_inset")) {
+       lex.nextToken();
+       token = lex.GetString();
+    }
+    if (token != "\\end_inset") {
+        lex.printError("Missing \\end_inset at this point. "
+                       "Read: `$$Token'");
+    }
+    tabular->SetLongTabular(true);
     init = true;
 }
 
     init = true;
 }
 
@@ -107,7 +121,7 @@ int InsetTabular::ascent(Painter & pain, LyXFont const & font) const
        calculate_width_of_cells(pain, font);
        init = false;
     }
        calculate_width_of_cells(pain, font);
        init = false;
     }
-    return tabular->AscentOfRow(0);
+    return tabular->GetAscentOfRow(0);
 }
 
 
 }
 
 
@@ -117,7 +131,7 @@ int InsetTabular::descent(Painter & pain, LyXFont const & font) const
        calculate_width_of_cells(pain, font);
        init = false;
     }
        calculate_width_of_cells(pain, font);
        init = false;
     }
-    return tabular->HeightOfTabular() - tabular->AscentOfRow(0);
+    return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0);
 }
 
 
 }
 
 
@@ -127,7 +141,7 @@ int InsetTabular::width(Painter & pain, LyXFont const & font) const
        calculate_width_of_cells(pain, font);
        init = false;
     }
        calculate_width_of_cells(pain, font);
        init = false;
     }
-    return tabular->WidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
+    return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
 }
 
 
 }
 
 
@@ -136,25 +150,61 @@ void InsetTabular::draw(Painter & pain, const LyXFont & font, int baseline,
 {
     int i, j, cell=0;
     int nx;
 {
     int i, j, cell=0;
     int nx;
+    float cx;
 
     UpdatableInset::draw(pain,font,baseline,x);
 
     UpdatableInset::draw(pain,font,baseline,x);
-    if (top_x != int(x)) {
-       int ox = top_x;
+    if ((top_x != int(x)) || (top_baseline != baseline)) {
        top_x = int(x);
        top_x = int(x);
-       setPos(pain, cursor.x - ox - 2, cursor.y);
+       top_baseline = baseline;
+       resetPos(pain);
     }
     }
-    top_baseline = baseline;
-    calculate_width_of_cells(pain, font);
     for(i=0;i<tabular->rows();++i) {
        nx = int(x);
         for(j=0;j<tabular->columns();++j) {
     for(i=0;i<tabular->rows();++i) {
        nx = int(x);
         for(j=0;j<tabular->columns();++j) {
+           cx = nx + tabular->GetBeginningOfTextInCell(cell);
+           tabular->GetCellInset(cell)->draw(pain, font, baseline, cx);
            DrawCellLines(pain, nx, baseline, i, cell);
            DrawCellLines(pain, nx, baseline, i, cell);
-           nx += tabular->WidthOfColumn(cell);
+           nx += tabular->GetWidthOfColumn(cell);
            ++cell;
        }
            ++cell;
        }
-        baseline += tabular->DescentOfRow(i) + tabular->AscentOfRow(i+1)
-            + tabular->AdditionalHeight(cell+1);
+        baseline += tabular->GetDescentOfRow(i) + tabular->GetAscentOfRow(i+1)
+            + tabular->GetAdditionalHeight(cell+1);
+    }
+}
+
+
+void InsetTabular::DrawCellLines(Painter & pain, int x, int baseline,
+                                 int row, int cell) const
+{
+    int  x2 = x + tabular->GetWidthOfColumn(cell);
+    bool on_off;
+
+    if (!tabular->TopAlreadyDrawed(cell)) {
+       on_off = !tabular->TopLine(cell);
+       pain.line(x, baseline - tabular->GetAscentOfRow(row),
+                 x2, baseline -  tabular->GetAscentOfRow(row),
+                 on_off ? LColor::tabularonoffline:LColor::tabularline,
+                 on_off ? Painter::line_onoffdash:Painter::line_solid);
+    }
+    on_off = !tabular->BottomLine(cell);
+    pain.line(x,baseline +  tabular->GetDescentOfRow(row),
+             x2, baseline +  tabular->GetDescentOfRow(row),
+             on_off ? LColor::tabularonoffline:LColor::tabularline,
+             on_off ? Painter::line_onoffdash:Painter::line_solid);
+    if (!tabular->LeftAlreadyDrawed(cell)) {
+       on_off = !tabular->LeftLine(cell);
+       pain.line(x, baseline -  tabular->GetAscentOfRow(row),
+                 x, baseline +  tabular->GetDescentOfRow(row),
+                 on_off ? LColor::tabularonoffline:LColor::tabularline,
+                 on_off ? Painter::line_onoffdash:Painter::line_solid);
     }
     }
+    on_off = !tabular->RightLine(cell);
+    pain.line(x2 - tabular->GetAdditionalWidth(cell),
+              baseline -  tabular->GetAscentOfRow(row),
+              x2 - tabular->GetAdditionalWidth(cell),
+              baseline +  tabular->GetDescentOfRow(row),
+             on_off ? LColor::tabularonoffline:LColor::tabularline,
+              on_off ? Painter::line_onoffdash:Painter::line_solid);
 }
 
 
 }
 
 
@@ -176,7 +226,10 @@ void InsetTabular::Edit(BufferView * bv, int x, int y, unsigned int button)
     sel_pos_start = sel_pos_end = inset_pos = inset_x = inset_y = 0;
     setPos(bv->painter(), x, y);
     sel_pos_start = sel_pos_end = cursor.pos;
     sel_pos_start = sel_pos_end = inset_pos = inset_x = inset_y = 0;
     setPos(bv->painter(), x, y);
     sel_pos_start = sel_pos_end = cursor.pos;
-//    bv->text->FinishUndo();
+    bv->text->FinishUndo();
+    if (InsetHit(bv, x, y)) {
+       ActivateCellInset(bv, x, y, button);
+    }
     UpdateLocal(bv, true);
 //    bv->getOwner()->getPopups().updateFormTabular();
 }
     UpdateLocal(bv, true);
 //    bv->getOwner()->getPopups().updateFormTabular();
 }
@@ -184,10 +237,11 @@ void InsetTabular::Edit(BufferView * bv, int x, int y, unsigned int button)
 
 void InsetTabular::InsetUnlock(BufferView * bv)
 {
 
 void InsetTabular::InsetUnlock(BufferView * bv)
 {
-    if (the_locking_inset)
+    if (the_locking_inset) {
        the_locking_inset->InsetUnlock(bv);
        the_locking_inset->InsetUnlock(bv);
+       the_locking_inset = 0;
+    }
     HideInsetCursor(bv);
     HideInsetCursor(bv);
-    the_locking_inset = 0;
     if (hasCharSelection()) {
        sel_pos_start = sel_pos_end = cursor.pos;
        UpdateLocal(bv, false);
     if (hasCharSelection()) {
        sel_pos_start = sel_pos_end = cursor.pos;
        UpdateLocal(bv, false);
@@ -196,36 +250,58 @@ void InsetTabular::InsetUnlock(BufferView * bv)
     no_selection = false;
 }
 
     no_selection = false;
 }
 
-
-bool InsetTabular::LockInsetInInset(UpdatableInset *)
+void InsetTabular::UpdateLocal(BufferView * bv, bool flag)
 {
 {
-    return true;
+    if (flag)
+       calculate_width_of_cells(bv->painter(), LyXFont(LyXFont::ALL_SANE));
+    bv->updateInset(this, flag);
 }
 
 }
 
-
-bool InsetTabular::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
-                                     bool lr)
+bool InsetTabular::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
 {
 {
-    if (!the_locking_inset)
+    lyxerr[Debug::INSETS] << "InsetTabular::LockInsetInInset(" <<inset<< "): ";
+    if (!inset)
        return false;
        return false;
-    if (the_locking_inset == inset) {
-       the_locking_inset->InsetUnlock(bv);
-       the_locking_inset = 0;
-       if (lr)
-           moveRight(bv);
+    if (inset == tabular->GetCellInset(actcell)) {
+       lyxerr[Debug::INSETS] << "OK" << endl;
+       the_locking_inset = tabular->GetCellInset(actcell);
+       resetPos(bv->painter());
+       inset_x = cursor.x - top_x + tabular->GetBeginningOfTextInCell(actcell);
+       inset_y = cursor.y;
+       inset_pos = cursor.pos;
        return true;
        return true;
+    } else if (the_locking_inset && (the_locking_inset == inset)) {
+       if (cursor.pos == inset_pos) {
+           lyxerr[Debug::INSETS] << "OK" << endl;
+           resetPos(bv->painter());
+           inset_x = cursor.x - top_x + tabular->GetBeginningOfTextInCell(actcell);
+           inset_y = cursor.y;
+       } else {
+           lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
+       }
+    } else if (the_locking_inset) {
+       lyxerr[Debug::INSETS] << "MAYBE" << endl;
+       return the_locking_inset->LockInsetInInset(bv, inset);
     }
     }
-    return the_locking_inset->UnlockInsetInInset(bv, inset, lr);
+    lyxerr[Debug::INSETS] << "NOT OK" << endl;
+    return false;
 }
 
 }
 
-
-void InsetTabular::UpdateLocal(BufferView * bv, bool flag)
+bool InsetTabular::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
+                                  bool lr)
 {
 {
-//    resetPos();
-    bv->updateInset(this, flag);
+    if (!the_locking_inset)
+        return false;
+    if (the_locking_inset == inset) {
+        the_locking_inset->InsetUnlock(bv);
+        the_locking_inset = 0;
+        if (lr)
+            moveRight(bv, false);
+        return true;
+    }
+    return the_locking_inset->UnlockInsetInInset(bv, inset, lr);
 }
 
 }
 
-
 bool InsetTabular::UpdateInsetInInset(BufferView * bv, Inset * inset)
 {
     if (!the_locking_inset)
 bool InsetTabular::UpdateInsetInInset(BufferView * bv, Inset * inset)
 {
     if (!the_locking_inset)
@@ -237,35 +313,53 @@ bool InsetTabular::UpdateInsetInInset(BufferView * bv, Inset * inset)
 }
 
 
 }
 
 
+int InsetTabular::InsetInInsetY()
+{
+    if (!the_locking_inset)
+       return 0;
+
+    return (inset_y + the_locking_inset->InsetInInsetY());
+}
+
 void InsetTabular::InsetButtonRelease(BufferView * bv,
                                      int x, int y, int button)
 {
     if (the_locking_inset) {
 void InsetTabular::InsetButtonRelease(BufferView * bv,
                                      int x, int y, int button)
 {
     if (the_locking_inset) {
-        the_locking_inset->InsetButtonRelease(bv, x-inset_x,y-inset_y,button);
+        the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
         return;
     }
     no_selection = false;
 }
 
 
         return;
     }
     no_selection = false;
 }
 
 
-void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int)
+void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int button)
 {
     if (hasCharSelection()) {
        sel_pos_start = sel_pos_end = 0;
        UpdateLocal(bv, false);
     }
     no_selection = false;
 {
     if (hasCharSelection()) {
        sel_pos_start = sel_pos_end = 0;
        UpdateLocal(bv, false);
     }
     no_selection = false;
-    if (the_locking_inset) {
-       // otherwise only unlock the_locking_inset
+
+    int oldcell = actcell;
+
+    setPos(bv->painter(), x, y);
+
+    bool inset_hit = InsetHit(bv, x, y);
+
+    if ((oldcell == actcell) && the_locking_inset && inset_hit) {
+        the_locking_inset->InsetButtonPress(bv, x-inset_x, y-inset_y, button);
+        return;
+    } else if (the_locking_inset) {
        the_locking_inset->InsetUnlock(bv);
     }
        the_locking_inset->InsetUnlock(bv);
     }
-#if 0
-    int oldcell = actcell;
-#endif
-    setPos(bv->painter(),x,y);
     the_locking_inset = 0;
     sel_pos_start = sel_pos_end = cursor.pos;
     sel_cell_start = sel_cell_end = actcell;
     the_locking_inset = 0;
     sel_pos_start = sel_pos_end = cursor.pos;
     sel_cell_start = sel_cell_end = actcell;
+    if (inset_hit && bv->the_locking_inset) {
+       ActivateCellInset(bv, x, y, button);
+       the_locking_inset->InsetButtonPress(bv, x-inset_x, y-inset_y, button);
+    }
+    
 #if 0
     if (button == 3)
         bview->getOwner()->getPopups().showFormTabular();
 #if 0
     if (button == 3)
         bview->getOwner()->getPopups().showFormTabular();
@@ -319,7 +413,7 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
     if (((result=UpdatableInset::LocalDispatch(bv, action, arg)) == DISPATCHED)
        || (result == DISPATCHED_NOUPDATE)) {
 
     if (((result=UpdatableInset::LocalDispatch(bv, action, arg)) == DISPATCHED)
        || (result == DISPATCHED_NOUPDATE)) {
 
-       resetPos(bv);
+       resetPos(bv->painter());
        return result;
     }
     result=DISPATCHED;
        return result;
     }
     result=DISPATCHED;
@@ -335,15 +429,15 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
        if (result == DISPATCHED_NOUPDATE)
            return result;
        else if (result == DISPATCHED) {
        if (result == DISPATCHED_NOUPDATE)
            return result;
        else if (result == DISPATCHED) {
-            setWidthOfCell(cursor.pos,actcell,actrow);
+            bool upd = SetCellDimensions(bv->painter(), actcell, actrow);
            the_locking_inset->ToggleInsetCursor(bv);
            the_locking_inset->ToggleInsetCursor(bv);
-           UpdateLocal(bv, false);
+           UpdateLocal(bv, upd);
            the_locking_inset->ToggleInsetCursor(bv);
             return result;
         } else if (result == FINISHED) {
            if ((action == LFUN_RIGHT) || (action == -1)) {
                cursor.pos = inset_pos + 1;
            the_locking_inset->ToggleInsetCursor(bv);
             return result;
         } else if (result == FINISHED) {
            if ((action == LFUN_RIGHT) || (action == -1)) {
                cursor.pos = inset_pos + 1;
-               resetPos(bv);
+               resetPos(bv->painter());
            }
            the_locking_inset=0;
            result = DISPATCHED;
            }
            the_locking_inset=0;
            result = DISPATCHED;
@@ -358,7 +452,7 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
          break;
       // --- Cursor Movements ---------------------------------------------
       case LFUN_RIGHTSEL:
          break;
       // --- Cursor Movements ---------------------------------------------
       case LFUN_RIGHTSEL:
-          moveRight(bv);
+          moveRight(bv, false);
          sel_pos_end = cursor.pos;
          UpdateLocal(bv, false);
          break;
          sel_pos_end = cursor.pos;
          UpdateLocal(bv, false);
          break;
@@ -371,12 +465,12 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
              sel_pos_start = sel_pos_end = cursor.pos;
           break;
       case LFUN_LEFTSEL:
              sel_pos_start = sel_pos_end = cursor.pos;
           break;
       case LFUN_LEFTSEL:
-          moveLeft();
+          moveLeft(bv, false);
          sel_pos_end = cursor.pos;
          UpdateLocal(bv, false);
          break;
       case LFUN_LEFT:
          sel_pos_end = cursor.pos;
          UpdateLocal(bv, false);
          break;
       case LFUN_LEFT:
-          result= moveLeft();
+          result = moveLeft(bv);
          if (hasCharSelection()) {
              sel_pos_start = sel_pos_end = cursor.pos;
              UpdateLocal(bv, false);
          if (hasCharSelection()) {
              sel_pos_start = sel_pos_end = cursor.pos;
              UpdateLocal(bv, false);
@@ -476,63 +570,28 @@ void InsetTabular::Validate(LaTeXFeatures & features) const
 void InsetTabular::calculate_width_of_cells(Painter & pain,
                                            LyXFont const & font) const
 {
 void InsetTabular::calculate_width_of_cells(Painter & pain,
                                            LyXFont const & font) const
 {
-       int cell = -1;
-        int maxAsc, maxDesc;
-       InsetText * inset;
+    int cell = -1;
+    int maxAsc, maxDesc;
+    InsetText * inset;
     
     
-       for(int i = 0; i < tabular->rows(); ++i) {
-               maxAsc = maxDesc = 0;
-               for(int j= 0; j < tabular->columns(); ++j) {
-                       if (tabular->IsPartOfMultiColumn(i,j))
-                               continue;
-                       ++cell;
-                       inset = tabular->GetCellInset(cell);
-                       maxAsc = max(maxAsc, inset->ascent(pain, font));
-                       maxDesc = max(maxDesc, inset->descent(pain, font));
-                       tabular->SetWidthOfCell(cell,
-                                               inset->width(pain, font));
-               }
-               tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT);
-               tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT);
+    for(int i = 0; i < tabular->rows(); ++i) {
+       maxAsc = maxDesc = 0;
+       for(int j= 0; j < tabular->columns(); ++j) {
+           if (tabular->IsPartOfMultiColumn(i,j))
+               continue;
+           ++cell;
+           inset = tabular->GetCellInset(cell);
+           maxAsc = max(maxAsc, inset->ascent(pain, font));
+           maxDesc = max(maxDesc, inset->descent(pain, font));
+           tabular->SetWidthOfCell(cell, inset->width(pain, font));
        }
        }
+       tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT);
+       tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT);
+    }
 }
 
 
 }
 
 
-void InsetTabular::DrawCellLines(Painter & pain, int x, int baseline,
-                                 int row, int cell) const
-{
-    // Juergen, have you thought about drawing the on-off lines in a
-    // different color (gray of some kind), especially since those
-    // lines will not be there on the hardcopy anyway. (Lgb)
-    int  x2 = x + tabular->WidthOfColumn(cell);
-    bool on_off = !tabular->TopLine(cell);
-
-    if (!tabular->TopAlreadyDrawed(cell))
-       pain.line(x, baseline - tabular->AscentOfRow(row),
-                 x2, baseline -  tabular->AscentOfRow(row),
-                 on_off ? LColor::tabularonoffline:LColor::tabularline,
-                 on_off ? Painter::line_onoffdash:Painter::line_solid);
-    on_off = !tabular->BottomLine(cell);
-    pain.line(x,baseline +  tabular->DescentOfRow(row),
-             x2, baseline +  tabular->DescentOfRow(row),
-             on_off ? LColor::tabularonoffline:LColor::tabularline,
-             on_off ? Painter::line_onoffdash:Painter::line_solid);
-    on_off = !tabular->LeftLine(cell);
-    pain.line(x, baseline -  tabular->AscentOfRow(row),
-              x, baseline +  tabular->DescentOfRow(row),
-             on_off ? LColor::tabularonoffline:LColor::tabularline,
-              on_off ? Painter::line_onoffdash:Painter::line_solid);
-    on_off = !tabular->RightLine(cell);
-    pain.line(x2 - tabular->AdditionalWidth(cell),
-              baseline -  tabular->AscentOfRow(row),
-              x2 - tabular->AdditionalWidth(cell),
-              baseline +  tabular->DescentOfRow(row),
-             on_off ? LColor::tabularonoffline:LColor::tabularline,
-              on_off ? Painter::line_onoffdash:Painter::line_solid);
-}
-
-
-void InsetTabular::GetCursorPos(int & x, int & y)
+void InsetTabular::GetCursorPos(int & x, int & y) const
 {
     x = cursor.x-top_x;
     y = cursor.y;
 {
     x = cursor.x-top_x;
     y = cursor.y;
@@ -580,80 +639,120 @@ void InsetTabular::HideInsetCursor(BufferView * bv)
 }
 
 
 }
 
 
-void InsetTabular::setPos(Painter &, int x, int y) const
+void InsetTabular::setPos(Painter & pain, int x, int y) const
 {
     cursor.y = cursor.pos = actcell = actrow = actcol = 0;
 {
     cursor.y = cursor.pos = actcell = actrow = actcol = 0;
-    int ly = tabular->DescentOfRow(actrow);
+    int ly = tabular->GetDescentOfRow(actrow);
 
     // first search the right row
     while((ly < y) && (actrow < tabular->rows())) {
 
     // first search the right row
     while((ly < y) && (actrow < tabular->rows())) {
-        cursor.y += tabular->DescentOfRow(actrow) +
-               tabular->AscentOfRow(actrow+1) +
-            tabular->AdditionalHeight(tabular->GetCellNumber(actcol,actrow+1));
+        cursor.y += tabular->GetDescentOfRow(actrow) +
+               tabular->GetAscentOfRow(actrow+1) +
+            tabular->GetAdditionalHeight(tabular->GetCellNumber(actcol,actrow+1));
         ++actrow;
         ++actrow;
-        ly = cursor.y + tabular->DescentOfRow(actrow);
+        ly = cursor.y + tabular->GetDescentOfRow(actrow);
     }
     actcell = tabular->GetCellNumber(actcol, actrow);
 
     // now search the right column
     }
     actcell = tabular->GetCellNumber(actcol, actrow);
 
     // now search the right column
-    int lx = tabular->GetWidthOfCell(actcell);
-    for(;
-       !tabular->IsLastCellInRow(actcell) && (lx < x);
-       ++actcell,lx += tabular->GetWidthOfCell(actcell)) {}
-    cursor.x = lx - tabular->GetWidthOfCell(actcell) + top_x + 2;
+    int lx = tabular->GetWidthOfColumn(actcell) -
+       tabular->GetAdditionalWidth(actcell);
+    for(; !tabular->IsLastCellInRow(actcell) && (lx < x);
+       ++actcell,lx += tabular->GetWidthOfColumn(actcell) +
+           tabular->GetAdditionalWidth(actcell-1));
+    cursor.pos = ((actcell+1) * 2) - 1;
+    resetPos(pain);
+    if ((lx - (tabular->GetWidthOfColumn(actcell)/2)) < x) {
+       cursor.x = lx + top_x - 2;
+    } else {
+       --cursor.pos;
+       cursor.x = lx - tabular->GetWidthOfColumn(actcell) + top_x + 2;
+    }
+    resetPos(pain);
 }
 
 
 }
 
 
-void InsetTabular::resetPos(BufferView * bv)
+void InsetTabular::resetPos(Painter & pain) const
 {
     actrow = cursor.y = actcol = 0;
 
     int cell = 0;
     for(; (cell<actcell) && !tabular->IsLastRow(cell); ++cell) {
        if (tabular->IsLastCellInRow(cell)) {
 {
     actrow = cursor.y = actcol = 0;
 
     int cell = 0;
     for(; (cell<actcell) && !tabular->IsLastRow(cell); ++cell) {
        if (tabular->IsLastCellInRow(cell)) {
-           cursor.y += tabular->DescentOfRow(actrow) +
-               tabular->AscentOfRow(actrow+1) +
-               tabular->AdditionalHeight(cell+1);
+           cursor.y += tabular->GetDescentOfRow(actrow) +
+               tabular->GetAscentOfRow(actrow+1) +
+               tabular->GetAdditionalHeight(cell+1);
            ++actrow;
        }
     }
     for(cell=actcell;!tabular->IsFirstCellInRow(cell);--cell)
        ;
            ++actrow;
        }
     }
     for(cell=actcell;!tabular->IsFirstCellInRow(cell);--cell)
        ;
-    int lx = tabular->GetWidthOfCell(actcell);
+    int lx = tabular->GetWidthOfColumn(actcell);
     for(; (cell < actcell); ++cell) {
     for(; (cell < actcell); ++cell) {
-       lx += tabular->GetWidthOfCell(actcell);
+       lx += tabular->GetWidthOfColumn(cell);
        ++actcol;
     }
        ++actcol;
     }
-    cursor.x = lx - tabular->GetWidthOfCell(actcell) + top_x + 2;
+    cursor.x = lx - tabular->GetWidthOfColumn(actcell) + top_x + 2;
     if (cursor.pos % 2) {
        LyXFont font(LyXFont::ALL_SANE);
     if (cursor.pos % 2) {
        LyXFont font(LyXFont::ALL_SANE);
-       cursor.x += tabular->GetCellInset(actcell)->width(bv->painter(),font);
+       cursor.x += tabular->GetCellInset(actcell)->width(pain,font) +
+               tabular->GetBeginningOfTextInCell(actcell);
     }
 }
 
 
     }
 }
 
 
-void InsetTabular::setWidthOfCell(int, int, int)
+bool InsetTabular::SetCellDimensions(Painter & pain, int cell, int row)
 {
 {
+    InsetText * inset = tabular->GetCellInset(cell);
+    LyXFont font(LyXFont::ALL_SANE);
+    int asc = inset->ascent(pain, font) + ADD_TO_HEIGHT;
+    int desc = inset->descent(pain, font) + ADD_TO_HEIGHT;
+    int maxAsc = tabular->GetAscentOfRow(row);
+    int maxDesc = tabular->GetDescentOfRow(row);
+    bool ret = tabular->SetWidthOfCell(cell, inset->width(pain, font));
+
+    if (maxAsc < asc) {
+       ret = true;
+       tabular->SetAscentOfRow(row, asc);
+    }
+    if (maxDesc < desc) {
+       ret = true;
+       tabular->SetDescentOfRow(row, desc);
+    }
+    return ret;
 }
 
 
 }
 
 
-UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv)
+UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
 {
     if (cursor.pos % 2) { // behind the inset
        ++actcell;
        if (actcell >= tabular->GetNumberOfCells())
            return FINISHED;
        ++cursor.pos;
 {
     if (cursor.pos % 2) { // behind the inset
        ++actcell;
        if (actcell >= tabular->GetNumberOfCells())
            return FINISHED;
        ++cursor.pos;
+    } else if (lock) {
+       if (ActivateCellInset(bv))
+           return DISPATCHED;
     } else {              // before the inset
        ++cursor.pos;
     }
     } else {              // before the inset
        ++cursor.pos;
     }
-    resetPos(bv);
+    resetPos(bv->painter());
     return DISPATCHED_NOUPDATE;
 }
 
 
     return DISPATCHED_NOUPDATE;
 }
 
 
-UpdatableInset::RESULT InsetTabular::moveLeft()
+UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
 {
 {
+    if (!cursor.pos)
+       return FINISHED;
+    --cursor.pos;
+    if (cursor.pos % 2) { // behind the inset
+       --actcell;
+    } else if (lock) {       // behind the inset
+       if (ActivateCellInset(bv, -1, -1))
+           return DISPATCHED;
+    }
+    resetPos(bv->painter());
     return DISPATCHED_NOUPDATE;
 }
 
     return DISPATCHED_NOUPDATE;
 }
 
@@ -688,7 +787,7 @@ bool InsetTabular::Delete()
 }
 
 
 }
 
 
-void  InsetTabular::SetFont(LyXFont const &)
+void InsetTabular::SetFont(BufferView *, LyXFont const &, bool)
 {
 }
 
 {
 }
 
@@ -1036,3 +1135,44 @@ void InsetTabular::TabularFeatures(int, string)
 void InsetTabular::RemoveTabularRow()
 {
 }
 void InsetTabular::RemoveTabularRow()
 {
 }
+
+bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button)
+{
+    // the cursor.pos has to be before the inset so if it isn't now just
+    // reset the curor pos first!
+    if (cursor.pos % 2) { // behind the inset
+       --cursor.pos;
+       resetPos(bv->painter());
+    }
+    UpdatableInset * inset =
+       static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
+    LyXFont font(LyXFont::ALL_SANE);
+    if (x < 0)
+       x = inset->width(bv->painter(), font) + top_x;
+    if (y < 0)
+       y = inset->descent(bv->painter(), font);
+    inset_x = cursor.x - top_x + tabular->GetBeginningOfTextInCell(actcell);
+    inset_y = cursor.y;
+    inset->Edit(bv, x-inset_x, y-inset_y, button);
+    if (!the_locking_inset)
+       return false;
+    UpdateLocal(bv, true);
+    return true;
+}
+
+bool InsetTabular::InsetHit(BufferView * bv, int x, int ) const
+{
+    InsetText * inset = tabular->GetCellInset(actcell);
+    int x1 = x + top_x;
+
+    if (cursor.pos % 2) { // behind the inset
+       return (((x+top_x) < cursor.x) &&
+               ((x+top_x) > (cursor.x - inset->width(bv->painter(),
+                                                     LyXFont(LyXFont::ALL_SANE)))));
+    } else {
+       int x2 = cursor.x + tabular->GetBeginningOfTextInCell(actcell);
+       return ((x1 > x2) &&
+               (x1 < (x2 + inset->width(bv->painter(),
+                                        LyXFont(LyXFont::ALL_SANE)))));
+    }
+}
index f47b2fee595519be0cf35e4bcc5cb48fa7a32bd1..9070104ea8efa9cbf3720adf9fe1183e5466daf8 100644 (file)
@@ -88,14 +88,16 @@ public:
     ///
     void InsetUnlock(BufferView *);
     ///
     ///
     void InsetUnlock(BufferView *);
     ///
-    bool LockInsetInInset(UpdatableInset *);
+    void UpdateLocal(BufferView *, bool flag = true);
     ///
     ///
-    bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr=false);
+    bool LockInsetInInset(BufferView *, UpdatableInset *);
     ///
     ///
-    void UpdateLocal(BufferView *, bool flag = true);
+    bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr=false);
     ///
     bool UpdateInsetInInset(BufferView *, Inset *);
     ///
     ///
     bool UpdateInsetInInset(BufferView *, Inset *);
     ///
+    int InsetInInsetY();
+    ///
     bool display() const { return tabular->IsLongTabular(); }
     ///
     void InsetButtonRelease(BufferView *, int, int, int);
     bool display() const { return tabular->IsLongTabular(); }
     ///
     void InsetButtonRelease(BufferView *, int, int, int);
@@ -120,7 +122,7 @@ public:
     ///
     Inset::Code LyxCode() const { return Inset::TABULAR_CODE; }
     ///
     ///
     Inset::Code LyxCode() const { return Inset::TABULAR_CODE; }
     ///
-    void GetCursorPos(int & x, int & y);
+    void GetCursorPos(int & x, int & y) const;
     ///
     void ToggleInsetCursor(BufferView *);
     ///
     ///
     void ToggleInsetCursor(BufferView *);
     ///
@@ -128,7 +130,7 @@ public:
     ///
     int GetActCell() { return actcell; }
     ///
     ///
     int GetActCell() { return actcell; }
     ///
-    void SetFont(LyXFont const &);
+    void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
     ///
     /// Public structures and variables
     ///
     ///
     /// Public structures and variables
     ///
@@ -145,27 +147,32 @@ private:
     ///
     void setPos(Painter &, int x, int y) const;
     ///
     ///
     void setPos(Painter &, int x, int y) const;
     ///
-    void setWidthOfCell(int pos, int cell, int row);
+    bool SetCellDimensions(Painter & pain, int cell, int row);
     ///
     ///
-    UpdatableInset::RESULT moveRight(BufferView *);
-    UpdatableInset::RESULT moveLeft();
+    UpdatableInset::RESULT moveRight(BufferView *, bool lock=true);
+    UpdatableInset::RESULT moveLeft(BufferView *, bool lock=true);
     UpdatableInset::RESULT moveUp();
     UpdatableInset::RESULT moveDown();
     bool moveNextCell();
     bool movePrevCell();
     bool Delete();
     ///
     UpdatableInset::RESULT moveUp();
     UpdatableInset::RESULT moveDown();
     bool moveNextCell();
     bool movePrevCell();
     bool Delete();
     ///
-    void resetPos(BufferView *);
+    void resetPos(Painter &) const;
     ///
     void RemoveTabularRow();
     ///
     bool hasCharSelection() const {return (sel_pos_start != sel_pos_end);}
     bool hasCellSelection() const {return hasCharSelection() &&
                                 (sel_cell_start != sel_cell_end);}
     ///
     void RemoveTabularRow();
     ///
     bool hasCharSelection() const {return (sel_pos_start != sel_pos_end);}
     bool hasCellSelection() const {return hasCharSelection() &&
                                 (sel_cell_start != sel_cell_end);}
+    ///
+    bool ActivateCellInset(BufferView *, int x=0, int y=0, int button=0);
+    ///
+    bool InsetHit(BufferView * bv, int x, int y) const;
+
     ///
     /// Private structures and variables
     ///
     ///
     /// Private structures and variables
     ///
-    UpdatableInset
+    InsetText
         * the_locking_inset;
     Buffer
         * buffer;
         * the_locking_inset;
     Buffer
         * buffer;
index 05fe43508bd839438e2503e48d9aea2328391967..b648a2407c4637408c1e859d2a9111ac1c31085a 100644 (file)
@@ -53,6 +53,8 @@
 #include "lyxcursor.h"
 #include "CutAndPaste.h"
 #include "font.h"
 #include "lyxcursor.h"
 #include "CutAndPaste.h"
 #include "font.h"
+#include "minibuffer.h"
+#include "toolbar.h"
 
 using std::ostream;
 using std::ifstream;
 
 using std::ostream;
 using std::ifstream;
@@ -61,6 +63,7 @@ using std::min;
 using std::max;
 
 extern unsigned char getCurrentTextClass(Buffer *);
 using std::max;
 
 extern unsigned char getCurrentTextClass(Buffer *);
+extern LyXTextClass::size_type current_layout;
 
 
 InsetText::InsetText(Buffer * buf)
 
 
 InsetText::InsetText(Buffer * buf)
@@ -84,7 +87,6 @@ void InsetText::init(Buffer * buf, InsetText const * ins)
     buffer = buf;
     cursor_visible = false;
     cursor.x_fix = -1;
     buffer = buf;
     cursor_visible = false;
     cursor.x_fix = -1;
-    selection_start = selection_end = 0;
     interline_space = 1;
     no_selection = false;
     init_inset = true;
     interline_space = 1;
     no_selection = false;
     init_inset = true;
@@ -93,14 +95,13 @@ void InsetText::init(Buffer * buf, InsetText const * ins)
     autoBreakRows = false;
     xpos = 0.0;
     if (ins) {
     autoBreakRows = false;
     xpos = 0.0;
     if (ins) {
-       if (par)
-           delete par;
-       par = ins->par->Clone();
+       SetParagraphData(ins->par);
        autoBreakRows = ins->autoBreakRows;
     }
     par->SetInsetOwner(this);
     cursor.par = par;
     cursor.pos = 0;
        autoBreakRows = ins->autoBreakRows;
     }
     par->SetInsetOwner(this);
     cursor.par = par;
     cursor.pos = 0;
+    selection_start_cursor = selection_end_cursor = cursor;
 }
 
 
 }
 
 
@@ -241,12 +242,12 @@ void InsetText::drawRowSelection(Painter & pain, int startpos, int endpos,
        return;
 
     int s_start, s_end;
        return;
 
     int s_start, s_end;
-    if (selection_start > selection_end) {
-       s_start = selection_end;
-       s_end = selection_start;
+    if (selection_start_cursor.pos > selection_end_cursor.pos) {
+       s_start = selection_end_cursor.pos;
+       s_end = selection_start_cursor.pos;
     } else {
     } else {
-       s_start = selection_start;
-       s_end = selection_end;
+       s_start = selection_start_cursor.pos;
+       s_end = selection_end_cursor.pos;
     }
     if ((s_start > endpos) || (s_end < startpos))
        return;
     }
     if ((s_start > endpos) || (s_end < startpos))
        return;
@@ -351,11 +352,10 @@ void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button)
        return;
     }
     the_locking_inset = 0;
        return;
     }
     the_locking_inset = 0;
-    selection_start = selection_end = inset_pos = inset_x = inset_y = 0;
-//    no_selection = true;
+    inset_pos = inset_x = inset_y = 0;
     setPos(bv->painter(), x, y);
     checkAndActivateInset(bv, x, y, button);
     setPos(bv->painter(), x, y);
     checkAndActivateInset(bv, x, y, button);
-    selection_start = selection_end = cursor.pos;
+    selection_start_cursor = selection_end_cursor = cursor;
     current_font = real_current_font = GetFont(par, cursor.pos);
     bv->text->FinishUndo();
     UpdateLocal(bv, true);
     current_font = real_current_font = GetFont(par, cursor.pos);
     bv->text->FinishUndo();
     UpdateLocal(bv, true);
@@ -368,10 +368,11 @@ void InsetText::InsetUnlock(BufferView * bv)
        the_locking_inset->InsetUnlock(bv);
        the_locking_inset = 0;
     }
        the_locking_inset->InsetUnlock(bv);
        the_locking_inset = 0;
     }
+    HideInsetCursor(bv);
     lyxerr[Debug::INSETS] << "InsetText::InsetUnlock(" << this <<
            ")" << endl;
     if (hasSelection()) {
     lyxerr[Debug::INSETS] << "InsetText::InsetUnlock(" << this <<
            ")" << endl;
     if (hasSelection()) {
-       selection_start = selection_end = cursor.pos;
+       selection_start_cursor = selection_end_cursor = cursor;
        UpdateLocal(bv, false);
     }
     no_selection = false;
        UpdateLocal(bv, false);
     }
     no_selection = false;
@@ -445,7 +446,7 @@ bool InsetText::UpdateInsetInInset(BufferView * bv, Inset * inset)
 void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
 {
     if (hasSelection()) {
 void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
 {
     if (hasSelection()) {
-       selection_start = selection_end = cursor.pos;
+       selection_start_cursor = selection_end_cursor = cursor;
        UpdateLocal(bv, false);
     }
     no_selection = false;
        UpdateLocal(bv, false);
     }
     no_selection = false;
@@ -486,7 +487,7 @@ void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
            UpdateLocal(bv, true);
        }
     }
            UpdateLocal(bv, true);
        }
     }
-    selection_start = selection_end = cursor.pos;
+    selection_start_cursor = selection_end_cursor = cursor;
 }
 
 
 }
 
 
@@ -521,11 +522,11 @@ void InsetText::InsetMotionNotify(BufferView * bv, int x, int y, int state)
         return;
     }
     if (!no_selection) {
         return;
     }
     if (!no_selection) {
-       int old = selection_end;
+       LyXCursor old = selection_end_cursor;
        HideInsetCursor(bv);
        setPos(bv->painter(), x, y);
        HideInsetCursor(bv);
        setPos(bv->painter(), x, y);
-       selection_end = cursor.pos;
-       if (old != selection_end)
+       selection_end_cursor = cursor;
+       if (old != selection_end_cursor)
            UpdateLocal(bv, false);
        ShowInsetCursor(bv);
     }
            UpdateLocal(bv, false);
        ShowInsetCursor(bv);
     }
@@ -593,82 +594,82 @@ InsetText::LocalDispatch(BufferView * bv,
            bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->previous,
            bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->next);
        cutSelection();
            bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->previous,
            bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->next);
        cutSelection();
-       cursor.pos = selection_start;
+       cursor = selection_start_cursor;
        par->InsertChar(cursor.pos,arg[0]);
        SetCharFont(cursor.pos,current_font);
        ++cursor.pos;
        par->InsertChar(cursor.pos,arg[0]);
        SetCharFont(cursor.pos,current_font);
        ++cursor.pos;
-       selection_start = selection_end = cursor.pos;
+       selection_start_cursor = selection_end_cursor = cursor;
        UpdateLocal(bv, true);
        break;
         // --- Cursor Movements ---------------------------------------------
     case LFUN_RIGHTSEL:
        bv->text->FinishUndo();
        moveRight(bv, false);
        UpdateLocal(bv, true);
        break;
         // --- Cursor Movements ---------------------------------------------
     case LFUN_RIGHTSEL:
        bv->text->FinishUndo();
        moveRight(bv, false);
-       selection_end = cursor.pos;
+       selection_end_cursor = cursor;
        UpdateLocal(bv, false);
        break;
     case LFUN_RIGHT:
        bv->text->FinishUndo();
        result = moveRight(bv);
        if (hasSelection()) {
        UpdateLocal(bv, false);
        break;
     case LFUN_RIGHT:
        bv->text->FinishUndo();
        result = moveRight(bv);
        if (hasSelection()) {
-           selection_start = selection_end = cursor.pos;
+           selection_start_cursor = selection_end_cursor = cursor;
            UpdateLocal(bv, false);
        } else {
            UpdateLocal(bv, false);
        } else {
-           selection_start = selection_end = cursor.pos;
+           selection_start_cursor = selection_end_cursor = cursor;
        }
        break;
     case LFUN_LEFTSEL:
        bv->text->FinishUndo();
        moveLeft(bv, false);
        }
        break;
     case LFUN_LEFTSEL:
        bv->text->FinishUndo();
        moveLeft(bv, false);
-       selection_end = cursor.pos;
+       selection_end_cursor = cursor;
        UpdateLocal(bv, false);
        break;
     case LFUN_LEFT:
        bv->text->FinishUndo();
        result= moveLeft(bv);
        if (hasSelection()) {
        UpdateLocal(bv, false);
        break;
     case LFUN_LEFT:
        bv->text->FinishUndo();
        result= moveLeft(bv);
        if (hasSelection()) {
-               selection_start = selection_end = cursor.pos;
+               selection_start_cursor = selection_end_cursor = cursor;
                UpdateLocal(bv, false);
        } else {
                UpdateLocal(bv, false);
        } else {
-               selection_start = selection_end = cursor.pos;
+               selection_start_cursor = selection_end_cursor = cursor;
        }
        break;
     case LFUN_DOWNSEL:
        bv->text->FinishUndo();
        moveDown(bv);
        }
        break;
     case LFUN_DOWNSEL:
        bv->text->FinishUndo();
        moveDown(bv);
-       selection_end = cursor.pos;
+       selection_end_cursor = cursor;
        UpdateLocal(bv, false);
        break;
     case LFUN_DOWN:
        bv->text->FinishUndo();
        result = moveDown(bv);
        if (hasSelection()) {
        UpdateLocal(bv, false);
        break;
     case LFUN_DOWN:
        bv->text->FinishUndo();
        result = moveDown(bv);
        if (hasSelection()) {
-           selection_start = selection_end = cursor.pos;
+           selection_start_cursor = selection_end_cursor = cursor;
            UpdateLocal(bv, false);
        } else {
            UpdateLocal(bv, false);
        } else {
-           selection_start = selection_end = cursor.pos;
+           selection_start_cursor = selection_end_cursor = cursor;
        }
        break;
     case LFUN_UPSEL:
        bv->text->FinishUndo();
        moveUp(bv);
        }
        break;
     case LFUN_UPSEL:
        bv->text->FinishUndo();
        moveUp(bv);
-       selection_end = cursor.pos;
+       selection_end_cursor = cursor;
        UpdateLocal(bv, false);
        break;
     case LFUN_UP:
        bv->text->FinishUndo();
        result = moveUp(bv);
        if (hasSelection()) {
        UpdateLocal(bv, false);
        break;
     case LFUN_UP:
        bv->text->FinishUndo();
        result = moveUp(bv);
        if (hasSelection()) {
-           selection_start = selection_end = cursor.pos;
+           selection_start_cursor = selection_end_cursor = cursor;
            UpdateLocal(bv, false);
        } else {
            UpdateLocal(bv, false);
        } else {
-           selection_start = selection_end = cursor.pos;
+           selection_start_cursor = selection_end_cursor = cursor;
        }
        break;
     case LFUN_BACKSPACE:
        }
        break;
     case LFUN_BACKSPACE:
-       if (!cursor.pos) { // || par->IsNewline(cursor.pos-1)) {
+       if (!cursor.pos) {
            if (hasSelection()) {
            if (hasSelection()) {
-               selection_start = selection_end = cursor.pos;
+               selection_start_cursor = selection_end_cursor = cursor;
                UpdateLocal(bv, false);
            }
            break;
                UpdateLocal(bv, false);
            }
            break;
@@ -681,17 +682,17 @@ InsetText::LocalDispatch(BufferView * bv,
            bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->next);
        bool ret = true;
        if (hasSelection()) {
            bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->next);
        bool ret = true;
        if (hasSelection()) {
-           LyXParagraph::size_type i = selection_start;
-           for (; i < selection_end; ++i) {
-               par->Erase(selection_start);
+           LyXParagraph::size_type i = selection_start_cursor.pos;
+           for (; i < selection_end_cursor.pos; ++i) {
+               par->Erase(selection_start_cursor.pos);
            }
        } else
            ret = Delete();
        if (ret) { // we need update
            }
        } else
            ret = Delete();
        if (ret) { // we need update
-           selection_start = selection_end = cursor.pos;
+           selection_start_cursor = selection_end_cursor = cursor;
            UpdateLocal(bv, true);
        } else if (hasSelection()) {
            UpdateLocal(bv, true);
        } else if (hasSelection()) {
-           selection_start = selection_end = cursor.pos;
+           selection_start_cursor = selection_end_cursor = cursor;
            UpdateLocal(bv, false);
        }
     }
            UpdateLocal(bv, false);
        }
     }
@@ -704,10 +705,10 @@ InsetText::LocalDispatch(BufferView * bv,
 
        if (cutSelection()) {
            // we need update
 
        if (cutSelection()) {
            // we need update
-           cursor.pos = selection_end = selection_start;
+           cursor = selection_end_cursor = selection_start_cursor;
            UpdateLocal(bv, true);
        } else if (hasSelection()) {
            UpdateLocal(bv, true);
        } else if (hasSelection()) {
-           selection_start = selection_end = cursor.pos;
+           selection_start_cursor = selection_end_cursor = cursor;
            UpdateLocal(bv, false);
        }
        resetPos(bv->painter());
            UpdateLocal(bv, false);
        }
        resetPos(bv->painter());
@@ -716,10 +717,10 @@ InsetText::LocalDispatch(BufferView * bv,
        bv->text->FinishUndo();
        if (copySelection()) {
            // we need update
        bv->text->FinishUndo();
        if (copySelection()) {
            // we need update
-           selection_start = selection_end = cursor.pos;
+           selection_start_cursor = selection_end_cursor = cursor;
            UpdateLocal(bv, true);
        } else if (hasSelection()) {
            UpdateLocal(bv, true);
        } else if (hasSelection()) {
-           selection_start = selection_end = cursor.pos;
+           selection_start_cursor = selection_end_cursor = cursor;
            UpdateLocal(bv, false);
        }
        break;
            UpdateLocal(bv, false);
        }
        break;
@@ -729,7 +730,7 @@ InsetText::LocalDispatch(BufferView * bv,
          bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->previous,
          bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->next);
        if (pasteSelection()) {
          bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->previous,
          bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->next);
        if (pasteSelection()) {
-           selection_start = selection_end = cursor.pos;
+           selection_start_cursor = selection_end_cursor = cursor;
            UpdateLocal(bv, true);
        }
     }
            UpdateLocal(bv, true);
        }
     }
@@ -741,10 +742,10 @@ InsetText::LocalDispatch(BufferView * bv,
            cursor.x -= SingleWidth(bv->painter(), par, cursor.pos);
        cursor.x -= SingleWidth(bv->painter(), par, cursor.pos);
        if (hasSelection()) {
            cursor.x -= SingleWidth(bv->painter(), par, cursor.pos);
        cursor.x -= SingleWidth(bv->painter(), par, cursor.pos);
        if (hasSelection()) {
-           selection_start = selection_end = cursor.pos;
+           selection_start_cursor = selection_end_cursor = cursor;
            UpdateLocal(bv, false);
        } else {
            UpdateLocal(bv, false);
        } else {
-           selection_start = selection_end = cursor.pos;
+           selection_start_cursor = selection_end_cursor = cursor;
        }
        resetPos(bv->painter());
        break;
        }
        resetPos(bv->painter());
        break;
@@ -757,10 +758,10 @@ InsetText::LocalDispatch(BufferView * bv,
        for(; cursor.pos < checkpos; ++cursor.pos)
            cursor.x += SingleWidth(bv->painter(), par, cursor.pos);
        if (hasSelection()) {
        for(; cursor.pos < checkpos; ++cursor.pos)
            cursor.x += SingleWidth(bv->painter(), par, cursor.pos);
        if (hasSelection()) {
-           selection_start = selection_end = cursor.pos;
+           selection_start_cursor = selection_end_cursor = cursor;
            UpdateLocal(bv, false);
        } else {
            UpdateLocal(bv, false);
        } else {
-           selection_start = selection_end = cursor.pos;
+           selection_start_cursor = selection_end_cursor = cursor;
        }
     }
     resetPos(bv->painter());
        }
     }
     resetPos(bv->painter());
@@ -782,9 +783,42 @@ InsetText::LocalDispatch(BufferView * bv,
        SetCharFont(cursor.pos,current_font);
        UpdateLocal(bv, true);
        ++cursor.pos;
        SetCharFont(cursor.pos,current_font);
        UpdateLocal(bv, true);
        ++cursor.pos;
-       selection_start = selection_end = cursor.pos;
+       selection_start_cursor = selection_end_cursor = cursor;
        resetPos(bv->painter());
        break;
        resetPos(bv->painter());
        break;
+    case LFUN_LAYOUT:
+    {
+       // Derive layout number from given argument (string)
+       // and current buffer's textclass (number). */    
+       LyXTextClassList::ClassList::size_type tclass =
+           buffer->params.textclass;
+       pair <bool, LyXTextClass::size_type> layout = 
+           textclasslist.NumberOfLayout(tclass, arg);
+
+       // If the entry is obsolete, use the new one instead.
+       if (layout.first) {
+           string obs = textclasslist.Style(tclass,layout.second).
+               obsoleted_by();
+           if (!obs.empty()) 
+               layout = textclasslist.NumberOfLayout(tclass, obs);
+       }
+
+       // see if we found the layout number:
+       if (!layout.first) {
+           string msg = string(N_("Layout ")) + arg + N_(" not known");
+
+           bv->owner()->getMiniBuffer()->Set(msg);
+           break;
+       }
+
+       if (current_layout != layout.second) {
+           bv->text->SetLayout(cursor, selection_start_cursor,
+                               selection_end_cursor, layout.second);
+           bv->owner()->getToolbar()->combox->select(cursor.par->GetLayout()+1);
+           UpdateLocal(bv, true);
+       }
+    }
+    break;
     default:
        result = UNDISPATCHED;
        break;
     default:
        result = UNDISPATCHED;
        break;
@@ -799,9 +833,9 @@ InsetText::LocalDispatch(BufferView * bv,
 
 int InsetText::Latex(ostream & os, bool /*fragile*/, bool /*fp*/) const
 {
 
 int InsetText::Latex(ostream & os, bool /*fragile*/, bool /*fp*/) const
 {
-       TexRow texrow;
-       int ret = par->SimpleTeXOnePar(os, texrow);
-       return ret;
+    TexRow texrow;
+    buffer->latexParagraphs(os, par, 0, texrow);
+    return texrow.rows();
 }
 
 
 }
 
 
@@ -1048,6 +1082,8 @@ void InsetText::setPos(Painter & pain, int x, int y) const
 
 void InsetText::resetPos(Painter & pain) const
 {
 
 void InsetText::resetPos(Painter & pain) const
 {
+    cursor.par = par;
+
     if (!rows.size())
        return;
 
     if (!rows.size())
        return;
 
@@ -1149,9 +1185,9 @@ bool InsetText::InsertInset(BufferView * bv, Inset * inset)
     par->InsertChar(cursor.pos, LyXParagraph::META_INSET);
     par->InsertInset(cursor.pos, inset);
     if (hasSelection()) {
     par->InsertChar(cursor.pos, LyXParagraph::META_INSET);
     par->InsertInset(cursor.pos, inset);
     if (hasSelection()) {
-       selection_start = selection_end = cursor.pos;
+       selection_start_cursor = selection_end_cursor = cursor;
     } else {
     } else {
-       selection_start = selection_end = cursor.pos;
+       selection_start_cursor = selection_end_cursor = cursor;
     }
     UpdateLocal(bv, true);
     static_cast<UpdatableInset*>(inset)->Edit(bv, 0, 0, 0);
     }
     UpdateLocal(bv, true);
     static_cast<UpdatableInset*>(inset)->Edit(bv, 0, 0, 0);
@@ -1189,12 +1225,12 @@ void InsetText::SetFont(BufferView * bv, LyXFont const & font, bool toggleall)
     }
     
     int s_start, s_end;
     }
     
     int s_start, s_end;
-    if (selection_start > selection_end) {
-       s_start = selection_end;
-       s_end = selection_start;
+    if (selection_start_cursor.pos > selection_end_cursor.pos) {
+       s_start = selection_end_cursor.pos;
+       s_end = selection_start_cursor.pos;
     } else {
     } else {
-       s_start = selection_start;
-       s_end = selection_end;
+       s_start = selection_start_cursor.pos;
+       s_end = selection_end_cursor.pos;
     }
     LyXFont newfont;
     while(s_start < s_end) {
     }
     LyXFont newfont;
     while(s_start < s_end) {
@@ -1427,6 +1463,7 @@ void InsetText::UpdateLocal(BufferView * bv, bool flag)
     bv->updateInset(this, flag);
     if (flag)
        resetPos(bv->painter());
     bv->updateInset(this, flag);
     if (flag)
        resetPos(bv->painter());
+    bv->owner()->getToolbar()->combox->select(cursor.par->GetLayout()+1);
 }
 
 
 }
 
 
@@ -1439,12 +1476,12 @@ bool InsetText::cutSelection()
 
     LyXParagraph * endpar = par;
     int start, end;
 
     LyXParagraph * endpar = par;
     int start, end;
-    if (selection_start > selection_end) {
-           start = selection_end;
-           end = selection_start;
+    if (selection_start_cursor.pos > selection_end_cursor.pos) {
+           start = selection_end_cursor.pos;
+           end = selection_start_cursor.pos;
     } else {
     } else {
-           start = selection_start;
-           end = selection_end;
+           start = selection_start_cursor.pos;
+           end = selection_end_cursor.pos;
     }
 
     return cap.cutSelection(par, &endpar, start, end,buffer->params.textclass);
     }
 
     return cap.cutSelection(par, &endpar, start, end,buffer->params.textclass);
@@ -1459,12 +1496,12 @@ bool InsetText::copySelection()
     CutAndPaste cap;
 
     int start, end;
     CutAndPaste cap;
 
     int start, end;
-    if (selection_start > selection_end) {
-           start = selection_end;
-           end = selection_start;
+    if (selection_start_cursor.pos > selection_end_cursor.pos) {
+           start = selection_end_cursor.pos;
+           end = selection_start_cursor.pos;
     } else {
     } else {
-           start = selection_start;
-           end = selection_end;
+           start = selection_start_cursor.pos;
+           end = selection_end_cursor.pos;
     }
     return cap.copySelection(par, par, start, end, buffer->params.textclass);
 }
     }
     return cap.copySelection(par, par, start, end, buffer->params.textclass);
 }
@@ -1516,3 +1553,12 @@ int InsetText::getMaxTextWidth(Painter & pain, UpdatableInset const * inset,
 {
     return getMaxWidth(pain, inset) - x;
 }
 {
     return getMaxWidth(pain, inset) - x;
 }
+
+void InsetText::SetParagraphData(LyXParagraph *p)
+{
+    if (par)
+       delete par;
+    par = p->Clone();
+    par->SetInsetOwner(this);
+    init_inset = true;
+}
index bbc558cf5fe8ec7b987fb9f5a2571526e435c7e6..b49374fa93d1212034ae6ab7989763c880ca148a 100644 (file)
@@ -34,10 +34,10 @@ class Buffer;
 */
 class InsetText : public UpdatableInset {
 public:
 */
 class InsetText : public UpdatableInset {
 public:
-       ///
-       enum { TEXT_TO_INSET_OFFSET = 1 };
     ///
     ///
-       explicit
+    enum { TEXT_TO_INSET_OFFSET = 1 };
+    ///
+    explicit
     InsetText(Buffer *);
     ///
     InsetText(InsetText const &, Buffer *);
     InsetText(Buffer *);
     ///
     InsetText(InsetText const &, Buffer *);
@@ -107,6 +107,8 @@ public:
     void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
     ///
     void init(Buffer *, InsetText const * ins = 0);
     void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
     ///
     void init(Buffer *, InsetText const * ins = 0);
+    ///
+    void SetParagraphData(LyXParagraph *);
 
     LyXParagraph * par;
 
 
     LyXParagraph * par;
 
@@ -178,7 +180,8 @@ private:
     bool copySelection();
     bool pasteSelection();
     ///
     bool copySelection();
     bool pasteSelection();
     ///
-    bool hasSelection() const { return selection_start != selection_end; }
+    bool hasSelection() const
+               { return (selection_start_cursor != selection_end_cursor); }
     ///
     void SetCharFont(int pos, LyXFont const & font);
     ///
     ///
     void SetCharFont(int pos, LyXFont const & font);
     ///
@@ -197,9 +200,9 @@ private:
     ///
     int interline_space;
     ///
     ///
     int interline_space;
     ///
-    int selection_start;
+    LyXCursor selection_start_cursor;
     ///
     ///
-    int selection_end;
+    LyXCursor selection_end_cursor;
     ///
     mutable LyXCursor cursor;
     ///
     ///
     mutable LyXCursor cursor;
     ///
@@ -241,9 +244,7 @@ private:
        inset_x = it.inset_x;
        inset_y = it.inset_y;
        interline_space = it.interline_space;
        inset_x = it.inset_x;
        inset_y = it.inset_y;
        interline_space = it.interline_space;
-       selection_start = it.selection_start;
-       selection_end = it.selection_end;
-       cursor = it.cursor;
+       selection_start_cursor = selection_end_cursor = cursor = it.cursor;
        actrow = it.actrow;
        no_selection = it.no_selection;
        the_locking_inset = it.the_locking_inset; // suspect
        actrow = it.actrow;
        no_selection = it.no_selection;
        the_locking_inset = it.the_locking_inset; // suspect
index 5f0a7326cf0d73bcb5432f7d4e15712e504e449d..401884e6d71ab6e91603e3bdb7ca79aacfcc244b 100644 (file)
@@ -177,8 +177,6 @@ public:
                return 0;
        }
        ///
                return 0;
        }
        ///
-       virtual void init(BufferView *) {}
-       ///
        virtual bool InsertInsetAllowed(Inset *) const { return false; }
        ///
        virtual void setInsetName(const char * s) { name = s; }
        virtual bool InsertInsetAllowed(Inset *) const { return false; }
        ///
        virtual void setInsetName(const char * s) { name = s; }
index 9699f7561474d73198eb6b7127ff66e2c8619be3..256a130e7daa03fa4a43e29a8b460dccdbdbe18d 100644 (file)
@@ -31,6 +31,11 @@ struct LyXCursor {
        unsigned long y;
        ///
        Row * row;
        unsigned long y;
        ///
        Row * row;
+       ///
+       inline bool operator==(const LyXCursor &a) const
+               { return (a.par == par) && (a.pos == pos); }
+       inline bool operator!=(const LyXCursor &a) const
+               { return (a.par != par) || (a.pos != pos); }
 };
 
 #endif
 };
 
 #endif
index c500764c22c0ad158aaae2b23f4b9f08c2847875..96f16b0fc6ac80d8af390f3b30af708b18e10d76 100644 (file)
@@ -88,6 +88,10 @@ public:
        /** set layout over selection and make a total rebreak of
          those paragraphs
          */
        /** set layout over selection and make a total rebreak of
          those paragraphs
          */
+       LyXParagraph * SetLayout(LyXCursor & actual_cursor,
+                                LyXCursor & selection_start,
+                                LyXCursor & selection_end,
+                                LyXTextClass::size_type layout);
        void SetLayout(LyXTextClass::size_type layout);
        
        /// used in setlayout
        void SetLayout(LyXTextClass::size_type layout);
        
        /// used in setlayout
index c8d21d074f1ae2ff876475753e5a74370d051277..f7c4994512bc5ffa032f05e4f66047c632d3d114 100644 (file)
@@ -2126,7 +2126,8 @@ LyXParagraph * LyXParagraph::TeXOnePar(ostream & os, TexRow & texrow,
                        || par->pextra_type != pextra_type))
                        break;
        default:
                        || par->pextra_type != pextra_type))
                        break;
        default:
-               if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE
+               // we don't need it for the last paragraph!!!
+               if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE
                      && footnotekind != LyXParagraph::FOOTNOTE
                      && footnotekind != LyXParagraph::MARGIN
                      && (table
                      && footnotekind != LyXParagraph::FOOTNOTE
                      && footnotekind != LyXParagraph::MARGIN
                      && (table
@@ -2168,7 +2169,8 @@ LyXParagraph * LyXParagraph::TeXOnePar(ostream & os, TexRow & texrow,
                texrow.newline();
        }
        
                texrow.newline();
        }
        
-       if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
+       // we don't need it for the last paragraph!!!
+       if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
               par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) {
                os << '\n';
                texrow.newline();
               par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) {
                os << '\n';
                texrow.newline();
index 14482eab501af59ae925c999a17b3a7a6cfab77e..54812b0306859c1516938f6d15034c6e08adf637 100644 (file)
@@ -1403,8 +1403,7 @@ int LyXTable::TexEndOfCell(ostream & os, int cell)
             }
         }
         if (nvcell < numberofcells && Linebreaks(nvcell)) {
             }
         }
         if (nvcell < numberofcells && Linebreaks(nvcell)) {
-//            !column_info[column_of_cell(nvcell)].p_width.empty()) {
-               os << "\\parbox{"
+               os << "\\parbox[t]{"
                   << GetPWidth(nvcell)
                   << "}{\\smallskip{}";
        }
                   << GetPWidth(nvcell)
                   << "}{\\smallskip{}";
        }
index 7639f1c3a08506a5dfb538e979baaab3c76ed8da..fc6620344dc97fb22aa97ee5dbf6d5fa82d7ce09 100644 (file)
@@ -37,16 +37,15 @@ static int const WIDTH_OF_LINE = 5;
 
 LyXTabular::cellstruct::cellstruct(Buffer * buf) 
 {
 
 LyXTabular::cellstruct::cellstruct(Buffer * buf) 
 {
-       cellno = 0; //should be initilaized correctly later.
-       width_of_cell = 0;
-       multicolumn = LyXTabular::CELL_NORMAL;
-       alignment = LYX_ALIGN_CENTER;
-       top_line = true;
-       bottom_line = false;
-       rotate = false;
-       linebreaks = false;
-       buf ? inset = new InsetText(buf): inset = 0;
-       
+    cellno = 0; //should be initilaized correctly later.
+    width_of_cell = 0;
+    multicolumn = LyXTabular::CELL_NORMAL;
+    alignment = LYX_ALIGN_CENTER;
+    top_line = true;
+    bottom_line = false;
+    rotate = false;
+    linebreaks = false;
+    inset = new InsetText(buf);
 }
 
 LyXTabular::cellstruct::~cellstruct() 
 }
 
 LyXTabular::cellstruct::~cellstruct() 
@@ -58,24 +57,24 @@ LyXTabular::cellstruct::~cellstruct()
 LyXTabular::cellstruct & 
   LyXTabular::cellstruct::operator=(cellstruct const & cs)
 {
 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;
-       return *this;
+    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;
+    return *this;
 }
 
 LyXTabular::rowstruct::rowstruct() 
 {
 }
 
 LyXTabular::rowstruct::rowstruct() 
 {
-       top_line = true;
-       bottom_line = false;
-       ascent_of_row = 0;
-       descent_of_row = 0;
-       newpage = false;
+    top_line = true;
+    bottom_line = false;
+    ascent_of_row = 0;
+    descent_of_row = 0;
+    newpage = false;
 }
 
 // Nothing to do, but gcc 2.7.2.3 wants one... (JMarc)
 }
 
 // Nothing to do, but gcc 2.7.2.3 wants one... (JMarc)
@@ -86,20 +85,20 @@ LyXTabular::rowstruct::~rowstruct()
 LyXTabular::rowstruct & 
   LyXTabular::rowstruct::operator=(rowstruct const & rs)
 {
 LyXTabular::rowstruct & 
   LyXTabular::rowstruct::operator=(rowstruct const & rs)
 {
-       top_line = rs.top_line;
-       bottom_line = rs.bottom_line;
-       ascent_of_row = rs.ascent_of_row;
-       descent_of_row = rs.descent_of_row;
-       newpage = rs.newpage;
-       return *this;
+    top_line = rs.top_line;
+    bottom_line = rs.bottom_line;
+    ascent_of_row = rs.ascent_of_row;
+    descent_of_row = rs.descent_of_row;
+    newpage = rs.newpage;
+    return *this;
 }
 
 LyXTabular::columnstruct::columnstruct() 
 {
 }
 
 LyXTabular::columnstruct::columnstruct() 
 {
-        left_line = true;
-        right_line = false;
-        alignment = LYX_ALIGN_CENTER;
-        width_of_column = 0;
+    left_line = true;
+    right_line = false;
+    alignment = LYX_ALIGN_CENTER;
+    width_of_column = 0;
 }
 
 LyXTabular::columnstruct::~columnstruct() 
 }
 
 LyXTabular::columnstruct::~columnstruct() 
@@ -109,13 +108,13 @@ LyXTabular::columnstruct::~columnstruct()
 LyXTabular::columnstruct & 
   LyXTabular::columnstruct::operator=(columnstruct const & cs)
 {
 LyXTabular::columnstruct & 
   LyXTabular::columnstruct::operator=(columnstruct const & cs)
 {
-        left_line = cs.left_line;
-        right_line = cs.right_line;
-        alignment = cs.alignment;
-        width_of_column = cs.width_of_column;
-       p_width = cs.p_width;
-       align_special = cs.align_special;
-       return *this;
+    left_line = cs.left_line;
+    right_line = cs.right_line;
+    alignment = cs.alignment;
+    width_of_column = cs.width_of_column;
+    p_width = cs.p_width;
+    align_special = cs.align_special;
+    return *this;
 }
 
 /* konstruktor */
 }
 
 /* konstruktor */
@@ -136,9 +135,8 @@ LyXTabular::LyXTabular(LyXTabular const & lt, Buffer * buf)
 
 LyXTabular::LyXTabular(LyXLex & lex, Buffer *buf)
 {
 
 LyXTabular::LyXTabular(LyXLex & lex, Buffer *buf)
 {
-    istream & is = lex.getStream();
     buffer = buf;
     buffer = buf;
-    Read(is);
+    Read(lex);
 }
 
 
 }
 
 
@@ -185,9 +183,9 @@ LyXTabular & LyXTabular::operator=(LyXTabular const & lt)
     return *this;
 }
 
     return *this;
 }
 
-LyXTabular * LyXTabular::Clone()
+LyXTabular * LyXTabular::Clone(Buffer * buf)
 {
 {
-    LyXTabular * result = new LyXTabular(rows_, columns_);
+    LyXTabular * result = new LyXTabular(rows_, columns_, buf);
     int row, column;;
 
     for (row = 0; row < rows_; ++row) {
     int row, column;;
 
     for (row = 0; row < rows_; ++row) {
@@ -270,7 +268,7 @@ void LyXTabular::AppendRow(int cell)
         row_info2[i + 1] = row_info[i];
     }
     row_info2[row + 1].top_line = row_info[i].top_line;
         row_info2[i + 1] = row_info[i];
     }
     row_info2[row + 1].top_line = row_info[i].top_line;
-    cell_info2[row + 1] = new cellstruct[columns_];
+    cell_info2[row + 1] = new cellstruct[columns_](buffer);
     for (i = 0; i < columns_; ++i) {
         cell_info2[row + 1][i].width_of_cell = 0;
         cell_info2[row + 1][i] = cell_info2[row][i];
     for (i = 0; i < columns_; ++i) {
         cell_info2[row + 1][i].width_of_cell = 0;
         cell_info2[row + 1][i] = cell_info2[row][i];
@@ -289,29 +287,29 @@ void LyXTabular::AppendRow(int cell)
 
 void LyXTabular::DeleteRow(int cell)
 {
 
 void LyXTabular::DeleteRow(int cell)
 {
-       int row = row_of_cell(cell);
-        rowstruct * row_info2 = new rowstruct[rows_ - 1];
-       cellstruct ** cell_info2 = new cellstruct * [rows_ - 1];
-
-       delete[] cell_info[row];
-       int i = 0;
-       for (; i < row; ++i) {
-               cell_info2[i] = cell_info[i];
-                row_info2[i] = row_info[i];
-       }
-       for (i = row; i < rows_ - 1; ++i) {
-               cell_info2[i] = cell_info[i + 1];
-                row_info2[i] = row_info[i + 1];
-       }
+    int row = row_of_cell(cell);
+    rowstruct * row_info2 = new rowstruct[rows_ - 1];
+    cellstruct ** cell_info2 = new cellstruct * [rows_ - 1];
 
 
-       delete[] cell_info;
-       cell_info = cell_info2;
-        delete[] row_info;
-        row_info = row_info2;
+    delete[] cell_info[row];
+    int i = 0;
+    for (; i < row; ++i) {
+       cell_info2[i] = cell_info[i];
+       row_info2[i] = row_info[i];
+    }
+    for (i = row; i < rows_ - 1; ++i) {
+       cell_info2[i] = cell_info[i + 1];
+       row_info2[i] = row_info[i + 1];
+    }
+
+    delete[] cell_info;
+    cell_info = cell_info2;
+    delete[] row_info;
+    row_info = row_info2;
    
    
-       --rows_;
+    --rows_;
 
 
-       Reinit();
+    Reinit();
 }
 
 
 }
 
 
@@ -334,7 +332,7 @@ void LyXTabular::AppendColumn(int cell)
     
     for (i = 0; i < rows_; ++i) {
         cellstruct * tmp = cell_info[i];
     
     for (i = 0; i < rows_; ++i) {
         cellstruct * tmp = cell_info[i];
-        cell_info[i] = new cellstruct[columns_ + 1];
+        cell_info[i] = new cellstruct[columns_ + 1](buffer);
         for (j = 0; j <= column; ++j) {
             cell_info[i][j] = tmp[j];
         }
         for (j = 0; j <= column; ++j) {
             cell_info[i][j] = tmp[j];
         }
@@ -363,101 +361,101 @@ void LyXTabular::AppendColumn(int cell)
 
 void LyXTabular::Reinit()
 {   
 
 void LyXTabular::Reinit()
 {   
-       int j;
+    int j;
 
 
-       int i = 0;
-       for (; i < rows_; ++i) {
-               for (j = 0; j < columns_; ++j) {
-                       cell_info[i][j].width_of_cell = 0;
-               }
+    int i = 0;
+    for (; i < rows_; ++i) {
+       for (j = 0; j < columns_; ++j) {
+           cell_info[i][j].width_of_cell = 0;
        }
        }
+    }
   
   
-       for (i = 0; i < columns_; ++i) {
-               calculate_width_of_column(i);
-       }
-       calculate_width_of_tabular();
+    for (i = 0; i < columns_; ++i) {
+       calculate_width_of_column(i);
+    }
+    calculate_width_of_tabular();
 
 
-       set_row_column_number_info();
+    set_row_column_number_info();
 }
 
 
 void LyXTabular::set_row_column_number_info()
 {
 }
 
 
 void LyXTabular::set_row_column_number_info()
 {
-       int c = 0;
-       int column = 0;
-       numberofcells = -1;
-       int row = 0;
-       for (; row < rows_; ++row) {
-               for (column = 0; column<columns_; ++column) {
-                       if (cell_info[row][column].multicolumn
-                           != LyXTabular::CELL_PART_OF_MULTICOLUMN)
-                               ++numberofcells;
-                        cell_info[row][column].cellno = numberofcells;
-               }
+    int c = 0;
+    int column = 0;
+    numberofcells = -1;
+    int row = 0;
+    for (; row < rows_; ++row) {
+       for (column = 0; column<columns_; ++column) {
+           if (cell_info[row][column].multicolumn
+               != LyXTabular::CELL_PART_OF_MULTICOLUMN)
+               ++numberofcells;
+           cell_info[row][column].cellno = numberofcells;
        }
        }
-       ++numberofcells; // because this is one more than as we start from 0
-       row = 0;
-       column = 0;
-
-       delete [] rowofcell;
-       rowofcell = new int[numberofcells];
-       delete [] columnofcell;
-       columnofcell = new int[numberofcells];
+    }
+    ++numberofcells; // because this is one more than as we start from 0
+    row = 0;
+    column = 0;
+
+    delete [] rowofcell;
+    rowofcell = new int[numberofcells];
+    delete [] columnofcell;
+    columnofcell = new int[numberofcells];
   
   
-       while (c < numberofcells && row < rows_ && column < columns_) {
-               rowofcell[c] = row;
-               columnofcell[c] = column;
-               ++c;
-               do {
-                       ++column;
-               } while (column < columns_ &&
-                        cell_info[row][column].multicolumn
-                        == LyXTabular::CELL_PART_OF_MULTICOLUMN);
-               if (column == columns_) {
-                       column = 0;
-                       ++row;
-               }
+    while (c < numberofcells && row < rows_ && column < columns_) {
+       rowofcell[c] = row;
+       columnofcell[c] = column;
+       ++c;
+       do {
+           ++column;
+       } while (column < columns_ &&
+                cell_info[row][column].multicolumn
+                == LyXTabular::CELL_PART_OF_MULTICOLUMN);
+       if (column == columns_) {
+           column = 0;
+           ++row;
        }
        }
+    }
 }
 
 
 void LyXTabular::DeleteColumn(int cell)
 {
 }
 
 
 void LyXTabular::DeleteColumn(int cell)
 {
-       int column1 = column_of_cell(cell);
-       int column2 = right_column_of_cell(cell);
-   
-       if (column1 == 0 && column2 == columns_ - 1)
-               return;
-   
-       for (int column = column1; column <= column2; ++column) {
-               delete_column(column1);
-       }
-       Reinit();
+    int column1 = column_of_cell(cell);
+    int column2 = right_column_of_cell(cell);
+    
+    if (column1 == 0 && column2 == columns_ - 1)
+       return;
+    
+    for (int column = column1; column <= column2; ++column) {
+       delete_column(column1);
+    }
+    Reinit();
 }
 
 
 }
 
 
-int LyXTabular::GetNumberOfCells()
+int LyXTabular::GetNumberOfCells() const
 {
 {
-       return numberofcells;
+    return numberofcells;
 }
 
 
 }
 
 
-int LyXTabular::NumberOfCellsInRow(int cell)
+int LyXTabular::NumberOfCellsInRow(int cell) const
 {
 {
-       int row = row_of_cell(cell);
-       int result = 0;
-       for (int i = 0; i < columns_; ++i) {
-               if (cell_info[row][i].multicolumn != LyXTabular::CELL_PART_OF_MULTICOLUMN)
-                       ++result;
-       }
-       return result;
+    int row = row_of_cell(cell);
+    int result = 0;
+    for (int i = 0; i < columns_; ++i) {
+       if (cell_info[row][i].multicolumn != LyXTabular::CELL_PART_OF_MULTICOLUMN)
+           ++result;
+    }
+    return result;
 }
 
 
 int LyXTabular::AppendCellAfterCell(int append_cell, int question_cell)
 {
 }
 
 
 int LyXTabular::AppendCellAfterCell(int append_cell, int question_cell)
 {
-       return (right_column_of_cell(append_cell) == 
-               right_column_of_cell(question_cell));
+    return (right_column_of_cell(append_cell) ==
+           right_column_of_cell(question_cell));
 }
 
 
 }
 
 
@@ -474,7 +472,7 @@ int LyXTabular::DeleteCellIfColumnIsDeleted(int cell, int delete_column_cell)
 
 
 /* returns 1 if there is a topline, returns 0 if not */ 
 
 
 /* returns 1 if there is a topline, returns 0 if not */ 
-bool LyXTabular::TopLine(int cell)
+bool LyXTabular::TopLine(int cell) const
 {
     int row = row_of_cell(cell);
     
 {
     int row = row_of_cell(cell);
     
@@ -484,7 +482,7 @@ bool LyXTabular::TopLine(int cell)
 }
 
 
 }
 
 
-bool LyXTabular::BottomLine(int cell)
+bool LyXTabular::BottomLine(int cell) const
 {
     //no bottom line underneath non-existent cells if you please
     if(cell >= numberofcells)
 {
     //no bottom line underneath non-existent cells if you please
     if(cell >= numberofcells)
@@ -496,108 +494,124 @@ bool LyXTabular::BottomLine(int cell)
 }
 
 
 }
 
 
-bool LyXTabular::LeftLine(int cell)
+bool LyXTabular::LeftLine(int cell) const
 {
 {
-       return column_info[column_of_cell(cell)].left_line;
+    return column_info[column_of_cell(cell)].left_line;
 }
 
 
 }
 
 
-bool LyXTabular::RightLine(int cell)
+bool LyXTabular::RightLine(int cell) const
 {
 {
-       return column_info[right_column_of_cell(cell)].right_line;
+    return column_info[right_column_of_cell(cell)].right_line;
 }
 
 
 }
 
 
-bool LyXTabular::TopAlreadyDrawed(int cell)
+bool LyXTabular::TopAlreadyDrawed(int cell) const
 {
 {
-       if (AdditionalHeight(cell))
-               return false;
-       int row = row_of_cell(cell);
-       if (row > 0){
-               int column = column_of_cell(cell);
-               while (column
-                      && cell_info[row-1][column].multicolumn
-                      == LyXTabular::CELL_PART_OF_MULTICOLUMN)
-                       --column;
-               if (cell_info[row-1][column].multicolumn
-                   == LyXTabular::CELL_NORMAL)
-                       return row_info[row-1].bottom_line;
-               else
-                       return cell_info[row-1][column].bottom_line;
-       }
+    if (GetAdditionalHeight(cell))
        return false;
        return false;
+    int row = row_of_cell(cell);
+    if (row > 0) {
+       int column = column_of_cell(cell);
+       --row;
+       while (column
+              && cell_info[row][column].multicolumn
+              == LyXTabular::CELL_PART_OF_MULTICOLUMN)
+           --column;
+       if (cell_info[row][column].multicolumn == LyXTabular::CELL_NORMAL)
+           return row_info[row].bottom_line;
+       else
+           return cell_info[row][column].bottom_line;
+    }
+    return false;
 }
 
 
 }
 
 
-bool LyXTabular::VeryLastRow(int cell)
+bool LyXTabular::LeftAlreadyDrawed(int cell) const
 {
 {
-       return (row_of_cell(cell) == rows_ - 1);
+    int column = column_of_cell(cell);
+    if (column > 0) {
+       int row = row_of_cell(cell);
+       while (--column &&
+              (cell_info[row][column].multicolumn ==
+               LyXTabular::CELL_PART_OF_MULTICOLUMN));
+       if (GetAdditionalWidth(cell_info[row][column].cellno))
+           return false;
+       return column_info[column].right_line;
+    }
+    return false;
 }
 
 
 }
 
 
-int LyXTabular::AdditionalHeight(int cell)
+bool LyXTabular::IsLastRow(int cell) const
 {
 {
-       int row = row_of_cell(cell);
-       if (!row) return 0;
+    return (row_of_cell(cell) == rows_ - 1);
+}
+
+
+int LyXTabular::GetAdditionalHeight(int cell) const
+{
+    int row = row_of_cell(cell);
+    if (!row) return 0;
        
        
-       int top = 1; // bool top = true; ??
-       int bottom = 1; // bool bottom = true; ??
-       int column;
-
-       for (column = 0; column < columns_ - 1 && bottom; ++column) {
-               switch (cell_info[row - 1][column].multicolumn) {
-               case LyXTabular::CELL_BEGIN_OF_MULTICOLUMN:
-                       bottom = cell_info[row - 1][column].bottom_line;
-                       break;
-               case LyXTabular::CELL_NORMAL:
-                       bottom = row_info[row - 1].bottom_line;
-               }
+    int top = 1; // bool top = true; ??
+    int bottom = 1; // bool bottom = true; ??
+    int column;
+
+    for (column = 0; column < columns_ - 1 && bottom; ++column) {
+       switch (cell_info[row - 1][column].multicolumn) {
+       case LyXTabular::CELL_BEGIN_OF_MULTICOLUMN:
+           bottom = cell_info[row - 1][column].bottom_line;
+           break;
+       case LyXTabular::CELL_NORMAL:
+           bottom = row_info[row - 1].bottom_line;
        }
        }
-       for (column = 0; column < columns_ - 1 && top; ++column) {
-               switch (cell_info[row][column].multicolumn){
-               case LyXTabular::CELL_BEGIN_OF_MULTICOLUMN:
-                       top = cell_info[row][column].top_line;
-                       break;
-               case LyXTabular::CELL_NORMAL:
-                       top = row_info[row].top_line;
-               }
+    }
+    for (column = 0; column < columns_ - 1 && top; ++column) {
+       switch (cell_info[row][column].multicolumn){
+       case LyXTabular::CELL_BEGIN_OF_MULTICOLUMN:
+           top = cell_info[row][column].top_line;
+           break;
+       case LyXTabular::CELL_NORMAL:
+           top = row_info[row].top_line;
        }
        }
-       if (top && bottom)
-               return WIDTH_OF_LINE;
-       return 0;
+    }
+    if (top && bottom)
+       return WIDTH_OF_LINE;
+    return 0;
 }
 
 
 }
 
 
-int LyXTabular::AdditionalWidth(int cell)
+int LyXTabular::GetAdditionalWidth(int cell) const
 {
 {
-       // internally already set in SetWidthOfCell
-       // used to get it back in text.C
-       int col = right_column_of_cell(cell);
-       if (col < columns_ - 1 && column_info[col].right_line &&
-            column_info[col+1].left_line)
-               return WIDTH_OF_LINE;
-       else
-               return 0;
+    // internally already set in SetWidthOfCell
+    // used to get it back in text.C
+    int col = right_column_of_cell(cell);
+    if (col < columns_ - 1 && column_info[col].right_line &&
+       column_info[col+1].left_line)
+       return WIDTH_OF_LINE;
+    else
+       return 0;
 }
 
 
 // returns the maximum over all rows 
 }
 
 
 // returns the maximum over all rows 
-int LyXTabular::WidthOfColumn(int cell)
-{
-       int column1 = column_of_cell(cell);
-       int column2 = right_column_of_cell(cell);
-       int result = 0;
-       int i = column1;
-       for (; i <= column2; ++i) {
-               result += column_info[i].width_of_column;
-       }
-       return result;
+int LyXTabular::GetWidthOfColumn(int cell) const
+{
+    int column1 = column_of_cell(cell);
+    int column2 = right_column_of_cell(cell);
+    int result = 0;
+    int i = column1;
+    for (; i <= column2; ++i) {
+       result += column_info[i].width_of_column;
+    }
+    return result;
 }
 
 
 }
 
 
-int LyXTabular::WidthOfTabular()
+int LyXTabular::GetWidthOfTabular() const
 {
 {
-       return width_of_tabular;
+    return width_of_tabular;
 }
 
 /* returns 1 if a complete update is necessary, otherwise 0 */ 
 }
 
 /* returns 1 if a complete update is necessary, otherwise 0 */ 
@@ -630,12 +644,12 @@ bool LyXTabular::SetWidthOfMulticolCell(int cell, int new_width)
 
 void LyXTabular::recalculateMulticolCells(int cell, int new_width)
 {
 
 void LyXTabular::recalculateMulticolCells(int cell, int new_width)
 {
-       int row = row_of_cell(cell);
-       int column1 = column_of_cell(cell);
-        int column2 = right_column_of_cell(cell);
+    int row = row_of_cell(cell);
+    int column1 = column_of_cell(cell);
+    int column2 = right_column_of_cell(cell);
 
     // first set columns to 0 so we can calculate the right width
 
     // first set columns to 0 so we can calculate the right width
-        int i = column1;
+    int i = column1;
     for (; i <= column2; ++i)
         cell_info[row][i].width_of_cell = 0;
     for(i = cell + 1; (i < numberofcells) && (!IsMultiColumn(i)); ++i)
     for (; i <= column2; ++i)
         cell_info[row][i].width_of_cell = 0;
     for(i = cell + 1; (i < numberofcells) && (!IsMultiColumn(i)); ++i)
@@ -692,8 +706,6 @@ bool LyXTabular::SetAlignment(int cell, char align)
 bool LyXTabular::SetPWidth(int cell, string width)
 {
     if (IsMultiColumn(cell)) {
 bool LyXTabular::SetPWidth(int cell, string width)
 {
     if (IsMultiColumn(cell)) {
-//        if (column_info[column_of_cell(cell)].p_width.empty())
-//            column_info[column_of_cell(cell)].p_width = width;
         cellinfo_of_cell(cell)->p_width = width;
     } else {
         column_info[column_of_cell(cell)].p_width = width;
         cellinfo_of_cell(cell)->p_width = width;
     } else {
         column_info[column_of_cell(cell)].p_width = width;
@@ -745,99 +757,100 @@ bool LyXTabular::SetBottomLine(int cell, bool line)
 
 bool LyXTabular::SetLeftLine(int cell, bool line)
 {
 
 bool LyXTabular::SetLeftLine(int cell, bool line)
 {
-       column_info[column_of_cell(cell)].left_line = line;
-       return true;
+    column_info[column_of_cell(cell)].left_line = line;
+    return true;
 }
 
 
 bool LyXTabular::SetRightLine(int cell, bool line)
 {
 }
 
 
 bool LyXTabular::SetRightLine(int cell, bool line)
 {
-       column_info[right_column_of_cell(cell)].right_line = line;
-       return true;
+    column_info[right_column_of_cell(cell)].right_line = line;
+    return true;
 }
 
 
 }
 
 
-char LyXTabular::GetAlignment(int cell)
+char LyXTabular::GetAlignment(int cell) const
 {
 {
-       if (IsMultiColumn(cell))
-               return cellinfo_of_cell(cell)->alignment;
-       else
-               return column_info[column_of_cell(cell)].alignment;
+    if (IsMultiColumn(cell))
+       return cellinfo_of_cell(cell)->alignment;
+    else
+       return column_info[column_of_cell(cell)].alignment;
 }
 
 }
 
-string LyXTabular::GetPWidth(int cell)
+string LyXTabular::GetPWidth(int cell) const
 {
 {
-       if (IsMultiColumn(cell))
-               return cellinfo_of_cell(cell)->p_width;
-       return column_info[column_of_cell(cell)].p_width;
+    if (IsMultiColumn(cell))
+       return cellinfo_of_cell(cell)->p_width;
+    return column_info[column_of_cell(cell)].p_width;
 }
 
 }
 
-string LyXTabular::GetAlignSpecial(int cell, int what)
+string LyXTabular::GetAlignSpecial(int cell, int what) const
 {
     if (what == SET_SPECIAL_MULTI)
         return cellinfo_of_cell(cell)->align_special;
     return column_info[column_of_cell(cell)].align_special;
 }
 
 {
     if (what == SET_SPECIAL_MULTI)
         return cellinfo_of_cell(cell)->align_special;
     return column_info[column_of_cell(cell)].align_special;
 }
 
-int LyXTabular::GetWidthOfCell(int cell)
+int LyXTabular::GetWidthOfCell(int cell) const
 {
 {
-       int row = row_of_cell(cell);
-       int column1 = column_of_cell(cell);
-       int column2 = right_column_of_cell(cell);
-       int result = 0;
-       int i = column1;
-       for (; i <= column2; ++i) {
-               result += cell_info[row][i].width_of_cell;
-       }
-  
-       result += AdditionalWidth(cell);
-  
-       return result;
+    int row = row_of_cell(cell);
+    int column1 = column_of_cell(cell);
+    int column2 = right_column_of_cell(cell);
+    int result = 0;
+    int i = column1;
+    for (; i <= column2; ++i) {
+       result += cell_info[row][i].width_of_cell;
+    }
+    
+//    result += GetAdditionalWidth(cell);
+    
+    return result;
 }
 
 
 }
 
 
-int LyXTabular::GetBeginningOfTextInCell(int cell)
+int LyXTabular::GetBeginningOfTextInCell(int cell) const
 {
 {
-       int x = 0;
+    int x = 0;
    
    
-       switch (GetAlignment(cell)){
-       case LYX_ALIGN_CENTER:
-               x += (WidthOfColumn(cell) - GetWidthOfCell(cell)) / 2;
-               break;
-       case LYX_ALIGN_RIGHT:
-               x += WidthOfColumn(cell) - GetWidthOfCell(cell) + AdditionalWidth(cell);
-               break;
-       default: /* LYX_ALIGN_LEFT: nothing :-) */ 
-               break;
-       }
-
-       // the LaTeX Way :-(
-       x += WIDTH_OF_LINE;
-       return x;
+    switch (GetAlignment(cell)){
+    case LYX_ALIGN_CENTER:
+       x += (GetWidthOfColumn(cell) - GetWidthOfCell(cell)) / 2;
+       break;
+    case LYX_ALIGN_RIGHT:
+       x += GetWidthOfColumn(cell) - GetWidthOfCell(cell);
+       // + GetAdditionalWidth(cell);
+       break;
+    default: /* LYX_ALIGN_LEFT: nothing :-) */ 
+       break;
+    }
+    
+    // the LaTeX Way :-(
+    x += WIDTH_OF_LINE;
+    return x;
 }
 
 
 }
 
 
-bool LyXTabular::IsFirstCellInRow(int cell)
+bool LyXTabular::IsFirstCellInRow(int cell) const
 {
 {
-       return (column_of_cell(cell) == 0);
+    return (column_of_cell(cell) == 0);
 }
 
 }
 
-bool LyXTabular::IsLastCellInRow(int cell)
+bool LyXTabular::IsLastCellInRow(int cell) const
 {
 {
-       return (right_column_of_cell(cell) == (columns_ - 1));
+    return (right_column_of_cell(cell) == (columns_ - 1));
 }
 
 
 bool LyXTabular::calculate_width_of_column(int column)
 {
 }
 
 
 bool LyXTabular::calculate_width_of_column(int column)
 {
-       int old_column_width = column_info[column].width_of_column;
-       int maximum = 0;
-
-       for (int i = 0; i < rows_; ++i) {
-               maximum = max(cell_info[i][column].width_of_cell, maximum);
-       }
-       column_info[column].width_of_column = maximum;
-       return (column_info[column].width_of_column != old_column_width);
+    int old_column_width = column_info[column].width_of_column;
+    int maximum = 0;
+    
+    for (int i = 0; i < rows_; ++i) {
+       maximum = max(cell_info[i][column].width_of_cell, maximum);
+    }
+    column_info[column].width_of_column = maximum;
+    return (column_info[column].width_of_column != old_column_width);
 }
 
 bool LyXTabular::calculate_width_of_column_NMC(int column)
 }
 
 bool LyXTabular::calculate_width_of_column_NMC(int column)
@@ -856,10 +869,10 @@ bool LyXTabular::calculate_width_of_column_NMC(int column)
 
 void LyXTabular::calculate_width_of_tabular()
 {
 
 void LyXTabular::calculate_width_of_tabular()
 {
-       width_of_tabular = 0;
-       for (int i = 0; i < columns_; ++i) {
-               width_of_tabular += column_info[i].width_of_column;
-       }
+    width_of_tabular = 0;
+    for (int i = 0; i < columns_; ++i) {
+       width_of_tabular += column_info[i].width_of_column;
+    }
 }
 
 
 }
 
 
@@ -883,181 +896,367 @@ int LyXTabular::column_of_cell(int cell) const
 }
 
 
 }
 
 
-int LyXTabular::right_column_of_cell(int cell) 
+int LyXTabular::right_column_of_cell(int cell) const
 {
 {
-       int row = row_of_cell(cell);
-       int column = column_of_cell(cell);
-       while (column < (columns_ - 1) &&
-              cell_info[row][column+1].multicolumn == LyXTabular::CELL_PART_OF_MULTICOLUMN)
-               ++column;
-       return column;
+    int row = row_of_cell(cell);
+    int column = column_of_cell(cell);
+    while (column < (columns_ - 1) &&
+          cell_info[row][column+1].multicolumn == LyXTabular::CELL_PART_OF_MULTICOLUMN)
+       ++column;
+    return column;
 }
 
 
 }
 
 
-void LyXTabular::Write(ostream & os, bool old_format)
+void LyXTabular::Write(ostream & os) const
 {
 {
-    if (old_format) {
-       int i, j;
-       os << "multicol5\n"
-          << rows_ << " " << columns_ << " " << is_long_tabular << " "
-          << rotate << " " << endhead << " " << endfirsthead << " "
-          << endfoot << " " << endlastfoot << "\n";
-       for (i = 0; i < rows_; ++i) {
-           os << row_info[i].top_line << " "
-              << row_info[i].bottom_line << " "
-              << row_info[i].newpage << "\n";
-       }
-       for (i = 0; i < columns_; ++i) {
-           os << column_info[i].alignment << " "
-              << column_info[i].left_line << " "
-              << column_info[i].right_line << " \""
-              << VSpace(column_info[i].p_width).asLyXCommand() << "\" \""
-              << column_info[i].align_special << "\"\n";
-       }
+    int i, j;
 
 
-       for (i = 0; i < rows_; ++i) {
-           for (j = 0; j < columns_; ++j) {
-               os << cell_info[i][j].multicolumn << " "
-                  << cell_info[i][j].alignment << " "
-                  << cell_info[i][j].top_line << " "
-                  << cell_info[i][j].bottom_line << " "
-                  << cell_info[i][j].rotate << " "
-                  << cell_info[i][j].linebreaks << " \""
-                  << cell_info[i][j].align_special << "\" \""
-                  << cell_info[i][j].p_width << "\"\n";
+    // header line
+    os << "<LyXTabular version=1 rows=" << rows_ << " columns=" << columns_ <<
+       ">" << endl;
+    // global longtable options
+    os << "<Features rotate=" << rotate <<
+       " islongtable=" << is_long_tabular <<
+       " endhead=" << endhead << " endfirsthead=" << endfirsthead <<
+       " endfoot=" << endfoot << " endlastfoot=" << endlastfoot <<
+       ">" << endl << endl;
+    for (i = 0; i < rows_; ++i) {
+       os << "<Row topline=" << row_info[i].top_line <<
+           " bottomline=" << row_info[i].bottom_line <<
+           " newpage=" << row_info[i].newpage <<
+           ">" << endl;
+       for (j = 0; j < columns_; ++j) {
+           if (!i) {
+               os << "<Column alignment=" << column_info[j].alignment <<
+                   " leftline=" << column_info[j].left_line <<
+                   " rightline=" << column_info[j].right_line <<
+                   " width=\"" << VSpace(column_info[j].p_width).asLyXCommand() <<
+                   "\" special=\"" << column_info[j].align_special <<
+                   "\">" << endl;
+           } else {
+               os << "<Column>" << endl;
            }
            }
+           os << "<Cell multicolumn=" << cell_info[i][j].multicolumn <<
+               " alignment=" << cell_info[i][j].alignment <<
+               " topline=" << cell_info[i][j].top_line <<
+               " bottomline=" << cell_info[i][j].bottom_line <<
+               " rotate=" << cell_info[i][j].rotate <<
+               " linebreaks=" << cell_info[i][j].linebreaks <<
+               " width=\"" << cell_info[i][j].p_width <<
+               "\" special=\"" << cell_info[i][j].align_special <<
+               "\">" << endl;
+           os << "\\begin_inset ";
+           cell_info[i][j].inset->Write(os);
+           os << "\n\\end_inset " << endl;
+           os << "</Cell>" << endl;
+           os << "</Column>" << endl;
        }
        }
-    } else {
-       lyxerr << "New format type not yet implemented!!!\n" << endl;
+       os << "</Row>" << endl;
+    }
+    os << "</LyXTabular>" << endl;
+}
+
+static bool getTokenValue(string const str, const char * token, string & ret)
+{
+    int pos = str.find(token);
+    char ch = str[pos+strlen(token)];
+
+    if ((pos < 0) || (ch != '='))
+       return false;
+    ret.clear();
+    pos += strlen(token)+1;
+    ch = str[pos];
+    if ((ch != '"') && (ch != '\'')) { // only read till next space
+       ret += ch;
+       ch = ' ';
+    }
+    while((pos < int(str.length()-1)) && (str[++pos] != ch))
+       ret += str[pos];
+
+    return true;
+}
+
+static bool getTokenValue(string const str, const char * token, int & num)
+{
+    string ret;
+    int pos = str.find(token);
+    char ch = str[pos+strlen(token)];
+
+    if ((pos < 0) || (ch != '='))
+       return false;
+    ret.clear();
+    pos += strlen(token)+1;
+    ch = str[pos];
+    if ((ch != '"') && (ch != '\'')) { // only read till next space
+       if (!isdigit(ch))
+           return false;
+       ret += ch;
     }
     }
+    ++pos;
+    while((pos < int(str.length()-1)) && isdigit(str[pos]))
+       ret += str[pos++];
+
+    num = strToInt(ret);
+    return true;
 }
 
 }
 
+static bool getTokenValue(string const str, const char * token, bool & flag)
+{
+    string ret;
+    int pos = str.find(token);
+    char ch = str[pos+strlen(token)];
 
 
-void LyXTabular::Read(istream & is)
+    if ((pos < 0) || (ch != '='))
+       return false;
+    ret.clear();
+    pos += strlen(token)+1;
+    ch = str[pos];
+    if ((ch != '"') && (ch != '\'')) { // only read till next space
+       if (!isdigit(ch))
+           return false;
+       ret += ch;
+    }
+    ++pos;
+    while((pos < int(str.length()-1)) && isdigit(str[pos]))
+       ret += str[pos++];
+
+    flag = strToInt(ret);
+    return true;
+}
+
+void l_getline(istream & is, string & str)
 {
 {
-       int version;
-       int i, j;
-       int rows_arg = 0;
-       int columns_arg = 0;
-       int is_long_tabular_arg = false;
-       int rotate_arg = false;
-       int a = -1;
-       int b = -1;
-       int c = -1;
-       int d = -1;
-       int e = 0;
-       int f = 0;
-       int g = 0;
-       int h = 0;
-       
-       string s;
-       getline(is, s);
-       if (s.length() > 8)
-               version = atoi(s.c_str() + 8);
-       else
-               version = 1;
-       if (version < 5) {
-               lyxerr << "Tabular format < 5 is not supported anymore\n"
-                       "Get an older version of LyX (< 1.1.x) for conversion!"
-                      << endl;
-               WriteAlert(_("Warning:"),
-                          _("Tabular format < 5 is not supported anymore\n"),
-                          _("Get an older version of LyX (< 1.1.x) for conversion!"));
-               if (version > 2) {
-                       is >> rows_arg >> columns_arg >> is_long_tabular_arg
-                          >> rotate_arg >> a >> b >> c >> d;
-               } else
-                       is >> rows_arg >> columns_arg;
-               Init(rows_arg, columns_arg);
-               SetLongTabular(is_long_tabular_arg);
-               SetRotateTabular(rotate_arg);
-               string tmp;
-               for (i = 0; i < rows_; ++i) {
-                       getline(is, tmp);
-               }
-               for (i = 0; i < columns_; ++i) {
-                       getline(is, tmp);
-               }
-               for (i = 0; i < rows_; ++i) {
-                       for (j = 0; j < columns_; ++j) {
-                               getline(is, tmp);
-                       }
-               }
-               set_row_column_number_info();
+    getline(is, str);
+    while(str.empty())
+       getline(is, str);
+}
+
+void LyXTabular::Read(LyXLex & lex)
+{
+    string line;
+    istream & is = lex.getStream();
+
+    l_getline(is, line);
+    if (!prefixIs(line, "<LyXTabular ")) {
+       OldFormatRead(is, line);
+       return;
+    }
+
+    int version;
+    int rows_arg;
+    int columns_arg;
+    if (!getTokenValue(line, "version", version))
+       return;
+    if (!getTokenValue(line, "rows", rows_arg))
+       return;
+    if (!getTokenValue(line, "columns", columns_arg))
+       return;
+    Init(rows_arg, columns_arg);
+    l_getline(is, line);
+    if (!prefixIs(line, "<Features ")) {
+       lyxerr << "Wrong tabular format (expected <Feture ...> got" <<
+           line << ")" << endl;
+       return;
+    }
+    (void)getTokenValue(line, "islongtable", is_long_tabular);
+    (void)getTokenValue(line, "endhead", endhead);
+    (void)getTokenValue(line, "endfirsthead", endfirsthead);
+    (void)getTokenValue(line, "endfoot", endfoot);
+    (void)getTokenValue(line, "endlastfoot", endlastfoot);
+    int i, j;
+    for(i = 0; i < rows_; ++i) {
+       l_getline(is, line);
+       if (!prefixIs(line, "<Row ")) {
+           lyxerr << "Wrong tabular format (expected <Row ...> got" <<
+               line << ")" << endl;
+           return;
+       }
+       (void)getTokenValue(line, "topline", row_info[i].top_line);
+       (void)getTokenValue(line, "bottomline", row_info[i].bottom_line);
+       (void)getTokenValue(line, "newpage", row_info[i].newpage);
+       for (j = 0; j < columns_; ++j) {
+           l_getline(is,line);
+           if (!prefixIs(line,"<Column")) {
+               lyxerr << "Wrong tabular format (expected <Column ...> got" <<
+                   line << ")" << endl;
+               return;
+           }
+           if (!i) {
+               (void)getTokenValue(line, "alignment", column_info[j].alignment);
+               (void)getTokenValue(line, "leftline", column_info[j].left_line);
+               (void)getTokenValue(line, "rightline", column_info[j].right_line);
+               (void)getTokenValue(line, "width", column_info[j].p_width);
+               (void)getTokenValue(line, "special", column_info[j].align_special);
+           }
+           l_getline(is, line);
+           if (!prefixIs(line, "<Cell")) {
+               lyxerr << "Wrong tabular format (expected <Cell ...> got" <<
+                   line << ")" << endl;
+               return;
+           }
+           (void)getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn);
+           (void)getTokenValue(line, "alignment", cell_info[i][j].alignment);
+           (void)getTokenValue(line, "topline", cell_info[i][j].top_line);
+           (void)getTokenValue(line, "bottomline", cell_info[i][j].bottom_line);
+           (void)getTokenValue(line, "rotate", cell_info[i][j].rotate);
+           (void)getTokenValue(line, "linebreaks", cell_info[i][j].linebreaks);
+           (void)getTokenValue(line, "width", cell_info[i][j].p_width);
+           (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);
+               l_getline(is, line);
+           }
+           if (line != "</Cell>") {
+               lyxerr << "Wrong tabular format (expected </Cell> got" <<
+                   line << ")" << endl;
+               return;
+           }
+           l_getline(is, line);
+           if (line != "</Column>") {
+               lyxerr << "Wrong tabular format (expected </Column> got" <<
+                   line << ")" << endl;
                return;
                return;
+           }
+       }
+       l_getline(is, line);
+       if (line != "</Row>") {
+           lyxerr << "Wrong tabular format (expected </Row> got" <<
+               line << ")" << endl;
+           return;
        }
        }
-       is >> rows_arg >> columns_arg >> is_long_tabular_arg
-          >> rotate_arg >> a >> b >> c >> d;
+    }
+    while (line != "</LyXTabular>") {
+       l_getline(is, line);
+    }
+    set_row_column_number_info();
+}
+
+void LyXTabular::OldFormatRead(istream & is, string fl)
+{
+    int version;
+    int i, j;
+    int rows_arg = 0;
+    int columns_arg = 0;
+    int is_long_tabular_arg = false;
+    int rotate_arg = false;
+    int a = -1;
+    int b = -1;
+    int c = -1;
+    int d = -1;
+    int e = 0;
+    int f = 0;
+    int g = 0;
+    int h = 0;
+       
+    string s;
+    s = fl;
+    if (s.length() > 8)
+       version = atoi(s.c_str() + 8);
+    else
+       version = 1;
+    if (version < 5) {
+       lyxerr << "Tabular format < 5 is not supported anymore\n"
+           "Get an older version of LyX (< 1.1.x) for conversion!"
+              << endl;
+       WriteAlert(_("Warning:"),
+                  _("Tabular format < 5 is not supported anymore\n"),
+                  _("Get an older version of LyX (< 1.1.x) for conversion!"));
+       if (version > 2) {
+           is >> rows_arg >> columns_arg >> is_long_tabular_arg
+              >> rotate_arg >> a >> b >> c >> d;
+       } else
+           is >> rows_arg >> columns_arg;
        Init(rows_arg, columns_arg);
        SetLongTabular(is_long_tabular_arg);
        SetRotateTabular(rotate_arg);
        Init(rows_arg, columns_arg);
        SetLongTabular(is_long_tabular_arg);
        SetRotateTabular(rotate_arg);
-       endhead = a;
-       endfirsthead = b;
-       endfoot = c;
-       endlastfoot = d;
+       string tmp;
        for (i = 0; i < rows_; ++i) {
        for (i = 0; i < rows_; ++i) {
-               a = b = c = d = e = f = g = h = 0;
-               is >> a >> b >> c >> d;
-               row_info[i].top_line = a;
-               row_info[i].bottom_line = b;
-//             row_info[i].is_cont_row = c;
-               row_info[i].newpage = d;
+           getline(is, tmp);
        }
        for (i = 0; i < columns_; ++i) {
        }
        for (i = 0; i < columns_; ++i) {
-               string s1;
-               string s2;
-               is >> a >> b >> c;
-               char ch; // skip '"'
-               is >> ch;
-               getline(is, s1, '"');
-               is >> ch; // skip '"'
-               getline(is, s2, '"');
-               column_info[i].alignment = static_cast<char>(a);
-               column_info[i].left_line = b;
-               column_info[i].right_line = c;
-               column_info[i].p_width = s1;
-               column_info[i].align_special = s2;
+           getline(is, tmp);
        }
        for (i = 0; i < rows_; ++i) {
        }
        for (i = 0; i < rows_; ++i) {
-               for (j = 0; j < columns_; ++j) {
-                       string s1;
-                       string s2;
-                       is >> a >> b >> c >> d >> e >> f >> g;
-                       char ch;
-                       is >> ch; // skip '"'
-                       getline(is, s1, '"');
-                       is >> ch; // skip '"'
-                       getline(is, s2, '"');
-                       cell_info[i][j].multicolumn = static_cast<char>(a);
-                       cell_info[i][j].alignment = static_cast<char>(b);
-                       cell_info[i][j].top_line = static_cast<char>(c);
-                       cell_info[i][j].bottom_line = static_cast<char>(d);
-//                     cell_info[i][j].has_cont_row = static_cast<bool>(e);
-                       cell_info[i][j].rotate = static_cast<bool>(f);
-                       cell_info[i][j].linebreaks = static_cast<bool>(g);
-                       cell_info[i][j].align_special = s1;
-                       cell_info[i][j].p_width = s2;
-               }
+           for (j = 0; j < columns_; ++j) {
+               getline(is, tmp);
+           }
        }
        set_row_column_number_info();
        }
        set_row_column_number_info();
+       return;
+    }
+    is >> rows_arg >> columns_arg >> is_long_tabular_arg
+       >> rotate_arg >> a >> b >> c >> d;
+    Init(rows_arg, columns_arg);
+    SetLongTabular(is_long_tabular_arg);
+    SetRotateTabular(rotate_arg);
+    endhead = a;
+    endfirsthead = b;
+    endfoot = c;
+    endlastfoot = d;
+    for (i = 0; i < rows_; ++i) {
+       a = b = c = d = e = f = g = h = 0;
+       is >> a >> b >> c >> d;
+       row_info[i].top_line = a;
+       row_info[i].bottom_line = b;
+//     row_info[i].is_cont_row = c;
+       row_info[i].newpage = d;
+    }
+    for (i = 0; i < columns_; ++i) {
+       string s1;
+       string s2;
+       is >> a >> b >> c;
+       char ch; // skip '"'
+       is >> ch;
+       getline(is, s1, '"');
+       is >> ch; // skip '"'
+       getline(is, s2, '"');
+       column_info[i].alignment = static_cast<char>(a);
+       column_info[i].left_line = b;
+       column_info[i].right_line = c;
+       column_info[i].p_width = s1;
+       column_info[i].align_special = s2;
+    }
+    for (i = 0; i < rows_; ++i) {
+       for (j = 0; j < columns_; ++j) {
+           string s1;
+           string s2;
+           is >> a >> b >> c >> d >> e >> f >> g;
+           char ch;
+           is >> ch; // skip '"'
+           getline(is, s1, '"');
+           is >> ch; // skip '"'
+           getline(is, s2, '"');
+           cell_info[i][j].multicolumn = static_cast<char>(a);
+           cell_info[i][j].alignment = static_cast<char>(b);
+           cell_info[i][j].top_line = static_cast<char>(c);
+           cell_info[i][j].bottom_line = static_cast<char>(d);
+//                     cell_info[i][j].has_cont_row = static_cast<bool>(e);
+           cell_info[i][j].rotate = static_cast<bool>(f);
+           cell_info[i][j].linebreaks = static_cast<bool>(g);
+           cell_info[i][j].align_special = s1;
+           cell_info[i][j].p_width = s2;
+       }
+    }
+    set_row_column_number_info();
 }
 
 
 }
 
 
-// cell <0 will tex the preamble
+// cell < 0 will tex the preamble
 // returns the number of printed newlines
 // returns the number of printed newlines
-int LyXTabular::TexEndOfCell(ostream & os, int cell)
+int LyXTabular::TexEndOfCell(ostream & os, int cell) const
 {
     int i;
     int ret = 0;
     int tmp; // tmp2;
     int fcell, nvcell;
 {
     int i;
     int ret = 0;
     int tmp; // tmp2;
     int fcell, nvcell;
-    if (ShouldBeVeryLastCell(cell)) {
+    if (IsLastCell(cell)) {
         // the very end at the very beginning
         // the very end at the very beginning
-        if (Linebreaks(cell))
+        if (GetLinebreaks(cell))
                os << "\\smallskip{}}";
         if (IsMultiColumn(cell))
                os << '}';
                os << "\\smallskip{}}";
         if (IsMultiColumn(cell))
                os << '}';
-        if (RotateCell(cell)) {
+        if (GetRotateCell(cell)) {
                os << "\n\\end{sideways}";
             ++ret;
         }
                os << "\n\\end{sideways}";
             ++ret;
         }
@@ -1164,18 +1363,18 @@ int LyXTabular::TexEndOfCell(ostream & os, int cell)
                     ++ret;
                 }
             }
                     ++ret;
                 }
             }
-            if (RotateCell(0)) {
+            if (GetRotateCell(0)) {
                    os << "\\begin{sideways}\n";
                 ++ret;
             }
         } else {
             // usual cells
                    os << "\\begin{sideways}\n";
                 ++ret;
             }
         } else {
             // usual cells
-            if (Linebreaks(cell))
+            if (GetLinebreaks(cell))
                    os << "\\smallskip{}}";
             if (IsMultiColumn(cell)){
                    os << '}';
             }
                    os << "\\smallskip{}}";
             if (IsMultiColumn(cell)){
                    os << '}';
             }
-            if (RotateCell(cell)) {
+            if (GetRotateCell(cell)) {
                    os << "\n\\end{sideways}";
                 ++ret;
             }
                    os << "\n\\end{sideways}";
                 ++ret;
             }
@@ -1251,9 +1450,8 @@ int LyXTabular::TexEndOfCell(ostream & os, int cell)
                     print_hline = false; // no line below a \\newpage-command
                 }
                 tmp = 0;
                     print_hline = false; // no line below a \\newpage-command
                 }
                 tmp = 0;
-                if (nvcell < numberofcells
-                   && (cell < GetNumberOfCells() - 1)
-                    && !ShouldBeVeryLastCell(cell)) {
+                if ((nvcell < numberofcells) &&
+                   (cell < GetNumberOfCells() - 1) && !IsLastCell(cell)) {
                     fcell = nvcell;
                     for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
                         if (TopLine(fcell + i))
                     fcell = nvcell;
                     for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
                         if (TopLine(fcell + i))
@@ -1296,8 +1494,6 @@ int LyXTabular::TexEndOfCell(ostream & os, int cell)
                 bool sflag2 = (row == endhead) || (row == endfirsthead) ||
                     (row == endfoot) || (row == endlastfoot);
                 --row;
                 bool sflag2 = (row == endhead) || (row == endfirsthead) ||
                     (row == endfoot) || (row == endlastfoot);
                 --row;
-//                sflag2 = IsLongTabular() && (row >= 0) &&
-//                    (sflag2 || (row == endhead) || (row == endfirsthead));
                 row += 2;
                 bool sflag1 = IsLongTabular() && (row != endhead) &&
                     (row != endfirsthead) &&
                 row += 2;
                 bool sflag1 = IsLongTabular() && (row != endhead) &&
                     (row != endfirsthead) &&
@@ -1324,14 +1520,14 @@ int LyXTabular::TexEndOfCell(ostream & os, int cell)
                         ++ret;
                     }
                 }
                         ++ret;
                     }
                 }
-                if (nvcell < numberofcells && RotateCell(nvcell)) {
+                if (nvcell < numberofcells && GetRotateCell(nvcell)) {
                        os << "\\begin{sideways}\n";
                     ++ret;
                 }
             } else {
                    os << "&\n";
                 ++ret;
                        os << "\\begin{sideways}\n";
                     ++ret;
                 }
             } else {
                    os << "&\n";
                 ++ret;
-                if (nvcell < numberofcells && RotateCell(nvcell)) {
+                if (nvcell < numberofcells && GetRotateCell(nvcell)) {
                        os << "\\begin{sideways}\n";
                     ++ret;
                 }
                        os << "\\begin{sideways}\n";
                     ++ret;
                 }
@@ -1370,9 +1566,8 @@ int LyXTabular::TexEndOfCell(ostream & os, int cell)
                os << "}{";
             }
         }
                os << "}{";
             }
         }
-        if (nvcell < numberofcells && Linebreaks(nvcell)) {
-//            !column_info[column_of_cell(nvcell)].p_width.empty()) {
-               os << "\\parbox{"
+        if (nvcell < numberofcells && GetLinebreaks(nvcell)) {
+               os << "\\parbox[t]{"
                   << GetPWidth(nvcell)
                   << "}{\\smallskip{}";
        }
                   << GetPWidth(nvcell)
                   << "}{\\smallskip{}";
        }
@@ -1477,7 +1672,7 @@ int LyXTabular::RoffEndOfCell(ostream & os, int cell)
 #endif
 
 
 #endif
 
 
-char const *LyXTabular::getDocBookAlign(int cell, bool isColumn)
+char const *LyXTabular::GetDocBookAlign(int cell, bool isColumn) const
 {
     int i;
     if (isColumn)
 {
     int i;
     if (isColumn)
@@ -1524,13 +1719,13 @@ char const *LyXTabular::getDocBookAlign(int cell, bool isColumn)
 
 // cell <0 will tex the preamble
 // returns the number of printed newlines
 
 // cell <0 will tex the preamble
 // returns the number of printed newlines
-int LyXTabular::DocBookEndOfCell(ostream & os, int cell, int & depth)
+int LyXTabular::DocBookEndOfCell(ostream & os, int cell, int & depth) const
 {
     int i;
     int ret = 0;
     //int tmp; // tmp2; // unused
     int nvcell; // fcell; // unused
 {
     int i;
     int ret = 0;
     //int tmp; // tmp2; // unused
     int nvcell; // fcell; // unused
-    if (ShouldBeVeryLastCell(cell)) {
+    if (IsLastCell(cell)) {
            os << newlineAndDepth(--depth)
               << "</ENTRY>"
               << newlineAndDepth(--depth)
            os << newlineAndDepth(--depth)
               << "</ENTRY>"
               << newlineAndDepth(--depth)
@@ -1559,7 +1754,7 @@ int LyXTabular::DocBookEndOfCell(ostream & os, int cell, int & depth)
             ++ret;
             for (i = 0; i < columns_; ++i) {
                    os << "<COLSPEC ALIGN='"
             ++ret;
             for (i = 0; i < columns_; ++i) {
                    os << "<COLSPEC ALIGN='"
-                      << getDocBookAlign(i, true)
+                      << GetDocBookAlign(i, true)
                       << "' COLNAME='col"
                       << i + 1
                       << "' COLNUM='"
                       << "' COLNAME='col"
                       << i + 1
                       << "' COLNUM='"
@@ -1587,7 +1782,7 @@ int LyXTabular::DocBookEndOfCell(ostream & os, int cell, int & depth)
               << "<ROW>"
               << newlineAndDepth(++depth)
               << "<ENTRY ALIGN='"
               << "<ROW>"
               << newlineAndDepth(++depth)
               << "<ENTRY ALIGN='"
-              << getDocBookAlign(0)
+              << GetDocBookAlign(0)
               << "'";
            if (IsMultiColumn(0)) {
                   os << " NAMEST='col1' NAMEEND='col"
               << "'";
            if (IsMultiColumn(0)) {
                   os << " NAMEST='col1' NAMEEND='col"
@@ -1607,7 +1802,7 @@ int LyXTabular::DocBookEndOfCell(ostream & os, int cell, int & depth)
                       << "<ROW>"
                       << newlineAndDepth(++depth)
                       << "<ENTRY ALIGN='"
                       << "<ROW>"
                       << newlineAndDepth(++depth)
                       << "<ENTRY ALIGN='"
-                      << getDocBookAlign(cell + 1)
+                      << GetDocBookAlign(cell + 1)
                       << "' VALIGN='middle'";
                if (IsMultiColumn(cell + 1)) {
                       os << " NAMEST='col"
                       << "' VALIGN='middle'";
                if (IsMultiColumn(cell + 1)) {
                       os << " NAMEST='col"
@@ -1625,7 +1820,7 @@ int LyXTabular::DocBookEndOfCell(ostream & os, int cell, int & depth)
                       << "</ENTRY>"
                       << newlineAndDepth(depth)
                       << "<ENTRY ALIGN='"
                       << "</ENTRY>"
                       << newlineAndDepth(depth)
                       << "<ENTRY ALIGN='"
-                      << getDocBookAlign(cell + 1)
+                      << GetDocBookAlign(cell + 1)
                       << "' VALIGN='middle'";
                if (IsMultiColumn(cell + 1)) {
                       os << " NAMEST='col"
                       << "' VALIGN='middle'";
                if (IsMultiColumn(cell + 1)) {
                       os << " NAMEST='col"
@@ -1645,13 +1840,13 @@ int LyXTabular::DocBookEndOfCell(ostream & os, int cell, int & depth)
 }
 
 
 }
 
 
-bool LyXTabular::IsMultiColumn(int cell)
+bool LyXTabular::IsMultiColumn(int cell) const
 {
     return (cellinfo_of_cell(cell)->multicolumn != LyXTabular::CELL_NORMAL);
 }
 
 
 {
     return (cellinfo_of_cell(cell)->multicolumn != LyXTabular::CELL_NORMAL);
 }
 
 
-LyXTabular::cellstruct* LyXTabular::cellinfo_of_cell(int cell)
+LyXTabular::cellstruct* LyXTabular::cellinfo_of_cell(int cell) const
 {
     int row = row_of_cell(cell);
     int column = column_of_cell(cell);
 {
     int row = row_of_cell(cell);
     int column = column_of_cell(cell);
@@ -1677,7 +1872,7 @@ void LyXTabular::SetMultiColumn(int cell, int number)
 }
 
 
 }
 
 
-int LyXTabular::cells_in_multicolumn(int cell)
+int LyXTabular::cells_in_multicolumn(int cell) const
 {
     int row = row_of_cell(cell);
     int column = column_of_cell(cell);
 {
     int row = row_of_cell(cell);
     int column = column_of_cell(cell);
@@ -1734,7 +1929,7 @@ void LyXTabular::delete_column(int column)
 
     for (i = 0; i < rows_; ++i) {
         cellstruct * tmp = cell_info[i];
 
     for (i = 0; i < rows_; ++i) {
         cellstruct * tmp = cell_info[i];
-        cell_info[i] = new cellstruct[columns_ - 1];
+        cell_info[i] = new cellstruct[columns_ - 1](buffer);
         for (j = 0; j < column; ++j) {
             cell_info[i][j] = tmp[j];
         }
         for (j = 0; j < column; ++j) {
             cell_info[i][j] = tmp[j];
         }
@@ -1755,7 +1950,7 @@ void LyXTabular::SetLongTabular(int what)
 }
 
 
 }
 
 
-bool LyXTabular::IsLongTabular()
+bool LyXTabular::IsLongTabular() const
 {
     return is_long_tabular;
 }
 {
     return is_long_tabular;
 }
@@ -1765,7 +1960,7 @@ void LyXTabular::SetRotateTabular(int what)
     rotate = what;
 }
 
     rotate = what;
 }
 
-bool LyXTabular::RotateTabular()
+bool LyXTabular::GetRotateTabular() const
 {
     return rotate;
 }
 {
     return rotate;
 }
@@ -1775,12 +1970,12 @@ void LyXTabular::SetRotateCell(int cell, int what)
     cellinfo_of_cell(cell)->rotate = what;
 }
 
     cellinfo_of_cell(cell)->rotate = what;
 }
 
-bool LyXTabular::RotateCell(int cell)
+bool LyXTabular::GetRotateCell(int cell) const
 {
     return cellinfo_of_cell(cell)->rotate;
 }
 
 {
     return cellinfo_of_cell(cell)->rotate;
 }
 
-bool LyXTabular::NeedRotating()
+bool LyXTabular::NeedRotating() const
 {
     if (rotate)
         return true;
 {
     if (rotate)
         return true;
@@ -1794,30 +1989,21 @@ bool LyXTabular::NeedRotating()
 }
 
 
 }
 
 
-bool LyXTabular::ShouldBeVeryLastCell(int cell)
-// "very last cell" ..of what? the row? the tabular?
-// "Cell" in this context appears to not count `virtual' cells
+bool LyXTabular::IsLastCell(int cell) const
 {
     if (cell < GetNumberOfCells())
         return false;
     return true;
 }
 
 {
     if (cell < GetNumberOfCells())
         return false;
     return true;
 }
 
-bool LyXTabular::IsLastRow(int cell)
-{
-    if (row_of_cell(cell) < rows_)
-        return false;
-    return true;
-}
-
-int LyXTabular::GetCellAbove(int cell)
+int LyXTabular::GetCellAbove(int cell) const
 {
     if (row_of_cell(cell) > 0)
         return cell_info[row_of_cell(cell)-1][column_of_cell(cell)].cellno;
     return cell;
 }
 
 {
     if (row_of_cell(cell) > 0)
         return cell_info[row_of_cell(cell)-1][column_of_cell(cell)].cellno;
     return cell;
 }
 
-int LyXTabular::GetCellNumber(int column, int row)
+int LyXTabular::GetCellNumber(int column, int row) const
 {
     if (column >= columns_)
         column = columns_ - 1;
 {
     if (column >= columns_)
         column = columns_ - 1;
@@ -1836,7 +2022,7 @@ void LyXTabular::SetLinebreaks(int cell, bool what)
     cellinfo_of_cell(cell)->linebreaks = what;
 }
 
     cellinfo_of_cell(cell)->linebreaks = what;
 }
 
-bool LyXTabular::Linebreaks(int cell)
+bool LyXTabular::GetLinebreaks(int cell) const
 {
     if (column_info[column_of_cell(cell)].p_width.empty() &&
         !(IsMultiColumn(cell) && !cellinfo_of_cell(cell)->p_width.empty()))
 {
     if (column_info[column_of_cell(cell)].p_width.empty() &&
         !(IsMultiColumn(cell) && !cellinfo_of_cell(cell)->p_width.empty()))
@@ -1861,17 +2047,17 @@ void LyXTabular::SetLTHead(int cell, bool first)
     }
 }
 
     }
 }
 
-bool LyXTabular::RowOfLTHead(int cell)
+bool LyXTabular::GetRowOfLTHead(int cell) const
 {
     if ((endhead+1) > rows_)
 {
     if ((endhead+1) > rows_)
-        endhead = -1;
+        return false;
     return (row_of_cell(cell) == endhead);
 }
 
     return (row_of_cell(cell) == endhead);
 }
 
-bool LyXTabular::RowOfLTFirstHead(int cell)
+bool LyXTabular::GetRowOfLTFirstHead(int cell) const
 {
     if ((endfirsthead+1) > rows_)
 {
     if ((endfirsthead+1) > rows_)
-        endfirsthead = -1;
+        return false;
     return (row_of_cell(cell) == endfirsthead);
 }
 
     return (row_of_cell(cell) == endfirsthead);
 }
 
@@ -1892,19 +2078,17 @@ void LyXTabular::SetLTFoot(int cell, bool last)
     }
 }
 
     }
 }
 
-bool LyXTabular::RowOfLTFoot(int cell)
+bool LyXTabular::GetRowOfLTFoot(int cell) const
 {
 {
-    if ((endfoot+1) > rows_) {
-        endfoot = -1;
+    if ((endfoot+1) > rows_)
         return false;
         return false;
-    }
     return (row_of_cell(cell) == endfoot);
 }
 
     return (row_of_cell(cell) == endfoot);
 }
 
-bool LyXTabular::RowOfLTLastFoot(int cell)
+bool LyXTabular::GetRowOfLTLastFoot(int cell) const
 {
     if ((endlastfoot+1) > rows_)
 {
     if ((endlastfoot+1) > rows_)
-        endlastfoot = -1;
+        return false;
     return (row_of_cell(cell) == endlastfoot);
 }
 
     return (row_of_cell(cell) == endlastfoot);
 }
 
@@ -1913,7 +2097,7 @@ void LyXTabular::SetLTNewPage(int cell, bool what)
     row_info[row_of_cell(cell)].newpage = what;
 }
 
     row_info[row_of_cell(cell)].newpage = what;
 }
 
-bool LyXTabular::LTNewPage(int cell)
+bool LyXTabular::GetLTNewPage(int cell) const
 {
     return row_info[row_of_cell(cell)].newpage;
 }
 {
     return row_info[row_of_cell(cell)].newpage;
 }
@@ -1932,40 +2116,40 @@ void LyXTabular::SetDescentOfRow(int row, int height)
     row_info[row].descent_of_row = height;
 }
 
     row_info[row].descent_of_row = height;
 }
 
-int LyXTabular::AscentOfRow(int row)
+int LyXTabular::GetAscentOfRow(int row) const
 {
     if (row >= rows_)
         return 0;
     return row_info[row].ascent_of_row;
 }
 
 {
     if (row >= rows_)
         return 0;
     return row_info[row].ascent_of_row;
 }
 
-int LyXTabular::DescentOfRow(int row)
+int LyXTabular::GetDescentOfRow(int row) const
 {
     if (row >= rows_)
         return 0;
     return row_info[row].descent_of_row;
 }
 
 {
     if (row >= rows_)
         return 0;
     return row_info[row].descent_of_row;
 }
 
-int LyXTabular::HeightOfTabular()
+int LyXTabular::GetHeightOfTabular() const
 {
     int
         height,
         row;
 
     for(row=0,height=0;(row<rows_); ++row)
 {
     int
         height,
         row;
 
     for(row=0,height=0;(row<rows_); ++row)
-        height += AscentOfRow(row) + DescentOfRow(row) +
-           AdditionalHeight(GetCellNumber(0,row));
+        height += GetAscentOfRow(row) + GetDescentOfRow(row) +
+           GetAdditionalHeight(GetCellNumber(0,row));
     return height;
 }
 
     return height;
 }
 
-bool LyXTabular::IsPartOfMultiColumn(int row, int column)
+bool LyXTabular::IsPartOfMultiColumn(int row, int column) const
 {
     if ((row >= rows_) || (column >= columns_))
         return false;
     return (cell_info[row][column].multicolumn==CELL_PART_OF_MULTICOLUMN);
 }
 
 {
     if ((row >= rows_) || (column >= columns_))
         return false;
     return (cell_info[row][column].multicolumn==CELL_PART_OF_MULTICOLUMN);
 }
 
-int LyXTabular::Latex(ostream &)
+int LyXTabular::Latex(ostream &) const
 {
     return 0;
 }
 {
     return 0;
 }
index 4af9255c6c7a16934fc1d8bd4c7c77241d2d5884..67876bc5671e620ebde27f368f2937e580c5f28f 100644 (file)
@@ -68,50 +68,52 @@ public:
     };
     /* konstruktor */
     ///
     };
     /* konstruktor */
     ///
-    LyXTabular(int columns_arg, int rows_arg, Buffer *buf = 0);
+    LyXTabular(int columns_arg, int rows_arg, Buffer *buf);
     ///
     ///
     ///
     ///
-    LyXTabular(LyXTabular const &, Buffer *buf = 0);
+    LyXTabular(LyXTabular const &, Buffer *buf);
     ///
     explicit
     ///
     explicit
-    LyXTabular(LyXLex & lex, Buffer *buf = 0);
+    LyXTabular(LyXLex & lex, Buffer *buf);
     ///
     ~LyXTabular();
     ///
     LyXTabular & operator=(LyXTabular const &);
     ///
     ///
     ~LyXTabular();
     ///
     LyXTabular & operator=(LyXTabular const &);
     ///
-    LyXTabular * Clone();
+    LyXTabular * Clone(Buffer * buf);
     
     /// Returns true if there is a topline, returns false if not
     
     /// Returns true if there is a topline, returns false if not
-    bool TopLine(int cell);
+    bool TopLine(int cell) const;
     /// Returns true if there is a topline, returns false if not
     /// Returns true if there is a topline, returns false if not
-    bool BottomLine(int cell);
+    bool BottomLine(int cell) const;
     /// Returns true if there is a topline, returns false if not
     /// Returns true if there is a topline, returns false if not
-    bool LeftLine(int cell);
+    bool LeftLine(int cell) const;
     /// Returns true if there is a topline, returns false if not
     /// Returns true if there is a topline, returns false if not
-    bool RightLine(int cell);
+    bool RightLine(int cell) const;
     
     ///
     
     ///
-    bool TopAlreadyDrawed(int cell);
+    bool TopAlreadyDrawed(int cell) const;
     ///
     ///
-    bool VeryLastRow(int cell);
+    bool LeftAlreadyDrawed(int cell) const;
+    ///
+    bool IsLastRow(int cell) const;
     
     ///
     
     ///
-    int AdditionalHeight(int cell);
+    int GetAdditionalHeight(int cell) const;
     ///
     ///
-    int AdditionalWidth(int cell);
+    int GetAdditionalWidth(int cell) const;
     
     /* returns the maximum over all rows */
     ///
     
     /* returns the maximum over all rows */
     ///
-    int WidthOfColumn(int cell);
+    int GetWidthOfColumn(int cell) const;
     ///
     ///
-    int WidthOfTabular();
+    int GetWidthOfTabular() const;
     ///
     ///
-    int AscentOfRow(int row);
+    int GetAscentOfRow(int row) const;
     ///
     ///
-    int DescentOfRow(int row);
+    int GetDescentOfRow(int row) const;
     ///
     ///
-    int HeightOfTabular();
+    int GetHeightOfTabular() const;
     ///
     void SetAscentOfRow(int row, int height);
     ///
     ///
     void SetAscentOfRow(int row, int height);
     ///
@@ -135,15 +137,15 @@ public:
     ///
     bool SetAlignSpecial(int cell, string special, int what);
     ///
     ///
     bool SetAlignSpecial(int cell, string special, int what);
     ///
-    char GetAlignment(int cell); // add approp. signedness
+    char GetAlignment(int cell) const; // add approp. signedness
     ///
     ///
-    string GetPWidth(int cell);
+    string GetPWidth(int cell) const;
     ///
     ///
-    string GetAlignSpecial(int cell, int what);
+    string GetAlignSpecial(int cell, int what) const;
     ///
     ///
-    int GetWidthOfCell(int cell);
+    int GetWidthOfCell(int cell) const;
     ///
     ///
-    int GetBeginningOfTextInCell(int cell);
+    int GetBeginningOfTextInCell(int cell) const;
     ///
     void AppendRow(int cell);
     ///
     ///
     void AppendRow(int cell);
     ///
@@ -153,49 +155,51 @@ public:
     ///
     void DeleteColumn(int cell);
     ///
     ///
     void DeleteColumn(int cell);
     ///
-    bool IsFirstCellInRow(int cell);
+    bool IsFirstCellInRow(int cell) const;
     ///
     ///
-    bool IsLastCellInRow(int cell);
+    bool IsLastCellInRow(int cell) const;
     ///
     ///
-    int GetNumberOfCells();
+    int GetNumberOfCells() const;
     ///
     int AppendCellAfterCell(int append_cell, int question_cell);
     ///
     int DeleteCellIfColumnIsDeleted(int cell, int delete_column_cell);
     ///
     ///
     int AppendCellAfterCell(int append_cell, int question_cell);
     ///
     int DeleteCellIfColumnIsDeleted(int cell, int delete_column_cell);
     ///
-    int NumberOfCellsInRow(int cell);
+    int NumberOfCellsInRow(int cell) const;
     ///
     void Reinit();
     ///
     void Init(int columns_arg, int rows_arg);
     ///
     ///
     void Reinit();
     ///
     void Init(int columns_arg, int rows_arg);
     ///
-    void Write(std::ostream &, bool old_format=true);
+    void Write(std::ostream &) const;
+    ///
+    void Read(LyXLex &);
     ///
     ///
-    void Read(std::istream &);
+    void OldFormatRead(std::istream &, string);
     ///
     ///
-    int Latex(std::ostream &);
+    int Latex(std::ostream &) const;
 
     // cell <0 will tex the preamble
     // returns the number of printed newlines
     ///
 
     // cell <0 will tex the preamble
     // returns the number of printed newlines
     ///
-    int TexEndOfCell(std::ostream &, int cell);
+    int TexEndOfCell(std::ostream &, int cell) const;
     ///
     ///
-    int DocBookEndOfCell(std::ostream &, int cell, int & depth);
+    int DocBookEndOfCell(std::ostream &, int cell, int & depth) const;
 #if 0
     ///
     int RoffEndOfCell(std::ostream &, int cell);
 #endif
     ///
 #if 0
     ///
     int RoffEndOfCell(std::ostream &, int cell);
 #endif
     ///
-    char const * getDocBookAlign(int cell, bool isColumn = false);
+    char const * GetDocBookAlign(int cell, bool isColumn = false) const;
 
     ///
 
     ///
-    bool IsMultiColumn(int cell);
+    bool IsMultiColumn(int cell) const;
     ///
     void SetMultiColumn(int cell, int number);
     ///
     int UnsetMultiColumn(int cell); // returns number of new cells
     ///
     ///
     void SetMultiColumn(int cell, int number);
     ///
     int UnsetMultiColumn(int cell); // returns number of new cells
     ///
-    bool IsPartOfMultiColumn(int row, int column);
+    bool IsPartOfMultiColumn(int row, int column) const;
     ///
     int row_of_cell(int cell) const;
     ///
     ///
     int row_of_cell(int cell) const;
     ///
@@ -203,47 +207,45 @@ public:
     ///
     void SetLongTabular(int what);
     ///
     ///
     void SetLongTabular(int what);
     ///
-    bool IsLongTabular();
+    bool IsLongTabular() const;
     ///
     void SetRotateTabular(int what);
     ///
     ///
     void SetRotateTabular(int what);
     ///
-    bool RotateTabular();
+    bool GetRotateTabular() const;
     ///
     void SetRotateCell(int cell, int what);
     ///
     ///
     void SetRotateCell(int cell, int what);
     ///
-    bool RotateCell(int cell);
-    ///
-    bool NeedRotating();
+    bool GetRotateCell(int cell) const;
     ///
     ///
-    bool ShouldBeVeryLastCell(int cell);
+    bool NeedRotating() const;
     ///
     ///
-    bool IsLastRow(int cell);
+    bool IsLastCell(int cell) const;
     ///
     ///
-    int GetCellAbove(int cell);
+    int GetCellAbove(int cell) const;
     ///
     ///
-    int GetCellNumber(int column, int row);
+    int GetCellNumber(int column, int row) const;
     ///
     void SetLinebreaks(int cell, bool what);
     ///
     ///
     void SetLinebreaks(int cell, bool what);
     ///
-    bool Linebreaks(int cell);
+    bool GetLinebreaks(int cell) const;
     ///
     /// Long Tabular Options
     ///
     void SetLTHead(int cell, bool first);
     ///
     ///
     /// Long Tabular Options
     ///
     void SetLTHead(int cell, bool first);
     ///
-    bool RowOfLTHead(int cell);
+    bool GetRowOfLTHead(int cell) const;
     ///
     ///
-    bool RowOfLTFirstHead(int cell);
+    bool GetRowOfLTFirstHead(int cell) const;
     ///
     void SetLTFoot(int cell, bool last);
     ///
     ///
     void SetLTFoot(int cell, bool last);
     ///
-    bool RowOfLTFoot(int cell);
+    bool GetRowOfLTFoot(int cell) const;
     ///
     ///
-    bool RowOfLTLastFoot(int cell);
+    bool GetRowOfLTLastFoot(int cell) const;
     ///
     void SetLTNewPage(int cell, bool what);
     ///
     ///
     void SetLTNewPage(int cell, bool what);
     ///
-    bool LTNewPage(int cell);
+    bool GetLTNewPage(int cell) const;
     ///
     InsetText * GetCellInset(int cell) const;
     ///
     ///
     InsetText * GetCellInset(int cell) const;
     ///
@@ -255,7 +257,7 @@ private: //////////////////////////////////////////////////////////////////
     ///
     struct cellstruct {
        ///
     ///
     struct cellstruct {
        ///
-        cellstruct(Buffer * buf = 0);
+        cellstruct(Buffer * buf);
        ///
        ~cellstruct();
        ///
        ///
        ~cellstruct();
        ///
@@ -355,16 +357,16 @@ private: //////////////////////////////////////////////////////////////////
     void calculate_width_of_tabular();
 
     ///
     void calculate_width_of_tabular();
 
     ///
-    int right_column_of_cell(int cell);
+    int right_column_of_cell(int cell) const;
 
     ///
 
     ///
-    cellstruct * cellinfo_of_cell(int cell);
+    cellstruct * cellinfo_of_cell(int cell) const;
 
     ///
     void delete_column(int column);
 
     ///
 
     ///
     void delete_column(int column);
 
     ///
-    int cells_in_multicolumn(int cell);
+    int cells_in_multicolumn(int cell) const;
     ///
     int is_long_tabular;
     ///
     ///
     int is_long_tabular;
     ///
index 674d3c58dc8060a652d04ca353c05d2d5730dc11..8db0533603f5f5e8d13a6841eb937ea5ea86d9e0 100644 (file)
@@ -45,6 +45,9 @@ public:
        /// Appends another TexRow
        TexRow & operator+= (TexRow const &);
 
        /// Appends another TexRow
        TexRow & operator+= (TexRow const &);
 
+       /// Returns the number of rows in this texrow
+       int rows() { return count; }
+
 private:
        /// Linked list of items
        struct RowItem {
 private:
        /// Linked list of items
        struct RowItem {
index 07d1a7abf5834c0595ccf2dca545a0717feb6385..4cee34067b3539cad7291bb6fdb57b8af0712715 100644 (file)
@@ -474,12 +474,78 @@ void LyXText::MakeFontEntriesLayoutSpecific(LyXParagraph * par)
        }
 }
 
        }
 }
 
+LyXParagraph * LyXText::SetLayout(LyXCursor & cur, LyXCursor & sstart_cur,
+                                 LyXCursor & send_cur,
+                                 LyXTextClass::size_type layout)
+{
+       LyXParagraph * endpar = send_cur.par->LastPhysicalPar()->Next();
+       LyXParagraph * undoendpar = endpar;
+
+       if (endpar && endpar->GetDepth()) {
+               while (endpar && endpar->GetDepth()) {
+                       endpar = endpar->LastPhysicalPar()->Next();
+                       undoendpar = endpar;
+               }
+       } else if (endpar) {
+               endpar = endpar->Next(); // because of parindents etc.
+       }
+   
+       SetUndo(Undo::EDIT,
+               sstart_cur.par->ParFromPos(sstart_cur.pos)->previous, 
+               undoendpar);
+
+       /* ok we have a selection. This is always between sstart_cur
+        * and sel_end cursor */ 
+       cur = sstart_cur;
+   
+       LyXLayout const & lyxlayout =
+               textclasslist.Style(buffer->params.textclass, layout);
+   
+       while (cur.par != send_cur.par) {
+               if (cur.par->footnoteflag == sstart_cur.par->footnoteflag) {
+                       cur.par->SetLayout(layout);
+                       MakeFontEntriesLayoutSpecific(cur.par);
+                       LyXParagraph* fppar = cur.par->FirstPhysicalPar();
+                       fppar->added_space_top = lyxlayout.fill_top ?
+                               VSpace(VSpace::VFILL) : VSpace(VSpace::NONE);
+                       fppar->added_space_bottom = lyxlayout.fill_bottom ? 
+                               VSpace(VSpace::VFILL) : VSpace(VSpace::NONE); 
+                       if (lyxlayout.margintype == MARGIN_MANUAL)
+                               cur.par->SetLabelWidthString(lyxlayout.labelstring());
+                       if (lyxlayout.labeltype != LABEL_BIBLIO
+                           && fppar->bibkey) {
+                               delete fppar->bibkey;
+                               fppar->bibkey = 0;
+                       }
+               }
+               cur.par = cur.par->Next();
+       }
+       if (cur.par->footnoteflag == sstart_cur.par->footnoteflag) {
+               cur.par->SetLayout(layout);
+               MakeFontEntriesLayoutSpecific(cur.par);
+               LyXParagraph* fppar = cur.par->FirstPhysicalPar();
+               fppar->added_space_top = lyxlayout.fill_top ?
+                       VSpace(VSpace::VFILL) : VSpace(VSpace::NONE);
+               fppar->added_space_bottom = lyxlayout.fill_bottom ? 
+                       VSpace(VSpace::VFILL) : VSpace(VSpace::NONE); 
+               if (lyxlayout.margintype == MARGIN_MANUAL)
+                       cur.par->SetLabelWidthString(lyxlayout.labelstring());
+               if (lyxlayout.labeltype != LABEL_BIBLIO
+                   && fppar->bibkey) {
+                       delete fppar->bibkey;
+                       fppar->bibkey = 0;
+               }
+       }
+       return endpar;
+}
 
 // set layout over selection and make a total rebreak of those paragraphs
 void LyXText::SetLayout(LyXTextClass::size_type layout)
 {
 
 // set layout over selection and make a total rebreak of those paragraphs
 void LyXText::SetLayout(LyXTextClass::size_type layout)
 {
-       LyXCursor tmpcursor;
+       LyXCursor
+               tmpcursor = cursor;  /* store the current cursor  */
 
 
+#ifdef USE_OLD_SET_LAYOUT
        // if there is no selection just set the layout
        // of the current paragraph  */
        if (!selection) {
        // if there is no selection just set the layout
        // of the current paragraph  */
        if (!selection) {
@@ -504,8 +570,6 @@ void LyXText::SetLayout(LyXTextClass::size_type layout)
                sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->previous, 
                undoendpar);
 
                sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->previous, 
                undoendpar);
 
-       tmpcursor = cursor;                    /* store the current cursor  */
-
        /* ok we have a selection. This is always between sel_start_cursor
         * and sel_end cursor */ 
        cursor = sel_start_cursor;
        /* ok we have a selection. This is always between sel_start_cursor
         * and sel_end cursor */ 
        cursor = sel_start_cursor;
@@ -550,7 +614,16 @@ void LyXText::SetLayout(LyXTextClass::size_type layout)
                        fppar->bibkey = 0;
                }
        }
                        fppar->bibkey = 0;
                }
        }
-   
+#else
+       // if there is no selection just set the layout
+       // of the current paragraph  */
+       if (!selection) {
+               sel_start_cursor = cursor;  // dummy selection
+               sel_end_cursor = cursor;
+       }
+       LyXParagraph *
+       endpar = SetLayout(cursor, sel_start_cursor, sel_end_cursor, layout);
+#endif
        RedoParagraphs(sel_start_cursor, endpar);
    
        // we have to reset the selection, because the
        RedoParagraphs(sel_start_cursor, endpar);
    
        // we have to reset the selection, because the
@@ -2210,7 +2283,7 @@ void LyXText::CopySelection()
        DeleteSimpleCutBuffer();
 
        // set the textclass
        DeleteSimpleCutBuffer();
 
        // set the textclass
-       simple_cut_buffer_textclass = buffer->params->textclass;
+       simple_cut_buffer_textclass = buffer->params.textclass;
 
        // copy behind a space if there is one
        while (sel_start_cursor.par->Last() > sel_start_cursor.pos
 
        // copy behind a space if there is one
        while (sel_start_cursor.par->Last() > sel_start_cursor.pos
@@ -2457,7 +2530,7 @@ void LyXText::PasteSelection()
      
                // make sure there is no class difference
                cap.SwitchLayoutsBetweenClasses(simple_cut_buffer_textclass,
      
                // make sure there is no class difference
                cap.SwitchLayoutsBetweenClasses(simple_cut_buffer_textclass,
-                                               buffer->params->textclass,
+                                               buffer->params.textclass,
                                                simple_cut_buffer);
      
                // make the simple_cut_buffer exactly the same layout than
                                                simple_cut_buffer);
      
                // make the simple_cut_buffer exactly the same layout than