This makes undo partially work. It crashes always when used in the last
par and after "complicated" operations, but it works if used in the middle
of the text for simple insertions/deletions, sometimes even multi-par
stuff. 

In any case, this is somewhat beter than what we have now.

Note that I had to implement Paragraph::operator=() (Lars, you are a
naughty boy...). Replace it with something closer to your taste if you
want. The swap idiom is a bit more work here because the inset owners
need to be set..

Next change i the return type of limited_stack::top(). It's (a) used this
way and (b) consistent with std::stack<> now.

The rest is undo specific stuff, some simplification of the logic and some
code to 'make it work'.

Ok?

[Note that the logic might even get simpler if we would not use paragraph
ids, but ParagraphList ids and use distances from plist->begin() instead of
'first_id' and from plist->end() fo 'last_id'.

In that case, undo would not need Paragraph::id anymore and possibly no
Inset::id, too.]

Andre'


-- 
Those who desire to give up Freedom in order to gain Security, will not have,
nor do they deserve, either one.     (T. Jefferson or B. Franklin or both...)
Index: buffer.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.h,v
retrieving revision 1.143
diff -u -p -r1.143 buffer.h
--- buffer.h    2 Jun 2003 14:02:58 -0000       1.143
+++ buffer.h    4 Jun 2003 06:09:49 -0000
@@ -23,7 +23,6 @@
 #include "author.h"
 #include "iterators.h"
 
-#include <boost/shared_ptr.hpp>
 #include <boost/scoped_ptr.hpp>
 
 class BufferView;
@@ -273,10 +272,10 @@ public:
        bool isMultiLingual();
 
        /// Does this mean that this is buffer local?
-       limited_stack<boost::shared_ptr<Undo> > undostack;
+       limited_stack<Undo> undostack;
 
        /// Does this mean that this is buffer local?
-       limited_stack<boost::shared_ptr<Undo> > redostack;
+       limited_stack<Undo> redostack;
 
        ///
        BufferParams params;
