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