]> git.lyx.org Git - features.git/commitdiff
more IU
authorAndré Pönitz <poenitz@gmx.net>
Mon, 26 Jan 2004 10:13:15 +0000 (10:13 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Mon, 26 Jan 2004 10:13:15 +0000 (10:13 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8371 a592a061-630c-0410-9148-cb99ea01b6c8

74 files changed:
src/BufferView.C
src/BufferView.h
src/BufferView_pimpl.C
src/BufferView_pimpl.h
src/ChangeLog
src/InsetList.C
src/InsetList.h
src/PosIterator.C
src/PosIterator.h
src/buffer.h
src/bufferview_funcs.C
src/cursor.C
src/cursor.h
src/cursor_slice.h
src/factory.C
src/factory.h
src/frontends/LyXView.C
src/insets/inset.C
src/insets/inset.h
src/insets/insetbase.C
src/insets/insetbase.h
src/insets/insetcollapsable.h
src/insets/insetert.h
src/insets/insetref.C
src/insets/insettabular.C
src/insets/insettabular.h
src/iterators.C
src/iterators.h
src/lyxfind.C
src/lyxfunc.C
src/lyxtext.h
src/mathed/Makefile.am
src/mathed/formula.C
src/mathed/formula.h
src/mathed/formulamacro.C
src/mathed/formulamacro.h
src/mathed/math_colorinset.C
src/mathed/math_data.C
src/mathed/math_fracbase.C
src/mathed/math_fracbase.h
src/mathed/math_gridinset.C
src/mathed/math_gridinset.h
src/mathed/math_hullinset.C
src/mathed/math_hullinset.h
src/mathed/math_inset.C
src/mathed/math_inset.h
src/mathed/math_macro.C
src/mathed/math_macro.h
src/mathed/math_nestinset.C
src/mathed/math_nestinset.h
src/mathed/math_rootinset.C
src/mathed/math_rootinset.h
src/mathed/math_scriptinset.C
src/mathed/math_scriptinset.h
src/mathed/math_textinset.C
src/mathed/math_textinset.h
src/mathed/math_undersetinset.C
src/mathed/math_undersetinset.h
src/output_docbook.C
src/output_latex.C
src/output_linuxdoc.C
src/output_plaintext.C
src/paragraph.C
src/paragraph.h
src/paragraph_funcs.C
src/paragraph_funcs.h
src/paragraph_pimpl.C
src/paragraph_pimpl.h
src/rowpainter.C
src/tabular.C
src/tabular.h
src/text.C
src/text2.C
src/text3.C

index ef6194388fe4891b9d38cfc6e11881667a14caf5..58d13607621a5d9c3fde024928cedd9a15db6330 100644 (file)
@@ -299,7 +299,7 @@ void BufferView::setCursorFromRow(int row)
 }
 
 
 }
 
 
-bool BufferView::insertInset(InsetOld * inset, string const & lout)
+bool BufferView::insertInset(InsetBase * inset, string const & lout)
 {
        return pimpl_->insertInset(inset, lout);
 }
 {
        return pimpl_->insertInset(inset, lout);
 }
@@ -410,10 +410,10 @@ Encoding const * BufferView::getEncoding() const
        LyXText * t = getLyXText();
        if (!t)
                return 0;
        LyXText * t = getLyXText();
        if (!t)
                return 0;
-       return t->cursorPar()->getFont(
-               buffer()->params(),
-               t->cursor().pos(),
-               outerFont(t->cursorPar(), t->paragraphs())
+       CursorSlice const & cur = cursor().innerTextSlice();
+       return t->getPar(cur.par())->getFont(
+               buffer()->params(), cur.pos(),
+               outerFont(t->getPar(cur.par()), t->paragraphs())
        ).language()->encoding();
 }
 
        ).language()->encoding();
 }
 
@@ -448,7 +448,7 @@ LyXText * BufferView::text() const
 if the fitCursor call refers to some point in never-explored-land, then we
 don't have y information in insets there, then we cannot even do an update
 to get it (because we need the y infomation for setting top_y first). So
 if the fitCursor call refers to some point in never-explored-land, then we
 don't have y information in insets there, then we cannot even do an update
 to get it (because we need the y infomation for setting top_y first). So
-this is solved in put_selection_at with:
+this is solved in putSelectionAt with:
 
 - setting top_y to the y of the outerPar (that has good info)
 - calling update
 
 - setting top_y to the y of the outerPar (that has good info)
 - calling update
index eeae02b2451048806185c2bb6dd5f416e6670e8f..d6beddec1a0e1b6e805c808811643a433d7597b4 100644 (file)
@@ -24,6 +24,7 @@ class Change;
 class Encoding;
 class ErrorList;
 class FuncRequest;
 class Encoding;
 class ErrorList;
 class FuncRequest;
+class InsetBase;
 class InsetOld;
 class Language;
 class LCursor;
 class InsetOld;
 class Language;
 class LCursor;
@@ -140,7 +141,7 @@ public:
         * Insert an inset into the buffer.
         * Place it in a layout of lout,
         */
         * Insert an inset into the buffer.
         * Place it in a layout of lout,
         */
-       bool insertInset(InsetOld * inset, std::string const & lout = std::string());
+       bool insertInset(InsetBase * inset, std::string const & lout = std::string());
 
        /// Inserts a lyx file at cursor position. return false if it fails
        bool insertLyXFile(std::string const & file);
 
        /// Inserts a lyx file at cursor position. return false if it fails
        bool insertLyXFile(std::string const & file);
index a6db146074e208901149c6ce67e2e3ea341febb0..73c3f7d7abdd5c844294c43ccb672c6f9f8b4409 100644 (file)
@@ -59,7 +59,7 @@
 
 #include "graphics/Previews.h"
 
 
 #include "graphics/Previews.h"
 
-#include "mathed/formulabase.h"
+#include "mathed/math_hullinset.h"
 
 #include "support/filetools.h"
 #include "support/globbing.h"
 
 #include "support/filetools.h"
 #include "support/globbing.h"
@@ -302,6 +302,9 @@ void BufferView::Pimpl::buffer(Buffer * b)
                //bv_->setText(0);
        }
 
                //bv_->setText(0);
        }
 
+       // reset old cursor
+       cursor_.reset();
+
        // set current buffer
        buffer_ = b;
 
        // set current buffer
        buffer_ = b;
 
@@ -403,8 +406,8 @@ void BufferView::Pimpl::resizeCurrentBuffer()
        LCursor & cur = bv_->cursor();
        par = cur.par();
        pos = cur.pos();
        LCursor & cur = bv_->cursor();
        par = cur.par();
        pos = cur.pos();
-       selstartpar = cur.selStart().par();
-       selstartpos = cur.selStart().pos();
+       selstartpar = cur.selBegin().par();
+       selstartpos = cur.selBegin().pos();
        selendpar = cur.selEnd().par();
        selendpos = cur.selEnd().pos();
        sel = cur.selection();
        selendpar = cur.selEnd().par();
        selendpos = cur.selEnd().pos();
        sel = cur.selection();
@@ -646,8 +649,8 @@ Change const BufferView::Pimpl::getCurrentChange()
        if (!cur.selection())
                return Change(Change::UNCHANGED);
 
        if (!cur.selection())
                return Change(Change::UNCHANGED);
 
-       return text->getPar(cur.selStart())
-               ->lookupChangeFull(cur.selStart().pos());
+       return text->getPar(cur.selBegin())
+               ->lookupChangeFull(cur.selBegin().pos());
 }
 
 
 }
 
 
@@ -745,7 +748,7 @@ void BufferView::Pimpl::stuffClipboard(string const & stuff) const
 }
 
 
 }
 
 
