This fixes a crash or two, speeds up drawing again (we/I painted
everything starting from top of doc...)

Andre'

-- 
Those who desire to give up Freedom in order to gain Security, will not have,
nor do they deserve, either one.     (T. Jefferson or B. Franklin or both...)
Index: BufferView.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView.C,v
retrieving revision 1.229
diff -u -p -r1.229 BufferView.C
--- BufferView.C        6 Feb 2004 13:59:24 -0000       1.229
+++ BufferView.C        11 Feb 2004 13:52:36 -0000
@@ -322,34 +322,6 @@ void BufferView::gotoLabel(string const 
 }
 
 
-void BufferView::undo()
-{
-       if (!available())
-               return;
-
-       owner()->message(_("Undo"));
-       cursor().clearSelection();
-       if (!textUndo(*this))
-               owner()->message(_("No further undo information"));
-       update();
-       switchKeyMap();
-}
-
-
-void BufferView::redo()
-{
-       if (!available())
-               return;
-
-       owner()->message(_("Redo"));
-       cursor().clearSelection();
-       if (!textRedo(*this))
-               owner()->message(_("No further redo information"));
-       update();
-       switchKeyMap();
-}
-
-
 void BufferView::replaceWord(string const & replacestring)
 {
        if (!available())
Index: BufferView.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView.h,v
retrieving revision 1.165
diff -u -p -r1.165 BufferView.h
--- BufferView.h        6 Feb 2004 13:59:24 -0000       1.165
+++ BufferView.h        11 Feb 2004 13:52:36 -0000
@@ -125,11 +125,6 @@ public:
        /// move cursor to the named label
        void gotoLabel(std::string const & label);
 
-       /// undo last action
-       void undo();
-       /// redo last action
-       void redo();
-
        /// get the stored error list
        ErrorList const & getErrorList() const;
        /// show the error list to the user
Index: BufferView_pimpl.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v
retrieving revision 1.505
diff -u -p -r1.505 BufferView_pimpl.C
--- BufferView_pimpl.C  6 Feb 2004 16:50:28 -0000       1.505
+++ BufferView_pimpl.C  11 Feb 2004 13:52:36 -0000
@@ -549,7 +549,7 @@ void BufferView::Pimpl::selectionRequest
                xsel_cache_.cursor = cur.cursor_.back();
                xsel_cache_.anchor = cur.anchor_.back();
                xsel_cache_.set = cur.selection();
-               sel = bv_->getLyXText()->selectionAsString(*bv_->buffer(), false);
+               sel = cur.selectionAsString(false);
                if (!sel.empty())
                        workarea().putClipboard(sel);
        } 
@@ -578,11 +578,9 @@ void BufferView::Pimpl::workAreaResize()
        work_area_width = workarea().workWidth();
        work_area_height = workarea().workHeight();
 
-       if (buffer_ != 0) {
-               if (widthChange) {
-                       // The visible LyXView need a resize
-                       resizeCurrentBuffer();
-               }
+       if (buffer_ && widthChange) {
+               // The visible LyXView need a resize
+               resizeCurrentBuffer();
        }
 
        if (widthChange || heightChange)
@@ -907,7 +905,7 @@ bool BufferView::Pimpl::workAreaDispatch
                }
 
                if (fitCursor() || res.update()) {
-                       bv_->update();
+                       update();
                        cur.updatePos();
                }
                return true;
@@ -950,7 +948,7 @@ bool BufferView::Pimpl::workAreaDispatch
                DispatchResult res = cur.dispatch(cmd);
 
                if (fitCursor() || res.update())
-                       bv_->update();
+                       update();
 
                // see workAreaKeyPress
                cursor_timeout.restart();
