]> git.lyx.org Git - lyx.git/blobdiff - src/text2.C
more changes, read the Changelog
[lyx.git] / src / text2.C
index c119a12ebf8efc9129a225b268cbd8ab7ec46e9c..5eabab4c0f102cdac9e362ffdfb5310a29908711 100644 (file)
@@ -22,6 +22,7 @@
 #include "insets/inseterror.h"
 #include "insets/insetbib.h"
 #include "insets/insetspecialchar.h"
+#include "insets/insettext.h"
 #include "layout.h"
 #include "LyXView.h"
 #include "support/textutils.h"
@@ -69,6 +70,8 @@ void LyXText::init()
        number_of_rows = 0;
        refresh_y = 0;
        height = 0;
+       width = 0;
+       first = 0;
        status = LyXText::UNCHANGED;
        // set cursor at the very top position
        selection = true;           /* these setting is necessary 
@@ -129,9 +132,10 @@ void LyXText::init(BufferView * bview)
                par = par->Next();
        }
        SetCursorIntern(bview, firstrow->par(), 0);
-#if 1
+#if 0
        // Dump all rowinformation:
        Row * tmprow = firstrow;
+       lyxerr << "Width = " << width << endl;
        lyxerr << "Baseline Paragraph Pos Height Ascent Fill\n";
        while (tmprow) {
                lyxerr << tmprow->baseline() << '\t'
@@ -158,14 +162,6 @@ LyXText::~LyXText()
 }
 
 
-#if 0
-void LyXText::owner(BufferView * bv)
-{
-       if (bv_owner && bv) lyxerr << "LyXText::bv_owner already set!" << endl;
-       bv_owner = bv;
-}
-#endif
-
 // Gets the fully instantiated font at a given position in a paragraph
 // Basically the same routine as LyXParagraph::getFont() in paragraph.C.
 // The difference is that this one is used for displaying, and thus we
@@ -239,13 +235,14 @@ LyXFont LyXText::GetFont(Buffer const * buf, LyXParagraph * par,
 
        tmpfont.realize(textclasslist.TextClass(buf->params.textclass).defaultfont());
 
+#ifndef NEW_INSETS
        // Cosmetic improvement: If this is an open footnote, make the font 
        // smaller.
        if (par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE
            && par->footnotekind == LyXParagraph::FOOTNOTE) {
                tmpfont.decSize();
        }
-
+#endif
        return tmpfont;
 }
 
@@ -287,11 +284,12 @@ void LyXText::SetCharFont(Buffer const * buf, LyXParagraph * par,
 
        layoutfont.realize(textclasslist.TextClass(buf->params.textclass).defaultfont());
 
+#ifndef NEW_INSETS
        if (par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE
            && par->footnotekind == LyXParagraph::FOOTNOTE) {
                layoutfont.decSize();
        }
-
+#endif
        // Now, reduce font against full layout font
        font.reduce(layoutfont);
 
@@ -390,8 +388,9 @@ void LyXText::InsertParagraph(BufferView * bview, LyXParagraph * par,
                AppendParagraph(bview, row->next());
        }
 }
-    
 
+
+#ifndef NEW_INSETS
 void LyXText::ToggleFootnote(BufferView * bview)
 {
        LyXParagraph * par = cursor.par()->ParFromPos(cursor.pos());
@@ -404,6 +403,7 @@ void LyXText::ToggleFootnote(BufferView * bview)
                CloseFootnote(bview);
        }
 }
+#endif
 
 
 void LyXText::OpenStuff(BufferView * bview)
@@ -425,6 +425,7 @@ void LyXText::OpenStuff(BufferView * bview)
 }
 
 
+#ifndef NEW_INSETS
 void LyXText::CloseFootnote(BufferView * bview)
 {
        LyXParagraph * tmppar;
@@ -494,11 +495,13 @@ void LyXText::CloseFootnote(BufferView * bview)
        if (cursor.row()->next())
                SetHeightOfRow(bview, cursor.row()->next());
 }
+#endif
 
 
 /* used in setlayout */
 // Asger is not sure we want to do this...
-void LyXText::MakeFontEntriesLayoutSpecific(Buffer const * buf, LyXParagraph * par)
+void LyXText::MakeFontEntriesLayoutSpecific(Buffer const * buf,
+                                           LyXParagraph * par)
 {
    
        LyXLayout const & layout =
@@ -518,6 +521,7 @@ void LyXText::MakeFontEntriesLayoutSpecific(Buffer const * buf, LyXParagraph * p
        }
 }
 
+
 LyXParagraph * LyXText::SetLayout(BufferView * bview,
                                  LyXCursor & cur, LyXCursor & sstart_cur,
                                  LyXCursor & send_cur,
@@ -681,7 +685,7 @@ void LyXText::SetLayout(BufferView * bview, LyXTextClass::size_type layout)
                  false);
        UpdateCounters(bview, cursor.row());
        ClearSelection();
-       SetSelection(bview);
+       SetSelection();
        SetCursor(bview, tmpcursor.par(), tmpcursor.pos(), true);
 }
 
@@ -697,7 +701,8 @@ void  LyXText::IncDepth(BufferView * bview)
        }
 
        // We end at the next paragraph with depth 0
-       LyXParagraph * endpar = sel_end_cursor.par()->LastPhysicalPar()->Next();
+       LyXParagraph * endpar =
+               sel_end_cursor.par()->LastPhysicalPar()->Next();
        LyXParagraph * undoendpar = endpar;
 
        if (endpar && endpar->GetDepth()) {
@@ -767,7 +772,7 @@ void  LyXText::IncDepth(BufferView * bview)
        SetCursor(bview, sel_end_cursor.par(), sel_end_cursor.pos());
        UpdateCounters(bview, cursor.row());
        ClearSelection();
-       SetSelection(bview);
+       SetSelection();
        SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
 }
 
@@ -828,7 +833,7 @@ void  LyXText::DecDepth(BufferView * bview)
        SetCursor(bview, sel_end_cursor.par(), sel_end_cursor.pos());
        UpdateCounters(bview, cursor.row());
        ClearSelection();
-       SetSelection(bview);
+       SetSelection();
        SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
 }
 
@@ -898,7 +903,7 @@ void LyXText::SetFont(BufferView * bview, LyXFont const & font, bool toggleall)
        sel_cursor = cursor;
        SetCursor(bview, sel_end_cursor.par(), sel_end_cursor.pos());
        ClearSelection();
-       SetSelection(bview);
+       SetSelection();
        SetCursor(bview, tmpcursor.par(), tmpcursor.pos(), true,
                  tmpcursor.boundary());
 }
