]> git.lyx.org Git - lyx.git/blobdiff - src/text.C
citation patch from Angus
[lyx.git] / src / text.C
index ae8594686eaeccd9891a919d1f16b6d5944da1ac..175ef9e90038d02efc4bbb315269b50c8a427ac6 100644 (file)
@@ -36,6 +36,7 @@
 #include "tracer.h"
 #include "font.h"
 #include "encoding.h"
+#include "lyxscreen.h"
 
 using std::max;
 using std::min;
@@ -260,8 +261,11 @@ void LyXText::ComputeBidiTables(Buffer const * buf, Row * row) const
                LyXParagraph::size_type pos =
                        (is_space && lpos + 1 <= bidi_end &&
                         !row->par()->IsLineSeparator(lpos + 1) &&
-                        (!row->par()->table
-                         || !row->par()->IsNewline(lpos + 1)) )
+                        (
+#ifndef NEW_TABULAR
+                                !row->par()->table ||
+#endif
+                                !row->par()->IsNewline(lpos + 1)) )
                        ? lpos + 1 : lpos;
                LyXFont font = row->par()->GetFontSettings(buf->params, pos);
                bool new_rtl = font.isVisibleRightToLeft();
@@ -327,7 +331,8 @@ void LyXText::ComputeBidiTables(Buffer const * buf, Row * row) const
        }
 
        LyXParagraph::size_type vpos = bidi_start - 1;