@@ -993,10 +991,26 @@ bool BufferView::Pimpl::dispatch(FuncReq
 
        switch (cmd.action) {
 
-       case LFUN_SCROLL_INSET:
-               // this is not handled here as this function is only active
-               // if we have a locking_inset and that one is (or contains)
-               // a tabular-inset
+       case LFUN_UNDO:
+               if (available()) {
+                       cur.message(_("Undo"));
+                       cur.clearSelection();
+                       if (!textUndo(*bv_))
+                               cur.message(_("No further undo information"));
+                       update();
+                       switchKeyMap();
+               }
+               break;
+
+       case LFUN_REDO:
+               if (available()) {
+                       cur.message(_("Redo"));
+                       cur.clearSelection();
+                       if (!textRedo(*bv_))
+                               cur.message(_("No further redo information"));
+                       update();
+                       switchKeyMap();
+               }
                break;
 
        case LFUN_FILE_INSERT:
@@ -1083,14 +1097,12 @@ bool BufferView::Pimpl::dispatch(FuncReq
                string arg = cmd.argument;
 
                if (arg.empty()) {
-                       arg = bv_->getLyXText()->selectionAsString(*buffer_,
-                                                                  false);
-
+                       arg = cur.selectionAsString(false);
                        // FIXME
                        if (arg.size() > 100 || arg.empty()) {
                                // Get word or selection
                                
bv_->getLyXText()->selectWordWhenUnderCursor(lyx::WHOLE_WORD);
-                               arg = bv_->getLyXText()->selectionAsString(*buffer_, 
false);
+                               arg = cur.selectionAsString(false);
                                // FIXME: where is getLyXText()->unselect(bv_) ?
                        }
                }
@@ -1147,7 +1159,7 @@ bool BufferView::Pimpl::dispatch(FuncReq
 
        case LFUN_MARK_OFF:
                cur.clearSelection();
-               bv_->update();
+               update();
                cur.resetAnchor();
                cur.message(N_("Mark off"));
                break;
@@ -1155,7 +1167,7 @@ bool BufferView::Pimpl::dispatch(FuncReq
        case LFUN_MARK_ON:
                cur.clearSelection();
                cur.mark() = true;
-               bv_->update();
+               update();
                cur.resetAnchor();
                cur.message(N_("Mark on"));
                break;
@@ -1169,7 +1181,7 @@ bool BufferView::Pimpl::dispatch(FuncReq
                        cur.message(N_("Mark set"));
                }
                cur.resetAnchor();
-               bv_->update();
+               update();
                break;
 
        case LFUN_UNKNOWN_ACTION:
Index: buffer.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.C,v
retrieving revision 1.553
diff -u -p -r1.553 buffer.C
--- buffer.C    21 Jan 2004 17:52:05 -0000      1.553
+++ buffer.C    11 Feb 2004 13:52:36 -0000
@@ -487,8 +487,8 @@ void Buffer::insertStringAsLines(Paragra
                                ++pos;
                                space_inserted = true;
                        } else {
-                               const pos_type nb = 8 - pos % 8;
-                               for (pos_type a = 0; a < nb ; ++a) {
+                               const pos_type n = 8 - pos % 8;
+                               for (pos_type i = 0; i < n; ++i) {
                                        par->insertChar(pos, ' ', font);
                                        ++pos;
                                }
@@ -531,7 +531,6 @@ bool Buffer::readFile(string const & fil
 {
        LyXLex lex(0, 0);
        lex.setFile(filename);
-
        return readFile(lex, filename, pit);
 }
 
@@ -711,9 +710,8 @@ bool Buffer::save() const
                removeAutosaveFile(fileName());
        } else {
                // Saving failed, so backup is not backup
-               if (lyxrc.make_backup) {
+               if (lyxrc.make_backup)
                        rename(s, fileName());
-               }
                return false;
        }
        return true;
@@ -722,20 +720,17 @@ bool Buffer::save() const
 
 bool Buffer::writeFile(string const & fname) const
 {
-       if (pimpl_->read_only && (fname == fileName())) {
+       if (pimpl_->read_only && fname == fileName())
                return false;
-       }
 
        FileInfo finfo(fname);
-       if (finfo.exist() && !finfo.writable()) {
+       if (finfo.exist() && !finfo.writable())
                return false;
-       }
 
        bool retval;
 
        if (params().compressed) {
                gz::ogzstream ofs(fname.c_str());
-
                if (!ofs)
                        return false;
 
Index: cursor.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.C,v
retrieving revision 1.53
diff -u -p -r1.53 cursor.C
--- cursor.C    6 Feb 2004 16:50:29 -0000       1.53
+++ cursor.C    11 Feb 2004 13:52:36 -0000
@@ -174,7 +174,7 @@ bool LCursor::popRight()
        }
        inset()->notifyCursorLeaves(idx());
        pop();
-       posRight();
+       ++pos();
        return true;
 }
 
@@ -387,7 +387,6 @@ CursorSlice const & LCursor::selBegin() 
 {
        if (!selection())
                return cursor_.back();
-       // can't use std::min as this creates a new object
        return anchor() < cursor_.back() ? anchor() : cursor_.back();
 }
 
@@ -396,6 +395,7 @@ CursorSlice & LCursor::selBegin()
 {
        if (!selection())
                return cursor_.back();
+       // can't use std::min as this returns a const ref
        return anchor() < cursor_.back() ? anchor() : cursor_.back();
 }
 
@@ -410,8 +410,9 @@ CursorSlice const & LCursor::selEnd() co
 
 CursorSlice & LCursor::selEnd()
 {
-       if (selection())
+       if (!selection())
                return cursor_.back();
+       // can't use std::min as this returns a const ref
        return anchor() > cursor_.back() ? anchor() : cursor_.back();
 }
 
@@ -629,8 +630,9 @@ string LCursor::grabSelection()
 
 void LCursor::eraseSelection()
 {
-       CursorSlice i1 = selBegin();
-       CursorSlice i2 = selEnd();
+       //lyxerr << "LCursor::eraseSelection" << endl;
+       CursorSlice const & i1 = selBegin();
+       CursorSlice const & i2 = selEnd();
 #warning FIXME
        if (i1.inset()->asMathInset()) {
                if (i1.idx_ == i2.idx_) {
@@ -648,6 +650,7 @@ void LCursor::eraseSelection()
        } else {
                lyxerr << "can't erase this selection 1" << endl;
        }
+       //lyxerr << "LCursor::eraseSelection end" << endl;
 }
 
 
@@ -688,6 +691,7 @@ void LCursor::selCut()
 
 void LCursor::selDel()
 {
+       //lyxerr << "LCursor::selDel" << endl;
        if (selection()) {
                eraseSelection();
                selection() = false;
@@ -707,6 +711,7 @@ void LCursor::selPaste(size_t n)
 
 void LCursor::selHandle(bool sel)
 {
+       //lyxerr << "LCursor::selHandle" << endl;
        if (sel == selection())
                return;
        resetAnchor();
@@ -714,15 +719,9 @@ void LCursor::selHandle(bool sel)
 }
 
 
-void LCursor::selStart()
-{
-       resetAnchor();
-       selection() = true;
-}
-
-
 void LCursor::selClearOrDel()
 {
+       //lyxerr << "LCursor::selClearOrDel" << endl;
        if (lyxrc.auto_region_delete)
                selDel();
        else
@@ -733,9 +732,9 @@ void LCursor::selClearOrDel()
 std::ostream & operator<<(std::ostream & os, LCursor const & cur)
 {
        for (size_t i = 0, n = cur.cursor_.size(); i != n; ++i)
-               os << "  (" << cur.cursor_[i] << " | " << cur.anchor_[i] << "\n";
-       os << "  current: " << cur.current_ << endl;
-       os << "  selection: " << cur.selection_ << endl;
+               os << " " << cur.cursor_[i] << " | " << cur.anchor_[i] << "\n";
+       os << " current: " << cur.current_ << endl;
+       os << " selection: " << cur.selection_ << endl;
        return os;
 }
 
@@ -983,26 +982,24 @@ void LCursor::plainInsert(MathAtom const
 }
 
 
-void LCursor::insert2(string const & str)
-{
-       MathArray ar;
-       asArray(str, ar);
-       insert(ar);
-}
-
-
 void LCursor::insert(string const & str)
 {
-       lyxerr << "inserting '" << str << "'" << endl;
+       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
 }
 
 
 void LCursor::insert(char c)
 {
-       lyxerr << "inserting '" << c << "'" << endl;
+       //lyxerr << "LCursor::insert char '" << c << "'" << endl;
        selClearOrDel();
        plainInsert(MathAtom(new MathCharInset(c)));
 }
@@ -1010,15 +1007,24 @@ void LCursor::insert(char c)
 
 void LCursor::insert(MathAtom const & t)
 {
+       //lyxerr << "LCursor::insert MathAtom: " << endl;
        macroModeClose();
        selClearOrDel();
        plainInsert(t);
 }
 
 
+void LCursor::insert(InsetBase * inset)
+{
+       if (inMathed())
+               insert(MathAtom(inset));
+       else
+               text()->insertInset(inset);
+}
+
+
 void LCursor::niceInsert(string const & t)
 {
-       lyxerr << "*** LCursor::niceInsert 1: " << t << endl;
        MathArray ar;
        asArray(t, ar);
        if (ar.size() == 1)
@@ -1030,17 +1036,17 @@ void LCursor::niceInsert(string const & 
 
 void LCursor::niceInsert(MathAtom const & t)
 {
-       lyxerr << "*** LCursor::niceInsert 2: " << t << endl;
        macroModeClose();
        string safe = grabAndEraseSelection();
        plainInsert(t);
        // enter the new inset and move the contents of the selection if possible
        if (t->isActive()) {
                posLeft();
+               // be careful here: don't use 'pushLeft(t)' as this we need to
+               // push the clone, not the original
                pushLeft(nextAtom().nucleus());
                paste(safe);
        }
-       lyxerr << "*** LCursor::niceInsert 3: " << t << endl;
 }
 
 
@@ -1187,11 +1193,12 @@ string LCursor::macroName()
 
 void LCursor::handleNest(MathAtom const & a, int c)
 {
+       //lyxerr << "LCursor::handleNest: " << c << endl;
        MathAtom t = a;
        asArray(grabAndEraseSelection(), t.nucleus()->cell(c));
        insert(t);
        posLeft();
-       pushLeft(t.nucleus());
+       pushLeft(nextAtom().nucleus());
 }
 
 
@@ -1268,17 +1275,15 @@ MathGridInset * LCursor::enclosingGrid(i
 
 void LCursor::pullArg()
 {
-#warning look here
-#if 0
+#warning Look here
        MathArray ar = cell();
-       if (popLeft()) {
+       if (popLeft() && inMathed()) {
                plainErase();
                cell().insert(pos(), ar);
                resetAnchor();
        } else {
-               formula()->mutateToText();
+               //formula()->mutateToText();
        }
-#endif
 }
 
 
@@ -1696,7 +1701,7 @@ void LCursor::lockToggle()
        } else if (popLeft() && pos() != lastpos()) {
                // ... or enclosing inset if we are in the last inset position
                nextAtom().nucleus()->lock(!nextAtom()->lock());
-               posRight();
+               ++pos();
        }
 }
 
@@ -1754,6 +1759,7 @@ DispatchResult dispatch(LCursor & cur, F
 
 void LCursor::handleFont(string const & font)
 {
+       lyxerr << "LCursor::handleFont: " << font << endl;
        string safe;
        if (selection()) {
                macroModeClose();
@@ -1836,4 +1842,41 @@ void LCursor::message(string const & msg
 void LCursor::errorMessage(string const & msg) const
 {
        bv().owner()->getLyXFunc().setErrorMessage(msg);
+}
+
+
+string LCursor::selectionAsString(bool label) const
+{
+       if (!selection())
+               return string();
+
+       if (inTexted()) {
+               Buffer const & buffer = *bv().buffer();
+
+               // should be const ...
+               ParagraphList::iterator startpit = text()->getPar(selBegin());
+               ParagraphList::iterator endpit = text()->getPar(selEnd());
+               size_t const startpos = selBegin().pos();
+               size_t const endpos = selEnd().pos();
+
+               if (startpit == endpit)
+                       return startpit->asString(buffer, startpos, endpos, label);
+
+               // First paragraph in selection
+               string result =
+                       startpit->asString(buffer, startpos, startpit->size(), label) 
+ "\n\n";
+
+               // The paragraphs in between (if any)
+               ParagraphList::iterator pit = startpit;
+               for (++pit; pit != endpit; ++pit)
+                       result += pit->asString(buffer, 0, pit->size(), label) + 
"\n\n";
+
+               // Last paragraph in selection
+               result += endpit->asString(buffer, 0, endpos, label);
+
+               return result;
+       }
+
+#warning an mathed?
+       return string();
 }
Index: cursor.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.h,v
retrieving revision 1.31
diff -u -p -r1.31 cursor.h
--- cursor.h    6 Feb 2004 16:14:04 -0000       1.31
+++ cursor.h    11 Feb 2004 13:52:36 -0000
@@ -144,6 +144,8 @@ public:
        void selClear();
        /// clears or deletes selection depending on lyxrc setting
        void selClearOrDel();
+       //
+       std::string selectionAsString(bool label) const;
        ///
        void paste(std::string const & data);
 
@@ -247,6 +249,13 @@ public:
        /// move one step to the right
        bool posRight();
 
+       /// insert an inset
+       void insert(InsetBase *);
+       /// insert a single char
+       void insert(char c);
+       /// insert a string
+       void insert(std::string const & str);
+
        /// write acess to target x position of cursor
        int & x_target();
        /// return target x position of cursor
@@ -327,8 +336,6 @@ public:
        void insert(MathAtom const &);
        ///
        void insert(MathArray const &);
-       ///
-       void insert2(std::string const &);
        /// return false for empty math insets
        bool erase();
        /// return false for empty math insets
@@ -398,10 +405,6 @@ public:
        /// returns the normalized anchor of the selection
        CursorSlice normalAnchor();
 
-       ///
-       void insert(char c);
-       ///
-       void insert(std::string const & str);
        /// lock/unlock inset
        void lockToggle();
 
Index: cursor_slice.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor_slice.C,v
retrieving revision 1.13
diff -u -p -r1.13 cursor_slice.C
--- cursor_slice.C      2 Feb 2004 11:56:50 -0000       1.13
+++ cursor_slice.C      11 Feb 2004 13:52:36 -0000
@@ -236,7 +236,7 @@ std::ostream & operator<<(std::ostream &
        os << "inset: " << item.inset_
           << " text: " << item.text()
           << " idx: " << item.idx_
-          << " par: " << item.par_
+//        << " par: " << item.par_
           << " pos: " << item.pos_
 //        << " x: " << item.inset_->x()
 //        << " y: " << item.inset_->y()
Index: lyxfind.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfind.C,v
retrieving revision 1.74
diff -u -p -r1.74 lyxfind.C
--- lyxfind.C   3 Feb 2004 08:56:21 -0000       1.74
+++ lyxfind.C   11 Feb 2004 13:52:36 -0000
@@ -223,11 +223,13 @@ public:
                string::size_type const size = str.length();
                lyx::pos_type i = 0;
                lyx::pos_type const parsize = par.size();
-               while ((pos + i < parsize)
-                      && (string::size_type(i) < size)
-                      && (cs ? (str[i] == par.getChar(pos + i))
-                          : (uppercase(str[i]) == uppercase(par.getChar(pos + i))))) {
-                       ++i;
+               for (i = 0; pos + i < parsize; ++i) {
+                       if (string::size_type(i) >= size)
+                               break;
+                 if (cs && str[i] != par.getChar(pos + i))
+                               break;
+                       if (!cs && uppercase(str[i]) != uppercase(par.getChar(pos + 
i)))
+                               break;
                }
 
                if (size != string::size_type(i))
@@ -359,16 +361,13 @@ int replaceAll(BufferView * bv,
 }
 
 
-bool stringSelected(BufferView * bv,
-                   string const & searchstr,
+bool stringSelected(BufferView * bv, string const & searchstr,
                    bool cs, bool mw, bool fw)
 {
-       LyXText * text = bv->getLyXText();
        // if nothing selected or selection does not equal search
        // string search and select next occurance and return
        string const & str1 = searchstr;
-       string const str2 = text->selectionAsString(*bv->buffer(),
-                                                   false);
+       string const str2 = bv->cursor().selectionAsString(false);
        if ((cs && str1 != str2) || lowercase(str1) != lowercase(str2)) {
                find(bv, searchstr, cs, mw, fw);
                return false;
@@ -378,9 +377,8 @@ bool stringSelected(BufferView * bv,
 }
 
 
-int replace(BufferView * bv,
-           string const & searchstr, string const & replacestr,
-           bool cs, bool mw, bool fw)
+int replace(BufferView * bv, string const & searchstr,
+      string const & replacestr, bool cs, bool mw, bool fw)
 {
        if (!searchAllowed(bv, searchstr) || bv->buffer()->isReadonly())
                return 0;
Index: lyxfunc.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfunc.C,v
retrieving revision 1.570
diff -u -p -r1.570 lyxfunc.C
--- lyxfunc.C   6 Feb 2004 16:14:04 -0000       1.570
+++ lyxfunc.C   11 Feb 2004 13:52:36 -0000
@@ -824,7 +824,7 @@ void LyXFunc::dispatch(FuncRequest const
        kb_action action = cmd.action;
 
        lyxerr[Debug::ACTION] << "LyXFunc::dispatch: cmd: " << cmd << endl;
-       //lyxerr << "*** LyXFunc::dispatch: cmd: " << cmd << endl;
+       lyxerr << "LyXFunc::dispatch: cmd: " << cmd << endl;
 
        // we have not done anything wrong yet.
        errorstat = false;
@@ -998,14 +998,6 @@ void LyXFunc::dispatch(FuncRequest const
                        AutoSave(view());
                        break;
 
-               case LFUN_UNDO:
-                       view()->undo();
-                       break;
-
-               case LFUN_REDO:
-                       view()->redo();
-                       break;
-
                case LFUN_RECONFIGURE:
                        Reconfigure(view());
                        break;
@@ -1162,14 +1154,6 @@ void LyXFunc::dispatch(FuncRequest const
                        break;
                }
 
-               // ---  Mathed stuff. If we are here, there is no locked inset yet.
-               case LFUN_MATH_EXTERN:
-               case LFUN_MATH_NUMBER:
-               case LFUN_MATH_NONUMBER:
-               case LFUN_MATH_LIMITS:
-                       setErrorMessage(N_("This is only allowed in math mode!"));
-                       break;
-
                case LFUN_DIALOG_SHOW: {
                        string const name = cmd.getArg(0);
                        string data = trim(cmd.argument.substr(name.size()));
@@ -1431,7 +1415,7 @@ void LyXFunc::dispatch(FuncRequest const
                }
        }
 
-       if (!view()->cursor().inMathed())
+       if (view()->cursor().inTexted())
                view()->owner()->updateLayoutChoice();
 
        if (view()->available()) {
@@ -1445,7 +1429,7 @@ void LyXFunc::dispatch(FuncRequest const
                        view()->buffer()->markDirty();
        }
 
-       if (!view()->cursor().inMathed())
+       if (view()->cursor().inTexted())
                sendDispatchMessage(getMessage(), cmd, verbose);
 }
 
Index: lyxtext.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtext.h,v
retrieving revision 1.287
diff -u -p -r1.287 lyxtext.h
--- lyxtext.h   6 Feb 2004 11:12:48 -0000       1.287
+++ lyxtext.h   11 Feb 2004 13:52:36 -0000
@@ -341,8 +341,6 @@ public:
        bool isFirstRow(ParagraphList::iterator pit, Row const & row) const;
 
        ///
-       std::string selectionAsString(Buffer const & buffer, bool label) const;
-       ///
        double spacing(Paragraph const &) const;
        ///
        void cursorLeftOneWord(CursorSlice &);
Index: output_latex.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/output_latex.C,v
retrieving revision 1.5
diff -u -p -r1.5 output_latex.C
--- output_latex.C      26 Jan 2004 10:13:09 -0000      1.5
+++ output_latex.C      11 Feb 2004 13:52:36 -0000
@@ -428,9 +428,8 @@ TeXOnePar(Buffer const & buf,
 
 } // anon namespace
 
-//
-// LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
-//
+
+// LaTeX all paragraphs
 void latexParagraphs(Buffer const & buf,
                     ParagraphList const & paragraphs,
                     ostream & os,
@@ -456,7 +455,7 @@ void latexParagraphs(Buffer const & buf,
 
                        if (layout->intitle) {
                                if (already_title) {
-                                       lyxerr <<"Error in latexParagraphs: You"
+                                       lyxerr << "Error in latexParagraphs: You"
                                                " should not mix title layouts"
                                                " with normal ones." << endl;
                                } else if (!was_title) {
Index: paragraph.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.C,v
retrieving revision 1.351
diff -u -p -r1.351 paragraph.C
--- paragraph.C 3 Feb 2004 08:56:22 -0000       1.351
+++ paragraph.C 11 Feb 2004 13:52:37 -0000
@@ -1385,7 +1385,6 @@ void Paragraph::simpleDocBookOnePar(Buff
                        }
                }
 
-
                if (isInset(i)) {
                        InsetBase const * inset = getInset(i);
                        // don't print the inset in position 0 if desc_on == 3 (label)
@@ -1703,7 +1702,6 @@ bool Paragraph::isChangeEdited(pos_type 
 void Paragraph::setChange(lyx::pos_type pos, Change::Type type)
 {
        pimpl_->setChange(pos, type);
-
 }
 
 
@@ -1738,7 +1736,6 @@ Paragraph::value_type Paragraph::getChar
                       << id() << " of size " << siz
                       << "  is a bit silly !" << endl;
                BOOST_ASSERT(false);
-               return '\0';
        }
 
        return text_[pos];
Index: rowpainter.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/rowpainter.C,v
retrieving revision 1.116
diff -u -p -r1.116 rowpainter.C
--- rowpainter.C        6 Feb 2004 11:50:13 -0000       1.116
+++ rowpainter.C        11 Feb 2004 13:52:37 -0000
@@ -888,7 +888,7 @@ int paintText(BufferView const & bv)
 {
        ParagraphList::iterator pit;
        bv.text()->updateParPositions();
-       bv.text()->getRowNearY(0, pit);
+       bv.text()->getRowNearY(bv.top_y(), pit);
        //lyxerr << "top_y: " << bv.top_y() << " y: " << pit->y << endl;
        return paintPars(bv, *bv.text(), pit, 0, 0, pit->y);
 }
Index: text.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v
retrieving revision 1.532
diff -u -p -r1.532 text.C
--- text.C      6 Feb 2004 13:18:46 -0000       1.532
+++ text.C      11 Feb 2004 13:52:37 -0000
@@ -1499,37 +1499,6 @@ void LyXText::previousRow(ParagraphList:
 }
 
 
-string LyXText::selectionAsString(Buffer const & buffer, bool label) const
-{
-       LCursor & cur = bv()->cursor();
-       if (!cur.selection())
-               return string();
-
-       // should be const ...
-       ParagraphList::iterator startpit = getPar(cur.selBegin());
-       ParagraphList::iterator endpit = getPar(cur.selEnd());
-       size_t const startpos = cur.selBegin().pos();
-       size_t const endpos = cur.selEnd().pos();
-
-       if (startpit == endpit)
-               return startpit->asString(buffer, startpos, endpos, label);
-
-       // First paragraph in selection
-       string result =
-               startpit->asString(buffer, startpos, startpit->size(), label) + "\n\n";
-
-       // The paragraphs in between (if any)
-       ParagraphList::iterator pit = startpit;
-       for (++pit; pit != endpit; ++pit)
-               result += pit->asString(buffer, 0, pit->size(), label) + "\n\n";
-
-       // Last paragraph in selection
-       result += endpit->asString(buffer, 0, endpos, label);
-
-       return result;
-}
-
-
 int LyXText::parOffset(ParagraphList::iterator pit) const
 {
        return distance(paragraphs().begin(), pit);
Index: text2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v
retrieving revision 1.540
diff -u -p -r1.540 text2.C
--- text2.C     6 Feb 2004 13:18:47 -0000       1.540
+++ text2.C     11 Feb 2004 13:52:37 -0000
@@ -466,8 +466,7 @@ void LyXText::cursorTop()
 
 void LyXText::cursorBottom()
 {
-       ParagraphList::iterator lastpit =
-               boost::prior(paragraphs().end());
+       ParagraphList::iterator lastpit = boost::prior(paragraphs().end());
        setCursor(lastpit, lastpit->size());
 }
 
@@ -520,7 +519,7 @@ string LyXText::getStringToIndex()
        else if (cur.selBegin().par() != cur.selEnd().par())
                bv()->owner()->message(_("Cannot index more than one paragraph!"));
        else
-               idxstring = selectionAsString(*bv()->buffer(), false);
+               idxstring = cur.selectionAsString(false);
 
        // Reset cursors to their original position.
        cursor() = reset_cursor;
@@ -896,7 +895,7 @@ void LyXText::cutSelection(bool doclear,
        // finished. The solution used currently just works, to make it
        // faster we need to be more clever and probably also have more
        // calls to stuffClipboard. (Lgb)
-       bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
+       bv()->stuffClipboard(cur.selectionAsString(true));
 
        // This doesn't make sense, if there is no selection
        if (!cur.selection())
@@ -947,7 +946,7 @@ void LyXText::copySelection()
 {
        LCursor & cur = bv()->cursor();
        // stuff the selection onto the X clipboard, from an explicit copy request
-       bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
+       bv()->stuffClipboard(cur.selectionAsString(true));
 
        // this doesnt make sense, if there is no selection
        if (!cur.selection())
Index: text3.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text3.C,v
retrieving revision 1.219
diff -u -p -r1.219 text3.C
--- text3.C     6 Feb 2004 16:50:29 -0000       1.219
+++ text3.C     11 Feb 2004 13:52:37 -0000
@@ -46,19 +46,24 @@
 #include "insets/insettext.h"
 
 #include "support/lstrings.h"
+#include "support/lyxlib.h"
 #include "support/tostr.h"
 #include "support/std_sstream.h"
 
 #include "mathed/math_hullinset.h"
+#include "mathed/formulamacro.h"
 
 #include <clocale>
 
+
 using bv_funcs::replaceSelection;
 
 using lyx::pos_type;
 
 using lyx::support::isStrUnsignedInt;
 using lyx::support::strToUnsignedInt;
+using lyx::support::atoi;
+using lyx::support::token;
 
 using std::endl;
 using std::find;
@@ -123,7 +128,43 @@ namespace {
                cur.bv().owner()->view_state_changed();
        }
 
-} // anon namespace
+
+       void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
+       {
+               string sel = cur.selectionAsString(false);
+               lyxerr << "selection is: '" << sel << "'" << endl;
+
+               if (sel.empty()) {
+                       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
+                       // -- I really hate "LyXfunc overloading"...
+                       if (display)
+                               cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
+                       cur.dispatch(FuncRequest(LFUN_INSERT_MATH, cmd.argument));
+               } else {
+                       // create a macro if we see "\\newcommand" somewhere, and an 
ordinary
+                       // formula otherwise
+                       cur.bv().getLyXText()->cutSelection(true, true);
+                       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"));
+       }
+
+} // namespace anon
+
 
 
 namespace bv_funcs {
@@ -1269,21 +1310,38 @@ DispatchResult LyXText::dispatch(LCursor
                bv->update();
                break;
 
-       case LFUN_MATH_DELIM:
        case LFUN_MATH_DISPLAY:
-       case LFUN_INSERT_MATH:
-       case LFUN_MATH_LIMITS:
-       case LFUN_MATH_MACRO:
-       case LFUN_MATH_MUTATE:
-       case LFUN_MATH_SPACE:
+               mathDispatch(cur, cmd, true);
+               break;
+
        case LFUN_MATH_IMPORT_SELECTION:
        case LFUN_MATH_MODE:
-       case LFUN_MATH_NONUMBER:
-       case LFUN_MATH_NUMBER:
-       case LFUN_MATH_EXTERN:
-       case LFUN_MATH_SIZE:
-               mathDispatch(cur, cmd);
+               mathDispatch(cur, cmd, false);
+               break;
+
+       case LFUN_MATH_MACRO:
+               if (cmd.argument.empty())
+                       cur.errorMessage(N_("Missing argument"));
+               else {
+                       string s = cmd.argument;
+                       string const s1 = token(s, ' ', 1);
+                       int const nargs = s1.empty() ? 0 : atoi(s1);
+                       string const s2 = token(s, ' ', 2);
+                       string const type = s2.empty() ? "newcommand" : s2;
+                       cur.insert(new InsetFormulaMacro(token(s, ' ', 0), nargs, s2));
+                       cur.nextInset()->edit(cur, true);
+               }
+               break;
+
+       case LFUN_INSERT_MATH:
+       case LFUN_INSERT_MATRIX:
+       case LFUN_MATH_DELIM: {
+               cur.insert(new MathHullInset);
+               cur.dispatch(FuncRequest(LFUN_RIGHT));
+               cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
+               cur.dispatch(cmd);
                break;
+       }
 
        case LFUN_EMPH: {
                LyXFont font(LyXFont::ALL_IGNORE);
Index: insets/insetenv.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetenv.h,v
retrieving revision 1.17
diff -u -p -r1.17 insetenv.h
--- insets/insetenv.h   5 Nov 2003 12:06:07 -0000       1.17
+++ insets/insetenv.h   11 Feb 2004 13:52:37 -0000
@@ -15,6 +15,7 @@
 #include "insettext.h"
 #include "lyxlayout_ptr_fwd.h"
 
+
 class InsetEnvironment : public InsetText {
 public:
        ///
Index: insets/insettabular.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettabular.C,v
retrieving revision 1.400
diff -u -p -r1.400 insettabular.C
--- insets/insettabular.C       31 Jan 2004 15:30:23 -0000      1.400
+++ insets/insettabular.C       11 Feb 2004 13:52:37 -0000
@@ -974,6 +974,7 @@ void InsetTabular::getCursorPos(CursorSl
 
 void InsetTabular::setPos(BufferView & bv, int x, int y) const
 {
+       lyxerr << "# InsetTabular::setPos()  cursor: " << bv.cursor() << endl;
        int const cell = getCell(x + xo_, y + yo_);
        lyxerr << "# InsetTabular::setPos()  cell: " << cell << endl;
        InsetText const & inset = tabular.getCellInset(cell);
Index: mathed/math_diminset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_diminset.C,v
retrieving revision 1.21
diff -u -p -r1.21 math_diminset.C
--- mathed/math_diminset.C      2 Feb 2004 17:32:56 -0000       1.21
+++ mathed/math_diminset.C      11 Feb 2004 13:52:37 -0000
@@ -15,7 +15,7 @@
 
 
 MathDimInset::MathDimInset()
-       : xo_(-3), yo_(-3)
+       : xo_(-3), yo_(-3) // some sentinel value for debugging
 {}
 
 
@@ -39,7 +39,7 @@ int MathDimInset::width() const
 
 void MathDimInset::setPosCache(PainterInfo const &, int x, int y) const
 {
-       lyxerr << "MathDimInset:: position cache to " << x << " " << y << std::endl;
+       //lyxerr << "MathDimInset: cache to " << x << " " << y << std::endl;
        xo_ = x;
        yo_ = y;
 }
Index: mathed/math_hullinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_hullinset.C,v
retrieving revision 1.116
diff -u -p -r1.116 math_hullinset.C
--- mathed/math_hullinset.C     6 Feb 2004 16:14:06 -0000       1.116
+++ mathed/math_hullinset.C     11 Feb 2004 13:52:37 -0000
@@ -34,7 +34,6 @@
 
 #include "support/std_sstream.h"
 
-using lyx::support::trim;
 
 using std::endl;
 using std::max;
@@ -788,7 +787,7 @@ void MathHullInset::doExtern(LCursor & c
 DispatchResult
 MathHullInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
-       lyxerr << "*** MathHullInset: request: " << cmd << endl;
+       //lyxerr << "*** MathHullInset: request: " << cmd << endl;
        switch (cmd.action) {
 
                case LFUN_BREAKLINE:
@@ -837,7 +836,7 @@ MathHullInset::priv_dispatch(LCursor & c
                                        : Alert::askForText(_("Enter label:"), 
old_label);
                                if (!res.first)
                                        return DispatchResult(false);
-                               new_label = trim(res.second);
+                               new_label = lyx::support::trim(res.second);
                        }
 
                        //if (new_label == old_label)
@@ -1182,109 +1181,4 @@ int MathHullInset::docbook(Buffer const 
        ms <<   ETag("math");
        ms << ETag("equation");
        return ms.line() + res;
-}
-
-
-
-/////////////////////////////////////////////
-
-namespace {
-
-bool openNewInset(LCursor & cur, InsetBase * inset)
-{
-       cur.bv().getLyXText()->insertInset(inset);
-       inset->edit(cur, true);
-       return true;
-}
-
-
-void mathDispatchCreation(LCursor & cur, FuncRequest const & cmd,
-       bool display)
-{
-       // use selection if available..
-       //string sel;
-       //if (action == LFUN_MATH_IMPORT_SELECTION)
-       //      sel = "";
-       //else
-
-       string sel =
-               cur.bv().getLyXText()->selectionAsString(*cur.bv().buffer(), false);
-
-       if (sel.empty()) {
-               InsetBase * f = new MathHullInset;
-               if (openNewInset(cur, f)) {
-                       cur.inset()->dispatch(cur, FuncRequest(LFUN_MATH_MUTATE, 
"simple"));
-                       // don't do that also for LFUN_MATH_MODE unless you want end 
up with
-                       // always changing to mathrm when opening an inlined inset
-                       // -- I really hate "LyXfunc overloading"...
-                       if (display)
-                               f->dispatch(cur, FuncRequest(LFUN_MATH_DISPLAY));
-                       f->dispatch(cur, FuncRequest(LFUN_INSERT_MATH, cmd.argument));
-               }
-       } else {
-               // create a macro if we see "\\newcommand" somewhere, and an ordinary
-               // formula otherwise
-               InsetBase * f;
-               if (sel.find("\\newcommand") == string::npos &&
-                               sel.find("\\def") == string::npos)
-                       f = new MathHullInset(sel);
-               else
-                       f = new InsetFormulaMacro(sel);
-               cur.bv().getLyXText()->cutSelection(true, false);
-               openNewInset(cur, f);
-       }
-       cur.message(N_("Math editor mode"));
-}
-
-} // namespace anon
-
-
-void mathDispatch(LCursor & cur, FuncRequest const & cmd)
-{
-       if (!cur.bv().available())
-               return;
-
-       switch (cmd.action) {
-
-               case LFUN_MATH_DISPLAY:
-                       mathDispatchCreation(cur, cmd, true);
-                       break;
-
-               case LFUN_MATH_MODE:
-                       mathDispatchCreation(cur, cmd, false);
-                       break;
-
-               case LFUN_MATH_IMPORT_SELECTION:
-                       mathDispatchCreation(cur, cmd, false);
-                       break;
-
-/*
-               case LFUN_MATH_MACRO:
-                       if (cmd.argument.empty())
-                               cmd.errorMessage(N_("Missing argument"));
-                       else {
-                               string s = cmd.argument;
-                               string const s1 = token(s, ' ', 1);
-                               int const nargs = s1.empty() ? 0 : atoi(s1);
-                               string const s2 = token(s, ' ', 2);
-                               string const type = s2.empty() ? "newcommand" : s2;
-                               openNewInset(cur, new InsetFormulaMacro(token(s, ' ', 
0), nargs, s2));
-                       }
-                       break;
-
-               case LFUN_INSERT_MATH:
-               case LFUN_INSERT_MATRIX:
-               case LFUN_MATH_DELIM: {
-                       MathHullInset * f = new MathHullInset;
-                       if (openNewInset(cur, f)) {
-                               cur.inset()->dispatch(cur, 
FuncRequest(LFUN_MATH_MUTATE, "simple"));
-                               cur.inset()->dispatch(cur, cmd);
-                       }
-                       break;
-               }
-*/
-
-               default:
-                       break;
-       }
 }
Index: mathed/math_nestinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_nestinset.C,v
retrieving revision 1.91
diff -u -p -r1.91 math_nestinset.C
--- mathed/math_nestinset.C     6 Feb 2004 16:50:29 -0000       1.91
+++ mathed/math_nestinset.C     11 Feb 2004 13:52:37 -0000
@@ -207,7 +207,7 @@ void MathNestInset::draw(PainterInfo &, 
 }
 
 
-void MathNestInset::drawSelection(PainterInfo & pi, int x, int y) const
+void MathNestInset::drawSelection(PainterInfo & pi, int, int) const
 {
        // this should use the x/y values given, not the cached values
        LCursor & cur = pi.base.bv->cursor();
@@ -218,14 +218,12 @@ void MathNestInset::drawSelection(Painte
        CursorSlice & s1 = cur.selBegin();
        CursorSlice & s2 = cur.selEnd();
        if (s1.idx() == s2.idx()) {
-               MathArray const & c = s1.cell();
-               lyxerr << "###### c.xo(): " << c.xo() << " c.yo(): " << c.yo() << endl;
+               MathArray const & c = cell(s1.idx());
                int x1 = c.xo() + c.pos2x(s1.pos());
                int y1 = c.yo() - c.ascent();
                int x2 = c.xo() + c.pos2x(s2.pos());
                int y2 = c.yo() + c.descent();
-               //pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
-               pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::red);
+               pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
        } else {
                for (idx_type i = 0; i < nargs(); ++i) {
                        if (idxBetween(i, s1.idx(), s2.idx())) {
@@ -234,8 +232,7 @@ void MathNestInset::drawSelection(Painte
                                int y1 = c.yo() - c.ascent();
                                int x2 = c.xo() + c.width();
                                int y2 = c.yo() + c.descent();
-                               //pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, 
LColor::selection);
-                               pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, 
LColor::red);
+                               pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, 
LColor::selection);
                        }
                }
        }
@@ -354,12 +351,7 @@ void MathNestInset::handleFont2(LCursor 
 DispatchResult
 MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
-       lyxerr << "*** MathNestInset: request: " << cmd << std::endl;
-       //lyxerr << "InsetFormulaBase::localDispatch: act: " << cmd.action
-       //      << " arg: '" << cmd.argument
-       //      << "' x: '" << cmd.x
-       //      << " y: '" << cmd.y
-       //      << "' button: " << cmd.button() << endl;
+       lyxerr << "MathNestInset: request: " << cmd << std::endl;
 
        switch (cmd.action) {
 
@@ -388,48 +380,41 @@ MathNestInset::priv_dispatch(LCursor & c
                return dispatch(cur, FuncRequest(LFUN_PASTE, 
cur.bv().getClipboard())); 
 
        case LFUN_MOUSE_PRESS:
-               //lyxerr << "Mouse single press" << endl;
                return lfunMousePress(cur, cmd);
        case LFUN_MOUSE_MOTION:
-               //lyxerr << "Mouse motion" << endl;
                return lfunMouseMotion(cur, cmd);
        case LFUN_MOUSE_RELEASE:
-               //lyxerr << "Mouse single release" << endl;
                return lfunMouseRelease(cur, cmd);
        case LFUN_MOUSE_DOUBLE:
-               //lyxerr << "Mouse double" << endl;
                return dispatch(cur, FuncRequest(LFUN_WORDSEL));
 
        case LFUN_RIGHTSEL:
-               cur.selection() = true; // fall through...
        case LFUN_RIGHT:
+               cur.selHandle(cmd.action == LFUN_RIGHTSEL);
                return cur.right() ?
                        DispatchResult(true, true) : DispatchResult(false, 
FINISHED_RIGHT);
-               //lyxerr << "calling scroll 20" << endl;
-               //scroll(&cur.bv(), 20);
-               // write something to the minibuffer
-               //cur.bv().owner()->message(cur.info());
 
        case LFUN_LEFTSEL:
-               cur.selection() = true; // fall through
        case LFUN_LEFT:
+               cur.selHandle(cmd.action == LFUN_LEFTSEL);
                return cur.left() ?
                        DispatchResult(true, true) : DispatchResult(false, FINISHED);
 
        case LFUN_UPSEL:
-               cur.selection() = true; // fall through
        case LFUN_UP:
+               cur.selHandle(cmd.action == LFUN_UPSEL);
                return cur.up() ?
                        DispatchResult(true, true) : DispatchResult(false, 
FINISHED_UP);
 
        case LFUN_DOWNSEL:
-               cur.selection() = true; // fall through
        case LFUN_DOWN:
+               cur.selHandle(cmd.action == LFUN_DOWNSEL);
                return cur.down() ?
                        DispatchResult(true, true) : DispatchResult(false, 
FINISHED_DOWN);
 
        case LFUN_WORDSEL:
                cur.home();
+               cur.resetAnchor();
                cur.selection() = true;
                cur.end();
                return DispatchResult(true, true);
@@ -440,19 +425,27 @@ MathNestInset::priv_dispatch(LCursor & c
        case LFUN_DOWN_PARAGRAPH:
                return DispatchResult(true, FINISHED);
 
-       case LFUN_HOMESEL:
        case LFUN_WORDLEFTSEL:
-               cur.selection() = true; // fall through
-       case LFUN_HOME:
        case LFUN_WORDLEFT:
+               cur.selHandle(cmd.action == LFUN_WORDLEFTSEL);
                return cur.home()
                        ? DispatchResult(true, true) : DispatchResult(true, FINISHED);
 
-       case LFUN_ENDSEL:
        case LFUN_WORDRIGHTSEL:
-               cur.selection() = true; // fall through
-       case LFUN_END:
        case LFUN_WORDRIGHT:
+               cur.selHandle(cmd.action == LFUN_WORDRIGHTSEL);
+               return cur.end()
+                       ? DispatchResult(true, true) : DispatchResult(false, 
FINISHED_RIGHT);
+
+       case LFUN_HOMESEL:
+       case LFUN_HOME:
+               cur.selHandle(cmd.action == LFUN_HOMESEL);
+               return cur.home()
+                       ? DispatchResult(true, true) : DispatchResult(true, FINISHED);
+
+       case LFUN_ENDSEL:
+       case LFUN_END:
+               cur.selHandle(cmd.action == LFUN_ENDSEL);
                return cur.end()
                        ? DispatchResult(true, true) : DispatchResult(false, 
FINISHED_RIGHT);
 
@@ -516,32 +509,14 @@ MathNestInset::priv_dispatch(LCursor & c
 //
 // this needs to be incorporated
 //
-       //lyxerr << "InsetFormulaBase::localDispatch: act: " << cmd.action
-       //      << " arg: '" << cmd.argument
-       //      << "' x: '" << cmd.x
-       //      << " y: '" << cmd.y
-       //      << "' button: " << cmd.button() << endl;
-
        // delete empty mathbox (LFUN_BACKSPACE and LFUN_DELETE)
        bool remove_inset = false;
 
-       switch (cmd.action) {
-               default:
-                       break;
-       }
-
        DispatchResult result(true);
        bool was_macro     = cur.inMacroMode();
 
        cur.normalize();
        cur.touch();
-
-       switch (cmd.action) {
-
-       case LFUN_MATH_LIMITS:
-               //recordUndo(cur, Undo::ATOMIC);
-               cur.dispatch(cmd);
-               break;
 #endif
 
        //    case LFUN_GETXY:
@@ -676,7 +651,7 @@ MathNestInset::priv_dispatch(LCursor & c
        }
 
        case LFUN_MATH_DELIM: {
-               //lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'" << 
endl;
+               lyxerr << "MathNestInset::LFUN_MATH_DELIM" << endl;
                string ls;
                string rs = lyx::support::split(cmd.argument, ls, ' ');
                // Reasonable default values
@@ -706,16 +681,6 @@ MathNestInset::priv_dispatch(LCursor & c
                cur.interpret('\\');
                return DispatchResult(true, true);
 
-#if 0
-       case LFUN_BREAKPARAGRAPH:
-       case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
-       case LFUN_BREAKPARAGRAPH_SKIP:
-               cmd.argument = "\n";
-               //recordUndo(cur, Undo::ATOMIC);
-               cur.niceInsert(argument);
-               return DispatchResult(true, true);
-#endif
-
 // FIXME: We probably should swap parts of "math-insert" and "self-insert"
 // handling such that "self-insert" works on "arbitrary stuff" too, and
 // math-insert only handles special math things like "matrix".
@@ -766,17 +731,6 @@ MathNestInset::priv_dispatch(LCursor & c
                return
                        searchForward(&cur.bv(), cmd.getArg(0), false, false)
                                ? DispatchResult(true, true) : DispatchResult(false);
-
-       case LFUN_INSERT_MATH:
-       case LFUN_INSERT_MATRIX:
-       case LFUN_MATH_DELIM: {
-               MathHullInset * f = new MathHullInset;
-               if (openNewInset(cur, f)) {
-                       cur.inset()->dispatch(cur, FuncRequest(LFUN_MATH_MUTATE, 
"simple"));
-                       cur.inset()->dispatch(cur, cmd);
-               }
-               return DispatchResult(true, true);
-       }
 
        cur.normalize();
        cur.touch();
Index: mathed/math_scriptinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_scriptinset.C,v
retrieving revision 1.107
diff -u -p -r1.107 math_scriptinset.C
--- mathed/math_scriptinset.C   2 Feb 2004 17:32:56 -0000       1.107
+++ mathed/math_scriptinset.C   11 Feb 2004 13:52:37 -0000
@@ -514,8 +514,10 @@ void MathScriptInset::notifyCursorLeaves
 
 
 DispatchResult
-MathScriptInset::priv_dispatch(LCursor & bv, FuncRequest const & cmd)
+MathScriptInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
+       lyxerr << "MathScriptInset: request: " << cmd << std::endl;
+
        if (cmd.action == LFUN_MATH_LIMITS) {
                if (!cmd.argument.empty()) {
                        if (cmd.argument == "limits")
@@ -531,5 +533,5 @@ MathScriptInset::priv_dispatch(LCursor &
                return DispatchResult(true, true);
        }
 
-       return MathNestInset::priv_dispatch(bv, cmd);
+       return MathNestInset::priv_dispatch(cur, cmd);
 }

Reply via email to