PageRenderTime 133ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/lltoast.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 245 lines | 128 code | 54 blank | 63 comment | 0 complexity | d21e1570aa6eb325b1c4d577ca97901c MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lltoast.h
  3. * @brief This class implements a placeholder for any notification panel.
  4. *
  5. * $LicenseInfo:firstyear=2003&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_LLTOAST_H
  27. #define LL_LLTOAST_H
  28. #include "llinstancetracker.h"
  29. #include "llpanel.h"
  30. #include "llmodaldialog.h"
  31. #include "lleventtimer.h"
  32. #include "llnotificationptr.h"
  33. #include "llviewercontrol.h"
  34. #include "lltexteditor.h"
  35. #define MOUSE_LEAVE false
  36. #define MOUSE_ENTER true
  37. namespace LLNotificationsUI
  38. {
  39. class LLToast;
  40. /**
  41. * Timer for toasts.
  42. */
  43. class LLToastLifeTimer: public LLEventTimer
  44. {
  45. public:
  46. LLToastLifeTimer(LLToast* toast, F32 period);
  47. /*virtual*/
  48. BOOL tick();
  49. void stop();
  50. void start();
  51. void restart();
  52. BOOL getStarted();
  53. void setPeriod(F32 period);
  54. F32 getRemainingTimeF32();
  55. LLTimer& getEventTimer() { return mEventTimer;}
  56. private :
  57. LLToast* mToast;
  58. };
  59. /**
  60. * Represents toast pop-up.
  61. * This is a parent view for all toast panels.
  62. */
  63. class LLToast : public LLModalDialog, public LLInstanceTracker<LLToast>
  64. {
  65. friend class LLToastLifeTimer;
  66. public:
  67. typedef boost::function<void (LLToast* toast)> toast_callback_t;
  68. typedef boost::signals2::signal<void (LLToast* toast)> toast_signal_t;
  69. struct Params : public LLInitParam::Block<Params>
  70. {
  71. Mandatory<LLPanel*> panel;
  72. Optional<LLUUID> notif_id, //notification ID
  73. session_id; //im session ID
  74. Optional<LLNotificationPtr> notification;
  75. //NOTE: Life time of a toast (i.e. period of time from the moment toast was shown
  76. //till the moment when toast was hidden) is the sum of lifetime_secs and fading_time_secs.
  77. Optional<F32> lifetime_secs, // Number of seconds while a toast is non-transparent
  78. fading_time_secs; // Number of seconds while a toast is transparent
  79. Optional<toast_callback_t> on_delete_toast;
  80. Optional<bool> can_fade,
  81. can_be_stored,
  82. enable_hide_btn,
  83. is_modal,
  84. is_tip,
  85. force_show,
  86. force_store;
  87. Params();
  88. };
  89. static void updateClass();
  90. LLToast(const LLToast::Params& p);
  91. virtual ~LLToast();
  92. BOOL postBuild();
  93. /*virtual*/ void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
  94. // Toast handlers
  95. virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask);
  96. //Fading
  97. /** Stop lifetime/fading timer */
  98. virtual void stopTimer();
  99. /** Start lifetime/fading timer */
  100. virtual void startTimer();
  101. bool isHovered() { return mIsHovered; }
  102. // Operating with toasts
  103. // insert a panel to a toast
  104. void insertPanel(LLPanel* panel);
  105. void reshapeToPanel();
  106. // get toast's panel
  107. LLPanel* getPanel() { return mPanel; }
  108. // enable/disable Toast's Hide button
  109. void setHideButtonEnabled(bool enabled);
  110. //
  111. F32 getTimeLeftToLive();
  112. //
  113. LLToastLifeTimer* getTimer() { return mTimer.get();}
  114. //
  115. virtual void draw();
  116. //
  117. virtual void setVisible(BOOL show);
  118. /*virtual*/ void setBackgroundOpaque(BOOL b);
  119. //
  120. virtual void hide();
  121. /*virtual*/ void onFocusLost();
  122. /*virtual*/ void onFocusReceived();
  123. void setLifetime(S32 seconds);
  124. void setFadingTime(S32 seconds);
  125. /**
  126. * Returns padding between floater top and wrapper_panel top.
  127. * This padding should be taken into account when positioning or reshaping toasts
  128. */
  129. S32 getTopPad();
  130. S32 getRightPad();
  131. // get/set Toast's flags or states
  132. // get information whether the notification corresponding to the toast is valid or not
  133. bool isNotificationValid();
  134. // get toast's Notification ID
  135. const LLUUID getNotificationID() { return mNotificationID;}
  136. // get toast's Session ID
  137. const LLUUID getSessionID() { return mSessionID;}
  138. //
  139. void setCanFade(bool can_fade);
  140. //
  141. void setCanBeStored(bool can_be_stored) { mCanBeStored = can_be_stored; }
  142. //
  143. bool getCanBeStored() { return mCanBeStored; }
  144. // set whether this toast considered as hidden or not
  145. void setIsHidden( bool is_toast_hidden ) { mIsHidden = is_toast_hidden; }
  146. const LLNotificationPtr& getNotification() { return mNotification;}
  147. // Registers signals/callbacks for events
  148. toast_signal_t mOnFadeSignal;
  149. toast_signal_t mOnDeleteToastSignal;
  150. toast_signal_t mOnToastDestroyedSignal;
  151. boost::signals2::connection setOnFadeCallback(toast_callback_t cb) { return mOnFadeSignal.connect(cb); }
  152. boost::signals2::connection setOnToastDestroyedCallback(toast_callback_t cb) { return mOnToastDestroyedSignal.connect(cb); }
  153. typedef boost::function<void (LLToast* toast, bool mouse_enter)> toast_hover_check_callback_t;
  154. typedef boost::signals2::signal<void (LLToast* toast, bool mouse_enter)> toast_hover_check_signal_t;
  155. toast_hover_check_signal_t mOnToastHoverSignal;
  156. boost::signals2::connection setOnToastHoverCallback(toast_hover_check_callback_t cb) { return mOnToastHoverSignal.connect(cb); }
  157. boost::signals2::connection setMouseEnterCallback( const commit_signal_t::slot_type& cb ) { return mToastMouseEnterSignal.connect(cb); };
  158. boost::signals2::connection setMouseLeaveCallback( const commit_signal_t::slot_type& cb ) { return mToastMouseLeaveSignal.connect(cb); };
  159. virtual S32 notifyParent(const LLSD& info);
  160. LLHandle<LLToast> getHandle() const { return getDerivedHandle<LLToast>(); }
  161. protected:
  162. void updateTransparency();
  163. private:
  164. void updateHoveredState();
  165. void expire();
  166. void setFading(bool fading);
  167. LLUUID mNotificationID;
  168. LLUUID mSessionID;
  169. LLNotificationPtr mNotification;
  170. //LLRootHandle<LLToast> mHandle;
  171. LLPanel* mWrapperPanel;
  172. // timer counts a lifetime of a toast
  173. std::auto_ptr<LLToastLifeTimer> mTimer;
  174. F32 mToastLifetime; // in seconds
  175. F32 mToastFadingTime; // in seconds
  176. LLPanel* mPanel;
  177. LLButton* mHideBtn;
  178. LLColor4 mBgColor;
  179. bool mCanFade;
  180. bool mCanBeStored;
  181. bool mHideBtnEnabled;
  182. bool mHideBtnPressed;
  183. bool mIsHidden; // this flag is TRUE when a toast has faded or was hidden with (x) button (EXT-1849)
  184. bool mIsTip;
  185. bool mIsFading;
  186. bool mIsHovered;
  187. commit_signal_t mToastMouseEnterSignal;
  188. commit_signal_t mToastMouseLeaveSignal;
  189. };
  190. }
  191. #endif