]> git.lyx.org Git - lyx.git/blobdiff - src/text.C
fixes because of SUN CC warnings, bmtable now compiled with C compilator, countChar...
[lyx.git] / src / text.C
index 6d8b9ca4d25bbeb97304813f6ec3094ea1f58e74..18fb9d0b51b514972ba310dd78901e67cc4ae1b7 100644 (file)
@@ -1,12 +1,12 @@
 /* This file is part of
-* ======================================================
-* 
-*           LyX, The Document Processor
-*       
-*          Copyright (C) 1995 Matthias Ettrich
-*           Copyright (C) 1995-1998 The LyX Team.
-*
-*======================================================*/
+ * ====================================================== 
+ 
+ *           LyX, The Document Processor
+ *      
+ *           Copyright 1995 Matthias Ettrich
+ *           Copyright 1995-1999 The LyX Team.
+ *
+ * ====================================================== */
 
 #include <config.h>
 #include <cstdlib>
 #include "buffer.h"
 #include "lyxscreen.h"
 #include "minibuffer.h"
+#include "debug.h"
+#include "LyXView.h"
 
 static const int LYX_PAPER_MARGIN = 20;
 
 extern int mono_video;
 extern int reverse_video;
 extern int fast_selection;
-extern BufferView *current_view;
-extern int UnlockInset(UpdatableInset* inset);
+extern BufferView * current_view;
+extern int UnlockInset(UpdatableInset * inset);
 
 // ale070405
-extern int bibitemMaxWidth(const class LyXFont &);
+extern int bibitemMaxWidth(LyXFont const &);
 
-// dnaber 1999-02-02
-extern MiniBuffer *minibuffer;
-
-int LyXText::SingleWidth(LyXParagraph *par, int pos)
+int LyXText::SingleWidth(LyXParagraph * par,
+                        LyXParagraph::size_type pos)
 {
        char c = par->GetChar(pos);
        return SingleWidth(par, pos, c);
 }
 
 
-int LyXText::SingleWidth(LyXParagraph *par, int pos, char c)
+int LyXText::SingleWidth(LyXParagraph * par,
+                        LyXParagraph::size_type pos, char c)
 {
        LyXFont font = GetFont(par, pos);
 
@@ -58,38 +59,38 @@ int LyXText::SingleWidth(LyXParagraph *par, int pos, char c)
                return font.width(c);
 
        } else if (IsHfillChar(c)) {
-               return 3;       /* because of the representation
+               return 3;       /* Because of the representation
                                 * as vertical lines */
 
-       } else if (c == LYX_META_FOOTNOTE ||
-                  c == LYX_META_MARGIN ||
-                  c == LYX_META_FIG ||
-                  c == LYX_META_TAB ||
-                  c == LYX_META_WIDE_FIG ||
-                  c == LYX_META_WIDE_TAB ||
-                  c == LYX_META_ALGORITHM) 
+       } else if (c == LyXParagraph::META_FOOTNOTE ||
+                  c == LyXParagraph::META_MARGIN ||
+                  c == LyXParagraph::META_FIG ||
+                  c == LyXParagraph::META_TAB ||
+                  c == LyXParagraph::META_WIDE_FIG ||
+                  c == LyXParagraph::META_WIDE_TAB ||
+                  c == LyXParagraph::META_ALGORITHM) 
        {
                string fs;
                switch (c) {
-               case LYX_META_MARGIN:
+               case LyXParagraph::META_MARGIN:
                        fs = "margin";
                        break;
-               case LYX_META_FIG:
+               case LyXParagraph::META_FIG:
                        fs = "fig";
                        break;
-               case LYX_META_TAB:
+               case LyXParagraph::META_TAB:
                        fs = "tab";
                        break;
-               case LYX_META_ALGORITHM:
+               case LyXParagraph::META_ALGORITHM:
                        fs = "alg";
                        break;
-               case LYX_META_WIDE_FIG:
+               case LyXParagraph::META_WIDE_FIG:
                        fs = "wide-fig";
                        break;
-               case LYX_META_WIDE_TAB:
+               case LyXParagraph::META_WIDE_TAB:
                        fs = "wide-tab";
                        break;
-               case LYX_META_FOOTNOTE:
+               case LyXParagraph::META_FOOTNOTE:
                        fs = "foot";
                        break;
                }
@@ -98,8 +99,8 @@ int LyXText::SingleWidth(LyXParagraph *par, int pos, char c)
                return font.stringWidth(fs);
        } 
    
