From 7521b5d20f42102cf444e3fd8718a088a60d0098 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Vigna?= Date: Fri, 6 Jul 2001 15:57:54 +0000 Subject: [PATCH] The BIG UNDO patch. Recodes undo handling for better use inside InsetText. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2195 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView2.C | 15 +- src/BufferView_pimpl.C | 77 +++--- src/ChangeLog | 30 +++ src/Makefile.am | 2 + src/buffer.C | 21 +- src/buffer.h | 10 + src/figureForm.C | 7 +- src/insets/ChangeLog | 15 ++ src/insets/figinset.C | 2 +- src/insets/figinset.h | 2 +- src/insets/inset.C | 20 ++ src/insets/inset.h | 32 ++- src/insets/insetbib.C | 4 +- src/insets/insetbib.h | 10 +- src/insets/insetcite.C | 2 +- src/insets/insetcite.h | 6 +- src/insets/insetcollapsable.C | 24 +- src/insets/insetcollapsable.h | 10 + src/insets/insetcommand.C | 5 +- src/insets/insetcommand.h | 2 +- src/insets/inseterror.C | 2 +- src/insets/inseterror.h | 6 +- src/insets/insetert.C | 10 +- src/insets/insetert.h | 2 +- src/insets/insetexternal.C | 4 +- src/insets/insetexternal.h | 2 +- src/insets/insetfloat.C | 6 +- src/insets/insetfloat.h | 2 +- src/insets/insetfloatlist.h | 2 +- src/insets/insetfoot.C | 6 +- src/insets/insetfoot.h | 2 +- src/insets/insetgraphics.C | 5 +- src/insets/insetgraphics.h | 2 +- src/insets/insetinclude.C | 2 +- src/insets/insetinclude.h | 2 +- src/insets/insetindex.C | 4 +- src/insets/insetindex.h | 12 +- src/insets/insetinfo.C | 2 +- src/insets/insetinfo.h | 2 +- src/insets/insetlabel.C | 2 +- src/insets/insetlabel.h | 6 +- src/insets/insetlatexaccent.C | 2 +- src/insets/insetlatexaccent.h | 2 +- src/insets/insetlist.C | 6 +- src/insets/insetlist.h | 2 +- src/insets/insetmarginal.C | 6 +- src/insets/insetmarginal.h | 2 +- src/insets/insetminipage.C | 6 +- src/insets/insetminipage.h | 2 +- src/insets/insetparent.C | 2 +- src/insets/insetparent.h | 6 +- src/insets/insetquotes.C | 2 +- src/insets/insetquotes.h | 2 +- src/insets/insetref.C | 2 +- src/insets/insetref.h | 6 +- src/insets/insetspecialchar.C | 2 +- src/insets/insetspecialchar.h | 2 +- src/insets/insettabular.C | 186 +++++++++------ src/insets/insettabular.h | 15 +- src/insets/insettext.C | 247 +++++++++++++------- src/insets/insettext.h | 27 ++- src/insets/insettheorem.C | 3 +- src/insets/insettheorem.h | 2 +- src/insets/insettoc.h | 7 +- src/insets/inseturl.C | 2 +- src/insets/inseturl.h | 6 +- src/lyxfunc.C | 18 +- src/lyxtext.h | 61 ++--- src/mathed/formula.C | 2 +- src/mathed/formula.h | 2 +- src/mathed/formulabase.C | 3 +- src/mathed/formulabase.h | 2 +- src/mathed/formulamacro.C | 2 +- src/mathed/formulamacro.h | 2 +- src/paragraph.C | 18 +- src/paragraph.h | 7 +- src/paragraph_pimpl.C | 20 +- src/paragraph_pimpl.h | 4 +- src/screen.C | 22 +- src/tabular.C | 8 +- src/text.C | 62 +++-- src/text2.C | 428 +++++++--------------------------- src/undo.C | 3 +- src/undo.h | 4 +- src/undo_funcs.C | 347 +++++++++++++++++++++++++++ src/undo_funcs.h | 61 +++++ 86 files changed, 1247 insertions(+), 755 deletions(-) create mode 100644 src/undo_funcs.C create mode 100644 src/undo_funcs.h diff --git a/src/BufferView2.C b/src/BufferView2.C index 4c08feb2de..d6f99fcef7 100644 --- a/src/BufferView2.C +++ b/src/BufferView2.C @@ -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()); } diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index e63c903df7..b15dd9ad75 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -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; } diff --git a/src/ChangeLog b/src/ChangeLog index 5e5087f990..3d626b1438 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,33 @@ +2001-07-06 Juergen Vigna + + * 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 + + * 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 * BufferView_pimpl.C (resizeCurrentBuffer): init the new LyXText diff --git a/src/Makefile.am b/src/Makefile.am index c32b9a9896..13eed40c4a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 \ diff --git a/src/buffer.C b/src/buffer.C index e0c1fb8124..8a0d18603b 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -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; +} diff --git a/src/buffer.h b/src/buffer.h index ae9cbb0ce2..47d94282ea 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -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; }; diff --git a/src/figureForm.C b/src/figureForm.C index 3721def9bf..e572f31351 100644 --- a/src/figureForm.C +++ b/src/figureForm.C @@ -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(); } diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 7e16bda48d..558189bbd4 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,13 @@ +2001-07-06 Juergen Vigna + + * 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 * insettext.[hC]: make cached_text a shared_ptr, make Cache be a map @@ -66,6 +76,11 @@ * inseturl.C: fix method names in these to begin with small char too, so they inherit +2001-06-28 Juergen Vigna + + * insettext.C (setFont): fixed font settings using toggleFree() + instead of setFont(). + 2001-06-28 Lars Gullik Bjønnes * Change a lot of method names to begin with a small char. diff --git a/src/insets/figinset.C b/src/insets/figinset.C index f2d17b3b85..f8c81fc2a9 100644 --- a/src/insets/figinset.C +++ b/src/insets/figinset.C @@ -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); diff --git a/src/insets/figinset.h b/src/insets/figinset.h index 3deaf532dc..daef7707de 100644 --- a/src/insets/figinset.h +++ b/src/insets/figinset.h @@ -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); /// diff --git a/src/insets/inset.C b/src/insets/inset.C index 23bdff5354..dc8163dd03 100644 --- a/src/insets/inset.C +++ b/src/insets/inset.C @@ -23,11 +23,16 @@ #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; +} diff --git a/src/insets/inset.h b/src/insets/inset.h index 9bc531b8c7..3e6f7cdc23 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -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_; diff --git a/src/insets/insetbib.C b/src/insets/insetbib.C index 70849d11db..c1b2226d2e 100644 --- a/src/insets/insetbib.C +++ b/src/insets/insetbib.C @@ -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) {} diff --git a/src/insets/insetbib.h b/src/insets/insetbib.h index e5d5c9d562..4dbd137305 100644 --- a/src/insets/insetbib.h +++ b/src/insets/insetbib.h @@ -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; diff --git a/src/insets/insetcite.C b/src/insets/insetcite.C index 321141a4b6..354cc56284 100644 --- a/src/insets/insetcite.C +++ b/src/insets/insetcite.C @@ -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) {} diff --git a/src/insets/insetcite.h b/src/insets/insetcite.h index 9c5c8671b5..2ff0dfa753 100644 --- a/src/insets/insetcite.h +++ b/src/insets/insetcite.h @@ -22,10 +22,10 @@ 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; diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 9bd46db48a..8f58e1435e 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -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(this); + return inset.getInsetFromID(id_arg); +} diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index 1bf9e5a57a..a0e24f8aa4 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -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: /// diff --git a/src/insets/insetcommand.C b/src/insets/insetcommand.C index 3a05f45556..0c89324088 100644 --- a/src/insets/insetcommand.C +++ b/src/insets/insetcommand.C @@ -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 ) diff --git a/src/insets/insetcommand.h b/src/insets/insetcommand.h index 7095f9c783..6dd6ad05da 100644 --- a/src/insets/insetcommand.h +++ b/src/insets/insetcommand.h @@ -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(); } /// diff --git a/src/insets/inseterror.C b/src/insets/inseterror.C index 43ceb17842..adeec9280f 100644 --- a/src/insets/inseterror.C +++ b/src/insets/inseterror.C @@ -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) {} diff --git a/src/insets/inseterror.h b/src/insets/inseterror.h index 95cd3ee1cb..62f146a687 100644 --- a/src/insets/inseterror.h +++ b/src/insets/inseterror.h @@ -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 diff --git a/src/insets/insetert.C b/src/insets/insetert.C index 5aefa67161..2cc6e304f2 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -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; } diff --git a/src/insets/insetert.h b/src/insets/insetert.h index 4d6c550af8..eddcd292c7 100644 --- a/src/insets/insetert.h +++ b/src/insets/insetert.h @@ -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; /// diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index 172f9b6418..8eaa064280 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -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; } diff --git a/src/insets/insetexternal.h b/src/insets/insetexternal.h index dc68effa30..2bc0a2a152 100644 --- a/src/insets/insetexternal.h +++ b/src/insets/insetexternal.h @@ -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; diff --git a/src/insets/insetfloat.C b/src/insets/insetfloat.C index 3e822ce0bd..5942f6b90d 100644 --- a/src/insets/insetfloat.C +++ b/src/insets/insetfloat.C @@ -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; } diff --git a/src/insets/insetfloat.h b/src/insets/insetfloat.h index ee0396d6fb..4668c68f14 100644 --- a/src/insets/insetfloat.h +++ b/src/insets/insetfloat.h @@ -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; } /// diff --git a/src/insets/insetfloatlist.h b/src/insets/insetfloatlist.h index 19e7d4b7aa..132a1b8494 100644 --- a/src/insets/insetfloatlist.h +++ b/src/insets/insetfloatlist.h @@ -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); } /// diff --git a/src/insets/insetfoot.C b/src/insets/insetfoot.C index b3b39f9171..926176e66b 100644 --- a/src/insets/insetfoot.C +++ b/src/insets/insetfoot.C @@ -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; } diff --git a/src/insets/insetfoot.h b/src/insets/insetfoot.h index 5892ec07e2..2495ebb67f 100644 --- a/src/insets/insetfoot.h +++ b/src/insets/insetfoot.h @@ -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; } /// diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index 4f5c82d049..ef7b1fac4c 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -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; diff --git a/src/insets/insetgraphics.h b/src/insets/insetgraphics.h index 042b8941a9..aa9dc9d6cf 100644 --- a/src/insets/insetgraphics.h +++ b/src/insets/insetgraphics.h @@ -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. diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index 01cd2530ba..3e66d587a2 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -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(); diff --git a/src/insets/insetinclude.h b/src/insets/insetinclude.h index 2a21c2976e..45257ad1eb 100644 --- a/src/insets/insetinclude.h +++ b/src/insets/insetinclude.h @@ -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 diff --git a/src/insets/insetindex.C b/src/insets/insetindex.C index 18d79e5551..a15c1e23e9 100644 --- a/src/insets/insetindex.C +++ b/src/insets/insetindex.C @@ -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) {} diff --git a/src/insets/insetindex.h b/src/insets/insetindex.h index 598ae99f3c..211043d945 100644 --- a/src/insets/insetindex.h +++ b/src/insets/insetindex.h @@ -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; diff --git a/src/insets/insetinfo.C b/src/insets/insetinfo.C index 0aabb9b22e..3afe9297c7 100644 --- a/src/insets/insetinfo.C +++ b/src/insets/insetinfo.C @@ -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); } diff --git a/src/insets/insetinfo.h b/src/insets/insetinfo.h index cbc7a01362..3128ef4c06 100644 --- a/src/insets/insetinfo.h +++ b/src/insets/insetinfo.h @@ -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: diff --git a/src/insets/insetlabel.C b/src/insets/insetlabel.C index cb1cc921fb..026721a0d7 100644 --- a/src/insets/insetlabel.C +++ b/src/insets/insetlabel.C @@ -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) {} diff --git a/src/insets/insetlabel.h b/src/insets/insetlabel.h index acdce96470..b4080df3a6 100644 --- a/src/insets/insetlabel.h +++ b/src/insets/insetlabel.h @@ -21,10 +21,10 @@ 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(); } diff --git a/src/insets/insetlatexaccent.C b/src/insets/insetlatexaccent.C index 555cdd8925..ccd8401ebf 100644 --- a/src/insets/insetlatexaccent.C +++ b/src/insets/insetlatexaccent.C @@ -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); } diff --git a/src/insets/insetlatexaccent.h b/src/insets/insetlatexaccent.h index 52fbc8fe75..6c184514c5 100644 --- a/src/insets/insetlatexaccent.h +++ b/src/insets/insetlatexaccent.h @@ -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; /// diff --git a/src/insets/insetlist.C b/src/insets/insetlist.C index 23f9f15318..d577c185ed 100644 --- a/src/insets/insetlist.C +++ b/src/insets/insetlist.C @@ -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; } diff --git a/src/insets/insetlist.h b/src/insets/insetlist.h index 6a67e20ee3..a5ea1f727d 100644 --- a/src/insets/insetlist.h +++ b/src/insets/insetlist.h @@ -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; } /// diff --git a/src/insets/insetmarginal.C b/src/insets/insetmarginal.C index a92dd47018..b4aa735602 100644 --- a/src/insets/insetmarginal.C +++ b/src/insets/insetmarginal.C @@ -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; } diff --git a/src/insets/insetmarginal.h b/src/insets/insetmarginal.h index 7f1e5b86c6..26654106a6 100644 --- a/src/insets/insetmarginal.h +++ b/src/insets/insetmarginal.h @@ -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; } /// diff --git a/src/insets/insetminipage.C b/src/insets/insetminipage.C index 10ac8dcb28..372c7bcef3 100644 --- a/src/insets/insetminipage.C +++ b/src/insets/insetminipage.C @@ -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; } diff --git a/src/insets/insetminipage.h b/src/insets/insetminipage.h index 11139b4d00..fb6a72220d 100644 --- a/src/insets/insetminipage.h +++ b/src/insets/insetminipage.h @@ -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; /// diff --git a/src/insets/insetparent.C b/src/insets/insetparent.C index feec44cd7f..d63c783a5e 100644 --- a/src/insets/insetparent.C +++ b/src/insets/insetparent.C @@ -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(); diff --git a/src/insets/insetparent.h b/src/insets/insetparent.h index 3f348a51de..5ae366e530 100644 --- a/src/insets/insetparent.h +++ b/src/insets/insetparent.h @@ -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; diff --git a/src/insets/insetquotes.C b/src/insets/insetquotes.C index 249df27754..2f917efe20 100644 --- a/src/insets/insetquotes.C +++ b/src/insets/insetquotes.C @@ -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); } diff --git a/src/insets/insetquotes.h b/src/insets/insetquotes.h index 7011656e14..b4b953d59c 100644 --- a/src/insets/insetquotes.h +++ b/src/insets/insetquotes.h @@ -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: diff --git a/src/insets/insetref.C b/src/insets/insetref.C index 0a0e40f0e8..1e9cf3ceee 100644 --- a/src/insets/insetref.C +++ b/src/insets/insetref.C @@ -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()) {} diff --git a/src/insets/insetref.h b/src/insets/insetref.h index 56a20ff3e8..2a60b2a655 100644 --- a/src/insets/insetref.h +++ b/src/insets/insetref.h @@ -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; diff --git a/src/insets/insetspecialchar.C b/src/insets/insetspecialchar.C index a94e33e425..5c17d9e95a 100644 --- a/src/insets/insetspecialchar.C +++ b/src/insets/insetspecialchar.C @@ -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); } diff --git a/src/insets/insetspecialchar.h b/src/insets/insetspecialchar.h index 05fb3ecf38..3e08623c70 100644 --- a/src/insets/insetspecialchar.h +++ b/src/insets/insetspecialchar.h @@ -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 { diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index d79dfc531e..95699d7a93 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -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(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; +} diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index 1cbc9f8c6d..b3c3c9f45e 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -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; /// diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 637ae9a041..58af552d64 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -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(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; +} diff --git a/src/insets/insettext.h b/src/insets/insettext.h index ff0d757e7e..1300c1bf31 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -21,6 +21,8 @@ #include "inset.h" #include "LString.h" +#include "LColor.h" +#include "paragraph.h" #include "lyxcursor.h" #include @@ -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; diff --git a/src/insets/insettheorem.C b/src/insets/insettheorem.C index 1f4068773d..fa46fcb392 100644 --- a/src/insets/insettheorem.C +++ b/src/insets/insettheorem.C @@ -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; diff --git a/src/insets/insettheorem.h b/src/insets/insettheorem.h index c81e54f036..22e2edfe0a 100644 --- a/src/insets/insettheorem.h +++ b/src/insets/insettheorem.h @@ -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; } /// diff --git a/src/insets/insettoc.h b/src/insets/insettoc.h index 9be3b6bdd8..01766e77eb 100644 --- a/src/insets/insettoc.h +++ b/src/insets/insettoc.h @@ -23,10 +23,11 @@ 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; diff --git a/src/insets/inseturl.C b/src/insets/inseturl.C index 0f51583463..e3758cb2ef 100644 --- a/src/insets/inseturl.C +++ b/src/insets/inseturl.C @@ -15,7 +15,7 @@ using std::ostream; -InsetUrl::InsetUrl(InsetCommandParams const & p) +InsetUrl::InsetUrl(InsetCommandParams const & p, bool) : InsetCommand(p) {} diff --git a/src/insets/inseturl.h b/src/insets/inseturl.h index a93367b5dc..095c71143f 100644 --- a/src/insets/inseturl.h +++ b/src/insets/inseturl.h @@ -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; } diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 7140be709d..b4a1af2178 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -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( @@ -723,8 +731,12 @@ string const LyXFunc::Dispatch(int ac, } else { inset = 0; } +#else + inset = static_cast(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 ??? diff --git a/src/lyxtext.h b/src/lyxtext.h index 144e71ed15..deeb79729d 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -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; }; diff --git a/src/mathed/formula.C b/src/mathed/formula.C index 65fe6aefab..4508d4dd9b 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -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); } diff --git a/src/mathed/formula.h b/src/mathed/formula.h index eb629c90e1..d73fd375b8 100644 --- a/src/mathed/formula.h +++ b/src/mathed/formula.h @@ -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; /// diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index 6c3f0b18da..f78222340d 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -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; diff --git a/src/mathed/formulabase.h b/src/mathed/formulabase.h index a3354867aa..be8e5ce689 100644 --- a/src/mathed/formulabase.h +++ b/src/mathed/formulabase.h @@ -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; /// diff --git a/src/mathed/formulamacro.C b/src/mathed/formulamacro.C index d0de1d9ee8..fbbfd72002 100644 --- a/src/mathed/formulamacro.C +++ b/src/mathed/formulamacro.C @@ -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); } diff --git a/src/mathed/formulamacro.h b/src/mathed/formulamacro.h index 8243e2a777..204ddaffe4 100644 --- a/src/mathed/formulamacro.h +++ b/src/mathed/formulamacro.h @@ -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; /// diff --git a/src/paragraph.C b/src/paragraph.C index 5b0989c6b6..c6553fdc39 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -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); +} diff --git a/src/paragraph.h b/src/paragraph.h index 8c6abcbf33..8d014b08b4 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -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); diff --git a/src/paragraph_pimpl.C b/src/paragraph_pimpl.C index 37f71b1569..74115b13f7 100644 --- a/src/paragraph_pimpl.C +++ b/src/paragraph_pimpl.C @@ -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; +} + diff --git a/src/paragraph_pimpl.h b/src/paragraph_pimpl.h index bda3bc960d..628f20d5e9 100644 --- a/src/paragraph_pimpl.h +++ b/src/paragraph_pimpl.h @@ -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; diff --git a/src/screen.C b/src/screen.C index bd802911a8..d09e3d42ed 100644 --- a/src/screen.C +++ b/src/screen.C @@ -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(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()); } diff --git a/src/tabular.C b/src/tabular.C index 99e7816168..86091c6e36 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -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 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) { diff --git a/src/text.C b/src/text.C index 5f69db7ed7..8d43f09089 100644 --- a/src/text.C +++ b/src/text.C @@ -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()); diff --git a/src/text2.C b/src/text2.C index 4793569831..7121831aac 100644 --- a/src/text2.C +++ b/src/text2.C @@ -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(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(before->next()); - else - start = firstParagraph(); - if (behind) - end = const_cast(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(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); + } +} diff --git a/src/undo.C b/src/undo.C index 5abd368bfb..f2c0228508 100644 --- a/src/undo.C +++ b/src/undo.C @@ -18,12 +18,13 @@ #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; diff --git a/src/undo.h b/src/undo.h index 90f344a5ec..e0c4899d92 100644 --- a/src/undo.h +++ b/src/undo.h @@ -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 index 0000000000..d1b0f2ab48 --- /dev/null +++ b/src/undo_funcs.C @@ -0,0 +1,347 @@ +/* This file is part of + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright 1995-2001 The LyX Team. + * + * ====================================================== */ + +#include + +#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(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(first); + Paragraph * end = 0; + +#if 0 + if (first) + start = const_cast(before->next()); + else + start = firstUndoParagraph(bv); +#endif + if (behind) + end = const_cast(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 index 0000000000..0339bbc5f1 --- /dev/null +++ b/src/undo_funcs.h @@ -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 -- 2.39.2