commit 4b64aaf4ce026aacce02cfda58dcb1cd954f4adb
Author: Richard Heck <[email protected]>
Date: Mon Jun 20 15:10:14 2016 -0400
This patch does two closely related things.
The main thing it does is integrate mouse-modifiers into the
FuncRequest machinery. Previously, these had to be passed
separately, which led to some ugly function signatures.
There was also an unnecessary form of the constructor, which
can now be removed.
No change of behavior is intended.
---
src/FuncRequest.cpp | 21 ++++++++-------------
src/FuncRequest.h | 12 +++++++-----
src/Server.cpp | 2 +-
src/Text3.cpp | 4 ++--
src/frontends/qt4/GuiWorkArea.cpp | 31 +++++++++----------------------
src/frontends/qt4/GuiWorkArea_Private.h | 2 +-
src/mathed/InsetMathNest.cpp | 2 +-
7 files changed, 29 insertions(+), 45 deletions(-)
diff --git a/src/FuncRequest.cpp b/src/FuncRequest.cpp
index c912b3a..62ba9cd 100644
--- a/src/FuncRequest.cpp
+++ b/src/FuncRequest.cpp
@@ -31,43 +31,38 @@ FuncRequest const FuncRequest::noaction(LFUN_NOACTION);
FuncRequest::FuncRequest(Origin o)
: action_(LFUN_NOACTION), origin_(o), x_(0), y_(0),
- button_(mouse_button::none)
+ button_(mouse_button::none), modifier_(NoModifier)
{}
FuncRequest::FuncRequest(FuncCode act, Origin o)
: action_(act), origin_(o), x_(0), y_(0),
- button_(mouse_button::none)
+ button_(mouse_button::none), modifier_(NoModifier)
{}
FuncRequest::FuncRequest(FuncCode act, docstring const & arg, Origin o)
: action_(act), argument_(arg), origin_(o), x_(0), y_(0),
- button_(mouse_button::none)
+ button_(mouse_button::none), modifier_(NoModifier)
{}
FuncRequest::FuncRequest(FuncCode act, string const & arg, Origin o)
: action_(act), argument_(from_utf8(arg)), origin_(o), x_(0), y_(0),
- button_(mouse_button::none)
+ button_(mouse_button::none), modifier_(NoModifier)
{}
FuncRequest::FuncRequest(FuncCode act, int ax, int ay,
- mouse_button::state but, Origin o)
- : action_(act), origin_(o), x_(ax), y_(ay), button_(but)
+ mouse_button::state but, KeyModifier modifier, Origin
o)
+ : action_(act), origin_(o), x_(ax), y_(ay), button_(but),
+ modifier_(modifier)
{}
FuncRequest::FuncRequest(FuncRequest const & cmd, docstring const & arg,
Origin o)
: action_(cmd.action()), argument_(arg), origin_(o),
- x_(cmd.x_), y_(cmd.y_), button_(cmd.button_)
-{}
-
-
-FuncRequest::FuncRequest(FuncRequest const & cmd, string const & arg, Origin o)
- : action_(cmd.action()), argument_(from_utf8(arg)), origin_(o),
- x_(cmd.x_), y_(cmd.y_), button_(cmd.button_)
+ x_(cmd.x_), y_(cmd.y_), button_(cmd.button_), modifier_(NoModifier)
{}
diff --git a/src/FuncRequest.h b/src/FuncRequest.h
index 2f25d0a..a5822f4 100644
--- a/src/FuncRequest.h
+++ b/src/FuncRequest.h
@@ -16,6 +16,7 @@
#include "support/docstring.h"
+#include "frontends/KeyModifier.h"
#include "frontends/mouse_state.h"
@@ -47,7 +48,7 @@ public:
explicit FuncRequest(FuncCode act, Origin o = INTERNAL);
/// actions without extra argument
FuncRequest(FuncCode act, int x, int y, mouse_button::state button,
- Origin o = INTERNAL);
+ KeyModifier modifier, Origin o = INTERNAL);
/// actions with extra argument
FuncRequest(FuncCode act, docstring const & arg,
Origin o = INTERNAL);
@@ -57,10 +58,7 @@ public:
/// for changing requests a bit
FuncRequest(FuncRequest const & cmd, docstring const & arg,
Origin o = INTERNAL);
- /// for changing requests a bit. FIXME: remove this
- FuncRequest(FuncRequest const & cmd, std::string const & arg,
- Origin o = INTERNAL);
-
+
/// access the whole argument
docstring const & argument() const { return argument_; }
///
@@ -79,6 +77,8 @@ public:
void set_y(int y) { y_ = y; }
///
mouse_button::state button() const { return button_; }
+ ///
+ KeyModifier modifier() { return modifier_; }
/// argument parsing, extract argument i as std::string
std::string getArg(unsigned int i) const;
@@ -103,6 +103,8 @@ private:
int y_;
/// some extra information (like button number)
mouse_button::state button_;
+ ///
+ KeyModifier modifier_;
};
diff --git a/src/Server.cpp b/src/Server.cpp
index c88ae82..0eec4b5 100644
--- a/src/Server.cpp
+++ b/src/Server.cpp
@@ -1175,7 +1175,7 @@ void Server::callback(string const & msg)
// connect to the lyxfunc in the single GuiView we
// support currently. (Lgb)
- FuncRequest fr(lyxaction.lookupFunc(cmd), arg);
+ FuncRequest fr(lyxaction.lookupFunc(cmd), from_ascii(arg));
fr.setOrigin(FuncRequest::LYXSERVER);
DispatchResult dr;
theApp()->dispatch(fr, dr);
diff --git a/src/Text3.cpp b/src/Text3.cpp
index fea23b0..3f48d19 100644
--- a/src/Text3.cpp
+++ b/src/Text3.cpp
@@ -1608,8 +1608,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
switch (cmd.button()) {
case mouse_button::button1:
// Set the cursor
- if (!bv->mouseSetCursor(cur, cmd.argument() ==
"region-select"))
- cur.screenUpdateFlags(Update::FitCursor);
+ if (!bv->mouseSetCursor(cur, cmd.modifier() ==
ShiftModifier))
+ cur.screenUpdateFlags(Update::SinglePar |
Update::FitCursor);
if (bvcur.wordSelection())
selectWord(bvcur, WHOLE_WORD);
break;
diff --git a/src/frontends/qt4/GuiWorkArea.cpp
b/src/frontends/qt4/GuiWorkArea.cpp
index b8886eb..192c82c 100644
--- a/src/frontends/qt4/GuiWorkArea.cpp
+++ b/src/frontends/qt4/GuiWorkArea.cpp
@@ -521,28 +521,15 @@ void GuiWorkArea::processKeySym(KeySymbol const & key,
KeyModifier mod)
}
-void GuiWorkArea::Private::dispatch(FuncRequest const & cmd0, KeyModifier mod)
+void GuiWorkArea::Private::dispatch(FuncRequest const & cmd)
{
// Handle drag&drop
- if (cmd0.action() == LFUN_FILE_OPEN) {
+ if (cmd.action() == LFUN_FILE_OPEN) {
DispatchResult dr;
- lyx_view_->dispatch(cmd0, dr);
+ lyx_view_->dispatch(cmd, dr);
return;
}
- FuncRequest cmd;
-
- if (cmd0.action() == LFUN_MOUSE_PRESS) {
- if (mod == ShiftModifier)
- cmd = FuncRequest(cmd0, "region-select");
- else if (mod == ControlModifier)
- cmd = FuncRequest(cmd0, "paragraph-select");
- else
- cmd = cmd0;
- }
- else
- cmd = cmd0;
-
bool const notJustMovingTheMouse =
cmd.action() != LFUN_MOUSE_MOTION || cmd.button() !=
mouse_button::none;
@@ -815,7 +802,7 @@ void GuiWorkArea::mousePressEvent(QMouseEvent * e)
if (d->dc_event_.active && d->dc_event_ == *e) {
d->dc_event_.active = false;
FuncRequest cmd(LFUN_MOUSE_TRIPLE, e->x(), e->y(),
- q_button_state(e->button()));
+ q_button_state(e->button()),
q_key_state(e->modifiers()));
d->dispatch(cmd);
e->accept();
return;
@@ -826,8 +813,8 @@ void GuiWorkArea::mousePressEvent(QMouseEvent * e)
#endif
FuncRequest const cmd(LFUN_MOUSE_PRESS, e->x(), e->y(),
- q_button_state(e->button()));
- d->dispatch(cmd, q_key_state(e->modifiers()));
+ q_button_state(e->button()), q_key_state(e->modifiers()));
+ d->dispatch(cmd);
// Save the context menu on mouse press, because also the mouse
// cursor is set on mouse press. Afterwards, we can either release
@@ -847,7 +834,7 @@ void GuiWorkArea::mouseReleaseEvent(QMouseEvent * e)
d->synthetic_mouse_event_.timeout.stop();
FuncRequest const cmd(LFUN_MOUSE_RELEASE, e->x(), e->y(),
- q_button_state(e->button()));
+ q_button_state(e->button()),
q_key_state(e->modifiers()));
d->dispatch(cmd);
e->accept();
}
@@ -858,7 +845,7 @@ void GuiWorkArea::mouseMoveEvent(QMouseEvent * e)
// we kill the triple click if we move
doubleClickTimeout();
FuncRequest cmd(LFUN_MOUSE_MOTION, e->x(), e->y(),
- q_motion_state(e->buttons()));
+ q_motion_state(e->buttons()), q_key_state(e->modifiers()));
e->accept();
@@ -1122,7 +1109,7 @@ void GuiWorkArea::mouseDoubleClickEvent(QMouseEvent * ev)
SLOT(doubleClickTimeout()));
FuncRequest cmd(LFUN_MOUSE_DOUBLE,
ev->x(), ev->y(),
- q_button_state(ev->button()));
+ q_button_state(ev->button()),
q_key_state(ev->modifiers()));
d->dispatch(cmd);
ev->accept();
}
diff --git a/src/frontends/qt4/GuiWorkArea_Private.h
b/src/frontends/qt4/GuiWorkArea_Private.h
index 5320c5c..8a1b98e 100644
--- a/src/frontends/qt4/GuiWorkArea_Private.h
+++ b/src/frontends/qt4/GuiWorkArea_Private.h
@@ -105,7 +105,7 @@ struct GuiWorkArea::Private
/// hide the cursor
void removeCursor();
///
- void dispatch(FuncRequest const & cmd0, KeyModifier = NoModifier);
+ void dispatch(FuncRequest const & cmd0);
/// hide the visible cursor, if it is visible
void hideCursor();
/// show the cursor if it is not visible
diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp
index 716ad66..87b7f42 100644
--- a/src/mathed/InsetMathNest.cpp
+++ b/src/mathed/InsetMathNest.cpp
@@ -1550,7 +1550,7 @@ void InsetMathNest::lfunMousePress(Cursor & cur,
FuncRequest & cmd)
}
}
bool do_selection = cmd.button() == mouse_button::button1
- && cmd.argument() == "region-select";
+ && cmd.modifier() == ShiftModifier;
bv.mouseSetCursor(cur, do_selection);
if (cmd.button() == mouse_button::button1) {
//lyxerr << "## lfunMousePress: setting cursor to: " << cur <<
endl;