PageRenderTime 830ms CodeModel.GetById 523ms app.highlight 16ms RepoModel.GetById 185ms app.codeStats 1ms

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