]> git.lyx.org Git - lyx.git/blobdiff - src/text.C
more changes, read the Changelog
[lyx.git] / src / text.C
index c16548a436cb1809d8fe4dd35f51fadad7c72f84..525bb546101cd90a07c5209a4dd0c3c425ba85a0 100644 (file)
@@ -22,6 +22,7 @@
 #include "lyxtext.h"
 #include "support/textutils.h"
 #include "insets/insetbib.h"
+#include "insets/insettext.h"
 #include "lyx_gui_misc.h"
 #include "gettext.h"
 #include "bufferparams.h"
@@ -116,12 +117,7 @@ bool is_nikud(unsigned char c)
 int LyXText::workWidth(BufferView * bview) const
 {
        if (inset_owner) {
-#if 1
-               return inset_owner->getMaxWidth(bview->painter(), inset_owner);
-#else
-               LyXFont font(LyXFont::ALL_SANE);
-               return inset_owner->width(bview->painter(), font);
-#endif
+               return inset_owner->textWidth(bview->painter());
        }
        return bview->workWidth();
 }
@@ -211,6 +207,7 @@ int LyXText::SingleWidth(BufferView * bview, LyXParagraph * par,
        } else if (IsHfillChar(c)) {
                return 3;       /* Because of the representation
                                 * as vertical lines */
+#ifndef NEW_INSETS
        } else if (c == LyXParagraph::META_FOOTNOTE ||
                   c == LyXParagraph::META_MARGIN ||
                   c == LyXParagraph::META_FIG ||
@@ -245,12 +242,13 @@ int LyXText::SingleWidth(BufferView * bview, LyXParagraph * par,
                font.decSize();
                font.decSize();
                return lyxfont::width(fs, font);
+#endif
        } else if (c == LyXParagraph::META_INSET) {
-               Inset * tmpinset= par->GetInset(pos);
-               if (tmpinset)
-                       return par->GetInset(pos)->width(bview->painter(),
-                                                        font);
-               else
+               Inset * tmpinset = par->GetInset(pos);
+               if (tmpinset) {
+                       tmpinset->update(bview, font);
+                       return tmpinset->width(bview->painter(), font);
+               else
                        return 0;
 
        } else if (IsSeparatorChar(c))
@@ -424,6 +422,7 @@ bool LyXText::IsBoundary(Buffer const * buf, LyXParagraph * par,
        return rtl != rtl2;
 }
 
+
 bool LyXText::IsBoundary(Buffer const * buf, LyXParagraph * par,
                         LyXParagraph::size_type pos,
                         LyXFont const & font) const
@@ -444,7 +443,7 @@ bool LyXText::IsBoundary(Buffer const * buf, LyXParagraph * par,
 
 void LyXText::draw(BufferView * bview, Row const * row,
                   LyXParagraph::size_type & vpos,
-                  int offset, float & x)
+                  int offset, float & x, bool cleared)
 {
        Painter & pain = bview->painter();
        
@@ -512,7 +511,7 @@ void LyXText::draw(BufferView * bview, Row const * row,
 
        LyXFont font = GetFont(bview->buffer(), row->par(), pos);
        LyXFont font2 = font;
-
+#ifndef NEW_INSETS
        if (c == LyXParagraph::META_FOOTNOTE
            || c == LyXParagraph::META_MARGIN
            || c == LyXParagraph::META_FIG
@@ -563,11 +562,14 @@ void LyXText::draw(BufferView * bview, Row const * row,
 
                ++vpos;
                return;
-       } else if (c == LyXParagraph::META_INSET) {
-               Inset const * tmpinset = row->par()->GetInset(pos);
+       } else
+#endif
+               if (c == LyXParagraph::META_INSET) {
+               Inset * tmpinset = row->par()->GetInset(pos);
                if (tmpinset) {
-                       tmpinset->draw(bview->painter(), font,
-                                      offset + row->baseline(), x);
+                       tmpinset->update(bview, font, false);
+                       tmpinset->draw(bview, font, offset+row->baseline(), x,
+                                      cleared);
                }
                ++vpos;
 
@@ -704,14 +706,14 @@ int LyXText::LeftMargin(BufferView * bview, Row const * row) const
                                  textclasslist
                                  .TextClass(bview->buffer()->params.textclass)
                                  .defaultfont());
-       
+#ifndef NEW_INSETS
        if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)  {
                LyXFont font(LyXFont::ALL_SANE);
                font.setSize(LyXFont::SIZE_SMALL);
                x += lyxfont::width("Mwide-figM", font)
                        + LYX_PAPER_MARGIN/2;
        }
-       
+#endif
        // this is the way, LyX handles the LaTeX-Environments.
        // I have had this idea very late, so it seems to be a
        // later added hack and this is true
@@ -920,11 +922,12 @@ int LyXText::RightMargin(Buffer const * buf, Row const * row) const
                                       textclasslist
                                       .TextClass(buf->params.textclass)
                                       .defaultfont());
-       
+
+#ifndef NEW_INSETS
        if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)  {
                x += LYX_PAPER_MARGIN / 2;
        }
-       
+#endif
        // this is the way, LyX handles the LaTeX-Environments.
        // I have had this idea very late, so it seems to be a
        // later added hack and this is true
@@ -986,6 +989,7 @@ int LyXText::LabelEnd (BufferView * bview, Row const * row) const
 }
 
 
+#ifndef NEW_TABULAR
 /* table stuff -- begin*/
 int LyXText::NumberOfCell(LyXParagraph * par,
                          LyXParagraph::size_type pos) const
@@ -1015,7 +1019,6 @@ int LyXText::WidthOfCell(BufferView * bview, LyXParagraph * par,
 }
 
 
-#ifndef NEW_TABULAR
 bool LyXText::HitInTable(BufferView * bview, Row * row, int x) const
 {
        float tmpx;
@@ -1026,7 +1029,6 @@ bool LyXText::HitInTable(BufferView * bview, Row * row, int x) const
                       fill_hfill, fill_label_hfill, false);
        return (x > tmpx && x < tmpx + row->par()->table->WidthOfTable());
 }
