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