@@ -1047,6 +1052,10 @@ void LyXText::RedoParagraphs(BufferView * bview, LyXCursor const & cur,
 
 bool LyXText::FullRebreak(BufferView * bview)
 {
+       if (!firstrow) {
+               init(bview);
+               return true;
+       }
        if (need_break_row) {
                BreakAgain(bview, need_break_row);
                need_break_row = 0;
@@ -1064,7 +1073,7 @@ bool LyXText::FullRebreak(BufferView * bview)
  * They also delete the corresponding row */
    
 // need the selection cursor:
-void LyXText::SetSelection(BufferView * bview)
+void LyXText::SetSelection()
 {
        if (!selection) {
                last_sel_cursor = sel_cursor;
@@ -1111,16 +1120,6 @@ void LyXText::SetSelection(BufferView * bview)
        if (sel_start_cursor.par() == sel_end_cursor.par() && 
            sel_start_cursor.pos() == sel_end_cursor.pos())
                selection = false;
-
-       // Stuff what we got on the clipboard. Even if there is no selection.
-
-       // There is a problem with having the stuffing here in that the
-       // larger the selection the slower LyX will get. This can be
-       // solved by running the line below only when the selection has
-       // finished. The solution used currently just works, to make it
-       // faster we need to be more clever and probably also have more
-       // calls to stuffClipboard. (Lgb)
-       bview->stuffClipboard(selectionAsString(bview->buffer()));
 }
 
 
@@ -1240,7 +1239,8 @@ Row * LyXText::GetRowNearY(long & y) const
 }
 
 
-void LyXText::ToggleFree(BufferView * bview, LyXFont const & font, bool toggleall)
+void LyXText::ToggleFree(BufferView * bview,
+                        LyXFont const & font, bool toggleall)
 {
        // If the mask is completely neutral, tell user
        if (font == LyXFont(LyXFont::ALL_IGNORE)) {
@@ -1273,7 +1273,8 @@ void LyXText::ToggleFree(BufferView * bview, LyXFont const & font, bool toggleal
 
 
 LyXParagraph::size_type
-LyXText::BeginningOfMainBody(Buffer const * buf, LyXParagraph const * par) const
+LyXText::BeginningOfMainBody(Buffer const * buf,
+                            LyXParagraph const * par) const
 {
        if (textclasslist.Style(buf->params.textclass,
                                par->GetLayout()).labeltype != LABEL_MANUAL)
@@ -1283,6 +1284,7 @@ LyXText::BeginningOfMainBody(Buffer const * buf, LyXParagraph const * par) const
 }
 
 
+#ifndef NEW_INSETS
 /* if there is a selection, reset every environment you can find
 * in the selection, otherwise just the environment you are in */ 
 void LyXText::MeltFootnoteEnvironment(BufferView * bview)
@@ -1377,6 +1379,7 @@ void LyXText::MeltFootnoteEnvironment(BufferView * bview)
    
        ClearSelection();
 }
+#endif
 
 
 /* the DTP switches for paragraphs. LyX will store them in the 
@@ -1462,7 +1465,7 @@ void LyXText::SetParagraph(BufferView * bview,
        SetCursor(bview, sel_start_cursor.par(), sel_start_cursor.pos());
        sel_cursor = cursor;
        SetCursor(bview, sel_end_cursor.par(), sel_end_cursor.pos());
-       SetSelection(bview);
+       SetSelection();
        SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
 }
 
@@ -1527,7 +1530,7 @@ void LyXText::SetParagraphExtraOpt(BufferView * bview, int type,
        SetCursor(bview, sel_start_cursor.par(), sel_start_cursor.pos());
        sel_cursor = cursor;
        SetCursor(bview, sel_end_cursor.par(), sel_end_cursor.pos());
-       SetSelection(bview);
+       SetSelection();
        SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
 }
 
@@ -1620,6 +1623,7 @@ void LyXText::SetCounter(Buffer const * buf, LyXParagraph * par) const
                par->itemdepth = 0;
        }
 
+#ifndef NEW_INSETS
         // if this is an open marginnote and this is the first
         // entry in the marginnote and the enclosing
         // environment is an enum/item then correct for the
@@ -1641,7 +1645,7 @@ void LyXText::SetCounter(Buffer const * buf, LyXParagraph * par) const
                 par->enumdepth++;
                 par->itemdepth++;
         }
-
+#endif
        /* Maybe we have to increment the enumeration depth.
         * BUT, enumeration in a footnote is considered in isolation from its
         *      surrounding paragraph so don't increment if this is the
@@ -1993,7 +1997,8 @@ void LyXText::UpdateCounters(BufferView * bview, Row * row) const
                        /* Rebreak the paragraph */ 
                        RemoveParagraph(row);
                        AppendParagraph(bview, row);
-       
+
+#ifndef NEW_INSETS
                        /* think about the damned open footnotes! */ 
                        while (par->Next() &&
                               (par->Next()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE
@@ -2006,6 +2011,7 @@ void LyXText::UpdateCounters(BufferView * bview, Row * row) const
                                        AppendParagraph(bview, row);
                                }
                        }
+#endif
                }
      
                par = par->LastPhysicalPar()->Next();
@@ -2015,14 +2021,13 @@ void LyXText::UpdateCounters(BufferView * bview, Row * row) const
 
 
 /* insets an inset. */ 
-void LyXText::InsertInset(BufferView * bview, Inset *inset)
+void LyXText::InsertInset(BufferView * bview, Inset * inset)
 {
        if (!cursor.par()->InsertInsetAllowed(inset))
                return;
        SetUndo(bview->buffer(), Undo::INSERT, 
                cursor.par()->ParFromPos(cursor.pos())->previous, 
                cursor.par()->ParFromPos(cursor.pos())->next);
-       cursor.par()->InsertChar(cursor.pos(), LyXParagraph::META_INSET);
        cursor.par()->InsertInset(cursor.pos(), inset);
        InsertChar(bview, LyXParagraph::META_INSET);  /* just to rebreak and refresh correctly.
                                      * The character will not be inserted a
@@ -2030,26 +2035,6 @@ void LyXText::InsertInset(BufferView * bview, Inset *inset)
 }
 
 
-#ifdef USE_OLD_CUT_AND_PASTE
-// this is for the simple cut and paste mechanism
-static LyXParagraph * simple_cut_buffer = 0;
-static char simple_cut_buffer_textclass = 0;
-
-void DeleteSimpleCutBuffer()
-{
-       if (!simple_cut_buffer)
-               return;
-       LyXParagraph * tmppar;
-
-       while (simple_cut_buffer) {
-               tmppar =  simple_cut_buffer;
-               simple_cut_buffer = simple_cut_buffer()->next;
-               delete tmppar;
-       }
-       simple_cut_buffer = 0;
-}
-#endif
-
 void LyXText::copyEnvironmentType()
 {
        copylayouttype = cursor.par()->GetLayout();
@@ -2061,9 +2046,19 @@ void LyXText::pasteEnvironmentType(BufferView * bview)
        SetLayout(bview, copylayouttype);
 }
 
-#ifdef USE_OLD_CUT_AND_PASTE
-void LyXText::CutSelection(Buffer const * buf, bool doclear)
+
+void LyXText::CutSelection(BufferView * bview, bool doclear)
 {
+       // Stuff what we got on the clipboard. Even if there is no selection.
+
+       // There is a problem with having the stuffing here in that the
+       // larger the selection the slower LyX will get. This can be
+       // solved by running the line below only when the selection has
+       // finished. The solution used currently just works, to make it
+       // faster we need to be more clever and probably also have more
+       // calls to stuffClipboard. (Lgb)
+       bview->stuffClipboard(selectionAsString(bview->buffer()));
+
        // This doesn't make sense, if there is no selection
        if (!selection)
                return;
@@ -2071,7 +2066,8 @@ void LyXText::CutSelection(Buffer const * buf, 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) {
@@ -2086,7 +2082,7 @@ void LyXText::CutSelection(Buffer const * buf, bool doclear)
                        tmppar = tmppar->Next();
                }
        }
-
+#endif
 #ifndef NEW_TABULAR
        /* table stuff -- begin */
        if (sel_start_cursor.par()->table || sel_end_cursor.par()->table) {
@@ -2100,11 +2096,10 @@ void LyXText::CutSelection(Buffer const * buf, bool doclear)
        }
        /* table stuff -- end */
 #endif
-       
        // make sure that the depth behind the selection are restored, too
        LyXParagraph * endpar = sel_end_cursor.par()->LastPhysicalPar()->Next();
        LyXParagraph * undoendpar = endpar;
-
+    
        if (endpar && endpar->GetDepth()) {
                while (endpar && endpar->GetDepth()) {
                        endpar = endpar->LastPhysicalPar()->Next();
@@ -2113,362 +2108,63 @@ void LyXText::CutSelection(Buffer const * buf, bool doclear)
        } 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);
-   
-       // clear the simple_cut_buffer
-       DeleteSimpleCutBuffer();
-   
-       // set the textclass
-       simple_cut_buffer_textclass = buf->params.textclass;
-
-#ifdef WITH_WARNINGS
-#warning Asger: Make cut more intelligent here.
-#endif
-       /* 
-          White paper for "intelligent" cutting:
-          
-          Example: "This is our text."
-          Using " our " as selection, cutting will give "This istext.".
-          Using "our" as selection, cutting will give "This is text.".
-          Using " our" as selection, cutting will give "This is text.".
-          Using "our " as selection, cutting will give "This is text.".
-          
-          All those four selections will (however) paste identically:
-          Pasting with the cursor right after the "is" will give the
-          original text with all four selections.
-          
-          The rationale is to be intelligent such that words are copied,
-          cut and pasted in a functional manner.
-          
-          This is not implemented yet. (Asger)
-
-          The changes below sees to do a lot of what you want. However
-          I have not verified that all cases work as they should:
-                    - cut in single row
-                    - cut in multiple row
-                    - cut with insets
-                    - cut across footnotes and paragraph
-          My simplistic tests show that the idea are basically sound but
-          there are some items to fix up...we only need to find them
-          first.
-
-          As do redo Asger's example above (with | beeing the cursor in the
-          result after cutting.):
-          
-          Example: "This is our text."
-          Using " our " as selection, cutting will give "This is|text.".
-          Using "our"   as selection, cutting will give "This is | text.".
-          Using " our"  as selection, cutting will give "This is| text.".
-          Using "our "  as selection, cutting will give "This is |text.".
-
-          (Lgb)
-       */
+    
+       SetUndo(bview->buffer(), Undo::DELETE, sel_start_cursor
+               .par()->ParFromPos(sel_start_cursor.pos())->previous, undoendpar);
+    
+       CutAndPaste cap;
 
        // there are two cases: cut only within one paragraph or
        // more than one paragraph
-   
        if (sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos()) 
            == sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())) {
                // only within one paragraph
-               simple_cut_buffer = new LyXParagraph;
-               LyXParagraph::size_type i =
-                       sel_start_cursor.pos();
-               for (; i < sel_end_cursor.pos(); ++i) {
-#ifndef NEW_TABULAR
-                       /* table stuff -- begin */
-                       if (sel_start_cursor.par()->table
-                           && sel_start_cursor.par()->IsNewline(sel_start_cursor.pos())) {
-                               sel_start_cursor.par()->CopyIntoMinibuffer(sel_start_cursor.pos());
-                               sel_start_cursor.pos()++;
-                       } else {
-                               /* table stuff -- end */
-#endif
-                               sel_start_cursor.par()->CopyIntoMinibuffer(sel_start_cursor.pos());
-                               sel_start_cursor.par()->Erase(sel_start_cursor.pos());
-#ifndef NEW_TABULAR
-                       }
-#endif
-                       simple_cut_buffer->InsertFromMinibuffer(simple_cut_buffer->Last());
-               }
-               endpar = sel_end_cursor.par()->Next();
+               endpar = sel_start_cursor.par();
+               int pos = sel_end_cursor.pos();
+               cap.cutSelection(sel_start_cursor.par(), &endpar,
+                                sel_start_cursor.pos(), pos,
+                                bview->buffer()->params.textclass, doclear);
+               sel_end_cursor.pos(pos);
        } else {
-               // cut more than one paragraph
-   
-               sel_end_cursor.par()
-                       ->BreakParagraphConservative(sel_end_cursor.pos());
-               sel_end_cursor.par() = sel_end_cursor.par()->Next();
-               sel_end_cursor.pos() = 0;
-   
-               cursor = sel_end_cursor;
-
-               sel_start_cursor.par()
-                       ->BreakParagraphConservative(sel_start_cursor.pos());
-               // store the endparagraph for redoing later
-               endpar = sel_end_cursor.par()->Next(); /* needed because
-                                                       the sel_end_
-                                                       cursor.par()
-                                                       will be pasted! */
-   
-               // store the selection
-               simple_cut_buffer = sel_start_cursor.par()
-                       ->ParFromPos(sel_start_cursor.pos())->next;
-               simple_cut_buffer->previous = 0;
-               sel_end_cursor.par()->previous->next = 0;
-
-               // cut the selection
-               sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos())->next 
-                       = sel_end_cursor.par();
-   
-               sel_end_cursor.par()->previous 
-                       = sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos());
-
-               // care about footnotes
-               if (simple_cut_buffer->footnoteflag) {
-                       LyXParagraph * tmppar = simple_cut_buffer;
-                       while (tmppar){
-                               tmppar->footnoteflag = LyXParagraph::NO_FOOTNOTE;
-                               tmppar = tmppar->next;
-                       }
-               }
+               endpar = sel_end_cursor.par();
 
-               // the cut selection should begin with standard layout
-               simple_cut_buffer->Clear(); 
-   
-               // paste the paragraphs again, if possible
-               if (doclear)
-                       sel_start_cursor.par()->Next()->StripLeadingSpaces(simple_cut_buffer_textclass);
-               if (sel_start_cursor.par()->FirstPhysicalPar()->HasSameLayout(sel_start_cursor.par()->Next())
-                   || 
-                   !sel_start_cursor.par()->Next()->Last())
-                       sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos())->PasteParagraph();
+               int pos = sel_end_cursor.pos();
+               cap.cutSelection(sel_start_cursor.par(), &endpar,
+                                sel_start_cursor.pos(), pos,
+                                bview->buffer()->params.textclass, doclear);
+               cursor.par(endpar);
+               sel_end_cursor.par(endpar);
+               sel_end_cursor.pos(pos);
+               cursor.pos(sel_end_cursor.pos());
        }
