summaryrefslogtreecommitdiff
path: root/indra/newview
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2011-08-25 14:54:38 -0400
committerNat Goodspeed <nat@lindenlab.com>2011-08-25 14:54:38 -0400
commit79f14b7febf512e96a7d63eff8e6db895a7e72cf (patch)
treebf0f0e62c30980fe755b9e3542a371911072eb50 /indra/newview
parentf7a6ed85e40f53e5e28868bf34ac4dbc9bb204fb (diff)
CHOP-763: Move llwindowlistener.{h,cpp} from llwindow to newview.
Instantiate LLWindowListener on LLViewerWindow instead of on LLWindow. This permits LLWindowListener to use machinery from llui, e.g. LLUI::resolvePath(). Document planned new ["path"], ["reply"] params to "keyDown", "keyUp", "mouseDown", "mouseUp", "mouseMove" operations; document relationship between ["path"] and ["x"] and ["y"]. NEW PARAMS NOT YET IMPLEMENTED.
Diffstat (limited to 'indra/newview')
-rw-r--r--indra/newview/CMakeLists.txt2
-rw-r--r--indra/newview/llviewerwindow.cpp9
-rw-r--r--indra/newview/llviewerwindow.h4
-rw-r--r--indra/newview/llwindowlistener.cpp247
-rw-r--r--indra/newview/llwindowlistener.h55
5 files changed, 315 insertions, 2 deletions
diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt
index 935dd2e887..bd080f2ac4 100644
--- a/indra/newview/CMakeLists.txt
+++ b/indra/newview/CMakeLists.txt
@@ -599,6 +599,7 @@ set(viewer_SOURCE_FILES
llweb.cpp
llwebsharing.cpp
llwind.cpp
+ llwindowlistener.cpp
llwlanimator.cpp
llwldaycycle.cpp
llwlhandlers.cpp
@@ -1153,6 +1154,7 @@ set(viewer_HEADER_FILES
llweb.h
llwebsharing.h
llwind.h
+ llwindowlistener.h
llwlanimator.h
llwldaycycle.h
llwlhandlers.h
diff --git a/indra/newview/llviewerwindow.cpp b/indra/newview/llviewerwindow.cpp
index 988c4ed1a2..0501b61592 100644
--- a/indra/newview/llviewerwindow.cpp
+++ b/indra/newview/llviewerwindow.cpp
@@ -36,6 +36,7 @@
#include <iostream>
#include <fstream>
#include <algorithm>
+#include <boost/lambda/core.hpp>
#include "llagent.h"
#include "llagentcamera.h"
@@ -198,6 +199,7 @@
#include "llfloaternotificationsconsole.h"
#include "llnearbychat.h"
+#include "llwindowlistener.h"
#include "llviewerwindowlistener.h"
#include "llpaneltopinfobar.h"
@@ -1552,7 +1554,12 @@ LLViewerWindow::LLViewerWindow(
mResDirty(false),
mStatesDirty(false),
mCurrResolutionIndex(0),
- mViewerWindowListener(new LLViewerWindowListener(this)),
+ // gKeyboard is still NULL, so it doesn't do LLWindowListener any good to
+ // pass its value right now. Instead, pass it a nullary function that
+ // will, when we later need it, return the value of gKeyboard.
+ // boost::lambda::var() constructs such a functor on the fly.
+ mWindowListener(new LLWindowListener(this, boost::lambda::var(gKeyboard))),
+ mViewerWindowListener(new LLViewerWindowListener(this)),
mProgressView(NULL)
{
LLNotificationChannel::buildChannel("VW_alerts", "Visible", LLNotificationFilters::filterBy<std::string>(&LLNotification::getType, "alert"));
diff --git a/indra/newview/llviewerwindow.h b/indra/newview/llviewerwindow.h
index ff49ed1f62..48599ebb00 100644
--- a/indra/newview/llviewerwindow.h
+++ b/indra/newview/llviewerwindow.h
@@ -62,6 +62,7 @@ class LLImageFormatted;
class LLHUDIcon;
class LLWindow;
class LLRootView;
+class LLWindowListener;
class LLViewerWindowListener;
class LLPopupView;
@@ -455,7 +456,8 @@ protected:
bool mStatesDirty;
U32 mCurrResolutionIndex;
- boost::scoped_ptr<LLViewerWindowListener> mViewerWindowListener;
+ boost::scoped_ptr<LLWindowListener> mWindowListener;
+ boost::scoped_ptr<LLViewerWindowListener> mViewerWindowListener;
protected:
static std::string sSnapshotBaseName;
diff --git a/indra/newview/llwindowlistener.cpp b/indra/newview/llwindowlistener.cpp
new file mode 100644
index 0000000000..e5deaa42cf
--- /dev/null
+++ b/indra/newview/llwindowlistener.cpp
@@ -0,0 +1,247 @@
+/**
+ * @file llwindowlistener.cpp
+ * @brief EventAPI interface for injecting input into LLWindow
+ *
+ * $LicenseInfo:firstyear=2001&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2010, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
+ * $/LicenseInfo$
+ */
+
+#include "linden_common.h"
+
+#include "llwindowlistener.h"
+
+#include "llcoord.h"
+#include "llkeyboard.h"
+#include "llwindowcallbacks.h"
+#include "llui.h"
+#include <map>
+
+LLWindowListener::LLWindowListener(LLWindowCallbacks *window, const KeyboardGetter& kbgetter)
+ : LLEventAPI("LLWindow", "Inject input events into the LLWindow instance"),
+ mWindow(window),
+ mKbGetter(kbgetter)
+{
+ std::string keySomething =
+ "Given [\"keysym\"], [\"keycode\"] or [\"char\"], inject the specified ";
+ std::string keyExplain =
+ "(integer keycode values, or keysym string from any addKeyName() call in\n"
+ "http://hg.secondlife.com/viewer-development/src/tip/indra/llwindow/llkeyboard.cpp )\n";
+ std::string mask =
+ "Specify optional [\"mask\"] as an array containing any of \"CTL\", \"ALT\",\n"
+ "\"SHIFT\" or \"MAC_CONTROL\"; the corresponding modifier bits will be combined\n"
+ "to form the mask used with the event.";
+
+ std::string given = "Given ";
+ std::string mouseParams =
+ "optional [\"path\"], optional [\"x\"] and [\"y\"], inject the requested mouse ";
+ std::string buttonParams =
+ std::string("[\"button\"], ") + mouseParams;
+ std::string buttonExplain =
+ "(button values \"LEFT\", \"MIDDLE\", \"RIGHT\")\n";
+ std::string paramsExplain =
+ "[\"path\"] is as for LLUI::resolvePath(), described in\n"
+ "http://hg.secondlife.com/viewer-development/src/tip/indra/llui/llui.h\n"
+ "If you omit [\"path\"], you must specify both [\"x\"] and [\"y\"].\n"
+ "If you specify [\"path\"] without both [\"x\"] and [\"y\"], will synthesize (x, y)\n"
+ "in the center of the LLView selected by [\"path\"].\n"
+ "You may specify [\"path\"] with both [\"x\"] and [\"y\"], will use your (x, y).\n"
+ "This may cause the LLView selected by [\"path\"] to reject the event.\n"
+ "Optional [\"reply\"] requests a reply event on the named LLEventPump.\n"
+ "reply[\"error\"] isUndefined (None) on success, else an explanatory message.\n";
+
+ add("keyDown",
+ keySomething + "keypress event.\n" + keyExplain + mask,
+ &LLWindowListener::keyDown);
+ add("keyUp",
+ keySomething + "key release event.\n" + keyExplain + mask,
+ &LLWindowListener::keyUp);
+ add("mouseDown",
+ given + buttonParams + "click event.\n" + buttonExplain + paramsExplain + mask,
+ &LLWindowListener::mouseDown);
+ add("mouseUp",
+ given + buttonParams + "release event.\n" + buttonExplain + paramsExplain + mask,
+ &LLWindowListener::mouseUp);
+ add("mouseMove",
+ given + mouseParams + "movement event.\n" + paramsExplain + mask,
+ &LLWindowListener::mouseMove);
+ add("mouseScroll",
+ "Given an integer number of [\"clicks\"], inject the requested mouse scroll event.\n"
+ "(positive clicks moves downward through typical content)",
+ &LLWindowListener::mouseScroll);
+}
+
+template <typename MAPPED>
+class StringLookup
+{
+private:
+ std::string mDesc;
+ typedef std::map<std::string, MAPPED> Map;
+ Map mMap;
+
+public:
+ StringLookup(const std::string& desc): mDesc(desc) {}
+
+ MAPPED lookup(const typename Map::key_type& key) const
+ {
+ typename Map::const_iterator found = mMap.find(key);
+ if (found == mMap.end())
+ {
+ LL_WARNS("LLWindowListener") << "Unknown " << mDesc << " '" << key << "'" << LL_ENDL;
+ return MAPPED();
+ }
+ return found->second;
+ }
+
+protected:
+ void add(const typename Map::key_type& key, const typename Map::mapped_type& value)
+ {
+ mMap.insert(typename Map::value_type(key, value));
+ }
+};
+
+// helper for getMask()
+static MASK lookupMask_(const std::string& maskname)
+{
+ // It's unclear to me whether MASK_MAC_CONTROL is important, but it's not
+ // supported by maskFromString(). Handle that specially.
+ if (maskname == "MAC_CONTROL")
+ {
+ return MASK_MAC_CONTROL;
+ }
+ else
+ {
+ // In case of lookup failure, return MASK_NONE, which won't affect our
+ // caller's OR.
+ MASK mask(MASK_NONE);
+ LLKeyboard::maskFromString(maskname, &mask);
+ return mask;
+ }
+}
+
+static MASK getMask(const LLSD& event)
+{
+ LLSD masknames(event["mask"]);
+ if (! masknames.isArray())
+ {
+ // If event["mask"] is a single string, perform normal lookup on it.
+ return lookupMask_(masknames);
+ }
+
+ // Here event["mask"] is an array of mask-name strings. OR together their
+ // corresponding bits.
+ MASK mask(MASK_NONE);
+ for (LLSD::array_const_iterator ai(masknames.beginArray()), aend(masknames.endArray());
+ ai != aend; ++ai)
+ {
+ mask |= lookupMask_(*ai);
+ }
+ return mask;
+}
+
+static KEY getKEY(const LLSD& event)
+{
+ if (event.has("keysym"))
+ {
+ // Initialize to KEY_NONE; that way we can ignore the bool return from
+ // keyFromString() and, in the lookup-fail case, simply return KEY_NONE.
+ KEY key(KEY_NONE);
+ LLKeyboard::keyFromString(event["keysym"], &key);
+ return key;
+ }
+ else if (event.has("keycode"))
+ {
+ return KEY(event["keycode"].asInteger());
+ }
+ else
+ {
+ return KEY(event["char"].asString()[0]);
+ }
+}
+
+void LLWindowListener::keyDown(LLSD const & evt)
+{
+ mKbGetter()->handleTranslatedKeyDown(getKEY(evt), getMask(evt));
+}
+
+void LLWindowListener::keyUp(LLSD const & evt)
+{
+ mKbGetter()->handleTranslatedKeyUp(getKEY(evt), getMask(evt));
+}
+
+// for WhichButton
+typedef BOOL (LLWindowCallbacks::*MouseFunc)(LLWindow *, LLCoordGL, MASK);
+struct Actions
+{
+ Actions(const MouseFunc& d, const MouseFunc& u): down(d), up(u), valid(true) {}
+ Actions(): valid(false) {}
+ MouseFunc down, up;
+ bool valid;
+};
+
+struct WhichButton: public StringLookup<Actions>
+{
+ WhichButton(): StringLookup<Actions>("mouse button")
+ {
+ add("LEFT", Actions(&LLWindowCallbacks::handleMouseDown,
+ &LLWindowCallbacks::handleMouseUp));
+ add("RIGHT", Actions(&LLWindowCallbacks::handleRightMouseDown,
+ &LLWindowCallbacks::handleRightMouseUp));
+ add("MIDDLE", Actions(&LLWindowCallbacks::handleMiddleMouseDown,
+ &LLWindowCallbacks::handleMiddleMouseUp));
+ }
+};
+static WhichButton buttons;
+
+static LLCoordGL getPos(const LLSD& event)
+{
+ return LLCoordGL(event["x"].asInteger(), event["y"].asInteger());
+}
+
+void LLWindowListener::mouseDown(LLSD const & evt)
+{
+ Actions actions(buttons.lookup(evt["button"]));
+ if (actions.valid)
+ {
+ (mWindow->*(actions.down))(NULL, getPos(evt), getMask(evt));
+ }
+}
+
+void LLWindowListener::mouseUp(LLSD const & evt)
+{
+ Actions actions(buttons.lookup(evt["button"]));
+ if (actions.valid)
+ {
+ (mWindow->*(actions.up))(NULL, getPos(evt), getMask(evt));
+ }
+}
+
+void LLWindowListener::mouseMove(LLSD const & evt)
+{
+ mWindow->handleMouseMove(NULL, getPos(evt), getMask(evt));
+}
+
+void LLWindowListener::mouseScroll(LLSD const & evt)
+{
+ S32 clicks = evt["clicks"].asInteger();
+
+ mWindow->handleScrollWheel(NULL, clicks);
+}
+
diff --git a/indra/newview/llwindowlistener.h b/indra/newview/llwindowlistener.h
new file mode 100644
index 0000000000..74e577ff93
--- /dev/null
+++ b/indra/newview/llwindowlistener.h
@@ -0,0 +1,55 @@
+/**
+ * @file llwindowlistener.h
+ * @brief EventAPI interface for injecting input into LLWindow
+ *
+ * $LicenseInfo:firstyear=2001&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2010, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
+ * $/LicenseInfo$
+ */
+
+#ifndef LL_LLWINDOWLISTENER_H
+#define LL_LLWINDOWLISTENER_H
+
+#include "lleventapi.h"
+#include <boost/function.hpp>
+
+class LLKeyboard;
+class LLWindowCallbacks;
+
+class LLWindowListener : public LLEventAPI
+{
+public:
+ typedef boost::function<LLKeyboard*()> KeyboardGetter;
+ LLWindowListener(LLWindowCallbacks * window, const KeyboardGetter& kbgetter);
+
+ void keyDown(LLSD const & evt);
+ void keyUp(LLSD const & evt);
+ void mouseDown(LLSD const & evt);
+ void mouseUp(LLSD const & evt);
+ void mouseMove(LLSD const & evt);
+ void mouseScroll(LLSD const & evt);
+
+private:
+ LLWindowCallbacks * mWindow;
+ KeyboardGetter mKbGetter;
+};
+
+
+#endif // LL_LLWINDOWLISTENER_H