From: André Pönitz Date: Mon, 12 Aug 2002 09:53:04 +0000 (+0000) Subject: new LFUN_MOUSE_(PRESS|MOTION|RELEASE) X-Git-Tag: 1.6.10~18601 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=a9e93befaa4c5ff47c5d31786bf790914b13b31d;p=features.git new LFUN_MOUSE_(PRESS|MOTION|RELEASE) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4941 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/ChangeLog b/src/ChangeLog index afe84ae8c6..436f45e518 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ + +2002-08-07 André Pönitz + + * commandtags.h: new LFUN_MOUSE_(PRESS|MOTION|RELEASE) + + * funcrequest.h: extension to keep mouse (x,y) position + 2002-08-12 Juergen Vigna * BufferView2.C (insertErrors): forbid undo when inserting error diff --git a/src/commandtags.h b/src/commandtags.h index 3f3eaf57fe..8eb6c6c830 100644 --- a/src/commandtags.h +++ b/src/commandtags.h @@ -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 */ }; diff --git a/src/funcrequest.h b/src/funcrequest.h index e3f4ccf15d..7f701ac202 100644 --- a/src/funcrequest.h +++ b/src/funcrequest.h @@ -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 diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index 27ad3eb7d4..9476d59905 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -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) { diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 315c6758c2..5f5feeb5dc 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -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; diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index fae5867490..30d5a1d7e6 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -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 diff --git a/src/mathed/math_factory.C b/src/mathed/math_factory.C index faa936b5a3..5dd795b5ac 100644 --- a/src/mathed/math_factory.C +++ b/src/mathed/math_factory.C @@ -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; diff --git a/src/mathed/math_gridinset.C b/src/mathed/math_gridinset.C index bac9b0e1b1..1be97fd561 100644 --- a/src/mathed/math_gridinset.C +++ b/src/mathed/math_gridinset.C @@ -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; } diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index e3a0f3be58..f075e4654c 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -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 } diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 065ad8db5a..8a98be797f 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -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 diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index fccd52205f..64f0c943e9 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -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); diff --git a/src/mathed/ref_inset.C b/src/mathed/ref_inset.C index aa433942e3..0055d75407 100644 --- a/src/mathed/ref_inset.C +++ b/src/mathed/ref_inset.C @@ -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; } diff --git a/src/mathed/ref_inset.h b/src/mathed/ref_inset.h index 852fc320d1..52c5f936d9 100644 --- a/src/mathed/ref_inset.h +++ b/src/mathed/ref_inset.h @@ -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; ///