]> git.lyx.org Git - lyx.git/blobdiff - src/text2.C
Make lyx2lyx output the new external inset format.
[lyx.git] / src / text2.C
index 9cc7edc767f2da8ecff50d219e4442a193e6ba1b..afa44ca91d7b7ba26e7b8d62a5e2e3b8c789a77f 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());
                }
@@ -393,7 +393,7 @@ LyXText::setLayout(LyXCursor & cur, LyXCursor & sstart_cur,
                ++endpit;
        }
 
-       setUndo(bv(), Undo::EDIT, sstart_cur.par(), undoendpit);
+       setUndo(bv(), Undo::EDIT, sstart_cur.par(), boost::prior(undoendpit));
 
        // ok we have a selection. This is always between sstart_cur
        // and sel_end cursor
@@ -427,10 +427,10 @@ LyXText::setLayout(LyXCursor & cur, LyXCursor & sstart_cur,
 // set layout over selection and make a total rebreak of those paragraphs
 void LyXText::setLayout(string const & layout)
 {
-       LyXCursor tmpcursor = cursor;  // store the current cursor 
+       LyXCursor tmpcursor = cursor;  // store the current cursor
 
        // if there is no selection just set the layout
-       // of the current paragraph 
+       // of the current paragraph
        if (!selection.set()) {
                selection.start = cursor;  // dummy selection
                selection.end = cursor;
@@ -486,7 +486,7 @@ bool LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only)
        ParagraphList::iterator pastend = boost::next(end);
 
        if (!test_only)
-               setUndo(bv(), Undo::EDIT, start, pastend);
+               setUndo(bv(), Undo::EDIT, start, end);
 
        bool changed = false;
 
@@ -588,8 +588,7 @@ void LyXText::setFont(LyXFont const & font, bool toggleall)
        // ok we have a selection. This is always between sel_start_cursor
        // and sel_end cursor
 
-       setUndo(bv(), Undo::EDIT,
-               selection.start.par(), boost::next(selection.end.par()));
+       setUndo(bv(), Undo::EDIT, selection.start.par(), selection.end.par());
        freezeUndo();
        cursor = selection.start;
        while (cursor.par() != selection.end.par() ||
@@ -659,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,
@@ -673,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();
@@ -710,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);
@@ -884,12 +883,9 @@ void LyXText::cursorTop()
 
 void LyXText::cursorBottom()
 {
-#warning FIXME
-       // This is how it should be:
-       // ParagraphList::iterator lastpit = boost::prior(ownerParagraphs().end());
-       ParagraphList::iterator lastpit = &ownerParagraphs().back();
-       int pos = lastpit->size();
-       setCursor(lastpit, pos);
+       ParagraphList::iterator lastpit =
+               boost::prior(ownerParagraphs().end());
+       setCursor(lastpit, lastpit->size());
 }
 
 
@@ -991,7 +987,8 @@ void LyXText::setParagraph(bool line_top, bool line_bottom,
                ++endpit;
        }
 
-       setUndo(bv(), Undo::EDIT, selection.start.par(), undoendpit);
+       setUndo(bv(), Undo::EDIT, selection.start.par(),
+               boost::prior(undoendpit));
 
 
        ParagraphList::iterator tmppit = selection.end.par();
@@ -1191,7 +1188,7 @@ void LyXText::setCounter(Buffer const * buf, ParagraphList::iterator pit)
                                        isOK = true;
                                        break;
                                } else {
-                                       tmppit = in->parOwner();
+                                       tmppit = std::find(ownerParagraphs().begin(), ownerParagraphs().end(), *in->parOwner());
                                }
                        }
 
@@ -1276,8 +1273,7 @@ void LyXText::insertInset(Inset * inset)
 {
        if (!cursor.par()->insetAllowed(inset->lyxCode()))
                return;
-       setUndo(bv(), Undo::FINISH, cursor.par(),
-               boost::next(cursor.par()));
+       setUndo(bv(), Undo::FINISH, cursor.par());
        freezeUndo();
        cursor.par()->insertInset(cursor.pos(), inset);
        // Just to rebreak and refresh correctly.
@@ -1329,7 +1325,8 @@ void LyXText::cutSelection(bool doclear, bool realcut)
                ++endpit;
        }
 
-       setUndo(bv(), Undo::DELETE, selection.start.par(), undoendpit);
+       setUndo(bv(), Undo::DELETE, selection.start.par(),
+               boost::prior(undoendpit));
 
 
        endpit = selection.end.par();
@@ -1401,8 +1398,7 @@ void LyXText::pasteSelection()
        if (!CutAndPaste::checkPastePossible())
                return;
 
-       setUndo(bv(), Undo::INSERT,
-               cursor.par(), boost::next(cursor.par()));
+       setUndo(bv(), Undo::INSERT, cursor.par());
 
        ParagraphList::iterator endpit;
        PitPosPair ppp;
@@ -1776,7 +1772,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
@@ -2264,7 +2260,8 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
                                ++endpit;
                        }
 
-                       setUndo(bv(), Undo::DELETE, old_cursor.par(), endpit);
+                       setUndo(bv(), Undo::DELETE, old_cursor.par(),
+                               boost::prior(endpit));
                        cursor = tmpcursor;
 
                        // delete old row
@@ -2295,7 +2292,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
                                ++endpit;
                        }
 
-                       setUndo(bv(), Undo::DELETE, old_cursor.par(), endpit);
+                       setUndo(bv(), Undo::DELETE, old_cursor.par(), boost::prior(endpit));
                        cursor = tmpcursor;
 
                        // delete old row