]> git.lyx.org Git - lyx.git/blobdiff - src/text.C
add GuiView parent to QToc for proper memory management.
[lyx.git] / src / text.C
index 905ee32d556433b9c75e2413be4c03121aa9c29a..d2826eb0cdc9731ab09924d4e3dd4cec650598b1 100644 (file)
@@ -319,7 +319,7 @@ void readParagraph(Buffer const & buf, Paragraph & par, LyXLex & lex,
                        break;
                }
 
-               lyxerr[Debug::PARSER] << "Handling paragraph token: `"
+               LYXERR(Debug::PARSER) << "Handling paragraph token: `"
                                      << token << '\'' << endl;
                if (token == "\\begin_layout" || token == "\\end_document"
                    || token == "\\end_inset" || token == "\\begin_deeper"
@@ -367,9 +367,7 @@ int LyXText::singleWidth(Paragraph const & par,
        if (isPrintable(c)) {
                Language const * language = font.language();
                if (language->rightToLeft()) {
-                       if ((lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
-                            lyxrc.font_norm_type == LyXRC::ISO_10646_1)
-                           && language->lang() == "arabic") {
+                       if (language->lang() == "arabic") {
                                if (Encodings::isComposeChar_arabic(c))
                                        return 0;
                                c = par.transformChar(c, pos);
@@ -655,9 +653,9 @@ void LyXText::breakParagraph(LCursor & cur, bool keep_layout)
        // This check is necessary. Otherwise the new empty paragraph will
        // be deleted automatically. And it is more friendly for the user!
        if (cur.pos() != 0 || isempty)
-               setCursor(cur.top(), cur.pit() + 1, 0);
+               setCursor(cur, cur.pit() + 1, 0);
        else
-               setCursor(cur.top(), cur.pit(), 0);
+               setCursor(cur, cur.pit(), 0);
 }
 
 
@@ -1086,40 +1084,88 @@ void LyXText::changeCase(LCursor & cur, LyXText::TextCase action)
                cursorRightOneWord(cur);
        }
 
-       recordUndoSelection(cur);
+       recordUndoSelection(cur, Undo::ATOMIC);
 
-       pos_type pos = from.pos();
-       int par = from.pit();
+       pit_type begPit = from.pit();
+       pit_type endPit = to.pit();
 
-       while (par != int(pars_.size()) && (pos != to.pos() || par != to.pit())) {
-               pit_type pit = par;
-               if (pos == pars_[pit].size()) {
-                       ++par;
-                       pos = 0;
-                       continue;
-               }
-               char_type c = pars_[pit].getChar(pos);
-               if (c != Paragraph::META_INSET) {
-                       switch (action) {
-                       case text_lowercase:
-                               c = lowercase(c);
-                               break;
-                       case text_capitalization:
-                               c = uppercase(c);
-                               action = text_lowercase;
-                               break;
-                       case text_uppercase:
-                               c = uppercase(c);
-                               break;
+       pos_type begPos = from.pos();
+       pos_type endPos = to.pos();
+
+       bool const trackChanges = cur.buffer().params().trackChanges;
+
+       pos_type right = 0; // needed after the for loop
+
+       for (pit_type pit = begPit; pit <= endPit; ++pit) {
+               pos_type parSize = pars_[pit].size();
+
+               pos_type pos = (pit == begPit ? begPos : 0);
+               right = (pit == endPit ? endPos : parSize);
+
+               // process sequences of modified characters; in change 
+               // tracking mode, this approach results in much better
+               // usability than changing case on a char-by-char basis
+               docstring changes;
+
+               bool capitalize = true;
+
+               for (; pos < right; ++pos) {
+                       char_type oldChar = pars_[pit].getChar(pos);
+                       char_type newChar = oldChar;
+
+                       // ignore insets and don't play with deleted text!
+                       if (oldChar != Paragraph::META_INSET && !pars_[pit].isDeleted(pos)) {
+                               switch (action) {
+                               case text_lowercase:
+                                       newChar = lowercase(oldChar);
+                                       break;
+                               case text_capitalization:
+                                       if (capitalize) {
+                                               newChar = uppercase(oldChar);
+                                               capitalize = false;
+                                       }
+                                       break;
+                               case text_uppercase:
+                                       newChar = uppercase(oldChar);
+                                       break;
+                               }
                        }
-               }
 
-               // FIXME: change tracking (MG)
-               // sorry but we are no longer allowed to set a single character directly
-               // we have to rewrite this method in terms of erase&insert operations
-               //pars_[pit].setChar(pos, c);
-               ++pos;
+                       if (!pars_[pit].isLetter(pos) || pars_[pit].isDeleted(pos)) {
+                               capitalize = true; // permit capitalization again
+                       }
+
+                       if (oldChar != newChar) {
+                               changes += newChar;
+                       }
+
+                       if (oldChar == newChar || pos == right - 1) {
+                               if (oldChar != newChar) {
+                                       pos++; // step behind the changing area
+                               }
+                               int erasePos = pos - changes.size();
+                               for (size_t i = 0; i < changes.size(); i++) {
+                                       pars_[pit].insertChar(pos, changes[i],
+                                               pars_[pit].getFontSettings(cur.buffer().params(),
+                                                               erasePos),
+                                               trackChanges);
+                                       if (!pars_[pit].eraseChar(erasePos, trackChanges)) {
+                                               ++erasePos;
+                                               ++pos; // advance
+                                               ++right; // expand selection
+                                       }
+                               }
+                               changes.clear();
+                       }
+               }
        }
+
+       // the selection may have changed due to logically-only deleted chars
+       setCursor(cur, begPit, begPos);
+       cur.resetAnchor();
+       setCursor(cur, endPit, right);
+       cur.setSelection();
+
        checkBufferStructure(cur.buffer(), cur);
 }
 
@@ -1320,12 +1366,10 @@ void LyXText::drawSelection(PainterInfo & pi, int x, int) const
        if (!ptr_cmp(cur.text(), this))
                return;
 
-       if (lyxerr.debugging(Debug::DEBUG)) {
-               lyxerr[Debug::DEBUG]
-                       << BOOST_CURRENT_FUNCTION
-                       << "draw selection at " << x
-                       << endl;
-       }
+       LYXERR(Debug::DEBUG)
+               << BOOST_CURRENT_FUNCTION
+               << "draw selection at " << x
+               << endl;
 
        DocIterator beg = cur.selectionBegin();
        DocIterator end = cur.selectionEnd();
@@ -1400,11 +1444,9 @@ void LyXText::drawSelection(PainterInfo & pi, int x, int) const
                return;
        }
 
-       if (lyxerr.debugging(Debug::DEBUG)) {
-               lyxerr[Debug::DEBUG] << " y1: " << y1 << " y2: " << y2
-                          << "X1:" << X1 << " x2: " << X2 << " wid: " << tm.width()
-                       << endl;
-       }
+       LYXERR(Debug::DEBUG) << " y1: " << y1 << " y2: " << y2
+               << "X1:" << X1 << " x2: " << X2 << " wid: " << tm.width()
+               << endl;
 
        // paint upper rectangle
        pi.pain.fillRectangle(x + x1, y1, x2 - x1, y2 - y1,
@@ -1801,7 +1843,7 @@ void LyXText::setCursorFromCoordinates(LCursor & cur, int const x, int const y)
        ParagraphMetrics const & pm = tm.parMetrics(pit);
 
        int yy = cur.bv().coordCache().get(this, pit).y_ - pm.ascent();
-       lyxerr[Debug::DEBUG]
+       LYXERR(Debug::DEBUG)
                << BOOST_CURRENT_FUNCTION
                << ": x: " << x
                << " y: " << y
@@ -1819,7 +1861,7 @@ void LyXText::setCursorFromCoordinates(LCursor & cur, int const x, int const y)
 
        Row const & row = pm.rows()[r];
 
-       lyxerr[Debug::DEBUG]
+       LYXERR(Debug::DEBUG)
                << BOOST_CURRENT_FUNCTION
                << ": row " << r
                << " from pos: " << row.pos()
@@ -1830,7 +1872,7 @@ void LyXText::setCursorFromCoordinates(LCursor & cur, int const x, int const y)
        pos_type const pos = row.pos() 
                + tm.getColumnNearX(pit, row, xx, bound);
 
-       lyxerr[Debug::DEBUG]
+       LYXERR(Debug::DEBUG)
                << BOOST_CURRENT_FUNCTION
                << ": setting cursor pit: " << pit
                << " pos: " << pos