]> git.lyx.org Git - lyx.git/commitdiff
Part of IU.
authorAndré Pönitz <poenitz@gmx.net>
Tue, 20 Jan 2004 14:25:24 +0000 (14:25 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Tue, 20 Jan 2004 14:25:24 +0000 (14:25 +0000)
####################################################################

          1.4.0cvs is now NOT fit for any serious use

####################################################################

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8363 a592a061-630c-0410-9148-cb99ea01b6c8

94 files changed:
src/BufferView.C
src/BufferView.h
src/BufferView_pimpl.C
src/ChangeLog
src/PosIterator.C
src/bufferview_funcs.C
src/cursor.C
src/cursor.h
src/cursor_slice.C
src/cursor_slice.h
src/factory.C
src/frontends/LyXView.C
src/frontends/screen.C
src/insets/ChangeLog
src/insets/inset.h
src/insets/insetbase.C
src/insets/insetbase.h
src/insets/insetbibitem.C
src/insets/insetbibitem.h
src/insets/insetbibtex.C
src/insets/insetbibtex.h
src/insets/insetbox.C
src/insets/insetbox.h
src/insets/insetbranch.C
src/insets/insetbranch.h
src/insets/insetcharstyle.C
src/insets/insetcharstyle.h
src/insets/insetcollapsable.C
src/insets/insetcollapsable.h
src/insets/insetcommand.C
src/insets/insetcommand.h
src/insets/insetert.C
src/insets/insetert.h
src/insets/insetexternal.C
src/insets/insetexternal.h
src/insets/insetfloat.C
src/insets/insetfloat.h
src/insets/insetgraphics.C
src/insets/insetgraphics.h
src/insets/insetinclude.C
src/insets/insetinclude.h
src/insets/insetlabel.C
src/insets/insetlabel.h
src/insets/insetnote.C
src/insets/insetnote.h
src/insets/insetref.C
src/insets/insetref.h
src/insets/insettabular.C
src/insets/insettabular.h
src/insets/insettext.C
src/insets/insettext.h
src/insets/insetvspace.C
src/insets/insetvspace.h
src/insets/insetwrap.C
src/insets/insetwrap.h
src/insets/updatableinset.C
src/insets/updatableinset.h
src/iterators.C
src/lyx_cb.C
src/lyxfind.C
src/lyxfunc.C
src/lyxtext.h
src/mathed/ChangeLog
src/mathed/command_inset.C
src/mathed/command_inset.h
src/mathed/formula.C
src/mathed/formula.h
src/mathed/formulabase.C
src/mathed/formulabase.h
src/mathed/formulamacro.C
src/mathed/math_cursor.C
src/mathed/math_cursor.h
src/mathed/math_fracbase.C
src/mathed/math_gridinset.C
src/mathed/math_gridinset.h
src/mathed/math_hullinset.C
src/mathed/math_hullinset.h
src/mathed/math_inset.h
src/mathed/math_macro.C
src/mathed/math_nestinset.C
src/mathed/math_nestinset.h
src/mathed/math_oversetinset.C
src/mathed/math_rootinset.C
src/mathed/math_scriptinset.C
src/mathed/math_scriptinset.h
src/mathed/math_undersetinset.C
src/mathed/ref_inset.C
src/mathed/ref_inset.h
src/rowpainter.C
src/text.C
src/text2.C
src/text3.C
src/undo.C
src/undo.h

index ecfdd5543b694ae3536646924094e2c4c9d61548..ef6194388fe4891b9d38cfc6e11881667a14caf5 100644 (file)
@@ -58,8 +58,7 @@ extern BufferList bufferlist;
 
 BufferView::BufferView(LyXView * owner, int xpos, int ypos,
                       int width, int height)
-       : pimpl_(new Pimpl(*this, owner, xpos, ypos, width, height)),
-         x_target_(0)
+       : pimpl_(new Pimpl(*this, owner, xpos, ypos, width, height))
 {}
 
 
@@ -260,7 +259,7 @@ bool BufferView::insertLyXFile(string const & filen)
 
        string const fname = MakeAbsPath(filen);
 
-       clearSelection();
+       cursor().clearSelection();
        text()->breakParagraph(buffer()->paragraphs());
 
        bool res = buffer()->readFile(fname, text()->cursorPar());
@@ -313,11 +312,11 @@ void BufferView::gotoLabel(string const & label)
                vector<string> labels;
                it->getLabelList(*buffer(), labels);
                if (find(labels.begin(),labels.end(),label) != labels.end()) {
-                       clearSelection();
+                       cursor().clearSelection();
                        text()->setCursor(
                                std::distance(text()->paragraphs().begin(), it.getPar()),
                                it.getPos());
-                       resetAnchor();
+                       cursor().resetAnchor();
                        update();
                        return;
                }
@@ -331,7 +330,7 @@ void BufferView::undo()
                return;
 
        owner()->message(_("Undo"));
-       clearSelection();
+       cursor().clearSelection();
        if (!textUndo(this))
                owner()->message(_("No further undo information"));
        update();
@@ -345,7 +344,7 @@ void BufferView::redo()
                return;
 
        owner()->message(_("Redo"));
-       clearSelection();
+       cursor().clearSelection();
        if (!textRedo(this))
                owner()->message(_("No further redo information"));
        update();
@@ -392,15 +391,9 @@ bool BufferView::ChangeRefsIfUnique(string const & from, string const & to)
 }
 
 
-UpdatableInset * BufferView::innerInset() const
-{
-       return static_cast<UpdatableInset*>(fullCursor().innerInset());
-}
-
-
 LyXText * BufferView::getLyXText() const
 {
-       return fullCursor().innerText();
+       return cursor().innerText();
 }
 
 
@@ -437,72 +430,6 @@ int BufferView::workHeight() const
 }
 
 
-void BufferView::fullCursor(LCursor const & cur)
-{
-       pimpl_->cursor_ = cur;
-}
-
-
-LCursor & BufferView::fullCursor()
-{
-       return pimpl_->cursor_;
-}
-
-
-LCursor const & BufferView::fullCursor() const
-{
-       return pimpl_->cursor_;
-}
-
-
-CursorSlice & BufferView::cursor()
-{
-       return fullCursor().cursor_.back();
-}
-
-
-CursorSlice const & BufferView::cursor() const
-{
-       return fullCursor().cursor_.back();
-}
-
-
-CursorSlice & BufferView::anchor()
-{
-       return fullCursor().anchor_.back();
-}
-
-
-CursorSlice const & BufferView::anchor() const
-{
-       return fullCursor().anchor_.back();
-}
-
-
-Selection & BufferView::selection()
-{
-       return selection_;
-}
-
-
-Selection const & BufferView::selection() const
-{
-       return selection_;
-}
-
-
-void BufferView::x_target(int x)
-{
-       x_target_ = x;
-}
-
-
-int BufferView::x_target() const
-{
-       return x_target_;
-}
-
-
 void BufferView::updateParagraphDialog()
 {
        pimpl_->updateParagraphDialog();
@@ -515,62 +442,6 @@ LyXText * BufferView::text() const
 }
 
 
-void BufferView::resetAnchor()
-{
-       return fullCursor().resetAnchor();
-}
-
-
-CursorSlice const & BufferView::selStart() const
-{
-       if (!selection().set())
-               return cursor();
-       // can't use std::min as this creates a new object
-       return anchor() < cursor() ? anchor() : cursor();
-}
-
-
-CursorSlice const & BufferView::selEnd() const
-{
-       if (!selection().set())
-               return cursor();
-       return anchor() > cursor() ? anchor() : cursor();
-}
-
-
-CursorSlice & BufferView::selStart()
-{
-       if (!selection().set())
-               return cursor();
-       return anchor() < cursor() ? anchor() : cursor();
-}
-
-
-CursorSlice & BufferView::selEnd()
-{
-       if (selection().set())
-               return cursor();
-       return anchor() > cursor() ? anchor() : cursor();
-}
-
-
-void BufferView::setSelection()
-{
-       selection().set(true);
-       // a selection with no contents is not a selection
-       if (cursor().par() == anchor().par() && cursor().pos() == anchor().pos())
-               selection().set(false);
-}
-
-
-void BufferView::clearSelection()
-{
-       selection().set(false);
-       selection().mark(false);
-       resetAnchor();
-       unsetXSel();
-}
-
 
 
 /*
@@ -592,7 +463,7 @@ void BufferView::putSelectionAt(PosIterator const & cur,
 {
        ParIterator par(cur);
        
-       clearSelection();
+       cursor().clearSelection();
 
        LyXText * text = par.text(*buffer());
        par.lockPath(this);
@@ -601,13 +472,13 @@ void BufferView::putSelectionAt(PosIterator const & cur,
                top_y(par.outerPar()->y);
        update();
        text->setCursor(cur.pit(), cur.pos());
-       fullCursor().updatePos();
+       cursor().updatePos();
 
        if (length) {
                text->setSelectionRange(length);
-               setSelection();
+               cursor().setSelection();
                if (backwards)
-                       std::swap(cursor(), anchor());
+                       std::swap(cursor().cursor_, cursor().anchor_);
        }
 
        fitCursor();
@@ -615,7 +486,14 @@ void BufferView::putSelectionAt(PosIterator const & cur,
 }
 
 
-CursorSlice & cursorTip(BufferView & bv)
+LCursor & BufferView::cursor()
+{
+       return pimpl_->cursor_;
+}
+
+
+LCursor const & BufferView::cursor() const
 {
-       return bv.cursor();
+       return pimpl_->cursor_;
 }
+
index a48fab0c842588b614c38370fd25d38c6f4053b7..eeae02b2451048806185c2bb6dd5f416e6670e8f 100644 (file)
@@ -21,7 +21,6 @@
 
 class Buffer;
 class Change;
-class CursorSlice;
 class Encoding;
 class ErrorList;
 class FuncRequest;
@@ -33,33 +32,9 @@ class LyXScreen;
 class LyXView;
 class Painter;
 class PosIterator;
-class Selection;
 class TeXErrors;
 class UpdatableInset;
 
-
-// The structure that keeps track of the selections set.
-struct Selection {
-       Selection()
-               : set_(false), mark_(false)
-               {}
-       bool set() const {
-               return set_;
-       }
-       void set(bool s) {
-               set_ = s;
-       }
-       bool mark() const {
-               return mark_;
-       }
-       void mark(bool m) {
-               mark_ = m;
-       }
-private:
-       bool set_; // former selection
-       bool mark_; // former mark_set
-};
-
 /**
  * A buffer view encapsulates a view onto a particular
  * buffer, and allows access to operate upon it. A view
@@ -204,56 +179,18 @@ public:
        /// execute the given function
        bool dispatch(FuncRequest const & argument);
        
-       /// set target x position of cursor
-       void x_target(int x);
-       /// return target x position of cursor
-       int x_target() const;
-
        /// clear the X selection
        void unsetXSel();
 
        /// access to full cursor
-       LCursor & fullCursor();
-       /// access to full cursor
-       void fullCursor(LCursor const &);
+       LCursor & cursor();
        /// access to full cursor
-       LCursor const & fullCursor() const;
-       /// access to topmost cursor slice
-       CursorSlice & cursor();
-       /// access to topmost cursor slice
-       CursorSlice const & cursor() const;
-       /// access to selection anchor
-       CursorSlice & anchor();
-       /// access to selection anchor
-       CursorSlice const & anchor() const;
-       ///
-       UpdatableInset * innerInset() const;
+       LCursor const & cursor() const;
        ///
        LyXText * text() const;
-       /// 
-       void resetAnchor();
-       ///
-       Selection & selection();
-       ///
-       Selection const & selection() const;
-       ///
-       CursorSlice & selStart();
-       ///
-       CursorSlice const & selStart() const;
-       ///
-       CursorSlice & selEnd();
-       ///
-       CursorSlice const & selEnd() const;
-       ///
-       void setSelection();
-       ///
-       void clearSelection();
        ///
        void putSelectionAt(PosIterator const & cur, int length, bool backwards);
 
-       ///
-       Selection selection_;
-
 private:
        ///
        struct Pimpl;
@@ -261,21 +198,6 @@ private:
        friend struct BufferView::Pimpl;
        ///
        Pimpl * pimpl_;
-
-       /**
-        * The target x position of the cursor. This is used for when
-        * we have text like :
-        *
-        * blah blah blah blah| blah blah blah
-        * blah blah blah
-        * blah blah blah blah blah blah
-        *
-        * When we move onto row 3, we would like to be vertically aligned
-        * with where we were in row 1, despite the fact that row 2 is
-        * shorter than x()
-        */
-       int x_target_;
-
 };
 
 #endif // BUFFERVIEW_H
index ace9dd401451713b6040c8c6f695eaceaefa0bee..a6db146074e208901149c6ce67e2e3ea341febb0 100644 (file)
@@ -400,33 +400,34 @@ void BufferView::Pimpl::resizeCurrentBuffer()
        if (!text)
                return;
 
-       par = bv_->cursor().par();
-       pos = bv_->cursor().pos();
-       selstartpar = bv_->selStart().par();
-       selstartpos = bv_->selStart().pos();
-       selendpar = bv_->selEnd().par();
-       selendpos = bv_->selEnd().pos();
-       sel = bv_->selection().set();
-       mark_set = bv_->selection().mark();
+       LCursor & cur = bv_->cursor();
+       par = cur.par();
+       pos = cur.pos();
+       selstartpar = cur.selStart().par();
+       selstartpos = cur.selStart().pos();
+       selendpar = cur.selEnd().par();
+       selendpos = cur.selEnd().pos();
+       sel = cur.selection();
+       mark_set = cur.mark();
        text->textwidth_ = bv_->workWidth();
        text->fullRebreak();
        update();
 
        if (par != -1) {
-               bv_->selection().set(true);
+               cur.selection() = true;
                // At this point just to avoid the Delete-Empty-Paragraph-
                // Mechanism when setting the cursor.
-               bv_->selection().mark(mark_set);
+               cur.mark() = mark_set;
                if (sel) {
                        text->setCursor(selstartpar, selstartpos);
-                       bv_->resetAnchor();
+                       cur.resetAnchor();
                        text->setCursor(selendpar, selendpos);
-                       bv_->setSelection();
+                       cur.setSelection();
                        text->setCursor(par, pos);
                } else {
                        text->setCursor(par, pos);
-                       bv_->resetAnchor();
-                       bv_->selection().set(false);
+                       cur.resetAnchor();
+                       cur.selection() = false;
                }
        }
 
@@ -536,21 +537,21 @@ void BufferView::Pimpl::selectionRequested()
        if (!available())
                return;
 
-       LyXText * text = bv_->getLyXText();
+       LCursor & cur = bv_->cursor();
 
-       if (!bv_->selection().set()) {
+       if (!cur.selection()) {
                xsel_cache_.set = false;
                return;
        }
 
        if (!xsel_cache_.set ||
-           bv_->cursor() != xsel_cache_.cursor ||
-           bv_->anchor() != xsel_cache_.anchor)
+           cur.cursor_.back() != xsel_cache_.cursor ||
+           cur.anchor_.back() != xsel_cache_.anchor)
        {
-               xsel_cache_.cursor = bv_->cursor();
-               xsel_cache_.anchor = bv_->anchor();
-               xsel_cache_.set = bv_->selection().set();
-               sel = text->selectionAsString(*bv_->buffer(), false);
+               xsel_cache_.cursor = cur.cursor_.back();
+               xsel_cache_.anchor = cur.anchor_.back();
+               xsel_cache_.set = cur.selection();
+               sel = bv_->getLyXText()->selectionAsString(*bv_->buffer(), false);
                if (!sel.empty())
                        workarea().putClipboard(sel);
        } 
@@ -561,7 +562,7 @@ void BufferView::Pimpl::selectionLost()
 {
        if (available()) {
                screen().hideCursor();
-               bv_->clearSelection();
+               bv_->cursor().clearSelection();
                xsel_cache_.set = false;
        }
 }
@@ -640,12 +641,13 @@ Change const BufferView::Pimpl::getCurrentChange()
                return Change(Change::UNCHANGED);
 
        LyXText * text = bv_->getLyXText();
+       LCursor & cur = bv_->cursor();
 
-       if (!bv_->selection().set())
+       if (!cur.selection())
                return Change(Change::UNCHANGED);
 
-       return text->getPar(bv_->selStart())
-               ->lookupChangeFull(bv_->selStart().pos());
+       return text->getPar(cur.selStart())
+               ->lookupChangeFull(cur.selStart().pos());
 }
 
 
@@ -668,7 +670,7 @@ void BufferView::Pimpl::restorePosition(unsigned int i)
 
        string const fname = saved_positions[i].filename;
 