+       endpar = endpar->Next();
 
        // sometimes necessary
        if (doclear)
-               sel_start_cursor.par()->StripLeadingSpaces(simple_cut_buffer_textclass);
+               sel_start_cursor.par()->StripLeadingSpaces(bview->buffer()->params.textclass);
 
-       RedoParagraphs(sel_start_cursor, endpar);
+       RedoParagraphs(bview, sel_start_cursor, endpar);
    
        ClearSelection();
        cursor = sel_start_cursor;
-       SetCursor(cursor.par(), cursor.pos());
+       SetCursor(bview, cursor.par(), cursor.pos());
        sel_cursor = cursor;
-       UpdateCounters(cursor.row());
+       UpdateCounters(bview, cursor.row());
 }
 
-#else ///////////////////////////////////////////////////////////////////
-
-void LyXText::CutSelection(BufferView * bview, bool doclear)
-{
-    // This doesn't make sense, if there is no selection
-    if (!selection)
-       return;
-   
-    // OK, we have a selection. This is always between sel_start_cursor
-    // and sel_end cursor
-    LyXParagraph * tmppar;
-    
-    // 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();
-       while (tmppar != sel_end_cursor.par()){
-           if (tmppar->footnoteflag != sel_end_cursor.par()->footnoteflag) {
-               WriteAlert(_("Impossible operation"),
-                          _("Don't know what to do with half floats."),
-                          _("sorry."));
-               return;
-                       }
-           tmppar = tmppar->Next();
-       }
-    }
 
