]> git.lyx.org Git - lyx.git/commitdiff
The BIG UNDO patch. Recodes undo handling for better use inside InsetText.
authorJürgen Vigna <jug@sad.it>
Fri, 6 Jul 2001 15:57:54 +0000 (15:57 +0000)
committerJürgen Vigna <jug@sad.it>
Fri, 6 Jul 2001 15:57:54 +0000 (15:57 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2195 a592a061-630c-0410-9148-cb99ea01b6c8

86 files changed:
src/BufferView2.C
src/BufferView_pimpl.C
src/ChangeLog
src/Makefile.am
src/buffer.C
src/buffer.h
src/figureForm.C
src/insets/ChangeLog
src/insets/figinset.C
src/insets/figinset.h
src/insets/inset.C
src/insets/inset.h
src/insets/insetbib.C
src/insets/insetbib.h
src/insets/insetcite.C
src/insets/insetcite.h
src/insets/insetcollapsable.C
src/insets/insetcollapsable.h
src/insets/insetcommand.C
src/insets/insetcommand.h
src/insets/inseterror.C
src/insets/inseterror.h
src/insets/insetert.C
src/insets/insetert.h
src/insets/insetexternal.C
src/insets/insetexternal.h
src/insets/insetfloat.C
src/insets/insetfloat.h
src/insets/insetfloatlist.h
src/insets/insetfoot.C
src/insets/insetfoot.h
src/insets/insetgraphics.C
src/insets/insetgraphics.h
src/insets/insetinclude.C
src/insets/insetinclude.h
src/insets/insetindex.C
src/insets/insetindex.h
src/insets/insetinfo.C
src/insets/insetinfo.h
src/insets/insetlabel.C
src/insets/insetlabel.h
src/insets/insetlatexaccent.C
src/insets/insetlatexaccent.h
src/insets/insetlist.C
src/insets/insetlist.h
src/insets/insetmarginal.C
src/insets/insetmarginal.h
src/insets/insetminipage.C
src/insets/insetminipage.h
src/insets/insetparent.C
src/insets/insetparent.h
src/insets/insetquotes.C
src/insets/insetquotes.h
src/insets/insetref.C
src/insets/insetref.h
src/insets/insetspecialchar.C
src/insets/insetspecialchar.h
src/insets/insettabular.C
src/insets/insettabular.h
src/insets/insettext.C
src/insets/insettext.h
src/insets/insettheorem.C
src/insets/insettheorem.h
src/insets/insettoc.h
src/insets/inseturl.C
src/insets/inseturl.h
src/lyxfunc.C
src/lyxtext.h
src/mathed/formula.C
src/mathed/formula.h
src/mathed/formulabase.C
src/mathed/formulabase.h
src/mathed/formulamacro.C
src/mathed/formulamacro.h
src/paragraph.C
src/paragraph.h
src/paragraph_pimpl.C
src/paragraph_pimpl.h
src/screen.C
src/tabular.C
src/text.C
src/text2.C
src/undo.C
src/undo.h
src/undo_funcs.C [new file with mode: 0644]
src/undo_funcs.h [new file with mode: 0644]

index 4c08feb2de3e6ae69d789c3d3886768c1b7db5b2..d6f99fcef760ac2893c12bef40d954cecf9255f8 100644 (file)
@@ -30,6 +30,7 @@
 #include "support/lyxfunctional.h" //equal_1st_in_pair
 #include "language.h"
 #include "gettext.h"
+#include "undo_funcs.h"
 
 extern BufferList bufferlist;
 
@@ -227,7 +228,7 @@ void BufferView::menuUndo()
                hideCursor();
                beforeChange(text);
                update(text, BufferView::SELECT|BufferView::FITCUR);
-               if (!text->textUndo(this))
+               if (!textUndo(this))
                        owner()->message(_("No forther undo information"));
                else
                        update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
@@ -248,7 +249,7 @@ void BufferView::menuRedo()
                hideCursor();
                beforeChange(text);
                update(text, BufferView::SELECT|BufferView::FITCUR);
-               if (!text->textRedo(this))
+               if (!textRedo(this))
                        owner()->message(_("No further redo information"));
                else
                        update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
@@ -469,11 +470,11 @@ int BufferView::unlockInset(UpdatableInset * inset)
        if (inset && theLockingInset() == inset) {
                inset->insetUnlock(this);
                theLockingInset(0);
-               text->finishUndo();
+               finishUndo();
                return 0;
        } else if (inset && theLockingInset() &&
                   theLockingInset()->unlockInsetInInset(this, inset)) {
-               text->finishUndo();
+               finishUndo();
                return 0;
        }
        return bufferlist.unlockInset(inset);
@@ -486,9 +487,9 @@ void BufferView::lockedInsetStoreUndo(Undo::undo_kind kind)
                return; // shouldn't happen
        if (kind == Undo::EDIT) // in this case insets would not be stored!
                kind = Undo::FINISH;
-       text->setUndo(buffer(), kind,
-                     text->cursor.par()->previous(), 
-                     text->cursor.par()->next());
+       setUndo(this, kind,
+               text->cursor.par(),
+               text->cursor.par()->next());
 }
 
 
index e63c903df79f0b321b948aa4f22d9bffdb5c21b4..b15dd9ad75811a2349fbabd7d216dc5e1312ba70 100644 (file)
@@ -59,6 +59,7 @@
 #include "insets/insetspecialchar.h"
 #include "gettext.h"
 #include "ParagraphParameters.h"
+#include "undo_funcs.h"
 #include "mathed/formulabase.h"
 
 extern LyXTextClass::size_type current_layout;
@@ -629,7 +630,7 @@ void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
        
        if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
                bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
-       bv_->text->finishUndo();
+       finishUndo();
        bv_->text->selection.cursor = bv_->text->cursor;
        bv_->text->cursor.x_fix(bv_->text->cursor.x());
        
@@ -774,7 +775,7 @@ void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
                // ...or maybe the SetCursorParUndo()
                // below isn't necessary at all anylonger?
                if (inset_hit->lyxCode() == Inset::REF_CODE) {
-                       bv_->text->setCursorParUndo(buffer_);
+                       setCursorParUndo(bv_);
                }
 
                owner_->message(inset_hit->editMessage());
@@ -1062,7 +1063,7 @@ void BufferView::Pimpl::cursorPrevious(LyXText * text)
                y += bv_->text->first;
        Row * cursorrow = text->cursor.row();
        text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
-       bv_->text->finishUndo();
+       finishUndo();
        // This is to allow jumping over large insets
        if ((cursorrow == text->cursor.row()))
                text->cursorUp(bv_);
@@ -1090,7 +1091,7 @@ void BufferView::Pimpl::cursorNext(LyXText * text)
     
        Row * cursorrow = text->cursor.row();
        text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
-       bv_->text->finishUndo();
+       finishUndo();
        // This is to allow jumping over large insets
        if ((cursorrow == bv_->text->cursor.row()))
                text->cursorDown(bv_);
@@ -1219,7 +1220,7 @@ void BufferView::Pimpl::insetUnlock()
                if (!inset_slept)
                        bv_->theLockingInset()->insetUnlock(bv_);
                bv_->theLockingInset(0);
-               bv_->text->finishUndo();
+               finishUndo();
                inset_slept = false;
        }
 }
@@ -1819,7 +1820,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                }
                if (!is_rtl)
                        lt->cursorRight(bv_, false);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(false);
                owner_->showState();
        }
@@ -1861,7 +1862,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                if  (is_rtl)
                        lt->cursorRight(bv_, false);
 
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(false);
                owner_->showState();
        }
@@ -1875,7 +1876,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        beforeChange(lt);
                update(lt, BufferView::UPDATE);
                lt->cursorUp(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(false);
                owner_->showState();
        }
@@ -1889,7 +1890,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        beforeChange(lt);
                update(lt, BufferView::UPDATE);
                lt->cursorDown(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(false);
                owner_->showState();
        }
@@ -1903,7 +1904,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        beforeChange(lt);
                update(lt, BufferView::UPDATE);
                lt->cursorUpParagraph(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(false);
                owner_->showState();
        }
@@ -1917,7 +1918,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        beforeChange(lt);
                update(lt, BufferView::UPDATE);
                lt->cursorDownParagraph(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(false);
                owner_->showState();
        }
@@ -1931,7 +1932,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        beforeChange(lt);
                update(lt, BufferView::UPDATE);
                cursorPrevious(lt);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(false);
                owner_->showState();
        }
@@ -1945,7 +1946,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        beforeChange(lt);
                update(lt, BufferView::UPDATE);
                cursorNext(lt);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(false);
                owner_->showState();
        }
@@ -1959,7 +1960,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        beforeChange(lt);
                update(lt, BufferView::SELECT|BufferView::FITCUR);
                lt->cursorHome(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(false);
                owner_->showState();
        }
@@ -1974,7 +1975,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                update(lt,
                       BufferView::SELECT|BufferView::FITCUR);
                lt->cursorEnd(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(false);
                owner_->showState();
        }
@@ -1990,7 +1991,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                update(lt,
                       BufferView::SELECT|BufferView::FITCUR);
                lt->cursorTab(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(false);
                owner_->showState();
        }
@@ -2007,7 +2008,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        lt->cursorLeftOneWord(bv_);
                else
                        lt->cursorRightOneWord(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(false);
                owner_->showState();
        }
@@ -2024,7 +2025,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        lt->cursorRightOneWord(bv_);
                else
                        lt->cursorLeftOneWord(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(false);
                owner_->showState();
        }
@@ -2039,7 +2040,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                update(lt,
                       BufferView::SELECT|BufferView::FITCUR);
                lt->cursorTop(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(false);
                owner_->showState();
        }
@@ -2054,7 +2055,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                update(lt,
                       BufferView::SELECT|BufferView::FITCUR);
                lt->cursorBottom(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(false);
                owner_->showState();
        }
@@ -2071,7 +2072,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        lt->cursorLeft(bv_);
                else
                        lt->cursorRight(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(true);
                owner_->showState();
        }
@@ -2087,7 +2088,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        lt->cursorRight(bv_);
                else
                        lt->cursorLeft(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(true);
                owner_->showState();
        }
@@ -2100,7 +2101,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                update(lt,
                       BufferView::SELECT|BufferView::FITCUR);
                lt->cursorUp(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(true);
                owner_->showState();
        }
@@ -2113,7 +2114,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                update(lt,
                       BufferView::SELECT|BufferView::FITCUR);
                lt->cursorDown(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(true);
                owner_->showState();
        }
@@ -2126,7 +2127,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                update(lt,
                       BufferView::SELECT|BufferView::FITCUR);
                lt->cursorUpParagraph(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(true);
                owner_->showState();
        }
@@ -2139,7 +2140,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                update(lt,
                       BufferView::SELECT|BufferView::FITCUR);
                lt->cursorDownParagraph(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(true);
                owner_->showState();
        }
@@ -2151,7 +2152,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                
                update(lt, BufferView::SELECT|BufferView::FITCUR);
                cursorPrevious(lt);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(true);
                owner_->showState();
        }
@@ -2163,7 +2164,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                
                update(lt, BufferView::SELECT|BufferView::FITCUR);
                cursorNext(lt);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(true);
                owner_->showState();
        }
@@ -2175,7 +2176,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                
                update(lt, BufferView::SELECT|BufferView::FITCUR);
                lt->cursorHome(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(true);
                owner_->showState();
        }
@@ -2187,7 +2188,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                
                update(lt, BufferView::SELECT|BufferView::FITCUR);
                lt->cursorEnd(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(true);
                owner_->showState();
        }
@@ -2202,7 +2203,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        lt->cursorLeftOneWord(bv_);
                else
                        lt->cursorRightOneWord(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(true);
                owner_->showState();
        }
@@ -2217,7 +2218,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        lt->cursorRightOneWord(bv_);
                else
                        lt->cursorLeftOneWord(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(true);
                owner_->showState();
        }
@@ -2231,7 +2232,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                        break;
                update(lt, BufferView::SELECT|BufferView::FITCUR);
                lt->cursorTop(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(true);
                owner_->showState();
        }
@@ -2246,7 +2247,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                update(lt,
                       BufferView::SELECT|BufferView::FITCUR);
                lt->cursorBottom(bv_);
-               lt->finishUndo();
+               finishUndo();
                moveCursorUpdate(true);
                owner_->showState();
        }
@@ -3308,7 +3309,7 @@ bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
        LyXText * lt = bv_->getLyXText();
        
        beforeChange(lt);
-       lt->finishUndo();
+       finishUndo();
        if (!insertInset(new_inset)) {
                delete new_inset;
                return false;
@@ -3333,8 +3334,8 @@ bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
        }
 
        // not quite sure if we want this...
-       bv_->text->setCursorParUndo(buffer_);
-       bv_->text->freezeUndo();
+       setCursorParUndo(bv_);
+       freezeUndo();
        
        beforeChange(bv_->text);
        if (!lout.empty()) {
@@ -3378,7 +3379,7 @@ bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
        bv_->text->insertInset(bv_, inset);
        update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
 
-       bv_->text->unFreezeUndo();
+       unFreezeUndo();
        return true;
 }
 
index 5e5087f99095bf177ce15c65a55e9f9c979a9d88..3d626b1438ec73948b9ad810b9929504c616aed7 100644 (file)
@@ -1,3 +1,33 @@
+2001-07-06  Juergen Vigna  <jug@sad.it>
+
+       * a lot of files: changed the access to LyXText::status and the
+       call of undo-functions.
+       
+       * undo.[Ch]: added a inset_id to the undo informations.
+
+       * undo_funcs.[Ch]: added and moved here all undo functions.
+
+       * lyxtext.h: give the status enum a weight, made status_ a private
+       variable and made accessor functions for it, removed the whole bunch
+       of undo-functions as they are now in their own file, make some
+       functions publically available. Added function ownerParagraph with
+       int parameter.
+
+       * paragraph.[Ch]: added "bool same_ids" to the constructor,
+       made InInset() a const function, added getParFromID() function.
+
+       * buffer.[Ch]: added const version for inset_iterator functions,
+       added getInsetFromID() function.
+
+       * BufferView2.C, BufferView_pimpl.C, text.C, text2.C, lyxfunc.C:
+       changed undo functions for new version.
+
+2001-07-05  Juergen Vigna  <jug@sad.it>
+
+       * paragraph_pimpl.C (Pimpl): set id_ also here (this is because some
+       unknow mechanism does not call the proper consturctor but only this
+       one also if I request the other!?
+
 2001-07-06  Lars Gullik Bjønnes  <larsbj@birdstep.com>
 
        * BufferView_pimpl.C (resizeCurrentBuffer): init the new LyXText
index c32b9a98963a9e112c3c76ea229e291bc4fd6b8f..13eed40c4a15442ab4db61a89f80efa743cbb640 100644 (file)
@@ -205,6 +205,8 @@ lyx_SOURCES = \
        trans_mgr.h \
        undo.C \
        undo.h \
+       undo_funcs.C \
+       undo_funcs.h \
        undostack.C \
        undostack.h \
        vc-backend.C \
index e0c1fb8124bb7e94d935773e1b8a695725487bec..8a0d18603b43a8daa650960b2745cd220b70ab84 100644 (file)
@@ -1114,7 +1114,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                            lyxerr << "WP:" << mini->width() << endl;
                            mini->width(tostr(par->params().pextraWidthp())+"%");
                        }
-                       mini->inset.par = par;
+                       mini->inset.paragraph(par);
                        // Insert the minipage last in the
                        // previous paragraph.
                        if (par->params().pextraHfill()) {
@@ -1184,7 +1184,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                    lyxerr << "WP:" << mini->width() << endl;
                    mini->width(tostr(par->params().pextraWidthp())+"%");
                }
-               mini->inset.par = minipar;
+               mini->inset.paragraph(minipar);
                        
                // Insert the minipage last in the
                // previous paragraph.
@@ -3438,7 +3438,7 @@ Buffer::Lists const Buffer::getLists() const
                                        // Now find the caption in the float...
                                        // We now tranverse the paragraphs of
                                        // the inset...
-                                       Paragraph * tmp = il->inset.par;
+                                       Paragraph * tmp = il->inset.paragraph();
                                        while (tmp) {
                                                if (tmp->layout == cap) {
                                                        SingleList & item = l[type];
@@ -3623,3 +3623,18 @@ void Buffer::inset_iterator::setParagraph()
        //it = 0;
        // We maintain an invariant that whenever par = 0 then it = 0
 }
+
+
+Inset * Buffer::getInsetFromID(int id_arg) const
+{
+       for (inset_iterator it = inset_const_iterator_begin();
+                it != inset_const_iterator_end(); ++it)
+       {
+               if ((*it)->id() == id_arg)
+                       return *it;
+               Inset * in = (*it)->getInsetFromID(id_arg);
+               if (in)
+                       return in;
+       }
+       return 0;
+}
index ae9cbb0ce2d0092e723ca8ba9169401cf0be3408..47d94282eaa51b0f2ac6bb9f3399e8c224f5ea3f 100644 (file)
@@ -427,6 +427,16 @@ public:
        inset_iterator inset_iterator_end() {
                return inset_iterator();
        }
+       ///
+       inset_iterator inset_const_iterator_begin() const {
+               return inset_iterator(paragraph);
+       }
+       ///
+       inset_iterator inset_const_iterator_end() const {
+               return inset_iterator();
+       }
+       ///
+       Inset * getInsetFromID(int id_arg) const;
 };
 
 
index 3721def9bfee89db924b49cb80715ab3f83d3a3a..e572f3135110334e3d49d6e224f1665cbb37d72e 100644 (file)
@@ -22,6 +22,7 @@
 #include "BufferView.h"
 #include "lyxtext.h"
 #include "LyXView.h"
+#include "undo_funcs.h"
 #include "gettext.h"
 
 extern FD_form_figure * fd_form_figure;
@@ -63,8 +64,8 @@ void FigureApplyCB(FL_OBJECT *, long)
        current_view->update(current_view->text, BufferView::SELECT|BufferView::FITCUR);
        current_view->beforeChange(current_view->text);
       
-       current_view->text->setCursorParUndo(current_view->buffer()); 
-       current_view->text->freezeUndo();
+       setCursorParUndo(current_view); 
+       freezeUndo();
 
        current_view->text->breakParagraph(current_view);
        current_view->update(current_view->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
@@ -96,7 +97,7 @@ void FigureApplyCB(FL_OBJECT *, long)
        new_inset->edit(current_view, 0, 0, 0);
        current_view->update(current_view->text, BufferView::SELECT|BufferView::FITCUR);
        current_view->owner()->message(_("Figure inserted"));
-       current_view->text->unFreezeUndo();
+       unFreezeUndo();
        current_view->setState();
 }
 
