]> git.lyx.org Git - features.git/commitdiff
streamlining interaction mathed <-> rest of the world
authorAndré Pönitz <poenitz@gmx.net>
Thu, 15 Aug 2002 14:33:14 +0000 (14:33 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Thu, 15 Aug 2002 14:33:14 +0000 (14:33 +0000)
remove unneeded lfun
general cleanup

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

src/BufferView_pimpl.C
src/ChangeLog
src/LyXAction.C
src/commandtags.h
src/lyx_cb.C
src/lyxfunc.C
src/mathed/formula.C
src/mathed/formula.h
src/mathed/formulabase.C
src/mathed/formulabase.h
src/mathed/math_hullinset.C

index 301285fe51114c1affb77122185e36d991164a1b..0ccdb69ecb1a163691a7a29f0fa2e5f6676fd549 100644 (file)
@@ -2915,40 +2915,15 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
                }
                break;
 
-       case LFUN_MATH:
-               mathDispatch(bv_, ev.argument);
-               break;
-
        case LFUN_MATH_MACRO:
-               mathDispatchMathMacro(bv_, ev.argument);
-               break;
-
        case LFUN_MATH_DELIM:
-               mathDispatchMathDelim(bv_, ev.argument);
-               break;
-
        case LFUN_INSERT_MATRIX:
-               mathDispatchInsertMatrix(bv_, ev.argument);
-               break;
-
        case LFUN_INSERT_MATH:
-               mathDispatchInsertMath(bv_, ev.argument);
-               break;
-
        case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
-               mathDispatchMathImportSelection(bv_, ev.argument);
-               break;
-
        case LFUN_MATH_DISPLAY:          // Open or create a displayed math inset
-               mathDispatchMathDisplay(bv_, ev.argument);
-               break;
-
        case LFUN_MATH_MODE:             // Open or create an inlined math inset
-               mathDispatchMathMode(bv_, ev.argument);
-               break;
-
        case LFUN_GREEK:                 // Insert a single greek letter
-               mathDispatchGreek(bv_, ev.argument);
+               mathDispatch(FuncRequest(bv_, ev.action, ev.argument));
                break;
 
        case LFUN_CITATION_INSERT:
index 3803a3d198dea1ca64ec86e4f14856d29de8a6c9..c81b1372e7c89c1a20f848bd28c708f8f9f6ce7f 100644 (file)
@@ -1,3 +1,11 @@
+       
+       *       lyxfunc.C:
+         BufferView_pimpl.C: streamlining mathed <-> outer world interaction
+
+       * commandtags.h:
+         LyXAction.C: remove unused LFUN_MATH
+
+
 2002-08-15  Lars Gullik Bjønnes  <larsbj@gullik.net>
 
        * paragraph.[Ch]: add some NO_NEXT ifdefs.
index ba7b6aeae07913bd51fe12e7b61e569c7e261649..348f935d1cf3fd2c0d09279a58b91e0b8063c5d7 100644 (file)
@@ -278,7 +278,6 @@ void LyXAction::init()
                { LFUN_MARK_OFF, "mark-off", "", ReadOnly },
                { LFUN_MARK_ON, "mark-on", "", ReadOnly },
                { LFUN_SETMARK, "mark-toggle", "", ReadOnly },
-               { LFUN_MATH, "math", "", Noop },
                { LFUN_MATH_DELIM, "math-delim", "", Noop },
                { LFUN_MATH_DISPLAY, "math-display", "", Noop },
                { LFUN_GREEK, "math-greek", N_("Math Greek"), Noop },