-#ifndef NEW_TABULAR
-    /* table stuff -- begin */
-    if (sel_start_cursor.par()->table || sel_end_cursor.par()->table) {
-       if ( sel_start_cursor.par() != sel_end_cursor.par()) {
-           WriteAlert(_("Impossible operation"),
-                      _("Don't know what to do with half tables."),
-                      _("sorry."));
-           return;
-       }
-       sel_start_cursor.par()->table->Reinit();
-    }
-    /* table stuff -- end */
-#endif
-    
-    // make sure that the depth behind the selection are restored, too
-    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(bview->buffer(), Undo::DELETE, sel_start_cursor
-           .par()->ParFromPos(sel_start_cursor.pos())->previous, undoendpar);
-    
-    CutAndPaste cap;
-
-    // there are two cases: cut only within one paragraph or
-    // more than one paragraph
-    if (sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos()) 
-       == sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())) {
-       // only within one paragraph
-       endpar = sel_start_cursor.par();
-       int pos = sel_end_cursor.pos();
-       cap.cutSelection(sel_start_cursor.par(), &endpar,
-                        sel_start_cursor.pos(), pos,
-                        bview->buffer()->params.textclass, doclear);
-       sel_end_cursor.pos(pos);
-    } else {
-       endpar = sel_end_cursor.par();
-
-       int pos = sel_end_cursor.pos();
-       cap.cutSelection(sel_start_cursor.par(), &endpar,
-                        sel_start_cursor.pos(), pos,
-                        bview->buffer()->params.textclass, doclear);
-       cursor.par(endpar);
-       sel_end_cursor.par(endpar);
-       sel_end_cursor.pos(pos);
-       cursor.pos(sel_end_cursor.pos());
-    }
-    endpar = endpar->Next();
-
-    // sometimes necessary
-    if (doclear)
-       sel_start_cursor.par()->StripLeadingSpaces(bview->buffer()->params.textclass);
-
-    RedoParagraphs(bview, sel_start_cursor, endpar);
-   
-    ClearSelection();
-    cursor = sel_start_cursor;
-    SetCursor(bview, cursor.par(), cursor.pos());
-    sel_cursor = cursor;
-    UpdateCounters(bview, cursor.row());
-}
-#endif
-    
-#ifdef USE_OLD_CUT_AND_PASTE
-void LyXText::CopySelection(Buffer const * buf)
+void LyXText::CopySelection(BufferView * bview)
 {
-       // this doesnt make sense, if there is no selection
-       if (!selection)
-               return;
-
-       // ok we have a selection. This is always between sel_start_cursor
-       // and sel_end cursor
-       LyXParagraph * tmppar;
-   
-       /* 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();
-               while (tmppar != sel_end_cursor.par()) {
-                       if (tmppar->footnoteflag !=
-                           sel_end_cursor.par()->footnoteflag) {
-                               WriteAlert(_("Impossible operation"),
-                                          _("Don't know what to do"
-                                            " with half floats."),
-                                          _("sorry."));
-                               return;
-                       }
-                       tmppar = tmppar->Next();
-               }
-       }
-
-#ifndef NEW_TABULAR
-       /* table stuff -- begin */
-       if (sel_start_cursor.par()->table || sel_end_cursor.par()->table){
-               if ( sel_start_cursor.par() != sel_end_cursor.par()){
-                       WriteAlert(_("Impossible operation"),
-                                  _("Don't know what to do with half tables."),
-                                  _("sorry."));
-                       return;
-               }
-       }
-       /* table stuff -- end */
-#endif
-       
-       // delete the simple_cut_buffer
-       DeleteSimpleCutBuffer();
-
-       // set the textclass
-       simple_cut_buffer_textclass = buf->params.textclass;
-
-       // copy behind a space if there is one
-       while (sel_start_cursor.par()->Last() > sel_start_cursor.pos()
-              && sel_start_cursor.par()->IsLineSeparator(sel_start_cursor.pos())
-              && (sel_start_cursor.par() != sel_end_cursor.par()
-                  || sel_start_cursor.pos() < sel_end_cursor.pos()))
-               sel_start_cursor.pos()++; 
-
-       // there are two cases: copy only within one paragraph
-       // or more than one paragraph
-       if (sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos()) 
-           == sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())) {
-               // only within one paragraph
-               simple_cut_buffer = new LyXParagraph;
-               LyXParagraph::size_type i = 0;
-               for (i = sel_start_cursor.pos(); i < sel_end_cursor.pos(); ++i){
-                       sel_start_cursor.par()->CopyIntoMinibuffer(i);
-                       simple_cut_buffer->InsertFromMinibuffer(i - sel_start_cursor.pos());
-               }
-       } else {
-               // copy more than one paragraph
-               // clone the paragraphs within the selection
-               tmppar =
-                       sel_start_cursor.par()->ParFromPos(sel_start_cursor.pos());
-               simple_cut_buffer = tmppar->Clone();
-               LyXParagraph *tmppar2 = simple_cut_buffer;
-     
-               while (tmppar != sel_end_cursor.par()->ParFromPos(sel_end_cursor.pos())
-                      && tmppar->next) {
-                       tmppar = tmppar->next;
-                       tmppar2->next = tmppar->Clone();
-                       tmppar2->next->previous = tmppar2;
-                       tmppar2 = tmppar2->next;
-               }
-               tmppar2->next = 0;
-
-               // care about footnotes
-               if (simple_cut_buffer->footnoteflag) {
-                       tmppar = simple_cut_buffer;
-                       while (tmppar){
-                               tmppar->footnoteflag =
-                                       LyXParagraph::NO_FOOTNOTE;
-                               tmppar = tmppar->next;
-                       }
-               }
-               
-               // the simple_cut_buffer paragraph is too big
-               LyXParagraph::size_type tmpi2 =
-                       sel_start_cursor.par()->PositionInParFromPos(sel_start_cursor.pos());
-               for (; tmpi2; --tmpi2)
-                       simple_cut_buffer->Erase(0);
-               
-               // now tmppar 2 is too big, delete all after sel_end_cursor.pos()
-     
-               tmpi2 = sel_end_cursor.par()->PositionInParFromPos(sel_end_cursor.pos());
-               while (tmppar2->size() > tmpi2) {
-                       tmppar2->Erase(tmppar2->size() - 1);
-               }
-       }
-}
+       // Stuff what we got on the clipboard. Even if there is no selection.
 