Index: lyxfunc.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfunc.C,v
retrieving revision 1.448
diff -u -p -r1.448 lyxfunc.C
--- lyxfunc.C   2 Jun 2003 14:19:29 -0000       1.448
+++ lyxfunc.C   4 Jun 2003 06:09:49 -0000
@@ -501,7 +501,7 @@ FuncStatus LyXFunc::getStatus(FuncReques
                // jump back to owner if an InsetText, so
                // we get back to the InsetTabular or whatever
                if (inset->lyxCode() == Inset::TEXT_CODE)
-                       inset = static_cast<UpdatableInset*>(inset->owner());
+                       inset = inset->owner();
 
                Inset::Code code = inset->lyxCode();
                switch (code) {
Index: paragraph.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.C,v
retrieving revision 1.280
diff -u -p -r1.280 paragraph.C
--- paragraph.C 3 Jun 2003 15:10:07 -0000       1.280
+++ paragraph.C 4 Jun 2003 06:09:49 -0000
@@ -97,6 +97,31 @@ Paragraph::Paragraph(Paragraph const & l
 }
 
 
+void Paragraph::operator=(Paragraph const & lp)
+{
+       if (&lp != this)
+               return;
+       lyxerr << "Paragraph::operator=()\n";
+       delete pimpl_;
+       pimpl_ = new Pimpl(*lp.pimpl_, this);
+
+       enumdepth = lp.enumdepth;
+       itemdepth = lp.itemdepth;
+       // this is because of the dummy layout of the paragraphs that
+       // follow footnotes
+       layout_ = lp.layout();
+
+       // copy everything behind the break-position to the new paragraph
+       insetlist = lp.insetlist;
+       InsetList::iterator it = insetlist.begin();
+       InsetList::iterator end = insetlist.end();
+       for (; it != end; ++it) {
+               it->inset = it->inset->clone();
+               // tell the new inset who is the boss now
+               it->inset->parOwner(this);
+       }
+}
+
 // the destructor removes the new paragraph from the list
 Paragraph::~Paragraph()
 {
@@ -1205,14 +1230,14 @@ string const Paragraph::asString(Buffer 
 }
 
 
-void Paragraph::setInsetOwner(Inset * i)
+void Paragraph::setInsetOwner(UpdatableInset * inset)
 {
-       pimpl_->inset_owner = i;
+       pimpl_->inset_owner = inset;
        InsetList::iterator it = insetlist.begin();
        InsetList::iterator end = insetlist.end();
        for (; it != end; ++it)
                if (it->inset)
-                       it->inset->setOwner(i);
+                       it->inset->setOwner(inset);
 }
 
 
@@ -1350,7 +1375,7 @@ void Paragraph::layout(LyXLayout_ptr con
 }
 
 
-Inset * Paragraph::inInset() const
+UpdatableInset * Paragraph::inInset() const
 {
        return pimpl_->inset_owner;
 }
Index: paragraph.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.h,v
retrieving revision 1.86
diff -u -p -r1.86 paragraph.h
--- paragraph.h 3 Jun 2003 15:10:07 -0000       1.86
+++ paragraph.h 4 Jun 2003 06:09:49 -0000
@@ -31,6 +31,7 @@ class LatexRunParams;
 class ParagraphParameters;
 class TexRow;
 class ParagraphList;
+class UpdatableInset;
 
 /// A Paragraph holds all text, attributes and insets in a text paragraph
 class Paragraph  {
@@ -55,7 +56,7 @@ public:
        ///
        Paragraph(Paragraph const &);
        ///
-       //void operator=(Paragraph const &);
+       void operator=(Paragraph const &);
        /// the destructor removes the new paragraph from the list
        ~Paragraph();
 
@@ -105,9 +106,9 @@ public:
        void makeSameLayout(Paragraph const & par);
 
        ///
-       Inset * inInset() const;
+       UpdatableInset * inInset() const;
        ///
-       void setInsetOwner(Inset * i);
+       void setInsetOwner(UpdatableInset * inset);
        ///
        void deleteInsetsLyXText(BufferView *);
        ///
Index: paragraph_pimpl.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph_pimpl.h,v
retrieving revision 1.31
diff -u -p -r1.31 paragraph_pimpl.h
--- paragraph_pimpl.h   29 May 2003 11:19:51 -0000      1.31
+++ paragraph_pimpl.h   4 Jun 2003 06:09:49 -0000
@@ -84,7 +84,7 @@ struct Paragraph::Pimpl {
        /// erase the given range
        int erase(lyx::pos_type start, lyx::pos_type end);
        ///
-       Inset * inset_owner;
+       UpdatableInset * inset_owner;
 
        /** A font entry covers a range of positions. Notice that the
            entries in the list are inserted in random order.
Index: text2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v
retrieving revision 1.365
diff -u -p -r1.365 text2.C
--- text2.C     29 May 2003 11:19:51 -0000      1.365
+++ text2.C     4 Jun 2003 06:09:49 -0000
@@ -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());
                }
@@ -1772,7 +1772,7 @@ float LyXText::getCursorX(RowList::itera
 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
Index: undo.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/undo.C,v
retrieving revision 1.14
diff -u -p -r1.14 undo.C
--- undo.C      2 May 2003 13:11:39 -0000       1.14
+++ undo.C      4 Jun 2003 06:09:49 -0000
@@ -17,7 +17,7 @@
 Undo::Undo(undo_kind kind_arg, int id_inset_arg,
           int number_before_arg, int number_behind_arg,
           int cursor_par_arg, int cursor_pos_arg,
-          std::vector<Paragraph *> const & par_arg)
+          ParagraphList const & par_arg)
        : pars(par_arg)
 {
        kind = kind_arg;
@@ -28,11 +28,3 @@ Undo::Undo(undo_kind kind_arg, int id_in
        cursor_pos = cursor_pos_arg;
 }
 
-
-Undo::~Undo()
-{
-       std::vector<Paragraph *>::iterator it = pars.begin();
-       std::vector<Paragraph *>::iterator end = pars.end();
-       for ( ; it != end; ++it)
-               delete *it;
-}
Index: undo.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/undo.h,v
retrieving revision 1.16
diff -u -p -r1.16 undo.h
--- undo.h      2 May 2003 13:11:39 -0000       1.16
+++ undo.h      4 Jun 2003 06:09:49 -0000
@@ -12,9 +12,7 @@
 #ifndef UNDO_H
 #define UNDO_H
 
-#include <vector>
-
-class Paragraph;
+#include "ParagraphList.h"
 
 ///
 class Undo {
@@ -43,14 +41,14 @@ public:
        ///
        int cursor_pos; // valid if >= 0
        ///
-       std::vector<Paragraph *> pars;
-       ///
-       Undo(undo_kind kind_arg, int id_inset_arg,
-            int number_before_arg, int number_behind_arg,
-            int cursor_par_arg, int cursor_pos_arg,
-            std::vector<Paragraph *> const & par_arg);
+       ParagraphList pars;
+
        ///
-       ~Undo();
+       Undo(undo_kind kind, int inset_id,
+            int before_par_id, int behind_par_id,
+            int cursor_par_id, int cursor_pos,
+            ParagraphList const & par_arg);
+
 };
 
 
Index: undo_funcs.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/undo_funcs.C,v
retrieving revision 1.68
diff -u -p -r1.68 undo_funcs.C
--- undo_funcs.C        27 May 2003 13:54:58 -0000      1.68
+++ undo_funcs.C        4 Jun 2003 06:09:49 -0000
@@ -20,11 +20,6 @@
 #include "support/LAssert.h"
 #include "iterators.h"
 
-#include <vector>
-
-using std::vector;
-using boost::shared_ptr;
-
 
 /// The flag used by FinishUndo().
 bool undo_finished;
@@ -33,31 +28,6 @@ bool undo_frozen;
 
 namespace {
 
-/// Utility to return the cursor.
-LyXCursor const & undoCursor(BufferView * bv)
-{
-       if (bv->theLockingInset())
-               return bv->theLockingInset()->cursor(bv);
-       return bv->text->cursor;
-}
-
-
-/**
- * Returns a pointer to the very first Paragraph depending of where
- * we are so it will return the first paragraph of the buffer or the
- * first paragraph of the textinset we're in.
- */
-ParagraphList * undoParagraphs(BufferView * bv, int inset_id)
-{
-       Inset * inset = bv->buffer()->getInsetFromID(inset_id);
-       if (inset) {
-               ParagraphList * result = inset->getParagraphs(0);
-               if (result && !result->empty())
-                       return result;
-       }
-       return &bv->text->ownerParagraphs();
-}
-
 
 /**
  * Finish the undo operation in the case there was no entry
@@ -76,120 +46,111 @@ void finishNoUndo(BufferView * bv)
 // Returns false if no undo possible.
 bool textHandleUndo(BufferView * bv, Undo & undo)
 {
-       Buffer * b = bv->buffer();
+       Buffer * buf = bv->buffer();
 
-       ParIterator const before = b->getParFromID(undo.number_of_before_par);
-       ParIterator const behind = b->getParFromID(undo.number_of_behind_par);
-       ParIterator const null   = b->par_iterator_end();
+       ParIterator const before = buf->getParFromID(undo.number_of_before_par);
+       ParIterator const behind = buf->getParFromID(undo.number_of_behind_par);
+       ParIterator const null   = buf->par_iterator_end();
 
        int const before_id = (before == null) ? -1 : before->id();
        int const behind_id = (behind == null) ? -1 : behind->id();
        int const inset_id  = undo.number_of_inset_id;
 
-       ParagraphList * plist = undoParagraphs(bv, inset_id);
+       Inset * inset = bv->buffer()->getInsetFromID(inset_id);
+       LyXText * text = inset ? inset->getLyXText(bv) : bv->text;
+
+       ParagraphList * plist = &bv->text->ownerParagraphs();
+       if (inset) {
+               ParagraphList * tmp = inset->getParagraphs(0);
+               if (tmp && !tmp->empty())
+                       plist = tmp;
+       }
 
        ParagraphList::iterator first;
        if (before == null) {
                // if there's no before take the beginning of parlist.
                first = plist->begin();
-               LyXText * t = bv->text;
-               if (inset_id >= 0)
-                       if (Inset * in = bv->buffer()->getInsetFromID(inset_id))
-                               t = in->getLyXText(bv);
-               t->setCursorIntern(plist->begin(), 0);
+               text->setCursorIntern(plist->begin(), 0);
        } else {
                first = *before;
                ++first;
        }
        int const first_id  = first->id();
 
-       int after_id;
-       ParagraphList::iterator after;
-       if (behind == null) {
-               // if there's no behind take the end of parlist.
-               after = plist->end();
-               after_id = -1;
-       } else {
-               after = *behind;
-               after_id = after->id();
-       }
-
-       lyxerr << "\nbefore_id: " << before_id << "\n";
-       lyxerr << "first_id:  " << first_id  << "\n";
-       lyxerr << "after_id: " << after_id << "\n";
-       lyxerr << "behind_id: " << behind_id << "\n";
-       lyxerr << "inset_id: " << inset_id << "\n";
+       lyxerr << "\nhandle: before_id: " << before_id << "\n";
+       lyxerr << "handle: first_id:  " << first_id  << "\n";
+       lyxerr << "handle: behind_id: " << behind_id << "\n";
+       lyxerr << "handle: inset_id: " << inset_id << "\n";
 
        // Set the right(new) inset-owner of the paragraph if there is any.
-       if (!undo.pars.empty()) {
-               Inset * in = 0;
-               if (before != null)
-                       in = before->inInset();
-               else if (inset_id >= 0)
-                       in = bv->buffer()->getInsetFromID(inset_id);
-               for (size_t i = 0, n = undo.pars.size(); i < n; ++i)
-                       undo.pars[i]->setInsetOwner(in);
-       }
-
+       UpdatableInset * in = 0;
+       if (before != null)
+               in = before->inInset();
+       else if (inset_id >= 0) {
+               Inset * inset = bv->buffer()->getInsetFromID(inset_id);
+               in = static_cast<UpdatableInset *>(inset);
+       }
+       ParagraphList::iterator pit = undo.pars.begin();
+       ParagraphList::iterator end = undo.pars.end();
+       for ( ; pit != end; ++pit)
+               pit->setInsetOwner(in);
+       lyxerr << "in: " << in << "\n";
+       lyxerr << "undo.pars.size(): " << undo.pars.size() << "\n";
+
+       // remove stuff between first and behind
+       if (behind == null) 
+               plist->erase(first, plist->end());
+       else
+               plist->erase(first, *behind);
+       lyxerr << "after erase\n";
 
-       // quick hack to make the common case work
-       if (undo.pars.size() == 1 && boost::next(first) == after) {
-       //      first = *undo.pars[0];
-               lyxerr << "could use special case...\n";
-       }
-
-#if 0
-       // remove stuff between first and after
-       plist->erase(first, after);
        // re-create first
        if (before == null) {
                // if there's no before take the beginning of parlist.
+               lyxerr << "no 'before'\n";
                first = plist->begin();
        } else {
+               lyxerr << "have 'before'\n";
                first = *before;
                ++first;
        }
 
-#endif
 
        // inset saved paragraphs
-       for (size_t i = 0, n = undo.pars.size(); i < n; ++i) {
-               lyxerr << " inserting par " << undo.pars[i]->id() << "\n";
-               lyxerr << " inserting plist: " << plist << "\n";
-               //plist->insert(first, new Paragraph(*undo.pars[i], true));
-               /*
-                       // A memory optimization for edit:
-                       // Only layout information
-                       // is stored in the undo. So restore
-                       // the text informations.
-                       if (undo.kind == Undo::EDIT) {
-                               undo.pars[par]->setContentsFromPar(*deletelist.back());
-                               ++par;
-                       }
-               */
-       }
+       lyxerr << "undo.pars.size(): " << undo.pars.size() << "\n";
+       plist->insert(first, undo.pars.begin(), undo.pars.end());
+       lyxerr << "after insert\n";
+       /*
+               // A memory optimization for edit:
+               // Only layout information
+               // is stored in the undo. So restore
+               // the text informations.
+               if (undo.kind == Undo::EDIT) {
+                       undo.pars[par]->setContentsFromPar(*deletelist.back());
+                       ++par;
+               }
+       */
 
        // Set the cursor for redoing
        // if we have a par before the first.
        if (before != null) {
                Inset * it = before->inInset();
-               if (it)
-                       it->getLyXText(bv)->setCursorIntern(*before, 0);
-               else
-                       bv->text->setCursorIntern(*before, 0);
+               LyXText * text = it ? it->getLyXText(bv) : bv->text;
+               text->setCursorIntern(*before, 0);
        }
 
        UpdatableInset * it = 0;
-       if (first != plist->begin())
-               it = static_cast<UpdatableInset*>(first->inInset());
+       if (first != plist->end())
+               it = first->inInset();
+       lyxerr << "it: " << it << "\n";
 
-       LyXText * text = it ? it->getLyXText(bv) : bv->text;
 
        text->redoParagraphs(text->cursor, plist->end());
 
        ParIterator tmppar = bv->buffer()->getParFromID(inset_id);
 
        if (tmppar != null) {
+               lyxerr << "tmppar: " << tmppar->id() << "\n";
                LyXText * t;
                Inset * it = tmppar->inInset();
                if (it) {
@@ -205,9 +166,12 @@ bool textHandleUndo(BufferView * bv, Und
                t->clearSelection();
                t->selection.cursor = t->cursor;
                t->updateCounters();
+       } else {
+               lyxerr << "tmppar == null \n";
        }
 
        if (it) {
+               lyxerr << "fit cursor...\n";
                bv->fitCursor();
                bv->updateInset(it);
                bv->text->setCursorIntern(bv->text->cursor.par(),
@@ -217,28 +181,30 @@ bool textHandleUndo(BufferView * bv, Und
        finishUndo();
        bv->text->postPaint(0);
 
+       lyxerr << "finished  textHandleUndo...\n";
        return true;
 }
 
 
-bool createUndo(BufferView * bv, Undo::undo_kind kind,
-       int first_id, int last_id, shared_ptr<Undo> & u)
+void createUndo(BufferView * bv, Undo::undo_kind kind,
+       int first_id, int last_id,
+       limited_stack<Undo> & stack)
 {
-       Buffer * b = bv->buffer();
+       Buffer * buf = bv->buffer();
 
-       ParIterator null    = b->par_iterator_end();
+       ParIterator null    = buf->par_iterator_end();
        ParIterator prev    = null;
        ParIterator before  = null;
        ParIterator first   = null;
        ParIterator last    = null;
        ParIterator behind  = null;
 
-       for (ParIterator it = b->par_iterator_begin(); it != null; ++it) {
-               if ((*it)->id() == first_id) {
+       for (ParIterator it = buf->par_iterator_begin(); it != null; ++it) {
+               if (it->id() == first_id) {
                        first = it;
                        before = prev;
                }
-               if ((*it)->id() == last_id) {
+               if (it->id() == last_id) {
                        last = it;
                        behind = last;
                        ++behind;
@@ -253,11 +219,12 @@ bool createUndo(BufferView * bv, Undo::u
        int const behind_id = (behind == null) ? -1 : behind->id();
        int inset_id        = (first->inInset()) ? first->inInset()->id() : -1;
 
-       lyxerr << "\nbefore_id: " << before_id << "\n";
-       lyxerr << "first_id:  " << first_id  << "\n";
-       lyxerr << "last_id:   " << last_id   << "\n";
-       lyxerr << "behind_id: " << behind_id << "\n";
-       lyxerr << "inset_id:  " << inset_id  << "\n";
+       lyxerr << "\ncreate: before_id: " << before_id << "\n";
+       lyxerr << "create: first_id:  " << first_id  << "\n";
+       lyxerr << "create: last_id:   " << last_id   << "\n";
+       lyxerr << "create: behind_id: " << behind_id << "\n";
+       lyxerr << "create: inset_id:  " << inset_id  << "\n";
+       lyxerr << "create: kind:  " << kind  << "\n";
 
        ParagraphList * plist = 0;
        if (first != null)
@@ -266,7 +233,7 @@ bool createUndo(BufferView * bv, Undo::u
                plist = &behind.plist();
        else if (!plist) {
                lyxerr << "plist from buffer (should this happen?)\n";
-               plist = &b->paragraphs;
+               plist = &buf->paragraphs;
        }
 
        // Undo::EDIT and Undo::FINISH are
@@ -276,32 +243,32 @@ bool createUndo(BufferView * bv, Undo::u
        // appear one by one when undoing.
        // EDIT is special since only layout information, not the
        // contents of a paragaph are stored.
-       if (!undo_finished && (kind != Undo::EDIT) && (kind != Undo::FINISH)) {
+       if (!undo_finished && kind != Undo::EDIT && kind != Undo::FINISH) {
                // Check whether storing is needed.
-               if (!b->undostack.empty() &&
-                   b->undostack.top()->kind == kind &&
-                   b->undostack.top()->number_of_before_par == before_id &&
-                   b->undostack.top()->number_of_behind_par == behind_id) {
+               if (!buf->undostack.empty() &&
+                   buf->undostack.top().kind == kind &&
+                   buf->undostack.top().number_of_before_par == before_id &&
+                   buf->undostack.top().number_of_behind_par == behind_id) {
                        // No undo needed.
-                       return false;
+                       return;
                }
        }
 
        // Create a new Undo.
-#warning FIXME Why is this a vector and not a ParagraphList?
-       std::vector<Paragraph *> undo_pars;
+       LyXCursor const & cur = bv->theLockingInset() ?
+                       bv->theLockingInset()->cursor(bv) : bv->text->cursor;
+
+       stack.push(Undo(kind, inset_id,
+               before_id, behind_id, cur.par()->id(), cur.pos(), ParagraphList()));
+
+       ParagraphList & undo_pars = stack.top().pars;
 
        for (ParagraphList::iterator it = *first; it != *last; ++it) {
-               int id = it->id();
-               Paragraph * tmp = new Paragraph(*it);
-               tmp->id(id);
-               undo_pars.push_back(tmp);
+               undo_pars.push_back(*it);
+               undo_pars.back().id(it->id());
        }
-
-       int const id = last->id();
-       Paragraph * tmp = new Paragraph(**last);
-       tmp->id(id);
-       undo_pars.push_back(tmp);
+       undo_pars.push_back(**last);
+       undo_pars.back().id(last->id());
 
        // A memory optimization: Just store the layout
        // information when only edit.
@@ -310,36 +277,29 @@ bool createUndo(BufferView * bv, Undo::u
        //      for (size_t i = 0, n = undo_pars.size(); i < n; ++i)
        //              undo_pars[i]->clearContents();
 
-       int cursor_par = undoCursor(bv).par()->id();
-       int cursor_pos = undoCursor(bv).pos();
-
-       u.reset(new Undo(kind, inset_id,
-               before_id, behind_id, cursor_par, cursor_pos, undo_pars));
-
        undo_finished = false;
-       return true;
 }
 
 
 // Returns false if no undo possible.
 bool textUndoOrRedo(BufferView * bv,
-       limited_stack<boost::shared_ptr<Undo> > & stack,
-                   limited_stack<boost::shared_ptr<Undo> > & /*otherstack*/)
+       limited_stack<Undo> & stack,
+       limited_stack<Undo> & /*otherstack*/)
 {
        if (stack.empty()) {
                finishNoUndo(bv);
                return false;
        }
 
-       shared_ptr<Undo> undo = stack.top();
+       Undo undo = stack.top();
        stack.pop();
        finishUndo();
 
 /*
        if (!undo_frozen) {
                Buffer * buf = bv->buffer();
-               ParIterator p = b->getParFromID(undo->number_of_before_par);
-               ParIterator const end = b->par_iterator_end();
+               ParIterator p = buf->getParFromID(undo->number_of_before_par);
+               ParIterator const end = buf->par_iterator_end();
                bool ok = false;
                ParagraphList::iterator first;
                // default constructed?
@@ -347,13 +307,21 @@ bool textUndoOrRedo(BufferView * bv,
                        first = p.par();
                        if (first->next())
                                first = first->next();
-               } else
-                       first = undoParagraphs(bv, undo->number_of_inset_id)->begin();
+               } else {
+                       // Set first to the very first Paragraph depending of where
+                       // we are so it will return the first paragraph of the buffer 
or the
+                       // first paragraph of the textinset we're in.
+                       first = bv->text->ownerParagraphs()->begin();
+                       Inset * inset = bv->buffer()->getInsetFromID(inset_id);
+                       if (inset) {
+                               ParagraphList * result = inset->getParagraphs(0);
+                               if (result && !result->empty())
+                                       first = result->begin();
+                       }
+               }
                if (ok) {
-                       shared_ptr<Undo> u;
-                       ParIterator behind = 
b->getParFromID(undo->number_of_behind_par);
-                       if (createUndo(bv, undo->kind, first, behind.par(), u))
-                               otherstack.push(u);
+                       ParIterator behind = 
buf->getParFromID(undo.number_of_behind_par);
+                       createUndo(bv, undo.kind, first, behind.par(), otherstack);
                }
        }
 */
@@ -364,7 +332,7 @@ bool textUndoOrRedo(BufferView * bv,
        // is requested.
        freezeUndo();
        bv->unlockInset(bv->theLockingInset());
-       bool const ret = textHandleUndo(bv, *undo.get());
+       bool const ret = textHandleUndo(bv, undo);
        unFreezeUndo();
        return ret;
 }
@@ -417,12 +385,8 @@ void setUndo(BufferView * bv, Undo::undo
 void setUndo(BufferView * bv, Undo::undo_kind kind,
             ParagraphList::iterator first, ParagraphList::iterator last)
 {
-#warning DISABLED
-       //return;
        if (!undo_frozen) {
-               shared_ptr<Undo> u;
-               if (createUndo(bv, kind, first->id(), last->id(), u))
-                       bv->buffer()->undostack.push(u);
+               createUndo(bv, kind, first->id(), last->id(), bv->buffer()->undostack);
                bv->buffer()->redostack.clear();
        }
 }
Index: insets/inset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/inset.C,v
retrieving revision 1.98
diff -u -p -r1.98 inset.C
--- insets/inset.C      2 Jun 2003 16:14:33 -0000       1.98
+++ insets/inset.C      4 Jun 2003 06:09:49 -0000
@@ -22,6 +22,8 @@
 #include "dimension.h"
 #include "metricsinfo.h"
 
+#include "insets/updatableinset.h"
+
 #include "frontends/Painter.h"
 #include "frontends/mouse_state.h"
 
Index: insets/inset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/inset.h,v
retrieving revision 1.99
diff -u -p -r1.99 inset.h
--- insets/inset.h      3 Jun 2003 15:10:08 -0000       1.99
+++ insets/inset.h      4 Jun 2003 06:09:49 -0000
@@ -33,6 +33,7 @@ class LyXCursor;
 class FuncRequest;
 class WordLangTuple;
 class ParagraphList;
+class UpdatableInset;
 
 namespace grfx {
        class PreviewLoader;
@@ -216,9 +217,9 @@ public:
        ///
        string const & getInsetName() const { return name_; }
        ///
-       void setOwner(Inset * inset) { owner_ = inset; }
+       void setOwner(UpdatableInset * inset) { owner_ = inset; }
        ///
-       Inset * owner() const { return owner_; }
+       UpdatableInset * owner() const { return owner_; }
        ///
        void parOwner(Paragraph * par) { par_owner_ = par; }
        ///
@@ -342,7 +343,7 @@ protected:
 
 private:
        ///
-       Inset * owner_;
+       UpdatableInset * owner_;
        /// the paragraph in which this inset has been inserted
        Paragraph * par_owner_;
        ///
Index: insets/insetinclude.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetinclude.C,v
retrieving revision 1.121
diff -u -p -r1.121 insetinclude.C
--- insets/insetinclude.C       3 Jun 2003 15:10:11 -0000       1.121
+++ insets/insetinclude.C       4 Jun 2003 06:09:49 -0000
@@ -528,14 +528,7 @@ void InsetInclude::draw(PainterInfo & pi
        if (!preview_->monitoring())
                preview_->startMonitoring();
 
-       Dimension dim;
-       MetricsInfo mi;
-       mi.base.bv = pi.base.bv;
-       mi.base.font = pi.base.font;
-       metrics(mi, dim);
-       dim_ = dim;
-
-       pi.pain.image(x, y - dim.asc, dim.wid, dim.height(),
+       pi.pain.image(x, y - dim_.asc, dim_.wid, dim_.height(),
                            *(preview_->pimage()->image()));
 }
 
Index: support/limited_stack.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/limited_stack.h,v
retrieving revision 1.6
diff -u -p -r1.6 limited_stack.h
--- support/limited_stack.h     6 May 2003 09:34:56 -0000       1.6
+++ support/limited_stack.h     4 Jun 2003 06:09:50 -0000
@@ -33,7 +33,7 @@ public:
        }
 
        /// Return the top element.
-       value_type top() {
+       value_type & top() {
                return c_.front();
        }
 

Reply via email to