]> git.lyx.org Git - features.git/commitdiff
The Buffer::LyXText -> Buffer::InsetText patch
authorAndré Pönitz <poenitz@gmx.net>
Thu, 18 Mar 2004 12:53:43 +0000 (12:53 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Thu, 18 Mar 2004 12:53:43 +0000 (12:53 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8498 a592a061-630c-0410-9148-cb99ea01b6c8

78 files changed:
src/BufferView.C
src/BufferView.h
src/BufferView_pimpl.C
src/BufferView_pimpl.h
src/buffer.C
src/buffer.h
src/buffer_funcs.C
src/cursor.C
src/cursor.h
src/cursor_slice.C
src/cursor_slice.h
src/dispatchresult.h
src/dociterator.C
src/dociterator.h
src/factory.C
src/frontends/screen.C
src/insets/insetbase.C
src/insets/insetbase.h
src/insets/insetbibitem.C
src/insets/insetbibitem.h
src/insets/insetbibtex.C
src/insets/insetbibtex.h
src/insets/insetbox.C
src/insets/insetbox.h
src/insets/insetbranch.C
src/insets/insetbranch.h
src/insets/insetcharstyle.C
src/insets/insetcharstyle.h
src/insets/insetcollapsable.C
src/insets/insetcollapsable.h
src/insets/insetcommand.C
src/insets/insetcommand.h
src/insets/insetert.C
src/insets/insetert.h
src/insets/insetexternal.C
src/insets/insetexternal.h
src/insets/insetfloat.C
src/insets/insetfloat.h
src/insets/insetgraphics.C
src/insets/insetgraphics.h
src/insets/insetinclude.C
src/insets/insetinclude.h
src/insets/insetlabel.C
src/insets/insetlabel.h
src/insets/insetnote.C
src/insets/insetnote.h
src/insets/insetref.C
src/insets/insetref.h
src/insets/insettabular.C
src/insets/insettabular.h
src/insets/insettext.C
src/insets/insettext.h
src/insets/insetvspace.C
src/insets/insetvspace.h
src/insets/insetwrap.C
src/insets/insetwrap.h
src/insets/updatableinset.C
src/insets/updatableinset.h
src/lyxfunc.C
src/lyxtext.h
src/mathed/math_gridinset.C
src/mathed/math_gridinset.h
src/mathed/math_hullinset.C
src/mathed/math_hullinset.h
src/mathed/math_mboxinset.C
src/mathed/math_mboxinset.h
src/mathed/math_nestinset.C
src/mathed/math_nestinset.h
src/mathed/math_scriptinset.C
src/mathed/math_scriptinset.h
src/mathed/ref_inset.C
src/mathed/ref_inset.h
src/output_latex.C
src/paragraph_funcs.C
src/text.C
src/text2.C
src/text3.C
src/undo.C

index 1cce3fed18a115f5255b92dbe0ae4438849ea44e..573da75b7a14cc6ecbf575a810a59c445e8a433d 100644 (file)
@@ -43,6 +43,7 @@
 
 #include "insets/insetcommand.h" // ChangeRefs
 #include "insets/updatableinset.h"
+#include "insets/insettext.h"
 
 #include "support/filetools.h"
 #include "support/lyxalgo.h" // lyx_count
@@ -102,15 +103,15 @@ Painter & BufferView::painter() const
 }
 
 
-void BufferView::buffer(Buffer * b)
+void BufferView::setBuffer(Buffer * b)
 {
-       pimpl_->buffer(b);
+       pimpl_->setBuffer(b);
 }
 
 
-bool BufferView::newFile(string const & fn, string const & tn, bool named)
+void BufferView::newFile(string const & fn, string const & tn, bool named)
 {
-       return pimpl_->newFile(fn, tn, named);
+       pimpl_->newFile(fn, tn, named);
 }
 
 
@@ -332,7 +333,9 @@ void BufferView::hideCursor()
 
 LyXText * BufferView::getLyXText() const
 {
-       return cursor().innerText();
+       LyXText * text = cursor().innerText();
+       BOOST_ASSERT(text);
+       return text;
 }
 
 
@@ -344,19 +347,6 @@ Language const * BufferView::getParentLanguage(InsetOld * inset) const
 }
 
 
-Encoding const * BufferView::getEncoding() const
-{
-       LyXText * t = getLyXText();
-       if (!t)
-               return 0;
-       CursorSlice const & cur = cursor().innerTextSlice();
-       return t->getPar(cur.par())->getFont(
-               buffer()->params(), cur.pos(),
-               outerFont(t->getPar(cur.par()), t->paragraphs())
-       ).language()->encoding();
-}
-
-
 void BufferView::haveSelection(bool sel)
 {
        pimpl_->workarea().haveSelection(sel);
@@ -371,22 +361,22 @@ int BufferView::workHeight() const
 
 LyXText * BufferView::text() const
 {
-       return pimpl_->buffer_ ? &pimpl_->buffer_->text() : 0;
+       return buffer() ? &buffer()->text() : 0;
 }
 
 
-void BufferView::setCursor(ParIterator const & par,
-                          lyx::pos_type pos)
+void BufferView::setCursor(ParIterator const & par, lyx::pos_type pos)
 {
        LCursor & cur = cursor();
        cur.reset();
+       cur.push(buffer()->inset());
        ParIterator::PosHolder const & positions = par.positions();
        int const last = par.size() - 1;
        for (int i = 0; i < last; ++i)
                (*positions[i].it)->inset->edit(cur, true);
        cur.resetAnchor();
-       LyXText * lt = par.text(*buffer());
-       lt->setCursor(cur, lt->parOffset(par.pit()), pos);
+       LyXText * text = par.text(*buffer());
+       text->setCursor(cur, text->parOffset(par.pit()), pos);
 }
 
 
index 9c50f9597b3fd0ffc83f69a7113ec52dda2662b9..a8cae7000b5b5937fe9771b9d549f26937ec5733 100644 (file)
@@ -58,7 +58,7 @@ public:
        ~BufferView();
 
        /// set the buffer we are viewing
-       void buffer(Buffer * b);
+       void setBuffer(Buffer * b);
        /// return the buffer being viewed
        Buffer * buffer() const;
 
@@ -81,7 +81,7 @@ public:
        /// reload the contained buffer
        void reload();
        /// create a new buffer based on template
-       bool newFile(std::string const & fname, std::string const & tname,
+       void newFile(std::string const & fname, std::string const & tname,
                     bool named = true);
        /// load a buffer into the view
        bool loadLyXFile(std::string const & name, bool tolastfiles = true);
@@ -111,9 +111,6 @@ public:
        /// return the lyxtext we are using
        LyXText * getLyXText() const;
 
-       /// return the current encoding at the cursor
-       Encoding const * getEncoding() const;
-
        /// return the parent language of the given inset
        Language const * getParentLanguage(InsetOld * inset) const;
 
index 98bd903d04472940ee13f80ecd7ea841e92e0328..55e540cd4585835cadbc7b067701f9ec92898831 100644 (file)
@@ -46,6 +46,7 @@
 #include "vspace.h"
 
 #include "insets/insetref.h"
+#include "insets/insettext.h"
 
 #include "frontends/Alert.h"
 #include "frontends/Dialogs.h"
@@ -157,19 +158,32 @@ void BufferView::Pimpl::connectBuffer(Buffer & buf)
                disconnectBuffer();
 
        errorConnection_ =
-               buf.error.connect(boost::bind(&BufferView::Pimpl::addError, this, _1));
+               buf.error.connect(
+                       boost::bind(&BufferView::Pimpl::addError, this, _1));
+
        messageConnection_ =
-               buf.message.connect(boost::bind(&LyXView::message, owner_, _1));
+               buf.message.connect(
+                       boost::bind(&LyXView::message, owner_, _1));
+
        busyConnection_ =
-               buf.busy.connect(boost::bind(&LyXView::busy, owner_, _1));
+               buf.busy.connect(
+                       boost::bind(&LyXView::busy, owner_, _1));
+
        titleConnection_ =
-               buf.updateTitles.connect(boost::bind(&LyXView::updateWindowTitle, owner_));
+               buf.updateTitles.connect(
+                       boost::bind(&LyXView::updateWindowTitle, owner_));
+
        timerConnection_ =
-               buf.resetAutosaveTimers.connect(boost::bind(&LyXView::resetAutosaveTimer, owner_));
+               buf.resetAutosaveTimers.connect(
+                       boost::bind(&LyXView::resetAutosaveTimer, owner_));
+
        readonlyConnection_ =
-               buf.readonly.connect(boost::bind(&BufferView::Pimpl::showReadonly, this, _1));
+               buf.readonly.connect(
+                       boost::bind(&BufferView::Pimpl::showReadonly, this, _1));
+
        closingConnection_ =
-               buf.closing.connect(boost::bind(&BufferView::Pimpl::buffer, this, (Buffer *)0));
+               buf.closing.connect(
+                       boost::bind(&BufferView::Pimpl::setBuffer, this, (Buffer *)0));
 }
 
 
@@ -185,13 +199,10 @@ void BufferView::Pimpl::disconnectBuffer()
 }
 
 
-bool BufferView::Pimpl::newFile(string const & filename,
-                               string const & tname,
-                               bool isNamed)
+void BufferView::Pimpl::newFile(string const & filename, string const & tname,
+       bool isNamed)
 {
-       Buffer * b = ::newFile(filename, tname, isNamed);
-       buffer(b);
-       return true;
+       setBuffer(::newFile(filename, tname, isNamed));
 }
 
 
@@ -216,14 +227,13 @@ bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles)
                        text, 0, 1,  _("&Revert"), _("&Switch to document"));
 
                if (ret != 0) {
-                       buffer(bufferlist.getBuffer(s));
+                       setBuffer(bufferlist.getBuffer(s));
                        return true;
-               } else {
-                       // FIXME: should be LFUN_REVERT
-                       if (!bufferlist.close(bufferlist.getBuffer(s), false))
-                               return false;
-                       // Fall through to new load. (Asger)
                }
+               // FIXME: should be LFUN_REVERT
+               if (!bufferlist.close(bufferlist.getBuffer(s), false))
+                       return false;
+               // Fall through to new load. (Asger)
        }
 
        Buffer * b;
@@ -248,7 +258,7 @@ bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles)
                        return false;
        }
 
-       buffer(b);
+       setBuffer(b);
        bv_->showErrorList(_("Parse"));
 
        if (tolastfiles)
@@ -288,48 +298,45 @@ int BufferView::Pimpl::top_y() const
 }
 
 
-void BufferView::Pimpl::buffer(Buffer * b)
+void BufferView::Pimpl::setBuffer(Buffer * b)
 {
        lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
                            << b << ')' << endl;
-       if (buffer_) {
+       if (buffer_)
                disconnectBuffer();
-               //delete bv_->text();
-               //bv_->setText(0);
-       }
-
-       // reset old cursor
-       cursor_.reset();
 
        // set current buffer
        buffer_ = b;
 
+       // reset old cursor
        top_y_ = 0;
+       cursor_ = LCursor(*bv_);
 
        // if we're quitting lyx, don't bother updating stuff
        if (quitting)
                return;
 
-       // if we are closing the buffer, use the first buffer as current
-       if (!buffer_)
-               buffer_ = bufferlist.first();
-
        if (buffer_) {
                lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl;
                connectBuffer(*buffer_);
 
+               cursor_.push(buffer_->inset());
+               cursor_.resetAnchor();
                buffer_->text().init(bv_);
 
                // If we don't have a text object for this, we make one
-               if (bv_->text() == 0)
-                       resizeCurrentBuffer();
+               //if (bv_->text() == 0)
+               //      resizeCurrentBuffer();
 
                // Buffer-dependent dialogs should be updated or
                // hidden. This should go here because some dialogs (eg ToC)
                // require bv_->text.
                owner_->getDialogs().updateBufferDependent(true);
+               owner_->setLayout(bv_->text()->getPar(0)->layout()->name());
        } else {
                lyxerr[Debug::INFO] << "  No Buffer!" << endl;
+               // we are closing the buffer, use the first buffer as current
+               buffer_ = bufferlist.first();
                owner_->getDialogs().hideBufferDependent();
        }
 
@@ -340,10 +347,6 @@ void BufferView::Pimpl::buffer(Buffer * b)
        owner_->updateLayoutChoice();
        owner_->updateWindowTitle();
 
-       // Don't forget to update the Layout
-       if (buffer_)
-               owner_->setLayout(bv_->text()->getPar(0)->layout()->name());
-
        if (lyx::graphics::Previews::activated() && buffer_)
                lyx::graphics::Previews::get().generateBufferPreviews(*buffer_);
 }
@@ -351,11 +354,10 @@ void BufferView::Pimpl::buffer(Buffer * b)
 
 bool BufferView::Pimpl::fitCursor()
 {
-       if (screen().fitCursor(bv_)) {
-               updateScrollbar();
-               return true;
-       }
-       return false;
+       if (!screen().fitCursor(bv_))
+               return false;
+       updateScrollbar();
+       return true;
 }
 
 
@@ -405,15 +407,17 @@ void BufferView::Pimpl::updateScrollbar()
 {
        if (!bv_->text()) {
                lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
+               lyxerr << "no text in updateScrollbar" << endl;
                workarea().setScrollbarParams(0, 0, 0);
                return;
        }
 
        LyXText const & t = *bv_->text();
 
-       lyxerr[Debug::GUI] << "Updating scrollbar: h" << t.height()
-                          << ", top_y()" << top_y() << ", default height "
-                          << defaultRowHeight() << endl;
+       lyxerr[Debug::GUI]
+               << "Updating scrollbar: height: " << t.height()
+               << " top_y: " << top_y()
+               << " default height " << defaultRowHeight() << endl;
 
        workarea().setScrollbarParams(t.height(), top_y(), defaultRowHeight());
 }
@@ -558,11 +562,11 @@ void BufferView::Pimpl::workAreaResize()
 
 void BufferView::Pimpl::update()
 {
-       //lyxerr << "BufferView::update()" << endl;
+       //lyxerr << "BufferView::Pimpl::update(), buffer: " << buffer_ << endl;
        // fix cursor coordinate cache in case something went wrong
 
        // check needed to survive LyX startup
-       if (bv_->getLyXText()) {
+       if (buffer_) {
                // update all 'visible' paragraphs
                ParagraphList::iterator beg;
                ParagraphList::iterator end;
@@ -638,7 +642,7 @@ void BufferView::Pimpl::restorePosition(unsigned int i)
                        ::loadLyXFile(b, fname); // don't ask, just load it
                }
                if (b)
-                       buffer(b);
+                       setBuffer(b);
        }
 
        ParIterator par = buffer_->getParFromID(saved_positions[i].par_id);
@@ -839,6 +843,8 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0)
        cmd.y += bv_->top_y();
        //lyxerr << "*** workAreaDispatch: request: " << cmd << std::endl;
        LCursor cur(*bv_);
+       cur.push(bv_->buffer()->inset());
+       cur.resetAnchor();
        cur.selection() = bv_->cursor().selection();
        switch (cmd.action) {
 
@@ -847,14 +853,7 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0)
                if (!available())
                        return false;
                FuncRequest cmd1 = cmd;
-               InsetBase * inset = cur.inset();
-               DispatchResult res;
-               if (inset) {
-                       res = inset->dispatch(cur, cmd);
-               } else {
-                       res = bv_->text()->dispatch(cur, cmd);
-               }
-
+               DispatchResult res = cur.inset().dispatch(cur, cmd);
                if (fitCursor() || res.update()) {
                        update();
                        cur.updatePos();
@@ -1089,6 +1088,22 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
                bv_->center();
                break;
 
+       case LFUN_BEGINNINGBUFSEL:
+               bv_->cursor().reset();
+               if (!cur.selection())
+                       cur.resetAnchor();
+               bv_->text()->cursorTop(cur);
+               finishUndo();
+               break;
+
+       case LFUN_ENDBUFSEL:
+               bv_->cursor().reset();
+               if (!cur.selection())
+                       cur.resetAnchor();
+               bv_->text()->cursorBottom(cur);
+               finishUndo();
+               break;
+
        default:
                return false;
        }