-#else //////////////////////////////////////////////////////////////////////
+       // There is a problem with having the stuffing here in that the
+       // larger the selection the slower LyX will get. This can be
+       // solved by running the line below only when the selection has
+       // finished. The solution used currently just works, to make it
+       // faster we need to be more clever and probably also have more
+       // calls to stuffClipboard. (Lgb)
+       bview->stuffClipboard(selectionAsString(bview->buffer()));
 
-void LyXText::CopySelection(Buffer const * buf)
-{
        // this doesnt make sense, if there is no selection
        if (!selection)
                return;
@@ -2476,7 +2172,8 @@ void LyXText::CopySelection(Buffer const * buf)
        // 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) {
@@ -2493,7 +2190,7 @@ void LyXText::CopySelection(Buffer const * buf)
                        tmppar = tmppar->Next();
                }
        }
-
+#endif
 #ifndef NEW_TABULAR
        /* table stuff -- begin */
        if (sel_start_cursor.par()->table || sel_end_cursor.par()->table){
@@ -2518,222 +2215,9 @@ void LyXText::CopySelection(Buffer const * buf)
 
        cap.copySelection(sel_start_cursor.par(), sel_end_cursor.par(),
                          sel_start_cursor.pos(), sel_end_cursor.pos(),
-                         buf->params.textclass);
+                         bview->buffer()->params.textclass);
 }
