]> git.lyx.org Git - lyx.git/blobdiff - src/text2.C
added a parseError signal to Buffer and use it
[lyx.git] / src / text2.C
index 55a7b7c20d50fc46fda361e81922d4dcbba5e1bd..311f6e345835f2eb3ba915c0cfaf0a72c0ba6772 100644 (file)
@@ -330,7 +330,7 @@ void LyXText::toggleInset()
                // No, try to see if we are inside a collapsable inset
                if (inset_owner && inset_owner->owner()
                    && inset_owner->owner()->isOpen()) {
-                       bv()->unlockInset(static_cast<UpdatableInset *>(inset_owner->owner()));
+                       bv()->unlockInset(inset_owner->owner());
                        inset_owner->owner()->close(bv());
                        bv()->getLyXText()->cursorRight(bv());
                }
@@ -658,7 +658,7 @@ void LyXText::redoDrawingOfParagraph(LyXCursor const & cur)
 }
 
 
-// deletes and inserts again all paragaphs between the cursor
+// deletes and inserts again all paragraphs between the cursor
 // and the specified par
 // This function is needed after SetLayout and SetFont etc.
 void LyXText::redoParagraphs(LyXCursor const & cur,
@@ -672,7 +672,7 @@ void LyXText::redoParagraphs(LyXCursor const & cur,
        if (tmprit == rows().begin()) {
                // A trick/hack for UNDO.
                // This is needed because in an UNDO/REDO we could have
-               // changed the ownerParagrah() so the paragraph inside
+               // changed the ownerParagraph() so the paragraph inside
                // the row is NOT my really first par anymore.
                // Got it Lars ;) (Jug 20011206)
                first_phys_pit = ownerParagraphs().begin();
@@ -709,10 +709,10 @@ void LyXText::redoParagraphs(LyXCursor const & cur,
        }
        if (prevrit != rows().end()) {
                setHeightOfRow(prevrit);
-               const_cast<LyXText *>(this)->postPaint(y - prevrit->height());
+               postPaint(y - prevrit->height());
        } else {
                setHeightOfRow(rows().begin());
-               const_cast<LyXText *>(this)->postPaint(0);
+               postPaint(0);
        }
        if (tmprit != rows().end())
                setHeightOfRow(tmprit);
@@ -883,18 +883,9 @@ void LyXText::cursorTop()
 
 void LyXText::cursorBottom()
 {
-#warning FIXME
-       // This is how it should be:
-#ifndef NO_STD_LIST
-       ParagraphList::iterator lastpit = boost::prior(ownerParagraphs().end());
-#else
-       ParagraphList::iterator lastpit = ownerParagraphs().begin();
-       ParagraphList::iterator end = ownerParagraphs().end();
-       while (boost::next(lastpit) != end)
-               ++lastpit;
-#endif
-       int pos = lastpit->size();
-       setCursor(lastpit, pos);
+       ParagraphList::iterator lastpit =
+               boost::prior(ownerParagraphs().end());
+       setCursor(lastpit, lastpit->size());
 }
 
 
@@ -1252,14 +1243,16 @@ void LyXText::updateCounters()
        // CHECK if this is really needed. (Lgb)
        bv()->buffer()->params.getLyXTextClass().counters().reset();
 
-       for (; pit != ownerParagraphs().end(); ++pit) {
+       ParagraphList::iterator beg = ownerParagraphs().begin();
+       ParagraphList::iterator end = ownerParagraphs().end();
+       for (; pit != end; ++pit) {
                while (rowit->par() != pit)
                        ++rowit;
 
                string const oldLabel = pit->params().labelString();
 
                size_t maxdepth = 0;
-               if (pit != ownerParagraphs().begin())
+               if (pit != beg)
                        maxdepth = boost::prior(pit)->getMaxDepthAfter();
 
                if (pit->params().depth() > maxdepth)
@@ -1342,12 +1335,14 @@ void LyXText::cutSelection(bool doclear, bool realcut)
        int endpos = selection.end.pos();
 
        boost::tie(endpit, endpos) = realcut ?
-               CutAndPaste::cutSelection(ownerParagraphs(),
+               CutAndPaste::cutSelection(bv()->buffer()->params,
+                                         ownerParagraphs(),
                                          selection.start.par(), endpit,
                                          selection.start.pos(), endpos,
                                          bv()->buffer()->params.textclass,
                                          doclear)
-               : CutAndPaste::eraseSelection(ownerParagraphs(),
+               : CutAndPaste::eraseSelection(bv()->buffer()->params,
+                                             ownerParagraphs(),
                                              selection.start.par(), endpit,
                                              selection.start.pos(), endpos,
                                              doclear);
@@ -1401,7 +1396,7 @@ void LyXText::copySelection()
 }
 
 
-void LyXText::pasteSelection()
+void LyXText::pasteSelection(size_t sel_index)
 {
        // this does not make sense, if there is nothing to paste
        if (!CutAndPaste::checkPastePossible())
@@ -1415,10 +1410,11 @@ void LyXText::pasteSelection()
        ErrorList el;
 
        boost::tie(ppp, endpit) =
-               CutAndPaste::pasteSelection(ownerParagraphs(),
+               CutAndPaste::pasteSelection(*bv()->buffer(),
+                                           ownerParagraphs(),
                                            cursor.par(), cursor.pos(),
                                            bv()->buffer()->params.textclass,
-                                           el);
+                                           sel_index, el);
        bv()->setErrorList(el);
        bv()->showErrorList(_("Paste"));
 
@@ -1464,7 +1460,9 @@ void LyXText::replaceSelectionWithString(string const & str)
                                  selection.start.pos());
 
        // Insert the new string
-       for (string::const_iterator cit = str.begin(); cit != str.end(); ++cit) {
+       string::const_iterator cit = str.begin();
+       string::const_iterator end = str.end();
+       for (; cit != end; ++cit) {
                selection.end.par()->insertChar(pos, (*cit), font);
                ++pos;
        }
@@ -1504,7 +1502,9 @@ void LyXText::insertStringAsParagraphs(string const & str)
 {
        string linestr(str);
        bool newline_inserted = false;
-       for (string::size_type i = 0; i < linestr.length(); ++i) {
+       string::size_type const siz = linestr.length();
+
+       for (string::size_type i = 0; i < siz; ++i) {
                if (linestr[i] == '\n') {
                        if (newline_inserted) {
                                // we know that \r will be ignored by
@@ -1781,7 +1781,7 @@ float LyXText::getCursorX(RowList::iterator rit,
 void LyXText::setCursorIntern(ParagraphList::iterator pit,
                              pos_type pos, bool setfont, bool boundary)
 {
-       InsetText * it = static_cast<InsetText *>(pit->inInset());
+       UpdatableInset * it = pit->inInset();
        if (it) {
                if (it != inset_owner) {
                        lyxerr[Debug::INSETS] << "InsetText   is " << it
@@ -1926,9 +1926,12 @@ LyXText::getColumnNearX(RowList::iterator rit, int & x, bool & boundary) const
        boundary = false;
        // This (rtl_support test) is not needed, but gives
        // some speedup if rtl_support=false
+       RowList::iterator next_rit = boost::next(rit);
+
        bool const lastrow = lyxrc.rtl_support &&
-               (boost::next(rit) == rowlist_.end() ||
-                boost::next(rit)->par() != rit_par);
+               (next_rit == rowlist_.end() ||
+                next_rit->par() != rit_par);
+
        // If lastrow is false, we don't need to compute
        // the value of rtl.
        bool const rtl = (lastrow)
@@ -1983,10 +1986,12 @@ namespace {
         * and the next row is filled by an inset that spans an entire
         * row.
         */
-       bool beforeFullRowInset(LyXText & lt, LyXCursor const & cur) {
+       bool beforeFullRowInset(LyXText & lt, LyXCursor const & cur)
+       {
                RowList::iterator row = cur.row();
                if (boost::next(row) == lt.rows().end())
                        return false;
+
                Row const & next = *boost::next(row);
 
                if (next.pos() != cur.pos() || next.par() != cur.par())
@@ -1995,9 +2000,11 @@ namespace {
                if (cur.pos() == cur.par()->size()
                    || !cur.par()->isInset(cur.pos()))
                        return false;
+
                Inset const * inset = cur.par()->getInset(cur.pos());
                if (inset->needFullRow() || inset->display())
                        return true;
+
                return false;
        }
 }
@@ -2017,11 +2024,13 @@ void LyXText::setCursorFromCoordinates(LyXCursor & cur, int x, int y)
        cur.row(row);
 
        if (beforeFullRowInset(*this, cur)) {
-               pos_type last = lastPrintablePos(*this, row);
-               float x = getCursorX(boost::next(row), cur.pos(), last, bound);
+               pos_type const last = lastPrintablePos(*this, row);
+               RowList::iterator next_row = boost::next(row);
+
+               float x = getCursorX(next_row, cur.pos(), last, bound);
                cur.ix(int(x));
-               cur.iy(y + row->height() + boost::next(row)->baseline());
-               cur.irow(boost::next(row));
+               cur.iy(y + row->height() + next_row->baseline());
+               cur.irow(next_row);
        } else {
                cur.iy(cur.y());
                cur.ix(cur.x());
@@ -2127,10 +2136,13 @@ void LyXText::cursorUpParagraph()
 
 void LyXText::cursorDownParagraph()
 {
-       if (boost::next(cursor.par()) != ownerParagraphs().end()) {
-               setCursor(boost::next(cursor.par()), 0);
+       ParagraphList::iterator par = cursor.par();
+       ParagraphList::iterator next_par = boost::next(par);
+
+       if (next_par != ownerParagraphs().end()) {
+               setCursor(next_par, 0);
        } else {
-               setCursor(cursor.par(), cursor.par()->size());
+               setCursor(par, par->size());
        }
 }
 
@@ -2233,7 +2245,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
                return false;
 
        // Do not delete empty paragraphs with keepempty set.
-       if (old_cursor.par()->layout()->keepempty)
+       if (old_cursor.par()->allowEmpty())
                return false;
 
        // only do our magic if we changed paragraph
@@ -2282,8 +2294,9 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
                         * the parindent that can occur or dissappear.
                         * The next row can change its height, if
                         * there is another layout before */
-                       if (boost::next(prevrow) != rows().end()) {
-                               breakAgain(boost::next(prevrow));
+                       RowList::iterator tmprit = boost::next(prevrow);
+                       if (tmprit != rows().end()) {
+                               breakAgain(tmprit);
                                updateCounters();
                        }
                        setHeightOfRow(prevrow);