index 7e16bda48dbd2baaf5b42263979085556d6492e2..558189bbd40de48551d80b6cc58ecf11ec6aa2b7 100644 (file)
@@ -1,3 +1,13 @@
+2001-07-06  Juergen Vigna  <jug@sad.it>
+
+       * a lot of files: added implementation of the below new functions
+       and the change to clone(). Also the call of the new undo-functions
+       where needed.
+       
+       * inset.h: added an inset_id, added functions getParFromID,
+       getInsetFromID, firstParagraph, cursor and id functions, added
+       bool same_ids to clone function.
+
 2001-07-05  Lars Gullik Bjønnes  <larsbj@birdstep.com>
 
        * insettext.[hC]: make cached_text a shared_ptr, make Cache be a map
        * inseturl.C: fix method names in these to begin
          with small char too, so they inherit
  
+2001-06-28  Juergen Vigna  <jug@sad.it>
+
+       * insettext.C (setFont): fixed font settings using toggleFree()
+       instead of setFont().
+
 2001-06-28  Lars Gullik Bjønnes  <larsbj@birdstep.com>
 
        * Change a lot of method names to begin with a small char.
index f2d17b3b85857a7a8b46a61d83a50314cb7aa088..f8c81fc2a93b4c3e0bbedcc216fa3bd3f82d4a75 100644 (file)
@@ -1241,7 +1241,7 @@ void InsetFig::edit(BufferView * bv, int, int, unsigned int)
 }
 
 
-Inset * InsetFig::clone(Buffer const & buffer) const
+Inset * InsetFig::clone(Buffer const & buffer, bool) const
 {
        InsetFig * tmp = new InsetFig(100, 100, buffer);
 
index 3deaf532dc9936de971de1d17b0748602bf68b49..daef7707de785e043dd0e677c0dc4f84ff01a591 100644 (file)
@@ -59,7 +59,7 @@ public:
        ///
        Inset::Code lyxCode() const;
        ///
-       Inset * clone(Buffer const &) const;
+       Inset * clone(Buffer const &, bool same_id = false) const;
        ///
        void callbackFig(long arg);
        ///
index 23bdff53547bc688764c2de0e40ccf7024c08ca6..dc8163dd031d2b83a511f29b2007db5ac84d3657 100644 (file)
 #include "support/lstrings.h"
 #include "gettext.h"
 #include "lyxfont.h"
+#include "lyxcursor.h"
+#include "lyxtext.h"
 
 using std::endl;
 
 // Insets default methods
 
+// Initialization of the counter for the inset id's,
+unsigned int Inset::inset_id = 0;
+
 bool Inset::deletable() const
 {
        return true;
@@ -81,6 +86,16 @@ LyXText * Inset::getLyXText(BufferView const * bv, bool const) const
 }
 
 
+int Inset::id() const
+{
+       return id_;
+}
+
+void Inset::id(int id_arg)
+{
+       id_ = id_arg;
+}
+
 // some stuff for inset locking
 
 void UpdatableInset::insetButtonPress(BufferView *, int x, int y, int button)
@@ -238,3 +253,8 @@ int UpdatableInset::getMaxWidth(BufferView * bv, UpdatableInset const *) const
                        (owner())->getMaxWidth(bv, this);
        return bv->workWidth();
 }
+
+LyXCursor const & Inset::cursor(BufferView * bv) const
+{
+       return bv->text->cursor;
+}
index 9bc531b8c75fa7cabc166c6db3a723682251fdd2..3e6f7cdc23ff415aeaee53c06d4dee5217b9a2a1 100644 (file)
@@ -26,6 +26,8 @@ class Buffer;
 class Painter;
 class LyXText;
 class LyXLex;
+class Paragraph;
+class LyXCursor;
 
 struct LaTeXFeatures;
 
@@ -124,7 +126,7 @@ public:
        };
        
        ///
-       Inset() : top_x(0), top_baseline(0), scx(0), owner_(0) {}
+       Inset() : top_x(0), top_baseline(0), scx(0), id_(inset_id++), owner_(0) {}
        /// Virtual base destructor
        virtual ~Inset() {}
        ///
@@ -191,7 +193,7 @@ public:
        }
 
        ///
-       virtual Inset * clone(Buffer const &) const = 0;
+       virtual Inset * clone(Buffer const &, bool same_ids = false) const = 0;
        
        /// returns true to override begin and end inset in file
        virtual bool directWrite() const;
@@ -234,6 +236,27 @@ public:
                        return scx;
                return 0;
        }
+       /// try to get a paragraph pointer from it's id if we have a
+       /// paragraph to give back!
+       virtual Paragraph * getParFromID(int /* id */) const {
+               return 0;
+       }
+       /// try to get a inset pointer from it's id if we have
+       /// an inset to give back!
+       virtual Inset * getInsetFromID(int /* id */) const {
+               return 0;
+       }
+       /// if this insets owns paragraphs (f.ex. InsetText) then it
+       /// should return it's very first one!
+       virtual Paragraph * firstParagraph() const {
+               return 0;
+       }
+       /// return the cursor if we own one otherwise giv'em just the
+       /// BufferView cursor to work with.
+       virtual LyXCursor const & cursor(BufferView * bview) const;
+       /// id functions
+       int id() const;
+       void id(int id_arg);
 
 protected:
        ///
@@ -242,6 +265,11 @@ protected:
        mutable int top_baseline;
        ///
        mutable int scx;
+       ///
+       unsigned int id_;
+       ///
+       static unsigned int inset_id;
+
 private:
        ///
        Inset * owner_;
index 70849d11db3012c99c8ec7fedfac4d5995e16da8..c1b2226d2e840364b2e7698dbf06a1bfde4831c4 100644 (file)
@@ -46,7 +46,7 @@ InsetBibKey::~InsetBibKey()
 }
 
 
-Inset * InsetBibKey::clone(Buffer const &) const
+Inset * InsetBibKey::clone(Buffer const &, bool) const
 {
        InsetBibKey * b = new InsetBibKey(params());
        b->setCounter(counter);
@@ -113,7 +113,7 @@ void InsetBibKey::edit(BufferView * bv, int, int, unsigned int)
 }
 
 
-InsetBibtex::InsetBibtex(InsetCommandParams const & p)
+InsetBibtex::InsetBibtex(InsetCommandParams const & p, bool)
        : InsetCommand(p)
 {}
 
index e5d5c9d56201fbe8a4bd6421b1c8d8510d329c96..4dbd137305f53be11b21b1595db93056f94bd706 100644 (file)
@@ -33,11 +33,11 @@ public:
        ///
        ~InsetBibKey();
        ///
-       Inset * clone(Buffer const &) const;
+       Inset * clone(Buffer const &, bool same_id = false) const;
        /** Currently \bibitem is used as a LyX2.x command,
            so we need this method.
        */
-        void write(Buffer const *, std::ostream &) const;
+       void write(Buffer const *, std::ostream &) const;
        ///
        void read(Buffer const *, LyXLex & lex);
        ///
@@ -79,12 +79,12 @@ private:
 class InsetBibtex : public InsetCommand {
 public:
        ///
-       InsetBibtex(InsetCommandParams const &);
+       InsetBibtex(InsetCommandParams const &, bool same_id = false);
        ///
        ~InsetBibtex();
        ///
-       Inset * clone(Buffer const &) const {
-               return new InsetBibtex(params());
+       Inset * clone(Buffer const &, bool same_id = false) const {
+               return new InsetBibtex(params(), same_id);
        }
        ///
        string const getScreenLabel() const;
index 321141a4b6989da29c8be030cb9eb5ee8056d8e6..354cc562840efa7c5bb93412b45e1b34a47421e2 100644 (file)
@@ -19,7 +19,7 @@
 #include "frontends/Dialogs.h"
 #include "support/lstrings.h"
 
-InsetCitation::InsetCitation(InsetCommandParams const & p)
+InsetCitation::InsetCitation(InsetCommandParams const & p, bool)
        : InsetCommand(p)
 {}
 
index 9c5c8671b5eef7cfc434ad9d4dbeecf3441d3dfa..2ff0dfa7539217b2333a655a3232adf848073d25 100644 (file)
 class InsetCitation : public InsetCommand {
 public:
        ///
-       InsetCitation(InsetCommandParams const &);
+       InsetCitation(InsetCommandParams const &, bool same_id = false);
        ///
-       Inset * clone(Buffer const &) const {
-               return new InsetCitation(params());
+       Inset * clone(Buffer const &, bool same_id = false) const {
+               return new InsetCitation(params(), same_id);
        }
        ///
        string const getScreenLabel() const;
index 9bd46db48a40e72f212d8005dde203f70056d66e..8f58e1435ed622cfd89e8ebcb5ab94ac3579b886 100644 (file)
@@ -192,7 +192,7 @@ void InsetCollapsable::draw(BufferView * bv, LyXFont const & f,
                // we don't need anymore to clear here we just have to tell
                // the underlying LyXText that it should do the RowClear!
                inset.setUpdateStatus(bv, InsetText::FULL);
-               bv->text->status = LyXText::CHANGED_IN_DRAW;
+               bv->text->status(bv, LyXText::CHANGED_IN_DRAW);
                return;
 #else
                int w =  owner() ? width(bv, f) : pain.paperWidth();
@@ -497,3 +497,25 @@ int InsetCollapsable::scroll(bool recursive) const
 
        return sx;
 }
+
+Paragraph * InsetCollapsable::getParFromID(int id) const
+{
+       return inset.getParFromID(id);
+}
+
+Paragraph * InsetCollapsable::firstParagraph() const
+{
+       return inset.firstParagraph();
+}
+
+LyXCursor const & InsetCollapsable::cursor(BufferView * bv) const
+{
+       return inset.cursor(bv);
+}
+
+Inset * InsetCollapsable::getInsetFromID(int id_arg) const
+{
+       if (id_arg == id())
+               return const_cast<InsetCollapsable *>(this);
+       return inset.getInsetFromID(id_arg);
+}
index 1bf9e5a57a34fb48bf17d7819efdb1334f979746..a0e24f8aa43142f2db08def59f895a723bcd3388 100644 (file)
@@ -24,6 +24,8 @@
 
 class Painter;
 class LyXText;
+class Paragraph;
+class LyXCursor;
 
 /** A colapsable text inset
   
@@ -139,6 +141,14 @@ public:
        void scroll(BufferView *bv, int offset) const {
                UpdatableInset::scroll(bv, offset);
        }
+       ///
+       Paragraph * getParFromID(int id) const;
+       ///
+       Inset * getInsetFromID(int id) const;
+       ///
+       Paragraph * firstParagraph() const;
+       ///
+       LyXCursor const & cursor(BufferView *) const;
 
 protected:
        ///
index 3a05f4555660121b6d3b3264ad0ac18981947901..0c893240880ad0a74a6b4fa045e6fa3de774e214 100644 (file)
@@ -178,9 +178,10 @@ string const InsetCommandParams::getCommand() const
 }
 
 
-InsetCommand::InsetCommand( InsetCommandParams const & p )
+InsetCommand::InsetCommand(InsetCommandParams const & p, bool)
        : p_( p.getCmdName(), p.getContents(), p.getOptions() )
-{}
+{
+}
 
 
 void InsetCommand::setParams(InsetCommandParams const & p )
index 7095f9c7832370f63552f109a6dc1f41c6a2e37c..6dd6ad05da935d539d415fc2ba793b4fbbe1cbc5 100644 (file)
@@ -78,7 +78,7 @@ class InsetCommand : public InsetButton, boost::noncopyable {
 public:
        ///
        explicit
-       InsetCommand(InsetCommandParams const &);
+       InsetCommand(InsetCommandParams const &, bool same_id = false);
        ///
        virtual ~InsetCommand() { hideDialog(); }
        ///
index 43ceb178424de95ba7e96c6fa585ac167c87643f..adeec9280fbf87bd9d3669742f8251f47aeb52ba 100644 (file)
@@ -26,7 +26,7 @@ using std::ostream;
 
 /* Error, used for the LaTeX-Error Messages */
 
-InsetError::InsetError(string const & str)
+InsetError::InsetError(string const & str, bool)
        : contents(str)
 {}
 
index 95cd3ee1cb74f7369c3306e3392474625cbf9425..62f146a6871c9abbf8d80c765be431f78ad8b8fb 100644 (file)
@@ -29,7 +29,7 @@ class InsetError : public Inset {
 public:
        ///
        explicit
-       InsetError(string const &);
+       InsetError(string const &, bool same_id = false);
        ///
        ~InsetError() { hideDialog(); }
        ///
@@ -61,7 +61,9 @@ public:
        ///
        EDITABLE editable() const { return IS_EDITABLE; }
        ///
-       Inset * clone(Buffer const &) const { return new InsetError(contents); }
+       Inset * clone(Buffer const &, bool same_id = false) const {
+               return new InsetError(contents, same_id);
+       }
        ///
        Inset::Code lyxCode() const { return Inset::ERROR_CODE; }
        /// We don't want "begin" and "end inset" in lyx-file
index 5aefa67161080c18ad92b3a5d7ec7456e2088776..2cc6e304f2c1a9fe5f629cf93348aec97c06d396 100644 (file)
@@ -46,12 +46,14 @@ void InsetERT::write(Buffer const * buf, ostream & os) const
 }
 
 
-Inset * InsetERT::clone(Buffer const &) const
+Inset * InsetERT::clone(Buffer const &, bool same_id) const
 {
        InsetERT * result = new InsetERT;
-       result->inset.init(&inset);
+       result->inset.init(&inset, same_id);
        
        result->collapsed = collapsed;
+       if (same_id)
+               result->id_ = id_;
        return result;
 }
 
@@ -92,9 +94,9 @@ void InsetERT::edit(BufferView * bv, int x, int y, unsigned int button)
 int InsetERT::latex(Buffer const *, std::ostream & os, bool /*fragile*/,
                    bool /*free_spc*/) const
 {
-       Paragraph::size_type siz = inset.par->size();
+       Paragraph::size_type siz = inset.paragraph()->size();
        for (Paragraph::size_type i = 0; i != siz; ++i) {
-               os << inset.par->getChar(i);
+               os << inset.paragraph()->getChar(i);
        }
        return 1;
 }
index 4d6c550af8af3d4d5d66f62cee2853bccb7d856e..eddcd292c7a8ce58b0588570b552bd2688780bdd 100644 (file)
@@ -32,7 +32,7 @@ public:
        ///
        virtual void write(Buffer const * buf, std::ostream & os) const;
        ///
-       virtual Inset * clone(Buffer const &) const;
+       virtual Inset * clone(Buffer const &, bool same_id = false) const;
        ///
        virtual string const editMessage() const;
        ///
index 172f9b6418c6ca20899f9aabdeea504ab5006669..8eaa064280d004d94d4b9048869e3bafdaf9870d 100644 (file)
@@ -185,11 +185,13 @@ void InsetExternal::validate(LaTeXFeatures & features) const
 }
 
 
-Inset * InsetExternal::clone(Buffer const &) const
+Inset * InsetExternal::clone(Buffer const &, bool same_id) const
 {
        InsetExternal * inset = new InsetExternal();
        inset->params_ = params_;
        inset->view_ = view_;
+       if (same_id)
+               inset->id_ = id_;
        return inset;
 }
 
index dc68effa30c109b2806072fcc77aeaecd5aea54e..2bc0a2a152fbc4e10fea5049704f618b26aba77b 100644 (file)
@@ -74,7 +74,7 @@ public:
        virtual Inset::Code lyxCode() const { return EXTERNAL_CODE; }
  
        ///
-       virtual Inset * clone(Buffer const &) const;
+       virtual Inset * clone(Buffer const &, bool same_id = false) const;
 
        /// returns the text of the button
        virtual string const getScreenLabel() const;
index 3e822ce0bd38b902f4592c6b95d82b812913b1ec..5942f6b90d7d7cad32505d5ca3df331294b401eb 100644 (file)
@@ -171,12 +171,14 @@ void InsetFloat::validate(LaTeXFeatures & features) const
 }
 
 
-Inset * InsetFloat::clone(Buffer const &) const
+Inset * InsetFloat::clone(Buffer const &, bool same_id) const
 {
        InsetFloat * result = new InsetFloat(floatType_);
-       result->inset.init(&inset);
+       result->inset.init(&inset, same_id);
 
        result->collapsed = collapsed;
+       if (same_id)
+               result->id_ = id_;
        return result;
 }
 
index ee0396d6fbe3244d8ef3689c623ba51d69129cba..4668c68f143323f8fe133d885a9e0220aeb9cd84 100644 (file)
@@ -34,7 +34,7 @@ public:
        ///
        void validate(LaTeXFeatures & features) const;
        ///
-       Inset * clone(Buffer const &) const;
+       Inset * clone(Buffer const &, bool same_id = false) const;
        ///
        Inset::Code lyxCode() const { return Inset::FLOAT_CODE; }
        ///
index 19e7d4b7aacea959c97342320c23fff57eec16ba..132a1b8494e83e43096e06076fffb6bd94a7d1a1 100644 (file)
@@ -28,7 +28,7 @@ public:
        InsetFloatList(string const & type) 
                : float_type(type) {}
        ///
-        Inset * clone(Buffer const &) const {
+       Inset * clone(Buffer const &, bool same_id = false) const {
                return new InsetFloatList(*this);
        }
        ///
index b3b39f9171b29c2f640daab406656f5e3db5aefa..926176e66b55d996480bade533489b9fcb1d431d 100644 (file)
@@ -32,12 +32,14 @@ InsetFoot::InsetFoot()
 }
 
 
-Inset * InsetFoot::clone(Buffer const &) const
+Inset * InsetFoot::clone(Buffer const &, bool same_id) const
 {
        InsetFoot * result = new InsetFoot;
-       result->inset.init(&inset);
+       result->inset.init(&inset, same_id);
 
        result->collapsed = collapsed;
+       if (same_id)
+               result->id_ = id_;
        return result;
 }
 
index 5892ec07e20d252e28dbc008dcffa993862b7c82..2495ebb67f50a20a2b9bc57bc85d24e636fc26b7 100644 (file)
@@ -28,7 +28,7 @@ public:
        ///
        InsetFoot();
        ///
-       Inset * clone(Buffer const &) const;
+       Inset * clone(Buffer const &, bool same_id = false) const;
        ///
        Inset::Code lyxCode() const { return Inset::FOOT_CODE; }
        ///
index 4f5c82d0494e230d4cab00b3c35e3e18a2d2e43d..ef7b1fac4c9af93d111391ef06eb750d92c05709 100644 (file)
@@ -272,7 +272,7 @@ void InsetGraphics::draw(BufferView * bv, LyXFont const & font,
                        imageLoaded = true;
 
                        // Tell BufferView we need to be updated!
-                       bv->text->status = LyXText::CHANGED_IN_DRAW;
+                       bv->text->status(bv, LyXText::CHANGED_IN_DRAW);
                        return;
                }
 
@@ -621,10 +621,11 @@ InsetGraphicsParams InsetGraphics::getParams() const
 }
 
 
-Inset * InsetGraphics::clone(Buffer const &) const
+Inset * InsetGraphics::clone(Buffer const &, bool) const
 {
 #ifdef WITH_WARNINGS
 #warning use the copy constructor instead. (Lgb)
+#warning and then please honor the same_id flag (Jug)
 #endif
        InsetGraphics * newInset = new InsetGraphics;
 
index 042b8941a96fee745616751ab3af0d92f34c99bc..aa9dc9d6cf19fd46101fbe3ea3a0f11e6e8b765a 100644 (file)
@@ -78,7 +78,7 @@ public:
        Inset::Code lyxCode() const { return Inset::GRAPHICS_CODE; }
 
        ///
-       virtual Inset * clone(Buffer const &) const;
+       virtual Inset * clone(Buffer const &, bool same_id = false) const;
 
        /** Set the inset parameters, used by the GUIndependent dialog.
            Return true of new params are different from what was so far.
index 01cd2530ba5aa1e5f70c75cb9f6625b943384720..3e66d587a2961046a9b3b4419a65c14ae25d33a7 100644 (file)
@@ -112,7 +112,7 @@ void InsetInclude::set(Params const & p)
 }
 
 
-Inset * InsetInclude::clone(Buffer const & buffer) const
+Inset * InsetInclude::clone(Buffer const & buffer, bool) const
 {
        Params p(params_);
        p.masterFilename_ = buffer.fileName();
index 2a21c2976e8d6c3220c8a8e46a5808ca85d1d0ca..45257ad1eb76d81c615b8091b4b66a9217576b4f 100644 (file)
@@ -69,7 +69,7 @@ public:
        void set(Params const & params);
 
        ///
-        virtual Inset * clone(Buffer const &) const;
+       virtual Inset * clone(Buffer const &, bool same_id = false) const;
        ///
        Inset::Code lyxCode() const { return Inset::INCLUDE_CODE; }
        /// This returns the list of labels on the child buffer
index 18d79e5551f9f260780321e2536dd7ecd3464260..a15c1e23e9d9e90576968b50707a93eb03960d11 100644 (file)
@@ -11,7 +11,7 @@
 #include "LaTeXFeatures.h"
 #include "gettext.h"
 
-InsetIndex::InsetIndex(InsetCommandParams const & p)
+InsetIndex::InsetIndex(InsetCommandParams const & p, bool)
        : InsetCommand(p)
 {}
 
@@ -28,7 +28,7 @@ void InsetIndex::edit(BufferView * bv, int, int, unsigned int)
 }
 
 
-InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p)
+InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p, bool)
        : InsetCommand(p)
 {}
 
index 598ae99f3ceaa2a3d94e8b2af448e16c6d71617a..211043d9452086a0ee79c7adfe038dd3e54f8fa2 100644 (file)
@@ -25,10 +25,10 @@ struct LaTeXFeatures;
 class InsetIndex : public InsetCommand {
 public:
        ///
-       InsetIndex(InsetCommandParams const &);
+       InsetIndex(InsetCommandParams const &, bool same_id = false);
        ///
-       virtual Inset * clone(Buffer const &) const {
-               return new InsetIndex(params());
+       virtual Inset * clone(Buffer const &, bool same_id = false) const {
+               return new InsetIndex(params(), same_id);
        }
        ///
        string const getScreenLabel() const;
@@ -42,10 +42,10 @@ public:
 class InsetPrintIndex : public InsetCommand {
 public:
        ///
-       InsetPrintIndex(InsetCommandParams const &);
+       InsetPrintIndex(InsetCommandParams const &, bool same_id = false);
        ///
-       virtual Inset * clone(Buffer const &) const {
-               return new InsetPrintIndex(params());
+       virtual Inset * clone(Buffer const &, bool same_id = false) const {
+               return new InsetPrintIndex(params(), same_id);
        }
        /// Updates needed features for this inset.
        void validate(LaTeXFeatures & features) const;
index 0aabb9b22e17cdd9d8dfd3feb0f3d294ca3e9abf..3afe9297c7646bfebd28421a8ae6141b66fefe73 100644 (file)
@@ -243,7 +243,7 @@ void InsetInfo::edit(BufferView *bv, int, int, unsigned int)
 }
 
 
-Inset * InsetInfo::clone(Buffer const &) const
+Inset * InsetInfo::clone(Buffer const &, bool) const
 {
        return new InsetInfo(contents);
 }
index cbc7a013620acf68a3a8ac821f275380ffcec18c..3128ef4c0613fc7db749227d0233392665c78385 100644 (file)
@@ -68,7 +68,7 @@ public:
        ///
        Inset::Code lyxCode() const;
        ///
-       virtual Inset * clone(Buffer const &) const;
+       virtual Inset * clone(Buffer const &, bool same_id = false) const;
        ///
        static void closeInfoCB(FL_OBJECT *, long data);
 private:
index cb1cc921fb5c1fe0932a3791626aad580217a430..026721a0d772b8865ef0d9ab143b9bee17737e44 100644 (file)
@@ -31,7 +31,7 @@ using std::pair;
 /* Label. Used to insert a label automatically */
 
 
-InsetLabel::InsetLabel(InsetCommandParams const & p)
+InsetLabel::InsetLabel(InsetCommandParams const & p, bool)
        : InsetCommand(p)
 {}
 
index acdce9647052c9769c5d0b6b88c1693897abeb17..b4080df3a6bf1e25b3f4b10ffb1a73c46e2a2946 100644 (file)
 class InsetLabel : public InsetCommand {
 public:
        ///
-       InsetLabel(InsetCommandParams const &);
+       InsetLabel(InsetCommandParams const &, bool same_id = false);
        ///
-       virtual Inset * clone(Buffer const &) const {
-               return new InsetLabel(params());
+       virtual Inset * clone(Buffer const &, bool same_id = false) const {
+               return new InsetLabel(params(), same_id);
        }
        ///
        string const getScreenLabel() const { return getContents(); }
index 555cdd8925058174b528f8049490a79b42cb25a4..ccd8401ebf742bf3a83ec07e1fae42676881fe40 100644 (file)
@@ -667,7 +667,7 @@ bool InsetLatexAccent::directWrite() const
 }
 
 
-Inset * InsetLatexAccent::clone(Buffer const &) const
+Inset * InsetLatexAccent::clone(Buffer const &, bool) const
 {
        return new InsetLatexAccent(contents);
 }
index 52fbc8fe75dd7e060d807e4627c31468dc974226..6c184514c53118be05c5b4edf23245953d7dd662 100644 (file)
@@ -67,7 +67,7 @@ public:
        ///
        bool directWrite() const;
        ///
-       virtual Inset * clone(Buffer const &) const;
+       virtual Inset * clone(Buffer const &, bool same_id = false) const;
        ///
        Inset::Code lyxCode()const;
        ///
index 23f9f15318b29f1121d59a85cbd76aaf8031a985..d577c185ed70879992fa831c188634020558f169 100644 (file)
@@ -57,12 +57,14 @@ void InsetList::write(Buffer const * buf, ostream & os) const
 }
 
 
-Inset * InsetList::clone(Buffer const &) const
+Inset * InsetList::clone(Buffer const &, bool same_id) const
 {
        InsetList * result = new InsetList;
-       result->inset.init(&inset);
+       result->inset.init(&inset, same_id);
        
        result->collapsed = collapsed;
+       if (same_id)
+               result->id_ = id_;
        return result;
 }
 
index 6a67e20ee3381d5780da1969c130837f59df1d97..a5ea1f727d07cb88ae41f4da9aec4d48004336a2 100644 (file)
@@ -28,7 +28,7 @@ public:
        ///
        void write(Buffer const * buf, std::ostream & os) const;
        ///
-       virtual Inset * clone(Buffer const &) const;
+       virtual Inset * clone(Buffer const &, bool same_id = false) const;
        ///
        Inset::Code lyxCode() const { return Inset::FOOT_CODE; }
        ///
index a92dd470188a146ae467e04e9ca644f2cf279c8b..b4aa735602644e5ab46ad291ac3763b7574276b7 100644 (file)
@@ -32,12 +32,14 @@ InsetMarginal::InsetMarginal()
 }
 
 
-Inset * InsetMarginal::clone(Buffer const &) const
+Inset * InsetMarginal::clone(Buffer const &, bool same_id) const
 {
        InsetMarginal * result = new InsetMarginal;
-       result->inset.init(&inset);
+       result->inset.init(&inset, same_id);
        
        result->collapsed = collapsed;
+       if (same_id)
+               result->id_ = id_;
        return result;
 }
 
index 7f1e5b86c6d4c592b457b055eab47f41b31b448e..26654106a674938493d1cea8e456e8bbe6b6acb5 100644 (file)
@@ -26,7 +26,7 @@ public:
        ///
        InsetMarginal();
        ///
-       Inset * clone(Buffer const &) const;
+       Inset * clone(Buffer const &, bool same_id = false) const;
        ///
        Inset::Code lyxCode() const { return Inset::MARGIN_CODE; }
        ///
index 10ac8dcb28a071e2bcf5a938ae92b9ce9c55ddc4..372c7bcef3b7824f869049e523498a3a9959e2d3 100644 (file)
@@ -174,16 +174,18 @@ void InsetMinipage::read(Buffer const * buf, LyXLex & lex)
 }
 
 
