PageRenderTime 325ms CodeModel.GetById 172ms app.highlight 11ms RepoModel.GetById 140ms app.codeStats 0ms

/indra/newview/llscriptfloater.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 213 lines | 77 code | 54 blank | 82 comment | 0 complexity | 01703334a40efe09acfe5eac894c6b97 MD5 | raw file
  1/** 
  2 * @file llscriptfloater.h
  3 * @brief LLScriptFloater class definition
  4 *
  5 * $LicenseInfo:firstyear=2009&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_SCRIPTFLOATER_H
 28#define LL_SCRIPTFLOATER_H
 29
 30#include "lltransientdockablefloater.h"
 31#include "llnotificationptr.h"
 32
 33class LLToastPanel;
 34
 35/**
 36 * Handles script notifications ("ScriptDialog" and "ScriptDialogGroup")
 37 * and manages Script Floaters.
 38 */
 39class LLScriptFloaterManager : public LLSingleton<LLScriptFloaterManager>
 40{
 41	// *TODO
 42	// LLScriptFloaterManager and LLScriptFloater will need some refactoring after we 
 43	// know how script notifications should look like.
 44public:
 45
 46	typedef enum e_object_type
 47	{
 48		OBJ_SCRIPT,
 49		OBJ_GIVE_INVENTORY,
 50		OBJ_LOAD_URL,
 51
 52		OBJ_UNKNOWN
 53	}EObjectType;
 54
 55	/**
 56	 * Handles new notifications.
 57	 * Saves notification and object ids, removes old notification if needed, creates script chiclet
 58	 * Note that one object can spawn one script floater.
 59	 */
 60	void onAddNotification(const LLUUID& notification_id);
 61
 62	/**
 63	 * Removes notification.
 64	 */
 65	void removeNotification(const LLUUID& notification_id);
 66
 67	/**
 68	 * Handles notification removal.
 69	 * Removes script notification toast, removes script chiclet, closes script floater
 70	 */
 71	void onRemoveNotification(const LLUUID& notification_id);
 72
 73	/**
 74	 * Toggles script floater.
 75	 * Removes "new message" icon from chiclet and removes notification toast.
 76	 */
 77	void toggleScriptFloater(const LLUUID& object_id, bool set_new_message = false);
 78
 79	LLUUID findObjectId(const LLUUID& notification_id);
 80
 81	LLUUID findNotificationId(const LLUUID& object_id);
 82
 83	static EObjectType getObjectType(const LLUUID& notification_id);
 84
 85	static std::string getObjectName(const LLUUID& notification_id);
 86
 87	typedef boost::signals2::signal<void(const LLSD&)> object_signal_t;
 88
 89	boost::signals2::connection addNewObjectCallback(const object_signal_t::slot_type& cb) { return mNewObjectSignal.connect(cb); }
 90	boost::signals2::connection addToggleObjectFloaterCallback(const object_signal_t::slot_type& cb) { return mToggleFloaterSignal.connect(cb); }
 91
 92	struct FloaterPositionInfo
 93	{
 94		LLRect mRect;
 95		bool mDockState;
 96	};
 97
 98	void saveFloaterPosition(const LLUUID& object_id, const FloaterPositionInfo& fpi);
 99
100	bool getFloaterPosition(const LLUUID& object_id, FloaterPositionInfo& fpi);
101
102	void setFloaterVisible(const LLUUID& notification_id, bool visible);
103
104protected:
105
106	typedef std::map<std::string, EObjectType> object_type_map;
107
108	static object_type_map initObjectTypeMap();
109
110	// <notification_id, object_id>
111	typedef std::map<LLUUID, LLUUID> script_notification_map_t;
112
113	script_notification_map_t::const_iterator findUsingObjectId(const LLUUID& object_id);
114
115private:
116
117	script_notification_map_t mNotifications;
118
119	object_signal_t mNewObjectSignal;
120	object_signal_t mToggleFloaterSignal;
121
122	// <object_id, floater position>
123	typedef std::map<LLUUID, FloaterPositionInfo> floater_position_map_t;
124
125	floater_position_map_t mFloaterPositions;
126};
127
128/**
129 * Floater script forms.
130 * LLScriptFloater will create script form based on notification data and 
131 * will auto fit the form.
132 */
133class LLScriptFloater : public LLDockableFloater
134{
135public:
136
137	/**
138	 * key - UUID of scripted Object
139	 */
140	LLScriptFloater(const LLSD& key);
141
142	virtual ~LLScriptFloater(){};
143
144	/**
145	 * Toggle existing floater or create and show a new one.
146	 */
147	static bool toggle(const LLUUID& object_id);
148
149	/**
150	 * Creates and shows floater
151	 */
152	static LLScriptFloater* show(const LLUUID& object_id);
153
154	const LLUUID& getNotificationId() { return mNotificationId; }
155
156	void setNotificationId(const LLUUID& id);
157
158	/**
159	 * Close notification if script floater is closed.
160	 */
161	/*virtual*/ void onClose(bool app_quitting);
162
163	/**
164	 * Hide all notification toasts when we show dockable floater
165	 */
166	/*virtual*/ void setDocked(bool docked, bool pop_on_undock = true);
167
168	/**
169	 * Hide all notification toasts when we show dockable floater
170	 */
171	/*virtual*/ void setVisible(BOOL visible);
172
173	bool getSavePosition() { return mSaveFloaterPosition; }
174
175	void setSavePosition(bool save) { mSaveFloaterPosition = save; }
176
177	void savePosition();
178
179	void restorePosition();
180
181protected:
182
183	/**
184	 * Creates script form, will delete old form if floater is shown for same object.
185	 */
186	void createForm(const LLUUID& object_id);
187
188	/**
189	 * Hide all notification toasts.
190	 */
191	static void hideToastsIfNeeded();
192
193	/**
194	 * Removes chiclets new messages icon
195	 */
196	void onMouseDown();
197
198	/*virtual*/ void onFocusLost();
199	
200	/*virtual*/ void onFocusReceived();
201
202	void dockToChiclet(bool dock);
203
204private:
205	bool isScriptTextbox(LLNotificationPtr notification);
206
207	LLToastPanel* mScriptForm;
208	LLUUID mNotificationId;
209	LLUUID mObjectId;
210	bool mSaveFloaterPosition;
211};
212
213#endif //LL_SCRIPTFLOATER_H