]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dnd.h | |
bc85d676 | 3 | // Purpose: interface of wxDropSource and wx*DropTarget |
23324ae1 | 4 | // Author: wxWidgets team |
526954c5 | 5 | // Licence: wxWindows licence |
23324ae1 FM |
6 | ///////////////////////////////////////////////////////////////////////////// |
7 | ||
04581fad VZ |
8 | /** |
9 | Possible flags for drag and drop operations. | |
10 | */ | |
11 | enum | |
12 | { | |
13 | wxDrag_CopyOnly = 0, ///< Allow only copying. | |
14 | wxDrag_AllowMove = 1, ///< Allow moving too (copying is always allowed). | |
15 | wxDrag_DefaultMove = 3 ///< Allow moving and make it default operation. | |
16 | }; | |
17 | ||
bc85d676 BP |
18 | /** |
19 | Result returned from a wxDropSource::DoDragDrop() call. | |
20 | */ | |
21 | enum wxDragResult | |
22 | { | |
23 | wxDragError, ///< Error prevented the D&D operation from completing. | |
24 | wxDragNone, ///< Drag target didn't accept the data. | |
25 | wxDragCopy, ///< The data was successfully copied. | |
26 | wxDragMove, ///< The data was successfully moved (MSW only). | |
27 | wxDragLink, ///< Operation is a drag-link. | |
28 | wxDragCancel ///< The operation was cancelled by user (not an error). | |
29 | }; | |
30 | ||
07b6b121 RD |
31 | |
32 | ||
23324ae1 FM |
33 | /** |
34 | @class wxDropTarget | |
7c913512 | 35 | |
bc85d676 BP |
36 | This class represents a target for a drag and drop operation. A |
37 | wxDataObject can be associated with it and by default, this object will be | |
38 | filled with the data from the drag source, if the data formats supported by | |
39 | the data object match the drag source data format. | |
40 | ||
41 | There are various virtual handler functions defined in this class which may | |
42 | be overridden to give visual feedback or react in a more fine-tuned way, | |
43 | e.g. by not accepting data on the whole window area, but only a small | |
44 | portion of it. The normal sequence of calls is OnEnter(), OnDragOver() | |
45 | possibly many times, OnDrop() and finally OnData(). | |
7c913512 | 46 | |
23324ae1 FM |
47 | @library{wxcore} |
48 | @category{dnd} | |
7c913512 | 49 | |
bc85d676 BP |
50 | @see @ref overview_dnd, @ref overview_dataobject, wxDropSource, |
51 | wxTextDropTarget, wxFileDropTarget, wxDataFormat, wxDataObject | |
23324ae1 | 52 | */ |
7c913512 | 53 | class wxDropTarget |
23324ae1 FM |
54 | { |
55 | public: | |
56 | /** | |
4cc4bfaf | 57 | Constructor. @a data is the data to be associated with the drop target. |
23324ae1 | 58 | */ |
4cc4bfaf | 59 | wxDropTarget(wxDataObject* data = NULL); |
23324ae1 FM |
60 | |
61 | /** | |
62 | Destructor. Deletes the associated data object, if any. | |
63 | */ | |
adaaa686 | 64 | virtual ~wxDropTarget(); |
23324ae1 FM |
65 | |
66 | /** | |
bc85d676 BP |
67 | This method may only be called from within OnData(). By default, this |
68 | method copies the data from the drop source to the wxDataObject | |
69 | associated with this drop target, calling its wxDataObject::SetData() | |
70 | method. | |
23324ae1 | 71 | */ |
07b6b121 | 72 | virtual bool GetData(); |
23324ae1 FM |
73 | |
74 | /** | |
bc85d676 | 75 | Called after OnDrop() returns @true. By default this will usually |
07b6b121 | 76 | GetData() and will return the suggested default value @a defResult. |
23324ae1 | 77 | */ |
07b6b121 | 78 | virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult defResult) = 0; |
23324ae1 FM |
79 | |
80 | /** | |
bc85d676 | 81 | Called when the mouse is being dragged over the drop target. By |
07b6b121 | 82 | default, this calls functions return the suggested return value @a defResult. |
3c4f71cc | 83 | |
7c913512 | 84 | @param x |
4cc4bfaf | 85 | The x coordinate of the mouse. |
7c913512 | 86 | @param y |
4cc4bfaf | 87 | The y coordinate of the mouse. |
07b6b121 | 88 | @param defResult |
bc85d676 BP |
89 | Suggested value for return value. Determined by SHIFT or CONTROL |
90 | key states. | |
3c4f71cc | 91 | |
d29a9a8a | 92 | @return The desired operation or wxDragNone. This is used for optical |
bc85d676 BP |
93 | feedback from the side of the drop source, typically in form |
94 | of changing the icon. | |
23324ae1 | 95 | */ |
07b6b121 | 96 | virtual wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult defResult); |
23324ae1 FM |
97 | |
98 | /** | |
bc85d676 BP |
99 | Called when the user drops a data object on the target. Return @false |
100 | to veto the operation. | |
3c4f71cc | 101 | |
7c913512 | 102 | @param x |
4cc4bfaf | 103 | The x coordinate of the mouse. |
7c913512 | 104 | @param y |
4cc4bfaf | 105 | The y coordinate of the mouse. |
3c4f71cc | 106 | |
d29a9a8a | 107 | @return @true to accept the data, or @false to veto the operation. |
23324ae1 | 108 | */ |
07b6b121 | 109 | virtual bool OnDrop(wxCoord x, wxCoord y); |
23324ae1 FM |
110 | |
111 | /** | |
112 | Called when the mouse enters the drop target. By default, this calls | |
113 | OnDragOver(). | |
3c4f71cc | 114 | |
7c913512 | 115 | @param x |
4cc4bfaf | 116 | The x coordinate of the mouse. |
7c913512 | 117 | @param y |
4cc4bfaf | 118 | The y coordinate of the mouse. |
07b6b121 | 119 | @param defResult |
bc85d676 BP |
120 | Suggested default for return value. Determined by SHIFT or CONTROL |
121 | key states. | |
3c4f71cc | 122 | |
d29a9a8a | 123 | @return The desired operation or wxDragNone. This is used for optical |
bc85d676 BP |
124 | feedback from the side of the drop source, typically in form |
125 | of changing the icon. | |
23324ae1 | 126 | */ |
07b6b121 | 127 | virtual wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult defResult); |
23324ae1 FM |
128 | |
129 | /** | |
130 | Called when the mouse leaves the drop target. | |
131 | */ | |
132 | virtual void OnLeave(); | |
133 | ||
2c71ae12 VZ |
134 | /** |
135 | Returns the data wxDataObject associated with the drop target | |
136 | */ | |
137 | wxDataObject *GetDataObject() const; | |
138 | ||
23324ae1 | 139 | /** |
bc85d676 BP |
140 | Sets the data wxDataObject associated with the drop target and deletes |
141 | any previously associated data object. | |
23324ae1 FM |
142 | */ |
143 | void SetDataObject(wxDataObject* data); | |
07b6b121 RD |
144 | |
145 | ||
146 | /** | |
147 | Sets the default action for drag and drop. Use wxDragMove or | |
148 | wxDragCopy to set deafult action to move or copy and use wxDragNone | |
149 | (default) to set default action specified by initialization of draging | |
150 | (see wxDropSource::DoDragDrop()) | |
151 | */ | |
152 | void SetDefaultAction(wxDragResult action); | |
153 | ||
154 | /** | |
155 | Returns default action for drag and drop or wxDragNone if this not | |
156 | specified. | |
157 | */ | |
158 | wxDragResult GetDefaultAction(); | |
159 | ||
23324ae1 FM |
160 | }; |
161 | ||
162 | ||
e54c96f1 | 163 | |
23324ae1 FM |
164 | /** |
165 | @class wxDropSource | |
7c913512 | 166 | |
23324ae1 | 167 | This class represents a source for a drag and drop operation. |
7c913512 | 168 | |
23324ae1 FM |
169 | @library{wxcore} |
170 | @category{dnd} | |
7c913512 | 171 | |
bc85d676 BP |
172 | @see @ref overview_dnd, @ref overview_dataobject, wxDropTarget, |
173 | wxTextDropTarget, wxFileDropTarget | |
23324ae1 | 174 | */ |
7c913512 | 175 | class wxDropSource |
23324ae1 FM |
176 | { |
177 | public: | |
23324ae1 | 178 | /** |
bc85d676 BP |
179 | This constructor requires that you must call SetData() later. |
180 | ||
408776d0 | 181 | Note that the type of @a iconCopy and subsequent parameters |
c0211f55 VZ |
182 | differs between different ports: these are cursors under Windows and OS |
183 | X but icons for GTK. You should use the macro wxDROP_ICON() in portable | |
23324ae1 | 184 | programs instead of directly using either of these types. |
3c4f71cc | 185 | |
0f6c9085 | 186 | @onlyfor{wxmsw,wxosx} |
408776d0 FM |
187 | |
188 | @param win | |
189 | The window which initiates the drag and drop operation. | |
190 | @param iconCopy | |
191 | The icon or cursor used for feedback for copy operation. | |
192 | @param iconMove | |
193 | The icon or cursor used for feedback for move operation. | |
194 | @param iconNone | |
195 | The icon or cursor used for feedback when operation can't be done. | |
196 | */ | |
197 | wxDropSource(wxWindow* win = NULL, | |
4e4fffec RD |
198 | const wxCursor& iconCopy = wxNullCursor, |
199 | const wxCursor& iconMove = wxNullCursor, | |
200 | const wxCursor& iconNone = wxNullCursor); | |
408776d0 FM |
201 | |
202 | /** | |
c0211f55 | 203 | The constructor taking a wxDataObject. |
408776d0 FM |
204 | |
205 | Note that the type of @a iconCopy and subsequent parameters | |
c0211f55 VZ |
206 | differs between different ports: these are cursors under Windows and OS |
207 | X but icons for GTK. You should use the macro wxDROP_ICON() in portable | |
408776d0 FM |
208 | programs instead of directly using either of these types. |
209 | ||
0f6c9085 | 210 | @onlyfor{wxmsw,wxosx} |
408776d0 FM |
211 | |
212 | @param data | |
213 | The data associated with the drop source. | |
214 | @param win | |
215 | The window which initiates the drag and drop operation. | |
216 | @param iconCopy | |
217 | The icon or cursor used for feedback for copy operation. | |
218 | @param iconMove | |
219 | The icon or cursor used for feedback for move operation. | |
220 | @param iconNone | |
221 | The icon or cursor used for feedback when operation can't be done. | |
222 | */ | |
223 | wxDropSource(wxDataObject& data, wxWindow* win = NULL, | |
4e4fffec RD |
224 | const wxCursor& iconCopy = wxNullCursor, |
225 | const wxCursor& iconMove = wxNullCursor, | |
226 | const wxCursor& iconNone = wxNullCursor); | |
408776d0 FM |
227 | |
228 | /** | |
229 | This constructor requires that you must call SetData() later. | |
230 | ||
c0211f55 VZ |
231 | This is the wxGTK-specific version of the constructor taking wxIcon |
232 | instead of wxCursor as the other ports. | |
408776d0 FM |
233 | |
234 | @onlyfor{wxgtk} | |
235 | ||
7c913512 | 236 | @param win |
4cc4bfaf | 237 | The window which initiates the drag and drop operation. |
7c913512 | 238 | @param iconCopy |
4cc4bfaf | 239 | The icon or cursor used for feedback for copy operation. |
7c913512 | 240 | @param iconMove |
4cc4bfaf | 241 | The icon or cursor used for feedback for move operation. |
7c913512 | 242 | @param iconNone |
4cc4bfaf | 243 | The icon or cursor used for feedback when operation can't be done. |
23324ae1 | 244 | */ |
4cc4bfaf | 245 | wxDropSource(wxWindow* win = NULL, |
4e4fffec RD |
246 | const wxIcon& iconCopy = wxNullIcon, |
247 | const wxIcon& iconMove = wxNullIcon, | |
248 | const wxIcon& iconNone = wxNullIcon); | |
76e9224e | 249 | |
bc85d676 | 250 | /** |
c0211f55 | 251 | The constructor taking a wxDataObject. |
76e9224e | 252 | |
c0211f55 VZ |
253 | This is the wxGTK-specific version of the constructor taking wxIcon |
254 | instead of wxCursor as the other ports. | |
bc85d676 | 255 | |
408776d0 FM |
256 | @onlyfor{wxgtk} |
257 | ||
76e9224e FM |
258 | @param data |
259 | The data associated with the drop source. | |
bc85d676 BP |
260 | @param win |
261 | The window which initiates the drag and drop operation. | |
262 | @param iconCopy | |
263 | The icon or cursor used for feedback for copy operation. | |
264 | @param iconMove | |
265 | The icon or cursor used for feedback for move operation. | |
266 | @param iconNone | |
267 | The icon or cursor used for feedback when operation can't be done. | |
268 | */ | |
4cc4bfaf | 269 | wxDropSource(wxDataObject& data, wxWindow* win = NULL, |
4e4fffec RD |
270 | const wxIcon& iconCopy = wxNullIcon, |
271 | const wxIcon& iconMove = wxNullIcon, | |
272 | const wxIcon& iconNone = wxNullIcon); | |
23324ae1 FM |
273 | |
274 | /** | |
bc85d676 BP |
275 | Starts the drag-and-drop operation which will terminate when the user |
276 | releases the mouse. Call this in response to a mouse button press, for | |
277 | example. | |
3c4f71cc | 278 | |
7c913512 | 279 | @param flags |
04581fad VZ |
280 | If ::wxDrag_AllowMove is included in the flags, data may be moved |
281 | and not only copied as is the case for the default | |
282 | ::wxDrag_CopyOnly. If ::wxDrag_DefaultMove is specified | |
283 | (which includes the previous flag), moving is not only possible but | |
284 | becomes the default operation. | |
3c4f71cc | 285 | |
d29a9a8a | 286 | @return The operation requested by the user, may be ::wxDragCopy, |
bc85d676 | 287 | ::wxDragMove, ::wxDragLink, ::wxDragCancel or ::wxDragNone if |
4cc4bfaf | 288 | an error occurred. |
23324ae1 FM |
289 | */ |
290 | virtual wxDragResult DoDragDrop(int flags = wxDrag_CopyOnly); | |
291 | ||
292 | /** | |
293 | Returns the wxDataObject object that has been assigned previously. | |
294 | */ | |
4cc4bfaf | 295 | wxDataObject* GetDataObject(); |
23324ae1 FM |
296 | |
297 | /** | |
bc85d676 BP |
298 | You may give some custom UI feedback during the drag and drop operation |
299 | by overriding this function. It is called on each mouse move, so your | |
300 | implementation must not be too slow. | |
3c4f71cc | 301 | |
7c913512 | 302 | @param effect |
bc85d676 BP |
303 | The effect to implement. One of ::wxDragCopy, ::wxDragMove, |
304 | ::wxDragLink and ::wxDragNone. | |
3c4f71cc | 305 | |
d29a9a8a | 306 | @return @false if you want default feedback, or @true if you implement |
fac938f8 | 307 | your own feedback. The return value is ignored under GTK. |
23324ae1 FM |
308 | */ |
309 | virtual bool GiveFeedback(wxDragResult effect); | |
310 | ||
311 | /** | |
312 | Set the icon to use for a certain drag result. | |
3c4f71cc | 313 | |
7c913512 | 314 | @param res |
4cc4bfaf | 315 | The drag result to set the icon for. |
7c913512 | 316 | @param cursor |
7bb22bd6 RD |
317 | The icon to show when this drag result occurs. |
318 | ||
319 | @onlyfor{wxmsw,wxosx} | |
23324ae1 FM |
320 | */ |
321 | void SetCursor(wxDragResult res, const wxCursor& cursor); | |
322 | ||
7bb22bd6 RD |
323 | /** |
324 | Set the icon to use for a certain drag result. | |
325 | ||
326 | @param res | |
327 | The drag result to set the icon for. | |
328 | @param icon | |
329 | The icon to show when this drag result occurs. | |
330 | ||
331 | @onlyfor{wxgtk} | |
332 | */ | |
333 | void SetIcon(wxDragResult res, const wxIcon& icon); | |
334 | ||
23324ae1 | 335 | /** |
bc85d676 BP |
336 | Sets the data wxDataObject associated with the drop source. This will |
337 | not delete any previously associated data. | |
23324ae1 FM |
338 | */ |
339 | void SetData(wxDataObject& data); | |
340 | }; | |
341 | ||
342 | ||
e54c96f1 | 343 | |
07b6b121 RD |
344 | /** |
345 | @class wxTextDropTarget | |
346 | ||
347 | A predefined drop target for dealing with text data. | |
348 | ||
349 | @library{wxcore} | |
350 | @category{dnd} | |
351 | ||
352 | @see @ref overview_dnd, wxDropSource, wxDropTarget, wxFileDropTarget | |
353 | */ | |
354 | class wxTextDropTarget : public wxDropTarget | |
355 | { | |
356 | public: | |
357 | /** | |
358 | Constructor. | |
359 | */ | |
360 | wxTextDropTarget(); | |
361 | ||
362 | /** | |
363 | See wxDropTarget::OnDrop(). This function is implemented appropriately | |
364 | for text, and calls OnDropText(). | |
365 | */ | |
366 | virtual bool OnDrop(wxCoord x, wxCoord y); | |
367 | ||
368 | /** | |
369 | Override this function to receive dropped text. | |
370 | ||
371 | @param x | |
372 | The x coordinate of the mouse. | |
373 | @param y | |
374 | The y coordinate of the mouse. | |
375 | @param data | |
376 | The data being dropped: a wxString. | |
377 | ||
378 | Return @true to accept the data, or @false to veto the operation. | |
379 | */ | |
380 | virtual bool OnDropText(wxCoord x, wxCoord y, const wxString& data) = 0; | |
381 | }; | |
382 | ||
383 | ||
23324ae1 FM |
384 | /** |
385 | @class wxFileDropTarget | |
7c913512 | 386 | |
bc85d676 BP |
387 | This is a drop target which accepts files (dragged from File Manager or |
388 | Explorer). | |
7c913512 | 389 | |
23324ae1 FM |
390 | @library{wxcore} |
391 | @category{dnd} | |
7c913512 | 392 | |
bc85d676 | 393 | @see @ref overview_dnd, wxDropSource, wxDropTarget, wxTextDropTarget |
23324ae1 FM |
394 | */ |
395 | class wxFileDropTarget : public wxDropTarget | |
396 | { | |
397 | public: | |
398 | /** | |
399 | Constructor. | |
400 | */ | |
401 | wxFileDropTarget(); | |
402 | ||
403 | /** | |
bc85d676 BP |
404 | See wxDropTarget::OnDrop(). This function is implemented appropriately |
405 | for files, and calls OnDropFiles(). | |
23324ae1 | 406 | */ |
5267aefd | 407 | virtual bool OnDrop(wxCoord x, wxCoord y); |
23324ae1 FM |
408 | |
409 | /** | |
410 | Override this function to receive dropped files. | |
3c4f71cc | 411 | |
7c913512 | 412 | @param x |
4cc4bfaf | 413 | The x coordinate of the mouse. |
7c913512 | 414 | @param y |
4cc4bfaf | 415 | The y coordinate of the mouse. |
7c913512 | 416 | @param filenames |
4cc4bfaf | 417 | An array of filenames. |
bc85d676 BP |
418 | |
419 | Return @true to accept the data, or @false to veto the operation. | |
23324ae1 FM |
420 | */ |
421 | virtual bool OnDropFiles(wxCoord x, wxCoord y, | |
fadc2df6 | 422 | const wxArrayString& filenames) = 0; |
23324ae1 FM |
423 | }; |
424 | ||
425 | ||
e54c96f1 | 426 | |
23324ae1 FM |
427 | // ============================================================================ |
428 | // Global functions/macros | |
429 | // ============================================================================ | |
430 | ||
b21126db | 431 | /** @addtogroup group_funcmacro_gdi */ |
a055a116 BP |
432 | //@{ |
433 | ||
23324ae1 | 434 | /** |
a055a116 BP |
435 | This macro creates either a cursor (MSW) or an icon (elsewhere) with the |
436 | given @a name (of type <tt>const char*</tt>). Under MSW, the cursor is | |
437 | loaded from the resource file and the icon is loaded from XPM file under | |
438 | other platforms. | |
439 | ||
440 | This macro should be used with wxDropSource::wxDropSource(). | |
441 | ||
d29a9a8a | 442 | @return wxCursor on MSW, otherwise returns a wxIcon |
a055a116 BP |
443 | |
444 | @header{wx/dnd.h} | |
23324ae1 | 445 | */ |
a055a116 BP |
446 | #define wxDROP_ICON(name) |
447 | ||
07b6b121 RD |
448 | /** |
449 | Returns true if res indicates that something was done during a DnD operation, | |
450 | i.e. is neither error nor none nor cancel. | |
451 | */ | |
452 | bool wxIsDragResultOk(wxDragResult res); | |
453 | ||
a055a116 | 454 | //@} |
23324ae1 | 455 |