The attached patch [do not apply, it does not work] demostrates what I'd
like to do to all insets (not just FormulaBase)

It basically replaces public methods

  insetButtonRelease(BufferView * bv, int x, int y, mouse_button::state button)

by private methods
 
  lfunMouseRelease(FuncRequest const & cmd)

which are called from the inset's localDispatch() on LFUN_MOUSE_RELEASE.
The plan is to drop the insetButton*() fucntions altogehter and use
the inset's localDispatch(LFUN_MOUSE,...) instead.

The lfun* functions could later get promoted to "lfun handlers" which could
be auto-registrated etc...

Is that direction ok?

Andre'

-- 
Those who desire to give up Freedom in order to gain Security,
will not have, nor do they deserve, either one. (T. Jefferson)
Index: mathed/formulabase.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/formulabase.C,v
retrieving revision 1.202
diff -u -p -r1.202 formulabase.C
--- mathed/formulabase.C        15 Aug 2002 14:33:14 -0000      1.202
+++ mathed/formulabase.C        16 Aug 2002 09:37:01 -0000
@@ -286,114 +286,105 @@ void InsetFormulaBase::updateLocal(Buffe
 }
 
 
-bool InsetFormulaBase::insetButtonRelease(BufferView * bv,
-       int x, int y, mouse_button::state button)
+UpdatableInset::RESULT
+InsetFormulaBase::lfunMouseRelease(FuncRequest const & cmd)
 {
        if (!mathcursor)
-               return false;
+               return UNDISPATCHED;
 
        //lyxerr << "insetButtonRelease: " << x << " " << y << "\n";
+       BufferView * bv = cmd.view();
        hideInsetCursor(bv);
        showInsetCursor(bv);
        bv->updateInset(this, false);
 
-       if (button == mouse_button::button3) {
+       if (cmd.extra == mouse_button::button3) {
                // try to dispatch to enclosed insets first
-               if (mathcursor->dispatch(FuncRequest(bv, LFUN_MOUSE_RELEASE, x, y, 3)))
-                       return true;
-
-               // launch math panel for right mouse button
-               bv->owner()->getDialogs().showMathPanel();
-               return true;
+               if (mathcursor->dispatch(cmd) == MathInset::UNDISPATCHED) {     
+                       // launch math panel for right mouse button
+                       bv->owner()->getDialogs().showMathPanel();
+               }
+               return DISPATCHED;
        }
 
-       if (button == mouse_button::button1) {
+       if (cmd.extra == mouse_button::button1) {
                // try to dispatch to enclosed insets first
-               if (mathcursor->dispatch(FuncRequest(bv, LFUN_MOUSE_RELEASE, x, y, 1)))
-                       return true;
-
+               mathcursor->dispatch(cmd);
                // try to set the cursor
                //delete mathcursor;
                //mathcursor = new MathCursor(this, x == 0);
                //metrics(bv);
                //mathcursor->setPos(x + xo_, y + yo_);
-               return true;
+               return DISPATCHED;
        }
-       return false;
+       return UNDISPATCHED;
 }
 
 
-void InsetFormulaBase::insetButtonPress(BufferView * bv,
-                                       int x, int y, mouse_button::state button)
+UpdatableInset::RESULT
+InsetFormulaBase::lfunMousePress(FuncRequest const & cmd)
 {
        //lyxerr << "insetButtonPress: "
        //      << x << " " << y << " but: " << button << "\n";
        //lyxerr << "formula: ";
        //par()->dump();
 
+       BufferView * bv = cmd.view();
        releaseMathCursor(bv);
-       mathcursor = new MathCursor(this, x == 0);
+       mathcursor = new MathCursor(this, cmd.x == 0);
 
-       if (button == mouse_button::button1) {
+       if (cmd.button() == 1) {
                // just set the cursor here
                //lyxerr << "setting cursor\n";
                metrics(bv);
-               first_x = x;
-               first_y = y;
+               first_x = cmd.x;
+               first_y = cmd.y;
                mathcursor->selClear();
-               mathcursor->setPos(x + xo_, y + yo_);
-
-               if (mathcursor->dispatch(FuncRequest(bv, LFUN_MOUSE_PRESS, x, y, 1))) {
-                       //delete mathcursor;
-                       return;
-               }
-
+               mathcursor->setPos(cmd.x + xo_, cmd.y + yo_);
+               mathcursor->dispatch(cmd);
+               return DISPATCHED;
        }
-       if (button == mouse_button::button3) {
-               if (mathcursor->dispatch(FuncRequest(bv, LFUN_MOUSE_PRESS, x, y, 3))) {
-                       //delete mathcursor;
-                       return;
-               }
+       if (cmd.button() == 3) {
+               mathcursor->dispatch(cmd);
+               //delete mathcursor;
+               return DISPATCHED;
        }
        bv->updateInset(this, false);
+       return DISPATCHED;
 }
 
 
-void InsetFormulaBase::insetMotionNotify(BufferView * bv,
-       int x, int y, mouse_button::state button)
+UpdatableInset::RESULT
+InsetFormulaBase::lfunMouseMotion(FuncRequest const & cmd)
 {
        if (!mathcursor)
-               return;
-
-       if (button == mouse_button::button1)
-               if (mathcursor->dispatch(FuncRequest(bv, LFUN_MOUSE_MOTION, x, y, 1)))
-                       return;
+               return DISPATCHED;
 
-       if (button == mouse_button::button3)
-               if (mathcursor->dispatch(FuncRequest(bv, LFUN_MOUSE_MOTION, x, y, 3)))
-                       return;
+       if (mathcursor->dispatch(FuncRequest(cmd)) != MathInset::UNDISPATCHED)
+               return DISPATCHED;
 
-       if (abs(x - first_x) < 2 && abs(y - first_y) < 2) {
+       if (abs(cmd.x - first_x) < 2 && abs(cmd.y - first_y) < 2) {
                //lyxerr << "insetMotionNotify: ignored\n";
-               return;
+               return DISPATCHED;
        }
-       first_x = x;
-       first_y = y;
+       first_x = cmd.x;
+       first_y = cmd.y;
 
        if (!mathcursor->selection())
                mathcursor->selStart();
 
        //lyxerr << "insetMotionNotify: " << x + xo_ << ' ' << y + yo_
        //      << ' ' << button << "\n";
+       BufferView * bv = cmd.view();
        hideInsetCursor(bv);
-       mathcursor->setPos(x + xo_, y + yo_);
+       mathcursor->setPos(cmd.x + xo_, cmd.y + yo_);
        showInsetCursor(bv);
        bv->updateInset(this, false);
+       return DISPATCHED;
 }
 
 
-UpdatableInset::RESULT
-InsetFormulaBase::localDispatch(FuncRequest const & ev)
+UpdatableInset::RESULT InsetFormulaBase::localDispatch(FuncRequest const & ev)
 {
        //lyxerr << "InsetFormulaBase::localDispatch: act: " << action
        //      << " arg: '" << arg
Index: mathed/formulabase.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/formulabase.h,v
retrieving revision 1.50
diff -u -p -r1.50 formulabase.h
--- mathed/formulabase.h        15 Aug 2002 14:33:14 -0000      1.50
+++ mathed/formulabase.h        16 Aug 2002 09:37:01 -0000
@@ -78,12 +78,6 @@ public:
        ///
        virtual void toggleInsetSelection(BufferView * bv);
        ///
-       virtual void insetButtonPress(BufferView *, int x, int y, mouse_button::state 
button);
-       ///
-       virtual bool insetButtonRelease(BufferView *, int x, int y, 
mouse_button::state button);
-       ///
-       virtual void insetMotionNotify(BufferView *, int x, int y, mouse_button::state 
state);
-       ///
        virtual void insetUnlock(BufferView *);
 
        /// To allow transparent use of math editing functions
@@ -124,6 +118,12 @@ private:
        void operator=(const InsetFormulaBase &);
        /// common base for handling accents
        void handleAccent(BufferView * bv, string const & arg, string const & name);
+       /// lfun handler 
+       virtual RESULT lfunMousePress(FuncRequest const &);
+       ///
+       virtual RESULT lfunMouseRelease(FuncRequest const &);
+       ///
+       virtual RESULT lfunMouseMotion(FuncRequest const &);
 
 protected:
        ///

Reply via email to