llnotify.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /**
  2. * @file llnotify.h
  3. * @brief Non-blocking notification that doesn't take keyboard focus.
  4. *
  5. * $LicenseInfo:firstyear=2003&license=viewergpl$
  6. *
  7. * Copyright (c) 2003-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLNOTIFY_H
  33. #define LL_LLNOTIFY_H
  34. #include <map>
  35. #include <vector>
  36. #include "lleventtimer.h"
  37. #include "llinitdestroyclass.h"
  38. #include "llnotifications.h"
  39. #include "llpanel.h"
  40. class LLButton;
  41. class LLColor4U;
  42. class LLFrameTimer;
  43. class LLFontGL;
  44. class LLNotifyBoxView;
  45. class LLNotifyBoxTemplate;
  46. class LLTextEditor;
  47. class LLTimer;
  48. // NotifyBox - for notifications that require a response from the user.
  49. class LLNotifyBox final : public LLPanel, public LLEventTimer,
  50. public LLInitClass<LLNotifyBox>,
  51. public LLInstanceTracker<LLNotifyBox, LLUUID>
  52. {
  53. friend class LLNotifyBoxView;
  54. protected:
  55. LOG_CLASS(LLNotifyBox);
  56. public:
  57. typedef void (*notify_callback_t)(S32 option, void* data);
  58. typedef std::vector<std::string> option_list_t;
  59. static void initClass();
  60. static void destroyClass();
  61. LL_INLINE bool isTip() const { return mIsTip; }
  62. LL_INLINE bool isCaution() const { return mIsCaution; }
  63. LL_INLINE void stopAnimation() { mAnimating = false; }
  64. void close();
  65. LL_INLINE LLNotificationPtr getNotification() const { return mNotification; }
  66. // Used for callbacks
  67. struct CallbackData
  68. {
  69. LLNotifyBox* mSelf;
  70. std::string mButtonName;
  71. };
  72. typedef std::vector<CallbackData*> cb_data_vec_t;
  73. LL_INLINE const cb_data_vec_t& getCallbackData() { return mBtnCallbackData; }
  74. LL_INLINE bool isDefaultBtnAdded() { return mAddedDefaultBtn; }
  75. static void format(std::string& msg,
  76. const LLStringUtil::format_map_t& args);
  77. static void setShowNotifications(bool show);
  78. LL_INLINE static bool areNotificationsShown() { return sShowNotifications; }
  79. LL_INLINE static S32 getNotifyBoxCount() { return sNotifyBoxCount; }
  80. LL_INLINE static S32 getNotifyTipCount() { return sNotifyTipCount; }
  81. static void substituteSLURL(const LLUUID& id, const std::string& slurl,
  82. const std::string& substitute);
  83. static void substitutionDone(const LLUUID& id);
  84. // To avoid piling restart notifications, we close any old one when a new
  85. // one arrives, or when TPing or moving away from the restarting sim, which
  86. // this method allows to do (called from send_complete_agent_movement() in
  87. // llviewermessage.cpp).
  88. static void closeLastNotifyRestart();
  89. protected:
  90. LLNotifyBox(LLNotificationPtr notification, bool script_dialog,
  91. bool is_ours);
  92. ~LLNotifyBox() override;
  93. LLButton* addButton(const std::string& name, const std::string& label,
  94. bool is_option, bool is_default);
  95. bool handleMouseUp(S32 x, S32 y, MASK mask) override;
  96. bool handleRightMouseDown(S32 x, S32 y, MASK mask) override;
  97. // Animate as sliding onto the screen.
  98. void draw() override;
  99. bool tick() override;
  100. void moveToBack(bool getfocus = false);
  101. // Returns the rect, relative to gNotifyView, where this
  102. // notify box should be placed.
  103. static LLRect getNotifyRect(S32 num_options, bool layout_script_dialog,
  104. bool is_caution);
  105. static LLRect getNotifyTipRect(const std::string& message,
  106. LLFontGL* fontp);
  107. // Internal handler for button being clicked
  108. static void onClickButton(void* data);
  109. // For "next" button
  110. static void onClickNext(void* data);
  111. private:
  112. void drawBackground() const;
  113. static bool onNotification(const LLSD& notify);
  114. protected:
  115. LLNotificationPtr mNotification;
  116. LLTextEditor* mUserInputBox;
  117. LLTextEditor* mTextEditor;
  118. LLButton* mNextBtn;
  119. std::string mMessage;
  120. // Time since this notification was displayed.
  121. // This is an LLTimer not a frame timer because I am concerned
  122. // that I could be out-of-sync by one frame in the animation.
  123. LLTimer mAnimateTimer;
  124. LLFrameTimer mNotifyShowingTimer;
  125. S32 mNumOptions;
  126. S32 mNumButtons;
  127. LLColor4U mBackgroundColor;
  128. cb_data_vec_t mBtnCallbackData;
  129. bool mIsTip;
  130. bool mIsCaution; // true for a caution notif.
  131. bool mAnimating; // Are we sliding onscreen ?
  132. bool mLayoutScriptDialog;
  133. bool mIsFromOurObject;
  134. bool mAddedDefaultBtn;
  135. static S32 sNotifyBoxCount;
  136. static S32 sNotifyTipCount;
  137. static bool sShowNotifications;
  138. typedef std::map<std::string, LLNotifyBox*> unique_map_t;
  139. static unique_map_t sOpenUniqueNotifyBoxes;
  140. typedef std::multimap<LLUUID, LLUUID> name_lookup_map_t;
  141. static name_lookup_map_t sNameLookupMap;
  142. static LLUUID sLastNotifyRestartId;
  143. };
  144. class LLNotifyBoxView final : public LLUICtrl
  145. {
  146. public:
  147. LLNotifyBoxView(const std::string& name, const LLRect& rect,
  148. bool mouse_opaque, U32 follows = FOLLOWS_NONE);
  149. ~LLNotifyBoxView() override;
  150. void showOnly(LLView* ctrl);
  151. LLNotifyBox* getFirstNontipBox() const;
  152. class Matcher
  153. {
  154. public:
  155. Matcher() {}
  156. virtual ~Matcher() {}
  157. virtual bool matches(const LLNotificationPtr) const = 0;
  158. };
  159. // Walks the list and removes any stacked messages for which the given
  160. // matcher returns true.
  161. // Useful when muting people and things in order to clear out any similar
  162. // previously queued messages.
  163. void purgeMessagesMatching(const Matcher& matcher);
  164. private:
  165. bool isGroupNotifyBox(const LLView* view) const;
  166. };
  167. // This view contains the stack of notification windows.
  168. extern LLNotifyBoxView* gNotifyBoxViewp;
  169. #endif