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