-#endif          
-
-#ifdef USE_OLD_CUT_AND_PASTE
-void LyXText::PasteSelection(Buffer const * buf)
-{
-       // this does not make sense, if there is nothing to paste
-       if (!simple_cut_buffer)
-               return;
-
-       LyXParagraph * tmppar;
-       LyXParagraph * endpar;
-
-       LyXCursor tmpcursor;
-
-       // be carefull with footnotes in footnotes
-       if (cursor.par()->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
-      
-               // check whether the cut_buffer includes a footnote
-               tmppar = simple_cut_buffer;
-               while (tmppar
-                      && tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
-                       tmppar = tmppar->next;
-      
-               if (tmppar) {
-                       WriteAlert(_("Impossible operation"),
-                                  _("Can't paste float into float!"),
-                                  _("Sorry."));
-                       return;
-               }
-       }
-
-#ifndef NEW_TABULAR
-       /* table stuff -- begin */
-       if (cursor.par()->table) {
-               if (simple_cut_buffer->next) {
-                       WriteAlert(_("Impossible operation"),
-                                  _("Table cell cannot include more than one paragraph!"),
-                                  _("Sorry."));
-                       return;
-               }
-       }
-       /* table stuff -- end */
-#endif
-   
-       SetUndo(bview->buffer(), Undo::INSERT, 
-               cursor.par()->ParFromPos(cursor.pos())->previous, 
-               cursor.par()->ParFromPos(cursor.pos())->next); 
 
-       tmpcursor = cursor;
-
-       // There are two cases: cutbuffer only one paragraph or many
-       if (!simple_cut_buffer->next) {
-               // only within a paragraph
-
-               tmppar = simple_cut_buffer->Clone();
-#ifndef NEW_TABULAR
-               /* table stuff -- begin */
-               bool table_too_small = false;
-               if (tmpcursor.par()->table) {
-                       while (simple_cut_buffer->size()
-                              && !table_too_small) {
-                               if (simple_cut_buffer->IsNewline(0)){
-                                       while(tmpcursor.pos() < tmpcursor.par()->Last() && !tmpcursor.par()->IsNewline(tmpcursor.pos()))
-                                               tmpcursor.pos()++;
-                                       simple_cut_buffer->Erase(0);
-                                       if (tmpcursor.pos() < tmpcursor.par()->Last())
-                                               tmpcursor.pos()++;
-                                       else
-                                               table_too_small = true;
-                               } else {
-                                       // This is an attempt to fix the
-                                       // "never insert a space at the
-                                       // beginning of a paragraph" problem.
-                                       if (tmpcursor.pos() == 0
-                                           && simple_cut_buffer->IsLineSeparator(0)) {
-                                               simple_cut_buffer->Erase(0);
-                                       } else {
-                                               simple_cut_buffer->CutIntoMinibuffer(0);
-                                               simple_cut_buffer->Erase(0);
-                                               tmpcursor.par()->InsertFromMinibuffer(tmpcursor.pos());
-                                               tmpcursor.pos()++;
-                                       }
-                               }
-                       }
-               } else {
-#endif
-                       /* table stuff -- end */
-                       // Some provisions should be done here for checking
-                       // if we are inserting at the beginning of a
-                       // paragraph. If there are a space at the beginning
-                       // of the text to insert and we are inserting at
-                       // the beginning of the paragraph the space should
-                       // be removed.
-                       while (simple_cut_buffer->size()) {
-                               // This is an attempt to fix the
-                               // "never insert a space at the
-                               // beginning of a paragraph" problem.
-                               if (tmpcursor.pos() == 0
-                                   && simple_cut_buffer->IsLineSeparator(0)) {
-                                       simple_cut_buffer->Erase(0);
-                               } else {
-                                       simple_cut_buffer->CutIntoMinibuffer(0);
-                                       simple_cut_buffer->Erase(0);
-                                       tmpcursor.par()->InsertFromMinibuffer(tmpcursor.pos());
-                                       tmpcursor.pos()++;
-                               }
-                       }
-#ifndef NEW_TABULAR
-               }
-#endif
-               delete simple_cut_buffer;
-               simple_cut_buffer = tmppar;
-               endpar = tmpcursor.par()->Next();
-       } else {
-               // many paragraphs
-               CutAndPaste cap;
-
-               // make a copy of the simple cut_buffer
-               tmppar = simple_cut_buffer;
-               LyXParagraph * simple_cut_clone = tmppar->Clone();
-               LyXParagraph * tmppar2 = simple_cut_clone;
-               if (cursor.par()->footnoteflag){
-                       tmppar->footnoteflag = cursor.par()->footnoteflag;
-                       tmppar->footnotekind = cursor.par()->footnotekind;
-               }
-               while (tmppar->next) {
-                       tmppar = tmppar->next;
-                       tmppar2->next = tmppar->Clone();
-                       tmppar2->next->previous = tmppar2;
-                       tmppar2 = tmppar2->next;
-                       if (cursor.par()->footnoteflag){
-                               tmppar->footnoteflag = cursor.par()->footnoteflag;
-                               tmppar->footnotekind = cursor.par()->footnotekind;
-                       }
-               }
-     
-               // make sure there is no class difference
-               cap.SwitchLayoutsBetweenClasses(simple_cut_buffer_textclass,
-                                               buf->params.textclass,
-                                               simple_cut_buffer);
-     
-               // make the simple_cut_buffer exactly the same layout than
-               // the cursor paragraph
-               simple_cut_buffer->MakeSameLayout(cursor.par());
-     
-               // find the end of the buffer
-               LyXParagraph * lastbuffer = simple_cut_buffer;
-               while (lastbuffer->Next())
-                       lastbuffer = lastbuffer->Next();
-     
-               bool paste_the_end = false;
-
-               // open the paragraph for inserting the simple_cut_buffer
-               // if necessary
-               if (cursor.par()->Last() > cursor.pos() || !cursor.par()->Next()){
-                       cursor.par()->BreakParagraphConservative(cursor.pos());
-                       paste_the_end = true;
-               }
-
-               // set the end for redoing later
-               endpar = cursor.par()->ParFromPos(cursor.pos())->next->Next();
-     
-               // paste it!
-               lastbuffer->ParFromPos(lastbuffer->Last())->next =
-                       cursor.par()->ParFromPos(cursor.pos())->next;
-               cursor.par()->ParFromPos(cursor.pos())->next->previous =
-                       lastbuffer->ParFromPos(lastbuffer->Last());
-     
-               cursor.par()->ParFromPos(cursor.pos())->next = simple_cut_buffer;
-               simple_cut_buffer->previous =
-                       cursor.par()->ParFromPos(cursor.pos());
-   
-               if (cursor.par()->ParFromPos(cursor.pos())->Next() == lastbuffer)
-                       lastbuffer = cursor.par();
-     
-               cursor.par()->ParFromPos(cursor.pos())->PasteParagraph();
-     
-               // store the new cursor position
-               tmpcursor.par() = lastbuffer;
-               tmpcursor.pos() = lastbuffer->Last();
-     
-               // maybe some pasting
-               if (lastbuffer->Next() && paste_the_end) {
-                       if (lastbuffer->Next()->HasSameLayout(lastbuffer)) {
-                               lastbuffer->ParFromPos(lastbuffer->Last())->PasteParagraph();
-        
-                       } else if (!lastbuffer->Next()->Last()) {
-                               lastbuffer->Next()->MakeSameLayout(lastbuffer);
-                               lastbuffer->ParFromPos(lastbuffer->Last())->PasteParagraph();
-        
-                       } else if (!lastbuffer->Last()) {
-                               lastbuffer->MakeSameLayout(lastbuffer->next);
-                               lastbuffer->ParFromPos(lastbuffer->Last())->PasteParagraph();
-        
-                       } else
-                               lastbuffer->Next()->StripLeadingSpaces(buffer->params.textclass);
-               }
-
-               // restore the simple cut buffer
-               simple_cut_buffer = simple_cut_clone;
-       }
-
-       RedoParagraphs(cursor, endpar);
-    
-       SetCursor(cursor.par(), cursor.pos());
-       ClearSelection();
-   
-       sel_cursor = cursor;
-       SetCursor(tmpcursor.par(), tmpcursor.pos());
-       SetSelection();
-       UpdateCounters(cursor.row());
-}
-
-#else ////////////////////////////////////////////////////////////////////
 
 void LyXText::PasteSelection(BufferView * bview)
 {
@@ -2760,10 +2244,10 @@ void LyXText::PasteSelection(BufferView * bview)
    
        sel_cursor = cursor;
        SetCursor(bview, actpar, pos);
-       SetSelection(bview);
+       SetSelection();
        UpdateCounters(bview, cursor.row());
 }
-#endif   
+
 
 // returns a pointer to the very first LyXParagraph
 LyXParagraph * LyXText::FirstParagraph() const
@@ -2796,7 +2280,7 @@ void LyXText::SetSelectionOverString(BufferView * bview, char const * string)
        sel_cursor = cursor;
        for (int i = 0; string[i]; ++i)
                CursorRight(bview);
-       SetSelection(bview);
+       SetSelection();
 }
 
 
@@ -2818,8 +2302,7 @@ void LyXText::ReplaceSelectionWithString(BufferView * bview, char const * str)
 
        // Insert the new string
        for (int i = 0; str[i]; ++i) {
-               sel_end_cursor.par()->InsertChar(pos, str[i]);
-               sel_end_cursor.par()->SetFont(pos, font);
+               sel_end_cursor.par()->InsertChar(pos, str[i], font);
                ++pos;
        }
 
@@ -2903,8 +2386,7 @@ void LyXText::InsertStringA(BufferView * bview, string const & str)
                        if (str[i] == ' ' 
                            && i + 1 < str.length() && str[i + 1] != ' '
                            && pos && par->GetChar(pos - 1)!= ' ') {
-                               par->InsertChar(pos,' ');
-                               par->SetFont(pos, current_font);
+                               par->InsertChar(pos, ' ', current_font);
                                ++pos;
 #ifndef NEW_TABLAR
                        } else if (par->table) {
@@ -2918,8 +2400,8 @@ void LyXText::InsertStringA(BufferView * bview, string const & str)
                                                break;
                                } else if ((str[i] != 13) &&
                                           ((str[i] & 127) >= ' ')) {
-                                       par->InsertChar(pos, str[i]);
-                                       par->SetFont(pos, current_font);
+                                       par->InsertChar(pos, str[i],
+                                                       current_font);
                                        ++pos;
                                }
 #endif
