]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/formulabase.C
Jean-Marc's fix for wrong descent
[lyx.git] / src / mathed / formulabase.C
index be8ee3c160fb0af4e107ff408edb34f15fe99faa..cca0e6f1c4fb964387eae4e1a02adccf851d64f3 100644 (file)
@@ -18,9 +18,6 @@
 #include "Lsstream.h"
 #include "support/LAssert.h"
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
 
 #include "formula.h"
 #include "formulamacro.h"
@@ -54,7 +51,6 @@
 #include "textpainter.h"
 #include "frontends/Dialogs.h"
 #include "intl.h"
-#include "insets/insetcommandparams.h"
 #include "ref_inset.h"
 
 using std::endl;
@@ -306,7 +302,7 @@ void InsetFormulaBase::updateLocal(BufferView * bv, bool dirty)
 }
 
 
-Inset::RESULT InsetFormulaBase::lfunMouseRelease(FuncRequest const & cmd)
+dispatch_result InsetFormulaBase::lfunMouseRelease(FuncRequest const & cmd)
 {
        if (!mathcursor)
                return UNDISPATCHED;
@@ -319,8 +315,9 @@ Inset::RESULT InsetFormulaBase::lfunMouseRelease(FuncRequest const & cmd)
 
        if (cmd.button() == mouse_button::button3) {
                // try to dispatch to enclosed insets first
-               if (mathcursor->dispatch(cmd) == MathInset::UNDISPATCHED) {
+               if (mathcursor->dispatch(cmd) == UNDISPATCHED) {
                        // launch math panel for right mouse button
+                       lyxerr << "lfunMouseRelease: undispatched: " << cmd.button() << endl;
                        bv->owner()->getDialogs().showMathPanel();
                }
                return DISPATCHED;
@@ -350,7 +347,7 @@ Inset::RESULT InsetFormulaBase::lfunMouseRelease(FuncRequest const & cmd)
 }
 
 
-Inset::RESULT InsetFormulaBase::lfunMousePress(FuncRequest const & cmd)
+dispatch_result InsetFormulaBase::lfunMousePress(FuncRequest const & cmd)
 {
        BufferView * bv = cmd.view();
        //lyxerr << "lfunMousePress: buttons: " << cmd.button() << endl;
@@ -382,12 +379,12 @@ Inset::RESULT InsetFormulaBase::lfunMousePress(FuncRequest const & cmd)
 }
 
 
-Inset::RESULT InsetFormulaBase::lfunMouseMotion(FuncRequest const & cmd)
+dispatch_result InsetFormulaBase::lfunMouseMotion(FuncRequest const & cmd)
 {
        if (!mathcursor)
                return DISPATCHED;
 
-       if (mathcursor->dispatch(FuncRequest(cmd)) != MathInset::UNDISPATCHED)
+       if (mathcursor->dispatch(FuncRequest(cmd)) != UNDISPATCHED)
                return DISPATCHED;
 
        // only select with button 1
@@ -412,7 +409,7 @@ Inset::RESULT InsetFormulaBase::lfunMouseMotion(FuncRequest const & cmd)
 }
 
 
-Inset::RESULT InsetFormulaBase::localDispatch(FuncRequest const & cmd)
+dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd)
 {
        //lyxerr << "InsetFormulaBase::localDispatch: act: " << cmd.action
        //      << " arg: '" << cmd.argument
@@ -420,12 +417,17 @@ Inset::RESULT InsetFormulaBase::localDispatch(FuncRequest const & cmd)
        //      << " y: '" << cmd.y
        //      << "' button: " << cmd.button() << endl;
 
+       // delete empty mathbox (LFUN_BACKSPACE and LFUN_DELETE)
+       bool remove_inset = false;
+
        switch (cmd.action) {
                case LFUN_MOUSE_PRESS:
+                       //lyxerr << "Mouse single press\n";
                        return lfunMousePress(cmd);
                case LFUN_MOUSE_MOTION:
-                       return lfunMouseMotion(cmd);
+                       //return lfunMouseMotion(cmd);
                case LFUN_MOUSE_RELEASE:
+                       //lyxerr << "Mouse single release\n";
                        return lfunMouseRelease(cmd);
                case LFUN_MOUSE_DOUBLE:
                        //lyxerr << "Mouse double\n";
@@ -536,7 +538,7 @@ Inset::RESULT InsetFormulaBase::localDispatch(FuncRequest const & cmd)
        case LFUN_PRIOR:
        case LFUN_BEGINNINGBUFSEL:
        case LFUN_BEGINNINGBUF:
-               result = FINISHED_UP;
+               result = FINISHED;
                updateLocal(bv, false);
                break;
 
@@ -544,7 +546,7 @@ Inset::RESULT InsetFormulaBase::localDispatch(FuncRequest const & cmd)
        case LFUN_NEXT:
        case LFUN_ENDBUFSEL:
        case LFUN_ENDBUF:
-               result = FINISHED_DOWN;
+               result = FINISHED_RIGHT;
                updateLocal(bv, false);
                break;
 
@@ -560,16 +562,26 @@ Inset::RESULT InsetFormulaBase::localDispatch(FuncRequest const & cmd)
 
        case LFUN_DELETE_WORD_BACKWARD:
        case LFUN_BACKSPACE:
-               bv->lockedInsetStoreUndo(Undo::DELETE);
-               mathcursor->backspace();
+               bv->lockedInsetStoreUndo(Undo::EDIT);
+               if (mathcursor->backspace()) {
+                       result = DISPATCHED;
+               } else {
+                       result = FINISHED;
+                       remove_inset = true;
+               }
                updateLocal(bv, true);
                break;
 
        case LFUN_DELETE_WORD_FORWARD:
        case LFUN_DELETE:
-               bv->lockedInsetStoreUndo(Undo::DELETE);
-               mathcursor->erase();
-               bv->updateInset(this, true);
+               bv->lockedInsetStoreUndo(Undo::EDIT);
+               if (mathcursor->erase()) {
+                       result = DISPATCHED;
+               } else {
+                       result = FINISHED;
+                       remove_inset = true;
+               }
+               updateLocal(bv, true);
                break;
 
        //    case LFUN_GETXY:
@@ -782,31 +794,37 @@ Inset::RESULT InsetFormulaBase::localDispatch(FuncRequest const & cmd)
                updateLocal(bv, true);
                break;
 
-       case LFUN_REF_INSERT:
-               //if (argument.empty()) {
-               //      InsetCommandParams p("ref");
-               //      owner_->getDialogs().createRef(p.getAsString());
-               //} else {
-               //      InsetCommandParams p;
-               //      p.setFromString(argument);
-
-               //      InsetRef * inset = new InsetRef(p, *buffer_);
-               //      if (!insertInset(inset))
-               //              delete inset;
-               //      else
-               //              updateInset(inset, true);
-               //}
-               //
-               if (cmd.argument.empty()) {
-                       InsetCommandParams p("ref");
-                       bv->owner()->getDialogs().createRef(p.getAsString());
+       case LFUN_DIALOG_SHOW_NEW_INSET: {
+               string const & name = argument;
+               if (name == "ref") {
+                       string data = "ref LatexCommand \\ref{}\n\\end_inset\n\n";
+                       bv->owner()->getDialogs().show(name, data, 0);
+               } else
+                       result = UNDISPATCHED;
+       }
+       break;
+
+       case LFUN_INSET_APPLY: {
+               string const name = cmd.getArg(0);
+               InsetBase * base =
+                       bv->owner()->getDialogs().getOpenInset(name);
+
+               if (base) {
+                       FuncRequest fr(bv, LFUN_INSET_MODIFY, cmd.argument);
+                       result = base->localDispatch(fr);
                } else {
-                       //mathcursor->handleNest(new InsetRef2);
-                       //mathcursor->insert(arg);
-                       mathcursor->insert(MathAtom(new RefInset(cmd.argument)));
+                       // Turn 'argument' into a temporary RefInset.
+                       MathArray ar;
+                       if (string2RefInset(cmd.argument, ar)) {
+                               mathcursor->insert(ar);
+                       } else {
+                               result = UNDISPATCHED;
+                       }
                }
-               updateLocal(bv, true);
-               break;
+               if (result == DISPATCHED)
+                       updateLocal(bv, true);
+       }
+       break;
 
        default:
                result = UNDISPATCHED;
@@ -829,6 +847,8 @@ Inset::RESULT InsetFormulaBase::localDispatch(FuncRequest const & cmd)
        } else {
                releaseMathCursor(bv);
                bv->unlockInset(this);
+               if (remove_inset)
+                       bv->owner()->dispatch(FuncRequest(LFUN_DELETE));
        }
 
        return result;  // original version