-#endif
 
 
 bool LyXText::MouseHitInTable(BufferView * bview, int x, long y) const
@@ -1037,6 +1039,7 @@ bool LyXText::MouseHitInTable(BufferView * bview, int x, long y) const
 
 
 /* table stuff -- end*/
+#endif
 
 
 // get the next breakpoint in a given paragraph
@@ -1093,25 +1096,30 @@ LyXText::NextBreakPoint(BufferView * bview, Row const * row, int width) const
                        par->Last();
                // this is the usual handling
                int x = LeftMargin(bview, row);
-               while (x < width && i < last) {
+               bool doitonetime = true;
+               while (doitonetime || ((x < width) && (i < last))) {
+                       doitonetime = false;
                        char c = par->GetChar(i);
                        if (IsNewlineChar(c)) {
                                last_separator = i;
                                x = width; // this means break
                        } else if (c == LyXParagraph::META_INSET &&
-                                  par->GetInset(i) && par->GetInset(i)->display()){
+                                  par->GetInset(i)) {
+                               
                                // check wether a Display() inset is
                                // valid here. if not, change it to
                                // non-display
-                               if (layout.isCommand()
-                                   || (layout.labeltype == LABEL_MANUAL
-                                       && i < BeginningOfMainBody(bview->buffer(), par))){
+                               if (par->GetInset(i)->display() &&
+                                   (layout.isCommand() ||
+                                    ((layout.labeltype == LABEL_MANUAL) &&
+                                     (i < BeginningOfMainBody(bview->buffer(), par))))) {
                                        // display istn't allowd
                                        par->GetInset(i)->display(false);
                                        x += SingleWidth(bview, par, i, c);
-                               } else {
-                                       // inset is display. So break the line here
-                                       if (i == pos){
+                               } else if (par->GetInset(i)->display() ||
+                                        par->GetInset(i)->needFullRow()) {
+                                       // So break the line here
+                                       if (i == pos) {
                                                if (pos < last-1) {
                                                        last_separator = i;
                                                        if (IsLineSeparatorChar(par->GetChar(i+1)))
@@ -1121,6 +1129,13 @@ LyXText::NextBreakPoint(BufferView * bview, Row const * row, int width) const
                                        } else
                                                last_separator = i - 1;
                                        x = width;  // this means break
+                               } else {
+#if 0
+                                       last_separator = i;
+                                       x += width;
+#else
+                                       x += SingleWidth(bview, par, i, c);
+#endif
                                }
                        } else  {
                                if (IsLineSeparatorChar(c))
@@ -1424,25 +1439,26 @@ void LyXText::SetHeightOfRow(BufferView * bview, Row * row_ptr) const
    int maxdesc = int(lyxfont::maxDescent(font) *
                    layout.spacing.getValue() *
                    spacing_val);
-
    int pos_end = RowLast(row_ptr);
-   
    int labeladdon = 0;
+   int maxwidth = 0;
 
    // Check if any insets are larger
    for (pos = row_ptr->pos(); pos <= pos_end; ++pos) {
-      if (row_ptr->par()->GetChar(pos) == LyXParagraph::META_INSET) {
-        tmpfont = GetFont(bview->buffer(), row_ptr->par(), pos);
-         tmpinset = row_ptr->par()->GetInset(pos);
-         if (tmpinset) {
-            asc = tmpinset->ascent(bview->painter(), tmpfont);
-            desc = tmpinset->descent(bview->painter(), tmpfont);
-           if (asc > maxasc) 
-             maxasc = asc;
-           if (desc > maxdesc)
-             maxdesc = desc;
-        }
-      }
+          if (row_ptr->par()->GetChar(pos) == LyXParagraph::META_INSET) {
+                  tmpfont = GetFont(bview->buffer(), row_ptr->par(), pos);
+                  tmpinset = row_ptr->par()->GetInset(pos);
+                  if (tmpinset) {
+                          tmpinset->update(bview, tmpfont);
+                          asc = tmpinset->ascent(bview->painter(), tmpfont);
+                          desc = tmpinset->descent(bview->painter(), tmpfont);
+                          maxwidth += tmpinset->width(bview->painter(), tmpfont);
+                          maxasc = max(maxasc, asc);
+                          maxdesc = max(maxdesc, desc);
+                  }
+          } else {
+                  maxwidth += SingleWidth(bview, row_ptr->par(), pos);
+          }
    }
 
    // Check if any custom fonts are larger (Asger)
@@ -1678,6 +1694,18 @@ void LyXText::SetHeightOfRow(BufferView * bview, Row * row_ptr) const
    row_ptr->baseline(maxasc + labeladdon);
    
    height += row_ptr->height();
+   float x, dummy;
+   PrepareToPrint(bview, row_ptr, x, dummy, dummy, dummy);
+   row_ptr->width(maxwidth+x);
+   if (inset_owner) {
+          Row * r = firstrow;
+          width = max(0,workWidth(bview));
+          while(r) {
+                  if (r->width() > width)
+                          width = r->width();
+                  r = r->next();
+          }
+   }
 }
 
 
@@ -1918,6 +1946,7 @@ void LyXText::BreakParagraph(BufferView * bview, char keep_layout)
 }
 
 
+#ifndef NEW_INSETS
 void LyXText::OpenFootnote(BufferView * bview)
 {
    LyXParagraph * endpar,* tmppar;
@@ -1972,8 +2001,10 @@ void LyXText::OpenFootnote(BufferView * bview)
    SetCursor(bview, par->next, 0);
    sel_cursor = cursor;
 }
-   
+#endif
 
+
+#ifndef NEW_TABULAR
 /* table stuff -- begin*/
 
 void LyXText::TableFeatures(BufferView * bview, int feature, string const & val) const
@@ -2077,8 +2108,7 @@ void LyXText::TableFeatures(BufferView * bview, int feature) const
          Language const * lang = cursor.par()->getParLanguage(bview->buffer()->params);
          LyXFont font(LyXFont::ALL_INHERIT,lang);
           for (int i = 0; i < number; ++i) {
-              cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE);
-             cursor.par()->SetFont(pos, font);
+              cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
          }
                
           /* append the row into the table */
@@ -2116,8 +2146,7 @@ void LyXText::TableFeatures(BufferView * bview, int feature) const
          Language const * lang = cursor.par()->getParLanguage(bview->buffer()->params);
          LyXFont font(LyXFont::ALL_INHERIT,lang);
           for (int i = 0; i < number; ++i) {
-              cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE);
-             cursor.par()->SetFont(pos, font);
+              cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
          }
 
           /* append the row into the table */
@@ -2134,8 +2163,9 @@ void LyXText::TableFeatures(BufferView * bview, int feature) const
           do{
               if (pos && (cursor.par()->IsNewline(pos-1))){
                   if (cursor.par()->table->AppendCellAfterCell(cell_org, cell)) {
-                      cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE);
-                     cursor.par()->SetFont(pos, font);
+                      cursor.par()->InsertChar(pos,
+                                              LyXParagraph::META_NEWLINE,
+                                              font);
                       if (pos <= cursor.pos())
                           cursor.pos(cursor.pos() + 1);
                       ++pos;
@@ -2148,8 +2178,8 @@ void LyXText::TableFeatures(BufferView * bview, int feature) const
              This saves one byte memory per table ;-) */
           if (cursor.par()->table->AppendCellAfterCell(cell_org, cell)) {
                  LyXParagraph::size_type last = cursor.par()->Last();
-                 cursor.par()->InsertChar(last, LyXParagraph::META_NEWLINE);
-                 cursor.par()->SetFont(last, font);
+                 cursor.par()->InsertChar(last,
+                                          LyXParagraph::META_NEWLINE, font);
          }
                
           /* append the column into the table */ 
@@ -2647,6 +2677,7 @@ void LyXText::BackspaceInTable(BufferView * bview)
 }
 
 /* table stuff -- end*/
+#endif
 
 
 // Just a macro to make some thing easier. 
@@ -2743,7 +2774,8 @@ void LyXText::InsertChar(BufferView * bview, char c)
        // the display inset stuff
        if (cursor.row()->par()->GetChar(cursor.row()->pos()) == LyXParagraph::META_INSET
            && cursor.row()->par()->GetInset(cursor.row()->pos())
-           && cursor.row()->par()->GetInset(cursor.row()->pos())->display())
+           && (cursor.row()->par()->GetInset(cursor.row()->pos())->display() ||
+               cursor.row()->par()->GetInset(cursor.row()->pos())->needFullRow()))
                cursor.row()->fill(-1); // to force a new break  
 
        // get the cursor row fist
@@ -2886,6 +2918,7 @@ void LyXText::charInserted()
        }
 }
 