@@ -2927,9 +2409,8 @@ void LyXText::InsertStringA(BufferView * bview, string const & str)
                                InsetSpecialChar * new_inset =
                                        new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
                                if (par->InsertInsetAllowed(new_inset)) {
-                                       par->InsertChar(pos, LyXParagraph::META_INSET);
-                                       par->SetFont(pos, current_font);
-                                       par->InsertInset(pos, new_inset);
+                                       par->InsertInset(pos, new_inset,
+                                                        current_font);
                                } else {
                                        delete new_inset;
                                }
@@ -2939,9 +2420,8 @@ void LyXText::InsertStringA(BufferView * bview, string const & str)
                                InsetSpecialChar * new_inset =
                                        new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
                                if (par->InsertInsetAllowed(new_inset)) {
-                                       par->InsertChar(pos, LyXParagraph::META_INSET);
-                                       par->SetFont(pos, current_font);
-                                       par->InsertInset(pos, new_inset);
+                                       par->InsertInset(pos, new_inset,
+                                                        current_font);
                                } else {
                                        delete new_inset;
                                }
@@ -2950,8 +2430,7 @@ void LyXText::InsertStringA(BufferView * bview, string const & str)
                        } else if (str[i] != 13 && 
                                   // Ignore unprintables
                                   (str[i] & 127) >= ' ') {
-                               par->InsertChar(pos, str[i]);
-                               par->SetFont(pos, current_font);
+                               par->InsertChar(pos, str[i], current_font);
                                ++pos;
                        }
                } else {
@@ -2985,9 +2464,9 @@ void LyXText::InsertStringA(BufferView * bview, string const & str)
                                        InsetSpecialChar * new_inset =
                                                new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
                                        if (par->InsertInsetAllowed(new_inset)) {
-                                               par->InsertChar(pos, LyXParagraph::META_INSET);
-                                               par->SetFont(pos, current_font);
-                                               par->InsertInset(pos, new_inset);
+                                               par->InsertInset(pos,
+                                                                new_inset,
+                                                                current_font);
                                        } else {
                                                delete new_inset;
                                        }
@@ -3007,7 +2486,7 @@ void LyXText::InsertStringA(BufferView * bview, string const & str)
        SetCursor(bview, cursor.par(), cursor.pos());
        sel_cursor = cursor;
        SetCursor(bview, par, pos);
-       SetSelection(bview);
+       SetSelection();
 }
 
 
@@ -3181,14 +2660,14 @@ void LyXText::CheckParagraph(BufferView * bview, LyXParagraph * par,
 }
 
 
-// returns 0 if inset wasn't found
-int LyXText::UpdateInset(BufferView * bview, Inset * inset)
+// returns false if inset wasn't found
+bool LyXText::UpdateInset(BufferView * bview, Inset * inset)
 {
        // first check the current paragraph
        int pos = cursor.par()->GetPositionOfInset(inset);
        if (pos != -1){
                CheckParagraph(bview, cursor.par(), pos);
-               return 1;
+               return true;
        }
   
        // check every paragraph
@@ -3200,13 +2679,13 @@ int LyXText::UpdateInset(BufferView * bview, Inset * inset)
                        pos = par->GetPositionOfInset(inset);
                        if (pos != -1){
                                CheckParagraph(bview, par, pos);
-                               return 1;
+                               return true;
                        }
                }
                par = par->Next();
        } while (par);
   
-       return 0;
+       return false;
 }
 
 
@@ -3229,6 +2708,7 @@ void LyXText::SetCursor(BufferView *bview, LyXCursor & cur, LyXParagraph * par,
                pos = par->PositionInParFromPos(pos);
                par = tmppar;
        }
+#ifndef NEW_INSETS
        if (par->IsDummy() && par->previous &&
            par->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
                while (par->previous &&
@@ -3248,7 +2728,7 @@ void LyXText::SetCursor(BufferView *bview, LyXCursor & cur, LyXParagraph * par,
                }
                pos += par->size() + 1;
        }
-
+#endif
        cur.par(par);
        cur.pos(pos);
        cur.boundary(boundary);
@@ -3359,127 +2839,6 @@ void LyXText::SetCursorIntern(BufferView * bview, LyXParagraph * par,
                              bool setfont, bool boundary) const
 {
        SetCursor(bview, cursor, par, pos, boundary);
-// #warning Remove this when verified working (Jug 20000413)
-#if 0
-       // correct the cursor position if impossible
-       if (pos > par->Last()){
-               LyXParagraph * tmppar = par->ParFromPos(pos);
-               pos = par->PositionInParFromPos(pos);
-               par = tmppar;
-       }
-       if (par->IsDummy() && par->previous &&
-           par->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
-               while (par->previous &&
-                      ((par->previous->IsDummy() && par->previous->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) ||
-                       (par->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))) {
-                       par = par->previous ;
-                       if (par->IsDummy() &&
-                           par->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
-                               pos += par->size() + 1;
-               }
-               if (par->previous) {
-                       par = par->previous;
-               }
-               pos += par->size() + 1;
-       }
-
-       cursor.par() = par;
-       cursor.pos() = pos;
-
-       /* get the cursor y position in text  */
-       long y = 0;
-       Row * row = GetRow(par, pos, y);
-       /* y is now the beginning of the cursor row */ 
-       y += row->baseline();
-       /* y is now the cursor baseline */ 
-       cursor.y() = y;
-   
-       /* now get the cursors x position */
-       float x;
-       float fill_separator, fill_hfill, fill_label_hfill;
-       PrepareToPrint(row, x, fill_separator, fill_hfill, fill_label_hfill);
-       LyXParagraph::size_type cursor_vpos;
-       LyXParagraph::size_type last = RowLastPrintable(row);
-
-       if (pos > last + 1)   // This shouldn't happen.
-               pos = last+1;
-
-       if (last < row->pos())
-                cursor_vpos = 0;
-       else if (pos > last ||
-           (pos - 1 >= row->pos() &&
-            (row->par()->IsSeparator(pos) ||
-             (row->par()->table && row->par()->IsNewline(pos))
-             )))
-               /// Place cursor after char at (logical) position pos-1
-               cursor_vpos = (bidi_level(pos-1) % 2 == 0)
-                       ? log2vis(pos-1) + 1 : log2vis(pos-1);
-       else
-               /// Place cursor before char at (logical) position pos
-               cursor_vpos = (bidi_level(pos) % 2 == 0)
-                       ? log2vis(pos) : log2vis(pos) + 1;
-
-#ifndef NEW_TABULAR
-       /* table stuff -- begin*/
-       if (row->par()->table) {
-               int cell = NumberOfCell(row->par(), row->pos());
-               float x_old = x;
-               x += row->par()->table->GetBeginningOfTextInCell(cell);
-               for (LyXParagraph::size_type vpos = row->pos(); vpos < cursor_vpos; ++vpos)  {
-                       pos = vis2log(vpos);
-                       if (row->par()->IsNewline(pos)) {
-                               x = x_old + row->par()->table->WidthOfColumn(cell);
-                               x_old = x;
-                               ++cell;
-                               x += row->par()->table->GetBeginningOfTextInCell(cell);
-                       } else {
-                               x += SingleWidth(row->par(), pos);
-                       }
-               }
-       } else {
-               /* table stuff -- end*/
-#endif
-               LyXParagraph::size_type main_body =
-                       BeginningOfMainBody(row->par());
-               if (main_body > 0 &&
-                   (main_body-1 > last || 
-                    !row->par()->IsLineSeparator(main_body-1)))
-                       main_body = 0;
-
-               for (LyXParagraph::size_type vpos = row->pos(); vpos < cursor_vpos; ++vpos)  {
-                       pos = vis2log(vpos);
-                       if (main_body > 0 && pos == main_body-1) {
-                               x += fill_label_hfill +
-                                       lyxfont::width(textclasslist
-                                                      .Style(bview->buffer()->params.textclass,
-                                                             row->par()->GetLayout())
-                                                      .labelsep,
-                                                      GetFont(row->par(), -2));
-                               if (row->par()->IsLineSeparator(main_body-1))
-                                       x -= SingleWidth(row->par(), main_body-1);
-                       }
-                       if (HfillExpansion(row, pos)) {
-                               x += SingleWidth(row->par(), pos);
-                               if (pos >= main_body)
-                                       x += fill_hfill;
-                               else 
-                                       x += fill_label_hfill;
-                       }
-                       else if (row->par()->IsSeparator(pos)) {
-                               x += SingleWidth(row->par(), pos);
-                               if (pos >= main_body)
-                                       x += fill_separator;
-                       } else
-                               x += SingleWidth(row->par(), pos);
-               }
-#ifndef NEW_TABULAR
-       }
-#endif
-       cursor.x = int(x);
-   
-       cursor.x_fix = cursor.x;
-       cursor.row() = row;
-#endif
        if (setfont)
                SetCurrentFont(bview);
 }
@@ -3504,7 +2863,8 @@ void LyXText::SetCurrentFont(BufferView * bview) const
                }
        }
 