-Inset * InsetMinipage::clone(Buffer const &) const
+Inset * InsetMinipage::clone(Buffer const &, bool same_id) const
 {
        InsetMinipage * result = new InsetMinipage;
-       result->inset.init(&inset);
+       result->inset.init(&inset, same_id);
        
        result->collapsed = collapsed;
        result->pos_ = pos_;
        result->inner_pos_ = inner_pos_;
        result->height_ = height_;
        result->width_ = width_;
+       if (same_id)
+               result->id_ = id_;
        return result;
 }
 
index 11139b4d0006cf8280ab90eae163e808df30c212..fb6a72220d069556b786a483e8059ffa4cfc6559 100644 (file)
@@ -47,7 +47,7 @@ public:
        ///
        void read(Buffer const * buf, LyXLex & lex);
        ///
-       virtual Inset * clone(Buffer const &) const;
+       virtual Inset * clone(Buffer const &, bool same_id = false) const;
        ///
        int ascent(BufferView *, LyXFont const &) const;
        ///
index feec44cd7f8484bb2797f24a400c884ccfbb780b..d63c783a5e2c5c72b340bdd1a94c080268a7c51a 100644 (file)
@@ -29,7 +29,7 @@
 using std::ostream;
 
 
-InsetParent::InsetParent(InsetCommandParams const & p, Buffer const & bf)
+InsetParent::InsetParent(InsetCommandParams const & p, Buffer const & bf, bool)
        : InsetCommand(p)
 {
        string const fn = p.getContents();
index 3f348a51de660b6dca6ec59a754486b965af98ba..5ae366e530e036422f148ca9a4707c88519e72d5 100644 (file)
@@ -27,10 +27,10 @@ class Buffer;
 class InsetParent : public InsetCommand {
 public:
        ///
-       InsetParent(InsetCommandParams const &, Buffer const &);
+       InsetParent(InsetCommandParams const &, Buffer const &, bool same_id = false);
        ///
-       virtual Inset * clone(Buffer const & buffer) const {
-               return new InsetParent(params(), buffer);
+       virtual Inset * clone(Buffer const & buffer, bool same_id = false) const {
+               return new InsetParent(params(), buffer, same_id);
        }
        ///
        string const getScreenLabel() const;
index 249df27754a4bec1f38f1d40cc2da7122a4f9e00..2f917efe2012edc62d703ef1c0ba6e4c7496639f 100644 (file)
@@ -326,7 +326,7 @@ void InsetQuotes::validate(LaTeXFeatures & features) const
 }
 
 
-Inset * InsetQuotes::clone(Buffer const &) const
+Inset * InsetQuotes::clone(Buffer const &, bool) const
 {
   return new InsetQuotes(language, side, times);
 }
index 7011656e1426c51ebb46bbe21a4313d70d059e06..b4b953d59c52d25f163d63fb4004d19b6dd8244c 100644 (file)
@@ -97,7 +97,7 @@ public:
        ///
        void validate(LaTeXFeatures &) const;
        ///
-       virtual Inset * clone(Buffer const &) const;
+       virtual Inset * clone(Buffer const &, bool same_id = false) const;
        ///
        Inset::Code lyxCode() const;
 private:
index 0a0e40f0e807c7e268fa82da1a1a227e31c80fde..1e9cf3ceee90321112366168bf23a88dfaf1bbcb 100644 (file)
@@ -18,7 +18,7 @@
 
 using std::ostream;
 
-InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf)
+InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf, bool)
        : InsetCommand(p), isLatex(buf.isLatex())
 {}
 
index 56a20ff3e82f44fb3dcdf85a5cf0ac8cf316dedc..2a60b2a65510a41284d2f7c838d228bbf16462cd 100644 (file)
@@ -38,10 +38,10 @@ public:
        static string const & getName(int type);
 
        ///
-       InsetRef(InsetCommandParams const &, Buffer const &);
+       InsetRef(InsetCommandParams const &, Buffer const &, bool same_id = false);
        ///
-       virtual Inset * clone(Buffer const & buffer) const {
-               return new InsetRef(params(), buffer);
+       virtual Inset * clone(Buffer const & buffer, bool same_id = false) const {
+               return new InsetRef(params(), buffer, same_id);
        }
        ///
        string const getScreenLabel() const;
index a94e33e42503264fdefcf870e1b3ae611b7f07cd..5c17d9e95ae1f31e1f4623024dec6ffb733a4a54 100644 (file)
@@ -222,7 +222,7 @@ int InsetSpecialChar::docBook(Buffer const * buf, ostream & os) const
 }
 
 
-Inset * InsetSpecialChar::clone(Buffer const &) const
+Inset * InsetSpecialChar::clone(Buffer const &, bool) const
 {
        return new InsetSpecialChar(kind);
 }
index 05fb3ecf38841b03d6b04e7e998bdccfcfa2614b..3e08623c70d92833bed8f6d05f159159f546fed0 100644 (file)
@@ -65,7 +65,7 @@ public:
        ///
        int docBook(Buffer const *, std::ostream &) const;
        ///
-       virtual Inset * clone(Buffer const &) const;
+       virtual Inset * clone(Buffer const &, bool same_id = false) const;
        ///  
        Inset::Code lyxCode() const
        {
index d79dfc531e2f3be1ab7bcc8415ad963b75392ee5..95699d7a9333cb39e8c4572f53f6e6b8ac6bb62b 100644 (file)
@@ -39,6 +39,7 @@
 #include "gettext.h"
 #include "language.h"
 #include "BufferView.h"
+#include "undo_funcs.h"
 
 using std::ostream;
 using std::ifstream;
@@ -126,7 +127,7 @@ InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
                rows = 1;
        if (columns <= 0)
                columns = 1;
-       tabular.reset(new LyXTabular(this, rows,columns));
+       tabular.reset(new LyXTabular(this, rows, columns));
        // for now make it always display as display() inset
        // just for test!!!
        the_locking_inset = 0;
@@ -138,7 +139,8 @@ InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
 }
 
 
-InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf)
+InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
+                                                  bool same_id)
        : buffer(&buf)
 {
        tabular.reset(new LyXTabular(this, *(tab.tabular)));
@@ -148,6 +150,8 @@ InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf)
        actrow = actcell = 0;
        sel_cell_start = sel_cell_end = 0;
        need_update = INIT;
+       if (same_id)
+               id_ = tab.id_;
 }
 
 
@@ -157,9 +161,9 @@ InsetTabular::~InsetTabular()
 }
 
 
-Inset * InsetTabular::clone(Buffer const & buf) const
+Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
 {
-       return new InsetTabular(*this, buf);
+       return new InsetTabular(*this, buf, same_id);
 }
 
 
