PageRenderTime 56ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llui/llfloaterreglistener.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 156 lines | 100 code | 10 blank | 46 comment | 5 complexity | a2f429cc9763073181dc4f23acc0d90e MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llfloaterreglistener.cpp
  3. * @author Nat Goodspeed
  4. * @date 2009-08-12
  5. * @brief Implementation for llfloaterreglistener.
  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 "linden_common.h"
  30. // associated header
  31. #include "llfloaterreglistener.h"
  32. // STL headers
  33. // std headers
  34. // external library headers
  35. // other Linden headers
  36. #include "llfloaterreg.h"
  37. #include "llfloater.h"
  38. #include "llbutton.h"
  39. LLFloaterRegListener::LLFloaterRegListener():
  40. LLEventAPI("LLFloaterReg",
  41. "LLFloaterReg listener to (e.g.) show/hide LLFloater instances")
  42. {
  43. add("getBuildMap",
  44. "Return on [\"reply\"] data about all registered LLFloaterReg floater names",
  45. &LLFloaterRegListener::getBuildMap,
  46. LLSD().with("reply", LLSD()));
  47. LLSD requiredName;
  48. requiredName["name"] = LLSD();
  49. add("showInstance",
  50. "Ask to display the floater specified in [\"name\"]",
  51. &LLFloaterRegListener::showInstance,
  52. requiredName);
  53. add("hideInstance",
  54. "Ask to hide the floater specified in [\"name\"]",
  55. &LLFloaterRegListener::hideInstance,
  56. requiredName);
  57. add("toggleInstance",
  58. "Ask to toggle the state of the floater specified in [\"name\"]",
  59. &LLFloaterRegListener::toggleInstance,
  60. requiredName);
  61. add("instanceVisible",
  62. "Return on [\"reply\"] an event whose [\"visible\"] indicates the visibility "
  63. "of the floater specified in [\"name\"]",
  64. &LLFloaterRegListener::instanceVisible,
  65. requiredName);
  66. LLSD requiredNameButton;
  67. requiredNameButton["name"] = LLSD();
  68. requiredNameButton["button"] = LLSD();
  69. add("clickButton",
  70. "Simulate clicking the named [\"button\"] in the visible floater named in [\"name\"]",
  71. &LLFloaterRegListener::clickButton,
  72. requiredNameButton);
  73. }
  74. void LLFloaterRegListener::getBuildMap(const LLSD& event) const
  75. {
  76. LLSD reply;
  77. // Build an LLSD map that mirrors sBuildMap. Since we have no good way to
  78. // represent a C++ callable in LLSD, the only part of BuildData we can
  79. // store is the filename. For each LLSD map entry, it would be more
  80. // extensible to store a nested LLSD map containing a single key "file" --
  81. // but we don't bother, simply storing the string filename instead.
  82. for (LLFloaterReg::build_map_t::const_iterator mi(LLFloaterReg::sBuildMap.begin()),
  83. mend(LLFloaterReg::sBuildMap.end());
  84. mi != mend; ++mi)
  85. {
  86. reply[mi->first] = mi->second.mFile;
  87. }
  88. // Send the reply to the LLEventPump named in event["reply"].
  89. sendReply(reply, event);
  90. }
  91. void LLFloaterRegListener::showInstance(const LLSD& event) const
  92. {
  93. LLFloaterReg::showInstance(event["name"], event["key"], event["focus"]);
  94. }
  95. void LLFloaterRegListener::hideInstance(const LLSD& event) const
  96. {
  97. LLFloaterReg::hideInstance(event["name"], event["key"]);
  98. }
  99. void LLFloaterRegListener::toggleInstance(const LLSD& event) const
  100. {
  101. LLFloaterReg::toggleInstance(event["name"], event["key"]);
  102. }
  103. void LLFloaterRegListener::instanceVisible(const LLSD& event) const
  104. {
  105. sendReply(LLSDMap("visible", LLFloaterReg::instanceVisible(event["name"], event["key"])),
  106. event);
  107. }
  108. void LLFloaterRegListener::clickButton(const LLSD& event) const
  109. {
  110. // If the caller requests a reply, build the reply.
  111. LLReqID reqID(event);
  112. LLSD reply(reqID.makeResponse());
  113. LLFloater* floater = LLFloaterReg::findInstance(event["name"], event["key"]);
  114. if (! LLFloater::isShown(floater))
  115. {
  116. reply["type"] = "LLFloater";
  117. reply["name"] = event["name"];
  118. reply["key"] = event["key"];
  119. reply["error"] = floater? "!isShown()" : "NULL";
  120. }
  121. else
  122. {
  123. // Here 'floater' points to an LLFloater instance with the specified
  124. // name and key which isShown().
  125. LLButton* button = floater->findChild<LLButton>(event["button"]);
  126. if (! LLButton::isAvailable(button))
  127. {
  128. reply["type"] = "LLButton";
  129. reply["name"] = event["button"];
  130. reply["error"] = button? "!isAvailable()" : "NULL";
  131. }
  132. else
  133. {
  134. // Here 'button' points to an isAvailable() LLButton child of
  135. // 'floater' with the specified button name. Pretend to click it.
  136. button->onCommit();
  137. // Leave reply["error"] isUndefined(): no error, i.e. success.
  138. }
  139. }
  140. // Send a reply only if caller asked for a reply.
  141. LLSD replyPump(event["reply"]);
  142. if (replyPump.isString()) // isUndefined() if absent
  143. {
  144. LLEventPumps::instance().obtain(replyPump).post(reply);
  145. }
  146. }