index 8eb6c6c830e500fdf2832fa36e84819887e2265c..5f69248f9814c9c728e22551b3688e086e32ebba 100644 (file)
@@ -131,7 +131,6 @@ enum kb_action {
        LFUN_INSERT_MATH,
        LFUN_INSERT_MATRIX,
        LFUN_GREEK,  // 110
-       LFUN_MATH,                      // Andre' 2002-06-14
        LFUN_MATH_LIMITS,
        LFUN_GREEK_TOGGLE,
        LFUN_MATH_DELIM,                // Alejandro 180696
index 44e2093f1f9e295187d69cd2051cbb80a2ebd64b..30f2d89da14f0d98808660482f405574260099a5 100644 (file)
@@ -428,7 +428,7 @@ string getContentsOfAsciiFile(BufferView * bv, string const & f, bool asParagrap
 
 void MenuInsertLabel(BufferView * bv, string const & arg)
 {
-       string label(arg);
+       string label = arg;
        bv->owner()->prohibitInput();
        if (label.empty()) {
                Paragraph * par = bv->getLyXText()->cursor.par();
index 9e10195da245307695af908d3f3f23d418447307..0b05ccc93fc2ae8c9db2d60786609d66d240e5e0 100644 (file)
@@ -417,7 +417,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                disable = !IsFileReadable(buf->getLogName().second);
                break;
        case LFUN_MATH_VALIGN:
-               if (mathcursor && mathcursor->formula()->hullType() != "simple") {
+               if (mathcursor) {
                        char align = mathcursor->valign();
                        if (align == '\0') {
                                disable = true;
@@ -437,7 +437,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                break;
 
        case LFUN_MATH_HALIGN:
-               if (mathcursor && mathcursor->formula()->hullType() != "simple") {
+               if (mathcursor) {
                        char align = mathcursor->halign();
                        if (align == '\0') {
                                disable = true;
@@ -457,8 +457,9 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                break;
 
        case LFUN_MATH_MUTATE:
-               if (tli && (tli->lyxCode() == Inset::MATH_CODE))
-                       flag.setOnOff(mathcursor->formula()->hullType() == ev.argument);
+               if (mathcursor)
+                       //flag.setOnOff(mathcursor->formula()->hullType() == ev.argument);
+                       flag.setOnOff(false);
                else
                        disable = true;
                break;
@@ -479,8 +480,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
        case LFUN_MATH_ROW_DELETE:
        case LFUN_MATH_COLUMN_INSERT:
        case LFUN_MATH_COLUMN_DELETE:
-               disable = !mathcursor || !mathcursor->halign() ||
-                       mathcursor->formula()->hullType() == "simple";
+               disable = !mathcursor || !mathcursor->halign();
                break;
 
        default:
index dc1d45e8e08f1f45bc71e94623ac1ddae72ff187..5bbd64be6cd9516c21d2add8f9ec5ad0307d20c2 100644 (file)
@@ -216,7 +216,6 @@ void InsetFormula::draw(BufferView * bv, LyXFont const & font,
                pi.pain.image(x, y - a, w, h,
                              *(preview_->pimage()->image(*this, *bv)));
        } else {
-               //pi.base.style = display() ? LM_ST_DISPLAY : LM_ST_TEXT;
                pi.base.style = LM_ST_TEXT;
                pi.base.font  = font;
                pi.base.font.setColor(LColor::math);
@@ -250,65 +249,6 @@ vector<string> const InsetFormula::getLabelList() const
 }
 
 
-UpdatableInset::RESULT
-InsetFormula::localDispatch(FuncRequest const & ev)
-{
-       RESULT result = DISPATCHED;
-       BufferView * bv = ev.view();
-
-       switch (ev.action) {
-
-               case LFUN_MATH_MUTATE:
-               {
-                       bv->lockedInsetStoreUndo(Undo::EDIT);
-                       int x;
-                       int y;
-                       mathcursor->getPos(x, y);
-                       mutate(ev.argument);
-                       mathcursor->setPos(x, y);
-                       mathcursor->normalize();
-                       updateLocal(bv, true);
-                       break;
-               }
-
-
-               case LFUN_MATH_DISPLAY:
-               {
-                       int x = 0;
-                       int y = 0;
-                       mathcursor->getPos(x, y);
-                       if (hullType() == "simple")
-                               mutate("equation");
-                       else
-                               mutate("simple");
-                       mathcursor->setPos(x, y);
-                       mathcursor->normalize();
-                       updateLocal(bv, true);
-                       break;
-               }
-
-               case LFUN_PASTESELECTION:
-               {
-                       string const clip = bv->getClipboard();
-                       if (!clip.empty())
-                               mathed_parse_normal(par_, clip);
-                       break;
-               }
-
-               default:
-                       result = InsetFormulaBase::localDispatch(ev);
-       }
-
-       return result;
-}
-
-
-bool InsetFormula::display() const
-{
-       return hullType() != "simple" && hullType() != "none";
-}
-
-
 Inset::Code InsetFormula::lyxCode() const
 {
        return Inset::MATH_CODE;
@@ -324,7 +264,7 @@ void InsetFormula::validate(LaTeXFeatures & features) const
 bool InsetFormula::insetAllowed(Inset::Code code) const
 {
        return
-               (code == Inset::LABEL_CODE && display())
+               (code == Inset::LABEL_CODE)
                || code == Inset::REF_CODE
                || code == Inset::ERT_CODE;
 }
@@ -355,16 +295,12 @@ int InsetFormula::width(BufferView * bv, LyXFont const & font) const
 }
 
 
-string InsetFormula::hullType() const
-{
-       return par()->getType();
-}
-
-
+/*
 void InsetFormula::mutate(string const & type)
 {
        par_.nucleus()->mutate(type);
 }
+*/
 
 
 //
index 846ade741b392c9fc12c116302520246104780b7..f52a6c2e9ca801e90f615d74f2b355dc6a115555 100644 (file)
@@ -26,8 +26,6 @@
 
 #include <boost/scoped_ptr.hpp>
 
-class MathHullInset;
-
 ///
 class InsetFormula : public InsetFormulaBase {
 public:
@@ -72,12 +70,8 @@ public:
        ///
        bool insetAllowed(Inset::Code code) const;
        ///
-       virtual RESULT localDispatch(FuncRequest const &);
-       ///
        std::vector<string> const getLabelList() const;
        ///
-       string hullType() const;
-       ///
        MathAtom const & par() const { return par_; }
        ///
        MathAtom & par() { return par_; }
@@ -86,11 +80,9 @@ public:
        ///
        void addPreview(grfx::PreviewLoader &) const;
        ///
-       void mutate(string const & type);
+       //void mutate(string const & type);
 
 private:
-       /// Is this a displayed environment?
-       bool display() const;
        /// available in AMS only?
        bool ams() const;
 
index 63c46f9de51d1a5c759064f6b15ae7c7379f22d2..e7777dd7c34f859b9c4626a8f72c94acb015582d 100644 (file)
@@ -416,6 +416,8 @@ InsetFormulaBase::localDispatch(FuncRequest const & ev)
 
        switch (ev.action) {
 
+       case LFUN_MATH_MUTATE:
+       case LFUN_MATH_DISPLAY:
        case LFUN_MATH_HALIGN:
        case LFUN_MATH_VALIGN:
        case LFUN_MATH_ROW_INSERT:
@@ -533,6 +535,15 @@ InsetFormulaBase::localDispatch(FuncRequest const & ev)
                break;
        }
 
+/*
+       case LFUN_PASTESELECTION: {
+               string const clip = bv->getClipboard();
+               if (!clip.empty())
+                       mathed_parse_normal(par_, clip);
+               break;
+       }
+*/
+
        case LFUN_PASTE:
                if (was_macro)
                        mathcursor->macroModeClose();
@@ -892,14 +903,18 @@ bool InsetFormulaBase::searchBackward(BufferView * bv, string const & what,
 }
 
 
+bool InsetFormulaBase::display() const
+{
+       return par()->asHullInset() && par()->asHullInset()->display();
+}
+
+
 /////////////////////////////////////////////////////////////////////
 
 
-void mathDispatchCreation(BufferView * bv, string const & arg, bool display)
+void mathDispatchCreation(FuncRequest const & cmd, bool display)
 {
-       if (!bv->available())
-               return;
-
+       BufferView * bv = cmd.view();
        // use selection if available..
        //string sel;
        //if (action == LFUN_MATH_IMPORT_SELECTION)
@@ -911,13 +926,14 @@ void mathDispatchCreation(BufferView * bv, string const & arg, bool display)
        if (sel.empty()) {
                InsetFormula * f = new InsetFormula(bv);
                if (openNewInset(bv, f)) {
-                       f->mutate("simple");
+                       bv->theLockingInset()->
+                               localDispatch(FuncRequest(bv, 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->localDispatch(FuncRequest(bv, LFUN_MATH_DISPLAY));
-                       f->localDispatch(FuncRequest(bv, LFUN_INSERT_MATH, arg));
+                       f->localDispatch(FuncRequest(bv, LFUN_INSERT_MATH, cmd.argument));
                }
        } else {
                // create a macro if we see "\\newcommand" somewhere, and an ordinary
@@ -935,91 +951,50 @@ void mathDispatchCreation(BufferView * bv, string const & arg, bool display)
 }
 
 
-void mathDispatchMathDisplay(BufferView * bv, string const & arg)
-{
-       mathDispatchCreation(bv, arg, true);
-}
-
-
-void mathDispatchMathMode(BufferView * bv, string const & arg)
-{
-       mathDispatchCreation(bv, arg, false);
-}
-
-
-void mathDispatchMathImportSelection(BufferView * bv, string const & arg)
-{
-       mathDispatchCreation(bv, arg, true);
-}
-
-
-void mathDispatchMathMacro(BufferView * bv, string const & arg)
-{
-       if (!bv->available())
-               return;
-       if (arg.empty())
-               bv->owner()->getLyXFunc().setErrorMessage(N_("Missing argument"));
-       else {
-               string s = arg;
-               string const s1 = token(s, ' ', 1);
-               int const na = s1.empty() ? 0 : lyx::atoi(s1);
-               openNewInset(bv, new InsetFormulaMacro(token(s, ' ', 0), na));
-       }
-}
-
-
-void mathDispatchMathDelim(BufferView * bv, string const & arg)
+void mathDispatch(FuncRequest const & cmd)
 {
+       BufferView * bv = cmd.view();
        if (!bv->available())
                return;
-       InsetFormula * f = new InsetFormula(bv);
-       if (openNewInset(bv, f)) {
-               f->mutate("simple");
-               bv->theLockingInset()->localDispatch(FuncRequest(bv, LFUN_MATH_DELIM, arg));
-       }
-}
-
 
-void mathDispatchInsertMatrix(BufferView * bv, string const & arg)
-{
-       if (!bv->available())
-               return;
-       InsetFormula * f = new InsetFormula(bv);
-       if (openNewInset(bv, f)) {
-               f->mutate("simple");
-               bv->theLockingInset()->localDispatch(FuncRequest(bv, LFUN_INSERT_MATRIX, arg));
-       }
-}
+       switch (cmd.action) {
 
+               case LFUN_MATH_DISPLAY:
+                       mathDispatchCreation(cmd, true);
+                       break;
 
-void mathDispatchInsertMath(BufferView * bv, string const & arg)
-{
-       if (!bv->available())
-               return;
-       InsetFormula * f = new InsetFormula(bv);
-       if (openNewInset(bv, f)) {
-               f->mutate("simple");
-    bv->theLockingInset()->localDispatch(FuncRequest(bv, LFUN_INSERT_MATH, arg));
-       }
-}
+               case LFUN_MATH_MODE:
+                       mathDispatchCreation(cmd, false);
+                       break;
 
+               case LFUN_MATH_IMPORT_SELECTION:
+                       mathDispatchCreation(cmd, false);
+                       break;
 
-void mathDispatchGreek(BufferView * bv, string const & arg)
-{
-       if (!bv->available())
-               return;
-       InsetFormula * f = new InsetFormula(bv);
-       if (openNewInset(bv, f)) {
-               f->mutate("simple");
-               bv->theLockingInset()->localDispatch(FuncRequest(bv, LFUN_GREEK, arg));
-               bv->unlockInset(f);
+               case LFUN_MATH_MACRO:
+                       if (cmd.argument.empty())
+                               bv->owner()->getLyXFunc().setErrorMessage(N_("Missing argument"));
+                       else {
+                               string s = cmd.argument;
+                               string const s1 = token(s, ' ', 1);
+                               int const na = s1.empty() ? 0 : lyx::atoi(s1);
+                               openNewInset(bv, new InsetFormulaMacro(token(s, ' ', 0), na));
+                       }
+                       break;
+
+               case LFUN_GREEK: 
+               case LFUN_INSERT_MATH: 
+               case LFUN_INSERT_MATRIX: 
+               case LFUN_MATH_DELIM: {
+                       InsetFormula * f = new InsetFormula(bv);
+                       if (openNewInset(bv, f)) {
+                               bv->theLockingInset()-> 
+                                       localDispatch(FuncRequest(bv, LFUN_MATH_MUTATE, "simple"));
+                               bv->theLockingInset()->localDispatch(cmd);
+                       }
+                       break;
+               }
+               default:
+                       break;
        }
 }
-
-
-void mathDispatch(BufferView *, kb_action, string const &)
-{}
-
-
-void mathDispatch(BufferView *, string const &)
-{}
index 2cfb57aea45c30441a6a5b56095e87e6dad7a95e..b7ab439939600ad95217fd4c7176a76037986e9b 100644 (file)
@@ -43,8 +43,6 @@ public:
        virtual int width(BufferView *, LyXFont const &) const = 0;
        ///
        virtual void draw(BufferView *,LyXFont const &, int, float &, bool) const = 0;
-       ///
-       virtual string hullType() const { return "none"; }
        /// lowest x coordinate
        virtual int xlow() const;
        /// highest x coordinate
@@ -90,6 +88,8 @@ public:
 
        /// To allow transparent use of math editing functions
        virtual RESULT localDispatch(FuncRequest const &);
+       /// To allow transparent use of math editing functions
+       //virtual void status(FuncRequest const &);
 
        ///
        virtual std::vector<string> const getLabelList() const;
@@ -116,6 +116,8 @@ public:
        virtual void revealCodes(BufferView *) const;
        ///
        virtual Inset::EDITABLE editable() const { return HIGHLY_EDITABLE; }
+       ///
+       bool display() const;
 
 private:
        /// unimplemented
@@ -145,27 +147,6 @@ protected:
 
 // We don't really mess want around with mathed stuff outside mathed.
 // So do it here.
-//
-void mathDispatchCreation(BufferView *, string const &, bool);
-//
-void mathDispatchMathDisplay(BufferView *, string const &);
-//
-void mathDispatchMathMode(BufferView *, string const &);
-//
-void mathDispatchMathMacro(BufferView *, string const &);
-//
-void mathDispatchMathDelim(BufferView *, string const &);
-//
-void mathDispatchInsertMath(BufferView *, string const &);
-//
-void mathDispatchInsertMatrix(BufferView *, string const &);
-//
-void mathDispatchGreek(BufferView *, string const &);
-//
-void mathDispatchMathImportSelection(BufferView *, string const &);
-//
-void mathDispatch(BufferView *, FuncRequest const &);
-//
-void mathDispatch(BufferView *, string const &);
+void mathDispatch(FuncRequest const &);
 
 #endif
index 4488dd9cc0830d4c2c52576d532a1112a53dddcd..8b1c556c5cadec47afe3418261e16fc5f3e71062 100644 (file)
@@ -809,6 +809,25 @@ MathInset::result_type MathHullInset::dispatch
                        doExtern(cmd, idx, pos);
                        return DISPATCHED_POP;
 
+               case LFUN_MATH_MUTATE: {
+                       row_type r = row(idx);
+                       col_type c = col(idx);
+                       mutate(cmd.argument);
+                       idx = r * ncols() + c;
+                       if (idx >= nargs())
+                               idx = nargs() - 1;
+                       if (pos > cell(idx).size()) 
+                               pos = cell(idx).size();
+                       return DISPATCHED_POP;
+               }
+
+               case LFUN_MATH_DISPLAY: {
+                       mutate(type_ == "simple" ? "equation" : "simple");
+                       idx = 0;
+                       pos = cell(idx).size();
+                       return DISPATCHED_POP;
+               }
+
                default:
                        return MathGridInset::dispatch(cmd, idx, pos);