PageRenderTime 31ms CodeModel.GetById 2ms app.highlight 24ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/lltooldraganddrop.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 287 lines | 193 code | 40 blank | 54 comment | 0 complexity | 172301fdd94b5aa4667455541eca1699 MD5 | raw file
  1/** 
  2 * @file lltooldraganddrop.h
  3 * @brief LLToolDragAndDrop class header file
  4 *
  5 * $LicenseInfo:firstyear=2001&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_TOOLDRAGANDDROP_H
 28#define LL_TOOLDRAGANDDROP_H
 29
 30#include "lldictionary.h"
 31#include "lltool.h"
 32#include "llview.h"
 33#include "lluuid.h"
 34#include "stdenums.h"
 35#include "llassetstorage.h"
 36#include "lldarray.h"
 37#include "llpermissions.h"
 38#include "llwindow.h"
 39#include "llviewerinventory.h"
 40
 41class LLToolDragAndDrop;
 42class LLViewerRegion;
 43class LLVOAvatar;
 44class LLPickInfo;
 45
 46class LLToolDragAndDrop : public LLTool, public LLSingleton<LLToolDragAndDrop>
 47{
 48public:
 49	typedef boost::signals2::signal<void ()> enddrag_signal_t;
 50
 51	LLToolDragAndDrop();
 52
 53	// overridden from LLTool
 54	virtual BOOL	handleMouseUp(S32 x, S32 y, MASK mask);
 55	virtual BOOL	handleHover(S32 x, S32 y, MASK mask);
 56	virtual BOOL	handleKey(KEY key, MASK mask);
 57	virtual BOOL	handleToolTip(S32 x, S32 y, MASK mask);
 58	virtual void	onMouseCaptureLost();
 59	virtual void	handleDeselect();
 60
 61	void			setDragStart( S32 x, S32 y );			// In screen space
 62	BOOL			isOverThreshold( S32 x, S32 y );		// In screen space
 63
 64	enum ESource
 65	{
 66		SOURCE_AGENT,
 67		SOURCE_WORLD,
 68		SOURCE_NOTECARD,
 69		SOURCE_LIBRARY,
 70		SOURCE_VIEWER
 71	};
 72
 73	void beginDrag(EDragAndDropType type,
 74				   const LLUUID& cargo_id,
 75				   ESource source,
 76				   const LLUUID& source_id = LLUUID::null,
 77				   const LLUUID& object_id = LLUUID::null);
 78	void beginMultiDrag(const std::vector<EDragAndDropType> types,
 79						const uuid_vec_t& cargo_ids,
 80						ESource source,
 81						const LLUUID& source_id = LLUUID::null);
 82	void endDrag();
 83	ESource getSource() const { return mSource; }
 84	const LLUUID& getSourceID() const { return mSourceID; }
 85	const LLUUID& getObjectID() const { return mObjectID; }
 86	EAcceptance getLastAccept() { return mLastAccept; }
 87
 88	boost::signals2::connection setEndDragCallback( const enddrag_signal_t::slot_type& cb ) { return mEndDragSignal.connect(cb); }
 89	
 90	uuid_vec_t::size_type getCargoIDsCount() const { return mCargoIDs.size(); }
 91	static S32 getOperationId() { return sOperationId; }
 92
 93protected:
 94	enum EDropTarget
 95	{
 96		DT_NONE = 0,
 97		DT_SELF = 1,
 98		DT_AVATAR = 2,
 99		DT_OBJECT = 3,
100		DT_LAND = 4,
101		DT_COUNT = 5
102	};
103
104protected:
105	// dragOrDrop3dImpl points to a member of LLToolDragAndDrop that
106	// takes parameters (LLViewerObject* obj, S32 face, MASK, BOOL
107	// drop) and returns a BOOL if drop is ok
108	typedef EAcceptance (LLToolDragAndDrop::*dragOrDrop3dImpl)
109		(LLViewerObject*, S32, MASK, BOOL);
110
111	void dragOrDrop(S32 x, S32 y, MASK mask, BOOL drop,
112					EAcceptance* acceptance);
113	void dragOrDrop3D(S32 x, S32 y, MASK mask, BOOL drop,
114					  EAcceptance* acceptance);
115	
116	static void pickCallback(const LLPickInfo& pick_info);
117	void pick(const LLPickInfo& pick_info);
118
119protected:
120
121	S32				mDragStartX;
122	S32				mDragStartY;
123	
124	std::vector<EDragAndDropType> mCargoTypes;
125	//void*			mCargoData;
126	uuid_vec_t mCargoIDs;
127	ESource mSource;
128	LLUUID mSourceID;
129	LLUUID mObjectID;
130
131	static S32		sOperationId;
132
133	LLVector3d		mLastCameraPos;
134	LLVector3d		mLastHitPos;
135
136	ECursorType		mCursor;
137	EAcceptance		mLastAccept;
138	BOOL			mDrop;
139	S32				mCurItemIndex;
140	std::string		mToolTipMsg;
141
142	enddrag_signal_t	mEndDragSignal;
143
144protected:
145	// 3d drop functions. these call down into the static functions
146	// named drop<ThingToDrop> if drop is TRUE and permissions allow
147	// that behavior.
148	EAcceptance dad3dNULL(LLViewerObject*, S32, MASK, BOOL);
149	EAcceptance dad3dRezObjectOnLand(LLViewerObject* obj, S32 face,
150									 MASK mask, BOOL drop);
151	EAcceptance dad3dRezObjectOnObject(LLViewerObject* obj, S32 face,
152									   MASK mask, BOOL drop);
153	EAcceptance dad3dRezScript(LLViewerObject* obj, S32 face,
154							   MASK mask, BOOL drop);
155	EAcceptance dad3dTextureObject(LLViewerObject* obj, S32 face,
156								   MASK mask, BOOL drop);
157	EAcceptance dad3dMeshObject(LLViewerObject* obj, S32 face,
158								   MASK mask, BOOL drop);
159//	EAcceptance dad3dTextureSelf(LLViewerObject* obj, S32 face,
160//								 MASK mask, BOOL drop);
161	EAcceptance dad3dWearItem(LLViewerObject* obj, S32 face,
162								 MASK mask, BOOL drop);
163	EAcceptance dad3dWearCategory(LLViewerObject* obj, S32 face,
164								 MASK mask, BOOL drop);
165	EAcceptance dad3dUpdateInventory(LLViewerObject* obj, S32 face,
166									 MASK mask, BOOL drop);
167	EAcceptance dad3dUpdateInventoryCategory(LLViewerObject* obj,
168											 S32 face,
169											 MASK mask,
170											 BOOL drop);
171	EAcceptance dad3dGiveInventoryObject(LLViewerObject* obj, S32 face,
172								   MASK mask, BOOL drop);
173	EAcceptance dad3dGiveInventory(LLViewerObject* obj, S32 face,
174								   MASK mask, BOOL drop);
175	EAcceptance dad3dGiveInventoryCategory(LLViewerObject* obj, S32 face,
176										   MASK mask, BOOL drop);
177	EAcceptance dad3dRezFromObjectOnLand(LLViewerObject* obj, S32 face,
178										 MASK mask, BOOL drop);
179	EAcceptance dad3dRezFromObjectOnObject(LLViewerObject* obj, S32 face,
180										   MASK mask, BOOL drop);
181	EAcceptance dad3dRezAttachmentFromInv(LLViewerObject* obj, S32 face,
182										  MASK mask, BOOL drop);
183	EAcceptance dad3dCategoryOnLand(LLViewerObject *obj, S32 face,
184									MASK mask, BOOL drop);
185	EAcceptance dad3dAssetOnLand(LLViewerObject *obj, S32 face,
186								 MASK mask, BOOL drop);
187	EAcceptance dad3dActivateGesture(LLViewerObject *obj, S32 face,
188								 MASK mask, BOOL drop);
189
190	// helper called by methods above to handle "application" of an item
191	// to an object (texture applied to face, mesh applied to shape, etc.)
192	EAcceptance dad3dApplyToObject(LLViewerObject* obj, S32 face, MASK mask, BOOL drop, EDragAndDropType cargo_type);
193		
194	
195	// set the LLToolDragAndDrop's cursor based on the given acceptance
196	ECursorType acceptanceToCursor( EAcceptance acceptance );
197
198	// This method converts mCargoID to an inventory item or
199	// folder. If no item or category is found, both pointers will be
200	// returned NULL.
201	LLInventoryObject* locateInventory(LLViewerInventoryItem*& item,
202									   LLViewerInventoryCategory*& cat);
203
204	//LLInventoryObject* locateMultipleInventory(
205	//	LLViewerInventoryCategory::cat_array_t& cats,
206	//	LLViewerInventoryItem::item_array_t& items);
207
208	void dropObject(LLViewerObject* raycast_target,
209			BOOL bypass_sim_raycast,
210			BOOL from_task_inventory,
211			BOOL remove_from_inventory);
212	
213	// accessor that looks at permissions, copyability, and names of
214	// inventory items to determine if a drop would be ok.
215	static EAcceptance willObjectAcceptInventory(LLViewerObject* obj, LLInventoryItem* item);
216
217	// deal with permissions of object, etc. returns TRUE if drop can
218	// proceed, otherwise FALSE.
219	static BOOL handleDropTextureProtections(LLViewerObject* hit_obj,
220						 LLInventoryItem* item,
221						 LLToolDragAndDrop::ESource source,
222						 const LLUUID& src_id);
223
224public:
225	// helper functions
226	static BOOL isInventoryDropAcceptable(LLViewerObject* obj, LLInventoryItem* item) { return (ACCEPT_YES_COPY_SINGLE <= willObjectAcceptInventory(obj, item)); }
227
228	BOOL dadUpdateInventory(LLViewerObject* obj, BOOL drop);
229	BOOL dadUpdateInventoryCategory(LLViewerObject* obj, BOOL drop);
230
231	// methods that act on the simulator state.
232	static void dropScript(LLViewerObject* hit_obj,
233						   LLInventoryItem* item,
234						   BOOL active,
235						   ESource source,
236						   const LLUUID& src_id);
237	static void dropTextureOneFace(LLViewerObject* hit_obj, S32 hit_face,
238								   LLInventoryItem* item,
239								   ESource source,
240								   const LLUUID& src_id);
241	static void dropTextureAllFaces(LLViewerObject* hit_obj,
242									LLInventoryItem* item,
243									ESource source,
244									const LLUUID& src_id);
245	static void dropMesh(LLViewerObject* hit_obj,
246						 LLInventoryItem* item,
247						 ESource source,
248						 const LLUUID& src_id);
249	
250	//static void	dropTextureOneFaceAvatar(LLVOAvatar* avatar,S32 hit_face,
251	//									 LLInventoryItem* item)
252
253	static void dropInventory(LLViewerObject* hit_obj,
254							  LLInventoryItem* item,
255							  ESource source,
256							  const LLUUID& src_id);
257
258	static bool handleGiveDragAndDrop(LLUUID agent, LLUUID session, BOOL drop,
259									  EDragAndDropType cargo_type,
260									  void* cargo_data,
261									  EAcceptance* accept,
262									  const LLSD& dest = LLSD());
263
264	// Classes used for determining 3d drag and drop types.
265private:
266	struct DragAndDropEntry : public LLDictionaryEntry
267	{
268		DragAndDropEntry(dragOrDrop3dImpl f_none,
269						 dragOrDrop3dImpl f_self,
270						 dragOrDrop3dImpl f_avatar,
271						 dragOrDrop3dImpl f_object,
272						 dragOrDrop3dImpl f_land);
273		dragOrDrop3dImpl mFunctions[DT_COUNT];
274	};	
275	class LLDragAndDropDictionary : public LLSingleton<LLDragAndDropDictionary>,
276									public LLDictionary<EDragAndDropType, DragAndDropEntry>
277	{
278	public:
279		LLDragAndDropDictionary();
280		dragOrDrop3dImpl get(EDragAndDropType dad_type, EDropTarget drop_target);
281	};
282};
283
284// utility functions
285void pack_permissions_slam(LLMessageSystem* msg, U32 flags, const LLPermissions& perms);
286
287#endif  // LL_TOOLDRAGANDDROP_H