-       current_font = cursor.par()->GetFontSettings(bview->buffer()->params, pos);
+       current_font =
+               cursor.par()->GetFontSettings(bview->buffer()->params, pos);
        real_current_font = GetFont(bview->buffer(), cursor.par(), pos);
 }
 
@@ -3875,6 +3235,8 @@ LyXParagraph * LyXText::GetParFromID(int id)
 // undo functions
 bool LyXText::TextUndo(BufferView * bview)
 {
+       if (inset_owner)
+               return false;
        // returns false if no undo possible
        Undo * undo = bview->buffer()->undostack.pop();
        if (undo) {
@@ -3891,6 +3253,8 @@ bool LyXText::TextUndo(BufferView * bview)
 
 bool LyXText::TextRedo(BufferView * bview)
 {
+       if (inset_owner)
+               return false;
        // returns false if no redo possible
        Undo * undo = bview->buffer()->redostack.pop();
        if (undo) {
@@ -3907,6 +3271,8 @@ bool LyXText::TextRedo(BufferView * bview)
 
 bool LyXText::TextHandleUndo(BufferView * bview, Undo * undo)
 {
+       if (inset_owner)
+               return false;
        // returns false if no undo possible
        bool result = false;
        if (undo) {
@@ -4025,6 +3391,8 @@ bool LyXText::TextHandleUndo(BufferView * bview, Undo * undo)
 
 void LyXText::FinishUndo()
 {
+       if (inset_owner)
+               return;
        // makes sure the next operation will be stored
        undo_finished = true;
 }
@@ -4032,6 +3400,8 @@ void LyXText::FinishUndo()
 
 void LyXText::FreezeUndo()
 {
+       if (inset_owner)
+               return;
        // this is dangerous and for internal use only
        undo_frozen = true;
 }
@@ -4039,6 +3409,8 @@ void LyXText::FreezeUndo()
 
 void LyXText::UnFreezeUndo()
 {
+       if (inset_owner)
+               return;
        // this is dangerous and for internal use only
        undo_frozen = false;
 }
@@ -4048,6 +3420,8 @@ void LyXText::SetUndo(Buffer * buf, Undo::undo_kind kind,
                      LyXParagraph const * before,
                      LyXParagraph const * behind) const
 {
+       if (inset_owner)
+               return;
        if (!undo_frozen)
                buf->undostack.push(CreateUndo(buf, kind, before, behind));
        buf->redostack.clear();
@@ -4057,6 +3431,8 @@ void LyXText::SetUndo(Buffer * buf, Undo::undo_kind kind,
 void LyXText::SetRedo(Buffer * buf, Undo::undo_kind kind,
                      LyXParagraph const * before, LyXParagraph const * behind)
 {
+       if (inset_owner)
+               return;
        buf->redostack.push(CreateUndo(buf, kind, before, behind));
 }
 
@@ -4065,6 +3441,9 @@ Undo * LyXText::CreateUndo(Buffer * buf, Undo::undo_kind kind,
                           LyXParagraph const * before,
                           LyXParagraph const * behind) const
 {
+       if (inset_owner)
+               return 0;
+
        int before_number = -1;
        int behind_number = -1;
        if (before)
@@ -4078,8 +3457,7 @@ Undo * LyXText::CreateUndo(Buffer * buf, Undo::undo_kind kind,
        // appear one by one when undoing. 
        // EDIT is special since only layout information, not the
        // contents of a paragaph are stored.
-       if (!undo_finished && kind != Undo::EDIT && 
-           kind != Undo::FINISH){
+       if (!undo_finished && (kind != Undo::EDIT) && (kind != Undo::FINISH)){
                // check wether storing is needed
                if (!buf->undostack.empty() && 
                    buf->undostack.top()->kind == kind &&
@@ -4157,6 +3535,8 @@ Undo * LyXText::CreateUndo(Buffer * buf, Undo::undo_kind kind,
 
 void LyXText::SetCursorParUndo(Buffer * buf)
 {
+       if (inset_owner)
+               return;
        SetUndo(buf, Undo::FINISH, 
                cursor.par()->ParFromPos(cursor.pos())->previous, 
                cursor.par()->ParFromPos(cursor.pos())->next);