]> git.lyx.org Git - lyx.git/blobdiff - src/text.C
Minor code shuffle.
[lyx.git] / src / text.C
index 06d534a349fc6755416cedc01cba1d864a57007d..3b21f04f20fc104d03be607814ae2e5129b80ea5 100644 (file)
@@ -35,6 +35,7 @@
 #include "BufferView.h"
 #include "language.h"
 #include "ParagraphParameters.h"
+#include "undo_funcs.h"
 
 using std::max;
 using std::min;
@@ -436,9 +437,9 @@ void LyXText::draw(BufferView * bview, Row const * row,
                        tmpinset->draw(bview, font, offset+row->baseline(), x,
                                       cleared);
 #ifdef SEEMS_TO_BE_NOT_NEEDED
-                       if (status == CHANGED_IN_DRAW) {
+                       if (status_ == CHANGED_IN_DRAW) {
                                UpdateInset(bview, tmpinset);
-                               status = CHANGED_IN_DRAW;
+                               status(bview, CHANGED_IN_DRAW);
                        }
 #endif
                }
@@ -1597,9 +1598,7 @@ void LyXText::breakParagraph(BufferView * bview, char keep_layout)
        && layout.labeltype!= LABEL_SENSITIVE)
           return;
    
-   setUndo(bview->buffer(), Undo::INSERT,
-          cursor.par()->previous(), 
-          cursor.par()->next()); 
+   setUndo(bview, Undo::INSERT,cursor.par(),cursor.par()->next()); 
 
    // Always break behind a space
    //
@@ -1636,7 +1635,7 @@ void LyXText::breakParagraph(BufferView * bview, char keep_layout)
           cursorLeft(bview);
    } 
    
-   status = LyXText::NEED_MORE_REFRESH;
+   status(bview, LyXText::NEED_MORE_REFRESH);
    refresh_row = cursor.row();
    refresh_y = cursor.y() - cursor.row()->baseline();
    
@@ -1690,9 +1689,8 @@ 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,
-               cursor.par()->previous(),
-               cursor.par()->next());
+       setUndo(bview, Undo::INSERT,
+               cursor.par(), cursor.par()->next());
 
        // When the free-spacing option is set for the current layout,
        // disable the double-space checking
@@ -1855,7 +1853,7 @@ void LyXText::insertChar(BufferView * bview, char c)
                        y -= row->previous()->height();
                        refresh_y = y;
                        refresh_row = row->previous();
-                       status = LyXText::NEED_MORE_REFRESH;
+                       status(bview, LyXText::NEED_MORE_REFRESH);
             
                        breakAgainOneRow(bview, row);
 
@@ -1890,7 +1888,7 @@ void LyXText::insertChar(BufferView * bview, char c)
                refresh_row = row; 
                refresh_x = cursor.x();
                refresh_pos = cursor.pos();