-       bv_->clearSelection();
+       bv_->cursor().clearSelection();
 
        if (fname != buffer_->fileName()) {
                Buffer * b = 0;
@@ -720,7 +722,7 @@ void BufferView::Pimpl::center()
 {
        LyXText * text = bv_->text();
 
-       bv_->clearSelection();
+       bv_->cursor().clearSelection();
        int const half_height = workarea().workHeight() / 2;
        int new_y = std::max(0, text->cursorY() - half_height);
 
@@ -879,7 +881,7 @@ void BufferView::Pimpl::trackChanges()
 }
 
 #warning remove me
-LCursor theTempCursor;
+CursorBase theTempCursor;
 
 namespace {
 
@@ -888,7 +890,7 @@ namespace {
                lyxerr << "insetFromCoords" << endl;
                LyXText * text = bv->text();
                InsetOld * inset = 0;
-               theTempCursor = LCursor(*bv);
+               theTempCursor.clear();
                while (true) {
                        InsetOld * const inset_hit = text->checkInsetHit(x, y);
                        if (!inset_hit) {
@@ -906,9 +908,9 @@ namespace {
                        text = inset_hit->getText(cell);
                        lyxerr << "Hit inset: " << inset << " at x: " << x
                                << " text: " << text << " y: " << y << endl;
-                       theTempCursor.push(static_cast<UpdatableInset*>(inset));
+                       theTempCursor.push_back(CursorSlice(inset));
                }
-               lyxerr << "theTempCursor: " << theTempCursor << endl;
+               //lyxerr << "theTempCursor: " << theTempCursor << endl;
                return inset;
        }
 
@@ -917,25 +919,26 @@ namespace {
 
 bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd)
 {
+       LCursor & cur = bv_->cursor();
        switch (cmd.action) {
        case LFUN_MOUSE_MOTION: {
                if (!available())
                        return false;
                FuncRequest cmd1 = cmd;
-               UpdatableInset * inset = bv_->fullCursor().innerInset();
+               InsetBase * inset = cur.inset();
                DispatchResult res;
                if (inset) {
                        cmd1.x -= inset->x();
                        cmd1.y -= inset->y();
-                       res = inset->dispatch(*bv_, cmd1);
+                       res = inset->dispatch(cur, cmd1);
                } else {
                        cmd1.y += bv_->top_y();
-                       res = bv_->fullCursor().innerText()->dispatch(*bv_, cmd1);
+                       res = cur.innerText()->dispatch(cur, cmd1);
                }
 
                if (bv_->fitCursor() || res.update()) {
                        bv_->update();
-                       bv_->fullCursor().updatePos();
+                       cur.updatePos();
                }
 
                return true;
@@ -971,10 +974,10 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd)
                               << " to inset " << inset << endl;
                        cmd2.x -= inset->x();
                        cmd2.y -= inset->y();
-                       res = inset->dispatch(*bv_, cmd2);
+                       res = inset->dispatch(cur, cmd2);
                        if (res.update()) {
                                bv_->update();
-                               bv_->fullCursor().updatePos();
+                               cur.updatePos();
                        }
                        res.update(false);
                        switch (res.val()) {
@@ -982,9 +985,9 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd)
                                case FINISHED_RIGHT:
                                case FINISHED_UP:
                                case FINISHED_DOWN:
-                                       theTempCursor.pop();
-                                       bv_->fullCursor(theTempCursor);
-                                       bv_->fullCursor().innerText()
+                                       theTempCursor.pop_back();
+                                       cur.cursor_ = theTempCursor;
+                                       cur.innerText()
                                                ->setCursorFromCoordinates(cmd.x, top_y() + cmd.y);
                                        if (bv_->fitCursor())
                                                bv_->update();
@@ -997,14 +1000,14 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd)
 
                // otherwise set cursor to surrounding LyXText
                if (!res.dispatched()) {
-                       lyxerr << "temp cursor is: " << theTempCursor << endl;
-                       lyxerr << "dispatching " << cmd
-                              << " to surrounding LyXText "
-                              << theTempCursor.innerText() << endl;
-                       bv_->fullCursor(theTempCursor);
+                       //lyxerr << "temp cursor is: " << theTempCursor << endl;
+                       //lyxerr << "dispatching " << cmd
+                        //      << " to surrounding LyXText "
+                         //     << theTempCursor.innerText() << endl;
+                       cur.cursor_ = theTempCursor;
                        FuncRequest cmd1 = cmd;
                        cmd1.y += bv_->top_y();
-                       res = bv_->fullCursor().innerText()->dispatch(*bv_, cmd1);
+                       res = cur.innerText()->dispatch(cur, cmd1);
                        if (bv_->fitCursor() || res.update())
                                bv_->update();
 
@@ -1046,6 +1049,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
                << endl;
 
        LyXTextClass const & tclass = buffer_->params().getLyXTextClass();
+       LCursor & cur = bv_->cursor();
 
        switch (ev.action) {
 
@@ -1142,7 +1146,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
        case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
        case LFUN_MATH_DISPLAY:          // Open or create a displayed math inset
        case LFUN_MATH_MODE:             // Open or create an inlined math inset
-               mathDispatch(*bv_, ev);
+               mathDispatch(cur, ev);
                break;
 
        case LFUN_INSET_INSERT: {
@@ -1248,29 +1252,29 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
                break;
 
        case LFUN_MARK_OFF:
-               bv_->clearSelection();
+               cur.clearSelection();
                bv_->update();
-               bv_->resetAnchor();
+               cur.resetAnchor();
                ev.message(N_("Mark off"));
                break;
 
        case LFUN_MARK_ON:
-               bv_->clearSelection();
-               bv_->selection().mark(true);
+               cur.clearSelection();
+               cur.mark() = true;
                bv_->update();
-               bv_->resetAnchor();
+               cur.resetAnchor();
                ev.message(N_("Mark on"));
                break;
 
        case LFUN_SETMARK:
-               bv_->clearSelection();
-               if (bv_->selection().mark()) {
+               cur.clearSelection();
+               if (cur.mark()) {
                        ev.message(N_("Mark removed"));
                } else {
-                       bv_->selection().mark(true);
+                       cur.mark() = true;
                        ev.message(N_("Mark set"));
                }
-               bv_->resetAnchor();
+               cur.resetAnchor();
                bv_->update();
                break;
 
@@ -1279,7 +1283,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
                break;
 
        default:
-               return bv_->getLyXText()->dispatch(*bv_, ev).dispatched();
+               return cur.dispatch(ev).dispatched();
        } // end of switch
 
        return true;
@@ -1292,7 +1296,7 @@ bool BufferView::Pimpl::insertInset(InsetOld * inset, string const & lout)
        bv_->text()->recUndo(bv_->text()->cursor().par());
        freezeUndo();
 
-       bv_->clearSelection();
+       bv_->cursor().clearSelection();
        if (!lout.empty()) {
                bv_->text()->breakParagraph(bv_->buffer()->paragraphs());
 
@@ -1308,7 +1312,7 @@ bool BufferView::Pimpl::insertInset(InsetOld * inset, string const & lout)
                bv_->text()->setLayout(hasLayout ? lres : tclass.defaultLayoutName());
                bv_->text()->setParagraph(Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
        }
-       bv_->fullCursor().innerText()->insertInset(inset);
+       bv_->cursor().innerText()->insertInset(inset);
        unFreezeUndo();
        return true;
 }
index 4d3a440c041ba954c1984c6628c3a250e152636c..5960159447dbee23401117e81e0e63a7cbc0f34d 100644 (file)
@@ -1,4 +1,25 @@
 
+2004-01-20  André Pönitz  <poenitz@gmx.net>
+
+       * BufferView.[Ch]:
+       * BufferView_pimpl.C:
+       * PosIterator.C:
+       * bufferview_funcs.C:
+       * cursor.[Ch]:
+       * cursor_slice.[Ch]:
+       * factory.C:
+       * iterators.C:
+       * lyx_cb.C:
+       * lyxfind.C:
+       * lyxfunc.C:
+       * lyxtext.h:
+       * rowpainter.C:
+       * text.C:
+       * text2.C:
+       * text3.C:
+       * undo.[Ch]: lots of IU. Shift selection stuff from the BufferView to
+         LCursor and mathcursor parts to LCursor and InsetBase.
+
 2004-01-15  André Pönitz  <poenitz@gmx.net>
 
        * cursor_slice.[Ch]: add a few covienience functions
index 69004c07948d079622c91b360f46f699546fd0b9..dcd6798f1053b9189e240a4a9168e2b184d143f3 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "buffer.h"
 #include "BufferView.h"
-#include "cursor_slice.h"
+#include "cursor.h"
 #include "iterators.h"
 #include "lyxtext.h"
 #include "paragraph.h"
index fb14fbf9bb1af520a8c74761cbe2e3195a05c2fe..2523b065c4458d7181d04026a51510b136b3bd71 100644 (file)
@@ -164,13 +164,15 @@ void changeDepth(BufferView * bv, LyXText * text, DEPTH_CHANGE type)
 // Returns the current font and depth as a message.
 string const currentState(BufferView * bv)
 {
+       ostringstream state;
+
        if (!bv->available())
                return string();
 
-       if (mathcursor)
-               return mathcursor->info(bv->fullCursor());
-
-       ostringstream state;
+       if (inMathed()) {
+               bv->cursor().info(state);
+               return state.str();
+       }
 
        LyXText * text = bv->getLyXText();
        Buffer * buffer = bv->buffer();
@@ -254,7 +256,7 @@ string const currentState(BufferView * bv)
 // deletes a selection during an insertion
 void replaceSelection(LyXText * text)
 {
-       if (text->bv()->selection().set()) {
+       if (text->bv()->cursor().selection()) {
                text->cutSelection(true, false);
                text->bv()->update();
        }
index 47b1d22152c6a37e369dd97716dcf5b00a666034..bc541b4472eb5e1a2009f6c5ff5d33c610e85998 100644 (file)
@@ -27,6 +27,7 @@
 #include "insets/insettext.h"
 
 #include "mathed/math_data.h"
+#include "mathed/math_inset.h"
 
 #include <boost/assert.hpp>
 
@@ -34,22 +35,10 @@ using std::vector;
 using std::endl;
 
 
-std::ostream & operator<<(std::ostream & os, LCursor const & cur)
-{
-       os << "\n";
-       for (size_t i = 0, n = cur.cursor_.size(); i != n; ++i)
-               os << "   (" << cur.cursor_[i] << " | " << cur.anchor_[i] << "\n";
-       return os;
-}
-
-
-LCursor::LCursor()
-       : cursor_(1), anchor_(1), bv_(0)
-{}
-
-
 LCursor::LCursor(BufferView & bv)
-       : cursor_(1), anchor_(1), bv_(&bv)
+       : cursor_(1), anchor_(1), bv_(&bv), current_(0),
+         cached_y_(0), x_target_(-1),
+         selection_(false), mark_(false)
 {}
 
 
@@ -59,9 +48,10 @@ DispatchResult LCursor::dispatch(FuncRequest const & cmd0)
        FuncRequest cmd = cmd0;
 
        for (int i = cursor_.size() - 1; i >= 1; --i) {
+               current_ = i;
                CursorSlice const & citem = cursor_[i];
                lyxerr << "trying to dispatch to inset " << citem.inset_ << endl;
-               DispatchResult res = citem.inset_->dispatch(*bv_, cmd);
+               DispatchResult res = inset()->dispatch(*this, cmd);
                if (res.dispatched()) {
                        lyxerr << " successfully dispatched to inset " << citem.inset_ << endl;
                        return DispatchResult(true, true);
@@ -90,7 +80,7 @@ DispatchResult LCursor::dispatch(FuncRequest const & cmd0)
                }
        }
        lyxerr << "trying to dispatch to main text " << bv_->text() << endl;
-       DispatchResult res = bv_->text()->dispatch(*bv_, cmd);
+       DispatchResult res = bv_->text()->dispatch(*this, cmd);
        lyxerr << "   result: " << res.val() << endl;
 
        if (!res.dispatched()) {
@@ -109,43 +99,53 @@ void LCursor::push(InsetBase * inset)
        lyxerr << "LCursor::push()  inset: " << inset << endl;
        cursor_.push_back(CursorSlice(inset));
        anchor_.push_back(CursorSlice(inset));
+       ++current_;
        updatePos();
 }
 
 
-
 void LCursor::pop(int depth)
 {
-       lyxerr << "LCursor::pop() to " << depth << endl;
-       while (cursor_.size() > 1 && depth < cursor_.size()) {
-               lyxerr <<   "LCursor::pop a level " << endl;
-               cursor_.pop_back();
-               anchor_.pop_back();
-       }
+       lyxerr << "LCursor::pop() to depth " << depth << endl;
+       while (cursor_.size() > depth)
+               pop();
 }
 
 
 void LCursor::pop()
 {
-       lyxerr << "LCursor::pop() " << endl;
+       lyxerr << "LCursor::pop() a level" << endl;
        //BOOST_ASSERT(!cursor_.empty());
        if (cursor_.size() <= 1)
                lyxerr << "### TRYING TO POP FROM EMPTY CURSOR" << endl;
        else {
                cursor_.pop_back();
                anchor_.pop_back();
+               current_ = cursor_.size() - 1;
        }
+       lyxerr << "LCursor::pop() current now: " << current_ << endl;
+}
+
+
+CursorSlice & LCursor::current()
+{
+       //lyxerr << "accessing cursor slice " << current_
+       //      << ": " << cursor_[current_] << endl;
+       return cursor_[current_];
 }
 
 
-UpdatableInset * LCursor::innerInset() const
+CursorSlice const & LCursor::current() const
 {
-       return cursor_.size() <= 1 ? 0 : cursor_.back().asUpdatableInset();
+       //lyxerr << "accessing cursor slice " << current_
+       //      << ": " << cursor_[current_] << endl;
+       return cursor_[current_];
 }
 
 
 LyXText * LCursor::innerText() const
 {
+       //lyxerr << "LCursor::innerText()  depth: " << cursor_.size() << endl;
        if (cursor_.size() > 1) {
                // go up until first non-0 text is hit
                // (innermost text is 0 e.g. for mathed and the outer tabular level)
@@ -173,7 +173,9 @@ void LCursor::getDim(int & asc, int & desc) const
                asc = row.baseline();
                desc = row.height() - asc;
        } else {
-               innerInset()->getCursorDim(asc, desc);
+               asc = 10;
+               desc = 10;
+               //innerInset()->getCursorDim(asc, desc);
        }
 }
 
@@ -185,37 +187,42 @@ void LCursor::getPos(int & x, int & y) const
                y = bv_->text()->cursorY();
 //             y -= bv_->top_y();
        } else {
-               // Would be nice to clean this up to make some understandable sense...
-               UpdatableInset * inset = innerInset();
-               // Non-obvious. The reason we have to have these
-               // extra checks is that the ->getCursor() calls rely
-               // on the inset's own knowledge of its screen position.
-               // If we scroll up or down in a big enough increment, the
-               // inset->draw() is not called: this doesn't update
-               // inset.top_baseline, so getCursor() returns an old value.
-               // Ugly as you like.
-               if (inset) {
-                       inset->getCursorPos(cursor_.back().idx_, x, y);
-                       x += inset->x();
+               if (inset()->asUpdatableInset()) {
+                       // Would be nice to clean this up to make some understandable sense...
+                       // Non-obvious. The reason we have to have these
+                       // extra checks is that the ->getCursor() calls rely
+                       // on the inset's own knowledge of its screen position.
+                       // If we scroll up or down in a big enough increment, the
+                       // inset->draw() is not called: this doesn't update
+                       // inset.top_baseline, so getCursor() returns an old value.
+                       // Ugly as you like.
+                       inset()->asUpdatableInset()->getCursorPos(cursor_.back().idx_, x, y);
+                       x += inset()->asUpdatableInset()->x();
                        y += cached_y_;
+               } else if (inset()->asMathInset()) {
+#warning FIXME
+                       x = 100;
+                       y = 100;
+               } else {
+                       // this should not happen
+                       BOOST_ASSERT(false);
                }
        }
 }
 
 
-UpdatableInset * LCursor::innerInsetOfType(int code) const
+InsetBase * LCursor::innerInsetOfType(int code) const
 {
        for (int i = cursor_.size() - 1; i >= 1; --i)
-               if (cursor_[i].asUpdatableInset()->lyxCode() == code)
-                       return cursor_[i].asUpdatableInset();
+               if (cursor_[i].inset_->lyxCode() == code)
+                       return cursor_[i].inset_;
        return 0;
 }
 
 
 InsetTabular * LCursor::innerInsetTabular() const
 {
-       return static_cast<InsetTabular *>
-               (innerInsetOfType(InsetOld::TABULAR_CODE));
+       return static_cast<InsetTabular *>(innerInsetOfType(InsetBase::TABULAR_CODE));
 }
 
 
@@ -275,3 +282,233 @@ bool LCursor::posRight()
        ++pos();
        return true;
 }
+
+
+CursorSlice & LCursor::anchor()
+{
+       return anchor_.back();
+}
+
+
+CursorSlice const & LCursor::anchor() const
+{
+       return anchor_.back();
+}
+
+
+CursorSlice const & LCursor::selStart() const
+{
+       if (!selection())
+               return cursor_.back();
+       // can't use std::min as this creates a new object
+       return anchor() < cursor_.back() ? anchor() : cursor_.back();
+}
+
+
+CursorSlice const & LCursor::selEnd() const
+{
+       if (!selection())
+               return cursor_.back();
+       return anchor() > cursor_.back() ? anchor() : cursor_.back();
+}
+
+
+CursorSlice & LCursor::selStart()
+{
+       if (!selection())
+               return cursor_.back();
+       return anchor() < cursor_.back() ? anchor() : cursor_.back();
+}
+
+
+CursorSlice & LCursor::selEnd()
+{
+       if (selection())
+               return cursor_.back();
+       return anchor() > cursor_.back() ? anchor() : cursor_.back();
+}
+
+
+void LCursor::setSelection()
+{
+       selection() = true;
+       // a selection with no contents is not a selection
+       if (par() == anchor().par() && pos() == anchor().pos())
+               selection() = false;
+}
+
+
+void LCursor::clearSelection()
+{
+       selection() = false;
+       mark() = false;
+       resetAnchor();
+       bv().unsetXSel();
+}
+
+
+
+//
+// CursorBase
+//
+
+
+void increment(CursorBase & it)
+{
+       CursorSlice & top = it.back();
+       MathArray & ar = top.asMathInset()->cell(top.idx_);
+
+       // move into the current inset if possible
+       // it is impossible for pos() == size()!
+       MathInset * n = 0;
+       if (top.pos() != top.lastpos())
+               n = (ar.begin() + top.pos_)->nucleus();
+       if (n && n->isActive()) {
+               it.push_back(CursorSlice(n));
+               return;
+       }
+
+       // otherwise move on one cell back if possible
+       if (top.pos() < top.lastpos()) {
+               // pos() == lastpos() is valid!
+               ++top.pos_;
+               return;
+       }
+
+       // otherwise try to move on one cell if possible
+       while (top.idx_ + 1 < top.asMathInset()->nargs()) {
+               // idx() == nargs() is _not_ valid!
+               ++top.idx_;
+               if (top.asMathInset()->validCell(top.idx_)) {
+                       top.pos_ = 0;
+                       return;
+               }
+       }
+
+       // otherwise leave array, move on one back
+       // this might yield pos() == size(), but that's a ok.
+       it.pop_back();
+       // it certainly invalidates top
+       ++it.back().pos_;
+}
+
+
+CursorBase ibegin(InsetBase * p)
+{
+       CursorBase it;
+       it.push_back(CursorSlice(p));
+       return it;
+}
+
+
+CursorBase iend(InsetBase * p)
+{
+       CursorBase it;
+       it.push_back(CursorSlice(p));
+       CursorSlice & top = it.back();
+       top.idx_ = top.asMathInset()->nargs() - 1;
+       top.pos_ = top.asMathInset()->cell(top.idx_).size();
+       return it;
+}
+
+
+void LCursor::x_target(int x)
+{
+       x_target_ = x;
+}
+
+
+int LCursor::x_target() const
+{
+       return x_target_;
+}
+
+
+Paragraph & LCursor::paragraph()
+{
+       return current_ ? current().paragraph() : *bv_->text()->getPar(par());
+}
+
+
+Paragraph const & LCursor::paragraph() const
+{
+       return current_ ? current().paragraph() : *bv_->text()->getPar(par());
+}
+
+
+LCursor::pos_type LCursor::lastpos() const
+{
+       return current_ ? current().lastpos() : bv_->text()->getPar(par())->size();
+}
+
+
+size_t LCursor::nargs() const
+{
+       // assume 1x1 grid for 'plain text'
+       return current_ ? current().nargs() : 1;
+}
+
+
+size_t LCursor::ncols() const
+{
+       // assume 1x1 grid for 'plain text'
+       return current_ ? current().ncols() : 1;
+}
+
+
+size_t LCursor::nrows() const
+{
+       // assume 1x1 grid for 'plain text'
+       return current_ ? current().nrows() : 1;
+}
+
+
+LCursor::row_type LCursor::row() const
+{
+       BOOST_ASSERT(current_ > 0);
+       return current().row();
+}
+
+
+LCursor::col_type LCursor::col() const
+{
+       BOOST_ASSERT(current_ > 0);
+       return current().col();
+}
+
+
+MathArray const & LCursor::cell() const
+{
+       BOOST_ASSERT(current_ > 0);
+       return current().cell();
+}
+
+
+MathArray & LCursor::cell()
+{
+       BOOST_ASSERT(current_ > 0);
+       return current().cell();
+}
+
+
+void LCursor::info(std::ostream & os)
+{
+       for (int i = 1, n = depth(); i < n; ++i) {
+               cursor_[i].inset()->infoize(os);
+               os << "  ";
+       }
+#warning FIXME
+       //if (pos() != 0)
+       //      prevAtom()->infoize2(os);
+       // overwite old message
+       os << "                    ";
+}
+
+
+std::ostream & operator<<(std::ostream & os, LCursor const & cur)
+{
+       os << "\n";
+       for (size_t i = 0, n = cur.cursor_.size(); i != n; ++i)
+               os << "  (" << cur.cursor_[i] << " | " << cur.anchor_[i] << "\n";
+       return os;
+}
index 35f858f09c5ae67592240b594c87d648cd18bfc3..d6537ffd5214b09da720ca6a638fb5d01ce10fd2 100644 (file)
@@ -22,8 +22,20 @@ class UpdatableInset;
 class MathAtom;
 class DispatchResult;
 class FuncRequest;
-class LyXText;
 class InsetTabular;
+class LyXText;
+class Paragraph;
+
+
+
+// this is used for traversing math insets
+typedef std::vector<CursorSlice> CursorBase;
+/// move on one step
+void increment(CursorBase &);
+///
+CursorBase ibegin(InsetBase * p);
+///
+CursorBase iend(InsetBase * p);
 
 
 /**
@@ -43,8 +55,6 @@ public:
        /// type for col indices
        typedef CursorSlice::col_type col_type;
 
-       /// create 'empty' cursor. REMOVE ME
-       LCursor();
        /// create the cursor of a BufferView
        explicit LCursor(BufferView & bv);
        /// dispatch from innermost inset upwards
@@ -55,48 +65,74 @@ public:
        void pop(int depth);
        /// pop one level off the cursor
        void pop();
-       /// access to cursor 'tip'
-       CursorSlice & top() { return cursor_.back(); }
-       /// access to cursor 'tip'
-       CursorSlice const & top() const { return cursor_.back(); }
+       /// access to current cursor slice
+       CursorSlice & current();
+       /// access to current cursor slice
+       CursorSlice const & current() const;
        /// how many nested insets do we have?
        size_t depth() const { return cursor_.size(); }
 
-       /// access to the topmost slice
+       //
+       // selection
+       //
+       /// selection active?
+       bool selection() const { return selection_; }
+       /// selection active?
+       bool & selection() { return selection_; }
+       /// did we place the anchor?
+       bool mark() const { return mark_; }
+       /// did we place the anchor?
+       bool & mark() { return mark_; }
+       ///
+       void setSelection();
+       ///
+       void clearSelection();
+       ///
+       CursorSlice & selStart();
+       ///
+       CursorSlice const & selStart() const;
+       ///
+       CursorSlice & selEnd();
+       ///
+       CursorSlice const & selEnd() const;
+
+       //
+       // access to the 'current' cursor slice
+       //
        /// the current inset
-       InsetBase * inset() const { return top().inset(); }
+       InsetBase * inset() const { return current().inset(); }
        /// return the text-ed cell this cursor is in
-       idx_type idx() const { return top().idx(); }
+       idx_type idx() const { return current().idx(); }
        /// return the text-ed cell this cursor is in
-       idx_type & idx() { return top().idx(); }
+       idx_type & idx() { return current().idx(); }
        /// return the paragraph this cursor is in
-       par_type par() const { return top().par(); }
+       par_type par() const { return current().par(); }
        /// return the paragraph this cursor is in
-       par_type & par() { return top().par(); }
+       par_type & par() { return current().par(); }
        /// return the position within the paragraph
-       pos_type pos() const { return top().pos(); }
+       pos_type pos() const { return current().pos(); }
        /// return the position within the paragraph
-       pos_type & pos() { return top().pos(); }
+       pos_type & pos() { return current().pos(); }
        /// return the last position within the paragraph
-       pos_type lastpos() const { return top().lastpos(); }
+       pos_type lastpos() const;
        /// return the number of embedded cells
-       size_t nargs() const { return top().nargs(); }
+       size_t nargs() const;
        /// return the number of embedded cells
-       size_t ncols() const { return top().ncols(); }
+       size_t ncols() const;
        /// return the number of embedded cells
-       size_t nrows() const { return top().nrows(); }
+       size_t nrows() const;
        /// return the grid row of the current cell
-       row_type row() const { return top().row(); }
+       row_type row() const;
        /// return the grid row of the current cell
-       col_type col() const { return top().col(); }
+       col_type col() const;
 
        //
        // math-specific part
        //
        /// return the mathed cell this cursor is in
-       MathArray const & cell() const { return top().cell(); }
+       MathArray const & cell() const;
        /// return the mathed cell this cursor is in
-       MathArray & cell() { return top().cell(); }
+       MathArray & cell();
        /// the mathatom left of the cursor
        MathAtom const & prevAtom() const;
        /// the mathatom left of the cursor
@@ -105,13 +141,25 @@ public:
        MathAtom const & nextAtom() const;
        /// the mathatom right of the cursor
        MathAtom & nextAtom();
+       /// auto-correct mode
+       bool autocorrect() const { return autocorrect_; }
+       /// auto-correct mode
+       bool & autocorrect() { return autocorrect_; }
+       /// are we entering a macro name?
+       bool macromode() const { return macromode_; }
+       /// are we entering a macro name?
+       bool & macromode() { return macromode_; }
 
        //
        // text-specific part
        ///
-       UpdatableInset * innerInset() const;
+       bool boundary() const { return current().boundary(); }
+       ///
+       Paragraph & paragraph();
+       ///
+       Paragraph const & paragraph() const;
        ///
-       UpdatableInset * innerInsetOfType(int code) const;
+       InsetBase * innerInsetOfType(int code) const;
        ///
        InsetTabular * innerInsetTabular() const;
        ///
@@ -129,24 +177,70 @@ public:
        /// move one step to the right
        bool posRight();
 
+       /// set target x position of cursor
+       void x_target(int x);
+       /// return target x position of cursor
+       int x_target() const;
+
+       /// access to selection anchor
+       CursorSlice & anchor();
+       /// access to selection anchor
+       CursorSlice const & anchor() const;
        /// cache the absolute coordinate from the top inset
        void updatePos();
        /// sets anchor to cursor position
        void resetAnchor(); 
        /// access to owning BufferView
        BufferView & bv() const; 
-       ///
-       friend std::ostream & operator<<(std::ostream &, LCursor const &);
+       /// get some interesting description of current position
+       void info(std::ostream & os);
+
+       /// output
+       friend std::ostream & operator<<(std::ostream & os, LCursor const & cur);
 public:
+//private:
        /// mainly used as stack, but wee need random access
        std::vector<CursorSlice> cursor_;
-       /// The
+       /// the anchor position
        std::vector<CursorSlice> anchor_;
-       ///
-       BufferView * bv_;
+
 private:
+       /// don't implement this
+       void operator=(LCursor const &);
+       /// don't implement this
+       LCursor(LCursor const &);
+
+       ///
+       BufferView * const bv_;
+       /// current slice
+       int current_;
        ///
        int cached_y_;
+       /**
+        * The target x position of the cursor. This is used for when
+        * we have text like :
+        *
+        * blah blah blah blah| blah blah blah
+        * blah blah blah
+        * blah blah blah blah blah blah
+        *
+        * When we move onto row 3, we would like to be vertically aligned
+        * with where we were in row 1, despite the fact that row 2 is
+        * shorter than x()
+        */
+       int x_target_;
+       // do we have a selection?
+       bool selection_;
+       // are we on the way to get one?
+       bool mark_;
+
+       //
+       // math specific stuff that could be promoted to "global" later
+       //
+       /// do we allow autocorrection
+       bool autocorrect_;
+       /// are we entering a macro name?
+       bool macromode_;
 };
 
 #endif // LYXCURSOR_H
index f4e6fb43a99fa3d01bb90ca4495965d94c4bbc4c..464f1517fb8122c8a54162e7e3d16892e64d97e7 100644 (file)
@@ -15,6 +15,8 @@
 
 #include "cursor_slice.h"
 #include "debug.h"
+#include "lyxtext.h"
+#include "paragraph.h"
 
 #include "mathed/math_inset.h"
 #include "mathed/math_data.h"
@@ -51,6 +53,12 @@ size_t CursorSlice::nargs() const
 }
 
 
+size_t CursorSlice::nrows() const
+{
+       return inset_->nrows();
+}
+
+
 size_t CursorSlice::ncols() const
 {
        return inset_->ncols();
@@ -107,9 +115,7 @@ CursorSlice::pos_type & CursorSlice::pos()
 
 CursorSlice::pos_type CursorSlice::lastpos() const
 {
-       BOOST_ASSERT(inset_);
-#warning implement me for texted, too.
-       return inset_->asMathInset() ? cell().size() : 0;
+       return (inset_ && inset_->asMathInset()) ? cell().size() : paragraph().size();
 }
 
 
@@ -171,6 +177,22 @@ LyXText * CursorSlice::text() const
 }
 
 
+Paragraph & CursorSlice::paragraph()
+{
+       // access to the main lyx text must be handled in the cursor
+       BOOST_ASSERT(text());
+       return *text()->getPar(par_);
+}
+
+
+Paragraph const & CursorSlice::paragraph() const
+{
+       // access to the main lyx text must be handled in the cursor
+       BOOST_ASSERT(text());
+       return *text()->getPar(par_);
+}
+
+
 bool operator==(CursorSlice const & p, CursorSlice const & q)
 {
        return p.inset_ == q.inset_
@@ -212,8 +234,8 @@ bool operator>(CursorSlice const & p, CursorSlice const & q)
 
 std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
 {
-       os << " inset: " << item.inset_
-          << " text: " << item.text()
+       os << "inset: " << item.inset_
+//        << " text: " << item.text()
           << " idx: " << item.idx_
           << " par: " << item.par_
           << " pos: " << item.pos_
@@ -222,64 +244,3 @@ std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
 ;
        return os;
 }
-
-
-
-
-void increment(CursorBase & it)
-{
-       CursorSlice & top = it.back();
-       MathArray   & ar  = top.asMathInset()->cell(top.idx_);
-
-       // move into the current inset if possible
-       // it is impossible for pos() == size()!
-       MathInset * n = 0;
-       if (top.pos_ != ar.size())
-               n = (ar.begin() + top.pos_)->nucleus();
-       if (n && n->isActive()) {
-               it.push_back(CursorSlice(n));
-               return;
-       }
-
-       // otherwise move on one cell back if possible
-       if (top.pos_ < ar.size()) {
-               // pos() == size() is valid!
-               ++top.pos_;
-               return;
-       }
-
-       // otherwise try to move on one cell if possible
-       while (top.idx_ + 1 < top.asMathInset()->nargs()) {
-               // idx() == nargs() is _not_ valid!
-               ++top.idx_;
-               if (top.asMathInset()->validCell(top.idx_)) {
-                       top.pos_ = 0;
-                       return;
-               }
-       }
-
-       // otherwise leave array, move on one back
-       // this might yield pos() == size(), but that's a ok.
-       it.pop_back();
-       // it certainly invalidates top
-       ++it.back().pos_;
-}
-
-
-CursorBase ibegin(InsetBase * p)
-{
-       CursorBase it;
-       it.push_back(CursorSlice(p));
-       return it;
-}
-
-
-CursorBase iend(InsetBase * p)
-{
-       CursorBase it;
-       it.push_back(CursorSlice(p));
-       CursorSlice & top = it.back();
-       top.idx_ = top.asMathInset()->nargs() - 1;
-       top.pos_ = top.asMathInset()->cell(top.idx_).size();
-       return it;
-}
index 51c23cc22d8d2061ef92be4905000bd1d2438a00..e64948a36fced8ff738d36ebacc9932b1e49cde2 100644 (file)
@@ -17,8 +17,8 @@
 #ifndef CURSORSLICE_H
 #define CURSORSLICE_H
 
-#include <iosfwd>
 #include <cstddef>
+#include <iosfwd>
 
 #include "support/types.h"
 
@@ -27,6 +27,7 @@ class InsetBase;
 class MathInset;
 class MathArray;
 class LyXText;
+class Paragraph;
 class UpdatableInset;
 
 
@@ -99,6 +100,10 @@ public:
        LyXText * text() const;
        ///
        UpdatableInset * asUpdatableInset() const;
+       ///
+       Paragraph & paragraph();
+       ///
+       Paragraph const & paragraph() const;
 
        ///
        /// mathed specific stuff
@@ -148,20 +153,4 @@ bool operator<(CursorSlice const &, CursorSlice const &);
 /// test for order
 bool operator>(CursorSlice const &, CursorSlice const &);
 
-#include <vector>
-
-
-// this is used for traversing math insets
-typedef std::vector<CursorSlice> CursorBase;
-/// move on one step
-void increment(CursorBase &);
-///
-CursorBase ibegin(InsetBase * p);
-///
-CursorBase iend(InsetBase * p);
-///
-CursorSlice & cursorTip(BufferView &);
-
-
-
 #endif
index f5a79b3ec543ba7d9fae794743371a4f566aac82..d1afb99668381cc7fcbc4d8e523d3d4b1cd08a97 100644 (file)
@@ -179,16 +179,19 @@ InsetOld * createInset(BufferView * bv, FuncRequest const & cmd)
                bv->owner()->getDialogs().show("tabularcreate");
                return 0;
 
-       case LFUN_INSET_CAPTION: 
-       if (!bv->innerInset()) {
-               auto_ptr<InsetCaption> inset(new InsetCaption(params));
-               inset->setOwner(bv->innerInset());
-               inset->setAutoBreakRows(true);
-               inset->setDrawFrame(InsetText::LOCKED);
-               inset->setFrameColor(LColor::captionframe);
-               return inset.release();
+       case LFUN_INSET_CAPTION: {
+               UpdatableInset * up = bv->cursor().inset()
+                       ? bv->cursor().inset()->asUpdatableInset() : 0;
+               if (!up) {
+                       auto_ptr<InsetCaption> inset(new InsetCaption(params));
+                       inset->setOwner(up);
+                       inset->setAutoBreakRows(true);
+                       inset->setDrawFrame(InsetText::LOCKED);
+                       inset->setFrameColor(LColor::captionframe);
+                       return inset.release();
+               }
+               return 0;
        }
-       return 0;
 
        case LFUN_INDEX_PRINT:
                return new InsetPrintIndex(InsetCommandParams("printindex"));
index ef85ab161230e4ab464f848a9419b76eb755089a..da79c4c181567185d3ae0dd8fcb59317ed359826 100644 (file)
@@ -105,7 +105,7 @@ void LyXView::setLayout(string const & layout)
 
 void LyXView::updateToolbar()
 {
-       bool const math = mathcursor;
+       bool const math = inMathed();
        bool const table =
                !getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).disabled();
        toolbar_->update(math, table);
index 7b06eabb3fffdbf7acc40bc7d5544a7fae1f6251..68da7ca38d9d6d22a7618964b4b69808e3db0a1f 100644 (file)
@@ -172,7 +172,7 @@ void LyXScreen::showCursor(BufferView & bv)
        int h = ascent + descent;
        int x = 0;
        int y = 0;
-       bv.fullCursor().getPos(x, y);
+       bv.cursor().getPos(x, y);
        y -= ascent + bv.top_y();
        //lyxerr << "LyXScreen::showCursor x: " << x << " y: " << y << endl;
 
@@ -211,8 +211,8 @@ bool LyXScreen::fitCursor(BufferView * bv)
        int newtop = top_y;
        int x, y, asc, desc;
 
-       bv->fullCursor().getPos(x, y);
-       bv->fullCursor().getDim(asc, desc);
+       bv->cursor().getPos(x, y);
+       bv->cursor().getDim(asc, desc);
        
        bool const big_row = h / 4 < asc + desc && asc + desc < h;
 
index 9bbdf1e70b477314863f1bb010ba99a437da4f58..ad96968e5c1db4a2df7ab6c032385734e4339864 100644 (file)
@@ -1,4 +1,30 @@
 
+2004-01-20  André Pönitz  <poenitz@gmx.net>
+
+       * inset.h:
+       * insetbase.[Ch]: move stuff from mathcursor here.
+
+       * insetbibitem.[Ch]:
+       * insetbibtex.[Ch]:
+       * insetbox.[Ch]:
+       * insetbranch.[Ch]:
+       * insetcharstyle.[Ch]:
+       * insetcollapsable.[Ch]:
+       * insetcommand.[Ch]:
+       * insetert.[Ch]:
+       * insetexternal.[Ch]:
+       * insetfloat.[Ch]:
+       * insetgraphics.[Ch]:
+       * insetinclude.[Ch]:
+       * insetlabel.[Ch]:
+       * insetnote.[Ch]:
+       * insetref.[Ch]:
+       * insettabular.[Ch]:
+       * insettext.[Ch]:
+       * insetvspace.[Ch]:
+       * insetwrap.[Ch]:
+       * updatableinset.[Ch]: Adjust to IU changes (see comment in src/Changelog)
+
 2004-01-15  André Pönitz  <poenitz@gmx.net>
 
        * insetbase.[Ch]:
index f1242d6c7f28419e9c09d545cc491456d55cd591..1f54edfcba496d0533b29f2877254f40a6ff9b16 100644 (file)
@@ -17,8 +17,6 @@
 
 #include "insetbase.h"
 #include "dimension.h"
-#include "ParagraphList_fwd.h"
-
 
 class Buffer;
 class LColor_color;
@@ -37,107 +35,10 @@ namespace graphics {
 }
 }
 
+
 /// Insets
 class InsetOld : public InsetBase {
 public:
-       /** This is not quite the correct place for this enum. I think
-           the correct would be to let each subclass of Inset declare
-           its own enum code. Actually the notion of an InsetOld::Code
-           should be avoided, but I am not sure how this could be done
-           in a cleaner way. */
-       enum Code {
-               ///
-               NO_CODE, // 0
-               ///
-               TOC_CODE,  // do these insets really need a code? (ale)
-               ///
-               QUOTE_CODE,
-               ///
-               MARK_CODE,
-               ///
-               REF_CODE,
-               ///
-               URL_CODE, // 5
-               ///
-               HTMLURL_CODE,
-               ///
-               SEPARATOR_CODE,
-               ///
-               ENDING_CODE,
-               ///
-               LABEL_CODE,
-               ///
-               NOTE_CODE, // 10
-               ///
-               ACCENT_CODE,
-               ///
-               MATH_CODE,
-               ///
-               INDEX_CODE,
-               ///
-               INCLUDE_CODE,
-               ///
-               GRAPHICS_CODE, // 15
-               ///
-               BIBITEM_CODE,
-               ///
-               BIBTEX_CODE,
-               ///
-               TEXT_CODE,
-               ///
-               ERT_CODE,
-               ///
-               FOOT_CODE, // 20
-               ///
-               MARGIN_CODE,
-               ///
-               FLOAT_CODE,
-               ///
-               WRAP_CODE,
-               ///
-               SPACE_CODE, // 25
-               ///
-               SPECIALCHAR_CODE,
-               ///
-               TABULAR_CODE,
-               ///
-               EXTERNAL_CODE,
-#if 0
-               ///
-               THEOREM_CODE,
-#endif
-               ///
-               CAPTION_CODE,
-               ///
-               MATHMACRO_CODE, // 30
-               ///
-               ERROR_CODE,
-               ///
-               CITE_CODE,
-               ///
-               FLOAT_LIST_CODE,
-               ///
-               INDEX_PRINT_CODE,
-               ///
-               OPTARG_CODE, // 35
-               ///
-               ENVIRONMENT_CODE,
-               ///
-               HFILL_CODE,
-               ///
-               NEWLINE_CODE,
-               ///
-               LINE_CODE,
-               ///
-               BRANCH_CODE, // 40
-               ///
-               BOX_CODE,
-               ///
-               CHARSTYLE_CODE,
-               ///
-               VSPACE_CODE
-       };
-
        ///
        enum {
                ///
@@ -195,9 +96,6 @@ public:
        virtual int docbook(Buffer const &, std::ostream &,
                            OutputParams const &) const = 0;
 
-       /// returns LyX code associated with the inset. Used for TOC, ...)
-       virtual InsetOld::Code lyxCode() const { return NO_CODE; }
-
        /// returns true to override begin and end inset in file
        virtual bool directWrite() const;
 
index c9c606203eb38394feb570680c11a4a608ab236d..6602812e7841158a08fbd2277051b3358ae1529c 100644 (file)
 #include "dispatchresult.h"
 
 
-DispatchResult InsetBase::dispatch(BufferView & bv, FuncRequest const & cmd)
+DispatchResult InsetBase::dispatch(LCursor & cur, FuncRequest const & cmd)
 {
-       return priv_dispatch(bv, cmd);
+       return priv_dispatch(cur, cmd);
 }
 
 
-DispatchResult
-InsetBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+DispatchResult InsetBase::priv_dispatch(LCursor &, FuncRequest const & cmd)
 {
        return DispatchResult(false);
 }
 
 
-void InsetBase::edit(BufferView *, bool)
+void InsetBase::edit(LCursor &, bool)
 {
        lyxerr << "InsetBase: edit left/right" << std::endl;
 }
 
 
-void InsetBase::edit(BufferView * bv, int, int)
+void InsetBase::edit(LCursor & cur, int, int)
 {
        lyxerr << "InsetBase: edit xy" << std::endl;
-       edit(bv, true);
+       edit(cur, true);
 }
index 771ff610fa74110866f610ecb4154a4f6a8557c9..0702a5f85eec2f177bdb3bd023f49f58cbfff858 100644 (file)
@@ -21,6 +21,7 @@ class BufferView;
 class DispatchResult;
 class FuncRequest;
 class LaTeXFeatures;
+class LCursor;
 class MathInset;
 class MetricsInfo;
 class Dimension;
@@ -54,23 +55,17 @@ public:
        virtual UpdatableInset * asUpdatableInset() { return 0; }
 
        // the real dispatcher
-       DispatchResult dispatch(BufferView & bv, FuncRequest const & cmd);
+       DispatchResult dispatch(LCursor & cur, FuncRequest const & cmd);
 
        /// cursor enters
-       virtual void edit(BufferView * bv, bool left);
+       virtual void edit(LCursor & cur, bool left);
        /// cursor enters
-       virtual void edit(BufferView * bv, int x, int y);
+       virtual void edit(LCursor & cur, int x, int y);
 
        /// compute the size of the object returned in dim
        virtual void metrics(MetricsInfo & mi, Dimension & dim) const = 0;
        /// draw inset and update (xo, yo)-cache
        virtual void draw(PainterInfo & pi, int x, int y) const = 0;
-
-       /// request "external features"
-       virtual void validate(LaTeXFeatures &) const {}
-       /// Appends \c list with all labels found within this inset.
-       virtual void getLabelList(Buffer const &,
-                                 std::vector<std::string> & /* list */) const {}
        /// last drawn position for 'important' insets
        virtual int x() const { return 0; }
        /// last drawn position for 'important' insets
@@ -82,10 +77,125 @@ public:
        virtual size_t nrows() const { return 0; }
        /// number of columns in gridlike structures
        virtual size_t ncols() const { return 0; }
+
+       /// request "external features"
+       virtual void validate(LaTeXFeatures &) const {}
+       /// Appends \c list with all labels found within this inset.
+       virtual void getLabelList(Buffer const &,
+                                 std::vector<std::string> & /* list */) const {}
+       /// describe content if cursor inside
+       virtual void infoize(std::ostream &) const {}
+       /// describe content if cursor behind
+       virtual void infoize2(std::ostream &) const {}
 protected:
        // the real dispatcher
        virtual
-       DispatchResult priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+       DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+public:
+       /** This is not quite the correct place for this enum. I think
+           the correct would be to let each subclass of Inset declare
+           its own enum code. Actually the notion of an InsetOld::Code
+           should be avoided, but I am not sure how this could be done
+           in a cleaner way. */
+       enum Code {
+               ///
+               NO_CODE, // 0
+               ///
+               TOC_CODE,  // do these insets really need a code? (ale)
+               ///
+               QUOTE_CODE,
+               ///
+               MARK_CODE,
+               ///
+               REF_CODE,
+               ///
+               URL_CODE, // 5
+               ///
+               HTMLURL_CODE,
+               ///
+               SEPARATOR_CODE,
+               ///
+               ENDING_CODE,
+               ///
+               LABEL_CODE,
+               ///
+               NOTE_CODE, // 10
+               ///
+               ACCENT_CODE,
+               ///
+               MATH_CODE,
+               ///
+               INDEX_CODE,
+               ///
+               INCLUDE_CODE,
+               ///
+               GRAPHICS_CODE, // 15
+               ///
+               BIBITEM_CODE,
+               ///
+               BIBTEX_CODE,
+               ///
+               TEXT_CODE,
+               ///
+               ERT_CODE,
+               ///
+               FOOT_CODE, // 20
+               ///
+               MARGIN_CODE,
+               ///
+               FLOAT_CODE,
+               ///
+               WRAP_CODE,
+               ///
+               SPACE_CODE, // 25
+               ///
+               SPECIALCHAR_CODE,
+               ///
+               TABULAR_CODE,
+               ///
+               EXTERNAL_CODE,
+#if 0
+               ///
+               THEOREM_CODE,
+#endif
+               ///
+               CAPTION_CODE,
+               ///
+               MATHMACRO_CODE, // 30
+               ///
+               ERROR_CODE,
+               ///
+               CITE_CODE,
+               ///
+               FLOAT_LIST_CODE,
+               ///
+               INDEX_PRINT_CODE,
+               ///
+               OPTARG_CODE, // 35
+               ///
+               ENVIRONMENT_CODE,
+               ///
+               HFILL_CODE,
+               ///
+               NEWLINE_CODE,
+               ///
+               LINE_CODE,
+               ///
+               BRANCH_CODE, // 40
+               ///
+               BOX_CODE,
+               ///
+               CHARSTYLE_CODE,
+               ///
+               VSPACE_CODE,
+               ///
+               MATHGRID_CODE,
+               ///
+               MATHHULL_CODE
+       };
+       /// returns LyX code associated with the inset. Used for TOC, ...)
+       virtual InsetBase::Code lyxCode() const { return NO_CODE; }
+
 };
 
 #endif
index 6a732d716e1f574ed7db234d577aaaf49668c582..49fa857cce3c22425feeeab1d66e3aa5de902634 100644 (file)
@@ -54,7 +54,7 @@ auto_ptr<InsetBase> InsetBibitem::clone() const
 
 
 DispatchResult
-InsetBibitem::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetBibitem::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
        switch (cmd.action) {
 
@@ -64,13 +64,13 @@ InsetBibitem::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                if (p.getCmdName().empty())
                        return DispatchResult(true, true);
                setParams(p);
-               bv.update();
-               bv.fitCursor();
+               cur.bv().update();
+               cur.bv().fitCursor();
                return DispatchResult(true, true);
        }
 
        default:
-               return InsetCommand::priv_dispatch(bv, cmd);
+               return InsetCommand::priv_dispatch(cur, cmd);
        }
 }
 
index b64a72f45c4ad575cfb896c9215e6d438ad70793..06f5813cade600b02c04b559fff1d8045fe297e5 100644 (file)
@@ -52,7 +52,7 @@ protected:
        ///
        virtual
        DispatchResult
-       priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+       priv_dispatch(LCursor & cur, FuncRequest const & cmd);
 private:
        ///
        int counter;
index bfc7806ffa8536ac7bad87c578a17c3cd4a23778..32ed3d3a8fe0480fd7390092de887baf8c2b6810 100644 (file)
@@ -66,7 +66,7 @@ std::auto_ptr<InsetBase> InsetBibtex::clone() const
 
 
 DispatchResult
-InsetBibtex::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetBibtex::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
        switch (cmd.action) {
 
@@ -79,7 +79,7 @@ InsetBibtex::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
        }
                
        default:
-               return InsetCommand::priv_dispatch(bv, cmd);
+               return InsetCommand::priv_dispatch(cur, cmd);
        }
 }
 
index 2146fff6ed404e28c6cb1e69088e4691365fc923..d1f6480d6abc7e07cddaa1e2bbb8b4a131cded25 100644 (file)
@@ -48,7 +48,7 @@ protected:
        ///
        virtual
        DispatchResult
-       priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+       priv_dispatch(LCursor & cur, FuncRequest const & cmd);
 };
 
 #endif // INSET_BIBTEX_H
index bcc0ab67f73c9d196f2a4ec90c8bda9f8ef3fa71..4f647c53fbc35c2b4ac3703c5995aaa97beb2097 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "insetbox.h"
 
-#include "BufferView.h"
+#include "cursor.h"
 #include "dispatchresult.h"
 #include "debug.h"
 #include "funcrequest.h"
@@ -170,7 +170,7 @@ bool InsetBox::showInsetDialog(BufferView * bv) const
 
 
 DispatchResult
-InsetBox::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetBox::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
        switch (cmd.action) {
 
@@ -182,18 +182,18 @@ InsetBox::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
        }
 
        case LFUN_INSET_DIALOG_UPDATE:
-               InsetBoxMailer(*this).updateDialog(&bv);
+               InsetBoxMailer(*this).updateDialog(&cur.bv());
                return DispatchResult(true);
 
        case LFUN_MOUSE_RELEASE:
                if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
-                       InsetBoxMailer(*this).showDialog(&bv);
+                       InsetBoxMailer(*this).showDialog(&cur.bv());
                        return DispatchResult(true);
                }
-               return InsetCollapsable::priv_dispatch(bv, cmd);
+               return InsetCollapsable::priv_dispatch(cur, cmd);
 
        default:
-               return InsetCollapsable::priv_dispatch(bv, cmd);
+               return InsetCollapsable::priv_dispatch(cur, cmd);
        }
 }
 
index af396197b47a8dbb8878aa4797a1a91a312040d8..3b6b17dab18ed3a0244099a3b95ad44cc261ff1e 100644 (file)
@@ -107,7 +107,7 @@ protected:
        ///
        virtual
        DispatchResult
-       priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+       priv_dispatch(LCursor & cur, FuncRequest const & cmd);
 private:
        friend class InsetBoxParams;
 
index 37c3b81ec3ce987d1ef56ecfd23b9160239329ac..40003e9687fb868ae5b045da23045238f2c81c1e 100644 (file)
@@ -15,7 +15,7 @@
 #include "buffer.h"
 #include "bufferparams.h"
 #include "BranchList.h"
-#include "BufferView.h"
+#include "cursor.h"
 #include "dispatchresult.h"
 #include "funcrequest.h"
 #include "gettext.h"
@@ -111,7 +111,7 @@ bool InsetBranch::showInsetDialog(BufferView * bv) const
 
 
 DispatchResult
-InsetBranch::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetBranch::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
        switch (cmd.action) {
        case LFUN_INSET_MODIFY: {
@@ -124,22 +124,22 @@ InsetBranch::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
 
        case LFUN_MOUSE_PRESS:
                if (cmd.button() != mouse_button::button3)
-                       return InsetCollapsable::priv_dispatch(bv, cmd);
+                       return InsetCollapsable::priv_dispatch(cur, cmd);
                return DispatchResult(false);
 
        case LFUN_INSET_DIALOG_UPDATE:
-               InsetBranchMailer(*this).updateDialog(&bv);
+               InsetBranchMailer(*this).updateDialog(&cur.bv());
                return DispatchResult(true);
 
        case LFUN_MOUSE_RELEASE:
                if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
-                       InsetBranchMailer(*this).showDialog(&bv);
+                       InsetBranchMailer(*this).showDialog(&cur.bv());
                        return DispatchResult(true);
                }
-               return InsetCollapsable::priv_dispatch(bv, cmd);
+               return InsetCollapsable::priv_dispatch(cur, cmd);
 
        default:
-               return InsetCollapsable::priv_dispatch(bv, cmd);
+               return InsetCollapsable::priv_dispatch(cur, cmd);
        }
 }
 
index 89dcb076b0ddf09793672342788a9e79f2732ed8..50f2ccb7c450115a30d336257da0e45915276c6f 100644 (file)
@@ -83,7 +83,7 @@ protected:
        ///
        virtual
        DispatchResult
-       priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+       priv_dispatch(LCursor & cur, FuncRequest const & cmd);
 private:
        friend class InsetBranchParams;
 
index 9189d35544e92b212fa9e9ea4454d87c44d3ecfe..5ad33db650168c286d0c373a8a868b95cbea4f2f 100644 (file)
@@ -148,7 +148,7 @@ void InsetCharStyle::getDrawFont(LyXFont & font) const
 
 
 DispatchResult
-InsetCharStyle::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetCharStyle::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
        setStatus(Inlined);
        switch (cmd.action) {
@@ -157,10 +157,10 @@ InsetCharStyle::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                                has_label_ = !has_label_;
                                return DispatchResult(true);
                        }
-                       inset.dispatch(bv, cmd);
+                       inset.dispatch(cur, cmd);
                        return DispatchResult(true, true);
                default:
-                       return InsetCollapsable::priv_dispatch(bv, cmd);
+                       return InsetCollapsable::priv_dispatch(cur, cmd);
        }
 }
 
@@ -235,7 +235,7 @@ int InsetCharStyle::docbook(Buffer const &, std::ostream & os,
 
 
 int InsetCharStyle::plaintext(Buffer const &, std::ostream & os,
-                             OutputParams const & runparams) const
+                             OutputParams const & /*runparams*/) const
 {
        return outputVerbatim(os, inset);
 }
index 58104ba35684afdfb97549b117385ad0b84020ef..135b1fa77c7e8f86c236e048768a7e9260a6b1d9 100644 (file)
@@ -87,7 +87,7 @@ protected:
        ///
        virtual
        DispatchResult
-       priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+       priv_dispatch(LCursor & cur, FuncRequest const & cmd);
 
 private:
        friend class InsetCharStyleParams;
index b850b4d42b350c142211e2b05d8c983afc93628c..bec1a74371693e9f0a88ea50cedf3c748ac22ed8 100644 (file)
@@ -214,11 +214,11 @@ FuncRequest InsetCollapsable::adjustCommand(FuncRequest const & cmd)
 
 
 DispatchResult
-InsetCollapsable::lfunMouseRelease(BufferView & bv, FuncRequest const & cmd)
+InsetCollapsable::lfunMouseRelease(LCursor & cur, FuncRequest const & cmd)
 {
        if (cmd.button() == mouse_button::button3) {
                lyxerr << "InsetCollapsable::lfunMouseRelease 0" << endl;
-               showInsetDialog(&bv);
+               showInsetDialog(&cur.bv());
                return DispatchResult(true, true);
        }
 
@@ -226,7 +226,7 @@ InsetCollapsable::lfunMouseRelease(BufferView & bv, FuncRequest const & cmd)
        case Collapsed:
                lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl;
                setStatus(Open);
-               edit(&bv, true);
+               edit(cur, true);
                return DispatchResult(true, true);
 
        case Open:
@@ -236,10 +236,10 @@ InsetCollapsable::lfunMouseRelease(BufferView & bv, FuncRequest const & cmd)
                        return DispatchResult(false, FINISHED_RIGHT);
                }
                lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl;
-               return inset.dispatch(bv, adjustCommand(cmd));
+               return inset.dispatch(cur, adjustCommand(cmd));
 
        case Inlined:
-               return inset.dispatch(bv, cmd);
+               return inset.dispatch(cur, cmd);
        }
 
        return DispatchResult(true, true);
@@ -301,17 +301,18 @@ string const InsetCollapsable::getNewLabel(string const & l) const
 }
 
 
-void InsetCollapsable::edit(BufferView * bv, bool left)
+void InsetCollapsable::edit(LCursor & cur, bool left)
 {
        lyxerr << "InsetCollapsable: edit left/right" << endl;
-       inset.edit(bv, left);
+       cur.push(this);
+       inset.edit(cur, left);
        open();
-       bv->fullCursor().push(this);
 }
 
 
-void InsetCollapsable::edit(BufferView * bv, int x, int y)
+void InsetCollapsable::edit(LCursor & cur, int x, int y)
 {
+       cur.push(this);
        lyxerr << "InsetCollapsable: edit xy" << endl;
        if (status_ == Collapsed) {
                setStatus(Open);
@@ -321,33 +322,32 @@ void InsetCollapsable::edit(BufferView * bv, int x, int y)
                else
                        y += inset.ascent() - height_collapsed();
        }
-       inset.edit(bv, x, y);
-       bv->fullCursor().push(this);
+       inset.edit(cur, x, y);
 }
 
 
 DispatchResult
-InsetCollapsable::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetCollapsable::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
        //lyxerr << "\nInsetCollapsable::priv_dispatch (begin): cmd: " << cmd
        //      << "  button y: " << button_dim.y2 << endl;
        switch (cmd.action) {
                case LFUN_MOUSE_PRESS:
                        if (status_ == Inlined)
-                               inset.dispatch(bv, cmd);
+                               inset.dispatch(cur, cmd);
                        else if (status_ == Open && cmd.y > button_dim.y2)
-                               inset.dispatch(bv, adjustCommand(cmd));
+                               inset.dispatch(cur, adjustCommand(cmd));
                        return DispatchResult(true, true);
 
                case LFUN_MOUSE_MOTION:
                        if (status_ == Inlined)
-                               inset.dispatch(bv, cmd);
+                               inset.dispatch(cur, cmd);
                        else if (status_ == Open && cmd.y > button_dim.y2)
-                               inset.dispatch(bv, adjustCommand(cmd));
+                               inset.dispatch(cur, adjustCommand(cmd));
                        return DispatchResult(true, true);
 
                case LFUN_MOUSE_RELEASE:
-                       return lfunMouseRelease(bv, cmd);
+                       return lfunMouseRelease(cur, cmd);
 
                case LFUN_INSET_TOGGLE:
                        if (inset.text_.toggleInset())
@@ -361,9 +361,8 @@ InsetCollapsable::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                        }
 
                default:
-                       return inset.dispatch(bv, adjustCommand(cmd));
+                       return inset.dispatch(cur, adjustCommand(cmd));
        }
-       //lyxerr << "InsetCollapsable::priv_dispatch (end)" << endl;
 }
 
 
index 232e7d00d7254798f37f33004b93474bdea624af..c237e73ced912a408a3a0ebe7f934f7b67637df8 100644 (file)
@@ -121,7 +121,7 @@ protected:
        ///
        virtual
        DispatchResult
-       priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+       priv_dispatch(LCursor & cur, FuncRequest const & cmd);
        ///
        void dimension_collapsed(Dimension &) const;
        ///
@@ -133,13 +133,13 @@ protected:
        ///
        Box const & buttonDim() const;
        ///
-       void edit(BufferView *, bool);
+       void edit(LCursor & cur, bool left);
        ///
-       void edit(BufferView *, int, int);
+       void edit(LCursor & cur, int x, int y);
 
 private:
        ///
-       DispatchResult lfunMouseRelease(BufferView & bv, FuncRequest const &);
+       DispatchResult lfunMouseRelease(LCursor & cur, FuncRequest const & cmd);
        ///
        FuncRequest adjustCommand(FuncRequest const &);
 