-       for (LyXParagraph::size_type lpos = bidi_start; lpos <= bidi_end; ++lpos) {
+       for (LyXParagraph::size_type lpos = bidi_start;
+            lpos <= bidi_end; ++lpos) {
                vpos += log2vis_list[lpos - bidi_start];
                vis2log_list[vpos - bidi_start] = lpos;
                log2vis_list[lpos - bidi_start] = vpos;
@@ -342,14 +347,20 @@ bool LyXText::IsBoundary(Buffer const * buf, LyXParagraph * par,
        if (!lyxrc.rtl_support)
                return false;    // This is just for speedup
 
-       if (!bidi_InRange(pos - 1) ||
-           (par->table && par->IsNewline(pos-1)) )
+       if (!bidi_InRange(pos - 1)
+#ifndef NEW_TABULAR
+           || (par->table && par->IsNewline(pos-1))
+#endif
+               )
                return false;
 
        bool rtl = bidi_level(pos - 1) % 2;
        bool rtl2 = rtl;
-       if (pos == par->Last() ||
-           (par->table && par->IsNewline(pos)))
+       if (pos == par->Last()
+#ifndef NEW_TABULAR
+           || (par->table && par->IsNewline(pos))
+#endif
+               )
                rtl2 = par->isRightToLeftPar(buf->params);
        else if (bidi_InRange(pos))
                rtl2 = bidi_level(pos) % 2;
@@ -366,8 +377,11 @@ bool LyXText::IsBoundary(Buffer const * buf, LyXParagraph * par,
 
        bool rtl = font.isVisibleRightToLeft();
        bool rtl2 = rtl;
-       if (pos == par->Last() ||
-           (par->table && par->IsNewline(pos)))
+       if (pos == par->Last()
+#ifndef NEW_TABULAR
+           || (par->table && par->IsNewline(pos))
+#endif
+               )
                rtl2 = par->isRightToLeftPar(buf->params);
        else if (bidi_InRange(pos))
                rtl2 =  bidi_level(pos) % 2;
@@ -504,8 +518,10 @@ void LyXText::draw(BufferView * bview, Row const * row,
 //                     tmpinset->update(bview, font, false);
                        tmpinset->draw(bview, font, offset+row->baseline(), x,
                                       cleared);
-                       if (status == CHANGED_IN_DRAW)
+                       if (status == CHANGED_IN_DRAW) {
                                UpdateInset(bview, tmpinset);
+                               status = CHANGED_IN_DRAW;
+                       }
                }
                ++vpos;
 
@@ -673,7 +689,11 @@ int LyXText::LeftMargin(BufferView * bview, Row const * row) const
        if (!row->par()->GetDepth()) {
                if (!row->par()->GetLayout()) {
                        // find the previous same level paragraph
+#ifndef NEW_INSETS
                        if (row->par()->FirstPhysicalPar()->Previous()) {
+#else
+                       if (row->par()->Previous()) {
+#endif
                                LyXParagraph * newpar = row->par()
                                        ->DepthHook(row->par()->GetDepth());
                                if (newpar &&
@@ -692,7 +712,10 @@ int LyXText::LeftMargin(BufferView * bview, Row const * row) const
                // make a corresponding row. Needed to call LeftMargin()
                
                // check wether it is a sufficent paragraph 
-               if (newpar && newpar->footnoteflag == row->par()->footnoteflag
+               if (newpar
+#ifndef NEW_INSETS
+                   && newpar->footnoteflag == row->par()->footnoteflag
+#endif
                    && textclasslist
                        .Style(bview->buffer()->params.textclass, 
                               newpar->GetLayout()).isEnvironment()) {
@@ -705,11 +728,19 @@ int LyXText::LeftMargin(BufferView * bview, Row const * row) const
                        // is used to clear impossible depths after changing
                        // a layout. Since there is always a redo,
                        // LeftMargin() is always called
+#ifndef NEW_INSETS
                        row->par()->FirstPhysicalPar()->depth = 0;
+#else
+                       row->par()->depth = 0;
+#endif
                }
                
                if (newpar && !row->par()->GetLayout()) {
+#ifndef NEW_INSETS
                        if (newpar->FirstPhysicalPar()->noindent)
+#else
+                       if (newpar->noindent)
+#endif
                                parindent.erase();
                        else
                                parindent = textclasslist
@@ -825,11 +856,17 @@ int LyXText::LeftMargin(BufferView * bview, Row const * row) const
        }
        
        int align; // wrong type
+#ifndef NEW_INSETS
        if (row->par()->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
                align = layout.align;
        else
                align = row->par()->FirstPhysicalPar()->align;
-       
+#else
+       if (row->par()->align == LYX_ALIGN_LAYOUT)
+               align = layout.align;
+       else
+               align = row->par()->align;
+#endif 
        // set the correct parindent
        if (row->pos() == 0) {
                if ((layout.labeltype == LABEL_NO_LABEL 
@@ -838,7 +875,9 @@ int LyXText::LeftMargin(BufferView * bview, Row const * row) const
                     || (layout.labeltype == LABEL_STATIC
                         && layout.latextype == LATEX_ENVIRONMENT
                         && ! row->par()->IsFirstInSequence()))
+#ifndef NEW_INSETS
                    && row->par() == row->par()->FirstPhysicalPar()
+#endif
                    && align == LYX_ALIGN_BLOCK
                    && !row->par()->noindent
                    && (row->par()->layout ||
@@ -888,17 +927,27 @@ int LyXText::RightMargin(Buffer const * buf, Row const * row) const
                
                LyXParagraph * newpar = row->par();
                
+#ifndef NEW_INSETS
                do {
                        newpar = newpar->FirstPhysicalPar()->Previous();
                        if (newpar) 
                                newpar = newpar->FirstPhysicalPar();
                } while (newpar && newpar->GetDepth() >= row->par()->GetDepth()
                         && newpar->footnoteflag == row->par()->footnoteflag);
+#else
+               do {
+                       newpar = newpar->Previous();
+               } while (newpar
+                        && newpar->GetDepth() >= row->par()->GetDepth());
+#endif
                
                // make a corresponding row. Needed to call LeftMargin()
                
                // check wether it is a sufficent paragraph
-               if (newpar && newpar->footnoteflag == row->par()->footnoteflag
+               if (newpar
+#ifndef NEW_INSETS
+                   && newpar->footnoteflag == row->par()->footnoteflag
+#endif
                    && textclasslist.Style(buf->params.textclass,
                                           newpar->GetLayout())
                       .isEnvironment()) {
@@ -911,7 +960,11 @@ int LyXText::RightMargin(Buffer const * buf, Row const * row) const
                        // is used to clear impossible depths after changing
                        // a layout. Since there is always a redo,
                        // LeftMargin() is always called
+#ifndef NEW_INSETS
                        row->par()->FirstPhysicalPar()->depth = 0;
+#else
+                       row->par()->depth = 0;
+#endif
                }
        }
        
@@ -1363,9 +1416,13 @@ void LyXText::SetHeightOfRow(BufferView * bview, Row * row_ptr) const
 
    /* Correction: only the fontsize count. The other properties
       are taken from the layoutfont. Nicer on the screen :) */
-   
+#ifndef NEW_INSETS   
    LyXParagraph * par = row_ptr->par()->LastPhysicalPar();
    LyXParagraph * firstpar = row_ptr->par()->FirstPhysicalPar();
+#else
+   LyXParagraph * par = row_ptr->par();
+   LyXParagraph * firstpar = row_ptr->par();
+#endif
    
    LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass,
                                                  firstpar->GetLayout());
@@ -1575,7 +1632,12 @@ void LyXText::SetHeightOfRow(BufferView * bview, Row * row_ptr) const
    }
    
    /* is it a bottom line? */ 
-   if (row_ptr->par()->ParFromPos(RowLast(row_ptr) + 1) == par
+   if (
+#ifndef NEW_INSETS
+          row_ptr->par()->ParFromPos(RowLast(row_ptr) + 1) == par
+#else
+          row_ptr->par() == par
+#endif
        && (!row_ptr->next() || row_ptr->next()->par() != row_ptr->par())) {     
          
          /* the paper margins */ 
@@ -1647,8 +1709,8 @@ void LyXText::SetHeightOfRow(BufferView * bview, Row * row_ptr) const
    
    height += row_ptr->height();
    float x, dummy;
-   PrepareToPrint(bview, row_ptr, x, dummy, dummy, dummy);
-   row_ptr->width(maxwidth+x);
+   PrepareToPrint(bview, row_ptr, x, dummy, dummy, dummy, false);
+   row_ptr->width(int(maxwidth + x));
    if (inset_owner) {
           Row * r = firstrow;
           width = max(0,workWidth(bview));
@@ -1797,14 +1859,24 @@ void LyXText::BreakParagraph(BufferView * bview, char keep_layout)
    /* table stuff -- end */
 #endif
    // this is only allowed, if the current paragraph is not empty or caption
-   if ((cursor.par()->Last() <= 0 && !cursor.par()->IsDummy())
+   if ((cursor.par()->Last() <= 0
+#ifndef NEW_INSETS
+       && !cursor.par()->IsDummy()
+#endif
+          )
        && 
        layout.labeltype!= LABEL_SENSITIVE)
      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
+          ); 
 
 #ifndef NEW_TABULAR
    /* table stuff -- begin */
@@ -1876,7 +1948,11 @@ void LyXText::BreakParagraph(BufferView * bview, char keep_layout)
 
    SetHeightOfRow(bview, cursor.row());
    
-   while (!cursor.par()->Next()->table && cursor.par()->Next()->Last()
+   while (
+#ifndef NEW_TABULAR
+          !cursor.par()->Next()->table &&
+#endif
+          cursor.par()->Next()->Last()
          && cursor.par()->Next()->IsNewline(0))
           cursor.par()->Next()->Erase(0);
    
@@ -2468,10 +2544,13 @@ void LyXText::InsertCharInTable(BufferView * bview, char c)
                if ((cursor.pos() > 0 && 
                     cursor.par()->IsLineSeparator(cursor.pos() - 1))
                    || (cursor.pos() > 0 && cursor.par()->IsNewline(cursor.pos() - 1))
-                   || (cursor.pos() == 0 &&
-                       !(cursor.par()->Previous()
+                   || (cursor.pos() == 0
+#ifndef NEW_INSETS
+                       && !(cursor.par()->Previous()
                          && cursor.par()->Previous()->footnoteflag
-                         == LyXParagraph::OPEN_FOOTNOTE)))
+                         == LyXParagraph::OPEN_FOOTNOTE)
+#endif
+                           ))
                        return;
        } else if (IsNewlineChar(c)) {
             if (!IsEmptyTableCell()) {
@@ -2645,9 +2724,15 @@ void LyXText::RedoParagraph(BufferView * bview) const
  * same Paragraph one to the right and make a rebreak */
 void LyXText::InsertChar(BufferView * bview, char c)
 {
-       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
+               );
 
        // When the free-spacing option is set for the current layout,
        // disable the double-space checking
@@ -2696,9 +2781,12 @@ void LyXText::InsertChar(BufferView * bview, char c)
                    || (cursor.pos() > 0
                        && cursor.par()->IsNewline(cursor.pos() - 1))
                    || (cursor.pos() == 0
+#ifndef NEW_INSETS
                        && !(cursor.par()->Previous()
                             && cursor.par()->Previous()->footnoteflag
-                            == LyXParagraph::OPEN_FOOTNOTE))) {
+                            == LyXParagraph::OPEN_FOOTNOTE)
+#endif
+                           )) {
                        if (cursor.pos() == 0 )
                                bview->owner()->getMiniBuffer()->Set(_("You cannot insert a space at the beginning of a paragraph.  Please read the Tutorial."));
                        else
@@ -2707,7 +2795,11 @@ void LyXText::InsertChar(BufferView * bview, char c)
                        return;
                }
        } else if (IsNewlineChar(c)) {
+#ifndef NEW_INSETS
                if (cursor.par()->FirstPhysicalPar() == cursor.par()
+#else
+               if (cursor.par() == cursor.par()
+#endif
                    && cursor.pos() <= BeginningOfMainBody(bview->buffer(), cursor.par())) {
                        charInserted();
                        return;
@@ -2886,8 +2978,8 @@ void LyXText::PrepareToPrint(BufferView * bview,
        fill_separator = 0;
        fill_label_hfill = 0;
 
-#ifndef NEW_INSETS
         bool is_rtl = row->par()->isRightToLeftPar(bview->buffer()->params);
+#ifndef NEW_INSETS
 
        if (is_rtl) {
                x = RightMargin(bview->buffer(), row);
@@ -2934,15 +3026,23 @@ void LyXText::PrepareToPrint(BufferView * bview,
                // is it block, flushleft or flushright? 
                // set x how you need it
        int align;
+#ifndef NEW_INSETS
        if (row->par()->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
          align = textclasslist.Style(bview->buffer()->params.textclass, row->par()->GetLayout()).align;
        else
          align = row->par()->FirstPhysicalPar()->align;
+#else
+       if (row->par()->align == LYX_ALIGN_LAYOUT)
+         align = textclasslist.Style(bview->buffer()->params.textclass, row->par()->GetLayout()).align;
+       else
+         align = row->par()->align;
+#endif
           
        // center displayed insets 
+       Inset * inset;
           if (row->par()->GetChar(row->pos()) == LyXParagraph::META_INSET
-              && row->par()->GetInset(row->pos())
-              && row->par()->GetInset(row->pos())->display())
+              && (inset=row->par()->GetInset(row->pos()))
+              && (inset->display())) // || (inset->scroll() < 0)))
             align = LYX_ALIGN_CENTER;
 
           switch (align) {
@@ -3092,13 +3192,17 @@ void LyXText::CursorLeftOneWord(BufferView * bview)  const
               && (tmpcursor.par()->IsSeparator(tmpcursor.pos() - 1) 
                   || tmpcursor.par()->IsKomma(tmpcursor.pos() - 1))
               && !(tmpcursor.par()->IsHfill(tmpcursor.pos() - 1)
+#ifndef NEW_INSETS
                    || tmpcursor.par()->IsFloat(tmpcursor.pos() - 1)
+#endif
                    || tmpcursor.par()->IsInset(tmpcursor.pos() - 1)))
                tmpcursor.pos(tmpcursor.pos() - 1);
 
        if (tmpcursor.pos()
            && (tmpcursor.par()->IsInset(tmpcursor.pos() - 1)
+#ifndef NEW_INSETS
                || tmpcursor.par()->IsFloat(tmpcursor.pos() - 1)
+#endif
                || tmpcursor.par()->IsHfill(tmpcursor.pos() - 1))) {
                tmpcursor.pos(tmpcursor.pos() - 1);
        } else if (!tmpcursor.pos()) {
@@ -3350,12 +3454,20 @@ void LyXText::DeleteLineForward(BufferView * bview)
 // version did. (JMarc) 
 void LyXText::ChangeWordCase(BufferView * bview, LyXText::TextCase action) 
 {
+#ifndef NEW_INSETS
        LyXParagraph * tmppar = cursor.par()->ParFromPos(cursor.pos());
+#else
+       LyXParagraph * tmppar = cursor.par();
+#endif
 
        SetUndo(bview->buffer(),Undo::FINISH, tmppar->previous, tmppar->next); 
 
+#ifndef NEW_INSETS
        LyXParagraph::size_type tmppos = 
                cursor.par()->PositionInParFromPos(cursor.pos());
+#else
+       LyXParagraph::size_type tmppos = cursor.pos();
+#endif
        while (tmppos < tmppar->size()) {
                unsigned char c = tmppar->GetChar(tmppos);
                if (IsKommaChar(c) || IsLineSeparatorChar(c))
@@ -3411,9 +3523,15 @@ void LyXText::Delete(BufferView * bview)
        if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
                LyXCursor tmpcursor = cursor;
                cursor = old_cursor; // to make sure undo gets the right cursor position
-               SetUndo(bview->buffer(), Undo::DELETE, 
+               SetUndo(bview->buffer(), Undo::DELETE,
+#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 = tmpcursor;
                Backspace(bview);
        }
@@ -3450,17 +3568,26 @@ void LyXText::Backspace(BufferView * bview)
       
                if ((lastpos == 0
                     || (lastpos == 1 && cursor.par()->IsSeparator(0)))
+#ifndef NEW_INSETS
                    && !(cursor.par()->Next() 
                         && cursor.par()->footnoteflag == LyXParagraph::NO_FOOTNOTE
-                        && cursor.par()->Next()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)) {
+                        && cursor.par()->Next()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)
+#endif
+                       ) {
                        // This is an empty paragraph and we delete it just by moving the cursor one step
                        // left and let the DeleteEmptyParagraphMechanism handle the actual deletion
                        // of the paragraph.
                        
                        if (cursor.par()->previous) {
+#ifndef NEW_INSETS
                                LyXParagraph * tmppar = cursor.par()->previous->FirstPhysicalPar();
+#else
+                               LyXParagraph * tmppar = cursor.par()->previous;
+#endif
                                if (cursor.par()->GetLayout() == tmppar->GetLayout()
+#ifndef NEW_INSETS
                                    && cursor.par()->footnoteflag == tmppar->footnoteflag
+#endif
                                    && cursor.par()->GetAlign() == tmppar->GetAlign()) {
                                        // Inherit botom DTD from the paragraph below.
                                        // (the one we are deleting)
@@ -3482,12 +3609,20 @@ void LyXText::Backspace(BufferView * bview)
                                return;
                        }
                }
-               
+
+#ifndef NEW_INSETS
                if (cursor.par()->ParFromPos(cursor.pos())->previous){
                        SetUndo(bview->buffer(), Undo::DELETE,
                                cursor.par()->ParFromPos(cursor.pos())->previous->previous,
                                cursor.par()->ParFromPos(cursor.pos())->next);
                }
+#else
+               if (cursor.par()->previous) {
+                       SetUndo(bview->buffer(), Undo::DELETE,
+                               cursor.par()->previous->previous,
+                               cursor.par()->next);
+               }
+#endif
                
                LyXParagraph * tmppar = cursor.par();
                Row * tmprow = cursor.row();
@@ -3515,7 +3650,9 @@ void LyXText::Backspace(BufferView * bview)
                if (cursor.par() != tmppar
                    && (cursor.par()->GetLayout() == tmppar->GetLayout()
                        || tmppar->GetLayout() == 0 /*standard*/)
+#ifndef NEW_INSETS
                    && cursor.par()->footnoteflag == tmppar->footnoteflag
+#endif
 #ifndef NEW_TABULAR
                    /* table stuff -- begin*/
                    && !cursor.par()->table /* no pasting of tables */ 
@@ -3558,9 +3695,15 @@ void LyXText::Backspace(BufferView * bview)
        } else {
                /* this is the code for a normal backspace, not pasting
                 * any paragraphs */ 
-               SetUndo(bview->buffer(), Undo::DELETE, 
+               SetUndo(bview->buffer(), Undo::DELETE,
+#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
+                       ); 
                // We used to do CursorLeftIntern() here, but it is
                // not a good idea since it triggers the auto-delete
                // mechanism. So we do a CursorLeftIntern()-lite,
@@ -3688,18 +3831,15 @@ void LyXText::Backspace(BufferView * bview)
                }
                
                // break the cursor row again
-               z = NextBreakPoint(bview, row, workWidth(bview));
-               
-               if (z != RowLast(row) || 
-                   (row->next() && row->next()->par() == row->par() &&
-                    RowLast(row) == row->par()->Last() - 1)){
+               if (row->next() && row->next()->par() == row->par() &&
+                   (RowLast(row) == row->par()->Last() - 1 ||
+                    NextBreakPoint(bview, row, workWidth(bview)) != RowLast(row))) {
                        
                        /* it can happen that a paragraph loses one row
                         * without a real breakup. This is when a word
                         * is to long to be broken. Well, I don t care this 
                         * hack ;-) */ 
-                       if (row->next() && row->next()->par() == row->par() &&
-                           RowLast(row) == row->par()->Last() - 1)
+                       if (RowLast(row) == row->par()->Last() - 1)
                                RemoveRow(row->next());
                        
                        refresh_y = y;
@@ -3710,10 +3850,7 @@ void LyXText::Backspace(BufferView * bview)
                        SetCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
                        // cursor MUST be in row now
                        
-                       if (row->next() && row->next()->par() == row->par())
-                               need_break_row = row->next();
-                       else
-                               need_break_row = 0;
+                       need_break_row = row->next();
                } else  {
                        // set the dimensions of the row
                        row->fill(Fill(bview, row, workWidth(bview)));
@@ -3734,9 +3871,9 @@ void LyXText::Backspace(BufferView * bview)
 
        lastpos = cursor.par()->Last();
        if (cursor.pos() == lastpos) {
-               SetCurrentFont(bview);
                if (IsBoundary(bview->buffer(), cursor.par(), cursor.pos()) != cursor.boundary())
                        SetCursor(bview, cursor.par(), cursor.pos(), false, !cursor.boundary());
+               SetCurrentFont(bview);
        }
        
        // check, wether the last characters font has changed.
@@ -3763,9 +3900,10 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
        LyXParagraph::size_type last = RowLastPrintable(row_ptr);
 
        LyXParagraph::size_type vpos, pos;
-       float x, tmpx;
-       int y_top, y_bottom;
-       float fill_separator, fill_hfill, fill_label_hfill;
+       float x;
+       float tmpx;
+       int y_top;
+       int y_bottom;
 
        LyXFont font(LyXFont::ALL_SANE);
        int maxdesc;
@@ -3774,6 +3912,10 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
                       << row_ptr->height() << endl;
                return;
        }
+
+       float fill_separator;
+       float fill_hfill;
+       float fill_label_hfill;
        PrepareToPrint(bview, row_ptr, x, fill_separator,
                       fill_hfill, fill_label_hfill);
        
@@ -3782,45 +3924,44 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
        x += x_offset;
        
        // clear the area where we want to paint/print
-       int ww;
-       ww = bview->workWidth();
+       int ww = bview->workWidth();
 
        bool clear_area = true;
        Inset * inset = 0;
 
-       if ((last == row_ptr->pos()) &&
+       if (!bview->screen()->forceClear() && (last == row_ptr->pos()) &&
            (row_ptr->par()->GetChar(row_ptr->pos()) == LyXParagraph::META_INSET) &&
-           (inset=row_ptr->par()->GetInset(row_ptr->pos())))
-       {
+           (inset = row_ptr->par()->GetInset(row_ptr->pos()))) {
                clear_area = inset->doClearArea();
        }
-       if (cleared) { // we don't need to clear it's already done!!!
+       // we don't need to clear it's already done!!!
+       if (cleared) {
                clear_area = true;
        } else if (clear_area) {
-               int w;
-               if (inset_owner)
-                       w = inset_owner->width(bview, font);
-               else
-                       w = ww;
+               int w = (inset_owner ? inset_owner->width(bview, font) : ww);
                pain.fillRectangle(x_offset, y_offset, w, row_ptr->height());
        } else if (inset != 0) {
                int h = row_ptr->baseline() - inset->ascent(bview, font);
                if (h > 0) {
-                       int w;
-                       if (inset_owner)
-                               w = inset_owner->width(bview, font);
-                       else
-                               w = ww;
+                       int w = (inset_owner ?
+                                inset_owner->width(bview, font) : ww);
                        pain.fillRectangle(x_offset, y_offset, w, h);
                }
+               h += inset->ascent(bview, font) + inset->descent(bview, font);
+               if ((row_ptr->height() - h) > 0) {
+                       int w = (inset_owner ?
+                                inset_owner->width(bview, font) : ww);
+                       pain.fillRectangle(x_offset,y_offset+h, w, row_ptr->height()-h);
+               }
+               if (!inset_owner && !inset->display() && !inset->needFullRow())
+               {
+                       int w = inset->width(bview, font) + int(x);
+                       pain.fillRectangle(w, y_offset, ww - w, row_ptr->height());
+               }
        }
        
        if (selection) {
-               int w;
-               if (inset_owner)
-                       w = inset_owner->width(bview, font);
-               else
-                       w = ww;
+               int w = (inset_owner ? inset_owner->width(bview, font) : ww);
                /* selection code */
                if (bidi_same_direction) {
                        if (sel_start_cursor.row() == row_ptr &&
@@ -3877,8 +4018,8 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
                } else if (sel_start_cursor.row() == row_ptr ||
                           sel_end_cursor.row() == row_ptr) {
                        float tmpx = x;
-                       int cell = 0;
 #ifndef NEW_TABULAR
+                       int cell = 0;
                        if (row_ptr->par()->table) {
                                cell = NumberOfCell(row_ptr->par(), row_ptr->pos());
                                tmpx += row_ptr->par()->table->GetBeginningOfTextInCell(cell);
@@ -4089,7 +4230,11 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
        }
 #endif
        // Draw appendix lines
+#ifndef NEW_INSETS
        LyXParagraph * firstpar = row_ptr->par()->FirstPhysicalPar();
+#else
+       LyXParagraph * firstpar = row_ptr->par();
+#endif
        if (firstpar->appendix){
                pain.line(1, y_offset,
                          1, y_offset + row_ptr->height(),
@@ -4113,18 +4258,25 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
                int next_depth = 0;
                int prev_depth = 0;
                if (row_ptr->next())
+#ifndef NEW_INSETS
                        if (row_ptr->par()->footnoteflag ==
                            row_ptr->next()->par()->footnoteflag)
                                next_depth = row_ptr->next()->par()->GetDepth();
                        else if (row_ptr->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE)
                                next_depth = depth;
-
+#else
+                               next_depth = row_ptr->next()->par()->GetDepth();
+#endif
                if (row_ptr->previous())
+#ifndef NEW_INSETS
                        if (row_ptr->par()->footnoteflag ==
                            row_ptr->previous()->par()->footnoteflag)
                                prev_depth = row_ptr->previous()->par()->GetDepth();
                        else if (row_ptr->par()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE)
                                prev_depth = depth;
+#else
+                               prev_depth = row_ptr->previous()->par()->GetDepth();
+#endif
 
                for (int i = 1; i <= depth; ++i) {
                        int line_x = (LYX_PAPER_MARGIN / 5) * (i + minipage) + box_x;
@@ -4275,11 +4427,13 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
                                        if (is_rtl) {
                                                tmpx = ww - LeftMargin(bview, row_ptr)
                                                        + lyxfont::width(layout.labelsep, font);
+#ifndef NEW_INSETS
                                                if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)  {
                                                        LyXFont font(LyXFont::ALL_SANE);
                                                        font.setSize(LyXFont::SIZE_SMALL);
                                                        tmpx += lyxfont::width("Mwide-fixM", font);
                                                }
+#endif
                                        } else
                                                tmpx = x - lyxfont::width(layout.labelsep, font)
                                                        - lyxfont::width(tmpstring, font);
@@ -4340,9 +4494,18 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
        }
        
        /* is it a last row? */
+#ifndef NEW_INSETS
        LyXParagraph * par = row_ptr->par()->LastPhysicalPar();
-       if ((row_ptr->par()->ParFromPos(last + 1) == par) &&
-           (!row_ptr->next() || (row_ptr->next()->par() != row_ptr->par())))
+#else
+       LyXParagraph * par = row_ptr->par();
+#endif
+       if (
+#ifndef NEW_INSETS
+               (row_ptr->par()->ParFromPos(last + 1) == par)
+#else
+               (row_ptr->par() == par)
+#endif
+           && (!row_ptr->next() || (row_ptr->next()->par() != row_ptr->par())))
        {
                /* think about the margins */ 
                if (!row_ptr->next() && bv_owner)
@@ -4419,6 +4582,7 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
                        int y = (y_offset + row_ptr->baseline()) - size;
                        int x = is_rtl ? LYX_PAPER_MARGIN 
                                : ww - LYX_PAPER_MARGIN - size;
+#ifndef NEW_INSETS
                        if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)
                                if (is_rtl) {
                                        LyXFont font(LyXFont::ALL_SANE);
@@ -4426,6 +4590,7 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
                                        x += lyxfont::width("Mwide-figM", font);
                                } else
                                        x -= LYX_PAPER_MARGIN/2;
+#endif
                        if (row_ptr->fill() <= size)
                                x += (size - row_ptr->fill() + 1) * (is_rtl ? -1 : 1);
                        if (endlabel == END_LABEL_BOX) {
@@ -4764,17 +4929,32 @@ int LyXText::GetColumnNearX(BufferView * bview, Row * row, int & x,
        }
 #endif
 
-
        if (vc > last + 1)  // This shouldn't happen.
                vc = last + 1;
 
        boundary = false;
-
+#if 0 // currently unused
+       bool lastrow = (!row->next() || row->next()->par() != row->par());
+       bool rtl = (lastrow)
+               ? row->par()->isRightToLeftPar(bview->buffer()->params)
+               : false;
+#endif
+       
        if (row->pos() > last)  // Row is empty?
                c = row->pos();
-       else if (vc == row->pos() ||
-                (row->par()->table
-                 && vc <= last && row->par()->IsNewline(vc-1)) ) {
+#warning This is wrong, please have a look Dekel (Jug)
+#if 0
+       else if (lastrow &&
+                ( (rtl && vc == row->pos()&& x < tmpx - 5) ||
+                  (!rtl && vc == last + 1 && x > tmpx + 5) ))
+               c = last + 1;
+#endif
+       else if (vc == row->pos()
+#ifndef NEW_TABULAR
+                || (row->par()->table
+                 && vc <= last && row->par()->IsNewline(vc-1))
+#endif
+               ) {
                c = vis2log(vc);
                if (bidi_level(c) % 2 == 1)
                        ++c;
@@ -4787,8 +4967,12 @@ int LyXText::GetColumnNearX(BufferView * bview, Row * row, int & x,
                }
        }
 
-       if (!row->par()->table && row->pos() <= last && c > last
-           && row->par()->IsNewline(last)) {
+       if (
+#ifndef NEW_TABULAR
+               !row->par()->table &&
+#endif
+               row->pos() <= last && c > last
+               && row->par()->IsNewline(last)) {
                if (bidi_level(last) % 2 == 0)
                        tmpx -= SingleWidth(bview, row->par(), last);
                else