From 79f14b7febf512e96a7d63eff8e6db895a7e72cf Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 25 Aug 2011 14:54:38 -0400 Subject: 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. --- indra/newview/CMakeLists.txt | 2 + indra/newview/llviewerwindow.cpp | 9 +- indra/newview/llviewerwindow.h | 4 +- indra/newview/llwindowlistener.cpp | 247 +++++++++++++++++++++++++++++++++++++ indra/newview/llwindowlistener.h | 55 +++++++++ 5 files changed, 315 insertions(+), 2 deletions(-) create mode 100644 indra/newview/llwindowlistener.cpp create mode 100644 indra/newview/llwindowlistener.h (limited to 'indra/newview') 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 #include #include +#include #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(&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 mViewerWindowListener; + boost::scoped_ptr mWindowListener; + boost::scoped_ptr 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 + +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 +class StringLookup +{ +private: + std::string mDesc; + typedef std::map 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 +{ + WhichButton(): StringLookup("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 + +class LLKeyboard; +class LLWindowCallbacks; + +class LLWindowListener : public LLEventAPI +{ +public: + typedef boost::function 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 -- cgit v1.2.3 From 1d31559b30a32c4ebfde7dc2c42baef840be7c4d Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Fri, 26 Aug 2011 15:06:14 -0500 Subject: implement path option for key events. --- indra/newview/llwindowlistener.cpp | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'indra/newview') diff --git a/indra/newview/llwindowlistener.cpp b/indra/newview/llwindowlistener.cpp index e5deaa42cf..3d756ef9b9 100644 --- a/indra/newview/llwindowlistener.cpp +++ b/indra/newview/llwindowlistener.cpp @@ -29,9 +29,13 @@ #include "llwindowlistener.h" #include "llcoord.h" +#include "llfocusmgr.h" #include "llkeyboard.h" #include "llwindowcallbacks.h" #include "llui.h" +#include "llview.h" +#include "llviewerwindow.h" +#include "llrootview.h" #include LLWindowListener::LLWindowListener(LLWindowCallbacks *window, const KeyboardGetter& kbgetter) @@ -117,8 +121,10 @@ protected: } }; +namespace { + // helper for getMask() -static MASK lookupMask_(const std::string& maskname) +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. @@ -136,7 +142,7 @@ static MASK lookupMask_(const std::string& maskname) } } -static MASK getMask(const LLSD& event) +MASK getMask(const LLSD& event) { LLSD masknames(event["mask"]); if (! masknames.isArray()) @@ -156,7 +162,7 @@ static MASK getMask(const LLSD& event) return mask; } -static KEY getKEY(const LLSD& event) +KEY getKEY(const LLSD& event) { if (event.has("keysym")) { @@ -176,13 +182,36 @@ static KEY getKEY(const LLSD& event) } } +} // namespace + void LLWindowListener::keyDown(LLSD const & evt) { - mKbGetter()->handleTranslatedKeyDown(getKEY(evt), getMask(evt)); + if (evt.has("path")) + { + LLView * target_view = + LLUI::resolvePath(gViewerWindow->getRootView(), evt["path"]); + if ((target_view != 0) && target_view->isAvailable()) + { + gFocusMgr.setKeyboardFocus(target_view); + KEY key = getKEY(evt); + MASK mask = getMask(evt); + if (!target_view->handleKey(key, mask, true)) target_view->handleUnicodeChar(key, true); + } + else + { + ; // TODO: Don't silently fail if target not available. + } + } + else + { + mKbGetter()->handleTranslatedKeyDown(getKEY(evt), getMask(evt)); + } } void LLWindowListener::keyUp(LLSD const & evt) { + if (evt.has("path")) return; // LLView only handles key down. + mKbGetter()->handleTranslatedKeyUp(getKEY(evt), getMask(evt)); } -- cgit v1.2.3 From 34a620523a7f4511c8f008f2e9a9428f41281480 Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Mon, 29 Aug 2011 13:27:17 -0500 Subject: a better way to inject key events. --- indra/newview/llwindowlistener.cpp | 27 ++++++++++++++++++++++----- indra/newview/llwindowlistener.h | 6 +++--- 2 files changed, 25 insertions(+), 8 deletions(-) (limited to 'indra/newview') diff --git a/indra/newview/llwindowlistener.cpp b/indra/newview/llwindowlistener.cpp index 3d756ef9b9..4cadc8773d 100644 --- a/indra/newview/llwindowlistener.cpp +++ b/indra/newview/llwindowlistener.cpp @@ -35,10 +35,11 @@ #include "llui.h" #include "llview.h" #include "llviewerwindow.h" +#include "llviewerkeyboard.h" #include "llrootview.h" #include -LLWindowListener::LLWindowListener(LLWindowCallbacks *window, const KeyboardGetter& kbgetter) +LLWindowListener::LLWindowListener(LLViewerWindow *window, const KeyboardGetter& kbgetter) : LLEventAPI("LLWindow", "Inject input events into the LLWindow instance"), mWindow(window), mKbGetter(kbgetter) @@ -195,7 +196,8 @@ void LLWindowListener::keyDown(LLSD const & evt) gFocusMgr.setKeyboardFocus(target_view); KEY key = getKEY(evt); MASK mask = getMask(evt); - if (!target_view->handleKey(key, mask, true)) target_view->handleUnicodeChar(key, true); + gViewerKeyboard.handleKey(key, mask, false); + if(key < 0x80) mWindow->handleUnicodeChar(key, mask); } else { @@ -210,9 +212,24 @@ void LLWindowListener::keyDown(LLSD const & evt) void LLWindowListener::keyUp(LLSD const & evt) { - if (evt.has("path")) return; // LLView only handles key down. - - mKbGetter()->handleTranslatedKeyUp(getKEY(evt), getMask(evt)); + if (evt.has("path")) + { + LLView * target_view = + LLUI::resolvePath(gViewerWindow->getRootView(), evt["path"]); + if ((target_view != 0) && target_view->isAvailable()) + { + gFocusMgr.setKeyboardFocus(target_view); + mKbGetter()->handleTranslatedKeyUp(getKEY(evt), getMask(evt)); + } + else + { + ; // TODO: Don't silently fail if target not available. + } + } + else + { + mKbGetter()->handleTranslatedKeyUp(getKEY(evt), getMask(evt)); + } } // for WhichButton diff --git a/indra/newview/llwindowlistener.h b/indra/newview/llwindowlistener.h index 74e577ff93..26adff35ff 100644 --- a/indra/newview/llwindowlistener.h +++ b/indra/newview/llwindowlistener.h @@ -31,13 +31,13 @@ #include class LLKeyboard; -class LLWindowCallbacks; +class LLViewerWindow; class LLWindowListener : public LLEventAPI { public: typedef boost::function KeyboardGetter; - LLWindowListener(LLWindowCallbacks * window, const KeyboardGetter& kbgetter); + LLWindowListener(LLViewerWindow * window, const KeyboardGetter& kbgetter); void keyDown(LLSD const & evt); void keyUp(LLSD const & evt); @@ -47,7 +47,7 @@ public: void mouseScroll(LLSD const & evt); private: - LLWindowCallbacks * mWindow; + LLViewerWindow * mWindow; KeyboardGetter mKbGetter; }; -- cgit v1.2.3 From f08d7fba9f2134a687169d8da478a44bdbe16955 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Mon, 29 Aug 2011 15:57:32 -0400 Subject: CHOP-763: Implement widget-pathname-based routing for mouse events. Send mouseDown(), mouseUp(), mouseMove() through static mouseEvent() helper function. Process new optional ["path"] param, validating corresponding LLView and capturing certain information about it for caller. Synthesize (x, y) pos if need be. Use LLView::TemporaryDrilldownFunc and llview::TargetEvent to temporarily hijack normal LLView mouse-event propagation. Define Response helper class to capture LLSD blob about the current request and ensure it gets sent on return. --- indra/newview/llwindowlistener.cpp | 199 ++++++++++++++++++++++++++++++++++--- 1 file changed, 183 insertions(+), 16 deletions(-) (limited to 'indra/newview') diff --git a/indra/newview/llwindowlistener.cpp b/indra/newview/llwindowlistener.cpp index 4cadc8773d..84126b7738 100644 --- a/indra/newview/llwindowlistener.cpp +++ b/indra/newview/llwindowlistener.cpp @@ -34,10 +34,19 @@ #include "llwindowcallbacks.h" #include "llui.h" #include "llview.h" +#include "llviewinject.h" #include "llviewerwindow.h" #include "llviewerkeyboard.h" #include "llrootview.h" +#include "llsdutil.h" +#include "stringize.h" +#include #include +#include +#include +#include + +namespace bll = boost::lambda; LLWindowListener::LLWindowListener(LLViewerWindow *window, const KeyboardGetter& kbgetter) : LLEventAPI("LLWindow", "Inject input events into the LLWindow instance"), @@ -233,12 +242,12 @@ void LLWindowListener::keyUp(LLSD const & evt) } // for WhichButton -typedef BOOL (LLWindowCallbacks::*MouseFunc)(LLWindow *, LLCoordGL, MASK); +typedef BOOL (LLWindowCallbacks::*MouseMethod)(LLWindow *, LLCoordGL, MASK); struct Actions { - Actions(const MouseFunc& d, const MouseFunc& u): down(d), up(u), valid(true) {} + Actions(const MouseMethod& d, const MouseMethod& u): down(d), up(u), valid(true) {} Actions(): valid(false) {} - MouseFunc down, up; + MouseMethod down, up; bool valid; }; @@ -256,38 +265,196 @@ struct WhichButton: public StringLookup }; static WhichButton buttons; -static LLCoordGL getPos(const LLSD& event) +struct Response +{ + Response(const LLSD& seed, const LLSD& request, const LLSD::String& replyKey="reply"): + mResp(seed), + mReq(request), + mKey(replyKey) + {} + + ~Response() + { + // When you instantiate a stack Response object, if the original + // request requested a reply, send it when we leave this block, no + // matter how. + sendReply(mResp, mReq, mKey); + } + + void warn(const std::string& warning) + { + LL_WARNS("LLWindowListener") << warning << LL_ENDL; + mResp["warnings"].append(warning); + } + + void error(const std::string& error) + { + // Use LL_WARNS rather than LL_ERROR: we don't want the viewer to shut + // down altogether. + LL_WARNS("LLWindowListener") << error << LL_ENDL; + + mResp["error"] = error; + } + + // set other keys... + LLSD& operator[](const LLSD::String& key) { return mResp[key]; } + + LLSD mResp, mReq; + LLSD::String mKey; +}; + +typedef boost::function MouseFunc; + +static void mouseEvent(const MouseFunc& func, const LLSD& request) { - return LLCoordGL(event["x"].asInteger(), event["y"].asInteger()); + // Ensure we send response + Response response(LLSD(), request); + // We haven't yet established whether the incoming request has "x" and "y", + // but capture this anyway, with 0 for omitted values. + LLCoordGL pos(request["x"].asInteger(), request["y"].asInteger()); + bool has_pos(request.has("x") && request.has("y")); + + boost::scoped_ptr tempfunc; + + // Documentation for mouseDown(), mouseUp() and mouseMove() claims you + // must either specify ["path"], or both of ["x"] and ["y"]. You MAY + // specify all. Let's say that passing "path" as an empty string is + // equivalent to not passing it at all. + std::string path(request["path"]); + if (path.empty()) + { + // Without "path", you must specify both "x" and "y". + if (! has_pos) + { + return response.error(STRINGIZE(request["op"].asString() << " request " + "without \"path\" must specify both \"x\" and \"y\": " + << request)); + } + } + else // ! path.empty() + { + LLView* root = LLUI::getRootView(); + LLView* target = LLUI::resolvePath(root, path); + if (! target) + { + return response.error(STRINGIZE(request["op"].asString() << " request " + "specified invalid \"path\": '" << path << "'")); + return; + } + + // Get info about this LLView* for when we send response. + response["path"] = target->getPathname(); + response["class"] = typeid(*target).name(); + bool visible_chain(target->isInVisibleChain()); + bool enabled_chain(target->isInEnabledChain()); + response["visible"] = target->getVisible(); + response["visible_chain"] = visible_chain; + response["enabled"] = target->getEnabled(); + response["enabled_chain"] = enabled_chain; + response["available"] = target->isAvailable(); + // Don't show caller the LLView's own relative rectangle; that only + // tells its dimensions. Provide actual location on screen. + LLRect rect(target->calcScreenRect()); + response["rect"] = LLSDMap("left", rect.mLeft)("top", rect.mTop)("right", rect.mRight)("bottom", rect.mBottom); + + // The intent of this test is to prevent trying to drill down to a + // widget in a hidden floater, or on a tab that's not current, etc. + if (! visible_chain) + { + return response.error(STRINGIZE(request["op"].asString() << " request " + "specified \"path\" not currently visible: '" + << path << "'")); + } + + // This test isn't folded in with the above error case since you can + // (e.g.) pop up a tooltip even for a disabled widget. + if (! enabled_chain) + { + response.warn(STRINGIZE(request["op"].asString() << " request " + "specified \"path\" not currently enabled: '" + << path << "'")); + } + + if (! has_pos) + { + pos.set(rect.getCenterX(), rect.getCenterY()); + // nonstandard warning tactic: probably usual case; we want event + // sender to know synthesized (x, y), but maybe don't need to log? + response["warnings"].append(STRINGIZE("using center point (" + << pos.mX << ", " << pos.mY << ")")); + } + + // recursive childFromPoint() should give us the frontmost, leafmost + // widget at the specified (x, y). + LLView* frontmost = root->childFromPoint(pos.mX, pos.mY, true); + if (frontmost != target) + { + response.warn(STRINGIZE(request["op"].asString() << " request " + "specified \"path\" = '" << path + << "', but frontmost LLView at (" << pos.mX << ", " << pos.mY + << ") is '" << frontmost->getPathname() << "'")); + } + + // Instantiate a TemporaryDrilldownFunc to route incoming mouse events + // to the target LLView*. But put it on the heap since "path" is + // optional. Nonetheless, manage it with a boost::scoped_ptr so it + // will be destroyed when we leave. + tempfunc.reset(new LLView::TemporaryDrilldownFunc(llview::TargetEvent(target))); + } + + // The question of whether the requested LLView actually handled the + // specified event is important enough, and its handling unclear enough, + // to warrant a separate response attribute. Instead of deciding here to + // make it a warning, or an error, let caller decide. + response["handled"] = func(pos, getMask(request)); + + // On exiting this scope, response will send, tempfunc will restore the + // normal pointInView(x, y) containment logic, etc. } -void LLWindowListener::mouseDown(LLSD const & evt) +void LLWindowListener::mouseDown(LLSD const & request) { - Actions actions(buttons.lookup(evt["button"])); + Actions actions(buttons.lookup(request["button"])); if (actions.valid) { - (mWindow->*(actions.down))(NULL, getPos(evt), getMask(evt)); + // Normally you can pass NULL to an LLWindow* without compiler + // complaint, but going through boost::lambda::bind() evidently + // bypasses that special case: it only knows you're trying to pass an + // int to a pointer. Explicitly cast NULL to the desired pointer type. + mouseEvent(bll::bind(actions.down, mWindow, + static_cast(NULL), bll::_1, bll::_2), + request); } } -void LLWindowListener::mouseUp(LLSD const & evt) +void LLWindowListener::mouseUp(LLSD const & request) { - Actions actions(buttons.lookup(evt["button"])); + Actions actions(buttons.lookup(request["button"])); if (actions.valid) { - (mWindow->*(actions.up))(NULL, getPos(evt), getMask(evt)); + mouseEvent(bll::bind(actions.up, mWindow, + static_cast(NULL), bll::_1, bll::_2), + request); } } -void LLWindowListener::mouseMove(LLSD const & evt) +void LLWindowListener::mouseMove(LLSD const & request) { - mWindow->handleMouseMove(NULL, getPos(evt), getMask(evt)); + // We want to call the same central mouseEvent() routine for + // handleMouseMove() as for button clicks. But handleMouseMove() returns + // void, whereas mouseEvent() accepts a function returning bool -- and + // uses that bool return. Use (void-lambda-expression, true) to construct + // a callable that returns bool anyway. Pass 'true' because we expect that + // our caller will usually treat 'false' as a problem. + mouseEvent((bll::bind(&LLWindowCallbacks::handleMouseMove, mWindow, + static_cast(NULL), bll::_1, bll::_2), + true), + request); } -void LLWindowListener::mouseScroll(LLSD const & evt) +void LLWindowListener::mouseScroll(LLSD const & request) { - S32 clicks = evt["clicks"].asInteger(); + S32 clicks = request["clicks"].asInteger(); mWindow->handleScrollWheel(NULL, clicks); } - -- cgit v1.2.3 From 12dbf4c7b4a7bf64acaa7207c8bceffb64f021b3 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Tue, 30 Aug 2011 11:30:51 -0400 Subject: CHOP-763: Add Windows magic precompiled header #include. --- indra/newview/llwindowlistener.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/newview') diff --git a/indra/newview/llwindowlistener.cpp b/indra/newview/llwindowlistener.cpp index 84126b7738..8d794e5380 100644 --- a/indra/newview/llwindowlistener.cpp +++ b/indra/newview/llwindowlistener.cpp @@ -24,6 +24,7 @@ * $/LicenseInfo$ */ +#include "llviewerprecompiledheaders.h" #include "linden_common.h" #include "llwindowlistener.h" -- cgit v1.2.3 From 713aa42f61d6d5791b26f56a73bd7cf7abb76f0d Mon Sep 17 00:00:00 2001 From: "Andrew A. de Laix" Date: Tue, 30 Aug 2011 13:37:10 -0500 Subject: add responses to key events. --- indra/newview/llwindowlistener.cpp | 142 ++++++++++++++++++++++--------------- 1 file changed, 85 insertions(+), 57 deletions(-) (limited to 'indra/newview') diff --git a/indra/newview/llwindowlistener.cpp b/indra/newview/llwindowlistener.cpp index 8d794e5380..84a490f661 100644 --- a/indra/newview/llwindowlistener.cpp +++ b/indra/newview/llwindowlistener.cpp @@ -134,6 +134,57 @@ protected: namespace { +class Response +{ +public: + Response(const LLSD& seed, const LLSD& request, const LLSD::String& replyKey="reply"): + mResp(seed), + mReq(request), + mKey(replyKey) + {} + + ~Response() + { + // When you instantiate a stack Response object, if the original + // request requested a reply, send it when we leave this block, no + // matter how. + sendReply(mResp, mReq, mKey); + } + + void warn(const std::string& warning) + { + LL_WARNS("LLWindowListener") << warning << LL_ENDL; + mResp["warnings"].append(warning); + } + + void error(const std::string& error) + { + // Use LL_WARNS rather than LL_ERROR: we don't want the viewer to shut + // down altogether. + LL_WARNS("LLWindowListener") << error << LL_ENDL; + + mResp["error"] = error; + } + + // set other keys... + LLSD& operator[](const LLSD::String& key) { return mResp[key]; } + + LLSD mResp, mReq; + LLSD::String mKey; +}; + +void insertViewInformation(Response & response, LLView * target) +{ + // Get info about this LLView* for when we send response. + response["path"] = target->getPathname(); + response["class"] = typeid(*target).name(); + response["visible"] = target->getVisible(); + response["visible_chain"] = target->isInVisibleChain(); + response["enabled"] = target->getEnabled(); + response["enabled_chain"] = target->isInEnabledChain(); + response["available"] = target->isAvailable(); +} + // helper for getMask() MASK lookupMask_(const std::string& maskname) { @@ -197,12 +248,22 @@ KEY getKEY(const LLSD& event) void LLWindowListener::keyDown(LLSD const & evt) { + Response response(LLSD(), evt); + if (evt.has("path")) { + std::string path(evt["path"]); LLView * target_view = - LLUI::resolvePath(gViewerWindow->getRootView(), evt["path"]); - if ((target_view != 0) && target_view->isAvailable()) + LLUI::resolvePath(gViewerWindow->getRootView(), path); + if (target_view == 0) + { + response.error(STRINGIZE(evt["op"].asString() << " request " + "specified invalid \"path\": '" << path << "'")); + } + else if(target_view->isAvailable()) { + insertViewInformation(response, target_view); + gFocusMgr.setKeyboardFocus(target_view); KEY key = getKEY(evt); MASK mask = getMask(evt); @@ -211,7 +272,9 @@ void LLWindowListener::keyDown(LLSD const & evt) } else { - ; // TODO: Don't silently fail if target not available. + response.error(STRINGIZE(evt["op"].asString() << " request " + "element specified byt \"path\": '" << path << "'" + << " is not visible")); } } else @@ -222,18 +285,30 @@ void LLWindowListener::keyDown(LLSD const & evt) void LLWindowListener::keyUp(LLSD const & evt) { + Response response(LLSD(), evt); + if (evt.has("path")) { + std::string path(evt["path"]); LLView * target_view = - LLUI::resolvePath(gViewerWindow->getRootView(), evt["path"]); - if ((target_view != 0) && target_view->isAvailable()) + LLUI::resolvePath(gViewerWindow->getRootView(), path); + if (target_view == 0 ) + { + response.error(STRINGIZE(evt["op"].asString() << " request " + "specified invalid \"path\": '" << path << "'")); + } + else if (target_view->isAvailable()) { + insertViewInformation(response, target_view); + gFocusMgr.setKeyboardFocus(target_view); mKbGetter()->handleTranslatedKeyUp(getKEY(evt), getMask(evt)); } else { - ; // TODO: Don't silently fail if target not available. + response.error(STRINGIZE(evt["op"].asString() << " request " + "element specified byt \"path\": '" << path << "'" + << " is not visible")); } } else @@ -266,44 +341,6 @@ struct WhichButton: public StringLookup }; static WhichButton buttons; -struct Response -{ - Response(const LLSD& seed, const LLSD& request, const LLSD::String& replyKey="reply"): - mResp(seed), - mReq(request), - mKey(replyKey) - {} - - ~Response() - { - // When you instantiate a stack Response object, if the original - // request requested a reply, send it when we leave this block, no - // matter how. - sendReply(mResp, mReq, mKey); - } - - void warn(const std::string& warning) - { - LL_WARNS("LLWindowListener") << warning << LL_ENDL; - mResp["warnings"].append(warning); - } - - void error(const std::string& error) - { - // Use LL_WARNS rather than LL_ERROR: we don't want the viewer to shut - // down altogether. - LL_WARNS("LLWindowListener") << error << LL_ENDL; - - mResp["error"] = error; - } - - // set other keys... - LLSD& operator[](const LLSD::String& key) { return mResp[key]; } - - LLSD mResp, mReq; - LLSD::String mKey; -}; - typedef boost::function MouseFunc; static void mouseEvent(const MouseFunc& func, const LLSD& request) @@ -340,19 +377,10 @@ static void mouseEvent(const MouseFunc& func, const LLSD& request) { return response.error(STRINGIZE(request["op"].asString() << " request " "specified invalid \"path\": '" << path << "'")); - return; } - // Get info about this LLView* for when we send response. - response["path"] = target->getPathname(); - response["class"] = typeid(*target).name(); - bool visible_chain(target->isInVisibleChain()); - bool enabled_chain(target->isInEnabledChain()); - response["visible"] = target->getVisible(); - response["visible_chain"] = visible_chain; - response["enabled"] = target->getEnabled(); - response["enabled_chain"] = enabled_chain; - response["available"] = target->isAvailable(); + insertViewInformation(response, target); + // Don't show caller the LLView's own relative rectangle; that only // tells its dimensions. Provide actual location on screen. LLRect rect(target->calcScreenRect()); @@ -360,7 +388,7 @@ static void mouseEvent(const MouseFunc& func, const LLSD& request) // The intent of this test is to prevent trying to drill down to a // widget in a hidden floater, or on a tab that's not current, etc. - if (! visible_chain) + if (! target->isInVisibleChain()) { return response.error(STRINGIZE(request["op"].asString() << " request " "specified \"path\" not currently visible: '" @@ -369,7 +397,7 @@ static void mouseEvent(const MouseFunc& func, const LLSD& request) // This test isn't folded in with the above error case since you can // (e.g.) pop up a tooltip even for a disabled widget. - if (! enabled_chain) + if (! target->isInEnabledChain()) { response.warn(STRINGIZE(request["op"].asString() << " request " "specified \"path\" not currently enabled: '" -- cgit v1.2.3 From 71aec7439c1a8027880ac06d99f923ab8fa7111b Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Tue, 30 Aug 2011 15:22:44 -0400 Subject: CHOP-763: Introduce static LLView::getPathname(LLView*). Use it for LLWindowListener to safely report an LLView* which might be NULL. --- indra/newview/llwindowlistener.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview') diff --git a/indra/newview/llwindowlistener.cpp b/indra/newview/llwindowlistener.cpp index 84a490f661..05cb798732 100644 --- a/indra/newview/llwindowlistener.cpp +++ b/indra/newview/llwindowlistener.cpp @@ -273,7 +273,7 @@ void LLWindowListener::keyDown(LLSD const & evt) else { response.error(STRINGIZE(evt["op"].asString() << " request " - "element specified byt \"path\": '" << path << "'" + "element specified by \"path\": '" << path << "'" << " is not visible")); } } @@ -421,7 +421,7 @@ static void mouseEvent(const MouseFunc& func, const LLSD& request) response.warn(STRINGIZE(request["op"].asString() << " request " "specified \"path\" = '" << path << "', but frontmost LLView at (" << pos.mX << ", " << pos.mY - << ") is '" << frontmost->getPathname() << "'")); + << ") is '" << LLView::getPathname(frontmost) << "'")); } // Instantiate a TemporaryDrilldownFunc to route incoming mouse events -- cgit v1.2.3 From 3ddf3aef9b2f2bb85932bd33b9daac5e59d3018a Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 1 Sep 2011 13:12:23 -0400 Subject: CHOP-763: Promote Response class from llwindowlistener.cpp to LLEventAPI. This is a generally-useful idiom, extending the sendReply() convenience function -- it shouldn't remain buried in a single .cpp file. --- indra/newview/llwindowlistener.cpp | 43 ++------------------------------------ 1 file changed, 2 insertions(+), 41 deletions(-) (limited to 'indra/newview') diff --git a/indra/newview/llwindowlistener.cpp b/indra/newview/llwindowlistener.cpp index 05cb798732..3e3287032c 100644 --- a/indra/newview/llwindowlistener.cpp +++ b/indra/newview/llwindowlistener.cpp @@ -134,46 +134,7 @@ protected: namespace { -class Response -{ -public: - Response(const LLSD& seed, const LLSD& request, const LLSD::String& replyKey="reply"): - mResp(seed), - mReq(request), - mKey(replyKey) - {} - - ~Response() - { - // When you instantiate a stack Response object, if the original - // request requested a reply, send it when we leave this block, no - // matter how. - sendReply(mResp, mReq, mKey); - } - - void warn(const std::string& warning) - { - LL_WARNS("LLWindowListener") << warning << LL_ENDL; - mResp["warnings"].append(warning); - } - - void error(const std::string& error) - { - // Use LL_WARNS rather than LL_ERROR: we don't want the viewer to shut - // down altogether. - LL_WARNS("LLWindowListener") << error << LL_ENDL; - - mResp["error"] = error; - } - - // set other keys... - LLSD& operator[](const LLSD::String& key) { return mResp[key]; } - - LLSD mResp, mReq; - LLSD::String mKey; -}; - -void insertViewInformation(Response & response, LLView * target) +void insertViewInformation(LLEventAPI::Response & response, LLView * target) { // Get info about this LLView* for when we send response. response["path"] = target->getPathname(); @@ -346,7 +307,7 @@ typedef boost::function MouseFunc; static void mouseEvent(const MouseFunc& func, const LLSD& request) { // Ensure we send response - Response response(LLSD(), request); + LLEventAPI::Response response(LLSD(), request); // We haven't yet established whether the incoming request has "x" and "y", // but capture this anyway, with 0 for omitted values. LLCoordGL pos(request["x"].asInteger(), request["y"].asInteger()); -- cgit v1.2.3 From 7215d1a9a9e6220d8744b662ab96feb41fc66ec8 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 1 Sep 2011 14:05:37 -0400 Subject: CHOP-763: Extend LLEventAPI "LLViewerControl" API; add queries. This is a significant refactoring of planned (but as yet unimplemented) work, though in fact it's almost completely compatible with the only implemented operation. The set() operation now requires op="set", where before that was inferred because set() was the only possibility. Whereas before LLViewerControlListener dispatched to different bound methods on the "group" key, with four known "group" string values, it now dispatches on the "op" key, supporting "set", "toggle", "get", "groups", "vars" -- the last two exposing query functionality. LLControlGroup is actually derived from LLInstanceTracker, keyed on string names, so we can look up instances using LLControlGroup::getInstance(const std::string&), or enumerate all such names. LLControlGroup similarly permits iterating over all defined LLControlVariables. The static LLViewerControlListener instance has been wrapped in an unnamed namespace and removed from llviewercontrollistener.h. The availability of the API depends on LLEventPumps::obtain(), rather than normal C++ visibility. --- indra/newview/llviewercontrollistener.cpp | 231 +++++++++++++++++++++--------- indra/newview/llviewercontrollistener.h | 10 +- 2 files changed, 169 insertions(+), 72 deletions(-) (limited to 'indra/newview') diff --git a/indra/newview/llviewercontrollistener.cpp b/indra/newview/llviewercontrollistener.cpp index 8bc25fa281..361b96221c 100644 --- a/indra/newview/llviewercontrollistener.cpp +++ b/indra/newview/llviewercontrollistener.cpp @@ -31,99 +31,196 @@ #include "llviewercontrollistener.h" #include "llviewercontrol.h" +#include "llcontrol.h" +#include "llerror.h" +#include "llsdutil.h" +#include "stringize.h" +#include -LLViewerControlListener gSavedSettingsListener; +namespace { + +LLViewerControlListener sSavedSettingsListener; + +} // unnamed namespace LLViewerControlListener::LLViewerControlListener() : LLEventAPI("LLViewerControl", - "LLViewerControl listener: set, toggle or set default for various controls", - "group") + "LLViewerControl listener: set, toggle or set default for various controls") { - add("Global", - "Set gSavedSettings control [\"key\"] to value [\"value\"]", - boost::bind(&LLViewerControlListener::set, &gSavedSettings, _1)); - add("PerAccount", - "Set gSavedPerAccountSettings control [\"key\"] to value [\"value\"]", - boost::bind(&LLViewerControlListener::set, &gSavedPerAccountSettings, _1)); - add("Warning", - "Set gWarningSettings control [\"key\"] to value [\"value\"]", - boost::bind(&LLViewerControlListener::set, &gWarningSettings, _1)); - add("Crash", - "Set gCrashSettings control [\"key\"] to value [\"value\"]", - boost::bind(&LLViewerControlListener::set, &gCrashSettings, _1)); - -#if 0 - add(/*"toggleControl",*/ "Global", boost::bind(&LLViewerControlListener::toggleControl, &gSavedSettings, _1)); - add(/*"toggleControl",*/ "PerAccount", boost::bind(&LLViewerControlListener::toggleControl, &gSavedPerAccountSettings, _1)); - add(/*"toggleControl",*/ "Warning", boost::bind(&LLViewerControlListener::toggleControl, &gWarningSettings, _1)); - add(/*"toggleControl",*/ "Crash", boost::bind(&LLViewerControlListener::toggleControl, &gCrashSettings, _1)); - - add(/*"setDefault",*/ "Global", boost::bind(&LLViewerControlListener::setDefault, &gSavedSettings, _1)); - add(/*"setDefault",*/ "PerAccount", boost::bind(&LLViewerControlListener::setDefault, &gSavedPerAccountSettings, _1)); - add(/*"setDefault",*/ "Warning", boost::bind(&LLViewerControlListener::setDefault, &gWarningSettings, _1)); - add(/*"setDefault",*/ "Crash", boost::bind(&LLViewerControlListener::setDefault, &gCrashSettings, _1)); -#endif // 0 + std::ostringstream groupnames; + groupnames << "[\"group\"] is one of "; + const char* delim = ""; + for (LLControlGroup::key_iter cgki(LLControlGroup::beginKeys()), + cgkend(LLControlGroup::endKeys()); + cgki != cgkend; ++cgki) + { + groupnames << delim << '"' << *cgki << '"'; + delim = ", "; + } + groupnames << '\n'; + std::string grouphelp(groupnames.str()); + std::string replyhelp("If [\"reply\"] requested, send new [\"value\"] on specified LLEventPump\n"); + + add("set", + std::string("Set [\"group\"] control [\"key\"] to optional value [\"value\"]\n" + "If [\"value\"] omitted, set to control's defined default value\n") + + grouphelp + replyhelp, + &LLViewerControlListener::set, + LLSDMap("group", LLSD())("key", LLSD())); + add("toggle", + std::string("Toggle [\"group\"] control [\"key\"], if boolean\n") + grouphelp + replyhelp, + &LLViewerControlListener::toggle, + LLSDMap("group", LLSD())("key", LLSD())); + add("get", + std::string("Query [\"group\"] control [\"key\"], replying on LLEventPump [\"reply\"]\n") + + grouphelp, + &LLViewerControlListener::get, + LLSDMap("group", LLSD())("key", LLSD())("reply", LLSD())); + add("groups", + "Send on LLEventPump [\"reply\"] an array [\"groups\"] of valid group names", + &LLViewerControlListener::groups, + LLSDMap("reply", LLSD())); + add("vars", + std::string("For [\"group\"], send on LLEventPump [\"reply\"] an array [\"vars\"],\n" + "each of whose entries looks like:\n" + " [\"name\"], [\"type\"], [\"value\"], [\"comment\"]\n") + grouphelp, + &LLViewerControlListener::vars, + LLSDMap("group", LLSD())("reply", LLSD())); } -//static -void LLViewerControlListener::set(LLControlGroup * controls, LLSD const & event_data) +struct Info { - if(event_data.has("key")) + Info(const LLSD& request): + response(LLSD(), request), + groupname(request["group"]), + group(LLControlGroup::getInstance(groupname)), + key(request["key"]), + control(NULL) { - std::string key(event_data["key"]); + if (! group) + { + response.error(STRINGIZE("Unrecognized group '" << groupname << "'")); + return; + } - if(controls->controlExists(key)) + control = group->getControl(key); + if (! control) { - controls->setUntypedValue(key, event_data["value"]); + response.error(STRINGIZE("In group '" << groupname + << "', unrecognized control key '" << key << "'")); } - else + } + + ~Info() + { + // If in fact the request passed to our constructor names a valid + // group and key, grab the final value of the indicated control and + // stuff it in our response. Since this outer destructor runs before + // the contained Response destructor, this data will go into the + // response we send. + if (control) { - llwarns << "requested unknown control: \"" << key << '\"' << llendl; + response["name"] = control->getName(); + response["type"] = group->typeEnumToString(control->type()); + response["value"] = control->get(); + response["comment"] = control->getComment(); } } + + LLEventAPI::Response response; + std::string groupname; + LLControlGroup* group; + std::string key; + LLControlVariable* control; +}; + +//static +void LLViewerControlListener::set(LLSD const & request) +{ + Info info(request); + if (! info.control) + return; + + if (request.has("value")) + { + info.control->setValue(request["value"]); + } + else + { + info.control->resetToDefault(); + } } //static -void LLViewerControlListener::toggleControl(LLControlGroup * controls, LLSD const & event_data) +void LLViewerControlListener::toggle(LLSD const & request) { - if(event_data.has("key")) + Info info(request); + if (! info.control) + return; + + if (info.control->isType(TYPE_BOOLEAN)) + { + info.control->set(! info.control->get().asBoolean()); + } + else { - std::string key(event_data["key"]); + info.response.error(STRINGIZE("toggle of non-boolean '" << info.groupname + << "' control '" << info.key + << "', type is " + << info.group->typeEnumToString(info.control->type()))); + } +} - if(controls->controlExists(key)) - { - LLControlVariable * control = controls->getControl(key); - if(control->isType(TYPE_BOOLEAN)) - { - control->set(!control->get().asBoolean()); - } - else - { - llwarns << "requested toggle of non-boolean control: \"" << key << "\", type is " << control->type() << llendl; - } - } - else - { - llwarns << "requested unknown control: \"" << key << '\"' << llendl; - } +void LLViewerControlListener::get(LLSD const & request) +{ + // The Info constructor and destructor actually do all the work here. + Info info(request); +} + +void LLViewerControlListener::groups(LLSD const & request) +{ + // No Info, we're not looking up either a group or a control name. + Response response(LLSD(), request); + for (LLControlGroup::key_iter cgki(LLControlGroup::beginKeys()), + cgkend(LLControlGroup::endKeys()); + cgki != cgkend; ++cgki) + { + response["groups"].append(*cgki); } } -//static -void LLViewerControlListener::setDefault(LLControlGroup * controls, LLSD const & event_data) +struct CollectVars: public LLControlGroup::ApplyFunctor { - if(event_data.has("key")) + CollectVars(LLControlGroup* g): + mGroup(g) + {} + + virtual void apply(const std::string& name, LLControlVariable* control) { - std::string key(event_data["key"]); + vars.append(LLSDMap + ("name", name) + ("type", mGroup->typeEnumToString(control->type())) + ("value", control->get()) + ("comment", control->getComment())); + } - if(controls->controlExists(key)) - { - LLControlVariable * control = controls->getControl(key); - control->resetToDefault(); - } - else - { - llwarns << "requested unknown control: \"" << key << '\"' << llendl; - } + LLControlGroup* mGroup; + LLSD vars; +}; + +void LLViewerControlListener::vars(LLSD const & request) +{ + // This method doesn't use Info, because we're not looking up a specific + // control name. + Response response(LLSD(), request); + std::string groupname(request["group"]); + LLControlGroup* group(LLControlGroup::getInstance(groupname)); + if (! group) + { + return response.error(STRINGIZE("Unrecognized group '" << groupname << "'")); } + + CollectVars collector(group); + group->applyToAll(&collector); + response["vars"] = collector.vars; } diff --git a/indra/newview/llviewercontrollistener.h b/indra/newview/llviewercontrollistener.h index fd211b97af..2e72046924 100644 --- a/indra/newview/llviewercontrollistener.h +++ b/indra/newview/llviewercontrollistener.h @@ -40,11 +40,11 @@ public: LLViewerControlListener(); private: - static void set(LLControlGroup *controls, LLSD const & event_data); - static void toggleControl(LLControlGroup *controls, LLSD const & event_data); - static void setDefault(LLControlGroup *controls, LLSD const & event_data); + static void set(LLSD const & event_data); + static void toggle(LLSD const & event_data); + static void get(LLSD const & event_data); + static void groups(LLSD const & event_data); + static void vars(LLSD const & event_data); }; -extern LLViewerControlListener gSavedSettingsListener; - #endif // LL_LLVIEWERCONTROLLISTENER_H -- cgit v1.2.3