lltooldraganddrop.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /**
  2. * @file lltooldraganddrop.h
  3. * @brief LLToolDragAndDrop class header file
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_TOOLDRAGANDDROP_H
  33. #define LL_TOOLDRAGANDDROP_H
  34. #include "llassetstorage.h"
  35. #include "lldictionary.h"
  36. #include "llpermissions.h"
  37. #include "lltool.h"
  38. #include "lluuid.h"
  39. #include "llview.h"
  40. #include "llviewerinventory.h"
  41. #include "llwindow.h"
  42. class LLToolDragAndDrop;
  43. class LLViewerRegion;
  44. class LLVOAvatar;
  45. class LLPickInfo;
  46. class LLToolDragAndDrop final : public LLTool
  47. {
  48. protected:
  49. LOG_CLASS(LLToolDragAndDrop);
  50. public:
  51. LLToolDragAndDrop();
  52. // Overridden from LLTool
  53. bool handleMouseUp(S32 x, S32 y, MASK mask) override;
  54. bool handleHover(S32 x, S32 y, MASK mask) override;
  55. bool handleKey(KEY key, MASK mask) override;
  56. bool handleToolTip(S32 x, S32 y, std::string& msg, LLRect* rect) override;
  57. void onMouseCaptureLost() override;
  58. void handleDeselect() override;
  59. LL_INLINE void setDragStart(S32 x, S32 y) // In screen space
  60. {
  61. mDragStartX = x;
  62. mDragStartY = y;
  63. }
  64. bool isOverThreshold(S32 x, S32 y); // In screen space
  65. enum ESource
  66. {
  67. SOURCE_AGENT,
  68. SOURCE_WORLD,
  69. SOURCE_NOTECARD,
  70. SOURCE_LIBRARY
  71. };
  72. void beginDrag(EDragAndDropType type, const LLUUID& cargo_id,
  73. ESource src, const LLUUID& src_id = LLUUID::null,
  74. const LLUUID& object_id = LLUUID::null);
  75. void beginMultiDrag(const std::vector<EDragAndDropType> types,
  76. const std::vector<LLUUID>& cargo_ids,
  77. ESource src, const LLUUID& src_id = LLUUID::null);
  78. void endDrag();
  79. LL_INLINE ESource getSource() const { return mSource; }
  80. LL_INLINE const LLUUID& getSourceID() const { return mSourceID; }
  81. LL_INLINE const LLUUID& getObjectID() const { return mObjectID; }
  82. LL_INLINE EAcceptance getLastAccept() { return mLastAccept; }
  83. LL_INLINE U32 getCargoCount() const { return mCargoIDs.size(); }
  84. LL_INLINE S32 getCargoIndex() const { return mCurItemIndex; }
  85. protected:
  86. enum EDropTarget
  87. {
  88. DT_NONE = 0,
  89. DT_SELF = 1,
  90. DT_AVATAR = 2,
  91. DT_OBJECT = 3,
  92. DT_LAND = 4,
  93. DT_COUNT = 5
  94. };
  95. // dragOrDrop3dImpl points to a member of LLToolDragAndDrop that
  96. // takes parameters (LLViewerObject* objp, S32 face, MASK, bool
  97. // drop) and returns a bool if drop is ok
  98. typedef EAcceptance (LLToolDragAndDrop::*dragOrDrop3dImpl)(LLViewerObject*,
  99. S32, MASK,
  100. bool);
  101. void dragOrDrop(S32 x, S32 y, MASK mask, bool drop,
  102. EAcceptance* acceptance);
  103. void dragOrDrop3D(S32 x, S32 y, MASK mask, bool drop,
  104. EAcceptance* acceptance);
  105. static void pickCallback(const LLPickInfo& pick_info);
  106. protected:
  107. // 3d drop functions. these call down into the static functions named
  108. // drop<ThingToDrop> if drop is true and permissions allow that behavior.
  109. EAcceptance dad3dNULL(LLViewerObject*, S32, MASK, bool);
  110. EAcceptance dad3dRezObjectOnLand(LLViewerObject* objp, S32 face,
  111. MASK mask, bool drop);
  112. EAcceptance dad3dRezObjectOnObject(LLViewerObject* objp, S32 face,
  113. MASK mask, bool drop);
  114. EAcceptance dad3dRezCategoryOnObject(LLViewerObject* objp, S32 face,
  115. MASK mask, bool drop);
  116. EAcceptance dad3dRezScript(LLViewerObject* objp, S32 face,
  117. MASK mask, bool drop);
  118. EAcceptance dad3dTextureObject(LLViewerObject* objp, S32 face,
  119. MASK mask, bool drop);
  120. EAcceptance dad3dMaterialObject(LLViewerObject* objp, S32 face,
  121. MASK mask, bool drop);
  122. #if LL_MESH_ASSET_SUPPORT
  123. EAcceptance dad3dMeshObject(LLViewerObject* objp, S32 face,
  124. MASK mask, bool drop);
  125. #endif
  126. EAcceptance dad3dWearItem(LLViewerObject* obj, S32 face,
  127. MASK mask, bool drop);
  128. EAcceptance dad3dWearCategory(LLViewerObject* objp, S32 face,
  129. MASK mask, bool drop);
  130. EAcceptance dad3dUpdateInventory(LLViewerObject* objp, S32 face,
  131. MASK mask, bool drop);
  132. EAcceptance dad3dUpdateInventoryCategory(LLViewerObject* objp, S32 face,
  133. MASK mask, bool drop);
  134. EAcceptance dad3dGiveInventoryObject(LLViewerObject* objp, S32 face,
  135. MASK mask, bool drop);
  136. EAcceptance dad3dGiveInventory(LLViewerObject* objp, S32 face,
  137. MASK mask, bool drop);
  138. EAcceptance dad3dGiveInventoryCategory(LLViewerObject* objp, S32 face,
  139. MASK mask, bool drop);
  140. EAcceptance dad3dRezFromObjectOnLand(LLViewerObject* objp, S32 face,
  141. MASK mask, bool drop);
  142. EAcceptance dad3dRezFromObjectOnObject(LLViewerObject* objp, S32 face,
  143. MASK mask, bool drop);
  144. EAcceptance dad3dRezAttachmentFromInv(LLViewerObject* objp, S32 face,
  145. MASK mask, bool drop);
  146. EAcceptance dad3dCategoryOnLand(LLViewerObject* objp, S32 face,
  147. MASK mask, bool drop);
  148. EAcceptance dad3dAssetOnLand(LLViewerObject* objp, S32 face,
  149. MASK mask, bool drop);
  150. EAcceptance dad3dActivateGesture(LLViewerObject* objp, S32 face,
  151. MASK mask, bool drop);
  152. // Helper called by methods above to handle "application" of an item to an
  153. // object (texture applied to face, mesh applied to shape, etc.)
  154. EAcceptance dad3dApplyToObject(LLViewerObject* objp, S32 face, MASK mask,
  155. bool drop, EDragAndDropType cargo_type);
  156. // Sets the LLToolDragAndDrop's cursor based on the given acceptance
  157. ECursorType acceptanceToCursor(EAcceptance acceptance);
  158. // This method converts mCargoID to an inventory item or folder. If no item
  159. // or category is found, both pointers will be returned NULL.
  160. LLInventoryObject* locateInventory(LLViewerInventoryItem*& itemp,
  161. LLViewerInventoryCategory*& catp);
  162. void dropObject(LLViewerObject* raycast_target, bool bypass_sim_raycast,
  163. bool from_task_inventory, bool remove_from_inventory);
  164. // Accessor that looks at permissions, copyability, and names of inventory
  165. // items to determine if a drop would be ok.
  166. static EAcceptance willObjectAcceptInventory(LLViewerObject* objp,
  167. LLInventoryItem* itemp,
  168. EDragAndDropType type =
  169. DAD_NONE);
  170. // Gives inventory item functionality
  171. static bool handleCopyProtectedItem(const LLSD& notification,
  172. const LLSD& response);
  173. static void commitGiveInventoryItem(const LLUUID& to_agent,
  174. LLInventoryItem* itemp,
  175. const LLUUID& im_session_id =
  176. LLUUID::null);
  177. // Gives inventory category functionality
  178. static bool handleCopyProtectedCategory(const LLSD& notification,
  179. const LLSD& response);
  180. static void commitGiveInventoryCategory(const LLUUID& to_agent,
  181. LLInventoryCategory* catp,
  182. const LLUUID& im_session_id =
  183. LLUUID::null);
  184. public:
  185. // Deals with permissions of object, etc. returns true if drop can
  186. // proceed, otherwise false.
  187. static bool handleDropAssetProtections(LLViewerObject* objp,
  188. LLInventoryItem* itemp,
  189. ESource source,
  190. const LLUUID& src_id =
  191. LLUUID::null);
  192. // Helper method
  193. LL_INLINE static bool isInventoryDropAcceptable(LLViewerObject* objp,
  194. LLInventoryItem* itemp)
  195. {
  196. return willObjectAcceptInventory(objp, itemp) >=
  197. ACCEPT_YES_COPY_SINGLE;
  198. }
  199. // This simple helper function assumes you are attempting to
  200. // transfer item. returns true if you can give, otherwise false.
  201. static bool isInventoryGiveAcceptable(LLInventoryItem* itemp);
  202. static bool isInventoryGroupGiveAcceptable(LLInventoryItem* itemp);
  203. bool dadUpdateInventory(LLViewerObject* objp, bool drop);
  204. bool dadUpdateInventoryCategory(LLViewerObject* objp, bool drop);
  205. // Methods that act on the simulator state.
  206. static void dropTextureOneFace(LLViewerObject* hit_objp, S32 hit_face,
  207. LLInventoryItem* itemp, ESource source,
  208. const LLUUID& src_id = LLUUID::null);
  209. static void dropTextureAllFaces(LLViewerObject* hit_objp,
  210. LLInventoryItem* itemp, ESource source,
  211. const LLUUID& src_id = LLUUID::null);
  212. static void dropMaterialOneFace(LLViewerObject* hit_objp, S32 hit_face,
  213. LLInventoryItem* itemp, ESource source,
  214. const LLUUID& src_id = LLUUID::null);
  215. static void dropMaterialAllFaces(LLViewerObject* hit_objp,
  216. LLInventoryItem* itemp, ESource source,
  217. const LLUUID& src_id = LLUUID::null);
  218. static void dropScript(LLViewerObject* hit_objp, LLInventoryItem* itemp,
  219. bool active, ESource source, const LLUUID& src_id);
  220. #if LL_MESH_ASSET_SUPPORT
  221. static void dropMesh(LLViewerObject* hit_objp, LLInventoryItem* itemp,
  222. ESource source, const LLUUID& src_id);
  223. #endif
  224. static void dropInventory(LLViewerObject* hit_objp, LLInventoryItem* itemp,
  225. ESource source,
  226. const LLUUID& src_id = LLUUID::null);
  227. static void giveInventory(const LLUUID& to_agent, LLInventoryItem* itemp,
  228. const LLUUID& session_id = LLUUID::null);
  229. static void giveInventoryCategory(const LLUUID& to_agent,
  230. LLInventoryCategory* catp,
  231. const LLUUID& session_id = LLUUID::null);
  232. static bool handleGiveDragAndDrop(const LLUUID& agent, const LLUUID& session,
  233. bool drop, EDragAndDropType cargo_type,
  234. void* cargo_data, EAcceptance* acceptp);
  235. // Classes used for determining 3d drag and drop types.
  236. private:
  237. struct DragAndDropEntry : public LLDictionaryEntry
  238. {
  239. DragAndDropEntry(dragOrDrop3dImpl f_none,
  240. dragOrDrop3dImpl f_self,
  241. dragOrDrop3dImpl f_avatar,
  242. dragOrDrop3dImpl f_object,
  243. dragOrDrop3dImpl f_land);
  244. dragOrDrop3dImpl mFunctions[DT_COUNT];
  245. };
  246. class LLDragAndDropDictionary : public LLSingleton<LLDragAndDropDictionary>,
  247. public LLDictionary<EDragAndDropType, DragAndDropEntry>
  248. {
  249. public:
  250. LLDragAndDropDictionary();
  251. dragOrDrop3dImpl get(EDragAndDropType dad_type,
  252. EDropTarget drop_target);
  253. };
  254. protected:
  255. LLUUID mSourceID;
  256. LLUUID mObjectID;
  257. std::vector<LLUUID> mCargoIDs;
  258. std::vector<EDragAndDropType> mCargoTypes;
  259. LLVector3d mLastCameraPos;
  260. LLVector3d mLastHitPos;
  261. std::string mToolTipMsg;
  262. S32 mCurItemIndex;
  263. S32 mDragStartX;
  264. S32 mDragStartY;
  265. ESource mSource;
  266. ECursorType mCursor;
  267. EAcceptance mLastAccept;
  268. bool mDrop;
  269. };
  270. // Utility function
  271. void pack_permissions_slam(LLMessageSystem* msg, U32 flags,
  272. const LLPermissions& perms);
  273. extern LLToolDragAndDrop gToolDragAndDrop;
  274. #endif // LL_TOOLDRAGANDDROP_H