+
 void LyXText::PrepareToPrint(BufferView * bview,
                             Row * row, float & x,
                             float & fill_separator, 
@@ -2901,6 +2934,7 @@ void LyXText::PrepareToPrint(BufferView * bview,
        fill_separator = 0;
        fill_label_hfill = 0;
 
+#ifndef NEW_INSETS
         bool is_rtl = row->par()->isRightToLeftPar(bview->buffer()->params);
 
        if (is_rtl) {
@@ -2910,7 +2944,9 @@ void LyXText::PrepareToPrint(BufferView * bview,
                        font.setSize(LyXFont::SIZE_SMALL);
                        x += lyxfont::width("Mwide-figM", font);
                }
-       } else if (workWidth(bview) > 0)
+       } else
+#endif
+               if (workWidth(bview) > 0)
                x = LeftMargin(bview, row);
        else
                x = 0;
@@ -3147,7 +3183,7 @@ void LyXText::SelectWord(BufferView * bview)
        SetCursor(bview, cursor.par(), cursor.pos() );
        
        // finally set the selection
-       SetSelection(bview);
+       SetSelection();
 }
 
 
@@ -3282,7 +3318,7 @@ void LyXText::SelectSelectedWord(BufferView * bview)
        SetCursor(bview, cursor.par(), cursor.pos());
        
        // finally set the selection