index 33e21fd671cef965939649d1896bc962d7632557..bb969dff47ad1b6b3fe0a55d0fa581facaf6a138 100644 (file)
@@ -52,7 +52,7 @@ struct BufferView::Pimpl : public boost::signals::trackable {
        /// return the screen for this bview
        LyXScreen & screen() const;
        ///
-       void buffer(Buffer *);
+       void setBuffer(Buffer * buf);
        /// Return true if the cursor was fitted.
        bool fitCursor();
        ///
@@ -61,12 +61,8 @@ struct BufferView::Pimpl : public boost::signals::trackable {
        void resizeCurrentBuffer();
        ///
        void update();
-       /**
-        * Repaint pixmap. Used for when we've made a visible
-        * change but don't need the full update() logic
-        */
        ///
-       bool newFile(std::string const &, std::string const &, bool);
+       void newFile(std::string const &, std::string const &, bool);
        ///
        bool loadLyXFile(std::string const &, bool);
        ///
index 45672b850a84c36934cda33560e3107e2ba7c5ff..273ece0f6edc9781511a6534fc5ca76d3b30fb24 100644 (file)
@@ -180,15 +180,15 @@ struct Buffer::Impl
         */
        bool file_fully_loaded;
 
-       /// our text
-       LyXText text;
+       /// our LyXText that should be wrapped in an InsetText
+       InsetText inset;
 };
 
 
 Buffer::Impl::Impl(Buffer & parent, string const & file, bool readonly_)
        : lyx_clean(true), bak_clean(true), unnamed(false), read_only(readonly_),
          filename(file), filepath(OnlyPath(file)), file_fully_loaded(false),
-               text(0, 0)
+               inset(params)
 {
        lyxvc.buffer(&parent);
        temppath = createBufferTmpDir();
@@ -202,6 +202,7 @@ Buffer::Buffer(string const & file, bool ronly)
        : pimpl_(new Impl(*this, file, ronly))
 {
        lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
+       lyxerr << "Buffer::Buffer()" << endl;
 }
 
 
@@ -225,7 +226,13 @@ Buffer::~Buffer()
 
 LyXText & Buffer::text() const
 {
-       return const_cast<LyXText &>(pimpl_->text);
+       return const_cast<LyXText &>(pimpl_->inset.text_);
+}
+
+
+InsetBase & Buffer::inset() const
+{
+       return const_cast<InsetText &>(pimpl_->inset);
 }
 
 
@@ -267,13 +274,13 @@ BufferParams const & Buffer::params() const
 
 ParagraphList & Buffer::paragraphs()
 {
-       return pimpl_->text.paragraphs();
+       return text().paragraphs();
 }
 
 
 ParagraphList const & Buffer::paragraphs() const
 {
-       return pimpl_->text.paragraphs();
+       return text().paragraphs();
 }
 
 
@@ -414,13 +421,8 @@ int Buffer::readHeader(LyXLex & lex)
 }
 
 
-// candidate for move to BufferView
-// (at least some parts in the beginning of the func)
-//
 // Uwe C. Schroeder
 // changed to be public and have one parameter
-// if par = 0 normal behavior
-// else insert behavior
 // Returns false if "\end_document" is not read (Asger)
 bool Buffer::readBody(LyXLex & lex)
 {
@@ -516,7 +518,9 @@ bool Buffer::readFile(string const & filename)
                params().compressed = true;
        }
 
-       bool ret = readFile(filename, paragraphs().begin());
+       // remove dummy empty par
+       paragraphs().clear();
+       bool ret = readFile(filename, paragraphs().end());
 
        // After we have read a file, we must ensure that the buffer
        // language is set and used in the gui.
@@ -641,12 +645,18 @@ bool Buffer::readFile(LyXLex & lex, string const & filename,
        bool the_end = readBody(lex);
        params().setPaperStuff();
 
+#warning Look here!
+#if 0
+       if (token == "\\end_document")
+               the_end_read = true;
+
        if (!the_end) {
                Alert::error(_("Document format failure"),
                             bformat(_("%1$s ended unexpectedly, which means"
                                       " that it is probably corrupted."),
                                       filename));
        }
+#endif 
        pimpl_->file_fully_loaded = true;
        return true;
 }
index ccff3086d49c70a8a4cdf8bfa2339d2b0430ce34..0a82f73b96cb22704aa7797892d3532aacd7ff14 100644 (file)
@@ -32,6 +32,7 @@ class BufferParams;
 class ErrorItem;
 class FuncRequest;
 class InsetBase;
+class InsetText;
 class LyXFont;
 class LyXLex;
 class LyXRC;
@@ -359,6 +360,8 @@ public:
 
        ///
        LyXText & text() const;
+       ///
+       InsetBase & inset() const;
 
 private:
        /** Inserts a file into a document
index dbb5e556d9cdfdc63d7aa26b3172f6db5448e3f5..bcbd98dce04c621f02c9756336ed55e180f77a4e 100644 (file)
@@ -177,12 +177,7 @@ Buffer * newFile(string const & filename, string const & templatename,
                        string const text  = bformat(_("The specified document template\n%1$s\ncould not be read."), file);
                        Alert::error(_("Could not read template"), text);
                        // no template, start with empty buffer
-                       b->paragraphs().push_back(Paragraph());
-                       b->paragraphs().begin()->layout(b->params().getLyXTextClass().defaultLayout());
                }
-       } else {  // start with empty buffer
-               b->paragraphs().push_back(Paragraph());
-               b->paragraphs().begin()->layout(b->params().getLyXTextClass().defaultLayout());
        }
 
        if (!isNamed) {
index ab0fc05d9411d3c94f69f73dc709de520f89f856..d8c6fb823adc694deac4d7f7c489f06b5ed974b5 100644 (file)
 
 #include <config.h>
 
-#include "buffer.h"
 #include "BufferView.h"
+#include "buffer.h"
 #include "cursor.h"
 #include "debug.h"
 #include "dispatchresult.h"
+#include "encoding.h"
 #include "funcrequest.h"
 #include "iterators.h"
+#include "language.h"
 #include "lfuns.h"
+#include "lyxfont.h"
 #include "lyxfunc.h" // only for setMessage()
 #include "lyxrc.h"
 #include "lyxrow.h"
 #include "lyxtext.h"
 #include "paragraph.h"
+#include "paragraph_funcs.h"
 
 #include "insets/updatableinset.h"
 #include "insets/insettabular.h"
@@ -57,7 +61,7 @@ limited_stack<string> theCutBuffer;
 
 
 LCursor::LCursor(BufferView & bv)
-       : DocumentIterator(bv), anchor_(bv),
+       : DocumentIterator(), bv_(&bv), anchor_(),
          cached_y_(0), x_target_(-1), selection_(false), mark_(false)
 {}
 
@@ -85,50 +89,33 @@ void LCursor::setCursor(DocumentIterator const & cur, bool sel)
 
 DispatchResult LCursor::dispatch(FuncRequest const & cmd0)
 {
+       if (empty())
+               return DispatchResult();
+
        //lyxerr << "\nLCursor::dispatch: cmd: " << cmd0 << endl << *this << endl;
-       BOOST_ASSERT(pos() <= lastpos());
-       BOOST_ASSERT(idx() <= lastidx());
-       BOOST_ASSERT(par() <= lastpar());
        FuncRequest cmd = cmd0;
        nopop_ = false;
-       DocumentIterator orig = *this;
-       disp_.update(true);
-       disp_.val(NONE);
-       while (size() != 1) {
-               // the inset's dispatch() is supposed to reset the update and
-               // val flags if necessary 
-               inset()->dispatch(*this, cmd);
-               
-               // "Mutate" the request for semi-handled requests that need
-               // additional handling in outer levels.
-               switch (disp_.val()) {
-                       case NONE:
-                               // the inset handled the event fully
-                               return DispatchResult(true, true);
-                       case FINISHED_LEFT:
-                               // the inset handled the event partially
-                               cmd = FuncRequest(LFUN_FINISHED_LEFT);
-                               break;
-                       case FINISHED_RIGHT:
-                               cmd = FuncRequest(LFUN_FINISHED_RIGHT);
-                               break;
-                       case FINISHED_UP:
-                               cmd = FuncRequest(LFUN_FINISHED_UP);
-                               break;
-                       case FINISHED_DOWN:
-                               cmd = FuncRequest(LFUN_FINISHED_DOWN);
-                               break;
-                       default:
-                               //lyxerr << "not handled on level " << depth()
-                               //      << " val: " << disp_.val() << endl;
-                               break;
-               }
-               pop();
+       DocumentIterator safe = *this;
+
+       for ( ; size(); pop_back()) {
+               lyxerr << "\nLCursor::dispatch: cmd: " << cmd0 << endl << *this << endl;
+               BOOST_ASSERT(pos() <= lastpos());
+               BOOST_ASSERT(idx() <= lastidx());
+               BOOST_ASSERT(par() <= lastpar());
+
+               // The common case is 'LFUN handled, need update', so make the 
+               // LFUN handler's life easier by assuming this as default value.
+               // The handler can reset the update and val flags if necessary.
+               disp_.update(true);
+               disp_.dispatched(true);
+               inset().dispatch(*this, cmd);
+               if (disp_.dispatched())
+                       break;
        }
-       bv().text()->dispatch(*this, cmd);
-       if (nopop_)
-               setCursor(orig, false);
-       //lyxerr << "   result: " << res.val() << endl;
+       // it completely to get a 'bomb early' behaviour in case this
+       // object will be used again.
+       if (nopop_ || !disp_.dispatched())
+               DocumentIterator::operator=(safe);
        return disp_;
 }
 
@@ -136,43 +123,30 @@ DispatchResult LCursor::dispatch(FuncRequest const & cmd0)
 bool LCursor::getStatus(FuncRequest const & cmd, FuncStatus & status)
 {
        lyxerr << "\nLCursor::getStatus: cmd: " << cmd << endl << *this << endl;
-       DocumentIterator orig = *this;
-       BOOST_ASSERT(pos() <= lastpos());
-       BOOST_ASSERT(idx() <= lastidx());
-       BOOST_ASSERT(par() <= lastpar());
-       for ( ; size() != 0; pop_back()) {
-               // the inset's getStatus() will return 'true' if it made
+       DocumentIterator safe = *this;
+       for ( ; size(); pop_back()) {
+               BOOST_ASSERT(pos() <= lastpos());
+               BOOST_ASSERT(idx() <= lastidx());
+               BOOST_ASSERT(par() <= lastpar());
+
+               // The inset's getStatus() will return 'true' if it made
                // a definitive decision on whether it want to handle the
                // request or not. The result of this decision is put into
                // the 'status' parameter.
-               bool const res = inset()->getStatus(*this, cmd, status);
-               if (res) {
-                       setCursor(orig, false);
-                       return true;
-               }
+               if (inset().getStatus(*this, cmd, status))
+                       break;
        }
-       bool const res = bv().text()->getStatus(*this, cmd, status);
-       setCursor(orig, false);
-       return res;
+       DocumentIterator::operator=(safe);
+       return true;
 }
 
 
 BufferView & LCursor::bv() const
 {
-       return DocumentIterator::bv();
+       return *bv_;
 }
 
 
-/*
-void LCursor::pop(int depth)
-{
-       while (int(size()) > depth + 1)
-               pop();
-       lyxerr << "LCursor::pop() result: " << *this << endl;
-}
-*/
-
-
 void LCursor::pop()
 {
        BOOST_ASSERT(size() >= 1);
@@ -181,18 +155,18 @@ void LCursor::pop()
 }
 
 
-void LCursor::push(InsetBase * p)
+void LCursor::push(InsetBase & p)
 {
        push_back(CursorSlice(p));
 }
 
 
-void LCursor::pushLeft(InsetBase * p)
+void LCursor::pushLeft(InsetBase & p)
 {
        BOOST_ASSERT(!empty());
        //lyxerr << "Entering inset " << t << " left" << endl;
        push(p);
-       p->idxFirst(*this);
+       p.idxFirst(*this);
 }
 
 
@@ -202,10 +176,10 @@ bool LCursor::popLeft()
        //lyxerr << "Leaving inset to the left" << endl;
        if (depth() <= 1) {
                if (depth() == 1)
-                       inset()->notifyCursorLeaves(idx());
+                       inset().notifyCursorLeaves(idx());
                return false;
        }
-       inset()->notifyCursorLeaves(idx());
+       inset().notifyCursorLeaves(idx());
        pop();
        return true;
 }
@@ -217,10 +191,10 @@ bool LCursor::popRight()
        //lyxerr << "Leaving inset to the right" << endl;
        if (depth() <= 1) {
                if (depth() == 1)
-                       inset()->notifyCursorLeaves(idx());
+                       inset().notifyCursorLeaves(idx());
                return false;
        }
-       inset()->notifyCursorLeaves(idx());
+       inset().notifyCursorLeaves(idx());
        pop();
        ++pos();
        return true;
@@ -231,7 +205,7 @@ int LCursor::currentMode()
 {
        BOOST_ASSERT(!empty());
        for (int i = size() - 1; i >= 1; --i) {
-               int res = operator[](i).inset()->currentMode();
+               int res = operator[](i).inset().currentMode();
                if (res != MathInset::UNDECIDED_MODE)
                        return res;
        }
@@ -243,55 +217,46 @@ void LCursor::updatePos()
 {
        BOOST_ASSERT(!empty());
        if (size() > 1)
-               cached_y_ = bv().top_y() + back().inset()->yo();
-               //cached_y_ = back().inset()->yo();
+               cached_y_ = bv().top_y() + back().inset().yo();
+               //cached_y_ = back().inset().yo();
 }
 
 
 void LCursor::getDim(int & asc, int & des) const
 {
-       BOOST_ASSERT(!empty());
        if (inMathed()) {
-               BOOST_ASSERT(inset());
-               BOOST_ASSERT(inset()->asMathInset());
-               //inset()->asMathInset()->getCursorDim(asc, des);
+               BOOST_ASSERT(inset().asMathInset());
+               //inset().asMathInset()->getCursorDim(asc, des);
                asc = 10;
                des = 10;
-       } else {
+       } else if (inTexted()) {
                Row const & row = textRow();
                asc = row.baseline();
                des = row.height() - asc;
+       } else {
+               lyxerr << "should this happen?" << endl;
+               asc = 10;
+               des = 10;
        }
 }
 
 
 void LCursor::getPos(int & x, int & y) const
 {
-       BOOST_ASSERT(!empty());
        x = 0;
        y = 0;
-       if (size() == 1) {
-               x = bv().text()->cursorX(front());
-               y = bv().text()->cursorY(front());
-       } else {
-               if (!inset()) {
-                       lyxerr << "#### LCursor::getPos: " << *this << endl;
-                       BOOST_ASSERT(inset());
-               }
-               inset()->getCursorPos(back(), x, y);
-               // getCursorPos gives _screen_ coordinates. We need to add
-               // top_y to get document coordinates. This is hidden in cached_y_.
-               //y += cached_y_ - inset()->yo();
-               // The rest is non-obvious. The reason we have to have these
-               // extra computation is that the getCursorPos() calls rely
-               // on the inset's own knowledge of its screen position.
-               // If we scroll up or down in a big enough increment,
-               // inset->draw() is not called: this doesn't update
-               // inset.yo_, so getCursor() returns an old value.
-               // Ugly as you like.
-       }
-       //lyxerr << "#### LCursor::getPos: " << *this 
-       // << " x: " << x << " y: " << y << endl;
+       if (!empty())
+               inset().getCursorPos(back(), x, y);
+       // getCursorPos gives _screen_ coordinates. We need to add
+       // top_y to get document coordinates. This is hidden in cached_y_.
+       //y += cached_y_ - inset().yo();
+       // The rest is non-obvious. The reason we have to have these
+       // extra computation is that the getCursorPos() calls rely
+       // on the inset's own knowledge of its screen position.
+       // If we scroll up or down in a big enough increment,
+       // inset->draw() is not called: this doesn't update
+       // inset.yo_, so getCursor() returns an old value.
+       // Ugly as you like.
 }
 
 
@@ -421,7 +386,7 @@ void LCursor::clearTargetX()
 void LCursor::info(std::ostream & os) const
 {
        for (int i = 1, n = depth(); i < n; ++i) {
-               operator[](i).inset()->infoize(os);
+               operator[](i).inset().infoize(os);
                os << "  ";
        }
        if (pos() != 0)
@@ -437,13 +402,13 @@ 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_);
+       InsetBase & p = i1.inset();
+       c1 = p.col(i1.idx_);
+       c2 = p.col(i2.idx_);
        if (c1 > c2)
                swap(c1, c2);
-       r1 = p->row(i1.idx_);
-       r2 = p->row(i2.idx_);
+       r1 = p.row(i1.idx_);
+       r2 = p.row(i2.idx_);
        if (r1 > r2)
                swap(r1, r2);
 }
