]> git.lyx.org Git - lyx.git/blobdiff - src/text2.C
Fix small bug in reading \set_color in lyxrc
[lyx.git] / src / text2.C
index d146c411912b2589b451aa594d8133e0e3455914..deda64412f4746743187715bdac66e58cfecc9c4 100644 (file)
 #include "lyxrc.h"
 #include "FloatList.h"
 
-//#define USE_OLD_CUT_AND_PASTE 1
-
 using std::copy;
 using std::endl;
 using std::pair;
 
+
 LyXText::LyXText(BufferView * bv)
 {
        bv_owner = bv;
@@ -414,6 +413,7 @@ void LyXText::ToggleFootnote(BufferView * bview)
 #endif
 
 
+#ifndef NEW_INSETS
 void LyXText::OpenStuff(BufferView * bview)
 {
        if (cursor.pos() == 0 && cursor.par()->bibkey){
@@ -433,6 +433,7 @@ void LyXText::OpenStuff(BufferView * bview)
        }
 #endif
 }
+#endif
 
 
 #ifndef NEW_INSETS
@@ -537,12 +538,20 @@ LyXParagraph * LyXText::SetLayout(BufferView * bview,
                                  LyXCursor & send_cur,
                                  LyXTextClass::size_type layout)
 {
+#ifndef NEW_INSETS
        LyXParagraph * endpar = send_cur.par()->LastPhysicalPar()->Next();
+#else
+       LyXParagraph * endpar = send_cur.par()->Next();
+#endif
        LyXParagraph * undoendpar = endpar;
 
        if (endpar && endpar->GetDepth()) {
                while (endpar && endpar->GetDepth()) {
+#ifndef NEW_INSETS
                        endpar = endpar->LastPhysicalPar()->Next();
+#else
+                       endpar = endpar->Next();
+#endif
                        undoendpar = endpar;
                }
        } else if (endpar) {
@@ -550,7 +559,11 @@ LyXParagraph * LyXText::SetLayout(BufferView * bview,
        }
    
        SetUndo(bview->buffer(), Undo::EDIT,
-               sstart_cur.par()->ParFromPos(sstart_cur.pos())->previous, 
+#ifndef NEW_INSETS
+               sstart_cur.par()->ParFromPos(sstart_cur.pos())->previous,
+#else
+               sstart_cur.par()->previous,
+#endif
                undoendpar);
 
        /* ok we have a selection. This is always between sstart_cur
@@ -566,7 +579,11 @@ LyXParagraph * LyXText::SetLayout(BufferView * bview,
 #endif
                        cur.par()->SetLayout(bview->buffer()->params, layout);
                        MakeFontEntriesLayoutSpecific(bview->buffer(), cur.par());
+#ifndef NEW_INSETS
                        LyXParagraph * fppar = cur.par()->FirstPhysicalPar();
+#else
+                       LyXParagraph * fppar = cur.par();
+#endif
                        fppar->added_space_top = lyxlayout.fill_top ?
                                VSpace(VSpace::VFILL) : VSpace(VSpace::NONE);
                        fppar->added_space_bottom = lyxlayout.fill_bottom ? 
@@ -588,7 +605,11 @@ LyXParagraph * LyXText::SetLayout(BufferView * bview,
 #endif
                cur.par()->SetLayout(bview->buffer()->params, layout);
                MakeFontEntriesLayoutSpecific(bview->buffer(), cur.par());
+#ifndef NEW_INSETS
                LyXParagraph * fppar = cur.par()->FirstPhysicalPar();
+#else
+               LyXParagraph * fppar = cur.par();
+#endif
                fppar->added_space_top = lyxlayout.fill_top ?
                        VSpace(VSpace::VFILL) : VSpace(VSpace::NONE);
                fppar->added_space_bottom = lyxlayout.fill_bottom ? 
@@ -609,79 +630,8 @@ LyXParagraph * LyXText::SetLayout(BufferView * bview,
 // set layout over selection and make a total rebreak of those paragraphs
 void LyXText::SetLayout(BufferView * bview, LyXTextClass::size_type layout)
 {
-       LyXCursor
-               tmpcursor = cursor;  /* store the current cursor  */
-
-#ifdef USE_OLD_SET_LAYOUT
-       // if there is no selection just set the layout
-       // of the current paragraph  */
-       if (!selection) {
-               sel_start_cursor = cursor;  // dummy selection
-               sel_end_cursor = cursor;
-       }
-
-       LyXParagraph * endpar = sel_end_cursor.par()->LastPhysicalPar()->Next();
-       LyXParagraph * undoendpar = endpar;
-
-       if (endpar && endpar->GetDepth()) {
-               while (endpar && endpar->GetDepth()) {
-                       endpar = endpar->LastPhysicalPar()->Next();
-                       undoendpar = endpar;
-               }
-       }
-       else if (endpar) {
-               endpar = endpar->Next(); // because of parindents etc.
-       }
-   
-       SetUndo(Undo::EDIT, 
-               sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos())->previous, 
-               undoendpar);
+       LyXCursor tmpcursor = cursor;  /* store the current cursor  */
 
-       /* ok we have a selection. This is always between sel_start_cursor
-        * and sel_end cursor */ 
-       cursor = sel_start_cursor;
-   
-       LyXLayout const & lyxlayout =
-               textclasslist.Style(bview->buffer()->params.textclass, layout);
-   
-       while (cursor.par() != sel_end_cursor.par()) {
-               if (cursor.par()->footnoteflag ==
-                   sel_start_cursor.par()->footnoteflag) {
-                       cursor.par()->SetLayout(layout);
-                       MakeFontEntriesLayoutSpecific(cursor.par());
-                       LyXParagraph* fppar = cursor.par()->FirstPhysicalPar();
-                       fppar->added_space_top = lyxlayout.fill_top ?
-                               VSpace(VSpace::VFILL) : VSpace(VSpace::NONE);
-                       fppar->added_space_bottom = lyxlayout.fill_bottom ? 
-                               VSpace(VSpace::VFILL) : VSpace(VSpace::NONE); 
-                       if (lyxlayout.margintype == MARGIN_MANUAL)
-                               cursor.par()->SetLabelWidthString(lyxlayout.labelstring());
-                       if (lyxlayout.labeltype != LABEL_BIBLIO
-                           && fppar->bibkey) {
-                               delete fppar->bibkey;
-                               fppar->bibkey = 0;
-                       }
-               }
-               cursor.par() = cursor.par()->Next();
-       }
-       if (cursor.par()->footnoteflag ==
-           sel_start_cursor.par()->footnoteflag) {
-               cursor.par()->SetLayout(layout);
-               MakeFontEntriesLayoutSpecific(cursor.par());
-               LyXParagraph* fppar = cursor.par()->FirstPhysicalPar();
-               fppar->added_space_top = lyxlayout.fill_top ?
-                       VSpace(VSpace::VFILL) : VSpace(VSpace::NONE);
-               fppar->added_space_bottom = lyxlayout.fill_bottom ? 
-                       VSpace(VSpace::VFILL) : VSpace(VSpace::NONE); 
-               if (lyxlayout.margintype == MARGIN_MANUAL)
-                       cursor.par()->SetLabelWidthString(lyxlayout.labelstring());
-               if (lyxlayout.labeltype != LABEL_BIBLIO
-                   && fppar->bibkey) {
-                       delete fppar->bibkey;
-                       fppar->bibkey = 0;
-               }
-       }
-#else
        // if there is no selection just set the layout
        // of the current paragraph  */
        if (!selection) {
@@ -691,11 +641,10 @@ void LyXText::SetLayout(BufferView * bview, LyXTextClass::size_type layout)
        LyXParagraph *
                endpar = SetLayout(bview, cursor, sel_start_cursor,
                                   sel_end_cursor, layout);
-#endif
        RedoParagraphs(bview, sel_start_cursor, endpar);
    
        // we have to reset the selection, because the
-       // geometry could have changed */ 
+       // geometry could have changed
        SetCursor(bview, sel_start_cursor.par(),
                  sel_start_cursor.pos(), false);
        sel_cursor = cursor;
@@ -720,12 +669,20 @@ void  LyXText::IncDepth(BufferView * bview)
 
        // We end at the next paragraph with depth 0
        LyXParagraph * endpar =
+#ifndef NEW_INSETS
                sel_end_cursor.par()->LastPhysicalPar()->Next();
+#else
+               sel_end_cursor.par()->Next();
+#endif
        LyXParagraph * undoendpar = endpar;
 
        if (endpar && endpar->GetDepth()) {
                while (endpar && endpar->GetDepth()) {
+#ifndef NEW_INSETS
                        endpar = endpar->LastPhysicalPar()->Next();
+#else
+                       endpar = endpar->Next();
+#endif
                        undoendpar = endpar;
                }
        }
@@ -733,9 +690,13 @@ void  LyXText::IncDepth(BufferView * bview)
                endpar = endpar->Next(); // because of parindents etc.
        }
        
-       SetUndo(bview->buffer(), Undo::EDIT, 
+       SetUndo(bview->buffer(), Undo::EDIT,
+#ifndef NEW_INSETS
                sel_start_cursor
-               .par()->ParFromPos(sel_start_cursor.pos())->previous, 
+               .par()->ParFromPos(sel_start_cursor.pos())->previous,
+#else
+               sel_start_cursor.par()->previous,
+#endif
                undoendpar);
 
        LyXCursor tmpcursor = cursor; // store the current cursor
@@ -748,19 +709,30 @@ void  LyXText::IncDepth(BufferView * bview)
    
        while (true) {
                // NOTE: you can't change the depth of a bibliography entry
-               if (cursor.par()->footnoteflag ==
-                   sel_start_cursor.par()->footnoteflag
-                   && textclasslist.Style(bview->buffer()->params.textclass,
+               if (
+#ifndef NEW_INSETS
+                       cursor.par()->footnoteflag ==
+                   sel_start_cursor.par()->footnoteflag &&
+#endif
+                   textclasslist.Style(bview->buffer()->params.textclass,
                                      cursor.par()->GetLayout()
                                     ).labeltype != LABEL_BIBLIO) {
                        LyXParagraph * prev =
+#ifndef NEW_INSETS
                                cursor.par()->FirstPhysicalPar()->Previous();
+#else
+                               cursor.par()->Previous();
+#endif
                        if (prev 
                            && (prev->GetDepth() - cursor.par()->GetDepth() > 0
                                || (prev->GetDepth() == cursor.par()->GetDepth()
                                    && textclasslist.Style(bview->buffer()->params.textclass,
                                                      prev->GetLayout()).isEnvironment()))) {
+#ifndef NEW_INSETS
                                cursor.par()->FirstPhysicalPar()->depth++;
+#else
+                               cursor.par()->depth++;
+#endif
                                anything_changed = true;
                                }
                }
@@ -773,11 +745,19 @@ void  LyXText::IncDepth(BufferView * bview)
        if (!anything_changed) {
                cursor = sel_start_cursor;
                while (cursor.par() != sel_end_cursor.par()) {
+#ifndef NEW_INSETS
                        cursor.par()->FirstPhysicalPar()->depth = 0;
+#else
+                       cursor.par()->depth = 0;
+#endif
                        cursor.par(cursor.par()->Next());
                }
+#ifndef NEW_INSETS
                if (cursor.par()->footnoteflag == sel_start_cursor.par()->footnoteflag)
                        cursor.par()->FirstPhysicalPar()->depth = 0;
+#else
+                       cursor.par()->depth = 0;
+#endif
        }
    
        RedoParagraphs(bview, sel_start_cursor, endpar);
@@ -805,13 +785,20 @@ void  LyXText::DecDepth(BufferView * bview)
                sel_start_cursor = cursor; // dummy selection
                sel_end_cursor = cursor;
        }
-   
+#ifndef NEW_INSETS
        LyXParagraph * endpar = sel_end_cursor.par()->LastPhysicalPar()->Next();
+#else
+       LyXParagraph * endpar = sel_end_cursor.par()->Next();
+#endif
        LyXParagraph * undoendpar = endpar;
 
        if (endpar && endpar->GetDepth()) {
                while (endpar && endpar->GetDepth()) {
+#ifndef NEW_INSETS
                        endpar = endpar->LastPhysicalPar()->Next();
+#else
+                       endpar = endpar->Next();
+#endif
                        undoendpar = endpar;
                }
        }
@@ -819,9 +806,13 @@ void  LyXText::DecDepth(BufferView * bview)
                endpar = endpar->Next(); // because of parindents etc.
        }
    
-       SetUndo(bview->buffer(), Undo::EDIT, 
+       SetUndo(bview->buffer(), Undo::EDIT,
+#ifndef NEW_INSETS
                sel_start_cursor
-               .par()->ParFromPos(sel_start_cursor.pos())->previous, 
+               .par()->ParFromPos(sel_start_cursor.pos())->previous,
+#else
+               sel_start_cursor.par()->previous,
+#endif
                undoendpar);
 
        LyXCursor tmpcursor = cursor; // store the current cursor
@@ -831,11 +822,16 @@ void  LyXText::DecDepth(BufferView * bview)
        cursor = sel_start_cursor;
 
        while (true) {
+#ifndef NEW_INSETS
                if (cursor.par()->footnoteflag ==
                    sel_start_cursor.par()->footnoteflag) {
                        if (cursor.par()->FirstPhysicalPar()->depth)
                                cursor.par()->FirstPhysicalPar()->depth--;
                }
+#else
+                       if (cursor.par()->depth)
+                               cursor.par()->depth--;
+#endif
                if (cursor.par() == sel_end_cursor.par())
                        break;
                cursor.par(cursor.par()->Next());
@@ -886,17 +882,29 @@ void LyXText::SetFont(BufferView * bview, LyXFont const & font, bool toggleall)
        // ok we have a selection. This is always between sel_start_cursor
        // and sel_end cursor
    
-       SetUndo(bview->buffer(), Undo::EDIT, 
+       SetUndo(bview->buffer(), Undo::EDIT,
+#ifndef NEW_INSETS
                sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos())->previous, 
-               sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())->next); 
+               sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())->next
+#else
+               sel_start_cursor.par()->previous, 
+               sel_end_cursor.par()->next
+#endif
+               ); 
        cursor = sel_start_cursor;
        while (cursor.par() != sel_end_cursor.par() ||
-              (cursor.par()->footnoteflag == sel_start_cursor.par()->footnoteflag
-               && cursor.pos() < sel_end_cursor.pos())) 
+              (
+#ifndef NEW_INSETS
+                      cursor.par()->footnoteflag == sel_start_cursor.par()->footnoteflag &&
+#endif
+               cursor.pos() < sel_end_cursor.pos())) 
        {
                if (cursor.pos() < cursor.par()->Last()
+#ifndef NEW_INSETS
                    && cursor.par()->footnoteflag
-                   == sel_start_cursor.par()->footnoteflag) {
+                   == sel_start_cursor.par()->footnoteflag
+#endif
+                       ) {
                        // an open footnote should behave
                        // like a closed one
                        LyXFont newfont = GetFont(bview->buffer(), 
@@ -933,7 +941,11 @@ void LyXText::RedoHeightOfParagraph(BufferView * bview, LyXCursor const & cur)
        long y = cur.y() - tmprow->baseline();
 
        SetHeightOfRow(bview, tmprow);
+#ifndef NEW_INSETS
        LyXParagraph * first_phys_par = tmprow->par()->FirstPhysicalPar();
+#else
+       LyXParagraph * first_phys_par = tmprow->par();
+#endif
        // find the first row of the paragraph
        if (first_phys_par != tmprow->par())
                while (tmprow->previous()
@@ -962,7 +974,11 @@ void LyXText::RedoDrawingOfParagraph(BufferView * bview, LyXCursor const & cur)
    
        long y = cur.y() - tmprow->baseline();
        SetHeightOfRow(bview, tmprow);
+#ifndef NEW_INSETS
        LyXParagraph * first_phys_par = tmprow->par()->FirstPhysicalPar();
+#else
+       LyXParagraph * first_phys_par = tmprow->par();
+#endif
        // find the first row of the paragraph
        if (first_phys_par != tmprow->par())
                while (tmprow->previous() && tmprow->previous()->par() != first_phys_par)  {
@@ -1000,7 +1016,11 @@ void LyXText::RedoParagraphs(BufferView * bview, LyXCursor const & cur,
        if (!tmprow->previous()){
                first_phys_par = FirstParagraph();   // a trick/hack for UNDO
        } else {
+#ifndef NEW_INSETS
                first_phys_par = tmprow->par()->FirstPhysicalPar();
+#else
+               first_phys_par = tmprow->par();
+#endif
                // find the first row of the paragraph
                if (first_phys_par != tmprow->par())
                        while (tmprow->previous() &&
@@ -1422,12 +1442,20 @@ void LyXText::SetParagraph(BufferView * bview,
        }
 
        // make sure that the depth behind the selection are restored, too
+#ifndef NEW_INSETS
        LyXParagraph * endpar = sel_end_cursor.par()->LastPhysicalPar()->Next();
+#else
+       LyXParagraph * endpar = sel_end_cursor.par()->Next();
+#endif
        LyXParagraph * undoendpar = endpar;
 
        if (endpar && endpar->GetDepth()) {
                while (endpar && endpar->GetDepth()) {
+#ifndef NEW_INSETS
                        endpar = endpar->LastPhysicalPar()->Next();
+#else
+                       endpar = endpar->Next();
+#endif
                        undoendpar = endpar;
                }
        }
@@ -1435,20 +1463,31 @@ void LyXText::SetParagraph(BufferView * bview,
                endpar = endpar->Next(); // because of parindents etc.
        }
    
-       SetUndo(bview->buffer(), Undo::EDIT, 
+       SetUndo(bview->buffer(), Undo::EDIT,
+#ifndef NEW_INSETS
                sel_start_cursor
-               .par()->ParFromPos(sel_start_cursor.pos())->previous, 
+               .par()->ParFromPos(sel_start_cursor.pos())->previous,
+#else
+               sel_start_cursor.par()->previous,
+#endif
                undoendpar);
 
        
        LyXParagraph * tmppar = sel_end_cursor.par();
+#ifndef NEW_INSETS
        while (tmppar != sel_start_cursor.par()->FirstPhysicalPar()->Previous()) {
                SetCursor(bview, tmppar->FirstPhysicalPar(), 0);
+#else
+       while (tmppar != sel_start_cursor.par()->Previous()) {
+               SetCursor(bview, tmppar, 0);
+#endif
                status = LyXText::NEED_MORE_REFRESH;
                refresh_row = cursor.row();
                refresh_y = cursor.y() - cursor.row()->baseline();
+#ifndef NEW_INSETS
                if (cursor.par()->footnoteflag ==
                    sel_start_cursor.par()->footnoteflag) {
+#endif
                        cursor.par()->line_top = line_top;
                        cursor.par()->line_bottom = line_bottom;
                        cursor.par()->pagebreak_top = pagebreak_top;
@@ -1472,9 +1511,13 @@ void LyXText::SetParagraph(BufferView * bview,
                        }
                        cursor.par()->SetLabelWidthString(labelwidthstring);
                        cursor.par()->noindent = noindent;
+#ifndef NEW_INSETS
                }
                
                tmppar = cursor.par()->FirstPhysicalPar()->Previous();
+#else
+               tmppar = cursor.par()->Previous();
+#endif
        }
        
        RedoParagraphs(bview, sel_start_cursor, endpar);
@@ -1502,12 +1545,20 @@ void LyXText::SetParagraphExtraOpt(BufferView * bview, int type,
        }
 
        // make sure that the depth behind the selection are restored, too
+#ifndef NEW_INSETS
        LyXParagraph * endpar = sel_end_cursor.par()->LastPhysicalPar()->Next();
+#else
+       LyXParagraph * endpar = sel_end_cursor.par()->Next();
+#endif
        LyXParagraph * undoendpar = endpar;
 
        if (endpar && endpar->GetDepth()) {
                while (endpar && endpar->GetDepth()) {
+#ifndef NEW_INSETS
                        endpar = endpar->LastPhysicalPar()->Next();
+#else
+                       endpar = endpar->Next();
+#endif
                        undoendpar = endpar;
                }
        }
@@ -1515,19 +1566,30 @@ void LyXText::SetParagraphExtraOpt(BufferView * bview, int type,
                endpar = endpar->Next(); // because of parindents etc.
        }
    
-       SetUndo(bview->buffer(), Undo::EDIT, 
+       SetUndo(bview->buffer(), Undo::EDIT,
+#ifndef NEW_INSETS
                sel_start_cursor
-               .par()->ParFromPos(sel_start_cursor.pos())->previous, 
+               .par()->ParFromPos(sel_start_cursor.pos())->previous,
+#else
+               sel_start_cursor.par()->previous,
+#endif
                undoendpar);
        
        tmppar = sel_end_cursor.par();
+#ifndef NEW_INSETS
        while(tmppar != sel_start_cursor.par()->FirstPhysicalPar()->Previous()) {
                 SetCursor(bview, tmppar->FirstPhysicalPar(), 0);
+#else
+       while(tmppar != sel_start_cursor.par()->Previous()) {
+                SetCursor(bview, tmppar, 0);
+#endif
                 status = LyXText::NEED_MORE_REFRESH;
                 refresh_row = cursor.row();
                 refresh_y = cursor.y() - cursor.row()->baseline();
+#ifndef NEW_INSETS
                 if (cursor.par()->footnoteflag ==
                     sel_start_cursor.par()->footnoteflag) {
+#endif
                         if (type == LyXParagraph::PEXTRA_NONE) {
                                 if (cursor.par()->pextra_type != LyXParagraph::PEXTRA_NONE) {
                                         cursor.par()->UnsetPExtraType(bview->buffer()->params);
@@ -1540,8 +1602,12 @@ void LyXText::SetParagraphExtraOpt(BufferView * bview, int type,
                                 cursor.par()->pextra_start_minipage = start_minipage;
                                 cursor.par()->pextra_alignment = alignment;
                         }
-                }
+#ifndef NEW_INSETS
+               }
                 tmppar = cursor.par()->FirstPhysicalPar()->Previous();
+#else
+                tmppar = cursor.par()->Previous();
+#endif
         }
        RedoParagraphs(bview, sel_start_cursor, endpar);
        ClearSelection();
@@ -1604,9 +1670,10 @@ char const * romanCounter(int n)
 // set the counter of a paragraph. This includes the labels
 void LyXText::SetCounter(Buffer const * buf, LyXParagraph * par) const
 {
+#ifndef NEW_INSETS
        // this is only relevant for the beginning of paragraph
        par = par->FirstPhysicalPar();
-       
+#endif
        LyXLayout const & layout =
                textclasslist.Style(buf->params.textclass, 
                                    par->GetLayout());
@@ -1617,9 +1684,11 @@ void LyXText::SetCounter(Buffer const * buf, LyXParagraph * par) const
        /* copy the prev-counters to this one, unless this is the start of a 
           footnote or of a bibliography or the very first paragraph */
        if (par->Previous()
+#ifndef NEW_INSETS
            && !(par->Previous()->footnoteflag == LyXParagraph::NO_FOOTNOTE 
                    && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE
                    && par->footnotekind == LyXParagraph::FOOTNOTE)
+#endif
            && !(textclasslist.Style(buf->params.textclass,
                                par->Previous()->GetLayout()
                                ).labeltype != LABEL_BIBLIO
@@ -1627,15 +1696,24 @@ void LyXText::SetCounter(Buffer const * buf, LyXParagraph * par) const
                for (int i = 0; i < 10; ++i) {
                        par->setCounter(i, par->Previous()->GetFirstCounter(i));
                }
+#ifndef NEW_INSETS
                par->appendix = par->Previous()->FirstPhysicalPar()->appendix;
+#else
+               par->appendix = par->Previous()->appendix;
+#endif
                if (!par->appendix && par->start_of_appendix){
                  par->appendix = true;
                  for (int i = 0; i < 10; ++i) {
                    par->setCounter(i, 0);
                  }  
                }
+#ifndef NEW_INSETS
                par->enumdepth = par->Previous()->FirstPhysicalPar()->enumdepth;
                par->itemdepth = par->Previous()->FirstPhysicalPar()->itemdepth;
+#else
+               par->enumdepth = par->Previous()->enumdepth;
+               par->itemdepth = par->Previous()->itemdepth;
+#endif
        } else {
                for (int i = 0; i < 10; ++i) {
                        par->setCounter(i, 0);
@@ -1975,9 +2053,9 @@ void LyXText::SetCounter(Buffer const * buf, LyXParagraph * par) const
                                   && par->footnotekind == LyXParagraph::ALGORITHM) {
                                s = (par->getParLanguage(buf->params)->lang() == "hebrew")
                                        ? ":íúéøåâìà" : "Algorithm:";
-                       }
+                       } else
 #endif
-                       else if (isOK) {
+                       if (isOK) {
                                InsetFloat * tmp = static_cast<InsetFloat*>(par->InInset()->owner());
                                Floating const & fl
                                        = floatList.getType(tmp->type());
@@ -2011,10 +2089,14 @@ void LyXText::UpdateCounters(BufferView * bview, Row * row) const
        } else {
                if (row->par()->next
 #ifndef NEW_INSETS
-                   && row->par()->next->footnoteflag != LyXParagraph::OPEN_FOOTNOTE)
+                   && row->par()->next->footnoteflag != LyXParagraph::OPEN_FOOTNOTE
 #endif
-                       {
+                       ) {
+#ifndef NEW_INSETS
                        par = row->par()->LastPhysicalPar()->Next();
+#else
+                       par = row->par()->Next();
+#endif
                } else {
                        par = row->par()->next;
                }
@@ -2028,8 +2110,11 @@ void LyXText::UpdateCounters(BufferView * bview, Row * row) const
                
                /* now  check for the headline layouts. remember that they
                 * have a dynamic left margin */ 
-               if (!par->IsDummy()
-                   && ( textclasslist.Style(bview->buffer()->params.textclass,
+               if (
+#ifndef NEW_INSETS
+                       !par->IsDummy() &&
+#endif
+                   ( textclasslist.Style(bview->buffer()->params.textclass,
                                             par->layout).margintype == MARGIN_DYNAMIC
                         || textclasslist.Style(bview->buffer()->params.textclass,
                                                par->layout).labeltype == LABEL_SENSITIVE)
@@ -2054,8 +2139,11 @@ void LyXText::UpdateCounters(BufferView * bview, Row * row) const
                        }
 #endif
                }
-     
+#ifndef NEW_INSETS
                par = par->LastPhysicalPar()->Next();
+#else
+               par = par->Next();
+#endif
      
        }
 }
@@ -2066,9 +2154,15 @@ void LyXText::InsertInset(BufferView * bview, Inset * inset)
 {
        if (!cursor.par()->InsertInsetAllowed(inset))
                return;
-       SetUndo(bview->buffer(), Undo::INSERT, 
+       SetUndo(bview->buffer(), Undo::INSERT,
+#ifndef NEW_INSETS
                cursor.par()->ParFromPos(cursor.pos())->previous, 
-               cursor.par()->ParFromPos(cursor.pos())->next);
+               cursor.par()->ParFromPos(cursor.pos())->next
+#else
+               cursor.par()->previous, 
+               cursor.par()->next
+#endif
+               );
        cursor.par()->InsertInset(cursor.pos(), inset);
        InsertChar(bview, LyXParagraph::META_INSET);  /* just to rebreak and refresh correctly.
                                      * The character will not be inserted a
@@ -2106,13 +2200,11 @@ void LyXText::CutSelection(BufferView * bview, bool doclear)
    
        // OK, we have a selection. This is always between sel_start_cursor
        // and sel_end cursor
-       LyXParagraph * tmppar;
-
 #ifndef NEW_INSETS
        // Check whether there are half footnotes in the selection
        if (sel_start_cursor.par()->footnoteflag != LyXParagraph::NO_FOOTNOTE
            || sel_end_cursor.par()->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
-               tmppar = sel_start_cursor.par();
+       LyXParagraph * tmppar = sel_start_cursor.par();
                while (tmppar != sel_end_cursor.par()){
                        if (tmppar->footnoteflag != sel_end_cursor.par()->footnoteflag) {
                                WriteAlert(_("Impossible operation"),
@@ -2138,27 +2230,46 @@ void LyXText::CutSelection(BufferView * bview, bool doclear)
        /* table stuff -- end */
 #endif
        // make sure that the depth behind the selection are restored, too
+#ifndef NEW_INSETS
        LyXParagraph * endpar = sel_end_cursor.par()->LastPhysicalPar()->Next();
+#else
+       LyXParagraph * endpar = sel_end_cursor.par()->Next();
+#endif
        LyXParagraph * undoendpar = endpar;
     
        if (endpar && endpar->GetDepth()) {
                while (endpar && endpar->GetDepth()) {
+#ifndef NEW_INSETS
                        endpar = endpar->LastPhysicalPar()->Next();
+#else
+                       endpar = endpar->Next();
+#endif
                        undoendpar = endpar;
                }
        } else if (endpar) {
                endpar = endpar->Next(); // because of parindents etc.
        }
     
-       SetUndo(bview->buffer(), Undo::DELETE, sel_start_cursor
-               .par()->ParFromPos(sel_start_cursor.pos())->previous, undoendpar);
+       SetUndo(bview->buffer(), Undo::DELETE,
+#ifndef NEW_INSETS
+               sel_start_cursor
+               .par()->ParFromPos(sel_start_cursor.pos())->previous,
+#else
+               sel_start_cursor.par()->previous,
+#endif
+               undoendpar);
     
        CutAndPaste cap;
 
        // there are two cases: cut only within one paragraph or
        // more than one paragraph
+#ifndef NEW_INSETS
        if (sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos()) 
-           == sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())) {
+           == sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos()))
+#else
+       if (sel_start_cursor.par() == sel_end_cursor.par())
+#endif
+               {
                // only within one paragraph
                endpar = sel_start_cursor.par();
                int pos = sel_end_cursor.pos();
@@ -2212,13 +2323,12 @@ void LyXText::CopySelection(BufferView * bview)
 
        // ok we have a selection. This is always between sel_start_cursor
        // and sel_end cursor
-       LyXParagraph * tmppar;
 
 #ifndef NEW_INSETS
        /* check wether there are half footnotes in the selection */
        if (sel_start_cursor.par()->footnoteflag != LyXParagraph::NO_FOOTNOTE
            || sel_end_cursor.par()->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
-               tmppar = sel_start_cursor.par();
+               LyXParagraph * tmppar = sel_start_cursor.par();
                while (tmppar != sel_end_cursor.par()) {
                        if (tmppar->footnoteflag !=
                            sel_end_cursor.par()->footnoteflag) {
@@ -2268,9 +2378,15 @@ void LyXText::PasteSelection(BufferView * bview)
        if (!cap.checkPastePossible(cursor.par(), cursor.pos()))
                return;
 
-       SetUndo(bview->buffer(), Undo::INSERT, 
+       SetUndo(bview->buffer(), Undo::INSERT,
+#ifndef NEW_INSETS
                cursor.par()->ParFromPos(cursor.pos())->previous, 
-               cursor.par()->ParFromPos(cursor.pos())->next); 
+               cursor.par()->ParFromPos(cursor.pos())->next
+#else
+               cursor.par()->previous, 
+               cursor.par()->next
+#endif
+               ); 
 
        LyXParagraph * endpar;
        LyXParagraph * actpar = cursor.par();
@@ -2409,7 +2525,6 @@ void LyXText::InsertStringA(BufferView * bview, string const & str)
        LyXParagraph * par = cursor.par();
        LyXParagraph::size_type pos = cursor.pos();
        LyXParagraph::size_type a = 0;
-        int cell = 0;
        LyXParagraph * endpar = cursor.par()->Next();
        
        SetCursorParUndo(bview->buffer());
@@ -2429,7 +2544,7 @@ void LyXText::InsertStringA(BufferView * bview, string const & str)
                            && pos && par->GetChar(pos - 1)!= ' ') {
                                par->InsertChar(pos, ' ', current_font);
                                ++pos;
-#ifndef NEW_TABLAR
+#ifndef NEW_TABULAR
                        } else if (par->table) {
                                if (str[i] == '\t') {
                                        while((pos < par->size()) &&
@@ -2486,7 +2601,7 @@ void LyXText::InsertStringA(BufferView * bview, string const & str)
                                       (par->GetChar(pos) != LyXParagraph::META_NEWLINE))
                                         ++pos;
                                 ++pos;
-                                cell = NumberOfCell(par, pos);
+                                int cell = NumberOfCell(par, pos);
                                 while((pos < par->size()) &&
                                       !(par->table->IsFirstCell(cell))) {
 
@@ -2538,14 +2653,24 @@ void LyXText::InsertStringA(BufferView * bview, string const & str)
 void LyXText::InsertStringB(BufferView * bview, string const & s)
 {
        string str(s);
+#ifndef NEW_TABULAR
        LyXParagraph * par = cursor.par();
+#endif
        string::size_type i = 1;
        while (i < str.length()) {
-               if (str[i] == '\t' && !par->table)
+               if (str[i] == '\t'
+#ifndef NEW_TABULAR
+                   && !par->table
+#endif
+                       )
                        str[i] = ' ';
                if (str[i] == ' ' && i + 1 < str.length() && str[i + 1] == ' ')
                        str[i] = 13;
-               if (str[i] == '\n' && i + 1 < str.length() && !par->table){
+               if (str[i] == '\n' && i + 1 < str.length()
+#ifndef NEW_TABULAR
+                   && !par->table
+#endif
+                       ){
                        if (str[i + 1] != '\n') {
                                if (str[i - 1] != ' ')
                                        str[i] = ' ';
@@ -2747,13 +2872,13 @@ void LyXText::SetCursor(BufferView * bview, LyXParagraph * par,
 void LyXText::SetCursor(BufferView *bview, LyXCursor & cur, LyXParagraph * par,
                        LyXParagraph::size_type pos, bool boundary) const
 {
+#ifndef NEW_INSETS
        // correct the cursor position if impossible
        if (pos > par->Last()){
                LyXParagraph * tmppar = par->ParFromPos(pos);
                pos = par->PositionInParFromPos(pos);
                par = tmppar;
        }
-#ifndef NEW_INSETS
        if (par->IsDummy() && par->previous &&
            par->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
                while (par->previous &&
@@ -2805,8 +2930,11 @@ void LyXText::SetCursor(BufferView *bview, LyXCursor & cur, LyXParagraph * par,
                cursor_vpos = (row->par()->isRightToLeftPar(bview->buffer()->params))
                        ? row->pos() : last + 1; 
        else if (pos > row->pos() &&
-                (pos > last || boundary || 
-                 (row->par()->table && row->par()->IsNewline(pos))))
+                (pos > last || boundary
+#ifndef NEW_TABULAR
+                 || (row->par()->table && row->par()->IsNewline(pos))
+#endif
+                        ))
                /// Place cursor after char at (logical) position pos - 1
                cursor_vpos = (bidi_level(pos - 1) % 2 == 0)
                        ? log2vis(pos - 1) + 1 : log2vis(pos - 1);
@@ -2895,8 +3023,11 @@ void LyXText::SetCurrentFont(BufferView * bview) const
                --pos;
 
        if (pos > 0) {
-               if (pos == cursor.par()->Last() ||
-                   (cursor.par()->table && cursor.par()->IsNewline(pos)))
+               if (pos == cursor.par()->Last()
+#ifndef NEW_TABULAR
+                   || (cursor.par()->table && cursor.par()->IsNewline(pos))
+#endif
+                       )
                        --pos;
                else if (cursor.par()->IsSeparator(pos)) {
                        if (pos > cursor.row()->pos() &&
@@ -3010,7 +3141,11 @@ void LyXText::CursorRight(BufferView * bview, bool internal) const
 void LyXText::CursorRightIntern(BufferView * bview, bool internal) const
 {
        if (!internal && cursor.boundary() &&
-           (!cursor.par()->table || !cursor.par()->IsNewline(cursor.pos())))
+           (
+#ifndef NEW_TABULAR
+                   !cursor.par()->table ||
+#endif
+                   !cursor.par()->IsNewline(cursor.pos())))
                SetCursor(bview, cursor.par(), cursor.pos(), true, false);
        else if (cursor.pos() < cursor.par()->Last()) {
                SetCursor(bview, cursor.par(), cursor.pos() + 1, true, false);
@@ -3160,12 +3295,17 @@ void LyXText::DeleteEmptyParagraphMechanism(BufferView * bview,
                if ( (old_cursor.par()->Last() == 0
                      || (old_cursor.par()->Last() == 1
                          && old_cursor.par()->IsLineSeparator(0)))
+#ifndef NEW_INSETS
                     && old_cursor.par()->FirstPhysicalPar()
-                    == old_cursor.par()->LastPhysicalPar()) {
+                    == old_cursor.par()->LastPhysicalPar()
+#endif
+                       ) {
                        // ok, we will delete anything
                        
                        // make sure that you do not delete any environments
-                       if ((old_cursor.par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE &&
+#ifndef NEW_INSETS
+                       if ((
+                               old_cursor.par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE &&
                             !(old_cursor.row()->previous() 
                               && old_cursor.row()->previous()->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)
                             && !(old_cursor.row()->next() 
@@ -3176,6 +3316,7 @@ void LyXText::DeleteEmptyParagraphMechanism(BufferView * bview,
                                    || (old_cursor.row()->next()
                                        && old_cursor.row()->next()->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE))
                                    )) {
+#endif
                                status = LyXText::NEED_MORE_REFRESH;
                                deleted = true;
                                
@@ -3187,7 +3328,11 @@ void LyXText::DeleteEmptyParagraphMechanism(BufferView * bview,
                                        LyXParagraph * endpar = old_cursor.par()->next;
                                        if (endpar && endpar->GetDepth()) {
                                                while (endpar && endpar->GetDepth()) {
+#ifndef NEW_INSETS
                                                        endpar = endpar->LastPhysicalPar()->Next();
+#else
+                                                       endpar = endpar->Next();
+#endif
                                                }
                                        }
                                        SetUndo(bview->buffer(), Undo::DELETE,
@@ -3222,7 +3367,11 @@ void LyXText::DeleteEmptyParagraphMechanism(BufferView * bview,
                                        LyXParagraph * endpar = old_cursor.par()->next;
                                        if (endpar && endpar->GetDepth()) {
                                                while (endpar && endpar->GetDepth()) {
+#ifndef NEW_INSETS
                                                        endpar = endpar->LastPhysicalPar()->Next();
+#else
+                                                       endpar = endpar->Next();
+#endif
                                                }
                                        }
                                        SetUndo(bview->buffer(), Undo::DELETE,
@@ -3259,7 +3408,9 @@ void LyXText::DeleteEmptyParagraphMechanism(BufferView * bview,
                                        // correct selection
                                        sel_cursor = cursor;
                                }
+#ifndef NEW_INSETS
                        }
+#endif
                }
                if (!deleted) {
                        if (old_cursor.par()->StripLeadingSpaces(bview->buffer()->params.textclass)) {
@@ -3390,7 +3541,11 @@ bool LyXText::TextHandleUndo(BufferView * bview, Undo * undo)
     
                // Set the cursor for redoing
                if (before) {
+#ifndef NEW_INSETS
                        SetCursorIntern(bview, before->FirstSelfrowPar(), 0);
+#else
+                       SetCursorIntern(bview, before, 0);
+#endif
 #ifndef NEW_INSETS
                        // check wether before points to a closed float and open it if necessary
                        if (before && before->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE
@@ -3423,11 +3578,11 @@ bool LyXText::TextHandleUndo(BufferView * bview, Undo * undo)
                if (behind) {
 #ifndef NEW_INSETS
                        if (behind->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
-#endif
                                endpar = behind->LastPhysicalPar()->Next();
-#ifndef NEW_INSETS
                        else
                                endpar = behind->NextAfterFootnote()->LastPhysicalPar()->Next();
+#else
+                               endpar = behind->Next();
 #endif
                } else
                        endpar = behind;
@@ -3576,9 +3731,14 @@ Undo * LyXText::CreateUndo(Buffer * buf, Undo::undo_kind kind,
                tmppar2->next = 0;
        } else
                undopar = 0; // nothing to replace (undo of delete maybe)
-  
+
+#ifndef NEW_INSETS
        int cursor_par = cursor.par()->ParFromPos(cursor.pos())->id();
        int cursor_pos =  cursor.par()->PositionInParFromPos(cursor.pos());
+#else
+       int cursor_par = cursor.par()->id();
+       int cursor_pos =  cursor.pos();
+#endif
 
        Undo * undo = new Undo(kind, 
                               before_number, behind_number,  
@@ -3594,9 +3754,15 @@ void LyXText::SetCursorParUndo(Buffer * buf)
 {
        if (inset_owner)
                return;
-       SetUndo(buf, Undo::FINISH, 
+       SetUndo(buf, Undo::FINISH,
+#ifndef NEW_INSETS
                cursor.par()->ParFromPos(cursor.pos())->previous, 
-               cursor.par()->ParFromPos(cursor.pos())->next); 
+               cursor.par()->ParFromPos(cursor.pos())->next
+#else
+               cursor.par()->previous, 
+               cursor.par()->next
+#endif
+               ); 
 }
 
 
@@ -3666,7 +3832,11 @@ bool LyXText::IsEmptyTableCell() const
 
 void LyXText::toggleAppendix(BufferView * bview)
 {
+#ifndef NEW_INSETS
        LyXParagraph * par = cursor.par()->FirstPhysicalPar();
+#else
+       LyXParagraph * par = cursor.par();
+#endif
        bool start = !par->start_of_appendix;
 
        // ensure that we have only one start_of_appendix in this document