index 354acc3831ad09bcc4acf9b8e0e9d3ea2cfc24b4..5e3699be851991a342fadfdf7ccd5f2a0226edde 100644 (file)
@@ -100,7 +100,7 @@ int InsetCommand::docbook(Buffer const &, ostream &,
 
 
 DispatchResult
-InsetCommand::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetCommand::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
        switch (cmd.action) {
        case LFUN_INSET_MODIFY: {
@@ -109,18 +109,18 @@ InsetCommand::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                if (p.getCmdName().empty())
                        return DispatchResult(false);
                setParams(p);
-               bv.update();
+               cur.bv().update();
                return DispatchResult(true, true);
        }
 
        case LFUN_INSET_DIALOG_UPDATE:
-               InsetCommandMailer(cmd.argument, *this).updateDialog(&bv);
+               InsetCommandMailer(cmd.argument, *this).updateDialog(&cur.bv());
                return DispatchResult(true, true);
 
        case LFUN_INSET_DIALOG_SHOW:
        case LFUN_MOUSE_RELEASE: {
                if (!mailer_name_.empty())
-                       InsetCommandMailer(mailer_name_, *this).showDialog(&bv);
+                       InsetCommandMailer(mailer_name_, *this).showDialog(&cur.bv());
                return DispatchResult(true);
        }
 
index c20d3efe0a9af95f6c45df2b1136f51cbed25bb6..ce0b85b629a5666b3c8607bdca5a310223ff6e68 100644 (file)
 #ifndef INSET_LATEXCOMMAND_H
 #define INSET_LATEXCOMMAND_H
 
-
 #include "inset.h"
 #include "insetcommandparams.h"
 #include "render_button.h"
 #include "mailinset.h"
+#include "cursor.h"
+
 
 // Created by Alejandro 970222
 /** Used to insert a LaTeX command automatically
@@ -30,9 +31,7 @@
 class InsetCommand : public InsetOld {
 public:
        ///
-       explicit
-       InsetCommand(InsetCommandParams const &,
-                    std::string const & mailer_name);
+       InsetCommand(InsetCommandParams const &, std::string const & mailer_name);
        ///
        ~InsetCommand();
        ///
@@ -77,7 +76,7 @@ protected:
        ///
        virtual
        DispatchResult
-       priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+       priv_dispatch(LCursor & cur, FuncRequest const & cmd);
        ///
        std::string const getCommand() const { return p_.getCommand(); }
        ///
index 897fc621b067e215083799698d281194666098dc..9e3e6281f578353b6b7da7770f281159313f9b17 100644 (file)
@@ -208,7 +208,7 @@ int InsetERT::docbook(Buffer const &, ostream & os,
 }
 
 
-DispatchResult InsetERT::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+DispatchResult InsetERT::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
        switch (cmd.action) {
 
@@ -237,7 +237,7 @@ DispatchResult InsetERT::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                return DispatchResult(true);
 
        default:
-               return InsetCollapsable::priv_dispatch(bv, cmd);
+               return InsetCollapsable::priv_dispatch(cur, cmd);
        }
 }
 
index a200c7921c43ae63f487c2cfb09104f46d49383c..2782a64d52b871209b5fb239f3178988f042d0c1 100644 (file)
@@ -76,7 +76,7 @@ protected:
        ///
        virtual
        DispatchResult
-       priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+       priv_dispatch(LCursor & cur, FuncRequest const & cmd);
 private:
        ///
        void init();
index 654342b74dc9bd0e12dd3e27b8edac8195ba83bb..3c43adb9ba7f546b9053b6b3743ee55dc58b3842 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "buffer.h"
 #include "BufferView.h"
+#include "cursor.h"
 #include "debug.h"
 #include "dispatchresult.h"
 #include "funcrequest.h"
 #include "support/lyxlib.h"
 #include "support/tostr.h"
 #include "support/translator.h"
+#include "support/std_sstream.h"
 
 #include <boost/bind.hpp>
 
-#include "support/std_sstream.h"
 
 namespace support = lyx::support;
 namespace external = lyx::external;
@@ -441,12 +442,12 @@ void InsetExternal::statusChanged() const
 
 
 DispatchResult
-InsetExternal::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetExternal::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
        switch (cmd.action) {
 
        case LFUN_EXTERNAL_EDIT: {
-               Buffer const & buffer = *bv.buffer();
+               Buffer const & buffer = *cur.bv().buffer();
                InsetExternalParams p;
                InsetExternalMailer::string2params(cmd.argument, buffer, p);
                external::editExternal(p, buffer);
@@ -454,20 +455,20 @@ InsetExternal::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
        }
 
        case LFUN_INSET_MODIFY: {
-               Buffer const & buffer = *bv.buffer();
+               Buffer const & buffer = *cur.bv().buffer();
                InsetExternalParams p;
                InsetExternalMailer::string2params(cmd.argument, buffer, p);
                setParams(p, buffer);
-               bv.update();
+               cur.bv().update();
                return DispatchResult(true, true);
        }
 
        case LFUN_INSET_DIALOG_UPDATE:
-               InsetExternalMailer(*this).updateDialog(&bv);
+               InsetExternalMailer(*this).updateDialog(&cur.bv());
                return DispatchResult(true, true);
 
        case LFUN_MOUSE_RELEASE:
-               InsetExternalMailer(*this).showDialog(&bv);
+               InsetExternalMailer(*this).showDialog(&cur.bv());
                return DispatchResult(true, true);
 
        default:
@@ -476,9 +477,9 @@ InsetExternal::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
 }
 
 
-void InsetExternal::edit(BufferView * bv, bool)
+void InsetExternal::edit(LCursor & cur, bool)
 {
-       InsetExternalMailer(*this).showDialog(bv);
+       InsetExternalMailer(*this).showDialog(&cur.bv());
 }
 
 
index 0f65f54d4f6a32072552a2801a60405d5495a7d7..37114c33af319c99e50097dd616f87d1a92c43b1 100644 (file)
@@ -146,13 +146,13 @@ public:
        ///
        void addPreview(lyx::graphics::PreviewLoader &) const;
        ///
-       void edit(BufferView * bv, bool);
+       void edit(LCursor & cur, bool);
 
 protected:
        ///
        virtual
        DispatchResult
-       priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+       priv_dispatch(LCursor & cur, FuncRequest const & cmd);
 private:
        /** This method is connected to the graphics loader, so we are
         *  informed when the image has been loaded.
index 0ed46be8a3b4131ccfd3318684165f26e29ff323..4e7ba7c409a51306f9cac5f8256f92086b96acc6 100644 (file)
@@ -16,6 +16,7 @@
 #include "buffer.h"
 #include "bufferparams.h"
 #include "BufferView.h"
+#include "cursor.h"
 #include "debug.h"
 #include "dispatchresult.h"
 #include "Floating.h"
@@ -31,7 +32,6 @@
 
 #include "support/lstrings.h"
 #include "support/tostr.h"
-
 #include "support/std_sstream.h"
 
 using lyx::support::contains;
@@ -156,7 +156,7 @@ InsetFloat::~InsetFloat()
 
 
 DispatchResult
-InsetFloat::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetFloat::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
        switch (cmd.action) {
 
@@ -165,18 +165,18 @@ InsetFloat::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                InsetFloatMailer::string2params(cmd.argument, params);
                params_.placement = params.placement;
                params_.wide      = params.wide;
-               wide(params_.wide, bv.buffer()->params());
-               bv.update();
+               wide(params_.wide, cur.bv().buffer()->params());
+               cur.bv().update();
                return DispatchResult(true, true);
        }
 
        case LFUN_INSET_DIALOG_UPDATE: {
-               InsetFloatMailer(*this).updateDialog(&bv);
+               InsetFloatMailer(*this).updateDialog(&cur.bv());
                return DispatchResult(true, true);
        }
 
        default:
-               return InsetCollapsable::priv_dispatch(bv, cmd);
+               return InsetCollapsable::priv_dispatch(cur, cmd);
        }
 }
 
index d738916645967fef887a2d370c7f3009a3dd028f..ee1abdf614cd5e47e24a6075a56eec61a33f843c 100644 (file)
@@ -80,7 +80,7 @@ public:
 protected:
        virtual
        DispatchResult
-       priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+       priv_dispatch(LCursor & cur, FuncRequest const & cmd);
 private:
        ///
        InsetFloatParams params_;
index f9f5e1352f8cb558e7178860bfa9f8e4c67798f1..b6d5c73768dc64d566f18e3d04a716272154f216 100644 (file)
@@ -58,6 +58,7 @@ TODO
 #include "buffer.h"
 #include "BufferView.h"
 #include "converter.h"
+#include "cursor.h"
 #include "debug.h"
 #include "dispatchresult.h"
 #include "format.h"
@@ -79,12 +80,11 @@ TODO
 #include "support/os.h"
 #include "support/systemcall.h"
 #include "support/tostr.h"
+#include "support/std_sstream.h"
 
 #include <boost/bind.hpp>
 #include <boost/tuple/tuple.hpp>
 
-#include "support/std_sstream.h"
-
 namespace support = lyx::support;
 using lyx::support::AbsolutePath;
 using lyx::support::bformat;
@@ -192,26 +192,26 @@ void InsetGraphics::statusChanged() const
 
 
 DispatchResult
-InsetGraphics::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetGraphics::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
        switch (cmd.action) {
        case LFUN_INSET_MODIFY: {
-               Buffer const & buffer = *bv.buffer();
+               Buffer const & buffer = *cur.bv().buffer();
                InsetGraphicsParams p;
                InsetGraphicsMailer::string2params(cmd.argument, buffer, p);
                if (!p.filename.empty()) {
                        setParams(p);
-                       bv.update();
+                       cur.bv().update();
                }
                return DispatchResult(true, true);
        }
 
        case LFUN_INSET_DIALOG_UPDATE:
-               InsetGraphicsMailer(*this).updateDialog(&bv);
+               InsetGraphicsMailer(*this).updateDialog(&cur.bv());
                return DispatchResult(true, true);
 
        case LFUN_MOUSE_RELEASE:
-               InsetGraphicsMailer(*this).showDialog(&bv);
+               InsetGraphicsMailer(*this).showDialog(&cur.bv());
                return DispatchResult(true, true);
 
        default:
@@ -220,9 +220,9 @@ InsetGraphics::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
 }
 
 
-void InsetGraphics::edit(BufferView * bv, bool)
+void InsetGraphics::edit(LCursor & cur, bool)
 {
-       InsetGraphicsMailer(*this).showDialog(bv);
+       InsetGraphicsMailer(*this).showDialog(&cur.bv());
 }
 
 
index bd7b4f08cab0a9f82209578c31f851a54772303e..7c99e11dbdc837d342d391c466fa7dd33a2e2427 100644 (file)
@@ -78,12 +78,12 @@ public:
        ///
        void draw(PainterInfo & pi, int x, int y) const;
        ///
-       void edit(BufferView * bv, bool);
+       void edit(LCursor & cur, bool);
 protected:
        ///
        virtual
        DispatchResult
-       priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+       priv_dispatch(LCursor & cur, FuncRequest const & cmd);
 private:
        ///
        friend class InsetGraphicsMailer;
index e79356d7d9da4edb1f3e0b93420c835cc42625fe..5bfe07ca68eb84183d86c9b4b4daf61a8b8f03b2 100644 (file)
@@ -17,6 +17,7 @@
 #include "bufferlist.h"
 #include "bufferparams.h"
 #include "BufferView.h"
+#include "cursor.h"
 #include "debug.h"
 #include "dispatchresult.h"
 #include "funcrequest.h"
@@ -108,7 +109,7 @@ InsetInclude::~InsetInclude()
 
 
 DispatchResult
-InsetInclude::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetInclude::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
        switch (cmd.action) {
 
@@ -116,23 +117,23 @@ InsetInclude::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                InsetCommandParams p;
                InsetIncludeMailer::string2params(cmd.argument, p);
                if (!p.getCmdName().empty()) {
-                       set(p, *bv.buffer());
-                       bv.update();
+                       set(p, *cur.bv().buffer());
+                       cur.bv().update();
                }
                return DispatchResult(true, true);
        }
 
        case LFUN_INSET_DIALOG_UPDATE:
-               InsetIncludeMailer(*this).updateDialog(&bv);
+               InsetIncludeMailer(*this).updateDialog(&cur.bv());
                return DispatchResult(true, true);
 
        case LFUN_MOUSE_RELEASE:
                if (button_.box().contains(cmd.x, cmd.y))
-                       InsetIncludeMailer(*this).showDialog(&bv);
+                       InsetIncludeMailer(*this).showDialog(&cur.bv());
                return DispatchResult(true, true);
 
        case LFUN_INSET_DIALOG_SHOW:
-               InsetIncludeMailer(*this).showDialog(&bv);
+               InsetIncludeMailer(*this).showDialog(&cur.bv());
                return DispatchResult(true, true);
 
        default:
index 456abb80a848782566247c55fdb6cd43fbcc4022..750b8209d83ee0c0b20daddbbca41360622c0189 100644 (file)
@@ -85,7 +85,7 @@ protected:
        ///
        virtual
        DispatchResult
-       priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+       priv_dispatch(LCursor & cur, FuncRequest const & cmd);
 private:
        /// Slot receiving a signal that the preview is ready to display.
        void statusChanged() const;
index 07a2b287635aff366199b73752f411c8aa744b7e..097b1f04b555580b6db2dcb34faa735560c38350 100644 (file)
@@ -52,7 +52,7 @@ string const InsetLabel::getScreenLabel(Buffer const &) const
 
 
 DispatchResult
-InsetLabel::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetLabel::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
        switch (cmd.action) {
 
@@ -63,15 +63,15 @@ InsetLabel::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                        return DispatchResult(false);
                bool clean = true;
                if (p.getContents() != params().getContents())
-                       clean = bv.ChangeRefsIfUnique(params().getContents(),
+                       clean = cur.bv().ChangeRefsIfUnique(params().getContents(),
                                                       p.getContents());
                setParams(p);
-               bv.update();
+               cur.bv().update();
                return DispatchResult(true, true);
        }
 
        default:
-               return InsetCommand::priv_dispatch(bv, cmd);
+               return InsetCommand::priv_dispatch(cur, cmd);
        }
 }
 
index 8bdea8a29178e0382292fa4ffba3d126086f4bae..6ee2e374e231f261d70ad45be2d85ff0db00f507 100644 (file)
@@ -44,7 +44,7 @@ protected:
        ///
        virtual
        DispatchResult
-       priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+       priv_dispatch(LCursor & cur, FuncRequest const & cmd);
 };
 
 #endif
index 58c3546c889da6c5e2ae07a9ee4713be132e1915..fb1d4cf68d2b6e2170af48e9e8629f24274612ae 100644 (file)
@@ -15,6 +15,7 @@
 #include "insetnote.h"
 
 #include "BufferView.h"
+#include "cursor.h"
 #include "debug.h"
 #include "dispatchresult.h"
 #include "funcrequest.h"
@@ -184,30 +185,30 @@ bool InsetNote::showInsetDialog(BufferView * bv) const
 
 
 DispatchResult
-InsetNote::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetNote::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
        switch (cmd.action) {
 
        case LFUN_INSET_MODIFY: {
                InsetNoteMailer::string2params(cmd.argument, params_);
                setButtonLabel();
-               bv.update();
+               cur.bv().update();
                return DispatchResult(true, true);
        }
 
        case LFUN_INSET_DIALOG_UPDATE:
-               InsetNoteMailer(*this).updateDialog(&bv);
+               InsetNoteMailer(*this).updateDialog(&cur.bv());
                return DispatchResult(true, true);
 
        case LFUN_MOUSE_RELEASE:
                if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
-                       InsetNoteMailer(*this).showDialog(&bv);
+                       InsetNoteMailer(*this).showDialog(&cur.bv());
                        return DispatchResult(true, true);
                }
-               return InsetCollapsable::priv_dispatch(bv, cmd);
+               return InsetCollapsable::priv_dispatch(cur, cmd);
 
        default:
-               return InsetCollapsable::priv_dispatch(bv, cmd);
+               return InsetCollapsable::priv_dispatch(cur, cmd);
        }
 }
 
index bf58055955f2f75678feeedc4609a1ee23b2c6c3..7beaac4648281f64bd464f981c8ef0460e3eb23f 100644 (file)
@@ -77,7 +77,7 @@ protected:
        ///
        virtual
        DispatchResult
-       priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+       priv_dispatch(LCursor & cur, FuncRequest const & cmd);
 private:
        friend class InsetNoteParams;
 
index da32aa0c4abc1d94891b94fd51c500304a12c830..942ba6b3353d0f0e48c02b75a7d6181a152a5f02 100644 (file)
@@ -40,19 +40,19 @@ InsetRef::InsetRef(InsetRef const & ir)
 
 
 DispatchResult
-InsetRef::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetRef::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
        switch (cmd.action) {
        case LFUN_MOUSE_PRESS:
                // Eventually trigger dialog with button 3 not 1
                if (cmd.button() == mouse_button::button3)
-                       bv.owner()->dispatch(FuncRequest(LFUN_REF_GOTO, getContents()));
+                       cur.bv().owner()->dispatch(FuncRequest(LFUN_REF_GOTO, getContents()));
                else
-                       InsetCommandMailer("ref", *this).showDialog(&bv);
+                       InsetCommandMailer("ref", *this).showDialog(&cur.bv());
                return DispatchResult(true, true);
 
        default:
-               return InsetCommand::priv_dispatch(bv, cmd);
+               return InsetCommand::priv_dispatch(cur, cmd);
        }
 }
 
index dc13a021eb59183f4b2fde9ee7b598fb37edf470..d2beb0e338119cbad71665b858df1e7558c25dcb 100644 (file)
@@ -70,7 +70,7 @@ protected:
        ///
        virtual
        DispatchResult
-       priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+       priv_dispatch(LCursor & cur, FuncRequest const & cmd);
 private:
        ///
        bool isLatex;
index d7851585cdf7e63a9cef879b56f745cc6508f678..583b83efd40d556183416dd948673f4ffc019987 100644 (file)
@@ -375,17 +375,17 @@ string const InsetTabular::editMessage() const
 }
 
 
-void InsetTabular::updateLocal(BufferView & bv) const
+void InsetTabular::updateLocal(LCursor & cur) const
 {
-       bv.update();
-       resetPos(bv);
+       cur.bv().update();
+       resetPos(cur);
 }
 
-extern LCursor theTempCursor;
 
+extern CursorBase theTempCursor;
 
 
-void InsetTabular::lfunMousePress(BufferView & bv, FuncRequest const & cmd)
+void InsetTabular::lfunMousePress(LCursor & cur, FuncRequest const & cmd)
 {
        if (hasSelection() && cmd.button() == mouse_button::button3)
                return;
@@ -396,93 +396,92 @@ void InsetTabular::lfunMousePress(BufferView & bv, FuncRequest const & cmd)
        lyxerr << "# InsetTabular::lfunMousePress cell: " << cell << endl;
        if (cell == -1) {
                tablemode = true;
-               bv.fullCursor(theTempCursor);
-               bv.fullCursor().push(this);
-               bv.fullCursor().idx() = cell;
+               cur.cursor_ = theTempCursor;
+               cur.push(this);
+               cur.idx() = cell;
        } else {
                tablemode = false;
-               setPos(bv, cmd.x, cmd.y);
-               bv.fullCursor(theTempCursor);
-               bv.fullCursor().idx() = cell;
+               setPos(cur.bv(), cmd.x, cmd.y);
+               cur.cursor_ = theTempCursor;
+               cur.idx() = cell;
        }
-       lyxerr << bv.cursor() << endl;
+       cur.resetAnchor();
+       lyxerr << cur << endl;
 
        if (cmd.button() == mouse_button::button2)
-               dispatch(bv, FuncRequest(LFUN_PASTESELECTION, "paragraph"));
+               dispatch(cur, FuncRequest(LFUN_PASTESELECTION, "paragraph"));
 }
 
 
-void InsetTabular::lfunMouseMotion(BufferView & bv, FuncRequest const & cmd)
+void InsetTabular::lfunMouseMotion(LCursor & cur, FuncRequest const & cmd)
 {
        int const actcell = getCell(cmd.x + xo_, cmd.y + yo_);
        lyxerr << "# InsetTabular::lfunMouseMotion cell: " << actcell << endl;
 
-       setPos(bv, cmd.x, cmd.y);
+       setPos(cur.bv(), cmd.x, cmd.y);
        if (!hasSelection()) {
                setSelection(actcell, actcell);
-               bv.setSelection();
+               cur.setSelection();
        } else {
-               bv.cursor().idx() = actcell;
+               cur.idx() = actcell;
                setSelection(sel_cell_start, actcell);
                tablemode = (sel_cell_start != actcell);
        }
 }
 
 
-void InsetTabular::lfunMouseRelease(BufferView & bv, FuncRequest const & cmd)
+void InsetTabular::lfunMouseRelease(LCursor & cur, FuncRequest const & cmd)
 {
        int const actcell = getCell(cmd.x + xo_, cmd.y + yo_);
        lyxerr << "# InsetTabular::lfunMouseRelease cell: " << actcell << endl;
        if (cmd.button() == mouse_button::button3)
-               InsetTabularMailer(*this).showDialog(&bv);
+               InsetTabularMailer(*this).showDialog(&cur.bv());
 }
 
 
-void InsetTabular::edit(BufferView * view, bool left)
+void InsetTabular::edit(LCursor & cur, bool left)
 {
-       BufferView & bv = *view;
        lyxerr << "InsetTabular::edit: " << this << endl;
        finishUndo();
        //tablemode = false;
        int cell;
        if (left) {
-               if (isRightToLeft(bv))
+               if (isRightToLeft(cur))
                        cell = tabular.getLastCellInRow(0);
                else
                        cell = 0;
        } else {
-               if (isRightToLeft(bv))
+               if (isRightToLeft(cur))
                        cell = tabular.getFirstCellInRow(tabular.rows()-1);
                else
                        cell = tabular.getNumberOfCells() - 1;
        }
        clearSelection();
-       resetPos(bv);
-       bv.fitCursor();
-       bv.fullCursor().push(this);
-       bv.fullCursor().idx() = cell;
-       lyxerr << bv.cursor() << endl;
+       resetPos(cur);
+       cur.bv().fitCursor();
+       cur.push(this);
+       cur.idx() = cell;
 }
 
 
-void InsetTabular::edit(BufferView * bv, int x, int y)
+void InsetTabular::edit(LCursor & cur, int x, int y)
 {
        lyxerr << "InsetTabular::edit: " << this << " first cell "
                << &tabular.cell_info[0][0].inset << endl;
 
        finishUndo();
-       setPos(*bv, x, y);
+       setPos(cur.bv(), x, y);
        clearSelection();
        finishUndo();
        //int xx = cursorx_ - xo_ + tabular.getBeginningOfTextInCell(actcell);
-       bv->fullCursor().push(this);
+       cur.push(this);
        //if (x > xx)
        //      activateCellInset(bv, cell, x - xx, y - cursory_);
 }
 
 
 DispatchResult
-InsetTabular::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetTabular::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
        lyxerr << "# InsetTabular::dispatch: " << cmd
                << " tablemode: " << tablemode << endl;
@@ -491,53 +490,51 @@ InsetTabular::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
        switch (cmd.action) {
 
        case LFUN_MOUSE_PRESS:
-               lfunMousePress(bv, cmd);
+               lfunMousePress(cur, cmd);
                return DispatchResult(true, true);
 
        case LFUN_MOUSE_MOTION:
-               lfunMouseMotion(bv, cmd);
+               lfunMouseMotion(cur, cmd);
                return DispatchResult(true, true);
 
        case LFUN_MOUSE_RELEASE:
-               lfunMouseRelease(bv, cmd);
+               lfunMouseRelease(cur, cmd);
                return DispatchResult(true, true);
 
        default:
                break;
        }
 
-       CursorSlice & cur = bv.cursor();
-
        if (!tablemode) {
                
-               int cell = cur.idx_;
+               int cell = cur.idx();
                lyxerr << "# InsetTabular::dispatch: A " << cur << endl;
-               result = tabular.getCellInset(cell).dispatch(bv, cmd);
+               result = tabular.getCellInset(cell).dispatch(cur, cmd);
 
                switch (result.val()) {
                case FINISHED:
-                       if (movePrevCell(bv, cur))
+                       if (movePrevCell(cur))
                                result = DispatchResult(true, true);
                        else
                                result = DispatchResult(false, FINISHED);
                        break;
 
                case FINISHED_RIGHT:
-                       if (moveNextCell(bv, cur))
+                       if (moveNextCell(cur))
                                result = DispatchResult(true, true);
                        else
                                result = DispatchResult(false, FINISHED_RIGHT);
                        break;
 
                case FINISHED_UP:
-                       if (moveUpLock(bv, cur))
+                       if (moveUpLock(cur))
                                result = DispatchResult(true, true);
                        else
                                result = DispatchResult(false, FINISHED_UP);
                        break;
 
                case FINISHED_DOWN:
-                       if (moveDownLock(bv, cur))
+                       if (moveDownLock(cur))
                                result = DispatchResult(true, true);
                        else
                                result = DispatchResult(false, FINISHED_UP);
@@ -557,79 +554,80 @@ InsetTabular::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                case LFUN_CELL_BACKWARD:
                case LFUN_CELL_FORWARD:
                        if (cmd.action == LFUN_CELL_FORWARD)
-                               moveNextCell(bv, cur);
+                               moveNextCell(cur);
                        else
-                               movePrevCell(bv, cur);
+                               movePrevCell(cur);
                        clearSelection();
                        return result;
 
                case LFUN_SCROLL_INSET:
                        if (!cmd.argument.empty()) {
                                if (cmd.argument.find('.') != cmd.argument.npos)
-                                       scroll(bv, static_cast<float>(strToDbl(cmd.argument)));
+                                       scroll(cur.bv(), static_cast<float>(strToDbl(cmd.argument)));
                                else
-                                       scroll(bv, strToInt(cmd.argument));
-                               bv.update();
+                                       scroll(cur.bv(), strToInt(cmd.argument));
+                               cur.bv().update();
                                return DispatchResult(true, true);
                        }
 
                case LFUN_RIGHTSEL: {
-                       int const start = hasSelection() ? sel_cell_start : cur.idx_;
-                       if (tabular.isLastCellInRow(cur.idx_)) {
-                               setSelection(start, cur.idx_);
+                       int const start = hasSelection() ? sel_cell_start : cur.idx();
+                       if (tabular.isLastCellInRow(cur.idx())) {
+                               setSelection(start, cur.idx());
                                break;
                        }
 
-                       int end = cur.idx_;
+                       int end = cur.idx();
                        // if we are starting a selection, only select
                        // the current cell at the beginning
                        if (hasSelection()) {
-                               moveRight(bv, cur);
-                               end = cur.idx_;
+                               moveRight(cur);
+                               end = cur.idx();
                        }
                        setSelection(start, end);
                        break;
                }
 
                case LFUN_RIGHT:
-                       if (!moveRightLock(bv, cur))
+                       if (!moveRightLock(cur))
                                result = DispatchResult(false, FINISHED_RIGHT);
                        clearSelection();
                        break;
 
                case LFUN_LEFTSEL: {
-                       int const start = hasSelection() ? sel_cell_start : cur.idx_;
-                       if (tabular.isFirstCellInRow(cur.idx_)) {
-                               setSelection(start, cur.idx_);
+                       int const start = hasSelection() ? sel_cell_start : cur.idx();
+                       if (tabular.isFirstCellInRow(cur.idx())) {
+                               setSelection(start, cur.idx());
                                break;
                        }
 
-                       int end = cur.idx_;
+                       int end = cur.idx();
                        // if we are starting a selection, only select
                        // the current cell at the beginning
                        if (hasSelection()) {
-                               moveLeft(bv, cur);
-                               end = cur.idx_;
+                               moveLeft(cur);
+                               end = cur.idx();
                        }
                        setSelection(start, end);
                        break;
                }
 
                case LFUN_LEFT:
-                       if (!moveLeftLock(bv, cur))
+                       if (!moveLeftLock(cur))
                                result = DispatchResult(false, FINISHED);
                        clearSelection();
                        break;
 
                case LFUN_DOWNSEL: {
-                       int const start = hasSelection() ? sel_cell_start : cur.idx_;
-                       int const ocell = cur.idx_;
+                       int const start = hasSelection() ? sel_cell_start : cur.idx();
+                       int const ocell = cur.idx();
                        // if we are starting a selection, only select
                        // the current cell at the beginning
                        if (hasSelection()) {
-                               moveDown(bv, cur);
+                               moveDown(cur);
                                if (ocell == sel_cell_end ||
-                                               tabular.column_of_cell(ocell) > tabular.column_of_cell(cur.idx_))
+                                               tabular.column_of_cell(ocell) >
+tabular.column_of_cell(cur.idx()))
                                        setSelection(start, tabular.getCellBelow(sel_cell_end));
                                else
                                        setSelection(start, tabular.getLastCellBelow(sel_cell_end));
@@ -640,20 +638,21 @@ InsetTabular::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                }
 
                case LFUN_DOWN:
-                       if (!moveDown(bv, cur))
+                       if (!moveDown(cur))
                                result = DispatchResult(false, FINISHED_DOWN);
                        clearSelection();
                        break;
 
                case LFUN_UPSEL: {
-                       int const start = hasSelection() ? sel_cell_start : cur.idx_;
-                       int const ocell = cur.idx_;
+                       int const start = hasSelection() ? sel_cell_start : cur.idx();
+                       int const ocell = cur.idx();
                        // if we are starting a selection, only select
                        // the current cell at the beginning
                        if (hasSelection()) {
-                               moveUp(bv, cur);
+                               moveUp(cur);
                                if (ocell == sel_cell_end ||
-                                               tabular.column_of_cell(ocell) > tabular.column_of_cell(cur.idx_))
+                                               tabular.column_of_cell(ocell) >
+tabular.column_of_cell(cur.idx()))
                                        setSelection(start, tabular.getCellAbove(sel_cell_end));
                                else
                                        setSelection(start, tabular.getLastCellAbove(sel_cell_end));
@@ -664,7 +663,7 @@ InsetTabular::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                }
 
                case LFUN_UP:
-                       if (!moveUp(bv, cur))
+                       if (!moveUp(cur))
                                result = DispatchResult(false, FINISHED_DOWN);
                        clearSelection();
                        break;
@@ -672,29 +671,29 @@ InsetTabular::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                case LFUN_NEXT: {
                        if (hasSelection())
                                clearSelection();
-                       int actcell = bv.cursor().idx();
+                       int actcell = cur.idx();
                        int actcol = tabular.column_of_cell(actcell);
                        int column = actcol;
-                       if (bv.top_y() + bv.painter().paperHeight()
+                       if (cur.bv().top_y() + cur.bv().painter().paperHeight()
                                        < yo_ + tabular.getHeightOfTabular())
                        {
-                               bv.scrollDocView(bv.top_y() + bv.painter().paperHeight());
+                               cur.bv().scrollDocView(
+                                       cur.bv().top_y() + cur.bv().painter().paperHeight());
                                cur.idx() = tabular.getCellBelow(first_visible_cell) + column;
                        } else {
                                cur.idx() = tabular.getFirstCellInRow(tabular.rows() - 1) + column;
                        }
-                       resetPos(bv);
+                       resetPos(cur);
                        break;
                }
 
                case LFUN_PRIOR: {
                        if (hasSelection())
                                clearSelection();
-                       int actcell = bv.cursor().idx();
-                       int actcol = tabular.column_of_cell(actcell);
-                       int column = actcol;
+                       int column = tabular.column_of_cell(cur.idx());
                        if (yo_ < 0) {
-                               bv.scrollDocView(bv.top_y() - bv.painter().paperHeight());
+                               cur.bv().scrollDocView( 
+                                       cur.bv().top_y() - cur.bv().painter().paperHeight());
                                if (yo_ > 0)
                                        cur.idx() = column;
                                else
@@ -702,7 +701,7 @@ InsetTabular::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                        } else {
                                cur.idx() = column;
                        }
-                       resetPos(bv);
+                       resetPos(cur);
                        break;
                }
 
@@ -732,23 +731,23 @@ InsetTabular::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                        break;
 
                case LFUN_LAYOUT_TABULAR:
-                       InsetTabularMailer(*this).showDialog(&bv);
+                       InsetTabularMailer(*this).showDialog(&cur.bv());
                        break;
 
                case LFUN_INSET_DIALOG_UPDATE:
-                       InsetTabularMailer(*this).updateDialog(&bv);
+                       InsetTabularMailer(*this).updateDialog(&cur.bv());
                        break;
 
                case LFUN_TABULAR_FEATURE:
-                       if (!tabularFeatures(bv, cmd.argument))
+                       if (!tabularFeatures(cur, cmd.argument))
                                result = DispatchResult(false);
                        break;
 
                // insert file functions
                case LFUN_FILE_INSERT_ASCII_PARA:
                case LFUN_FILE_INSERT_ASCII: {
-                       string tmpstr = getContentsOfAsciiFile(&bv, cmd.argument, false);
-                       if (!tmpstr.empty() && !insertAsciiString(bv, tmpstr, false))
+                       string tmpstr = getContentsOfAsciiFile(&cur.bv(), cmd.argument, false);
+                       if (!tmpstr.empty() && !insertAsciiString(cur.bv(), tmpstr, false))
                                result = DispatchResult(false);
                        break;
                }
@@ -767,26 +766,26 @@ InsetTabular::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                        break;
 
                case LFUN_CUT:
-                       if (copySelection(bv)) {
-                               recordUndo(bv, Undo::DELETE);
-                               cutSelection(bv.buffer()->params());
+                       if (copySelection(cur.bv())) {
+                               recordUndo(cur, Undo::DELETE);
+                               cutSelection(cur.bv().buffer()->params());
                        }
                        break;
 
                case LFUN_DELETE:
-                       recordUndo(bv, Undo::DELETE);
-                       cutSelection(bv.buffer()->params());
+                       recordUndo(cur, Undo::DELETE);
+                       cutSelection(cur.bv().buffer()->params());
                        break;
 
                case LFUN_COPY:
                        if (!hasSelection())
                                break;
                        finishUndo();
-                       copySelection(bv);
+                       copySelection(cur.bv());
                        break;
 
                case LFUN_PASTESELECTION: {
-                       string const clip = bv.getClipboard();
+                       string const clip = cur.bv().getClipboard();
                        if (clip.empty())
                                break;
                        if (clip.find('\t') != string::npos) {
@@ -814,7 +813,7 @@ InsetTabular::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                                maxCols = max(cols, maxCols);
 
                                paste_tabular.reset(
-                                       new LyXTabular(bv.buffer()->params(), rows, maxCols));
+                                       new LyXTabular(cur.bv().buffer()->params(), rows, maxCols));
 
                                string::size_type op = 0;
                                int cell = 0;
@@ -848,7 +847,7 @@ InsetTabular::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                                if (cell < cells && op < len)
                                        paste_tabular->getCellInset(cell).
                                                setText(clip.substr(op, len-op), font);
-                       } else if (!insertAsciiString(bv, clip, true))
+                       } else if (!insertAsciiString(cur.bv(), clip, true))
                        {
                                // so that the clipboard is used and it goes on
                                // to default
@@ -860,8 +859,8 @@ InsetTabular::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
 
                case LFUN_PASTE:
                        if (hasPasteBuffer()) {
-                               recordUndo(bv, Undo::INSERT);
-                               pasteSelection(bv);
+                               recordUndo(cur, Undo::INSERT);
+                               pasteSelection(cur.bv());
                                break;
                        }
                        // fall through
@@ -877,8 +876,8 @@ InsetTabular::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                        break;
                }
 
-               updateLocal(bv);
-               InsetTabularMailer(*this).updateDialog(&bv);
+               updateLocal(cur);
+               InsetTabularMailer(*this).updateDialog(&cur.bv());
        }
 
        if (cmd.action == LFUN_INSET_TOGGLE) {
@@ -1013,7 +1012,7 @@ void InsetTabular::setPos(BufferView & bv, int x, int y) const
 
        cursorx_ = lx - tabular.getWidthOfColumn(actcell) + xo_ + 2;
 #endif
-       resetPos(bv);
+       resetPos(bv.cursor());
 }
 
 
@@ -1031,7 +1030,7 @@ int InsetTabular::getCellXPos(int cell) const
 }
 
 
-void InsetTabular::resetPos(BufferView &) const
+void InsetTabular::resetPos(LCursor &) const
 {
 #if 0
 #ifdef WITH_WARNINGS
@@ -1041,8 +1040,9 @@ void InsetTabular::resetPos(BufferView &) const
        if (in_reset_pos > 0)
                return;
 
+       BufferView & bv = cur.bv();
        int cell = 0;
-       int actcell = bv->cursor().cell();
+       int actcell = cur.cell();
        int actcol = tabular.column_of_cell(actcell);
        int actrow = 0;
        cursory_ = 0;
@@ -1066,19 +1066,19 @@ void InsetTabular::resetPos(BufferView &) const
                tabular.getWidthOfTabular() < bv->workWidth()-20)
        {
                scroll(bv, 0.0F);
-               updateLocal(bv);
+               updateLocal(cur);
        } else if (cursorx_ - offset > 20 &&
                   cursorx_ - offset + tabular.getWidthOfColumn(actcell)
                   > bv.workWidth() - 20) {
                scroll(&bv, - tabular.getWidthOfColumn(actcell) - 20);
-               updateLocal(bv);
+               updateLocal(cur);
        } else if (cursorx_ - offset < 20) {
                scroll(&bv, 20 - cursorx_ + offset);
-               updateLocal(bv);
+               updateLocal(cur);
        } else if (scroll() && xo_ > 20 &&
                   xo_ + tabular.getWidthOfTabular() > bv->workWidth() - 20) {
                scroll(&bv, old_x - cursorx_);
-               updateLocal(bv);
+               updateLocal(cur);
        }
        InsetTabularMailer(*this).updateDialog(bv);
        in_reset_pos = 0;
@@ -1086,147 +1086,143 @@ void InsetTabular::resetPos(BufferView &) const
 }
 
 
-bool InsetTabular::moveRight(BufferView & bv, CursorSlice & cur)
+bool InsetTabular::moveRight(LCursor & cur)
 {
-       bool moved = isRightToLeft(bv)
-               ? movePrevCell(bv, cur) : moveNextCell(bv, cur);
+       bool moved = isRightToLeft(cur) ? movePrevCell(cur) : moveNextCell(cur);
        if (!moved)
                return false;
-       resetPos(bv);
+       resetPos(cur);
        return true;
 }
 
 
-bool InsetTabular::moveRightLock(BufferView & bv, CursorSlice & cur)
+bool InsetTabular::moveRightLock(LCursor & cur)
 {
-       bool moved = isRightToLeft(bv)
-               ? movePrevCell(bv, cur) : moveNextCell(bv, cur);
+       bool moved = isRightToLeft(cur) ? movePrevCell(cur) : moveNextCell(cur);
        if (!moved)
                return false;
-       activateCellInset(bv, cur.idx_, false);
+       activateCellInset(cur, cur.idx(), false);
        return true;
 }
 
 
-bool InsetTabular::moveLeft(BufferView & bv, CursorSlice & cur)
+bool InsetTabular::moveLeft(LCursor & cur)
 {
-       bool moved = isRightToLeft(bv)
-               ? moveNextCell(bv, cur) : movePrevCell(bv, cur);
+       bool moved = isRightToLeft(cur) ? moveNextCell(cur) : movePrevCell(cur);
        if (!moved)
                return false;
-       resetPos(bv);
+       resetPos(cur);
        return true;
 }
 
 
-bool InsetTabular::moveLeftLock(BufferView & bv, CursorSlice & cur)
+bool InsetTabular::moveLeftLock(LCursor & cur)
 {
-       bool moved = isRightToLeft(bv)
-               ? moveNextCell(bv, cur) : movePrevCell(bv, cur);
+       bool moved = isRightToLeft(cur) ? moveNextCell(cur) : movePrevCell(cur);
        if (!moved)
                return false;
-       activateCellInset(bv, cur.idx_, true);
+       activateCellInset(cur, cur.idx(), true);
        return true;
 }
 
 
-bool InsetTabular::moveUp(BufferView & bv, CursorSlice & cur)
+bool InsetTabular::moveUp(LCursor & cur)
 {
-       if (tabular.row_of_cell(cur.idx_) == 0)
+       if (tabular.row_of_cell(cur.idx()) == 0)
                return false;
-       cur.idx_ = tabular.getCellAbove(cur.idx_);
-       resetPos(bv);
+       cur.idx() = tabular.getCellAbove(cur.idx());
+       resetPos(cur);
        return true;
 }
 
 
-bool InsetTabular::moveUpLock(BufferView & bv, CursorSlice & cur)
+bool InsetTabular::moveUpLock(LCursor & cur)
 {
-       if (tabular.row_of_cell(cur.idx_) == 0)
+       if (tabular.row_of_cell(cur.idx()) == 0)
                return false;
-       cur.idx_ = tabular.getCellAbove(cur.idx_);
-       resetPos(bv);
-       activateCellInset(bv, cur.idx_, bv.x_target(), 0);
+       cur.idx() = tabular.getCellAbove(cur.idx());
+       resetPos(cur);
+       activateCellInset(cur, cur.idx(), cur.x_target(), 0);
        return true;
 }
 
 
-bool InsetTabular::moveDown(BufferView & bv, CursorSlice & cur)
+bool InsetTabular::moveDown(LCursor & cur)
 {
-       if (tabular.row_of_cell(cur.idx_) == tabular.rows() - 1)
+       if (tabular.row_of_cell(cur.idx()) == tabular.rows() - 1)
                return false;
-       cur.idx_ = tabular.getCellBelow(cur.idx_);
-       resetPos(bv);
+       cur.idx() = tabular.getCellBelow(cur.idx());
+       resetPos(cur);
        return true;
 }
 
 
-bool InsetTabular::moveDownLock(BufferView & bv, CursorSlice & cur)
+bool InsetTabular::moveDownLock(LCursor & cur)
 {
-       if (tabular.row_of_cell(cur.idx_) == tabular.rows() - 1)
+       if (tabular.row_of_cell(cur.idx()) == tabular.rows() - 1)
                return false;
-       cur.idx_ = tabular.getCellBelow(cur.idx_);
-       resetPos(bv);
-       activateCellInset(bv, cur.idx_, bv.x_target());
+       cur.idx() = tabular.getCellBelow(cur.idx());
+       resetPos(cur);
+       activateCellInset(cur, cur.idx(), cur.x_target());
        return true;
 }
 
 
-bool InsetTabular::moveNextCell(BufferView & bv, CursorSlice & cur)
+bool InsetTabular::moveNextCell(LCursor & cur)
 {
        lyxerr << "InsetTabular::moveNextCell 1 cur: " << cur << endl;
-       if (isRightToLeft(bv)) {
-               if (tabular.isFirstCellInRow(cur.idx_)) {
-                       int row = tabular.row_of_cell(cur.idx_);
+       if (isRightToLeft(cur)) {
+               if (tabular.isFirstCellInRow(cur.idx())) {
+                       int row = tabular.row_of_cell(cur.idx());
                        if (row == tabular.rows() - 1)
                                return false;
-                       cur.idx_ = tabular.getLastCellInRow(row);
-                       cur.idx_ = tabular.getCellBelow(cur.idx_);
+                       cur.idx() = tabular.getLastCellInRow(row);
+                       cur.idx() = tabular.getCellBelow(cur.idx());
                } else {
-                       if (cur.idx_ == 0)
+                       if (cur.idx() == 0)
                                return false;
-                       --cur.idx_;
+                       --cur.idx();
                }
        } else {
-               if (tabular.isLastCell(cur.idx_))
+               if (tabular.isLastCell(cur.idx()))
                        return false;
-               ++cur.idx_;
+               ++cur.idx();
        }
-       cur.par_ = 0;
-       cur.pos_ = 0;
+       cur.par() = 0;
+       cur.pos() = 0;
        lyxerr << "InsetTabular::moveNextCell 2 cur: " << cur << endl;
-       resetPos(bv);
+       resetPos(cur);
        return true;
 }
 
 
-bool InsetTabular::movePrevCell(BufferView & bv, CursorSlice & cur)
+bool InsetTabular::movePrevCell(LCursor & cur)
 {
-       if (isRightToLeft(bv)) {
-               if (tabular.isLastCellInRow(cur.idx_)) {
-                       int row = tabular.row_of_cell(cur.idx_);
+       if (isRightToLeft(cur)) {
+               if (tabular.isLastCellInRow(cur.idx())) {
+                       int row = tabular.row_of_cell(cur.idx());
                        if (row == 0)
                                return false;
-                       cur.idx_ = tabular.getFirstCellInRow(row);
-                       cur.idx_ = tabular.getCellAbove(cur.idx_);
+                       cur.idx() = tabular.getFirstCellInRow(row);
+                       cur.idx() = tabular.getCellAbove(cur.idx());
                } else {
-                       if (tabular.isLastCell(cur.idx_))
+                       if (tabular.isLastCell(cur.idx()))
                                return false;
-                       ++cur.idx_;
+                       ++cur.idx();
                }
        } else {
-               if (cur.idx_ == 0) // first cell
+               if (cur.idx() == 0) // first cell
                        return false;
-               --cur.idx_;
+               --cur.idx();
        }
-       cur.par_ = 0;
-       cur.pos_ = 0;
-       resetPos(bv);
+       cur.par() = 0;
+       cur.pos() = 0;
+       resetPos(cur);
        return true;
 }
 
 
-bool InsetTabular::tabularFeatures(BufferView & bv, string const & what)
+bool InsetTabular::tabularFeatures(LCursor & cur, std::string const & what)
 {
        LyXTabular::Feature action = LyXTabular::LAST_ACTION;
 
@@ -1246,7 +1242,7 @@ bool InsetTabular::tabularFeatures(BufferView & bv, string const & what)
 
        string const val =
                ltrim(what.substr(tabularFeature[i].feature.length()));
-       tabularFeatures(bv, action, val);
+       tabularFeatures(cur, action, val);
        return true;
 }
 
@@ -1274,10 +1270,11 @@ void checkLongtableSpecial(LyXTabular::ltType & ltt,
 } // anon namespace
 
 
-void InsetTabular::tabularFeatures(BufferView & bv,
+void InsetTabular::tabularFeatures(LCursor & cur,
        LyXTabular::Feature feature, string const & value)
 {
-       int actcell = bv.cursor().idx();
+       BufferView & bv = cur.bv();
+       int actcell = cur.idx();
        int sel_col_start;
        int sel_col_end;
        int sel_row_start;
@@ -1332,7 +1329,7 @@ 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);
        }
-       recordUndo(bv, Undo::ATOMIC);
+       recordUndo(cur, Undo::ATOMIC);
 
        int row =  tabular.row_of_cell(actcell);
        int column = tabular.column_of_cell(actcell);
@@ -1346,10 +1343,10 @@ void InsetTabular::tabularFeatures(BufferView & bv,
                tabular.setColumnPWidth(actcell, len);
                if (len.zero()
                    && tabular.getAlignment(actcell, true) == LYX_ALIGN_BLOCK)
-                       tabularFeatures(bv, LyXTabular::ALIGN_CENTER, string());
+                       tabularFeatures(cur, LyXTabular::ALIGN_CENTER, string());
                else if (!len.zero()
                         && tabular.getAlignment(actcell, true) != LYX_ALIGN_BLOCK)
-                       tabularFeatures(bv, LyXTabular::ALIGN_BLOCK, string());
+                       tabularFeatures(cur, LyXTabular::ALIGN_BLOCK, string());
                break;
        }
 
@@ -1600,24 +1597,24 @@ void InsetTabular::tabularFeatures(BufferView & bv,
                break;
        }
 
-       updateLocal(bv);
+       updateLocal(cur);
        InsetTabularMailer(*this).updateDialog(&bv);
 }
 
 
-void InsetTabular::activateCellInset(BufferView & bv, int cell, int x, int y)
+void InsetTabular::activateCellInset(LCursor & cur, int cell, int x, int y)
 {
-       tabular.getCellInset(cell).edit(&bv, x, y);
-       bv.cursor().idx(cell);
-       updateLocal(bv);
+       tabular.getCellInset(cell).edit(cur, x, y);
+       cur.idx() = cell;
+       updateLocal(cur);
 }
 
 
-void InsetTabular::activateCellInset(BufferView & bv, int cell, bool behind)
+void InsetTabular::activateCellInset(LCursor & cur, int cell, bool behind)
 {
-       tabular.getCellInset(cell).edit(&bv, behind);
-       bv.cursor().idx(cell);
-       updateLocal(bv);
+       tabular.getCellInset(cell).edit(cur, behind);
+       cur.idx() = cell;
+       updateLocal(cur);
 }
 
 
@@ -1941,9 +1938,9 @@ bool InsetTabular::cutSelection(BufferParams const & bp)
 }
 
 
-bool InsetTabular::isRightToLeft(BufferView & bv)
+bool InsetTabular::isRightToLeft(LCursor & cur)
 {
-       return bv.getParentLanguage(this)->RightToLeft();
+       return cur.bv().getParentLanguage(this)->RightToLeft();
 }
 
 
index e7c90a4415cb70066a4670f6610e8c54f780f39e..1849f8b407ff4e045ce77247a41063b50523333f 100644 (file)
@@ -82,7 +82,7 @@ public:
        ///
        std::string const editMessage() const;
        ///
-       void updateLocal(BufferView & bv) const;
+       void updateLocal(LCursor & cur) const;
        ///
        bool insetAllowed(InsetOld::Code) const { return true; }
        ///
@@ -112,9 +112,9 @@ public:
        /// get the absolute screen x,y of the cursor
        void getCursorPos(int cell, int & x, int & y) const;
        ///
-       bool tabularFeatures(BufferView & bv, std::string const & what);
+       bool tabularFeatures(LCursor & cur, std::string const & what);
        ///
-       void tabularFeatures(BufferView & bv, LyXTabular::Feature feature,
+       void tabularFeatures(LCursor & cur, LyXTabular::Feature feature,
                             std::string const & val = std::string());
        ///
        void openLayoutDialog(BufferView *) const;
@@ -147,9 +147,9 @@ public:
        /// set the owning buffer
        void buffer(Buffer * buf);
        /// lock cell with given index
-       void edit(BufferView * bv, bool);
+       void edit(LCursor & cur, bool);
        ///
-       void edit(BufferView * bv, int, int);
+       void edit(LCursor & cur, int, int);
        /// can we go further down on mouse click?
        bool descendable() const { return true; }
 
@@ -162,14 +162,14 @@ protected:
        ///
        virtual
        DispatchResult
-       priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+       priv_dispatch(LCursor & cur, FuncRequest const & cmd);
 private:
        ///
-       void lfunMousePress(BufferView & bv, FuncRequest const & cmd);
+       void lfunMousePress(LCursor & cur, FuncRequest const & cmd);
        ///
-       void lfunMouseRelease(BufferView & bv, FuncRequest const & cmd);
+       void lfunMouseRelease(LCursor & cur, FuncRequest const & cmd);
        ///
-       void lfunMouseMotion(BufferView & bv, FuncRequest const & cmd);
+       void lfunMouseMotion(LCursor & cur, FuncRequest const & cmd);
        ///
        void calculate_dimensions_of_cells(MetricsInfo & mi) const;
        ///
@@ -181,33 +181,33 @@ private:
        ///
        void setPos(BufferView &, int x, int y) const;
        ///
-       bool moveRight(BufferView &, CursorSlice & cur);
+       bool moveRight(LCursor & cur);
        ///
-       bool moveLeft(BufferView &, CursorSlice & cur);
+       bool moveLeft(LCursor & cur);
        ///
-       bool moveUp(BufferView &, CursorSlice & cur);
+       bool moveUp(LCursor & cur);
        ///
-       bool moveDown(BufferView &, CursorSlice & cur);
+       bool moveDown(LCursor & cur);
 
        ///
-       bool moveRightLock(BufferView &, CursorSlice & cur);
+       bool moveRightLock(LCursor & cur);
        ///
-       bool moveLeftLock(BufferView &, CursorSlice & cur);
+       bool moveLeftLock(LCursor & cur);
        ///
-       bool moveUpLock(BufferView &, CursorSlice & cur);
+       bool moveUpLock(LCursor & cur);
        ///
-       bool moveDownLock(BufferView &, CursorSlice & cur);
+       bool moveDownLock(LCursor & cur);
 
        ///
-       bool moveNextCell(BufferView &, CursorSlice & cur);
+       bool moveNextCell(LCursor & cur);
        ///
-       bool movePrevCell(BufferView &, CursorSlice & cur);
+       bool movePrevCell(LCursor & cur);
 
 
        ///
        int getCellXPos(int cell) const;
        ///
-       void resetPos(BufferView &) const;
+       void resetPos(LCursor & cur) const;
        ///
        void removeTabularRow();
        ///
@@ -215,9 +215,9 @@ private:
        ///
        void setSelection(int start, int end) const;
        ///
-       void activateCellInset(BufferView &, int cell, int x, int y);
+       void activateCellInset(LCursor &, int cell, int x, int y);
        ///
-       void activateCellInset(BufferView &, int cell, bool behind);
+       void activateCellInset(LCursor &, int cell, bool behind);
        ///
        bool hasPasteBuffer() const;
        ///
@@ -227,7 +227,7 @@ private:
        ///
        bool cutSelection(BufferParams const & bp);
        ///
-       bool isRightToLeft(BufferView &);
+       bool isRightToLeft(LCursor & cur);
        ///
        void getSelection(int cell,
                int & scol, int & ecol, int & srow, int & erow) const;
index cd4953c42ad98dd57e3399e93411bc689f13058f..d243604755736a1b7815715c99c3e3909558b773 100644 (file)
@@ -227,23 +227,37 @@ void InsetText::drawFrame(Painter & pain, int x) const
 }
 
 
-void InsetText::updateLocal(BufferView * bv)
-{
-       if (!bv)
-               return;
-
-       if (!autoBreakRows_ && paragraphs().size() > 1)
-               collapseParagraphs(bv);
+void InsetText::updateLocal(LCursor & cur)
+{
+       if (!autoBreakRows_ && paragraphs().size() > 1) {
+               // collapseParagraphs
+               while (paragraphs().size() > 1) {
+                       ParagraphList::iterator const first = paragraphs().begin();
+                       ParagraphList::iterator second = first;
+                       ++second;
+                       size_t const first_par_size = first->size();
+
+                       if (!first->empty() &&
+                                       !second->empty() &&
+                                       !first->isSeparator(first_par_size - 1)) {
+                               first->insertChar(first_par_size, ' ');
+                       }
+
+                       cur.clearSelection();
+                       mergeParagraph(cur.bv().buffer()->params(), paragraphs(), first);
+               }
+       }
 
-       if (!bv->selection().set())
-               bv->resetAnchor();
+       if (!cur.selection())
+               cur.resetAnchor();
 
-       bv->owner()->view_state_changed();
-       bv->owner()->updateMenubar();
-       bv->owner()->updateToolbar();
-       if (old_par != bv->cursor().par()) {
-               bv->owner()->setLayout(text_.cursorPar()->layout()->name());
-               old_par = bv->cursor().par();
+       LyXView * lv = cur.bv().owner();
+       lv->view_state_changed();
+       lv->updateMenubar();
+       lv->updateToolbar();
+       if (old_par != cur.par()) {
+               lv->setLayout(text_.cursorPar()->layout()->name());
+               old_par = cur.par();
        }
 }
 
@@ -254,57 +268,56 @@ string const InsetText::editMessage() const
 }
 
 
-void InsetText::sanitizeEmptyText(BufferView * bv)
+void InsetText::sanitizeEmptyText(BufferView & bv)
 {
        if (paragraphs().size() == 1
            && paragraphs().begin()->empty()
-           && bv->getParentLanguage(this) != text_.current_font.language()) {
+           && bv.getParentLanguage(this) != text_.current_font.language()) {
                LyXFont font(LyXFont::ALL_IGNORE);
-               font.setLanguage(bv->getParentLanguage(this));
+               font.setLanguage(bv.getParentLanguage(this));
                text_.setFont(font, false);
        }
 }
 
 
-extern LCursor theTempCursor;
+extern CursorBase theTempCursor;
 
 
-void InsetText::edit(BufferView * bv, bool left)
+void InsetText::edit(LCursor & cur, bool left)
 {
        lyxerr << "InsetText: edit left/right" << endl;
        old_par = -1;
-       setViewCache(bv);
+       setViewCache(&cur.bv());
        int const par = left ? 0 : paragraphs().size() - 1;
        int const pos = left ? 0 : paragraphs().back().size();
        text_.setCursor(par, pos);
-       bv->clearSelection();
+       cur.clearSelection();
        finishUndo();
-       sanitizeEmptyText(bv);
-       updateLocal(bv);
-       bv->updateParagraphDialog();
+       sanitizeEmptyText(cur.bv());
+       updateLocal(cur);
+       cur.bv().updateParagraphDialog();
 }
 
 
-void InsetText::edit(BufferView * bv, int x, int y)
+void InsetText::edit(LCursor & cur, int x, int y)
 {
        lyxerr << "InsetText::edit xy" << endl;
        old_par = -1;
-       text_.setCursorFromCoordinates(x - text_.xo_, y + bv->top_y() - text_.yo_);
-       bv->clearSelection();
+       text_.setCursorFromCoordinates(x - text_.xo_, y + cur.bv().top_y() - text_.yo_);
+       cur.clearSelection();
        finishUndo();
-       sanitizeEmptyText(bv);
-       updateLocal(bv);
-       bv->updateParagraphDialog();
+       sanitizeEmptyText(cur.bv());
+       updateLocal(cur);
+       cur.bv().updateParagraphDialog();
 }
 
 
-DispatchResult
-InsetText::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+DispatchResult InsetText::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
        //lyxerr << "InsetText::priv_dispatch (begin), act: "
        //      << cmd.action << " " << endl;
 
-       setViewCache(&bv);
+       setViewCache(&cur.bv());
 
        DispatchResult result;
        result.dispatched(true);
@@ -313,10 +326,13 @@ InsetText::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
 
        switch (cmd.action) {
        case LFUN_MOUSE_PRESS:
-               bv.fullCursor(theTempCursor);
-               // fall through
+               cur.cursor_ = theTempCursor;
+               cur.resetAnchor();
+               result = text_.dispatch(cur, cmd);
+               break;
+
        default:
-               result = text_.dispatch(bv, cmd);
+               result = text_.dispatch(cur, cmd);
                break;
        }
 
@@ -326,7 +342,7 @@ InsetText::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
        if (!was_empty && paragraphs().begin()->empty() &&
            paragraphs().size() == 1) {
                LyXFont font(LyXFont::ALL_IGNORE);
-               font.setLanguage(bv.getParentLanguage(this));
+               font.setLanguage(cur.bv().getParentLanguage(this));
                text_.setFont(font, false);
        }
 
@@ -527,26 +543,6 @@ LyXText * InsetText::getText(int i) const
 }
 
 
-void InsetText::collapseParagraphs(BufferView * bv)
-{
-       while (paragraphs().size() > 1) {
-               ParagraphList::iterator const first = paragraphs().begin();
-               ParagraphList::iterator second = first;
-               ++second;
-               size_t const first_par_size = first->size();
-
-               if (!first->empty() &&
-                   !second->empty() &&
-                   !first->isSeparator(first_par_size - 1)) {
-                       first->insertChar(first_par_size, ' ');
-               }
-
-               bv->clearSelection();
-               mergeParagraph(bv->buffer()->params(), paragraphs(), first);
-       }
-}
-
-
 void InsetText::appendParagraphs(Buffer * buffer, ParagraphList & plist)
 {
 #warning FIXME Check if Changes stuff needs changing here. (Lgb)
index c09f845873a612a17d60c5b2a448963edf74a31f..fafb5d355b3f59283da0119a8a59b091d2b7bfcc 100644 (file)
@@ -144,9 +144,9 @@ public:
        void addPreview(lyx::graphics::PreviewLoader &) const;
 
        ///
-       void edit(BufferView *, bool);
+       void edit(LCursor & cur, bool);
        ///
-       void edit(BufferView *, int, int);
+       void edit(LCursor & cur, int, int);
 
        ///
        int numParagraphs() const { return 1; }
@@ -155,15 +155,14 @@ public:
 
 private:
        ///
-       DispatchResult
-       priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+       DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
        ///
-       void updateLocal(BufferView *);
+       void updateLocal(LCursor &);
        ///
        void init();
        // If the inset is empty set the language of the current font to the
        // language to the surronding text (if different).
-       void sanitizeEmptyText(BufferView *);
+       void sanitizeEmptyText(BufferView &);
        ///
        void setCharFont(Buffer const &, int pos, LyXFont const & font);
        ///
@@ -172,8 +171,6 @@ private:
        void drawFrame(Painter &, int x) const;
        ///
        void clearInset(Painter &, int x, int y) const;
-       ///
-       void collapseParagraphs(BufferView *);
 
        /* Private structures and variables */
        ///
index 9a249fffe5e751f27bf386ab85d877de78a0113f..6cac2c883f58de61e98b6d9a380d5c150d055211 100644 (file)
@@ -15,6 +15,7 @@
 
 #include "buffer.h"
 #include "BufferView.h"
+#include "cursor.h"
 #include "dispatchresult.h"
 #include "funcrequest.h"
 #include "gettext.h"
@@ -60,7 +61,7 @@ std::auto_ptr<InsetBase> InsetVSpace::clone() const
 
 
 DispatchResult
-InsetVSpace::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetVSpace::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
        switch (cmd.action) {
 
@@ -70,11 +71,11 @@ InsetVSpace::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
        }
 
        case LFUN_MOUSE_PRESS:
-               InsetVSpaceMailer(*this).showDialog(&bv);
+               InsetVSpaceMailer(*this).showDialog(&cur.bv());
                return DispatchResult(true, true);
 
        default:
-               return InsetOld::priv_dispatch(bv, cmd);
+               return InsetOld::priv_dispatch(cur, cmd);
        }
 }
 
