PageRenderTime 30ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llscriptfloater.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 213 lines | 77 code | 54 blank | 82 comment | 0 complexity | 01703334a40efe09acfe5eac894c6b97 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llscriptfloater.h
  3. * @brief LLScriptFloater class definition
  4. *
  5. * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_SCRIPTFLOATER_H
  27. #define LL_SCRIPTFLOATER_H
  28. #include "lltransientdockablefloater.h"
  29. #include "llnotificationptr.h"
  30. class LLToastPanel;
  31. /**
  32. * Handles script notifications ("ScriptDialog" and "ScriptDialogGroup")
  33. * and manages Script Floaters.
  34. */
  35. class LLScriptFloaterManager : public LLSingleton<LLScriptFloaterManager>
  36. {
  37. // *TODO
  38. // LLScriptFloaterManager and LLScriptFloater will need some refactoring after we
  39. // know how script notifications should look like.
  40. public:
  41. typedef enum e_object_type
  42. {
  43. OBJ_SCRIPT,
  44. OBJ_GIVE_INVENTORY,
  45. OBJ_LOAD_URL,
  46. OBJ_UNKNOWN
  47. }EObjectType;
  48. /**
  49. * Handles new notifications.
  50. * Saves notification and object ids, removes old notification if needed, creates script chiclet
  51. * Note that one object can spawn one script floater.
  52. */
  53. void onAddNotification(const LLUUID& notification_id);
  54. /**
  55. * Removes notification.
  56. */
  57. void removeNotification(const LLUUID& notification_id);
  58. /**
  59. * Handles notification removal.
  60. * Removes script notification toast, removes script chiclet, closes script floater
  61. */
  62. void onRemoveNotification(const LLUUID& notification_id);
  63. /**
  64. * Toggles script floater.
  65. * Removes "new message" icon from chiclet and removes notification toast.
  66. */
  67. void toggleScriptFloater(const LLUUID& object_id, bool set_new_message = false);
  68. LLUUID findObjectId(const LLUUID& notification_id);
  69. LLUUID findNotificationId(const LLUUID& object_id);
  70. static EObjectType getObjectType(const LLUUID& notification_id);
  71. static std::string getObjectName(const LLUUID& notification_id);
  72. typedef boost::signals2::signal<void(const LLSD&)> object_signal_t;
  73. boost::signals2::connection addNewObjectCallback(const object_signal_t::slot_type& cb) { return mNewObjectSignal.connect(cb); }
  74. boost::signals2::connection addToggleObjectFloaterCallback(const object_signal_t::slot_type& cb) { return mToggleFloaterSignal.connect(cb); }
  75. struct FloaterPositionInfo
  76. {
  77. LLRect mRect;
  78. bool mDockState;
  79. };
  80. void saveFloaterPosition(const LLUUID& object_id, const FloaterPositionInfo& fpi);
  81. bool getFloaterPosition(const LLUUID& object_id, FloaterPositionInfo& fpi);
  82. void setFloaterVisible(const LLUUID& notification_id, bool visible);
  83. protected:
  84. typedef std::map<std::string, EObjectType> object_type_map;
  85. static object_type_map initObjectTypeMap();
  86. // <notification_id, object_id>
  87. typedef std::map<LLUUID, LLUUID> script_notification_map_t;
  88. script_notification_map_t::const_iterator findUsingObjectId(const LLUUID& object_id);
  89. private:
  90. script_notification_map_t mNotifications;
  91. object_signal_t mNewObjectSignal;
  92. object_signal_t mToggleFloaterSignal;
  93. // <object_id, floater position>
  94. typedef std::map<LLUUID, FloaterPositionInfo> floater_position_map_t;
  95. floater_position_map_t mFloaterPositions;
  96. };
  97. /**
  98. * Floater script forms.
  99. * LLScriptFloater will create script form based on notification data and
  100. * will auto fit the form.
  101. */
  102. class LLScriptFloater : public LLDockableFloater
  103. {
  104. public:
  105. /**
  106. * key - UUID of scripted Object
  107. */
  108. LLScriptFloater(const LLSD& key);
  109. virtual ~LLScriptFloater(){};
  110. /**
  111. * Toggle existing floater or create and show a new one.
  112. */
  113. static bool toggle(const LLUUID& object_id);
  114. /**
  115. * Creates and shows floater
  116. */
  117. static LLScriptFloater* show(const LLUUID& object_id);
  118. const LLUUID& getNotificationId() { return mNotificationId; }
  119. void setNotificationId(const LLUUID& id);
  120. /**
  121. * Close notification if script floater is closed.
  122. */
  123. /*virtual*/ void onClose(bool app_quitting);
  124. /**
  125. * Hide all notification toasts when we show dockable floater
  126. */
  127. /*virtual*/ void setDocked(bool docked, bool pop_on_undock = true);
  128. /**
  129. * Hide all notification toasts when we show dockable floater
  130. */
  131. /*virtual*/ void setVisible(BOOL visible);
  132. bool getSavePosition() { return mSaveFloaterPosition; }
  133. void setSavePosition(bool save) { mSaveFloaterPosition = save; }
  134. void savePosition();
  135. void restorePosition();
  136. protected:
  137. /**
  138. * Creates script form, will delete old form if floater is shown for same object.
  139. */
  140. void createForm(const LLUUID& object_id);
  141. /**
  142. * Hide all notification toasts.
  143. */
  144. static void hideToastsIfNeeded();
  145. /**
  146. * Removes chiclets new messages icon
  147. */
  148. void onMouseDown();
  149. /*virtual*/ void onFocusLost();
  150. /*virtual*/ void onFocusReceived();
  151. void dockToChiclet(bool dock);
  152. private:
  153. bool isScriptTextbox(LLNotificationPtr notification);
  154. LLToastPanel* mScriptForm;
  155. LLUUID mNotificationId;
  156. LLUUID mObjectId;
  157. bool mSaveFloaterPosition;
  158. };
  159. #endif //LL_SCRIPTFLOATER_H