-       SetSelection(bview);
+       SetSelection();
 }
 
 
@@ -3299,7 +3335,7 @@ void LyXText::DeleteWordForward(BufferView * bview)
                SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
                sel_cursor = cursor;
                cursor = tmpcursor;
-               SetSelection(bview); 
+               SetSelection(); 
                
                /* -----> Great, CutSelection() gets rid of multiple spaces. */
                CutSelection(bview);
@@ -3320,7 +3356,7 @@ void LyXText::DeleteWordBackward(BufferView * bview)
               SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
               sel_cursor = cursor;
               cursor = tmpcursor;
-              SetSelection(bview);
+              SetSelection();
               CutSelection(bview);
        }
 }
@@ -3342,7 +3378,7 @@ void LyXText::DeleteLineForward(BufferView * bview)
                SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
                sel_cursor = cursor;
                cursor = tmpcursor;
-               SetSelection(bview);
+               SetSelection();
                // What is this test for ??? (JMarc)
                if (!selection) {
                        DeleteWordForward(bview);
@@ -3586,7 +3622,8 @@ void LyXText::Backspace(BufferView * bview)
                                return; 
                        // force complete redo when erasing display insets
                        // this is a cruel method but safe..... Matthias 
-                       if (cursor.par()->GetInset(cursor.pos())->display()){
+                       if (cursor.par()->GetInset(cursor.pos())->display() ||
+                           cursor.par()->GetInset(cursor.pos())->needFullRow()) {
                                cursor.par()->Erase(cursor.pos());
                                RedoParagraph(bview);
                                return;
@@ -3765,7 +3802,7 @@ void LyXText::Backspace(BufferView * bview)
 
 
 void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
-                           Row * row_ptr, long y)
+                           Row * row_ptr, long y, bool cleared)
 {
        /* returns a printed row */
        Painter & pain = bview->painter();
@@ -3778,7 +3815,7 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
        int y_top, y_bottom;
        float fill_separator, fill_hfill, fill_label_hfill;
 
-       LyXFont font;
+       LyXFont font(LyXFont::ALL_SANE);
        int maxdesc;
        if (row_ptr->height() <= 0) {
                lyxerr << "LYX_ERROR: row.height: "
@@ -3788,14 +3825,43 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
        PrepareToPrint(bview, row_ptr, x, fill_separator,
                       fill_hfill, fill_label_hfill);
        
+       if (inset_owner && (x < 0))
+               x = 0;
        x += x_offset;
        
        // clear the area where we want to paint/print
-       int ww = workWidth(bview);
-       if (ww < 0)
-               ww = bview->workWidth();
-       if (bv_owner)
-               pain.fillRectangle(x_offset, y_offset, ww, row_ptr->height());
+       int ww;
+       ww = bview->workWidth();
+
+       bool clear_area = true;
+       Inset * inset = 0;
+
+       if ((last == row_ptr->pos()) &&
+           (row_ptr->par()->GetChar(row_ptr->pos()) == LyXParagraph::META_INSET) &&
+           (inset=row_ptr->par()->GetInset(row_ptr->pos())))
+       {
+               clear_area = inset->doClearArea();
+       }
+       if (cleared) { // we don't need to clear it's already done!!!
+               clear_area = true;
+       } else if (clear_area) {
+               int w;
+               if (inset_owner)
+                       w = inset_owner->width(bview->painter(), font);
+               else
+                       w = ww;
+               pain.fillRectangle(x_offset, y_offset, w, row_ptr->height());
+       } else if (inset != 0) {
+               int h = row_ptr->baseline() - inset->ascent(pain, font);
+               if (h > 0) {
+                       int w;
+                       if (inset_owner)
+                               w = inset_owner->width(bview->painter(), font);
+                       else
+                               w = ww;
+                       pain.fillRectangle(x_offset, y_offset, w, h);
+               }
+       }
        
        if (selection) {
                /* selection code */
@@ -3803,48 +3869,53 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
                        if (sel_start_cursor.row() == row_ptr &&
                            sel_end_cursor.row() == row_ptr) {
                                if (sel_start_cursor.x() < sel_end_cursor.x())
-                                       pain.fillRectangle(sel_start_cursor.x(), y_offset,
+                                       pain.fillRectangle(x_offset + sel_start_cursor.x(),
+                                                          y_offset,
                                                           sel_end_cursor.x() - sel_start_cursor.x(),
                                                           row_ptr->height(),
                                                           LColor::selection);
                                else
-                                       pain.fillRectangle(sel_end_cursor.x(), y_offset,
+                                       pain.fillRectangle(x_offset + sel_end_cursor.x(),
+                                                          y_offset,
                                                           sel_start_cursor.x() - sel_end_cursor.x(),
                                                           row_ptr->height(),
                                                           LColor::selection);
                        } else if (sel_start_cursor.row() == row_ptr) {
                                if (is_rtl)
-                                       pain.fillRectangle(0, y_offset,
+                                       pain.fillRectangle(x_offset, y_offset,
                                                           sel_start_cursor.x(),
                                                           row_ptr->height(),
                                                           LColor::selection);
                                else
-                                       pain.fillRectangle(sel_start_cursor.x(), y_offset,
+                                       pain.fillRectangle(x_offset + sel_start_cursor.x(),
+                                                          y_offset,
                                                           ww - sel_start_cursor.x(),
                                                           row_ptr->height(),
                                                           LColor::selection);
                        } else if (sel_end_cursor.row() == row_ptr) {
                                if (is_rtl)
-                                       pain.fillRectangle(sel_end_cursor.x(), y_offset,
+                                       pain.fillRectangle(x_offset + sel_end_cursor.x(),
+                                                          y_offset,
                                                           ww - sel_end_cursor.x(),
                                                           row_ptr->height(),
                                                           LColor::selection);
                                else
-                                       pain.fillRectangle(0, y_offset,
+                                       pain.fillRectangle(x_offset, y_offset,
                                                           sel_end_cursor.x(),
                                                           row_ptr->height(),
                                                           LColor::selection);
                        } else if (y > long(sel_start_cursor.y())
                                   && y < long(sel_end_cursor.y())) {
-                               pain.fillRectangle(0, y_offset,
-                                                  ww, row_ptr->height(),
+                               pain.fillRectangle(x_offset, y_offset, ww,
+                                                  row_ptr->height(),
                                                   LColor::selection);
                        }
                } else if ( sel_start_cursor.row() != row_ptr &&
                            sel_end_cursor.row() != row_ptr &&
                            y > long(sel_start_cursor.y())
                            && y < long(sel_end_cursor.y())) {
-                       pain.fillRectangle(0, y_offset, ww, row_ptr->height(),
+                       pain.fillRectangle(x_offset, y_offset, ww,
+                                          row_ptr->height(),
                                           LColor::selection);
                } else if (sel_start_cursor.row() == row_ptr ||
                           sel_end_cursor.row() == row_ptr) {
@@ -3858,7 +3929,7 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
 #endif
                        if ( (sel_start_cursor.row() != row_ptr && !is_rtl) ||
                             (sel_end_cursor.row() != row_ptr && is_rtl))
-                               pain.fillRectangle(0, y_offset,
+                               pain.fillRectangle(x_offset, y_offset,
                                                   int(tmpx),
                                                   row_ptr->height(),
                                                   LColor::selection);
@@ -3880,7 +3951,8 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
                                              sel_start_cursor.pos() <= pos) &&
                                             (sel_end_cursor.row() != row_ptr ||
                                              pos < sel_end_cursor.pos()) )
-                                               pain.fillRectangle(int(old_tmpx), y_offset,
+                                               pain.fillRectangle(x_offset + int(old_tmpx),
+                                                                  y_offset,
                                                                   int(tmpx - old_tmpx + 1),
                                                                   row_ptr->height(),
                                                                   LColor::selection);
@@ -3920,17 +3992,19 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
                                              sel_start_cursor.pos() <= pos) &&
                                             (sel_end_cursor.row() != row_ptr ||
                                              pos < sel_end_cursor.pos()) )
-                                               pain.fillRectangle(int(old_tmpx), y_offset,
+                                               pain.fillRectangle(x_offset + int(old_tmpx),
+                                                                  y_offset,
                                                                   int(tmpx - old_tmpx + 1),
                                                                   row_ptr->height(),
-                                                          LColor::selection);
+                                                                  LColor::selection);
                                }
 #ifndef NEW_TABULAR
                        }
 #endif
                        if ( (sel_start_cursor.row() != row_ptr && is_rtl) ||
                             (sel_end_cursor.row() != row_ptr && !is_rtl) )
-                               pain.fillRectangle(int(tmpx), y_offset,
+                               pain.fillRectangle(x_offset + int(tmpx),
+                                                  y_offset,
                                                   int(ww - tmpx),
                                                   row_ptr->height(),
                                                   LColor::selection);
@@ -3938,6 +4012,7 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
        }
 
        int box_x = 0;
+#ifndef NEW_INSETS
        if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
                LyXFont font(LyXFont::ALL_SANE);
                font.setSize(LyXFont::SIZE_FOOTNOTE);
@@ -4055,7 +4130,7 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
                          workWidth(bview) - LYX_PAPER_MARGIN,
                          y_offset, LColor::footnote);
        }
-
+#endif
        // Draw appendix lines
        LyXParagraph * firstpar = row_ptr->par()->FirstPhysicalPar();
        if (firstpar->appendix){
@@ -4301,10 +4376,9 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
                        else
                                tmpx = x - lyxfont::width(layout.labelsep, font)
                                        - row_ptr->par()->bibkey->width(bview->painter(), font);
-                       row_ptr->par()->bibkey->draw(pain,
-                                                  font,
+                       row_ptr->par()->bibkey->draw(bview, font,
                                                   y_offset + row_ptr->baseline(), 
-                                                  tmpx);
+                                                  tmpx, clear_area);
                }
        }
        
@@ -4508,7 +4582,7 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
                                                row_ptr->par(), pos);
                                ++vpos;
                        } else
-                               draw(bview, row_ptr, vpos, y_offset, x);
+                               draw(bview, row_ptr, vpos, y_offset, x, clear_area);
                }
                
                /* do not forget the very last cell. This has no NEWLINE so 
@@ -4620,13 +4694,11 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
                                        x += fill_separator;
                                ++vpos;
                        } else
-                               draw(bview, row_ptr, vpos, y_offset, x);
+                               draw(bview, row_ptr, vpos, y_offset, x, clear_area);
                }
 #ifndef NEW_TABULAR
        }
 #endif
-       // Jürgen!!! FIX This! (NOW!!!) (please)
-       width = max(x - x_offset, float(width));
 }
 
 
@@ -4772,7 +4844,8 @@ int LyXText::GetColumnNearX(BufferView * bview, Row * row, int & x,
        return c;
 }
 
-   
+
+#ifndef NEW_INSETS
 /* turn the selection into a new environment. If there is no selection,
 * create an empty environment */ 
 void LyXText::InsertFootnoteEnvironment(BufferView * bview, 
@@ -4915,7 +4988,8 @@ void LyXText::InsertFootnoteEnvironment(BufferView * bview,
 
    ClearSelection();
 }
-   
+#endif
+
 
 // returns pointer to a specified row
 Row * LyXText::GetRow(LyXParagraph * par,