]> git.lyx.org Git - features.git/commitdiff
math internal re-organization to prepare de-centralized dispatch
authorAndré Pönitz <poenitz@gmx.net>
Mon, 8 Jul 2002 06:39:40 +0000 (06:39 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Mon, 8 Jul 2002 06:39:40 +0000 (06:39 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4542 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/formula.C
src/mathed/formulabase.C
src/mathed/math_cursor.C
src/mathed/math_cursor.h
src/mathed/math_factory.C
src/mathed/math_hullinset.C
src/mathed/math_hullinset.h
src/mathed/math_inset.C
src/mathed/math_inset.h
src/mathed/math_parser.C
src/mathed/ref_inset.C

index 638da3eac3f0d1f055e714934fb943f3e789459b..0de6a27e80f736a70350408f1cbd9bd9575efb88 100644 (file)
@@ -139,8 +139,8 @@ Inset * InsetFormula::clone(Buffer const &, bool) const
 
 void InsetFormula::write(Buffer const *, ostream & os) const
 {
-       os << "Formula ";
        WriteStream wi(os, false, false);
+       os << par_->fileInsetLabel() << " ";
        par_->write(wi);
 }
 
@@ -238,10 +238,10 @@ void InsetFormula::draw(BufferView * bv, LyXFont const & font,
                                const_cast<InsetFormulaBase const *>(mathcursor->formula()) == this)
                {
                        mathcursor->drawSelection(pi);
-                       pi.pain.rectangle(x, y - a, w, h, LColor::mathframe);
+                       //pi.pain.rectangle(x, y - a, w, h, LColor::mathframe);
                }
 
-               par_->draw(pi, x, y);
+               par_->draw(pi, x + 1, y);
        }
 
        xx += w;
@@ -254,7 +254,7 @@ void InsetFormula::draw(BufferView * bv, LyXFont const & font,
 
 vector<string> const InsetFormula::getLabelList() const
 {
-       return hull()->getLabelList();
+       return par()->getLabelList();
 }
 
 
@@ -278,7 +278,7 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
                        //lyxerr << "toggling all numbers\n";
                        if (display()) {
                                bv->lockedInsetStoreUndo(Undo::INSERT);
-                               bool old = hull()->numberedType();
+                               bool old = par()->numberedType();
                                for (MathInset::row_type row = 0; row < par_->nrows(); ++row)
                                        hull()->numbered(row, !old);
                                bv->owner()->message(old ? _("No number") : _("Number"));
@@ -461,14 +461,13 @@ int InsetFormula::width(BufferView * bv, LyXFont const & font) const
 
 string InsetFormula::hullType() const
 {
-       return hull() ? hull()->getType() : "none";
+       return par()->getType();
 }
 
 
-void InsetFormula::mutate(string const & type )
+void InsetFormula::mutate(string const & type)
 {
-       if (hull())
-               hull()->mutate(type);
+       par()->mutate(type);
 }
 
 
index d3b03a8a1d046eae2274167658459b3d3cfd06e0..746697dc5f2439cb30be79d8585afc1c8c78b3ae 100644 (file)
@@ -54,7 +54,6 @@
 #include "frontends/Dialogs.h"
 #include "intl.h"
 #include "insets/insetcommandparams.h"
-
 #include "ref_inset.h"
 
 using std::endl;
@@ -309,23 +308,36 @@ void InsetFormulaBase::updateLocal(BufferView * bv, bool dirty)
 bool InsetFormulaBase::insetButtonRelease(BufferView * bv,
        int /*x*/, int /*y*/, mouse_button::state button)
 {
-       //lyxerr << "insetButtonRelease: " << x << " " << y << "\n";
-
        if (!mathcursor)
                return false;
+
+       //lyxerr << "insetButtonRelease: " << x << " " << y << "\n";
        hideInsetCursor(bv);
        showInsetCursor(bv);
        bv->updateInset(this, false);
 
        if (button == mouse_button::button3) {
                // try to dispatch to enclosed insets first
-               if (mathcursor->dispatch("mouse 3"))
+               if (mathcursor->dispatch("mouse-3-release"))
                        return true;
 
                // launch math panel for right mouse button
                bv->owner()->getDialogs()->showMathPanel();
                return true;
        }
+
+       if (button == mouse_button::button1) {
+               // try to dispatch to enclosed insets first
+               if (mathcursor->dispatch("mouse-1-release"))
+                       return true;
+
+               // try to set the cursor
+               //delete mathcursor;
+               //mathcursor = new MathCursor(this, x == 0);
+               //metrics(bv);
+               //mathcursor->setPos(x + xo_, y + yo_);
+               return true;
+       }
        return false;
 }
 
@@ -333,70 +345,53 @@ bool InsetFormulaBase::insetButtonRelease(BufferView * bv,
 void InsetFormulaBase::insetButtonPress(BufferView * bv,
                                        int x, int y, mouse_button::state button)
 {
-       //lyxerr << "insetButtonPress: "
-       //      << x << " " << y << " but: " << button << "\n";
-#if 0
-       switch (button) {
-               default:
-               case 1:
-                       // left click
-                       delete mathcursor;
-                       mathcursor = new MathCursor(this, x == 0);
-                       metrics(bv);
-                       first_x = x;
-                       first_y = y;
-                       mathcursor->selClear();
-                       mathcursor->setPos(x + xo_, y + yo_);
-                       break;
-/*
-               case 2:
-                       lyxerr << "insetButtonPress: 2\n";
-                       // insert stuff
-                       if (mathcursor) {
-                               bv->lockedInsetStoreUndo(Undo::EDIT);
-                               MathArray ar;
-                               mathcursor->selGet(ar);
-                               mathcursor->setPos(x + xo_, y + yo_);
-                               string sel =
-                                       bv->getLyXText()->selectionAsString(bv->buffer(), false);
-                               mathed_parse_cell(ar, sel);
-                               mathcursor->insert(ar);
-                       }
-                       break;
-*/
-               case 3:
-                       // launch math panel for right mouse button
-                       bv->owner()->getDialogs()->showMathPanel();
-                       break;
-       }
-#else
-       if (button == mouse_button::button1 || !mathcursor) {
-               delete mathcursor;
-               mathcursor = new MathCursor(this, x == 0);
+       lyxerr << "insetButtonPress: "
+               << x << " " << y << " but: " << button << "\n";
+       lyxerr << "formula: ";
+       par()->dump();
+
+       delete mathcursor;
+       mathcursor = new MathCursor(this, x == 0);
+
+       if (button == mouse_button::button1) {
+               // just set the cursor here
+               lyxerr << "setting cursor\n";
                metrics(bv);
                first_x = x;
                first_y = y;
                mathcursor->selClear();
                mathcursor->setPos(x + xo_, y + yo_);
+
+               if (mathcursor->dispatch("mouse-1-press")) {
+                       //delete mathcursor;
+                       return;
+               }
+       
        }
-#if 0
-#warning Never launch a Dialog on "Press" event ONLY on "Release" event!
-       if (button == 3) {
-               // launch math panel for right mouse button
-               bv->owner()->getDialogs()->showMathPanel();
+       if (button == mouse_button::button3) { 
+               if (mathcursor->dispatch("mouse-3-press")) {
+                       //delete mathcursor;
+                       return;
+               }
        }
-#endif
-#endif
        bv->updateInset(this, false);
 }
 
 
 void InsetFormulaBase::insetMotionNotify(BufferView * bv,
-       int x, int y, mouse_button::state)
+       int x, int y, mouse_button::state button)
 {
        if (!mathcursor)
                return;
 
+       if (button == mouse_button::button1) 
+               if (mathcursor->dispatch("mouse-1-motion"))
+                       return;
+
+       if (button == mouse_button::button3) 
+               if (mathcursor->dispatch("mouse-3-motion"))
+                       return;
+
        if (abs(x - first_x) < 2 && abs(y - first_y) < 2) {
                //lyxerr << "insetMotionNotify: ignored\n";
                return;
@@ -421,7 +416,9 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
                            string const & arg)
 {
        //lyxerr << "InsetFormulaBase::localDispatch: act: " << action
-       //      << " arg: '" << arg << "' cursor: " << mathcursor << "\n";
+       //      << " arg: '" << arg
+       //      << "' cursor: " << mathcursor
+       //      << "\n";
 
        if (!mathcursor)
                return UNDISPATCHED;
index acbea4ce016568a4ee1b9ac5eb7350674b3e2808..74ad9e9214088e1be471819b77224a0b9defd84e 100644 (file)
@@ -736,7 +736,7 @@ MathInset * MathCursor::par() const
 }
 
 
-InsetFormulaBase * MathCursor::formula()
+InsetFormulaBase * MathCursor::formula() const
 {
        return formula_;
 }
@@ -1759,9 +1759,18 @@ void MathCursor::handleExtern(const string & arg)
 
 int MathCursor::dispatch(string const & cmd)
 {
+       // try to dispatch to adajcent items if they are not editable
+       // actually, this should only happen for mouse clicks...
+       if (hasNextAtom() && !openable(nextAtom(), false))
+               if (int res = nextAtom()->dispatch(cmd, 0, 0))
+                       return res;
+       if (hasPrevAtom() && !openable(prevAtom(), false))
+               if (int res = prevAtom()->dispatch(cmd, 0, 0))
+                       return res;
+
        for (int i = Cursor_.size() - 1; i >= 0; --i) {
                MathCursorPos & pos = Cursor_[i];
-               if (int res = pos.par_-> dispatch(cmd, pos.idx_, pos.pos_))
+               if (int res = pos.par_->dispatch(cmd, pos.idx_, pos.pos_))
                        return res;
        }
        return 0;
index f250c4975b6687baa424619769050578975878ec..96d0348085baebb5a80f0bfa5afc51de198e5ad9 100644 (file)
@@ -117,7 +117,7 @@ public:
        /// go up to the hull inset
        void popToEnclosingHull();
        ///
-       InsetFormulaBase * formula();
+       InsetFormulaBase * formula() const;
        /// current offset in the current cell
        pos_type pos() const;
        /// current cell
index 6b43461120f5836c54711161d5213577b3957a5e..2b4bdddca64309adfc8c4ca9fbff1292a6d3eeb4 100644 (file)
@@ -31,6 +31,7 @@
 #include "math_xymatrixinset.h"
 #include "math_xyarrowinset.h"
 
+//#include "insets/insetref.h"
 #include "ref_inset.h"
 
 #include "math_metricsinfo.h"
@@ -121,10 +122,13 @@ key_type wordlist_array[] =
        {"overline",  "decoration", ""},
        {"overrightarrow",  "decoration", ""},
        {"overleftrightarrow", "decoration", ""},
+       {"pageref",  "ref", ""},
        {"pmatrix",  "matrix", ""},
+       {"prettyref",  "ref", ""},
        {"protect",  "protect", ""},
        {"qquad",  "space", ""},
        {"quad",  "space", ""},
+       {"ref",  "ref", ""},
        {"right",  "right", ""},
        {"rm",  "oldfont", ""},
        {"scriptscriptstyle",  "style", ""},
@@ -149,6 +153,8 @@ key_type wordlist_array[] =
        {"vdots",  "dots", ""},
        {"vec",  "decoration", ""},
        {"vmatrix",  "matrix", ""},
+       {"vpageref",  "ref", ""},
+       {"vref",  "ref", ""},
        {"widehat",  "decoration", ""},
        {"widetilde",  "decoration", ""}
 };
@@ -307,14 +313,13 @@ MathAtom createMathInset(string const & s)
                return MathAtom(new MathNotInset);
        if (s == "lefteqn")
                return MathAtom(new MathLefteqnInset);
-       if (s == "ref")
-               return MathAtom(new RefInset);
-
 
        latexkeys const * l = in_word_set(s);
        if (l) {
                string const & inset = l->inset;
                lyxerr[Debug::MATHED] << " found inset: '" << inset << "'\n";
+               if (inset == "ref")
+                       return MathAtom(new RefInset(l->name));
                if (inset == "underset")
                        return MathAtom(new MathUndersetInset);
                if (inset == "decoration")
index 39a231889a443072ac0f80b1a1eba225e2b0437d..bf6afdaf1c203fcbf670ae455ceec1b8bffa8b5e 100644 (file)
@@ -189,13 +189,17 @@ void MathHullInset::metrics(MathMetricsInfo & mi) const
        math_font_max_dim(mi.base.font, asc, des);
        ascent_  = max(ascent_,  asc);
        descent_ = max(descent_, des);
+
+       // for markers
+       width_   += 2;
+       descent_ += 1;
 }
 
 
 void MathHullInset::draw(MathPainterInfo & pi, int x, int y) const
 {
        MathFontSetChanger dummy(pi.base, standardFont());
-       MathGridInset::draw(pi, x, y);
+       MathGridInset::draw(pi, x + 1, y);
 
        if (numberedType()) {
                int const xx = x + colinfo_.back().offset_ + colinfo_.back().width_ + 20;
@@ -205,6 +209,8 @@ void MathHullInset::draw(MathPainterInfo & pi, int x, int y) const
                        drawStr(pi, pi.base.font, xx, yy, nicelabel(row));
                }
        }
+
+       drawMarkers(pi, x, y);
 }
 
 
@@ -286,7 +292,7 @@ bool MathHullInset::display() const
 }
 
 
-vector<string> const MathHullInset::getLabelList() const
+vector<string> MathHullInset::getLabelList() const
 {
        vector<string> res;
        for (row_type row = 0; row < nrows(); ++row)
index b401e8ca0a911faf7ebacf751ba98cbc42e28b09..fefebc6b532602c38ce07725b96b4c66c3424bbd 100644 (file)
@@ -49,7 +49,7 @@ public:
        ///
        bool ams() const;
        ///
-       std::vector<string> const getLabelList() const;
+       std::vector<string> getLabelList() const;
        ///
        void validate(LaTeXFeatures & features) const;
        /// identifies MatrixInsets
index 5260a4c7dfedf50dc42aa6b9a5b289edae6d1a1c..fb8e78baff01d742d5c96420cfdfadb6fc4022a3 100644 (file)
 #include "math_scriptinset.h"
 #include "math_charinset.h"
 #include "math_mathmlstream.h"
+#include "math_cursor.h"
 #include "debug.h"
 
+#include "frontends/LyXView.h"
+#include "frontends/Dialogs.h"
+#include "BufferView.h"
+#include "formulabase.h"
+
 
 using std::ostream;
 using std::vector;
@@ -278,6 +284,19 @@ int MathInset::dispatch(string const &, idx_type, pos_type)
 }
 
 
+std::vector<string> MathInset::getLabelList() const
+{
+       return std::vector<string>();
+}
+
+
+string const & MathInset::getType() const
+{
+       static string t("none");
+       return t;
+}
+
+
 string asString(MathArray const & ar)
 {
        string res;
@@ -295,3 +314,15 @@ MathArray asArray(string const & str)
                ar.push_back(MathAtom(new MathCharInset(*it)));
        return ar;
 }
+
+
+Dialogs * getDialogs()
+{
+       return mathcursor->formula()->view()->owner()->getDialogs();
+}
+
+
+LyXFunc * getLyXFunc()
+{
+       return mathcursor->formula()->view()->owner()->getLyXFunc();
+}
index e3fbf90a3f84e5e0663855c85dca1421c01a2c58..1e5eda10121eb0f1d031ce05ce570b51cdec7d39 100644 (file)
@@ -67,6 +67,9 @@ class MathSpaceInset;
 class MathSymbolInset;
 class MathUnknownInset;
 class MathXYMatrixInset;
+class MathXYMatrixInset;
+
+class InsetRef;
 
 class NormalStream;
 class OctaveStream;
@@ -213,6 +216,7 @@ public:
        virtual MathUnknownInset       * asUnknownInset()       { return 0; }
        virtual MathUnknownInset const * asUnknownInset() const { return 0; }
        virtual MathXYMatrixInset const* asXYMatrixInset() const{ return 0; }
+       virtual InsetRef               * asInsetRef()           { return 0; }
 
        /// identifies things that can get scripts
        virtual bool isScriptable() const { return false; }
@@ -271,6 +275,17 @@ public:
        virtual void dump() const;
        /// local dispatcher
        virtual int dispatch(string const & cmd, idx_type idx, pos_type pos);
+
+       /// LyXInset stuff
+       virtual std::vector<string> getLabelList() const;
+       /// LyXInset stuff
+       virtual bool numberedType() const { return false; }
+       /// hull type
+       virtual string const & getType() const;
+       /// change type
+       virtual void mutate(string const &) {}
+       /// how is the inset called in the .lyx file?
+       virtual string fileInsetLabel() const { return "Formula"; }
 };
 
 std::ostream & operator<<(std::ostream &, MathInset const &);
@@ -279,4 +294,11 @@ std::ostream & operator<<(std::ostream &, MathAtom const &);
 string asString(MathArray const & ar);
 MathArray asArray(string const & str);
 
+/// here to ssave a few includes in the insets
+class Dialogs;
+class LyXFunc;
+
+Dialogs * getDialogs();
+LyXFunc * getLyXFunc();
+
 #endif
index 53aa3991fe05d332fc942a61c5c1b58100719833..913a66a309ad512d3931fdbb1bfbae9cdaf68eb1 100644 (file)
@@ -58,6 +58,7 @@ following hack as starting point to write some macros:
 #include "math_support.h"
 #include "math_xyarrowinset.h"
 
+//#include "insets/insetref.h"
 #include "ref_inset.h"
 
 #include "lyxlex.h"
@@ -579,13 +580,13 @@ bool Parser::parse_normal(MathAtom & at)
        skipSpaces();
        MathArray ar;
        parse_into(ar, false, false);
-       if (ar.size() != 1) {
-               lyxerr << "Unusual contents found: " << ar << endl;
+       if (ar.size() != 1 || ar.front()->getType() == "none") {
+               lyxerr << "unusual contents found: " << ar << endl;
                at.reset(new MathParInset);
                if (at->nargs() > 0)
                        at->cell(0) = ar;
                else
-                       lyxerr << "Unusual contents found: " << ar << endl;
+                       lyxerr << "unusual contents found: " << ar << endl;
                return true;
        }
        at = ar[0];
index 89ef47cd1e0169e1d5e8c6a4c3543e9117930426..f748a22476d59575c9a44c69ab7fb26c81c02a38 100644 (file)
@@ -38,14 +38,14 @@ void RefInset::infoize(std::ostream & os) const
 
 int RefInset::dispatch(string const & cmd, idx_type, pos_type)
 {
-       if (cmd == "mouse 3") {
+       if (cmd == "mouse-3-release") {
                lyxerr << "trying to goto ref" << cell(0) << "\n";
                mathcursor->formula()->view()->owner()->getLyXFunc()->
                        dispatch(LFUN_REF_GOTO, asString(cell(0)));
                return 1; // dispatched
        }
 
-       if (cmd == "mouse 1") {
+       if (cmd == "mouse-1-release") {
                lyxerr << "trying to open ref" << cell(0) << "\n";
                // Eventually trigger dialog with button 3 not 1
 //             mathcursor->formula()->view()->owner()->getDialogs()
@@ -53,6 +53,10 @@ int RefInset::dispatch(string const & cmd, idx_type, pos_type)
                return 1; // dispatched
        }
 
+       // eat other mouse commands
+       if (cmd.substr(0, 6) == "mouse-")       
+               return 1;
+
        return 0; // undispatched
 }