]> git.lyx.org Git - lyx.git/blobdiff - src/text.C
more changes, read the Changelog
[lyx.git] / src / text.C
index 4a87628de48c9715fa5d9ba7bfd2625972c0b334..525bb546101cd90a07c5209a4dd0c3c425ba85a0 100644 (file)
@@ -117,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();
 }
@@ -212,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 ||
@@ -246,6 +242,7 @@ 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) {
@@ -425,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
@@ -445,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();
        
@@ -513,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
@@ -564,10 +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, 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))
@@ -1679,7 +1694,18 @@ void LyXText::SetHeightOfRow(BufferView * bview, Row * row_ptr) const
    row_ptr->baseline(maxasc + labeladdon);
    
    height += row_ptr->height();
-   width = maxwidth;
+   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();
+          }
+   }
 }
 
 
@@ -1920,6 +1946,7 @@ void LyXText::BreakParagraph(BufferView * bview, char keep_layout)
 }
 
 
+#ifndef NEW_INSETS
 void LyXText::OpenFootnote(BufferView * bview)
 {
    LyXParagraph * endpar,* tmppar;
@@ -1974,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
@@ -2079,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 */
@@ -2118,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 */
@@ -2136,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;
@@ -2150,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 */ 
@@ -2649,6 +2677,7 @@ void LyXText::BackspaceInTable(BufferView * bview)
 }
 
 /* table stuff -- end*/
+#endif
 
 
 // Just a macro to make some thing easier. 
@@ -2745,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
@@ -2888,6 +2918,7 @@ void LyXText::charInserted()
        }
 }
 
+
 void LyXText::PrepareToPrint(BufferView * bview,
                             Row * row, float & x,
                             float & fill_separator, 
@@ -2903,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) {
@@ -2912,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;
@@ -3588,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;
@@ -3767,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();
@@ -3790,23 +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;
-       if (inset_owner)
-               ww = inset_owner->width(bview->painter(), font) - 1;
-       else
-               ww = bview->workWidth();
+       ww = bview->workWidth();
 
        bool clear_area = true;
+       Inset * inset = 0;
 
        if ((last == row_ptr->pos()) &&
-           row_ptr->par()->GetInset(row_ptr->pos())) {
-               clear_area = row_ptr->par()->GetInset(row_ptr->pos())->doClearArea();
+           (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 (bv_owner && clear_area)
-               pain.fillRectangle(x_offset, y_offset, ww, row_ptr->height());
        
        if (selection) {
                /* selection code */
@@ -3957,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);
@@ -4074,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){
@@ -4322,7 +4378,7 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
                                        - row_ptr->par()->bibkey->width(bview->painter(), font);
                        row_ptr->par()->bibkey->draw(bview, font,
                                                   y_offset + row_ptr->baseline(), 
-                                                  tmpx);
+                                                  tmpx, clear_area);
                }
        }
        
@@ -4526,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 
@@ -4638,7 +4694,7 @@ 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
        }
@@ -4788,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, 
@@ -4931,7 +4988,8 @@ void LyXText::InsertFootnoteEnvironment(BufferView * bview,
 
    ClearSelection();
 }
-   
+#endif
+
 
 // returns pointer to a specified row
 Row * LyXText::GetRow(LyXParagraph * par,