-       else if (c == LYX_META_INSET) {
-               Inset *tmpinset=par->GetInset(pos);
+       else if (c == LyXParagraph::META_INSET) {
+               Inset *tmpinset= par->GetInset(pos);
                if (tmpinset)
                        return par->GetInset(pos)->Width(font);
                else
@@ -113,9 +114,8 @@ int LyXText::SingleWidth(LyXParagraph *par, int pos, char c)
 }
 
 
-/* returns the paragraph position of the last character in the 
- * specified row */
-int LyXText::RowLast(Row *row)
+// Returns the paragraph position of the last character in the specified row
+LyXParagraph::size_type LyXText::RowLast(Row * row)
 {
        if (row->next == 0)
                return row->par->Last()-1;
@@ -126,12 +126,13 @@ int LyXText::RowLast(Row *row)
 }
 
 
-void LyXText::Draw(Row *row, int &pos, LyXScreen &scr, int offset, float &x)
+void LyXText::Draw(Row * row, LyXParagraph::size_type & pos,
+                  LyXScreen & scr, int offset, float & x)
 {
        char c = row->par->GetChar(pos);
 
        if (IsNewlineChar(c)) {
-               pos++;
+               ++pos;
                // Draw end-of-line marker
 
                LyXFont font = GetFont(row->par, pos);
@@ -142,56 +143,56 @@ void LyXText::Draw(Row *row, int &pos, LyXScreen &scr, int offset, float &x)
                p[0].x = int(x + wid*0.375); p[0].y = int(y - 0.875*asc*0.75);
                p[1].x = int(x);             p[1].y = int(y - 0.500*asc*0.75);
                p[2].x = int(x + wid*0.375); p[2].y = int(y - 0.125*asc*0.75);
-               scr.drawLines(::getGC(gc_new_line),p, 3);
+               scr.drawLines(::getGC(gc_new_line), p, 3);
                
                p[0].x = int(x);             p[0].y = int(y - 0.500*asc*0.75);
                p[1].x = int(x + wid);       p[1].y = int(y - 0.500*asc*0.75);
                p[2].x = int(x + wid);       p[2].y = int(y - asc*0.75);
-               scr.drawLines(::getGC(gc_new_line),p, 3);
+               scr.drawLines(::getGC(gc_new_line), p, 3);
                return;
        }
 
        LyXFont font = GetFont(row->par, pos);
        LyXFont font2 = font;
 
-       if (c == LYX_META_FOOTNOTE ||
-           c == LYX_META_MARGIN ||
-           c == LYX_META_FIG ||
-           c == LYX_META_TAB ||
-           c == LYX_META_WIDE_FIG ||
-           c == LYX_META_WIDE_TAB ||
-           c == LYX_META_ALGORITHM) {
+       if (c == LyXParagraph::META_FOOTNOTE
+           || c == LyXParagraph::META_MARGIN
+           || c == LyXParagraph::META_FIG
+           || c == LyXParagraph::META_TAB
+           || c == LyXParagraph::META_WIDE_FIG
+           || c == LyXParagraph::META_WIDE_TAB
+           || c == LyXParagraph::META_ALGORITHM) {
                string fs;
                switch (c) {
-               case LYX_META_MARGIN:
+               case LyXParagraph::META_MARGIN:
                        fs = "margin";
-                       /* draw a sign at the left margin! */ 
+                       // Draw a sign at the left margin! 
                        scr.drawText(font, "!", 1, offset + row->baseline,
                                     (LYX_PAPER_MARGIN - font.width('!'))/2);
                        break;
-               case LYX_META_FIG:
+               case LyXParagraph::META_FIG:
                        fs = "fig";
                        break;
-               case LYX_META_TAB:
+               case LyXParagraph::META_TAB:
                        fs = "tab";
                        break;
-               case LYX_META_ALGORITHM:
+               case LyXParagraph::META_ALGORITHM:
                        fs = "alg";
                        break;
-               case LYX_META_WIDE_FIG:
+               case LyXParagraph::META_WIDE_FIG:
                        fs = "wide-fig";
                        break;
-               case LYX_META_WIDE_TAB:
+               case LyXParagraph::META_WIDE_TAB:
                        fs = "wide-tab";
                        break;
-               case LYX_META_FOOTNOTE:
+               case LyXParagraph::META_FOOTNOTE:
                        fs = "foot";
                        break;
                }
                font.decSize();
                font.decSize();
          
-               /* calculate the position of the footnotemark */
+               // calculate the position of the footnotemark
                int y = (row->baseline - font2.maxAscent() 
                         + font.maxAscent());
          
@@ -199,7 +200,7 @@ void LyXText::Draw(Row *row, int &pos, LyXScreen &scr, int offset, float &x)
 
                float tmpx = x;
 
-               /* draw it and set new x position */
+               // draw it and set new x position
                x += scr.drawString(font, fs, offset + y, int(x));
 
                scr.drawLine(gc_foot, offset + row->baseline,
@@ -207,8 +208,8 @@ void LyXText::Draw(Row *row, int &pos, LyXScreen &scr, int offset, float &x)
          
                pos++;
                return;
-       } else if (c == LYX_META_INSET) {
-               Inset *tmpinset = row->par->GetInset(pos);
+       } else if (c == LyXParagraph::META_INSET) {
+               Inset * tmpinset = row->par->GetInset(pos);
                if (tmpinset) 
                        tmpinset->Draw(font, scr, offset + row->baseline, x);
                pos++;
@@ -222,39 +223,39 @@ void LyXText::Draw(Row *row, int &pos, LyXScreen &scr, int offset, float &x)
        // This is dirty, but fast. Notice that it will never be too small.
        // For the record, I'll note that Microsoft Word has a limit
        // of 768 here. We have none :-) (Asger)
-       static char textstring[1024];
-
-       int last = RowLast(row);
-       // Prevent crash in the extremely unlikely event
-       // that our array is too small
-       if (last > pos+1020) last = pos + 1020;
-
-       textstring[0] = c;
-       pos++;
-
-       int i = 1;
-
-       while (pos <= last &&
-              (unsigned char) (c = row->par->GetChar(pos)) > ' ' &&
-              font2 == GetFont(row->par, pos)) {
-               textstring[i++] = c;
-               pos++;
+       // Ok. I am the first to admit that the use of std::string will be
+       // a tiny bit slower than using a POD char array. However, I claim
+       // that this slowdown is so small that it is close to inperceptive.
+       // So IMHO we should go with the easier and clearer implementation.
+       // And even if 1024 is a large number here it might overflow, string
+       // will only overflow if the machine is out of memory...
+       static string textstring;
+       textstring = c;
+       ++pos;
+
+       LyXParagraph::size_type last = RowLast(row);
+       
+       while (pos <= last
+              && static_cast<char>(c = row->par->GetChar(pos)) > ' '
+              && font2 == GetFont(row->par, pos)) {
+               textstring += c;
+               ++pos;
        }
-       textstring[i] = 0; 
-
        float tmpx = x;
 
        // If monochrome and LaTeX mode, provide reverse background
        if (mono_video && font.latex() == LyXFont::ON) {
-               int a=font.maxAscent(), d=font.maxDescent();
+               int a = font.maxAscent(), d = font.maxDescent();
                scr.fillRectangle(gc_copy, int(tmpx), offset + row->baseline-a,
-                                 font.textWidth(textstring, i), a+d);
+                                 font.textWidth(textstring.c_str(),
+                                                textstring.length()), a+d);
        }
-
-       /* Draw text and set the new x position */ 
-       x += scr.drawText(font, textstring, i, offset + row->baseline, 
+       // Draw text and set the new x position
+       x += scr.drawText(font, textstring.c_str(), textstring.length(),
+                         offset + row->baseline, 
                          int(x));
-       /* what about underbars? */
+       
+       // what about underbars?
        if (font.underbar() == LyXFont::ON && font.latex() != LyXFont::ON) {
                scr.drawLine(gc_copy, offset + row->baseline + 2,
                             int(tmpx), int(x - tmpx));
@@ -270,26 +271,25 @@ void LyXText::Draw(Row *row, int &pos, LyXScreen &scr, int offset, float &x)
 * This information cannot be taken from the layouts-objekt, because in 
 * LaTeX the beginning of the text fits in some cases (for example sections)
 * exactly the label-width. */
-int LyXText::LeftMargin(Row* row)
+int LyXText::LeftMargin(Row * row)
 {
-   int x;
-   LyXLayout *layout;
    LyXFont labelfont;
-   LyXParagraph *newpar;
+   LyXParagraph * newpar;
    Row dummyrow;
-   layout = lyxstyle.Style(parameters->textclass, row->par->GetLayout());
+   LyXLayout const & layout = textclasslist.Style(parameters->textclass,
+                                                 row->par->GetLayout());
    
-   string parindent = layout->parindent; 
+   string parindent = layout.parindent; 
 
    /* table stuff -- begin*/ 
    if (row->par->table)
-      parindent.erase();
+      parindent.clear();
    /* table stuff -- end*/       
 
-   x = LYX_PAPER_MARGIN;
+   int x = LYX_PAPER_MARGIN;
 
-   x += lyxstyle.TextClass(parameters->textclass)->
-     defaultfont.signedStringWidth(lyxstyle.TextClass(parameters->textclass)->leftmargin);
+   x += textclasslist.TextClass(parameters->textclass).
+     defaultfont().signedStringWidth(textclasslist.TextClass(parameters->textclass).leftmargin());
 
    if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)  {
        LyXFont font(LyXFont::ALL_SANE);
@@ -305,8 +305,9 @@ int LyXText::LeftMargin(Row* row)
         /* find the previous same level paragraph */
         if (row->par->FirstPhysicalPar()->Previous()) {
            newpar = row->par->DepthHook(row->par->GetDepth());
-           if (newpar && lyxstyle.Style(parameters->textclass, newpar->GetLayout())->nextnoindent)
-              parindent.erase();
+           if (newpar && textclasslist.Style(parameters->textclass,
+                                             newpar->GetLayout()).nextnoindent)
+              parindent.clear();
         }
       }
    }
@@ -319,8 +320,8 @@ int LyXText::LeftMargin(Row* row)
       
       /* check wether it is a sufficent paragraph */ 
       if (newpar && newpar->footnoteflag == row->par->footnoteflag
-         && lyxstyle.Style(parameters->textclass, 
-                           newpar->GetLayout())->isEnvironment()) {
+         && textclasslist.Style(parameters->textclass, 
+                           newpar->GetLayout()).isEnvironment()) {
             dummyrow.par = newpar;
             dummyrow.pos = newpar->Last();
             x = LeftMargin(&dummyrow);
@@ -336,58 +337,58 @@ int LyXText::LeftMargin(Row* row)
       
       if (newpar && !row->par->GetLayout()) {
         if (newpar->FirstPhysicalPar()->noindent)
-           parindent.erase();
+           parindent.clear();
         else
-           parindent = lyxstyle.Style(parameters->textclass, 
-                                      newpar->GetLayout())->parindent;
+           parindent = textclasslist.Style(parameters->textclass, 
+                                      newpar->GetLayout()).parindent;
       }
       
    }
    
    labelfont = GetFont(row->par, -2);
-   switch (layout->margintype) {
+   switch (layout.margintype) {
     case MARGIN_DYNAMIC:
-      if (!layout->leftmargin.empty()) {
-       x += lyxstyle.TextClass(parameters->textclass)->defaultfont.signedStringWidth(layout->leftmargin);
+      if (!layout.leftmargin.empty()) {
+       x += textclasslist.TextClass(parameters->textclass).defaultfont().signedStringWidth(layout.leftmargin);
       }
       if (!row->par->GetLabestring().empty()) {
-           x += labelfont.signedStringWidth(layout->labelindent);
+           x += labelfont.signedStringWidth(layout.labelindent);
            x += labelfont.stringWidth(row->par->GetLabestring());
-           x += labelfont.stringWidth(layout->labelsep);
+           x += labelfont.stringWidth(layout.labelsep);
       }
       break;
     case MARGIN_MANUAL:
-      x += labelfont.signedStringWidth(layout->labelindent);
+      x += labelfont.signedStringWidth(layout.labelindent);
       if (row->pos >= BeginningOfMainBody(row->par)) {
         if (!row->par->GetLabelWidthString().empty()) {
            x += labelfont.stringWidth(row->par->GetLabelWidthString());
-           x += labelfont.stringWidth(layout->labelsep);
+           x += labelfont.stringWidth(layout.labelsep);
         }
       }
       break;
     case MARGIN_STATIC:
-      x += ( lyxstyle.TextClass(parameters->textclass)->defaultfont.signedStringWidth(layout->leftmargin) * 4
+      x += ( textclasslist.TextClass(parameters->textclass).defaultfont().signedStringWidth(layout.leftmargin) * 4
             / (row->par->GetDepth() + 4));
       break;
     case MARGIN_FIRST_DYNAMIC:
-      if (layout->labeltype == LABEL_MANUAL) {
+      if (layout.labeltype == LABEL_MANUAL) {
         if (row->pos >= BeginningOfMainBody(row->par)) {
-           x += labelfont.signedStringWidth(layout->leftmargin);
+           x += labelfont.signedStringWidth(layout.leftmargin);
         } else {
-           x += labelfont.signedStringWidth(layout->labelindent);
+           x += labelfont.signedStringWidth(layout.labelindent);
         }
       } else {
         if (row->pos
             // Special case to fix problems with theorems (JMarc)
-            || (layout->labeltype == LABEL_STATIC
-                && layout->latextype == LATEX_ENVIRONMENT
+            || (layout.labeltype == LABEL_STATIC
+                && layout.latextype == LATEX_ENVIRONMENT
                 && ! row->par->IsFirstInSequence())) {
-                x += labelfont.signedStringWidth(layout->leftmargin);
-        } else if (layout->labeltype != LABEL_TOP_ENVIRONMENT
-                 && layout->labeltype != LABEL_BIBLIO
-                 && layout->labeltype != LABEL_CENTERED_TOP_ENVIRONMENT) {
-                x += labelfont.signedStringWidth(layout->labelindent);
-                x += labelfont.stringWidth(layout->labelsep);
+                x += labelfont.signedStringWidth(layout.leftmargin);
+        } else if (layout.labeltype != LABEL_TOP_ENVIRONMENT
+                 && layout.labeltype != LABEL_BIBLIO
+                 && layout.labeltype != LABEL_CENTERED_TOP_ENVIRONMENT) {
+                x += labelfont.signedStringWidth(layout.labelindent);
+                x += labelfont.stringWidth(layout.labelsep);
                 x += labelfont.stringWidth(row->par->GetLabestring());
         } 
       }
@@ -400,7 +401,7 @@ int LyXText::LeftMargin(Row* row)
        * allowed in the LaTeX realisation of this layout. */ 
       
       /* find the first row of this paragraph */ 
-      Row *tmprow = row;
+      Row * tmprow = row;
       while (tmprow->previous && tmprow->previous->par == row->par)
        tmprow = tmprow->previous;
       
@@ -411,12 +412,12 @@ int LyXText::LeftMargin(Row* row)
           minfill = tmprow->fill;
       }
       
-      x += lyxstyle.TextClass(parameters->textclass)->defaultfont.signedStringWidth(layout->leftmargin);
+      x += textclasslist.TextClass(parameters->textclass).defaultfont().signedStringWidth(layout.leftmargin);
       x += minfill;
     }
       break;
    }
-   if (row->par->pextra_type == PEXTRA_INDENT) {
+   if (row->par->pextra_type == LyXParagraph::PEXTRA_INDENT) {
        if (!row->par->pextra_widthp.empty()) {
            x += paperwidth * atoi(row->par->pextra_widthp.c_str()) / 100;
        } else if (!row->par->pextra_width.empty()) {
@@ -433,27 +434,27 @@ int LyXText::LeftMargin(Row* row)
    
    int align;
    if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
-     align = layout->align;
+     align = layout.align;
    else
      align = row->par->FirstPhysicalPar()->align;
    
    /* set the correct parindent */
    if (row->pos == 0) {
-       if ((layout->labeltype == LABEL_NO_LABEL 
-           || layout->labeltype == LABEL_TOP_ENVIRONMENT 
-           || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
-           || (layout->labeltype == LABEL_STATIC
-               && layout->latextype == LATEX_ENVIRONMENT
+       if ((layout.labeltype == LABEL_NO_LABEL 
+           || layout.labeltype == LABEL_TOP_ENVIRONMENT 
+           || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
+           || (layout.labeltype == LABEL_STATIC
+               && layout.latextype == LATEX_ENVIRONMENT
                && ! row->par->IsFirstInSequence()))
           && row->par == row->par->FirstPhysicalPar()
           && align == LYX_ALIGN_BLOCK
           && !row->par->noindent
           && (row->par->layout ||
-              parameters->paragraph_separation == LYX_PARSEP_INDENT))
-        x += lyxstyle.TextClass(parameters->textclass)->defaultfont.stringWidth(parindent);
+              parameters->paragraph_separation == BufferParams::PARSEP_INDENT))
+        x += textclasslist.TextClass(parameters->textclass).defaultfont().stringWidth(parindent);
        else 
-        if (layout->labeltype==LABEL_BIBLIO) { // ale970405 Right width for bibitems
-            x += bibitemMaxWidth(lyxstyle.TextClass(parameters->textclass)->defaultfont);
+        if (layout.labeltype == LABEL_BIBLIO) { // ale970405 Right width for bibitems
+            x += bibitemMaxWidth(textclasslist.TextClass(parameters->textclass).defaultfont());
         }
    }
 
@@ -463,17 +464,14 @@ int LyXText::LeftMargin(Row* row)
    
 int LyXText::RightMargin(Row *row)
 {
-   int  x;
-   LyXLayout* layout;
-   
-   LyXParagraph *newpar;
+   LyXParagraph * newpar;
    Row dummyrow;
-   layout = lyxstyle.Style(parameters->textclass, row->par->GetLayout());
+   LyXLayout const & layout = textclasslist.Style(parameters->textclass, row->par->GetLayout());
 
-   x = LYX_PAPER_MARGIN;
+   int x = LYX_PAPER_MARGIN;
 
-   x += lyxstyle.TextClass(parameters->textclass)->
-     defaultfont.signedStringWidth(lyxstyle.TextClass(parameters->textclass)->rightmargin);
+   x += textclasslist.TextClass(parameters->textclass).
+     defaultfont().signedStringWidth(textclasslist.TextClass(parameters->textclass).rightmargin());
    if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)  {
      x += LYX_PAPER_MARGIN/2;
    }
@@ -497,8 +495,8 @@ int LyXText::RightMargin(Row *row)
 
       /* check wether it is a sufficent paragraph */ 
       if (newpar && newpar->footnoteflag == row->par->footnoteflag
-         && lyxstyle.Style(parameters->textclass,
-                           newpar->GetLayout())->isEnvironment()) {
+         && textclasslist.Style(parameters->textclass,
+                           newpar->GetLayout()).isEnvironment()) {
             dummyrow.par = newpar;
             dummyrow.pos = 0;
             x = RightMargin(&dummyrow);
@@ -513,18 +511,17 @@ int LyXText::RightMargin(Row *row)
       }
    }
 
-   //fprintf(stderr,"rightmargin: %s\n", layout->rightmargin.c_str());
-   //fflush(stderr);
-   x += (lyxstyle.TextClass(parameters->textclass)->defaultfont.signedStringWidth(layout->rightmargin) * 4
+   //lyxerr << "rightmargin: " << layout->rightmargin << endl;
+   x += (textclasslist.TextClass(parameters->textclass).defaultfont().signedStringWidth(layout.rightmargin) * 4
         / (row->par->GetDepth() + 4));
    return x;
    
 }
 
 
-int LyXText::LabelEnd (Row *row)
+int LyXText::LabelEnd (Row * row)
 {
-   if (lyxstyle.Style(parameters->textclass, row->par->GetLayout())->margintype == MARGIN_MANUAL) {
+   if (textclasslist.Style(parameters->textclass, row->par->GetLayout()).margintype == MARGIN_MANUAL) {
       Row tmprow;
       tmprow = *row;
       tmprow.pos = row->par->Last();
@@ -538,11 +535,12 @@ int LyXText::LabelEnd (Row *row)
 }
 
 
-/* table stuff -- begin*/ 
-int LyXText::NumberOfCell(LyXParagraph *par, int pos)
+/* table stuff -- begin*/
+int LyXText::NumberOfCell(LyXParagraph * par,
+                         LyXParagraph::size_type pos)
 {
    int cell = 0;
-   int tmp_pos = 0;
+   LyXParagraph::size_type tmp_pos = 0;
    while (tmp_pos < pos) {
       if (par->IsNewline(tmp_pos))
         cell++;
@@ -552,7 +550,7 @@ int LyXText::NumberOfCell(LyXParagraph *par, int pos)
 }
 
 
-int LyXText::WidthOfCell(LyXParagraph *par, int &pos)
+int LyXText::WidthOfCell(LyXParagraph * par, LyXParagraph::size_type & pos)
 {
    int w = 0;
    while (pos < par->Last() && !par->IsNewline(pos)) {
@@ -565,12 +563,12 @@ int LyXText::WidthOfCell(LyXParagraph *par, int &pos)
 }
 
 
-char LyXText::HitInTable(Row* row, int x)
+bool LyXText::HitInTable(Row * row, int x)
 {
   float tmpx;
   float fill_separator, fill_hfill, fill_label_hfill;
   if (!row->par->table)
-    return 0;
+    return false;
   PrepareToPrint(row, tmpx, fill_separator, fill_hfill, fill_label_hfill);
   return (x > tmpx && x < tmpx + row->par->table->WidthOfTable());
 }
@@ -578,7 +576,7 @@ char LyXText::HitInTable(Row* row, int x)
 
 bool LyXText::MouseHitInTable(int x, long y)
 {
-       Row *row = GetRowNearY(y);
+       Row * row = GetRowNearY(y);
         return HitInTable(row, x);
 }
 
@@ -587,25 +585,27 @@ bool LyXText::MouseHitInTable(int x, long y)
 
 
 /* get the next breakpoint in a given paragraph */
-int LyXText::NextBreakPoint(Row* row, int width)
+LyXParagraph::size_type
+LyXText::NextBreakPoint(Row * row, int width)
 {
        int x = 0;
-       int last_separator = -1; /* position of the last possible breakpoint 
-                                 * -1 isn't a suitable value, but a flag */
-       int i = 0;
+       LyXParagraph::size_type last_separator = -1;
+       /* position of the last possible breakpoint 
+        * -1 isn't a suitable value, but a flag */
        int left_margin;
        
-       LyXParagraph *par = row->par;
-       int pos = row->pos;
+       LyXParagraph * par = row->par;
+       LyXParagraph::size_type i = 0;
+       LyXParagraph::size_type pos = row->pos;
        
        /* table stuff -- begin*/ 
        if (par->table) {
-               while (pos<par->last 
+               while (pos < par->size()
                       && (!par->IsNewline(pos) 
                           || !par->table->IsFirstCell(NumberOfCell(par, pos+1)))) {
-                       if (par->GetChar(pos) == LYX_META_INSET &&
-                           par->GetInset(pos) && par->GetInset(pos)->Display()){
-                               par->GetInset(pos)->SetDisplay(false);
+                       if (par->GetChar(pos) == LyXParagraph::META_INSET &&
+                           par->GetInset(pos) && par->GetInset(pos)->display()){
+                               par->GetInset(pos)->display(false);
                        }
                        pos++;
                }
@@ -615,27 +615,29 @@ int LyXText::NextBreakPoint(Row* row, int width)
        
        left_margin = LabelEnd(row);
        width -= RightMargin(row);
-       int main_body = BeginningOfMainBody(par);
-       LyXLayout* layout = lyxstyle.Style(parameters->textclass, par->GetLayout());
+       LyXParagraph::size_type main_body = 
+               BeginningOfMainBody(par);
+       LyXLayout const & layout = textclasslist.Style(parameters->textclass, par->GetLayout());
        i = pos;
        char c;
        
-       if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
+       if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
                /* special code for right address boxes, only newlines count */
                while (i < par->Last()) {
                        if (par->IsNewline(i)) {
                                last_separator = i;
                                i = par->Last() - 1;/* this means break  */
                                x = width;
-                       } else if (par->GetChar(i) == LYX_META_INSET &&
-                                  par->GetInset(i) && par->GetInset(i)->Display()){
-                               par->GetInset(i)->SetDisplay(false);
+                       } else if (par->GetChar(i) == LyXParagraph::META_INSET &&
+                                  par->GetInset(i) && par->GetInset(i)->display()){
+                               par->GetInset(i)->display(false);
                        }
                        i++;
                }
        } else {
                // Last position is an invariant
-               int const last = par->Last();
+               LyXParagraph::size_type const last = 
+                       par->Last();
                /* this is the usual handling */ 
                x = LeftMargin(row);
                while (x < width && i < last) {
@@ -643,19 +645,19 @@ int LyXText::NextBreakPoint(Row* row, int width)
                        if (IsNewlineChar(c)) {
                                last_separator = i;
                                x = width;                     /* this means break  */
-                       } else if (c == LYX_META_INSET &&
-                                  par->GetInset(i) && par->GetInset(i)->Display()){
+                       } else if (c == LyXParagraph::META_INSET &&
+                                  par->GetInset(i) && par->GetInset(i)->display()){
                                /* check wether a Display() inset is valid here .
                                   if not, change it to non-display*/ 
-                               if (layout->isCommand()
-                                   || (layout->labeltype == LABEL_MANUAL
+                               if (layout.isCommand()
+                                   || (layout.labeltype == LABEL_MANUAL
                                        && i < BeginningOfMainBody(par))){
                                        /* display istn't allowd */ 
-                                       par->GetInset(i)->SetDisplay(false);
+                                       par->GetInset(i)->display(false);
                                        x += SingleWidth(par, i, c);
                                } else {
                                        /* inset is display. So break the line here */ 
-                                       if (i==pos){
+                                       if (i == pos){
                                                if (pos < last-1) {
                                                        last_separator = i;
                                                        if (IsLineSeparatorChar(par->GetChar(i+1)))
@@ -673,7 +675,7 @@ int LyXText::NextBreakPoint(Row* row, int width)
                        }
                        i++;
                        if (i == main_body) {
-                               x += GetFont(par, -2).stringWidth(layout->labelsep);
+                               x += GetFont(par, -2).stringWidth(layout.labelsep);
                                if (par->IsLineSeparator(i - 1))
                                        x-= SingleWidth(par, i - 1);
                                if (x < left_margin)
@@ -700,17 +702,16 @@ int LyXText::NextBreakPoint(Row* row, int width)
 
 
 /* returns the minimum space a row needs on the screen in pixel */
-int LyXText::Fill(Row *row, int paperwidth)
+int LyXText::Fill(Row * row, int paper_width)
 {
-   int w,i, last, fill, left_margin;
+   int w, fill;
    /* get the pure distance */
-   last = RowLast(row);
-   
+   LyXParagraph::size_type last = RowLast(row);
    /* table stuff -- begin*/
    if (row->par->table) {
       /* for tables FILL does calculate the widthes of each cell in 
-       * the row */ 
-      int pos = row->pos;
+       * the row */
+      LyXParagraph::size_type pos = row->pos;
       int cell = NumberOfCell(row->par, pos);
       w = 0;
       do {
@@ -727,7 +728,7 @@ int LyXText::Fill(Row *row, int paperwidth)
    }
    /* table stuff -- end*/ 
 
-   left_margin = LabelEnd(row);
+   int left_margin = LabelEnd(row);
 
      /* if the row ends with newline, this newline will not be relevant */ 
      if (last >= 0 && row->par->IsNewline(last))
@@ -738,47 +739,44 @@ int LyXText::Fill(Row *row, int paperwidth)
        last--;
 
    /* special handling of the right address boxes */ 
-   if (lyxstyle.Style(parameters->textclass, row->par->GetLayout())->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
+   if (textclasslist.Style(parameters->textclass,
+                          row->par->GetLayout()).margintype
+       == MARGIN_RIGHT_ADDRESS_BOX) {
       int tmpfill = row->fill;
       row->fill = 0;                  /* the minfill in MarginLeft()  */
       w = LeftMargin(row);
       row->fill = tmpfill;
-      
-      /* the old way, impossible when using environments: */ 
-      /*  w = LyXStringWidth(lyxstyle.Style(parameters->textclass, row->par->GetLayout())->font, */ 
-      /*                        lyxstyle.Style(parameters->textclass, row->par->GetLayout())->leftmargin); */
    }
    else
      w = LeftMargin(row);
    
-   int main_body = BeginningOfMainBody(row->par);
-   LyXLayout *layout = lyxstyle.Style(parameters->textclass,
+   LyXLayout const & layout = textclasslist.Style(parameters->textclass,
                                      row->par->GetLayout());
-   i = row->pos;
-   while (i<= last) {
+   LyXParagraph::size_type main_body = 
+          BeginningOfMainBody(row->par);
+   LyXParagraph::size_type i = row->pos;
+   while (i <= last) {
       w += SingleWidth(row->par, i);
-      i++;
+      ++i;
       if (i == main_body) {
-        w += GetFont(row->par, -2).stringWidth(layout->labelsep);
+        w += GetFont(row->par, -2).stringWidth(layout.labelsep);
         if (row->par->IsLineSeparator(i - 1))
-          w-= SingleWidth(row->par, i - 1);
+          w -= SingleWidth(row->par, i - 1);
         if (w < left_margin)
           w = left_margin;
       }
    }
    
-   fill = paperwidth - w - RightMargin(row);
+   fill = paper_width - w - RightMargin(row);
    return fill;
 }
 
 
 /* returns the minimum space a manual label needs on the screen in pixel */ 
-int LyXText::LabelFill(Row *row)
+int LyXText::LabelFill(Row * row)
 {
-   int w,i, last;
-   int fill=0;
-   
-   last = BeginningOfMainBody(row->par) - 1;
+
+   LyXParagraph::size_type last = BeginningOfMainBody(row->par) - 1;
    /* -1 because a label ends either with a space that is in the label, 
     * or with the beginning of a footnote that is outside the label. */ 
 
@@ -786,19 +784,20 @@ int LyXText::LabelFill(Row *row)
    // 0 and this causes a crash. This fix seems to work correctly, but I
    // bet the real error is elsewhere.  The bug is triggered when you have an 
    // open footnote in a paragraph environment with a manual label. (Asger)
-   if (last<0) last = 0;
+   if (last < 0) last = 0;
 
    if (row->par->IsLineSeparator(last))    /* a sepearator at this end 
                                        * does not count */
      last--;
    
-   w = 0;
-   i = row->pos;
+   int w = 0;
+   int i = row->pos;
    while (i<= last) {
       w += SingleWidth(row->par, i);
       i++;
    }
    
+   int fill = 0;
    if (!row->par->labelwidthstring.empty()) {
       fill = GetFont(row->par, -2).stringWidth(row->par->labelwidthstring) - w;
    }
@@ -814,11 +813,9 @@ int LyXText::LabelFill(Row *row)
 * on the very last column doesnt count */ 
 int LyXText::NumberOfSeparators(Row *row)
 {
-   int n,p,last;
-   
-   last = RowLast(row);
-   n = 0;
-   p = row->pos;
+   int last = RowLast(row);
+   int n = 0;
+   int p = row->pos;
    int main_body = BeginningOfMainBody(row->par);
    if (p < main_body)
      p = main_body;
@@ -834,23 +831,21 @@ int LyXText::NumberOfSeparators(Row *row)
 /* returns the number of hfills in the specified row. The LyX-Hfill is
 * a LaTeX \hfill so that the hfills at the beginning and at the end were 
 * ignored. This is *MUCH* more usefull than not to ignore!  */
-int LyXText::NumberOfHfills(Row *row)
+int LyXText::NumberOfHfills(Row * row)
 {
-   int n,p,last, first;
-   
-   last = RowLast(row);
-   first = row->pos;
+   int last = RowLast(row);
+   int first = row->pos;
    if (first) {                               /* hfill *DO* count at the beginning 
                                        * of paragraphs! */
      while(first <= last && row->par->IsHfill(first))
        first++;
    }
 
-   n = 0;
    int main_body = BeginningOfMainBody(row->par);
    if (first < main_body)
      first = main_body;
-   for (p = first; p <= last; p++) {    /* last, because the end is ignored!  */
+   int n = 0;
+   for (int p = first; p <= last; p++) { // last, because the end is ignored!
       if (row->par->IsHfill(p)) {
         n++;
       }
@@ -860,27 +855,25 @@ int LyXText::NumberOfHfills(Row *row)
 
 
 /* like NumberOfHfills, but only those in the manual label! */ 
-int LyXText::NumberOfLabelHfills(Row *row)
+int LyXText::NumberOfLabelHfills(Row * row)
 {
-   int n,p,last, first;
-   
-   last = RowLast(row);
-   first = row->pos;
+   LyXParagraph::size_type last = RowLast(row);
+   LyXParagraph::size_type first = row->pos;
    if (first) {                               /* hfill *DO* count at the beginning 
                                        * of paragraphs! */
       while(first < last && row->par->IsHfill(first))
        first++;
    }
-
-   n = 0;
-   int main_body = BeginningOfMainBody(row->par);
-   
+   LyXParagraph::size_type main_body = 
+          BeginningOfMainBody(row->par);
    if (last > main_body)
      last = main_body;
-   
-   for (p = first; p < last; p++) {    /* last, because the end is ignored!  */
+
+   int n = 0;
+   for (LyXParagraph::size_type p = first;
+       p < last; ++p) {  // last, because the end is ignored!
       if (row->par->IsHfill(p)) {
-        n++;
+        ++n;
       }
    }
    return n;
@@ -888,8 +881,9 @@ int LyXText::NumberOfLabelHfills(Row *row)
 
 
 /* returns true, if a expansion is needed.
- * Rules are given by LaTeX */ 
-bool LyXText::HfillExpansion(Row *row_ptr, int pos)
+ * Rules are given by LaTeX */
+bool LyXText::HfillExpansion(Row * row_ptr,
+                            LyXParagraph::size_type pos)
 {
    /* by the way, is it a hfill? */ 
    if (!row_ptr->par->IsHfill(pos))
@@ -905,15 +899,14 @@ bool LyXText::HfillExpansion(Row *row_ptr, int pos)
      return true;
    
    /* in some labels  it does not count */ 
-   if ( lyxstyle.Style(parameters->textclass, row_ptr->par->GetLayout())->margintype != MARGIN_MANUAL &&
+   if ( textclasslist.Style(parameters->textclass, row_ptr->par->GetLayout()).margintype != MARGIN_MANUAL &&
        pos < BeginningOfMainBody(row_ptr->par))
      return false; 
    
    /* if there is anything between the first char of the row and
     * the sepcified position that is not a newline and not a hfill,
     * the hfill will count, otherwise not */ 
-   
-   int i = row_ptr->pos;
+   LyXParagraph::size_type i = row_ptr->pos;
    while (i < pos && (row_ptr->par->IsNewline(i)
                      || row_ptr->par->IsHfill(i)))
      i++;
@@ -922,16 +915,15 @@ bool LyXText::HfillExpansion(Row *row_ptr, int pos)
 }
 
 
-void LyXText::SetHeightOfRow(Row *row_ptr)
+void LyXText::SetHeightOfRow(Row * row_ptr)
 {
     /* get the maximum ascent and the maximum descent */
    int asc, maxasc, desc, maxdesc, pos_end, pos, labeladdon;
    float layoutasc = 0;
    float layoutdesc = 0;
    float tmptop = 0;
-   LyXParagraph *par, *firstpar;
    LyXFont tmpfont;
-   Inset *tmpinset;
+   Inset * tmpinset;
 
    /* this must not happen before the currentrow for clear reasons.
       so the trick is just to set the current row onto this row */
@@ -946,10 +938,10 @@ void LyXText::SetHeightOfRow(Row *row_ptr)
    /* Correction: only the fontsize count. The other properties
       are taken from the layoutfont. Nicer on the screen :) */
    
-   par = row_ptr->par->LastPhysicalPar();
-   firstpar = row_ptr->par->FirstPhysicalPar();
+   LyXParagraph * par = row_ptr->par->LastPhysicalPar();
+   LyXParagraph * firstpar = row_ptr->par->FirstPhysicalPar();
    
-   LyXLayout *layout = lyxstyle.Style(parameters->textclass, firstpar->GetLayout());
+   LyXLayout const & layout = textclasslist.Style(parameters->textclass, firstpar->GetLayout());
    
    LyXFont font = GetFont(par, par->Last()-1);
    LyXFont::FONT_SIZE size = font.size();
@@ -959,10 +951,10 @@ void LyXText::SetHeightOfRow(Row *row_ptr)
    LyXFont labelfont = GetFont(par, -2);
 
    maxasc = int(font.maxAscent() *
-                  layout->spacing.getValue() *
+                  layout.spacing.getValue() *
                   parameters->spacing.getValue());
    maxdesc = int(font.maxDescent() *
-                   layout->spacing.getValue() *
+                   layout.spacing.getValue() *
                    parameters->spacing.getValue());
 
    pos_end = RowLast(row_ptr);
@@ -971,7 +963,7 @@ void LyXText::SetHeightOfRow(Row *row_ptr)
 
    // Check if any insets are larger
    for (pos = row_ptr->pos; pos <= pos_end; pos++) {
-      if (row_ptr->par->GetChar(pos) == LYX_META_INSET) {
+      if (row_ptr->par->GetChar(pos) == LyXParagraph::META_INSET) {
         tmpfont = GetFont(row_ptr->par, pos);
          tmpinset = row_ptr->par->GetInset(pos);
          if (tmpinset) {
@@ -1004,7 +996,7 @@ void LyXText::SetHeightOfRow(Row *row_ptr)
    if (row_ptr->par->table){
      // stretch the rows a bit
       maxasc += 1;
-      maxdesc +=1;
+      maxdesc += 1;
    }
    /* table stuff -- end*/
 
@@ -1019,14 +1011,14 @@ void LyXText::SetHeightOfRow(Row *row_ptr)
        && row_ptr->par == firstpar) {
       
       /* some parksips VERY EASY IMPLEMENTATION */ 
-      if (parameters->paragraph_separation == LYX_PARSEP_SKIP) {
-        if (layout->isParagraph()
+      if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) {
+        if (layout.isParagraph()
             && firstpar->GetDepth() == 0
             && firstpar->Previous())
            maxasc += parameters->getDefSkip().inPixels();
         else if (firstpar->Previous()
-                 && lyxstyle.Style(parameters->textclass,
-                          firstpar->Previous()->GetLayout())->isParagraph()
+                 && textclasslist.Style(parameters->textclass,
+                          firstpar->Previous()->GetLayout()).isParagraph()
                  && firstpar->Previous()->GetDepth() == 0)
           // is it right to use defskip here too? (AS)
           maxasc += parameters->getDefSkip().inPixels();
@@ -1051,31 +1043,31 @@ void LyXText::SetHeightOfRow(Row *row_ptr)
       
       /*  this is special code for the chapter, since the label of this
        * layout is printed in an extra row */ 
-      if (layout->labeltype == LABEL_COUNTER_CHAPTER
-         && parameters->secnumdepth>=0) {
+      if (layout.labeltype == LABEL_COUNTER_CHAPTER
+         && parameters->secnumdepth>= 0) {
              labeladdon = int(labelfont.maxDescent() *
-                                 layout->spacing.getValue() *
+                                 layout.spacing.getValue() *
                                  parameters->spacing.getValue())
                      + int(labelfont.maxAscent() *
-                              layout->spacing.getValue() *
+                              layout.spacing.getValue() *
                               parameters->spacing.getValue());
       }
       
       /* special code for the top label */ 
-      if ((layout->labeltype == LABEL_TOP_ENVIRONMENT
-          || layout->labeltype == LABEL_BIBLIO
-          || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
+      if ((layout.labeltype == LABEL_TOP_ENVIRONMENT
+          || layout.labeltype == LABEL_BIBLIO
+          || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
          && row_ptr->par->IsFirstInSequence()
          && !row_ptr->par->GetLabestring().empty()) {
         labeladdon = int(
                 (labelfont.maxAscent() *
-                 layout->spacing.getValue() *
+                 layout.spacing.getValue() *
                  parameters->spacing.getValue())
                 +(labelfont.maxDescent() *
-                  layout->spacing.getValue() *
+                  layout.spacing.getValue() *
                   parameters->spacing.getValue())
-                + layout->topsep * DefaultHeight()
-                + layout->labelbottomsep *  DefaultHeight());
+                + layout.topsep * DefaultHeight()
+                + layout.labelbottomsep *  DefaultHeight());
       }
    
       /* and now the layout spaces, for example before and after a section, 
@@ -1089,19 +1081,19 @@ void LyXText::SetHeightOfRow(Row *row_ptr)
             && prev->GetDepth() == firstpar->GetDepth()
             && prev->GetLabelWidthString() == firstpar->GetLabelWidthString())
           {
-             layoutasc = (layout->itemsep * DefaultHeight());
+             layoutasc = (layout.itemsep * DefaultHeight());
           }
         else if (row_ptr->previous) {
-           tmptop = layout->topsep;
+           tmptop = layout.topsep;
            
            if (row_ptr->previous->par->GetDepth() >= row_ptr->par->GetDepth())
-              tmptop-=lyxstyle.Style(parameters->textclass, row_ptr->previous->par->GetLayout())->bottomsep;
+              tmptop-= textclasslist.Style(parameters->textclass, row_ptr->previous->par->GetLayout()).bottomsep;
            
            if (tmptop > 0)
               layoutasc = (tmptop * DefaultHeight());
         }
         else if (row_ptr->par->line_top){
-           tmptop = layout->topsep;
+           tmptop = layout.topsep;
            
            if (tmptop > 0)
               layoutasc = (tmptop * DefaultHeight());
@@ -1109,8 +1101,8 @@ void LyXText::SetHeightOfRow(Row *row_ptr)
         
         prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth()-1);
         if (prev)  {
-           maxasc += int(lyxstyle.Style(parameters->textclass,
-                                        prev->GetLayout())->parsep * DefaultHeight());
+           maxasc += int(textclasslist.Style(parameters->textclass,
+                                        prev->GetLayout()).parsep * DefaultHeight());
         }
         else {
                if (firstpar->Previous()
@@ -1119,7 +1111,7 @@ void LyXText::SetHeightOfRow(Row *row_ptr)
                   /* avoid parsep */ 
                }
            else if (firstpar->Previous()){
-              maxasc += int(layout->parsep * DefaultHeight());
+              maxasc += int(layout.parsep * DefaultHeight());
            }
         }
       }
@@ -1155,12 +1147,12 @@ void LyXText::SetHeightOfRow(Row *row_ptr)
             float  unusual = 0;
             
             if (comparepar->GetDepth() > nextpar->GetDepth()) {
-               usual = (lyxstyle.Style(parameters->textclass, comparepar->GetLayout())->bottomsep * DefaultHeight());
+               usual = (textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
                comparepar = comparepar->DepthHook(nextpar->GetDepth());
-               if (comparepar->GetLayout()!=nextpar->GetLayout()
+               if (comparepar->GetLayout()!= nextpar->GetLayout()
                    || nextpar->GetLabelWidthString() != 
                        comparepar->GetLabelWidthString())
-                 unusual = (lyxstyle.Style(parameters->textclass, comparepar->GetLayout())->bottomsep * DefaultHeight());
+                 unusual = (textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
                
                if (unusual > usual)
                  layoutdesc = unusual;
@@ -1170,9 +1162,9 @@ void LyXText::SetHeightOfRow(Row *row_ptr)
             else if (comparepar->GetDepth() ==  nextpar->GetDepth()) {
                
                if (comparepar->GetLayout()!= nextpar->GetLayout()
-                   || nextpar->GetLabelWidthString() !=
+                   || nextpar->GetLabelWidthString() != 
                        comparepar->GetLabelWidthString())
-                 layoutdesc = int(lyxstyle.Style(parameters->textclass, comparepar->GetLayout())->bottomsep * DefaultHeight());
+                 layoutdesc = int(textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
             }
          }
        }
@@ -1191,8 +1183,8 @@ void LyXText::SetHeightOfRow(Row *row_ptr)
    /* calculate the new height of the text */ 
    height -= row_ptr->height;
    
-   row_ptr->height=maxasc+maxdesc+labeladdon;
-   row_ptr->baseline=maxasc+labeladdon;
+   row_ptr->height= maxasc+maxdesc+labeladdon;
+   row_ptr->baseline= maxasc+labeladdon;
    
    height += row_ptr->height;
 }
@@ -1200,24 +1192,19 @@ void LyXText::SetHeightOfRow(Row *row_ptr)
 
 /* Appends the implicit specified paragraph behind the specified row,
  * start at the implicit given position */
-void LyXText::AppendParagraph(Row *row)
+void LyXText::AppendParagraph(Row * row)
 {
-   int z;
-   Row *tmprow;
    bool not_ready = true;
    
-   // Get the width of the row
-   z = row->pos;
-
    // The last character position of a paragraph is an invariant so we can 
    // safely get it here. (Asger)
    int lastposition = row->par->Last();
 
    do {
       // Get the next breakpoint
-      z = NextBreakPoint(row, paperwidth);
+      int z = NextBreakPoint(row, paperwidth);
       
-      tmprow = row;
+      Row * tmprow = row;
 
       // Insert the new row
       if (z < lastposition) {
@@ -1237,20 +1224,15 @@ void LyXText::AppendParagraph(Row *row)
 }
 
 
-void LyXText::BreakAgain(Row *row)
+void LyXText::BreakAgain(Row * row)
 {
-   int z;
-   char not_ready;
-   z = row->pos;
-   Row *tmprow, *tmprow2;
-   
-   not_ready = 1;
+   bool not_ready = true;
    
    do  {
       /* get the next breakpoint */
-      z = NextBreakPoint(row, paperwidth);
-      
-      tmprow = row;
+       LyXParagraph::size_type z = 
+               NextBreakPoint(row, paperwidth);
+      Row * tmprow = row;
       
       if (z < row->par->Last() ) {
         if (!row->next || (row->next && row->next->par != row->par)) {
@@ -1259,21 +1241,19 @@ void LyXText::BreakAgain(Row *row)
            InsertRow(row, row->par, z);
            row = row->next;
            row->height = 0;
-        }
-        else  {
-           row=row->next;
+        } else  {
+           row = row->next;
            z++;
            if (row->pos == z)
-             not_ready = 0;           /* the rest will not change  */
+                   not_ready = false;     // the rest will not change
            else {
               row->pos = z;
            }
         }
-      }
-      else {
+      } else {
         /* if there are some rows too much, delete them */
         /* only if you broke the whole paragraph! */ 
-        tmprow2 = row;
+        Row * tmprow2 = row;
         while (tmprow2->next && tmprow2->next->par == row->par) {
            tmprow2 = tmprow2->next;
         }
@@ -1281,7 +1261,7 @@ void LyXText::BreakAgain(Row *row)
            tmprow2 = tmprow2->previous;
            RemoveRow(tmprow2->next);
         }
-        not_ready = 0;
+        not_ready = false;
       }
        
       /* set the dimensions of the row */ 
@@ -1292,19 +1272,11 @@ void LyXText::BreakAgain(Row *row)
 
 
 /* this is just a little changed version of break again */ 
-void LyXText::BreakAgainOneRow(Row *row)
+void LyXText::BreakAgainOneRow(Row * row)
 {
-   int z;
-   char not_ready;
-   z = row->pos;
-   Row *tmprow, *tmprow2;
-   
-   not_ready = 1;
-   
    /* get the next breakpoint */
-   z = NextBreakPoint(row, paperwidth);
-   
-   tmprow = row;
+   LyXParagraph::size_type z = NextBreakPoint(row, paperwidth);
+   Row * tmprow = row;
    
    if (z < row->par->Last() ) {
       if (!row->next || (row->next && row->next->par != row->par)) {
@@ -1315,19 +1287,16 @@ void LyXText::BreakAgainOneRow(Row *row)
         row->height = 0;
       }
       else  {
-        row=row->next;
+        row= row->next;
         z++;
-        if (row->pos == z)
-          not_ready = 0;              /* the rest will not change  */
-        else {
+        if (row->pos != z)
            row->pos = z;
-        }
       }
    }
    else {
       /* if there are some rows too much, delete them */
       /* only if you broke the whole paragraph! */ 
-      tmprow2 = row;
+      Row * tmprow2 = row;
       while (tmprow2->next && tmprow2->next->par == row->par) {
         tmprow2 = tmprow2->next;
       }
@@ -1335,7 +1304,6 @@ void LyXText::BreakAgainOneRow(Row *row)
         tmprow2 = tmprow2->previous;
         RemoveRow(tmprow2->next);
       }
-      not_ready = 0;
    }
    
    /* set the dimensions of the row */ 
@@ -1346,13 +1314,13 @@ void LyXText::BreakAgainOneRow(Row *row)
 
 void LyXText::BreakParagraph(char keep_layout)
 {
-   LyXLayout *layout = lyxstyle.Style(parameters->textclass,
+   LyXLayout const & layout = textclasslist.Style(parameters->textclass,
                                      cursor.par->GetLayout());
    
    /* table stuff -- begin*/
    if (cursor.par->table) {
        // breaking of tables is only allowed at the beginning or the end */
-       if (cursor.pos && cursor.pos < cursor.par->last &&
+       if (cursor.pos && cursor.pos < cursor.par->size() &&
            !cursor.par->table->ShouldBeVeryLastCell(NumberOfCell(cursor.par, cursor.pos)))
            return; /* no breaking of tables allowed */ 
    }
@@ -1361,7 +1329,7 @@ void LyXText::BreakParagraph(char keep_layout)
    /* this is only allowed, if the current paragraph is not empty or caption*/ 
    if ((cursor.par->Last() <= 0 && !cursor.par->IsDummy())
        && 
-       layout->labeltype!=LABEL_SENSITIVE)
+       layout.labeltype!= LABEL_SENSITIVE)
      return;
 
    SetUndo(Undo::INSERT, 
@@ -1372,7 +1340,7 @@ void LyXText::BreakParagraph(char keep_layout)
    if (cursor.par->table) {
        int cell = NumberOfCell(cursor.par, cursor.pos);
        if (cursor.par->table->ShouldBeVeryLastCell(cell))
-           SetCursor(cursor.par,cursor.par->last);
+           SetCursor(cursor.par, cursor.par->text.size());
    }
    /* table stuff -- end*/
    /* please break alway behind a space */ 
@@ -1384,7 +1352,7 @@ void LyXText::BreakParagraph(char keep_layout)
    if (keep_layout)
      keep_layout = 2;
    else        
-     keep_layout = layout->isEnvironment();
+     keep_layout = layout.isEnvironment();
    cursor.par->BreakParagraph(cursor.pos, keep_layout);
 
    /* table stuff -- begin*/
@@ -1398,7 +1366,7 @@ void LyXText::BreakParagraph(char keep_layout)
    /* table stuff -- end*/
 
    /* well this is the caption hack since one caption is really enough */
-   if (layout->labeltype == LABEL_SENSITIVE){
+   if (layout.labeltype == LABEL_SENSITIVE){
      if (!cursor.pos)
        cursor.par->SetLayout(0); /* set the new paragraph to standard-layout */
      else
@@ -1420,7 +1388,7 @@ void LyXText::BreakParagraph(char keep_layout)
    refresh_y = cursor.y - cursor.row->baseline;
    
    /* Do not forget the special right address boxes */
-   if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
+   if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
       while (refresh_row->previous &&
             refresh_row->previous->par == refresh_row->par) {
                refresh_row = refresh_row->previous;
@@ -1458,10 +1426,10 @@ void LyXText::BreakParagraph(char keep_layout)
 
 void LyXText::OpenFootnote()
 {
-   LyXParagraph *par, *endpar,*tmppar;
-   Row *row;
+   LyXParagraph * endpar,* tmppar;
+   Row * row;
    
-   par = cursor.par->ParFromPos(cursor.pos);
+   LyXParagraph * par = cursor.par->ParFromPos(cursor.pos);
    
    /* if there is no footnote in this paragraph, just return. */ 
    if (!par->next
@@ -1471,9 +1439,10 @@ void LyXText::OpenFootnote()
    /* ok, move the cursor right before the footnote */ 
    
    /* just a little faster than using CursorRight() */
-   for (cursor.pos=0; cursor.par->ParFromPos(cursor.pos)!=par; cursor.pos++);
+   for (cursor.pos= 0; cursor.par->ParFromPos(cursor.pos)!= par; cursor.pos++);
    /* now the cursor is at the beginning of the physical par */
-   SetCursor(cursor.par, cursor.pos + cursor.par->ParFromPos(cursor.pos)->last);
+   SetCursor(cursor.par,
+            cursor.pos + cursor.par->ParFromPos(cursor.pos)->text.size());
    
    /* the cursor must be exactly before the footnote */ 
    par = cursor.par->ParFromPos(cursor.pos);
@@ -1510,24 +1479,21 @@ void LyXText::OpenFootnote()
 
 void LyXText::TableFeatures(int feature, string val)
 {
-    int
-        actCell;
-    
     if (!cursor.par->table)
         return; /* this should never happen */
   
-    actCell = NumberOfCell(cursor.par, cursor.pos);
+    int actCell = NumberOfCell(cursor.par, cursor.pos);
     SetUndo(Undo::FINISH, 
             cursor.par->ParFromPos(cursor.pos)->previous, 
             cursor.par->ParFromPos(cursor.pos)->next); 
 
     switch (feature){
       case LyXTable::SET_PWIDTH:
-          cursor.par->table->SetPWidth(actCell,val);
+          cursor.par->table->SetPWidth(actCell, val);
           break;
       case LyXTable::SET_SPECIAL_COLUMN:
       case LyXTable::SET_SPECIAL_MULTI:
-          cursor.par->table->SetAlignSpecial(actCell,val,feature);
+          cursor.par->table->SetAlignSpecial(actCell, val, feature);
           break;
       default:
           break;
@@ -1538,39 +1504,37 @@ void LyXText::TableFeatures(int feature, string val)
 
 void LyXText::TableFeatures(int feature)
 {
-    int
-        setLines = 0,
-        setAlign = LYX_ALIGN_LEFT,
-        lineSet,
-        actCell;
-    bool
-        what;
+       int setLines = 0;
+       int setAlign = LYX_ALIGN_LEFT;
+       int lineSet;
+       bool what;
     
     if (!cursor.par->table)
         return; /* this should never happen */
   
-    actCell = NumberOfCell(cursor.par, cursor.pos);
+    int actCell = NumberOfCell(cursor.par, cursor.pos);
     SetUndo(Undo::FINISH, 
             cursor.par->ParFromPos(cursor.pos)->previous, 
             cursor.par->ParFromPos(cursor.pos)->next); 
 
     switch (feature){
       case LyXTable::ALIGN_LEFT:
-          setAlign=LYX_ALIGN_LEFT;
+          setAlign= LYX_ALIGN_LEFT;
           break;
       case LyXTable::ALIGN_RIGHT:
-          setAlign=LYX_ALIGN_RIGHT;
+          setAlign= LYX_ALIGN_RIGHT;
           break;
       case LyXTable::ALIGN_CENTER:
-          setAlign=LYX_ALIGN_CENTER;
+          setAlign= LYX_ALIGN_CENTER;
           break;
       default:
           break;
     }
     switch (feature){
       case LyXTable::APPEND_ROW: {
-         int pos = cursor.pos;
-          /* move to the next row */
+             LyXParagraph::size_type pos = cursor.pos;
+
+             /* move to the next row */
           int cell_org = actCell;
           int cell = cell_org;
 
@@ -1611,9 +1575,8 @@ void LyXText::TableFeatures(int feature)
                
           /* insert the new cells */ 
           int number = cursor.par->table->NumberOfCellsInRow(cell_org);
-          int i;
-          for (i=0; i<number; i++)
-              cursor.par->InsertChar(pos, LYX_META_NEWLINE);
+          for (int i = 0; i < number; ++i)
+              cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
                
           /* append the row into the table */
           cursor.par->table->AppendRow(cell_org);
@@ -1621,7 +1584,7 @@ void LyXText::TableFeatures(int feature)
           return;
       }
       case LyXTable::APPEND_CONT_ROW: {
-          int pos = cursor.pos;
+             LyXParagraph::size_type pos = cursor.pos;
           /* move to the next row */
           int cell_org = actCell;
           int cell = cell_org;
@@ -1648,34 +1611,34 @@ void LyXText::TableFeatures(int feature)
           /* insert the new cells */ 
           int number = cursor.par->table->NumberOfCellsInRow(cell_org);
           int i;
-          for (i=0; i<number; i++)
-              cursor.par->InsertChar(pos, LYX_META_NEWLINE);
+          for (i= 0; i<number; i++)
+              cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
                
           /* append the row into the table */
           cursor.par->table->AppendContRow(cell_org);
           RedoParagraph();
           return;
       }
-      case LyXTable::APPEND_COLUMN: { 
-          int pos = 0;
+      case LyXTable::APPEND_COLUMN: {
+             LyXParagraph::size_type pos = 0;
           int cell_org = actCell;
           int cell = 0;
           do{
               if (pos && (cursor.par->IsNewline(pos-1))){
                   if (cursor.par->table->AppendCellAfterCell(cell_org, cell)){
-                      cursor.par->InsertChar(pos, LYX_META_NEWLINE);
-                      if (pos<=cursor.pos)
+                      cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
+                      if (pos <= cursor.pos)
                           cursor.pos++;
-                      pos++;
+                      ++pos;
                   }
-                  cell++;
+                  ++cell;
               }
-              pos++;
-          } while (pos<= cursor.par->Last());
+              ++pos;
+          } while (pos <= cursor.par->Last());
           /* remember that the very last cell doesn't end with a newline.
              This saves one byte memory per table ;-) */ 
           if (cursor.par->table->AppendCellAfterCell(cell_org, cell))
-              cursor.par->InsertChar(cursor.par->Last(), LYX_META_NEWLINE);
+              cursor.par->InsertChar(cursor.par->Last(), LyXParagraph::META_NEWLINE);
                
           /* append the column into the table */ 
           cursor.par->table->AppendColumn(cell_org);
@@ -1684,18 +1647,18 @@ void LyXText::TableFeatures(int feature)
           return;
       }
       case LyXTable::DELETE_ROW:
-          if (current_view->currentBuffer()->the_locking_inset)
-              UnlockInset(current_view->currentBuffer()->the_locking_inset);
+          if (current_view->buffer()->the_locking_inset)
+              UnlockInset(current_view->buffer()->the_locking_inset);
           RemoveTableRow(&cursor);
           RedoParagraph();
           return;
        
       case LyXTable::DELETE_COLUMN: {
-          int pos = 0;
+             LyXParagraph::size_type pos = 0;
           int cell_org = actCell;
           int cell = 0;
-          if (current_view->currentBuffer()->the_locking_inset)
-              UnlockInset(current_view->currentBuffer()->the_locking_inset);
+          if (current_view->buffer()->the_locking_inset)
+              UnlockInset(current_view->buffer()->the_locking_inset);
           do {
               if (!pos || (cursor.par->IsNewline(pos-1))){
                   if (cursor.par->table->DeleteCellIfColumnIsDeleted(cell, cell_org)){
@@ -1706,12 +1669,12 @@ void LyXText::TableFeatures(int feature)
                           cursor.par->Erase(pos);
                       else 
                           cursor.par->Erase(pos - 1); // the missing newline at the end of a table
-                      pos--; // because of pos++ below
+                      --pos; // because of pos++ below
                   }   
-                  cell++;
+                  ++cell;
               }
-              pos++;
-          } while (pos<= cursor.par->Last());
+              ++pos;
+          } while (pos <= cursor.par->Last());
                
           /* delete the column from the table */ 
           cursor.par->table->DeleteColumn(cell_org);
@@ -1724,12 +1687,13 @@ void LyXText::TableFeatures(int feature)
       case LyXTable::TOGGLE_LINE_TOP:
           lineSet = !cursor.par->table->TopLine(actCell);
           if (!selection){
-              cursor.par->table->SetTopLine(actCell,lineSet);
+              cursor.par->table->SetTopLine(actCell, lineSet);
           } else {
-              int i,n=-1,m=-2;
-              for (i=sel_start_cursor.pos; i<=sel_end_cursor.pos; i++){
-                  if ((n=NumberOfCell(sel_start_cursor.par,i)) != m) {
-                      cursor.par->table->SetTopLine(n,lineSet);
+                 LyXParagraph::size_type i;
+                 int n = -1, m = -2;
+              for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
+                  if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
+                      cursor.par->table->SetTopLine(n, lineSet);
                       m = n;
                   }
               }
@@ -1740,12 +1704,13 @@ void LyXText::TableFeatures(int feature)
       case LyXTable::TOGGLE_LINE_BOTTOM:
           lineSet = !cursor.par->table->BottomLine(actCell);
           if (!selection){
-              cursor.par->table->SetBottomLine(actCell,lineSet);
+              cursor.par->table->SetBottomLine(actCell, lineSet);
           } else {
-              int i,n=-1,m=-2;
-              for (i=sel_start_cursor.pos; i<=sel_end_cursor.pos; i++){
-                  if ((n=NumberOfCell(sel_start_cursor.par,i)) != m) {
-                      cursor.par->table->SetBottomLine(n,lineSet);
+                 LyXParagraph::size_type i;
+                 int n = -1, m = -2;
+              for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
+                  if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
+                      cursor.par->table->SetBottomLine(n, lineSet);
                       m = n;
                   }
               }
@@ -1756,12 +1721,13 @@ void LyXText::TableFeatures(int feature)
       case LyXTable::TOGGLE_LINE_LEFT:
           lineSet = !cursor.par->table->LeftLine(actCell);
           if (!selection){
-              cursor.par->table->SetLeftLine(actCell,lineSet);
+              cursor.par->table->SetLeftLine(actCell, lineSet);
           } else {
-              int i,n=-1,m=-2;
-              for (i=sel_start_cursor.pos; i<=sel_end_cursor.pos; i++){
-                  if ((n=NumberOfCell(sel_start_cursor.par,i)) != m) {
-                      cursor.par->table->SetLeftLine(n,lineSet);
+                 LyXParagraph::size_type i;
+                 int n = -1, m = -2;
+              for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
+                  if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
+                      cursor.par->table->SetLeftLine(n, lineSet);
                       m = n;
                   }
               }
@@ -1772,12 +1738,13 @@ void LyXText::TableFeatures(int feature)
       case LyXTable::TOGGLE_LINE_RIGHT:
           lineSet = !cursor.par->table->RightLine(actCell);
           if (!selection){
-              cursor.par->table->SetRightLine(actCell,lineSet);
+              cursor.par->table->SetRightLine(actCell, lineSet);
           } else {
-              int i,n=-1,m=-2;
-              for (i=sel_start_cursor.pos; i<=sel_end_cursor.pos; i++){
-                  if ((n=NumberOfCell(sel_start_cursor.par,i)) != m) {
-                      cursor.par->table->SetRightLine(n,lineSet);
+                 LyXParagraph::size_type i;
+                 int n = -1, m = -2;
+              for (i= sel_start_cursor.pos; i<= sel_end_cursor.pos; i++){
+                  if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
+                      cursor.par->table->SetRightLine(n, lineSet);
                       m = n;
                   }
               }
@@ -1789,12 +1756,13 @@ void LyXText::TableFeatures(int feature)
       case LyXTable::ALIGN_RIGHT:
       case LyXTable::ALIGN_CENTER:
           if (!selection){
-              cursor.par->table->SetAlignment(actCell,setAlign);
+              cursor.par->table->SetAlignment(actCell, setAlign);
           } else {
-              int i,n=-1,m=-2;
-              for (i=sel_start_cursor.pos; i<=sel_end_cursor.pos; i++){
-                  if ((n=NumberOfCell(sel_start_cursor.par,i)) != m) {
-                      cursor.par->table->SetAlignment(n,setAlign);
+                 LyXParagraph::size_type i;
+              int n = -1, m = -2;
+              for (i= sel_start_cursor.pos; i<= sel_end_cursor.pos; i++){
+                  if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
+                      cursor.par->table->SetAlignment(n, setAlign);
                       m = n;
                   }
               }
@@ -1809,8 +1777,8 @@ void LyXText::TableFeatures(int feature)
           // temporary: Should put table in simple_cut_buffer (with before and after
           // dummy-paragraph !! 
           // not necessar anymore with UNDO :)
-          int i;
-          for (i = cursor.par->last-1; i>=0; i--)
+          for (LyXParagraph::size_type i = 
+                      cursor.par->text.size() - 1; i >= 0; --i)
              cursor.par->Erase(i);
           RedoParagraph();
           return;
@@ -1826,11 +1794,11 @@ void LyXText::TableFeatures(int feature)
 
           if (multicol){
              int newlines = cursor.par->table->UnsetMultiColumn(actCell);
-             int pos = cursor.pos;
-             while (pos<cursor.par->Last() && !cursor.par->IsNewline(pos))
+             LyXParagraph::size_type pos = cursor.pos;
+             while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
                   pos++;
              for (;newlines;newlines--)
-                  cursor.par->InsertChar(pos, LYX_META_NEWLINE);
+                  cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
              RedoParagraph();
              return;
           }
@@ -1845,15 +1813,16 @@ void LyXText::TableFeatures(int feature)
              }
              else {
                   if (sel_start_cursor.row == sel_end_cursor.row){
-                      int i;
+                      LyXParagraph::size_type i;
                       number = 1;
-                      for (i=sel_start_cursor.pos; i<sel_end_cursor.pos; i++){
+                      for (i = sel_start_cursor.pos;
+                          i < sel_end_cursor.pos; ++i){
                           if (sel_start_cursor.par->IsNewline(i)){
                               sel_start_cursor.par->Erase(i);
                               // check for double-blanks
                               if ((i && !sel_start_cursor.par->IsLineSeparator(i-1))
                                   &&
-                                  (i<sel_start_cursor.par->Last() 
+                                  (i < sel_start_cursor.par->Last() 
                                    && !sel_start_cursor.par->IsLineSeparator(i)))
                                   sel_start_cursor.par->InsertChar(i, ' ');
                               else {
@@ -1888,10 +1857,11 @@ void LyXText::TableFeatures(int feature)
                                                           cursor.pos),
                                              setLines);
           } else {
-              int i,n=-1,m=-2;
-              for (i=sel_start_cursor.pos; i<=sel_end_cursor.pos; i++){
-                  if ((n=NumberOfCell(sel_start_cursor.par,i)) != m) {
-                      cursor.par->table->SetAllLines(n,setLines);
+                 LyXParagraph::size_type i;
+                 int n = -1, m = -2;
+              for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
+                  if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
+                      cursor.par->table->SetAllLines(n, setLines);
                       m = n;
                   }
               }
@@ -1912,12 +1882,13 @@ void LyXText::TableFeatures(int feature)
           return;
       case LyXTable::SET_ROTATE_CELL:
           if (!selection){
-              cursor.par->table->SetRotateCell(actCell,true);
+              cursor.par->table->SetRotateCell(actCell, true);
           } else {
-              int i,n=-1,m=-2;
-              for (i=sel_start_cursor.pos; i<=sel_end_cursor.pos; i++){
-                  if ((n=NumberOfCell(sel_start_cursor.par,i)) != m) {
-                      cursor.par->table->SetRotateCell(n,true);
+                 LyXParagraph::size_type i;
+                 int n = -1, m = -2;
+              for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
+                  if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
+                      cursor.par->table->SetRotateCell(n, true);
                       m = n;
                   }
               }
@@ -1925,12 +1896,13 @@ void LyXText::TableFeatures(int feature)
           return;
       case LyXTable::UNSET_ROTATE_CELL:
           if (!selection){
-              cursor.par->table->SetRotateCell(actCell,false);
+              cursor.par->table->SetRotateCell(actCell, false);
           } else {
-              int i,n=-1,m=-2;
-              for (i=sel_start_cursor.pos; i<=sel_end_cursor.pos; i++){
-                  if ((n=NumberOfCell(sel_start_cursor.par,i)) != m) {
-                      cursor.par->table->SetRotateCell(n,false);
+                 LyXParagraph::size_type i;
+                 int n = -1, m = -2;
+              for (i= sel_start_cursor.pos; i<= sel_end_cursor.pos; i++){
+                  if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
+                      cursor.par->table->SetRotateCell(n, false);
                       m = n;
                   }
               }
@@ -1939,32 +1911,33 @@ void LyXText::TableFeatures(int feature)
       case LyXTable::SET_LINEBREAKS:
           what = !cursor.par->table->Linebreaks(cursor.par->table->FirstVirtualCell(actCell));
           if (!selection){
-              cursor.par->table->SetLinebreaks(actCell,what);
+              cursor.par->table->SetLinebreaks(actCell, what);
           } else {
-              int i,n=-1,m=-2;
-              for (i=sel_start_cursor.pos; i<=sel_end_cursor.pos; i++){
-                  if ((n=NumberOfCell(sel_start_cursor.par,i)) != m) {
-                      cursor.par->table->SetLinebreaks(n,what);
+                 LyXParagraph::size_type i;
+                 int n = -1, m = -2;
+              for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
+                  if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
+                      cursor.par->table->SetLinebreaks(n, what);
                       m = n;
                   }
               }
           }
           return;
       case LyXTable::SET_LTFIRSTHEAD:
-          cursor.par->table->SetLTHead(actCell,true);
+          cursor.par->table->SetLTHead(actCell, true);
           return;
       case LyXTable::SET_LTHEAD:
-          cursor.par->table->SetLTHead(actCell,false);
+          cursor.par->table->SetLTHead(actCell, false);
           return;
       case LyXTable::SET_LTFOOT:
-          cursor.par->table->SetLTFoot(actCell,false);
+          cursor.par->table->SetLTFoot(actCell, false);
           return;
       case LyXTable::SET_LTLASTFOOT:
-          cursor.par->table->SetLTFoot(actCell,true);
+          cursor.par->table->SetLTFoot(actCell, true);
           return;
       case LyXTable::SET_LTNEWPAGE:
           what = !cursor.par->table->LTNewPage(actCell);
-          cursor.par->table->SetLTNewPage(actCell,what);
+          cursor.par->table->SetLTNewPage(actCell, what);
           return;
     }
 }
@@ -1972,8 +1945,8 @@ void LyXText::TableFeatures(int feature)
 
 void LyXText::InsertCharInTable(char c)
 {
-       Row *row;
-       Row *tmprow;
+       Row * row;
+       Row * tmprow;
        long y;
        bool jumped_over_space;
        
@@ -1991,7 +1964,8 @@ void LyXText::InsertCharInTable(char c)
                                            * current font */
 
        // Get the font that is used to calculate the baselineskip
-       int const lastpos = cursor.par->Last();
+       LyXParagraph::size_type const lastpos = 
+               cursor.par->Last();
        LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
 
        jumped_over_space = false;
@@ -2019,17 +1993,12 @@ void LyXText::InsertCharInTable(char c)
                 TableFeatures(LyXTable::APPEND_CONT_ROW);
                 CursorDown();
             }
-         /* the newline character is the separator of the cells */
-         // cursor.par->InsertChar(cursor.pos, c);
-         // SetCharFont(cursor.par, cursor.pos, rawtmpfont);
-         // RedoParagraphs(cursor, cursor.par->Next());
-         // SetCursor(cursor.par, cursor.pos+1);
          return;
        }
    
        row = cursor.row;
        y = cursor.y - row->baseline;
-       if (c != LYX_META_INSET)        /* in this case LyXText::InsertInset 
+       if (c != LyXParagraph::META_INSET)      /* in this case LyXText::InsertInset 
                                         * already inserted the character */
                cursor.par->InsertChar(cursor.pos, c);
        SetCharFont(cursor.par, cursor.pos, rawtmpfont);
@@ -2057,22 +2026,22 @@ void LyXText::InsertCharInTable(char c)
 }
 
 
-void LyXText::CheckParagraphInTable(LyXParagraph* par, int pos)
+void LyXText::CheckParagraphInTable(LyXParagraph * par,
+                                   LyXParagraph::size_type pos)
 {
-       Row *row;
-       long y;
        
-       if (par->GetChar(pos) == LYX_META_INSET &&
-           par->GetInset(pos) && par->GetInset(pos)->Display()){
-         par->GetInset(pos)->SetDisplay(false);
+       if (par->GetChar(pos) == LyXParagraph::META_INSET &&
+           par->GetInset(pos) && par->GetInset(pos)->display()){
+         par->GetInset(pos)->display(false);
        }
 
-       row = GetRow(par, pos, y);
+       long y;
+       Row * row = GetRow(par, pos, y);
        
        int tmpheight = row->height;
        SetHeightOfRow(row);
-       
-       int tmp_pos = pos;
+
+       LyXParagraph::size_type tmp_pos = pos;
        /* update the table information */
        while (tmp_pos && !par->IsNewline(tmp_pos - 1))
                tmp_pos--;
@@ -2105,7 +2074,7 @@ void LyXText::CheckParagraphInTable(LyXParagraph* par, int pos)
 
 void LyXText::BackspaceInTable()
 {
-       Row *tmprow, *row;
+       Row * tmprow, * row;
        long y;
        
        LyXFont rawtmpfont = current_font;
@@ -2130,7 +2099,7 @@ void LyXText::BackspaceInTable()
                CursorLeftIntern();
                
                /* some insets are undeletable here */
-               if (cursor.par->GetChar(cursor.pos)==LYX_META_INSET) {
+               if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {
                        if (!cursor.par->GetInset(cursor.pos)->Deletable())
                                return;
                }
@@ -2206,41 +2175,25 @@ void LyXText::RedoParagraph()
  * same Paragraph one to the right and make a rebreak */
 void  LyXText::InsertChar(char c)
 {
-       Row *row;
-       Row *tmprow;
-       int z;
-       long y;
-       bool jumped_over_space;
-       LyXFont realtmpfont;
-       LyXFont rawtmpfont;
-       int lastpos;
-       LyXFont rawparfont;
-   
        SetUndo(Undo::INSERT, 
                cursor.par->ParFromPos(cursor.pos)->previous, 
                cursor.par->ParFromPos(cursor.pos)->next);
 
        /* When the free-spacing option is set for the current layout,
         * all spaces are converted to protected spaces. */
-       bool freeSpacingBo =
-               lyxstyle.Style(parameters->textclass,
-                              cursor.row->par->GetLayout())->free_spacing;
-       //
-       // Is this wanted? There cannot be a line break between protected
-       // separators. Therefore I suggest the way implemented below
-       // (Matthias)
-       //
-       //   if ( freeSpacingBo && IsLineSeparatorChar(c) )
-       //         c = LYX_META_PROTECTED_SEPARATOR;
+       bool freeSpacingBo = 
+               textclasslist.Style(parameters->textclass,
+                              cursor.row->par->GetLayout()).free_spacing;
    
        if (freeSpacingBo && IsLineSeparatorChar(c) 
            && (!cursor.pos || cursor.par->IsLineSeparator(cursor.pos-1))) 
-               c = LYX_META_PROTECTED_SEPARATOR;
+               c = LyXParagraph::META_PROTECTED_SEPARATOR;
    
        /* table stuff -- begin*/
        if (cursor.par->table) {
                InsertCharInTable(c);
-               goto out;
+               charInserted();
+               return;
        }
        /* table stuff -- end*/
    
@@ -2257,18 +2210,18 @@ void  LyXText::InsertChar(char c)
 #warning There is a bug here! (Asger)
 #endif
        
-       realtmpfont = real_current_font;
-       rawtmpfont = current_font;  /* store the current font.
+       LyXFont realtmpfont = real_current_font;
+       LyXFont rawtmpfont = current_font;  /* store the current font.
                                     * This is because of the use
                                     * of cursor movements. The moving
                                     * cursor would refresh the 
                                     * current font */
 
        // Get the font that is used to calculate the baselineskip
-       lastpos = cursor.par->Last();
-       rawparfont = cursor.par->GetFontSettings(lastpos - 1);
+       LyXParagraph::size_type lastpos = cursor.par->Last();
+       LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
 
-       jumped_over_space = false;
+       bool jumped_over_space = false;
    
        if (IsLineSeparatorChar(c)) {
           
@@ -2281,7 +2234,7 @@ void  LyXText::InsertChar(char c)
                         * blank at the end of a row we have to force
                         * a rebreak.*/ 
           
-                       minibuffer->Set(_("You cannot type two spaces this way.  Please read the Tutorial."));
+                       current_view->owner()->getMiniBuffer()->Set(_("You cannot type two spaces this way.  Please read the Tutorial."));
                        if (cursor.pos == RowLast(cursor.row)
                            && !IsLineSeparatorChar(c))
                                cursor.row->fill = -1;    /* force rebreak  */
@@ -2298,15 +2251,18 @@ void  LyXText::InsertChar(char c)
                                    && cursor.par->Previous()->footnoteflag
                                    == LyXParagraph::OPEN_FOOTNOTE))) {
                        if (cursor.pos == 0 )
-                               minibuffer->Set(_("You cannot insert a space at the beginning of a paragraph.  Please read the Tutorial."));
+                               current_view->owner()->getMiniBuffer()->Set(_("You cannot insert a space at the beginning of a paragraph.  Please read the Tutorial."));
                        else
-                               minibuffer->Set(_("You cannot type two spaces this way.  Please read the Tutorial."));
-                       goto out;
+                               current_view->owner()->getMiniBuffer()->Set(_("You cannot type two spaces this way.  Please read the Tutorial."));
+                       charInserted();
+                       return;
                }
        } else if (IsNewlineChar(c)) {
                if (cursor.par->FirstPhysicalPar() == cursor.par
-                   && cursor.pos <= BeginningOfMainBody(cursor.par))
-                       goto out;
+                   && cursor.pos <= BeginningOfMainBody(cursor.par)) {
+                       charInserted();
+                       return;
+               }
                /* no newline at first position 
                 * of a paragraph or behind labels. 
                 * TeX does not allow that. */
@@ -2318,9 +2274,9 @@ void  LyXText::InsertChar(char c)
        }
    
        /* the display inset stuff */ 
-       if (cursor.row->par->GetChar(cursor.row->pos) == LYX_META_INSET
+       if (cursor.row->par->GetChar(cursor.row->pos) == LyXParagraph::META_INSET
            && cursor.row->par->GetInset(cursor.row->pos)
-           && cursor.row->par->GetInset(cursor.row->pos)->Display())
+           && cursor.row->par->GetInset(cursor.row->pos)->display())
                cursor.row->fill = -1; // to force a new break  
 
        /* get the cursor row fist */
@@ -2328,16 +2284,16 @@ void  LyXText::InsertChar(char c)
           in future */ 
        /* row = GetRow(cursor.par, cursor.pos, y);*/
        /* ok, heres a better way: */ 
-       row = cursor.row;
-       y = cursor.y - row->baseline;
-       if (c != LYX_META_INSET)  /* in this case LyXText::InsertInset 
+       Row * row = cursor.row;
+       long y = cursor.y - row->baseline;
+       if (c != LyXParagraph::META_INSET)  /* in this case LyXText::InsertInset 
                                   * already insertet the character */
                cursor.par->InsertChar(cursor.pos, c);
        SetCharFont(cursor.par, cursor.pos, rawtmpfont);
 
        if (!jumped_over_space) {
                /* refresh the positions */
-               tmprow = row;
+               Row * tmprow = row;
                while (tmprow->next && tmprow->next->par == row->par) {
                        tmprow = tmprow->next;
                        tmprow->pos++;
@@ -2349,7 +2305,8 @@ void  LyXText::InsertChar(char c)
             || cursor.par->IsNewline(cursor.pos)
             || cursor.row->fill == -1)
            && row->previous && row->previous->par == row->par) {
-               z = NextBreakPoint(row->previous, paperwidth);
+               LyXParagraph::size_type z = NextBreakPoint(row->previous,
+                                                          paperwidth);
                if ( z >= row->pos) {
                        row->pos = z + 1;
                        
@@ -2380,7 +2337,8 @@ void  LyXText::InsertChar(char c)
                            && rawparfont != rawtmpfont)
                                RedoHeightOfParagraph(cursor);
                        
-                       goto out;
+                       charInserted();
+                       return;
                }
        }
    
@@ -2436,33 +2394,37 @@ void  LyXText::InsertChar(char c)
                RedoHeightOfParagraph(cursor);
        } else {
                /* now the special right address boxes */
-               if (lyxstyle.Style(parameters->textclass,
-                                  cursor.par->GetLayout())->margintype
+               if (textclasslist.Style(parameters->textclass,
+                                  cursor.par->GetLayout()).margintype
                    == MARGIN_RIGHT_ADDRESS_BOX) {
                        RedoDrawingOfParagraph(cursor); 
                }
        }
-  out:
 
+       charInserted();
+}
+   
+
+void LyXText::charInserted()
+{
        // Here we could call FinishUndo for every 20 characters inserted.
        // This is from my experience how emacs does it.
-       static unsigned short counter = 0;
+       static unsigned int counter = 0;
        if (counter < 20) {
                ++counter;
        } else {
                FinishUndo();
                counter = 0;
        }
-       return;
 }
-   
-   
-void LyXText::PrepareToPrint(Row *row, float &x, float &fill_separator, 
-                            float &fill_hfill, float &fill_label_hfill)
+
+
+void LyXText::PrepareToPrint(Row * row, float & x, float & fill_separator, 
+                            float & fill_hfill, float & fill_label_hfill)
 {
-       float w, nh, nlh, ns;
+       float nh, nlh, ns;
        
-       w = row->fill;
+       float w = row->fill;
        fill_hfill = 0;
        fill_label_hfill = 0;
        fill_separator = 0;
@@ -2471,10 +2433,10 @@ void LyXText::PrepareToPrint(Row *row, float &x, float &fill_separator,
        x = LeftMargin(row);
        
        /* is there a manual margin with a manual label */ 
-       if (lyxstyle.Style(parameters->textclass,
-                          row->par->GetLayout())->margintype == MARGIN_MANUAL
-           && lyxstyle.Style(parameters->textclass,
-                             row->par->GetLayout())->labeltype == LABEL_MANUAL) {
+       if (textclasslist.Style(parameters->textclass,
+                          row->par->GetLayout()).margintype == MARGIN_MANUAL
+           && textclasslist.Style(parameters->textclass,
+                             row->par->GetLayout()).labeltype == LABEL_MANUAL) {
               
                nlh = NumberOfLabelHfills(row) + 1; /* one more since labels 
                                                    * are left aligned*/ 
@@ -2501,14 +2463,14 @@ void LyXText::PrepareToPrint(Row *row, float &x, float &fill_separator,
            * set x how you need it */
           int align;
           if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
-            align = lyxstyle.Style(parameters->textclass, row->par->GetLayout())->align;
+            align = textclasslist.Style(parameters->textclass, row->par->GetLayout()).align;
           else
             align = row->par->FirstPhysicalPar()->align;
           
           /* center displayed insets */ 
-          if (row->par->GetChar(row->pos) == LYX_META_INSET
+          if (row->par->GetChar(row->pos) == LyXParagraph::META_INSET
               && row->par->GetInset(row->pos)
-              && row->par->GetInset(row->pos)->Display())
+              && row->par->GetInset(row->pos)->display())
             align = LYX_ALIGN_CENTER;
 
           switch (align) {
@@ -2516,9 +2478,9 @@ void LyXText::PrepareToPrint(Row *row, float &x, float &fill_separator,
              ns = NumberOfSeparators(row);
              if (ns && row->next && row->next->par == row->par &&
                  !(row->next->par->IsNewline(row->next->pos-1))
-                 && !(row->next->par->GetChar(row->next->pos) == LYX_META_INSET
+                 && !(row->next->par->GetChar(row->next->pos) == LyXParagraph::META_INSET
                       && row->next->par->GetInset(row->next->pos)
-                      && row->next->par->GetInset(row->next->pos)->Display())
+                      && row->next->par->GetInset(row->next->pos)->display())
                  )
                fill_separator = w / ns;
              break;
@@ -2557,7 +2519,7 @@ void LyXText::CursorRightOneWord()
                while ( tmpcursor.pos < tmpcursor.par->Last() &&
                        ! tmpcursor.par->IsWord( tmpcursor.pos ) ) 
                {
-                 //    printf("Current pos1 %d",tmpcursor.pos) ;
+                 //    printf("Current pos1 %d", tmpcursor.pos) ;
                        tmpcursor.pos++;
                        steps++;
                }
@@ -2565,7 +2527,7 @@ void LyXText::CursorRightOneWord()
                while ( tmpcursor.pos < tmpcursor.par->Last() &&
                        tmpcursor.par->IsWord( tmpcursor.pos ) )
                {
-                 //     printf("Current pos2 %d",tmpcursor.pos) ;
+                 //     printf("Current pos2 %d", tmpcursor.pos) ;
                        tmpcursor.pos++;
                        steps++;
                }
@@ -2703,9 +2665,9 @@ int LyXText::SelectWordWhenUnderCursor()
 
 // This function is only used by the spellchecker for NextWord().
 // It doesn't handle LYX_ACCENTs and probably never will.
-char* LyXText::SelectNextWord(float &value)
+char * LyXText::SelectNextWord(float & value)
 {
-       LyXParagraph* tmppar = cursor.par;
+       LyXParagraph * tmppar = cursor.par;
        
        // If this is not the very first word, skip rest of
        // current word because we are probably in the middle
@@ -2744,26 +2706,25 @@ char* LyXText::SelectNextWord(float &value)
           (optional hyphens are part of a word) */
        while (cursor.pos < cursor.par->Last()
               && (cursor.par->IsLetter(cursor.pos)) 
-                  || (cursor.par->GetChar(cursor.pos) == LYX_META_INSET &&
+                  || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET &&
                       cursor.par->GetInset(cursor.pos) != 0 &&
-                      cursor.par->GetInset(cursor.pos)->Latex(latex,0)==0 &&
+                      cursor.par->GetInset(cursor.pos)->Latex(latex, 0) == 0 &&
                       latex == "\\-"))
                cursor.pos++;
 
        // Finally, we copy the word to a string and return it
-       char* string = 0;
+       char * str = 0;
 
        if (sel_cursor.pos < cursor.pos) {
-               string = new char [cursor.pos - sel_cursor.pos + 2];
-               int i,j;
-               
-               for (i=sel_cursor.pos, j=0; i<cursor.pos; i++) {
-                       if (cursor.par->GetChar(i) != LYX_META_INSET)
-                               string[j++] = cursor.par->GetChar(i);
+               str = new char [cursor.pos - sel_cursor.pos + 2];
+               LyXParagraph::size_type i, j;
+               for (i = sel_cursor.pos, j = 0; i < cursor.pos; ++i) {
+                       if (cursor.par->GetChar(i) != LyXParagraph::META_INSET)
+                               str[j++] = cursor.par->GetChar(i);
                }
-               string[j] = '\0';
+               str[j] = '\0';
        }
-       return string;
+       return str;
 }
 
 
@@ -2781,9 +2742,9 @@ void LyXText::SelectSelectedWord()
        /* now find the end of the word */
        while (cursor.pos < cursor.par->Last()
               && (cursor.par->IsLetter(cursor.pos)
-                  || (cursor.par->GetChar(cursor.pos) == LYX_META_INSET &&
+                  || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET &&
                       cursor.par->GetInset(cursor.pos) != 0 &&
-                      cursor.par->GetInset(cursor.pos)->Latex(latex,0)==0 &&
+                      cursor.par->GetInset(cursor.pos)->Latex(latex, 0) == 0 &&
                       latex == "\\-")))
                cursor.pos++;
        
@@ -2828,7 +2789,7 @@ void LyXText::DeleteWordBackward()
        if (!cursor.par->Last())
          CursorLeft();
        else{
-         selection = True; // to avoid deletion 
+         selection = true; // to avoid deletion 
          CursorLeftOneWord();
          sel_cursor = cursor;
          cursor = tmpcursor;
@@ -2857,6 +2818,7 @@ void LyXText::DeleteLineForward()
        }
 }
 
+
 // Change the case of a word at cursor position. The meaning of action
 // is:
 // 0  change to lowercase
@@ -2868,34 +2830,35 @@ void LyXText::DeleteLineForward()
 // LyXParagraph, but it will have to change for 1.1 anyway. At least
 // it does not access outside of the allocated array as the older
 // version did. (JMarc) 
-void LyXText::ChangeWordCase(int action) 
+void LyXText::ChangeWordCase(LyXText::TextCase action) 
 {
-       LyXParagraph *tmppar = cursor.par->ParFromPos(cursor.pos);
-       int tmppos = cursor.par->PositionInParFromPos(cursor.pos);
+       LyXParagraph * tmppar = cursor.par->ParFromPos(cursor.pos);
 
        SetUndo(Undo::FINISH, tmppar->previous, tmppar->next); 
 
-       while (tmppos < tmppar->last) {
+       LyXParagraph::size_type tmppos = 
+               cursor.par->PositionInParFromPos(cursor.pos);
+       while (tmppos < tmppar->size()) {
                unsigned char c = tmppar->text[tmppos];
                if (IsKommaChar(c) || IsLineSeparatorChar(c))
                        break;
-               if (c != LYX_META_INSET) {
+               if (c != LyXParagraph::META_INSET) {
                        switch (action) {
-                       case 0:
+                       case text_lowercase:
                                c = tolower(c);
                                break;
-                       case 1:
+                       case text_capitalization:
                                c = toupper(c);
-                               action = 0;
+                               action = text_lowercase;
                                break;
-                       case 2:
+                       case text_uppercase:
                                c = toupper(c);
                                break;
                        }
                }
                
                tmppar->text[tmppos] = c;
-               tmppos++;
+               ++tmppos;
        }
        CheckParagraph(tmppar, tmppos);
        CursorRightOneWord();
@@ -2905,7 +2868,6 @@ void LyXText::ChangeWordCase(int action)
 void  LyXText::Delete()
 {
    LyXCursor old_cursor = cursor;
-   LyXCursor tmpcursor;
    /* this is a very easy implementation*/ 
    
    /* just move to the right */ 
@@ -2917,7 +2879,7 @@ void  LyXText::Delete()
    
    /* if you had success make a backspace */ 
    if (old_cursor.par != cursor.par || old_cursor.pos != cursor.pos) {
-     tmpcursor = cursor;
+     LyXCursor tmpcursor = cursor;
      cursor = old_cursor; // to make sure undo gets the right cursor position
      SetUndo(Undo::DELETE, 
             cursor.par->ParFromPos(cursor.pos)->previous, 
@@ -2930,8 +2892,8 @@ void  LyXText::Delete()
 
 void  LyXText::Backspace()
 {
-       LyXParagraph *tmppar;
-       Row *tmprow, *row;
+       LyXParagraph * tmppar;
+       Row * tmprow, * row;
        long y;
        int tmpheight;
 
@@ -2958,9 +2920,9 @@ void  LyXText::Backspace()
                if ((lastpos == 0
                     || (lastpos == 1 && cursor.par->IsSeparator(0)))
                    && !(cursor.par->Next() 
-                        && cursor.par->footnoteflag ==
+                        && cursor.par->footnoteflag == 
                         LyXParagraph::NO_FOOTNOTE
-                        && cursor.par->Next()->footnoteflag ==
+                        && cursor.par->Next()->footnoteflag == 
                         LyXParagraph::OPEN_FOOTNOTE)) {
                        
                        if (cursor.par->previous) {
@@ -2995,14 +2957,16 @@ void  LyXText::Backspace()
                tmppar = cursor.par;
                tmprow = cursor.row;
                CursorLeftIntern();
-               /* Pasting is not allowed, if the paragraphs have different layout.
-                * I think it is a real bug of all other word processors to allow
-                * it. It confuses the user. Even so with a footnote paragraph and
-                * a non-footnote paragraph. I will not allow pasting in this case, 
-                * because the user would be confused if the footnote behaves 
-                * different wether it is open or closed.
-                * 
-                * Correction: Pasting is always allowed with standard-layout */
+               /* Pasting is not allowed, if the paragraphs have different
+                  layout. I think it is a real bug of all other
+                  word processors to allow it. It confuses the user.
+                  Even so with a footnote paragraph and a non-footnote
+                  paragraph. I will not allow pasting in this case, 
+                  because the user would be confused if the footnote behaves 
+                  different wether it is open or closed.
+                 
+                  Correction: Pasting is always allowed with standard-layout
+               */
                if (cursor.par != tmppar
                    && (cursor.par->GetLayout() == tmppar->GetLayout()
                        || !tmppar->GetLayout())
@@ -3029,9 +2993,6 @@ void  LyXText::Backspace()
                        RemoveParagraph(tmprow);
                        RemoveRow(tmprow);  
                        
-                       /* break the paragraph again */ 
-                       /* BreakAgain(cursor.row); */ 
-                       
                        AppendParagraph(cursor.row);
                        UpdateCounters(cursor.row);
                        
@@ -3047,12 +3008,12 @@ void  LyXText::Backspace()
                CursorLeftIntern();
                
                /* some insets are undeletable here */
-               if (cursor.par->GetChar(cursor.pos)==LYX_META_INSET) {
+               if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {
                        if (!cursor.par->GetInset(cursor.pos)->Deletable())
                                return; 
                        /* force complete redo when erasing display insets */ 
                        /* this is a cruel mathod but save..... Matthias */ 
-                       if (cursor.par->GetInset(cursor.pos)->Display()){
+                       if (cursor.par->GetInset(cursor.pos)->display()){
                                cursor.par->Erase(cursor.pos);
                                RedoParagraph();
                                return;
@@ -3061,8 +3022,7 @@ void  LyXText::Backspace()
                
                row = cursor.row;
                y = cursor.y - row->baseline;
-               int z;
-               
+               LyXParagraph::size_type z;
                /* remember that a space at the end of a row doesnt count
                 * when calculating the fill */ 
                if (cursor.pos < RowLast(row) ||
@@ -3125,8 +3085,7 @@ void  LyXText::Backspace()
                        /* delete newlines at the beginning of paragraphs */ 
                        while (cursor.par->Last() &&
                               cursor.par->IsNewline(cursor.pos) &&
-                              cursor.pos == BeginningOfMainBody(cursor.par)
-                               ) {
+                              cursor.pos == BeginningOfMainBody(cursor.par)) {
                                cursor.par->Erase(cursor.pos);
                                /* refresh the positions */
                                tmprow = row;
@@ -3233,38 +3192,36 @@ void  LyXText::Backspace()
                RedoHeightOfParagraph(cursor);
        } else {
                /* now the special right address boxes */
-               if (lyxstyle.Style(parameters->textclass,
-                                  cursor.par->GetLayout())->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
+               if (textclasslist.Style(parameters->textclass,
+                                  cursor.par->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) {
                        RedoDrawingOfParagraph(cursor); 
                }
        }
 }
 
 
-void LyXText::GetVisibleRow(LyXScreen &scr, int offset, 
-                           Row *row_ptr, long y)
+void LyXText::GetVisibleRow(LyXScreen & scr, int offset, 
+                           Row * row_ptr, long y)
 {
        /* returns a printed row */
-       
-       int pos, pos_end;
+       LyXParagraph::size_type pos, pos_end;
        float x, tmpx;
        int y_top, y_bottom;
        float fill_separator, fill_hfill, fill_label_hfill;
-       LyXParagraph *par, *firstpar;
+       LyXParagraph * par, * firstpar;
        int left_margin;
        LyXFont font;
        int maxdesc;
        if (row_ptr->height <= 0) {
-               fprintf(stderr, "LYX_ERROR: row.height: %d \n",
-                       row_ptr->height);
+               lyxerr << "LYX_ERROR: row.height: " << row_ptr->height << endl;
                return;
        }
        left_margin = LabelEnd(row_ptr);
        PrepareToPrint(row_ptr, x, fill_separator,
                       fill_hfill, fill_label_hfill);
-       
-       int main_body = BeginningOfMainBody(row_ptr->par);
-       
+
+       LyXParagraph::size_type main_body = 
+               BeginningOfMainBody(row_ptr->par);
        /* initialize the pixmap */
        
        scr.fillRectangle(gc_clear,
@@ -3286,7 +3243,7 @@ void LyXText::GetVisibleRow(LyXScreen &scr, int offset,
                                          paperwidth - sel_start_cursor.x,
                                          row_ptr->height);
                } else if (sel_end_cursor.row == row_ptr) {
-                       scr.fillRectangle(gc_selection,0, offset,
+                       scr.fillRectangle(gc_selection, 0, offset,
                                          sel_end_cursor.x, row_ptr->height);
                } else if (y > sel_start_cursor.y && y < sel_end_cursor.y) {
                        scr.fillRectangle(gc_selection, 0, offset,
@@ -3300,7 +3257,7 @@ void LyXText::GetVisibleRow(LyXScreen &scr, int offset,
          scr.drawVerticalLine(gc_math, paperwidth-2 , offset, offset+row_ptr->height);
        }
 
-       if (row_ptr->par->pextra_type == PEXTRA_MINIPAGE) {
+       if (row_ptr->par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
                /* draw a marker at the left margin! */ 
                LyXFont font = GetFont(row_ptr->par, 0);
                int asc = font.maxAscent();
@@ -3349,7 +3306,7 @@ void LyXText::GetVisibleRow(LyXScreen &scr, int offset,
                        if (mono_video) {
                                back = gc_clear;
                        }
-                       scr.fillRectangle(back,LYX_PAPER_MARGIN, offset+1,
+                       scr.fillRectangle(back, LYX_PAPER_MARGIN, offset+1,
                                          box_x - LYX_PAPER_MARGIN, 
                                          int(font.maxAscent())+
                                          int(font.maxDescent()));
@@ -3403,7 +3360,7 @@ void LyXText::GetVisibleRow(LyXScreen &scr, int offset,
                }
        }
        
-       LyXLayout* layout = lyxstyle.Style(parameters->textclass,
+       LyXLayout const & layout = textclasslist.Style(parameters->textclass,
                                           row_ptr->par->GetLayout());
        firstpar = row_ptr->par->FirstPhysicalPar();
        
@@ -3452,14 +3409,14 @@ void LyXText::GetVisibleRow(LyXScreen &scr, int offset,
                
                /* think about the parskip */ 
                /* some parskips VERY EASY IMPLEMENTATION */ 
-               if (parameters->paragraph_separation == LYX_PARSEP_SKIP) {
-                       if (layout->latextype == LATEX_PARAGRAPH
+               if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) {
+                       if (layout.latextype == LATEX_PARAGRAPH
                            && firstpar->GetDepth() == 0
                            && firstpar->Previous())
                                y_top += parameters->getDefSkip().inPixels();
                        else if (firstpar->Previous()
-                                && lyxstyle.Style(parameters->textclass,
-                                                  firstpar->Previous()->GetLayout())->latextype == LATEX_PARAGRAPH
+                                && textclasslist.Style(parameters->textclass,
+                                                  firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
                                 && firstpar->Previous()->GetDepth() == 0)
                                // is it right to use defskip here, too? (AS) 
                                y_top += parameters->getDefSkip().inPixels();
@@ -3474,28 +3431,28 @@ void LyXText::GetVisibleRow(LyXScreen &scr, int offset,
                }
                
                /* should we print a label? */ 
-               if (layout->labeltype >= LABEL_STATIC
-                   && (layout->labeltype != LABEL_STATIC
-                       || layout->latextype != LATEX_ENVIRONMENT
+               if (layout.labeltype >= LABEL_STATIC
+                   && (layout.labeltype != LABEL_STATIC
+                       || layout.latextype != LATEX_ENVIRONMENT
                        || row_ptr->par->IsFirstInSequence())) {
                        font = GetFont(row_ptr->par, -2);
                        if (!row_ptr->par->GetLabestring().empty()) {
                                tmpx = x;
                                string tmpstring = row_ptr->par->GetLabestring();
                                
-                               if (layout->labeltype == LABEL_COUNTER_CHAPTER) {
-                                       if (parameters->secnumdepth >=0){
+                               if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
+                                       if (parameters->secnumdepth >= 0){
                                                /* this is special code for the chapter layout. This is printed in
                                                 * an extra row and has a pagebreak at the top. */
-                                               maxdesc = int(font.maxDescent() * layout->spacing.getValue() * parameters->spacing.getValue())
-                                                       + int(layout->parsep) * DefaultHeight();
+                                               maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue())
+                                                       + int(layout.parsep) * DefaultHeight();
                                                scr.drawString(font, tmpstring,
                                                               offset + row_ptr->baseline
                                                               - row_ptr->ascent_of_text - maxdesc,
                                                               int(x));
                                        }
                                } else {
-                                       x -= font.stringWidth( layout->labelsep);
+                                       x -= font.stringWidth( layout.labelsep);
                                        x -= font.stringWidth( tmpstring);
                                        /* draw it! */
                                        scr.drawString(font, tmpstring,
@@ -3504,19 +3461,19 @@ void LyXText::GetVisibleRow(LyXScreen &scr, int offset,
                                x = tmpx;
                        }
                        /* the labels at the top of an environment. More or less for bibliography */ 
-               } else if (layout->labeltype == LABEL_TOP_ENVIRONMENT ||
-                          layout->labeltype == LABEL_BIBLIO ||
-                          layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
+               } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
+                          layout.labeltype == LABEL_BIBLIO ||
+                          layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
                        if (row_ptr->par->IsFirstInSequence()) {
                                font = GetFont(row_ptr->par, -2);
                                if (!row_ptr->par->GetLabestring().empty()) {
                                        string tmpstring = row_ptr->par->GetLabestring();
                                        
-                                       maxdesc = int(font.maxDescent() * layout->spacing.getValue() * parameters->spacing.getValue()
-                                                        + (layout->labelbottomsep * DefaultHeight()));
+                                       maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue()
+                                                        + (layout.labelbottomsep * DefaultHeight()));
                                        
                                        int top_label_x = int(x);
-                                       if (layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
+                                       if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
                                                top_label_x = int(x + (paperwidth - RightMargin(row_ptr) - x) / 2); 
                                                top_label_x -= (font.stringWidth( tmpstring)/2);
                                        }
@@ -3528,10 +3485,10 @@ void LyXText::GetVisibleRow(LyXScreen &scr, int offset,
                                }
                        }
                }
-               if (layout->labeltype==LABEL_BIBLIO) { // ale970302
+               if (layout.labeltype == LABEL_BIBLIO) { // ale970302
                        if (row_ptr->par->bibkey) {
                                tmpx = x;
-                               x -= font.stringWidth(layout->labelsep);
+                               x -= font.stringWidth(layout.labelsep);
                                font = GetFont(row_ptr->par, -1);
                                x -= row_ptr->par->bibkey->Width(font);
                                row_ptr->par->bibkey->Draw(font, scr,
@@ -3647,10 +3604,10 @@ void LyXText::GetVisibleRow(LyXScreen &scr, int offset,
                        } else {
                                if (row_ptr->par->IsSeparator(pos)) {
                                        tmpx = x;
-                                       x+=SingleWidth(row_ptr->par, pos);
+                                       x+= SingleWidth(row_ptr->par, pos);
                                        /* -------> Only draw protected spaces when not in
                                         * free-spacing mode. */
-                                       if (row_ptr->par->GetChar(pos)==LYX_META_PROTECTED_SEPARATOR && !layout->free_spacing) {
+                                       if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
                                                scr.drawVerticalLine(gc_fill, int(tmpx),
                                                                     offset + row_ptr->baseline - 3,
                                                                     offset + row_ptr->baseline - 1);
@@ -3722,7 +3679,7 @@ void LyXText::GetVisibleRow(LyXScreen &scr, int offset,
                                scr.drawVerticalLine(gc_fill, int(x),  
                                                     offset + row_ptr->baseline - DefaultHeight()/2, 
                                                     offset + row_ptr->baseline);               
-                               if (HfillExpansion(row_ptr,pos)) {
+                               if (HfillExpansion(row_ptr, pos)) {
                                        if (pos >= main_body) {
                                                scr.drawOnOffLine(offset + row_ptr->baseline -
                                                                  DefaultHeight()/4,
@@ -3746,12 +3703,12 @@ void LyXText::GetVisibleRow(LyXScreen &scr, int offset,
                        } else {
                                if (row_ptr->par->IsSeparator(pos)) {
                                        tmpx = x;
-                                       x+=SingleWidth(row_ptr->par, pos);
+                                       x+= SingleWidth(row_ptr->par, pos);
                                        if (pos >= main_body)
                                                x+= fill_separator;
                                        /* -------> Only draw protected spaces when not in
                                         * free-spacing mode. */
-                                       if (row_ptr->par->GetChar(pos)==LYX_META_PROTECTED_SEPARATOR && !layout->free_spacing) {
+                                       if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
                                                
                                                scr.drawVerticalLine(gc_fill, int(tmpx),
                                                                     offset + row_ptr->baseline - 3,
@@ -3779,7 +3736,7 @@ void LyXText::GetVisibleRow(LyXScreen &scr, int offset,
                        }
                        if (pos == main_body) {
                                x += GetFont(row_ptr->par, -2).stringWidth(
-                                       layout->labelsep);
+                                       layout.labelsep);
                                if (row_ptr->par->IsLineSeparator(pos - 1))
                                        x-= SingleWidth(row_ptr->par, pos - 1);
                                if (x < left_margin)
@@ -3793,7 +3750,7 @@ void LyXText::GetVisibleRow(LyXScreen &scr, int offset,
                        
                        /* selection code */ 
                        if (sel_start_cursor.row == row_ptr && sel_end_cursor.row == row_ptr) {
-                               scr.fillRectangle(gc_select,sel_start_cursor.x, offset,
+                               scr.fillRectangle(gc_select, sel_start_cursor.x, offset,
                                                  sel_end_cursor.x - sel_start_cursor.x,
                                                  row_ptr->height); 
                        } else if (sel_start_cursor.row == row_ptr) {
@@ -3825,27 +3782,25 @@ int LyXText::DefaultHeight()
    
 /* returns the column near the specified x-coordinate of the row 
 * x is set to the real beginning of this column  */ 
-int  LyXText::GetColumnNearX(Row *row, int& x)
+int  LyXText::GetColumnNearX(Row * row, int& x)
 {
-       int c; 
        float tmpx = 0.0;
        float fill_separator, fill_hfill, fill_label_hfill;
-       int left_margin;
    
-       left_margin = LabelEnd(row);
+       int left_margin = LabelEnd(row);
        PrepareToPrint(row, tmpx, fill_separator,
                       fill_hfill, fill_label_hfill);
        int main_body = BeginningOfMainBody(row->par);
    
-       c = row->pos;
+       int c = row->pos;
 
        int last = RowLast(row);
        if (row->par->IsNewline(last))
                last--;
    
-       LyXLayout *layout = lyxstyle.Style(parameters->textclass,
+       LyXLayout const & layout = textclasslist.Style(parameters->textclass,
                                           row->par->GetLayout());
-       /* table stuff -- begin*/
+       /* table stuff -- begin */
        if (row->par->table) {
                if (!row->next || row->next->par != row->par)
                        last = RowLast(row); /* the last row doesn't need a newline at the end*/
@@ -3879,7 +3834,7 @@ int  LyXText::GetColumnNearX(Row *row, int& x)
                        if (c && c == main_body
                            && !row->par->IsLineSeparator(c - 1)) {
                                tmpx += GetFont(row->par, -2)
-                                       .stringWidth(layout->labelsep);
+                                       .stringWidth(layout.labelsep);
                                if (tmpx < left_margin)
                                        tmpx = left_margin;
                        }
@@ -3899,7 +3854,7 @@ int  LyXText::GetColumnNearX(Row *row, int& x)
                        if (c == main_body
                            && row->par->IsLineSeparator(c - 1)) {
                                tmpx += GetFont(row->par, -2)
-                                       .stringWidth(layout->labelsep);
+                                       .stringWidth(layout.labelsep);
                                tmpx-= SingleWidth(row->par, c - 1);
                                if (tmpx < left_margin)
                                        tmpx = left_margin;
@@ -3912,7 +3867,7 @@ int  LyXText::GetColumnNearX(Row *row, int& x)
                tmpx -= SingleWidth(row->par, c - 1);
                tmpx -= fill_separator;
        }
-       c-=row->pos;
+       c-= row->pos;
        
        x = int(tmpx);
        return c;
@@ -3932,7 +3887,7 @@ void LyXText::InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind)
    }
    /* no marginpars in minipages */
    if (kind == LyXParagraph::MARGIN 
-      && cursor.par->pextra_type == PEXTRA_MINIPAGE) {
+      && cursor.par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
       WriteAlert(_("Impossible operation"), 
                 _("You can't insert a marginpar in a minipage!"), 
                 _("Sorry."));
@@ -4021,8 +3976,8 @@ void LyXText::InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind)
                || kind == LyXParagraph::WIDE_TAB
               || kind == LyXParagraph::WIDE_FIG 
                || kind == LyXParagraph::ALGORITHM) {
-                  int lay = lyxstyle.NumberOfLayout(parameters->textclass,
-                                                    "Caption");
+                  int lay = textclasslist.NumberOfLayout(parameters->textclass,
+                                                    "Caption").second;
                   if (lay == -1) // layout not found
                           // use default layout "Standard" (0)
                           lay = 0;
@@ -4057,9 +4012,9 @@ void LyXText::InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind)
    
 
 /* returns pointer to a specified row */
-Row* LyXText::GetRow(LyXParagraph *par, int pos, long &y)
+Row * LyXText::GetRow(LyXParagraph * par, LyXParagraph::size_type pos, long &y)
 {
-   Row* tmprow;
+   Row * tmprow;
 
    if (currentrow){
      if (par == currentrow->par || par == currentrow->par->Previous()){