index 4ce44ce6bf0530b9881605481e5472fafdb3c3ca..1a805d54825dc2cf6ce4f46d4303a3ace5e3050c 100644 (file)
@@ -56,7 +56,7 @@ protected:
        ///
        virtual
        DispatchResult
-       priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+       priv_dispatch(LCursor & cur, FuncRequest const & cmd);
 
 private:
        ///
index 1ea115fb2a79a405290989c5599b23d1b222bbe9..3e08a57637e9c00d28e0fee710f6daa8b2cccffc 100644 (file)
@@ -15,6 +15,7 @@
 #include "buffer.h"
 #include "bufferparams.h"
 #include "BufferView.h"
+#include "cursor.h"
 #include "debug.h"
 #include "dispatchresult.h"
 #include "Floating.h"
@@ -80,7 +81,7 @@ InsetWrap::~InsetWrap()
 
 
 DispatchResult
-InsetWrap::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetWrap::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
        switch (cmd.action) {
        case LFUN_INSET_MODIFY: {
@@ -90,16 +91,16 @@ InsetWrap::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                params_.placement = params.placement;
                params_.width     = params.width;
 
-               bv.update();
+               cur.bv().update();
                return DispatchResult(true, true);
        }
 
        case LFUN_INSET_DIALOG_UPDATE:
-               InsetWrapMailer(*this).updateDialog(&bv);
+               InsetWrapMailer(*this).updateDialog(&cur.bv());
                return DispatchResult(true, true);
 
        default:
-               return InsetCollapsable::priv_dispatch(bv, cmd);
+               return InsetCollapsable::priv_dispatch(cur, cmd);
        }
 }
 
index 60a8872a87b7d0f36c22ed2a30cc1a6f9e257bf4..25d87c086aff9459c4328b5ed6ccf79d017fda83 100644 (file)
@@ -70,7 +70,7 @@ protected:
        ///
        virtual
        DispatchResult
-       priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+       priv_dispatch(LCursor & cur, FuncRequest const & cmd);
 private:
        ///
        InsetWrapParams params_;
index dfd3aedd348734778f4af8fd9e98606f5a94848f..0e0713c301c26dac4052a8b5a7b7bff46c81479e 100644 (file)
@@ -16,6 +16,7 @@
 #include "updatableinset.h"
 
 #include "BufferView.h"
+#include "cursor.h"
 #include "debug.h"
 #include "dispatchresult.h"
 #include "funcrequest.h"
@@ -85,7 +86,7 @@ void UpdatableInset::scroll(BufferView & bv, int offset) const
 
 ///  An updatable inset could handle lyx editing commands
 DispatchResult
-UpdatableInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+UpdatableInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
        switch (cmd.action) {
        case LFUN_MOUSE_RELEASE:
@@ -94,10 +95,10 @@ UpdatableInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
        case LFUN_SCROLL_INSET:
                if (!cmd.argument.empty()) {
                        if (cmd.argument.find('.') != cmd.argument.npos)
-                               scroll(bv, static_cast<float>(strToDbl(cmd.argument)));
+                               scroll(cur.bv(), static_cast<float>(strToDbl(cmd.argument)));
                        else
-                               scroll(bv, strToInt(cmd.argument));
-                       bv.update();
+                               scroll(cur.bv(), strToInt(cmd.argument));
+                       cur.bv().update();
                        return DispatchResult(true, true);
                }
 
index 51382ed94086d18abcdee542d7d133af79b3ef6d..5723fad72015195ed12ad4f1bf424d28acd38a87 100644 (file)
@@ -42,7 +42,7 @@ protected:
        ///  An updatable inset could handle lyx editing commands
        virtual
        DispatchResult
-       priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+       priv_dispatch(LCursor & cur, FuncRequest const & cmd);
        /// scrolls to absolute position in bufferview-workwidth * sx units
        void scroll(BufferView &, float sx) const;
        /// scrolls offset pixels
index 5f5a535bad0ab435d804b6d32fab891e69c5deba..e9e40d78044e597ef39cd67264dfdb2ab2c0f5dc 100644 (file)
@@ -401,7 +401,9 @@ ParIterator::ParIterator(PosIterator const & pos)
 
 void ParIterator::lockPath(BufferView * bv) const
 {
-       bv->fullCursor() = LCursor(*bv);
+       LCursor & cur = bv->cursor();
+       cur.cursor_.clear();
        for (int i = 0, last = size() - 1; i < last; ++i)
-               (*pimpl_->positions[i].it)->inset->edit(bv, true);
+               (*pimpl_->positions[i].it)->inset->edit(cur, true);
+       cur.resetAnchor();
 }
index d8c34ada01f61a9647b8259201e3b3229270cba5..48ac377406df0ff2497807cf0c895cde8df6fd44 100644 (file)
@@ -19,6 +19,7 @@
 #include "buffer.h"
 #include "bufferlist.h"
 #include "BufferView.h"
+#include "cursor.h"
 #include "debug.h"
 #include "gettext.h"
 #include "lastfiles.h"
@@ -358,7 +359,7 @@ void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
 
        // clear the selection
        if (bv->text() == bv->getLyXText())
-               bv->clearSelection();
+               bv->cursor().clearSelection();
        if (asParagraph)
                bv->getLyXText()->insertStringAsParagraphs(tmpstr);
        else
index 65d5843b6b57d968a1011946601f18467fe6b5c8..1cfdc86a48597481d8d2c6cc85db613c62136de7 100644 (file)
@@ -16,7 +16,7 @@
 #include "lyxfind.h"
 
 #include "buffer.h"
-#include "cursor_slice.h"
+#include "cursor.h"
 #include "BufferView.h"
 #include "debug.h"
 #include "iterators.h"
@@ -391,7 +391,7 @@ int replace(BufferView * bv,
 
        text->replaceSelectionWithString(replacestr);
        text->setSelectionRange(replacestr.length());
-       bv->cursor() = fw ? bv->selEnd() : bv->selStart();
+       bv->cursor().current() = fw ? bv->cursor().selEnd() : bv->cursor().selStart();
        bv->buffer()->markDirty();
        find(bv, searchstr, cs, mw, fw);
        bv->update();
index 284f1202b1cb5e8c4c91cfeb5b6b0d8f51d3e750..d4ef9aa8d0e39ec9cdb104cd11d6c44a32a7074f 100644 (file)
@@ -157,7 +157,7 @@ void LyXFunc::handleKeyFunc(kb_action action)
        // actions
        keyseq.clear();
        // copied verbatim from do_accent_char
-       view()->resetAnchor();
+       view()->cursor().resetAnchor();
        view()->update();
 }
 
@@ -320,8 +320,9 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                }
        }
 
-       UpdatableInset * tli = view()->fullCursor().innerInset();
-       InsetTabular * tab = view()->fullCursor().innerInsetTabular();
+       UpdatableInset * tli = view()->cursor().inset()
+               ? view()->cursor().inset()->asUpdatableInset() : 0;
+       InsetTabular * tab = view()->cursor().innerInsetTabular();
 
        // I would really like to avoid having this switch and rather try to
        // encode this in the function itself.
@@ -342,7 +343,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                if (tab && tab->hasSelection())
                        disable = false;
                else
-                       disable = !mathcursor && !view()->selection().set();
+                       disable = !inMathed() && !view()->cursor().selection();
                break;
 
        case LFUN_RUNCHKTEX:
@@ -354,7 +355,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                break;
 
        case LFUN_LAYOUT_TABULAR:
-               disable = !view()->fullCursor().innerInsetTabular();
+               disable = !view()->cursor().innerInsetTabular();
                break;
 
        case LFUN_DEPTH_MIN:
@@ -378,10 +379,10 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
 
        case LFUN_TABULAR_FEATURE:
 #if 0
