]> git.lyx.org Git - features.git/commitdiff
new LFUN_MOUSE_(PRESS|MOTION|RELEASE)
authorAndré Pönitz <poenitz@gmx.net>
Mon, 12 Aug 2002 09:53:04 +0000 (09:53 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Mon, 12 Aug 2002 09:53:04 +0000 (09:53 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4941 a592a061-630c-0410-9148-cb99ea01b6c8

13 files changed:
src/ChangeLog
src/commandtags.h
src/funcrequest.h
src/mathed/formulabase.C
src/mathed/math_cursor.C
src/mathed/math_cursor.h
src/mathed/math_factory.C
src/mathed/math_gridinset.C
src/mathed/math_inset.C
src/mathed/math_inset.h
src/mathed/math_parser.C
src/mathed/ref_inset.C
src/mathed/ref_inset.h

index afe84ae8c6162322df49593002d8a87a50da5515..436f45e518947099a708bde7d1ed12086af27988 100644 (file)
@@ -1,3 +1,10 @@
+
+2002-08-07  André Pönitz <poenitz@gmx.net>
+
+       * commandtags.h: new LFUN_MOUSE_(PRESS|MOTION|RELEASE)
+
+       * funcrequest.h: extension to keep mouse (x,y) position
+
 2002-08-12  Juergen Vigna  <jug@sad.it>
 
        * BufferView2.C (insertErrors): forbid undo when inserting error
index 3f3eaf57feaeff4352d66fbdd8079244416e6c1d..8eb6c6c830e500fdf2832fa36e84819887e2265c 100644 (file)
@@ -289,6 +289,9 @@ enum kb_action {
        LFUN_FORKS_SHOW,                // Angus 16 Feb 2002
        LFUN_FORKS_KILL,                // Angus 16 Feb 2002
        LFUN_TOOLTIPS_TOGGLE,           // Angus 8 Mar 2002
+       LFUN_MOUSE_PRESS,               // André 9 Aug 2002
+       LFUN_MOUSE_MOTION,              // André 9 Aug 2002
+       LFUN_MOUSE_RELEASE,             // André 9 Aug 2002
        LFUN_LASTACTION  /* this marks the end of the table */
 };
 
index e3f4ccf15d42d5ea6432c79d2ff2befc18e91b0c..7f701ac202ab57c3e9c868250b96e572ccf01119 100644 (file)
@@ -30,10 +30,21 @@ struct FuncRequest {
                : action(act), argument(arg)
        {}
 
+       /// for mouse events
+       FuncRequest(kb_action act, int ax, int ay, int aextra)
+               : action(act), argument(), x(ax), y(ay), extra(aextra)
+       {}
+
        /// the action
        kb_action action;
        /// the action's string argument
        string argument;
+       /// the x coordinate of a mouse press
+       int x;
+       /// the y coordinate of a mouse press
+       int y;
+       /// some extra information (like button number)
+       int extra;
 };
 
 #endif // FUNCREQUEST_H
index 27ad3eb7d42fed8742d124343087872843aa72bf..9476d5990524e009764b022f88f1377b577b8df5 100644 (file)
@@ -287,7 +287,7 @@ void InsetFormulaBase::updateLocal(BufferView * bv, bool dirty)
 
 
 bool InsetFormulaBase::insetButtonRelease(BufferView * bv,
-       int /*x*/, int /*y*/, mouse_button::state button)
+       int x, int y, mouse_button::state button)
 {
        if (!mathcursor)
                return false;
@@ -299,7 +299,7 @@ bool InsetFormulaBase::insetButtonRelease(BufferView * bv,
 
        if (button == mouse_button::button3) {
                // try to dispatch to enclosed insets first
-               if (mathcursor->dispatch("mouse-3-release"))
+               if (mathcursor->dispatch(FuncRequest(LFUN_MOUSE_RELEASE, x, y, 3)))
                        return true;
 
                // launch math panel for right mouse button
@@ -309,7 +309,7 @@ bool InsetFormulaBase::insetButtonRelease(BufferView * bv,
 
        if (button == mouse_button::button1) {
                // try to dispatch to enclosed insets first
-               if (mathcursor->dispatch("mouse-1-release"))
+               if (mathcursor->dispatch(FuncRequest(LFUN_MOUSE_RELEASE, x, y, 1)))
                        return true;
 
                // try to set the cursor
@@ -329,7 +329,7 @@ void InsetFormulaBase::insetButtonPress(BufferView * bv,
        //lyxerr << "insetButtonPress: "
        //      << x << " " << y << " but: " << button << "\n";
        //lyxerr << "formula: ";
-       par()->dump();
+       //par()->dump();
 
        releaseMathCursor(bv);
        mathcursor = new MathCursor(this, x == 0);
@@ -343,14 +343,14 @@ void InsetFormulaBase::insetButtonPress(BufferView * bv,
                mathcursor->selClear();
                mathcursor->setPos(x + xo_, y + yo_);
 
-               if (mathcursor->dispatch("mouse-1-press")) {
+               if (mathcursor->dispatch(FuncRequest(LFUN_MOUSE_PRESS, x, y, 1))) {
                        //delete mathcursor;
                        return;
                }
 
        }
        if (button == mouse_button::button3) {
-               if (mathcursor->dispatch("mouse-3-press")) {
+               if (mathcursor->dispatch(FuncRequest(LFUN_MOUSE_PRESS, x, y, 3))) {
                        //delete mathcursor;
                        return;
                }
@@ -366,11 +366,11 @@ void InsetFormulaBase::insetMotionNotify(BufferView * bv,
                return;
 
        if (button == mouse_button::button1)
-               if (mathcursor->dispatch("mouse-1-motion"))
+               if (mathcursor->dispatch(FuncRequest(LFUN_MOUSE_MOTION, x, y, 1)))
                        return;
 
        if (button == mouse_button::button3)
-               if (mathcursor->dispatch("mouse-3-motion"))
+               if (mathcursor->dispatch(FuncRequest(LFUN_MOUSE_MOTION, x, y, 3)))
                        return;
 
        if (abs(x - first_x) < 2 && abs(y - first_y) < 2) {
index 315c6758c2c1731eee59939a702b8ef482bb304c..5f5feeb5dc3911e8bc9ca7efc49d7bea26fb4e50 100644 (file)
@@ -1701,7 +1701,7 @@ void MathCursor::handleExtern(const string & arg)
 }
 
 
-int MathCursor::dispatch(string const & cmd)
+int MathCursor::dispatch(FuncRequest const & cmd)
 {
        // try to dispatch to adajcent items if they are not editable
        // actually, this should only happen for mouse clicks...
@@ -1714,7 +1714,8 @@ int MathCursor::dispatch(string const & cmd)
 
        for (int i = Cursor_.size() - 1; i >= 0; --i) {
                MathCursorPos & pos = Cursor_[i];
-               if (int res = pos.par_->dispatch(cmd, pos.idx_, pos.pos_))
+               int const res = pos.par_->dispatch(cmd, pos.idx_, pos.pos_);
+               if (res)
                        return res;
        }
        return 0;
index fae5867490b95784e71310b1fa48571092feedb2..30d5a1d7e631fcf02fa6c28cbd309090e523f9a8 100644 (file)
@@ -238,7 +238,7 @@ public:
        unsigned depth() const;
 
        /// local dispatcher
-       int dispatch(string const & cmd);
+       int dispatch(FuncRequest const & cmd);
        /// describe the situation
        string info() const;
        /// dump selection information for debugging
index faa936b5a3ac969550d740a5e7f44b985a721eb3..5dd795b5ac11ae80b92de2f02352841e4c2162a2 100644 (file)
@@ -96,7 +96,7 @@ void initSymbols()
 
                // special case of pre-defined macros
                if (line.size() > 8 && line.substr(0, 5) == "\\def\\") {
-                       lyxerr << "defining: '" << line << "'\n";
+                       //lyxerr << "defining: '" << line << "'\n";
                        istringstream is(line);
                        MathMacroTable::create(MathAtom(new MathMacroTemplate(is)));
                        continue;
index bac9b0e1b11fa38fdf211098d60ed17ba713b381..1be97fd5619c53a648c0ee385edafd73aa82724b 100644 (file)
@@ -74,6 +74,7 @@ MathGridInset::MathGridInset(char v, string const & h)
        setDefaults();
        valign(v);
        halign(h);
+       //lyxerr << "created grid with " << ncols() << " columns\n";
 }
 
 
@@ -141,6 +142,8 @@ void MathGridInset::halign(string const & hh)
 {
        col_type col = 0;
        for (string::const_iterator it = hh.begin(); it != hh.end(); ++it) {
+               if (col >= ncols())
+                       break;
                char c = *it;
                if (c == '|') {
                        colinfo_[col].lines_++;
@@ -149,7 +152,7 @@ void MathGridInset::halign(string const & hh)
                        ++col;
                        colinfo_[col].lines_ = 0;
                } else {
-                       lyxerr << "unkown column separator: '" << c << "'\n";
+                       lyxerr << "unknown column separator: '" << c << "'\n";
                }
        }
 
@@ -169,6 +172,10 @@ MathGridInset::col_type MathGridInset::guessColumns(string const & hh) const
        for (string::const_iterator it = hh.begin(); it != hh.end(); ++it)
                if (*it == 'c' || *it == 'l' || *it == 'r')
                        ++col;
+       // let's have at least one column, even if we did not recognize its 
+       // alignment
+       if (col == 0)
+               col = 1;
        return col;
 }
 
index e3a0f3be588aca82aff9068c9198a69858530181..f075e4654c53bc689ec2c13e3344ede477e99765 100644 (file)
@@ -265,7 +265,7 @@ int MathInset::docbook(std::ostream &, bool) const
 }
 
 
-int MathInset::dispatch(string const &, idx_type, pos_type) 
+int MathInset::dispatch(FuncRequest const &, idx_type, pos_type) 
 {
        return 0; // undispatched
 }
index 065ad8db5a319fc526c7f6f7e63ce4d8a76cd153..8a98be797f420c15b91c24cced5d8782d7131e24 100644 (file)
@@ -80,6 +80,7 @@ class UpdatableInset;
 class MathMacroTemplate;
 class MathPosFinder;
 class Dimension;
+class FuncRequest;
 
 
 class MathInset {
@@ -280,7 +281,7 @@ public:
        /// dump content to stderr for debugging
        virtual void dump() const;
        /// local dispatcher
-       virtual int dispatch(string const & cmd, idx_type idx, pos_type pos);
+       virtual int dispatch(FuncRequest const & cmd, idx_type idx, pos_type pos);
 
        /// LyXInset stuff
        /// write labels into a list
index fccd52205f566ac54ad3a5bba199f30b4286ec10..64f0c943e9ffe9def47a2ea153c43d9512df75ba 100644 (file)
@@ -144,7 +144,8 @@ enum {
        FLAG_SIMPLE     = 1 << 8,  //  next $ leaves the loop
        FLAG_EQUATION   = 1 << 9,  //  next \] leaves the loop
        FLAG_SIMPLE2    = 1 << 10, //  next \) leaves the loop
-       FLAG_OPTION     = 1 << 11  //  read [...] style option
+       FLAG_OPTION     = 1 << 11, //  read [...] style option
+       FLAG_BRACED     = 1 << 12  //  read {...} style argument
 };
 
 
@@ -230,6 +231,8 @@ public:
        ///
        void parse(MathArray & array, unsigned flags, mode_type mode);
        ///
+       MathArray parse(unsigned flags, mode_type mode);
+       ///
        int lineno() const { return lineno_; }
        ///
        void putback();
@@ -518,6 +521,14 @@ bool Parser::parse(MathAtom & at)
 }
 
 
+MathArray Parser::parse(unsigned flags, mode_type mode)
+{
+       MathArray ar;
+       parse(ar, flags, mode);
+       return ar;
+}
+
+
 void Parser::parse(MathArray & array, unsigned flags, mode_type mode)
 {
        MathGridInset grid(1, 1);
@@ -573,6 +584,21 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
                }
 
 
+               if (flags & FLAG_BRACED) {
+                       if (t.cat() == catSpace)
+                               continue;
+
+                       if (t.cat() != catBegin) {
+                               error("opening brace expected");
+                               return;
+                       }
+
+                       // skip the brace and collect everything to the next matching
+                       // closing brace
+                       flags = FLAG_BRACE_LAST;
+               }
+
+
                if (flags & FLAG_OPTION) {
                        if (t.cat() == catOther && t.character() == '[') {
                                MathArray ar;
@@ -903,9 +929,12 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
 
                else if (t.cs() == "begin") {
                        string const name = getArg('{', '}');
+
                        if (name == "array" || name == "subarray") {
-                               string const valign = getArg('[', ']') + 'c';
-                               string const halign = getArg('{', '}');
+                               string const valign =
+                                       asString(parse(FLAG_OPTION, MathInset::VERBATIM_MODE)) + 'c';
+                               string const halign =
+                                       asString(parse(FLAG_ITEM, MathInset::VERBATIM_MODE));
                                cell->push_back(MathAtom(new MathArrayInset(name, valign[0], halign)));
                                parse2(cell->back(), FLAG_END, mode, false);
                        }
@@ -1002,8 +1031,7 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
                }
 
                else if (t.cs() == "label") {
-                       MathArray ar;
-                       parse(ar, FLAG_ITEM, MathInset::VERBATIM_MODE);
+                       MathArray ar = parse(FLAG_ITEM, MathInset::VERBATIM_MODE);
                        if (grid.asHullInset()) {
                                grid.asHullInset()->label(cellrow, asString(ar));
                        } else {
@@ -1074,6 +1102,7 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
                                        // read optional positioning and width
                                        MathArray pos, width;
                                        parse(pos, FLAG_OPTION, MathInset::VERBATIM_MODE);
+
                                        parse(width, FLAG_ITEM, MathInset::VERBATIM_MODE);
                                        cell->push_back(createMathInset(t.cs()));
                                        parse(cell->back().nucleus()->cell(0), FLAG_ITEM, MathInset::TEXT_MODE);
index aa433942e3f3c63e296d41b5c6e2264523666340..0055d75407b3f2714b73d497fdf80950c56ea888 100644 (file)
@@ -36,28 +36,33 @@ void RefInset::infoize(std::ostream & os) const
 }
 
 
-int RefInset::dispatch(string const & cmd, idx_type, pos_type)
+int RefInset::dispatch(FuncRequest const & cmd, idx_type, pos_type)
 {
-       if (cmd == "mouse-3-release") {
-               lyxerr << "trying to goto ref" << cell(0) << "\n";
-               mathcursor->formula()->view()->owner()->getLyXFunc()->
-                       dispatch(FuncRequest(LFUN_REF_GOTO, asString(cell(0))));
-               return 1; // dispatched
-       }
-
-       if (cmd == "mouse-1-release") {
-               lyxerr << "trying to open ref" << cell(0) << "\n";
-               // FuncRequestually trigger dialog with button 3 not 1
-//             mathcursor->formula()->view()->owner()->getDialogs()
-//                     ->showRef(this);
-               return 1; // dispatched
+       switch (cmd.action) {
+               case LFUN_MOUSE_RELEASE:
+                       if (cmd.extra == 3) {
+                               lyxerr << "trying to goto ref" << cell(0) << "\n";
+                               mathcursor->formula()->view()->owner()->getLyXFunc()->
+                                       dispatch(FuncRequest(LFUN_REF_GOTO, asString(cell(0))));
+                               return 1; // dispatched
+                       }
+                       if (cmd.extra == 1) {
+                               lyxerr << "trying to open ref" << cell(0) << "\n";
+                               // Eventually trigger dialog with button 3 not 1
+               //              mathcursor->formula()->view()->owner()->getDialogs()
+               //                      ->showRef(this);
+                               return 1; // dispatched
+                       }
+                       break;
+               case LFUN_MOUSE_PRESS:  
+               case LFUN_MOUSE_MOTION:
+                       // eat other mouse commands
+                       return 1;
+               default:
+                       break;
        }
-
-       // eat other mouse commands
-       if (cmd.substr(0, 6) == "mouse-")       
-               return 1;
-
-       return 0; // undispatched
+       // not our business
+       return 0;
 }
 
 
index 852fc320d199cd61dee105ae560a092119188955..52c5f936d9b0f4fc4469794c3811712a2e58bac3 100644 (file)
@@ -17,7 +17,7 @@ public:
        ///
        void infoize(std::ostream & os) const;
        ///
-       int dispatch(string const & cmd, idx_type idx, pos_type pos);
+       int dispatch(FuncRequest const & cmd, idx_type idx, pos_type pos);
        ///
        string screenLabel() const;
        ///