-InsetOld * BufferView::Pimpl::getInsetByCode(InsetOld::Code code)
+InsetBase * BufferView::Pimpl::getInsetByCode(InsetBase::Code code)
 {
 #if 0
        CursorSlice cursor = bv_->getLyXText()->cursor;
 {
 #if 0
        CursorSlice cursor = bv_->getLyXText()->cursor;
@@ -885,14 +888,16 @@ CursorBase theTempCursor;
 
 namespace {
 
 
 namespace {
 
-       InsetOld * insetFromCoords(BufferView * bv, int x, int y)
+       InsetBase * insetFromCoords(BufferView * bv, int x, int y)
        {
                lyxerr << "insetFromCoords" << endl;
        {
                lyxerr << "insetFromCoords" << endl;
-               LyXText * text = bv->text();
-               InsetOld * inset = 0;
+               InsetBase * inset = 0;
                theTempCursor.clear();
                theTempCursor.clear();
+               LyXText * text = bv->text();
+#warning FIXME
+#if 0
                while (true) {
                while (true) {
-                       InsetOld * const inset_hit = text->checkInsetHit(x, y);
+                       InsetBase * const inset_hit = text->checkInsetHit(x, y);
                        if (!inset_hit) {
                                lyxerr << "no further inset hit" << endl;
                                break;
                        if (!inset_hit) {
                                lyxerr << "no further inset hit" << endl;
                                break;
@@ -910,6 +915,7 @@ namespace {
                                << " text: " << text << " y: " << y << endl;
                        theTempCursor.push_back(CursorSlice(inset));
                }
                                << " text: " << text << " y: " << y << endl;
                        theTempCursor.push_back(CursorSlice(inset));
                }
+#endif
                //lyxerr << "theTempCursor: " << theTempCursor << endl;
                return inset;
        }
                //lyxerr << "theTempCursor: " << theTempCursor << endl;
                return inset;
        }
@@ -964,7 +970,7 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd)
                // handle this event.
 
                // built temporary path to inset
                // handle this event.
 
                // built temporary path to inset
-               InsetOld * inset = insetFromCoords(bv_, cmd.x, cmd.y);
+               InsetBase * inset = insetFromCoords(bv_, cmd.x, cmd.y);
                DispatchResult res;
 
                // try to dispatch to that inset
                DispatchResult res;
 
                // try to dispatch to that inset
@@ -1097,7 +1103,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
                string label = ev.argument;
                if (label.empty()) {
                        InsetRef * inset =
                string label = ev.argument;
                if (label.empty()) {
                        InsetRef * inset =
-                               static_cast<InsetRef*>(getInsetByCode(InsetOld::REF_CODE));
+                               static_cast<InsetRef*>(getInsetByCode(InsetBase::REF_CODE));
                        if (inset) {
                                label = inset->getContents();
                                savePosition(0);
                        if (inset) {
                                label = inset->getContents();
                                savePosition(0);
@@ -1152,7 +1158,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
        case LFUN_INSET_INSERT: {
                // Same as above.
                BOOST_ASSERT(false);
        case LFUN_INSET_INSERT: {
                // Same as above.
                BOOST_ASSERT(false);
-               InsetOld * inset = createInset(bv_, ev);
+               InsetBase * inset = createInset(bv_, ev);
                if (!inset || !insertInset(inset))
                        delete inset;
                break;
                if (!inset || !insertInset(inset))
                        delete inset;
                break;
@@ -1160,7 +1166,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
 
        case LFUN_FLOAT_LIST:
                if (tclass.floats().typeExist(ev.argument)) {
 
        case LFUN_FLOAT_LIST:
                if (tclass.floats().typeExist(ev.argument)) {
-                       InsetOld * inset = new InsetFloatList(ev.argument);
+                       InsetBase * inset = new InsetFloatList(ev.argument);
                        if (!insertInset(inset, tclass.defaultLayoutName()))
                                delete inset;
                } else {
                        if (!insertInset(inset, tclass.defaultLayoutName()))
                                delete inset;
                } else {
@@ -1290,7 +1296,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
 }
 
 
 }
 
 
-bool BufferView::Pimpl::insertInset(InsetOld * inset, string const & lout)
+bool BufferView::Pimpl::insertInset(InsetBase * inset, string const & lout)
 {
        // not quite sure if we want this...
        bv_->text()->recUndo(bv_->text()->cursor().par());
 {
        // not quite sure if we want this...
        bv_->text()->recUndo(bv_->text()->cursor().par());
@@ -1318,7 +1324,7 @@ bool BufferView::Pimpl::insertInset(InsetOld * inset, string const & lout)
 }
 
 
 }
 
 
-bool BufferView::Pimpl::ChangeInsets(InsetOld::Code code,
+bool BufferView::Pimpl::ChangeInsets(InsetBase::Code code,
                                     string const & from, string const & to)
 {
        bool need_update = false;
                                     string const & from, string const & to)
 {
        bool need_update = false;
@@ -1360,12 +1366,14 @@ void BufferView::Pimpl::updateParagraphDialog()
 {
        if (!bv_->owner()->getDialogs().visible("paragraph"))
                return;
 {
        if (!bv_->owner()->getDialogs().visible("paragraph"))
                return;
-       Paragraph const & par = *bv_->getLyXText()->cursorPar();
+       CursorSlice const & cur = bv_->cursor().innerTextSlice();
+       LyXText * text = bv_->cursor().innerText();
+       Paragraph const & par = *text->getPar(cur.par());
        string data;
        params2string(par, data);
 
        // Will the paragraph accept changes from the dialog?
        string data;
        params2string(par, data);
 
        // Will the paragraph accept changes from the dialog?
-       InsetOld * const inset = par.inInset();
+       InsetBase * const inset = cur.inset();
        bool const accept =
                !(inset && inset->forceDefaultParagraphs(inset));
 
        bool const accept =
                !(inset && inset->forceDefaultParagraphs(inset));
 
index 789b75fc023d4805d5322785f657b3362941a4a4..9880aabe7b36e701fa8633bb6f34e018c88596e9 100644 (file)
@@ -102,7 +102,7 @@ struct BufferView::Pimpl : public boost::signals::trackable {
        ///
        void center();
        ///
        ///
        void center();
        ///
-       bool insertInset(InsetOld * inset, std::string const & lout = std::string());
+       bool insertInset(InsetBase * inset, std::string const & lout = std::string());
        /// a function should be executed from the workarea
        bool workAreaDispatch(FuncRequest const & ev);
        /// a function should be executed
        /// a function should be executed from the workarea
        bool workAreaDispatch(FuncRequest const & ev);
        /// a function should be executed
@@ -148,7 +148,7 @@ private:
         * string. May only be used with InsetCommand-derived insets
         * Returns true if a screen update is needed.
         */
         * string. May only be used with InsetCommand-derived insets
         * Returns true if a screen update is needed.
         */
-       bool ChangeInsets(InsetOld::Code code, std::string const & from,
+       bool ChangeInsets(InsetBase::Code code, std::string const & from,
                          std::string const & to);
 
        ///
                          std::string const & to);
 
        ///
@@ -187,7 +187,7 @@ private:
        ///
        std::vector<Position> saved_positions;
        /// Get next inset of this class from current cursor position
        ///
        std::vector<Position> saved_positions;
        /// Get next inset of this class from current cursor position
-       InsetOld * getInsetByCode(InsetOld::Code code);
+       InsetBase * getInsetByCode(InsetBase::Code code);
        ///
        void MenuInsertLyXFile(std::string const & filen);
        /// our workarea
        ///
        void MenuInsertLyXFile(std::string const & filen);
        /// our workarea
index 640a1aeb942e84b2152a67e1aa589708d0ee3300..6a8d627ad5ed8b0e4d137d6f9d7dbe7172c74e0d 100644 (file)
@@ -1,3 +1,35 @@
+
+
+2004-01-26  André Pönitz  <poenitz@gmx.net>
+
+       * BufferView.[Ch]:
+       * BufferView_pimpl.[Ch]:
+       * InsetList.[Ch]:
+       * PosIterator.[Ch]:
+       * buffer.h:
+       * bufferview_funcs.C:
+       * cursor.[Ch]:
+       * cursor_slice.h:
+       * factory.[Ch]:
+       * iterators.[Ch]:
+       * lyxfind.C:
+       * lyxfunc.C:
+       * lyxtext.h:
+       * output_docbook.C:
+       * output_latex.C:
+       * output_linuxdoc.C:
+       * output_plaintext.C:
+       * paragraph.[Ch]:
+       * paragraph_funcs.[Ch]:
+       * paragraph_pimpl.[Ch]:
+       * rowpainter.C:
+       * tabular.C:
+       * tabular.h:
+       * text.C:
+       * text2.C:
+       * text3.C: more IU:  dumps most of the rest of the mathcursor
+    implementation into cursor.[Ch]; "globalize" a bit of it.
+
 2004-01-25  Angus Leeming  <leeming@lyx.org>
 
        * lyxfunc.C (dispatch): Dialogs::showSearch is no more.
 2004-01-25  Angus Leeming  <leeming@lyx.org>
 
        * lyxfunc.C (dispatch): Dialogs::showSearch is no more.
index db74a08e816f54e0f02796eaaf45a14470091d88..d9d90d5591d2a2852729d633f8ed4c2461de2939 100644 (file)
@@ -26,12 +26,13 @@ using lyx::pos_type;
 using std::endl;
 using std::lower_bound;
 
 using std::endl;
 using std::lower_bound;
 
+
 namespace {
 
 namespace {
 
-class InsetTablePosLess : public std::binary_function<InsetList::InsetTable, InsetList::InsetTable, bool> {
-public:
-       bool operator()(InsetList::InsetTable const & t1,
-                     InsetList::InsetTable const & t2) const
+typedef InsetList::InsetTable Table;
+
+struct InsetTablePosLess : public std::binary_function<Table, Table, bool> {
+       bool operator()(Table const & t1, Table const & t2) const
        {
                return t1.pos < t2.pos;
        }
        {
                return t1.pos < t2.pos;
        }
@@ -39,6 +40,8 @@ public:
 
 } // namespace anon
 
 
 } // namespace anon
 
+
+
 InsetList::~InsetList()
 {
        // If we begin storing a shared_ptr in the List
 InsetList::~InsetList()
 {
        // If we begin storing a shared_ptr in the List
@@ -67,7 +70,7 @@ InsetList::const_iterator InsetList::insetIterator(pos_type pos) const
 }
 
 
 }
 
 
-void InsetList::insert(InsetOld * inset, lyx::pos_type pos)
+void InsetList::insert(InsetBase * inset, lyx::pos_type pos)
 {
        List::iterator end = list.end();
        List::iterator it = insetIterator(pos);
 {
        List::iterator end = list.end();
        List::iterator it = insetIterator(pos);
@@ -91,12 +94,12 @@ void InsetList::erase(pos_type pos)
 }
 
 
 }
 
 
-InsetOld * InsetList::release(pos_type pos)
+InsetBase * InsetList::release(pos_type pos)
 {
        List::iterator end = list.end();
        List::iterator it = insetIterator(pos);
        if (it != end && it->pos == pos) {
 {
        List::iterator end = list.end();
        List::iterator it = insetIterator(pos);
        if (it != end && it->pos == pos) {
-               InsetOld * tmp = it->inset;
+               InsetBase * tmp = it->inset;
                it->inset = 0;
                return tmp;
        }
                it->inset = 0;
                return tmp;
        }
@@ -104,7 +107,7 @@ InsetOld * InsetList::release(pos_type pos)
 }
 
 
 }
 
 
-InsetOld * InsetList::get(pos_type pos) const
+InsetBase * InsetList::get(pos_type pos) const
 {
        List::const_iterator end = list.end();
        List::const_iterator it = insetIterator(pos);
 {
        List::const_iterator end = list.end();
        List::const_iterator it = insetIterator(pos);
@@ -139,8 +142,9 @@ void InsetList::insetsOpenCloseBranch(Buffer const & buf)
        List::iterator it = list.begin();
        List::iterator end = list.end();
        for (; it != end; ++it) {
        List::iterator it = list.begin();
        List::iterator end = list.end();
        for (; it != end; ++it) {
-               if (!it->inset ||
-                   it->inset->lyxCode() != InsetOld::BRANCH_CODE)
+               if (!it->inset)
+                       continue;
+               if (it->inset->lyxCode() != InsetBase::BRANCH_CODE)
                        continue;
 
                InsetBranch * inset = static_cast<InsetBranch *>(it->inset);
                        continue;
 
                InsetBranch * inset = static_cast<InsetBranch *>(it->inset);
index fc40e450889a960aaad1adaad98e13850aff4c66..5baa9087944364e98f0a2430dc9da0ce75acff1c 100644 (file)
@@ -16,7 +16,7 @@
 
 #include <vector>
 
 
 #include <vector>
 
-class InsetOld;
+class InsetBase;
 class Buffer;
 
 
 class Buffer;
 
 
@@ -28,9 +28,9 @@ public:
                ///
                lyx::pos_type pos;
                ///
                ///
                lyx::pos_type pos;
                ///
-               InsetOld * inset;
+               InsetBase * inset;
                ///
                ///
-               InsetTable(lyx::pos_type p, InsetOld * i) : pos(p), inset(i) {}
+               InsetTable(lyx::pos_type p, InsetBase * i) : pos(p), inset(i) {}
        };
        ///
        typedef std::vector<InsetTable> List;
        };
        ///
        typedef std::vector<InsetTable> List;
@@ -56,13 +56,13 @@ public:
        ///
        const_iterator insetIterator(lyx::pos_type pos) const;
        ///
        ///
        const_iterator insetIterator(lyx::pos_type pos) const;
        ///
-       void insert(InsetOld * inset, lyx::pos_type pos);
+       void insert(InsetBase * inset, lyx::pos_type pos);
        ///
        void erase(lyx::pos_type pos);
        ///
        ///
        void erase(lyx::pos_type pos);
        ///
-       InsetOld * release(lyx::pos_type);
+       InsetBase * release(lyx::pos_type);
        ///
        ///
-       InsetOld * get(lyx::pos_type pos) const;
+       InsetBase * get(lyx::pos_type pos) const;
        ///
        void increasePosAfterPos(lyx::pos_type pos);
        ///
        ///
        void increasePosAfterPos(lyx::pos_type pos);
        ///
index dcd6798f1053b9189e240a4a9168e2b184d143f3..d806e60dbfc30b17579c0433b2f4b7c56cb2bbdb 100644 (file)
@@ -35,7 +35,7 @@ PosIterator & PosIterator::operator++()
                PosIteratorItem & p = stack_.back();
                
                if (p.pos < p.pit->size()) {
                PosIteratorItem & p = stack_.back();
                
                if (p.pos < p.pit->size()) {
-                       if (InsetOld * inset = p.pit->getInset(p.pos)) {
+                       if (InsetBase * inset = p.pit->getInset(p.pos)) {
                                if (LyXText * text = inset->getText(p.index)) {
                                        ParagraphList & pl = text->paragraphs();
                                        p.index++;
                                if (LyXText * text = inset->getText(p.index)) {
                                        ParagraphList & pl = text->paragraphs();
                                        p.index++;
@@ -68,7 +68,7 @@ PosIterator & PosIterator::operator--()
        PosIteratorItem & p = stack_.back();
        if (p.pos > 0) {
                --p.pos;
        PosIteratorItem & p = stack_.back();
        if (p.pos > 0) {
                --p.pos;
-               InsetOld * inset = p.pit->getInset(p.pos);
+               InsetBase * inset = p.pit->getInset(p.pos);
                if (inset)
                        p.index = inset->numParagraphs();
        } else {
                if (inset)
                        p.index = inset->numParagraphs();
        } else {
@@ -85,7 +85,7 @@ PosIterator & PosIterator::operator--()
        // try to push an item if there is some left unexplored
        PosIteratorItem & q = stack_.back();
        if (q.pos < q.pit->size()) {
        // try to push an item if there is some left unexplored
        PosIteratorItem & q = stack_.back();
        if (q.pos < q.pit->size()) {
-               InsetOld * inset = q.pit->getInset(q.pos);
+               InsetBase * inset = q.pit->getInset(q.pos);
                if (inset && q.index > 0) {
                        LyXText * text = inset->getText(q.index - 1);
                        BOOST_ASSERT(text);
                if (inset && q.index > 0) {
                        LyXText * text = inset->getText(q.index - 1);
                        BOOST_ASSERT(text);
@@ -144,7 +144,7 @@ PosIterator::PosIterator(BufferView & bv)
 }
 
 
 }
 
 
-InsetOld * PosIterator::inset() const
+InsetBase * PosIterator::inset() const
 {
        if (stack_.size() == 1)
                return 0;
 {
        if (stack_.size() == 1)
                return 0;
@@ -155,9 +155,8 @@ InsetOld * PosIterator::inset() const
 
 int distance(PosIterator const & cur, PosIterator const & end)
 {
 
 int distance(PosIterator const & cur, PosIterator const & end)
 {
-       PosIterator p = cur;
        int count = 0;
        int count = 0;
-       for (; p != end; ++p, ++count)
+       for (PosIterator p = cur; p != end; ++p, ++count)
                ;
        return count;
 }
                ;
        return count;
 }
index 903a7ec2203f44f0acaa7921001492d20cbbd610..19449c1c0be6278e59c8c4747d34ca2091894fb7 100644 (file)
@@ -22,8 +22,7 @@
 
 class BufferView;
 
 
 class BufferView;
 
-struct PosIteratorItem 
-{
+struct PosIteratorItem {
        PosIteratorItem(ParagraphList * pl,
                        ParagraphList::iterator pit,
                        lyx::pos_type pos,
        PosIteratorItem(ParagraphList * pl,
                        ParagraphList::iterator pit,
                        lyx::pos_type pos,
@@ -36,8 +35,7 @@ struct PosIteratorItem
 };
 
 
 };
 
 
-class PosIterator
-{
+class PosIterator {
 public:
        PosIterator(BufferView & bv);
        PosIterator(ParIterator & par, lyx::pos_type pos);
 public:
        PosIterator(BufferView & bv);
        PosIterator(ParIterator & par, lyx::pos_type pos);
@@ -51,7 +49,7 @@ public:
        ParagraphList::iterator pit() const { return stack_.back().pit; }
        lyx::pos_type pos() const { return stack_.back().pos; }
        bool at_end() const;
        ParagraphList::iterator pit() const { return stack_.back().pit; }
        lyx::pos_type pos() const { return stack_.back().pos; }
        bool at_end() const;
-       InsetOld * inset() const;
+       InsetBase * inset() const;
        friend PosIterator ParIterator::asPosIterator(lyx::pos_type) const;
        friend ParIterator::ParIterator(PosIterator const &);
        
        friend PosIterator ParIterator::asPosIterator(lyx::pos_type) const;
        friend ParIterator::ParIterator(PosIterator const &);
        
@@ -61,6 +59,7 @@ private:
        std::vector<PosIteratorItem> stack_;
 };
 
        std::vector<PosIteratorItem> stack_;
 };
 
+
 bool operator!=(PosIterator const &, PosIterator const &);
 bool operator==(PosIterator const &, PosIterator const &);
 
 bool operator!=(PosIterator const &, PosIterator const &);
 bool operator==(PosIterator const &, PosIterator const &);
 
index f7c7d64999006cfcef9c99447b44bc95863d6ee9..431725bb378e8221346cf102014fc6a0e057839a 100644 (file)
 class BufferParams;
 class ErrorItem;
 class FuncRequest;
 class BufferParams;
 class ErrorItem;
 class FuncRequest;
+class InsetBase;
 class LyXFont;
 class LyXLex;
 class LyXRC;
 class LyXText;
 class LyXVC;
 class LaTeXFeatures;
 class LyXFont;
 class LyXLex;
 class LyXRC;
 class LyXText;
 class LyXVC;
 class LaTeXFeatures;
-class OutputParams;
 class Language;
 class Messages;
 class Language;
 class Messages;
+class OutputParams;
 class ParIterator;
 class PosIterator;
 class ParConstIterator;
 class ParIterator;
 class PosIterator;
 class ParConstIterator;
@@ -282,10 +283,10 @@ public:
        class inset_iterator {
        public:
                typedef std::input_iterator_tag iterator_category;
        class inset_iterator {
        public:
                typedef std::input_iterator_tag iterator_category;
-               typedef InsetOld value_type;
+               typedef InsetBase value_type;
                typedef ptrdiff_t difference_type;
                typedef ptrdiff_t difference_type;
-               typedef InsetOld * pointer;
-               typedef InsetOld & reference;
+               typedef InsetBase * pointer;
+               typedef InsetBase & reference;
                typedef ParagraphList::iterator base_type;
 
                ///
                typedef ParagraphList::iterator base_type;
 
                ///
index 2523b065c4458d7181d04026a51510b136b3bd71..634ed5f9c4342190530f8823a651a36c1778f67d 100644 (file)
 
 #include "insets/insettext.h"
 
 
 #include "insets/insettext.h"
 
-#include "mathed/math_cursor.h"
-
 #include "support/tostr.h"
 #include "support/tostr.h"
-
 #include "support/std_sstream.h"
 
 using lyx::support::bformat;
 #include "support/std_sstream.h"
 
 using lyx::support::bformat;
@@ -169,7 +166,7 @@ string const currentState(BufferView * bv)
        if (!bv->available())
                return string();
 
        if (!bv->available())
                return string();
 
-       if (inMathed()) {
+       if (bv->cursor().inMathed()) {
                bv->cursor().info(state);
                return state.str();
        }
                bv->cursor().info(state);
                return state.str();
        }
index bc541b4472eb5e1a2009f6c5ff5d33c610e85998..5eb17f6bf414b5db68a59d26f6acaf23a11935d4 100644 (file)
@@ -3,6 +3,8 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
+ * \author Alejandro Aguilar Sierra
+ * \author Alfredo Braunstein
  * \author André Pönitz
  *
  * Full author contact details are available in file CREDITS.
  * \author André Pönitz
  *
  * Full author contact details are available in file CREDITS.
 #include "funcrequest.h"
 #include "iterators.h"
 #include "lfuns.h"
 #include "funcrequest.h"
 #include "iterators.h"
 #include "lfuns.h"
+#include "lyxrc.h"
 #include "lyxtext.h"
 #include "lyxtext.h"
-#include "paragraph.h"
 #include "lyxrow.h"
 #include "lyxrow.h"
+#include "paragraph.h"
 
 #include "insets/updatableinset.h"
 #include "insets/insettabular.h"
 #include "insets/insettext.h"
 
 #include "mathed/math_data.h"
 
 #include "insets/updatableinset.h"
 #include "insets/insettabular.h"
 #include "insets/insettext.h"
 
 #include "mathed/math_data.h"
-#include "mathed/math_inset.h"
+#include "mathed/math_hullinset.h"
+#include "mathed/math_support.h"
+
+#include "support/limited_stack.h"
 
 #include <boost/assert.hpp>
 
 
 #include <boost/assert.hpp>
 
+using std::string;
 using std::vector;
 using std::endl;
 using std::vector;
 using std::endl;
+#ifndef CXX_GLOBAL_CSTD
+using std::isalpha;
+#endif
+using std::min;
+using std::swap;
+
+
+
+// our own cut buffer
+limited_stack<string> theCutBuffer;
 
 
 LCursor::LCursor(BufferView & bv)
 
 
 LCursor::LCursor(BufferView & bv)
@@ -42,6 +59,20 @@ LCursor::LCursor(BufferView & bv)
 {}
 
 
 {}
 
 
+void LCursor::reset()
+{
+       cursor_.clear();
+       anchor_.clear();
+       cursor_.push_back(CursorSlice());
+       anchor_.push_back(CursorSlice());
+       current_ = 0;
+       cached_y_ = 0;
+       x_target_ = -1;
+       selection_ = false;
+       mark_ = false;
+}
+
+
 DispatchResult LCursor::dispatch(FuncRequest const & cmd0)
 {
        lyxerr << "\nLCursor::dispatch: " << *this << endl;
 DispatchResult LCursor::dispatch(FuncRequest const & cmd0)
 {
        lyxerr << "\nLCursor::dispatch: " << *this << endl;
@@ -107,7 +138,7 @@ void LCursor::push(InsetBase * inset)
 void LCursor::pop(int depth)
 {
        lyxerr << "LCursor::pop() to depth " << depth << endl;
 void LCursor::pop(int depth)
 {
        lyxerr << "LCursor::pop() to depth " << depth << endl;
-       while (cursor_.size() > depth)
+       while (int(cursor_.size()) > depth)
                pop();
 }
 
                pop();
 }
 
@@ -127,6 +158,43 @@ void LCursor::pop()
 }
 
 
 }
 
 
+void LCursor::pushLeft(InsetBase * p)
+{
+       //lyxerr << "Entering inset " << t << " left" << endl;
+       push(p);
+       p->idxFirst(*this);
+}
+
+
+bool LCursor::popLeft()
+{
+       //lyxerr << "Leaving inset to the left" << endl;
+       if (depth() <= 1) {
+               if (depth() == 1)
+                       inset()->notifyCursorLeaves(idx());
+               return false;
+       }
+       inset()->notifyCursorLeaves(idx());
+       pop();
+       return true;
+}
+
+
+bool LCursor::popRight()
+{
+       //lyxerr << "Leaving inset to the right" << endl;
+       if (depth() <= 1) {
+               if (depth() == 1)
+                       inset()->notifyCursorLeaves(idx());
+               return false;
+       }
+       inset()->notifyCursorLeaves(idx());
+       pop();
+       posRight();
+       return true;
+}
+
+
 CursorSlice & LCursor::current()
 {
        //lyxerr << "accessing cursor slice " << current_
 CursorSlice & LCursor::current()
 {
        //lyxerr << "accessing cursor slice " << current_
@@ -143,12 +211,23 @@ CursorSlice const & LCursor::current() const
 }
 
 
 }
 
 
+int LCursor::currentMode()
+{
+       for (int i = cursor_.size() - 1; i >= 1; --i) {
+               int res = cursor_[i].inset()->currentMode();
+               if (res != MathInset::UNDECIDED_MODE)
+                       return res;
+       }
+       return MathInset::TEXT_MODE;
+}
+
+
 LyXText * LCursor::innerText() const
 {
        //lyxerr << "LCursor::innerText()  depth: " << cursor_.size() << endl;
        if (cursor_.size() > 1) {
                // go up until first non-0 text is hit
 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)
+               // (innermost text is 0 in mathed)
                for (int i = cursor_.size() - 1; i >= 1; --i)
                        if (cursor_[i].text())
                                return cursor_[i].text();
                for (int i = cursor_.size() - 1; i >= 1; --i)
                        if (cursor_[i].text())
                                return cursor_[i].text();
@@ -157,6 +236,20 @@ LyXText * LCursor::innerText() const
 }
 
 
 }
 
 
+CursorSlice const & LCursor::innerTextSlice() const
+{
+       //lyxerr << "LCursor::innerTextSlice()  depth: " << cursor_.size() << endl;
+       if (cursor_.size() > 1) {
+               // go up until first non-0 text is hit
+               // (innermost text is 0 in mathed)
+               for (int i = cursor_.size() - 1; i >= 1; --i)
+                       if (cursor_[i].text())
+                               return cursor_[i];
+       }
+       return cursor_[0];
+}
+
+
 void LCursor::updatePos()
 {
        if (cursor_.size() > 1)
 void LCursor::updatePos()
 {
        if (cursor_.size() > 1)
@@ -200,9 +293,7 @@ void LCursor::getPos(int & x, int & y) const
                        x += inset()->asUpdatableInset()->x();
                        y += cached_y_;
                } else if (inset()->asMathInset()) {
                        x += inset()->asUpdatableInset()->x();
                        y += cached_y_;
                } else if (inset()->asMathInset()) {
-#warning FIXME
-                       x = 100;
-                       y = 100;
+                       getScreenPos(x, y);
                } else {
                        // this should not happen
                        BOOST_ASSERT(false);
                } else {
                        // this should not happen
                        BOOST_ASSERT(false);
@@ -211,6 +302,12 @@ void LCursor::getPos(int & x, int & y) const
 }
 
 
 }
 
 
+void LCursor::paste(string const & data)
+{
+       dispatch(FuncRequest(LFUN_PASTE, data));
+}
+
+
 InsetBase * LCursor::innerInsetOfType(int code) const
 {
        for (int i = cursor_.size() - 1; i >= 1; --i)
 InsetBase * LCursor::innerInsetOfType(int code) const
 {
        for (int i = cursor_.size() - 1; i >= 1; --i)
@@ -296,7 +393,7 @@ CursorSlice const & LCursor::anchor() const
 }
 
 
 }
 
 
-CursorSlice const & LCursor::selStart() const
+CursorSlice const & LCursor::selBegin() const
 {
        if (!selection())
                return cursor_.back();
 {
        if (!selection())
                return cursor_.back();
@@ -305,19 +402,19 @@ CursorSlice const & LCursor::selStart() const
 }
 
 
 }
 
 
-CursorSlice const & LCursor::selEnd() const
+CursorSlice & LCursor::selBegin()
 {
        if (!selection())
                return cursor_.back();
 {
        if (!selection())
                return cursor_.back();
-       return anchor() > cursor_.back() ? anchor() : cursor_.back();
+       return anchor() < cursor_.back() ? anchor() : cursor_.back();
 }
 
 
 }
 
 
-CursorSlice & LCursor::selStart()
+CursorSlice const & LCursor::selEnd() const
 {
        if (!selection())
                return cursor_.back();
 {
        if (!selection())
                return cursor_.back();
-       return anchor() < cursor_.back() ? anchor() : cursor_.back();
+       return anchor() > cursor_.back() ? anchor() : cursor_.back();
 }
 
 
 }
 
 
@@ -338,6 +435,15 @@ void LCursor::setSelection()
 }
 
 
 }
 
 
+void LCursor::setSelection(CursorBase const & where, size_t n)
+{
+       selection() = true;
+       cursor_ = where;
+       anchor_ = where;
+       pos() += n;
+}
+
+
 void LCursor::clearSelection()
 {
        selection() = false;
 void LCursor::clearSelection()
 {
        selection() = false;
@@ -347,71 +453,6 @@ void LCursor::clearSelection()
 }
 
 
 }
 
 
-
-//
-// 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;
 void LCursor::x_target(int x)
 {
        x_target_ = x;
@@ -438,7 +479,11 @@ Paragraph const & LCursor::paragraph() const
 
 LCursor::pos_type LCursor::lastpos() const
 {
 
 LCursor::pos_type LCursor::lastpos() const
 {
-       return current_ ? current().lastpos() : bv_->text()->getPar(par())->size();
+       CursorSlice const & cur = current();
+       if (cur.inset() && cur.inset()->asMathInset())
+               return cell().size();
+       else
+               return paragraph().size();
 }
 
 
 }
 
 
@@ -505,6 +550,168 @@ void LCursor::info(std::ostream & os)
 }
 
 
 }
 
 
+namespace {
+
+void region(CursorSlice const & i1, CursorSlice const & i2,
+       LCursor::row_type & r1, LCursor::row_type & r2,
+       LCursor::col_type & c1, LCursor::col_type & c2)
+{
+       InsetBase * p = i1.inset();
+       c1 = p->col(i1.idx_);
+       c2 = p->col(i2.idx_);
+       if (c1 > c2)
+               std::swap(c1, c2);
+       r1 = p->row(i1.idx_);
+       r2 = p->row(i2.idx_);
+       if (r1 > r2)
+               std::swap(r1, r2);
+}
+
+}
+
+
+string LCursor::grabSelection()
+{
+       if (!selection())
+               return string();
+
+       CursorSlice i1 = selBegin();
+       CursorSlice i2 = selEnd();
+
+       if (i1.idx_ == i2.idx_) {
+               if (i1.inset()->asMathInset()) {
+                       MathArray::const_iterator it = i1.cell().begin();
+                       return asString(MathArray(it + i1.pos_, it + i2.pos_));
+               } else {
+                       return "unknown selection 1";
+               }
+       }
+
+       row_type r1, r2;
+       col_type c1, c2;
+       region(i1, i2, r1, r2, c1, c2);
+
+       string data;
+       if (i1.inset()->asMathInset()) {
+               for (row_type row = r1; row <= r2; ++row) {
+                       if (row > r1)
+                               data += "\\\\";
+                       for (col_type col = c1; col <= c2; ++col) {
+                               if (col > c1)
+                                       data += '&';
+                               data += asString(i1.asMathInset()->cell(i1.asMathInset()->index(row, col)));
+                       }
+               }
+       } else {
+               data = "unknown selection 2";
+       }
+       return data;
+}
+
+
+void LCursor::eraseSelection()
+{
+       CursorSlice i1 = selBegin();
+       CursorSlice i2 = selEnd();
+#warning FIXME
+       if (i1.inset()->asMathInset()) {
+               if (i1.idx_ == i2.idx_) {
+                       i1.cell().erase(i1.pos_, i2.pos_);
+               } else {
+                       MathInset * p = i1.asMathInset();
+                       row_type r1, r2;
+                       col_type c1, c2;
+                       region(i1, i2, r1, r2, c1, c2);
+                       for (row_type row = r1; row <= r2; ++row)
+                               for (col_type col = c1; col <= c2; ++col)
+                                       p->cell(p->index(row, col)).clear();
+               }
+               current() = i1;
+       } else {
+               lyxerr << "can't erase this selection 1" << endl;
+       }
+}
+
+
+string LCursor::grabAndEraseSelection()
+{
+       if (!selection())
+               return string();
+       string res = grabSelection();
+       eraseSelection();
+       selection() = false;
+       return res;
+}
+
+
+void LCursor::selClear()
+{
+       resetAnchor();
+       clearSelection();
+}
+
+
+void LCursor::selCopy()
+{
+       if (selection()) {
+               theCutBuffer.push(grabSelection());
+               selection() = false;
+       } else {
+               //theCutBuffer.erase();
+       }
+}
+
+
+void LCursor::selCut()
+{
+       theCutBuffer.push(grabAndEraseSelection());
+}
+
+
+void LCursor::selDel()
+{
+       if (selection()) {
+               eraseSelection();
+               selection() = false;
+       }
+}
+
+
+void LCursor::selPaste(size_t n)
+{
+       selClearOrDel();
+       if (n < theCutBuffer.size())
+               paste(theCutBuffer[n]);
+       //grabSelection();
+       selection() = false;
+}
+
+
+void LCursor::selHandle(bool sel)
+{
+       if (sel == selection())
+               return;
+       resetAnchor();
+       selection() = sel;
+}
+
+
+void LCursor::selStart()
+{
+       resetAnchor();
+       selection() = true;
+}
+
+
+void LCursor::selClearOrDel()
+{
+       if (lyxrc.auto_region_delete)
+               selDel();
+       else
+               selection() = false;
+}
+
+
 std::ostream & operator<<(std::ostream & os, LCursor const & cur)
 {
        os << "\n";
 std::ostream & operator<<(std::ostream & os, LCursor const & cur)
 {
        os << "\n";
@@ -512,3 +719,1074 @@ std::ostream & operator<<(std::ostream & os, LCursor const & cur)
                os << "  (" << cur.cursor_[i] << " | " << cur.anchor_[i] << "\n";
        return os;
 }
                os << "  (" << cur.cursor_[i] << " | " << cur.anchor_[i] << "\n";
        return os;
 }
+
+
+
+
+//
+// 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() < top.lastidx()) {
+               ++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 & cur = it.back();
+       cur.idx() = cur.lastidx();
+       cur.pos() = cur.lastpos();
+       return it;
+}
+
+
+
+
+///////////////////////////////////////////////////////////////////
+//
+// The part below is the non-integrated rest of the original math
+// cursor. This should be either generalized for texted or moved
+// back to the math insets.
+//
+///////////////////////////////////////////////////////////////////
+
+#include "mathed/math_braceinset.h"
+#include "mathed/math_charinset.h"
+#include "mathed/math_commentinset.h"
+#include "mathed/math_factory.h"
+#include "mathed/math_gridinset.h"
+#include "mathed/math_macroarg.h"
+#include "mathed/math_macrotemplate.h"
+#include "mathed/math_mathmlstream.h"
+#include "mathed/math_scriptinset.h"
+#include "mathed/math_spaceinset.h"
+#include "mathed/math_support.h"
+#include "mathed/math_unknowninset.h"
+
+//#define FILEDEBUG 1
+
+
+bool LCursor::isInside(InsetBase const * p)
+{
+       for (unsigned i = 0; i < depth(); ++i)
+               if (cursor_[i].inset() == p)
+                       return true;
+       return false;
+}
+
+
+bool LCursor::openable(MathAtom const & t)
+{
+       if (!t->isActive())
+               return false;
+
+       if (t->lock())
+               return false;
+
+       if (!selection())
+               return true;
+
+       // we can't move into anything new during selection
+       if (depth() == anchor_.size())
+               return false;
+       if (t.operator->() != anchor_[depth()].inset())
+               return false;
+
+       return true;
+}
+
+
+bool LCursor::inNucleus()
+{
+       return inset()->asMathInset()->asScriptInset() && idx() == 2;
+}
+
+
+bool LCursor::left()
+{
+       autocorrect() = false;
+       x_target(-1); // "no target"
+       if (inMacroMode()) {
+               macroModeClose();
+               return true;
+       }
+
+       if (pos() != 0 && openable(prevAtom())) {
+               posLeft();
+               push(inset());
+               inset()->idxFirst(*this);
+               return true;
+       }
+
+       return posLeft() || idxLeft() || popLeft() || selection();
+}
+
+
+bool LCursor::right()
+{
+       autocorrect() = false;
+       x_target(-1); // "no target"
+       if (inMacroMode()) {
+               macroModeClose();
+               return true;
+       }
+
+       if (pos() != lastpos() && openable(nextAtom())) {
+               pushLeft(inset());
+               return true;
+       }
+
+       return posRight() || idxRight() || popRight() || selection();
+}
+
+
+bool positionable(CursorBase const & cursor, CursorBase const & anchor)
+{
+       // avoid deeper nested insets when selecting
+       if (cursor.size() > anchor.size())
+               return false;
+
+       // anchor might be deeper, should have same path then
+       for (CursorBase::size_type i = 0; i < cursor.size(); ++i)
+               if (cursor[i].inset() != anchor[i].inset())
+                       return false;
+
+       // position should be ok.
+       return true;
+}
+
+
+void LCursor::setScreenPos(int x, int y)
+{
+       bool res = bruteFind(x, y, formula()->xlow(), formula()->xhigh(),
+               formula()->ylow(), formula()->yhigh());
+       if (!res) {
+               // this can happen on creation of "math-display"
+               idx() = 0;
+               pos() = 0;
+       }
+       x_target(-1); // "no target"
+}
+
+
+
+bool LCursor::home()
+{
+       autocorrect() = false;
+       macroModeClose();
+       if (!inset()->idxHome(*this))
+               return popLeft();
+       x_target(-1); // "no target"
+       return true;
+}
+
+
+bool LCursor::end()
+{
+       autocorrect() = false;
+       macroModeClose();
+       if (!inset()->idxEnd(*this))
+               return popRight();
+       x_target(-1); // "no target"
+       return true;
+}
+
+
+void LCursor::plainErase()
+{
+       cell().erase(pos());
+}
+
+
+void LCursor::markInsert()
+{
+       cell().insert(pos(), MathAtom(new MathCharInset(0)));
+}
+
+
+void LCursor::markErase()
+{
+       cell().erase(pos());
+}
+
+
+void LCursor::plainInsert(MathAtom const & t)
+{
+       cell().insert(pos(), t);
+       ++pos();
+}
+
+
+void LCursor::insert2(string const & str)
+{
+       MathArray ar;
+       asArray(str, ar);
+       insert(ar);
+}
+
+
+void LCursor::insert(string const & str)
+{
+       //lyxerr << "inserting '" << str << "'" << endl;
+       selClearOrDel();
+       for (string::const_iterator it = str.begin(); it != str.end(); ++it)
+               plainInsert(MathAtom(new MathCharInset(*it)));
+}
+
+
+void LCursor::insert(char c)
+{
+       //lyxerr << "inserting '" << c << "'" << endl;
+       selClearOrDel();
+       plainInsert(MathAtom(new MathCharInset(c)));
+}
+
+
+void LCursor::insert(MathAtom const & t)
+{
+       macroModeClose();
+       selClearOrDel();
+       plainInsert(t);
+}
+
+
+void LCursor::niceInsert(string const & t)
+{
+       MathArray ar;
+       asArray(t, ar);
+       if (ar.size() == 1)
+               niceInsert(ar[0]);
+       else
+               insert(ar);
+}
+
+
+void LCursor::niceInsert(MathAtom const & t)
+{
+       macroModeClose();
+       string safe = grabAndEraseSelection();
+       plainInsert(t);
+       // enter the new inset and move the contents of the selection if possible
+       if (t->isActive()) {
+               posLeft();
+               pushLeft(inset());
+               paste(safe);
+       }
+}
+
+
+void LCursor::insert(MathArray const & ar)
+{
+       macroModeClose();
+       if (selection())
+               eraseSelection();
+       cell().insert(pos(), ar);
+       pos() += ar.size();
+}
+
+
+bool LCursor::backspace()
+{
+       autocorrect() = false;
+
+       if (selection()) {
+               selDel();
+               return true;
+       }
+
+       if (pos() == 0) {
+               if (inset()->nargs() == 1 && depth() == 1 && lastpos() == 0)
+                       return false;
+               pullArg();
+               return true;
+       }
+
+       if (inMacroMode()) {
+               MathUnknownInset * p = activeMacro();
+               if (p->name().size() > 1) {
+                       p->setName(p->name().substr(0, p->name().size() - 1));
+                       return true;
+               }
+       }
+
+       if (pos() != 0 && prevAtom()->nargs() > 0) {
+               // let's require two backspaces for 'big stuff' and
+               // highlight on the first
+               selection() = true;
+               left();
+       } else {
+               --pos();
+               plainErase();
+       }
+       return true;
+}
+
+
+bool LCursor::erase()
+{
+       autocorrect() = false;
+       if (inMacroMode())
+               return true;
+
+       if (selection()) {
+               selDel();
+               return true;
+       }
+
+       // delete empty cells if possible
+#warning FIXME
+       //if (cell().empty() && inset()->idxDelete(idx()))
+       //              return true;
+
+       // special behaviour when in last position of cell
+       if (pos() == lastpos()) {
+               bool one_cell = inset()->nargs() == 1;
+               if (one_cell && depth() == 1 && lastpos() == 0)
+                       return false;
+               // remove markup
+               if (one_cell)
+                       pullArg();
+               else
+                       inset()->idxGlue(idx());
+               return true;
+       }
+
+       if (pos() != lastpos() && inset()->nargs() > 0) {
+               selection() = true;
+               right();
+       } else {
+               plainErase();
+       }
+
+       return true;
+}
+
+
+bool LCursor::up()
+{
+       macroModeClose();
+       CursorBase save = cursor_;
+       if (goUpDown(true))
+               return true;
+       cursor_ = save;
+       autocorrect() = false;
+       return selection();
+}
+
+
+bool LCursor::down()
+{
+       macroModeClose();
+       CursorBase save = cursor_;
+       if (goUpDown(false))
+               return true;
+       cursor_ = save;
+       autocorrect() = false;
+       return selection();
+}
+
+
+void LCursor::macroModeClose()
+{
+       if (!inMacroMode())
+               return;
+       MathUnknownInset * p = activeMacro();
+       p->finalize();
+       string s = p->name();
+       --pos();
+       cell().erase(pos());
+
+       // do nothing if the macro name is empty
+       if (s == "\\")
+               return;
+
+       string const name = s.substr(1);
+
+       // prevent entering of recursive macros
+       if (formula()->lyxCode() == InsetOld::MATHMACRO_CODE
+                       && formula()->getInsetName() == name)
+               lyxerr << "can't enter recursive macro" << endl;
+
+       niceInsert(createMathInset(name));
+}
+
+
+string LCursor::macroName()
+{
+       return inMacroMode() ? activeMacro()->name() : string();
+}
+
+
+void LCursor::drawSelection(PainterInfo & pi)
+{
+       if (!selection())
+               return;
+       CursorSlice i1 = selBegin();
+       CursorSlice i2 = selEnd();
+       i1.asMathInset()->drawSelection(pi, i1.idx_, i1.pos_, i2.idx_, i2.pos_);
+}
+
+
+void LCursor::handleNest(MathAtom const & a, int c)
+{
+       MathAtom at = a;
+       asArray(grabAndEraseSelection(), at.nucleus()->cell(c));
+       insert(at);
+       posLeft();
+       pushLeft(inset());
+}
+
+
+void LCursor::getScreenPos(int & x, int & y) const
+{
+       BOOST_ASSERT(inset());
+       BOOST_ASSERT(inset()->asMathInset());
+       inset()->asMathInset()->getScreenPos(idx(), pos(), x, y);
+}
+
+
+int LCursor::targetX() const
+{
+       if (x_target() != -1)
+               return x_target();
+       int x = 0;
+       int y = 0;
+       getScreenPos(x, y);
+       return x;
+}
+
+
+MathHullInset * LCursor::formula() const
+{
+       for (int i = cursor_.size() - 1; i >= 1; --i)
+               if (cursor_[i].inset()->lyxCode() == InsetBase::MATH_CODE)
+                       return static_cast<MathHullInset *>(cursor_[i].inset());
+       return 0;
+}
+
+
+void LCursor::adjust(pos_type from, int diff)
+{      
+       if (pos() > from)
+               pos() += diff;
+       if (anchor().pos_ > from)
+               anchor().pos_ += diff;
+       // just to be on the safe side
+       // theoretically unecessary
+       normalize();
+}
+
+
+bool LCursor::inMacroMode() const
+{
+       if (!pos() != 0)
+               return false;
+       MathUnknownInset const * p = prevAtom()->asUnknownInset();
+       return p && !p->final();
+}
+
+
+MathUnknownInset * LCursor::activeMacro()
+{
+       return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : 0;
+}
+
+
+bool LCursor::inMacroArgMode() const
+{
+       return pos() > 0 && prevAtom()->getChar() == '#';
+}
+
+
+MathGridInset * LCursor::enclosingGrid(idx_type & idx) const
+{
+       for (MathInset::difference_type i = depth() - 1; i >= 0; --i) {
+               MathInset * m = cursor_[i].inset()->asMathInset();
+               if (!m)
+                       return 0;
+               MathGridInset * p = m->asGridInset();
+               if (p) {
+                       idx = cursor_[i].idx_;
+                       return p;
+               }
+       }
+       return 0;
+}
+
+
+void LCursor::pullArg()
+{
+#warning look here
+#if 0
+       MathArray ar = cell();
+       if (popLeft()) {
+               plainErase();
+               cell().insert(pos(), ar);
+               resetAnchor();
+       } else {
+               formula()->mutateToText();
+       }
+#endif
+}
+
+
+void LCursor::touch()
+{
+#warning look here
+#if 0
+       CursorBase::const_iterator it = cursor_.begin();
+       CursorBase::const_iterator et = cursor_.end();
+       for ( ; it != et; ++it)
+               it->cell().touch();
+#endif
+}
+
+
+void LCursor::normalize()
+{
+       if (idx() >= nargs()) {
+               lyxerr << "this should not really happen - 1: "
+                      << idx() << ' ' << nargs()
+                      << " in: " << inset() << endl;
+       }
+       idx() = min(idx(), nargs() - 1);
+
+       if (pos() > lastpos()) {
+               lyxerr << "this should not really happen - 2: "
+                       << pos() << ' ' << lastpos() <<  " in idx: " << idx()
+                      << " in atom: '";
+               WriteStream wi(lyxerr, false, true);
+               inset()->asMathInset()->write(wi);
+               lyxerr << endl;
+       }
+       pos() = min(pos(), lastpos());
+}
+
+
+char LCursor::valign()
+{
+       idx_type idx;
+       MathGridInset * p = enclosingGrid(idx);
+       return p ? p->valign() : '\0';
+}
+
+
+char LCursor::halign()
+{
+       idx_type idx;
+       MathGridInset * p = enclosingGrid(idx);
+       return p ? p->halign(idx % p->ncols()) : '\0';
+}
+
+
+bool LCursor::goUpDown(bool up)
+{
+       // Be warned: The 'logic' implemented in this function is highly fragile.
+       // A distance of one pixel or a '<' vs '<=' _really_ matters.
+       // So fiddle around with it only if you know what you are doing!
+  int xo = 0;
+       int yo = 0;
+       getScreenPos(xo, yo);
+
+       // check if we had something else in mind, if not, this is the future goal
+       if (x_target() == -1)
+               x_target(xo);
+       else
+               xo = x_target();
+
+       // try neigbouring script insets
+       if (!selection()) {
+               // try left
+               if (pos() != 0) {
+                       MathScriptInset const * p = prevAtom()->asScriptInset();
+                       if (p && p->has(up)) {
+                               --pos();
+                               push(inset());
+                               idx() = up; // the superscript has index 1
+                               pos() = lastpos();
+                               //lyxerr << "updown: handled by scriptinset to the left" << endl;
+                               return true;
+                       }
+               }
+
+               // try right
+               if (pos() != lastpos()) {
+                       MathScriptInset const * p = nextAtom()->asScriptInset();
+                       if (p && p->has(up)) {
+                               push(inset());
+                               idx() = up;
+                               pos() = 0;
+                               //lyxerr << "updown: handled by scriptinset to the right" << endl;
+                               return true;
+                       }
+               }
+       }
+
+       // try current cell for e.g. text insets
+       if (inset()->idxUpDown2(*this, up))
+               return true;
+
+       //xarray().boundingBox(xlow, xhigh, ylow, yhigh);
+       //if (up)
+       //      yhigh = yo - 4;
+       //else
+       //      ylow = yo + 4;
+       //if (bruteFind(xo, yo, xlow, xhigh, ylow, yhigh)) {
+       //      lyxerr << "updown: handled by brute find in the same cell" << endl;
+       //      return true;
+       //}
+
+       // try to find an inset that knows better then we
+       while (1) {
+               //lyxerr << "updown: We are in " << inset() << " idx: " << idx() << endl;
+               // ask inset first
+               if (inset()->idxUpDown(*this, up)) {
+                       // try to find best position within this inset
+                       if (!selection())
+                               bruteFind2(xo, yo);
+                       return true;
+               }
+
+               // no such inset found, just take something "above"
+               //lyxerr << "updown: handled by strange case" << endl;
+               if (!popLeft()) {
+                       return
+                               bruteFind(xo, yo,
+                                       formula()->xlow(),
+                                       formula()->xhigh(),
+                                       up ? formula()->ylow() : yo + 4,
+                                       up ? yo - 4 : formula()->yhigh()
+                               );
+               }
+
+               // any improvement so far?
+               int xnew, ynew;
+               getScreenPos(xnew, ynew);
+               if (up ? ynew < yo : ynew > yo)
+                       return true;
+       }
+}
+
+
+bool LCursor::bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh)
+{
+       CursorBase best_cursor;
+       double best_dist = 1e10;
+
+       CursorBase it = ibegin(formula());
+       CursorBase et = iend(formula());
+       while (1) {
+               // avoid invalid nesting when selecting
+               if (!selection() || positionable(it, anchor_)) {
+                       int xo, yo;
+                       it.back().getScreenPos(xo, yo);
+                       if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
+                               double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
+                               //lyxerr << "x: " << x << " y: " << y << " d: " << endl;
+                               // '<=' in order to take the last possible position
+                               // this is important for clicking behind \sum in e.g. '\sum_i a'
+                               if (d <= best_dist) {
+                                       best_dist   = d;
+                                       best_cursor = it;
+                               }
+                       }
+               }
+
+               if (it == et)
+                       break;
+               increment(it);
+       }
+
+       if (best_dist < 1e10)
+               cursor_ = best_cursor;
+       return best_dist < 1e10;
+}
+
+
+void LCursor::bruteFind2(int x, int y)
+{
+       double best_dist = 1e10;
+
+       CursorBase it = cursor_;
+       it.back().pos(0);
+       CursorBase et = cursor_;
+       int n = et.back().asMathInset()->cell(et.back().idx_).size();
+       et.back().pos(n);
+       for (int i = 0; ; ++i) {
+               int xo, yo;
+               it.back().getScreenPos(xo, yo);
+               double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
+               // '<=' in order to take the last possible position
+               // this is important for clicking behind \sum in e.g. '\sum_i a'
+               lyxerr << "i: " << i << " d: " << d << " best: " << best_dist << endl;
+               if (d <= best_dist) {
+                       best_dist = d;
+                       cursor_ = it;
+               }
+               if (it == et)
+                       break;
+               increment(it);
+       }
+}
+
+
+bool LCursor::idxLineLast()
+{
+       idx() -= idx() % ncols();
+       idx() += ncols() - 1;
+       pos() = lastpos();
+       return true;
+}
+
+
+bool LCursor::idxLeft()
+{
+       return inset()->idxLeft(*this);
+}
+
+
+bool LCursor::idxRight()
+{
+       return inset()->idxRight(*this);
+}
+
+
+bool LCursor::script(bool up)
+{
+       // Hack to get \\^ and \\_ working
+       if (inMacroMode() && macroName() == "\\") {
+               if (up)
+                       niceInsert(createMathInset("mathcircumflex"));
+               else
+                       interpret('_');
+               return true;
+       }
+
+       macroModeClose();
+       string safe = grabAndEraseSelection();
+       if (inNucleus()) {
+               // we are in a nucleus of a script inset, move to _our_ script
+               inset()->asMathInset()->asScriptInset()->ensure(up);
+               idx() = up;
+               pos() = 0;
+       } else if (pos() != 0 && prevAtom()->asScriptInset()) {
+               prevAtom().nucleus()->asScriptInset()->ensure(up);
+               posLeft();
+               push(inset());
+               idx() = up;
+               pos() = lastpos();
+       } else if (pos() != 0) {
+               --pos();
+               cell()[pos()]
+                       = MathAtom(new MathScriptInset(nextAtom(), up));
+               push(inset());
+               idx() = up;
+               pos() = 0;
+       } else {
+               plainInsert(MathAtom(new MathScriptInset(up)));
+               posLeft();
+               nextAtom().nucleus()->asScriptInset()->ensure(up);
+               push(inset());
+               idx() = up;
+               pos() = 0;
+       }
+       paste(safe);
+       return true;
+}
+
+
+bool LCursor::interpret(char c)
+{
+       //lyxerr << "interpret 2: '" << c << "'" << endl;
+       x_target(-1); // "no target"
+       if (inMacroArgMode()) {
+               posLeft();
+               plainErase();
+#warning FIXME
+#if 0
+               int n = c - '0';
+               MathMacroTemplate const * p = formula()->asMacroTemplate();
+               if (p && 1 <= n && n <= p->numargs())
+                       insert(MathAtom(new MathMacroArgument(c - '0')));
+               else {
+                       insert(createMathInset("#"));
+                       interpret(c); // try again
+               }
+#endif
+               return true;
+       }
+
+       // handle macroMode
+       if (inMacroMode()) {
+               string name = macroName();
+               //lyxerr << "interpret name: '" << name << "'" << endl;
+
+               if (isalpha(c)) {
+                       activeMacro()->setName(activeMacro()->name() + c);
+                       return true;
+               }
+
+               // handle 'special char' macros
+               if (name == "\\") {
+                       // remove the '\\'
+                       backspace();
+                       if (c == '\\') {
+                               if (currentMode() == MathInset::TEXT_MODE)
+                                       niceInsert(createMathInset("textbackslash"));
+                               else
+                                       niceInsert(createMathInset("backslash"));
+                       } else if (c == '{') {
+                               niceInsert(MathAtom(new MathBraceInset));
+                       } else {
+                               niceInsert(createMathInset(string(1, c)));
+                       }
+                       return true;
+               }
+
+               // leave macro mode and try again if necessary
+               macroModeClose();
+               if (c == '{')
+                       niceInsert(MathAtom(new MathBraceInset));
+               else if (c != ' ')
+                       interpret(c);
+               return true;
+       }
+
+       // This is annoying as one has to press <space> far too often.
+       // Disable it.
+
+       if (0) {
+               // leave autocorrect mode if necessary
+               if (autocorrect() && c == ' ') {
+                       autocorrect() = false;
+                       return true;
+               }
+       }
+
+       // just clear selection on pressing the space bar
+       if (selection() && c == ' ') {
+               selection() = false;
+               return true;
+       }
+
+       selClearOrDel();
+
+       if (c == '\\') {
+               //lyxerr << "starting with macro" << endl;
+               insert(MathAtom(new MathUnknownInset("\\", false)));
+               return true;
+       }
+
+       if (c == '\n') {
+               if (currentMode() == MathInset::TEXT_MODE)
+                       insert(c);
+               return true;
+       }
+
+       if (c == ' ') {
+               if (currentMode() == MathInset::TEXT_MODE) {
+                       // insert spaces in text mode,
+                       // but suppress direct insertion of two spaces in a row
+                       // the still allows typing  '<space>a<space>' and deleting the 'a', but
+                       // it is better than nothing...
+                       if (!pos() != 0 || prevAtom()->getChar() != ' ')
+                               insert(c);
+                       return true;
+               }
+               if (pos() != 0 && prevAtom()->asSpaceInset()) {
+                       prevAtom().nucleus()->asSpaceInset()->incSpace();
+                       return true;
+               }
+               if (popRight())
+                       return true;
+               // if are at the very end, leave the formula
+               return pos() != lastpos();
+       }
+
+       if (c == '_') {
+               script(false);
+               return true;
+       }
+
+       if (c == '^') {
+               script(true);
+               return true;
+       }
+
+       if (c == '{' || c == '}' || c == '#' || c == '&' || c == '$') {
+               niceInsert(createMathInset(string(1, c)));
+               return true;
+       }
+
+       if (c == '%') {
+               niceInsert(MathAtom(new MathCommentInset));
+               return true;
+       }
+
+       // try auto-correction
+       //if (autocorrect() && hasPrevAtom() && math_autocorrect(prevAtom(), c))
+       //      return true;
+
+       // no special circumstances, so insert the character without any fuss
+       insert(c);
+       autocorrect() = true;
+       return true;
+}
+
+
+void LCursor::lockToggle()
+{
+       if (pos() != lastpos()) {
+               // toggle previous inset ...
+               nextAtom().nucleus()->lock(!nextAtom()->lock());
+       } else if (popLeft() && pos() != lastpos()) {
+               // ... or enclosing inset if we are in the last inset position
+               nextAtom().nucleus()->lock(!nextAtom()->lock());
+               posRight();
+       }
+}
+
+
+CursorSlice LCursor::normalAnchor()
+{
+       if (anchor_.size() < depth()) {
+               resetAnchor();
+               lyxerr << "unusual Anchor size" << endl;
+       }
+       //lyx::BOOST_ASSERT(Anchor_.size() >= cursor.depth());
+       // use Anchor on the same level as Cursor
+       CursorSlice normal = anchor_[depth() - 1];
+#if 0
+       if (depth() < anchor_.size() && !(normal < xx())) {
+               // anchor is behind cursor -> move anchor behind the inset
+               ++normal.pos_;
+       }
+#endif
+       return normal;
+}
+
+
+/*
+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();
+                       int x = 0;
+                       int y = 0;
+                       getScreenPos(x, y);
+                       if (x < cmd.x && pos() != 0) {
+                               DispatchResult const res = prevAtom().nucleus()->dispatch(cmd);
+                               if (res.dispatched())
+                                       return res;
+                       }
+                       if (x > cmd.x && pos() != lastpos()) {
+                               DispatchResult const res = inset()->dispatch(cmd);
+                               if (res.dispatched())
+                                       return res;
+                       }
+               }
+               default:
+                       break;
+       }
+       /...
+}
+*/
+
+
+void LCursor::handleFont(string const & font)
+{
+       string safe;
+       if (selection()) {
+               macroModeClose();
+               safe = grabAndEraseSelection();
+       }
+
+       if (lastpos() != 0) {
+               // something left in the cell
+               if (pos() == 0) {
+                       // cursor in first position
+                       popLeft();
+               } else if (pos() == lastpos()) {
+                       // cursor in last position
+                       popRight();
+               } else {
+                       // cursor in between. split cell
+                       MathArray::iterator bt = cell().begin();
+                       MathAtom at = createMathInset(font);
+                       at.nucleus()->cell(0) = MathArray(bt, bt + pos());
+                       cell().erase(bt, bt + pos());
+                       popLeft();
+                       plainInsert(at);
+               }
+       } else {
+               // nothing left in the cell
+               pullArg();
+               plainErase();
+       }
+       insert(safe);
+}
+
+
+void LCursor::releaseMathCursor()
+{
+       if (inMathed())
+               formula()->insetUnlock(bv());
+}
+
+
+bool LCursor::inMathed() const
+{
+       return formula();
+}
index d6537ffd5214b09da720ca6a638fb5d01ce10fd2..59519bbb865c2e7c23d69ca4d495aac2ad4a5ff5 100644 (file)
@@ -27,6 +27,11 @@ class LyXText;
 class Paragraph;
 
 
 class Paragraph;
 
 
+// these should go
+class MathHullInset;
+class PainterInfo;
+class MathUnknownInset;
+class MathGridInset;
 
 // this is used for traversing math insets
 typedef std::vector<CursorSlice> CursorBase;
 
 // this is used for traversing math insets
 typedef std::vector<CursorSlice> CursorBase;
@@ -59,12 +64,18 @@ public:
        explicit LCursor(BufferView & bv);
        /// dispatch from innermost inset upwards
        DispatchResult dispatch(FuncRequest const & cmd);
        explicit LCursor(BufferView & bv);
        /// dispatch from innermost inset upwards
        DispatchResult dispatch(FuncRequest const & cmd);
-       ///
+       /// add a new cursor slice
        void push(InsetBase * inset);
        void push(InsetBase * inset);
-       /// restrict cursor nesting to given size
-       void pop(int depth);
+       /// add a new cursor slice, place cursor on left end
+       void pushLeft(InsetBase * inset);
        /// pop one level off the cursor
        void pop();
        /// pop one level off the cursor
        void pop();
+       /// pop one slice off the cursor stack and go left
+       bool popLeft();
+       /// pop one slice off the cursor stack and go right
+       bool popRight();
+       /// restrict cursor nesting to given size
+       void pop(int depth);
        /// access to current cursor slice
        CursorSlice & current();
        /// access to current cursor slice
        /// access to current cursor slice
        CursorSlice & current();
        /// access to current cursor slice
@@ -85,26 +96,55 @@ public:
        bool & mark() { return mark_; }
        ///
        void setSelection();
        bool & mark() { return mark_; }
        ///
        void setSelection();
+       /// set selection at given position
+       void setSelection(CursorBase const & where, size_t n);
        ///
        void clearSelection();
        ///
        void clearSelection();
+       /// access start of selection
+       CursorSlice & selBegin();
+       /// access start of selection
+       CursorSlice const & selBegin() const;
+       /// access end of selection
+       CursorSlice & selEnd();
+       /// access end of selection
+       CursorSlice const & selEnd() const;
        ///
        ///
-       CursorSlice & selStart();
+       std::string grabSelection();
        ///
        ///
-       CursorSlice const & selStart() const;
+       void eraseSelection();
        ///
        ///
-       CursorSlice & selEnd();
+       std::string grabAndEraseSelection();
+       // other selection methods
        ///
        ///
-       CursorSlice const & selEnd() const;
+       void selCopy();
+       ///
+       void selCut();
+       ///
+       void selDel();
+       /// pastes n-th element of cut buffer
+       void selPaste(size_t n);
+       ///
+       void selHandle(bool selecting);
+       /// start selection
+       void selStart();
+       /// clear selection
+       void selClear();
+       /// clears or deletes selection depending on lyxrc setting
+       void selClearOrDel();
+       ///
+       void paste(std::string const & data);
 
        //
        // access to the 'current' cursor slice
        //
        /// the current inset
        InsetBase * inset() const { return current().inset(); }
 
        //
        // access to the 'current' cursor slice
        //
        /// the current inset
        InsetBase * inset() const { return current().inset(); }
-       /// return the text-ed cell this cursor is in
+       /// return the cell of the inset this cursor is in
        idx_type idx() const { return current().idx(); }
        idx_type idx() const { return current().idx(); }
-       /// return the text-ed cell this cursor is in
+       /// return the cell of the inset this cursor is in
        idx_type & idx() { return current().idx(); }
        idx_type & idx() { return current().idx(); }
+       /// return the last possible cell in this inset
+       idx_type lastidx() const { return current().lastidx(); }
        /// return the paragraph this cursor is in
        par_type par() const { return current().par(); }
        /// return the paragraph this cursor is in
        /// return the paragraph this cursor is in
        par_type par() const { return current().par(); }
        /// return the paragraph this cursor is in
@@ -164,6 +204,8 @@ public:
        InsetTabular * innerInsetTabular() const;
        ///
        LyXText * innerText() const;
        InsetTabular * innerInsetTabular() const;
        ///
        LyXText * innerText() const;
+       ///
+       CursorSlice const & innerTextSlice() const;
        /// returns x,y position
        void getPos(int & x, int & y) const;
        /// returns cursor dimension
        /// returns x,y position
        void getPos(int & x, int & y) const;
        /// returns cursor dimension
@@ -194,6 +236,10 @@ public:
        BufferView & bv() const; 
        /// get some interesting description of current position
        void info(std::ostream & os);
        BufferView & bv() const; 
        /// get some interesting description of current position
        void info(std::ostream & os);
+       /// are we in math mode (2), text mode (1) or unsure (0)?
+       int currentMode();
+       /// reset cursor
+       void reset();
 
        /// output
        friend std::ostream & operator<<(std::ostream & os, LCursor const & cur);
 
        /// output
        friend std::ostream & operator<<(std::ostream & os, LCursor const & cur);
@@ -241,6 +287,137 @@ private:
        bool autocorrect_;
        /// are we entering a macro name?
        bool macromode_;
        bool autocorrect_;
        /// are we entering a macro name?
        bool macromode_;
+
+
+///////////////////////////////////////////////////////////////////
+//
+// The part below is the non-integrated rest of the original math
+// cursor. This should be either generalized for texted or moved
+// back to the math insets.
+//
+///////////////////////////////////////////////////////////////////
+
+public:
+       ///
+       void insert(MathAtom const &);
+       ///
+       void insert(MathArray const &);
+       ///
+       void insert2(std::string const &);
+       /// return false for empty math insets
+       bool erase();
+       /// return false for empty math insets
+       bool backspace();
+       /// called for LFUN_HOME etc
+       bool home();
+       /// called for LFUN_END etc
+       bool end();
+       /// called for LFUN_RIGHT and LFUN_RIGHTSEL
+       bool right();
+       /// called for LFUN_LEFT etc
+       bool left();
+       /// called for LFUN_UP etc
+       bool up();
+       /// called for LFUN_DOWN etc
+       bool down();
+       ///
+       void plainErase();
+       ///
+       void plainInsert(MathAtom const & at);
+       ///
+       void niceInsert(MathAtom const & at);
+       ///
+       void niceInsert(std::string const & str);
+
+       /// in pixels from top of screen
+       void setScreenPos(int x, int y);
+       /// in pixels from top of screen
+       void getScreenPos(int & x, int & y) const;
+       /// in pixels from left of screen
+       int targetX() const;
+       /// return the next enclosing grid inset and the cursor's index in it
+       MathGridInset * enclosingGrid(idx_type & idx) const;
+       /// adjust anchor position after deletions/insertions
+       void adjust(pos_type from, int diff);
+       ///
+       MathHullInset * formula() const;
+       /// current offset in the current cell
+       ///
+       bool script(bool);
+       ///
+       bool interpret(char);
+       /// interpret name a name of a macro
+       void macroModeClose();
+       /// are we currently typing the name of a macro?
+       bool inMacroMode() const;
+       /// get access to the macro we are currently typing
+       MathUnknownInset * activeMacro();
+       /// are we currently typing '#1' or '#2' or...?
+       bool inMacroArgMode() const;
+
+       /// draws light-blue selection background
+       void drawSelection(PainterInfo & pi);
+       /// replace selected stuff with at, placing the former
+       // selection in given cell of atom
+       void handleNest(MathAtom const & at, int cell = 0);
+       /// remove this as soon as LyXFunc::getStatus is "localized"
+       //inline std::string getLastCode() { return "mathnormal"; }
+       ///
+       bool isInside(InsetBase const *);
+       ///
+       char valign();
+       ///
+       char halign();
+
+       /// make sure cursor position is valid
+       void normalize();
+       /// mark current cursor trace for redraw
+       void touch();
+
+       /// returns the normalized anchor of the selection
+       CursorSlice normalAnchor();
+
+       ///
+       void insert(char c);
+       ///
+       void insert(std::string const & str);
+       /// lock/unlock inset
+       void lockToggle();
+
+       /// hack for reveal codes
+       void markInsert();
+       void markErase();
+       /// injects content of a cell into parent
+       void pullArg();
+       /// split font inset etc
+       void handleFont(std::string const & font);
+
+       void releaseMathCursor();
+
+       bool inMathed() const;
+
+private:
+       /// moves cursor index one cell to the left
+       bool idxLeft();
+       /// moves cursor index one cell to the right
+       bool idxRight();
+       /// moves cursor to end of last cell of current line
+       bool idxLineLast();
+       /// moves position somehow up or down
+       bool goUpDown(bool up);
+       /// moves position closest to (x, y) in given box
+       bool bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh);
+       /// moves position closest to (x, y) in current cell
+       void bruteFind2(int x, int y);
+       /// are we in a nucleus of a script inset?
+       bool inNucleus();
+
+       /// the name of the macro we are currently inputting
+       std::string macroName();
+       /// where in the curent cell does the macro name start?
+       int macroNamePos();
+       /// can we enter the inset?
+       bool openable(MathAtom const &);
 };
 
 #endif // LYXCURSOR_H
 };
 
 #endif // LYXCURSOR_H
index e64948a36fced8ff738d36ebacc9932b1e49cde2..045ac748bd9279e6cf36bcc6dae90d56dbaffca0 100644 (file)
@@ -60,10 +60,12 @@ public:
        InsetBase * inset() const { return inset_; }
        /// set the paragraph that contains this cursor
        void idx(idx_type idx);
        InsetBase * inset() const { return inset_; }
        /// set the paragraph that contains this cursor
        void idx(idx_type idx);
-       /// return the paragraph this cursor is in
+       /// return the cell this cursor is in
        idx_type idx() const;
        idx_type idx() const;
-       /// return the paragraph this cursor is in
+       /// return the cell this cursor is in
        idx_type & idx();
        idx_type & idx();
+       /// return the last cell in this inset
+       idx_type lastidx() const { return nargs() - 1; }
        /// set the paragraph that contains this cursor
        void par(par_type par);
        /// return the paragraph this cursor is in
        /// set the paragraph that contains this cursor
        void par(par_type par);
        /// return the paragraph this cursor is in
index d1afb99668381cc7fcbc4d8e523d3d4b1cd08a97..b0f443fdab9ed8ea3a06f3662e6510cce9fe6d71 100644 (file)
 #include "insets/inseturl.h"
 #include "insets/insetvspace.h"
 #include "insets/insetwrap.h"
 #include "insets/inseturl.h"
 #include "insets/insetvspace.h"
 #include "insets/insetwrap.h"
+
 #include "mathed/formulamacro.h"
 #include "mathed/formulamacro.h"
-#include "mathed/formula.h"
+#include "mathed/math_hullinset.h"
 
 #include "frontends/Dialogs.h"
 #include "frontends/LyXView.h"
 
 #include "frontends/Dialogs.h"
 #include "frontends/LyXView.h"
+
 #include "support/lstrings.h"
 #include "support/std_sstream.h"
 
 #include "support/lstrings.h"
 #include "support/std_sstream.h"
 
@@ -69,7 +71,7 @@ using std::endl;
 using std::string;
 
 
 using std::string;
 
 
-InsetOld * createInset(BufferView * bv, FuncRequest const & cmd)
+InsetBase * createInset(BufferView * bv, FuncRequest const & cmd)
 {
        BufferParams const & params = bv->buffer()->params();
 
 {
        BufferParams const & params = bv->buffer()->params();
 
@@ -330,7 +332,7 @@ InsetOld * createInset(BufferView * bv, FuncRequest const & cmd)
 }
 
 
 }
 
 
-InsetOld * readInset(LyXLex & lex, Buffer const & buf)
+InsetBase * readInset(LyXLex & lex, Buffer const & buf)
 {
        // consistency check
        if (lex.getString() != "\\begin_inset") {
 {
        // consistency check
        if (lex.getString() != "\\begin_inset") {
@@ -338,7 +340,7 @@ InsetOld * readInset(LyXLex & lex, Buffer const & buf)
                       << endl;
        }
 
                       << endl;
        }
 
-       auto_ptr<InsetOld> inset;
+       auto_ptr<InsetBase> inset;
 
        LyXTextClass tclass = buf.params().getLyXTextClass();
                
 
        LyXTextClass tclass = buf.params().getLyXTextClass();
                
@@ -405,7 +407,7 @@ InsetOld * readInset(LyXLex & lex, Buffer const & buf)
                } else if (tmptok == "FormulaMacro") {
                        inset.reset(new InsetFormulaMacro);
                } else if (tmptok == "Formula") {
                } else if (tmptok == "FormulaMacro") {
                        inset.reset(new InsetFormulaMacro);
                } else if (tmptok == "Formula") {
-                       inset.reset(new InsetFormula);
+                       inset.reset(new MathHullInset);
                } else if (tmptok == "Graphics") {
                        inset.reset(new InsetGraphics);
                } else if (tmptok == "Note") {
                } else if (tmptok == "Graphics") {
                        inset.reset(new InsetGraphics);
                } else if (tmptok == "Note") {
index d1a6d5e32efddd01d59b0302dcc93f8db101d806..0c7ec876009fca605b3b09b5aab217bc7cdaecc3 100644 (file)
 class Buffer;
 class BufferView;
 class FuncRequest;
 class Buffer;
 class BufferView;
 class FuncRequest;
-class InsetOld;
+class InsetBase;
 class LyXLex;
 
 
 /// creates inset according to 'cmd'
 class LyXLex;
 
 
 /// creates inset according to 'cmd'
-InsetOld * createInset(BufferView * bv, FuncRequest const & cmd);
+InsetBase * createInset(BufferView * bv, FuncRequest const & cmd);
 
 /// read inset from a file
 
 /// read inset from a file
-InsetOld * readInset(LyXLex & lex, Buffer const & buf);
+InsetBase * readInset(LyXLex & lex, Buffer const & buf);
 
 #endif // FACTORY_H
 
 #endif // FACTORY_H
index da79c4c181567185d3ae0dd8fcb59317ed359826..a0376f3dea81d45db907c41dd61e49fd64c0ba93 100644 (file)
@@ -21,6 +21,7 @@
 #include "bufferparams.h"
 #include "BufferView.h"
 #include "bufferview_funcs.h"
 #include "bufferparams.h"
 #include "BufferView.h"
 #include "bufferview_funcs.h"
+#include "cursor.h"
 #include "debug.h"
 #include "funcrequest.h"
 #include "gettext.h"
 #include "debug.h"
 #include "funcrequest.h"
 #include "gettext.h"
@@ -34,8 +35,6 @@
 
 #include "controllers/ControlCommandBuffer.h"
 
 
 #include "controllers/ControlCommandBuffer.h"
 
-#include "mathed/math_cursor.h"
-
 #include "support/filetools.h" // OnlyFilename()
 
 #include <boost/bind.hpp>
 #include "support/filetools.h" // OnlyFilename()
 
 #include <boost/bind.hpp>
@@ -105,7 +104,7 @@ void LyXView::setLayout(string const & layout)
 
 void LyXView::updateToolbar()
 {
 
 void LyXView::updateToolbar()
 {
-       bool const math = inMathed();
+       bool const math = bufferview_->cursor().inMathed();
        bool const table =
                !getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).disabled();
        toolbar_->update(math, table);
        bool const table =
                !getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).disabled();
        toolbar_->update(math, table);
index 9d56a9713bb1d89fef593532d76192ea90ec50f1..353712f59a86a0cb203ab6f70f92004ba43f286b 100644 (file)
@@ -41,30 +41,6 @@ InsetOld::InsetOld(InsetOld const & in)
 {}
 
 
 {}
 
 
-bool InsetOld::directWrite() const
-{
-       return false;
-}
-
-
-InsetOld::EDITABLE InsetOld::editable() const
-{
-       return NOT_EDITABLE;
-}
-
-
-bool InsetOld::autoDelete() const
-{
-       return false;
-}
-
-
-string const InsetOld::editMessage() const
-{
-       return _("Opened inset");
-}
-
-
 void InsetOld::setBackgroundColor(LColor_color color)
 {
        background_color_ = color;
 void InsetOld::setBackgroundColor(LColor_color color)
 {
        background_color_ = color;
@@ -77,7 +53,7 @@ LColor_color InsetOld::backgroundColor() const
 }
 
 
 }
 
 
-bool InsetOld::forceDefaultParagraphs(InsetOld const * inset) const
+bool InsetOld::forceDefaultParagraphs(InsetBase const * inset) const
 {
        if (owner())
                return owner()->forceDefaultParagraphs(inset);
 {
        if (owner())
                return owner()->forceDefaultParagraphs(inset);
@@ -103,52 +79,9 @@ int InsetOld::width() const
 }
 
 
 }
 
 
-bool InsetOld::insetAllowed(InsetOld * in) const
-{
-       return insetAllowed(in->lyxCode());
-}
-
-
 int InsetOld::scroll(bool recursive) const
 {
        if (!recursive || !owner_)
                return scx;
        return 0;
 }
 int InsetOld::scroll(bool recursive) const
 {
        if (!recursive || !owner_)
                return scx;
        return 0;
 }
-
-
-int InsetOld::getCell(int x, int y) const
-{
-       for (int i = 0, n = numParagraphs(); i < n; ++i) {
-               LyXText * text = getText(i);
-               //lyxerr << "### text: " << text << " i: " << i
-               //      << " xo: " << text->xo_ << "..." << text->xo_ + text->width
-               //      << " yo: " << text->yo_ 
-               //      << " yo: " << text->yo_ - text->ascent() << "..."
-               //              <<  text->yo_ + text->descent()
-               //      << std::endl;   
-               if (x >= text->xo_
-                               && x <= text->xo_ + text->width
-                               && y >= text->yo_ 
-                               && y <= text->yo_ + text->height)
-               {
-                       lyxerr << "### found text # " << i << std::endl;        
-                       return i;
-               }
-       }
-       return -1;
-}
-
-
-bool isEditableInset(InsetOld const * i)
-{
-       return i && i->editable();
-}
-
-
-bool isHighlyEditableInset(InsetOld const * i)
-{
-       return i && i->editable() == InsetOld::HIGHLY_EDITABLE;
-}
-
-
index 1f54edfcba496d0533b29f2877254f40a6ff9b16..3d75481725e43a59d8bf62c4bc12231027bda3c8 100644 (file)
 #include "insetbase.h"
 #include "dimension.h"
 
 #include "insetbase.h"
 #include "dimension.h"
 
-class Buffer;
 class LColor_color;
 class LColor_color;
-class FuncRequest;
-class OutputParams;
-class CursorSlice;
-class LyXLex;
-class LyXText;
-class Painter;
-class Paragraph;
 class UpdatableInset;
 
 class UpdatableInset;
 
-namespace lyx {
-namespace graphics {
-       class PreviewLoader;
-}
-}
-
 
 /// Insets
 class InsetOld : public InsetBase {
 
 /// Insets
 class InsetOld : public InsetBase {
@@ -45,16 +31,6 @@ public:
                TEXT_TO_INSET_OFFSET = 2
        };
 
                TEXT_TO_INSET_OFFSET = 2
        };
 
-       ///
-       enum EDITABLE {
-               ///
-               NOT_EDITABLE = 0,
-               ///
-               IS_EDITABLE,
-               ///
-               HIGHLY_EDITABLE
-       };
-
        ///
        InsetOld();
        ///
        ///
        InsetOld();
        ///
@@ -65,39 +41,6 @@ public:
        int descent() const;
        ///
        int width() const;
        int descent() const;
        ///
        int width() const;
-       /// what appears in the minibuffer when opening
-       virtual std::string const editMessage() const;
-       ///
-       virtual EDITABLE editable() const;
-       /// can we go further down on mouse click?
-       virtual bool descendable() const { return false; }
-       ///
-       virtual bool isTextInset() const { return false; }
-       /// return true if the inset should be removed automatically
-       virtual bool autoDelete() const;
-       /// returns true the inset can hold an inset of given type
-       virtual bool insetAllowed(InsetOld::Code) const { return false; }
-       /// wrapper around the above
-       bool insetAllowed(InsetOld * in) const;
-       ///
-       virtual void write(Buffer const &, std::ostream &) const = 0;
-       ///
-       virtual void read(Buffer const &, LyXLex & lex) = 0;
-       /// returns the number of rows (\n's) of generated tex code.
-       virtual int latex(Buffer const &, std::ostream &,
-                         OutputParams const &) const = 0;
-       ///
-       virtual int plaintext(Buffer const &, std::ostream &,
-                         OutputParams const &) const = 0;
-       ///
-       virtual int linuxdoc(Buffer const &, std::ostream &,
-                            OutputParams const &) const = 0;
-       ///
-       virtual int docbook(Buffer const &, std::ostream &,
-                           OutputParams const &) const = 0;
-
-       /// returns true to override begin and end inset in file
-       virtual bool directWrite() const;
 
        ///
        void setInsetName(std::string const & s) { name_ = s; }
 
        ///
        void setInsetName(std::string const & s) { name_ = s; }
@@ -118,52 +61,8 @@ public:
        /// returns the actual scroll-value
        virtual int scroll(bool recursive = true) const;
 
        /// returns the actual scroll-value
        virtual int scroll(bool recursive = true) const;
 
-       /// if this insets owns text cells (e.g. InsetText) return cell num
-       virtual LyXText * getText(int /*num*/) const { return 0; }
        ///
        ///
-       virtual int numParagraphs() const { return 0; }
-       /// returns cell covering position (x,y), -1 if none exists
-       virtual int getCell(int x, int y) const;
-
-       /// used to toggle insets
-       // is the inset open?
-       virtual bool isOpen() const { return false; }
-       /// open the inset
-       virtual void open() {}
-       /// close the inset
-       virtual void close() {}
-       // should this inset be handled like a normal charater
-       virtual bool isChar() const { return false; }
-       // is this equivalent to a letter?
-       virtual bool isLetter() const { return false; }
-       // is this equivalent to a space (which is BTW different from
-       // a line separator)?
-       virtual bool isSpace() const { return false; }
-       // should we have a non-filled line before this inset?
-       virtual bool display() const { return false; }
-       // should we break lines after this inset?
-       virtual bool isLineSeparator() const { return false; }
-       // if this inset has paragraphs should they be output all as default
-       // paragraphs with "Standard" layout?
-       virtual bool forceDefaultParagraphs(InsetOld const *) const;
-       /** returns true if, when outputing LaTeX, font changes should
-           be closed before generating this inset. This is needed for
-           insets that may contain several paragraphs */
-       virtual bool noFontChange() const { return false; }
-
-       /// mark the inset contents as erased (for change tracking)
-       virtual void markErased() {}
-
-       /// does this inset allows spellchecking?
-       virtual bool allowSpellCheck() const { return true; }
-
-       /** Adds a LaTeX snippet to the Preview Loader for transformation
-        *  into a bitmap image. Does not start the laoding process.
-        *
-        *  Most insets have no interest in this capability, so the method
-        *  defaults to empty.
-        */
-       virtual void addPreview(lyx::graphics::PreviewLoader &) const {}
+       bool forceDefaultParagraphs(InsetBase const * inset) const;
 protected:
        ///
        mutable int xo_;
 protected:
        ///
        mutable int xo_;
@@ -197,18 +96,4 @@ public:
        operator InsetOld::Code() const { return val_; }
 };
 
        operator InsetOld::Code() const { return val_; }
 };
 
-
-/**
- * returns true if pointer argument is valid
- * and points to an editable inset
- */
-bool isEditableInset(InsetOld const * inset);
-
-
-/**
- * returns true if pointer argument is valid
- * and points to a highly editable inset
- */
-bool isHighlyEditableInset(InsetOld const * inset);
-
 #endif
 #endif
index 6602812e7841158a08fbd2277051b3358ae1529c..9e52e8639e157244aab00bc8d0424005f18c172d 100644 (file)
@@ -13,6 +13,8 @@
 #include "insetbase.h"
 #include "debug.h"
 #include "dispatchresult.h"
 #include "insetbase.h"
 #include "debug.h"
 #include "dispatchresult.h"
+#include "gettext.h"
+#include "lyxtext.h"
 
 
 DispatchResult InsetBase::dispatch(LCursor & cur, FuncRequest const & cmd)
 
 
 DispatchResult InsetBase::dispatch(LCursor & cur, FuncRequest const & cmd)
@@ -21,7 +23,7 @@ DispatchResult InsetBase::dispatch(LCursor & cur, FuncRequest const & cmd)
 }
 
 
 }
 
 
-DispatchResult InsetBase::priv_dispatch(LCursor &, FuncRequest const & cmd)
+DispatchResult InsetBase::priv_dispatch(LCursor &, FuncRequest const &)
 {
        return DispatchResult(false);
 }
 {
        return DispatchResult(false);
 }
@@ -38,3 +40,138 @@ void InsetBase::edit(LCursor & cur, int, int)
        lyxerr << "InsetBase: edit xy" << std::endl;
        edit(cur, true);
 }
        lyxerr << "InsetBase: edit xy" << std::endl;
        edit(cur, true);
 }
+
+
+InsetBase::idx_type InsetBase::index(row_type row, col_type col) const
+{
+       if (row != 0)
+               lyxerr << "illegal row: " << row << std::endl;
+       if (col != 0)
+               lyxerr << "illegal col: " << col << std::endl;
+       return 0;
+}
+
+
+bool InsetBase::idxBetween(idx_type idx, idx_type from, idx_type to) const
+{
+       return from <= idx && idx <= to;
+}
+
+
+bool InsetBase::idxUpDown(LCursor &, bool) const
+{
+       return false;
+}
+
+
+bool InsetBase::idxUpDown2(LCursor &, bool) const
+{
+       return false;
+}
+
+
+void InsetBase::getScreenPos(idx_type, pos_type, int & x, int & y) const
+{
+       lyxerr << "InsetBase::getScreenPos() called directly!" << std::endl;
+       x = y = 0;
+}
+
+
+int InsetBase::plaintext(Buffer const &,
+       std::ostream &, OutputParams const &) const
+{
+       return 0;
+}
+
+
+int InsetBase::linuxdoc(Buffer const &,
+       std::ostream &, OutputParams const &) const
+{
+       return 0;
+}
+
+
+int InsetBase::docbook(Buffer const &,
+       std::ostream &, OutputParams const &) const
+{
+       return 0;
+}
+
+
+bool InsetBase::directWrite() const
+{
+       return false;
+}
+
+
+InsetBase::EDITABLE InsetBase::editable() const
+{
+       return NOT_EDITABLE;
+}
+
+
+bool InsetBase::autoDelete() const
+{
+       return false;
+}
+
+
+std::string const InsetBase::editMessage() const
+{
+       return _("Opened inset");
+}
+
+
+bool InsetBase::insetAllowed(InsetBase * inset) const
+{
+       return insetAllowed(inset->lyxCode());
+}
+
+
+std::string const & InsetBase::getInsetName() const
+{
+       static std::string const name = "unknown";
+       return name;
+}
+
+
+int InsetBase::getCell(int x, int y) const
+{
+       for (int i = 0, n = numParagraphs(); i < n; ++i) {
+               LyXText * text = getText(i);
+               //lyxerr << "### text: " << text << " i: " << i
+               //      << " xo: " << text->xo_ << "..." << text->xo_ + text->width
+               //      << " yo: " << text->yo_ 
+               //      << " yo: " << text->yo_ - text->ascent() << "..."
+               //              <<  text->yo_ + text->descent()
+               //      << std::endl;   
+               if (x >= text->xo_
+                               && x <= text->xo_ + text->width
+                               && y >= text->yo_ 
+                               && y <= text->yo_ + text->height)
+               {
+                       lyxerr << "### found text # " << i << std::endl;        
+                       return i;
+               }
+       }
+       return -1;
+}
+
+
+void InsetBase::markErased()
+{}
+
+/////////////////////////////////////////
+
+bool isEditableInset(InsetBase const * i)
+{
+       return i && i->editable();
+}
+
+
+bool isHighlyEditableInset(InsetBase const * i)
+{
+       return i && i->editable() == InsetBase::HIGHLY_EDITABLE;
+}
+
+
index 0702a5f85eec2f177bdb3bd023f49f58cbfff858..0e0219bec86f34762ad3d17a9df60b8cf3e850f9 100644 (file)
@@ -22,13 +22,24 @@ class DispatchResult;
 class FuncRequest;
 class LaTeXFeatures;
 class LCursor;
 class FuncRequest;
 class LaTeXFeatures;
 class LCursor;
+class LyXLex;
+class LyXText;
 class MathInset;
 class MetricsInfo;
 class Dimension;
 class PainterInfo;
 class MathInset;
 class MetricsInfo;
 class Dimension;
 class PainterInfo;
+class OutputParams;
 class UpdatableInset;
 
 class UpdatableInset;
 
+namespace lyx { namespace graphics { class PreviewLoader; } }
+
+
 /// Common base class to all insets
 /// Common base class to all insets
+
+// Do not add _any_ (non-static) data members as this would inflate
+// everything storing large quantities of insets. Mathed e.g. would
+// suffer.
+
 class InsetBase {
 public:
        ///
 class InsetBase {
 public:
        ///
@@ -71,27 +82,104 @@ public:
        /// last drawn position for 'important' insets
        virtual int y() const { return 0; }
  
        /// last drawn position for 'important' insets
        virtual int y() const { return 0; }
  
+       /// is this an inset that can be moved into?
+       virtual bool isActive() const { return nargs() > 0; }
+       /// Where should we go when we press the up or down cursor key?
+       virtual bool idxUpDown(LCursor & cur, bool up) const;
+       /// Where should we go when we press the up or down cursor key?
+       virtual bool idxUpDown2(LCursor & cur, bool up) const;
+       /// Move one cell to the left
+       virtual bool idxLeft(LCursor &) const { return false; }
+       /// Move one cell to the right
+       virtual bool idxRight(LCursor &) const { return false; }
+
+       /// Move one physical cell up
+       virtual bool idxNext(LCursor &) const { return false; }
+       /// Move one physical cell down
+       virtual bool idxPrev(LCursor &) const { return false; }
+
+       /// Target pos when we enter the inset from the left by pressing "Right"
+       virtual bool idxFirst(LCursor &) const { return false; }
+       /// Target pos when we enter the inset from the right by pressing "Left"
+       virtual bool idxLast(LCursor &) const { return false; }
+
+       /// Where should we go if we press home?
+       virtual bool idxHome(LCursor &) const { return false; }
+       /// Where should we go if we press end?
+       virtual bool idxEnd(LCursor &) const { return false; }
+
+       /// Delete a cell and move cursor
+       virtual bool idxDelete(idx_type &) { return false; }
+       /// pulls cell after pressing erase
+       virtual void idxGlue(idx_type) {}
+       // returns list of cell indices that are "between" from and to for
+       // selection purposes
+       virtual bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
+
+       /// to which column belongs a cell with a given index?
+       virtual col_type col(idx_type) const { return 0; }
+       /// to which row belongs a cell with a given index?
+       virtual row_type row(idx_type) const { return 0; }
+       /// cell idex corresponding to row and column;
+       virtual idx_type index(row_type row, col_type col) const;
+       /// any additional x-offset when drawing a cell?
+       virtual int cellXOffset(idx_type) const { return 0; }
+       /// any additional y-offset when drawing a cell?
+       virtual int cellYOffset(idx_type) const { return 0; }
+       /// can we enter this cell?
+       virtual bool validCell(idx_type) const { return true; }
+       /// get coordinates
+       virtual void getScreenPos(idx_type idx, pos_type pos, int & x, int & y) const;
        /// number of embedded cells
        virtual size_t nargs() const { return 0; }
        /// number of rows in gridlike structures
        virtual size_t nrows() const { return 0; }
        /// number of columns in gridlike structures
        virtual size_t ncols() const { return 0; }
        /// number of embedded cells
        virtual size_t nargs() const { return 0; }
        /// number of rows in gridlike structures
        virtual size_t nrows() const { return 0; }
        /// number of columns in gridlike structures
        virtual size_t ncols() const { return 0; }
+       /// is called when the cursor leaves this inset
+       virtual void notifyCursorLeaves(idx_type) {}
 
        /// 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 {}
 
        /// 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 {}
        /// 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(LCursor & cur, FuncRequest const & cmd);
-public:
+
+       /// plain ascii output
+       virtual int plaintext(Buffer const &, std::ostream & os,
+               OutputParams const &) const;
+       /// linuxdoc output
+       virtual int linuxdoc(Buffer const &, std::ostream & os,
+               OutputParams const &) const;
+       /// docbook output
+       virtual int docbook(Buffer const &, std::ostream & os,
+               OutputParams const &) const;
+
+       ///
+       enum EDITABLE {
+               ///
+               NOT_EDITABLE = 0,
+               ///
+               IS_EDITABLE,
+               ///
+               HIGHLY_EDITABLE
+       };
+       /// what appears in the minibuffer when opening
+       virtual std::string const editMessage() const;
+       ///
+       virtual EDITABLE editable() const;
+       /// can we go further down on mouse click?
+       virtual bool descendable() const { return false; }
+       ///
+       virtual bool isTextInset() const { return false; }
+       /// return true if the inset should be removed automatically
+       virtual bool autoDelete() const;
+
        /** 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
        /** 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
@@ -193,9 +281,102 @@ public:
                ///
                MATHHULL_CODE
        };
                ///
                MATHHULL_CODE
        };
+       /// returns true the inset can hold an inset of given type
+       virtual bool insetAllowed(Code) const { return false; }
+       /// wrapper around the above
+       bool insetAllowed(InsetBase * inset) const;
+       // if this inset has paragraphs should they be output all as default
+       // paragraphs with "Standard" layout?
+       virtual bool forceDefaultParagraphs(InsetBase const *) const { return false; }
+       ///
+       virtual std::string const & getInsetName() const;
+       /// used to toggle insets
+       // is the inset open?
+       virtual bool isOpen() const { return false; }
+       /// open the inset
+       virtual void open() {}
+       /// close the inset
+       virtual void close() {}
+       // should this inset be handled like a normal charater
+       virtual bool isChar() const { return false; }
+       // is this equivalent to a letter?
+       virtual bool isLetter() const { return false; }
+       // is this equivalent to a space (which is BTW different from
+       // a line separator)?
+       virtual bool isSpace() const { return false; }
+       // should we have a non-filled line before this inset?
+       virtual bool display() const { return false; }
+       // should we break lines after this inset?
+       virtual bool isLineSeparator() const { return false; }
+       ///
+       virtual void write(Buffer const &, std::ostream &) const {}
+       ///
+       virtual void read(Buffer const &, LyXLex &) {}
+       /// returns the number of rows (\n's) of generated tex code.
+       virtual int latex(Buffer const &, std::ostream &,
+                         OutputParams const &) const { return 0; }
+       /// returns true to override begin and end inset in file
+       virtual bool directWrite() const;
+       ///
+       virtual bool allowSpellCheck() const { return false; }
+
+       /// if this insets owns text cells (e.g. InsetText) return cell num
+       virtual LyXText * getText(int /*num*/) const { return 0; }
+       ///
+       virtual int numParagraphs() const { return 0; }
+       /// returns cell covering position (x,y), -1 if none exists
+       virtual int getCell(int x, int y) const;
+
+       /** Adds a LaTeX snippet to the Preview Loader for transformation
+        *  into a bitmap image. Does not start the laoding process.
+        *
+        *  Most insets have no interest in this capability, so the method
+        *  defaults to empty.
+        */
+       virtual void addPreview(lyx::graphics::PreviewLoader &) const {}
+protected:
+       // the real dispatcher
+       virtual
+       DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+public:
        /// returns LyX code associated with the inset. Used for TOC, ...)
        /// returns LyX code associated with the inset. Used for TOC, ...)
-       virtual InsetBase::Code lyxCode() const { return NO_CODE; }
+       virtual Code lyxCode() const { return NO_CODE; }
+
+       /// -1: text mode, 1: math mode, 0 undecided
+       enum mode_type {UNDECIDED_MODE, TEXT_MODE, MATH_MODE};
+       /// return text or mathmode if that is possible to determine
+       virtual mode_type currentMode() const { return UNDECIDED_MODE; }
 
 
+       /// FIXME: This ought to die.
+       virtual void setOwner(UpdatableInset *) {}
+       ///
+       virtual UpdatableInset * owner() const { return 0; }
+
+       /// is this inset allowed within a font change?
+       virtual bool noFontChange() const { return false; }
+
+       ///
+       virtual void markErased();
+       /// pretty arbitrary
+       virtual int width() const { return 10; }
+       /// pretty arbitrary
+       virtual int ascent() const { return 10; }
+       /// pretty arbitrary
+       virtual int descent() const { return 10; }
 };
 
 };
 
+
+/**
+ * returns true if pointer argument is valid
+ * and points to an editable inset
+ */
+bool isEditableInset(InsetBase const * inset);
+
+
+/**
+ * returns true if pointer argument is valid
+ * and points to a highly editable inset
+ */
+bool isHighlyEditableInset(InsetBase const * inset);
+
 #endif
 #endif
index c237e73ced912a408a3a0ebe7f934f7b67637df8..dd2147ce5a786e46f5422d41235866db3f024281 100644 (file)
@@ -116,6 +116,8 @@ public:
        void setBackgroundColor(LColor_color);
        ///
        void setStatus(CollapseStatus st);
        void setBackgroundColor(LColor_color);
        ///
        void setStatus(CollapseStatus st);
+       ///
+       bool allowSpellCheck() const { return true; }
 
 protected:
        ///
 
 protected:
        ///
index 2782a64d52b871209b5fb239f3178988f042d0c1..d17fdc2558f5f72f53ecf4ddf12e756dd702cccf 100644 (file)
@@ -71,7 +71,7 @@ public:
        ///
        void getDrawFont(LyXFont &) const;
        ///
        ///
        void getDrawFont(LyXFont &) const;
        ///
-       bool forceDefaultParagraphs(InsetOld const *) const { return true; }
+       bool forceDefaultParagraphs(InsetBase const *) const { return true; }
 protected:
        ///
        virtual
 protected:
        ///
        virtual
index 942ba6b3353d0f0e48c02b75a7d6181a152a5f02..cbbd10371ec1151fe988d086be5dec4c3950ead5 100644 (file)
@@ -12,6 +12,7 @@
 #include "insetref.h"
 
 #include "buffer.h"
 #include "insetref.h"
 
 #include "buffer.h"
+#include "cursor.h"
 #include "BufferView.h"
 #include "dispatchresult.h"
 #include "funcrequest.h"
 #include "BufferView.h"
 #include "dispatchresult.h"
 #include "funcrequest.h"
index 583b83efd40d556183416dd948673f4ffc019987..b676d8d66d0a8e52f74c21263581e7befb8af7c4 100644 (file)
@@ -1985,7 +1985,7 @@ void InsetTabular::markErased()
 }
 
 
 }
 
 
-bool InsetTabular::forceDefaultParagraphs(InsetOld const * in) const
+bool InsetTabular::forceDefaultParagraphs(InsetBase const * in) const
 {
        const int cell = tabular.getCellFromInset(in);
 
 {
        const int cell = tabular.getCellFromInset(in);
 
index 1849f8b407ff4e045ce77247a41063b50523333f..b4658d087e0ec0c09315ee134fa00c9d95fa0c23 100644 (file)
@@ -134,7 +134,7 @@ public:
 
        // this should return true if we have a "normal" cell, otherwise true.
        // "normal" means without width set!
 
        // this should return true if we have a "normal" cell, otherwise true.
        // "normal" means without width set!
-       bool forceDefaultParagraphs(InsetOld const * in) const;
+       bool forceDefaultParagraphs(InsetBase const * in) const;
 
        ///
        void addPreview(lyx::graphics::PreviewLoader &) const;
 
        ///
        void addPreview(lyx::graphics::PreviewLoader &) const;
index e9e40d78044e597ef39cd67264dfdb2ab2c0f5dc..ebd8958d5936fc012f77b781661db30cbc3614de 100644 (file)
@@ -166,7 +166,7 @@ LyXText * ParIterator::text(Buffer & buf) const
 }
 
 
 }
 
 
-InsetOld * ParIterator::inset() const
+InsetBase * ParIterator::inset() const
 {
        //lyxerr << "positions.size: " << pimpl_->positions.size() << std::endl;
        if (pimpl_->positions.size() <= 1)
 {
        //lyxerr << "positions.size: " << pimpl_->positions.size() << std::endl;
        if (pimpl_->positions.size() <= 1)
@@ -385,7 +385,7 @@ ParIterator::ParIterator(PosIterator const & pos)
                PosIteratorItem const & it = pos.stack_[i];
                ParPosition pp(it.pit, *it.pl);
                if (i < size - 1) {
                PosIteratorItem const & it = pos.stack_[i];
                ParPosition pp(it.pit, *it.pl);
                if (i < size - 1) {
-                       InsetOld * inset = it.pit->getInset(it.pos);
+                       InsetBase * inset = it.pit->getInset(it.pos);
                        BOOST_ASSERT(inset);
                        InsetList::iterator beg = it.pit->insetlist.begin();
                        InsetList::iterator end = it.pit->insetlist.end();
                        BOOST_ASSERT(inset);
                        InsetList::iterator beg = it.pit->insetlist.begin();
                        InsetList::iterator end = it.pit->insetlist.end();
index 7d0e0cc4102676339eaafa47ce4d38f90928d7d5..22dec98f17a21c9596c87c71bd3df7ffb8097dd4 100644 (file)
@@ -18,7 +18,7 @@
 #include <boost/scoped_ptr.hpp>
 
 class LyXText;
 #include <boost/scoped_ptr.hpp>
 
 class LyXText;
-class InsetOld;
+class InsetBase;
 class Cursor;
 class Buffer;
 class BufferView;
 class Cursor;
 class Buffer;
 class BufferView;
@@ -52,7 +52,7 @@ public:
        /// returns 'innermost' LyXText
        LyXText * text(Buffer &) const;
        /// returns innermost inset
        /// returns 'innermost' LyXText
        LyXText * text(Buffer &) const;
        /// returns innermost inset
-       InsetOld * inset() const;
+       InsetBase * inset() const;
        /// returns index of cell in innermost inset
        int index() const;
        ///
        /// returns index of cell in innermost inset
        int index() const;
        ///
index 1cfdc86a48597481d8d2c6cc85db613c62136de7..c17cb344957f4e1b6eb87edbf67b966375dc0c20 100644 (file)
@@ -391,7 +391,7 @@ int replace(BufferView * bv,
 
        text->replaceSelectionWithString(replacestr);
        text->setSelectionRange(replacestr.length());
 
        text->replaceSelectionWithString(replacestr);
        text->setSelectionRange(replacestr.length());
-       bv->cursor().current() = fw ? bv->cursor().selEnd() : bv->cursor().selStart();
+       bv->cursor().current() = fw ? bv->cursor().selEnd() : bv->cursor().selBegin();
        bv->buffer()->markDirty();
        find(bv, searchstr, cs, mw, fw);
        bv->update();
        bv->buffer()->markDirty();
        find(bv, searchstr, cs, mw, fw);
        bv->update();
index 63607907f6ce5b0b9595692f8a9e891d933c5aa8..2c503cfdba7560153e28adf3c381c3aa3cef2e33 100644 (file)
@@ -63,8 +63,6 @@
 #include "insets/insetvspace.h"
 #include "insets/insetwrap.h"
 
 #include "insets/insetvspace.h"
 #include "insets/insetwrap.h"
 
-#include "mathed/math_cursor.h"
-
 #include "frontends/Alert.h"
 #include "frontends/Dialogs.h"
 #include "frontends/FileDialog.h"
 #include "frontends/Alert.h"
 #include "frontends/Dialogs.h"
 #include "frontends/FileDialog.h"
@@ -162,8 +160,7 @@ void LyXFunc::handleKeyFunc(kb_action action)
 }
 
 
 }
 
 
-void LyXFunc::processKeySym(LyXKeySymPtr keysym,
-                           key_modifier::state state)
+void LyXFunc::processKeySym(LyXKeySymPtr keysym, key_modifier::state state)
 {
        string argument;
 
 {
        string argument;
 
@@ -343,7 +340,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                if (tab && tab->hasSelection())
                        disable = false;
                else
                if (tab && tab->hasSelection())
                        disable = false;
                else
-                       disable = !inMathed() && !view()->cursor().selection();
+                       disable = !view()->cursor().inMathed() && !view()->cursor().selection();
                break;
 
        case LFUN_RUNCHKTEX:
                break;
 
        case LFUN_RUNCHKTEX:
@@ -379,7 +376,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
 
        case LFUN_TABULAR_FEATURE:
 #if 0
 
        case LFUN_TABULAR_FEATURE:
 #if 0
-               if (inMathed()) {
+               if (view()->cursor().inMathed()) {
                        // FIXME: check temporarily disabled
                        // valign code
                        char align = mathcursor::valign();
                        // FIXME: check temporarily disabled
                        // valign code
                        char align = mathcursor::valign();
@@ -511,7 +508,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
        }
 
        case LFUN_MATH_MUTATE:
        }
 
        case LFUN_MATH_MUTATE:
-               if (inMathed())
+               if (view()->cursor().inMathed())
                        //flag.setOnOff(mathcursor::formula()->hullType() == ev.argument);
                        flag.setOnOff(false);
                else
                        //flag.setOnOff(mathcursor::formula()->hullType() == ev.argument);
                        flag.setOnOff(false);
                else
@@ -525,7 +522,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
        case LFUN_MATH_NONUMBER:
        case LFUN_MATH_NUMBER:
        case LFUN_MATH_EXTERN:
        case LFUN_MATH_NONUMBER:
        case LFUN_MATH_NUMBER:
        case LFUN_MATH_EXTERN:
-               disable = !inMathed();
+               disable = !view()->cursor().inMathed();
                break;
 
        case LFUN_DIALOG_SHOW: {
                break;
 
        case LFUN_DIALOG_SHOW: {
@@ -684,13 +681,13 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                break;
        case LFUN_SPACE_INSERT:
                // slight hack: we know this is allowed in math mode
                break;
        case LFUN_SPACE_INSERT:
                // slight hack: we know this is allowed in math mode
-               if (!inMathed())
+               if (!view()->cursor().inMathed())
                        code = InsetOld::SPACE_CODE;
                break;
        case LFUN_INSET_DIALOG_SHOW: {
                        code = InsetOld::SPACE_CODE;
                break;
        case LFUN_INSET_DIALOG_SHOW: {
-               InsetOld * inset = view()->getLyXText()->getInset();
+               InsetBase * inset = view()->getLyXText()->getInset();
                disable = !inset;
                disable = !inset;
-               if (!disable) {
+               if (inset) {
                        code = inset->lyxCode();
                        if (!(code == InsetOld::INCLUDE_CODE
                                || code == InsetOld::BIBTEX_CODE
                        code = inset->lyxCode();
                        if (!(code == InsetOld::INCLUDE_CODE
                                || code == InsetOld::BIBTEX_CODE
@@ -736,7 +733,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
 
 #ifdef LOCK
        // the font related toggles
 
 #ifdef LOCK
        // the font related toggles
-       if (!inMathed()) {
+       if (!view()->cursor().inMathed()) {
                LyXFont const & font = view()->getLyXText()->real_current_font;
                switch (ev.action) {
                case LFUN_EMPH:
                LyXFont const & font = view()->getLyXText()->real_current_font;
                switch (ev.action) {
                case LFUN_EMPH:
@@ -1289,7 +1286,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                        break;
 
                case LFUN_INSET_DIALOG_SHOW: {
                        break;
 
                case LFUN_INSET_DIALOG_SHOW: {
-                       InsetOld * inset = view()->getLyXText()->getInset();
+                       InsetBase * inset = view()->getLyXText()->getInset();
                        if (inset)
                                inset->dispatch(view()->cursor(), FuncRequest(LFUN_INSET_DIALOG_SHOW));
                        break;
                        if (inset)
                                inset->dispatch(view()->cursor(), FuncRequest(LFUN_INSET_DIALOG_SHOW));
                        break;
index ee0f9e116bc644d42d89accdbd320cb1a8860e22..880f9002c21314677a8cbb2936206e768de115fb 100644 (file)
 
 #include "bufferview_funcs.h"
 #include "Bidi.h"
 
 #include "bufferview_funcs.h"
 #include "Bidi.h"
-#include "layout.h"
+#include "dispatchresult.h"
 #include "lyxfont.h"
 #include "lyxfont.h"
-#include "lyxtextclass.h"
+#include "layout.h"
+#include "lyxlayout_ptr_fwd.h"
 #include "ParagraphList_fwd.h"
 #include "RowList_fwd.h"
 
 #include "ParagraphList_fwd.h"
 #include "RowList_fwd.h"
 
-#include "insets/inset.h"
-
 #include <iosfwd>
 
 class Buffer;
 class BufferParams;
 class BufferView;
 #include <iosfwd>
 
 class Buffer;
 class BufferParams;
 class BufferView;
+class CursorSlice;
 class Dimension;
 class Dimension;
+class InsetBase;
+class InsetOld_code;
+class FuncRequest;
 class LColor_color;
 class LColor_color;
-class CursorSlice;
+class LCursor;
+class LyXTextClass;
 class MetricsInfo;
 class MetricsInfo;
+class PainterInfo;
 class Paragraph;
 class Row;
 class Spacing;
 class Paragraph;
 class Row;
 class Spacing;
@@ -112,7 +117,7 @@ public:
          */
        void insertChar(char c);
        ///
          */
        void insertChar(char c);
        ///
-       void insertInset(InsetOld * inset);
+       void insertInset(InsetBase * inset);
 
        /// a full rebreak of the whole text
        void fullRebreak();
 
        /// a full rebreak of the whole text
        void fullRebreak();
@@ -163,7 +168,7 @@ public:
        /// just selects the word the cursor is in
        void selectWord(lyx::word_location loc);
        /// returns the inset at cursor (if it exists), 0 otherwise
        /// just selects the word the cursor is in
        void selectWord(lyx::word_location loc);
        /// returns the inset at cursor (if it exists), 0 otherwise
-       InsetOld * getInset() const;
+       InsetBase * getInset() const;
 
        /// accept selected change
        void acceptChange();
 
        /// accept selected change
        void acceptChange();
@@ -278,13 +283,13 @@ public:
        void insertStringAsParagraphs(std::string const & str);
 
        /// Find next inset of some specified type.
        void insertStringAsParagraphs(std::string const & str);
 
        /// Find next inset of some specified type.
-       bool gotoNextInset(std::vector<InsetOld::Code> const & codes,
+       bool gotoNextInset(std::vector<InsetOld_code> const & codes,
                           std::string const & contents = std::string());
        ///
                           std::string const & contents = std::string());
        ///
-       void gotoInset(std::vector<InsetOld::Code> const & codes,
+       void gotoInset(std::vector<InsetOld_code> const & codes,
                       bool same_content);
        ///
                       bool same_content);
        ///
-       void gotoInset(InsetOld::Code code, bool same_content);
+       void gotoInset(InsetOld_code code, bool same_content);
 
        /// current max text width
        int textWidth() const;
 
        /// current max text width
        int textWidth() const;
@@ -292,7 +297,7 @@ public:
        /// updates all counters
        void updateCounters();
        /// Returns an inset if inset was hit, or 0 if not.
        /// updates all counters
        void updateCounters();
        /// Returns an inset if inset was hit, or 0 if not.
-       InsetOld * checkInsetHit(int x, int y);
+       InsetBase * checkInsetHit(int x, int y);
 
        ///
        int singleWidth(ParagraphList::iterator pit, lyx::pos_type pos) const;
 
        ///
        int singleWidth(ParagraphList::iterator pit, lyx::pos_type pos) const;
index c400caeb2545b46f75898816660aa1528170b947..f7a2abadbd11c5ee2c8c808c0d035bbd5ef02f6f 100644 (file)
@@ -7,10 +7,6 @@ INCLUDES = -I$(srcdir)/../ $(BOOST_INCLUDES)
 libmathed_la_SOURCES = \
        textpainter.C \
        textpainter.h \
 libmathed_la_SOURCES = \
        textpainter.C \
        textpainter.h \
-       formulabase.C \
-       formulabase.h \
-       formula.C \
-       formula.h \
        formulamacro.C \
        formulamacro.h \
        math_amsarrayinset.C \
        formulamacro.C \
        formulamacro.h \
        math_amsarrayinset.C \
@@ -39,8 +35,6 @@ libmathed_la_SOURCES = \
        math_colorinset.h \
        math_commentinset.C \
        math_commentinset.h \
        math_colorinset.h \
        math_commentinset.C \
        math_commentinset.h \
-       math_cursor.C \
-       math_cursor.h \
        math_data.C \
        math_data.h \
        math_decorationinset.C \
        math_data.C \
        math_data.h \
        math_decorationinset.C \
index 938990da2573a7fffffd898ebc23bca99f73c0ed..9544b1fb705a46b095399790819ac0f083d1e354 100644 (file)
@@ -9,16 +9,18 @@
  * Full author contact details are available in file CREDITS.
  */
 
  * Full author contact details are available in file CREDITS.
  */
 
+#if 0
 #include <config.h>
 
 #include "formula.h"
 #include <config.h>
 
 #include "formula.h"
-#include "math_cursor.h"
+#include "math_data.h"
 #include "math_parser.h"
 #include "math_hullinset.h"
 #include "math_mathmlstream.h"
 #include "textpainter.h"
 
 #include "BufferView.h"
 #include "math_parser.h"
 #include "math_hullinset.h"
 #include "math_mathmlstream.h"
 #include "textpainter.h"
 
 #include "BufferView.h"
+#include "cursor.h"
 #include "debug.h"
 #include "LColor.h"
 #include "lyx_main.h"
 #include "debug.h"
 #include "LColor.h"
 #include "lyx_main.h"
@@ -164,25 +166,13 @@ void InsetFormula::read(Buffer const &, LyXLex & lex)
 }
 
 
 }
 
 
-namespace {
-
-bool editing_inset(InsetFormula const * inset)
-{
-       return inMathed() &&
-               (const_cast<InsetFormulaBase const *>(mathcursor::formula()) ==
-                inset);
-}
-
-} // namespace anon
-
-
 void InsetFormula::draw(PainterInfo & pi, int x, int y) const
 {
        xo_ = x;
        yo_ = y;
 
        // The previews are drawn only when we're not editing the inset.
 void InsetFormula::draw(PainterInfo & pi, int x, int y) const
 {
        xo_ = x;
        yo_ = y;
 
        // The previews are drawn only when we're not editing the inset.
-       bool const use_preview = !editing_inset(this)
+       bool const use_preview = !pi.base.bv->cursor().isInside(this)
                && RenderPreview::activated()
                && preview_->previewReady();
 
                && RenderPreview::activated()
                && preview_->previewReady();
 
@@ -203,8 +193,8 @@ void InsetFormula::draw(PainterInfo & pi, int x, int y) const
                            != lcolor.getX11Name(LColor::background))
                        p.pain.fillRectangle(x, y - a, w, h, LColor::mathbg);
 
                            != lcolor.getX11Name(LColor::background))
                        p.pain.fillRectangle(x, y - a, w, h, LColor::mathbg);
 
-               if (editing_inset(this)) {
-                       mathcursor::drawSelection(pi);
+               if (!pi.base.bv->cursor().isInside(this)) {
+                       pi.base.bv->cursor().drawSelection(pi);
                        //p.pain.rectangle(x, y - a, w, h, LColor::mathframe);
                }
 
                        //p.pain.rectangle(x, y - a, w, h, LColor::mathframe);
                }
 
@@ -243,7 +233,7 @@ bool InsetFormula::insetAllowed(InsetOld::Code code) const
 
 void InsetFormula::metrics(MetricsInfo & m, Dimension & dim) const
 {
 
 void InsetFormula::metrics(MetricsInfo & m, Dimension & dim) const
 {
-       bool const use_preview = !editing_inset(this)
+       bool const use_preview = !m.base.bv->cursor().isInside(this)
                && RenderPreview::activated()
                && preview_->previewReady();
 
                && RenderPreview::activated()
                && preview_->previewReady();
 
@@ -308,3 +298,4 @@ void InsetFormula::generatePreview(Buffer const & buffer) const
        preview_->addPreview(snippet, buffer);
        preview_->startLoading(buffer);
 }
        preview_->addPreview(snippet, buffer);
        preview_->startLoading(buffer);
 }
+#endif
index add5fb14423d4e15c1d5c4a71dace86fabdb648e..1d3f654f8e01d6e9b810330931b6122a4c04a08b 100644 (file)
@@ -10,6 +10,7 @@
  * Full author contact details are available in file CREDITS.
  */
 
  * Full author contact details are available in file CREDITS.
  */
 
+#if 0
 #ifndef INSET_FORMULA_H
 #define INSET_FORMULA_H
 
 #ifndef INSET_FORMULA_H
 #define INSET_FORMULA_H
 
@@ -89,3 +90,4 @@ private:
        boost::scoped_ptr<RenderPreview> const preview_;
 };
 #endif
        boost::scoped_ptr<RenderPreview> const preview_;
 };
 #endif
+#endif
index 69a2ad36d1619a613b0bf40153c3d3087e73eaab..ec4a5addc4e981d4243db07b26a20a13452b5a84 100644 (file)
 #include <config.h>
 
 #include "formulamacro.h"
 #include <config.h>
 
 #include "formulamacro.h"
-#include "math_cursor.h"
 #include "math_macrotable.h"
 #include "math_macrotemplate.h"
 #include "math_mathmlstream.h"
 
 #include "math_macrotable.h"
 #include "math_macrotemplate.h"
 #include "math_mathmlstream.h"
 
+#include "BufferView.h"
+#include "cursor.h"
 #include "gettext.h"
 #include "LColor.h"
 #include "lyxlex.h"
 #include "gettext.h"
 #include "LColor.h"
 #include "lyxlex.h"
@@ -35,22 +36,22 @@ using std::auto_ptr;
 using std::ostream;
 
 
 using std::ostream;
 
 
+
 InsetFormulaMacro::InsetFormulaMacro()
 InsetFormulaMacro::InsetFormulaMacro()
-{
-       // inset name is inherited from Inset
-       setInsetName("unknown");
-}
+       : MathNestInset(2), name_("unknown")
+{}
 
 
 InsetFormulaMacro::InsetFormulaMacro
 
 
 InsetFormulaMacro::InsetFormulaMacro
-       (string const & name, int nargs, string const & type)
+               (string const & name, int nargs, string const & type)
+       : MathNestInset(2), name_(name)
 {
 {
-       setInsetName(name);
        MathMacroTable::create(MathAtom(new MathMacroTemplate(name, nargs, type)));
 }
 
 
 InsetFormulaMacro::InsetFormulaMacro(string const & s)
        MathMacroTable::create(MathAtom(new MathMacroTemplate(name, nargs, type)));
 }
 
 
 InsetFormulaMacro::InsetFormulaMacro(string const & s)
+       : MathNestInset(2), name_("unknown")
 {
        std::istringstream is(s);
        read(is);
 {
        std::istringstream is(s);
        read(is);
@@ -67,7 +68,7 @@ void InsetFormulaMacro::write(Buffer const &, ostream & os) const
 {
        os << "FormulaMacro ";
        WriteStream wi(os, false, false);
 {
        os << "FormulaMacro ";
        WriteStream wi(os, false, false);
-       par()->write(wi);
+       MathNestInset::write(wi);
 }
 
 
 }
 
 
@@ -75,7 +76,7 @@ int InsetFormulaMacro::latex(Buffer const &, ostream & os,
                             OutputParams const & runparams) const
 {
        WriteStream wi(os, runparams.moving_arg, true);
                             OutputParams const & runparams) const
 {
        WriteStream wi(os, runparams.moving_arg, true);
-       par()->write(wi);
+       MathNestInset::write(wi);
        return 2;
 }
 
        return 2;
 }
 
@@ -84,7 +85,7 @@ int InsetFormulaMacro::plaintext(Buffer const &, ostream & os,
                             OutputParams const &) const
 {
        WriteStream wi(os, false, true);
                             OutputParams const &) const
 {
        WriteStream wi(os, false, true);
-       par()->write(wi);
+       MathNestInset::write(wi);
        return 0;
 }
 
        return 0;
 }
 
@@ -112,7 +113,7 @@ void InsetFormulaMacro::read(Buffer const &, LyXLex & lex)
 void InsetFormulaMacro::read(std::istream & is)
 {
        auto_ptr<MathMacroTemplate> p(new MathMacroTemplate(is));
 void InsetFormulaMacro::read(std::istream & is)
 {
        auto_ptr<MathMacroTemplate> p(new MathMacroTemplate(is));
-       setInsetName(p->name());
+       name_ = p->name();
        MathMacroTable::create(MathAtom(p.release()));
        //metrics();
 }
        MathMacroTable::create(MathAtom(p.release()));
        //metrics();
 }
@@ -120,20 +121,24 @@ void InsetFormulaMacro::read(std::istream & is)
 
 string InsetFormulaMacro::prefix() const
 {
 
 string InsetFormulaMacro::prefix() const
 {
-       return bformat(_(" Macro: %1$s: "), getInsetName());
+       return bformat(_(" Macro: %1$s: "), name_);
 }
 
 
 void InsetFormulaMacro::metrics(MetricsInfo & mi, Dimension & dim) const
 {
 }
 
 
 void InsetFormulaMacro::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       par()->metrics(mi, dim_);
-       dim_.asc += 5;
-       dim_.des += 5;
-       dim_.wid += 10 + font_metrics::width(prefix(), mi.base.font);
+       MathNestInset::metrics(mi);
+       dim = cell(0).dim(); 
+       dim += cell(1).dim(); 
+       dim.asc += 5;
+       dim.des += 5;
+       dim.wid += 10 + font_metrics::width(prefix(), mi.base.font);
        dim = dim_;
 }
 
 
        dim = dim_;
 }
 
 
+#warning FIXME
+#if 0
 MathAtom const & InsetFormulaMacro::par() const
 {
        return MathMacroTable::provide(getInsetName());
 MathAtom const & InsetFormulaMacro::par() const
 {
        return MathMacroTable::provide(getInsetName());
@@ -144,12 +149,7 @@ MathAtom & InsetFormulaMacro::par()
 {
        return MathMacroTable::provide(getInsetName());
 }
 {
        return MathMacroTable::provide(getInsetName());
 }
-
-
-InsetOld::Code InsetFormulaMacro::lyxCode() const
-{
-       return InsetOld::MATHMACRO_CODE;
-}
+#endif
 
 
 void InsetFormulaMacro::draw(PainterInfo & p, int x, int y) const
 
 
 void InsetFormulaMacro::draw(PainterInfo & p, int x, int y) const
@@ -170,14 +170,17 @@ 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);
 
        pi.pain.fillRectangle(x, a, w, h, LColor::mathmacrobg);
        pi.pain.rectangle(x, a, w, h, LColor::mathframe);
 
-       if (inMathed() &&
-                       const_cast<InsetFormulaBase const *>(mathcursor::formula()) == this)
-               mathcursor::drawSelection(pi);
+       LCursor & cur = p.base.bv->cursor();
+       if (cur.isInside(this))
+               cur.drawSelection(pi);
 
        pi.pain.text(x + 2, y, prefix(), font);
 
        // formula
 
        pi.pain.text(x + 2, y, prefix(), font);
 
        // formula
+#warning FIXME
+#if 0
        par()->draw(pi, x + font_metrics::width(prefix(), p.base.font) + 5, y);
        xo_ = x;
        yo_ = y;
        par()->draw(pi, x + font_metrics::width(prefix(), p.base.font) + 5, y);
        xo_ = x;
        yo_ = y;
+#endif
 }
 }
index b13d26713e5a0b6958f2f1f7ee5aed2a6d0642ce..c0f674c96187624b852baf7469304194e100402d 100644 (file)
 #ifndef INSET_FORMULA_MACRO_H
 #define INSET_FORMULA_MACRO_H
 
 #ifndef INSET_FORMULA_MACRO_H
 #define INSET_FORMULA_MACRO_H
 
-#include "formulabase.h"
-
+#include "math_nestinset.h"
 
 class MathMacroTemplate;
 
 class MathMacroTemplate;
+class LyXLex;
+
 
 // An InsetFormulaMacro only knows its name and asks the global
 // MathMacroTable if it needs to know more.
 
 /// Main LyX Inset for defining math macros
 
 // An InsetFormulaMacro only knows its name and asks the global
 // MathMacroTable if it needs to know more.
 
 /// Main LyX Inset for defining math macros
-class InsetFormulaMacro : public InsetFormulaBase {
+class InsetFormulaMacro : public MathNestInset {
 public:
        ///
        InsetFormulaMacro();
        /// construct a macro hull from its name and the number of arguments
 public:
        ///
        InsetFormulaMacro();
        /// construct a macro hull from its name and the number of arguments
-       explicit InsetFormulaMacro(std::string const & name, int nargs, std::string const & t);
+       InsetFormulaMacro(std::string const & name, int nargs, std::string const & t);
        /// constructs a mocro from its LaTeX definition
        explicit InsetFormulaMacro(std::string const & s);
        ///
        /// constructs a mocro from its LaTeX definition
        explicit InsetFormulaMacro(std::string const & s);
        ///
@@ -53,18 +54,16 @@ public:
                    OutputParams const &) const;
 
        ///
                    OutputParams const &) const;
 
        ///
-       virtual std::auto_ptr<InsetBase> clone() const;
-       ///
-       InsetOld::Code lyxCode() const;
+       std::auto_ptr<InsetBase> clone() const;
        ///
        ///
-       MathAtom const & par() const;
-       ///
-       MathAtom & par();
+       InsetBase::Code lyxCode() const { return MATHMACRO_CODE; }
 private:
        ///
        void read(std::istream & is);
        /// prefix in inset
        std::string prefix() const;
 private:
        ///
        void read(std::istream & is);
        /// prefix in inset
        std::string prefix() const;
+       ///
+       std::string name_;
 };
 
 #endif
 };
 
 #endif
index 3d5a68b398fbe52372e583055c46e59ca2dfe26e..16a9acc1a8901d91cd4d32ca40b17796f9c05345 100644 (file)
@@ -37,7 +37,7 @@ auto_ptr<InsetBase> MathColorInset::clone() const
 void MathColorInset::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        cell(1).metrics(mi, dim);
 void MathColorInset::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        cell(1).metrics(mi, dim);
-       if (editing()) {
+       if (editing(mi.base.bv)) {
                FontSetChanger dummy(mi.base, "textnormal");
                cell(0).metrics(mi);
                dim  += cell(0).dim();
                FontSetChanger dummy(mi.base, "textnormal");
                cell(0).metrics(mi);
                dim  += cell(0).dim();
@@ -53,7 +53,7 @@ void MathColorInset::metrics(MetricsInfo & mi, Dimension & dim) const
 
 void MathColorInset::draw(PainterInfo & pi, int x, int y) const
 {
 
 void MathColorInset::draw(PainterInfo & pi, int x, int y) const
 {
-       if (editing()) {
+       if (editing(pi.base.bv)) {
                FontSetChanger dummy(pi.base, "textnormal");
                drawMarkers(pi, x, y);
                drawStrBlack(pi, x, y, "[");
                FontSetChanger dummy(pi.base, "textnormal");
                drawMarkers(pi, x, y);
                drawStrBlack(pi, x, y, "[");
index 028d213e5ab8207fb3f7d5c0a4df908730dea981..89d607f2633b666763a44a6aea63e41c2dcc0e7d 100644 (file)
@@ -11,7 +11,6 @@
 #include <config.h>
 
 #include "math_data.h"
 #include <config.h>
 
 #include "math_data.h"
-#include "math_cursor.h"
 #include "math_fontinset.h"
 #include "math_scriptinset.h"
 #include "math_mathmlstream.h"
 #include "math_fontinset.h"
 #include "math_scriptinset.h"
 #include "math_mathmlstream.h"
index 1645de6872eae5248e004126b77a5bd4be3799d3..f55f7fe8d402f212a06fe5c3b0b664607ea7b744 100644 (file)
@@ -32,12 +32,12 @@ bool MathFracbaseInset::idxLeft(LCursor &) const
 }
 
 
 }
 
 
-bool MathFracbaseInset::idxUpDown(LCursor & cur, bool up, int targetx) const
+bool MathFracbaseInset::idxUpDown(LCursor & cur, bool up) const
 {
        MathInset::idx_type target = !up; // up ? 0 : 1, since upper cell has idx 0
        if (cur.idx() == target)
                return false;
        cur.idx() = target;
 {
        MathInset::idx_type target = !up; // up ? 0 : 1, since upper cell has idx 0
        if (cur.idx() == target)
                return false;
        cur.idx() = target;
-       cur.pos() = cell(target).x2pos(targetx);
+       cur.pos() = cell(target).x2pos(cur.x_target());
        return true;
 }
        return true;
 }
index 03558bae28c3268457404595e8ca1af964b9d2e2..5339db82711a8b6c187f039bcf731845fadfe961 100644 (file)
@@ -20,7 +20,7 @@ public:
        ///
        MathFracbaseInset();
        ///
        ///
        MathFracbaseInset();
        ///
-       bool idxUpDown(LCursor &, bool up, int targetx) const;
+       bool idxUpDown(LCursor &, bool up) const;
        ///
        bool idxLeft(LCursor &) const;
        ///
        ///
        bool idxLeft(LCursor &) const;
        ///
index ae28abed661647f5f28b387fcb0ca30945a674d6..9909ee8ff1fc6083db5f357951aa73df3856487d 100644 (file)
@@ -755,7 +755,7 @@ int MathGridInset::cellYOffset(idx_type idx) const
 }
 
 
 }
 
 
-bool MathGridInset::idxUpDown(LCursor & cur, bool up, int targetx) const
+bool MathGridInset::idxUpDown(LCursor & cur, bool up) const
 {
        if (up) {
                if (cur.idx() < ncols())
 {
        if (up) {
                if (cur.idx() < ncols())
@@ -766,7 +766,7 @@ bool MathGridInset::idxUpDown(LCursor & cur, bool up, int targetx) const
                        return false;
                cur.idx() += ncols();
        }
                        return false;
                cur.idx() += ncols();
        }
-       cur.pos() = cur.cell().x2pos(targetx - cur.cell().xo());
+       cur.pos() = cur.cell().x2pos(cur.x_target() - cur.cell().xo());
        return true;
 }
 
        return true;
 }
 
index f7d0fb9e35204b02672904114cd5f95d63ef66f8..5fc1e513648ddb943f83799cf7a1b0954a1ff685 100644 (file)
@@ -145,7 +145,7 @@ public:
        row_type row(idx_type idx) const;
 
        ///
        row_type row(idx_type idx) const;
 
        ///
-       bool idxUpDown(LCursor &, bool up, int targetx) const;
+       bool idxUpDown(LCursor &, bool up) const;
        ///
        bool idxLeft(LCursor &) const;
        ///
        ///
        bool idxLeft(LCursor &) const;
        ///
index cb9b5e63b5a9326fad8face7eb863391b502df3d..781cfd08b42a997053d2dd6283372183529fefa5 100644 (file)
 
 #include <config.h>
 
 
 #include <config.h>
 
+#include "math_charinset.h"
+#include "math_data.h"
+#include "math_extern.h"
 #include "math_hullinset.h"
 #include "math_mathmlstream.h"
 #include "math_streamstr.h"
 #include "math_hullinset.h"
 #include "math_mathmlstream.h"
 #include "math_streamstr.h"
-#include "math_cursor.h"
 #include "math_support.h"
 #include "math_support.h"
-#include "math_extern.h"
-#include "math_charinset.h"
-#include "textpainter.h"
+
 #include "BufferView.h"
 #include "BufferView.h"
+#include "cursor.h"
 #include "dispatchresult.h"
 #include "debug.h"
 #include "funcrequest.h"
 #include "dispatchresult.h"
 #include "debug.h"
 #include "funcrequest.h"
@@ -26,6 +27,7 @@
 #include "LaTeXFeatures.h"
 #include "LColor.h"
 #include "lyxrc.h"
 #include "LaTeXFeatures.h"
 #include "LColor.h"
 #include "lyxrc.h"
+#include "textpainter.h"
 
 #include "frontends/Alert.h"
 
 
 #include "frontends/Alert.h"
 
@@ -66,7 +68,7 @@ namespace {
 
        // returns position of first relation operator in the array
        // used for "intelligent splitting"
 
        // returns position of first relation operator in the array
        // used for "intelligent splitting"
-       MathArray::size_type firstRelOp(MathArray const & ar)
+       size_t firstRelOp(MathArray const & ar)
        {
                for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it)
                        if ((*it)->isRelOp())
        {
                for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it)
                        if ((*it)->isRelOp())
@@ -110,6 +112,12 @@ namespace {
 MathHullInset::MathHullInset()
        : MathGridInset(1, 1), type_("none"), nonum_(1), label_(1)
 {
 MathHullInset::MathHullInset()
        : MathGridInset(1, 1), type_("none"), nonum_(1), label_(1)
 {
+       // This is needed as long the math parser is not re-entrant
+       initMath();
+       //lyxerr << "sizeof MathInset: " << sizeof(MathInset) << endl;
+       //lyxerr << "sizeof MetricsInfo: " << sizeof(MetricsInfo) << endl;
+       //lyxerr << "sizeof MathCharInset: " << sizeof(MathCharInset) << endl;
+       //lyxerr << "sizeof LyXFont: " << sizeof(LyXFont) << endl;
        setDefaults();
 }
 
        setDefaults();
 }
 
@@ -725,8 +733,8 @@ void MathHullInset::doExtern(LCursor & cur, FuncRequest const & func)
        if (getType() == "simple") {
                size_type pos = cur.cell().find_last(eq);
                MathArray ar;
        if (getType() == "simple") {
                size_type pos = cur.cell().find_last(eq);
                MathArray ar;
-               if (inMathed() && cur.selection()) {
-                       asArray(mathcursor::grabAndEraseSelection(cur), ar);
+               if (cur.inMathed() && cur.selection()) {
+                       asArray(cur.grabAndEraseSelection(), ar);
                } else if (pos == cur.cell().size()) {
                        ar = cur.cell();
                        lyxerr << "use whole cell: " << ar << endl;
                } else if (pos == cur.cell().size()) {
                        ar = cur.cell();
                        lyxerr << "use whole cell: " << ar << endl;
@@ -871,3 +879,509 @@ string MathHullInset::fileInsetLabel() const
 {
        return "Formula";
 }
 {
        return "Formula";
 }
+
+
+/////////////////////////////////////////////////////////////////////
+
+#include "formulamacro.h"
+#include "math_arrayinset.h"
+#include "math_data.h"
+#include "math_deliminset.h"
+#include "math_factory.h"
+#include "math_hullinset.h"
+#include "math_parser.h"
+#include "math_spaceinset.h"
+#include "math_support.h"
+#include "ref_inset.h"
+
+#include "BufferView.h"
+#include "bufferview_funcs.h"
+#include "cursor.h"
+#include "dispatchresult.h"
+#include "debug.h"
+#include "funcrequest.h"
+#include "gettext.h"
+#include "LColor.h"
+#include "lyxtext.h"
+#include "undo.h"
+
+#include "frontends/LyXView.h"
+#include "frontends/Dialogs.h"
+
+#include "support/std_sstream.h"
+#include "support/lstrings.h"
+#include "support/lyxlib.h"
+
+using lyx::support::atoi;
+using lyx::support::split;
+using lyx::support::token;
+
+using std::abs;
+using std::endl;
+using std::max;
+using std::istringstream;
+using std::ostringstream;
+
+
+namespace {
+
+// local global
+int first_x;
+int first_y;
+
+bool openNewInset(LCursor & cur, InsetBase * inset)
+{
+       if (!cur.bv().insertInset(inset)) {
+               delete inset;
+               return false;
+       }
+       inset->edit(cur, true);
+       return true;
+}
+
+
+} // namespace anon
+
+
+
+int MathHullInset::ylow() const
+{
+       return yo_ - dim_.asc;
+}
+
+
+int MathHullInset::yhigh() const
+{
+       return yo_ + dim_.des;
+}
+
+
+int MathHullInset::xlow() const
+{
+       return xo_;
+}
+
+
+int MathHullInset::xhigh() const
+{
+       return xo_ + dim_.wid;
+}
+
+
+// simply scrap this function if you want
+void MathHullInset::mutateToText()
+{
+#if 0
+       // translate to latex
+       ostringstream os;
+       latex(NULL, os, false, false);
+       string str = os.str();
+
+       // insert this text
+       LyXText * lt = view_->getLyXText();
+       string::const_iterator cit = str.begin();
+       string::const_iterator end = str.end();
+       for (; cit != end; ++cit)
+               view_->owner()->getIntl()->getTransManager().TranslateAndInsert(*cit, lt);
+
+       // remove ourselves
+       //view_->owner()->dispatch(LFUN_ESCAPE);
+#endif
+}
+
+
+void MathHullInset::handleFont
+       (LCursor & cur, string const & arg, string const & font)
+{
+       // this whole function is a hack and won't work for incremental font
+       // changes...
+       recordUndo(cur, Undo::ATOMIC);
+
+       if (cur.inset()->asMathInset()->name() == font)
+               cur.handleFont(font);
+       else {
+               cur.handleNest(createMathInset(font));
+               cur.insert(arg);
+       }
+}
+
+
+void MathHullInset::handleFont2(LCursor & cur, string const & arg)
+{
+       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));
+               cur.handleNest(at, 1);
+       }
+}
+
+
+string const MathHullInset::editMessage() const
+{
+       return _("Math editor mode");
+}
+
+
+void MathHullInset::insetUnlock(BufferView & bv)
+{
+       if (bv.cursor().inMathed()) {
+               if (bv.cursor().inMacroMode())
+                       bv.cursor().macroModeClose();
+               bv.cursor().releaseMathCursor();
+       }
+       if (bv.buffer())
+               generatePreview(*bv.buffer());
+       bv.update();
+}
+
+
+void MathHullInset::getCursorPos(BufferView & bv, int & x, int & y) const
+{
+       if (bv.cursor().inMathed()) {
+               bv.cursor().getScreenPos(x, y);
+               x = bv.cursor().targetX();
+               x -= xo_;
+               y -= yo_;
+               lyxerr << "MathHullInset::getCursorPos: " << x << ' ' << y << endl;
+       } else {
+               x = 0;
+               y = 0;
+               lyxerr << "getCursorPos - should not happen";
+       }
+}
+
+
+void MathHullInset::getCursorDim(int & asc, int & desc) const
+{
+       asc = 10;
+       desc = 2;
+       //math_font_max_dim(font_, asc, des);
+}
+
+
+DispatchResult
+MathHullInset::lfunMouseRelease(LCursor & cur, FuncRequest const & cmd)
+{
+       if (!cur.inMathed())
+               return DispatchResult(false);
+       cur.bv().update();
+       //lyxerr << "lfunMouseRelease: buttons: " << cmd.button() << endl;
+
+       if (cmd.button() == mouse_button::button3) {
+               // try to dispatch to enclosed insets first
+               if (!cur.dispatch(cmd).dispatched()) {
+                       // launch math panel for right mouse button
+                       lyxerr << "lfunMouseRelease: undispatched: " << cmd.button() << endl;
+                       cur.bv().owner()->getDialogs().show("mathpanel");
+               }
+               return DispatchResult(true, true);
+       }
+
+       if (cmd.button() == mouse_button::button2) {
+               MathArray ar;
+               asArray(cur.bv().getClipboard(), ar);
+               cur.selClear();
+               cur.setScreenPos(cmd.x + xo_, cmd.y + yo_);
+               cur.insert(ar);
+               cur.bv().update();
+               return DispatchResult(true, true);
+       }
+
+       if (cmd.button() == mouse_button::button1) {
+               // try to dispatch to enclosed insets first
+               cur.dispatch(cmd);
+               cur.bv().stuffClipboard(cur.grabSelection());
+               // try to set the cursor
+               //delete mathcursor;
+               //mathcursor = new MathCursor(bv, this, x == 0);
+               //metrics(bv);
+               //cur.setScreenPos(x + xo_, y + yo_);
+               return DispatchResult(true, true);
+       }
+
+       return DispatchResult(false);
+}
+
+
+DispatchResult
+MathHullInset::lfunMousePress(LCursor & cur, FuncRequest const & cmd)
+{
+       //lyxerr << "lfunMousePress: buttons: " << cmd.button() << endl;
+
+       if (!cur.inMathed() || cur.formula() != this) {
+               lyxerr[Debug::MATHED] << "re-create cursor" << endl;
+               cur.releaseMathCursor();
+               cur.idx() = 0;
+               //metrics(bv);
+               cur.setScreenPos(cmd.x + xo_, cmd.y + yo_);
+       }
+
+       if (cmd.button() == mouse_button::button3) {
+               cur.dispatch(cmd);
+               return DispatchResult(true, true);
+       }
+
+       if (cmd.button() == mouse_button::button1) {
+               first_x = cmd.x;
+               first_y = cmd.y;
+               cur.selClear();
+               cur.setScreenPos(cmd.x + xo_, cmd.y + yo_);
+               cur.dispatch(cmd);
+               return DispatchResult(true, true);
+       }
+
+       cur.bv().update();
+       return DispatchResult(true, true);
+}
+
+
+DispatchResult
+MathHullInset::lfunMouseMotion(LCursor & cur, FuncRequest const & cmd)
+{
+       if (!cur.inMathed())
+               return DispatchResult(true, true);
+
+       if (cur.dispatch(FuncRequest(cmd)).dispatched())
+               return DispatchResult(true, true);
+
+       // only select with button 1
+       if (cmd.button() != mouse_button::button1)
+               return DispatchResult(true, true);
+
+       if (abs(cmd.x - first_x) < 2 && abs(cmd.y - first_y) < 2)
+               return DispatchResult(true, true);
+
+       first_x = cmd.x;
+       first_y = cmd.y;
+
+       if (!cur.selection())
+               cur.selBegin();
+
+       cur.setScreenPos(cmd.x + xo_, cmd.y + yo_);
+       cur.bv().update();
+       return DispatchResult(true, true);
+}
+
+
+void MathHullInset::edit(LCursor & cur, bool left)
+{
+       lyxerr << "Called FormulaBase::edit" << endl;
+       cur.push(this);
+       cur.idx() = left ? 0 : cur.lastidx();
+       cur.pos() = left ? 0 : cur.lastpos();
+       cur.resetAnchor();
+}
+
+
+void MathHullInset::edit(LCursor & cur, int x, int y)
+{
+       lyxerr << "Called FormulaBase::EDIT with '" << x << ' ' << y << "'" << endl;
+       //metrics(bv);
+       cur.push(this);
+       //cur.idx() = left ? 0 : cur.lastidx();
+       cur.idx() = 0;
+       cur.idx() = 0;
+       cur.setScreenPos(x + xo_, y + yo_);
+       // if that is removed, we won't get the magenta box when entering an
+       // inset for the first time
+       cur.bv().update();
+}
+
+
+
+
+void MathHullInset::revealCodes(LCursor & cur) const
+{
+       if (!cur.inMathed())
+               return;
+       ostringstream os;
+       cur.info(os);
+       cur.bv().owner()->message(os.str());
+/*
+       // write something to the minibuffer
+       // translate to latex
+       cur.markInsert(bv);
+       ostringstream os;
+       write(NULL, os);
+       string str = os.str();
+       cur.markErase(bv);
+       string::size_type pos = 0;
+       string res;
+       for (string::iterator it = str.begin(); it != str.end(); ++it) {
+               if (*it == '\n')
+                       res += ' ';
+               else if (*it == '\0') {
+                       res += "  -X-  ";
+                       pos = it - str.begin();
+               }
+               else
+                       res += *it;
+       }
+       if (pos > 30)
+               res = res.substr(pos - 30);
+       if (res.size() > 60)
+               res = res.substr(0, 60);
+       bv.owner()->message(res);
+*/
+}
+
+
+InsetBase::Code MathHullInset::lyxCode() const
+{
+       return MATH_CODE;
+}
+
+
+/////////////////////////////////////////////////////////////////////
+
+
+#if 1
+bool MathHullInset::searchForward(BufferView *, string const &, bool, bool)
+{
+       return false;
+}
+
+#else
+bool MathHullInset::searchForward(BufferView * bv, string const & str,
+                                    bool, bool)
+{
+       return false;
+#ifdef WITH_WARNINGS
+#warning pretty ugly
+#endif
+       static MathHullInset * lastformula = 0;
+       static CursorBase current = CursorBase(ibegin(par().nucleus()));
+       static MathArray ar;
+       static string laststr;
+
+       if (lastformula != this || laststr != str) {
+               //lyxerr << "reset lastformula to " << this << endl;
+               lastformula = this;
+               laststr = str;
+               current = ibegin(par().nucleus());
+               ar.clear();
+               mathed_parse_cell(ar, str);
+       } else {
+               increment(current);
+       }
+       //lyxerr << "searching '" << str << "' in " << this << ar << endl;
+
+       for (CursorBase it = current; it != iend(par().nucleus()); increment(it)) {
+               CursorSlice & top = it.back();
+               MathArray const & a = top.asMathInset()->cell(top.idx_);
+               if (a.matchpart(ar, top.pos_)) {
+                       bv->cursor().setSelection(it, ar.size());
+                       current = it;
+                       top.pos_ += ar.size();
+                       bv->update();
+                       return true;
+               }
+       }
+
+       //lyxerr << "not found!" << endl;
+       lastformula = 0;
+       return false;
+}
+#endif
+
+
+bool MathHullInset::searchBackward(BufferView * bv, string const & what,
+                                     bool a, bool b)
+{
+       lyxerr[Debug::MATHED] << "searching backward not implemented in mathed" << endl;
+       return searchForward(bv, what, a, b);
+}
+
+
+void mathDispatchCreation(LCursor & cur, FuncRequest const & cmd,
+       bool display)
+{
+       // use selection if available..
+       //string sel;
+       //if (action == LFUN_MATH_IMPORT_SELECTION)
+       //      sel = "";
+       //else
+
+       string sel =
+               cur.bv().getLyXText()->selectionAsString(*cur.bv().buffer(), false);
+
+       if (sel.empty()) {
+               InsetBase * f = new MathHullInset;
+               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(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
+               // formula otherwise
+               InsetBase * f;
+               if (sel.find("\\newcommand") == string::npos &&
+                               sel.find("\\def") == string::npos)
+                       f = new MathHullInset(sel);
+               else
+                       f = new InsetFormulaMacro(sel);
+               cur.bv().getLyXText()->cutSelection(true, false);
+               openNewInset(cur, f);
+       }
+       cmd.message(N_("Math editor mode"));
+}
+
+
+void mathDispatch(LCursor & cur, FuncRequest const & cmd)
+{
+       if (!cur.bv().available())
+               return;
+
+       switch (cmd.action) {
+
+               case LFUN_MATH_DISPLAY:
+                       mathDispatchCreation(cur, cmd, true);
+                       break;
+
+               case LFUN_MATH_MODE:
+                       mathDispatchCreation(cur, cmd, false);
+                       break;
+
+               case LFUN_MATH_IMPORT_SELECTION:
+                       mathDispatchCreation(cur, cmd, false);
+                       break;
+
+/*
+               case LFUN_MATH_MACRO:
+                       if (cmd.argument.empty())
+                               cmd.errorMessage(N_("Missing argument"));
+                       else {
+                               string s = cmd.argument;
+                               string const s1 = token(s, ' ', 1);
+                               int const nargs = s1.empty() ? 0 : atoi(s1);
+                               string const s2 = token(s, ' ', 2);
+                               string const type = s2.empty() ? "newcommand" : s2;
+                               openNewInset(cur, new InsetFormulaMacro(token(s, ' ', 0), nargs, s2));
+                       }
+                       break;
+
+               case LFUN_INSERT_MATH:
+               case LFUN_INSERT_MATRIX:
+               case LFUN_MATH_DELIM: {
+                       MathHullInset * f = new MathHullInset;
+                       if (openNewInset(cur, f)) {
+                               cur.inset()->dispatch(cur, FuncRequest(LFUN_MATH_MUTATE, "simple"));
+                               cur.inset()->dispatch(cur, cmd);
+                       }
+                       break;
+               }
+*/
+
+               default:
+                       break;
+       }
+}
index bd9858cfa844f615b2f0a465449dbac489b53d51..a951d77da276c205a5b08d53a4faf1128d0cc590 100644 (file)
@@ -47,8 +47,6 @@ public:
        ///
        bool numberedType() const;
        ///
        ///
        bool numberedType() const;
        ///
-       bool display() const;
-       ///
        bool ams() const;
        /// Appends \c list with all labels found within this inset.
        void getLabelList(Buffer const &,
        bool ams() const;
        /// Appends \c list with all labels found within this inset.
        void getLabelList(Buffer const &,
@@ -98,9 +96,7 @@ public:
 
 protected:
        ///
 
 protected:
        ///
-       virtual
-       DispatchResult
-       priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+       DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
        ///
        std::string eolString(row_type row, bool fragile) const;
 
        ///
        std::string eolString(row_type row, bool fragile) const;
 
@@ -132,6 +128,93 @@ private:
        std::vector<int> nonum_;
        ///
        std::vector<std::string> label_;
        std::vector<int> nonum_;
        ///
        std::vector<std::string> label_;
+
+//
+// Incorporate me
+//
+public:
+       /// lowest x coordinate
+       int xlow() const;
+       /// highest x coordinate
+       int xhigh() const;
+       /// lowest y coordinate
+       int ylow() const;
+       /// highest y coordinate
+       int yhigh() const;
+
+
+       /// what appears in the minibuffer when opening
+       virtual std::string const editMessage() const;
+       /// get the absolute document x,y of the cursor
+       virtual void getCursorPos(BufferView & bv, int & x, int & y) const;
+       ///
+       virtual void getCursorDim(int &, int &) const;
+       ///
+       virtual void insetUnlock(BufferView & bv);
+
+       /// To allow transparent use of math editing functions
+       //virtual void status(FuncRequest const &);
+
+       ///
+       virtual bool searchForward(BufferView *, std::string const &,
+                                  bool = true, bool = false);
+       ///
+       virtual bool searchBackward(BufferView *, std::string const &,
+                                   bool = true, bool = false);
+       ///
+       virtual bool isTextInset() const { return true; }
+       ///
+       virtual void mutateToText();
+       ///
+       virtual void revealCodes(LCursor & cur) const;
+       ///
+       virtual EDITABLE editable() const { return HIGHLY_EDITABLE; }
+       ///
+       bool display() const;
+       ///
+       void edit(LCursor & cur, bool);
+       ///
+       void edit(LCursor & cur, int, int);
+       ///
+       Code MathHullInset::lyxCode() const;
+
+private:
+       /// common base for handling accents
+       void handleAccent(BufferView & bv, std::string const & arg,
+               std::string const & name);
+
+       /// lfun handler
+       DispatchResult lfunMousePress(LCursor &, FuncRequest const &);
+       ///
+       DispatchResult lfunMouseRelease(LCursor &, FuncRequest const &);
+       ///
+       DispatchResult lfunMouseMotion(LCursor &, FuncRequest const &);
+       ///
+       int x() const { return xo_; }
+       ///
+       int y() const { return yo_; }
+       ///
+       int yo_;
+       ///
+       int xo_;
+
+protected:
+
+       /** Find the PreviewLoader, add a LaTeX snippet to it and
+        *  start the loading process.
+        *
+        *  Most insets have no interest in this capability, so the method
+        *  defaults to empty.
+        */
+       virtual void generatePreview(Buffer const &) const {}
+
+       ///
+       void handleFont(LCursor &, std::string const & arg, std::string const & font);
+       ///
+       void handleFont2(LCursor &, std::string const & arg);
 };
 
 };
 
+// We don't really mess want around with mathed stuff outside mathed.
+// So do it here.
+void mathDispatch(LCursor & cur, FuncRequest const & cmd);
 #endif
 #endif
index 33f2119d5006f8fe7bc98ea6abecdc6d126c48a7..0d25b777168dfba54a2811d7d8a1aa580f14a6aa 100644 (file)
@@ -21,12 +21,6 @@ using std::ostream;
 using std::endl;
 
 
 using std::endl;
 
 
-MathInset::size_type MathInset::nargs() const
-{
-       return 0;
-}
-
-
 MathArray dummyCell;
 
 MathArray & MathInset::cell(idx_type)
 MathArray dummyCell;
 
 MathArray & MathInset::cell(idx_type)
@@ -43,85 +37,10 @@ MathArray const & MathInset::cell(idx_type) const
 }
 
 
 }
 
 
-MathInset::idx_type MathInset::index(row_type row, col_type col) const
-{
-       if (row != 0)
-               lyxerr << "illegal row: " << row << endl;
-       if (col != 0)
-               lyxerr << "illegal col: " << col << endl;
-       return 0;
-}
-
 void MathInset::substitute(MathMacro const &)
 {}
 
 
 void MathInset::substitute(MathMacro const &)
 {}
 
 
-bool MathInset::idxNext(LCursor &) const
-{
-       return false;
-}
-
-
-bool MathInset::idxRight(LCursor &) const
-{
-       return false;
-}
-
-
-bool MathInset::idxPrev(LCursor &) const
-{
-       return false;
-}
-
-
-bool MathInset::idxLeft(LCursor &) const
-{
-       return false;
-}
-
-
-bool MathInset::idxUpDown(LCursor &, bool, int) const
-{
-       return false;
-}
-
-
-bool MathInset::idxUpDown2(LCursor &, bool, int) const
-{
-       return false;
-}
-
-
-bool MathInset::idxFirst(LCursor &) const
-{
-       return false;
-}
-
-
-bool MathInset::idxLast(LCursor &) const
-{
-       return false;
-}
-
-
-bool MathInset::idxHome(LCursor &) const
-{
-       return false;
-}
-
-
-bool MathInset::idxEnd(LCursor &) const
-{
-       return false;
-}
-
-
-void MathInset::getScreenPos(idx_type, pos_type, int & x, int & y) const
-{
-       lyxerr << "MathInset::getScreenPos() called directly!" << endl;
-       x = y = 0;
-}
-
 
 void MathInset::dump() const
 {
 
 void MathInset::dump() const
 {
@@ -132,12 +51,6 @@ void MathInset::dump() const
 }
 
 
 }
 
 
-bool MathInset::idxBetween(idx_type idx, idx_type from, idx_type to) const
-{
-       return from <= idx && idx <= to;
-}
-
-
 void MathInset::drawSelection(PainterInfo &,
        idx_type, pos_type, idx_type, pos_type) const
 {
 void MathInset::drawSelection(PainterInfo &,
        idx_type, pos_type, idx_type, pos_type) const
 {
@@ -210,24 +123,6 @@ void MathInset::mathmlize(MathMLStream & os) const
 }
 
 
 }
 
 
-int MathInset::plaintext(std::ostream &, OutputParams const &) const
-{
-       return 0;
-}
-
-
-int MathInset::linuxdoc(std::ostream &, OutputParams const &) const
-{
-       return 0;
-}
-
-
-int MathInset::docbook(std::ostream &, OutputParams const &) const
-{
-       return 0;
-}
-
-
 string const & MathInset::getType() const
 {
        static string const t("none");
 string const & MathInset::getType() const
 {
        static string const t("none");
index 9ca5c55e5cb66a8422f051d5d98a70c379756737..57fcca147b78c62b12f654a98d180210b5cf148f 100644 (file)
@@ -75,8 +75,6 @@ class ReplaceData;
 
 class MathInset : public InsetBase {
 public:
 
 class MathInset : public InsetBase {
 public:
-       /// our members behave nicely...
-       MathInset() {}
        /// identification as math inset
        MathInset * asMathInset() { return this; }
 
        /// identification as math inset
        MathInset * asMathInset() { return this; }
 
@@ -91,65 +89,11 @@ public:
        /// draw the object as text
        virtual void drawT(TextPainter &, int x, int y) const;
 
        /// draw the object as text
        virtual void drawT(TextPainter &, int x, int y) const;
 
-       /// Where should we go when we press the up or down cursor key?
-       virtual bool idxUpDown(LCursor & cur, bool up, int targetx) const;
-       /// Where should we go when we press the up or down cursor key?
-       virtual bool idxUpDown2(LCursor & cur, bool up, int targetx) const;
-       /// The left key
-       virtual bool idxLeft(LCursor & cur) const;
-       /// The right key
-       virtual bool idxRight(LCursor & cur) const;
-
-       /// Move one physical cell up
-       virtual bool idxNext(LCursor & cur) const;
-       /// Move one physical cell down
-       virtual bool idxPrev(LCursor & cur) const;
-
-       /// Target pos when we enter the inset from the left by pressing "Right"
-       virtual bool idxFirst(LCursor & cur) const;
-       /// Target pos when we enter the inset from the right by pressing "Left"
-       virtual bool idxLast(LCursor & cur) const;
-
-       /// Where should we go if we press home?
-       virtual bool idxHome(LCursor & cur) const;
-       /// Where should we go if we press end?
-       virtual bool idxEnd(LCursor & cur) const;
-
-       /// Delete a cell and move cursor
-       virtual bool idxDelete(idx_type &) { return false; }
-       /// pulls cell after pressing erase
-       virtual void idxGlue(idx_type) {}
-       // returns list of cell indices that are "between" from and to for
-       // selection purposes
-       virtual bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
-
-       /// the number of nested cells this inset owns
-       virtual idx_type nargs() const;
-
        /// return cell given its number
        virtual MathArray & cell(idx_type);
        /// return cell given its number
        virtual MathArray const & cell(idx_type) const;
 
        /// return cell given its number
        virtual MathArray & cell(idx_type);
        /// return cell given its number
        virtual MathArray const & cell(idx_type) const;
 
-       /// the number of columns of this inset if it is grid-like
-       virtual col_type ncols() const { return 1; }
-       /// the number of rows of this inset if it is grid-like
-       virtual row_type nrows() const { return 1; }
-       /// to which column belongs a cell with a given index?
-       virtual col_type col(idx_type) const { return 0; }
-       /// to which row belongs a cell with a given index?
-       virtual row_type row(idx_type) const { return 0; }
-       /// cell idex corresponding to row and column;
-       virtual idx_type index(row_type row, col_type col) const;
-       /// any additional x-offset when drawing a cell?
-       virtual int cellXOffset(idx_type) const { return 0; }
-       /// any additional y-offset when drawing a cell?
-       virtual int cellYOffset(idx_type) const { return 0; }
-       /// can we enter this cell?
-       virtual bool validCell(idx_type) const { return true; }
-       /// get coordinates
-       virtual void getScreenPos(idx_type idx, pos_type pos, int & x, int & y) const;
-
        /// identifies certain types of insets
        virtual MathAMSArrayInset       * asAMSArrayInset()       { return 0; }
        virtual MathAMSArrayInset const * asAMSArrayInset() const { return 0; }
        /// identifies certain types of insets
        virtual MathAMSArrayInset       * asAMSArrayInset()       { return 0; }
        virtual MathAMSArrayInset const * asAMSArrayInset() const { return 0; }
@@ -185,14 +129,8 @@ public:
 
        /// identifies things that can get scripts
        virtual bool isScriptable() const { return false; }
 
        /// identifies things that can get scripts
        virtual bool isScriptable() const { return false; }
-       /// thing that can be moved into
-       virtual bool isActive() const { return nargs() > 0; }
        /// is the a relational operator (used for splitting equations)
        virtual bool isRelOp() const { return false; }
        /// is the a relational operator (used for splitting equations)
        virtual bool isRelOp() const { return false; }
-       /// -1: text mode, 1: math mode, 0 undecided
-       enum mode_type {UNDECIDED_MODE, TEXT_MODE, MATH_MODE};
-
-       virtual mode_type currentMode() const { return UNDECIDED_MODE; }
        /// will this get written as a single block in {..}
        virtual bool extraBraces() const { return false; }
 
        /// will this get written as a single block in {..}
        virtual bool extraBraces() const { return false; }
 
@@ -211,8 +149,6 @@ public:
        virtual bool lock() const { return false; }
        /// access to the lock (only nest array have one)
        virtual void lock(bool) {}
        virtual bool lock() const { return false; }
        /// access to the lock (only nest array have one)
        virtual void lock(bool) {}
-       /// get notification when the cursor leaves this inset
-       virtual void notifyCursorLeaves(idx_type) {}
 
        /// write LaTeX and Lyx code
        virtual void write(WriteStream & os) const;
 
        /// write LaTeX and Lyx code
        virtual void write(WriteStream & os) const;
@@ -228,12 +164,6 @@ public:
        virtual void mathmlize(MathMLStream &) const;
        /// write content as something readable by Octave
        virtual void octave(OctaveStream &) const;
        virtual void mathmlize(MathMLStream &) const;
        /// write content as something readable by Octave
        virtual void octave(OctaveStream &) const;
-       /// plain ascii output
-       virtual int plaintext(std::ostream & os, OutputParams const &) const;
-       /// linuxdoc output
-       virtual int linuxdoc(std::ostream & os, OutputParams const &) const;
-       /// docbook output
-       virtual int docbook(std::ostream & os, OutputParams const &) const;
 
        /// dump content to stderr for debugging
        virtual void dump() const;
 
        /// dump content to stderr for debugging
        virtual void dump() const;
index f0f34f265c32e6597126eb613f31f0868928a9a2..9058cb1fa59e6a586f3b3cfc05141217cfea2848 100644 (file)
@@ -75,13 +75,13 @@ void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const
 
                mathed_string_dim(font_, name(), dim_);
 
 
                mathed_string_dim(font_, name(), dim_);
 
-       } else if (editing()) {
+       } else if (editing(mi.base.bv)) {
 
                expand();
                expanded_.metrics(mi_, dim_);
                metricsMarkers();
 
 
                expand();
                expanded_.metrics(mi_, dim_);
                metricsMarkers();
 
-               dim_.wid +=  mathed_string_width(font_, name()) + 10;
+               dim_.wid += mathed_string_width(font_, name()) + 10;
 
                int ww = mathed_string_width(font_, "#1: ");
 
 
                int ww = mathed_string_width(font_, "#1: ");
 
@@ -117,7 +117,7 @@ void MathMacro::draw(PainterInfo & pi, int x, int y) const
                return;
        }
 
                return;
        }
 
-       if (editing()) {
+       if (editing(pi.base.bv)) {
                int h = y - dim_.ascent() + 2 + expanded_.ascent();
                drawStr(pi, font_, x + 3, h, name());
 
                int h = y - dim_.ascent() + 2 + expanded_.ascent();
                drawStr(pi, font_, x + 3, h, name());
 
@@ -156,7 +156,7 @@ void MathMacro::dump() const
 }
 
 
 }
 
 
-bool MathMacro::idxUpDown(LCursor & cur, bool up, int x) const
+bool MathMacro::idxUpDown(LCursor & cur, bool up) const
 {
        if (up) {
                if (!MathNestInset::idxLeft(cur))
 {
        if (up) {
                if (!MathNestInset::idxLeft(cur))
@@ -165,7 +165,7 @@ bool MathMacro::idxUpDown(LCursor & cur, bool up, int x) const
                if (!MathNestInset::idxRight(cur))
                        return false;
        }
                if (!MathNestInset::idxRight(cur))
                        return false;
        }
-       cur.pos() = cur.cell().x2pos(x);
+       cur.pos() = cur.cell().x2pos(cur.x_target());
        return true;
 }
 
        return true;
 }
 
index 1df6ed4bb0181cbe88a144c6be12cb99ffa3c6eb..9351d8ea51f367552bd97932f22fd6f908ce6a6c 100644 (file)
@@ -38,11 +38,11 @@ public:
        void dump() const;
 
        ///
        void dump() const;
 
        ///
-       bool idxUpDown(LCursor &, bool up, int targetx) const;
+       bool idxUpDown(LCursor & cur, bool up) const;
        ///
        ///
-       bool idxLeft(LCursor &) const;
+       bool idxLeft(LCursor & cur) const;
        ///
        ///
-       bool idxRight(LCursor &) const;
+       bool idxRight(LCursor & cur) const;
 
        ///
        void validate(LaTeXFeatures &) const;
 
        ///
        void validate(LaTeXFeatures &) const;
index f756b280b8f8a561a300cfa1111ce4dcaa7c425d..f2f485a81c8872c3da9095166dee5c9a33bf4c23 100644 (file)
 #include <config.h>
 
 #include "math_nestinset.h"
 #include <config.h>
 
 #include "math_nestinset.h"
-#include "math_cursor.h"
-#include "math_mathmlstream.h"
-#include "math_parser.h"
+
 #include "BufferView.h"
 #include "BufferView.h"
-#include "dispatchresult.h"
+#include "LColor.h"
+#include "cursor.h"
 #include "debug.h"
 #include "debug.h"
+#include "dispatchresult.h"
 #include "funcrequest.h"
 #include "funcrequest.h"
-#include "LColor.h"
+#include "math_data.h"
+#include "math_mathmlstream.h"
+#include "math_parser.h"
 #include "undo.h"
 
 #include "frontends/Painter.h"
 #include "undo.h"
 
 #include "frontends/Painter.h"
@@ -214,9 +216,9 @@ bool MathNestInset::contains(MathArray const & ar) const
 }
 
 
 }
 
 
-bool MathNestInset::editing() const
+bool MathNestInset::editing(BufferView * bv) const
 {
 {
-       return inMathed() && mathcursor::isInside(this);
+       return bv->cursor().isInside(this);
 }
 
 
 }
 
 
@@ -306,43 +308,415 @@ MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
        case LFUN_RIGHTSEL:
                cur.selection() = true; // fall through...
        case LFUN_RIGHT:
        case LFUN_RIGHTSEL:
                cur.selection() = true; // fall through...
        case LFUN_RIGHT:
-               return mathcursor::right(cur, cur.selection()) ?
+               return cur.right() ?
                        DispatchResult(true, true) : DispatchResult(false, FINISHED_RIGHT);
                //lyxerr << "calling scroll 20" << endl;
                //scroll(&cur.bv(), 20);
                // write something to the minibuffer
                        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());
+               //cur.bv().owner()->message(cur.info());
 
        case LFUN_LEFTSEL:
                cur.selection() = true; // fall through
        case LFUN_LEFT:
 
        case LFUN_LEFTSEL:
                cur.selection() = true; // fall through
        case LFUN_LEFT:
-               return mathcursor::left(cur, cur.selection()) ?
+               return cur.left() ?
                        DispatchResult(true, true) : DispatchResult(false, FINISHED);
 
        case LFUN_UPSEL:
                cur.selection() = true; // fall through
        case LFUN_UP:
                        DispatchResult(true, true) : DispatchResult(false, FINISHED);
 
        case LFUN_UPSEL:
                cur.selection() = true; // fall through
        case LFUN_UP:
-               return mathcursor::up(cur, cur.selection()) ?
+               return cur.up() ?
                        DispatchResult(true, true) : DispatchResult(false, FINISHED_UP);
 
        case LFUN_DOWNSEL:
                cur.selection() = true; // fall through
        case LFUN_DOWN:
                        DispatchResult(true, true) : DispatchResult(false, FINISHED_UP);
 
        case LFUN_DOWNSEL:
                cur.selection() = true; // fall through
        case LFUN_DOWN:
-               return mathcursor::down(cur, cur.selection()) ?
+               return cur.down() ?
                        DispatchResult(true, true) : DispatchResult(false, FINISHED_DOWN);
 
                        DispatchResult(true, true) : DispatchResult(false, FINISHED_DOWN);
 
+       case LFUN_WORDSEL:
+               cur.home();
+               cur.selection() = true;
+               cur.end();
+               return DispatchResult(true, true);
+
+       case LFUN_UP_PARAGRAPHSEL:
+       case LFUN_UP_PARAGRAPH:
+       case LFUN_DOWN_PARAGRAPHSEL:
+       case LFUN_DOWN_PARAGRAPH:
+               return DispatchResult(true, FINISHED);
+
+       case LFUN_HOMESEL:
+       case LFUN_WORDLEFTSEL:
+               cur.selection() = true; // fall through
+       case LFUN_HOME:
+       case LFUN_WORDLEFT:
+               return cur.home()
+                       ? DispatchResult(true, true) : DispatchResult(true, FINISHED);
+
+       case LFUN_ENDSEL:
+       case LFUN_WORDRIGHTSEL:
+               cur.selection() = true; // fall through
+       case LFUN_END:
+       case LFUN_WORDRIGHT:
+               return cur.end()
+                       ? DispatchResult(true, true) : DispatchResult(false, FINISHED_RIGHT);
+
+       case LFUN_PRIORSEL:
+       case LFUN_PRIOR:
+       case LFUN_BEGINNINGBUFSEL:
+       case LFUN_BEGINNINGBUF:
+               return DispatchResult(true, FINISHED);
+
+       case LFUN_NEXTSEL:
+       case LFUN_NEXT:
+       case LFUN_ENDBUFSEL:
+       case LFUN_ENDBUF:
+               return DispatchResult(false, FINISHED_RIGHT);
+
+       case LFUN_CELL_FORWARD:
+               cur.inset()->idxNext(cur);
+               return DispatchResult(true, true);
+
+       case LFUN_CELL_BACKWARD:
+               cur.inset()->idxPrev(cur);
+               return DispatchResult(true, true);
+
+       case LFUN_DELETE_WORD_BACKWARD:
+       case LFUN_BACKSPACE:
+               recordUndo(cur, Undo::ATOMIC);
+               cur.backspace();
+               return DispatchResult(true, true);
+
+       case LFUN_DELETE_WORD_FORWARD:
+       case LFUN_DELETE:
+               recordUndo(cur, Undo::ATOMIC);
+               cur.erase();
+               return DispatchResult(true, FINISHED);
+
+       case LFUN_ESCAPE:
+               if (!cur.selection())
+                       return DispatchResult(true, true);
+               cur.selClear();
+               return DispatchResult(false);
+
+       case LFUN_INSET_TOGGLE:
+               cur.lockToggle();
+               return DispatchResult(true, true);
+
        case LFUN_SELFINSERT:
                if (!cmd.argument.empty()) {
                        recordUndo(cur, Undo::ATOMIC);
                        if (cmd.argument.size() == 1) {
        case LFUN_SELFINSERT:
                if (!cmd.argument.empty()) {
                        recordUndo(cur, Undo::ATOMIC);
                        if (cmd.argument.size() == 1) {
-                               if (mathcursor::interpret(cur, cmd.argument[0]))
+                               if (cur.interpret(cmd.argument[0]))
                                        return DispatchResult(true, true);
                                else
                                        return DispatchResult(false, FINISHED_RIGHT);
                        }
                                        return DispatchResult(true, true);
                                else
                                        return DispatchResult(false, FINISHED_RIGHT);
                        }
-                       mathcursor::insert(cur, cmd.argument);
+                       cur.insert(cmd.argument);
+               }
+               return DispatchResult(false, FINISHED_RIGHT);
+
+
+#if 0
+//
+// this needs to bee incorporated
+//
+       //lyxerr << "InsetFormulaBase::localDispatch: act: " << cmd.action
+       //      << " arg: '" << cmd.argument
+       //      << "' x: '" << cmd.x
+       //      << " y: '" << cmd.y
+       //      << "' button: " << cmd.button() << endl;
+
+       // delete empty mathbox (LFUN_BACKSPACE and LFUN_DELETE)
+       bool remove_inset = false;
+
+       switch (cmd.action) {
+               case LFUN_MOUSE_PRESS:
+                       //lyxerr << "Mouse single press" << endl;
+                       return lfunMousePress(cur, cmd);
+               case LFUN_MOUSE_MOTION:
+                       //lyxerr << "Mouse motion" << endl;
+                       return lfunMouseMotion(cur, cmd);
+               case LFUN_MOUSE_RELEASE:
+                       //lyxerr << "Mouse single release" << endl;
+                       return lfunMouseRelease(cur, cmd);
+               case LFUN_MOUSE_DOUBLE:
+                       //lyxerr << "Mouse double" << endl;
+                       return dispatch(cur, FuncRequest(LFUN_WORDSEL));
+               default:
+                       break;
+       }
+
+       DispatchResult result(true);
+       string argument    = cmd.argument;
+       bool was_macro     = cur.inMacroMode();
+
+       cur.normalize();
+       cur.touch();
+
+       switch (cmd.action) {
+
+       case LFUN_MATH_MUTATE:
+       case LFUN_MATH_DISPLAY:
+       case LFUN_MATH_NUMBER:
+       case LFUN_MATH_NONUMBER:
+       case LFUN_CELL_SPLIT:
+       case LFUN_BREAKLINE:
+       case LFUN_DELETE_LINE_FORWARD:
+       case LFUN_INSERT_LABEL:
+       case LFUN_MATH_EXTERN:
+       case LFUN_TABULAR_FEATURE:
+       case LFUN_PASTESELECTION:
+       case LFUN_MATH_LIMITS:
+               recordUndo(cur, Undo::ATOMIC);
+               cur.dispatch(cmd);
+               break;
+
+       //    case LFUN_GETXY:
+       //      sprintf(dispatch_buffer, "%d %d",);
+       //      DispatchResult= dispatch_buffer;
+       //      break;
+       case LFUN_SETXY: {
+               lyxerr << "LFUN_SETXY broken!" << endl;
+               int x = 0;
+               int y = 0;
+               istringstream is(cmd.argument.c_str());
+               is >> x >> y;
+               cur.setScreenPos(x, y);
+               break;
+       }
+
+       case LFUN_PASTE: {
+               size_t n = 0;
+               istringstream is(cmd.argument.c_str());
+               is >> n;
+               if (was_macro)
+                       cur.macroModeClose();
+               recordUndo(cur, Undo::ATOMIC);
+               cur.selPaste(n);
+               break;
+       }
+
+       case LFUN_CUT:
+               recordUndo(cur, Undo::DELETE);
+               cur.selCut();
+               break;
+
+       case LFUN_COPY:
+               cur.selCopy();
+               break;
+
+
+       // Special casing for superscript in case of LyX handling
+       // dead-keys:
+       case LFUN_CIRCUMFLEX:
+               if (cmd.argument.empty()) {
+                       // do superscript if LyX handles
+                       // deadkeys
+                       recordUndo(cur, Undo::ATOMIC);
+                       cur.script(true);
+               }
+               break;
+
+       case LFUN_UMLAUT:
+       case LFUN_ACUTE:
+       case LFUN_GRAVE:
+       case LFUN_BREVE:
+       case LFUN_DOT:
+       case LFUN_MACRON:
+       case LFUN_CARON:
+       case LFUN_TILDE:
+       case LFUN_CEDILLA:
+       case LFUN_CIRCLE:
+       case LFUN_UNDERDOT:
+       case LFUN_TIE:
+       case LFUN_OGONEK:
+       case LFUN_HUNG_UMLAUT:
+               break;
+
+       //  Math fonts
+       case LFUN_FREEFONT_APPLY:
+       case LFUN_FREEFONT_UPDATE:
+               handleFont2(cur, cmd.argument);
+               break;
+
+       case LFUN_BOLD:         handleFont(cur, cmd.argument, "mathbf"); break;
+       case LFUN_SANS:         handleFont(cur, cmd.argument, "mathsf"); break;
+       case LFUN_EMPH:         handleFont(cur, cmd.argument, "mathcal"); break;
+       case LFUN_ROMAN:        handleFont(cur, cmd.argument, "mathrm"); break;
+       case LFUN_CODE:         handleFont(cur, cmd.argument, "texttt"); break;
+       case LFUN_FRAK:         handleFont(cur, cmd.argument, "mathfrak"); break;
+       case LFUN_ITAL:         handleFont(cur, cmd.argument, "mathit"); break;
+       case LFUN_NOUN:         handleFont(cur, cmd.argument, "mathbb"); break;
+       //case LFUN_FREEFONT_APPLY:  handleFont(cur, cmd.argument, "textrm"); break;
+       case LFUN_DEFAULT:      handleFont(cur, cmd.argument, "textnormal"); break;
+
+       case LFUN_MATH_MODE:
+               if (cur.currentMode() == InsetBase::TEXT_MODE)
+                       cur.niceInsert(MathAtom(new MathHullInset("simple")));
+               else
+                       handleFont(cur, cmd.argument, "textrm");
+               //cur.owner()->message(_("math text mode toggled"));
+               break;
+
+       case LFUN_MATH_SIZE:
+#if 0
+               if (!arg.empty()) {
+                       recordUndo(cur, Undo::ATOMIC);
+                       cur.setSize(arg);
+               }
+#endif
+               break;
+
+       case LFUN_INSERT_MATRIX: {
+               recordUndo(cur, Undo::ATOMIC);
+               unsigned int m = 1;
+               unsigned int n = 1;
+               string v_align;
+               string h_align;
+               istringstream is(argument);
+               is >> m >> n >> v_align >> h_align;
+               m = max(1u, m);
+               n = max(1u, n);
+               v_align += 'c';
+               cur.niceInsert(
+                       MathAtom(new MathArrayInset("array", m, n, v_align[0], h_align)));
+               break;
+       }
+
+       case LFUN_MATH_DELIM: {
+               //lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'" << endl;
+               string ls;
+               string rs = split(cmd.argument, ls, ' ');
+               // Reasonable default values
+               if (ls.empty())
+                       ls = '(';
+               if (rs.empty())
+                       rs = ')';
+               recordUndo(cur, Undo::ATOMIC);
+               cur.handleNest(MathAtom(new MathDelimInset(ls, rs)));
+               break;
+       }
+
+       case LFUN_SPACE_INSERT:
+       case LFUN_MATH_SPACE:
+               recordUndo(cur, Undo::ATOMIC);
+               cur.insert(MathAtom(new MathSpaceInset(",")));
+               break;
+
+       case LFUN_UNDO:
+               cur.bv().owner()->message(_("Invalid action in math mode!"));
+               break;
+
+
+       case LFUN_EXEC_COMMAND:
+               result = DispatchResult(false);
+               break;
+
+       case LFUN_INSET_ERT:
+               // interpret this as if a backslash was typed
+               recordUndo(cur, Undo::ATOMIC);
+               cur.interpret('\\');
+               break;
+
+       case LFUN_BREAKPARAGRAPH:
+       case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
+       case LFUN_BREAKPARAGRAPH_SKIP:
+               argument = "\n";
+               // fall through
+
+// FIXME: We probably should swap parts of "math-insert" and "self-insert"
+// 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(cur, Undo::ATOMIC);
+               cur.niceInsert(argument);
+               break;
+
+       case LFUN_INSET_TOGGLE:
+               cur.lockToggle();
+               break;
+
+       case LFUN_DIALOG_SHOW:
+               result = DispatchResult(false);
+               break;
+
+       case LFUN_DIALOG_SHOW_NEW_INSET: {
+               string const & name = argument;
+               string data;
+               if (name == "ref") {
+                       RefInset tmp(name);
+                       data = tmp.createDialogStr(name);
+               }
+
+               if (data.empty())
+                       result = DispatchResult(false);
+               else
+                       cur.bv().owner()->getDialogs().show(name, data, 0);
+               break;
+       }
+
+       case LFUN_INSET_APPLY: {
+               string const name = cmd.getArg(0);
+               InsetBase * base = cur.bv().owner()->getDialogs().getOpenInset(name);
+
+               if (base) {
+                       FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument);
+                       result = base->dispatch(cur, fr);
+               } else {
+                       MathArray ar;
+                       if (createMathInset_fromDialogStr(cmd.argument, ar)) {
+                               cur.insert(ar);
+                               result = DispatchResult(true, true);
+                       } else {
+                               result = DispatchResult(false);
+                       }
+               }
+               break;
+       }
+
+       case LFUN_WORD_REPLACE:
+       case LFUN_WORD_FIND: {
+               result = 
+                       searchForward(&cur.bv(), cmd.getArg(0), false, false)
+                               ? DispatchResult(true, true) : DispatchResult(false);
+               break;
+       }
+
+       case LFUN_INSERT_MATH:
+       case LFUN_INSERT_MATRIX:
+       case LFUN_MATH_DELIM: {
+               MathHullInset * f = new MathHullInset;
+               if (openNewInset(cur, f)) {
+                       cur.inset()->dispatch(cur, FuncRequest(LFUN_MATH_MUTATE, "simple"));
+                       cur.inset()->dispatch(cur, cmd);
                }
                break;
                }
                break;
+       }
+
+       default:
+               result = DispatchResult(false);
+       }
+
+       if (result == DispatchResult(true, true))
+               cur.bv().update();
+
+       cur.normalize();
+       cur.touch();
+
+       BOOST_ASSERT(cur.inMathed());
+
+       if (result.dispatched()) {
+               revealCodes(cur);
+               cur.bv().stuffClipboard(cur.grabSelection());
+       } else {
+               cur.releaseMathCursor();
+               if (remove_inset)
+                       cur.bv().owner()->dispatch(FuncRequest(LFUN_DELETE));
+       }
+
+       return result;  // original version
+#endif
 
        default:
                return MathInset::priv_dispatch(cur, cmd);
 
        default:
                return MathInset::priv_dispatch(cur, cmd);
@@ -364,9 +738,10 @@ void MathNestInset::metricsMarkers2(int) const
        dim_.des += 1;
 }
 
        dim_.des += 1;
 }
 
+
 void MathNestInset::drawMarkers(PainterInfo & pi, int x, int y) const
 {
 void MathNestInset::drawMarkers(PainterInfo & pi, int x, int y) const
 {
-       if (!editing())
+       if (!editing(pi.base.bv))
                return;
        int t = x + dim_.width() - 1;
        int d = y + dim_.descent();
                return;
        int t = x + dim_.width() - 1;
        int d = y + dim_.descent();
@@ -379,7 +754,7 @@ void MathNestInset::drawMarkers(PainterInfo & pi, int x, int y) const
 
 void MathNestInset::drawMarkers2(PainterInfo & pi, int x, int y) const
 {
 
 void MathNestInset::drawMarkers2(PainterInfo & pi, int x, int y) const
 {
-       if (!editing())
+       if (!editing(pi.base.bv))
                return;
        drawMarkers(pi, x, y);
        int t = x + dim_.width() - 1;
                return;
        drawMarkers(pi, x, y);
        int t = x + dim_.width() - 1;
index 354b5aa4a135105ccfadb63605e255dcbf7a07ea..27de5a1c924e92d3082c7cae979c751759a58eb4 100644 (file)
@@ -25,7 +25,7 @@ public:
        /// nestinsets have a fixed size to start with
        explicit MathNestInset(idx_type ncells);
 
        /// nestinsets have a fixed size to start with
        explicit MathNestInset(idx_type ncells);
 
-       /// the size is usuall some sort of convex hull of the cells
+       /// the size is usually some sort of convex hull of the cells
        /// hides inset::metrics() intentionally!
        void metrics(MetricsInfo const & mi) const;
        /// draw background if locked
        /// hides inset::metrics() intentionally!
        void metrics(MetricsInfo const & mi) const;
        /// draw background if locked
@@ -90,8 +90,6 @@ public:
 
        /// debug helper
        void dump() const;
 
        /// debug helper
        void dump() const;
-       /// is the cursor currently somewhere within this inset?
-       virtual bool editing() const;
 
        /// writes \\, name(), and args in braces and '\\lyxlock' if necessary
        void write(WriteStream & os) const;
 
        /// writes \\, name(), and args in braces and '\\lyxlock' if necessary
        void write(WriteStream & os) const;
@@ -110,6 +108,8 @@ protected:
        /// if the inset is locked, it can't be entered with the cursor
        bool lock_;
 
        /// if the inset is locked, it can't be entered with the cursor
        bool lock_;
 
+       ///
+       bool editing(BufferView * bv) const;
        /// draw four angular markers
        void drawMarkers(PainterInfo & pi, int x, int y) const;
        /// draw two angular markers
        /// draw four angular markers
        void drawMarkers(PainterInfo & pi, int x, int y) const;
        /// draw two angular markers
index 0b99091aadb16cf973c07e130b33ef53dea5c024..310d6e9fa5deeec756366d777aacaa30e9deeff9 100644 (file)
@@ -80,7 +80,7 @@ void MathRootInset::normalize(NormalStream & os) const
 }
 
 
 }
 
 
-bool MathRootInset::idxUpDown(LCursor & cur, bool up, int) const
+bool MathRootInset::idxUpDown(LCursor & cur, bool up) const
 {
        bool target = !up; // up ? 0 : 1;
        if (cur.idx() == target)
 {
        bool target = !up; // up ? 0 : 1;
        if (cur.idx() == target)
index 406dd60e99b459e4597830873ae129ed6f8d5b8b..025304b3340947e48c034011a3c01e8bfb2f0625 100644 (file)
@@ -24,7 +24,7 @@ public:
        ///
        virtual std::auto_ptr<InsetBase> clone() const;
        ///
        ///
        virtual std::auto_ptr<InsetBase> clone() const;
        ///
-       bool idxUpDown(LCursor &, bool up, int targetx) const;
+       bool idxUpDown(LCursor & cur, bool up) const;
        ///
        void metrics(MetricsInfo & mi, Dimension & dim) const;
        ///
        ///
        void metrics(MetricsInfo & mi, Dimension & dim) const;
        ///
index faa46b1e673cc07b768c03cf46f9df54cfef6c3a..26151a7c1f05af40cd3e9a976c899963f340ba49 100644 (file)
@@ -231,7 +231,7 @@ void MathScriptInset::draw(PainterInfo & pi, int x, int y) const
                nuc().draw(pi, x + dxx(), y);
        else {
                nuc().setXY(x + dxx(), y);
                nuc().draw(pi, x + dxx(), y);
        else {
                nuc().setXY(x + dxx(), y);
-               if (editing())
+               if (editing(pi.base.bv))
                        drawStr(pi, pi.base.font, x + dxx(), y, ".");
        }
        ScriptChanger dummy(pi.base);
                        drawStr(pi, pi.base.font, x + dxx(), y, ".");
        }
        ScriptChanger dummy(pi.base);
@@ -326,7 +326,7 @@ bool MathScriptInset::idxLeft(LCursor &) const
 }
 
 
 }
 
 
-bool MathScriptInset::idxUpDown(LCursor & cur, bool up, int) const
+bool MathScriptInset::idxUpDown(LCursor & cur, bool up) const
 {
        if (cur.idx() == 1) {
                // if we are 'up' we can't go further up
 {
        if (cur.idx() == 1) {
                // if we are 'up' we can't go further up
index d2b889dc0b5e0478a2982f903b9df47f2fce7dab..45514a844a195ed6d1814a9e627e35c08a2d8b64 100644 (file)
@@ -35,6 +35,19 @@ public:
        ///
        void drawT(TextPainter & pi, int x, int y) const;
 
        ///
        void drawT(TextPainter & pi, int x, int y) const;
 
+       /// move cursor left
+       bool idxLeft(LCursor & cur) const;
+       /// move cursor right
+       bool idxRight(LCursor & cur) const;
+       /// move cursor up or down
+       bool idxUpDown(LCursor & cur, bool up) const;
+       /// Target pos when we enter the inset from the left by pressing "Right"
+       bool idxFirst(LCursor & cur) const;
+       /// Target pos when we enter the inset from the right by pressing "Left"
+       bool idxLast(LCursor & cur) const;
+       /// can we enter this cell?
+       bool validCell(idx_type i) const { return i == 2 || script_[i]; }
+
        /// write LaTeX and Lyx code
        void write(WriteStream & os) const;
        /// write normalized content
        /// write LaTeX and Lyx code
        void write(WriteStream & os) const;
        /// write normalized content
@@ -47,18 +60,6 @@ public:
        void mathmlize(MathMLStream &) const;
        /// write content as something readable by Octave
        void octave(OctaveStream &) const;
        void mathmlize(MathMLStream &) const;
        /// write content as something readable by Octave
        void octave(OctaveStream &) const;
-       /// move cursor left
-       bool idxLeft(LCursor &) const;
-       /// move cursor right
-       bool idxRight(LCursor &) const;
-       /// move cursor up or down
-       bool idxUpDown(LCursor &, bool up, int targetx) const;
-       /// Target pos when we enter the inset from the left by pressing "Right"
-       bool idxFirst(LCursor &) const;
-       /// Target pos when we enter the inset from the right by pressing "Left"
-       bool idxLast(LCursor &) const;
-       /// can we enter this cell?
-       bool validCell(idx_type i) const { return i == 2 || script_[i]; }
 
        /// identifies scriptinsets
        MathScriptInset const * asScriptInset() const;
 
        /// identifies scriptinsets
        MathScriptInset const * asScriptInset() const;
index 6a8ef248ebf6b598ff51c9974b6c55ce99fac2a9..0c8772d7c36bda2f255e406f6379ff146866866d 100644 (file)
@@ -50,8 +50,7 @@ void MathTextInset::getScreenPos(idx_type /*idx*/, pos_type pos, int & x, int &
 
 
 #if 0
 
 
 #if 0
-bool MathTextInset::idxUpDown2(LCursor & pos, bool up,
-       int /*targetx*/) const
+bool MathTextInset::idxUpDown2(LCursor & pos, bool up) const
 {
        // try to move only one screen row up or down if possible
        idx_type i = pos2row(pos);
 {
        // try to move only one screen row up or down if possible
        idx_type i = pos2row(pos);
index f146467bdf19a2755ccf035d419fbfd835f72a11..8f81c8321689afa37606b9a1ce83d3ce326d4731 100644 (file)
@@ -33,7 +33,7 @@ public:
        void drawSelection(PainterInfo & pi,
                idx_type idx1, pos_type pos1, idx_type idx2, pos_type pos2) const;
        /// moves cursor up or down
        void drawSelection(PainterInfo & pi,
                idx_type idx1, pos_type pos1, idx_type idx2, pos_type pos2) const;
        /// moves cursor up or down
-       //bool idxUpDown2(LCursor & pos, bool up, int targetx) const;
+       //bool idxUpDown2(LCursor & pos, bool up) const;
 protected:
        /// row corresponding to given position
        idx_type pos2row(pos_type pos) const;
 protected:
        /// row corresponding to given position
        idx_type pos2row(pos_type pos) const;
index 734984e9069b838c9eed2ef607dffdff4017d5db..74b8f0494d1b092e0557417fc84b8e2931867221 100644 (file)
@@ -64,13 +64,13 @@ bool MathUndersetInset::idxLast(LCursor & cur) const
 }
 
 
 }
 
 
-bool MathUndersetInset::idxUpDown(LCursor & cur, bool up, int targetx) const
+bool MathUndersetInset::idxUpDown(LCursor & cur, bool up) const
 {
        idx_type target = up; // up ? 1 : 0, since upper cell has idx 1
        if (cur.idx() == target)
                return false;
        cur.idx() = target;
 {
        idx_type target = up; // up ? 1 : 0, since upper cell has idx 1
        if (cur.idx() == target)
                return false;
        cur.idx() = target;
-       cur.pos() = cur.cell().x2pos(targetx);
+       cur.pos() = cur.cell().x2pos(cur.x_target());
        return true;
 }
 
        return true;
 }
 
index 0be7417cd08abd5c34e15cc932f8bfd3cbd67707..002ff0d7bd7465d061bfd73bc8e4cc0fc03366c5 100644 (file)
@@ -25,15 +25,15 @@ public:
        ///
        void draw(PainterInfo & pi, int x, int y) const;
        ///
        ///
        void draw(PainterInfo & pi, int x, int y) const;
        ///
-       bool idxFirst(LCursor &) const;
+       bool idxFirst(LCursor & cur) const;
        ///
        ///
-       bool idxLast(LCursor &) const;
+       bool idxLast(LCursor & cur) const;
        ///
        ///
-       bool idxUpDown(LCursor &, bool up, int targetx) const;
+       bool idxUpDown(LCursor & cur, bool up) const;
        ///
        ///
-       void write(WriteStream & os) const;
+       void write(WriteStream & ws) const;
        ///
        ///
-       void normalize(NormalStream &) const;
+       void normalize(NormalStream & ns) const;
 };
 
 #endif
 };
 
 #endif
index e8daa3feeb460f77849b290474a1c7a274d345df..c57bb0d32127c754a9ec7d7f5b695a3cafde0be0 100644 (file)
@@ -149,9 +149,8 @@ void docbookParagraphs(Buffer const & buf,
                        // This is a hack while paragraphs can't have
                        // attributes, like id in this case.
                        if (par->size() && par->isInset(0)) {
                        // This is a hack while paragraphs can't have
                        // attributes, like id in this case.
                        if (par->size() && par->isInset(0)) {
-                               InsetOld * inset = par->getInset(0);
-                               InsetOld::Code lyx_code = inset->lyxCode();
-                               if (lyx_code == InsetOld::LABEL_CODE) {
+                               InsetBase * inset = par->getInset(0);
+                               if (inset->lyxCode() == InsetOld::LABEL_CODE) {
                                        command_name += " id=\"";
                                        command_name += (static_cast<InsetCommand *>(inset))->getContents();
                                        command_name += '"';
                                        command_name += " id=\"";
                                        command_name += (static_cast<InsetCommand *>(inset))->getContents();
                                        command_name += '"';
index 837c6dbc32db369fbd1ebed7a0a4486889043350..739cec7c62f925330b801875e54ae5de5dd26fa6 100644 (file)
@@ -194,8 +194,8 @@ InsetOptArg * optArgInset(Paragraph const & par)
        InsetList::const_iterator it = par.insetlist.begin();
        InsetList::const_iterator end = par.insetlist.end();
        for (; it != end; ++it) {
        InsetList::const_iterator it = par.insetlist.begin();
        InsetList::const_iterator end = par.insetlist.end();
        for (; it != end; ++it) {
-               InsetOld * ins = it->inset;
-               if (ins->lyxCode() == InsetOld::OPTARG_CODE) {
+               InsetBase * ins = it->inset;
+               if (ins->lyxCode() == InsetBase::OPTARG_CODE) {
                        return static_cast<InsetOptArg *>(ins);
                }
        }
                        return static_cast<InsetOptArg *>(ins);
                }
        }
index 213112b490dcffbe83bb82000377f28362391aff..7ce1e932bcbd5b3f601d013e7a00659082907bb5 100644 (file)
@@ -46,9 +46,8 @@ void linuxdocParagraphs(Buffer const & buf,
                LyXLayout_ptr const & style = pit->layout();
                // treat <toc> as a special case for compatibility with old code
                if (pit->isInset(0)) {
                LyXLayout_ptr const & style = pit->layout();
                // treat <toc> as a special case for compatibility with old code
                if (pit->isInset(0)) {
-                       InsetOld * inset = pit->getInset(0);
-                       InsetOld::Code lyx_code = inset->lyxCode();
-                       if (lyx_code == InsetOld::TOC_CODE) {
+                       InsetBase * inset = pit->getInset(0);
+                       if (inset->lyxCode() == InsetOld::TOC_CODE) {
                                string const temp = "toc";
                                sgml::openTag(os, depth, false, temp);
                                continue;
                                string const temp = "toc";
                                sgml::openTag(os, depth, false, temp);
                                continue;
@@ -92,8 +91,7 @@ void linuxdocParagraphs(Buffer const & buf,
 
                case LATEX_ENVIRONMENT:
                case LATEX_ITEM_ENVIRONMENT:
 
                case LATEX_ENVIRONMENT:
                case LATEX_ITEM_ENVIRONMENT:
-               case LATEX_BIB_ENVIRONMENT:
-               {
+               case LATEX_BIB_ENVIRONMENT: {
                        string const & latexname = style->latexname();
 
                        if (depth == pit->params().depth()
                        string const & latexname = style->latexname();
 
                        if (depth == pit->params().depth()
index 79095bbe4365feae6b6cce3196779c3dff61f312..70c72e59a74e17695d962c0e0076aafc0feafebb 100644 (file)
@@ -204,7 +204,7 @@ void asciiParagraph(Buffer const & buf,
                char c = par.getUChar(buf.params(), i);
                switch (c) {
                case Paragraph::META_INSET: {
                char c = par.getUChar(buf.params(), i);
                switch (c) {
                case Paragraph::META_INSET: {
-                       InsetOld const * inset = par.getInset(i);
+                       InsetBase const * inset = par.getInset(i);
                        if (runparams.linelen > 0) {
                                os << word;
                                currlinelen += word.length();
                        if (runparams.linelen > 0) {
                                os << word;
                                currlinelen += word.length();
@@ -225,13 +225,11 @@ void asciiParagraph(Buffer const & buf,
                                os << p.second;
                                currlinelen = p.first;
                        }
                                os << p.second;
                                currlinelen = p.first;
                        }
-
                        os << word << ' ';
                        currlinelen += word.length() + 1;
                        word.erase();
                        break;
 
                        os << word << ' ';
                        currlinelen += word.length() + 1;
                        word.erase();
                        break;
 
-
                case '\0':
                        lyxerr[Debug::INFO] <<
                                "writeAsciiFile: NULL char in structure." << endl;
                case '\0':
                        lyxerr[Debug::INFO] <<
                                "writeAsciiFile: NULL char in structure." << endl;
index 9dce9f546ec3599fe3a5f67f9882e5cb51f19e77..1dec5968edb708a13aa3997c57942645e511ab28 100644 (file)
@@ -85,10 +85,8 @@ Paragraph::Paragraph(Paragraph const & par)
        insetlist = par.insetlist;
        InsetList::iterator it = insetlist.begin();
        InsetList::iterator end = insetlist.end();
        insetlist = par.insetlist;
        InsetList::iterator it = insetlist.begin();
        InsetList::iterator end = insetlist.end();
-       for (; it != end; ++it) {
-               // currently we hold Inset*, not InsetBase*
-               it->inset = static_cast<InsetOld*>(it->inset->clone().release());
-       }
+       for (; it != end; ++it)
+               it->inset = it->inset->clone().release();
 }
 
 
 }
 
 
@@ -114,9 +112,8 @@ void Paragraph::operator=(Paragraph const & par)
        insetlist = par.insetlist;
        InsetList::iterator it = insetlist.begin();
        InsetList::iterator end = insetlist.end();
        insetlist = par.insetlist;
        InsetList::iterator it = insetlist.begin();
        InsetList::iterator end = insetlist.end();
-       for (; it != end; ++it) {
-               it->inset = static_cast<InsetOld*>(it->inset->clone().release());
-       }
+       for (; it != end; ++it)
+               it->inset = it->inset->clone().release();
 }
 
 
 }
 
 
@@ -181,7 +178,7 @@ void Paragraph::write(Buffer const & buf, ostream & os,
                switch (c) {
                case META_INSET:
                {
                switch (c) {
                case META_INSET:
                {
-                       InsetOld const * inset = getInset(i);
+                       InsetBase const * inset = getInset(i);
                        if (inset)
                                if (inset->directWrite()) {
                                        // international char, let it write
                        if (inset)
                                if (inset->directWrite()) {
                                        // international char, let it write
@@ -290,13 +287,13 @@ void Paragraph::insertChar(pos_type pos, Paragraph::value_type c,
 }
 
 
 }
 
 
-void Paragraph::insertInset(pos_type pos, InsetOld * inset)
+void Paragraph::insertInset(pos_type pos, InsetBase * inset)
 {
        insertInset(pos, inset, LyXFont(LyXFont::ALL_INHERIT));
 }
 
 
 {
        insertInset(pos, inset, LyXFont(LyXFont::ALL_INHERIT));
 }
 
 
-void Paragraph::insertInset(pos_type pos, InsetOld * inset,
+void Paragraph::insertInset(pos_type pos, InsetBase * inset,
        LyXFont const & font, Change change)
 {
        pimpl_->insertInset(pos, inset, font, change);
        LyXFont const & font, Change change)
 {
        pimpl_->insertInset(pos, inset, font, change);
@@ -312,14 +309,14 @@ bool Paragraph::insetAllowed(InsetOld_code code)
 }
 
 
 }
 
 
-InsetOld * Paragraph::getInset(pos_type pos)
+InsetBase * Paragraph::getInset(pos_type pos)
 {
        BOOST_ASSERT(pos < size());
        return insetlist.get(pos);
 }
 
 
 {
        BOOST_ASSERT(pos < size());
        return insetlist.get(pos);
 }
 
 
-InsetOld const * Paragraph::getInset(pos_type pos) const
+InsetBase const * Paragraph::getInset(pos_type pos) const
 {
        BOOST_ASSERT(pos < size());
        return insetlist.get(pos);
 {
        BOOST_ASSERT(pos < size());
        return insetlist.get(pos);
@@ -689,7 +686,7 @@ void Paragraph::setBeginOfBody()
 
 
 // returns -1 if inset not found
 
 
 // returns -1 if inset not found
-int Paragraph::getPositionOfInset(InsetOld const * inset) const
+int Paragraph::getPositionOfInset(InsetBase const * inset) const
 {
        // Find the entry.
        InsetList::const_iterator it = insetlist.begin();
 {
        // Find the entry.
        InsetList::const_iterator it = insetlist.begin();
@@ -704,8 +701,8 @@ int Paragraph::getPositionOfInset(InsetOld const * inset) const
 InsetBibitem * Paragraph::bibitem() const
 {
        if (!insetlist.empty()) {
 InsetBibitem * Paragraph::bibitem() const
 {
        if (!insetlist.empty()) {
-               InsetOld * inset = insetlist.begin()->inset;
-               if (inset->lyxCode() == InsetOld::BIBTEX_CODE)
+               InsetBase * inset = insetlist.begin()->inset;
+               if (inset->lyxCode() == InsetBase::BIBTEX_CODE)
                        return static_cast<InsetBibitem *>(inset);
        }
        return 0;
                        return static_cast<InsetBibitem *>(inset);
        }
        return 0;
@@ -720,9 +717,9 @@ namespace {
 bool noTrivlistCentering(UpdatableInset const * inset)
 {
        if (inset && inset->owner()) {
 bool noTrivlistCentering(UpdatableInset const * inset)
 {
        if (inset && inset->owner()) {
-               InsetOld::Code const code = inset->owner()->lyxCode();
-               return code == InsetOld::FLOAT_CODE ||
-                       code == InsetOld::WRAP_CODE;
+               InsetBase::Code const code = inset->owner()->lyxCode();
+               return code == InsetBase::FLOAT_CODE ||
+                       code == InsetBase::WRAP_CODE;
        }
        return false;
 }
        }
        return false;
 }
@@ -1087,7 +1084,7 @@ void sgmlLineBreak(ostream & os, string::size_type & colcount,
 }
 
 enum PAR_TAG {
 }
 
 enum PAR_TAG {
-       NONE=0,
+       PAR_NONE=0,
        TT = 1,
        SF = 2,
        BF = 4,
        TT = 1,
        SF = 2,
        BF = 4,
@@ -1099,7 +1096,7 @@ enum PAR_TAG {
 
 string tag_name(PAR_TAG const & pt) {
        switch (pt) {
 
 string tag_name(PAR_TAG const & pt) {
        switch (pt) {
-       case NONE: return "!-- --";
+       case PAR_NONE: return "!-- --";
        case TT: return "tt";
        case SF: return "sf";
        case BF: return "bf";
        case TT: return "tt";
        case SF: return "sf";
        case BF: return "bf";
@@ -1158,7 +1155,7 @@ void Paragraph::simpleLinuxDocOnePar(Buffer const & buf,
        // parsing main loop
        for (pos_type i = 0; i < size(); ++i) {
 
        // parsing main loop
        for (pos_type i = 0; i < size(); ++i) {
 
-               PAR_TAG tag_close = NONE;
+               PAR_TAG tag_close = PAR_NONE;
                list < PAR_TAG > tag_open;
 
                LyXFont const font = getFont(buf.params(), i, outerfont);
                list < PAR_TAG > tag_open;
 
                LyXFont const font = getFont(buf.params(), i, outerfont);
@@ -1389,7 +1386,7 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
 
 
                if (isInset(i)) {
 
 
                if (isInset(i)) {
-                       InsetOld const * inset = getInset(i);
+                       InsetBase const * inset = getInset(i);
                        // don't print the inset in position 0 if desc_on == 3 (label)
                        //if (i || desc_on != 3) {
                        if (!labelid) {
                        // don't print the inset in position 0 if desc_on == 3 (label)
                        //if (i || desc_on != 3) {
                        if (!labelid) {
@@ -1463,7 +1460,7 @@ bool IsInsetChar(char c)
 bool Paragraph::isHfill(pos_type pos) const
 {
        return IsInsetChar(getChar(pos))
 bool Paragraph::isHfill(pos_type pos) const
 {
        return IsInsetChar(getChar(pos))
-              && getInset(pos)->lyxCode() == InsetOld::HFILL_CODE;
+              && getInset(pos)->lyxCode() == InsetBase::HFILL_CODE;
 }
 
 
 }
 
 
@@ -1476,7 +1473,7 @@ bool Paragraph::isInset(pos_type pos) const
 bool Paragraph::isNewline(pos_type pos) const
 {
        return IsInsetChar(getChar(pos))
 bool Paragraph::isNewline(pos_type pos) const
 {
        return IsInsetChar(getChar(pos))
-              && getInset(pos)->lyxCode() == InsetOld::NEWLINE_CODE;
+              && getInset(pos)->lyxCode() == InsetBase::NEWLINE_CODE;
 }
 
 
 }
 
 
@@ -1539,7 +1536,7 @@ bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
        return lyxrc.rtl_support
                && getParLanguage(bparams)->RightToLeft()
                && !(inInset() && inInset()->owner() &&
        return lyxrc.rtl_support
                && getParLanguage(bparams)->RightToLeft()
                && !(inInset() && inInset()->owner() &&
-                    inInset()->owner()->lyxCode() == InsetOld::ERT_CODE);
+                    inInset()->owner()->lyxCode() == InsetBase::ERT_CODE);
 }
 
 
 }
 
 
@@ -1595,7 +1592,7 @@ string const Paragraph::asString(Buffer const & buffer,
                if (IsPrintable(c))
                        s += c;
                else if (c == META_INSET &&
                if (IsPrintable(c))
                        s += c;
                else if (c == META_INSET &&
-                        getInset(i)->lyxCode() == InsetOld::MATH_CODE) {
+                        getInset(i)->lyxCode() == InsetBase::MATH_CODE) {
                        ostringstream os;
                        getInset(i)->plaintext(buffer, os, runparams);
                        s += subst(STRCONV(os.str()),'\n',' ');
                        ostringstream os;
                        getInset(i)->plaintext(buffer, os, runparams);
                        s += subst(STRCONV(os.str()),'\n',' ');
@@ -1756,8 +1753,8 @@ int Paragraph::id() const
 LyXLayout_ptr const & Paragraph::layout() const
 {
 /*
 LyXLayout_ptr const & Paragraph::layout() const
 {
 /*
-       InsetOld * inset = inInset();
-       if (inset && inset->lyxCode() == InsetOld::ENVIRONMENT_CODE)
+       InsetBase * inset = inInset();
+       if (inset && inset->lyxCode() == InsetBase::ENVIRONMENT_CODE)
                return static_cast<InsetEnvironment*>(inset)->layout();
 */
        return layout_;
                return static_cast<InsetEnvironment*>(inset)->layout();
 */
        return layout_;
@@ -1806,9 +1803,9 @@ bool Paragraph::isFreeSpacing() const
                return true;
 
        // for now we just need this, later should we need this in some
                return true;
 
        // for now we just need this, later should we need this in some
-       // other way we can always add a function to InsetOld too.
+       // other way we can always add a function to InsetBase too.
        if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
        if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
-               return pimpl_->inset_owner->owner()->lyxCode() == InsetOld::ERT_CODE;
+               return pimpl_->inset_owner->owner()->lyxCode() == InsetBase::ERT_CODE;
        return false;
 }
 
        return false;
 }
 
@@ -1818,7 +1815,7 @@ bool Paragraph::allowEmpty() const
        if (layout()->keepempty)
                return true;
        if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
        if (layout()->keepempty)
                return true;
        if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
-               return pimpl_->inset_owner->owner()->lyxCode() == InsetOld::ERT_CODE;
+               return pimpl_->inset_owner->owner()->lyxCode() == InsetBase::ERT_CODE;
        return false;
 }
 
        return false;
 }
 
index fca8d25163e77b0d775ab233b87ce0395473dde2..b604b37da3ee04ba0d051d52cf33398c2e7ce9ec 100644 (file)
@@ -29,6 +29,7 @@ class Buffer;
 class BufferParams;
 class BufferView;
 class Counters;
 class BufferParams;
 class BufferView;
 class Counters;
+class InsetBase;
 class InsetBibitem;
 class InsetOld_code;
 class Language;
 class InsetBibitem;
 class InsetOld_code;
 class Language;
@@ -44,7 +45,7 @@ class UpdatableInset;
 class Paragraph  {
 public:
        ///
 class Paragraph  {
 public:
        ///
-       enum META_KIND {
+       enum {
                /// Note that this is 1 right now to avoid
                /// crashes where getChar() is called wrongly
                /// (returning 0) - if this was 0, then we'd
                /// Note that this is 1 right now to avoid
                /// crashes where getChar() is called wrongly
                /// (returning 0) - if this was 0, then we'd
@@ -61,12 +62,11 @@ public:
 
        ///
        Paragraph();
 
        ///
        Paragraph();
-
        ///
        Paragraph(Paragraph const &);
        ///
        void operator=(Paragraph const &);
        ///
        Paragraph(Paragraph const &);
        ///
        void operator=(Paragraph const &);
-       /// the destructor removes the new paragraph from the list
+       ///
        ~Paragraph();
 
        ///
        ~Paragraph();
 
        ///
@@ -276,19 +276,21 @@ public:
        ///
        void insertChar(lyx::pos_type pos, value_type c);
        ///
        ///
        void insertChar(lyx::pos_type pos, value_type c);
        ///
-       void insertChar(lyx::pos_type pos, value_type c, LyXFont const &, Change change = Change(Change::INSERTED));
+       void insertChar(lyx::pos_type pos, value_type c,
+               LyXFont const &, Change change = Change(Change::INSERTED));
        ///
        bool checkInsertChar(LyXFont &);
        ///
        ///
        bool checkInsertChar(LyXFont &);
        ///
-       void insertInset(lyx::pos_type pos, InsetOld * inset);
+       void insertInset(lyx::pos_type pos, InsetBase * inset);
        ///
        ///
-       void insertInset(lyx::pos_type pos, InsetOld * inset, LyXFont const &, Change change = Change(Change::INSERTED));
+       void insertInset(lyx::pos_type pos, InsetBase * inset,
+               LyXFont const &, Change change = Change(Change::INSERTED));
        ///
        bool insetAllowed(InsetOld_code code);
        ///
        ///
        bool insetAllowed(InsetOld_code code);
        ///
-       InsetOld * getInset(lyx::pos_type pos);
+       InsetBase * getInset(lyx::pos_type pos);
        ///
        ///
-       InsetOld const * getInset(lyx::pos_type pos) const;
+       InsetBase const * getInset(lyx::pos_type pos) const;
 
        ///
        bool isHfill(lyx::pos_type pos) const;
 
        ///
        bool isHfill(lyx::pos_type pos) const;
@@ -308,7 +310,7 @@ public:
        bool isWord(lyx::pos_type pos) const;
 
        /// returns -1 if inset not found
        bool isWord(lyx::pos_type pos) const;
 
        /// returns -1 if inset not found
-       int getPositionOfInset(InsetOld const * inset) const;
+       int getPositionOfInset(InsetBase const * inset) const;
 
        ///
        int stripLeadingSpaces();
 
        ///
        int stripLeadingSpaces();
index 17bb406577a027c989a02f631892270eac451508..487ee37eb55a6f4d754ae262ad240fb0ec95565b 100644 (file)
@@ -77,7 +77,7 @@ bool moveItem(Paragraph & from, Paragraph & to,
        LyXFont tmpfont = from.getFontSettings(params, i);
 
        if (tmpchar == Paragraph::META_INSET) {
        LyXFont tmpfont = from.getFontSettings(params, i);
 
        if (tmpchar == Paragraph::META_INSET) {
-               InsetOld * tmpinset = 0;
+               InsetBase * tmpinset = 0;
                if (from.getInset(i)) {
                        // the inset is not in a paragraph anymore
                        tmpinset = from.insetlist.release(i);
                if (from.getInset(i)) {
                        // the inset is not in a paragraph anymore
                        tmpinset = from.insetlist.release(i);
@@ -356,7 +356,7 @@ int readParToken(Buffer const & buf, Paragraph & par, LyXLex & lex,
                lyxerr << "Solitary \\end_inset in line " << lex.getLineNo() << "\n"
                       << "Missing \\begin_inset?.\n";
        } else if (token == "\\begin_inset") {
                lyxerr << "Solitary \\end_inset in line " << lex.getLineNo() << "\n"
                       << "Missing \\begin_inset?.\n";
        } else if (token == "\\begin_inset") {
-               InsetOld * inset = readInset(lex, buf);
+               InsetBase * inset = readInset(lex, buf);
                if (inset)
                        par.insertInset(par.size(), inset, font, change);
                else {
                if (inset)
                        par.insertInset(par.size(), inset, font, change);
                else {
@@ -431,7 +431,7 @@ int readParToken(Buffer const & buf, Paragraph & par, LyXLex & lex,
                                }
                        }
                } else {
                                }
                        }
                } else {
-                       auto_ptr<InsetOld> inset;
+                       auto_ptr<InsetBase> inset;
                        if (token == "\\SpecialChar" )
                                inset.reset(new InsetSpecialChar);
                        else
                        if (token == "\\SpecialChar" )
                                inset.reset(new InsetSpecialChar);
                        else
@@ -441,17 +441,17 @@ int readParToken(Buffer const & buf, Paragraph & par, LyXLex & lex,
                                        font, change);
                }
        } else if (token == "\\i") {
                                        font, change);
                }
        } else if (token == "\\i") {
-               auto_ptr<InsetOld> inset(new InsetLatexAccent);
+               auto_ptr<InsetBase> inset(new InsetLatexAccent);
                inset->read(buf, lex);
                par.insertInset(par.size(), inset.release(), font, change);
        } else if (token == "\\backslash") {
                par.insertChar(par.size(), '\\', font, change);
        } else if (token == "\\newline") {
                inset->read(buf, lex);
                par.insertInset(par.size(), inset.release(), font, change);
        } else if (token == "\\backslash") {
                par.insertChar(par.size(), '\\', font, change);
        } else if (token == "\\newline") {
-               auto_ptr<InsetOld> inset(new InsetNewline);
+               auto_ptr<InsetBase> inset(new InsetNewline);
                inset->read(buf, lex);
                par.insertInset(par.size(), inset.release(), font, change);
        } else if (token == "\\LyXTable") {
                inset->read(buf, lex);
                par.insertInset(par.size(), inset.release(), font, change);
        } else if (token == "\\LyXTable") {
-               auto_ptr<InsetOld> inset(new InsetTabular(buf));
+               auto_ptr<InsetBase> inset(new InsetTabular(buf));
                inset->read(buf, lex);
                par.insertInset(par.size(), inset.release(), font, change);
        } else if (token == "\\bibitem") {
                inset->read(buf, lex);
                par.insertInset(par.size(), inset.release(), font, change);
        } else if (token == "\\bibitem") {
@@ -559,7 +559,7 @@ LyXFont const outerFont(ParagraphList::iterator pit,
 }
 
 
 }
 
 
-ParagraphList::iterator outerPar(Buffer const & buf, InsetOld const * inset)
+ParagraphList::iterator outerPar(Buffer const & buf, InsetBase const * inset)
 {
        ParIterator pit = const_cast<Buffer &>(buf).par_iterator_begin();
        ParIterator end = const_cast<Buffer &>(buf).par_iterator_end();
 {
        ParIterator pit = const_cast<Buffer &>(buf).par_iterator_begin();
        ParIterator end = const_cast<Buffer &>(buf).par_iterator_end();
@@ -582,7 +582,7 @@ ParagraphList::iterator outerPar(Buffer const & buf, InsetOld const * inset)
 }
 
 
 }
 
 
-Paragraph const & ownerPar(Buffer const & buf, InsetOld const * inset)
+Paragraph const & ownerPar(Buffer const & buf, InsetBase const * inset)
 {
        ParConstIterator pit = buf.par_iterator_begin();
        ParConstIterator end = buf.par_iterator_end();
 {
        ParConstIterator pit = buf.par_iterator_begin();
        ParConstIterator end = buf.par_iterator_end();
index c25327c447111a6e637bf1dff26dc551fc116dd9..0b1284962c5f94f4a0b8f39d96b12bdd12268521 100644 (file)
@@ -22,7 +22,7 @@ class Buffer;
 class BufferParams;
 class LyXFont;
 class LyXLex;
 class BufferParams;
 class LyXFont;
 class LyXLex;
-class InsetOld;
+class InsetBase;
 
 ///
 void breakParagraph(BufferParams const & bparams,
 
 ///
 void breakParagraph(BufferParams const & bparams,
@@ -70,10 +70,10 @@ LyXFont const outerFont(ParagraphList::iterator pit,
                        ParagraphList const & plist);
 
 /// find outermost paragraph containing an inset
                        ParagraphList const & plist);
 
 /// find outermost paragraph containing an inset
-ParagraphList::iterator outerPar(Buffer const & buf, InsetOld const * inset);
+ParagraphList::iterator outerPar(Buffer const & buf, InsetBase const * inset);
 
 /// find owning paragraph containing an inset
 
 /// find owning paragraph containing an inset
-Paragraph const & ownerPar(Buffer const & buf, InsetOld const * inset);
+Paragraph const & ownerPar(Buffer const & buf, InsetBase const * inset);
 
 /// return the range of pars [beg, end[ owning the range of y [ystart, yend] 
 void getParsInRange(ParagraphList & pl,
 
 /// return the range of pars [beg, end[ owning the range of y [ystart, yend] 
 void getParsInRange(ParagraphList & pl,
index 91d67776610bbff0ca207c5353890633543ae561..6186259e59d8cd523689a5093e7fe728055f04d8 100644 (file)
@@ -291,7 +291,7 @@ void Paragraph::Pimpl::insertChar(pos_type pos, value_type c,
 
 
 void Paragraph::Pimpl::insertInset(pos_type pos,
 
 
 void Paragraph::Pimpl::insertInset(pos_type pos,
-                                  InsetOld * inset, LyXFont const & font, Change change)
+                                  InsetBase * inset, LyXFont const & font, Change change)
 {
        BOOST_ASSERT(inset);
        BOOST_ASSERT(pos <= size());
 {
        BOOST_ASSERT(inset);
        BOOST_ASSERT(pos <= size());
@@ -467,8 +467,7 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const & buf,
                        if (c != '\0')
                                os << c;
                } else {
                        if (c != '\0')
                                os << c;
                } else {
-                       InsetOld const * inset = owner_->getInset(i);
-                       inset->plaintext(buf, os, runparams);
+                       owner_->getInset(i)->plaintext(buf, os, runparams);
                }
                return;
        }
                }
                return;
        }
@@ -478,14 +477,14 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const & buf,
        // and then split to handle the two modes separately.
        switch (c) {
        case Paragraph::META_INSET: {
        // and then split to handle the two modes separately.
        switch (c) {
        case Paragraph::META_INSET: {
-               InsetOld * inset = owner_->getInset(i);
+               InsetBase * inset = owner_->getInset(i);
 
                // FIXME: remove this check
                if (!inset)
                        break;
 
                // FIXME: move this to InsetNewline::latex
 
                // FIXME: remove this check
                if (!inset)
                        break;
 
                // FIXME: move this to InsetNewline::latex
-               if (inset->lyxCode() == InsetOld::NEWLINE_CODE) {
+               if (inset->lyxCode() == InsetBase::NEWLINE_CODE) {
                        // newlines are handled differently here than
                        // the default in simpleTeXSpecialChars().
                        if (!style.newline_allowed) {
                        // newlines are handled differently here than
                        // the default in simpleTeXSpecialChars().
                        if (!style.newline_allowed) {
@@ -521,9 +520,9 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const & buf,
                bool close = false;
                ostream::pos_type const len = os.tellp();
 
                bool close = false;
                ostream::pos_type const len = os.tellp();
 
-               if ((inset->lyxCode() == InsetOld::GRAPHICS_CODE
-                    || inset->lyxCode() == InsetOld::MATH_CODE
-                    || inset->lyxCode() == InsetOld::URL_CODE)
+               if ((inset->lyxCode() == InsetBase::GRAPHICS_CODE
+                    || inset->lyxCode() == InsetBase::MATH_CODE
+                    || inset->lyxCode() == InsetBase::URL_CODE)
                    && running_font.isRightToLeft()) {
                        os << "\\L{";
                        close = true;
                    && running_font.isRightToLeft()) {
                        os << "\\L{";
                        close = true;
@@ -790,7 +789,7 @@ void Paragraph::Pimpl::validate(LaTeXFeatures & features,
                if (icit->inset) {
                        icit->inset->validate(features);
                        if (layout.needprotect &&
                if (icit->inset) {
                        icit->inset->validate(features);
                        if (layout.needprotect &&
-                           icit->inset->lyxCode() == InsetOld::FOOT_CODE)
+                           icit->inset->lyxCode() == InsetBase::FOOT_CODE)
                                features.require("NeedLyXFootnoteCode");
                }
        }
                                features.require("NeedLyXFootnoteCode");
                }
        }
index 906e59a8b8a6a36d4f642fdfa284c7e20a0efb3d..a9b1e07d52f0873c6ebcdad898bf3de4b29b525f 100644 (file)
@@ -28,10 +28,14 @@ class LyXLayout;
 struct Paragraph::Pimpl {
        ///
        Pimpl(Paragraph * owner);
 struct Paragraph::Pimpl {
        ///
        Pimpl(Paragraph * owner);
-       /// Copy constructor
+       /// "Copy constructor"
        Pimpl(Pimpl const &, Paragraph * owner);
        ///
        void setContentsFromPar(Paragraph const & par);
        Pimpl(Pimpl const &, Paragraph * owner);
        ///
        void setContentsFromPar(Paragraph const & par);
+
+       //
+       // Change tracking
+       //
        /// set tracking mode
        void trackChanges(Change::Type type = Change::UNCHANGED);
        /// stop tracking
        /// set tracking mode
        void trackChanges(Change::Type type = Change::UNCHANGED);
        /// stop tracking
@@ -46,32 +50,27 @@ struct Paragraph::Pimpl {
        bool isChanged(lyx::pos_type start, lyx::pos_type end) const;
        /// is there a non-addition in this range ?
        bool isChangeEdited(lyx::pos_type start, lyx::pos_type end) const;
        bool isChanged(lyx::pos_type start, lyx::pos_type end) const;
        /// is there a non-addition in this range ?
        bool isChangeEdited(lyx::pos_type start, lyx::pos_type end) const;
-
        /// set change at pos
        void setChange(lyx::pos_type pos, Change::Type type);
        /// set change at pos
        void setChange(lyx::pos_type pos, Change::Type type);
-
        /// mark as erased
        void markErased();
        /// mark as erased
        void markErased();
-
        /// accept change
        void acceptChange(lyx::pos_type start, lyx::pos_type end);
        /// accept change
        void acceptChange(lyx::pos_type start, lyx::pos_type end);
-
        /// reject change
        void rejectChange(lyx::pos_type start, lyx::pos_type end);
        /// reject change
        void rejectChange(lyx::pos_type start, lyx::pos_type end);
-
        /// are we tracking changes ?
        /// are we tracking changes ?
-       bool tracking() const {
-               return changes_.get();
-       }
+       bool tracking() const { return changes_.get(); }
 
        ///
        value_type getChar(lyx::pos_type pos) const;
        ///
        void setChar(lyx::pos_type pos, value_type c);
        ///
 
        ///
        value_type getChar(lyx::pos_type pos) const;
        ///
        void setChar(lyx::pos_type pos, value_type c);
        ///
-       void insertChar(lyx::pos_type pos, value_type c, LyXFont const & font, Change change = Change(Change::INSERTED));
+       void insertChar(lyx::pos_type pos, value_type c,
+               LyXFont const & font, Change change = Change(Change::INSERTED));
        ///
        ///
-       void insertInset(lyx::pos_type pos, InsetOld * inset, LyXFont const & font, Change change = Change(Change::INSERTED));
+       void insertInset(lyx::pos_type pos, InsetBase * inset,
+               LyXFont const & font, Change change = Change(Change::INSERTED));
        /// definite erase
        void eraseIntern(lyx::pos_type pos);
        /// erase the given position. Returns true if it was actually erased
        /// definite erase
        void eraseIntern(lyx::pos_type pos);
        /// erase the given position. Returns true if it was actually erased
@@ -96,9 +95,9 @@ struct Paragraph::Pimpl {
                ///
                FontTable(lyx::pos_type p, LyXFont const & f)
                        : pos_(p)
                ///
                FontTable(lyx::pos_type p, LyXFont const & f)
                        : pos_(p)
-                       {
-                               font_ = container.get(f);
-                       }
+               {
+                       font_ = container.get(f);
+               }
                ///
                lyx::pos_type pos() const { return pos_; }
                ///
                ///
                lyx::pos_type pos() const { return pos_; }
                ///
index cf4d8bfe7d0d097caa68d1a303ed8612505dd5a9..d90558a4e87dcd9979b13408343f93a9f0ddd4ef 100644 (file)
@@ -189,10 +189,8 @@ int RowPainter::leftMargin() const
 
 void RowPainter::paintInset(pos_type const pos)
 {
 
 void RowPainter::paintInset(pos_type const pos)
 {
-       InsetOld * inset = const_cast<InsetOld*>(pit_->getInset(pos));
-
+       InsetBase * inset = const_cast<InsetBase *>(pit_->getInset(pos));
        BOOST_ASSERT(inset);
        BOOST_ASSERT(inset);
-
        PainterInfo pi(const_cast<BufferView *>(&bv_));
        pi.base.font = getFont(pos);
        inset->draw(pi, int(x_), yo_ + row_.baseline());
        PainterInfo pi(const_cast<BufferView *>(&bv_));
        pi.base.font = getFont(pos);
        inset->draw(pi, int(x_), yo_ + row_.baseline());
@@ -242,7 +240,7 @@ void RowPainter::paintArabicComposeChar(pos_type & vpos)
        // first char
        char c = pit_->getChar(pos);
        c = pit_->transformChar(c, pos);
        // first char
        char c = pit_->getChar(pos);
        c = pit_->transformChar(c, pos);
-       str +=c;
+       str += c;
        ++vpos;
 
        LyXFont const & font = getFont(pos);
        ++vpos;
 
        LyXFont const & font = getFont(pos);
@@ -392,13 +390,13 @@ void RowPainter::paintSelection()
 
        // the current selection
        LCursor const & cur = bv_.cursor();
 
        // the current selection
        LCursor const & cur = bv_.cursor();
-       int const startx = text_.cursorX(cur.selStart());
+       int const startx = text_.cursorX(cur.selBegin());
        int const endx = text_.cursorX(cur.selEnd());
        int const endx = text_.cursorX(cur.selEnd());
-       int const starty = text_.cursorY(cur.selStart());
+       int const starty = text_.cursorY(cur.selBegin());
        int const endy = text_.cursorY(cur.selEnd());
        int const endy = text_.cursorY(cur.selEnd());
-       ParagraphList::iterator startpit = text_.getPar(cur.selStart());
+       ParagraphList::iterator startpit = text_.getPar(cur.selBegin());
        ParagraphList::iterator endpit = text_.getPar(cur.selEnd());
        ParagraphList::iterator endpit = text_.getPar(cur.selEnd());
-       RowList::iterator startrow = startpit->getRow(cur.selStart().pos());
+       RowList::iterator startrow = startpit->getRow(cur.selBegin().pos());
        RowList::iterator endrow = endpit->getRow(cur.selEnd().pos());
        int const h = row_.height();
 
        RowList::iterator endrow = endpit->getRow(cur.selEnd().pos());
        int const h = row_.height();
 
@@ -469,7 +467,7 @@ void RowPainter::paintSelection()
                }
 
                if (((startpit != pit_ && startrow != rit_)
                }
 
                if (((startpit != pit_ && startrow != rit_)
-                               || cur.selStart().pos() <= pos) &&
+                               || cur.selBegin().pos() <= pos) &&
                        ((endpit != pit_ && endrow != rit_)
                                || pos < cur.selEnd().pos())) {
                        // Here we do not use x_ as xo_ was added to x_.
                        ((endpit != pit_ && endrow != rit_)
                                || pos < cur.selEnd().pos())) {
                        // Here we do not use x_ as xo_ was added to x_.
index 2294c231a58f8fb6b76405e1ceed508270529425..3f43ff0de86612db84a9600964b7880e89354c26 100644 (file)
@@ -2542,7 +2542,7 @@ InsetText & LyXTabular::getCellInset(int row, int column) const
 }
 
 
 }
 
 
-int LyXTabular::getCellFromInset(InsetOld const * inset) const
+int LyXTabular::getCellFromInset(InsetBase const * inset) const
 {
        // is this inset part of the tabular?
        if (!inset) {
 {
        // is this inset part of the tabular?
        if (!inset) {
index ad2818fc890180f5b12e894d999276b9cb4b65d1..d5df8c93f7d15ee493fc52e5fdb245ddc7973ac6 100644 (file)
@@ -371,7 +371,7 @@ public:
        InsetText & getCellInset(int row, int column) const;
        /// Search for \param inset in the tabular, with the
        ///
        InsetText & getCellInset(int row, int column) const;
        /// Search for \param inset in the tabular, with the
        ///
-       int getCellFromInset(InsetOld const * inset) const;
+       int getCellFromInset(InsetBase const * inset) const;
        ///
        int rows() const { return rows_; }
        ///
        ///
        int rows() const { return rows_; }
        ///
index b2073c384a2363baa2d508ae6f74b91b64bde2ec..24b65382f520de705687c119d7e225412c5020a9 100644 (file)
@@ -1027,7 +1027,7 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit, Row & row) const
                                int const ns = numberOfSeparators(*pit, row);
                                bool disp_inset = false;
                                if (row.endpos() < pit->size()) {
                                int const ns = numberOfSeparators(*pit, row);
                                bool disp_inset = false;
                                if (row.endpos() < pit->size()) {
-                                       InsetOld * in = pit->getInset(row.endpos());
+                                       InsetBase * in = pit->getInset(row.endpos());
                                        if (in)
                                                disp_inset = in->display();
                                }
                                        if (in)
                                                disp_inset = in->display();
                                }
@@ -1127,8 +1127,8 @@ void LyXText::acceptChange()
        if (!cur.selection() && cursorPar()->size())
                return;
 
        if (!cur.selection() && cursorPar()->size())
                return;
 
-       if (cur.selStart().par() == cur.par()) {
-               CursorSlice const & startc = cur.selStart();
+       if (cur.selBegin().par() == cur.par()) {
+               CursorSlice const & startc = cur.selBegin();
                CursorSlice const & endc = cur.selEnd();
                recordUndo(Undo::INSERT, this, startc.par());
                getPar(startc)->acceptChange(startc.pos(), endc.pos());
                CursorSlice const & endc = cur.selEnd();
                recordUndo(Undo::INSERT, this, startc.par());
                getPar(startc)->acceptChange(startc.pos(), endc.pos());
@@ -1147,8 +1147,8 @@ void LyXText::rejectChange()
        if (!cur.selection() && cursorPar()->size())
                return;
 
        if (!cur.selection() && cursorPar()->size())
                return;
 
-       if (cur.selStart().par() == cur.selEnd().par()) {
-               CursorSlice const & startc = cur.selStart();
+       if (cur.selBegin().par() == cur.selEnd().par()) {
+               CursorSlice const & startc = cur.selBegin();
                CursorSlice const & endc = cur.selEnd();
                recordUndo(Undo::INSERT, this, startc.par());
                getPar(startc)->rejectChange(startc.pos(), endc.pos());
                CursorSlice const & endc = cur.selEnd();
                recordUndo(Undo::INSERT, this, startc.par());
                getPar(startc)->rejectChange(startc.pos(), endc.pos());
@@ -1230,7 +1230,7 @@ void LyXText::changeCase(LyXText::TextCase action)
        CursorSlice to;
 
        if (cur.selection()) {
        CursorSlice to;
 
        if (cur.selection()) {
-               from = cur.selStart();
+               from = cur.selBegin();
                to = cur.selEnd();
        } else {
                from = cursor();
                to = cur.selEnd();
        } else {
                from = cursor();
@@ -1517,9 +1517,9 @@ string LyXText::selectionAsString(Buffer const & buffer, bool label) const
                return string();
 
        // should be const ...
                return string();
 
        // should be const ...
-       ParagraphList::iterator startpit = getPar(cur.selStart());
+       ParagraphList::iterator startpit = getPar(cur.selBegin());
        ParagraphList::iterator endpit = getPar(cur.selEnd());
        ParagraphList::iterator endpit = getPar(cur.selEnd());
-       size_t const startpos = cur.selStart().pos();
+       size_t const startpos = cur.selBegin().pos();
        size_t const endpos = cur.selEnd().pos();
 
        if (startpit == endpit)
        size_t const endpos = cur.selEnd().pos();
 
        if (startpit == endpit)
index 61ae776ac7febfbb477a6749f98b7fc31f8a8a89..5aeeb6fbc1ea3779dc3b9598cb44967fb54ad943 100644 (file)
@@ -214,7 +214,7 @@ void LyXText::setCharFont(
 }
 
 
 }
 
 
-InsetOld * LyXText::getInset() const
+InsetBase * LyXText::getInset() const
 {
        ParagraphList::iterator pit = cursorPar();
        pos_type const pos = cursor().pos();
 {
        ParagraphList::iterator pit = cursorPar();
        pos_type const pos = cursor().pos();
@@ -228,7 +228,7 @@ InsetOld * LyXText::getInset() const
 
 bool LyXText::toggleInset()
 {
 
 bool LyXText::toggleInset()
 {
-       InsetOld * inset = getInset();
+       InsetBase * inset = getInset();
        // is there an editable inset at cursor position?
        if (!isEditableInset(inset))
                return false;
        // is there an editable inset at cursor position?
        if (!isEditableInset(inset))
                return false;
@@ -324,7 +324,7 @@ void LyXText::setLayout(string const & layout)
                bv()->owner()->dispatch(FuncRequest(LFUN_HOME));
                bv()->owner()->dispatch(FuncRequest(LFUN_ENDSEL));
                bv()->owner()->dispatch(FuncRequest(LFUN_CUT));
                bv()->owner()->dispatch(FuncRequest(LFUN_HOME));
                bv()->owner()->dispatch(FuncRequest(LFUN_ENDSEL));
                bv()->owner()->dispatch(FuncRequest(LFUN_CUT));
-               InsetOld * inset = new InsetEnvironment(params, layout);
+               InsetBase * inset = new InsetEnvironment(params, layout);
                if (bv()->insertInset(inset)) {
                        //inset->edit(bv());
                        //bv()->owner()->dispatch(FuncRequest(LFUN_PASTE));
                if (bv()->insertInset(inset)) {
                        //inset->edit(bv());
                        //bv()->owner()->dispatch(FuncRequest(LFUN_PASTE));
@@ -334,7 +334,7 @@ void LyXText::setLayout(string const & layout)
        }
 
        ParagraphList::iterator start =
        }
 
        ParagraphList::iterator start =
-               getPar(bv()->cursor().selStart().par());
+               getPar(bv()->cursor().selBegin().par());
        ParagraphList::iterator end =
                boost::next(getPar(bv()->cursor().selEnd().par()));
        ParagraphList::iterator endpit = setLayout(start, end, layout);
        ParagraphList::iterator end =
                boost::next(getPar(bv()->cursor().selEnd().par()));
        ParagraphList::iterator endpit = setLayout(start, end, layout);
@@ -355,7 +355,7 @@ void getSelectionSpan(LyXText & text,
                beg = text.cursorPar();
                end = boost::next(beg);
        } else {
                beg = text.cursorPar();
                end = boost::next(beg);
        } else {
-               beg = text.getPar(text.bv()->cursor().selStart());
+               beg = text.getPar(text.bv()->cursor().selBegin());
                end = boost::next(text.getPar(text.bv()->cursor().selEnd()));
        }
 }
                end = boost::next(text.getPar(text.bv()->cursor().selEnd()));
        }
 }
@@ -451,13 +451,13 @@ void LyXText::setFont(LyXFont const & font, bool toggleall)
        }
 
        // ok we have a selection.
        }
 
        // ok we have a selection.
-       recUndo(cur.selStart().par(), cur.selEnd().par());
+       recUndo(cur.selBegin().par(), cur.selEnd().par());
        freezeUndo();
 
        freezeUndo();
 
-       ParagraphList::iterator beg = getPar(cur.selStart().par());
+       ParagraphList::iterator beg = getPar(cur.selBegin().par());
        ParagraphList::iterator end = getPar(cur.selEnd().par());
        
        ParagraphList::iterator end = getPar(cur.selEnd().par());
        
-       PosIterator pos(&paragraphs(), beg, cur.selStart().pos());
+       PosIterator pos(&paragraphs(), beg, cur.selBegin().pos());
        PosIterator posend(&paragraphs(), end, cur.selEnd().pos());
 
        BufferParams const & params = bv()->buffer()->params();
        PosIterator posend(&paragraphs(), end, cur.selEnd().pos());
 
        BufferParams const & params = bv()->buffer()->params();
@@ -553,7 +553,7 @@ string LyXText::getStringToIndex()
        string idxstring;
        if (!cur.selection())
                bv()->owner()->message(_("Nothing to index!"));
        string idxstring;
        if (!cur.selection())
                bv()->owner()->message(_("Nothing to index!"));
-       else if (cur.selStart().par() != cur.selEnd().par())
+       else if (cur.selBegin().par() != cur.selEnd().par())
                bv()->owner()->message(_("Cannot index more than one paragraph!"));
        else
                idxstring = selectionAsString(*bv()->buffer(), false);
                bv()->owner()->message(_("Cannot index more than one paragraph!"));
        else
                idxstring = selectionAsString(*bv()->buffer(), false);
@@ -582,10 +582,10 @@ void LyXText::setParagraph(Spacing const & spacing, LyXAlignment align,
        LCursor & cur = bv()->cursor();
        // make sure that the depth behind the selection are restored, too
        ParagraphList::iterator undopit = undoSpan(getPar(cur.selEnd()));
        LCursor & cur = bv()->cursor();
        // make sure that the depth behind the selection are restored, too
        ParagraphList::iterator undopit = undoSpan(getPar(cur.selEnd()));
-       recUndo(cur.selStart().par(), parOffset(undopit) - 1);
+       recUndo(cur.selBegin().par(), parOffset(undopit) - 1);
 
        ParagraphList::reverse_iterator pit(getPar(cur.selEnd().par()));
 
        ParagraphList::reverse_iterator pit(getPar(cur.selEnd().par()));
-       ParagraphList::reverse_iterator beg(getPar(cur.selStart().par()));
+       ParagraphList::reverse_iterator beg(getPar(cur.selBegin().par()));
 
        for (--pit; pit != beg; ++pit) {
                ParagraphParameters & params = pit->params();
 
        for (--pit; pit != beg; ++pit) {
                ParagraphParameters & params = pit->params();
@@ -606,7 +606,7 @@ void LyXText::setParagraph(Spacing const & spacing, LyXAlignment align,
                params.noindent(noindent);
        }
 
                params.noindent(noindent);
        }
 
-       redoParagraphs(getPar(cur.selStart()), undopit);
+       redoParagraphs(getPar(cur.selBegin()), undopit);
 }
 
 
 }
 
 
@@ -819,14 +819,14 @@ void LyXText::setCounter(Buffer const & buf, ParagraphList::iterator pit)
                if (layout->labeltype == LABEL_SENSITIVE) {
                        ParagraphList::iterator end = paragraphs().end();
                        ParagraphList::iterator tmppit = pit;
                if (layout->labeltype == LABEL_SENSITIVE) {
                        ParagraphList::iterator end = paragraphs().end();
                        ParagraphList::iterator tmppit = pit;
-                       InsetOld * in = 0;
+                       InsetBase * in = 0;
                        bool isOK = false;
                        while (tmppit != end && tmppit->inInset()
                               // the single '=' is intended below
                               && (in = tmppit->inInset()->owner()))
                        {
                        bool isOK = false;
                        while (tmppit != end && tmppit->inInset()
                               // the single '=' is intended below
                               && (in = tmppit->inInset()->owner()))
                        {
-                               if (in->lyxCode() == InsetOld::FLOAT_CODE ||
-                                   in->lyxCode() == InsetOld::WRAP_CODE) {
+                               if (in->lyxCode() == InsetBase::FLOAT_CODE ||
+                                   in->lyxCode() == InsetBase::WRAP_CODE) {
                                        isOK = true;
                                        break;
                                } else {
                                        isOK = true;
                                        break;
                                } else {
@@ -841,9 +841,9 @@ void LyXText::setCounter(Buffer const & buf, ParagraphList::iterator pit)
                        if (isOK) {
                                string type;
 
                        if (isOK) {
                                string type;
 
-                               if (in->lyxCode() == InsetOld::FLOAT_CODE)
+                               if (in->lyxCode() == InsetBase::FLOAT_CODE)
                                        type = static_cast<InsetFloat*>(in)->params().type;
                                        type = static_cast<InsetFloat*>(in)->params().type;
-                               else if (in->lyxCode() == InsetOld::WRAP_CODE)
+                               else if (in->lyxCode() == InsetBase::WRAP_CODE)
                                        type = static_cast<InsetWrap*>(in)->params().type;
                                else
                                        BOOST_ASSERT(false);
                                        type = static_cast<InsetWrap*>(in)->params().type;
                                else
                                        BOOST_ASSERT(false);
@@ -899,7 +899,7 @@ void LyXText::updateCounters()
 }
 
 
 }
 
 
-void LyXText::insertInset(InsetOld * inset)
+void LyXText::insertInset(InsetBase * inset)
 {
        if (!cursorPar()->insetAllowed(inset->lyxCode()))
                return;
 {
        if (!cursorPar()->insetAllowed(inset->lyxCode()))
                return;
@@ -938,14 +938,14 @@ void LyXText::cutSelection(bool doclear, bool realcut)
        if (!cur.selection())
                return;
 
        if (!cur.selection())
                return;
 
-       // OK, we have a selection. This is always between cur.selStart()
+       // OK, we have a selection. This is always between cur.selBegin()
        // and cur.selEnd()
 
        // make sure that the depth behind the selection are restored, too
        // and cur.selEnd()
 
        // make sure that the depth behind the selection are restored, too
-       ParagraphList::iterator begpit = getPar(cur.selStart().par());
+       ParagraphList::iterator begpit = getPar(cur.selBegin().par());
        ParagraphList::iterator endpit = getPar(cur.selEnd().par());
        ParagraphList::iterator undopit = undoSpan(endpit);
        ParagraphList::iterator endpit = getPar(cur.selEnd().par());
        ParagraphList::iterator undopit = undoSpan(endpit);
-       recUndo(cur.selStart().par(), parOffset(undopit) - 1);
+       recUndo(cur.selBegin().par(), parOffset(undopit) - 1);
 
        int endpos = cur.selEnd().pos();
 
 
        int endpos = cur.selEnd().pos();
 
@@ -954,13 +954,13 @@ void LyXText::cutSelection(bool doclear, bool realcut)
                CutAndPaste::cutSelection(bufparams,
                                          paragraphs(),
                                          begpit , endpit,
                CutAndPaste::cutSelection(bufparams,
                                          paragraphs(),
                                          begpit , endpit,
-                                         cur.selStart().pos(), endpos,
+                                         cur.selBegin().pos(), endpos,
                                          bufparams.textclass,
                                          doclear)
                : CutAndPaste::eraseSelection(bufparams,
                                              paragraphs(),
                                              begpit, endpit,
                                          bufparams.textclass,
                                          doclear)
                : CutAndPaste::eraseSelection(bufparams,
                                              paragraphs(),
                                              begpit, endpit,
-                                             cur.selStart().pos(), endpos,
+                                             cur.selBegin().pos(), endpos,
                                              doclear);
        // sometimes necessary
        if (doclear)
                                              doclear);
        // sometimes necessary
        if (doclear)
@@ -989,19 +989,19 @@ void LyXText::copySelection()
        if (!cur.selection())
                return;
 
        if (!cur.selection())
                return;
 
-       // ok we have a selection. This is always between cur.selStart()
+       // ok we have a selection. This is always between cur.selBegin()
        // and sel_end cursor
 
        // copy behind a space if there is one
        // and sel_end cursor
 
        // copy behind a space if there is one
-       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);
+       while (getPar(cur.selBegin())->size() > cur.selBegin().pos()
+              && getPar(cur.selBegin())->isLineSeparator(cur.selBegin().pos())
+              && (cur.selBegin().par() != cur.selEnd().par()
+                  || cur.selBegin().pos() < cur.selEnd().pos()))
+               cur.selBegin().pos(cur.selBegin().pos() + 1);
 
 
-       CutAndPaste::copySelection(getPar(cur.selStart().par()),
+       CutAndPaste::copySelection(getPar(cur.selBegin().par()),
                                   getPar(cur.selEnd().par()),
                                   getPar(cur.selEnd().par()),
-                                  cur.selStart().pos(), 
+                                  cur.selBegin().pos(), 
                                   cur.selEnd().pos(),
                                   bv()->buffer()->params().textclass);
 }
                                   cur.selEnd().pos(),
                                   bv()->buffer()->params().textclass);
 }
@@ -1062,9 +1062,9 @@ void LyXText::replaceSelectionWithString(string const & str)
 
        // Get font setting before we cut
        pos_type pos = cur.selEnd().pos();
 
        // Get font setting before we cut
        pos_type pos = cur.selEnd().pos();
-       LyXFont const font = getPar(cur.selStart())
+       LyXFont const font = getPar(cur.selBegin())
                ->getFontSettings(bv()->buffer()->params(),
                ->getFontSettings(bv()->buffer()->params(),
-                                 cur.selStart().pos());
+                                 cur.selBegin().pos());
 
        // Insert the new string
        string::const_iterator cit = str.begin();
 
        // Insert the new string
        string::const_iterator cit = str.begin();
@@ -1375,7 +1375,7 @@ bool LyXText::checkAndActivateInset(bool front)
 {
        if (cursor().pos() == cursorPar()->size())
                return false;
 {
        if (cursor().pos() == cursorPar()->size())
                return false;
-       InsetOld * inset = cursorPar()->getInset(cursor().pos());
+       InsetBase * inset = cursorPar()->getInset(cursor().pos());
        if (!isHighlyEditableInset(inset))
                return false;
        inset->edit(bv()->cursor(), front);
        if (!isHighlyEditableInset(inset))
                return false;
        inset->edit(bv()->cursor(), front);
@@ -1508,7 +1508,7 @@ void LyXText::cursorUp(bool selecting)
 
        if (!selecting) {
                int y_abs = y + yo_ - bv()->top_y();
 
        if (!selecting) {
                int y_abs = y + yo_ - bv()->top_y();
-               InsetOld * inset_hit = checkInsetHit(cur.x_target(), y_abs);
+               InsetBase * inset_hit = checkInsetHit(cur.x_target(), y_abs);
                if (inset_hit && isHighlyEditableInset(inset_hit))
                        inset_hit->edit(cur, cur.x_target(), y_abs);
        }
                if (inset_hit && isHighlyEditableInset(inset_hit))
                        inset_hit->edit(cur, cur.x_target(), y_abs);
        }
@@ -1525,7 +1525,7 @@ void LyXText::cursorDown(bool selecting)
 
        if (!selecting) {
                int y_abs = y + yo_ - bv()->top_y();
 
        if (!selecting) {
                int y_abs = y + yo_ - bv()->top_y();
-               InsetOld * inset_hit = checkInsetHit(cur.x_target(), y_abs);
+               InsetBase * inset_hit = checkInsetHit(cur.x_target(), y_abs);
                if (inset_hit && isHighlyEditableInset(inset_hit))
                        inset_hit->edit(cur, cur.x_target(), y_abs);
        }
                if (inset_hit && isHighlyEditableInset(inset_hit))
                        inset_hit->edit(cur, cur.x_target(), y_abs);
        }
index 083c0fade8a62590d40bd0fa86d24ed4df65c227..eadbe33e905af6829b667501a83b4bbff3776ffc 100644 (file)
@@ -48,7 +48,7 @@
 #include "support/tostr.h"
 #include "support/std_sstream.h"
 
 #include "support/tostr.h"
 #include "support/std_sstream.h"
 
-#include "mathed/formulabase.h"
+#include "mathed/math_hullinset.h"
 
 #include <clocale>
 
 
 #include <clocale>
 
@@ -69,7 +69,7 @@ using std::vector;
 extern string current_layout;
 
 // the selection possible is needed, that only motion events are
 extern string current_layout;
 
 // the selection possible is needed, that only motion events are
-// used, where the bottom press event was on the drawing area too
+// used, where the button press event was on the drawing area too
 bool selection_possible = false;
 
 
 bool selection_possible = false;
 
 
@@ -246,7 +246,7 @@ string const freefont2string()
 }
 
 
 }
 
 
-InsetOld * LyXText::checkInsetHit(int x, int y)
+InsetBase * LyXText::checkInsetHit(int x, int y)
 {
        ParagraphList::iterator pit;
        ParagraphList::iterator end;
 {
        ParagraphList::iterator pit;
        ParagraphList::iterator end;
@@ -261,7 +261,7 @@ InsetOld * LyXText::checkInsetHit(int x, int y)
                InsetList::iterator iit = pit->insetlist.begin();
                InsetList::iterator iend = pit->insetlist.end();
                for ( ; iit != iend; ++iit) {
                InsetList::iterator iit = pit->insetlist.begin();
                InsetList::iterator iend = pit->insetlist.end();
                for ( ; iit != iend; ++iit) {
-                       InsetOld * inset = iit->inset;
+                       InsetBase * inset = iit->inset;
                        //lyxerr << "examining inset " << inset
                        //      << " xy: " << inset->x() << "/" << inset->y()
                        //      << " x: " << inset->x() << "..." << inset->x() + inset->width()
                        //lyxerr << "examining inset " << inset
                        //      << " xy: " << inset->x() << "/" << inset->y()
                        //      << " x: " << inset->x() << "..." << inset->x() + inset->width()
@@ -283,14 +283,14 @@ InsetOld * LyXText::checkInsetHit(int x, int y)
 }
 
 
 }
 
 
-bool LyXText::gotoNextInset(vector<InsetOld::Code> const & codes,
+bool LyXText::gotoNextInset(vector<InsetOld_code> const & codes,
                            string const & contents)
 {
        ParagraphList::iterator end = paragraphs().end();
        ParagraphList::iterator pit = cursorPar();
        pos_type pos = cursor().pos();
 
                            string const & contents)
 {
        ParagraphList::iterator end = paragraphs().end();
        ParagraphList::iterator pit = cursorPar();
        pos_type pos = cursor().pos();
 
-       InsetOld * inset;
+       InsetBase * inset;
        do {
                if (pos + 1 < pit->size()) {
                        ++pos;
        do {
                if (pos + 1 < pit->size()) {
                        ++pos;
@@ -315,7 +315,7 @@ 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)
 {
        LCursor & cur = bv()->cursor();
        cur.clearSelection();
 {
        LCursor & cur = bv()->cursor();
        cur.clearSelection();
@@ -324,7 +324,7 @@ void LyXText::gotoInset(vector<InsetOld::Code> const & codes, bool same_content)
        if (same_content
            && cur.pos() < cur.lastpos()
            && cur.paragraph().isInset(cur.pos())) {
        if (same_content
            && cur.pos() < cur.lastpos()
            && cur.paragraph().isInset(cur.pos())) {
-               InsetOld const * inset = cur.paragraph().getInset(cur.pos());
+               InsetBase 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 (find(codes.begin(), codes.end(), inset->lyxCode())
                    != codes.end())
                        contents = static_cast<InsetCommand const *>(inset)->getContents();
@@ -348,9 +348,9 @@ void LyXText::gotoInset(vector<InsetOld::Code> const & codes, bool same_content)
 }
 
 
 }
 
 
-void LyXText::gotoInset(InsetOld::Code code, bool same_content)
+void LyXText::gotoInset(InsetOld_code code, bool same_content)
 {
 {
-       gotoInset(vector<InsetOld::Code>(1, code), same_content);
+       gotoInset(vector<InsetOld_code>(1, code), same_content);
 }
 
 
 }
 
 
@@ -412,7 +412,7 @@ void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
 void doInsertInset(BufferView * bv, FuncRequest const & cmd,
        bool edit, bool pastesel)
 {
 void doInsertInset(BufferView * bv, FuncRequest const & cmd,
        bool edit, bool pastesel)
 {
-       InsetOld * inset = createInset(bv, cmd);
+       InsetBase * inset = createInset(bv, cmd);
        if (!inset)
                return;
 
        if (!inset)
                return;
 
@@ -865,7 +865,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
        }
 
        case LFUN_INSET_INSERT: {
        }
 
        case LFUN_INSET_INSERT: {
-               InsetOld * inset = createInset(bv, cmd);
+               InsetBase * inset = createInset(bv, cmd);
                if (inset && !bv->insertInset(inset))
                        delete inset;
                break;
                if (inset && !bv->insertInset(inset))
                        delete inset;
                break;
@@ -1042,9 +1042,9 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                bool change_layout = (current_layout != layout);
 
                if (!change_layout && cur.selection() &&
                bool change_layout = (current_layout != layout);
 
                if (!change_layout && cur.selection() &&
-                       cur.selStart().par() != cur.selEnd().par())
+                       cur.selBegin().par() != cur.selEnd().par())
                {
                {
-                       ParagraphList::iterator spit = getPar(cur.selStart());
+                       ParagraphList::iterator spit = getPar(cur.selBegin());
                        ParagraphList::iterator epit = boost::next(getPar(cur.selEnd()));
                        while (spit != epit) {
                                if (spit->layout()->name() != current_layout) {
                        ParagraphList::iterator epit = boost::next(getPar(cur.selEnd()));
                        while (spit != epit) {
                                if (spit->layout()->name() != current_layout) {
@@ -1079,17 +1079,17 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
        }
 
        case LFUN_GOTOERROR:
        }
 
        case LFUN_GOTOERROR:
-               gotoInset(InsetOld::ERROR_CODE, false);
+               gotoInset(InsetBase::ERROR_CODE, false);
                break;
 
        case LFUN_GOTONOTE:
                break;
 
        case LFUN_GOTONOTE:
-               gotoInset(InsetOld::NOTE_CODE, false);
+               gotoInset(InsetBase::NOTE_CODE, false);
                break;
 
        case LFUN_REFERENCE_GOTO: {
                break;
 
        case LFUN_REFERENCE_GOTO: {
-               vector<InsetOld::Code> tmp;
-               tmp.push_back(InsetOld::LABEL_CODE);
-               tmp.push_back(InsetOld::REF_CODE);
+               vector<InsetOld_code> tmp;
+               tmp.push_back(InsetBase::LABEL_CODE);
+               tmp.push_back(InsetBase::REF_CODE);
                gotoInset(tmp, true);
                break;
        }
                gotoInset(tmp, true);
                break;
        }