-               if (mathcursor) {
+               if (inMathed()) {
                        // FIXME: check temporarily disabled
                        // valign code
-                       char align = mathcursor->valign();
+                       char align = mathcursor::valign();
                        if (align == '\0') {
                                disable = true;
                                break;
@@ -398,7 +399,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                } else {
                        disable = true;
 
-                       char align = mathcursor->halign();
+                       char align = mathcursor::halign();
                        if (align == '\0') {
                                disable = true;
                                break;
@@ -413,7 +414,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                        }
                        flag.setOnOff(ev.argument[0] == align);
 
-                       disable = !mathcursor->halign();
+                       disable = !mathcursor::halign();
                        break;
                }
 
@@ -469,7 +470,8 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
 
        case LFUN_INSET_SETTINGS: {
                disable = true;
-               UpdatableInset * inset = view()->fullCursor().innerInset();
+               UpdatableInset * inset = view()->cursor().inset()
+                       ? view()->cursor().inset()->asUpdatableInset() : 0;
 
                if (!inset)
                        break;
@@ -509,8 +511,8 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
        }
 
        case LFUN_MATH_MUTATE:
-               if (mathcursor)
-                       //flag.setOnOff(mathcursor->formula()->hullType() == ev.argument);
+               if (inMathed())
+                       //flag.setOnOff(mathcursor::formula()->hullType() == ev.argument);
                        flag.setOnOff(false);
                else
                        disable = true;
@@ -523,7 +525,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
        case LFUN_MATH_NONUMBER:
        case LFUN_MATH_NUMBER:
        case LFUN_MATH_EXTERN:
-               disable = !mathcursor;
+               disable = !inMathed();
                break;
 
        case LFUN_DIALOG_SHOW: {
@@ -541,8 +543,8 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                        disable = !Exporter::IsExportable(*buf, "dvi") ||
                                lyxrc.print_command == "none";
                } else if (name == "character") {
-                       UpdatableInset * tli = view()->fullCursor().innerInset();
-                       disable = tli && tli->lyxCode() == InsetOld::ERT_CODE;
+                       InsetBase * inset = view()->cursor().inset();
+                       disable = inset && inset->lyxCode() == InsetOld::ERT_CODE;
                } else if (name == "vclog") {
                        disable = !buf->lyxvc().inUse();
                } else if (name == "latexlog") {
@@ -682,7 +684,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                break;
        case LFUN_SPACE_INSERT:
                // slight hack: we know this is allowed in math mode
-               if (!mathcursor)
+               if (!inMathed())
                        code = InsetOld::SPACE_CODE;
                break;
        case LFUN_INSET_DIALOG_SHOW: {
@@ -734,7 +736,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
 
 #ifdef LOCK
        // the font related toggles
-       if (!mathcursor) {
+       if (!inMathed()) {
                LyXFont const & font = view()->getLyXText()->real_current_font;
                switch (ev.action) {
                case LFUN_EMPH:
@@ -759,7 +761,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                        break;
                }
        } else {
-               string tc = mathcursor->getLastCode();
+               string tc = mathcursor::getLastCode();
                switch (ev.action) {
                case LFUN_BOLD:
                        flag.setOnOff(tc == "mathbf");
@@ -864,7 +866,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                case LFUN_ESCAPE: {
                        if (!view()->available())
                                break;
-                       view()->fullCursor().pop();
+                       view()->cursor().pop();
                        // Tell the paragraph dialog that we changed paragraph
                        dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
                        break;
@@ -1097,7 +1099,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                        break;
 
                case LFUN_LAYOUT_TABULAR:
-                       if (InsetTabular * tab = view()->fullCursor().innerInsetTabular())
+                       if (InsetTabular * tab = view()->cursor().innerInsetTabular())
                                tab->openLayoutDialog(view());
                        break;
 
@@ -1291,7 +1293,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                case LFUN_INSET_DIALOG_SHOW: {
                        InsetOld * inset = view()->getLyXText()->getInset();
                        if (inset)
-                               inset->dispatch(*view(), FuncRequest(LFUN_INSET_DIALOG_SHOW));
+                               inset->dispatch(view()->cursor(), FuncRequest(LFUN_INSET_DIALOG_SHOW));
                        break;
                }
 
@@ -1301,7 +1303,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                        InsetBase * inset = owner->getDialogs().getOpenInset(name);
                        if (inset) {
                                FuncRequest fr(LFUN_INSET_DIALOG_UPDATE, func.argument);
-                               inset->dispatch(*view(), fr);
+                               inset->dispatch(view()->cursor(), fr);
                        } else if (name == "paragraph") {
                                dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
                        }
@@ -1439,11 +1441,11 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                        break;
 
                case LFUN_EXTERNAL_EDIT:
-                       InsetExternal().dispatch(*view(), FuncRequest(action, argument));
+                       InsetExternal().dispatch(view()->cursor(), FuncRequest(action, argument));
                        break;
 
                default:
-                       view()->fullCursor().dispatch(FuncRequest(func));
+                       view()->cursor().dispatch(FuncRequest(func));
                        break;
                }
        }
@@ -1453,7 +1455,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
        if (view()->available()) {
                view()->fitCursor();
                view()->update();
-               view()->fullCursor().updatePos();
+               view()->cursor().updatePos();
                // if we executed a mutating lfun, mark the buffer as dirty
                if (!getStatus(func).disabled()
                    && !lyxaction.funcHasFlag(func.action, LyXAction::NoBuffer)
index 87a75db6423746e7bde71f231ec1e005050fa96c..ee0f9e116bc644d42d89accdbd320cb1a8860e22 100644 (file)
@@ -122,7 +122,7 @@ public:
        void draw(PainterInfo & pi, int x, int y) const;
 
        /// try to handle that request
-       DispatchResult dispatch(BufferView & bv, FuncRequest const & cmd);
+       DispatchResult dispatch(LCursor & cur, FuncRequest const & cmd);
 
        BufferView * bv();
 
index d0f9aaab63ae9fe2f807f68c574bf87e072272a4..cdd54a88ccb41feb9ea7b1a0d899fb70cfe00349 100644 (file)
@@ -1,4 +1,8 @@
 
+2004-01-15  André Pönitz  <poenitz@gmx.net>
+
+       * *.[Ch]: Part of IU. Shift stuff from MathCursor and InsetFormula
+       to LCursor and InsetBase.
 
 2004-01-15  André Pönitz  <poenitz@gmx.net>
 
index ca0f0ebb4e06e261b551e78587f1998e7062fa29..8ddd8fbe9aff80b96dc6d302888d40f4f986e5a7 100644 (file)
@@ -55,7 +55,7 @@ void CommandInset::draw(PainterInfo & pi, int x, int y) const
 
 
 DispatchResult
-CommandInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+CommandInset::priv_dispatch(LCursor & bv, FuncRequest const & cmd)
 {
        switch (cmd.action) {
                default:
index 4ac6a413fb05bca56a62a35d22027e9b61c736b2..b724832cc2cb00e127de734e8b5e41224320cf27 100644 (file)
@@ -42,7 +42,7 @@ protected:
        ///
        virtual
        DispatchResult
-       priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+       priv_dispatch(LCursor & cur, FuncRequest const & cmd);
 private:
        std::string name_;
        mutable bool set_label_;
index c80334a0567a390cb38ac229fac79a01571103b2..938990da2573a7fffffd898ebc23bca99f73c0ed 100644 (file)
@@ -42,13 +42,11 @@ using std::auto_ptr;
 using std::endl;
 
 
-InsetFormula::InsetFormula(bool chemistry)
+InsetFormula::InsetFormula()
        : par_(MathAtom(new MathHullInset)),
          preview_(new RenderPreview)
 {
        preview_->connect(boost::bind(&InsetFormula::statusChanged, this));
-       if (chemistry)
-               mutate("chemistry");
 }
 
 
@@ -61,14 +59,6 @@ InsetFormula::InsetFormula(InsetFormula const & other)
 }
 
 
-InsetFormula::InsetFormula(BufferView *)
-       : par_(MathAtom(new MathHullInset)),
-         preview_(new RenderPreview)
-{
-       preview_->connect(boost::bind(&InsetFormula::statusChanged, this));
-}
-
-
 InsetFormula::InsetFormula(string const & data)
        : par_(MathAtom(new MathHullInset)),
          preview_(new RenderPreview)
@@ -178,8 +168,8 @@ namespace {
 
 bool editing_inset(InsetFormula const * inset)
 {
-       return mathcursor &&
-               (const_cast<InsetFormulaBase const *>(mathcursor->formula()) ==
+       return inMathed() &&
+               (const_cast<InsetFormulaBase const *>(mathcursor::formula()) ==
                 inset);
 }
 
@@ -214,7 +204,7 @@ void InsetFormula::draw(PainterInfo & pi, int x, int y) const
                        p.pain.fillRectangle(x, y - a, w, h, LColor::mathbg);
 
                if (editing_inset(this)) {
-                       mathcursor->drawSelection(pi);
+                       mathcursor::drawSelection(pi);
                        //p.pain.rectangle(x, y - a, w, h, LColor::mathframe);
                }
 
index 19acb55cea660525d64b3a5d227ca580b292cd26..add5fb14423d4e15c1d5c4a71dace86fabdb648e 100644 (file)
@@ -25,9 +25,7 @@ class RenderPreview;
 class InsetFormula : public InsetFormulaBase {
 public:
        ///
-       InsetFormula(bool chemistry = false);
-       ///
-       explicit InsetFormula(BufferView *);
+       InsetFormula();
        ///
        explicit InsetFormula(std::string const & data);
        ///
index 78cbdbfc3c43153858732088274cc200fc64c036..f2a31f32e19f557c47e5ff8a9b37d2f449f1b9aa 100644 (file)
@@ -54,21 +54,19 @@ using std::istringstream;
 using std::ostringstream;
 
 
-MathCursor * mathcursor = 0;
-
 namespace {
 
 // local global
 int first_x;
 int first_y;
 
-bool openNewInset(BufferView & bv, UpdatableInset * inset)
+bool openNewInset(LCursor & cur, UpdatableInset * inset)
 {
-       if (!bv.insertInset(inset)) {
+       if (!cur.bv().insertInset(inset)) {
                delete inset;
                return false;
        }
-       inset->edit(&bv, true);
+       inset->edit(cur, true);
        return true;
 }
 
@@ -115,27 +113,27 @@ void InsetFormulaBase::handleFont
 {
        // this whole function is a hack and won't work for incremental font
        // changes...
-       recordUndo(cur.bv(), Undo::ATOMIC);
+       recordUndo(cur, Undo::ATOMIC);
 
        if (cur.inset()->asMathInset()->name() == font)
-               mathcursor->handleFont(cur, font);
+               mathcursor::handleFont(cur, font);
        else {
-               mathcursor->handleNest(cur, createMathInset(font));
-               mathcursor->insert(cur, arg);
+               mathcursor::handleNest(cur, createMathInset(font));
+               mathcursor::insert(cur, arg);
        }
 }
 
 
 void InsetFormulaBase::handleFont2(LCursor & cur, string const & arg)
 {
-       recordUndo(cur.bv(), Undo::ATOMIC);
+       recordUndo(cur, Undo::ATOMIC);
        LyXFont font;
        bool b;
        bv_funcs::string2font(arg, font, b);
        if (font.color() != LColor::inherit) {
                MathAtom at = createMathInset("color");
                asArray(lcolor.getGUIName(font.color()), at.nucleus()->cell(0));
-               mathcursor->handleNest(cur, at, 1);
+               mathcursor::handleNest(cur, at, 1);
        }
 }
 
@@ -153,10 +151,10 @@ string const InsetFormulaBase::editMessage() const
 
 void InsetFormulaBase::insetUnlock(BufferView & bv)
 {
-       if (mathcursor) {
-               if (mathcursor->inMacroMode(bv.fullCursor()))
-                       mathcursor->macroModeClose(bv.fullCursor());
-               releaseMathCursor(bv);
+       if (inMathed()) {
+               if (mathcursor::inMacroMode(bv.cursor()))
+                       mathcursor::macroModeClose(bv.cursor());
+               releaseMathCursor(bv.cursor());
        }
        if (bv.buffer())
                generatePreview(*bv.buffer());
@@ -166,9 +164,9 @@ void InsetFormulaBase::insetUnlock(BufferView & bv)
 
 void InsetFormulaBase::getCursorPos(BufferView & bv, int & x, int & y) const
 {
-       if (mathcursor) {
-               mathcursor->getScreenPos(bv.fullCursor(), x, y);
-               x = mathcursor->targetX(bv.fullCursor());
+       if (inMathed()) {
+               mathcursor::getScreenPos(bv.cursor(), x, y);
+               x = mathcursor::targetX(bv.cursor());
                x -= xo_;
                y -= yo_;
                lyxerr << "InsetFormulaBase::getCursorPos: " << x << ' ' << y << endl;
@@ -182,7 +180,7 @@ void InsetFormulaBase::getCursorPos(BufferView & bv, int & x, int & y) const
 
 void InsetFormulaBase::getCursorDim(int & asc, int & desc) const
 {
-       if (mathcursor) {
+       if (inMathed()) {
                asc = 10;
                desc = 2;
                //math_font_max_dim(font_, asc, des);
@@ -191,42 +189,42 @@ void InsetFormulaBase::getCursorDim(int & asc, int & desc) const
 
 
 DispatchResult
-InsetFormulaBase::lfunMouseRelease(BufferView & bv, FuncRequest const & cmd)
+InsetFormulaBase::lfunMouseRelease(LCursor & cur, FuncRequest const & cmd)
 {
-       if (!mathcursor)
+       if (!inMathed())
                return DispatchResult(false);
-       bv.update();
+       cur.bv().update();
        //lyxerr << "lfunMouseRelease: buttons: " << cmd.button() << endl;
 
        if (cmd.button() == mouse_button::button3) {
                // try to dispatch to enclosed insets first
-               if (!mathcursor->dispatch(bv.fullCursor(), cmd).dispatched()) {
+               if (!mathcursor::dispatch(cur, cmd).dispatched()) {
                        // launch math panel for right mouse button
                        lyxerr << "lfunMouseRelease: undispatched: " << cmd.button() << endl;
-                       bv.owner()->getDialogs().show("mathpanel");
+                       cur.bv().owner()->getDialogs().show("mathpanel");
                }
                return DispatchResult(true, true);
        }
 
        if (cmd.button() == mouse_button::button2) {
                MathArray ar;
-               asArray(bv.getClipboard(), ar);
-               mathcursor->selClear(bv.fullCursor());
-               mathcursor->setScreenPos(bv.fullCursor(), cmd.x + xo_, cmd.y + yo_);
-               mathcursor->insert(bv.fullCursor(), ar);
-               bv.update();
+               asArray(cur.bv().getClipboard(), ar);
+               mathcursor::selClear(cur);
+               mathcursor::setScreenPos(cur, cmd.x + xo_, cmd.y + yo_);
+               mathcursor::insert(cur, ar);
+               cur.bv().update();
                return DispatchResult(true, true);
        }
 
        if (cmd.button() == mouse_button::button1) {
                // try to dispatch to enclosed insets first
-               mathcursor->dispatch(bv.fullCursor(), cmd);
-               bv.stuffClipboard(mathcursor->grabSelection(bv.fullCursor()));
+               mathcursor::dispatch(cur, cmd);
+               cur.bv().stuffClipboard(mathcursor::grabSelection(cur));
                // try to set the cursor
                //delete mathcursor;
                //mathcursor = new MathCursor(bv, this, x == 0);
                //metrics(bv);
-               //mathcursor->setScreenPos(x + xo_, y + yo_);
+               //mathcursor::setScreenPos(x + xo_, y + yo_);
                return DispatchResult(true, true);
        }
 
@@ -235,44 +233,45 @@ InsetFormulaBase::lfunMouseRelease(BufferView & bv, FuncRequest const & cmd)
 
 
 DispatchResult
-InsetFormulaBase::lfunMousePress(BufferView & bv, FuncRequest const & cmd)
+InsetFormulaBase::lfunMousePress(LCursor & cur, FuncRequest const & cmd)
 {
        //lyxerr << "lfunMousePress: buttons: " << cmd.button() << endl;
 
-       if (!mathcursor || mathcursor->formula() != this) {
+       if (!inMathed() || mathcursor::formula() != this) {
                lyxerr[Debug::MATHED] << "re-create cursor" << endl;
-               releaseMathCursor(bv);
-               mathcursor = new MathCursor(&bv, this, cmd.x == 0);
+               releaseMathCursor(cur);
+               mathcursor::formula_ = this;
+               cur.idx() = 0;
                //metrics(bv);
-               mathcursor->setScreenPos(bv.fullCursor(), cmd.x + xo_, cmd.y + yo_);
+               mathcursor::setScreenPos(cur, cmd.x + xo_, cmd.y + yo_);
        }
 
        if (cmd.button() == mouse_button::button3) {
-               mathcursor->dispatch(bv.fullCursor(), cmd);
+               mathcursor::dispatch(cur, cmd);
                return DispatchResult(true, true);
        }
 
        if (cmd.button() == mouse_button::button1) {
                first_x = cmd.x;
                first_y = cmd.y;
-               mathcursor->selClear(bv.fullCursor());
-               mathcursor->setScreenPos(bv.fullCursor(), cmd.x + xo_, cmd.y + yo_);
-               mathcursor->dispatch(bv.fullCursor(), cmd);
+               mathcursor::selClear(cur);
+               mathcursor::setScreenPos(cur, cmd.x + xo_, cmd.y + yo_);
+               mathcursor::dispatch(cur, cmd);
                return DispatchResult(true, true);
        }
 
-       bv.update();
+       cur.bv().update();
        return DispatchResult(true, true);
 }
 
 
 DispatchResult
-InsetFormulaBase::lfunMouseMotion(BufferView & bv, FuncRequest const & cmd)
+InsetFormulaBase::lfunMouseMotion(LCursor & cur, FuncRequest const & cmd)
 {
-       if (!mathcursor)
+       if (!inMathed())
                return DispatchResult(true, true);
 
-       if (mathcursor->dispatch(bv.fullCursor(), FuncRequest(cmd)).dispatched())
+       if (mathcursor::dispatch(cur, FuncRequest(cmd)).dispatched())
                return DispatchResult(true, true);
 
        // only select with button 1
@@ -285,81 +284,89 @@ InsetFormulaBase::lfunMouseMotion(BufferView & bv, FuncRequest const & cmd)
        first_x = cmd.x;
        first_y = cmd.y;
 
-       if (!mathcursor->selection())
-               mathcursor->selStart(bv.fullCursor());
+       if (!cur.selection())
+               mathcursor::selStart(cur);
 
-       mathcursor->setScreenPos(bv.fullCursor(), cmd.x + xo_, cmd.y + yo_);
-       bv.update();
+       mathcursor::setScreenPos(cur, cmd.x + xo_, cmd.y + yo_);
+       cur.bv().update();
        return DispatchResult(true, true);
 }
 
 
-void InsetFormulaBase::edit(BufferView * bv, bool left)
+void InsetFormulaBase::edit(LCursor & cur, bool /*left*/)
 {
        lyxerr << "Called FormulaBase::edit" << endl;
-       releaseMathCursor(*bv);
-       mathcursor = new MathCursor(bv, this, left);
-       bv->fullCursor().push(this);
-       // if that is removed, we won't get the magenta box when entering an
-       // inset for the first time
-       bv->update();
+       mathcursor::formula_ = this;
+       cur.push(this);
+       cur.idx() = 0;
+       cur.pos() = 0;
+#warning FIXME
+       cur.push(par().nucleus()->asHullInset());
+       //cur.idx() = left ? 0 : cur.lastidx();
+       cur.idx() = 0;
+       cur.pos() = 0;
+       cur.resetAnchor();
 }
 
 
-void InsetFormulaBase::edit(BufferView * bv, int x, int y)
+void InsetFormulaBase::edit(LCursor & cur, int x, int y)
 {
        lyxerr << "Called FormulaBase::EDIT with '" << x << ' ' << y << "'" << endl;
-       releaseMathCursor(*bv);
-       mathcursor = new MathCursor(bv, this, true);
+       releaseMathCursor(cur);
        //metrics(bv);
-       mathcursor->setScreenPos(bv->fullCursor(), x + xo_, y + yo_);
-       bv->fullCursor().push(this);
+       cur.push(this);
+       cur.idx() = 0;
+       cur.pos() = 0;
+       mathcursor::setScreenPos(cur, x + xo_, y + yo_);
+       cur.push(par().nucleus()->asHullInset());
+       //cur.idx() = left ? 0 : cur.lastidx();
+       cur.idx() = 0;
+       cur.pos() = 0;
        // if that is removed, we won't get the magenta box when entering an
        // inset for the first time
-       bv->update();
+       cur.bv().update();
 }
 
 
 DispatchResult
-InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetFormulaBase::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
+       return par().nucleus()->dispatch(cur, cmd);
+
        //lyxerr << "InsetFormulaBase::localDispatch: act: " << cmd.action
        //      << " arg: '" << cmd.argument
        //      << "' x: '" << cmd.x
        //      << " y: '" << cmd.y
        //      << "' button: " << cmd.button() << endl;
 
+#if 0
        // delete empty mathbox (LFUN_BACKSPACE and LFUN_DELETE)
        bool remove_inset = false;
-       LCursor & cur = bv.fullCursor();
 
        switch (cmd.action) {
                case LFUN_MOUSE_PRESS:
                        //lyxerr << "Mouse single press" << endl;
-                       return lfunMousePress(bv, cmd);
+                       return lfunMousePress(cur, cmd);
                case LFUN_MOUSE_MOTION:
                        //lyxerr << "Mouse motion" << endl;
-                       return lfunMouseMotion(bv, cmd);
+                       return lfunMouseMotion(cur, cmd);
                case LFUN_MOUSE_RELEASE:
                        //lyxerr << "Mouse single release" << endl;
-                       return lfunMouseRelease(bv, cmd);
+                       return lfunMouseRelease(cur, cmd);
                case LFUN_MOUSE_DOUBLE:
                        //lyxerr << "Mouse double" << endl;
-                       return dispatch(bv, FuncRequest(LFUN_WORDSEL));
+                       return dispatch(cur, FuncRequest(LFUN_WORDSEL));
                default:
                        break;
        }
 
-       if (!mathcursor)
-               return DispatchResult(false);
-
        DispatchResult result(true);
        string argument    = cmd.argument;
        bool sel           = false;
-       bool was_macro     = mathcursor->inMacroMode(cur);
+       bool was_macro     = mathcursor::inMacroMode(cur);
 
-       mathcursor->normalize(cur);
-       mathcursor->touch();
+       mathcursor::normalize(cur);
+       mathcursor::touch();
 
        switch (cmd.action) {
 
@@ -375,45 +382,13 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
        case LFUN_TABULAR_FEATURE:
        case LFUN_PASTESELECTION:
        case LFUN_MATH_LIMITS:
-               recordUndo(bv, Undo::ATOMIC);
-               mathcursor->dispatch(cur, cmd);
-               break;
-
-       case LFUN_RIGHTSEL:
-               sel = true; // fall through...
-       case LFUN_RIGHT:
-               result = mathcursor->right(cur, sel) ?
-                       DispatchResult(true, true) : DispatchResult(false, FINISHED_RIGHT);
-               //lyxerr << "calling scroll 20" << endl;
-               //scroll(&bv, 20);
-               // write something to the minibuffer
-               //bv.owner()->message(mathcursor->info());
-               break;
-
-       case LFUN_LEFTSEL:
-               sel = true; // fall through
-       case LFUN_LEFT:
-               result = mathcursor->left(cur, sel) ?
-                       DispatchResult(true, true) : DispatchResult(false, FINISHED);
-               break;
-
-       case LFUN_UPSEL:
-               sel = true; // fall through
-       case LFUN_UP:
-               result = mathcursor->up(cur, sel) ?
-                       DispatchResult(true, true) : DispatchResult(false, FINISHED_UP);
-               break;
-
-       case LFUN_DOWNSEL:
-               sel = true; // fall through
-       case LFUN_DOWN:
-               result = mathcursor->down(cur, sel) ?
-                       DispatchResult(true, true) : DispatchResult(false, FINISHED_DOWN);
+               recordUndo(cur, Undo::ATOMIC);
+               mathcursor::dispatch(cur, cmd);
                break;
 
        case LFUN_WORDSEL:
-               mathcursor->home(cur, false);
-               mathcursor->end(cur, true);
+               mathcursor::home(cur, false);
+               mathcursor::end(cur, true);
                break;
 
        case LFUN_UP_PARAGRAPHSEL:
@@ -428,7 +403,7 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                sel = true; // fall through
        case LFUN_HOME:
        case LFUN_WORDLEFT:
-               result = mathcursor->home(cur, sel)
+               result = mathcursor::home(cur, sel)
                        ? DispatchResult(true, true) : DispatchResult(true, FINISHED);
                break;
 
@@ -437,7 +412,7 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                sel = true; // fall through
        case LFUN_END:
        case LFUN_WORDRIGHT:
-               result = mathcursor->end(cur, sel)
+               result = mathcursor::end(cur, sel)
                        ? DispatchResult(true, true) : DispatchResult(false, FINISHED_RIGHT);
                break;
 
@@ -456,17 +431,17 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                break;
 
        case LFUN_CELL_FORWARD:
-               mathcursor->idxNext(cur);
+               mathcursor::idxNext(cur);
                break;
 
        case LFUN_CELL_BACKWARD:
-               mathcursor->idxPrev(cur);
+               mathcursor::idxPrev(cur);
                break;
 
        case LFUN_DELETE_WORD_BACKWARD:
        case LFUN_BACKSPACE:
-               recordUndo(bv, Undo::ATOMIC);
-               if (!mathcursor->backspace(cur)) {
+               recordUndo(cur, Undo::ATOMIC);
+               if (!mathcursor::backspace(cur)) {
                        result = DispatchResult(true, FINISHED);
                        remove_inset = true;
                }
@@ -474,8 +449,8 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
 
        case LFUN_DELETE_WORD_FORWARD:
        case LFUN_DELETE:
-               recordUndo(bv, Undo::ATOMIC);
-               if (!mathcursor->erase(cur)) {
+               recordUndo(cur, Undo::ATOMIC);
+               if (!mathcursor::erase(cur)) {
                        result = DispatchResult(true, FINISHED);
                        remove_inset = true;
                }
@@ -491,7 +466,7 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                int y = 0;
                istringstream is(cmd.argument.c_str());
                is >> x >> y;
-               mathcursor->setScreenPos(cur, x, y);
+               mathcursor::setScreenPos(cur, x, y);
                break;
        }
 
@@ -500,19 +475,19 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                istringstream is(cmd.argument.c_str());
                is >> n;
                if (was_macro)
-                       mathcursor->macroModeClose(cur);
-               recordUndo(bv, Undo::ATOMIC);
-               mathcursor->selPaste(cur, n);
+                       mathcursor::macroModeClose(cur);
+               recordUndo(cur, Undo::ATOMIC);
+               mathcursor::selPaste(cur, n);
                break;
        }
 
        case LFUN_CUT:
-               recordUndo(bv, Undo::DELETE);
-               mathcursor->selCut(cur);
+               recordUndo(cur, Undo::DELETE);
+               mathcursor::selCut(cur);
                break;
 
        case LFUN_COPY:
-               mathcursor->selCopy(cur);
+               mathcursor::selCopy(cur);
                break;
 
 
@@ -522,8 +497,8 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                if (cmd.argument.empty()) {
                        // do superscript if LyX handles
                        // deadkeys
-                       recordUndo(bv, Undo::ATOMIC);
-                       mathcursor->script(cur, true);
+                       recordUndo(cur, Undo::ATOMIC);
+                       mathcursor::script(cur, true);
                }
                break;
 
@@ -561,8 +536,8 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
        case LFUN_DEFAULT:      handleFont(cur, cmd.argument, "textnormal"); break;
 
        case LFUN_MATH_MODE:
-               if (mathcursor->currentMode(cur) == MathInset::TEXT_MODE)
-                       mathcursor->niceInsert(cur, MathAtom(new MathHullInset("simple")));
+               if (mathcursor::currentMode(cur) == MathInset::TEXT_MODE)
+                       mathcursor::niceInsert(cur, MathAtom(new MathHullInset("simple")));
                else
                        handleFont(cur, cmd.argument, "textrm");
                //cur.owner()->message(_("math text mode toggled"));
@@ -571,14 +546,14 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
        case LFUN_MATH_SIZE:
 #if 0
                if (!arg.empty()) {
-                       recordUndo(bv, Undo::ATOMIC);
-                       mathcursor->setSize(arg);
+                       recordUndo(cur, Undo::ATOMIC);
+                       mathcursor::setSize(arg);
                }
 #endif
                break;
 
        case LFUN_INSERT_MATRIX: {
-               recordUndo(bv, Undo::ATOMIC);
+               recordUndo(cur, Undo::ATOMIC);
                unsigned int m = 1;
                unsigned int n = 1;
                string v_align;
@@ -588,7 +563,7 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                m = max(1u, m);
                n = max(1u, n);
                v_align += 'c';
-               mathcursor->niceInsert(cur,
+               mathcursor::niceInsert(cur,
                        MathAtom(new MathArrayInset("array", m, n, v_align[0], h_align)));
                break;
        }
@@ -602,19 +577,19 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                        ls = '(';
                if (rs.empty())
                        rs = ')';
-               recordUndo(bv, Undo::ATOMIC);
-               mathcursor->handleNest(cur, MathAtom(new MathDelimInset(ls, rs)));
+               recordUndo(cur, Undo::ATOMIC);
+               mathcursor::handleNest(cur, MathAtom(new MathDelimInset(ls, rs)));
                break;
        }
 
        case LFUN_SPACE_INSERT:
        case LFUN_MATH_SPACE:
-               recordUndo(bv, Undo::ATOMIC);
-               mathcursor->insert(cur, MathAtom(new MathSpaceInset(",")));
+               recordUndo(cur, Undo::ATOMIC);
+               mathcursor::insert(cur, MathAtom(new MathSpaceInset(",")));
                break;
 
        case LFUN_UNDO:
-               bv.owner()->message(_("Invalid action in math mode!"));
+               cur.bv().owner()->message(_("Invalid action in math mode!"));
                break;
 
 
@@ -624,8 +599,8 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
 
        case LFUN_INSET_ERT:
                // interpret this as if a backslash was typed
-               recordUndo(bv, Undo::ATOMIC);
-               mathcursor->interpret(cur, '\\');
+               recordUndo(cur, Undo::ATOMIC);
+               mathcursor::interpret(cur, '\\');
                break;
 
        case LFUN_BREAKPARAGRAPH:
@@ -638,31 +613,31 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
 // handling such that "self-insert" works on "arbitrary stuff" too, and
 // math-insert only handles special math things like "matrix".
        case LFUN_INSERT_MATH:
-               recordUndo(bv, Undo::ATOMIC);
-               mathcursor->niceInsert(cur, argument);
+               recordUndo(cur, Undo::ATOMIC);
+               mathcursor::niceInsert(cur, argument);
                break;
 
        case -1:
        case LFUN_SELFINSERT:
                if (!argument.empty()) {
-                       recordUndo(bv, Undo::ATOMIC);
+                       recordUndo(cur, Undo::ATOMIC);
                        if (argument.size() == 1)
-                               result = mathcursor->interpret(cur, argument[0])
+                               result = mathcursor::interpret(cur, argument[0])
                                        ? DispatchResult(true, true) : DispatchResult(false, FINISHED_RIGHT);
                        else
-                               mathcursor->insert(cur, argument);
+                               mathcursor::insert(cur, argument);
                }
                break;
 
        case LFUN_ESCAPE:
-               if (mathcursor->selection())
-                       mathcursor->selClear(cur);
+               if (cur.selection())
+                       mathcursor::selClear(cur);
                else
                        result = DispatchResult(false);
                break;
 
        case LFUN_INSET_TOGGLE:
-               mathcursor->insetToggle(cur);
+               mathcursor::insetToggle(cur);
                break;
 
        case LFUN_DIALOG_SHOW:
@@ -680,21 +655,21 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                if (data.empty())
                        result = DispatchResult(false);
                else
-                       bv.owner()->getDialogs().show(name, data, 0);
+                       cur.bv().owner()->getDialogs().show(name, data, 0);
                break;
        }
 
        case LFUN_INSET_APPLY: {
                string const name = cmd.getArg(0);
-               InsetBase * base = bv.owner()->getDialogs().getOpenInset(name);
+               InsetBase * base = cur.bv().owner()->getDialogs().getOpenInset(name);
 
                if (base) {
                        FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument);
-                       result = base->dispatch(bv, fr);
+                       result = base->dispatch(cur, fr);
                } else {
                        MathArray ar;
                        if (createMathInset_fromDialogStr(cmd.argument, ar)) {
-                               mathcursor->insert(cur, ar);
+                               mathcursor::insert(cur, ar);
                                result = DispatchResult(true, true);
                        } else {
                                result = DispatchResult(false);
@@ -706,7 +681,7 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
        case LFUN_WORD_REPLACE:
        case LFUN_WORD_FIND: {
                result = 
-                       searchForward(&bv, cmd.getArg(0), false, false)
+                       searchForward(&cur.bv(), cmd.getArg(0), false, false)
                                ? DispatchResult(true, true) : DispatchResult(false);
                break;
        }
@@ -716,39 +691,42 @@ InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
        }
 
        if (result == DispatchResult(true, true))
-               bv.update();
+               cur.bv().update();
 
-       mathcursor->normalize(cur);
-       mathcursor->touch();
+       mathcursor::normalize(cur);
+       mathcursor::touch();
 
-       BOOST_ASSERT(mathcursor);
+       BOOST_ASSERT(inMathed());
 
        if (result.dispatched()) {
-               revealCodes(bv);
-               bv.stuffClipboard(mathcursor->grabSelection(cur));
+               revealCodes(cur);
+               cur.bv().stuffClipboard(mathcursor::grabSelection(cur));
        } else {
-               releaseMathCursor(bv);
+               releaseMathCursor(cur);
                if (remove_inset)
-                       bv.owner()->dispatch(FuncRequest(LFUN_DELETE));
+                       cur.bv().owner()->dispatch(FuncRequest(LFUN_DELETE));
        }
 
        return result;  // original version
+#endif
 }
 
 
-void InsetFormulaBase::revealCodes(BufferView & bv) const
+void InsetFormulaBase::revealCodes(LCursor & cur) const
 {
-       if (!mathcursor)
+       if (!inMathed())
                return;
-       bv.owner()->message(mathcursor->info(bv.fullCursor()));
+       ostringstream os;
+       cur.info(os);
+       cur.bv().owner()->message(os.str());
 /*
        // write something to the minibuffer
        // translate to latex
-       mathcursor->markInsert(bv);
+       mathcursor::markInsert(bv);
        ostringstream os;
        write(NULL, os);
        string str = os.str();
-       mathcursor->markErase(bv);
+       mathcursor::markErase(bv);
        string::size_type pos = 0;
        string res;
        for (string::iterator it = str.begin(); it != str.end(); ++it) {
@@ -806,6 +784,7 @@ int InsetFormulaBase::xhigh() const
 bool InsetFormulaBase::searchForward(BufferView * bv, string const & str,
                                     bool, bool)
 {
+       return false;
 #ifdef WITH_WARNINGS
 #warning pretty ugly
 #endif
@@ -830,10 +809,8 @@ bool InsetFormulaBase::searchForward(BufferView * bv, string const & str,
                CursorSlice & top = it.back();
                MathArray const & a = top.asMathInset()->cell(top.idx_);
                if (a.matchpart(ar, top.pos_)) {
-                       delete mathcursor;
-                       mathcursor = new MathCursor(bv, this, true);
-                       //metrics(bv);
-                       mathcursor->setSelection(bv->fullCursor(), it, ar.size());
+                       mathcursor::formula_ = this;
+                       mathcursor::setSelection(bv->cursor(), it, ar.size());
                        current = it;
                        top.pos_ += ar.size();
                        bv->update();
@@ -863,13 +840,13 @@ bool InsetFormulaBase::display() const
 
 string InsetFormulaBase::selectionAsString(BufferView & bv) const
 {
-       return mathcursor ? mathcursor->grabSelection(bv.fullCursor()) : string();
+       return inMathed() ? mathcursor::grabSelection(bv.cursor()) : string();
 }
 
 /////////////////////////////////////////////////////////////////////
 
 
-void mathDispatchCreation(BufferView & bv, FuncRequest const & cmd,
+void mathDispatchCreation(LCursor & cur, FuncRequest const & cmd,
        bool display)
 {
        // use selection if available..
@@ -878,19 +855,19 @@ void mathDispatchCreation(BufferView & bv, FuncRequest const & cmd,
        //      sel = "";
        //else
 
-       string sel = bv.getLyXText()->selectionAsString(*bv.buffer(), false);
+       string sel =
+               cur.bv().getLyXText()->selectionAsString(*cur.bv().buffer(), false);
 
        if (sel.empty()) {
-               InsetFormula * f = new InsetFormula(&bv);
-               if (openNewInset(bv, f)) {
-                       bv.fullCursor().innerInset()->
-                               dispatch(bv, FuncRequest(LFUN_MATH_MUTATE, "simple"));
+               InsetFormula * f = new InsetFormula;
+               if (openNewInset(cur, f)) {
+                       cur.inset()->dispatch(cur, FuncRequest(LFUN_MATH_MUTATE, "simple"));
                        // don't do that also for LFUN_MATH_MODE unless you want end up with
                        // always changing to mathrm when opening an inlined inset
                        // -- I really hate "LyXfunc overloading"...
                        if (display)
-                               f->dispatch(bv, FuncRequest(LFUN_MATH_DISPLAY));
-                       f->dispatch(bv, FuncRequest(LFUN_INSERT_MATH, cmd.argument));
+                               f->dispatch(cur, FuncRequest(LFUN_MATH_DISPLAY));
+                       f->dispatch(cur, FuncRequest(LFUN_INSERT_MATH, cmd.argument));
                }
        } else {
                // create a macro if we see "\\newcommand" somewhere, and an ordinary
@@ -901,30 +878,30 @@ void mathDispatchCreation(BufferView & bv, FuncRequest const & cmd,
                        f = new InsetFormula(sel);
                else
                        f = new InsetFormulaMacro(sel);
-               bv.getLyXText()->cutSelection(true, false);
-               openNewInset(bv, f);
+               cur.bv().getLyXText()->cutSelection(true, false);
+               openNewInset(cur, f);
        }
        cmd.message(N_("Math editor mode"));
 }
 
 
-void mathDispatch(BufferView & bv, FuncRequest const & cmd)
+void mathDispatch(LCursor & cur, FuncRequest const & cmd)
 {
-       if (!bv.available())
+       if (!cur.bv().available())
                return;
 
        switch (cmd.action) {
 
                case LFUN_MATH_DISPLAY:
-                       mathDispatchCreation(bv, cmd, true);
+                       mathDispatchCreation(cur, cmd, true);
                        break;
 
                case LFUN_MATH_MODE:
-                       mathDispatchCreation(bv, cmd, false);
+                       mathDispatchCreation(cur, cmd, false);
                        break;
 
                case LFUN_MATH_IMPORT_SELECTION:
-                       mathDispatchCreation(bv, cmd, false);
+                       mathDispatchCreation(cur, cmd, false);
                        break;
 
                case LFUN_MATH_MACRO:
@@ -936,18 +913,17 @@ void mathDispatch(BufferView & bv, FuncRequest const & cmd)
                                int const nargs = s1.empty() ? 0 : atoi(s1);
                                string const s2 = token(s, ' ', 2);
                                string const type = s2.empty() ? "newcommand" : s2;
-                               openNewInset(bv, new InsetFormulaMacro(token(s, ' ', 0), nargs, s2));
+                               openNewInset(cur, new InsetFormulaMacro(token(s, ' ', 0), nargs, s2));
                        }
                        break;
 
                case LFUN_INSERT_MATH:
                case LFUN_INSERT_MATRIX:
                case LFUN_MATH_DELIM: {
-                       InsetFormula * f = new InsetFormula(&bv);
-                       if (openNewInset(bv, f)) {
-                               UpdatableInset * inset = bv.fullCursor().innerInset();
-                               inset->dispatch(bv, FuncRequest(LFUN_MATH_MUTATE, "simple"));
-                               inset->dispatch(bv, cmd);
+                       InsetFormula * f = new InsetFormula;
+                       if (openNewInset(cur, f)) {
+                               cur.inset()->dispatch(cur, FuncRequest(LFUN_MATH_MUTATE, "simple"));
+                               cur.inset()->dispatch(cur, cmd);
                        }
                        break;
                }
index 7de324fac880831c8b1745b2a0df499186c9526c..d9854faa6817e3f37a5dd9e9e3cdaab8d8692272 100644 (file)
@@ -72,7 +72,7 @@ public:
        ///
        virtual void mutateToText();
        ///
-       virtual void revealCodes(BufferView & bv) const;
+       virtual void revealCodes(LCursor & cur) const;
        ///
        virtual EDITABLE editable() const { return HIGHLY_EDITABLE; }
        ///
@@ -80,24 +80,23 @@ public:
        // return the selection as std::string
        std::string selectionAsString(BufferView & bv) const;
        ///
-       void edit(BufferView * bv, bool);
+       void edit(LCursor & cur, bool);
        ///
-       void edit(BufferView * bv, int, int);
+       void edit(LCursor & cur, int, int);
 protected:
        /// To allow transparent use of math editing functions
-       virtual
-       DispatchResult priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+       DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
 private:
        /// unimplemented
        void operator=(const InsetFormulaBase &);
        /// common base for handling accents
        void handleAccent(BufferView & bv, std::string const & arg, std::string const & name);
        /// lfun handler
-       DispatchResult lfunMousePress(BufferView &, FuncRequest const &);
+       DispatchResult lfunMousePress(LCursor &, FuncRequest const &);
        ///
-       DispatchResult lfunMouseRelease(BufferView &, FuncRequest const &);
+       DispatchResult lfunMouseRelease(LCursor &, FuncRequest const &);
        ///
-       DispatchResult lfunMouseMotion(BufferView &, FuncRequest const &);
+       DispatchResult lfunMouseMotion(LCursor &, FuncRequest const &);
 
 protected:
 
@@ -117,9 +116,9 @@ protected:
 
 // We don't really mess want around with mathed stuff outside mathed.
 // So do it here.
-void mathDispatch(BufferView & bv, FuncRequest const & cmd);
+void mathDispatch(LCursor & cur, FuncRequest const & cmd);
 
 ///
-void releaseMathCursor(BufferView & bv);
+void releaseMathCursor(LCursor & cur);
 
 #endif
index 9ea39270e6d16d04a3ef8ebe3b5b243a4048d863..69a2ad36d1619a613b0bf40153c3d3087e73eaab 100644 (file)
@@ -35,9 +35,6 @@ using std::auto_ptr;
 using std::ostream;
 
 
-extern MathCursor * mathcursor;
-
-
 InsetFormulaMacro::InsetFormulaMacro()
 {
        // inset name is inherited from Inset
@@ -173,9 +170,9 @@ void InsetFormulaMacro::draw(PainterInfo & p, int x, int y) const
        pi.pain.fillRectangle(x, a, w, h, LColor::mathmacrobg);
        pi.pain.rectangle(x, a, w, h, LColor::mathframe);
 
-       if (mathcursor &&
-                       const_cast<InsetFormulaBase const *>(mathcursor->formula()) == this)
-               mathcursor->drawSelection(pi);
+       if (inMathed() &&
+                       const_cast<InsetFormulaBase const *>(mathcursor::formula()) == this)
+               mathcursor::drawSelection(pi);
 
        pi.pain.text(x + 2, y, prefix(), font);
 
index da3f51fa1f2f23541b546bfbde1bfbf15a4ebe6a..cd65ed5b798c3da05f0260e83ce0d8230cd66d93 100644 (file)
@@ -53,28 +53,48 @@ using std::ostringstream;
 limited_stack<string> theCutBuffer;
 
 
-MathCursor::MathCursor(BufferView * bv, InsetFormulaBase * formula, bool front)
-       :       formula_(formula), autocorrect_(false), selection_(false)
-{
-       front ? first(bv->fullCursor()) : last(bv->fullCursor());
-}
+namespace mathcursor {
 
+       //front ? first(cur) : last(cur);
 
-MathCursor::~MathCursor()
-{
-       // ensure that 'notifyCursorLeave' is called
-       //while (popLeft())
-       //      ;
-}
+
+       /// moves cursor index one cell to the left
+       bool idxLeft(LCursor & cur);
+       /// moves cursor index one cell to the right
+       bool idxRight(LCursor & cur);
+       /// moves cursor to end of last cell of current line
+       bool idxLineLast(LCursor & cur);
+       /// moves position somehow up or down
+       bool goUpDown(LCursor & cur, bool up);
+       /// moves position closest to (x, y) in given box
+       bool bruteFind(LCursor & cur,
+               int x, int y, int xlow, int xhigh, int ylow, int yhigh);
+       /// moves position closest to (x, y) in current cell
+       void bruteFind2(LCursor & cur, int x, int y);
+       /// are we in a nucleus of a script inset?
+       bool inNucleus(LCursor & cur);
+
+       /// erase the selected part and re-sets the cursor
+       void eraseSelection(LCursor & cur);
+
+       /// the name of the macro we are currently inputting
+       std::string macroName(LCursor & cur);
+       /// where in the curent cell does the macro name start?
+       difference_type macroNamePos(LCursor & cur);
+       /// can we enter the inset?
+       bool openable(MathAtom const &, bool selection);
+
+       /// pointer to enclsing LyX inset
+       InsetFormulaBase * formula_;
 
 
-void MathCursor::push(LCursor & cur, MathAtom & t)
+void push(LCursor & cur, MathAtom & t)
 {
        cur.push(t.nucleus());
 }
 
 
-void MathCursor::pushLeft(LCursor & cur, MathAtom & t)
+void pushLeft(LCursor & cur, MathAtom & t)
 {
        //lyxerr << "Entering atom " << t << " left" << endl;
        push(cur, t);
@@ -82,7 +102,7 @@ void MathCursor::pushLeft(LCursor & cur, MathAtom & t)
 }
 
 
-void MathCursor::pushRight(LCursor & cur, MathAtom & t)
+void pushRight(LCursor & cur, MathAtom & t)
 {
        //lyxerr << "Entering atom " << t << " right" << endl;
        cur.posLeft();
@@ -91,7 +111,7 @@ void MathCursor::pushRight(LCursor & cur, MathAtom & t)
 }
 
 
-bool MathCursor::popLeft(LCursor & cur)
+bool popLeft(LCursor & cur)
 {
        //lyxerr << "Leaving atom to the left" << endl;
        if (cur.depth() <= 1) {
@@ -105,7 +125,7 @@ bool MathCursor::popLeft(LCursor & cur)
 }
 
 
-bool MathCursor::popRight(LCursor & cur)
+bool popRight(LCursor & cur)
 {
        //lyxerr << "Leaving atom "; bv.inset->asMathInset()->write(cerr, false); cerr << " right" << endl;
        if (cur.depth() <= 1) {
@@ -122,7 +142,7 @@ bool MathCursor::popRight(LCursor & cur)
 
 
 #if FILEDEBUG
-       void MathCursor::dump(char const * what) const
+       void dump(char const * what)
        {
                lyxerr << "MC: " << what << endl;
                lyxerr << " Cursor: " << cur.depth() << endl;
@@ -131,14 +151,14 @@ bool MathCursor::popRight(LCursor & cur)
                lyxerr << " Anchor: " << Anchor_.size() << endl;
                for (unsigned i = 0; i < Anchor_.size(); ++i)
                        lyxerr << "    i: " << i << ' ' << Anchor_[i] << endl;
-               lyxerr  << " sel: " << selection_ << endl;
+               lyxerr  << " sel: " << cur.selection() << endl;
        }
 #else
-       void MathCursor::dump(char const *) const {}
+       void dump(char const *) {}
 #endif
 
 
-bool MathCursor::isInside(MathInset const *) const
+bool isInside(MathInset const *)
 {
 #warning FIXME
 /*
@@ -150,7 +170,7 @@ bool MathCursor::isInside(MathInset const *) const
 }
 
 
-bool MathCursor::openable(MathAtom const & t, bool sel) const
+bool openable(MathAtom const & t, bool sel)
 {
        if (!t->isActive())
                return false;
@@ -176,17 +196,17 @@ bool MathCursor::openable(MathAtom const & t, bool sel) const
 }
 
 
-bool MathCursor::inNucleus(LCursor & cur) const
+bool inNucleus(LCursor & cur)
 {
        return cur.inset()->asMathInset()->asScriptInset() && cur.idx() == 2;
 }
 
 
-bool MathCursor::left(LCursor & cur, bool sel)
+bool left(LCursor & cur, bool sel)
 {
        dump("Left 1");
-       autocorrect_ = false;
-       cur.bv().x_target(-1); // "no target"
+       cur.autocorrect() = false;
+       cur.x_target(-1); // "no target"
        if (inMacroMode(cur)) {
                macroModeClose(cur);
                return true;
@@ -198,15 +218,15 @@ bool MathCursor::left(LCursor & cur, bool sel)
                return true;
        }
 
-       return cur.posLeft() || idxLeft(cur) || popLeft(cur) || selection_;
+       return cur.posLeft() || idxLeft(cur) || popLeft(cur) || cur.selection();
 }
 
 
-bool MathCursor::right(LCursor & cur, bool sel)
+bool right(LCursor & cur, bool sel)
 {
        dump("Right 1");
-       autocorrect_ = false;
-       cur.bv().x_target(-1); // "no target"
+       cur.autocorrect() = false;
+       cur.x_target(-1); // "no target"
        if (inMacroMode(cur)) {
                macroModeClose(cur);
                return true;
@@ -218,27 +238,7 @@ bool MathCursor::right(LCursor & cur, bool sel)
                return true;
        }
 
-       return cur.posRight() || idxRight(cur) || popRight(cur) || selection_;
-}
-
-
-void MathCursor::first(LCursor & cur)
-{
-#warning FIXME
-       //Cursor_.clear();
-       push(cur, formula_->par());
-       cur.inset()->asMathInset()->idxFirst(cur);
-       cur.resetAnchor();
-}
-
-
-void MathCursor::last(LCursor & cur)
-{
-#warning FIXME
-       //Cursor_.clear();
-       push(cur, formula_->par());
-       cur.inset()->asMathInset()->idxLast(cur);
-       cur.resetAnchor();
+       return cur.posRight() || idxRight(cur) || popRight(cur) || cur.selection();
 }
 
 
@@ -258,7 +258,7 @@ bool positionable(CursorBase const & cursor, CursorBase const & anchor)
 }
 
 
-void MathCursor::setScreenPos(LCursor & cur, int x, int y)
+void setScreenPos(LCursor & cur, int x, int y)
 {
        dump("setScreenPos 1");
        bool res = bruteFind(cur, x, y,
@@ -267,63 +267,64 @@ void MathCursor::setScreenPos(LCursor & cur, int x, int y)
        if (!res) {
                // this can happen on creation of "math-display"
                dump("setScreenPos 1.5");
-               first(cur);
+               cur.idx() = 0;
+               cur.pos() = 0;
        }
-       cur.bv().x_target(-1); // "no target"
+       cur.x_target(-1); // "no target"
        dump("setScreenPos 2");
 }
 
 
 
-bool MathCursor::home(LCursor & cur, bool sel)
+bool home(LCursor & cur, bool sel)
 {
        dump("home 1");
-       autocorrect_ = false;
+       cur.autocorrect() = false;
        selHandle(cur, sel);
        macroModeClose(cur);
        if (!cur.inset()->asMathInset()->idxHome(cur))
                return popLeft(cur);
        dump("home 2");
-       cur.bv().x_target(-1); // "no target"
+       cur.x_target(-1); // "no target"
        return true;
 }
 
 
-bool MathCursor::end(LCursor & cur, bool sel)
+bool end(LCursor & cur, bool sel)
 {
        dump("end 1");
-       autocorrect_ = false;
+       cur.autocorrect() = false;
        selHandle(cur, sel);
        macroModeClose(cur);
        if (!cur.inset()->asMathInset()->idxEnd(cur))
                return popRight(cur);
        dump("end 2");
-       cur.bv().x_target(-1); // "no target"
+       cur.x_target(-1); // "no target"
        return true;
 }
 
 
-void MathCursor::plainErase(LCursor & cur)
+void plainErase(LCursor & cur)
 {
        cur.cell().erase(cur.pos());
 }
 
 
-void MathCursor::markInsert(LCursor & cur)
+void markInsert(LCursor & cur)
 {
        //lyxerr << "inserting mark" << endl;
        cur.cell().insert(cur.pos(), MathAtom(new MathCharInset(0)));
 }
 
 
-void MathCursor::markErase(LCursor & cur)
+void markErase(LCursor & cur)
 {
        //lyxerr << "deleting mark" << endl;
        cur.cell().erase(cur.pos());
 }
 
 
-void MathCursor::plainInsert(LCursor & cur, MathAtom const & t)
+void plainInsert(LCursor & cur, MathAtom const & t)
 {
        dump("plainInsert");
        cur.cell().insert(cur.pos(), t);
@@ -331,7 +332,7 @@ void MathCursor::plainInsert(LCursor & cur, MathAtom const & t)
 }
 
 
-void MathCursor::insert2(LCursor & cur, string const & str)
+void insert2(LCursor & cur, string const & str)
 {
        MathArray ar;
        asArray(str, ar);
@@ -339,7 +340,7 @@ void MathCursor::insert2(LCursor & cur, string const & str)
 }
 
 
-void MathCursor::insert(LCursor & cur, string const & str)
+void insert(LCursor & cur, string const & str)
 {
        //lyxerr << "inserting '" << str << "'" << endl;
        selClearOrDel(cur);
@@ -348,7 +349,7 @@ void MathCursor::insert(LCursor & cur, string const & str)
 }
 
 
-void MathCursor::insert(LCursor & cur, char c)
+void insert(LCursor & cur, char c)
 {
        //lyxerr << "inserting '" << c << "'" << endl;
        selClearOrDel(cur);
@@ -356,7 +357,7 @@ void MathCursor::insert(LCursor & cur, char c)
 }
 
 
-void MathCursor::insert(LCursor & cur, MathAtom const & t)
+void insert(LCursor & cur, MathAtom const & t)
 {
        macroModeClose(cur);
        selClearOrDel(cur);
@@ -364,7 +365,7 @@ void MathCursor::insert(LCursor & cur, MathAtom const & t)
 }
 
 
-void MathCursor::niceInsert(LCursor & cur, string const & t)
+void niceInsert(LCursor & cur, string const & t)
 {
        MathArray ar;
        asArray(t, ar);
@@ -375,7 +376,7 @@ void MathCursor::niceInsert(LCursor & cur, string const & t)
 }
 
 
-void MathCursor::niceInsert(LCursor & cur, MathAtom const & t)
+void niceInsert(LCursor & cur, MathAtom const & t)
 {
        macroModeClose(cur);
        string safe = grabAndEraseSelection(cur);
@@ -389,27 +390,27 @@ void MathCursor::niceInsert(LCursor & cur, MathAtom const & t)
 }
 
 
-void MathCursor::insert(LCursor & cur, MathArray const & ar)
+void insert(LCursor & cur, MathArray const & ar)
 {
        macroModeClose(cur);
-       if (selection_)
+       if (cur.selection())
                eraseSelection(cur);
        cur.cell().insert(cur.pos(), ar);
        cur.pos() += ar.size();
 }
 
 
-void MathCursor::paste(LCursor & cur, string const & data)
+void paste(LCursor & cur, string const & data)
 {
        dispatch(cur, FuncRequest(LFUN_PASTE, data));
 }
 
 
-bool MathCursor::backspace(LCursor & cur)
+bool backspace(LCursor & cur)
 {
-       autocorrect_ = false;
+       cur.autocorrect() = false;
 
-       if (selection_) {
+       if (cur.selection()) {
                selDel(cur);
                return true;
        }
@@ -443,13 +444,13 @@ bool MathCursor::backspace(LCursor & cur)
 }
 
 
-bool MathCursor::erase(LCursor & cur)
+bool erase(LCursor & cur)
 {
-       autocorrect_ = false;
+       cur.autocorrect() = false;
        if (inMacroMode(cur))
                return true;
 
-       if (selection_) {
+       if (cur.selection()) {
                selDel(cur);
                return true;
        }
@@ -481,41 +482,37 @@ bool MathCursor::erase(LCursor & cur)
 }
 
 
-bool MathCursor::up(LCursor & cur, bool sel)
+bool up(LCursor & cur, bool sel)
 {
        dump("up 1");
        macroModeClose(cur);
        selHandle(cur, sel);
-#warning FIXME
-#if 0
-       CursorBase save = Cursor_;
-       if (goUpDown(true))
+#warning look here
+       //CursorBase save = cur.cursor_;
+       if (goUpDown(cur, true))
                return true;
-       Cursor_ = save;
-#endif
-       autocorrect_ = false;
-       return selection_;
+       //cur.cursor_ = save;
+       cur.autocorrect() = false;
+       return cur.selection();
 }
 
 
-bool MathCursor::down(LCursor & cur, bool sel)
+bool down(LCursor & cur, bool sel)
 {
        dump("down 1");
        macroModeClose(cur);
        selHandle(cur, sel);
-#warning FIXME
-#if 0
-       CursorBase save = Cursor_;
-       if (goUpDown(false))
+#warning look here
+       //CursorBase save = cur.cursor_;
+       if (goUpDown(cur, false))
                return true;
-       Cursor_ = save;
-#endif
-       autocorrect_ = false;
-       return selection_;
+       //cur.cursor_ = save;
+       cur.autocorrect() = false;
+       return cur.selection();
 }
 
 
-void MathCursor::macroModeClose(LCursor & cur)
+void macroModeClose(LCursor & cur)
 {
        if (!inMacroMode(cur))
                return;
@@ -540,100 +537,99 @@ void MathCursor::macroModeClose(LCursor & cur)
 }
 
 
-string MathCursor::macroName(LCursor & cur) const
+string macroName(LCursor & cur)
 {
        return inMacroMode(cur) ? activeMacro(cur)->name() : string();
 }
 
 
-void MathCursor::selClear(LCursor & cur)
+void selClear(LCursor & cur)
 {
        cur.resetAnchor();
-       cur.bv().clearSelection();
+       cur.clearSelection();
 }
 
 
-void MathCursor::selCopy(LCursor & cur)
+void selCopy(LCursor & cur)
 {
        dump("selCopy");
-       if (selection_) {
+       if (cur.selection()) {
                theCutBuffer.push(grabSelection(cur));
-               selection_ = false;
+               cur.selection() = false;
        } else {
                //theCutBuffer.erase();
        }
 }
 
 
-void MathCursor::selCut(LCursor & cur)
+void selCut(LCursor & cur)
 {
        dump("selCut");
        theCutBuffer.push(grabAndEraseSelection(cur));
 }
 
 
-void MathCursor::selDel(LCursor & cur)
+void selDel(LCursor & cur)
 {
        dump("selDel");
-       if (selection_) {
+       if (cur.selection()) {
                eraseSelection(cur);
-               selection_ = false;
+               cur.selection() = false;
        }
 }
 
 
-void MathCursor::selPaste(LCursor & cur, size_t n)
+void selPaste(LCursor & cur, size_t n)
 {
        dump("selPaste");
        selClearOrDel(cur);
        if (n < theCutBuffer.size())
                paste(cur, theCutBuffer[n]);
        //grabSelection(cur);
-       selection_ = false;
+       cur.selection() = false;
 }
 
 
-void MathCursor::selHandle(LCursor & cur, bool sel)
+void selHandle(LCursor & cur, bool sel)
 {
-       if (sel == selection_)
+       if (sel == cur.selection())
                return;
        //clear();
        cur.resetAnchor();
-       selection_ = sel;
+       cur.selection() = sel;
 }
 
 
-void MathCursor::selStart(LCursor & cur)
+void selStart(LCursor & cur)
 {
        dump("selStart 1");
        //clear();
        cur.resetAnchor();
-       selection_ = true;
+       cur.selection() = true;
        dump("selStart 2");
 }
 
 
-void MathCursor::selClearOrDel(LCursor & cur)
+void selClearOrDel(LCursor & cur)
 {
        if (lyxrc.auto_region_delete)
                selDel(cur);
        else
-               selection_ = false;
+               cur.selection() = false;
 }
 
 
-void MathCursor::drawSelection(PainterInfo & pi) const
+void drawSelection(PainterInfo & pi)
 {
-       if (!selection_)
+       if (!pi.base.bv->cursor().selection())
                return;
-       CursorSlice i1;
-       CursorSlice i2;
-       getSelection(pi.base.bv->fullCursor(), i1, i2);
+       CursorSlice i1 = pi.base.bv->cursor().selStart();
+       CursorSlice i2 = pi.base.bv->cursor().selEnd();
        i1.asMathInset()->drawSelection(pi, i1.idx_, i1.pos_, i2.idx_, i2.pos_);
 }
 
 
-void MathCursor::handleNest(LCursor & cur, MathAtom const & a, int c)
+void handleNest(LCursor & cur, MathAtom const & a, int c)
 {
        MathAtom at = a;
        asArray(grabAndEraseSelection(cur), at.nucleus()->cell(c));
@@ -642,16 +638,16 @@ void MathCursor::handleNest(LCursor & cur, MathAtom const & a, int c)
 }
 
 
-void MathCursor::getScreenPos(LCursor & cur, int & x, int & y) const
+void getScreenPos(LCursor & cur, int & x, int & y)
 {
        cur.inset()->asMathInset()->getScreenPos(cur.idx(), cur.pos(), x, y);
 }
 
 
-int MathCursor::targetX(LCursor & cur) const
+int targetX(LCursor & cur)
 {
-       if (cur.bv().x_target() != -1)
-               return cur.bv().x_target();
+       if (cur.x_target() != -1)
+               return cur.x_target();
        int x = 0;
        int y = 0;
        getScreenPos(cur, x, y);
@@ -659,28 +655,25 @@ int MathCursor::targetX(LCursor & cur) const
 }
 
 
-InsetFormulaBase * MathCursor::formula() const
+InsetFormulaBase * formula()
 {
        return formula_;
 }
 
 
-void MathCursor::adjust(LCursor & cur, pos_type from, difference_type diff)
+void adjust(LCursor & cur, pos_type from, difference_type diff)
 {      
        if (cur.pos() > from)
                cur.pos() += diff;
-#warning FIXME
-#if 0
-       if (Anchor_.back().pos_ > from)
-               Anchor_.back().pos_ += diff;
+       if (cur.anchor().pos_ > from)
+               cur.anchor().pos_ += diff;
        // just to be on the safe side
        // theoretically unecessary
-#endif
        normalize(cur);
 }
 
 
-bool MathCursor::inMacroMode(LCursor & cur) const
+bool inMacroMode(LCursor & cur)
 {
        if (!cur.pos() != 0)
                return false;
@@ -689,32 +682,19 @@ bool MathCursor::inMacroMode(LCursor & cur) const
 }
 
 
-MathUnknownInset * MathCursor::activeMacro(LCursor & cur)
+MathUnknownInset * activeMacro(LCursor & cur)
 {
        return inMacroMode(cur) ? cur.prevAtom().nucleus()->asUnknownInset() : 0;
 }
 
 
-MathUnknownInset const * MathCursor::activeMacro(LCursor & cur) const
-{
-       return inMacroMode(cur) ? cur.prevAtom()->asUnknownInset() : 0;
-}
-
-
-bool MathCursor::inMacroArgMode(LCursor & cur) const
+bool inMacroArgMode(LCursor & cur)
 {
        return cur.pos() > 0 && cur.prevAtom()->getChar() == '#';
 }
 
 
-bool MathCursor::selection() const
-{
-       return selection_;
-}
-
-
-MathGridInset *
-MathCursor::enclosingGrid(LCursor & cur, MathCursor::idx_type & idx) const
+MathGridInset * enclosingGrid(LCursor & cur, idx_type & idx)
 {
        for (MathInset::difference_type i = cur.depth() - 1; i >= 0; --i) {
                MathInset * m = cur.cursor_[i].inset()->asMathInset();
@@ -730,28 +710,28 @@ MathCursor::enclosingGrid(LCursor & cur, MathCursor::idx_type & idx) const
 }
 
 
-void MathCursor::popToHere(LCursor & cur, MathInset const * p)
+void popToHere(LCursor & cur, MathInset const * p)
 {
        while (cur.depth() && cur.inset()->asMathInset() != p)
                cur.pop();
 }
 
 
-void MathCursor::popToEnclosingGrid(LCursor & cur)
+void popToEnclosingGrid(LCursor & cur)
 {
        while (cur.depth() && !cur.inset()->asMathInset()->asGridInset())
                cur.pop();
 }
 
 
-void MathCursor::popToEnclosingHull(LCursor & cur)
+void popToEnclosingHull(LCursor & cur)
 {
        while (cur.depth() && !cur.inset()->asMathInset()->asGridInset())
                cur.pop();
 }
 
 
-void MathCursor::pullArg(LCursor & cur)
+void pullArg(LCursor & cur)
 {
        dump("pullarg");
        MathArray ar = cur.cell();
@@ -765,7 +745,7 @@ void MathCursor::pullArg(LCursor & cur)
 }
 
 
-void MathCursor::touch()
+void touch()
 {
 #warning
 #if 0
@@ -777,8 +757,10 @@ void MathCursor::touch()
 }
 
 
-void MathCursor::normalize(LCursor & cur)
+void normalize(LCursor & cur)
 {
+#warning FIXME
+#if 0
        if (cur.idx() >= cur.nargs()) {
                lyxerr << "this should not really happen - 1: "
                       << cur.idx() << ' ' << cur.nargs()
@@ -797,22 +779,23 @@ void MathCursor::normalize(LCursor & cur)
                dump("error 4");
        }
        cur.pos() = min(cur.pos(), cur.lastpos());
+#endif
 }
 
 
-void MathCursor::idxNext(LCursor & cur)
+void idxNext(LCursor & cur)
 {
        cur.inset()->asMathInset()->idxNext(cur);
 }
 
 
-void MathCursor::idxPrev(LCursor & cur)
+void idxPrev(LCursor & cur)
 {
        cur.inset()->asMathInset()->idxPrev(cur);
 }
 
 
-char MathCursor::valign(LCursor & cur) const
+char valign(LCursor & cur)
 {
        idx_type idx;
        MathGridInset * p = enclosingGrid(cur, idx);
@@ -820,7 +803,7 @@ char MathCursor::valign(LCursor & cur) const
 }
 
 
-char MathCursor::halign(LCursor & cur) const
+char halign(LCursor & cur)
 {
        idx_type idx;
        MathGridInset * p = enclosingGrid(cur, idx);
@@ -828,21 +811,7 @@ char MathCursor::halign(LCursor & cur) const
 }
 
 
-void MathCursor::getSelection(LCursor & cur,
-       CursorSlice & i1, CursorSlice & i2) const
-{
-       CursorSlice anc = normalAnchor(cur);
-       if (anc < cur.top()) {
-               i1 = anc;
-               i2 = cur.top();
-       } else {
-               i1 = cur.top();
-               i2 = anc;
-       }
-}
-
-
-bool MathCursor::goUpDown(LCursor & cur, bool up)
+bool goUpDown(LCursor & cur, bool up)
 {
        // Be warned: The 'logic' implemented in this function is highly fragile.
        // A distance of one pixel or a '<' vs '<=' _really_ matters.
@@ -852,13 +821,13 @@ bool MathCursor::goUpDown(LCursor & cur, bool up)
        getScreenPos(cur, xo, yo);
 
        // check if we had something else in mind, if not, this is the future goal
-       if (cur.bv().x_target() == -1)
-               cur.bv().x_target(xo);
+       if (cur.x_target() == -1)
+               cur.x_target(xo);
        else
-               xo = cur.bv().x_target();
+               xo = cur.x_target();
 
        // try neigbouring script insets
-       if (!selection()) {
+       if (!cur.selection()) {
                // try left
                if (cur.pos() != 0) {
                        MathScriptInset const * p = cur.prevAtom()->asScriptInset();
@@ -886,7 +855,7 @@ bool MathCursor::goUpDown(LCursor & cur, bool up)
        }
 
        // try current cell for e.g. text insets
-       if (cur.inset()->asMathInset()->idxUpDown2(cur, up, cur.bv().x_target()))
+       if (cur.inset()->asMathInset()->idxUpDown2(cur, up, cur.x_target()))
                return true;
 
        //xarray().boundingBox(xlow, xhigh, ylow, yhigh);
@@ -903,9 +872,9 @@ bool MathCursor::goUpDown(LCursor & cur, bool up)
        while (1) {
                //lyxerr << "updown: We are in " << inset() << " idx: " << idx() << endl;
                // ask inset first
-               if (cur.inset()->asMathInset()->idxUpDown(cur, up, cur.bv().x_target())) {
+               if (cur.inset()->asMathInset()->idxUpDown(cur, up, cur.x_target())) {
                        // try to find best position within this inset
-                       if (!selection())
+                       if (!cur.selection())
                                bruteFind2(cur, xo, yo);
                        return true;
                }
@@ -930,7 +899,7 @@ bool MathCursor::goUpDown(LCursor & cur, bool up)
 }
 
 
-bool MathCursor::bruteFind
+bool bruteFind
        (LCursor & cur, int x, int y, int xlow, int xhigh, int ylow, int yhigh)
 {
        CursorBase best_cursor;
@@ -940,7 +909,7 @@ bool MathCursor::bruteFind
        CursorBase et = iend(formula()->par().nucleus());
        while (1) {
                // avoid invalid nesting when selecting
-               if (!selection_ || positionable(it, cur.anchor_)) {
+               if (!cur.selection() || positionable(it, cur.anchor_)) {
                        int xo, yo;
                        it.back().getScreenPos(xo, yo);
                        if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
@@ -966,7 +935,7 @@ bool MathCursor::bruteFind
 }
 
 
-void MathCursor::bruteFind2(LCursor & cur, int x, int y)
+void bruteFind2(LCursor & cur, int x, int y)
 {
        double best_dist = 1e10;
 
@@ -993,7 +962,7 @@ void MathCursor::bruteFind2(LCursor & cur, int x, int y)
 }
 
 
-bool MathCursor::idxLineLast(LCursor & cur)
+bool idxLineLast(LCursor & cur)
 {
        cur.idx() -= cur.idx() % cur.ncols();
        cur.idx() += cur.ncols() - 1;
@@ -1002,19 +971,19 @@ bool MathCursor::idxLineLast(LCursor & cur)
 }
 
 
-bool MathCursor::idxLeft(LCursor & cur)
+bool idxLeft(LCursor & cur)
 {
        return cur.inset()->asMathInset()->idxLeft(cur);
 }
 
 
-bool MathCursor::idxRight(LCursor & cur)
+bool idxRight(LCursor & cur)
 {
        return cur.inset()->asMathInset()->idxRight(cur);
 }
 
 
-bool MathCursor::script(LCursor & cur, bool up)
+bool script(LCursor & cur, bool up)
 {
        // Hack to get \\^ and \\_ working
        if (inMacroMode(cur) && macroName(cur) == "\\") {
@@ -1057,10 +1026,10 @@ bool MathCursor::script(LCursor & cur, bool up)
 }
 
 
-bool MathCursor::interpret(LCursor & cur, char c)
+bool interpret(LCursor & cur, char c)
 {
        //lyxerr << "interpret 2: '" << c << "'" << endl;
-       cur.bv().x_target(-1); // "no target"
+       cur.x_target(-1); // "no target"
        if (inMacroArgMode(cur)) {
                --cur.pos();
                plainErase(cur);
@@ -1116,15 +1085,15 @@ bool MathCursor::interpret(LCursor & cur, char c)
 
        if (0) {
                // leave autocorrect mode if necessary
-               if (autocorrect_ && c == ' ') {
-                       autocorrect_ = false;
+               if (cur.autocorrect() && c == ' ') {
+                       cur.autocorrect() = false;
                        return true;
                }
        }
 
        // just clear selection on pressing the space bar
-       if (selection_ && c == ' ') {
-               selection_ = false;
+       if (cur.selection() && c == ' ') {
+               cur.selection() = false;
                return true;
        }
 
@@ -1183,27 +1152,26 @@ bool MathCursor::interpret(LCursor & cur, char c)
        }
 
        // try auto-correction
-       //if (autocorrect_ && hasPrevAtom() && math_autocorrect(prevAtom(), c))
+       //if (cur.autocorrect() && hasPrevAtom() && math_autocorrect(prevAtom(), c))
        //      return true;
 
        // no special circumstances, so insert the character without any fuss
        insert(cur, c);
-       autocorrect_ = true;
+       cur.autocorrect() = true;
        return true;
 }
 
 
-void MathCursor::setSelection
-       (LCursor & cur, CursorBase const & where, size_t n)
+void setSelection(LCursor & cur, CursorBase const & where, size_t n)
 {
-       selection_ = true;
+       cur.selection() = true;
        cur.cursor_ = where;
        cur.anchor_ = where;
        cur.pos() += n;
 }
 
 
-void MathCursor::insetToggle(LCursor & cur)
+void insetToggle(LCursor & cur)
 {
        if (cur.pos() != cur.lastpos()) {
                // toggle previous inset ...
@@ -1216,21 +1184,6 @@ void MathCursor::insetToggle(LCursor & cur)
 }
 
 
-string MathCursor::info(LCursor & cur) const
-{
-       ostringstream os;
-       os << "Math editor mode.  ";
-       for (int i = 0, n = cur.depth(); i < n; ++i) {
-               cur.cursor_[i].asMathInset()->infoize(os);
-               os << "  ";
-       }
-       if (cur.pos() != 0)
-               cur.prevAtom()->infoize2(os);
-       os << "                    ";
-       return os.str();
-}
-
-
 namespace {
 
 void region(CursorSlice const & i1, CursorSlice const & i2,
@@ -1251,14 +1204,13 @@ void region(CursorSlice const & i1, CursorSlice const & i2,
 }
 
 
-string MathCursor::grabSelection(LCursor & cur) const
+string grabSelection(LCursor & cur)
 {
-       if (!selection_)
+       if (!cur.selection())
                return string();
 
-       CursorSlice i1;
-       CursorSlice i2;
-       getSelection(cur, i1, i2);
+       CursorSlice i1 = cur.selStart();
+       CursorSlice i2 = cur.selEnd();
 
        if (i1.idx_ == i2.idx_) {
                MathArray::const_iterator it = i1.cell().begin();
@@ -1283,11 +1235,10 @@ string MathCursor::grabSelection(LCursor & cur) const
 }
 
 
-void MathCursor::eraseSelection(LCursor & cur)
+void eraseSelection(LCursor & cur)
 {
-       CursorSlice i1;
-       CursorSlice i2;
-       getSelection(cur, i1, i2);
+       CursorSlice i1 = cur.selStart();
+       CursorSlice i2 = cur.selEnd();
        if (i1.idx_ == i2.idx_)
                i1.cell().erase(i1.pos_, i2.pos_);
        else {
@@ -1299,22 +1250,22 @@ void MathCursor::eraseSelection(LCursor & cur)
                        for (col_type col = c1; col <= c2; ++col)
                                p->cell(p->index(row, col)).clear();
        }
-       cur.top() = i1;
+       cur.current() = i1;
 }
 
 
-string MathCursor::grabAndEraseSelection(LCursor & cur)
+string grabAndEraseSelection(LCursor & cur)
 {
-       if (!selection_)
+       if (!cur.selection())
                return string();
        string res = grabSelection(cur);
        eraseSelection(cur);
-       selection_ = false;
+       cur.selection() = false;
        return res;
 }
 
 
-CursorSlice MathCursor::normalAnchor(LCursor & cur) const
+CursorSlice normalAnchor(LCursor & cur)
 {
 #warning FIXME
 #if 0
@@ -1331,44 +1282,42 @@ CursorSlice MathCursor::normalAnchor(LCursor & cur) const
        }
        return normal;
 #else
-       return cur.top();
+       return cur.anchor_.back();
 #endif
 }
 
 
-DispatchResult MathCursor::dispatch(LCursor &, FuncRequest const & cmd)
+DispatchResult dispatch(LCursor & cur, FuncRequest const & cmd)
 {
        // mouse clicks are somewhat special
        // check
+/*
        switch (cmd.action) {
                case LFUN_MOUSE_PRESS:
                case LFUN_MOUSE_MOTION:
                case LFUN_MOUSE_RELEASE:
                case LFUN_MOUSE_DOUBLE: {
-/*
-                       CursorSlice & pos = Cursor_.back();
+                       CursorSlice & pos = cur.cursor_.back();
                        int x = 0;
                        int y = 0;
                        getScreenPos(x, y);
-                       if (x < cmd.x && hasPrevAtom()) {
+                       if (x < cmd.x && cur.hasPrevAtom()) {
                                DispatchResult const res =
-                                       prevAtom().nucleus()->dispatch(cur, cmd);
+                                       cur.prevAtom().nucleus()->dispatch(cur, cmd);
                                if (res.dispatched())
                                        return res;
                        }
-                       if (x > cmd.x && hasNextAtom()) {
+                       if (x > cmd.x && cur.hasNextAtom()) {
                                DispatchResult const res =
-                                       nextAtom().nucleus()->dispatch(cur, cmd);
+                                       cur.nextAtom().nucleus()->dispatch(cur, cmd);
                                if (res.dispatched())
                                        return res;
                        }
-*/
                }
                default:
                        break;
        }
 
-/*
        for (int i = cur.depth() - 1; i >= 0; --i) {
                CursorBase tmp = cur->cursor_;
                CursorSlice & pos = tmp.back()
@@ -1387,7 +1336,7 @@ DispatchResult MathCursor::dispatch(LCursor &, FuncRequest const & cmd)
 }
 
 
-MathInset::mode_type MathCursor::currentMode(LCursor &) const
+MathInset::mode_type currentMode(LCursor &)
 {
 #if 0
        for (int i = Cursor_.size() - 1; i >= 0; --i) {
@@ -1400,10 +1349,10 @@ MathInset::mode_type MathCursor::currentMode(LCursor &) const
 }
 
 
-void MathCursor::handleFont(LCursor & cur, string const & font)
+void handleFont(LCursor & cur, string const & font)
 {
        string safe;
-       if (selection()) {
+       if (cur.selection()) {
                macroModeClose(cur);
                safe = grabAndEraseSelection(cur);
        }
@@ -1433,13 +1382,19 @@ void MathCursor::handleFont(LCursor & cur, string const & font)
        insert(cur, safe);
 }
 
+}
+
 
-void releaseMathCursor(BufferView & bv)
+void releaseMathCursor(LCursor & cur)
 {
-       if (mathcursor) {
-               InsetFormulaBase * f = mathcursor->formula();
-               delete mathcursor;
-               mathcursor = 0;
-               f->insetUnlock(bv);
+       if (inMathed()) {
+               mathcursor::formula_->insetUnlock(cur.bv());
+               mathcursor::formula_ = 0;
        }
 }
+
+
+bool inMathed()
+{
+       return mathcursor::formula_;
+}
index 22b92d5615920979309103e4b539e8e2cb2139d9..32a8e52108217c9566da24b42dc49e80e25ed1c6 100644 (file)
@@ -13,7 +13,7 @@
 #ifndef MATH_CURSOR
 #define MATH_CURSOR
 
-#include "cursor_slice.h"
+#include "cursor.h"
 #include "math_inset.h"
 #include "math_data.h"
 
@@ -36,8 +36,7 @@ this formula's MathHullInset to the current position.
 */
 
 
-class MathCursor {
-public:
+namespace mathcursor {
        /// short of anything else reasonable
        typedef size_t             size_type;
        /// type for column numbers
@@ -51,10 +50,6 @@ public:
        /// type for column numbers
        typedef size_t             col_type;
 
-       ///
-       explicit MathCursor(BufferView *, InsetFormulaBase *, bool left);
-       ///
-       ~MathCursor();
        ///
        void insert(LCursor & cur, MathAtom const &);
        ///
@@ -79,10 +74,6 @@ public:
        bool up(LCursor & cur, bool sel = false);
        /// called for LFUN_DOWN etc
        bool down(LCursor & cur, bool sel = false);
-       /// Put the cursor in the first position
-       void first(LCursor & cur);
-       /// Put the cursor in the last position
-       void last(LCursor & cur);
        /// move to next cell in current inset
        void idxNext(LCursor & bv);
        /// move to previous cell in current inset
@@ -99,11 +90,11 @@ public:
        /// in pixels from top of screen
        void setScreenPos(LCursor & cur, int x, int y);
        /// in pixels from top of screen
-       void getScreenPos(LCursor & cur, int & x, int & y) const;
+       void getScreenPos(LCursor & cur, int & x, int & y);
        /// in pixels from left of screen
-       int targetX(LCursor & cur) const;
+       int targetX(LCursor & cur);
        /// return the next enclosing grid inset and the cursor's index in it
-       MathGridInset * enclosingGrid(LCursor & cur, idx_type & idx) const;
+       MathGridInset * enclosingGrid(LCursor & cur, idx_type & idx);
        /// go up to enclosing grid
        void popToEnclosingGrid(LCursor & cur);
        /// go up to the hull inset
@@ -113,7 +104,7 @@ public:
        /// adjust anchor position after deletions/insertions
        void adjust(LCursor & cur, pos_type from, difference_type diff);
        ///
-       InsetFormulaBase * formula() const;
+       InsetFormulaBase * formula();
        /// current offset in the current cell
        ///
        bool script(LCursor & cur, bool);
@@ -122,20 +113,16 @@ public:
        /// interpret name a name of a macro
        void macroModeClose(LCursor & cur);
        /// are we currently typing the name of a macro?
-       bool inMacroMode(LCursor & cur) const;
+       bool inMacroMode(LCursor & cur);
        /// get access to the macro we are currently typing
        MathUnknownInset * activeMacro(LCursor & cur);
-       /// get access to the macro we are currently typing
-       MathUnknownInset const * activeMacro(LCursor & cur) const;
        /// are we currently typing '#1' or '#2' or...?
-       bool inMacroArgMode(LCursor & cur) const;
+       bool inMacroArgMode(LCursor & cur);
        /// are we in math mode (1), text mode (-1) or unsure?
-       MathInset::mode_type currentMode(LCursor & cur) const;
+       MathInset::mode_type currentMode(LCursor & cur);
 
        // Local selection methods
        ///
-       bool selection() const;
-       ///
        void selCopy(LCursor & cur);
        ///
        void selCut(LCursor & cur);
@@ -152,18 +139,18 @@ public:
        /// clears or deletes selection depending on lyxrc setting
        void selClearOrDel(LCursor & cur);
        /// draws light-blue selection background
-       void drawSelection(PainterInfo & pi) const;
+       void drawSelection(PainterInfo & pi);
        /// replace selected stuff with at, placing the former
        // selection in given cell of atom
        void handleNest(LCursor & cur, MathAtom const & at, int cell = 0);
        /// remove this as soon as LyXFunc::getStatus is "localized"
-       std::string getLastCode() const { return "mathnormal"; }
+       inline std::string getLastCode() { return "mathnormal"; }
        ///
-       bool isInside(MathInset const *) const;
+       bool isInside(MathInset const *);
        ///
-       char valign(LCursor & cur) const;
+       char valign(LCursor & cur);
        ///
-       char halign(LCursor & cur) const;
+       char halign(LCursor & cur);
 
        /// make sure cursor position is valid
        void normalize(LCursor & cur);
@@ -181,21 +168,17 @@ public:
        /// leave current MathInset to the left
        bool popRight(LCursor & cur);
 
-       /// returns the selection
-       void getSelection(LCursor & cur, CursorSlice &, CursorSlice &) const;
        /// returns the normalized anchor of the selection
-       CursorSlice normalAnchor(LCursor & cur) const;
+       CursorSlice normalAnchor(LCursor & cur);
 
-       /// describe the situation
-       std::string info(LCursor & cur) const;
        /// dump selection information for debugging
-       void seldump(char const * str) const;
+       void seldump(char const * str);
        /// dump selection information for debugging
-       void dump(char const * str) const;
+       void dump(char const * str);
        /// moves on
        void setSelection(LCursor & cur, CursorBase const & where, size_type n);
        /// grab selection marked by anchor and current cursor
-       std::string grabSelection(LCursor & cur) const;
+       std::string grabSelection(LCursor & cur);
        /// guess what
        std::string grabAndEraseSelection(LCursor & cur);
        ///
@@ -214,47 +197,13 @@ public:
        void handleFont(LCursor & cur, std::string const & font);
        ///
        DispatchResult dispatch(LCursor & cur, FuncRequest const & cmd);
-private:
-       /// moves cursor index one cell to the left
-       bool idxLeft(LCursor & bv);
-       /// moves cursor index one cell to the right
-       bool idxRight(LCursor & bv);
-       /// moves cursor to end of last cell of current line
-       bool idxLineLast(LCursor & bv);
-       /// moves position somehow up or down
-       bool goUpDown(LCursor & cur, bool up);
-       /// moves position closest to (x, y) in given box
-       bool bruteFind(LCursor & cur,
-               int x, int y, int xlow, int xhigh, int ylow, int yhigh);
-       /// moves position closest to (x, y) in current cell
-       void bruteFind2(LCursor & cur, int x, int y);
-       /// are we in a nucleus of a script inset?
-       bool inNucleus(LCursor & cur) const;
-
-       /// erase the selected part and re-sets the cursor
-       void eraseSelection(LCursor & cur);
-
-       /// the name of the macro we are currently inputting
-       std::string macroName(LCursor & cur) const;
-       /// where in the curent cell does the macro name start?
-       difference_type macroNamePos(LCursor & cur) const;
-       /// can we enter the inset?
-       bool openable(MathAtom const &, bool selection) const;
 
        /// pointer to enclsing LyX inset
-       InsetFormulaBase * formula_;
-       // Selection stuff
-       /// text code of last char entered
-       //MathTextCodes lastcode_;
-       /// do we allow autocorrection
-       bool autocorrect_;
-       /// do we currently select
-       bool selection_;
-       /// are we entering a macro name?
-       bool macromode_;
-};
+       extern InsetFormulaBase * formula_;
+}
+
+void releaseMathCursor(LCursor & cur);
 
-extern MathCursor * mathcursor;
-void releaseMathCursor(BufferView & bv);
+bool inMathed();
 
 #endif
index 53c880599060427e5b07c994ab0e7a39170b4629..1645de6872eae5248e004126b77a5bd4be3799d3 100644 (file)
@@ -12,6 +12,7 @@
 
 #include "math_fracbase.h"
 #include "math_data.h"
+#include "cursor.h"
 
 
 MathFracbaseInset::MathFracbaseInset()
index 1384d1e399316d4b4ec6f2d092a439cadb2ceb1c..ae28abed661647f5f28b387fcb0ca30945a674d6 100644 (file)
@@ -15,6 +15,7 @@
 #include "math_mathmlstream.h"
 #include "math_streamstr.h"
 #include "BufferView.h"
+#include "cursor.h"
 #include "dispatchresult.h"
 #include "debug.h"
 #include "funcrequest.h"
@@ -1043,9 +1044,8 @@ void MathGridInset::splitCell(LCursor & cur)
 
 
 DispatchResult
-MathGridInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+MathGridInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
-       LCursor & cur = bv.fullCursor();
        switch (cmd.action) {
 
                case LFUN_MOUSE_RELEASE:
@@ -1056,7 +1056,7 @@ MathGridInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                        return DispatchResult(false);
 
                case LFUN_INSET_DIALOG_UPDATE:
-                       GridInsetMailer(*this).updateDialog(&bv);
+                       GridInsetMailer(*this).updateDialog(&cur.bv());
                        return DispatchResult(false);
 
                // insert file functions
@@ -1076,12 +1076,12 @@ MathGridInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                        return DispatchResult(true, FINISHED);
 
                case LFUN_CELL_SPLIT:
-                       //recordUndo(bv, Undo::ATOMIC);
+                       //recordUndo(cur, Undo::ATOMIC);
                        splitCell(cur);
                        return DispatchResult(true, FINISHED);
 
                case LFUN_BREAKLINE: {
-                       //recordUndo(bv, Undo::INSERT);
+                       //recordUndo(cur, Undo::INSERT);
                        row_type const r = cur.row();
                        addRow(r);
 
@@ -1191,6 +1191,6 @@ cur.row());
                }
 
                default:
-                       return MathNestInset::priv_dispatch(bv, cmd);
+                       return MathNestInset::priv_dispatch(cur, cmd);
        }
 }
index 648fc7a58873b0e1bf2df1cad32ec137a05b25df..f7d0fb9e35204b02672904114cd5f95d63ef66f8 100644 (file)
@@ -216,7 +216,7 @@ public:
 
 protected:
        ///
-       DispatchResult priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+       DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
        /// returns x offset of cell compared to inset
        int cellXOffset(idx_type idx) const;
        /// returns y offset of cell compared to inset
index c18072ee95b478768724854fec65a0dc7ae0de87..cb9b5e63b5a9326fad8face7eb863391b502df3d 100644 (file)
@@ -706,9 +706,9 @@ void MathHullInset::doExtern(LCursor & cur, FuncRequest const & func)
 
 #ifdef WITH_WARNINGS
 #warning temporarily disabled
-       //if (selection()) {
+       //if (cur.selection()) {
        //      MathArray ar;
-       //      selGet(ar);
+       //      selGet(cur.ar);
        //      lyxerr << "use selection: " << ar << endl;
        //      insert(pipeThroughExtern(lang, extra, ar));
        //      return;
@@ -725,8 +725,8 @@ void MathHullInset::doExtern(LCursor & cur, FuncRequest const & func)
        if (getType() == "simple") {
                size_type pos = cur.cell().find_last(eq);
                MathArray ar;
-               if (mathcursor && mathcursor->selection()) {
-                       asArray(mathcursor->grabAndEraseSelection(cur), ar);
+               if (inMathed() && cur.selection()) {
+                       asArray(mathcursor::grabAndEraseSelection(cur), ar);
                } else if (pos == cur.cell().size()) {
                        ar = cur.cell();
                        lyxerr << "use whole cell: " << ar << endl;
@@ -775,9 +775,8 @@ void MathHullInset::doExtern(LCursor & cur, FuncRequest const & func)
 
 
 DispatchResult
-MathHullInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+MathHullInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
-       CursorSlice & cur = cursorTip(bv);
        switch (cmd.action) {
 
                case LFUN_BREAKLINE:
@@ -787,28 +786,28 @@ MathHullInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                                cur.pos() = 0;
                                return DispatchResult(true, FINISHED);
                        }
-                       return MathGridInset::priv_dispatch(bv, cmd);
+                       return MathGridInset::priv_dispatch(cur, cmd);
 
                case LFUN_MATH_NUMBER:
                        //lyxerr << "toggling all numbers" << endl;
                        if (display()) {
-                               //recordUndo(bv, Undo::INSERT);
+                               //recordUndo(cur, Undo::INSERT);
                                bool old = numberedType();
                                if (type_ == "multline")
                                        numbered(nrows() - 1, !old);
                                else
                                        for (row_type row = 0; row < nrows(); ++row)
                                                numbered(row, !old);
-                               //bv->owner()->message(old ? _("No number") : _("Number"));
+                               //cur.bv()->owner()->message(old ? _("No number") : _("Number"));
                        }
                        return DispatchResult(true, true);
 
                case LFUN_MATH_NONUMBER:
                        if (display()) {
                                row_type r = (type_ == "multline") ? nrows() - 1 : cur.row();
-                               //recordUndo(bv, Undo::INSERT);
+                               //recordUndo(cur, Undo::INSERT);
                                bool old = numbered(r);
-                               //bv->owner()->message(old ? _("No number") : _("Number"));
+                               //cur.bv()->owner()->message(old ? _("No number") : _("Number"));
                                numbered(r, !old);
                        }
                        return DispatchResult(true, true);
@@ -839,7 +838,7 @@ MathHullInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                }
 
                case LFUN_MATH_EXTERN:
-                       doExtern(bv.fullCursor(), cmd);
+                       doExtern(cur, cmd);
                        return DispatchResult(true, FINISHED);
 
                case LFUN_MATH_MUTATE: {
@@ -863,7 +862,7 @@ MathHullInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                }
 
                default:
-                       return MathGridInset::priv_dispatch(bv, cmd);
+                       return MathGridInset::priv_dispatch(cur, cmd);
        }
 }
 
index 0885bf6f1df4cba51ec58629041ec97cd3560653..bd9858cfa844f615b2f0a465449dbac489b53d51 100644 (file)
@@ -100,7 +100,7 @@ protected:
        ///
        virtual
        DispatchResult
-       priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+       priv_dispatch(LCursor & cur, FuncRequest const & cmd);
        ///
        std::string eolString(row_type row, bool fragile) const;
 
index 25d77e9a3cb91a9d1619c1bd28498f2eacc0d1e6..9ca5c55e5cb66a8422f051d5d98a70c379756737 100644 (file)
@@ -13,7 +13,6 @@
 #ifndef MATH_INSET_H
 #define MATH_INSET_H
 
-#include "cursor.h"
 #include "insets/insetbase.h"
 
 #include <string>
@@ -68,6 +67,7 @@ class MathMacroTemplate;
 class MathMacro;
 class MathPosFinder;
 class Dimension;
+class LCursor;
 class TextPainter;
 class TextMetricsInfo;
 class ReplaceData;
@@ -228,10 +228,6 @@ public:
        virtual void mathmlize(MathMLStream &) const;
        /// write content as something readable by Octave
        virtual void octave(OctaveStream &) const;
-       /// describe content if cursor inside
-       virtual void infoize(std::ostream &) const {}
-       /// describe content if cursor behind
-       virtual void infoize2(std::ostream &) const {}
        /// plain ascii output
        virtual int plaintext(std::ostream & os, OutputParams const &) const;
        /// linuxdoc output
index 0092dd52e019ac658eea714ebcb22c35342a5d46..f0f34f265c32e6597126eb613f31f0868928a9a2 100644 (file)
@@ -17,6 +17,7 @@
 #include "math_macrotable.h"
 #include "math_macrotemplate.h"
 #include "math_mathmlstream.h"
+#include "cursor.h"
 #include "debug.h"
 #include "LaTeXFeatures.h"
 
index da4ea89da9fe469df1ef2a477850aa9739fa8486..f756b280b8f8a561a300cfa1111ce4dcaa7c425d 100644 (file)
@@ -19,6 +19,8 @@
 #include "debug.h"
 #include "funcrequest.h"
 #include "LColor.h"
+#include "undo.h"
+
 #include "frontends/Painter.h"
 
 
@@ -214,7 +216,7 @@ bool MathNestInset::contains(MathArray const & ar) const
 
 bool MathNestInset::editing() const
 {
-       return mathcursor && mathcursor->isInside(this);
+       return inMathed() && mathcursor::isInside(this);
 }
 
 
@@ -239,7 +241,7 @@ bool MathNestInset::isActive() const
 MathArray MathNestInset::glue() const
 {
        MathArray ar;
-       for (unsigned i = 0; i < nargs(); ++i)
+       for (size_t i = 0; i < nargs(); ++i)
                ar.append(cell(i));
        return ar;
 }
@@ -248,7 +250,7 @@ MathArray MathNestInset::glue() const
 void MathNestInset::write(WriteStream & os) const
 {
        os << '\\' << name().c_str();
-       for (unsigned i = 0; i < nargs(); ++i)
+       for (size_t i = 0; i < nargs(); ++i)
                os << '{' << cell(i) << '}';
        if (nargs() == 0)
                os.pendingSpace(true);
@@ -262,7 +264,7 @@ void MathNestInset::write(WriteStream & os) const
 void MathNestInset::normalize(NormalStream & os) const
 {
        os << '[' << name().c_str();
-       for (unsigned i = 0; i < nargs(); ++i)
+       for (size_t i = 0; i < nargs(); ++i)
                os << ' ' << cell(i);
        os << ']';
 }
@@ -275,29 +277,75 @@ void MathNestInset::notifyCursorLeaves(idx_type idx)
 
 
 DispatchResult
-MathNestInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
-       CursorSlice & cur = cursorTip(bv);
-       switch (cmd.action) {
+       //lyxerr << "InsetFormulaBase::localDispatch: act: " << cmd.action
+       //      << " arg: '" << cmd.argument
+       //      << "' x: '" << cmd.x
+       //      << " y: '" << cmd.y
+       //      << "' button: " << cmd.button() << endl;
 
-               case LFUN_PASTE: {
-                       MathArray ar;
-                       mathed_parse_cell(ar, cmd.argument);
-                       cur.cell().insert(cur.pos(), ar);
-                       cur.pos() += ar.size();
-                       return DispatchResult(true, true);
-               }
+       switch (cmd.action) {
 
-               case LFUN_PASTESELECTION:
-                       return dispatch(bv, FuncRequest(LFUN_PASTE, bv.getClipboard())); 
+       case LFUN_PASTE: {
+               MathArray ar;
+               mathed_parse_cell(ar, cmd.argument);
+               cur.cell().insert(cur.pos(), ar);
+               cur.pos() += ar.size();
+               return DispatchResult(true, true);
+       }
 
-               case LFUN_MOUSE_PRESS:
-                       if (cmd.button() == mouse_button::button2)
-                               return priv_dispatch(bv, FuncRequest(LFUN_PASTESELECTION));
-                       return DispatchResult(false);
+       case LFUN_PASTESELECTION:
+               return dispatch(cur, FuncRequest(LFUN_PASTE, cur.bv().getClipboard())); 
+
+       case LFUN_MOUSE_PRESS:
+               if (cmd.button() == mouse_button::button2)
+                       return priv_dispatch(cur, FuncRequest(LFUN_PASTESELECTION));
+               return DispatchResult(false);
+
+       case LFUN_RIGHTSEL:
+               cur.selection() = true; // fall through...
+       case LFUN_RIGHT:
+               return mathcursor::right(cur, cur.selection()) ?
+                       DispatchResult(true, true) : DispatchResult(false, FINISHED_RIGHT);
+               //lyxerr << "calling scroll 20" << endl;
+               //scroll(&cur.bv(), 20);
+               // write something to the minibuffer
+               //cur.bv().owner()->message(mathcursor::info());
+
+       case LFUN_LEFTSEL:
+               cur.selection() = true; // fall through
+       case LFUN_LEFT:
+               return mathcursor::left(cur, cur.selection()) ?
+                       DispatchResult(true, true) : DispatchResult(false, FINISHED);
+
+       case LFUN_UPSEL:
+               cur.selection() = true; // fall through
+       case LFUN_UP:
+               return mathcursor::up(cur, cur.selection()) ?
+                       DispatchResult(true, true) : DispatchResult(false, FINISHED_UP);
+
+       case LFUN_DOWNSEL:
+               cur.selection() = true; // fall through
+       case LFUN_DOWN:
+               return mathcursor::down(cur, cur.selection()) ?
+                       DispatchResult(true, true) : DispatchResult(false, FINISHED_DOWN);
+
+       case LFUN_SELFINSERT:
+               if (!cmd.argument.empty()) {
+                       recordUndo(cur, Undo::ATOMIC);
+                       if (cmd.argument.size() == 1) {
+                               if (mathcursor::interpret(cur, cmd.argument[0]))
+                                       return DispatchResult(true, true);
+                               else
+                                       return DispatchResult(false, FINISHED_RIGHT);
+                       }
+                       mathcursor::insert(cur, cmd.argument);
+               }
+               break;
 
-               default:
-                       return MathInset::priv_dispatch(bv, cmd);
+       default:
+               return MathInset::priv_dispatch(cur, cmd);
        }
 }
 
index 9fd8401a81fd5ded46367c04c279b50eaf8108ca..354b5aa4a135105ccfadb63605e255dcbf7a07ea 100644 (file)
@@ -101,7 +101,7 @@ protected:
        ///
        virtual
        DispatchResult
-       priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+       priv_dispatch(LCursor & cur, FuncRequest const & cmd);
 
        /// we store the cells in a vector
        typedef std::vector<MathArray> cells_type;
index 5f32d98e8495add6c0217619452677e13cc5a2cf..b16f4b2c7cf96d197b91c357c96088184d7523c0 100644 (file)
@@ -13,7 +13,7 @@
 #include "math_oversetinset.h"
 #include "math_data.h"
 #include "math_mathmlstream.h"
-
+#include "cursor.h"
 
 using std::max;
 using std::auto_ptr;
index 7ba1100edea89b350abaa86884a43e281f7212a2..0b99091aadb16cf973c07e130b33ef53dea5c024 100644 (file)
 #include "math_rootinset.h"
 #include "math_data.h"
 #include "math_mathmlstream.h"
+#include "cursor.h"
 #include "LColor.h"
-#include "frontends/Painter.h"
 
+#include "frontends/Painter.h"
 
 using std::max;
 using std::auto_ptr;
 
 
+
 MathRootInset::MathRootInset()
        : MathNestInset(2)
 {}
index 4e52e1abd48e1d59f013a4d49afbb923de6a2587..faa46b1e673cc07b768c03cf46f9df54cfef6c3a 100644 (file)
 #include "math_support.h"
 #include "math_symbolinset.h"
 #include "dispatchresult.h"
+#include "cursor.h"
 #include "debug.h"
 #include "funcrequest.h"
 
 #include <boost/assert.hpp>
 
-
 using std::string;
 using std::max;
 using std::auto_ptr;
 using std::endl;
 
 
+
 MathScriptInset::MathScriptInset()
        : MathNestInset(3), limits_(0)
 {
@@ -512,7 +513,7 @@ void MathScriptInset::notifyCursorLeaves(idx_type idx)
 
 
 DispatchResult
-MathScriptInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+MathScriptInset::priv_dispatch(LCursor & bv, FuncRequest const & cmd)
 {
        if (cmd.action == LFUN_MATH_LIMITS) {
                if (!cmd.argument.empty()) {
index c948751f86ed66b037044a3c974f111c2eecda4b..d2b889dc0b5e0478a2982f903b9df47f2fce7dab 100644 (file)
@@ -99,7 +99,7 @@ protected:
        ///
        virtual
        DispatchResult
-       priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+       priv_dispatch(LCursor & cur, FuncRequest const & cmd);
 private:
        /// returns x offset for main part
        int dxx() const;
index 6d1f34ecd4069f32588a93d031c7fafcf77df0ca..734984e9069b838c9eed2ef607dffdff4017d5db 100644 (file)
 #include "math_undersetinset.h"
 #include "math_data.h"
 #include "math_mathmlstream.h"
-
+#include "cursor.h"
 
 using std::max;
 using std::auto_ptr;
 
 
+
 auto_ptr<InsetBase> MathUndersetInset::clone() const
 {
        return auto_ptr<InsetBase>(new MathUndersetInset(*this));
index 23ec4e5b1b8529872710638943026f00b73630d8..391cffda4960177a9afffea1668c5ada10e4433d 100644 (file)
@@ -15,6 +15,7 @@
 #include "math_factory.h"
 
 #include "BufferView.h"
+#include "cursor.h"
 #include "dispatchresult.h"
 #include "debug.h"
 #include "funcrequest.h"
 #include "frontends/LyXView.h"
 #include "frontends/Dialogs.h"
 
-
 using std::string;
 using std::auto_ptr;
 using std::endl;
 
 
+
 RefInset::RefInset()
        : CommandInset("ref")
 {}
@@ -53,8 +54,7 @@ void RefInset::infoize(std::ostream & os) const
 }
 
 
-DispatchResult
-RefInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+DispatchResult RefInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
        switch (cmd.action) {
        case LFUN_INSET_MODIFY:
@@ -62,35 +62,34 @@ RefInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                        MathArray ar;
                        if (!createMathInset_fromDialogStr(cmd.argument, ar))
                                return DispatchResult(false);
-
                        *this = *ar[0].nucleus()->asRefInset();
-
                        return DispatchResult(true, true);
                }
-               break;
+               return DispatchResult(false);
+
        case LFUN_MOUSE_RELEASE:
                if (cmd.button() == mouse_button::button3) {
                        lyxerr << "trying to goto ref" << cell(0) << endl;
-                       bv.dispatch(FuncRequest(LFUN_REF_GOTO, asString(cell(0))));
+                       cur.bv().dispatch(FuncRequest(LFUN_REF_GOTO, asString(cell(0))));
                        return DispatchResult(true, true);
                }
                if (cmd.button() == mouse_button::button1) {
                        // Eventually trigger dialog with button 3
                        // not 1
                        string const data = createDialogStr("ref");
-                       bv.owner()->getDialogs().show("ref", data, this);
+                       cur.bv().owner()->getDialogs().show("ref", data, this);
                        return DispatchResult(true, true);
                }
-               break;
+               return DispatchResult(false);
+
        case LFUN_MOUSE_PRESS:
        case LFUN_MOUSE_MOTION:
                // eat other mouse commands
                return DispatchResult(true, true);
+
        default:
-               return CommandInset::priv_dispatch(bv, cmd);
+               return CommandInset::priv_dispatch(cur, cmd);
        }
-       // not our business
-       return DispatchResult(false);
 }
 
 
index a65f9be9e28458ae6b3943c5fa3ec77902366af0..8ca6155f79429ae2d0e927e9f8e786a2835a9161 100644 (file)
@@ -62,7 +62,7 @@ protected:
        ///
        virtual
        DispatchResult
-       priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+       priv_dispatch(LCursor & cur, FuncRequest const & cmd);
 };
 
 #endif
index 8fe21d9e616c7fff7e3f9ab99ecc521dbea25a19..cf4d8bfe7d0d097caa68d1a303ed8612505dd5a9 100644 (file)
@@ -132,7 +132,7 @@ RowPainter::RowPainter(BufferView const & bv, LyXText const & text,
                paintBackground();
 
        // paint the selection background
-       if (bv_.selection().set() && &text_ == bv_.fullCursor().innerText())
+       if (bv_.cursor().selection() && &text_ == bv_.cursor().innerText())
                paintSelection();
 
        // vertical lines for appendix
@@ -391,14 +391,15 @@ void RowPainter::paintSelection()
        bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params());
 
        // the current selection
-       int const startx = text_.cursorX(bv_.selStart());
-       int const endx = text_.cursorX(bv_.selEnd());
-       int const starty = text_.cursorY(bv_.selStart());
-       int const endy = text_.cursorY(bv_.selEnd());
-       ParagraphList::iterator startpit = text_.getPar(bv_.selStart());
-       ParagraphList::iterator endpit = text_.getPar(bv_.selEnd());
-       RowList::iterator startrow = startpit->getRow(bv_.selStart().pos());
-       RowList::iterator endrow = endpit->getRow(bv_.selEnd().pos());
+       LCursor const & cur = bv_.cursor();
+       int const startx = text_.cursorX(cur.selStart());
+       int const endx = text_.cursorX(cur.selEnd());
+       int const starty = text_.cursorY(cur.selStart());
+       int const endy = text_.cursorY(cur.selEnd());
+       ParagraphList::iterator startpit = text_.getPar(cur.selStart());
+       ParagraphList::iterator endpit = text_.getPar(cur.selEnd());
+       RowList::iterator startrow = startpit->getRow(cur.selStart().pos());
+       RowList::iterator endrow = endpit->getRow(cur.selEnd().pos());
        int const h = row_.height();
 
        int const row_y = pit_->y + row_.y_offset();
@@ -468,9 +469,9 @@ void RowPainter::paintSelection()
                }
 
                if (((startpit != pit_ && startrow != rit_)
-                               || bv_.selStart().pos() <= pos) &&
+                               || cur.selStart().pos() <= pos) &&
                        ((endpit != pit_ && endrow != rit_)
-                               || pos < bv_.selEnd().pos())) {
+                               || pos < cur.selEnd().pos())) {
                        // Here we do not use x_ as xo_ was added to x_.
                        pain_.fillRectangle(int(old_tmpx), yo_,
                                int(tmpx - old_tmpx + 1), h, LColor::selection);
index 5f477a7605f2f3e43538dc906b83150b518c6f54..b2073c384a2363baa2d508ae6f74b91b64bde2ec 100644 (file)
@@ -833,7 +833,7 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
 // convenience function
 void LyXText::redoParagraph()
 {
-       bv()->clearSelection();
+       bv()->cursor().clearSelection();
        redoParagraph(cursorPar());
        setCursorIntern(cursor().par(), cursor().pos());
 }
@@ -1104,9 +1104,9 @@ void LyXText::selectWord(word_location loc)
                setCursor(from.par(), from.pos());
        if (to == from)
                return;
-       bv()->resetAnchor();
+       bv()->cursor().resetAnchor();
        setCursor(to.par(), to.pos());
-       bv()->setSelection();
+       bv()->cursor().setSelection();
 }
 
 
@@ -1114,26 +1114,26 @@ void LyXText::selectWord(word_location loc)
 // selection is currently set
 bool LyXText::selectWordWhenUnderCursor(word_location loc)
 {
-       if (!bv()->selection().set()) {
-               selectWord(loc);
-               return bv()->selection().set();
-       }
-       return false;
+       if (bv()->cursor().selection())
+               return false;
+       selectWord(loc);
+       return bv()->cursor().selection();
 }
 
 
 void LyXText::acceptChange()
 {
-       if (!bv()->selection().set() && cursorPar()->size())
+       LCursor & cur = bv()->cursor();
+       if (!cur.selection() && cursorPar()->size())
                return;
 
-       if (bv()->selStart().par() == bv()->selEnd().par()) {
-               CursorSlice const & startc = bv()->selStart();
-               CursorSlice const & endc = bv()->selEnd();
+       if (cur.selStart().par() == cur.par()) {
+               CursorSlice const & startc = cur.selStart();
+               CursorSlice const & endc = cur.selEnd();
                recordUndo(Undo::INSERT, this, startc.par());
                getPar(startc)->acceptChange(startc.pos(), endc.pos());
                finishUndo();
-               bv()->clearSelection();
+               cur.clearSelection();
                redoParagraph(getPar(startc));
                setCursorIntern(startc.par(), 0);
        }
@@ -1143,16 +1143,17 @@ void LyXText::acceptChange()
 
 void LyXText::rejectChange()
 {
-       if (!bv()->selection().set() && cursorPar()->size())
+       LCursor & cur = bv()->cursor();
+       if (!cur.selection() && cursorPar()->size())
                return;
 
-       if (bv()->selStart().par() == bv()->selEnd().par()) {
-               CursorSlice const & startc = bv()->selStart();
-               CursorSlice const & endc = bv()->selEnd();
+       if (cur.selStart().par() == cur.selEnd().par()) {
+               CursorSlice const & startc = cur.selStart();
+               CursorSlice const & endc = cur.selEnd();
                recordUndo(Undo::INSERT, this, startc.par());
                getPar(startc)->rejectChange(startc.pos(), endc.pos());
                finishUndo();
-               bv()->clearSelection();
+               cur.clearSelection();
                redoParagraph(getPar(startc));
                setCursorIntern(startc.par(), 0);
        }
@@ -1163,16 +1164,17 @@ void LyXText::rejectChange()
 // Delete from cursor up to the end of the current or next word.
 void LyXText::deleteWordForward()
 {
+       LCursor & cur = bv()->cursor();
        if (cursorPar()->empty())
-               cursorRight(bv());
+               cursorRight(true);
        else {
                CursorSlice tmpcursor = cursor();
-               bv()->selection().set(true); // to avoid deletion
+               cur.selection() = true; // to avoid deletion
                cursorRightOneWord();
                setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
-               bv()->resetAnchor();
+               cur.resetAnchor();
                cursor() = tmpcursor;
-               bv()->setSelection();
+               cur.setSelection();
                cutSelection(true, false);
        }
 }
@@ -1181,16 +1183,17 @@ void LyXText::deleteWordForward()
 // Delete from cursor to start of current or prior word.
 void LyXText::deleteWordBackward()
 {
+       LCursor & cur = bv()->cursor();
        if (cursorPar()->empty())
-               cursorLeft(bv());
+               cursorLeft(true);
        else {
                CursorSlice tmpcursor = cursor();
-               bv()->selection().set(true); // to avoid deletion
+               cur.selection() = true; // to avoid deletion
                cursorLeftOneWord();
                setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
-               bv()->resetAnchor();
+               cur.resetAnchor();
                cursor() = tmpcursor;
-               bv()->setSelection();
+               cur.setSelection();
                cutSelection(true, false);
        }
 }
@@ -1199,19 +1202,20 @@ void LyXText::deleteWordBackward()
 // Kill to end of line.
 void LyXText::deleteLineForward()
 {
+       LCursor & cur = bv()->cursor();
        if (cursorPar()->empty()) {
                // Paragraph is empty, so we just go to the right
-               cursorRight(bv());
+               cursorRight(true);
        } else {
                CursorSlice tmpcursor = cursor();
-               bv()->selection().set(true); // to avoid deletion
+               cur.selection() = true; // to avoid deletion
                cursorEnd();
                setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
-               bv()->resetAnchor();
+               cur.resetAnchor();
                cursor() = tmpcursor;
-               bv()->setSelection();
+               cur.setSelection();
                // What is this test for ??? (JMarc)
-               if (!bv()->selection().set())
+               if (!cur.selection())
                        deleteWordForward();
                else
                        cutSelection(true, false);
@@ -1221,12 +1225,13 @@ void LyXText::deleteLineForward()
 
 void LyXText::changeCase(LyXText::TextCase action)
 {
+       LCursor & cur = bv()->cursor();
        CursorSlice from;
        CursorSlice to;
 
-       if (bv()->selection().set()) {
-               from = bv()->selStart();
-               to = bv()->selEnd();
+       if (cur.selection()) {
+               from = cur.selStart();
+               to = cur.selEnd();
        } else {
                from = cursor();
                getWord(from, to, lyx::PARTIAL_WORD);
@@ -1507,14 +1512,15 @@ void LyXText::previousRow(ParagraphList::iterator & pit,
 
 string LyXText::selectionAsString(Buffer const & buffer, bool label) const
 {
-       if (!bv()->selection().set())
+       LCursor & cur = bv()->cursor();
+       if (!cur.selection())
                return string();
 
        // should be const ...
-       ParagraphList::iterator startpit = getPar(bv()->selStart());
-       ParagraphList::iterator endpit = getPar(bv()->selEnd());
-       size_t const startpos = bv()->selStart().pos();
-       size_t const endpos = bv()->selEnd().pos();
+       ParagraphList::iterator startpit = getPar(cur.selStart());
+       ParagraphList::iterator endpit = getPar(cur.selEnd());
+       size_t const startpos = cur.selStart().pos();
+       size_t const endpos = cur.selEnd().pos();
 
        if (startpit == endpit)
                return startpit->asString(buffer, startpos, endpos, label);
@@ -1601,7 +1607,7 @@ void LyXText::redoParagraph(ParagraphList::iterator pit)
 void LyXText::fullRebreak()
 {
        redoParagraphs(paragraphs().begin(), paragraphs().end());
-       bv()->resetAnchor();
+       bv()->cursor().resetAnchor();
 }
 
 
@@ -1937,23 +1943,23 @@ int LyXText::cursorY(CursorSlice const & cur) const
 
 CursorSlice & LyXText::cursor()
 {
-       return bv()->cursor();
+       return bv()->cursor().cursor_.back();
 }
 
 
 CursorSlice const & LyXText::cursor() const
 {
-       return bv()->cursor();
+       return bv()->cursor().cursor_.back();
 }
 
 
 CursorSlice & LyXText::anchor()
 {
-       return bv()->anchor();
+       return bv()->cursor().anchor_.back();
 }
 
 
 CursorSlice const & LyXText::anchor() const
 {
-       return bv()->anchor();
+       return bv()->cursor().anchor_.back();
 }
index d29df28b39a25ff46b6ac6e1b8d44e5e0967d52b..61ae776ac7febfbb477a6749f98b7fc31f8a8a89 100644 (file)
@@ -95,7 +95,7 @@ void LyXText::init(BufferView * bview)
 
        redoParagraphs(beg, end);
        setCursorIntern(0, 0);
-       bv()->resetAnchor();
+       bv()->cursor().resetAnchor();
 
        updateCounters();
 }
@@ -333,8 +333,10 @@ void LyXText::setLayout(string const & layout)
                return;
        }
 
-       ParagraphList::iterator start = getPar(bv()->selStart().par());
-       ParagraphList::iterator end = boost::next(getPar(bv()->selEnd().par()));
+       ParagraphList::iterator start =
+               getPar(bv()->cursor().selStart().par());
+       ParagraphList::iterator end =
+               boost::next(getPar(bv()->cursor().selEnd().par()));
        ParagraphList::iterator endpit = setLayout(start, end, layout);
 
        redoParagraphs(start, endpit);
@@ -349,12 +351,12 @@ void getSelectionSpan(LyXText & text,
        ParagraphList::iterator & beg,
        ParagraphList::iterator & end)
 {
-       if (!text.bv()->selection().set()) {
+       if (!text.bv()->cursor().selection()) {
                beg = text.cursorPar();
                end = boost::next(beg);
        } else {
-               beg = text.getPar(text.bv()->selStart());
-               end = boost::next(text.getPar(text.bv()->selEnd()));
+               beg = text.getPar(text.bv()->cursor().selStart());
+               end = boost::next(text.getPar(text.bv()->cursor().selEnd()));
        }
 }
 
@@ -424,8 +426,9 @@ void LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type)
 // set font over selection and make a total rebreak of those paragraphs
 void LyXText::setFont(LyXFont const & font, bool toggleall)
 {
+       LCursor & cur = bv()->cursor();
        // if there is no selection just set the current_font
-       if (!bv()->selection().set()) {
+       if (!cur.selection()) {
                // Determine basis font
                LyXFont layoutfont;
                if (cursor().pos() < cursorPar()->beginOfBody())
@@ -448,14 +451,14 @@ void LyXText::setFont(LyXFont const & font, bool toggleall)
        }
 
        // ok we have a selection.
-       recUndo(bv()->selStart().par(), bv()->selEnd().par());
+       recUndo(cur.selStart().par(), cur.selEnd().par());
        freezeUndo();
 
-       ParagraphList::iterator beg = getPar(bv()->selStart().par());
-       ParagraphList::iterator end = getPar(bv()->selEnd().par());
+       ParagraphList::iterator beg = getPar(cur.selStart().par());
+       ParagraphList::iterator end = getPar(cur.selEnd().par());
        
-       PosIterator pos(&paragraphs(), beg, bv()->selStart().pos());
-       PosIterator posend(&paragraphs(), end, bv()->selEnd().pos());
+       PosIterator pos(&paragraphs(), beg, cur.selStart().pos());
+       PosIterator posend(&paragraphs(), end, cur.selEnd().pos());
 
        BufferParams const & params = bv()->buffer()->params();
 
@@ -530,15 +533,16 @@ void LyXText::toggleFree(LyXFont const & font, bool toggleall)
        // Implicit selections are cleared afterwards
        //and cursor is set to the original position.
        if (implicitSelection) {
-               bv()->clearSelection();
+               bv()->cursor().clearSelection();
                cursor() = resetCursor;
-               bv()->resetAnchor();
+               bv()->cursor().resetAnchor();
        }
 }
 
 
 string LyXText::getStringToIndex()
 {
+       LCursor & cur = bv()->cursor();
        // Try implicit word selection
        // If there is a change in the language the implicit word selection
        // is disabled.
@@ -547,20 +551,20 @@ string LyXText::getStringToIndex()
                selectWordWhenUnderCursor(lyx::PREVIOUS_WORD);
 
        string idxstring;
-       if (!bv()->selection().set())
+       if (!cur.selection())
                bv()->owner()->message(_("Nothing to index!"));
-       else if (bv()->selStart().par() != bv()->selEnd().par())
+       else if (cur.selStart().par() != cur.selEnd().par())
                bv()->owner()->message(_("Cannot index more than one paragraph!"));
        else
                idxstring = selectionAsString(*bv()->buffer(), false);
 
        // Reset cursors to their original position.
        cursor() = reset_cursor;
-       bv()->resetAnchor();
+       cur.resetAnchor();
 
        // Clear the implicit selection.
        if (implicitSelection)
-               bv()->clearSelection();
+               cur.clearSelection();
 
        return idxstring;
 }
@@ -575,12 +579,13 @@ string LyXText::getStringToIndex()
 void LyXText::setParagraph(Spacing const & spacing, LyXAlignment align,
        string const & labelwidthstring, bool noindent)
 {
+       LCursor & cur = bv()->cursor();
        // make sure that the depth behind the selection are restored, too
-       ParagraphList::iterator undopit = undoSpan(getPar(bv()->selEnd()));
-       recUndo(bv()->selStart().par(), parOffset(undopit) - 1);
+       ParagraphList::iterator undopit = undoSpan(getPar(cur.selEnd()));
+       recUndo(cur.selStart().par(), parOffset(undopit) - 1);
 
-       ParagraphList::reverse_iterator pit(getPar(bv()->selEnd().par()));
-       ParagraphList::reverse_iterator beg(getPar(bv()->selStart().par()));
+       ParagraphList::reverse_iterator pit(getPar(cur.selEnd().par()));
+       ParagraphList::reverse_iterator beg(getPar(cur.selStart().par()));
 
        for (--pit; pit != beg; ++pit) {
                ParagraphParameters & params = pit->params();
@@ -601,7 +606,7 @@ void LyXText::setParagraph(Spacing const & spacing, LyXAlignment align,
                params.noindent(noindent);
        }
 
-       redoParagraphs(getPar(bv()->selStart()), undopit);
+       redoParagraphs(getPar(cur.selStart()), undopit);
 }
 
 
@@ -918,6 +923,7 @@ void LyXText::insertInset(InsetOld * inset)
 
 void LyXText::cutSelection(bool doclear, bool realcut)
 {
+       LCursor & cur = bv()->cursor();
        // Stuff what we got on the clipboard. Even if there is no selection.
 
        // There is a problem with having the stuffing here in that the
@@ -929,32 +935,32 @@ void LyXText::cutSelection(bool doclear, bool realcut)
        bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
 
        // This doesn't make sense, if there is no selection
-       if (!bv()->selection().set())
+       if (!cur.selection())
                return;
 
-       // OK, we have a selection. This is always between bv()->selStart()
-       // and bv()->selEnd()
+       // OK, we have a selection. This is always between cur.selStart()
+       // and cur.selEnd()
 
        // make sure that the depth behind the selection are restored, too
-       ParagraphList::iterator begpit = getPar(bv()->selStart().par());
-       ParagraphList::iterator endpit = getPar(bv()->selEnd().par());
+       ParagraphList::iterator begpit = getPar(cur.selStart().par());
+       ParagraphList::iterator endpit = getPar(cur.selEnd().par());
        ParagraphList::iterator undopit = undoSpan(endpit);
-       recUndo(bv()->selStart().par(), parOffset(undopit) - 1);
+       recUndo(cur.selStart().par(), parOffset(undopit) - 1);
 
-       int endpos = bv()->selEnd().pos();
+       int endpos = cur.selEnd().pos();
 
        BufferParams const & bufparams = bv()->buffer()->params();
        boost::tie(endpit, endpos) = realcut ?
                CutAndPaste::cutSelection(bufparams,
                                          paragraphs(),
                                          begpit , endpit,
-                                         bv()->selStart().pos(), endpos,
+                                         cur.selStart().pos(), endpos,
                                          bufparams.textclass,
                                          doclear)
                : CutAndPaste::eraseSelection(bufparams,
                                              paragraphs(),
                                              begpit, endpit,
-                                             bv()->selStart().pos(), endpos,
+                                             cur.selStart().pos(), endpos,
                                              doclear);
        // sometimes necessary
        if (doclear)
@@ -968,40 +974,42 @@ void LyXText::cutSelection(bool doclear, bool realcut)
        cursor().par(parOffset(endpit));
 
        // need a valid cursor. (Lgb)
-       bv()->clearSelection();
+       cur.clearSelection();
        updateCounters();
 }
 
 
 void LyXText::copySelection()
 {
+       LCursor & cur = bv()->cursor();
        // stuff the selection onto the X clipboard, from an explicit copy request
        bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
 
        // this doesnt make sense, if there is no selection
-       if (!bv()->selection().set())
+       if (!cur.selection())
                return;
 
-       // ok we have a selection. This is always between bv()->selStart()
+       // ok we have a selection. This is always between cur.selStart()
        // and sel_end cursor
 
        // copy behind a space if there is one
-       while (getPar(bv()->selStart())->size() > bv()->selStart().pos()
-              && getPar(bv()->selStart())->isLineSeparator(bv()->selStart().pos())
-              && (bv()->selStart().par() != bv()->selEnd().par()
-                  || bv()->selStart().pos() < bv()->selEnd().pos()))
-               bv()->selStart().pos(bv()->selStart().pos() + 1);
-
-       CutAndPaste::copySelection(getPar(bv()->selStart().par()),
-                                  getPar(bv()->selEnd().par()),
-                                  bv()->selStart().pos(), 
-                                  bv()->selEnd().pos(),
+       while (getPar(cur.selStart())->size() > cur.selStart().pos()
+              && getPar(cur.selStart())->isLineSeparator(cur.selStart().pos())
+              && (cur.selStart().par() != cur.selEnd().par()
+                  || cur.selStart().pos() < cur.selEnd().pos()))
+               cur.selStart().pos(cur.selStart().pos() + 1);
+
+       CutAndPaste::copySelection(getPar(cur.selStart().par()),
+                                  getPar(cur.selEnd().par()),
+                                  cur.selStart().pos(), 
+                                  cur.selEnd().pos(),
                                   bv()->buffer()->params().textclass);
 }
 
 
 void LyXText::pasteSelection(size_t sel_index)
 {
+       LCursor & cur = bv()->cursor();
        // this does not make sense, if there is nothing to paste
        if (!CutAndPaste::checkPastePossible())
                return;
@@ -1024,10 +1032,10 @@ void LyXText::pasteSelection(size_t sel_index)
 
        redoParagraphs(cursorPar(), endpit);
 
-       bv()->clearSelection();
-       bv()->resetAnchor();
+       cur.clearSelection();
+       cur.resetAnchor();
        setCursor(ppp.first, ppp.second);
-       bv()->setSelection();
+       cur.setSelection();
        updateCounters();
 }
 
@@ -1037,30 +1045,32 @@ void LyXText::setSelectionRange(lyx::pos_type length)
        if (!length)
                return;
 
-       bv()->resetAnchor();
+       LCursor & cur = bv()->cursor();
+       cur.resetAnchor();
        while (length--)
                cursorRight(true);
-       bv()->setSelection();
+       cur.setSelection();
 }
 
 
 // simple replacing. The font of the first selected character is used
 void LyXText::replaceSelectionWithString(string const & str)
 {
-       recUndo(cursor().par());
+       LCursor & cur = bv()->cursor();
+       recUndo(cur.par());
        freezeUndo();
 
        // Get font setting before we cut
-       pos_type pos = bv()->selEnd().pos();
-       LyXFont const font = getPar(bv()->selStart())
+       pos_type pos = cur.selEnd().pos();
+       LyXFont const font = getPar(cur.selStart())
                ->getFontSettings(bv()->buffer()->params(),
-                                 bv()->selStart().pos());
+                                 cur.selStart().pos());
 
        // Insert the new string
        string::const_iterator cit = str.begin();
        string::const_iterator end = str.end();
        for (; cit != end; ++cit) {
-               getPar(bv()->selEnd())->insertChar(pos, (*cit), font);
+               getPar(cur.selEnd())->insertChar(pos, (*cit), font);
                ++pos;
        }
 
@@ -1074,6 +1084,7 @@ void LyXText::replaceSelectionWithString(string const & str)
 // needed to insert the selection
 void LyXText::insertStringAsLines(string const & str)
 {
+       LCursor & cur = bv()->cursor();
        ParagraphList::iterator pit = cursorPar();
        pos_type pos = cursor().pos();
        ParagraphList::iterator endpit = boost::next(cursorPar());
@@ -1081,13 +1092,13 @@ void LyXText::insertStringAsLines(string const & str)
        recUndo(cursor().par());
 
        // only to be sure, should not be neccessary
-       bv()->clearSelection();
+       cur.clearSelection();
        bv()->buffer()->insertStringAsLines(pit, pos, current_font, str);
 
        redoParagraphs(cursorPar(), endpit);
-       bv()->resetAnchor();
+       cur.resetAnchor();
        setCursor(pit, pos);
-       bv()->setSelection();
+       cur.setSelection();
 }
 
 
@@ -1148,8 +1159,8 @@ void LyXText::setCursor(CursorSlice & cur, paroffset_type par,
                return;
 
        // now some strict checking
-       ParagraphList::iterator pit = getPar(par);
-       Row const & row = *pit->getRow(pos);
+       Paragraph & para = *getPar(par);
+       Row const & row = *para.getRow(pos);
        pos_type const end = row.endpos();
 
        // None of these should happen, but we're scaredy-cats
@@ -1158,9 +1169,9 @@ void LyXText::setCursor(CursorSlice & cur, paroffset_type par,
                pos = 0;
                cur.pos(0);
                BOOST_ASSERT(false);
-       } else if (pos > pit->size()) {
+       } else if (pos > para.size()) {
                lyxerr << "dont like 1, pos: " << pos
-                      << " size: " << pit->size()
+                      << " size: " << para.size()
                       << " row.pos():" << row.pos()
                       << " paroffset: " << par << endl;
                pos = 0;
@@ -1174,7 +1185,7 @@ void LyXText::setCursor(CursorSlice & cur, paroffset_type par,
                BOOST_ASSERT(false);
        } else if (pos < row.pos()) {
                lyxerr << "dont like 3 please report pos:" << pos
-                      << " size: " << pit->size()
+                      << " size: " << para.size()
                       << " row.pos():" << row.pos()
                       << " paroffset: " << par << endl;
                pos = row.pos();
@@ -1188,7 +1199,7 @@ void LyXText::setCursorIntern(paroffset_type par,
                              pos_type pos, bool setfont, bool boundary)
 {
        setCursor(cursor(), par, pos, boundary);
-       bv()->x_target(cursorX() + xo_);
+       bv()->cursor().x_target(cursorX() + xo_);
        if (setfont)
                setCurrentFont();
 }
@@ -1196,7 +1207,8 @@ void LyXText::setCursorIntern(paroffset_type par,
 
 void LyXText::setCurrentFont()
 {
-       pos_type pos = cursor().pos();
+       LCursor & cur = bv()->cursor();
+       pos_type pos = cur.pos();
        ParagraphList::iterator pit = cursorPar();
 
        if (cursor().boundary() && pos > 0)
@@ -1303,7 +1315,7 @@ pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
 
        // If lastrow is false, we don't need to compute
        // the value of rtl.
-       bool const rtl = (lastrow)
+       bool const rtl = lastrow
                ? pit->isRightToLeftPar(bv()->buffer()->params())
                : false;
        if (lastrow &&
@@ -1366,7 +1378,7 @@ bool LyXText::checkAndActivateInset(bool front)
        InsetOld * inset = cursorPar()->getInset(cursor().pos());
        if (!isHighlyEditableInset(inset))
                return false;
-       inset->edit(bv(), front);
+       inset->edit(bv()->cursor(), front);
        return true;
 }
 
@@ -1399,7 +1411,7 @@ DispatchResult LyXText::moveRightIntern(bool front, bool activate_inset, bool se
                return DispatchResult(true, true);
        cursorRight(true);
        if (!selecting)
-               bv()->clearSelection();
+               bv()->cursor().clearSelection();
        return DispatchResult(true);
 }
 
@@ -1411,7 +1423,7 @@ DispatchResult LyXText::moveLeftIntern(bool front,
                return DispatchResult(false, FINISHED);
        cursorLeft(true);
        if (!selecting)
-               bv()->clearSelection();
+               bv()->cursor().clearSelection();
        if (activate_inset && checkAndActivateInset(front))
                return DispatchResult(true, true);
        return DispatchResult(true);
@@ -1423,35 +1435,37 @@ DispatchResult LyXText::moveUp()
        if (cursorPar() == firstPar() && cursorRow() == firstRow())
                return DispatchResult(false, FINISHED_UP);
        cursorUp(false);
-       bv()->clearSelection();
+       bv()->cursor().clearSelection();
        return DispatchResult(true);
 }
 
 
 DispatchResult LyXText::moveDown()
 {
+       LCursor & cur = bv()->cursor();
        if (cursorPar() == lastPar() && cursorRow() == lastRow())
                return DispatchResult(false, FINISHED_DOWN);
        cursorDown(false);
-       bv()->clearSelection();
+       cur.clearSelection();
        return DispatchResult(true);
 }
 
 
 bool LyXText::cursorLeft(bool internal)
 {
-       if (cursor().pos() > 0) {
-               bool boundary = cursor().boundary();
-               setCursor(cursor().par(), cursor().pos() - 1, true, false);
+       LCursor & cur = bv()->cursor();
+       if (cur.pos() > 0) {
+               bool boundary = cur.boundary();
+               setCursor(cur.par(), cur.pos() - 1, true, false);
                if (!internal && !boundary &&
-                   bidi.isBoundary(*bv()->buffer(), *cursorPar(), cursor().pos() + 1))
-                       setCursor(cursor().par(), cursor().pos() + 1, true, true);
+                   bidi.isBoundary(*bv()->buffer(), cur.paragraph(), cur.pos() + 1))
+                       setCursor(cur.par(), cur.pos() + 1, true, true);
                return true;
        }
 
-       if (cursor().par() != 0) {
+       if (cur.par() != 0) {
                // steps into the paragraph above
-               setCursor(cursor().par() - 1, boost::prior(cursorPar())->size());
+               setCursor(cur.par() - 1, boost::prior(cursorPar())->size());
                return true;
        }
 
@@ -1461,21 +1475,22 @@ bool LyXText::cursorLeft(bool internal)
 
 bool LyXText::cursorRight(bool internal)
 {
-       if (!internal && cursor().boundary()) {
-               setCursor(cursor().par(), cursor().pos(), true, false);
+       LCursor & cur = bv()->cursor();
+       if (!internal && cur.boundary()) {
+               setCursor(cur.par(), cur.pos(), true, false);
                return true;
        }
 
-       if (cursor().pos() != cursorPar()->size()) {
-               setCursor(cursor().par(), cursor().pos() + 1, true, false);
-               if (!internal && bidi.isBoundary(*bv()->buffer(), *cursorPar(),
-                                                cursor().pos()))
-                       setCursor(cursor().par(), cursor().pos(), true, true);
+       if (cur.pos() != cur.lastpos()) {
+               setCursor(cur.par(), cur.pos() + 1, true, false);
+               if (!internal && bidi.isBoundary(*bv()->buffer(), cur.paragraph(),
+                                                cur.pos()))
+                       setCursor(cur.par(), cur.pos(), true, true);
                return true;
        }
 
-       if (cursor().par() + 1 != int(paragraphs().size())) {
-               setCursor(cursor().par() + 1, 0);
+       if (cur.par() + 1 != int(paragraphs().size())) {
+               setCursor(cur.par() + 1, 0);
                return true;
        }
 
@@ -1485,32 +1500,34 @@ bool LyXText::cursorRight(bool internal)
 
 void LyXText::cursorUp(bool selecting)
 {
+       LCursor & cur = bv()->cursor();
        Row const & row = *cursorRow();
-       int x = bv()->x_target() - xo_;
+       int x = cur.x_target() - xo_;
        int y = cursorY() - row.baseline() - 1;
        setCursorFromCoordinates(x, y);
 
        if (!selecting) {
                int y_abs = y + yo_ - bv()->top_y();
-               InsetOld * inset_hit = checkInsetHit(bv()->x_target(), y_abs);
+               InsetOld * inset_hit = checkInsetHit(cur.x_target(), y_abs);
                if (inset_hit && isHighlyEditableInset(inset_hit))
-                       inset_hit->edit(bv(), bv()->x_target(), y_abs);
+                       inset_hit->edit(cur, cur.x_target(), y_abs);
        }
 }
 
 
 void LyXText::cursorDown(bool selecting)
 {
+       LCursor & cur = bv()->cursor();
        Row const & row = *cursorRow();
-       int x = bv()->x_target() - xo_;
+       int x = cur.x_target() - xo_;
        int y = cursorY() - row.baseline() + row.height() + 1;
        setCursorFromCoordinates(x, y);
 
        if (!selecting) {
                int y_abs = y + yo_ - bv()->top_y();
-               InsetOld * inset_hit = checkInsetHit(bv()->x_target(), y_abs);
+               InsetOld * inset_hit = checkInsetHit(cur.x_target(), y_abs);
                if (inset_hit && isHighlyEditableInset(inset_hit))
-                       inset_hit->edit(bv(), bv()->x_target(), y_abs);
+                       inset_hit->edit(cur, cur.x_target(), y_abs);
        }
 }
 
@@ -1553,8 +1570,8 @@ void LyXText::fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where)
 
        // check also if we don't want to set the cursor on a spot behind the
        // pagragraph because we erased the last character.
-       if (cur.pos() > getPar(cur)->size())
-               cur.pos(getPar(cur)->size());
+       if (cur.pos() > cur.lastpos())
+               cur.pos() = cur.lastpos();
 }
 
 
@@ -1564,13 +1581,14 @@ bool LyXText::deleteEmptyParagraphMechanism(CursorSlice const & old_cursor)
        return false;
 
        // Would be wrong to delete anything if we have a selection.
-       if (bv()->selection().set())
+       if (bv()->cursor().selection())
                return false;
 
        // Don't do anything if the cursor is invalid
        if (old_cursor.par() == -1)
                return false;
 
+#if 0
        // We allow all kinds of "mumbo-jumbo" when freespacing.
        ParagraphList::iterator const old_pit = getPar(old_cursor);
        if (old_pit->isFreeSpacing())
@@ -1685,6 +1703,7 @@ bool LyXText::deleteEmptyParagraphMechanism(CursorSlice const & old_cursor)
                bv()->resetAnchor();
        }
        return false;
+#endif
 }
 
 
index 522f1b53de044a4f4c956adf9c0492c3b84f03b9..083c0fade8a62590d40bd0fa86d24ed4df65c227 100644 (file)
@@ -213,21 +213,20 @@ namespace {
        }
 
 
-       void moveCursor(BufferView * bv, bool selecting)
+       void moveCursor(LCursor & cur, bool selecting)
        {
-               if (selecting || bv->selection().mark())
-                       bv->setSelection();
-
-               if (!bv->selection().set())
-                       bv->haveSelection(false);
-               bv->switchKeyMap();
+               if (selecting || cur.mark())
+                       cur.setSelection();
+               if (!cur.selection())
+                       cur.bv().haveSelection(false);
+               cur.bv().switchKeyMap();
        }
 
 
        void finishChange(BufferView * bv, bool selecting = false)
        {
                finishUndo();
-               moveCursor(bv, selecting);
+               moveCursor(bv->cursor(), selecting);
                bv->owner()->view_state_changed();
        }
 
@@ -316,35 +315,36 @@ bool LyXText::gotoNextInset(vector<InsetOld::Code> const & codes,
 }
 
 
-void LyXText::gotoInset(vector<InsetOld::Code> const & codes,
-                       bool same_content)
+void LyXText::gotoInset(vector<InsetOld::Code> const & codes, bool same_content)
 {
-       bv()->clearSelection();
+       LCursor & cur = bv()->cursor();
+       cur.clearSelection();
 
        string contents;
-       if (same_content && cursor().pos() < cursorPar()->size()
-           && cursorPar()->isInset(cursor().pos())) {
-               InsetOld const * inset = cursorPar()->getInset(cursor().pos());
+       if (same_content
+           && cur.pos() < cur.lastpos()
+           && cur.paragraph().isInset(cur.pos())) {
+               InsetOld const * inset = cur.paragraph().getInset(cur.pos());
                if (find(codes.begin(), codes.end(), inset->lyxCode())
                    != codes.end())
                        contents = static_cast<InsetCommand const *>(inset)->getContents();
        }
 
        if (!gotoNextInset(codes, contents)) {
-               if (cursor().pos() || cursorPar() != paragraphs().begin()) {
+               if (cur.pos() || cur.par() != 0) {
                        CursorSlice tmp = cursor();
-                       cursor().par(0);
-                       cursor().pos(0);
+                       cur.par() = 0;
+                       cur.pos() = 0;
                        if (!gotoNextInset(codes, contents)) {
                                cursor() = tmp;
-                               bv()->owner()->message(_("No more insets"));
+                               cur.bv().owner()->message(_("No more insets"));
                        }
                } else {
-                       bv()->owner()->message(_("No more insets"));
+                       cur.bv().owner()->message(_("No more insets"));
                }
        }
-       bv()->update();
-       bv()->resetAnchor();
+       cur.bv().update();
+       cur.resetAnchor();
 }
 
 
@@ -356,15 +356,15 @@ void LyXText::gotoInset(InsetOld::Code code, bool same_content)
 
 void LyXText::cursorPrevious()
 {
-
+       LCursor & cur = bv()->cursor();
        RowList::iterator crit = cursorRow();
-       ParagraphList::iterator cpar = cursorPar();
+       lyx::paroffset_type cpar = cur.par();
 
-       int x = bv()->x_target() - xo_;
+       int x = bv()->cursor().x_target() - xo_;
        int y = bv()->top_y() - yo_;
        setCursorFromCoordinates(x, y);
 
-       if (cpar == cursorPar() && crit == cursorRow()) {
+       if (cpar == cur.par() && crit == cursorRow()) {
                // we have a row which is taller than the workarea. The
                // simplest solution is to move to the previous row instead.
                cursorUp(true);
@@ -380,7 +380,7 @@ void LyXText::cursorNext()
        RowList::iterator crit = cursorRow();
        ParagraphList::iterator cpar = cursorPar();
 
-       int x = bv()->x_target() - xo_;
+       int x = bv()->cursor().x_target() - xo_;
        int y = bv()->top_y() + bv()->workHeight() - yo_;
        setCursorFromCoordinates(x, y);
 
@@ -417,17 +417,18 @@ void doInsertInset(BufferView * bv, FuncRequest const & cmd,
                return;
 
        bool gotsel = false;
-       if (bv->selection().set()) {
+       if (bv->cursor().selection()) {
                bv->owner()->dispatch(FuncRequest(LFUN_CUT));
                gotsel = true;
        }
        if (bv->insertInset(inset)) {
                if (edit)
-                       inset->edit(bv, true);
+                       inset->edit(bv->cursor(), true);
                if (gotsel && pastesel)
                        bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
-       } else
+       } else {
                delete inset;
+       }
 }
 
 } // anon namespace
@@ -447,11 +448,11 @@ bool LyXText::rtl() const
 }
 
 
-DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
+DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
 {
        //lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
 
-       BufferView * bv = &view;
+       BufferView * bv = &cur.bv();
 
        switch (cmd.action) {
 
@@ -483,26 +484,26 @@ DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
        }
 
        case LFUN_DELETE_WORD_FORWARD:
-               bv->clearSelection();
+               cur.clearSelection();
                deleteWordForward();
                finishChange(bv);
                break;
 
        case LFUN_DELETE_WORD_BACKWARD:
-               bv->clearSelection();
+               cur.clearSelection();
                deleteWordBackward();
                finishChange(bv);
                break;
 
        case LFUN_DELETE_LINE_FORWARD:
-               bv->clearSelection();
+               cur.clearSelection();
                deleteLineForward();
                finishChange(bv);
                break;
 
        case LFUN_WORDRIGHT:
-               if (!bv->selection().mark())
-                       bv->clearSelection();
+               if (!cur.mark())
+                       cur.clearSelection();
                if (rtl())
                        cursorLeftOneWord();
                else
@@ -511,8 +512,8 @@ DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
                break;
 
        case LFUN_WORDLEFT:
-               if (!bv->selection().mark())
-                       bv->clearSelection();
+               if (!cur.mark())
+                       cur.clearSelection();
                if (rtl())
                        cursorRightOneWord();
                else
@@ -521,98 +522,98 @@ DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
                break;
 
        case LFUN_BEGINNINGBUF:
-               if (!bv->selection().mark())
-                       bv->clearSelection();
+               if (!cur.mark())
+                       cur.clearSelection();
                cursorTop();
                finishChange(bv);
                break;
 
        case LFUN_ENDBUF:
-               if (bv->selection().mark())
-                       bv->clearSelection();
+               if (!cur.mark())
+                       cur.clearSelection();
                cursorBottom();
                finishChange(bv);
                break;
 
        case LFUN_RIGHTSEL:
-               if (!bv->selection().set())
-                       bv->resetAnchor();
+               if (!cur.selection())
+                       cur.resetAnchor();
                if (rtl())
-                       cursorLeft(bv);
+                       cursorLeft(true);
                else
-                       cursorRight(bv);
+                       cursorRight(true);
                finishChange(bv, true);
                break;
 
        case LFUN_LEFTSEL:
-               if (!bv->selection().set())
-                       bv->resetAnchor();
+               if (!cur.selection())
+                       cur.resetAnchor();
                if (rtl())
-                       cursorRight(bv);
+                       cursorRight(true);
                else
-                       cursorLeft(bv);
+                       cursorLeft(true);
                finishChange(bv, true);
                break;
 
        case LFUN_UPSEL:
-               if (!bv->selection().set())
-                       bv->resetAnchor();
+               if (!cur.selection())
+                       cur.resetAnchor();
                cursorUp(true);
                finishChange(bv, true);
                break;
 
        case LFUN_DOWNSEL:
-               if (!bv->selection().set())
-                       bv->resetAnchor();
+               if (!cur.selection())
+                       cur.resetAnchor();
                cursorDown(true);
                finishChange(bv, true);
                break;
 
        case LFUN_UP_PARAGRAPHSEL:
-               if (!bv->selection().set())
-                       bv->resetAnchor();
+               if (!cur.selection())
+                       cur.resetAnchor();
                cursorUpParagraph();
                finishChange(bv, true);
                break;
 
        case LFUN_DOWN_PARAGRAPHSEL:
-               if (!bv->selection().set())
-                       bv->resetAnchor();
+               if (!cur.selection())
+                       cur.resetAnchor();
                cursorDownParagraph();
                finishChange(bv, true);
                break;
 
        case LFUN_PRIORSEL:
-               if (!bv->selection().set())
-                       bv->resetAnchor();
+               if (!cur.selection())
+                       cur.resetAnchor();
                cursorPrevious();
                finishChange(bv, true);
                break;
 
        case LFUN_NEXTSEL:
-               if (!bv->selection().set())
-                       bv->resetAnchor();
+               if (!cur.selection())
+                       cur.resetAnchor();
                cursorNext();
                finishChange(bv, true);
                break;
 
        case LFUN_HOMESEL:
-               if (!bv->selection().set())
-                       bv->resetAnchor();
+               if (!cur.selection())
+                       cur.resetAnchor();
                cursorHome();
                finishChange(bv, true);
                break;
 
        case LFUN_ENDSEL:
-               if (!bv->selection().set())
-                       bv->resetAnchor();
+               if (!cur.selection())
+                       cur.resetAnchor();
                cursorEnd();
                finishChange(bv, true);
                break;
 
        case LFUN_WORDRIGHTSEL:
-               if (!bv->selection().set())
-                       bv->resetAnchor();
+               if (!cur.selection())
+                       cur.resetAnchor();
                if (rtl())
                        cursorLeftOneWord();
                else
@@ -621,8 +622,8 @@ DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
                break;
 
        case LFUN_WORDLEFTSEL:
-               if (!bv->selection().set())
-                       bv->resetAnchor();
+               if (!cur.selection())
+                       cur.resetAnchor();
                if (rtl())
                        cursorRightOneWord();
                else
@@ -653,22 +654,22 @@ DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
                return moveDown();
 
        case LFUN_UP_PARAGRAPH:
-               if (!bv->selection().mark())
-                       bv->clearSelection();
+               if (!cur.mark())
+                       cur.clearSelection();
                cursorUpParagraph();
                finishChange(bv);
                break;
 
        case LFUN_DOWN_PARAGRAPH:
-               if (!bv->selection().mark())
-                       bv->clearSelection();
+               if (!cur.mark())
+                       cur.clearSelection();
                cursorDownParagraph();
                finishChange(bv, false);
                break;
 
        case LFUN_PRIOR:
-               if (!bv->selection().mark())
-                       bv->clearSelection();
+               if (!cur.mark())
+                       cur.clearSelection();
                finishChange(bv, false);
                if (cursorPar() == firstPar() && cursorRow() == firstRow())
                        return DispatchResult(false, FINISHED_UP);
@@ -676,8 +677,8 @@ DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
                break;
 
        case LFUN_NEXT:
-               if (!bv->selection().mark())
-                       bv->clearSelection();
+               if (!cur.mark())
+                       cur.clearSelection();
                finishChange(bv, false);
                if (cursorPar() == lastPar() && cursorRow() == lastRow())
                        return DispatchResult(false, FINISHED_DOWN);
@@ -685,15 +686,15 @@ DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
                break;
 
        case LFUN_HOME:
-               if (!bv->selection().mark())
-                       bv->clearSelection();
+               if (!cur.mark())
+                       cur.clearSelection();
                cursorHome();
                finishChange(bv, false);
                break;
 
        case LFUN_END:
-               if (!bv->selection().mark())
-                       bv->clearSelection();
+               if (!cur.mark())
+                       cur.clearSelection();
                cursorEnd();
                finishChange(bv, false);
                break;
@@ -707,34 +708,34 @@ DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
 
                replaceSelection(bv->getLyXText());
                insertInset(new InsetNewline);
-               moveCursor(bv, false);
+               moveCursor(cur, false);
                break;
        }
 
        case LFUN_DELETE:
-               if (!bv->selection().set()) {
+               if (!cur.selection()) {
                        Delete();
-                       bv->resetAnchor();
+                       cur.resetAnchor();
                        // It is possible to make it a lot faster still
                        // just comment out the line below...
                } else {
                        cutSelection(true, false);
                }
-               moveCursor(bv, false);
+               moveCursor(cur, false);
                bv->owner()->view_state_changed();
                break;
 
        case LFUN_DELETE_SKIP:
                // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
-               if (!bv->selection().set()) {
+               if (!cur.selection()) {
                        if (cursor().pos() == cursorPar()->size()) {
                                cursorRight(bv);
                                cursorLeft(bv);
                                Delete();
-                               bv->resetAnchor();
+                               cur.resetAnchor();
                        } else {
                                Delete();
-                               bv->resetAnchor();
+                               cur.resetAnchor();
                        }
                } else {
                        cutSelection(true, false);
@@ -744,10 +745,10 @@ DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
 
 
        case LFUN_BACKSPACE:
-               if (!bv->selection().set()) {
+               if (!cur.selection()) {
                        if (bv->owner()->getIntl().getTransManager().backspace()) {
                                backspace();
-                               bv->resetAnchor();
+                               cur.resetAnchor();
                                // It is possible to make it a lot faster still
                                // just comment out the line below...
                        }
@@ -761,7 +762,7 @@ DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
 
        case LFUN_BACKSPACE_SKIP:
                // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
-               if (!bv->selection().set()) {
+               if (!cur.selection()) {
                        CursorSlice cur = cursor();
                        backspace();
                        anchor() = cur;
@@ -775,7 +776,7 @@ DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
                replaceSelection(bv->getLyXText());
                breakParagraph(bv->buffer()->paragraphs(), 0);
                bv->update();
-               bv->resetAnchor();
+               cur.resetAnchor();
                bv->switchKeyMap();
                bv->owner()->view_state_changed();
                break;
@@ -784,7 +785,7 @@ DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
                replaceSelection(bv->getLyXText());
                breakParagraph(bv->buffer()->paragraphs(), 1);
                bv->update();
-               bv->resetAnchor();
+               cur.resetAnchor();
                bv->switchKeyMap();
                bv->owner()->view_state_changed();
                break;
@@ -856,13 +857,10 @@ DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
        case LFUN_INSET_APPLY: {
                string const name = cmd.getArg(0);
                InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
-               if (inset) {
-                       FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument);
-                       inset->dispatch(*bv, fr);
-               } else {
-                       FuncRequest fr(LFUN_INSET_INSERT, cmd.argument);
-                       dispatch(*bv, fr);
-               }
+               if (inset)
+                       inset->dispatch(cur, FuncRequest(LFUN_INSET_MODIFY, cmd.argument));
+               else
+                       dispatch(cur, FuncRequest(LFUN_INSET_INSERT, cmd.argument));
                break;
        }
 
@@ -874,11 +872,12 @@ DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
        }
 
        case LFUN_INSET_SETTINGS:
-               bv->fullCursor().innerInset()->showInsetDialog(bv);
+               if (cur.inset() && cur.inset()->asUpdatableInset())
+                       cur.inset()->asUpdatableInset()->showInsetDialog(bv);
                break;
 
        case LFUN_INSET_TOGGLE:
-               bv->clearSelection();
+               cur.clearSelection();
                if (!toggleInset())
                        return DispatchResult(false);
                bv->update();
@@ -890,7 +889,7 @@ DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
                        insertChar(' ');
                else
                        doInsertInset(bv, cmd, false, false);
-               moveCursor(bv, false);
+               moveCursor(cur, false);
                break;
 
        case LFUN_HYPHENATION:
@@ -942,7 +941,7 @@ DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
                        pasteSelection(strToUnsignedInt(cmd.argument));
                else
                        pasteSelection(0);
-               bv->clearSelection(); // bug 393
+               cur.clearSelection(); // bug 393
                bv->update();
                bv->switchKeyMap();
                finishUndo();
@@ -962,8 +961,8 @@ DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
        case LFUN_BEGINNINGBUFSEL:
                if (in_inset_)
                        return DispatchResult(false);
-               if (!bv->selection().set())
-                       bv->resetAnchor();
+               if (!cur.selection())
+                       cur.resetAnchor();
                cursorTop();
                finishChange(bv, true);
                break;
@@ -971,8 +970,8 @@ DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
        case LFUN_ENDBUFSEL:
                if (in_inset_)
                        return DispatchResult(false);
-               if (!bv->selection().set())
-                       bv->resetAnchor();
+               if (!cur.selection())
+                       cur.resetAnchor();
                cursorBottom();
                finishChange(bv, true);
                break;
@@ -1042,11 +1041,11 @@ DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
 
                bool change_layout = (current_layout != layout);
 
-               if (!change_layout && bv->selection().set() &&
-                       bv->selStart().par() != bv->selEnd().par())
+               if (!change_layout && cur.selection() &&
+                       cur.selStart().par() != cur.selEnd().par())
                {
-                       ParagraphList::iterator spit = getPar(bv->selStart());
-                       ParagraphList::iterator epit = boost::next(getPar(bv->selEnd()));
+                       ParagraphList::iterator spit = getPar(cur.selStart());
+                       ParagraphList::iterator epit = boost::next(getPar(cur.selEnd()));
                        while (spit != epit) {
                                if (spit->layout()->name() != current_layout) {
                                        change_layout = true;
@@ -1067,7 +1066,7 @@ DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
        }
 
        case LFUN_PASTESELECTION: {
-               bv->clearSelection();
+               cur.clearSelection();
                string const clip = bv->getClipboard();
                if (!clip.empty()) {
                        if (cmd.argument == "paragraph")
@@ -1134,31 +1133,27 @@ DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
                for (int i = 0; i < datetmp_len; i++)
                        insertChar(datetmp[i]);
 
-               bv->resetAnchor();
-               moveCursor(bv, false);
+               cur.resetAnchor();
+               moveCursor(cur, false);
                break;
        }
 
        case LFUN_MOUSE_TRIPLE:
-               if (!bv->buffer())
-                       break;
-               if (cmd.button() == mouse_button::button1) {
+               if (bv->buffer() && cmd.button() == mouse_button::button1) {
                        selection_possible = true;
                        cursorHome();
-                       bv->resetAnchor();
+                       cur.resetAnchor();
                        cursorEnd();
-                       bv->setSelection();
-                       bv->haveSelection(bv->selection().set());
+                       cur.setSelection();
+                       bv->haveSelection(cur.selection());
                }
                break;
 
        case LFUN_MOUSE_DOUBLE:
-               if (!bv->buffer())
-                       break;
-               if (cmd.button() == mouse_button::button1) {
+               if (bv->buffer() && cmd.button() == mouse_button::button1) {
                        selection_possible = true;
                        selectWord(lyx::WHOLE_WORD_STRICT);
-                       bv->haveSelection(bv->selection().set());
+                       bv->haveSelection(cur.selection());
                }
                break;
 
@@ -1189,7 +1184,7 @@ DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
                        else if (cmd.y - bv->top_y() < 0)
                                cursorUp(true);
                }
-               bv->setSelection();
+               cur.setSelection();
                break;
        }
 
@@ -1216,7 +1211,7 @@ DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
                // it could get cleared on the unlocking of the inset so
                // we have to check this first
                bool paste_internally = false;
-               if (cmd.button() == mouse_button::button2 && bv->selection().set()) {
+               if (cmd.button() == mouse_button::button2 && cur.selection()) {
                        bv->owner()->dispatch(FuncRequest(LFUN_COPY));
                        paste_internally = true;
                }
@@ -1224,7 +1219,7 @@ DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
                selection_possible = true;
 
                // Clear the selection
-               bv->clearSelection();
+               cur.clearSelection();
 
                // Right click on a footnote flag opens float menu
                if (cmd.button() == mouse_button::button3) {
@@ -1233,9 +1228,9 @@ DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
                }
 
                setCursorFromCoordinates(cmd.x, cmd.y);
-               bv->resetAnchor();
+               cur.resetAnchor();
                finishUndo();
-               bv->x_target(cursorX() + xo_);
+               cur.x_target(cursorX() + xo_);
 
                if (bv->fitCursor())
                        selection_possible = false;
@@ -1269,7 +1264,7 @@ DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
 
                // finish selection
                if (cmd.button() == mouse_button::button1)
-                       bv->haveSelection(bv->selection().set());
+                       bv->haveSelection(cur.selection());
 
                bv->switchKeyMap();
                bv->owner()->view_state_changed();
@@ -1289,12 +1284,12 @@ DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
                // true (on).
 
                if (lyxrc.auto_region_delete) {
-                       if (bv->selection().set())
+                       if (cur.selection())
                                cutSelection(false, false);
                        bv->haveSelection(false);
                }
 
-               bv->clearSelection();
+               cur.clearSelection();
                LyXFont const old_font = real_current_font;
 
                string::const_iterator cit = cmd.argument.begin();
@@ -1303,8 +1298,8 @@ DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
                        bv->owner()->getIntl().getTransManager().
                                TranslateAndInsert(*cit, this);
 
-               bv->resetAnchor();
-               moveCursor(bv, false);
+               cur.resetAnchor();
+               moveCursor(cur, false);
 
                // real_current_font.number can change so we need to
                // update the minibuffer
@@ -1397,7 +1392,7 @@ DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
        case LFUN_MATH_NUMBER:
        case LFUN_MATH_EXTERN:
        case LFUN_MATH_SIZE:
-               mathDispatch(*bv, cmd);
+               mathDispatch(cur, cmd);
                break;
 
        case LFUN_EMPH:
@@ -1462,7 +1457,7 @@ DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
        case LFUN_FINISHED_LEFT:
                lyxerr << "swallow LFUN_FINISHED_LEFT" << endl;
                if (rtl())
-                       cursorRight(true);
+                       cursorLeft(true);
                break;
 
        case LFUN_FINISHED_RIGHT:
index 2d47d2f51a3e541454db162a2627ae9b1092b6ba..d165adf73486ea502cabbd1cb520ad3f4af2f768 100644 (file)
@@ -17,7 +17,7 @@
 #include "undo.h"
 
 #include "buffer.h"
-#include "cursor_slice.h"
+#include "cursor.h"
 #include "debug.h"
 #include "BufferView.h"
 #include "iterators.h"
@@ -179,12 +179,13 @@ bool performUndoOrRedo(BufferView * bv, Undo const & undo)
               << std::endl;
 
        // set cursor again to force the position to be the right one
-       bv->cursor().par(undo.cursor_par);
-       bv->cursor().pos(undo.cursor_pos);
+       LCursor & cur = bv->cursor();
+       cur.par() = undo.cursor_par;
+       cur.pos() = undo.cursor_pos;
 
        // clear any selection
-       bv->clearSelection();
-       bv->resetAnchor();
+       cur.clearSelection();
+       cur.resetAnchor();
        text->updateCounters();
 
        // rebreak the entire lyxtext
@@ -293,11 +294,11 @@ void recordUndo(Undo::undo_kind kind, LyXText const * text, paroffset_type par)
 
 void recordUndo(BufferView * bv, Undo::undo_kind kind)
 {
-       recordUndo(*bv, kind);
+       recordUndo(bv->cursor(), kind);
 }
 
 
-void recordUndo(BufferView & bv, Undo::undo_kind kind)
+void recordUndo(LCursor & cur, Undo::undo_kind kind)
 {
-       recordUndo(kind, bv.text(), bv.text()->cursor().par());
+       recordUndo(kind, cur.bv().text(), cur.bv().text()->cursor().par());
 }
index a45e97bff56493e78e23b73a3ab3903e14467a31..925d87d20bd2f64f2c15a0208c5a643a91dab4fb 100644 (file)
@@ -19,6 +19,7 @@
 #include "ParagraphList_fwd.h"
 #include "support/types.h"
 
+class LCursor;
 class LyXText;
 class BufferView;
 
@@ -110,7 +111,7 @@ void recordUndo(Undo::undo_kind kind,
 
 /// convienience: prepare undo for the paragraph that contains the cursor
 void recordUndo(BufferView *, Undo::undo_kind kind);
-void recordUndo(BufferView &, Undo::undo_kind kind);
+void recordUndo(LCursor &, Undo::undo_kind kind);
 
 /// are we avoiding tracking undos currently?
 extern bool undo_frozen;