@@ -304,7 +308,6 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
                if (the_locking_inset &&
                        tabular->GetCellInset(actcell) != the_locking_inset)
                {
-#warning Jürgen, why is this?
                        Inset * inset = tabular->GetCellInset(cell);
                        for (i = 0;
                             inset != the_locking_inset && i < tabular->rows();
@@ -327,7 +330,7 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
                                }
                        }
                } else {
-                       // copute baseline for actual row
+                       // compute baseline for actual row
                        for (i = 0; i < actrow; ++i) {
                                baseline += tabular->GetDescentOfRow(i) +
                                        tabular->GetAscentOfRow(i + 1) +
@@ -378,7 +381,7 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
        }
        x -= ADD_TO_TABULAR_WIDTH;
        x += width(bv, font);
-       if (bv->text->status == LyXText::CHANGED_IN_DRAW) {
+       if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
                int i = 0;
                for(Inset * inset=owner(); inset; ++i)
                        inset = inset->owner();
@@ -461,6 +464,11 @@ void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
        }
        if (the_locking_inset)
                the_locking_inset->update(bv, font, reinit);
+       if (need_update < FULL &&
+               bv->text->status() == LyXText::NEED_MORE_REFRESH)
+       {
+               need_update = FULL;
+       }
 
        switch (need_update) {
        case INIT:
@@ -498,7 +506,7 @@ void InsetTabular::edit(BufferView * bv, int x, int y, unsigned int button)
        inset_y = 0;
        setPos(bv, x, y);
        sel_cell_start = sel_cell_end = actcell;
-       bv->text->finishUndo();
+       finishUndo();
        if (insetHit(bv, x, y) && (button != 3)) {
                activateCellInsetAbs(bv, x, y, button);
        }
@@ -554,14 +562,14 @@ bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
                lyxerr[Debug::INSETS] << "OK" << endl;
                the_locking_inset = tabular->GetCellInset(actcell);
                resetPos(bv);
-               inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
-               inset_y = cursor.y();
+               inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
+               inset_y = cursor_.y();
                return true;
        } else if (the_locking_inset && (the_locking_inset == inset)) {
                lyxerr[Debug::INSETS] << "OK" << endl;
                resetPos(bv);
-               inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
-               inset_y = cursor.y();
+               inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
+               inset_y = cursor_.y();
        } else if (the_locking_inset) {
                lyxerr[Debug::INSETS] << "MAYBE" << endl;
                return the_locking_inset->lockInsetInInset(bv, inset);
@@ -958,16 +966,16 @@ InsetTabular::localDispatch(BufferView * bv,
        case LFUN_CUT:
                if (!copySelection(bv))
                        break;
-               bv->text->setUndo(bv->buffer(), Undo::DELETE,
-                                 bv->text->cursor.par()->previous(),
-                                 bv->text->cursor.par()->next());
+               setUndo(bv, Undo::DELETE,
+                       bv->text->cursor.par(),
+                       bv->text->cursor.par()->next());
                cutSelection();
                updateLocal(bv, INIT, true);
                break;
        case LFUN_COPY:
                if (!hasSelection())
                        break;
-               bv->text->finishUndo();
+               finishUndo();
                copySelection(bv);
                break;
        case LFUN_PASTESELECTION:
@@ -1038,9 +1046,9 @@ InsetTabular::localDispatch(BufferView * bv,
        }
        case LFUN_PASTE:
                if (hasPasteBuffer()) {
-                       bv->text->setUndo(bv->buffer(), Undo::INSERT,
-                                         bv->text->cursor.par()->previous(),
-                                         bv->text->cursor.par()->next());
+                       setUndo(bv, Undo::INSERT,
+                               bv->text->cursor.par(),
+                               bv->text->cursor.par()->next());
                        pasteSelection(bv);
                        updateLocal(bv, INIT, true);
                        break;
@@ -1167,8 +1175,8 @@ bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
 void InsetTabular::getCursorPos(BufferView *,
                                int & x, int & y) const
 {
-       x = cursor.x() - top_x;
-       y = cursor.y();
+       x = cursor_.x() - top_x;
+       y = cursor_.y();
 }
 
 
@@ -1187,7 +1195,7 @@ void InsetTabular::toggleInsetCursor(BufferView * bv)
        if (isCursorVisible())
                bv->hideLockedInsetCursor();
        else
-               bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
+               bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
        toggleCursorVisible();
 }
 
@@ -1199,9 +1207,9 @@ void InsetTabular::showInsetCursor(BufferView * bv, bool show)
        
                int const asc = lyxfont::maxAscent(font);
                int const desc = lyxfont::maxDescent(font);
-               bv->fitLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
+               bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
                if (show)
-                       bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
+                       bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
                setCursorVisible(true);
        }
 }
@@ -1220,18 +1228,18 @@ void InsetTabular::hideInsetCursor(BufferView * bv)
 
 void InsetTabular::setPos(BufferView * bv, int x, int y) const
 {
-       cursor.y(0);
+       cursor_.y(0);
        
        actcell = actrow = actcol = 0;
        int ly = tabular->GetDescentOfRow(actrow);
 
        // first search the right row
        while((ly < y) && (actrow < tabular->rows())) {
-               cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
+               cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
                                 tabular->GetAscentOfRow(actrow + 1) +
                                 tabular->GetAdditionalHeight(actrow + 1));
                ++actrow;
-               ly = cursor.y() + tabular->GetDescentOfRow(actrow);
+               ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
        }
        actcell = tabular->GetCellNumber(actrow, actcol);
 
@@ -1253,7 +1261,7 @@ void InsetTabular::setPos(BufferView * bv, int x, int y) const
        }
        
 #endif
-       cursor.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
+       cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
        resetPos(bv);
 }
 
@@ -1280,10 +1288,10 @@ void InsetTabular::resetPos(BufferView * bv) const
 
        int cell = 0;
        actrow = 0;
-       cursor.y(0);
+       cursor_.y(0);
        for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
                if (tabular->IsLastCellInRow(cell)) {
-                       cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
+                       cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
                                         tabular->GetAscentOfRow(actrow + 1) +
                                         tabular->GetAdditionalHeight(actrow + 1));
                        ++actrow;
@@ -1291,9 +1299,9 @@ void InsetTabular::resetPos(BufferView * bv) const
        }
        static int const offset = ADD_TO_TABULAR_WIDTH + 2;
        int new_x = getCellXPos(actcell);
-       int old_x = cursor.x();
+       int old_x = cursor_.x();
        new_x += offset;
-       cursor.x(new_x);
+       cursor_.x(new_x);
 //    cursor.x(getCellXPos(actcell) + offset);
        if ((actcol < tabular->columns()-1) && scroll(false) &&
                (tabular->GetWidthOfTabular() < bv->workWidth()-20))
@@ -1303,7 +1311,7 @@ void InsetTabular::resetPos(BufferView * bv) const
        } else if (the_locking_inset &&
                 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
        {
-               int xx = cursor.x() - offset + bv->text->getRealCursorX(bv);
+               int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
                if (xx > (bv->workWidth()-20)) {
                        scroll(bv, -(xx - bv->workWidth() + 60));
                        updateLocal(bv, FULL, false);
@@ -1315,17 +1323,17 @@ void InsetTabular::resetPos(BufferView * bv) const
                        scroll(bv, xx);
                        updateLocal(bv, FULL, false);
                }
-       } else if ((cursor.x() - offset) > 20 &&
-                  (cursor.x() - offset + tabular->GetWidthOfColumn(actcell))
+       } else if ((cursor_.x() - offset) > 20 &&
+                  (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
                   > (bv->workWidth() - 20)) {
                scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
                updateLocal(bv, FULL, false);
-       } else if ((cursor.x() - offset) < 20) {
-               scroll(bv, 20 - cursor.x() + offset);
+       } else if ((cursor_.x() - offset) < 20) {
+               scroll(bv, 20 - cursor_.x() + offset);
                updateLocal(bv, FULL, false);
        } else if (scroll(false) && top_x > 20 &&
                   (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
-               scroll(bv, old_x - cursor.x());
+               scroll(bv, old_x - cursor_.x());
                updateLocal(bv, FULL, false);
        }
        if ((!the_locking_inset ||
@@ -1382,7 +1390,7 @@ UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
                int y = 0;
                if (old_locking_inset) {
                        old_locking_inset->getCursorPos(bv, x, y);
-                       x -= cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
+                       x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
                }
                if (activateCellInset(bv, x, 0))
                        return DISPATCHED;
@@ -1403,7 +1411,7 @@ UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
                int y = 0;
                if (old_locking_inset) {
                        old_locking_inset->getCursorPos(bv, x, y);
-                       x -= cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
+                       x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
                }
                if (activateCellInset(bv, x, 0))
                        return DISPATCHED;
@@ -1432,7 +1440,7 @@ bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
                ++actcell;
        }
        if (lock) {
-               bool rtl = tabular->GetCellInset(actcell)->par->
+               bool rtl = tabular->GetCellInset(actcell)->paragraph()->
                        isRightToLeftPar(bv->buffer()->params);
                activateCellInset(bv, 0, 0, 0, !rtl);
        }
@@ -1461,7 +1469,7 @@ bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
                --actcell;
        }
        if (lock) {
-               bool rtl = tabular->GetCellInset(actcell)->par->
+               bool rtl = tabular->GetCellInset(actcell)->paragraph()->
                        isRightToLeftPar(bv->buffer()->params);
                activateCellInset(bv, 0, 0, 0, !rtl);
        }
@@ -1472,7 +1480,8 @@ bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
 
 bool InsetTabular::Delete()
 {
-#warning Is this func correctly named? Or should it be "deletable"?
+#warning Is this func correctly named? Or should it be "deletable"? (Lgb?)
+#warning I guess this could be 'deletable'! (Jug)
        return true;
 }
 
@@ -1486,12 +1495,12 @@ void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
        }
        if (hasSelection()) {
                bool frozen;
-               bv->text->setUndo(bv->buffer(), Undo::EDIT,
-                                 bv->text->cursor.par()->previous(),
-                                 bv->text->cursor.par()->next());
-               frozen = bv->text->undo_frozen;
+               setUndo(bv, Undo::EDIT,
+                       bv->text->cursor.par(),
+                       bv->text->cursor.par()->next());
+               frozen = undo_frozen;
                if (!frozen)
-                       bv->text->freezeUndo();
+                       freezeUndo();
                // apply the fontchange on the whole selection
                int sel_row_start;
                int sel_row_end;
@@ -1504,7 +1513,7 @@ void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
                        }
                }
                if (!frozen)
-                       bv->text->unFreezeUndo();
+                       unFreezeUndo();
                updateLocal(bv, INIT, true);
        }
        if (the_locking_inset)
@@ -1583,9 +1592,9 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
                sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
        }
-       bv->text->setUndo(bv->buffer(), Undo::FINISH,
-                         bv->text->cursor.par()->previous(),
-                         bv->text->cursor.par()->next());
+       setUndo(bv, Undo::FINISH,
+               bv->text->cursor.par(),
+               bv->text->cursor.par()->next());
 
        int row = tabular->row_of_cell(actcell);
        int column = tabular->column_of_cell(actcell);
@@ -1874,9 +1883,9 @@ bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
                                        int button)
 {
-       inset_x = cursor.x()
+       inset_x = cursor_.x()
                - top_x + tabular->GetBeginningOfTextInCell(actcell);
-       inset_y = cursor.y();
+       inset_y = cursor_.y();
        return activateCellInset(bv, x - inset_x, y - inset_y, button);
 }
 
@@ -1884,7 +1893,7 @@ bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
 bool InsetTabular::insetHit(BufferView *, int x, int) const
 {
        return (x + top_x)
-               > (cursor.x() + tabular->GetBeginningOfTextInCell(actcell));
+               > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
 }
 
 
@@ -1901,30 +1910,30 @@ int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
 
 
 int InsetTabular::getMaxWidth(BufferView * bv,
-                             UpdatableInset const * inset) const
+                              UpdatableInset const * inset) const
 {
        int cell = tabular->cur_cell;
        if (tabular->GetCellInset(cell) != inset) {
-                       cell = actcell;
-                       if (tabular->GetCellInset(cell) != inset) {
-                                       lyxerr << "Actcell not equal to actual cell!" << std::endl;
-                                       //raise(SIGSTOP);
-                                       cell = -1;
-                       }
+               cell = actcell;
+               if (tabular->GetCellInset(cell) != inset) {
+                       
+                       lyxerr << "Actcell not equal to actual cell!\n";
+                       cell = -1;
+               }
        }
        
        int const n = tabular->GetNumberOfCells();
 
        if (cell == -1) {
-               cell = 0;
-               for (; cell < n; ++cell) {
+               for (cell = 0; cell < n; ++cell) {
                        if (tabular->GetCellInset(cell) == inset)
                                break;
                }
        }
        
        if (cell >= n) {
-                       return -1;
+               lyxerr << "Own inset not found, shouldn't really happen!\n";
+               return -1;
        }
        
        int w = getMaxWidthOfCell(bv, cell);
@@ -2381,9 +2390,44 @@ void InsetTabular::getSelection(int & srow, int & erow, int & scol, int & ecol)
                        ecol = tabular->right_column_of_cell(sel_cell_end);
 }
 
-/* Emacs:
- * Local variables:
- * tab-width: 4
- * End:
- * vi:set tabstop=4:
- */
+Paragraph * InsetTabular::getParFromID(int id) const
+{
+       Paragraph * result;
+       for(int i=0; i < tabular->rows(); ++i) {
+               for(int j=0; j < tabular->columns(); ++j) {
+                       if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
+                               return result;
+               }
+       }
+       return 0;
+}
+
+Paragraph * InsetTabular::firstParagraph() const
+{
+       if (the_locking_inset)
+               return the_locking_inset->firstParagraph();
+       return 0;
+}
+
+LyXCursor const & InsetTabular::cursor(BufferView * bv) const
+{
+       if (the_locking_inset)
+               return the_locking_inset->cursor(bv);
+       return Inset::cursor(bv);
+}
+
+
+Inset * InsetTabular::getInsetFromID(int id_arg) const
+{
+       if (id_arg == id())
+               return const_cast<InsetTabular *>(this);
+
+       Inset * result;
+       for(int i=0; i < tabular->rows(); ++i) {
+               for(int j=0; j < tabular->columns(); ++j) {
+                       if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
+                               return result;
+               }
+       }
+       return 0;
+}
index 1cbc9f8c6d693811f252e9227d00052975e45cc8..b3c3c9f45e86bccec1ac962e4f421aa19e4d89df 100644 (file)
@@ -62,6 +62,7 @@ class LyXLex;
 class Painter;
 class BufferView;
 class Buffer;
+class Paragraph;
 
 class InsetTabular : public UpdatableInset {
 public:
@@ -77,11 +78,11 @@ public:
        ///
        InsetTabular(Buffer const &, int rows = 1, int columns = 1);
        ///
-       InsetTabular(InsetTabular const &, Buffer const &);
+       InsetTabular(InsetTabular const &, Buffer const &, bool same_id = false);
        ///
        ~InsetTabular();
        ///
-       Inset * clone(Buffer const &) const;
+       Inset * clone(Buffer const &, bool same_id = false) const;
        ///
        void read(Buffer const *, LyXLex &);
        ///
@@ -196,6 +197,14 @@ public:
        void scroll(BufferView *bv, int offset) const {
                UpdatableInset::scroll(bv, offset);
        }
+       ///
+       Paragraph * getParFromID(int id) const;
+       ///
+       Inset * getInsetFromID(int id) const;
+       ///
+       Paragraph * firstParagraph() const;
+       ///
+       LyXCursor const & cursor(BufferView *) const;
 
        //
        // Public structures and variables
@@ -281,7 +290,7 @@ private:
        ///
        Buffer const * buffer;
        ///
-       mutable LyXCursor cursor;
+       mutable LyXCursor cursor_;
        ///
        mutable unsigned int inset_x;
        ///
index 637ae9a0412424767f299cdb08cdb4998a0c67ae..58af552d6466e49a9053320ea8e2b4c4c89f02bd 100644 (file)
@@ -48,6 +48,7 @@
 #include "gettext.h"
 #include "lyxfunc.h"
 #include "ParagraphParameters.h"
+#include "undo_funcs.h"
 
 using std::ostream;
 using std::ifstream;
@@ -67,11 +68,11 @@ InsetText::InsetText()
 }
 
 
-InsetText::InsetText(InsetText const & ins)
+InsetText::InsetText(InsetText const & ins, bool same_id)
        : UpdatableInset()
 {
        par = 0;
-       init(&ins);
+       init(&ins, same_id);
        autoBreakRows = ins.autoBreakRows;
 }
 
@@ -84,7 +85,7 @@ InsetText & InsetText::operator=(InsetText const & it)
 }
 
 
-void InsetText::init(InsetText const * ins)
+void InsetText::init(InsetText const * ins, bool same_id)
 {
        top_y = 0;
        last_width = 0;
@@ -105,6 +106,8 @@ void InsetText::init(InsetText const * ins)
                setParagraphData(ins->par);
                autoBreakRows = ins->autoBreakRows;
                drawFrame_ = ins->drawFrame_;
+               if (same_id)
+                       id_ = ins->id_;
        }
        par->setInsetOwner(this);
        frame_color = LColor::insetframe;
@@ -146,9 +149,9 @@ void InsetText::clear()
 }
 
 
-Inset * InsetText::clone(Buffer const &) const
+Inset * InsetText::clone(Buffer const &, bool same_id) const
 {
-       InsetText * t = new InsetText(*this);
+       InsetText * t = new InsetText(*this, same_id);
        return t;
 }
 
@@ -295,7 +298,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
                        resizeLyXText(bv);
                        need_update |= FULL;
                        old_max_width = getLyXText(bv)->width;
-                       bv->text->status = LyXText::CHANGED_IN_DRAW;
+                       bv->text->status(bv, LyXText::CHANGED_IN_DRAW);
                }
                top_x = int(x);
 #if 1
@@ -376,14 +379,14 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
        }
 
        getLyXText(bv)->refresh_y = 0;
-       getLyXText(bv)->status = LyXText::UNCHANGED;
+       getLyXText(bv)->status(bv, LyXText::UNCHANGED);
        if ((need_update != CURSOR_PAR) &&
                ((drawFrame_ == ALWAYS) || ((drawFrame_ == LOCKED) && locked)))
                drawFrame(pain, cleared);
        else if (need_update & CLEAR_FRAME)
                clearFrame(pain, cleared);
        x += last_width /* was width(bv, f) */ - TEXT_TO_INSET_OFFSET;
-       if (bv->text->status==LyXText::CHANGED_IN_DRAW) {
+       if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
                need_update |= INIT;
        } else if (need_update != INIT)
                need_update = NONE;
@@ -450,12 +453,13 @@ void InsetText::update(BufferView * bv, LyXFont const & font, bool reinit)
 //             update(bv, font, reinit);
                return;
        }
