PageRenderTime 29ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/lluilistener.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 101 lines | 49 code | 9 blank | 43 comment | 2 complexity | b6f3049e47e3ad8958a9b2d39eaa9357 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lluilistener.cpp
  3. * @author Nat Goodspeed
  4. * @date 2009-08-18
  5. * @brief Implementation for lluilistener.
  6. *
  7. * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  8. * Second Life Viewer Source Code
  9. * Copyright (C) 2010, Linden Research, Inc.
  10. *
  11. * This library is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation;
  14. * version 2.1 of the License only.
  15. *
  16. * This library is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public
  22. * License along with this library; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. *
  25. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  26. * $/LicenseInfo$
  27. */
  28. // Precompiled header
  29. #include "llviewerprecompiledheaders.h"
  30. // associated header
  31. #include "lluilistener.h"
  32. // STL headers
  33. // std headers
  34. // external library headers
  35. // other Linden headers
  36. #include "llui.h" // getRootView(), resolvePath()
  37. #include "lluictrl.h"
  38. #include "llerror.h"
  39. LLUIListener::LLUIListener():
  40. LLEventAPI("UI",
  41. "LLUICtrl::CommitCallbackRegistry listener.\n"
  42. "Capable of invoking any function (with parameter) you can specify in XUI.")
  43. {
  44. add("call",
  45. "Invoke the operation named by [\"function\"], passing [\"parameter\"],\n"
  46. "as if from a user gesture on a menu -- or a button click.",
  47. &LLUIListener::call,
  48. LLSD().with("function", LLSD()));
  49. add("getValue",
  50. "For the UI control identified by the path in [\"path\"], return the control's\n"
  51. "current value as [\"value\"] reply.",
  52. &LLUIListener::getValue,
  53. LLSDMap("path", LLSD())("reply", LLSD()));
  54. }
  55. void LLUIListener::call(const LLSD& event) const
  56. {
  57. LLUICtrl::commit_callback_t* func =
  58. LLUICtrl::CommitCallbackRegistry::getValue(event["function"]);
  59. if (! func)
  60. {
  61. // This API is intended for use by a script. It's a fire-and-forget
  62. // API: we provide no reply. Therefore, a typo in the script will
  63. // provide no feedback whatsoever to that script. To rub the coder's
  64. // nose in such an error, crump rather than quietly ignoring it.
  65. LL_ERRS("LLUIListener") << "function '" << event["function"] << "' not found" << LL_ENDL;
  66. }
  67. else
  68. {
  69. // Interestingly, view_listener_t::addMenu() (addCommit(),
  70. // addEnable()) constructs a commit_callback_t callable that accepts
  71. // two parameters but discards the first. Only the second is passed to
  72. // handleEvent(). Therefore we feel completely safe passing NULL for
  73. // the first parameter.
  74. (*func)(NULL, event["parameter"]);
  75. }
  76. }
  77. void LLUIListener::getValue(const LLSD&event) const
  78. {
  79. LLSD reply = LLSD::emptyMap();
  80. const LLView* root = LLUI::getRootView();
  81. const LLView* view = LLUI::resolvePath(root, event["path"].asString());
  82. const LLUICtrl* ctrl(dynamic_cast<const LLUICtrl*>(view));
  83. if (ctrl)
  84. {
  85. reply["value"] = ctrl->getValue();
  86. }
  87. else
  88. {
  89. // *TODO: ??? return something indicating failure to resolve
  90. }
  91. sendReply(reply, event);
  92. }