]> git.lyx.org Git - lyx.git/blobdiff - src/text.C
small changes to ButtonController usage
[lyx.git] / src / text.C
index f7e321723e57ba31e086f76807dd1ba9f156db1a..0783fe9753bee37361c04ea47de743a87df94196 100644 (file)
@@ -260,8 +260,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 +330,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 +346,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 +376,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 +517,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;
 
@@ -1616,7 +1631,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 */ 
@@ -1689,7 +1709,7 @@ void LyXText::SetHeightOfRow(BufferView * bview, Row * row_ptr) const
    height += row_ptr->height();
    float x, dummy;
    PrepareToPrint(bview, row_ptr, x, dummy, dummy, dummy, false);
-   row_ptr->width(maxwidth+x);
+   row_ptr->width(int(maxwidth + x));
    if (inset_owner) {
           Row * r = firstrow;
           width = max(0,workWidth(bview));
@@ -1847,9 +1867,15 @@ void LyXText::BreakParagraph(BufferView * bview, char keep_layout)
        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 */
@@ -1921,7 +1947,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);
    
@@ -2693,9 +2723,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
@@ -3002,9 +3038,10 @@ void LyXText::PrepareToPrint(BufferView * bview,
 #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) {
@@ -3416,12 +3453,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))
@@ -3477,9 +3522,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);
        }
@@ -3557,12 +3608,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();
@@ -3635,9 +3694,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,
@@ -3834,9 +3899,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;
@@ -3845,6 +3911,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);
        
@@ -3853,45 +3923,33 @@ 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()) &&
            (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!!!
                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;
-                       if (inset_owner)
-                               w = inset_owner->width(bview, font);
-                       else
-                               w = ww;
-                       pain.fillRectangle(x_offset,h, w, row_ptr->height()-h);
+                       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())
                {
@@ -3901,11 +3959,7 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
        }
        
        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 &&
@@ -3962,8 +4016,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);
@@ -4443,8 +4497,13 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
 #else
        LyXParagraph * par = row_ptr->par();
 #endif
-       if ((row_ptr->par()->ParFromPos(last + 1) == par) &&
-           (!row_ptr->next() || (row_ptr->next()->par() != row_ptr->par())))
+       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)
@@ -4888,9 +4947,12 @@ int LyXText::GetColumnNearX(BufferView * bview, Row * row, int & x,
                   (!rtl && vc == last + 1 && x > tmpx + 5) ))
                c = last + 1;
 #endif
-       else if (vc == row->pos() ||
-                (row->par()->table
-                 && vc <= last && row->par()->IsNewline(vc-1)) ) {
+       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;
@@ -4903,8 +4965,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