Ok. I duplicated open_new_inset. Buffer*.h is _not_ touched anymore.
I think it is stupid. And it is even more stupid to waste time in such
effort...

Andre'

-- 
André Pönitz ............................................. [EMAIL PROTECTED]
Index: BufferView_pimpl.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v
retrieving revision 1.129
diff -u -p -r1.129 BufferView_pimpl.C
--- BufferView_pimpl.C  2001/07/04 07:19:08     1.129
+++ BufferView_pimpl.C  2001/07/05 07:51:51
@@ -57,8 +57,6 @@
 #include "insets/insetcaption.h"
 #include "insets/insetfloatlist.h"
 #include "insets/insetspecialchar.h"
-#include "mathed/formulamacro.h"
-#include "mathed/formula.h"
 #include "gettext.h"
 #include "ParagraphParameters.h"
 
@@ -85,6 +83,11 @@ extern bool math_insert_greek(BufferView
 extern void sigchldhandler(pid_t pid, int * status);
 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
 
+// wrap up all mathed specific code in this function
+// which is defined in mathed/formulabase.C
+extern UpdatableInset::RESULT
+       InsetFormulaExternalDispatch(BufferView *, kb_action, string const &);
+
 namespace {
 
 const unsigned int saved_positions_num = 20;
@@ -2906,57 +2909,12 @@ bool BufferView::Pimpl::Dispatch(kb_acti
        
        case LFUN_MATH_DELIM:     
        case LFUN_INSERT_MATRIX:
-       {          
-               if (available()) { 
-                       if (open_new_inset(new InsetFormula, false)) {
-                               bv_->theLockingInset()
-                                       ->localDispatch(bv_, action, argument);
-                       }
-               }
-       }          
-       break;
-              
        case LFUN_INSERT_MATH:
-       {
-               if (!available())
-                       break;
- 
-               InsetFormula * f = new InsetFormula(LM_OT_EQUATION);
-               open_new_inset(f);
-               f->localDispatch(bv_, LFUN_INSERT_MATH, argument);
-       }
-       break;
-       
-       case LFUN_MATH_DISPLAY:
-       {       
-               if (available())
-                       open_new_inset(new InsetFormula(LM_OT_EQUATION), false);
-               break;
-       }
-                   
-       case LFUN_MATH_MACRO:
-       {
-               if (available()) {
-                       string s(argument);
-                       if (s.empty())
-                               owner_->getLyXFunc()->setErrorMessage(N_("Missing 
argument"));
-                       else {
-                               string const s1 = token(s, ' ', 1);
-                               int const na = s1.empty() ? 0 : lyx::atoi(s1);
-                               open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), 
na), false);
-                       }
-               }
-       }
-       break;
-
-       case LFUN_MATH_MODE:   // Open or create a math inset
-       {               
-               if (available())
-                       open_new_inset(new InsetFormula, false);
-               owner_->getLyXFunc()->setMessage(N_("Math editor mode"));
-       }
-       break;
-         
+       case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
+       case LFUN_MATH_DISPLAY:          // Open or create a displayed math inset
+       case LFUN_MATH_MODE:             // Open or create an inlined math inset 
+               return InsetFormulaExternalDispatch(bv_, action, argument);
+               
        case LFUN_CITATION_INSERT:
        {
                InsetCommandParams p;
Index: LyXAction.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/LyXAction.C,v
retrieving revision 1.88
diff -u -p -r1.88 LyXAction.C
--- LyXAction.C 2001/06/27 14:10:22     1.88
+++ LyXAction.C 2001/07/05 07:51:51
@@ -289,6 +289,7 @@ void LyXAction::init()
                { LFUN_MATH_LIMITS, "math-limits", "", Noop },
                { LFUN_MATH_MACRO, "math-macro", "", Noop },
                { LFUN_MATH_MUTATE, "math-mutate", "", Noop },
+               { LFUN_MATH_IMPORT_SELECTION, "math-import-selection", "", Noop },
                { LFUN_MATH_MACROARG, "math-macro-arg", "", Noop },
                { LFUN_INSERT_MATRIX, "math-matrix", "", Noop },
                { LFUN_MATH_MODE, "math-mode", N_("Math mode"), Noop },
Index: commandtags.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/commandtags.h,v
retrieving revision 1.64
diff -u -p -r1.64 commandtags.h
--- commandtags.h       2001/06/27 14:10:24     1.64
+++ commandtags.h       2001/07/05 07:51:51
@@ -148,15 +148,16 @@ enum kb_action {
        LFUN_MATH_SIZE,   //  Alejandro 150896
        LFUN_MATH_MACRO, // ale970510
        LFUN_MATH_MACROARG,  // ale970510  // 120
-       LFUN_MATH_EXTERN,          // Andre' 20010424
-       LFUN_MATH_PANEL,           // Andre' 20010522
-       LFUN_MATH_VALIGN,          // Andre' 20010522
-       LFUN_MATH_HALIGN,          // Andre' 20010522
-       LFUN_MATH_ROW_INSERT,      // Andre' 20010522
-       LFUN_MATH_ROW_DELETE,      // Andre' 20010522
-       LFUN_MATH_COLUMN_INSERT,   // Andre' 20010522
-       LFUN_MATH_COLUMN_DELETE,   // Andre' 20010522
-       LFUN_MATH_MUTATE,          // Andre' 20010523
+       LFUN_MATH_EXTERN,           // Andre' 20010424
+       LFUN_MATH_PANEL,            // Andre' 20010522
+       LFUN_MATH_VALIGN,           // Andre' 20010522
+       LFUN_MATH_HALIGN,           // Andre' 20010522
+       LFUN_MATH_ROW_INSERT,       // Andre' 20010522
+       LFUN_MATH_ROW_DELETE,       // Andre' 20010522
+       LFUN_MATH_COLUMN_INSERT,    // Andre' 20010522
+       LFUN_MATH_COLUMN_DELETE,    // Andre' 20010522
+       LFUN_MATH_MUTATE,           // Andre' 20010523
+       LFUN_MATH_IMPORT_SELECTION, // Andre' 20010523
        LFUN_FIGURE,
        LFUN_DELETE_WORD_FORWARD,
        LFUN_DELETE_WORD_BACKWARD,
Index: mathed/formula.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/formula.C,v
retrieving revision 1.109
diff -u -p -r1.109 formula.C
--- mathed/formula.C    2001/06/28 10:25:20     1.109
+++ mathed/formula.C    2001/07/05 07:51:51
@@ -70,49 +70,56 @@ InsetFormula::InsetFormula(MathInsetType
 {}
 
 
+InsetFormula::InsetFormula(string const & s)
+       : InsetFormulaBase(0)
+{
+       istringstream is(s.c_str());
+       par(mathed_parse(is));
+}
 
+
 Inset * InsetFormula::clone(Buffer const &) const
 {
        return new InsetFormula(*this);
 }
 
 
-void InsetFormula::write(Buffer const * buf, ostream & os) const
+void InsetFormula::write(ostream & os) const
 {
        os << "Formula ";
-       latex(buf, os, false, false);
+       latex(os, false, false);
 }
 
 
-int InsetFormula::latex(Buffer const *, ostream & os, bool fragile, bool) const
+int InsetFormula::latex(ostream & os, bool fragile, bool) const
 {
        par()->Write(os, fragile);
        return 1;
 }
 
 
-int InsetFormula::ascii(Buffer const *, ostream & os, int) const
+int InsetFormula::ascii(ostream & os, int) const
 {
        par()->Write(os, false);
        return 1;
 }
 
 
-int InsetFormula::linuxdoc(Buffer const * buf, ostream & os) const
+int InsetFormula::linuxdoc(ostream & os) const
 {
-       return ascii(buf, os, 0);
+       return ascii(os, 0);
 }
 
 
-int InsetFormula::docBook(Buffer const * buf, ostream & os) const
+int InsetFormula::docBook(ostream & os) const
 {
-       return ascii(buf, os, 0);
+       return ascii(os, 0);
 }
 
 
-void InsetFormula::read(Buffer const *, LyXLex & lex)
+void InsetFormula::read(LyXLex & lex)
 {
-       par_ = mathed_parse(lex);
+       par(mathed_parse(lex));
 }
 
 
@@ -167,7 +174,7 @@ InsetFormula::localDispatch(BufferView *
 
                case LFUN_BREAKLINE: 
                        bv->lockedInsetStoreUndo(Undo::INSERT);
-                       par()->breakLine();
+                       mathcursor->breakLine();
                        updateLocal(bv);
                        break;
 
@@ -245,24 +252,28 @@ InsetFormula::localDispatch(BufferView *
                }
 
                case LFUN_MATH_EXTERN:
+                       bv->lockedInsetStoreUndo(Undo::EDIT);
                        handleExtern(arg, bv);
                        updateLocal(bv);
                        break;
 
                case LFUN_MATH_MUTATE:
+               {
+                       bv->lockedInsetStoreUndo(Undo::EDIT);
+                       int x, y;
+                       mathcursor->GetPos(x, y);
                        par()->mutate(arg);
-                       updateLocal(bv);
-                       break;
-
-               case LFUN_TABINSERT:
-                       lyxerr << "take index from cursor\n";
-                       par()->splitCell(0);
+                       mathcursor->SetPos(x, y);
+                       mathcursor->normalize();
                        updateLocal(bv);
                        break;
+               }
 
                case LFUN_MATH_DISPLAY:
-                       if (par()->GetType() == LM_OT_SIMPLE)
+                       if (par()->GetType() == LM_OT_SIMPLE) {
                                par()->mutate(LM_OT_EQUATION);
+                               par()->numbered(0, false);
+                       }
                        else
                                par()->mutate(LM_OT_SIMPLE);
                        updateLocal(bv);
@@ -288,7 +299,7 @@ void InsetFormula::handleExtern(const st
        Systemcalls cmd(Systemcalls::System, script, 0);
 
        ifstream is(outfile.c_str());
-       par_ = mathed_parse(is);
+       par(mathed_parse(is));
 }
 
 bool InsetFormula::display() const
@@ -302,6 +313,12 @@ MathMatrixInset * InsetFormula::par() co
        return static_cast<MathMatrixInset *>(par_);
 }
 
+void InsetFormula::par(MathInset * p)
+{ 
+       delete par_;
+       par_ = p ? p : new MathMatrixInset;
+}
+
 
 Inset::Code InsetFormula::lyxCode() const
 {
@@ -332,13 +349,3 @@ int InsetFormula::width(BufferView *, Ly
        par()->Metrics(LM_ST_TEXT);
        return par()->width();
 }
-
-/*
-LyXFont const InsetFormula::ConvertFont(LyXFont const & f) const
-{
-       // We have already discussed what was here
-       LyXFont font(f);
-       font.setLatex(LyXFont::OFF);
-       return font;
-}
-*/
Index: mathed/formula.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/formula.h,v
retrieving revision 1.41
diff -u -p -r1.41 formula.h
--- mathed/formula.h    2001/06/28 10:25:20     1.41
+++ mathed/formula.h    2001/07/05 07:51:51
@@ -21,6 +21,7 @@
 #pragma interface
 #endif
 
+#include "LString.h"
 #include "mathed/formulabase.h"
 #include "math_defs.h"
 
@@ -34,6 +35,8 @@ public:
        ///
        explicit InsetFormula(MathInsetTypes);
        ///
+       explicit InsetFormula(string const &);
+       ///
        int ascent(BufferView *, LyXFont const &) const;
        ///
        int descent(BufferView *, LyXFont const &) const;
@@ -41,19 +44,21 @@ public:
        int width(BufferView *, LyXFont const &) const;
        ///
        void draw(BufferView *, LyXFont const &, int, float &, bool) const;
+
        ///
-       void write(Buffer const *, std::ostream &) const;
+       void write(std::ostream &) const;
        ///
-       void read(Buffer const *, LyXLex & lex);
+       void read(LyXLex & lex);
        ///
-       int latex(Buffer const *, std::ostream &,
+       int latex(std::ostream &,
                  bool fragile, bool free_spc) const;
        ///
-       int ascii(Buffer const *, std::ostream &, int linelen) const;
+       int ascii(std::ostream &, int linelen) const;
        ///
-       int linuxdoc(Buffer const *, std::ostream &) const;
+       int linuxdoc(std::ostream &) const;
        ///
-       int docBook(Buffer const *, std::ostream &) const;
+       int docBook(std::ostream &) const;
+
        ///
        Inset * clone(Buffer const &) const;
        ///
@@ -72,5 +77,8 @@ public:
        bool display() const;
        ///
        bool ams() const;
+private:
+       /// Safe setting of contents
+       void par(MathInset *);
 };
 #endif
Index: mathed/formulabase.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/formulabase.C,v
retrieving revision 1.7
diff -u -p -r1.7 formulabase.C
--- mathed/formulabase.C        2001/07/03 07:56:55     1.7
+++ mathed/formulabase.C        2001/07/05 07:51:51
@@ -23,11 +23,13 @@
 #endif
 
 #include "formula.h"
+#include "formulamacro.h"
 #include "commandtags.h"
 #include "math_cursor.h"
 #include "math_parser.h"
 #include "BufferView.h"
 #include "lyxtext.h"
+#include "lyxfunc.h"
 #include "gettext.h"
 #include "LaTeXFeatures.h"
 #include "debug.h"
@@ -75,6 +77,20 @@ void handleFont(BufferView * bv, MathTex
        mathcursor->handleFont(t);
 }
 
+bool openNewInset(BufferView * bv, UpdatableInset * new_inset)
+{
+       LyXText * lt = bv->getLyXText();
+       
+       bv->beforeChange(lt);
+       lt->finishUndo();
+       if (!bv->insertInset(new_inset)) {
+               delete new_inset;
+               return false;
+       }
+       new_inset->edit(bv, 0, 0, 0);
+       return true;
+}
+
 } // namespaces
 
 
@@ -222,32 +238,39 @@ InsetFormulaBase::~InsetFormulaBase()
 }
 
 
-void InsetFormulaBase::write(Buffer const * buf, ostream & os) const
+void InsetFormulaBase::read(Buffer const *, LyXLex & lex)
 {
-       os << "Formula ";
-       latex(buf, os, false, false);
+       read(lex);
 }
-
 
-int InsetFormulaBase::ascii(Buffer const *, ostream & os, int) const
+void InsetFormulaBase::write(Buffer const *, ostream & os) const
 {
-       par_->Write(os, false);
-       return 0;
+       write(os);
 }
 
+int InsetFormulaBase::latex(Buffer const *, ostream & os,
+       bool fragile, bool spacing) const
+{
+       return latex(os, fragile, spacing);
+}
 
-int InsetFormulaBase::linuxdoc(Buffer const * buf, ostream & os) const
+int InsetFormulaBase::ascii(Buffer const *, ostream & os, int spacing) const
 {
-       return ascii(buf, os, 0);
+       return ascii(os, spacing);
 }
 
+int InsetFormulaBase::linuxdoc(Buffer const *, ostream & os) const
+{
+       return linuxdoc(os);
+}
 
-int InsetFormulaBase::docBook(Buffer const * buf, ostream & os) const
+int InsetFormulaBase::docBook(Buffer const *, ostream & os) const
 {
-       return ascii(buf, os, 0);
+       return docBook(os);
 }
 
 
+
 // Check if uses AMS macros
 void InsetFormulaBase::validate(LaTeXFeatures &) const
 {}
@@ -522,14 +545,18 @@ InsetFormulaBase::localDispatch(BufferVi
                break;
 
        case LFUN_TAB:
-               bv->lockedInsetStoreUndo(Undo::INSERT);
-               mathcursor->idxRight();
+               mathcursor->idxNext();
+               updateLocal(bv);
+               break;
+
+       case LFUN_SHIFT_TAB:
+               mathcursor->idxPrev();
                updateLocal(bv);
                break;
 
        case LFUN_TABINSERT:
-               bv->lockedInsetStoreUndo(Undo::INSERT);
-               mathcursor->idxRight();
+               bv->lockedInsetStoreUndo(Undo::EDIT);
+               mathcursor->splitCell();
                updateLocal(bv);
                break;
 
@@ -829,6 +856,9 @@ InsetFormulaBase::localDispatch(BufferVi
        default:
                if ((action == -1 || action == LFUN_SELFINSERT) && !arg.empty()) {
                        unsigned char c = arg[0];
+                       lyxerr << "char: '" << c << "'  int: " << int(c) << endl;
+                       //owner_->getIntl()->getTrans().TranslateAndInsert(c, lt);     
+ 
+                       lyxerr << "trans: '" << c << "'  int: " << int(c) << endl;
                        bv->lockedInsetStoreUndo(Undo::INSERT);
 
                        if (c == ' ' && mathcursor->getAccent() == LM_hat) {
@@ -1044,3 +1074,90 @@ MathInset * InsetFormulaBase::par() cons
        return par_;
 }
 
+
+UpdatableInset::RESULT
+InsetFormulaExternalDispatch(BufferView * bv, kb_action action,
+                           string const & arg)
+{
+       UpdatableInset::RESULT result = UpdatableInset::DISPATCHED;
+
+       switch (action) {
+               case LFUN_MATH_DELIM:     
+               case LFUN_INSERT_MATRIX:
+               {          
+                       if (bv->available()) { 
+                               if (openNewInset(bv, new InsetFormula)) {
+                                       bv->theLockingInset()
+                                               ->localDispatch(bv, action, arg);
+                               }
+                       }
+               }          
+               break;
+                                        
+               case LFUN_INSERT_MATH:
+               {
+                       if (bv->available()) {
+                               if (arg.size() && arg[0] == '\\') {
+                                       InsetFormula * f = new InsetFormula(arg);
+                                       openNewInset(bv, f);
+                               } else {
+                                       return InsetFormulaExternalDispatch(bv, 
+LFUN_MATH_DISPLAY, arg);
+                               }
+                       }
+               }
+               break;
+               
+               case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
+               case LFUN_MATH_DISPLAY:          // Open or create a displayed math 
+inset
+               case LFUN_MATH_MODE:             // Open or create an inlined math 
+inset 
+               {       
+                       if (bv->available()) {
+// Feature "Read math inset from selection" disabled.
+//                             // use selection if available..
+//                             string sel;
+//                             if (action == LFUN_MATH_IMPORT_SELECTION)
+//                                     sel = "";
+//                             else
+//                                     sel = 
+bv->getLyXText()->selectionAsString(bv->buffer());
+
+                               InsetFormula * f;
+//                             if (sel.empty()) {
+                                       f = new InsetFormula;
+                                       openNewInset(bv, f);
+                                       // 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 (action == LFUN_MATH_DISPLAY)
+                                               f->localDispatch(bv, 
+LFUN_MATH_DISPLAY, string());
+                                       f->localDispatch(bv, LFUN_INSERT_MATH, arg);
+//                             } else {
+//                                     f = new InsetFormula(sel);
+//                                     bv->getLyXText()->cutSelection(bv);
+//                                     openNewInset(bv, f);
+//                             }
+                       }
+                       bv->owner()->getLyXFunc()->setMessage(N_("Math editor mode"));
+                       break;
+               }
+                       
+               case LFUN_MATH_MACRO:
+               {
+                       if (bv->available()) {
+                               string s(arg);
+                               if (s.empty())
+                                       
+bv->owner()->getLyXFunc()->setErrorMessage(N_("Missing argument"));
+                               else {
+                                       string const s1 = token(s, ' ', 1);
+                                       int const na = s1.empty() ? 0 : lyx::atoi(s1);
+                                       openNewInset(bv, new 
+InsetFormulaMacro(token(s, ' ', 0), na));
+                               }
+                       }
+               }
+               break;
+
+               default:
+                       result = UpdatableInset::UNDISPATCHED;
+       }
+
+       return result;
+}
Index: mathed/formulabase.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/formulabase.h,v
retrieving revision 1.2
diff -u -p -r1.2 formulabase.h
--- mathed/formulabase.h        2001/06/28 10:25:20     1.2
+++ mathed/formulabase.h        2001/07/05 07:51:51
@@ -1,15 +1,13 @@
 // -*- C++ -*-
 /*
- *  File:        formula.h
- *  Purpose:     Declaration of formula inset
- *  Author:      Alejandro Aguilar Sierra <[EMAIL PROTECTED]> 
- *  Created:     January 1996
+ *  File:        formulabase.h
+ *  Purpose:     Common parts of the math LyX insets
+ *  Author:      André Pönitz
+ *  Created:     May 2001
  *  Description: Allows the edition of math paragraphs inside Lyx. 
  *
- *  Copyright: 1996, Alejandro Aguilar Sierra
+ *  Copyright: 2001, The LyX Project
  *
- *  Version: 0.4, Lyx project.
- *
  *   You are free to use and modify this code under the terms of
  *   the GNU General Public Licence version 2 or later.
  */
@@ -27,6 +25,7 @@
 #include "insets/inset.h"
 
 class Buffer;
+class BufferView;
 class MathInset;
 
 ///
@@ -46,20 +45,39 @@ public:
        virtual int width(BufferView *, LyXFont const &) const = 0;
        ///
        virtual void draw(BufferView *,LyXFont const &, int, float &, bool) const = 0;
-       ///
-       virtual void write(Buffer const *, std::ostream &) const = 0;
+
+       /// These are just wrappers taking the unused Buffer * dummy parameter
+       /// 
+       virtual void write(Buffer const *, std::ostream &) const;
        ///
-       virtual void read(Buffer const *, LyXLex & lex) = 0;
+       virtual void read(Buffer const *, LyXLex & lex);
        ///
        virtual int latex(Buffer const *, std::ostream &,
-                 bool fragile, bool free_spc) const = 0;
+                 bool fragile, bool free_spc) const;
        ///
-       virtual int ascii(Buffer const *, std::ostream &, int linelen) const = 0;
+       virtual int ascii(Buffer const *, std::ostream &, int linelen) const;
+       ///
+       virtual int linuxdoc(Buffer const *, std::ostream &) const;
+       ///
+       virtual int docBook(Buffer const *, std::ostream &) const;
+
+protected:
+       /// the actual functions don't use the Buffer * parameter
        ///
-       virtual int linuxdoc(Buffer const *, std::ostream &) const = 0;
+       virtual void write(std::ostream &) const = 0;
        ///
-       virtual int docBook(Buffer const *, std::ostream &) const = 0;
+       virtual void read(LyXLex & lex) = 0;
        ///
+       virtual int latex(std::ostream &, bool fragile, bool free_spc) const = 0;
+       ///
+       virtual int ascii(std::ostream &, int linelen) const = 0;
+       ///
+       virtual int linuxdoc(std::ostream &) const = 0;
+       ///
+       virtual int docBook(std::ostream &) const = 0;
+
+public:
+       ///
        virtual void validate(LaTeXFeatures &) const;
        ///
        virtual Inset * clone(Buffer const &) const = 0;
@@ -92,7 +110,7 @@ public:
        ///
        virtual void insetUnlock(BufferView *);
    
-       ///  To allow transparent use of math editing functions
+       /// To allow transparent use of math editing functions
        virtual RESULT localDispatch(BufferView *, kb_action, string const &);
     
        ///
@@ -106,5 +124,10 @@ protected:
        ///
        MathInset * par_;
 };
+
+// We don't really mess want around with mathed stuff outside mathed.
+// So do it here.
+UpdatableInset::RESULT
+       InsetFormulaExternalDispatch(BufferView *, kb_action, string const &);
 
 #endif
Index: mathed/formulamacro.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/formulamacro.C,v
retrieving revision 1.59
diff -u -p -r1.59 formulamacro.C
--- mathed/formulamacro.C       2001/06/28 10:25:20     1.59
+++ mathed/formulamacro.C       2001/07/05 07:51:51
@@ -61,40 +61,40 @@ Inset * InsetFormulaMacro::clone(Buffer 
 }
 
 
-void InsetFormulaMacro::write(Buffer const *, ostream & os) const
+void InsetFormulaMacro::write(ostream & os) const
 {
        os << "FormulaMacro ";
        tmacro()->Write(os, false);
 }
 
 
-int InsetFormulaMacro::latex(Buffer const *, ostream & os, bool fragile, 
+int InsetFormulaMacro::latex(ostream & os, bool fragile, 
                             bool /*free_spacing*/) const
 {
        tmacro()->Write(os, fragile);
        return 2;
 }
 
-int InsetFormulaMacro::ascii(Buffer const *, ostream & os, int) const
+int InsetFormulaMacro::ascii(ostream & os, int) const
 {
        tmacro()->Write(os, false);
        return 0;
 }
 
 
-int InsetFormulaMacro::linuxdoc(Buffer const * buf, ostream & os) const
+int InsetFormulaMacro::linuxdoc(ostream & os) const
 {
-       return ascii(buf, os, 0);
+       return ascii(os, 0);
 }
 
 
-int InsetFormulaMacro::docBook(Buffer const * buf, ostream & os) const
+int InsetFormulaMacro::docBook(ostream & os) const
 {
-       return ascii(buf, os, 0);
+       return ascii(os, 0);
 }
 
 
-void InsetFormulaMacro::read(Buffer const *, LyXLex & lex)
+void InsetFormulaMacro::read(LyXLex & lex)
 {
        // Awful hack...
        par_ = mathed_parse(lex);
@@ -141,7 +141,8 @@ void InsetFormulaMacro::draw(BufferView 
        int const w = width(bv, font) - 2;
        int const h = ascent(bv, font) + descent(bv, font) - 2;
 
-       pain.fillRectangle(int(x), y , w, h, LColor::mathbg);
+       // LColor::mathbg used to be "AntiqueWhite" but is "linen" now, too
+       pain.fillRectangle(int(x), y , w, h, LColor::mathmacrobg);
        pain.rectangle(int(x), y, w, h, LColor::mathframe);
 
        if (mathcursor && mathcursor->formula() == this && mathcursor->Selection()) {
Index: mathed/formulamacro.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/formulamacro.h,v
retrieving revision 1.36
diff -u -p -r1.36 formulamacro.h
--- mathed/formulamacro.h       2001/06/28 10:25:20     1.36
+++ mathed/formulamacro.h       2001/07/05 07:51:51
@@ -44,19 +44,20 @@ public:
        int width(BufferView *, LyXFont const &) const;
        ///
        void draw(BufferView *,LyXFont const &, int, float &, bool) const;
+
        ///
-       void read(Buffer const *, LyXLex & lex);
+       void read(LyXLex & lex);
        ///
-       void write(Buffer const *, std::ostream & os) const;
+       void write(std::ostream & os) const;
        ///
-       int ascii(Buffer const *, std::ostream &, int linelen) const;
+       int ascii(std::ostream &, int linelen) const;
        ///
-       int latex(Buffer const *, std::ostream & os, bool fragile,
-                 bool free_spc) const;
+       int latex(std::ostream & os, bool fragile, bool free_spc) const;
        ///
-       int linuxdoc(Buffer const *, std::ostream & os) const;
+       int linuxdoc(std::ostream & os) const;
        ///
-       int docBook(Buffer const *, std::ostream &) const;
+       int docBook(std::ostream &) const;
+
        ///
        Inset * clone(Buffer const &) const;
        ///
Index: mathed/math_cursor.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_cursor.C,v
retrieving revision 1.53
diff -u -p -r1.53 math_cursor.C
--- mathed/math_cursor.C        2001/07/03 07:56:55     1.53
+++ mathed/math_cursor.C        2001/07/05 07:51:51
@@ -20,6 +20,7 @@
 #endif
 
 #include <config.h>
+#include <cctype>
 
 #include "math_inset.h"
 #include "math_parser.h"
@@ -51,6 +52,7 @@
 using std::endl;
 using std::min;
 using std::max;
+using std::isalnum;
 
 
 namespace {
@@ -174,8 +176,8 @@ bool MathCursor::Left(bool sel)
                        result = array().next(anchor_);
                }
        } else {
-               MathInset * p = prevActiveInset();
-               if (p) {
+               MathInset * p = prevInset();
+               if (p && p->isActive()) {
                        // We have to move deeper into the previous inset
                        array().prev(cursor_);
                        push(p, false);
@@ -224,8 +226,8 @@ bool MathCursor::Right(bool sel)
                        result = array().next(cursor_);
                }
        } else {
-               MathInset * p = nextActiveInset();
-               if (p) {
+               MathInset * p = nextInset();
+               if (p && p->isActive()) {
                        push(p, true);
                        result = true;
                } else {
@@ -281,6 +283,7 @@ void MathCursor::SetPos(int x, int y)
        while (1) {
                idx_    = -1;
                cursor_ = -1;
+               lyxerr << "found idx: " << idx_ << " cursor: " << cursor_  << "\n";
                int distmin = 1 << 30; // large enough
                for (int i = 0; i < par_->nargs(); ++i) {
                        MathXArray const & ar = par_->xcell(i);
@@ -298,11 +301,11 @@ void MathCursor::SetPos(int x, int y)
                        }
                }
                lyxerr << "found idx: " << idx_ << " cursor: " << cursor_  << "\n";
-               if (nextIsActive() && nextInset()->covers(x, y)) {
-                       MathInset * p = nextActiveInset();
-                       push(p, true);
-               } else if (prevIsActive() && prevInset()->covers(x, y)) {
-                       MathInset * p = prevActiveInset();
+               MathInset * n = nextInset();
+               MathInset * p = prevInset();
+               if (n && (n->isActive() || n->isScriptInset()) && n->covers(x, y))
+                       push(n, true);
+               else if (p && (p->isActive() || p->isScriptInset()) && p->covers(x, 
+y)) {
                        array().prev(cursor_);
                        push(p, false);
                } else 
@@ -661,10 +664,15 @@ void MathCursor::Interpret(string const 
        }
 
        if (p) {
+               bool oldsel = selection;
+               if (oldsel) 
+                       SelCut();
                insert(p);
                if (p->nargs()) {
                        array().prev(cursor_);
                        push(p, true);
+                       if (oldsel) 
+                               SelPaste();
                }
                p->Metrics(p->size());
        }
@@ -920,10 +928,11 @@ void MathCursor::handleFont(MathTextCode
        if (selection)  {
                int const p1 = std::min(cursor_, anchor_);
                int const p2 = std::max(cursor_, anchor_);
-               for (int pos = p1; pos != p2; array().next(pos))
-                       if (!array().isInset(pos)) { 
-                               MathTextCodes c = array().GetCode(pos) == t ? 
LM_TC_VAR : t;
-                               array().setCode(pos, c);
+               MathArray & ar = array();
+               for (int pos = p1; pos != p2; ar.next(pos))
+                       if (!ar.isInset(pos) && isalnum(ar.GetChar(pos))) { 
+                               MathTextCodes c = ar.GetCode(pos) == t ? LM_TC_VAR : t;
+                               ar.setCode(pos, c);
                        }
        } else {
                if (lastcode == t)
@@ -1094,14 +1103,6 @@ MathInset * MathCursor::prevInset() cons
        return array().GetInset(c);
 }
 
-MathInset * MathCursor::prevActiveInset() const
-{
-       if (cursor_ <= 0 || !array().isInset(cursor_ - 1))
-               return 0;
-       MathInset * inset = prevInset();
-       return inset->isActive() ? inset : 0;
-}
-
 
 MathInset * MathCursor::nextInset() const
 {
@@ -1110,15 +1111,6 @@ MathInset * MathCursor::nextInset() cons
 }
 
 
-MathInset * MathCursor::nextActiveInset() const
-{
-       if (!array().isInset(cursor_))
-               return 0;
-       MathInset * inset = nextInset();
-       return inset->isActive() ? inset : 0;
-}
-
-
 MathScriptInset * MathCursor::nearbyScriptInset() const
 {
        normalize();
@@ -1160,24 +1152,12 @@ bool MathCursor::nextIsInset() const
 }
 
 
-bool MathCursor::nextIsActive() const
-{
-       return nextIsInset() && nextInset()->isActive();
-}
-
-
 bool MathCursor::prevIsInset() const
 {
        return cursor_ > 0 && MathIsInset(prevCode());
 }
 
 
-bool MathCursor::prevIsActive() const
-{
-       return prevIsInset() && prevInset()->isActive();
-}
-
-
 bool MathCursor::IsFont() const
 {
        return MathIsFont(nextCode());
@@ -1202,9 +1182,49 @@ void MathCursor::gotoX(int x)
        cursor_ = xarray().x2pos(x);    
 }
 
-void MathCursor::idxRight()
+void MathCursor::idxNext()
 {
-       par_->idxRight(idx_, cursor_);
+       par_->idxNext(idx_, cursor_);
+}
+
+void MathCursor::idxPrev()
+{
+       par_->idxPrev(idx_, cursor_);
+}
+
+void MathCursor::splitCell()
+{
+       if (idx_ == par_->nargs() - 1) 
+               return;
+       MathArray ar = array();
+       ar.erase(0, cursor_);
+       array().erase(cursor_, array().size());
+       ++idx_;
+       cursor_ = 0;
+       array().insert(0, ar);
+}
+
+void MathCursor::breakLine()
+{
+       MathMatrixInset * p = static_cast<MathMatrixInset *>(formula()->par());
+       if (p->GetType() == LM_OT_SIMPLE || p->GetType() == LM_OT_EQUATION)
+               p->mutate(LM_OT_EQNARRAY);
+       p->addRow(row());
+
+       // split line
+       const int r = row();
+       for (int c = col() + 1; c < p->ncols(); ++c) {
+               const int i1 = p->index(r, c);
+               const int i2 = p->index(r + 1, c);      
+               lyxerr << "swapping cells " << i1 << " and " << i2 << "\n";
+               p->cell(i1).swap(p->cell(i2));
+       }
+
+       // split cell
+       splitCell();
+       MathArray & halfcell = array();
+       idx_ += p->ncols() - 1;
+       halfcell.swap(array());
 }
 
 char MathCursor::valign() const
Index: mathed/math_cursor.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_cursor.h,v
retrieving revision 1.22
diff -u -p -r1.22 math_cursor.h
--- mathed/math_cursor.h        2001/07/03 07:56:55     1.22
+++ mathed/math_cursor.h        2001/07/05 07:51:51
@@ -117,13 +117,19 @@ public:
        void setLastCode(MathTextCodes t);
        ///
        void handleFont(MathTextCodes t);
+       /// Splits cells and shifts right part to the next cell
+       void splitCell();
+       /// Splits line and insert new row of cell 
+       void breakLine();
        ///
        MathTextCodes getLastCode() const;
        ///
        int idx() const { return idx_; }
        ///
-       void idxRight();
+       void idxNext();
        ///
+       void idxPrev();
+       ///
        void pullArg();
        ///
        bool isInside(MathInset *) const;
@@ -213,12 +219,8 @@ private:
        ///
        bool nextIsInset() const;
        ///
-       bool nextIsActive() const;
-       ///
        bool prevIsInset() const;
        ///
-       bool prevIsActive() const;
-       ///
        bool IsFont() const;
        ///
        bool IsScript() const;
@@ -227,11 +229,7 @@ private:
        ///
        MathInset * nextInset() const;
        ///
-       MathInset * nextActiveInset() const;
-       ///
        MathInset * prevInset() const;
-       ///
-       MathInset * prevActiveInset() const;
        ///
        MathScriptInset * nearbyScriptInset() const;
 
Index: mathed/math_grid.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_grid.h,v
retrieving revision 1.3
diff -u -p -r1.3 math_grid.h
--- mathed/math_grid.h  2001/06/28 10:25:20     1.3
+++ mathed/math_grid.h  2001/07/05 07:51:51
@@ -110,11 +110,10 @@ public: 
        void delCol(int);
        ///
        virtual void appendRow();
-
-protected:
        ///
        int index(int row, int col) const;
 
+protected:
        /// row info
        std::vector<RowInfo> rowinfo_;
        /// column info
Index: mathed/math_inset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_inset.C,v
retrieving revision 1.29
diff -u -p -r1.29 math_inset.C
--- mathed/math_inset.C 2001/06/28 10:25:20     1.29
+++ mathed/math_inset.C 2001/07/05 07:51:51
@@ -202,7 +202,7 @@ void MathInset::draw(Painter & pain, int
 }
 
 
-bool MathInset::idxRight(int & idx, int & pos) const
+bool MathInset::idxNext(int & idx, int & pos) const
 {
        if (idx + 1 >= nargs())
                return false;
@@ -212,8 +212,14 @@ bool MathInset::idxRight(int & idx, int 
 }
 
 
-bool MathInset::idxLeft(int & idx, int & pos) const
+bool MathInset::idxRight(int & idx, int & pos) const
 {
+       return idxNext(idx, pos);
+}
+
+
+bool MathInset::idxPrev(int & idx, int & pos) const
+{
        if (idx == 0)
                return false;
        --idx;
@@ -221,6 +227,11 @@ bool MathInset::idxLeft(int & idx, int &
        return true;
 }
 
+
+bool MathInset::idxLeft(int & idx, int & pos) const
+{
+       return idxPrev(idx, pos);
+}
 
 bool MathInset::idxUp(int &, int &) const
 {
Index: mathed/math_inset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_inset.h,v
retrieving revision 1.31
diff -u -p -r1.31 math_inset.h
--- mathed/math_inset.h 2001/06/28 10:25:20     1.31
+++ mathed/math_inset.h 2001/07/05 07:51:51
@@ -95,6 +95,11 @@ public: 
        /// The right key
        virtual bool idxRight(int & idx, int & pos) const;
 
+       /// Move one physical cell up
+       virtual bool idxNext(int & idx, int & pos) const;
+       /// Move one physical cell down
+       virtual bool idxPrev(int & idx, int & pos) const;
+
        /// Target pos when we enter the inset from the left by pressing "Right"
        virtual bool idxFirst(int & idx, int & pos) const;
        /// Target pos when we enter the inset from the left by pressing "Up"
Index: mathed/math_matrixinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_matrixinset.C,v
retrieving revision 1.21
diff -u -p -r1.21 math_matrixinset.C
--- mathed/math_matrixinset.C   2001/06/28 10:25:20     1.21
+++ mathed/math_matrixinset.C   2001/07/05 07:51:51
@@ -379,25 +379,7 @@ void MathMatrixInset::delCol(int col)
        }
 }
 
-void MathMatrixInset::breakLine() 
-{
-       if (GetType() == LM_OT_SIMPLE || GetType() == LM_OT_EQUATION) 
-               mutate(LM_OT_EQNARRAY);
-       addRow(nrows() - 1);
-}
-
 
-void MathMatrixInset::splitCell(int idx)
-{
-       if (idx == nargs() - 1) {
-               lyxerr << "can't split last cell\n";
-               return;
-       }
-
-       lyxerr << "unimplemented\n";
-}
-
-
 string MathMatrixInset::nicelabel(int row) const
 {
        if (nonum_[row])
@@ -521,7 +503,7 @@ void MathMatrixInset::mutate(short newty
                                case LM_OT_EQNARRAY:
                                        MathGridInset::addCol(1);
                                        SetType(LM_OT_EQNARRAY);
-                                       halign("lrl");
+                                       halign("rcl");
                                        mutate(newtype);
                                        break;
                                
Index: mathed/math_matrixinset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_matrixinset.h,v
retrieving revision 1.13
diff -u -p -r1.13 math_matrixinset.h
--- mathed/math_matrixinset.h   2001/06/28 10:25:20     1.13
+++ mathed/math_matrixinset.h   2001/07/05 07:51:51
@@ -31,8 +31,6 @@ public: 
        ///
        void Metrics(MathStyles st);
        ///
-       void breakLine();
-       ///
        void draw(Painter &, int, int);
        ///
        string label(int row) const;
@@ -69,9 +67,6 @@ public: 
        ///
        void mutate(short);
 
-       /// Splits cells and shifts right part to the next cell
-       void splitCell(int idx);
-       
 private:
        ///
        void Validate1(LaTeXFeatures & features);
Index: mathed/math_parser.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_parser.C,v
retrieving revision 1.57
diff -u -p -r1.57 math_parser.C
--- mathed/math_parser.C        2001/07/04 17:15:08     1.57
+++ mathed/math_parser.C        2001/07/05 07:51:51
@@ -733,7 +733,7 @@ void mathed_parse(MathArray & array, uns
 
                case LM_TK_SQRT:
                {           
-                       unsigned char c;
+                       unsigned char c = '\0'; // shut up gcc 3.0
                        yyis->get(c);
                        if (c == '[') {
                                MathRootInset * rt = new MathRootInset;

Reply via email to