PageRenderTime 60ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/Dependencies/wxWidgets/interface/wx/dnd.h

https://github.com/goofoo/Helium
C Header | 412 lines | 64 code | 39 blank | 309 comment | 0 complexity | 59776a800b4bb331a24b774784728c52 MD5 | raw file
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: dnd.h
  3. // Purpose: interface of wxDropSource and wx*DropTarget
  4. // Author: wxWidgets team
  5. // RCS-ID: $Id$
  6. // Licence: wxWindows licence
  7. /////////////////////////////////////////////////////////////////////////////
  8. /**
  9. @class wxTextDropTarget
  10. A predefined drop target for dealing with text data.
  11. @library{wxcore}
  12. @category{dnd}
  13. @see @ref overview_dnd, wxDropSource, wxDropTarget, wxFileDropTarget
  14. */
  15. class wxTextDropTarget : public wxDropTarget
  16. {
  17. public:
  18. /**
  19. Constructor.
  20. */
  21. wxTextDropTarget();
  22. /**
  23. See wxDropTarget::OnDrop(). This function is implemented appropriately
  24. for text, and calls OnDropText().
  25. */
  26. virtual bool OnDrop(wxCoord x, wxCoord y);
  27. /**
  28. Override this function to receive dropped text.
  29. @param x
  30. The x coordinate of the mouse.
  31. @param y
  32. The y coordinate of the mouse.
  33. @param data
  34. The data being dropped: a wxString.
  35. Return @true to accept the data, or @false to veto the operation.
  36. */
  37. virtual bool OnDropText(wxCoord x, wxCoord y, const wxString& data) = 0;
  38. };
  39. /**
  40. Result returned from a wxDropSource::DoDragDrop() call.
  41. */
  42. enum wxDragResult
  43. {
  44. wxDragError, ///< Error prevented the D&D operation from completing.
  45. wxDragNone, ///< Drag target didn't accept the data.
  46. wxDragCopy, ///< The data was successfully copied.
  47. wxDragMove, ///< The data was successfully moved (MSW only).
  48. wxDragLink, ///< Operation is a drag-link.
  49. wxDragCancel ///< The operation was cancelled by user (not an error).
  50. };
  51. /**
  52. @class wxDropTarget
  53. This class represents a target for a drag and drop operation. A
  54. wxDataObject can be associated with it and by default, this object will be
  55. filled with the data from the drag source, if the data formats supported by
  56. the data object match the drag source data format.
  57. There are various virtual handler functions defined in this class which may
  58. be overridden to give visual feedback or react in a more fine-tuned way,
  59. e.g. by not accepting data on the whole window area, but only a small
  60. portion of it. The normal sequence of calls is OnEnter(), OnDragOver()
  61. possibly many times, OnDrop() and finally OnData().
  62. @library{wxcore}
  63. @category{dnd}
  64. @see @ref overview_dnd, @ref overview_dataobject, wxDropSource,
  65. wxTextDropTarget, wxFileDropTarget, wxDataFormat, wxDataObject
  66. */
  67. class wxDropTarget
  68. {
  69. public:
  70. /**
  71. Constructor. @a data is the data to be associated with the drop target.
  72. */
  73. wxDropTarget(wxDataObject* data = NULL);
  74. /**
  75. Destructor. Deletes the associated data object, if any.
  76. */
  77. virtual ~wxDropTarget();
  78. /**
  79. This method may only be called from within OnData(). By default, this
  80. method copies the data from the drop source to the wxDataObject
  81. associated with this drop target, calling its wxDataObject::SetData()
  82. method.
  83. */
  84. virtual bool GetData();
  85. /**
  86. Called after OnDrop() returns @true. By default this will usually
  87. GetData() and will return the suggested default value @a def.
  88. */
  89. virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def);
  90. /**
  91. Called when the mouse is being dragged over the drop target. By
  92. default, this calls functions return the suggested return value @a def.
  93. @param x
  94. The x coordinate of the mouse.
  95. @param y
  96. The y coordinate of the mouse.
  97. @param def
  98. Suggested value for return value. Determined by SHIFT or CONTROL
  99. key states.
  100. @return The desired operation or wxDragNone. This is used for optical
  101. feedback from the side of the drop source, typically in form
  102. of changing the icon.
  103. */
  104. virtual wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
  105. /**
  106. Called when the user drops a data object on the target. Return @false
  107. to veto the operation.
  108. @param x
  109. The x coordinate of the mouse.
  110. @param y
  111. The y coordinate of the mouse.
  112. @return @true to accept the data, or @false to veto the operation.
  113. */
  114. virtual bool OnDrop(wxCoord x, wxCoord y);
  115. /**
  116. Called when the mouse enters the drop target. By default, this calls
  117. OnDragOver().
  118. @param x
  119. The x coordinate of the mouse.
  120. @param y
  121. The y coordinate of the mouse.
  122. @param def
  123. Suggested default for return value. Determined by SHIFT or CONTROL
  124. key states.
  125. @return The desired operation or wxDragNone. This is used for optical
  126. feedback from the side of the drop source, typically in form
  127. of changing the icon.
  128. */
  129. virtual wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult def);
  130. /**
  131. Called when the mouse leaves the drop target.
  132. */
  133. virtual void OnLeave();
  134. /**
  135. Sets the data wxDataObject associated with the drop target and deletes
  136. any previously associated data object.
  137. */
  138. void SetDataObject(wxDataObject* data);
  139. };
  140. /**
  141. @class wxDropSource
  142. This class represents a source for a drag and drop operation.
  143. @library{wxcore}
  144. @category{dnd}
  145. @see @ref overview_dnd, @ref overview_dataobject, wxDropTarget,
  146. wxTextDropTarget, wxFileDropTarget
  147. */
  148. class wxDropSource
  149. {
  150. public:
  151. /**
  152. This constructor requires that you must call SetData() later.
  153. Note that the type of @a iconCopy and subsequent parameters
  154. differs between different ports: these are cursors under Windows but
  155. icons for GTK. You should use the macro wxDROP_ICON() in portable
  156. programs instead of directly using either of these types.
  157. @onlyfor{wxmsw,wxosx}
  158. @param win
  159. The window which initiates the drag and drop operation.
  160. @param iconCopy
  161. The icon or cursor used for feedback for copy operation.
  162. @param iconMove
  163. The icon or cursor used for feedback for move operation.
  164. @param iconNone
  165. The icon or cursor used for feedback when operation can't be done.
  166. */
  167. wxDropSource(wxWindow* win = NULL,
  168. const wxIcon& iconCopy = wxNullIcon,
  169. const wxIcon& iconMove = wxNullIcon,
  170. const wxIcon& iconNone = wxNullIcon);
  171. /**
  172. The constructor for wxDataObject.
  173. Note that the type of @a iconCopy and subsequent parameters
  174. differs between different ports: these are cursors under Windows but
  175. icons for GTK. You should use the macro wxDROP_ICON() in portable
  176. programs instead of directly using either of these types.
  177. @onlyfor{wxmsw,wxosx}
  178. @param data
  179. The data associated with the drop source.
  180. @param win
  181. The window which initiates the drag and drop operation.
  182. @param iconCopy
  183. The icon or cursor used for feedback for copy operation.
  184. @param iconMove
  185. The icon or cursor used for feedback for move operation.
  186. @param iconNone
  187. The icon or cursor used for feedback when operation can't be done.
  188. */
  189. wxDropSource(wxDataObject& data, wxWindow* win = NULL,
  190. const wxIcon& iconCopy = wxNullIcon,
  191. const wxIcon& iconMove = wxNullIcon,
  192. const wxIcon& iconNone = wxNullIcon);
  193. /**
  194. This constructor requires that you must call SetData() later.
  195. Note that the type of @a iconCopy and subsequent parameters
  196. differs between different ports: these are cursors under Windows but
  197. icons for GTK. You should use the macro wxDROP_ICON() in portable
  198. programs instead of directly using either of these types.
  199. @onlyfor{wxgtk}
  200. @param win
  201. The window which initiates the drag and drop operation.
  202. @param iconCopy
  203. The icon or cursor used for feedback for copy operation.
  204. @param iconMove
  205. The icon or cursor used for feedback for move operation.
  206. @param iconNone
  207. The icon or cursor used for feedback when operation can't be done.
  208. */
  209. wxDropSource(wxWindow* win = NULL,
  210. const wxCursor& iconCopy = wxNullCursor,
  211. const wxCursor& iconMove = wxNullCursor,
  212. const wxCursor& iconNone = wxNullCursor);
  213. /**
  214. The constructor for wxDataObject.
  215. Note that the type of @a iconCopy and subsequent parameters
  216. differs between different ports: these are cursors under Windows but
  217. icons for GTK. You should use the macro wxDROP_ICON() in portable
  218. programs instead of directly using either of these types.
  219. @onlyfor{wxgtk}
  220. @param data
  221. The data associated with the drop source.
  222. @param win
  223. The window which initiates the drag and drop operation.
  224. @param iconCopy
  225. The icon or cursor used for feedback for copy operation.
  226. @param iconMove
  227. The icon or cursor used for feedback for move operation.
  228. @param iconNone
  229. The icon or cursor used for feedback when operation can't be done.
  230. */
  231. wxDropSource(wxDataObject& data, wxWindow* win = NULL,
  232. const wxCursor& iconCopy = wxNullCursor,
  233. const wxCursor& iconMove = wxNullCursor,
  234. const wxCursor& iconNone = wxNullCursor);
  235. /**
  236. Default constructor.
  237. */
  238. virtual ~wxDropSource();
  239. /**
  240. Starts the drag-and-drop operation which will terminate when the user
  241. releases the mouse. Call this in response to a mouse button press, for
  242. example.
  243. @param flags
  244. If wxDrag_AllowMove is included in the flags, data may be moved and
  245. not only copied (default). If wxDrag_DefaultMove is specified
  246. (which includes the previous flag), this is even the default
  247. operation.
  248. @return The operation requested by the user, may be ::wxDragCopy,
  249. ::wxDragMove, ::wxDragLink, ::wxDragCancel or ::wxDragNone if
  250. an error occurred.
  251. */
  252. virtual wxDragResult DoDragDrop(int flags = wxDrag_CopyOnly);
  253. /**
  254. Returns the wxDataObject object that has been assigned previously.
  255. */
  256. wxDataObject* GetDataObject();
  257. /**
  258. You may give some custom UI feedback during the drag and drop operation
  259. by overriding this function. It is called on each mouse move, so your
  260. implementation must not be too slow.
  261. @param effect
  262. The effect to implement. One of ::wxDragCopy, ::wxDragMove,
  263. ::wxDragLink and ::wxDragNone.
  264. @return @false if you want default feedback, or @true if you implement
  265. your own feedback. The return value is ignored under GTK.
  266. */
  267. virtual bool GiveFeedback(wxDragResult effect);
  268. /**
  269. Set the icon to use for a certain drag result.
  270. @param res
  271. The drag result to set the icon for.
  272. @param cursor
  273. The ion to show when this drag result occurs.
  274. */
  275. void SetCursor(wxDragResult res, const wxCursor& cursor);
  276. /**
  277. Sets the data wxDataObject associated with the drop source. This will
  278. not delete any previously associated data.
  279. */
  280. void SetData(wxDataObject& data);
  281. };
  282. /**
  283. @class wxFileDropTarget
  284. This is a drop target which accepts files (dragged from File Manager or
  285. Explorer).
  286. @library{wxcore}
  287. @category{dnd}
  288. @see @ref overview_dnd, wxDropSource, wxDropTarget, wxTextDropTarget
  289. */
  290. class wxFileDropTarget : public wxDropTarget
  291. {
  292. public:
  293. /**
  294. Constructor.
  295. */
  296. wxFileDropTarget();
  297. /**
  298. See wxDropTarget::OnDrop(). This function is implemented appropriately
  299. for files, and calls OnDropFiles().
  300. */
  301. virtual bool OnDrop(wxCoord x, wxCoord y);
  302. /**
  303. Override this function to receive dropped files.
  304. @param x
  305. The x coordinate of the mouse.
  306. @param y
  307. The y coordinate of the mouse.
  308. @param filenames
  309. An array of filenames.
  310. Return @true to accept the data, or @false to veto the operation.
  311. */
  312. virtual bool OnDropFiles(wxCoord x, wxCoord y,
  313. const wxArrayString& filenames) = 0;
  314. };
  315. // ============================================================================
  316. // Global functions/macros
  317. // ============================================================================
  318. /** @addtogroup group_funcmacro_gdi */
  319. //@{
  320. /**
  321. This macro creates either a cursor (MSW) or an icon (elsewhere) with the
  322. given @a name (of type <tt>const char*</tt>). Under MSW, the cursor is
  323. loaded from the resource file and the icon is loaded from XPM file under
  324. other platforms.
  325. This macro should be used with wxDropSource::wxDropSource().
  326. @return wxCursor on MSW, otherwise returns a wxIcon
  327. @header{wx/dnd.h}
  328. */
  329. #define wxDROP_ICON(name)
  330. //@}