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

/indra/newview/llscreenchannel.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 304 lines | 158 code | 63 blank | 83 comment | 4 complexity | c191123e87cb54d19bc7b6ea0e9db0bb MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llscreenchannel.h
  3. * @brief Class implements a channel on a screen in which appropriate toasts may appear.
  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_LLSCREENCHANNEL_H
  27. #define LL_LLSCREENCHANNEL_H
  28. #include "lltoast.h"
  29. #include <map>
  30. #include <boost/shared_ptr.hpp>
  31. namespace LLNotificationsUI
  32. {
  33. typedef enum e_notification_toast_alignment
  34. {
  35. NA_TOP,
  36. NA_CENTRE,
  37. NA_BOTTOM,
  38. } EToastAlignment;
  39. typedef enum e_channel_alignment
  40. {
  41. CA_LEFT,
  42. CA_CENTRE,
  43. CA_RIGHT,
  44. } EChannelAlignment;
  45. class LLScreenChannelBase : public LLUICtrl
  46. {
  47. friend class LLChannelManager;
  48. public:
  49. struct Params : public LLInitParam::Block<Params, LLUICtrl::Params>
  50. {
  51. Mandatory<LLUUID> id;
  52. Optional<bool> display_toasts_always;
  53. Optional<EToastAlignment> toast_align;
  54. Optional<EChannelAlignment> channel_align;
  55. Params()
  56. : id("id", LLUUID("")),
  57. display_toasts_always("display_toasts_always", false),
  58. toast_align("toast_align", NA_BOTTOM),
  59. channel_align("channel_align", CA_LEFT)
  60. {}
  61. };
  62. LLScreenChannelBase(const Params&);
  63. BOOL postBuild();
  64. void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
  65. // Channel's outfit-functions
  66. // update channel's size and position in the World View
  67. virtual void updatePositionAndSize(LLRect rect);
  68. // initialization of channel's shape and position
  69. virtual void init(S32 channel_left, S32 channel_right);
  70. // kill or modify a toast by its ID
  71. virtual void killToastByNotificationID(LLUUID id) {};
  72. virtual void modifyToastNotificationByID(LLUUID id, LLSD data) {};
  73. // hide all toasts from screen, but not remove them from a channel
  74. virtual void hideToastsFromScreen() {};
  75. // removes all toasts from a channel
  76. virtual void removeToastsFromChannel() {};
  77. // show all toasts in a channel
  78. virtual void redrawToasts() {};
  79. // Channel's behavior-functions
  80. // set whether a channel will control hovering inside itself or not
  81. virtual void setControlHovering(bool control) { mControlHovering = control; }
  82. bool isHovering();
  83. void setCanStoreToasts(bool store) { mCanStoreToasts = store; }
  84. bool getDisplayToastsAlways() { return mDisplayToastsAlways; }
  85. // get number of hidden notifications from a channel
  86. S32 getNumberOfHiddenToasts() { return mHiddenToastsNum;}
  87. void setShowToasts(bool show) { mShowToasts = show; }
  88. bool getShowToasts() { return mShowToasts; }
  89. // get toast allignment preset for a channel
  90. e_notification_toast_alignment getToastAlignment() {return mToastAlignment;}
  91. // get ID of a channel
  92. LLUUID getChannelID() { return mID; }
  93. LLHandle<LLScreenChannelBase> getHandle() { mRootHandle.bind(this); return mRootHandle; }
  94. protected:
  95. void updateRect();
  96. LLRect getChannelRect();
  97. // Channel's flags
  98. bool mControlHovering;
  99. LLToast* mHoveredToast;
  100. bool mCanStoreToasts;
  101. bool mDisplayToastsAlways;
  102. // controls whether a channel shows toasts or not
  103. bool mShowToasts;
  104. LLRootHandle<LLScreenChannelBase> mRootHandle;
  105. //
  106. EToastAlignment mToastAlignment;
  107. EChannelAlignment mChannelAlignment;
  108. S32 mHiddenToastsNum;
  109. // channel's ID
  110. LLUUID mID;
  111. LLView* mFloaterSnapRegion;
  112. LLView* mChicletRegion;
  113. };
  114. /**
  115. * Screen channel manages toasts visibility and positioning on the screen.
  116. */
  117. class LLScreenChannel : public LLScreenChannelBase
  118. {
  119. friend class LLChannelManager;
  120. public:
  121. LLScreenChannel(const Params&);
  122. virtual ~LLScreenChannel();
  123. class Matcher
  124. {
  125. public:
  126. Matcher(){}
  127. virtual ~Matcher() {}
  128. virtual bool matches(const LLNotificationPtr) const = 0;
  129. };
  130. std::list<LLToast*> findToasts(const Matcher& matcher);
  131. // Channel's outfit-functions
  132. // update channel's size and position in the World View
  133. void updatePositionAndSize(LLRect new_rect);
  134. // initialization of channel's shape and position
  135. void init(S32 channel_left, S32 channel_right);
  136. // Operating with toasts
  137. // add a toast to a channel
  138. void addToast(const LLToast::Params& p);
  139. // kill or modify a toast by its ID
  140. void killToastByNotificationID(LLUUID id);
  141. void killMatchedToasts(const Matcher& matcher);
  142. void modifyToastByNotificationID(LLUUID id, LLPanel* panel);
  143. // hide all toasts from screen, but not remove them from a channel
  144. void hideToastsFromScreen();
  145. // hide toast by notification id
  146. void hideToast(const LLUUID& notification_id);
  147. /**
  148. * Closes hidden matched toasts from channel.
  149. */
  150. void closeHiddenToasts(const Matcher& matcher);
  151. // removes all toasts from a channel
  152. void removeToastsFromChannel();
  153. // show all toasts in a channel
  154. void redrawToasts();
  155. //
  156. void loadStoredToastsToChannel();
  157. // finds a toast among stored by its Notification ID and throws it on a screen to a channel
  158. void loadStoredToastByNotificationIDToChannel(LLUUID id);
  159. // removes a toast from stored finding it by its Notification ID
  160. void removeStoredToastByNotificationID(LLUUID id);
  161. // removes from channel all toasts that belongs to the certain IM session
  162. void removeToastsBySessionID(LLUUID id);
  163. // remove all storable toasts from screen and store them
  164. void removeAndStoreAllStorableToasts();
  165. // close the StartUp Toast
  166. void closeStartUpToast();
  167. /** Stop fading given toast */
  168. virtual void stopToastTimer(LLToast* toast);
  169. /** Start fading given toast */
  170. virtual void startToastTimer(LLToast* toast);
  171. // get StartUp Toast's state
  172. static bool getStartUpToastShown() { return mWasStartUpToastShown; }
  173. // tell all channels that the StartUp toast was shown and allow them showing of toasts
  174. static void setStartUpToastShown() { mWasStartUpToastShown = true; }
  175. // let a channel update its ShowToast flag
  176. void updateShowToastsState();
  177. // Channel's other interface functions functions
  178. // update number of notifications in the StartUp Toast
  179. void updateStartUpString(S32 num);
  180. LLToast* getToastByNotificationID(LLUUID id);
  181. // Channel's signals
  182. // signal on storing of faded toasts event
  183. typedef boost::function<void (LLPanel* info_panel, const LLUUID id)> store_tost_callback_t;
  184. typedef boost::signals2::signal<void (LLPanel* info_panel, const LLUUID id)> store_tost_signal_t;
  185. store_tost_signal_t mOnStoreToast;
  186. boost::signals2::connection setOnStoreToastCallback(store_tost_callback_t cb) { return mOnStoreToast.connect(cb); }
  187. // signal on rejecting of a toast event
  188. typedef boost::function<void (LLUUID id)> reject_tost_callback_t;
  189. typedef boost::signals2::signal<void (LLUUID id)> reject_tost_signal_t;
  190. reject_tost_signal_t mRejectToastSignal; boost::signals2::connection setOnRejectToastCallback(reject_tost_callback_t cb) { return mRejectToastSignal.connect(cb); }
  191. private:
  192. struct ToastElem
  193. {
  194. LLUUID id;
  195. LLToast* toast;
  196. ToastElem(LLToast::Params p) : id(p.notif_id)
  197. {
  198. toast = new LLToast(p);
  199. }
  200. ToastElem(const ToastElem& toast_elem)
  201. {
  202. id = toast_elem.id;
  203. toast = toast_elem.toast;
  204. }
  205. bool operator == (const LLUUID &id_op) const
  206. {
  207. return (id == id_op);
  208. }
  209. bool operator == (LLPanel* panel_op) const
  210. {
  211. return (toast == panel_op);
  212. }
  213. };
  214. // Channel's handlers
  215. void onToastHover(LLToast* toast, bool mouse_enter);
  216. void onToastFade(LLToast* toast);
  217. void onToastDestroyed(LLToast* toast);
  218. void onStartUpToastHide();
  219. //
  220. void storeToast(ToastElem& toast_elem);
  221. // send signal to observers about destroying of a toast, update channel's Hovering state, close the toast
  222. void deleteToast(LLToast* toast);
  223. // show-functions depending on allignment of toasts
  224. void showToastsBottom();
  225. void showToastsCentre();
  226. void showToastsTop();
  227. // create the StartUp Toast
  228. void createStartUpToast(S32 notif_num, F32 timer);
  229. /**
  230. * Notification channel and World View ratio(0.0 - always show 1 notification, 1.0 - max ratio).
  231. */
  232. static F32 getHeightRatio();
  233. // Channel's flags
  234. static bool mWasStartUpToastShown;
  235. // attributes for the StartUp Toast
  236. LLToast* mStartUpToastPanel;
  237. std::vector<ToastElem> mToastList;
  238. std::vector<ToastElem> mStoredToastList;
  239. };
  240. }
  241. #endif