-       if ((need_update & CURSOR_PAR) && t->status == LyXText::UNCHANGED &&
-               the_locking_inset) {
+       if ((need_update & CURSOR_PAR) && (t->status() == LyXText::UNCHANGED) &&
+               the_locking_inset)
+       {
                t->updateInset(bv, the_locking_inset);
        }
        
-       if (t->status == LyXText::NEED_MORE_REFRESH)
+       if (t->status() == LyXText::NEED_MORE_REFRESH)
                need_update |= FULL;
 #if 0
        int y_temp = 0;
@@ -470,9 +474,9 @@ void InsetText::setUpdateStatus(BufferView * bv, int what) const
 {
        LyXText * t = getLyXText(bv);
        need_update |= what;
-       if (t->status == LyXText::NEED_MORE_REFRESH)
+       if (t->status() == LyXText::NEED_MORE_REFRESH)
                need_update |= FULL;
-       else if (t->status == LyXText::NEED_VERY_LITTLE_REFRESH)
+       else if (t->status() == LyXText::NEED_VERY_LITTLE_REFRESH)
                need_update |= CURSOR_PAR;
 
        // this to not draw a selection when we redraw all of it!
@@ -486,9 +490,11 @@ void InsetText::updateLocal(BufferView * bv, int what, bool mark_dirty)
        LyXText * t = getLyXText(bv);
        t->fullRebreak(bv);
        setUpdateStatus(bv, what);
-       if (need_update != CURSOR || t->status != LyXText::UNCHANGED ||
+       if ((need_update != CURSOR) || (t->status() != LyXText::UNCHANGED) ||
                t->selection.set())
+       {
                bv->updateInset(this, mark_dirty);
+       }
        bv->owner()->showState();
        if (old_par != cpar(bv)) {
                bv->owner()->setLayout(cpar(bv)->getLayout());
@@ -521,13 +527,11 @@ void InsetText::edit(BufferView * bv, int x, int y, unsigned int button)
        int tmp_y = (y < 0) ? 0 : y;
        LyXText * t = getLyXText(bv);
 
-       if (!checkAndActivateInset(bv, x, tmp_y, button)) {
+       if (!checkAndActivateInset(bv, x, tmp_y, button))
                t->setCursorFromCoordinates(bv, x - drawTextXOffset,
-                                                                       y + insetAscent);
-       }
-       
+                                           y + insetAscent);
        t->selection.cursor = t->cursor;
-       bv->text->finishUndo();
+       finishUndo();
        showInsetCursor(bv);
        updateLocal(bv, CURSOR, false);
 
@@ -846,16 +850,16 @@ InsetText::localDispatch(BufferView * bv,
                         * "auto_region_delete", which defaults to
                         * true (on). */
 
-                       bv->text->setUndo(bv->buffer(), Undo::INSERT,
-                                         bv->text->cursor.par()->previous(),
-                                         bv->text->cursor.par()->next());
+                       LyXText * t = getLyXText(bv);
+                       setUndo(bv, Undo::INSERT,
+                               t->cursor.par(), t->cursor.par()->next());
                        bv->setState();
                        if (lyxrc.auto_region_delete) {
-                               if (getLyXText(bv)->selection.set()) {
-                                       getLyXText(bv)->cutSelection(bv, false);
+                               if (t->selection.set()) {
+                                       t->cutSelection(bv, false);
                                }
                        }
-                       getLyXText(bv)->clearSelection(bv);
+                       t->clearSelection(bv);
                        for (string::size_type i = 0; i < arg.length(); ++i) {
                                if (greek_kb_flag) {
                                        if (!math_insert_greek(bv, arg[i])) {
@@ -874,51 +878,51 @@ InsetText::localDispatch(BufferView * bv,
                break;
                // --- Cursor Movements -----------------------------------
        case LFUN_RIGHTSEL:
-               bv->text->finishUndo();
+               finishUndo();
                moveRight(bv, false, true);
                getLyXText(bv)->setSelection(bv);
                updateLocal(bv, SELECTION, false);
                break;
        case LFUN_RIGHT:
                result = moveRight(bv);
-               bv->text->finishUndo();
+               finishUndo();
                updateLocal(bv, CURSOR, false);
                break;
        case LFUN_LEFTSEL:
-               bv->text->finishUndo();
+               finishUndo();
                moveLeft(bv, false, true);
                getLyXText(bv)->setSelection(bv);
                updateLocal(bv, SELECTION, false);
                break;
        case LFUN_LEFT:
-               bv->text->finishUndo();
+               finishUndo();
                result = moveLeft(bv);
                updateLocal(bv, CURSOR, false);
                break;
        case LFUN_DOWNSEL:
-               bv->text->finishUndo();
+               finishUndo();
                moveDown(bv);
                getLyXText(bv)->setSelection(bv);
                updateLocal(bv, SELECTION, false);
                break;
        case LFUN_DOWN:
-               bv->text->finishUndo();
+               finishUndo();
                result = moveDown(bv);
                updateLocal(bv, CURSOR, false);
                break;
        case LFUN_UPSEL:
-               bv->text->finishUndo();
+               finishUndo();
                moveUp(bv);
                getLyXText(bv)->setSelection(bv);
                updateLocal(bv, SELECTION, false);
                break;
        case LFUN_UP:
-               bv->text->finishUndo();
+               finishUndo();
                result = moveUp(bv);
                updateLocal(bv, CURSOR, false);
                break;
        case LFUN_HOME:
-               bv->text->finishUndo();
+               finishUndo();
                getLyXText(bv)->cursorHome(bv);
                updateLocal(bv, CURSOR, false);
                break;
@@ -927,28 +931,21 @@ InsetText::localDispatch(BufferView * bv,
                updateLocal(bv, CURSOR, false);
                break;
        case LFUN_BACKSPACE: {
-               bv->text->setUndo(bv->buffer(), Undo::DELETE,
-                                 bv->text->cursor.par()->previous(),
-                                 bv->text->cursor.par()->next());
                LyXText * t = getLyXText(bv);
-               
-               if (t->selection.set()) {
+               setUndo(bv, Undo::DELETE,
+                       t->cursor.par(), t->cursor.par()->next());
+               if (t->selection.set())
                        t->cutSelection(bv);
-               } else {
+               else
                        t->backspace(bv);
-               }
-               
                updateLocal(bv, CURSOR_PAR, true);
        }
        break;
        
-       case LFUN_DELETE:
-       {
-               bv->text->setUndo(bv->buffer(), Undo::DELETE,
-                                 bv->text->cursor.par()->previous(),
-                                 bv->text->cursor.par()->next());
+       case LFUN_DELETE: {
                LyXText * t = getLyXText(bv);
-               
+               setUndo(bv, Undo::DELETE,
+                       t->cursor.par(), t->cursor.par()->next());
                if (t->selection.set()) {
                        t->cutSelection(bv);
                } else {
@@ -958,15 +955,17 @@ InsetText::localDispatch(BufferView * bv,
        }
        break;
        
-       case LFUN_CUT:
-               bv->text->setUndo(bv->buffer(), Undo::DELETE,
-                                 bv->text->cursor.par()->previous(),
-                                 bv->text->cursor.par()->next());
-               getLyXText(bv)->cutSelection(bv);
+       case LFUN_CUT: {
+               LyXText * t = getLyXText(bv);
+               setUndo(bv, Undo::DELETE,
+                       t->cursor.par(), t->cursor.par()->next());
+               t->cutSelection(bv);
                updateLocal(bv, CURSOR_PAR, true);
-               break;
+       }
+       break;
+
        case LFUN_COPY:
-               bv->text->finishUndo();
+               finishUndo();
                getLyXText(bv)->copySelection(bv);
                updateLocal(bv, CURSOR_PAR, false);
                break;
@@ -984,7 +983,7 @@ InsetText::localDispatch(BufferView * bv,
                updateLocal(bv, CURSOR_PAR, true);
                break;
        }
-       case LFUN_PASTE:
+       case LFUN_PASTE: {
                if (!autoBreakRows) {
 
                        if (CutAndPaste::nrOfParagraphs() > 1) {
@@ -994,12 +993,14 @@ InsetText::localDispatch(BufferView * bv,
                                break;
                        }
                }
-               bv->text->setUndo(bv->buffer(), Undo::INSERT,
-                                 bv->text->cursor.par()->previous(),
-                                 bv->text->cursor.par()->next());
-               getLyXText(bv)->pasteSelection(bv);
+               LyXText * t = getLyXText(bv);
+               setUndo(bv, Undo::INSERT,
+                       t->cursor.par(), t->cursor.par()->next());
+               t->pasteSelection(bv);
                updateLocal(bv, CURSOR_PAR, true);
-               break;
+       }
+       break;
+
        case LFUN_BREAKPARAGRAPH:
                if (!autoBreakRows)
                        return DISPATCHED;
@@ -1012,15 +1013,18 @@ InsetText::localDispatch(BufferView * bv,
                getLyXText(bv)->breakParagraph(bv, 1);
                updateLocal(bv, FULL, true);
                break;
-       case LFUN_BREAKLINE:
+
+       case LFUN_BREAKLINE: {
                if (!autoBreakRows)
                        return DISPATCHED;
-               bv->text->setUndo(bv->buffer(), Undo::INSERT,
-                                 bv->text->cursor.par()->previous(),
-                                 bv->text->cursor.par()->next());
-               getLyXText(bv)->insertChar(bv, Paragraph::META_NEWLINE);
+               LyXText * t = getLyXText(bv);
+               setUndo(bv, Undo::INSERT,
+                       t->cursor.par(), t->cursor.par()->next());
+               t->insertChar(bv, Paragraph::META_NEWLINE);
                updateLocal(bv, CURSOR_PAR, true);
-               break;
+       }
+       break;
+
        case LFUN_LAYOUT:
                // do not set layouts on non breakable textinsets
                if (autoBreakRows) {
@@ -1334,18 +1338,19 @@ bool InsetText::insertInset(BufferView * bv, Inset * inset)
                        return the_locking_inset->insertInset(bv, inset);
                return false;
        }
-       bv->text->setUndo(bv->buffer(), Undo::INSERT,
-                         bv->text->cursor.par()->previous(),
-                         bv->text->cursor.par()->next());
+       LyXText * t = getLyXText(bv);
+       setUndo(bv, Undo::INSERT,
+               t->cursor.par(), t->cursor.par()->next());
        inset->setOwner(this);
        hideInsetCursor(bv);
-       getLyXText(bv)->insertInset(bv, inset);
+       t = getLyXText(bv);
+       t->insertInset(bv, inset);
 #if 0
        if ((cpar(bv)->GetChar(cpos(bv)) != Paragraph::META_INSET) ||
                (cpar(bv)->GetInset(cpos(bv)) != inset))
-               getLyXText(bv)->CursorLeft(bv);
+               t->CursorLeft(bv);
 #endif
-       bv->fitCursor(getLyXText(bv));
+       bv->fitCursor(t);
        updateLocal(bv, CURSOR_PAR|CURSOR, true);
        showInsetCursor(bv);
        return true;
@@ -1401,18 +1406,22 @@ void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
                the_locking_inset->setFont(bv, font, toggleall, selectall);
                return;
        }
-       if (getLyXText(bv)->selection.set()) {
-               bv->text->setUndo(bv->buffer(), Undo::EDIT,
-                                 bv->text->cursor.par()->previous(),
-                                 bv->text->cursor.par()->next());
+       LyXText * t = getLyXText(bv);
+       if (t->selection.set()) {
+               setUndo(bv, Undo::EDIT,
+                       t->cursor.par(), t->cursor.par()->next());
        }
        if (selectall)
                selectAll(bv);
-       getLyXText(bv)->setFont(bv, font, toggleall);
+#if 1
+       t->toggleFree(bv, font, toggleall);
+#else
+       t->setFont(bv, font, toggleall);
+#endif
        if (selectall)
-               getLyXText(bv)->clearSelection(bv);
-       bv->fitCursor(getLyXText(bv));
-       if (selectall || getLyXText(bv)->selection.set())
+               t->clearSelection(bv);
+       bv->fitCursor(t);
+       if (selectall || t->selection.set())
                updateLocal(bv, FULL, true);
        else
                updateLocal(bv, CURSOR_PAR, true);
@@ -1816,9 +1825,73 @@ void InsetText::clearInset(Painter & pain, int baseline, bool & cleared) const
        cleared = true;
        need_update = FULL;
 }
-/* Emacs:
- * Local variables:
- * tab-width: 4
- * End:
- * vi:set tabstop=4:
- */
+
+Paragraph * InsetText::getParFromID(int id) const
+{
+       Paragraph * result = par;
+       Paragraph * ires = 0;
+       while (result && result->id() != id) {
+               if ((ires = result->getParFromID(id)))
+                       return ires;
+               result = result->next();
+       }
+       return result;
+}
+
+Paragraph * InsetText::firstParagraph() const
+{
+       Paragraph * result;
+       if (the_locking_inset)
+               if ((result = the_locking_inset->firstParagraph()))
+                       return result;
+       return par;
+}
+
+LyXCursor const & InsetText::cursor(BufferView * bv) const
+{
+               if (the_locking_inset)
+                               return the_locking_inset->cursor(bv);
+               return getLyXText(bv)->cursor;
+}
+
+Paragraph * InsetText::paragraph() const
+{
+       return par;
+}
+
+void InsetText::paragraph(Paragraph * p)
+{
+       par = p;
+#if 0
+       // we now have to update/redraw all instances
+       for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit) {
+               delete (*cit).second;
+               (*cit).second = 0;
+       }
+#endif
+       // redraw myself when asked for
+       need_update |= INIT;
+}
+
+Inset * InsetText::getInsetFromID(int id_arg) const
+{
+       if (id_arg == id())
+               return const_cast<InsetText *>(this);
+
+       Paragraph * lp = par;
+
+       while(lp) {
+               for (Paragraph::inset_iterator it = lp->inset_iterator_begin(),
+                        en = lp->inset_iterator_end();
+                        it != en; ++it)
+               {
+                       if ((*it)->id() == id_arg)
+                               return *it;
+                       Inset * in = (*it)->getInsetFromID(id_arg);
+                       if (in)
+                               return in;
+               }
+               lp = lp->next();
+       }
+       return 0;
+}
index ff0d757e7edf4ef9ba5bbb446a27d28bce2c527f..1300c1bf31629ce02868c0a10fa7c4021690f756 100644 (file)
@@ -21,6 +21,8 @@
 
 #include "inset.h"
 #include "LString.h"
+#include "LColor.h"
+#include "paragraph.h"
 #include "lyxcursor.h"
 #include <boost/smart_ptr.hpp>
 
@@ -28,10 +30,9 @@ class Painter;
 class BufferView;
 class Buffer;
 class LyXCursor;
-class Paragraph;
-class LColor;
 class LyXText;
 class LyXScreen;
+class Row;
 
 /**
  A text inset is like a TeX box to write full text
@@ -74,11 +75,11 @@ public:
        InsetText();
        ///
        explicit
-       InsetText(InsetText const &);
+       InsetText(InsetText const &, bool same_id = false);
        ///
        ~InsetText();
        ///
-       Inset * clone(Buffer const &) const;
+       Inset * clone(Buffer const &, bool same_id = false) const;
        ///
        InsetText & operator=(InsetText const & it);
        ///
@@ -161,7 +162,7 @@ public:
        ///
        int getMaxWidth(BufferView *, UpdatableInset const *) const;
        ///
-       void init(InsetText const * ins = 0);
+       void init(InsetText const * ins = 0, bool same_id = false);
        ///
        void writeParagraphData(Buffer const *, std::ostream &) const;
        ///
@@ -201,8 +202,18 @@ public:
        void selectAll(BufferView *bv);
        ///
        void clearSelection(BufferView *bv);
-
-       Paragraph * par;
+       ///
+       Paragraph * getParFromID(int id) const;
+       ///
+       Inset * getInsetFromID(int id) const;
+       ///
+       Paragraph * firstParagraph() const;
+       ///
+       LyXCursor const & cursor(BufferView *) const;
+       ///
+       Paragraph * paragraph() const;
+       ///
+       void paragraph(Paragraph *);
        ///
        mutable int need_update;
 
@@ -284,6 +295,8 @@ private:
        
        /* Private structures and variables */
        ///
+       Paragraph * par;
+       ///
        mutable bool locked;
        ///
        mutable int insetAscent;
index 1f4068773dcf4ea414ca8ad3392f0dc4721ff431..fa46fcb3921a0706125d624ca0ec0d7efa42e0ae 100644 (file)
@@ -54,8 +54,9 @@ void InsetTheorem::write(Buffer const * buf, ostream & os) const
 }
 
 
-Inset * InsetTheorem::clone(Buffer const &) const
+Inset * InsetTheorem::clone(Buffer const &, bool) const
 {
+#warning Is this inset used? If YES this is WRONG!!! (Jug)
        InsetTheorem * result = new InsetTheorem;
        
        result->collapsed = collapsed;
index c81e54f036bfd8a010f977504c6dee936cbfc560..22e2edfe0afbdc5225bd9cf4b17a7d1b42cb8d56 100644 (file)
@@ -28,7 +28,7 @@ public:
        ///
        void write(Buffer const * buf, std::ostream & os) const;
        ///
-       virtual Inset * clone(Buffer const &) const;
+       virtual Inset * clone(Buffer const &, bool same_id = false) const;
        ///
        Inset::Code lyxCode() const { return Inset::THEOREM_CODE; }
        ///
index 9be3b6bdd80fb7096b9e67fd5efdbd0752fd7714..01766e77eb96947f79a69a921bad777864cf2f15 100644 (file)
 class InsetTOC : public InsetCommand {
 public:
        ///
-       InsetTOC(InsetCommandParams const & p) : InsetCommand(p) {}
+       InsetTOC(InsetCommandParams const & p, bool same_id = false)
+                       : InsetCommand(p, same_id) {}
        ///
-        virtual Inset * clone(Buffer const &) const {
-               return new InsetTOC(params());
+       virtual Inset * clone(Buffer const &, bool same_id = false) const {
+               return new InsetTOC(params(), same_id);
        }
        ///
        string const getScreenLabel() const;
index 0f515834638e25aac6de72cea44629439809023e..e3758cb2efc542e44c7631c41eb45c4d1f8bb588 100644 (file)
@@ -15,7 +15,7 @@
 using std::ostream;
 
 
-InsetUrl::InsetUrl(InsetCommandParams const & p)
+InsetUrl::InsetUrl(InsetCommandParams const & p, bool)
                : InsetCommand(p)
 {}
 
index a93367b5dc80d7e6d15132844fe4c1403e34ce67..095c71143ff0507aed12f462014eda255ae24ed1 100644 (file)
@@ -25,10 +25,10 @@ class InsetUrl : public InsetCommand {
 public:
        ///
        explicit
-       InsetUrl(InsetCommandParams const &);
+       InsetUrl(InsetCommandParams const &, bool same_id = false);
         ///
-       virtual Inset * clone(Buffer const &) const {
-               return new InsetUrl(params());
+       virtual Inset * clone(Buffer const &, bool same_id = false) const {
+               return new InsetUrl(params(), same_id);
        }
        ///
        Inset::Code lyxCode() const { return Inset::URL_CODE; }
index 7140be709d664c765f39c0f8bb2e98ef76f1a511..b4a1af2178517da99b48776c04bb8ba77ceeaa47 100644 (file)
@@ -90,6 +90,7 @@
 #include "FontLoader.h"
 #include "TextCache.h"
 #include "lyxfind.h"
+#include "undo_funcs.h"
 
 using std::pair;
 using std::make_pair; 
@@ -706,14 +707,21 @@ string const LyXFunc::Dispatch(int ac,
                                argument = keyseq.getiso();
                        }
                        // Undo/Redo is a bit tricky for insets.
-                       if (action == LFUN_UNDO) {
+                       if (action == LFUN_UNDO) {
+#ifdef RETHINK_THIS_FOR_NOW_WE_LEAVE_ALL_UNLOCKED
                                int slx;
                                int sly;
                                UpdatableInset * inset = 
-                                       owner->view()->theLockingInset();
+                                       owner->view()->theLockingInset()->getLockingInset();
+                               int inset_id = inset->id();
                                inset->getCursorPos(owner->view(), slx, sly);
                                owner->view()->unlockInset(inset);
+#else
+                               owner->view()->unlockInset(owner->view()->theLockingInset());
+#endif
                                owner->view()->menuUndo();
+#ifdef RETHINK_THIS_FOR_NOW_WE_LEAVE_ALL_UNLOCKED
+#if 0
                                if (TEXT()->cursor.par()->
                                    isInset(TEXT()->cursor.pos())) {
                                        inset = static_cast<UpdatableInset*>(
@@ -723,8 +731,12 @@ string const LyXFunc::Dispatch(int ac,
                                } else {
                                        inset = 0;
                                }
+#else
+                               inset = static_cast<UpdatableInset *>(owner->view()->buffer()->getInsetFromID(inset_id));
+#endif
                                if (inset)
                                        inset->edit(owner->view(),slx,sly,0);
+#endif
                                return string();
                        } else if (action == LFUN_REDO) {
                                int slx;
@@ -843,7 +855,7 @@ string const LyXFunc::Dispatch(int ac,
                        // Move cursor so that successive C-s 's will not stand in place. 
                        if (action == LFUN_WORDFINDFORWARD ) 
                                TEXT()->cursorRightOneWord(owner->view());
-                       TEXT()->finishUndo();
+                       finishUndo();
                        moveCursorUpdate(true, false);
 
                        // ??? Needed ???
index 144e71ed15b99af3e6ed194bdfc32b1e46bc9488..deeb79729d8692e3d52056004d05979da1c6355a 100644 (file)
@@ -17,7 +17,6 @@
 #endif
 
 #include "lyxfont.h"
-#include "undo.h"
 #include "lyxcursor.h"
 #include "paragraph.h"
 #include "layout.h"
@@ -38,13 +37,13 @@ public:
        ///
        enum text_status {
                ///
-               UNCHANGED,
+               UNCHANGED = 0,
                ///
-               NEED_MORE_REFRESH,
+               CHANGED_IN_DRAW = 1,
                ///
-               NEED_VERY_LITTLE_REFRESH,
+               NEED_VERY_LITTLE_REFRESH = 2,
                ///
-               CHANGED_IN_DRAW
+               NEED_MORE_REFRESH = 3
        };
        ///
        enum word_location {
@@ -182,12 +181,18 @@ public:
        mutable Row * refresh_row;
        ///
        int refresh_pos;
-       
+
+       /// give and set the LyXText status
+       text_status status() const;
+       void status(BufferView *, text_status) const;
+
+private:       
        /** wether the screen needs a refresh,
           starting with refresh_y
           */
-       mutable text_status status;
+       mutable text_status status_;
        
+public:
        /** returns a pointer to the row near the specified y-coordinate
          (relative to the whole text). y is set to the real beginning
          of this row
@@ -362,7 +367,7 @@ public:
                                       LyXCursor const & to,
                                       LyXText::TextCase action);
        ///
-       void transposeChars(BufferView const &);
+       void transposeChars(BufferView &);
        
        /** returns a printed row in a pixmap. The y value is needed to
          decide, wether it is selected text or not. This is a strange
@@ -438,39 +443,8 @@ public:
        int numberOfCell(Paragraph * par,
                         Paragraph::size_type pos) const;
        ///
-       Paragraph * getParFromID(int id);
-
-       // undo functions
-       /// returns false if no undo possible
-       bool textUndo(BufferView *);
-       /// returns false if no redo possible
-       bool textRedo(BufferView *);
-       /// used by TextUndo/TextRedo
-       bool textHandleUndo(BufferView *, Undo * undo);
-       /// makes sure the next operation will be stored
-       void finishUndo();
-       /// this is dangerous and for internal use only
-       void freezeUndo();
-       /// this is dangerous and for internal use only
-       void unFreezeUndo();
-       /// the flag used by FinishUndo();
-       mutable bool undo_finished;
-       /// a flag
-       bool undo_frozen;
-       ///
-       void setUndo(Buffer *, Undo::undo_kind kind,
-                    Paragraph const * before,
-                    Paragraph const * end) const;
-       ///
-       void setRedo(Buffer *, Undo::undo_kind kind,
-                    Paragraph const * before,
-                    Paragraph const * end);
-       ///
-       Undo * createUndo(Buffer *, Undo::undo_kind kind,
-                         Paragraph const * before,
-                         Paragraph const * end) const;
-       /// for external use in lyx_cb.C
-       void setCursorParUndo(Buffer *);
+       Paragraph * getParFromID(int id) const;
+
        ///
        void removeTableRow(LyXCursor & cursor) const;
        ///
@@ -562,9 +536,11 @@ private:
        void deleteEmptyParagraphMechanism(BufferView *,
                                           LyXCursor const & old_cursor) const;
 
+public:
        /** Updates all counters starting BEHIND the row. Changed paragraphs
         * with a dynamic left margin will be rebroken. */ 
        void updateCounters(BufferView *, Row * row) const;
+private:
        ///
        void setCounter(Buffer const *, Paragraph * par) const;
    
@@ -660,12 +636,15 @@ private:
 
        ///
        void charInserted();
+public:
        //
        // special owner functions
        ///
        Paragraph * ownerParagraph() const;
        //
        Paragraph * ownerParagraph(Paragraph *) const;
+       // set it searching first for the right owner using the paragraph id
+       Paragraph * ownerParagraph(int id, Paragraph *) const;
 };
 
 
index 65fe6aefab62cb1a266193a863889aec2ed1b052..4508d4dd9b693ddcbe561416c21ddf3254838883 100644 (file)
@@ -76,7 +76,7 @@ InsetFormula::InsetFormula(string const & s)
 }
 
 
-Inset * InsetFormula::clone(Buffer const &) const
+Inset * InsetFormula::clone(Buffer const &, bool) const
 {
        return new InsetFormula(*this);
 }
index eb629c90e11c852e60b2c1ac42c043c360685ce9..d73fd375b80f316674d669eca118e86af1df0e4f 100644 (file)
@@ -60,7 +60,7 @@ public:
        int docBook(std::ostream &) const;
 
        ///
-       Inset * clone(Buffer const &) const;
+       Inset * clone(Buffer const &, bool same_id = false) const;
        ///
        void validate(LaTeXFeatures & features) const;
        ///
index 6c3f0b18da2e961a5a3df0e39f0df1aefcdb3fc8..f78222340d6d9ee3bff0417f6cf09caad16d6fa5 100644 (file)
@@ -42,6 +42,7 @@
 #include "math_deliminset.h"
 #include "support/lyxlib.h"
 #include "mathed/support.h"
+#include "undo_funcs.h"
 
 using std::endl;
 using std::ostream;
@@ -82,7 +83,7 @@ bool openNewInset(BufferView * bv, UpdatableInset * new_inset)
        LyXText * lt = bv->getLyXText();
        
        bv->beforeChange(lt);
-       lt->finishUndo();
+       finishUndo();
        if (!bv->insertInset(new_inset)) {
                delete new_inset;
                return false;
index a3354867aacaddbf58e86800d6d06c3afe1d914a..be8e5ce689a5e2d18d8fc5f7fc3bf779440c3fd8 100644 (file)
@@ -80,7 +80,7 @@ public:
        ///
        virtual void validate(LaTeXFeatures &) const;
        ///
-       virtual Inset * clone(Buffer const &) const = 0;
+       virtual Inset * clone(Buffer const &, bool same_id = false) const = 0;
        ///
        virtual Inset::Code lyxCode() const;
        ///
index d0de1d9ee8bf96a0d408a77769e974b54ff96a9f..fbbfd72002c3ac9d2dad07dbf434bb60fd4ffa30 100644 (file)
@@ -53,7 +53,7 @@ InsetFormulaMacro::InsetFormulaMacro(string nm, int na)
 }
 
 
-Inset * InsetFormulaMacro::clone(Buffer const &) const
+Inset * InsetFormulaMacro::clone(Buffer const &, bool) const
 {
        return new InsetFormulaMacro(*this);
 }
index 8243e2a777a1bc416b5e888b475219acf76c04b9..204ddaffe45738af5eefbf3c47fea846f47a77d3 100644 (file)
@@ -59,7 +59,7 @@ public:
        int docBook(std::ostream &) const;
 
        ///
-       Inset * clone(Buffer const &) const;
+       Inset * clone(Buffer const &, bool same_id = false) const;
        ///
        Inset::Code lyxCode() const;
        ///
index 5b0989c6b629fc6c4e3dfe8e360805815c124638..c6553fdc3925364c9dca4ac9f0819e0e38486c0d 100644 (file)
@@ -107,10 +107,11 @@ Paragraph::Paragraph(Paragraph * par)
 }
 
 
-Paragraph::Paragraph(Paragraph const & lp)
-       : pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this))
+Paragraph::Paragraph(Paragraph const & lp, bool same_ids)
+       : pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this, same_ids))
 {
-       for (int i = 0; i < 10; ++i) setCounter(i , 0);
+       for (int i = 0; i < 10; ++i)
+               setCounter(i , 0);
        enumdepth = 0;
        itemdepth = 0;
        next_ = 0;
@@ -132,8 +133,9 @@ Paragraph::Paragraph(Paragraph const & lp)
 
        insetlist = lp.insetlist;
        for (InsetList::iterator it = insetlist.begin();
-            it != insetlist.end(); ++it) {
-               it->inset = it->inset->clone(*current_view->buffer());
+            it != insetlist.end(); ++it)
+       {
+               it->inset = it->inset->clone(*current_view->buffer(), same_ids);
        }
 }
 
@@ -2016,7 +2018,7 @@ bool Paragraph::isFirstInSequence() const
 }
 
 
-Inset * Paragraph::InInset()
+Inset * Paragraph::InInset() const
 {
        return pimpl_->inset_owner;
 }
@@ -2081,3 +2083,7 @@ ParagraphParameters const & Paragraph::params() const
        return pimpl_->params;
 }
 
+Paragraph * Paragraph::getParFromID(int id) const
+{
+       return pimpl_->getParFromID(id);
+}
index 8c6abcbf330de81bb776a6ff7d50caa72a1a911c..8d014b08b414856987bbf4e734e35cf73f96f98b 100644 (file)
@@ -94,7 +94,7 @@ public:
        explicit
        Paragraph(Paragraph * par);
        ///
-       Paragraph(Paragraph const &);
+       Paragraph(Paragraph const &, bool same_ids = false);
        /// the destructor removes the new paragraph from the list
        ~Paragraph();
 
@@ -150,7 +150,7 @@ public:
            proof environment */
        int getEndLabel(BufferParams const &) const;
        ///
-       Inset * InInset();
+       Inset * InInset() const;
        ///
        void setInsetOwner(Inset * i);
        ///
@@ -321,6 +321,9 @@ public:
        /// returns -1 if inset not found
        int getPositionOfInset(Inset * inset) const;
 
+       /// some good comment here John?
+       Paragraph * getParFromID(int id) const;
+
        ///
        int stripLeadingSpaces(LyXTextClassList::size_type tclass); 
 
index 37f71b1569420b61457dcf38440773a6069dbe9c..74115b13f72a6378a2bdf702e4ade22f5ed50d1b 100644 (file)
@@ -39,12 +39,17 @@ Paragraph::Pimpl::Pimpl(Paragraph * owner)
 }
 
 
-Paragraph::Pimpl::Pimpl(Paragraph::Pimpl const & p, Paragraph * owner)
+Paragraph::Pimpl::Pimpl(Paragraph::Pimpl const & p, Paragraph * owner,
+                        bool same_ids)
        : params(p.params), owner_(owner)
 {
        inset_owner = p.inset_owner;
        text = p.text;
        fontlist = p.fontlist;
+       if (same_ids)
+               id_ = p.id_;
+       else
+               id_ = paragraph_id++;
 }
 
 
@@ -539,3 +544,16 @@ Paragraph * Paragraph::Pimpl::TeXDeeper(Buffer const * buf,
 }
 
 
+Paragraph * Paragraph::Pimpl::getParFromID(int id) const
+{
+       InsetList::const_iterator lend = owner_->insetlist.end();
+       Paragraph * result;
+       for (InsetList::const_iterator cit = owner_->insetlist.begin();
+            cit != lend; ++cit)
+       {
+               if ((result = cit->inset->getParFromID(id)))
+                       return result;
+       }
+       return 0;
+}
+
index bda3bc960dac2e27948f62236b5a5bb6d724ff75..628f20d5e9e976d4055674968a438f2f245a4280 100644 (file)
@@ -24,7 +24,7 @@ struct Paragraph::Pimpl {
        ///
        Pimpl(Paragraph * owner);
        /// Copy constructor
-       Pimpl(Pimpl const &, Paragraph * owner);
+       Pimpl(Pimpl const &, Paragraph * owner, bool same_ids = false);
        ///
        Paragraph::size_type size() const {
                return text.size();
@@ -140,6 +140,8 @@ struct Paragraph::Pimpl {
                                   size_type & i,
                                   int & column, value_type const c);
        ///
+       Paragraph * getParFromID(int id) const;
+       ///
        unsigned int id_;
        ///
        static unsigned int paragraph_id;
index bd802911a85ee2204edad36cc4dbe462be79c7f8..d09e3d42ed0767a8d5986c971618804574a4041e 100644 (file)
@@ -124,13 +124,13 @@ void LyXScreen::drawFromTo(LyXText * text, BufferView * bv,
        // y1 is now the real beginning of row on the screen
        
        while (row != 0 && y < y2) {
-               LyXText::text_status st = bv->text->status;
+               LyXText::text_status st = bv->text->status();
                do {
-                       bv->text->status = st;
+                       bv->text->status(bv, st);
                        text->getVisibleRow(bv, y + y_offset,
                                            x_offset, row, y + text->first);
-               } while (bv->text->status == LyXText::CHANGED_IN_DRAW);
-               bv->text->status = st;
+               } while (bv->text->status() == LyXText::CHANGED_IN_DRAW);
+               bv->text->status(bv, st);
                y += row->height();
                row = row->next();
        }
@@ -154,13 +154,13 @@ void LyXScreen::drawOneRow(LyXText * text, BufferView * bv, Row * row,
        if (((y + row->height()) > 0) &&
            ((y - row->height()) <= static_cast<int>(owner.height()))) {
                // ok there is something visible
-               LyXText::text_status st = bv->text->status;
+               LyXText::text_status st = bv->text->status();
                do {
-                       bv->text->status = st;
+                       bv->text->status(bv, st);
                        text->getVisibleRow(bv, y, x_offset, row,
                                            y + text->first);
-               } while (bv->text->status == LyXText::CHANGED_IN_DRAW);
-               bv->text->status = st;
+               } while (bv->text->status() == LyXText::CHANGED_IN_DRAW);
+               bv->text->status(bv, st);
        }
        force_clear = false;
 }
@@ -420,13 +420,13 @@ bool LyXScreen::fitCursor(LyXText * text, BufferView * bv)
 void LyXScreen::update(LyXText * text, BufferView * bv,
                       int y_offset, int x_offset)
 {
-       switch (text->status) {
+       switch (text->status()) {
        case LyXText::NEED_MORE_REFRESH:
        {
                int const y = max(int(text->refresh_y - text->first), 0);
                drawFromTo(text, bv, y, owner.height(), y_offset, x_offset);
                text->refresh_y = 0;
-               text->status = LyXText::UNCHANGED;
+               text->status(bv, LyXText::UNCHANGED);
                expose(0, y, owner.workWidth(), owner.height() - y);
        }
        break;
@@ -435,7 +435,7 @@ void LyXScreen::update(LyXText * text, BufferView * bv,
                // ok I will update the current cursor row
                drawOneRow(text, bv, text->refresh_row, text->refresh_y,
                           y_offset, x_offset);
-               text->status = LyXText::UNCHANGED;
+               text->status(bv, LyXText::UNCHANGED);
                expose(0, text->refresh_y - text->first + y_offset,
                       owner.workWidth(), text->refresh_row->height());
        }
index 99e7816168bc011a4d64bf3c845fd3b14a4161a6..86091c6e36a02486ec4f65ffa911810f50349877 100644 (file)
@@ -1556,7 +1556,7 @@ void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl)
                        }
                }
                par->copyIntoMinibuffer(*owner_->bufferOwner(), i);
-               inset->par->insertFromMinibuffer(inset->par->size());
+               inset->paragraph()->insertFromMinibuffer(inset->paragraph()->size());
        }
        delete par;
        Reinit();
@@ -2163,8 +2163,8 @@ int LyXTabular::Latex(Buffer const * buf,
                        ret += TeXCellPreamble(os, cell);
                        InsetText * inset = GetCellInset(cell);
 
-                       bool rtl = inset->par->isRightToLeftPar(buf->params) &&
-                                       inset->par->size() > 0 && GetPWidth(cell).empty();
+                       bool rtl = inset->paragraph()->isRightToLeftPar(buf->params) &&
+                                       inset->paragraph()->size() > 0 && GetPWidth(cell).empty();
 
                        if (rtl)
                                os << "\\R{";
@@ -2570,7 +2570,7 @@ std::vector<string> const LyXTabular::getLabelList() const
                        
 LyXTabular::BoxType LyXTabular::UseParbox(int cell) const
 {
-       Paragraph * par = GetCellInset(cell)->par;
+       Paragraph * par = GetCellInset(cell)->paragraph();
 
        for (; par; par = par->next()) {
                for (int i = 0; i < par->size(); ++i) {
index 5f69db7ed7079fe5809635366c916d87f39f4da9..8d43f09089dcbbd1815e3f4d7d165256ea8bb9b2 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;
@@ -2414,8 +2412,8 @@ void LyXText::changeRegionCase(BufferView * bview,
 {
        lyx::Assert(from <= to);
        
-       setUndo(bview->buffer(), Undo::FINISH,
-               from.par()->previous(), to.par()->next());
+       setUndo(bview, Undo::FINISH,
+               from.par(), to.par()->next());
 
        Paragraph::size_type pos = from.pos();
        Paragraph * par = from.par();
@@ -2448,17 +2446,17 @@ void LyXText::changeRegionCase(BufferView * bview,
        if (to.row() != from.row()) {
                refresh_y = from.y() - from.row()->baseline();
                refresh_row = from.row();
-               status = LyXText::NEED_MORE_REFRESH;
+               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();
 
@@ -2511,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);
        }
@@ -2561,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());
                }
                
@@ -2615,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();
                        
@@ -2637,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,
@@ -2755,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;
@@ -2783,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?
@@ -2805,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());
index 4793569831eab6a7545e5bef7feb8a15b4c0f9c4..7121831aac3fa2fbdb540f56ca7021ff84df21eb 100644 (file)
@@ -25,7 +25,7 @@
 #include "layout.h"
 #include "LyXView.h"
 #include "support/textutils.h"
-#include "undo.h"
+#include "undo_funcs.h"
 #include "buffer.h"
 #include "bufferparams.h"
 #include "lyx_gui_misc.h"
@@ -51,21 +51,18 @@ using std::pair;
 LyXText::LyXText(BufferView * bv)
        : number_of_rows(0), height(0), width(0), first(0),
          bv_owner(bv), inset_owner(0), the_locking_inset(0),
-         need_break_row(0), refresh_y(0), status(LyXText::UNCHANGED),
-         undo_finished(true), undo_frozen(false), firstrow(0), lastrow(0),
-         copylayouttype(0)
+         need_break_row(0), refresh_y(0), status_(LyXText::UNCHANGED),
+         firstrow(0), lastrow(0), copylayouttype(0)
 {}
 
 
 LyXText::LyXText(InsetText * inset)
        :  number_of_rows(0),  height(0), width(0), first(0),
           bv_owner(0), inset_owner(inset), the_locking_inset(0),
-          need_break_row(0), refresh_y(0), status(LyXText::UNCHANGED),
-          undo_finished(true), undo_frozen(false), firstrow(0), lastrow(0),
-          copylayouttype(0)
+          need_break_row(0), refresh_y(0), status_(LyXText::UNCHANGED),
+          firstrow(0), lastrow(0), copylayouttype(0)
 {}
 
-
 void LyXText::init(BufferView * bview)
 {
        if (firstrow)
@@ -402,9 +399,8 @@ Paragraph * LyXText::setLayout(BufferView * bview,
                endpar = endpar->next(); // because of parindents etc.
        }
        
-       setUndo(bview->buffer(), Undo::EDIT,
-               sstart_cur.par()->previous(),
-               undoendpar);
+       setUndo(bview, Undo::EDIT,
+               sstart_cur.par(), undoendpar);
        
        /* ok we have a selection. This is always between sstart_cur
         * and sel_end cursor */ 
@@ -504,9 +500,8 @@ void  LyXText::incDepth(BufferView * bview)
                endpar = endpar->next(); // because of parindents etc.
        }
        
-       setUndo(bview->buffer(), Undo::EDIT,
-               selection.start.par()->previous(),
-               undoendpar);
+       setUndo(bview, Undo::EDIT,
+               selection.start.par(), undoendpar);
 
        LyXCursor tmpcursor = cursor; // store the current cursor
 
@@ -584,9 +579,8 @@ void  LyXText::decDepth(BufferView * bview)
                endpar = endpar->next(); // because of parindents etc.
        }
    
-       setUndo(bview->buffer(), Undo::EDIT,
-               selection.start.par()->previous(),
-               undoendpar);
+       setUndo(bview, Undo::EDIT,
+               selection.start.par(), undoendpar);
 
        LyXCursor tmpcursor = cursor; // store the current cursor
 
@@ -647,8 +641,8 @@ void LyXText::setFont(BufferView * bview, LyXFont const & font, bool toggleall)
        // ok we have a selection. This is always between sel_start_cursor
        // and sel_end cursor
    
-       setUndo(bview->buffer(), Undo::EDIT,
-               selection.start.par()->previous(),
+       setUndo(bview, Undo::EDIT,
+               selection.start.par(),
                selection.end.par()->next()); 
        freezeUndo();
        cursor = selection.start;
@@ -712,7 +706,7 @@ void LyXText::redoHeightOfParagraph(BufferView * bview, LyXCursor const & cur)
 #endif
        
        // we can set the refreshing parameters now
-       status = LyXText::NEED_MORE_REFRESH;
+       status(bview, LyXText::NEED_MORE_REFRESH);
        refresh_y = y;
        refresh_row = tmprow;
        setCursor(bview, cur.par(), cur.pos(), false, cursor.boundary());
@@ -746,11 +740,11 @@ void LyXText::redoDrawingOfParagraph(BufferView * bview, LyXCursor const & cur)
        }
 #endif
        // we can set the refreshing parameters now
-       if (status == LyXText::UNCHANGED || y < refresh_y) {
+       if (status_ == LyXText::UNCHANGED || y < refresh_y) {
                refresh_y = y;
                refresh_row = tmprow;
        }
-       status = LyXText::NEED_MORE_REFRESH;
+       status(bview, LyXText::NEED_MORE_REFRESH);
        setCursor(bview, cur.par(), cur.pos());
 }
 
@@ -804,7 +798,7 @@ void LyXText::redoParagraphs(BufferView * bview, LyXCursor const & cur,
 #endif
        
        // we can set the refreshing parameters now
-       status = LyXText::NEED_MORE_REFRESH;
+       status(bview, LyXText::NEED_MORE_REFRESH);
        refresh_y = y;
        refresh_row = tmprow->previous();        /* the real refresh row will
                                            be deleted, so I store
@@ -839,7 +833,7 @@ void LyXText::redoParagraphs(BufferView * bview, LyXCursor const & cur,
                                tmprow = tmprow->next();
                        tmppar = tmppar->next();
                }
-       } while (tmppar != endpar);
+       } while (tmppar && tmppar != endpar);
    
        // this is because of layout changes
        if (refresh_row) {
@@ -1096,15 +1090,13 @@ void LyXText::setParagraph(BufferView * bview,
                endpar = endpar->next(); // because of parindents etc.
        }
    
-       setUndo(bview->buffer(), Undo::EDIT,
-               selection.start.par()->previous(),
-               undoendpar);
+       setUndo(bview, Undo::EDIT, selection.start.par(), undoendpar);
 
        
        Paragraph * tmppar = selection.end.par();
        while (tmppar != selection.start.par()->previous()) {
                setCursor(bview, tmppar, 0);
-               status = LyXText::NEED_MORE_REFRESH;
+               status(bview, LyXText::NEED_MORE_REFRESH);
                refresh_row = cursor.row();
                refresh_y = cursor.y() - cursor.row()->baseline();
                        cursor.par()->params().lineTop(line_top);
@@ -1568,9 +1560,8 @@ void LyXText::insertInset(BufferView * bview, Inset * inset)
 {
        if (!cursor.par()->insertInsetAllowed(inset))
                return;
-       setUndo(bview->buffer(), Undo::INSERT,
-               cursor.par()->previous(),
-               cursor.par()->next());
+       setUndo(bview, Undo::INSERT,
+               cursor.par(), cursor.par()->next());
        cursor.par()->insertInset(cursor.pos(), inset);
        insertChar(bview, Paragraph::META_INSET);  /* just to rebreak and refresh correctly.
                                      * The character will not be inserted a
@@ -1632,9 +1623,8 @@ void LyXText::cutSelection(BufferView * bview, bool doclear)
                endpar = endpar->next(); // because of parindents etc.
        }
     
-       setUndo(bview->buffer(), Undo::DELETE,
-               selection.start.par()->previous(),
-               undoendpar);
+       setUndo(bview, Undo::DELETE,
+               selection.start.par(), undoendpar);
     
        // there are two cases: cut only within one paragraph or
        // more than one paragraph
@@ -1705,8 +1695,8 @@ void LyXText::copySelection(BufferView * bview)
                selection.start.pos(selection.start.pos() + 1); 
 
        CutAndPaste::copySelection(selection.start.par(), selection.end.par(),
-                         selection.start.pos(), selection.end.pos(),
-                         bview->buffer()->params.textclass);
+                                  selection.start.pos(), selection.end.pos(),
+                                  bview->buffer()->params.textclass);
 }
 
 
@@ -1716,9 +1706,8 @@ void LyXText::pasteSelection(BufferView * bview)
        if (!CutAndPaste::checkPastePossible(cursor.par()))
                return;
 
-       setUndo(bview->buffer(), Undo::INSERT,
-               cursor.par()->previous(),
-               cursor.par()->next()); 
+       setUndo(bview, Undo::INSERT,
+               cursor.par(), cursor.par()->next()); 
 
        Paragraph * endpar;
        Paragraph * actpar = cursor.par();
@@ -1763,7 +1752,7 @@ void LyXText::setSelectionOverString(BufferView * bview, string const & str)
 void LyXText::replaceSelectionWithString(BufferView * bview,
                                         string const & str)
 {
-       setCursorParUndo(bview->buffer());
+       setCursorParUndo(bview);
        freezeUndo();
 
        if (!selection.set()) { // create a dummy selection
@@ -1797,7 +1786,7 @@ void LyXText::insertStringAsLines(BufferView * bview, string const & str)
        Paragraph::size_type pos = cursor.pos();
        Paragraph * endpar = cursor.par()->next();
        
-       setCursorParUndo(bview->buffer());
+       setCursorParUndo(bview);
        
        bool isEnvironment =
                textclasslist.Style(bview->buffer()->params.textclass, 
@@ -1941,7 +1930,7 @@ void LyXText::checkParagraph(BufferView * bview, Paragraph * par,
                        y -= row->previous()->height();
                        refresh_y = y;
                        refresh_row = row->previous();
-                       status = LyXText::NEED_MORE_REFRESH;
+                       status(bview, LyXText::NEED_MORE_REFRESH);
                        
                        breakAgain(bview, row->previous());
                        
@@ -1961,9 +1950,9 @@ void LyXText::checkParagraph(BufferView * bview, Paragraph * par,
        
        breakAgain(bview, row);
        if (row->height() == tmpheight && rowLast(row) == tmplast)
-               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)
        
        // check the special right address boxes
        if (textclasslist.Style(bview->buffer()->params.textclass,
@@ -2130,9 +2119,15 @@ void LyXText::setCursorIntern(BufferView * bview, Paragraph * par,
                              Paragraph::size_type pos,
                              bool setfont, bool boundary) const
 {
-       setCursor(bview, cursor, par, pos, boundary);
-       if (setfont)
-               setCurrentFont(bview);
+       InsetText * it = static_cast<InsetText *>(par->InInset());
+       if (it && (it != inset_owner)) {
+               it->getLyXText(bview)->setCursorIntern(bview, par, pos, setfont,
+                                                                                          boundary);
+       } else {
+               setCursor(bview, cursor, par, pos, boundary);
+               if (setfont)
+                       setCurrentFont(bview);
+       }
 }
 
 
@@ -2350,7 +2345,7 @@ void LyXText::deleteEmptyParagraphMechanism(BufferView * bview,
                        // ok, we will delete anything
                        
                        // make sure that you do not delete any environments
-                               status = LyXText::NEED_MORE_REFRESH;
+                               status(bview, LyXText::NEED_MORE_REFRESH);
                                deleted = true;
                                
                                if (old_cursor.row()->previous()) {
@@ -2364,8 +2359,8 @@ void LyXText::deleteEmptyParagraphMechanism(BufferView * bview,
                                                        endpar = endpar->next();
                                                }
                                        }
-                                       setUndo(bview->buffer(), Undo::DELETE,
-                                               old_cursor.par()->previous(),
+                                       setUndo(bview, Undo::DELETE,
+                                               old_cursor.par(),
                                                endpar);
                                        cursor = tmpcursor;
 
@@ -2399,8 +2394,8 @@ void LyXText::deleteEmptyParagraphMechanism(BufferView * bview,
                                                        endpar = endpar->next();
                                                }
                                        }
-                                       setUndo(bview->buffer(), Undo::DELETE,
-                                               old_cursor.par()->previous(),
+                                       setUndo(bview, Undo::DELETE,
+                                               old_cursor.par(),
                                                endpar);
                                        cursor = tmpcursor;
 
@@ -2447,297 +2442,20 @@ void LyXText::deleteEmptyParagraphMechanism(BufferView * bview,
 }
 
 
-Paragraph * LyXText::getParFromID(int id)
+Paragraph * LyXText::getParFromID(int id) const
 {
+       if (id < 0)
+               return 0;
        Paragraph * result = firstParagraph();
-       while (result && result->id() != id)
+       Paragraph * ires = 0;
+       while (result && result->id() != id) {
+               if ((ires = result->getParFromID(id)))
+                       return ires;
                result = result->next();
-       return result;
-}
-
-
-// undo functions
-bool LyXText::textUndo(BufferView * bview)
-{
-       if (inset_owner)
-               return false;
-       // returns false if no undo possible
-       Undo * undo = bview->buffer()->undostack.pop();
-       if (undo) {
-               finishUndo();
-               if (!undo_frozen)
-                       bview->buffer()->redostack
-                               .push(createUndo(bview->buffer(), undo->kind, 
-                                                getParFromID(undo->number_of_before_par),
-                                                getParFromID(undo->number_of_behind_par)));
-       }
-       return textHandleUndo(bview, undo);
-}
-
-
-bool LyXText::textRedo(BufferView * bview)
-{
-       if (inset_owner)
-               return false;
-       // returns false if no redo possible
-       Undo * undo = bview->buffer()->redostack.pop();
-       if (undo) {
-               finishUndo();
-               if (!undo_frozen)
-                       bview->buffer()->undostack
-                               .push(createUndo(bview->buffer(), undo->kind, 
-                                                getParFromID(undo->number_of_before_par),
-                                                getParFromID(undo->number_of_behind_par)));
-       }
-       return textHandleUndo(bview, undo);
-}
-
-
-bool LyXText::textHandleUndo(BufferView * bview, Undo * undo)
-{
-       if (inset_owner)
-               return false;
-       // returns false if no undo possible
-       bool result = false;
-       if (undo) {
-               Paragraph * before =
-                       getParFromID(undo->number_of_before_par); 
-               Paragraph * behind =
-                       getParFromID(undo->number_of_behind_par); 
-               Paragraph * tmppar;
-               Paragraph * tmppar2;
-               Paragraph * endpar;
-               Paragraph * tmppar5;
-    
-               // if there's no before take the beginning
-               // of the document for redoing
-               if (!before)
-                       setCursorIntern(bview, firstParagraph(), 0);
-
-               // replace the paragraphs with the undo informations
-
-               Paragraph * tmppar3 = undo->par;
-               undo->par = 0; // otherwise the undo destructor would delete the paragraph
-               Paragraph * tmppar4 = tmppar3;
-
-               if (tmppar4) {
-                       while (tmppar4->next())
-                               tmppar4 = tmppar4->next();
-               } // get last undo par
-    
-               // now remove the old text if there is any
-               if (before != behind || (!behind && !before)) {
-                       if (before)
-                               tmppar5 = before->next();
-                       else
-                               tmppar5 = ownerParagraph();
-                       tmppar2 = tmppar3;
-                       while (tmppar5 && tmppar5 != behind) {
-                               tmppar = tmppar5;
-                               tmppar5 = tmppar5->next();
-                               // a memory optimization for edit: Only layout information
-                               // is stored in the undo. So restore the text informations.
-                               if (undo->kind == Undo::EDIT) {
-                                       tmppar2->setContentsFromPar(tmppar);
-                                       tmppar->clearContents();
-                                       tmppar2 = tmppar2->next();
-                               }
-                       }
-               }
-    
-               // put the new stuff in the list if there is one
-               if (tmppar3){
-                       if (before)
-                               before->next(tmppar3);
-                       else
-                               ownerParagraph(tmppar3);
-                       tmppar3->previous(before);
-               } else {
-                       if (!before)
-                               ownerParagraph(behind);
-               }
-               if (tmppar4) {
-                       tmppar4->next(behind);
-                       if (behind)
-                               behind->previous(tmppar4);
-               }
-    
-    
-               // Set the cursor for redoing
-               if (before) {
-                       setCursorIntern(bview, before, 0);
-               }
-
-               // calculate the endpar for redoing the paragraphs.
-               if (behind) {
-                               endpar = behind->next();
-               } else
-                       endpar = behind;
-    
-               tmppar = getParFromID(undo->number_of_cursor_par);
-               redoParagraphs(bview, cursor, endpar); 
-               if (tmppar){
-                       setCursorIntern(bview, tmppar, undo->cursor_pos);
-                       updateCounters(bview, cursor.row());
-               }
-               result = true;
-               delete undo;
        }
-       finishUndo();
        return result;
 }
 
-
-void LyXText::finishUndo()
-{
-       if (inset_owner)
-               return;
-       // makes sure the next operation will be stored
-       undo_finished = true;
-}
-
-
-void LyXText::freezeUndo()
-{
-       if (inset_owner)
-               return;
-       // this is dangerous and for internal use only
-       undo_frozen = true;
-}
-
-
-void LyXText::unFreezeUndo()
-{
-       if (inset_owner)
-               return;
-       // this is dangerous and for internal use only
-       undo_frozen = false;
-}
-
-
-void LyXText::setUndo(Buffer * buf, Undo::undo_kind kind,
-                     Paragraph const * before,
-                     Paragraph const * behind) const
-{
-       if (inset_owner)
-               return;
-       if (!undo_frozen)
-               buf->undostack.push(createUndo(buf, kind, before, behind));
-       buf->redostack.clear();
-}
-
-
-void LyXText::setRedo(Buffer * buf, Undo::undo_kind kind,
-                     Paragraph const * before, Paragraph const * behind)
-{
-       if (inset_owner)
-               return;
-       buf->redostack.push(createUndo(buf, kind, before, behind));
-}
-
-
-Undo * LyXText::createUndo(Buffer * buf, Undo::undo_kind kind,
-                          Paragraph const * before,
-                          Paragraph const * behind) const
-{
-       if (inset_owner)
-               return 0;
-
-       int before_number = -1;
-       int behind_number = -1;
-       if (before)
-               before_number = before->id();
-       if (behind)
-               behind_number = behind->id();
-       // Undo::EDIT  and Undo::FINISH are
-       // always finished. (no overlapping there)
-       // overlapping only with insert and delete inside one paragraph: 
-       // Nobody wants all removed  character
-       // 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)){
-               // check wether storing is needed
-               if (!buf->undostack.empty() && 
-                   buf->undostack.top()->kind == kind &&
-                   buf->undostack.top()->number_of_before_par ==  before_number &&
-                   buf->undostack.top()->number_of_behind_par ==  behind_number ){
-                       // no undo needed
-                       return 0;
-               }
-       }
-       // create a new Undo
-       Paragraph * undopar;
-
-       Paragraph * start = 0;
-       Paragraph * end = 0;
-
-       if (before)
-               start = const_cast<Paragraph*>(before->next());
-       else
-               start = firstParagraph();
-       if (behind)
-               end = const_cast<Paragraph*>(behind->previous());
-       else {
-               end = firstParagraph();
-               while (end->next())
-                       end = end->next();
-       }
-       if (start && end && (start != end->next()) &&
-           ((before != behind) || (!before && !behind))) {
-               Paragraph * tmppar = start;
-               Paragraph * tmppar2 = new Paragraph(*tmppar);
-               tmppar2->id(tmppar->id());
-               
-               // a memory optimization: Just store the layout information
-               // when only edit
-               if (kind == Undo::EDIT){
-                       //tmppar2->text.clear();
-                       tmppar2->clearContents();
-               }
-
-               undopar = tmppar2;
-  
-               while (tmppar != end && tmppar->next()) {
-                       tmppar = tmppar->next();
-                       tmppar2->next(new Paragraph(*tmppar));
-                       tmppar2->next()->id(tmppar->id());
-                       // a memory optimization: Just store the layout
-                       // information when only edit
-                       if (kind == Undo::EDIT){
-                               //tmppar2->next->text.clear();
-                               tmppar2->clearContents();
-                       }
-                       tmppar2->next()->previous(tmppar2);
-                       tmppar2 = tmppar2->next();
-               }
-               tmppar2->next(0);
-       } else
-               undopar = 0; // nothing to replace (undo of delete maybe)
-
-       int cursor_par = cursor.par()->id();
-       int cursor_pos =  cursor.pos();
-       
-       Undo * undo = new Undo(kind, 
-                              before_number, behind_number,  
-                              cursor_par, cursor_pos, 
-                              undopar);
-  
-       undo_finished = false;
-       return undo;
-}
-
-
-void LyXText::setCursorParUndo(Buffer * buf)
-{
-       if (inset_owner)
-               return;
-       setUndo(buf, Undo::FINISH,
-               cursor.par()->previous(),
-               cursor.par()->next()); 
-}
-
-
 void LyXText::toggleAppendix(BufferView * bview)
 {
        Paragraph * par = cursor.par();
@@ -2751,7 +2469,7 @@ void LyXText::toggleAppendix(BufferView * bview)
        par->params().startOfAppendix(start);
 
        // we can set the refreshing parameters now
-       status = LyXText::NEED_MORE_REFRESH;
+       status(bview, LyXText::NEED_MORE_REFRESH);
        refresh_y = 0;
        refresh_row = 0; // not needed for full update
        updateCounters(bview, 0);
@@ -2762,7 +2480,7 @@ void LyXText::toggleAppendix(BufferView * bview)
 Paragraph * LyXText::ownerParagraph() const
 {
        if (inset_owner)
-               return inset_owner->par;
+               return inset_owner->paragraph();
 
        return bv_owner->buffer()->paragraph;
 }
@@ -2771,8 +2489,40 @@ Paragraph * LyXText::ownerParagraph() const
 Paragraph * LyXText::ownerParagraph(Paragraph * p) const
 {
        if (inset_owner)
-               inset_owner->par = p;
+               inset_owner->paragraph(p);
        else
                bv_owner->buffer()->paragraph = p;
        return 0;
 }
+
+Paragraph * LyXText::ownerParagraph(int id, Paragraph * p) const
+{
+       Paragraph * op = getParFromID(id);
+       if (op && op->InInset()) {
+               static_cast<InsetText *>(op->InInset())->paragraph(p);
+       } else {
+               if (inset_owner)
+                       inset_owner->paragraph(p);
+               else
+                       bv_owner->buffer()->paragraph = p;
+       }
+       return 0;
+}
+
+
+LyXText::text_status LyXText::status() const
+{
+       return status_;
+}
+
+
+void LyXText::status(BufferView * bview, LyXText::text_status st) const
+{
+       if ((status_ != NEED_MORE_REFRESH) ||
+               (status_ == NEED_MORE_REFRESH) && (st != NEED_VERY_LITTLE_REFRESH))
+       {
+               status_ = st;
+               if (inset_owner && st != UNCHANGED)
+                       bview->text->status(bview, NEED_VERY_LITTLE_REFRESH);
+       }
+}
index 5abd368bfbcb368c8ad3f39b51b7f995eace41e8..f2c02285089528ef1d91a2cbe33de79c79a0ff01 100644 (file)
 #include "paragraph.h"
 
 
-Undo::Undo(undo_kind kind_arg,
+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,
           Paragraph * par_arg)
 {
        kind = kind_arg;
+       number_of_inset_id = id_inset_arg;
        number_of_before_par = number_before_arg;
        number_of_behind_par = number_behind_arg;
        number_of_cursor_par = cursor_par_arg;
index 90f344a5ec48ebcb62e469f22938ac24d361768d..e0c4899d9223bed37157ae9ae03087e2e724bdfa 100644 (file)
@@ -41,11 +41,13 @@ public:
        ///
        int number_of_cursor_par;
        ///
+       int number_of_inset_id; // valid if >= 0, if < 0 then not in inset
+       ///
        int cursor_pos; // valid if >= 0
        ///
        Paragraph * par;
        ///
-       Undo(undo_kind kind_arg,
+       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,
             Paragraph * par_arg);
diff --git a/src/undo_funcs.C b/src/undo_funcs.C
new file mode 100644 (file)
index 0000000..d1b0f2a
--- /dev/null
@@ -0,0 +1,347 @@
+/* This file is part of
+ * ====================================================== 
+ * 
+ *           LyX, The Document Processor
+ *        
+ *           Copyright 1995-2001 The LyX Team.
+ *
+ * ====================================================== */
+
+#include <config.h>
+
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include "undo_funcs.h"
+#include "lyxtext.h"
+#include "BufferView.h"
+#include "buffer.h"
+#include "insets/inset.h"
+#include "debug.h"
+
+/// the flag used by FinishUndo();
+bool undo_finished;
+/// a flag
+bool undo_frozen;
+
+bool textUndo(BufferView * bv)
+{
+       // returns false if no undo possible
+       Undo * undo = bv->buffer()->undostack.pop();
+       if (undo) {
+               finishUndo();
+               if (!undo_frozen) {
+                       Paragraph * first = bv->text->getParFromID(undo->number_of_before_par);
+                       if (!first)
+                               first = firstUndoParagraph(bv, undo->number_of_inset_id);
+                       if (first) {
+                               bv->buffer()->redostack.push(
+                                       createUndo(bv, undo->kind, first,
+                                                          bv->text->getParFromID(undo->number_of_behind_par)));
+                       }
+               }
+       }
+       return textHandleUndo(bv, undo);
+}
+
+
+bool textRedo(BufferView * bv)
+{
+       // returns false if no redo possible
+       Undo * undo = bv->buffer()->redostack.pop();
+       if (undo) {
+               finishUndo();
+               if (!undo_frozen) {
+                       Paragraph * first = bv->text->getParFromID(undo->number_of_before_par);
+                       if (!first)
+                               first = firstUndoParagraph(bv, undo->number_of_inset_id);
+                       if (first) {
+                               bv->buffer()->undostack.push(
+                                       createUndo(bv, undo->kind, first,
+                                                  bv->text->getParFromID(undo->number_of_behind_par)));
+                       }
+               }
+       }
+       return textHandleUndo(bv, undo);
+}
+
+
+bool textHandleUndo(BufferView * bv, Undo * undo)
+{
+       // returns false if no undo possible
+       bool result = false;
+       if (undo) {
+               Paragraph * before =
+                       bv->text->getParFromID(undo->number_of_before_par); 
+               Paragraph * behind =
+                       bv->text->getParFromID(undo->number_of_behind_par); 
+               Paragraph * tmppar;
+               Paragraph * tmppar2;
+               Paragraph * endpar;
+               Paragraph * tmppar5;
+
+               // if there's no before take the beginning
+               // of the document for redoing
+               if (!before) {
+                       LyXText * t = bv->text;
+                       int num = undo->number_of_inset_id;
+                       if (undo->number_of_inset_id >= 0) {
+                               Inset * in = bv->buffer()->getInsetFromID(num);
+                               if (in) {
+                                       t = in->getLyXText(bv);
+                               } else {
+                                       num = -1;
+                               }
+                       }
+                       t->setCursorIntern(bv, firstUndoParagraph(bv, num), 0);
+               }
+
+               // replace the paragraphs with the undo informations
+
+               Paragraph * tmppar3 = undo->par;
+               undo->par = 0; // otherwise the undo destructor would delete the paragraph
+               Paragraph * tmppar4 = tmppar3;
+
+               if (tmppar4) {
+                       while (tmppar4->next())
+                               tmppar4 = tmppar4->next();
+               } // get last undo par
+    
+               // now remove the old text if there is any
+               if (before != behind || (!behind && !before)) {
+                       if (before)
+                               tmppar5 = before->next();
+                       else
+                               tmppar5 = firstUndoParagraph(bv, undo->number_of_inset_id);
+                       tmppar2 = tmppar3;
+                       while (tmppar5 && tmppar5 != behind) {
+                               tmppar = tmppar5;
+                               tmppar5 = tmppar5->next();
+                               // a memory optimization for edit: Only layout information
+                               // is stored in the undo. So restore the text informations.
+                               if (undo->kind == Undo::EDIT) {
+                                       tmppar2->setContentsFromPar(tmppar);
+                                       tmppar->clearContents();
+                                       tmppar2 = tmppar2->next();
+                               }
+                       }
+               }
+    
+               // put the new stuff in the list if there is one
+               if (tmppar3){
+                       if (before)
+                               before->next(tmppar3);
+                       else
+                               bv->text->ownerParagraph(tmppar3->id(), tmppar3);
+                       tmppar3->previous(before);
+               } else {
+                       // Do we really enter here ??? (Jug)
+                       if (!before)
+                               bv->text->ownerParagraph(behind);
+               }
+               if (tmppar4) {
+                       tmppar4->next(behind);
+                       if (behind)
+                               behind->previous(tmppar4);
+               }
+    
+    
+               // Set the cursor for redoing
+               if (before) {
+                       bv->text->setCursorIntern(bv, before, 0);
+               }
+
+               // calculate the endpar for redoing the paragraphs.
+               if (behind) {
+                               endpar = behind->next();
+               } else
+                       endpar = behind;
+    
+               tmppar = bv->text->getParFromID(undo->number_of_cursor_par);
+               UpdatableInset* it = static_cast<UpdatableInset*>(tmppar3->InInset());
+               if (it) {
+                       it->getLyXText(bv)->redoParagraphs(bv, it->getLyXText(bv)->cursor,
+                                                          endpar);
+                       if (tmppar){
+                               it->getLyXText(bv)->setCursorIntern(bv, tmppar, undo->cursor_pos);
+                               it->getLyXText(bv)->updateCounters(bv, it->getLyXText(bv)->cursor.row());
+                       }
+#ifdef THIS_DOES_NOT_WORK
+                       // we need this anyway as also if the undo was inside an inset
+                       // we have to redo the paragraph breaking
+                       bv->text->redoParagraphs(bv, bv->text->cursor,
+                                                                        bv->text->cursor.par());
+#endif
+               } else {
+                       bv->text->redoParagraphs(bv, bv->text->cursor, endpar);
+                       if (tmppar) {
+                               bv->text->setCursorIntern(bv, tmppar, undo->cursor_pos);
+                               bv->text->updateCounters(bv, bv->text->cursor.row());
+                       }
+               }
+               result = true;
+               delete undo;
+       }
+       finishUndo();
+       bv->text->status(bv, LyXText::NEED_MORE_REFRESH);
+       return result;
+}
+
+
+void finishUndo()
+{
+       // makes sure the next operation will be stored
+       undo_finished = true;
+}
+
+
+void freezeUndo()
+{
+       // this is dangerous and for internal use only
+       undo_frozen = true;
+}
+
+
+void unFreezeUndo()
+{
+       // this is dangerous and for internal use only
+       undo_frozen = false;
+}
+
+
+void setUndo(BufferView * bv, Undo::undo_kind kind,
+             Paragraph const * first, Paragraph const * behind)
+{
+       if (!undo_frozen)
+               bv->buffer()->undostack.push(createUndo(bv, kind, first, behind));
+       bv->buffer()->redostack.clear();
+}
+
+
+void setRedo(BufferView * bv, Undo::undo_kind kind,
+             Paragraph const * first, Paragraph const * behind)
+{
+       bv->buffer()->redostack.push(createUndo(bv, kind, first, behind));
+}
+
+
+Undo * createUndo(BufferView * bv, Undo::undo_kind kind,
+                  Paragraph const * first, Paragraph const * behind)
+{
+       lyx::Assert(first);
+
+       int before_number = -1;
+       int behind_number = -1;
+       int inset_id = -1;
+
+       if (first->previous())
+               before_number = first->previous()->id();
+       if (behind)
+               behind_number = behind->id();
+       if (first->InInset())
+               inset_id = first->InInset()->id();
+
+       // Undo::EDIT  and Undo::FINISH are
+       // always finished. (no overlapping there)
+       // overlapping only with insert and delete inside one paragraph: 
+       // Nobody wants all removed  character
+       // 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)){
+               // check wether storing is needed
+               if (!bv->buffer()->undostack.empty() && 
+                   bv->buffer()->undostack.top()->kind == kind &&
+                   bv->buffer()->undostack.top()->number_of_before_par ==  before_number &&
+                   bv->buffer()->undostack.top()->number_of_behind_par ==  behind_number ){
+                       // no undo needed
+                       return 0;
+               }
+       }
+       // create a new Undo
+       Paragraph * undopar;
+
+       Paragraph * start = const_cast<Paragraph *>(first);
+       Paragraph * end = 0;
+
+#if 0
+       if (first)
+               start = const_cast<Paragraph*>(before->next());
+       else
+               start = firstUndoParagraph(bv);
+#endif
+       if (behind)
+               end = const_cast<Paragraph*>(behind->previous());
+       else {
+               end = start;
+               while (end->next())
+                       end = end->next();
+       }
+       if (start && end && (start != end->next()) &&
+           ((before_number != behind_number) ||
+                ((before_number < 0) && (behind_number < 0)))) {
+               Paragraph * tmppar = start;
+               Paragraph * tmppar2 = new Paragraph(*tmppar, true);
+               tmppar2->id(tmppar->id());
+               
+               // a memory optimization: Just store the layout information
+               // when only edit
+               if (kind == Undo::EDIT) {
+                       tmppar2->clearContents();
+               }
+
+               undopar = tmppar2;
+  
+               while (tmppar != end && tmppar->next()) {
+                       tmppar = tmppar->next();
+                       tmppar2->next(new Paragraph(*tmppar));
+                       tmppar2->next()->id(tmppar->id());
+                       // a memory optimization: Just store the layout
+                       // information when only edit
+                       if (kind == Undo::EDIT) {
+                               tmppar2->clearContents();
+                       }
+                       tmppar2->next()->previous(tmppar2);
+                       tmppar2 = tmppar2->next();
+               }
+               tmppar2->next(0);
+       } else
+               undopar = 0; // nothing to replace (undo of delete maybe)
+
+       int cursor_par = undoCursor(bv).par()->id();
+       int cursor_pos =  undoCursor(bv).pos();
+       
+       Undo * undo = new Undo(kind, inset_id,
+                              before_number, behind_number,  
+                              cursor_par, cursor_pos, undopar);
+  
+       undo_finished = false;
+       return undo;
+}
+
+
+void setCursorParUndo(BufferView * bv)
+{
+       setUndo(bv, Undo::FINISH,
+               bv->text->cursor.par(),
+                       bv->text->cursor.par()->next());
+}
+
+Paragraph * firstUndoParagraph(BufferView * bv, int inset_id)
+{
+       Inset * inset = bv->buffer()->getInsetFromID(inset_id);
+       if (inset) {
+               Paragraph * result = inset->firstParagraph();
+               if (result)
+                       return result;
+       }
+       return bv->text->ownerParagraph();
+}
+
+LyXCursor const & undoCursor(BufferView * bv)
+{
+       if (bv->theLockingInset())
+               return bv->theLockingInset()->cursor(bv);
+       return bv->text->cursor;
+}
diff --git a/src/undo_funcs.h b/src/undo_funcs.h
new file mode 100644 (file)
index 0000000..0339bbc
--- /dev/null
@@ -0,0 +1,61 @@
+// -*- C++ -*-
+/* This file is part of
+ * ====================================================== 
+ * 
+ *           LyX, The Document Processor
+ *        
+ *           Copyright 1995-2001 The LyX Team.
+ *
+ * ====================================================== */
+
+#ifndef UNDO_FUNCS_H
+#define UNDO_FUNCS_H
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include "undo.h"
+
+class BufferView;
+class Paragraph;
+class LyXCursor;
+
+/// returns false if no undo possible
+extern bool textUndo(BufferView *);
+/// returns false if no redo possible
+extern bool textRedo(BufferView *);
+/// used by TextUndo/TextRedo
+extern bool textHandleUndo(BufferView *, Undo * undo);
+/// makes sure the next operation will be stored
+extern void finishUndo();
+/// this is dangerous and for internal use only
+extern void freezeUndo();
+/// this is dangerous and for internal use only
+extern void unFreezeUndo();
+///
+extern void setUndo(BufferView *, Undo::undo_kind kind, 
+                    Paragraph const * first, Paragraph const * behind);
+///
+extern void setRedo(BufferView *, Undo::undo_kind kind,
+                    Paragraph const * first, Paragraph const * behind);
+///
+extern Undo * createUndo(BufferView *, Undo::undo_kind kind,
+                         Paragraph const * first, Paragraph const * behind);
+/// for external use in lyx_cb.C
+extern void setCursorParUndo(BufferView *);
+
+// 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.
+extern Paragraph * firstUndoParagraph(BufferView *, int inset_arg);
+
+///
+extern LyXCursor const & undoCursor(BufferView * bv);
+
+/// the flag used by FinishUndo();
+extern bool undo_finished;
+/// a flag
+extern bool undo_frozen;
+
+#endif