@@ -460,7 +425,7 @@ string LCursor::grabSelection()
        CursorSlice i2 = selEnd();
 
        if (i1.idx_ == i2.idx_) {
-               if (i1.inset()->asMathInset()) {
+               if (i1.inset().asMathInset()) {
                        MathArray::const_iterator it = i1.cell().begin();
                        return asString(MathArray(it + i1.pos_, it + i2.pos_));
                } else {
@@ -473,7 +438,7 @@ string LCursor::grabSelection()
        region(i1, i2, r1, r2, c1, c2);
 
        string data;
-       if (i1.inset()->asMathInset()) {
+       if (i1.inset().asMathInset()) {
                for (row_type row = r1; row <= r2; ++row) {
                        if (row > r1)
                                data += "\\\\";
@@ -496,7 +461,7 @@ void LCursor::eraseSelection()
        CursorSlice const & i1 = selBegin();
        CursorSlice const & i2 = selEnd();
 #warning FIXME
-       if (i1.inset()->asMathInset()) {
+       if (i1.inset().asMathInset()) {
                if (i1.idx_ == i2.idx_) {
                        i1.cell().erase(i1.pos_, i2.pos_);
                } else {
@@ -626,7 +591,7 @@ std::ostream & operator<<(std::ostream & os, LCursor const & cur)
 bool LCursor::isInside(InsetBase const * p)
 {
        for (unsigned i = 0; i < depth(); ++i)
-               if (operator[](i).inset() == p)
+               if (&operator[](i).inset() == p)
                        return true;
        return false;
 }
@@ -646,7 +611,7 @@ bool LCursor::openable(MathAtom const & t) const
        // we can't move into anything new during selection
        if (depth() == anchor_.size())
                return false;
-       if (!ptr_cmp(t.nucleus(), anchor_[depth()].inset()))
+       if (!ptr_cmp(t.nucleus(), &anchor_[depth()].inset()))
                return false;
 
        return true;
@@ -662,7 +627,7 @@ bool positionable(DocumentIterator const & cursor,
 
        // anchor might be deeper, should have same path then
        for (size_t i = 0; i < cursor.size(); ++i)
-               if (cursor[i].inset() != anchor[i].inset())
+               if (&cursor[i].inset() != &anchor[i].inset())
                        return false;
 
        // position should be ok.
@@ -712,23 +677,21 @@ void LCursor::plainInsert(MathAtom const & t)
 void LCursor::insert(string const & str)
 {
        lyxerr << "LCursor::insert str '" << str << "'" << endl;
-       selClearOrDel();
-#if 0
        for (string::const_iterator it = str.begin(); it != str.end(); ++it)
-               plainInsert(MathAtom(new MathCharInset(*it)));
-#else
-       MathArray ar;
-       asArray(str, ar);
-       insert(ar);
-#endif
+               insert(*it);
 }
 
 
 void LCursor::insert(char c)
 {
        //lyxerr << "LCursor::insert char '" << c << "'" << endl;
-       selClearOrDel();
-       plainInsert(MathAtom(new MathCharInset(c)));
+       BOOST_ASSERT(!empty());
+       if (inMathed()) {
+               selClearOrDel();
+               plainInsert(MathAtom(new MathCharInset(c)));
+       } else {
+               text()->insertChar(*this, c);
+       }
 }
 
 
@@ -771,7 +734,7 @@ void LCursor::niceInsert(MathAtom const & t)
                posLeft();
                // be careful here: don't use 'pushLeft(t)' as this we need to
                // push the clone, not the original
-               pushLeft(nextAtom().nucleus());
+               pushLeft(*nextInset());
                paste(safe);
        }
 }
@@ -797,7 +760,7 @@ bool LCursor::backspace()
        }
 
        if (pos() == 0) {
-               if (inset()->nargs() == 1 && depth() == 1 && lastpos() == 0)
+               if (inset().nargs() == 1 && depth() == 1 && lastpos() == 0)
                        return false;
                pullArg();
                return true;
@@ -836,23 +799,23 @@ bool LCursor::erase()
        }
 
        // delete empty cells if possible
-       if (pos() == lastpos() && inset()->idxDelete(idx()))
+       if (pos() == lastpos() && inset().idxDelete(idx()))
                return true;
 
        // special behaviour when in last position of cell
        if (pos() == lastpos()) {
-               bool one_cell = inset()->nargs() == 1;
+               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());
+                       inset().idxGlue(idx());
                return true;
        }
 
-       if (pos() != lastpos() && inset()->nargs() > 0) {
+       if (pos() != lastpos() && inset().nargs() > 0) {
                selection() = true;
                ++pos();
        } else {
@@ -925,7 +888,7 @@ void LCursor::handleNest(MathAtom const & a, int c)
        asArray(grabAndEraseSelection(), t.nucleus()->cell(c));
        insert(t);
        posLeft();
-       pushLeft(nextAtom().nucleus());
+       pushLeft(*nextInset());
 }
 
 
@@ -943,7 +906,7 @@ int LCursor::targetX() const
 MathHullInset * LCursor::formula() const
 {
        for (int i = size() - 1; i >= 1; --i) {
-               MathInset * inset = operator[](i).inset()->asMathInset();
+               MathInset * inset = operator[](i).inset().asMathInset();
                if (inset && inset->asHullInset())
                        return static_cast<MathHullInset *>(inset);
        }
@@ -987,7 +950,7 @@ bool LCursor::inMacroArgMode() const
 MathGridInset * LCursor::enclosingGrid(idx_type & idx) const
 {
        for (MathInset::difference_type i = depth() - 1; i >= 0; --i) {
-               MathInset * m = operator[](i).inset()->asMathInset();
+               MathInset * m = operator[](i).inset().asMathInset();
                if (!m)
                        return 0;
                MathGridInset * p = m->asGridInset();
@@ -1031,7 +994,7 @@ void LCursor::normalize()
        if (idx() >= nargs()) {
                lyxerr << "this should not really happen - 1: "
                       << idx() << ' ' << nargs()
-                      << " in: " << inset() << endl;
+                      << " in: " << &inset() << endl;
        }
        idx() = min(idx(), lastidx());
 
@@ -1040,7 +1003,7 @@ void LCursor::normalize()
                        << pos() << ' ' << lastpos() <<  " in idx: " << idx()
                       << " in atom: '";
                WriteStream wi(lyxerr, false, true);
-               inset()->asMathInset()->write(wi);
+               inset().asMathInset()->write(wi);
                lyxerr << endl;
        }
        pos() = min(pos(), lastpos());
@@ -1108,7 +1071,7 @@ bool LCursor::goUpDown(bool up)
        }
 
        // try current cell for e.g. text insets
-       if (inset()->idxUpDown2(*this, up))
+       if (inset().idxUpDown2(*this, up))
                return true;
 
        //xarray().boundingBox(xlow, xhigh, ylow, yhigh);
@@ -1123,9 +1086,9 @@ bool LCursor::goUpDown(bool up)
 
        // try to find an inset that knows better then we
        while (1) {
-               //lyxerr << "updown: We are in " << inset() << " idx: " << idx() << endl;
+               //lyxerr << "updown: We are in " << &inset() << " idx: " << idx() << endl;
                // ask inset first
-               if (inset()->idxUpDown(*this, up)) {
+               if (inset().idxUpDown(*this, up)) {
                        // try to find best position within this inset
                        if (!selection())
                                bruteFind2(xo, yo);
@@ -1155,17 +1118,17 @@ bool LCursor::goUpDown(bool up)
 
 bool LCursor::bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh)
 {
-       DocumentIterator best_cursor(bv());
+       DocumentIterator best_cursor;
        double best_dist = 1e10;
 
-       DocumentIterator it = bufferBegin(bv());
-       DocumentIterator et = bufferEnd();
+       DocumentIterator it = insetBegin(bv().buffer()->inset());
+       DocumentIterator et = insetEnd();
        while (1) {
                // avoid invalid nesting when selecting
                if (!selection() || positionable(it, anchor_)) {
                        int xo, yo;
                        CursorSlice & cur = it.back();
-                       cur.inset()->getCursorPos(cur, xo, yo);
+                       cur.inset().getCursorPos(cur, 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;
@@ -1200,7 +1163,7 @@ void LCursor::bruteFind2(int x, int y)
        for (int i = 0; ; ++i) {
                int xo, yo;
                CursorSlice & cur = it.back();
-               cur.inset()->getCursorPos(cur, xo, yo);
+               cur.inset().getCursorPos(cur, 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'
@@ -1314,7 +1277,7 @@ string LCursor::selectionAsString(bool label) const
                return result;
        }
 
-#warning an mathed?
+#warning and mathed?
        return string();
 }
 
@@ -1326,7 +1289,11 @@ string LCursor::currentState()
                info(os);
                return os.str();
        }
-       return text() ? text()->currentState(*this) : string();
+
+       if (inTexted())
+        return text()->currentState(*this);
+
+       return string();
 }
 
 
@@ -1357,15 +1324,30 @@ string LCursor::getPossibleLabel()
 }
 
 
-void LCursor::undispatched()
+Encoding const * LCursor::getEncoding() const
 {
-       disp_.dispatched(false);
+       if (empty())
+               return 0;
+       if (!bv().buffer())
+               return 0;
+       int s = 0;
+       // go up until first non-0 text is hit
+       // (innermost text is 0 in mathed)
+       for (s = size() - 1; s >= 0; --s)
+               if (operator[](s).text())
+                       break;
+       CursorSlice const & sl = operator[](s);
+       LyXText & text = *sl.text();
+       ParagraphList::iterator pit = text.getPar(sl.par());
+       LyXFont font = pit->getFont(
+               bv().buffer()->params(), sl.pos(), outerFont(pit, text.paragraphs()));  
+       return font.language()->encoding();
 }
 
 
-void LCursor::dispatched(dispatch_result_t res)
+void LCursor::undispatched()
 {
-       disp_.val(res);
+       disp_.dispatched(false);
 }
 
 
@@ -1373,9 +1355,3 @@ void LCursor::noUpdate()
 {
        disp_.update(false);
 }
-
-
-void LCursor::noPop()
-{
-       nopop_ = true;
-}
index 6654f1660b3c316d9a8c888ab9ddfcd18abb3289..f2dbf1b3a04db21673ba6f8251994a38690e25ea 100644 (file)
 #include <iosfwd>
 #include <vector>
 
-class UpdatableInset;
-class DispatchResult;
+class BufferView;
 class FuncStatus;
 class FuncRequest;
-class InsetTabular;
 
 // these should go
 class MathHullInset;
 class MathUnknownInset;
 class MathGridInset;
+class Encoding;
 
 
 /// The cursor class describes the position of a cursor within a document.
@@ -36,18 +35,18 @@ class MathGridInset;
 // (or maybe private inheritance) at some point of time.
 class LCursor : public DocumentIterator {
 public:
-
        /// create the cursor of a BufferView
        explicit LCursor(BufferView & bv);
+
        /// dispatch from innermost inset upwards
        DispatchResult dispatch(FuncRequest const & cmd);
        /// are we willing to handle this event?
        bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
 
        /// add a new cursor slice
-       void push(InsetBase * inset);
+       void push(InsetBase & inset);
        /// add a new cursor slice, place cursor on left end
-       void pushLeft(InsetBase * inset);
+       void pushLeft(InsetBase & inset);
        /// pop one level off the cursor
        void pop();
        /// pop one slice off the cursor stack and go left
@@ -167,9 +166,7 @@ public:
        void replaceWord(std::string const & replacestring);
        /// update our view
        void update();
-       /// set dispatch result
-       void dispatched(dispatch_result_t res);
-       /// assume event was not (yet) dispatched
+       /// the event was not (yet) dispatched
        void undispatched();
        /// don't call update() when done
        void noUpdate();
@@ -178,7 +175,10 @@ public:
 
        /// output
        friend std::ostream & operator<<(std::ostream & os, LCursor const & cur);
+
 public:
+       ///
+       BufferView * bv_;
 //private:
        /// the anchor position
        DocumentIterator anchor_;
@@ -202,11 +202,12 @@ private:
         * shorter than x()
         */
        int x_target_;
-       // do we have a selection?
+       /// do we have a selection?
        bool selection_;
-       // are we on the way to get one?
+       /// are we on the way to get one?
        bool mark_;
-       ///
+       /// Reset cursor to the value it had at the beginning of the latest
+       // dispatch() once the event is fully handled.
        bool nopop_;
 
        //
@@ -316,6 +317,8 @@ public:
        int macroNamePos();
        /// can we enter the inset?
        bool openable(MathAtom const &) const;
+       ///
+       Encoding const * getEncoding() const;
 };
 
 #endif // LYXCURSOR_H
index 746ab78224860e551eb0d8eb31619789801bb08c..7528be9d4337a6248f5777747a4065cb43748148 100644 (file)
@@ -34,8 +34,8 @@ CursorSlice::CursorSlice()
 {}
 
 
-CursorSlice::CursorSlice(InsetBase * p)
-       : inset_(p), idx_(0), par_(0), pos_(0), boundary_(false)
+CursorSlice::CursorSlice(InsetBase & p)
+       : inset_(&p), idx_(0), par_(0), pos_(0), boundary_(false)
 {
        ///BOOST_ASSERT(inset_);
 }
@@ -100,7 +100,8 @@ CursorSlice::pos_type & CursorSlice::pos()
 
 CursorSlice::pos_type CursorSlice::lastpos() const
 {
-       return (inset_ && inset_->asMathInset()) ? cell().size() : paragraph().size();
+       BOOST_ASSERT(inset_);
+       return inset_->asMathInset() ? cell().size() : paragraph().size();
 }
 
 
@@ -132,13 +133,15 @@ CursorSlice::col_type CursorSlice::col() const
 
 MathInset * CursorSlice::asMathInset() const
 {
-       return inset_ ? inset_->asMathInset() : 0;
+       BOOST_ASSERT(inset_);
+       return inset_->asMathInset();
 }
 
 
 UpdatableInset * CursorSlice::asUpdatableInset() const
 {
-       return inset_ ? inset_->asUpdatableInset() : 0;
+       BOOST_ASSERT(inset_);
+       return inset_->asUpdatableInset();
 }
 
 
@@ -151,7 +154,8 @@ MathArray & CursorSlice::cell() const
 
 LyXText * CursorSlice::text() const
 {
-       return inset_ ? inset_->getText(idx_) : 0;
+       BOOST_ASSERT(inset_);
+       return inset_->getText(idx_);
 }
 
 
@@ -212,7 +216,7 @@ bool operator>(CursorSlice const & p, CursorSlice const & q)
 
 std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
 {
-       os
+       return os
           << "inset: " << item.inset_
 //        << " text: " << item.text()
           << " idx: " << item.idx_
@@ -221,5 +225,4 @@ std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
 //        << " x: " << item.inset_->x()
 //        << " y: " << item.inset_->y()
 ;
-       return os;
 }
index 33770a54216f06bc0e9858d57a057952a415fe6c..d3a24aef6c362bd5d3c42127c74cafafc898ed2b 100644 (file)
@@ -54,10 +54,10 @@ public:
        ///
        CursorSlice();
        ///
-       explicit CursorSlice(InsetBase *);
+       explicit CursorSlice(InsetBase &);
 
        /// the current inset
-       InsetBase * inset() const { return inset_; }
+       InsetBase & inset() const { return *inset_; }
        /// return the cell this cursor is in
        idx_type idx() const;
        /// return the cell this cursor is in
index d5492172fab02784edae953e571e8b71ae3ca6a1..d5133fd5a1f3c5aa75068aff026ff6e0d4e59c30 100644 (file)
 #ifndef DISPATCH_RESULT_H
 #define DISPATCH_RESULT_H
 
-/** Dispatch result codes
-       NONE                = no special action required
-       FINISHED_LEFT       = the cursor leaves the inset to the LEFT
-                             as consequence of this action
-       FINISHED_RIGHT      = FINISHED, but move the cursor RIGHT from
-                       the inset.
-       FINISHED_UP         = FINISHED, but move the cursor UP from
-                       the inset.
-       FINISHED_DOWN       = FINISHED, but move the cursor DOWN from
-                       the inset.
-*/
-enum dispatch_result_t {
-       NONE = 0,
-       FINISHED_LEFT,
-       FINISHED_RIGHT,
-       FINISHED_UP,
-       FINISHED_DOWN
-};
-
-
-/** \c DispatchResult is a wrapper for dispatch_result_t.
- *  It can be forward-declared and passed as a function argument without
- *  having to expose insetbase.h.
- */
+/// Maybe this can go entirely
 class DispatchResult {
 public:
-       DispatchResult()
-               : dispatched_(false), val_(NONE) {}
-       explicit
-       DispatchResult(bool dis)
-               : dispatched_(dis), update_(false), val_(NONE) {}
-       DispatchResult(bool dis, bool update)
-               : dispatched_(dis), update_(update), val_(NONE) {}
-       DispatchResult(bool dis, dispatch_result_t val)
-               : dispatched_(dis), update_(true), val_(val) {}
-       dispatch_result_t val() const { return val_; }
-       void val(dispatch_result_t drt) {
-               val_ = drt;
-       }
-       bool dispatched() const {
-               return dispatched_;
-       }
-       void dispatched(bool dis) {
-               dispatched_ = dis;
-       }
-       bool update() const {
-               return update_;
-       }
-       void update(bool up) {
-               update_ = up;
-       }
+       ///
+       DispatchResult() : dispatched_(false), update_(false) {}
+       ///
+       DispatchResult(bool disp, bool upd) : dispatched_(disp), update_(upd) {}
+       //
+       bool dispatched() const { return dispatched_; }
+       ///
+       void dispatched(bool disp) { dispatched_ = disp; }
+       ///
+       bool update() const { return update_; }
+       ///
+       void update(bool up) { update_ = up; }
 private:
+       /// was the event fully dispatched?
        bool dispatched_;
+       /// do we need to redraw the screen afterwards?
        bool update_;
-       dispatch_result_t val_;
 };
 
-
-inline
-bool operator==(DispatchResult const & lhs, DispatchResult const & rhs)
-{
-       return lhs.dispatched() == rhs.dispatched() && lhs.val() == rhs.val();
-}
-
-
-inline
-bool operator!=(DispatchResult const & lhs, DispatchResult const & rhs)
-{
-       return !(lhs == rhs);
-}
-
 #endif // DISPATCH_RESULT_H
index 1293fb3d0223d59a723bfa73fcd23feeb820b096..b8baa1a28e48b5450f3d470d8cdaa1eb3072353b 100644 (file)
@@ -1,7 +1,6 @@
 
 #include "dociterator.h"
 
-#include "BufferView.h"
 #include "debug.h"
 #include "lyxtext.h"
 #include "lyxrow.h"
 #include <boost/assert.hpp>
 
 
-
-DocumentIterator::DocumentIterator()
-       : bv_(0)
-{}
-
-
-DocumentIterator::DocumentIterator(BufferView & bv)
-       : std::vector<CursorSlice>(1), bv_(&bv)
-{}
-
-
 InsetBase * DocumentIterator::nextInset()
 {
        if (pos() == lastpos())
@@ -84,21 +72,21 @@ MathAtom & DocumentIterator::nextAtom()
 
 LyXText * DocumentIterator::text() const
 {
-       return size() > 1 ? top().text() : bv().text();
+       return top().text();
 }
 
 
 Paragraph & DocumentIterator::paragraph()
 {
        BOOST_ASSERT(inTexted());
-       return size() > 1 ? top().paragraph() : *bv().text()->getPar(par());
+       return top().paragraph();
 }
 
 
 Paragraph const & DocumentIterator::paragraph() const
 {
        BOOST_ASSERT(inTexted());
-       return size() > 1 ? top().paragraph() : *bv().text()->getPar(par());
+       return top().paragraph();
 }
 
 
@@ -140,100 +128,84 @@ DocumentIterator::row_type DocumentIterator::lastcrow() const
 
 DocumentIterator::idx_type DocumentIterator::lastidx() const
 {
-       return size() > 1 ? top().lastidx() : 0;
+       return top().lastidx();
 }
 
 
 size_t DocumentIterator::nargs() const
 {
        // assume 1x1 grid for main text
-       return size() > 1 ? top().nargs() : 1;
+       return top().nargs();
 }
 
 
 size_t DocumentIterator::ncols() const
 {
        // assume 1x1 grid for main text
-       return size() > 1 ? top().ncols() : 1;
+       return top().ncols();
 }
 
 
 size_t DocumentIterator::nrows() const
 {
        // assume 1x1 grid for main text
-       return size() > 1 ? top().nrows() : 1;
+       return top().nrows();
 }
 
 
 DocumentIterator::row_type DocumentIterator::row() const
 {
-       return size() > 1 ? top().row() : 0;
+       return top().row();
 }
 
 
 DocumentIterator::col_type DocumentIterator::col() const
 {
-       return size() > 1 ? top().col() : 0;
+       return top().col();
 }
 
 
 MathArray const & DocumentIterator::cell() const
 {
-       BOOST_ASSERT(size() > 1);
+       BOOST_ASSERT(inMathed());
        return top().cell();
 }
 
 
 MathArray & DocumentIterator::cell()
 {
-       BOOST_ASSERT(size() > 1);
+       BOOST_ASSERT(inMathed());
        return top().cell();
 }
 
 
 bool DocumentIterator::inMathed() const
 {
-       return size() > 1 && inset()->inMathed();
+       return !empty() && inset().inMathed();
 }
 
 
 bool DocumentIterator::inTexted() const
 {
-       return !inMathed();
+       return !empty() && !inset().inMathed();
 }
 
 
 LyXText * DocumentIterator::innerText() const
 {
        BOOST_ASSERT(!empty());
-       if (size() > 1) {
-               // go up until first non-0 text is hit
-               // (innermost text is 0 in mathed)
-               for (int i = size() - 1; i >= 1; --i)
-                       if (operator[](i).text())
-                               return operator[](i).text();
-       }
-       return bv().text();
-}
-
-
-CursorSlice const & DocumentIterator::innerTextSlice() const
-{
-       BOOST_ASSERT(!empty());
-       if (size() > 1) {
-               // go up until first non-0 text is hit
-               // (innermost text is 0 in mathed)
-               for (int i = size() - 1; i >= 1; --i)
-                       if (operator[](i).text())
-                               return operator[](i);
-       }
-       return operator[](0);
+       // go up until first non-0 text is hit
+       // (innermost text is 0 in mathed)
+       for (int i = size() - 1; i >= 0; --i)
+               if (operator[](i).text())
+                       return operator[](i).text();
+       return 0;
 }
 
 
 InsetBase * DocumentIterator::innerInsetOfType(int code) const
 {
-       for (int i = size() - 1; i >= 1; --i)
+       for (int i = size() - 1; i >= 0; --i)
                if (operator[](i).inset_->lyxCode() == code)
                        return operator[](i).inset_;
        return 0;
@@ -259,7 +231,7 @@ void DocumentIterator::forwardPos()
 
        if (n && n->isActive()) {
                //lyxerr << "... descend" << std::endl;
-               push_back(CursorSlice(n));
+               push_back(CursorSlice(*n));
                return;
        }
 
@@ -287,7 +259,7 @@ void DocumentIterator::forwardPos()
                ++top.idx();
                top.par() = 0;
                top.pos() = 0;
-               if (top.inset() && top.inset()->validCell(top.idx())) {
+               if (top.inset().validCell(top.idx())) {
                        //lyxerr << "     ... ok" << std::endl;
                        return;
                }
@@ -323,7 +295,7 @@ void DocumentIterator::forwardPar()
 
        if (n && n->isActive()) {
                lyxerr << "... descend" << std::endl;
-               push_back(CursorSlice(n));
+               push_back(CursorSlice(*n));
                return;
        }
 
@@ -350,7 +322,7 @@ void DocumentIterator::forwardPar()
                ++top.idx();
                top.par() = 0;
                top.pos() = 0;
-               if (top.inset() && top.inset()->validCell(top.idx())) {
+               if (top.inset().validCell(top.idx())) {
                        lyxerr << "     ... ok" << std::endl;
                        return;
                }
@@ -364,22 +336,10 @@ void DocumentIterator::forwardPar()
 }
 
 
-DocumentIterator bufferBegin(BufferView & bv)
-{
-       return DocumentIterator(bv);
-}
-
-
-DocumentIterator bufferEnd()
-{
-       return DocumentIterator();
-}
-
-
-DocumentIterator insetBegin(BufferView & bv, InsetBase * p)
+DocumentIterator insetBegin(InsetBase & inset)
 {
-       DocumentIterator it(bv);
-       it.back() = CursorSlice(p);
+       DocumentIterator it;
+       it.push_back(CursorSlice(inset));
        return it;
 }
 
@@ -392,7 +352,6 @@ DocumentIterator insetEnd()
 
 std::ostream & operator<<(std::ostream & os, DocumentIterator const & dit)
 {
-       os << "bv: " << &dit.bv() << "\n";
        for (size_t i = 0, n = dit.size(); i != n; ++i)
                os << " " << dit.operator[](i) << "\n";
        return os;
@@ -411,13 +370,11 @@ StableDocumentIterator::StableDocumentIterator(const DocumentIterator & dit)
 
 
 DocumentIterator
-StableDocumentIterator::asDocumentIterator(BufferView & bv) const
+StableDocumentIterator::asDocumentIterator(InsetBase * inset) const
 {
        // this function re-creates the cache of inset pointers
        //lyxerr << "converting:\n" << *this << std::endl;
-       DocumentIterator dit(bv);
-       dit.clear();
-       InsetBase * inset = 0;
+       DocumentIterator dit;
        for (size_t i = 0, n = data_.size(); i != n; ++i) {
                dit.push_back(data_[i]);
                dit.back().inset_ = inset;
index 22e49c8b455ecf6d9c2bbf8eaf82dd473c0a89e3..baff5c690e86b8153b620e215d36fd3df1723d09 100644 (file)
@@ -17,9 +17,8 @@
 #include <vector>
 #include <iosfwd>
 
-class BufferView;
-class MathAtom;
 class LyXText;
+class MathAtom;
 class Paragraph;
 class Row;
 
@@ -50,13 +49,6 @@ public:
        typedef CursorSlice::col_type col_type;
 
 public:
-       ///
-       DocumentIterator();
-       ///
-       explicit DocumentIterator(BufferView & bv);
-       ///
-       BufferView & bv() const { return *bv_; } 
-
        //
        // access to slice at tip
        //
@@ -67,7 +59,7 @@ public:
        /// how many nested insets do we have?
        size_t depth() const { return size(); }
        /// the containing inset
-       InsetBase * inset() const { return back().inset(); }
+       InsetBase & inset() const { return back().inset(); }
        /// return the cell of the inset this cursor is in
        idx_type idx() const { return back().idx(); }
        /// return the cell of the inset this cursor is in
@@ -151,8 +143,6 @@ public:
        ///
        LyXText * text() const;
        ///
-       CursorSlice const & innerTextSlice() const;
-       ///
        InsetBase * innerInsetOfType(int code) const;
        ///
        LyXText * innerText() const;
@@ -171,19 +161,11 @@ public:
        /// output
        friend std::ostream &
        operator<<(std::ostream & os, DocumentIterator const & cur);
-
-private:
-       ///
-       BufferView * bv_;       
 };
 
 
 ///
-DocumentIterator bufferBegin(BufferView & bv);
-///
-DocumentIterator bufferEnd();
-///
-DocumentIterator insetBegin(BufferView & bv, InsetBase * inset);
+DocumentIterator insetBegin(InsetBase & inset);
 ///
 DocumentIterator insetEnd();
 
@@ -199,7 +181,7 @@ public:
        /// non-explicit intended
        StableDocumentIterator(const DocumentIterator & it);
        ///
-       DocumentIterator asDocumentIterator(BufferView & bv) const;
+       DocumentIterator asDocumentIterator(InsetBase * start) const;
        ///
        size_t size() const { return data_.size(); }
        ///
index 11340acb54cd9e9e8f5518a40ecdf0c4835663c2..727939de48b7877834502a7c2ab17ba9234d64d4 100644 (file)
@@ -182,8 +182,7 @@ InsetBase * createInset(BufferView * bv, FuncRequest const & cmd)
                return 0;
 
        case LFUN_INSET_CAPTION: {
-               UpdatableInset * up = bv->cursor().inset()
-                       ? bv->cursor().inset()->asUpdatableInset() : 0;
+               UpdatableInset * up = bv->cursor().inset().asUpdatableInset();
                if (!up) {
                        auto_ptr<InsetCaption> inset(new InsetCaption(params));
                        inset->setOwner(up);
index 2a2309cf1616223701aa5046dbf663d5f8ac9622..93f30487b88fb6d6dda9f29aacfa36ac44f1f905 100644 (file)
@@ -259,7 +259,7 @@ void LyXScreen::redraw(BufferView & bv)
 
        // maybe we have to clear the screen at the bottom
        int const y2 = workarea().workHeight();
-       if (y < y2 && !bv.text()->isInInset()) {
+       if (y < y2 && bv.text()->isMainText()) {
                workarea().getPainter().fillRectangle(0, y,
                        workarea().workWidth(), y2 - y,
                        LColor::bottomarea);
index e9be990c99e226f83e04020241397f509ff34041..b24bb93356217a65ee3feb35961d723b07d5f107 100644 (file)
 
 
 
-void InsetBase::dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetBase::dispatch(LCursor & cur, FuncRequest & cmd)
 {
        priv_dispatch(cur, cmd);
 }
 
 
-void InsetBase::priv_dispatch(LCursor & cur, FuncRequest const &)
+void InsetBase::priv_dispatch(LCursor & cur, FuncRequest &)
 {
        cur.noUpdate();
        cur.undispatched();
index a47414d3fa4f01dd3232e4dd2b2bf15e1cd37c12..e9a045c8a87da8e51270acb8a5b6c15793e6664a 100644 (file)
@@ -71,7 +71,7 @@ public:
        virtual bool inMathed() const { return false; }
 
        // the real dispatcher
-       void dispatch(LCursor & cur, FuncRequest const & cmd);
+       void dispatch(LCursor & cur, FuncRequest & cmd);
        /// do we want to handle this event?
        virtual bool getStatus(LCursor & cur, FuncRequest const & cmd,
                FuncStatus & status);
@@ -351,7 +351,7 @@ public:
        virtual void addPreview(lyx::graphics::PreviewLoader &) const {}
 protected:
        // the real dispatcher
-       virtual void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+       virtual void priv_dispatch(LCursor & cur, FuncRequest & cmd);
 public:
        /// returns LyX code associated with the inset. Used for TOC, ...)
        virtual Code lyxCode() const { return NO_CODE; }
index 682d0f97a8e2005159af679a8286f066923c3dde..26790b6614253b045f054bf5bc3afd6cd41d9065 100644 (file)
@@ -53,7 +53,7 @@ auto_ptr<InsetBase> InsetBibitem::clone() const
 }
 
 
-void InsetBibitem::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetBibitem::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action) {
 
index 7f988b5803014c3a7c1821dd20e5a64ebd6cfe4e..05983fb25c691aa91d98fd3725e5b54374b59d79 100644 (file)
@@ -50,7 +50,7 @@ public:
        std::string const getBibLabel() const;
 protected:
        ///
-       virtual void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+       virtual void priv_dispatch(LCursor & cur, FuncRequest & cmd);
 private:
        ///
        int counter;
index 49dffcd6bed2cb077a7b7472bd2dce31dbde9561..6a7e97fdd8546f09d77a8c5f19c15b02afcc386c 100644 (file)
@@ -65,7 +65,7 @@ std::auto_ptr<InsetBase> InsetBibtex::clone() const
 }
 
 
-void InsetBibtex::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetBibtex::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action) {
 
index ea64e5efee77891da001fb17353bbfe68edc9558..cb6128226e54b850b48687950611720ece0ff35d 100644 (file)
@@ -46,7 +46,7 @@ public:
        bool delDatabase(std::string const &);
 protected:
        ///
-       virtual void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+       virtual void priv_dispatch(LCursor & cur, FuncRequest & cmd);
 };
 
 #endif // INSET_BIBTEX_H
index b57eae3d786e665073a985a5c285725832b0c6eb..93130f69bf0b3f0f4f8566aaaa3202c26ae2e304 100644 (file)
@@ -169,7 +169,7 @@ bool InsetBox::showInsetDialog(BufferView * bv) const
 }
 
 
-void InsetBox::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetBox::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action) {
 
index 4b4030625bec019badafa01c975b2f0ae3b72045..49281cbdf86b208af8b127617c1e4f193f82dbc6 100644 (file)
@@ -105,7 +105,7 @@ public:
        };
 protected:
        ///
-       virtual void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+       virtual void priv_dispatch(LCursor & cur, FuncRequest & cmd);
 private:
        friend class InsetBoxParams;
 
index 800e56ceb10debfe2094fad2508c54d4ed7a4ecf..9c3309ed35490426098702ec236dcd8b35f881f2 100644 (file)
@@ -110,7 +110,7 @@ bool InsetBranch::showInsetDialog(BufferView * bv) const
 }
 
 
-void InsetBranch::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetBranch::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action) {
        case LFUN_INSET_MODIFY: {
index aba81186a138976fbda7f31b0947dc8b16d504da..4cb870a15516c4a09af7e03fdab54b70683650e8 100644 (file)
@@ -81,7 +81,7 @@ public:
 
 protected:
        ///
-       virtual void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+       virtual void priv_dispatch(LCursor & cur, FuncRequest & cmd);
 private:
        friend class InsetBranchParams;
 
index 5c127a4648f66ba703b63ee523723ef5a9f5377d..81647143bac0813ef696d6fcc54770b836d5071b 100644 (file)
@@ -146,7 +146,7 @@ void InsetCharStyle::getDrawFont(LyXFont & font) const
 }
 
 
-void InsetCharStyle::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetCharStyle::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
        setStatus(Inlined);
        switch (cmd.action) {
index 88eed54511e76118bf7e5279626eec89a413c852..ca31e33357bdb1d83caf4d16ee74eb90ad8b1a19 100644 (file)
@@ -85,7 +85,7 @@ public:
 
 protected:
        ///
-       virtual void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+       virtual void priv_dispatch(LCursor & cur, FuncRequest & cmd);
 
 private:
        friend class InsetCharStyleParams;
index 9ae7b1541ac3160532b3e19fdb8eef370e1c2a7a..3b61fdfd6bb6120ae865e0640c5457fe5278c181 100644 (file)
@@ -205,7 +205,7 @@ bool InsetCollapsable::descendable() const
 }
 
 
-void InsetCollapsable::lfunMouseRelease(LCursor & cur, FuncRequest const & cmd)
+void InsetCollapsable::lfunMouseRelease(LCursor & cur, FuncRequest & cmd)
 {
        if (cmd.button() == mouse_button::button3) {
                showInsetDialog(&cur.bv());
@@ -225,7 +225,7 @@ void InsetCollapsable::lfunMouseRelease(LCursor & cur, FuncRequest const & cmd)
                if (hitButton(cmd1)) {
                        lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl;
                        setStatus(Collapsed);
-                       cur.dispatched(FINISHED_RIGHT);
+                       cmd = FuncRequest(LFUN_FINISHED_RIGHT);
                        break;
                }
                lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl;
@@ -268,7 +268,7 @@ int InsetCollapsable::docbook(Buffer const & buf, ostream & os,
 }
 
 
-bool InsetCollapsable::hitButton(FuncRequest const & cmd) const
+bool InsetCollapsable::hitButton(FuncRequest & cmd) const
 {
        return button_dim.contains(cmd.x, cmd.y);
 }
@@ -298,7 +298,7 @@ string const InsetCollapsable::getNewLabel(string const & l) const
 void InsetCollapsable::edit(LCursor & cur, bool left)
 {
        //lyxerr << "InsetCollapsable: edit left/right" << endl;
-       cur.push(this);
+       cur.push(*this);
        inset.edit(cur, left);
        open();
 }
@@ -306,7 +306,7 @@ void InsetCollapsable::edit(LCursor & cur, bool left)
 
 InsetBase * InsetCollapsable::editXY(LCursor & cur, int x, int y)
 {
-       cur.push(this);
+       cur.push(*this);
        //lyxerr << "InsetCollapsable: edit xy" << endl;
        if (status_ == Collapsed) {
                setStatus(Open);
@@ -320,7 +320,7 @@ InsetBase * InsetCollapsable::editXY(LCursor & cur, int x, int y)
 }
 
 
-void InsetCollapsable::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetCollapsable::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
        //lyxerr << "\nInsetCollapsable::priv_dispatch (begin): cmd: " << cmd
        //      << "  button y: " << button_dim.y2 << endl;
@@ -351,7 +351,7 @@ void InsetCollapsable::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
                                break;
                        }
                        setStatus(Collapsed);
-                       cur.dispatched(FINISHED_RIGHT);
+                       cmd = FuncRequest(LFUN_FINISHED_RIGHT);
                        break;
 
                default:
index 2ed7643435b5197a5b35d6715e4059b5ab91dfc9..c4866a1dcc6ab450b4b5e7c179a7913871f93470 100644 (file)
@@ -55,7 +55,7 @@ public:
        ///
        void drawSelection(PainterInfo & pi, int x, int y) const;
        ///
-       bool hitButton(FuncRequest const &) const;
+       bool hitButton(FuncRequest &) const;
        ///
        std::string const getNewLabel(std::string const & l) const;
        ///
@@ -123,7 +123,7 @@ public:
 
 protected:
        ///
-       void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+       void priv_dispatch(LCursor & cur, FuncRequest & cmd);
        ///
        void dimension_collapsed(Dimension &) const;
        ///
@@ -139,7 +139,7 @@ protected:
 
 private:
        ///
-       void lfunMouseRelease(LCursor & cur, FuncRequest const & cmd);
+       void lfunMouseRelease(LCursor & cur, FuncRequest & cmd);
 
 public:
        ///
index 0bb66e3e2359dd326dbbaa8b78a839d5282cbee7..40fde7b7fc81840200fab1ea004a36db611fd70b 100644 (file)
@@ -98,7 +98,7 @@ int InsetCommand::docbook(Buffer const &, ostream &,
 }
 
 
-void InsetCommand::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetCommand::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action) {
        case LFUN_INSET_MODIFY: {
index 4311621fe0396b91e500b60cfed565b0c4b70e79..1548d7c84d2eaa1d96be80e4365be517ad6bbed5 100644 (file)
@@ -76,7 +76,7 @@ public:
 
 protected:
        ///
-       void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+       void priv_dispatch(LCursor & cur, FuncRequest & cmd);
        ///
        std::string const getCommand() const { return p_.getCommand(); }
        ///
index 40aaff995954f47be01c224a4bab8c22c2ca05dc..b1495e77260c2e652496327757b815f1c87742cc 100644 (file)
@@ -208,7 +208,7 @@ int InsetERT::docbook(Buffer const &, ostream & os,
 }
 
 
-void InsetERT::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetERT::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
        //lyxerr << "\nInsetERT::priv_dispatch (begin): cmd: " << cmd << endl;
        switch (cmd.action) {
index 9927e45be0c0df07408afb5118ca33793aa6a7dd..6ae4d140a90802b8bdd0bccb44c782d221ba9d11 100644 (file)
@@ -74,7 +74,7 @@ public:
        bool forceDefaultParagraphs(InsetBase const *) const { return true; }
 protected:
        ///
-       virtual void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+       virtual void priv_dispatch(LCursor & cur, FuncRequest & cmd);
 private:
        ///
        void init();
index 9e27a11dfbf61ad910941d4e4c500b7fb1052788..870dcf6bee4b84326f1a6b2451d73060279be8c4 100644 (file)
@@ -442,7 +442,7 @@ void InsetExternal::statusChanged() const
 }
 
 
-void InsetExternal::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetExternal::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action) {
 
index c6b0c47a0e2a4b5c4622ec446ee184f60650c9eb..c2e38d952961f1ea96bff91291a64e850cf66be2 100644 (file)
@@ -151,7 +151,7 @@ public:
 
 protected:
        ///
-       void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+       void priv_dispatch(LCursor & cur, FuncRequest & cmd);
 private:
        /** This method is connected to the graphics loader, so we are
         *  informed when the image has been loaded.
index 4b00ff4a782265d32d7069193c1b299f283ca0ee..1d20cd0a9454385c858e5884ab19ec06026c4e93 100644 (file)
@@ -155,7 +155,7 @@ InsetFloat::~InsetFloat()
 }
 
 
-void InsetFloat::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetFloat::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action) {
 
index 8d69c1c05e04284e88b8c7df27c742426e9071aa..53f6e742beffb043e40c009f1dead14affe8e650 100644 (file)
@@ -78,7 +78,7 @@ public:
        ///
        InsetFloatParams const & params() const { return params_; }
 protected:
-       virtual void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+       virtual void priv_dispatch(LCursor & cur, FuncRequest & cmd);
 private:
        ///
        InsetFloatParams params_;
index 6b12a172c8576f4ef7667c8bcaf07d72026119cb..f4ab82716df2fe79f8295455d98d53f7a49c8846 100644 (file)
@@ -188,7 +188,7 @@ void InsetGraphics::statusChanged() const
 }
 
 
-void InsetGraphics::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetGraphics::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action) {
        case LFUN_INSET_MODIFY: {
index 60770ef658e671f8619a73b7884c2c7ec129581c..e36f49860fdcd711cdb65f59f826cbada0a8734f 100644 (file)
@@ -81,7 +81,7 @@ public:
        void edit(LCursor & cur, bool left);
 protected:
        ///
-       void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+       void priv_dispatch(LCursor & cur, FuncRequest & cmd);
 private:
        ///
        friend class InsetGraphicsMailer;
index adc479b396a5e1e5de9baf9a70b2aecbb1b4a9e7..fc34f9c63795f5586e7f62d04d7b31e523fd7bec 100644 (file)
@@ -112,7 +112,7 @@ InsetInclude::~InsetInclude()
 }
 
 
-void InsetInclude::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetInclude::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action) {
 
index 7e4340f56a465147bbfab26d529e92d229dfe59d..391940f0f71aaa71c6e6d7adf119647b60ed09bd 100644 (file)
@@ -83,7 +83,7 @@ public:
        void addPreview(lyx::graphics::PreviewLoader &) const;
 protected:
        ///
-       virtual void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+       virtual void priv_dispatch(LCursor & cur, FuncRequest & cmd);
 private:
        /// Slot receiving a signal that the preview is ready to display.
        void statusChanged() const;
index 42731136e5c443de62a8538f9a643e32f34323e1..e915f787ffc594cbb60f64c246b6b3a30ace0e32 100644 (file)
@@ -91,7 +91,7 @@ void changeRefsIfUnique(BufferView & bv, string const & from, string const & to)
 } // namespace anon
 
 
-void InsetLabel::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetLabel::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action) {
 
index 0a5adfccd2d58e1f86f690de000198b270775cc2..3d18632c0de63aa6a41b149179e459778e244a57 100644 (file)
@@ -42,7 +42,7 @@ public:
                    OutputParams const &) const;
 protected:
        ///
-       virtual void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+       virtual void priv_dispatch(LCursor & cur, FuncRequest & cmd);
 };
 
 #endif
index ba99588e4c6737133df39fd2fe3f1ce494b58b2e..a9b0cb966219da60a2e07f59e3b712c59f6ec150 100644 (file)
@@ -184,7 +184,7 @@ bool InsetNote::showInsetDialog(BufferView * bv) const
 }
 
 
-void InsetNote::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetNote::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action) {
 
index 83cb528ae750e036f61999f2fc622213f94aa5d1..65d05ce4cc9a65464bcdb2365d7394a8f4ce60f4 100644 (file)
@@ -75,7 +75,7 @@ public:
        InsetNoteParams const & params() const { return params_; }
 protected:
        ///
-       virtual void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+       virtual void priv_dispatch(LCursor & cur, FuncRequest & cmd);
 private:
        friend class InsetNoteParams;
 
index 490d5e58090dd593c703c67336cbfda8328fb5d8..c5394d499d141244cf33f503305379cdde12e5f9 100644 (file)
@@ -40,7 +40,7 @@ InsetRef::InsetRef(InsetRef const & ir)
 {}
 
 
-void InsetRef::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetRef::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action) {
        case LFUN_MOUSE_PRESS:
index 0fb54e4a0368e645bdf5fcccf74dc4be93edfdaa..239d3317f0e748514a8bcb304d0a83f1aae2a6ea 100644 (file)
@@ -65,7 +65,7 @@ public:
        void validate(LaTeXFeatures & features) const;
 protected:
        ///
-       void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+       void priv_dispatch(LCursor & cur, FuncRequest & cmd);
 private:
        ///
        bool isLatex;
index e12e7dd2e8308473557be942b325a7ee9fa3f0f1..1f45315603f1d6286b14d32295b4ec9b7fd3402e 100644 (file)
@@ -396,7 +396,7 @@ void InsetTabular::edit(LCursor & cur, bool left)
        cur.selection() = false;
        resetPos(cur);
        cur.bv().fitCursor();
-       cur.push(this);
+       cur.push(*this);
        cur.idx() = cell;
 }
 
@@ -405,13 +405,13 @@ InsetBase * InsetTabular::editXY(LCursor & cur, int x, int y)
 {
        //lyxerr << "InsetTabular::editXY: " << this << endl;
        cur.selection() = false;
-       cur.push(this);
+       cur.push(*this);
        return setPos(cur, x, y);
        //int xx = cursorx_ - xo_ + tabular.getBeginningOfTextInCell(actcell);
 }
 
 
-void InsetTabular::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetTabular::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
        lyxerr << "# InsetTabular::dispatch: cmd: " << cmd << endl;
        //lyxerr << "  cur:\n" << cur << endl;
@@ -469,27 +469,28 @@ void InsetTabular::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
        case LFUN_RIGHTSEL:
        case LFUN_RIGHT:
                cell(cur.idx()).dispatch(cur, cmd);
-               cur.dispatched(NONE); // override the cell's result
                if (sl == cur.top())
                        isRightToLeft(cur) ? movePrevCell(cur) : moveNextCell(cur);
-               if (sl == cur.top())
-                       cur.dispatched(FINISHED_RIGHT);
+               if (sl == cur.top()) {
+                       cmd = FuncRequest(LFUN_FINISHED_RIGHT);
+                       cur.undispatched();
+               }
                break;
 
        case LFUN_LEFTSEL: 
        case LFUN_LEFT:
                cell(cur.idx()).dispatch(cur, cmd);
-               cur.dispatched(NONE); // override the cell's result
                if (sl == cur.top())
                        isRightToLeft(cur) ? moveNextCell(cur) : movePrevCell(cur);
-               if (sl == cur.top())
-                       cur.dispatched(FINISHED_LEFT);
+               if (sl == cur.top()) {
+                       cmd = FuncRequest(LFUN_FINISHED_LEFT);
+                       cur.undispatched();
+               }
                break;
 
        case LFUN_DOWNSEL:
        case LFUN_DOWN:
                cell(cur.idx()).dispatch(cur, cmd);
-               cur.dispatched(NONE); // override the cell's result
                if (sl == cur.top())
                        if (tabular.row_of_cell(cur.idx()) != tabular.rows() - 1) {
                                cur.idx() = tabular.getCellBelow(cur.idx());
@@ -497,14 +498,15 @@ void InsetTabular::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
                                cur.pos() = 0;
                                resetPos(cur);
                        }
-               if (sl == cur.top())
-                       cur.dispatched(FINISHED_DOWN);
+               if (sl == cur.top()) {
+                       cmd = FuncRequest(LFUN_FINISHED_DOWN);
+                       cur.undispatched();
+               }
                break;
 
        case LFUN_UPSEL:
        case LFUN_UP:
                cell(cur.idx()).dispatch(cur, cmd);
-               cur.dispatched(NONE); // override the cell's result
                if (sl == cur.top())
                        if (tabular.row_of_cell(cur.idx()) != 0) {
                                cur.idx() = tabular.getCellAbove(cur.idx());
@@ -512,8 +514,10 @@ void InsetTabular::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
                                cur.pos() = cur.lastpos();
                                resetPos(cur);
                        }
-               if (sl == cur.top())
-                       cur.dispatched(FINISHED_UP);
+               if (sl == cur.top()) {
+                       cmd = FuncRequest(LFUN_FINISHED_UP);
+                       cur.undispatched();
+               }
                break;
 
        case LFUN_NEXT: {
index 9d4a7eac5097114aa7af666790df5f841da50d45..c37d692fe8f248a7000b25214c952671b69304e1 100644 (file)
@@ -151,7 +151,7 @@ public:
 
 protected:
        ///
-       void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+       void priv_dispatch(LCursor & cur, FuncRequest & cmd);
 private:
        ///
        void drawCellLines(Painter &, int x, int baseline,
index faf3173e58d6a2e4c996802ac92f60cc7e3e68ed..92adcd34a4fc2bb358894ff51065bd2b4dcdc594 100644 (file)
@@ -70,18 +70,18 @@ using std::vector;
 
 InsetText::InsetText(BufferParams const & bp)
        : autoBreakRows_(false), drawFrame_(NEVER),
-         frame_color_(LColor::insetframe), text_(0, true)
+         frame_color_(LColor::insetframe), text_(0)
 {
        paragraphs().push_back(Paragraph());
-       paragraphs().begin()->layout(bp.getLyXTextClass().defaultLayout());
+       paragraphs().back().layout(bp.getLyXTextClass().defaultLayout());
        if (bp.tracking_changes)
-               paragraphs().begin()->trackChanges();
+               paragraphs().back().trackChanges();
        init();
 }
 
 
 InsetText::InsetText(InsetText const & in)
-       : UpdatableInset(in), text_(in.text_.bv_owner, true)
+       : UpdatableInset(in), text_(in.text_.bv_owner)
 {
        // this is ugly...
        operator=(in);
@@ -94,7 +94,7 @@ void InsetText::operator=(InsetText const & in)
        autoBreakRows_ = in.autoBreakRows_;
        drawFrame_ = in.drawFrame_;
        frame_color_ = in.frame_color_;
-       text_ = LyXText(in.text_.bv_owner, true);
+       text_ = LyXText(in.text_.bv_owner);
        text_.paragraphs() = in.text_.paragraphs();
        init();
 }
@@ -294,7 +294,6 @@ void InsetText::edit(LCursor & cur, bool left)
        finishUndo();
        sanitizeEmptyText(cur.bv());
        updateLocal(cur);
-       dispatch(cur, FuncRequest(LFUN_PARAGRAPH_UPDATE));
 }
 
 
@@ -305,11 +304,10 @@ InsetBase * InsetText::editXY(LCursor & cur, int x, int y)
        return text_.editXY(cur, x, y);
        //sanitizeEmptyText(cur.bv());
        //updateLocal(cur);
-       //dispatch(cur, FuncRequest(LFUN_PARAGRAPH_UPDATE));
 }
 
 
-void InsetText::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetText::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
        //lyxerr << "InsetText::priv_dispatch (begin), act: "
        //      << cmd.action << " " << endl;
@@ -393,12 +391,10 @@ bool InsetText::insetAllowed(InsetOld::Code code) const
        // to allow us to call the owner's insetAllowed
        // without stack overflow, which can happen
        // when the owner uses InsetCollapsable::insetAllowed()
-       bool ret = true;
        if (in_insetAllowed)
-               return ret;
+               return true;
        in_insetAllowed = true;
-       if (owner())
-               ret = owner()->insetAllowed(code);
+       bool const ret = owner() && owner()->insetAllowed(code);
        in_insetAllowed = false;
        return ret;
 }
index d0ae16da7599e23bbdfae3e134da4cc27942f3e9..04985a1d5fc555852e0b49c37942aeb1b98dcac8 100644 (file)
@@ -156,7 +156,7 @@ public:
 
 private:
        ///
-       void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+       void priv_dispatch(LCursor & cur, FuncRequest & cmd);
        ///
        void updateLocal(LCursor &);
        ///
index 1938eee454606ffd45761d306a23083be0400e8d..5559fa325bda2b9322d63d2b1fe088fba8a320b8 100644 (file)
@@ -60,7 +60,7 @@ std::auto_ptr<InsetBase> InsetVSpace::clone() const
 }
 
 
-void InsetVSpace::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetVSpace::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action) {
 
index 58eca2979908fb2de1b5b978a01d31e805c352cc..b7e0ef444654c51fe54995a7c6add6a4159d373f 100644 (file)
@@ -54,7 +54,7 @@ public:
 
 protected:
        ///
-       virtual void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+       virtual void priv_dispatch(LCursor & cur, FuncRequest & cmd);
 
 private:
        ///
index 00e2caa97fd907e5ff0fecc1457fa6df09aa50d6..ec433af6eb8711e3865b9391ab8ca9cb3f0dd1a2 100644 (file)
@@ -80,7 +80,7 @@ InsetWrap::~InsetWrap()
 }
 
 
-void InsetWrap::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetWrap::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action) {
        case LFUN_INSET_MODIFY: {
index b7b1b6ca86943d2f126dc6c4ba17eb418c1d0798..bfd3f59c01bd639403f21f9f9e68e4f496b3e5a7 100644 (file)
@@ -68,7 +68,7 @@ public:
        InsetWrapParams const & params() const { return params_; }
 protected:
        ///
-       virtual void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+       virtual void priv_dispatch(LCursor & cur, FuncRequest & cmd);
 private:
        ///
        InsetWrapParams params_;
index 028f36a66374d7e1f50419666960544eebadbe26..6572ed47f82457211ddc75a870824d0bbb0c167b 100644 (file)
@@ -84,7 +84,7 @@ void UpdatableInset::scroll(BufferView & bv, int offset) const
 }
 
 
-void UpdatableInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void UpdatableInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action) {
        //case LFUN_MOUSE_RELEASE:
index b216b4e4429b55f50cb9be641a4fa34a3152dc74..c0c89b5682093656cfbb3668022c32ab762f1004 100644 (file)
@@ -38,7 +38,7 @@ public:
 
 protected:
        ///  An updatable inset could handle lyx editing commands
-       void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+       void priv_dispatch(LCursor & cur, FuncRequest & cmd);
        /// scrolls to absolute position in bufferview-workwidth * sx units
        void scroll(BufferView &, float sx) const;
        /// scrolls offset pixels
index 7f45fa4a337a9c31be56e76d523d1f3afd0646f3..41a3772a69a5ceecb0080de73080b66c006f865e 100644 (file)
@@ -174,7 +174,7 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym, key_modifier::state state)
                return;
        }
 
-       Encoding const * encoding = view()->getEncoding();
+       Encoding const * encoding = view()->cursor().getEncoding();
 
        encoded_last_key = keysym->getISOEncoded(encoding ? encoding->Name() : "");
 
@@ -309,8 +309,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
                }
        }
 
-       UpdatableInset * tli = cur.inset() ? cur.inset()->asUpdatableInset() : 0;
-
        // I would really like to avoid having this switch and rather try to
        // encode this in the function itself.
        bool disable = false;
@@ -352,8 +350,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
 
        case LFUN_LAYOUT:
        case LFUN_LAYOUT_PARAGRAPH:
-               disable = cur.inset()
-                       && cur.inset()->forceDefaultParagraphs(cur.inset());
+               disable = cur.inset().forceDefaultParagraphs(&cur.inset());
                break;
 
        case LFUN_INSET_OPTARG:
@@ -383,7 +380,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
                } else {
                        disable = true;
 
-                       char align = mathcursor::halign();
+                       char const align = mathcursor::halign();
                        if (align == '\0') {
                                disable = true;
                                break;
@@ -402,7 +399,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
                        break;
                }
 
-               if (tli) {
+               if (!cur.empty() && cur.inset().asUpdatableInset()) {
                        FuncStatus ret;
                        //ret.disabled(true);
                        InsetTabular * tab = static_cast<InsetTabular *>
@@ -455,9 +452,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
 
        case LFUN_INSET_SETTINGS: {
                disable = true;
-               if (!cur.inset())
-                       break;
-               UpdatableInset * inset = cur.inset()->asUpdatableInset();
+               UpdatableInset * inset = cur.inset().asUpdatableInset();
                if (!inset)
                        break;
 
@@ -515,25 +510,20 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
 
        case LFUN_DIALOG_SHOW: {
                string const name = cmd.getArg(0);
-               if (!buf) {
+               if (!buf)
                        disable = !(name == "aboutlyx" ||
                                    name == "file" ||
                                    name == "preferences" ||
                                    name == "texinfo");
-                       break;
-               }
-
-               if (name == "print") {
+               else if (name == "print")
                        disable = !Exporter::IsExportable(*buf, "dvi") ||
                                lyxrc.print_command == "none";
-               } else if (name == "character") {
-                       InsetBase * inset = cur.inset();
-                       disable = inset && inset->lyxCode() == InsetOld::ERT_CODE;
-               } else if (name == "vclog") {
+               else if (name == "character")
+                       disable = cur.inset().lyxCode() == InsetOld::ERT_CODE;
+               else if (name == "vclog")
                        disable = !buf->lyxvc().inUse();
-               } else if (name == "latexlog") {
+               else if (name == "latexlog")
                        disable = !IsFileReadable(buf->getLogName().second);
-               }
                break;
        }
 
@@ -687,7 +677,9 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
        default:
                break;
        }
-       if (code != InsetOld::NO_CODE && tli && !tli->insetAllowed(code))
+
+       if (code != InsetOld::NO_CODE
+                       && (cur.empty() || !cur.inset().insetAllowed(code)))
                disable = true;
 
        if (disable)
@@ -815,8 +807,8 @@ bool ensureBufferClean(BufferView * bv)
 
 void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
 {
-       string argument = cmd.argument;
-       kb_action action = cmd.action;
+       string const argument = cmd.argument;
+       kb_action const action = cmd.action;
 
        lyxerr[Debug::ACTION] << "LyXFunc::dispatch: cmd: " << cmd << endl;
        //lyxerr << "LyXFunc::dispatch: cmd: " << cmd << endl;
@@ -1044,7 +1036,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
 
                // --- buffers ----------------------------------------
                case LFUN_SWITCHBUFFER:
-                       view()->buffer(bufferlist.getBuffer(argument));
+                       view()->setBuffer(bufferlist.getBuffer(argument));
                        break;
 
                case LFUN_FILE_NEW:
@@ -1084,14 +1076,14 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
                        if (prefixIs(file_name, getTmpDir())) {
                                // Needed by inverse dvi search. If it is a file
                                // in tmpdir, call the apropriated function
-                               view()->buffer(bufferlist.getBufferFromTmp(file_name));
+                               view()->setBuffer(bufferlist.getBufferFromTmp(file_name));
                        } else {
                                // Must replace extension of the file to be .lyx
                                // and get full path
                                string const s = ChangeExtension(file_name, ".lyx");
                                // Either change buffer or load the file
                                if (bufferlist.exists(s)) {
-                                       view()->buffer(bufferlist.getBuffer(s));
+                                       view()->setBuffer(bufferlist.getBuffer(s));
                                } else {
                                        view()->loadLyXFile(s);
                                }
@@ -1228,13 +1220,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
                case LFUN_DIALOG_SHOW_NEXT_INSET:
                        break;
 
-               case LFUN_INSET_DIALOG_SHOW: {
-                       InsetBase * inset = view()->cursor().nextInset();
-                       if (inset)
-                               inset->dispatch(view()->cursor(), FuncRequest(LFUN_INSET_DIALOG_SHOW));
-                       break;
-               }
-
                case LFUN_DIALOG_UPDATE: {
                        string const & name = argument;
                        // Can only update a dialog connected to an existing inset
@@ -1264,7 +1249,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
                        view()->savePosition(0);
                        string const parentfilename = owner->buffer()->fileName();
                        if (bufferlist.exists(filename))
-                               view()->buffer(bufferlist.getBuffer(filename));
+                               view()->setBuffer(bufferlist.getBuffer(filename));
                        else
                                view()->loadLyXFile(filename);
                        // Set the parent name of the child document.
@@ -1297,13 +1282,13 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
                case LFUN_REPEAT: {
                        // repeat command
                        string countstr;
-                       argument = split(argument, countstr, ' ');
+                       string rest = split(argument, countstr, ' ');
                        istringstream is(countstr);
                        int count = 0;
                        is >> count;
-                       lyxerr << "repeat: count: " << count << " cmd: " << argument << endl;
+                       lyxerr << "repeat: count: " << count << " cmd: " << rest << endl;
                        for (int i = 0; i < count; ++i)
-                               dispatch(lyxaction.lookupFunc(argument));
+                               dispatch(lyxaction.lookupFunc(rest));
                        break;
                }
 
@@ -1311,8 +1296,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
                        // argument contains ';'-terminated commands
                        while (!argument.empty()) {
                                string first;
-                               argument = split(argument, first, ';');
-                               dispatch(lyxaction.lookupFunc(first));
+                               string rest = split(argument, first, ';');
+                               dispatch(lyxaction.lookupFunc(rest));
                        }
                        break;
 
@@ -1373,21 +1358,21 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
                        owner->getDialogs().toggleTooltips();
                        break;
 
-               case LFUN_EXTERNAL_EDIT:
-                       InsetExternal().dispatch(view()->cursor(), FuncRequest(action, argument));
+               case LFUN_EXTERNAL_EDIT: {
+                       FuncRequest fr(action, argument);
+                       InsetExternal().dispatch(view()->cursor(), fr);
                        break;
+               }
 
-               default:
+               default: {
                        DispatchResult res = view()->cursor().dispatch(cmd);
                        if (!res.dispatched());
                                view()->dispatch(cmd);
                        break;
                }
+               }
        }
 
-       if (view()->cursor().inTexted())
-               view()->owner()->updateLayoutChoice();
-
        if (view()->available()) {
                view()->fitCursor();
                view()->update();
@@ -1399,8 +1384,10 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
                        view()->buffer()->markDirty();
        }
 
-       if (view()->cursor().inTexted())
+       if (view()->cursor().inTexted()) {
+               view()->owner()->updateLayoutChoice();
                sendDispatchMessage(getMessage(), cmd, verbose);
+       }
 }
 
 
@@ -1673,7 +1660,7 @@ void LyXFunc::closeBuffer()
                        // since there's no current buffer
                        owner->getDialogs().hideBufferDependent();
                } else {
-                       view()->buffer(bufferlist.first());
+                       view()->setBuffer(bufferlist.first());
                }
        }
 }
index 5ab7cd9e0b5b985fee943117a4aceac9bb548b50..d715c15a4290cfe85cae6e988b4fdbf903640c57 100644 (file)
@@ -55,7 +55,7 @@ public:
        typedef lyx::paroffset_type par_type;
        
        /// constructor
-       LyXText(BufferView *, bool ininset);
+       explicit LyXText(BufferView *);
        ///
        void init(BufferView *);
 
@@ -130,7 +130,7 @@ public:
        int dist(int x, int y) const;
 
        /// try to handle that request
-       void dispatch(LCursor & cur, FuncRequest const & cmd);
+       void dispatch(LCursor & cur, FuncRequest & cmd);
        /// do we want to handle this event?
        bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus & status);
 
@@ -328,8 +328,8 @@ public:
 
        /// access to our paragraphs
        ParagraphList & paragraphs() const;
-       /// return true if this is owned by an inset.
-       bool isInInset() const;
+       /// return true if this is the main text
+       bool isMainText() const;
        
        /// return first row of text
        RowList::iterator firstRow() const;
@@ -401,8 +401,6 @@ public:
        ///
        mutable Bidi bidi;
        ///
-       bool in_inset_;
-       ///
        ParagraphList paragraphs_;
 
        /// absolute document pixel coordinates of this LyXText
index ed6c5457488e05e0004764138be884b540732bdb..5ca48a0ca74443a2723f9fa46ad7889592f9cf81 100644 (file)
@@ -1002,7 +1002,7 @@ void MathGridInset::splitCell(LCursor & cur)
 }
 
 
-void MathGridInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void MathGridInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
        //lyxerr << "*** MathGridInset: request: " << cmd << endl;
        switch (cmd.action) {
@@ -1057,7 +1057,7 @@ void MathGridInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
                cur.idx() = cur.lastpos();
 
                //mathcursor->normalize();
-               cur.dispatched(FINISHED_LEFT);
+               cmd = FuncRequest(LFUN_FINISHED_LEFT);
                return;
        }
 
@@ -1164,7 +1164,7 @@ void MathGridInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
                else if (cur.idx() != 0)
                        cur.idx() = 0;
                else
-                       cur.dispatched(FINISHED_LEFT);
+                       cmd = FuncRequest(LFUN_FINISHED_LEFT);
                break;
 
        case LFUN_WORDRIGHTSEL:
@@ -1179,7 +1179,7 @@ void MathGridInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
                else if (cur.idx() != cur.lastidx())
                        cur.idx() = cur.lastidx();
                else
-                       cur.dispatched(FINISHED_RIGHT);
+                       cmd = FuncRequest(LFUN_FINISHED_RIGHT);
                break;
 
        default:
index e664dd7cff962ab50d48ed49211c3a53b73e0988..1d8cf33e8b4719c1108adb202aff3d99ea2bbb5f 100644 (file)
@@ -212,7 +212,7 @@ public:
 
 protected:
        ///
-       void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+       void priv_dispatch(LCursor & cur, FuncRequest & cmd);
        /// returns x offset of cell compared to inset
        int cellXOffset(idx_type idx) const;
        /// returns y offset of cell compared to inset
index 3f46a091c1a015ea127865f8455b4d6611da6be0..eaa5797c53bc5859485eb4f2b4dbe8009bd2eddc 100644 (file)
@@ -29,6 +29,7 @@
 #include "lyxrc.h"
 #include "outputparams.h"
 #include "textpainter.h"
+#include "undo.h"
 
 #include "frontends/Alert.h"
 
@@ -705,7 +706,7 @@ void MathHullInset::check() const
 }
 
 
-void MathHullInset::doExtern(LCursor & cur, FuncRequest const & func)
+void MathHullInset::doExtern(LCursor & cur, FuncRequest & func)
 {
        string lang;
        string extra;
@@ -784,7 +785,7 @@ void MathHullInset::doExtern(LCursor & cur, FuncRequest const & func)
 }
 
 
-void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
        //lyxerr << "*** MathHullInset: request: " << cmd << endl;
        switch (cmd.action) {
@@ -803,7 +804,7 @@ void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
        case LFUN_MATH_NUMBER:
                //lyxerr << "toggling all numbers" << endl;
                if (display()) {
-                       ////recordUndo(cur, Undo::INSERT);
+                       recordUndo(cur);
                        bool old = numberedType();
                        if (type_ == "multline")
                                numbered(nrows() - 1, !old);
@@ -817,7 +818,7 @@ void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
        case LFUN_MATH_NONUMBER:
                if (display()) {
                        row_type r = (type_ == "multline") ? nrows() - 1 : cur.row();
-                       ////recordUndo(cur, Undo::INSERT);
+                       recordUndo(cur);
                        bool old = numbered(r);
                        cur.message(old ? _("No number") : _("Number"));
                        numbered(r, !old);
@@ -954,14 +955,13 @@ void MathHullInset::mutateToText()
 }
 
 
-void MathHullInset::handleFont
-       (LCursor & cur, string const & arg, string const & font)
+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)
+       recordUndo(cur);
+       if (cur.inset().asMathInset()->name() == font)
                cur.handleFont(font);
        else {
                cur.handleNest(createMathInset(font));
@@ -972,7 +972,7 @@ void MathHullInset::handleFont
 
 void MathHullInset::handleFont2(LCursor & cur, string const & arg)
 {
-       //recordUndo(cur, Undo::ATOMIC);
+       recordUndo(cur);
        LyXFont font;
        bool b;
        bv_funcs::string2font(arg, font, b);
index 30c9e8cc083545481b68488e475f1cdb57fb3baa..e2bb3755db6b5a5e49a8ff6e5d470016525aef35 100644 (file)
@@ -117,7 +117,7 @@ public:
 
 protected:
        ///
-       void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+       void priv_dispatch(LCursor & cur, FuncRequest & cmd);
        ///
        std::string eolString(row_type row, bool fragile) const;
 
@@ -133,7 +133,7 @@ private:
        ///
        std::string nicelabel(row_type row) const;
        ///
-       void doExtern(LCursor & cur, FuncRequest const & func);
+       void doExtern(LCursor & cur, FuncRequest & func);
        ///
        void glueall();
        ///
@@ -172,7 +172,7 @@ public:
        virtual void insetUnlock(BufferView & bv);
 
        /// To allow transparent use of math editing functions
-       //virtual void status(FuncRequest const &);
+       //virtual void status(FuncRequest &);
 
        ///
        virtual bool searchForward(BufferView *, std::string const &,
@@ -216,5 +216,5 @@ protected:
 
 // We don't really want to mess around with mathed stuff outside mathed.
 // So do it here.
-void mathDispatch(LCursor & cur, FuncRequest const & cmd);
+void mathDispatch(LCursor & cur, FuncRequest & cmd);
 #endif
index 0b7fa1548539e2e5c2063824f84535290282bbe3..d1088bdbd43ce3153703513407acd53b51702f9c 100644 (file)
@@ -26,7 +26,7 @@ using std::endl;
 
 
 MathMBoxInset::MathMBoxInset(BufferView & bv)
-       : text_(&bv, true), bv_(&bv)
+       : text_(&bv), bv_(&bv)
 {
        text_.paragraphs().push_back(Paragraph());
        text_.paragraphs().back().
@@ -64,7 +64,7 @@ void MathMBoxInset::write(WriteStream & os) const
 }
 
 
-void MathMBoxInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void MathMBoxInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
        text_.dispatch(cur, cmd);
 }
index 6d54d99c93f80afedbc1df14b8e0fcdc87298ae9..a512b9b9d821da712966e5d09b58db6e157460ff 100644 (file)
@@ -31,7 +31,7 @@ public:
        /// draw according to cached metrics
        void draw(PainterInfo &, int x, int y) const;
        ///
-       void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+       void priv_dispatch(LCursor & cur, FuncRequest & cmd);
 
        ///
        void write(WriteStream & os) const;
index 2c58c03fb33391a58005113ad35385e75b8f068b..f20ef1914deeb537e7b69110dc6f3e6ae2446445 100644 (file)
@@ -87,7 +87,7 @@ MathArray const & MathNestInset::cell(idx_type i) const
 void MathNestInset::getCursorPos(CursorSlice const & cur,
        int & x, int & y) const
 {
-       BOOST_ASSERT(ptr_cmp(cur.inset(), this));
+       BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
        MathArray const & ar = cur.cell();
        x = ar.xo() + ar.pos2x(cur.pos());
        y = ar.yo();
@@ -114,7 +114,7 @@ void MathNestInset::metrics(MetricsInfo const & mi) const
 
 bool MathNestInset::idxNext(LCursor & cur) const
 {
-       BOOST_ASSERT(ptr_cmp(cur.inset(), this));
+       BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
        if (cur.idx() == cur.lastidx())
                return false;
        ++cur.idx();
@@ -131,7 +131,7 @@ bool MathNestInset::idxRight(LCursor & cur) const
 
 bool MathNestInset::idxPrev(LCursor & cur) const
 {
-       BOOST_ASSERT(ptr_cmp(cur.inset(), this));
+       BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
        if (cur.idx() == 0)
                return false;
        --cur.idx();
@@ -148,7 +148,7 @@ bool MathNestInset::idxLeft(LCursor & cur) const
 
 bool MathNestInset::idxFirst(LCursor & cur) const
 {
-       BOOST_ASSERT(ptr_cmp(cur.inset(), this));
+       BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
        if (nargs() == 0)
                return false;
        cur.idx() = 0;
@@ -159,7 +159,7 @@ bool MathNestInset::idxFirst(LCursor & cur) const
 
 bool MathNestInset::idxLast(LCursor & cur) const
 {
-       BOOST_ASSERT(ptr_cmp(cur.inset(), this));
+       BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
        if (nargs() == 0)
                return false;
        cur.idx() = cur.lastidx();
@@ -197,7 +197,7 @@ void MathNestInset::drawSelection(PainterInfo & pi, int, int) const
        LCursor & cur = pi.base.bv->cursor();
        if (!cur.selection())
                return;
-       if (!ptr_cmp(cur.inset(), this))
+       if (!ptr_cmp(&cur.inset(), this))
                return;
        CursorSlice & s1 = cur.selBegin();
        CursorSlice & s2 = cur.selEnd();
@@ -309,7 +309,7 @@ void MathNestInset::handleFont
        // changes...
        recordUndo(cur, Undo::ATOMIC);
 
-       if (cur.inset()->asMathInset()->name() == font)
+       if (cur.inset().asMathInset()->name() == font)
                cur.handleFont(font);
        else {
                cur.handleNest(createMathInset(font));
@@ -332,13 +332,21 @@ void MathNestInset::handleFont2(LCursor & cur, string const & arg)
 }
 
 
-void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
        lyxerr << "MathNestInset: request: " << cmd << std::endl;
        //CursorSlice sl = cur.current();
 
        switch (cmd.action) {
 
+       case LFUN_PASTESELECTION: {
+               MathArray ar;
+               mathed_parse_cell(ar, cur.bv().getClipboard());
+               cur.cell().insert(cur.pos(), ar);
+               cur.pos() += ar.size();
+               break;
+       }
+
        case LFUN_PASTE:
                if (!cmd.argument.empty()) {
                        MathArray ar;
@@ -360,10 +368,6 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
        }
 */
 
-       case LFUN_PASTESELECTION:
-               dispatch(cur, FuncRequest(LFUN_PASTE, cur.bv().getClipboard()));
-               break;
-
        case LFUN_MOUSE_PRESS:
                lfunMousePress(cur, cmd);
                break;
@@ -376,13 +380,6 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
                lfunMouseRelease(cur, cmd);
                break;
 
-       case LFUN_MOUSE_DOUBLE:
-       case LFUN_MOUSE_TRIPLE:
-               //lyxerr << "Mouse double" << endl;
-               //lyxerr << "Mouse triple" << endl;
-               dispatch(cur, FuncRequest(LFUN_WORDSEL));
-               break;
-
        case LFUN_FINISHED_LEFT:
                cur.bv().cursor() = cur;
                break;
@@ -411,13 +408,13 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
                if (cur.inMacroMode())
                        cur.macroModeClose();
                else if (cur.pos() != cur.lastpos() && cur.openable(cur.nextAtom())) {
-                       cur.pushLeft(cur.nextAtom().nucleus());
-                       cur.inset()->idxFirst(cur);
+                       cur.pushLeft(*cur.nextAtom().nucleus());
+                       cur.inset().idxFirst(cur);
                } else if (cur.posRight() || idxRight(cur)
                        || cur.popRight() || cur.selection())
                        ;
                else
-                       cur.dispatched(FINISHED_RIGHT);
+                       cmd = FuncRequest(LFUN_FINISHED_RIGHT);
                lyxerr << "mathnest RIGHT: to:\n" << cur << endl;
                break;
 
@@ -430,29 +427,31 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
                        cur.macroModeClose();
                else if (cur.pos() != 0 && cur.openable(cur.prevAtom())) {
                        cur.posLeft();
-                       cur.push(cur.nextAtom().nucleus());
-                       cur.inset()->idxLast(cur);
+                       cur.push(*cur.nextAtom().nucleus());
+                       cur.inset().idxLast(cur);
                } else if (cur.posLeft() || idxLeft(cur)
                        || cur.popLeft() || cur.selection())
                        ;
                else
-                       cur.dispatched(FINISHED_LEFT);
+                       cmd = FuncRequest(LFUN_FINISHED_LEFT);
                break;
 
        case LFUN_UPSEL:
        case LFUN_UP:
                cur.selHandle(cmd.action == LFUN_UPSEL);
                if (!cur.up())
-                       cur.dispatched(FINISHED_UP);
+                       cmd = FuncRequest(LFUN_FINISHED_UP);
                break;
 
        case LFUN_DOWNSEL:
        case LFUN_DOWN:
                cur.selHandle(cmd.action == LFUN_DOWNSEL);
                if (!cur.down())
-                       cur.dispatched(FINISHED_DOWN);
+                       cmd = FuncRequest(LFUN_FINISHED_DOWN);
                break;
 
+       case LFUN_MOUSE_DOUBLE:
+       case LFUN_MOUSE_TRIPLE:
        case LFUN_WORDSEL:
                cur.pos() = 0;
                cur.idx() = 0;
@@ -483,7 +482,7 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
                        cur.idx() = 0;
                        cur.pos() = 0;
                } else {
-                       cur.dispatched(FINISHED_LEFT);
+                       cmd = FuncRequest(LFUN_FINISHED_LEFT);
                }
                break;
 
@@ -503,7 +502,7 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
                        cur.idx() = cur.lastidx();
                        cur.pos() = cur.lastpos();
                } else {
-                       cur.dispatched(FINISHED_RIGHT);
+                       cmd = FuncRequest(LFUN_FINISHED_RIGHT);
                }
                break;
 
@@ -511,22 +510,22 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
        case LFUN_PRIOR:
        case LFUN_BEGINNINGBUFSEL:
        case LFUN_BEGINNINGBUF:
-               cur.dispatched(FINISHED_LEFT);
+               cmd = FuncRequest(LFUN_FINISHED_LEFT);
                break;
 
        case LFUN_NEXTSEL:
        case LFUN_NEXT:
        case LFUN_ENDBUFSEL:
        case LFUN_ENDBUF:
-               cur.dispatched(FINISHED_RIGHT);
+               cmd = FuncRequest(LFUN_FINISHED_RIGHT);
                break;
 
        case LFUN_CELL_FORWARD:
-               cur.inset()->idxNext(cur);
+               cur.inset().idxNext(cur);
                break;
 
        case LFUN_CELL_BACKWARD:
-               cur.inset()->idxPrev(cur);
+               cur.inset().idxPrev(cur);
                break;
 
        case LFUN_DELETE_WORD_BACKWARD:
@@ -539,14 +538,14 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
        case LFUN_DELETE:
                recordUndo(cur, Undo::ATOMIC);
                cur.erase();
-               cur.dispatched(FINISHED_LEFT);
+               cmd = FuncRequest(LFUN_FINISHED_LEFT);
                break;
 
        case LFUN_ESCAPE:
                if (cur.selection()) 
                        cur.selClear();
                else 
-                       cur.dispatched(FINISHED_LEFT);
+                       cmd = FuncRequest(LFUN_FINISHED_LEFT);
                break;
 
        case LFUN_INSET_TOGGLE:
@@ -563,7 +562,7 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 
        case LFUN_SELFINSERT:
                if (cmd.argument.empty()) {
-                       cur.dispatched(FINISHED_RIGHT);
+                       cmd = FuncRequest(LFUN_FINISHED_RIGHT);
                        break;
                }
                recordUndo(cur, Undo::ATOMIC);
@@ -572,7 +571,7 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
                        break;
                }
                if (!interpret(cur, cmd.argument[0]))
-                       cur.dispatched(FINISHED_RIGHT);
+                       cmd = FuncRequest(LFUN_FINISHED_RIGHT);
                break;
 
 #if 0
@@ -682,7 +681,7 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
                cur.selClearOrDel();
                cur.plainInsert(MathAtom(new MathMBoxInset(cur.bv())));
                cur.posLeft();
-               cur.pushLeft(cur.nextInset());
+               cur.pushLeft(*cur.nextInset());
 #else
                if (currentMode() == InsetBase::TEXT_MODE)
                        cur.niceInsert(MathAtom(new MathHullInset("simple")));
@@ -776,7 +775,8 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
                InsetBase * base = cur.bv().owner()->getDialogs().getOpenInset(name);
 
                if (base) {
-                       base->dispatch(cur, FuncRequest(LFUN_INSET_MODIFY, cmd.argument));
+                       FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument);
+                       base->dispatch(cur, fr);
                        break;
                }
                MathArray ar;
@@ -821,7 +821,7 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 
 void MathNestInset::edit(LCursor & cur, bool left)
 {
-       cur.push(this);
+       cur.push(*this);
        cur.idx() = left ? 0 : cur.lastidx();
        cur.pos() = left ? 0 : cur.lastpos();
        cur.resetAnchor();
@@ -840,7 +840,7 @@ InsetBase * MathNestInset::editXY(LCursor & cur, int x, int y)
                }
        }
        MathArray & ar = cell(idx_min);
-       cur.push(this);
+       cur.push(*this);
        cur.idx() = idx_min;
        cur.pos() = ar.x2pos(x - ar.xo());
        lyxerr << "found cell : " << idx_min << " pos: " << cur.pos() << endl;
@@ -854,7 +854,7 @@ InsetBase * MathNestInset::editXY(LCursor & cur, int x, int y)
 }
 
 
-void MathNestInset::lfunMouseRelease(LCursor & cur, FuncRequest const & cmd)
+void MathNestInset::lfunMouseRelease(LCursor & cur, FuncRequest & cmd)
 {
        //lyxerr << "lfunMouseRelease: buttons: " << cmd.button() << endl;
 
@@ -884,7 +884,7 @@ void MathNestInset::lfunMouseRelease(LCursor & cur, FuncRequest const & cmd)
 }
 
 
-void MathNestInset::lfunMousePress(LCursor & cur, FuncRequest const & cmd)
+void MathNestInset::lfunMousePress(LCursor & cur, FuncRequest & cmd)
 {
        lyxerr << "lfunMousePress: buttons: " << cmd.button() << endl;
        if (cmd.button() == mouse_button::button1) {
@@ -897,12 +897,12 @@ void MathNestInset::lfunMousePress(LCursor & cur, FuncRequest const & cmd)
        }
 
        if (cmd.button() == mouse_button::button2) {
-               priv_dispatch(cur, FuncRequest(LFUN_PASTESELECTION));
+               cur.dispatch(FuncRequest(LFUN_PASTESELECTION));
        }
 }
 
 
-void MathNestInset::lfunMouseMotion(LCursor & cur, FuncRequest const & cmd)
+void MathNestInset::lfunMouseMotion(LCursor & cur, FuncRequest & cmd)
 {
        // only select with button 1
        if (cmd.button() != mouse_button::button1)
@@ -1083,20 +1083,20 @@ bool MathNestInset::script(LCursor & cur, bool up)
        } else if (cur.pos() != 0 && cur.prevAtom()->asScriptInset()) {
                --cur.pos();
                cur.nextAtom().nucleus()->asScriptInset()->ensure(up);
-               cur.push(cur.nextInset());
+               cur.push(*cur.nextInset());
                cur.idx() = up;
                cur.pos() = cur.lastpos();
        } else if (cur.pos() != 0) {
                --cur.pos();
                cur.cell()[cur.pos()] = MathAtom(new MathScriptInset(cur.nextAtom(), up));
-               cur.push(cur.nextInset());
+               cur.push(*cur.nextInset());
                cur.idx() = up;
                cur.pos() = 0;
        } else {
                cur.plainInsert(MathAtom(new MathScriptInset(up)));
                --cur.pos();
                cur.nextAtom().nucleus()->asScriptInset()->ensure(up);
-               cur.push(cur.nextInset());
+               cur.push(*cur.nextInset());
                cur.idx() = up;
                cur.pos() = 0;
        }
index b07aa565d7d11b4d45d8088bb8bbac59cd86a9b5..4eae6eeaf061f532cb7232fd5fc36455a8482815 100644 (file)
@@ -96,7 +96,7 @@ public:
 
 protected:
        ///
-       void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+       void priv_dispatch(LCursor & cur, FuncRequest & cmd);
        ///
        void handleFont(LCursor & cur,
                std::string const & arg, std::string const & font);
@@ -111,11 +111,11 @@ protected:
 
 private:
        /// lfun handler
-       void lfunMousePress(LCursor &, FuncRequest const &);
+       void lfunMousePress(LCursor &, FuncRequest &);
        ///
-       void lfunMouseRelease(LCursor &, FuncRequest const &);
+       void lfunMouseRelease(LCursor &, FuncRequest &);
        ///
-       void lfunMouseMotion(LCursor &, FuncRequest const &);
+       void lfunMouseMotion(LCursor &, FuncRequest &);
 
 protected:
        /// we store the cells in a vector
index 07bf1164b7ae254b9f456eb4da1e5233ef9a5634..be25b5cea862692a403f9463eb4aec9f36e9ab24 100644 (file)
@@ -513,7 +513,7 @@ void MathScriptInset::notifyCursorLeaves(idx_type idx)
 }
 
 
-void MathScriptInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void MathScriptInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
        //lyxerr << "MathScriptInset: request: " << cmd << std::endl;
 
index 5d6c17f1323ed60e67be4955596fe5b0ff5c45c3..5a332a185dbe0d84992f82d8da23d3e172d6ea1f 100644 (file)
@@ -98,7 +98,7 @@ public:
        void infoize2(std::ostream & os) const;
 protected:
        ///
-       void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+       void priv_dispatch(LCursor & cur, FuncRequest & cmd);
 private:
        /// returns x offset for main part
        int dxx() const;
index 5089f85ec2be296dde6997044c7e23879043fa1c..c1804cdb47d94470c53f2778773e76945cb3262a 100644 (file)
@@ -53,7 +53,7 @@ void RefInset::infoize(std::ostream & os) const
 }
 
 
-void RefInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void RefInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action) {
        case LFUN_INSET_MODIFY:
index 4e33280bd483a85ee7b0b45f10406d9c1529cc40..d3d8aa402cc87002a693204d14e44bad9d8c0892 100644 (file)
@@ -43,7 +43,7 @@ public:
        int docbook(std::ostream & os, OutputParams const &) const;
 
        /// small wrapper for the time being
-       DispatchResult localDispatch(FuncRequest const & cmd);
+       DispatchResult localDispatch(FuncRequest & cmd);
 
        struct ref_type_info {
                ///
@@ -60,7 +60,7 @@ public:
        static std::string const & getName(int type);
 protected:
        ///
-       void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+       void priv_dispatch(LCursor & cur, FuncRequest & cmd);
 };
 
 #endif
index 483fe10bcecd30163f648edc253308d4e47641b3..f775d4af126f668f6ea7f93a8438839baa4a71e7 100644 (file)
@@ -332,7 +332,7 @@ TeXOnePar(Buffer const & buf,
        // Is this really needed ? (Dekel)
        // We do not need to use to change the font for the last paragraph
        // or for a command.
-       LyXFont const outerfont(outerFont(pit, paragraphs));
+       LyXFont const outerfont = outerFont(pit, paragraphs);
 
        LyXFont const font =
                (pit->empty()
index 07c9703dc1f6abd3279ed68cdd96436446ac3dd8..a88b014f65235fe0796db34c578842d98fd9e216 100644 (file)
@@ -623,4 +623,3 @@ void getParsInRange(ParagraphList & pl,
        for (end = beg ; end != endpar && end->y <= yend; ++end)
                ;
 }
-
index 8cef593271959d27c3ba245b67ba3d7ee82f76ee..03033d16d300315ec12daa6f7eea5854d0644f14 100644 (file)
@@ -1740,25 +1740,17 @@ bool LyXText::read(Buffer const & buf, LyXLex & lex)
                if (token.empty())
                        continue;
 
-               if (in_inset_) {
-
-                       if (token == "\\end_inset") {
-                               the_end_read = true;
-                               break;
-                       }
-
-                       if (token == "\\end_document") {
-                               lex.printError("\\end_document read in inset! Error in document!");
-                               return false;
-                       }
-
-               } else {
-
-                       if (token == "\\end_document") {
-                               the_end_read = true;
-                               continue;
-                       }
+               if (token == "\\end_inset") {
+                       the_end_read = true;
+                       break;
+               }
 
+               if (token == "\\end_document") {
+#warning Look here!
+#if 0
+                       lex.printError("\\end_document read in inset! Error in document!");
+#endif
+                       return false;
                }
 
                // FIXME: ugly.
@@ -1771,8 +1763,7 @@ bool LyXText::read(Buffer const & buf, LyXLex & lex)
                        par.params().depth(depth);
                        if (buf.params().tracking_changes)
                                par.trackChanges();
-                       LyXFont f(LyXFont::ALL_INHERIT, buf.params().language);
-                       par.setFont(0, f);
+                       par.setFont(0, LyXFont(LyXFont::ALL_INHERIT, buf.params().language));
 
                        // insert after
                        if (pit != paragraphs().end())
index f8ebd65b6540dad2fe4eaf6bd8329000a38ff8dc..bdf2183f4355202ddd774a05223d0431da6d5b10 100644 (file)
@@ -71,10 +71,10 @@ using std::ostringstream;
 using std::string;
 
 
-LyXText::LyXText(BufferView * bv, bool in_inset)
+LyXText::LyXText(BufferView * bv)
        : width_(0), maxwidth_(bv ? bv->workWidth() : 100), height_(0),
          background_color_(LColor::background),
-         bv_owner(bv), in_inset_(in_inset), xo_(0), yo_(0)
+         bv_owner(bv), xo_(0), yo_(0)
 {}
 
 
@@ -101,6 +101,12 @@ void LyXText::init(BufferView * bv)
 }
 
 
+bool LyXText::isMainText() const
+{
+       return &bv()->buffer()->text() == this;
+}
+
+
 // Gets the fully instantiated font at a given position in a paragraph
 // Basically the same routine as Paragraph::getFont() in paragraph.C.
 // The difference is that this one is used for displaying, and thus we
@@ -118,7 +124,7 @@ LyXFont LyXText::getFont(ParagraphList::iterator pit, pos_type pos) const
        // We specialize the 95% common case:
        if (!pit->getDepth()) {
                LyXFont f = pit->getFontSettings(params, pos);
-               if (in_inset_)
+               if (!isMainText())
                        f.realize(font_);
                if (layout->labeltype == LABEL_MANUAL && pos < body_pos)
                        return f.realize(layout->reslabelfont);
@@ -136,7 +142,7 @@ LyXFont LyXText::getFont(ParagraphList::iterator pit, pos_type pos) const
        LyXFont font = pit->getFontSettings(params, pos);
        font.realize(layoutfont);
 
-       if (in_inset_)
+       if (!isMainText())
                font.realize(font_);
 
        // Realize with the fonts of lesser depth.
@@ -1596,12 +1602,6 @@ void LyXText::recUndo(par_type par) const
 }
 
 
-bool LyXText::isInInset() const
-{
-       return in_inset_;
-}
-
-
 bool LyXText::toggleInset(LCursor & cur)
 {
        InsetBase * inset = cur.nextInset();
index ba25ab6020abd888b57e0956ef6811087f30f937..e907ac0f9efc3cb2612b9b9d52aa8631654e8f9d 100644 (file)
@@ -131,7 +131,8 @@ namespace {
                lyxerr << "selection is: '" << sel << "'" << endl;
 
                if (sel.empty()) {
-                       cur.insert(new MathHullInset); // activates inset
+                       cur.insert(new MathHullInset);
+                       cur.dispatch(FuncRequest(LFUN_RIGHT));
                        cur.dispatch(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
@@ -143,14 +144,16 @@ namespace {
                        // create a macro if we see "\\newcommand" somewhere, and an ordinary
                        // formula otherwise
                        text->cutSelection(cur, true, true);
-                       if (sel.find("\\newcommand") == string::npos &&
-                                       sel.find("\\def") == string::npos)
+                       if (sel.find("\\newcommand") == string::npos
+                           && sel.find("\\def") == string::npos)
                        {
                                cur.insert(new MathHullInset);
+                               cur.dispatch(FuncRequest(LFUN_RIGHT));
                                cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
                                cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel));
                        } else {
                                cur.insert(new InsetFormulaMacro(sel));
+                               cur.dispatch(FuncRequest(LFUN_RIGHT));
                        }
                }
                cur.message(N_("Math editor mode"));
@@ -367,7 +370,7 @@ bool LyXText::isRTL(Paragraph const & par) const
 }
 
 
-void LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
+void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
 {
        lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
        //lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
@@ -464,7 +467,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                else
                        cursorRight(cur);
                if (sl == cur.top())
-                       cur.dispatched(FINISHED_RIGHT);
+                       cmd = FuncRequest(LFUN_FINISHED_RIGHT);
                break;
 
        case LFUN_LEFT:
@@ -475,7 +478,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                else
                        cursorLeft(cur);
                if (sl == cur.top())
-                       cur.dispatched(FINISHED_LEFT);
+                       cmd = FuncRequest(LFUN_FINISHED_LEFT);
                break;
 
        case LFUN_UP:
@@ -483,7 +486,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                cur.selHandle(cmd.action == LFUN_UPSEL);
                cursorUp(cur);
                if (sl == cur.top())
-                       cur.dispatched(FINISHED_UP);
+                       cmd = FuncRequest(LFUN_FINISHED_UP);
                break;
 
        case LFUN_DOWN:
@@ -491,7 +494,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                cur.selHandle(cmd.action == LFUN_DOWNSEL);
                cursorDown(cur);
                if (sl == cur.top())
-                       cur.dispatched(FINISHED_DOWN);
+                       cmd = FuncRequest(LFUN_FINISHED_DOWN);
                break;
 
        case LFUN_UP_PARAGRAPHSEL:
@@ -581,7 +584,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                        cur.clearSelection();
                finishChange(cur, false);
                if (cur.par() == 0 && cur.textRow().pos() == 0)
-                       cur.dispatched(FINISHED_UP);
+                       cmd = FuncRequest(LFUN_FINISHED_UP);
                else
                        cursorPrevious(cur);
                break;
@@ -592,7 +595,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                finishChange(cur, false);
                if (cur.par() == cur.lastpar()
                          && cur.textRow().endpos() == cur.lastpos())
-                       cur.dispatched(FINISHED_DOWN);
+                       cmd = FuncRequest(LFUN_FINISHED_DOWN);
                else
                        cursorNext(cur);
                break;
@@ -758,10 +761,13 @@ void LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
        case LFUN_INSET_APPLY: {
                string const name = cmd.getArg(0);
                InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
-               if (inset)
-                       inset->dispatch(cur, FuncRequest(LFUN_INSET_MODIFY, cmd.argument));
-               else
-                       dispatch(cur, FuncRequest(LFUN_INSET_INSERT, cmd.argument));
+               if (inset) {
+                       FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument);
+                       inset->dispatch(cur, fr);
+               } else {
+                       FuncRequest fr(LFUN_INSET_INSERT, cmd.argument);
+                       dispatch(cur, fr);
+               }
                break;
        }
 
@@ -774,8 +780,8 @@ void LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
        }
 
        case LFUN_INSET_SETTINGS:
-               if (cur.inset() && cur.inset()->asUpdatableInset())
-                       cur.inset()->asUpdatableInset()->showInsetDialog(bv);
+               if (cur.inset().asUpdatableInset())
+                       cur.inset().asUpdatableInset()->showInsetDialog(bv);
                break;
 
        case LFUN_INSET_TOGGLE:
@@ -860,28 +866,6 @@ void LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                cur.message(_("Copy"));
                break;
 
-       case LFUN_BEGINNINGBUFSEL:
-               if (in_inset_) {
-                       cur.undispatched();
-               } else {
-                       if (!cur.selection())
-                               cur.resetAnchor();
-                       cursorTop(cur);
-                       finishChange(cur, true);
-               }
-               break;
-
-       case LFUN_ENDBUFSEL:
-               if (in_inset_) {
-                       cur.undispatched();
-               } else {
-                       if (!cur.selection())
-                               cur.resetAnchor();
-                       cursorBottom(cur);
-                       finishChange(cur, true);
-               }
-               break;
-
        case LFUN_GETXY:
                cur.message(tostr(cursorX(cur.top())) + ' '
                          + tostr(cursorY(cur.top())));
@@ -1029,7 +1013,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                                    InsetQuotes::DoubleQ));
                        else
                                cur.insert(new InsetQuotes(c, bufparams));
-                       }
+               }
                else
                        bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
                break;
@@ -1093,7 +1077,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
 
                // This is to allow jumping over large insets
                // FIXME: shouldn't be top-text-specific
-               if (!in_inset_ && cur.top() == old) {
+               if (isMainText() && cur.top() == old) {
                        if (cmd.y - bv->top_y() >= bv->workHeight())
                                cursorDown(cur);
                        else if (cmd.y - bv->top_y() < 0)
@@ -1461,9 +1445,8 @@ void LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                params2string(cur.paragraph(), data);
 
                // Will the paragraph accept changes from the dialog?
-               InsetBase * const inset = cur.inset();
-               bool const accept =
-                       !(inset && inset->forceDefaultParagraphs(inset));
+               InsetBase & inset = cur.inset();
+               bool const accept = !inset.forceDefaultParagraphs(&inset);
 
                data = "update " + tostr(accept) + '\n' + data;
                bv->owner()->getDialogs().update("paragraph", data);
@@ -1562,11 +1545,20 @@ void LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                break;
        }
 
+       case LFUN_INSET_DIALOG_SHOW: {
+               InsetBase * inset = cur.nextInset();
+               if (inset) {
+                       FuncRequest fr(LFUN_INSET_DIALOG_SHOW);
+                       inset->dispatch(cur, fr);
+               }
+               break;
+       }
+
        case LFUN_ESCAPE:
                if (cur.selection())
                        cur.selection() = false;
                else
-                       cur.dispatched(FINISHED_LEFT);
+                       cmd = FuncRequest(LFUN_FINISHED_LEFT);
                break;
 
        default:
index 9d028f03c7b18bf0d0764d5d2b23f7c44e481c8f..ab798f3dfe8d32c6d60eedb02da7bef9a09f4310 100644 (file)
@@ -107,7 +107,7 @@ void performUndoOrRedo(BufferView & bv, Undo const & undo)
 {
        LCursor & cur = bv.cursor();
        lyxerr << "undo, performing: " << undo << std::endl;
-       cur.setCursor(undo.cursor.asDocumentIterator(bv), false);
+       cur.setCursor(undo.cursor.asDocumentIterator(&bv.buffer()->inset()), false);
 
        if (cur.inMathed()) {
                // We stored the full cell here as there is not much to be
@@ -155,7 +155,8 @@ bool textUndoOrRedo(BufferView & bv,
        // this implements redo
        if (!undo_frozen) {
                otherstack.push(undo);
-               DocumentIterator dit = undo.cursor.asDocumentIterator(bv);
+               DocumentIterator dit =
+                       undo.cursor.asDocumentIterator(&bv.buffer()->inset());
                if (dit.inMathed()) {
                        // not much to be done
                } else {