new LFUN_MOUSE_(PRESS|MOTION|RELEASE)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4941 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2002-08-12 09:53:04 +00:00
parent 46af93a495
commit a9e93befaa
13 changed files with 105 additions and 41 deletions

View 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

View 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 */
};

View 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

View 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) {

View 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;

View 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

View 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;

View 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;
}

View 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
}

View 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

View 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);

View 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
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;
}
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
}
// eat other mouse commands
if (cmd.substr(0, 6) == "mouse-")
return 1;
return 0; // undispatched
// not our business
return 0;
}

View 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;
///