-               status = LyXText::NEED_MORE_REFRESH;
+               status(bview, LyXText::NEED_MORE_REFRESH);
                breakAgainOneRow(bview, row); 
                // will the cursor be in another row now?
                if (rowLast(row) <= cursor.pos() + 1 && row->next()) {
@@ -1921,9 +1919,9 @@ void LyXText::insertChar(BufferView * bview, char c)
                int const tmpheight = row->height();
                setHeightOfRow(bview, row);
                if (tmpheight == row->height())
-                       status = LyXText::NEED_VERY_LITTLE_REFRESH;
+                       status(bview, LyXText::NEED_VERY_LITTLE_REFRESH);
                else
-                       status = LyXText::NEED_MORE_REFRESH;
+                       status(bview, LyXText::NEED_MORE_REFRESH);
             
                current_font = rawtmpfont;
                real_current_font = realtmpfont;
@@ -2018,7 +2016,7 @@ void LyXText::prepareToPrint(BufferView * bview,
           if (row->par()->getChar(row->pos()) == Paragraph::META_INSET
               && (inset=row->par()->getInset(row->pos()))
               && (inset->display())) // || (inset->scroll() < 0)))
-            align = (inset->LyxCode() == Inset::MATHMACRO_CODE)
+            align = (inset->lyxCode() == Inset::MATHMACRO_CODE)
                     ? LYX_ALIGN_BLOCK : LYX_ALIGN_CENTER;
 
           switch (align) {
@@ -2263,7 +2261,7 @@ string const LyXText::selectNextWord(BufferView * bview,
        // Start the selection from here
        selection.cursor = cursor;
        
-       std::ostringstream latex;
+       ostringstream latex;
 
        // and find the end of the word 
        // (optional hyphens are part of a word)
@@ -2271,7 +2269,7 @@ string const LyXText::selectNextWord(BufferView * bview,
               && (cursor.par()->isLetter(cursor.pos())) 
                   || (cursor.par()->getChar(cursor.pos()) == Paragraph::META_INSET
                       && cursor.par()->getInset(cursor.pos()) != 0
-                      && cursor.par()->getInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0
+                      && cursor.par()->getInset(cursor.pos())->latex(bview->buffer(), latex, false, false) == 0
                       && latex.str() == "\\-"
                           ))
                cursor.pos(cursor.pos() + 1);
@@ -2297,14 +2295,14 @@ void LyXText::selectSelectedWord(BufferView * bview)
        
        // set the sel cursor
        selection.cursor = cursor;
-       std::ostringstream latex;
+       ostringstream latex;
        
        // now find the end of the word
        while (cursor.pos() < cursor.par()->size()
               && (cursor.par()->isLetter(cursor.pos())
                   || (cursor.par()->getChar(cursor.pos()) == Paragraph::META_INSET
                       && cursor.par()->getInset(cursor.pos()) != 0
-                      && cursor.par()->getInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0
+                      && cursor.par()->getInset(cursor.pos())->latex(bview->buffer(), latex, false, false) == 0
                       && latex.str() == "\\-"
                           )))
                cursor.pos(cursor.pos() + 1);
@@ -2396,49 +2394,14 @@ void LyXText::changeCase(BufferView * bview, LyXText::TextCase action)
        LyXCursor to;
 
        if (selection.set()) {
-               from = selection.cursor;
-               to = cursor;
+               from = selection.start;
+               to = selection.end;
        } else {
                getWord(from, to, PARTIAL_WORD);
-               setCursor(bview, to.par(), to.pos()+1);
+               setCursor(bview, to.par(), to.pos() + 1);
        }
 
-       setUndo(bview->buffer(), Undo::FINISH,
-               from.par()->previous(), to.par()->next()); 
-
-#if 1
-       changeRegionCase(bview, to, from, action);
-#else
-       while(from != to) {
-               unsigned char c = from.par()->getChar(from.pos());
-               if (!IsInsetChar(c) && !IsHfillChar(c)) {
-                       switch (action) {
-                       case text_lowercase:
-                               c = tolower(c);
-                               break;
-                       case text_capitalization:
-                               c = toupper(c);
-                               action = text_lowercase;
-                               break;
-                       case text_uppercase:
-                               c = toupper(c);
-                               break;
-                       }
-               }
-               from.par()->setChar(from.pos(), c);
-               checkParagraph(bview, from.par(), from.pos());
-               from.pos(from.pos() + 1);
-               if (from.pos() >= from.par()->size()) {
-                       from.par(from.par()->next());
-                       from.pos(0);
-               }
-       }
-       if (to.row() != from.row()) {
-               refresh_y = from.y() - from.row()->baseline();
-               refresh_row = from.row();
-               status = LyXText::NEED_MORE_REFRESH;
-       }
-#endif
+       changeRegionCase(bview, from, to, action);
 }
 
 
@@ -2447,13 +2410,16 @@ void LyXText::changeRegionCase(BufferView * bview,
                               LyXCursor const & to,
                               LyXText::TextCase action)
 {
-       setUndo(bview->buffer(), Undo::FINISH,
-               from.par()->previous(), to.par()->next());
-
-       LyXCursor tmp(from);
+       lyx::Assert(from <= to);
        
-       while(tmp != to) {
-               unsigned char c = tmp.par()->getChar(tmp.pos());
+       setUndo(bview, Undo::FINISH,
+               from.par(), to.par()->next());
+
+       Paragraph::size_type pos = from.pos();
+       Paragraph * par = from.par();
+
+       while (par && (pos != to.pos() || par != to.par())) {
+               unsigned char c = par->getChar(pos);
                if (!IsInsetChar(c) && !IsHfillChar(c)) {
                        switch (action) {
                        case text_lowercase:
@@ -2468,28 +2434,29 @@ void LyXText::changeRegionCase(BufferView * bview,
                                break;
                        }
                }
-               tmp.par()->setChar(tmp.pos(), c);
-               checkParagraph(bview, tmp.par(), tmp.pos());
-               tmp.pos(tmp.pos() + 1);
-               if (tmp.pos() >= tmp.par()->size()) {
-                       tmp.par(tmp.par()->next());
-                       tmp.pos(0);
+               par->setChar(pos, c);
+               checkParagraph(bview, par, pos);
+
+               ++pos;
+               if (pos == par->size()) {
+                       par = par->next();
+                       pos = 0;
                }
        }
-       if (to.row() != tmp.row()) {
-               refresh_y = tmp.y() - tmp.row()->baseline();
-               refresh_row = tmp.row();
-               status = LyXText::NEED_MORE_REFRESH;
+       if (to.row() != from.row()) {
+               refresh_y = from.y() - from.row()->baseline();
+               refresh_row = from.row();
+               status(bview, LyXText::NEED_MORE_REFRESH);
        }
 }
 
 
-void LyXText::transposeChars(BufferView const & bview)
+void LyXText::transposeChars(BufferView & bview)
 {
        Paragraph * tmppar = cursor.par();
 
-       setUndo(bview.buffer(), Undo::FINISH,
-               tmppar->previous(), tmppar->next()); 
+       setUndo(&bview, Undo::FINISH,
+               tmppar, tmppar->next()); 
 
        Paragraph::size_type tmppos = cursor.pos();
 
@@ -2542,9 +2509,8 @@ 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,
-                       cursor.par()->previous(), 
-                       cursor.par()->next()); 
+               setUndo(bview, Undo::DELETE,
+                       cursor.par(), cursor.par()->next()); 
                cursor = tmpcursor;
                backspace(bview);
        }
@@ -2592,15 +2558,15 @@ void LyXText::backspace(BufferView * bview)
                                if (cursor.row()->height() != tmpheight) {
                                        refresh_y = cursor.y() - cursor.row()->baseline();
                                        refresh_row = cursor.row();
-                                       status = LyXText::NEED_MORE_REFRESH;
+                                       status(bview, LyXText::NEED_MORE_REFRESH);
                                }
                                return;
                        }
                }
 
                if (cursor.par()->previous()) {
-                       setUndo(bview->buffer(), Undo::DELETE,
-                               cursor.par()->previous()->previous(),
+                       setUndo(bview, Undo::DELETE,
+                               cursor.par()->previous(),
                                cursor.par()->next());
                }
                
@@ -2646,7 +2612,7 @@ void LyXText::backspace(BufferView * bview)
                                if (cursor.pos())
                                        cursor.pos(cursor.pos() - 1);
                        
-                       status = LyXText::NEED_MORE_REFRESH;
+                       status(bview, LyXText::NEED_MORE_REFRESH);
                        refresh_row = cursor.row();
                        refresh_y = cursor.y() - cursor.row()->baseline();
                        
@@ -2668,9 +2634,8 @@ void LyXText::backspace(BufferView * bview)
        } else {
                /* this is the code for a normal backspace, not pasting
                 * any paragraphs */ 
-               setUndo(bview->buffer(), Undo::DELETE,
-                       cursor.par()->previous(),
-                       cursor.par()->next()); 
+               setUndo(bview, Undo::DELETE,
+                       cursor.par(), cursor.par()->next()); 
                // 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,
@@ -2680,7 +2645,7 @@ void LyXText::backspace(BufferView * bview)
                
                // some insets are undeletable here
                if (cursor.par()->getChar(cursor.pos()) == Paragraph::META_INSET) {
-                       if (!cursor.par()->getInset(cursor.pos())->Deletable())
+                       if (!cursor.par()->getInset(cursor.pos())->deletable())
                                return; 
                        // force complete redo when erasing display insets
                        // this is a cruel method but safe..... Matthias 
@@ -2786,7 +2751,7 @@ void LyXText::backspace(BufferView * bview)
                                
                                refresh_y = y;
                                refresh_row = tmprow;
-                               status = LyXText::NEED_MORE_REFRESH;
+                               status(bview, LyXText::NEED_MORE_REFRESH);
                                setCursor(bview, cursor.par(), cursor.pos(),
                                          false, cursor.boundary());
                                //current_font = rawtmpfont;
@@ -2814,7 +2779,7 @@ void LyXText::backspace(BufferView * bview)
                        
                        refresh_y = y;
                        refresh_row = row;
-                       status = LyXText::NEED_MORE_REFRESH;
+                       status(bview, LyXText::NEED_MORE_REFRESH);
                        
                        breakAgainOneRow(bview, row);
                        // will the cursor be in another row now?
@@ -2836,9 +2801,9 @@ void LyXText::backspace(BufferView * bview)
                        int const tmpheight = row->height();
                        setHeightOfRow(bview, row);
                        if (tmpheight == row->height())
-                               status = LyXText::NEED_VERY_LITTLE_REFRESH;
+                               status(bview, LyXText::NEED_VERY_LITTLE_REFRESH);
                        else
-                               status = LyXText::NEED_MORE_REFRESH;
+                               status(bview, LyXText::NEED_MORE_REFRESH);
                        refresh_y = y;
                        refresh_row = row;
                        setCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());